From 43881edc572f1d080bca8ccd30d54cf19b870f0a Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 31 Oct 2009 13:31:47 +0200 Subject: [PATCH] imported winuaesrc2000b19.zip --- a2065.c | 1142 +- a2091.c | 1544 +- akiko.c | 2454 +- amax.c | 186 +- ar.c | 3127 +-- arcadia.c | 630 +- audio.c | 2778 +- autoconf.c | 258 +- blitter.c | 2180 +- blkdev.c | 564 +- bsdsocket.c | 1918 +- catweasel.c | 1110 +- cd32_fmv.c | 218 +- cdrom.c | 374 +- cdtv.c | 2166 +- cfgfile.c | 6898 ++--- cia.c | 2592 +- cpummu.c | 208 +- crc32.c | 484 +- custom.c | 9540 +++---- debug.c | 6028 ++--- disk.c | 5342 ++-- diskutil.c | 194 +- dongle.c | 308 +- drawing.c | 4476 ++-- driveclick.c | 720 +- enforcer.c | 894 +- epsonprinter.c | 724 +- ersatz.c | 438 +- expansion.c | 1604 +- fdi2raw.c | 224 +- filesys.c | 9932 +++---- fpp.c | 3108 +-- fsdb.c | 566 +- fsusage.c | 354 +- gayle.c | 2688 +- gencpu.c | 6674 +++-- gfxutil.c | 1312 +- hardfile.c | 3153 +-- identify.c | 702 +- include/audio.h | 2 +- include/cpu_prefetch.h | 453 +- include/custom.h | 4 +- include/events.h | 1 + include/filesys.h | 1 + include/memory.h | 191 +- include/newcpu.h | 216 +- inputdevice.c | 6680 ++--- keybuf.c | 328 +- main.c | 1162 +- memory.c | 5364 ++-- missing.c | 30 +- native2amiga.c | 116 +- ncr_scsi.c | 496 +- newcpu.c | 6155 ++--- od-win32/ahidsound_dsonly.c | 1344 +- od-win32/ahidsound_new.c | 3128 +-- od-win32/avioutput.c | 1816 +- od-win32/blkdev_win32_aspi.c | 1522 +- od-win32/blkdev_win32_ioctl.c | 1374 +- od-win32/blkdev_win32_spti.c | 1112 +- od-win32/bsdsock.c | 724 +- od-win32/build68k_msvc/build68k_msvc.vcxproj | 72 +- .../build68k_msvc.vcxproj.filters | 2 +- od-win32/caps/caps_win32.c | 280 +- od-win32/clipboard_win32.c | 1460 +- od-win32/debug_win32.c | 2700 +- od-win32/dinput.c | 3976 +-- od-win32/direct3d.c | 2538 +- od-win32/driveclick_win32.c | 192 +- od-win32/dxwrap.c | 1792 +- od-win32/fsdb_mywin32.c | 564 +- od-win32/fsdb_win32.c | 878 +- .../genblitter_msvc/genblitter_msvc.vcxproj | 72 +- .../genblitter_msvc.vcxproj.filters | 2 +- od-win32/gencomp_msvc/gencomp_msvc.vcxproj | 70 +- .../gencomp_msvc/gencomp_msvc.vcxproj.filters | 2 +- od-win32/gencpu_msvc/gencpu_msvc.vcxproj | 70 +- .../gencpu_msvc/gencpu_msvc.vcxproj.filters | 2 +- .../genlinetoscr_msvc.vcxproj | 44 +- od-win32/hardfile_win32.c | 2877 +-- od-win32/ioport.c | 460 +- od-win32/keyboard_win32.c | 792 +- od-win32/lcd.c | 286 +- od-win32/midi.c | 1088 +- od-win32/mman.c | 1230 +- od-win32/parser.c | 1900 +- od-win32/picasso96_win.c | 6566 ++--- od-win32/posixemu.c | 392 +- od-win32/registry.c | 694 +- od-win32/resources/winuae.rc | 58 +- od-win32/rp.c | 1528 +- od-win32/scaler.c | 2132 +- od-win32/scaler_more.c | 592 +- od-win32/screenshot.c | 460 +- od-win32/serial_win32.c | 536 +- od-win32/sounddep/sound.c | 3727 +-- od-win32/uaeunp/uaeunp.vcxproj | 73 +- od-win32/uaeunp/uaeunp.vcxproj.filters | 18 +- od-win32/unicode.c | 164 +- od-win32/win32.c | 7588 +++--- od-win32/win32.h | 8 +- od-win32/win32_scale2x.c | 1084 +- od-win32/win32_uaenet.c | 674 +- od-win32/win32gfx.c | 3992 +-- od-win32/win32gui.c | 21540 ++++++++-------- od-win32/win32gui_extra.c | 260 +- od-win32/winuaechangelog.txt | 25 +- od-win32/writelog.c | 662 +- readcpu.c | 1588 +- sana2.c | 2542 +- savestate.c | 2196 +- scsi.c | 206 +- scsiemul.c | 1630 +- traps.c | 634 +- uaeexe.c | 186 +- uaeipc.c | 426 +- uaelib.c | 610 +- uaeresource.c | 180 +- uaeserial.c | 1052 +- zfile.c | 4104 +-- zfile_archive.c | 2902 +-- 122 files changed, 108350 insertions(+), 108059 deletions(-) diff --git a/a2065.c b/a2065.c index c30b2015..c6d35bd6 100644 --- a/a2065.c +++ b/a2065.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * A2065 ZorroII Ethernet Card - * - * Copyright 2009 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* A2065 ZorroII Ethernet Card +* +* Copyright 2009 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -105,39 +105,39 @@ static uae_u8 broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; static void ew (int addr, uae_u32 value) { - addr &= 0xffff; - if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { - config[addr] = (value & 0xf0); - config[addr + 2] = (value & 0x0f) << 4; - } else { - config[addr] = ~(value & 0xf0); - config[addr + 2] = ~((value & 0x0f) << 4); - } + addr &= 0xffff; + if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { + config[addr] = (value & 0xf0); + config[addr + 2] = (value & 0x0f) << 4; + } else { + config[addr] = ~(value & 0xf0); + config[addr + 2] = ~((value & 0x0f) << 4); + } } void a2065_reset (void) { - am_initialized = 0; - csr[0] = csr[1] = csr[2] = csr[3] = 0; - rap = 0; - - uaenet_close (sysdata); - xfree (sysdata); - sysdata = NULL; - td = NULL; + am_initialized = 0; + csr[0] = csr[1] = csr[2] = csr[3] = 0; + rap = 0; + + uaenet_close (sysdata); + xfree (sysdata); + sysdata = NULL; + td = NULL; } static void dumppacket (TCHAR *n, uae_u8 *packet, int len) { - int i; - TCHAR buf[10000]; - - for (i = 0; i < len; i++) { - _stprintf (buf + i * 3, L".%02X", packet[i]); - } - write_log (L"%s %d: ", n, len); - write_log (buf); - write_log (L"\n\n"); + int i; + TCHAR buf[10000]; + + for (i = 0; i < len; i++) { + _stprintf (buf + i * 3, L".%02X", packet[i]); + } + write_log (L"%s %d: ", n, len); + write_log (buf); + write_log (L"\n\n"); } #define MAX_PACKET_SIZE 4000 @@ -146,15 +146,15 @@ static int transmitlen; static int dofakemac (uae_u8 *packet) { - if (!memcmp (packet, fakemac, 6)) { - memcpy (packet, realmac, 6); - return 1; - } - if (!memcmp (packet, realmac, 6)) { - memcpy (packet, fakemac, 6); - return 1; - } - return 0; + if (!memcmp (packet, fakemac, 6)) { + memcpy (packet, realmac, 6); + return 1; + } + if (!memcmp (packet, realmac, 6)) { + memcpy (packet, fakemac, 6); + return 1; + } + return 0; } // Replace card's MAC with real MAC and vice versa. @@ -163,560 +163,560 @@ static int dofakemac (uae_u8 *packet) static int mungepacket (uae_u8 *packet, int len) { - uae_u8 *data; - uae_u16 type; - int ret = 0; - - if (len < 60) - return 0; - //dumppacket (L"pre:", packet, len); - data = packet + 14; - type = (packet[12] << 8) | packet[13]; - // switch destination mac - ret |= dofakemac (packet); - // switch source mac - ret |= dofakemac (packet + 6); - if (type == 0x0806) { // ARP? - if (((data[0] << 8) | data[1]) == 1 && data[4] == 6) { // Ethernet and LEN=6? - ret |= dofakemac (data + 8); // sender - ret |= dofakemac (data + 8 + 6 + 4); // target - } - } else if (type == 0x0800) { // IPv4? - int proto = data[9]; - int ihl = data[0] & 15; - uae_u8 *ipv4 = data; - - data += ihl * 4; - if (proto == 17) { // UDP? - int udpcrc = 0; - int sp = (data[0] << 8) | data[1]; - int dp = (data[2] << 8) | data[3]; - int len = (data[4] << 8) | data[5]; - if (sp == 67 || sp == 68 || dp == 67 || dp == 68) - udpcrc |= dofakemac (data + 36); // DHCP CHADDR - if (udpcrc && (data[6] || data[7])) { - // fix UDP checksum - int i; - uae_u32 sum; - data[6] = data[7] = 0; - data[len] = 0; - sum = 0; - for (i = 0; i < ((len + 1) & ~1); i += 2) - sum += (data[i] << 8) | data[i + 1]; - sum += (ipv4[12] << 8) | ipv4[13]; - sum += (ipv4[14] << 8) | ipv4[15]; - sum += (ipv4[16] << 8) | ipv4[17]; - sum += (ipv4[18] << 8) | ipv4[19]; - sum += 17; - sum += len; - while (sum >> 16) - sum = (sum & 0xFFFF) + (sum >> 16); - sum = ~sum; - if (sum == 0) - sum = 0xffff; - data[6] = sum >> 8; - data[7] = sum >> 0; - ret |= 1; - } - // this all just to translate single DHCP MAC.. + uae_u8 *data; + uae_u16 type; + int ret = 0; + + if (len < 60) + return 0; + //dumppacket (L"pre:", packet, len); + data = packet + 14; + type = (packet[12] << 8) | packet[13]; + // switch destination mac + ret |= dofakemac (packet); + // switch source mac + ret |= dofakemac (packet + 6); + if (type == 0x0806) { // ARP? + if (((data[0] << 8) | data[1]) == 1 && data[4] == 6) { // Ethernet and LEN=6? + ret |= dofakemac (data + 8); // sender + ret |= dofakemac (data + 8 + 6 + 4); // target + } + } else if (type == 0x0800) { // IPv4? + int proto = data[9]; + int ihl = data[0] & 15; + uae_u8 *ipv4 = data; + + data += ihl * 4; + if (proto == 17) { // UDP? + int udpcrc = 0; + int sp = (data[0] << 8) | data[1]; + int dp = (data[2] << 8) | data[3]; + int len = (data[4] << 8) | data[5]; + if (sp == 67 || sp == 68 || dp == 67 || dp == 68) + udpcrc |= dofakemac (data + 36); // DHCP CHADDR + if (udpcrc && (data[6] || data[7])) { + // fix UDP checksum + int i; + uae_u32 sum; + data[6] = data[7] = 0; + data[len] = 0; + sum = 0; + for (i = 0; i < ((len + 1) & ~1); i += 2) + sum += (data[i] << 8) | data[i + 1]; + sum += (ipv4[12] << 8) | ipv4[13]; + sum += (ipv4[14] << 8) | ipv4[15]; + sum += (ipv4[16] << 8) | ipv4[17]; + sum += (ipv4[18] << 8) | ipv4[19]; + sum += 17; + sum += len; + while (sum >> 16) + sum = (sum & 0xFFFF) + (sum >> 16); + sum = ~sum; + if (sum == 0) + sum = 0xffff; + data[6] = sum >> 8; + data[7] = sum >> 0; + ret |= 1; + } + // this all just to translate single DHCP MAC.. + } } - } - //dumppacket (L"post:", packet, len); - return ret; + //dumppacket (L"post:", packet, len); + return ret; } static int getfunc (struct devstruct *dev, uae_u8 *d, int *len) { - int tlen; - - tlen = transmitlen; - transmitlen = 0; - if (tlen > 0) { - if (tlen > *len) - return 0; - memcpy (d, transmitbuffer, tlen); - *len = tlen; - transmitnow = 1; - return 1; - } - return 0; + int tlen; + + tlen = transmitlen; + transmitlen = 0; + if (tlen > 0) { + if (tlen > *len) + return 0; + memcpy (d, transmitbuffer, tlen); + *len = tlen; + transmitnow = 1; + return 1; + } + return 0; } static int mcfilter (const uae_u8 *data) { - if (am_ladrf == 0) // multicast filter completely disabled? - return 0; - return 1; // just allow everything + if (am_ladrf == 0) // multicast filter completely disabled? + return 0; + return 1; // just allow everything } static void gotfunc (struct devstruct *dev, const uae_u8 *data2, int len) { - int i; - int size, insize, first; - uae_u32 addr; - uae_u8 *p, *d; - uae_u16 rmd0, rmd1, rmd2, rmd3; - uae_u32 crc32; - uae_u8 tmp[MAX_PACKET_SIZE], *data; - - if (!(csr[0] & CSR0_RXON)) // receiver off? - return; - if (len < 60) // too short - return; - - if (data2[0] & 0x80) { - // multicast - if (!mcfilter (data2)) - return; - } else { - // !promiscuous and dst != me and dst != broadcast - if (!prom && (memcmp (data2, realmac, sizeof realmac) != 0 && memcmp (data2, broadcast, sizeof broadcast) != 0)) - return; - } - - // src and dst = me? right, better drop it. - if (memcmp (data2, realmac, sizeof realmac) == 0 && memcmp (data2 + 6, realmac, sizeof realmac) == 0) - return; - // dst = broadcast and src = me? no thanks. - if (memcmp (data2, broadcast, sizeof broadcast) == 0 && memcmp (data2 + 6, realmac, sizeof realmac) == 0) - return; - - memcpy (tmp, data2, len); - d = tmp; - if (a2065_log) { - if (memcmp (d, realmac, sizeof realmac) == 0) { - write_log (L"A2065<-DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - (d[12] << 8) | d[13], len); - } - } - if (mungepacket (d, len)) { - if (a2065_log) { - write_log (L"A2065<*DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - (d[12] << 8) | d[13], len); - } - } - - // winpcap does not include checksum bytes - crc32 = get_crc32 (d, len); - d[len++] = crc32 >> 24; - d[len++] = crc32 >> 16; - d[len++] = crc32 >> 8; - d[len++] = crc32 >> 0; - data = tmp; - - size = 0; - insize = 0; - first = 1; - - for (;;) { - rdr_offset %= am_rdr_rlen; - p = boardram + ((am_rdr_rdra + rdr_offset * 8) & RAM_MASK); - rmd0 = (p[1] << 8) | (p[0] << 0); - rmd1 = (p[3] << 8) | (p[2] << 0); - rmd2 = (p[5] << 8) | (p[4] << 0); - rmd3 = (p[7] << 8) | (p[6] << 0); - addr = rmd0 | ((rmd1 & 0xff) << 16); - addr &= RAM_MASK; - - if (!(rmd1 & RX_OWN)) { - if (!first) { - rmd1 |= RX_BUFF | RX_OFLO; - csr[0] &= ~CSR0_RXON; - } else { - csr[0] |= CSR0_MISS; - } - p[3] = rmd1 >> 8; - p[2] = rmd1 >> 0; - return; + int i; + int size, insize, first; + uae_u32 addr; + uae_u8 *p, *d; + uae_u16 rmd0, rmd1, rmd2, rmd3; + uae_u32 crc32; + uae_u8 tmp[MAX_PACKET_SIZE], *data; + + if (!(csr[0] & CSR0_RXON)) // receiver off? + return; + if (len < 60) // too short + return; + + if (data2[0] & 0x80) { + // multicast + if (!mcfilter (data2)) + return; + } else { + // !promiscuous and dst != me and dst != broadcast + if (!prom && (memcmp (data2, realmac, sizeof realmac) != 0 && memcmp (data2, broadcast, sizeof broadcast) != 0)) + return; } - rmd1 &= ~RX_OWN; - rdr_offset++; + // src and dst = me? right, better drop it. + if (memcmp (data2, realmac, sizeof realmac) == 0 && memcmp (data2 + 6, realmac, sizeof realmac) == 0) + return; + // dst = broadcast and src = me? no thanks. + if (memcmp (data2, broadcast, sizeof broadcast) == 0 && memcmp (data2 + 6, realmac, sizeof realmac) == 0) + return; - if (first) { - rmd1 |= RX_STP; - first = 0; + memcpy (tmp, data2, len); + d = tmp; + if (a2065_log) { + if (memcmp (d, realmac, sizeof realmac) == 0) { + write_log (L"A2065<-DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + (d[12] << 8) | d[13], len); + } } - - size = 65536 - rmd2; - for (i = 0; i < size && insize < len; i++, insize++) - boardram[((addr + i) ^ byteswap) & RAM_MASK] = data[insize]; - if (insize >= len) { - rmd1 |= RX_ENP; - rmd3 = len; + if (mungepacket (d, len)) { + if (a2065_log) { + write_log (L"A2065<*DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + (d[12] << 8) | d[13], len); + } } - p[3] = rmd1 >> 8; - p[2] = rmd1 >> 0; - p[7] = rmd3 >> 8; - p[6] = rmd3 >> 0; - - if (insize >= len) - break; - } + // winpcap does not include checksum bytes + crc32 = get_crc32 (d, len); + d[len++] = crc32 >> 24; + d[len++] = crc32 >> 16; + d[len++] = crc32 >> 8; + d[len++] = crc32 >> 0; + data = tmp; + + size = 0; + insize = 0; + first = 1; + + for (;;) { + rdr_offset %= am_rdr_rlen; + p = boardram + ((am_rdr_rdra + rdr_offset * 8) & RAM_MASK); + rmd0 = (p[1] << 8) | (p[0] << 0); + rmd1 = (p[3] << 8) | (p[2] << 0); + rmd2 = (p[5] << 8) | (p[4] << 0); + rmd3 = (p[7] << 8) | (p[6] << 0); + addr = rmd0 | ((rmd1 & 0xff) << 16); + addr &= RAM_MASK; + + if (!(rmd1 & RX_OWN)) { + if (!first) { + rmd1 |= RX_BUFF | RX_OFLO; + csr[0] &= ~CSR0_RXON; + } else { + csr[0] |= CSR0_MISS; + } + p[3] = rmd1 >> 8; + p[2] = rmd1 >> 0; + return; + } + + rmd1 &= ~RX_OWN; + rdr_offset++; + + if (first) { + rmd1 |= RX_STP; + first = 0; + } + + size = 65536 - rmd2; + for (i = 0; i < size && insize < len; i++, insize++) + boardram[((addr + i) ^ byteswap) & RAM_MASK] = data[insize]; + if (insize >= len) { + rmd1 |= RX_ENP; + rmd3 = len; + } + + p[3] = rmd1 >> 8; + p[2] = rmd1 >> 0; + p[7] = rmd3 >> 8; + p[6] = rmd3 >> 0; + + if (insize >= len) + break; + } - csr[0] |= CSR0_RINT; - rethink_a2065 (); + csr[0] |= CSR0_RINT; + rethink_a2065 (); } static void do_transmit (void) { - int i; - int size, outsize; - int err, add_fcs; - uae_u32 addr; - uae_u8 *p; - uae_u16 tmd0, tmd1, tmd2, tmd3; - - err = 0; - size = 0; - outsize = 0; - - tdr_offset %= am_tdr_tlen; - p = boardram + ((am_tdr_tdra + tdr_offset * 8) & RAM_MASK); - tmd1 = (p[3] << 8) | (p[2] << 0); - if (!(tmd1 & TX_OWN) || !(tmd1 & TX_STP)) - return; - add_fcs = tmd1 & TX_ADD_FCS; - - for (;;) { + int i; + int size, outsize; + int err, add_fcs; + uae_u32 addr; + uae_u8 *p; + uae_u16 tmd0, tmd1, tmd2, tmd3; + + err = 0; + size = 0; + outsize = 0; + tdr_offset %= am_tdr_tlen; p = boardram + ((am_tdr_tdra + tdr_offset * 8) & RAM_MASK); - tmd0 = (p[1] << 8) | (p[0] << 0); tmd1 = (p[3] << 8) | (p[2] << 0); - tmd2 = (p[5] << 8) | (p[4] << 0); - tmd3 = (p[7] << 8) | (p[6] << 0); - addr = tmd0 | ((tmd1 & 0xff) << 16); - addr &= RAM_MASK; - - if (!(tmd1 & TX_OWN)) { - tmd3 |= TX_BUFF | TX_UFLO; - csr[0] &= ~CSR0_TXON; - write_log (L"A2065: TRANSMIT BUFFER ERROR\n"); - err = 1; - } else { - tmd1 &= ~TX_OWN; - size = 65536 - tmd2; - if (size > MAX_PACKET_SIZE) - size = MAX_PACKET_SIZE; - for (i = 0; i < size; i++) - transmitbuffer[outsize++] = boardram[((addr + i) ^ byteswap) & RAM_MASK]; - tdr_offset++; + if (!(tmd1 & TX_OWN) || !(tmd1 & TX_STP)) + return; + add_fcs = tmd1 & TX_ADD_FCS; + + for (;;) { + tdr_offset %= am_tdr_tlen; + p = boardram + ((am_tdr_tdra + tdr_offset * 8) & RAM_MASK); + tmd0 = (p[1] << 8) | (p[0] << 0); + tmd1 = (p[3] << 8) | (p[2] << 0); + tmd2 = (p[5] << 8) | (p[4] << 0); + tmd3 = (p[7] << 8) | (p[6] << 0); + addr = tmd0 | ((tmd1 & 0xff) << 16); + addr &= RAM_MASK; + + if (!(tmd1 & TX_OWN)) { + tmd3 |= TX_BUFF | TX_UFLO; + csr[0] &= ~CSR0_TXON; + write_log (L"A2065: TRANSMIT BUFFER ERROR\n"); + err = 1; + } else { + tmd1 &= ~TX_OWN; + size = 65536 - tmd2; + if (size > MAX_PACKET_SIZE) + size = MAX_PACKET_SIZE; + for (i = 0; i < size; i++) + transmitbuffer[outsize++] = boardram[((addr + i) ^ byteswap) & RAM_MASK]; + tdr_offset++; + } + p[3] = tmd1 >> 8; + p[2] = tmd1 >> 0; + p[7] = tmd3 >> 8; + p[6] = tmd3 >> 0; + if ((tmd1 & TX_ENP) || err) + break; } - p[3] = tmd1 >> 8; - p[2] = tmd1 >> 0; - p[7] = tmd3 >> 8; - p[6] = tmd3 >> 0; - if ((tmd1 & TX_ENP) || err) - break; - } - if (outsize < 60) { - tmd3 |= TX_BUFF | TX_UFLO; - csr[0] &= ~CSR0_TXON; - write_log (L"A2065: TRANSMIT SIZE %d\n", outsize); - err = 1; - } - - if (!err) { - uae_u8 *d = transmitbuffer; - if ((am_mode & MODE_DTCR) && !add_fcs) - outsize -= 4; // do not include checksum bytes - if (a2065_log) { - write_log (L"A2065->DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - (d[12] << 8) | d[13], outsize); + if (outsize < 60) { + tmd3 |= TX_BUFF | TX_UFLO; + csr[0] &= ~CSR0_TXON; + write_log (L"A2065: TRANSMIT SIZE %d\n", outsize); + err = 1; } - transmitlen = outsize; - if (mungepacket (d, transmitlen)) { - if (a2065_log) { - write_log (L"A2065*>DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - (d[12] << 8) | d[13], outsize); - } + + if (!err) { + uae_u8 *d = transmitbuffer; + if ((am_mode & MODE_DTCR) && !add_fcs) + outsize -= 4; // do not include checksum bytes + if (a2065_log) { + write_log (L"A2065->DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + (d[12] << 8) | d[13], outsize); + } + transmitlen = outsize; + if (mungepacket (d, transmitlen)) { + if (a2065_log) { + write_log (L"A2065*>DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + (d[12] << 8) | d[13], outsize); + } + } + uaenet_trigger (sysdata); + csr[0] |= CSR0_TINT; + rethink_a2065 (); } - uaenet_trigger (sysdata); - csr[0] |= CSR0_TINT; - rethink_a2065 (); - } } void a2065_hsync_handler (void) { - static int cnt; - - cnt--; - if (cnt < 0 || transmitnow) { - transmitnow = 0; - if ((csr[0] & CSR0_TXON) && transmitlen <= 0) - do_transmit (); - cnt = 15; - } + static int cnt; + + cnt--; + if (cnt < 0 || transmitnow) { + transmitnow = 0; + if ((csr[0] & CSR0_TXON) && transmitlen <= 0) + do_transmit (); + cnt = 15; + } } void rethink_a2065 (void) { - uae_u16 csr0 = csr[0]; - - if (!configured) - return; - if (csr0 & (CSR0_BABL | CSR0_MISS | CSR0_MERR | CSR0_RINT | CSR0_TINT | CSR0_IDON)) { - if (!(csr0 & CSR0_INTR)) { - csr0 |= CSR0_INTR; - if (csr0 & CSR0_INEA) { - INTREQ_0 (0x8000 | 0x0008); - } + uae_u16 csr0 = csr[0]; + + if (!configured) + return; + if (csr0 & (CSR0_BABL | CSR0_MISS | CSR0_MERR | CSR0_RINT | CSR0_TINT | CSR0_IDON)) { + if (!(csr0 & CSR0_INTR)) { + csr0 |= CSR0_INTR; + if (csr0 & CSR0_INEA) { + INTREQ_0 (0x8000 | 0x0008); + } + } + } else { + csr0 &= ~CSR0_INTR; } - } else { - csr0 &= ~CSR0_INTR; - } - csr[0] = csr0; + csr[0] = csr0; } static void chip_init (void) { - uae_u32 iaddr = ((csr[2] & 0xff) << 16) | csr[1]; - uae_u8 *p = boardram + (iaddr & RAM_MASK); - - am_mode = (p[0] << 8) | (p[1] << 0); - am_ladrf = ((uae_u64)p[15] << 56) | ((uae_u64)p[14] << 48) | ((uae_u64)p[13] << 40) | ((uae_u64)p[12] << 32) | (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | (p[8] << 0); - am_rdr = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | (p[16] << 0); - am_tdr = (p[23] << 24) | (p[22] << 16) | (p[21] << 8) | (p[20] << 0); - - am_rdr_rlen = 1 << ((am_rdr >> 29) & 7); - am_tdr_tlen = 1 << ((am_tdr >> 29) & 7); - am_rdr_rdra = am_rdr & 0x00fffff8; - am_tdr_tdra = am_tdr & 0x00fffff8; - - prom = (am_mode & MODE_PROM) ? 1 : 0; - - fakemac[0] = p[2]; - fakemac[1] = p[3]; - fakemac[2] = p[4]; - fakemac[3] = p[5]; - fakemac[4] = p[6]; - fakemac[5] = p[7]; - - write_log (L"A2065: %06X %d %d %d %06X %06X %02X:%02X:%02X:%02X:%02X:%02X\n", - iaddr, prom, am_rdr_rlen, am_tdr_tlen, am_rdr_rdra, am_tdr_tdra, - fakemac[0], fakemac[1], fakemac[2], fakemac[3], fakemac[4], fakemac[5]); - - - am_rdr_rdra &= RAM_MASK; - am_tdr_tdra &= RAM_MASK; - tdr_offset = rdr_offset = 0; - - uaenet_close (sysdata); - if (td != NULL) { - if (!sysdata) - sysdata = xcalloc (uaenet_getdatalenght(), 1); - if (!uaenet_open (sysdata, td, NULL, gotfunc, getfunc, prom)) { - write_log (L"A2065: failed to initialize winpcap driver\n"); + uae_u32 iaddr = ((csr[2] & 0xff) << 16) | csr[1]; + uae_u8 *p = boardram + (iaddr & RAM_MASK); + + am_mode = (p[0] << 8) | (p[1] << 0); + am_ladrf = ((uae_u64)p[15] << 56) | ((uae_u64)p[14] << 48) | ((uae_u64)p[13] << 40) | ((uae_u64)p[12] << 32) | (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | (p[8] << 0); + am_rdr = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | (p[16] << 0); + am_tdr = (p[23] << 24) | (p[22] << 16) | (p[21] << 8) | (p[20] << 0); + + am_rdr_rlen = 1 << ((am_rdr >> 29) & 7); + am_tdr_tlen = 1 << ((am_tdr >> 29) & 7); + am_rdr_rdra = am_rdr & 0x00fffff8; + am_tdr_tdra = am_tdr & 0x00fffff8; + + prom = (am_mode & MODE_PROM) ? 1 : 0; + + fakemac[0] = p[2]; + fakemac[1] = p[3]; + fakemac[2] = p[4]; + fakemac[3] = p[5]; + fakemac[4] = p[6]; + fakemac[5] = p[7]; + + write_log (L"A2065: %06X %d %d %d %06X %06X %02X:%02X:%02X:%02X:%02X:%02X\n", + iaddr, prom, am_rdr_rlen, am_tdr_tlen, am_rdr_rdra, am_tdr_tdra, + fakemac[0], fakemac[1], fakemac[2], fakemac[3], fakemac[4], fakemac[5]); + + + am_rdr_rdra &= RAM_MASK; + am_tdr_tdra &= RAM_MASK; + tdr_offset = rdr_offset = 0; + + uaenet_close (sysdata); + if (td != NULL) { + if (!sysdata) + sysdata = xcalloc (uaenet_getdatalenght(), 1); + if (!uaenet_open (sysdata, td, NULL, gotfunc, getfunc, prom)) { + write_log (L"A2065: failed to initialize winpcap driver\n"); + } } - } } static uae_u16 chip_wget (uaecptr addr) { - if (addr == RAP) { - return rap; - } else if (addr = RDP) { - uae_u16 v = csr[rap]; - if (rap == 0) { - if (v & (CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR)) - v |= CSR0_ERR; + if (addr == RAP) { + return rap; + } else if (addr = RDP) { + uae_u16 v = csr[rap]; + if (rap == 0) { + if (v & (CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR)) + v |= CSR0_ERR; + } + if (a2065_log > 2) + write_log (L"A2065_CHIPWGET: CSR%d=%04X PC=%08X\n", rap, v, M68K_GETPC); + return v; } - if (a2065_log > 2) - write_log (L"A2065_CHIPWGET: CSR%d=%04X PC=%08X\n", rap, v, M68K_GETPC); - return v; - } - return 0xffff; + return 0xffff; } static void chip_wput (uaecptr addr, uae_u16 v) { - if (addr == RAP) { - - rap = v & 3; - - } else if (addr == RDP) { - - uae_u16 reg = csr[rap]; - uae_u16 oreg = reg; - uae_u16 t; - - if (a2065_log > 2) - write_log (L"A2065_CHIPWPUT: CSR%d=%04X PC=%08X\n", rap, v & 0xffff, M68K_GETPC); - - switch (rap) - { - case 0: - reg &= ~CSR0_INEA; reg |= v & CSR0_INEA; - // bit = 1 -> set, bit = 0 -> nop - t = v & (CSR0_INIT | CSR0_STRT | CSR0_STOP | CSR0_TDMD); - reg |= t; - // bit = 1 -> clear, bit = 0 -> nop - t = v & (CSR0_IDON | CSR0_TINT | CSR0_RINT | CSR0_MERR | CSR0_MISS | CSR0_CERR | CSR0_BABL); - reg &= ~t; - reg &= ~CSR0_ERR; - - if ((reg & (CSR0_STOP | CSR0_STRT | CSR0_INIT)) == (CSR0_STOP | CSR0_STRT | CSR0_INIT)) - reg &= ~(CSR0_STRT | CSR0_INIT); - if (reg & CSR0_INIT) - reg &= ~CSR0_STOP; - - if ((reg & CSR0_STRT) && !(oreg & CSR0_STRT)) { - reg &= ~CSR0_STOP; - if (!(am_mode & MODE_DTX)) - reg |= CSR0_TXON; - if (!(am_mode & MODE_DRX)) - reg |= CSR0_RXON; - if (a2065_log) - write_log (L"A2065: START\n"); - } - - if ((reg & CSR0_STOP) && !(oreg & CSR0_STOP)) { - reg = CSR0_STOP; - if (a2065_log) - write_log (L"A2065: STOP\n"); - csr[3] = 0; - am_initialized = 0; - } - - if ((reg & CSR0_INIT) && am_initialized == 0) { - if (a2065_log) - write_log (L"A2065: INIT\n"); - chip_init (); - reg |= CSR0_IDON; - am_initialized = 1; - } - - if ((reg & CSR0_STRT) && am_initialized) { - if (reg & CSR0_TDMD) - transmitnow = 1; - } - reg &= ~CSR0_TDMD; - - break; - case 1: - if (csr[0] & 4) { - reg = v; - reg &= ~1; - } - break; - case 2: - if (csr[0] & 4) { - reg = v; - reg &= 0x00ff; - } - break; - case 3: - if (csr[0] & 4) { - reg = v; - reg &= 7; - } - byteswap = (reg & CSR3_BSWP) ? 1 : 0; - break; - + if (addr == RAP) { + + rap = v & 3; + + } else if (addr == RDP) { + + uae_u16 reg = csr[rap]; + uae_u16 oreg = reg; + uae_u16 t; + + if (a2065_log > 2) + write_log (L"A2065_CHIPWPUT: CSR%d=%04X PC=%08X\n", rap, v & 0xffff, M68K_GETPC); + + switch (rap) + { + case 0: + reg &= ~CSR0_INEA; reg |= v & CSR0_INEA; + // bit = 1 -> set, bit = 0 -> nop + t = v & (CSR0_INIT | CSR0_STRT | CSR0_STOP | CSR0_TDMD); + reg |= t; + // bit = 1 -> clear, bit = 0 -> nop + t = v & (CSR0_IDON | CSR0_TINT | CSR0_RINT | CSR0_MERR | CSR0_MISS | CSR0_CERR | CSR0_BABL); + reg &= ~t; + reg &= ~CSR0_ERR; + + if ((reg & (CSR0_STOP | CSR0_STRT | CSR0_INIT)) == (CSR0_STOP | CSR0_STRT | CSR0_INIT)) + reg &= ~(CSR0_STRT | CSR0_INIT); + if (reg & CSR0_INIT) + reg &= ~CSR0_STOP; + + if ((reg & CSR0_STRT) && !(oreg & CSR0_STRT)) { + reg &= ~CSR0_STOP; + if (!(am_mode & MODE_DTX)) + reg |= CSR0_TXON; + if (!(am_mode & MODE_DRX)) + reg |= CSR0_RXON; + if (a2065_log) + write_log (L"A2065: START\n"); + } + + if ((reg & CSR0_STOP) && !(oreg & CSR0_STOP)) { + reg = CSR0_STOP; + if (a2065_log) + write_log (L"A2065: STOP\n"); + csr[3] = 0; + am_initialized = 0; + } + + if ((reg & CSR0_INIT) && am_initialized == 0) { + if (a2065_log) + write_log (L"A2065: INIT\n"); + chip_init (); + reg |= CSR0_IDON; + am_initialized = 1; + } + + if ((reg & CSR0_STRT) && am_initialized) { + if (reg & CSR0_TDMD) + transmitnow = 1; + } + reg &= ~CSR0_TDMD; + + break; + case 1: + if (csr[0] & 4) { + reg = v; + reg &= ~1; + } + break; + case 2: + if (csr[0] & 4) { + reg = v; + reg &= 0x00ff; + } + break; + case 3: + if (csr[0] & 4) { + reg = v; + reg &= 7; + } + byteswap = (reg & CSR3_BSWP) ? 1 : 0; + break; + + } + csr[rap] = reg; } - csr[rap] = reg; - } } static uae_u32 a2065_bget2 (uaecptr addr) { - uae_u32 v = 0; - - if (addr < 0x40) { - v = config[addr]; - } else if (addr >= RAM_OFFSET) { - v = boardram[(addr & RAM_MASK) ^ 1]; - } - if (a2065_log > 2) - write_log (L"A2065_BGET: %08X -> %02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); - return v; + uae_u32 v = 0; + + if (addr < 0x40) { + v = config[addr]; + } else if (addr >= RAM_OFFSET) { + v = boardram[(addr & RAM_MASK) ^ 1]; + } + if (a2065_log > 2) + write_log (L"A2065_BGET: %08X -> %02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); + return v; } static void a2065_bput2 (uaecptr addr, uae_u32 v) { - if (addr >= RAM_OFFSET) { - boardram[(addr & RAM_MASK) ^ 1] = v; - } - if (a2065_log > 2) - write_log (L"A2065_BPUT: %08X <- %02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); + if (addr >= RAM_OFFSET) { + boardram[(addr & RAM_MASK) ^ 1] = v; + } + if (a2065_log > 2) + write_log (L"A2065_BPUT: %08X <- %02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); } static uae_u32 REGPARAM2 a2065_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - if (addr == CHIP_OFFSET || addr == CHIP_OFFSET + 2) { - v = chip_wget (addr); - } else { - v = a2065_bget2 (addr) << 8; - v |= a2065_bget2 (addr + 1); - } - return v; + addr &= 65535; + if (addr == CHIP_OFFSET || addr == CHIP_OFFSET + 2) { + v = chip_wget (addr); + } else { + v = a2065_bget2 (addr) << 8; + v |= a2065_bget2 (addr + 1); + } + return v; } static uae_u32 REGPARAM2 a2065_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = a2065_wget (addr) << 16; - v |= a2065_wget (addr + 2); - return v; + addr &= 65535; + v = a2065_wget (addr) << 16; + v |= a2065_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 a2065_bget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = a2065_bget2 (addr); - if (!configured) + addr &= 65535; + v = a2065_bget2 (addr); + if (!configured) + return v; return v; - return v; } static void REGPARAM2 a2065_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; - if (addr == CHIP_OFFSET || addr == CHIP_OFFSET + 2) { - chip_wput (addr, w); - } else { - a2065_bput2 (addr, w >> 8); - a2065_bput2 (addr + 1, w); - } + addr &= 65535; + if (addr == CHIP_OFFSET || addr == CHIP_OFFSET + 2) { + chip_wput (addr, w); + } else { + a2065_bput2 (addr, w >> 8); + a2065_bput2 (addr + 1, w); + } } static void REGPARAM2 a2065_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; - a2065_wput (addr, l >> 16); - a2065_wput (addr + 2, l); + addr &= 65535; + a2065_wput (addr, l >> 16); + a2065_wput (addr + 2, l); } static addrbank a2065_bank; @@ -724,95 +724,95 @@ static addrbank a2065_bank; static void REGPARAM2 a2065_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - b &= 0xff; - addr &= 65535; - if (addr == 0x48 && !configured) { - map_banks (&a2065_bank, b, 0x10000 >> 16, 0x10000); - write_log (L"A2065 Z2 autoconfigured at %02X0000\n", b); - configured = 1; - expamem_next (); - return; - } - if (addr == 0x4c && !configured) { - write_log (L"A2065 DMAC AUTOCONFIG SHUT-UP!\n"); - configured = 1; - expamem_next (); - return; - } - if (!configured) - return; - a2065_bput2 (addr, b); + b &= 0xff; + addr &= 65535; + if (addr == 0x48 && !configured) { + map_banks (&a2065_bank, b, 0x10000 >> 16, 0x10000); + write_log (L"A2065 Z2 autoconfigured at %02X0000\n", b); + configured = 1; + expamem_next (); + return; + } + if (addr == 0x4c && !configured) { + write_log (L"A2065 DMAC AUTOCONFIG SHUT-UP!\n"); + configured = 1; + expamem_next (); + return; + } + if (!configured) + return; + a2065_bput2 (addr, b); } static uae_u32 REGPARAM2 a2065_wgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - return v; + addr &= 65535; + return v; } static uae_u32 REGPARAM2 a2065_lgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = (a2065_wgeti (addr) << 16) | a2065_wgeti (addr + 2); - return v; + addr &= 65535; + v = (a2065_wgeti (addr) << 16) | a2065_wgeti (addr + 2); + return v; } static addrbank a2065_bank = { - a2065_lget, a2065_wget, a2065_bget, - a2065_lput, a2065_wput, a2065_bput, - default_xlate, default_check, NULL, L"A2065 Z2 Ethernet", - a2065_lgeti, a2065_wgeti, ABFLAG_IO + a2065_lget, a2065_wget, a2065_bget, + a2065_lput, a2065_wput, a2065_bput, + default_xlate, default_check, NULL, L"A2065 Z2 Ethernet", + a2065_lgeti, a2065_wgeti, ABFLAG_IO }; void a2065_init (void) { - memset (config, 0xff, sizeof config); - configured = 0; - ew (0x00, 0xc0 | 0x01); - // hardware id - ew (0x04, 0x70); - // manufacturer (Commodore) - ew (0x10, 0x02); - ew (0x14, 0x02); - - td = NULL; - if ((td = uaenet_enumerate (NULL, currprefs.a2065name))) { - memcpy (realmac, td->mac, sizeof realmac); - write_log (L"A2065: '%s' %02X:%02X:%02X:%02X:%02X:%02X\n", - td->name, td->mac[0], td->mac[1], td->mac[2], td->mac[3], td->mac[4], td->mac[5]); - } else { - realmac[0] = 0x00; - realmac[1] = 0x80; - realmac[2] = 0x10; - realmac[3] = 4; - realmac[4] = 3; - realmac[5] = 2; - write_log (L"A2065: Disconnected mode %02X:%02X:%02X:%02X:%02X:%02X\n", - realmac[0], realmac[1], realmac[2], realmac[3], realmac[4], realmac[5]); - } - - ew (0x18, realmac[2]); - ew (0x1c, realmac[3]); - ew (0x20, realmac[4]); - ew (0x24, realmac[5]); - - fakemac[0] = 0x00; - fakemac[1] = 0x80; - fakemac[2] = 0x10; - fakemac[3] = realmac[3]; - fakemac[4] = realmac[4]; - fakemac[5] = realmac[5]; - - /* KS autoconfig handles the rest */ - map_banks (&a2065_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); + memset (config, 0xff, sizeof config); + configured = 0; + ew (0x00, 0xc0 | 0x01); + // hardware id + ew (0x04, 0x70); + // manufacturer (Commodore) + ew (0x10, 0x02); + ew (0x14, 0x02); + + td = NULL; + if ((td = uaenet_enumerate (NULL, currprefs.a2065name))) { + memcpy (realmac, td->mac, sizeof realmac); + write_log (L"A2065: '%s' %02X:%02X:%02X:%02X:%02X:%02X\n", + td->name, td->mac[0], td->mac[1], td->mac[2], td->mac[3], td->mac[4], td->mac[5]); + } else { + realmac[0] = 0x00; + realmac[1] = 0x80; + realmac[2] = 0x10; + realmac[3] = 4; + realmac[4] = 3; + realmac[5] = 2; + write_log (L"A2065: Disconnected mode %02X:%02X:%02X:%02X:%02X:%02X\n", + realmac[0], realmac[1], realmac[2], realmac[3], realmac[4], realmac[5]); + } + + ew (0x18, realmac[2]); + ew (0x1c, realmac[3]); + ew (0x20, realmac[4]); + ew (0x24, realmac[5]); + + fakemac[0] = 0x00; + fakemac[1] = 0x80; + fakemac[2] = 0x10; + fakemac[3] = realmac[3]; + fakemac[4] = realmac[4]; + fakemac[5] = realmac[5]; + + /* KS autoconfig handles the rest */ + map_banks (&a2065_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); } diff --git a/a2091.c b/a2091.c index 81b08a62..6c21e51d 100644 --- a/a2091.c +++ b/a2091.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * A590/A2091/A3000/CDTV SCSI expansion (DMAC/SuperDMAC + WD33C93) emulation - * - * Copyright 2007 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* A590/A2091/A3000/CDTV SCSI expansion (DMAC/SuperDMAC + WD33C93) emulation +* +* Copyright 2007 Toni Wilen +* +*/ #define A2091_DEBUG 0 #define A3000_DEBUG 0 @@ -116,7 +116,7 @@ #define CSR_SELECT 0x11 #define CSR_SEL_XFER_DONE 0x16 #define CSR_XFER_DONE 0x18 - /* terminated interrupts */ +/* terminated interrupts */ #define CSR_INVALID 0x40 #define CSR_UNEXP_DISC 0x41 #define CSR_TIMEOUT 0x42 @@ -124,7 +124,7 @@ #define CSR_PARITY_ATN 0x44 #define CSR_BAD_STATUS 0x45 #define CSR_UNEXP 0x48 - /* service required interrupts */ +/* service required interrupts */ #define CSR_RESEL 0x80 #define CSR_RESEL_AM 0x81 #define CSR_DISC 0x85 @@ -166,541 +166,541 @@ uae_u8 wdregs[32]; static int isirq (void) { - if (superdmac) { - if ((dmac_cntr & SCNTR_INTEN) && (dmac_istr & (ISTR_INTS | ISTR_E_INT))) - return 1; - } else { - if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & (ISTR_INTS | ISTR_E_INT))) - return 1; - } - return 0; + if (superdmac) { + if ((dmac_cntr & SCNTR_INTEN) && (dmac_istr & (ISTR_INTS | ISTR_E_INT))) + return 1; + } else { + if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & (ISTR_INTS | ISTR_E_INT))) + return 1; + } + return 0; } void rethink_a2091 (void) { - if (currprefs.cs_cdtvscsi) - return; - if (isirq()) { - uae_int_requested |= 2; + if (currprefs.cs_cdtvscsi) + return; + if (isirq()) { + uae_int_requested |= 2; #if A2091_DEBUG > 2 || A3000_DEBUG > 2 - write_log (L"Interrupt_RETHINK\n"); + write_log (L"Interrupt_RETHINK\n"); #endif - } else { - uae_int_requested &= ~2; - } + } else { + uae_int_requested &= ~2; + } } static void INT2 (void) { - int irq = 0; - - if (currprefs.cs_cdtvscsi) - return; - if (!(auxstatus & 0x80)) - return; - dmac_istr |= ISTR_INTS; - if (isirq ()) - uae_int_requested |= 2; + int irq = 0; + + if (currprefs.cs_cdtvscsi) + return; + if (!(auxstatus & 0x80)) + return; + dmac_istr |= ISTR_INTS; + if (isirq ()) + uae_int_requested |= 2; } static void dmac_start_dma (void) { #if A3000_DEBUG > 0 || A2091_DEBUG > 0 - write_log (L"DMAC DMA started, ADDR=%08X, LEN=%08X words\n", dmac_acr, dmac_wtc); + write_log (L"DMAC DMA started, ADDR=%08X, LEN=%08X words\n", dmac_acr, dmac_wtc); #endif - dmac_dma = 1; + dmac_dma = 1; } static void dmac_stop_dma (void) { - dmac_dma = 0; - dmac_istr &= ~ISTR_E_INT; + dmac_dma = 0; + dmac_istr &= ~ISTR_E_INT; } static void dmac_reset (void) { #if WD33C93_DEBUG > 0 - if (superdmac) - write_log (L"A3000 %s SCSI reset\n", WD33C93); - else - write_log (L"A2091 %s SCSI reset\n", WD33C93); + if (superdmac) + write_log (L"A3000 %s SCSI reset\n", WD33C93); + else + write_log (L"A2091 %s SCSI reset\n", WD33C93); #endif } static void incsasr (int w) { - if (sasr == WD_AUXILIARY_STATUS || sasr == WD_DATA || sasr == WD_COMMAND) - return; - if (w && sasr == WD_SCSI_STATUS) - return; - sasr++; - sasr &= 0x1f; + if (sasr == WD_AUXILIARY_STATUS || sasr == WD_DATA || sasr == WD_COMMAND) + return; + if (w && sasr == WD_SCSI_STATUS) + return; + sasr++; + sasr &= 0x1f; } static void dmac_cint (void) { - dmac_istr = 0; - rethink_a2091(); + dmac_istr = 0; + rethink_a2091(); } static void doscsistatus (void) { - wdregs[WD_SCSI_STATUS] = scsidelay_status; - auxstatus |= 0x80; + wdregs[WD_SCSI_STATUS] = scsidelay_status; + auxstatus |= 0x80; #if WD33C93_DEBUG > 0 - write_log (L"%s STATUS=%02X\n", WD33C93, scsidelay_status); + write_log (L"%s STATUS=%02X\n", WD33C93, scsidelay_status); #endif - if (currprefs.cs_cdtvscsi) { - cdtv_scsi_int (); - return; - } - if (!currprefs.cs_a2091 && currprefs.cs_mbdmac != 1) - return; - INT2(); + if (currprefs.cs_cdtvscsi) { + cdtv_scsi_int (); + return; + } + if (!currprefs.cs_a2091 && currprefs.cs_mbdmac != 1) + return; + INT2(); #if A2091_DEBUG > 2 || A3000_DEBUG > 2 - write_log (L"Interrupt\n"); + write_log (L"Interrupt\n"); #endif } void scsi_hsync (void) { - if (scsidelay_irq == 1) { - scsidelay_irq = 0; - doscsistatus(); - return; - } - if (scsidelay_irq > 1) - scsidelay_irq--; + if (scsidelay_irq == 1) { + scsidelay_irq = 0; + doscsistatus(); + return; + } + if (scsidelay_irq > 1) + scsidelay_irq--; } static void set_status (uae_u8 status, int quick) { - scsidelay_irq = quick <= 2 ? 2 : quick; - scsidelay_status = status; + scsidelay_irq = quick <= 2 ? 2 : quick; + scsidelay_status = status; } static TCHAR *scsitostring (void) { - static TCHAR buf[200]; - TCHAR *p; - int i; - - p = buf; - p[0] = 0; - for (i = 0; i < wd_tc && i < sizeof wd_data; i++) { - if (i > 0) { - _tcscat (p, L"."); - p++; + static TCHAR buf[200]; + TCHAR *p; + int i; + + p = buf; + p[0] = 0; + for (i = 0; i < wd_tc && i < sizeof wd_data; i++) { + if (i > 0) { + _tcscat (p, L"."); + p++; + } + _stprintf (p, L"%02X", wd_data[i]); + p += _tcslen (p); } - _stprintf (p, L"%02X", wd_data[i]); - p += _tcslen (p); - } - return buf; + return buf; } static void wd_cmd_sel_xfer (void) { - int phase = wdregs[WD_COMMAND_PHASE]; + int phase = wdregs[WD_COMMAND_PHASE]; #if WD33C93_DEBUG > 0 - write_log (L"* %s select and transfer, ID=%d phase=%02X\n", WD33C93, wdregs[WD_DESTINATION_ID] & 0x7, phase); + write_log (L"* %s select and transfer, ID=%d phase=%02X\n", WD33C93, wdregs[WD_DESTINATION_ID] & 0x7, phase); #endif - if (!SCSIID) { - set_status (CSR_TIMEOUT, 0); - return; - } - SCSIID->buffer[0] = 0; - if (phase >= 0x46) { - phase = 0x50; - wdregs[WD_TARGET_LUN] = SCSIID->status; - SCSIID->buffer[0] = SCSIID->status; - } - wdregs[WD_COMMAND_PHASE] = phase; - wd_phase = CSR_XFER_DONE | PHS_MESS_IN; - set_status (wd_phase, 1); + if (!SCSIID) { + set_status (CSR_TIMEOUT, 0); + return; + } + SCSIID->buffer[0] = 0; + if (phase >= 0x46) { + phase = 0x50; + wdregs[WD_TARGET_LUN] = SCSIID->status; + SCSIID->buffer[0] = SCSIID->status; + } + wdregs[WD_COMMAND_PHASE] = phase; + wd_phase = CSR_XFER_DONE | PHS_MESS_IN; + set_status (wd_phase, 1); } static void dmacheck (void) { - dmac_acr++; - if (old_dmac && (dmac_cntr & CNTR_TCEN)) { - if (dmac_wtc == 0) - dmac_istr |= ISTR_E_INT; - else - dmac_wtc--; - } + dmac_acr++; + if (old_dmac && (dmac_cntr & CNTR_TCEN)) { + if (dmac_wtc == 0) + dmac_istr |= ISTR_E_INT; + else + dmac_wtc--; + } } static void do_dma (void) { - if (currprefs.cs_cdtvscsi) - cdtv_getdmadata (&dmac_acr); - if (SCSIID->direction == 0) { - write_log (L"%s DMA but no data!?\n", WD33C93); - } else if (SCSIID->direction < 0) { - for (;;) { - uae_u8 v; - int status = scsi_receive_data (SCSIID, &v); - put_byte (dmac_acr, v); - if (wd_dataoffset < sizeof wd_data) - wd_data[wd_dataoffset++] = v; - dmacheck (); - if (status) - break; - } - } else if (SCSIID->direction > 0) { - for (;;) { - int status; - uae_u8 v = get_byte (dmac_acr); - if (wd_dataoffset < sizeof wd_data) - wd_data[wd_dataoffset++] = v; - status = scsi_send_data (SCSIID, v); - dmacheck (); - if (status) - break; + if (currprefs.cs_cdtvscsi) + cdtv_getdmadata (&dmac_acr); + if (SCSIID->direction == 0) { + write_log (L"%s DMA but no data!?\n", WD33C93); + } else if (SCSIID->direction < 0) { + for (;;) { + uae_u8 v; + int status = scsi_receive_data (SCSIID, &v); + put_byte (dmac_acr, v); + if (wd_dataoffset < sizeof wd_data) + wd_data[wd_dataoffset++] = v; + dmacheck (); + if (status) + break; + } + } else if (SCSIID->direction > 0) { + for (;;) { + int status; + uae_u8 v = get_byte (dmac_acr); + if (wd_dataoffset < sizeof wd_data) + wd_data[wd_dataoffset++] = v; + status = scsi_send_data (SCSIID, v); + dmacheck (); + if (status) + break; + } } - } } static void wd_do_transfer_out (void) { #if WD33C93_DEBUG > 0 - write_log (L"%s SCSI O [%02X] %d/%d %s\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_dataoffset, wd_tc, scsitostring ()); + write_log (L"%s SCSI O [%02X] %d/%d %s\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_dataoffset, wd_tc, scsitostring ()); #endif - if (wdregs[WD_COMMAND_PHASE] == 0x11) { - wdregs[WD_COMMAND_PHASE] = 0x20; - wd_phase = CSR_XFER_DONE | PHS_COMMAND; - } else if (wdregs[WD_COMMAND_PHASE] == 0x30) { - /* command was sent */ - SCSIID->direction = scsi_data_dir (SCSIID); - if (SCSIID->direction > 0) { - /* if write command, need to wait for data */ - wd_phase = CSR_XFER_DONE | PHS_DATA_OUT; - wdregs[WD_COMMAND_PHASE] = 0x46; - } else { - scsi_emulate_cmd (SCSIID); - if (SCSIID->data_len <= 0 || SCSIID->status != 0 || SCSIID->direction == 0) { - wd_phase = CSR_XFER_DONE | PHS_STATUS; + if (wdregs[WD_COMMAND_PHASE] == 0x11) { + wdregs[WD_COMMAND_PHASE] = 0x20; + wd_phase = CSR_XFER_DONE | PHS_COMMAND; + } else if (wdregs[WD_COMMAND_PHASE] == 0x30) { + /* command was sent */ + SCSIID->direction = scsi_data_dir (SCSIID); + if (SCSIID->direction > 0) { + /* if write command, need to wait for data */ + wd_phase = CSR_XFER_DONE | PHS_DATA_OUT; + wdregs[WD_COMMAND_PHASE] = 0x46; + } else { + scsi_emulate_cmd (SCSIID); + if (SCSIID->data_len <= 0 || SCSIID->status != 0 || SCSIID->direction == 0) { + wd_phase = CSR_XFER_DONE | PHS_STATUS; + wdregs[WD_COMMAND_PHASE] = 0x47; + } else { + wd_phase = CSR_XFER_DONE | PHS_DATA_IN; + wdregs[WD_COMMAND_PHASE] = 0x3f; + } + } + } else if (wdregs[WD_COMMAND_PHASE] == 0x46) { + if (SCSIID->direction > 0) { + /* data was sent */ + scsi_emulate_cmd (SCSIID); + wd_phase = CSR_XFER_DONE | PHS_STATUS; + } wdregs[WD_COMMAND_PHASE] = 0x47; - } else { - wd_phase = CSR_XFER_DONE | PHS_DATA_IN; - wdregs[WD_COMMAND_PHASE] = 0x3f; - } } - } else if (wdregs[WD_COMMAND_PHASE] == 0x46) { - if (SCSIID->direction > 0) { - /* data was sent */ - scsi_emulate_cmd (SCSIID); - wd_phase = CSR_XFER_DONE | PHS_STATUS; - } - wdregs[WD_COMMAND_PHASE] = 0x47; - } - wd_dataoffset = 0; - set_status (wd_phase, SCSIID->direction ? 0 : 1); - wd_busy = 0; + wd_dataoffset = 0; + set_status (wd_phase, SCSIID->direction ? 0 : 1); + wd_busy = 0; } static void wd_do_transfer_in (void) { #if WD33C93_DEBUG > 0 - write_log (L"%s SCSI I [%02X] %d/%d %s\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_dataoffset, wd_tc, scsitostring ()); + write_log (L"%s SCSI I [%02X] %d/%d %s\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_dataoffset, wd_tc, scsitostring ()); #endif - wd_dataoffset = 0; - if (wdregs[WD_COMMAND_PHASE] >= 0x36 && wdregs[WD_COMMAND_PHASE] < 0x47) { - wdregs[WD_COMMAND_PHASE] = 0x47; - wd_phase = CSR_XFER_DONE | PHS_STATUS; - } else if (wdregs[WD_COMMAND_PHASE] == 0x47) { - wdregs[WD_COMMAND_PHASE] = 0x50; - wd_phase = CSR_XFER_DONE | PHS_MESS_IN; - } else if (wdregs[WD_COMMAND_PHASE] == 0x50) { - wdregs[WD_COMMAND_PHASE] = 0x60; - wd_phase = CSR_DISC; - } - set_status (wd_phase, 1); - wd_busy = 0; - SCSIID->direction = 0; + wd_dataoffset = 0; + if (wdregs[WD_COMMAND_PHASE] >= 0x36 && wdregs[WD_COMMAND_PHASE] < 0x47) { + wdregs[WD_COMMAND_PHASE] = 0x47; + wd_phase = CSR_XFER_DONE | PHS_STATUS; + } else if (wdregs[WD_COMMAND_PHASE] == 0x47) { + wdregs[WD_COMMAND_PHASE] = 0x50; + wd_phase = CSR_XFER_DONE | PHS_MESS_IN; + } else if (wdregs[WD_COMMAND_PHASE] == 0x50) { + wdregs[WD_COMMAND_PHASE] = 0x60; + wd_phase = CSR_DISC; + } + set_status (wd_phase, 1); + wd_busy = 0; + SCSIID->direction = 0; } static void wd_cmd_sel_xfer_atn (void) { - int i, tmp_tc; + int i, tmp_tc; - tmp_tc = wdregs[WD_TRANSFER_COUNT_LSB] | (wdregs[WD_TRANSFER_COUNT] << 8) | (wdregs[WD_TRANSFER_COUNT_MSB] << 16); + tmp_tc = wdregs[WD_TRANSFER_COUNT_LSB] | (wdregs[WD_TRANSFER_COUNT] << 8) | (wdregs[WD_TRANSFER_COUNT_MSB] << 16); #if WD33C93_DEBUG > 0 - write_log (L"* %s select and transfer with atn, ID=%d PHASE=%02X TC=%d\n", - WD33C93, wdregs[WD_DESTINATION_ID] & 0x7, wdregs[WD_COMMAND_PHASE], tmp_tc); + write_log (L"* %s select and transfer with atn, ID=%d PHASE=%02X TC=%d\n", + WD33C93, wdregs[WD_DESTINATION_ID] & 0x7, wdregs[WD_COMMAND_PHASE], tmp_tc); #endif - if (wdregs[WD_COMMAND] & 0x80) - wd_tc = 1; - if (!SCSIID) { - set_status (CSR_TIMEOUT, 0); - return; - } - SCSIID->buffer[0] = 0; - SCSIID->direction = 0; - if (wdregs[WD_COMMAND_PHASE] <= 0x30) { - wd_tc = 6; - wd_dataoffset = 0; - scsi_start_transfer (SCSIID, 6); - for (i = 0; i < wd_tc; i++) { - uae_u8 b = wdregs[3 + i]; - wd_data[i] = b; - scsi_send_data (SCSIID, b); - wd_dataoffset++; - } - // command - SCSIID->direction = (wdregs[WD_SOURCE_ID] & 0x20) ? 1 : -1; - wdregs[WD_COMMAND_PHASE] = 0x30; - wd_do_transfer_out (); - wdregs[WD_COMMAND_PHASE] = 0x36; - } - if (wdregs[WD_COMMAND_PHASE] <= 0x41) { - wd_tc = tmp_tc; - wd_dataoffset = 0; - wdregs[WD_COMMAND_PHASE] = 0x45; - if (wd_tc == 0) { - if (SCSIID->direction != 0 && SCSIID->status == 0) { - wd_phase = CSR_UNEXP; - if (SCSIID->direction < 0) - wd_phase |= PHS_DATA_IN; - else - wd_phase |= PHS_DATA_OUT; - set_status (wd_phase, 1); + if (wdregs[WD_COMMAND] & 0x80) + wd_tc = 1; + if (!SCSIID) { + set_status (CSR_TIMEOUT, 0); return; - } } - if ((wdregs[WD_CONTROL] >> 5) == 4) { - if (wd_phase == (CSR_XFER_DONE | PHS_DATA_IN)) - do_dma (); - else if(wd_phase == (CSR_XFER_DONE | PHS_DATA_OUT)) - do_dma (); + SCSIID->buffer[0] = 0; + SCSIID->direction = 0; + if (wdregs[WD_COMMAND_PHASE] <= 0x30) { + wd_tc = 6; + wd_dataoffset = 0; + scsi_start_transfer (SCSIID, 6); + for (i = 0; i < wd_tc; i++) { + uae_u8 b = wdregs[3 + i]; + wd_data[i] = b; + scsi_send_data (SCSIID, b); + wd_dataoffset++; + } + // command + SCSIID->direction = (wdregs[WD_SOURCE_ID] & 0x20) ? 1 : -1; + wdregs[WD_COMMAND_PHASE] = 0x30; + wd_do_transfer_out (); + wdregs[WD_COMMAND_PHASE] = 0x36; } + if (wdregs[WD_COMMAND_PHASE] <= 0x41) { + wd_tc = tmp_tc; + wd_dataoffset = 0; + wdregs[WD_COMMAND_PHASE] = 0x45; + if (wd_tc == 0) { + if (SCSIID->direction != 0 && SCSIID->status == 0) { + wd_phase = CSR_UNEXP; + if (SCSIID->direction < 0) + wd_phase |= PHS_DATA_IN; + else + wd_phase |= PHS_DATA_OUT; + set_status (wd_phase, 1); + return; + } + } + if ((wdregs[WD_CONTROL] >> 5) == 4) { + if (wd_phase == (CSR_XFER_DONE | PHS_DATA_IN)) + do_dma (); + else if(wd_phase == (CSR_XFER_DONE | PHS_DATA_OUT)) + do_dma (); + } - } - wdregs[WD_COMMAND_PHASE] = 0x60; - wdregs[WD_TARGET_LUN] = SCSIID->status; - SCSIID->buffer[0] = SCSIID->status; - wd_phase = CSR_SEL_XFER_DONE; - set_status (wd_phase, 0); + } + wdregs[WD_COMMAND_PHASE] = 0x60; + wdregs[WD_TARGET_LUN] = SCSIID->status; + SCSIID->buffer[0] = SCSIID->status; + wd_phase = CSR_SEL_XFER_DONE; + set_status (wd_phase, 0); } static void wd_cmd_trans_info (void) { - if (wdregs[WD_COMMAND_PHASE] == 0x47) - SCSIID->buffer[0] = SCSIID->status; - if (wdregs[WD_COMMAND_PHASE] == 0x20) - wdregs[WD_COMMAND_PHASE] = 0x30; - wd_busy = 1; - wd_tc = wdregs[WD_TRANSFER_COUNT_LSB] | (wdregs[WD_TRANSFER_COUNT] << 8) | (wdregs[WD_TRANSFER_COUNT_MSB] << 16); - if (wdregs[WD_COMMAND] & 0x80) - wd_tc = 1; - wd_dataoffset = 0; + if (wdregs[WD_COMMAND_PHASE] == 0x47) + SCSIID->buffer[0] = SCSIID->status; + if (wdregs[WD_COMMAND_PHASE] == 0x20) + wdregs[WD_COMMAND_PHASE] = 0x30; + wd_busy = 1; + wd_tc = wdregs[WD_TRANSFER_COUNT_LSB] | (wdregs[WD_TRANSFER_COUNT] << 8) | (wdregs[WD_TRANSFER_COUNT_MSB] << 16); + if (wdregs[WD_COMMAND] & 0x80) + wd_tc = 1; + wd_dataoffset = 0; #if WD33C93_DEBUG > 0 - write_log (L"* %s transfer info phase=%02x len=%d dma=%d\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_tc, wdregs[WD_CONTROL] >> 5); + write_log (L"* %s transfer info phase=%02x len=%d dma=%d\n", WD33C93, wdregs[WD_COMMAND_PHASE], wd_tc, wdregs[WD_CONTROL] >> 5); #endif - scsi_start_transfer (SCSIID, wd_tc); - if (wdregs[WD_COMMAND_PHASE] >= 0x36 && wdregs[WD_COMMAND_PHASE] <= 0x3f) - wdregs[WD_COMMAND_PHASE] = 0x45; - if ((wdregs[WD_CONTROL] >> 5) == 4) { - do_dma (); - if (SCSIID->direction < 0) - wd_do_transfer_in (); - else if (SCSIID->direction > 0) - wd_do_transfer_out (); - SCSIID->direction = 0; - dmac_dma = 0; - } + scsi_start_transfer (SCSIID, wd_tc); + if (wdregs[WD_COMMAND_PHASE] >= 0x36 && wdregs[WD_COMMAND_PHASE] <= 0x3f) + wdregs[WD_COMMAND_PHASE] = 0x45; + if ((wdregs[WD_CONTROL] >> 5) == 4) { + do_dma (); + if (SCSIID->direction < 0) + wd_do_transfer_in (); + else if (SCSIID->direction > 0) + wd_do_transfer_out (); + SCSIID->direction = 0; + dmac_dma = 0; + } } static void wd_cmd_sel_atn (void) { #if WD33C93_DEBUG > 0 - write_log (L"* %s select with atn, ID=%d\n", WD33C93, wdregs[WD_DESTINATION_ID] & 0x7); + write_log (L"* %s select with atn, ID=%d\n", WD33C93, wdregs[WD_DESTINATION_ID] & 0x7); #endif - wd_phase = 0; - wdregs[WD_COMMAND_PHASE] = 0; - if (SCSIID) { - wd_phase = CSR_SELECT; - set_status (wd_phase, 1); - wdregs[WD_COMMAND_PHASE] = 0x10; - return; - } - set_status (CSR_TIMEOUT, 1000); + wd_phase = 0; + wdregs[WD_COMMAND_PHASE] = 0; + if (SCSIID) { + wd_phase = CSR_SELECT; + set_status (wd_phase, 1); + wdregs[WD_COMMAND_PHASE] = 0x10; + return; + } + set_status (CSR_TIMEOUT, 1000); } static void wd_cmd_reset (void) { - int i; + int i; #if WD33C93_DEBUG > 0 - write_log (L"%s reset\n", WD33C93); + write_log (L"%s reset\n", WD33C93); #endif - for (i = 1; i < 0x16; i++) - wdregs[i] = 0; - wdregs[0x18] = 0; - if (!wd33c93a) - wdregs[0] &= ~(0x08 | 0x10); - set_status ((wdregs[0] & 0x10) ? 1 : 0, 1); + for (i = 1; i < 0x16; i++) + wdregs[i] = 0; + wdregs[0x18] = 0; + if (!wd33c93a) + wdregs[0] &= ~(0x08 | 0x10); + set_status ((wdregs[0] & 0x10) ? 1 : 0, 1); } static void wd_cmd_abort (void) { #if WD33C93_DEBUG > 0 - write_log (L"%s abort\n", WD33C93); + write_log (L"%s abort\n", WD33C93); #endif - set_status (CSR_SEL_ABORT, 0); + set_status (CSR_SEL_ABORT, 0); } static int writeonlyreg (int reg) { - if (reg == WD_SCSI_STATUS) - return 1; - return 0; + if (reg == WD_SCSI_STATUS) + return 1; + return 0; } void wdscsi_put (uae_u8 d) { #if WD33C93_DEBUG > 1 - if (WD33C93_DEBUG > 3 || sasr != WD_DATA) - write_log (L"W %s REG %02X (%d) = %02X (%d) PC=%08X\n", WD33C93, sasr, sasr, d, d, M68K_GETPC); + if (WD33C93_DEBUG > 3 || sasr != WD_DATA) + write_log (L"W %s REG %02X (%d) = %02X (%d) PC=%08X\n", WD33C93, sasr, sasr, d, d, M68K_GETPC); #endif - if (!writeonlyreg (sasr)) - wdregs[sasr] = d; - if (!wd_used) { - wd_used = 1; - write_log (L"%s in use\n", WD33C93); - } - if (sasr == WD_COMMAND_PHASE) { + if (!writeonlyreg (sasr)) + wdregs[sasr] = d; + if (!wd_used) { + wd_used = 1; + write_log (L"%s in use\n", WD33C93); + } + if (sasr == WD_COMMAND_PHASE) { #if WD33C93_DEBUG > 0 - write_log (L"%s PHASE=%02X\n", WD33C93, d); + write_log (L"%s PHASE=%02X\n", WD33C93, d); #endif - } else if (sasr == WD_DATA) { - if (wd_dataoffset < sizeof wd_data) - wd_data[wd_dataoffset] = wdregs[sasr]; - wd_dataoffset++; - if (scsi_send_data (SCSIID, wdregs[sasr])) - wd_do_transfer_out (); - } else if (sasr == WD_COMMAND) { - switch (d & 0x7f) - { - case WD_CMD_RESET: - wd_cmd_reset (); - break; - break; - case WD_CMD_SEL_ATN: - wd_cmd_sel_atn (); - break; - case WD_CMD_SEL_ATN_XFER: - wd_cmd_sel_xfer_atn (); - break; - case WD_CMD_SEL_XFER: - wd_cmd_sel_xfer (); - break; - case WD_CMD_TRANS_INFO: - wd_cmd_trans_info (); - break; - default: - write_log (L"%s unimplemented/unknown command %02X\n", WD33C93, d); - break; + } else if (sasr == WD_DATA) { + if (wd_dataoffset < sizeof wd_data) + wd_data[wd_dataoffset] = wdregs[sasr]; + wd_dataoffset++; + if (scsi_send_data (SCSIID, wdregs[sasr])) + wd_do_transfer_out (); + } else if (sasr == WD_COMMAND) { + switch (d & 0x7f) + { + case WD_CMD_RESET: + wd_cmd_reset (); + break; + break; + case WD_CMD_SEL_ATN: + wd_cmd_sel_atn (); + break; + case WD_CMD_SEL_ATN_XFER: + wd_cmd_sel_xfer_atn (); + break; + case WD_CMD_SEL_XFER: + wd_cmd_sel_xfer (); + break; + case WD_CMD_TRANS_INFO: + wd_cmd_trans_info (); + break; + default: + write_log (L"%s unimplemented/unknown command %02X\n", WD33C93, d); + break; + } } - } - incsasr(1); + incsasr(1); } void wdscsi_sasr (uae_u8 b) { - sasr = b; + sasr = b; } uae_u8 wdscsi_getauxstatus (void) { - return (auxstatus & 0x80) | (wd_busy ? 0x20 : 0) | (wd_busy ? 0x01 : 0); + return (auxstatus & 0x80) | (wd_busy ? 0x20 : 0) | (wd_busy ? 0x01 : 0); } uae_u8 wdscsi_get (void) { - uae_u8 v, osasr = sasr; - - v = wdregs[sasr]; - if (sasr == WD_DATA) { - int status = scsi_receive_data (SCSIID, &v); - if (wd_dataoffset < sizeof wd_data) - wd_data[wd_dataoffset] = v; - wd_dataoffset++; - wdregs[sasr] = v; - if (status) - wd_do_transfer_in (); - } else if (sasr == WD_SCSI_STATUS) { - uae_int_requested &= ~2; - auxstatus &= ~0x80; - cdtv_scsi_clear_int (); - dmac_istr &= ~ISTR_INTS; - if (wdregs[WD_COMMAND_PHASE] == 0x10) { - wdregs[WD_COMMAND_PHASE] = 0x11; - wd_phase = CSR_SRV_REQ | PHS_MESS_OUT; - set_status (wd_phase, 1); + uae_u8 v, osasr = sasr; + + v = wdregs[sasr]; + if (sasr == WD_DATA) { + int status = scsi_receive_data (SCSIID, &v); + if (wd_dataoffset < sizeof wd_data) + wd_data[wd_dataoffset] = v; + wd_dataoffset++; + wdregs[sasr] = v; + if (status) + wd_do_transfer_in (); + } else if (sasr == WD_SCSI_STATUS) { + uae_int_requested &= ~2; + auxstatus &= ~0x80; + cdtv_scsi_clear_int (); + dmac_istr &= ~ISTR_INTS; + if (wdregs[WD_COMMAND_PHASE] == 0x10) { + wdregs[WD_COMMAND_PHASE] = 0x11; + wd_phase = CSR_SRV_REQ | PHS_MESS_OUT; + set_status (wd_phase, 1); + } } - } - incsasr (0); + incsasr (0); #if WD33C93_DEBUG > 1 - if (WD33C93_DEBUG > 3 || osasr != WD_DATA) - write_log (L"R %s REG %02X (%d) = %02X (%d) PC=%08X\n", WD33C93, osasr, osasr, v, v, M68K_GETPC); + if (WD33C93_DEBUG > 3 || osasr != WD_DATA) + write_log (L"R %s REG %02X (%d) = %02X (%d) PC=%08X\n", WD33C93, osasr, osasr, v, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 dmac_bget2 (uaecptr addr) { - uae_u32 v = 0; - - if (addr < 0x40) - return dmacmemory[addr]; - if (addr >= ROM_OFFSET) { - if (rom) { - int off = addr & rom_mask; - if (rombankswitcher && (addr & 0xffe0) == ROM_OFFSET) - rombank = (addr & 0x02) >> 1; - off += rombank * rom_size; - return rom[off]; + uae_u32 v = 0; + + if (addr < 0x40) + return dmacmemory[addr]; + if (addr >= ROM_OFFSET) { + if (rom) { + int off = addr & rom_mask; + if (rombankswitcher && (addr & 0xffe0) == ROM_OFFSET) + rombank = (addr & 0x02) >> 1; + off += rombank * rom_size; + return rom[off]; + } + return 0; } - return 0; - } - switch (addr) - { + switch (addr) + { case 0x41: - v = dmac_istr; - if (v) - v |= ISTR_INT_P; - dmac_istr &= ~0xf; - break; + v = dmac_istr; + if (v) + v |= ISTR_INT_P; + dmac_istr &= ~0xf; + break; case 0x43: - v = dmac_cntr; - break; + v = dmac_cntr; + break; case 0x80: - if (old_dmac) - v = (dmac_wtc >> 24) & 0xff; - break; + if (old_dmac) + v = (dmac_wtc >> 24) & 0xff; + break; case 0x81: - if (old_dmac) - v = (dmac_wtc >> 16) & 0xff; - break; + if (old_dmac) + v = (dmac_wtc >> 16) & 0xff; + break; case 0x82: - if (old_dmac) - v = (dmac_wtc >> 8) & 0xff; - break; + if (old_dmac) + v = (dmac_wtc >> 8) & 0xff; + break; case 0x83: - if (old_dmac) - v = (dmac_wtc >> 0) & 0xff; - break; + if (old_dmac) + v = (dmac_wtc >> 0) & 0xff; + break; case 0x91: - v = wdscsi_getauxstatus (); - break; + v = wdscsi_getauxstatus (); + break; case 0x93: - v = wdscsi_get (); - break; + v = wdscsi_get (); + break; case 0xc1: - v = 0xf8 | (1 << 0) | (1 << 1) | (1 << 2); // bits 0-2 = dip-switches - break; - /* XT IO */ + v = 0xf8 | (1 << 0) | (1 << 1) | (1 << 2); // bits 0-2 = dip-switches + break; + /* XT IO */ case 0xa1: case 0xa3: case 0xa5: @@ -708,118 +708,118 @@ static uae_u32 dmac_bget2 (uaecptr addr) case 0xc3: case 0xc5: case 0xc7: - v = 0xff; - break; + v = 0xff; + break; case 0xe0: case 0xe1: - if (!dmac_dma) - dmac_start_dma (); - break; + if (!dmac_dma) + dmac_start_dma (); + break; case 0xe2: case 0xe3: - dmac_stop_dma (); - break; + dmac_stop_dma (); + break; case 0xe4: case 0xe5: - dmac_cint (); - break; + dmac_cint (); + break; case 0xe8: case 0xe9: - /* FLUSH (new only) */ - if (!old_dmac && dmac_dma) - dmac_istr |= ISTR_FE_FLG; - break; - } + /* FLUSH (new only) */ + if (!old_dmac && dmac_dma) + dmac_istr |= ISTR_FE_FLG; + break; + } #if A2091_DEBUG > 0 - write_log (L"dmac_bget %04X=%02X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"dmac_bget %04X=%02X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static void dmac_bput2 (uaecptr addr, uae_u32 b) { - if (addr < 0x40) - return; - if (addr >= ROM_OFFSET) - return; + if (addr < 0x40) + return; + if (addr >= ROM_OFFSET) + return; - switch (addr) - { + switch (addr) + { case 0x43: - dmac_cntr = b; - if (dmac_cntr & CNTR_PREST) - dmac_reset (); - break; + dmac_cntr = b; + if (dmac_cntr & CNTR_PREST) + dmac_reset (); + break; case 0x80: - dmac_wtc &= 0x00ffffff; - dmac_wtc |= b << 24; - break; + dmac_wtc &= 0x00ffffff; + dmac_wtc |= b << 24; + break; case 0x81: - dmac_wtc &= 0xff00ffff; - dmac_wtc |= b << 16; - break; + dmac_wtc &= 0xff00ffff; + dmac_wtc |= b << 16; + break; case 0x82: - dmac_wtc &= 0xffff00ff; - dmac_wtc |= b << 8; - break; + dmac_wtc &= 0xffff00ff; + dmac_wtc |= b << 8; + break; case 0x83: - dmac_wtc &= 0xffffff00; - dmac_wtc |= b << 0; - break; + dmac_wtc &= 0xffffff00; + dmac_wtc |= b << 0; + break; case 0x84: - dmac_acr &= 0x00ffffff; - dmac_acr |= b << 24; - break; + dmac_acr &= 0x00ffffff; + dmac_acr |= b << 24; + break; case 0x85: - dmac_acr &= 0xff00ffff; - dmac_acr |= b << 16; - break; + dmac_acr &= 0xff00ffff; + dmac_acr |= b << 16; + break; case 0x86: - dmac_acr &= 0xffff00ff; - dmac_acr |= b << 8; - break; + dmac_acr &= 0xffff00ff; + dmac_acr |= b << 8; + break; case 0x87: - dmac_acr &= 0xffffff00; - dmac_acr |= b << 0; - dmac_acr &= ~1; - if (old_dmac) - dmac_acr &= ~3; - break; + dmac_acr &= 0xffffff00; + dmac_acr |= b << 0; + dmac_acr &= ~1; + if (old_dmac) + dmac_acr &= ~3; + break; case 0x8e: - dmac_dawr &= 0x00ff; - dmac_dawr |= b << 8; - break; + dmac_dawr &= 0x00ff; + dmac_dawr |= b << 8; + break; case 0x8f: - dmac_dawr &= 0xff00; - dmac_dawr |= b << 0; - break; + dmac_dawr &= 0xff00; + dmac_dawr |= b << 0; + break; case 0x91: - wdscsi_sasr (b); - break; + wdscsi_sasr (b); + break; case 0x93: - wdscsi_put (b); - break; + wdscsi_put (b); + break; case 0xe0: case 0xe1: - if (!dmac_dma) - dmac_start_dma (); - break; + if (!dmac_dma) + dmac_start_dma (); + break; case 0xe2: case 0xe3: - dmac_stop_dma (); - break; + dmac_stop_dma (); + break; case 0xe4: case 0xe5: - dmac_cint (); - break; + dmac_cint (); + break; case 0xe8: case 0xe9: - /* FLUSH */ - dmac_istr |= ISTR_FE_FLG; - break; - } + /* FLUSH */ + dmac_istr |= ISTR_FE_FLG; + break; + } #if A2091_DEBUG > 0 - write_log (L"dmac_bput %04X=%02X PC=%08X\n", addr, b & 255, M68K_GETPC); + write_log (L"dmac_bput %04X=%02X PC=%08X\n", addr, b & 255, M68K_GETPC); #endif } @@ -827,283 +827,283 @@ static void dmac_bput2 (uaecptr addr, uae_u32 b) static uae_u32 REGPARAM2 dmac_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = dmac_bget2 (addr) << 24; - v |= dmac_bget2 (addr + 1) << 16; - v |= dmac_bget2 (addr + 2) << 8; - v |= dmac_bget2 (addr + 3); + addr &= 65535; + v = dmac_bget2 (addr) << 24; + v |= dmac_bget2 (addr + 1) << 16; + v |= dmac_bget2 (addr + 2) << 8; + v |= dmac_bget2 (addr + 3); #ifdef A2091_DEBUG - if (addr >= 0x40 && addr < ROM_OFFSET) - write_log (L"dmac_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); + if (addr >= 0x40 && addr < ROM_OFFSET) + write_log (L"dmac_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 dmac_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = dmac_bget2 (addr) << 8; - v |= dmac_bget2 (addr + 1); + addr &= 65535; + v = dmac_bget2 (addr) << 8; + v |= dmac_bget2 (addr + 1); #if A2091_DEBUG > 0 - if (addr >= 0x40 && addr < ROM_OFFSET) - write_log (L"dmac_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); + if (addr >= 0x40 && addr < ROM_OFFSET) + write_log (L"dmac_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 dmac_bget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = dmac_bget2 (addr); - if (!configured) + addr &= 65535; + v = dmac_bget2 (addr); + if (!configured) + return v; return v; - return v; } static void REGPARAM2 dmac_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; + addr &= 65535; #if A2091_DEBUG > 0 - if (addr >= 0x40 && addr < ROM_OFFSET) - write_log (L"dmac_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); + if (addr >= 0x40 && addr < ROM_OFFSET) + write_log (L"dmac_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); #endif - dmac_bput2 (addr, l >> 24); - dmac_bput2 (addr + 1, l >> 16); - dmac_bput2 (addr + 2, l >> 8); - dmac_bput2 (addr + 3, l); + dmac_bput2 (addr, l >> 24); + dmac_bput2 (addr + 1, l >> 16); + dmac_bput2 (addr + 2, l >> 8); + dmac_bput2 (addr + 3, l); } static void REGPARAM2 dmac_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; + addr &= 65535; #if A2091_DEBUG > 0 - if (addr >= 0x40 && addr < ROM_OFFSET) - write_log (L"dmac_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); + if (addr >= 0x40 && addr < ROM_OFFSET) + write_log (L"dmac_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); #endif - dmac_bput2 (addr, w >> 8); - dmac_bput2 (addr + 1, w); + dmac_bput2 (addr, w >> 8); + dmac_bput2 (addr + 1, w); } static void REGPARAM2 dmac_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - b &= 0xff; - addr &= 65535; - if (addr == 0x48 && !configured) { - map_banks (&dmaca2091_bank, b, 0x10000 >> 16, 0x10000); - write_log (L"A590/A2091 Z2 autoconfigured at %02X0000\n", b); - configured = 1; - expamem_next (); - return; - } - if (addr == 0x4c && !configured) { - write_log (L"A590/A2091 DMAC AUTOCONFIG SHUT-UP!\n"); - configured = 1; - expamem_next (); - return; - } - if (!configured) - return; - dmac_bput2 (addr, b); + b &= 0xff; + addr &= 65535; + if (addr == 0x48 && !configured) { + map_banks (&dmaca2091_bank, b, 0x10000 >> 16, 0x10000); + write_log (L"A590/A2091 Z2 autoconfigured at %02X0000\n", b); + configured = 1; + expamem_next (); + return; + } + if (addr == 0x4c && !configured) { + write_log (L"A590/A2091 DMAC AUTOCONFIG SHUT-UP!\n"); + configured = 1; + expamem_next (); + return; + } + if (!configured) + return; + dmac_bput2 (addr, b); } static uae_u32 REGPARAM2 dmac_wgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - if (addr >= ROM_OFFSET) - v = (rom[addr & rom_mask] << 8) | rom[(addr + 1) & rom_mask]; - return v; + addr &= 65535; + if (addr >= ROM_OFFSET) + v = (rom[addr & rom_mask] << 8) | rom[(addr + 1) & rom_mask]; + return v; } static uae_u32 REGPARAM2 dmac_lgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = (dmac_wgeti(addr) << 16) | dmac_wgeti(addr + 2); - return v; + addr &= 65535; + v = (dmac_wgeti(addr) << 16) | dmac_wgeti(addr + 2); + return v; } addrbank dmaca2091_bank = { - dmac_lget, dmac_wget, dmac_bget, - dmac_lput, dmac_wput, dmac_bput, - default_xlate, default_check, NULL, L"A2091/A590", - dmac_lgeti, dmac_wgeti, ABFLAG_IO + dmac_lget, dmac_wget, dmac_bget, + dmac_lput, dmac_wput, dmac_bput, + default_xlate, default_check, NULL, L"A2091/A590", + dmac_lgeti, dmac_wgeti, ABFLAG_IO }; static void dmacreg_write (uae_u32 *reg, int addr, uae_u32 val, int size) { - addr = (size - 1) - addr; - (*reg) &= ~(0xff << (addr * 8)); - (*reg) |= (val & 0xff) << (addr * 8); + addr = (size - 1) - addr; + (*reg) &= ~(0xff << (addr * 8)); + (*reg) |= (val & 0xff) << (addr * 8); } static uae_u32 dmacreg_read (uae_u32 val, int addr, int size) { - addr = (size - 1) - addr; - return (val >> (addr * 8)) & 0xff; + addr = (size - 1) - addr; + return (val >> (addr * 8)) & 0xff; } static void mbdmac_write (uae_u32 addr, uae_u32 val, int mode) { - if (currprefs.cs_mbdmac > 1) - return; + if (currprefs.cs_mbdmac > 1) + return; #if A3000_DEBUG > 1 - write_log (L"DMAC_WRITE %08X=%02X PC=%08X\n", addr, val & 0xff, M68K_GETPC); + write_log (L"DMAC_WRITE %08X=%02X PC=%08X\n", addr, val & 0xff, M68K_GETPC); #endif - addr &= 0xffff; - switch (addr) - { + addr &= 0xffff; + switch (addr) + { case 0x02: case 0x03: - dmacreg_write (&dmac_dawr, addr - 0x02, val, 2); - break; + dmacreg_write (&dmac_dawr, addr - 0x02, val, 2); + break; case 0x04: case 0x05: case 0x06: case 0x07: - dmacreg_write (&dmac_wtc, addr - 0x04, val, 4); - break; + dmacreg_write (&dmac_wtc, addr - 0x04, val, 4); + break; case 0x0a: case 0x0b: - dmacreg_write (&dmac_cntr, addr - 0x0a, val, 2); - if (dmac_cntr & SCNTR_PREST) - dmac_reset (); - break; + dmacreg_write (&dmac_cntr, addr - 0x0a, val, 2); + if (dmac_cntr & SCNTR_PREST) + dmac_reset (); + break; case 0x0c: case 0x0d: case 0x0e: case 0x0f: - dmacreg_write (&dmac_acr, addr - 0x0c, val, 4); - break; + dmacreg_write (&dmac_acr, addr - 0x0c, val, 4); + break; case 0x12: case 0x13: - if (!dmac_dma) - dmac_start_dma (); - break; + if (!dmac_dma) + dmac_start_dma (); + break; case 0x16: case 0x17: - /* FLUSH */ - dmac_istr |= ISTR_FE_FLG; - break; + /* FLUSH */ + dmac_istr |= ISTR_FE_FLG; + break; case 0x1a: case 0x1b: - dmac_cint(); - break; + dmac_cint(); + break; case 0x1e: case 0x1f: - /* ISTR */ - break; + /* ISTR */ + break; case 0x3e: case 0x3f: - dmac_stop_dma (); - break; + dmac_stop_dma (); + break; case 0x41: - if (mode & 0x10) - sasr = val; - break; + if (mode & 0x10) + sasr = val; + break; case 0x49: - sasr = val; - break; + sasr = val; + break; case 0x43: - if (mode & 0x10) - wdscsi_put (val); - else - sasr = val; - break; - } + if (mode & 0x10) + wdscsi_put (val); + else + sasr = val; + break; + } } static uae_u32 mbdmac_read (uae_u32 addr, int mode) { - uae_u32 vaddr = addr; - uae_u32 v = 0xffffffff; + uae_u32 vaddr = addr; + uae_u32 v = 0xffffffff; - if (currprefs.cs_mbdmac > 1) - return 0; + if (currprefs.cs_mbdmac > 1) + return 0; - addr &= 0xffff; - switch (addr) - { + addr &= 0xffff; + switch (addr) + { case 0x02: case 0x03: - v = dmacreg_read (dmac_dawr, addr - 0x02, 2); - break; + v = dmacreg_read (dmac_dawr, addr - 0x02, 2); + break; case 0x04: case 0x05: case 0x06: case 0x07: - v = 0xff; - break; + v = 0xff; + break; case 0x0a: case 0x0b: - v = dmacreg_read (dmac_cntr, addr - 0x0a, 2); - break; + v = dmacreg_read (dmac_cntr, addr - 0x0a, 2); + break; case 0x0c: case 0x0d: case 0x0e: case 0x0f: - v = dmacreg_read (dmac_acr, addr - 0x0c, 4); - break; + v = dmacreg_read (dmac_acr, addr - 0x0c, 4); + break; case 0x12: case 0x13: - if (!dmac_dma) - dmac_start_dma (); - v = 0; - break; + if (!dmac_dma) + dmac_start_dma (); + v = 0; + break; case 0x1a: case 0x1b: - dmac_cint (); - v = 0; - break;; + dmac_cint (); + v = 0; + break;; case 0x1e: case 0x1f: - v = dmacreg_read (dmac_istr, addr - 0x1e, 2); - if (v & ISTR_INTS) - v |= ISTR_INT_P; - dmac_istr &= ~15; - break; + v = dmacreg_read (dmac_istr, addr - 0x1e, 2); + if (v & ISTR_INTS) + v |= ISTR_INT_P; + dmac_istr &= ~15; + break; case 0x3e: case 0x3f: - dmac_stop_dma (); - v = 0; - break; + dmac_stop_dma (); + v = 0; + break; case 0x41: case 0x49: - v = wdscsi_getauxstatus (); - break; + v = wdscsi_getauxstatus (); + break; case 0x43: - v = wdscsi_get (); - break; - } + v = wdscsi_get (); + break; + } #if A3000_DEBUG > 1 - write_log (L"DMAC_READ %08X=%02X PC=%X\n", vaddr, v & 0xff, M68K_GETPC); + write_log (L"DMAC_READ %08X=%02X PC=%X\n", vaddr, v & 0xff, M68K_GETPC); #endif - return v; + return v; } @@ -1116,248 +1116,248 @@ static void REGPARAM3 mbdmac_bput (uaecptr, uae_u32) REGPARAM; static uae_u32 REGPARAM2 mbdmac_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = mbdmac_read (addr, 0x40 | 0) << 24; - v |= mbdmac_read (addr + 1, 0x40 | 1) << 16; - v |= mbdmac_read (addr + 2, 0x40 | 2) << 8; - v |= mbdmac_read (addr + 3, 0x40 | 3); - return v; + v = mbdmac_read (addr, 0x40 | 0) << 24; + v |= mbdmac_read (addr + 1, 0x40 | 1) << 16; + v |= mbdmac_read (addr + 2, 0x40 | 2) << 8; + v |= mbdmac_read (addr + 3, 0x40 | 3); + return v; } static uae_u32 REGPARAM2 mbdmac_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = mbdmac_read (addr, 0x40 | 0) << 8; - v |= mbdmac_read (addr + 1, 0x40 | 1) << 0; - return v; + v = mbdmac_read (addr, 0x40 | 0) << 8; + v |= mbdmac_read (addr + 1, 0x40 | 1) << 0; + return v; } static uae_u32 REGPARAM2 mbdmac_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return mbdmac_read (addr, 0x10); + return mbdmac_read (addr, 0x10); } static void REGPARAM2 mbdmac_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbdmac_write (addr + 0, l >> 24, 0x40 | 0); - mbdmac_write (addr + 1, l >> 16, 0x40 | 1); - mbdmac_write (addr + 2, l >> 8, 0x40 | 2); - mbdmac_write (addr + 3, l, 0x40 | 3); + mbdmac_write (addr + 0, l >> 24, 0x40 | 0); + mbdmac_write (addr + 1, l >> 16, 0x40 | 1); + mbdmac_write (addr + 2, l >> 8, 0x40 | 2); + mbdmac_write (addr + 3, l, 0x40 | 3); } static void REGPARAM2 mbdmac_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbdmac_write (addr + 0, w >> 8, 0x20 | 0); - mbdmac_write (addr + 1, w >> 0, 0x20 | 1); + mbdmac_write (addr + 0, w >> 8, 0x20 | 0); + mbdmac_write (addr + 1, w >> 0, 0x20 | 1); } static void REGPARAM2 mbdmac_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbdmac_write (addr, b, 0x10 | 0); + mbdmac_write (addr, b, 0x10 | 0); } addrbank mbdmac_a3000_bank = { - mbdmac_lget, mbdmac_wget, mbdmac_bget, - mbdmac_lput, mbdmac_wput, mbdmac_bput, - default_xlate, default_check, NULL, L"A3000 DMAC", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + mbdmac_lget, mbdmac_wget, mbdmac_bget, + mbdmac_lput, mbdmac_wput, mbdmac_bput, + default_xlate, default_check, NULL, L"A3000 DMAC", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static void ew (int addr, uae_u32 value) { - addr &= 0xffff; - if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { - dmacmemory[addr] = (value & 0xf0); - dmacmemory[addr + 2] = (value & 0x0f) << 4; - } else { - dmacmemory[addr] = ~(value & 0xf0); - dmacmemory[addr + 2] = ~((value & 0x0f) << 4); - } + addr &= 0xffff; + if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { + dmacmemory[addr] = (value & 0xf0); + dmacmemory[addr + 2] = (value & 0x0f) << 4; + } else { + dmacmemory[addr] = ~(value & 0xf0); + dmacmemory[addr + 2] = ~((value & 0x0f) << 4); + } } static void freescsi (struct scsi_data *sd) { - if (!sd) - return; - hdf_hd_close (sd->hfd); - scsi_free (sd); + if (!sd) + return; + hdf_hd_close (sd->hfd); + scsi_free (sd); } int addscsi (int ch, TCHAR *path, int blocksize, int readonly, - TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, TCHAR *filesys, int scsi_level) + TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, TCHAR *filesys, int scsi_level) { - struct hd_hardfiledata *hfd; - - freescsi (scsis[ch]); - scsis[ch] = NULL; - hfd = xcalloc (sizeof (struct hd_hardfiledata), 1); - if (!hdf_hd_open (hfd, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys)) - return 0; - hfd->ansi_version = scsi_level; - scsis[ch] = scsi_alloc (ch, hfd); - return scsis[ch] ? 1 : 0; + struct hd_hardfiledata *hfd; + + freescsi (scsis[ch]); + scsis[ch] = NULL; + hfd = xcalloc (sizeof (struct hd_hardfiledata), 1); + if (!hdf_hd_open (hfd, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys)) + return 0; + hfd->ansi_version = scsi_level; + scsis[ch] = scsi_alloc (ch, hfd); + return scsis[ch] ? 1 : 0; } static void freenativescsi (void) { - int i; - for (i = 0; i < 7; i++) { - freescsi (scsis[i]); - scsis[i] = NULL; - } + int i; + for (i = 0; i < 7; i++) { + freescsi (scsis[i]); + scsis[i] = NULL; + } } static void addnativescsi (void) { - int i, j; - int devices[MAX_TOTAL_DEVICES]; - int types[MAX_TOTAL_DEVICES]; - struct device_info dis[MAX_TOTAL_DEVICES]; - - freenativescsi (); - i = 0; - while (i < MAX_TOTAL_DEVICES) { - types[i] = -1; - devices[i] = -1; - if (sys_command_open (DF_SCSI, i)) { - if (sys_command_info (DF_SCSI, i, &dis[i])) { - devices[i] = i; - types[i] = 100 - i; - if (dis[i].type == INQ_ROMD) - types[i] = 1000 - i; - } - sys_command_close (DF_SCSI, i); + int i, j; + int devices[MAX_TOTAL_DEVICES]; + int types[MAX_TOTAL_DEVICES]; + struct device_info dis[MAX_TOTAL_DEVICES]; + + freenativescsi (); + i = 0; + while (i < MAX_TOTAL_DEVICES) { + types[i] = -1; + devices[i] = -1; + if (sys_command_open (DF_SCSI, i)) { + if (sys_command_info (DF_SCSI, i, &dis[i])) { + devices[i] = i; + types[i] = 100 - i; + if (dis[i].type == INQ_ROMD) + types[i] = 1000 - i; + } + sys_command_close (DF_SCSI, i); + } + i++; } - i++; - } - i = 0; - while (devices[i] >= 0) { - j = i + 1; - while (devices[j] >= 0) { - if (types[i] > types[j]) { - int tmp = types[i]; - types[i] = types[j]; - types[j] = tmp; - } - j++; + i = 0; + while (devices[i] >= 0) { + j = i + 1; + while (devices[j] >= 0) { + if (types[i] > types[j]) { + int tmp = types[i]; + types[i] = types[j]; + types[j] = tmp; + } + j++; + } + i++; } - i++; - } - i = 0; j = 0; - while (devices[i] >= 0 && j < 7) { - if (scsis[j] == NULL) { - scsis[j] = scsi_alloc_native(j, devices[i]); - write_log (L"SCSI: %d:'%s'\n", j, dis[i].label); - i++; + i = 0; j = 0; + while (devices[i] >= 0 && j < 7) { + if (scsis[j] == NULL) { + scsis[j] = scsi_alloc_native(j, devices[i]); + write_log (L"SCSI: %d:'%s'\n", j, dis[i].label); + i++; + } + j++; } - j++; - } } int a3000_add_scsi_unit (int ch, TCHAR *path, int blocksize, int readonly, - TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, TCHAR *filesys) + TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, TCHAR *filesys) { - return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 2); + return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 2); } void a3000scsi_reset (void) { - map_banks (&mbdmac_a3000_bank, 0xDD, 1, 0); + map_banks (&mbdmac_a3000_bank, 0xDD, 1, 0); } void a3000scsi_free (void) { - freenativescsi (); + freenativescsi (); } int a2091_add_scsi_unit (int ch, TCHAR *path, int blocksize, int readonly, - TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, TCHAR *filesys) + TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, TCHAR *filesys) { - return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 1); + return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 1); } void a2091_free (void) { - freenativescsi (); - xfree (rom); - rom = NULL; + freenativescsi (); + xfree (rom); + rom = NULL; } void a2091_reset (void) { - configured = 0; - wd_used = 0; - superdmac = 0; - superdmac = currprefs.cs_mbdmac ? 1 : 0; - if (currprefs.scsi == 2) - addnativescsi (); + configured = 0; + wd_used = 0; + superdmac = 0; + superdmac = currprefs.cs_mbdmac ? 1 : 0; + if (currprefs.scsi == 2) + addnativescsi (); } void a2091_init (void) { - int roms[5]; - struct romlist *rl; - struct romdata *rd; - - configured = 0; - memset (dmacmemory, 0xff, 100); - ew (0x00, 0xc0 | 0x01 | 0x10); - /* A590/A2091 hardware id */ - ew (0x04, old_dmac ? 0x02 : 0x03); - /* commodore's manufacturer id */ - ew (0x10, 0x02); - ew (0x14, 0x02); - /* rom vector */ - ew (0x28, ROM_VECTOR >> 8); - ew (0x2c, ROM_VECTOR); - - ew (0x18, 0x00); /* ser.no. Byte 0 */ - ew (0x1c, 0x00); /* ser.no. Byte 1 */ - ew (0x20, 0x00); /* ser.no. Byte 2 */ - ew (0x24, 0x00); /* ser.no. Byte 3 */ - - roms[0] = 55; - roms[1] = 54; - roms[2] = 53; - roms[3] = 56; - roms[4] = -1; - - rombankswitcher = 0; - rombank = 0; - rl = getromlistbyids (roms); - if (rl) { - struct zfile *z; - rd = rl->rd; - z = read_rom (&rd); - if (z) { - write_log (L"A590/A2091 BOOT ROM %d.%d ", rd->ver, rd->rev); - rom_size = rd->size; - rom = xmalloc (rom_size); - if (rl->rd->id == 56) - rombankswitcher = 1; - zfile_fread (rom, rom_size, 1, z); - zfile_fclose (z); - rom_mask = rom_size - 1; + int roms[5]; + struct romlist *rl; + struct romdata *rd; + + configured = 0; + memset (dmacmemory, 0xff, 100); + ew (0x00, 0xc0 | 0x01 | 0x10); + /* A590/A2091 hardware id */ + ew (0x04, old_dmac ? 0x02 : 0x03); + /* commodore's manufacturer id */ + ew (0x10, 0x02); + ew (0x14, 0x02); + /* rom vector */ + ew (0x28, ROM_VECTOR >> 8); + ew (0x2c, ROM_VECTOR); + + ew (0x18, 0x00); /* ser.no. Byte 0 */ + ew (0x1c, 0x00); /* ser.no. Byte 1 */ + ew (0x20, 0x00); /* ser.no. Byte 2 */ + ew (0x24, 0x00); /* ser.no. Byte 3 */ + + roms[0] = 55; + roms[1] = 54; + roms[2] = 53; + roms[3] = 56; + roms[4] = -1; + + rombankswitcher = 0; + rombank = 0; + rl = getromlistbyids (roms); + if (rl) { + struct zfile *z; + rd = rl->rd; + z = read_rom (&rd); + if (z) { + write_log (L"A590/A2091 BOOT ROM %d.%d ", rd->ver, rd->rev); + rom_size = rd->size; + rom = xmalloc (rom_size); + if (rl->rd->id == 56) + rombankswitcher = 1; + zfile_fread (rom, rom_size, 1, z); + zfile_fclose (z); + rom_mask = rom_size - 1; + } + } else { + romwarning (roms); } - } else { - romwarning (roms); - } - map_banks (&dmaca2091_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); + map_banks (&dmaca2091_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); } diff --git a/akiko.c b/akiko.c index 7dfcd93a..c50488ad 100644 --- a/akiko.c +++ b/akiko.c @@ -1,15 +1,15 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * CD32 Akiko emulation - * - * - C2P - * - NVRAM - * - CDROM - * - * Copyright 2001-2009 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* CD32 Akiko emulation +* +* - C2P +* - NVRAM +* - CDROM +* +* Copyright 2001-2009 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -38,31 +38,31 @@ static void irq (void) { #if AKIKO_DEBUG_IO > 1 - write_log (L"Akiko Interrupt\n"); + write_log (L"Akiko Interrupt\n"); #endif - if (!(intreq & 8)) { - INTREQ_0 (0x8000 | 0x0008); - } + if (!(intreq & 8)) { + INTREQ_0 (0x8000 | 0x0008); + } } /* - * CD32 1Kb NVRAM (EEPROM) emulation - * - * NVRAM chip is 24C08 CMOS EEPROM (1024x8 bits = 1Kb) - * Chip interface is I2C (2 wire serial) - * Akiko addresses used: - * 0xb80030: bit 7 = SCL (clock), 6 = SDA (data) - * 0xb80032: 0xb80030 data direction register (0 = input, 1 = output) - * - * Because I don't have any experience on I2C, following code may be - * unnecessarily complex and not 100% correct.. - */ +* CD32 1Kb NVRAM (EEPROM) emulation +* +* NVRAM chip is 24C08 CMOS EEPROM (1024x8 bits = 1Kb) +* Chip interface is I2C (2 wire serial) +* Akiko addresses used: +* 0xb80030: bit 7 = SCL (clock), 6 = SDA (data) +* 0xb80032: 0xb80030 data direction register (0 = input, 1 = output) +* +* Because I don't have any experience on I2C, following code may be +* unnecessarily complex and not 100% correct.. +*/ enum i2c { I2C_WAIT, I2C_START, I2C_DEVICEADDR, I2C_WORDADDR, I2C_DATA }; /* size of EEPROM, don't try to change, - * (hardcoded in Kickstart) - */ +* (hardcoded in Kickstart) +*/ #define NVRAM_SIZE 1024 /* max size of one write request */ #define NVRAM_PAGE_SIZE 16 @@ -78,212 +78,212 @@ static int state = I2C_WAIT; static void nvram_write (int offset, int len) { - struct zfile *f; - - if (!currprefs.cs_cd32nvram) - return; - f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) { - f = zfile_fopen (currprefs.flashfile, L"wb", 0); - if (!f) return; - zfile_fwrite (cd32_nvram, NVRAM_SIZE, 1, f); - } - zfile_fseek (f, offset, SEEK_SET); - zfile_fwrite (cd32_nvram + offset, len, 1, f); - zfile_fclose (f); + struct zfile *f; + + if (!currprefs.cs_cd32nvram) + return; + f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) { + f = zfile_fopen (currprefs.flashfile, L"wb", 0); + if (!f) return; + zfile_fwrite (cd32_nvram, NVRAM_SIZE, 1, f); + } + zfile_fseek (f, offset, SEEK_SET); + zfile_fwrite (cd32_nvram + offset, len, 1, f); + zfile_fclose (f); } static void nvram_read (void) { - struct zfile *f; - - if (!currprefs.cs_cd32nvram) - return; - f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); - memset (cd32_nvram, 0, NVRAM_SIZE); - if (!f) return; - zfile_fread (cd32_nvram, NVRAM_SIZE, 1, f); - zfile_fclose (f); + struct zfile *f; + + if (!currprefs.cs_cd32nvram) + return; + f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); + memset (cd32_nvram, 0, NVRAM_SIZE); + if (!f) return; + zfile_fread (cd32_nvram, NVRAM_SIZE, 1, f); + zfile_fclose (f); } static void i2c_do (void) { #if AKIKO_DEBUG_NVRAM - int i; + int i; #endif - sda_in = 1; - if (!sda_dir_nvram && scl_out && oscl) { - if (!sda_out && osda) { /* START-condition? */ - state = I2C_DEVICEADDR; - bitcounter = 0; - direction = -1; + sda_in = 1; + if (!sda_dir_nvram && scl_out && oscl) { + if (!sda_out && osda) { /* START-condition? */ + state = I2C_DEVICEADDR; + bitcounter = 0; + direction = -1; #if AKIKO_DEBUG_NVRAM - write_log (L"START\n"); + write_log (L"START\n"); #endif - return; - } else if(sda_out && !osda) { /* STOP-condition? */ - state = I2C_WAIT; - bitcounter = -1; + return; + } else if(sda_out && !osda) { /* STOP-condition? */ + state = I2C_WAIT; + bitcounter = -1; #if AKIKO_DEBUG_NVRAM - write_log (L"STOP\n"); + write_log (L"STOP\n"); #endif - if (direction > 0) { - memcpy (cd32_nvram + (nvram_address & ~(NVRAM_PAGE_SIZE - 1)), nvram_writetmp, NVRAM_PAGE_SIZE); - nvram_write (nvram_address & ~(NVRAM_PAGE_SIZE - 1), NVRAM_PAGE_SIZE); - direction = -1; + if (direction > 0) { + memcpy (cd32_nvram + (nvram_address & ~(NVRAM_PAGE_SIZE - 1)), nvram_writetmp, NVRAM_PAGE_SIZE); + nvram_write (nvram_address & ~(NVRAM_PAGE_SIZE - 1), NVRAM_PAGE_SIZE); + direction = -1; #if AKIKO_DEBUG_NVRAM - write_log (L"NVRAM write address %04X:", nvram_address & ~(NVRAM_PAGE_SIZE - 1)); - for (i = 0; i < NVRAM_PAGE_SIZE; i++) - write_log (L"%02X", nvram_writetmp[i]); - write_log (L"\n"); + write_log (L"NVRAM write address %04X:", nvram_address & ~(NVRAM_PAGE_SIZE - 1)); + for (i = 0; i < NVRAM_PAGE_SIZE; i++) + write_log (L"%02X", nvram_writetmp[i]); + write_log (L"\n"); #endif - } - return; + } + return; + } } - } - if (bitcounter >= 0) { - if (direction) { - /* Amiga -> NVRAM */ - if (scl_out && !oscl) { - if (bitcounter == 8) { + if (bitcounter >= 0) { + if (direction) { + /* Amiga -> NVRAM */ + if (scl_out && !oscl) { + if (bitcounter == 8) { #if AKIKO_DEBUG_NVRAM - write_log (L"RB %02X ", nvram_byte, M68K_GETPC); + write_log (L"RB %02X ", nvram_byte, M68K_GETPC); #endif - sda_in = 0; /* ACK */ - if (direction > 0) { - nvram_writetmp[nvram_writeaddr++] = nvram_byte; - nvram_writeaddr &= 15; - bitcounter = 0; - } else { - bitcounter = -1; - } + sda_in = 0; /* ACK */ + if (direction > 0) { + nvram_writetmp[nvram_writeaddr++] = nvram_byte; + nvram_writeaddr &= 15; + bitcounter = 0; + } else { + bitcounter = -1; + } + } else { + //write_log (L"NVRAM received bit %d, offset %d\n", sda_out, bitcounter); + nvram_byte <<= 1; + nvram_byte |= sda_out; + bitcounter++; + } + } } else { - //write_log (L"NVRAM received bit %d, offset %d\n", sda_out, bitcounter); - nvram_byte <<= 1; - nvram_byte |= sda_out; - bitcounter++; - } - } - } else { - /* NVRAM -> Amiga */ - if (scl_out && !oscl && bitcounter < 8) { - if (bitcounter == 0) - nvram_byte = cd32_nvram[nvram_address]; - sda_dir_nvram = 1; - sda_in = (nvram_byte & 0x80) ? 1 : 0; - //write_log (L"NVRAM sent bit %d, offset %d\n", sda_in, bitcounter); - nvram_byte <<= 1; - bitcounter++; - if (bitcounter == 8) { + /* NVRAM -> Amiga */ + if (scl_out && !oscl && bitcounter < 8) { + if (bitcounter == 0) + nvram_byte = cd32_nvram[nvram_address]; + sda_dir_nvram = 1; + sda_in = (nvram_byte & 0x80) ? 1 : 0; + //write_log (L"NVRAM sent bit %d, offset %d\n", sda_in, bitcounter); + nvram_byte <<= 1; + bitcounter++; + if (bitcounter == 8) { #if AKIKO_DEBUG_NVRAM - write_log (L"NVRAM sent byte %02X address %04X PC=%08X\n", cd32_nvram[nvram_address], nvram_address, M68K_GETPC); + write_log (L"NVRAM sent byte %02X address %04X PC=%08X\n", cd32_nvram[nvram_address], nvram_address, M68K_GETPC); #endif - nvram_address++; - nvram_address &= NVRAM_SIZE - 1; - sda_dir_nvram = 0; + nvram_address++; + nvram_address &= NVRAM_SIZE - 1; + sda_dir_nvram = 0; + } + } + if(!sda_out && sda_dir && !scl_out) /* ACK from Amiga */ + bitcounter = 0; } - } - if(!sda_out && sda_dir && !scl_out) /* ACK from Amiga */ - bitcounter = 0; + if (bitcounter >= 0) return; } - if (bitcounter >= 0) return; - } - switch (state) - { + switch (state) + { case I2C_DEVICEADDR: - if ((nvram_byte & 0xf0) != 0xa0) { - write_log (L"WARNING: I2C_DEVICEADDR: device address != 0xA0\n"); - state = I2C_WAIT; - return; - } - nvram_rw = (nvram_byte & 1) ? 0 : 1; - if (nvram_rw) { - /* 2 high address bits, only fetched if WRITE = 1 */ - nvram_address &= 0xff; - nvram_address |= ((nvram_byte >> 1) & 3) << 8; - state = I2C_WORDADDR; - direction = -1; - } else { - state = I2C_DATA; - direction = 0; - sda_dir_nvram = 1; - } - bitcounter = 0; + if ((nvram_byte & 0xf0) != 0xa0) { + write_log (L"WARNING: I2C_DEVICEADDR: device address != 0xA0\n"); + state = I2C_WAIT; + return; + } + nvram_rw = (nvram_byte & 1) ? 0 : 1; + if (nvram_rw) { + /* 2 high address bits, only fetched if WRITE = 1 */ + nvram_address &= 0xff; + nvram_address |= ((nvram_byte >> 1) & 3) << 8; + state = I2C_WORDADDR; + direction = -1; + } else { + state = I2C_DATA; + direction = 0; + sda_dir_nvram = 1; + } + bitcounter = 0; #if AKIKO_DEBUG_NVRAM - write_log (L"I2C_DEVICEADDR: rw %d, address %02Xxx PC=%08X\n", nvram_rw, nvram_address >> 8, M68K_GETPC); + write_log (L"I2C_DEVICEADDR: rw %d, address %02Xxx PC=%08X\n", nvram_rw, nvram_address >> 8, M68K_GETPC); #endif - break; + break; case I2C_WORDADDR: - nvram_address &= 0x300; - nvram_address |= nvram_byte; + nvram_address &= 0x300; + nvram_address |= nvram_byte; #if AKIKO_DEBUG_NVRAM - write_log (L"I2C_WORDADDR: address %04X PC=%08X\n", nvram_address, M68K_GETPC); + write_log (L"I2C_WORDADDR: address %04X PC=%08X\n", nvram_address, M68K_GETPC); #endif - if (direction < 0) { - memcpy (nvram_writetmp, cd32_nvram + (nvram_address & ~(NVRAM_PAGE_SIZE - 1)), NVRAM_PAGE_SIZE); - nvram_writeaddr = nvram_address & (NVRAM_PAGE_SIZE - 1); + if (direction < 0) { + memcpy (nvram_writetmp, cd32_nvram + (nvram_address & ~(NVRAM_PAGE_SIZE - 1)), NVRAM_PAGE_SIZE); + nvram_writeaddr = nvram_address & (NVRAM_PAGE_SIZE - 1); + } + state = I2C_DATA; + bitcounter = 0; + direction = 1; + break; } - state = I2C_DATA; - bitcounter = 0; - direction = 1; - break; - } } static void akiko_nvram_write (int offset, uae_u32 v) { - int sda; - switch (offset) - { + int sda; + switch (offset) + { case 0: - oscl = scl_out; - scl_out = (v & 0x80) ? 1 : 0; - osda = sda_out; - sda_out = (v & 0x40) ? 1 : 0; - break; + oscl = scl_out; + scl_out = (v & 0x80) ? 1 : 0; + osda = sda_out; + sda_out = (v & 0x40) ? 1 : 0; + break; case 2: - scl_dir = (v & 0x80) ? 1 : 0; - sda_dir = (v & 0x40) ? 1 : 0; - break; + scl_dir = (v & 0x80) ? 1 : 0; + sda_dir = (v & 0x40) ? 1 : 0; + break; default: - return; - } - sda = sda_out; - if (oscl != scl_out || osda != sda) { - i2c_do (); - oscl = scl_out; - osda = sda; - } + return; + } + sda = sda_out; + if (oscl != scl_out || osda != sda) { + i2c_do (); + oscl = scl_out; + osda = sda; + } } static uae_u32 akiko_nvram_read (int offset) { - uae_u32 v = 0; - switch (offset) - { + uae_u32 v = 0; + switch (offset) + { case 0: - if (!scl_dir) - v |= scl_in ? 0x80 : 0x00; - else - v |= scl_out ? 0x80 : 0x00; - if (!sda_dir) - v |= sda_in ? 0x40 : 0x00; - else - v |= sda_out ? 0x40 : 0x00; - break; + if (!scl_dir) + v |= scl_in ? 0x80 : 0x00; + else + v |= scl_out ? 0x80 : 0x00; + if (!sda_dir) + v |= sda_in ? 0x40 : 0x00; + else + v |= sda_out ? 0x40 : 0x00; + break; case 2: - v |= scl_dir ? 0x80 : 0x00; - v |= sda_dir ? 0x40 : 0x00; - break; - } - return v; + v |= scl_dir ? 0x80 : 0x00; + v |= sda_dir ? 0x40 : 0x00; + break; + } + return v; } /* CD32 Chunky to Planar hardware emulation - * Akiko addresses used: - * 0xb80038-0xb8003b - */ +* Akiko addresses used: +* 0xb80038-0xb8003b +*/ static uae_u32 akiko_buffer[8]; static int akiko_read_offset, akiko_write_offset; @@ -291,48 +291,48 @@ static uae_u32 akiko_result[8]; static void akiko_c2p_do (void) { - int i; - - for (i = 0; i < 8; i++) - akiko_result[i] = 0; - /* FIXME: better c2p algoritm than this piece of crap.... */ - for (i = 0; i < 8 * 32; i++) { - if (akiko_buffer[7 - (i >> 5)] & (1 << (i & 31))) - akiko_result[i & 7] |= 1 << (i >> 3); - } + int i; + + for (i = 0; i < 8; i++) + akiko_result[i] = 0; + /* FIXME: better c2p algoritm than this piece of crap.... */ + for (i = 0; i < 8 * 32; i++) { + if (akiko_buffer[7 - (i >> 5)] & (1 << (i & 31))) + akiko_result[i & 7] |= 1 << (i >> 3); + } } static void akiko_c2p_write (int offset, uae_u32 v) { - if (offset == 3) - akiko_buffer[akiko_write_offset] = 0; - akiko_buffer[akiko_write_offset] |= v << ( 8 * (3 - offset)); - if (offset == 0) { - akiko_write_offset++; - akiko_write_offset &= 7; - } - akiko_read_offset = 0; + if (offset == 3) + akiko_buffer[akiko_write_offset] = 0; + akiko_buffer[akiko_write_offset] |= v << ( 8 * (3 - offset)); + if (offset == 0) { + akiko_write_offset++; + akiko_write_offset &= 7; + } + akiko_read_offset = 0; } static uae_u32 akiko_c2p_read (int offset) { - uae_u32 v; - - if (akiko_read_offset == 0 && offset == 3) - akiko_c2p_do (); - akiko_write_offset = 0; - v = akiko_result[akiko_read_offset]; - if (offset == 0) { - akiko_read_offset++; - akiko_read_offset &= 7; - } - return v >> (8 * (3 - offset)); + uae_u32 v; + + if (akiko_read_offset == 0 && offset == 3) + akiko_c2p_do (); + akiko_write_offset = 0; + v = akiko_result[akiko_read_offset]; + if (offset == 0) { + akiko_read_offset++; + akiko_read_offset &= 7; + } + return v >> (8 * (3 - offset)); } /* CD32 CDROM hardware emulation - * Akiko addresses used: - * 0xb80004-0xb80028 - */ +* Akiko addresses used: +* 0xb80004-0xb80028 +*/ #define CDINTERRUPT_SUBCODE 0x80000000 #define CDINTERRUPT_DRIVEXMIT 0x40000000 /* not used by ROM */ @@ -427,119 +427,119 @@ static volatile int akiko_thread_running; static void checkint (void) { - if (cdrom_intreq & cdrom_intena) - irq (); + if (cdrom_intreq & cdrom_intena) + irq (); } static void set_status (uae_u32 status) { - cdrom_intreq |= status; - checkint (); - cdrom_led ^= LED_CD_ACTIVE2; + cdrom_intreq |= status; + checkint (); + cdrom_led ^= LED_CD_ACTIVE2; } void rethink_akiko (void) { - checkint (); + checkint (); } static uae_u8 frombcd (uae_u8 v) { - return (v >> 4) * 10 + (v & 15); + return (v >> 4) * 10 + (v & 15); } static uae_u8 tobcd (uae_u8 v) { - return ((v / 10) << 4) | (v % 10); + return ((v / 10) << 4) | (v % 10); } static int fromlongbcd (uae_u8 *p) { - return (frombcd (p[0]) << 16) | (frombcd (p[1]) << 8) | (frombcd (p[2]) << 0); + return (frombcd (p[0]) << 16) | (frombcd (p[1]) << 8) | (frombcd (p[2]) << 0); } /* convert minutes, seconds and frames -> logical sector number */ static int msf2lsn (int msf) { - int sector = (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff)) - 150; - if (sector < 0) - sector = 0; - return sector; + int sector = (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff)) - 150; + if (sector < 0) + sector = 0; + return sector; } /* convert logical sector number -> minutes, seconds and frames */ static int lsn2msf (int sectors) { - int msf; - sectors += 150; - msf = (sectors / (75 * 60)) << 16; - msf |= ((sectors / 75) % 60) << 8; - msf |= (sectors % 75) << 0; - return msf; + int msf; + sectors += 150; + msf = (sectors / (75 * 60)) << 16; + msf |= ((sectors / 75) % 60) << 8; + msf |= (sectors % 75) << 0; + return msf; } static void cdaudiostop_do (void) { - qcode_valid = 0; - if (unitnum < 0) - return; - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - sys_command_cd_stop (DF_IOCTL, unitnum); - sys_command_cd_pause (DF_IOCTL, unitnum, 1); + qcode_valid = 0; + if (unitnum < 0) + return; + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + sys_command_cd_stop (DF_IOCTL, unitnum); + sys_command_cd_pause (DF_IOCTL, unitnum, 1); } static void cdaudiostop (void) { - cdrom_playing = 0; - cdrom_paused = 0; - cdrom_audiotimeout = 0; - write_comm_pipe_u32 (&requests, 0x104, 1); + cdrom_playing = 0; + cdrom_paused = 0; + cdrom_audiotimeout = 0; + write_comm_pipe_u32 (&requests, 0x104, 1); } static void cdaudioplay_do (void) { - uae_u32 startmsf = read_comm_pipe_u32_blocking (&requests); - uae_u32 endmsf = read_comm_pipe_u32_blocking (&requests); - uae_u32 scan = read_comm_pipe_u32_blocking (&requests); - qcode_valid = 0; - if (unitnum < 0) - return; - sys_command_cd_play (DF_IOCTL, unitnum, startmsf, endmsf, scan); + uae_u32 startmsf = read_comm_pipe_u32_blocking (&requests); + uae_u32 endmsf = read_comm_pipe_u32_blocking (&requests); + uae_u32 scan = read_comm_pipe_u32_blocking (&requests); + qcode_valid = 0; + if (unitnum < 0) + return; + sys_command_cd_play (DF_IOCTL, unitnum, startmsf, endmsf, scan); } static uae_u32 last_play_end; static int cd_play_audio (uae_u32 startmsf, uae_u32 endmsf, int scan) { #if 1 - uae_u8 *buf = cdrom_toc_cd_buffer; - uae_u8 *s; - uae_u32 addr; - int i; - - for (i = 0; i < cdrom_toc_entries; i++) { - s = buf + 4 + i * 11; - addr = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); - if (s[3] > 0 && s[3] < 100 && addr >= startmsf) - break; - } - if ((s[1] & 0x0c) == 0x04) { - write_log (L"tried to play data track %d!\n", s[3]); - s += 11; - startmsf = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); - s += 11; - endmsf = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); - //cdrom_audiotimeout = 312; - return 0; - } + uae_u8 *buf = cdrom_toc_cd_buffer; + uae_u8 *s; + uae_u32 addr; + int i; + + for (i = 0; i < cdrom_toc_entries; i++) { + s = buf + 4 + i * 11; + addr = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); + if (s[3] > 0 && s[3] < 100 && addr >= startmsf) + break; + } + if ((s[1] & 0x0c) == 0x04) { + write_log (L"tried to play data track %d!\n", s[3]); + s += 11; + startmsf = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); + s += 11; + endmsf = (s[8] << 16) | (s[9] << 8) | (s[10] << 0); + //cdrom_audiotimeout = 312; + return 0; + } #endif - last_play_end = endmsf; - cdrom_audiotimeout = 0; - write_comm_pipe_u32 (&requests, 0x110, 0); - write_comm_pipe_u32 (&requests, startmsf, 0); - write_comm_pipe_u32 (&requests, endmsf, 0); - write_comm_pipe_u32 (&requests, scan, 1); - return 1; + last_play_end = endmsf; + cdrom_audiotimeout = 0; + write_comm_pipe_u32 (&requests, 0x110, 0); + write_comm_pipe_u32 (&requests, startmsf, 0); + write_comm_pipe_u32 (&requests, endmsf, 0); + write_comm_pipe_u32 (&requests, scan, 1); + return 1; } @@ -547,471 +547,471 @@ static int cd_play_audio (uae_u32 startmsf, uae_u32 endmsf, int scan) static uae_u32 last_play_pos; static int cd_qcode (uae_u8 *d) { - uae_u8 *buf, *s, as; - - if (d) - memset (d, 0, 11); - last_play_pos = 0; - if (!qcode_valid) - return 0; - buf = qcode_buf; - as = buf[1]; - if (as != 0x11 && as != 0x12 && as != 0x13 && as != 0x15) /* audio status ok? */ - return 0; - s = buf + 4; - last_play_pos = (s[5] << 16) | (s[6] << 8) | (s[7] << 0); - if (!d) - return 0; - /* ??? */ - d[0] = 0; - /* CtlAdr */ - d[1] = (s[1] >> 4) | (s[1] << 4); - /* Track */ - d[2] = tobcd (s[2]); - /* Index */ - d[3] = tobcd (s[3]); - /* TrackPos */ - d[4] = tobcd (s[9]); - d[5] = tobcd (s[10]); - d[6] = tobcd (s[11]); - /* DiskPos */ - d[7] = 0; - d[8] = tobcd (s[5]); - d[9] = tobcd (s[6]); - d[10] = tobcd (s[7]); - if (as == 0x15) { - /* Make sure end of disc position is not missed. - */ - int lsn = msf2lsn ((s[5] << 16) | (s[6] << 8) | (s[7] << 0)); - int msf = lsn2msf (cdrom_leadout); - if (lsn >= cdrom_leadout || cdrom_leadout - lsn < 10) { - d[8] = tobcd ((uae_u8)(msf >> 16)); - d[9] = tobcd ((uae_u8)(msf >> 8)); - d[10] = tobcd ((uae_u8)(msf >> 0)); + uae_u8 *buf, *s, as; + + if (d) + memset (d, 0, 11); + last_play_pos = 0; + if (!qcode_valid) + return 0; + buf = qcode_buf; + as = buf[1]; + if (as != 0x11 && as != 0x12 && as != 0x13 && as != 0x15) /* audio status ok? */ + return 0; + s = buf + 4; + last_play_pos = (s[5] << 16) | (s[6] << 8) | (s[7] << 0); + if (!d) + return 0; + /* ??? */ + d[0] = 0; + /* CtlAdr */ + d[1] = (s[1] >> 4) | (s[1] << 4); + /* Track */ + d[2] = tobcd (s[2]); + /* Index */ + d[3] = tobcd (s[3]); + /* TrackPos */ + d[4] = tobcd (s[9]); + d[5] = tobcd (s[10]); + d[6] = tobcd (s[11]); + /* DiskPos */ + d[7] = 0; + d[8] = tobcd (s[5]); + d[9] = tobcd (s[6]); + d[10] = tobcd (s[7]); + if (as == 0x15) { + /* Make sure end of disc position is not missed. + */ + int lsn = msf2lsn ((s[5] << 16) | (s[6] << 8) | (s[7] << 0)); + int msf = lsn2msf (cdrom_leadout); + if (lsn >= cdrom_leadout || cdrom_leadout - lsn < 10) { + d[8] = tobcd ((uae_u8)(msf >> 16)); + d[9] = tobcd ((uae_u8)(msf >> 8)); + d[10] = tobcd ((uae_u8)(msf >> 0)); + } } - } - return 0; + return 0; } /* read toc */ static int cdrom_toc (void) { - int i, j; - int datatrack = 0, secondtrack = 0; - uae_u8 *s, *d, *buf; - - cdrom_toc_counter = -1; - cdrom_toc_entries = 0; - buf = sys_command_cd_toc (DF_IOCTL, unitnum); - if (!buf) - return 1; - i = (buf[0] << 8) | (buf[1] << 0); - i -= 2; - i /= 11; - if (i > MAX_TOC_ENTRIES) - return -1; - cdrom_toc_entries = i; - memset (cdrom_toc_buffer, 0, MAX_TOC_ENTRIES * 13); - memcpy (cdrom_toc_cd_buffer, buf, 4 + cdrom_toc_entries * 11); - cdrom_data_end = -1; - for (j = 0; j < cdrom_toc_entries; j++) { - uae_u32 addr; - s = buf + 4 + j * 11; - d = &cdrom_toc_buffer[j * 13]; - addr = msf2lsn ((s[8] << 16) | (s[9] << 8) | (s[10] << 0)); - d[1] = (s[1] >> 4) | (s[1] << 4); - d[3] = s[3] < 100 ? tobcd(s[3]) : s[3]; - d[8] = tobcd (s[8]); - d[9] = tobcd (s[9]); - d[10] = tobcd (s[10]); - if (s[3] == 1 && (s[1] & 0x0c) == 0x04) - datatrack = 1; - if (s[3] == 2) - secondtrack = addr; - if (s[3] == 0xa2) - cdrom_leadout = addr; - } - cdrom_toc_crc = get_crc32(cdrom_toc_buffer, cdrom_toc_entries * 13); - if (datatrack) { - if (secondtrack) - cdrom_data_end = secondtrack; - else - cdrom_data_end = cdrom_leadout; - } - return 0; + int i, j; + int datatrack = 0, secondtrack = 0; + uae_u8 *s, *d, *buf; + + cdrom_toc_counter = -1; + cdrom_toc_entries = 0; + buf = sys_command_cd_toc (DF_IOCTL, unitnum); + if (!buf) + return 1; + i = (buf[0] << 8) | (buf[1] << 0); + i -= 2; + i /= 11; + if (i > MAX_TOC_ENTRIES) + return -1; + cdrom_toc_entries = i; + memset (cdrom_toc_buffer, 0, MAX_TOC_ENTRIES * 13); + memcpy (cdrom_toc_cd_buffer, buf, 4 + cdrom_toc_entries * 11); + cdrom_data_end = -1; + for (j = 0; j < cdrom_toc_entries; j++) { + uae_u32 addr; + s = buf + 4 + j * 11; + d = &cdrom_toc_buffer[j * 13]; + addr = msf2lsn ((s[8] << 16) | (s[9] << 8) | (s[10] << 0)); + d[1] = (s[1] >> 4) | (s[1] << 4); + d[3] = s[3] < 100 ? tobcd(s[3]) : s[3]; + d[8] = tobcd (s[8]); + d[9] = tobcd (s[9]); + d[10] = tobcd (s[10]); + if (s[3] == 1 && (s[1] & 0x0c) == 0x04) + datatrack = 1; + if (s[3] == 2) + secondtrack = addr; + if (s[3] == 0xa2) + cdrom_leadout = addr; + } + cdrom_toc_crc = get_crc32(cdrom_toc_buffer, cdrom_toc_entries * 13); + if (datatrack) { + if (secondtrack) + cdrom_data_end = secondtrack; + else + cdrom_data_end = cdrom_leadout; + } + return 0; } /* open device */ static int sys_cddev_open (void) { - int first = -1; - struct device_info di1, *di2; - int cd32unit = -1; - int audiounit = -1; - - for (unitnum = 0; unitnum < MAX_TOTAL_DEVICES; unitnum++) { - if (sys_command_open (DF_IOCTL, unitnum)) { - di2 = sys_command_info (DF_IOCTL, unitnum, &di1); - if (di2 && di2->type == INQ_ROMD) { - write_log (L"%s: ", di2->label); - if (first < 0) - first = unitnum; - if (!cdrom_toc ()) { - if (cdrom_data_end > 0) { - uae_u8 *p = sys_command_cd_read (DF_IOCTL, unitnum, 16); - if (p) { - if (!memcmp (p + 8, "CDTV", 4) || !memcmp (p + 8, "CD32", 4)) { - uae_u32 crc; - write_log (L"CD32 or CDTV"); - if (cd32unit < 0) - cd32unit = unitnum; - p = sys_command_cd_read (DF_IOCTL, unitnum, 21); - crc = get_crc32 (p, 2048); - if (crc == 0xe56c340f) - write_log (L" [CD32.TM]"); - write_log (L"\n"); - } else { - write_log (L"non CD32/CDTV data CD\n"); - } - } else { - write_log (L"read error\n"); + int first = -1; + struct device_info di1, *di2; + int cd32unit = -1; + int audiounit = -1; + + for (unitnum = 0; unitnum < MAX_TOTAL_DEVICES; unitnum++) { + if (sys_command_open (DF_IOCTL, unitnum)) { + di2 = sys_command_info (DF_IOCTL, unitnum, &di1); + if (di2 && di2->type == INQ_ROMD) { + write_log (L"%s: ", di2->label); + if (first < 0) + first = unitnum; + if (!cdrom_toc ()) { + if (cdrom_data_end > 0) { + uae_u8 *p = sys_command_cd_read (DF_IOCTL, unitnum, 16); + if (p) { + if (!memcmp (p + 8, "CDTV", 4) || !memcmp (p + 8, "CD32", 4)) { + uae_u32 crc; + write_log (L"CD32 or CDTV"); + if (cd32unit < 0) + cd32unit = unitnum; + p = sys_command_cd_read (DF_IOCTL, unitnum, 21); + crc = get_crc32 (p, 2048); + if (crc == 0xe56c340f) + write_log (L" [CD32.TM]"); + write_log (L"\n"); + } else { + write_log (L"non CD32/CDTV data CD\n"); + } + } else { + write_log (L"read error\n"); + } + } else { + write_log (L"Audio CD\n"); + if (audiounit < 0) + audiounit = unitnum; + } + } else { + write_log (L"can't read TOC\n"); + } } - } else { - write_log (L"Audio CD\n"); - if (audiounit < 0) - audiounit = unitnum; - } - } else { - write_log (L"can't read TOC\n"); + sys_command_close (DF_IOCTL, unitnum); } - } - sys_command_close (DF_IOCTL, unitnum); } - } - unitnum = audiounit; - if (cd32unit >= 0) - unitnum = cd32unit; - if (unitnum < 0) - unitnum = first; - if (unitnum < 0) - return 1; - if (!sys_command_open (DF_IOCTL, unitnum)) - write_log (L"re-opening unit %d failed!\n", unitnum); - di2 = sys_command_info (DF_IOCTL, unitnum, &di1); - if (!di2) { - write_log (L"unit %d info failed\n", unitnum); - sys_command_close (DF_IOCTL, unitnum); - return 1; - } - if (!sys_command_ismedia (DF_IOCTL, unitnum, 0)) - cd_hunt = 1; - write_log (L"using drive %s (unit %d, media %d)\n", di2->label, unitnum, di2->media_inserted); - /* make sure CD audio is not playing */ - cdaudiostop_do (); - return 0; + unitnum = audiounit; + if (cd32unit >= 0) + unitnum = cd32unit; + if (unitnum < 0) + unitnum = first; + if (unitnum < 0) + return 1; + if (!sys_command_open (DF_IOCTL, unitnum)) + write_log (L"re-opening unit %d failed!\n", unitnum); + di2 = sys_command_info (DF_IOCTL, unitnum, &di1); + if (!di2) { + write_log (L"unit %d info failed\n", unitnum); + sys_command_close (DF_IOCTL, unitnum); + return 1; + } + if (!sys_command_ismedia (DF_IOCTL, unitnum, 0)) + cd_hunt = 1; + write_log (L"using drive %s (unit %d, media %d)\n", di2->label, unitnum, di2->media_inserted); + /* make sure CD audio is not playing */ + cdaudiostop_do (); + return 0; } /* close device */ static void sys_cddev_close (void) { - cdaudiostop_do (); - sys_command_close (DF_IOCTL, unitnum); + cdaudiostop_do (); + sys_command_close (DF_IOCTL, unitnum); } static int command_lengths[] = { 1,2,1,1,12,2,1,1,4,1,-1,-1,-1,-1,-1,-1 }; static void cdrom_start_return_data (int len) { - if (len <= 0 || cdrom_receive_started > 0) - return; - cdrom_receive_started = len; + if (len <= 0 || cdrom_receive_started > 0) + return; + cdrom_receive_started = len; } static void cdrom_return_data (void) { - uae_u32 cmd_buf = cdrx_address; - int i; - uae_u8 checksum; - int len = cdrom_receive_started; - - if (!len) - return; - if (!(cdrom_flags & CDFLAG_RXD)) - return; + uae_u32 cmd_buf = cdrx_address; + int i; + uae_u8 checksum; + int len = cdrom_receive_started; + + if (!len) + return; + if (!(cdrom_flags & CDFLAG_RXD)) + return; #if AKIKO_DEBUG_IO_CMD - write_log (L"OUT:"); + write_log (L"OUT:"); #endif - checksum = 0xff; - for (i = 0; i < len; i++) { - checksum -= cdrom_result_buffer[i]; - put_byte (cmd_buf + ((cdcomrxinx + i) & 0xff), cdrom_result_buffer[i]); + checksum = 0xff; + for (i = 0; i < len; i++) { + checksum -= cdrom_result_buffer[i]; + put_byte (cmd_buf + ((cdcomrxinx + i) & 0xff), cdrom_result_buffer[i]); #if AKIKO_DEBUG_IO_CMD - write_log (L"%02X ", cdrom_result_buffer[i]); + write_log (L"%02X ", cdrom_result_buffer[i]); #endif - } - put_byte (cmd_buf + ((cdcomrxinx + len) & 0xff), checksum); + } + put_byte (cmd_buf + ((cdcomrxinx + len) & 0xff), checksum); #if AKIKO_DEBUG_IO_CMD - write_log (L"%02X\n", checksum); + write_log (L"%02X\n", checksum); #endif - cdcomrxinx += len + 1; - cdcomrxinx &= 0xff; - set_status (CDINTERRUPT_RXDMADONE); - cdrom_receive_started = 0; + cdcomrxinx += len + 1; + cdcomrxinx &= 0xff; + set_status (CDINTERRUPT_RXDMADONE); + cdrom_receive_started = 0; } static int cdrom_command_led (void) { - int v = cdrom_command_buffer[1]; - int old = cdrom_led; - cdrom_led &= ~1; - cdrom_led |= v & 1; - if (cdrom_led != old) - gui_cd_led (0, cdrom_led); - if (v & 0x80) { // result wanted? - cdrom_result_buffer[0] = cdrom_command; - cdrom_result_buffer[1] = cdrom_led & 1; - return 2; - } - return 0; + int v = cdrom_command_buffer[1]; + int old = cdrom_led; + cdrom_led &= ~1; + cdrom_led |= v & 1; + if (cdrom_led != old) + gui_cd_led (0, cdrom_led); + if (v & 0x80) { // result wanted? + cdrom_result_buffer[0] = cdrom_command; + cdrom_result_buffer[1] = cdrom_led & 1; + return 2; + } + return 0; } static int cdrom_command_media_status (void) { - cdrom_result_buffer[0] = 10; - cdrom_result_buffer[1] = sys_command_ismedia (DF_IOCTL, unitnum, 0); - return 2; + cdrom_result_buffer[0] = 10; + cdrom_result_buffer[1] = sys_command_ismedia (DF_IOCTL, unitnum, 0); + return 2; } /* check if cd drive door is open or closed, return firmware info */ static int cdrom_command_status (void) { - cdrom_result_buffer[1] = 0x01; - //cdrom_result_buffer[1] = 0x80; door open - if (unitnum >= 0) - cdrom_toc (); - /* firmware info */ - strcpy (cdrom_result_buffer + 2, FIRMWAREVERSION); - cdrom_result_buffer[0] = cdrom_command; - cd_initialized = 1; - return 20; + cdrom_result_buffer[1] = 0x01; + //cdrom_result_buffer[1] = 0x80; door open + if (unitnum >= 0) + cdrom_toc (); + /* firmware info */ + strcpy (cdrom_result_buffer + 2, FIRMWAREVERSION); + cdrom_result_buffer[0] = cdrom_command; + cd_initialized = 1; + return 20; } /* return one TOC entry */ static int cdrom_return_toc_entry (void) { - cdrom_result_buffer[0] = 6; - if (cdrom_toc_entries == 0) { - cdrom_result_buffer[1] = CDS_ERROR; + cdrom_result_buffer[0] = 6; + if (cdrom_toc_entries == 0) { + cdrom_result_buffer[1] = CDS_ERROR; + return 15; + } + cdrom_result_buffer[1] = 0; + memcpy (cdrom_result_buffer + 2, cdrom_toc_buffer + cdrom_toc_counter * 13, 13); + cdrom_toc_counter++; + if (cdrom_toc_counter >= cdrom_toc_entries) + cdrom_toc_counter = -1; return 15; - } - cdrom_result_buffer[1] = 0; - memcpy (cdrom_result_buffer + 2, cdrom_toc_buffer + cdrom_toc_counter * 13, 13); - cdrom_toc_counter++; - if (cdrom_toc_counter >= cdrom_toc_entries) - cdrom_toc_counter = -1; - return 15; } static int checkerr (void) { - if (!cdrom_disk) { - cdrom_result_buffer[1] = CH_ERR_NODISK; - return 1; - } - return 0; + if (!cdrom_disk) { + cdrom_result_buffer[1] = CH_ERR_NODISK; + return 1; + } + return 0; } /* pause CD audio */ static int cdrom_command_pause (void) { - cdrom_toc_counter = -1; - cdrom_result_buffer[0] = cdrom_command; - if (checkerr ()) - return 2; - cdrom_result_buffer[1] = cdrom_playing ? CDS_PLAYING : 0; - if (!cdrom_playing) - return 2; - if (cdrom_paused) + cdrom_toc_counter = -1; + cdrom_result_buffer[0] = cdrom_command; + if (checkerr ()) + return 2; + cdrom_result_buffer[1] = cdrom_playing ? CDS_PLAYING : 0; + if (!cdrom_playing) + return 2; + if (cdrom_paused) + return 2; + cdrom_audiotimeout = 0; + write_comm_pipe_u32 (&requests, 0x102, 1); + cdrom_paused = 1; return 2; - cdrom_audiotimeout = 0; - write_comm_pipe_u32 (&requests, 0x102, 1); - cdrom_paused = 1; - return 2; } /* unpause CD audio */ static int cdrom_command_unpause (void) { - cdrom_result_buffer[0] = cdrom_command; - if (checkerr ()) - return 2; - cdrom_result_buffer[1] = cdrom_playing ? CDS_PLAYING : 0; - if (!cdrom_paused) - return 2; - if (!cdrom_playing) + cdrom_result_buffer[0] = cdrom_command; + if (checkerr ()) + return 2; + cdrom_result_buffer[1] = cdrom_playing ? CDS_PLAYING : 0; + if (!cdrom_paused) + return 2; + if (!cdrom_playing) + return 2; + cdrom_paused = 0; + write_comm_pipe_u32 (&requests, 0x103, 1); return 2; - cdrom_paused = 0; - write_comm_pipe_u32 (&requests, 0x103, 1); - return 2; } /* seek head/play CD audio/read data sectors */ static int cdrom_command_multi (void) { - int seekpos = fromlongbcd (cdrom_command_buffer + 1); - int endpos = fromlongbcd (cdrom_command_buffer + 4); - - if (cdrom_playing) - cdaudiostop (); - cdrom_speed = (cdrom_command_buffer[8] & 0x40) ? 2 : 1; - cdrom_result_buffer[0] = cdrom_command; - cdrom_result_buffer[1] = 0; - if (!cdrom_disk) { - cdrom_result_buffer[1] = 1; // no disk - return 2; - } - - if (cdrom_command_buffer[7] == 0x80) { /* data read */ - int cdrom_data_offset_end = msf2lsn (endpos); - cdrom_data_offset = msf2lsn (seekpos); - cdrom_seek_delay = abs (cdrom_current_sector - cdrom_data_offset); - if (cdrom_seek_delay < 100) { - cdrom_seek_delay = 1; - } else { - cdrom_seek_delay /= 1000; - cdrom_seek_delay += 10; - if (cdrom_seek_delay > 100) - cdrom_seek_delay = 100; + int seekpos = fromlongbcd (cdrom_command_buffer + 1); + int endpos = fromlongbcd (cdrom_command_buffer + 4); + + if (cdrom_playing) + cdaudiostop (); + cdrom_speed = (cdrom_command_buffer[8] & 0x40) ? 2 : 1; + cdrom_result_buffer[0] = cdrom_command; + cdrom_result_buffer[1] = 0; + if (!cdrom_disk) { + cdrom_result_buffer[1] = 1; // no disk + return 2; } + + if (cdrom_command_buffer[7] == 0x80) { /* data read */ + int cdrom_data_offset_end = msf2lsn (endpos); + cdrom_data_offset = msf2lsn (seekpos); + cdrom_seek_delay = abs (cdrom_current_sector - cdrom_data_offset); + if (cdrom_seek_delay < 100) { + cdrom_seek_delay = 1; + } else { + cdrom_seek_delay /= 1000; + cdrom_seek_delay += 10; + if (cdrom_seek_delay > 100) + cdrom_seek_delay = 100; + } #if AKIKO_DEBUG_IO_CMD - write_log (L"READ DATA %06X (%d) - %06X (%d) SPD=%dx PC=%08X\n", - seekpos, cdrom_data_offset, endpos, cdrom_data_offset_end, cdrom_speed, M68K_GETPC); + write_log (L"READ DATA %06X (%d) - %06X (%d) SPD=%dx PC=%08X\n", + seekpos, cdrom_data_offset, endpos, cdrom_data_offset_end, cdrom_speed, M68K_GETPC); #endif - cdrom_result_buffer[1] |= 0x02; - } else if (cdrom_command_buffer[10] & 4) { /* play audio */ - int scan = 0; - if (cdrom_command_buffer[7] & 0x04) - scan = 1; - else if (cdrom_command_buffer[7] & 0x08) - scan = -1; + cdrom_result_buffer[1] |= 0x02; + } else if (cdrom_command_buffer[10] & 4) { /* play audio */ + int scan = 0; + if (cdrom_command_buffer[7] & 0x04) + scan = 1; + else if (cdrom_command_buffer[7] & 0x08) + scan = -1; #if AKIKO_DEBUG_IO_CMD - write_log (L"PLAY FROM %06X (%d) to %06X (%d) SCAN=%d\n", - seekpos, msf2lsn (seekpos), endpos, msf2lsn (endpos), scan); + write_log (L"PLAY FROM %06X (%d) to %06X (%d) SCAN=%d\n", + seekpos, msf2lsn (seekpos), endpos, msf2lsn (endpos), scan); #endif - if (!cd_play_audio (seekpos, endpos, 0)) { - cdrom_result_buffer[1] = CDS_ERROR; + if (!cd_play_audio (seekpos, endpos, 0)) { + cdrom_result_buffer[1] = CDS_ERROR; + } else { + cdrom_playing = 1; + cdrom_result_buffer[1] |= CDS_PLAYING; + } } else { - cdrom_playing = 1; - cdrom_result_buffer[1] |= CDS_PLAYING; - } - } else { #if AKIKO_DEBUG_IO_CMD - write_log (L"SEEKTO %06X\n",seekpos); + write_log (L"SEEKTO %06X\n",seekpos); #endif - if (seekpos < 150) - cdrom_toc_counter = 0; - else - cdrom_toc_counter = -1; - } - return 2; + if (seekpos < 150) + cdrom_toc_counter = 0; + else + cdrom_toc_counter = -1; + } + return 2; } /* return subq entry */ static int cdrom_command_subq (void) { - cdrom_result_buffer[0] = cdrom_command; - cdrom_result_buffer[1] = 0; - if (cd_qcode (cdrom_result_buffer + 2)) - cdrom_result_buffer[1] = CDS_ERROR; - return 15; + cdrom_result_buffer[0] = cdrom_command; + cdrom_result_buffer[1] = 0; + if (cd_qcode (cdrom_result_buffer + 2)) + cdrom_result_buffer[1] = CDS_ERROR; + return 15; } static void cdrom_run_command (void) { - int i, cmd_len; - uae_u8 checksum; - uae_u8 *pp = get_real_address (cdtx_address); - - for (;;) { - if (cdrom_command_active) - return; - if (cdcomtxinx == cdcomtxcmp) - return; - cdrom_command = get_byte (cdtx_address + cdcomtxinx); - if ((cdrom_command & 0xf0) == 0) { - cdcomtxinx = (cdcomtxinx + 1) & 0xff; - return; - } - cdrom_checksum_error = 0; - cmd_len = command_lengths[cdrom_command & 0x0f]; - if (cmd_len < 0) { + int i, cmd_len; + uae_u8 checksum; + uae_u8 *pp = get_real_address (cdtx_address); + + for (;;) { + if (cdrom_command_active) + return; + if (cdcomtxinx == cdcomtxcmp) + return; + cdrom_command = get_byte (cdtx_address + cdcomtxinx); + if ((cdrom_command & 0xf0) == 0) { + cdcomtxinx = (cdcomtxinx + 1) & 0xff; + return; + } + cdrom_checksum_error = 0; + cmd_len = command_lengths[cdrom_command & 0x0f]; + if (cmd_len < 0) { #if AKIKO_DEBUG_IO_CMD - write_log (L"unknown command\n"); + write_log (L"unknown command\n"); #endif - cmd_len = 1; - } + cmd_len = 1; + } #if AKIKO_DEBUG_IO_CMD - write_log (L"IN:"); + write_log (L"IN:"); #endif - checksum = 0; - for (i = 0; i < cmd_len + 1; i++) { - cdrom_command_buffer[i] = get_byte (cdtx_address + ((cdcomtxinx + i) & 0xff)); - checksum += cdrom_command_buffer[i]; + checksum = 0; + for (i = 0; i < cmd_len + 1; i++) { + cdrom_command_buffer[i] = get_byte (cdtx_address + ((cdcomtxinx + i) & 0xff)); + checksum += cdrom_command_buffer[i]; #if AKIKO_DEBUG_IO_CMD - write_log (L"%02X ", cdrom_command_buffer[i]); + write_log (L"%02X ", cdrom_command_buffer[i]); #endif - } - if (checksum != 0xff) { + } + if (checksum != 0xff) { #if AKIKO_DEBUG_IO_CMD - write_log (L" checksum error"); + write_log (L" checksum error"); #endif - cdrom_checksum_error = 1; - } + cdrom_checksum_error = 1; + } #if AKIKO_DEBUG_IO_CMD - write_log (L"\n"); + write_log (L"\n"); #endif - cdrom_command_active = 1; - cdrom_command_length = cmd_len; - set_status (CDINTERRUPT_TXDMADONE); - return; - } + cdrom_command_active = 1; + cdrom_command_length = cmd_len; + set_status (CDINTERRUPT_TXDMADONE); + return; + } } static void cdrom_run_command_run (void) { - int len; + int len; - cdcomtxinx = (cdcomtxinx + cdrom_command_length + 1) & 0xff; - memset (cdrom_result_buffer, 0, sizeof (cdrom_result_buffer)); - switch (cdrom_command & 0x0f) - { + cdcomtxinx = (cdcomtxinx + cdrom_command_length + 1) & 0xff; + memset (cdrom_result_buffer, 0, sizeof (cdrom_result_buffer)); + switch (cdrom_command & 0x0f) + { case 2: - len = cdrom_command_pause (); - break; + len = cdrom_command_pause (); + break; case 3: - len = cdrom_command_unpause (); - break; + len = cdrom_command_unpause (); + break; case 4: - len = cdrom_command_multi (); - break; + len = cdrom_command_multi (); + break; case 5: - cdrom_dosomething = 1; // this is a hack - len = cdrom_command_led (); - break; + cdrom_dosomething = 1; // this is a hack + len = cdrom_command_led (); + break; case 6: - len = cdrom_command_subq (); - break; + len = cdrom_command_subq (); + break; case 7: - len = cdrom_command_status (); - break; + len = cdrom_command_status (); + break; default: - len = 0; - break; - } - if (len == 0) - return; - if (cdrom_checksum_error) - cdrom_result_buffer[1] |= 0x80; - cdrom_start_return_data (len); + len = 0; + break; + } + if (len == 0) + return; + if (cdrom_checksum_error) + cdrom_result_buffer[1] |= 0x80; + cdrom_start_return_data (len); } extern void encode_l2 (uae_u8 *p, int address); @@ -1019,62 +1019,62 @@ extern void encode_l2 (uae_u8 *p, int address); /* DMA transfer one CD sector */ static void cdrom_run_read (void) { - int i, sector, inc; - int read = 0; - int sec; - static int seccnt; - - if (!(cdrom_flags & CDFLAG_ENABLE)) - return; - if (!cdrom_pbx) { - set_status (CDINTERRUPT_OVERFLOW); - return; - } - if (!(cdrom_flags & CDFLAG_PBX)) - return; - if (cdrom_data_offset < 0) - return; - if (unitnum < 0) - return; - - inc = 1; - // always use highest available slot or Lotus 3 (Lotus Trilogy) fails to load - for (seccnt = 15; seccnt >= 0; seccnt--) { - if (cdrom_pbx & (1 << seccnt)) - break; - } - sector = cdrom_current_sector = cdrom_data_offset + cdrom_sector_counter; - sec = sector - sector_buffer_sector_1; - if (sector_buffer_sector_1 >= 0 && sec >= 0 && sec < SECTOR_BUFFER_SIZE) { - if (sector_buffer_info_1[sec] != 0xff && sector_buffer_info_1[sec] != 0) { - uae_u8 buf[2352]; - - memcpy (buf + 16, sector_buffer_1 + sec * 2048, 2048); - encode_l2 (buf, sector + 150); - buf[0] = 0; - buf[1] = 0; - buf[2] = 0; - buf[3] = cdrom_sector_counter & 31; - for (i = 0; i < 2352; i++) - put_byte (cdrom_addressdata + seccnt * 4096 + i, buf[i]); - for (i = 0; i < 73 * 2; i++) - put_byte (cdrom_addressdata + seccnt * 4096 + 0xc00 + i, 0); - cdrom_pbx &= ~(1 << seccnt); - set_status (CDINTERRUPT_PBX); - } else { - inc = 0; + int i, sector, inc; + int read = 0; + int sec; + static int seccnt; + + if (!(cdrom_flags & CDFLAG_ENABLE)) + return; + if (!cdrom_pbx) { + set_status (CDINTERRUPT_OVERFLOW); + return; } - if (sector_buffer_info_1[sec] != 0xff) - sector_buffer_info_1[sec]--; + if (!(cdrom_flags & CDFLAG_PBX)) + return; + if (cdrom_data_offset < 0) + return; + if (unitnum < 0) + return; + + inc = 1; + // always use highest available slot or Lotus 3 (Lotus Trilogy) fails to load + for (seccnt = 15; seccnt >= 0; seccnt--) { + if (cdrom_pbx & (1 << seccnt)) + break; + } + sector = cdrom_current_sector = cdrom_data_offset + cdrom_sector_counter; + sec = sector - sector_buffer_sector_1; + if (sector_buffer_sector_1 >= 0 && sec >= 0 && sec < SECTOR_BUFFER_SIZE) { + if (sector_buffer_info_1[sec] != 0xff && sector_buffer_info_1[sec] != 0) { + uae_u8 buf[2352]; + + memcpy (buf + 16, sector_buffer_1 + sec * 2048, 2048); + encode_l2 (buf, sector + 150); + buf[0] = 0; + buf[1] = 0; + buf[2] = 0; + buf[3] = cdrom_sector_counter & 31; + for (i = 0; i < 2352; i++) + put_byte (cdrom_addressdata + seccnt * 4096 + i, buf[i]); + for (i = 0; i < 73 * 2; i++) + put_byte (cdrom_addressdata + seccnt * 4096 + 0xc00 + i, 0); + cdrom_pbx &= ~(1 << seccnt); + set_status (CDINTERRUPT_PBX); + } else { + inc = 0; + } + if (sector_buffer_info_1[sec] != 0xff) + sector_buffer_info_1[sec]--; #if AKIKO_DEBUG_IO_CMD - write_log (L"read sector=%d, scnt=%d -> %d. %08X\n", - cdrom_data_offset, cdrom_sector_counter, sector, cdrom_addressdata + seccnt * 4096); + write_log (L"read sector=%d, scnt=%d -> %d. %08X\n", + cdrom_data_offset, cdrom_sector_counter, sector, cdrom_addressdata + seccnt * 4096); #endif - } else { - inc = 0; - } - if (inc) - cdrom_sector_counter++; + } else { + inc = 0; + } + if (inc) + cdrom_sector_counter++; } static uae_sem_t akiko_sem; @@ -1082,247 +1082,247 @@ static int lastmediastate = 0; static void akiko_handler (void) { - if (unitnum < 0) - return; - if (!cd_initialized || cdrom_receive_started) - return; + if (unitnum < 0) + return; + if (!cd_initialized || cdrom_receive_started) + return; #if 0 - if (cdrom_result_complete > cdcomrxcmp && cdrom_result_complete - cdcomrxcmp < 100) { - //set_status (CDINTERRUPT_RXDMADONE); - return; - } - if (cdcomrxcmp < cdrom_result_complete) - return; + if (cdrom_result_complete > cdcomrxcmp && cdrom_result_complete - cdcomrxcmp < 100) { + //set_status (CDINTERRUPT_RXDMADONE); + return; + } + if (cdcomrxcmp < cdrom_result_complete) + return; #endif - if (mediachanged) { - mediachanged = 0; - cdrom_start_return_data (cdrom_command_media_status ()); - if (!lastmediastate) - cd_hunt = 1; - cdrom_toc (); - /* do not remove! first try may fail */ - cdrom_toc (); - return; - } - if (cdrom_toc_counter >= 0 && !cdrom_command_active && cdrom_dosomething) { - cdrom_start_return_data (cdrom_return_toc_entry ()); - cdrom_dosomething--; - return; - } + if (mediachanged) { + mediachanged = 0; + cdrom_start_return_data (cdrom_command_media_status ()); + if (!lastmediastate) + cd_hunt = 1; + cdrom_toc (); + /* do not remove! first try may fail */ + cdrom_toc (); + return; + } + if (cdrom_toc_counter >= 0 && !cdrom_command_active && cdrom_dosomething) { + cdrom_start_return_data (cdrom_return_toc_entry ()); + cdrom_dosomething--; + return; + } } static void akiko_internal (void) { - if (!currprefs.cs_cd32cd) - return; - cdrom_return_data (); - cdrom_run_command (); - if (cdrom_command_active > 0) { - cdrom_command_active--; - if (!cdrom_command_active) - cdrom_run_command_run (); - } + if (!currprefs.cs_cd32cd) + return; + cdrom_return_data (); + cdrom_run_command (); + if (cdrom_command_active > 0) { + cdrom_command_active--; + if (!cdrom_command_active) + cdrom_run_command_run (); + } } static void do_hunt (void) { - int i; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (sys_command_ismedia (DF_IOCTL, i, 1) > 0) - break; - } - if (i == MAX_TOTAL_DEVICES) - return; - if (unitnum >= 0) { - int ou = unitnum; - unitnum = -1; - sys_command_close (DF_IOCTL, ou); - } - if (sys_command_open (DF_IOCTL, i) > 0) { - unitnum = i; - cd_hunt = 0; - write_log (L"CD32: autodetected unit %d\n", unitnum); - } + int i; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (sys_command_ismedia (DF_IOCTL, i, 1) > 0) + break; + } + if (i == MAX_TOTAL_DEVICES) + return; + if (unitnum >= 0) { + int ou = unitnum; + unitnum = -1; + sys_command_close (DF_IOCTL, ou); + } + if (sys_command_open (DF_IOCTL, i) > 0) { + unitnum = i; + cd_hunt = 0; + write_log (L"CD32: autodetected unit %d\n", unitnum); + } } void AKIKO_hsync_handler (void) { - static int framecounter; + static int framecounter; - if (!currprefs.cs_cd32cd) - return; + if (!currprefs.cs_cd32cd) + return; - if (cd_hunt) { - static int huntcnt; - if (huntcnt <= 0) { - do_hunt (); - huntcnt = 312 * 50 * 2; + if (cd_hunt) { + static int huntcnt; + if (huntcnt <= 0) { + do_hunt (); + huntcnt = 312 * 50 * 2; + } + huntcnt--; } - huntcnt--; - } - framecounter--; - if (framecounter <= 0) { - int i; - if (cdrom_led) { - if (cdrom_playing) - cdrom_led |= LED_CD_AUDIO; - else - cdrom_led &= ~LED_CD_AUDIO; - gui_cd_led (0, cdrom_led); - } - if (cdrom_seek_delay <= 0) { - cdrom_run_read (); - } else { - cdrom_seek_delay--; - } - framecounter = 1000000 / (58 * 75 * cdrom_speed); - if (cdrom_flags & CDFLAG_SUBCODE) { - set_status (CDINTERRUPT_SUBCODE); - if (cdrom_subcodeoffset >= 128) - cdrom_subcodeoffset = 0; - else - cdrom_subcodeoffset = 128; - for (i = 0; i < 100; i += 4) { - put_long (subcode_address + cdrom_subcodeoffset, 0); - cdrom_subcodeoffset += 4; - } + framecounter--; + if (framecounter <= 0) { + int i; + if (cdrom_led) { + if (cdrom_playing) + cdrom_led |= LED_CD_AUDIO; + else + cdrom_led &= ~LED_CD_AUDIO; + gui_cd_led (0, cdrom_led); + } + if (cdrom_seek_delay <= 0) { + cdrom_run_read (); + } else { + cdrom_seek_delay--; + } + framecounter = 1000000 / (63 * 75 * cdrom_speed); + if (cdrom_flags & CDFLAG_SUBCODE) { + set_status (CDINTERRUPT_SUBCODE); + if (cdrom_subcodeoffset >= 128) + cdrom_subcodeoffset = 0; + else + cdrom_subcodeoffset = 128; + for (i = 0; i < 100; i += 4) { + put_long (subcode_address + cdrom_subcodeoffset, 0); + cdrom_subcodeoffset += 4; + } + } } - } - - if (frame2counter > 0) - frame2counter--; - if (mediacheckcounter > 0) - mediacheckcounter--; - - if (cdrom_playing) { - if (cdrom_audiotimeout > 0) { - cdrom_audiotimeout--; - if (cdrom_audiotimeout == 0) { - set_status (CDINTERRUPT_RXDMADONE); - cdrom_playing = 0; - cdrom_result_buffer[1] = 0; - cdrom_start_return_data (2); - } + + if (frame2counter > 0) + frame2counter--; + if (mediacheckcounter > 0) + mediacheckcounter--; + + if (cdrom_playing) { + if (cdrom_audiotimeout > 0) { + cdrom_audiotimeout--; + if (cdrom_audiotimeout == 0) { + set_status (CDINTERRUPT_RXDMADONE); + cdrom_playing = 0; + cdrom_result_buffer[1] = 0; + cdrom_start_return_data (2); + } + } } - } - akiko_internal (); - akiko_handler (); + akiko_internal (); + akiko_handler (); } /* cdrom data buffering thread */ static void *akiko_thread (void *null) { - int i; - uae_u8 *tmp1; - uae_u8 *tmp2; - int tmp3; - uae_u8 *p; - int offset; - int sector; - - while (akiko_thread_running || comm_pipe_has_data (&requests)) { - - if (comm_pipe_has_data (&requests)) { - uae_u32 b = read_comm_pipe_u32_blocking (&requests); - switch (b) - { - case 0x0102: // pause - sys_command_cd_pause (DF_IOCTL, unitnum, 1); - break; - case 0x0103: // unpause - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - break; - case 0x0104: // stop - cdaudiostop_do (); - break; - case 0x0110: // do_play! - cdaudioplay_do (); - break; - } - } + int i; + uae_u8 *tmp1; + uae_u8 *tmp2; + int tmp3; + uae_u8 *p; + int offset; + int sector; + + while (akiko_thread_running || comm_pipe_has_data (&requests)) { + + if (comm_pipe_has_data (&requests)) { + uae_u32 b = read_comm_pipe_u32_blocking (&requests); + switch (b) + { + case 0x0102: // pause + sys_command_cd_pause (DF_IOCTL, unitnum, 1); + break; + case 0x0103: // unpause + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + break; + case 0x0104: // stop + cdaudiostop_do (); + break; + case 0x0110: // do_play! + cdaudioplay_do (); + break; + } + } - if (frame2counter <= 0) { - uae_u8 *s; - frame2counter = 312 * 50 / 2; - s = sys_command_cd_qcode (DF_IOCTL, unitnum); - if (s) { - uae_u8 as = s[1]; - memcpy (qcode_buf, s, sizeof qcode_buf); - qcode_valid = 1; - if (as == AUDIO_STATUS_IN_PROGRESS) { - int lsn = msf2lsn ((s[5 + 4] << 16) | (s[6 + 4] << 8) | (s[7 + 4] << 0)); - //write_log("%d %d (%d %d)\n", lsn, msf2lsn (last_play_end) - lsn, cdrom_leadout, msf2lsn (last_play_end)); - // make sure audio play really ends because not all drives report position accurately - if ((lsn >= cdrom_leadout - 3 * 75 || lsn >= msf2lsn(last_play_end) - 3 * 75) && !cdrom_audiotimeout) { - cdrom_audiotimeout = 3 * 312; - //write_log("audiotimeout starts\n"); - } + if (frame2counter <= 0) { + uae_u8 *s; + frame2counter = 312 * 50 / 2; + s = sys_command_cd_qcode (DF_IOCTL, unitnum); + if (s) { + uae_u8 as = s[1]; + memcpy (qcode_buf, s, sizeof qcode_buf); + qcode_valid = 1; + if (as == AUDIO_STATUS_IN_PROGRESS) { + int lsn = msf2lsn ((s[5 + 4] << 16) | (s[6 + 4] << 8) | (s[7 + 4] << 0)); + //write_log("%d %d (%d %d)\n", lsn, msf2lsn (last_play_end) - lsn, cdrom_leadout, msf2lsn (last_play_end)); + // make sure audio play really ends because not all drives report position accurately + if ((lsn >= cdrom_leadout - 3 * 75 || lsn >= msf2lsn(last_play_end) - 3 * 75) && !cdrom_audiotimeout) { + cdrom_audiotimeout = 3 * 312; + //write_log("audiotimeout starts\n"); + } + } + } } - } - } - if (mediacheckcounter <= 0) { - int media = sys_command_ismedia (DF_IOCTL, unitnum, 1); - mediacheckcounter = 312 * 50 * 2; - if (media != lastmediastate) { - write_log (L"media changed = %d\n", media); - lastmediastate = cdrom_disk = media; - mediachanged = 1; - cdaudiostop_do (); - } - } + if (mediacheckcounter <= 0) { + int media = sys_command_ismedia (DF_IOCTL, unitnum, 1); + mediacheckcounter = 312 * 50 * 2; + if (media != lastmediastate) { + write_log (L"media changed = %d\n", media); + lastmediastate = cdrom_disk = media; + mediachanged = 1; + cdaudiostop_do (); + } + } - uae_sem_wait (&akiko_sem); - sector = cdrom_current_sector; - for (i = 0; i < SECTOR_BUFFER_SIZE; i++) { - if (sector_buffer_info_1[i] == 0xff) - break; - } - if (cdrom_data_end > 0 && sector >= 0 && - (sector_buffer_sector_1 < 0 || sector < sector_buffer_sector_1 || sector >= sector_buffer_sector_1 + SECTOR_BUFFER_SIZE * 2 / 3 || i != SECTOR_BUFFER_SIZE)) { - memset (sector_buffer_info_2, 0, SECTOR_BUFFER_SIZE); + uae_sem_wait (&akiko_sem); + sector = cdrom_current_sector; + for (i = 0; i < SECTOR_BUFFER_SIZE; i++) { + if (sector_buffer_info_1[i] == 0xff) + break; + } + if (cdrom_data_end > 0 && sector >= 0 && + (sector_buffer_sector_1 < 0 || sector < sector_buffer_sector_1 || sector >= sector_buffer_sector_1 + SECTOR_BUFFER_SIZE * 2 / 3 || i != SECTOR_BUFFER_SIZE)) { + memset (sector_buffer_info_2, 0, SECTOR_BUFFER_SIZE); #if AKIKO_DEBUG_IO_CMD - write_log (L"filling buffer sector=%d (max=%d)\n", sector, cdrom_data_end); + write_log (L"filling buffer sector=%d (max=%d)\n", sector, cdrom_data_end); #endif - sector_buffer_sector_2 = sector; - offset = 0; - while (offset < SECTOR_BUFFER_SIZE) { - p = 0; - if (sector < cdrom_data_end) - p = sys_command_cd_read (DF_IOCTL, unitnum, sector); - if (p) - memcpy (sector_buffer_2 + offset * 2048, p, 2048); - sector_buffer_info_2[offset] = p ? 3 : 0; - offset++; - sector++; - } - tmp1 = sector_buffer_info_1; - sector_buffer_info_1 = sector_buffer_info_2; - sector_buffer_info_2 = tmp1; - tmp2 = sector_buffer_1; - sector_buffer_1 = sector_buffer_2; - sector_buffer_2 = tmp2; - tmp3 = sector_buffer_sector_1; - sector_buffer_sector_1 = sector_buffer_sector_2; - sector_buffer_sector_2 = tmp3; + sector_buffer_sector_2 = sector; + offset = 0; + while (offset < SECTOR_BUFFER_SIZE) { + p = 0; + if (sector < cdrom_data_end) + p = sys_command_cd_read (DF_IOCTL, unitnum, sector); + if (p) + memcpy (sector_buffer_2 + offset * 2048, p, 2048); + sector_buffer_info_2[offset] = p ? 3 : 0; + offset++; + sector++; + } + tmp1 = sector_buffer_info_1; + sector_buffer_info_1 = sector_buffer_info_2; + sector_buffer_info_2 = tmp1; + tmp2 = sector_buffer_1; + sector_buffer_1 = sector_buffer_2; + sector_buffer_2 = tmp2; + tmp3 = sector_buffer_sector_1; + sector_buffer_sector_1 = sector_buffer_sector_2; + sector_buffer_sector_2 = tmp3; + } + uae_sem_post (&akiko_sem); + sleep_millis (10); } - uae_sem_post (&akiko_sem); - sleep_millis (10); - } - akiko_thread_running = -1; - return 0; + akiko_thread_running = -1; + return 0; } STATIC_INLINE uae_u8 akiko_get_long (uae_u32 v, int offset) { - return v >> ((3 - offset) * 8); + return v >> ((3 - offset) * 8); } STATIC_INLINE void akiko_put_long (uae_u32 *p, int offset, int v) { - *p &= ~(0xff << ((3 - offset) * 8)); - *p |= v << ((3 - offset) * 8); + *p &= ~(0xff << ((3 - offset) * 8)); + *p |= v << ((3 - offset) * 8); } static uae_u32 REGPARAM3 akiko_lget (uaecptr) REGPARAM; @@ -1336,516 +1336,516 @@ static void REGPARAM3 akiko_bput (uaecptr, uae_u32) REGPARAM; static uae_u32 akiko_bget2 (uaecptr addr, int msg) { - uae_u8 v = 0; + uae_u8 v = 0; - addr &= 0xffff; + addr &= 0xffff; - switch (addr) - { - /* "CAFE" = Akiko identification. - * Kickstart ignores Akiko C2P if this ID isn't correct */ + switch (addr) + { + /* "CAFE" = Akiko identification. + * Kickstart ignores Akiko C2P if this ID isn't correct */ case 0x02: - return 0xCA; + return 0xCA; case 0x03: - return 0xFE; - /* NVRAM */ + return 0xFE; + /* NVRAM */ case 0x30: case 0x31: case 0x32: case 0x33: - if (currprefs.cs_cd32nvram) - v = akiko_nvram_read (addr - 0x30); - return v; + if (currprefs.cs_cd32nvram) + v = akiko_nvram_read (addr - 0x30); + return v; - /* C2P */ + /* C2P */ case 0x38: case 0x39: case 0x3a: case 0x3b: - if (currprefs.cs_cd32c2p) - v = akiko_c2p_read (addr - 0x38); - return v; - } + if (currprefs.cs_cd32c2p) + v = akiko_c2p_read (addr - 0x38); + return v; + } - uae_sem_wait (&akiko_sem); - switch (addr) - { - if (currprefs.cs_cd32cd) { - /* CDROM control */ + uae_sem_wait (&akiko_sem); + switch (addr) + { + if (currprefs.cs_cd32cd) { + /* CDROM control */ case 0x04: case 0x05: case 0x06: case 0x07: - v = akiko_get_long (cdrom_intreq, addr - 0x04); - break; + v = akiko_get_long (cdrom_intreq, addr - 0x04); + break; case 0x08: case 0x09: case 0x0a: case 0x0b: - v = akiko_get_long (cdrom_intena, addr - 0x08); - break; + v = akiko_get_long (cdrom_intena, addr - 0x08); + break; case 0x10: case 0x11: case 0x12: case 0x13: - v = akiko_get_long (cdrom_addressdata, addr - 0x10); - break; + v = akiko_get_long (cdrom_addressdata, addr - 0x10); + break; case 0x14: case 0x15: case 0x16: case 0x17: - v = akiko_get_long (cdrom_addressmisc, addr - 0x14); - break; + v = akiko_get_long (cdrom_addressmisc, addr - 0x14); + break; case 0x18: - v = cdrom_subcodeoffset; - break; + v = cdrom_subcodeoffset; + break; case 0x19: - v = cdcomtxinx; - break; + v = cdcomtxinx; + break; case 0x1a: - v = cdcomrxinx; - break; + v = cdcomrxinx; + break; case 0x20: case 0x21: - v = akiko_get_long (cdrom_pbx, addr - 0x20 + 2); - break; + v = akiko_get_long (cdrom_pbx, addr - 0x20 + 2); + break; case 0x24: case 0x25: case 0x26: case 0x27: - v = akiko_get_long (cdrom_flags, addr - 0x24); - break; - } else if (addr < 0x30) { - break; - } + v = akiko_get_long (cdrom_flags, addr - 0x24); + break; + } else if (addr < 0x30) { + break; + } default: - write_log (L"akiko_bget: unknown address %08X PC=%08X\n", addr, M68K_GETPC); - v = 0; - break; - } - akiko_internal (); - uae_sem_post (&akiko_sem); - if (msg && addr < 0x30 && AKIKO_DEBUG_IO) - write_log (L"akiko_bget %08X: %08X %02X\n", M68K_GETPC, addr, v & 0xff); - return v; + write_log (L"akiko_bget: unknown address %08X PC=%08X\n", addr, M68K_GETPC); + v = 0; + break; + } + akiko_internal (); + uae_sem_post (&akiko_sem); + if (msg && addr < 0x30 && AKIKO_DEBUG_IO) + write_log (L"akiko_bget %08X: %08X %02X\n", M68K_GETPC, addr, v & 0xff); + return v; } static uae_u32 REGPARAM2 akiko_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return akiko_bget2 (addr, 1); + return akiko_bget2 (addr, 1); } static uae_u32 REGPARAM2 akiko_wget (uaecptr addr) { - uae_u16 v; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xffff; - v = akiko_bget2 (addr + 1, 0); - v |= akiko_bget2 (addr + 0, 0) << 8; - if (addr < 0x30 && AKIKO_DEBUG_IO) - write_log (L"akiko_wget %08X: %08X %04X\n", M68K_GETPC, addr, v & 0xffff); - return v; + addr &= 0xffff; + v = akiko_bget2 (addr + 1, 0); + v |= akiko_bget2 (addr + 0, 0) << 8; + if (addr < 0x30 && AKIKO_DEBUG_IO) + write_log (L"akiko_wget %08X: %08X %04X\n", M68K_GETPC, addr, v & 0xffff); + return v; } static uae_u32 REGPARAM2 akiko_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xffff; - v = akiko_bget2 (addr + 3, 0); - v |= akiko_bget2 (addr + 2, 0) << 8; - v |= akiko_bget2 (addr + 1, 0) << 16; - v |= akiko_bget2 (addr + 0, 0) << 24; - if (addr < 0x30 && (addr != 4 && addr != 8) && AKIKO_DEBUG_IO) - write_log (L"akiko_lget %08X: %08X %08X\n", M68K_GETPC, addr, v); - return v; + addr &= 0xffff; + v = akiko_bget2 (addr + 3, 0); + v |= akiko_bget2 (addr + 2, 0) << 8; + v |= akiko_bget2 (addr + 1, 0) << 16; + v |= akiko_bget2 (addr + 0, 0) << 24; + if (addr < 0x30 && (addr != 4 && addr != 8) && AKIKO_DEBUG_IO) + write_log (L"akiko_lget %08X: %08X %08X\n", M68K_GETPC, addr, v); + return v; } static void akiko_bput2 (uaecptr addr, uae_u32 v, int msg) { - uae_u32 tmp; + uae_u32 tmp; - addr &= 0xffff; - v &= 0xff; + addr &= 0xffff; + v &= 0xff; - if(msg && addr < 0x30 && AKIKO_DEBUG_IO) - write_log (L"akiko_bput %08X: %08X=%02X\n", M68K_GETPC, addr, v & 0xff); + if(msg && addr < 0x30 && AKIKO_DEBUG_IO) + write_log (L"akiko_bput %08X: %08X=%02X\n", M68K_GETPC, addr, v & 0xff); - switch (addr) - { + switch (addr) + { case 0x30: case 0x31: case 0x32: case 0x33: - if (currprefs.cs_cd32nvram) - akiko_nvram_write (addr - 0x30, v); - return; + if (currprefs.cs_cd32nvram) + akiko_nvram_write (addr - 0x30, v); + return; case 0x38: case 0x39: case 0x3a: case 0x3b: - if (currprefs.cs_cd32c2p) - akiko_c2p_write (addr - 0x38, v); - return; - } - - uae_sem_wait (&akiko_sem); - switch (addr) - { - if (currprefs.cs_cd32cd) { + if (currprefs.cs_cd32c2p) + akiko_c2p_write (addr - 0x38, v); + return; + } + + uae_sem_wait (&akiko_sem); + switch (addr) + { + if (currprefs.cs_cd32cd) { case 0x04: case 0x05: case 0x06: case 0x07: - akiko_put_long (&cdrom_intreq, addr - 0x04, v); - break; + akiko_put_long (&cdrom_intreq, addr - 0x04, v); + break; case 0x08: case 0x09: case 0x0a: case 0x0b: - akiko_put_long (&cdrom_intena, addr - 0x08, v); - if (addr == 8) - cdrom_intreq &= cdrom_intena; - break; + akiko_put_long (&cdrom_intena, addr - 0x08, v); + if (addr == 8) + cdrom_intreq &= cdrom_intena; + break; case 0x10: case 0x11: case 0x12: case 0x13: - akiko_put_long (&cdrom_addressdata, addr - 0x10, v); - cdrom_addressdata &= 0x00ff0000; - break; + akiko_put_long (&cdrom_addressdata, addr - 0x10, v); + cdrom_addressdata &= 0x00ff0000; + break; case 0x14: case 0x15: case 0x16: case 0x17: - akiko_put_long (&cdrom_addressmisc, addr - 0x14, v); - cdrom_addressmisc &= 0x00fffc00; - subcode_address = cdrom_addressmisc | 0x100; - cdrx_address = cdrom_addressmisc; - cdtx_address = cdrom_addressmisc | 0x200; - break; + akiko_put_long (&cdrom_addressmisc, addr - 0x14, v); + cdrom_addressmisc &= 0x00fffc00; + subcode_address = cdrom_addressmisc | 0x100; + cdrx_address = cdrom_addressmisc; + cdtx_address = cdrom_addressmisc | 0x200; + break; case 0x18: - cdrom_intreq &= ~CDINTERRUPT_SUBCODE; - break; + cdrom_intreq &= ~CDINTERRUPT_SUBCODE; + break; case 0x1d: - cdrom_intreq &= ~CDINTERRUPT_TXDMADONE; - cdcomtxcmp = v; - break; + cdrom_intreq &= ~CDINTERRUPT_TXDMADONE; + cdcomtxcmp = v; + break; case 0x1f: - cdrom_intreq &= ~CDINTERRUPT_RXDMADONE; - break; + cdrom_intreq &= ~CDINTERRUPT_RXDMADONE; + break; case 0x20: case 0x21: - tmp = cdrom_pbx; - akiko_put_long (&cdrom_pbx, addr - 0x20 + 2, v); - cdrom_pbx |= tmp; - cdrom_pbx &= 0xffff; - cdrom_intreq &= ~CDINTERRUPT_PBX; - break; + tmp = cdrom_pbx; + akiko_put_long (&cdrom_pbx, addr - 0x20 + 2, v); + cdrom_pbx |= tmp; + cdrom_pbx &= 0xffff; + cdrom_intreq &= ~CDINTERRUPT_PBX; + break; case 0x24: case 0x25: case 0x26: case 0x27: - tmp = cdrom_flags; - akiko_put_long (&cdrom_flags, addr - 0x24, v); - if ((cdrom_flags & CDFLAG_ENABLE) && !(tmp & CDFLAG_ENABLE)) - cdrom_sector_counter = 0; - if (!(cdrom_flags & CDFLAG_PBX) && (tmp & CDFLAG_PBX)) - cdrom_pbx = 0; - break; - } else if (addr < 0x30) { - break; - } + tmp = cdrom_flags; + akiko_put_long (&cdrom_flags, addr - 0x24, v); + if ((cdrom_flags & CDFLAG_ENABLE) && !(tmp & CDFLAG_ENABLE)) + cdrom_sector_counter = 0; + if (!(cdrom_flags & CDFLAG_PBX) && (tmp & CDFLAG_PBX)) + cdrom_pbx = 0; + break; + } else if (addr < 0x30) { + break; + } default: - write_log (L"akiko_bput: unknown address %08X=%02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); - break; - } - akiko_internal (); - uae_sem_post (&akiko_sem); + write_log (L"akiko_bput: unknown address %08X=%02X PC=%08X\n", addr, v & 0xff, M68K_GETPC); + break; + } + akiko_internal (); + uae_sem_post (&akiko_sem); } static void REGPARAM2 akiko_bput (uaecptr addr, uae_u32 v) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - akiko_bput2 (addr, v, 1); + akiko_bput2 (addr, v, 1); } static void REGPARAM2 akiko_wput (uaecptr addr, uae_u32 v) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 0xfff; - if((addr < 0x30 && AKIKO_DEBUG_IO)) - write_log (L"akiko_wput %08X: %08X=%04X\n", M68K_GETPC, addr, v & 0xffff); - akiko_bput2 (addr + 1, v & 0xff, 0); - akiko_bput2 (addr + 0, v >> 8, 0); + addr &= 0xfff; + if((addr < 0x30 && AKIKO_DEBUG_IO)) + write_log (L"akiko_wput %08X: %08X=%04X\n", M68K_GETPC, addr, v & 0xffff); + akiko_bput2 (addr + 1, v & 0xff, 0); + akiko_bput2 (addr + 0, v >> 8, 0); } static void REGPARAM2 akiko_lput (uaecptr addr, uae_u32 v) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 0xffff; - if(addr < 0x30 && AKIKO_DEBUG_IO) - write_log (L"akiko_lput %08X: %08X=%08X\n", M68K_GETPC, addr, v); - akiko_bput2 (addr + 3, (v >> 0) & 0xff, 0); - akiko_bput2 (addr + 2, (v >> 8) & 0xff, 0); - akiko_bput2 (addr + 1, (v >> 16) & 0xff, 0); - akiko_bput2 (addr + 0, (v >> 24) & 0xff, 0); + addr &= 0xffff; + if(addr < 0x30 && AKIKO_DEBUG_IO) + write_log (L"akiko_lput %08X: %08X=%08X\n", M68K_GETPC, addr, v); + akiko_bput2 (addr + 3, (v >> 0) & 0xff, 0); + akiko_bput2 (addr + 2, (v >> 8) & 0xff, 0); + akiko_bput2 (addr + 1, (v >> 16) & 0xff, 0); + akiko_bput2 (addr + 0, (v >> 24) & 0xff, 0); } addrbank akiko_bank = { - akiko_lget, akiko_wget, akiko_bget, - akiko_lput, akiko_wput, akiko_bput, - default_xlate, default_check, NULL, L"Akiko", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + akiko_lget, akiko_wget, akiko_bget, + akiko_lput, akiko_wput, akiko_bput, + default_xlate, default_check, NULL, L"Akiko", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static void akiko_cdrom_free (void) { - if (unitnum >= 0) - sys_cddev_close (); - unitnum = -1; - xfree (sector_buffer_1); - xfree (sector_buffer_2); - xfree (sector_buffer_info_1); - xfree (sector_buffer_info_2); - sector_buffer_1 = 0; - sector_buffer_2 = 0; - sector_buffer_info_1 = 0; - sector_buffer_info_2 = 0; - cdromok = 0; + if (unitnum >= 0) + sys_cddev_close (); + unitnum = -1; + xfree (sector_buffer_1); + xfree (sector_buffer_2); + xfree (sector_buffer_info_1); + xfree (sector_buffer_info_2); + sector_buffer_1 = 0; + sector_buffer_2 = 0; + sector_buffer_info_1 = 0; + sector_buffer_info_2 = 0; + cdromok = 0; } void akiko_reset (void) { - cdaudiostop_do (); - nvram_read (); - state = I2C_WAIT; - bitcounter = -1; - direction = -1; - - cdrom_speed = 1; - cdrom_current_sector = -1; - cdcomtxinx = 0; - cdcomrxinx = 0; - cdcomtxcmp = 0; - cdrom_led = 0; - lastmediastate = 0; - cdrom_receive_started = 0; - cd_initialized = 0; - - if (akiko_thread_running > 0) { - cdaudiostop (); - akiko_thread_running = 0; - while(akiko_thread_running == 0) - Sleep (10); - akiko_thread_running = 0; - } - akiko_cdrom_free (); + cdaudiostop_do (); + nvram_read (); + state = I2C_WAIT; + bitcounter = -1; + direction = -1; + + cdrom_speed = 1; + cdrom_current_sector = -1; + cdcomtxinx = 0; + cdcomrxinx = 0; + cdcomtxcmp = 0; + cdrom_led = 0; + lastmediastate = 0; + cdrom_receive_started = 0; + cd_initialized = 0; + + if (akiko_thread_running > 0) { + cdaudiostop (); + akiko_thread_running = 0; + while(akiko_thread_running == 0) + Sleep (10); + akiko_thread_running = 0; + } + akiko_cdrom_free (); } void akiko_free (void) { - akiko_reset (); - akiko_cdrom_free (); + akiko_reset (); + akiko_cdrom_free (); } int akiko_init (void) { - if (currprefs.cs_cd32cd && cdromok == 0) { - unitnum = -1; - if (!device_func_init (DEVICE_TYPE_ANY)) { - write_log (L"no CDROM support\n"); - return 0; + if (currprefs.cs_cd32cd && cdromok == 0) { + unitnum = -1; + if (!device_func_init (DEVICE_TYPE_ANY)) { + write_log (L"no CDROM support\n"); + return 0; + } + if (!sys_cddev_open ()) { + cdromok = 1; + sector_buffer_1 = xmalloc (SECTOR_BUFFER_SIZE * 2048); + sector_buffer_2 = xmalloc (SECTOR_BUFFER_SIZE * 2048); + sector_buffer_info_1 = xmalloc (SECTOR_BUFFER_SIZE); + sector_buffer_info_2 = xmalloc (SECTOR_BUFFER_SIZE); + sector_buffer_sector_1 = -1; + sector_buffer_sector_2 = -1; + } } - if (!sys_cddev_open ()) { - cdromok = 1; - sector_buffer_1 = xmalloc (SECTOR_BUFFER_SIZE * 2048); - sector_buffer_2 = xmalloc (SECTOR_BUFFER_SIZE * 2048); - sector_buffer_info_1 = xmalloc (SECTOR_BUFFER_SIZE); - sector_buffer_info_2 = xmalloc (SECTOR_BUFFER_SIZE); - sector_buffer_sector_1 = -1; - sector_buffer_sector_2 = -1; + uae_sem_init (&akiko_sem, 0, 1); + if (!savestate_state) { + cdrom_playing = cdrom_paused = 0; + cdrom_data_offset = -1; } - } - uae_sem_init (&akiko_sem, 0, 1); - if (!savestate_state) { - cdrom_playing = cdrom_paused = 0; - cdrom_data_offset = -1; - } - if (cdromok && !akiko_thread_running) { - akiko_thread_running = 1; - init_comm_pipe (&requests, 100, 1); - uae_start_thread (L"akiko", akiko_thread, 0, NULL); - } - return 1; + if (cdromok && !akiko_thread_running) { + akiko_thread_running = 1; + init_comm_pipe (&requests, 100, 1); + uae_start_thread (L"akiko", akiko_thread, 0, NULL); + } + return 1; } #ifdef SAVESTATE uae_u8 *save_akiko(int *len) { - uae_u8 *dstbak, *dst; - int i; - - if (!currprefs.cs_cd32cd) - return NULL; - - dstbak = dst = malloc (1000); - save_u16 (0); - save_u16 (0xCAFE); - save_u32 (cdrom_intreq); - save_u32 (cdrom_intena); - save_u32 (0); - save_u32 (cdrom_addressdata); - save_u32 (cdrom_addressmisc); - save_u8 (cdrom_subcodeoffset); - save_u8 (cdcomrxinx); - save_u8 (cdcomrxinx); - save_u8 (0); - save_u8 (0); - save_u8 (cdcomtxcmp); - save_u8 (0); - save_u8 (0); - save_u16 ((uae_u16)cdrom_pbx); - save_u16 (0); - save_u32 (cdrom_flags); - save_u32 (0); - save_u32 (0); - save_u32 ((scl_dir ? 0x8000 : 0) | (sda_dir ? 0x4000 : 0)); - save_u32 (0); - save_u32 (0); - - for (i = 0; i < 8; i++) - save_u32 (akiko_buffer[i]); - save_u8 ((uae_u8)akiko_read_offset); - save_u8 ((uae_u8)akiko_write_offset); - - save_u32 ((cdrom_playing ? 1 : 0) | (cdrom_paused ? 2 : 0) | (cdrom_disk ? 4 : 0)); - if (cdrom_playing) - cd_qcode (0); - save_u32 (last_play_pos); - save_u32 (last_play_end); - save_u8 ((uae_u8)cdrom_toc_counter); - - save_u8 (cdrom_speed); - save_u8 (cdrom_current_sector); - - save_u32 (cdrom_toc_crc); - save_u8 (cdrom_toc_entries); - save_u32 (cdrom_leadout); - - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + int i; + + if (!currprefs.cs_cd32cd) + return NULL; + + dstbak = dst = malloc (1000); + save_u16 (0); + save_u16 (0xCAFE); + save_u32 (cdrom_intreq); + save_u32 (cdrom_intena); + save_u32 (0); + save_u32 (cdrom_addressdata); + save_u32 (cdrom_addressmisc); + save_u8 (cdrom_subcodeoffset); + save_u8 (cdcomrxinx); + save_u8 (cdcomrxinx); + save_u8 (0); + save_u8 (0); + save_u8 (cdcomtxcmp); + save_u8 (0); + save_u8 (0); + save_u16 ((uae_u16)cdrom_pbx); + save_u16 (0); + save_u32 (cdrom_flags); + save_u32 (0); + save_u32 (0); + save_u32 ((scl_dir ? 0x8000 : 0) | (sda_dir ? 0x4000 : 0)); + save_u32 (0); + save_u32 (0); + + for (i = 0; i < 8; i++) + save_u32 (akiko_buffer[i]); + save_u8 ((uae_u8)akiko_read_offset); + save_u8 ((uae_u8)akiko_write_offset); + + save_u32 ((cdrom_playing ? 1 : 0) | (cdrom_paused ? 2 : 0) | (cdrom_disk ? 4 : 0)); + if (cdrom_playing) + cd_qcode (0); + save_u32 (last_play_pos); + save_u32 (last_play_end); + save_u8 ((uae_u8)cdrom_toc_counter); + + save_u8 (cdrom_speed); + save_u8 (cdrom_current_sector); + + save_u32 (cdrom_toc_crc); + save_u8 (cdrom_toc_entries); + save_u32 (cdrom_leadout); + + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_akiko (uae_u8 *src) { - uae_u32 v; - int i; - - if (!currprefs.cs_cd32cd) { - changed_prefs.cs_cd32c2p = changed_prefs.cs_cd32cd = changed_prefs.cs_cd32nvram = 1; - currprefs.cs_cd32c2p = currprefs.cs_cd32cd = currprefs.cs_cd32nvram = 1; - akiko_init (); - } - - restore_u16 (); - restore_u16 (); - cdrom_intreq = restore_u32 (); - cdrom_intena = restore_u32 (); - restore_u32 (); - cdrom_addressdata = restore_u32 (); - cdrom_addressmisc = restore_u32 (); - cdrom_subcodeoffset = restore_u8 (); - cdcomtxinx = restore_u8 (); - cdcomrxinx = restore_u8 (); - restore_u8 (); - restore_u8 (); - cdcomtxcmp = restore_u8 (); - restore_u8 (); - restore_u8 (); - cdrom_pbx = restore_u16 (); - restore_u16 (); - cdrom_flags = restore_u32 (); - restore_u32 (); - restore_u32 (); - v = restore_u32 (); - scl_dir = (v & 0x8000) ? 1 : 0; - sda_dir = (v & 0x4000) ? 1 : 0; - restore_u32 (); - restore_u32 (); - - for (i = 0; i < 8; i++) - akiko_buffer[i] = restore_u32 (); - akiko_read_offset = restore_u8 (); - akiko_write_offset = restore_u8 (); - - cdrom_playing = cdrom_paused = 0; - v = restore_u32 (); - if (v & 1) - cdrom_playing = 1; - if (v & 2) - cdrom_paused = 1; + uae_u32 v; + int i; - last_play_pos = restore_u32 (); - last_play_end = restore_u32 (); - cdrom_toc_counter = (uae_s8)restore_u8 (); - cdrom_speed = restore_u8 (); - cdrom_current_sector = (uae_s8)restore_u8 (); + if (!currprefs.cs_cd32cd) { + changed_prefs.cs_cd32c2p = changed_prefs.cs_cd32cd = changed_prefs.cs_cd32nvram = 1; + currprefs.cs_cd32c2p = currprefs.cs_cd32cd = currprefs.cs_cd32nvram = 1; + akiko_init (); + } - restore_u32 (); - restore_u8 (); - restore_u32 (); + restore_u16 (); + restore_u16 (); + cdrom_intreq = restore_u32 (); + cdrom_intena = restore_u32 (); + restore_u32 (); + cdrom_addressdata = restore_u32 (); + cdrom_addressmisc = restore_u32 (); + cdrom_subcodeoffset = restore_u8 (); + cdcomtxinx = restore_u8 (); + cdcomrxinx = restore_u8 (); + restore_u8 (); + restore_u8 (); + cdcomtxcmp = restore_u8 (); + restore_u8 (); + restore_u8 (); + cdrom_pbx = restore_u16 (); + restore_u16 (); + cdrom_flags = restore_u32 (); + restore_u32 (); + restore_u32 (); + v = restore_u32 (); + scl_dir = (v & 0x8000) ? 1 : 0; + sda_dir = (v & 0x4000) ? 1 : 0; + restore_u32 (); + restore_u32 (); + + for (i = 0; i < 8; i++) + akiko_buffer[i] = restore_u32 (); + akiko_read_offset = restore_u8 (); + akiko_write_offset = restore_u8 (); - return src; + cdrom_playing = cdrom_paused = 0; + v = restore_u32 (); + if (v & 1) + cdrom_playing = 1; + if (v & 2) + cdrom_paused = 1; + + last_play_pos = restore_u32 (); + last_play_end = restore_u32 (); + cdrom_toc_counter = (uae_s8)restore_u8 (); + cdrom_speed = restore_u8 (); + cdrom_current_sector = (uae_s8)restore_u8 (); + + restore_u32 (); + restore_u8 (); + restore_u32 (); + + return src; } void restore_akiko_finish (void) { - if (!currprefs.cs_cd32cd) - return; - akiko_c2p_do (); - write_comm_pipe_u32 (&requests, 0x102, 1); // pause - write_comm_pipe_u32 (&requests, 0x104, 1); // stop - write_comm_pipe_u32 (&requests, 0x103, 1); // unpause - if (cdrom_playing) { + if (!currprefs.cs_cd32cd) + return; + akiko_c2p_do (); + write_comm_pipe_u32 (&requests, 0x102, 1); // pause + write_comm_pipe_u32 (&requests, 0x104, 1); // stop write_comm_pipe_u32 (&requests, 0x103, 1); // unpause - write_comm_pipe_u32 (&requests, 0x110, 0); // play - write_comm_pipe_u32 (&requests, last_play_pos, 0); - write_comm_pipe_u32 (&requests, last_play_end, 0); - write_comm_pipe_u32 (&requests, 0, 1); - } + if (cdrom_playing) { + write_comm_pipe_u32 (&requests, 0x103, 1); // unpause + write_comm_pipe_u32 (&requests, 0x110, 0); // play + write_comm_pipe_u32 (&requests, last_play_pos, 0); + write_comm_pipe_u32 (&requests, last_play_end, 0); + write_comm_pipe_u32 (&requests, 0, 1); + } } #endif void akiko_entergui (void) { - if (cdrom_playing) - write_comm_pipe_u32 (&requests, 0x102, 1); + if (cdrom_playing) + write_comm_pipe_u32 (&requests, 0x102, 1); } void akiko_exitgui (void) { - if (cdrom_playing) - write_comm_pipe_u32 (&requests, 0x103, 1); + if (cdrom_playing) + write_comm_pipe_u32 (&requests, 0x103, 1); } diff --git a/amax.c b/amax.c index ce483b9a..e66349db 100644 --- a/amax.c +++ b/amax.c @@ -23,135 +23,135 @@ static uae_u8 dselect; static void load_byte (void) { - int addr, i; - uae_u8 val, v; - - v = 0xff; - addr = 0; - for (i = 0; i < 16; i++) { - if (romptr & (1 << i)) - addr |= 1 << addr_scramble[i]; - } - if (rom_oddeven < 0) { - val = v; - } else { - v = rom[addr * 2 + rom_oddeven]; - val = 0; - for (i = 0; i < 8; i++) { - if (v & (1 << data_scramble[i])) - val |= 1 << i; + int addr, i; + uae_u8 val, v; + + v = 0xff; + addr = 0; + for (i = 0; i < 16; i++) { + if (romptr & (1 << i)) + addr |= 1 << addr_scramble[i]; } - } - data = val; - if (AMAX_LOG > 0) - write_log (L"AMAX: load byte, rom=%d addr=%06x (%06x) data=%02x (%02x) PC=%08X\n", rom_oddeven, romptr, addr, v, val, M68K_GETPC); + if (rom_oddeven < 0) { + val = v; + } else { + v = rom[addr * 2 + rom_oddeven]; + val = 0; + for (i = 0; i < 8; i++) { + if (v & (1 << data_scramble[i])) + val |= 1 << i; + } + } + data = val; + if (AMAX_LOG > 0) + write_log (L"AMAX: load byte, rom=%d addr=%06x (%06x) data=%02x (%02x) PC=%08X\n", rom_oddeven, romptr, addr, v, val, M68K_GETPC); } static void amax_check (void) { - /* DIR low = reset address counter */ - if ((bfd100 & 2)) { - if (romptr && AMAX_LOG > 0) - write_log (L"AMAX: counter reset PC=%08X\n", M68K_GETPC); - romptr = 0; - } + /* DIR low = reset address counter */ + if ((bfd100 & 2)) { + if (romptr && AMAX_LOG > 0) + write_log (L"AMAX: counter reset PC=%08X\n", M68K_GETPC); + romptr = 0; + } } static int dwlastbit; void amax_diskwrite (uae_u16 w) { - int i; - - /* this is weird, 1->0 transition in disk write line increases address pointer.. */ - for (i = 0; i < 16; i++) { - if (dwlastbit && !(w & 0x8000)) { - romptr++; - if (AMAX_LOG > 0) - write_log (L"AMAX: counter increase %d PC=%08X\n", romptr, M68K_GETPC); + int i; + + /* this is weird, 1->0 transition in disk write line increases address pointer.. */ + for (i = 0; i < 16; i++) { + if (dwlastbit && !(w & 0x8000)) { + romptr++; + if (AMAX_LOG > 0) + write_log (L"AMAX: counter increase %d PC=%08X\n", romptr, M68K_GETPC); + } + dwlastbit = (w & 0x8000) ? 1 : 0; + w <<= 1; } - dwlastbit = (w & 0x8000) ? 1 : 0; - w <<= 1; - } - romptr &= rom_size - 1; - amax_check (); + romptr &= rom_size - 1; + amax_check (); } static uae_u8 bfe001_ov; void amax_bfe001_write (uae_u8 pra, uae_u8 dra) { - uae_u8 v = dra & pra; - - bfe001 = v; - /* CHNG low -> high: shift data register */ - if ((v & 4) && !(bfe001_ov & 4)) { - data <<= 1; - data |= 1; - if (AMAX_LOG > 0) - write_log (L"AMAX: data shifted\n"); - } - /* TK0 = even, WPRO = odd */ - rom_oddeven = -1; - if ((v & (8 | 16)) != (8 | 16)) { - rom_oddeven = 0; - if (!(v & 16)) - rom_oddeven = 1; - } - bfe001_ov = v; - amax_check (); + uae_u8 v = dra & pra; + + bfe001 = v; + /* CHNG low -> high: shift data register */ + if ((v & 4) && !(bfe001_ov & 4)) { + data <<= 1; + data |= 1; + if (AMAX_LOG > 0) + write_log (L"AMAX: data shifted\n"); + } + /* TK0 = even, WPRO = odd */ + rom_oddeven = -1; + if ((v & (8 | 16)) != (8 | 16)) { + rom_oddeven = 0; + if (!(v & 16)) + rom_oddeven = 1; + } + bfe001_ov = v; + amax_check (); } void amax_disk_select (uae_u8 v, uae_u8 ov) { - bfd100 = v; + bfd100 = v; - if (!(bfd100 & dselect) && (ov & dselect)) - load_byte (); - amax_check (); + if (!(bfd100 & dselect) && (ov & dselect)) + load_byte (); + amax_check (); } uae_u8 amax_disk_status (void) { - uae_u8 st = 0x3c; + uae_u8 st = 0x3c; - if (!(data & 0x80)) - st &= ~0x20; - return st; + if (!(data & 0x80)) + st &= ~0x20; + return st; } void amax_reset (void) { - romptr = 0; - rom_oddeven = 0; - bfe001_ov = 0; - dwlastbit = 0; - data = 0xff; - xfree (rom); - rom = NULL; - dselect = 0; + romptr = 0; + rom_oddeven = 0; + bfe001_ov = 0; + dwlastbit = 0; + data = 0xff; + xfree (rom); + rom = NULL; + dselect = 0; } void amax_init (void) { - struct zfile *z; - - if (!currprefs.amaxromfile[0]) - return; - amax_reset (); - z = zfile_fopen (currprefs.amaxromfile, L"rb", ZFD_NORMAL); - if (!z) { - write_log (L"AMAX: failed to load rom '%s'\n", currprefs.amaxromfile); - return; - } - zfile_fseek (z, 0, SEEK_END); - rom_size = zfile_ftell (z); - zfile_fseek (z, 0, SEEK_SET); - rom = xmalloc (rom_size); - zfile_fread (rom, rom_size, 1, z); - zfile_fclose (z); - write_log (L"AMAX: '%s' loaded, %d bytes\n", currprefs.amaxromfile, rom_size); - dselect = 0x20; + struct zfile *z; + + if (!currprefs.amaxromfile[0]) + return; + amax_reset (); + z = zfile_fopen (currprefs.amaxromfile, L"rb", ZFD_NORMAL); + if (!z) { + write_log (L"AMAX: failed to load rom '%s'\n", currprefs.amaxromfile); + return; + } + zfile_fseek (z, 0, SEEK_END); + rom_size = zfile_ftell (z); + zfile_fseek (z, 0, SEEK_SET); + rom = xmalloc (rom_size); + zfile_fread (rom, rom_size, 1, z); + zfile_fclose (z); + write_log (L"AMAX: '%s' loaded, %d bytes\n", currprefs.amaxromfile, rom_size); + dselect = 0x20; } diff --git a/ar.c b/ar.c index 21fbbebd..66a459f3 100644 --- a/ar.c +++ b/ar.c @@ -1,199 +1,199 @@ /* - * UAE Action Replay 1/2/3/1200 and HRTMon support - * - * (c) 2000-2006 Toni Wilen - * (c) 2003 Mark Cox - * - * Action Replay 1200 (basically old version of HRTMon): - * - * 256k ROM at 0x800000 - * 64k RAM at 0x880000 - * status register at 0x8c0000 (bit 3 = freeze button, bit 4 = hide) - * custom register writes stored at 0x88f000 - * CIA-A at 0x88e000 - * CIA-B at 0x88d000 - * freeze button = bus error + rom mapped at 0x0 - * - * 14.06.2006 first implementation - * - * Action Replay 2/3: - * - * Tested with AR3 ROM version 3.09 (10/13/91) and AR2 2.12 (12/24/90) - * - * Found to work for the following roms by Mark Cox: - * (Yes the date format is inconsistent, i just copied it straight from the rom) - * 1.15 - * 2.14 22/02/91 dd/mm/yy - * 3.09 10/13/91 mm/dd/yy - * 3.17 12/17/91 mm/dd/yy - * - * This patch also makes AR3 compatible with KickStart's other than 1.3 - * (ROM checksum error is normal with KS != 1.3) - * NOTE: AR has problems with 68020+ processors. - * For maximum compatibility select 68000/68010 and A500 speed from UAE - * options. - * - * How to rip Action Replay 1/2/3 ROM: - * - * Find A500 with AR1/2/3, press 'freeze'-button - * - * type following: - * - * AR1: - * lord olaf - * - * AR2 or AR3: - * may - * the - * force - * be - * with - * you - * new (AR3 only) - * - * AR1: 64K ROM is visible at 0xf00000-0xf0ffff - * and 16K RAM at 0x9fc000-0x9fffff - * AR2: 128K ROM is visible at 0x400000-0x41ffff - * AR3: 256K ROM is visible at 0x400000-0x43ffff - * and 64K RAM at 0x440000-0x44ffff - * - * following command writes ROM to disk: - * - * AR1: sm ar1.rom,f00000 f10000 - * AR2: sm ar2.rom,400000 420000 - * AR3: sm ar3.rom,400000 440000 - * - * NOTE: I (mark) could not get the action replay 1 dump to work as above. - * (also, it will only dump to the action replay special disk format) - * To dump the rom i had to : - * 1. Boot the a500 and start a monitor (e.g. cmon). - * 2. Use the monitor to allocate 64k memory. - * 3. Enter the action replay. - * 4. Enter sysop mode. - * 5. Copy the rom into the address the monitor allocated. - * 6. Exit the action replay. - * 7. Save the ram from the monitor to disk. - * - * I DO NOT REPLY MAILS ASKING FOR ACTION REPLAY ROMS! - * - * AR2/3 hardware notes (not 100% correct..) - * - * first 8 bytes of ROM are not really ROM, they are - * used to read/write cartridge's hardware state - * - * 0x400000: hides cartridge ROM/RAM when written - * 0x400001: read/write HW state - * 3 = reset (read-only) - * 2 = sets HW to activate when breakpoint condition is detected - * 1 = ??? - * 0 = freeze pressed - * 0x400002/0x400003: mirrors 0x400000/0x400001 - * 0x400006/0x400007: when written to, turns chip-ram overlay off - * - * breakpoint condition is detected when CPU first accesses - * chip memory below 1024 bytes and then reads CIA register - * $BFE001. - * - * cartridge hardware also snoops CPU accesses to custom chip - * registers (DFF000-DFF1FE). All CPU custom chip accesses are - * saved to RAM at 0x44f000-0x44f1ff. Note that emulated AR3 also - * saves copper's custom chip accesses. This fix stops programs - * that try to trick AR by using copper to update write-only - * custom registers. - * - * 30.04.2001 - added AR2 support - * 21.07.2001 - patch updated - * 29.07.2002 - added AR1 support - * 11.03.2003 - added AR1 breakpoint support, checksum support and fixes. (Mark Cox) - * - */ +* UAE Action Replay 1/2/3/1200 and HRTMon support +* +* (c) 2000-2006 Toni Wilen +* (c) 2003 Mark Cox +* +* Action Replay 1200 (basically old version of HRTMon): +* +* 256k ROM at 0x800000 +* 64k RAM at 0x880000 +* status register at 0x8c0000 (bit 3 = freeze button, bit 4 = hide) +* custom register writes stored at 0x88f000 +* CIA-A at 0x88e000 +* CIA-B at 0x88d000 +* freeze button = bus error + rom mapped at 0x0 +* +* 14.06.2006 first implementation +* +* Action Replay 2/3: +* +* Tested with AR3 ROM version 3.09 (10/13/91) and AR2 2.12 (12/24/90) +* +* Found to work for the following roms by Mark Cox: +* (Yes the date format is inconsistent, i just copied it straight from the rom) +* 1.15 +* 2.14 22/02/91 dd/mm/yy +* 3.09 10/13/91 mm/dd/yy +* 3.17 12/17/91 mm/dd/yy +* +* This patch also makes AR3 compatible with KickStart's other than 1.3 +* (ROM checksum error is normal with KS != 1.3) +* NOTE: AR has problems with 68020+ processors. +* For maximum compatibility select 68000/68010 and A500 speed from UAE +* options. +* +* How to rip Action Replay 1/2/3 ROM: +* +* Find A500 with AR1/2/3, press 'freeze'-button +* +* type following: +* +* AR1: +* lord olaf +* +* AR2 or AR3: +* may +* the +* force +* be +* with +* you +* new (AR3 only) +* +* AR1: 64K ROM is visible at 0xf00000-0xf0ffff +* and 16K RAM at 0x9fc000-0x9fffff +* AR2: 128K ROM is visible at 0x400000-0x41ffff +* AR3: 256K ROM is visible at 0x400000-0x43ffff +* and 64K RAM at 0x440000-0x44ffff +* +* following command writes ROM to disk: +* +* AR1: sm ar1.rom,f00000 f10000 +* AR2: sm ar2.rom,400000 420000 +* AR3: sm ar3.rom,400000 440000 +* +* NOTE: I (mark) could not get the action replay 1 dump to work as above. +* (also, it will only dump to the action replay special disk format) +* To dump the rom i had to : +* 1. Boot the a500 and start a monitor (e.g. cmon). +* 2. Use the monitor to allocate 64k memory. +* 3. Enter the action replay. +* 4. Enter sysop mode. +* 5. Copy the rom into the address the monitor allocated. +* 6. Exit the action replay. +* 7. Save the ram from the monitor to disk. +* +* I DO NOT REPLY MAILS ASKING FOR ACTION REPLAY ROMS! +* +* AR2/3 hardware notes (not 100% correct..) +* +* first 8 bytes of ROM are not really ROM, they are +* used to read/write cartridge's hardware state +* +* 0x400000: hides cartridge ROM/RAM when written +* 0x400001: read/write HW state +* 3 = reset (read-only) +* 2 = sets HW to activate when breakpoint condition is detected +* 1 = ??? +* 0 = freeze pressed +* 0x400002/0x400003: mirrors 0x400000/0x400001 +* 0x400006/0x400007: when written to, turns chip-ram overlay off +* +* breakpoint condition is detected when CPU first accesses +* chip memory below 1024 bytes and then reads CIA register +* $BFE001. +* +* cartridge hardware also snoops CPU accesses to custom chip +* registers (DFF000-DFF1FE). All CPU custom chip accesses are +* saved to RAM at 0x44f000-0x44f1ff. Note that emulated AR3 also +* saves copper's custom chip accesses. This fix stops programs +* that try to trick AR by using copper to update write-only +* custom registers. +* +* 30.04.2001 - added AR2 support +* 21.07.2001 - patch updated +* 29.07.2002 - added AR1 support +* 11.03.2003 - added AR1 breakpoint support, checksum support and fixes. (Mark Cox) +* +*/ /* AR2/3 'NORES' info. - * On ar2 there is a 'nores' command, - * on ar3, it is accessible using the mouse. - * This command will not work using the current infrastructure, - * so don't use it 8). - */ +* On ar2 there is a 'nores' command, +* on ar3, it is accessible using the mouse. +* This command will not work using the current infrastructure, +* so don't use it 8). +*/ /* AR1 Breakpoint info. - * 1.15 If a breakpoint occurred. Its address is stored at 9fe048. - * The 5 breakpoint entries each consisting of 6 bytes are stored at 9fe23e. - * Each entry contains the breakpoint long word followed by 2 bytes of the original contents of memory - * that is replaced by a trap instruction in mem. - * So the table finishes at 9fe25c. - */ +* 1.15 If a breakpoint occurred. Its address is stored at 9fe048. +* The 5 breakpoint entries each consisting of 6 bytes are stored at 9fe23e. +* Each entry contains the breakpoint long word followed by 2 bytes of the original contents of memory +* that is replaced by a trap instruction in mem. +* So the table finishes at 9fe25c. +*/ /* How AR1 is entered on reset: - * In the kickstart (1.3) there is the following code: - * I have marked the important lines: - * - * fc00e6 lea f00000,a1 ; address where AR1 rom is located. - * fc00ec cmpa.l a1,a0 - * fc00ee beq fc00fe.s - * fc00f0 lea C(pc), a5 - * fc00f4 cmpi.w #1111,(a1) ; The first word of the AR1 rom is set to 1111. - * fc00f8 bne fc00fe.s - * fc00fa jmp 2(a1) ; This is the entry point of the rom. - */ - - /* Flag info: - * AR3:'ARON'. This is unset initially. It is set the first time you enter the AR via a freeze. - * It enables you to keep the keyboard buffer and such. - * If this flag is unset, the keyboard buffer is cleared, the breakpoints are deleted and ... */ - - /* AR3:'PRIN'. This flag is unset initially. It is set at some point and when you switch to the 2nd screen - * for the first time it displays all the familiar text. Then unsets 'PRIN'. - */ - - /* Super IV: - * - * Possible "ROM" addresses ("ROM" is loaded from disk to Amiga memory) - * - 0xd00000 - * - 0xc00000 - * - 0x080000 - * - * CIA-A: 0xb40000 (0x000, 0x100,...) - * CIA-B: 0xb40001 (0x001, 0x101,...) - * Custom: 0xe40000 - * - * NOTE: emulation also supports 0xd00000 relocated "rom"-images - */ - - /* X-Power 500: - * - * ROM: 0xe20000 (128k) - * RAM: 0xf20000 (64k) - * CIA-A: 0xf2fc00 (00,02,04,...) - * CIA-B: 0xf2fc01 (01,03,05,...) - * Custom: 0xf2fc00 (from 0x20->) - */ - - /* Nordic Power: - * - * ROM: 0xf00000 (64k, mirrored at 0xf10000) - * RAM: 0xf40000 (32k, mirrored at 0xf48000 - 0xf5ffff) - * CIA-A: 0xf43c00 (00,02,04,...) - * CIA-B: 0xf43c01 (01,03,05,...) - * Custom: 0xf43c00 (from 0x20->) - * addresses 0 to 1023: 0xf40000 (weird feature..) - */ - - /* X-Power and Nordic Power ROM scrambling - * - * Data lines are swapped. - * Address lines are XOR'd (0x817F) and swapped. - * - * Even (middle) ROM - * - * Data: 0-3,1-6,2-0,3-4,4-7,5-5,6-1,7-2 - * Addr: 0-7,1-1,2-2,3-11,4-12,5-0,6-13,7-14,8-8,9-3,10-5,11-6,12-4,13-10,14-9,15-15 - * - * Odd (corner) ROM - * - * Data: 0-2,1-3,2-4,3-5,4-6,5-7,6-0,7-1 - * Addr: 0-3,1-6,2-5,3-7,4-9,5-12,6-14,7-13,8-8,9-11,10-10,11-1,12-0,13-4,14-2,15-15 - * - */ +* In the kickstart (1.3) there is the following code: +* I have marked the important lines: +* +* fc00e6 lea f00000,a1 ; address where AR1 rom is located. +* fc00ec cmpa.l a1,a0 +* fc00ee beq fc00fe.s +* fc00f0 lea C(pc), a5 +* fc00f4 cmpi.w #1111,(a1) ; The first word of the AR1 rom is set to 1111. +* fc00f8 bne fc00fe.s +* fc00fa jmp 2(a1) ; This is the entry point of the rom. +*/ + +/* Flag info: +* AR3:'ARON'. This is unset initially. It is set the first time you enter the AR via a freeze. +* It enables you to keep the keyboard buffer and such. +* If this flag is unset, the keyboard buffer is cleared, the breakpoints are deleted and ... */ + +/* AR3:'PRIN'. This flag is unset initially. It is set at some point and when you switch to the 2nd screen +* for the first time it displays all the familiar text. Then unsets 'PRIN'. +*/ + +/* Super IV: +* +* Possible "ROM" addresses ("ROM" is loaded from disk to Amiga memory) +* - 0xd00000 +* - 0xc00000 +* - 0x080000 +* +* CIA-A: 0xb40000 (0x000, 0x100,...) +* CIA-B: 0xb40001 (0x001, 0x101,...) +* Custom: 0xe40000 +* +* NOTE: emulation also supports 0xd00000 relocated "rom"-images +*/ + +/* X-Power 500: +* +* ROM: 0xe20000 (128k) +* RAM: 0xf20000 (64k) +* CIA-A: 0xf2fc00 (00,02,04,...) +* CIA-B: 0xf2fc01 (01,03,05,...) +* Custom: 0xf2fc00 (from 0x20->) +*/ + +/* Nordic Power: +* +* ROM: 0xf00000 (64k, mirrored at 0xf10000) +* RAM: 0xf40000 (32k, mirrored at 0xf48000 - 0xf5ffff) +* CIA-A: 0xf43c00 (00,02,04,...) +* CIA-B: 0xf43c01 (01,03,05,...) +* Custom: 0xf43c00 (from 0x20->) +* addresses 0 to 1023: 0xf40000 (weird feature..) +*/ + +/* X-Power and Nordic Power ROM scrambling +* +* Data lines are swapped. +* Address lines are XOR'd (0x817F) and swapped. +* +* Even (middle) ROM +* +* Data: 0-3,1-6,2-0,3-4,4-7,5-5,6-1,7-2 +* Addr: 0-7,1-1,2-2,3-11,4-12,5-0,6-13,7-14,8-8,9-3,10-5,11-6,12-4,13-10,14-9,15-15 +* +* Odd (corner) ROM +* +* Data: 0-2,1-3,2-4,3-5,4-6,5-7,6-0,7-1 +* Addr: 0-3,1-6,2-5,3-7,4-9,5-12,6-14,7-13,8-8,9-11,10-10,11-1,12-0,13-4,14-2,15-15 +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -222,7 +222,7 @@ static TCHAR *cart_memnames[] = { NULL, L"hrtmon", L"arhrtmon", L"superiv" }; #define ARMODE_BREAKPOINT_AR2 2 /* AR2: The action replay is activated via a breakpoint. */ #define ARMODE_BREAKPOINT_ACTIVATED 1 #define ARMODE_BREAKPOINT_AR3_RESET_AR2 3 /* AR2: The action replay is activated after a reset. */ - /* AR3: The action replay is activated by a breakpoint. */ +/* AR3: The action replay is activated by a breakpoint. */ #define CART_AR 0 #define CART_HRTMON 1 @@ -248,245 +248,245 @@ static int triggered_once; static void hrtmon_unmap_banks (void); -void check_prefs_changed_carts(int in_memory_reset); +void check_prefs_changed_carts (int in_memory_reset); int action_replay_unload (int in_memory_reset); static int stored_picasso_on = -1; -static void cartridge_enter(void) +static void cartridge_enter (void) { #ifdef PICASSO96 - stored_picasso_on = picasso_on; - picasso_requested_on = 0; + stored_picasso_on = picasso_on; + picasso_requested_on = 0; #endif } -static void cartridge_exit(void) +static void cartridge_exit (void) { #ifdef PICASSO96 - if (stored_picasso_on >= 0) - picasso_requested_on = stored_picasso_on; - stored_picasso_on = -1; + if (stored_picasso_on >= 0) + picasso_requested_on = stored_picasso_on; + stored_picasso_on = -1; #endif } static uae_u32 REGPARAM2 hrtmem3_bget (uaecptr addr) { - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - return hrtmemory3[addr]; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + return hrtmemory3[addr]; } static uae_u32 REGPARAM2 hrtmem3_wget (uaecptr addr) { - return (hrtmem3_bget (addr) << 8) | hrtmem3_bget (addr + 1); + return (hrtmem3_bget (addr) << 8) | hrtmem3_bget (addr + 1); } static uae_u32 REGPARAM2 hrtmem3_lget (uaecptr addr) { - return (hrtmem3_wget (addr) << 16) | hrtmem3_wget (addr + 2); + return (hrtmem3_wget (addr) << 16) | hrtmem3_wget (addr + 2); } static void REGPARAM2 hrtmem3_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - m = (uae_u32 *)(hrtmemory3 + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + m = (uae_u32 *)(hrtmemory3 + addr); + do_put_mem_long (m, l); } static void REGPARAM2 hrtmem3_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - m = (uae_u16 *)(hrtmemory3 + addr); - do_put_mem_word (m, (uae_u16)w); + uae_u16 *m; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + m = (uae_u16 *)(hrtmemory3 + addr); + do_put_mem_word (m, (uae_u16)w); } static void REGPARAM2 hrtmem3_bput (uaecptr addr, uae_u32 b) { - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - hrtmemory3[addr] = b; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + hrtmemory3[addr] = b; } static int REGPARAM2 hrtmem3_check (uaecptr addr, uae_u32 size) { - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - return (addr + size) <= hrtmem3_size; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + return (addr + size) <= hrtmem3_size; } static uae_u8 *REGPARAM2 hrtmem3_xlate (uaecptr addr) { - addr -= hrtmem3_start & hrtmem3_mask; - addr &= hrtmem3_mask; - return hrtmemory3 + addr; + addr -= hrtmem3_start & hrtmem3_mask; + addr &= hrtmem3_mask; + return hrtmemory3 + addr; } static uae_u32 REGPARAM2 hrtmem2_bget (uaecptr addr) { - if (addr == 0xb8007c && cart_type == CART_SUPER4) { - static int cnt = 60; - cnt--; - if (cnt == 0) - uae_reset(0); - } - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - return hrtmemory2[addr]; + if (addr == 0xb8007c && cart_type == CART_SUPER4) { + static int cnt = 60; + cnt--; + if (cnt == 0) + uae_reset(0); + } + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + return hrtmemory2[addr]; } static uae_u32 REGPARAM2 hrtmem2_wget (uaecptr addr) { - return (hrtmem2_bget (addr) << 8) | hrtmem2_bget (addr + 1); + return (hrtmem2_bget (addr) << 8) | hrtmem2_bget (addr + 1); } static uae_u32 REGPARAM2 hrtmem2_lget (uaecptr addr) { - return (hrtmem2_wget (addr) << 16) | hrtmem2_wget (addr + 2); + return (hrtmem2_wget (addr) << 16) | hrtmem2_wget (addr + 2); } static void REGPARAM2 hrtmem2_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - m = (uae_u32 *)(hrtmemory2 + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + m = (uae_u32 *)(hrtmemory2 + addr); + do_put_mem_long (m, l); } static void REGPARAM2 hrtmem2_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - m = (uae_u16 *)(hrtmemory2 + addr); - do_put_mem_word (m, (uae_u16)w); + uae_u16 *m; + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + m = (uae_u16 *)(hrtmemory2 + addr); + do_put_mem_word (m, (uae_u16)w); } static void REGPARAM2 hrtmem2_bput (uaecptr addr, uae_u32 b) { - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - hrtmemory2[addr] = b; + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + hrtmemory2[addr] = b; } static int REGPARAM2 hrtmem2_check (uaecptr addr, uae_u32 size) { - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - return (addr + size) <= hrtmem2_size; + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + return (addr + size) <= hrtmem2_size; } static uae_u8 *REGPARAM2 hrtmem2_xlate (uaecptr addr) { - addr -= hrtmem2_start & hrtmem2_mask; - addr &= hrtmem2_mask; - return hrtmemory2 + addr; + addr -= hrtmem2_start & hrtmem2_mask; + addr &= hrtmem2_mask; + return hrtmemory2 + addr; } static uae_u32 REGPARAM2 hrtmem_lget (uaecptr addr) { - uae_u32 *m; - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - m = (uae_u32 *)(hrtmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + m = (uae_u32 *)(hrtmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 hrtmem_wget (uaecptr addr) { - uae_u16 *m; - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - m = (uae_u16 *)(hrtmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + m = (uae_u16 *)(hrtmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 hrtmem_bget (uaecptr addr) { - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - return hrtmemory[addr]; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + return hrtmemory[addr]; } static void REGPARAM2 hrtmem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - if (cart_type == CART_AR1200 && addr < 0x80000) - return; - if (hrtmem_rom) - return; - m = (uae_u32 *)(hrtmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + if (cart_type == CART_AR1200 && addr < 0x80000) + return; + if (hrtmem_rom) + return; + m = (uae_u32 *)(hrtmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 hrtmem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - if (cart_type == CART_AR1200 && addr < 0x80000) - return; - if (hrtmem_rom) - return; - m = (uae_u16 *)(hrtmemory + addr); - do_put_mem_word (m, (uae_u16)w); + uae_u16 *m; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + if (cart_type == CART_AR1200 && addr < 0x80000) + return; + if (hrtmem_rom) + return; + m = (uae_u16 *)(hrtmemory + addr); + do_put_mem_word (m, (uae_u16)w); } static void REGPARAM2 hrtmem_bput (uaecptr addr, uae_u32 b) { - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - if (cart_type == CART_AR1200 && addr < 0x80000) - return; - if (hrtmem_rom) - return; - hrtmemory[addr] = b; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + if (cart_type == CART_AR1200 && addr < 0x80000) + return; + if (hrtmem_rom) + return; + hrtmemory[addr] = b; } static int REGPARAM2 hrtmem_check (uaecptr addr, uae_u32 size) { - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - return (addr + size) <= hrtmem_size; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + return (addr + size) <= hrtmem_size; } static uae_u8 *REGPARAM2 hrtmem_xlate (uaecptr addr) { - addr -= hrtmem_start & hrtmem_mask; - addr &= hrtmem_mask; - return hrtmemory + addr; + addr -= hrtmem_start & hrtmem_mask; + addr &= hrtmem_mask; + return hrtmemory + addr; } static addrbank hrtmem_bank = { - hrtmem_lget, hrtmem_wget, hrtmem_bget, - hrtmem_lput, hrtmem_wput, hrtmem_bput, - hrtmem_xlate, hrtmem_check, NULL, L"Cartridge Bank", - hrtmem_lget, hrtmem_wget, ABFLAG_RAM + hrtmem_lget, hrtmem_wget, hrtmem_bget, + hrtmem_lput, hrtmem_wput, hrtmem_bput, + hrtmem_xlate, hrtmem_check, NULL, L"Cartridge Bank", + hrtmem_lget, hrtmem_wget, ABFLAG_RAM }; static addrbank hrtmem2_bank = { - hrtmem2_lget, hrtmem2_wget, hrtmem2_bget, - hrtmem2_lput, hrtmem2_wput, hrtmem2_bput, - hrtmem2_xlate, hrtmem2_check, NULL, L"Cartridge Bank 2", - hrtmem2_lget, hrtmem2_wget, ABFLAG_RAM + hrtmem2_lget, hrtmem2_wget, hrtmem2_bget, + hrtmem2_lput, hrtmem2_wput, hrtmem2_bput, + hrtmem2_xlate, hrtmem2_check, NULL, L"Cartridge Bank 2", + hrtmem2_lget, hrtmem2_wget, ABFLAG_RAM }; static addrbank hrtmem3_bank = { - hrtmem3_lget, hrtmem3_wget, hrtmem3_bget, - hrtmem3_lput, hrtmem3_wput, hrtmem3_bput, - hrtmem3_xlate, hrtmem3_check, NULL, L"Cartridge Bank 3", - hrtmem3_lget, hrtmem3_wget, ABFLAG_RAM + hrtmem3_lget, hrtmem3_wget, hrtmem3_bget, + hrtmem3_lput, hrtmem3_wput, hrtmem3_bput, + hrtmem3_xlate, hrtmem3_check, NULL, L"Cartridge Bank 3", + hrtmem3_lget, hrtmem3_wget, ABFLAG_RAM }; static void copyfromamiga (uae_u8 *dst, uaecptr src, int len) { - while (len--) { - *dst++ = get_byte (src); - src++; - } + while (len--) { + *dst++ = get_byte (src); + src++; + } } static void copytoamiga (uaecptr dst, uae_u8 *src, int len) { - while (len--) { - put_byte (dst, *src++); - dst++; - } + while (len--) { + put_byte (dst, *src++); + dst++; + } } int action_replay_flag = ACTION_REPLAY_INACTIVE; @@ -505,151 +505,151 @@ static int ar_wait_pop = 0; /* bool used by AR1 when waiting for the program cou uaecptr wait_for_pc = 0; /* The program counter that we wait for. */ /* returns true if the Program counter is currently in the AR rom. */ -int is_ar_pc_in_rom() +int is_ar_pc_in_rom (void) { - uaecptr pc = m68k_getpc () & 0xFFFFFF; - return pc >= arrom_start && pc < arrom_start+arrom_size; + uaecptr pc = m68k_getpc () & 0xFFFFFF; + return pc >= arrom_start && pc < arrom_start+arrom_size; } /* returns true if the Program counter is currently in the AR RAM. */ -int is_ar_pc_in_ram() +int is_ar_pc_in_ram (void) { - uaecptr pc = m68k_getpc () & 0xFFFFFF; - return pc >= arram_start && pc < arram_start+arram_size; + uaecptr pc = m68k_getpc () & 0xFFFFFF; + return pc >= arram_start && pc < arram_start+arram_size; } /* flag writing == 1 for writing memory, 0 for reading from memory. */ STATIC_INLINE int ar3a (uaecptr addr, uae_u8 b, int writing) { - uaecptr pc; -/* if (addr < 8) //|| writing ) */ -/* { */ -/* if (writing) */ -/* write_log_debug("ARSTATUS armode:%d, Writing %d to address %p, PC=%p\n", armode, b, addr, m68k_getpc ()); */ -/* else */ -/* write_log_debug("ARSTATUS armode:%d, Reading %d from address %p, PC=%p\n", armode, armemory_rom[addr], addr, m68k_getpc ()); */ -/* } */ - - if (armodel == 1) /* With AR1. It is always a read. Actually, it is a strobe on exit of the AR. - * but, it is also read during the checksum routine. */ - { - if (addr < 2) { - if (is_ar_pc_in_rom()) { - if (ar_wait_pop) { - action_replay_flag = ACTION_REPLAY_WAIT_PC; -/* write_log_debug ("SP %p\n", m68k_areg (regs, 7)); */ -/* write_log_debug ("SP+2 %p\n", m68k_areg (regs, 7) + 2); */ -/* write_log_debug ("(SP+2) %p\n", longget (m68k_areg (regs, 7) + 2)); */ - ar_wait_pop = 0; - /* We get (SP+2) here, as the first word on the stack is the status register. */ - /* We want the following long, which is the return program counter. */ - wait_for_pc = longget (m68k_areg (regs, 7) + 2); /* Get (SP+2) */ - set_special (SPCFLAG_ACTION_REPLAY); - - pc = m68k_getpc (); -/* write_log_debug ("Action Replay marked as ACTION_REPLAY_WAIT_PC, PC=%p\n",pc);*/ - } - else - { - uaecptr pc = m68k_getpc (); -/* write_log_debug ("Action Replay marked as IDLE, PC=%p\n",pc);*/ - action_replay_flag = ACTION_REPLAY_IDLE; + uaecptr pc; + /* if (addr < 8) //|| writing ) */ + /* { */ + /* if (writing) */ + /* write_log_debug("ARSTATUS armode:%d, Writing %d to address %p, PC=%p\n", armode, b, addr, m68k_getpc ()); */ + /* else */ + /* write_log_debug("ARSTATUS armode:%d, Reading %d from address %p, PC=%p\n", armode, armemory_rom[addr], addr, m68k_getpc ()); */ + /* } */ + + if (armodel == 1) /* With AR1. It is always a read. Actually, it is a strobe on exit of the AR. + * but, it is also read during the checksum routine. */ + { + if (addr < 2) { + if (is_ar_pc_in_rom()) { + if (ar_wait_pop) { + action_replay_flag = ACTION_REPLAY_WAIT_PC; + /* write_log_debug ("SP %p\n", m68k_areg (regs, 7)); */ + /* write_log_debug ("SP+2 %p\n", m68k_areg (regs, 7) + 2); */ + /* write_log_debug ("(SP+2) %p\n", longget (m68k_areg (regs, 7) + 2)); */ + ar_wait_pop = 0; + /* We get (SP+2) here, as the first word on the stack is the status register. */ + /* We want the following long, which is the return program counter. */ + wait_for_pc = longget (m68k_areg (regs, 7) + 2); /* Get (SP+2) */ + set_special (SPCFLAG_ACTION_REPLAY); + + pc = m68k_getpc (); + /* write_log_debug ("Action Replay marked as ACTION_REPLAY_WAIT_PC, PC=%p\n",pc);*/ + } + else + { + uaecptr pc = m68k_getpc (); + /* write_log_debug ("Action Replay marked as IDLE, PC=%p\n",pc);*/ + action_replay_flag = ACTION_REPLAY_IDLE; + } + } } - } + /* This probably violates the hide_banks thing except ar1 doesn't use that yet .*/ + return armemory_rom[addr]; } - /* This probably violates the hide_banks thing except ar1 doesn't use that yet .*/ - return armemory_rom[addr]; - } #ifdef ACTION_REPLAY_HIDE_CARTRIDGE - if (addr >= 8) - return armemory_rom[addr]; + if (addr >= 8) + return armemory_rom[addr]; - if (action_replay_flag != ACTION_REPLAY_ACTIVE) - return 0; + if (action_replay_flag != ACTION_REPLAY_ACTIVE) + return 0; #endif - if (!writing) /* reading */ - { - if (addr == 1 || addr == 3) /* This is necessary because we don't update rom location 0 every time we change armode */ - return armode | (regs.irc & ~3); - else if (addr < 4) - return (addr & 1) ? regs.irc : regs.irc >> 8; - else - return armemory_rom[addr]; - } - /* else, we are writing */ - else if (addr == 1) { - armode = b; - if (armode >= 2) { - if (armode == ARMODE_BREAKPOINT_AR2) { - write_log (L"AR2: exit with breakpoint(s) active\n"); /* Correct for AR2 */ - } else if (armode == ARMODE_BREAKPOINT_AR3_RESET_AR2 ) - write_log (L"AR3: exit waiting for breakpoint.\n"); /* Correct for AR3 (waiting for breakpoint)*/ - else - write_log (L"AR2/3: mode(%d) > 3 this shouldn't happen.\n", armode); - } else - write_log (L"AR: exit with armode(%d)\n", armode); - - set_special (SPCFLAG_ACTION_REPLAY); - action_replay_flag = ACTION_REPLAY_HIDE; - } else if (addr == 6) { - copytoamiga (regs.vbr + 0x7c, artemp, 4); - write_log (L"AR: chipmem returned\n"); - } - return 0; + if (!writing) /* reading */ + { + if (addr == 1 || addr == 3) /* This is necessary because we don't update rom location 0 every time we change armode */ + return armode | (regs.irc & ~3); + else if (addr < 4) + return (addr & 1) ? regs.irc : regs.irc >> 8; + else + return armemory_rom[addr]; + } + /* else, we are writing */ + else if (addr == 1) { + armode = b; + if (armode >= 2) { + if (armode == ARMODE_BREAKPOINT_AR2) { + write_log (L"AR2: exit with breakpoint(s) active\n"); /* Correct for AR2 */ + } else if (armode == ARMODE_BREAKPOINT_AR3_RESET_AR2 ) + write_log (L"AR3: exit waiting for breakpoint.\n"); /* Correct for AR3 (waiting for breakpoint)*/ + else + write_log (L"AR2/3: mode(%d) > 3 this shouldn't happen.\n", armode); + } else + write_log (L"AR: exit with armode(%d)\n", armode); + + set_special (SPCFLAG_ACTION_REPLAY); + action_replay_flag = ACTION_REPLAY_HIDE; + } else if (addr == 6) { + copytoamiga (regs.vbr + 0x7c, artemp, 4); + write_log (L"AR: chipmem returned\n"); + } + return 0; } void REGPARAM2 chipmem_lput_actionreplay1 (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - if (addr == 0x60 && !is_ar_pc_in_rom()) - action_replay_chipwrite (); - m = (uae_u32 *)(chipmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + if (addr == 0x60 && !is_ar_pc_in_rom()) + action_replay_chipwrite (); + m = (uae_u32 *)(chipmemory + addr); + do_put_mem_long (m, l); } void REGPARAM2 chipmem_wput_actionreplay1 (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - if (addr == 0x62 && !is_ar_pc_in_rom()) - action_replay_chipwrite (); - m = (uae_u16 *)(chipmemory + addr); - do_put_mem_word (m, w); + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + if (addr == 0x62 && !is_ar_pc_in_rom()) + action_replay_chipwrite (); + m = (uae_u16 *)(chipmemory + addr); + do_put_mem_word (m, w); } void REGPARAM2 chipmem_bput_actionreplay1 (uaecptr addr, uae_u32 b) { - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - if (addr >= 0x60 && addr <= 0x63 && !is_ar_pc_in_rom()) - action_replay_chipwrite(); - chipmemory[addr] = b; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + if (addr >= 0x60 && addr <= 0x63 && !is_ar_pc_in_rom()) + action_replay_chipwrite(); + chipmemory[addr] = b; } void REGPARAM2 chipmem_lput_actionreplay23 (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - do_put_mem_long (m, l); - if (addr >= 0x40 && addr < 0x200 && action_replay_flag == ACTION_REPLAY_WAITRESET) - action_replay_chipwrite(); + uae_u32 *m; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + do_put_mem_long (m, l); + if (addr >= 0x40 && addr < 0x200 && action_replay_flag == ACTION_REPLAY_WAITRESET) + action_replay_chipwrite(); } void REGPARAM2 chipmem_wput_actionreplay23 (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); - do_put_mem_word (m, w); - if (addr >= 0x40 && addr < 0x200 && action_replay_flag == ACTION_REPLAY_WAITRESET) - action_replay_chipwrite(); + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); + do_put_mem_word (m, w); + if (addr >= 0x40 && addr < 0x200 && action_replay_flag == ACTION_REPLAY_WAITRESET) + action_replay_chipwrite(); } @@ -678,264 +678,264 @@ static void disable_rom_test(void); static uae_u32 REGPARAM2 arram_lget (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arram_start; - addr &= arram_mask; - m = (uae_u32 *)(armemory_ram + addr); - if (strncmp ("T8", (char*)m, 2) == 0) - write_log_debug (L"Reading T8 from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("LAME", (char*)m, 4) == 0) - write_log_debug (L"Reading LAME from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("RES1", (char*)m, 4) == 0) - write_log_debug (L"Reading RES1 from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("ARON", (char*)m, 4) == 0) - write_log_debug (L"Reading ARON from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("KILL", (char*)m, 4) == 0) - write_log_debug (L"Reading KILL from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("BRON", (char*)m, 4) == 0) - write_log_debug (L"Reading BRON from addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("PRIN", (char*)m, 4) == 0) - write_log_debug (L"Reading PRIN from addr %08x PC=%p\n", addr, m68k_getpc ()); - return do_get_mem_long (m); + addr -= arram_start; + addr &= arram_mask; + m = (uae_u32 *)(armemory_ram + addr); + if (strncmp ("T8", (char*)m, 2) == 0) + write_log_debug (L"Reading T8 from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("LAME", (char*)m, 4) == 0) + write_log_debug (L"Reading LAME from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("RES1", (char*)m, 4) == 0) + write_log_debug (L"Reading RES1 from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("ARON", (char*)m, 4) == 0) + write_log_debug (L"Reading ARON from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("KILL", (char*)m, 4) == 0) + write_log_debug (L"Reading KILL from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("BRON", (char*)m, 4) == 0) + write_log_debug (L"Reading BRON from addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("PRIN", (char*)m, 4) == 0) + write_log_debug (L"Reading PRIN from addr %08x PC=%p\n", addr, m68k_getpc ()); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 arram_wget (uaecptr addr) { - uae_u16 *m; + uae_u16 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arram_start; - addr &= arram_mask; - m = (uae_u16 *)(armemory_ram + addr); - return do_get_mem_word (m); + addr -= arram_start; + addr &= arram_mask; + m = (uae_u16 *)(armemory_ram + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 arram_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arram_start; - addr &= arram_mask; - return armemory_ram[addr]; + addr -= arram_start; + addr &= arram_mask; + return armemory_ram[addr]; } void REGPARAM2 arram_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arram_start; - addr &= arram_mask; - m = (uae_u32 *)(armemory_ram + addr); - if (strncmp ("T8", (char*)m, 2) == 0) - write_log_debug (L"Writing T8 to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("LAME", (char*)m, 4) == 0) - write_log_debug (L"Writing LAME to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("RES1", (char*)m, 4) == 0) - write_log_debug (L"Writing RES1 to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("ARON", (char*)m, 4) == 0) - write_log_debug (L"Writing ARON to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("KILL", (char*)m, 4) == 0) - write_log_debug (L"Writing KILL to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("BRON", (char*)m, 4) == 0) - write_log_debug (L"Writing BRON to addr %08x PC=%p\n", addr, m68k_getpc ()); - if (strncmp ("PRIN", (char*)m, 4) == 0) - write_log_debug (L"Writing PRIN to addr %08x PC=%p\n", addr, m68k_getpc ()); - do_put_mem_long (m, l); + addr -= arram_start; + addr &= arram_mask; + m = (uae_u32 *)(armemory_ram + addr); + if (strncmp ("T8", (char*)m, 2) == 0) + write_log_debug (L"Writing T8 to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("LAME", (char*)m, 4) == 0) + write_log_debug (L"Writing LAME to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("RES1", (char*)m, 4) == 0) + write_log_debug (L"Writing RES1 to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("ARON", (char*)m, 4) == 0) + write_log_debug (L"Writing ARON to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("KILL", (char*)m, 4) == 0) + write_log_debug (L"Writing KILL to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("BRON", (char*)m, 4) == 0) + write_log_debug (L"Writing BRON to addr %08x PC=%p\n", addr, m68k_getpc ()); + if (strncmp ("PRIN", (char*)m, 4) == 0) + write_log_debug (L"Writing PRIN to addr %08x PC=%p\n", addr, m68k_getpc ()); + do_put_mem_long (m, l); } void REGPARAM2 arram_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arram_start; - addr &= arram_mask; - m = (uae_u16 *)(armemory_ram + addr); - do_put_mem_word (m, w); + addr -= arram_start; + addr &= arram_mask; + m = (uae_u16 *)(armemory_ram + addr); + do_put_mem_word (m, w); } void REGPARAM2 arram_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arram_start; - addr &= arram_mask; - armemory_ram[addr] = b; + addr -= arram_start; + addr &= arram_mask; + armemory_ram[addr] = b; } static int REGPARAM2 arram_check (uaecptr addr, uae_u32 size) { - addr -= arram_start; - addr &= arram_mask; - return (addr + size) <= arram_size; + addr -= arram_start; + addr &= arram_mask; + return (addr + size) <= arram_size; } static uae_u8 *REGPARAM2 arram_xlate (uaecptr addr) { - addr -= arram_start; - addr &= arram_mask; - return armemory_ram + addr; + addr -= arram_start; + addr &= arram_mask; + return armemory_ram + addr; } static uae_u32 REGPARAM2 arrom_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arrom_start; - addr &= arrom_mask; - return (ar3a (addr, 0, 0) << 24) | (ar3a (addr + 1, 0, 0) << 16) | (ar3a (addr + 2, 0, 0) << 8) | ar3a (addr + 3, 0, 0); + addr -= arrom_start; + addr &= arrom_mask; + return (ar3a (addr, 0, 0) << 24) | (ar3a (addr + 1, 0, 0) << 16) | (ar3a (addr + 2, 0, 0) << 8) | ar3a (addr + 3, 0, 0); } static uae_u32 REGPARAM2 arrom_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arrom_start; - addr &= arrom_mask; - return (ar3a (addr, 0, 0) << 8) | ar3a (addr + 1, 0, 0); + addr -= arrom_start; + addr &= arrom_mask; + return (ar3a (addr, 0, 0) << 8) | ar3a (addr + 1, 0, 0); } static uae_u32 REGPARAM2 arrom_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= arrom_start; - addr &= arrom_mask; - return ar3a (addr, 0, 0); + addr -= arrom_start; + addr &= arrom_mask; + return ar3a (addr, 0, 0); } static void REGPARAM2 arrom_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arrom_start; - addr &= arrom_mask; - ar3a (addr + 0,(uae_u8)(l >> 24), 1); - ar3a (addr + 1,(uae_u8)(l >> 16), 1); - ar3a (addr + 2,(uae_u8)(l >> 8), 1); - ar3a (addr + 3,(uae_u8)(l >> 0), 1); + addr -= arrom_start; + addr &= arrom_mask; + ar3a (addr + 0,(uae_u8)(l >> 24), 1); + ar3a (addr + 1,(uae_u8)(l >> 16), 1); + ar3a (addr + 2,(uae_u8)(l >> 8), 1); + ar3a (addr + 3,(uae_u8)(l >> 0), 1); } static void REGPARAM2 arrom_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arrom_start; - addr &= arrom_mask; - ar3a (addr + 0,(uae_u8)(w >> 8), 1); - ar3a (addr + 1,(uae_u8)(w >> 0), 1); + addr -= arrom_start; + addr &= arrom_mask; + ar3a (addr + 0,(uae_u8)(w >> 8), 1); + ar3a (addr + 1,(uae_u8)(w >> 0), 1); } static void REGPARAM2 arrom_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= arrom_start; - addr &= arrom_mask; - ar3a (addr, b, 1); + addr -= arrom_start; + addr &= arrom_mask; + ar3a (addr, b, 1); } static int REGPARAM2 arrom_check (uaecptr addr, uae_u32 size) { - addr -= arrom_start; - addr &= arrom_mask; - return (addr + size) <= arrom_size; + addr -= arrom_start; + addr &= arrom_mask; + return (addr + size) <= arrom_size; } static uae_u8 *REGPARAM2 arrom_xlate (uaecptr addr) { - addr -= arrom_start; - addr &= arrom_mask; - return armemory_rom + addr; + addr -= arrom_start; + addr &= arrom_mask; + return armemory_rom + addr; } static addrbank arrom_bank = { - arrom_lget, arrom_wget, arrom_bget, - arrom_lput, arrom_wput, arrom_bput, - arrom_xlate, arrom_check, NULL, L"Action Replay ROM", - arrom_lget, arrom_wget, ABFLAG_ROM + arrom_lget, arrom_wget, arrom_bget, + arrom_lput, arrom_wput, arrom_bput, + arrom_xlate, arrom_check, NULL, L"Action Replay ROM", + arrom_lget, arrom_wget, ABFLAG_ROM }; static addrbank arram_bank = { - arram_lget, arram_wget, arram_bget, - arram_lput, arram_wput, arram_bput, - arram_xlate, arram_check, NULL, L"Action Replay RAM", - arram_lget, arram_wget, ABFLAG_RAM + arram_lget, arram_wget, arram_bget, + arram_lput, arram_wput, arram_bput, + arram_xlate, arram_check, NULL, L"Action Replay RAM", + arram_lget, arram_wget, ABFLAG_RAM }; -static void action_replay_unmap_banks () +static void action_replay_unmap_banks (void) { - if(!armemory_rom) - return; - if (armodel == 1) { - action_replay_map_banks (); - return; - } - map_banks (&dummy_bank, arrom_start >> 16 , arrom_size >> 16, 0); - map_banks (&dummy_bank, arram_start >> 16 , arram_size >> 16, 0); + if(!armemory_rom) + return; + if (armodel == 1) { + action_replay_map_banks (); + return; + } + map_banks (&dummy_bank, arrom_start >> 16 , arrom_size >> 16, 0); + map_banks (&dummy_bank, arram_start >> 16 , arram_size >> 16, 0); } -static void action_replay_map_banks () +static void action_replay_map_banks (void) { - if(!armemory_rom) - return; - map_banks (&arrom_bank, arrom_start >> 16, arrom_size >> 16, 0); - map_banks (&arram_bank, arram_start >> 16, arram_size >> 16, 0); + if(!armemory_rom) + return; + map_banks (&arrom_bank, arrom_start >> 16, arrom_size >> 16, 0); + map_banks (&arram_bank, arram_start >> 16, arram_size >> 16, 0); } -static void hide_cart(int hide) +static void hide_cart (int hide) { #ifdef ACTION_REPLAY_HIDE_CARTRIDGE - if(hide) { - action_replay_unmap_banks (); - } else { - action_replay_map_banks (); - } + if(hide) { + action_replay_unmap_banks (); + } else { + action_replay_map_banks (); + } #endif } /* Cartridge activates itself by overlaying its rom - * over chip-ram and then issuing IRQ 7 - * - * I just copy IRQ vector 7 from ROM to chip RAM - * instead of fully emulating cartridge's behaviour. - */ +* over chip-ram and then issuing IRQ 7 +* +* I just copy IRQ vector 7 from ROM to chip RAM +* instead of fully emulating cartridge's behaviour. +*/ static void action_replay_go (void) { - cartridge_enter(); - hide_cart (0); - memcpy (armemory_ram + 0xf000, ar_custom, 2 * 256); - action_replay_flag = ACTION_REPLAY_ACTIVE; - set_special (SPCFLAG_ACTION_REPLAY); - copyfromamiga (artemp, regs.vbr + 0x7c, 4); - copytoamiga (regs.vbr + 0x7c, armemory_rom + 0x7c, 4); - NMI (); + cartridge_enter(); + hide_cart (0); + memcpy (armemory_ram + 0xf000, ar_custom, 2 * 256); + action_replay_flag = ACTION_REPLAY_ACTIVE; + set_special (SPCFLAG_ACTION_REPLAY); + copyfromamiga (artemp, regs.vbr + 0x7c, 4); + copytoamiga (regs.vbr + 0x7c, armemory_rom + 0x7c, 4); + NMI (); } static void action_replay_go1 (int irq) { - cartridge_enter(); - hide_cart (0); - action_replay_flag = ACTION_REPLAY_ACTIVE; - memcpy (armemory_ram + 0xf000, ar_custom, 2 * 256); - NMI (); + cartridge_enter(); + hide_cart (0); + action_replay_flag = ACTION_REPLAY_ACTIVE; + memcpy (armemory_ram + 0xf000, ar_custom, 2 * 256); + NMI (); } typedef struct { @@ -973,761 +973,761 @@ typedef struct { static void hrtmon_go (void) { - uaecptr old; - int i; - - triggered_once = 1; - cartridge_enter(); - hrtmon_flag = ACTION_REPLAY_ACTIVE; - set_special (SPCFLAG_ACTION_REPLAY); - if (hrtmon_zeropage) - memcpy (hrtmon_zeropage, chipmemory, 1024); - if (hrtmon_custom) - memcpy (hrtmon_custom, ar_custom, 2 * 256); - for (i = 0; i < 16; i++) { - if (hrtmon_ciaa) - hrtmon_ciaa[i * hrtmon_ciadiv + 1] = ar_ciaa[i]; - if (hrtmon_ciab) - hrtmon_ciab[i * hrtmon_ciadiv + 0] = ar_ciab[i]; - } - if (cart_type == CART_AR1200) { - old = get_long ((uaecptr)(regs.vbr + 0x8)); - put_word (hrtmem_start + 0xc0000, 4); - put_long ((uaecptr)(regs.vbr + 8), get_long (hrtmem_start + 8)); - Exception (2, 0); - put_long ((uaecptr)(regs.vbr + 8), old); - } else if (cart_type == CART_SUPER4) { - uae_u32 v = get_long (hrtmem_start + 0x7c); - if (v) { - old = get_long ((uaecptr)(regs.vbr + 0x7c)); - put_long ((uaecptr)(regs.vbr + 0x7c), v); - NMI (); - put_long ((uaecptr)(regs.vbr + 0x7c), old); + uaecptr old; + int i; + + triggered_once = 1; + cartridge_enter(); + hrtmon_flag = ACTION_REPLAY_ACTIVE; + set_special (SPCFLAG_ACTION_REPLAY); + if (hrtmon_zeropage) + memcpy (hrtmon_zeropage, chipmemory, 1024); + if (hrtmon_custom) + memcpy (hrtmon_custom, ar_custom, 2 * 256); + for (i = 0; i < 16; i++) { + if (hrtmon_ciaa) + hrtmon_ciaa[i * hrtmon_ciadiv + 1] = ar_ciaa[i]; + if (hrtmon_ciab) + hrtmon_ciab[i * hrtmon_ciadiv + 0] = ar_ciab[i]; + } + if (cart_type == CART_AR1200) { + old = get_long ((uaecptr)(regs.vbr + 0x8)); + put_word (hrtmem_start + 0xc0000, 4); + put_long ((uaecptr)(regs.vbr + 8), get_long (hrtmem_start + 8)); + Exception (2, 0); + put_long ((uaecptr)(regs.vbr + 8), old); + } else if (cart_type == CART_SUPER4) { + uae_u32 v = get_long (hrtmem_start + 0x7c); + if (v) { + old = get_long ((uaecptr)(regs.vbr + 0x7c)); + put_long ((uaecptr)(regs.vbr + 0x7c), v); + NMI (); + put_long ((uaecptr)(regs.vbr + 0x7c), old); + } + } else { // HRTMON + old = get_long ((uaecptr)(regs.vbr + 0x7c)); + put_long ((uaecptr)(regs.vbr + 0x7c), hrtmem_start + 8 + 4); + NMI (); + //put_long ((uaecptr)(regs.vbr + 0x7c), old); } - } else { // HRTMON - old = get_long ((uaecptr)(regs.vbr + 0x7c)); - put_long ((uaecptr)(regs.vbr + 0x7c), hrtmem_start + 8 + 4); - NMI (); - //put_long ((uaecptr)(regs.vbr + 0x7c), old); - } } void hrtmon_enter (void) { - if (!hrtmemory) - return; - hrtmon_map_banks (); - write_log (L"%s: freeze\n", cart_memnames[cart_type]); - hrtmon_go(); + if (!hrtmemory) + return; + hrtmon_map_banks (); + write_log (L"%s: freeze\n", cart_memnames[cart_type]); + hrtmon_go(); } -void action_replay_enter(void) +void action_replay_enter (void) { - if (!armemory_rom) - return; - triggered_once = 1; - if (armodel == 1) { - write_log (L"AR1: Enter PC:%p\n", m68k_getpc ()); - action_replay_go1 (7); - unset_special (SPCFLAG_ACTION_REPLAY); - return; - } - if (action_replay_flag == ACTION_REPLAY_DORESET) { - write_log (L"AR2/3: reset\n"); - armode = ARMODE_BREAKPOINT_AR3_RESET_AR2; - } else if (armode == ARMODE_FREEZE) { - write_log (L"AR2/3: activated (freeze)\n"); - } else if (armode >= 2) { - if (armode == ARMODE_BREAKPOINT_AR2) - write_log (L"AR2: activated (breakpoint)\n"); - else if (armode == ARMODE_BREAKPOINT_AR3_RESET_AR2) - write_log (L"AR3: activated (breakpoint)\n"); - else - write_log (L"AR2/3: mode(%d) > 3 this shouldn't happen.\n", armode); - armode = ARMODE_BREAKPOINT_ACTIVATED; - } - action_replay_go(); -} - -void check_prefs_changed_carts(int in_memory_reset) -{ - if (currprefs.cart_internal != changed_prefs.cart_internal) - currprefs.cart_internal = changed_prefs.cart_internal; - if (_tcscmp (currprefs.cartfile, changed_prefs.cartfile) != 0) { - write_log (L"Cartridge ROM Prefs changed.\n"); - if (action_replay_unload (in_memory_reset)) { - memcpy (currprefs.cartfile, changed_prefs.cartfile, sizeof currprefs.cartfile); - #ifdef ACTION_REPLAY - action_replay_load (); - action_replay_init(1); - #endif - #ifdef ACTION_REPLAY_HRTMON - hrtmon_load (); - #endif + if (!armemory_rom) + return; + triggered_once = 1; + if (armodel == 1) { + write_log (L"AR1: Enter PC:%p\n", m68k_getpc ()); + action_replay_go1 (7); + unset_special (SPCFLAG_ACTION_REPLAY); + return; } - } + if (action_replay_flag == ACTION_REPLAY_DORESET) { + write_log (L"AR2/3: reset\n"); + armode = ARMODE_BREAKPOINT_AR3_RESET_AR2; + } else if (armode == ARMODE_FREEZE) { + write_log (L"AR2/3: activated (freeze)\n"); + } else if (armode >= 2) { + if (armode == ARMODE_BREAKPOINT_AR2) + write_log (L"AR2: activated (breakpoint)\n"); + else if (armode == ARMODE_BREAKPOINT_AR3_RESET_AR2) + write_log (L"AR3: activated (breakpoint)\n"); + else + write_log (L"AR2/3: mode(%d) > 3 this shouldn't happen.\n", armode); + armode = ARMODE_BREAKPOINT_ACTIVATED; + } + action_replay_go(); } -void action_replay_reset(void) +void check_prefs_changed_carts (int in_memory_reset) { - if (hrtmemory) { - if (savestate_state == STATE_RESTORE) { - if (m68k_getpc () >= hrtmem_start && m68k_getpc () <= hrtmem_start + hrtmem_size) - hrtmon_map_banks (); - else - hrtmon_unmap_banks (); + if (currprefs.cart_internal != changed_prefs.cart_internal) + currprefs.cart_internal = changed_prefs.cart_internal; + if (_tcscmp (currprefs.cartfile, changed_prefs.cartfile) != 0) { + write_log (L"Cartridge ROM Prefs changed.\n"); + if (action_replay_unload (in_memory_reset)) { + memcpy (currprefs.cartfile, changed_prefs.cartfile, sizeof currprefs.cartfile); +#ifdef ACTION_REPLAY + action_replay_load (); + action_replay_init (1); +#endif +#ifdef ACTION_REPLAY_HRTMON + hrtmon_load (); +#endif + } } - } else { - if (action_replay_flag == ACTION_REPLAY_INACTIVE) - return; +} - if (savestate_state == STATE_RESTORE) { - if (m68k_getpc () >= arrom_start && m68k_getpc () <= arrom_start + arrom_size) { - action_replay_flag = ACTION_REPLAY_ACTIVE; - hide_cart (0); - } else { - action_replay_flag = ACTION_REPLAY_IDLE; - hide_cart (1); - } - return; - } - if (armodel == 1) { - /* We need to mark it as active here, because the kickstart rom jumps directly into it. */ - action_replay_flag = ACTION_REPLAY_ACTIVE; - hide_cart (0); +void action_replay_reset (void) +{ + if (hrtmemory) { + if (savestate_state == STATE_RESTORE) { + if (m68k_getpc () >= hrtmem_start && m68k_getpc () <= hrtmem_start + hrtmem_size) + hrtmon_map_banks (); + else + hrtmon_unmap_banks (); + } } else { - write_log_debug (L"Setting flag to ACTION_REPLAY_WAITRESET\n"); - write_log_debug (L"armode == %d\n", armode); - action_replay_flag = ACTION_REPLAY_WAITRESET; - hide_cart (0); + if (action_replay_flag == ACTION_REPLAY_INACTIVE) + return; + + if (savestate_state == STATE_RESTORE) { + if (m68k_getpc () >= arrom_start && m68k_getpc () <= arrom_start + arrom_size) { + action_replay_flag = ACTION_REPLAY_ACTIVE; + hide_cart (0); + } else { + action_replay_flag = ACTION_REPLAY_IDLE; + hide_cart (1); + } + return; + } + if (armodel == 1) { + /* We need to mark it as active here, because the kickstart rom jumps directly into it. */ + action_replay_flag = ACTION_REPLAY_ACTIVE; + hide_cart (0); + } else { + write_log_debug (L"Setting flag to ACTION_REPLAY_WAITRESET\n"); + write_log_debug (L"armode == %d\n", armode); + action_replay_flag = ACTION_REPLAY_WAITRESET; + hide_cart (0); + } } - } } -void action_replay_ciaread(void) +void action_replay_ciaread (void) { - if (armodel < 2) - return; - if (action_replay_flag != ACTION_REPLAY_IDLE) - return; - if (action_replay_flag == ACTION_REPLAY_INACTIVE) - return; - if (armode < 2) - /* If there are no active breakpoints */ - return; - if (m68k_getpc () >= 0x200) - return; - action_replay_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); + if (armodel < 2) + return; + if (action_replay_flag != ACTION_REPLAY_IDLE) + return; + if (action_replay_flag == ACTION_REPLAY_INACTIVE) + return; + if (armode < 2) + /* If there are no active breakpoints */ + return; + if (m68k_getpc () >= 0x200) + return; + action_replay_flag = ACTION_REPLAY_ACTIVATE; + set_special (SPCFLAG_ACTION_REPLAY); } -int action_replay_freeze(void) +int action_replay_freeze (void) { - if (action_replay_flag == ACTION_REPLAY_IDLE) { - if (armodel == 1) { - action_replay_chipwrite(); - } else { - action_replay_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); - armode = ARMODE_FREEZE; + if (action_replay_flag == ACTION_REPLAY_IDLE) { + if (armodel == 1) { + action_replay_chipwrite (); + } else { + action_replay_flag = ACTION_REPLAY_ACTIVATE; + set_special (SPCFLAG_ACTION_REPLAY); + armode = ARMODE_FREEZE; + } + return 1; + } else if (hrtmon_flag) { + hrtmon_flag = ACTION_REPLAY_ACTIVATE; + set_special (SPCFLAG_ACTION_REPLAY); + return 1; } - return 1; - } else { - hrtmon_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); - return 1; - } - return 0; + return 0; } -void action_replay_chipwrite(void) +void action_replay_chipwrite (void) { - if (armodel == 2 || armodel == 3) { - action_replay_flag = ACTION_REPLAY_DORESET; - set_special (SPCFLAG_ACTION_REPLAY); - } else if (armodel == 1) { - /* copy 0x60 addr info to level 7 */ - /* This is to emulate the 0x60 interrupt. */ - copyfromamiga (artemp, regs.vbr + 0x60, 4); - copytoamiga (regs.vbr + 0x7c, artemp, 4); - ar_wait_pop = 1; /* Wait for stack to pop. */ + if (armodel == 2 || armodel == 3) { + action_replay_flag = ACTION_REPLAY_DORESET; + set_special (SPCFLAG_ACTION_REPLAY); + } else if (armodel == 1) { + /* copy 0x60 addr info to level 7 */ + /* This is to emulate the 0x60 interrupt. */ + copyfromamiga (artemp, regs.vbr + 0x60, 4); + copytoamiga (regs.vbr + 0x7c, artemp, 4); + ar_wait_pop = 1; /* Wait for stack to pop. */ - action_replay_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); - } + action_replay_flag = ACTION_REPLAY_ACTIVATE; + set_special (SPCFLAG_ACTION_REPLAY); + } } void action_replay_hide(void) { - hide_cart(1); - action_replay_flag = ACTION_REPLAY_IDLE; + hide_cart(1); + action_replay_flag = ACTION_REPLAY_IDLE; } void hrtmon_hide(void) { - HRTCFG *cfg = (HRTCFG*)hrtmemory; - if (cart_type != CART_AR1200 && cfg->entered) - return; - cartridge_exit(); - hrtmon_flag = ACTION_REPLAY_IDLE; - unset_special (SPCFLAG_ACTION_REPLAY); - //write_log (L"HRTMON: Exit\n"); + HRTCFG *cfg = (HRTCFG*)hrtmemory; + if (cart_type != CART_AR1200 && cfg->entered) + return; + cartridge_exit(); + hrtmon_flag = ACTION_REPLAY_IDLE; + unset_special (SPCFLAG_ACTION_REPLAY); + //write_log (L"HRTMON: Exit\n"); } void hrtmon_breakenter(void) { - //hrtmon_flag = ACTION_REPLAY_HIDE; - //set_special (SPCFLAG_ACTION_REPLAY); + //hrtmon_flag = ACTION_REPLAY_HIDE; + //set_special (SPCFLAG_ACTION_REPLAY); } /* Disabling copperlist processing: - * On: ar317 an rts at 41084c does it. - * On: ar214: an rts at 41068e does it. - */ +* On: ar317 an rts at 41084c does it. +* On: ar214: an rts at 41068e does it. +*/ /* Original AR3 only works with KS 1.3 - * this patch fixes that problem. - */ +* this patch fixes that problem. +*/ -static uae_u8 ar3patch1[]={0x20,0xc9,0x51,0xc9,0xff,0xfc}; -static uae_u8 ar3patch2[]={0x00,0xfc,0x01,0x44}; +static uae_u8 ar3patch1[] = {0x20,0xc9,0x51,0xc9,0xff,0xfc}; +static uae_u8 ar3patch2[] = {0x00,0xfc,0x01,0x44}; -static void action_replay_patch(void) +static void action_replay_patch (void) { - int off1,off2; - uae_u8 *kickmem = kickmemory; + int off1,off2; + uae_u8 *kickmem = kickmemory; - if (armodel != 3 || !kickmem) - return; - if (!memcmp (kickmem, kickmem + 262144, 262144)) off1 = 262144; else off1 = 0; - for (;;) { - if (!memcmp (kickmem + off1, ar3patch1, sizeof (ar3patch1)) || off1 == 524288 - sizeof (ar3patch1)) break; - off1++; - } - off2 = 0; - for(;;) { - if (!memcmp (armemory_rom + off2, ar3patch2, sizeof(ar3patch2)) || off2 == ar_rom_file_size - sizeof (ar3patch2)) break; - off2++; - } - if (off1 == 524288 - sizeof (ar3patch1) || off2 == ar_rom_file_size - sizeof (ar3patch2)) - return; - armemory_rom[off2 + 0] = (uae_u8)((off1 + kickmem_start + 2) >> 24); - armemory_rom[off2 + 1] = (uae_u8)((off1 + kickmem_start + 2) >> 16); - armemory_rom[off2 + 2] = (uae_u8)((off1 + kickmem_start + 2) >> 8); - armemory_rom[off2 + 3] = (uae_u8)((off1 + kickmem_start + 2) >> 0); - write_log (L"AR ROM patched for KS2.0+\n"); + if (armodel != 3 || !kickmem || !armemory_rom) + return; + if (!memcmp (kickmem, kickmem + 262144, 262144)) off1 = 262144; else off1 = 0; + for (;;) { + if (!memcmp (kickmem + off1, ar3patch1, sizeof (ar3patch1)) || off1 == 524288 - sizeof (ar3patch1)) break; + off1++; + } + off2 = 0; + for(;;) { + if (!memcmp (armemory_rom + off2, ar3patch2, sizeof(ar3patch2)) || off2 == ar_rom_file_size - sizeof (ar3patch2)) break; + off2++; + } + if (off1 == 524288 - sizeof (ar3patch1) || off2 == ar_rom_file_size - sizeof (ar3patch2)) + return; + armemory_rom[off2 + 0] = (uae_u8)((off1 + kickmem_start + 2) >> 24); + armemory_rom[off2 + 1] = (uae_u8)((off1 + kickmem_start + 2) >> 16); + armemory_rom[off2 + 2] = (uae_u8)((off1 + kickmem_start + 2) >> 8); + armemory_rom[off2 + 3] = (uae_u8)((off1 + kickmem_start + 2) >> 0); + write_log (L"AR ROM patched for KS2.0+\n"); } /* Returns 0 if the checksum is OK. - * Else, it returns the calculated checksum. - * Note: Will be wrong if the checksum is zero, but i'll take my chances on that not happenning ;) - */ -static uae_u32 action_replay_calculate_checksum(void) -{ - uae_u32* checksum_end; - uae_u32* checksum_start; - uae_u8 checksum_start_offset[] = { 0, 0, 4, 0x7c }; - uae_u32 checksum = 0; - uae_u32 stored_checksum; - - /* All models: The checksum is calculated right upto the long checksum in the rom. - * AR1: The checksum starts at offset 0. - * AR1: The checksum is the last non-zero long in the rom. - * AR2: The checksum starts at offset 4. - * AR2: The checksum is the last Long in the rom. - * AR3: The checksum starts at offset 0x7c. - * AR3: The checksum is the last Long in the rom. - * - * Checksums: (This is a good way to compare roms. I have two with different md5sums, - * but the same checksum, so the difference must be in the first four bytes.) - * 3.17 0xf009bfc9 - * 3.09 0xd34d04a7 - * 2.14 0xad839d36 - * 2.14 0xad839d36 - * 1.15 0xee12116 - */ - - if (!armemory_rom) - return 0; /* If there is no rom then i guess the checksum is ok */ - - checksum_start = (uae_u32*)&armemory_rom[checksum_start_offset[armodel]]; - checksum_end = (uae_u32*)&armemory_rom[ar_rom_file_size]; - - /* Search for first non-zero Long starting from the end of the rom. */ - /* Assume long alignment, (will always be true for AR2 and AR3 and the AR1 rom i've got). */ - /* If anyone finds an AR1 rom with a word-aligned checksum, then this code will have to be modified. */ - while (! *(--checksum_end)); - - if (armodel == 1) - { - uae_u16* rom_ptr_word; - uae_s16 sign_extended_word; - - rom_ptr_word = (uae_u16*)checksum_start; - while (rom_ptr_word != (uae_u16*)checksum_end) +* Else, it returns the calculated checksum. +* Note: Will be wrong if the checksum is zero, but i'll take my chances on that not happenning ;) +*/ +static uae_u32 action_replay_calculate_checksum (void) +{ + uae_u32* checksum_end; + uae_u32* checksum_start; + uae_u8 checksum_start_offset[] = { 0, 0, 4, 0x7c }; + uae_u32 checksum = 0; + uae_u32 stored_checksum; + + /* All models: The checksum is calculated right upto the long checksum in the rom. + * AR1: The checksum starts at offset 0. + * AR1: The checksum is the last non-zero long in the rom. + * AR2: The checksum starts at offset 4. + * AR2: The checksum is the last Long in the rom. + * AR3: The checksum starts at offset 0x7c. + * AR3: The checksum is the last Long in the rom. + * + * Checksums: (This is a good way to compare roms. I have two with different md5sums, + * but the same checksum, so the difference must be in the first four bytes.) + * 3.17 0xf009bfc9 + * 3.09 0xd34d04a7 + * 2.14 0xad839d36 + * 2.14 0xad839d36 + * 1.15 0xee12116 + */ + + if (!armemory_rom) + return 0; /* If there is no rom then i guess the checksum is ok */ + + checksum_start = (uae_u32*)&armemory_rom[checksum_start_offset[armodel]]; + checksum_end = (uae_u32*)&armemory_rom[ar_rom_file_size]; + + /* Search for first non-zero Long starting from the end of the rom. */ + /* Assume long alignment, (will always be true for AR2 and AR3 and the AR1 rom i've got). */ + /* If anyone finds an AR1 rom with a word-aligned checksum, then this code will have to be modified. */ + while (! *(--checksum_end)); + + if (armodel == 1) { - sign_extended_word = (uae_s16)do_get_mem_word (rom_ptr_word); - /* When the word is cast on the following line, it will get sign-extended. */ - checksum += (uae_u32)sign_extended_word; - rom_ptr_word++; + uae_u16* rom_ptr_word; + uae_s16 sign_extended_word; + + rom_ptr_word = (uae_u16*)checksum_start; + while (rom_ptr_word != (uae_u16*)checksum_end) + { + sign_extended_word = (uae_s16)do_get_mem_word (rom_ptr_word); + /* When the word is cast on the following line, it will get sign-extended. */ + checksum += (uae_u32)sign_extended_word; + rom_ptr_word++; + } } - } - else - { - uae_u32* rom_ptr_long; - rom_ptr_long = checksum_start; - while (rom_ptr_long != checksum_end) + else { - checksum += do_get_mem_long (rom_ptr_long); - rom_ptr_long++; + uae_u32* rom_ptr_long; + rom_ptr_long = checksum_start; + while (rom_ptr_long != checksum_end) + { + checksum += do_get_mem_long (rom_ptr_long); + rom_ptr_long++; + } } - } - stored_checksum = do_get_mem_long (checksum_end); + stored_checksum = do_get_mem_long (checksum_end); - return checksum == stored_checksum ? 0 : checksum; + return checksum == stored_checksum ? 0 : checksum; } /* Returns 0 on error. */ -static uae_u8* get_checksum_location() +static uae_u8* get_checksum_location (void) { - uae_u32* checksum_end; + uae_u32* checksum_end; - /* See action_replay_calculate_checksum() for checksum info. */ + /* See action_replay_calculate_checksum() for checksum info. */ - if (!armemory_rom) - return 0; + if (!armemory_rom) + return 0; - checksum_end = (uae_u32*)&armemory_rom[ar_rom_file_size]; + checksum_end = (uae_u32*)&armemory_rom[ar_rom_file_size]; - /* Search for first non-zero Long starting from the end of the rom. */ - while (! *(--checksum_end)); + /* Search for first non-zero Long starting from the end of the rom. */ + while (! *(--checksum_end)); - return (uae_u8*)checksum_end; + return (uae_u8*)checksum_end; } /* Replaces the existing cart checksum with a correct one. */ /* Useful if you want to patch the rom. */ -static void action_replay_fixup_checksum(uae_u32 new_checksum) +static void action_replay_fixup_checksum (uae_u32 new_checksum) { - uae_u32* checksum = (uae_u32*)get_checksum_location(); - if (checksum) - do_put_mem_long (checksum, new_checksum); - else - write_log (L"Unable to locate Checksum in ROM.\n"); - return; + uae_u32* checksum = (uae_u32*)get_checksum_location(); + if (checksum) + do_put_mem_long (checksum, new_checksum); + else + write_log (L"Unable to locate Checksum in ROM.\n"); + return; } /* Longword search on word boundary - * the search_value is assumed to already be in the local endian format - * return 0 on failure - */ +* the search_value is assumed to already be in the local endian format +* return 0 on failure +*/ static uae_u8* find_absolute_long (uae_u8* start_addr, uae_u8* end_addr, uae_u32 search_value) { - uae_u8* addr; + uae_u8* addr; - for (addr = start_addr; addr < end_addr;) { - if (do_get_mem_long ((uae_u32*)addr) == search_value) { -/* write_log_debug("Found %p at offset %p.\n", search_value, addr - start_addr);*/ - return addr; + for (addr = start_addr; addr < end_addr;) { + if (do_get_mem_long ((uae_u32*)addr) == search_value) { + /* write_log_debug("Found %p at offset %p.\n", search_value, addr - start_addr);*/ + return addr; + } + addr += 2; } - addr += 2; - } - return 0; + return 0; } /* word search on word boundary - * the search_addr is assumed to already be in the local endian format - * return 0 on failure - * Currently only tested where the address we are looking for is AFTER the instruction. - * Not sure it works with negative offsets. - */ -static uae_u8* find_relative_word(uae_u8* start_addr, uae_u8* end_addr, uae_u16 search_addr) -{ - uae_u8* addr; - - for (addr = start_addr; addr < end_addr;) { - if (do_get_mem_word((uae_u16*)addr) == (uae_u16)(search_addr - (uae_u16)(addr - start_addr))) { -/* write_log_debug("Found %p at offset %p.\n", search_addr, addr - start_addr);*/ - return addr; +* the search_addr is assumed to already be in the local endian format +* return 0 on failure +* Currently only tested where the address we are looking for is AFTER the instruction. +* Not sure it works with negative offsets. +*/ +static uae_u8* find_relative_word (uae_u8* start_addr, uae_u8* end_addr, uae_u16 search_addr) +{ + uae_u8* addr; + + for (addr = start_addr; addr < end_addr;) { + if (do_get_mem_word((uae_u16*)addr) == (uae_u16)(search_addr - (uae_u16)(addr - start_addr))) { + /* write_log_debug("Found %p at offset %p.\n", search_addr, addr - start_addr);*/ + return addr; + } + addr += 2; } - addr += 2; - } - return 0; + return 0; } /* Disable rom test */ /* This routine replaces the rom-test routine with a 'rts'. - * It does this in a 'safe' way, by searching for a reference to the checksum - * and only disables it if the surounding bytes are what it expects. - */ - -static void disable_rom_test(void) -{ - uae_u8* addr; - - uae_u8* start_addr = armemory_rom; - uae_u8* end_addr = get_checksum_location(); - - /* - * To see what the routine below is doing. Here is some code from the Action replay rom where it does the - * checksum test. - * AR1: - * F0D4D0 6100 ???? bsr.w calc_checksum ; calculate the checksum - * F0D4D4 41FA 147A lea (0xf0e950,PC),a0 ; load the existing checksum. - * ; do a comparison. - * AR2: - * 40EC92 6100 ???? bsr.w calc_checksum - * 40EC96 41F9 0041 FFFC lea (0x41fffc),a0 - */ - - if (armodel == 1) { - uae_u16 search_value_rel = end_addr - start_addr; - addr = find_relative_word(start_addr, end_addr, search_value_rel); - - if (addr) { - if (do_get_mem_word((uae_u16*)(addr-6)) == 0x6100 && /* bsr.w */ - do_get_mem_word((uae_u16*)(addr-2)) == 0x41fa) /* lea relative */ - { - write_log (L"Patching to disable ROM TEST.\n"); - do_put_mem_word((uae_u16*)(addr-6), 0x4e75); /* rts */ - } - } - } else { - uae_u32 search_value_abs = arrom_start + end_addr - start_addr; - addr = find_absolute_long (start_addr, end_addr, search_value_abs); - - if (addr) { - if (do_get_mem_word((uae_u16*)(addr-6)) == 0x6100 && /* bsr.w */ - do_get_mem_word((uae_u16*)(addr-2)) == 0x41f9) /* lea absolute */ - { - write_log (L"Patching to disable ROM TEST.\n"); - do_put_mem_word((uae_u16*)(addr-6), 0x4e75); /* rts */ - } +* It does this in a 'safe' way, by searching for a reference to the checksum +* and only disables it if the surounding bytes are what it expects. +*/ + +static void disable_rom_test (void) +{ + uae_u8* addr; + + uae_u8* start_addr = armemory_rom; + uae_u8* end_addr = get_checksum_location(); + + /* + * To see what the routine below is doing. Here is some code from the Action replay rom where it does the + * checksum test. + * AR1: + * F0D4D0 6100 ???? bsr.w calc_checksum ; calculate the checksum + * F0D4D4 41FA 147A lea (0xf0e950,PC),a0 ; load the existing checksum. + * ; do a comparison. + * AR2: + * 40EC92 6100 ???? bsr.w calc_checksum + * 40EC96 41F9 0041 FFFC lea (0x41fffc),a0 + */ + + if (armodel == 1) { + uae_u16 search_value_rel = end_addr - start_addr; + addr = find_relative_word(start_addr, end_addr, search_value_rel); + + if (addr) { + if (do_get_mem_word((uae_u16*)(addr-6)) == 0x6100 && /* bsr.w */ + do_get_mem_word((uae_u16*)(addr-2)) == 0x41fa) /* lea relative */ + { + write_log (L"Patching to disable ROM TEST.\n"); + do_put_mem_word((uae_u16*)(addr-6), 0x4e75); /* rts */ + } + } + } else { + uae_u32 search_value_abs = arrom_start + end_addr - start_addr; + addr = find_absolute_long (start_addr, end_addr, search_value_abs); + + if (addr) { + if (do_get_mem_word((uae_u16*)(addr-6)) == 0x6100 && /* bsr.w */ + do_get_mem_word((uae_u16*)(addr-2)) == 0x41f9) /* lea absolute */ + { + write_log (L"Patching to disable ROM TEST.\n"); + do_put_mem_word((uae_u16*)(addr-6), 0x4e75); /* rts */ + } + } } - } } /* After we have calculated the checksum, and verified the rom is ok, - * we can do two things. - * 1. (optionally)Patch it and then update the checksum. - * 2. Remove the checksum check and (optionally) patch it. - * I have chosen to use no.2 here, because it should speed up the Action Replay slightly (and it was fun). - */ -static void action_replay_checksum_info(void) -{ - if (!armemory_rom) - return; - if (action_replay_calculate_checksum() == 0) - write_log (L"Action Replay Checksum is OK.\n"); - else - write_log (L"Action Replay Checksum is INVALID.\n"); - disable_rom_test(); +* we can do two things. +* 1. (optionally)Patch it and then update the checksum. +* 2. Remove the checksum check and (optionally) patch it. +* I have chosen to use no.2 here, because it should speed up the Action Replay slightly (and it was fun). +*/ +static void action_replay_checksum_info (void) +{ + if (!armemory_rom) + return; + if (action_replay_calculate_checksum() == 0) + write_log (L"Action Replay Checksum is OK.\n"); + else + write_log (L"Action Replay Checksum is INVALID.\n"); + disable_rom_test(); } static void action_replay_setbanks (void) { - if (!savestate_state && chipmem_bank.lput == chipmem_lput) { - switch (armodel) { - case 2: - case 3: - if (currprefs.cpu_cycle_exact) - chipmem_bank.wput = chipmem_wput_actionreplay23; - chipmem_bank.lput = chipmem_lput_actionreplay23; - break; - case 1: - chipmem_bank.bput = chipmem_bput_actionreplay1; - chipmem_bank.wput = chipmem_wput_actionreplay1; - chipmem_bank.lput = chipmem_lput_actionreplay1; - break; + if (!savestate_state && chipmem_bank.lput == chipmem_lput) { + switch (armodel) { + case 2: + case 3: + if (currprefs.cpu_cycle_exact) + chipmem_bank.wput = chipmem_wput_actionreplay23; + chipmem_bank.lput = chipmem_lput_actionreplay23; + break; + case 1: + chipmem_bank.bput = chipmem_bput_actionreplay1; + chipmem_bank.wput = chipmem_wput_actionreplay1; + chipmem_bank.lput = chipmem_lput_actionreplay1; + break; + } } - } } static void action_replay_unsetbanks (void) { - chipmem_bank.bput = chipmem_bput; - chipmem_bank.wput = chipmem_wput; - chipmem_bank.lput = chipmem_lput; + chipmem_bank.bput = chipmem_bput; + chipmem_bank.wput = chipmem_wput; + chipmem_bank.lput = chipmem_lput; } /* param to allow us to unload the cart. Currently we know it is safe if we are doing a reset to unload it.*/ int action_replay_unload (int in_memory_reset) { - static const TCHAR *state[] = { - L"ACTION_REPLAY_WAIT_PC", - L"ACTION_REPLAY_INACTIVE", - L"ACTION_REPLAY_WAITRESET", - L"0", - L"ACTION_REPLAY_IDLE", - L"ACTION_REPLAY_ACTIVATE", - L"ACTION_REPLAY_ACTIVE", - L"ACTION_REPLAY_DORESET", - L"ACTION_REPLAY_HIDE", - }; - - write_log_debug (L"Action Replay State:(%s)\nHrtmon State:(%s)\n", - state[action_replay_flag + 3], state[hrtmon_flag + 3]); - - if (armemory_rom && armodel == 1) { - if (is_ar_pc_in_ram() || is_ar_pc_in_rom() || action_replay_flag == ACTION_REPLAY_WAIT_PC) { - write_log (L"Can't Unload Action Replay 1. It is Active.\n"); - return 0; - } - } else { - if (action_replay_flag != ACTION_REPLAY_IDLE && action_replay_flag != ACTION_REPLAY_INACTIVE) { - write_log (L"Can't Unload Action Replay. It is Active.\n"); - return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ - } - if (hrtmon_flag != ACTION_REPLAY_IDLE && hrtmon_flag != ACTION_REPLAY_INACTIVE) { - write_log (L"Can't Unload Hrtmon. It is Active.\n"); - return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ + static const TCHAR *state[] = { + L"ACTION_REPLAY_WAIT_PC", + L"ACTION_REPLAY_INACTIVE", + L"ACTION_REPLAY_WAITRESET", + L"0", + L"ACTION_REPLAY_IDLE", + L"ACTION_REPLAY_ACTIVATE", + L"ACTION_REPLAY_ACTIVE", + L"ACTION_REPLAY_DORESET", + L"ACTION_REPLAY_HIDE", + }; + + write_log_debug (L"Action Replay State:(%s)\nHrtmon State:(%s)\n", + state[action_replay_flag + 3], state[hrtmon_flag + 3]); + + if (armemory_rom && armodel == 1) { + if (is_ar_pc_in_ram() || is_ar_pc_in_rom() || action_replay_flag == ACTION_REPLAY_WAIT_PC) { + write_log (L"Can't Unload Action Replay 1. It is Active.\n"); + return 0; + } + } else { + if (action_replay_flag != ACTION_REPLAY_IDLE && action_replay_flag != ACTION_REPLAY_INACTIVE) { + write_log (L"Can't Unload Action Replay. It is Active.\n"); + return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ + } + if (hrtmon_flag != ACTION_REPLAY_IDLE && hrtmon_flag != ACTION_REPLAY_INACTIVE) { + write_log (L"Can't Unload Hrtmon. It is Active.\n"); + return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ + } } - } - unset_special (SPCFLAG_ACTION_REPLAY); /* This shouldn't be necessary here, but just in case. */ - action_replay_flag = ACTION_REPLAY_INACTIVE; - hrtmon_flag = ACTION_REPLAY_INACTIVE; - action_replay_unsetbanks (); - action_replay_unmap_banks (); - hrtmon_unmap_banks (); - /* Make sure you unmap everything before you call action_replay_cleanup() */ - action_replay_cleanup (); - return 1; + unset_special (SPCFLAG_ACTION_REPLAY); /* This shouldn't be necessary here, but just in case. */ + action_replay_flag = ACTION_REPLAY_INACTIVE; + hrtmon_flag = ACTION_REPLAY_INACTIVE; + action_replay_unsetbanks (); + action_replay_unmap_banks (); + hrtmon_unmap_banks (); + /* Make sure you unmap everything before you call action_replay_cleanup() */ + action_replay_cleanup (); + return 1; } static int superiv_init (struct romdata *rd, struct zfile *f) { - uae_u32 chip = currprefs.chipmem_size - 0x10000; - int subtype = rd->id; - int flags = rd->type; - TCHAR *memname1, *memname2, *memname3; - - memname1 = memname2 = memname3 = NULL; - - cart_type = CART_SUPER4; - - hrtmon_custom = 0; - hrtmon_ciaa = 0; - hrtmon_ciab = 0; - - if (flags & ROMTYPE_XPOWER) { /* xpower */ - hrtmem_start = 0xe20000; - hrtmem_size = 0x20000; - hrtmem2_start = 0xf20000; - hrtmem2_size = 0x10000; - hrtmem_rom = 1; - memname1 = L"xpower_e2"; - memname2 = L"xpower_f2"; - } else if (flags & ROMTYPE_NORDIC) { /* nordic */ - hrtmem_start = 0xf00000; - hrtmem_size = 0x10000; - hrtmem_end = 0xf20000; - hrtmem2_start = 0xf40000; - hrtmem2_end = 0xf60000; - hrtmem2_size = 0x10000; - hrtmem_rom = 1; - memname1 = L"nordic_f0"; - memname2 = L"nordic_f4"; - if (subtype == 70) { - hrtmem_start += 0x60000; - hrtmem_end += 0x60000; - memname1 = L"nordic_f6"; + uae_u32 chip = currprefs.chipmem_size - 0x10000; + int subtype = rd->id; + int flags = rd->type; + TCHAR *memname1, *memname2, *memname3; + + memname1 = memname2 = memname3 = NULL; + + cart_type = CART_SUPER4; + + hrtmon_custom = 0; + hrtmon_ciaa = 0; + hrtmon_ciab = 0; + + if (flags & ROMTYPE_XPOWER) { /* xpower */ + hrtmem_start = 0xe20000; + hrtmem_size = 0x20000; + hrtmem2_start = 0xf20000; + hrtmem2_size = 0x10000; + hrtmem_rom = 1; + memname1 = L"xpower_e2"; + memname2 = L"xpower_f2"; + } else if (flags & ROMTYPE_NORDIC) { /* nordic */ + hrtmem_start = 0xf00000; + hrtmem_size = 0x10000; + hrtmem_end = 0xf20000; + hrtmem2_start = 0xf40000; + hrtmem2_end = 0xf60000; + hrtmem2_size = 0x10000; + hrtmem_rom = 1; + memname1 = L"nordic_f0"; + memname2 = L"nordic_f4"; + if (subtype == 70) { + hrtmem_start += 0x60000; + hrtmem_end += 0x60000; + memname1 = L"nordic_f6"; + } + } else { /* super4 */ + hrtmem_start = 0xd00000; + hrtmem_size = 0x40000; + hrtmem2_start = 0xb00000; + hrtmem2_size = 0x100000; + hrtmem2_size2 = 0x0c0000; + hrtmem3_start = 0xe00000; + hrtmem3_size = 0x80000; + memname1 = L"superiv_d0"; + memname2 = L"superiv_b0"; + memname3 = L"superiv_e0"; } - } else { /* super4 */ - hrtmem_start = 0xd00000; - hrtmem_size = 0x40000; - hrtmem2_start = 0xb00000; - hrtmem2_size = 0x100000; - hrtmem2_size2 = 0x0c0000; - hrtmem3_start = 0xe00000; - hrtmem3_size = 0x80000; - memname1 = L"superiv_d0"; - memname2 = L"superiv_b0"; - memname3 = L"superiv_e0"; - } - if (hrtmem2_size && !hrtmem2_size2) - hrtmem2_size2 = hrtmem2_size; - - hrtmemory = mapped_malloc (hrtmem_size, memname1); - memset (hrtmemory, 0x00, hrtmem_size); - if (f) { - zfile_fseek (f, 0, SEEK_SET); - zfile_fread (hrtmemory, 1, hrtmem_size, f); - zfile_fclose (f); - } - - hrtmem_mask = hrtmem_size - 1; - hrtmem2_mask = hrtmem2_size - 1; - hrtmem3_mask = hrtmem3_size - 1; - if (hrtmem2_size) { - hrtmemory2 = mapped_malloc (hrtmem2_size, memname2); - memset(hrtmemory2, 0, hrtmem2_size); - } - if (hrtmem3_size) { - hrtmemory3 = mapped_malloc (hrtmem3_size, memname3); - memset(hrtmemory3, 0, hrtmem3_size); - } - hrtmem3_bank.baseaddr = hrtmemory3; - hrtmem2_bank.baseaddr = hrtmemory2; - hrtmem_bank.baseaddr = hrtmemory; - - if (flags & ROMTYPE_XPOWER) { - hrtmon_custom = hrtmemory2 + 0xfc00; - hrtmon_ciaa = hrtmemory2 + 0xfc00; - hrtmon_ciab = hrtmemory2 + 0xfc01; - hrtmon_ciadiv = 2; - chip += 0x30000; - hrtmemory2[0xfc80] = chip >> 24; - hrtmemory2[0xfc81] = chip >> 16; - hrtmemory2[0xfc82] = chip >> 8; - hrtmemory2[0xfc83] = chip >> 0; - } else if (flags & ROMTYPE_NORDIC) { - hrtmon_custom = hrtmemory2 + 0x3c00; - hrtmon_ciaa = hrtmemory2 + 0x3c00; - hrtmon_ciab = hrtmemory2 + 0x3c01; - hrtmon_ciadiv = 2; - hrtmon_zeropage = hrtmemory2 + 0; /* eh? why not just use CPU? */ - } else { - hrtmon_custom = hrtmemory3 + 0x040000; - hrtmon_ciaa = hrtmemory2 + 0x040000; - hrtmon_ciab = hrtmemory2 + 0x040001; - chip += 0x30000; - hrtmemory2[0x80] = chip >> 24; - hrtmemory2[0x81] = chip >> 16; - hrtmemory2[0x82] = chip >> 8; - hrtmemory2[0x83] = chip >> 0; - } - - hrtmon_flag = ACTION_REPLAY_IDLE; - write_log (L"%s installed at %08X\n", cart_memnames[cart_type], hrtmem_start); - return 1; + if (hrtmem2_size && !hrtmem2_size2) + hrtmem2_size2 = hrtmem2_size; + + hrtmemory = mapped_malloc (hrtmem_size, memname1); + memset (hrtmemory, 0x00, hrtmem_size); + if (f) { + zfile_fseek (f, 0, SEEK_SET); + zfile_fread (hrtmemory, 1, hrtmem_size, f); + zfile_fclose (f); + } + + hrtmem_mask = hrtmem_size - 1; + hrtmem2_mask = hrtmem2_size - 1; + hrtmem3_mask = hrtmem3_size - 1; + if (hrtmem2_size) { + hrtmemory2 = mapped_malloc (hrtmem2_size, memname2); + memset(hrtmemory2, 0, hrtmem2_size); + } + if (hrtmem3_size) { + hrtmemory3 = mapped_malloc (hrtmem3_size, memname3); + memset(hrtmemory3, 0, hrtmem3_size); + } + hrtmem3_bank.baseaddr = hrtmemory3; + hrtmem2_bank.baseaddr = hrtmemory2; + hrtmem_bank.baseaddr = hrtmemory; + + if (flags & ROMTYPE_XPOWER) { + hrtmon_custom = hrtmemory2 + 0xfc00; + hrtmon_ciaa = hrtmemory2 + 0xfc00; + hrtmon_ciab = hrtmemory2 + 0xfc01; + hrtmon_ciadiv = 2; + chip += 0x30000; + hrtmemory2[0xfc80] = chip >> 24; + hrtmemory2[0xfc81] = chip >> 16; + hrtmemory2[0xfc82] = chip >> 8; + hrtmemory2[0xfc83] = chip >> 0; + } else if (flags & ROMTYPE_NORDIC) { + hrtmon_custom = hrtmemory2 + 0x3c00; + hrtmon_ciaa = hrtmemory2 + 0x3c00; + hrtmon_ciab = hrtmemory2 + 0x3c01; + hrtmon_ciadiv = 2; + hrtmon_zeropage = hrtmemory2 + 0; /* eh? why not just use CPU? */ + } else { + hrtmon_custom = hrtmemory3 + 0x040000; + hrtmon_ciaa = hrtmemory2 + 0x040000; + hrtmon_ciab = hrtmemory2 + 0x040001; + chip += 0x30000; + hrtmemory2[0x80] = chip >> 24; + hrtmemory2[0x81] = chip >> 16; + hrtmemory2[0x82] = chip >> 8; + hrtmemory2[0x83] = chip >> 0; + } + + hrtmon_flag = ACTION_REPLAY_IDLE; + write_log (L"%s installed at %08X\n", cart_memnames[cart_type], hrtmem_start); + return 1; } int action_replay_load (void) { - struct zfile *f; - uae_u8 header[8]; - struct romdata *rd; - - armodel = 0; - action_replay_flag = ACTION_REPLAY_INACTIVE; - write_log_debug (L"Entered action_replay_load ()\n"); - /* Don't load a rom if one is already loaded. Use action_replay_unload () first. */ - if (armemory_rom || hrtmemory) { - write_log (L"action_replay_load () ROM already loaded.\n"); - return 0; - } + struct zfile *f; + uae_u8 header[8]; + struct romdata *rd; + + armodel = 0; + action_replay_flag = ACTION_REPLAY_INACTIVE; + write_log_debug (L"Entered action_replay_load ()\n"); + /* Don't load a rom if one is already loaded. Use action_replay_unload () first. */ + if (armemory_rom || hrtmemory) { + write_log (L"action_replay_load () ROM already loaded.\n"); + return 0; + } - if (_tcslen (currprefs.cartfile) == 0) - return 0; - rd = getromdatabypath (currprefs.cartfile); - if (rd) { - if (rd->id == 62) - return superiv_init (rd, NULL); - if (rd->type & ROMTYPE_CD32CART) - return 0; - } - f = read_rom_name (currprefs.cartfile); - if (!f) { - write_log (L"failed to load '%s' cartridge ROM\n", currprefs.cartfile); - return 0; - } - rd = getromdatabyzfile(f); - if (!rd) { - write_log (L"Unknown cartridge ROM\n"); - } else { - if (rd->type & (ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER)) { - return superiv_init (rd, f); + if (_tcslen (currprefs.cartfile) == 0) + return 0; + rd = getromdatabypath (currprefs.cartfile); + if (rd) { + if (rd->id == 62) + return superiv_init (rd, NULL); + if (rd->type & ROMTYPE_CD32CART) + return 0; + } + f = read_rom_name (currprefs.cartfile); + if (!f) { + write_log (L"failed to load '%s' cartridge ROM\n", currprefs.cartfile); + return 0; + } + rd = getromdatabyzfile(f); + if (!rd) { + write_log (L"Unknown cartridge ROM\n"); + } else { + if (rd->type & (ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER)) { + return superiv_init (rd, f); + } } - } - zfile_fseek(f, 0, SEEK_END); - ar_rom_file_size = zfile_ftell(f); - zfile_fseek(f, 0, SEEK_SET); - zfile_fread (header, 1, sizeof header, f); - zfile_fseek (f, 0, SEEK_SET); - if (!memcmp (header, "ATZ!HRT!", 8)) { + zfile_fseek(f, 0, SEEK_END); + ar_rom_file_size = zfile_ftell(f); + zfile_fseek(f, 0, SEEK_SET); + zfile_fread (header, 1, sizeof header, f); + zfile_fseek (f, 0, SEEK_SET); + if (!memcmp (header, "ATZ!HRT!", 8)) { + zfile_fclose (f); + return 0; + } + if (ar_rom_file_size != 65536 && ar_rom_file_size != 131072 && ar_rom_file_size != 262144) { + write_log (L"rom size must be 64KB (AR1), 128KB (AR2) or 256KB (AR3)\n"); + zfile_fclose(f); + return 0; + } + action_replay_flag = ACTION_REPLAY_INACTIVE; + armemory_rom = xmalloc (ar_rom_file_size); + zfile_fread (armemory_rom, 1, ar_rom_file_size, f); zfile_fclose (f); - return 0; - } - if (ar_rom_file_size != 65536 && ar_rom_file_size != 131072 && ar_rom_file_size != 262144) { - write_log (L"rom size must be 64KB (AR1), 128KB (AR2) or 256KB (AR3)\n"); - zfile_fclose(f); - return 0; - } - action_replay_flag = ACTION_REPLAY_INACTIVE; - armemory_rom = xmalloc (ar_rom_file_size); - zfile_fread (armemory_rom, 1, ar_rom_file_size, f); - zfile_fclose (f); - if (ar_rom_file_size == 65536) { - armodel = 1; - arrom_start = 0xf00000; - arrom_size = 0x10000; - /* real AR1 RAM location is 0x9fc000-0x9fffff */ - arram_start = 0x9f0000; - arram_size = 0x10000; - } else { - armodel = ar_rom_file_size / 131072 + 1; - arrom_start = 0x400000; - arrom_size = armodel == 2 ? 0x20000 : 0x40000; - arram_start = 0x440000; - arram_size = 0x10000; - } - arram_mask = arram_size - 1; - arrom_mask = arrom_size - 1; - armemory_ram = xcalloc (arram_size, 1); - write_log (L"Action Replay %d installed at %08X, size %08X\n", armodel, arrom_start, arrom_size); - action_replay_version(); - return armodel; + if (ar_rom_file_size == 65536) { + armodel = 1; + arrom_start = 0xf00000; + arrom_size = 0x10000; + /* real AR1 RAM location is 0x9fc000-0x9fffff */ + arram_start = 0x9f0000; + arram_size = 0x10000; + } else { + armodel = ar_rom_file_size / 131072 + 1; + arrom_start = 0x400000; + arrom_size = armodel == 2 ? 0x20000 : 0x40000; + arram_start = 0x440000; + arram_size = 0x10000; + } + arram_mask = arram_size - 1; + arrom_mask = arrom_size - 1; + armemory_ram = xcalloc (arram_size, 1); + write_log (L"Action Replay %d installed at %08X, size %08X\n", armodel, arrom_start, arrom_size); + action_replay_version(); + return armodel; } void action_replay_init (int activate) { - if (!armemory_rom) - return; - hide_cart (0); - if (armodel > 1) - hide_cart (1); - if (activate) { + if (!armemory_rom) + return; + hide_cart (0); if (armodel > 1) - action_replay_flag = ACTION_REPLAY_WAITRESET; - } + hide_cart (1); + if (activate) { + if (armodel > 1) + action_replay_flag = ACTION_REPLAY_WAITRESET; + } } /* This only deallocates memory, it is not suitable for unloading roms and continuing */ void action_replay_cleanup() { - if (armemory_rom) - free (armemory_rom); - if (armemory_ram) - free (armemory_ram); - if (hrtmemory) - mapped_free (hrtmemory); - if (hrtmemory2) - mapped_free (hrtmemory2); - if (hrtmemory3) - mapped_free (hrtmemory3); - - armemory_rom = 0; - armemory_ram = 0; - hrtmemory = 0; - hrtmemory2 = 0; - hrtmemory3 = 0; - hrtmem_size = 0; - hrtmem2_size = 0; - hrtmem2_size2 = 0; - hrtmem3_size = 0; - cart_type = 0; - hrtmem_rom = 0; - hrtmon_ciadiv = 256; - hrtmon_zeropage = 0; - hrtmem_end = 0; - hrtmem2_end = 0; + if (armemory_rom) + free (armemory_rom); + if (armemory_ram) + free (armemory_ram); + if (hrtmemory) + mapped_free (hrtmemory); + if (hrtmemory2) + mapped_free (hrtmemory2); + if (hrtmemory3) + mapped_free (hrtmemory3); + + armemory_rom = 0; + armemory_ram = 0; + hrtmemory = 0; + hrtmemory2 = 0; + hrtmemory3 = 0; + hrtmem_size = 0; + hrtmem2_size = 0; + hrtmem2_size2 = 0; + hrtmem3_size = 0; + cart_type = 0; + hrtmem_rom = 0; + hrtmon_ciadiv = 256; + hrtmon_zeropage = 0; + hrtmem_end = 0; + hrtmem2_end = 0; } #ifndef FALSE @@ -1745,157 +1745,157 @@ int hrtmon_lang = 0; static void hrtmon_configure(void) { - HRTCFG *cfg = (HRTCFG*)hrtmemory; - if (cart_type != CART_HRTMON || armodel || !cfg) - return; - cfg->col0h = 0x00; cfg->col0l = 0x5a; - cfg->col1h = 0x0f; cfg->col1l = 0xff; - cfg->aga = (currprefs.chipset_mask & CSMASK_AGA) ? 1 : 0; - cfg->cd32 = currprefs.cs_cd32cd ? 1 : 0; - cfg->screenmode = currprefs.ntscmode; - cfg->novbr = TRUE; - cfg->hexmode = TRUE; - cfg->entered = 0; - cfg->keyboard = hrtmon_lang; - do_put_mem_long (&cfg->max_chip, currprefs.chipmem_size); - do_put_mem_long (&cfg->mon_size, 0x800000); - cfg->ide = currprefs.cs_ide ? 1 : 0; - cfg->a1200 = currprefs.cs_ide == IDE_A600A1200 ? 1 : 0; /* type of IDE interface, not Amiga model */ + HRTCFG *cfg = (HRTCFG*)hrtmemory; + if (cart_type != CART_HRTMON || armodel || !cfg) + return; + cfg->col0h = 0x00; cfg->col0l = 0x5a; + cfg->col1h = 0x0f; cfg->col1l = 0xff; + cfg->aga = (currprefs.chipset_mask & CSMASK_AGA) ? 1 : 0; + cfg->cd32 = currprefs.cs_cd32cd ? 1 : 0; + cfg->screenmode = currprefs.ntscmode; + cfg->novbr = TRUE; + cfg->hexmode = TRUE; + cfg->entered = 0; + cfg->keyboard = hrtmon_lang; + do_put_mem_long (&cfg->max_chip, currprefs.chipmem_size); + do_put_mem_long (&cfg->mon_size, 0x800000); + cfg->ide = currprefs.cs_ide ? 1 : 0; + cfg->a1200 = currprefs.cs_ide == IDE_A600A1200 ? 1 : 0; /* type of IDE interface, not Amiga model */ } int hrtmon_load (void) { - struct zfile *f; - uae_u32 header[4]; - struct romdata *rd; - int isinternal = 0; + struct zfile *f; + uae_u32 header[4]; + struct romdata *rd; + int isinternal = 0; - /* Don't load a rom if one is already loaded. Use action_replay_unload () first. */ - if (armemory_rom) - return 0; - if (hrtmemory) - return 0; - - triggered_once = 0; - armodel = 0; - cart_type = CART_AR; - hrtmem_start = 0xa10000; - rd = getromdatabypath(currprefs.cartfile); - if (rd) { - if (rd->id == 63) - isinternal = 1; - if (rd->type & ROMTYPE_CD32CART) - return 0; - } - - if (!isinternal) { - if (_tcslen (currprefs.cartfile) == 0) - return 0; - f = read_rom_name (currprefs.cartfile); - if(!f) { - write_log (L"failed to load '%s' cartridge ROM\n", currprefs.cartfile); - return 0; + /* Don't load a rom if one is already loaded. Use action_replay_unload () first. */ + if (armemory_rom) + return 0; + if (hrtmemory) + return 0; + + triggered_once = 0; + armodel = 0; + cart_type = CART_AR; + hrtmem_start = 0xa10000; + rd = getromdatabypath(currprefs.cartfile); + if (rd) { + if (rd->id == 63) + isinternal = 1; + if (rd->type & ROMTYPE_CD32CART) + return 0; } - zfile_fread(header, sizeof header, 1, f); - if (!memcmp (header, "ATZ!", 4)) { - cart_type = CART_AR1200; - armodel = 1200; - hrtmem_start = 0x800000; - } else if (!memcmp (header, "HRT!", 4)) { - cart_type = CART_HRTMON; - } else { - zfile_fclose (f); - return 0; + + if (!isinternal) { + if (_tcslen (currprefs.cartfile) == 0) + return 0; + f = read_rom_name (currprefs.cartfile); + if(!f) { + write_log (L"failed to load '%s' cartridge ROM\n", currprefs.cartfile); + return 0; + } + zfile_fread(header, sizeof header, 1, f); + if (!memcmp (header, "ATZ!", 4)) { + cart_type = CART_AR1200; + armodel = 1200; + hrtmem_start = 0x800000; + } else if (!memcmp (header, "HRT!", 4)) { + cart_type = CART_HRTMON; + } else { + zfile_fclose (f); + return 0; + } } - } - hrtmem_size = 0x100000; - hrtmem_mask = hrtmem_size - 1; - if (isinternal) { - #ifdef ACTION_REPLAY_HRTMON - struct zfile *zf; - zf = zfile_fopen_data (L"hrtrom.gz", hrtrom_len, hrtrom); -// f = zfile_fopen (L"d:\\amiga\\amiga\\hrtmon\\src\\hrtmon.rom", L"rb", 0); - f = zfile_gunzip (zf); - #else - return 0; - #endif - cart_type = CART_HRTMON; - } - hrtmemory = mapped_malloc (hrtmem_size, L"hrtmem"); - memset (hrtmemory, 0xff, 0x80000); - zfile_fseek (f, 0, SEEK_SET); - zfile_fread (hrtmemory, 1, 524288, f); - zfile_fclose (f); - hrtmon_configure (); - hrtmon_custom = hrtmemory + 0x08f000; - hrtmon_ciaa = hrtmemory + 0x08e000; - hrtmon_ciab = hrtmemory + 0x08d000; + hrtmem_size = 0x100000; + hrtmem_mask = hrtmem_size - 1; + if (isinternal) { +#ifdef ACTION_REPLAY_HRTMON + struct zfile *zf; + zf = zfile_fopen_data (L"hrtrom.gz", hrtrom_len, hrtrom); + // f = zfile_fopen (L"d:\\amiga\\amiga\\hrtmon\\src\\hrtmon.rom", L"rb", 0); + f = zfile_gunzip (zf); +#else + return 0; +#endif + cart_type = CART_HRTMON; + } + hrtmemory = mapped_malloc (hrtmem_size, L"hrtmem"); + memset (hrtmemory, 0xff, 0x80000); + zfile_fseek (f, 0, SEEK_SET); + zfile_fread (hrtmemory, 1, 524288, f); + zfile_fclose (f); + hrtmon_configure (); + hrtmon_custom = hrtmemory + 0x08f000; + hrtmon_ciaa = hrtmemory + 0x08e000; + hrtmon_ciab = hrtmemory + 0x08d000; #if 0 - if (hrtmem2_size) { - hrtmem2_mask = hrtmem2_size - 1; - hrtmemory2 = mapped_malloc (hrtmem2_size, cart_memnames2[cart_type]); - memset(hrtmemory2, 0, hrtmem2_size); - hrtmem2_bank.baseaddr = hrtmemory2; - } + if (hrtmem2_size) { + hrtmem2_mask = hrtmem2_size - 1; + hrtmemory2 = mapped_malloc (hrtmem2_size, cart_memnames2[cart_type]); + memset(hrtmemory2, 0, hrtmem2_size); + hrtmem2_bank.baseaddr = hrtmemory2; + } #endif - hrtmem_bank.baseaddr = hrtmemory; - hrtmon_flag = ACTION_REPLAY_IDLE; - write_log (L"%s installed at %08X\n", cart_memnames[cart_type], hrtmem_start); - return 1; + hrtmem_bank.baseaddr = hrtmemory; + hrtmon_flag = ACTION_REPLAY_IDLE; + write_log (L"%s installed at %08X\n", cart_memnames[cart_type], hrtmem_start); + return 1; } void hrtmon_map_banks (void) { - uaecptr addr; + uaecptr addr; - if (!hrtmemory) - return; + if (!hrtmemory) + return; - addr = hrtmem_start; - while (addr != hrtmem_end) { - map_banks (&hrtmem_bank, addr >> 16, hrtmem_size >> 16, 0); - addr += hrtmem_size; - if (!hrtmem_end) - break; - } - if (hrtmem2_size) { - addr = hrtmem2_start; - while (addr != hrtmem2_end) { - map_banks (&hrtmem2_bank, addr >> 16, hrtmem2_size2 >> 16, 0); - addr += hrtmem2_size; - if (!hrtmem2_end) - break; + addr = hrtmem_start; + while (addr != hrtmem_end) { + map_banks (&hrtmem_bank, addr >> 16, hrtmem_size >> 16, 0); + addr += hrtmem_size; + if (!hrtmem_end) + break; + } + if (hrtmem2_size) { + addr = hrtmem2_start; + while (addr != hrtmem2_end) { + map_banks (&hrtmem2_bank, addr >> 16, hrtmem2_size2 >> 16, 0); + addr += hrtmem2_size; + if (!hrtmem2_end) + break; + } } - } - if (hrtmem3_size) - map_banks (&hrtmem3_bank, hrtmem3_start >> 16, hrtmem3_size >> 16, 0); + if (hrtmem3_size) + map_banks (&hrtmem3_bank, hrtmem3_start >> 16, hrtmem3_size >> 16, 0); } static void hrtmon_unmap_banks (void) { - uaecptr addr; + uaecptr addr; - if (!hrtmemory) - return; + if (!hrtmemory) + return; - addr = hrtmem_start; - while (addr != hrtmem_end) { - map_banks (&dummy_bank, addr >> 16, hrtmem_size >> 16, 0); - addr += hrtmem_size; - if (!hrtmem_end) - break; - } - if (hrtmem2_size) { - addr = hrtmem2_start; - while (addr != hrtmem2_end) { - map_banks (&dummy_bank, addr >> 16, hrtmem2_size2 >> 16, 0); - addr += hrtmem2_size; - if (!hrtmem2_end) - break; + addr = hrtmem_start; + while (addr != hrtmem_end) { + map_banks (&dummy_bank, addr >> 16, hrtmem_size >> 16, 0); + addr += hrtmem_size; + if (!hrtmem_end) + break; + } + if (hrtmem2_size) { + addr = hrtmem2_start; + while (addr != hrtmem2_end) { + map_banks (&dummy_bank, addr >> 16, hrtmem2_size2 >> 16, 0); + addr += hrtmem2_size; + if (!hrtmem2_end) + break; + } } - } - if (hrtmem3_size) - map_banks (&dummy_bank, hrtmem3_start >> 16, hrtmem3_size >> 16, 0); + if (hrtmem3_size) + map_banks (&dummy_bank, hrtmem3_start >> 16, hrtmem3_size >> 16, 0); } #define AR_VER_STR_OFFSET 0x4 /* offset in the rom where the version string begins. */ @@ -1907,223 +1907,226 @@ static uae_char arVersionString[AR_VER_STR_LEN+1]; void action_replay_version(void) { - char* tmp; - int iArVersionMajor = -1 ; - int iArVersionMinor = -1; - char* pNext; - uae_char sArDate[11]; + char* tmp; + int iArVersionMajor = -1 ; + int iArVersionMinor = -1; + char* pNext; + uae_char sArDate[11]; - *sArDate = '\0'; - if (!armemory_rom) - return; + *sArDate = '\0'; + if (!armemory_rom) + return; + + if (armodel == 1) + return; /* no support yet. */ + + /* Extract Version string */ + memcpy(arVersionString, armemory_rom+AR_VER_STR_OFFSET, AR_VER_STR_LEN); + arVersionString[AR_VER_STR_LEN]= '\0'; + tmp = strchr(arVersionString, 0x0d); + if (tmp) { + *tmp = '\0'; + } + /* write_log_debug("Version string is : '%s'\n", arVersionString); */ - if (armodel == 1) - return; /* no support yet. */ - - /* Extract Version string */ - memcpy(arVersionString, armemory_rom+AR_VER_STR_OFFSET, AR_VER_STR_LEN); - arVersionString[AR_VER_STR_LEN]= '\0'; - tmp = strchr(arVersionString, 0x0d); - if (tmp) { - *tmp = '\0'; - } -/* write_log_debug("Version string is : '%s'\n", arVersionString); */ - - tmp = strchr(arVersionString,')'); - if (tmp) { - *tmp = '\0'; - tmp = strchr(arVersionString, '('); + tmp = strchr(arVersionString,')'); if (tmp) { - if (*(tmp + 1) == 'V') { - pNext = tmp + 2; - tmp = strchr(pNext, '.'); + *tmp = '\0'; + tmp = strchr(arVersionString, '('); if (tmp) { - *tmp = '\0'; - iArVersionMajor = atoi(pNext); - pNext = tmp+1; - tmp = strchr(pNext, ' '); - if (tmp) { - *tmp = '\0'; - iArVersionMinor = atoi(pNext); - } - pNext = tmp+1; - strcpy (sArDate, pNext); + if (*(tmp + 1) == 'V') { + pNext = tmp + 2; + tmp = strchr(pNext, '.'); + if (tmp) { + *tmp = '\0'; + iArVersionMajor = atoi(pNext); + pNext = tmp+1; + tmp = strchr(pNext, ' '); + if (tmp) { + *tmp = '\0'; + iArVersionMinor = atoi(pNext); + } + pNext = tmp+1; + strcpy (sArDate, pNext); + } + + } } - - } } - } - if (iArVersionMajor > 0) { - TCHAR *s = au (sArDate); - write_log (L"Version of cart is '%d.%.02d', date is '%s'\n", iArVersionMajor, iArVersionMinor, s); - xfree (s); - } + if (iArVersionMajor > 0) { + TCHAR *s = au (sArDate); + write_log (L"Version of cart is '%d.%.02d', date is '%s'\n", iArVersionMajor, iArVersionMinor, s); + xfree (s); + } } /* This function doesn't reset the Cart memory, it is just called during a memory reset */ -void action_replay_memory_reset(void) +void action_replay_memory_reset (void) { - #ifdef ACTION_REPLAY_HRTMON - if (hrtmemory) { - hrtmon_hide (); /* It is never really idle */ - hrtmon_flag = ACTION_REPLAY_IDLE; - if (cart_type == CART_SUPER4) - hrtmon_map_banks (); - } - #endif - #ifdef ACTION_REPLAY_COMMON - check_prefs_changed_carts (1); - #endif - action_replay_patch (); - action_replay_checksum_info (); - action_replay_setbanks (); - hrtmon_configure (); - if (armodel == 1) - action_replay_flag = ACTION_REPLAY_ACTIVE; +#ifdef ACTION_REPLAY_HRTMON + if (hrtmemory) { + hrtmon_hide (); /* It is never really idle */ + hrtmon_flag = ACTION_REPLAY_IDLE; + if (cart_type == CART_SUPER4) + hrtmon_map_banks (); + } +#endif +#ifdef ACTION_REPLAY_COMMON + check_prefs_changed_carts (1); +#endif + action_replay_patch (); + action_replay_checksum_info (); + action_replay_setbanks (); + hrtmon_configure (); + if (armodel == 1) + action_replay_flag = ACTION_REPLAY_ACTIVE; } uae_u8 *save_hrtmon (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; + uae_u8 *dstbak, *dst; - if (!hrtmemory) - return 0; - if (!triggered_once) - return 0; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = (uae_u8*)malloc (hrtmem_size + hrtmem2_size + sizeof ar_custom + sizeof ar_ciaa + sizeof ar_ciab + 1024); - save_u8 (cart_type); - save_u8 (0); - save_u32 (0); - save_string (currprefs.cartfile); - save_u32 (0); - if (!hrtmem_rom) { - save_u32 (hrtmem_size); - memcpy (dst, hrtmemory, hrtmem_size); - dst += hrtmem_size; - } else if (hrtmem2_size) { - save_u32 (hrtmem2_size); - memcpy (dst, hrtmemory2, hrtmem2_size); - dst += hrtmem2_size; - } else { + if (!hrtmemory) + return 0; + if (!triggered_once) + return 0; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = (uae_u8*)malloc (hrtmem_size + hrtmem2_size + sizeof ar_custom + sizeof ar_ciaa + sizeof ar_ciab + 1024); + save_u8 (cart_type); + save_u8 (0); + save_u32 (0); + save_string (currprefs.cartfile); save_u32 (0); - } - save_u32 (sizeof ar_custom); - memcpy (dst, ar_custom, sizeof ar_custom); - dst += sizeof ar_custom; - save_u32 (sizeof ar_ciaa); - memcpy (dst, ar_ciaa, sizeof ar_ciaa); - dst += sizeof ar_ciaa; - save_u32 (sizeof ar_ciab); - memcpy (dst, ar_ciab, sizeof ar_ciab); - dst += sizeof ar_ciab; - *len = dst - dstbak; - return dstbak; + if (!hrtmem_rom) { + save_u32 (hrtmem_size); + memcpy (dst, hrtmemory, hrtmem_size); + dst += hrtmem_size; + } else if (hrtmem2_size) { + save_u32 (hrtmem2_size); + memcpy (dst, hrtmemory2, hrtmem2_size); + dst += hrtmem2_size; + } else { + save_u32 (0); + } + save_u32 (sizeof ar_custom); + memcpy (dst, ar_custom, sizeof ar_custom); + dst += sizeof ar_custom; + save_u32 (sizeof ar_ciaa); + memcpy (dst, ar_ciaa, sizeof ar_ciaa); + dst += sizeof ar_ciaa; + save_u32 (sizeof ar_ciab); + memcpy (dst, ar_ciab, sizeof ar_ciab); + dst += sizeof ar_ciab; + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_hrtmon (uae_u8 *src) { - uae_u32 size; - TCHAR *s; - - action_replay_unload (1); - restore_u8 (); - restore_u8 (); - restore_u32 (); - s = restore_string (); - _tcsncpy (changed_prefs.cartfile, s, 255); - xfree (s); - _tcscpy (currprefs.cartfile, changed_prefs.cartfile); - hrtmon_load (); - action_replay_load (); - if (restore_u32 () != 0) + uae_u32 size; + TCHAR *s; + + action_replay_unload (1); + restore_u8 (); + restore_u8 (); + restore_u32 (); + s = restore_string (); + _tcsncpy (changed_prefs.cartfile, s, 255); + xfree (s); + _tcscpy (currprefs.cartfile, changed_prefs.cartfile); + hrtmon_load (); + action_replay_load (); + if (restore_u32 () != 0) + return src; + size = restore_u32 (); + if (!hrtmem_rom) { + if (hrtmemory) + memcpy (hrtmemory, src, size); + } else if (hrtmem2_size) { + if (hrtmemory2) + memcpy (hrtmemory2, src, size); + } + src += size; + restore_u32 (); + memcpy (ar_custom, src, sizeof ar_custom); + src += sizeof ar_custom; + restore_u32 (); + memcpy (ar_ciaa, src, sizeof ar_ciaa); + src += sizeof ar_ciaa; + restore_u32 (); + memcpy (ar_ciab, src, sizeof ar_ciab); + src += sizeof ar_ciab; return src; - size = restore_u32 (); - if (!hrtmem_rom) { - if (hrtmemory) - memcpy (hrtmemory, src, size); - } else if (hrtmem2_size) { - if (hrtmemory2) - memcpy (hrtmemory2, src, size); - } - src += size; - restore_u32 (); - memcpy (ar_custom, src, sizeof ar_custom); - src += sizeof ar_custom; - restore_u32 (); - memcpy (ar_ciaa, src, sizeof ar_ciaa); - src += sizeof ar_ciaa; - restore_u32 (); - memcpy (ar_ciab, src, sizeof ar_ciab); - src += sizeof ar_ciab; - return src; } uae_u8 *save_action_replay (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; + uae_u8 *dstbak, *dst; - if (!armemory_ram || !armemory_rom || !armodel) - return 0; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = malloc (arram_size + sizeof ar_custom + sizeof ar_ciaa + sizeof ar_ciab + 1024); - save_u8 (0); - save_u8 (armodel); - save_u32 (get_crc32 (armemory_rom + 4, arrom_size - 4)); - save_string (currprefs.cartfile); - save_u32 (arrom_size); - save_u32 (arram_size); - memcpy (dst, armemory_ram, arram_size); - dst += arram_size; - save_u32 (sizeof ar_custom); - memcpy (dst, ar_custom, sizeof ar_custom); - dst += sizeof ar_custom; - save_u32 (sizeof ar_ciaa); - memcpy (dst, ar_ciaa, sizeof ar_ciaa); - dst += sizeof ar_ciaa; - save_u32 (sizeof ar_ciab); - memcpy (dst, ar_ciab, sizeof ar_ciab); - dst += sizeof ar_ciab; - *len = dst - dstbak; - return dstbak; + if (!armemory_ram || !armemory_rom || !armodel) + return 0; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (arram_size + sizeof ar_custom + sizeof ar_ciaa + sizeof ar_ciab + 1024); + save_u8 (0); + save_u8 (armodel); + save_u32 (get_crc32 (armemory_rom + 4, arrom_size - 4)); + save_string (currprefs.cartfile); + save_u32 (arrom_size); + save_u32 (arram_size); + memcpy (dst, armemory_ram, arram_size); + dst += arram_size; + save_u32 (sizeof ar_custom); + memcpy (dst, ar_custom, sizeof ar_custom); + dst += sizeof ar_custom; + save_u32 (sizeof ar_ciaa); + memcpy (dst, ar_ciaa, sizeof ar_ciaa); + dst += sizeof ar_ciaa; + save_u32 (sizeof ar_ciab); + memcpy (dst, ar_ciab, sizeof ar_ciab); + dst += sizeof ar_ciab; + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_action_replay (uae_u8 *src) { - uae_u32 crc32; - TCHAR *s; - - action_replay_unload (1); - restore_u8 (); - armodel = restore_u8 (); - if (!armodel) - return src; - crc32 = restore_u32 (); - s = restore_string (); - _tcsncpy (changed_prefs.cartfile, s, 255); - _tcscpy (currprefs.cartfile, changed_prefs.cartfile); - xfree (s); - action_replay_load (); - if (restore_u32 () != arrom_size) - return src; - if (restore_u32 () != arram_size) + uae_u32 crc32; + TCHAR *s; + + action_replay_unload (1); + restore_u8 (); + armodel = restore_u8 (); + if (!armodel) + return src; + crc32 = restore_u32 (); + s = restore_string (); + _tcsncpy (changed_prefs.cartfile, s, 255); + _tcscpy (currprefs.cartfile, changed_prefs.cartfile); + xfree (s); + action_replay_load (); + if (restore_u32 () != arrom_size) + return src; + if (restore_u32 () != arram_size) + return src; + if (armemory_ram) + memcpy (armemory_ram, src, arram_size); + src += arram_size; + restore_u32 (); + memcpy (ar_custom, src, sizeof ar_custom); + src += sizeof ar_custom; + restore_u32 (); + src += sizeof ar_ciaa; + restore_u32 (); + src += sizeof ar_ciab; + action_replay_flag = ACTION_REPLAY_IDLE; + if (is_ar_pc_in_rom ()) + action_replay_flag = ACTION_REPLAY_ACTIVE; return src; - if (armemory_ram) - memcpy (armemory_ram, src, arram_size); - src += arram_size; - restore_u32 (); - memcpy (ar_custom, src, sizeof ar_custom); - src += sizeof ar_custom; - restore_u32 (); - src += sizeof ar_ciaa; - restore_u32 (); - src += sizeof ar_ciab; - return src; } @@ -2131,40 +2134,40 @@ uae_u8 *restore_action_replay (uae_u8 *src) static uae_u8 bswap (uae_u8 v,int b7,int b6,int b5,int b4,int b3,int b2,int b1,int b0) { - uae_u8 b = 0; + uae_u8 b = 0; - b |= ((v >> b7) & 1) << 7; - b |= ((v >> b6) & 1) << 6; - b |= ((v >> b5) & 1) << 5; - b |= ((v >> b4) & 1) << 4; - b |= ((v >> b3) & 1) << 3; - b |= ((v >> b2) & 1) << 2; - b |= ((v >> b1) & 1) << 1; - b |= ((v >> b0) & 1) << 0; - return b; + b |= ((v >> b7) & 1) << 7; + b |= ((v >> b6) & 1) << 6; + b |= ((v >> b5) & 1) << 5; + b |= ((v >> b4) & 1) << 4; + b |= ((v >> b3) & 1) << 3; + b |= ((v >> b2) & 1) << 2; + b |= ((v >> b1) & 1) << 1; + b |= ((v >> b0) & 1) << 0; + return b; } static uae_u16 wswap (uae_u16 v,int b15,int b14,int b13,int b12, int b11, int b10, int b9, int b8, int b7,int b6,int b5,int b4,int b3,int b2,int b1,int b0) { - uae_u16 b = 0; - - b |= ((v >> b15) & 1) << 15; - b |= ((v >> b14) & 1) << 14; - b |= ((v >> b13) & 1) << 13; - b |= ((v >> b12) & 1) << 12; - b |= ((v >> b11) & 1) << 11; - b |= ((v >> b10) & 1) << 10; - b |= ((v >> b9) & 1) << 9; - b |= ((v >> b8) & 1) << 8; - b |= ((v >> b7) & 1) << 7; - b |= ((v >> b6) & 1) << 6; - b |= ((v >> b5) & 1) << 5; - b |= ((v >> b4) & 1) << 4; - b |= ((v >> b3) & 1) << 3; - b |= ((v >> b2) & 1) << 2; - b |= ((v >> b1) & 1) << 1; - b |= ((v >> b0) & 1) << 0; - return b; + uae_u16 b = 0; + + b |= ((v >> b15) & 1) << 15; + b |= ((v >> b14) & 1) << 14; + b |= ((v >> b13) & 1) << 13; + b |= ((v >> b12) & 1) << 12; + b |= ((v >> b11) & 1) << 11; + b |= ((v >> b10) & 1) << 10; + b |= ((v >> b9) & 1) << 9; + b |= ((v >> b8) & 1) << 8; + b |= ((v >> b7) & 1) << 7; + b |= ((v >> b6) & 1) << 6; + b |= ((v >> b5) & 1) << 5; + b |= ((v >> b4) & 1) << 4; + b |= ((v >> b3) & 1) << 3; + b |= ((v >> b2) & 1) << 2; + b |= ((v >> b1) & 1) << 1; + b |= ((v >> b0) & 1) << 0; + return b; } #define AXOR 0x817f @@ -2172,48 +2175,48 @@ static uae_u16 wswap (uae_u16 v,int b15,int b14,int b13,int b12, int b11, int b1 // middle (even) static void descramble1 (uae_u8 *buf, int size) { - int i; + int i; - for (i = 0; i < size; i++) - buf[i] = bswap (buf[i], 4, 1, 5, 3, 0, 7, 6, 2); + for (i = 0; i < size; i++) + buf[i] = bswap (buf[i], 4, 1, 5, 3, 0, 7, 6, 2); } static void descramble1a (uae_u8 *buf, int size) { - int i; - uae_u8 tbuf[NPSIZE]; + int i; + uae_u8 tbuf[NPSIZE]; - memcpy (tbuf, buf, size); - for (i = 0; i < size; i++) { - int a = (i ^ AXOR) & (size - 1); - buf[i] = tbuf[wswap (a, 15, 9, 10, 4, 6, 5, 3, 8, 14, 13, 0, 12, 11, 2, 1, 7)]; - } + memcpy (tbuf, buf, size); + for (i = 0; i < size; i++) { + int a = (i ^ AXOR) & (size - 1); + buf[i] = tbuf[wswap (a, 15, 9, 10, 4, 6, 5, 3, 8, 14, 13, 0, 12, 11, 2, 1, 7)]; + } } // corner (odd) static void descramble2 (uae_u8 *buf, int size) { - int i; + int i; - for (i = 0; i < size; i++) - buf[i] = bswap (buf[i], 5, 4, 3, 2, 1, 0, 7, 6); + for (i = 0; i < size; i++) + buf[i] = bswap (buf[i], 5, 4, 3, 2, 1, 0, 7, 6); } static void descramble2a (uae_u8 *buf, int size) { - int i; - uae_u8 tbuf[NPSIZE]; + int i; + uae_u8 tbuf[NPSIZE]; - memcpy (tbuf, buf, size); - for (i = 0; i < size; i++) { - int a = (i ^ AXOR) & (size - 1); - buf[i] = tbuf[wswap (a, 15, 2, 4, 0, 1, 10, 11, 8, 13, 14, 12, 9, 7, 5, 6, 3)]; - } + memcpy (tbuf, buf, size); + for (i = 0; i < size; i++) { + int a = (i ^ AXOR) & (size - 1); + buf[i] = tbuf[wswap (a, 15, 2, 4, 0, 1, 10, 11, 8, 13, 14, 12, 9, 7, 5, 6, 3)]; + } } void descramble_nordicpro (uae_u8 *buf, int size, int odd) { - if (odd) { - descramble2 (buf, size); - descramble2a (buf, size); - } else { - descramble1 (buf, size); - descramble1a (buf, size); - } + if (odd) { + descramble2 (buf, size); + descramble2a (buf, size); + } else { + descramble1 (buf, size); + descramble1a (buf, size); + } } diff --git a/arcadia.c b/arcadia.c index 801427e9..f0abcbb1 100644 --- a/arcadia.c +++ b/arcadia.c @@ -1,12 +1,12 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Arcadia emulation - * - * Copyright 2005-2007 Toni Wilen - * - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Arcadia emulation +* +* Copyright 2005-2007 Toni Wilen +* +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -21,21 +21,21 @@ #include "zfile.h" /* supported roms (mame 0.90) - * - * - ar_airh - * - ar_bowl - * - ar_fast - * - ar_ldrb - * - ar_ldrba - * - ar_ninj - * - ar_rdwr - * - ar_socc (99u8) - * - ar_sdwr - * - ar_spot - * - ar_sprg - * - ar_xeon - * - */ +* +* - ar_airh +* - ar_bowl +* - ar_fast +* - ar_ldrb +* - ar_ldrba +* - ar_ninj +* - ar_rdwr +* - ar_socc (99u8) +* - ar_sdwr +* - ar_spot +* - ar_sprg +* - ar_xeon +* +*/ static void multigame(int); @@ -47,25 +47,25 @@ struct arcadiarom *arcadia_bios, *arcadia_game; static struct arcadiarom roms[] = { - { 49, L"ar_bios.zip", L"scpa21", ARCADIA_BIOS, 0, 6, 1, 0, 2, 3, 4, 5, 7 }, - { 50, L"ar_bios.zip", L"gcp-", ARCADIA_BIOS, 3, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 51, L"ar_bios.zip", L"scpav3_0.", ARCADIA_BIOS, 0, 6, 1, 0, 2, 3, 4, 5, 7 }, - - { 33, L"ar_airh.zip", L"airh_", ARCADIA_GAME, 1, 5, 0, 2, 4, 7, 6, 1, 3 }, - { 34, L"ar_bowl.zip", L"bowl_", ARCADIA_GAME, 1, 7, 6, 0, 1, 2, 3, 4, 5 }, - { 35, L"ar_dart.zip", L"dart_", ARCADIA_GAME, 1, 4, 0, 7, 6, 3, 1, 2, 5 }, - { 36, L"ar_fast.zip", L"fastv28.", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 37, L"ar_ldrb.zip", L"lbg240", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 38, L"ar_ldrba.zip",L"ldrb_", ARCADIA_GAME, 1, 2, 3, 4, 1, 0, 7, 5, 6 }, - { 39, L"ar_ninj.zip", L"ninj_", ARCADIA_GAME, 1, 1, 6, 5, 7, 4, 2, 0, 3 }, - { 40, L"ar_rdwr.zip", L"rdwr_", ARCADIA_GAME, 1, 3, 1, 6, 4, 0, 5, 2, 7 }, - { 41, L"ar_sdwr.zip", L"sdwr_", ARCADIA_GAME, 1, 6, 3, 4, 5, 2, 1, 0, 7 }, - { 42, L"ar_spot.zip", L"spotv2.", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 43, L"ar_sprg.zip", L"sprg_", ARCADIA_GAME, 1, 4, 7, 3, 0, 6, 5, 2, 1 }, - { 44, L"ar_xeon.zip", L"xeon_", ARCADIA_GAME, 1, 3, 1, 2, 4, 0, 5, 6, 7 }, - { 45, L"ar_socc.zip", L"socc30.", ARCADIA_GAME, 2, 0, 7, 1, 6, 5, 4, 3, 2 }, - - { -1 } + { 49, L"ar_bios.zip", L"scpa21", ARCADIA_BIOS, 0, 6, 1, 0, 2, 3, 4, 5, 7 }, + { 50, L"ar_bios.zip", L"gcp-", ARCADIA_BIOS, 3, 7, 6, 5, 4, 3, 2, 1, 0 }, + { 51, L"ar_bios.zip", L"scpav3_0.", ARCADIA_BIOS, 0, 6, 1, 0, 2, 3, 4, 5, 7 }, + + { 33, L"ar_airh.zip", L"airh_", ARCADIA_GAME, 1, 5, 0, 2, 4, 7, 6, 1, 3 }, + { 34, L"ar_bowl.zip", L"bowl_", ARCADIA_GAME, 1, 7, 6, 0, 1, 2, 3, 4, 5 }, + { 35, L"ar_dart.zip", L"dart_", ARCADIA_GAME, 1, 4, 0, 7, 6, 3, 1, 2, 5 }, + { 36, L"ar_fast.zip", L"fastv28.", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, + { 37, L"ar_ldrb.zip", L"lbg240", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, + { 38, L"ar_ldrba.zip",L"ldrb_", ARCADIA_GAME, 1, 2, 3, 4, 1, 0, 7, 5, 6 }, + { 39, L"ar_ninj.zip", L"ninj_", ARCADIA_GAME, 1, 1, 6, 5, 7, 4, 2, 0, 3 }, + { 40, L"ar_rdwr.zip", L"rdwr_", ARCADIA_GAME, 1, 3, 1, 6, 4, 0, 5, 2, 7 }, + { 41, L"ar_sdwr.zip", L"sdwr_", ARCADIA_GAME, 1, 6, 3, 4, 5, 2, 1, 0, 7 }, + { 42, L"ar_spot.zip", L"spotv2.", ARCADIA_GAME, 0, 7, 6, 5, 4, 3, 2, 1, 0 }, + { 43, L"ar_sprg.zip", L"sprg_", ARCADIA_GAME, 1, 4, 7, 3, 0, 6, 5, 2, 1 }, + { 44, L"ar_xeon.zip", L"xeon_", ARCADIA_GAME, 1, 3, 1, 2, 4, 0, 5, 6, 7 }, + { 45, L"ar_socc.zip", L"socc30.", ARCADIA_GAME, 2, 0, 7, 1, 6, 5, 4, 3, 2 }, + + { -1 } }; static uae_u8 *arbmemory, *arbbmemory; @@ -87,165 +87,165 @@ static int nvwrite; static int load_rom8 (TCHAR *xpath, uae_u8 *mem, int extra) { - struct zfile *zf; - TCHAR path[MAX_DPATH]; - int i; - uae_u8 *tmp = xmalloc (131072); - TCHAR *bin = extra == 1 ? L".bin" : L""; - - memset (tmp, 0, 131072); - _stprintf (path, L"%s%s%s", xpath, extra == 3 ? L"-hi" : (extra == 2 ? L"hi" : L"h"), bin); - zf = zfile_fopen (path, L"rb", ZFD_NORMAL); - if (!zf) - goto end; - if (zfile_fread (tmp, 65536, 1, zf) == 0) - goto end; - zfile_fclose (zf); - _stprintf (path, L"%s%s%s", xpath, extra == 3 ? L"-lo" : (extra == 2 ? L"lo" : L"l"), bin); - zf = zfile_fopen (path, L"rb", ZFD_NORMAL); - if (!zf) - goto end; - if (zfile_fread (tmp + 65536, 65536, 1, zf) == 0) - goto end; - zfile_fclose (zf); - for (i = 0; i < 65536; i++) { - mem[i * 2 + 0] = tmp[i]; - mem[i * 2 + 1] = tmp[i + 65536]; - } - xfree (tmp); - return 1; - end: - xfree (tmp); - return 0; + struct zfile *zf; + TCHAR path[MAX_DPATH]; + int i; + uae_u8 *tmp = xmalloc (131072); + TCHAR *bin = extra == 1 ? L".bin" : L""; + + memset (tmp, 0, 131072); + _stprintf (path, L"%s%s%s", xpath, extra == 3 ? L"-hi" : (extra == 2 ? L"hi" : L"h"), bin); + zf = zfile_fopen (path, L"rb", ZFD_NORMAL); + if (!zf) + goto end; + if (zfile_fread (tmp, 65536, 1, zf) == 0) + goto end; + zfile_fclose (zf); + _stprintf (path, L"%s%s%s", xpath, extra == 3 ? L"-lo" : (extra == 2 ? L"lo" : L"l"), bin); + zf = zfile_fopen (path, L"rb", ZFD_NORMAL); + if (!zf) + goto end; + if (zfile_fread (tmp + 65536, 65536, 1, zf) == 0) + goto end; + zfile_fclose (zf); + for (i = 0; i < 65536; i++) { + mem[i * 2 + 0] = tmp[i]; + mem[i * 2 + 1] = tmp[i + 65536]; + } + xfree (tmp); + return 1; +end: + xfree (tmp); + return 0; } static struct arcadiarom *is_arcadia (const TCHAR *xpath, int cnt) { - TCHAR path[MAX_DPATH], *p; - struct arcadiarom *rom = NULL; - int i; - - _tcscpy (path, xpath); - p = path; - for (i = _tcslen (xpath) - 1; i > 0; i--) { - if (path[i] == '\\' || path[i] == '/') { - path[i++] = 0; - p = path + i; - break; + TCHAR path[MAX_DPATH], *p; + struct arcadiarom *rom = NULL; + int i; + + _tcscpy (path, xpath); + p = path; + for (i = _tcslen (xpath) - 1; i > 0; i--) { + if (path[i] == '\\' || path[i] == '/') { + path[i++] = 0; + p = path + i; + break; + } } - } - for (i = 0; roms[i].romid > 0; i++) { - if (!_tcsicmp (p, roms[i].name) || !_tcsicmp (p, roms[i].rom)) { - if (cnt > 0) { - cnt--; - continue; - } - rom = &roms[i]; - break; + for (i = 0; roms[i].romid > 0; i++) { + if (!_tcsicmp (p, roms[i].name) || !_tcsicmp (p, roms[i].rom)) { + if (cnt > 0) { + cnt--; + continue; + } + rom = &roms[i]; + break; + } } - } - if (!rom) - return 0; - return rom; + if (!rom) + return 0; + return rom; } static int load_roms (struct arcadiarom *rom) { - TCHAR path[MAX_DPATH], path2[MAX_DPATH], path3[MAX_DPATH], *p; - int i, offset; - TCHAR *xpath; - - if (rom->type == ARCADIA_BIOS) - xpath = currprefs.romextfile; - else - xpath = currprefs.cartfile; - - _tcscpy (path3, xpath); - p = path3 + _tcslen (path3) - 1; - while (p > path3) { - if (p[0] == '\\' || p[0] == '/') { - *p = 0; - break; + TCHAR path[MAX_DPATH], path2[MAX_DPATH], path3[MAX_DPATH], *p; + int i, offset; + TCHAR *xpath; + + if (rom->type == ARCADIA_BIOS) + xpath = currprefs.romextfile; + else + xpath = currprefs.cartfile; + + _tcscpy (path3, xpath); + p = path3 + _tcslen (path3) - 1; + while (p > path3) { + if (p[0] == '\\' || p[0] == '/') { + *p = 0; + break; + } + p--; } - p--; - } - if (p == path3) - *p = 0; - _tcscpy (path2, xpath); - - offset = 0; - if (rom->type == ARCADIA_BIOS) - offset = bios_offset; - i = 0; - for (;;) { - _stprintf (path, L"%s%d", xpath, i + 1); - if (!load_rom8 (path, arbmemory + 2 * 65536 * i + offset, rom->extra)) { - if (i == 0) - write_log (L"Arcadia: %s rom load failed ('%s')\n", rom->type == ARCADIA_BIOS ? "bios" : "game", path); - break; + if (p == path3) + *p = 0; + _tcscpy (path2, xpath); + + offset = 0; + if (rom->type == ARCADIA_BIOS) + offset = bios_offset; + i = 0; + for (;;) { + _stprintf (path, L"%s%d", xpath, i + 1); + if (!load_rom8 (path, arbmemory + 2 * 65536 * i + offset, rom->extra)) { + if (i == 0) + write_log (L"Arcadia: %s rom load failed ('%s')\n", rom->type == ARCADIA_BIOS ? "bios" : "game", path); + break; + } + i++; } - i++; - } - if (i == 0) - return 0; - write_log (L"Arcadia: %s rom %s loaded\n", rom->type == ARCADIA_BIOS ? "bios" : "game", xpath); - return 1; + if (i == 0) + return 0; + write_log (L"Arcadia: %s rom %s loaded\n", rom->type == ARCADIA_BIOS ? "bios" : "game", xpath); + return 1; } static uae_u8 bswap (uae_u8 v,int b7,int b6,int b5,int b4,int b3,int b2,int b1,int b0) { - uae_u8 b = 0; - - b |= ((v >> b7) & 1) << 7; - b |= ((v >> b6) & 1) << 6; - b |= ((v >> b5) & 1) << 5; - b |= ((v >> b4) & 1) << 4; - b |= ((v >> b3) & 1) << 3; - b |= ((v >> b2) & 1) << 2; - b |= ((v >> b1) & 1) << 1; - b |= ((v >> b0) & 1) << 0; - return b; + uae_u8 b = 0; + + b |= ((v >> b7) & 1) << 7; + b |= ((v >> b6) & 1) << 6; + b |= ((v >> b5) & 1) << 5; + b |= ((v >> b4) & 1) << 4; + b |= ((v >> b3) & 1) << 3; + b |= ((v >> b2) & 1) << 2; + b |= ((v >> b1) & 1) << 1; + b |= ((v >> b0) & 1) << 0; + return b; } static void decrypt_roms (struct arcadiarom *rom) { - int i, start = 1, end = 0x20000; - - if (rom->type == ARCADIA_BIOS) { - start += bios_offset; - end += bios_offset; - } - for (i = start; i < end; i += 2) { - arbmemory[i] = bswap (arbmemory[i], - rom->b7,rom->b6,rom->b5,rom->b4,rom->b3,rom->b2,rom->b1,rom->b0); - if (rom->extra == 2) - arbmemory[i - 1] = bswap (arbmemory[i - 1],7,6,5,4,3,2,1,0); - } + int i, start = 1, end = 0x20000; + + if (rom->type == ARCADIA_BIOS) { + start += bios_offset; + end += bios_offset; + } + for (i = start; i < end; i += 2) { + arbmemory[i] = bswap (arbmemory[i], + rom->b7,rom->b6,rom->b5,rom->b4,rom->b3,rom->b2,rom->b1,rom->b0); + if (rom->extra == 2) + arbmemory[i - 1] = bswap (arbmemory[i - 1],7,6,5,4,3,2,1,0); + } } static uae_u32 REGPARAM2 arbb_lget (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; - addr -= arbb_start & arbb_mask; - addr &= arbb_mask; - m = (uae_u32 *)(arbbmemory + addr); - return do_get_mem_long (m); + addr -= arbb_start & arbb_mask; + addr &= arbb_mask; + m = (uae_u32 *)(arbbmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 arbb_wget (uaecptr addr) { - uae_u16 *m; + uae_u16 *m; - addr -= arbb_start & arbb_mask; - addr &= arbb_mask; - m = (uae_u16 *)(arbbmemory + addr); - return do_get_mem_word (m); + addr -= arbb_start & arbb_mask; + addr &= arbb_mask; + m = (uae_u16 *)(arbbmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 arbb_bget (uaecptr addr) { - addr -= arbb_start & arbb_mask; - addr &= arbb_mask; - return arbbmemory[addr]; + addr -= arbb_start & arbb_mask; + addr &= arbb_mask; + return arbbmemory[addr]; } static void REGPARAM2 arbb_lput (uaecptr addr, uae_u32 l) @@ -261,212 +261,212 @@ static void REGPARAM2 arbb_bput (uaecptr addr, uae_u32 b) } static addrbank arcadia_boot_bank = { - arbb_lget, arbb_wget, arbb_bget, - arbb_lput, arbb_wput, arbb_bput, - default_xlate, default_check, NULL, L"Arcadia BIOS", - arbb_lget, arbb_wget, ABFLAG_ROM + arbb_lget, arbb_wget, arbb_bget, + arbb_lput, arbb_wput, arbb_bput, + default_xlate, default_check, NULL, L"Arcadia BIOS", + arbb_lget, arbb_wget, ABFLAG_ROM }; static uae_u32 REGPARAM2 arb_lget (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; - addr -= arb_start & arb_mask; - addr &= arb_mask; - m = (uae_u32 *)(arbmemory + addr); - return do_get_mem_long (m); + addr -= arb_start & arb_mask; + addr &= arb_mask; + m = (uae_u32 *)(arbmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 arb_wget (uaecptr addr) { - uae_u16 *m; + uae_u16 *m; - addr -= arb_start & arb_mask; - addr &= arb_mask; - m = (uae_u16 *)(arbmemory + addr); - return do_get_mem_word (m); + addr -= arb_start & arb_mask; + addr &= arb_mask; + m = (uae_u16 *)(arbmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 arb_bget (uaecptr addr) { - addr -= arb_start & arb_mask; - addr &= arb_mask; - return arbmemory[addr]; + addr -= arb_start & arb_mask; + addr &= arb_mask; + return arbmemory[addr]; } static void REGPARAM2 arb_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - - addr -= arb_start & arb_mask; - addr &= arb_mask; - if (addr >= nvram_offset) { - m = (uae_u32 *)(arbmemory + addr); - do_put_mem_long (m, l); - nvwrite++; - } + uae_u32 *m; + + addr -= arb_start & arb_mask; + addr &= arb_mask; + if (addr >= nvram_offset) { + m = (uae_u32 *)(arbmemory + addr); + do_put_mem_long (m, l); + nvwrite++; + } } static void REGPARAM2 arb_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - - addr -= arb_start & arb_mask; - addr &= arb_mask; - if (addr >= nvram_offset) { - m = (uae_u16 *)(arbmemory + addr); - do_put_mem_word (m, w); - nvwrite++; - if (addr == 0x1ffffe) - multigame(w); - } + uae_u16 *m; + + addr -= arb_start & arb_mask; + addr &= arb_mask; + if (addr >= nvram_offset) { + m = (uae_u16 *)(arbmemory + addr); + do_put_mem_word (m, w); + nvwrite++; + if (addr == 0x1ffffe) + multigame(w); + } } static void REGPARAM2 arb_bput (uaecptr addr, uae_u32 b) { - addr -= arb_start & arb_mask; - addr &= arb_mask; - if (addr >= nvram_offset) { - arbmemory[addr] = b; - nvwrite++; - } + addr -= arb_start & arb_mask; + addr &= arb_mask; + if (addr >= nvram_offset) { + arbmemory[addr] = b; + nvwrite++; + } } static addrbank arcadia_rom_bank = { - arb_lget, arb_wget, arb_bget, - arb_lput, arb_wput, arb_bput, - default_xlate, default_check, NULL, L"Arcadia Game ROM", - arb_lget, arb_wget, ABFLAG_ROM + arb_lget, arb_wget, arb_bget, + arb_lput, arb_wput, arb_bput, + default_xlate, default_check, NULL, L"Arcadia Game ROM", + arb_lget, arb_wget, ABFLAG_ROM }; static void multigame(int v) { - if (v != 0) - map_banks (&kickmem_bank, arb_start >> 16, - 8, 0); - else - map_banks (&arcadia_rom_bank, arb_start >> 16, - allocated_arbmemory >> 16, 0); + if (v != 0) + map_banks (&kickmem_bank, arb_start >> 16, + 8, 0); + else + map_banks (&arcadia_rom_bank, arb_start >> 16, + allocated_arbmemory >> 16, 0); } int is_arcadia_rom (const TCHAR *path) { - struct arcadiarom *rom; - - rom = is_arcadia (path, 0); - if (!rom || rom->type == NO_ARCADIA_ROM) - return NO_ARCADIA_ROM; - if (rom->type == ARCADIA_BIOS) { - arcadia_bios = rom; - return ARCADIA_BIOS; - } - arcadia_game = rom; - return ARCADIA_GAME; + struct arcadiarom *rom; + + rom = is_arcadia (path, 0); + if (!rom || rom->type == NO_ARCADIA_ROM) + return NO_ARCADIA_ROM; + if (rom->type == ARCADIA_BIOS) { + arcadia_bios = rom; + return ARCADIA_BIOS; + } + arcadia_game = rom; + return ARCADIA_GAME; } static void nvram_write (void) { - struct zfile *f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) { - f = zfile_fopen (currprefs.flashfile, L"wb", 0); - if (!f) - return; - } - zfile_fwrite (arbmemory + nvram_offset, NVRAM_SIZE, 1, f); - zfile_fclose (f); + struct zfile *f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) { + f = zfile_fopen (currprefs.flashfile, L"wb", 0); + if (!f) + return; + } + zfile_fwrite (arbmemory + nvram_offset, NVRAM_SIZE, 1, f); + zfile_fclose (f); } static void nvram_read (void) { - struct zfile *f; - - f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); - memset (arbmemory + nvram_offset, 0, NVRAM_SIZE); - if (!f) - return; - zfile_fread (arbmemory + nvram_offset, NVRAM_SIZE, 1, f); - zfile_fclose (f); + struct zfile *f; + + f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); + memset (arbmemory + nvram_offset, 0, NVRAM_SIZE); + if (!f) + return; + zfile_fread (arbmemory + nvram_offset, NVRAM_SIZE, 1, f); + zfile_fclose (f); } void arcadia_unmap (void) { - xfree (arbmemory); - arbmemory = NULL; - arcadia_bios = NULL; - arcadia_game = NULL; + xfree (arbmemory); + arbmemory = NULL; + arcadia_bios = NULL; + arcadia_game = NULL; } int arcadia_map_banks (void) { - if (!arcadia_bios) - return 0; - arbmemory = (uae_u8*)xmalloc (allocated_arbmemory); - arbbmemory = arbmemory + bios_offset; - memset (arbmemory, 0, allocated_arbmemory); - if (!load_roms (arcadia_bios)) { - arcadia_unmap (); - return 0; - } - if (arcadia_game) - load_roms (arcadia_game); - decrypt_roms (arcadia_bios); - if (arcadia_game) - decrypt_roms (arcadia_game); - nvram_read (); - multigame(0); - map_banks (&arcadia_boot_bank, 0xf0, - 8, 0); - return 1; + if (!arcadia_bios) + return 0; + arbmemory = (uae_u8*)xmalloc (allocated_arbmemory); + arbbmemory = arbmemory + bios_offset; + memset (arbmemory, 0, allocated_arbmemory); + if (!load_roms (arcadia_bios)) { + arcadia_unmap (); + return 0; + } + if (arcadia_game) + load_roms (arcadia_game); + decrypt_roms (arcadia_bios); + if (arcadia_game) + decrypt_roms (arcadia_game); + nvram_read (); + multigame(0); + map_banks (&arcadia_boot_bank, 0xf0, + 8, 0); + return 1; } void arcadia_vsync (void) { - static int cnt; - - cnt--; - if (cnt > 0) - return; - cnt = 50; - if (!nvwrite) - return; - nvram_write (); - nvwrite = 0; + static int cnt; + + cnt--; + if (cnt > 0) + return; + cnt = 50; + if (!nvwrite) + return; + nvram_write (); + nvwrite = 0; } uae_u8 arcadia_parport (int port, uae_u8 pra, uae_u8 dra) { - uae_u8 v; + uae_u8 v; - v = (pra & dra) | (dra ^ 0xff); - if (port) { - if (dra & 1) - arcadia_coin[0] = arcadia_coin[1] = 0; - return 0; - } - v = 0; - v |= (arcadia_flag & 1) ? 0 : 2; - v |= (arcadia_flag & 2) ? 0 : 4; - v |= (arcadia_flag & 4) ? 0 : 8; - v |= (arcadia_coin[0] & 3) << 4; - v |= (arcadia_coin[1] & 3) << 6; - return v; + v = (pra & dra) | (dra ^ 0xff); + if (port) { + if (dra & 1) + arcadia_coin[0] = arcadia_coin[1] = 0; + return 0; + } + v = 0; + v |= (arcadia_flag & 1) ? 0 : 2; + v |= (arcadia_flag & 2) ? 0 : 4; + v |= (arcadia_flag & 4) ? 0 : 8; + v |= (arcadia_coin[0] & 3) << 4; + v |= (arcadia_coin[1] & 3) << 6; + return v; } struct romdata *scan_arcadia_rom (TCHAR *path, int cnt) { - struct romdata *rd = 0; - struct romlist **arc_rl; - struct arcadiarom *arcadia_rom; - int i; - - arcadia_rom = is_arcadia (path, cnt); - if (arcadia_rom) { - arc_rl = getarcadiaroms(); - for (i = 0; arc_rl[i]; i++) { - if (arc_rl[i]->rd->id == arcadia_rom->romid) { - rd = arc_rl[i]->rd; - _tcscat (path, L"/"); - _tcscat (path, arcadia_rom->rom); - break; - } + struct romdata *rd = 0; + struct romlist **arc_rl; + struct arcadiarom *arcadia_rom; + int i; + + arcadia_rom = is_arcadia (path, cnt); + if (arcadia_rom) { + arc_rl = getarcadiaroms(); + for (i = 0; arc_rl[i]; i++) { + if (arc_rl[i]->rd->id == arcadia_rom->romid) { + rd = arc_rl[i]->rd; + _tcscat (path, L"/"); + _tcscat (path, arcadia_rom->rom); + break; + } + } + xfree (arc_rl); } - xfree (arc_rl); - } - return rd; + return rd; } diff --git a/audio.c b/audio.c index 91832481..589685ea 100644 --- a/audio.c +++ b/audio.c @@ -1,16 +1,16 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Paula audio emulation - * - * Copyright 1995, 1996, 1997 Bernd Schmidt - * Copyright 1996 Marcus Sundberg - * Copyright 1996 Manfred Thole - * Copyright 2006 Toni Wilen - * - * new filter algorithm and anti&sinc interpolators by Antti S. Lankila - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Paula audio emulation +* +* Copyright 1995, 1996, 1997 Bernd Schmidt +* Copyright 1996 Marcus Sundberg +* Copyright 1996 Manfred Thole +* Copyright 2006 Toni Wilen +* +* new filter algorithm and anti&sinc interpolators by Antti S. Lankila +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -51,46 +51,46 @@ int audio_channel_mask = 15; STATIC_INLINE int isaudio(void) { - if (!currprefs.produce_sound) - return 0; - return 1; + if (!currprefs.produce_sound) + return 0; + return 1; } static int debugchannel (int ch) { - if ((1 << ch) & DEBUG_CHANNEL_MASK) - return 1; - return 0; + if ((1 << ch) & DEBUG_CHANNEL_MASK) + return 1; + return 0; } #define SINC_QUEUE_MAX_AGE 2048 /* Queue length 128 implies minimum emulated period of 16. I add a few extra - * entries so that CPU updates during minimum period can be played back. */ +* entries so that CPU updates during minimum period can be played back. */ #define SINC_QUEUE_LENGTH (SINC_QUEUE_MAX_AGE / 16 + 2) #include "sinctable.c" typedef struct { - int age, output; + int age, output; } sinc_queue_t; struct audio_channel_data { - unsigned long adk_mask; - unsigned long evtime; - uae_u8 dmaen, intreq2; - uaecptr lc, pt; - int current_sample, last_sample; - int state; - int per; - int vol; - int len, wlen; - uae_u16 dat, dat2; - int request_word, request_word_skip; - int vpos; - int sample_accum, sample_accum_time; - int sinc_output_state; - sinc_queue_t sinc_queue[SINC_QUEUE_LENGTH]; - int sinc_queue_length; + unsigned long adk_mask; + unsigned long evtime; + uae_u8 dmaen, intreq2; + uaecptr lc, pt; + int current_sample, last_sample; + int state; + int per; + int vol; + int len, wlen; + uae_u16 dat, dat2; + int request_word, request_word_skip; + int vpos; + int sample_accum, sample_accum_time; + int sinc_output_state; + sinc_queue_t sinc_queue[SINC_QUEUE_LENGTH]; + int sinc_queue_length; }; static int samplecnt; @@ -101,174 +101,174 @@ static int extrasamples, outputsample, doublesample; int sampleripper_enabled; struct ripped_sample { - struct ripped_sample *next; - uae_u8 *sample; - int len, per, changed; + struct ripped_sample *next; + uae_u8 *sample; + int len, per, changed; }; static struct ripped_sample *ripped_samples; void write_wavheader (struct zfile *wavfile, uae_u32 size, uae_u32 freq) { - uae_u16 tw; - uae_u32 tl; - int bits = 8, channels = 1; - - zfile_fseek (wavfile, 0, SEEK_SET); - zfile_fwrite ("RIFF", 1, 4, wavfile); - tl = 0; - if (size) - tl = size - 8; - zfile_fwrite (&tl, 1, 4, wavfile); - zfile_fwrite ("WAVEfmt ", 1, 8, wavfile); - tl = 16; - zfile_fwrite (&tl, 1, 4, wavfile); - tw = 1; - zfile_fwrite (&tw, 1, 2, wavfile); - tw = channels; - zfile_fwrite (&tw, 1, 2, wavfile); - tl = freq; - zfile_fwrite (&tl, 1, 4, wavfile); - tl = freq * channels * bits / 8; - zfile_fwrite (&tl, 1, 4, wavfile); - tw = channels * bits / 8; - zfile_fwrite (&tw, 1, 2, wavfile); - tw = bits; - zfile_fwrite (&tw, 1, 2, wavfile); - zfile_fwrite ("data", 1, 4, wavfile); - tl = 0; - if (size) - tl = size - 44; - zfile_fwrite (&tl, 1, 4, wavfile); + uae_u16 tw; + uae_u32 tl; + int bits = 8, channels = 1; + + zfile_fseek (wavfile, 0, SEEK_SET); + zfile_fwrite ("RIFF", 1, 4, wavfile); + tl = 0; + if (size) + tl = size - 8; + zfile_fwrite (&tl, 1, 4, wavfile); + zfile_fwrite ("WAVEfmt ", 1, 8, wavfile); + tl = 16; + zfile_fwrite (&tl, 1, 4, wavfile); + tw = 1; + zfile_fwrite (&tw, 1, 2, wavfile); + tw = channels; + zfile_fwrite (&tw, 1, 2, wavfile); + tl = freq; + zfile_fwrite (&tl, 1, 4, wavfile); + tl = freq * channels * bits / 8; + zfile_fwrite (&tl, 1, 4, wavfile); + tw = channels * bits / 8; + zfile_fwrite (&tw, 1, 2, wavfile); + tw = bits; + zfile_fwrite (&tw, 1, 2, wavfile); + zfile_fwrite ("data", 1, 4, wavfile); + tl = 0; + if (size) + tl = size - 44; + zfile_fwrite (&tl, 1, 4, wavfile); } static void convertsample(uae_u8 *sample, int len) { - int i; - for (i = 0; i < len; i++) - sample[i] += 0x80; + int i; + for (i = 0; i < len; i++) + sample[i] += 0x80; } static void namesplit (TCHAR *s) { - int l; + int l; - l = _tcslen (s) - 1; - while (l >= 0) { - if (s[l] == '.') - s[l] = 0; - if (s[l] == '\\' || s[l] == '/' || s[l] == ':' || s[l] == '?') { - l++; - break; + l = _tcslen (s) - 1; + while (l >= 0) { + if (s[l] == '.') + s[l] = 0; + if (s[l] == '\\' || s[l] == '/' || s[l] == ':' || s[l] == '?') { + l++; + break; + } + l--; } - l--; - } - if (l > 0) - memmove (s, s + l, (_tcslen (s + l) + 1) * sizeof (TCHAR)); + if (l > 0) + memmove (s, s + l, (_tcslen (s + l) + 1) * sizeof (TCHAR)); } void audio_sampleripper (int mode) { - struct ripped_sample *rs = ripped_samples; - int cnt = 1; - TCHAR path[MAX_DPATH], name[MAX_DPATH], filename[MAX_DPATH]; - TCHAR underline[] = L"_"; - TCHAR extension[4]; - struct zfile *wavfile; + struct ripped_sample *rs = ripped_samples; + int cnt = 1; + TCHAR path[MAX_DPATH], name[MAX_DPATH], filename[MAX_DPATH]; + TCHAR underline[] = L"_"; + TCHAR extension[4]; + struct zfile *wavfile; + + if (mode < 0) { + while (rs) { + struct ripped_sample *next = rs->next; + xfree(rs); + rs = next; + } + ripped_samples = NULL; + return; + } - if (mode < 0) { while (rs) { - struct ripped_sample *next = rs->next; - xfree(rs); - rs = next; - } - ripped_samples = NULL; - return; - } - - while (rs) { - if (rs->changed) { - rs->changed = 0; - fetch_ripperpath (path, sizeof (path)); - name[0] = 0; - if (currprefs.dfxtype[0] >= 0) - _tcscpy (name, currprefs.df[0]); - if (!name[0]) - underline[0] = 0; - namesplit (name); - _tcscpy (extension, L"wav"); - _stprintf (filename, L"%s%s%s%03.3d.%s", path, name, underline, cnt, extension); - wavfile = zfile_fopen (filename, L"wb", 0); - if (wavfile) { - int freq = rs->per > 0 ? (currprefs.ntscmode ? 3579545 : 3546895 / rs->per) : 8000; - write_wavheader (wavfile, 0, 0); - convertsample (rs->sample, rs->len); - zfile_fwrite (rs->sample, rs->len, 1, wavfile); - convertsample (rs->sample, rs->len); - write_wavheader (wavfile, zfile_ftell(wavfile), freq); - zfile_fclose (wavfile); - write_log (L"SAMPLERIPPER: %d: %dHz %d bytes\n", cnt, freq, rs->len); - } else { - write_log (L"SAMPLERIPPER: failed to open '%s'\n", filename); - } + if (rs->changed) { + rs->changed = 0; + fetch_ripperpath (path, sizeof (path)); + name[0] = 0; + if (currprefs.dfxtype[0] >= 0) + _tcscpy (name, currprefs.df[0]); + if (!name[0]) + underline[0] = 0; + namesplit (name); + _tcscpy (extension, L"wav"); + _stprintf (filename, L"%s%s%s%03.3d.%s", path, name, underline, cnt, extension); + wavfile = zfile_fopen (filename, L"wb", 0); + if (wavfile) { + int freq = rs->per > 0 ? (currprefs.ntscmode ? 3579545 : 3546895 / rs->per) : 8000; + write_wavheader (wavfile, 0, 0); + convertsample (rs->sample, rs->len); + zfile_fwrite (rs->sample, rs->len, 1, wavfile); + convertsample (rs->sample, rs->len); + write_wavheader (wavfile, zfile_ftell(wavfile), freq); + zfile_fclose (wavfile); + write_log (L"SAMPLERIPPER: %d: %dHz %d bytes\n", cnt, freq, rs->len); + } else { + write_log (L"SAMPLERIPPER: failed to open '%s'\n", filename); + } + } + cnt++; + rs = rs->next; } - cnt++; - rs = rs->next; - } } static void do_samplerip (struct audio_channel_data *adp) { - struct ripped_sample *rs = ripped_samples, *prev; - int len = adp->len * 2; - uae_u8 *smp = chipmem_bank.xlateaddr (adp->pt); - int cnt = 0, i; - - if (!smp || !chipmem_bank.check (adp->pt, len)) - return; - for (i = 0; i < len; i++) { - if (smp[i] != 0) - break; - } - if (i == len || len <= 2) - return; - prev = NULL; - while(rs) { - if (rs->sample) { - if (len == rs->len && !memcmp (rs->sample, smp, len)) - break; - /* replace old identical but shorter sample */ - if (len > rs->len && !memcmp (rs->sample, smp, rs->len)) { - xfree (rs->sample); - rs->sample = xmalloc (len); - memcpy (rs->sample, smp, len); - write_log (L"SAMPLERIPPER: replaced sample %d (%d -> %d)\n", cnt, rs->len, len); - rs->len = len; - rs->per = adp->per / CYCLE_UNIT; - rs->changed = 1; - audio_sampleripper (0); + struct ripped_sample *rs = ripped_samples, *prev; + int len = adp->len * 2; + uae_u8 *smp = chipmem_bank.xlateaddr (adp->pt); + int cnt = 0, i; + + if (!smp || !chipmem_bank.check (adp->pt, len)) return; - } + for (i = 0; i < len; i++) { + if (smp[i] != 0) + break; } - prev = rs; - rs = rs->next; - cnt++; - } - if (rs || cnt > 100) - return; - rs = xmalloc (sizeof(struct ripped_sample)); - if (prev) - prev->next = rs; - else - ripped_samples = rs; - rs->len = len; - rs->per = adp->per / CYCLE_UNIT; - rs->sample = xmalloc (len); - memcpy (rs->sample, smp, len); - rs->next = NULL; - rs->changed = 1; - write_log (L"SAMPLERIPPER: sample added (%06X, %d bytes), total %d samples\n", adp->pt, len, ++cnt); - audio_sampleripper (0); + if (i == len || len <= 2) + return; + prev = NULL; + while(rs) { + if (rs->sample) { + if (len == rs->len && !memcmp (rs->sample, smp, len)) + break; + /* replace old identical but shorter sample */ + if (len > rs->len && !memcmp (rs->sample, smp, rs->len)) { + xfree (rs->sample); + rs->sample = xmalloc (len); + memcpy (rs->sample, smp, len); + write_log (L"SAMPLERIPPER: replaced sample %d (%d -> %d)\n", cnt, rs->len, len); + rs->len = len; + rs->per = adp->per / CYCLE_UNIT; + rs->changed = 1; + audio_sampleripper (0); + return; + } + } + prev = rs; + rs = rs->next; + cnt++; + } + if (rs || cnt > 100) + return; + rs = xmalloc (sizeof(struct ripped_sample)); + if (prev) + prev->next = rs; + else + ripped_samples = rs; + rs->len = len; + rs->per = adp->per / CYCLE_UNIT; + rs->sample = xmalloc (len); + memcpy (rs->sample, smp, len); + rs->next = NULL; + rs->changed = 1; + write_log (L"SAMPLERIPPER: sample added (%06X, %d bytes), total %d samples\n", adp->pt, len, ++cnt); + audio_sampleripper (0); } static struct audio_channel_data audio_channel[4]; @@ -287,15 +287,15 @@ typedef uae_s8 sample8_t; STATIC_INLINE int FINISH_DATA (int data, int bits, int logn) { - if (14 - bits + logn > 0) { - data >>= 14 - bits + logn; - } else { - int shift = bits - 14 - logn; - int right = data & ((1 << shift) - 1); - data <<= shift; - data |= right; - } - return data; + if (14 - bits + logn > 0) { + data >>= 14 - bits + logn; + } else { + int shift = bits - 14 - logn; + int right = data & ((1 << shift) - 1); + data <<= shift; + data |= right; + } + return data; } static uae_u32 right_word_saved[SOUND_MAX_DELAY_BUFFER]; @@ -308,12 +308,12 @@ static int mixed_on, mixed_stereo_size, mixed_mul1, mixed_mul2; static int led_filter_forced, sound_use_filter, sound_use_filter_sinc, led_filter_on; /* denormals are very small floating point numbers that force FPUs into slow - mode. All lowpass filters using floats are suspectible to denormals unless - a small offset is added to avoid very small floating point numbers. */ +mode. All lowpass filters using floats are suspectible to denormals unless +a small offset is added to avoid very small floating point numbers. */ #define DENORMAL_OFFSET (1E-10) static struct filter_state { - float rc1, rc2, rc3, rc4, rc5; + float rc1, rc2, rc3, rc4, rc5; } sound_filter_state[4]; static float a500e_filter1_a0; @@ -321,136 +321,136 @@ static float a500e_filter2_a0; static float filter_a0; /* a500 and a1200 use the same */ enum { - FILTER_NONE = 0, - FILTER_MODEL_A500, - FILTER_MODEL_A1200 + FILTER_NONE = 0, + FILTER_MODEL_A500, + FILTER_MODEL_A1200 }; /* Amiga has two separate filtering circuits per channel, a static RC filter - * on A500 and the LED filter. This code emulates both. - * - * The Amiga filtering circuitry depends on Amiga model. Older Amigas seem - * to have a 6 dB/oct RC filter with cutoff frequency such that the -6 dB - * point for filter is reached at 6 kHz, while newer Amigas have no filtering. - * - * The LED filter is complicated, and we are modelling it with a pair of - * RC filters, the other providing a highboost. The LED starts to cut - * into signal somewhere around 5-6 kHz, and there's some kind of highboost - * in effect above 12 kHz. Better measurements are required. - * - * The current filtering should be accurate to 2 dB with the filter on, - * and to 1 dB with the filter off. +* on A500 and the LED filter. This code emulates both. +* +* The Amiga filtering circuitry depends on Amiga model. Older Amigas seem +* to have a 6 dB/oct RC filter with cutoff frequency such that the -6 dB +* point for filter is reached at 6 kHz, while newer Amigas have no filtering. +* +* The LED filter is complicated, and we are modelling it with a pair of +* RC filters, the other providing a highboost. The LED starts to cut +* into signal somewhere around 5-6 kHz, and there's some kind of highboost +* in effect above 12 kHz. Better measurements are required. +* +* The current filtering should be accurate to 2 dB with the filter on, +* and to 1 dB with the filter off. */ static int filter (int input, struct filter_state *fs) { - int o; - float normal_output, led_output; + int o; + float normal_output, led_output; - input = (uae_s16)input; - switch (sound_use_filter) { + input = (uae_s16)input; + switch (sound_use_filter) { - case FILTER_NONE: - return input; - case FILTER_MODEL_A500: - fs->rc1 = a500e_filter1_a0 * input + (1 - a500e_filter1_a0) * fs->rc1 + DENORMAL_OFFSET; - fs->rc2 = a500e_filter2_a0 * fs->rc1 + (1-a500e_filter2_a0) * fs->rc2; - normal_output = fs->rc2; + case FILTER_NONE: + return input; + case FILTER_MODEL_A500: + fs->rc1 = a500e_filter1_a0 * input + (1 - a500e_filter1_a0) * fs->rc1 + DENORMAL_OFFSET; + fs->rc2 = a500e_filter2_a0 * fs->rc1 + (1-a500e_filter2_a0) * fs->rc2; + normal_output = fs->rc2; - fs->rc3 = filter_a0 * normal_output + (1 - filter_a0) * fs->rc3; - fs->rc4 = filter_a0 * fs->rc3 + (1 - filter_a0) * fs->rc4; - fs->rc5 = filter_a0 * fs->rc4 + (1 - filter_a0) * fs->rc5; + fs->rc3 = filter_a0 * normal_output + (1 - filter_a0) * fs->rc3; + fs->rc4 = filter_a0 * fs->rc3 + (1 - filter_a0) * fs->rc4; + fs->rc5 = filter_a0 * fs->rc4 + (1 - filter_a0) * fs->rc5; - led_output = fs->rc5; - break; + led_output = fs->rc5; + break; - case FILTER_MODEL_A1200: - normal_output = input; + case FILTER_MODEL_A1200: + normal_output = input; - fs->rc2 = filter_a0 * normal_output + (1 - filter_a0) * fs->rc2 + DENORMAL_OFFSET; - fs->rc3 = filter_a0 * fs->rc2 + (1 - filter_a0) * fs->rc3; - fs->rc4 = filter_a0 * fs->rc3 + (1 - filter_a0) * fs->rc4; + fs->rc2 = filter_a0 * normal_output + (1 - filter_a0) * fs->rc2 + DENORMAL_OFFSET; + fs->rc3 = filter_a0 * fs->rc2 + (1 - filter_a0) * fs->rc3; + fs->rc4 = filter_a0 * fs->rc3 + (1 - filter_a0) * fs->rc4; - led_output = fs->rc4; - break; + led_output = fs->rc4; + break; - } + } - if (led_filter_on) - o = led_output; - else - o = normal_output; + if (led_filter_on) + o = led_output; + else + o = normal_output; - if (o > 32767) - o = 32767; - else if (o < -32768) - o = -32768; + if (o > 32767) + o = 32767; + else if (o < -32768) + o = -32768; - return o; + return o; } /* Always put the right word before the left word. */ STATIC_INLINE void put_sound_word_right (uae_u32 w) { - if (mixed_on) { - right_word_saved[saved_ptr] = w; - return; - } - PUT_SOUND_WORD_RIGHT (w); + if (mixed_on) { + right_word_saved[saved_ptr] = w; + return; + } + PUT_SOUND_WORD_RIGHT (w); } STATIC_INLINE void put_sound_word_left (uae_u32 w) { - if (mixed_on) { - uae_u32 rold, lold, rnew, lnew, tmp; + if (mixed_on) { + uae_u32 rold, lold, rnew, lnew, tmp; - left_word_saved[saved_ptr] = w; - lnew = w - SOUND16_BASE_VAL; - rnew = right_word_saved[saved_ptr] - SOUND16_BASE_VAL; + left_word_saved[saved_ptr] = w; + lnew = w - SOUND16_BASE_VAL; + rnew = right_word_saved[saved_ptr] - SOUND16_BASE_VAL; - saved_ptr = (saved_ptr + 1) & mixed_stereo_size; + saved_ptr = (saved_ptr + 1) & mixed_stereo_size; - lold = left_word_saved[saved_ptr] - SOUND16_BASE_VAL; - tmp = (rnew * mixed_mul2 + lold * mixed_mul1) / MIXED_STEREO_SCALE; - tmp += SOUND16_BASE_VAL; - PUT_SOUND_WORD_RIGHT (tmp); + lold = left_word_saved[saved_ptr] - SOUND16_BASE_VAL; + tmp = (rnew * mixed_mul2 + lold * mixed_mul1) / MIXED_STEREO_SCALE; + tmp += SOUND16_BASE_VAL; + PUT_SOUND_WORD_RIGHT (tmp); - rold = right_word_saved[saved_ptr] - SOUND16_BASE_VAL; - w = (lnew * mixed_mul2 + rold * mixed_mul1) / MIXED_STEREO_SCALE; - } - PUT_SOUND_WORD_LEFT (w); + rold = right_word_saved[saved_ptr] - SOUND16_BASE_VAL; + w = (lnew * mixed_mul2 + rold * mixed_mul1) / MIXED_STEREO_SCALE; + } + PUT_SOUND_WORD_LEFT (w); } STATIC_INLINE void put_sound_word_right2 (uae_u32 w) { - if (mixed_on) { - right2_word_saved[saved_ptr2] = w; - return; - } - PUT_SOUND_WORD_RIGHT2 (w); + if (mixed_on) { + right2_word_saved[saved_ptr2] = w; + return; + } + PUT_SOUND_WORD_RIGHT2 (w); } STATIC_INLINE void put_sound_word_left2 (uae_u32 w) { - if (mixed_on) { - uae_u32 rold, lold, rnew, lnew, tmp; + if (mixed_on) { + uae_u32 rold, lold, rnew, lnew, tmp; - left2_word_saved[saved_ptr2] = w; - lnew = w - SOUND16_BASE_VAL; - rnew = right2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; + left2_word_saved[saved_ptr2] = w; + lnew = w - SOUND16_BASE_VAL; + rnew = right2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; - saved_ptr2 = (saved_ptr2 + 1) & mixed_stereo_size; + saved_ptr2 = (saved_ptr2 + 1) & mixed_stereo_size; - lold = left2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; - tmp = (rnew * mixed_mul2 + lold * mixed_mul1) / MIXED_STEREO_SCALE; - tmp += SOUND16_BASE_VAL; - PUT_SOUND_WORD_RIGHT2 (tmp); + lold = left2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; + tmp = (rnew * mixed_mul2 + lold * mixed_mul1) / MIXED_STEREO_SCALE; + tmp += SOUND16_BASE_VAL; + PUT_SOUND_WORD_RIGHT2 (tmp); - rold = right2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; - w = (lnew * mixed_mul2 + rold * mixed_mul1) / MIXED_STEREO_SCALE; - } - PUT_SOUND_WORD_LEFT2 (w); + rold = right2_word_saved[saved_ptr2] - SOUND16_BASE_VAL; + w = (lnew * mixed_mul2 + rold * mixed_mul1) / MIXED_STEREO_SCALE; + } + PUT_SOUND_WORD_LEFT2 (w); } @@ -458,555 +458,555 @@ STATIC_INLINE void put_sound_word_left2 (uae_u32 w) static void anti_prehandler (unsigned long best_evtime) { - int i, output; - struct audio_channel_data *acd; + int i, output; + struct audio_channel_data *acd; - /* Handle accumulator antialiasiation */ - for (i = 0; i < 4; i++) { - acd = &audio_channel[i]; - output = (acd->current_sample * acd->vol) & acd->adk_mask; - acd->sample_accum += output * best_evtime; - acd->sample_accum_time += best_evtime; - } + /* Handle accumulator antialiasiation */ + for (i = 0; i < 4; i++) { + acd = &audio_channel[i]; + output = (acd->current_sample * acd->vol) & acd->adk_mask; + acd->sample_accum += output * best_evtime; + acd->sample_accum_time += best_evtime; + } } STATIC_INLINE void samplexx_anti_handler (int *datasp) { - int i; - for (i = 0; i < 4; i++) { - datasp[i] = audio_channel[i].sample_accum_time ? (audio_channel[i].sample_accum / audio_channel[i].sample_accum_time) : 0; - audio_channel[i].sample_accum = 0; - audio_channel[i].sample_accum_time = 0; + int i; + for (i = 0; i < 4; i++) { + datasp[i] = audio_channel[i].sample_accum_time ? (audio_channel[i].sample_accum / audio_channel[i].sample_accum_time) : 0; + audio_channel[i].sample_accum = 0; + audio_channel[i].sample_accum_time = 0; - } + } } static void sinc_prehandler (unsigned long best_evtime) { - int i, j, output; - struct audio_channel_data *acd; + int i, j, output; + struct audio_channel_data *acd; - for (i = 0; i < 4; i++) { - acd = &audio_channel[i]; - output = (acd->current_sample * acd->vol) & acd->adk_mask; - - /* age the sinc queue and truncate it when necessary */ - for (j = 0; j < acd->sinc_queue_length; j += 1) { - acd->sinc_queue[j].age += best_evtime; - if (acd->sinc_queue[j].age >= SINC_QUEUE_MAX_AGE) { - acd->sinc_queue_length = j; - break; - } - } + for (i = 0; i < 4; i++) { + acd = &audio_channel[i]; + output = (acd->current_sample * acd->vol) & acd->adk_mask; + + /* age the sinc queue and truncate it when necessary */ + for (j = 0; j < acd->sinc_queue_length; j += 1) { + acd->sinc_queue[j].age += best_evtime; + if (acd->sinc_queue[j].age >= SINC_QUEUE_MAX_AGE) { + acd->sinc_queue_length = j; + break; + } + } - /* if output state changes, record the state change and also - * write data into sinc queue for mixing in the BLEP */ - if (acd->sinc_output_state != output) { - if (acd->sinc_queue_length > SINC_QUEUE_LENGTH - 1) { - //write_log (L"warning: sinc queue truncated. Last age: %d.\n", acd->sinc_queue[SINC_QUEUE_LENGTH-1].age); - acd->sinc_queue_length = SINC_QUEUE_LENGTH - 1; - } - /* make room for new and add the new value */ - memmove (&acd->sinc_queue[1], &acd->sinc_queue[0], - sizeof (acd->sinc_queue[0]) * acd->sinc_queue_length); - acd->sinc_queue_length += 1; - acd->sinc_queue[0].age = best_evtime; - acd->sinc_queue[0].output = output - acd->sinc_output_state; - acd->sinc_output_state = output; + /* if output state changes, record the state change and also + * write data into sinc queue for mixing in the BLEP */ + if (acd->sinc_output_state != output) { + if (acd->sinc_queue_length > SINC_QUEUE_LENGTH - 1) { + //write_log (L"warning: sinc queue truncated. Last age: %d.\n", acd->sinc_queue[SINC_QUEUE_LENGTH-1].age); + acd->sinc_queue_length = SINC_QUEUE_LENGTH - 1; + } + /* make room for new and add the new value */ + memmove (&acd->sinc_queue[1], &acd->sinc_queue[0], + sizeof (acd->sinc_queue[0]) * acd->sinc_queue_length); + acd->sinc_queue_length += 1; + acd->sinc_queue[0].age = best_evtime; + acd->sinc_queue[0].output = output - acd->sinc_output_state; + acd->sinc_output_state = output; + } } - } } /* this interpolator performs BLEP mixing (bleps are shaped like integrated sinc - * functions) with a type of BLEP that matches the filtering configuration. */ +* functions) with a type of BLEP that matches the filtering configuration. */ STATIC_INLINE void samplexx_sinc_handler (int *datasp) { - int i, n; - int const *winsinc; + int i, n; + int const *winsinc; - if (sound_use_filter_sinc) { - n = (sound_use_filter_sinc == FILTER_MODEL_A500) ? 0 : 2; - if (led_filter_on) - n += 1; - } else { - n = 4; - } - winsinc = winsinc_integral[n]; - - for (i = 0; i < 4; i += 1) { - int j, v; - struct audio_channel_data *acd = &audio_channel[i]; - /* The sum rings with harmonic components up to infinity... */ - int sum = acd->sinc_output_state << 17; - /* ...but we cancel them through mixing in BLEPs instead */ - for (j = 0; j < acd->sinc_queue_length; j += 1) - sum -= winsinc[acd->sinc_queue[j].age] * acd->sinc_queue[j].output; - v = sum >> 17; - if (v > 32767) - v = 32767; - else if (v < -32768) - v = -32768; - datasp[i] = v; - } + if (sound_use_filter_sinc) { + n = (sound_use_filter_sinc == FILTER_MODEL_A500) ? 0 : 2; + if (led_filter_on) + n += 1; + } else { + n = 4; + } + winsinc = winsinc_integral[n]; + + for (i = 0; i < 4; i += 1) { + int j, v; + struct audio_channel_data *acd = &audio_channel[i]; + /* The sum rings with harmonic components up to infinity... */ + int sum = acd->sinc_output_state << 17; + /* ...but we cancel them through mixing in BLEPs instead */ + for (j = 0; j < acd->sinc_queue_length; j += 1) + sum -= winsinc[acd->sinc_queue[j].age] * acd->sinc_queue[j].output; + v = sum >> 17; + if (v > 32767) + v = 32767; + else if (v < -32768) + v = -32768; + datasp[i] = v; + } } static void sample16i_sinc_handler (void) { - int datas[4], data1; + int datas[4], data1; - samplexx_sinc_handler (datas); - data1 = datas[0] + datas[3] + datas[1] + datas[2]; - data1 = FINISH_DATA (data1, 16, 2); - set_sound_buffers (); - PUT_SOUND_WORD_MONO (data1); - check_sound_buffers (); + samplexx_sinc_handler (datas); + data1 = datas[0] + datas[3] + datas[1] + datas[2]; + data1 = FINISH_DATA (data1, 16, 2); + set_sound_buffers (); + PUT_SOUND_WORD_MONO (data1); + check_sound_buffers (); } void sample16_handler (void) { - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - uae_u32 data; - - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - data0 &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - data0 += data1; - data0 += data2; - data0 += data3; - data = SBASEVAL16(2) + data0; - data = FINISH_DATA (data, 16, 2); - set_sound_buffers (); - PUT_SOUND_WORD_MONO (data); - check_sound_buffers (); + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + uae_u32 data; + + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data0 += data1; + data0 += data2; + data0 += data3; + data = SBASEVAL16(2) + data0; + data = FINISH_DATA (data, 16, 2); + set_sound_buffers (); + PUT_SOUND_WORD_MONO (data); + check_sound_buffers (); } /* This interpolator examines sample points when Paula switches the output - * voltage and computes the average of Paula's output */ +* voltage and computes the average of Paula's output */ static void sample16i_anti_handler (void) { - int datas[4], data1; + int datas[4], data1; - samplexx_anti_handler (datas); - data1 = datas[0] + datas[3] + datas[1] + datas[2]; - data1 = FINISH_DATA (data1, 16, 2); - set_sound_buffers (); - PUT_SOUND_WORD_MONO (data1); - check_sound_buffers (); + samplexx_anti_handler (datas); + data1 = datas[0] + datas[3] + datas[1] + datas[2]; + data1 = FINISH_DATA (data1, 16, 2); + set_sound_buffers (); + PUT_SOUND_WORD_MONO (data1); + check_sound_buffers (); } static void sample16i_rh_handler (void) { - unsigned long delta, ratio; - - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - uae_u32 data0p = audio_channel[0].last_sample; - uae_u32 data1p = audio_channel[1].last_sample; - uae_u32 data2p = audio_channel[2].last_sample; - uae_u32 data3p = audio_channel[3].last_sample; - uae_u32 data; - - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - DO_CHANNEL_1 (data0p, 0); - DO_CHANNEL_1 (data1p, 1); - DO_CHANNEL_1 (data2p, 2); - DO_CHANNEL_1 (data3p, 3); - - data0 &= audio_channel[0].adk_mask; - data0p &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data1p &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data2p &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - data3p &= audio_channel[3].adk_mask; - - /* linear interpolation and summing up... */ - delta = audio_channel[0].per; - ratio = ((audio_channel[0].evtime % delta) << 8) / delta; - data0 = (data0 * (256 - ratio) + data0p * ratio) >> 8; - delta = audio_channel[1].per; - ratio = ((audio_channel[1].evtime % delta) << 8) / delta; - data0 += (data1 * (256 - ratio) + data1p * ratio) >> 8; - delta = audio_channel[2].per; - ratio = ((audio_channel[2].evtime % delta) << 8) / delta; - data0 += (data2 * (256 - ratio) + data2p * ratio) >> 8; - delta = audio_channel[3].per; - ratio = ((audio_channel[3].evtime % delta) << 8) / delta; - data0 += (data3 * (256 - ratio) + data3p * ratio) >> 8; - data = SBASEVAL16(2) + data0; - data = FINISH_DATA (data, 16, 2); - set_sound_buffers (); - PUT_SOUND_WORD_MONO (data); - check_sound_buffers (); + unsigned long delta, ratio; + + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + uae_u32 data0p = audio_channel[0].last_sample; + uae_u32 data1p = audio_channel[1].last_sample; + uae_u32 data2p = audio_channel[2].last_sample; + uae_u32 data3p = audio_channel[3].last_sample; + uae_u32 data; + + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + DO_CHANNEL_1 (data0p, 0); + DO_CHANNEL_1 (data1p, 1); + DO_CHANNEL_1 (data2p, 2); + DO_CHANNEL_1 (data3p, 3); + + data0 &= audio_channel[0].adk_mask; + data0p &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data1p &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data2p &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data3p &= audio_channel[3].adk_mask; + + /* linear interpolation and summing up... */ + delta = audio_channel[0].per; + ratio = ((audio_channel[0].evtime % delta) << 8) / delta; + data0 = (data0 * (256 - ratio) + data0p * ratio) >> 8; + delta = audio_channel[1].per; + ratio = ((audio_channel[1].evtime % delta) << 8) / delta; + data0 += (data1 * (256 - ratio) + data1p * ratio) >> 8; + delta = audio_channel[2].per; + ratio = ((audio_channel[2].evtime % delta) << 8) / delta; + data0 += (data2 * (256 - ratio) + data2p * ratio) >> 8; + delta = audio_channel[3].per; + ratio = ((audio_channel[3].evtime % delta) << 8) / delta; + data0 += (data3 * (256 - ratio) + data3p * ratio) >> 8; + data = SBASEVAL16(2) + data0; + data = FINISH_DATA (data, 16, 2); + set_sound_buffers (); + PUT_SOUND_WORD_MONO (data); + check_sound_buffers (); } static void sample16i_crux_handler (void) { - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - uae_u32 data0p = audio_channel[0].last_sample; - uae_u32 data1p = audio_channel[1].last_sample; - uae_u32 data2p = audio_channel[2].last_sample; - uae_u32 data3p = audio_channel[3].last_sample; - uae_u32 data; - - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - DO_CHANNEL_1 (data0p, 0); - DO_CHANNEL_1 (data1p, 1); - DO_CHANNEL_1 (data2p, 2); - DO_CHANNEL_1 (data3p, 3); - - data0 &= audio_channel[0].adk_mask; - data0p &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data1p &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data2p &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - data3p &= audio_channel[3].adk_mask; - - { - struct audio_channel_data *cdp; - unsigned long ratio, ratio1; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + uae_u32 data0p = audio_channel[0].last_sample; + uae_u32 data1p = audio_channel[1].last_sample; + uae_u32 data2p = audio_channel[2].last_sample; + uae_u32 data3p = audio_channel[3].last_sample; + uae_u32 data; + + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + DO_CHANNEL_1 (data0p, 0); + DO_CHANNEL_1 (data1p, 1); + DO_CHANNEL_1 (data2p, 2); + DO_CHANNEL_1 (data3p, 3); + + data0 &= audio_channel[0].adk_mask; + data0p &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data1p &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data2p &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data3p &= audio_channel[3].adk_mask; + + { + struct audio_channel_data *cdp; + unsigned long ratio, ratio1; #define INTERVAL (scaled_sample_evtime * 3) - cdp = audio_channel + 0; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data0 = (data0 * ratio + data0p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 1; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data1 = (data1 * ratio + data1p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 2; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data2 = (data2 * ratio + data2p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 3; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data3 = (data3 * ratio + data3p * (4096 - ratio)) >> 12; - } - data1 += data2; - data0 += data3; - data0 += data1; - data = SBASEVAL16(2) + data0; - data = FINISH_DATA (data, 16, 2); - set_sound_buffers (); - PUT_SOUND_WORD_MONO (data); - check_sound_buffers (); + cdp = audio_channel + 0; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data0 = (data0 * ratio + data0p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 1; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data1 = (data1 * ratio + data1p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 2; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data2 = (data2 * ratio + data2p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 3; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data3 = (data3 * ratio + data3p * (4096 - ratio)) >> 12; + } + data1 += data2; + data0 += data3; + data0 += data1; + data = SBASEVAL16(2) + data0; + data = FINISH_DATA (data, 16, 2); + set_sound_buffers (); + PUT_SOUND_WORD_MONO (data); + check_sound_buffers (); } #ifdef HAVE_STEREO_SUPPORT STATIC_INLINE void make6ch (uae_s32 d0, uae_s32 d1, uae_s32 d2, uae_s32 d3) { - uae_s32 sum = d0 + d1 + d2 + d3; - sum /= 8; - PUT_SOUND_WORD (sum); - PUT_SOUND_WORD (sum); + uae_s32 sum = d0 + d1 + d2 + d3; + sum /= 8; + PUT_SOUND_WORD (sum); + PUT_SOUND_WORD (sum); } void sample16ss_handler (void) { - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - - data0 &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - - data0 = FINISH_DATA (data0, 16, 0); - data1 = FINISH_DATA (data1, 16, 0); - data2 = FINISH_DATA (data2, 16, 0); - data3 = FINISH_DATA (data3, 16, 0); - set_sound_buffers (); - put_sound_word_left (data0); - put_sound_word_right (data1); - if (currprefs.sound_stereo == SND_6CH) - make6ch (data0, data1, data2, data3); - put_sound_word_left2 (data3); - put_sound_word_right2 (data2); - check_sound_buffers (); + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + + data0 = FINISH_DATA (data0, 16, 0); + data1 = FINISH_DATA (data1, 16, 0); + data2 = FINISH_DATA (data2, 16, 0); + data3 = FINISH_DATA (data3, 16, 0); + set_sound_buffers (); + put_sound_word_left (data0); + put_sound_word_right (data1); + if (currprefs.sound_stereo == SND_6CH) + make6ch (data0, data1, data2, data3); + put_sound_word_left2 (data3); + put_sound_word_right2 (data2); + check_sound_buffers (); } /* This interpolator examines sample points when Paula switches the output - * voltage and computes the average of Paula's output */ +* voltage and computes the average of Paula's output */ void sample16ss_anti_handler (void) { - int data0, data1, data2, data3; - int datas[4]; + int data0, data1, data2, data3; + int datas[4]; - samplexx_anti_handler (datas); - data0 = FINISH_DATA (datas[0], 16, 0); - data1 = FINISH_DATA (datas[1], 16, 0); - data2 = FINISH_DATA (datas[2], 16, 0); - data3 = FINISH_DATA (datas[3], 16, 0); - set_sound_buffers (); - put_sound_word_left (data0); - put_sound_word_right (data1); - if (currprefs.sound_stereo == SND_6CH) - make6ch (data0, data1, data2, data3); - put_sound_word_left2 (data3); - put_sound_word_right2 (data2); - check_sound_buffers (); + samplexx_anti_handler (datas); + data0 = FINISH_DATA (datas[0], 16, 0); + data1 = FINISH_DATA (datas[1], 16, 0); + data2 = FINISH_DATA (datas[2], 16, 0); + data3 = FINISH_DATA (datas[3], 16, 0); + set_sound_buffers (); + put_sound_word_left (data0); + put_sound_word_right (data1); + if (currprefs.sound_stereo == SND_6CH) + make6ch (data0, data1, data2, data3); + put_sound_word_left2 (data3); + put_sound_word_right2 (data2); + check_sound_buffers (); } static void sample16si_anti_handler (void) { - int datas[4], data1, data2; + int datas[4], data1, data2; - samplexx_anti_handler (datas); - data1 = datas[0] + datas[3]; - data2 = datas[1] + datas[2]; - data1 = FINISH_DATA (data1, 16, 1); - data2 = FINISH_DATA (data2, 16, 1); - set_sound_buffers (); - put_sound_word_left (data1); - put_sound_word_right (data2); - check_sound_buffers (); + samplexx_anti_handler (datas); + data1 = datas[0] + datas[3]; + data2 = datas[1] + datas[2]; + data1 = FINISH_DATA (data1, 16, 1); + data2 = FINISH_DATA (data2, 16, 1); + set_sound_buffers (); + put_sound_word_left (data1); + put_sound_word_right (data2); + check_sound_buffers (); } void sample16ss_sinc_handler (void) { - int data0, data1, data2, data3; - int datas[4]; + int data0, data1, data2, data3; + int datas[4]; - samplexx_sinc_handler (datas); - data0 = FINISH_DATA (datas[0], 16, 0); - data1 = FINISH_DATA (datas[1], 16, 0); - data2 = FINISH_DATA (datas[2], 16, 0); - data3 = FINISH_DATA (datas[3], 16, 0); - set_sound_buffers (); - put_sound_word_left (data0); - put_sound_word_right (data1); - if (currprefs.sound_stereo == SND_6CH) - make6ch (data0, data1, data2, data3); - put_sound_word_left2 (data3); - put_sound_word_right2 (data2); - check_sound_buffers (); + samplexx_sinc_handler (datas); + data0 = FINISH_DATA (datas[0], 16, 0); + data1 = FINISH_DATA (datas[1], 16, 0); + data2 = FINISH_DATA (datas[2], 16, 0); + data3 = FINISH_DATA (datas[3], 16, 0); + set_sound_buffers (); + put_sound_word_left (data0); + put_sound_word_right (data1); + if (currprefs.sound_stereo == SND_6CH) + make6ch (data0, data1, data2, data3); + put_sound_word_left2 (data3); + put_sound_word_right2 (data2); + check_sound_buffers (); } static void sample16si_sinc_handler (void) { - int datas[4], data1, data2; + int datas[4], data1, data2; - samplexx_sinc_handler (datas); - data1 = datas[0] + datas[3]; - data2 = datas[1] + datas[2]; - data1 = FINISH_DATA (data1, 16, 1); - data2 = FINISH_DATA (data2, 16, 1); - set_sound_buffers (); - put_sound_word_left (data1); - put_sound_word_right (data2); - check_sound_buffers (); + samplexx_sinc_handler (datas); + data1 = datas[0] + datas[3]; + data2 = datas[1] + datas[2]; + data1 = FINISH_DATA (data1, 16, 1); + data2 = FINISH_DATA (data2, 16, 1); + set_sound_buffers (); + put_sound_word_left (data1); + put_sound_word_right (data2); + check_sound_buffers (); } void sample16s_handler (void) { - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - - data0 &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - - data0 += data3; - data1 += data2; - data2 = SBASEVAL16(1) + data0; - data2 = FINISH_DATA (data2, 16, 1); - data3 = SBASEVAL16(1) + data1; - data3 = FINISH_DATA (data3, 16, 1); - set_sound_buffers (); - put_sound_word_left (data2); - put_sound_word_right (data3); - check_sound_buffers (); + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + + data0 += data3; + data1 += data2; + data2 = SBASEVAL16(1) + data0; + data2 = FINISH_DATA (data2, 16, 1); + data3 = SBASEVAL16(1) + data1; + data3 = FINISH_DATA (data3, 16, 1); + set_sound_buffers (); + put_sound_word_left (data2); + put_sound_word_right (data3); + check_sound_buffers (); } static void sample16si_crux_handler (void) { - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - uae_u32 data0p = audio_channel[0].last_sample; - uae_u32 data1p = audio_channel[1].last_sample; - uae_u32 data2p = audio_channel[2].last_sample; - uae_u32 data3p = audio_channel[3].last_sample; - - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - DO_CHANNEL_1 (data0p, 0); - DO_CHANNEL_1 (data1p, 1); - DO_CHANNEL_1 (data2p, 2); - DO_CHANNEL_1 (data3p, 3); - - data0 &= audio_channel[0].adk_mask; - data0p &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data1p &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data2p &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - data3p &= audio_channel[3].adk_mask; - - { - struct audio_channel_data *cdp; - unsigned long ratio, ratio1; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + uae_u32 data0p = audio_channel[0].last_sample; + uae_u32 data1p = audio_channel[1].last_sample; + uae_u32 data2p = audio_channel[2].last_sample; + uae_u32 data3p = audio_channel[3].last_sample; + + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + DO_CHANNEL_1 (data0p, 0); + DO_CHANNEL_1 (data1p, 1); + DO_CHANNEL_1 (data2p, 2); + DO_CHANNEL_1 (data3p, 3); + + data0 &= audio_channel[0].adk_mask; + data0p &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data1p &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data2p &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data3p &= audio_channel[3].adk_mask; + + { + struct audio_channel_data *cdp; + unsigned long ratio, ratio1; #define INTERVAL (scaled_sample_evtime * 3) - cdp = audio_channel + 0; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data0 = (data0 * ratio + data0p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 1; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data1 = (data1 * ratio + data1p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 2; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data2 = (data2 * ratio + data2p * (4096 - ratio)) >> 12; - - cdp = audio_channel + 3; - ratio1 = cdp->per - cdp->evtime; - ratio = (ratio1 << 12) / INTERVAL; - if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) - ratio = 4096; - data3 = (data3 * ratio + data3p * (4096 - ratio)) >> 12; - } - data1 += data2; - data0 += data3; - data2 = SBASEVAL16(1) + data0; - data2 = FINISH_DATA (data2, 16, 1); - data3 = SBASEVAL16(1) + data1; - data3 = FINISH_DATA (data3, 16, 1); - set_sound_buffers (); - put_sound_word_left (data2); - put_sound_word_right (data3); - check_sound_buffers (); + cdp = audio_channel + 0; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data0 = (data0 * ratio + data0p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 1; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data1 = (data1 * ratio + data1p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 2; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data2 = (data2 * ratio + data2p * (4096 - ratio)) >> 12; + + cdp = audio_channel + 3; + ratio1 = cdp->per - cdp->evtime; + ratio = (ratio1 << 12) / INTERVAL; + if (cdp->evtime < scaled_sample_evtime || ratio1 >= INTERVAL) + ratio = 4096; + data3 = (data3 * ratio + data3p * (4096 - ratio)) >> 12; + } + data1 += data2; + data0 += data3; + data2 = SBASEVAL16(1) + data0; + data2 = FINISH_DATA (data2, 16, 1); + data3 = SBASEVAL16(1) + data1; + data3 = FINISH_DATA (data3, 16, 1); + set_sound_buffers (); + put_sound_word_left (data2); + put_sound_word_right (data3); + check_sound_buffers (); } static void sample16si_rh_handler (void) { - unsigned long delta, ratio; - - uae_u32 data0 = audio_channel[0].current_sample; - uae_u32 data1 = audio_channel[1].current_sample; - uae_u32 data2 = audio_channel[2].current_sample; - uae_u32 data3 = audio_channel[3].current_sample; - uae_u32 data0p = audio_channel[0].last_sample; - uae_u32 data1p = audio_channel[1].last_sample; - uae_u32 data2p = audio_channel[2].last_sample; - uae_u32 data3p = audio_channel[3].last_sample; - - DO_CHANNEL_1 (data0, 0); - DO_CHANNEL_1 (data1, 1); - DO_CHANNEL_1 (data2, 2); - DO_CHANNEL_1 (data3, 3); - DO_CHANNEL_1 (data0p, 0); - DO_CHANNEL_1 (data1p, 1); - DO_CHANNEL_1 (data2p, 2); - DO_CHANNEL_1 (data3p, 3); - - data0 &= audio_channel[0].adk_mask; - data0p &= audio_channel[0].adk_mask; - data1 &= audio_channel[1].adk_mask; - data1p &= audio_channel[1].adk_mask; - data2 &= audio_channel[2].adk_mask; - data2p &= audio_channel[2].adk_mask; - data3 &= audio_channel[3].adk_mask; - data3p &= audio_channel[3].adk_mask; - - /* linear interpolation and summing up... */ - delta = audio_channel[0].per; - ratio = ((audio_channel[0].evtime % delta) << 8) / delta; - data0 = (data0 * (256 - ratio) + data0p * ratio) >> 8; - delta = audio_channel[1].per; - ratio = ((audio_channel[1].evtime % delta) << 8) / delta; - data1 = (data1 * (256 - ratio) + data1p * ratio) >> 8; - delta = audio_channel[2].per; - ratio = ((audio_channel[2].evtime % delta) << 8) / delta; - data1 += (data2 * (256 - ratio) + data2p * ratio) >> 8; - delta = audio_channel[3].per; - ratio = ((audio_channel[3].evtime % delta) << 8) / delta; - data0 += (data3 * (256 - ratio) + data3p * ratio) >> 8; - data2 = SBASEVAL16(1) + data0; - data2 = FINISH_DATA (data2, 16, 1); - data3 = SBASEVAL16(1) + data1; - data3 = FINISH_DATA (data3, 16, 1); - set_sound_buffers (); - put_sound_word_left (data2); - put_sound_word_right (data3); - check_sound_buffers (); + unsigned long delta, ratio; + + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + uae_u32 data0p = audio_channel[0].last_sample; + uae_u32 data1p = audio_channel[1].last_sample; + uae_u32 data2p = audio_channel[2].last_sample; + uae_u32 data3p = audio_channel[3].last_sample; + + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + DO_CHANNEL_1 (data0p, 0); + DO_CHANNEL_1 (data1p, 1); + DO_CHANNEL_1 (data2p, 2); + DO_CHANNEL_1 (data3p, 3); + + data0 &= audio_channel[0].adk_mask; + data0p &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data1p &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data2p &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data3p &= audio_channel[3].adk_mask; + + /* linear interpolation and summing up... */ + delta = audio_channel[0].per; + ratio = ((audio_channel[0].evtime % delta) << 8) / delta; + data0 = (data0 * (256 - ratio) + data0p * ratio) >> 8; + delta = audio_channel[1].per; + ratio = ((audio_channel[1].evtime % delta) << 8) / delta; + data1 = (data1 * (256 - ratio) + data1p * ratio) >> 8; + delta = audio_channel[2].per; + ratio = ((audio_channel[2].evtime % delta) << 8) / delta; + data1 += (data2 * (256 - ratio) + data2p * ratio) >> 8; + delta = audio_channel[3].per; + ratio = ((audio_channel[3].evtime % delta) << 8) / delta; + data0 += (data3 * (256 - ratio) + data3p * ratio) >> 8; + data2 = SBASEVAL16(1) + data0; + data2 = FINISH_DATA (data2, 16, 1); + data3 = SBASEVAL16(1) + data1; + data3 = FINISH_DATA (data3, 16, 1); + set_sound_buffers (); + put_sound_word_left (data2); + put_sound_word_right (data3); + check_sound_buffers (); } #else void sample16s_handler (void) { - sample16_handler (); + sample16_handler (); } static void sample16si_crux_handler (void) { - sample16i_crux_handler (); + sample16i_crux_handler (); } static void sample16si_rh_handler (void) { - sample16i_rh_handler (); + sample16i_rh_handler (); } #endif @@ -1014,899 +1014,905 @@ static int audio_work_to_do; static void zerostate (struct audio_channel_data *cdp) { - cdp->state = 0; - cdp->evtime = MAX_EV; - cdp->request_word = 0; + cdp->state = 0; + cdp->evtime = MAX_EV; + cdp->request_word = 0; } static void audio_event_reset (void) { - int i; + int i; - last_cycles = get_cycles () - 1; - next_sample_evtime = scaled_sample_evtime; - for (i = 0; i < 4; i++) { - struct audio_channel_data *cdp = audio_channel + i; - zerostate (cdp); - } - schedule_audio (); - events_schedule (); - samplecnt = 0; - extrasamples = 0; - outputsample = 1; - doublesample = 0; + last_cycles = get_cycles () - 1; + next_sample_evtime = scaled_sample_evtime; + for (i = 0; i < 4; i++) { + struct audio_channel_data *cdp = audio_channel + i; + zerostate (cdp); + } + schedule_audio (); + events_schedule (); + samplecnt = 0; + extrasamples = 0; + outputsample = 1; + doublesample = 0; } static void audio_deactivate (void) { - if (!currprefs.sound_auto) - return; - gui_data.sndbuf_status = 3; - gui_data.sndbuf = 0; - reset_sound (); - clear_sound_buffers (); - audio_event_reset (); + if (!currprefs.sound_auto) + return; + gui_data.sndbuf_status = 3; + gui_data.sndbuf = 0; + reset_sound (); + clear_sound_buffers (); + audio_event_reset (); } int audio_activate (void) { - int ret = 0; + int ret = 0; - if (!audio_work_to_do) { - restart_sound_buffer (); - ret = 1; - audio_event_reset (); - } - audio_work_to_do = 4 * maxvpos * 50; - return ret; + if (!audio_work_to_do) { + restart_sound_buffer (); + ret = 1; + audio_event_reset (); + } + audio_work_to_do = 4 * maxvpos * 50; + return ret; } STATIC_INLINE int is_audio_active (void) { - return audio_work_to_do; + return audio_work_to_do; } void schedule_audio (void) { - unsigned long best = MAX_EV; - int i; - - eventtab[ev_audio].active = 0; - eventtab[ev_audio].oldcycles = get_cycles (); - for (i = 0; i < 4; i++) { - struct audio_channel_data *cdp = audio_channel + i; - if (cdp->evtime != MAX_EV) { - if (best > cdp->evtime) { - best = cdp->evtime; - eventtab[ev_audio].active = 1; - } + unsigned long best = MAX_EV; + int i; + + eventtab[ev_audio].active = 0; + eventtab[ev_audio].oldcycles = get_cycles (); + for (i = 0; i < 4; i++) { + struct audio_channel_data *cdp = audio_channel + i; + if (cdp->evtime != MAX_EV) { + if (best > cdp->evtime) { + best = cdp->evtime; + eventtab[ev_audio].active = 1; + } + } } - } - eventtab[ev_audio].evtime = get_cycles () + best; + eventtab[ev_audio].evtime = get_cycles () + best; } static int isirq (int nr) { - return INTREQR () & (0x80 << nr); + return INTREQR () & (0x80 << nr); } static void setirq (int nr) { #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"SETIRQ %d %08X\n", nr, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"SETIRQ %d %08X\n", nr, M68K_GETPC); #endif - INTREQ (0x8000 | (0x80 << nr)); + INTREQ (0x8000 | (0x80 << nr)); } static void newsample (int nr, sample8_t sample) { - struct audio_channel_data *cdp = audio_channel + nr; + struct audio_channel_data *cdp = audio_channel + nr; #ifdef DEBUG_AUDIO - if (!debugchannel (nr)) sample = 0; + if (!debugchannel (nr)) sample = 0; #endif - if (!(audio_channel_mask & (1 << nr))) - sample = 0; - cdp->last_sample = cdp->current_sample; - cdp->current_sample = sample; + if (!(audio_channel_mask & (1 << nr))) + sample = 0; + cdp->last_sample = cdp->current_sample; + cdp->current_sample = sample; } static void state23 (struct audio_channel_data *cdp) { - if (!cdp->dmaen) - return; - if (cdp->request_word >= 0) - return; - cdp->request_word = 0; - if (cdp->wlen == 1) { - cdp->wlen = cdp->len; - cdp->pt = cdp->lc; - cdp->intreq2 = 1; - if (sampleripper_enabled) - do_samplerip (cdp); + if (!cdp->dmaen) + return; + if (cdp->request_word >= 0) + return; + cdp->request_word = 0; + if (cdp->wlen == 1) { + cdp->wlen = cdp->len; + cdp->pt = cdp->lc; + cdp->intreq2 = 1; + if (sampleripper_enabled) + do_samplerip (cdp); #ifdef DEBUG_AUDIO - if (debugchannel (cdp - audio_channel)) - write_log (L"Channel %d looped, LC=%08X LEN=%d\n", cdp - audio_channel, cdp->pt, cdp->wlen); + if (debugchannel (cdp - audio_channel)) + write_log (L"Channel %d looped, LC=%08X LEN=%d\n", cdp - audio_channel, cdp->pt, cdp->wlen); #endif - } else { - cdp->wlen = (cdp->wlen - 1) & 0xFFFF; - } + } else { + cdp->wlen = (cdp->wlen - 1) & 0xFFFF; + } } static void audio_handler (int nr) { - struct audio_channel_data *cdp = audio_channel + nr; + struct audio_channel_data *cdp = audio_channel + nr; - int audav = adkcon & (0x01 << nr); - int audap = adkcon & (0x10 << nr); - int napnav = (!audav && !audap) || audav; - int evtime = cdp->evtime; + int audav = adkcon & (0x01 << nr); + int audap = adkcon & (0x10 << nr); + int napnav = (!audav && !audap) || audav; + int evtime = cdp->evtime; - audio_activate (); - cdp->evtime = MAX_EV; - switch (cdp->state) - { + audio_activate (); + cdp->evtime = MAX_EV; + switch (cdp->state) + { case 0: - cdp->intreq2 = 0; - cdp->vpos = vpos; - if (cdp->dmaen) { - cdp->state = 1; - cdp->wlen = cdp->len; - /* there are too many stupid sound routines that fail on "too" fast cpus.. */ - if (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact) - cdp->pt = cdp->lc; + cdp->intreq2 = 0; + cdp->vpos = vpos; + if (cdp->dmaen) { + cdp->state = 1; + cdp->wlen = cdp->len; + /* there are too many stupid sound routines that fail on "too" fast cpus.. */ + if (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact) + cdp->pt = cdp->lc; #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"%d:0>1: LEN=%d\n", nr, cdp->wlen); + if (debugchannel (nr)) + write_log (L"%d:0>1: LEN=%d\n", nr, cdp->wlen); #endif + cdp->request_word = 0; + cdp->request_word_skip = 0; + audio_handler (nr); + return; + } else if (!cdp->dmaen && cdp->request_word < 0 && !isirq (nr)) { + cdp->evtime = 0; + cdp->state = 2; + setirq (nr); + audio_handler (nr); + return; + } cdp->request_word = 0; cdp->request_word_skip = 0; - audio_handler (nr); return; - } else if (!cdp->dmaen && cdp->request_word < 0 && !isirq (nr)) { - cdp->evtime = 0; - cdp->state = 2; - setirq (nr); - audio_handler (nr); - return; - } - cdp->request_word = 0; - cdp->request_word_skip = 0; - return; case 1: - if (!cdp->dmaen) { - cdp->state = 0; + if (!cdp->dmaen) { + cdp->state = 0; + return; + } + cdp->state = 5; + if (cdp->wlen != 1) + cdp->wlen = (cdp->wlen - 1) & 0xFFFF; + cdp->request_word = 2; + /* "mysterious" delay for Mission Elevator */ + //if (cdp->vpos == vpos) + if (current_hpos () > maxhpos - 20) + cdp->request_word_skip = 1; return; - } - cdp->state = 5; - if (cdp->wlen != 1) - cdp->wlen = (cdp->wlen - 1) & 0xFFFF; - cdp->request_word = 2; - /* "mysterious" delay for Mission Elevator */ - //if (cdp->vpos == vpos) - if (current_hpos () > maxhpos - 20) - cdp->request_word_skip = 1; - return; case 5: - if (!cdp->request_word) { - cdp->request_word = 2; - return; - } - setirq (nr); - if (!cdp->dmaen) { - cdp->state = 0; - cdp->request_word = 0; + if (!cdp->request_word) { + cdp->request_word = 2; + return; + } + setirq (nr); + if (!cdp->dmaen) { + cdp->state = 0; + cdp->request_word = 0; + return; + } + cdp->state = 2; + cdp->request_word = 3; + if (napnav) + cdp->request_word = 2; + cdp->dat = cdp->dat2; return; - } - cdp->state = 2; - cdp->request_word = 3; - if (napnav) - cdp->request_word = 2; - cdp->dat = cdp->dat2; - return; case 2: - if (currprefs.produce_sound == 0) - cdp->per = PERIOD_MAX; + if (currprefs.produce_sound == 0) + cdp->per = PERIOD_MAX; - if (!cdp->dmaen && isirq (nr) && (evtime == 0 || evtime == MAX_EV || evtime == cdp->per)) { - zerostate (cdp); + if (!cdp->dmaen && isirq (nr) && (evtime == 0 || evtime == MAX_EV || evtime == cdp->per)) { + zerostate (cdp); + return; + } + + state23 (cdp); + cdp->state = 3; + cdp->evtime = cdp->per; + newsample (nr, (cdp->dat >> 8) & 0xff); + cdp->dat <<= 8; + /* Period attachment? */ + if (audap) { + if (cdp->intreq2 && cdp->dmaen) + setirq (nr); + cdp->intreq2 = 0; + cdp->request_word = 1; + cdp->dat = cdp->dat2; + if (nr < 3) { + if (cdp->dat == 0) + (cdp+1)->per = PERIOD_MAX; + else if (cdp->dat < maxhpos * CYCLE_UNIT / 2 && currprefs.produce_sound < 3) + (cdp+1)->per = maxhpos * CYCLE_UNIT / 2; + else + (cdp+1)->per = cdp->dat * CYCLE_UNIT; + } + } return; - } - - state23 (cdp); - cdp->state = 3; - cdp->evtime = cdp->per; - newsample (nr, (cdp->dat >> 8) & 0xff); - cdp->dat <<= 8; - /* Period attachment? */ - if (audap) { - if (cdp->intreq2 && cdp->dmaen) - setirq (nr); - cdp->intreq2 = 0; - cdp->request_word = 1; + + case 3: + if (currprefs.produce_sound == 0) + cdp->per = PERIOD_MAX; + state23 (cdp); + cdp->state = 2; + cdp->evtime = cdp->per; + newsample (nr, (cdp->dat >> 8) & 0xff); + cdp->dat <<= 8; cdp->dat = cdp->dat2; - if (nr < 3) { - if (cdp->dat == 0) - (cdp+1)->per = PERIOD_MAX; - else if (cdp->dat < maxhpos * CYCLE_UNIT / 2 && currprefs.produce_sound < 3) - (cdp+1)->per = maxhpos * CYCLE_UNIT / 2; - else - (cdp+1)->per = cdp->dat * CYCLE_UNIT; + if (cdp->dmaen) { + if (napnav) + cdp->request_word = 1; + if (cdp->intreq2 && napnav) + setirq (nr); + } else { + if (napnav) + setirq (nr); } - } - return; + cdp->intreq2 = 0; - case 3: - if (currprefs.produce_sound == 0) - cdp->per = PERIOD_MAX; - state23 (cdp); - cdp->state = 2; - cdp->evtime = cdp->per; - newsample (nr, (cdp->dat >> 8) & 0xff); - cdp->dat <<= 8; - cdp->dat = cdp->dat2; - if (cdp->dmaen) { - if (napnav) - cdp->request_word = 1; - if (cdp->intreq2 && napnav) - setirq (nr); - } else { - if (napnav) - setirq (nr); - } - cdp->intreq2 = 0; - - /* Volume attachment? */ - if (audav) { - if (nr < 3) { - (cdp+1)->vol = cdp->dat; + /* Volume attachment? */ + if (audav) { + if (nr < 3) { + (cdp+1)->vol = cdp->dat; + } } - } - return; - } + return; + } } void audio_reset (void) { - int i; - struct audio_channel_data *cdp; + int i; + struct audio_channel_data *cdp; #ifdef AHI - ahi_close_sound (); - free_ahi_v2 (); + ahi_close_sound (); + free_ahi_v2 (); #endif - reset_sound (); - memset (sound_filter_state, 0, sizeof sound_filter_state); - if (savestate_state != STATE_RESTORE) { - for (i = 0; i < 4; i++) { - cdp = &audio_channel[i]; - memset (cdp, 0, sizeof *audio_channel); - cdp->per = PERIOD_MAX - 1; - cdp->vol = 0; - cdp->evtime = MAX_EV; - } - } else { - for (i = 0; i < 4; i++) { - cdp = &audio_channel[i]; - cdp->dmaen = (dmacon & DMA_MASTER) && (dmacon & (1 << i)); + reset_sound (); + memset (sound_filter_state, 0, sizeof sound_filter_state); + if (savestate_state != STATE_RESTORE) { + for (i = 0; i < 4; i++) { + cdp = &audio_channel[i]; + memset (cdp, 0, sizeof *audio_channel); + cdp->per = PERIOD_MAX - 1; + cdp->vol = 0; + cdp->evtime = MAX_EV; + } + } else { + for (i = 0; i < 4; i++) { + cdp = &audio_channel[i]; + cdp->dmaen = (dmacon & DMA_MASTER) && (dmacon & (1 << i)); + } } - } - last_cycles = get_cycles (); - next_sample_evtime = scaled_sample_evtime; - schedule_audio (); - events_schedule (); + last_cycles = get_cycles (); + next_sample_evtime = scaled_sample_evtime; + schedule_audio (); + events_schedule (); } STATIC_INLINE int sound_prefs_changed (void) { - if (changed_prefs.produce_sound != currprefs.produce_sound - || changed_prefs.win32_soundcard != currprefs.win32_soundcard - || changed_prefs.win32_soundexclusive != currprefs.win32_soundexclusive - || changed_prefs.sound_stereo != currprefs.sound_stereo - || changed_prefs.sound_maxbsiz != currprefs.sound_maxbsiz - || changed_prefs.sound_freq != currprefs.sound_freq - || changed_prefs.sound_auto != currprefs.sound_auto) - return 1; - - if (changed_prefs.sound_stereo_separation != currprefs.sound_stereo_separation - || changed_prefs.sound_mixed_stereo_delay != currprefs.sound_mixed_stereo_delay - || changed_prefs.sound_interpol != currprefs.sound_interpol - || changed_prefs.sound_volume != currprefs.sound_volume - || changed_prefs.sound_stereo_swap_paula != currprefs.sound_stereo_swap_paula - || changed_prefs.sound_stereo_swap_ahi != currprefs.sound_stereo_swap_ahi - || changed_prefs.sound_filter != currprefs.sound_filter - || changed_prefs.sound_filter_type != currprefs.sound_filter_type) + if (changed_prefs.produce_sound != currprefs.produce_sound + || changed_prefs.win32_soundcard != currprefs.win32_soundcard + || changed_prefs.win32_soundexclusive != currprefs.win32_soundexclusive + || changed_prefs.sound_stereo != currprefs.sound_stereo + || changed_prefs.sound_maxbsiz != currprefs.sound_maxbsiz + || changed_prefs.sound_freq != currprefs.sound_freq + || changed_prefs.sound_auto != currprefs.sound_auto) + return 1; + + if (changed_prefs.sound_stereo_separation != currprefs.sound_stereo_separation + || changed_prefs.sound_mixed_stereo_delay != currprefs.sound_mixed_stereo_delay + || changed_prefs.sound_interpol != currprefs.sound_interpol + || changed_prefs.sound_volume != currprefs.sound_volume + || changed_prefs.sound_stereo_swap_paula != currprefs.sound_stereo_swap_paula + || changed_prefs.sound_stereo_swap_ahi != currprefs.sound_stereo_swap_ahi + || changed_prefs.sound_filter != currprefs.sound_filter + || changed_prefs.sound_filter_type != currprefs.sound_filter_type) return -1; - return 0; + return 0; } /* This computes the 1st order low-pass filter term b0. - * The a1 term is 1.0 - b0. The center frequency marks the -3 dB point. */ +* The a1 term is 1.0 - b0. The center frequency marks the -3 dB point. */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif static float rc_calculate_a0 (int sample_rate, int cutoff_freq) { - float omega; - /* The BLT correction formula below blows up if the cutoff is above nyquist. */ - if (cutoff_freq >= sample_rate / 2) - return 1.0; + float omega; + /* The BLT correction formula below blows up if the cutoff is above nyquist. */ + if (cutoff_freq >= sample_rate / 2) + return 1.0; - omega = 2 * M_PI * cutoff_freq / sample_rate; - /* Compensate for the bilinear transformation. This allows us to specify the - * stop frequency more exactly, but the filter becomes less steep further - * from stopband. */ - omega = tan (omega / 2) * 2; - return 1 / (1 + 1 / omega); + omega = 2 * M_PI * cutoff_freq / sample_rate; + /* Compensate for the bilinear transformation. This allows us to specify the + * stop frequency more exactly, but the filter becomes less steep further + * from stopband. */ + omega = tan (omega / 2) * 2; + return 1 / (1 + 1 / omega); } void check_prefs_changed_audio (void) { - int ch; + int ch; #ifdef DRIVESOUND - driveclick_check_prefs (); + driveclick_check_prefs (); #endif - if (!sound_available) - return; - ch = sound_prefs_changed (); - if (!ch) - return; - if (ch > 0) { + if (!sound_available) + return; + ch = sound_prefs_changed (); + if (!ch) + return; + if (ch > 0) { #ifdef AVIOUTPUT - AVIOutput_Restart (); + AVIOutput_Restart (); #endif - clear_sound_buffers (); - } - set_audio (); - audio_activate(); + clear_sound_buffers (); + } + set_audio (); + audio_activate(); } void set_audio (void) { - int old_mixed_on = mixed_on; - int old_mixed_size = mixed_stereo_size; - int sep, delay; - int ch; - - - ch = sound_prefs_changed (); - if (ch >= 0) - close_sound (); - - currprefs.produce_sound = changed_prefs.produce_sound; - currprefs.win32_soundcard = changed_prefs.win32_soundcard; - currprefs.win32_soundexclusive = changed_prefs.win32_soundexclusive; - currprefs.sound_stereo = changed_prefs.sound_stereo; - currprefs.sound_auto = changed_prefs.sound_auto; - currprefs.sound_freq = changed_prefs.sound_freq; - currprefs.sound_maxbsiz = changed_prefs.sound_maxbsiz; - - currprefs.sound_stereo_separation = changed_prefs.sound_stereo_separation; - currprefs.sound_mixed_stereo_delay = changed_prefs.sound_mixed_stereo_delay; - currprefs.sound_interpol = changed_prefs.sound_interpol; - currprefs.sound_filter = changed_prefs.sound_filter; - currprefs.sound_filter_type = changed_prefs.sound_filter_type; - currprefs.sound_volume = changed_prefs.sound_volume; - currprefs.sound_stereo_swap_paula = changed_prefs.sound_stereo_swap_paula; - currprefs.sound_stereo_swap_ahi = changed_prefs.sound_stereo_swap_ahi; - - if (ch >= 0) { - if (currprefs.produce_sound >= 2) { - if (!init_audio ()) { - if (! sound_available) { - write_log (L"Sound is not supported.\n"); - } else { - write_log (L"Sorry, can't initialize sound.\n"); - currprefs.produce_sound = 1; - /* So we don't do this every frame */ - changed_prefs.produce_sound = 1; + int old_mixed_on = mixed_on; + int old_mixed_size = mixed_stereo_size; + int sep, delay; + int ch; + + + ch = sound_prefs_changed (); + if (ch >= 0) + close_sound (); + + currprefs.produce_sound = changed_prefs.produce_sound; + currprefs.win32_soundcard = changed_prefs.win32_soundcard; + currprefs.win32_soundexclusive = changed_prefs.win32_soundexclusive; + currprefs.sound_stereo = changed_prefs.sound_stereo; + currprefs.sound_auto = changed_prefs.sound_auto; + currprefs.sound_freq = changed_prefs.sound_freq; + currprefs.sound_maxbsiz = changed_prefs.sound_maxbsiz; + + currprefs.sound_stereo_separation = changed_prefs.sound_stereo_separation; + currprefs.sound_mixed_stereo_delay = changed_prefs.sound_mixed_stereo_delay; + currprefs.sound_interpol = changed_prefs.sound_interpol; + currprefs.sound_filter = changed_prefs.sound_filter; + currprefs.sound_filter_type = changed_prefs.sound_filter_type; + currprefs.sound_volume = changed_prefs.sound_volume; + currprefs.sound_stereo_swap_paula = changed_prefs.sound_stereo_swap_paula; + currprefs.sound_stereo_swap_ahi = changed_prefs.sound_stereo_swap_ahi; + + if (ch >= 0) { + if (currprefs.produce_sound >= 2) { + if (!init_audio ()) { + if (! sound_available) { + write_log (L"Sound is not supported.\n"); + } else { + write_log (L"Sorry, can't initialize sound.\n"); + currprefs.produce_sound = 1; + /* So we don't do this every frame */ + changed_prefs.produce_sound = 1; + } + } } - } + next_sample_evtime = scaled_sample_evtime; + last_cycles = get_cycles () - 1; + compute_vsynctime (); + } else { + sound_volume (0); } - next_sample_evtime = scaled_sample_evtime; - last_cycles = get_cycles () - 1; - compute_vsynctime (); - } else { - sound_volume (0); - } - - sep = (currprefs.sound_stereo_separation = changed_prefs.sound_stereo_separation) * 3 / 2; - if (sep >= 15) - sep = 16; - delay = currprefs.sound_mixed_stereo_delay = changed_prefs.sound_mixed_stereo_delay; - mixed_mul1 = MIXED_STEREO_SCALE / 2 - sep; - mixed_mul2 = MIXED_STEREO_SCALE / 2 + sep; - mixed_stereo_size = delay > 0 ? (1 << (delay - 1)) - 1 : 0; - mixed_on = (sep > 0 && sep < MIXED_STEREO_MAX) || mixed_stereo_size > 0; - if (mixed_on && old_mixed_size != mixed_stereo_size) { - saved_ptr = 0; - memset (right_word_saved, 0, sizeof right_word_saved); - } - - led_filter_forced = -1; // always off - sound_use_filter = sound_use_filter_sinc = 0; - if (currprefs.sound_filter) { - if (currprefs.sound_filter == FILTER_SOUND_ON) - led_filter_forced = 1; - if (currprefs.sound_filter == FILTER_SOUND_EMUL) - led_filter_forced = 0; - if (currprefs.sound_filter_type == FILTER_SOUND_TYPE_A500) - sound_use_filter = FILTER_MODEL_A500; - else if (currprefs.sound_filter_type == FILTER_SOUND_TYPE_A1200) - sound_use_filter = FILTER_MODEL_A1200; - } - a500e_filter1_a0 = rc_calculate_a0 (currprefs.sound_freq, 6200); - a500e_filter2_a0 = rc_calculate_a0 (currprefs.sound_freq, 20000); - filter_a0 = rc_calculate_a0 (currprefs.sound_freq, 7000); - led_filter_audio (); - - /* Select the right interpolation method. */ - if (sample_handler == sample16_handler - || sample_handler == sample16i_crux_handler - || sample_handler == sample16i_rh_handler - || sample_handler == sample16i_sinc_handler - || sample_handler == sample16i_anti_handler) - { - sample_handler = (currprefs.sound_interpol == 0 ? sample16_handler - : currprefs.sound_interpol == 3 ? sample16i_rh_handler - : currprefs.sound_interpol == 4 ? sample16i_crux_handler - : currprefs.sound_interpol == 2 ? sample16i_sinc_handler - : sample16i_anti_handler); - } else if (sample_handler == sample16s_handler - || sample_handler == sample16si_crux_handler - || sample_handler == sample16si_rh_handler - || sample_handler == sample16si_sinc_handler - || sample_handler == sample16si_anti_handler) - { - sample_handler = (currprefs.sound_interpol == 0 ? sample16s_handler - : currprefs.sound_interpol == 3 ? sample16si_rh_handler - : currprefs.sound_interpol == 4 ? sample16si_crux_handler - : currprefs.sound_interpol == 2 ? sample16si_sinc_handler - : sample16si_anti_handler); - } else if (sample_handler == sample16ss_handler - || sample_handler == sample16ss_sinc_handler - || sample_handler == sample16ss_anti_handler) - { - sample_handler = (currprefs.sound_interpol == 0 ? sample16ss_handler - : currprefs.sound_interpol == 3 ? sample16ss_handler - : currprefs.sound_interpol == 4 ? sample16ss_handler - : currprefs.sound_interpol == 2 ? sample16ss_sinc_handler - : sample16ss_anti_handler); - } - sample_prehandler = NULL; - if (sample_handler == sample16si_sinc_handler || sample_handler == sample16i_sinc_handler || sample_handler == sample16ss_sinc_handler) { - sample_prehandler = sinc_prehandler; - sound_use_filter_sinc = sound_use_filter; - sound_use_filter = 0; - } else if (sample_handler == sample16si_anti_handler || sample_handler == sample16i_anti_handler || sample_handler == sample16ss_anti_handler) { - sample_prehandler = anti_prehandler; - } - - audio_activate (); - - if (currprefs.produce_sound == 0) { - eventtab[ev_audio].active = 0; - events_schedule (); - } -} -void update_audio (void) -{ - unsigned long int n_cycles = 0; - static int samplecounter; + sep = (currprefs.sound_stereo_separation = changed_prefs.sound_stereo_separation) * 3 / 2; + if (sep >= 15) + sep = 16; + delay = currprefs.sound_mixed_stereo_delay = changed_prefs.sound_mixed_stereo_delay; + mixed_mul1 = MIXED_STEREO_SCALE / 2 - sep; + mixed_mul2 = MIXED_STEREO_SCALE / 2 + sep; + mixed_stereo_size = delay > 0 ? (1 << (delay - 1)) - 1 : 0; + mixed_on = (sep > 0 && sep < MIXED_STEREO_MAX) || mixed_stereo_size > 0; + if (mixed_on && old_mixed_size != mixed_stereo_size) { + saved_ptr = 0; + memset (right_word_saved, 0, sizeof right_word_saved); + } - if (!isaudio ()) - goto end; - if (savestate_state == STATE_RESTORE) - goto end; - if (!is_audio_active ()) - goto end; + led_filter_forced = -1; // always off + sound_use_filter = sound_use_filter_sinc = 0; + if (currprefs.sound_filter) { + if (currprefs.sound_filter == FILTER_SOUND_ON) + led_filter_forced = 1; + if (currprefs.sound_filter == FILTER_SOUND_EMUL) + led_filter_forced = 0; + if (currprefs.sound_filter_type == FILTER_SOUND_TYPE_A500) + sound_use_filter = FILTER_MODEL_A500; + else if (currprefs.sound_filter_type == FILTER_SOUND_TYPE_A1200) + sound_use_filter = FILTER_MODEL_A1200; + } + a500e_filter1_a0 = rc_calculate_a0 (currprefs.sound_freq, 6200); + a500e_filter2_a0 = rc_calculate_a0 (currprefs.sound_freq, 20000); + filter_a0 = rc_calculate_a0 (currprefs.sound_freq, 7000); + led_filter_audio (); + + /* Select the right interpolation method. */ + if (sample_handler == sample16_handler + || sample_handler == sample16i_crux_handler + || sample_handler == sample16i_rh_handler + || sample_handler == sample16i_sinc_handler + || sample_handler == sample16i_anti_handler) + { + sample_handler = (currprefs.sound_interpol == 0 ? sample16_handler + : currprefs.sound_interpol == 3 ? sample16i_rh_handler + : currprefs.sound_interpol == 4 ? sample16i_crux_handler + : currprefs.sound_interpol == 2 ? sample16i_sinc_handler + : sample16i_anti_handler); + } else if (sample_handler == sample16s_handler + || sample_handler == sample16si_crux_handler + || sample_handler == sample16si_rh_handler + || sample_handler == sample16si_sinc_handler + || sample_handler == sample16si_anti_handler) + { + sample_handler = (currprefs.sound_interpol == 0 ? sample16s_handler + : currprefs.sound_interpol == 3 ? sample16si_rh_handler + : currprefs.sound_interpol == 4 ? sample16si_crux_handler + : currprefs.sound_interpol == 2 ? sample16si_sinc_handler + : sample16si_anti_handler); + } else if (sample_handler == sample16ss_handler + || sample_handler == sample16ss_sinc_handler + || sample_handler == sample16ss_anti_handler) + { + sample_handler = (currprefs.sound_interpol == 0 ? sample16ss_handler + : currprefs.sound_interpol == 3 ? sample16ss_handler + : currprefs.sound_interpol == 4 ? sample16ss_handler + : currprefs.sound_interpol == 2 ? sample16ss_sinc_handler + : sample16ss_anti_handler); + } + sample_prehandler = NULL; + if (sample_handler == sample16si_sinc_handler || sample_handler == sample16i_sinc_handler || sample_handler == sample16ss_sinc_handler) { + sample_prehandler = sinc_prehandler; + sound_use_filter_sinc = sound_use_filter; + sound_use_filter = 0; + } else if (sample_handler == sample16si_anti_handler || sample_handler == sample16i_anti_handler || sample_handler == sample16ss_anti_handler) { + sample_prehandler = anti_prehandler; + } - n_cycles = get_cycles () - last_cycles; - while (n_cycles > 0) { - unsigned long int best_evtime = n_cycles + 1; - unsigned long rounded; - int i; + audio_activate (); - for (i = 0; i < 4; i++) { - if (audio_channel[i].evtime != MAX_EV && best_evtime > audio_channel[i].evtime) - best_evtime = audio_channel[i].evtime; + if (currprefs.produce_sound == 0) { + eventtab[ev_audio].active = 0; + events_schedule (); } +} - /* next_sample_evtime >= 0 so floor() behaves as expected */ - rounded = floorf (next_sample_evtime); - if ((next_sample_evtime - rounded) >= 0.5) - rounded++; +void update_audio (void) +{ + unsigned long int n_cycles = 0; + static int samplecounter; + + if (!isaudio ()) + goto end; + if (savestate_state == STATE_RESTORE) + goto end; + if (!is_audio_active ()) + goto end; + + n_cycles = get_cycles () - last_cycles; + while (n_cycles > 0) { + unsigned long int best_evtime = n_cycles + 1; + unsigned long rounded; + int i; + + for (i = 0; i < 4; i++) { + if (audio_channel[i].evtime != MAX_EV && best_evtime > audio_channel[i].evtime) + best_evtime = audio_channel[i].evtime; + } - if (currprefs.produce_sound > 1 && best_evtime > rounded) - best_evtime = rounded; + /* next_sample_evtime >= 0 so floor() behaves as expected */ + rounded = floorf (next_sample_evtime); + if ((next_sample_evtime - rounded) >= 0.5) + rounded++; - if (best_evtime > n_cycles) - best_evtime = n_cycles; + if (currprefs.produce_sound > 1 && best_evtime > rounded) + best_evtime = rounded; - /* Decrease time-to-wait counters */ - next_sample_evtime -= best_evtime; + if (best_evtime > n_cycles) + best_evtime = n_cycles; - if (currprefs.produce_sound > 1) { - if (sample_prehandler) - sample_prehandler (best_evtime / CYCLE_UNIT); - } + /* Decrease time-to-wait counters */ + next_sample_evtime -= best_evtime; - for (i = 0; i < 4; i++) { - if (audio_channel[i].evtime != MAX_EV) - audio_channel[i].evtime -= best_evtime; - } + if (currprefs.produce_sound > 1) { + if (sample_prehandler) + sample_prehandler (best_evtime / CYCLE_UNIT); + } - n_cycles -= best_evtime; + for (i = 0; i < 4; i++) { + if (audio_channel[i].evtime != MAX_EV) + audio_channel[i].evtime -= best_evtime; + } + + n_cycles -= best_evtime; - if (currprefs.produce_sound > 1) { - /* Test if new sample needs to be outputted */ - if (rounded == best_evtime) { - /* Before the following addition, next_sample_evtime is in range [-0.5, 0.5) */ - next_sample_evtime += scaled_sample_evtime - extrasamples * 15; + if (currprefs.produce_sound > 1) { + /* Test if new sample needs to be outputted */ + if (rounded == best_evtime) { + /* Before the following addition, next_sample_evtime is in range [-0.5, 0.5) */ + next_sample_evtime += scaled_sample_evtime - extrasamples * 15; #if SOUNDSTUFF > 1 - doublesample = 0; - if (--samplecounter <= 0) { - samplecounter = currprefs.sound_freq / 1000; - if (extrasamples > 0) { - outputsample = 1; - doublesample = 1; - extrasamples--; - } else if (extrasamples < 0) { - outputsample = 0; - doublesample = 0; - extrasamples++; - } - } + doublesample = 0; + if (--samplecounter <= 0) { + samplecounter = currprefs.sound_freq / 1000; + if (extrasamples > 0) { + outputsample = 1; + doublesample = 1; + extrasamples--; + } else if (extrasamples < 0) { + outputsample = 0; + doublesample = 0; + extrasamples++; + } + } #endif - (*sample_handler) (); + (*sample_handler) (); #if SOUNDSTUFF > 1 - if (outputsample == 0) - outputsample = -1; - else if (outputsample < 0) - outputsample = 1; + if (outputsample == 0) + outputsample = -1; + else if (outputsample < 0) + outputsample = 1; #endif - } - } + } + } - for (i = 0; i < 4; i++) { - if (audio_channel[i].evtime == 0) - audio_handler (i); + for (i = 0; i < 4; i++) { + if (audio_channel[i].evtime == 0) + audio_handler (i); + } } - } end: - last_cycles = get_cycles () - n_cycles; + last_cycles = get_cycles () - n_cycles; } void audio_evhandler (void) { - update_audio (); - schedule_audio (); + update_audio (); + schedule_audio (); } uae_u16 dmacon; void audio_hsync (int hpos) { - int nr, handle; - static int old_dma; - int dmaaction = hpos < 0; + int nr, handle; + static int old_dma; + int dmaaction = hpos < 0; - if (!isaudio ()) - return; - - if (old_dma != (dmacon & (DMA_MASTER | 15))) { - old_dma = dmacon & (DMA_MASTER | 15); - audio_activate (); - } - - if (audio_work_to_do > 0 && currprefs.sound_auto) { - audio_work_to_do--; - if (audio_work_to_do == 0) - audio_deactivate (); - } - - if (!is_audio_active ()) - return; + if (!isaudio ()) + return; - update_audio (); - handle = 0; - /* Sound data is fetched at the beginning of each line */ - for (nr = 0; nr < 4; nr++) { - struct audio_channel_data *cdp = audio_channel + nr; - int chan_ena = (dmacon & DMA_MASTER) && (dmacon & (1 << nr)); - int handle2 = 0; + if (old_dma != (dmacon & (DMA_MASTER | 15))) { + old_dma = dmacon & (DMA_MASTER | 15); + audio_activate (); + } - if (dmaaction && cdp->request_word > 0) { + if (audio_work_to_do > 0 && currprefs.sound_auto) { + audio_work_to_do--; + if (audio_work_to_do == 0) + audio_deactivate (); + } - if (cdp->request_word_skip) { - cdp->request_word_skip = 0; - continue; - } + if (!is_audio_active ()) + return; - if (cdp->state == 5) { - cdp->pt = cdp->lc; - if (sampleripper_enabled) - do_samplerip (cdp); + update_audio (); + handle = 0; + /* Sound data is fetched at the beginning of each line */ + for (nr = 0; nr < 4; nr++) { + struct audio_channel_data *cdp = audio_channel + nr; + int chan_ena = (dmacon & DMA_MASTER) && (dmacon & (1 << nr)); + int handle2 = 0; + + if (dmaaction && cdp->request_word > 0) { + + if (cdp->request_word_skip) { + cdp->request_word_skip = 0; + continue; + } + + if (cdp->state == 5) { + cdp->pt = cdp->lc; + if (sampleripper_enabled) + do_samplerip (cdp); #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"%d:>5: LEN=%d PT=%08X\n", nr, cdp->wlen, cdp->pt); + if (debugchannel (nr)) + write_log (L"%d:>5: LEN=%d PT=%08X\n", nr, cdp->wlen, cdp->pt); #endif - } - cdp->dat2 = last_custom_value1 = chipmem_agnus_wget (cdp->pt); - if (cdp->request_word >= 2) - handle2 = 1; - if (chan_ena) { - if (dmaaction) { - alloc_cycle_ext (13 + nr * 2, CYCLE_MISC); + } + cdp->dat2 = last_custom_value1 = chipmem_agnus_wget (cdp->pt); + if (cdp->request_word >= 2) + handle2 = 1; + if (chan_ena) { + if (dmaaction) { + alloc_cycle_ext (13 + nr * 2, CYCLE_MISC); #ifdef DEBUGGER - if (debug_dma) - record_dma (0xaa + nr * 16, cdp->dat2, cdp->pt, 13 + nr * 2, vpos, DMARECORD_AUDIO); + if (debug_dma) + record_dma (0xaa + nr * 16, cdp->dat2, cdp->pt, 13 + nr * 2, vpos, DMARECORD_AUDIO); #endif - } - if (cdp->request_word == 1 || cdp->request_word == 2) - cdp->pt += 2; - } - cdp->request_word = -1; + } + if (cdp->request_word == 1 || cdp->request_word == 2) + cdp->pt += 2; + } + cdp->request_word = -1; - } + } - if (cdp->dmaen != chan_ena) { + if (cdp->dmaen != chan_ena) { #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dDMA %d->%d (%d) LEN=%d/%d %08X\n", nr, cdp->dmaen, chan_ena, - cdp->state, cdp->wlen, cdp->len, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dDMA %d->%d (%d) LEN=%d/%d %08X\n", nr, cdp->dmaen, chan_ena, + cdp->state, cdp->wlen, cdp->len, M68K_GETPC); #endif - cdp->dmaen = chan_ena; - if (cdp->dmaen) - handle2 = 1; + cdp->dmaen = chan_ena; + if (cdp->dmaen) + handle2 = 1; + } + if (handle2) + audio_handler (nr); + handle |= handle2; + } + if (handle) { + schedule_audio (); + events_schedule (); } - if (handle2) - audio_handler (nr); - handle |= handle2; - } - if (handle) { - schedule_audio (); - events_schedule (); - } } void AUDxDAT (int nr, uae_u16 v) { - struct audio_channel_data *cdp = audio_channel + nr; + struct audio_channel_data *cdp = audio_channel + nr; #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dDAT: %04X STATE=%d IRQ=%d %08X\n", nr, - v, cdp->state, isirq(nr) ? 1 : 0, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dDAT: %04X STATE=%d IRQ=%d %08X\n", nr, + v, cdp->state, isirq(nr) ? 1 : 0, M68K_GETPC); #endif - audio_activate(); - update_audio (); - cdp->dat2 = v; - if (cdp->request_word >= 2 && cdp->request_word_skip == 0) - audio_handler (nr); - cdp->request_word = -1; - cdp->request_word_skip = 0; - /* cpu >= 68020: another "too fast" memory/CPU hack */ - if (cdp->state == 0 || (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact)) { - cdp->state = 2; - cdp->wlen = cdp->len; - cdp->pt = cdp->lc; - if (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact) - INTREQ (0x80 << nr); - audio_handler (nr); - schedule_audio (); - events_schedule (); - } - } + audio_activate(); + update_audio (); + cdp->dat2 = v; + if (cdp->request_word >= 2 && cdp->request_word_skip == 0) + audio_handler (nr); + cdp->request_word = -1; + cdp->request_word_skip = 0; + /* cpu >= 68020: another "too fast" memory/CPU hack */ + if (cdp->state == 0 || (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact)) { + cdp->state = 2; + cdp->wlen = cdp->len; + cdp->pt = cdp->lc; + if (currprefs.cpu_model >= 68020 && !currprefs.cpu_cycle_exact) + INTREQ (0x80 << nr); + audio_handler (nr); + schedule_audio (); + events_schedule (); + } +} void AUDxLCH (int nr, uae_u16 v) { - audio_activate(); - update_audio (); - audio_channel[nr].lc = (audio_channel[nr].lc & 0xffff) | ((uae_u32)v << 16); + audio_activate(); + update_audio (); + audio_channel[nr].lc = (audio_channel[nr].lc & 0xffff) | ((uae_u32)v << 16); #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dLCH: %04X %08X\n", nr, v, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dLCH: %04X %08X\n", nr, v, M68K_GETPC); #endif } void AUDxLCL (int nr, uae_u16 v) { - audio_activate(); - update_audio (); - audio_channel[nr].lc = (audio_channel[nr].lc & ~0xffff) | (v & 0xFFFE); + audio_activate(); + update_audio (); + audio_channel[nr].lc = (audio_channel[nr].lc & ~0xffff) | (v & 0xFFFE); #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dLCL: %04X %08X\n", nr, v, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dLCL: %04X %08X\n", nr, v, M68K_GETPC); #endif } void AUDxPER (int nr, uae_u16 v) { - unsigned long per = v * CYCLE_UNIT; - - audio_activate(); - update_audio (); - if (per == 0) - per = PERIOD_MAX - 1; + unsigned long per = v * CYCLE_UNIT; - if (per < maxhpos * CYCLE_UNIT / 2 && currprefs.produce_sound < 3) - per = maxhpos * CYCLE_UNIT / 2; - else if (per < 4 * CYCLE_UNIT) - /* smaller values would cause extremely high cpu usage */ - per = 4 * CYCLE_UNIT; - - if (audio_channel[nr].per == PERIOD_MAX - 1 && per != PERIOD_MAX - 1) { - audio_channel[nr].evtime = CYCLE_UNIT; - if (isaudio()) { - schedule_audio (); - events_schedule (); + audio_activate(); + update_audio (); + if (per == 0) + per = PERIOD_MAX - 1; + + if (per < maxhpos * CYCLE_UNIT / 2 && currprefs.produce_sound < 3) + per = maxhpos * CYCLE_UNIT / 2; + else if (per < 4 * CYCLE_UNIT) + /* smaller values would cause extremely high cpu usage */ + per = 4 * CYCLE_UNIT; + + if (audio_channel[nr].per == PERIOD_MAX - 1 && per != PERIOD_MAX - 1) { + audio_channel[nr].evtime = CYCLE_UNIT; + if (isaudio()) { + schedule_audio (); + events_schedule (); + } } - } - audio_channel[nr].per = per; + audio_channel[nr].per = per; #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dPER: %d %08X\n", nr, v, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dPER: %d %08X\n", nr, v, M68K_GETPC); #endif } void AUDxLEN (int nr, uae_u16 v) { - audio_activate(); - update_audio (); - audio_channel[nr].len = v; + audio_activate(); + update_audio (); + audio_channel[nr].len = v; #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dLEN: %d %08X\n", nr, v, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dLEN: %d %08X\n", nr, v, M68K_GETPC); #endif } void AUDxVOL (int nr, uae_u16 v) { - int v2 = v & 64 ? 63 : v & 63; + int v2 = v & 64 ? 63 : v & 63; - audio_activate(); - update_audio (); - audio_channel[nr].vol = v2; + audio_activate(); + update_audio (); + audio_channel[nr].vol = v2; #ifdef DEBUG_AUDIO - if (debugchannel (nr)) - write_log (L"AUD%dVOL: %d %08X\n", nr, v2, M68K_GETPC); + if (debugchannel (nr)) + write_log (L"AUD%dVOL: %d %08X\n", nr, v2, M68K_GETPC); #endif } void audio_update_irq (uae_u16 v) { #ifdef DEBUG_AUDIO - uae_u16 v2 = intreq, v3 = intreq; - int i; - if (v & 0x8000) - v2 |= v & 0x7FFF; - else - v2 &= ~v; - v2 &= (0x80 | 0x100 | 0x200 | 0x400); - v3 &= (0x80 | 0x100 | 0x200 | 0x400); - for (i = 0; i < 4; i++) { - if ((1 << i) & DEBUG_CHANNEL_MASK) { - uae_u16 mask = 0x80 << i; - if ((v2 & mask) != (v3 & mask)) - write_log (L"AUD%dINTREQ %d->%d %08X\n", i, !!(v3 & mask), !!(v2 & mask), M68K_GETPC); + uae_u16 v2 = intreq, v3 = intreq; + int i; + if (v & 0x8000) + v2 |= v & 0x7FFF; + else + v2 &= ~v; + v2 &= (0x80 | 0x100 | 0x200 | 0x400); + v3 &= (0x80 | 0x100 | 0x200 | 0x400); + for (i = 0; i < 4; i++) { + if ((1 << i) & DEBUG_CHANNEL_MASK) { + uae_u16 mask = 0x80 << i; + if ((v2 & mask) != (v3 & mask)) + write_log (L"AUD%dINTREQ %d->%d %08X\n", i, !!(v3 & mask), !!(v2 & mask), M68K_GETPC); + } } - } #endif } void audio_update_adkmasks (void) { - static int prevcon = -1; - unsigned long t = adkcon | (adkcon >> 4); + static int prevcon = -1; + unsigned long t = adkcon | (adkcon >> 4); - audio_channel[0].adk_mask = (((t >> 0) & 1) - 1); - audio_channel[1].adk_mask = (((t >> 1) & 1) - 1); - audio_channel[2].adk_mask = (((t >> 2) & 1) - 1); - audio_channel[3].adk_mask = (((t >> 3) & 1) - 1); - if ((prevcon & 0xff) != (adkcon & 0xff)) { - audio_activate(); + audio_channel[0].adk_mask = (((t >> 0) & 1) - 1); + audio_channel[1].adk_mask = (((t >> 1) & 1) - 1); + audio_channel[2].adk_mask = (((t >> 2) & 1) - 1); + audio_channel[3].adk_mask = (((t >> 3) & 1) - 1); + if ((prevcon & 0xff) != (adkcon & 0xff)) { + audio_activate(); #ifdef DEBUG_AUDIO - write_log (L"ADKCON=%02x %08X\n", adkcon & 0xff, M68K_GETPC); + write_log (L"ADKCON=%02x %08X\n", adkcon & 0xff, M68K_GETPC); #endif - prevcon = adkcon; - } + prevcon = adkcon; + } } int init_audio (void) { - return init_sound (); + return init_sound (); } void led_filter_audio (void) { - led_filter_on = 0; - if (led_filter_forced > 0 || (gui_data.powerled && led_filter_forced >= 0)) - led_filter_on = 1; + led_filter_on = 0; + if (led_filter_forced > 0 || (gui_data.powerled && led_filter_forced >= 0)) + led_filter_on = 1; } uae_u8 *restore_audio (int i, uae_u8 *src) { - struct audio_channel_data *acd; - uae_u16 p; + struct audio_channel_data *acd; + uae_u16 p; - acd = audio_channel + i; - acd->state = restore_u8 (); - acd->vol = restore_u8 (); - acd->intreq2 = restore_u8 (); - acd->request_word = restore_u8 (); - acd->len = restore_u16 (); - acd->wlen = restore_u16 (); - p = restore_u16 (); - acd->per = p ? p * CYCLE_UNIT : PERIOD_MAX; - p = restore_u16 (); - acd->lc = restore_u32 (); - acd->pt = restore_u32 (); - acd->evtime = restore_u32 (); - return src; + acd = audio_channel + i; + acd->state = restore_u8 (); + acd->vol = restore_u8 (); + acd->intreq2 = restore_u8 (); + acd->request_word = restore_u8 (); + acd->len = restore_u16 (); + acd->wlen = restore_u16 (); + p = restore_u16 (); + acd->per = p ? p * CYCLE_UNIT : PERIOD_MAX; + p = restore_u16 (); + acd->lc = restore_u32 (); + acd->pt = restore_u32 (); + acd->evtime = restore_u32 (); + return src; } uae_u8 *save_audio (int i, int *len, uae_u8 *dstptr) { - struct audio_channel_data *acd; - uae_u8 *dst, *dstbak; - uae_u16 p; - - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = (uae_u8*)malloc (100); - acd = audio_channel + i; - save_u8 ((uae_u8)acd->state); - save_u8 (acd->vol); - save_u8 (acd->intreq2); - save_u8 (acd->request_word); - save_u16 (acd->len); - save_u16 (acd->wlen); - p = acd->per == PERIOD_MAX ? 0 : acd->per / CYCLE_UNIT; - save_u16 (p); - save_u16 (acd->dat2); - save_u32 (acd->lc); - save_u32 (acd->pt); - save_u32 (acd->evtime); - *len = dst - dstbak; - return dstbak; + struct audio_channel_data *acd; + uae_u8 *dst, *dstbak; + uae_u16 p; + + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = (uae_u8*)malloc (100); + acd = audio_channel + i; + save_u8 ((uae_u8)acd->state); + save_u8 (acd->vol); + save_u8 (acd->intreq2); + save_u8 (acd->request_word); + save_u16 (acd->len); + save_u16 (acd->wlen); + p = acd->per == PERIOD_MAX ? 0 : acd->per / CYCLE_UNIT; + save_u16 (p); + save_u16 (acd->dat2); + save_u32 (acd->lc); + save_u32 (acd->pt); + save_u32 (acd->evtime); + *len = dst - dstbak; + return dstbak; } void audio_vsync (void) { #if SOUNDSTUFF > 0 - int i, max, min; - static int lastdir; - - min = -10 * 10; - max = (isfullscreen () > 0 && currprefs.gfx_avsync > 0) ? 10 * 10 : 20 * 10; - extrasamples = 0; - if (gui_data.sndbuf < min) { // +1 - extrasamples = (min - gui_data.sndbuf) / 10; - lastdir = 1; - } else if (gui_data.sndbuf > max) { // -1 - extrasamples = (max - gui_data.sndbuf) / 10; - } else if (gui_data.sndbuf > 1 * 50 && lastdir < 0) { - extrasamples--; - } else if (gui_data.sndbuf < -1 * 50 && lastdir > 0) { - extrasamples++; - } else { - lastdir = 0; - } - - if (extrasamples > 99) - extrasamples = 99; - if (extrasamples < -99) - extrasamples = -99; + int max, min; + int vsync = isfullscreen () > 0 && currprefs.gfx_avsync > 0; + static int lastdir; + + if (!vsync) { + extrasamples = 0; + return; + } + + min = -10 * 10; + max = vsync ? 10 * 10 : 20 * 10; + extrasamples = 0; + if (gui_data.sndbuf < min) { // +1 + extrasamples = (min - gui_data.sndbuf) / 10; + lastdir = 1; + } else if (gui_data.sndbuf > max) { // -1 + extrasamples = (max - gui_data.sndbuf) / 10; + } else if (gui_data.sndbuf > 1 * 50 && lastdir < 0) { + extrasamples--; + } else if (gui_data.sndbuf < -1 * 50 && lastdir > 0) { + extrasamples++; + } else { + lastdir = 0; + } + + if (extrasamples > 99) + extrasamples = 99; + if (extrasamples < -99) + extrasamples = -99; #endif } diff --git a/autoconf.c b/autoconf.c index 79a4581e..31fa5e16 100644 --- a/autoconf.c +++ b/autoconf.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * AutoConfig devices - * - * Copyright 1995, 1996 Bernd Schmidt - * Copyright 1996 Ed Hanway - */ +/* +* UAE - The Un*x Amiga Emulator +* +* AutoConfig devices +* +* Copyright 1995, 1996 Bernd Schmidt +* Copyright 1996 Ed Hanway +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -40,274 +40,274 @@ static uae_u8 *REGPARAM3 rtarea_xlate (uaecptr) REGPARAM; static int REGPARAM3 rtarea_check (uaecptr addr, uae_u32 size) REGPARAM; addrbank rtarea_bank = { - rtarea_lget, rtarea_wget, rtarea_bget, - rtarea_lput, rtarea_wput, rtarea_bput, - rtarea_xlate, rtarea_check, NULL, L"UAE Boot ROM", - rtarea_lget, rtarea_wget, ABFLAG_ROMIN + rtarea_lget, rtarea_wget, rtarea_bget, + rtarea_lput, rtarea_wput, rtarea_bput, + rtarea_xlate, rtarea_check, NULL, L"UAE Boot ROM", + rtarea_lget, rtarea_wget, ABFLAG_ROMIN }; static uae_u8 *REGPARAM2 rtarea_xlate (uaecptr addr) { - addr &= 0xFFFF; - return rtarea + addr; + addr &= 0xFFFF; + return rtarea + addr; } static int REGPARAM2 rtarea_check (uaecptr addr, uae_u32 size) { - addr &= 0xFFFF; - return (addr + size) <= 0xFFFF; + addr &= 0xFFFF; + return (addr + size) <= 0xFFFF; } static uae_u32 REGPARAM2 rtarea_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xFFFF; - return (uae_u32)(rtarea_wget (addr) << 16) + rtarea_wget (addr + 2); + addr &= 0xFFFF; + return (uae_u32)(rtarea_wget (addr) << 16) + rtarea_wget (addr + 2); } static uae_u32 REGPARAM2 rtarea_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xFFFF; - return (rtarea[addr] << 8) + rtarea[addr + 1]; + addr &= 0xFFFF; + return (rtarea[addr] << 8) + rtarea[addr + 1]; } static uae_u32 REGPARAM2 rtarea_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xFFFF; - return rtarea[addr]; + addr &= 0xFFFF; + return rtarea[addr]; } static void REGPARAM2 rtarea_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } static void REGPARAM2 rtarea_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } static void REGPARAM2 rtarea_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } /* some quick & dirty code to fill in the rt area and save me a lot of - * scratch paper - */ +* scratch paper +*/ static int rt_addr; static int rt_straddr; uae_u32 addr (int ptr) { - return (uae_u32)ptr + rtarea_base; + return (uae_u32)ptr + rtarea_base; } void db (uae_u8 data) { - rtarea[rt_addr++] = data; + rtarea[rt_addr++] = data; } void dw (uae_u16 data) { - rtarea[rt_addr++] = (uae_u8)(data >> 8); - rtarea[rt_addr++] = (uae_u8)data; + rtarea[rt_addr++] = (uae_u8)(data >> 8); + rtarea[rt_addr++] = (uae_u8)data; } void dl (uae_u32 data) { - rtarea[rt_addr++] = data >> 24; - rtarea[rt_addr++] = data >> 16; - rtarea[rt_addr++] = data >> 8; - rtarea[rt_addr++] = data; + rtarea[rt_addr++] = data >> 24; + rtarea[rt_addr++] = data >> 16; + rtarea[rt_addr++] = data >> 8; + rtarea[rt_addr++] = data; } uae_u8 dbg (uaecptr addr) { - addr -= rtarea_base; - return rtarea[addr]; + addr -= rtarea_base; + return rtarea[addr]; } /* store strings starting at the end of the rt area and working - * backward. store pointer at current address - */ +* backward. store pointer at current address +*/ uae_u32 ds_ansi (const uae_char *str) { - int len; + int len; - if (!str) + if (!str) + return addr (rt_straddr); + len = strlen (str) + 1; + rt_straddr -= len; + strcpy ((uae_char*)rtarea + rt_straddr, str); return addr (rt_straddr); - len = strlen (str) + 1; - rt_straddr -= len; - strcpy ((uae_char*)rtarea + rt_straddr, str); - return addr (rt_straddr); } uae_u32 ds (const TCHAR *str) { - char *s = ua (str); - uae_u32 v = ds_ansi (s); - xfree (s); - return v; + char *s = ua (str); + uae_u32 v = ds_ansi (s); + xfree (s); + return v; } void calltrap (uae_u32 n) { - dw (0xA000 + n); + dw (0xA000 + n); } void org (uae_u32 a) { - if ( ((a & 0xffff0000) != 0x00f00000) && ((a & 0xffff0000) != rtarea_base) ) - write_log (L"ORG: corrupt address! %08X", a); - rt_addr = a & 0xffff; + if ( ((a & 0xffff0000) != 0x00f00000) && ((a & 0xffff0000) != rtarea_base) ) + write_log (L"ORG: corrupt address! %08X", a); + rt_addr = a & 0xffff; } uae_u32 here (void) { - return addr (rt_addr); + return addr (rt_addr); } void align (int b) { - rt_addr = (rt_addr + b - 1) & ~(b - 1); + rt_addr = (rt_addr + b - 1) & ~(b - 1); } static uae_u32 REGPARAM2 nullfunc (TrapContext *context) { - write_log (L"Null function called\n"); - return 0; + write_log (L"Null function called\n"); + return 0; } static uae_u32 REGPARAM2 getchipmemsize (TrapContext *context) { - return allocated_chipmem; + return allocated_chipmem; } static uae_u32 REGPARAM2 uae_puts (TrapContext *context) { - puts ((uae_u8*)get_real_address (m68k_areg (regs, 0))); - return 0; + puts ((uae_u8*)get_real_address (m68k_areg (regs, 0))); + return 0; } void rtarea_init_mem (void) { - rtarea = mapped_malloc (0x10000, L"rtarea"); - if (!rtarea) { - write_log (L"virtual memory exhausted (rtarea)!\n"); - abort (); - } - rtarea_bank.baseaddr = rtarea; + rtarea = mapped_malloc (0x10000, L"rtarea"); + if (!rtarea) { + write_log (L"virtual memory exhausted (rtarea)!\n"); + abort (); + } + rtarea_bank.baseaddr = rtarea; } void rtarea_init (void) { - uae_u32 a; - TCHAR uaever[100]; + uae_u32 a; + TCHAR uaever[100]; - rt_straddr = 0xFF00 - 2; - rt_addr = 0; + rt_straddr = 0xFF00 - 2; + rt_addr = 0; - init_traps (); + init_traps (); - rtarea_init_mem (); - memset (rtarea, 0, 0x10000); + rtarea_init_mem (); + memset (rtarea, 0, 0x10000); - _stprintf (uaever, L"uae-%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); + _stprintf (uaever, L"uae-%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); - EXPANSION_uaeversion = ds (uaever); - EXPANSION_explibname = ds (L"expansion.library"); - EXPANSION_doslibname = ds (L"dos.library"); - EXPANSION_uaedevname = ds (L"uae.device"); + EXPANSION_uaeversion = ds (uaever); + EXPANSION_explibname = ds (L"expansion.library"); + EXPANSION_doslibname = ds (L"dos.library"); + EXPANSION_uaedevname = ds (L"uae.device"); - deftrap (NULL); /* Generic emulator trap */ + deftrap (NULL); /* Generic emulator trap */ - dw (0); - dw (0); + dw (0); + dw (0); - a = here(); - /* Dummy trap - removing this breaks the filesys emulation. */ - org (rtarea_base + 0xFF00); - calltrap (deftrap2 (nullfunc, TRAPFLAG_NO_RETVAL, L"")); + a = here(); + /* Dummy trap - removing this breaks the filesys emulation. */ + org (rtarea_base + 0xFF00); + calltrap (deftrap2 (nullfunc, TRAPFLAG_NO_RETVAL, L"")); - org (rtarea_base + 0xFF80); - calltrap (deftrapres (getchipmemsize, TRAPFLAG_DORET, L"getchipmemsize")); + org (rtarea_base + 0xFF80); + calltrap (deftrapres (getchipmemsize, TRAPFLAG_DORET, L"getchipmemsize")); - org (rtarea_base + 0xFF10); - calltrap (deftrapres (uae_puts, TRAPFLAG_NO_RETVAL, L"uae_puts")); - dw (RTS); + org (rtarea_base + 0xFF10); + calltrap (deftrapres (uae_puts, TRAPFLAG_NO_RETVAL, L"uae_puts")); + dw (RTS); - org (a); + org (a); #ifdef FILESYS - filesys_install_code (); + filesys_install_code (); #endif #ifdef PICASSO96 - uaegfx_install_code (); + uaegfx_install_code (); #endif - uae_boot_rom_size = here() - rtarea_base; - init_extended_traps (); + uae_boot_rom_size = here() - rtarea_base; + init_extended_traps (); } volatile int uae_int_requested = 0; void set_uae_int_flag (void) { - rtarea[0xFFFB] = uae_int_requested & 1; + rtarea[0xFFFB] = uae_int_requested & 1; } void rtarea_setup (void) { - uaecptr base = need_uae_boot_rom (); - if (base) { - write_log (L"RTAREA located at %08X\n", base); - rtarea_base = base; - } + uaecptr base = need_uae_boot_rom (); + if (base) { + write_log (L"RTAREA located at %08X\n", base); + rtarea_base = base; + } } uaecptr makedatatable (uaecptr resid, uaecptr resname, uae_u8 type, uae_s8 priority, uae_u16 ver, uae_u16 rev) { - uaecptr datatable = here (); - - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (type << 8); - dw (0xE000); /* INITBYTE */ - dw (0x0009); /* LN_PRI */ - dw (priority << 8); - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (ver); - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (rev); - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (resid); - dw (0x0000); /* end of table */ - return datatable; + uaecptr datatable = here (); + + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (type << 8); + dw (0xE000); /* INITBYTE */ + dw (0x0009); /* LN_PRI */ + dw (priority << 8); + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (ver); + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (rev); + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (resid); + dw (0x0000); /* end of table */ + return datatable; } diff --git a/blitter.c b/blitter.c index 25474aa9..08eaa1b1 100644 --- a/blitter.c +++ b/blitter.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Custom chip emulation - * - * (c) 1995 Bernd Schmidt, Alessandro Bissacco - * (c) 2002 - 2005 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Custom chip emulation +* +* (c) 1995 Bernd Schmidt, Alessandro Bissacco +* (c) 2002 - 2005 Toni Wilen +*/ //#define BLITTER_DEBUG_NOWAIT //#define BLITTER_DEBUG @@ -85,208 +85,208 @@ static int last_blitter_hpos; #define BLITTER_STARTUP_CYCLES 2 /* - Blitter Idle Cycle: +Blitter Idle Cycle: - Cycles that are free cycles (available for CPU) and - are not used by any other Agnus DMA channel. Blitter - idle cycle is not "used" by blitter, CPU can still use - it normally if it needs the bus. +Cycles that are free cycles (available for CPU) and +are not used by any other Agnus DMA channel. Blitter +idle cycle is not "used" by blitter, CPU can still use +it normally if it needs the bus. - same in both block and line modes +same in both block and line modes - number of cycles, initial cycle, main cycle +number of cycles, initial cycle, main cycle */ static const int blit_cycle_diagram[][10] = { - { 2, 0,0, 0,0 }, /* 0 */ - { 2, 0,0, 0,4 }, /* 1 */ - { 2, 0,3, 0,3 }, /* 2 */ - { 3, 0,3,0, 0,3,4 }, /* 3 */ - { 3, 0,2,0, 0,2,0 }, /* 4 */ - { 3, 0,2,0, 0,2,4 }, /* 5 */ - { 3, 0,2,3, 0,2,3 }, /* 6 */ - { 4, 0,2,3,0, 0,2,3,4 }, /* 7 */ - { 2, 1,0, 1,0 }, /* 8 */ - { 2, 1,0, 1,4 }, /* 9 */ - { 2, 1,3, 1,3 }, /* A */ - { 3, 1,3,0, 1,3,4, }, /* B */ - { 3, 1,2,0, 1,2,0 }, /* C */ - { 3, 1,2,0, 1,2,4 }, /* D */ - { 3, 1,2,3, 1,2,3 }, /* E */ - { 4, 1,2,3,0, 1,2,3,4 } /* F */ + { 2, 0,0, 0,0 }, /* 0 */ + { 2, 0,0, 0,4 }, /* 1 */ + { 2, 0,3, 0,3 }, /* 2 */ + { 3, 0,3,0, 0,3,4 }, /* 3 */ + { 3, 0,2,0, 0,2,0 }, /* 4 */ + { 3, 0,2,0, 0,2,4 }, /* 5 */ + { 3, 0,2,3, 0,2,3 }, /* 6 */ + { 4, 0,2,3,0, 0,2,3,4 }, /* 7 */ + { 2, 1,0, 1,0 }, /* 8 */ + { 2, 1,0, 1,4 }, /* 9 */ + { 2, 1,3, 1,3 }, /* A */ + { 3, 1,3,0, 1,3,4, }, /* B */ + { 3, 1,2,0, 1,2,0 }, /* C */ + { 3, 1,2,0, 1,2,4 }, /* D */ + { 3, 1,2,3, 1,2,3 }, /* E */ + { 4, 1,2,3,0, 1,2,3,4 } /* F */ }; /* - following 4 channel combinations in fill mode have extra - idle cycle added (still requires free bus cycle) +following 4 channel combinations in fill mode have extra +idle cycle added (still requires free bus cycle) */ static const int blit_cycle_diagram_fill[][10] = { - { 0 }, /* 0 */ - { 3, 0,0,0, 0,4,0 }, /* 1 */ - { 0 }, /* 2 */ - { 0 }, /* 3 */ - { 0 }, /* 4 */ - { 4, 0,2,0,0, 0,2,4,0 }, /* 5 */ - { 0 }, /* 6 */ - { 0 }, /* 7 */ - { 0 }, /* 8 */ - { 3, 1,0,0, 1,4,0 }, /* 9 */ - { 0 }, /* A */ - { 0 }, /* B */ - { 0 }, /* C */ - { 4, 1,2,0,0, 1,2,4,0 }, /* D */ - { 0 }, /* E */ - { 0 }, /* F */ + { 0 }, /* 0 */ + { 3, 0,0,0, 0,4,0 }, /* 1 */ + { 0 }, /* 2 */ + { 0 }, /* 3 */ + { 0 }, /* 4 */ + { 4, 0,2,0,0, 0,2,4,0 }, /* 5 */ + { 0 }, /* 6 */ + { 0 }, /* 7 */ + { 0 }, /* 8 */ + { 3, 1,0,0, 1,4,0 }, /* 9 */ + { 0 }, /* A */ + { 0 }, /* B */ + { 0 }, /* C */ + { 4, 1,2,0,0, 1,2,4,0 }, /* D */ + { 0 }, /* E */ + { 0 }, /* F */ }; /* - -C-D C-D- ... C-D- -- - - line draw takes 4 cycles (-C-D) - idle cycles do the same as above, 2 dma fetches - (read from C, write to D, but see below) - - Oddities: - - - first word is written to address pointed by BLTDPT - but all following writes go to address pointed by BLTCPT! - (some kind of internal copy because all bus cyles are - using normal BLTDDAT) - - BLTDMOD is ignored by blitter (BLTCMOD is used) - - state of D-channel enable bit does not matter! - - disabling A-channel freezes the content of BPLAPT - - C-channel disabled: nothing is written - - There is one tricky situation, writing to DFF058 just before - last D write cycle (which is normally free) does not distrupt - blitter operation, final D is still written correctly before - blitter starts normally (after 2 idle cycles) - - There is at least one demo that does this.. - +-C-D C-D- ... C-D- -- + +line draw takes 4 cycles (-C-D) +idle cycles do the same as above, 2 dma fetches +(read from C, write to D, but see below) + +Oddities: + +- first word is written to address pointed by BLTDPT +but all following writes go to address pointed by BLTCPT! +(some kind of internal copy because all bus cyles are +using normal BLTDDAT) +- BLTDMOD is ignored by blitter (BLTCMOD is used) +- state of D-channel enable bit does not matter! +- disabling A-channel freezes the content of BPLAPT +- C-channel disabled: nothing is written + +There is one tricky situation, writing to DFF058 just before +last D write cycle (which is normally free) does not distrupt +blitter operation, final D is still written correctly before +blitter starts normally (after 2 idle cycles) + +There is at least one demo that does this.. + */ // 5 = internal "processing cycle" static const int blit_cycle_diagram_line[] = { - 4, 0,3,5,4, 0,3,5,4 + 4, 0,3,5,4, 0,3,5,4 }; static const int blit_cycle_diagram_finald[] = { - 2, 0,4, 0,4 + 2, 0,4, 0,4 }; static const int blit_cycle_diagram_finalld[] = { - 2, 0,0, 0,0 + 2, 0,0, 0,0 }; void build_blitfilltable (void) { - unsigned int d, fillmask; - int i; - - for (i = 0; i < BLITTER_MAX_WORDS; i++) - blit_masktable[i] = 0xFFFF; - - for (d = 0; d < 256; d++) { - for (i = 0; i < 4; i++) { - int fc = i & 1; - uae_u8 data = d; - for (fillmask = 1; fillmask != 0x100; fillmask <<= 1) { - uae_u16 tmp = data; - if (fc) { - if (i & 2) - data |= fillmask; - else - data ^= fillmask; + unsigned int d, fillmask; + int i; + + for (i = 0; i < BLITTER_MAX_WORDS; i++) + blit_masktable[i] = 0xFFFF; + + for (d = 0; d < 256; d++) { + for (i = 0; i < 4; i++) { + int fc = i & 1; + uae_u8 data = d; + for (fillmask = 1; fillmask != 0x100; fillmask <<= 1) { + uae_u16 tmp = data; + if (fc) { + if (i & 2) + data |= fillmask; + else + data ^= fillmask; + } + if (tmp & fillmask) fc = !fc; + } + blit_filltable[d][i][0] = data; + blit_filltable[d][i][1] = fc; } - if (tmp & fillmask) fc = !fc; - } - blit_filltable[d][i][0] = data; - blit_filltable[d][i][1] = fc; } - } } STATIC_INLINE void record_dma_blit (uae_u16 reg, uae_u16 dat, uae_u32 addr, int hpos) { #ifdef DEBUGGER - int type; - - if (blitline) - type = DMARECORD_BLITTER_LINE; - else - type = DMARECORD_BLITTER; - if (debug_dma) - record_dma (reg, dat, addr, hpos, vpos, type); + int type; + + if (blitline) + type = DMARECORD_BLITTER_LINE; + else + type = DMARECORD_BLITTER; + if (debug_dma) + record_dma (reg, dat, addr, hpos, vpos, type); #endif } static void blitter_dump (void) { - write_log (L"PT A=%08X B=%08X C=%08X D=%08X\n", bltapt, bltbpt, bltcpt, bltdpt); - write_log (L"CON0=%04X CON1=%04X DAT A=%04X B=%04X C=%04X\n", - bltcon0, bltcon1, blt_info.bltadat, blt_info.bltbdat, blt_info.bltcdat); - write_log (L"AFWM=%04X ALWM=%04X MOD A=%04X B=%04X C=%04X D=%04X\n", - blt_info.bltafwm, blt_info.bltalwm, - blt_info.bltamod & 0xffff, blt_info.bltbmod & 0xffff, blt_info.bltcmod & 0xffff, blt_info.bltdmod & 0xffff); + write_log (L"PT A=%08X B=%08X C=%08X D=%08X\n", bltapt, bltbpt, bltcpt, bltdpt); + write_log (L"CON0=%04X CON1=%04X DAT A=%04X B=%04X C=%04X\n", + bltcon0, bltcon1, blt_info.bltadat, blt_info.bltbdat, blt_info.bltcdat); + write_log (L"AFWM=%04X ALWM=%04X MOD A=%04X B=%04X C=%04X D=%04X\n", + blt_info.bltafwm, blt_info.bltalwm, + blt_info.bltamod & 0xffff, blt_info.bltbmod & 0xffff, blt_info.bltcmod & 0xffff, blt_info.bltdmod & 0xffff); } STATIC_INLINE const int *get_ch (void) { - if (blit_faulty) - return &blit_diag[0]; - if (blit_final) - return blitline ? blit_cycle_diagram_finalld : blit_cycle_diagram_finald; - return blit_diag; + if (blit_faulty) + return &blit_diag[0]; + if (blit_final) + return blitline ? blit_cycle_diagram_finalld : blit_cycle_diagram_finald; + return blit_diag; } STATIC_INLINE int channel_state (int cycles) { - const int *diag; - if (cycles < 0) - return 0; - diag = get_ch (); - if (cycles < diag[0]) - return diag[1 + cycles]; - cycles -= diag[0]; - cycles %= diag[0]; - return diag[1 + diag[0] + cycles]; + const int *diag; + if (cycles < 0) + return 0; + diag = get_ch (); + if (cycles < diag[0]) + return diag[1 + cycles]; + cycles -= diag[0]; + cycles %= diag[0]; + return diag[1 + diag[0] + cycles]; } STATIC_INLINE int channel_pos (int cycles) { - const int *diag; - if (cycles < 0) - return 0; - diag = get_ch (); - if (cycles < diag[0]) + const int *diag; + if (cycles < 0) + return 0; + diag = get_ch (); + if (cycles < diag[0]) + return cycles; + cycles -= diag[0]; + cycles %= diag[0]; return cycles; - cycles -= diag[0]; - cycles %= diag[0]; - return cycles; } int blitter_channel_state (void) { - return channel_state (blit_cyclecounter); + return channel_state (blit_cyclecounter); } extern int is_bitplane_dma (int hpos); STATIC_INLINE int canblit (int hpos) { - if (is_bitplane_dma (hpos)) - return 0; - if (cycle_line[hpos]) - return 0; - return 1; + if (is_bitplane_dma (hpos)) + return 0; + if (cycle_line[hpos]) + return 0; + return 1; } // blitter interrupt is set when last "main" cycle @@ -294,346 +294,346 @@ STATIC_INLINE int canblit (int hpos) // still needs 2 more cycles before final D is written static void blitter_interrupt (int hpos, int done) { - if (blit_interrupt) - return; - if (!done && (!currprefs.blitter_cycle_exact || (currprefs.chipset_mask & CSMASK_AGA))) - return; - blit_interrupt = 1; - INTREQ (0x8040); - if (debug_dma) - record_dma_event (DMA_EVENT_BLITIRQ, hpos, vpos); + if (blit_interrupt) + return; + if (!done && (!currprefs.blitter_cycle_exact || (currprefs.chipset_mask & CSMASK_AGA))) + return; + blit_interrupt = 1; + INTREQ (0x8040); + if (debug_dma) + record_dma_event (DMA_EVENT_BLITIRQ, hpos, vpos); } static void blitter_done (int hpos) { - ddat1use = ddat2use = 0; - bltstate = blit_startcycles == 0 || !currprefs.blitter_cycle_exact ? BLT_done : BLT_init; - blitter_interrupt (hpos, 1); - blitter_done_notify (hpos); - if (debug_dma) - record_dma_event (DMA_EVENT_BLITFINISHED, hpos, vpos); - event2_remevent (ev2_blitter); - unset_special (SPCFLAG_BLTNASTY); + ddat1use = ddat2use = 0; + bltstate = blit_startcycles == 0 || !currprefs.blitter_cycle_exact ? BLT_done : BLT_init; + blitter_interrupt (hpos, 1); + blitter_done_notify (hpos); + if (debug_dma) + record_dma_event (DMA_EVENT_BLITFINISHED, hpos, vpos); + event2_remevent (ev2_blitter); + unset_special (SPCFLAG_BLTNASTY); #ifdef BLITTER_DEBUG - write_log (L"cycles %d, missed %d, total %d\n", - blit_totalcyclecounter, blit_misscyclecounter, blit_totalcyclecounter + blit_misscyclecounter); + write_log (L"cycles %d, missed %d, total %d\n", + blit_totalcyclecounter, blit_misscyclecounter, blit_totalcyclecounter + blit_misscyclecounter); #endif } -STATIC_INLINE chipmem_agnus_wput2 (uaecptr addr, uae_u32 w) +STATIC_INLINE void chipmem_agnus_wput2 (uaecptr addr, uae_u32 w) { - last_custom_value1 = w; + last_custom_value1 = w; #ifndef BLITTER_DEBUG_NO_D - chipmem_agnus_wput (addr, w); + chipmem_agnus_wput (addr, w); #endif } static void blitter_dofast (void) { - int i,j; - uaecptr bltadatptr = 0, bltbdatptr = 0, bltcdatptr = 0, bltddatptr = 0; - uae_u8 mt = bltcon0 & 0xFF; - - blit_masktable[0] = blt_info.bltafwm; - blit_masktable[hblitsize - 1] &= blt_info.bltalwm; - - if (bltcon0 & 0x800) { - bltadatptr = bltapt; - bltapt += (hblitsize * 2 + blt_info.bltamod) * vblitsize; - } - if (bltcon0 & 0x400) { - bltbdatptr = bltbpt; - bltbpt += (hblitsize * 2 + blt_info.bltbmod) * vblitsize; - } - if (bltcon0 & 0x200) { - bltcdatptr = bltcpt; - bltcpt += (hblitsize * 2 + blt_info.bltcmod) * vblitsize; - } - if (bltcon0 & 0x100) { - bltddatptr = bltdpt; - bltdpt += (hblitsize * 2 + blt_info.bltdmod) * vblitsize; - } + int i,j; + uaecptr bltadatptr = 0, bltbdatptr = 0, bltcdatptr = 0, bltddatptr = 0; + uae_u8 mt = bltcon0 & 0xFF; -#ifdef SPEEDUP - if (blitfunc_dofast[mt] && !blitfill) { - (*blitfunc_dofast[mt])(bltadatptr, bltbdatptr, bltcdatptr, bltddatptr, &blt_info); - } else -#endif - { - uae_u32 blitbhold = blt_info.bltbhold; - uae_u32 preva = 0, prevb = 0; - uaecptr dstp = 0; - int dodst = 0; - - /*if (!blitfill) write_log (L"minterm %x not present\n",mt); */ - for (j = 0; j < vblitsize; j++) { - blitfc = !!(bltcon1 & 0x4); - for (i = 0; i < hblitsize; i++) { - uae_u32 bltadat, blitahold; - uae_u16 bltbdat; - if (bltadatptr) { - blt_info.bltadat = bltadat = chipmem_agnus_wget (bltadatptr); - bltadatptr += 2; - } else - bltadat = blt_info.bltadat; - bltadat &= blit_masktable[i]; - blitahold = (((uae_u32)preva << 16) | bltadat) >> blt_info.blitashift; - preva = bltadat; + blit_masktable[0] = blt_info.bltafwm; + blit_masktable[hblitsize - 1] &= blt_info.bltalwm; - if (bltbdatptr) { - blt_info.bltbdat = bltbdat = chipmem_agnus_wget (bltbdatptr); - bltbdatptr += 2; - blitbhold = (((uae_u32)prevb << 16) | bltbdat) >> blt_info.blitbshift; - prevb = bltbdat; - } + if (bltcon0 & 0x800) { + bltadatptr = bltapt; + bltapt += (hblitsize * 2 + blt_info.bltamod) * vblitsize; + } + if (bltcon0 & 0x400) { + bltbdatptr = bltbpt; + bltbpt += (hblitsize * 2 + blt_info.bltbmod) * vblitsize; + } + if (bltcon0 & 0x200) { + bltcdatptr = bltcpt; + bltcpt += (hblitsize * 2 + blt_info.bltcmod) * vblitsize; + } + if (bltcon0 & 0x100) { + bltddatptr = bltdpt; + bltdpt += (hblitsize * 2 + blt_info.bltdmod) * vblitsize; + } - if (bltcdatptr) { - blt_info.bltcdat = chipmem_agnus_wget (bltcdatptr); - bltcdatptr += 2; +#ifdef SPEEDUP + if (blitfunc_dofast[mt] && !blitfill) { + (*blitfunc_dofast[mt])(bltadatptr, bltbdatptr, bltcdatptr, bltddatptr, &blt_info); + } else +#endif + { + uae_u32 blitbhold = blt_info.bltbhold; + uae_u32 preva = 0, prevb = 0; + uaecptr dstp = 0; + int dodst = 0; + + /*if (!blitfill) write_log (L"minterm %x not present\n",mt); */ + for (j = 0; j < vblitsize; j++) { + blitfc = !!(bltcon1 & 0x4); + for (i = 0; i < hblitsize; i++) { + uae_u32 bltadat, blitahold; + uae_u16 bltbdat; + if (bltadatptr) { + blt_info.bltadat = bltadat = chipmem_agnus_wget (bltadatptr); + bltadatptr += 2; + } else + bltadat = blt_info.bltadat; + bltadat &= blit_masktable[i]; + blitahold = (((uae_u32)preva << 16) | bltadat) >> blt_info.blitashift; + preva = bltadat; + + if (bltbdatptr) { + blt_info.bltbdat = bltbdat = chipmem_agnus_wget (bltbdatptr); + bltbdatptr += 2; + blitbhold = (((uae_u32)prevb << 16) | bltbdat) >> blt_info.blitbshift; + prevb = bltbdat; + } + + if (bltcdatptr) { + blt_info.bltcdat = chipmem_agnus_wget (bltcdatptr); + bltcdatptr += 2; + } + if (dodst) + chipmem_agnus_wput2 (dstp, blt_info.bltddat); + blt_info.bltddat = blit_func (blitahold, blitbhold, blt_info.bltcdat, mt) & 0xFFFF; + if (blitfill) { + uae_u16 d = blt_info.bltddat; + int ifemode = blitife ? 2 : 0; + int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; + blt_info.bltddat = (blit_filltable[d & 255][ifemode + blitfc][0] + + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); + blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; + } + if (blt_info.bltddat) + blt_info.blitzero = 0; + if (bltddatptr) { + dodst = 1; + dstp = bltddatptr; + bltddatptr += 2; + } + } + if (bltadatptr) + bltadatptr += blt_info.bltamod; + if (bltbdatptr) + bltbdatptr += blt_info.bltbmod; + if (bltcdatptr) + bltcdatptr += blt_info.bltcmod; + if (bltddatptr) + bltddatptr += blt_info.bltdmod; } if (dodst) - chipmem_agnus_wput2 (dstp, blt_info.bltddat); - blt_info.bltddat = blit_func (blitahold, blitbhold, blt_info.bltcdat, mt) & 0xFFFF; - if (blitfill) { - uae_u16 d = blt_info.bltddat; - int ifemode = blitife ? 2 : 0; - int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; - blt_info.bltddat = (blit_filltable[d & 255][ifemode + blitfc][0] - + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); - blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; - } - if (blt_info.bltddat) - blt_info.blitzero = 0; - if (bltddatptr) { - dodst = 1; - dstp = bltddatptr; - bltddatptr += 2; - } - } - if (bltadatptr) - bltadatptr += blt_info.bltamod; - if (bltbdatptr) - bltbdatptr += blt_info.bltbmod; - if (bltcdatptr) - bltcdatptr += blt_info.bltcmod; - if (bltddatptr) - bltddatptr += blt_info.bltdmod; + chipmem_agnus_wput2 (dstp, blt_info.bltddat); + blt_info.bltbhold = blitbhold; } - if (dodst) - chipmem_agnus_wput2 (dstp, blt_info.bltddat); - blt_info.bltbhold = blitbhold; - } - blit_masktable[0] = 0xFFFF; - blit_masktable[hblitsize - 1] = 0xFFFF; - - bltstate = BLT_done; + blit_masktable[0] = 0xFFFF; + blit_masktable[hblitsize - 1] = 0xFFFF; + + bltstate = BLT_done; } static void blitter_dofast_desc (void) { - int i,j; - uaecptr bltadatptr = 0, bltbdatptr = 0, bltcdatptr = 0, bltddatptr = 0; - uae_u8 mt = bltcon0 & 0xFF; - - blit_masktable[0] = blt_info.bltafwm; - blit_masktable[hblitsize - 1] &= blt_info.bltalwm; - - if (bltcon0 & 0x800) { - bltadatptr = bltapt; - bltapt -= (hblitsize*2 + blt_info.bltamod)*vblitsize; - } - if (bltcon0 & 0x400) { - bltbdatptr = bltbpt; - bltbpt -= (hblitsize*2 + blt_info.bltbmod)*vblitsize; - } - if (bltcon0 & 0x200) { - bltcdatptr = bltcpt; - bltcpt -= (hblitsize*2 + blt_info.bltcmod)*vblitsize; - } - if (bltcon0 & 0x100) { - bltddatptr = bltdpt; - bltdpt -= (hblitsize*2 + blt_info.bltdmod)*vblitsize; - } -#ifdef SPEEDUP - if (blitfunc_dofast_desc[mt] && !blitfill) { - (*blitfunc_dofast_desc[mt])(bltadatptr, bltbdatptr, bltcdatptr, bltddatptr, &blt_info); - } else -#endif - { - uae_u32 blitbhold = blt_info.bltbhold; - uae_u32 preva = 0, prevb = 0; - uaecptr dstp = 0; - int dodst = 0; - - for (j = 0; j < vblitsize; j++) { - blitfc = !!(bltcon1 & 0x4); - for (i = 0; i < hblitsize; i++) { - uae_u32 bltadat, blitahold; - uae_u16 bltbdat; - if (bltadatptr) { - bltadat = blt_info.bltadat = chipmem_agnus_wget (bltadatptr); - bltadatptr -= 2; - } else - bltadat = blt_info.bltadat; - bltadat &= blit_masktable[i]; - blitahold = (((uae_u32)bltadat << 16) | preva) >> blt_info.blitdownashift; - preva = bltadat; + int i,j; + uaecptr bltadatptr = 0, bltbdatptr = 0, bltcdatptr = 0, bltddatptr = 0; + uae_u8 mt = bltcon0 & 0xFF; - if (bltbdatptr) { - blt_info.bltbdat = bltbdat = chipmem_agnus_wget (bltbdatptr); - bltbdatptr -= 2; - blitbhold = (((uae_u32)bltbdat << 16) | prevb) >> blt_info.blitdownbshift; - prevb = bltbdat; - } + blit_masktable[0] = blt_info.bltafwm; + blit_masktable[hblitsize - 1] &= blt_info.bltalwm; - if (bltcdatptr) { - blt_info.bltcdat = blt_info.bltbdat = chipmem_agnus_wget (bltcdatptr); - bltcdatptr -= 2; + if (bltcon0 & 0x800) { + bltadatptr = bltapt; + bltapt -= (hblitsize*2 + blt_info.bltamod)*vblitsize; + } + if (bltcon0 & 0x400) { + bltbdatptr = bltbpt; + bltbpt -= (hblitsize*2 + blt_info.bltbmod)*vblitsize; + } + if (bltcon0 & 0x200) { + bltcdatptr = bltcpt; + bltcpt -= (hblitsize*2 + blt_info.bltcmod)*vblitsize; + } + if (bltcon0 & 0x100) { + bltddatptr = bltdpt; + bltdpt -= (hblitsize*2 + blt_info.bltdmod)*vblitsize; + } +#ifdef SPEEDUP + if (blitfunc_dofast_desc[mt] && !blitfill) { + (*blitfunc_dofast_desc[mt])(bltadatptr, bltbdatptr, bltcdatptr, bltddatptr, &blt_info); + } else +#endif + { + uae_u32 blitbhold = blt_info.bltbhold; + uae_u32 preva = 0, prevb = 0; + uaecptr dstp = 0; + int dodst = 0; + + for (j = 0; j < vblitsize; j++) { + blitfc = !!(bltcon1 & 0x4); + for (i = 0; i < hblitsize; i++) { + uae_u32 bltadat, blitahold; + uae_u16 bltbdat; + if (bltadatptr) { + bltadat = blt_info.bltadat = chipmem_agnus_wget (bltadatptr); + bltadatptr -= 2; + } else + bltadat = blt_info.bltadat; + bltadat &= blit_masktable[i]; + blitahold = (((uae_u32)bltadat << 16) | preva) >> blt_info.blitdownashift; + preva = bltadat; + + if (bltbdatptr) { + blt_info.bltbdat = bltbdat = chipmem_agnus_wget (bltbdatptr); + bltbdatptr -= 2; + blitbhold = (((uae_u32)bltbdat << 16) | prevb) >> blt_info.blitdownbshift; + prevb = bltbdat; + } + + if (bltcdatptr) { + blt_info.bltcdat = blt_info.bltbdat = chipmem_agnus_wget (bltcdatptr); + bltcdatptr -= 2; + } + if (dodst) + chipmem_agnus_wput2 (dstp, blt_info.bltddat); + blt_info.bltddat = blit_func (blitahold, blitbhold, blt_info.bltcdat, mt) & 0xFFFF; + if (blitfill) { + uae_u16 d = blt_info.bltddat; + int ifemode = blitife ? 2 : 0; + int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; + blt_info.bltddat = (blit_filltable[d & 255][ifemode + blitfc][0] + + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); + blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; + } + if (blt_info.bltddat) + blt_info.blitzero = 0; + if (bltddatptr) { + dstp = bltddatptr; + dodst = 1; + bltddatptr -= 2; + } + } + if (bltadatptr) + bltadatptr -= blt_info.bltamod; + if (bltbdatptr) + bltbdatptr -= blt_info.bltbmod; + if (bltcdatptr) + bltcdatptr -= blt_info.bltcmod; + if (bltddatptr) + bltddatptr -= blt_info.bltdmod; } if (dodst) - chipmem_agnus_wput2 (dstp, blt_info.bltddat); - blt_info.bltddat = blit_func (blitahold, blitbhold, blt_info.bltcdat, mt) & 0xFFFF; - if (blitfill) { - uae_u16 d = blt_info.bltddat; - int ifemode = blitife ? 2 : 0; - int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; - blt_info.bltddat = (blit_filltable[d & 255][ifemode + blitfc][0] - + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); - blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; - } - if (blt_info.bltddat) - blt_info.blitzero = 0; - if (bltddatptr) { - dstp = bltddatptr; - dodst = 1; - bltddatptr -= 2; - } - } - if (bltadatptr) - bltadatptr -= blt_info.bltamod; - if (bltbdatptr) - bltbdatptr -= blt_info.bltbmod; - if (bltcdatptr) - bltcdatptr -= blt_info.bltcmod; - if (bltddatptr) - bltddatptr -= blt_info.bltdmod; + chipmem_agnus_wput2 (dstp, blt_info.bltddat); + blt_info.bltbhold = blitbhold; } - if (dodst) - chipmem_agnus_wput2 (dstp, blt_info.bltddat); - blt_info.bltbhold = blitbhold; - } - blit_masktable[0] = 0xFFFF; - blit_masktable[hblitsize - 1] = 0xFFFF; - - bltstate = BLT_done; + blit_masktable[0] = 0xFFFF; + blit_masktable[hblitsize - 1] = 0xFFFF; + + bltstate = BLT_done; } STATIC_INLINE void blitter_read (void) { - if (bltcon0 & 0x200) { - if (!dmaen (DMA_BLITTER)) - return; - blt_info.bltcdat = chipmem_bank.wget (bltcpt); - last_custom_value1 = blt_info.bltcdat; - } - bltstate = BLT_work; + if (bltcon0 & 0x200) { + if (!dmaen (DMA_BLITTER)) + return; + blt_info.bltcdat = chipmem_bank.wget (bltcpt); + last_custom_value1 = blt_info.bltcdat; + } + bltstate = BLT_work; } STATIC_INLINE void blitter_write (void) { - if (blt_info.bltddat) - blt_info.blitzero = 0; - /* D-channel state has no effect on linedraw, but C must be enabled or nothing is drawn! */ - if (bltcon0 & 0x200) { - if (!dmaen (DMA_BLITTER)) - return; - last_custom_value1 = blt_info.bltddat; - chipmem_bank.wput (bltdpt, blt_info.bltddat); - } - bltstate = BLT_next; + if (blt_info.bltddat) + blt_info.blitzero = 0; + /* D-channel state has no effect on linedraw, but C must be enabled or nothing is drawn! */ + if (bltcon0 & 0x200) { + if (!dmaen (DMA_BLITTER)) + return; + last_custom_value1 = blt_info.bltddat; + chipmem_bank.wput (bltdpt, blt_info.bltddat); + } + bltstate = BLT_next; } STATIC_INLINE void blitter_line_incx (void) { - if (++blinea_shift == 16) { - blinea_shift = 0; - bltcpt += 2; - } + if (++blinea_shift == 16) { + blinea_shift = 0; + bltcpt += 2; + } } STATIC_INLINE void blitter_line_decx (void) { - if (blinea_shift-- == 0) { - blinea_shift = 15; - bltcpt -= 2; - } + if (blinea_shift-- == 0) { + blinea_shift = 15; + bltcpt -= 2; + } } STATIC_INLINE void blitter_line_decy (void) { - bltcpt -= blt_info.bltcmod; - blitonedot = 0; + bltcpt -= blt_info.bltcmod; + blitonedot = 0; } STATIC_INLINE void blitter_line_incy (void) { - bltcpt += blt_info.bltcmod; - blitonedot = 0; + bltcpt += blt_info.bltcmod; + blitonedot = 0; } static void blitter_line (void) { - uae_u16 blitahold = (blinea & blt_info.bltafwm) >> blinea_shift; - uae_u16 blitbhold = blineb & 1 ? 0xFFFF : 0; - uae_u16 blitchold = blt_info.bltcdat; - - if (blitsing && blitonedot) - blitahold = 0; - blitonedot++; - blt_info.bltddat = blit_func (blitahold, blitbhold, blitchold, bltcon0 & 0xFF); + uae_u16 blitahold = (blinea & blt_info.bltafwm) >> blinea_shift; + uae_u16 blitbhold = blineb & 1 ? 0xFFFF : 0; + uae_u16 blitchold = blt_info.bltcdat; + + if (blitsing && blitonedot) + blitahold = 0; + blitonedot++; + blt_info.bltddat = blit_func (blitahold, blitbhold, blitchold, bltcon0 & 0xFF); } static void blitter_line_proc (void) { - if (!blitsign) { - if (bltcon0 & 0x800) - bltapt += (uae_s16)blt_info.bltamod; + if (!blitsign) { + if (bltcon0 & 0x800) + bltapt += (uae_s16)blt_info.bltamod; + if (bltcon1 & 0x10) { + if (bltcon1 & 0x8) + blitter_line_decy (); + else + blitter_line_incy (); + } else { + if (bltcon1 & 0x8) + blitter_line_decx (); + else + blitter_line_incx (); + } + } else { + if (bltcon0 & 0x800) + bltapt += (uae_s16)blt_info.bltbmod; + } if (bltcon1 & 0x10) { - if (bltcon1 & 0x8) - blitter_line_decy (); - else - blitter_line_incy (); + if (bltcon1 & 0x4) + blitter_line_decx (); + else + blitter_line_incx (); } else { - if (bltcon1 & 0x8) - blitter_line_decx (); - else - blitter_line_incx (); + if (bltcon1 & 0x4) + blitter_line_decy (); + else + blitter_line_incy (); } - } else { - if (bltcon0 & 0x800) - bltapt += (uae_s16)blt_info.bltbmod; - } - if (bltcon1 & 0x10) { - if (bltcon1 & 0x4) - blitter_line_decx (); - else - blitter_line_incx (); - } else { - if (bltcon1 & 0x4) - blitter_line_decy (); - else - blitter_line_incy (); - } - blitsign = 0 > (uae_s16)bltapt; - bltstate = BLT_write; + blitsign = 0 > (uae_s16)bltapt; + bltstate = BLT_write; } STATIC_INLINE void blitter_nxline (void) { - blineb = (blineb << 1) | (blineb >> 15); - vblitsize--; - bltstate = BLT_read; - blit_line_pixel = 0; + blineb = (blineb << 1) | (blineb >> 15); + vblitsize--; + bltstate = BLT_read; + blit_line_pixel = 0; } #ifdef CPUEMU_12 @@ -644,139 +644,139 @@ static int blitter_vcounter1, blitter_vcounter2; static void decide_blitter_line (int hsync, int hpos) { - if (blit_final && vblitsize) - blit_final = 0; - while (last_blitter_hpos < hpos) { - int c = channel_state (blit_cyclecounter); - - for (;;) { - int v = canblit (last_blitter_hpos); - - if (!v) { - blit_misscyclecounter++; - blitter_nasty++; - break; - } - - if ((!dmaen (DMA_BLITTER) || v <= 0) && (c == 3 || c == 4)) { - blit_misscyclecounter++; - blitter_nasty++; - break; - } - - blit_cyclecounter++; - blit_totalcyclecounter++; - - // final 2 idle cycles? - if (blit_final) { - if (blit_cyclecounter > get_ch ()[0]) { - blitter_done (last_blitter_hpos); - return; - } - break; - } - - /* onedot mode and no pixel = bus write access is skipped */ - if (c == 4 && blitsing && blitonedot > 1) { - if (vblitsize == 0) { - bltdpt = bltcpt; - blit_final = 1; - blit_cyclecounter = 0; - } - break; - } - - if (c == 3) { - - blitter_read (); - alloc_cycle_ext (last_blitter_hpos, CYCLE_BLITTER); - record_dma_blit (0x70, blt_info.bltcdat, bltcpt, last_blitter_hpos); - - } else if (c == 5) { - - if (ddat1use) { - bltdpt = bltcpt; - } - ddat1use = 1; - blitter_line (); - blitter_line_proc (); - blitter_nxline (); - - } else if (c == 4) { - - blitter_write (); - alloc_cycle_ext (last_blitter_hpos, CYCLE_BLITTER); - record_dma_blit (0x00, blt_info.bltddat, bltdpt, last_blitter_hpos); - if (vblitsize == 0) { - bltdpt = bltcpt; - blit_final = 1; - blit_cyclecounter = 0; - break; + if (blit_final && vblitsize) + blit_final = 0; + while (last_blitter_hpos < hpos) { + int c = channel_state (blit_cyclecounter); + + for (;;) { + int v = canblit (last_blitter_hpos); + + if (!v) { + blit_misscyclecounter++; + blitter_nasty++; + break; + } + + if ((!dmaen (DMA_BLITTER) || v <= 0) && (c == 3 || c == 4)) { + blit_misscyclecounter++; + blitter_nasty++; + break; + } + + blit_cyclecounter++; + blit_totalcyclecounter++; + + // final 2 idle cycles? + if (blit_final) { + if (blit_cyclecounter > get_ch ()[0]) { + blitter_done (last_blitter_hpos); + return; + } + break; + } + + /* onedot mode and no pixel = bus write access is skipped */ + if (c == 4 && blitsing && blitonedot > 1) { + if (vblitsize == 0) { + bltdpt = bltcpt; + blit_final = 1; + blit_cyclecounter = 0; + } + break; + } + + if (c == 3) { + + blitter_read (); + alloc_cycle_ext (last_blitter_hpos, CYCLE_BLITTER); + record_dma_blit (0x70, blt_info.bltcdat, bltcpt, last_blitter_hpos); + + } else if (c == 5) { + + if (ddat1use) { + bltdpt = bltcpt; + } + ddat1use = 1; + blitter_line (); + blitter_line_proc (); + blitter_nxline (); + + } else if (c == 4) { + + blitter_write (); + alloc_cycle_ext (last_blitter_hpos, CYCLE_BLITTER); + record_dma_blit (0x00, blt_info.bltddat, bltdpt, last_blitter_hpos); + if (vblitsize == 0) { + bltdpt = bltcpt; + blit_final = 1; + blit_cyclecounter = 0; + break; + } + + } + + break; } - - } - - break; + last_blitter_hpos++; } - last_blitter_hpos++; - } - if (hsync) - last_blitter_hpos = 0; + if (hsync) + last_blitter_hpos = 0; } #endif static void actually_do_blit (void) { - if (blitline) { - do { - blitter_read (); - blitter_line (); - blitter_line_proc (); - blitter_write (); - bltdpt = bltcpt; - blitter_nxline (); - if (vblitsize == 0) + if (blitline) { + do { + blitter_read (); + blitter_line (); + blitter_line_proc (); + blitter_write (); + bltdpt = bltcpt; + blitter_nxline (); + if (vblitsize == 0) + bltstate = BLT_done; + } while (bltstate != BLT_done); + } else { + if (blitdesc) + blitter_dofast_desc (); + else + blitter_dofast (); bltstate = BLT_done; - } while (bltstate != BLT_done); - } else { - if (blitdesc) - blitter_dofast_desc (); - else - blitter_dofast (); - bltstate = BLT_done; - } + } } void blitter_handler (uae_u32 data) { - static int blitter_stuck; - - if (!dmaen (DMA_BLITTER)) { - event2_newevent (ev2_blitter, 10); - blitter_stuck++; - if (blitter_stuck < 20000 || !currprefs.immediate_blits) - return; /* gotta come back later. */ - /* "free" blitter in immediate mode if it has been "stuck" ~3 frames - * fixes some JIT game incompatibilities - */ - debugtest (DEBUGTEST_BLITTER, L"force-unstuck!\n"); - } - blitter_stuck = 0; - if (blit_slowdown > 0 && !currprefs.immediate_blits) { - event2_newevent (ev2_blitter, blit_slowdown); - blit_slowdown = -1; - return; - } + static int blitter_stuck; + + if (!dmaen (DMA_BLITTER)) { + event2_newevent (ev2_blitter, 10); + blitter_stuck++; + if (blitter_stuck < 20000 || !currprefs.immediate_blits) + return; /* gotta come back later. */ + /* "free" blitter in immediate mode if it has been "stuck" ~3 frames + * fixes some JIT game incompatibilities + */ + debugtest (DEBUGTEST_BLITTER, L"force-unstuck!\n"); + } + blitter_stuck = 0; + if (blit_slowdown > 0 && !currprefs.immediate_blits) { + event2_newevent (ev2_blitter, blit_slowdown); + blit_slowdown = -1; + return; + } #ifdef BLITTER_DEBUG - if (!blitter_dontdo) - actually_do_blit (); - else - bltstate = BLT_done; + if (!blitter_dontdo) + actually_do_blit (); + else + bltstate = BLT_done; #else - actually_do_blit (); + actually_do_blit (); #endif - blitter_done (current_hpos ()); + blitter_done (current_hpos ()); } #ifdef CPUEMU_12 @@ -784,273 +784,273 @@ void blitter_handler (uae_u32 data) static uae_u32 preva, prevb; STATIC_INLINE uae_u16 blitter_doblit (void) { - uae_u32 blitahold; - uae_u16 bltadat, ddat; - uae_u8 mt = bltcon0 & 0xFF; - - bltadat = blt_info.bltadat; - if (blitter_hcounter1 == 0) - bltadat &= blt_info.bltafwm; - if (blitter_hcounter1 == hblitsize - 1) - bltadat &= blt_info.bltalwm; - if (blitdesc) - blitahold = (((uae_u32)bltadat << 16) | preva) >> blt_info.blitdownashift; - else - blitahold = (((uae_u32)preva << 16) | bltadat) >> blt_info.blitashift; - preva = bltadat; - - ddat = blit_func (blitahold, blt_info.bltbhold, blt_info.bltcdat, mt) & 0xFFFF; - - if (bltcon1 & 0x18) { - uae_u16 d = ddat; - int ifemode = blitife ? 2 : 0; - int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; - ddat = (blit_filltable[d & 255][ifemode + blitfc][0] - + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); - blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; - } - - if (ddat) - blt_info.blitzero = 0; - - return ddat; + uae_u32 blitahold; + uae_u16 bltadat, ddat; + uae_u8 mt = bltcon0 & 0xFF; + + bltadat = blt_info.bltadat; + if (blitter_hcounter1 == 0) + bltadat &= blt_info.bltafwm; + if (blitter_hcounter1 == hblitsize - 1) + bltadat &= blt_info.bltalwm; + if (blitdesc) + blitahold = (((uae_u32)bltadat << 16) | preva) >> blt_info.blitdownashift; + else + blitahold = (((uae_u32)preva << 16) | bltadat) >> blt_info.blitashift; + preva = bltadat; + + ddat = blit_func (blitahold, blt_info.bltbhold, blt_info.bltcdat, mt) & 0xFFFF; + + if (bltcon1 & 0x18) { + uae_u16 d = ddat; + int ifemode = blitife ? 2 : 0; + int fc1 = blit_filltable[d & 255][ifemode + blitfc][1]; + ddat = (blit_filltable[d & 255][ifemode + blitfc][0] + + (blit_filltable[d >> 8][ifemode + fc1][0] << 8)); + blitfc = blit_filltable[d >> 8][ifemode + fc1][1]; + } + + if (ddat) + blt_info.blitzero = 0; + + return ddat; } STATIC_INLINE int blitter_doddma (int hpos) { - int wd; - uae_u16 d; - - wd = 0; - if (blit_dmacount2 == 0) { - d = blitter_doblit (); - wd = -1; - } else if (ddat2use) { - d = ddat2; - ddat2use = 0; - wd = 2; - } else if (ddat1use) { - d = ddat1; - ddat1use = 0; - wd = 1; - } - if (wd) { - alloc_cycle_ext (hpos, CYCLE_BLITTER); - record_dma_blit (0x00, d, bltdpt, hpos); - last_custom_value1 = d; - chipmem_agnus_wput2 (bltdpt, d); - bltdpt += blit_add; - blitter_hcounter2++; - if (blitter_hcounter2 == hblitsize) { - blitter_hcounter2 = 0; - bltdpt += blit_modaddd; - blitter_vcounter2++; - if (blitter_vcounter2 > blitter_vcounter1) - blitter_vcounter1 = blitter_vcounter2; + int wd; + uae_u16 d; + + wd = 0; + if (blit_dmacount2 == 0) { + d = blitter_doblit (); + wd = -1; + } else if (ddat2use) { + d = ddat2; + ddat2use = 0; + wd = 2; + } else if (ddat1use) { + d = ddat1; + ddat1use = 0; + wd = 1; } - if (blit_ch == 1) - blitter_hcounter1 = blitter_hcounter2; - } - return wd; + if (wd) { + alloc_cycle_ext (hpos, CYCLE_BLITTER); + record_dma_blit (0x00, d, bltdpt, hpos); + last_custom_value1 = d; + chipmem_agnus_wput2 (bltdpt, d); + bltdpt += blit_add; + blitter_hcounter2++; + if (blitter_hcounter2 == hblitsize) { + blitter_hcounter2 = 0; + bltdpt += blit_modaddd; + blitter_vcounter2++; + if (blitter_vcounter2 > blitter_vcounter1) + blitter_vcounter1 = blitter_vcounter2; + } + if (blit_ch == 1) + blitter_hcounter1 = blitter_hcounter2; + } + return wd; } STATIC_INLINE void blitter_dodma (int ch, int hpos) { - uae_u16 dat, reg; - uae_u32 addr; + uae_u16 dat, reg; + uae_u32 addr; - switch (ch) - { + switch (ch) + { case 1: - blt_info.bltadat = dat = chipmem_agnus_wget (bltapt); - last_custom_value1 = blt_info.bltadat; - addr = bltapt; - bltapt += blit_add; - reg = 0x74; - break; + blt_info.bltadat = dat = chipmem_agnus_wget (bltapt); + last_custom_value1 = blt_info.bltadat; + addr = bltapt; + bltapt += blit_add; + reg = 0x74; + break; case 2: - blt_info.bltbdat = dat = chipmem_agnus_wget (bltbpt); - last_custom_value1 = blt_info.bltbdat; - addr = bltbpt; - bltbpt += blit_add; - if (blitdesc) - blt_info.bltbhold = (((uae_u32)blt_info.bltbdat << 16) | prevb) >> blt_info.blitdownbshift; - else - blt_info.bltbhold = (((uae_u32)prevb << 16) | blt_info.bltbdat) >> blt_info.blitbshift; - prevb = blt_info.bltbdat; - reg = 0x72; - break; + blt_info.bltbdat = dat = chipmem_agnus_wget (bltbpt); + last_custom_value1 = blt_info.bltbdat; + addr = bltbpt; + bltbpt += blit_add; + if (blitdesc) + blt_info.bltbhold = (((uae_u32)blt_info.bltbdat << 16) | prevb) >> blt_info.blitdownbshift; + else + blt_info.bltbhold = (((uae_u32)prevb << 16) | blt_info.bltbdat) >> blt_info.blitbshift; + prevb = blt_info.bltbdat; + reg = 0x72; + break; case 3: - blt_info.bltcdat = dat = chipmem_agnus_wget (bltcpt); - last_custom_value1 = blt_info.bltcdat; - addr = bltcpt; - bltcpt += blit_add; - reg = 0x70; - break; + blt_info.bltcdat = dat = chipmem_agnus_wget (bltcpt); + last_custom_value1 = blt_info.bltcdat; + addr = bltcpt; + bltcpt += blit_add; + reg = 0x70; + break; default: - abort (); - } - - blitter_cyclecounter++; - if (blitter_cyclecounter >= blit_dmacount2) { - blitter_cyclecounter = 0; - ddat2 = ddat1; - ddat2use = ddat1use; - ddat1use = 0; - ddat1 = blitter_doblit (); - if (bltcon0 & 0x100) - ddat1use = 1; - blitter_hcounter1++; - if (blitter_hcounter1 == hblitsize) { - blitter_hcounter1 = 0; - if (bltcon0 & 0x800) - bltapt += blit_modadda; - if (bltcon0 & 0x400) - bltbpt += blit_modaddb; - if (bltcon0 & 0x200) - bltcpt += blit_modaddc; - blitter_vcounter1++; - blitfc = !!(bltcon1 & 0x4); + abort (); + } + + blitter_cyclecounter++; + if (blitter_cyclecounter >= blit_dmacount2) { + blitter_cyclecounter = 0; + ddat2 = ddat1; + ddat2use = ddat1use; + ddat1use = 0; + ddat1 = blitter_doblit (); + if (bltcon0 & 0x100) + ddat1use = 1; + blitter_hcounter1++; + if (blitter_hcounter1 == hblitsize) { + blitter_hcounter1 = 0; + if (bltcon0 & 0x800) + bltapt += blit_modadda; + if (bltcon0 & 0x400) + bltbpt += blit_modaddb; + if (bltcon0 & 0x200) + bltcpt += blit_modaddc; + blitter_vcounter1++; + blitfc = !!(bltcon1 & 0x4); + } } - } - alloc_cycle_ext (hpos, CYCLE_BLITTER); - record_dma_blit (reg, dat, addr, hpos); + alloc_cycle_ext (hpos, CYCLE_BLITTER); + record_dma_blit (reg, dat, addr, hpos); } int blitter_need (int hpos) { - int c; - if (bltstate == BLT_done) - return 0; - if (!dmaen (DMA_BLITTER)) - return 0; - c = channel_state (blit_cyclecounter); - return c; + int c; + if (bltstate == BLT_done) + return 0; + if (!dmaen (DMA_BLITTER)) + return 0; + c = channel_state (blit_cyclecounter); + return c; } static void do_startcycles (int hpos) { - int vhpos = last_blitter_hpos; - while (vhpos < hpos) { - int v = canblit (vhpos); - vhpos++; - if (v) { - blit_startcycles--; - if (blit_startcycles == 0) { - if (blit_faulty) - blit_faulty = -1; - bltstate = BLT_done; - blit_final = 0; - do_blitter (vhpos, 0); - blit_startcycles = 0; - blit_cyclecounter = 0; - if (blit_faulty) - blit_faulty = 1; - return; - } + int vhpos = last_blitter_hpos; + while (vhpos < hpos) { + int v = canblit (vhpos); + vhpos++; + if (v) { + blit_startcycles--; + if (blit_startcycles == 0) { + if (blit_faulty) + blit_faulty = -1; + bltstate = BLT_done; + blit_final = 0; + do_blitter (vhpos, 0); + blit_startcycles = 0; + blit_cyclecounter = 0; + if (blit_faulty) + blit_faulty = 1; + return; + } + } } - } } void decide_blitter (int hpos) { - int hsync = hpos < 0; + int hsync = hpos < 0; - if (blit_startcycles > 0) - do_startcycles (hpos); + if (blit_startcycles > 0) + do_startcycles (hpos); - if (bltstate == BLT_done || blit_frozen) - return; + if (bltstate == BLT_done || blit_frozen) + return; #ifdef BLITTER_DEBUG - if (blitter_delayed_debug) { - blitter_delayed_debug = 0; - blitter_dump (); - } + if (blitter_delayed_debug) { + blitter_delayed_debug = 0; + blitter_dump (); + } #endif - if (!blitter_cycle_exact) - return; - - if (hpos < 0) - hpos = maxhpos; - - if (blitline) { - blt_info.got_cycle = 1; - decide_blitter_line (hsync, hpos); - return; - } + if (!blitter_cycle_exact) + return; - while (last_blitter_hpos < hpos) { - int c; + if (hpos < 0) + hpos = maxhpos; - c = channel_state (blit_cyclecounter); + if (blitline) { + blt_info.got_cycle = 1; + decide_blitter_line (hsync, hpos); + return; + } - for (;;) { - int v; - - v = canblit (last_blitter_hpos); - - // idle cycles require free bus.. - // (CPU can still use this cycle) - if (c == 0 && v == 0) { - blitter_nasty++; - blit_misscyclecounter++; - break; - } - - if (c == 0) { - blt_info.got_cycle = 1; - blit_cyclecounter++; - if (blit_cyclecounter == 0) - blit_final = 0; - blit_totalcyclecounter++; - /* check if blit with zero channels has ended */ - if (blit_ch == 0 && blit_cyclecounter >= blit_maxcyclecounter) { - blitter_done (last_blitter_hpos); - return; + while (last_blitter_hpos < hpos) { + int c; + + c = channel_state (blit_cyclecounter); + + for (;;) { + int v; + + v = canblit (last_blitter_hpos); + + // idle cycles require free bus.. + // (CPU can still use this cycle) + if (c == 0 && v == 0) { + blitter_nasty++; + blit_misscyclecounter++; + break; + } + + if (c == 0) { + blt_info.got_cycle = 1; + blit_cyclecounter++; + if (blit_cyclecounter == 0) + blit_final = 0; + blit_totalcyclecounter++; + /* check if blit with zero channels has ended */ + if (blit_ch == 0 && blit_cyclecounter >= blit_maxcyclecounter) { + blitter_done (last_blitter_hpos); + return; + } + break; + } + + blitter_nasty++; + + if (!dmaen (DMA_BLITTER) || v <= 0) { + blit_misscyclecounter++; + break; + } + + blt_info.got_cycle = 1; + if (c == 4) { + if (blitter_doddma (last_blitter_hpos)) { + blit_cyclecounter++; + blit_totalcyclecounter++; + } + } else { + if (blitter_vcounter1 < vblitsize) { + blitter_dodma (c, last_blitter_hpos); + } + blit_cyclecounter++; + blit_totalcyclecounter++; + } + + if (blitter_vcounter1 >= vblitsize && blitter_vcounter2 >= vblitsize) { + if (!ddat1use && !ddat2use) { + blitter_done (last_blitter_hpos); + return; + } + } + break; } - break; - } - - blitter_nasty++; - if (!dmaen (DMA_BLITTER) || v <= 0) { - blit_misscyclecounter++; - break; - } - - blt_info.got_cycle = 1; - if (c == 4) { - if (blitter_doddma (last_blitter_hpos)) { - blit_cyclecounter++; - blit_totalcyclecounter++; - } - } else { - if (blitter_vcounter1 < vblitsize) { - blitter_dodma (c, last_blitter_hpos); - } - blit_cyclecounter++; - blit_totalcyclecounter++; - } - - if (blitter_vcounter1 >= vblitsize && blitter_vcounter2 >= vblitsize) { - if (!ddat1use && !ddat2use) { - blitter_done (last_blitter_hpos); - return; + if (!blit_final && blitter_vcounter1 == vblitsize && channel_pos (blit_cyclecounter - 1) == blit_diag[0] - 1) { + blitter_interrupt (last_blitter_hpos, 0); + blit_cyclecounter = 0; + blit_final = 1; } - } - break; + last_blitter_hpos++; } - - if (!blit_final && blitter_vcounter1 == vblitsize && channel_pos (blit_cyclecounter - 1) == blit_diag[0] - 1) { - blitter_interrupt (last_blitter_hpos, 0); - blit_cyclecounter = 0; - blit_final = 1; - } - last_blitter_hpos++; - } - if (hsync) - last_blitter_hpos = 0; + if (hsync) + last_blitter_hpos = 0; } #else void decide_blitter (int hpos) { } @@ -1058,423 +1058,423 @@ void decide_blitter (int hpos) { } static void blitter_force_finish (void) { - uae_u16 odmacon; - if (bltstate == BLT_done) - return; - if (bltstate != BLT_done) { - /* blitter is currently running - * force finish (no blitter state support yet) - */ - odmacon = dmacon; - dmacon |= DMA_MASTER | DMA_BLITTER; - write_log (L"forcing blitter finish\n"); - if (blitter_cycle_exact) { - int rounds = 10000; - while (bltstate != BLT_done && rounds > 0) { - memset (cycle_line, 0, maxhpos); - decide_blitter (maxhpos); - rounds--; - } - if (rounds == 0) - write_log (L"blitter froze!?\n"); - } else { - actually_do_blit (); + uae_u16 odmacon; + if (bltstate == BLT_done) + return; + if (bltstate != BLT_done) { + /* blitter is currently running + * force finish (no blitter state support yet) + */ + odmacon = dmacon; + dmacon |= DMA_MASTER | DMA_BLITTER; + write_log (L"forcing blitter finish\n"); + if (blitter_cycle_exact) { + int rounds = 10000; + while (bltstate != BLT_done && rounds > 0) { + memset (cycle_line, 0, maxhpos); + decide_blitter (maxhpos); + rounds--; + } + if (rounds == 0) + write_log (L"blitter froze!?\n"); + } else { + actually_do_blit (); + } + blitter_done (current_hpos ()); + dmacon = odmacon; } - blitter_done (current_hpos ()); - dmacon = odmacon; - } } static void blit_bltset (int con) { - int i; - const int *olddiag = blit_diag; - - if (con & 2) { - blitdesc = bltcon1 & 2; - blt_info.blitbshift = bltcon1 >> 12; - blt_info.blitdownbshift = 16 - blt_info.blitbshift; - } - - if (con & 1) { - blt_info.blitashift = bltcon0 >> 12; - blt_info.blitdownashift = 16 - blt_info.blitashift; - } - - blit_ch = (bltcon0 & 0x0f00) >> 8; - blitline = bltcon1 & 1; - blitfill = bltcon1 & 0x18; - - if (blitline) { - if (hblitsize != 2) - debugtest (DEBUGTEST_BLITTER, L"weird hblitsize in linemode: %d vsize=%d\n", - hblitsize, vblitsize); - blit_diag = blit_cycle_diagram_line; - } else { + int i; + const int *olddiag = blit_diag; + if (con & 2) { - blitfc = !!(bltcon1 & 0x4); - blitife = bltcon1 & 0x8; - if ((bltcon1 & 0x18) == 0x18) { - debugtest (DEBUGTEST_BLITTER, L"weird fill mode\n"); - blitife = 0; - } + blitdesc = bltcon1 & 2; + blt_info.blitbshift = bltcon1 >> 12; + blt_info.blitdownbshift = 16 - blt_info.blitbshift; + } + + if (con & 1) { + blt_info.blitashift = bltcon0 >> 12; + blt_info.blitdownashift = 16 - blt_info.blitashift; } - if (blitfill && !blitdesc) - debugtest (DEBUGTEST_BLITTER, L"fill without desc\n"); - blit_diag = blitfill && blit_cycle_diagram_fill[blit_ch][0] ? blit_cycle_diagram_fill[blit_ch] : blit_cycle_diagram[blit_ch]; - } - if ((bltcon1 & 0x80) && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - debugtest (DEBUGTEST_BLITTER, L"ECS BLTCON1 DOFF-bit set\n"); - - // on the fly switching fillmode from extra cycle to non-extra: blitter freezes - // non-extra cycle to extra cycle: does not freeze but cycle diagram goes weird, - // extra free cycle changes to another D write.. - // (Absolute Inebriation vector cube inside semi-filled vector object requires freezing blitter.) - if (!savestate_state && bltstate != BLT_done) { - static int freezes = 10; - int isen = blit_diag >= &blit_cycle_diagram_fill[0][0] && blit_diag <= &blit_cycle_diagram_fill[15][0]; - int iseo = olddiag >= &blit_cycle_diagram_fill[0][0] && olddiag <= &blit_cycle_diagram_fill[15][0]; - if (iseo != isen) { - if (freezes > 0) { - write_log (L"BLITTER: on the fly %d (%d) -> %d (%d) switch!\n", original_ch, iseo, blit_ch, isen); - freezes--; - } + + blit_ch = (bltcon0 & 0x0f00) >> 8; + blitline = bltcon1 & 1; + blitfill = bltcon1 & 0x18; + + if (blitline) { + if (hblitsize != 2) + debugtest (DEBUGTEST_BLITTER, L"weird hblitsize in linemode: %d vsize=%d\n", + hblitsize, vblitsize); + blit_diag = blit_cycle_diagram_line; + } else { + if (con & 2) { + blitfc = !!(bltcon1 & 0x4); + blitife = bltcon1 & 0x8; + if ((bltcon1 & 0x18) == 0x18) { + debugtest (DEBUGTEST_BLITTER, L"weird fill mode\n"); + blitife = 0; + } + } + if (blitfill && !blitdesc) + debugtest (DEBUGTEST_BLITTER, L"fill without desc\n"); + blit_diag = blitfill && blit_cycle_diagram_fill[blit_ch][0] ? blit_cycle_diagram_fill[blit_ch] : blit_cycle_diagram[blit_ch]; } - if (iseo && !isen) { - blit_frozen = 1; - } else if (!iseo && isen) { + if ((bltcon1 & 0x80) && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + debugtest (DEBUGTEST_BLITTER, L"ECS BLTCON1 DOFF-bit set\n"); + + // on the fly switching fillmode from extra cycle to non-extra: blitter freezes + // non-extra cycle to extra cycle: does not freeze but cycle diagram goes weird, + // extra free cycle changes to another D write.. + // (Absolute Inebriation vector cube inside semi-filled vector object requires freezing blitter.) + if (!savestate_state && bltstate != BLT_done) { + static int freezes = 10; + int isen = blit_diag >= &blit_cycle_diagram_fill[0][0] && blit_diag <= &blit_cycle_diagram_fill[15][0]; + int iseo = olddiag >= &blit_cycle_diagram_fill[0][0] && olddiag <= &blit_cycle_diagram_fill[15][0]; + if (iseo != isen) { + if (freezes > 0) { + write_log (L"BLITTER: on the fly %d (%d) -> %d (%d) switch!\n", original_ch, iseo, blit_ch, isen); + freezes--; + } + } + if (iseo && !isen) { + blit_frozen = 1; + } else if (!iseo && isen) { #ifdef BLITTER_DEBUG_NOWAIT - write_log (L"BLITTER: on the fly %d (%d) -> %d (%d) switch\n", original_ch, iseo, blit_ch, isen); + write_log (L"BLITTER: on the fly %d (%d) -> %d (%d) switch\n", original_ch, iseo, blit_ch, isen); #endif + } + } + + // on the fly switching from CH=1 to CH=D -> blitter stops writing (Rampage/TEK) + // currently just switch to no-channels mode, better than crashing the demo.. + if (!savestate_state && bltstate != BLT_done) { + static uae_u8 changetable[32 * 32]; + int o = original_ch + (original_fill ? 16 : 0); + int n = blit_ch + (blitfill ? 16 : 0); + if (o != n) { + if (changetable[o * 32 + n] < 10) { + changetable[o * 32 + n]++; + write_log (L"BLITTER: channel mode changed while active (%02X->%02X)\n", o, n); + } + } + if (blit_ch == 13 && original_ch == 1) { + blit_faulty = 1; + } } - } - - // on the fly switching from CH=1 to CH=D -> blitter stops writing (Rampage/TEK) - // currently just switch to no-channels mode, better than crashing the demo.. - if (!savestate_state && bltstate != BLT_done) { - static uae_u8 changetable[32 * 32]; - int o = original_ch + (original_fill ? 16 : 0); - int n = blit_ch + (blitfill ? 16 : 0); - if (o != n) { - if (changetable[o * 32 + n] < 10) { - changetable[o * 32 + n]++; - write_log (L"BLITTER: channel mode changed while active (%02X->%02X)\n", o, n); - } + + if (blit_faulty) { + blit_ch = 0; + blit_diag = blit_cycle_diagram[blit_ch]; } - if (blit_ch == 13 && original_ch == 1) { - blit_faulty = 1; + + blit_dmacount = blit_dmacount2 = 0; + blit_nod = 1; + for (i = 0; i < blit_diag[0]; i++) { + int v = blit_diag[1 + blit_diag[0] + i]; + if (v <= 4) + blit_dmacount++; + if (v > 0 && v < 4) + blit_dmacount2++; + if (v == 4) + blit_nod = 0; } - } - - if (blit_faulty) { - blit_ch = 0; - blit_diag = blit_cycle_diagram[blit_ch]; - } - - blit_dmacount = blit_dmacount2 = 0; - blit_nod = 1; - for (i = 0; i < blit_diag[0]; i++) { - int v = blit_diag[1 + blit_diag[0] + i]; - if (v <= 4) - blit_dmacount++; - if (v > 0 && v < 4) - blit_dmacount2++; - if (v == 4) - blit_nod = 0; - } } static void blit_modset (void) { - int mult; - - blit_add = blitdesc ? -2 : 2; - mult = blitdesc ? -1 : 1; - blit_modadda = mult * blt_info.bltamod; - blit_modaddb = mult * blt_info.bltbmod; - blit_modaddc = mult * blt_info.bltcmod; - blit_modaddd = mult * blt_info.bltdmod; + int mult; + + blit_add = blitdesc ? -2 : 2; + mult = blitdesc ? -1 : 1; + blit_modadda = mult * blt_info.bltamod; + blit_modaddb = mult * blt_info.bltbmod; + blit_modaddc = mult * blt_info.bltcmod; + blit_modaddd = mult * blt_info.bltdmod; } void reset_blit (int bltcon) { - if (bltcon & 1) - blinea_shift = bltcon0 >> 12; - if (bltstate == BLT_done) - return; - if (bltcon) - blit_bltset (bltcon); - blit_modset (); + if (bltcon & 1) + blinea_shift = bltcon0 >> 12; + if (bltstate == BLT_done) + return; + if (bltcon) + blit_bltset (bltcon); + blit_modset (); } static void do_blitter2 (int hpos, int copper) { - int cycles; - int cleanstart; + int cycles; + int cleanstart; #ifdef BLITTER_DEBUG_NOWAIT - if (bltstate != BLT_done) { - if (blit_final) - write_log (L"blitter was already active! PC=%08x\n", M68K_GETPC); - } + if (bltstate != BLT_done) { + if (blit_final) + write_log (L"blitter was already active! PC=%08x\n", M68K_GETPC); + } #endif - cleanstart = 0; - if (bltstate == BLT_done) { - if (blit_faulty > 0) - blit_faulty = 0; - cleanstart = 1; - } - - bltstate = BLT_done; - - hblitsize = blt_info.hblitsize; - vblitsize = blt_info.vblitsize; - blitter_cycle_exact = currprefs.blitter_cycle_exact; - blt_info.blitzero = 1; - preva = 0; - prevb = 0; - blt_info.got_cycle = 0; - blit_frozen = 0; - - blit_firstline_cycles = blit_first_cycle = get_cycles (); - blit_misscyclecounter = 0; - blit_last_cycle = 0; - blit_maxcyclecounter = 0; - last_blitter_hpos = hpos + 1; - blit_cyclecounter = 0; - blit_totalcyclecounter = 0; - - blit_bltset (1 | 2); - blit_modset (); - ddat1use = ddat2use = 0; - blit_interrupt = 0; - - if (blitline) { - blitsing = bltcon1 & 0x2; - blinea = blt_info.bltadat; - blineb = (blt_info.bltbdat >> blt_info.blitbshift) | (blt_info.bltbdat << (16 - blt_info.blitbshift)); - blitsign = bltcon1 & 0x40; - blitonedot = 0; - cycles = vblitsize; - } else { - blit_firstline_cycles = blit_first_cycle + (blit_diag[0] * hblitsize + cpu_cycles) * CYCLE_UNIT; - cycles = vblitsize * hblitsize; - } - - if (cleanstart) { - original_ch = blit_ch; - original_fill = blitfill; - original_line = blitline; - } + cleanstart = 0; + if (bltstate == BLT_done) { + if (blit_faulty > 0) + blit_faulty = 0; + cleanstart = 1; + } + + bltstate = BLT_done; + + hblitsize = blt_info.hblitsize; + vblitsize = blt_info.vblitsize; + blitter_cycle_exact = currprefs.blitter_cycle_exact; + blt_info.blitzero = 1; + preva = 0; + prevb = 0; + blt_info.got_cycle = 0; + blit_frozen = 0; + + blit_firstline_cycles = blit_first_cycle = get_cycles (); + blit_misscyclecounter = 0; + blit_last_cycle = 0; + blit_maxcyclecounter = 0; + last_blitter_hpos = hpos + 1; + blit_cyclecounter = 0; + blit_totalcyclecounter = 0; + + blit_bltset (1 | 2); + blit_modset (); + ddat1use = ddat2use = 0; + blit_interrupt = 0; + + if (blitline) { + blitsing = bltcon1 & 0x2; + blinea = blt_info.bltadat; + blineb = (blt_info.bltbdat >> blt_info.blitbshift) | (blt_info.bltbdat << (16 - blt_info.blitbshift)); + blitsign = bltcon1 & 0x40; + blitonedot = 0; + cycles = vblitsize; + } else { + blit_firstline_cycles = blit_first_cycle + (blit_diag[0] * hblitsize + cpu_cycles) * CYCLE_UNIT; + cycles = vblitsize * hblitsize; + } + + if (cleanstart) { + original_ch = blit_ch; + original_fill = blitfill; + original_line = blitline; + } #ifdef BLITTER_DEBUG - blitter_dontdo = 0; - if (1) { - int ch = 0; - if (blit_ch & 1) - ch++; - if (blit_ch & 2) - ch++; - if (blit_ch & 4) - ch++; - if (blit_ch & 8) - ch++; - write_log (L"blitstart: %dx%d ch=%d %d*%d=%d d=%d f=%02X n=%d pc=%p l=%d dma=%04X\n", - hblitsize, vblitsize, ch, blit_diag[0], cycles, blit_diag[0] * cycles, - blitdesc ? 1 : 0, blitfill, dmaen (DMA_BLITPRI) ? 1 : 0, M68K_GETPC, blitline, dmacon); - blitter_dump (); - } + blitter_dontdo = 0; + if (1) { + int ch = 0; + if (blit_ch & 1) + ch++; + if (blit_ch & 2) + ch++; + if (blit_ch & 4) + ch++; + if (blit_ch & 8) + ch++; + write_log (L"blitstart: %dx%d ch=%d %d*%d=%d d=%d f=%02X n=%d pc=%p l=%d dma=%04X\n", + hblitsize, vblitsize, ch, blit_diag[0], cycles, blit_diag[0] * cycles, + blitdesc ? 1 : 0, blitfill, dmaen (DMA_BLITPRI) ? 1 : 0, M68K_GETPC, blitline, dmacon); + blitter_dump (); + } #endif - bltstate = BLT_init; - blit_slowdown = 0; + bltstate = BLT_init; + blit_slowdown = 0; - unset_special (SPCFLAG_BLTNASTY); - if (dmaen (DMA_BLITPRI)) - set_special (SPCFLAG_BLTNASTY); + unset_special (SPCFLAG_BLTNASTY); + if (dmaen (DMA_BLITPRI)) + set_special (SPCFLAG_BLTNASTY); #if 0 - if (M68K_GETPC >= 0x00070554 && M68K_GETPC <= 0x000706B0) { - blitter_done (); - return; - } - if (M68K_GETPC >= 0x00070838) { - blitter_done (); - return; - } + if (M68K_GETPC >= 0x00070554 && M68K_GETPC <= 0x000706B0) { + blitter_done (); + return; + } + if (M68K_GETPC >= 0x00070838) { + blitter_done (); + return; + } #endif - if (dmaen (DMA_BLITTER)) - bltstate = BLT_work; + if (dmaen (DMA_BLITTER)) + bltstate = BLT_work; - blit_maxcyclecounter = 0x7fffffff; - if (blitter_cycle_exact) { - blitter_hcounter1 = blitter_hcounter2 = 0; - blitter_vcounter1 = blitter_vcounter2 = 0; - if (blit_nod) - blitter_vcounter2 = vblitsize; - blit_cyclecounter = -(BLITTER_STARTUP_CYCLES + (copper ? 1 : 0)); - blit_startcycles = 0; - blit_maxcyclecounter = hblitsize * vblitsize + 2; - return; - } - - if (vblitsize == 0 || (blitline && hblitsize != 2)) { - blitter_done (hpos); - return; - } - - blt_info.got_cycle = 1; - if (currprefs.immediate_blits) - cycles = 1; - - blit_cyclecounter = cycles * (blit_dmacount2 + (blit_nod ? 0 : 1)); - event2_newevent (ev2_blitter, blit_cyclecounter); + blit_maxcyclecounter = 0x7fffffff; + if (blitter_cycle_exact) { + blitter_hcounter1 = blitter_hcounter2 = 0; + blitter_vcounter1 = blitter_vcounter2 = 0; + if (blit_nod) + blitter_vcounter2 = vblitsize; + blit_cyclecounter = -(BLITTER_STARTUP_CYCLES + (copper ? 1 : 0)); + blit_startcycles = 0; + blit_maxcyclecounter = hblitsize * vblitsize + 2; + return; + } + + if (vblitsize == 0 || (blitline && hblitsize != 2)) { + blitter_done (hpos); + return; + } + + blt_info.got_cycle = 1; + if (currprefs.immediate_blits) + cycles = 1; + + blit_cyclecounter = cycles * (blit_dmacount2 + (blit_nod ? 0 : 1)); + event2_newevent (ev2_blitter, blit_cyclecounter); } void do_blitter (int hpos, int copper) { - if (bltstate == BLT_done || !currprefs.blitter_cycle_exact) { - do_blitter2 (hpos, copper); - return; - } - // previous blit may have last write cycle left - // and we must let it finish - blit_startcycles = BLITTER_STARTUP_CYCLES + (copper ? 1 : 0); + if (bltstate == BLT_done || !currprefs.blitter_cycle_exact) { + do_blitter2 (hpos, copper); + return; + } + // previous blit may have last write cycle left + // and we must let it finish + blit_startcycles = BLITTER_STARTUP_CYCLES + (copper ? 1 : 0); } void maybe_blit (int hpos, int hack) { - static int warned = 10; + static int warned = 10; - if (bltstate == BLT_done) - return; - if (savestate_state) - return; + if (bltstate == BLT_done) + return; + if (savestate_state) + return; - if (warned && dmaen (DMA_BLITTER) && blt_info.got_cycle) { - warned--; - debugtest (DEBUGTEST_BLITTER, L"program does not wait for blitter tc=%d\n", - blit_cyclecounter); + if (warned && dmaen (DMA_BLITTER) && blt_info.got_cycle) { + warned--; + debugtest (DEBUGTEST_BLITTER, L"program does not wait for blitter tc=%d\n", + blit_cyclecounter); #ifdef BLITTER_DEBUG - warned = 0; + warned = 0; #endif #ifdef BLITTER_DEBUG_NOWAIT - warned = 10; - write_log (L"program does not wait for blitter PC=%08x\n", M68K_GETPC); - //activate_debugger (); - //blitter_done (hpos); + warned = 10; + write_log (L"program does not wait for blitter PC=%08x\n", M68K_GETPC); + //activate_debugger (); + //blitter_done (hpos); #endif - } + } - if (blitter_cycle_exact) { - decide_blitter (hpos); - goto end; - } + if (blitter_cycle_exact) { + decide_blitter (hpos); + goto end; + } - if (hack == 1 && get_cycles() < blit_firstline_cycles) - goto end; + if (hack == 1 && get_cycles() < blit_firstline_cycles) + goto end; - blitter_handler (0); + blitter_handler (0); end:; #ifdef BLITTER_DEBUG - blitter_delayed_debug = 1; + blitter_delayed_debug = 1; #endif } int blitnasty (void) { - int cycles, ccnt; - if (bltstate == BLT_done) - return 0; - if (!dmaen (DMA_BLITTER)) - return 0; - if (blit_last_cycle >= blit_diag[0] && blit_dmacount == blit_diag[0]) - return 0; - cycles = (get_cycles () - blit_first_cycle) / CYCLE_UNIT; - ccnt = 0; - while (blit_last_cycle < cycles) { - int c = channel_state (blit_last_cycle++); - if (!c) - ccnt++; - } - return ccnt; + int cycles, ccnt; + if (bltstate == BLT_done) + return 0; + if (!dmaen (DMA_BLITTER)) + return 0; + if (blit_last_cycle >= blit_diag[0] && blit_dmacount == blit_diag[0]) + return 0; + cycles = (get_cycles () - blit_first_cycle) / CYCLE_UNIT; + ccnt = 0; + while (blit_last_cycle < cycles) { + int c = channel_state (blit_last_cycle++); + if (!c) + ccnt++; + } + return ccnt; } /* very approximate emulation of blitter slowdown caused by bitplane DMA */ void blitter_slowdown (int ddfstrt, int ddfstop, int totalcycles, int freecycles) { - static int oddfstrt, oddfstop, ototal, ofree; - static int slow; - - if (!totalcycles || ddfstrt < 0 || ddfstop < 0) - return; - if (ddfstrt != oddfstrt || ddfstop != oddfstop || totalcycles != ototal || ofree != freecycles) { - int linecycles = ((ddfstop - ddfstrt + totalcycles - 1) / totalcycles) * totalcycles; - int freelinecycles = ((ddfstop - ddfstrt + totalcycles - 1) / totalcycles) * freecycles; - int dmacycles = (linecycles * blit_dmacount) / blit_diag[0]; - oddfstrt = ddfstrt; - oddfstop = ddfstop; - ototal = totalcycles; - ofree = freecycles; - slow = 0; - if (dmacycles > freelinecycles) - slow = dmacycles - freelinecycles; - } - if (blit_slowdown < 0 || blitline) - return; - blit_slowdown += slow; - blit_misscyclecounter += slow; + static int oddfstrt, oddfstop, ototal, ofree; + static int slow; + + if (!totalcycles || ddfstrt < 0 || ddfstop < 0) + return; + if (ddfstrt != oddfstrt || ddfstop != oddfstop || totalcycles != ototal || ofree != freecycles) { + int linecycles = ((ddfstop - ddfstrt + totalcycles - 1) / totalcycles) * totalcycles; + int freelinecycles = ((ddfstop - ddfstrt + totalcycles - 1) / totalcycles) * freecycles; + int dmacycles = (linecycles * blit_dmacount) / blit_diag[0]; + oddfstrt = ddfstrt; + oddfstop = ddfstop; + ototal = totalcycles; + ofree = freecycles; + slow = 0; + if (dmacycles > freelinecycles) + slow = dmacycles - freelinecycles; + } + if (blit_slowdown < 0 || blitline) + return; + blit_slowdown += slow; + blit_misscyclecounter += slow; } #ifdef SAVESTATE uae_u8 *restore_blitter (uae_u8 *src) { - uae_u32 flags = restore_u32(); - - bltstate = BLT_done; - if (bltstate & 4) { - bltstate = (flags & 1) ? BLT_done : BLT_init; - } - if (flags & 2) { - write_log (L"blitter was force-finished when this statefile was saved\n"); - write_log (L"contact the author if restored program freezes\n"); - } - return src; + uae_u32 flags = restore_u32(); + + bltstate = BLT_done; + if (bltstate & 4) { + bltstate = (flags & 1) ? BLT_done : BLT_init; + } + if (flags & 2) { + write_log (L"blitter was force-finished when this statefile was saved\n"); + write_log (L"contact the author if restored program freezes\n"); + } + return src; } void restore_blitter_finish (void) { - record_dma_reset (); - record_dma_reset (); - blit_interrupt = 1; - if (bltstate == BLT_init) { - write_log (L"blitter was started but DMA was inactive during save\n"); - //do_blitter (0); - } + record_dma_reset (); + record_dma_reset (); + blit_interrupt = 1; + if (bltstate == BLT_init) { + write_log (L"blitter was started but DMA was inactive during save\n"); + //do_blitter (0); + } } uae_u8 *save_blitter (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak,*dst; - int forced; - - forced = 0; - if (bltstate != BLT_done && bltstate != BLT_init) { - write_log (L"blitter is active, forcing immediate finish\n"); - /* blitter is active just now but we don't have blitter state support yet */ - blitter_force_finish (); - forced = 2; - } - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (16); - save_u32 (((bltstate != BLT_done) ? 0 : 1) | forced | 4); - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak,*dst; + int forced; + + forced = 0; + if (bltstate != BLT_done && bltstate != BLT_init) { + write_log (L"blitter is active, forcing immediate finish\n"); + /* blitter is active just now but we don't have blitter state support yet */ + blitter_force_finish (); + forced = 2; + } + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (16); + save_u32 (((bltstate != BLT_done) ? 0 : 1) | forced | 4); + *len = dst - dstbak; + return dstbak; } diff --git a/blkdev.c b/blkdev.c index 264d8214..f0e284bd 100644 --- a/blkdev.c +++ b/blkdev.c @@ -1,9 +1,9 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * lowlevel device glue - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* lowlevel device glue +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -28,236 +28,236 @@ extern struct device_functions devicefunc_win32_ioctl; static void install_driver (int flags) { - int installed = 0; + int installed = 0; - device_func[DF_SCSI] = &devicefunc_win32_aspi; -#ifdef WINDDK - device_func[DF_IOCTL] = &devicefunc_win32_ioctl; - device_func[DF_SCSI] = &devicefunc_win32_spti; - installed = 1; - if (currprefs.win32_uaescsimode == UAESCSI_ADAPTECASPI || - currprefs.win32_uaescsimode == UAESCSI_NEROASPI || - currprefs.win32_uaescsimode == UAESCSI_FROGASPI || - !installed) { device_func[DF_SCSI] = &devicefunc_win32_aspi; - device_func[DF_IOCTL] = 0; - } +#ifdef WINDDK + device_func[DF_IOCTL] = &devicefunc_win32_ioctl; + device_func[DF_SCSI] = &devicefunc_win32_spti; + installed = 1; + if (currprefs.win32_uaescsimode == UAESCSI_ADAPTECASPI || + currprefs.win32_uaescsimode == UAESCSI_NEROASPI || + currprefs.win32_uaescsimode == UAESCSI_FROGASPI || + !installed) { + device_func[DF_SCSI] = &devicefunc_win32_aspi; + device_func[DF_IOCTL] = 0; + } #endif } #endif int sys_command_open (int mode, int unitnum) { - if (mode == DF_SCSI || !have_ioctl) - return device_func[DF_SCSI]->opendev (unitnum); - else - return device_func[DF_IOCTL]->opendev (unitnum); + if (mode == DF_SCSI || !have_ioctl) + return device_func[DF_SCSI]->opendev (unitnum); + else + return device_func[DF_IOCTL]->opendev (unitnum); } void sys_command_close (int mode, int unitnum) { - if (mode == DF_SCSI || !have_ioctl) - device_func[DF_SCSI]->closedev (unitnum); - else - device_func[DF_IOCTL]->closedev (unitnum); + if (mode == DF_SCSI || !have_ioctl) + device_func[DF_SCSI]->closedev (unitnum); + else + device_func[DF_IOCTL]->closedev (unitnum); } void device_func_reset (void) { - initialized = 0; - have_ioctl = 0; + initialized = 0; + have_ioctl = 0; } int device_func_init (int flags) { - int support_scsi = 0, support_ioctl = 0; - int oflags = (flags & DEVICE_TYPE_SCSI) ? 0 : (1 << INQ_ROMD); - - if (initialized) - return initialized; - install_driver (flags); - if (device_func[DF_IOCTL]) - have_ioctl = 1; - else - have_ioctl = 0; - support_scsi = device_func[DF_SCSI]->openbus (oflags) ? 1 : 0; - if (have_ioctl) - support_ioctl = device_func[DF_IOCTL]->openbus (1 << INQ_ROMD) ? 1 : 0; - initialized = 1; - write_log (L"support_scsi = %d support_ioctl = %d\n", support_scsi, support_ioctl); - return (support_scsi ? (1 << DF_SCSI) : 0) | (support_ioctl ? (1 << DF_IOCTL) : 0); + int support_scsi = 0, support_ioctl = 0; + int oflags = (flags & DEVICE_TYPE_SCSI) ? 0 : (1 << INQ_ROMD); + + if (initialized) + return initialized; + install_driver (flags); + if (device_func[DF_IOCTL]) + have_ioctl = 1; + else + have_ioctl = 0; + support_scsi = device_func[DF_SCSI]->openbus (oflags) ? 1 : 0; + if (have_ioctl) + support_ioctl = device_func[DF_IOCTL]->openbus (1 << INQ_ROMD) ? 1 : 0; + initialized = 1; + write_log (L"support_scsi = %d support_ioctl = %d\n", support_scsi, support_ioctl); + return (support_scsi ? (1 << DF_SCSI) : 0) | (support_ioctl ? (1 << DF_IOCTL) : 0); } static int audiostatus (int unitnum) { - uae_u8 cmd[10] = {0x42,2,0x40,1,0,0,0,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; - uae_u8 *p = device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); - if (!p) - return 0; - return p[1]; + uae_u8 cmd[10] = {0x42,2,0x40,1,0,0,0,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; + uae_u8 *p = device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); + if (!p) + return 0; + return p[1]; } /* pause/unpause CD audio */ void sys_command_cd_pause (int mode, int unitnum, int paused) { - if (mode == DF_SCSI || !have_ioctl) { - int as = audiostatus (unitnum); - if ((paused && as == 0x11) && (!paused && as == 0x12)) { - uae_u8 cmd[10] = {0x4b,0,0,0,0,0,0,0,paused?0:1,0}; - device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)); + if (mode == DF_SCSI || !have_ioctl) { + int as = audiostatus (unitnum); + if ((paused && as == 0x11) && (!paused && as == 0x12)) { + uae_u8 cmd[10] = {0x4b,0,0,0,0,0,0,0,paused?0:1,0}; + device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)); + } + return; } - return; - } - device_func[DF_IOCTL]->pause (unitnum, paused); + device_func[DF_IOCTL]->pause (unitnum, paused); } /* stop CD audio */ void sys_command_cd_stop (int mode, int unitnum) { - if (mode == DF_SCSI || !have_ioctl) { - int as = audiostatus (unitnum); - if (as == 0x11) { - uae_u8 cmd[6] = {0x4e,0,0,0,0,0}; - device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)); + if (mode == DF_SCSI || !have_ioctl) { + int as = audiostatus (unitnum); + if (as == 0x11) { + uae_u8 cmd[6] = {0x4e,0,0,0,0,0}; + device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)); + } + return; } - return; - } - device_func[DF_IOCTL]->stop (unitnum); + device_func[DF_IOCTL]->stop (unitnum); } /* play CD audio */ int sys_command_cd_play (int mode, int unitnum,uae_u32 startmsf, uae_u32 endmsf, int scan) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; #if 0 - if (scan) { - cmd[0] = 0xba; - cmd[1] = scan < 0 ? 0x10 : 0x0; - cmd[3] = (uae_u8)(startmsf >> 16); - cmd[4] = (uae_u8)(startmsf >> 8); - cmd[5] = (uae_u8)(startmsf >> 0); - cmd[9] = 0x40; - } else { + if (scan) { + cmd[0] = 0xba; + cmd[1] = scan < 0 ? 0x10 : 0x0; + cmd[3] = (uae_u8)(startmsf >> 16); + cmd[4] = (uae_u8)(startmsf >> 8); + cmd[5] = (uae_u8)(startmsf >> 0); + cmd[9] = 0x40; + } else { #endif - cmd[0] = 0x47; - cmd[3] = (uae_u8)(startmsf >> 16); - cmd[4] = (uae_u8)(startmsf >> 8); - cmd[5] = (uae_u8)(startmsf >> 0); - cmd[6] = (uae_u8)(endmsf >> 16); - cmd[7] = (uae_u8)(endmsf >> 8); - cmd[8] = (uae_u8)(endmsf >> 0); + cmd[0] = 0x47; + cmd[3] = (uae_u8)(startmsf >> 16); + cmd[4] = (uae_u8)(startmsf >> 8); + cmd[5] = (uae_u8)(startmsf >> 0); + cmd[6] = (uae_u8)(endmsf >> 16); + cmd[7] = (uae_u8)(endmsf >> 8); + cmd[8] = (uae_u8)(endmsf >> 0); #if 0 - } + } #endif - return device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)) == 0 ? 0 : 1; - } - return device_func[DF_IOCTL]->play (unitnum, startmsf, endmsf, scan); + return device_func[DF_SCSI]->exec_out (unitnum, cmd, sizeof (cmd)) == 0 ? 0 : 1; + } + return device_func[DF_IOCTL]->play (unitnum, startmsf, endmsf, scan); } /* read qcode */ uae_u8 *sys_command_cd_qcode (int mode, int unitnum) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[10] = {0x42,2,0x40,1,0,0,0,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; - return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); - } - return device_func[DF_IOCTL]->qcode (unitnum); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[10] = {0x42,2,0x40,1,0,0,0,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; + return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); + } + return device_func[DF_IOCTL]->qcode (unitnum); }; /* read table of contents */ uae_u8 *sys_command_cd_toc (int mode, int unitnum) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd [10] = { 0x43,0,2,0,0,0,1,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; - return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof(cmd), 0); - } - return device_func[DF_IOCTL]->toc (unitnum); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd [10] = { 0x43,0,2,0,0,0,1,(uae_u8)(DEVICE_SCSI_BUFSIZE>>8),(uae_u8)(DEVICE_SCSI_BUFSIZE&0xff),0}; + return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof(cmd), 0); + } + return device_func[DF_IOCTL]->toc (unitnum); } /* read one cd sector */ uae_u8 *sys_command_cd_read (int mode, int unitnum, int offset) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; - cmd[3] = (uae_u8)(offset >> 16); - cmd[4] = (uae_u8)(offset >> 8); - cmd[5] = (uae_u8)(offset >> 0); - return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); - } - return device_func[DF_IOCTL]->read (unitnum, offset); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; + cmd[3] = (uae_u8)(offset >> 16); + cmd[4] = (uae_u8)(offset >> 8); + cmd[5] = (uae_u8)(offset >> 0); + return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); + } + return device_func[DF_IOCTL]->read (unitnum, offset); } uae_u8 *sys_command_cd_rawread (int mode, int unitnum, int offset, int size) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; - cmd[3] = (uae_u8)(offset >> 16); - cmd[4] = (uae_u8)(offset >> 8); - cmd[5] = (uae_u8)(offset >> 0); - return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); - } - return device_func[DF_IOCTL]->rawread (unitnum, offset, size); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; + cmd[3] = (uae_u8)(offset >> 16); + cmd[4] = (uae_u8)(offset >> 8); + cmd[5] = (uae_u8)(offset >> 0); + return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); + } + return device_func[DF_IOCTL]->rawread (unitnum, offset, size); } /* read block */ uae_u8 *sys_command_read (int mode, int unitnum, int offset) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[10] = { 0x28, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; - cmd[2] = (uae_u8)(offset >> 24); - cmd[3] = (uae_u8)(offset >> 16); - cmd[4] = (uae_u8)(offset >> 8); - cmd[5] = (uae_u8)(offset >> 0); - return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); - } - return device_func[DF_IOCTL]->read (unitnum, offset); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[10] = { 0x28, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; + cmd[2] = (uae_u8)(offset >> 24); + cmd[3] = (uae_u8)(offset >> 16); + cmd[4] = (uae_u8)(offset >> 8); + cmd[5] = (uae_u8)(offset >> 0); + return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0); + } + return device_func[DF_IOCTL]->read (unitnum, offset); } /* write block */ int sys_command_write (int mode, int unitnum, int offset) { - if (mode == DF_SCSI || !have_ioctl) { - uae_u8 cmd[10] = { 0x2a, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; - cmd[2] = (uae_u8)(offset >> 24); - cmd[3] = (uae_u8)(offset >> 16); - cmd[4] = (uae_u8)(offset >> 8); - cmd[5] = (uae_u8)(offset >> 0); - if (device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0)) - return -1; - return 0; - } - return device_func[DF_IOCTL]->write (unitnum, offset); + if (mode == DF_SCSI || !have_ioctl) { + uae_u8 cmd[10] = { 0x2a, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; + cmd[2] = (uae_u8)(offset >> 24); + cmd[3] = (uae_u8)(offset >> 16); + cmd[4] = (uae_u8)(offset >> 8); + cmd[5] = (uae_u8)(offset >> 0); + if (device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0)) + return -1; + return 0; + } + return device_func[DF_IOCTL]->write (unitnum, offset); } int sys_command_ismedia (int mode, int unitnum, int quick) { - struct device_info di; - - if (mode == DF_SCSI || !have_ioctl || !device_func[DF_IOCTL]->ismedia) { - if (quick) - return -1; - memset(&di, 0, sizeof di); - device_func[DF_SCSI]->info (unitnum, &di); - return di.media_inserted; - } else { - return device_func[DF_IOCTL]->ismedia (unitnum, quick); - } + struct device_info di; + + if (mode == DF_SCSI || !have_ioctl || !device_func[DF_IOCTL]->ismedia) { + if (quick) + return -1; + memset(&di, 0, sizeof di); + device_func[DF_SCSI]->info (unitnum, &di); + return di.media_inserted; + } else { + return device_func[DF_IOCTL]->ismedia (unitnum, quick); + } } struct device_info *sys_command_info (int mode, int unitnum, struct device_info *di) { - if (mode == DF_SCSI || !have_ioctl) - return device_func[DF_SCSI]->info (unitnum, di); - else - return device_func[DF_IOCTL]->info (unitnum, di); + if (mode == DF_SCSI || !have_ioctl) + return device_func[DF_SCSI]->info (unitnum, di); + else + return device_func[DF_IOCTL]->info (unitnum, di); } struct device_scsi_info *sys_command_scsi_info (int mode, int unitnum, struct device_scsi_info *dsi) { - if (mode == DF_SCSI || !have_ioctl) - return device_func[DF_SCSI]->scsiinfo (unitnum, dsi); - else - return device_func[DF_IOCTL]->scsiinfo (unitnum, dsi); + if (mode == DF_SCSI || !have_ioctl) + return device_func[DF_SCSI]->scsiinfo (unitnum, dsi); + else + return device_func[DF_IOCTL]->scsiinfo (unitnum, dsi); } #define MODE_SELECT_6 0x15 @@ -267,161 +267,161 @@ struct device_scsi_info *sys_command_scsi_info (int mode, int unitnum, struct de void scsi_atapi_fixup_pre (uae_u8 *scsi_cmd, int *len, uae_u8 **datap, int *datalenp, int *parm) { - uae_u8 cmd, *p, *data = *datap; - int l, datalen = *datalenp; - - *parm = 0; - cmd = scsi_cmd[0]; - if (cmd != MODE_SELECT_6 && cmd != MODE_SENSE_6) - return; - l = scsi_cmd[4]; - if (l > 4) - l += 4; - scsi_cmd[7] = l >> 8; - scsi_cmd[8] = l; - if (cmd == MODE_SELECT_6) { - scsi_cmd[0] = MODE_SELECT_10; - scsi_cmd[9] = scsi_cmd[5]; - scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = scsi_cmd[6] = 0; - *len = 10; - p = (uae_u8*)xmalloc (8 + datalen + 4); - if (datalen > 4) - memcpy (p + 8, data + 4, datalen - 4); - p[0] = 0; - p[1] = data[0]; - p[2] = data[1]; - p[3] = data[2]; - p[4] = p[5] = p[6] = 0; - p[7] = data[3]; - if (l > 8) - datalen += 4; - *parm = MODE_SELECT_10; - *datap = p; - } else { - scsi_cmd[0] = MODE_SENSE_10; - scsi_cmd[9] = scsi_cmd[5]; - scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = scsi_cmd[6] = 0; - if (l > 8) - datalen += 4; - *datap = (uae_u8*)xmalloc (datalen); - *len = 10; - *parm = MODE_SENSE_10; - } - *datalenp = datalen; + uae_u8 cmd, *p, *data = *datap; + int l, datalen = *datalenp; + + *parm = 0; + cmd = scsi_cmd[0]; + if (cmd != MODE_SELECT_6 && cmd != MODE_SENSE_6) + return; + l = scsi_cmd[4]; + if (l > 4) + l += 4; + scsi_cmd[7] = l >> 8; + scsi_cmd[8] = l; + if (cmd == MODE_SELECT_6) { + scsi_cmd[0] = MODE_SELECT_10; + scsi_cmd[9] = scsi_cmd[5]; + scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = scsi_cmd[6] = 0; + *len = 10; + p = (uae_u8*)xmalloc (8 + datalen + 4); + if (datalen > 4) + memcpy (p + 8, data + 4, datalen - 4); + p[0] = 0; + p[1] = data[0]; + p[2] = data[1]; + p[3] = data[2]; + p[4] = p[5] = p[6] = 0; + p[7] = data[3]; + if (l > 8) + datalen += 4; + *parm = MODE_SELECT_10; + *datap = p; + } else { + scsi_cmd[0] = MODE_SENSE_10; + scsi_cmd[9] = scsi_cmd[5]; + scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = scsi_cmd[6] = 0; + if (l > 8) + datalen += 4; + *datap = (uae_u8*)xmalloc (datalen); + *len = 10; + *parm = MODE_SENSE_10; + } + *datalenp = datalen; } void scsi_atapi_fixup_post (uae_u8 *scsi_cmd, int len, uae_u8 *olddata, uae_u8 *data, int *datalenp, int parm) { - int datalen = *datalenp; - if (!data || !datalen) - return; - if (parm == MODE_SENSE_10) { - olddata[0] = data[1]; - olddata[1] = data[2]; - olddata[2] = data[3]; - olddata[3] = data[7]; - datalen -= 4; - if (datalen > 4) - memcpy (olddata + 4, data + 8, datalen - 4); - *datalenp = datalen; - } + int datalen = *datalenp; + if (!data || !datalen) + return; + if (parm == MODE_SENSE_10) { + olddata[0] = data[1]; + olddata[1] = data[2]; + olddata[2] = data[3]; + olddata[3] = data[7]; + datalen -= 4; + if (datalen > 4) + memcpy (olddata + 4, data + 8, datalen - 4); + *datalenp = datalen; + } } static void scsi_atapi_fixup_inquiry (struct amigascsi *as) { - uae_u8 *scsi_data = as->data; - uae_u32 scsi_len = as->len; - uae_u8 *scsi_cmd = as->cmd; - uae_u8 cmd; - - cmd = scsi_cmd[0]; - /* CDROM INQUIRY: most Amiga programs expect ANSI version == 2 - * (ATAPI normally responds with zero) - */ - if (cmd == 0x12 && scsi_len > 2 && scsi_data) { - uae_u8 per = scsi_data[0]; - uae_u8 b = scsi_data[2]; - /* CDROM and ANSI version == 0 ? */ - if ((per & 31) == 5 && (b & 7) == 0) { - b |= 2; - scsi_data[2] = b; + uae_u8 *scsi_data = as->data; + uae_u32 scsi_len = as->len; + uae_u8 *scsi_cmd = as->cmd; + uae_u8 cmd; + + cmd = scsi_cmd[0]; + /* CDROM INQUIRY: most Amiga programs expect ANSI version == 2 + * (ATAPI normally responds with zero) + */ + if (cmd == 0x12 && scsi_len > 2 && scsi_data) { + uae_u8 per = scsi_data[0]; + uae_u8 b = scsi_data[2]; + /* CDROM and ANSI version == 0 ? */ + if ((per & 31) == 5 && (b & 7) == 0) { + b |= 2; + scsi_data[2] = b; + } } - } } int sys_command_scsi_direct_native(int unitnum, struct amigascsi *as) { - int ret = device_func[DF_SCSI]->exec_direct (unitnum, as); - if (!ret && device_func[DF_SCSI]->isatapi(unitnum)) - scsi_atapi_fixup_inquiry (as); - return ret; + int ret = device_func[DF_SCSI]->exec_direct (unitnum, as); + if (!ret && device_func[DF_SCSI]->isatapi(unitnum)) + scsi_atapi_fixup_inquiry (as); + return ret; } int sys_command_scsi_direct (int unitnum, uaecptr acmd) { - int ret, i; - struct amigascsi as; - uaecptr ap; - addrbank *bank; - - ap = get_long (acmd + 0); - as.len = get_long (acmd + 4); - - bank = &get_mem_bank (ap); - if (!bank || !bank->check(ap, as.len)) - return -5; - as.data = bank->xlateaddr (ap); - - ap = get_long (acmd + 12); - as.cmd_len = get_word (acmd + 16); - for (i = 0; i < as.cmd_len; i++) - as.cmd[i] = get_byte (ap++); - as.flags = get_byte (acmd + 20); - as.sense_len = get_word (acmd + 26); - - ret = sys_command_scsi_direct_native (unitnum, &as); - - put_long (acmd + 8, as.actual); - put_word (acmd + 18, as.cmdactual); - put_byte (acmd + 21, as.status); - put_word (acmd + 28, as.sactual); - - ap = get_long (acmd + 22); - for (i = 0; i < as.sactual; i++) - put_byte (ap, as.sensedata[i]); - - return ret; + int ret, i; + struct amigascsi as; + uaecptr ap; + addrbank *bank; + + ap = get_long (acmd + 0); + as.len = get_long (acmd + 4); + + bank = &get_mem_bank (ap); + if (!bank || !bank->check(ap, as.len)) + return -5; + as.data = bank->xlateaddr (ap); + + ap = get_long (acmd + 12); + as.cmd_len = get_word (acmd + 16); + for (i = 0; i < as.cmd_len; i++) + as.cmd[i] = get_byte (ap++); + as.flags = get_byte (acmd + 20); + as.sense_len = get_word (acmd + 26); + + ret = sys_command_scsi_direct_native (unitnum, &as); + + put_long (acmd + 8, as.actual); + put_word (acmd + 18, as.cmdactual); + put_byte (acmd + 21, as.status); + put_word (acmd + 28, as.sactual); + + ap = get_long (acmd + 22); + for (i = 0; i < as.sactual; i++) + put_byte (ap, as.sensedata[i]); + + return ret; } void scsi_log_before (uae_u8 *cdb, int cdblen, uae_u8 *data, int datalen) { - int i; - for (i = 0; i < cdblen; i++) { - write_log (L"%s%02X", i > 0 ? "." : "", cdb[i]); - } - write_log (L"\n"); - if (data) { - write_log (L"DATAOUT: %d\n", datalen); - for (i = 0; i < datalen && i < 100; i++) - write_log (L"%s%02X", i > 0 ? "." : "", data[i]); - if (datalen > 0) - write_log (L"\n"); - } + int i; + for (i = 0; i < cdblen; i++) { + write_log (L"%s%02X", i > 0 ? "." : "", cdb[i]); + } + write_log (L"\n"); + if (data) { + write_log (L"DATAOUT: %d\n", datalen); + for (i = 0; i < datalen && i < 100; i++) + write_log (L"%s%02X", i > 0 ? "." : "", data[i]); + if (datalen > 0) + write_log (L"\n"); + } } void scsi_log_after (uae_u8 *data, int datalen, uae_u8 *sense, int senselen) { - int i; - write_log (L"DATAIN: %d\n", datalen); - for (i = 0; i < datalen && i < 100 && data; i++) - write_log (L"%s%02X", i > 0 ? "." : "", data[i]); - if (data && datalen > 0) - write_log (L"\n"); - if (senselen > 0) { - write_log (L"SENSE: %d,", senselen); - for (i = 0; i < senselen && i < 32; i++) { - write_log (L"%s%02X", i > 0 ? "." : "", sense[i]); + int i; + write_log (L"DATAIN: %d\n", datalen); + for (i = 0; i < datalen && i < 100 && data; i++) + write_log (L"%s%02X", i > 0 ? "." : "", data[i]); + if (data && datalen > 0) + write_log (L"\n"); + if (senselen > 0) { + write_log (L"SENSE: %d,", senselen); + for (i = 0; i < senselen && i < 32; i++) { + write_log (L"%s%02X", i > 0 ? "." : "", sense[i]); + } + write_log (L"\n"); } - write_log (L"\n"); - } } diff --git a/bsdsocket.c b/bsdsocket.c index 583bb43d..0d4b8129 100644 --- a/bsdsocket.c +++ b/bsdsocket.c @@ -1,12 +1,12 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * bsdsocket.library emulation machine-independent part - * - * Copyright 1997, 1998 Mathias Ortmann - * - * Library initialization code (c) Tauno Taipaleenmaki - */ +/* +* UAE - The Un*x Amiga Emulator +* +* bsdsocket.library emulation machine-independent part +* +* Copyright 1997, 1998 Mathias Ortmann +* +* Library initialization code (c) Tauno Taipaleenmaki +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -33,9 +33,9 @@ static uae_u32 SockLibBase; /* ObtainSocket()/ReleaseSocket() public socket pool */ struct sockd { - long sockpoolids[SOCKPOOLSIZE]; - SOCKET_TYPE sockpoolsocks[SOCKPOOLSIZE]; - uae_u32 sockpoolflags[SOCKPOOLSIZE]; + long sockpoolids[SOCKPOOLSIZE]; + SOCKET_TYPE sockpoolsocks[SOCKPOOLSIZE]; + uae_u32 sockpoolflags[SOCKPOOLSIZE]; }; static long curruniqid = 65536; @@ -43,194 +43,194 @@ static struct sockd *sockdata; uae_u32 strncpyha (uae_u32 dst, const uae_char *src, int size) { - uae_u32 res = dst; - if (!addr_valid (L"strncpyha", dst, size)) + uae_u32 res = dst; + if (!addr_valid (L"strncpyha", dst, size)) + return res; + while (size--) { + put_byte (dst++, *src); + if (!*src++) + return res; + } return res; - while (size--) { - put_byte (dst++, *src); - if (!*src++) - return res; - } - return res; } uae_u32 addstr (uae_u32 * dst, const TCHAR *src) { - uae_u32 res = *dst; - int len; - char *s = ua (src); - len = strlen (s) + 1; - strcpyha_safe (*dst, s); - (*dst) += len; - xfree (s); - return res; + uae_u32 res = *dst; + int len; + char *s = ua (src); + len = strlen (s) + 1; + strcpyha_safe (*dst, s); + (*dst) += len; + xfree (s); + return res; } uae_u32 addstr_ansi (uae_u32 * dst, const uae_char *src) { - uae_u32 res = *dst; - int len; - len = strlen (src) + 1; - strcpyha_safe (*dst, src); - (*dst) += len; - return res; + uae_u32 res = *dst; + int len; + len = strlen (src) + 1; + strcpyha_safe (*dst, src); + (*dst) += len; + return res; } uae_u32 addmem (uae_u32 * dst, const uae_char *src, int len) { - uae_u32 res = *dst; + uae_u32 res = *dst; - if (!src) - return 0; + if (!src) + return 0; - memcpyha_safe (*dst, src, len); - (*dst) += len; + memcpyha_safe (*dst, src, len); + (*dst) += len; - return res; + return res; } /* Get current task */ static uae_u32 gettask (TrapContext *context) { - uae_u32 currtask, a1 = m68k_areg (regs, 1); + uae_u32 currtask, a1 = m68k_areg (regs, 1); - m68k_areg (regs, 1) = 0; - currtask = CallLib (context, get_long (4), -0x126); /* FindTask */ + m68k_areg (regs, 1) = 0; + currtask = CallLib (context, get_long (4), -0x126); /* FindTask */ - m68k_areg (regs, 1) = a1; + m68k_areg (regs, 1) = a1; - BSDTRACE ((L"[%s] ", get_real_address (get_long (currtask + 10)))); - return currtask; + BSDTRACE ((L"[%s] ", get_real_address (get_long (currtask + 10)))); + return currtask; } /* errno/herrno setting */ void bsdsocklib_seterrno (SB, int sb_errno) { - sb->sb_errno = sb_errno; - if (sb->sb_errno >= 1001 && sb->sb_errno <= 1005) - bsdsocklib_setherrno(sb,sb->sb_errno-1000); - if (sb->errnoptr) { - switch (sb->errnosize) { - case 1: - put_byte (sb->errnoptr, sb_errno); - break; - case 2: - put_word (sb->errnoptr, sb_errno); - break; - case 4: - put_long (sb->errnoptr, sb_errno); + sb->sb_errno = sb_errno; + if (sb->sb_errno >= 1001 && sb->sb_errno <= 1005) + bsdsocklib_setherrno(sb,sb->sb_errno-1000); + if (sb->errnoptr) { + switch (sb->errnosize) { + case 1: + put_byte (sb->errnoptr, sb_errno); + break; + case 2: + put_word (sb->errnoptr, sb_errno); + break; + case 4: + put_long (sb->errnoptr, sb_errno); + } } - } } void bsdsocklib_setherrno (SB, int sb_herrno) { - sb->sb_herrno = sb_herrno; - - if (sb->herrnoptr) { - switch (sb->herrnosize) { - case 1: - put_byte (sb->herrnoptr, sb_herrno); - break; - case 2: - put_word (sb->herrnoptr, sb_herrno); - break; - case 4: - put_long (sb->herrnoptr, sb_herrno); + sb->sb_herrno = sb_herrno; + + if (sb->herrnoptr) { + switch (sb->herrnosize) { + case 1: + put_byte (sb->herrnoptr, sb_herrno); + break; + case 2: + put_word (sb->herrnoptr, sb_herrno); + break; + case 4: + put_long (sb->herrnoptr, sb_herrno); + } } - } } BOOL checksd(SB, int sd) { - int iCounter; - SOCKET s; - - s = getsock(sb,sd); - if (s != INVALID_SOCKET) { - for (iCounter = 1; iCounter <= sb->dtablesize; iCounter++) { - if (iCounter != sd) { - if (getsock(sb,iCounter) == s) { - releasesock(sb,sd); - return TRUE; + int iCounter; + SOCKET s; + + s = getsock(sb,sd); + if (s != INVALID_SOCKET) { + for (iCounter = 1; iCounter <= sb->dtablesize; iCounter++) { + if (iCounter != sd) { + if (getsock(sb,iCounter) == s) { + releasesock(sb,sd); + return TRUE; + } + } + } + for (iCounter = 0; iCounter < SOCKPOOLSIZE; iCounter++) { + if (s == sockdata->sockpoolsocks[iCounter]) + return TRUE; } - } - } - for (iCounter = 0; iCounter < SOCKPOOLSIZE; iCounter++) { - if (s == sockdata->sockpoolsocks[iCounter]) - return TRUE; } - } - BSDTRACE((L"checksd FALSE s 0x%x sd %d\n",s,sd)); - return FALSE; + BSDTRACE((L"checksd FALSE s 0x%x sd %d\n",s,sd)); + return FALSE; } void setsd(SB, int sd, SOCKET_TYPE s) { - sb->dtable[sd - 1] = s; + sb->dtable[sd - 1] = s; } /* Socket descriptor/opaque socket handle management */ int getsd (SB, SOCKET_TYPE s) { - int i; - SOCKET_TYPE *dt = sb->dtable; + int i; + SOCKET_TYPE *dt = sb->dtable; - /* return socket descriptor if already exists */ - for (i = sb->dtablesize; i--;) - if (dt[i] == s) - return i + 1; - - /* create new table entry */ - for (i = 0; i < sb->dtablesize; i++) - if (dt[i] == -1) { - dt[i] = s; - sb->ftable[i] = SF_BLOCKING; - return i + 1; + /* return socket descriptor if already exists */ + for (i = sb->dtablesize; i--;) + if (dt[i] == s) + return i + 1; + + /* create new table entry */ + for (i = 0; i < sb->dtablesize; i++) + if (dt[i] == -1) { + dt[i] = s; + sb->ftable[i] = SF_BLOCKING; + return i + 1; } - /* descriptor table full. */ - bsdsocklib_seterrno (sb, 24); /* EMFILE */ + /* descriptor table full. */ + bsdsocklib_seterrno (sb, 24); /* EMFILE */ - return -1; + return -1; } SOCKET_TYPE getsock (SB, int sd) { - if ((unsigned int) (sd - 1) >= (unsigned int) sb->dtablesize) { - BSDTRACE ((L"Invalid Socket Descriptor (%d)\n", sd)); - bsdsocklib_seterrno (sb, 38); /* ENOTSOCK */ - return -1; - } - if (sb->dtable[sd - 1] == INVALID_SOCKET) { - struct socketbase *sb1, *nsb; - uaecptr ot; - if (!addr_valid (L"getsock1", sb->ownertask + 10, 4)) - return -1; - ot = get_long (sb->ownertask + 10); - if (!addr_valid (L"getsock2", ot, 1)) - return -1; - // Fix for Newsrog (All Tasks of Newsrog using the same dtable) - for (sb1 = socketbases; sb1; sb1 = nsb) { - uaecptr ot1; - if (!addr_valid (L"getsock3", sb1->ownertask + 10, 4)) - break; - ot1 = get_long (sb1->ownertask + 10); - if (!addr_valid (L"getsock4", ot1, 1)) - break; - if (strcmp(get_real_address (ot1), get_real_address (ot)) == 0) { - // Task with same name already exists -> use same dtable - if (sb1->dtable[sd - 1] != INVALID_SOCKET) - return sb1->dtable[sd - 1]; - } - nsb = sb1->next; + if ((unsigned int) (sd - 1) >= (unsigned int) sb->dtablesize) { + BSDTRACE ((L"Invalid Socket Descriptor (%d)\n", sd)); + bsdsocklib_seterrno (sb, 38); /* ENOTSOCK */ + return -1; + } + if (sb->dtable[sd - 1] == INVALID_SOCKET) { + struct socketbase *sb1, *nsb; + uaecptr ot; + if (!addr_valid (L"getsock1", sb->ownertask + 10, 4)) + return -1; + ot = get_long (sb->ownertask + 10); + if (!addr_valid (L"getsock2", ot, 1)) + return -1; + // Fix for Newsrog (All Tasks of Newsrog using the same dtable) + for (sb1 = socketbases; sb1; sb1 = nsb) { + uaecptr ot1; + if (!addr_valid (L"getsock3", sb1->ownertask + 10, 4)) + break; + ot1 = get_long (sb1->ownertask + 10); + if (!addr_valid (L"getsock4", ot1, 1)) + break; + if (strcmp(get_real_address (ot1), get_real_address (ot)) == 0) { + // Task with same name already exists -> use same dtable + if (sb1->dtable[sd - 1] != INVALID_SOCKET) + return sb1->dtable[sd - 1]; + } + nsb = sb1->next; + } } - } - return sb->dtable[sd - 1]; + return sb->dtable[sd - 1]; } void releasesock (SB, int sd) { - if ((unsigned int) (sd - 1) < (unsigned int) sb->dtablesize) - sb->dtable[sd - 1] = -1; + if ((unsigned int) (sd - 1) < (unsigned int) sb->dtablesize) + sb->dtable[sd - 1] = -1; } /* Signal queue */ @@ -243,37 +243,37 @@ volatile int bsd_int_requested; void addtosigqueue (SB, int events) { #if 0 - uae_u32 ot, sts; + uae_u32 ot, sts; #endif - locksigqueue (); + locksigqueue (); - if (events) - sb->sigstosend |= sb->eventsigs; - else - sb->sigstosend |= ((uae_u32) 1) << sb->signal; + if (events) + sb->sigstosend |= sb->eventsigs; + else + sb->sigstosend |= ((uae_u32) 1) << sb->signal; #if 1 - if (!sb->dosignal) { - sb->nextsig = sbsigqueue; - sbsigqueue = sb; - } - sb->dosignal = 1; + if (!sb->dosignal) { + sb->nextsig = sbsigqueue; + sbsigqueue = sb; + } + sb->dosignal = 1; - bsd_int_requested = 1; + bsd_int_requested = 1; - unlocksigqueue (); + unlocksigqueue (); #else - ot = sb->ownertask; - sts = sb->sigstosend; + ot = sb->ownertask; + sts = sb->sigstosend; - sb->sigstosend = 0; + sb->sigstosend = 0; - unlocksigqueue (); + unlocksigqueue (); - if (sts) - uae_Signal (ot, sts); + if (sts) + uae_Signal (ot, sts); #endif } @@ -281,828 +281,828 @@ void addtosigqueue (SB, int events) #if 1 void bsdsock_fake_int_handler(void) { - locksigqueue (); + locksigqueue (); - bsd_int_requested = 0; + bsd_int_requested = 0; - if (sbsigqueue != NULL) { - SB; + if (sbsigqueue != NULL) { + SB; - for (sb = sbsigqueue; sb; sb = sb->nextsig) { - if (sb->dosignal == 1) { - uae_Signal (sb->ownertask, sb->sigstosend); - sb->sigstosend = 0; - } - sb->dosignal = 0; - } + for (sb = sbsigqueue; sb; sb = sb->nextsig) { + if (sb->dosignal == 1) { + uae_Signal (sb->ownertask, sb->sigstosend); + sb->sigstosend = 0; + } + sb->dosignal = 0; + } - sbsigqueue = NULL; - } + sbsigqueue = NULL; + } - unlocksigqueue (); + unlocksigqueue (); } #else static uae_u32 REGPARAM2 bsdsock_int_handler (TrapContext *context) { - SB; - - locksigqueue (); - bsd_int_requested = 0; + SB; - if (sbsigqueue != NULL) { + locksigqueue (); + bsd_int_requested = 0; + + if (sbsigqueue != NULL) { + + for (sb = sbsigqueue; sb; sb = sb->nextsig) { + if (sb->dosignal == 1) { + struct regstruct sbved_regs = context->regs; + m68k_areg (regs, 1) = sb->ownertask; + m68k_dreg (regs, 0) = sb->sigstosend; + CallLib (context, get_long (4), -0x144); /* Signal() */ + context->regs = sbved_regs; + sb->sigstosend = 0; + } + sb->dosignal = 0; + } - for (sb = sbsigqueue; sb; sb = sb->nextsig) { - if (sb->dosignal == 1) { - struct regstruct sbved_regs = context->regs; - m68k_areg (regs, 1) = sb->ownertask; - m68k_dreg (regs, 0) = sb->sigstosend; - CallLib (context, get_long (4), -0x144); /* Signal() */ - context->regs = sbved_regs; - sb->sigstosend = 0; - } - sb->dosignal = 0; + sbsigqueue = NULL; } - sbsigqueue = NULL; - } - - unlocksigqueue (); + unlocksigqueue (); - return 0; + return 0; } #endif void waitsig (TrapContext *context, SB) { - long sigs; - m68k_dreg (regs, 0) = (((uae_u32) 1) << sb->signal) | sb->eintrsigs; - if ((sigs = CallLib (context, get_long (4), -0x13e)) & sb->eintrsigs) { /* Wait */ - sockabort (sb); - bsdsocklib_seterrno (sb, 4); /* EINTR */ + long sigs; + m68k_dreg (regs, 0) = (((uae_u32) 1) << sb->signal) | sb->eintrsigs; + if ((sigs = CallLib (context, get_long (4), -0x13e)) & sb->eintrsigs) { /* Wait */ + sockabort (sb); + bsdsocklib_seterrno (sb, 4); /* EINTR */ - // Set signal - m68k_dreg (regs, 0) = sigs; - m68k_dreg (regs, 1) = sb->eintrsigs; - sigs = CallLib (context, get_long (4), -0x132); /* SetSignal() */ + // Set signal + m68k_dreg (regs, 0) = sigs; + m68k_dreg (regs, 1) = sb->eintrsigs; + sigs = CallLib (context, get_long (4), -0x132); /* SetSignal() */ - sb->eintr = 1; - } else - sb->eintr = 0; + sb->eintr = 1; + } else + sb->eintr = 0; } void cancelsig (TrapContext *context, SB) { #if 1 - locksigqueue (); - if (sb->dosignal) - sb->dosignal = 2; - unlocksigqueue (); + locksigqueue (); + if (sb->dosignal) + sb->dosignal = 2; + unlocksigqueue (); #endif - m68k_dreg (regs, 0) = 0; - m68k_dreg (regs, 1) = ((uae_u32) 1) << sb->signal; - CallLib (context, get_long (4), -0x132); /* SetSignal() */ + m68k_dreg (regs, 0) = 0; + m68k_dreg (regs, 1) = ((uae_u32) 1) << sb->signal; + CallLib (context, get_long (4), -0x132); /* SetSignal() */ } /* Allocate and initialize per-task state structure */ static struct socketbase *alloc_socketbase (TrapContext *context) { - SB; - int i; + SB; + int i; - if ((sb = (struct socketbase*)calloc (sizeof (struct socketbase), 1)) != NULL) { - sb->ownertask = gettask (context); + if ((sb = (struct socketbase*)calloc (sizeof (struct socketbase), 1)) != NULL) { + sb->ownertask = gettask (context); - m68k_dreg (regs, 0) = -1; - sb->signal = CallLib (context, get_long (4), -0x14A); /* AllocSignal */ + m68k_dreg (regs, 0) = -1; + sb->signal = CallLib (context, get_long (4), -0x14A); /* AllocSignal */ - if (sb->signal == -1) { - write_log (L"bsdsocket: ERROR: Couldn't allocate signal for task 0x%lx.\n", sb->ownertask); - free (sb); - return NULL; - } - m68k_dreg (regs, 0) = SCRATCHBUFSIZE; - m68k_dreg (regs, 1) = 0; + if (sb->signal == -1) { + write_log (L"bsdsocket: ERROR: Couldn't allocate signal for task 0x%lx.\n", sb->ownertask); + free (sb); + return NULL; + } + m68k_dreg (regs, 0) = SCRATCHBUFSIZE; + m68k_dreg (regs, 1) = 0; - sb->dtablesize = DEFAULT_DTABLE_SIZE; - /* @@@ check malloc() result */ - sb->dtable = (SOCKET*)malloc (sb->dtablesize * sizeof (*sb->dtable)); - sb->ftable = (int*)malloc (sb->dtablesize * sizeof (*sb->ftable)); + sb->dtablesize = DEFAULT_DTABLE_SIZE; + /* @@@ check malloc() result */ + sb->dtable = (SOCKET*)malloc (sb->dtablesize * sizeof (*sb->dtable)); + sb->ftable = (int*)malloc (sb->dtablesize * sizeof (*sb->ftable)); - for (i = sb->dtablesize; i--;) - sb->dtable[i] = -1; + for (i = sb->dtablesize; i--;) + sb->dtable[i] = -1; - sb->eintrsigs = 0x1000; /* SIGBREAKF_CTRL_C */ + sb->eintrsigs = 0x1000; /* SIGBREAKF_CTRL_C */ - if (!host_sbinit (context, sb)) { - /* @@@ free everything */ - } + if (!host_sbinit (context, sb)) { + /* @@@ free everything */ + } - locksigqueue(); + locksigqueue(); - if (socketbases) - sb->next = socketbases; - socketbases = sb; + if (socketbases) + sb->next = socketbases; + socketbases = sb; - unlocksigqueue(); + unlocksigqueue(); - return sb; - } - return NULL; + return sb; + } + return NULL; } STATIC_INLINE struct socketbase *get_socketbase (TrapContext *context) { - return (struct socketbase*)get_pointer (m68k_areg (regs, 6) + offsetof (struct UAEBSDBase, sb)); + return (struct socketbase*)get_pointer (m68k_areg (regs, 6) + offsetof (struct UAEBSDBase, sb)); } static void free_socketbase (TrapContext *context) { - struct socketbase *sb, *nsb; + struct socketbase *sb, *nsb; - if ((sb = get_socketbase (context)) != NULL) { - m68k_dreg (regs, 0) = sb->signal; - CallLib (context, get_long (4), -0x150); /* FreeSignal */ + if ((sb = get_socketbase (context)) != NULL) { + m68k_dreg (regs, 0) = sb->signal; + CallLib (context, get_long (4), -0x150); /* FreeSignal */ - if (sb->hostent) { - m68k_areg (regs, 1) = sb->hostent; - m68k_dreg (regs, 0) = sb->hostentsize; - CallLib (context, get_long (4), -0xD2); /* FreeMem */ + if (sb->hostent) { + m68k_areg (regs, 1) = sb->hostent; + m68k_dreg (regs, 0) = sb->hostentsize; + CallLib (context, get_long (4), -0xD2); /* FreeMem */ - } - if (sb->protoent) { - m68k_areg (regs, 1) = sb->protoent; - m68k_dreg (regs, 0) = sb->protoentsize; - CallLib (context, get_long (4), -0xD2); /* FreeMem */ + } + if (sb->protoent) { + m68k_areg (regs, 1) = sb->protoent; + m68k_dreg (regs, 0) = sb->protoentsize; + CallLib (context, get_long (4), -0xD2); /* FreeMem */ - } - if (sb->servent) { - m68k_areg (regs, 1) = sb->servent; - m68k_dreg (regs, 0) = sb->serventsize; - CallLib (context, get_long (4), -0xD2); /* FreeMem */ + } + if (sb->servent) { + m68k_areg (regs, 1) = sb->servent; + m68k_dreg (regs, 0) = sb->serventsize; + CallLib (context, get_long (4), -0xD2); /* FreeMem */ - } - host_sbcleanup (sb); + } + host_sbcleanup (sb); - free (sb->dtable); - free (sb->ftable); + free (sb->dtable); + free (sb->ftable); - locksigqueue (); + locksigqueue (); - if (sb == socketbases) - socketbases = sb->next; - else { - for (nsb = socketbases; nsb; nsb = nsb->next) { - if (sb == nsb->next) { - nsb->next = sb->next; - break; + if (sb == socketbases) + socketbases = sb->next; + else { + for (nsb = socketbases; nsb; nsb = nsb->next) { + if (sb == nsb->next) { + nsb->next = sb->next; + break; + } + } } - } - } #if 1 - if (sb == sbsigqueue) - sbsigqueue = sb->next; - else { - for (nsb = sbsigqueue; nsb; nsb = nsb->next) { - if (sb == nsb->next) { - nsb->next = sb->next; - break; + if (sb == sbsigqueue) + sbsigqueue = sb->next; + else { + for (nsb = sbsigqueue; nsb; nsb = nsb->next) { + if (sb == nsb->next) { + nsb->next = sb->next; + break; + } + } } - } - } #endif - unlocksigqueue (); + unlocksigqueue (); - free (sb); - } + free (sb); + } } static uae_u32 REGPARAM2 bsdsocklib_Expunge (TrapContext *context) { - BSDTRACE ((L"Expunge() -> [ignored]\n")); - return 0; + BSDTRACE ((L"Expunge() -> [ignored]\n")); + return 0; } static uae_u32 functable, datatable, inittable; static uae_u32 REGPARAM2 bsdsocklib_Open (TrapContext *context) { - uae_u32 result = 0; - int opencount; - SB; + uae_u32 result = 0; + int opencount; + SB; - BSDTRACE ((L"OpenLibrary() -> ")); + BSDTRACE ((L"OpenLibrary() -> ")); - if ((sb = alloc_socketbase (context)) != NULL) { - put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) + 1); + if ((sb = alloc_socketbase (context)) != NULL) { + put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) + 1); - m68k_areg (regs, 0) = functable; - m68k_areg (regs, 1) = datatable; - m68k_areg (regs, 2) = 0; - m68k_dreg (regs, 0) = sizeof (struct UAEBSDBase); - m68k_dreg (regs, 1) = 0; - result = CallLib (context, get_long (4), -0x54); /* MakeLibrary */ + m68k_areg (regs, 0) = functable; + m68k_areg (regs, 1) = datatable; + m68k_areg (regs, 2) = 0; + m68k_dreg (regs, 0) = sizeof (struct UAEBSDBase); + m68k_dreg (regs, 1) = 0; + result = CallLib (context, get_long (4), -0x54); /* MakeLibrary */ - put_pointer (result + offsetof (struct UAEBSDBase, sb), sb); + put_pointer (result + offsetof (struct UAEBSDBase, sb), sb); - BSDTRACE ((L"%0lx [%d]\n", result, opencount)); - } else - BSDTRACE ((L"failed (out of memory)\n")); + BSDTRACE ((L"%0lx [%d]\n", result, opencount)); + } else + BSDTRACE ((L"failed (out of memory)\n")); - return result; + return result; } static uae_u32 REGPARAM2 bsdsocklib_Close (TrapContext *context) { - int opencount; + int opencount; - uae_u32 base = m68k_areg (regs, 6); - uae_u32 negsize = get_word (base + 16); + uae_u32 base = m68k_areg (regs, 6); + uae_u32 negsize = get_word (base + 16); - free_socketbase (context); + free_socketbase (context); - put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) - 1); + put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) - 1); - m68k_areg (regs, 1) = base - negsize; - m68k_dreg (regs, 0) = negsize + get_word (base + 18); - CallLib (context, get_long (4), -0xD2); /* FreeMem */ + m68k_areg (regs, 1) = base - negsize; + m68k_dreg (regs, 0) = negsize + get_word (base + 18); + CallLib (context, get_long (4), -0xD2); /* FreeMem */ - BSDTRACE ((L"CloseLibrary() -> [%d]\n", opencount)); + BSDTRACE ((L"CloseLibrary() -> [%d]\n", opencount)); - return 0; + return 0; } /* socket(domain, type, protocol)(d0/d1/d2) */ static uae_u32 REGPARAM2 bsdsocklib_socket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_socket (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), - m68k_dreg (regs, 2)); + struct socketbase *sb = get_socketbase (context); + return host_socket (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), + m68k_dreg (regs, 2)); } /* bind(s, name, namelen)(d0/a0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_bind (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_bind (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), - m68k_dreg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_bind (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), + m68k_dreg (regs, 1)); } /* listen(s, backlog)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_listen (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_listen (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_listen (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); } /* accept(s, addr, addrlen)(d0/a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_accept (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_accept (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_accept (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); + return sb->resultval; } /* connect(s, name, namelen)(d0/a0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_connect (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_connect (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1)); - return sb->sb_errno ? -1 : 0; + struct socketbase *sb = get_socketbase (context); + host_connect (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1)); + return sb->sb_errno ? -1 : 0; } /* sendto(s, msg, len, flags, to, tolen)(d0/a0/d1/d2/a1/d3) */ static uae_u32 REGPARAM2 bsdsocklib_sendto (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_sendto (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), - m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_dreg (regs, 3)); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_sendto (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), + m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_dreg (regs, 3)); + return sb->resultval; } /* send(s, msg, len, flags)(d0/a0/d1/d2) */ static uae_u32 REGPARAM2 bsdsocklib_send (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_sendto (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), - m68k_dreg (regs, 2), 0, 0); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_sendto (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), + m68k_dreg (regs, 2), 0, 0); + return sb->resultval; } /* recvfrom(s, buf, len, flags, from, fromlen)(d0/a0/d1/d2/a1/a2) */ static uae_u32 REGPARAM2 bsdsocklib_recvfrom (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_recvfrom (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), - m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_areg (regs, 2)); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_recvfrom (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), + m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_areg (regs, 2)); + return sb->resultval; } /* recv(s, buf, len, flags)(d0/a0/d1/d2) */ static uae_u32 REGPARAM2 bsdsocklib_recv (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_recvfrom (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), - m68k_dreg (regs, 2), 0, 0); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_recvfrom (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1), + m68k_dreg (regs, 2), 0, 0); + return sb->resultval; } /* shutdown(s, how)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_shutdown (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_shutdown (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_shutdown (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); } /* setsockopt(s, level, optname, optval, optlen)(d0/d1/d2/a0/d3) */ static uae_u32 REGPARAM2 bsdsocklib_setsockopt (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_setsockopt (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), - m68k_areg (regs, 0), m68k_dreg (regs, 3)); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_setsockopt (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), + m68k_areg (regs, 0), m68k_dreg (regs, 3)); + return sb->resultval; } /* getsockopt(s, level, optname, optval, optlen)(d0/d1/d2/a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_getsockopt (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_getsockopt (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), - m68k_areg (regs, 0), m68k_areg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_getsockopt (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), + m68k_areg (regs, 0), m68k_areg (regs, 1)); } /* getsockname(s, hostname, namelen)(d0/a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_getsockname (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_getsockname (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_getsockname (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); } /* getpeername(s, hostname, namelen)(d0/a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_getpeername (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_getpeername (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_getpeername (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1)); } /* *------ generic system calls related to sockets */ /* IoctlSocket(d, request, argp)(d0/d1/a0) */ static uae_u32 REGPARAM2 bsdsocklib_IoctlSocket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_IoctlSocket (context, sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_areg (regs, 0)); + struct socketbase *sb = get_socketbase (context); + return host_IoctlSocket (context, sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_areg (regs, 0)); } /* *------ AmiTCP/IP specific stuff */ /* CloseSocket(d)(d0) */ static uae_u32 REGPARAM2 bsdsocklib_CloseSocket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_CloseSocket (context, sb, m68k_dreg (regs, 0)); + struct socketbase *sb = get_socketbase (context); + return host_CloseSocket (context, sb, m68k_dreg (regs, 0)); } /* WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp)(d0/a0/a1/a2/a3/d1) */ static uae_u32 REGPARAM2 bsdsocklib_WaitSelect (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_WaitSelect (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1), - m68k_areg (regs, 2), m68k_areg (regs, 3), m68k_dreg (regs, 1)); - return sb->resultval; + struct socketbase *sb = get_socketbase (context); + host_WaitSelect (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1), + m68k_areg (regs, 2), m68k_areg (regs, 3), m68k_dreg (regs, 1)); + return sb->resultval; } /* SetSocketSignals(SIGINTR, SIGIO, SIGURG)(d0/d1/d2) */ static uae_u32 REGPARAM2 bsdsocklib_SetSocketSignals (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); + struct socketbase *sb = get_socketbase (context); - BSDTRACE ((L"SetSocketSignals(0x%08lx,0x%08lx,0x%08lx) -> ", m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2))); - sb->eintrsigs = m68k_dreg (regs, 0); - sb->eventsigs = m68k_dreg (regs, 1); + BSDTRACE ((L"SetSocketSignals(0x%08lx,0x%08lx,0x%08lx) -> ", m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2))); + sb->eintrsigs = m68k_dreg (regs, 0); + sb->eventsigs = m68k_dreg (regs, 1); - return 0; + return 0; } /* SetDTableSize(size)(d0) */ static uae_u32 bsdsocklib_SetDTableSize (SB, int newSize) { - int *newdtable; - int *newftable; - int *newmtable; - int i; + int *newdtable; + int *newftable; + int *newmtable; + int i; - if (newSize < sb->dtablesize) { - /* I don't support lowering the size */ - return 0; - } - - newdtable = (int *)calloc(newSize, sizeof(*sb->dtable)); - newftable = (int *)calloc(newSize, sizeof(*sb->ftable)); - newmtable = (int *)calloc(newSize, sizeof(*sb->mtable)); - - if (newdtable == NULL || newftable == NULL || newmtable == NULL) { - sb->resultval = -1; - bsdsocklib_seterrno(sb, ENOMEM); - free (newdtable); - free (newftable); - free (newmtable); - return -1; - } + if (newSize < sb->dtablesize) { + /* I don't support lowering the size */ + return 0; + } - memcpy(newdtable, sb->dtable, sb->dtablesize * sizeof(*sb->dtable)); - memcpy(newftable, sb->ftable, sb->dtablesize * sizeof(*sb->ftable)); - memcpy(newmtable, sb->mtable, sb->dtablesize * sizeof(*sb->mtable)); - for (i = sb->dtablesize + 1; i < newSize; i++) - newdtable[i] = -1; + newdtable = (int *)calloc(newSize, sizeof(*sb->dtable)); + newftable = (int *)calloc(newSize, sizeof(*sb->ftable)); + newmtable = (int *)calloc(newSize, sizeof(*sb->mtable)); - sb->dtablesize = newSize; - free(sb->dtable); - free(sb->ftable); - free(sb->mtable); - sb->dtable = (SOCKET*)newdtable; - sb->ftable = newftable; - sb->mtable = newmtable; - sb->resultval = 0; - return 0; + if (newdtable == NULL || newftable == NULL || newmtable == NULL) { + sb->resultval = -1; + bsdsocklib_seterrno(sb, ENOMEM); + free (newdtable); + free (newftable); + free (newmtable); + return -1; + } + + memcpy(newdtable, sb->dtable, sb->dtablesize * sizeof(*sb->dtable)); + memcpy(newftable, sb->ftable, sb->dtablesize * sizeof(*sb->ftable)); + memcpy(newmtable, sb->mtable, sb->dtablesize * sizeof(*sb->mtable)); + for (i = sb->dtablesize + 1; i < newSize; i++) + newdtable[i] = -1; + + sb->dtablesize = newSize; + free(sb->dtable); + free(sb->ftable); + free(sb->mtable); + sb->dtable = (SOCKET*)newdtable; + sb->ftable = newftable; + sb->mtable = newmtable; + sb->resultval = 0; + return 0; } static int sockpoolindex (long id) { - int i; + int i; - for (i = 0; i < SOCKPOOLSIZE; i++) - if (sockdata->sockpoolids[i] == id) - return i; + for (i = 0; i < SOCKPOOLSIZE; i++) + if (sockdata->sockpoolids[i] == id) + return i; - return -1; + return -1; } /* ObtainSocket(id, domain, type, protocol)(d0/d1/d2/d3) */ static uae_u32 REGPARAM2 bsdsocklib_ObtainSocket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - int sd; - long id; - SOCKET_TYPE s; - int i; + struct socketbase *sb = get_socketbase (context); + int sd; + long id; + SOCKET_TYPE s; + int i; - id = m68k_dreg (regs, 0); + id = m68k_dreg (regs, 0); - BSDTRACE ((L"ObtainSocket(%d,%d,%d,%d) -> ", id, m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3))); + BSDTRACE ((L"ObtainSocket(%d,%d,%d,%d) -> ", id, m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3))); - i = sockpoolindex (id); + i = sockpoolindex (id); - if (i == -1) { - BSDTRACE ((L"[invalid key]\n")); - return -1; - } - s = sockdata->sockpoolsocks[i]; + if (i == -1) { + BSDTRACE ((L"[invalid key]\n")); + return -1; + } + s = sockdata->sockpoolsocks[i]; - sd = getsd (sb, s); + sd = getsd (sb, s); - BSDTRACE ((L"%d\n", sd)); + BSDTRACE ((L"%d\n", sd)); - if (sd != -1) { - sb->ftable[sd - 1] = sockdata->sockpoolflags[i]; - sockdata->sockpoolids[i] = UNIQUE_ID; - return sd - 1; - } + if (sd != -1) { + sb->ftable[sd - 1] = sockdata->sockpoolflags[i]; + sockdata->sockpoolids[i] = UNIQUE_ID; + return sd - 1; + } - return -1; + return -1; } /* ReleaseSocket(fd, id)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_ReleaseSocket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - int sd; - long id; - SOCKET_TYPE s; - int i; - uae_u32 flags; + struct socketbase *sb = get_socketbase (context); + int sd; + long id; + SOCKET_TYPE s; + int i; + uae_u32 flags; - sd = m68k_dreg (regs, 0); - id = m68k_dreg (regs, 1); + sd = m68k_dreg (regs, 0); + id = m68k_dreg (regs, 1); - sd++; - BSDTRACE ((L"ReleaseSocket(%d,%d) -> ", sd, id)); + sd++; + BSDTRACE ((L"ReleaseSocket(%d,%d) -> ", sd, id)); - s = getsock (sb, sd); + s = getsock (sb, sd); - if (s != -1) { - flags = sb->ftable[sd - 1]; + if (s != -1) { + flags = sb->ftable[sd - 1]; - if (flags & REP_ALL) { - write_log (L"bsdsocket: ERROR: ReleaseSocket() is not supported for sockets with async event notification enabled!\n"); - return -1; - } - releasesock (sb, sd); - - if (id == UNIQUE_ID) { - for (;;) { - if (sockpoolindex (curruniqid) == -1) - break; - curruniqid += 129; - if ((unsigned long) (curruniqid + 1) < 65536) - curruniqid += 65537; - } - - id = curruniqid; - } else if (id < 0 && id > 65535) { - if (sockpoolindex (id) != -1) { - BSDTRACE ((L"[unique ID already exists]\n")); - return -1; - } - } - i = sockpoolindex (-1); + if (flags & REP_ALL) { + write_log (L"bsdsocket: ERROR: ReleaseSocket() is not supported for sockets with async event notification enabled!\n"); + return -1; + } + releasesock (sb, sd); + + if (id == UNIQUE_ID) { + for (;;) { + if (sockpoolindex (curruniqid) == -1) + break; + curruniqid += 129; + if ((unsigned long) (curruniqid + 1) < 65536) + curruniqid += 65537; + } - if (i == -1) { - BSDTRACE ((L"-1\n")); - write_log (L"bsdsocket: ERROR: Global socket pool overflow\n"); - return -1; - } - sockdata->sockpoolids[i] = id; - sockdata->sockpoolsocks[i] = s; - sockdata->sockpoolflags[i] = flags; + id = curruniqid; + } else if (id < 0 && id > 65535) { + if (sockpoolindex (id) != -1) { + BSDTRACE ((L"[unique ID already exists]\n")); + return -1; + } + } + i = sockpoolindex (-1); - BSDTRACE ((L"id %d s 0x%x\n", id,s)); - } else { - BSDTRACE ((L"[invalid socket descriptor]\n")); - return -1; - } + if (i == -1) { + BSDTRACE ((L"-1\n")); + write_log (L"bsdsocket: ERROR: Global socket pool overflow\n"); + return -1; + } + sockdata->sockpoolids[i] = id; + sockdata->sockpoolsocks[i] = s; + sockdata->sockpoolflags[i] = flags; + + BSDTRACE ((L"id %d s 0x%x\n", id,s)); + } else { + BSDTRACE ((L"[invalid socket descriptor]\n")); + return -1; + } - return id; + return id; } /* ReleaseCopyOfSocket(fd, id)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_ReleaseCopyOfSocket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - int sd; - long id; - SOCKET_TYPE s; - int i; - uae_u32 flags; + struct socketbase *sb = get_socketbase (context); + int sd; + long id; + SOCKET_TYPE s; + int i; + uae_u32 flags; - sd = m68k_dreg (regs, 0); - id = m68k_dreg (regs, 1); + sd = m68k_dreg (regs, 0); + id = m68k_dreg (regs, 1); - sd++; - BSDTRACE ((L"ReleaseSocket(%d,%d) -> ", sd, id)); + sd++; + BSDTRACE ((L"ReleaseSocket(%d,%d) -> ", sd, id)); - s = getsock (sb, sd); + s = getsock (sb, sd); - if (s != -1) { - flags = sb->ftable[sd - 1]; + if (s != -1) { + flags = sb->ftable[sd - 1]; - if (flags & REP_ALL) { - write_log (L"bsdsocket: ERROR: ReleaseCopyOfSocket() is not supported for sockets with async event notification enabled!\n"); - return -1; - } - if (id == UNIQUE_ID) { - for (;;) { - if (sockpoolindex (curruniqid) == -1) - break; - curruniqid += 129; - if ((unsigned long) (curruniqid + 1) < 65536) - curruniqid += 65537; - } - id = curruniqid; - } else if (id < 0 && id > 65535) { - if (sockpoolindex (id) != -1) { - BSDTRACE ((L"[unique ID already exists]\n")); - return -1; - } - } - i = sockpoolindex (-1); + if (flags & REP_ALL) { + write_log (L"bsdsocket: ERROR: ReleaseCopyOfSocket() is not supported for sockets with async event notification enabled!\n"); + return -1; + } + if (id == UNIQUE_ID) { + for (;;) { + if (sockpoolindex (curruniqid) == -1) + break; + curruniqid += 129; + if ((unsigned long) (curruniqid + 1) < 65536) + curruniqid += 65537; + } + id = curruniqid; + } else if (id < 0 && id > 65535) { + if (sockpoolindex (id) != -1) { + BSDTRACE ((L"[unique ID already exists]\n")); + return -1; + } + } + i = sockpoolindex (-1); - if (i == -1) { - BSDTRACE ((L"-1\n")); - write_log (L"bsdsocket: ERROR: Global socket pool overflow\n"); - return -1; - } - sockdata->sockpoolids[i] = id; - sockdata->sockpoolsocks[i] = s; - sockdata->sockpoolflags[i] = flags; + if (i == -1) { + BSDTRACE ((L"-1\n")); + write_log (L"bsdsocket: ERROR: Global socket pool overflow\n"); + return -1; + } + sockdata->sockpoolids[i] = id; + sockdata->sockpoolsocks[i] = s; + sockdata->sockpoolflags[i] = flags; - BSDTRACE ((L"id %d s 0x%x\n", id,s)); + BSDTRACE ((L"id %d s 0x%x\n", id,s)); - } else { + } else { - BSDTRACE ((L"[invalid socket descriptor]\n")); - return -1; - } + BSDTRACE ((L"[invalid socket descriptor]\n")); + return -1; + } - return id; + return id; } /* Errno()() */ static uae_u32 REGPARAM2 bsdsocklib_Errno (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - BSDTRACE ((L"Errno() -> %d\n", sb->sb_errno)); - return sb->sb_errno; + struct socketbase *sb = get_socketbase (context); + BSDTRACE ((L"Errno() -> %d\n", sb->sb_errno)); + return sb->sb_errno; } /* SetErrnoPtr(errno_p, size)(a0/d0) */ static uae_u32 REGPARAM2 bsdsocklib_SetErrnoPtr (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - uae_u32 errnoptr = m68k_areg (regs, 0), size = m68k_dreg (regs, 0); + struct socketbase *sb = get_socketbase (context); + uae_u32 errnoptr = m68k_areg (regs, 0), size = m68k_dreg (regs, 0); - BSDTRACE ((L"SetErrnoPtr(0x%lx,%d) -> ", errnoptr, size)); + BSDTRACE ((L"SetErrnoPtr(0x%lx,%d) -> ", errnoptr, size)); - if (size == 1 || size == 2 || size == 4) { - sb->errnoptr = errnoptr; - sb->errnosize = size; - BSDTRACE ((L"OK\n")); - return 0; - } - bsdsocklib_seterrno (sb, 22); /* EINVAL */ + if (size == 1 || size == 2 || size == 4) { + sb->errnoptr = errnoptr; + sb->errnosize = size; + BSDTRACE ((L"OK\n")); + return 0; + } + bsdsocklib_seterrno (sb, 22); /* EINVAL */ - return -1; + return -1; } /* *------ inet library calls related to inet address manipulation */ /* Inet_NtoA(in)(d0) */ static uae_u32 REGPARAM2 bsdsocklib_Inet_NtoA (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_Inet_NtoA (context, sb, m68k_dreg (regs, 0)); + struct socketbase *sb = get_socketbase (context); + return host_Inet_NtoA (context, sb, m68k_dreg (regs, 0)); } /* inet_addr(cp)(a0) */ static uae_u32 REGPARAM2 bsdsocklib_inet_addr (TrapContext *context) { - return host_inet_addr (m68k_areg (regs, 0)); + return host_inet_addr (m68k_areg (regs, 0)); } /* Inet_LnaOf(in)(d0) */ static uae_u32 REGPARAM2 bsdsocklib_Inet_LnaOf (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: Inet_LnaOf()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: Inet_LnaOf()\n"); + return 0; } /* Inet_NetOf(in)(d0) */ static uae_u32 REGPARAM2 bsdsocklib_Inet_NetOf (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: Inet_NetOf()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: Inet_NetOf()\n"); + return 0; } /* Inet_MakeAddr(net, host)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_Inet_MakeAddr (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: Inet_MakeAddr()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: Inet_MakeAddr()\n"); + return 0; } /* inet_network(cp)(a0) */ static uae_u32 REGPARAM2 bsdsocklib_inet_network (TrapContext *context) { - return host_inet_addr (m68k_areg (regs, 0)); + return host_inet_addr (m68k_areg (regs, 0)); } /* *------ gethostbyname etc */ /* gethostbyname(name)(a0) */ static uae_u32 REGPARAM2 bsdsocklib_gethostbyname (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_gethostbynameaddr (context, sb, m68k_areg (regs, 0), 0, -1); - return sb->sb_herrno ? 0 : sb->hostent; + struct socketbase *sb = get_socketbase (context); + host_gethostbynameaddr (context, sb, m68k_areg (regs, 0), 0, -1); + return sb->sb_herrno ? 0 : sb->hostent; } /* gethostbyaddr(addr, len, type)(a0/d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_gethostbyaddr (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_gethostbynameaddr (context, sb, m68k_areg (regs, 0), m68k_dreg (regs, 0), m68k_dreg (regs, 1)); - return sb->sb_herrno ? 0 : sb->hostent; + struct socketbase *sb = get_socketbase (context); + host_gethostbynameaddr (context, sb, m68k_areg (regs, 0), m68k_dreg (regs, 0), m68k_dreg (regs, 1)); + return sb->sb_herrno ? 0 : sb->hostent; } /* getnetbyname(name)(a0) */ static uae_u32 REGPARAM2 bsdsocklib_getnetbyname (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: getnetbyname()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: getnetbyname()\n"); + return 0; } /* getnetbyaddr(net, type)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_getnetbyaddr (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: getnetbyaddr()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: getnetbyaddr()\n"); + return 0; } /* getservbyname(name, proto)(a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_getservbyname (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_getservbynameport (context, sb, m68k_areg (regs, 0), m68k_areg (regs, 1), 0); - return sb->sb_errno ? 0 : sb->servent; + struct socketbase *sb = get_socketbase (context); + host_getservbynameport (context, sb, m68k_areg (regs, 0), m68k_areg (regs, 1), 0); + return sb->sb_errno ? 0 : sb->servent; } /* getservbyport(port, proto)(d0/a0) */ static uae_u32 REGPARAM2 bsdsocklib_getservbyport (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_getservbynameport (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), 1); - return sb->sb_errno ? 0 : sb->servent; + struct socketbase *sb = get_socketbase (context); + host_getservbynameport (context, sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), 1); + return sb->sb_errno ? 0 : sb->servent; } /* getprotobyname(name)(a0) */ static uae_u32 REGPARAM2 bsdsocklib_getprotobyname (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_getprotobyname (context, sb, m68k_areg (regs, 0)); - return sb->sb_errno ? 0 : sb->protoent; + struct socketbase *sb = get_socketbase (context); + host_getprotobyname (context, sb, m68k_areg (regs, 0)); + return sb->sb_errno ? 0 : sb->protoent; } /* getprotobynumber(proto)(d0) */ static uae_u32 REGPARAM2 bsdsocklib_getprotobynumber (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - host_getprotobynumber (context, sb, m68k_dreg (regs, 0)); - return sb->sb_errno ? 0 : sb->protoent; + struct socketbase *sb = get_socketbase (context); + host_getprotobynumber (context, sb, m68k_dreg (regs, 0)); + return sb->sb_errno ? 0 : sb->protoent; } /* *------ syslog functions */ /* Syslog(level, format, ap)(d0/a0/a1) */ static uae_u32 REGPARAM2 bsdsocklib_vsyslog (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: vsyslog()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: vsyslog()\n"); + return 0; } /* *------ AmiTCP/IP 1.1 extensions */ /* Dup2Socket(fd1, fd2)(d0/d1) */ static uae_u32 REGPARAM2 bsdsocklib_Dup2Socket (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - return host_dup2socket (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); + struct socketbase *sb = get_socketbase (context); + return host_dup2socket (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1)); } static uae_u32 REGPARAM2 bsdsocklib_sendmsg (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: sendmsg()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: sendmsg()\n"); + return 0; } static uae_u32 REGPARAM2 bsdsocklib_recvmsg (TrapContext *context) { - write_log (L"bsdsocket: UNSUPPORTED: recvmsg()\n"); - return 0; + write_log (L"bsdsocket: UNSUPPORTED: recvmsg()\n"); + return 0; } static uae_u32 REGPARAM2 bsdsocklib_gethostname (TrapContext *context) { - return host_gethostname (m68k_areg (regs, 0), m68k_dreg (regs, 0)); + return host_gethostname (m68k_areg (regs, 0), m68k_dreg (regs, 0)); } static uae_u32 REGPARAM2 bsdsocklib_gethostid (TrapContext *context) { - write_log (L"bsdsocket: WARNING: Process '%s' calls deprecated function gethostid() - returning 127.0.0.1\n", - get_real_address (get_long (gettask (context) + 10))); - return 0x7f000001; + write_log (L"bsdsocket: WARNING: Process '%s' calls deprecated function gethostid() - returning 127.0.0.1\n", + get_real_address (get_long (gettask (context) + 10))); + return 0x7f000001; } static const TCHAR *errortexts[] = {L"No error", L"Operation not permitted", L"No such file or directory", - L"No such process", L"Interrupted system call", L"Input/output error", L"Device not configured", - L"Argument list too long", L"Exec format error", L"Bad file descriptor", L"No child processes", - L"Resource deadlock avoided", L"Cannot allocate memory", L"Permission denied", L"Bad address", - L"Block device required", L"Device busy", L"Object exists", L"Cross-device link", - L"Operation not supported by device", L"Not a directory", L"Is a directory", L"Invalid argument", - L"Too many open files in system", L"Too many open files", L"Inappropriate ioctl for device", - L"Text file busy", L"File too large", L"No space left on device", L"Illegal seek", - L"Read-only file system", L"Too many links", L"Broken pipe", L"Numerical argument out of domain", - L"Result too large", L"Resource temporarily unavailable", L"Operation now in progress", - L"Operation already in progress", L"Socket operation on non-socket", L"Destination address required", - L"Message too long", L"Protocol wrong type for socket", L"Protocol not available", - L"Protocol not supported", L"Socket type not supported", L"Operation not supported", - L"Protocol family not supported", L"Address family not supported by protocol family", - L"Address already in use", L"Can't assign requested address", L"Network is down", - L"Network is unreachable", L"Network dropped connection on reset", L"Software caused connection abort", - L"Connection reset by peer", L"No buffer space available", L"Socket is already connected", - L"Socket is not connected", L"Can't send after socket shutdown", L"Too many references: can't splice", - L"Connection timed out", L"Connection refused", L"Too many levels of symbolic links", - L"File name too long", L"Host is down", L"No route to host", L"Directory not empty", - L"Too many processes", L"Too many users", L"Disc quota exceeded", L"Stale NFS file handle", - L"Too many levels of remote in path", L"RPC struct is bad", L"RPC version wrong", - L"RPC prog. not avail", L"Program version wrong", L"Bad procedure for program", L"No locks available", - L"Function not implemented", L"Inappropriate file type or format", L"PError 0"}; +L"No such process", L"Interrupted system call", L"Input/output error", L"Device not configured", +L"Argument list too long", L"Exec format error", L"Bad file descriptor", L"No child processes", +L"Resource deadlock avoided", L"Cannot allocate memory", L"Permission denied", L"Bad address", +L"Block device required", L"Device busy", L"Object exists", L"Cross-device link", +L"Operation not supported by device", L"Not a directory", L"Is a directory", L"Invalid argument", +L"Too many open files in system", L"Too many open files", L"Inappropriate ioctl for device", +L"Text file busy", L"File too large", L"No space left on device", L"Illegal seek", +L"Read-only file system", L"Too many links", L"Broken pipe", L"Numerical argument out of domain", +L"Result too large", L"Resource temporarily unavailable", L"Operation now in progress", +L"Operation already in progress", L"Socket operation on non-socket", L"Destination address required", +L"Message too long", L"Protocol wrong type for socket", L"Protocol not available", +L"Protocol not supported", L"Socket type not supported", L"Operation not supported", +L"Protocol family not supported", L"Address family not supported by protocol family", +L"Address already in use", L"Can't assign requested address", L"Network is down", +L"Network is unreachable", L"Network dropped connection on reset", L"Software caused connection abort", +L"Connection reset by peer", L"No buffer space available", L"Socket is already connected", +L"Socket is not connected", L"Can't send after socket shutdown", L"Too many references: can't splice", +L"Connection timed out", L"Connection refused", L"Too many levels of symbolic links", +L"File name too long", L"Host is down", L"No route to host", L"Directory not empty", +L"Too many processes", L"Too many users", L"Disc quota exceeded", L"Stale NFS file handle", +L"Too many levels of remote in path", L"RPC struct is bad", L"RPC version wrong", +L"RPC prog. not avail", L"Program version wrong", L"Bad procedure for program", L"No locks available", +L"Function not implemented", L"Inappropriate file type or format", L"PError 0"}; static uae_u32 errnotextptrs[sizeof (errortexts) / sizeof (*errortexts)]; static const uae_u32 number_sys_error = sizeof (errortexts) / sizeof (*errortexts); static const TCHAR *herrortexts[] = - {L"No error", L"Unknown host", L"Host name lookup failure", L"Unknown server error", - L"No address associated with name"}; +{L"No error", L"Unknown host", L"Host name lookup failure", L"Unknown server error", +L"No address associated with name"}; static uae_u32 herrnotextptrs[sizeof (herrortexts) / sizeof (*herrortexts)]; static const uae_u32 number_host_error = sizeof (herrortexts) / sizeof (*herrortexts); @@ -1125,12 +1125,12 @@ static uae_u32 strErrptr; #define SBTF_GET 0x0 #define SBTF_SET 0x1 #define SBTM_GETREF(code) \ - (TAG_USER | SBTF_REF | (((code) & SBTS_CODE) << SBTB_CODE)) + (TAG_USER | SBTF_REF | (((code) & SBTS_CODE) << SBTB_CODE)) #define SBTM_GETVAL(code) (TAG_USER | (((code) & SBTS_CODE) << SBTB_CODE)) #define SBTM_SETREF(code) \ - (TAG_USER | SBTF_REF | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_SET) + (TAG_USER | SBTF_REF | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_SET) #define SBTM_SETVAL(code) \ - (TAG_USER | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_SET) + (TAG_USER | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_SET) #define SBTC_BREAKMASK 1 #define SBTC_SIGIOMASK 2 #define SBTC_SIGURGMASK 3 @@ -1156,345 +1156,345 @@ static uae_u32 strErrptr; static void tagcopy (uae_u32 currtag, uae_u32 currval, uae_u32 tagptr, uae_u32 * ptr) { - switch (currtag & 0x8001) { - case 0x0000: /* SBTM_GETVAL */ + switch (currtag & 0x8001) { + case 0x0000: /* SBTM_GETVAL */ - put_long (tagptr + 4, *ptr); - break; - case 0x8000: /* SBTM_GETREF */ + put_long (tagptr + 4, *ptr); + break; + case 0x8000: /* SBTM_GETREF */ - put_long (currval, *ptr); - break; - case 0x0001: /* SBTM_SETVAL */ + put_long (currval, *ptr); + break; + case 0x0001: /* SBTM_SETVAL */ - *ptr = currval; - break; - default: /* SBTM_SETREF */ + *ptr = currval; + break; + default: /* SBTM_SETREF */ - *ptr = get_long (currval); - } + *ptr = get_long (currval); + } } static uae_u32 REGPARAM2 bsdsocklib_SocketBaseTagList (TrapContext *context) { - struct socketbase *sb = get_socketbase (context); - uae_u32 tagptr = m68k_areg (regs, 0); - uae_u32 tagsprocessed = 1; - uae_u32 currtag; - uae_u32 currval; - - BSDTRACE ((L"SocketBaseTagList(")); - - for (;;) { - currtag = get_long (tagptr); - currval = get_long (tagptr + 4); - tagsprocessed++; - - switch (currtag) { - case TAG_DONE: - BSDTRACE ((L"TAG_DONE")); - tagsprocessed = 0; - goto done; - case TAG_IGNORE: - BSDTRACE ((L"TAG_IGNORE")); - break; - case TAG_MORE: - BSDTRACE ((L"TAG_MORE(0x%lx)", currval)); - tagptr = currval; - break; - case TAG_SKIP: - BSDTRACE ((L"TAG_SKIP(%d)", currval)); - tagptr += currval * 8; - break; - - default: - if (currtag & TAG_USER) { - BSDTRACE ((L"SBTM_")); - BSDTRACE ((currtag & 0x0001 ? L"SET" : L"GET")); - BSDTRACE ((currtag & 0x8000 ? L"REF(" : L"VAL(")); - - switch ((currtag >> 1) & SBTS_CODE) { - case SBTC_BREAKMASK: - BSDTRACE ((L"SBTC_BREAKMASK),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->eintrsigs); - break; - case SBTC_SIGEVENTMASK: - BSDTRACE ((L"SBTC_SIGEVENTMASK),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->eventsigs); - break; - case SBTC_SIGIOMASK: - BSDTRACE ((L"SBTC_SIGEVENTMASK),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->eventsigs); - break; - case SBTC_ERRNO: - BSDTRACE ((L"SBTC_ERRNO),%d", currval)); - tagcopy (currtag, currval, tagptr, &sb->sb_errno); - break; - case SBTC_HERRNO: - BSDTRACE ((L"SBTC_HERRNO),%d", currval)); - tagcopy (currtag, currval, tagptr, &sb->sb_herrno); - break; - case SBTC_DTABLESIZE: - BSDTRACE ((L"SBTC_DTABLESIZE),0x%lx", currval)); - if (currtag & 1) { - bsdsocklib_SetDTableSize(sb, currval); - } else { - put_long (tagptr + 4, sb->dtablesize); - } - break; - case SBTC_ERRNOSTRPTR: - if (currtag & 1) { - BSDTRACE ((L"ERRNOSTRPTR),invalid")); - } else { - unsigned long ulTmp; - if (currtag & 0x8000) { /* SBTM_GETREF */ - ulTmp = get_long (currval); - } else { /* SBTM_GETVAL */ - ulTmp = currval; - } - BSDTRACE ((L"ERRNOSTRPTR),%d", ulTmp)); - if (ulTmp < number_sys_error) { - tagcopy (currtag, currval, tagptr, &errnotextptrs[ulTmp]); + struct socketbase *sb = get_socketbase (context); + uae_u32 tagptr = m68k_areg (regs, 0); + uae_u32 tagsprocessed = 1; + uae_u32 currtag; + uae_u32 currval; + + BSDTRACE ((L"SocketBaseTagList(")); + + for (;;) { + currtag = get_long (tagptr); + currval = get_long (tagptr + 4); + tagsprocessed++; + + switch (currtag) { + case TAG_DONE: + BSDTRACE ((L"TAG_DONE")); + tagsprocessed = 0; + goto done; + case TAG_IGNORE: + BSDTRACE ((L"TAG_IGNORE")); + break; + case TAG_MORE: + BSDTRACE ((L"TAG_MORE(0x%lx)", currval)); + tagptr = currval; + break; + case TAG_SKIP: + BSDTRACE ((L"TAG_SKIP(%d)", currval)); + tagptr += currval * 8; + break; + + default: + if (currtag & TAG_USER) { + BSDTRACE ((L"SBTM_")); + BSDTRACE ((currtag & 0x0001 ? L"SET" : L"GET")); + BSDTRACE ((currtag & 0x8000 ? L"REF(" : L"VAL(")); + + switch ((currtag >> 1) & SBTS_CODE) { + case SBTC_BREAKMASK: + BSDTRACE ((L"SBTC_BREAKMASK),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->eintrsigs); + break; + case SBTC_SIGEVENTMASK: + BSDTRACE ((L"SBTC_SIGEVENTMASK),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->eventsigs); + break; + case SBTC_SIGIOMASK: + BSDTRACE ((L"SBTC_SIGEVENTMASK),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->eventsigs); + break; + case SBTC_ERRNO: + BSDTRACE ((L"SBTC_ERRNO),%d", currval)); + tagcopy (currtag, currval, tagptr, &sb->sb_errno); + break; + case SBTC_HERRNO: + BSDTRACE ((L"SBTC_HERRNO),%d", currval)); + tagcopy (currtag, currval, tagptr, &sb->sb_herrno); + break; + case SBTC_DTABLESIZE: + BSDTRACE ((L"SBTC_DTABLESIZE),0x%lx", currval)); + if (currtag & 1) { + bsdsocklib_SetDTableSize(sb, currval); + } else { + put_long (tagptr + 4, sb->dtablesize); + } + break; + case SBTC_ERRNOSTRPTR: + if (currtag & 1) { + BSDTRACE ((L"ERRNOSTRPTR),invalid")); + } else { + unsigned long ulTmp; + if (currtag & 0x8000) { /* SBTM_GETREF */ + ulTmp = get_long (currval); + } else { /* SBTM_GETVAL */ + ulTmp = currval; + } + BSDTRACE ((L"ERRNOSTRPTR),%d", ulTmp)); + if (ulTmp < number_sys_error) { + tagcopy (currtag, currval, tagptr, &errnotextptrs[ulTmp]); + } else { + tagcopy (currtag, currval, tagptr, &strErrptr); + } + } + break; + case SBTC_HERRNOSTRPTR: + if (currtag & 1) { + BSDTRACE ((L"HERRNOSTRPTR),invalid")); + } else { + unsigned long ulTmp; + if (currtag & 0x8000) { /* SBTM_GETREF */ + ulTmp = get_long (currval); + } else { /* SBTM_GETVAL */ + ulTmp = currval; + } + BSDTRACE ((L"HERRNOSTRPTR),%d", ulTmp)); + if (ulTmp < number_host_error) { + tagcopy (currtag, currval, tagptr, &herrnotextptrs[ulTmp]); + } else { + tagcopy (currtag, currval, tagptr, &strErrptr); + } + } + break; + case SBTC_ERRNOBYTEPTR: + BSDTRACE ((L"SBTC_ERRNOBYTEPTR),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->errnoptr); + sb->errnosize = 1; + break; + case SBTC_ERRNOWORDPTR: + BSDTRACE ((L"SBTC_ERRNOWORDPTR),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->errnoptr); + sb->errnosize = 2; + break; + case SBTC_ERRNOLONGPTR: + BSDTRACE ((L"SBTC_ERRNOLONGPTR),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->errnoptr); + sb->errnosize = 4; + break; + case SBTC_HERRNOLONGPTR: + BSDTRACE ((L"SBTC_HERRNOLONGPTR),0x%lx", currval)); + tagcopy (currtag, currval, tagptr, &sb->herrnoptr); + sb->herrnosize = 4; + break; + default: + write_log (L"bsdsocket: WARNING: Unsupported tag type (%08x) in SocketBaseTagList(%x)\n", + currtag, m68k_areg (regs, 0)); + break; + } } else { - tagcopy (currtag, currval, tagptr, &strErrptr); + BSDTRACE ((L"TAG_UNKNOWN(0x%x)", currtag)); + /* Aminetradio uses 0x00004e55 as an ending tag */ + if ((currtag & 0xffff8000) == 0) { + write_log (L"bsdsocket: WARNING: Corrupted SocketBaseTagList(%x) tag detected (%08x)\n", + m68k_areg (regs, 0), currtag); + goto done; + } } - } - break; - case SBTC_HERRNOSTRPTR: - if (currtag & 1) { - BSDTRACE ((L"HERRNOSTRPTR),invalid")); - } else { - unsigned long ulTmp; - if (currtag & 0x8000) { /* SBTM_GETREF */ - ulTmp = get_long (currval); - } else { /* SBTM_GETVAL */ - ulTmp = currval; - } - BSDTRACE ((L"HERRNOSTRPTR),%d", ulTmp)); - if (ulTmp < number_host_error) { - tagcopy (currtag, currval, tagptr, &herrnotextptrs[ulTmp]); - } else { - tagcopy (currtag, currval, tagptr, &strErrptr); - } - } - break; - case SBTC_ERRNOBYTEPTR: - BSDTRACE ((L"SBTC_ERRNOBYTEPTR),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->errnoptr); - sb->errnosize = 1; - break; - case SBTC_ERRNOWORDPTR: - BSDTRACE ((L"SBTC_ERRNOWORDPTR),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->errnoptr); - sb->errnosize = 2; - break; - case SBTC_ERRNOLONGPTR: - BSDTRACE ((L"SBTC_ERRNOLONGPTR),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->errnoptr); - sb->errnosize = 4; - break; - case SBTC_HERRNOLONGPTR: - BSDTRACE ((L"SBTC_HERRNOLONGPTR),0x%lx", currval)); - tagcopy (currtag, currval, tagptr, &sb->herrnoptr); - sb->herrnosize = 4; - break; - default: - write_log (L"bsdsocket: WARNING: Unsupported tag type (%08x) in SocketBaseTagList(%x)\n", - currtag, m68k_areg (regs, 0)); - break; } - } else { - BSDTRACE ((L"TAG_UNKNOWN(0x%x)", currtag)); - /* Aminetradio uses 0x00004e55 as an ending tag */ - if ((currtag & 0xffff8000) == 0) { - write_log (L"bsdsocket: WARNING: Corrupted SocketBaseTagList(%x) tag detected (%08x)\n", - m68k_areg (regs, 0), currtag); - goto done; - } - } - } - BSDTRACE ((L",")); - tagptr += 8; - } + BSDTRACE ((L",")); + tagptr += 8; + } - done: - BSDTRACE ((L") -> %d\n", tagsprocessed)); +done: + BSDTRACE ((L") -> %d\n", tagsprocessed)); - return tagsprocessed; + return tagsprocessed; } static uae_u32 REGPARAM2 bsdsocklib_GetSocketEvents (TrapContext *context) { #ifdef _WIN32 - struct socketbase *sb = get_socketbase (context); - int i; - int flags; - uae_u32 ptr = m68k_areg (regs, 0); - - BSDTRACE ((L"GetSocketEvents(0x%x) -> ", ptr)); - - for (i = sb->dtablesize; i--; sb->eventindex++) { - if (sb->eventindex >= sb->dtablesize) - sb->eventindex = 0; - - if (sb->mtable[sb->eventindex]) { - flags = sb->ftable[sb->eventindex] & SET_ALL; - if (flags) { - sb->ftable[sb->eventindex] &= ~SET_ALL; - put_long (m68k_areg (regs, 0), flags >> 8); - BSDTRACE ((L"%d (0x%x)\n", sb->eventindex + 1, flags >> 8)); - return sb->eventindex; // xxx - } + struct socketbase *sb = get_socketbase (context); + int i; + int flags; + uae_u32 ptr = m68k_areg (regs, 0); + + BSDTRACE ((L"GetSocketEvents(0x%x) -> ", ptr)); + + for (i = sb->dtablesize; i--; sb->eventindex++) { + if (sb->eventindex >= sb->dtablesize) + sb->eventindex = 0; + + if (sb->mtable[sb->eventindex]) { + flags = sb->ftable[sb->eventindex] & SET_ALL; + if (flags) { + sb->ftable[sb->eventindex] &= ~SET_ALL; + put_long (m68k_areg (regs, 0), flags >> 8); + BSDTRACE ((L"%d (0x%x)\n", sb->eventindex + 1, flags >> 8)); + return sb->eventindex; // xxx + } + } } - } #endif - BSDTRACE ((L"-1\n")); - return -1; + BSDTRACE ((L"-1\n")); + return -1; } static uae_u32 REGPARAM2 bsdsocklib_getdtablesize (TrapContext *context) { - return get_socketbase (context)->dtablesize; + return get_socketbase (context)->dtablesize; } static uae_u32 REGPARAM2 bsdsocklib_null (TrapContext *context) { - return 0; + return 0; } static uae_u32 REGPARAM2 bsdsocklib_init (TrapContext *context) { - uae_u32 tmp1; - int i; + uae_u32 tmp1; + int i; - write_log (L"Creating UAE bsdsocket.library 4.1\n"); - if (SockLibBase) - bsdlib_reset (); + write_log (L"Creating UAE bsdsocket.library 4.1\n"); + if (SockLibBase) + bsdlib_reset (); - m68k_areg (regs, 0) = functable; - m68k_areg (regs, 1) = datatable; - m68k_areg (regs, 2) = 0; - m68k_dreg (regs, 0) = LIBRARY_SIZEOF; - m68k_dreg (regs, 1) = 0; - tmp1 = CallLib (context, m68k_areg (regs, 6), -0x54); /* MakeLibrary */ + m68k_areg (regs, 0) = functable; + m68k_areg (regs, 1) = datatable; + m68k_areg (regs, 2) = 0; + m68k_dreg (regs, 0) = LIBRARY_SIZEOF; + m68k_dreg (regs, 1) = 0; + tmp1 = CallLib (context, m68k_areg (regs, 6), -0x54); /* MakeLibrary */ - if (!tmp1) { - write_log (L"bsdoscket: FATAL: Cannot create bsdsocket.library!\n"); - return 0; - } - m68k_areg (regs, 1) = tmp1; - CallLib (context, m68k_areg (regs, 6), -0x18c); /* AddLibrary */ - SockLibBase = tmp1; + if (!tmp1) { + write_log (L"bsdoscket: FATAL: Cannot create bsdsocket.library!\n"); + return 0; + } + m68k_areg (regs, 1) = tmp1; + CallLib (context, m68k_areg (regs, 6), -0x18c); /* AddLibrary */ + SockLibBase = tmp1; - /* Install error strings in Amiga memory */ - tmp1 = 0; - for (i = number_sys_error; i--;) - tmp1 += _tcslen (errortexts[i]) + 1; + /* Install error strings in Amiga memory */ + tmp1 = 0; + for (i = number_sys_error; i--;) + tmp1 += _tcslen (errortexts[i]) + 1; - for (i = number_host_error; i--;) - tmp1 += _tcslen (herrortexts[i]) + 1; + for (i = number_host_error; i--;) + tmp1 += _tcslen (herrortexts[i]) + 1; - tmp1 += _tcslen (strErr) + 1; + tmp1 += _tcslen (strErr) + 1; - m68k_dreg (regs, 0) = tmp1; - m68k_dreg (regs, 1) = 0; - tmp1 = CallLib (context, get_long (4), -0xC6); /* AllocMem */ + m68k_dreg (regs, 0) = tmp1; + m68k_dreg (regs, 1) = 0; + tmp1 = CallLib (context, get_long (4), -0xC6); /* AllocMem */ - if (!tmp1) { - write_log (L"bsdsocket: FATAL: Ran out of memory while creating bsdsocket.library!\n"); - return 0; - } - for (i = 0; i < (int) (number_sys_error); i++) - errnotextptrs[i] = addstr (&tmp1, errortexts[i]); - for (i = 0; i < (int) (number_host_error); i++) - herrnotextptrs[i] = addstr (&tmp1, herrortexts[i]); - strErrptr = addstr (&tmp1, strErr); + if (!tmp1) { + write_log (L"bsdsocket: FATAL: Ran out of memory while creating bsdsocket.library!\n"); + return 0; + } + for (i = 0; i < (int) (number_sys_error); i++) + errnotextptrs[i] = addstr (&tmp1, errortexts[i]); + for (i = 0; i < (int) (number_host_error); i++) + herrnotextptrs[i] = addstr (&tmp1, herrortexts[i]); + strErrptr = addstr (&tmp1, strErr); #if 0 - /* @@@ someone please implement a proper interrupt handler setup here :) */ - tmp1 = here (); - calltrap (deftrap2 (bsdsock_int_handler, TRAPFLAG_EXTRA_STACK | TRAPFLAG_NO_RETVAL, "bsdsock_int_handler")); - dw (0x4ef9); - dl (get_long (context->regs.vbr + 0x78)); - put_long (context->regs.vbr + 0x78, tmp1); + /* @@@ someone please implement a proper interrupt handler setup here :) */ + tmp1 = here (); + calltrap (deftrap2 (bsdsock_int_handler, TRAPFLAG_EXTRA_STACK | TRAPFLAG_NO_RETVAL, "bsdsock_int_handler")); + dw (0x4ef9); + dl (get_long (context->regs.vbr + 0x78)); + put_long (context->regs.vbr + 0x78, tmp1); #endif - m68k_dreg (regs, 0) = 1; - return 0; + m68k_dreg (regs, 0) = 1; + return 0; } void bsdlib_reset (void) { - SB, *nsb; - int i; + SB, *nsb; + int i; - if (!SockLibBase) - return; + if (!SockLibBase) + return; - SockLibBase = 0; + SockLibBase = 0; - write_log (L"BSDSOCK: cleanup start..\n"); - host_sbcleanup (NULL); - for (sb = socketbases; sb; sb = nsb) { - nsb = sb->next; + write_log (L"BSDSOCK: cleanup start..\n"); + host_sbcleanup (NULL); + for (sb = socketbases; sb; sb = nsb) { + nsb = sb->next; - write_log (L"BSDSOCK: cleanup start socket %x\n", sb); - host_sbcleanup (sb); + write_log (L"BSDSOCK: cleanup start socket %x\n", sb); + host_sbcleanup (sb); - free (sb->dtable); - free (sb->ftable); + free (sb->dtable); + free (sb->ftable); - free (sb); - } - write_log (L"BSDSOCK: cleanup end\n"); + free (sb); + } + write_log (L"BSDSOCK: cleanup end\n"); - socketbases = NULL; + socketbases = NULL; #if 1 - sbsigqueue = NULL; + sbsigqueue = NULL; #endif - for (i = 0; i < SOCKPOOLSIZE; i++) { - if (sockdata->sockpoolids[i] != UNIQUE_ID) { - sockdata->sockpoolids[i] = UNIQUE_ID; - host_closesocketquick (sockdata->sockpoolsocks[i]); + for (i = 0; i < SOCKPOOLSIZE; i++) { + if (sockdata->sockpoolids[i] != UNIQUE_ID) { + sockdata->sockpoolids[i] = UNIQUE_ID; + host_closesocketquick (sockdata->sockpoolsocks[i]); + } } - } - host_sbreset (); - write_log (L"BSDSOCK: cleanup finished\n"); + host_sbreset (); + write_log (L"BSDSOCK: cleanup finished\n"); } static const TrapHandler sockfuncs[] = { - bsdsocklib_init, bsdsocklib_Open, bsdsocklib_Close, bsdsocklib_Expunge, - bsdsocklib_socket, bsdsocklib_bind, bsdsocklib_listen, bsdsocklib_accept, - bsdsocklib_connect, bsdsocklib_sendto, bsdsocklib_send, bsdsocklib_recvfrom, bsdsocklib_recv, - bsdsocklib_shutdown, bsdsocklib_setsockopt, bsdsocklib_getsockopt, bsdsocklib_getsockname, - bsdsocklib_getpeername, bsdsocklib_IoctlSocket, bsdsocklib_CloseSocket, bsdsocklib_WaitSelect, - bsdsocklib_SetSocketSignals, bsdsocklib_getdtablesize, bsdsocklib_ObtainSocket, bsdsocklib_ReleaseSocket, - bsdsocklib_ReleaseCopyOfSocket, bsdsocklib_Errno, bsdsocklib_SetErrnoPtr, bsdsocklib_Inet_NtoA, - bsdsocklib_inet_addr, bsdsocklib_Inet_LnaOf, bsdsocklib_Inet_NetOf, bsdsocklib_Inet_MakeAddr, - bsdsocklib_inet_network, bsdsocklib_gethostbyname, bsdsocklib_gethostbyaddr, bsdsocklib_getnetbyname, - bsdsocklib_getnetbyaddr, bsdsocklib_getservbyname, bsdsocklib_getservbyport, bsdsocklib_getprotobyname, - bsdsocklib_getprotobynumber, bsdsocklib_vsyslog, bsdsocklib_Dup2Socket, bsdsocklib_sendmsg, - bsdsocklib_recvmsg, bsdsocklib_gethostname, bsdsocklib_gethostid, bsdsocklib_SocketBaseTagList, - bsdsocklib_GetSocketEvents + bsdsocklib_init, bsdsocklib_Open, bsdsocklib_Close, bsdsocklib_Expunge, + bsdsocklib_socket, bsdsocklib_bind, bsdsocklib_listen, bsdsocklib_accept, + bsdsocklib_connect, bsdsocklib_sendto, bsdsocklib_send, bsdsocklib_recvfrom, bsdsocklib_recv, + bsdsocklib_shutdown, bsdsocklib_setsockopt, bsdsocklib_getsockopt, bsdsocklib_getsockname, + bsdsocklib_getpeername, bsdsocklib_IoctlSocket, bsdsocklib_CloseSocket, bsdsocklib_WaitSelect, + bsdsocklib_SetSocketSignals, bsdsocklib_getdtablesize, bsdsocklib_ObtainSocket, bsdsocklib_ReleaseSocket, + bsdsocklib_ReleaseCopyOfSocket, bsdsocklib_Errno, bsdsocklib_SetErrnoPtr, bsdsocklib_Inet_NtoA, + bsdsocklib_inet_addr, bsdsocklib_Inet_LnaOf, bsdsocklib_Inet_NetOf, bsdsocklib_Inet_MakeAddr, + bsdsocklib_inet_network, bsdsocklib_gethostbyname, bsdsocklib_gethostbyaddr, bsdsocklib_getnetbyname, + bsdsocklib_getnetbyaddr, bsdsocklib_getservbyname, bsdsocklib_getservbyport, bsdsocklib_getprotobyname, + bsdsocklib_getprotobynumber, bsdsocklib_vsyslog, bsdsocklib_Dup2Socket, bsdsocklib_sendmsg, + bsdsocklib_recvmsg, bsdsocklib_gethostname, bsdsocklib_gethostid, bsdsocklib_SocketBaseTagList, + bsdsocklib_GetSocketEvents }; static const TCHAR * const funcnames[] = { - L"bsdsocklib_init", L"bsdsocklib_Open", L"bsdsocklib_Close", L"bsdsocklib_Expunge", - L"bsdsocklib_socket", L"bsdsocklib_bind", L"bsdsocklib_listen", L"bsdsocklib_accept", - L"bsdsocklib_connect", L"bsdsocklib_sendto", L"bsdsocklib_send", L"bsdsocklib_recvfrom", L"bsdsocklib_recv", - L"bsdsocklib_shutdown", L"bsdsocklib_setsockopt", L"bsdsocklib_getsockopt", L"bsdsocklib_getsockname", - L"bsdsocklib_getpeername", L"bsdsocklib_IoctlSocket", L"bsdsocklib_CloseSocket", L"bsdsocklib_WaitSelect", - L"bsdsocklib_SetSocketSignals", L"bsdsocklib_getdtablesize", L"bsdsocklib_ObtainSocket", L"bsdsocklib_ReleaseSocket", - L"bsdsocklib_ReleaseCopyOfSocket", L"bsdsocklib_Errno", L"bsdsocklib_SetErrnoPtr", L"bsdsocklib_Inet_NtoA", - L"bsdsocklib_inet_addr", L"bsdsocklib_Inet_LnaOf", L"bsdsocklib_Inet_NetOf", L"bsdsocklib_Inet_MakeAddr", - L"bsdsocklib_inet_network", L"bsdsocklib_gethostbyname", L"bsdsocklib_gethostbyaddr", L"bsdsocklib_getnetbyname", - L"bsdsocklib_getnetbyaddr", L"bsdsocklib_getservbyname", L"bsdsocklib_getservbyport", L"bsdsocklib_getprotobyname", - L"bsdsocklib_getprotobynumber", L"bsdsocklib_vsyslog", L"bsdsocklib_Dup2Socket", L"bsdsocklib_sendmsg", - L"bsdsocklib_recvmsg", L"bsdsocklib_gethostname", L"bsdsocklib_gethostid", L"bsdsocklib_SocketBaseTagList", - L"bsdsocklib_GetSocketEvents" + L"bsdsocklib_init", L"bsdsocklib_Open", L"bsdsocklib_Close", L"bsdsocklib_Expunge", + L"bsdsocklib_socket", L"bsdsocklib_bind", L"bsdsocklib_listen", L"bsdsocklib_accept", + L"bsdsocklib_connect", L"bsdsocklib_sendto", L"bsdsocklib_send", L"bsdsocklib_recvfrom", L"bsdsocklib_recv", + L"bsdsocklib_shutdown", L"bsdsocklib_setsockopt", L"bsdsocklib_getsockopt", L"bsdsocklib_getsockname", + L"bsdsocklib_getpeername", L"bsdsocklib_IoctlSocket", L"bsdsocklib_CloseSocket", L"bsdsocklib_WaitSelect", + L"bsdsocklib_SetSocketSignals", L"bsdsocklib_getdtablesize", L"bsdsocklib_ObtainSocket", L"bsdsocklib_ReleaseSocket", + L"bsdsocklib_ReleaseCopyOfSocket", L"bsdsocklib_Errno", L"bsdsocklib_SetErrnoPtr", L"bsdsocklib_Inet_NtoA", + L"bsdsocklib_inet_addr", L"bsdsocklib_Inet_LnaOf", L"bsdsocklib_Inet_NetOf", L"bsdsocklib_Inet_MakeAddr", + L"bsdsocklib_inet_network", L"bsdsocklib_gethostbyname", L"bsdsocklib_gethostbyaddr", L"bsdsocklib_getnetbyname", + L"bsdsocklib_getnetbyaddr", L"bsdsocklib_getservbyname", L"bsdsocklib_getservbyport", L"bsdsocklib_getprotobyname", + L"bsdsocklib_getprotobynumber", L"bsdsocklib_vsyslog", L"bsdsocklib_Dup2Socket", L"bsdsocklib_sendmsg", + L"bsdsocklib_recvmsg", L"bsdsocklib_gethostname", L"bsdsocklib_gethostid", L"bsdsocklib_SocketBaseTagList", + L"bsdsocklib_GetSocketEvents" }; static uae_u32 sockfuncvecs[sizeof (sockfuncs) / sizeof (*sockfuncs)]; @@ -1503,83 +1503,83 @@ static uae_u32 res_name, res_id, res_init; uaecptr bsdlib_startup (uaecptr resaddr) { - if (res_name == 0 || !currprefs.socket_emu) + if (res_name == 0 || !currprefs.socket_emu) + return resaddr; + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8004); /* RTF_AUTOINIT, RT_VERSION */ + put_word (resaddr + 0xC, 0x0970); /* NT_LIBRARY, RT_PRI */ + put_long (resaddr + 0xE, res_name); + put_long (resaddr + 0x12, res_id); + put_long (resaddr + 0x16, res_init); + resaddr += 0x1A; return resaddr; - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8004); /* RTF_AUTOINIT, RT_VERSION */ - put_word (resaddr + 0xC, 0x0970); /* NT_LIBRARY, RT_PRI */ - put_long (resaddr + 0xE, res_name); - put_long (resaddr + 0x12, res_id); - put_long (resaddr + 0x16, res_init); - resaddr += 0x1A; - return resaddr; } void bsdlib_install (void) { - int i; + int i; - if (!sockdata) { - sockdata = xcalloc (sizeof (struct sockd), 1); - for (i = 0; i < SOCKPOOLSIZE; i++) - sockdata->sockpoolids[i] = UNIQUE_ID; - } - - if (!init_socket_layer ()) - return; - - res_name = ds (L"bsdsocket.library"); - res_id = ds (L"UAE bsdsocket.library 4.1"); - - for (i = 0; i < (int) (sizeof (sockfuncs) / sizeof (sockfuncs[0])); i++) { - sockfuncvecs[i] = here (); - calltrap (deftrap2 (sockfuncs[i], TRAPFLAG_EXTRA_STACK, funcnames[i])); - dw (RTS); - } - - /* FuncTable */ - functable = here (); - for (i = 1; i < 4; i++) - dl (sockfuncvecs[i]); /* Open / Close / Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - for (i = 4; i < (int) (sizeof (sockfuncs) / sizeof (sockfuncs[0])); i++) - dl (sockfuncvecs[i]); - dl (0xFFFFFFFF); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0900); /* NT_LIBRARY */ - dw (0xE000); /* INITBYTE */ - dw (0x0009); /* LN_PRI */ - dw (0xCE00); /* -50 */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (res_name); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); - dw (0xD000); - dw (0x0016); /* LIB_REVISION */ - dw (0x0001); - dw (0xC000); - dw (0x0018); /* LIB_IDSTRING */ - dl (res_id); - dl (0x00000000); /* end of table */ - - res_init = here (); - dl (512); - dl (functable); - dl (datatable); - dl (*sockfuncvecs); - - write_log (L"bsdsocked.library installed\n"); + if (!sockdata) { + sockdata = xcalloc (sizeof (struct sockd), 1); + for (i = 0; i < SOCKPOOLSIZE; i++) + sockdata->sockpoolids[i] = UNIQUE_ID; + } + + if (!init_socket_layer ()) + return; + + res_name = ds (L"bsdsocket.library"); + res_id = ds (L"UAE bsdsocket.library 4.1"); + + for (i = 0; i < (int) (sizeof (sockfuncs) / sizeof (sockfuncs[0])); i++) { + sockfuncvecs[i] = here (); + calltrap (deftrap2 (sockfuncs[i], TRAPFLAG_EXTRA_STACK, funcnames[i])); + dw (RTS); + } + + /* FuncTable */ + functable = here (); + for (i = 1; i < 4; i++) + dl (sockfuncvecs[i]); /* Open / Close / Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + for (i = 4; i < (int) (sizeof (sockfuncs) / sizeof (sockfuncs[0])); i++) + dl (sockfuncvecs[i]); + dl (0xFFFFFFFF); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0900); /* NT_LIBRARY */ + dw (0xE000); /* INITBYTE */ + dw (0x0009); /* LN_PRI */ + dw (0xCE00); /* -50 */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (res_name); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); + dw (0xD000); + dw (0x0016); /* LIB_REVISION */ + dw (0x0001); + dw (0xC000); + dw (0x0018); /* LIB_IDSTRING */ + dl (res_id); + dl (0x00000000); /* end of table */ + + res_init = here (); + dl (512); + dl (functable); + dl (datatable); + dl (*sockfuncvecs); + + write_log (L"bsdsocked.library installed\n"); } #endif /* ! BSDSOCKET */ diff --git a/catweasel.c b/catweasel.c index 320bc5c7..5bdea34c 100644 --- a/catweasel.c +++ b/catweasel.c @@ -26,375 +26,375 @@ static HANDLE handle = INVALID_HANDLE_VALUE; int catweasel_isjoystick (void) { - uae_u8 b = cwc.can_joy; - if (!cwc.direct_access) - return 0; - if (b) { - if (cwc.type == CATWEASEL_TYPE_MK3 && cwc.sid[0]) - b |= 0x80; - if (cwc.type >= CATWEASEL_TYPE_MK4) - b |= 0x80; - } - return b; + uae_u8 b = cwc.can_joy; + if (!cwc.direct_access) + return 0; + if (b) { + if (cwc.type == CATWEASEL_TYPE_MK3 && cwc.sid[0]) + b |= 0x80; + if (cwc.type >= CATWEASEL_TYPE_MK4) + b |= 0x80; + } + return b; } int catweasel_ismouse (void) { - if (!cwc.direct_access) - return 0; - return cwc.can_mouse; + if (!cwc.direct_access) + return 0; + return cwc.can_mouse; } static int hsync_requested; static void hsync_request (void) { - hsync_requested = 10; + hsync_requested = 10; }; static void sid_write (uae_u8 reg, uae_u8 val, int sidnum) { - if (sidnum >= cwc.can_sid) - return; - catweasel_do_bput(0xd8, val); - catweasel_do_bput(0xdc, reg | (sidnum << 7)); - catweasel_do_bget(0xd8); // dummy read - catweasel_do_bget(0xd8); // dummy read + if (sidnum >= cwc.can_sid) + return; + catweasel_do_bput(0xd8, val); + catweasel_do_bput(0xdc, reg | (sidnum << 7)); + catweasel_do_bget(0xd8); // dummy read + catweasel_do_bget(0xd8); // dummy read } static uae_u8 sid_read (uae_u8 reg, int sidnum) { - if (sidnum >= cwc.can_sid) - return 0; - catweasel_do_bput(0xdc, 0x20 | reg | (sidnum << 7)); - catweasel_do_bget(0xd8); // dummy read - catweasel_do_bget(0xd8); // dummy read - return catweasel_do_bget(0xd8); + if (sidnum >= cwc.can_sid) + return 0; + catweasel_do_bput(0xdc, 0x20 | reg | (sidnum << 7)); + catweasel_do_bget(0xd8); // dummy read + catweasel_do_bget(0xd8); // dummy read + return catweasel_do_bget(0xd8); } static uae_u8 get_buttons (void) { - uae_u8 b, b2; - - b = 0; - if (cwc.type < CATWEASEL_TYPE_MK3 || !cwc.direct_access) - return b; - hsync_request(); - b2 = catweasel_do_bget(0xc8) & (0x80 | 0x40); - if (!(b2 & 0x80)) - b |= 0x80; - if (!(b2 & 0x40)) - b |= 0x08; - if (cwc.type >= CATWEASEL_TYPE_MK4) { - b &= ~0x80; - catweasel_do_bput(3, 0x81); - if (!(catweasel_do_bget(0x07) & 0x10)) - b |= 0x80; - b2 = catweasel_do_bget(0xd0) ^ 15; - catweasel_do_bput(3, 0x41); - if (cwc.sid[0]) { - b2 &= ~(1 | 2); - if (sid_read(0x19, 0) > 0x7f) - b2 |= 2; - if (sid_read(0x1a, 0) > 0x7f) - b2 |= 1; - } - if (cwc.sid[1]) { - b2 &= ~(4 | 8); - if (sid_read(0x19, 1) > 0x7f) - b2 |= 8; - if (sid_read(0x1a, 1) > 0x7f) - b2 |= 4; + uae_u8 b, b2; + + b = 0; + if (cwc.type < CATWEASEL_TYPE_MK3 || !cwc.direct_access) + return b; + hsync_request(); + b2 = catweasel_do_bget(0xc8) & (0x80 | 0x40); + if (!(b2 & 0x80)) + b |= 0x80; + if (!(b2 & 0x40)) + b |= 0x08; + if (cwc.type >= CATWEASEL_TYPE_MK4) { + b &= ~0x80; + catweasel_do_bput(3, 0x81); + if (!(catweasel_do_bget(0x07) & 0x10)) + b |= 0x80; + b2 = catweasel_do_bget(0xd0) ^ 15; + catweasel_do_bput(3, 0x41); + if (cwc.sid[0]) { + b2 &= ~(1 | 2); + if (sid_read(0x19, 0) > 0x7f) + b2 |= 2; + if (sid_read(0x1a, 0) > 0x7f) + b2 |= 1; + } + if (cwc.sid[1]) { + b2 &= ~(4 | 8); + if (sid_read(0x19, 1) > 0x7f) + b2 |= 8; + if (sid_read(0x1a, 1) > 0x7f) + b2 |= 4; + } + } else { + b2 = cwmk3port1 | (cwmk3port2 << 2); } - } else { - b2 = cwmk3port1 | (cwmk3port2 << 2); - } - b |= (b2 & (8 | 4)) << 3; - b |= (b2 & (1 | 2)) << 1; - return b; + b |= (b2 & (8 | 4)) << 3; + b |= (b2 & (1 | 2)) << 1; + return b; } int catweasel_read_mouse (int port, int *dx, int *dy, int *buttons) { - if (!cwc.can_mouse || !cwc.direct_access) - return 0; - hsync_request(); - *dx = mouse_x[port]; - mouse_x[port] = 0; - *dy = mouse_y[port]; - mouse_y[port] = 0; - *buttons = (get_buttons() >> (port * 4)) & 15; - return 1; + if (!cwc.can_mouse || !cwc.direct_access) + return 0; + hsync_request(); + *dx = mouse_x[port]; + mouse_x[port] = 0; + *dy = mouse_y[port]; + mouse_y[port] = 0; + *buttons = (get_buttons() >> (port * 4)) & 15; + return 1; } static void sid_reset (void) { - int i; - for (i = 0; i < 0x19; i++) { - sid_write(i, 0, 0); - sid_write(i, 0, 1); - } + int i; + for (i = 0; i < 0x19; i++) { + sid_write(i, 0, 0); + sid_write(i, 0, 1); + } } static void catweasel_detect_sid (void) { - int i, j; - uae_u8 b1, b2; - - cwc.sid[0] = cwc.sid[1] = 0; - if (!cwc.can_sid || !cwc.direct_access) - return; - sid_reset(); - if (cwc.type >= CATWEASEL_TYPE_MK4) { - catweasel_do_bput(3, 0x81); - b1 = catweasel_do_bget(0xd0); - for (i = 0; i < 100; i++) { - sid_read(0x19, 0); // delay - b2 = catweasel_do_bget(0xd0); - if ((b1 & 3) != (b2 & 3)) - cwc.sid[0] = 6581; - if ((b1 & 12) != (b2 & 12)) - cwc.sid[1] = 6581; - } - } - catweasel_do_bput(3, 0x41); - for (i = 0; i < 2 ;i++) { + int i, j; + uae_u8 b1, b2; + + cwc.sid[0] = cwc.sid[1] = 0; + if (!cwc.can_sid || !cwc.direct_access) + return; sid_reset(); - sid_write(0x0f, 0xff, i); - sid_write(0x12, 0x10, i); - for(j = 0; j != 1000; j++) { - sid_write(0, 0, i); - if((sid_read(0x1b, i) & 0x80) != 0) { - cwc.sid[i] = 6581; - break; - } + if (cwc.type >= CATWEASEL_TYPE_MK4) { + catweasel_do_bput(3, 0x81); + b1 = catweasel_do_bget(0xd0); + for (i = 0; i < 100; i++) { + sid_read(0x19, 0); // delay + b2 = catweasel_do_bget(0xd0); + if ((b1 & 3) != (b2 & 3)) + cwc.sid[0] = 6581; + if ((b1 & 12) != (b2 & 12)) + cwc.sid[1] = 6581; + } } - sid_reset(); - sid_write(0x0f, 0xff, i); - sid_write(0x12, 0x30, i); - for(j = 0; j != 1000; j++) { - sid_write(0, 0, i); - if((sid_read(0x1b, i) & 0x80) != 0) { - cwc.sid[i] = 8580; - break; - } + catweasel_do_bput(3, 0x41); + for (i = 0; i < 2 ;i++) { + sid_reset(); + sid_write(0x0f, 0xff, i); + sid_write(0x12, 0x10, i); + for(j = 0; j != 1000; j++) { + sid_write(0, 0, i); + if((sid_read(0x1b, i) & 0x80) != 0) { + cwc.sid[i] = 6581; + break; + } + } + sid_reset(); + sid_write(0x0f, 0xff, i); + sid_write(0x12, 0x30, i); + for(j = 0; j != 1000; j++) { + sid_write(0, 0, i); + if((sid_read(0x1b, i) & 0x80) != 0) { + cwc.sid[i] = 8580; + break; + } + } } - } - sid_reset(); + sid_reset(); } void catweasel_hsync (void) { - int i; - - if (cwc.type < CATWEASEL_TYPE_MK3 || !cwc.direct_access) - return; - cwhsync--; - if (cwhsync > 0) - return; - cwhsync = 10; - if (handshake) { - /* keyboard handshake */ - catweasel_do_bput (0xd0, 0); - handshake = 0; - } - if (hsync_requested < 0) - return; - hsync_requested--; - if (cwc.type == CATWEASEL_TYPE_MK3 && cwc.sid[0]) { - uae_u8 b; - cwmk3buttonsync--; - if (cwmk3buttonsync <= 0) { - cwmk3buttonsync = 30; - b = 0; - if (sid_read (0x19, 0) > 0x7f) - b |= 2; - if (sid_read (0x1a, 0) > 0x7f) - b |= 1; - if (cwmk3port == 0) { - cwmk3port1 = b; - catweasel_do_bput (0xd4, 0); // select port2 - cwmk3port = 1; - } else { - cwmk3port2 = b; - catweasel_do_bget (0xd4); // select port1 - cwmk3port = 0; - } + int i; + + if (cwc.type < CATWEASEL_TYPE_MK3 || !cwc.direct_access) + return; + cwhsync--; + if (cwhsync > 0) + return; + cwhsync = 10; + if (handshake) { + /* keyboard handshake */ + catweasel_do_bput (0xd0, 0); + handshake = 0; } - } - if (!cwc.can_mouse) - return; - /* read MK4 mouse counters */ - catweasel_do_bput (3, 0x81); - for (i = 0; i < 2; i++) { - int x, y, dx, dy; - x = (uae_s8)catweasel_do_bget (0xc4 + i * 8); - y = (uae_s8)catweasel_do_bget (0xc0 + i * 8); - dx = mouse_px[i] - x; - if (dx > 127) - dx = 255 - dx; - if (dx < -128) - dx = 255 + dx; - dy = mouse_py[i] - y; - if (dy > 127) - dy = 255 - dy; - if (dy < -128) - dy = 255 + dy; - mouse_x[i] -= dx; - mouse_y[i] -= dy; - mouse_px[i] = x; - mouse_py[i] = y; - } - catweasel_do_bput (3, 0x41); + if (hsync_requested < 0) + return; + hsync_requested--; + if (cwc.type == CATWEASEL_TYPE_MK3 && cwc.sid[0]) { + uae_u8 b; + cwmk3buttonsync--; + if (cwmk3buttonsync <= 0) { + cwmk3buttonsync = 30; + b = 0; + if (sid_read (0x19, 0) > 0x7f) + b |= 2; + if (sid_read (0x1a, 0) > 0x7f) + b |= 1; + if (cwmk3port == 0) { + cwmk3port1 = b; + catweasel_do_bput (0xd4, 0); // select port2 + cwmk3port = 1; + } else { + cwmk3port2 = b; + catweasel_do_bget (0xd4); // select port1 + cwmk3port = 0; + } + } + } + if (!cwc.can_mouse) + return; + /* read MK4 mouse counters */ + catweasel_do_bput (3, 0x81); + for (i = 0; i < 2; i++) { + int x, y, dx, dy; + x = (uae_s8)catweasel_do_bget (0xc4 + i * 8); + y = (uae_s8)catweasel_do_bget (0xc0 + i * 8); + dx = mouse_px[i] - x; + if (dx > 127) + dx = 255 - dx; + if (dx < -128) + dx = 255 + dx; + dy = mouse_py[i] - y; + if (dy > 127) + dy = 255 - dy; + if (dy < -128) + dy = 255 + dy; + mouse_x[i] -= dx; + mouse_y[i] -= dy; + mouse_px[i] = x; + mouse_py[i] = y; + } + catweasel_do_bput (3, 0x41); } int catweasel_read_joystick (uae_u8 *dir, uae_u8 *buttons) { - if (!cwc.can_joy || !cwc.direct_access) - return 0; - hsync_request (); - *dir = catweasel_do_bget (0xc0); - *buttons = get_buttons (); - return 1; + if (!cwc.can_joy || !cwc.direct_access) + return 0; + hsync_request (); + *dir = catweasel_do_bget (0xc0); + *buttons = get_buttons (); + return 1; } int catweasel_read_keyboard (uae_u8 *keycode) { - uae_u8 v; + uae_u8 v; - if (!cwc.can_kb || !cwc.direct_access) - return 0; - if (!currprefs.catweasel) - return 0; - v = catweasel_do_bget (0xd4); - if (!(v & 0x80)) - return 0; - if (handshake) - return 0; - *keycode = catweasel_do_bget (0xd0); - catweasel_do_bput (0xd0, 0); - handshake = 1; - return 1; + if (!cwc.can_kb || !cwc.direct_access) + return 0; + if (!currprefs.catweasel) + return 0; + v = catweasel_do_bget (0xd4); + if (!(v & 0x80)) + return 0; + if (handshake) + return 0; + *keycode = catweasel_do_bget (0xd0); + catweasel_do_bput (0xd0, 0); + handshake = 1; + return 1; } uae_u32 catweasel_do_bget (uaecptr addr) { - DWORD did_read = 0; - uae_u8 buf1[1], buf2[1]; + DWORD did_read = 0; + uae_u8 buf1[1], buf2[1]; - if (addr >= 0x100) - return 0; - buf1[0] = (uae_u8)addr; - if (handle != INVALID_HANDLE_VALUE) { - if (!DeviceIoControl (handle, CW_PEEKREG_FULL, buf1, 1, buf2, 1, &did_read, 0)) - write_log (L"catweasel_do_bget %02x fail err=%d\n", buf1[0], GetLastError ()); - } else { - buf2[0] = ioport_read (cwc.iobase + addr); - } - //write_log (L"G %02X %02X %d\n", buf1[0], buf2[0], did_read); - return buf2[0]; + if (addr >= 0x100) + return 0; + buf1[0] = (uae_u8)addr; + if (handle != INVALID_HANDLE_VALUE) { + if (!DeviceIoControl (handle, CW_PEEKREG_FULL, buf1, 1, buf2, 1, &did_read, 0)) + write_log (L"catweasel_do_bget %02x fail err=%d\n", buf1[0], GetLastError ()); + } else { + buf2[0] = ioport_read (cwc.iobase + addr); + } + //write_log (L"G %02X %02X %d\n", buf1[0], buf2[0], did_read); + return buf2[0]; } void catweasel_do_bput (uaecptr addr, uae_u32 b) { - uae_u8 buf[2]; - DWORD did_read = 0; - - if (addr >= 0x100) - return; - buf[0] = (uae_u8)addr; - buf[1] = b; - if (handle != INVALID_HANDLE_VALUE) { - if (!DeviceIoControl (handle, CW_POKEREG_FULL, buf, 2, 0, 0, &did_read, 0)) - write_log (L"catweasel_do_bput %02x=%02x fail err=%d\n", buf[0], buf[1], GetLastError ()); - } else { - ioport_write (cwc.iobase + addr, b); - } - //write_log (L"P %02X %02X %d\n", (uae_u8)addr, (uae_u8)b, did_read); + uae_u8 buf[2]; + DWORD did_read = 0; + + if (addr >= 0x100) + return; + buf[0] = (uae_u8)addr; + buf[1] = b; + if (handle != INVALID_HANDLE_VALUE) { + if (!DeviceIoControl (handle, CW_POKEREG_FULL, buf, 2, 0, 0, &did_read, 0)) + write_log (L"catweasel_do_bput %02x=%02x fail err=%d\n", buf[0], buf[1], GetLastError ()); + } else { + ioport_write (cwc.iobase + addr, b); + } + //write_log (L"P %02X %02X %d\n", (uae_u8)addr, (uae_u8)b, did_read); } #include "core.cw4.c" static int cw_config_done (void) { - return ioport_read (cwc.iobase + 7) & 4; + return ioport_read (cwc.iobase + 7) & 4; } static int cw_fpga_ready (void) { - return ioport_read (cwc.iobase + 7) & 8; + return ioport_read (cwc.iobase + 7) & 8; } static void cw_resetFPGA (void) { - ioport_write (cwc.iobase + 2, 227); - ioport_write (cwc.iobase + 3, 0); - sleep_millis (10); - ioport_write (cwc.iobase + 3, 65); + ioport_write (cwc.iobase + 2, 227); + ioport_write (cwc.iobase + 3, 0); + sleep_millis (10); + ioport_write (cwc.iobase + 3, 65); } static int catweasel3_configure (void) { - ioport_write (cwc.iobase, 241); - ioport_write (cwc.iobase + 1, 0); - ioport_write (cwc.iobase + 2, 0); - ioport_write (cwc.iobase + 4, 0); - ioport_write (cwc.iobase + 5, 0); - ioport_write (cwc.iobase + 0x29, 0); - ioport_write (cwc.iobase + 0x2b, 0); - return 1; + ioport_write (cwc.iobase, 241); + ioport_write (cwc.iobase + 1, 0); + ioport_write (cwc.iobase + 2, 0); + ioport_write (cwc.iobase + 4, 0); + ioport_write (cwc.iobase + 5, 0); + ioport_write (cwc.iobase + 0x29, 0); + ioport_write (cwc.iobase + 0x2b, 0); + return 1; } static int catweasel4_configure (void) { - struct zfile *f; - time_t t; - - ioport_write (cwc.iobase, 241); - ioport_write (cwc.iobase + 1, 0); - ioport_write (cwc.iobase + 2, 227); - ioport_write (cwc.iobase + 3, 65); - ioport_write (cwc.iobase + 4, 0); - ioport_write (cwc.iobase + 5, 0); - ioport_write (cwc.iobase + 0x29, 0); - ioport_write (cwc.iobase + 0x2b, 0); - sleep_millis(10); - - if (cw_config_done()) { - write_log (L"CW: FPGA already configured, skipping core upload\n"); - return 1; - } - cw_resetFPGA(); - sleep_millis(10); - if (cw_config_done()) { - write_log (L"CW: FPGA failed to reset!\n"); - return 0; - } - f = zfile_fopen(L"core.cw4", L"rb", ZFD_NORMAL); - if (!f) { - f = zfile_fopen_data (L"core.cw4.gz", core_len, core); - f = zfile_gunzip (f); - } - write_log (L"CW: starting core upload, this will take few seconds\n"); - t = time(NULL) + 10; // give up if upload takes more than 10s - for (;;) { - uae_u8 b; - if (zfile_fread (&b, 1, 1, f) != 1) - break; - ioport_write (cwc.iobase + 3, (b & 1) ? 67 : 65); - while (!cw_fpga_ready()) { - if (time(NULL) >= t) { - write_log (L"CW: FPGA core upload got stuck!?\n"); + struct zfile *f; + time_t t; + + ioport_write (cwc.iobase, 241); + ioport_write (cwc.iobase + 1, 0); + ioport_write (cwc.iobase + 2, 227); + ioport_write (cwc.iobase + 3, 65); + ioport_write (cwc.iobase + 4, 0); + ioport_write (cwc.iobase + 5, 0); + ioport_write (cwc.iobase + 0x29, 0); + ioport_write (cwc.iobase + 0x2b, 0); + sleep_millis(10); + + if (cw_config_done()) { + write_log (L"CW: FPGA already configured, skipping core upload\n"); + return 1; + } + cw_resetFPGA(); + sleep_millis(10); + if (cw_config_done()) { + write_log (L"CW: FPGA failed to reset!\n"); + return 0; + } + f = zfile_fopen(L"core.cw4", L"rb", ZFD_NORMAL); + if (!f) { + f = zfile_fopen_data (L"core.cw4.gz", core_len, core); + f = zfile_gunzip (f); + } + write_log (L"CW: starting core upload, this will take few seconds\n"); + t = time(NULL) + 10; // give up if upload takes more than 10s + for (;;) { + uae_u8 b; + if (zfile_fread (&b, 1, 1, f) != 1) + break; + ioport_write (cwc.iobase + 3, (b & 1) ? 67 : 65); + while (!cw_fpga_ready()) { + if (time(NULL) >= t) { + write_log (L"CW: FPGA core upload got stuck!?\n"); + cw_resetFPGA(); + return 0; + } + } + ioport_write (cwc.iobase + 192, b); + } + if (!cw_config_done()) { + write_log (L"CW: FPGA didn't accept the core!\n"); cw_resetFPGA(); return 0; - } } - ioport_write (cwc.iobase + 192, b); - } - if (!cw_config_done()) { - write_log (L"CW: FPGA didn't accept the core!\n"); - cw_resetFPGA(); - return 0; - } - sleep_millis(10); - write_log (L"CW: core uploaded successfully\n"); - return 1; + sleep_millis(10); + write_log (L"CW: core uploaded successfully\n"); + return 1; } #include @@ -408,310 +408,310 @@ extern int os_winnt; int force_direct_catweasel; static int direct_detect(void) { - HDEVINFO devs; - SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail; - SP_DEVINFO_DATA devInfo; - int devIndex; - int cw = 0; + HDEVINFO devs; + SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail; + SP_DEVINFO_DATA devInfo; + int devIndex; + int cw = 0; - if (!os_winnt) - return 0; - devs = SetupDiGetClassDevsEx(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT, NULL, NULL, NULL); - if (devs == INVALID_HANDLE_VALUE) - return 0; - devInfoListDetail.cbSize = sizeof(devInfoListDetail); - if(SetupDiGetDeviceInfoListDetail(devs,&devInfoListDetail)) { - devInfo.cbSize = sizeof(devInfo); - for(devIndex=0;SetupDiEnumDeviceInfo(devs,devIndex,&devInfo);devIndex++) { - TCHAR devID[MAX_DEVICE_ID_LEN]; - if(CM_Get_Device_ID_Ex(devInfo.DevInst,devID,MAX_DEVICE_ID_LEN,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS) - devID[0] = TEXT('\0'); - if (!_tcsncmp (devID, PCI_CW_MK3, _tcslen (PCI_CW_MK3))) { - if (cw > 3) - break; - cw = 3; - } - if (!_tcsncmp (devID, PCI_CW_MK4, _tcslen (PCI_CW_MK4)) || - !_tcsncmp (devID, PCI_CW_MK4_BUG, _tcslen (PCI_CW_MK4_BUG))) - cw = 4; - if (cw) { - SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail; - ULONG status = 0; - ULONG problem = 0; - LOG_CONF config = 0; - BOOL haveConfig = FALSE; - ULONG dataSize; - PBYTE resDesData; - RES_DES prevResDes, resDes; - RESOURCEID resId = ResType_IO; - - devInfoListDetail.cbSize = sizeof(devInfoListDetail); - if((!SetupDiGetDeviceInfoListDetail(devs,&devInfoListDetail)) || - (CM_Get_DevNode_Status_Ex(&status,&problem,devInfo.DevInst,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS)) - break; - if(!(status & DN_HAS_PROBLEM)) { - if (CM_Get_First_Log_Conf_Ex(&config, - devInfo.DevInst, - ALLOC_LOG_CONF, - devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { - haveConfig = TRUE; - } - } - if(!haveConfig) { - if (CM_Get_First_Log_Conf_Ex(&config, - devInfo.DevInst, - FORCED_LOG_CONF, - devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { - haveConfig = TRUE; - } - } - if(!haveConfig) { - if(!(status & DN_HAS_PROBLEM) || (problem != CM_PROB_HARDWARE_DISABLED)) { - if (CM_Get_First_Log_Conf_Ex(&config, - devInfo.DevInst, - BOOT_LOG_CONF, - devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { - haveConfig = TRUE; + if (!os_winnt) + return 0; + devs = SetupDiGetClassDevsEx(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT, NULL, NULL, NULL); + if (devs == INVALID_HANDLE_VALUE) + return 0; + devInfoListDetail.cbSize = sizeof(devInfoListDetail); + if(SetupDiGetDeviceInfoListDetail(devs,&devInfoListDetail)) { + devInfo.cbSize = sizeof(devInfo); + for(devIndex=0;SetupDiEnumDeviceInfo(devs,devIndex,&devInfo);devIndex++) { + TCHAR devID[MAX_DEVICE_ID_LEN]; + if(CM_Get_Device_ID_Ex(devInfo.DevInst,devID,MAX_DEVICE_ID_LEN,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS) + devID[0] = TEXT('\0'); + if (!_tcsncmp (devID, PCI_CW_MK3, _tcslen (PCI_CW_MK3))) { + if (cw > 3) + break; + cw = 3; } - } - } - if(!haveConfig) - break; - prevResDes = (RES_DES)config; - resDes = 0; - while(CM_Get_Next_Res_Des_Ex(&resDes,prevResDes,ResType_IO,&resId,0,NULL)==CR_SUCCESS) { - if(prevResDes != config) - CM_Free_Res_Des_Handle(prevResDes); - prevResDes = resDes; - if(CM_Get_Res_Des_Data_Size_Ex(&dataSize,resDes,0,NULL)!=CR_SUCCESS) - continue; - resDesData = (PBYTE)malloc (dataSize); - if(!resDesData) - continue; - if(CM_Get_Res_Des_Data_Ex(resDes,resDesData,dataSize,0,NULL)!=CR_SUCCESS) { - free (resDesData); - continue; - } - if (resId == ResType_IO) { - PIO_RESOURCE pIoData = (PIO_RESOURCE)resDesData; - if(pIoData->IO_Header.IOD_Alloc_End-pIoData->IO_Header.IOD_Alloc_Base+1) { - write_log (L"CW: PCI SCAN: CWMK%d @%I64X - %I64X\n", cw, - pIoData->IO_Header.IOD_Alloc_Base,pIoData->IO_Header.IOD_Alloc_End); - cwc.iobase = (int)pIoData->IO_Header.IOD_Alloc_Base; - cwc.direct_type = cw; + if (!_tcsncmp (devID, PCI_CW_MK4, _tcslen (PCI_CW_MK4)) || + !_tcsncmp (devID, PCI_CW_MK4_BUG, _tcslen (PCI_CW_MK4_BUG))) + cw = 4; + if (cw) { + SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail; + ULONG status = 0; + ULONG problem = 0; + LOG_CONF config = 0; + BOOL haveConfig = FALSE; + ULONG dataSize; + PBYTE resDesData; + RES_DES prevResDes, resDes; + RESOURCEID resId = ResType_IO; + + devInfoListDetail.cbSize = sizeof(devInfoListDetail); + if((!SetupDiGetDeviceInfoListDetail(devs,&devInfoListDetail)) || + (CM_Get_DevNode_Status_Ex(&status,&problem,devInfo.DevInst,0,devInfoListDetail.RemoteMachineHandle)!=CR_SUCCESS)) + break; + if(!(status & DN_HAS_PROBLEM)) { + if (CM_Get_First_Log_Conf_Ex(&config, + devInfo.DevInst, + ALLOC_LOG_CONF, + devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { + haveConfig = TRUE; + } + } + if(!haveConfig) { + if (CM_Get_First_Log_Conf_Ex(&config, + devInfo.DevInst, + FORCED_LOG_CONF, + devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { + haveConfig = TRUE; + } + } + if(!haveConfig) { + if(!(status & DN_HAS_PROBLEM) || (problem != CM_PROB_HARDWARE_DISABLED)) { + if (CM_Get_First_Log_Conf_Ex(&config, + devInfo.DevInst, + BOOT_LOG_CONF, + devInfoListDetail.RemoteMachineHandle) == CR_SUCCESS) { + haveConfig = TRUE; + } + } + } + if(!haveConfig) + break; + prevResDes = (RES_DES)config; + resDes = 0; + while(CM_Get_Next_Res_Des_Ex(&resDes,prevResDes,ResType_IO,&resId,0,NULL)==CR_SUCCESS) { + if(prevResDes != config) + CM_Free_Res_Des_Handle(prevResDes); + prevResDes = resDes; + if(CM_Get_Res_Des_Data_Size_Ex(&dataSize,resDes,0,NULL)!=CR_SUCCESS) + continue; + resDesData = (PBYTE)malloc (dataSize); + if(!resDesData) + continue; + if(CM_Get_Res_Des_Data_Ex(resDes,resDesData,dataSize,0,NULL)!=CR_SUCCESS) { + free (resDesData); + continue; + } + if (resId == ResType_IO) { + PIO_RESOURCE pIoData = (PIO_RESOURCE)resDesData; + if(pIoData->IO_Header.IOD_Alloc_End-pIoData->IO_Header.IOD_Alloc_Base+1) { + write_log (L"CW: PCI SCAN: CWMK%d @%I64X - %I64X\n", cw, + pIoData->IO_Header.IOD_Alloc_Base,pIoData->IO_Header.IOD_Alloc_End); + cwc.iobase = (int)pIoData->IO_Header.IOD_Alloc_Base; + cwc.direct_type = cw; + } + } + free (resDesData); + } + if(prevResDes != config) + CM_Free_Res_Des_Handle(prevResDes); + CM_Free_Log_Conf_Handle(config); } - } - free (resDesData); } - if(prevResDes != config) - CM_Free_Res_Des_Handle(prevResDes); - CM_Free_Log_Conf_Handle(config); - } } - } - SetupDiDestroyDeviceInfoList(devs); - if (cw) { - if (!ioport_init ()) - cw = 0; - } - return cw; + SetupDiDestroyDeviceInfoList(devs); + if (cw) { + if (!ioport_init ()) + cw = 0; + } + return cw; } static int detected; int catweasel_init(void) { - TCHAR name[32], tmp[1000], *s; - int i, len; - uae_u8 buffer[10000]; - uae_u32 model, base; - int detect = 0; + TCHAR name[32], tmp[1000], *s; + int i, len; + uae_u8 buffer[10000]; + uae_u32 model, base; + int detect = 0; - if (cwc.type) - return 1; + if (cwc.type) + return 1; + + if (force_direct_catweasel >= 100) { - if (force_direct_catweasel >= 100) { + cwc.iobase = force_direct_catweasel & 0xffff; + if (force_direct_catweasel > 0xffff) { + cwc.direct_type = force_direct_catweasel >> 16; + } else { + cwc.direct_type = force_direct_catweasel >= 0x400 ? 3 : 1; + } + cwc.direct_access = 1; - cwc.iobase = force_direct_catweasel & 0xffff; - if (force_direct_catweasel > 0xffff) { - cwc.direct_type = force_direct_catweasel >> 16; } else { - cwc.direct_type = force_direct_catweasel >= 0x400 ? 3 : 1; - } - cwc.direct_access = 1; - - } else { - for (i = 0; i < 4; i++) { - if (currprefs.catweasel > 0) - i = currprefs.catweasel; - if (currprefs.catweasel < 0) - i = -currprefs.catweasel + 1; - _stprintf (name, L"\\\\.\\CAT%d_F0", i); - handle = CreateFile (name, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (handle != INVALID_HANDLE_VALUE || currprefs.catweasel > 0) - break; - } - if (handle == INVALID_HANDLE_VALUE) - catweasel_detect(); - cwc.direct_access = 0; - if (currprefs.catweasel < 0) - cwc.direct_access = 1; - } - - if (handle == INVALID_HANDLE_VALUE) { - _tcscpy (name, L"[DIRECT]"); - if (cwc.direct_type && ioport_init()) { - cwc.direct_access = 1; - if (cwc.direct_type == 4 && catweasel4_configure()) { - cwc.type = 4; - cwc.can_joy = 2; - cwc.can_sid = 2; - cwc.can_kb = 1; - cwc.can_mouse = 2; - } else if (cwc.direct_type == 3 && catweasel3_configure()) { - cwc.type = 3; - cwc.can_joy = 1; - cwc.can_sid = 1; - cwc.can_kb = 1; - cwc.can_mouse = 0; - } - } - if (cwc.type == 0) { - write_log (L"CW: No Catweasel detected\n"); - goto fail; + for (i = 0; i < 4; i++) { + if (currprefs.catweasel > 0) + i = currprefs.catweasel; + if (currprefs.catweasel < 0) + i = -currprefs.catweasel + 1; + _stprintf (name, L"\\\\.\\CAT%d_F0", i); + handle = CreateFile (name, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (handle != INVALID_HANDLE_VALUE || currprefs.catweasel > 0) + break; + } + if (handle == INVALID_HANDLE_VALUE) + catweasel_detect(); + cwc.direct_access = 0; + if (currprefs.catweasel < 0) + cwc.direct_access = 1; } - } - if (!cwc.direct_type) { - if (!DeviceIoControl (handle, CW_GET_VERSION, 0, 0, buffer, sizeof (buffer), &len, 0)) { - write_log (L"CW: CW_GET_VERSION failed %d\n", GetLastError ()); - goto fail; - } - s = au (buffer); - write_log (L"CW driver version string '%s'\n", s); - xfree (s); - if (!DeviceIoControl (handle, CW_GET_HWVERSION, 0, 0, buffer, sizeof (buffer), &len, 0)) { - write_log (L"CW: CW_GET_HWVERSION failed %d\n", GetLastError ()); - goto fail; - } - write_log (L"CW: v=%d 14=%d 28=%d 56=%d joy=%d dpm=%d sid=%d kb=%d sidfifo=%d\n", - buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], - buffer[6], buffer[7], ((uae_u32*)(buffer + 8))[0]); - cwc.can_joy = (buffer[4] & 1) ? 2 : 0; - cwc.can_sid = buffer[6] ? 1 : 0; - cwc.can_kb = buffer[7] & 1; - cwc.can_mouse = (buffer[4] & 2) ? 2 : 0; - if (!DeviceIoControl (handle, CW_LOCK_EXCLUSIVE, 0, 0, buffer, sizeof (buffer), &len, 0)) { - write_log (L"CW: CW_LOCK_EXCLUSIVE failed %d\n", GetLastError ()); - goto fail; + if (handle == INVALID_HANDLE_VALUE) { + _tcscpy (name, L"[DIRECT]"); + if (cwc.direct_type && ioport_init()) { + cwc.direct_access = 1; + if (cwc.direct_type == 4 && catweasel4_configure()) { + cwc.type = 4; + cwc.can_joy = 2; + cwc.can_sid = 2; + cwc.can_kb = 1; + cwc.can_mouse = 2; + } else if (cwc.direct_type == 3 && catweasel3_configure()) { + cwc.type = 3; + cwc.can_joy = 1; + cwc.can_sid = 1; + cwc.can_kb = 1; + cwc.can_mouse = 0; + } + } + if (cwc.type == 0) { + write_log (L"CW: No Catweasel detected\n"); + goto fail; + } } - model = *((uae_u32*)(buffer + 4)); - base = *((uae_u32*)(buffer + 0)); - cwc.type = model == 0 ? 1 : model == 2 ? 4 : 3; - cwc.iobase = base; - if (!cwc.direct_access) { - if (!DeviceIoControl (handle, CW_UNLOCK_EXCLUSIVE, 0, 0, 0, 0, &len, 0)) { - write_log (L"CW: CW_UNLOCK_EXCLUSIVE failed %d\n", GetLastError ()); - } + + if (!cwc.direct_type) { + if (!DeviceIoControl (handle, CW_GET_VERSION, 0, 0, buffer, sizeof (buffer), &len, 0)) { + write_log (L"CW: CW_GET_VERSION failed %d\n", GetLastError ()); + goto fail; + } + s = au (buffer); + write_log (L"CW driver version string '%s'\n", s); + xfree (s); + if (!DeviceIoControl (handle, CW_GET_HWVERSION, 0, 0, buffer, sizeof (buffer), &len, 0)) { + write_log (L"CW: CW_GET_HWVERSION failed %d\n", GetLastError ()); + goto fail; + } + write_log (L"CW: v=%d 14=%d 28=%d 56=%d joy=%d dpm=%d sid=%d kb=%d sidfifo=%d\n", + buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], + buffer[6], buffer[7], ((uae_u32*)(buffer + 8))[0]); + cwc.can_joy = (buffer[4] & 1) ? 2 : 0; + cwc.can_sid = buffer[6] ? 1 : 0; + cwc.can_kb = buffer[7] & 1; + cwc.can_mouse = (buffer[4] & 2) ? 2 : 0; + if (!DeviceIoControl (handle, CW_LOCK_EXCLUSIVE, 0, 0, buffer, sizeof (buffer), &len, 0)) { + write_log (L"CW: CW_LOCK_EXCLUSIVE failed %d\n", GetLastError ()); + goto fail; + } + model = *((uae_u32*)(buffer + 4)); + base = *((uae_u32*)(buffer + 0)); + cwc.type = model == 0 ? 1 : model == 2 ? 4 : 3; + cwc.iobase = base; + if (!cwc.direct_access) { + if (!DeviceIoControl (handle, CW_UNLOCK_EXCLUSIVE, 0, 0, 0, 0, &len, 0)) { + write_log (L"CW: CW_UNLOCK_EXCLUSIVE failed %d\n", GetLastError ()); + } + } + if (cwc.type == CATWEASEL_TYPE_MK4 && cwc.can_sid) + cwc.can_sid = 2; } - if (cwc.type == CATWEASEL_TYPE_MK4 && cwc.can_sid) - cwc.can_sid = 2; - } - - if (cwc.direct_access) { - if (cwc.type == CATWEASEL_TYPE_MK4) { - if (cwc.can_mouse) { - int i; - catweasel_do_bput (3, 0x81); - catweasel_do_bput (0xd0, 4|8); // amiga mouse + pullups - // clear mouse counters - for (i = 0; i < 2; i++) { - catweasel_do_bput (0xc4 + i * 8, 0); - catweasel_do_bput (0xc0 + i * 8, 0); + + if (cwc.direct_access) { + if (cwc.type == CATWEASEL_TYPE_MK4) { + if (cwc.can_mouse) { + int i; + catweasel_do_bput (3, 0x81); + catweasel_do_bput (0xd0, 4|8); // amiga mouse + pullups + // clear mouse counters + for (i = 0; i < 2; i++) { + catweasel_do_bput (0xc4 + i * 8, 0); + catweasel_do_bput (0xc0 + i * 8, 0); + } + } + catweasel_do_bput (3, 0x41); /* enable MK3-mode */ } - } - catweasel_do_bput (3, 0x41); /* enable MK3-mode */ + if (cwc.can_joy) + catweasel_do_bput (0xcc, 0); // joystick buttons = input } - if (cwc.can_joy) - catweasel_do_bput (0xcc, 0); // joystick buttons = input - } - - //catweasel_init_controller(&cwc); - _stprintf (tmp, L"CW: Catweasel MK%d @%08x (%s) enabled. %s.", - cwc.type, (int)cwc.iobase, name, cwc.direct_access ? L"DIRECTIO": L"API"); - if (cwc.direct_access) { - if (cwc.can_sid) { - TCHAR *p = tmp + _tcslen (tmp); - catweasel_detect_sid (); - _stprintf (p, L" SID0=%d", cwc.sid[0]); - if (cwc.can_sid > 1) { - p += _tcslen (p); - _stprintf (p, L" SID1=%d", cwc.sid[1]); - } + + //catweasel_init_controller(&cwc); + _stprintf (tmp, L"CW: Catweasel MK%d @%08x (%s) enabled. %s.", + cwc.type, (int)cwc.iobase, name, cwc.direct_access ? L"DIRECTIO": L"API"); + if (cwc.direct_access) { + if (cwc.can_sid) { + TCHAR *p = tmp + _tcslen (tmp); + catweasel_detect_sid (); + _stprintf (p, L" SID0=%d", cwc.sid[0]); + if (cwc.can_sid > 1) { + p += _tcslen (p); + _stprintf (p, L" SID1=%d", cwc.sid[1]); + } + } } - } - write_log (L"%s\n", tmp); - detected = 1; + write_log (L"%s\n", tmp); + detected = 1; - return 1; + return 1; fail: - catweasel_free (); - return 0; + catweasel_free (); + return 0; } void catweasel_free (void) { - if (cwc.direct_access) { - if (cwc.type == CATWEASEL_TYPE_MK4) - catweasel_do_bput(3, 0x61); // enable floppy passthrough - } - if (handle != INVALID_HANDLE_VALUE) - CloseHandle (handle); - handle = INVALID_HANDLE_VALUE; - ioport_free (); - memset (&cwc, 0, sizeof cwc); - mouse_x[0] = mouse_x[1] = mouse_y[0] = mouse_y[1] = 0; - mouse_px[0] = mouse_px[1] = mouse_py[0] = mouse_py[1] = 0; - cwmk3port = cwmk3port1 = cwmk3port2 = 0; - cwhsync = cwmk3buttonsync = 0; + if (cwc.direct_access) { + if (cwc.type == CATWEASEL_TYPE_MK4) + catweasel_do_bput(3, 0x61); // enable floppy passthrough + } + if (handle != INVALID_HANDLE_VALUE) + CloseHandle (handle); + handle = INVALID_HANDLE_VALUE; + ioport_free (); + memset (&cwc, 0, sizeof cwc); + mouse_x[0] = mouse_x[1] = mouse_y[0] = mouse_y[1] = 0; + mouse_px[0] = mouse_px[1] = mouse_py[0] = mouse_py[1] = 0; + cwmk3port = cwmk3port1 = cwmk3port2 = 0; + cwhsync = cwmk3buttonsync = 0; } int catweasel_detect (void) { - TCHAR name[32]; - int i; - HANDLE h; - - if (detected) - return detected < 0 ? 0 : 1; - - detected = -1; - for (i = 0; i < 4; i++) { - _stprintf (name, L"\\\\.\\CAT%u_F0", i); - h = CreateFile (name, GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (h != INVALID_HANDLE_VALUE) { - CloseHandle (h); - write_log (L"CW: Windows driver device detected '%s'\n", name); - detected = 1; - return TRUE; - } - } - if (h == INVALID_HANDLE_VALUE) { - if (force_direct_catweasel >= 100) { - if (ioport_init ()) - return TRUE; - return FALSE; + TCHAR name[32]; + int i; + HANDLE h; + + if (detected) + return detected < 0 ? 0 : 1; + + detected = -1; + for (i = 0; i < 4; i++) { + _stprintf (name, L"\\\\.\\CAT%u_F0", i); + h = CreateFile (name, GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (h != INVALID_HANDLE_VALUE) { + CloseHandle (h); + write_log (L"CW: Windows driver device detected '%s'\n", name); + detected = 1; + return TRUE; + } } - if (direct_detect ()) { - detected = 1; - return TRUE; + if (h == INVALID_HANDLE_VALUE) { + if (force_direct_catweasel >= 100) { + if (ioport_init ()) + return TRUE; + return FALSE; + } + if (direct_detect ()) { + detected = 1; + return TRUE; + } } - } - return FALSE; + return FALSE; } #endif \ No newline at end of file diff --git a/cd32_fmv.c b/cd32_fmv.c index ceaba01e..7ea43cb0 100644 --- a/cd32_fmv.c +++ b/cd32_fmv.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * CD32 FMV cartridge - * - * Copyright 2008 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* CD32 FMV cartridge +* +* Copyright 2008 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -57,92 +57,92 @@ static int fmv_size = 1048576; static uae_u8 fmv_bget2 (uaecptr addr) { #ifdef FMV_DEBUG - write_log (L"fmv_bget2 %08X PC=%8X\n", addr, M68K_GETPC); -#endif - if (addr >= rom_size && addr < 0x80000) { write_log (L"fmv_bget2 %08X PC=%8X\n", addr, M68K_GETPC); - return 0; - } - return rom[addr]; +#endif + if (addr >= rom_size && addr < 0x80000) { + write_log (L"fmv_bget2 %08X PC=%8X\n", addr, M68K_GETPC); + return 0; + } + return rom[addr]; } static void fmv_bput2 (uaecptr addr, uae_u8 v) { - if (addr >= rom_size && addr < 0x80000) { - write_log (L"fmv_bput2 %08X=%02X PC=%8X\n", addr, v & 0xff, M68K_GETPC); - } + if (addr >= rom_size && addr < 0x80000) { + write_log (L"fmv_bput2 %08X=%02X PC=%8X\n", addr, v & 0xff, M68K_GETPC); + } } static uae_u32 REGPARAM2 fmv_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - v = (fmv_bget2 (addr) << 24) | (fmv_bget2 (addr + 1) << 16) | - (fmv_bget2 (addr + 2) << 8) | (fmv_bget2 (addr + 3)); + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + v = (fmv_bget2 (addr) << 24) | (fmv_bget2 (addr + 1) << 16) | + (fmv_bget2 (addr + 2) << 8) | (fmv_bget2 (addr + 3)); #ifdef FMV_DEBUG - write_log (L"fmv_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"fmv_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 fmv_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - v = (fmv_bget2 (addr) << 8) | fmv_bget2 (addr + 1); + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + v = (fmv_bget2 (addr) << 8) | fmv_bget2 (addr + 1); #ifdef FMV_DEBUG - write_log (L"fmv_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"fmv_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 fmv_bget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - v = fmv_bget2 (addr); - return v; + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + v = fmv_bget2 (addr); + return v; } static void REGPARAM2 fmv_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; #ifdef FMV_DEBUG - write_log (L"fmv_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); + write_log (L"fmv_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); #endif - fmv_bput2 (addr, l >> 24); - fmv_bput2 (addr + 1, l >> 16); - fmv_bput2 (addr + 2, l >> 8); - fmv_bput2 (addr + 3, l); + fmv_bput2 (addr, l >> 24); + fmv_bput2 (addr + 1, l >> 16); + fmv_bput2 (addr + 2, l >> 8); + fmv_bput2 (addr + 3, l); } static void REGPARAM2 fmv_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; #ifdef FMV_DEBUG - write_log (L"fmv_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); + write_log (L"fmv_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); #endif - fmv_bput2 (addr, w >> 8); - fmv_bput2 (addr + 1, w); + fmv_bput2 (addr, w >> 8); + fmv_bput2 (addr + 1, w); } static addrbank fmv_bank; @@ -150,95 +150,95 @@ static addrbank fmv_bank; static void REGPARAM2 fmv_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - fmv_bput2 (addr, b); + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + fmv_bput2 (addr, b); } static uae_u32 REGPARAM2 fmv_wgeti (uaecptr addr) { - uae_u32 v = 0; - uae_u8 *m; + uae_u32 v = 0; + uae_u8 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - m = rom + addr; - if (addr < rom_size) - return do_get_mem_word ((uae_u16 *)m); + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + m = rom + addr; + if (addr < rom_size) + return do_get_mem_word ((uae_u16 *)m); #ifdef FMV_DEBUG - write_log (L"fmv_wgeti %08X %08X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"fmv_wgeti %08X %08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 fmv_lgeti (uaecptr addr) { - uae_u32 v = 0; - uae_u8 *m; + uae_u32 v = 0; + uae_u8 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - m = rom + addr; - if (addr < rom_size) - return do_get_mem_long ((uae_u32 *)m); + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + m = rom + addr; + if (addr < rom_size) + return do_get_mem_long ((uae_u32 *)m); #ifdef FMV_DEBUG - write_log (L"fmv_lgeti %08X %08X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"fmv_lgeti %08X %08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static int REGPARAM2 fmv_check (uaecptr addr, uae_u32 size) { - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - return (addr + size) <= fmv_size; + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + return (addr + size) <= fmv_size; } static uae_u8 *REGPARAM2 fmv_xlate (uaecptr addr) { - addr -= fmv_start & fmv_mask; - addr &= fmv_mask; - return rom + addr; + addr -= fmv_start & fmv_mask; + addr &= fmv_mask; + return rom + addr; } static addrbank fmv_bank = { - fmv_lget, fmv_wget, fmv_bget, - fmv_lput, fmv_wput, fmv_bput, - fmv_xlate, fmv_check, NULL, L"CD32 FMV module", - fmv_lgeti, fmv_wgeti, ABFLAG_ROM | ABFLAG_IO + fmv_lget, fmv_wget, fmv_bget, + fmv_lput, fmv_wput, fmv_bput, + fmv_xlate, fmv_check, NULL, L"CD32 FMV module", + fmv_lgeti, fmv_wgeti, ABFLAG_ROM | ABFLAG_IO }; void cd32_fmv_init (uaecptr start) { - int ids[] = { 23, -1 }; - struct romlist *rl = getromlistbyids (ids); - struct romdata *rd; - struct zfile *z; - - write_log (L"CD32 FMV mapped @$%lx\n", start); - if (start != fmv_start) - return; - if (!rl) - return; - rd = rl->rd; - z = read_rom (&rd); - if (z) { - write_log (L"CD32 FMV ROM %d.%d\n", rd->ver, rd->rev); - rom = mapped_malloc (fmv_size, L"fast"); - if (rom) - zfile_fread (rom, rd->size, 1, z); - zfile_fclose (z); - } - fmv_mask = fmv_size - 1; - fmv_bank.baseaddr = rom; - rom[0x282] = 0; - map_banks (&fmv_bank, start >> 16, fmv_size >> 16, 0); + int ids[] = { 23, -1 }; + struct romlist *rl = getromlistbyids (ids); + struct romdata *rd; + struct zfile *z; + + write_log (L"CD32 FMV mapped @$%lx\n", start); + if (start != fmv_start) + return; + if (!rl) + return; + rd = rl->rd; + z = read_rom (&rd); + if (z) { + write_log (L"CD32 FMV ROM %d.%d\n", rd->ver, rd->rev); + rom = mapped_malloc (fmv_size, L"fast"); + if (rom) + zfile_fread (rom, rd->size, 1, z); + zfile_fclose (z); + } + fmv_mask = fmv_size - 1; + fmv_bank.baseaddr = rom; + rom[0x282] = 0; + map_banks (&fmv_bank, start >> 16, fmv_size >> 16, 0); } diff --git a/cdrom.c b/cdrom.c index ad869605..793760a7 100644 --- a/cdrom.c +++ b/cdrom.c @@ -25,70 +25,70 @@ static const uae_u32 EDC_crctable[256] = { - 0x00000000L, 0x90910101L, 0x91210201L, 0x01B00300L, - 0x92410401L, 0x02D00500L, 0x03600600L, 0x93F10701L, - 0x94810801L, 0x04100900L, 0x05A00A00L, 0x95310B01L, - 0x06C00C00L, 0x96510D01L, 0x97E10E01L, 0x07700F00L, - 0x99011001L, 0x09901100L, 0x08201200L, 0x98B11301L, - 0x0B401400L, 0x9BD11501L, 0x9A611601L, 0x0AF01700L, - 0x0D801800L, 0x9D111901L, 0x9CA11A01L, 0x0C301B00L, - 0x9FC11C01L, 0x0F501D00L, 0x0EE01E00L, 0x9E711F01L, - 0x82012001L, 0x12902100L, 0x13202200L, 0x83B12301L, - 0x10402400L, 0x80D12501L, 0x81612601L, 0x11F02700L, - 0x16802800L, 0x86112901L, 0x87A12A01L, 0x17302B00L, - 0x84C12C01L, 0x14502D00L, 0x15E02E00L, 0x85712F01L, - 0x1B003000L, 0x8B913101L, 0x8A213201L, 0x1AB03300L, - 0x89413401L, 0x19D03500L, 0x18603600L, 0x88F13701L, - 0x8F813801L, 0x1F103900L, 0x1EA03A00L, 0x8E313B01L, - 0x1DC03C00L, 0x8D513D01L, 0x8CE13E01L, 0x1C703F00L, - 0xB4014001L, 0x24904100L, 0x25204200L, 0xB5B14301L, - 0x26404400L, 0xB6D14501L, 0xB7614601L, 0x27F04700L, - 0x20804800L, 0xB0114901L, 0xB1A14A01L, 0x21304B00L, - 0xB2C14C01L, 0x22504D00L, 0x23E04E00L, 0xB3714F01L, - 0x2D005000L, 0xBD915101L, 0xBC215201L, 0x2CB05300L, - 0xBF415401L, 0x2FD05500L, 0x2E605600L, 0xBEF15701L, - 0xB9815801L, 0x29105900L, 0x28A05A00L, 0xB8315B01L, - 0x2BC05C00L, 0xBB515D01L, 0xBAE15E01L, 0x2A705F00L, - 0x36006000L, 0xA6916101L, 0xA7216201L, 0x37B06300L, - 0xA4416401L, 0x34D06500L, 0x35606600L, 0xA5F16701L, - 0xA2816801L, 0x32106900L, 0x33A06A00L, 0xA3316B01L, - 0x30C06C00L, 0xA0516D01L, 0xA1E16E01L, 0x31706F00L, - 0xAF017001L, 0x3F907100L, 0x3E207200L, 0xAEB17301L, - 0x3D407400L, 0xADD17501L, 0xAC617601L, 0x3CF07700L, - 0x3B807800L, 0xAB117901L, 0xAAA17A01L, 0x3A307B00L, - 0xA9C17C01L, 0x39507D00L, 0x38E07E00L, 0xA8717F01L, - 0xD8018001L, 0x48908100L, 0x49208200L, 0xD9B18301L, - 0x4A408400L, 0xDAD18501L, 0xDB618601L, 0x4BF08700L, - 0x4C808800L, 0xDC118901L, 0xDDA18A01L, 0x4D308B00L, - 0xDEC18C01L, 0x4E508D00L, 0x4FE08E00L, 0xDF718F01L, - 0x41009000L, 0xD1919101L, 0xD0219201L, 0x40B09300L, - 0xD3419401L, 0x43D09500L, 0x42609600L, 0xD2F19701L, - 0xD5819801L, 0x45109900L, 0x44A09A00L, 0xD4319B01L, - 0x47C09C00L, 0xD7519D01L, 0xD6E19E01L, 0x46709F00L, - 0x5A00A000L, 0xCA91A101L, 0xCB21A201L, 0x5BB0A300L, - 0xC841A401L, 0x58D0A500L, 0x5960A600L, 0xC9F1A701L, - 0xCE81A801L, 0x5E10A900L, 0x5FA0AA00L, 0xCF31AB01L, - 0x5CC0AC00L, 0xCC51AD01L, 0xCDE1AE01L, 0x5D70AF00L, - 0xC301B001L, 0x5390B100L, 0x5220B200L, 0xC2B1B301L, - 0x5140B400L, 0xC1D1B501L, 0xC061B601L, 0x50F0B700L, - 0x5780B800L, 0xC711B901L, 0xC6A1BA01L, 0x5630BB00L, - 0xC5C1BC01L, 0x5550BD00L, 0x54E0BE00L, 0xC471BF01L, - 0x6C00C000L, 0xFC91C101L, 0xFD21C201L, 0x6DB0C300L, - 0xFE41C401L, 0x6ED0C500L, 0x6F60C600L, 0xFFF1C701L, - 0xF881C801L, 0x6810C900L, 0x69A0CA00L, 0xF931CB01L, - 0x6AC0CC00L, 0xFA51CD01L, 0xFBE1CE01L, 0x6B70CF00L, - 0xF501D001L, 0x6590D100L, 0x6420D200L, 0xF4B1D301L, - 0x6740D400L, 0xF7D1D501L, 0xF661D601L, 0x66F0D700L, - 0x6180D800L, 0xF111D901L, 0xF0A1DA01L, 0x6030DB00L, - 0xF3C1DC01L, 0x6350DD00L, 0x62E0DE00L, 0xF271DF01L, - 0xEE01E001L, 0x7E90E100L, 0x7F20E200L, 0xEFB1E301L, - 0x7C40E400L, 0xECD1E501L, 0xED61E601L, 0x7DF0E700L, - 0x7A80E800L, 0xEA11E901L, 0xEBA1EA01L, 0x7B30EB00L, - 0xE8C1EC01L, 0x7850ED00L, 0x79E0EE00L, 0xE971EF01L, - 0x7700F000L, 0xE791F101L, 0xE621F201L, 0x76B0F300L, - 0xE541F401L, 0x75D0F500L, 0x7460F600L, 0xE4F1F701L, - 0xE381F801L, 0x7310F900L, 0x72A0FA00L, 0xE231FB01L, - 0x71C0FC00L, 0xE151FD01L, 0xE0E1FE01L, 0x7070FF00L + 0x00000000L, 0x90910101L, 0x91210201L, 0x01B00300L, + 0x92410401L, 0x02D00500L, 0x03600600L, 0x93F10701L, + 0x94810801L, 0x04100900L, 0x05A00A00L, 0x95310B01L, + 0x06C00C00L, 0x96510D01L, 0x97E10E01L, 0x07700F00L, + 0x99011001L, 0x09901100L, 0x08201200L, 0x98B11301L, + 0x0B401400L, 0x9BD11501L, 0x9A611601L, 0x0AF01700L, + 0x0D801800L, 0x9D111901L, 0x9CA11A01L, 0x0C301B00L, + 0x9FC11C01L, 0x0F501D00L, 0x0EE01E00L, 0x9E711F01L, + 0x82012001L, 0x12902100L, 0x13202200L, 0x83B12301L, + 0x10402400L, 0x80D12501L, 0x81612601L, 0x11F02700L, + 0x16802800L, 0x86112901L, 0x87A12A01L, 0x17302B00L, + 0x84C12C01L, 0x14502D00L, 0x15E02E00L, 0x85712F01L, + 0x1B003000L, 0x8B913101L, 0x8A213201L, 0x1AB03300L, + 0x89413401L, 0x19D03500L, 0x18603600L, 0x88F13701L, + 0x8F813801L, 0x1F103900L, 0x1EA03A00L, 0x8E313B01L, + 0x1DC03C00L, 0x8D513D01L, 0x8CE13E01L, 0x1C703F00L, + 0xB4014001L, 0x24904100L, 0x25204200L, 0xB5B14301L, + 0x26404400L, 0xB6D14501L, 0xB7614601L, 0x27F04700L, + 0x20804800L, 0xB0114901L, 0xB1A14A01L, 0x21304B00L, + 0xB2C14C01L, 0x22504D00L, 0x23E04E00L, 0xB3714F01L, + 0x2D005000L, 0xBD915101L, 0xBC215201L, 0x2CB05300L, + 0xBF415401L, 0x2FD05500L, 0x2E605600L, 0xBEF15701L, + 0xB9815801L, 0x29105900L, 0x28A05A00L, 0xB8315B01L, + 0x2BC05C00L, 0xBB515D01L, 0xBAE15E01L, 0x2A705F00L, + 0x36006000L, 0xA6916101L, 0xA7216201L, 0x37B06300L, + 0xA4416401L, 0x34D06500L, 0x35606600L, 0xA5F16701L, + 0xA2816801L, 0x32106900L, 0x33A06A00L, 0xA3316B01L, + 0x30C06C00L, 0xA0516D01L, 0xA1E16E01L, 0x31706F00L, + 0xAF017001L, 0x3F907100L, 0x3E207200L, 0xAEB17301L, + 0x3D407400L, 0xADD17501L, 0xAC617601L, 0x3CF07700L, + 0x3B807800L, 0xAB117901L, 0xAAA17A01L, 0x3A307B00L, + 0xA9C17C01L, 0x39507D00L, 0x38E07E00L, 0xA8717F01L, + 0xD8018001L, 0x48908100L, 0x49208200L, 0xD9B18301L, + 0x4A408400L, 0xDAD18501L, 0xDB618601L, 0x4BF08700L, + 0x4C808800L, 0xDC118901L, 0xDDA18A01L, 0x4D308B00L, + 0xDEC18C01L, 0x4E508D00L, 0x4FE08E00L, 0xDF718F01L, + 0x41009000L, 0xD1919101L, 0xD0219201L, 0x40B09300L, + 0xD3419401L, 0x43D09500L, 0x42609600L, 0xD2F19701L, + 0xD5819801L, 0x45109900L, 0x44A09A00L, 0xD4319B01L, + 0x47C09C00L, 0xD7519D01L, 0xD6E19E01L, 0x46709F00L, + 0x5A00A000L, 0xCA91A101L, 0xCB21A201L, 0x5BB0A300L, + 0xC841A401L, 0x58D0A500L, 0x5960A600L, 0xC9F1A701L, + 0xCE81A801L, 0x5E10A900L, 0x5FA0AA00L, 0xCF31AB01L, + 0x5CC0AC00L, 0xCC51AD01L, 0xCDE1AE01L, 0x5D70AF00L, + 0xC301B001L, 0x5390B100L, 0x5220B200L, 0xC2B1B301L, + 0x5140B400L, 0xC1D1B501L, 0xC061B601L, 0x50F0B700L, + 0x5780B800L, 0xC711B901L, 0xC6A1BA01L, 0x5630BB00L, + 0xC5C1BC01L, 0x5550BD00L, 0x54E0BE00L, 0xC471BF01L, + 0x6C00C000L, 0xFC91C101L, 0xFD21C201L, 0x6DB0C300L, + 0xFE41C401L, 0x6ED0C500L, 0x6F60C600L, 0xFFF1C701L, + 0xF881C801L, 0x6810C900L, 0x69A0CA00L, 0xF931CB01L, + 0x6AC0CC00L, 0xFA51CD01L, 0xFBE1CE01L, 0x6B70CF00L, + 0xF501D001L, 0x6590D100L, 0x6420D200L, 0xF4B1D301L, + 0x6740D400L, 0xF7D1D501L, 0xF661D601L, 0x66F0D700L, + 0x6180D800L, 0xF111D901L, 0xF0A1DA01L, 0x6030DB00L, + 0xF3C1DC01L, 0x6350DD00L, 0x62E0DE00L, 0xF271DF01L, + 0xEE01E001L, 0x7E90E100L, 0x7F20E200L, 0xEFB1E301L, + 0x7C40E400L, 0xECD1E501L, 0xED61E601L, 0x7DF0E700L, + 0x7A80E800L, 0xEA11E901L, 0xEBA1EA01L, 0x7B30EB00L, + 0xE8C1EC01L, 0x7850ED00L, 0x79E0EE00L, 0xE971EF01L, + 0x7700F000L, 0xE791F101L, 0xE621F201L, 0x76B0F300L, + 0xE541F401L, 0x75D0F500L, 0x7460F600L, 0xE4F1F701L, + 0xE381F801L, 0x7310F900L, 0x72A0FA00L, 0xE231FB01L, + 0x71C0FC00L, 0xE151FD01L, 0xE0E1FE01L, 0x7070FF00L }; /*****************************************************************/ @@ -96,139 +96,139 @@ static const uae_u32 EDC_crctable[256] = /*****************************************************************/ static uae_u8 rs_l12_alog[255] = { - 1, 2, 4, 8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143, 3, 6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140, 5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141, 7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138, 9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,}; -static uae_u8 rs_l12_log[256] = { - 0, 0, 1,25, 2,50,26,198, 3,223,51,238,27,104,199,75, 4,100,224,14,52,141,239,129,28,193,105,248,200, 8,76,113, 5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154, 9,120,77,228,114,166, 6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87, 7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175,}; -static uae_u8 DQ[2][43] = { -{190,96,250,132,59,81,159,154,200,7,111,245,10,20,41,156,168,79,173,231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,}, -{97,251,133,60,82,160,155,201,8,112,246,11,21,42,157,169,80,174,232,230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,}, -}; -static uae_u8 DP[2][24] = { -{231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,}, -{230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,}, -}; + 1, 2, 4, 8,16,32,64,128,29,58,116,232,205,135,19,38,76,152,45,90,180,117,234,201,143, 3, 6,12,24,48,96,192,157,39,78,156,37,74,148,53,106,212,181,119,238,193,159,35,70,140, 5,10,20,40,80,160,93,186,105,210,185,111,222,161,95,190,97,194,153,47,94,188,101,202,137,15,30,60,120,240,253,231,211,187,107,214,177,127,254,225,223,163,91,182,113,226,217,175,67,134,17,34,68,136,13,26,52,104,208,189,103,206,129,31,62,124,248,237,199,147,59,118,236,197,151,51,102,204,133,23,46,92,184,109,218,169,79,158,33,66,132,21,42,84,168,77,154,41,82,164,85,170,73,146,57,114,228,213,183,115,230,209,191,99,198,145,63,126,252,229,215,179,123,246,241,255,227,219,171,75,150,49,98,196,149,55,110,220,165,87,174,65,130,25,50,100,200,141, 7,14,28,56,112,224,221,167,83,166,81,162,89,178,121,242,249,239,195,155,43,86,172,69,138, 9,18,36,72,144,61,122,244,245,247,243,251,235,203,139,11,22,44,88,176,125,250,233,207,131,27,54,108,216,173,71,142,}; + static uae_u8 rs_l12_log[256] = { + 0, 0, 1,25, 2,50,26,198, 3,223,51,238,27,104,199,75, 4,100,224,14,52,141,239,129,28,193,105,248,200, 8,76,113, 5,138,101,47,225,36,15,33,53,147,142,218,240,18,130,69,29,181,194,125,106,39,249,185,201,154, 9,120,77,228,114,166, 6,191,139,98,102,221,48,253,226,152,37,179,16,145,34,136,54,208,148,206,143,150,219,189,241,210,19,92,131,56,70,64,30,66,182,163,195,72,126,110,107,58,40,84,250,133,186,61,202,94,155,159,10,21,121,43,78,212,229,172,115,243,167,87, 7,112,192,247,140,128,99,13,103,74,222,237,49,197,254,24,227,165,153,119,38,184,180,124,17,68,146,217,35,32,137,46,55,63,209,91,149,188,207,205,144,135,151,178,220,252,190,97,242,86,211,171,20,42,93,158,132,60,57,83,71,109,65,162,31,45,67,216,183,123,164,118,196,23,73,236,127,12,111,246,108,161,59,82,41,157,85,170,251,96,134,177,187,204,62,90,203,89,95,176,156,169,160,81,11,245,22,235,122,117,44,215,79,174,213,233,230,231,173,232,116,214,244,234,168,80,88,175,}; + static uae_u8 DQ[2][43] = { + {190,96,250,132,59,81,159,154,200,7,111,245,10,20,41,156,168,79,173,231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,}, + {97,251,133,60,82,160,155,201,8,112,246,11,21,42,157,169,80,174,232,230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,}, + }; + static uae_u8 DP[2][24] = { + {231,229,171,210,240,17,67,215,43,120,8,199,74,102,220,251,95,175,87,166,113,75,198,25,}, + {230,172,211,241,18,68,216,44,121,9,200,75,103,221,252,96,176,88,167,114,76,199,26,1,}, + }; -/* data sector definitions for RSPC */ -/* user data bytes per frame */ + /* data sector definitions for RSPC */ + /* user data bytes per frame */ #define L2_RAW (1024*2) -/* parity bytes for 16 bit units */ + /* parity bytes for 16 bit units */ #define L2_Q (26*2*2) #define L2_P (43*2*2) #define RS_L12_BITS 8 -static uae_u32 build_edc (const uae_u8 *inout, int from, int upto) -{ - const uae_u8 *p = inout + from; - uae_u32 result = 0; - for (; from <= upto; from++) - result = EDC_crctable[(result ^ *p++) & 0xff] ^ (result >> 8); - return result; -} + static uae_u32 build_edc (const uae_u8 *inout, int from, int upto) + { + const uae_u8 *p = inout + from; + uae_u32 result = 0; + for (; from <= upto; from++) + result = EDC_crctable[(result ^ *p++) & 0xff] ^ (result >> 8); + return result; + } -static void encode_L2_Q(uae_u8 *inout) -{ - uae_u8 *Q; - int i,j; + static void encode_L2_Q(uae_u8 *inout) + { + uae_u8 *Q; + int i,j; - Q = inout + 4 + L2_RAW + 4 + 8 + L2_P; - memset(Q, 0, L2_Q); - for (j = 0; j < 26; j++) { - for (i = 0; i < 43; i++) { - uae_u8 data; - /* LSB */ - data = inout[(j*43*2+i*2*44) % (4 + L2_RAW + 4 + 8 + L2_P)]; - if (data != 0) { - uae_u32 base = rs_l12_log[data]; - uae_u32 sum = base + DQ[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - Q[0] ^= rs_l12_alog[sum]; - sum = base + DQ[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - Q[26*2] ^= rs_l12_alog[sum]; - } - /* MSB */ - data = inout[(j*43*2+i*2*44+1) % (4 + L2_RAW + 4 + 8 + L2_P)]; - if (data != 0) { - uae_u32 base = rs_l12_log[data]; - uae_u32 sum = base+DQ[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - Q[1] ^= rs_l12_alog[sum]; - sum = base + DQ[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - Q[26*2+1] ^= rs_l12_alog[sum]; - } - } - Q += 2; - } -} + Q = inout + 4 + L2_RAW + 4 + 8 + L2_P; + memset(Q, 0, L2_Q); + for (j = 0; j < 26; j++) { + for (i = 0; i < 43; i++) { + uae_u8 data; + /* LSB */ + data = inout[(j*43*2+i*2*44) % (4 + L2_RAW + 4 + 8 + L2_P)]; + if (data != 0) { + uae_u32 base = rs_l12_log[data]; + uae_u32 sum = base + DQ[0][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + Q[0] ^= rs_l12_alog[sum]; + sum = base + DQ[1][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + Q[26*2] ^= rs_l12_alog[sum]; + } + /* MSB */ + data = inout[(j*43*2+i*2*44+1) % (4 + L2_RAW + 4 + 8 + L2_P)]; + if (data != 0) { + uae_u32 base = rs_l12_log[data]; + uae_u32 sum = base+DQ[0][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + Q[1] ^= rs_l12_alog[sum]; + sum = base + DQ[1][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + Q[26*2+1] ^= rs_l12_alog[sum]; + } + } + Q += 2; + } + } -static void encode_L2_P(uae_u8 inout[4 + L2_RAW + 4 + 8 + L2_P]) -{ - uae_u8 *P; - int i,j; + static void encode_L2_P(uae_u8 inout[4 + L2_RAW + 4 + 8 + L2_P]) + { + uae_u8 *P; + int i,j; - P = inout + 4 + L2_RAW + 4 + 8; - memset(P, 0, L2_P); - for (j = 0; j < 43; j++) { - for (i = 0; i < 24; i++) { - uae_u8 data; - /* LSB */ - data = inout[i*2*43]; - if (data != 0) { - uae_u32 base = rs_l12_log[data]; - uae_u32 sum = base + DP[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - P[0] ^= rs_l12_alog[sum]; - sum = base + DP[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - P[43*2] ^= rs_l12_alog[sum]; - } - /* MSB */ - data = inout[i*2*43+1]; - if (data != 0) { - uae_u32 base = rs_l12_log[data]; - uae_u32 sum = base + DP[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - P[1] ^= rs_l12_alog[sum]; - sum = base + DP[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - P[43*2+1] ^= rs_l12_alog[sum]; - } - } - P += 2; - inout += 2; - } -} + P = inout + 4 + L2_RAW + 4 + 8; + memset(P, 0, L2_P); + for (j = 0; j < 43; j++) { + for (i = 0; i < 24; i++) { + uae_u8 data; + /* LSB */ + data = inout[i*2*43]; + if (data != 0) { + uae_u32 base = rs_l12_log[data]; + uae_u32 sum = base + DP[0][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + P[0] ^= rs_l12_alog[sum]; + sum = base + DP[1][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + P[43*2] ^= rs_l12_alog[sum]; + } + /* MSB */ + data = inout[i*2*43+1]; + if (data != 0) { + uae_u32 base = rs_l12_log[data]; + uae_u32 sum = base + DP[0][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + P[1] ^= rs_l12_alog[sum]; + sum = base + DP[1][i]; + if (sum >= ((1 << RS_L12_BITS)-1)) + sum -= (1 << RS_L12_BITS)-1; + P[43*2+1] ^= rs_l12_alog[sum]; + } + } + P += 2; + inout += 2; + } + } -static uae_u8 tobcd (uae_u8 v) -{ - return ((v / 10) << 4) | (v % 10); -} + static uae_u8 tobcd (uae_u8 v) + { + return ((v / 10) << 4) | (v % 10); + } -void encode_l2 (uae_u8 *p, int address) -{ - uae_u32 v; + void encode_l2 (uae_u8 *p, int address) + { + uae_u32 v; - p[0] = 0x00; - memset (p + 1, 0xff, 11); - p[12] = tobcd ((uae_u8)(address / (60 * 75))); - p[13] = tobcd ((uae_u8)((address / 75) % 60)); - p[14] = tobcd ((uae_u8)(address % 75)); - p[15] = 1; /* MODE1 */ - v = build_edc (p, 0, 16 + 2048 - 1); - p[2064 + 0] = (uae_u8) (v >> 0); - p[2064 + 1] = (uae_u8) (v >> 8); - p[2064 + 2] = (uae_u8) (v >> 16); - p[2064 + 3] = (uae_u8) (v >> 24); - memset (p + 2064 + 4, 0, 8); - encode_L2_P (p + 12); - encode_L2_Q (p + 12); -} + p[0] = 0x00; + memset (p + 1, 0xff, 11); + p[12] = tobcd ((uae_u8)(address / (60 * 75))); + p[13] = tobcd ((uae_u8)((address / 75) % 60)); + p[14] = tobcd ((uae_u8)(address % 75)); + p[15] = 1; /* MODE1 */ + v = build_edc (p, 0, 16 + 2048 - 1); + p[2064 + 0] = (uae_u8) (v >> 0); + p[2064 + 1] = (uae_u8) (v >> 8); + p[2064 + 2] = (uae_u8) (v >> 16); + p[2064 + 3] = (uae_u8) (v >> 24); + memset (p + 2064 + 4, 0, 8); + encode_L2_P (p + 12); + encode_L2_Q (p + 12); + } diff --git a/cdtv.c b/cdtv.c index e80885ea..9dc69b98 100644 --- a/cdtv.c +++ b/cdtv.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * CDTV DMAC/CDROM controller emulation - * - * Copyright 2004/2007 Toni Wilen - * - * Thanks to Mark Knibbs for CDTV Technical information - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* CDTV DMAC/CDROM controller emulation +* +* Copyright 2004/2007 Toni Wilen +* +* Thanks to Mark Knibbs for CDTV Technical information +* +*/ //#define ROMHACK //#define ROMHACK2 @@ -99,10 +99,10 @@ static void do_stch (void); static void INT2 (void) { - if (!(intreq & 8)) { - INTREQ_0 (0x8000 | 0x0008); - } - cd_led ^= LED_CD_ACTIVE2; + if (!(intreq & 8)) { + INTREQ_0 (0x8000 | 0x0008); + } + cd_led ^= LED_CD_ACTIVE2; } static int cdrom_command_cnt_out, cdrom_command_size_out; @@ -116,604 +116,604 @@ static int unitnum = -1; /* convert minutes, seconds and frames -> logical sector number */ static int msf2lsn (int msf) { - int sector = ((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff); - if (sector < 0) - sector = 0; - return sector; + int sector = ((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff); + if (sector < 0) + sector = 0; + return sector; } /* convert logical sector number -> minutes, seconds and frames */ static int lsn2msf (int sectors) { - int msf; - msf = (sectors / (75 * 60)) << 16; - msf |= ((sectors / 75) % 60) << 8; - msf |= (sectors % 75) << 0; - return msf; + int msf; + msf = (sectors / (75 * 60)) << 16; + msf |= ((sectors / 75) % 60) << 8; + msf |= (sectors % 75) << 0; + return msf; } static int get_toc (void) { - uae_u8 *buf; - int i; - - datatrack = 0; - buf = sys_command_cd_toc (DF_IOCTL, unitnum); - if (!buf) - return 0; - i = (buf[0] << 8) | (buf[1] << 0); - memcpy (cdrom_toc, buf, i); - last_cd_position = (buf[4 + 2 * 11 + 8] << 16) | (buf[4 + 2 * 11 + 9] << 8) | (buf[4 + 2 * 11 + 10] << 0); - last_cd_position = lsn2msf (msf2lsn (last_cd_position) - 1); - if (buf[4 + 3 * 11 + 3] == 1 && (buf[4 + 3 * 11 + 1] & 0x0c) == 0x04) - datatrack = 1; - return 1; + uae_u8 *buf; + int i; + + datatrack = 0; + buf = sys_command_cd_toc (DF_IOCTL, unitnum); + if (!buf) + return 0; + i = (buf[0] << 8) | (buf[1] << 0); + memcpy (cdrom_toc, buf, i); + last_cd_position = (buf[4 + 2 * 11 + 8] << 16) | (buf[4 + 2 * 11 + 9] << 8) | (buf[4 + 2 * 11 + 10] << 0); + last_cd_position = lsn2msf (msf2lsn (last_cd_position) - 1); + if (buf[4 + 3 * 11 + 3] == 1 && (buf[4 + 3 * 11 + 1] & 0x0c) == 0x04) + datatrack = 1; + return 1; } static void finished_cdplay (void) { - cd_audio_status = AUDIO_STATUS_PLAY_COMPLETE; - cd_playing = 0; - cd_finished = 1; - cd_paused = 0; - do_stch (); + cd_audio_status = AUDIO_STATUS_PLAY_COMPLETE; + cd_playing = 0; + cd_finished = 1; + cd_paused = 0; + do_stch (); } static int get_qcode (void) { - uae_u8 *s; - static uae_u8 subq0; - - memset (cdrom_qcode, 0, 16); - s = sys_command_cd_qcode (DF_IOCTL, unitnum); - if (!s) - return 0; - memcpy (cdrom_qcode, s, 16); - if (cd_playing) { - if (s[1] == AUDIO_STATUS_IN_PROGRESS) { - int end = msf2lsn((s[5 + 4] << 16) | (s[6 + 4] << 8) | (s[7 + 4])); - if (end >= play_end - 75) - finished_cdplay (); - } else if (s[1] == AUDIO_STATUS_PLAY_COMPLETE) { - finished_cdplay (); + uae_u8 *s; + static uae_u8 subq0; + + memset (cdrom_qcode, 0, 16); + s = sys_command_cd_qcode (DF_IOCTL, unitnum); + if (!s) + return 0; + memcpy (cdrom_qcode, s, 16); + if (cd_playing) { + if (s[1] == AUDIO_STATUS_IN_PROGRESS) { + int end = msf2lsn((s[5 + 4] << 16) | (s[6 + 4] << 8) | (s[7 + 4])); + if (end >= play_end - 75) + finished_cdplay (); + } else if (s[1] == AUDIO_STATUS_PLAY_COMPLETE) { + finished_cdplay (); + } } - } - s[1] = cd_audio_status; - return 1; + s[1] = cd_audio_status; + return 1; } static void cdaudiostop (void) { - cd_finished = 0; - if (cd_playing) - cd_finished = 1; - cd_playing = 0; - cd_paused = 0; - cd_motor = 0; - cd_audio_status = AUDIO_STATUS_NO_STATUS; - if (unitnum < 0) - return; - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - sys_command_cd_stop (DF_IOCTL, unitnum); + cd_finished = 0; + if (cd_playing) + cd_finished = 1; + cd_playing = 0; + cd_paused = 0; + cd_motor = 0; + cd_audio_status = AUDIO_STATUS_NO_STATUS; + if (unitnum < 0) + return; + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + sys_command_cd_stop (DF_IOCTL, unitnum); } static int pause_audio (int pause) { - sys_command_cd_pause (DF_IOCTL, unitnum, pause); - if (!cd_playing) { - cd_paused = 0; - cd_audio_status = AUDIO_STATUS_NO_STATUS; - return 0; - } - cd_paused = pause; - cd_audio_status = pause ? AUDIO_STATUS_PAUSED : AUDIO_STATUS_IN_PROGRESS; - return 1; + sys_command_cd_pause (DF_IOCTL, unitnum, pause); + if (!cd_playing) { + cd_paused = 0; + cd_audio_status = AUDIO_STATUS_NO_STATUS; + return 0; + } + cd_paused = pause; + cd_audio_status = pause ? AUDIO_STATUS_PAUSED : AUDIO_STATUS_IN_PROGRESS; + return 1; } static int read_sectors(int start, int length) { #ifdef CDTV_DEBUG - write_log (L"READ DATA sector %d, %d sectors (blocksize=%d)\n", start, length, cdtv_sectorsize); + write_log (L"READ DATA sector %d, %d sectors (blocksize=%d)\n", start, length, cdtv_sectorsize); #endif - cdrom_sector = start; - cdrom_sectors = length; - cdrom_offset = start * cdtv_sectorsize; - cdrom_length = length * cdtv_sectorsize; - cd_motor = 1; - cd_audio_status = AUDIO_STATUS_NOT_SUPPORTED; - if (cd_playing) - cdaudiostop (); - return 0; + cdrom_sector = start; + cdrom_sectors = length; + cdrom_offset = start * cdtv_sectorsize; + cdrom_length = length * cdtv_sectorsize; + cd_motor = 1; + cd_audio_status = AUDIO_STATUS_NOT_SUPPORTED; + if (cd_playing) + cdaudiostop (); + return 0; } static int ismedia (void) { - if (unitnum < 0) - return 0; - return sys_command_ismedia (DF_IOCTL, unitnum, 0); + if (unitnum < 0) + return 0; + return sys_command_ismedia (DF_IOCTL, unitnum, 0); } static void do_play (void) { - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - cd_audio_status = AUDIO_STATUS_PLAY_ERROR; - if (sys_command_cd_play (DF_IOCTL, unitnum, lsn2msf (play_start), lsn2msf (play_end), 0)) { - cd_audio_status = AUDIO_STATUS_IN_PROGRESS; - cd_playing = 1; - } else { - cd_error = 1; - } - activate_stch = 1; + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + cd_audio_status = AUDIO_STATUS_PLAY_ERROR; + if (sys_command_cd_play (DF_IOCTL, unitnum, lsn2msf (play_start), lsn2msf (play_end), 0)) { + cd_audio_status = AUDIO_STATUS_IN_PROGRESS; + cd_playing = 1; + } else { + cd_error = 1; + } + activate_stch = 1; } static int play_cdtrack (uae_u8 *p) { - int track_start = p[1]; - int index_start = p[2]; - int track_end = p[3]; - int index_end = p[4]; - uae_u32 start, end; - int i, j; - - i = (cdrom_toc[0] << 8) | (cdrom_toc[1] << 0); - i -= 2; - i /= 11; - end = last_cd_position; - for (j = 0; j < i; j++) { - uae_u8 *s = cdrom_toc + 4 + j * 11; - if (track_start == s[3]) - start = (s[8] << 16) | (s[9] << 8) | s[10]; - if (track_end == s[3]) - end = (s[8] << 16) | (s[9] << 8) | s[10]; - } - play_end = msf2lsn (end); - play_start = msf2lsn (start); + int track_start = p[1]; + int index_start = p[2]; + int track_end = p[3]; + int index_end = p[4]; + uae_u32 start, end; + int i, j; + + i = (cdrom_toc[0] << 8) | (cdrom_toc[1] << 0); + i -= 2; + i /= 11; + end = last_cd_position; + for (j = 0; j < i; j++) { + uae_u8 *s = cdrom_toc + 4 + j * 11; + if (track_start == s[3]) + start = (s[8] << 16) | (s[9] << 8) | s[10]; + if (track_end == s[3]) + end = (s[8] << 16) | (s[9] << 8) | s[10]; + } + play_end = msf2lsn (end); + play_start = msf2lsn (start); #ifdef CDTV_DEBUG - write_log (L"PLAY CD AUDIO from %d-%d, %06X (%d) to %06X (%d)\n", - track_start, track_end, start, msf2lsn (start), end, msf2lsn (end)); + write_log (L"PLAY CD AUDIO from %d-%d, %06X (%d) to %06X (%d)\n", + track_start, track_end, start, msf2lsn (start), end, msf2lsn (end)); #endif - play_state = 1; - play_state_cmd = 1; - return 0; + play_state = 1; + play_state_cmd = 1; + return 0; } static int play_cd (uae_u8 *p) { - uae_u32 start, end; - - start = (p[1] << 16) | (p[2] << 8) | p[3]; - end = (p[4] << 16) | (p[5] << 8) | p[6]; - if (p[0] == 0x09) /* end is length in lsn-mode */ - end += start; - if (start == 0 && end == 0) { - cd_finished = 0; - if (cd_playing) - cd_finished = 1; - cd_playing = 0; - cd_paused = 0; - cd_motor = 0; - cd_audio_status = AUDIO_STATUS_PLAY_COMPLETE; - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - sys_command_cd_stop (DF_IOCTL, unitnum); - cd_isready = 50; - cd_error = 1; - return 0; - } - if (p[0] == 0x09) { /* lsn */ - start = lsn2msf (start); - if (end < 0x00ffffff) - end = lsn2msf (end); - } - if (end == 0x00ffffff || end > last_cd_position) - end = last_cd_position; - play_end = msf2lsn (end); - play_start = msf2lsn (start); + uae_u32 start, end; + + start = (p[1] << 16) | (p[2] << 8) | p[3]; + end = (p[4] << 16) | (p[5] << 8) | p[6]; + if (p[0] == 0x09) /* end is length in lsn-mode */ + end += start; + if (start == 0 && end == 0) { + cd_finished = 0; + if (cd_playing) + cd_finished = 1; + cd_playing = 0; + cd_paused = 0; + cd_motor = 0; + cd_audio_status = AUDIO_STATUS_PLAY_COMPLETE; + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + sys_command_cd_stop (DF_IOCTL, unitnum); + cd_isready = 50; + cd_error = 1; + return 0; + } + if (p[0] == 0x09) { /* lsn */ + start = lsn2msf (start); + if (end < 0x00ffffff) + end = lsn2msf (end); + } + if (end == 0x00ffffff || end > last_cd_position) + end = last_cd_position; + play_end = msf2lsn (end); + play_start = msf2lsn (start); #ifdef CDTV_DEBUG - write_log (L"PLAY CD AUDIO from %06X (%d) to %06X (%d)\n", - start, msf2lsn (start), end, msf2lsn (end)); + write_log (L"PLAY CD AUDIO from %06X (%d) to %06X (%d)\n", + start, msf2lsn (start), end, msf2lsn (end)); #endif - play_state = 1; - play_state_cmd = 1; - return 0; + play_state = 1; + play_state_cmd = 1; + return 0; } static int cdrom_subq (uae_u8 *out, int msflsn) { - uae_u8 *s = cdrom_qcode; - uae_u32 trackposlsn, trackposmsf; - uae_u32 diskposlsn, diskposmsf; - - get_qcode (); - out[0] = cd_audio_status; - s += 4; - out[1] = s[1]; - out[2] = s[2]; - out[3] = s[3]; - trackposmsf = (s[9] << 16) | (s[10] << 8) | s[11]; - diskposmsf = (s[5] << 16) | (s[6] << 8) | s[7]; - trackposlsn = msf2lsn (trackposmsf); - diskposlsn = msf2lsn (diskposmsf); - out[4] = 0; - out[5] = (msflsn ? diskposmsf : diskposlsn) >> 16; - out[6] = (msflsn ? diskposmsf : diskposlsn) >> 8; - out[7] = (msflsn ? diskposmsf : diskposlsn) >> 0; - out[8] = 0; - out[9] = (msflsn ? trackposmsf : trackposlsn) >> 16; - out[10] = (msflsn ? trackposmsf : trackposlsn) >> 8; - out[11] = (msflsn ? trackposmsf : trackposlsn) >> 0; - out[12] = 0; - - return 13; + uae_u8 *s = cdrom_qcode; + uae_u32 trackposlsn, trackposmsf; + uae_u32 diskposlsn, diskposmsf; + + get_qcode (); + out[0] = cd_audio_status; + s += 4; + out[1] = s[1]; + out[2] = s[2]; + out[3] = s[3]; + trackposmsf = (s[9] << 16) | (s[10] << 8) | s[11]; + diskposmsf = (s[5] << 16) | (s[6] << 8) | s[7]; + trackposlsn = msf2lsn (trackposmsf); + diskposlsn = msf2lsn (diskposmsf); + out[4] = 0; + out[5] = (msflsn ? diskposmsf : diskposlsn) >> 16; + out[6] = (msflsn ? diskposmsf : diskposlsn) >> 8; + out[7] = (msflsn ? diskposmsf : diskposlsn) >> 0; + out[8] = 0; + out[9] = (msflsn ? trackposmsf : trackposlsn) >> 16; + out[10] = (msflsn ? trackposmsf : trackposlsn) >> 8; + out[11] = (msflsn ? trackposmsf : trackposlsn) >> 0; + out[12] = 0; + + return 13; } static int cdrom_info (uae_u8 *out) { - uae_u8 *p; - uae_u32 size; - int i; + uae_u8 *p; + uae_u32 size; + int i; - if (!ismedia ()) - return -1; - cd_motor = 1; - out[0] = cdrom_toc[2]; - i = (cdrom_toc[0] << 8) | (cdrom_toc[1] << 0); - i -= 2 + 11; - i /= 11; - p = cdrom_toc + 4 + i * 11; - out[1] = p[3]; - p = cdrom_toc + 4 + 2 * 11; - size = ((p[8] << 16) | (p[9] << 8) | p[10]); - out[2] = size >> 16; - out[3] = size >> 8; - out[4] = size >> 0; - cd_finished = 1; - return 5; + if (!ismedia ()) + return -1; + cd_motor = 1; + out[0] = cdrom_toc[2]; + i = (cdrom_toc[0] << 8) | (cdrom_toc[1] << 0); + i -= 2 + 11; + i /= 11; + p = cdrom_toc + 4 + i * 11; + out[1] = p[3]; + p = cdrom_toc + 4 + 2 * 11; + size = ((p[8] << 16) | (p[9] << 8) | p[10]); + out[2] = size >> 16; + out[3] = size >> 8; + out[4] = size >> 0; + cd_finished = 1; + return 5; } static int read_toc (int track, int msflsn, uae_u8 *out) { - uae_u8 *buf = cdrom_toc, *s; - int i, j; + uae_u8 *buf = cdrom_toc, *s; + int i, j; - if (!ismedia ()) - return -1; - if (!out) - return 0; - cd_motor = 1; - i = (buf[0] << 8) | (buf[1] << 0); - i -= 2; - i /= 11; - for (j = 0; j < i; j++) { - s = buf + 4 + j * 11; - if (track == s[3]) { - uae_u32 msf = (s[8] << 16) | (s[9] << 8) | s[10]; - uae_u32 lsn = msf2lsn (msf); - out[0] = 0; - out[1] = s[1]; - out[2] = s[3]; - out[3] = buf[3]; - out[4] = 0; - out[5] = (msflsn ? msf : lsn) >> 16; - out[6] = (msflsn ? msf : lsn) >> 8; - out[7] = (msflsn ? msf : lsn) >> 0; - cd_finished = 1; - return 8; + if (!ismedia ()) + return -1; + if (!out) + return 0; + cd_motor = 1; + i = (buf[0] << 8) | (buf[1] << 0); + i -= 2; + i /= 11; + for (j = 0; j < i; j++) { + s = buf + 4 + j * 11; + if (track == s[3]) { + uae_u32 msf = (s[8] << 16) | (s[9] << 8) | s[10]; + uae_u32 lsn = msf2lsn (msf); + out[0] = 0; + out[1] = s[1]; + out[2] = s[3]; + out[3] = buf[3]; + out[4] = 0; + out[5] = (msflsn ? msf : lsn) >> 16; + out[6] = (msflsn ? msf : lsn) >> 8; + out[7] = (msflsn ? msf : lsn) >> 0; + cd_finished = 1; + return 8; + } } - } - return -1; + return -1; } static int cdrom_modeset (uae_u8 *cmd) { - cdtv_sectorsize = (cmd[2] << 8) | cmd[3]; - if (cdtv_sectorsize != 2048 && cdtv_sectorsize != 2336) { - write_log (L"CDTV: tried to set unknown sector size %d\n", cdtv_sectorsize); - cdtv_sectorsize = 2048; - } - return 0; + cdtv_sectorsize = (cmd[2] << 8) | cmd[3]; + if (cdtv_sectorsize != 2048 && cdtv_sectorsize != 2336) { + write_log (L"CDTV: tried to set unknown sector size %d\n", cdtv_sectorsize); + cdtv_sectorsize = 2048; + } + return 0; } static void cdrom_command_accepted (int size, uae_u8 *cdrom_command_input, int *cdrom_command_cnt_in) { #ifdef CDTV_DEBUG_CMD - TCHAR tmp[200]; - int i; + TCHAR tmp[200]; + int i; #endif - cdrom_command_size_out = size; + cdrom_command_size_out = size; #ifdef CDTV_DEBUG_CMD - tmp[0] = 0; - for (i = 0; i < *cdrom_command_cnt_in; i++) - _stprintf (tmp + i * 3, L"%02X%c", cdrom_command_input[i], i < *cdrom_command_cnt_in - 1 ? '.' : ' '); - write_log (L"CD<-: %s\n", tmp); - if (size > 0) { tmp[0] = 0; - for (i = 0; i < size; i++) - _stprintf (tmp + i * 3, L"%02X%c", cdrom_command_output[i], i < size - 1 ? '.' : ' '); - write_log (L"CD->: %s\n", tmp); - } + for (i = 0; i < *cdrom_command_cnt_in; i++) + _stprintf (tmp + i * 3, L"%02X%c", cdrom_command_input[i], i < *cdrom_command_cnt_in - 1 ? '.' : ' '); + write_log (L"CD<-: %s\n", tmp); + if (size > 0) { + tmp[0] = 0; + for (i = 0; i < size; i++) + _stprintf (tmp + i * 3, L"%02X%c", cdrom_command_output[i], i < size - 1 ? '.' : ' '); + write_log (L"CD->: %s\n", tmp); + } #endif - *cdrom_command_cnt_in = 0; - cdrom_command_cnt_out = 0; - cdrom_command_done = 1; + *cdrom_command_cnt_in = 0; + cdrom_command_cnt_out = 0; + cdrom_command_done = 1; } static void cdrom_command_thread (uae_u8 b) { - static uae_u8 cdrom_command_input[16]; - static int cdrom_command_cnt_in; - uae_u8 *s; + static uae_u8 cdrom_command_input[16]; + static int cdrom_command_cnt_in; + uae_u8 *s; - cdrom_command_input[cdrom_command_cnt_in] = b; - cdrom_command_cnt_in++; - s = cdrom_command_input; + cdrom_command_input[cdrom_command_cnt_in] = b; + cdrom_command_cnt_in++; + s = cdrom_command_input; - switch (cdrom_command_input[0]) - { + switch (cdrom_command_input[0]) + { case 0x01: /* seek */ - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0x02: /* read */ - if (cdrom_command_cnt_in == 7) { - read_sectors((s[1] << 16) | (s[2] << 8) | (s[3] << 0), (s[4] << 8) | (s[5] << 0)); - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + read_sectors((s[1] << 16) | (s[2] << 8) | (s[3] << 0), (s[4] << 8) | (s[5] << 0)); + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + } + break; case 0x04: /* motor on */ - if (cdrom_command_cnt_in == 7) { - cd_motor = 1; - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + cd_motor = 1; + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0x05: /* motor off */ - if (cdrom_command_cnt_in == 7) { - cd_motor = 0; - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + cd_motor = 0; + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0x09: /* play (lsn) */ case 0x0a: /* play (msf) */ - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (play_cd (cdrom_command_input), s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (play_cd (cdrom_command_input), s, &cdrom_command_cnt_in); + } + break; case 0x0b: - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (play_cdtrack (cdrom_command_input), s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (play_cdtrack (cdrom_command_input), s, &cdrom_command_cnt_in); + } + break; case 0x81: - if (cdrom_command_cnt_in == 1) { - uae_u8 flag = 0; - if (!cd_isready) - flag |= 1 << 0; - if (cd_playing) - flag |= 1 << 2; - if (cd_finished) - flag |= 1 << 3; - if (cd_error) - flag |= 1 << 4; - if (cd_motor) - flag |= 1 << 5; - if (cd_media) - flag |= 1 << 6; - cdrom_command_output[0] = flag; - cdrom_command_accepted (1, s, &cdrom_command_cnt_in); - cd_finished = 0; - if (first == -1) - first = 100; - } - break; + if (cdrom_command_cnt_in == 1) { + uae_u8 flag = 0; + if (!cd_isready) + flag |= 1 << 0; + if (cd_playing) + flag |= 1 << 2; + if (cd_finished) + flag |= 1 << 3; + if (cd_error) + flag |= 1 << 4; + if (cd_motor) + flag |= 1 << 5; + if (cd_media) + flag |= 1 << 6; + cdrom_command_output[0] = flag; + cdrom_command_accepted (1, s, &cdrom_command_cnt_in); + cd_finished = 0; + if (first == -1) + first = 100; + } + break; case 0x82: - if (cdrom_command_cnt_in == 7) { - if (cd_error) - cdrom_command_output[2] |= 1 << 4; - cd_error = 0; - cd_isready = 0; - cdrom_command_accepted (6, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + if (cd_error) + cdrom_command_output[2] |= 1 << 4; + cd_error = 0; + cd_isready = 0; + cdrom_command_accepted (6, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0x83: - if (cdrom_command_cnt_in == 7) { - memcpy (cdrom_command_output, MODEL_NAME, strlen (MODEL_NAME)); - cdrom_command_accepted (strlen (MODEL_NAME), s, &cdrom_command_cnt_in); - cd_finished = 1; - } + if (cdrom_command_cnt_in == 7) { + memcpy (cdrom_command_output, MODEL_NAME, strlen (MODEL_NAME)); + cdrom_command_accepted (strlen (MODEL_NAME), s, &cdrom_command_cnt_in); + cd_finished = 1; + } case 0x84: - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (cdrom_modeset (cdrom_command_input), s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (cdrom_modeset (cdrom_command_input), s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0x87: /* subq */ - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (cdrom_subq (cdrom_command_output, cdrom_command_input[1] & 2), s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (cdrom_subq (cdrom_command_output, cdrom_command_input[1] & 2), s, &cdrom_command_cnt_in); + } + break; case 0x89: - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (cdrom_info (cdrom_command_output), s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (cdrom_info (cdrom_command_output), s, &cdrom_command_cnt_in); + } + break; case 0x8a: /* read toc */ - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (read_toc (cdrom_command_input[2], cdrom_command_input[1] & 2, cdrom_command_output), s, &cdrom_command_cnt_in); - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (read_toc (cdrom_command_input[2], cdrom_command_input[1] & 2, cdrom_command_output), s, &cdrom_command_cnt_in); + } + break; case 0x8b: - if (cdrom_command_cnt_in == 7) { - pause_audio (s[1] == 0x00 ? 1 : 0); - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + pause_audio (s[1] == 0x00 ? 1 : 0); + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; case 0xa3: /* front panel */ - if (cdrom_command_cnt_in == 7) { - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - cd_finished = 1; - } - break; + if (cdrom_command_cnt_in == 7) { + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + cd_finished = 1; + } + break; default: - write_log (L"unknown CDROM command %02X!\n", s[0]); - cd_error = 1; - cdrom_command_accepted (0, s, &cdrom_command_cnt_in); - break; - } + write_log (L"unknown CDROM command %02X!\n", s[0]); + cd_error = 1; + cdrom_command_accepted (0, s, &cdrom_command_cnt_in); + break; + } } static uae_u8 *read_raw (int sector, int size) { - int osector = sector; - static struct zfile *f; - static int track; - int trackcnt; - TCHAR fname[MAX_DPATH]; - static uae_u8 buf[4096]; - uae_u32 prevlsn = 0; - uae_u8 *s = cdrom_toc + 4; - - memset (buf, 0, sizeof buf); - trackcnt = 0; - for (;;) { - uae_u32 msf = (s[8] << 16) | (s[9] << 8) | s[10]; - uae_u32 lsn = msf2lsn (msf); - if (s[3] >= 0xa0) { - s += 11; - continue; + int osector = sector; + static struct zfile *f; + static int track; + int trackcnt; + TCHAR fname[MAX_DPATH]; + static uae_u8 buf[4096]; + uae_u32 prevlsn = 0; + uae_u8 *s = cdrom_toc + 4; + + memset (buf, 0, sizeof buf); + trackcnt = 0; + for (;;) { + uae_u32 msf = (s[8] << 16) | (s[9] << 8) | s[10]; + uae_u32 lsn = msf2lsn (msf); + if (s[3] >= 0xa0) { + s += 11; + continue; + } + if (sector < lsn - prevlsn) + break; + trackcnt++; + sector -= lsn - prevlsn; + prevlsn = lsn; + s += 11; } - if (sector < lsn - prevlsn) - break; - trackcnt++; - sector -= lsn - prevlsn; - prevlsn = lsn; - s += 11; - } - if (track != trackcnt) { - _stprintf (fname, L"track%d.bin", trackcnt); - zfile_fclose (f); - f = zfile_fopen (fname, L"rb", ZFD_NORMAL); - if (!f) - write_log (L"failed to open '%s'\n", fname); - else - write_log (L"opened '%s'\n", fname); - track = trackcnt; - } - if (f) { - write_log (L"CDTV fakeraw: %dx%d=%d\n", sector, size, sector * size); - zfile_fseek (f, sector * size, SEEK_SET); - zfile_fread (buf, size, 1, f); - return buf; - } - return sys_command_cd_rawread (DF_IOCTL, unitnum, osector, size); + if (track != trackcnt) { + _stprintf (fname, L"track%d.bin", trackcnt); + zfile_fclose (f); + f = zfile_fopen (fname, L"rb", ZFD_NORMAL); + if (!f) + write_log (L"failed to open '%s'\n", fname); + else + write_log (L"opened '%s'\n", fname); + track = trackcnt; + } + if (f) { + write_log (L"CDTV fakeraw: %dx%d=%d\n", sector, size, sector * size); + zfile_fseek (f, sector * size, SEEK_SET); + zfile_fread (buf, size, 1, f); + return buf; + } + return sys_command_cd_rawread (DF_IOCTL, unitnum, osector, size); } static void dma_do_thread (void) { - static int readsector; - uae_u8 *p = NULL; - int cnt; + static int readsector; + uae_u8 *p = NULL; + int cnt; - while (dma_finished) - sleep_millis (2); + while (dma_finished) + sleep_millis (2); - if (!cdtv_sectorsize) - return; - cnt = dmac_wtc; + if (!cdtv_sectorsize) + return; + cnt = dmac_wtc; #ifdef CDTV_DEBUG - write_log (L"DMAC DMA: sector=%d, addr=%08X, words=%d (of %d)\n", - cdrom_offset / cdtv_sectorsize, dmac_acr, cnt, cdrom_length / 2); + write_log (L"DMAC DMA: sector=%d, addr=%08X, words=%d (of %d)\n", + cdrom_offset / cdtv_sectorsize, dmac_acr, cnt, cdrom_length / 2); #endif - dma_wait += cnt * (uae_u64)312 * 50 / 75 + 1; - while (cnt > 0 && dmac_dma) { - if (!p || readsector != (cdrom_offset / cdtv_sectorsize)) { - readsector = cdrom_offset / cdtv_sectorsize; - if (cdtv_sectorsize == 2336) - p = read_raw (readsector, cdtv_sectorsize); - else - p = sys_command_cd_read (DF_IOCTL, unitnum, readsector); - if (!p) { - cd_error = 1; - activate_stch = 1; - write_log (L"CDTV: CD read error!\n"); - break; - } + dma_wait += cnt * (uae_u64)312 * 50 / 75 + 1; + while (cnt > 0 && dmac_dma) { + if (!p || readsector != (cdrom_offset / cdtv_sectorsize)) { + readsector = cdrom_offset / cdtv_sectorsize; + if (cdtv_sectorsize == 2336) + p = read_raw (readsector, cdtv_sectorsize); + else + p = sys_command_cd_read (DF_IOCTL, unitnum, readsector); + if (!p) { + cd_error = 1; + activate_stch = 1; + write_log (L"CDTV: CD read error!\n"); + break; + } + } + put_byte (dmac_acr, p[(cdrom_offset % cdtv_sectorsize) + 0]); + put_byte (dmac_acr + 1, p[(cdrom_offset % cdtv_sectorsize) + 1]); + cnt--; + dmac_acr += 2; + cdrom_length -= 2; + cdrom_offset += 2; } - put_byte (dmac_acr, p[(cdrom_offset % cdtv_sectorsize) + 0]); - put_byte (dmac_acr + 1, p[(cdrom_offset % cdtv_sectorsize) + 1]); - cnt--; - dmac_acr += 2; - cdrom_length -= 2; - cdrom_offset += 2; - } - dmac_wtc = 0; - dmac_dma = 0; - dma_finished = 1; - cd_finished = 1; + dmac_wtc = 0; + dmac_dma = 0; + dma_finished = 1; + cd_finished = 1; } static void *dev_thread (void *p) { - write_log (L"CDTV: CD thread started\n"); - thread_alive = 1; - for (;;) { - - uae_u32 b = read_comm_pipe_u32_blocking (&requests); - if (unitnum < 0) - continue; - - switch (b) - { - case 0x0100: - dma_do_thread (); - break; - case 0x0101: - { - if (ismedia () != cd_media) { - cd_media = ismedia (); - get_toc (); - activate_stch = 1; - if (cd_playing) - cd_error = 1; - if (!cd_media) - cd_hunt = 1; + write_log (L"CDTV: CD thread started\n"); + thread_alive = 1; + for (;;) { + + uae_u32 b = read_comm_pipe_u32_blocking (&requests); + if (unitnum < 0) + continue; + + switch (b) + { + case 0x0100: + dma_do_thread (); + break; + case 0x0101: + { + if (ismedia () != cd_media) { + cd_media = ismedia (); + get_toc (); + activate_stch = 1; + if (cd_playing) + cd_error = 1; + if (!cd_media) + cd_hunt = 1; + } + if (cd_media) + get_qcode (); + } + break; + case 0x0102: // pause + sys_command_cd_pause (DF_IOCTL, unitnum, 1); + break; + case 0x0103: // unpause + sys_command_cd_pause (DF_IOCTL, unitnum, 0); + break; + case 0x0104: // stop + cdaudiostop (); + break; + case 0x0110: // do_play! + do_play (); + break; + case 0xffff: + thread_alive = -1; + return NULL; + default: + cdrom_command_thread (b); + break; } - if (cd_media) - get_qcode (); - } - break; - case 0x0102: // pause - sys_command_cd_pause (DF_IOCTL, unitnum, 1); - break; - case 0x0103: // unpause - sys_command_cd_pause (DF_IOCTL, unitnum, 0); - break; - case 0x0104: // stop - cdaudiostop (); - break; - case 0x0110: // do_play! - do_play (); - break; - case 0xffff: - thread_alive = -1; - return NULL; - default: - cdrom_command_thread (b); - break; - } - } + } } static void cdrom_command (uae_u8 b) { - write_comm_pipe_u32 (&requests, b, 1); + write_comm_pipe_u32 (&requests, b, 1); } static uae_u8 tp_a, tp_b, tp_c, tp_ad, tp_bd, tp_cd; @@ -721,123 +721,123 @@ static uae_u8 tp_imr, tp_cr, tp_air; static void tp_check_interrupts (void) { - /* MC = 1 ? */ - if ((tp_cr & 1) != 1) - return; - - if (sten == 1) { - sten = -1; - if (tp_cd & (1 << 3)) - tp_air |= 1 << 3; - } - if ((tp_air & tp_cd) & 0x1f) - INT2 (); + /* MC = 1 ? */ + if ((tp_cr & 1) != 1) + return; + + if (sten == 1) { + sten = -1; + if (tp_cd & (1 << 3)) + tp_air |= 1 << 3; + } + if ((tp_air & tp_cd) & 0x1f) + INT2 (); } static void tp_bput (int addr, uae_u8 v) { - static int volstrobe1, volstrobe2; + static int volstrobe1, volstrobe2; #ifdef CDTV_DEBUG_6525 - write_log (L"6525 write %x=%02X PC=%x\n", addr, v, M68K_GETPC); + write_log (L"6525 write %x=%02X PC=%x\n", addr, v, M68K_GETPC); #endif - switch (addr) - { + switch (addr) + { case 0: - tp_a = v; - break; + tp_a = v; + break; case 1: - tp_b = v; - break; + tp_b = v; + break; case 2: - if (!(tp_cr & 1)) - tp_c = v; - break; + if (!(tp_cr & 1)) + tp_c = v; + break; case 3: - tp_ad = v; - break; + tp_ad = v; + break; case 4: - tp_bd = v; - break; + tp_bd = v; + break; case 5: - tp_cd = v; - break; + tp_cd = v; + break; case 6: - tp_cr = v; - break; + tp_cr = v; + break; case 7: - tp_air = v; - break; - } - cmd = (tp_b >> 0) & 1; - enable = (tp_b >> 1) & 1; - xaen = (tp_b >> 2) & 1; - dten = (tp_b >> 3) & 1; - - if (!volstrobe1 && ((tp_b >> 6) & 1)) { - cd_volume >>= 1; - cd_volume |= ((tp_b >> 5) & 1) << 11; - volstrobe1 = 1; - } else if (volstrobe1 && !((tp_b >> 6) & 1)) { - volstrobe1 = 0; - } - if (!volstrobe2 && ((tp_b >> 7) & 1)) { + tp_air = v; + break; + } + cmd = (tp_b >> 0) & 1; + enable = (tp_b >> 1) & 1; + xaen = (tp_b >> 2) & 1; + dten = (tp_b >> 3) & 1; + + if (!volstrobe1 && ((tp_b >> 6) & 1)) { + cd_volume >>= 1; + cd_volume |= ((tp_b >> 5) & 1) << 11; + volstrobe1 = 1; + } else if (volstrobe1 && !((tp_b >> 6) & 1)) { + volstrobe1 = 0; + } + if (!volstrobe2 && ((tp_b >> 7) & 1)) { #ifdef CDTV_DEBUG_CMD - write_log (L"CDTV CD volume = %d\n", cd_volume); + write_log (L"CDTV CD volume = %d\n", cd_volume); #endif - cd_volume = 0; - volstrobe2 = 1; - } else if (volstrobe2 && !((tp_b >> 7) & 1)) { - volstrobe2 = 0; - } + cd_volume = 0; + volstrobe2 = 1; + } else if (volstrobe2 && !((tp_b >> 7) & 1)) { + volstrobe2 = 0; + } } static uae_u8 tp_bget(int addr) { - uae_u8 v = 0; - switch (addr) - { + uae_u8 v = 0; + switch (addr) + { case 0: - v = tp_a; - write_log (L"TPA read!\n"); - break; + v = tp_a; + write_log (L"TPA read!\n"); + break; case 1: - v = tp_b; - break; + v = tp_b; + break; case 2: - v = (sbcp << 0) | ((scor ^ 1) << 1) | ((stch ^ 1) << 2) | (sten << 3); - if (tp_cr & 1) { - if (!v) - v |= 1 << 5; // /IRQ - } else { - v |= tp_c & ~(0x80 | 0x40); - } - v |= tp_c & (0x80 | 0x40); - sbcp = 0; - break; + v = (sbcp << 0) | ((scor ^ 1) << 1) | ((stch ^ 1) << 2) | (sten << 3); + if (tp_cr & 1) { + if (!v) + v |= 1 << 5; // /IRQ + } else { + v |= tp_c & ~(0x80 | 0x40); + } + v |= tp_c & (0x80 | 0x40); + sbcp = 0; + break; case 3: - v = tp_ad; - break; + v = tp_ad; + break; case 4: - v = tp_bd; - break; + v = tp_bd; + break; case 5: - v = tp_cd; - break; + v = tp_cd; + break; case 6: - v = tp_cr; - break; + v = tp_cr; + break; case 7: - v = tp_air; - tp_air = 0; - break; - } + v = tp_air; + tp_air = 0; + break; + } #ifdef CDTV_DEBUG_6525 - if (addr < 7) - write_log (L"6525 read %x=%02X PC=%x\n", addr, v, M68K_GETPC); + if (addr < 7) + write_log (L"6525 read %x=%02X PC=%x\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM3 dmac_lget (uaecptr) REGPARAM; @@ -849,577 +849,577 @@ static void REGPARAM3 dmac_bput (uaecptr, uae_u32) REGPARAM; static void dmac_start_dma (void) { - if (!(dmac_cntr & CNTR_PDMD)) { // non-scsi dma - write_comm_pipe_u32 (&requests, 0x0100, 1); - } + if (!(dmac_cntr & CNTR_PDMD)) { // non-scsi dma + write_comm_pipe_u32 (&requests, 0x0100, 1); + } } void cdtv_getdmadata (uae_u32 *acr) { - *acr = dmac_acr; + *acr = dmac_acr; } static void do_hunt (void) { - int i; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (sys_command_ismedia (DF_IOCTL, i, 1) > 0) - break; - } - if (i == MAX_TOTAL_DEVICES) - return; - if (unitnum >= 0) { - cdaudiostop (); - sys_command_close (DF_IOCTL, unitnum); - } - if (sys_command_open (DF_IOCTL, i) > 0) { - unitnum = i; - cd_hunt = 0; - write_log (L"CDTV: autodetected unit %d\n", unitnum); - } else { - unitnum = -1; - } + int i; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (sys_command_ismedia (DF_IOCTL, i, 1) > 0) + break; + } + if (i == MAX_TOTAL_DEVICES) + return; + if (unitnum >= 0) { + cdaudiostop (); + sys_command_close (DF_IOCTL, unitnum); + } + if (sys_command_open (DF_IOCTL, i) > 0) { + unitnum = i; + cd_hunt = 0; + write_log (L"CDTV: autodetected unit %d\n", unitnum); + } else { + unitnum = -1; + } } static void checkint (void) { - int irq = 0; - - if (currprefs.cs_cdtvscsi && (wdscsi_getauxstatus () & 0x80)) { - dmac_istr |= ISTR_INTS; - if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & ISTR_INTS)) - irq = 1; - } - if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & ISTR_E_INT)) - irq = 1; - if (irq) - INT2 (); + int irq = 0; + + if (currprefs.cs_cdtvscsi && (wdscsi_getauxstatus () & 0x80)) { + dmac_istr |= ISTR_INTS; + if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & ISTR_INTS)) + irq = 1; + } + if ((dmac_cntr & CNTR_INTEN) && (dmac_istr & ISTR_E_INT)) + irq = 1; + if (irq) + INT2 (); } void cdtv_scsi_int (void) { - checkint (); + checkint (); } void cdtv_scsi_clear_int (void) { - dmac_istr &= ~ISTR_INTS; + dmac_istr &= ~ISTR_INTS; } void rethink_cdtv (void) { - checkint (); - tp_check_interrupts (); + checkint (); + tp_check_interrupts (); } void CDTV_hsync_handler (void) { - static int subqcnt; + static int subqcnt; - if (!currprefs.cs_cdtvcd || !configured) - return; + if (!currprefs.cs_cdtvcd || !configured) + return; - cdtv_hsync++; + cdtv_hsync++; - if (dma_wait >= 1024) - dma_wait -= 1024; - if (dma_wait >= 0 && dma_wait < 1024 && dma_finished) { - if ((dmac_cntr & (CNTR_INTEN | CNTR_TCEN)) == (CNTR_INTEN | CNTR_TCEN)) { - dmac_istr |= ISTR_INT_P | ISTR_E_INT; + if (dma_wait >= 1024) + dma_wait -= 1024; + if (dma_wait >= 0 && dma_wait < 1024 && dma_finished) { + if ((dmac_cntr & (CNTR_INTEN | CNTR_TCEN)) == (CNTR_INTEN | CNTR_TCEN)) { + dmac_istr |= ISTR_INT_P | ISTR_E_INT; #ifdef CDTV_DEBUG - write_log (L"DMA finished\n"); + write_log (L"DMA finished\n"); #endif + } + dma_finished = 0; + cdtv_hsync = -1; } - dma_finished = 0; - cdtv_hsync = -1; - } - checkint(); + checkint(); - if (cdrom_command_done) { - cdrom_command_done = 0; - sten = 1; - tp_check_interrupts (); - } + if (cdrom_command_done) { + cdrom_command_done = 0; + sten = 1; + tp_check_interrupts (); + } - if (cdtv_hsync < 312 * 50 / 75 && cdtv_hsync >= 0) - return; - cdtv_hsync = 0; + if (cdtv_hsync < 312 * 50 / 75 && cdtv_hsync >= 0) + return; + cdtv_hsync = 0; - if (first > 0) { - first--; - if (first == 0) - do_stch (); - } + if (first > 0) { + first--; + if (first == 0) + do_stch (); + } - if (play_state == 1) { - play_state = 2; - cd_playing = 1; - cd_motor = 1; - activate_stch = 1; - play_statewait = 5; - } else if (play_statewait > 0) { - play_statewait--; - } else if (play_state == 2) { - write_comm_pipe_u32 (&requests, 0x0110, 1); - play_state = 0; - } - - if (cd_isready > 0) { - cd_isready--; - if (!cd_isready) - do_stch (); - } - if (cd_playing) - cd_led |= LED_CD_AUDIO; - else - cd_led &= ~LED_CD_AUDIO; - if (dmac_dma) - cd_led |= LED_CD_ACTIVE; - else - cd_led &= ~LED_CD_ACTIVE; - if (cd_led) - gui_cd_led (0, cd_led); - - if (cd_media && (tp_cr & 1)) { - tp_air |= 1 << 1; - INT2 (); - } - - subqcnt--; - if (subqcnt < 0) { - write_comm_pipe_u32 (&requests, 0x0101, 1); - subqcnt = 75; - if (cd_hunt) - do_hunt (); - } - if (activate_stch) - do_stch (); + if (play_state == 1) { + play_state = 2; + cd_playing = 1; + cd_motor = 1; + activate_stch = 1; + play_statewait = 5; + } else if (play_statewait > 0) { + play_statewait--; + } else if (play_state == 2) { + write_comm_pipe_u32 (&requests, 0x0110, 1); + play_state = 0; + } + + if (cd_isready > 0) { + cd_isready--; + if (!cd_isready) + do_stch (); + } + if (cd_playing) + cd_led |= LED_CD_AUDIO; + else + cd_led &= ~LED_CD_AUDIO; + if (dmac_dma) + cd_led |= LED_CD_ACTIVE; + else + cd_led &= ~LED_CD_ACTIVE; + if (cd_led) + gui_cd_led (0, cd_led); + + if (cd_media && (tp_cr & 1)) { + tp_air |= 1 << 1; + INT2 (); + } + + subqcnt--; + if (subqcnt < 0) { + write_comm_pipe_u32 (&requests, 0x0101, 1); + subqcnt = 75; + if (cd_hunt) + do_hunt (); + } + if (activate_stch) + do_stch (); } static void do_stch (void) { - static int stch_cnt; - - if ((tp_cr & 1) && !(tp_air & (1 << 2)) && (tp_cd & (1 << 2))) { - activate_stch = 0; - tp_air |= 1 << 2; - INT2 (); + static int stch_cnt; + + if ((tp_cr & 1) && !(tp_air & (1 << 2)) && (tp_cd & (1 << 2))) { + activate_stch = 0; + tp_air |= 1 << 2; + INT2 (); #ifdef CDTV_DEBUG - write_log (L"STCH %d\n", stch_cnt++); + write_log (L"STCH %d\n", stch_cnt++); #endif - } + } } void bleh (void) { #if 0 - cd_playing = cd_finished = cd_motor = cd_media = 1; - cd_isready = 0; - cd_playing = 0; - do_stch(); + cd_playing = cd_finished = cd_motor = cd_media = 1; + cd_isready = 0; + cd_playing = 0; + do_stch(); #endif } static void cdtv_reset (void) { - write_log (L"CDTV: reset\n"); - cdaudiostop(); - cd_playing = cd_paused = 0; - cd_motor = 0; - cd_media = 0; - cd_error = 0; - cd_finished = 0; - cd_led = 0; - stch = 0; - first = -1; + write_log (L"CDTV: reset\n"); + cdaudiostop(); + cd_playing = cd_paused = 0; + cd_motor = 0; + cd_media = 0; + cd_error = 0; + cd_finished = 0; + cd_led = 0; + stch = 0; + first = -1; } static uae_u32 dmac_bget2 (uaecptr addr) { - uae_u8 v = 0; + uae_u8 v = 0; - if (addr < 0x40) - return dmacmemory[addr]; + if (addr < 0x40) + return dmacmemory[addr]; - if (addr >= 0xb0 && addr < 0xc0) - return tp_bget ((addr - 0xb0) / 2); + if (addr >= 0xb0 && addr < 0xc0) + return tp_bget ((addr - 0xb0) / 2); #ifdef ROMHACK - if (addr >= ROM_OFFSET) { - if (rom) { - int off = addr & rom_mask; - return rom[off]; + if (addr >= ROM_OFFSET) { + if (rom) { + int off = addr & rom_mask; + return rom[off]; + } + return 0; } - return 0; - } #endif - switch (addr) - { + switch (addr) + { case 0x41: - v = dmac_istr; - if (v) - v |= ISTR_INT_P; - dmac_istr &= ~0xf; - break; + v = dmac_istr; + if (v) + v |= ISTR_INT_P; + dmac_istr &= ~0xf; + break; case 0x43: - v = dmac_cntr; - break; + v = dmac_cntr; + break; case 0x91: - if (currprefs.cs_cdtvscsi) - v = wdscsi_getauxstatus (); - break; + if (currprefs.cs_cdtvscsi) + v = wdscsi_getauxstatus (); + break; case 0x93: - if (currprefs.cs_cdtvscsi) { - v = wdscsi_get (); - checkint (); - } - break; + if (currprefs.cs_cdtvscsi) { + v = wdscsi_get (); + checkint (); + } + break; case 0xa1: - if (cdrom_command_cnt_out >= 0) { - v = cdrom_command_output[cdrom_command_cnt_out]; - cdrom_command_output[cdrom_command_cnt_out++] = 0; - if (cdrom_command_cnt_out >= cdrom_command_size_out) { - stch = 1; - sten = 0; - cdrom_command_size_out = 0; - cdrom_command_cnt_out = -1; - } else { - sten = 1; - tp_check_interrupts (); - } - } - break; + if (cdrom_command_cnt_out >= 0) { + v = cdrom_command_output[cdrom_command_cnt_out]; + cdrom_command_output[cdrom_command_cnt_out++] = 0; + if (cdrom_command_cnt_out >= cdrom_command_size_out) { + stch = 1; + sten = 0; + cdrom_command_size_out = 0; + cdrom_command_cnt_out = -1; + } else { + sten = 1; + tp_check_interrupts (); + } + } + break; case 0xe8: case 0xe9: - dmac_istr |= ISTR_FE_FLG; - break; - /* XT IO */ + dmac_istr |= ISTR_FE_FLG; + break; + /* XT IO */ case 0xa3: case 0xa5: case 0xa7: - v = 0xff; - break; - } + v = 0xff; + break; + } #ifdef CDTV_DEBUG - if (addr != 0x41) - write_log (L"dmac_bget %04X=%02X PC=%08X\n", addr, v, M68K_GETPC); + if (addr != 0x41) + write_log (L"dmac_bget %04X=%02X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static void dmac_bput2 (uaecptr addr, uae_u32 b) { - if (addr >= 0xb0 && addr < 0xc0) { - tp_bput ((addr - 0xb0) / 2, b); - return; - } + if (addr >= 0xb0 && addr < 0xc0) { + tp_bput ((addr - 0xb0) / 2, b); + return; + } #ifdef CDTV_DEBUG - write_log (L"dmac_bput %04X=%02X PC=%08X\n", addr, b & 255, M68K_GETPC); + write_log (L"dmac_bput %04X=%02X PC=%08X\n", addr, b & 255, M68K_GETPC); #endif - switch (addr) - { + switch (addr) + { case 0x43: - dmac_cntr = b; - if (dmac_cntr & CNTR_PREST) - cdtv_reset (); - break; + dmac_cntr = b; + if (dmac_cntr & CNTR_PREST) + cdtv_reset (); + break; case 0x80: - dmac_wtc &= 0x00ffffff; - dmac_wtc |= b << 24; - break; + dmac_wtc &= 0x00ffffff; + dmac_wtc |= b << 24; + break; case 0x81: - dmac_wtc &= 0xff00ffff; - dmac_wtc |= b << 16; - break; + dmac_wtc &= 0xff00ffff; + dmac_wtc |= b << 16; + break; case 0x82: - dmac_wtc &= 0xffff00ff; - dmac_wtc |= b << 8; - break; + dmac_wtc &= 0xffff00ff; + dmac_wtc |= b << 8; + break; case 0x83: - dmac_wtc &= 0xffffff00; - dmac_wtc |= b << 0; - break; + dmac_wtc &= 0xffffff00; + dmac_wtc |= b << 0; + break; case 0x84: - dmac_acr &= 0x00ffffff; - dmac_acr |= b << 24; - break; + dmac_acr &= 0x00ffffff; + dmac_acr |= b << 24; + break; case 0x85: - dmac_acr &= 0xff00ffff; - dmac_acr |= b << 16; - break; + dmac_acr &= 0xff00ffff; + dmac_acr |= b << 16; + break; case 0x86: - dmac_acr &= 0xffff00ff; - dmac_acr |= b << 8; - break; + dmac_acr &= 0xffff00ff; + dmac_acr |= b << 8; + break; case 0x87: - dmac_acr &= 0xffffff01; - dmac_acr |= (b & ~ 1) << 0; - break; + dmac_acr &= 0xffffff01; + dmac_acr |= (b & ~ 1) << 0; + break; case 0x8e: - dmac_dawr &= 0x00ff; - dmac_dawr |= b << 8; - break; + dmac_dawr &= 0x00ff; + dmac_dawr |= b << 8; + break; case 0x8f: - dmac_dawr &= 0xff00; - dmac_dawr |= b << 0; - break; + dmac_dawr &= 0xff00; + dmac_dawr |= b << 0; + break; case 0x91: - if (currprefs.cs_cdtvscsi) { - wdscsi_sasr (b); - checkint (); - } - break; + if (currprefs.cs_cdtvscsi) { + wdscsi_sasr (b); + checkint (); + } + break; case 0x93: - if (currprefs.cs_cdtvscsi) { - wdscsi_put (b); - checkint (); - } - break; + if (currprefs.cs_cdtvscsi) { + wdscsi_put (b); + checkint (); + } + break; case 0xa1: - cdrom_command(b); - break; + cdrom_command(b); + break; case 0xe0: case 0xe1: - if (!dmac_dma) { - dmac_dma = 1; - dmac_start_dma (); - } - break; + if (!dmac_dma) { + dmac_dma = 1; + dmac_start_dma (); + } + break; case 0xe2: case 0xe3: - dmac_dma = 0; - dma_finished = 0; - break; + dmac_dma = 0; + dma_finished = 0; + break; case 0xe4: case 0xe5: - dmac_istr = 0; - checkint (); - break; + dmac_istr = 0; + checkint (); + break; case 0xe8: case 0xe9: - dmac_istr |= ISTR_FE_FLG; - break; - } + dmac_istr |= ISTR_FE_FLG; + break; + } - tp_check_interrupts (); + tp_check_interrupts (); } static uae_u32 REGPARAM2 dmac_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = (dmac_bget2 (addr) << 24) | (dmac_bget2 (addr + 1) << 16) | - (dmac_bget2 (addr + 2) << 8) | (dmac_bget2 (addr + 3)); + addr &= 65535; + v = (dmac_bget2 (addr) << 24) | (dmac_bget2 (addr + 1) << 16) | + (dmac_bget2 (addr + 2) << 8) | (dmac_bget2 (addr + 3)); #ifdef CDTV_DEBUG - write_log (L"dmac_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"dmac_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 dmac_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = (dmac_bget2 (addr) << 8) | dmac_bget2 (addr + 1); + addr &= 65535; + v = (dmac_bget2 (addr) << 8) | dmac_bget2 (addr + 1); #ifdef CDTV_DEBUG - write_log (L"dmac_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); + write_log (L"dmac_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 dmac_bget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = dmac_bget2 (addr); - if (!configured) + addr &= 65535; + v = dmac_bget2 (addr); + if (!configured) + return v; return v; - return v; } static void REGPARAM2 dmac_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; + addr &= 65535; #ifdef CDTV_DEBUG - write_log (L"dmac_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); + write_log (L"dmac_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); #endif - dmac_bput2 (addr, l >> 24); - dmac_bput2 (addr + 1, l >> 16); - dmac_bput2 (addr + 2, l >> 8); - dmac_bput2 (addr + 3, l); + dmac_bput2 (addr, l >> 24); + dmac_bput2 (addr + 1, l >> 16); + dmac_bput2 (addr + 2, l >> 8); + dmac_bput2 (addr + 3, l); } static void REGPARAM2 dmac_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; + addr &= 65535; #ifdef CDTV_DEBUG - write_log (L"dmac_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); + write_log (L"dmac_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); #endif - dmac_bput2 (addr, w >> 8); - dmac_bput2 (addr + 1, w); + dmac_bput2 (addr, w >> 8); + dmac_bput2 (addr + 1, w); } static void REGPARAM2 dmac_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 65535; - b &= 0xff; - if (addr == 0x48) { - map_banks (&dmac_bank, b, 0x10000 >> 16, 0x10000); - write_log (L"CDTV DMAC autoconfigured at %02X0000\n", b); - configured = 1; - expamem_next (); - return; - } - if (addr == 0x4c) { - write_log (L"CDTV DMAC AUTOCONFIG SHUT-UP!\n"); - configured = 1; - expamem_next (); - return; - } - if (!configured) - return; - dmac_bput2 (addr, b); + addr &= 65535; + b &= 0xff; + if (addr == 0x48) { + map_banks (&dmac_bank, b, 0x10000 >> 16, 0x10000); + write_log (L"CDTV DMAC autoconfigured at %02X0000\n", b); + configured = 1; + expamem_next (); + return; + } + if (addr == 0x4c) { + write_log (L"CDTV DMAC AUTOCONFIG SHUT-UP!\n"); + configured = 1; + expamem_next (); + return; + } + if (!configured) + return; + dmac_bput2 (addr, b); } static void open_unit (void) { - struct device_info di1, *di2; - int first = -1; - int cdtvunit = -1, audiounit = -1; - - if (unitnum >= 0) - sys_command_close (DF_IOCTL, unitnum); - unitnum = -1; - cdtv_reset (); - if (!device_func_init (DEVICE_TYPE_ANY)) { - write_log (L"no CDROM support\n"); - return; - } - for (unitnum = 0; unitnum < MAX_TOTAL_DEVICES; unitnum++) { - if (sys_command_open (DF_IOCTL, unitnum)) { - di2 = sys_command_info (DF_IOCTL, unitnum, &di1); - if (di2 && di2->type == INQ_ROMD) { - write_log (L"%s: ", di2->label); - if (first < 0) - first = unitnum; - if (get_toc () > 0) { - if (datatrack) { - uae_u8 *p = sys_command_cd_read (DF_IOCTL, unitnum, 16); - if (p) { - if (!memcmp (p + 8, "CDTV", 4)) { - write_log (L"CDTV\n"); - if (cdtvunit < 0) - cdtvunit = unitnum; - } + struct device_info di1, *di2; + int first = -1; + int cdtvunit = -1, audiounit = -1; + + if (unitnum >= 0) + sys_command_close (DF_IOCTL, unitnum); + unitnum = -1; + cdtv_reset (); + if (!device_func_init (DEVICE_TYPE_ANY)) { + write_log (L"no CDROM support\n"); + return; + } + for (unitnum = 0; unitnum < MAX_TOTAL_DEVICES; unitnum++) { + if (sys_command_open (DF_IOCTL, unitnum)) { + di2 = sys_command_info (DF_IOCTL, unitnum, &di1); + if (di2 && di2->type == INQ_ROMD) { + write_log (L"%s: ", di2->label); + if (first < 0) + first = unitnum; + if (get_toc () > 0) { + if (datatrack) { + uae_u8 *p = sys_command_cd_read (DF_IOCTL, unitnum, 16); + if (p) { + if (!memcmp (p + 8, "CDTV", 4)) { + write_log (L"CDTV\n"); + if (cdtvunit < 0) + cdtvunit = unitnum; + } + } + } else { + write_log (L"Audio CD\n"); + if (audiounit < 0) + audiounit = unitnum; + } + } else { + write_log (L"TOC read failed\n"); + } } - } else { - write_log (L"Audio CD\n"); - if (audiounit < 0) - audiounit = unitnum; - } - } else { - write_log (L"TOC read failed\n"); + sys_command_close (DF_IOCTL, unitnum); } - } - sys_command_close (DF_IOCTL, unitnum); } - } - unitnum = audiounit; - if (cdtvunit >= 0) - unitnum = cdtvunit; - if (unitnum < 0) - unitnum = first; - cd_media = 0; - if (unitnum >= 0) { - sys_command_open (DF_IOCTL, unitnum); - cd_media = ismedia () ? -1 : 0; - if (!cd_media) - cd_hunt = 1; - if (!get_toc()) - cd_media = 0; - cdaudiostop (); - } + unitnum = audiounit; + if (cdtvunit >= 0) + unitnum = cdtvunit; + if (unitnum < 0) + unitnum = first; + cd_media = 0; + if (unitnum >= 0) { + sys_command_open (DF_IOCTL, unitnum); + cd_media = ismedia () ? -1 : 0; + if (!cd_media) + cd_hunt = 1; + if (!get_toc()) + cd_media = 0; + cdaudiostop (); + } } static void ew (int addr, uae_u32 value) { - addr &= 0xffff; - if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { - dmacmemory[addr] = (value & 0xf0); - dmacmemory[addr + 2] = (value & 0x0f) << 4; - } else { - dmacmemory[addr] = ~(value & 0xf0); - dmacmemory[addr + 2] = ~((value & 0x0f) << 4); - } + addr &= 0xffff; + if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { + dmacmemory[addr] = (value & 0xf0); + dmacmemory[addr + 2] = (value & 0x0f) << 4; + } else { + dmacmemory[addr] = ~(value & 0xf0); + dmacmemory[addr + 2] = ~((value & 0x0f) << 4); + } } static uae_u32 REGPARAM2 dmac_wgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif #ifdef ROMHACK - addr &= 65535; - if (addr >= ROM_OFFSET) - v = (rom[addr & rom_mask] << 8) | rom[(addr + 1) & rom_mask]; + addr &= 65535; + if (addr >= ROM_OFFSET) + v = (rom[addr & rom_mask] << 8) | rom[(addr + 1) & rom_mask]; #endif - return v; + return v; } static uae_u32 REGPARAM2 dmac_lgeti (uaecptr addr) { - uae_u32 v = 0xffff; + uae_u32 v = 0xffff; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif #ifdef ROMHACK - addr &= 65535; - v = (dmac_wgeti(addr) << 16) | dmac_wgeti(addr + 2); + addr &= 65535; + v = (dmac_wgeti(addr) << 16) | dmac_wgeti(addr + 2); #endif - return v; + return v; } addrbank dmac_bank = { - dmac_lget, dmac_wget, dmac_bget, - dmac_lput, dmac_wput, dmac_bput, - default_xlate, default_check, NULL, L"CDTV DMAC/CD Controller", - dmac_lgeti, dmac_wgeti, ABFLAG_IO + dmac_lget, dmac_wget, dmac_bget, + dmac_lput, dmac_wput, dmac_bput, + default_xlate, default_check, NULL, L"CDTV DMAC/CD Controller", + dmac_lgeti, dmac_wgeti, ABFLAG_IO }; void cdtv_entergui (void) { - if (cd_playing && !cd_paused) - write_comm_pipe_u32 (&requests, 0x102, 1); + if (cd_playing && !cd_paused) + write_comm_pipe_u32 (&requests, 0x102, 1); } void cdtv_exitgui (void) { - if (cd_playing && !cd_paused) - write_comm_pipe_u32 (&requests, 0x103, 1); + if (cd_playing && !cd_paused) + write_comm_pipe_u32 (&requests, 0x103, 1); } @@ -1430,182 +1430,182 @@ static uae_u8 cdtv_battram[CDTV_NVRAM_SIZE]; void cdtv_loadcardmem(uae_u8 *p, int size) { - struct zfile *f; - - memset (p, 0, size); - f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); - if (!f) - return; - zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); - zfile_fread (p, size, 1, f); - zfile_fclose (f); + struct zfile *f; + + memset (p, 0, size); + f = zfile_fopen (currprefs.flashfile, L"rb", ZFD_NORMAL); + if (!f) + return; + zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); + zfile_fread (p, size, 1, f); + zfile_fclose (f); } void cdtv_savecardmem(uae_u8 *p, int size) { - struct zfile *f; - - f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) - return; - zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); - zfile_fwrite (p, size, 1, f); - zfile_fclose (f); + struct zfile *f; + + f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) + return; + zfile_fseek (f, CDTV_NVRAM_SIZE, SEEK_SET); + zfile_fwrite (p, size, 1, f); + zfile_fclose (f); } static void cdtv_battram_reset (void) { - struct zfile *f; - int v; - - memset (cdtv_battram, 0, CDTV_NVRAM_SIZE); - f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) { - f = zfile_fopen (currprefs.flashfile, L"wb", 0); - if (f) { - zfile_fwrite (cdtv_battram, CDTV_NVRAM_SIZE, 1, f); - zfile_fclose (f); + struct zfile *f; + int v; + + memset (cdtv_battram, 0, CDTV_NVRAM_SIZE); + f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) { + f = zfile_fopen (currprefs.flashfile, L"wb", 0); + if (f) { + zfile_fwrite (cdtv_battram, CDTV_NVRAM_SIZE, 1, f); + zfile_fclose (f); + } + return; } - return; - } - v = zfile_fread (cdtv_battram, 1, CDTV_NVRAM_SIZE, f); - if (v < CDTV_NVRAM_SIZE) - zfile_fwrite (cdtv_battram + v, 1, CDTV_NVRAM_SIZE - v, f); - zfile_fclose (f); + v = zfile_fread (cdtv_battram, 1, CDTV_NVRAM_SIZE, f); + if (v < CDTV_NVRAM_SIZE) + zfile_fwrite (cdtv_battram + v, 1, CDTV_NVRAM_SIZE - v, f); + zfile_fclose (f); } void cdtv_battram_write (int addr, int v) { - struct zfile *f; - int offset = addr & CDTV_NVRAM_MASK; - - if (offset >= CDTV_NVRAM_SIZE) - return; - if (cdtv_battram[offset] == v) - return; - cdtv_battram[offset] = v; - f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) - return; - zfile_fseek (f, offset, SEEK_SET); - zfile_fwrite (cdtv_battram + offset, 1, 1, f); - zfile_fclose (f); + struct zfile *f; + int offset = addr & CDTV_NVRAM_MASK; + + if (offset >= CDTV_NVRAM_SIZE) + return; + if (cdtv_battram[offset] == v) + return; + cdtv_battram[offset] = v; + f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) + return; + zfile_fseek (f, offset, SEEK_SET); + zfile_fwrite (cdtv_battram + offset, 1, 1, f); + zfile_fclose (f); } uae_u8 cdtv_battram_read (int addr) { - uae_u8 v; - int offset; - offset = addr & CDTV_NVRAM_MASK; - if (offset >= CDTV_NVRAM_SIZE) - return 0; - v = cdtv_battram[offset]; - return v; + uae_u8 v; + int offset; + offset = addr & CDTV_NVRAM_MASK; + if (offset >= CDTV_NVRAM_SIZE) + return 0; + v = cdtv_battram[offset]; + return v; } int cdtv_add_scsi_unit(int ch, TCHAR *path, int blocksize, int readonly, - TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, TCHAR *filesys) + TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, TCHAR *filesys) { - return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 1); + return addscsi (ch, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys, 1); } void cdtv_free (void) { - if (thread_alive > 0) { - dmac_dma = 0; - dma_finished = 0; - write_comm_pipe_u32 (&requests, 0x0104, 1); - write_comm_pipe_u32 (&requests, 0xffff, 1); - while (thread_alive > 0) - sleep_millis (10); - } - thread_alive = 0; - cdaudiostop (); - if (unitnum >= 0) - sys_command_close (DF_IOCTL, unitnum); - unitnum = -1; - configured = 0; + if (thread_alive > 0) { + dmac_dma = 0; + dma_finished = 0; + write_comm_pipe_u32 (&requests, 0x0104, 1); + write_comm_pipe_u32 (&requests, 0xffff, 1); + while (thread_alive > 0) + sleep_millis (10); + } + thread_alive = 0; + cdaudiostop (); + if (unitnum >= 0) + sys_command_close (DF_IOCTL, unitnum); + unitnum = -1; + configured = 0; } #ifdef ROMHACK2 extern uae_u8 *extendedkickmemory, *cardmemory; static void romhack (void) { - struct zfile *z; - int roms[5]; - struct romlist *rl; - int rom_size; - uae_u8 *rom, *p; - - extendedkickmemory[0x558c] = 0xff; - - roms[0] = 55; - roms[1] = 54; - roms[2] = 53; - roms[3] = -1; - - rl = getromlistbyids(roms); - if (rl) { - write_log (L"A590/A2091 BOOT ROM '%s' %d.%d\n", rl->path, rl->rd->ver, rl->rd->rev); - z = zfile_fopen(rl->path, "rb", ZFD_NORMAL); - if (z) { - rom_size = 16384; - rom = (uae_u8*)xmalloc (rom_size); - zfile_fread (rom, rom_size, 1, z); - rom[0x2071] = 0xe0; rom[0x2072] |= 0x40; - rom[0x2075] = 0xe0; rom[0x2076] |= 0x40; - rom[0x207d] = 0xe0; rom[0x207e] |= 0x40; - rom[0x2081] = 0xe0; rom[0x2082] |= 0x40; - rom[0x2085] = 0xe0; rom[0x2086] |= 0x40; - rom[0x207b] = 0x32; - p = cardmemory + 0x4000; - memcpy (p, rom + 0x2000, 0x2000); - memcpy (p + 0x2000, rom, 0x2000); + struct zfile *z; + int roms[5]; + struct romlist *rl; + int rom_size; + uae_u8 *rom, *p; + + extendedkickmemory[0x558c] = 0xff; + + roms[0] = 55; + roms[1] = 54; + roms[2] = 53; + roms[3] = -1; + + rl = getromlistbyids(roms); + if (rl) { + write_log (L"A590/A2091 BOOT ROM '%s' %d.%d\n", rl->path, rl->rd->ver, rl->rd->rev); + z = zfile_fopen(rl->path, "rb", ZFD_NORMAL); + if (z) { + rom_size = 16384; + rom = (uae_u8*)xmalloc (rom_size); + zfile_fread (rom, rom_size, 1, z); + rom[0x2071] = 0xe0; rom[0x2072] |= 0x40; + rom[0x2075] = 0xe0; rom[0x2076] |= 0x40; + rom[0x207d] = 0xe0; rom[0x207e] |= 0x40; + rom[0x2081] = 0xe0; rom[0x2082] |= 0x40; + rom[0x2085] = 0xe0; rom[0x2086] |= 0x40; + rom[0x207b] = 0x32; + p = cardmemory + 0x4000; + memcpy (p, rom + 0x2000, 0x2000); + memcpy (p + 0x2000, rom, 0x2000); + } + zfile_fclose(z); } - zfile_fclose(z); - } - //kickmemory[0x3592c] = 0xff; + //kickmemory[0x3592c] = 0xff; } #endif void cdtv_init (void) { - if (!thread_alive) { - init_comm_pipe (&requests, 100, 1); - uae_start_thread (L"cdtv", dev_thread, NULL, NULL); - while (!thread_alive) - sleep_millis(10); - } - write_comm_pipe_u32 (&requests, 0x0104, 1); - - configured = 0; - tp_a = tp_b = tp_c = tp_ad = tp_bd = tp_cd = 0; - tp_imr = tp_cr = tp_air = 0; - stch = 1; - sten = 1; - scor = 1; - sbcp = 0; - cdrom_command_cnt_out = -1; - cmd = enable = xaen = dten = 0; - memset (dmacmemory, 0xff, 100); - ew (0x00, 0xc0 | 0x01); - ew (0x04, 0x03); - ew (0x08, 0x40); - ew (0x10, 0x02); - ew (0x14, 0x02); - - ew (0x18, 0x00); /* ser.no. Byte 0 */ - ew (0x1c, 0x00); /* ser.no. Byte 1 */ - ew (0x20, 0x00); /* ser.no. Byte 2 */ - ew (0x24, 0x00); /* ser.no. Byte 3 */ + if (!thread_alive) { + init_comm_pipe (&requests, 100, 1); + uae_start_thread (L"cdtv", dev_thread, NULL, NULL); + while (!thread_alive) + sleep_millis(10); + } + write_comm_pipe_u32 (&requests, 0x0104, 1); + + configured = 0; + tp_a = tp_b = tp_c = tp_ad = tp_bd = tp_cd = 0; + tp_imr = tp_cr = tp_air = 0; + stch = 1; + sten = 1; + scor = 1; + sbcp = 0; + cdrom_command_cnt_out = -1; + cmd = enable = xaen = dten = 0; + memset (dmacmemory, 0xff, 100); + ew (0x00, 0xc0 | 0x01); + ew (0x04, 0x03); + ew (0x08, 0x40); + ew (0x10, 0x02); + ew (0x14, 0x02); + + ew (0x18, 0x00); /* ser.no. Byte 0 */ + ew (0x1c, 0x00); /* ser.no. Byte 1 */ + ew (0x20, 0x00); /* ser.no. Byte 2 */ + ew (0x24, 0x00); /* ser.no. Byte 3 */ #ifdef ROMHACK2 - romhack(); + romhack(); #endif - /* KS autoconfig handles the rest */ - map_banks (&dmac_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); - cdtv_battram_reset (); - open_unit (); + /* KS autoconfig handles the rest */ + map_banks (&dmac_bank, 0xe80000 >> 16, 0x10000 >> 16, 0x10000); + cdtv_battram_reset (); + open_unit (); } diff --git a/cfgfile.c b/cfgfile.c index f3e1ed91..f17bce0c 100644 --- a/cfgfile.c +++ b/cfgfile.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Config file handling - * This still needs some thought before it's complete... - * - * Copyright 1998 Brian King, Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Config file handling +* This still needs some thought before it's complete... +* +* Copyright 1998 Brian King, Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -37,84 +37,84 @@ static int uaeconfig; static int unicode_config = 0; /* @@@ need to get rid of this... just cut part of the manual and print that - * as a help text. */ +* as a help text. */ struct cfg_lines { - const TCHAR *config_label, *config_help; + const TCHAR *config_label, *config_help; }; static const struct cfg_lines opttable[] = { - {L"help", L"Prints this help" }, - {L"config_description", L"" }, - {L"config_info", L"" }, - {L"use_gui", L"Enable the GUI? If no, then goes straight to emulator" }, - {L"use_debugger", L"Enable the debugger?" }, - {L"cpu_speed", L"can be max, real, or a number between 1 and 20" }, - {L"cpu_model", L"Can be 68000, 68010, 68020, 68030, 68040, 68060" }, - {L"fpu_model", L"Can be 68881, 68882, 68040, 68060" }, - {L"cpu_compatible", L"yes enables compatibility-mode" }, - {L"cpu_24bit_addressing", L"must be set to 'no' in order for Z3mem or P96mem to work" }, - {L"autoconfig", L"yes = add filesystems and extra ram" }, - {L"log_illegal_mem", L"print illegal memory access by Amiga software?" }, - {L"fastmem_size", L"Size in megabytes of fast-memory" }, - {L"chipmem_size", L"Size in megabytes of chip-memory" }, - {L"bogomem_size", L"Size in megabytes of bogo-memory at 0xC00000" }, - {L"a3000mem_size", L"Size in megabytes of A3000 memory" }, - {L"gfxcard_size", L"Size in megabytes of Picasso96 graphics-card memory" }, - {L"z3mem_size", L"Size in megabytes of Zorro-III expansion memory" }, - {L"gfx_test_speed", L"Test graphics speed?" }, - {L"gfx_framerate", L"Print every nth frame" }, - {L"gfx_width", L"Screen width" }, - {L"gfx_height", L"Screen height" }, - {L"gfx_refreshrate", L"Fullscreen refresh rate" }, - {L"gfx_vsync", L"Sync screen refresh to refresh rate" }, - {L"gfx_lores", L"Treat display as lo-res?" }, - {L"gfx_linemode", L"Can be none, double, or scanlines" }, - {L"gfx_fullscreen_amiga", L"Amiga screens are fullscreen?" }, - {L"gfx_fullscreen_picasso", L"Picasso screens are fullscreen?" }, - {L"gfx_center_horizontal", L"Center display horizontally?" }, - {L"gfx_center_vertical", L"Center display vertically?" }, - {L"gfx_colour_mode", L"" }, - {L"32bit_blits", L"Enable 32 bit blitter emulation" }, - {L"immediate_blits", L"Perform blits immediately" }, - {L"show_leds", L"LED display" }, - {L"keyboard_leds", L"Keyboard LEDs" }, - {L"gfxlib_replacement", L"Use graphics.library replacement?" }, - {L"sound_output", L"" }, - {L"sound_frequency", L"" }, - {L"sound_bits", L"" }, - {L"sound_channels", L"" }, - {L"sound_max_buff", L"" }, - {L"comp_trustbyte", L"How to access bytes in compiler (direct/indirect/indirectKS/afterPic" }, - {L"comp_trustword", L"How to access words in compiler (direct/indirect/indirectKS/afterPic" }, - {L"comp_trustlong", L"How to access longs in compiler (direct/indirect/indirectKS/afterPic" }, - {L"comp_nf", L"Whether to optimize away flag generation where possible" }, - {L"comp_fpu", L"Whether to provide JIT FPU emulation" }, - {L"compforcesettings", L"Whether to force the JIT compiler settings" }, - {L"cachesize", L"How many MB to use to buffer translated instructions"}, - {L"override_dga_address",L"Address from which to map the frame buffer (upper 16 bits) (DANGEROUS!)"}, - {L"avoid_cmov", L"Set to yes on machines that lack the CMOV instruction" }, - {L"avoid_dga", L"Set to yes if the use of DGA extension creates problems" }, - {L"avoid_vid", L"Set to yes if the use of the Vidmode extension creates problems" }, - {L"parallel_on_demand", L"" }, - {L"serial_on_demand", L"" }, - {L"scsi", L"scsi.device emulation" }, - {L"joyport0", L"" }, - {L"joyport1", L"" }, - {L"pci_devices", L"List of PCI devices to make visible to the emulated Amiga" }, - {L"kickstart_rom_file", L"Kickstart ROM image, (C) Copyright Amiga, Inc." }, - {L"kickstart_ext_rom_file", L"Extended Kickstart ROM image, (C) Copyright Amiga, Inc." }, - {L"kickstart_key_file", L"Key-file for encrypted ROM images (from Cloanto's Amiga Forever)" }, - {L"flash_ram_file", L"Flash/battery backed RAM image file." }, - {L"cart_file", L"Freezer cartridge ROM image file." }, - {L"floppy0", L"Diskfile for drive 0" }, - {L"floppy1", L"Diskfile for drive 1" }, - {L"floppy2", L"Diskfile for drive 2" }, - {L"floppy3", L"Diskfile for drive 3" }, - {L"hardfile", L"access,sectors, surfaces, reserved, blocksize, path format" }, - {L"filesystem", L"access,'Amiga volume-name':'host directory path' - where 'access' can be 'read-only' or 'read-write'" }, - {L"catweasel", L"Catweasel board io base address" } + {L"help", L"Prints this help" }, + {L"config_description", L"" }, + {L"config_info", L"" }, + {L"use_gui", L"Enable the GUI? If no, then goes straight to emulator" }, + {L"use_debugger", L"Enable the debugger?" }, + {L"cpu_speed", L"can be max, real, or a number between 1 and 20" }, + {L"cpu_model", L"Can be 68000, 68010, 68020, 68030, 68040, 68060" }, + {L"fpu_model", L"Can be 68881, 68882, 68040, 68060" }, + {L"cpu_compatible", L"yes enables compatibility-mode" }, + {L"cpu_24bit_addressing", L"must be set to 'no' in order for Z3mem or P96mem to work" }, + {L"autoconfig", L"yes = add filesystems and extra ram" }, + {L"log_illegal_mem", L"print illegal memory access by Amiga software?" }, + {L"fastmem_size", L"Size in megabytes of fast-memory" }, + {L"chipmem_size", L"Size in megabytes of chip-memory" }, + {L"bogomem_size", L"Size in megabytes of bogo-memory at 0xC00000" }, + {L"a3000mem_size", L"Size in megabytes of A3000 memory" }, + {L"gfxcard_size", L"Size in megabytes of Picasso96 graphics-card memory" }, + {L"z3mem_size", L"Size in megabytes of Zorro-III expansion memory" }, + {L"gfx_test_speed", L"Test graphics speed?" }, + {L"gfx_framerate", L"Print every nth frame" }, + {L"gfx_width", L"Screen width" }, + {L"gfx_height", L"Screen height" }, + {L"gfx_refreshrate", L"Fullscreen refresh rate" }, + {L"gfx_vsync", L"Sync screen refresh to refresh rate" }, + {L"gfx_lores", L"Treat display as lo-res?" }, + {L"gfx_linemode", L"Can be none, double, or scanlines" }, + {L"gfx_fullscreen_amiga", L"Amiga screens are fullscreen?" }, + {L"gfx_fullscreen_picasso", L"Picasso screens are fullscreen?" }, + {L"gfx_center_horizontal", L"Center display horizontally?" }, + {L"gfx_center_vertical", L"Center display vertically?" }, + {L"gfx_colour_mode", L"" }, + {L"32bit_blits", L"Enable 32 bit blitter emulation" }, + {L"immediate_blits", L"Perform blits immediately" }, + {L"show_leds", L"LED display" }, + {L"keyboard_leds", L"Keyboard LEDs" }, + {L"gfxlib_replacement", L"Use graphics.library replacement?" }, + {L"sound_output", L"" }, + {L"sound_frequency", L"" }, + {L"sound_bits", L"" }, + {L"sound_channels", L"" }, + {L"sound_max_buff", L"" }, + {L"comp_trustbyte", L"How to access bytes in compiler (direct/indirect/indirectKS/afterPic" }, + {L"comp_trustword", L"How to access words in compiler (direct/indirect/indirectKS/afterPic" }, + {L"comp_trustlong", L"How to access longs in compiler (direct/indirect/indirectKS/afterPic" }, + {L"comp_nf", L"Whether to optimize away flag generation where possible" }, + {L"comp_fpu", L"Whether to provide JIT FPU emulation" }, + {L"compforcesettings", L"Whether to force the JIT compiler settings" }, + {L"cachesize", L"How many MB to use to buffer translated instructions"}, + {L"override_dga_address",L"Address from which to map the frame buffer (upper 16 bits) (DANGEROUS!)"}, + {L"avoid_cmov", L"Set to yes on machines that lack the CMOV instruction" }, + {L"avoid_dga", L"Set to yes if the use of DGA extension creates problems" }, + {L"avoid_vid", L"Set to yes if the use of the Vidmode extension creates problems" }, + {L"parallel_on_demand", L"" }, + {L"serial_on_demand", L"" }, + {L"scsi", L"scsi.device emulation" }, + {L"joyport0", L"" }, + {L"joyport1", L"" }, + {L"pci_devices", L"List of PCI devices to make visible to the emulated Amiga" }, + {L"kickstart_rom_file", L"Kickstart ROM image, (C) Copyright Amiga, Inc." }, + {L"kickstart_ext_rom_file", L"Extended Kickstart ROM image, (C) Copyright Amiga, Inc." }, + {L"kickstart_key_file", L"Key-file for encrypted ROM images (from Cloanto's Amiga Forever)" }, + {L"flash_ram_file", L"Flash/battery backed RAM image file." }, + {L"cart_file", L"Freezer cartridge ROM image file." }, + {L"floppy0", L"Diskfile for drive 0" }, + {L"floppy1", L"Diskfile for drive 1" }, + {L"floppy2", L"Diskfile for drive 2" }, + {L"floppy3", L"Diskfile for drive 3" }, + {L"hardfile", L"access,sectors, surfaces, reserved, blocksize, path format" }, + {L"filesystem", L"access,'Amiga volume-name':'host directory path' - where 'access' can be 'read-only' or 'read-write'" }, + {L"catweasel", L"Catweasel board io base address" } }; static const TCHAR *guimode1[] = { L"no", L"yes", L"nowait", 0 }; @@ -152,8 +152,8 @@ static const TCHAR *rtctype[] = { L"none", L"MSM6242B", L"RP5C01A", 0 }; static const TCHAR *ciaatodmode[] = { L"vblank", L"50hz", L"60hz", 0 }; static const TCHAR *ksmirrortype[] = { L"none", L"e0", L"a8+e0", 0 }; static const TCHAR *cscompa[] = { - L"-", L"Generic", L"CDTV", L"CD32", L"A500", L"A500+", L"A600", - L"A1000", L"A1200", L"A2000", L"A3000", L"A3000T", L"A4000", L"A4000T", 0 + L"-", L"Generic", L"CDTV", L"CD32", L"A500", L"A500+", L"A600", + L"A1000", L"A1200", L"A2000", L"A3000", L"A3000T", L"A4000", L"A4000T", 0 }; /* 3-state boolean! */ static const TCHAR *fullmodes[] = { L"false", L"true", /* "FILE_NOT_FOUND", */ L"fullwindow", 0 }; @@ -169,3911 +169,3911 @@ static const TCHAR *epsonprinter[] = { L"none", L"ascii", L"epson_matrix_9pin", static const TCHAR *aspects[] = { L"none", L"vga", L"tv", 0 }; static const TCHAR *vsyncmodes[] = { L"false", L"true", L"autoswitch", 0 }; static const TCHAR *dongles[] = - { - L"none", - L"robocop 3", L"leaderboard", L"b.a.t. ii", L"italy'90 soccer", L"dames grand maitre", - L"rugby coach", L"cricket captain", L"leviathan", - NULL +{ + L"none", + L"robocop 3", L"leaderboard", L"b.a.t. ii", L"italy'90 soccer", L"dames grand maitre", + L"rugby coach", L"cricket captain", L"leviathan", + NULL }; static const TCHAR *obsolete[] = { - L"accuracy", L"gfx_opengl", L"gfx_32bit_blits", L"32bit_blits", - L"gfx_immediate_blits", L"gfx_ntsc", L"win32", L"gfx_filter_bits", - L"sound_pri_cutoff", L"sound_pri_time", L"sound_min_buff", L"sound_bits", - L"gfx_test_speed", L"gfxlib_replacement", L"enforcer", L"catweasel_io", - L"kickstart_key_file", L"fast_copper", L"sound_adjust", - L"serial_hardware_dtrdsr", L"gfx_filter_upscale", - L"gfx_correct_aspect", L"gfx_autoscale", - NULL + L"accuracy", L"gfx_opengl", L"gfx_32bit_blits", L"32bit_blits", + L"gfx_immediate_blits", L"gfx_ntsc", L"win32", L"gfx_filter_bits", + L"sound_pri_cutoff", L"sound_pri_time", L"sound_min_buff", L"sound_bits", + L"gfx_test_speed", L"gfxlib_replacement", L"enforcer", L"catweasel_io", + L"kickstart_key_file", L"fast_copper", L"sound_adjust", + L"serial_hardware_dtrdsr", L"gfx_filter_upscale", + L"gfx_correct_aspect", L"gfx_autoscale", + NULL }; #define UNEXPANDED L"$(FILE_PATH)" static void trimwsa (char *s) { - /* Delete trailing whitespace. */ - int len = strlen (s); - while (len > 0 && strcspn (s + len - 1, "\t \r\n") == 0) - s[--len] = '\0'; + /* Delete trailing whitespace. */ + int len = strlen (s); + while (len > 0 && strcspn (s + len - 1, "\t \r\n") == 0) + s[--len] = '\0'; } static int match_string (const TCHAR *table[], const TCHAR *str) { - int i; - for (i = 0; table[i] != 0; i++) - if (strcasecmp (table[i], str) == 0) - return i; - return -1; + int i; + for (i = 0; table[i] != 0; i++) + if (strcasecmp (table[i], str) == 0) + return i; + return -1; } TCHAR *cfgfile_subst_path (const TCHAR *path, const TCHAR *subst, const TCHAR *file) { - /* @@@ use strcasecmp for some targets. */ - if (_tcslen (path) > 0 && _tcsncmp (file, path, _tcslen (path)) == 0) { - int l; - TCHAR *p = xmalloc ((_tcslen (file) + _tcslen (subst) + 2) * sizeof (TCHAR)); - _tcscpy (p, subst); - l = _tcslen (p); - while (l > 0 && p[l - 1] == '/') - p[--l] = '\0'; - l = _tcslen (path); - while (file[l] == '/') - l++; - _tcscat (p, L"/"); _tcscat (p, file + l); - return p; - } - return my_strdup (file); + /* @@@ use strcasecmp for some targets. */ + if (_tcslen (path) > 0 && _tcsncmp (file, path, _tcslen (path)) == 0) { + int l; + TCHAR *p = xmalloc ((_tcslen (file) + _tcslen (subst) + 2) * sizeof (TCHAR)); + _tcscpy (p, subst); + l = _tcslen (p); + while (l > 0 && p[l - 1] == '/') + p[--l] = '\0'; + l = _tcslen (path); + while (file[l] == '/') + l++; + _tcscat (p, L"/"); _tcscat (p, file + l); + return p; + } + return my_strdup (file); } static int isdefault (const TCHAR *s) { - TCHAR tmp[MAX_DPATH]; - if (!default_file || uaeconfig) + TCHAR tmp[MAX_DPATH]; + if (!default_file || uaeconfig) + return 0; + zfile_fseek (default_file, 0, SEEK_SET); + while (zfile_fgets (tmp, sizeof tmp / sizeof (TCHAR), default_file)) { + if (!_tcscmp (tmp, s)) + return 1; + } return 0; - zfile_fseek (default_file, 0, SEEK_SET); - while (zfile_fgets (tmp, sizeof tmp / sizeof (TCHAR), default_file)) { - if (!_tcscmp (tmp, s)) - return 1; - } - return 0; } static size_t cfg_write (void *b, struct zfile *z) { - size_t v; - if (unicode_config) { - TCHAR lf = 10; - v = zfile_fwrite (b, _tcslen (b), sizeof (TCHAR), z); - zfile_fwrite (&lf, 1, 1, z); - } else { - char lf = 10; - char *s = ua (b); - v = zfile_fwrite (s, strlen (s), 1, z); - zfile_fwrite (&lf, 1, 1, z); - xfree (s); - } - return v; + size_t v; + if (unicode_config) { + TCHAR lf = 10; + v = zfile_fwrite (b, _tcslen (b), sizeof (TCHAR), z); + zfile_fwrite (&lf, 1, 1, z); + } else { + char lf = 10; + char *s = ua (b); + v = zfile_fwrite (s, strlen (s), 1, z); + zfile_fwrite (&lf, 1, 1, z); + xfree (s); + } + return v; } #define UTF8NAME L".utf8" static void cfg_dowrite (struct zfile *f, const TCHAR *option, const TCHAR *value, int d, int target) { - char lf = 10; - TCHAR tmp[CONFIG_BLEN]; - char tmpa[CONFIG_BLEN]; - char *tmp1, *tmp2; - int utf8; - - utf8 = 0; - tmp1 = ua (value); - tmp2 = uutf8 (value); - if (strcmp (tmp1, tmp2)) - utf8 = 1; - - if (target) - _stprintf (tmp, L"%s.%s=%s", TARGET_NAME, option, value); - else - _stprintf (tmp, L"%s=%s", option, value); - if (d && isdefault (tmp)) - goto end; - cfg_write (tmp, f); - if (utf8 && !unicode_config) { - char *opt = ua (option); - if (target) { - char *tna = ua (TARGET_NAME); - sprintf (tmpa, "%s.%s.utf8=%s", tna, opt, tmp2); - xfree (tna); - } else { - sprintf (tmpa, "%s.utf8=%s", opt, tmp2); + char lf = 10; + TCHAR tmp[CONFIG_BLEN]; + char tmpa[CONFIG_BLEN]; + char *tmp1, *tmp2; + int utf8; + + utf8 = 0; + tmp1 = ua (value); + tmp2 = uutf8 (value); + if (strcmp (tmp1, tmp2)) + utf8 = 1; + + if (target) + _stprintf (tmp, L"%s.%s=%s", TARGET_NAME, option, value); + else + _stprintf (tmp, L"%s=%s", option, value); + if (d && isdefault (tmp)) + goto end; + cfg_write (tmp, f); + if (utf8 && !unicode_config) { + char *opt = ua (option); + if (target) { + char *tna = ua (TARGET_NAME); + sprintf (tmpa, "%s.%s.utf8=%s", tna, opt, tmp2); + xfree (tna); + } else { + sprintf (tmpa, "%s.utf8=%s", opt, tmp2); + } + xfree (opt); + zfile_fwrite (tmpa, strlen (tmpa), 1, f); + zfile_fwrite (&lf, 1, 1, f); } - xfree (opt); - zfile_fwrite (tmpa, strlen (tmpa), 1, f); - zfile_fwrite (&lf, 1, 1, f); - } end: - xfree (tmp2); - xfree (tmp1); + xfree (tmp2); + xfree (tmp1); } void cfgfile_write_bool (struct zfile *f, const TCHAR *option, int b) { - cfg_dowrite (f, option, b ? L"true" : L"false", 0, 0); + cfg_dowrite (f, option, b ? L"true" : L"false", 0, 0); } void cfgfile_dwrite_bool (struct zfile *f, const TCHAR *option, int b) { - cfg_dowrite (f, option, b ? L"true" : L"false", 1, 0); + cfg_dowrite (f, option, b ? L"true" : L"false", 1, 0); } void cfgfile_write_str (struct zfile *f, const TCHAR *option, const TCHAR *value) { - cfg_dowrite (f, option, value, 0, 0); + cfg_dowrite (f, option, value, 0, 0); } void cfgfile_dwrite_str (struct zfile *f, const TCHAR *option, const TCHAR *value) { - cfg_dowrite (f, option, value, 1, 0); + cfg_dowrite (f, option, value, 1, 0); } void cfgfile_target_write_bool (struct zfile *f, const TCHAR *option, int b) { - cfg_dowrite (f, option, b ? L"true" : L"false", 0, 1); + cfg_dowrite (f, option, b ? L"true" : L"false", 0, 1); } void cfgfile_target_dwrite_bool (struct zfile *f, const TCHAR *option, int b) { - cfg_dowrite (f, option, b ? L"true" : L"false", 1, 1); + cfg_dowrite (f, option, b ? L"true" : L"false", 1, 1); } void cfgfile_target_write_str (struct zfile *f, const TCHAR *option, const TCHAR *value) { - cfg_dowrite (f, option, value, 0, 1); + cfg_dowrite (f, option, value, 0, 1); } void cfgfile_target_dwrite_str (struct zfile *f, const TCHAR *option, const TCHAR *value) { - cfg_dowrite (f, option, value, 1, 1); + cfg_dowrite (f, option, value, 1, 1); } void cfgfile_write (struct zfile *f, const TCHAR *option, const TCHAR *format,...) { - va_list parms; - TCHAR tmp[CONFIG_BLEN]; + va_list parms; + TCHAR tmp[CONFIG_BLEN]; - va_start (parms, format); - _vstprintf (tmp, format, parms); - cfg_dowrite (f, option, tmp, 0, 0); - va_end (parms); + va_start (parms, format); + _vsntprintf (tmp, CONFIG_BLEN, format, parms); + cfg_dowrite (f, option, tmp, 0, 0); + va_end (parms); } void cfgfile_dwrite (struct zfile *f, const TCHAR *option, const TCHAR *format,...) { - va_list parms; - TCHAR tmp[CONFIG_BLEN]; + va_list parms; + TCHAR tmp[CONFIG_BLEN]; - va_start (parms, format); - _vstprintf (tmp, format, parms); - cfg_dowrite (f, option, tmp, 1, 0); - va_end (parms); + va_start (parms, format); + _vsntprintf (tmp, CONFIG_BLEN, format, parms); + cfg_dowrite (f, option, tmp, 1, 0); + va_end (parms); } void cfgfile_target_write (struct zfile *f, const TCHAR *option, const TCHAR *format,...) { - va_list parms; - TCHAR tmp[CONFIG_BLEN]; + va_list parms; + TCHAR tmp[CONFIG_BLEN]; - va_start (parms, format); - _vstprintf (tmp, format, parms); - cfg_dowrite (f, option, tmp, 0, 1); - va_end (parms); + va_start (parms, format); + _vsntprintf (tmp, CONFIG_BLEN, format, parms); + cfg_dowrite (f, option, tmp, 0, 1); + va_end (parms); } void cfgfile_target_dwrite (struct zfile *f, const TCHAR *option, const TCHAR *format,...) { - va_list parms; - TCHAR tmp[CONFIG_BLEN]; + va_list parms; + TCHAR tmp[CONFIG_BLEN]; - va_start (parms, format); - _vstprintf (tmp, format, parms); - cfg_dowrite (f, option, tmp, 1, 1); - va_end (parms); + va_start (parms, format); + _vsntprintf (tmp, CONFIG_BLEN, format, parms); + cfg_dowrite (f, option, tmp, 1, 1); + va_end (parms); } static void write_filesys_config (struct uae_prefs *p, const TCHAR *unexpanded, - const TCHAR *default_path, struct zfile *f) -{ - int i; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - TCHAR *hdcontrollers[] = { L"uae", - L"ide0", L"ide1", L"ide2", L"ide3", - L"scsi0", L"scsi1", L"scsi2", L"scsi3", L"scsi4", L"scsi5", L"scsi6", - L"scsram", L"scside" }; /* scsram = smart card sram = pcmcia sram card */ - - for (i = 0; i < p->mountitems; i++) { - struct uaedev_config_info *uci = &p->mountconfig[i]; - TCHAR *str; - int bp = uci->bootpri; - - if (!uci->autoboot) - bp = -128; - if (uci->donotmount) - bp = -129; - str = cfgfile_subst_path (default_path, unexpanded, uci->rootdir); - if (!uci->ishdf) { - _stprintf (tmp, L"%s,%s:%s:%s,%d", uci->readonly ? L"ro" : L"rw", - uci->devname ? uci->devname : L"", uci->volname, str, bp); - cfgfile_write_str (f, L"filesystem2", tmp); + const TCHAR *default_path, struct zfile *f) +{ + int i; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; + TCHAR *hdcontrollers[] = { L"uae", + L"ide0", L"ide1", L"ide2", L"ide3", + L"scsi0", L"scsi1", L"scsi2", L"scsi3", L"scsi4", L"scsi5", L"scsi6", + L"scsram", L"scside" }; /* scsram = smart card sram = pcmcia sram card */ + + for (i = 0; i < p->mountitems; i++) { + struct uaedev_config_info *uci = &p->mountconfig[i]; + TCHAR *str; + int bp = uci->bootpri; + + if (!uci->autoboot) + bp = -128; + if (uci->donotmount) + bp = -129; + str = cfgfile_subst_path (default_path, unexpanded, uci->rootdir); + if (!uci->ishdf) { + _stprintf (tmp, L"%s,%s:%s:%s,%d", uci->readonly ? L"ro" : L"rw", + uci->devname ? uci->devname : L"", uci->volname, str, bp); + cfgfile_write_str (f, L"filesystem2", tmp); #if 0 - _stprintf (tmp2, L"filesystem=%s,%s:%s", uci->readonly ? L"ro" : L"rw", - uci->volname, str); - zfile_fputs (f, tmp2); + _stprintf (tmp2, L"filesystem=%s,%s:%s", uci->readonly ? L"ro" : L"rw", + uci->volname, str); + zfile_fputs (f, tmp2); #endif - } else { - _stprintf (tmp, L"%s,%s:%s,%d,%d,%d,%d,%d,%s,%s", - uci->readonly ? L"ro" : L"rw", - uci->devname ? uci->devname : L"", str, - uci->sectors, uci->surfaces, uci->reserved, uci->blocksize, - bp, uci->filesys ? uci->filesys : L"", hdcontrollers[uci->controller]); - cfgfile_write_str (f, L"hardfile2", tmp); + } else { + _stprintf (tmp, L"%s,%s:%s,%d,%d,%d,%d,%d,%s,%s", + uci->readonly ? L"ro" : L"rw", + uci->devname ? uci->devname : L"", str, + uci->sectors, uci->surfaces, uci->reserved, uci->blocksize, + bp, uci->filesys ? uci->filesys : L"", hdcontrollers[uci->controller]); + cfgfile_write_str (f, L"hardfile2", tmp); #if 0 - _stprintf (tmp2, L"hardfile=%s,%d,%d,%d,%d,%s", - uci->readonly ? "ro" : "rw", uci->sectors, - uci->surfaces, uci->reserved, uci->blocksize, str); - zfile_fputs (f, tmp2); + _stprintf (tmp2, L"hardfile=%s,%d,%d,%d,%d,%s", + uci->readonly ? "ro" : "rw", uci->sectors, + uci->surfaces, uci->reserved, uci->blocksize, str); + zfile_fputs (f, tmp2); #endif + } + _stprintf (tmp2, L"uaehf%d", i); + cfgfile_write (f, tmp2, L"%s,%s", uci->ishdf ? L"hdf" : L"dir", tmp); + xfree (str); } - _stprintf (tmp2, L"uaehf%d", i); - cfgfile_write (f, tmp2, L"%s,%s", uci->ishdf ? L"hdf" : L"dir", tmp); - xfree (str); - } } static void write_compatibility_cpu (struct zfile *f, struct uae_prefs *p) { - TCHAR tmp[100]; - int model; - - model = p->cpu_model; - if (model == 68030) - model = 68020; - if (model == 68060) - model = 68040; - if (p->address_space_24 && model == 68020) - _tcscpy (tmp, L"68ec020"); - else - _stprintf (tmp, L"%d", model); - if (model == 68020 && (p->fpu_model == 68881 || p->fpu_model == 68882)) - _tcscat (tmp, L"/68881"); - cfgfile_write (f, L"cpu_type", tmp); + TCHAR tmp[100]; + int model; + + model = p->cpu_model; + if (model == 68030) + model = 68020; + if (model == 68060) + model = 68040; + if (p->address_space_24 && model == 68020) + _tcscpy (tmp, L"68ec020"); + else + _stprintf (tmp, L"%d", model); + if (model == 68020 && (p->fpu_model == 68881 || p->fpu_model == 68882)) + _tcscat (tmp, L"/68881"); + cfgfile_write (f, L"cpu_type", tmp); } void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) { - struct strlist *sl; - TCHAR *str, tmp[MAX_DPATH]; - int i; - - cfgfile_write_str (f, L"config_description", p->description); - cfgfile_write_bool (f, L"config_hardware", type & CONFIG_TYPE_HARDWARE); - cfgfile_write_bool (f, L"config_host", type & CONFIG_TYPE_HOST); - if (p->info[0]) - cfgfile_write (f, L"config_info", p->info); - cfgfile_write (f, L"config_version", L"%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); - cfgfile_write_str (f, L"config_hardware_path", p->config_hardware_path); - cfgfile_write_str (f, L"config_host_path", p->config_host_path); - - for (sl = p->all_lines; sl; sl = sl->next) { - if (sl->unknown) - cfgfile_write_str (f, sl->option, sl->value); - } - - _stprintf (tmp, L"%s.rom_path", TARGET_NAME); - cfgfile_write_str (f, tmp, p->path_rom); - _stprintf (tmp, L"%s.floppy_path", TARGET_NAME); - cfgfile_write_str (f, tmp, p->path_floppy); - _stprintf (tmp, L"%s.hardfile_path", TARGET_NAME); - cfgfile_write_str (f, tmp, p->path_hardfile); - - cfg_write (L"; host-specific", f); - - target_save_options (f, p); - - cfg_write (L"; common", f); - - cfgfile_write_str (f, L"use_gui", guimode1[p->start_gui]); - cfgfile_write_bool (f, L"use_debugger", p->start_debugger); - str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romfile); - cfgfile_write_str (f, L"kickstart_rom_file", str); - xfree (str); - if (p->romident[0]) - cfgfile_dwrite_str (f, L"kickstart_rom", p->romident); - str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romextfile); - cfgfile_write_str (f, L"kickstart_ext_rom_file", str); - xfree (str); - if (p->romextident[0]) - cfgfile_write_str (f, L"kickstart_ext_rom=", p->romextident); - str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->flashfile); - cfgfile_write_str (f, L"flash_file", str); - xfree (str); - str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->cartfile); - cfgfile_write_str (f, L"cart_file", str); - xfree (str); - if (p->cartident[0]) - cfgfile_write_str (f, L"cart", p->cartident); - if (p->amaxromfile[0]) { - str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->amaxromfile); - cfgfile_write_str (f, L"amax_rom_file", str); - xfree (str); - } + struct strlist *sl; + TCHAR *str, tmp[MAX_DPATH]; + int i; - cfgfile_write_bool (f, L"kickshifter", p->kickshifter); + cfgfile_write_str (f, L"config_description", p->description); + cfgfile_write_bool (f, L"config_hardware", type & CONFIG_TYPE_HARDWARE); + cfgfile_write_bool (f, L"config_host", type & CONFIG_TYPE_HOST); + if (p->info[0]) + cfgfile_write (f, L"config_info", p->info); + cfgfile_write (f, L"config_version", L"%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); + cfgfile_write_str (f, L"config_hardware_path", p->config_hardware_path); + cfgfile_write_str (f, L"config_host_path", p->config_host_path); - p->nr_floppies = 4; - for (i = 0; i < 4; i++) { - str = cfgfile_subst_path (p->path_floppy, UNEXPANDED, p->df[i]); - _stprintf (tmp, L"floppy%d", i); - cfgfile_write_str (f, tmp, str); + for (sl = p->all_lines; sl; sl = sl->next) { + if (sl->unknown) + cfgfile_write_str (f, sl->option, sl->value); + } + + _stprintf (tmp, L"%s.rom_path", TARGET_NAME); + cfgfile_write_str (f, tmp, p->path_rom); + _stprintf (tmp, L"%s.floppy_path", TARGET_NAME); + cfgfile_write_str (f, tmp, p->path_floppy); + _stprintf (tmp, L"%s.hardfile_path", TARGET_NAME); + cfgfile_write_str (f, tmp, p->path_hardfile); + + cfg_write (L"; host-specific", f); + + target_save_options (f, p); + + cfg_write (L"; common", f); + + cfgfile_write_str (f, L"use_gui", guimode1[p->start_gui]); + cfgfile_write_bool (f, L"use_debugger", p->start_debugger); + str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romfile); + cfgfile_write_str (f, L"kickstart_rom_file", str); xfree (str); - _stprintf (tmp, L"floppy%dtype", i); - cfgfile_dwrite (f, tmp, L"%d", p->dfxtype[i]); - _stprintf (tmp, L"floppy%dsound", i); - cfgfile_dwrite (f, tmp, L"%d", p->dfxclick[i]); - if (p->dfxclick[i] < 0 && p->dfxclickexternal[i][0]) { - _stprintf (tmp, L"floppy%dsoundext", i); - cfgfile_dwrite (f, tmp, p->dfxclickexternal[i]); - } - if (p->dfxtype[i] < 0 && p->nr_floppies > i) - p->nr_floppies = i; - } - for (i = 0; i < MAX_SPARE_DRIVES; i++) { - if (p->dfxlist[i][0]) { - _stprintf (tmp, L"diskimage%d", i); - cfgfile_dwrite_str (f, tmp, p->dfxlist[i]); - } - } - - cfgfile_write (f, L"nr_floppies", L"%d", p->nr_floppies); - cfgfile_write (f, L"floppy_speed", L"%d", p->floppy_speed); - cfgfile_write (f, L"floppy_volume", L"%d", p->dfxclickvolume); - cfgfile_write_bool (f, L"parallel_on_demand", p->parallel_demand); - cfgfile_write_bool (f, L"serial_on_demand", p->serial_demand); - cfgfile_write_bool (f, L"serial_hardware_ctsrts", p->serial_hwctsrts); - cfgfile_write_bool (f, L"serial_direct", p->serial_direct); - cfgfile_write_str (f, L"scsi", scsimode[p->scsi]); - cfgfile_write_bool (f, L"uaeserial", p->uaeserial); - cfgfile_write_bool (f, L"sana2", p->sana2); - - cfgfile_write_str (f, L"sound_output", soundmode1[p->produce_sound]); - cfgfile_write_str (f, L"sound_channels", stereomode[p->sound_stereo]); - cfgfile_write (f, L"sound_stereo_separation", L"%d", p->sound_stereo_separation); - cfgfile_write (f, L"sound_stereo_mixing_delay", L"%d", p->sound_mixed_stereo_delay >= 0 ? p->sound_mixed_stereo_delay : 0); - cfgfile_write (f, L"sound_max_buff", L"%d", p->sound_maxbsiz); - cfgfile_write (f, L"sound_frequency", L"%d", p->sound_freq); - cfgfile_write (f, L"sound_latency", L"%d", p->sound_latency); - cfgfile_write_str (f, L"sound_interpol", interpolmode[p->sound_interpol]); - cfgfile_write_str (f, L"sound_filter", soundfiltermode1[p->sound_filter]); - cfgfile_write_str (f, L"sound_filter_type", soundfiltermode2[p->sound_filter_type]); - cfgfile_write (f, L"sound_volume", L"%d", p->sound_volume); - cfgfile_write_bool (f, L"sound_auto", p->sound_auto); - cfgfile_write_bool (f, L"sound_stereo_swap_paula", p->sound_stereo_swap_paula); - cfgfile_write_bool (f, L"sound_stereo_swap_ahi", p->sound_stereo_swap_ahi); - - cfgfile_write_str (f, L"comp_trustbyte", compmode[p->comptrustbyte]); - cfgfile_write_str (f, L"comp_trustword", compmode[p->comptrustword]); - cfgfile_write_str (f, L"comp_trustlong", compmode[p->comptrustlong]); - cfgfile_write_str (f, L"comp_trustnaddr", compmode[p->comptrustnaddr]); - cfgfile_write_bool (f, L"comp_nf", p->compnf); - cfgfile_write_bool (f, L"comp_constjump", p->comp_constjump); - cfgfile_write_bool (f, L"comp_oldsegv", p->comp_oldsegv); - - cfgfile_write_str (f, L"comp_flushmode", flushmode[p->comp_hardflush]); - cfgfile_write_bool (f, L"compfpu", p->compfpu); - cfgfile_write_bool (f, L"fpu_strict", p->fpu_strict); - cfgfile_write_bool (f, L"comp_midopt", p->comp_midopt); - cfgfile_write_bool (f, L"comp_lowopt", p->comp_lowopt); - cfgfile_write_bool (f, L"avoid_cmov", p->avoid_cmov); - cfgfile_write_bool (f, L"avoid_dga", p->avoid_dga); - cfgfile_write_bool (f, L"avoid_vid", p->avoid_vid); - cfgfile_write (f, L"cachesize", L"%d", p->cachesize); - if (p->override_dga_address) - cfgfile_write (f, L"override_dga_address", L"0x%08x", p->override_dga_address); - - for (i = 0; i < MAX_JPORTS; i++) { - struct jport *jp = &p->jports[i]; - int v = jp->id; - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; - if (v < 0) { - _tcscpy (tmp2, L"none"); - } else if (v < JSEM_JOYS) { - _stprintf (tmp2, L"kbd%d", v + 1); - } else if (v < JSEM_MICE) { - _stprintf (tmp2, L"joy%d", v - JSEM_JOYS); - } else { - _tcscpy (tmp2, L"mouse"); - if (v - JSEM_MICE > 0) - _stprintf (tmp2, L"mouse%d", v - JSEM_MICE); - } - if (i < 2 || jp->id >= 0) { - _stprintf (tmp1, L"joyport%d", i); - cfgfile_write (f, tmp1, tmp2); - if (i < 2 && jp->mode > 0) { - _stprintf (tmp1, L"joyport%dmode", i); - cfgfile_write (f, tmp1, joyportmodes[jp->mode]); - } - if (jp->name) { - _stprintf (tmp1, L"joyportfriendlyname%d", i); - cfgfile_write (f, tmp1, jp->name); - } - if (jp->configname) { - _stprintf (tmp1, L"joyportname%d", i); - cfgfile_write (f, tmp1, jp->configname); - } - } - } - if (p->dongle) { - if (p->dongle + 1 >= sizeof (dongles) / sizeof (TCHAR*)) - cfgfile_write (f, L"dongle", L"%d", p->dongle); - else - cfgfile_write_str (f, L"dongle", dongles[p->dongle]); - } - - cfgfile_write_bool (f, L"bsdsocket_emu", p->socket_emu); - if (p->a2065name[0]) - cfgfile_write_str (f, L"a2065", p->a2065name); - - cfgfile_write_bool (f, L"synchronize_clock", p->tod_hack); - cfgfile_write (f, L"maprom", L"0x%x", p->maprom); - cfgfile_dwrite_str (f, L"parallel_matrix_emulation", epsonprinter[p->parallel_matrix_emulation]); - cfgfile_write_bool (f, L"parallel_postscript_emulation", p->parallel_postscript_emulation); - cfgfile_write_bool (f, L"parallel_postscript_detection", p->parallel_postscript_detection); - cfgfile_write_str (f, L"ghostscript_parameters", p->ghostscript_parameters); - cfgfile_write (f, L"parallel_autoflush", L"%d", p->parallel_autoflush_time); - cfgfile_dwrite (f, L"uae_hide", L"%d", p->uae_hide); - cfgfile_dwrite_bool (f, L"magic_mouse", p->input_magic_mouse); - cfgfile_dwrite_str (f, L"magic_mousecursor", magiccursors[p->input_magic_mouse_cursor]); - cfgfile_dwrite_str (f, L"absolute_mouse", abspointers[p->input_tablet]); - - cfgfile_write (f, L"gfx_display", L"%d", p->gfx_display); - cfgfile_write_str (f, L"gfx_display_name", p->gfx_display_name); - cfgfile_write (f, L"gfx_framerate", L"%d", p->gfx_framerate); - cfgfile_write (f, L"gfx_width", L"%d", p->gfx_size_win.width); /* compatibility with old versions */ - cfgfile_write (f, L"gfx_height", L"%d", p->gfx_size_win.height); /* compatibility with old versions */ - cfgfile_write (f, L"gfx_top_windowed", L"%d", p->gfx_size_win.x); - cfgfile_write (f, L"gfx_left_windowed", L"%d", p->gfx_size_win.y); - cfgfile_write (f, L"gfx_width_windowed", L"%d", p->gfx_size_win.width); - cfgfile_write (f, L"gfx_height_windowed", L"%d", p->gfx_size_win.height); - cfgfile_write (f, L"gfx_width_fullscreen", L"%d", p->gfx_size_fs.width); - cfgfile_write (f, L"gfx_height_fullscreen", L"%d", p->gfx_size_fs.height); - cfgfile_write (f, L"gfx_refreshrate", L"%d", p->gfx_refreshrate); - cfgfile_write (f, L"gfx_autoresolution", L"%d", p->gfx_autoresolution); - cfgfile_write_str (f, L"gfx_vsync", vsyncmodes[p->gfx_avsync]); - cfgfile_write_bool (f, L"gfx_vsync_picasso", p->gfx_pvsync); - cfgfile_write_bool (f, L"gfx_lores", p->gfx_resolution == 0); - cfgfile_write_str (f, L"gfx_resolution", lorestype1[p->gfx_resolution]); - cfgfile_write_str (f, L"gfx_lores_mode", loresmode[p->gfx_lores_mode]); - cfgfile_write_bool (f, L"gfx_flickerfixer", p->gfx_scandoubler); - cfgfile_write_str (f, L"gfx_linemode", linemode1[p->gfx_linedbl]); - cfgfile_write_str (f, L"gfx_fullscreen_amiga", fullmodes[p->gfx_afullscreen]); - cfgfile_write_str (f, L"gfx_fullscreen_picasso", fullmodes[p->gfx_pfullscreen]); - cfgfile_write_str (f, L"gfx_center_horizontal", centermode1[p->gfx_xcenter]); - cfgfile_write_str (f, L"gfx_center_vertical", centermode1[p->gfx_ycenter]); - cfgfile_write_str (f, L"gfx_colour_mode", colormode1[p->color_mode]); - cfgfile_write_bool (f, L"gfx_blacker_than_black", p->gfx_blackerthanblack); + if (p->romident[0]) + cfgfile_dwrite_str (f, L"kickstart_rom", p->romident); + str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romextfile); + cfgfile_write_str (f, L"kickstart_ext_rom_file", str); + xfree (str); + if (p->romextident[0]) + cfgfile_write_str (f, L"kickstart_ext_rom=", p->romextident); + str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->flashfile); + cfgfile_write_str (f, L"flash_file", str); + xfree (str); + str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->cartfile); + cfgfile_write_str (f, L"cart_file", str); + xfree (str); + if (p->cartident[0]) + cfgfile_write_str (f, L"cart", p->cartident); + if (p->amaxromfile[0]) { + str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->amaxromfile); + cfgfile_write_str (f, L"amax_rom_file", str); + xfree (str); + } -#ifdef GFXFILTER - if (p->gfx_filter > 0) { - int i = 0; - struct uae_filter *uf; - while (uaefilters[i].name) { - uf = &uaefilters[i]; - if (uf->type == p->gfx_filter) { - if (p->gfx_filtershader[0]) - cfgfile_dwrite (f, L"gfx_filter", L"%s:%s", uf->cfgname, p->gfx_filtershader); + cfgfile_write_bool (f, L"kickshifter", p->kickshifter); + + p->nr_floppies = 4; + for (i = 0; i < 4; i++) { + str = cfgfile_subst_path (p->path_floppy, UNEXPANDED, p->df[i]); + _stprintf (tmp, L"floppy%d", i); + cfgfile_write_str (f, tmp, str); + xfree (str); + _stprintf (tmp, L"floppy%dtype", i); + cfgfile_dwrite (f, tmp, L"%d", p->dfxtype[i]); + _stprintf (tmp, L"floppy%dsound", i); + cfgfile_dwrite (f, tmp, L"%d", p->dfxclick[i]); + if (p->dfxclick[i] < 0 && p->dfxclickexternal[i][0]) { + _stprintf (tmp, L"floppy%dsoundext", i); + cfgfile_dwrite (f, tmp, p->dfxclickexternal[i]); + } + if (p->dfxtype[i] < 0 && p->nr_floppies > i) + p->nr_floppies = i; + } + for (i = 0; i < MAX_SPARE_DRIVES; i++) { + if (p->dfxlist[i][0]) { + _stprintf (tmp, L"diskimage%d", i); + cfgfile_dwrite_str (f, tmp, p->dfxlist[i]); + } + } + + cfgfile_write (f, L"nr_floppies", L"%d", p->nr_floppies); + cfgfile_write (f, L"floppy_speed", L"%d", p->floppy_speed); + cfgfile_write (f, L"floppy_volume", L"%d", p->dfxclickvolume); + cfgfile_write_bool (f, L"parallel_on_demand", p->parallel_demand); + cfgfile_write_bool (f, L"serial_on_demand", p->serial_demand); + cfgfile_write_bool (f, L"serial_hardware_ctsrts", p->serial_hwctsrts); + cfgfile_write_bool (f, L"serial_direct", p->serial_direct); + cfgfile_write_str (f, L"scsi", scsimode[p->scsi]); + cfgfile_write_bool (f, L"uaeserial", p->uaeserial); + cfgfile_write_bool (f, L"sana2", p->sana2); + + cfgfile_write_str (f, L"sound_output", soundmode1[p->produce_sound]); + cfgfile_write_str (f, L"sound_channels", stereomode[p->sound_stereo]); + cfgfile_write (f, L"sound_stereo_separation", L"%d", p->sound_stereo_separation); + cfgfile_write (f, L"sound_stereo_mixing_delay", L"%d", p->sound_mixed_stereo_delay >= 0 ? p->sound_mixed_stereo_delay : 0); + cfgfile_write (f, L"sound_max_buff", L"%d", p->sound_maxbsiz); + cfgfile_write (f, L"sound_frequency", L"%d", p->sound_freq); + cfgfile_write (f, L"sound_latency", L"%d", p->sound_latency); + cfgfile_write_str (f, L"sound_interpol", interpolmode[p->sound_interpol]); + cfgfile_write_str (f, L"sound_filter", soundfiltermode1[p->sound_filter]); + cfgfile_write_str (f, L"sound_filter_type", soundfiltermode2[p->sound_filter_type]); + cfgfile_write (f, L"sound_volume", L"%d", p->sound_volume); + cfgfile_write_bool (f, L"sound_auto", p->sound_auto); + cfgfile_write_bool (f, L"sound_stereo_swap_paula", p->sound_stereo_swap_paula); + cfgfile_write_bool (f, L"sound_stereo_swap_ahi", p->sound_stereo_swap_ahi); + + cfgfile_write_str (f, L"comp_trustbyte", compmode[p->comptrustbyte]); + cfgfile_write_str (f, L"comp_trustword", compmode[p->comptrustword]); + cfgfile_write_str (f, L"comp_trustlong", compmode[p->comptrustlong]); + cfgfile_write_str (f, L"comp_trustnaddr", compmode[p->comptrustnaddr]); + cfgfile_write_bool (f, L"comp_nf", p->compnf); + cfgfile_write_bool (f, L"comp_constjump", p->comp_constjump); + cfgfile_write_bool (f, L"comp_oldsegv", p->comp_oldsegv); + + cfgfile_write_str (f, L"comp_flushmode", flushmode[p->comp_hardflush]); + cfgfile_write_bool (f, L"compfpu", p->compfpu); + cfgfile_write_bool (f, L"fpu_strict", p->fpu_strict); + cfgfile_write_bool (f, L"comp_midopt", p->comp_midopt); + cfgfile_write_bool (f, L"comp_lowopt", p->comp_lowopt); + cfgfile_write_bool (f, L"avoid_cmov", p->avoid_cmov); + cfgfile_write_bool (f, L"avoid_dga", p->avoid_dga); + cfgfile_write_bool (f, L"avoid_vid", p->avoid_vid); + cfgfile_write (f, L"cachesize", L"%d", p->cachesize); + if (p->override_dga_address) + cfgfile_write (f, L"override_dga_address", L"0x%08x", p->override_dga_address); + + for (i = 0; i < MAX_JPORTS; i++) { + struct jport *jp = &p->jports[i]; + int v = jp->id; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; + if (v < 0) { + _tcscpy (tmp2, L"none"); + } else if (v < JSEM_JOYS) { + _stprintf (tmp2, L"kbd%d", v + 1); + } else if (v < JSEM_MICE) { + _stprintf (tmp2, L"joy%d", v - JSEM_JOYS); + } else { + _tcscpy (tmp2, L"mouse"); + if (v - JSEM_MICE > 0) + _stprintf (tmp2, L"mouse%d", v - JSEM_MICE); + } + if (i < 2 || jp->id >= 0) { + _stprintf (tmp1, L"joyport%d", i); + cfgfile_write (f, tmp1, tmp2); + if (i < 2 && jp->mode > 0) { + _stprintf (tmp1, L"joyport%dmode", i); + cfgfile_write (f, tmp1, joyportmodes[jp->mode]); + } + if (jp->name) { + _stprintf (tmp1, L"joyportfriendlyname%d", i); + cfgfile_write (f, tmp1, jp->name); + } + if (jp->configname) { + _stprintf (tmp1, L"joyportname%d", i); + cfgfile_write (f, tmp1, jp->configname); + } + } + } + if (p->dongle) { + if (p->dongle + 1 >= sizeof (dongles) / sizeof (TCHAR*)) + cfgfile_write (f, L"dongle", L"%d", p->dongle); else - cfgfile_dwrite_str (f, L"gfx_filter", uf->cfgname); - if (uf->type == p->gfx_filter) { - if (uf->x[0]) { - cfgfile_dwrite_str (f, L"gfx_filter_mode", filtermode1[p->gfx_filter_filtermode]); - } else { - int mt[4], i = 0; - if (uf->x[1]) - mt[i++] = 1; - if (uf->x[2]) - mt[i++] = 2; - if (uf->x[3]) - mt[i++] = 3; - if (uf->x[4]) - mt[i++] = 4; - cfgfile_dwrite (f, L"gfx_filter_mode", L"%dx", mt[p->gfx_filter_filtermode]); - } + cfgfile_write_str (f, L"dongle", dongles[p->dongle]); + } + + cfgfile_write_bool (f, L"bsdsocket_emu", p->socket_emu); + if (p->a2065name[0]) + cfgfile_write_str (f, L"a2065", p->a2065name); + + cfgfile_write_bool (f, L"synchronize_clock", p->tod_hack); + cfgfile_write (f, L"maprom", L"0x%x", p->maprom); + cfgfile_dwrite_str (f, L"parallel_matrix_emulation", epsonprinter[p->parallel_matrix_emulation]); + cfgfile_write_bool (f, L"parallel_postscript_emulation", p->parallel_postscript_emulation); + cfgfile_write_bool (f, L"parallel_postscript_detection", p->parallel_postscript_detection); + cfgfile_write_str (f, L"ghostscript_parameters", p->ghostscript_parameters); + cfgfile_write (f, L"parallel_autoflush", L"%d", p->parallel_autoflush_time); + cfgfile_dwrite (f, L"uae_hide", L"%d", p->uae_hide); + cfgfile_dwrite_bool (f, L"magic_mouse", p->input_magic_mouse); + cfgfile_dwrite_str (f, L"magic_mousecursor", magiccursors[p->input_magic_mouse_cursor]); + cfgfile_dwrite_str (f, L"absolute_mouse", abspointers[p->input_tablet]); + + cfgfile_write (f, L"gfx_display", L"%d", p->gfx_display); + cfgfile_write_str (f, L"gfx_display_name", p->gfx_display_name); + cfgfile_write (f, L"gfx_framerate", L"%d", p->gfx_framerate); + cfgfile_write (f, L"gfx_width", L"%d", p->gfx_size_win.width); /* compatibility with old versions */ + cfgfile_write (f, L"gfx_height", L"%d", p->gfx_size_win.height); /* compatibility with old versions */ + cfgfile_write (f, L"gfx_top_windowed", L"%d", p->gfx_size_win.x); + cfgfile_write (f, L"gfx_left_windowed", L"%d", p->gfx_size_win.y); + cfgfile_write (f, L"gfx_width_windowed", L"%d", p->gfx_size_win.width); + cfgfile_write (f, L"gfx_height_windowed", L"%d", p->gfx_size_win.height); + cfgfile_write (f, L"gfx_width_fullscreen", L"%d", p->gfx_size_fs.width); + cfgfile_write (f, L"gfx_height_fullscreen", L"%d", p->gfx_size_fs.height); + cfgfile_write (f, L"gfx_refreshrate", L"%d", p->gfx_refreshrate); + cfgfile_write (f, L"gfx_autoresolution", L"%d", p->gfx_autoresolution); + cfgfile_write_str (f, L"gfx_vsync", vsyncmodes[p->gfx_avsync]); + cfgfile_write_bool (f, L"gfx_vsync_picasso", p->gfx_pvsync); + cfgfile_write_bool (f, L"gfx_lores", p->gfx_resolution == 0); + cfgfile_write_str (f, L"gfx_resolution", lorestype1[p->gfx_resolution]); + cfgfile_write_str (f, L"gfx_lores_mode", loresmode[p->gfx_lores_mode]); + cfgfile_write_bool (f, L"gfx_flickerfixer", p->gfx_scandoubler); + cfgfile_write_str (f, L"gfx_linemode", linemode1[p->gfx_linedbl]); + cfgfile_write_str (f, L"gfx_fullscreen_amiga", fullmodes[p->gfx_afullscreen]); + cfgfile_write_str (f, L"gfx_fullscreen_picasso", fullmodes[p->gfx_pfullscreen]); + cfgfile_write_str (f, L"gfx_center_horizontal", centermode1[p->gfx_xcenter]); + cfgfile_write_str (f, L"gfx_center_vertical", centermode1[p->gfx_ycenter]); + cfgfile_write_str (f, L"gfx_colour_mode", colormode1[p->color_mode]); + cfgfile_write_bool (f, L"gfx_blacker_than_black", p->gfx_blackerthanblack); + +#ifdef GFXFILTER + if (p->gfx_filter > 0) { + int i = 0; + struct uae_filter *uf; + while (uaefilters[i].name) { + uf = &uaefilters[i]; + if (uf->type == p->gfx_filter) { + if (p->gfx_filtershader[0]) + cfgfile_dwrite (f, L"gfx_filter", L"%s:%s", uf->cfgname, p->gfx_filtershader); + else + cfgfile_dwrite_str (f, L"gfx_filter", uf->cfgname); + if (uf->type == p->gfx_filter) { + if (uf->x[0]) { + cfgfile_dwrite_str (f, L"gfx_filter_mode", filtermode1[p->gfx_filter_filtermode]); + } else { + int mt[4], i = 0; + if (uf->x[1]) + mt[i++] = 1; + if (uf->x[2]) + mt[i++] = 2; + if (uf->x[3]) + mt[i++] = 3; + if (uf->x[4]) + mt[i++] = 4; + cfgfile_dwrite (f, L"gfx_filter_mode", L"%dx", mt[p->gfx_filter_filtermode]); + } + } + } + i++; } - } - i++; - } - } else { - cfgfile_dwrite (f, L"gfx_filter", L"no"); - } - - cfgfile_dwrite (f, L"gfx_filter_vert_zoom", L"%d", p->gfx_filter_vert_zoom); - cfgfile_dwrite (f, L"gfx_filter_horiz_zoom", L"%d", p->gfx_filter_horiz_zoom); - cfgfile_dwrite (f, L"gfx_filter_vert_zoom_mult", L"%d", p->gfx_filter_vert_zoom_mult); - cfgfile_dwrite (f, L"gfx_filter_horiz_zoom_mult", L"%d", p->gfx_filter_horiz_zoom_mult); - cfgfile_dwrite (f, L"gfx_filter_vert_offset", L"%d", p->gfx_filter_vert_offset); - cfgfile_dwrite (f, L"gfx_filter_horiz_offset", L"%d", p->gfx_filter_horiz_offset); - cfgfile_dwrite (f, L"gfx_filter_scanlines", L"%d", p->gfx_filter_scanlines); - cfgfile_dwrite (f, L"gfx_filter_scanlinelevel", L"%d", p->gfx_filter_scanlinelevel); - cfgfile_dwrite (f, L"gfx_filter_scanlineratio", L"%d", p->gfx_filter_scanlineratio); - cfgfile_dwrite (f, L"gfx_filter_luminance", L"%d", p->gfx_filter_luminance); - cfgfile_dwrite (f, L"gfx_filter_contrast", L"%d", p->gfx_filter_contrast); - cfgfile_dwrite (f, L"gfx_filter_saturation", L"%d", p->gfx_filter_saturation); - cfgfile_dwrite (f, L"gfx_filter_gamma", L"%d", p->gfx_filter_gamma); - cfgfile_dwrite (f, L"gfx_filter_blur", L"%d", p->gfx_filter_blur); - cfgfile_dwrite (f, L"gfx_filter_noise", L"%d", p->gfx_filter_noise); - cfgfile_dwrite_str (f, L"gfx_filter_keep_aspect", aspects[p->gfx_filter_keep_aspect]); - cfgfile_dwrite_str (f, L"gfx_filter_autoscale", autoscale[p->gfx_filter_autoscale]); - cfgfile_dwrite (f, L"gfx_filter_aspect_ratio", L"%d:%d", - p->gfx_filter_aspect >= 0 ? (p->gfx_filter_aspect >> 8) : -1, - p->gfx_filter_aspect >= 0 ? (p->gfx_filter_aspect & 0xff) : -1); - cfgfile_dwrite (f, L"gfx_luminance", L"%d", p->gfx_luminance); - cfgfile_dwrite (f, L"gfx_contrast", L"%d", p->gfx_contrast); - cfgfile_dwrite (f, L"gfx_gamma", L"%d", p->gfx_gamma); + } else { + cfgfile_dwrite (f, L"gfx_filter", L"no"); + } + + cfgfile_dwrite (f, L"gfx_filter_vert_zoom", L"%d", p->gfx_filter_vert_zoom); + cfgfile_dwrite (f, L"gfx_filter_horiz_zoom", L"%d", p->gfx_filter_horiz_zoom); + cfgfile_dwrite (f, L"gfx_filter_vert_zoom_mult", L"%d", p->gfx_filter_vert_zoom_mult); + cfgfile_dwrite (f, L"gfx_filter_horiz_zoom_mult", L"%d", p->gfx_filter_horiz_zoom_mult); + cfgfile_dwrite (f, L"gfx_filter_vert_offset", L"%d", p->gfx_filter_vert_offset); + cfgfile_dwrite (f, L"gfx_filter_horiz_offset", L"%d", p->gfx_filter_horiz_offset); + cfgfile_dwrite (f, L"gfx_filter_scanlines", L"%d", p->gfx_filter_scanlines); + cfgfile_dwrite (f, L"gfx_filter_scanlinelevel", L"%d", p->gfx_filter_scanlinelevel); + cfgfile_dwrite (f, L"gfx_filter_scanlineratio", L"%d", p->gfx_filter_scanlineratio); + cfgfile_dwrite (f, L"gfx_filter_luminance", L"%d", p->gfx_filter_luminance); + cfgfile_dwrite (f, L"gfx_filter_contrast", L"%d", p->gfx_filter_contrast); + cfgfile_dwrite (f, L"gfx_filter_saturation", L"%d", p->gfx_filter_saturation); + cfgfile_dwrite (f, L"gfx_filter_gamma", L"%d", p->gfx_filter_gamma); + cfgfile_dwrite (f, L"gfx_filter_blur", L"%d", p->gfx_filter_blur); + cfgfile_dwrite (f, L"gfx_filter_noise", L"%d", p->gfx_filter_noise); + cfgfile_dwrite_str (f, L"gfx_filter_keep_aspect", aspects[p->gfx_filter_keep_aspect]); + cfgfile_dwrite_str (f, L"gfx_filter_autoscale", autoscale[p->gfx_filter_autoscale]); + cfgfile_dwrite (f, L"gfx_filter_aspect_ratio", L"%d:%d", + p->gfx_filter_aspect >= 0 ? (p->gfx_filter_aspect >> 8) : -1, + p->gfx_filter_aspect >= 0 ? (p->gfx_filter_aspect & 0xff) : -1); + cfgfile_dwrite (f, L"gfx_luminance", L"%d", p->gfx_luminance); + cfgfile_dwrite (f, L"gfx_contrast", L"%d", p->gfx_contrast); + cfgfile_dwrite (f, L"gfx_gamma", L"%d", p->gfx_gamma); #endif - cfgfile_write_bool (f, L"immediate_blits", p->immediate_blits); - cfgfile_write_bool (f, L"ntsc", p->ntscmode); - cfgfile_write_bool (f, L"genlock", p->genlock); - cfgfile_dwrite_bool (f, L"show_leds", p->leds_on_screen & STATUSLINE_CHIPSET); - cfgfile_dwrite_bool (f, L"show_leds_rtg", p->leds_on_screen & STATUSLINE_RTG); - cfgfile_dwrite (f, L"keyboard_leds", L"numlock:%s,capslock:%s,scrolllock:%s", - kbleds[p->keyboard_leds[0]], kbleds[p->keyboard_leds[1]], kbleds[p->keyboard_leds[2]]); - if (p->chipset_mask & CSMASK_AGA) - cfgfile_dwrite (f, L"chipset",L"aga"); - else if ((p->chipset_mask & CSMASK_ECS_AGNUS) && (p->chipset_mask & CSMASK_ECS_DENISE)) - cfgfile_dwrite (f, L"chipset",L"ecs"); - else if (p->chipset_mask & CSMASK_ECS_AGNUS) - cfgfile_dwrite (f, L"chipset",L"ecs_agnus"); - else if (p->chipset_mask & CSMASK_ECS_DENISE) - cfgfile_dwrite (f, L"chipset",L"ecs_denise"); - else - cfgfile_dwrite (f, L"chipset", L"ocs"); - cfgfile_write (f, L"chipset_refreshrate", L"%d", p->chipset_refreshrate); - cfgfile_write_str (f, L"collision_level", collmode[p->collision_level]); - - cfgfile_write_str(f, L"chipset_compatible", cscompa[p->cs_compatible]); - cfgfile_dwrite_str (f, L"ciaatod", ciaatodmode[p->cs_ciaatod]); - cfgfile_dwrite_str (f, L"rtc", rtctype[p->cs_rtc]); - //cfgfile_dwrite (f, L"chipset_rtc_adjust", L"%d", p->cs_rtc_adjust); - cfgfile_dwrite_bool (f, L"ksmirror_e0", p->cs_ksmirror_e0); - cfgfile_dwrite_bool (f, L"ksmirror_a8", p->cs_ksmirror_a8); - cfgfile_dwrite_bool (f, L"cd32cd", p->cs_cd32cd); - cfgfile_dwrite_bool (f, L"cd32c2p", p->cs_cd32c2p); - cfgfile_dwrite_bool (f, L"cd32nvram", p->cs_cd32nvram); - cfgfile_dwrite_bool (f, L"cdtvcd", p->cs_cdtvcd); - cfgfile_dwrite_bool (f, L"cdtvram", p->cs_cdtvram); - cfgfile_dwrite (f, L"cdtvramcard", L"%d", p->cs_cdtvcard); - cfgfile_dwrite_str (f, L"ide", p->cs_ide == IDE_A600A1200 ? L"a600/a1200" : (p->cs_ide == IDE_A4000 ? L"a4000" : L"none")); - cfgfile_dwrite_bool (f, L"a1000ram", p->cs_a1000ram); - cfgfile_dwrite (f, L"fatgary", L"%d", p->cs_fatgaryrev); - cfgfile_dwrite (f, L"ramsey", L"%d", p->cs_ramseyrev); - cfgfile_dwrite_bool (f, L"pcmcia", p->cs_pcmcia); - cfgfile_dwrite_bool (f, L"scsi_cdtv", p->cs_cdtvscsi); - cfgfile_dwrite_bool (f, L"scsi_a2091", p->cs_a2091); - cfgfile_dwrite_bool (f, L"scsi_a4091", p->cs_a4091); - cfgfile_dwrite_bool (f, L"scsi_a3000", p->cs_mbdmac == 1); - cfgfile_dwrite_bool (f, L"scsi_a4000t", p->cs_mbdmac == 2); - cfgfile_dwrite_bool (f, L"bogomem_fast", p->cs_slowmemisfast); - cfgfile_dwrite_bool (f, L"resetwarning", p->cs_resetwarning); - cfgfile_dwrite_bool (f, L"denise_noehb", p->cs_denisenoehb); - cfgfile_dwrite_bool (f, L"agnus_bltbusybug", p->cs_agnusbltbusybug); - - cfgfile_write (f, L"fastmem_size", L"%d", p->fastmem_size / 0x100000); - cfgfile_write (f, L"a3000mem_size", L"%d", p->mbresmem_low_size / 0x100000); - cfgfile_write (f, L"mbresmem_size", L"%d", p->mbresmem_high_size / 0x100000); - cfgfile_write (f, L"z3mem_size", L"%d", p->z3fastmem_size / 0x100000); - cfgfile_write (f, L"z3mem2_size", L"%d", p->z3fastmem2_size / 0x100000); - cfgfile_write (f, L"z3mem_start", L"0x%x", p->z3fastmem_start); - cfgfile_write (f, L"bogomem_size", L"%d", p->bogomem_size / 0x40000); - cfgfile_write (f, L"gfxcard_size", L"%d", p->gfxmem_size / 0x100000); - cfgfile_write (f, L"chipmem_size", L"%d", p->chipmem_size == 0x20000 ? -1 : (p->chipmem_size == 0x40000 ? 0 : p->chipmem_size / 0x80000)); - - if (p->m68k_speed > 0) - cfgfile_write (f, L"finegrain_cpu_speed", L"%d", p->m68k_speed); - else - cfgfile_write_str (f, L"cpu_speed", p->m68k_speed == -1 ? L"max" : L"real"); - - /* do not reorder start */ - write_compatibility_cpu(f, p); - cfgfile_write (f, L"cpu_model", L"%d", p->cpu_model); - if (p->fpu_model) - cfgfile_write (f, L"fpu_model", L"%d", p->fpu_model); - if (p->mmu_model) - cfgfile_write (f, L"mmu_model", L"%d", p->mmu_model); - cfgfile_write_bool (f, L"cpu_compatible", p->cpu_compatible); - cfgfile_write_bool (f, L"cpu_24bit_addressing", p->address_space_24); - /* do not reorder end */ - - if (currprefs.cpu_cycle_exact) { - if (p->cpu_frequency) - cfgfile_write (f, L"cpu_frequency", L"%d", p->cpu_frequency); - if (p->cpu_clock_multiplier) { - if (p->cpu_clock_multiplier >= 256) - cfgfile_write (f, L"cpu_multiplier", L"%d", p->cpu_clock_multiplier >> 8); - } - } - - cfgfile_write_bool (f, L"cpu_cycle_exact", p->cpu_cycle_exact); - cfgfile_write_bool (f, L"blitter_cycle_exact", p->blitter_cycle_exact); - cfgfile_write_bool (f, L"cycle_exact", p->cpu_cycle_exact && p->blitter_cycle_exact ? 1 : 0); - cfgfile_write_bool (f, L"rtg_nocustom", p->picasso96_nocustom); - cfgfile_write (f, L"rtg_modes", L"0x%x", p->picasso96_modeflags); - - cfgfile_write_bool (f, L"log_illegal_mem", p->illegal_mem); - if (p->catweasel >= 100) - cfgfile_dwrite (f, L"catweasel", L"0x%x", p->catweasel); - else - cfgfile_dwrite (f, L"catweasel", L"%d", p->catweasel); - - cfgfile_write_str (f, L"kbd_lang", (p->keyboard_lang == KBD_LANG_DE ? L"de" - : p->keyboard_lang == KBD_LANG_DK ? L"dk" - : p->keyboard_lang == KBD_LANG_ES ? L"es" - : p->keyboard_lang == KBD_LANG_US ? L"us" - : p->keyboard_lang == KBD_LANG_SE ? L"se" - : p->keyboard_lang == KBD_LANG_FR ? L"fr" - : p->keyboard_lang == KBD_LANG_IT ? L"it" - : L"FOO")); - - cfgfile_dwrite_str (f, L"state_replay", p->statecapture ? L"yes" : L"no"); - cfgfile_dwrite (f, L"state_replay_rate", L"%d", p->statecapturerate); - cfgfile_dwrite (f, L"state_replay_buffer", L"%d", p->statecapturebuffersize); + cfgfile_write_bool (f, L"immediate_blits", p->immediate_blits); + cfgfile_write_bool (f, L"ntsc", p->ntscmode); + cfgfile_write_bool (f, L"genlock", p->genlock); + cfgfile_dwrite_bool (f, L"show_leds", p->leds_on_screen & STATUSLINE_CHIPSET); + cfgfile_dwrite_bool (f, L"show_leds_rtg", p->leds_on_screen & STATUSLINE_RTG); + cfgfile_dwrite (f, L"keyboard_leds", L"numlock:%s,capslock:%s,scrolllock:%s", + kbleds[p->keyboard_leds[0]], kbleds[p->keyboard_leds[1]], kbleds[p->keyboard_leds[2]]); + if (p->chipset_mask & CSMASK_AGA) + cfgfile_dwrite (f, L"chipset",L"aga"); + else if ((p->chipset_mask & CSMASK_ECS_AGNUS) && (p->chipset_mask & CSMASK_ECS_DENISE)) + cfgfile_dwrite (f, L"chipset",L"ecs"); + else if (p->chipset_mask & CSMASK_ECS_AGNUS) + cfgfile_dwrite (f, L"chipset",L"ecs_agnus"); + else if (p->chipset_mask & CSMASK_ECS_DENISE) + cfgfile_dwrite (f, L"chipset",L"ecs_denise"); + else + cfgfile_dwrite (f, L"chipset", L"ocs"); + cfgfile_write (f, L"chipset_refreshrate", L"%d", p->chipset_refreshrate); + cfgfile_write_str (f, L"collision_level", collmode[p->collision_level]); + + cfgfile_write_str(f, L"chipset_compatible", cscompa[p->cs_compatible]); + cfgfile_dwrite_str (f, L"ciaatod", ciaatodmode[p->cs_ciaatod]); + cfgfile_dwrite_str (f, L"rtc", rtctype[p->cs_rtc]); + //cfgfile_dwrite (f, L"chipset_rtc_adjust", L"%d", p->cs_rtc_adjust); + cfgfile_dwrite_bool (f, L"ksmirror_e0", p->cs_ksmirror_e0); + cfgfile_dwrite_bool (f, L"ksmirror_a8", p->cs_ksmirror_a8); + cfgfile_dwrite_bool (f, L"cd32cd", p->cs_cd32cd); + cfgfile_dwrite_bool (f, L"cd32c2p", p->cs_cd32c2p); + cfgfile_dwrite_bool (f, L"cd32nvram", p->cs_cd32nvram); + cfgfile_dwrite_bool (f, L"cdtvcd", p->cs_cdtvcd); + cfgfile_dwrite_bool (f, L"cdtvram", p->cs_cdtvram); + cfgfile_dwrite (f, L"cdtvramcard", L"%d", p->cs_cdtvcard); + cfgfile_dwrite_str (f, L"ide", p->cs_ide == IDE_A600A1200 ? L"a600/a1200" : (p->cs_ide == IDE_A4000 ? L"a4000" : L"none")); + cfgfile_dwrite_bool (f, L"a1000ram", p->cs_a1000ram); + cfgfile_dwrite (f, L"fatgary", L"%d", p->cs_fatgaryrev); + cfgfile_dwrite (f, L"ramsey", L"%d", p->cs_ramseyrev); + cfgfile_dwrite_bool (f, L"pcmcia", p->cs_pcmcia); + cfgfile_dwrite_bool (f, L"scsi_cdtv", p->cs_cdtvscsi); + cfgfile_dwrite_bool (f, L"scsi_a2091", p->cs_a2091); + cfgfile_dwrite_bool (f, L"scsi_a4091", p->cs_a4091); + cfgfile_dwrite_bool (f, L"scsi_a3000", p->cs_mbdmac == 1); + cfgfile_dwrite_bool (f, L"scsi_a4000t", p->cs_mbdmac == 2); + cfgfile_dwrite_bool (f, L"bogomem_fast", p->cs_slowmemisfast); + cfgfile_dwrite_bool (f, L"resetwarning", p->cs_resetwarning); + cfgfile_dwrite_bool (f, L"denise_noehb", p->cs_denisenoehb); + cfgfile_dwrite_bool (f, L"agnus_bltbusybug", p->cs_agnusbltbusybug); + + cfgfile_write (f, L"fastmem_size", L"%d", p->fastmem_size / 0x100000); + cfgfile_write (f, L"a3000mem_size", L"%d", p->mbresmem_low_size / 0x100000); + cfgfile_write (f, L"mbresmem_size", L"%d", p->mbresmem_high_size / 0x100000); + cfgfile_write (f, L"z3mem_size", L"%d", p->z3fastmem_size / 0x100000); + cfgfile_write (f, L"z3mem2_size", L"%d", p->z3fastmem2_size / 0x100000); + cfgfile_write (f, L"z3mem_start", L"0x%x", p->z3fastmem_start); + cfgfile_write (f, L"bogomem_size", L"%d", p->bogomem_size / 0x40000); + cfgfile_write (f, L"gfxcard_size", L"%d", p->gfxmem_size / 0x100000); + cfgfile_write (f, L"chipmem_size", L"%d", p->chipmem_size == 0x20000 ? -1 : (p->chipmem_size == 0x40000 ? 0 : p->chipmem_size / 0x80000)); + + if (p->m68k_speed > 0) + cfgfile_write (f, L"finegrain_cpu_speed", L"%d", p->m68k_speed); + else + cfgfile_write_str (f, L"cpu_speed", p->m68k_speed == -1 ? L"max" : L"real"); + + /* do not reorder start */ + write_compatibility_cpu(f, p); + cfgfile_write (f, L"cpu_model", L"%d", p->cpu_model); + if (p->fpu_model) + cfgfile_write (f, L"fpu_model", L"%d", p->fpu_model); + if (p->mmu_model) + cfgfile_write (f, L"mmu_model", L"%d", p->mmu_model); + cfgfile_write_bool (f, L"cpu_compatible", p->cpu_compatible); + cfgfile_write_bool (f, L"cpu_24bit_addressing", p->address_space_24); + /* do not reorder end */ + + if (currprefs.cpu_cycle_exact) { + if (p->cpu_frequency) + cfgfile_write (f, L"cpu_frequency", L"%d", p->cpu_frequency); + if (p->cpu_clock_multiplier) { + if (p->cpu_clock_multiplier >= 256) + cfgfile_write (f, L"cpu_multiplier", L"%d", p->cpu_clock_multiplier >> 8); + } + } + + cfgfile_write_bool (f, L"cpu_cycle_exact", p->cpu_cycle_exact); + cfgfile_write_bool (f, L"blitter_cycle_exact", p->blitter_cycle_exact); + cfgfile_write_bool (f, L"cycle_exact", p->cpu_cycle_exact && p->blitter_cycle_exact ? 1 : 0); + cfgfile_write_bool (f, L"rtg_nocustom", p->picasso96_nocustom); + cfgfile_write (f, L"rtg_modes", L"0x%x", p->picasso96_modeflags); + + cfgfile_write_bool (f, L"log_illegal_mem", p->illegal_mem); + if (p->catweasel >= 100) + cfgfile_dwrite (f, L"catweasel", L"0x%x", p->catweasel); + else + cfgfile_dwrite (f, L"catweasel", L"%d", p->catweasel); + + cfgfile_write_str (f, L"kbd_lang", (p->keyboard_lang == KBD_LANG_DE ? L"de" + : p->keyboard_lang == KBD_LANG_DK ? L"dk" + : p->keyboard_lang == KBD_LANG_ES ? L"es" + : p->keyboard_lang == KBD_LANG_US ? L"us" + : p->keyboard_lang == KBD_LANG_SE ? L"se" + : p->keyboard_lang == KBD_LANG_FR ? L"fr" + : p->keyboard_lang == KBD_LANG_IT ? L"it" + : L"FOO")); + + cfgfile_dwrite_str (f, L"state_replay", p->statecapture ? L"yes" : L"no"); + cfgfile_dwrite (f, L"state_replay_rate", L"%d", p->statecapturerate); + cfgfile_dwrite (f, L"state_replay_buffer", L"%d", p->statecapturebuffersize); #ifdef FILESYS - write_filesys_config (p, UNEXPANDED, p->path_hardfile, f); - if (p->filesys_no_uaefsdb) - cfgfile_write_bool (f, L"filesys_no_fsdb", p->filesys_no_uaefsdb); + write_filesys_config (p, UNEXPANDED, p->path_hardfile, f); + if (p->filesys_no_uaefsdb) + cfgfile_write_bool (f, L"filesys_no_fsdb", p->filesys_no_uaefsdb); #endif - write_inputdevice_config (p, f); + write_inputdevice_config (p, f); - /* Don't write gfxlib/gfx_test_speed options. */ + /* Don't write gfxlib/gfx_test_speed options. */ } int cfgfile_yesno (const TCHAR *option, const TCHAR *value, const TCHAR *name, int *location) { - if (_tcscmp (option, name) != 0) - return 0; - if (strcasecmp (value, L"yes") == 0 || strcasecmp (value, L"y") == 0 - || strcasecmp (value, L"true") == 0 || strcasecmp (value, L"t") == 0) - *location = 1; - else if (strcasecmp (value, L"no") == 0 || strcasecmp (value, L"n") == 0 - || strcasecmp (value, L"false") == 0 || strcasecmp (value, L"f") == 0) - *location = 0; - else { - write_log (L"Option `%s' requires a value of either `yes' or `no'.\n", option); - return -1; - } - return 1; + if (_tcscmp (option, name) != 0) + return 0; + if (strcasecmp (value, L"yes") == 0 || strcasecmp (value, L"y") == 0 + || strcasecmp (value, L"true") == 0 || strcasecmp (value, L"t") == 0) + *location = 1; + else if (strcasecmp (value, L"no") == 0 || strcasecmp (value, L"n") == 0 + || strcasecmp (value, L"false") == 0 || strcasecmp (value, L"f") == 0) + *location = 0; + else { + write_log (L"Option `%s' requires a value of either `yes' or `no'.\n", option); + return -1; + } + return 1; } int cfgfile_intval (const TCHAR *option, const TCHAR *value, const TCHAR *name, int *location, int scale) { - int base = 10; - TCHAR *endptr; - if (_tcscmp (option, name) != 0) - return 0; - /* I guess octal isn't popular enough to worry about here... */ - if (value[0] == '0' && value[1] == 'x') - value += 2, base = 16; - *location = _tcstol (value, &endptr, base) * scale; - - if (*endptr != '\0' || *value == '\0') { - write_log (L"Option '%s' requires a numeric argument but got '%s'\n", option, value); - return -1; - } - return 1; + int base = 10; + TCHAR *endptr; + if (_tcscmp (option, name) != 0) + return 0; + /* I guess octal isn't popular enough to worry about here... */ + if (value[0] == '0' && value[1] == 'x') + value += 2, base = 16; + *location = _tcstol (value, &endptr, base) * scale; + + if (*endptr != '\0' || *value == '\0') { + write_log (L"Option '%s' requires a numeric argument but got '%s'\n", option, value); + return -1; + } + return 1; } int cfgfile_strval (const TCHAR *option, const TCHAR *value, const TCHAR *name, int *location, const TCHAR *table[], int more) { - int val; - if (_tcscmp (option, name) != 0) - return 0; - val = match_string (table, value); - if (val == -1) { - if (more) - return 0; + int val; + if (_tcscmp (option, name) != 0) + return 0; + val = match_string (table, value); + if (val == -1) { + if (more) + return 0; - write_log (L"Unknown value ('%s') for option '%s'.\n", value, option); - return -1; - } - *location = val; - return 1; + write_log (L"Unknown value ('%s') for option '%s'.\n", value, option); + return -1; + } + *location = val; + return 1; } int cfgfile_string (const TCHAR *option, const TCHAR *value, const TCHAR *name, TCHAR *location, int maxsz) { - if (_tcscmp (option, name) != 0) - return 0; - _tcsncpy (location, value, maxsz - 1); - location[maxsz - 1] = '\0'; - return 1; + if (_tcscmp (option, name) != 0) + return 0; + _tcsncpy (location, value, maxsz - 1); + location[maxsz - 1] = '\0'; + return 1; } static int getintval (TCHAR **p, int *result, int delim) { - TCHAR *value = *p; - int base = 10; - TCHAR *endptr; - TCHAR *p2 = _tcschr (*p, delim); + TCHAR *value = *p; + int base = 10; + TCHAR *endptr; + TCHAR *p2 = _tcschr (*p, delim); - if (p2 == 0) - return 0; + if (p2 == 0) + return 0; - *p2++ = '\0'; + *p2++ = '\0'; - if (value[0] == '0' && _totupper (value[1]) == 'X') - value += 2, base = 16; - *result = _tcstol (value, &endptr, base); - *p = p2; + if (value[0] == '0' && _totupper (value[1]) == 'X') + value += 2, base = 16; + *result = _tcstol (value, &endptr, base); + *p = p2; - if (*endptr != '\0' || *value == '\0') - return 0; + if (*endptr != '\0' || *value == '\0') + return 0; - return 1; + return 1; } static int getintval2 (TCHAR **p, int *result, int delim) { - TCHAR *value = *p; - int base = 10; - TCHAR *endptr; - TCHAR *p2 = _tcschr (*p, delim); + TCHAR *value = *p; + int base = 10; + TCHAR *endptr; + TCHAR *p2 = _tcschr (*p, delim); - if (p2 == 0) { - p2 = _tcschr (*p, 0); if (p2 == 0) { - *p = 0; - return 0; + p2 = _tcschr (*p, 0); + if (p2 == 0) { + *p = 0; + return 0; + } } - } - if (*p2 != 0) - *p2++ = '\0'; + if (*p2 != 0) + *p2++ = '\0'; - if (value[0] == '0' && _totupper (value[1]) == 'X') - value += 2, base = 16; - *result = _tcstol (value, &endptr, base); - *p = p2; + if (value[0] == '0' && _totupper (value[1]) == 'X') + value += 2, base = 16; + *result = _tcstol (value, &endptr, base); + *p = p2; - if (*endptr != '\0' || *value == '\0') { - *p = 0; - return 0; - } + if (*endptr != '\0' || *value == '\0') { + *p = 0; + return 0; + } - return 1; + return 1; } static void set_chipset_mask (struct uae_prefs *p, int val) { - p->chipset_mask = (val == 0 ? 0 - : val == 1 ? CSMASK_ECS_AGNUS - : val == 2 ? CSMASK_ECS_DENISE - : val == 3 ? CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS - : CSMASK_AGA | CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS); + p->chipset_mask = (val == 0 ? 0 + : val == 1 ? CSMASK_ECS_AGNUS + : val == 2 ? CSMASK_ECS_DENISE + : val == 3 ? CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS + : CSMASK_AGA | CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS); } static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) { - int i, v; - TCHAR *section = 0; - TCHAR *tmpp; - TCHAR tmpbuf[CONFIG_BLEN]; + int i, v; + TCHAR *section = 0; + TCHAR *tmpp; + TCHAR tmpbuf[CONFIG_BLEN]; - if (_tcsncmp (option, L"input.", 6) == 0) { - read_inputdevice_config (p, option, value); - return 1; - } - - for (tmpp = option; *tmpp != '\0'; tmpp++) - if (_istupper (*tmpp)) - *tmpp = _totlower (*tmpp); - tmpp = _tcschr (option, '.'); - if (tmpp) { - section = option; - option = tmpp + 1; - *tmpp = '\0'; - if (_tcscmp (section, TARGET_NAME) == 0) { - /* We special case the various path options here. */ - if (cfgfile_string (option, value, L"rom_path", p->path_rom, sizeof p->path_rom / sizeof (TCHAR)) - || cfgfile_string (option, value, L"floppy_path", p->path_floppy, sizeof p->path_floppy / sizeof (TCHAR)) - || cfgfile_string (option, value, L"hardfile_path", p->path_hardfile, sizeof p->path_hardfile / sizeof (TCHAR))) - return 1; - return target_parse_option (p, option, value); + if (_tcsncmp (option, L"input.", 6) == 0) { + read_inputdevice_config (p, option, value); + return 1; } - return 0; - } - for (i = 0; i < MAX_SPARE_DRIVES; i++) { - _stprintf (tmpbuf, L"diskimage%d", i); - if (cfgfile_string (option, value, tmpbuf, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof (TCHAR))) { + + for (tmpp = option; *tmpp != '\0'; tmpp++) + if (_istupper (*tmpp)) + *tmpp = _totlower (*tmpp); + tmpp = _tcschr (option, '.'); + if (tmpp) { + section = option; + option = tmpp + 1; + *tmpp = '\0'; + if (_tcscmp (section, TARGET_NAME) == 0) { + /* We special case the various path options here. */ + if (cfgfile_string (option, value, L"rom_path", p->path_rom, sizeof p->path_rom / sizeof (TCHAR)) + || cfgfile_string (option, value, L"floppy_path", p->path_floppy, sizeof p->path_floppy / sizeof (TCHAR)) + || cfgfile_string (option, value, L"hardfile_path", p->path_hardfile, sizeof p->path_hardfile / sizeof (TCHAR))) + return 1; + return target_parse_option (p, option, value); + } + return 0; + } + for (i = 0; i < MAX_SPARE_DRIVES; i++) { + _stprintf (tmpbuf, L"diskimage%d", i); + if (cfgfile_string (option, value, tmpbuf, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof (TCHAR))) { #if 0 - if (i < 4 && !p->df[i][0]) - _tcscpy (p->df[i], p->dfxlist[i]); + if (i < 4 && !p->df[i][0]) + _tcscpy (p->df[i], p->dfxlist[i]); #endif - return 1; + return 1; + } } - } - if (cfgfile_intval (option, value, L"sound_frequency", &p->sound_freq, 1)) { - /* backwards compatibility */ - p->sound_latency = 1000 * (p->sound_maxbsiz >> 1) / p->sound_freq; - return 1; - } - - if (cfgfile_intval (option, value, L"sound_latency", &p->sound_latency, 1) - || cfgfile_intval (option, value, L"sound_max_buff", &p->sound_maxbsiz, 1) - || cfgfile_intval (option, value, L"state_replay_rate", &p->statecapturerate, 1) - || cfgfile_intval (option, value, L"state_replay_buffer", &p->statecapturebuffersize, 1) - || cfgfile_intval (option, value, L"sound_frequency", &p->sound_freq, 1) - || cfgfile_intval (option, value, L"sound_volume", &p->sound_volume, 1) - || cfgfile_intval (option, value, L"sound_stereo_separation", &p->sound_stereo_separation, 1) - || cfgfile_intval (option, value, L"sound_stereo_mixing_delay", &p->sound_mixed_stereo_delay, 1) - - || cfgfile_intval (option, value, L"gfx_display", &p->gfx_display, 1) - || cfgfile_intval (option, value, L"gfx_framerate", &p->gfx_framerate, 1) - || cfgfile_intval (option, value, L"gfx_width_windowed", &p->gfx_size_win.width, 1) - || cfgfile_intval (option, value, L"gfx_height_windowed", &p->gfx_size_win.height, 1) - || cfgfile_intval (option, value, L"gfx_top_windowed", &p->gfx_size_win.x, 1) - || cfgfile_intval (option, value, L"gfx_left_windowed", &p->gfx_size_win.y, 1) - || cfgfile_intval (option, value, L"gfx_width_fullscreen", &p->gfx_size_fs.width, 1) - || cfgfile_intval (option, value, L"gfx_height_fullscreen", &p->gfx_size_fs.height, 1) - || cfgfile_intval (option, value, L"gfx_refreshrate", &p->gfx_refreshrate, 1) - || cfgfile_intval (option, value, L"gfx_autoresolution", &p->gfx_autoresolution, 1) - || cfgfile_intval (option, value, L"gfx_backbuffers", &p->gfx_backbuffers, 1) - - || cfgfile_intval (option, value, L"gfx_center_horizontal_position", &p->gfx_xcenter_pos, 1) - || cfgfile_intval (option, value, L"gfx_center_vertical_position", &p->gfx_ycenter_pos, 1) - || cfgfile_intval (option, value, L"gfx_center_horizontal_size", &p->gfx_xcenter_size, 1) - || cfgfile_intval (option, value, L"gfx_center_vertical_size", &p->gfx_ycenter_size, 1) + if (cfgfile_intval (option, value, L"sound_frequency", &p->sound_freq, 1)) { + /* backwards compatibility */ + p->sound_latency = 1000 * (p->sound_maxbsiz >> 1) / p->sound_freq; + return 1; + } + + if (cfgfile_intval (option, value, L"sound_latency", &p->sound_latency, 1) + || cfgfile_intval (option, value, L"sound_max_buff", &p->sound_maxbsiz, 1) + || cfgfile_intval (option, value, L"state_replay_rate", &p->statecapturerate, 1) + || cfgfile_intval (option, value, L"state_replay_buffer", &p->statecapturebuffersize, 1) + || cfgfile_intval (option, value, L"sound_frequency", &p->sound_freq, 1) + || cfgfile_intval (option, value, L"sound_volume", &p->sound_volume, 1) + || cfgfile_intval (option, value, L"sound_stereo_separation", &p->sound_stereo_separation, 1) + || cfgfile_intval (option, value, L"sound_stereo_mixing_delay", &p->sound_mixed_stereo_delay, 1) + + || cfgfile_intval (option, value, L"gfx_display", &p->gfx_display, 1) + || cfgfile_intval (option, value, L"gfx_framerate", &p->gfx_framerate, 1) + || cfgfile_intval (option, value, L"gfx_width_windowed", &p->gfx_size_win.width, 1) + || cfgfile_intval (option, value, L"gfx_height_windowed", &p->gfx_size_win.height, 1) + || cfgfile_intval (option, value, L"gfx_top_windowed", &p->gfx_size_win.x, 1) + || cfgfile_intval (option, value, L"gfx_left_windowed", &p->gfx_size_win.y, 1) + || cfgfile_intval (option, value, L"gfx_width_fullscreen", &p->gfx_size_fs.width, 1) + || cfgfile_intval (option, value, L"gfx_height_fullscreen", &p->gfx_size_fs.height, 1) + || cfgfile_intval (option, value, L"gfx_refreshrate", &p->gfx_refreshrate, 1) + || cfgfile_intval (option, value, L"gfx_autoresolution", &p->gfx_autoresolution, 1) + || cfgfile_intval (option, value, L"gfx_backbuffers", &p->gfx_backbuffers, 1) + + || cfgfile_intval (option, value, L"gfx_center_horizontal_position", &p->gfx_xcenter_pos, 1) + || cfgfile_intval (option, value, L"gfx_center_vertical_position", &p->gfx_ycenter_pos, 1) + || cfgfile_intval (option, value, L"gfx_center_horizontal_size", &p->gfx_xcenter_size, 1) + || cfgfile_intval (option, value, L"gfx_center_vertical_size", &p->gfx_ycenter_size, 1) #ifdef GFXFILTER - || cfgfile_intval (option, value, L"gfx_filter_vert_zoom", &p->gfx_filter_vert_zoom, 1) - || cfgfile_intval (option, value, L"gfx_filter_horiz_zoom", &p->gfx_filter_horiz_zoom, 1) - || cfgfile_intval (option, value, L"gfx_filter_vert_zoom_mult", &p->gfx_filter_vert_zoom_mult, 1) - || cfgfile_intval (option, value, L"gfx_filter_horiz_zoom_mult", &p->gfx_filter_horiz_zoom_mult, 1) - || cfgfile_intval (option, value, L"gfx_filter_vert_offset", &p->gfx_filter_vert_offset, 1) - || cfgfile_intval (option, value, L"gfx_filter_horiz_offset", &p->gfx_filter_horiz_offset, 1) - || cfgfile_intval (option, value, L"gfx_filter_scanlines", &p->gfx_filter_scanlines, 1) - || cfgfile_intval (option, value, L"gfx_filter_scanlinelevel", &p->gfx_filter_scanlinelevel, 1) - || cfgfile_intval (option, value, L"gfx_filter_scanlineratio", &p->gfx_filter_scanlineratio, 1) - || cfgfile_intval (option, value, L"gfx_filter_luminance", &p->gfx_filter_luminance, 1) - || cfgfile_intval (option, value, L"gfx_filter_contrast", &p->gfx_filter_contrast, 1) - || cfgfile_intval (option, value, L"gfx_filter_saturation", &p->gfx_filter_saturation, 1) - || cfgfile_intval (option, value, L"gfx_filter_gamma", &p->gfx_filter_gamma, 1) - || cfgfile_intval (option, value, L"gfx_filter_blur", &p->gfx_filter_blur, 1) - || cfgfile_intval (option, value, L"gfx_filter_noise", &p->gfx_filter_noise, 1) - || cfgfile_intval (option, value, L"gfx_luminance", &p->gfx_luminance, 1) - || cfgfile_intval (option, value, L"gfx_contrast", &p->gfx_contrast, 1) - || cfgfile_intval (option, value, L"gfx_gamma", &p->gfx_gamma, 1) + || cfgfile_intval (option, value, L"gfx_filter_vert_zoom", &p->gfx_filter_vert_zoom, 1) + || cfgfile_intval (option, value, L"gfx_filter_horiz_zoom", &p->gfx_filter_horiz_zoom, 1) + || cfgfile_intval (option, value, L"gfx_filter_vert_zoom_mult", &p->gfx_filter_vert_zoom_mult, 1) + || cfgfile_intval (option, value, L"gfx_filter_horiz_zoom_mult", &p->gfx_filter_horiz_zoom_mult, 1) + || cfgfile_intval (option, value, L"gfx_filter_vert_offset", &p->gfx_filter_vert_offset, 1) + || cfgfile_intval (option, value, L"gfx_filter_horiz_offset", &p->gfx_filter_horiz_offset, 1) + || cfgfile_intval (option, value, L"gfx_filter_scanlines", &p->gfx_filter_scanlines, 1) + || cfgfile_intval (option, value, L"gfx_filter_scanlinelevel", &p->gfx_filter_scanlinelevel, 1) + || cfgfile_intval (option, value, L"gfx_filter_scanlineratio", &p->gfx_filter_scanlineratio, 1) + || cfgfile_intval (option, value, L"gfx_filter_luminance", &p->gfx_filter_luminance, 1) + || cfgfile_intval (option, value, L"gfx_filter_contrast", &p->gfx_filter_contrast, 1) + || cfgfile_intval (option, value, L"gfx_filter_saturation", &p->gfx_filter_saturation, 1) + || cfgfile_intval (option, value, L"gfx_filter_gamma", &p->gfx_filter_gamma, 1) + || cfgfile_intval (option, value, L"gfx_filter_blur", &p->gfx_filter_blur, 1) + || cfgfile_intval (option, value, L"gfx_filter_noise", &p->gfx_filter_noise, 1) + || cfgfile_intval (option, value, L"gfx_luminance", &p->gfx_luminance, 1) + || cfgfile_intval (option, value, L"gfx_contrast", &p->gfx_contrast, 1) + || cfgfile_intval (option, value, L"gfx_gamma", &p->gfx_gamma, 1) #endif - || cfgfile_intval (option, value, L"floppy0sound", &p->dfxclick[0], 1) - || cfgfile_intval (option, value, L"floppy1sound", &p->dfxclick[1], 1) - || cfgfile_intval (option, value, L"floppy2sound", &p->dfxclick[2], 1) - || cfgfile_intval (option, value, L"floppy3sound", &p->dfxclick[3], 1) - || cfgfile_intval (option, value, L"floppy_volume", &p->dfxclickvolume, 1) - || cfgfile_intval (option, value, L"override_dga_address", &p->override_dga_address, 1)) - return 1; - - if (cfgfile_string (option, value, L"floppy0soundext", p->dfxclickexternal[0], sizeof p->dfxclickexternal[0] / sizeof (TCHAR)) - || cfgfile_string (option, value, L"floppy1soundext", p->dfxclickexternal[1], sizeof p->dfxclickexternal[1] / sizeof (TCHAR)) - || cfgfile_string (option, value, L"floppy2soundext", p->dfxclickexternal[2], sizeof p->dfxclickexternal[2] / sizeof (TCHAR)) - || cfgfile_string (option, value, L"floppy3soundext", p->dfxclickexternal[3], sizeof p->dfxclickexternal[3] / sizeof (TCHAR)) - || cfgfile_string (option, value, L"gfx_display_name", p->gfx_display_name, sizeof p->gfx_display_name / sizeof (TCHAR)) - || cfgfile_string (option, value, L"config_info", p->info, sizeof p->info / sizeof (TCHAR)) - || cfgfile_string (option, value, L"config_description", p->description, sizeof p->description / sizeof (TCHAR))) - return 1; - - if (cfgfile_yesno (option, value, L"use_debugger", &p->start_debugger) - || cfgfile_yesno (option, value, L"sound_auto", &p->sound_auto) - || cfgfile_yesno (option, value, L"sound_stereo_swap_paula", &p->sound_stereo_swap_paula) - || cfgfile_yesno (option, value, L"sound_stereo_swap_ahi", &p->sound_stereo_swap_ahi) - || cfgfile_yesno (option, value, L"state_replay", &p->statecapture) - || cfgfile_yesno (option, value, L"avoid_cmov", &p->avoid_cmov) - || cfgfile_yesno (option, value, L"avoid_dga", &p->avoid_dga) - || cfgfile_yesno (option, value, L"avoid_vid", &p->avoid_vid) - || cfgfile_yesno (option, value, L"log_illegal_mem", &p->illegal_mem) - || cfgfile_yesno (option, value, L"filesys_no_fsdb", &p->filesys_no_uaefsdb) - || cfgfile_yesno (option, value, L"gfx_vsync_picasso", &p->gfx_pvsync) - || cfgfile_yesno (option, value, L"gfx_blacker_than_black", &p->gfx_blackerthanblack) - || cfgfile_yesno (option, value, L"gfx_flickerfixer", &p->gfx_scandoubler) - || cfgfile_yesno (option, value, L"synchronize_clock", &p->tod_hack) - || cfgfile_yesno (option, value, L"magic_mouse", &p->input_magic_mouse) - || cfgfile_yesno (option, value, L"warp", &p->turbo_emulation) - || cfgfile_yesno (option, value, L"headless", &p->headless) - || cfgfile_yesno (option, value, L"bsdsocket_emu", &p->socket_emu)) - return 1; - - if (cfgfile_strval (option, value, L"sound_output", &p->produce_sound, soundmode1, 1) - || cfgfile_strval (option, value, L"sound_output", &p->produce_sound, soundmode2, 0) - || cfgfile_strval (option, value, L"sound_interpol", &p->sound_interpol, interpolmode, 0) - || cfgfile_strval (option, value, L"sound_filter", &p->sound_filter, soundfiltermode1, 0) - || cfgfile_strval (option, value, L"sound_filter_type", &p->sound_filter_type, soundfiltermode2, 0) - || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode1, 1) - || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode2, 1) - || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode3, 0) - || cfgfile_strval (option, value, L"gfx_resolution", &p->gfx_resolution, lorestype1, 0) - || cfgfile_strval (option, value, L"gfx_lores", &p->gfx_resolution, lorestype2, 0) - || cfgfile_strval (option, value, L"gfx_lores_mode", &p->gfx_lores_mode, loresmode, 0) - || cfgfile_strval (option, value, L"gfx_fullscreen_amiga", &p->gfx_afullscreen, fullmodes, 0) - || cfgfile_strval (option, value, L"gfx_fullscreen_picasso", &p->gfx_pfullscreen, fullmodes, 0) - || cfgfile_strval (option, value, L"gfx_linemode", &p->gfx_linedbl, linemode1, 1) - || cfgfile_strval (option, value, L"gfx_linemode", &p->gfx_linedbl, linemode2, 0) - || cfgfile_strval (option, value, L"gfx_center_horizontal", &p->gfx_xcenter, centermode1, 1) - || cfgfile_strval (option, value, L"gfx_center_vertical", &p->gfx_ycenter, centermode1, 1) - || cfgfile_strval (option, value, L"gfx_center_horizontal", &p->gfx_xcenter, centermode2, 0) - || cfgfile_strval (option, value, L"gfx_center_vertical", &p->gfx_ycenter, centermode2, 0) - || cfgfile_strval (option, value, L"gfx_colour_mode", &p->color_mode, colormode1, 1) - || cfgfile_strval (option, value, L"gfx_colour_mode", &p->color_mode, colormode2, 0) - || cfgfile_strval (option, value, L"gfx_color_mode", &p->color_mode, colormode1, 1) - || cfgfile_strval (option, value, L"gfx_color_mode", &p->color_mode, colormode2, 0) - || cfgfile_strval (option, value, L"gfx_max_horizontal", &p->gfx_max_horizontal, maxhoriz, 0) - || cfgfile_strval (option, value, L"gfx_max_vertical", &p->gfx_max_vertical, maxvert, 0) - || cfgfile_strval (option, value, L"gfx_filter_autoscale", &p->gfx_filter_autoscale, autoscale, 0) - || cfgfile_strval (option, value, L"magic_mousecursor", &p->input_magic_mouse_cursor, magiccursors, 0) - || cfgfile_strval (option, value, L"gfx_filter_keep_aspect", &p->gfx_filter_keep_aspect, aspects, 0) - || cfgfile_strval (option, value, L"absolute_mouse", &p->input_tablet, abspointers, 0)) - return 1; - - - if (_tcscmp (option, L"gfx_vsync") == 0) { - if (cfgfile_strval (option, value, L"gfx_vsync", &p->gfx_avsync, vsyncmodes, 0) >= 0) - return 1; - return cfgfile_yesno (option, value, L"gfx_vsync", &p->gfx_avsync); - } - - if (cfgfile_yesno (option, value, L"show_leds", &v)) { - if (v) - p->leds_on_screen |= STATUSLINE_CHIPSET; - return 1; - } - if (cfgfile_yesno (option, value, L"show_leds_rtg", &v)) { - if (v) - p->leds_on_screen |= STATUSLINE_RTG; - return 1; - } + || cfgfile_intval (option, value, L"floppy0sound", &p->dfxclick[0], 1) + || cfgfile_intval (option, value, L"floppy1sound", &p->dfxclick[1], 1) + || cfgfile_intval (option, value, L"floppy2sound", &p->dfxclick[2], 1) + || cfgfile_intval (option, value, L"floppy3sound", &p->dfxclick[3], 1) + || cfgfile_intval (option, value, L"floppy_volume", &p->dfxclickvolume, 1) + || cfgfile_intval (option, value, L"override_dga_address", &p->override_dga_address, 1)) + return 1; + + if (cfgfile_string (option, value, L"floppy0soundext", p->dfxclickexternal[0], sizeof p->dfxclickexternal[0] / sizeof (TCHAR)) + || cfgfile_string (option, value, L"floppy1soundext", p->dfxclickexternal[1], sizeof p->dfxclickexternal[1] / sizeof (TCHAR)) + || cfgfile_string (option, value, L"floppy2soundext", p->dfxclickexternal[2], sizeof p->dfxclickexternal[2] / sizeof (TCHAR)) + || cfgfile_string (option, value, L"floppy3soundext", p->dfxclickexternal[3], sizeof p->dfxclickexternal[3] / sizeof (TCHAR)) + || cfgfile_string (option, value, L"gfx_display_name", p->gfx_display_name, sizeof p->gfx_display_name / sizeof (TCHAR)) + || cfgfile_string (option, value, L"config_info", p->info, sizeof p->info / sizeof (TCHAR)) + || cfgfile_string (option, value, L"config_description", p->description, sizeof p->description / sizeof (TCHAR))) + return 1; + + if (cfgfile_yesno (option, value, L"use_debugger", &p->start_debugger) + || cfgfile_yesno (option, value, L"sound_auto", &p->sound_auto) + || cfgfile_yesno (option, value, L"sound_stereo_swap_paula", &p->sound_stereo_swap_paula) + || cfgfile_yesno (option, value, L"sound_stereo_swap_ahi", &p->sound_stereo_swap_ahi) + || cfgfile_yesno (option, value, L"state_replay", &p->statecapture) + || cfgfile_yesno (option, value, L"avoid_cmov", &p->avoid_cmov) + || cfgfile_yesno (option, value, L"avoid_dga", &p->avoid_dga) + || cfgfile_yesno (option, value, L"avoid_vid", &p->avoid_vid) + || cfgfile_yesno (option, value, L"log_illegal_mem", &p->illegal_mem) + || cfgfile_yesno (option, value, L"filesys_no_fsdb", &p->filesys_no_uaefsdb) + || cfgfile_yesno (option, value, L"gfx_vsync_picasso", &p->gfx_pvsync) + || cfgfile_yesno (option, value, L"gfx_blacker_than_black", &p->gfx_blackerthanblack) + || cfgfile_yesno (option, value, L"gfx_flickerfixer", &p->gfx_scandoubler) + || cfgfile_yesno (option, value, L"synchronize_clock", &p->tod_hack) + || cfgfile_yesno (option, value, L"magic_mouse", &p->input_magic_mouse) + || cfgfile_yesno (option, value, L"warp", &p->turbo_emulation) + || cfgfile_yesno (option, value, L"headless", &p->headless) + || cfgfile_yesno (option, value, L"bsdsocket_emu", &p->socket_emu)) + return 1; + + if (cfgfile_strval (option, value, L"sound_output", &p->produce_sound, soundmode1, 1) + || cfgfile_strval (option, value, L"sound_output", &p->produce_sound, soundmode2, 0) + || cfgfile_strval (option, value, L"sound_interpol", &p->sound_interpol, interpolmode, 0) + || cfgfile_strval (option, value, L"sound_filter", &p->sound_filter, soundfiltermode1, 0) + || cfgfile_strval (option, value, L"sound_filter_type", &p->sound_filter_type, soundfiltermode2, 0) + || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode1, 1) + || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode2, 1) + || cfgfile_strval (option, value, L"use_gui", &p->start_gui, guimode3, 0) + || cfgfile_strval (option, value, L"gfx_resolution", &p->gfx_resolution, lorestype1, 0) + || cfgfile_strval (option, value, L"gfx_lores", &p->gfx_resolution, lorestype2, 0) + || cfgfile_strval (option, value, L"gfx_lores_mode", &p->gfx_lores_mode, loresmode, 0) + || cfgfile_strval (option, value, L"gfx_fullscreen_amiga", &p->gfx_afullscreen, fullmodes, 0) + || cfgfile_strval (option, value, L"gfx_fullscreen_picasso", &p->gfx_pfullscreen, fullmodes, 0) + || cfgfile_strval (option, value, L"gfx_linemode", &p->gfx_linedbl, linemode1, 1) + || cfgfile_strval (option, value, L"gfx_linemode", &p->gfx_linedbl, linemode2, 0) + || cfgfile_strval (option, value, L"gfx_center_horizontal", &p->gfx_xcenter, centermode1, 1) + || cfgfile_strval (option, value, L"gfx_center_vertical", &p->gfx_ycenter, centermode1, 1) + || cfgfile_strval (option, value, L"gfx_center_horizontal", &p->gfx_xcenter, centermode2, 0) + || cfgfile_strval (option, value, L"gfx_center_vertical", &p->gfx_ycenter, centermode2, 0) + || cfgfile_strval (option, value, L"gfx_colour_mode", &p->color_mode, colormode1, 1) + || cfgfile_strval (option, value, L"gfx_colour_mode", &p->color_mode, colormode2, 0) + || cfgfile_strval (option, value, L"gfx_color_mode", &p->color_mode, colormode1, 1) + || cfgfile_strval (option, value, L"gfx_color_mode", &p->color_mode, colormode2, 0) + || cfgfile_strval (option, value, L"gfx_max_horizontal", &p->gfx_max_horizontal, maxhoriz, 0) + || cfgfile_strval (option, value, L"gfx_max_vertical", &p->gfx_max_vertical, maxvert, 0) + || cfgfile_strval (option, value, L"gfx_filter_autoscale", &p->gfx_filter_autoscale, autoscale, 0) + || cfgfile_strval (option, value, L"magic_mousecursor", &p->input_magic_mouse_cursor, magiccursors, 0) + || cfgfile_strval (option, value, L"gfx_filter_keep_aspect", &p->gfx_filter_keep_aspect, aspects, 0) + || cfgfile_strval (option, value, L"absolute_mouse", &p->input_tablet, abspointers, 0)) + return 1; + + + if (_tcscmp (option, L"gfx_vsync") == 0) { + if (cfgfile_strval (option, value, L"gfx_vsync", &p->gfx_avsync, vsyncmodes, 0) >= 0) + return 1; + return cfgfile_yesno (option, value, L"gfx_vsync", &p->gfx_avsync); + } + + if (cfgfile_yesno (option, value, L"show_leds", &v)) { + if (v) + p->leds_on_screen |= STATUSLINE_CHIPSET; + return 1; + } + if (cfgfile_yesno (option, value, L"show_leds_rtg", &v)) { + if (v) + p->leds_on_screen |= STATUSLINE_RTG; + return 1; + } #ifdef GFXFILTER - if (_tcscmp (option, L"gfx_filter") == 0) { - int i = 0; - TCHAR *s = _tcschr (value, ':'); - if (s) - *s++ = 0; - p->gfx_filtershader[0] = 0; - p->gfx_filter = 0; - while(uaefilters[i].name) { - if (!_tcscmp (uaefilters[i].cfgname, value)) { - p->gfx_filter = uaefilters[i].type; + if (_tcscmp (option, L"gfx_filter") == 0) { + int i = 0; + TCHAR *s = _tcschr (value, ':'); if (s) - _tcscpy (p->gfx_filtershader, s); - break; - } - i++; + *s++ = 0; + p->gfx_filtershader[0] = 0; + p->gfx_filter = 0; + while(uaefilters[i].name) { + if (!_tcscmp (uaefilters[i].cfgname, value)) { + p->gfx_filter = uaefilters[i].type; + if (s) + _tcscpy (p->gfx_filtershader, s); + break; + } + i++; + } + return 1; } - return 1; - } - if (_tcscmp (option, L"gfx_filter_mode") == 0) { - p->gfx_filter_filtermode = 0; - if (p->gfx_filter > 0) { - struct uae_filter *uf; - int i = 0; - while(uaefilters[i].name) { - uf = &uaefilters[i]; - if (uf->type == p->gfx_filter) { - if (uf->x[0]) { - cfgfile_strval (option, value, L"gfx_filter_mode", &p->gfx_filter_filtermode, filtermode1, 0); - } else { - int mt[4], j; - i = 0; - if (uf->x[1]) - mt[i++] = 1; - if (uf->x[2]) - mt[i++] = 2; - if (uf->x[3]) - mt[i++] = 3; - if (uf->x[4]) - mt[i++] = 4; - cfgfile_strval (option, value, L"gfx_filter_mode", &i, filtermode2, 0); - for (j = 0; j < i; j++) { - if (mt[j] == i) - p->gfx_filter_filtermode = j; + if (_tcscmp (option, L"gfx_filter_mode") == 0) { + p->gfx_filter_filtermode = 0; + if (p->gfx_filter > 0) { + struct uae_filter *uf; + int i = 0; + while(uaefilters[i].name) { + uf = &uaefilters[i]; + if (uf->type == p->gfx_filter) { + if (uf->x[0]) { + cfgfile_strval (option, value, L"gfx_filter_mode", &p->gfx_filter_filtermode, filtermode1, 0); + } else { + int mt[4], j; + i = 0; + if (uf->x[1]) + mt[i++] = 1; + if (uf->x[2]) + mt[i++] = 2; + if (uf->x[3]) + mt[i++] = 3; + if (uf->x[4]) + mt[i++] = 4; + cfgfile_strval (option, value, L"gfx_filter_mode", &i, filtermode2, 0); + for (j = 0; j < i; j++) { + if (mt[j] == i) + p->gfx_filter_filtermode = j; + } + } + break; + } + i++; } - } - break; } - i++; - } + return 1; } - return 1; - } - if (cfgfile_string (option, value, L"gfx_filter_aspect_ratio", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - int v1, v2; - TCHAR *s; - - p->gfx_filter_aspect = -1; - v1 = _tstol (tmpbuf); - s = _tcschr (tmpbuf, ':'); - if (s) { - v2 = _tstol (s + 1); - if (v1 < 0 || v2 < 0) + if (cfgfile_string (option, value, L"gfx_filter_aspect_ratio", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + int v1, v2; + TCHAR *s; + p->gfx_filter_aspect = -1; - else if (v1 == 0 || v2 == 0) - p->gfx_filter_aspect = 0; - else - p->gfx_filter_aspect = (v1 << 8) | v2; + v1 = _tstol (tmpbuf); + s = _tcschr (tmpbuf, ':'); + if (s) { + v2 = _tstol (s + 1); + if (v1 < 0 || v2 < 0) + p->gfx_filter_aspect = -1; + else if (v1 == 0 || v2 == 0) + p->gfx_filter_aspect = 0; + else + p->gfx_filter_aspect = (v1 << 8) | v2; + } + return 1; } - return 1; - } #endif - if (_tcscmp (option, L"gfx_width") == 0 || _tcscmp (option, L"gfx_height") == 0) { - cfgfile_intval (option, value, L"gfx_width", &p->gfx_size_win.width, 1); - cfgfile_intval (option, value, L"gfx_height", &p->gfx_size_win.height, 1); - p->gfx_size_fs.width = p->gfx_size_win.width; - p->gfx_size_fs.height = p->gfx_size_win.height; - return 1; - } - - if (_tcscmp (option, L"gfx_fullscreen_multi") == 0 || _tcscmp (option, L"gfx_windowed_multi") == 0) { - TCHAR tmp[256], *tmpp, *tmpp2; - struct wh *wh = p->gfx_size_win_xtra; - if (_tcscmp (option, L"gfx_fullscreen_multi") == 0) - wh = p->gfx_size_fs_xtra; - _stprintf (tmp, L",%s,", value); - tmpp2 = tmp; - for (i = 0; i < 4; i++) { - tmpp = _tcschr (tmpp2, ','); - tmpp++; - wh[i].width = _tstol (tmpp); - while (*tmpp != ',' && *tmpp != 'x') - tmpp++; - wh[i].height = _tstol (tmpp + 1); - tmpp2 = tmpp; + if (_tcscmp (option, L"gfx_width") == 0 || _tcscmp (option, L"gfx_height") == 0) { + cfgfile_intval (option, value, L"gfx_width", &p->gfx_size_win.width, 1); + cfgfile_intval (option, value, L"gfx_height", &p->gfx_size_win.height, 1); + p->gfx_size_fs.width = p->gfx_size_win.width; + p->gfx_size_fs.height = p->gfx_size_win.height; + return 1; } - return 1; - } - if (_tcscmp (option, L"joyportfriendlyname0") == 0 || _tcscmp (option, L"joyportfriendlyname1") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportfriendlyname0") == 0 ? 0 : 1, 0, 2); - return 1; - } - if (_tcscmp (option, L"joyportfriendlyname2") == 0 || _tcscmp (option, L"joyportfriendlyname3") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportfriendlyname2") == 0 ? 2 : 3, 0, 2); - return 1; - } - if (_tcscmp (option, L"joyportname0") == 0 || _tcscmp (option, L"joyportname1") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportname0") == 0 ? 0 : 1, 0, 1); - return 1; - } - if (_tcscmp (option, L"joyportname2") == 0 || _tcscmp (option, L"joyportname3") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportname2") == 0 ? 2 : 3, 0, 1); - return 1; - } - if (_tcscmp (option, L"joyport0") == 0 || _tcscmp (option, L"joyport1") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyport0") == 0 ? 0 : 1, 0, 0); - return 1; - } - if (_tcscmp (option, L"joyport2") == 0 || _tcscmp (option, L"joyport3") == 0) { - inputdevice_joyport_config (p, value, _tcscmp (option, L"joyport2") == 0 ? 2 : 3, 0, 0); - return 1; - } - if (cfgfile_strval (option, value, L"joyport0mode", &p->jports[0].mode, joyportmodes, 0)) - return 1; - if (cfgfile_strval (option, value, L"joyport1mode", &p->jports[1].mode, joyportmodes, 0)) - return 1; - if (cfgfile_strval (option, value, L"joyport2mode", &p->jports[2].mode, joyportmodes, 0)) - return 1; - if (cfgfile_strval (option, value, L"joyport3mode", &p->jports[3].mode, joyportmodes, 0)) - return 1; + if (_tcscmp (option, L"gfx_fullscreen_multi") == 0 || _tcscmp (option, L"gfx_windowed_multi") == 0) { + TCHAR tmp[256], *tmpp, *tmpp2; + struct wh *wh = p->gfx_size_win_xtra; + if (_tcscmp (option, L"gfx_fullscreen_multi") == 0) + wh = p->gfx_size_fs_xtra; + _stprintf (tmp, L",%s,", value); + tmpp2 = tmp; + for (i = 0; i < 4; i++) { + tmpp = _tcschr (tmpp2, ','); + tmpp++; + wh[i].width = _tstol (tmpp); + while (*tmpp != ',' && *tmpp != 'x') + tmpp++; + wh[i].height = _tstol (tmpp + 1); + tmpp2 = tmpp; + } + return 1; + } - if (cfgfile_string (option, value, L"statefile", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { - _tcscpy (savestate_fname, tmpbuf); - if (zfile_exists (savestate_fname)) { - savestate_state = STATE_DORESTORE; - } else { - int ok = 0; - if (savestate_fname[0]) { - for (;;) { - TCHAR *p; - if (my_existsdir (savestate_fname)) { - ok = 1; - break; - } - p = _tcsrchr (savestate_fname, '\\'); - if (!p) - p = _tcsrchr (savestate_fname, '/'); - if (!p) - break; - *p = 0; + if (_tcscmp (option, L"joyportfriendlyname0") == 0 || _tcscmp (option, L"joyportfriendlyname1") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportfriendlyname0") == 0 ? 0 : 1, 0, 2); + return 1; + } + if (_tcscmp (option, L"joyportfriendlyname2") == 0 || _tcscmp (option, L"joyportfriendlyname3") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportfriendlyname2") == 0 ? 2 : 3, 0, 2); + return 1; + } + if (_tcscmp (option, L"joyportname0") == 0 || _tcscmp (option, L"joyportname1") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportname0") == 0 ? 0 : 1, 0, 1); + return 1; + } + if (_tcscmp (option, L"joyportname2") == 0 || _tcscmp (option, L"joyportname3") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyportname2") == 0 ? 2 : 3, 0, 1); + return 1; + } + if (_tcscmp (option, L"joyport0") == 0 || _tcscmp (option, L"joyport1") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyport0") == 0 ? 0 : 1, 0, 0); + return 1; + } + if (_tcscmp (option, L"joyport2") == 0 || _tcscmp (option, L"joyport3") == 0) { + inputdevice_joyport_config (p, value, _tcscmp (option, L"joyport2") == 0 ? 2 : 3, 0, 0); + return 1; + } + if (cfgfile_strval (option, value, L"joyport0mode", &p->jports[0].mode, joyportmodes, 0)) + return 1; + if (cfgfile_strval (option, value, L"joyport1mode", &p->jports[1].mode, joyportmodes, 0)) + return 1; + if (cfgfile_strval (option, value, L"joyport2mode", &p->jports[2].mode, joyportmodes, 0)) + return 1; + if (cfgfile_strval (option, value, L"joyport3mode", &p->jports[3].mode, joyportmodes, 0)) + return 1; + + if (cfgfile_string (option, value, L"statefile", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { + _tcscpy (savestate_fname, tmpbuf); + if (zfile_exists (savestate_fname)) { + savestate_state = STATE_DORESTORE; + } else { + int ok = 0; + if (savestate_fname[0]) { + for (;;) { + TCHAR *p; + if (my_existsdir (savestate_fname)) { + ok = 1; + break; + } + p = _tcsrchr (savestate_fname, '\\'); + if (!p) + p = _tcsrchr (savestate_fname, '/'); + if (!p) + break; + *p = 0; + } + } + if (!ok) + savestate_fname[0] = 0; } - } - if (!ok) - savestate_fname[0] = 0; + return 1; } - return 1; - } - if (cfgfile_strval (option, value, L"sound_channels", &p->sound_stereo, stereomode, 1)) { - if (p->sound_stereo == SND_NONE) { /* "mixed stereo" compatibility hack */ - p->sound_stereo = SND_STEREO; - p->sound_mixed_stereo_delay = 5; - p->sound_stereo_separation = 7; + if (cfgfile_strval (option, value, L"sound_channels", &p->sound_stereo, stereomode, 1)) { + if (p->sound_stereo == SND_NONE) { /* "mixed stereo" compatibility hack */ + p->sound_stereo = SND_STEREO; + p->sound_mixed_stereo_delay = 5; + p->sound_stereo_separation = 7; + } + return 1; } - return 1; - } - - if (_tcscmp (option, L"kbd_lang") == 0) { - KbdLang l; - if ((l = KBD_LANG_DE, strcasecmp (value, L"de") == 0) - || (l = KBD_LANG_DK, strcasecmp (value, L"dk") == 0) - || (l = KBD_LANG_SE, strcasecmp (value, L"se") == 0) - || (l = KBD_LANG_US, strcasecmp (value, L"us") == 0) - || (l = KBD_LANG_FR, strcasecmp (value, L"fr") == 0) - || (l = KBD_LANG_IT, strcasecmp (value, L"it") == 0) - || (l = KBD_LANG_ES, strcasecmp (value, L"es") == 0)) - p->keyboard_lang = l; - else - write_log (L"Unknown keyboard language\n"); - return 1; - } - if (cfgfile_string (option, value, L"config_version", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { - TCHAR *tmpp2; - tmpp = _tcschr (value, '.'); - if (tmpp) { - *tmpp++ = 0; - tmpp2 = tmpp; - p->config_version = _tstol (tmpbuf) << 16; - tmpp = _tcschr (tmpp, '.'); - if (tmpp) { - *tmpp++ = 0; - p->config_version |= _tstol (tmpp2) << 8; - p->config_version |= _tstol (tmpp); - } + if (_tcscmp (option, L"kbd_lang") == 0) { + KbdLang l; + if ((l = KBD_LANG_DE, strcasecmp (value, L"de") == 0) + || (l = KBD_LANG_DK, strcasecmp (value, L"dk") == 0) + || (l = KBD_LANG_SE, strcasecmp (value, L"se") == 0) + || (l = KBD_LANG_US, strcasecmp (value, L"us") == 0) + || (l = KBD_LANG_FR, strcasecmp (value, L"fr") == 0) + || (l = KBD_LANG_IT, strcasecmp (value, L"it") == 0) + || (l = KBD_LANG_ES, strcasecmp (value, L"es") == 0)) + p->keyboard_lang = l; + else + write_log (L"Unknown keyboard language\n"); + return 1; } - return 1; - } - if (cfgfile_string (option, value, L"keyboard_leds", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { - TCHAR *tmpp2 = tmpbuf; - int i, num; - p->keyboard_leds[0] = p->keyboard_leds[1] = p->keyboard_leds[2] = 0; - p->keyboard_leds_in_use = 0; - _tcscat (tmpbuf, L","); - for (i = 0; i < 3; i++) { - tmpp = _tcschr (tmpp2, ':'); - if (!tmpp) - break; - *tmpp++= 0; - num = -1; - if (!strcasecmp (tmpp2, L"numlock")) - num = 0; - if (!strcasecmp (tmpp2, L"capslock")) - num = 1; - if (!strcasecmp (tmpp2, L"scrolllock")) - num = 2; - tmpp2 = tmpp; - tmpp = _tcschr (tmpp2, ','); - if (!tmpp) - break; - *tmpp++= 0; - if (num >= 0) { - p->keyboard_leds[num] = match_string (kbleds, tmpp2); - if (p->keyboard_leds[num]) - p->keyboard_leds_in_use = 1; - } - tmpp2 = tmpp; + if (cfgfile_string (option, value, L"config_version", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { + TCHAR *tmpp2; + tmpp = _tcschr (value, '.'); + if (tmpp) { + *tmpp++ = 0; + tmpp2 = tmpp; + p->config_version = _tstol (tmpbuf) << 16; + tmpp = _tcschr (tmpp, '.'); + if (tmpp) { + *tmpp++ = 0; + p->config_version |= _tstol (tmpp2) << 8; + p->config_version |= _tstol (tmpp); + } + } + return 1; + } + + if (cfgfile_string (option, value, L"keyboard_leds", tmpbuf, sizeof (tmpbuf) / sizeof (TCHAR))) { + TCHAR *tmpp2 = tmpbuf; + int i, num; + p->keyboard_leds[0] = p->keyboard_leds[1] = p->keyboard_leds[2] = 0; + p->keyboard_leds_in_use = 0; + _tcscat (tmpbuf, L","); + for (i = 0; i < 3; i++) { + tmpp = _tcschr (tmpp2, ':'); + if (!tmpp) + break; + *tmpp++= 0; + num = -1; + if (!strcasecmp (tmpp2, L"numlock")) + num = 0; + if (!strcasecmp (tmpp2, L"capslock")) + num = 1; + if (!strcasecmp (tmpp2, L"scrolllock")) + num = 2; + tmpp2 = tmpp; + tmpp = _tcschr (tmpp2, ','); + if (!tmpp) + break; + *tmpp++= 0; + if (num >= 0) { + p->keyboard_leds[num] = match_string (kbleds, tmpp2); + if (p->keyboard_leds[num]) + p->keyboard_leds_in_use = 1; + } + tmpp2 = tmpp; + } + return 1; } - return 1; - } - return 0; + return 0; } static void decode_rom_ident (TCHAR *romfile, int maxlen, TCHAR *ident) { - TCHAR *p; - int ver, rev, subver, subrev, round, i; - TCHAR model[64], *modelp; - struct romlist **rl; - TCHAR *romtxt; - - if (!ident[0]) - return; - romtxt = malloc (10000 * sizeof (TCHAR)); - romtxt[0] = 0; - for (round = 0; round < 2; round++) { - ver = rev = subver = subrev = -1; - modelp = NULL; - memset (model, 0, sizeof model); - p = ident; - while (*p) { - TCHAR c = *p++; - int *pp1 = NULL, *pp2 = NULL; - if (_totupper(c) == 'V' && _istdigit(*p)) { - pp1 = &ver; - pp2 = &rev; - } else if (_totupper(c) == 'R' && _istdigit(*p)) { - pp1 = &subver; - pp2 = &subrev; - } else if (!_istdigit(c) && c != ' ') { - _tcsncpy (model, p - 1, (sizeof model) - 1); - p += _tcslen (model); - modelp = model; - } - if (pp1) { - *pp1 = _tstol(p); - while (*p != 0 && *p != '.' && *p != ' ') - p++; - if (*p == '.') { - p++; - if (pp2) - *pp2 = _tstol(p); - } - } - if (*p == 0 || *p == ';') { - rl = getromlistbyident (ver, rev, subver, subrev, modelp, round); - if (rl) { - for (i = 0; rl[i]; i++) { - if (round) { - TCHAR romname[MAX_DPATH]; - getromname(rl[i]->rd, romname); - _tcscat (romtxt, romname); - _tcscat (romtxt, L"\n"); - } else { - _tcsncpy (romfile, rl[i]->path, maxlen); - goto end; + TCHAR *p; + int ver, rev, subver, subrev, round, i; + TCHAR model[64], *modelp; + struct romlist **rl; + TCHAR *romtxt; + + if (!ident[0]) + return; + romtxt = malloc (10000 * sizeof (TCHAR)); + romtxt[0] = 0; + for (round = 0; round < 2; round++) { + ver = rev = subver = subrev = -1; + modelp = NULL; + memset (model, 0, sizeof model); + p = ident; + while (*p) { + TCHAR c = *p++; + int *pp1 = NULL, *pp2 = NULL; + if (_totupper(c) == 'V' && _istdigit(*p)) { + pp1 = &ver; + pp2 = &rev; + } else if (_totupper(c) == 'R' && _istdigit(*p)) { + pp1 = &subver; + pp2 = &subrev; + } else if (!_istdigit(c) && c != ' ') { + _tcsncpy (model, p - 1, (sizeof model) - 1); + p += _tcslen (model); + modelp = model; + } + if (pp1) { + *pp1 = _tstol(p); + while (*p != 0 && *p != '.' && *p != ' ') + p++; + if (*p == '.') { + p++; + if (pp2) + *pp2 = _tstol(p); + } + } + if (*p == 0 || *p == ';') { + rl = getromlistbyident (ver, rev, subver, subrev, modelp, round); + if (rl) { + for (i = 0; rl[i]; i++) { + if (round) { + TCHAR romname[MAX_DPATH]; + getromname(rl[i]->rd, romname); + _tcscat (romtxt, romname); + _tcscat (romtxt, L"\n"); + } else { + _tcsncpy (romfile, rl[i]->path, maxlen); + goto end; + } + } + xfree (rl); + } } - } - xfree (rl); } - } } - } end: - if (round && romtxt[0]) { - notify_user_parms (NUMSG_ROMNEED, romtxt, romtxt); - } - xfree (romtxt); + if (round && romtxt[0]) { + notify_user_parms (NUMSG_ROMNEED, romtxt, romtxt); + } + xfree (romtxt); } static struct uaedev_config_info *getuci(struct uae_prefs *p) { - if (p->mountitems < MOUNT_CONFIG_SIZE) - return &p->mountconfig[p->mountitems++]; - return NULL; + if (p->mountitems < MOUNT_CONFIG_SIZE) + return &p->mountconfig[p->mountitems++]; + return NULL; } struct uaedev_config_info *add_filesys_config (struct uae_prefs *p, int index, - TCHAR *devname, TCHAR *volname, TCHAR *rootdir, int readonly, - int secspertrack, int surfaces, int reserved, - int blocksize, int bootpri, - TCHAR *filesysdir, int hdc, int flags) { - struct uaedev_config_info *uci; - int i; - TCHAR *s; - - if (index < 0) { - uci = getuci(p); - uci->configoffset = -1; - } else { - uci = &p->mountconfig[index]; - } - if (!uci) - return 0; - uci->ishdf = volname == NULL ? 1 : 0; - _tcscpy (uci->devname, devname ? devname : L""); - _tcscpy (uci->volname, volname ? volname : L""); - _tcscpy (uci->rootdir, rootdir ? rootdir : L""); - uci->readonly = readonly; - uci->sectors = secspertrack; - uci->surfaces = surfaces; - uci->reserved = reserved; - uci->blocksize = blocksize; - uci->bootpri = bootpri; - uci->donotmount = 0; - uci->autoboot = 0; - if (bootpri < -128) - uci->donotmount = 1; - else if (bootpri >= -127) - uci->autoboot = 1; - uci->controller = hdc; - _tcscpy (uci->filesys, filesysdir ? filesysdir : L""); - if (!uci->devname[0]) { - TCHAR base[32]; - TCHAR base2[32]; - int num = 0; - if (uci->rootdir[0] == 0 && !uci->ishdf) - _tcscpy (base, L"RDH"); - else - _tcscpy (base, L"DH"); - _tcscpy (base2, base); - for (i = 0; i < p->mountitems; i++) { - _stprintf (base2, L"%s%d", base, num); - if (!_tcscmp(base2, p->mountconfig[i].devname)) { - num++; - i = -1; - continue; - } - } - _tcscpy (uci->devname, base2); - } - s = filesys_createvolname (volname, rootdir, L"Harddrive"); - _tcscpy (uci->volname, s); - xfree (s); - return uci; + TCHAR *devname, TCHAR *volname, TCHAR *rootdir, int readonly, + int secspertrack, int surfaces, int reserved, + int blocksize, int bootpri, + TCHAR *filesysdir, int hdc, int flags) { + struct uaedev_config_info *uci; + int i; + TCHAR *s; + + if (index < 0) { + uci = getuci(p); + uci->configoffset = -1; + } else { + uci = &p->mountconfig[index]; + } + if (!uci) + return 0; + uci->ishdf = volname == NULL ? 1 : 0; + _tcscpy (uci->devname, devname ? devname : L""); + _tcscpy (uci->volname, volname ? volname : L""); + _tcscpy (uci->rootdir, rootdir ? rootdir : L""); + uci->readonly = readonly; + uci->sectors = secspertrack; + uci->surfaces = surfaces; + uci->reserved = reserved; + uci->blocksize = blocksize; + uci->bootpri = bootpri; + uci->donotmount = 0; + uci->autoboot = 0; + if (bootpri < -128) + uci->donotmount = 1; + else if (bootpri >= -127) + uci->autoboot = 1; + uci->controller = hdc; + _tcscpy (uci->filesys, filesysdir ? filesysdir : L""); + if (!uci->devname[0]) { + TCHAR base[32]; + TCHAR base2[32]; + int num = 0; + if (uci->rootdir[0] == 0 && !uci->ishdf) + _tcscpy (base, L"RDH"); + else + _tcscpy (base, L"DH"); + _tcscpy (base2, base); + for (i = 0; i < p->mountitems; i++) { + _stprintf (base2, L"%s%d", base, num); + if (!_tcscmp(base2, p->mountconfig[i].devname)) { + num++; + i = -1; + continue; + } + } + _tcscpy (uci->devname, base2); + } + s = filesys_createvolname (volname, rootdir, L"Harddrive"); + _tcscpy (uci->volname, s); + xfree (s); + return uci; } static void parse_addmem (struct uae_prefs *p, TCHAR *buf, int num) { - uae_u32 size = 0, addr = 0; + uae_u32 size = 0, addr = 0; - if (!getintval2 (&buf, &addr, ',')) - return; - if (!getintval2 (&buf, &size, 0)) - return; - if (addr & 0xffff) - return; - if ((size & 0xffff) || (size & 0xffff0000) == 0) - return; - p->custom_memory_addrs[num] = addr; - p->custom_memory_sizes[num] = size; + if (!getintval2 (&buf, &addr, ',')) + return; + if (!getintval2 (&buf, &size, 0)) + return; + if (addr & 0xffff) + return; + if ((size & 0xffff) || (size & 0xffff0000) == 0) + return; + p->custom_memory_addrs[num] = addr; + p->custom_memory_sizes[num] = size; } static int cfgfile_parse_hardware (struct uae_prefs *p, TCHAR *option, TCHAR *value) { - int tmpval, dummyint, i; - TCHAR *section = 0; - TCHAR tmpbuf[CONFIG_BLEN]; + int tmpval, dummyint, i; + TCHAR *section = 0; + TCHAR tmpbuf[CONFIG_BLEN]; - if (cfgfile_yesno (option, value, L"cpu_cycle_exact", &p->cpu_cycle_exact) - || cfgfile_yesno (option, value, L"blitter_cycle_exact", &p->blitter_cycle_exact)) { - if (p->cpu_model >= 68020 && p->cachesize > 0) - p->cpu_cycle_exact = p->blitter_cycle_exact = 0; - /* we don't want cycle-exact in 68020/40+JIT modes */ - return 1; - } - if (cfgfile_yesno (option, value, L"cycle_exact", &tmpval)) { - p->cpu_cycle_exact = p->blitter_cycle_exact = tmpval ? 1 : 0; - if (p->cpu_model >= 68020 && p->cachesize > 0) - p->cpu_cycle_exact = p->blitter_cycle_exact = 0; - return 1; - } + if (cfgfile_yesno (option, value, L"cpu_cycle_exact", &p->cpu_cycle_exact) + || cfgfile_yesno (option, value, L"blitter_cycle_exact", &p->blitter_cycle_exact)) { + if (p->cpu_model >= 68020 && p->cachesize > 0) + p->cpu_cycle_exact = p->blitter_cycle_exact = 0; + /* we don't want cycle-exact in 68020/40+JIT modes */ + return 1; + } + if (cfgfile_yesno (option, value, L"cycle_exact", &tmpval)) { + p->cpu_cycle_exact = p->blitter_cycle_exact = tmpval ? 1 : 0; + if (p->cpu_model >= 68020 && p->cachesize > 0) + p->cpu_cycle_exact = p->blitter_cycle_exact = 0; + return 1; + } - if (cfgfile_string (option, value, L"cpu_multiplier", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - p->cpu_clock_multiplier = (int)(_tstof (tmpbuf) * 256.0); - return 1; - } + if (cfgfile_string (option, value, L"cpu_multiplier", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + p->cpu_clock_multiplier = (int)(_tstof (tmpbuf) * 256.0); + return 1; + } - if (cfgfile_yesno (option, value, L"scsi_a3000", &dummyint)) { - if (dummyint) - p->cs_mbdmac = 1; - return 1; - } - if (cfgfile_yesno (option, value, L"scsi_a4000t", &dummyint)) { - if (dummyint) - p->cs_mbdmac = 2; - return 1; - } - - if (cfgfile_string (option, value, L"a2065", p->a2065name, sizeof p->a2065name / sizeof (TCHAR))) - return 1; + if (cfgfile_yesno (option, value, L"scsi_a3000", &dummyint)) { + if (dummyint) + p->cs_mbdmac = 1; + return 1; + } + if (cfgfile_yesno (option, value, L"scsi_a4000t", &dummyint)) { + if (dummyint) + p->cs_mbdmac = 2; + return 1; + } - if (cfgfile_yesno (option, value, L"immediate_blits", &p->immediate_blits) - || cfgfile_yesno (option, value, L"cd32cd", &p->cs_cd32cd) - || cfgfile_yesno (option, value, L"cd32c2p", &p->cs_cd32c2p) - || cfgfile_yesno (option, value, L"cd32nvram", &p->cs_cd32nvram) - || cfgfile_yesno (option, value, L"cdtvcd", &p->cs_cdtvcd) - || cfgfile_yesno (option, value, L"cdtvram", &p->cs_cdtvram) - || cfgfile_yesno (option, value, L"a1000ram", &p->cs_a1000ram) - || cfgfile_yesno (option, value, L"pcmcia", &p->cs_pcmcia) - || cfgfile_yesno (option, value, L"scsi_cdtv", &p->cs_cdtvscsi) - || cfgfile_yesno (option, value, L"scsi_a4091", &p->cs_a4091) - || cfgfile_yesno (option, value, L"scsi_a2091", &p->cs_a2091) - || cfgfile_yesno (option, value, L"cia_overlay", &p->cs_ciaoverlay) - || cfgfile_yesno (option, value, L"bogomem_fast", &p->cs_slowmemisfast) - || cfgfile_yesno (option, value, L"ksmirror_e0", &p->cs_ksmirror_e0) - || cfgfile_yesno (option, value, L"ksmirror_a8", &p->cs_ksmirror_a8) - || cfgfile_yesno (option, value, L"resetwarning", &p->cs_resetwarning) - || cfgfile_yesno (option, value, L"denise_noehb", &p->cs_denisenoehb) - || cfgfile_yesno (option, value, L"agnus_bltbusybug", &p->cs_agnusbltbusybug) - - || cfgfile_yesno (option, value, L"kickshifter", &p->kickshifter) - || cfgfile_yesno (option, value, L"ntsc", &p->ntscmode) - || cfgfile_yesno (option, value, L"sana2", &p->sana2) - || cfgfile_yesno (option, value, L"genlock", &p->genlock) - || cfgfile_yesno (option, value, L"cpu_compatible", &p->cpu_compatible) - || cfgfile_yesno (option, value, L"cpu_24bit_addressing", &p->address_space_24) - || cfgfile_yesno (option, value, L"parallel_on_demand", &p->parallel_demand) - || cfgfile_yesno (option, value, L"parallel_postscript_emulation", &p->parallel_postscript_emulation) - || cfgfile_yesno (option, value, L"parallel_postscript_detection", &p->parallel_postscript_detection) - || cfgfile_yesno (option, value, L"serial_on_demand", &p->serial_demand) - || cfgfile_yesno (option, value, L"serial_hardware_ctsrts", &p->serial_hwctsrts) - || cfgfile_yesno (option, value, L"serial_direct", &p->serial_direct) - || cfgfile_yesno (option, value, L"comp_nf", &p->compnf) - || cfgfile_yesno (option, value, L"comp_constjump", &p->comp_constjump) - || cfgfile_yesno (option, value, L"comp_oldsegv", &p->comp_oldsegv) - || cfgfile_yesno (option, value, L"compforcesettings", &dummyint) - || cfgfile_yesno (option, value, L"compfpu", &p->compfpu) - || cfgfile_yesno (option, value, L"fpu_strict", &p->fpu_strict) - || cfgfile_yesno (option, value, L"comp_midopt", &p->comp_midopt) - || cfgfile_yesno (option, value, L"comp_lowopt", &p->comp_lowopt) - || cfgfile_yesno (option, value, L"rtg_nocustom", &p->picasso96_nocustom) - || cfgfile_yesno (option, value, L"uaeserial", &p->uaeserial)) - return 1; + if (cfgfile_string (option, value, L"a2065", p->a2065name, sizeof p->a2065name / sizeof (TCHAR))) + return 1; - if (cfgfile_intval (option, value, L"cachesize", &p->cachesize, 1) - || cfgfile_intval (option, value, L"cpu060_revision", &p->cpu060_revision, 1) - || cfgfile_intval (option, value, L"fpu_revision", &p->fpu_revision, 1) - || cfgfile_intval (option, value, L"cdtvramcard", &p->cs_cdtvcard, 1) - || cfgfile_intval (option, value, L"fatgary", &p->cs_fatgaryrev, 1) - || cfgfile_intval (option, value, L"ramsey", &p->cs_ramseyrev, 1) - || cfgfile_intval (option, value, L"chipset_refreshrate", &p->chipset_refreshrate, 1) - || cfgfile_intval (option, value, L"fastmem_size", &p->fastmem_size, 0x100000) - || cfgfile_intval (option, value, L"a3000mem_size", &p->mbresmem_low_size, 0x100000) - || cfgfile_intval (option, value, L"mbresmem_size", &p->mbresmem_high_size, 0x100000) - || cfgfile_intval (option, value, L"z3mem_size", &p->z3fastmem_size, 0x100000) - || cfgfile_intval (option, value, L"z3mem2_size", &p->z3fastmem2_size, 0x100000) - || cfgfile_intval (option, value, L"z3mem_start", &p->z3fastmem_start, 1) - || cfgfile_intval (option, value, L"bogomem_size", &p->bogomem_size, 0x40000) - || cfgfile_intval (option, value, L"gfxcard_size", &p->gfxmem_size, 0x100000) - || cfgfile_intval (option, value, L"rtg_modes", &p->picasso96_modeflags, 1) - || cfgfile_intval (option, value, L"floppy_speed", &p->floppy_speed, 1) - || cfgfile_intval (option, value, L"floppy_write_length", &p->floppy_write_length, 1) - || cfgfile_intval (option, value, L"nr_floppies", &p->nr_floppies, 1) - || cfgfile_intval (option, value, L"floppy0type", &p->dfxtype[0], 1) - || cfgfile_intval (option, value, L"floppy1type", &p->dfxtype[1], 1) - || cfgfile_intval (option, value, L"floppy2type", &p->dfxtype[2], 1) - || cfgfile_intval (option, value, L"floppy3type", &p->dfxtype[3], 1) - || cfgfile_intval (option, value, L"maprom", &p->maprom, 1) - || cfgfile_intval (option, value, L"parallel_autoflush", &p->parallel_autoflush_time, 1) - || cfgfile_intval (option, value, L"uae_hide", &p->uae_hide, 1) - || cfgfile_intval (option, value, L"cpu_frequency", &p->cpu_frequency, 1) - || cfgfile_intval (option, value, L"catweasel", &p->catweasel, 1)) - return 1; + if (cfgfile_yesno (option, value, L"immediate_blits", &p->immediate_blits) + || cfgfile_yesno (option, value, L"cd32cd", &p->cs_cd32cd) + || cfgfile_yesno (option, value, L"cd32c2p", &p->cs_cd32c2p) + || cfgfile_yesno (option, value, L"cd32nvram", &p->cs_cd32nvram) + || cfgfile_yesno (option, value, L"cdtvcd", &p->cs_cdtvcd) + || cfgfile_yesno (option, value, L"cdtvram", &p->cs_cdtvram) + || cfgfile_yesno (option, value, L"a1000ram", &p->cs_a1000ram) + || cfgfile_yesno (option, value, L"pcmcia", &p->cs_pcmcia) + || cfgfile_yesno (option, value, L"scsi_cdtv", &p->cs_cdtvscsi) + || cfgfile_yesno (option, value, L"scsi_a4091", &p->cs_a4091) + || cfgfile_yesno (option, value, L"scsi_a2091", &p->cs_a2091) + || cfgfile_yesno (option, value, L"cia_overlay", &p->cs_ciaoverlay) + || cfgfile_yesno (option, value, L"bogomem_fast", &p->cs_slowmemisfast) + || cfgfile_yesno (option, value, L"ksmirror_e0", &p->cs_ksmirror_e0) + || cfgfile_yesno (option, value, L"ksmirror_a8", &p->cs_ksmirror_a8) + || cfgfile_yesno (option, value, L"resetwarning", &p->cs_resetwarning) + || cfgfile_yesno (option, value, L"denise_noehb", &p->cs_denisenoehb) + || cfgfile_yesno (option, value, L"agnus_bltbusybug", &p->cs_agnusbltbusybug) + + || cfgfile_yesno (option, value, L"kickshifter", &p->kickshifter) + || cfgfile_yesno (option, value, L"ntsc", &p->ntscmode) + || cfgfile_yesno (option, value, L"sana2", &p->sana2) + || cfgfile_yesno (option, value, L"genlock", &p->genlock) + || cfgfile_yesno (option, value, L"cpu_compatible", &p->cpu_compatible) + || cfgfile_yesno (option, value, L"cpu_24bit_addressing", &p->address_space_24) + || cfgfile_yesno (option, value, L"parallel_on_demand", &p->parallel_demand) + || cfgfile_yesno (option, value, L"parallel_postscript_emulation", &p->parallel_postscript_emulation) + || cfgfile_yesno (option, value, L"parallel_postscript_detection", &p->parallel_postscript_detection) + || cfgfile_yesno (option, value, L"serial_on_demand", &p->serial_demand) + || cfgfile_yesno (option, value, L"serial_hardware_ctsrts", &p->serial_hwctsrts) + || cfgfile_yesno (option, value, L"serial_direct", &p->serial_direct) + || cfgfile_yesno (option, value, L"comp_nf", &p->compnf) + || cfgfile_yesno (option, value, L"comp_constjump", &p->comp_constjump) + || cfgfile_yesno (option, value, L"comp_oldsegv", &p->comp_oldsegv) + || cfgfile_yesno (option, value, L"compforcesettings", &dummyint) + || cfgfile_yesno (option, value, L"compfpu", &p->compfpu) + || cfgfile_yesno (option, value, L"fpu_strict", &p->fpu_strict) + || cfgfile_yesno (option, value, L"comp_midopt", &p->comp_midopt) + || cfgfile_yesno (option, value, L"comp_lowopt", &p->comp_lowopt) + || cfgfile_yesno (option, value, L"rtg_nocustom", &p->picasso96_nocustom) + || cfgfile_yesno (option, value, L"uaeserial", &p->uaeserial)) + return 1; - if (cfgfile_strval (option, value, L"comp_trustbyte", &p->comptrustbyte, compmode, 0) - || cfgfile_strval (option, value, L"chipset_compatible", &p->cs_compatible, cscompa, 0) - || cfgfile_strval (option, value, L"rtc", &p->cs_rtc, rtctype, 0) - || cfgfile_strval (option, value, L"ksmirror", &p->cs_ksmirror_e0, ksmirrortype, 0) - || cfgfile_strval (option, value, L"ciaatod", &p->cs_ciaatod, ciaatodmode, 0) - || cfgfile_strval (option, value, L"ide", &p->cs_ide, idemode, 0) - || cfgfile_strval (option, value, L"scsi", &p->scsi, scsimode, 0) - || cfgfile_strval (option, value, L"comp_trustword", &p->comptrustword, compmode, 0) - || cfgfile_strval (option, value, L"comp_trustlong", &p->comptrustlong, compmode, 0) - || cfgfile_strval (option, value, L"comp_trustnaddr", &p->comptrustnaddr, compmode, 0) - || cfgfile_strval (option, value, L"collision_level", &p->collision_level, collmode, 0) - || cfgfile_strval (option, value, L"parallel_matrix_emulation", &p->parallel_matrix_emulation, epsonprinter, 0) - || cfgfile_strval (option, value, L"comp_flushmode", &p->comp_hardflush, flushmode, 0)) - return 1; + if (cfgfile_intval (option, value, L"cachesize", &p->cachesize, 1) + || cfgfile_intval (option, value, L"cpu060_revision", &p->cpu060_revision, 1) + || cfgfile_intval (option, value, L"fpu_revision", &p->fpu_revision, 1) + || cfgfile_intval (option, value, L"cdtvramcard", &p->cs_cdtvcard, 1) + || cfgfile_intval (option, value, L"fatgary", &p->cs_fatgaryrev, 1) + || cfgfile_intval (option, value, L"ramsey", &p->cs_ramseyrev, 1) + || cfgfile_intval (option, value, L"chipset_refreshrate", &p->chipset_refreshrate, 1) + || cfgfile_intval (option, value, L"fastmem_size", &p->fastmem_size, 0x100000) + || cfgfile_intval (option, value, L"a3000mem_size", &p->mbresmem_low_size, 0x100000) + || cfgfile_intval (option, value, L"mbresmem_size", &p->mbresmem_high_size, 0x100000) + || cfgfile_intval (option, value, L"z3mem_size", &p->z3fastmem_size, 0x100000) + || cfgfile_intval (option, value, L"z3mem2_size", &p->z3fastmem2_size, 0x100000) + || cfgfile_intval (option, value, L"z3mem_start", &p->z3fastmem_start, 1) + || cfgfile_intval (option, value, L"bogomem_size", &p->bogomem_size, 0x40000) + || cfgfile_intval (option, value, L"gfxcard_size", &p->gfxmem_size, 0x100000) + || cfgfile_intval (option, value, L"rtg_modes", &p->picasso96_modeflags, 1) + || cfgfile_intval (option, value, L"floppy_speed", &p->floppy_speed, 1) + || cfgfile_intval (option, value, L"floppy_write_length", &p->floppy_write_length, 1) + || cfgfile_intval (option, value, L"nr_floppies", &p->nr_floppies, 1) + || cfgfile_intval (option, value, L"floppy0type", &p->dfxtype[0], 1) + || cfgfile_intval (option, value, L"floppy1type", &p->dfxtype[1], 1) + || cfgfile_intval (option, value, L"floppy2type", &p->dfxtype[2], 1) + || cfgfile_intval (option, value, L"floppy3type", &p->dfxtype[3], 1) + || cfgfile_intval (option, value, L"maprom", &p->maprom, 1) + || cfgfile_intval (option, value, L"parallel_autoflush", &p->parallel_autoflush_time, 1) + || cfgfile_intval (option, value, L"uae_hide", &p->uae_hide, 1) + || cfgfile_intval (option, value, L"cpu_frequency", &p->cpu_frequency, 1) + || cfgfile_intval (option, value, L"catweasel", &p->catweasel, 1)) + return 1; - if (cfgfile_string (option, value, L"kickstart_rom_file", p->romfile, sizeof p->romfile / sizeof (TCHAR)) - || cfgfile_string (option, value, L"kickstart_ext_rom_file", p->romextfile, sizeof p->romextfile / sizeof (TCHAR)) - || cfgfile_string (option, value, L"amax_rom_file", p->amaxromfile, sizeof p->amaxromfile / sizeof (TCHAR)) - || cfgfile_string (option, value, L"flash_file", p->flashfile, sizeof p->flashfile / sizeof (TCHAR)) - || cfgfile_string (option, value, L"cart_file", p->cartfile, sizeof p->cartfile / sizeof (TCHAR)) - || cfgfile_string (option, value, L"pci_devices", p->pci_devices, sizeof p->pci_devices / sizeof (TCHAR)) - || cfgfile_string (option, value, L"ghostscript_parameters", p->ghostscript_parameters, sizeof p->ghostscript_parameters / sizeof (TCHAR))) - return 1; + if (cfgfile_strval (option, value, L"comp_trustbyte", &p->comptrustbyte, compmode, 0) + || cfgfile_strval (option, value, L"chipset_compatible", &p->cs_compatible, cscompa, 0) + || cfgfile_strval (option, value, L"rtc", &p->cs_rtc, rtctype, 0) + || cfgfile_strval (option, value, L"ksmirror", &p->cs_ksmirror_e0, ksmirrortype, 0) + || cfgfile_strval (option, value, L"ciaatod", &p->cs_ciaatod, ciaatodmode, 0) + || cfgfile_strval (option, value, L"ide", &p->cs_ide, idemode, 0) + || cfgfile_strval (option, value, L"scsi", &p->scsi, scsimode, 0) + || cfgfile_strval (option, value, L"comp_trustword", &p->comptrustword, compmode, 0) + || cfgfile_strval (option, value, L"comp_trustlong", &p->comptrustlong, compmode, 0) + || cfgfile_strval (option, value, L"comp_trustnaddr", &p->comptrustnaddr, compmode, 0) + || cfgfile_strval (option, value, L"collision_level", &p->collision_level, collmode, 0) + || cfgfile_strval (option, value, L"parallel_matrix_emulation", &p->parallel_matrix_emulation, epsonprinter, 0) + || cfgfile_strval (option, value, L"comp_flushmode", &p->comp_hardflush, flushmode, 0)) + return 1; - if (cfgfile_strval (option, value, L"cart_internal", &p->cart_internal, cartsmode, 0)) { - if (p->cart_internal) { - struct romdata *rd = getromdatabyid (63); - if (rd) - _stprintf (p->cartfile, L":%s", rd->configname); - } - return 1; - } - if (cfgfile_string (option, value, L"kickstart_rom", p->romident, sizeof p->romident / sizeof (TCHAR))) { - decode_rom_ident (p->romfile, sizeof p->romfile / sizeof (TCHAR), p->romident); - return 1; - } - if (cfgfile_string (option, value, L"kickstart_ext_rom", p->romextident, sizeof p->romextident / sizeof (TCHAR))) { - decode_rom_ident (p->romextfile, sizeof p->romextfile / sizeof (TCHAR), p->romextident); - return 1; - } - if (cfgfile_string (option, value, L"cart", p->cartident, sizeof p->cartident / sizeof (TCHAR))) { - decode_rom_ident (p->cartfile, sizeof p->cartfile / sizeof (TCHAR), p->cartident); - return 1; - } - - for (i = 0; i < 4; i++) { - _stprintf (tmpbuf, L"floppy%d", i); - if (cfgfile_string (option, value, tmpbuf, p->df[i], sizeof p->df[i] / sizeof (TCHAR))) - return 1; - } - - if (cfgfile_intval (option, value, L"chipmem_size", &dummyint, 1)) { - if (dummyint < 0) - p->chipmem_size = 0x20000; /* 128k, prototype support */ - else if (dummyint == 0) - p->chipmem_size = 0x40000; /* 256k */ - else - p->chipmem_size = dummyint * 0x80000; - return 1; - } + if (cfgfile_string (option, value, L"kickstart_rom_file", p->romfile, sizeof p->romfile / sizeof (TCHAR)) + || cfgfile_string (option, value, L"kickstart_ext_rom_file", p->romextfile, sizeof p->romextfile / sizeof (TCHAR)) + || cfgfile_string (option, value, L"amax_rom_file", p->amaxromfile, sizeof p->amaxromfile / sizeof (TCHAR)) + || cfgfile_string (option, value, L"flash_file", p->flashfile, sizeof p->flashfile / sizeof (TCHAR)) + || cfgfile_string (option, value, L"cart_file", p->cartfile, sizeof p->cartfile / sizeof (TCHAR)) + || cfgfile_string (option, value, L"pci_devices", p->pci_devices, sizeof p->pci_devices / sizeof (TCHAR)) + || cfgfile_string (option, value, L"ghostscript_parameters", p->ghostscript_parameters, sizeof p->ghostscript_parameters / sizeof (TCHAR))) + return 1; - if (cfgfile_string (option, value, L"addmem1", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - parse_addmem (p, tmpbuf, 0); - return 1; - } - if (cfgfile_string (option, value, L"addmem2", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - parse_addmem (p, tmpbuf, 1); - return 1; - } + if (cfgfile_strval (option, value, L"cart_internal", &p->cart_internal, cartsmode, 0)) { + if (p->cart_internal) { + struct romdata *rd = getromdatabyid (63); + if (rd) + _stprintf (p->cartfile, L":%s", rd->configname); + } + return 1; + } + if (cfgfile_string (option, value, L"kickstart_rom", p->romident, sizeof p->romident / sizeof (TCHAR))) { + decode_rom_ident (p->romfile, sizeof p->romfile / sizeof (TCHAR), p->romident); + return 1; + } + if (cfgfile_string (option, value, L"kickstart_ext_rom", p->romextident, sizeof p->romextident / sizeof (TCHAR))) { + decode_rom_ident (p->romextfile, sizeof p->romextfile / sizeof (TCHAR), p->romextident); + return 1; + } + if (cfgfile_string (option, value, L"cart", p->cartident, sizeof p->cartident / sizeof (TCHAR))) { + decode_rom_ident (p->cartfile, sizeof p->cartfile / sizeof (TCHAR), p->cartident); + return 1; + } - if (cfgfile_strval (option, value, L"chipset", &tmpval, csmode, 0)) { - set_chipset_mask (p, tmpval); - return 1; - } + for (i = 0; i < 4; i++) { + _stprintf (tmpbuf, L"floppy%d", i); + if (cfgfile_string (option, value, tmpbuf, p->df[i], sizeof p->df[i] / sizeof (TCHAR))) + return 1; + } - if (cfgfile_string (option, value, L"mmu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - p->mmu_model = _tstol(tmpbuf); - return 1; - } + if (cfgfile_intval (option, value, L"chipmem_size", &dummyint, 1)) { + if (dummyint < 0) + p->chipmem_size = 0x20000; /* 128k, prototype support */ + else if (dummyint == 0) + p->chipmem_size = 0x40000; /* 256k */ + else + p->chipmem_size = dummyint * 0x80000; + return 1; + } - if (cfgfile_string (option, value, L"fpu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - p->fpu_model = _tstol(tmpbuf); - return 1; - } + if (cfgfile_string (option, value, L"addmem1", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + parse_addmem (p, tmpbuf, 0); + return 1; + } + if (cfgfile_string (option, value, L"addmem2", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + parse_addmem (p, tmpbuf, 1); + return 1; + } - if (cfgfile_string (option, value, L"cpu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - p->cpu_model = _tstol(tmpbuf); - p->fpu_model = 0; - return 1; - } + if (cfgfile_strval (option, value, L"chipset", &tmpval, csmode, 0)) { + set_chipset_mask (p, tmpval); + return 1; + } - /* old-style CPU configuration */ - if (cfgfile_string (option, value, L"cpu_type", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - p->fpu_model = 0; - p->address_space_24 = 0; - p->cpu_model = 680000; - if (!_tcscmp (tmpbuf, L"68000")) { - p->cpu_model = 68000; - } else if (!_tcscmp (tmpbuf, L"68010")) { - p->cpu_model = 68010; - } else if (!_tcscmp (tmpbuf, L"68ec020")) { - p->cpu_model = 68020; - p->address_space_24 = 1; - } else if (!_tcscmp (tmpbuf, L"68020")) { - p->cpu_model = 68020; - } else if (!_tcscmp (tmpbuf, L"68ec020/68881")) { - p->cpu_model = 68020; - p->fpu_model = 68881; - p->address_space_24 = 1; - } else if (!_tcscmp (tmpbuf, L"68020/68881")) { - p->cpu_model = 68020; - p->fpu_model = 68881; - } else if (!_tcscmp (tmpbuf, L"68040")) { - p->cpu_model = 68040; - p->fpu_model = 68040; - } else if (!_tcscmp (tmpbuf, L"68060")) { - p->cpu_model = 68060; - p->fpu_model = 68060; + if (cfgfile_string (option, value, L"mmu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + p->mmu_model = _tstol(tmpbuf); + return 1; } - return 1; - } - if (p->config_version < (21 << 16)) { - if (cfgfile_strval (option, value, L"cpu_speed", &p->m68k_speed, speedmode, 1) - /* Broken earlier versions used to write this out as a string. */ - || cfgfile_strval (option, value, L"finegraincpu_speed", &p->m68k_speed, speedmode, 1)) - { - p->m68k_speed--; - return 1; + if (cfgfile_string (option, value, L"fpu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + p->fpu_model = _tstol(tmpbuf); + return 1; } - } - if (cfgfile_intval (option, value, L"cpu_speed", &p->m68k_speed, 1)) { - p->m68k_speed *= CYCLE_UNIT; - return 1; - } + if (cfgfile_string (option, value, L"cpu_model", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + p->cpu_model = _tstol(tmpbuf); + p->fpu_model = 0; + return 1; + } - if (cfgfile_intval (option, value, L"finegrain_cpu_speed", &p->m68k_speed, 1)) { - if (OFFICIAL_CYCLE_UNIT > CYCLE_UNIT) { - int factor = OFFICIAL_CYCLE_UNIT / CYCLE_UNIT; - p->m68k_speed = (p->m68k_speed + factor - 1) / factor; + /* old-style CPU configuration */ + if (cfgfile_string (option, value, L"cpu_type", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + p->fpu_model = 0; + p->address_space_24 = 0; + p->cpu_model = 680000; + if (!_tcscmp (tmpbuf, L"68000")) { + p->cpu_model = 68000; + } else if (!_tcscmp (tmpbuf, L"68010")) { + p->cpu_model = 68010; + } else if (!_tcscmp (tmpbuf, L"68ec020")) { + p->cpu_model = 68020; + p->address_space_24 = 1; + } else if (!_tcscmp (tmpbuf, L"68020")) { + p->cpu_model = 68020; + } else if (!_tcscmp (tmpbuf, L"68ec020/68881")) { + p->cpu_model = 68020; + p->fpu_model = 68881; + p->address_space_24 = 1; + } else if (!_tcscmp (tmpbuf, L"68020/68881")) { + p->cpu_model = 68020; + p->fpu_model = 68881; + } else if (!_tcscmp (tmpbuf, L"68040")) { + p->cpu_model = 68040; + p->fpu_model = 68040; + } else if (!_tcscmp (tmpbuf, L"68060")) { + p->cpu_model = 68060; + p->fpu_model = 68060; + } + return 1; } - if (strcasecmp (value, L"max") == 0) - p->m68k_speed = -1; - return 1; - } - if (cfgfile_intval (option, value, L"dongle", &p->dongle, 1)) { - if (p->dongle == 0) - cfgfile_strval (option, value, L"dongle", &p->dongle, dongles, 0); - return 1; - } + if (p->config_version < (21 << 16)) { + if (cfgfile_strval (option, value, L"cpu_speed", &p->m68k_speed, speedmode, 1) + /* Broken earlier versions used to write this out as a string. */ + || cfgfile_strval (option, value, L"finegraincpu_speed", &p->m68k_speed, speedmode, 1)) + { + p->m68k_speed--; + return 1; + } + } - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - TCHAR tmp[100]; - _stprintf (tmp, L"uaehf%d", i); - if (_tcscmp (option, tmp) == 0) - return 1; - } - - if (_tcscmp (option, L"filesystem") == 0 - || _tcscmp (option, L"hardfile") == 0) - { - int secs, heads, reserved, bs, ro; - TCHAR *aname, *root; - TCHAR *tmpp = _tcschr (value, ','); - TCHAR *str; - - if (config_newfilesystem) - return 1; - - if (tmpp == 0) - goto invalid_fs; - - *tmpp++ = '\0'; - if (_tcscmp (value, L"1") == 0 || strcasecmp (value, L"ro") == 0 - || strcasecmp (value, L"readonly") == 0 - || strcasecmp (value, L"read-only") == 0) - ro = 1; - else if (_tcscmp (value, L"0") == 0 || strcasecmp (value, L"rw") == 0 - || strcasecmp (value, L"readwrite") == 0 - || strcasecmp (value, L"read-write") == 0) - ro = 0; - else - goto invalid_fs; - secs = 0; heads = 0; reserved = 0; bs = 0; - - value = tmpp; - if (_tcscmp (option, L"filesystem") == 0) { - tmpp = _tcschr (value, ':'); - if (tmpp == 0) - goto invalid_fs; - *tmpp++ = '\0'; - aname = value; - root = tmpp; - } else { - if (! getintval (&value, &secs, ',') - || ! getintval (&value, &heads, ',') - || ! getintval (&value, &reserved, ',') - || ! getintval (&value, &bs, ',')) - goto invalid_fs; - root = value; - aname = 0; - } - str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root); + if (cfgfile_intval (option, value, L"cpu_speed", &p->m68k_speed, 1)) { + p->m68k_speed *= CYCLE_UNIT; + return 1; + } + + if (cfgfile_intval (option, value, L"finegrain_cpu_speed", &p->m68k_speed, 1)) { + if (OFFICIAL_CYCLE_UNIT > CYCLE_UNIT) { + int factor = OFFICIAL_CYCLE_UNIT / CYCLE_UNIT; + p->m68k_speed = (p->m68k_speed + factor - 1) / factor; + } + if (strcasecmp (value, L"max") == 0) + p->m68k_speed = -1; + return 1; + } + + if (cfgfile_intval (option, value, L"dongle", &p->dongle, 1)) { + if (p->dongle == 0) + cfgfile_strval (option, value, L"dongle", &p->dongle, dongles, 0); + return 1; + } + + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + TCHAR tmp[100]; + _stprintf (tmp, L"uaehf%d", i); + if (_tcscmp (option, tmp) == 0) + return 1; + } + + if (_tcscmp (option, L"filesystem") == 0 + || _tcscmp (option, L"hardfile") == 0) + { + int secs, heads, reserved, bs, ro; + TCHAR *aname, *root; + TCHAR *tmpp = _tcschr (value, ','); + TCHAR *str; + + if (config_newfilesystem) + return 1; + + if (tmpp == 0) + goto invalid_fs; + + *tmpp++ = '\0'; + if (_tcscmp (value, L"1") == 0 || strcasecmp (value, L"ro") == 0 + || strcasecmp (value, L"readonly") == 0 + || strcasecmp (value, L"read-only") == 0) + ro = 1; + else if (_tcscmp (value, L"0") == 0 || strcasecmp (value, L"rw") == 0 + || strcasecmp (value, L"readwrite") == 0 + || strcasecmp (value, L"read-write") == 0) + ro = 0; + else + goto invalid_fs; + secs = 0; heads = 0; reserved = 0; bs = 0; + + value = tmpp; + if (_tcscmp (option, L"filesystem") == 0) { + tmpp = _tcschr (value, ':'); + if (tmpp == 0) + goto invalid_fs; + *tmpp++ = '\0'; + aname = value; + root = tmpp; + } else { + if (! getintval (&value, &secs, ',') + || ! getintval (&value, &heads, ',') + || ! getintval (&value, &reserved, ',') + || ! getintval (&value, &bs, ',')) + goto invalid_fs; + root = value; + aname = 0; + } + str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root); #ifdef FILESYS - add_filesys_config (p, -1, NULL, aname, str, ro, secs, heads, reserved, bs, 0, NULL, 0, 0); + add_filesys_config (p, -1, NULL, aname, str, ro, secs, heads, reserved, bs, 0, NULL, 0, 0); #endif - free (str); - return 1; + free (str); + return 1; - } - - if (_tcscmp (option, L"filesystem2") == 0 - || _tcscmp (option, L"hardfile2") == 0) - { - int secs, heads, reserved, bs, ro, bp, hdcv; - TCHAR *dname = NULL, *aname = L"", *root = NULL, *fs = NULL, *hdc; - TCHAR *tmpp = _tcschr (value, ','); - TCHAR *str = NULL; - - config_newfilesystem = 1; - if (tmpp == 0) - goto invalid_fs; - - *tmpp++ = '\0'; - if (strcasecmp (value, L"ro") == 0) - ro = 1; - else if (strcasecmp (value, L"rw") == 0) - ro = 0; - else - goto invalid_fs; - secs = 0; heads = 0; reserved = 0; bs = 0; bp = 0; - fs = 0; hdc = 0; hdcv = 0; - - value = tmpp; - if (_tcscmp (option, L"filesystem2") == 0) { - tmpp = _tcschr (value, ':'); - if (tmpp == 0) - goto empty_fs; - *tmpp++ = 0; - dname = value; - aname = tmpp; - tmpp = _tcschr (tmpp, ':'); - if (tmpp == 0) - goto empty_fs; - *tmpp++ = 0; - root = tmpp; - tmpp = _tcschr (tmpp, ','); - if (tmpp == 0) - goto empty_fs; - *tmpp++ = 0; - if (! getintval (&tmpp, &bp, 0)) - goto empty_fs; - } else { - tmpp = _tcschr (value, ':'); - if (tmpp == 0) - goto invalid_fs; - *tmpp++ = '\0'; - dname = value; - root = tmpp; - tmpp = _tcschr (tmpp, ','); - if (tmpp == 0) - goto invalid_fs; - *tmpp++ = 0; - aname = 0; - if (! getintval (&tmpp, &secs, ',') - || ! getintval (&tmpp, &heads, ',') - || ! getintval (&tmpp, &reserved, ',') - || ! getintval (&tmpp, &bs, ',')) - goto invalid_fs; - if (getintval2 (&tmpp, &bp, ',')) { - fs = tmpp; - tmpp = _tcschr (tmpp, ','); - if (tmpp != 0) { - *tmpp++ = 0; - hdc = tmpp; - if(_tcslen (hdc) >= 4 && !_tcsncmp (hdc, L"ide", 3)) { - hdcv = hdc[3] - '0' + HD_CONTROLLER_IDE0; - if (hdcv < HD_CONTROLLER_IDE0 || hdcv > HD_CONTROLLER_IDE3) - hdcv = 0; - } - if(_tcslen (hdc) >= 5 && !_tcsncmp (hdc, L"scsi", 4)) { - hdcv = hdc[4] - '0' + HD_CONTROLLER_SCSI0; - if (hdcv < HD_CONTROLLER_SCSI0 || hdcv > HD_CONTROLLER_SCSI6) - hdcv = 0; - } - if (_tcslen (hdc) >= 6 && !_tcsncmp (hdc, L"scsram", 6)) - hdcv = HD_CONTROLLER_PCMCIA_SRAM; - } - } } - empty_fs: - if (root) - str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root); + + if (_tcscmp (option, L"filesystem2") == 0 + || _tcscmp (option, L"hardfile2") == 0) + { + int secs, heads, reserved, bs, ro, bp, hdcv; + TCHAR *dname = NULL, *aname = L"", *root = NULL, *fs = NULL, *hdc; + TCHAR *tmpp = _tcschr (value, ','); + TCHAR *str = NULL; + + config_newfilesystem = 1; + if (tmpp == 0) + goto invalid_fs; + + *tmpp++ = '\0'; + if (strcasecmp (value, L"ro") == 0) + ro = 1; + else if (strcasecmp (value, L"rw") == 0) + ro = 0; + else + goto invalid_fs; + secs = 0; heads = 0; reserved = 0; bs = 0; bp = 0; + fs = 0; hdc = 0; hdcv = 0; + + value = tmpp; + if (_tcscmp (option, L"filesystem2") == 0) { + tmpp = _tcschr (value, ':'); + if (tmpp == 0) + goto empty_fs; + *tmpp++ = 0; + dname = value; + aname = tmpp; + tmpp = _tcschr (tmpp, ':'); + if (tmpp == 0) + goto empty_fs; + *tmpp++ = 0; + root = tmpp; + tmpp = _tcschr (tmpp, ','); + if (tmpp == 0) + goto empty_fs; + *tmpp++ = 0; + if (! getintval (&tmpp, &bp, 0)) + goto empty_fs; + } else { + tmpp = _tcschr (value, ':'); + if (tmpp == 0) + goto invalid_fs; + *tmpp++ = '\0'; + dname = value; + root = tmpp; + tmpp = _tcschr (tmpp, ','); + if (tmpp == 0) + goto invalid_fs; + *tmpp++ = 0; + aname = 0; + if (! getintval (&tmpp, &secs, ',') + || ! getintval (&tmpp, &heads, ',') + || ! getintval (&tmpp, &reserved, ',') + || ! getintval (&tmpp, &bs, ',')) + goto invalid_fs; + if (getintval2 (&tmpp, &bp, ',')) { + fs = tmpp; + tmpp = _tcschr (tmpp, ','); + if (tmpp != 0) { + *tmpp++ = 0; + hdc = tmpp; + if(_tcslen (hdc) >= 4 && !_tcsncmp (hdc, L"ide", 3)) { + hdcv = hdc[3] - '0' + HD_CONTROLLER_IDE0; + if (hdcv < HD_CONTROLLER_IDE0 || hdcv > HD_CONTROLLER_IDE3) + hdcv = 0; + } + if(_tcslen (hdc) >= 5 && !_tcsncmp (hdc, L"scsi", 4)) { + hdcv = hdc[4] - '0' + HD_CONTROLLER_SCSI0; + if (hdcv < HD_CONTROLLER_SCSI0 || hdcv > HD_CONTROLLER_SCSI6) + hdcv = 0; + } + if (_tcslen (hdc) >= 6 && !_tcsncmp (hdc, L"scsram", 6)) + hdcv = HD_CONTROLLER_PCMCIA_SRAM; + } + } + } +empty_fs: + if (root) + str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root); #ifdef FILESYS - add_filesys_config (p, -1, dname, aname, str, ro, secs, heads, reserved, bs, bp, fs, hdcv, 0); + add_filesys_config (p, -1, dname, aname, str, ro, secs, heads, reserved, bs, bp, fs, hdcv, 0); #endif - free (str); - return 1; + free (str); + return 1; - invalid_fs: - write_log (L"Invalid filesystem/hardfile specification.\n"); - return 1; - } +invalid_fs: + write_log (L"Invalid filesystem/hardfile specification.\n"); + return 1; + } - return 0; + return 0; } int cfgfile_parse_option (struct uae_prefs *p, TCHAR *option, TCHAR *value, int type) { - if (!_tcscmp (option, L"config_hardware")) - return 1; - if (!_tcscmp (option, L"config_host")) - return 1; - if (cfgfile_string (option, value, L"config_hardware_path", p->config_hardware_path, sizeof p->config_hardware_path / sizeof (TCHAR))) - return 1; - if (cfgfile_string (option, value, L"config_host_path", p->config_host_path, sizeof p->config_host_path / sizeof (TCHAR))) - return 1; - if (type == 0 || (type & CONFIG_TYPE_HARDWARE)) { - if (cfgfile_parse_hardware (p, option, value)) - return 1; - } - if (type == 0 || (type & CONFIG_TYPE_HOST)) { - if (cfgfile_parse_host (p, option, value)) - return 1; - } - if (type > 0) - return 1; - return 0; + if (!_tcscmp (option, L"config_hardware")) + return 1; + if (!_tcscmp (option, L"config_host")) + return 1; + if (cfgfile_string (option, value, L"config_hardware_path", p->config_hardware_path, sizeof p->config_hardware_path / sizeof (TCHAR))) + return 1; + if (cfgfile_string (option, value, L"config_host_path", p->config_host_path, sizeof p->config_host_path / sizeof (TCHAR))) + return 1; + if (type == 0 || (type & CONFIG_TYPE_HARDWARE)) { + if (cfgfile_parse_hardware (p, option, value)) + return 1; + } + if (type == 0 || (type & CONFIG_TYPE_HOST)) { + if (cfgfile_parse_host (p, option, value)) + return 1; + } + if (type > 0) + return 1; + return 0; } static int isutf8ext (TCHAR *s) { - if (_tcslen (s) > _tcslen (UTF8NAME) && !_tcscmp (s + _tcslen (s) - _tcslen (UTF8NAME), UTF8NAME)) { - s[_tcslen (s) - _tcslen (UTF8NAME)] = 0; - return 1; - } - return 0; + if (_tcslen (s) > _tcslen (UTF8NAME) && !_tcscmp (s + _tcslen (s) - _tcslen (UTF8NAME), UTF8NAME)) { + s[_tcslen (s) - _tcslen (UTF8NAME)] = 0; + return 1; + } + return 0; } static int cfgfile_separate_linea (char *line, TCHAR *line1b, TCHAR *line2b) { - char *line1, *line2; - int i; + char *line1, *line2; + int i; - line1 = line; - line2 = strchr (line, '='); - if (! line2) { - TCHAR *s = au (line1); - write_log (L"CFGFILE: linea was incomplete with only %s\n", s); - xfree (s); - return 0; - } - *line2++ = '\0'; - - /* Get rid of whitespace. */ - i = strlen (line2); - while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' ' - || line2[i - 1] == '\r' || line2[i - 1] == '\n')) - line2[--i] = '\0'; - line2 += strspn (line2, "\t \r\n"); - - i = strlen (line); - while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' ' - || line[i - 1] == '\r' || line[i - 1] == '\n')) - line[--i] = '\0'; - line += strspn (line, "\t \r\n"); - au_copy (line1b, MAX_DPATH, line); - if (isutf8ext (line1b)) { - TCHAR *s = utf8u (line2); - _tcscpy (line2b, s); - xfree (s); - } else { - au_copy (line2b, MAX_DPATH, line2); - } - return 1; + line1 = line; + line2 = strchr (line, '='); + if (! line2) { + TCHAR *s = au (line1); + write_log (L"CFGFILE: linea was incomplete with only %s\n", s); + xfree (s); + return 0; + } + *line2++ = '\0'; + + /* Get rid of whitespace. */ + i = strlen (line2); + while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' ' + || line2[i - 1] == '\r' || line2[i - 1] == '\n')) + line2[--i] = '\0'; + line2 += strspn (line2, "\t \r\n"); + + i = strlen (line); + while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' ' + || line[i - 1] == '\r' || line[i - 1] == '\n')) + line[--i] = '\0'; + line += strspn (line, "\t \r\n"); + au_copy (line1b, MAX_DPATH, line); + if (isutf8ext (line1b)) { + TCHAR *s = utf8u (line2); + _tcscpy (line2b, s); + xfree (s); + } else { + au_copy (line2b, MAX_DPATH, line2); + } + return 1; } static int cfgfile_separate_line (TCHAR *line, TCHAR *line1b, TCHAR *line2b) { - TCHAR *line1, *line2; - int i; + TCHAR *line1, *line2; + int i; - line1 = line; - line2 = _tcschr (line, '='); - if (! line2) { - write_log (L"CFGFILE: line was incomplete with only %s\n", line1); - return 0; - } - *line2++ = '\0'; - - /* Get rid of whitespace. */ - i = _tcslen (line2); - while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' ' - || line2[i - 1] == '\r' || line2[i - 1] == '\n')) - line2[--i] = '\0'; - line2 += _tcsspn (line2, L"\t \r\n"); - _tcscpy (line2b, line2); - i = _tcslen (line); - while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' ' - || line[i - 1] == '\r' || line[i - 1] == '\n')) - line[--i] = '\0'; - line += _tcsspn (line, L"\t \r\n"); - _tcscpy (line1b, line); - - if (line2b[0] == '"' || line2b[0] == '\"') { - TCHAR c = line2b[0]; - int i = 0; - memmove (line2b, line2b + 1, (_tcslen (line2b) + 1) * sizeof (TCHAR)); - while (line2b[i] != 0 && line2b[i] != c) - i++; - line2b[i] = 0; - } + line1 = line; + line2 = _tcschr (line, '='); + if (! line2) { + write_log (L"CFGFILE: line was incomplete with only %s\n", line1); + return 0; + } + *line2++ = '\0'; + + /* Get rid of whitespace. */ + i = _tcslen (line2); + while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' ' + || line2[i - 1] == '\r' || line2[i - 1] == '\n')) + line2[--i] = '\0'; + line2 += _tcsspn (line2, L"\t \r\n"); + _tcscpy (line2b, line2); + i = _tcslen (line); + while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' ' + || line[i - 1] == '\r' || line[i - 1] == '\n')) + line[--i] = '\0'; + line += _tcsspn (line, L"\t \r\n"); + _tcscpy (line1b, line); + + if (line2b[0] == '"' || line2b[0] == '\"') { + TCHAR c = line2b[0]; + int i = 0; + memmove (line2b, line2b + 1, (_tcslen (line2b) + 1) * sizeof (TCHAR)); + while (line2b[i] != 0 && line2b[i] != c) + i++; + line2b[i] = 0; + } - if (isutf8ext (line1b)) - return 0; - return 1; + if (isutf8ext (line1b)) + return 0; + return 1; } static int isobsolete (TCHAR *s) { - int i = 0; - while (obsolete[i]) { - if (!strcasecmp (s, obsolete[i])) { - write_log (L"obsolete config entry '%s'\n", s); - return 1; + int i = 0; + while (obsolete[i]) { + if (!strcasecmp (s, obsolete[i])) { + write_log (L"obsolete config entry '%s'\n", s); + return 1; + } + i++; } - i++; - } - if (_tcslen (s) > 2 && !_tcsncmp (s, L"w.", 2)) - return 1; - if (_tcslen (s) >= 10 && !_tcsncmp (s, L"gfx_opengl", 10)) { - write_log (L"obsolete config entry '%s\n", s); - return 1; - } - if (_tcslen (s) >= 6 && !_tcsncmp (s, L"gfx_3d", 6)) { - write_log (L"obsolete config entry '%s\n", s); - return 1; - } - return 0; + if (_tcslen (s) > 2 && !_tcsncmp (s, L"w.", 2)) + return 1; + if (_tcslen (s) >= 10 && !_tcsncmp (s, L"gfx_opengl", 10)) { + write_log (L"obsolete config entry '%s\n", s); + return 1; + } + if (_tcslen (s) >= 6 && !_tcsncmp (s, L"gfx_3d", 6)) { + write_log (L"obsolete config entry '%s\n", s); + return 1; + } + return 0; } static void cfgfile_parse_separated_line (struct uae_prefs *p, TCHAR *line1b, TCHAR *line2b, int type) { - TCHAR line3b[CONFIG_BLEN], line4b[CONFIG_BLEN]; - struct strlist *sl; - int ret; + TCHAR line3b[CONFIG_BLEN], line4b[CONFIG_BLEN]; + struct strlist *sl; + int ret; - _tcscpy (line3b, line1b); - _tcscpy (line4b, line2b); - ret = cfgfile_parse_option (p, line1b, line2b, type); - if (!isobsolete (line3b)) { - for (sl = p->all_lines; sl; sl = sl->next) { - if (sl->option && !strcasecmp (line1b, sl->option)) break; - } - if (!sl) { - struct strlist *u = xcalloc (sizeof (struct strlist), 1); - u->option = my_strdup (line3b); - u->value = my_strdup (line4b); - u->next = p->all_lines; - p->all_lines = u; - if (!ret) { - u->unknown = 1; - write_log (L"unknown config entry: '%s=%s'\n", u->option, u->value); - } + _tcscpy (line3b, line1b); + _tcscpy (line4b, line2b); + ret = cfgfile_parse_option (p, line1b, line2b, type); + if (!isobsolete (line3b)) { + for (sl = p->all_lines; sl; sl = sl->next) { + if (sl->option && !strcasecmp (line1b, sl->option)) break; + } + if (!sl) { + struct strlist *u = xcalloc (sizeof (struct strlist), 1); + u->option = my_strdup (line3b); + u->value = my_strdup (line4b); + u->next = p->all_lines; + p->all_lines = u; + if (!ret) { + u->unknown = 1; + write_log (L"unknown config entry: '%s=%s'\n", u->option, u->value); + } + } } - } } void cfgfile_parse_line (struct uae_prefs *p, TCHAR *line, int type) { - TCHAR line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; + TCHAR line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; - if (!cfgfile_separate_line (line, line1b, line2b)) - return; - cfgfile_parse_separated_line (p, line1b, line2b, type); + if (!cfgfile_separate_line (line, line1b, line2b)) + return; + cfgfile_parse_separated_line (p, line1b, line2b, type); } static void subst (TCHAR *p, TCHAR *f, int n) { - TCHAR *str = cfgfile_subst_path (UNEXPANDED, p, f); - _tcsncpy (f, str, n - 1); - f[n - 1] = '\0'; - free (str); + TCHAR *str = cfgfile_subst_path (UNEXPANDED, p, f); + _tcsncpy (f, str, n - 1); + f[n - 1] = '\0'; + free (str); } static char *cfg_fgets (char *line, int max, struct zfile *fh) { #ifdef SINGLEFILE - extern TCHAR singlefile_config[]; - static TCHAR *sfile_ptr; - TCHAR *p; + extern TCHAR singlefile_config[]; + static TCHAR *sfile_ptr; + TCHAR *p; #endif - if (fh) - return zfile_fgetsa (line, max, fh); + if (fh) + return zfile_fgetsa (line, max, fh); #ifdef SINGLEFILE - if (sfile_ptr == 0) { - sfile_ptr = singlefile_config; - if (*sfile_ptr) { - write_log (L"singlefile config found\n"); - while (*sfile_ptr++); - } - } - if (*sfile_ptr == 0) { - sfile_ptr = singlefile_config; - return 0; - } - p = sfile_ptr; - while (*p != 13 && *p != 10 && *p != 0) p++; - memset (line, 0, max); - memcpy (line, sfile_ptr, (p - sfile_ptr) * sizeof (TCHAR)); - sfile_ptr = p + 1; - if (*sfile_ptr == 13) - sfile_ptr++; - if (*sfile_ptr == 10) - sfile_ptr++; - return line; + if (sfile_ptr == 0) { + sfile_ptr = singlefile_config; + if (*sfile_ptr) { + write_log (L"singlefile config found\n"); + while (*sfile_ptr++); + } + } + if (*sfile_ptr == 0) { + sfile_ptr = singlefile_config; + return 0; + } + p = sfile_ptr; + while (*p != 13 && *p != 10 && *p != 0) p++; + memset (line, 0, max); + memcpy (line, sfile_ptr, (p - sfile_ptr) * sizeof (TCHAR)); + sfile_ptr = p + 1; + if (*sfile_ptr == 13) + sfile_ptr++; + if (*sfile_ptr == 10) + sfile_ptr++; + return line; #endif - return 0; + return 0; } static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, int real, int *type) { - int i; - struct zfile *fh; - char linea[CONFIG_BLEN]; - TCHAR line[CONFIG_BLEN], line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; - struct strlist *sl; - int type1 = 0, type2 = 0, askedtype = 0; - - if (type) { - askedtype = *type; - *type = 0; - } - if (real) { - p->config_version = 0; - config_newfilesystem = 0; - reset_inputdevice_config (p); - } - - fh = zfile_fopen (filename, L"r", ZFD_NORMAL); + int i; + struct zfile *fh; + char linea[CONFIG_BLEN]; + TCHAR line[CONFIG_BLEN], line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; + struct strlist *sl; + int type1 = 0, type2 = 0, askedtype = 0; + + if (type) { + askedtype = *type; + *type = 0; + } + if (real) { + p->config_version = 0; + config_newfilesystem = 0; + reset_inputdevice_config (p); + } + + fh = zfile_fopen (filename, L"r", ZFD_NORMAL); #ifndef SINGLEFILE - if (! fh) - return 0; + if (! fh) + return 0; #endif - while (cfg_fgets (linea, sizeof (linea), fh) != 0) { - trimwsa (linea); - if (strlen (linea) > 0) { - if (linea[0] == '#' || linea[0] == ';') - continue; - if (!cfgfile_separate_linea (linea, line1b, line2b)) - continue; - type1 = type2 = 0; - if (cfgfile_yesno (line1b, line2b, L"config_hardware", &type1) || - cfgfile_yesno (line1b, line2b, L"config_host", &type2)) { - if (type1 && type) - *type |= CONFIG_TYPE_HARDWARE; - if (type2 && type) - *type |= CONFIG_TYPE_HOST; - continue; - } - if (real) { - cfgfile_parse_separated_line (p, line1b, line2b, askedtype); - } else { - cfgfile_string (line1b, line2b, L"config_description", p->description, sizeof p->description / sizeof (TCHAR)); - cfgfile_string (line1b, line2b, L"config_hardware_path", p->config_hardware_path, sizeof p->config_hardware_path / sizeof (TCHAR)); - cfgfile_string (line1b, line2b, L"config_host_path", p->config_host_path, sizeof p->config_host_path / sizeof (TCHAR)); - } - } - } - - if (type && *type == 0) - *type = CONFIG_TYPE_HARDWARE | CONFIG_TYPE_HOST; - zfile_fclose (fh); - - if (!real) - return 1; + while (cfg_fgets (linea, sizeof (linea), fh) != 0) { + trimwsa (linea); + if (strlen (linea) > 0) { + if (linea[0] == '#' || linea[0] == ';') + continue; + if (!cfgfile_separate_linea (linea, line1b, line2b)) + continue; + type1 = type2 = 0; + if (cfgfile_yesno (line1b, line2b, L"config_hardware", &type1) || + cfgfile_yesno (line1b, line2b, L"config_host", &type2)) { + if (type1 && type) + *type |= CONFIG_TYPE_HARDWARE; + if (type2 && type) + *type |= CONFIG_TYPE_HOST; + continue; + } + if (real) { + cfgfile_parse_separated_line (p, line1b, line2b, askedtype); + } else { + cfgfile_string (line1b, line2b, L"config_description", p->description, sizeof p->description / sizeof (TCHAR)); + cfgfile_string (line1b, line2b, L"config_hardware_path", p->config_hardware_path, sizeof p->config_hardware_path / sizeof (TCHAR)); + cfgfile_string (line1b, line2b, L"config_host_path", p->config_host_path, sizeof p->config_host_path / sizeof (TCHAR)); + } + } + } - for (sl = temp_lines; sl; sl = sl->next) { - _stprintf (line, L"%s=%s", sl->option, sl->value); - cfgfile_parse_line (p, line, 0); - } + if (type && *type == 0) + *type = CONFIG_TYPE_HARDWARE | CONFIG_TYPE_HOST; + zfile_fclose (fh); - for (i = 0; i < 4; i++) - subst (p->path_floppy, p->df[i], sizeof p->df[i] / sizeof (TCHAR)); - subst (p->path_rom, p->romfile, sizeof p->romfile / sizeof (TCHAR)); - subst (p->path_rom, p->romextfile, sizeof p->romextfile / sizeof (TCHAR)); + if (!real) + return 1; + + for (sl = temp_lines; sl; sl = sl->next) { + _stprintf (line, L"%s=%s", sl->option, sl->value); + cfgfile_parse_line (p, line, 0); + } + + for (i = 0; i < 4; i++) + subst (p->path_floppy, p->df[i], sizeof p->df[i] / sizeof (TCHAR)); + subst (p->path_rom, p->romfile, sizeof p->romfile / sizeof (TCHAR)); + subst (p->path_rom, p->romextfile, sizeof p->romextfile / sizeof (TCHAR)); - return 1; + return 1; } int cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int *type, int ignorelink, int userconfig) { - int v; - TCHAR tmp[MAX_DPATH]; - int type2; - static int recursive; - - if (recursive > 1) - return 0; - recursive++; - write_log (L"load config '%s':%d\n", filename, type ? *type : -1); - v = cfgfile_load_2 (p, filename, 1, type); - if (!v) { - write_log (L"load failed\n"); - goto end; - } - if (userconfig) - target_addtorecent (filename, 0); - if (!ignorelink) { - if (p->config_hardware_path[0]) { - fetch_configurationpath (tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcsncat (tmp, p->config_hardware_path, sizeof (tmp) / sizeof (TCHAR)); - type2 = CONFIG_TYPE_HARDWARE; - cfgfile_load (p, tmp, &type2, 1, 0); - } - if (p->config_host_path[0]) { - fetch_configurationpath (tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcsncat (tmp, p->config_host_path, sizeof (tmp) / sizeof (TCHAR)); - type2 = CONFIG_TYPE_HOST; - cfgfile_load (p, tmp, &type2, 1, 0); - } - } + int v; + TCHAR tmp[MAX_DPATH]; + int type2; + static int recursive; + + if (recursive > 1) + return 0; + recursive++; + write_log (L"load config '%s':%d\n", filename, type ? *type : -1); + v = cfgfile_load_2 (p, filename, 1, type); + if (!v) { + write_log (L"load failed\n"); + goto end; + } + if (userconfig) + target_addtorecent (filename, 0); + if (!ignorelink) { + if (p->config_hardware_path[0]) { + fetch_configurationpath (tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcsncat (tmp, p->config_hardware_path, sizeof (tmp) / sizeof (TCHAR)); + type2 = CONFIG_TYPE_HARDWARE; + cfgfile_load (p, tmp, &type2, 1, 0); + } + if (p->config_host_path[0]) { + fetch_configurationpath (tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcsncat (tmp, p->config_host_path, sizeof (tmp) / sizeof (TCHAR)); + type2 = CONFIG_TYPE_HOST; + cfgfile_load (p, tmp, &type2, 1, 0); + } + } end: - recursive--; - fixup_prefs (p); - return v; + recursive--; + fixup_prefs (p); + return v; } void cfgfile_backup (const TCHAR *path) { - TCHAR dpath[MAX_DPATH]; + TCHAR dpath[MAX_DPATH]; - fetch_configurationpath (dpath, sizeof (dpath) / sizeof (TCHAR)); - _tcscat (dpath, L"configuration.backup"); - my_unlink (dpath); - my_rename (path, dpath); + fetch_configurationpath (dpath, sizeof (dpath) / sizeof (TCHAR)); + _tcscat (dpath, L"configuration.backup"); + my_unlink (dpath); + my_rename (path, dpath); } int cfgfile_save (struct uae_prefs *p, const TCHAR *filename, int type) { - struct zfile *fh; + struct zfile *fh; - cfgfile_backup (filename); - fh = zfile_fopen (filename, unicode_config ? L"w, ccs=UTF-8" : L"w", ZFD_NORMAL); - if (! fh) - return 0; + cfgfile_backup (filename); + fh = zfile_fopen (filename, unicode_config ? L"w, ccs=UTF-8" : L"w", ZFD_NORMAL); + if (! fh) + return 0; - if (!type) - type = CONFIG_TYPE_HARDWARE | CONFIG_TYPE_HOST; - cfgfile_save_options (fh, p, type); - zfile_fclose (fh); - return 1; + if (!type) + type = CONFIG_TYPE_HARDWARE | CONFIG_TYPE_HOST; + cfgfile_save_options (fh, p, type); + zfile_fclose (fh); + return 1; } int cfgfile_get_description (const TCHAR *filename, TCHAR *description, TCHAR *hostlink, TCHAR *hardwarelink, int *type) { - int result = 0; - struct uae_prefs *p = xmalloc (sizeof (struct uae_prefs)); - - p->description[0] = 0; - p->config_host_path[0] = 0; - p->config_hardware_path[0] = 0; - if (cfgfile_load_2 (p, filename, 0, type)) { - result = 1; - if (description) - _tcscpy (description, p->description); - if (hostlink) - _tcscpy (hostlink, p->config_host_path); - if (hardwarelink) - _tcscpy (hardwarelink, p->config_hardware_path); - } - xfree (p); - return result; + int result = 0; + struct uae_prefs *p = xmalloc (sizeof (struct uae_prefs)); + + p->description[0] = 0; + p->config_host_path[0] = 0; + p->config_hardware_path[0] = 0; + if (cfgfile_load_2 (p, filename, 0, type)) { + result = 1; + if (description) + _tcscpy (description, p->description); + if (hostlink) + _tcscpy (hostlink, p->config_host_path); + if (hardwarelink) + _tcscpy (hardwarelink, p->config_hardware_path); + } + xfree (p); + return result; } int cfgfile_configuration_change (int v) { - static int mode; - if (v >= 0) - mode = v; - return mode; + static int mode; + if (v >= 0) + mode = v; + return mode; } void cfgfile_show_usage (void) { - int i; - write_log (L"UAE Configuration Help:\n" \ - L"=======================\n"); - for (i = 0; i < sizeof opttable / sizeof *opttable; i++) - write_log (L"%s: %s\n", opttable[i].config_label, opttable[i].config_help); + int i; + write_log (L"UAE Configuration Help:\n" \ + L"=======================\n"); + for (i = 0; i < sizeof opttable / sizeof *opttable; i++) + write_log (L"%s: %s\n", opttable[i].config_label, opttable[i].config_help); } /* This implements the old commandline option parsing. I've re-added this - because the new way of doing things is painful for me (it requires me - to type a couple hundred characters when invoking UAE). The following - is far less annoying to use. */ +because the new way of doing things is painful for me (it requires me +to type a couple hundred characters when invoking UAE). The following +is far less annoying to use. */ static void parse_gfx_specs (struct uae_prefs *p, const TCHAR *spec) { - TCHAR *x0 = my_strdup (spec); - TCHAR *x1, *x2; - - x1 = _tcschr (x0, ':'); - if (x1 == 0) - goto argh; - x2 = _tcschr (x1+1, ':'); - if (x2 == 0) - goto argh; - *x1++ = 0; *x2++ = 0; - - p->gfx_size_win.width = p->gfx_size_fs.width = _tstoi (x0); - p->gfx_size_win.height = p->gfx_size_fs.height = _tstoi (x1); - p->gfx_resolution = _tcschr (x2, 'l') != 0 ? 1 : 0; - p->gfx_xcenter = _tcschr (x2, 'x') != 0 ? 1 : _tcschr (x2, 'X') != 0 ? 2 : 0; - p->gfx_ycenter = _tcschr (x2, 'y') != 0 ? 1 : _tcschr (x2, 'Y') != 0 ? 2 : 0; - p->gfx_linedbl = _tcschr (x2, 'd') != 0; - p->gfx_linedbl += 2 * (_tcschr (x2, 'D') != 0); - p->gfx_afullscreen = _tcschr (x2, 'a') != 0; - p->gfx_pfullscreen = _tcschr (x2, 'p') != 0; - - if (p->gfx_linedbl == 3) { - write_log (L"You can't use both 'd' and 'D' modifiers in the display mode specification.\n"); - } - - free (x0); - return; - - argh: - write_log (L"Bad display mode specification.\n"); - write_log (L"The format to use is: \"width:height:modifiers\"\n"); - write_log (L"Type \"uae -h\" for detailed help.\n"); - free (x0); + TCHAR *x0 = my_strdup (spec); + TCHAR *x1, *x2; + + x1 = _tcschr (x0, ':'); + if (x1 == 0) + goto argh; + x2 = _tcschr (x1+1, ':'); + if (x2 == 0) + goto argh; + *x1++ = 0; *x2++ = 0; + + p->gfx_size_win.width = p->gfx_size_fs.width = _tstoi (x0); + p->gfx_size_win.height = p->gfx_size_fs.height = _tstoi (x1); + p->gfx_resolution = _tcschr (x2, 'l') != 0 ? 1 : 0; + p->gfx_xcenter = _tcschr (x2, 'x') != 0 ? 1 : _tcschr (x2, 'X') != 0 ? 2 : 0; + p->gfx_ycenter = _tcschr (x2, 'y') != 0 ? 1 : _tcschr (x2, 'Y') != 0 ? 2 : 0; + p->gfx_linedbl = _tcschr (x2, 'd') != 0; + p->gfx_linedbl += 2 * (_tcschr (x2, 'D') != 0); + p->gfx_afullscreen = _tcschr (x2, 'a') != 0; + p->gfx_pfullscreen = _tcschr (x2, 'p') != 0; + + if (p->gfx_linedbl == 3) { + write_log (L"You can't use both 'd' and 'D' modifiers in the display mode specification.\n"); + } + + free (x0); + return; + +argh: + write_log (L"Bad display mode specification.\n"); + write_log (L"The format to use is: \"width:height:modifiers\"\n"); + write_log (L"Type \"uae -h\" for detailed help.\n"); + free (x0); } static void parse_sound_spec (struct uae_prefs *p, const TCHAR *spec) { - TCHAR *x0 = my_strdup (spec); - TCHAR *x1, *x2 = NULL, *x3 = NULL, *x4 = NULL, *x5 = NULL; - - x1 = _tcschr (x0, ':'); - if (x1 != NULL) { - *x1++ = '\0'; - x2 = _tcschr (x1 + 1, ':'); - if (x2 != NULL) { - *x2++ = '\0'; - x3 = _tcschr (x2 + 1, ':'); - if (x3 != NULL) { - *x3++ = '\0'; - x4 = _tcschr (x3 + 1, ':'); - if (x4 != NULL) { - *x4++ = '\0'; - x5 = _tcschr (x4 + 1, ':'); + TCHAR *x0 = my_strdup (spec); + TCHAR *x1, *x2 = NULL, *x3 = NULL, *x4 = NULL, *x5 = NULL; + + x1 = _tcschr (x0, ':'); + if (x1 != NULL) { + *x1++ = '\0'; + x2 = _tcschr (x1 + 1, ':'); + if (x2 != NULL) { + *x2++ = '\0'; + x3 = _tcschr (x2 + 1, ':'); + if (x3 != NULL) { + *x3++ = '\0'; + x4 = _tcschr (x3 + 1, ':'); + if (x4 != NULL) { + *x4++ = '\0'; + x5 = _tcschr (x4 + 1, ':'); + } + } } - } - } - } - p->produce_sound = _tstoi (x0); - if (x1) { - p->sound_stereo_separation = 0; - if (*x1 == 'S') { - p->sound_stereo = SND_STEREO; - p->sound_stereo_separation = 7; - } else if (*x1 == 's') - p->sound_stereo = SND_STEREO; - else - p->sound_stereo = SND_MONO; - } - if (x3) - p->sound_freq = _tstoi (x3); - if (x4) - p->sound_maxbsiz = _tstoi (x4); - free (x0); + } + p->produce_sound = _tstoi (x0); + if (x1) { + p->sound_stereo_separation = 0; + if (*x1 == 'S') { + p->sound_stereo = SND_STEREO; + p->sound_stereo_separation = 7; + } else if (*x1 == 's') + p->sound_stereo = SND_STEREO; + else + p->sound_stereo = SND_MONO; + } + if (x3) + p->sound_freq = _tstoi (x3); + if (x4) + p->sound_maxbsiz = _tstoi (x4); + free (x0); } static void parse_joy_spec (struct uae_prefs *p, const TCHAR *spec) { - int v0 = 2, v1 = 0; - if (_tcslen(spec) != 2) - goto bad; - - switch (spec[0]) { - case '0': v0 = JSEM_JOYS; break; - case '1': v0 = JSEM_JOYS + 1; break; - case 'M': case 'm': v0 = JSEM_MICE; break; - case 'A': case 'a': v0 = JSEM_KBDLAYOUT; break; - case 'B': case 'b': v0 = JSEM_KBDLAYOUT + 1; break; - case 'C': case 'c': v0 = JSEM_KBDLAYOUT + 2; break; - default: goto bad; - } - - switch (spec[1]) { - case '0': v1 = JSEM_JOYS; break; - case '1': v1 = JSEM_JOYS + 1; break; - case 'M': case 'm': v1 = JSEM_MICE; break; - case 'A': case 'a': v1 = JSEM_KBDLAYOUT; break; - case 'B': case 'b': v1 = JSEM_KBDLAYOUT + 1; break; - case 'C': case 'c': v1 = JSEM_KBDLAYOUT + 2; break; - default: goto bad; - } - if (v0 == v1) - goto bad; - /* Let's scare Pascal programmers */ - if (0) + int v0 = 2, v1 = 0; + if (_tcslen(spec) != 2) + goto bad; + + switch (spec[0]) { + case '0': v0 = JSEM_JOYS; break; + case '1': v0 = JSEM_JOYS + 1; break; + case 'M': case 'm': v0 = JSEM_MICE; break; + case 'A': case 'a': v0 = JSEM_KBDLAYOUT; break; + case 'B': case 'b': v0 = JSEM_KBDLAYOUT + 1; break; + case 'C': case 'c': v0 = JSEM_KBDLAYOUT + 2; break; + default: goto bad; + } + + switch (spec[1]) { + case '0': v1 = JSEM_JOYS; break; + case '1': v1 = JSEM_JOYS + 1; break; + case 'M': case 'm': v1 = JSEM_MICE; break; + case 'A': case 'a': v1 = JSEM_KBDLAYOUT; break; + case 'B': case 'b': v1 = JSEM_KBDLAYOUT + 1; break; + case 'C': case 'c': v1 = JSEM_KBDLAYOUT + 2; break; + default: goto bad; + } + if (v0 == v1) + goto bad; + /* Let's scare Pascal programmers */ + if (0) bad: - write_log (L"Bad joystick mode specification. Use -J xy, where x and y\n" - L"can be 0 for joystick 0, 1 for joystick 1, M for mouse, and\n" - L"a, b or c for different keyboard settings.\n"); + write_log (L"Bad joystick mode specification. Use -J xy, where x and y\n" + L"can be 0 for joystick 0, 1 for joystick 1, M for mouse, and\n" + L"a, b or c for different keyboard settings.\n"); - p->jports[0].id = v0; - p->jports[1].id = v1; + p->jports[0].id = v0; + p->jports[1].id = v1; } static void parse_filesys_spec (struct uae_prefs *p, int readonly, const TCHAR *spec) { - TCHAR buf[256]; - TCHAR *s2; + TCHAR buf[256]; + TCHAR *s2; - _tcsncpy (buf, spec, 255); buf[255] = 0; - s2 = _tcschr (buf, ':'); - if (s2) { - *s2++ = '\0'; + _tcsncpy (buf, spec, 255); buf[255] = 0; + s2 = _tcschr (buf, ':'); + if (s2) { + *s2++ = '\0'; #ifdef __DOS__ - { - TCHAR *tmp; + { + TCHAR *tmp; - while ((tmp = _tcschr (s2, '\\'))) - *tmp = '/'; - } + while ((tmp = _tcschr (s2, '\\'))) + *tmp = '/'; + } #endif #ifdef FILESYS - add_filesys_config (p, -1, NULL, buf, s2, readonly, 0, 0, 0, 0, 0, 0, 0, 0); + add_filesys_config (p, -1, NULL, buf, s2, readonly, 0, 0, 0, 0, 0, 0, 0, 0); #endif - } else { - write_log (L"Usage: [-m | -M] VOLNAME:mount_point\n"); - } + } else { + write_log (L"Usage: [-m | -M] VOLNAME:mount_point\n"); + } } static void parse_hardfile_spec (struct uae_prefs *p, const TCHAR *spec) { - TCHAR *x0 = my_strdup (spec); - TCHAR *x1, *x2, *x3, *x4; - - x1 = _tcschr (x0, ':'); - if (x1 == NULL) - goto argh; - *x1++ = '\0'; - x2 = _tcschr (x1 + 1, ':'); - if (x2 == NULL) - goto argh; - *x2++ = '\0'; - x3 = _tcschr (x2 + 1, ':'); - if (x3 == NULL) - goto argh; - *x3++ = '\0'; - x4 = _tcschr (x3 + 1, ':'); - if (x4 == NULL) - goto argh; - *x4++ = '\0'; + TCHAR *x0 = my_strdup (spec); + TCHAR *x1, *x2, *x3, *x4; + + x1 = _tcschr (x0, ':'); + if (x1 == NULL) + goto argh; + *x1++ = '\0'; + x2 = _tcschr (x1 + 1, ':'); + if (x2 == NULL) + goto argh; + *x2++ = '\0'; + x3 = _tcschr (x2 + 1, ':'); + if (x3 == NULL) + goto argh; + *x3++ = '\0'; + x4 = _tcschr (x3 + 1, ':'); + if (x4 == NULL) + goto argh; + *x4++ = '\0'; #ifdef FILESYS - add_filesys_config (p, -1, NULL, NULL, x4, 0, _tstoi (x0), _tstoi (x1), _tstoi (x2), _tstoi (x3), 0, 0, 0, 0); + add_filesys_config (p, -1, NULL, NULL, x4, 0, _tstoi (x0), _tstoi (x1), _tstoi (x2), _tstoi (x3), 0, 0, 0, 0); #endif - free (x0); - return; + free (x0); + return; - argh: - free (x0); - write_log (L"Bad hardfile parameter specified - type \"uae -h\" for help.\n"); - return; +argh: + free (x0); + write_log (L"Bad hardfile parameter specified - type \"uae -h\" for help.\n"); + return; } static void parse_cpu_specs (struct uae_prefs *p, const TCHAR *spec) { - if (*spec < '0' || *spec > '4') { - write_log (L"CPU parameter string must begin with '0', '1', '2', '3' or '4'.\n"); - return; - } - - p->cpu_model = (*spec++) * 10 + 68000; - p->address_space_24 = p->cpu_model < 68020; - p->cpu_compatible = 0; - while (*spec != '\0') { - switch (*spec) { - case 'a': - if (p->cpu_model < 68020) - write_log (L"In 68000/68010 emulation, the address space is always 24 bit.\n"); - else if (p->cpu_model >= 68040) - write_log (L"In 68040/060 emulation, the address space is always 32 bit.\n"); - else - p->address_space_24 = 1; - break; - case 'c': - if (p->cpu_model != 68000) - write_log (L"The more compatible CPU emulation is only available for 68000\n" - L"emulation, not for 68010 upwards.\n"); - else - p->cpu_compatible = 1; - break; - default: - write_log (L"Bad CPU parameter specified - type \"uae -h\" for help.\n"); - break; - } - spec++; - } + if (*spec < '0' || *spec > '4') { + write_log (L"CPU parameter string must begin with '0', '1', '2', '3' or '4'.\n"); + return; + } + + p->cpu_model = (*spec++) * 10 + 68000; + p->address_space_24 = p->cpu_model < 68020; + p->cpu_compatible = 0; + while (*spec != '\0') { + switch (*spec) { + case 'a': + if (p->cpu_model < 68020) + write_log (L"In 68000/68010 emulation, the address space is always 24 bit.\n"); + else if (p->cpu_model >= 68040) + write_log (L"In 68040/060 emulation, the address space is always 32 bit.\n"); + else + p->address_space_24 = 1; + break; + case 'c': + if (p->cpu_model != 68000) + write_log (L"The more compatible CPU emulation is only available for 68000\n" + L"emulation, not for 68010 upwards.\n"); + else + p->cpu_compatible = 1; + break; + default: + write_log (L"Bad CPU parameter specified - type \"uae -h\" for help.\n"); + break; + } + spec++; + } } /* Returns the number of args used up (0 or 1). */ int parse_cmdline_option (struct uae_prefs *p, TCHAR c, const TCHAR *arg) { - struct strlist *u = xcalloc (sizeof (struct strlist), 1); - const TCHAR arg_required[] = L"0123rKpImWSAJwNCZUFcblOdHRv"; + struct strlist *u = xcalloc (sizeof (struct strlist), 1); + const TCHAR arg_required[] = L"0123rKpImWSAJwNCZUFcblOdHRv"; - if (_tcschr (arg_required, c) && ! arg) { - write_log (L"Missing argument for option `-%c'!\n", c); - return 0; - } - - u->option = malloc (2 * sizeof (TCHAR)); - u->option[0] = c; - u->option[1] = 0; - u->value = my_strdup (arg); - u->next = p->all_lines; - p->all_lines = u; - - switch (c) { - case 'h': usage (); exit (0); - - case '0': _tcsncpy (p->df[0], arg, 255); p->df[0][255] = 0; break; - case '1': _tcsncpy (p->df[1], arg, 255); p->df[1][255] = 0; break; - case '2': _tcsncpy (p->df[2], arg, 255); p->df[2][255] = 0; break; - case '3': _tcsncpy (p->df[3], arg, 255); p->df[3][255] = 0; break; - case 'r': _tcsncpy (p->romfile, arg, 255); p->romfile[255] = 0; break; - case 'K': _tcsncpy (p->romextfile, arg, 255); p->romextfile[255] = 0; break; - case 'p': _tcsncpy (p->prtname, arg, 255); p->prtname[255] = 0; break; - /* case 'I': _tcsncpy (p->sername, arg, 255); p->sername[255] = 0; currprefs.use_serial = 1; break; */ - case 'm': case 'M': parse_filesys_spec (p, c == 'M', arg); break; - case 'W': parse_hardfile_spec (p, arg); break; - case 'S': parse_sound_spec (p, arg); break; - case 'R': p->gfx_framerate = _tstoi (arg); break; - case 'x': p->no_xhair = 1; break; - case 'i': p->illegal_mem = 1; break; - case 'J': parse_joy_spec (p, arg); break; - - case 't': p->test_drawing_speed = 1; break; + if (_tcschr (arg_required, c) && ! arg) { + write_log (L"Missing argument for option `-%c'!\n", c); + return 0; + } + + u->option = xmalloc (2 * sizeof (TCHAR)); + u->option[0] = c; + u->option[1] = 0; + u->value = my_strdup (arg); + u->next = p->all_lines; + p->all_lines = u; + + switch (c) { + case 'h': usage (); exit (0); + + case '0': _tcsncpy (p->df[0], arg, 255); p->df[0][255] = 0; break; + case '1': _tcsncpy (p->df[1], arg, 255); p->df[1][255] = 0; break; + case '2': _tcsncpy (p->df[2], arg, 255); p->df[2][255] = 0; break; + case '3': _tcsncpy (p->df[3], arg, 255); p->df[3][255] = 0; break; + case 'r': _tcsncpy (p->romfile, arg, 255); p->romfile[255] = 0; break; + case 'K': _tcsncpy (p->romextfile, arg, 255); p->romextfile[255] = 0; break; + case 'p': _tcsncpy (p->prtname, arg, 255); p->prtname[255] = 0; break; + /* case 'I': _tcsncpy (p->sername, arg, 255); p->sername[255] = 0; currprefs.use_serial = 1; break; */ + case 'm': case 'M': parse_filesys_spec (p, c == 'M', arg); break; + case 'W': parse_hardfile_spec (p, arg); break; + case 'S': parse_sound_spec (p, arg); break; + case 'R': p->gfx_framerate = _tstoi (arg); break; + case 'x': p->no_xhair = 1; break; + case 'i': p->illegal_mem = 1; break; + case 'J': parse_joy_spec (p, arg); break; + + case 't': p->test_drawing_speed = 1; break; #ifdef USE_X11_GFX - case 'L': p->x11_use_low_bandwidth = 1; break; - case 'T': p->x11_use_mitshm = 1; break; + case 'L': p->x11_use_low_bandwidth = 1; break; + case 'T': p->x11_use_mitshm = 1; break; #endif - case 'w': p->m68k_speed = _tstoi (arg); break; - - /* case 'g': p->use_gfxlib = 1; break; */ - case 'G': p->start_gui = 0; break; - case 'D': p->start_debugger = 1; break; - - case 'n': - if (_tcschr (arg, 'i') != 0) - p->immediate_blits = 1; - break; - - case 'v': - set_chipset_mask (p, _tstoi (arg)); - break; - - case 'C': - parse_cpu_specs (p, arg); - break; - - case 'Z': - p->z3fastmem_size = _tstoi (arg) * 0x100000; - break; - - case 'U': - p->gfxmem_size = _tstoi (arg) * 0x100000; - break; - - case 'F': - p->fastmem_size = _tstoi (arg) * 0x100000; - break; - - case 'b': - p->bogomem_size = _tstoi (arg) * 0x40000; - break; - - case 'c': - p->chipmem_size = _tstoi (arg) * 0x80000; - break; - - case 'l': - if (0 == strcasecmp(arg, L"de")) - p->keyboard_lang = KBD_LANG_DE; - else if (0 == strcasecmp(arg, L"dk")) - p->keyboard_lang = KBD_LANG_DK; - else if (0 == strcasecmp(arg, L"us")) - p->keyboard_lang = KBD_LANG_US; - else if (0 == strcasecmp(arg, L"se")) - p->keyboard_lang = KBD_LANG_SE; - else if (0 == strcasecmp(arg, L"fr")) - p->keyboard_lang = KBD_LANG_FR; - else if (0 == strcasecmp(arg, L"it")) - p->keyboard_lang = KBD_LANG_IT; - else if (0 == strcasecmp(arg, L"es")) - p->keyboard_lang = KBD_LANG_ES; - break; - - case 'O': parse_gfx_specs (p, arg); break; - case 'd': - if (_tcschr (arg, 'S') != NULL || _tcschr (arg, 's')) { - write_log (L" Serial on demand.\n"); - p->serial_demand = 1; - } - if (_tcschr (arg, 'P') != NULL || _tcschr (arg, 'p')) { - write_log (L" Parallel on demand.\n"); - p->parallel_demand = 1; - } - - break; - - case 'H': - p->color_mode = _tstoi (arg); - if (p->color_mode < 0) { - write_log (L"Bad color mode selected. Using default.\n"); - p->color_mode = 0; - } - break; - default: - write_log (L"Unknown option `-%c'!\n", c); - break; - } - return !! _tcschr (arg_required, c); + case 'w': p->m68k_speed = _tstoi (arg); break; + + /* case 'g': p->use_gfxlib = 1; break; */ + case 'G': p->start_gui = 0; break; + case 'D': p->start_debugger = 1; break; + + case 'n': + if (_tcschr (arg, 'i') != 0) + p->immediate_blits = 1; + break; + + case 'v': + set_chipset_mask (p, _tstoi (arg)); + break; + + case 'C': + parse_cpu_specs (p, arg); + break; + + case 'Z': + p->z3fastmem_size = _tstoi (arg) * 0x100000; + break; + + case 'U': + p->gfxmem_size = _tstoi (arg) * 0x100000; + break; + + case 'F': + p->fastmem_size = _tstoi (arg) * 0x100000; + break; + + case 'b': + p->bogomem_size = _tstoi (arg) * 0x40000; + break; + + case 'c': + p->chipmem_size = _tstoi (arg) * 0x80000; + break; + + case 'l': + if (0 == strcasecmp(arg, L"de")) + p->keyboard_lang = KBD_LANG_DE; + else if (0 == strcasecmp(arg, L"dk")) + p->keyboard_lang = KBD_LANG_DK; + else if (0 == strcasecmp(arg, L"us")) + p->keyboard_lang = KBD_LANG_US; + else if (0 == strcasecmp(arg, L"se")) + p->keyboard_lang = KBD_LANG_SE; + else if (0 == strcasecmp(arg, L"fr")) + p->keyboard_lang = KBD_LANG_FR; + else if (0 == strcasecmp(arg, L"it")) + p->keyboard_lang = KBD_LANG_IT; + else if (0 == strcasecmp(arg, L"es")) + p->keyboard_lang = KBD_LANG_ES; + break; + + case 'O': parse_gfx_specs (p, arg); break; + case 'd': + if (_tcschr (arg, 'S') != NULL || _tcschr (arg, 's')) { + write_log (L" Serial on demand.\n"); + p->serial_demand = 1; + } + if (_tcschr (arg, 'P') != NULL || _tcschr (arg, 'p')) { + write_log (L" Parallel on demand.\n"); + p->parallel_demand = 1; + } + + break; + + case 'H': + p->color_mode = _tstoi (arg); + if (p->color_mode < 0) { + write_log (L"Bad color mode selected. Using default.\n"); + p->color_mode = 0; + } + break; + default: + write_log (L"Unknown option `-%c'!\n", c); + break; + } + return !! _tcschr (arg_required, c); } void cfgfile_addcfgparam (TCHAR *line) { - struct strlist *u; - TCHAR line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; - - if (!line) { - struct strlist **ps = &temp_lines; - while (*ps) { - struct strlist *s = *ps; - *ps = s->next; - xfree (s->value); - xfree (s->option); - xfree (s); + struct strlist *u; + TCHAR line1b[CONFIG_BLEN], line2b[CONFIG_BLEN]; + + if (!line) { + struct strlist **ps = &temp_lines; + while (*ps) { + struct strlist *s = *ps; + *ps = s->next; + xfree (s->value); + xfree (s->option); + xfree (s); + } + temp_lines = 0; + return; } - temp_lines = 0; - return; - } - if (!cfgfile_separate_line (line, line1b, line2b)) - return; - u = xcalloc (sizeof (struct strlist), 1); - u->option = my_strdup (line1b); - u->value = my_strdup (line2b); - u->next = temp_lines; - temp_lines = u; + if (!cfgfile_separate_line (line, line1b, line2b)) + return; + u = xcalloc (sizeof (struct strlist), 1); + u->option = my_strdup (line1b); + u->value = my_strdup (line2b); + u->next = temp_lines; + temp_lines = u; } static int getconfigstoreline (struct zfile *z, TCHAR *option, TCHAR *value) { - TCHAR tmp[CONFIG_BLEN * 2]; - int idx = 0; + TCHAR tmp[CONFIG_BLEN * 2]; + int idx = 0; - for (;;) { - TCHAR b = 0; - if (zfile_fread (&b, 1, sizeof (TCHAR), z) != 1) - return 0; - tmp[idx++] = b; - tmp[idx] = 0; - if (b == '\n' || b == 0) - break; - } - return cfgfile_separate_line (tmp, option, value); + for (;;) { + TCHAR b = 0; + if (zfile_fread (&b, 1, sizeof (TCHAR), z) != 1) + return 0; + tmp[idx++] = b; + tmp[idx] = 0; + if (b == '\n' || b == 0) + break; + } + return cfgfile_separate_line (tmp, option, value); } #if 0 static int cfgfile_handle_custom_event (TCHAR *custom, int mode) { - TCHAR option[CONFIG_BLEN], value[CONFIG_BLEN]; - TCHAR option2[CONFIG_BLEN], value2[CONFIG_BLEN]; - TCHAR *tmp, *p, *nextp; - struct zfile *configstore = NULL; - int cnt = 0, cnt_ok = 0; + TCHAR option[CONFIG_BLEN], value[CONFIG_BLEN]; + TCHAR option2[CONFIG_BLEN], value2[CONFIG_BLEN]; + TCHAR *tmp, *p, *nextp; + struct zfile *configstore = NULL; + int cnt = 0, cnt_ok = 0; + + if (!mode) { + uae_u8 zero = 0; + configstore = zfile_fopen_empty ("configstore", 50000); + cfgfile_save_options (configstore, &currprefs, 0); + cfg_write (&zero, configstore); + } - if (!mode) { - uae_u8 zero = 0; - configstore = zfile_fopen_empty ("configstore", 50000); - cfgfile_save_options (configstore, &currprefs, 0); - cfg_write (&zero, configstore); - } - - nextp = NULL; - tmp = p = xcalloc (_tcslen (custom) + 2, 1); - _tcscpy (tmp, custom); - while (p && *p) { - if (*p == '\"') { - TCHAR *p2; - p++; - p2 = p; - while (*p2 != '\"' && *p2 != 0) - p2++; - if (*p2 == '\"') { - *p2++ = 0; - nextp = p2 + 1; - if (*nextp == ' ') - nextp++; - } - } - if (cfgfile_separate_line (p, option, value)) { - cnt++; - if (mode) { - cfgfile_parse_option (&changed_prefs, option, value, 0); - } else { - zfile_fseek (configstore, 0, SEEK_SET); - for (;;) { - if (!getconfigstoreline (configstore, option2, value2)) - break; - if (!_tcscmpi (option, option2) && !_tcscmpi (value, value2)) { - cnt_ok++; - break; - } + nextp = NULL; + tmp = p = xcalloc (_tcslen (custom) + 2, 1); + _tcscpy (tmp, custom); + while (p && *p) { + if (*p == '\"') { + TCHAR *p2; + p++; + p2 = p; + while (*p2 != '\"' && *p2 != 0) + p2++; + if (*p2 == '\"') { + *p2++ = 0; + nextp = p2 + 1; + if (*nextp == ' ') + nextp++; + } + } + if (cfgfile_separate_line (p, option, value)) { + cnt++; + if (mode) { + cfgfile_parse_option (&changed_prefs, option, value, 0); + } else { + zfile_fseek (configstore, 0, SEEK_SET); + for (;;) { + if (!getconfigstoreline (configstore, option2, value2)) + break; + if (!_tcscmpi (option, option2) && !_tcscmpi (value, value2)) { + cnt_ok++; + break; + } + } + } } - } + p = nextp; } - p = nextp; - } - xfree (tmp); - zfile_fclose (configstore); - if (cnt > 0 && cnt == cnt_ok) - return 1; - return 0; + xfree (tmp); + zfile_fclose (configstore); + if (cnt > 0 && cnt == cnt_ok) + return 1; + return 0; } #endif int cmdlineparser (TCHAR *s, TCHAR *outp[], int max) { - int j, cnt = 0; - int slash = 0; - int quote = 0; - TCHAR tmp1[MAX_DPATH]; - TCHAR *prev; - int doout; - - doout = 0; - prev = s; - j = 0; - outp[0] = 0; - while (cnt < max) { - TCHAR c = *s++; - if (!c) - break; - if (c < 32) - continue; - if (c == '\\') - slash = 1; - if (!slash && c == '"') { - if (quote) { - quote = 0; - doout = 1; - } else { - quote = 1; - j = -1; - } - } - if (!quote && c == ' ') - doout = 1; - if (!doout) { - if (j >= 0) { - tmp1[j] = c; - tmp1[j + 1] = 0; - } - j++; - } - if (doout) { - outp[cnt++] = my_strdup (tmp1); - outp[cnt] = 0; - tmp1[0] = 0; - doout = 0; - j = 0; - } - slash = 0; - } - if (j > 0 && cnt < max) { - outp[cnt++] = my_strdup (tmp1); - outp[cnt] = 0; - } - return cnt; + int j, cnt = 0; + int slash = 0; + int quote = 0; + TCHAR tmp1[MAX_DPATH]; + TCHAR *prev; + int doout; + + doout = 0; + prev = s; + j = 0; + outp[0] = 0; + while (cnt < max) { + TCHAR c = *s++; + if (!c) + break; + if (c < 32) + continue; + if (c == '\\') + slash = 1; + if (!slash && c == '"') { + if (quote) { + quote = 0; + doout = 1; + } else { + quote = 1; + j = -1; + } + } + if (!quote && c == ' ') + doout = 1; + if (!doout) { + if (j >= 0) { + tmp1[j] = c; + tmp1[j + 1] = 0; + } + j++; + } + if (doout) { + outp[cnt++] = my_strdup (tmp1); + outp[cnt] = 0; + tmp1[0] = 0; + doout = 0; + j = 0; + } + slash = 0; + } + if (j > 0 && cnt < max) { + outp[cnt++] = my_strdup (tmp1); + outp[cnt] = 0; + } + return cnt; } #define UAELIB_MAX_PARSE 100 uae_u32 cfgfile_modify (uae_u32 index, TCHAR *parms, uae_u32 size, TCHAR *out, uae_u32 outsize) { - TCHAR *p; - TCHAR *argc[UAELIB_MAX_PARSE]; - int argv, i; - uae_u32 err; - TCHAR zero = 0; - static struct zfile *configstore; - static TCHAR *configsearch; - static int configsearchfound; - - err = 0; - argv = 0; - p = 0; - if (index != 0xffffffff) { - if (!configstore) { - err = 20; - goto end; - } - if (configsearch) { - TCHAR tmp[CONFIG_BLEN]; - int j = 0; - TCHAR *in = configsearch; - int inlen = _tcslen (configsearch); - int joker = 0; - - if (in[inlen - 1] == '*') { - joker = 1; - inlen--; - } - - for (;;) { - uae_u8 b = 0; - - if (zfile_fread (&b, 1, 1, configstore) != 1) { - err = 10; - if (configsearch) - err = 5; - if (configsearchfound) - err = 0; - goto end; - } - if (j >= sizeof (tmp) / sizeof (TCHAR) - 1) - j = sizeof (tmp) / sizeof (TCHAR) - 1; - if (b == 0) { - err = 10; - if (configsearch) - err = 5; - if (configsearchfound) - err = 0; - goto end; + TCHAR *p; + TCHAR *argc[UAELIB_MAX_PARSE]; + int argv, i; + uae_u32 err; + TCHAR zero = 0; + static struct zfile *configstore; + static TCHAR *configsearch; + static int configsearchfound; + + err = 0; + argv = 0; + p = 0; + if (index != 0xffffffff) { + if (!configstore) { + err = 20; + goto end; } - if (b == '\n') { - if (configsearch && !_tcsncmp (tmp, in, inlen) && - ((inlen > 0 && _tcslen (tmp) > inlen && tmp[inlen] == '=') || (joker))) { - TCHAR *p; - if (joker) - p = tmp - 1; - else - p = _tcschr (tmp, '='); - if (p) { - for (i = 0; out && i < outsize - 1; i++) { - TCHAR b = *++p; - out[i] = b; - out[i + 1] = 0; - if (!b) - break; - } + if (configsearch) { + TCHAR tmp[CONFIG_BLEN]; + int j = 0; + TCHAR *in = configsearch; + int inlen = _tcslen (configsearch); + int joker = 0; + + if (in[inlen - 1] == '*') { + joker = 1; + inlen--; + } + + for (;;) { + uae_u8 b = 0; + + if (zfile_fread (&b, 1, 1, configstore) != 1) { + err = 10; + if (configsearch) + err = 5; + if (configsearchfound) + err = 0; + goto end; + } + if (j >= sizeof (tmp) / sizeof (TCHAR) - 1) + j = sizeof (tmp) / sizeof (TCHAR) - 1; + if (b == 0) { + err = 10; + if (configsearch) + err = 5; + if (configsearchfound) + err = 0; + goto end; + } + if (b == '\n') { + if (configsearch && !_tcsncmp (tmp, in, inlen) && + ((inlen > 0 && _tcslen (tmp) > inlen && tmp[inlen] == '=') || (joker))) { + TCHAR *p; + if (joker) + p = tmp - 1; + else + p = _tcschr (tmp, '='); + if (p) { + for (i = 0; out && i < outsize - 1; i++) { + TCHAR b = *++p; + out[i] = b; + out[i + 1] = 0; + if (!b) + break; + } + } + err = 0xffffffff; + configsearchfound++; + goto end; + } + index--; + j = 0; + } else { + tmp[j++] = b; + tmp[j] = 0; + } } - err = 0xffffffff; - configsearchfound++; - goto end; - } - index--; - j = 0; - } else { - tmp[j++] = b; - tmp[j] = 0; } - } - } - err = 0xffffffff; - for (i = 0; out && i < outsize - 1; i++) { - uae_u8 b = 0; - if (zfile_fread (&b, 1, 1, configstore) != 1) - err = 0; - if (b == 0) - err = 0; - if (b == '\n') - b = 0; - out[i] = b; - out[i + 1] = 0; - if (!b) - break; + err = 0xffffffff; + for (i = 0; out && i < outsize - 1; i++) { + uae_u8 b = 0; + if (zfile_fread (&b, 1, 1, configstore) != 1) + err = 0; + if (b == 0) + err = 0; + if (b == '\n') + b = 0; + out[i] = b; + out[i + 1] = 0; + if (!b) + break; + } + goto end; } - goto end; - } - if (size > 10000) - return 10; - argv = cmdlineparser (parms, argc, UAELIB_MAX_PARSE); + if (size > 10000) + return 10; + argv = cmdlineparser (parms, argc, UAELIB_MAX_PARSE); + + if (argv <= 1 && index == 0xffffffff) { + zfile_fclose (configstore); + xfree (configsearch); + configstore = zfile_fopen_empty (NULL, L"configstore", 50000); + configsearch = NULL; + if (argv > 0 && _tcslen (argc[0]) > 0) + configsearch = my_strdup (argc[0]); + if (!configstore) { + err = 20; + goto end; + } + zfile_fseek (configstore, 0, SEEK_SET); + uaeconfig++; + cfgfile_save_options (configstore, &currprefs, 0); + uaeconfig--; + cfg_write (&zero, configstore); + zfile_fseek (configstore, 0, SEEK_SET); + err = 0xffffffff; + configsearchfound = 0; + goto end; + } - if (argv <= 1 && index == 0xffffffff) { - zfile_fclose (configstore); - xfree (configsearch); - configstore = zfile_fopen_empty (NULL, L"configstore", 50000); - configsearch = NULL; - if (argv > 0 && _tcslen (argc[0]) > 0) - configsearch = my_strdup (argc[0]); - if (!configstore) { - err = 20; - goto end; - } - zfile_fseek (configstore, 0, SEEK_SET); - uaeconfig++; - cfgfile_save_options (configstore, &currprefs, 0); - uaeconfig--; - cfg_write (&zero, configstore); - zfile_fseek (configstore, 0, SEEK_SET); - err = 0xffffffff; - configsearchfound = 0; - goto end; - } - - for (i = 0; i < argv; i++) { - if (i + 2 <= argv) { - if (!inputdevice_uaelib (argc[i], argc[i + 1])) { - if (!cfgfile_parse_option (&changed_prefs, argc[i], argc[i + 1], 0)) { - err = 5; - break; + for (i = 0; i < argv; i++) { + if (i + 2 <= argv) { + if (!inputdevice_uaelib (argc[i], argc[i + 1])) { + if (!cfgfile_parse_option (&changed_prefs, argc[i], argc[i + 1], 0)) { + err = 5; + break; + } + } + set_special (SPCFLAG_BRK); + i++; } - } - set_special (SPCFLAG_BRK); - i++; } - } end: - for (i = 0; i < argv; i++) - xfree (argc[i]); - xfree (p); - return err; + for (i = 0; i < argv; i++) + xfree (argc[i]); + xfree (p); + return err; } uae_u32 cfgfile_uaelib_modify (uae_u32 index, uae_u32 parms, uae_u32 size, uae_u32 out, uae_u32 outsize) { - uae_char *p, *parms_p = NULL, *parms_out = NULL; - int i, ret; - TCHAR *out_p = NULL, *parms_in = NULL; - - if (out) - put_byte (out, 0); - if (size == 0) { - while (get_byte (parms + size) != 0) - size++; - } - parms_p = xmalloc (size + 1); - if (!parms_p) { - ret = 10; - goto end; - } - if (out) { - out_p = xmalloc ((outsize + 1) * sizeof (TCHAR)); - if (!out_p) { - ret = 10; - goto end; - } - out_p[0] = 0; - } - p = parms_p; - for (i = 0; i < size; i++) { - p[i] = get_byte (parms + i); - if (p[i] == 10 || p[i] == 13 || p[i] == 0) - break; - } - p[i] = 0; - parms_in = au (parms_p); - ret = cfgfile_modify (index, parms_in, size, out_p, outsize); - xfree (parms_in); - if (out) { - parms_out = ua (out_p); - p = parms_out; - for (i = 0; i < outsize - 1; i++) { - uae_u8 b = *p++; - put_byte (out + i, b); - put_byte (out + i + 1, 0); - if (!b) - break; + uae_char *p, *parms_p = NULL, *parms_out = NULL; + int i, ret; + TCHAR *out_p = NULL, *parms_in = NULL; + + if (out) + put_byte (out, 0); + if (size == 0) { + while (get_byte (parms + size) != 0) + size++; + } + parms_p = xmalloc (size + 1); + if (!parms_p) { + ret = 10; + goto end; + } + if (out) { + out_p = xmalloc ((outsize + 1) * sizeof (TCHAR)); + if (!out_p) { + ret = 10; + goto end; + } + out_p[0] = 0; } - } - xfree (parms_out); + p = parms_p; + for (i = 0; i < size; i++) { + p[i] = get_byte (parms + i); + if (p[i] == 10 || p[i] == 13 || p[i] == 0) + break; + } + p[i] = 0; + parms_in = au (parms_p); + ret = cfgfile_modify (index, parms_in, size, out_p, outsize); + xfree (parms_in); + if (out) { + parms_out = ua (out_p); + p = parms_out; + for (i = 0; i < outsize - 1; i++) { + uae_u8 b = *p++; + put_byte (out + i, b); + put_byte (out + i + 1, 0); + if (!b) + break; + } + } + xfree (parms_out); end: - xfree (out_p); - xfree (parms_p); - return ret; + xfree (out_p); + xfree (parms_p); + return ret; } uae_u32 cfgfile_uaelib (int mode, uae_u32 name, uae_u32 dst, uae_u32 maxlen) { - TCHAR tmp[CONFIG_BLEN]; - int i; - struct strlist *sl; + TCHAR tmp[CONFIG_BLEN]; + int i; + struct strlist *sl; - if (mode) - return 0; + if (mode) + return 0; - for (i = 0; i < sizeof (tmp) / sizeof (TCHAR); i++) { - tmp[i] = get_byte (name + i); - if (tmp[i] == 0) - break; - } - tmp[sizeof(tmp) / sizeof (TCHAR) - 1] = 0; - if (tmp[0] == 0) - return 0; - for (sl = currprefs.all_lines; sl; sl = sl->next) { - if (!strcasecmp (sl->option, tmp)) - break; - } - - if (sl) { - char *s = ua (sl->value); - for (i = 0; i < maxlen; i++) { - put_byte (dst + i, s[i]); - if (s[i] == 0) - break; + for (i = 0; i < sizeof (tmp) / sizeof (TCHAR); i++) { + tmp[i] = get_byte (name + i); + if (tmp[i] == 0) + break; } - xfree (s); - return dst; - } - return 0; + tmp[sizeof(tmp) / sizeof (TCHAR) - 1] = 0; + if (tmp[0] == 0) + return 0; + for (sl = currprefs.all_lines; sl; sl = sl->next) { + if (!strcasecmp (sl->option, tmp)) + break; + } + + if (sl) { + char *s = ua (sl->value); + for (i = 0; i < maxlen; i++) { + put_byte (dst + i, s[i]); + if (s[i] == 0) + break; + } + xfree (s); + return dst; + } + return 0; } uae_u8 *restore_configuration (uae_u8 *src) { - TCHAR *s = au (src); - //write_log (s); - xfree (s); - src += strlen (src) + 1; - return src; + TCHAR *s = au (src); + //write_log (s); + xfree (s); + src += strlen (src) + 1; + return src; } uae_u8 *save_configuration (int *len) { - int tmpsize = 30000; - uae_u8 *dstbak, *dst, *p; - int index = -1; - - dstbak = dst = malloc (tmpsize * sizeof (TCHAR)); - p = dst; - for (;;) { - TCHAR tmpout[256]; - int ret; - tmpout[0] = 0; - ret = cfgfile_modify (index, L"*", 1, tmpout, sizeof (tmpout) / sizeof (TCHAR)); - index++; - if (_tcslen (tmpout) > 0) { - char *out; - if (!_tcsncmp (tmpout, L"input.", 6)) - continue; - out = ua (tmpout); - strcpy (p, out); - xfree (out); - strcat (p, "\n"); - p += strlen (p); - if (p - dstbak >= tmpsize - sizeof (tmpout)) - break; + int tmpsize = 30000; + uae_u8 *dstbak, *dst, *p; + int index = -1; + + dstbak = dst = malloc (tmpsize * sizeof (TCHAR)); + p = dst; + for (;;) { + TCHAR tmpout[256]; + int ret; + tmpout[0] = 0; + ret = cfgfile_modify (index, L"*", 1, tmpout, sizeof (tmpout) / sizeof (TCHAR)); + index++; + if (_tcslen (tmpout) > 0) { + char *out; + if (!_tcsncmp (tmpout, L"input.", 6)) + continue; + out = ua (tmpout); + strcpy (p, out); + xfree (out); + strcat (p, "\n"); + p += strlen (p); + if (p - dstbak >= tmpsize - sizeof (tmpout)) + break; + } + if (ret >= 0) + break; } - if (ret >= 0) - break; - } - *len = p - dstbak + 1; - return dstbak; + *len = p - dstbak + 1; + return dstbak; } static int configure_rom (struct uae_prefs *p, int *rom, int msg) { - struct romdata *rd; - TCHAR *path = 0; - int i; - - i = 0; - while (rom[i] >= 0) { - rd = getromdatabyid (rom[i]); - if (!rd) { - i++; - continue; - } - path = romlist_get (rd); - if (path) - break; - i++; - } - if (!path) { - if (msg) - romwarning(rom); - return 0; - } - if (rd->type & (ROMTYPE_KICK | ROMTYPE_KICKCD32)) - _tcscpy (p->romfile, path); - if (rd->type & (ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS)) - _tcscpy (p->romextfile, path); - if (rd->type & (ROMTYPE_CD32CART | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON | ROMTYPE_XPOWER | ROMTYPE_NORDIC | ROMTYPE_AR | ROMTYPE_SUPERIV)) - _tcscpy (p->cartfile, path); - return 1; + struct romdata *rd; + TCHAR *path = 0; + int i; + + i = 0; + while (rom[i] >= 0) { + rd = getromdatabyid (rom[i]); + if (!rd) { + i++; + continue; + } + path = romlist_get (rd); + if (path) + break; + i++; + } + if (!path) { + if (msg) + romwarning(rom); + return 0; + } + if (rd->type & (ROMTYPE_KICK | ROMTYPE_KICKCD32)) + _tcscpy (p->romfile, path); + if (rd->type & (ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS)) + _tcscpy (p->romextfile, path); + if (rd->type & (ROMTYPE_CD32CART | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON | ROMTYPE_XPOWER | ROMTYPE_NORDIC | ROMTYPE_AR | ROMTYPE_SUPERIV)) + _tcscpy (p->cartfile, path); + return 1; } static void default_prefs_mini (struct uae_prefs *p, int type) { - _tcscpy (p->description, L"UAE default A500 configuration"); + _tcscpy (p->description, L"UAE default A500 configuration"); - p->nr_floppies = 1; - p->dfxtype[0] = DRV_35_DD; - p->dfxtype[1] = DRV_NONE; - p->cpu_model = 68000; - p->address_space_24 = 1; - p->chipmem_size = 0x00080000; - p->bogomem_size = 0x00080000; + p->nr_floppies = 1; + p->dfxtype[0] = DRV_35_DD; + p->dfxtype[1] = DRV_NONE; + p->cpu_model = 68000; + p->address_space_24 = 1; + p->chipmem_size = 0x00080000; + p->bogomem_size = 0x00080000; } #include "sounddep/sound.h" void default_prefs (struct uae_prefs *p, int type) { - int i; - int roms[] = { 6, 7, 8, 9, 10, 14, 5, 4, 3, 2, 1, -1 }; - uae_u8 zero = 0; - struct zfile *f; - - memset (p, 0, sizeof (*p)); - _tcscpy (p->description, L"UAE default configuration"); - p->config_hardware_path[0] = 0; - p->config_host_path[0] = 0; - - p->gfx_scandoubler = 0; - p->start_gui = 1; - p->start_debugger = 0; - - p->all_lines = 0; - /* Note to porters: please don't change any of these options! UAE is supposed - * to behave identically on all platforms if possible. - * (TW says: maybe it is time to update default config..) */ - p->illegal_mem = 0; - p->no_xhair = 0; - p->use_serial = 0; - p->serial_demand = 0; - p->serial_hwctsrts = 1; - p->parallel_demand = 0; - p->parallel_matrix_emulation = 0; - p->parallel_postscript_emulation = 0; - p->parallel_postscript_detection = 0; - p->parallel_autoflush_time = 5; - p->ghostscript_parameters[0] = 0; - p->uae_hide = 0; - - memset (&p->jports[0], 0, sizeof (struct jport)); - memset (&p->jports[1], 0, sizeof (struct jport)); - memset (&p->jports[2], 0, sizeof (struct jport)); - memset (&p->jports[3], 0, sizeof (struct jport)); - p->jports[0].id = JSEM_MICE; - p->jports[1].id = JSEM_KBDLAYOUT; - p->jports[2].id = -1; - p->jports[3].id = -1; - p->keyboard_lang = KBD_LANG_US; - - p->produce_sound = 3; - p->sound_stereo = SND_STEREO; - p->sound_stereo_separation = 7; - p->sound_mixed_stereo_delay = 0; - p->sound_freq = DEFAULT_SOUND_FREQ; - p->sound_maxbsiz = DEFAULT_SOUND_MAXB; - p->sound_latency = 100; - p->sound_interpol = 1; - p->sound_filter = FILTER_SOUND_EMUL; - p->sound_filter_type = 0; - p->sound_auto = 1; - - p->comptrustbyte = 0; - p->comptrustword = 0; - p->comptrustlong = 0; - p->comptrustnaddr= 0; - p->compnf = 1; - p->comp_hardflush = 0; - p->comp_constjump = 1; - p->comp_oldsegv = 0; - p->compfpu = 1; - p->fpu_strict = 0; - p->cachesize = 0; - p->avoid_cmov = 0; - p->avoid_dga = 0; - p->avoid_vid = 0; - p->comp_midopt = 0; - p->comp_lowopt = 0; - p->override_dga_address = 0; - - for (i = 0;i < 10; i++) - p->optcount[i] = -1; - p->optcount[0] = 4; /* How often a block has to be executed before it is translated */ - p->optcount[1] = 0; /* How often to use the naive translation */ - p->optcount[2] = 0; - p->optcount[3] = 0; - p->optcount[4] = 0; - p->optcount[5] = 0; - - p->gfx_framerate = 1; - p->gfx_autoframerate = 50; - p->gfx_size_fs.width = 800; - p->gfx_size_fs.height = 600; - p->gfx_size_win.width = 720; - p->gfx_size_win.height = 568; - for (i = 0; i < 4; i++) { - p->gfx_size_fs_xtra[i].width = 0; - p->gfx_size_fs_xtra[i].height = 0; - p->gfx_size_win_xtra[i].width = 0; - p->gfx_size_win_xtra[i].height = 0; - } - p->gfx_resolution = 1; - p->gfx_linedbl = 1; - p->gfx_afullscreen = 0; - p->gfx_pfullscreen = 0; - p->gfx_xcenter = 0; p->gfx_ycenter = 0; - p->gfx_xcenter_pos = -1; p->gfx_ycenter_pos = -1; - p->gfx_xcenter_size = -1; p->gfx_ycenter_size = -1; - p->gfx_max_horizontal = RES_HIRES; - p->gfx_max_vertical = 1; - p->color_mode = 2; - p->gfx_blackerthanblack = 0; - p->gfx_backbuffers = 2; - - p->x11_use_low_bandwidth = 0; - p->x11_use_mitshm = 0; - p->x11_hide_cursor = 1; - - p->svga_no_linear = 0; - - p->curses_reverse_video = 0; - - target_default_options (p, type); - - p->immediate_blits = 0; - p->collision_level = 2; - p->leds_on_screen = 0; - p->keyboard_leds_in_use = 0; - p->keyboard_leds[0] = p->keyboard_leds[1] = p->keyboard_leds[2] = 0; - p->scsi = 0; - p->uaeserial = 0; - p->cpu_idle = 0; - p->turbo_emulation = 0; - p->headless = 0; - p->catweasel = 0; - p->tod_hack = 0; - p->maprom = 0; - p->filesys_no_uaefsdb = 0; - p->filesys_custom_uaefsdb = 1; - p->picasso96_nocustom = 1; - p->cart_internal = 1; - p->sana2 = 0; - - p->cs_compatible = 1; - p->cs_rtc = 2; - p->cs_df0idhw = 1; - p->cs_a1000ram = 0; - p->cs_fatgaryrev = -1; - p->cs_ramseyrev = -1; - p->cs_agnusrev = -1; - p->cs_deniserev = -1; - p->cs_mbdmac = 0; - p->cs_a2091 = 0; - p->cs_a4091 = 0; - p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; - p->cs_cdtvcd = p->cs_cdtvram = p->cs_cdtvcard = 0; - p->cs_pcmcia = 0; - p->cs_ksmirror_e0 = 1; - p->cs_ksmirror_a8 = 0; - p->cs_ciaoverlay = 1; - p->cs_ciaatod = 0; - p->cs_df0idhw = 1; - p->cs_slowmemisfast = 0; - p->cs_resetwarning = 1; - - p->gfx_filter = 0; - p->gfx_filtershader[0] = 0; - p->gfx_filter_horiz_zoom_mult = 0; - p->gfx_filter_vert_zoom_mult = 0; - p->gfx_filter_filtermode = 0; - p->gfx_filter_scanlineratio = (1 << 4) | 1; - p->gfx_filter_keep_aspect = 0; - p->gfx_filter_autoscale = 0; - - _tcscpy (p->df[0], L"df0.adf"); - _tcscpy (p->df[1], L"df1.adf"); - _tcscpy (p->df[2], L"df2.adf"); - _tcscpy (p->df[3], L"df3.adf"); - - configure_rom (p, roms, 0); - _tcscpy (p->romextfile, L""); - _tcscpy (p->flashfile, L""); - _tcscpy (p->cartfile, L""); - - _tcscpy (p->path_rom, L"./"); - _tcscpy (p->path_floppy, L"./"); - _tcscpy (p->path_hardfile, L"./"); - - p->prtname[0] = 0; - p->sername[0] = 0; - - p->fpu_model = 0; - p->cpu_model = 68000; - p->cpu_clock_multiplier = 0; - p->cpu_frequency = 0; - p->mmu_model = 0; - p->cpu060_revision = 6; - p->fpu_revision = -1; - p->m68k_speed = 0; - p->cpu_compatible = 1; - p->address_space_24 = 1; - p->cpu_cycle_exact = 0; - p->blitter_cycle_exact = 0; - p->chipset_mask = CSMASK_ECS_AGNUS; - p->genlock = 0; - p->ntscmode = 0; - - p->fastmem_size = 0x00000000; - p->mbresmem_low_size = 0x00000000; - p->mbresmem_high_size = 0x00000000; - p->z3fastmem_size = 0x00000000; - p->z3fastmem2_size = 0x00000000; - p->z3fastmem_start = 0x10000000; - p->chipmem_size = 0x00080000; - p->bogomem_size = 0x00080000; - p->gfxmem_size = 0x00000000; - p->custom_memory_addrs[0] = 0; - p->custom_memory_sizes[0] = 0; - p->custom_memory_addrs[1] = 0; - p->custom_memory_sizes[1] = 0; - - p->nr_floppies = 2; - p->dfxtype[0] = DRV_35_DD; - p->dfxtype[1] = DRV_35_DD; - p->dfxtype[2] = DRV_NONE; - p->dfxtype[3] = DRV_NONE; - p->floppy_speed = 100; - p->floppy_write_length = 0; - p->dfxclickvolume = 33; - - p->statecapturebuffersize = 20 * 1024 * 1024; - p->statecapturerate = 5 * 50; - p->statecapture = 0; + int i; + int roms[] = { 6, 7, 8, 9, 10, 14, 5, 4, 3, 2, 1, -1 }; + uae_u8 zero = 0; + struct zfile *f; + + memset (p, 0, sizeof (*p)); + _tcscpy (p->description, L"UAE default configuration"); + p->config_hardware_path[0] = 0; + p->config_host_path[0] = 0; + + p->gfx_scandoubler = 0; + p->start_gui = 1; + p->start_debugger = 0; + + p->all_lines = 0; + /* Note to porters: please don't change any of these options! UAE is supposed + * to behave identically on all platforms if possible. + * (TW says: maybe it is time to update default config..) */ + p->illegal_mem = 0; + p->no_xhair = 0; + p->use_serial = 0; + p->serial_demand = 0; + p->serial_hwctsrts = 1; + p->parallel_demand = 0; + p->parallel_matrix_emulation = 0; + p->parallel_postscript_emulation = 0; + p->parallel_postscript_detection = 0; + p->parallel_autoflush_time = 5; + p->ghostscript_parameters[0] = 0; + p->uae_hide = 0; + + memset (&p->jports[0], 0, sizeof (struct jport)); + memset (&p->jports[1], 0, sizeof (struct jport)); + memset (&p->jports[2], 0, sizeof (struct jport)); + memset (&p->jports[3], 0, sizeof (struct jport)); + p->jports[0].id = JSEM_MICE; + p->jports[1].id = JSEM_KBDLAYOUT; + p->jports[2].id = -1; + p->jports[3].id = -1; + p->keyboard_lang = KBD_LANG_US; + + p->produce_sound = 3; + p->sound_stereo = SND_STEREO; + p->sound_stereo_separation = 7; + p->sound_mixed_stereo_delay = 0; + p->sound_freq = DEFAULT_SOUND_FREQ; + p->sound_maxbsiz = DEFAULT_SOUND_MAXB; + p->sound_latency = 100; + p->sound_interpol = 1; + p->sound_filter = FILTER_SOUND_EMUL; + p->sound_filter_type = 0; + p->sound_auto = 1; + + p->comptrustbyte = 0; + p->comptrustword = 0; + p->comptrustlong = 0; + p->comptrustnaddr= 0; + p->compnf = 1; + p->comp_hardflush = 0; + p->comp_constjump = 1; + p->comp_oldsegv = 0; + p->compfpu = 1; + p->fpu_strict = 0; + p->cachesize = 0; + p->avoid_cmov = 0; + p->avoid_dga = 0; + p->avoid_vid = 0; + p->comp_midopt = 0; + p->comp_lowopt = 0; + p->override_dga_address = 0; + + for (i = 0;i < 10; i++) + p->optcount[i] = -1; + p->optcount[0] = 4; /* How often a block has to be executed before it is translated */ + p->optcount[1] = 0; /* How often to use the naive translation */ + p->optcount[2] = 0; + p->optcount[3] = 0; + p->optcount[4] = 0; + p->optcount[5] = 0; + + p->gfx_framerate = 1; + p->gfx_autoframerate = 50; + p->gfx_size_fs.width = 800; + p->gfx_size_fs.height = 600; + p->gfx_size_win.width = 720; + p->gfx_size_win.height = 568; + for (i = 0; i < 4; i++) { + p->gfx_size_fs_xtra[i].width = 0; + p->gfx_size_fs_xtra[i].height = 0; + p->gfx_size_win_xtra[i].width = 0; + p->gfx_size_win_xtra[i].height = 0; + } + p->gfx_resolution = 1; + p->gfx_linedbl = 1; + p->gfx_afullscreen = 0; + p->gfx_pfullscreen = 0; + p->gfx_xcenter = 0; p->gfx_ycenter = 0; + p->gfx_xcenter_pos = -1; p->gfx_ycenter_pos = -1; + p->gfx_xcenter_size = -1; p->gfx_ycenter_size = -1; + p->gfx_max_horizontal = RES_HIRES; + p->gfx_max_vertical = 1; + p->color_mode = 2; + p->gfx_blackerthanblack = 0; + p->gfx_backbuffers = 2; + + p->x11_use_low_bandwidth = 0; + p->x11_use_mitshm = 0; + p->x11_hide_cursor = 1; + + p->svga_no_linear = 0; + + p->curses_reverse_video = 0; + + target_default_options (p, type); + + p->immediate_blits = 0; + p->collision_level = 2; + p->leds_on_screen = 0; + p->keyboard_leds_in_use = 0; + p->keyboard_leds[0] = p->keyboard_leds[1] = p->keyboard_leds[2] = 0; + p->scsi = 0; + p->uaeserial = 0; + p->cpu_idle = 0; + p->turbo_emulation = 0; + p->headless = 0; + p->catweasel = 0; + p->tod_hack = 0; + p->maprom = 0; + p->filesys_no_uaefsdb = 0; + p->filesys_custom_uaefsdb = 1; + p->picasso96_nocustom = 1; + p->cart_internal = 1; + p->sana2 = 0; + + p->cs_compatible = 1; + p->cs_rtc = 2; + p->cs_df0idhw = 1; + p->cs_a1000ram = 0; + p->cs_fatgaryrev = -1; + p->cs_ramseyrev = -1; + p->cs_agnusrev = -1; + p->cs_deniserev = -1; + p->cs_mbdmac = 0; + p->cs_a2091 = 0; + p->cs_a4091 = 0; + p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; + p->cs_cdtvcd = p->cs_cdtvram = p->cs_cdtvcard = 0; + p->cs_pcmcia = 0; + p->cs_ksmirror_e0 = 1; + p->cs_ksmirror_a8 = 0; + p->cs_ciaoverlay = 1; + p->cs_ciaatod = 0; + p->cs_df0idhw = 1; + p->cs_slowmemisfast = 0; + p->cs_resetwarning = 1; -#ifdef UAE_MINI - default_prefs_mini (p, 0); -#endif + p->gfx_filter = 0; + p->gfx_filtershader[0] = 0; + p->gfx_filter_horiz_zoom_mult = 0; + p->gfx_filter_vert_zoom_mult = 0; + p->gfx_filter_filtermode = 0; + p->gfx_filter_scanlineratio = (1 << 4) | 1; + p->gfx_filter_keep_aspect = 0; + p->gfx_filter_autoscale = 0; + + _tcscpy (p->df[0], L"df0.adf"); + _tcscpy (p->df[1], L"df1.adf"); + _tcscpy (p->df[2], L"df2.adf"); + _tcscpy (p->df[3], L"df3.adf"); + + configure_rom (p, roms, 0); + _tcscpy (p->romextfile, L""); + _tcscpy (p->flashfile, L""); + _tcscpy (p->cartfile, L""); - p->input_tablet = TABLET_OFF; - p->input_magic_mouse = 0; - p->input_magic_mouse_cursor = 0; + _tcscpy (p->path_rom, L"./"); + _tcscpy (p->path_floppy, L"./"); + _tcscpy (p->path_hardfile, L"./"); - inputdevice_default_prefs (p); + p->prtname[0] = 0; + p->sername[0] = 0; - zfile_fclose (default_file); - default_file = NULL; - f = zfile_fopen_empty (NULL, L"configstore", 100000); - if (f) { - uaeconfig++; - cfgfile_save_options (f, p, 0); - uaeconfig--; - cfg_write (&zero, f); - default_file = f; - } + p->fpu_model = 0; + p->cpu_model = 68000; + p->cpu_clock_multiplier = 0; + p->cpu_frequency = 0; + p->mmu_model = 0; + p->cpu060_revision = 6; + p->fpu_revision = -1; + p->m68k_speed = 0; + p->cpu_compatible = 1; + p->address_space_24 = 1; + p->cpu_cycle_exact = 0; + p->blitter_cycle_exact = 0; + p->chipset_mask = CSMASK_ECS_AGNUS; + p->genlock = 0; + p->ntscmode = 0; + + p->fastmem_size = 0x00000000; + p->mbresmem_low_size = 0x00000000; + p->mbresmem_high_size = 0x00000000; + p->z3fastmem_size = 0x00000000; + p->z3fastmem2_size = 0x00000000; + p->z3fastmem_start = 0x10000000; + p->chipmem_size = 0x00080000; + p->bogomem_size = 0x00080000; + p->gfxmem_size = 0x00000000; + p->custom_memory_addrs[0] = 0; + p->custom_memory_sizes[0] = 0; + p->custom_memory_addrs[1] = 0; + p->custom_memory_sizes[1] = 0; + + p->nr_floppies = 2; + p->dfxtype[0] = DRV_35_DD; + p->dfxtype[1] = DRV_35_DD; + p->dfxtype[2] = DRV_NONE; + p->dfxtype[3] = DRV_NONE; + p->floppy_speed = 100; + p->floppy_write_length = 0; + p->dfxclickvolume = 33; + + p->statecapturebuffersize = 20 * 1024 * 1024; + p->statecapturerate = 5 * 50; + p->statecapture = 0; + +#ifdef UAE_MINI + default_prefs_mini (p, 0); +#endif + + p->input_tablet = TABLET_OFF; + p->input_magic_mouse = 0; + p->input_magic_mouse_cursor = 0; + + inputdevice_default_prefs (p); + + zfile_fclose (default_file); + default_file = NULL; + f = zfile_fopen_empty (NULL, L"configstore", 100000); + if (f) { + uaeconfig++; + cfgfile_save_options (f, p, 0); + uaeconfig--; + cfg_write (&zero, f); + default_file = f; + } } static void buildin_default_prefs_68020 (struct uae_prefs *p) { - p->cpu_model = 68020; - p->address_space_24 = 1; - p->cpu_compatible = 1; - p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA; - p->chipmem_size = 0x200000; - p->bogomem_size = 0; - p->m68k_speed = -1; + p->cpu_model = 68020; + p->address_space_24 = 1; + p->cpu_compatible = 1; + p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA; + p->chipmem_size = 0x200000; + p->bogomem_size = 0; + p->m68k_speed = -1; } static void buildin_default_host_prefs (struct uae_prefs *p) { #if 0 - p->sound_filter = FILTER_SOUND_OFF; - p->sound_stereo = SND_STEREO; - p->sound_stereo_separation = 7; - p->sound_mixed_stereo = 0; + p->sound_filter = FILTER_SOUND_OFF; + p->sound_stereo = SND_STEREO; + p->sound_stereo_separation = 7; + p->sound_mixed_stereo = 0; #endif } static void buildin_default_prefs (struct uae_prefs *p) { - buildin_default_host_prefs (p); + buildin_default_host_prefs (p); - p->dfxtype[0] = DRV_35_DD; - if (p->nr_floppies != 1 && p->nr_floppies != 2) - p->nr_floppies = 2; - p->dfxtype[1] = p->nr_floppies >= 2 ? DRV_35_DD : DRV_NONE; - p->dfxtype[2] = DRV_NONE; - p->dfxtype[3] = DRV_NONE; - p->floppy_speed = 100; - - p->fpu_model = 0; - p->cpu_model = 68000; - p->cpu_clock_multiplier = 0; - p->cpu_frequency = 0; - p->cpu060_revision = 1; - p->fpu_revision = -1; - p->m68k_speed = 0; - p->cpu_compatible = 1; - p->address_space_24 = 1; - p->cpu_cycle_exact = 0; - p->blitter_cycle_exact = 0; - p->chipset_mask = CSMASK_ECS_AGNUS; - p->immediate_blits = 0; - p->collision_level = 2; - p->produce_sound = 3; - p->scsi = 0; - p->uaeserial = 0; - p->cpu_idle = 0; - p->turbo_emulation = 0; - p->catweasel = 0; - p->tod_hack = 0; - p->maprom = 0; - p->cachesize = 0; - p->socket_emu = 0; - - p->chipmem_size = 0x00080000; - p->bogomem_size = 0x00080000; - p->fastmem_size = 0x00000000; - p->mbresmem_low_size = 0x00000000; - p->mbresmem_high_size = 0x00000000; - p->z3fastmem_size = 0x00000000; - p->z3fastmem2_size = 0x00000000; - p->gfxmem_size = 0x00000000; - - p->cs_rtc = 0; - p->cs_a1000ram = 0; - p->cs_fatgaryrev = -1; - p->cs_ramseyrev = -1; - p->cs_agnusrev = -1; - p->cs_deniserev = -1; - p->cs_mbdmac = 0; - p->cs_a2091 = 0; - p->cs_a4091 = 0; - p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; - p->cs_cdtvcd = p->cs_cdtvram = p->cs_cdtvcard = 0; - p->cs_ide = 0; - p->cs_pcmcia = 0; - p->cs_ksmirror_e0 = 1; - p->cs_ksmirror_a8 = 0; - p->cs_ciaoverlay = 1; - p->cs_ciaatod = 0; - p->cs_df0idhw = 1; - p->cs_resetwarning = 0; - - _tcscpy (p->romfile, L""); - _tcscpy (p->romextfile, L""); - _tcscpy (p->flashfile, L""); - _tcscpy (p->cartfile, L""); - _tcscpy (p->amaxromfile, L""); - p->prtname[0] = 0; - p->sername[0] = 0; - - p->mountitems = 0; - - target_default_options (p, 1); + p->dfxtype[0] = DRV_35_DD; + if (p->nr_floppies != 1 && p->nr_floppies != 2) + p->nr_floppies = 2; + p->dfxtype[1] = p->nr_floppies >= 2 ? DRV_35_DD : DRV_NONE; + p->dfxtype[2] = DRV_NONE; + p->dfxtype[3] = DRV_NONE; + p->floppy_speed = 100; + + p->fpu_model = 0; + p->cpu_model = 68000; + p->cpu_clock_multiplier = 0; + p->cpu_frequency = 0; + p->cpu060_revision = 1; + p->fpu_revision = -1; + p->m68k_speed = 0; + p->cpu_compatible = 1; + p->address_space_24 = 1; + p->cpu_cycle_exact = 0; + p->blitter_cycle_exact = 0; + p->chipset_mask = CSMASK_ECS_AGNUS; + p->immediate_blits = 0; + p->collision_level = 2; + p->produce_sound = 3; + p->scsi = 0; + p->uaeserial = 0; + p->cpu_idle = 0; + p->turbo_emulation = 0; + p->catweasel = 0; + p->tod_hack = 0; + p->maprom = 0; + p->cachesize = 0; + p->socket_emu = 0; + + p->chipmem_size = 0x00080000; + p->bogomem_size = 0x00080000; + p->fastmem_size = 0x00000000; + p->mbresmem_low_size = 0x00000000; + p->mbresmem_high_size = 0x00000000; + p->z3fastmem_size = 0x00000000; + p->z3fastmem2_size = 0x00000000; + p->gfxmem_size = 0x00000000; + + p->cs_rtc = 0; + p->cs_a1000ram = 0; + p->cs_fatgaryrev = -1; + p->cs_ramseyrev = -1; + p->cs_agnusrev = -1; + p->cs_deniserev = -1; + p->cs_mbdmac = 0; + p->cs_a2091 = 0; + p->cs_a4091 = 0; + p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; + p->cs_cdtvcd = p->cs_cdtvram = p->cs_cdtvcard = 0; + p->cs_ide = 0; + p->cs_pcmcia = 0; + p->cs_ksmirror_e0 = 1; + p->cs_ksmirror_a8 = 0; + p->cs_ciaoverlay = 1; + p->cs_ciaatod = 0; + p->cs_df0idhw = 1; + p->cs_resetwarning = 0; + + _tcscpy (p->romfile, L""); + _tcscpy (p->romextfile, L""); + _tcscpy (p->flashfile, L""); + _tcscpy (p->cartfile, L""); + _tcscpy (p->amaxromfile, L""); + p->prtname[0] = 0; + p->sername[0] = 0; + + p->mountitems = 0; + + target_default_options (p, 1); } static void set_68020_compa (struct uae_prefs *p, int compa) { - if (compa == 0) { - p->blitter_cycle_exact = 1; - p->m68k_speed = 0; - if (p->cpu_model == 68020 && p->cachesize == 0) { - p->cpu_cycle_exact = 1; - p->cpu_clock_multiplier = 4 << 8; + if (compa == 0) { + p->blitter_cycle_exact = 1; + p->m68k_speed = 0; + if (p->cpu_model == 68020 && p->cachesize == 0) { + p->cpu_cycle_exact = 1; + p->cpu_clock_multiplier = 4 << 8; + } + } + if (compa > 0) { + p->cpu_compatible = 0; + p->address_space_24 = 0; + p->cachesize = 8192; + } + if (compa > 1) { + p->immediate_blits = 1; + p->produce_sound = 2; } - } - if (compa > 0) { - p->cpu_compatible = 0; - p->address_space_24 = 0; - p->cachesize = 8192; - } - if (compa > 1) { - p->immediate_blits = 1; - p->produce_sound = 2; - } } /* 0: cycle-exact - * 1: more compatible - * 2: no more compatible, no 100% sound - * 3: no more compatible, immediate blits, no 100% sound - */ +* 1: more compatible +* 2: no more compatible, no 100% sound +* 3: no more compatible, immediate blits, no 100% sound +*/ static void set_68000_compa (struct uae_prefs *p, int compa) { - p->cpu_clock_multiplier = 2 << 8; - switch (compa) - { + p->cpu_clock_multiplier = 2 << 8; + switch (compa) + { case 0: - p->cpu_cycle_exact = p->blitter_cycle_exact = 1; - break; + p->cpu_cycle_exact = p->blitter_cycle_exact = 1; + break; case 1: - break; + break; case 2: - p->cpu_compatible = 0; - break; + p->cpu_compatible = 0; + break; case 3: - p->immediate_blits = 1; - p->produce_sound = 2; - p->cpu_compatible = 0; - break; - } + p->immediate_blits = 1; + p->produce_sound = 2; + p->cpu_compatible = 0; + break; + } } static int bip_a3000 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[2]; - - if (config == 2) - roms[0] = 61; - else if (config == 1) - roms[0] = 71; - else - roms[0] = 59; - roms[1] = -1; - p->immediate_blits = 1; - p->bogomem_size = 0; - p->chipmem_size = 0x200000; - p->cpu_model = 68030; - p->fpu_model = 68882; - p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - p->cpu_compatible = p->address_space_24 = 0; - p->m68k_speed = -1; - p->immediate_blits = 0; - p->produce_sound = 2; - p->cachesize = 8192; - p->dfxtype[0] = DRV_35_HD; - p->floppy_speed = 0; - p->cpu_idle = 150; - p->cs_compatible = CP_A3000; - p->mbresmem_low_size = 8 * 1024 * 1024; - built_in_chipset_prefs (p); - p->cs_ciaatod = p->ntscmode ? 2 : 1; - return configure_rom (p, roms, romcheck); + int roms[2]; + + if (config == 2) + roms[0] = 61; + else if (config == 1) + roms[0] = 71; + else + roms[0] = 59; + roms[1] = -1; + p->immediate_blits = 1; + p->bogomem_size = 0; + p->chipmem_size = 0x200000; + p->cpu_model = 68030; + p->fpu_model = 68882; + p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + p->cpu_compatible = p->address_space_24 = 0; + p->m68k_speed = -1; + p->immediate_blits = 0; + p->produce_sound = 2; + p->cachesize = 8192; + p->dfxtype[0] = DRV_35_HD; + p->floppy_speed = 0; + p->cpu_idle = 150; + p->cs_compatible = CP_A3000; + p->mbresmem_low_size = 8 * 1024 * 1024; + built_in_chipset_prefs (p); + p->cs_ciaatod = p->ntscmode ? 2 : 1; + return configure_rom (p, roms, romcheck); } static int bip_a4000 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[8]; - - roms[0] = 16; - roms[1] = 31; - roms[2] = 13; - roms[3] = 12; - roms[4] = -1; - p->immediate_blits = 1; - p->bogomem_size = 0; - p->chipmem_size = 0x200000; - p->mbresmem_low_size = 8 * 1024 * 1024; - p->cpu_model = 68030; - p->fpu_model = 68882; - if (config > 0) - p->cpu_model = p->fpu_model = 68040; - p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - p->cpu_compatible = p->address_space_24 = 0; - p->m68k_speed = -1; - p->immediate_blits = 0; - p->produce_sound = 2; - p->cachesize = 8192; - p->dfxtype[0] = DRV_35_HD; - p->dfxtype[1] = DRV_35_HD; - p->floppy_speed = 0; - p->cpu_idle = 150; - p->cs_compatible = CP_A4000; - built_in_chipset_prefs (p); - p->cs_ciaatod = p->ntscmode ? 2 : 1; - return configure_rom (p, roms, romcheck); + int roms[8]; + + roms[0] = 16; + roms[1] = 31; + roms[2] = 13; + roms[3] = 12; + roms[4] = -1; + p->immediate_blits = 1; + p->bogomem_size = 0; + p->chipmem_size = 0x200000; + p->mbresmem_low_size = 8 * 1024 * 1024; + p->cpu_model = 68030; + p->fpu_model = 68882; + if (config > 0) + p->cpu_model = p->fpu_model = 68040; + p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + p->cpu_compatible = p->address_space_24 = 0; + p->m68k_speed = -1; + p->immediate_blits = 0; + p->produce_sound = 2; + p->cachesize = 8192; + p->dfxtype[0] = DRV_35_HD; + p->dfxtype[1] = DRV_35_HD; + p->floppy_speed = 0; + p->cpu_idle = 150; + p->cs_compatible = CP_A4000; + built_in_chipset_prefs (p); + p->cs_ciaatod = p->ntscmode ? 2 : 1; + return configure_rom (p, roms, romcheck); } static int bip_a4000t (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[8]; - - roms[0] = 16; - roms[1] = 31; - roms[2] = 13; - roms[3] = -1; - p->immediate_blits = 1; - p->bogomem_size = 0; - p->chipmem_size = 0x200000; - p->mbresmem_low_size = 8 * 1024 * 1024; - p->cpu_model = 68030; - p->fpu_model = 68882; - if (config > 0) - p->cpu_model = p->fpu_model = 68040; - p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - p->cpu_compatible = p->address_space_24 = 0; - p->m68k_speed = -1; - p->immediate_blits = 0; - p->produce_sound = 2; - p->cachesize = 8192; - p->dfxtype[0] = DRV_35_HD; - p->dfxtype[1] = DRV_35_HD; - p->floppy_speed = 0; - p->cpu_idle = 150; - p->cs_compatible = CP_A4000T; - built_in_chipset_prefs (p); - p->cs_ciaatod = p->ntscmode ? 2 : 1; - return configure_rom (p, roms, romcheck); + int roms[8]; + + roms[0] = 16; + roms[1] = 31; + roms[2] = 13; + roms[3] = -1; + p->immediate_blits = 1; + p->bogomem_size = 0; + p->chipmem_size = 0x200000; + p->mbresmem_low_size = 8 * 1024 * 1024; + p->cpu_model = 68030; + p->fpu_model = 68882; + if (config > 0) + p->cpu_model = p->fpu_model = 68040; + p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + p->cpu_compatible = p->address_space_24 = 0; + p->m68k_speed = -1; + p->immediate_blits = 0; + p->produce_sound = 2; + p->cachesize = 8192; + p->dfxtype[0] = DRV_35_HD; + p->dfxtype[1] = DRV_35_HD; + p->floppy_speed = 0; + p->cpu_idle = 150; + p->cs_compatible = CP_A4000T; + built_in_chipset_prefs (p); + p->cs_ciaatod = p->ntscmode ? 2 : 1; + return configure_rom (p, roms, romcheck); } static int bip_a1000 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[4]; - - roms[0] = 24; - roms[1] = 23; - roms[2] = -1; - p->chipset_mask = 0; - p->bogomem_size = 0; - p->sound_filter = FILTER_SOUND_ON; - set_68000_compa (p, compa); - p->dfxtype[1] = DRV_NONE; - p->cs_compatible = CP_A1000; - p->cs_slowmemisfast = 1; - built_in_chipset_prefs (p); - if (config > 0) - p->cs_denisenoehb = 1; - if (config > 1) - p->chipmem_size = 0x40000; - return configure_rom (p, roms, romcheck); + int roms[4]; + + roms[0] = 24; + roms[1] = 23; + roms[2] = -1; + p->chipset_mask = 0; + p->bogomem_size = 0; + p->sound_filter = FILTER_SOUND_ON; + set_68000_compa (p, compa); + p->dfxtype[1] = DRV_NONE; + p->cs_compatible = CP_A1000; + p->cs_slowmemisfast = 1; + built_in_chipset_prefs (p); + if (config > 0) + p->cs_denisenoehb = 1; + if (config > 1) + p->chipmem_size = 0x40000; + return configure_rom (p, roms, romcheck); } static int bip_cdtv (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[4]; + int roms[4]; - roms[0] = 6; - roms[1] = 32; - roms[2] = -1; - if (!configure_rom (p, roms, romcheck)) - return 0; - roms[0] = 20; - roms[1] = 21; - roms[2] = 22; - roms[3] = -1; - if (!configure_rom (p, roms, romcheck)) - return 0; - p->bogomem_size = 0; - p->chipmem_size = 0x100000; - p->chipset_mask = CSMASK_ECS_AGNUS; - p->cs_cdtvcd = p->cs_cdtvram = 1; - if (config > 0) - p->cs_cdtvcard = 64; - p->cs_rtc = 1; - p->nr_floppies = 0; - p->dfxtype[0] = DRV_NONE; - if (config > 0) - p->dfxtype[0] = DRV_35_DD; - p->dfxtype[1] = DRV_NONE; - set_68000_compa (p, compa); - p->cs_compatible = CP_CDTV; - built_in_chipset_prefs (p); - fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); - _tcscat (p->flashfile, L"cdtv.nvr"); - return 1; + roms[0] = 6; + roms[1] = 32; + roms[2] = -1; + if (!configure_rom (p, roms, romcheck)) + return 0; + roms[0] = 20; + roms[1] = 21; + roms[2] = 22; + roms[3] = -1; + if (!configure_rom (p, roms, romcheck)) + return 0; + p->bogomem_size = 0; + p->chipmem_size = 0x100000; + p->chipset_mask = CSMASK_ECS_AGNUS; + p->cs_cdtvcd = p->cs_cdtvram = 1; + if (config > 0) + p->cs_cdtvcard = 64; + p->cs_rtc = 1; + p->nr_floppies = 0; + p->dfxtype[0] = DRV_NONE; + if (config > 0) + p->dfxtype[0] = DRV_35_DD; + p->dfxtype[1] = DRV_NONE; + set_68000_compa (p, compa); + p->cs_compatible = CP_CDTV; + built_in_chipset_prefs (p); + fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); + _tcscat (p->flashfile, L"cdtv.nvr"); + return 1; } static int bip_cd32 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[2]; + int roms[2]; - buildin_default_prefs_68020 (p); - roms[0] = 64; - roms[1] = -1; - if (!configure_rom (p, roms, 0)) { - roms[0] = 18; + buildin_default_prefs_68020 (p); + roms[0] = 64; roms[1] = -1; - if (!configure_rom (p, roms, romcheck)) - return 0; - roms[0] = 19; - if (!configure_rom (p, roms, romcheck)) - return 0; - } - if (config > 0) { - roms[0] = 23; - if (!configure_rom (p, roms, romcheck)) - return 0; - } - p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 1; - p->nr_floppies = 0; - p->dfxtype[0] = DRV_NONE; - p->dfxtype[1] = DRV_NONE; - set_68020_compa (p, compa); - p->cs_compatible = CP_CD32; - built_in_chipset_prefs (p); - fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); - _tcscat (p->flashfile, L"cd32.nvr"); - return 1; + if (!configure_rom (p, roms, 0)) { + roms[0] = 18; + roms[1] = -1; + if (!configure_rom (p, roms, romcheck)) + return 0; + roms[0] = 19; + if (!configure_rom (p, roms, romcheck)) + return 0; + } + if (config > 0) { + roms[0] = 23; + if (!configure_rom (p, roms, romcheck)) + return 0; + } + p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 1; + p->nr_floppies = 0; + p->dfxtype[0] = DRV_NONE; + p->dfxtype[1] = DRV_NONE; + set_68020_compa (p, compa); + p->cs_compatible = CP_CD32; + built_in_chipset_prefs (p); + fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); + _tcscat (p->flashfile, L"cd32.nvr"); + return 1; } static int bip_a1200 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[4]; + int roms[4]; - buildin_default_prefs_68020 (p); - roms[0] = 11; - roms[1] = 15; - roms[2] = 31; - roms[3] = -1; - p->cs_rtc = 0; - if (config == 1) { - p->fastmem_size = 0x400000; - p->cs_rtc = 2; - } - set_68020_compa (p, compa); - p->cs_compatible = CP_A1200; - built_in_chipset_prefs (p); - return configure_rom (p, roms, romcheck); + buildin_default_prefs_68020 (p); + roms[0] = 11; + roms[1] = 15; + roms[2] = 31; + roms[3] = -1; + p->cs_rtc = 0; + if (config == 1) { + p->fastmem_size = 0x400000; + p->cs_rtc = 2; + } + set_68020_compa (p, compa); + p->cs_compatible = CP_A1200; + built_in_chipset_prefs (p); + return configure_rom (p, roms, romcheck); } static int bip_a600 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[4]; + int roms[4]; - roms[0] = 10; - roms[1] = 9; - roms[2] = 8; - roms[3] = -1; - p->bogomem_size = 0; - p->chipmem_size = 0x100000; - if (config > 0) - p->cs_rtc = 1; - if (config == 1) - p->chipmem_size = 0x200000; - if (config == 2) - p->fastmem_size = 0x400000; - p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - set_68000_compa (p, compa); - p->cs_compatible = CP_A600; - built_in_chipset_prefs (p); - return configure_rom (p, roms, romcheck); + roms[0] = 10; + roms[1] = 9; + roms[2] = 8; + roms[3] = -1; + p->bogomem_size = 0; + p->chipmem_size = 0x100000; + if (config > 0) + p->cs_rtc = 1; + if (config == 1) + p->chipmem_size = 0x200000; + if (config == 2) + p->fastmem_size = 0x400000; + p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + set_68000_compa (p, compa); + p->cs_compatible = CP_A600; + built_in_chipset_prefs (p); + return configure_rom (p, roms, romcheck); } static int bip_a500p (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[2]; + int roms[2]; - roms[0] = 7; - roms[1] = -1; - p->bogomem_size = 0; - p->chipmem_size = 0x100000; - if (config > 0) - p->cs_rtc = 1; - if (config == 1) - p->chipmem_size = 0x200000; - if (config == 2) - p->fastmem_size = 0x400000; - p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - set_68000_compa (p, compa); - p->cs_compatible = CP_A500P; - built_in_chipset_prefs (p); - return configure_rom (p, roms, romcheck); + roms[0] = 7; + roms[1] = -1; + p->bogomem_size = 0; + p->chipmem_size = 0x100000; + if (config > 0) + p->cs_rtc = 1; + if (config == 1) + p->chipmem_size = 0x200000; + if (config == 2) + p->fastmem_size = 0x400000; + p->chipset_mask = CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + set_68000_compa (p, compa); + p->cs_compatible = CP_A500P; + built_in_chipset_prefs (p); + return configure_rom (p, roms, romcheck); } static int bip_a500 (struct uae_prefs *p, int config, int compa, int romcheck) { - int roms[4]; + int roms[4]; - roms[0] = roms[1] = roms[2] = roms[3] = -1; - switch (config) - { - case 0: // KS 1.3, OCS Agnus, 0.5M Chip + 0.5M Slow - roms[0] = 6; - roms[1] = 32; - p->chipset_mask = 0; - break; - case 1: // KS 1.3, ECS Agnus, 0.5M Chip + 0.5M Slow - roms[0] = 6; - roms[1] = 32; - break; - case 2: // KS 1.3, ECS Agnus, 1.0M Chip - roms[0] = 6; - roms[1] = 32; - p->bogomem_size = 0; - p->chipmem_size = 0x100000; - break; - case 3: // KS 1.3, OCS Agnus, 0.5M Chip - roms[0] = 6; - roms[1] = 32; + roms[0] = roms[1] = roms[2] = roms[3] = -1; + switch (config) + { + case 0: // KS 1.3, OCS Agnus, 0.5M Chip + 0.5M Slow + roms[0] = 6; + roms[1] = 32; + p->chipset_mask = 0; + break; + case 1: // KS 1.3, ECS Agnus, 0.5M Chip + 0.5M Slow + roms[0] = 6; + roms[1] = 32; + break; + case 2: // KS 1.3, ECS Agnus, 1.0M Chip + roms[0] = 6; + roms[1] = 32; + p->bogomem_size = 0; + p->chipmem_size = 0x100000; + break; + case 3: // KS 1.3, OCS Agnus, 0.5M Chip + roms[0] = 6; + roms[1] = 32; + p->bogomem_size = 0; + p->chipset_mask = 0; + p->cs_rtc = 0; + p->dfxtype[1] = DRV_NONE; + break; + case 4: // KS 1.2, OCS Agnus, 0.5M Chip + roms[0] = 5; + roms[1] = 4; + roms[2] = 3; + p->bogomem_size = 0; + p->chipset_mask = 0; + p->cs_rtc = 0; + p->dfxtype[1] = DRV_NONE; + break; + case 5: // KS 1.2, OCS Agnus, 0.5M Chip + 0.5M Slow + roms[0] = 5; + roms[1] = 4; + roms[2] = 3; + p->chipset_mask = 0; + break; + } + set_68000_compa (p, compa); + p->cs_compatible = CP_A500; + built_in_chipset_prefs (p); + return configure_rom (p, roms, romcheck); +} + +static int bip_super (struct uae_prefs *p, int config, int compa, int romcheck) +{ + int roms[8]; + + roms[0] = 46; + roms[1] = 16; + roms[2] = 31; + roms[3] = 15; + roms[4] = 14; + roms[5] = 12; + roms[6] = 11; + roms[7] = -1; p->bogomem_size = 0; - p->chipset_mask = 0; - p->cs_rtc = 0; - p->dfxtype[1] = DRV_NONE; - break; - case 4: // KS 1.2, OCS Agnus, 0.5M Chip - roms[0] = 5; - roms[1] = 4; - roms[2] = 3; + p->chipmem_size = 0x400000; + p->z3fastmem_size = 8 * 1024 * 1024; + p->gfxmem_size = 8 * 1024 * 1024; + p->cpu_model = 68040; + p->fpu_model = 68040; + p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + p->cpu_compatible = p->address_space_24 = 0; + p->m68k_speed = -1; + p->immediate_blits = 1; + p->produce_sound = 2; + p->cachesize = 8192; + p->dfxtype[0] = DRV_35_HD; + p->dfxtype[1] = DRV_35_HD; + p->floppy_speed = 0; + p->cpu_idle = 150; + p->scsi = 1; + p->uaeserial = 1; + p->socket_emu = 1; + p->cart_internal = 0; + p->picasso96_nocustom = 1; + p->cs_compatible = 1; + built_in_chipset_prefs (p); + p->cs_ide = -1; + p->cs_ciaatod = p->ntscmode ? 2 : 1; + //_tcscat(p->flashfile, L"battclock.nvr"); + return configure_rom (p, roms, romcheck); +} + +static int bip_arcadia (struct uae_prefs *p, int config, int compa, int romcheck) +{ + int roms[4]; + p->bogomem_size = 0; p->chipset_mask = 0; p->cs_rtc = 0; + p->nr_floppies = 0; + p->dfxtype[0] = DRV_NONE; p->dfxtype[1] = DRV_NONE; - break; - case 5: // KS 1.2, OCS Agnus, 0.5M Chip + 0.5M Slow + set_68000_compa (p, compa); + p->cs_compatible = CP_A500; + built_in_chipset_prefs (p); + fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); + _tcscat (p->flashfile, L"arcadia.nvr"); roms[0] = 5; roms[1] = 4; - roms[2] = 3; - p->chipset_mask = 0; - break; - } - set_68000_compa (p, compa); - p->cs_compatible = CP_A500; - built_in_chipset_prefs (p); - return configure_rom (p, roms, romcheck); -} - -static int bip_super (struct uae_prefs *p, int config, int compa, int romcheck) -{ - int roms[8]; - - roms[0] = 46; - roms[1] = 16; - roms[2] = 31; - roms[3] = 15; - roms[4] = 14; - roms[5] = 12; - roms[6] = 11; - roms[7] = -1; - p->bogomem_size = 0; - p->chipmem_size = 0x400000; - p->z3fastmem_size = 8 * 1024 * 1024; - p->gfxmem_size = 8 * 1024 * 1024; - p->cpu_model = 68040; - p->fpu_model = 68040; - p->chipset_mask = CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - p->cpu_compatible = p->address_space_24 = 0; - p->m68k_speed = -1; - p->immediate_blits = 1; - p->produce_sound = 2; - p->cachesize = 8192; - p->dfxtype[0] = DRV_35_HD; - p->dfxtype[1] = DRV_35_HD; - p->floppy_speed = 0; - p->cpu_idle = 150; - p->scsi = 1; - p->uaeserial = 1; - p->socket_emu = 1; - p->cart_internal = 0; - p->picasso96_nocustom = 1; - p->cs_compatible = 1; - built_in_chipset_prefs (p); - p->cs_ide = -1; - p->cs_ciaatod = p->ntscmode ? 2 : 1; - //_tcscat(p->flashfile, L"battclock.nvr"); - return configure_rom (p, roms, romcheck); -} - - static int bip_arcadia (struct uae_prefs *p, int config, int compa, int romcheck) - { - int roms[4]; - - p->bogomem_size = 0; - p->chipset_mask = 0; - p->cs_rtc = 0; - p->nr_floppies = 0; - p->dfxtype[0] = DRV_NONE; - p->dfxtype[1] = DRV_NONE; - set_68000_compa (p, compa); - p->cs_compatible = CP_A500; - built_in_chipset_prefs (p); - fetch_datapath (p->flashfile, sizeof (p->flashfile) / sizeof (TCHAR)); - _tcscat (p->flashfile, L"arcadia.nvr"); - roms[0] = 5; - roms[1] = 4; - roms[2] = -1; - if (!configure_rom (p, roms, romcheck)) - return 0; - roms[0] = 49; - roms[1] = 50; - roms[2] = 51; - roms[3] = -1; - if (!configure_rom (p, roms, romcheck)) - return 0; - return 1; + roms[2] = -1; + if (!configure_rom (p, roms, romcheck)) + return 0; + roms[0] = 49; + roms[1] = 50; + roms[2] = 51; + roms[3] = -1; + if (!configure_rom (p, roms, romcheck)) + return 0; + return 1; } int built_in_prefs (struct uae_prefs *p, int model, int config, int compa, int romcheck) { - int v = 0, i; - - buildin_default_prefs (p); - switch (model) - { - case 0: - v = bip_a500 (p, config, compa, romcheck); - break; - case 1: - v = bip_a500p (p, config, compa, romcheck); - break; - case 2: - v = bip_a600 (p, config, compa, romcheck); - break; - case 3: - v = bip_a1000 (p, config, compa, romcheck); - break; - case 4: - v = bip_a1200 (p, config, compa, romcheck); - break; - case 5: - v = bip_a3000 (p, config, compa, romcheck); - break; - case 6: - v = bip_a4000 (p, config, compa, romcheck); - break; - case 7: - v = bip_a4000t (p, config, compa, romcheck); - break; - case 8: - v = bip_cd32 (p, config, compa, romcheck); - break; - case 9: - v = bip_cdtv (p, config, compa, romcheck); - break; - case 10: - v = bip_arcadia (p, config , compa, romcheck); - break; - case 11: - v = bip_super (p, config, compa, romcheck); - break; - } - for (i = 0; i < 4; i++) { - if (p->dfxtype[i] < 0) - p->df[i][0] = DRV_35_DD; - } - return v; + int v = 0, i; + + buildin_default_prefs (p); + switch (model) + { + case 0: + v = bip_a500 (p, config, compa, romcheck); + break; + case 1: + v = bip_a500p (p, config, compa, romcheck); + break; + case 2: + v = bip_a600 (p, config, compa, romcheck); + break; + case 3: + v = bip_a1000 (p, config, compa, romcheck); + break; + case 4: + v = bip_a1200 (p, config, compa, romcheck); + break; + case 5: + v = bip_a3000 (p, config, compa, romcheck); + break; + case 6: + v = bip_a4000 (p, config, compa, romcheck); + break; + case 7: + v = bip_a4000t (p, config, compa, romcheck); + break; + case 8: + v = bip_cd32 (p, config, compa, romcheck); + break; + case 9: + v = bip_cdtv (p, config, compa, romcheck); + break; + case 10: + v = bip_arcadia (p, config , compa, romcheck); + break; + case 11: + v = bip_super (p, config, compa, romcheck); + break; + } + for (i = 0; i < 4; i++) { + if (p->dfxtype[i] < 0) + p->df[i][0] = DRV_35_DD; + } + return v; } int built_in_chipset_prefs (struct uae_prefs *p) { - if (!p->cs_compatible) - return 1; + if (!p->cs_compatible) + return 1; - p->cs_a1000ram = 0; - p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; - p->cs_cdtvcd = p->cs_cdtvram = 0; - p->cs_fatgaryrev = -1; - p->cs_ide = 0; - p->cs_ramseyrev = -1; - p->cs_deniserev = -1; - p->cs_agnusrev = -1; - p->cs_mbdmac = 0; - p->cs_a2091 = 0; - p->cs_pcmcia = 0; - p->cs_ksmirror_e0 = 1; - p->cs_ciaoverlay = 1; - p->cs_ciaatod = 0; - p->cs_df0idhw = 1; - p->cs_resetwarning = 1; - - switch (p->cs_compatible) - { - case CP_GENERIC: // generic - p->cs_rtc = 2; - p->cs_fatgaryrev = 0; - p->cs_ide = -1; - p->cs_mbdmac = 1; - p->cs_ramseyrev = 0x0f; - break; - case CP_CDTV: // CDTV - p->cs_rtc = 1; - p->cs_cdtvcd = p->cs_cdtvram = 1; - p->cs_df0idhw = 1; - p->cs_ksmirror_e0 = 0; - break; - case CP_CD32: // CD32 - p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 1; - p->cs_ksmirror_e0 = 0; - p->cs_ksmirror_a8 = 1; - p->cs_ciaoverlay = 0; - p->cs_resetwarning = 0; - break; - case CP_A500: // A500 - p->cs_df0idhw = 0; - p->cs_resetwarning = 0; - if (p->bogomem_size || p->chipmem_size > 1 || p->fastmem_size) - p->cs_rtc = 1; - break; - case CP_A500P: // A500+ - p->cs_rtc = 1; - p->cs_resetwarning = 0; - break; - case CP_A600: // A600 - p->cs_rtc = 1; - p->cs_ide = IDE_A600A1200; - p->cs_pcmcia = 1; - p->cs_ksmirror_a8 = 1; - p->cs_ciaoverlay = 0; - p->cs_resetwarning = 0; - break; - case CP_A1000: // A1000 - p->cs_a1000ram = 1; - p->cs_ciaatod = p->ntscmode ? 2 : 1; - p->cs_ksmirror_e0 = 0; - p->cs_rtc = 0; - p->cs_agnusbltbusybug = 1; - break; - case CP_A1200: // A1200 - p->cs_ide = IDE_A600A1200; - p->cs_pcmcia = 1; - p->cs_ksmirror_a8 = 1; - p->cs_ciaoverlay = 0; - break; - case CP_A2000: // A2000 - p->cs_rtc = 1; - p->cs_ciaatod = p->ntscmode ? 2 : 1; - break; - case CP_A3000: // A3000 - p->cs_rtc = 2; - p->cs_fatgaryrev = 0; - p->cs_ramseyrev = 0x0d; - p->cs_mbdmac = 1; - p->cs_ciaatod = p->ntscmode ? 2 : 1; - break; - case CP_A3000T: // A3000T - p->cs_rtc = 2; - p->cs_fatgaryrev = 0; - p->cs_ramseyrev = 0x0d; - p->cs_mbdmac = 1; - p->cs_ciaatod = p->ntscmode ? 2 : 1; - break; - case CP_A4000: // A4000 - p->cs_rtc = 2; - p->cs_fatgaryrev = 0; - p->cs_ramseyrev = 0x0f; - p->cs_ide = IDE_A4000; + p->cs_a1000ram = 0; + p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 0; + p->cs_cdtvcd = p->cs_cdtvram = 0; + p->cs_fatgaryrev = -1; + p->cs_ide = 0; + p->cs_ramseyrev = -1; + p->cs_deniserev = -1; + p->cs_agnusrev = -1; p->cs_mbdmac = 0; - p->cs_ksmirror_a8 = 1; - p->cs_ciaoverlay = 0; - break; - case CP_A4000T: // A4000T - p->cs_rtc = 2; - p->cs_fatgaryrev = 0; - p->cs_ramseyrev = 0x0f; - p->cs_ide = IDE_A4000; - p->cs_mbdmac = 2; - p->cs_ksmirror_a8 = 1; - p->cs_ciaoverlay = 0; - break; - } - return 1; + p->cs_a2091 = 0; + p->cs_pcmcia = 0; + p->cs_ksmirror_e0 = 1; + p->cs_ciaoverlay = 1; + p->cs_ciaatod = 0; + p->cs_df0idhw = 1; + p->cs_resetwarning = 1; + + switch (p->cs_compatible) + { + case CP_GENERIC: // generic + p->cs_rtc = 2; + p->cs_fatgaryrev = 0; + p->cs_ide = -1; + p->cs_mbdmac = 1; + p->cs_ramseyrev = 0x0f; + break; + case CP_CDTV: // CDTV + p->cs_rtc = 1; + p->cs_cdtvcd = p->cs_cdtvram = 1; + p->cs_df0idhw = 1; + p->cs_ksmirror_e0 = 0; + break; + case CP_CD32: // CD32 + p->cs_cd32c2p = p->cs_cd32cd = p->cs_cd32nvram = 1; + p->cs_ksmirror_e0 = 0; + p->cs_ksmirror_a8 = 1; + p->cs_ciaoverlay = 0; + p->cs_resetwarning = 0; + break; + case CP_A500: // A500 + p->cs_df0idhw = 0; + p->cs_resetwarning = 0; + if (p->bogomem_size || p->chipmem_size > 1 || p->fastmem_size) + p->cs_rtc = 1; + break; + case CP_A500P: // A500+ + p->cs_rtc = 1; + p->cs_resetwarning = 0; + break; + case CP_A600: // A600 + p->cs_rtc = 1; + p->cs_ide = IDE_A600A1200; + p->cs_pcmcia = 1; + p->cs_ksmirror_a8 = 1; + p->cs_ciaoverlay = 0; + p->cs_resetwarning = 0; + break; + case CP_A1000: // A1000 + p->cs_a1000ram = 1; + p->cs_ciaatod = p->ntscmode ? 2 : 1; + p->cs_ksmirror_e0 = 0; + p->cs_rtc = 0; + p->cs_agnusbltbusybug = 1; + break; + case CP_A1200: // A1200 + p->cs_ide = IDE_A600A1200; + p->cs_pcmcia = 1; + p->cs_ksmirror_a8 = 1; + p->cs_ciaoverlay = 0; + break; + case CP_A2000: // A2000 + p->cs_rtc = 1; + p->cs_ciaatod = p->ntscmode ? 2 : 1; + break; + case CP_A3000: // A3000 + p->cs_rtc = 2; + p->cs_fatgaryrev = 0; + p->cs_ramseyrev = 0x0d; + p->cs_mbdmac = 1; + p->cs_ciaatod = p->ntscmode ? 2 : 1; + break; + case CP_A3000T: // A3000T + p->cs_rtc = 2; + p->cs_fatgaryrev = 0; + p->cs_ramseyrev = 0x0d; + p->cs_mbdmac = 1; + p->cs_ciaatod = p->ntscmode ? 2 : 1; + break; + case CP_A4000: // A4000 + p->cs_rtc = 2; + p->cs_fatgaryrev = 0; + p->cs_ramseyrev = 0x0f; + p->cs_ide = IDE_A4000; + p->cs_mbdmac = 0; + p->cs_ksmirror_a8 = 1; + p->cs_ciaoverlay = 0; + break; + case CP_A4000T: // A4000T + p->cs_rtc = 2; + p->cs_fatgaryrev = 0; + p->cs_ramseyrev = 0x0f; + p->cs_ide = IDE_A4000; + p->cs_mbdmac = 2; + p->cs_ksmirror_a8 = 1; + p->cs_ciaoverlay = 0; + break; + } + return 1; } diff --git a/cia.c b/cia.c index e8fa8b6f..e2039387 100644 --- a/cia.c +++ b/cia.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * CIA chip support - * - * Copyright 1995 Bernd Schmidt, Alessandro Bissacco - * Copyright 1996, 1997 Stefan Reinauer, Christian Schmitt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* CIA chip support +* +* Copyright 1995 Bernd Schmidt, Alessandro Bissacco +* Copyright 1996, 1997 Stefan Reinauer, Christian Schmitt +*/ #include "sysconfig.h" @@ -75,258 +75,258 @@ static int warned = 10; static void setclr (unsigned int *p, unsigned int val) { - if (val & 0x80) { - *p |= val & 0x7F; - } else { - *p &= ~val; - } + if (val & 0x80) { + *p |= val & 0x7F; + } else { + *p &= ~val; + } } #include "newcpu.h" static void RethinkICRA (void) { - if (ciaaimask & ciaaicr) { - ciaaicr |= 0x80; - INTREQ_0 (0x8000 | 0x0008); - } + if (ciaaimask & ciaaicr) { + ciaaicr |= 0x80; + INTREQ_0 (0x8000 | 0x0008); + } } static void RethinkICRB (void) { - if (ciabimask & ciabicr) { - ciabicr |= 0x80; - INTREQ_0 (0x8000 | 0x2000); - } + if (ciabimask & ciabicr) { + ciabicr |= 0x80; + INTREQ_0 (0x8000 | 0x2000); + } } void rethink_cias (void) { - RethinkICRA (); - RethinkICRB (); + RethinkICRA (); + RethinkICRB (); } /* Figure out how many CIA timer cycles have passed for each timer since the - last call of CIA_calctimers. */ +last call of CIA_calctimers. */ static void compute_passed_time (void) { - unsigned long int ccount = (get_cycles () - eventtab[ev_cia].oldcycles + div10); - unsigned long int ciaclocks = ccount / DIV10; - - ciaata_passed = ciaatb_passed = ciabta_passed = ciabtb_passed = 0; - - /* CIA A timers */ - if ((ciaacra & 0x21) == 0x01) { - assert ((ciaata + 1) >= ciaclocks); - ciaata_passed = ciaclocks; - } - if ((ciaacrb & 0x61) == 0x01) { - assert ((ciaatb + 1) >= ciaclocks); - ciaatb_passed = ciaclocks; - } - - /* CIA B timers */ - if ((ciabcra & 0x21) == 0x01) { - assert ((ciabta + 1) >= ciaclocks); - ciabta_passed = ciaclocks; - } - if ((ciabcrb & 0x61) == 0x01) { - assert ((ciabtb + 1) >= ciaclocks); - ciabtb_passed = ciaclocks; - } + unsigned long int ccount = (get_cycles () - eventtab[ev_cia].oldcycles + div10); + unsigned long int ciaclocks = ccount / DIV10; + + ciaata_passed = ciaatb_passed = ciabta_passed = ciabtb_passed = 0; + + /* CIA A timers */ + if ((ciaacra & 0x21) == 0x01) { + assert ((ciaata + 1) >= ciaclocks); + ciaata_passed = ciaclocks; + } + if ((ciaacrb & 0x61) == 0x01) { + assert ((ciaatb + 1) >= ciaclocks); + ciaatb_passed = ciaclocks; + } + + /* CIA B timers */ + if ((ciabcra & 0x21) == 0x01) { + assert ((ciabta + 1) >= ciaclocks); + ciabta_passed = ciaclocks; + } + if ((ciabcrb & 0x61) == 0x01) { + assert ((ciabtb + 1) >= ciaclocks); + ciabtb_passed = ciaclocks; + } } /* Called to advance all CIA timers to the current time. This expects that - one of the timer values will be modified, and CIA_calctimers will be called - in the same cycle. */ +one of the timer values will be modified, and CIA_calctimers will be called +in the same cycle. */ static void CIA_update (void) { - unsigned long int ccount = (get_cycles () - eventtab[ev_cia].oldcycles + div10); - unsigned long int ciaclocks = ccount / DIV10; - - int aovfla = 0, aovflb = 0, asp = 0, bovfla = 0, bovflb = 0, bsp = 0; - - div10 = ccount % DIV10; - - /* CIA A timers */ - if ((ciaacra & 0x21) == 0x01) { - assert ((ciaata + 1) >= ciaclocks); - if ((ciaata + 1) == ciaclocks) { - if ((ciaacra & 0x48) == 0x40 && ciaasdr_cnt > 0 && --ciaasdr_cnt == 0) - asp = 1; - aovfla = 1; - if ((ciaacrb & 0x61) == 0x41 || (ciaacrb & 0x61) == 0x61) { - if (ciaatb-- == 0) - aovflb = 1; - } + unsigned long int ccount = (get_cycles () - eventtab[ev_cia].oldcycles + div10); + unsigned long int ciaclocks = ccount / DIV10; + + int aovfla = 0, aovflb = 0, asp = 0, bovfla = 0, bovflb = 0, bsp = 0; + + div10 = ccount % DIV10; + + /* CIA A timers */ + if ((ciaacra & 0x21) == 0x01) { + assert ((ciaata + 1) >= ciaclocks); + if ((ciaata + 1) == ciaclocks) { + if ((ciaacra & 0x48) == 0x40 && ciaasdr_cnt > 0 && --ciaasdr_cnt == 0) + asp = 1; + aovfla = 1; + if ((ciaacrb & 0x61) == 0x41 || (ciaacrb & 0x61) == 0x61) { + if (ciaatb-- == 0) + aovflb = 1; + } + } + ciaata -= ciaclocks; } - ciaata -= ciaclocks; - } - if ((ciaacrb & 0x61) == 0x01) { - assert ((ciaatb + 1) >= ciaclocks); - if ((ciaatb + 1) == ciaclocks) aovflb = 1; - ciaatb -= ciaclocks; - } - - /* CIA B timers */ - if ((ciabcra & 0x21) == 0x01) { - assert ((ciabta + 1) >= ciaclocks); - if ((ciabta + 1) == ciaclocks) { - if ((ciabcra & 0x48) == 0x40 && ciabsdr_cnt > 0 && --ciabsdr_cnt == 0) - bsp = 1; - bovfla = 1; - if ((ciabcrb & 0x61) == 0x41 || (ciabcrb & 0x61) == 0x61) { - if (ciabtb-- == 0) - bovflb = 1; - } + if ((ciaacrb & 0x61) == 0x01) { + assert ((ciaatb + 1) >= ciaclocks); + if ((ciaatb + 1) == ciaclocks) aovflb = 1; + ciaatb -= ciaclocks; + } + + /* CIA B timers */ + if ((ciabcra & 0x21) == 0x01) { + assert ((ciabta + 1) >= ciaclocks); + if ((ciabta + 1) == ciaclocks) { + if ((ciabcra & 0x48) == 0x40 && ciabsdr_cnt > 0 && --ciabsdr_cnt == 0) + bsp = 1; + bovfla = 1; + if ((ciabcrb & 0x61) == 0x41 || (ciabcrb & 0x61) == 0x61) { + if (ciabtb-- == 0) + bovflb = 1; + } + } + ciabta -= ciaclocks; + } + if ((ciabcrb & 0x61) == 0x01) { + assert ((ciabtb + 1) >= ciaclocks); + if ((ciabtb + 1) == ciaclocks) bovflb = 1; + ciabtb -= ciaclocks; + } + + if (aovfla) { + ciaaicr |= 1; RethinkICRA (); + ciaata = ciaala; + if (ciaacra & 0x8) ciaacra &= ~1; + } + if (aovflb) { + ciaaicr |= 2; RethinkICRA (); + ciaatb = ciaalb; + if (ciaacrb & 0x8) ciaacrb &= ~1; + } + if (asp) { + ciaaicr |= 8; RethinkICRA (); + } + if (bovfla) { + ciabicr |= 1; RethinkICRB (); + ciabta = ciabla; + if (ciabcra & 0x8) ciabcra &= ~1; + } + if (bovflb) { + ciabicr |= 2; RethinkICRB (); + ciabtb = ciablb; + if (ciabcrb & 0x8) ciabcrb &= ~1; + } + if (bsp) { + ciabicr |= 8; RethinkICRB (); } - ciabta -= ciaclocks; - } - if ((ciabcrb & 0x61) == 0x01) { - assert ((ciabtb + 1) >= ciaclocks); - if ((ciabtb + 1) == ciaclocks) bovflb = 1; - ciabtb -= ciaclocks; - } - - if (aovfla) { - ciaaicr |= 1; RethinkICRA (); - ciaata = ciaala; - if (ciaacra & 0x8) ciaacra &= ~1; - } - if (aovflb) { - ciaaicr |= 2; RethinkICRA (); - ciaatb = ciaalb; - if (ciaacrb & 0x8) ciaacrb &= ~1; - } - if (asp) { - ciaaicr |= 8; RethinkICRA (); - } - if (bovfla) { - ciabicr |= 1; RethinkICRB (); - ciabta = ciabla; - if (ciabcra & 0x8) ciabcra &= ~1; - } - if (bovflb) { - ciabicr |= 2; RethinkICRB (); - ciabtb = ciablb; - if (ciabcrb & 0x8) ciabcrb &= ~1; - } - if (bsp) { - ciabicr |= 8; RethinkICRB (); - } } /* Call this only after CIA_update has been called in the same cycle. */ static void CIA_calctimers (void) { - long int ciaatimea = -1, ciaatimeb = -1, ciabtimea = -1, ciabtimeb = -1; - - eventtab[ev_cia].oldcycles = get_cycles (); - if ((ciaacra & 0x21) == 0x01) { - ciaatimea = (DIV10 - div10) + DIV10 * ciaata; - } - if ((ciaacrb & 0x61) == 0x41) { - /* Timer B will not get any pulses if Timer A is off. */ - if (ciaatimea >= 0) { - /* If Timer A is in one-shot mode, and Timer B needs more than - * one pulse, it will not underflow. */ - if (ciaatb == 0 || (ciaacra & 0x8) == 0) { - /* Otherwise, we can determine the time of the underflow. */ - /* This may overflow, however. So just ignore this timer and - use the fact that we'll call CIA_handler for the A timer. */ + long int ciaatimea = -1, ciaatimeb = -1, ciabtimea = -1, ciabtimeb = -1; + + eventtab[ev_cia].oldcycles = get_cycles (); + if ((ciaacra & 0x21) == 0x01) { + ciaatimea = (DIV10 - div10) + DIV10 * ciaata; + } + if ((ciaacrb & 0x61) == 0x41) { + /* Timer B will not get any pulses if Timer A is off. */ + if (ciaatimea >= 0) { + /* If Timer A is in one-shot mode, and Timer B needs more than + * one pulse, it will not underflow. */ + if (ciaatb == 0 || (ciaacra & 0x8) == 0) { + /* Otherwise, we can determine the time of the underflow. */ + /* This may overflow, however. So just ignore this timer and + use the fact that we'll call CIA_handler for the A timer. */ #if 0 - ciaatimeb = ciaatimea + ciaala * DIV10 * ciaatb; + ciaatimeb = ciaatimea + ciaala * DIV10 * ciaatb; #endif - } + } + } + } + if ((ciaacrb & 0x61) == 0x01) { + ciaatimeb = (DIV10 - div10) + DIV10 * ciaatb; } - } - if ((ciaacrb & 0x61) == 0x01) { - ciaatimeb = (DIV10 - div10) + DIV10 * ciaatb; - } - - if ((ciabcra & 0x21) == 0x01) { - ciabtimea = (DIV10 - div10) + DIV10 * ciabta; - } - if ((ciabcrb & 0x61) == 0x41) { - /* Timer B will not get any pulses if Timer A is off. */ - if (ciabtimea >= 0) { - /* If Timer A is in one-shot mode, and Timer B needs more than - * one pulse, it will not underflow. */ - if (ciabtb == 0 || (ciabcra & 0x8) == 0) { - /* Otherwise, we can determine the time of the underflow. */ + + if ((ciabcra & 0x21) == 0x01) { + ciabtimea = (DIV10 - div10) + DIV10 * ciabta; + } + if ((ciabcrb & 0x61) == 0x41) { + /* Timer B will not get any pulses if Timer A is off. */ + if (ciabtimea >= 0) { + /* If Timer A is in one-shot mode, and Timer B needs more than + * one pulse, it will not underflow. */ + if (ciabtb == 0 || (ciabcra & 0x8) == 0) { + /* Otherwise, we can determine the time of the underflow. */ #if 0 - ciabtimeb = ciabtimea + ciabla * DIV10 * ciabtb; + ciabtimeb = ciabtimea + ciabla * DIV10 * ciabtb; #endif - } + } + } + } + if ((ciabcrb & 0x61) == 0x01) { + ciabtimeb = (DIV10 - div10) + DIV10 * ciabtb; + } + eventtab[ev_cia].active = (ciaatimea != -1 || ciaatimeb != -1 + || ciabtimea != -1 || ciabtimeb != -1); + if (eventtab[ev_cia].active) { + unsigned long int ciatime = ~0L; + if (ciaatimea != -1) ciatime = ciaatimea; + if (ciaatimeb != -1 && ciaatimeb < ciatime) ciatime = ciaatimeb; + if (ciabtimea != -1 && ciabtimea < ciatime) ciatime = ciabtimea; + if (ciabtimeb != -1 && ciabtimeb < ciatime) ciatime = ciabtimeb; + eventtab[ev_cia].evtime = ciatime + get_cycles (); } - } - if ((ciabcrb & 0x61) == 0x01) { - ciabtimeb = (DIV10 - div10) + DIV10 * ciabtb; - } - eventtab[ev_cia].active = (ciaatimea != -1 || ciaatimeb != -1 - || ciabtimea != -1 || ciabtimeb != -1); - if (eventtab[ev_cia].active) { - unsigned long int ciatime = ~0L; - if (ciaatimea != -1) ciatime = ciaatimea; - if (ciaatimeb != -1 && ciaatimeb < ciatime) ciatime = ciaatimeb; - if (ciabtimea != -1 && ciabtimea < ciatime) ciatime = ciabtimea; - if (ciabtimeb != -1 && ciabtimeb < ciatime) ciatime = ciabtimeb; - eventtab[ev_cia].evtime = ciatime + get_cycles (); - } - events_schedule(); + events_schedule(); } void CIA_handler (void) { - CIA_update (); - CIA_calctimers (); + CIA_update (); + CIA_calctimers (); } void cia_diskindex (void) { - ciabicr |= 0x10; - RethinkICRB (); + ciabicr |= 0x10; + RethinkICRB (); } void cia_parallelack (void) { - ciaaicr |= 0x10; - RethinkICRA (); + ciaaicr |= 0x10; + RethinkICRA (); } static int checkalarm (unsigned long tod, unsigned long alarm, int inc) { - if (tod == alarm) - return 1; - if (!inc) - return 0; - /* emulate buggy TODMED counter. - * it counts: .. 29 2A 2B 2C 2D 2E 2F 20 30 31 32 .. - * (2F->20->30 only takes couple of cycles but it will trigger alarm.. - */ - if (tod & 0x000fff) + if (tod == alarm) + return 1; + if (!inc) + return 0; + /* emulate buggy TODMED counter. + * it counts: .. 29 2A 2B 2C 2D 2E 2F 20 30 31 32 .. + * (2F->20->30 only takes couple of cycles but it will trigger alarm.. + */ + if (tod & 0x000fff) + return 0; + if (((tod - 1) & 0xfff000) == alarm) + return 1; return 0; - if (((tod - 1) & 0xfff000) == alarm) - return 1; - return 0; } STATIC_INLINE void ciab_checkalarm (int inc) { - if (checkalarm (ciabtod, ciabalarm, inc)) { - ciabicr |= 4; - RethinkICRB (); - } + if (checkalarm (ciabtod, ciabalarm, inc)) { + ciabicr |= 4; + RethinkICRB (); + } } STATIC_INLINE void ciaa_checkalarm (int inc) { - if (checkalarm (ciaatod, ciaaalarm, inc)) { - ciaaicr |= 4; - RethinkICRA (); - } + if (checkalarm (ciaatod, ciaaalarm, inc)) { + ciaaicr |= 4; + RethinkICRA (); + } } @@ -335,872 +335,872 @@ static uae_u64 tod_hack_tv, tod_hack_tod, tod_hack_tod_last; static int tod_hack_enabled; static void tod_hack_reset (void) { - struct timeval tv; - gettimeofday (&tv, NULL); - tod_hack_tv = (uae_u64)tv.tv_sec * 1000000 + tv.tv_usec; - tod_hack_tod = ciaatod; - tod_hack_tod_last = tod_hack_tod; + struct timeval tv; + gettimeofday (&tv, NULL); + tod_hack_tv = (uae_u64)tv.tv_sec * 1000000 + tv.tv_usec; + tod_hack_tod = ciaatod; + tod_hack_tod_last = tod_hack_tod; } #endif static void do_tod_hack (int dotod) { - struct timeval tv; - static int oldrate; - uae_u64 t; - int rate; - int docount = 0; - - if (tod_hack_enabled == 0) - return; - if (tod_hack_enabled > 1) { - tod_hack_enabled--; - if (tod_hack_enabled == 1) { - write_log (L"TOD HACK enabled\n"); - tod_hack_reset (); + struct timeval tv; + static int oldrate; + uae_u64 t; + int rate; + int docount = 0; + + if (tod_hack_enabled == 0) + return; + if (tod_hack_enabled > 1) { + tod_hack_enabled--; + if (tod_hack_enabled == 1) { + write_log (L"TOD HACK enabled\n"); + tod_hack_reset (); + } + return; + } + + if (currprefs.cs_ciaatod == 0) + rate = vblank_hz; + else if (currprefs.cs_ciaatod == 1) + rate = 50; + else + rate = 60; + if (rate <= 0) + return; + if (rate != oldrate || ciaatod != tod_hack_tod_last) { + if (ciaatod != 0) + write_log (L"TOD HACK reset %d,%d %d,%d\n", + rate, oldrate, ciaatod, tod_hack_tod_last); + tod_hack_reset (); + oldrate = rate; + docount = 1; + } + if (!dotod && currprefs.cs_ciaatod == 0) + return; + gettimeofday (&tv, NULL); + t = (uae_u64)tv.tv_sec * 1000000 + tv.tv_usec; + if (t - tod_hack_tv >= 1000000 / rate) { + tod_hack_tv += 1000000 / rate; + docount = 1; + } + if (docount) { + ciaatod++; + ciaatod &= 0x00ffffff; + tod_hack_tod_last = ciaatod; + ciaa_checkalarm (0); } - return; - } - - if (currprefs.cs_ciaatod == 0) - rate = vblank_hz; - else if (currprefs.cs_ciaatod == 1) - rate = 50; - else - rate = 60; - if (rate <= 0) - return; - if (rate != oldrate || ciaatod != tod_hack_tod_last) { - if (ciaatod != 0) - write_log (L"TOD HACK reset %d,%d %d,%d\n", - rate, oldrate, ciaatod, tod_hack_tod_last); - tod_hack_reset (); - oldrate = rate; - docount = 1; - } - if (!dotod && currprefs.cs_ciaatod == 0) - return; - gettimeofday (&tv, NULL); - t = (uae_u64)tv.tv_sec * 1000000 + tv.tv_usec; - if (t - tod_hack_tv >= 1000000 / rate) { - tod_hack_tv += 1000000 / rate; - docount = 1; - } - if (docount) { - ciaatod++; - ciaatod &= 0x00ffffff; - tod_hack_tod_last = ciaatod; - ciaa_checkalarm (0); - } } static int resetwarning_phase, resetwarning_timer; static void setcode (uae_u8 keycode) { - ciaasdr = ~((keycode << 1) | (keycode >> 7)); + ciaasdr = ~((keycode << 1) | (keycode >> 7)); } static void sendrw (void) { - setcode (AK_RESETWARNING); - ciaasdr_unread = 1; - ciaaicr |= 8; - RethinkICRA (); - write_log (L"KB: sent reset warning code (phase=%d)\n", resetwarning_phase); + setcode (AK_RESETWARNING); + ciaasdr_unread = 1; + ciaaicr |= 8; + RethinkICRA (); + write_log (L"KB: sent reset warning code (phase=%d)\n", resetwarning_phase); } int resetwarning_do (int canreset) { - if (resetwarning_phase) { - /* just force reset if second reset happens during resetwarning */ - if (canreset) { - resetwarning_phase = 0; - resetwarning_timer = 0; + if (resetwarning_phase) { + /* just force reset if second reset happens during resetwarning */ + if (canreset) { + resetwarning_phase = 0; + resetwarning_timer = 0; + } + return 0; } - return 0; - } - resetwarning_phase = 1; - resetwarning_timer = maxvpos * 5; - write_log (L"KB: reset warning triggered\n"); - sendrw (); - return 1; + resetwarning_phase = 1; + resetwarning_timer = maxvpos * 5; + write_log (L"KB: reset warning triggered\n"); + sendrw (); + return 1; } static void resetwarning_check (void) { - if (resetwarning_timer > 0) { - resetwarning_timer--; - if (resetwarning_timer <= 0) { - write_log (L"KB: reset warning forced reset. Phase=%d\n", resetwarning_phase); - resetwarning_phase = -1; - uae_reset (0); + if (resetwarning_timer > 0) { + resetwarning_timer--; + if (resetwarning_timer <= 0) { + write_log (L"KB: reset warning forced reset. Phase=%d\n", resetwarning_phase); + resetwarning_phase = -1; + uae_reset (0); + } } - } - if (resetwarning_phase == 1) { - if (kback && !(ciaacra & 0x40) && ciaasdr_unread == 2) { - write_log (L"KB: reset warning second phase..\n"); - resetwarning_phase = 2; - resetwarning_timer = maxvpos * 5; - sendrw (); + if (resetwarning_phase == 1) { + if (kback && !(ciaacra & 0x40) && ciaasdr_unread == 2) { + write_log (L"KB: reset warning second phase..\n"); + resetwarning_phase = 2; + resetwarning_timer = maxvpos * 5; + sendrw (); + } + } else if (resetwarning_phase == 2) { + if (ciaacra & 0x40) { + resetwarning_phase = 3; + write_log (L"KB: reset warning SP = output\n"); + resetwarning_timer = 10 * maxvpos * vblank_hz; /* wait max 10s */ + } + } else if (resetwarning_phase == 3) { + if (!(ciaacra & 0x40)) { + write_log (L"KB: reset warning end by software. reset.\n"); + resetwarning_phase = -1; + uae_reset (0); + } } - } else if (resetwarning_phase == 2) { - if (ciaacra & 0x40) { - resetwarning_phase = 3; - write_log (L"KB: reset warning SP = output\n"); - resetwarning_timer = 10 * maxvpos * vblank_hz; /* wait max 10s */ - } - } else if (resetwarning_phase == 3) { - if (!(ciaacra & 0x40)) { - write_log (L"KB: reset warning end by software. reset.\n"); - resetwarning_phase = -1; - uae_reset (0); - } - } } void CIA_hsync_handler (int dotod) { - if (ciabtodon && dotod) { - ciabtod++; - ciabtod &= 0xFFFFFF; - ciab_checkalarm (1); - } - - if (currprefs.tod_hack && ciaatodon) - do_tod_hack (dotod); - - if (resetwarning_phase) { - resetwarning_check (); - while (keys_available ()) - get_next_key (); - } else if ((keys_available() || kbstate < 3) && kback && (ciaacra & 0x40) == 0 && (hsync_counter & 15) == 0) { - /* - * This hack lets one possible ciaaicr cycle go by without any key - * being read, for every cycle in which a key is pulled out of the - * queue. If no hack is used, a lot of key events just get lost - * when you type fast. With a simple hack that waits for ciaasdr - * to be read before feeding it another, it will keep up until the - * queue gets about 14 characters ahead and then lose events, and - * the mouse pointer will freeze while typing is being taken in. - * With this hack, you can type 30 or 40 characters ahead with little - * or no lossage, and the mouse doesn't get stuck. The tradeoff is - * that the total slowness of typing appearing on screen is worse. - */ - if (ciaasdr_unread == 2) { - ciaasdr_unread = 0; - } else if (ciaasdr_unread == 0) { - switch (kbstate) { - case 0: - ciaasdr = 0; /* powerup resync */ - kbstate++; - ciaasdr_unread = 3; - break; - case 1: - setcode (AK_INIT_POWERUP); - kbstate++; - ciaasdr_unread = 3; - break; - case 2: - setcode (AK_TERM_POWERUP); - kbstate++; - ciaasdr_unread = 3; - break; - case 3: - ciaasdr = ~get_next_key (); - ciaasdr_unread = 1; /* interlock to prevent lost keystrokes */ - break; - } - ciaaicr |= 8; - RethinkICRA (); - sleepyhead = 0; - } else if (!(++sleepyhead & 15)) { - if (ciaasdr_unread == 3) - ciaaicr |= 8; - if (ciaasdr_unread < 3) - ciaasdr_unread = 0; /* give up on this key event after unread for a long time */ + if (ciabtodon && dotod) { + ciabtod++; + ciabtod &= 0xFFFFFF; + ciab_checkalarm (1); + } + + if (currprefs.tod_hack && ciaatodon) + do_tod_hack (dotod); + + if (resetwarning_phase) { + resetwarning_check (); + while (keys_available ()) + get_next_key (); + } else if ((keys_available() || kbstate < 3) && kback && (ciaacra & 0x40) == 0 && (hsync_counter & 15) == 0) { + /* + * This hack lets one possible ciaaicr cycle go by without any key + * being read, for every cycle in which a key is pulled out of the + * queue. If no hack is used, a lot of key events just get lost + * when you type fast. With a simple hack that waits for ciaasdr + * to be read before feeding it another, it will keep up until the + * queue gets about 14 characters ahead and then lose events, and + * the mouse pointer will freeze while typing is being taken in. + * With this hack, you can type 30 or 40 characters ahead with little + * or no lossage, and the mouse doesn't get stuck. The tradeoff is + * that the total slowness of typing appearing on screen is worse. + */ + if (ciaasdr_unread == 2) { + ciaasdr_unread = 0; + } else if (ciaasdr_unread == 0) { + switch (kbstate) { + case 0: + ciaasdr = 0; /* powerup resync */ + kbstate++; + ciaasdr_unread = 3; + break; + case 1: + setcode (AK_INIT_POWERUP); + kbstate++; + ciaasdr_unread = 3; + break; + case 2: + setcode (AK_TERM_POWERUP); + kbstate++; + ciaasdr_unread = 3; + break; + case 3: + ciaasdr = ~get_next_key (); + ciaasdr_unread = 1; /* interlock to prevent lost keystrokes */ + break; + } + ciaaicr |= 8; + RethinkICRA (); + sleepyhead = 0; + } else if (!(++sleepyhead & 15)) { + if (ciaasdr_unread == 3) + ciaaicr |= 8; + if (ciaasdr_unread < 3) + ciaasdr_unread = 0; /* give up on this key event after unread for a long time */ + } } - } } static int led_times; static unsigned long led_on, led_cycle; - + static void calc_led (int old_led) { - unsigned long c = get_cycles (); - unsigned long t = c - led_cycle; - if (old_led) - led_on += t; - led_times++; - led_cycle = c; + unsigned long c = get_cycles (); + unsigned long t = c - led_cycle; + if (old_led) + led_on += t; + led_times++; + led_cycle = c; } static void led_vsync (void) { - gui_data.powerled_brightness = gui_data.powerled ? 255 : 0; - calc_led (gui_data.powerled); - if (led_on > 0 && led_times > 2) { - int v = led_on / CYCLE_UNIT * 256 / (maxhpos * maxvpos); - if (v < 0) - v = 0; - if (v > 255) - v = 255; - gui_data.powerled_brightness = v; - } - led_on = 0; - led_times = 0; - if (led_changed) - gui_led (0, gui_data.powerled_brightness); - led_changed = 0; - led_cycle = get_cycles (); + gui_data.powerled_brightness = gui_data.powerled ? 255 : 0; + calc_led (gui_data.powerled); + if (led_on > 0 && led_times > 2) { + int v = led_on / CYCLE_UNIT * 256 / (maxhpos * maxvpos); + if (v < 0) + v = 0; + if (v > 255) + v = 255; + gui_data.powerled_brightness = v; + } + led_on = 0; + led_times = 0; + if (led_changed) + gui_led (0, gui_data.powerled_brightness); + led_changed = 0; + led_cycle = get_cycles (); } void CIA_vsync_handler (int dotod) { - led_vsync (); + led_vsync (); #ifdef TOD_HACK - if (currprefs.tod_hack && tod_hack_enabled == 1) - return; + if (currprefs.tod_hack && tod_hack_enabled == 1) + return; #endif - if (ciaatodon && dotod) { - ciaatod++; - ciaatod &= 0xFFFFFF; - ciaa_checkalarm (1); - } + if (ciaatodon && dotod) { + ciaatod++; + ciaatod &= 0xFFFFFF; + ciaa_checkalarm (1); + } } static void bfe001_change (void) { - uae_u8 v = ciaapra; - int led; - - v |= ~ciaadra; /* output is high when pin's direction is input */ - led = (v & 2) ? 0 : 1; - if (led != oldled) { - calc_led (oldled); - oldled = led; - gui_data.powerled = led; - led_changed = 1; - led_filter_audio (); - } - if (currprefs.cs_ciaoverlay && (v & 1) != oldovl) { - oldovl = v & 1; - if (!oldovl || ersatzkickfile) { - map_overlay (1); - } else { - //activate_debugger (); - map_overlay (0); + uae_u8 v = ciaapra; + int led; + + v |= ~ciaadra; /* output is high when pin's direction is input */ + led = (v & 2) ? 0 : 1; + if (led != oldled) { + calc_led (oldled); + oldled = led; + gui_data.powerled = led; + led_changed = 1; + led_filter_audio (); + } + if (currprefs.cs_ciaoverlay && (v & 1) != oldovl) { + oldovl = v & 1; + if (!oldovl || ersatzkickfile) { + map_overlay (1); + } else { + //activate_debugger (); + map_overlay (0); + } } - } } static uae_u8 ReadCIAA (unsigned int addr) { - unsigned int tmp; - int reg = addr & 15; + unsigned int tmp; + int reg = addr & 15; - compute_passed_time (); + compute_passed_time (); #ifdef CIAA_DEBUG_R - write_log (L"R_CIAA: bfe%x01 %08X\n", reg, M68K_GETPC); + write_log (L"R_CIAA: bfe%x01 %08X\n", reg, M68K_GETPC); #endif - switch (reg) { - case 0: + switch (reg) { + case 0: #ifdef ACTION_REPLAY - action_replay_ciaread (); + action_replay_ciaread (); #endif - tmp = DISK_status() & 0x3c; - tmp |= handle_joystick_buttons (ciaadra); - tmp |= (ciaapra | (ciaadra ^ 3)) & 0x03; - if (ciaadra & 0x40) - tmp = (tmp & ~0x40) | (ciaapra & 0x40); - if (ciaadra & 0x80) - tmp = (tmp & ~0x80) | (ciaapra & 0x80); - tmp = dongle_cia_read (0, reg, tmp); + tmp = DISK_status() & 0x3c; + tmp |= handle_joystick_buttons (ciaadra); + tmp |= (ciaapra | (ciaadra ^ 3)) & 0x03; + if (ciaadra & 0x40) + tmp = (tmp & ~0x40) | (ciaapra & 0x40); + if (ciaadra & 0x80) + tmp = (tmp & ~0x80) | (ciaapra & 0x80); + tmp = dongle_cia_read (0, reg, tmp); #ifdef DONGLE_DEBUG - if (notinrom()) - write_log (L"BFE001 R %02X %s\n", tmp, debuginfo(0)); + if (notinrom()) + write_log (L"BFE001 R %02X %s\n", tmp, debuginfo(0)); #endif - return tmp; - case 1: + return tmp; + case 1: #ifdef PARALLEL_PORT - if (isprinter () > 0) { - tmp = ciaaprb; - } else if (isprinter () < 0) { - uae_u8 v; - parallel_direct_read_data (&v); - tmp = v; + if (isprinter () > 0) { + tmp = ciaaprb; + } else if (isprinter () < 0) { + uae_u8 v; + parallel_direct_read_data (&v); + tmp = v; #ifdef ARCADIA - } else if (arcadia_bios) { - tmp = arcadia_parport (0, ciaaprb, ciaadrb); + } else if (arcadia_bios) { + tmp = arcadia_parport (0, ciaaprb, ciaadrb); #endif - } else + } else #endif - { - tmp = handle_parport_joystick (0, ciaaprb, ciaadrb); - tmp = dongle_cia_read (1, reg, tmp); + { + tmp = handle_parport_joystick (0, ciaaprb, ciaadrb); + tmp = dongle_cia_read (1, reg, tmp); #ifdef DONGLE_DEBUG - if (notinrom()) - write_log (L"BFE101 R %02X %s\n", tmp, debuginfo(0)); + if (notinrom()) + write_log (L"BFE101 R %02X %s\n", tmp, debuginfo(0)); #endif - } - if (ciaacrb & 2) { - int pb7 = 0; - if (ciaacrb & 4) - pb7 = ciaacrb & 1; - tmp &= ~0x80; - tmp |= pb7 ? 0x80 : 00; - } - if (ciaacra & 2) { - int pb6 = 0; - if (ciaacra & 4) - pb6 = ciaacra & 1; - tmp &= ~0x40; - tmp |= pb6 ? 0x40 : 00; - } - return tmp; - case 2: + } + if (ciaacrb & 2) { + int pb7 = 0; + if (ciaacrb & 4) + pb7 = ciaacrb & 1; + tmp &= ~0x80; + tmp |= pb7 ? 0x80 : 00; + } + if (ciaacra & 2) { + int pb6 = 0; + if (ciaacra & 4) + pb6 = ciaacra & 1; + tmp &= ~0x40; + tmp |= pb6 ? 0x40 : 00; + } + return tmp; + case 2: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE201 R %02X %s\n", ciaadra, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE201 R %02X %s\n", ciaadra, debuginfo(0)); #endif - return ciaadra; - case 3: + return ciaadra; + case 3: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE301 R %02X %s\n", ciaadrb, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE301 R %02X %s\n", ciaadrb, debuginfo(0)); #endif - return ciaadrb; - case 4: - return (uae_u8)((ciaata - ciaata_passed) & 0xff); - case 5: - return (uae_u8)((ciaata - ciaata_passed) >> 8); - case 6: - return (uae_u8)((ciaatb - ciaatb_passed) & 0xff); - case 7: - return (uae_u8)((ciaatb - ciaatb_passed) >> 8); - case 8: - if (ciaatlatch) { - ciaatlatch = 0; - return (uae_u8)ciaatol; - } else - return (uae_u8)ciaatod; - case 9: - if (ciaatlatch) - return (uae_u8)(ciaatol >> 8); - else - return (uae_u8)(ciaatod >> 8); - case 10: - if (!ciaatlatch) { /* only if not already latched. A1200 confirmed. (TW) */ - /* no latching if ALARM is set */ - if (!(ciaacrb & 0x80)) - ciaatlatch = 1; - ciaatol = ciaatod; + return ciaadrb; + case 4: + return (uae_u8)((ciaata - ciaata_passed) & 0xff); + case 5: + return (uae_u8)((ciaata - ciaata_passed) >> 8); + case 6: + return (uae_u8)((ciaatb - ciaatb_passed) & 0xff); + case 7: + return (uae_u8)((ciaatb - ciaatb_passed) >> 8); + case 8: + if (ciaatlatch) { + ciaatlatch = 0; + return (uae_u8)ciaatol; + } else + return (uae_u8)ciaatod; + case 9: + if (ciaatlatch) + return (uae_u8)(ciaatol >> 8); + else + return (uae_u8)(ciaatod >> 8); + case 10: + if (!ciaatlatch) { /* only if not already latched. A1200 confirmed. (TW) */ + /* no latching if ALARM is set */ + if (!(ciaacrb & 0x80)) + ciaatlatch = 1; + ciaatol = ciaatod; + } + return (uae_u8)(ciaatol >> 16); + case 12: + if (ciaasdr_unread >= 1) + ciaasdr_unread = 2; + return ciaasdr; + case 13: + tmp = ciaaicr; ciaaicr = 0; RethinkICRA (); + return tmp; + case 14: + return ciaacra; + case 15: + return ciaacrb; } - return (uae_u8)(ciaatol >> 16); - case 12: - if (ciaasdr_unread >= 1) - ciaasdr_unread = 2; - return ciaasdr; - case 13: - tmp = ciaaicr; ciaaicr = 0; RethinkICRA (); - return tmp; - case 14: - return ciaacra; - case 15: - return ciaacrb; - } - return 0; + return 0; } static uae_u8 ReadCIAB (unsigned int addr) { - unsigned int tmp; - int reg = addr & 15; + unsigned int tmp; + int reg = addr & 15; #ifdef CIAB_DEBUG_R - if (addr >= 8 && addr <= 10) - write_log (L"R_CIAB: bfd%x00 %08X\n", reg, M68K_GETPC); + if (addr >= 8 && addr <= 10) + write_log (L"R_CIAB: bfd%x00 %08X\n", reg, M68K_GETPC); #endif - compute_passed_time (); + compute_passed_time (); - switch (reg) { - case 0: - tmp = 0; + switch (reg) { + case 0: + tmp = 0; #ifdef SERIAL_PORT - if (currprefs.use_serial) - tmp = serial_readstatus(ciabdra); + if (currprefs.use_serial) + tmp = serial_readstatus(ciabdra); #endif #ifdef PARALLEL_PORT - if (isprinter () > 0) { - tmp |= ciabpra & (0x04 | 0x02 | 0x01); - } else if (isprinter () < 0) { - uae_u8 v; - parallel_direct_read_status (&v); - tmp |= v & 7; - } else { - tmp |= handle_parport_joystick (1, ciabpra, ciabdra); - } + if (isprinter () > 0) { + tmp |= ciabpra & (0x04 | 0x02 | 0x01); + } else if (isprinter () < 0) { + uae_u8 v; + parallel_direct_read_status (&v); + tmp |= v & 7; + } else { + tmp |= handle_parport_joystick (1, ciabpra, ciabdra); + } #endif - tmp = dongle_cia_read (1, reg, tmp); + tmp = dongle_cia_read (1, reg, tmp); #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD000 R %02X %s\n", tmp, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD000 R %02X %s\n", tmp, debuginfo(0)); #endif - return tmp; - case 1: + return tmp; + case 1: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD100 R %02X %s\n", ciabprb, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD100 R %02X %s\n", ciabprb, debuginfo(0)); #endif - tmp = ciabprb; - tmp = dongle_cia_read (1, reg, tmp); - if (ciabcrb & 2) { - int pb7 = 0; - if (ciabcrb & 4) - pb7 = ciabcrb & 1; - tmp &= ~0x80; - tmp |= pb7 ? 0x80 : 00; - } - if (ciabcra & 2) { - int pb6 = 0; - if (ciabcra & 4) - pb6 = ciabcra & 1; - tmp &= ~0x40; - tmp |= pb6 ? 0x40 : 00; - } - return tmp; - case 2: - return ciabdra; - case 3: - return ciabdrb; - case 4: - return (uae_u8)((ciabta - ciabta_passed) & 0xff); - case 5: - return (uae_u8)((ciabta - ciabta_passed) >> 8); - case 6: - return (uae_u8)((ciabtb - ciabtb_passed) & 0xff); - case 7: - return (uae_u8)((ciabtb - ciabtb_passed) >> 8); - case 8: - if (ciabtlatch) { - ciabtlatch = 0; - return (uae_u8)ciabtol; - } else - return (uae_u8)ciabtod; - case 9: - if (ciabtlatch) - return (uae_u8)(ciabtol >> 8); - else - return (uae_u8)(ciabtod >> 8); - case 10: - if (!ciabtlatch) { - /* no latching if ALARM is set */ - if (!(ciabcrb & 0x80)) - ciabtlatch = 1; - ciabtol = ciabtod; + tmp = ciabprb; + tmp = dongle_cia_read (1, reg, tmp); + if (ciabcrb & 2) { + int pb7 = 0; + if (ciabcrb & 4) + pb7 = ciabcrb & 1; + tmp &= ~0x80; + tmp |= pb7 ? 0x80 : 00; + } + if (ciabcra & 2) { + int pb6 = 0; + if (ciabcra & 4) + pb6 = ciabcra & 1; + tmp &= ~0x40; + tmp |= pb6 ? 0x40 : 00; + } + return tmp; + case 2: + return ciabdra; + case 3: + return ciabdrb; + case 4: + return (uae_u8)((ciabta - ciabta_passed) & 0xff); + case 5: + return (uae_u8)((ciabta - ciabta_passed) >> 8); + case 6: + return (uae_u8)((ciabtb - ciabtb_passed) & 0xff); + case 7: + return (uae_u8)((ciabtb - ciabtb_passed) >> 8); + case 8: + if (ciabtlatch) { + ciabtlatch = 0; + return (uae_u8)ciabtol; + } else + return (uae_u8)ciabtod; + case 9: + if (ciabtlatch) + return (uae_u8)(ciabtol >> 8); + else + return (uae_u8)(ciabtod >> 8); + case 10: + if (!ciabtlatch) { + /* no latching if ALARM is set */ + if (!(ciabcrb & 0x80)) + ciabtlatch = 1; + ciabtol = ciabtod; + } + return (uae_u8)(ciabtol >> 16); + case 12: + return ciabsdr; + case 13: + tmp = ciabicr; ciabicr = 0; RethinkICRB (); + return tmp; + case 14: + return ciabcra; + case 15: + return ciabcrb; } - return (uae_u8)(ciabtol >> 16); - case 12: - return ciabsdr; - case 13: - tmp = ciabicr; ciabicr = 0; RethinkICRB (); - return tmp; - case 14: - return ciabcra; - case 15: - return ciabcrb; - } - return 0; + return 0; } static void WriteCIAA (uae_u16 addr, uae_u8 val) { - int reg = addr & 15; + int reg = addr & 15; #ifdef CIAA_DEBUG_W - write_log (L"W_CIAA: bfe%x01 %02X %08X\n", reg, val, M68K_GETPC); + write_log (L"W_CIAA: bfe%x01 %02X %08X\n", reg, val, M68K_GETPC); #endif #ifdef ACTION_REPLAY - ar_ciaa[reg] = val; + ar_ciaa[reg] = val; #endif - if (!currprefs.cs_ciaoverlay && oldovl) { - map_overlay (1); - oldovl = 0; - } - switch (reg) { - case 0: + if (!currprefs.cs_ciaoverlay && oldovl) { + map_overlay (1); + oldovl = 0; + } + switch (reg) { + case 0: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE001 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE001 W %02X %s\n", val, debuginfo(0)); #endif - ciaapra = (ciaapra & ~0xc3) | (val & 0xc3); - bfe001_change (); - handle_cd32_joystick_cia (ciaapra, ciaadra); - dongle_cia_write (0, reg, val); + ciaapra = (ciaapra & ~0xc3) | (val & 0xc3); + bfe001_change (); + handle_cd32_joystick_cia (ciaapra, ciaadra); + dongle_cia_write (0, reg, val); #ifdef AMAX - if (currprefs.amaxromfile[0]) - amax_bfe001_write (val, ciaadra); + if (currprefs.amaxromfile[0]) + amax_bfe001_write (val, ciaadra); #endif - break; - case 1: + break; + case 1: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE101 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE101 W %02X %s\n", val, debuginfo(0)); #endif - ciaaprb = val; - dongle_cia_write (0, reg, val); + ciaaprb = val; + dongle_cia_write (0, reg, val); #ifdef PARALLEL_PORT - if (isprinter() > 0) { - doprinter (val); - cia_parallelack (); - } else if (isprinter() < 0) { - parallel_direct_write_data (val, ciaadrb); - cia_parallelack (); + if (isprinter() > 0) { + doprinter (val); + cia_parallelack (); + } else if (isprinter() < 0) { + parallel_direct_write_data (val, ciaadrb); + cia_parallelack (); #ifdef ARCADIA - } else if (arcadia_bios) { - arcadia_parport (1, ciaaprb, ciaadrb); + } else if (arcadia_bios) { + arcadia_parport (1, ciaaprb, ciaadrb); #endif - } + } #endif - break; - case 2: + break; + case 2: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE201 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE201 W %02X %s\n", val, debuginfo(0)); #endif - ciaadra = val; - dongle_cia_write (0, reg, val); - bfe001_change (); - break; - case 3: - ciaadrb = val; - dongle_cia_write (0, reg, val); + ciaadra = val; + dongle_cia_write (0, reg, val); + bfe001_change (); + break; + case 3: + ciaadrb = val; + dongle_cia_write (0, reg, val); #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFE301 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFE301 W %02X %s\n", val, debuginfo(0)); #endif #ifdef ARCADIA - if (arcadia_bios) - arcadia_parport (1, ciaaprb, ciaadrb); + if (arcadia_bios) + arcadia_parport (1, ciaaprb, ciaadrb); #endif - break; - case 4: - CIA_update (); - ciaala = (ciaala & 0xff00) | val; - CIA_calctimers (); - break; - case 5: - CIA_update (); - ciaala = (ciaala & 0xff) | (val << 8); - if ((ciaacra & 1) == 0) - ciaata = ciaala; - if (ciaacra & 8) { - ciaata = ciaala; - ciaacra |= 1; - } - CIA_calctimers (); - break; - case 6: - CIA_update (); - ciaalb = (ciaalb & 0xff00) | val; - CIA_calctimers (); - break; - case 7: - CIA_update (); - ciaalb = (ciaalb & 0xff) | (val << 8); - if ((ciaacrb & 1) == 0) - ciaatb = ciaalb; - if (ciaacrb & 8) { - ciaatb = ciaalb; - ciaacrb |= 1; - } - CIA_calctimers (); - break; - case 8: - if (ciaacrb & 0x80) { - ciaaalarm = (ciaaalarm & ~0xff) | val; - } else { - ciaatod = (ciaatod & ~0xff) | val; - ciaatodon = 1; - ciaa_checkalarm (0); - } - break; - case 9: - if (ciaacrb & 0x80) { - ciaaalarm = (ciaaalarm & ~0xff00) | (val << 8); - } else { - ciaatod = (ciaatod & ~0xff00) | (val << 8); - } - break; - case 10: - if (ciaacrb & 0x80) { - ciaaalarm = (ciaaalarm & ~0xff0000) | (val << 16); - } else { - ciaatod = (ciaatod & ~0xff0000) | (val << 16); - ciaatodon = 0; - } - break; - case 12: - CIA_update (); - ciaasdr = val; - if (ciaacra & 0x40) { - kback = 1; - } else { - ciaasdr_cnt = 0; - } - if ((ciaacra & 0x41) == 0x41 && ciaasdr_cnt == 0) - ciaasdr_cnt = 8 * 2; - CIA_calctimers (); - break; - case 13: - setclr (&ciaaimask,val); - break; - case 14: - CIA_update (); - val &= 0x7f; /* bit 7 is unused */ - if (!(ciaacra & 0x40) && (val & 0x40)) - kback = 1; - ciaacra = val; - if (ciaacra & 0x10) { - ciaacra &= ~0x10; - ciaata = ciaala; - } - CIA_calctimers (); - break; - case 15: - CIA_update (); - ciaacrb = val; - if (ciaacrb & 0x10) { - ciaacrb &= ~0x10; - ciaatb = ciaalb; + break; + case 4: + CIA_update (); + ciaala = (ciaala & 0xff00) | val; + CIA_calctimers (); + break; + case 5: + CIA_update (); + ciaala = (ciaala & 0xff) | (val << 8); + if ((ciaacra & 1) == 0) + ciaata = ciaala; + if (ciaacra & 8) { + ciaata = ciaala; + ciaacra |= 1; + } + CIA_calctimers (); + break; + case 6: + CIA_update (); + ciaalb = (ciaalb & 0xff00) | val; + CIA_calctimers (); + break; + case 7: + CIA_update (); + ciaalb = (ciaalb & 0xff) | (val << 8); + if ((ciaacrb & 1) == 0) + ciaatb = ciaalb; + if (ciaacrb & 8) { + ciaatb = ciaalb; + ciaacrb |= 1; + } + CIA_calctimers (); + break; + case 8: + if (ciaacrb & 0x80) { + ciaaalarm = (ciaaalarm & ~0xff) | val; + } else { + ciaatod = (ciaatod & ~0xff) | val; + ciaatodon = 1; + ciaa_checkalarm (0); + } + break; + case 9: + if (ciaacrb & 0x80) { + ciaaalarm = (ciaaalarm & ~0xff00) | (val << 8); + } else { + ciaatod = (ciaatod & ~0xff00) | (val << 8); + } + break; + case 10: + if (ciaacrb & 0x80) { + ciaaalarm = (ciaaalarm & ~0xff0000) | (val << 16); + } else { + ciaatod = (ciaatod & ~0xff0000) | (val << 16); + ciaatodon = 0; + } + break; + case 12: + CIA_update (); + ciaasdr = val; + if (ciaacra & 0x40) { + kback = 1; + } else { + ciaasdr_cnt = 0; + } + if ((ciaacra & 0x41) == 0x41 && ciaasdr_cnt == 0) + ciaasdr_cnt = 8 * 2; + CIA_calctimers (); + break; + case 13: + setclr (&ciaaimask,val); + break; + case 14: + CIA_update (); + val &= 0x7f; /* bit 7 is unused */ + if (!(ciaacra & 0x40) && (val & 0x40)) + kback = 1; + ciaacra = val; + if (ciaacra & 0x10) { + ciaacra &= ~0x10; + ciaata = ciaala; + } + CIA_calctimers (); + break; + case 15: + CIA_update (); + ciaacrb = val; + if (ciaacrb & 0x10) { + ciaacrb &= ~0x10; + ciaatb = ciaalb; + } + CIA_calctimers (); + break; } - CIA_calctimers (); - break; - } } static void WriteCIAB (uae_u16 addr, uae_u8 val) { - int reg = addr & 15; + int reg = addr & 15; #ifdef CIAB_DEBUG_W - if (addr >= 8 && addr <= 10) - write_log (L"W_CIAB: bfd%x00 %02X %08X\n", reg, val, M68K_GETPC); + if (addr >= 8 && addr <= 10) + write_log (L"W_CIAB: bfd%x00 %02X %08X\n", reg, val, M68K_GETPC); #endif #ifdef ACTION_REPLAY - ar_ciab[reg] = val; + ar_ciab[reg] = val; #endif - switch (reg) { - case 0: + switch (reg) { + case 0: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD000 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD000 W %02X %s\n", val, debuginfo(0)); #endif - dongle_cia_write (1, reg, val); - ciabpra = val; + dongle_cia_write (1, reg, val); + ciabpra = val; #ifdef SERIAL_PORT - if (currprefs.use_serial) - serial_writestatus(ciabpra, ciabdra); + if (currprefs.use_serial) + serial_writestatus(ciabpra, ciabdra); #endif #ifdef PARALLEL_PORT - if (isprinter () < 0) - parallel_direct_write_status (val, ciabdra); + if (isprinter () < 0) + parallel_direct_write_status (val, ciabdra); #endif - break; - case 1: + break; + case 1: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD100 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD100 W %02X %s\n", val, debuginfo(0)); #endif - dongle_cia_write (1, reg, val); - ciabprb = val; - DISK_select (val); - break; - case 2: + dongle_cia_write (1, reg, val); + ciabprb = val; + DISK_select (val); + break; + case 2: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD200 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD200 W %02X %s\n", val, debuginfo(0)); #endif - dongle_cia_write (1, reg, val); - ciabdra = val; + dongle_cia_write (1, reg, val); + ciabdra = val; #ifdef SERIAL_PORT - if (currprefs.use_serial) - serial_writestatus (ciabpra, ciabdra); + if (currprefs.use_serial) + serial_writestatus (ciabpra, ciabdra); #endif - break; - case 3: + break; + case 3: #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"BFD300 W %02X %s\n", val, debuginfo(0)); + if (notinrom ()) + write_log (L"BFD300 W %02X %s\n", val, debuginfo(0)); #endif - dongle_cia_write (1, reg, val); - ciabdrb = val; - break; - case 4: - CIA_update (); - ciabla = (ciabla & 0xff00) | val; - CIA_calctimers (); - break; - case 5: - CIA_update (); - ciabla = (ciabla & 0xff) | (val << 8); - if ((ciabcra & 1) == 0) - ciabta = ciabla; - if (ciabcra & 8) { - ciabta = ciabla; - ciabcra |= 1; - } - CIA_calctimers (); - break; - case 6: - CIA_update (); - ciablb = (ciablb & 0xff00) | val; - CIA_calctimers (); - break; - case 7: - CIA_update (); - ciablb = (ciablb & 0xff) | (val << 8); - if ((ciabcrb & 1) == 0) - ciabtb = ciablb; - if (ciabcrb & 8) { - ciabtb = ciablb; - ciabcrb |= 1; - } - CIA_calctimers (); - break; - case 8: - if (ciabcrb & 0x80) { - ciabalarm = (ciabalarm & ~0xff) | val; - } else { - ciabtod = (ciabtod & ~0xff) | val; - ciabtodon = 1; - ciab_checkalarm (0); - } - break; - case 9: - if (ciabcrb & 0x80) { - ciabalarm = (ciabalarm & ~0xff00) | (val << 8); - } else { - ciabtod = (ciabtod & ~0xff00) | (val << 8); - } - break; - case 10: - if (ciabcrb & 0x80) { - ciabalarm = (ciabalarm & ~0xff0000) | (val << 16); - } else { - ciabtod = (ciabtod & ~0xff0000) | (val << 16); - ciabtodon = 0; - } - break; - case 12: - CIA_update (); - ciabsdr = val; - if ((ciabcra & 0x40) == 0) - ciabsdr_cnt = 0; - if ((ciabcra & 0x41) == 0x41 && ciabsdr_cnt == 0) - ciabsdr_cnt = 8 * 2; - CIA_calctimers (); - break; - case 13: - setclr (&ciabimask,val); - break; - case 14: - CIA_update (); - val &= 0x7f; /* bit 7 is unused */ - ciabcra = val; - if (ciabcra & 0x10) { - ciabcra &= ~0x10; - ciabta = ciabla; - } - CIA_calctimers (); - break; - case 15: - CIA_update (); - ciabcrb = val; - if (ciabcrb & 0x10) { - ciabcrb &= ~0x10; - ciabtb = ciablb; + dongle_cia_write (1, reg, val); + ciabdrb = val; + break; + case 4: + CIA_update (); + ciabla = (ciabla & 0xff00) | val; + CIA_calctimers (); + break; + case 5: + CIA_update (); + ciabla = (ciabla & 0xff) | (val << 8); + if ((ciabcra & 1) == 0) + ciabta = ciabla; + if (ciabcra & 8) { + ciabta = ciabla; + ciabcra |= 1; + } + CIA_calctimers (); + break; + case 6: + CIA_update (); + ciablb = (ciablb & 0xff00) | val; + CIA_calctimers (); + break; + case 7: + CIA_update (); + ciablb = (ciablb & 0xff) | (val << 8); + if ((ciabcrb & 1) == 0) + ciabtb = ciablb; + if (ciabcrb & 8) { + ciabtb = ciablb; + ciabcrb |= 1; + } + CIA_calctimers (); + break; + case 8: + if (ciabcrb & 0x80) { + ciabalarm = (ciabalarm & ~0xff) | val; + } else { + ciabtod = (ciabtod & ~0xff) | val; + ciabtodon = 1; + ciab_checkalarm (0); + } + break; + case 9: + if (ciabcrb & 0x80) { + ciabalarm = (ciabalarm & ~0xff00) | (val << 8); + } else { + ciabtod = (ciabtod & ~0xff00) | (val << 8); + } + break; + case 10: + if (ciabcrb & 0x80) { + ciabalarm = (ciabalarm & ~0xff0000) | (val << 16); + } else { + ciabtod = (ciabtod & ~0xff0000) | (val << 16); + ciabtodon = 0; + } + break; + case 12: + CIA_update (); + ciabsdr = val; + if ((ciabcra & 0x40) == 0) + ciabsdr_cnt = 0; + if ((ciabcra & 0x41) == 0x41 && ciabsdr_cnt == 0) + ciabsdr_cnt = 8 * 2; + CIA_calctimers (); + break; + case 13: + setclr (&ciabimask,val); + break; + case 14: + CIA_update (); + val &= 0x7f; /* bit 7 is unused */ + ciabcra = val; + if (ciabcra & 0x10) { + ciabcra &= ~0x10; + ciabta = ciabla; + } + CIA_calctimers (); + break; + case 15: + CIA_update (); + ciabcrb = val; + if (ciabcrb & 0x10) { + ciabcrb &= ~0x10; + ciabtb = ciablb; + } + CIA_calctimers (); + break; } - CIA_calctimers (); - break; - } } void CIA_inprec_prepare (void) { - sleepyhead = 0; + sleepyhead = 0; } void CIA_reset (void) { #ifdef TOD_HACK - tod_hack_tv = 0; - tod_hack_tod = 0; - tod_hack_enabled = 0; - if (currprefs.tod_hack) - tod_hack_enabled = 312 * 50 * 10; + tod_hack_tv = 0; + tod_hack_tod = 0; + tod_hack_enabled = 0; + if (currprefs.tod_hack) + tod_hack_enabled = 312 * 50 * 10; #endif - kback = 1; - kbstate = 3; - ciaasdr_unread = 0; - serbits = 0; - oldovl = 1; - oldled = -1; - resetwarning_phase = resetwarning_timer = 0; - - if (!savestate_state) { - kbstate = 0; - ciaatlatch = ciabtlatch = 0; - ciaapra = 0; ciaadra = 0; - ciaatod = ciabtod = 0; ciaatodon = ciabtodon = 0; - ciaaicr = ciabicr = ciaaimask = ciabimask = 0; - ciaacra = ciaacrb = ciabcra = ciabcrb = 0x4; /* outmode = toggle; */ - ciaala = ciaalb = ciabla = ciablb = ciaata = ciaatb = ciabta = ciabtb = 0xFFFF; - ciaaalarm = ciabalarm = 0; - ciabpra = 0x8C; ciabdra = 0; - div10 = 0; - ciaasdr_cnt = 0; ciaasdr = 0; - ciabsdr_cnt = 0; ciabsdr = 0; - ciaata_passed = ciaatb_passed = ciabta_passed = ciabtb_passed = 0; - } - CIA_calctimers (); - if (ersatzkickfile) - ersatz_chipcopy (); - else - map_overlay (0); + kback = 1; + kbstate = 3; + ciaasdr_unread = 0; + serbits = 0; + oldovl = 1; + oldled = -1; + resetwarning_phase = resetwarning_timer = 0; + + if (!savestate_state) { + kbstate = 0; + ciaatlatch = ciabtlatch = 0; + ciaapra = 0; ciaadra = 0; + ciaatod = ciabtod = 0; ciaatodon = ciabtodon = 0; + ciaaicr = ciabicr = ciaaimask = ciabimask = 0; + ciaacra = ciaacrb = ciabcra = ciabcrb = 0x4; /* outmode = toggle; */ + ciaala = ciaalb = ciabla = ciablb = ciaata = ciaatb = ciabta = ciabtb = 0xFFFF; + ciaaalarm = ciabalarm = 0; + ciabpra = 0x8C; ciabdra = 0; + div10 = 0; + ciaasdr_cnt = 0; ciaasdr = 0; + ciabsdr_cnt = 0; ciabsdr = 0; + ciaata_passed = ciaatb_passed = ciabta_passed = ciabtb_passed = 0; + } + CIA_calctimers (); + if (ersatzkickfile) + ersatz_chipcopy (); + else + map_overlay (0); #ifdef SERIAL_PORT - if (currprefs.use_serial && !savestate_state) - serial_dtr_off (); /* Drop DTR at reset */ + if (currprefs.use_serial && !savestate_state) + serial_dtr_off (); /* Drop DTR at reset */ #endif - if (savestate_state) { - bfe001_change (); - /* select drives */ - DISK_select (ciabprb); - } + if (savestate_state) { + bfe001_change (); + /* select drives */ + DISK_select (ciabprb); + } #ifdef CD32 - if (savestate_state != STATE_RESTORE) { - akiko_reset (); - if (!akiko_init ()) - currprefs.cs_cd32cd = changed_prefs.cs_cd32cd = 0; - } + if (savestate_state != STATE_RESTORE) { + akiko_reset (); + if (!akiko_init ()) + currprefs.cs_cd32cd = changed_prefs.cs_cd32cd = 0; + } #endif } void dumpcia (void) { - console_out_f (L"A: CRA %02x CRB %02x ICR %02x IM %02x TA %04x (%04x) TB %04x (%04x)\n", - ciaacra, ciaacrb, ciaaicr, ciaaimask, ciaata, ciaala, ciaatb, ciaalb); - console_out_f (L"TOD %06x (%06x) ALARM %06x %c%c\n", - ciaatod, ciaatol, ciaaalarm, ciaatlatch ? 'L' : ' ', ciaatodon ? ' ' : 'S'); - console_out_f (L"B: CRA %02x CRB %02x ICR %02x IM %02x TA %04x (%04x) TB %04x (%04x)\n", - ciabcra, ciabcrb, ciaaicr, ciabimask, ciabta, ciabla, ciabtb, ciablb); - console_out_f (L"TOD %06x (%06x) ALARM %06x %c%c\n", - ciabtod, ciabtol, ciabalarm, ciabtlatch ? 'L' : ' ', ciabtodon ? ' ' : 'S'); + console_out_f (L"A: CRA %02x CRB %02x ICR %02x IM %02x TA %04x (%04x) TB %04x (%04x)\n", + ciaacra, ciaacrb, ciaaicr, ciaaimask, ciaata, ciaala, ciaatb, ciaalb); + console_out_f (L"TOD %06x (%06x) ALARM %06x %c%c\n", + ciaatod, ciaatol, ciaaalarm, ciaatlatch ? 'L' : ' ', ciaatodon ? ' ' : 'S'); + console_out_f (L"B: CRA %02x CRB %02x ICR %02x IM %02x TA %04x (%04x) TB %04x (%04x)\n", + ciabcra, ciabcrb, ciaaicr, ciabimask, ciabta, ciabla, ciabtb, ciablb); + console_out_f (L"TOD %06x (%06x) ALARM %06x %c%c\n", + ciabtod, ciabtol, ciabalarm, ciabtlatch ? 'L' : ' ', ciabtodon ? ' ' : 'S'); } /* CIA memory access */ @@ -1215,187 +1215,187 @@ static void REGPARAM3 cia_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 cia_bput (uaecptr, uae_u32) REGPARAM; addrbank cia_bank = { - cia_lget, cia_wget, cia_bget, - cia_lput, cia_wput, cia_bput, - default_xlate, default_check, NULL, L"CIA", - cia_lgeti, cia_wgeti, ABFLAG_IO + cia_lget, cia_wget, cia_bget, + cia_lput, cia_wput, cia_bput, + default_xlate, default_check, NULL, L"CIA", + cia_lgeti, cia_wgeti, ABFLAG_IO }; STATIC_INLINE isgayle (void) { - return (currprefs.cs_ide == IDE_A600A1200 || currprefs.cs_pcmcia); + return (currprefs.cs_ide == IDE_A600A1200 || currprefs.cs_pcmcia); } /* e-clock is 10 CPU cycles, 6 cycles low, 4 high - * data transfer happens during 4 high cycles - */ +* data transfer happens during 4 high cycles +*/ #define ECLOCK_DATA_CYCLE 4 static void cia_wait_pre (void) { #ifndef CUSTOM_SIMPLE - int div10 = (get_cycles () - eventtab[ev_cia].oldcycles) % DIV10; - int cycles; - - cycles = 5 * CYCLE_UNIT / 2; - if (div10 > DIV10 * ECLOCK_DATA_CYCLE / 10) { - cycles += DIV10 - div10; - cycles += DIV10 * ECLOCK_DATA_CYCLE / 10; - } else { - cycles += DIV10 * ECLOCK_DATA_CYCLE / 10 - div10; - } - do_cycles (cycles); + int div10 = (get_cycles () - eventtab[ev_cia].oldcycles) % DIV10; + int cycles; + + cycles = 5 * CYCLE_UNIT / 2; + if (div10 > DIV10 * ECLOCK_DATA_CYCLE / 10) { + cycles += DIV10 - div10; + cycles += DIV10 * ECLOCK_DATA_CYCLE / 10; + } else { + cycles += DIV10 * ECLOCK_DATA_CYCLE / 10 - div10; + } + do_cycles (cycles); #endif } static void cia_wait_post (void) { - do_cycles (2 * CYCLE_UNIT / 2); + do_cycles (2 * CYCLE_UNIT / 2); } static uae_u32 REGPARAM2 cia_bget (uaecptr addr) { - int r = (addr & 0xf00) >> 8; - uae_u8 v; + int r = (addr & 0xf00) >> 8; + uae_u8 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - cia_wait_pre (); - v = 0xff; - switch ((addr >> 12) & 3) { + cia_wait_pre (); + v = 0xff; + switch ((addr >> 12) & 3) { case 0: - if (!isgayle ()) - v = (addr & 1) ? ReadCIAA (r) : ReadCIAB (r); - break; + if (!isgayle ()) + v = (addr & 1) ? ReadCIAA (r) : ReadCIAB (r); + break; case 1: - v = (addr & 1) ? 0xff : ReadCIAB (r); - break; + v = (addr & 1) ? 0xff : ReadCIAB (r); + break; case 2: - v = (addr & 1) ? ReadCIAA (r) : 0xff; - break; + v = (addr & 1) ? ReadCIAA (r) : 0xff; + break; case 3: - if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) - v = (addr & 1) ? regs.irc : regs.irc >> 8; - if (warned > 0) { - write_log (L"cia_bget: unknown CIA address %x PC=%x\n", addr, M68K_GETPC); - warned--; - } - break; - } - cia_wait_post (); - return v; + if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) + v = (addr & 1) ? regs.irc : regs.irc >> 8; + if (warned > 0) { + write_log (L"cia_bget: unknown CIA address %x PC=%x\n", addr, M68K_GETPC); + warned--; + } + break; + } + cia_wait_post (); + return v; } static uae_u32 REGPARAM2 cia_wget (uaecptr addr) { - int r = (addr & 0xf00) >> 8; - uae_u16 v; + int r = (addr & 0xf00) >> 8; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - cia_wait_pre (); - v = 0xffff; - switch ((addr >> 12) & 3) - { + cia_wait_pre (); + v = 0xffff; + switch ((addr >> 12) & 3) + { case 0: - if (!isgayle ()) - v = (ReadCIAB (r) << 8) | ReadCIAA (r); - break; + if (!isgayle ()) + v = (ReadCIAB (r) << 8) | ReadCIAA (r); + break; case 1: - v = (ReadCIAB (r) << 8) | 0xff; - break; + v = (ReadCIAB (r) << 8) | 0xff; + break; case 2: - v = (0xff << 8) | ReadCIAA (r); - break; + v = (0xff << 8) | ReadCIAA (r); + break; case 3: - if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) - v = regs.irc; - if (warned > 0) { - write_log (L"cia_wget: unknown CIA address %x PC=%x\n", addr, M68K_GETPC); - warned--; - } - break; - } - cia_wait_post (); - return v; + if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) + v = regs.irc; + if (warned > 0) { + write_log (L"cia_wget: unknown CIA address %x PC=%x\n", addr, M68K_GETPC); + warned--; + } + break; + } + cia_wait_post (); + return v; } static uae_u32 REGPARAM2 cia_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = cia_wget (addr) << 16; - v |= cia_wget (addr + 2); - return v; + v = cia_wget (addr) << 16; + v |= cia_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 cia_wgeti (uaecptr addr) { - if (currprefs.cpu_model >= 68020) - return dummy_wgeti(addr); - return cia_wget(addr); + if (currprefs.cpu_model >= 68020) + return dummy_wgeti(addr); + return cia_wget(addr); } static uae_u32 REGPARAM2 cia_lgeti (uaecptr addr) { - if (currprefs.cpu_model >= 68020) - return dummy_lgeti(addr); - return cia_lget(addr); + if (currprefs.cpu_model >= 68020) + return dummy_lgeti(addr); + return cia_lget(addr); } static void REGPARAM2 cia_bput (uaecptr addr, uae_u32 value) { - int r = (addr & 0xf00) >> 8; + int r = (addr & 0xf00) >> 8; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - cia_wait_pre (); - if (!isgayle () || (addr & 0x3000) != 0) { - if ((addr & 0x2000) == 0) - WriteCIAB (r, value); - if ((addr & 0x1000) == 0) - WriteCIAA (r, value); - if (((addr & 0x3000) == 0x3000) && warned > 0) { - write_log (L"cia_bput: unknown CIA address %x %x\n", addr, value); - warned--; + cia_wait_pre (); + if (!isgayle () || (addr & 0x3000) != 0) { + if ((addr & 0x2000) == 0) + WriteCIAB (r, value); + if ((addr & 0x1000) == 0) + WriteCIAA (r, value); + if (((addr & 0x3000) == 0x3000) && warned > 0) { + write_log (L"cia_bput: unknown CIA address %x %x\n", addr, value); + warned--; + } } - } - cia_wait_post (); + cia_wait_post (); } static void REGPARAM2 cia_wput (uaecptr addr, uae_u32 value) { - int r = (addr & 0xf00) >> 8; + int r = (addr & 0xf00) >> 8; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - cia_wait_pre (); - if (!isgayle () || (addr & 0x3000) != 0) { - if ((addr & 0x2000) == 0) - WriteCIAB (r, value >> 8); - if ((addr & 0x1000) == 0) - WriteCIAA (r, value & 0xff); - if (((addr & 0x3000) == 0x3000) && warned > 0) { - write_log (L"cia_wput: unknown CIA address %x %x\n", addr, value); - warned--; + cia_wait_pre (); + if (!isgayle () || (addr & 0x3000) != 0) { + if ((addr & 0x2000) == 0) + WriteCIAB (r, value >> 8); + if ((addr & 0x1000) == 0) + WriteCIAA (r, value & 0xff); + if (((addr & 0x3000) == 0x3000) && warned > 0) { + write_log (L"cia_wput: unknown CIA address %x %x\n", addr, value); + warned--; + } } - } - cia_wait_post (); + cia_wait_post (); } static void REGPARAM2 cia_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - cia_wput (addr, value >> 16); - cia_wput (addr + 2, value & 0xffff); + cia_wput (addr, value >> 16); + cia_wput (addr + 2, value & 0xffff); } /* battclock memory access */ @@ -1408,10 +1408,10 @@ static void REGPARAM3 clock_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 clock_bput (uaecptr, uae_u32) REGPARAM; addrbank clock_bank = { - clock_lget, clock_wget, clock_bget, - clock_lput, clock_wput, clock_bput, - default_xlate, default_check, NULL, L"Battery backed up clock (none)", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + clock_lget, clock_wget, clock_bget, + clock_lput, clock_wput, clock_bput, + default_xlate, default_check, NULL, L"Battery backed up clock (none)", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static unsigned int clock_control_d; @@ -1423,206 +1423,206 @@ static uae_u8 rtc_memory[RF5C01A_RAM_SIZE], rtc_alarm[RF5C01A_RAM_SIZE]; static void write_battclock (void) { - struct zfile *f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); - if (!f) { - f = zfile_fopen (currprefs.flashfile, L"wb", 0); - if (f) { - zfile_fwrite (rtc_memory, RF5C01A_RAM_SIZE, 1, f); - zfile_fwrite (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); - zfile_fclose (f); + struct zfile *f = zfile_fopen (currprefs.flashfile, L"rb+", ZFD_NORMAL); + if (!f) { + f = zfile_fopen (currprefs.flashfile, L"wb", 0); + if (f) { + zfile_fwrite (rtc_memory, RF5C01A_RAM_SIZE, 1, f); + zfile_fwrite (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); + zfile_fclose (f); + } + return; + } + zfile_fseek (f, 0, SEEK_END); + if (zfile_ftell (f) <= 2 * RF5C01A_RAM_SIZE) { + zfile_fseek (f, 0, SEEK_SET); + zfile_fwrite (rtc_memory, RF5C01A_RAM_SIZE, 1, f); + zfile_fwrite (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); } - return; - } - zfile_fseek (f, 0, SEEK_END); - if (zfile_ftell (f) <= 2 * RF5C01A_RAM_SIZE) { - zfile_fseek (f, 0, SEEK_SET); - zfile_fwrite (rtc_memory, RF5C01A_RAM_SIZE, 1, f); - zfile_fwrite (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); - } - zfile_fclose (f); + zfile_fclose (f); } void rtc_hardreset (void) { - if (currprefs.cs_rtc == 1) { /* MSM6242B */ - clock_bank.name = L"Battery backed up clock (MSM6242B)"; - clock_control_d = 0x1; - clock_control_e = 0; - clock_control_f = 0x4; /* 24/12 */ - } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ - clock_bank.name = L"Battery backed up clock (RF5C01A)"; - clock_control_d = 0x4; /* Timer EN */ - clock_control_e = 0; - clock_control_f = 0; - memset (rtc_memory, 0, RF5C01A_RAM_SIZE); - memset (rtc_alarm, 0, RF5C01A_RAM_SIZE); + if (currprefs.cs_rtc == 1) { /* MSM6242B */ + clock_bank.name = L"Battery backed up clock (MSM6242B)"; + clock_control_d = 0x1; + clock_control_e = 0; + clock_control_f = 0x4; /* 24/12 */ + } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ + clock_bank.name = L"Battery backed up clock (RF5C01A)"; + clock_control_d = 0x4; /* Timer EN */ + clock_control_e = 0; + clock_control_f = 0; + memset (rtc_memory, 0, RF5C01A_RAM_SIZE); + memset (rtc_alarm, 0, RF5C01A_RAM_SIZE); #if 0 - struct zfile *f; - f = zfile_fopen (currprefs.flashfile, "rb", ZFD_NORMAL); - if (f) { - zfile_fread (rtc_memory, RF5C01A_RAM_SIZE, 1, f); - zfile_fread (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); - zfile_fclose (f); - } + struct zfile *f; + f = zfile_fopen (currprefs.flashfile, "rb", ZFD_NORMAL); + if (f) { + zfile_fread (rtc_memory, RF5C01A_RAM_SIZE, 1, f); + zfile_fread (rtc_alarm, RF5C01A_RAM_SIZE, 1, f); + zfile_fclose (f); + } #endif - } + } } static uae_u32 REGPARAM2 clock_lget (uaecptr addr) { - return (clock_wget (addr) << 16) | clock_wget (addr + 2); + return (clock_wget (addr) << 16) | clock_wget (addr + 2); } static uae_u32 REGPARAM2 clock_wget (uaecptr addr) { - return (clock_bget (addr) << 8) | clock_bget (addr + 1); + return (clock_bget (addr) << 8) | clock_bget (addr + 1); } static uae_u32 REGPARAM2 clock_bget (uaecptr addr) { - time_t t; - struct tm *ct; + time_t t; + struct tm *ct; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - //write_log("R: %x (%x), PC=%08x\n", addr, addr >> 2, M68K_GETPC); + //write_log("R: %x (%x), PC=%08x\n", addr, addr >> 2, M68K_GETPC); #ifdef CDTV - if (currprefs.cs_cdtvram && addr >= 0xdc8000) - return cdtv_battram_read (addr); + if (currprefs.cs_cdtvram && addr >= 0xdc8000) + return cdtv_battram_read (addr); #endif - addr &= 0x3f; - if ((addr & 3) == 2 || (addr & 3) == 0 || currprefs.cs_rtc == 0) { - int v = 0; - if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) - v = regs.irc >> 8; - return v; - } - t = time (0); - t += currprefs.cs_rtc_adjust; - ct = localtime (&t); - addr >>= 2; - if (currprefs.cs_rtc == 1) { /* MSM6242B */ - switch (addr) { - case 0x0: return ct->tm_sec % 10; - case 0x1: return ct->tm_sec / 10; - case 0x2: return ct->tm_min % 10; - case 0x3: return ct->tm_min / 10; - case 0x4: return ct->tm_hour % 10; - case 0x5: return ct->tm_hour / 10; - case 0x6: return ct->tm_mday % 10; - case 0x7: return ct->tm_mday / 10; - case 0x8: return (ct->tm_mon + 1) % 10; - case 0x9: return (ct->tm_mon + 1) / 10; - case 0xA: return ct->tm_year % 10; - case 0xB: return ct->tm_year / 10; - case 0xC: return ct->tm_wday; - case 0xD: return clock_control_d; - case 0xE: return clock_control_e; - case 0xF: return clock_control_f; + addr &= 0x3f; + if ((addr & 3) == 2 || (addr & 3) == 0 || currprefs.cs_rtc == 0) { + int v = 0; + if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) + v = regs.irc >> 8; + return v; } - } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ - int bank = clock_control_d & 3; - /* memory access */ - if (bank >= 2 && addr < 0x0d) - return (rtc_memory[addr] >> ((bank == 2) ? 0 : 4)) & 0x0f; - /* alarm */ - if (bank == 1 && addr < 0x0d) - return rtc_alarm[addr]; - switch (addr) { - case 0x0: return ct->tm_sec % 10; - case 0x1: return ct->tm_sec / 10; - case 0x2: return ct->tm_min % 10; - case 0x3: return ct->tm_min / 10; - case 0x4: return ct->tm_hour % 10; - case 0x5: return ct->tm_hour / 10; - case 0x6: return ct->tm_wday; - case 0x7: return ct->tm_mday % 10; - case 0x8: return ct->tm_mday / 10; - case 0x9: return (ct->tm_mon+1) % 10; - case 0xA: return (ct->tm_mon+1) / 10; - case 0xB: return ct->tm_year % 10; - case 0xC: return ct->tm_year / 10; - case 0xD: return clock_control_d; - /* E and F = write-only */ + t = time (0); + t += currprefs.cs_rtc_adjust; + ct = localtime (&t); + addr >>= 2; + if (currprefs.cs_rtc == 1) { /* MSM6242B */ + switch (addr) { + case 0x0: return ct->tm_sec % 10; + case 0x1: return ct->tm_sec / 10; + case 0x2: return ct->tm_min % 10; + case 0x3: return ct->tm_min / 10; + case 0x4: return ct->tm_hour % 10; + case 0x5: return ct->tm_hour / 10; + case 0x6: return ct->tm_mday % 10; + case 0x7: return ct->tm_mday / 10; + case 0x8: return (ct->tm_mon + 1) % 10; + case 0x9: return (ct->tm_mon + 1) / 10; + case 0xA: return ct->tm_year % 10; + case 0xB: return ct->tm_year / 10; + case 0xC: return ct->tm_wday; + case 0xD: return clock_control_d; + case 0xE: return clock_control_e; + case 0xF: return clock_control_f; + } + } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ + int bank = clock_control_d & 3; + /* memory access */ + if (bank >= 2 && addr < 0x0d) + return (rtc_memory[addr] >> ((bank == 2) ? 0 : 4)) & 0x0f; + /* alarm */ + if (bank == 1 && addr < 0x0d) + return rtc_alarm[addr]; + switch (addr) { + case 0x0: return ct->tm_sec % 10; + case 0x1: return ct->tm_sec / 10; + case 0x2: return ct->tm_min % 10; + case 0x3: return ct->tm_min / 10; + case 0x4: return ct->tm_hour % 10; + case 0x5: return ct->tm_hour / 10; + case 0x6: return ct->tm_wday; + case 0x7: return ct->tm_mday % 10; + case 0x8: return ct->tm_mday / 10; + case 0x9: return (ct->tm_mon+1) % 10; + case 0xA: return (ct->tm_mon+1) / 10; + case 0xB: return ct->tm_year % 10; + case 0xC: return ct->tm_year / 10; + case 0xD: return clock_control_d; + /* E and F = write-only */ + } } - } - return 0; + return 0; } static void REGPARAM2 clock_lput (uaecptr addr, uae_u32 value) { - clock_wput (addr, value >> 16); - clock_wput (addr + 2, value); + clock_wput (addr, value >> 16); + clock_wput (addr + 2, value); } static void REGPARAM2 clock_wput (uaecptr addr, uae_u32 value) { - clock_bput (addr, value >> 8); - clock_bput (addr + 1, value); + clock_bput (addr, value >> 8); + clock_bput (addr + 1, value); } static void REGPARAM2 clock_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - //write_log("W: %x: %x, PC=%08x\n", addr, value & 0xff, M68K_GETPC); + //write_log("W: %x: %x, PC=%08x\n", addr, value & 0xff, M68K_GETPC); #ifdef CDTV - if (currprefs.cs_cdtvram && addr >= 0xdc8000) { - cdtv_battram_write (addr, value); - return; - } -#endif - addr &= 0x3f; - if ((addr & 1) != 1 || currprefs.cs_rtc == 0) - return; - addr >>= 2; - value &= 0x0f; - if (currprefs.cs_rtc == 1) { /* MSM6242B */ - switch (addr) - { - case 0xD: clock_control_d = value & (1|8); break; - case 0xE: clock_control_e = value; break; - case 0xF: clock_control_f = value; break; + if (currprefs.cs_cdtvram && addr >= 0xdc8000) { + cdtv_battram_write (addr, value); + return; } - } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ - int bank = clock_control_d & 3; - /* memory access */ - if (bank >= 2 && addr < 0x0d) { - rtc_memory[addr] &= ((bank == 2) ? 0xf0 : 0x0f); - rtc_memory[addr] |= value << ((bank == 2) ? 0 : 4); +#endif + addr &= 0x3f; + if ((addr & 1) != 1 || currprefs.cs_rtc == 0) + return; + addr >>= 2; + value &= 0x0f; + if (currprefs.cs_rtc == 1) { /* MSM6242B */ + switch (addr) + { + case 0xD: clock_control_d = value & (1|8); break; + case 0xE: clock_control_e = value; break; + case 0xF: clock_control_f = value; break; + } + } else if (currprefs.cs_rtc == 2) { /* RF5C01A */ + int bank = clock_control_d & 3; + /* memory access */ + if (bank >= 2 && addr < 0x0d) { + rtc_memory[addr] &= ((bank == 2) ? 0xf0 : 0x0f); + rtc_memory[addr] |= value << ((bank == 2) ? 0 : 4); #if 0 - uae_u8 ov = rtc_memory[addr]; - if (rtc_memory[addr] != ov) - write_battclock (); + uae_u8 ov = rtc_memory[addr]; + if (rtc_memory[addr] != ov) + write_battclock (); #endif - return; - } - /* alarm */ - if (bank == 1 && addr < 0x0d) { - rtc_alarm[addr] = value; - rtc_alarm[0] = rtc_alarm[1] = rtc_alarm[9] = rtc_alarm[12] = 0; - rtc_alarm[3] &= ~0x8; - rtc_alarm[5] &= ~0xc; - rtc_alarm[6] &= ~0x8; - rtc_alarm[8] &= ~0xc; - rtc_alarm[10] &= ~0xe; - rtc_alarm[11] &= ~0xc; + return; + } + /* alarm */ + if (bank == 1 && addr < 0x0d) { + rtc_alarm[addr] = value; + rtc_alarm[0] = rtc_alarm[1] = rtc_alarm[9] = rtc_alarm[12] = 0; + rtc_alarm[3] &= ~0x8; + rtc_alarm[5] &= ~0xc; + rtc_alarm[6] &= ~0x8; + rtc_alarm[8] &= ~0xc; + rtc_alarm[10] &= ~0xe; + rtc_alarm[11] &= ~0xc; #if 0 - uae_u8 ov = rtc_alarm[addr]; - if (rtc_alarm[addr] != value) - write_battclock (); + uae_u8 ov = rtc_alarm[addr]; + if (rtc_alarm[addr] != value) + write_battclock (); #endif - return; + return; + } + switch (addr) + { + case 0xD: clock_control_d = value; break; + case 0xE: clock_control_e = value; break; + case 0xF: clock_control_f = value; break; + } } - switch (addr) - { - case 0xD: clock_control_d = value; break; - case 0xE: clock_control_e = value; break; - case 0xF: clock_control_f = value; break; - } - } } @@ -1632,145 +1632,145 @@ static void REGPARAM2 clock_bput (uaecptr addr, uae_u32 value) uae_u8 *restore_cia (int num, uae_u8 *src) { - uae_u8 b; - uae_u16 w; - uae_u32 l; - - /* CIA registers */ - b = restore_u8 (); /* 0 PRA */ - if (num) ciabpra = b; else ciaapra = b; - b = restore_u8 (); /* 1 PRB */ - if (num) ciabprb = b; else ciaaprb = b; - b = restore_u8 (); /* 2 DDRA */ - if (num) ciabdra = b; else ciaadra = b; - b = restore_u8 (); /* 3 DDRB */ - if (num) ciabdrb = b; else ciaadrb = b; - w = restore_u16 (); /* 4 TA */ - if (num) ciabta = w; else ciaata = w; - w = restore_u16 (); /* 6 TB */ - if (num) ciabtb = w; else ciaatb = w; - l = restore_u8 (); /* 8/9/A TOD */ - l |= restore_u8 () << 8; - l |= restore_u8 () << 16; - if (num) ciabtod = l; else ciaatod = l; - restore_u8 (); /* B unused */ - b = restore_u8 (); /* C SDR */ - if (num) ciabsdr = b; else ciaasdr = b; - b = restore_u8 (); /* D ICR INFORMATION (not mask!) */ - if (num) ciabicr = b; else ciaaicr = b; - b = restore_u8 (); /* E CRA */ - if (num) ciabcra = b; else ciaacra = b; - b = restore_u8 (); /* F CRB */ - if (num) ciabcrb = b; else ciaacrb = b; - - /* CIA internal data */ - - b = restore_u8 (); /* ICR MASK */ - if (num) ciabimask = b; else ciaaimask = b; - w = restore_u8 (); /* timer A latch */ - w |= restore_u8 () << 8; - if (num) ciabla = w; else ciaala = w; - w = restore_u8 (); /* timer B latch */ - w |= restore_u8 () << 8; - if (num) ciablb = w; else ciaalb = w; - w = restore_u8 (); /* TOD latched value */ - w |= restore_u8 () << 8; - w |= restore_u8 () << 16; - if (num) ciabtol = w; else ciaatol = w; - l = restore_u8 (); /* alarm */ - l |= restore_u8 () << 8; - l |= restore_u8 () << 16; - if (num) ciabalarm = l; else ciaaalarm = l; - b = restore_u8 (); - if (num) ciabtlatch = b & 1; else ciaatlatch = b & 1; /* is TOD latched? */ - if (num) ciabtodon = b & 2; else ciaatodon = b & 2; /* is TOD stopped? */ - b = restore_u8 (); - if (num) - div10 = CYCLE_UNIT * b; - b = restore_u8 (); - if (num) ciabsdr_cnt = b; else ciaasdr_cnt = b; - return src; + uae_u8 b; + uae_u16 w; + uae_u32 l; + + /* CIA registers */ + b = restore_u8 (); /* 0 PRA */ + if (num) ciabpra = b; else ciaapra = b; + b = restore_u8 (); /* 1 PRB */ + if (num) ciabprb = b; else ciaaprb = b; + b = restore_u8 (); /* 2 DDRA */ + if (num) ciabdra = b; else ciaadra = b; + b = restore_u8 (); /* 3 DDRB */ + if (num) ciabdrb = b; else ciaadrb = b; + w = restore_u16 (); /* 4 TA */ + if (num) ciabta = w; else ciaata = w; + w = restore_u16 (); /* 6 TB */ + if (num) ciabtb = w; else ciaatb = w; + l = restore_u8 (); /* 8/9/A TOD */ + l |= restore_u8 () << 8; + l |= restore_u8 () << 16; + if (num) ciabtod = l; else ciaatod = l; + restore_u8 (); /* B unused */ + b = restore_u8 (); /* C SDR */ + if (num) ciabsdr = b; else ciaasdr = b; + b = restore_u8 (); /* D ICR INFORMATION (not mask!) */ + if (num) ciabicr = b; else ciaaicr = b; + b = restore_u8 (); /* E CRA */ + if (num) ciabcra = b; else ciaacra = b; + b = restore_u8 (); /* F CRB */ + if (num) ciabcrb = b; else ciaacrb = b; + + /* CIA internal data */ + + b = restore_u8 (); /* ICR MASK */ + if (num) ciabimask = b; else ciaaimask = b; + w = restore_u8 (); /* timer A latch */ + w |= restore_u8 () << 8; + if (num) ciabla = w; else ciaala = w; + w = restore_u8 (); /* timer B latch */ + w |= restore_u8 () << 8; + if (num) ciablb = w; else ciaalb = w; + w = restore_u8 (); /* TOD latched value */ + w |= restore_u8 () << 8; + w |= restore_u8 () << 16; + if (num) ciabtol = w; else ciaatol = w; + l = restore_u8 (); /* alarm */ + l |= restore_u8 () << 8; + l |= restore_u8 () << 16; + if (num) ciabalarm = l; else ciaaalarm = l; + b = restore_u8 (); + if (num) ciabtlatch = b & 1; else ciaatlatch = b & 1; /* is TOD latched? */ + if (num) ciabtodon = b & 2; else ciaatodon = b & 2; /* is TOD stopped? */ + b = restore_u8 (); + if (num) + div10 = CYCLE_UNIT * b; + b = restore_u8 (); + if (num) ciabsdr_cnt = b; else ciaasdr_cnt = b; + return src; } uae_u8 *save_cia (int num, int *len, uae_u8 *dstptr) { - uae_u8 *dstbak,*dst, b; - uae_u16 t; - - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = (uae_u8*)malloc (16 + 12 + 1 + 1); - - compute_passed_time (); - - /* CIA registers */ - - b = num ? ciabpra : ciaapra; /* 0 PRA */ - save_u8 (b); - b = num ? ciabprb : ciaaprb; /* 1 PRB */ - save_u8 (b); - b = num ? ciabdra : ciaadra; /* 2 DDRA */ - save_u8 (b); - b = num ? ciabdrb : ciaadrb; /* 3 DDRB */ - save_u8 (b); - t = (num ? ciabta - ciabta_passed : ciaata - ciaata_passed);/* 4 TA */ - save_u16 (t); - t = (num ? ciabtb - ciabtb_passed : ciaatb - ciaatb_passed);/* 6 TB */ - save_u16 (t); - b = (num ? ciabtod : ciaatod); /* 8 TODL */ - save_u8 (b); - b = (num ? ciabtod >> 8 : ciaatod >> 8); /* 9 TODM */ - save_u8 (b); - b = (num ? ciabtod >> 16 : ciaatod >> 16); /* A TODH */ - save_u8 (b); - save_u8 (0); /* B unused */ - b = num ? ciabsdr : ciaasdr; /* C SDR */ - save_u8 (b); - b = num ? ciabicr : ciaaicr; /* D ICR INFORMATION (not mask!) */ - save_u8 (b); - b = num ? ciabcra : ciaacra; /* E CRA */ - save_u8 (b); - b = num ? ciabcrb : ciaacrb; /* F CRB */ - save_u8 (b); - - /* CIA internal data */ - - save_u8 (num ? ciabimask : ciaaimask); /* ICR */ - b = (num ? ciabla : ciaala); /* timer A latch LO */ - save_u8 (b); - b = (num ? ciabla >> 8 : ciaala >> 8); /* timer A latch HI */ - save_u8 (b); - b = (num ? ciablb : ciaalb); /* timer B latch LO */ - save_u8 (b); - b = (num ? ciablb >> 8 : ciaalb >> 8); /* timer B latch HI */ - save_u8 (b); - b = (num ? ciabtol : ciaatol); /* latched TOD LO */ - save_u8 (b); - b = (num ? ciabtol >> 8 : ciaatol >> 8); /* latched TOD MED */ - save_u8 (b); - b = (num ? ciabtol >> 16 : ciaatol >> 16); /* latched TOD HI */ - save_u8 (b); - b = (num ? ciabalarm : ciaaalarm); /* alarm LO */ - save_u8 (b); - b = (num ? ciabalarm >> 8 : ciaaalarm >> 8); /* alarm MED */ - save_u8 (b); - b = (num ? ciabalarm >> 16 : ciaaalarm >> 16); /* alarm HI */ - save_u8 (b); - b = 0; - if (num) - b |= ciabtlatch ? 1 : 0; - else - b |= ciaatlatch ? 1 : 0; /* is TOD latched? */ - if (num) - b |= ciabtodon ? 2 : 0; - else - b |= ciaatodon ? 2 : 0; /* TOD stopped? */ - save_u8 (b); - save_u8 (div10 / CYCLE_UNIT); - save_u8 (num ? ciabsdr_cnt : ciaasdr_cnt); - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak,*dst, b; + uae_u16 t; + + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = (uae_u8*)malloc (16 + 12 + 1 + 1); + + compute_passed_time (); + + /* CIA registers */ + + b = num ? ciabpra : ciaapra; /* 0 PRA */ + save_u8 (b); + b = num ? ciabprb : ciaaprb; /* 1 PRB */ + save_u8 (b); + b = num ? ciabdra : ciaadra; /* 2 DDRA */ + save_u8 (b); + b = num ? ciabdrb : ciaadrb; /* 3 DDRB */ + save_u8 (b); + t = (num ? ciabta - ciabta_passed : ciaata - ciaata_passed);/* 4 TA */ + save_u16 (t); + t = (num ? ciabtb - ciabtb_passed : ciaatb - ciaatb_passed);/* 6 TB */ + save_u16 (t); + b = (num ? ciabtod : ciaatod); /* 8 TODL */ + save_u8 (b); + b = (num ? ciabtod >> 8 : ciaatod >> 8); /* 9 TODM */ + save_u8 (b); + b = (num ? ciabtod >> 16 : ciaatod >> 16); /* A TODH */ + save_u8 (b); + save_u8 (0); /* B unused */ + b = num ? ciabsdr : ciaasdr; /* C SDR */ + save_u8 (b); + b = num ? ciabicr : ciaaicr; /* D ICR INFORMATION (not mask!) */ + save_u8 (b); + b = num ? ciabcra : ciaacra; /* E CRA */ + save_u8 (b); + b = num ? ciabcrb : ciaacrb; /* F CRB */ + save_u8 (b); + + /* CIA internal data */ + + save_u8 (num ? ciabimask : ciaaimask); /* ICR */ + b = (num ? ciabla : ciaala); /* timer A latch LO */ + save_u8 (b); + b = (num ? ciabla >> 8 : ciaala >> 8); /* timer A latch HI */ + save_u8 (b); + b = (num ? ciablb : ciaalb); /* timer B latch LO */ + save_u8 (b); + b = (num ? ciablb >> 8 : ciaalb >> 8); /* timer B latch HI */ + save_u8 (b); + b = (num ? ciabtol : ciaatol); /* latched TOD LO */ + save_u8 (b); + b = (num ? ciabtol >> 8 : ciaatol >> 8); /* latched TOD MED */ + save_u8 (b); + b = (num ? ciabtol >> 16 : ciaatol >> 16); /* latched TOD HI */ + save_u8 (b); + b = (num ? ciabalarm : ciaaalarm); /* alarm LO */ + save_u8 (b); + b = (num ? ciabalarm >> 8 : ciaaalarm >> 8); /* alarm MED */ + save_u8 (b); + b = (num ? ciabalarm >> 16 : ciaaalarm >> 16); /* alarm HI */ + save_u8 (b); + b = 0; + if (num) + b |= ciabtlatch ? 1 : 0; + else + b |= ciaatlatch ? 1 : 0; /* is TOD latched? */ + if (num) + b |= ciabtodon ? 2 : 0; + else + b |= ciaatodon ? 2 : 0; /* TOD stopped? */ + save_u8 (b); + save_u8 (div10 / CYCLE_UNIT); + save_u8 (num ? ciabsdr_cnt : ciaasdr_cnt); + *len = dst - dstbak; + return dstbak; } #endif /* SAVESTATE */ diff --git a/cpummu.c b/cpummu.c index 9bd6c670..f918d8a1 100644 --- a/cpummu.c +++ b/cpummu.c @@ -1,27 +1,27 @@ /* - * cpummu.cpp - MMU emulation - * - * Copyright (c) 2001-2004 Milan Jurik of ARAnyM dev team (see AUTHORS) - * - * Inspired by UAE MMU patch - * - * This file is part of the ARAnyM project which builds a new and powerful - * TOS/FreeMiNT compatible virtual machine running on almost any hardware. - * - * ARAnyM is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * ARAnyM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ARAnyM; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +* cpummu.cpp - MMU emulation +* +* Copyright (c) 2001-2004 Milan Jurik of ARAnyM dev team (see AUTHORS) +* +* Inspired by UAE MMU patch +* +* This file is part of the ARAnyM project which builds a new and powerful +* TOS/FreeMiNT compatible virtual machine running on almost any hardware. +* +* ARAnyM is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* ARAnyM is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with ARAnyM; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ #define DEBUG 0 #include "sysconfig.h" @@ -54,13 +54,13 @@ static void mmu_dump_ttr(const TCHAR * label, uae_u32 ttr) to_addr = (ttr & MMU_TTR_LOGICAL_MASK) << 8; D(bug(L"%s: [%08lx] %08lx - %08lx enabled=%d supervisor=%d wp=%d cm=%02d\n", - label, ttr, - from_addr, to_addr, - ttr & MMU_TTR_BIT_ENABLED ? 1 : 0, - (ttr & (MMU_TTR_BIT_SFIELD_ENABLED | MMU_TTR_BIT_SFIELD_SUPER)) >> MMU_TTR_SFIELD_SHIFT, - ttr & MMU_TTR_BIT_WRITE_PROTECT ? 1 : 0, - (ttr & MMU_TTR_CACHE_MASK) >> MMU_TTR_CACHE_SHIFT - )); + label, ttr, + from_addr, to_addr, + ttr & MMU_TTR_BIT_ENABLED ? 1 : 0, + (ttr & (MMU_TTR_BIT_SFIELD_ENABLED | MMU_TTR_BIT_SFIELD_SUPER)) >> MMU_TTR_SFIELD_SHIFT, + ttr & MMU_TTR_BIT_WRITE_PROTECT ? 1 : 0, + (ttr & MMU_TTR_CACHE_MASK) >> MMU_TTR_CACHE_SHIFT + )); } void mmu_make_transparent_region(uaecptr baseaddr, uae_u32 size, int datamode) @@ -131,7 +131,7 @@ STATIC_INLINE int mmu_match_ttr(uaecptr addr, int super, int data) /* {{{ mmu_dump_table */ static void mmu_dump_table(const TCHAR * label, uaecptr root_ptr) { -// DUNUSED(label); + // DUNUSED(label); // const int PAGE_INDEX_SHIFT = 12; int root_idx, ptr_idx, page_idx; uae_u32 root_des, ptr_des, page_des; @@ -147,10 +147,10 @@ static void mmu_dump_table(const TCHAR * label, uaecptr root_ptr) continue; /* invalid */ D(bug(L" ROOT: %03d U=%d W=%d UDT=%02d\n", root_idx, - root_des & 8 ? 1 : 0, - root_des & 4 ? 1 : 0, - root_des & 3 - )); + root_des & 8 ? 1 : 0, + root_des & 4 ? 1 : 0, + root_des & 3 + )); root_log = root_idx << ROOT_INDEX_SHIFT; @@ -179,22 +179,22 @@ static void mmu_dump_table(const TCHAR * label, uaecptr root_ptr) page_log = ptr_log | (page_idx << 2); // ??? PAGE_INDEX_SHIFT switch (page_des & 3) { - case 0: /* invalid */ - continue; - case 1: case 3: /* resident */ - case 2: /* indirect */ - if (n_pages_used == -1 || page_info[n_pages_used].match != page_des) { - /* use the next entry */ - n_pages_used++; - - page_info[n_pages_used].match = page_des; - page_info[n_pages_used].n_pages = 1; - page_info[n_pages_used].start_idx = page_idx; - page_info[n_pages_used].log = page_log; - } else { - page_info[n_pages_used].n_pages++; - } - break; + case 0: /* invalid */ + continue; + case 1: case 3: /* resident */ + case 2: /* indirect */ + if (n_pages_used == -1 || page_info[n_pages_used].match != page_des) { + /* use the next entry */ + n_pages_used++; + + page_info[n_pages_used].match = page_des; + page_info[n_pages_used].n_pages = 1; + page_info[n_pages_used].start_idx = page_idx; + page_info[n_pages_used].log = page_log; + } else { + page_info[n_pages_used].n_pages++; + } + break; } } @@ -205,7 +205,7 @@ static void mmu_dump_table(const TCHAR * label, uaecptr root_ptr) ptr_des & 8 ? 1 : 0, ptr_des & 4 ? 1 : 0, ptr_des & 3 - )); + )); for (page_idx = 0; page_idx <= n_pages_used; page_idx++) { @@ -213,28 +213,28 @@ static void mmu_dump_table(const TCHAR * label, uaecptr root_ptr) if ((page_des & MMU_PDT_MASK) == 2) { D(bug(L" PAGE: %03d-%03d log=%08lx INDIRECT --> addr=%08lx (%08lx)\n", - page_info[page_idx].start_idx, - page_info[page_idx].start_idx + page_info[page_idx].n_pages - 1, - page_info[page_idx].log, - page_des & MMU_PAGE_INDIRECT_MASK, - phys_get_long (page_des & MMU_PAGE_INDIRECT_MASK) - )); + page_info[page_idx].start_idx, + page_info[page_idx].start_idx + page_info[page_idx].n_pages - 1, + page_info[page_idx].log, + page_des & MMU_PAGE_INDIRECT_MASK, + phys_get_long (page_des & MMU_PAGE_INDIRECT_MASK) + )); } else { D(bug(L" PAGE: %03d-%03d log=%08lx addr=%08lx UR=%02d G=%d U1/0=%d S=%d CM=%d M=%d U=%d W=%d\n", - page_info[page_idx].start_idx, - page_info[page_idx].start_idx + page_info[page_idx].n_pages - 1, - page_info[page_idx].log, - page_des & (regs.mmu_pagesize_8k ? MMU_PAGE_ADDR_MASK_8 : MMU_PAGE_ADDR_MASK_4), - (page_des & (regs.mmu_pagesize_8k ? MMU_PAGE_UR_MASK_8 : MMU_PAGE_UR_MASK_4)) >> MMU_PAGE_UR_SHIFT, - page_des & MMU_DES_GLOBAL ? 1 : 0, - (page_des & MMU_TTR_UX_MASK) >> MMU_TTR_UX_SHIFT, - page_des & MMU_DES_SUPER ? 1 : 0, - (page_des & MMU_TTR_CACHE_MASK) >> MMU_TTR_CACHE_SHIFT, - page_des & MMU_DES_MODIFIED ? 1 : 0, - page_des & MMU_DES_USED ? 1 : 0, - page_des & MMU_DES_WP ? 1 : 0 - )); + page_info[page_idx].start_idx, + page_info[page_idx].start_idx + page_info[page_idx].n_pages - 1, + page_info[page_idx].log, + page_des & (regs.mmu_pagesize_8k ? MMU_PAGE_ADDR_MASK_8 : MMU_PAGE_ADDR_MASK_4), + (page_des & (regs.mmu_pagesize_8k ? MMU_PAGE_UR_MASK_8 : MMU_PAGE_UR_MASK_4)) >> MMU_PAGE_UR_SHIFT, + page_des & MMU_DES_GLOBAL ? 1 : 0, + (page_des & MMU_TTR_UX_MASK) >> MMU_TTR_UX_SHIFT, + page_des & MMU_DES_SUPER ? 1 : 0, + (page_des & MMU_TTR_CACHE_MASK) >> MMU_TTR_CACHE_SHIFT, + page_des & MMU_DES_MODIFIED ? 1 : 0, + page_des & MMU_DES_USED ? 1 : 0, + page_des & MMU_DES_WP ? 1 : 0 + )); } } } @@ -269,7 +269,7 @@ void mmu_dump_tables(void) mmu_dump_ttr(L"DTT1", regs.dtt1); mmu_dump_ttr(L"ITT0", regs.itt0); mmu_dump_ttr(L"ITT1", regs.itt1); -// mmu_dump_atc(); + // mmu_dump_atc(); #if DEBUG mmu_dump_table(L"URP", regs.urp); mmu_dump_table(L"SRP", regs.srp); @@ -306,7 +306,7 @@ static void mmu_bus_error(uaecptr addr, int fc, int write, int size) ssw |= MMU_SSW_RW; if (regs.t0 || regs.t1) - ssw |= MMU_SSW_CT; + ssw |= MMU_SSW_CT; regs.mmu_fault_addr = addr; regs.mmu_ssw = ssw | MMU_SSW_ATC; @@ -319,10 +319,10 @@ static void mmu_bus_error(uaecptr addr, int fc, int write, int size) } /* - * Update the atc line for a given address by doing a mmu lookup. - */ +* Update the atc line for a given address by doing a mmu lookup. +*/ static uaecptr mmu_fill_atc_l2(uaecptr addr, int super, int data, int write, - struct mmu_atc_line *l) +struct mmu_atc_line *l) { int res; uae_u32 desc; @@ -373,7 +373,7 @@ static uaecptr mmu_fill_atc_l2(uaecptr addr, int super, int data, int write, } if ((desc & 1) == 0 || (!super && desc & MMU_MMUSR_S)) { - fail: +fail: l->valid_data = l->valid_inst = 0; l->global = 0; } else { @@ -392,15 +392,15 @@ static uaecptr mmu_fill_atc_l2(uaecptr addr, int super, int data, int write, } static ALWAYS_INLINE bool -mmu_fill_atc_l1(uaecptr addr, int super, int data, int write, - struct mmu_atc_line *l1) + mmu_fill_atc_l1(uaecptr addr, int super, int data, int write, +struct mmu_atc_line *l1) { int idx = ATC_L2_INDEX(addr); int tag = ATC_TAG(addr); struct mmu_atc_line *l = &atc_l2[super][idx]; if (l->tag != tag) { - restart: +restart: mmu_fill_atc_l2(addr, super, data, write, l); } if (!(data ? l->valid_data : l->valid_inst)) { @@ -453,10 +453,10 @@ uaecptr REGPARAM2 mmu_translate(uaecptr addr, int super, int data, int write) return addr + l->phys; } /* - * Lookup the address by walking the page table and updating - * the page descriptors accordingly. Returns the found descriptor - * or produces a bus error. - */ +* Lookup the address by walking the page table and updating +* the page descriptors accordingly. Returns the found descriptor +* or produces a bus error. +*/ static uaecptr REGPARAM2 mmu_lookup_pagetable(uaecptr addr, int super, int write) { uae_u32 desc, desc_addr, wp; @@ -518,9 +518,9 @@ static uaecptr REGPARAM2 mmu_lookup_pagetable(uaecptr addr, int super, int write phys_put_long(desc_addr, desc); } } else if ((desc & (MMU_DES_USED|MMU_DES_MODIFIED)) != - (MMU_DES_USED|MMU_DES_MODIFIED)) { - desc |= MMU_DES_USED|MMU_DES_MODIFIED; - phys_put_long(desc_addr, desc); + (MMU_DES_USED|MMU_DES_MODIFIED)) { + desc |= MMU_DES_USED|MMU_DES_MODIFIED; + phys_put_long(desc_addr, desc); } } else { if ((desc & MMU_DES_USED) == 0) { @@ -587,12 +587,12 @@ uae_u32 REGPARAM2 mmu_get_long_unaligned(uaecptr addr, int data) } uae_u8 REGPARAM2 mmu_get_byte_slow(uaecptr addr, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) return HWget_b(cl->phys + addr); mmu_bus_error(addr, mmu_get_fc(super, data), 0, size); @@ -606,12 +606,12 @@ uae_u8 REGPARAM2 mmu_get_byte_slow(uaecptr addr, int super, int data, } uae_u16 REGPARAM2 mmu_get_word_slow(uaecptr addr, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) return HWget_w(cl->phys + addr); mmu_bus_error(addr, mmu_get_fc(super, data), 0, size); @@ -625,12 +625,12 @@ uae_u16 REGPARAM2 mmu_get_word_slow(uaecptr addr, int super, int data, } uae_u32 REGPARAM2 mmu_get_long_slow(uaecptr addr, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) return HWget_l(cl->phys + addr); mmu_bus_error(addr, mmu_get_fc(super, data), 0, size); @@ -689,12 +689,12 @@ void REGPARAM2 mmu_put_word_unaligned(uaecptr addr, uae_u16 val, int data) } void REGPARAM2 mmu_put_byte_slow(uaecptr addr, uae_u8 val, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) { HWput_b(cl->phys + addr, val); return; @@ -707,17 +707,17 @@ void REGPARAM2 mmu_put_byte_slow(uaecptr addr, uae_u8 val, int super, int data, if (!mmu_fill_atc_l1(addr, super, data, 1, cl)) goto redo; - + phys_put_byte(mmu_get_real_address(addr, cl), val); } void REGPARAM2 mmu_put_word_slow(uaecptr addr, uae_u16 val, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) { HWput_w(cl->phys + addr, val); return; @@ -734,12 +734,12 @@ void REGPARAM2 mmu_put_word_slow(uaecptr addr, uae_u16 val, int super, int data, } void REGPARAM2 mmu_put_long_slow(uaecptr addr, uae_u32 val, int super, int data, - int size, struct mmu_atc_line *cl) + int size, struct mmu_atc_line *cl) { uae_u32 tag = ATC_TAG(addr); if (cl->tag == (uae_u16)~tag) { - redo: +redo: if (cl->hw) { HWput_l(cl->phys + addr, val); return; @@ -946,7 +946,7 @@ void REGPARAM2 mmu_op_real(uae_u32 opcode, uae_u16 extra) regs.mmusr = MMU_MMUSR_T | MMU_MMUSR_R; else { regs.mmusr = desc & (~0xfff|MMU_MMUSR_G|MMU_MMUSR_Ux|MMU_MMUSR_S| - MMU_MMUSR_CM|MMU_MMUSR_M|MMU_MMUSR_W); + MMU_MMUSR_CM|MMU_MMUSR_M|MMU_MMUSR_W); regs.mmusr |= MMU_MMUSR_R; } } @@ -1016,9 +1016,9 @@ void REGPARAM2 mmu_reset(void) void REGPARAM2 mmu_set_tc(uae_u16 tc) { -// if (regs.tcr == tc) -// return; -// regs.tcr = tc; + // if (regs.tcr == tc) + // return; + // regs.tcr = tc; regs.mmu_enabled = tc & 0x8000 ? 1 : 0; regs.mmu_pagesize_8k = tc & 0x4000 ? 1 : 0; diff --git a/crc32.c b/crc32.c index d9b5d603..a82fd9d6 100644 --- a/crc32.c +++ b/crc32.c @@ -8,53 +8,53 @@ static unsigned long crc_table32[256]; static unsigned short crc_table16[256]; static void make_crc_table (void) { - unsigned long c; - unsigned short w; - int n, k; - for (n = 0; n < 256; n++) { - c = (unsigned long)n; - w = n << 8; - for (k = 0; k < 8; k++) { - c = (c >> 1) ^ (c & 1 ? 0xedb88320 : 0); - w = (w << 1) ^ ((w & 0x8000) ? 0x1021 : 0); + unsigned long c; + unsigned short w; + int n, k; + for (n = 0; n < 256; n++) { + c = (unsigned long)n; + w = n << 8; + for (k = 0; k < 8; k++) { + c = (c >> 1) ^ (c & 1 ? 0xedb88320 : 0); + w = (w << 1) ^ ((w & 0x8000) ? 0x1021 : 0); + } + crc_table32[n] = c; + crc_table16[n] = w; } - crc_table32[n] = c; - crc_table16[n] = w; - } } uae_u32 get_crc32_val (uae_u8 v, uae_u32 crc) { - if (!crc_table32[1]) - make_crc_table(); - crc ^= 0xffffffff; - crc = crc_table32[(crc ^ v) & 0xff] ^ (crc >> 8); - return crc ^ 0xffffffff; + if (!crc_table32[1]) + make_crc_table(); + crc ^= 0xffffffff; + crc = crc_table32[(crc ^ v) & 0xff] ^ (crc >> 8); + return crc ^ 0xffffffff; } uae_u32 get_crc32 (uae_u8 *buf, int len) { - uae_u32 crc; - if (!crc_table32[1]) - make_crc_table(); - crc = 0xffffffff; - while (len-- > 0) - crc = crc_table32[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8); - return crc ^ 0xffffffff; + uae_u32 crc; + if (!crc_table32[1]) + make_crc_table(); + crc = 0xffffffff; + while (len-- > 0) + crc = crc_table32[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8); + return crc ^ 0xffffffff; } uae_u16 get_crc16 (uae_u8 *buf, int len) { - uae_u16 crc; - if (!crc_table32[1]) - make_crc_table(); - crc = 0xffff; - while (len-- > 0) - crc = (crc << 8) ^ crc_table16[((crc >> 8) ^ (*buf++)) & 0xff]; - return crc; + uae_u16 crc; + if (!crc_table32[1]) + make_crc_table(); + crc = 0xffff; + while (len-- > 0) + crc = (crc << 8) ^ crc_table16[((crc >> 8) ^ (*buf++)) & 0xff]; + return crc; } #ifndef GET_UINT32_BE #define GET_UINT32_BE(n,b,i) \ { \ - (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ + (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ | ( (unsigned long) (b)[(i) + 1] << 16 ) \ | ( (unsigned long) (b)[(i) + 2] << 8 ) \ | ( (unsigned long) (b)[(i) + 3] ); \ @@ -63,97 +63,97 @@ uae_u16 get_crc16 (uae_u8 *buf, int len) #ifndef PUT_UINT32_BE #define PUT_UINT32_BE(n,b,i) \ { \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ + (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ + (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ + (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ + (b)[(i) + 3] = (unsigned char) ( (n) ); \ } #endif typedef struct { - unsigned long total[2]; /*!< number of bytes processed */ - unsigned long state[5]; /*!< intermediate digest state */ - unsigned char buffer[64]; /*!< data block being processed */ + unsigned long total[2]; /*!< number of bytes processed */ + unsigned long state[5]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ } sha1_context; static void sha1_starts( sha1_context *ctx ) { - ctx->total[0] = 0; - ctx->total[1] = 0; - - ctx->state[0] = 0x67452301; - ctx->state[1] = 0xEFCDAB89; - ctx->state[2] = 0x98BADCFE; - ctx->state[3] = 0x10325476; - ctx->state[4] = 0xC3D2E1F0; + ctx->total[0] = 0; + ctx->total[1] = 0; + + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xEFCDAB89; + ctx->state[2] = 0x98BADCFE; + ctx->state[3] = 0x10325476; + ctx->state[4] = 0xC3D2E1F0; } static void sha1_process( sha1_context *ctx, unsigned char data[64] ) { - unsigned long temp, W[16], A, B, C, D, E; - - GET_UINT32_BE( W[0], data, 0 ); - GET_UINT32_BE( W[1], data, 4 ); - GET_UINT32_BE( W[2], data, 8 ); - GET_UINT32_BE( W[3], data, 12 ); - GET_UINT32_BE( W[4], data, 16 ); - GET_UINT32_BE( W[5], data, 20 ); - GET_UINT32_BE( W[6], data, 24 ); - GET_UINT32_BE( W[7], data, 28 ); - GET_UINT32_BE( W[8], data, 32 ); - GET_UINT32_BE( W[9], data, 36 ); - GET_UINT32_BE( W[10], data, 40 ); - GET_UINT32_BE( W[11], data, 44 ); - GET_UINT32_BE( W[12], data, 48 ); - GET_UINT32_BE( W[13], data, 52 ); - GET_UINT32_BE( W[14], data, 56 ); - GET_UINT32_BE( W[15], data, 60 ); + unsigned long temp, W[16], A, B, C, D, E; + + GET_UINT32_BE( W[0], data, 0 ); + GET_UINT32_BE( W[1], data, 4 ); + GET_UINT32_BE( W[2], data, 8 ); + GET_UINT32_BE( W[3], data, 12 ); + GET_UINT32_BE( W[4], data, 16 ); + GET_UINT32_BE( W[5], data, 20 ); + GET_UINT32_BE( W[6], data, 24 ); + GET_UINT32_BE( W[7], data, 28 ); + GET_UINT32_BE( W[8], data, 32 ); + GET_UINT32_BE( W[9], data, 36 ); + GET_UINT32_BE( W[10], data, 40 ); + GET_UINT32_BE( W[11], data, 44 ); + GET_UINT32_BE( W[12], data, 48 ); + GET_UINT32_BE( W[13], data, 52 ); + GET_UINT32_BE( W[14], data, 56 ); + GET_UINT32_BE( W[15], data, 60 ); #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) #define R(t) \ -( \ - temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ - W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ - ( W[t & 0x0F] = S(temp,1) ) \ -) + ( \ + temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ + W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ + ( W[t & 0x0F] = S(temp,1) ) \ + ) #define P(a,b,c,d,e,x) \ -{ \ - e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \ -} + { \ + e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \ + } - A = ctx->state[0]; - B = ctx->state[1]; - C = ctx->state[2]; - D = ctx->state[3]; - E = ctx->state[4]; + A = ctx->state[0]; + B = ctx->state[1]; + C = ctx->state[2]; + D = ctx->state[3]; + E = ctx->state[4]; #define F(x,y,z) (z ^ (x & (y ^ z))) #define K 0x5A827999 - P( A, B, C, D, E, W[0] ); - P( E, A, B, C, D, W[1] ); - P( D, E, A, B, C, W[2] ); - P( C, D, E, A, B, W[3] ); - P( B, C, D, E, A, W[4] ); - P( A, B, C, D, E, W[5] ); - P( E, A, B, C, D, W[6] ); - P( D, E, A, B, C, W[7] ); - P( C, D, E, A, B, W[8] ); - P( B, C, D, E, A, W[9] ); - P( A, B, C, D, E, W[10] ); - P( E, A, B, C, D, W[11] ); - P( D, E, A, B, C, W[12] ); - P( C, D, E, A, B, W[13] ); - P( B, C, D, E, A, W[14] ); - P( A, B, C, D, E, W[15] ); - P( E, A, B, C, D, R(16) ); - P( D, E, A, B, C, R(17) ); - P( C, D, E, A, B, R(18) ); - P( B, C, D, E, A, R(19) ); + P( A, B, C, D, E, W[0] ); + P( E, A, B, C, D, W[1] ); + P( D, E, A, B, C, W[2] ); + P( C, D, E, A, B, W[3] ); + P( B, C, D, E, A, W[4] ); + P( A, B, C, D, E, W[5] ); + P( E, A, B, C, D, W[6] ); + P( D, E, A, B, C, W[7] ); + P( C, D, E, A, B, W[8] ); + P( B, C, D, E, A, W[9] ); + P( A, B, C, D, E, W[10] ); + P( E, A, B, C, D, W[11] ); + P( D, E, A, B, C, W[12] ); + P( C, D, E, A, B, W[13] ); + P( B, C, D, E, A, W[14] ); + P( A, B, C, D, E, W[15] ); + P( E, A, B, C, D, R(16) ); + P( D, E, A, B, C, R(17) ); + P( C, D, E, A, B, R(18) ); + P( B, C, D, E, A, R(19) ); #undef K #undef F @@ -161,26 +161,26 @@ static void sha1_process( sha1_context *ctx, unsigned char data[64] ) #define F(x,y,z) (x ^ y ^ z) #define K 0x6ED9EBA1 - P( A, B, C, D, E, R(20) ); - P( E, A, B, C, D, R(21) ); - P( D, E, A, B, C, R(22) ); - P( C, D, E, A, B, R(23) ); - P( B, C, D, E, A, R(24) ); - P( A, B, C, D, E, R(25) ); - P( E, A, B, C, D, R(26) ); - P( D, E, A, B, C, R(27) ); - P( C, D, E, A, B, R(28) ); - P( B, C, D, E, A, R(29) ); - P( A, B, C, D, E, R(30) ); - P( E, A, B, C, D, R(31) ); - P( D, E, A, B, C, R(32) ); - P( C, D, E, A, B, R(33) ); - P( B, C, D, E, A, R(34) ); - P( A, B, C, D, E, R(35) ); - P( E, A, B, C, D, R(36) ); - P( D, E, A, B, C, R(37) ); - P( C, D, E, A, B, R(38) ); - P( B, C, D, E, A, R(39) ); + P( A, B, C, D, E, R(20) ); + P( E, A, B, C, D, R(21) ); + P( D, E, A, B, C, R(22) ); + P( C, D, E, A, B, R(23) ); + P( B, C, D, E, A, R(24) ); + P( A, B, C, D, E, R(25) ); + P( E, A, B, C, D, R(26) ); + P( D, E, A, B, C, R(27) ); + P( C, D, E, A, B, R(28) ); + P( B, C, D, E, A, R(29) ); + P( A, B, C, D, E, R(30) ); + P( E, A, B, C, D, R(31) ); + P( D, E, A, B, C, R(32) ); + P( C, D, E, A, B, R(33) ); + P( B, C, D, E, A, R(34) ); + P( A, B, C, D, E, R(35) ); + P( E, A, B, C, D, R(36) ); + P( D, E, A, B, C, R(37) ); + P( C, D, E, A, B, R(38) ); + P( B, C, D, E, A, R(39) ); #undef K #undef F @@ -188,26 +188,26 @@ static void sha1_process( sha1_context *ctx, unsigned char data[64] ) #define F(x,y,z) ((x & y) | (z & (x | y))) #define K 0x8F1BBCDC - P( A, B, C, D, E, R(40) ); - P( E, A, B, C, D, R(41) ); - P( D, E, A, B, C, R(42) ); - P( C, D, E, A, B, R(43) ); - P( B, C, D, E, A, R(44) ); - P( A, B, C, D, E, R(45) ); - P( E, A, B, C, D, R(46) ); - P( D, E, A, B, C, R(47) ); - P( C, D, E, A, B, R(48) ); - P( B, C, D, E, A, R(49) ); - P( A, B, C, D, E, R(50) ); - P( E, A, B, C, D, R(51) ); - P( D, E, A, B, C, R(52) ); - P( C, D, E, A, B, R(53) ); - P( B, C, D, E, A, R(54) ); - P( A, B, C, D, E, R(55) ); - P( E, A, B, C, D, R(56) ); - P( D, E, A, B, C, R(57) ); - P( C, D, E, A, B, R(58) ); - P( B, C, D, E, A, R(59) ); + P( A, B, C, D, E, R(40) ); + P( E, A, B, C, D, R(41) ); + P( D, E, A, B, C, R(42) ); + P( C, D, E, A, B, R(43) ); + P( B, C, D, E, A, R(44) ); + P( A, B, C, D, E, R(45) ); + P( E, A, B, C, D, R(46) ); + P( D, E, A, B, C, R(47) ); + P( C, D, E, A, B, R(48) ); + P( B, C, D, E, A, R(49) ); + P( A, B, C, D, E, R(50) ); + P( E, A, B, C, D, R(51) ); + P( D, E, A, B, C, R(52) ); + P( C, D, E, A, B, R(53) ); + P( B, C, D, E, A, R(54) ); + P( A, B, C, D, E, R(55) ); + P( E, A, B, C, D, R(56) ); + P( D, E, A, B, C, R(57) ); + P( C, D, E, A, B, R(58) ); + P( B, C, D, E, A, R(59) ); #undef K #undef F @@ -215,139 +215,139 @@ static void sha1_process( sha1_context *ctx, unsigned char data[64] ) #define F(x,y,z) (x ^ y ^ z) #define K 0xCA62C1D6 - P( A, B, C, D, E, R(60) ); - P( E, A, B, C, D, R(61) ); - P( D, E, A, B, C, R(62) ); - P( C, D, E, A, B, R(63) ); - P( B, C, D, E, A, R(64) ); - P( A, B, C, D, E, R(65) ); - P( E, A, B, C, D, R(66) ); - P( D, E, A, B, C, R(67) ); - P( C, D, E, A, B, R(68) ); - P( B, C, D, E, A, R(69) ); - P( A, B, C, D, E, R(70) ); - P( E, A, B, C, D, R(71) ); - P( D, E, A, B, C, R(72) ); - P( C, D, E, A, B, R(73) ); - P( B, C, D, E, A, R(74) ); - P( A, B, C, D, E, R(75) ); - P( E, A, B, C, D, R(76) ); - P( D, E, A, B, C, R(77) ); - P( C, D, E, A, B, R(78) ); - P( B, C, D, E, A, R(79) ); + P( A, B, C, D, E, R(60) ); + P( E, A, B, C, D, R(61) ); + P( D, E, A, B, C, R(62) ); + P( C, D, E, A, B, R(63) ); + P( B, C, D, E, A, R(64) ); + P( A, B, C, D, E, R(65) ); + P( E, A, B, C, D, R(66) ); + P( D, E, A, B, C, R(67) ); + P( C, D, E, A, B, R(68) ); + P( B, C, D, E, A, R(69) ); + P( A, B, C, D, E, R(70) ); + P( E, A, B, C, D, R(71) ); + P( D, E, A, B, C, R(72) ); + P( C, D, E, A, B, R(73) ); + P( B, C, D, E, A, R(74) ); + P( A, B, C, D, E, R(75) ); + P( E, A, B, C, D, R(76) ); + P( D, E, A, B, C, R(77) ); + P( C, D, E, A, B, R(78) ); + P( B, C, D, E, A, R(79) ); #undef K #undef F - ctx->state[0] += A; - ctx->state[1] += B; - ctx->state[2] += C; - ctx->state[3] += D; - ctx->state[4] += E; + ctx->state[0] += A; + ctx->state[1] += B; + ctx->state[2] += C; + ctx->state[3] += D; + ctx->state[4] += E; } /* - * SHA-1 process buffer - */ +* SHA-1 process buffer +*/ static void sha1_update( sha1_context *ctx, unsigned char *input, int ilen ) { - int fill; - unsigned long left; - - if( ilen <= 0 ) - return; - - left = ctx->total[0] & 0x3F; - fill = 64 - left; - - ctx->total[0] += ilen; - ctx->total[0] &= 0xFFFFFFFF; - - if( ctx->total[0] < (unsigned long) ilen ) - ctx->total[1]++; - - if( left && ilen >= fill ) - { - memcpy( (void *) (ctx->buffer + left), - (void *) input, fill ); - sha1_process( ctx, ctx->buffer ); - input += fill; - ilen -= fill; - left = 0; - } - - while( ilen >= 64 ) - { - sha1_process( ctx, input ); - input += 64; - ilen -= 64; - } - - if( ilen > 0 ) - { - memcpy( (void *) (ctx->buffer + left), - (void *) input, ilen ); - } + int fill; + unsigned long left; + + if( ilen <= 0 ) + return; + + left = ctx->total[0] & 0x3F; + fill = 64 - left; + + ctx->total[0] += ilen; + ctx->total[0] &= 0xFFFFFFFF; + + if( ctx->total[0] < (unsigned long) ilen ) + ctx->total[1]++; + + if( left && ilen >= fill ) + { + memcpy( (void *) (ctx->buffer + left), + (void *) input, fill ); + sha1_process( ctx, ctx->buffer ); + input += fill; + ilen -= fill; + left = 0; + } + + while( ilen >= 64 ) + { + sha1_process( ctx, input ); + input += 64; + ilen -= 64; + } + + if( ilen > 0 ) + { + memcpy( (void *) (ctx->buffer + left), + (void *) input, ilen ); + } } static const unsigned char sha1_padding[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* - * SHA-1 final digest - */ +* SHA-1 final digest +*/ static void sha1_finish( sha1_context *ctx, unsigned char output[20] ) { - unsigned long last, padn; - unsigned long high, low; - unsigned char msglen[8]; + unsigned long last, padn; + unsigned long high, low; + unsigned char msglen[8]; - high = ( ctx->total[0] >> 29 ) - | ( ctx->total[1] << 3 ); - low = ( ctx->total[0] << 3 ); + high = ( ctx->total[0] >> 29 ) + | ( ctx->total[1] << 3 ); + low = ( ctx->total[0] << 3 ); - PUT_UINT32_BE( high, msglen, 0 ); - PUT_UINT32_BE( low, msglen, 4 ); + PUT_UINT32_BE( high, msglen, 0 ); + PUT_UINT32_BE( low, msglen, 4 ); - last = ctx->total[0] & 0x3F; - padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); + last = ctx->total[0] & 0x3F; + padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); - sha1_update( ctx, (unsigned char *) sha1_padding, padn ); - sha1_update( ctx, msglen, 8 ); + sha1_update( ctx, (unsigned char *) sha1_padding, padn ); + sha1_update( ctx, msglen, 8 ); - PUT_UINT32_BE( ctx->state[0], output, 0 ); - PUT_UINT32_BE( ctx->state[1], output, 4 ); - PUT_UINT32_BE( ctx->state[2], output, 8 ); - PUT_UINT32_BE( ctx->state[3], output, 12 ); - PUT_UINT32_BE( ctx->state[4], output, 16 ); + PUT_UINT32_BE( ctx->state[0], output, 0 ); + PUT_UINT32_BE( ctx->state[1], output, 4 ); + PUT_UINT32_BE( ctx->state[2], output, 8 ); + PUT_UINT32_BE( ctx->state[3], output, 12 ); + PUT_UINT32_BE( ctx->state[4], output, 16 ); } void get_sha1 (uae_u8 *input, int len, uae_u8 *out) { - sha1_context ctx; + sha1_context ctx; - sha1_starts( &ctx ); - sha1_update( &ctx, input, len ); - sha1_finish( &ctx, out ); + sha1_starts( &ctx ); + sha1_update( &ctx, input, len ); + sha1_finish( &ctx, out ); } const TCHAR *get_sha1_txt (uae_u8 *input, int len) { - static TCHAR outtxt[SHA1_SIZE * 2 + 1]; - uae_u8 out[SHA1_SIZE]; - int i; - TCHAR *p; - - p = outtxt; - get_sha1 (input, len, out); - for (i = 0; i < SHA1_SIZE; i++) { - _stprintf (p, L"%02X", out[i]); - p += 2; - } - *p = 0; - return outtxt; + static TCHAR outtxt[SHA1_SIZE * 2 + 1]; + uae_u8 out[SHA1_SIZE]; + int i; + TCHAR *p; + + p = outtxt; + get_sha1 (input, len, out); + for (i = 0; i < SHA1_SIZE; i++) { + _stprintf (p, L"%02X", out[i]); + p += 2; + } + *p = 0; + return outtxt; } \ No newline at end of file diff --git a/custom.c b/custom.c index 085a837b..d85c5550 100644 --- a/custom.c +++ b/custom.c @@ -1,12 +1,12 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Custom chip emulation - * - * Copyright 1995-2002 Bernd Schmidt - * Copyright 1995 Alessandro Bissacco - * Copyright 2000-2009 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Custom chip emulation +* +* Copyright 1995-2002 Bernd Schmidt +* Copyright 1995 Alessandro Bissacco +* Copyright 2000-2009 Toni Wilen +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -66,43 +66,43 @@ STATIC_INLINE int nocustom (void) { - if (picasso_on && currprefs.picasso96_nocustom) - return 1; - return 0; + if (picasso_on && currprefs.picasso96_nocustom) + return 1; + return 0; } void uae_abort (const TCHAR *format,...) { - static int nomore; - va_list parms; - TCHAR buffer[1000]; + static int nomore; + va_list parms; + TCHAR buffer[1000]; - va_start (parms, format); - _vsntprintf (buffer, sizeof (buffer) - 1, format, parms ); - va_end (parms); - if (nomore) { - write_log (L"%s\n", buffer); - return; - } - gui_message (buffer); - nomore = 1; + va_start (parms, format); + _vsntprintf (buffer, sizeof (buffer) - 1, format, parms ); + va_end (parms); + if (nomore) { + write_log (L"%s\n", buffer); + return; + } + gui_message (buffer); + nomore = 1; } #if 0 void customhack_put (struct customhack *ch, uae_u16 v, int hpos) { - ch->v = v; - ch->vpos = vpos; - ch->hpos = hpos; + ch->v = v; + ch->vpos = vpos; + ch->hpos = hpos; } uae_u16 customhack_get (struct customhack *ch, int hpos) { - if (ch->vpos == vpos && ch->hpos == hpos) { - ch->vpos = -1; - return 0xffff; - } - return ch->v; + if (ch->vpos == vpos && ch->hpos == hpos) { + ch->vpos = -1; + return 0xffff; + } + return ch->v; } #endif @@ -141,10 +141,10 @@ static int lof_changed = 0; static int scandoubled_line; /* Stupid genlock-detection prevention hack. - * We should stop calling vsync_handler() and - * hstop_handler() completely but it is not - * worth the trouble.. - */ +* We should stop calling vsync_handler() and +* hstop_handler() completely but it is not +* worth the trouble.. +*/ static int vpos_previous, hpos_previous; static int vpos_lpen, hpos_lpen, lightpen_triggered; int lightpen_x, lightpen_y, lightpen_cx, lightpen_cy; @@ -158,8 +158,8 @@ static uae_u32 sprclx[16], clxmask[16]; static uae_u8 color_regs_aga_genlock[256]; /* - * Hardware registers of all sorts. - */ +* Hardware registers of all sorts. +*/ static int REGPARAM3 custom_wput_1 (int, uaecptr, uae_u32, int) REGPARAM; @@ -187,16 +187,16 @@ static int ciavsyncmode; #define HSYNCTIME (maxhpos * CYCLE_UNIT); /* This is but an educated guess. It seems to be correct, but this stuff - * isn't documented well. */ +* isn't documented well. */ struct sprite { - uaecptr pt; - int xpos; - int vstart; - int vstop; - int dblscan; /* AGA SSCAN2 */ - int armed; - int dmastate; - int dmacycle; + uaecptr pt; + int xpos; + int vstart; + int vstop; + int dblscan; /* AGA SSCAN2 */ + int armed; + int dmastate; + int dmacycle; }; static struct sprite spr[MAX_SPRITES]; @@ -247,7 +247,7 @@ static int bplcon1_hpos; enum diw_states { - DIW_waiting_start, DIW_waiting_stop + DIW_waiting_start, DIW_waiting_stop }; static int plffirstline, plflastline; @@ -272,42 +272,42 @@ static int copper_access; static unsigned int clxdat, clxcon, clxcon2, clxcon_bpl_enable, clxcon_bpl_match; enum copper_states { - COP_stop, - COP_read1, - COP_read2, - COP_bltwait, - COP_wait_in2, - COP_skip_in2, - COP_wait1, - COP_wait, - COP_skip1, - COP_strobe_delay1, - COP_strobe_delay2, - COP_start_delay + COP_stop, + COP_read1, + COP_read2, + COP_bltwait, + COP_wait_in2, + COP_skip_in2, + COP_wait1, + COP_wait, + COP_skip1, + COP_strobe_delay1, + COP_strobe_delay2, + COP_start_delay }; struct copper { - /* The current instruction words. */ - unsigned int i1, i2; - unsigned int saved_i1, saved_i2; - enum copper_states state, state_prev; - /* Instruction pointer. */ - uaecptr ip, saved_ip; - int hpos, vpos; - unsigned int ignore_next; - int vcmp, hcmp; - - int strobe; /* COPJMP1 / COPJMP2 accessed */ - int last_write, last_write_hpos; - int moveaddr, movedata, movedelay; + /* The current instruction words. */ + unsigned int i1, i2; + unsigned int saved_i1, saved_i2; + enum copper_states state, state_prev; + /* Instruction pointer. */ + uaecptr ip, saved_ip; + int hpos, vpos; + unsigned int ignore_next; + int vcmp, hcmp; + + int strobe; /* COPJMP1 / COPJMP2 accessed */ + int last_write, last_write_hpos; + int moveaddr, movedata, movedelay; }; static struct copper cop_state; static int copper_enabled_thisline; static int cop_min_waittime; /* - * Statistics - */ +* Statistics +*/ /* Used also by bebox.cpp */ unsigned long int frametime = 0, lastframetime = 0, timeframes = 0; @@ -365,149 +365,149 @@ static int fetch_cycle, fetch_modulo_cycle; enum plfstate { - plf_idle, - plf_start, - plf_active, - plf_passed_stop, - plf_passed_stop2, - plf_end + plf_idle, + plf_start, + plf_active, + plf_passed_stop, + plf_passed_stop2, + plf_end } plf_state; enum fetchstate { - fetch_not_started, - fetch_started, - fetch_was_plane0 + fetch_not_started, + fetch_started, + fetch_was_plane0 } fetch_state; /* - * helper functions - */ +* helper functions +*/ STATIC_INLINE int ecsshres(void) { - return bplcon0_res == RES_SUPERHIRES && (currprefs.chipset_mask & CSMASK_ECS_DENISE) && !(currprefs.chipset_mask & CSMASK_AGA); + return bplcon0_res == RES_SUPERHIRES && (currprefs.chipset_mask & CSMASK_ECS_DENISE) && !(currprefs.chipset_mask & CSMASK_AGA); } STATIC_INLINE int nodraw (void) { - return !currprefs.cpu_cycle_exact && framecnt != 0; + return !currprefs.cpu_cycle_exact && framecnt != 0; } static int doflickerfix (void) { - return currprefs.gfx_linedbl && doublescan < 0; + return currprefs.gfx_linedbl && doublescan < 0; } uae_u32 get_copper_address (int copno) { - switch (copno) { - case 1: return cop1lc; - case 2: return cop2lc; - case -1: return cop_state.ip; - default: return 0; - } + switch (copno) { + case 1: return cop1lc; + case 2: return cop2lc; + case -1: return cop_state.ip; + default: return 0; + } } int rpt_available = 0; void reset_frame_rate_hack (void) { - if (currprefs.m68k_speed != -1) - return; + if (currprefs.m68k_speed != -1) + return; - if (! rpt_available) { - currprefs.m68k_speed = 0; - return; - } + if (! rpt_available) { + currprefs.m68k_speed = 0; + return; + } - rpt_did_reset = 1; - is_lastline = 0; - vsyncmintime = read_processor_time () + vsynctime; - write_log (L"Resetting frame rate hack\n"); + rpt_did_reset = 1; + is_lastline = 0; + vsyncmintime = read_processor_time () + vsynctime; + write_log (L"Resetting frame rate hack\n"); } STATIC_INLINE void setclr (uae_u16 *p, uae_u16 val) { - if (val & 0x8000) - *p |= val & 0x7FFF; - else - *p &= ~val; + if (val & 0x8000) + *p |= val & 0x7FFF; + else + *p &= ~val; } STATIC_INLINE alloc_cycle (int hpos, int type) { #ifdef CPUEMU_12 #if 0 - if (cycle_line[hpos]) - write_log (L"hpos=%d, old=%d, new=%d\n", hpos, cycle_line[hpos], type); - if ((type == CYCLE_CPU || type == CYCLE_COPPER) && (hpos & 1)) - write_log (L"odd %d cycle %d\n", hpos); - if (!(hpos & 1) && (type == CYCLE_SPRITE || type == CYCLE_REFRESH || type == CYCLE_MISC)) - write_log (L"even %d cycle %d\n", type, hpos); + if (cycle_line[hpos]) + write_log (L"hpos=%d, old=%d, new=%d\n", hpos, cycle_line[hpos], type); + if ((type == CYCLE_CPU || type == CYCLE_COPPER) && (hpos & 1)) + write_log (L"odd %d cycle %d\n", hpos); + if (!(hpos & 1) && (type == CYCLE_SPRITE || type == CYCLE_REFRESH || type == CYCLE_MISC)) + write_log (L"even %d cycle %d\n", type, hpos); #endif - cycle_line[hpos] = type; + cycle_line[hpos] = type; #endif } STATIC_INLINE alloc_cycle_maybe (int hpos, int type) { - if (cycle_line[hpos] == 0) - alloc_cycle (hpos, type); + if (cycle_line[hpos] == 0) + alloc_cycle (hpos, type); } void alloc_cycle_ext(int hpos, int type) { - alloc_cycle (hpos, type); + alloc_cycle (hpos, type); } static void hsyncdelay (void) { #if 0 - static int prevhpos; - while (current_hpos () == prevhpos) - do_cycles(CYCLE_UNIT); - prevhpos = current_hpos(); + static int prevhpos; + while (current_hpos () == prevhpos) + do_cycles(CYCLE_UNIT); + prevhpos = current_hpos(); #endif } static void update_mirrors (void) { - aga_mode = (currprefs.chipset_mask & CSMASK_AGA) ? 1 : 0; - direct_rgb = aga_mode; + aga_mode = (currprefs.chipset_mask & CSMASK_AGA) ? 1 : 0; + direct_rgb = aga_mode; } STATIC_INLINE uae_u8 *pfield_xlateptr (uaecptr plpt, int bytecount) { - if (!chipmem_bank.check (plpt, bytecount)) { - static int count = 0; - if (!count) - count++, write_log (L"Warning: Bad playfield pointer\n"); - return NULL; - } - return chipmem_bank.xlateaddr (plpt); + if (!chipmem_bank.check (plpt, bytecount)) { + static int count = 0; + if (!count) + count++, write_log (L"Warning: Bad playfield pointer\n"); + return NULL; + } + return chipmem_bank.xlateaddr (plpt); } STATIC_INLINE void docols (struct color_entry *colentry) { - int i; + int i; #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) { - for (i = 0; i < 256; i++) { - int v = color_reg_get (colentry, i); - if (v < 0 || v > 16777215) - continue; - colentry->acolors[i] = getxcolor (v); - } - } else { + if (currprefs.chipset_mask & CSMASK_AGA) { + for (i = 0; i < 256; i++) { + int v = color_reg_get (colentry, i); + if (v < 0 || v > 16777215) + continue; + colentry->acolors[i] = getxcolor (v); + } + } else { #endif - for (i = 0; i < 32; i++) { - int v = color_reg_get (colentry, i); - if (v < 0 || v > 4095) - continue; - colentry->acolors[i] = getxcolor (v); - } + for (i = 0; i < 32; i++) { + int v = color_reg_get (colentry, i); + if (v < 0 || v > 4095) + continue; + colentry->acolors[i] = getxcolor (v); + } #ifdef AGA - } + } #endif } @@ -515,90 +515,90 @@ extern struct color_entry colors_for_drawing; void notice_new_xcolors (void) { - int i; + int i; - update_mirrors (); - docols (¤t_colors); - docols (&colors_for_drawing); - for (i = 0; i < (MAXVPOS + 1) * 2; i++) { - docols (color_tables[0] + i); - docols (color_tables[1] + i); - } + update_mirrors (); + docols (¤t_colors); + docols (&colors_for_drawing); + for (i = 0; i < (MAXVPOS + 1) * 2; i++) { + docols (color_tables[0] + i); + docols (color_tables[1] + i); + } } static void do_sprites (int currhp); static void remember_ctable (void) { - if (remembered_color_entry == -1) { - /* The colors changed since we last recorded a color map. Record a - * new one. */ - color_reg_cpy (curr_color_tables + next_color_entry, ¤t_colors); - remembered_color_entry = next_color_entry++; - } - thisline_decision.ctable = remembered_color_entry; - if (color_src_match == -1 || color_dest_match != remembered_color_entry - || line_decisions[next_lineno].ctable != color_src_match) - { - /* The remembered comparison didn't help us - need to compare again. */ - int oldctable = line_decisions[next_lineno].ctable; - int changed = 0; - - if (oldctable == -1) { - changed = 1; - color_src_match = color_dest_match = -1; + if (remembered_color_entry == -1) { + /* The colors changed since we last recorded a color map. Record a + * new one. */ + color_reg_cpy (curr_color_tables + next_color_entry, ¤t_colors); + remembered_color_entry = next_color_entry++; + } + thisline_decision.ctable = remembered_color_entry; + if (color_src_match == -1 || color_dest_match != remembered_color_entry + || line_decisions[next_lineno].ctable != color_src_match) + { + /* The remembered comparison didn't help us - need to compare again. */ + int oldctable = line_decisions[next_lineno].ctable; + int changed = 0; + + if (oldctable == -1) { + changed = 1; + color_src_match = color_dest_match = -1; + } else { + color_compare_result = color_reg_cmp (&prev_color_tables[oldctable], ¤t_colors) != 0; + if (color_compare_result) + changed = 1; + color_src_match = oldctable; + color_dest_match = remembered_color_entry; + } + thisline_changed |= changed; } else { - color_compare_result = color_reg_cmp (&prev_color_tables[oldctable], ¤t_colors) != 0; - if (color_compare_result) - changed = 1; - color_src_match = oldctable; - color_dest_match = remembered_color_entry; + /* We know the result of the comparison */ + if (color_compare_result) + thisline_changed = 1; } - thisline_changed |= changed; - } else { - /* We know the result of the comparison */ - if (color_compare_result) - thisline_changed = 1; - } } static void remember_ctable_for_border (void) { - remember_ctable (); + remember_ctable (); } /* Called to determine the state of the horizontal display window state - * machine at the current position. It might have changed since we last - * checked. */ +* machine at the current position. It might have changed since we last +* checked. */ static void decide_diw (int hpos) { - /* Last hpos = hpos + 0.5, eg. normal PAL end hpos is 227.5 * 2 = 455 */ - int pix_hpos = coord_diw_to_window_x (hpos == maxhpos ? hpos * 2 + 1 : hpos * 2); - if (hdiwstate == DIW_waiting_start && thisline_decision.diwfirstword == -1 - && pix_hpos >= diwfirstword && last_diw_pix_hpos < diwfirstword) - { - thisline_decision.diwfirstword = diwfirstword < 0 ? 0 : diwfirstword; - hdiwstate = DIW_waiting_stop; - } - if (hdiwstate == DIW_waiting_stop && thisline_decision.diwlastword == -1 - && pix_hpos >= diwlastword && last_diw_pix_hpos < diwlastword) - { - thisline_decision.diwlastword = diwlastword < 0 ? 0 : diwlastword; - hdiwstate = DIW_waiting_start; - } - last_diw_pix_hpos = pix_hpos; + /* Last hpos = hpos + 0.5, eg. normal PAL end hpos is 227.5 * 2 = 455 */ + int pix_hpos = coord_diw_to_window_x (hpos == maxhpos ? hpos * 2 + 1 : hpos * 2); + if (hdiwstate == DIW_waiting_start && thisline_decision.diwfirstword == -1 + && pix_hpos >= diwfirstword && last_diw_pix_hpos < diwfirstword) + { + thisline_decision.diwfirstword = diwfirstword < 0 ? 0 : diwfirstword; + hdiwstate = DIW_waiting_stop; + } + if (hdiwstate == DIW_waiting_stop && thisline_decision.diwlastword == -1 + && pix_hpos >= diwlastword && last_diw_pix_hpos < diwlastword) + { + thisline_decision.diwlastword = diwlastword < 0 ? 0 : diwlastword; + hdiwstate = DIW_waiting_start; + } + last_diw_pix_hpos = pix_hpos; } static int fetchmode; static int real_bitplane_number[3][3][9]; /* Disable bitplane DMA if planes > available DMA slots. This is needed - e.g. by the Sanity WOC demo (at the "Party Effect"). */ +e.g. by the Sanity WOC demo (at the "Party Effect"). */ STATIC_INLINE int GET_PLANES_LIMIT (uae_u16 bc0) { - int res = GET_RES_AGNUS (bc0); - int planes = GET_PLANES (bc0); - return real_bitplane_number[fetchmode][res][planes]; + int res = GET_RES_AGNUS (bc0); + int planes = GET_PLANES (bc0); + return real_bitplane_number[fetchmode][res][planes]; } /* The HRM says 0xD8, but that can't work... */ @@ -607,19 +607,19 @@ STATIC_INLINE int GET_PLANES_LIMIT (uae_u16 bc0) static void add_modulos (void) { - int m1, m2; + int m1, m2; - if (fmode & 0x4000) { - if (((diwstrt >> 8) ^ vpos) & 1) - m1 = m2 = bpl2mod; - else - m1 = m2 = bpl1mod; - } else { - m1 = bpl1mod; - m2 = bpl2mod; - } + if (fmode & 0x4000) { + if (((diwstrt >> 8) ^ vpos) & 1) + m1 = m2 = bpl2mod; + else + m1 = m2 = bpl1mod; + } else { + m1 = bpl1mod; + m2 = bpl2mod; + } - switch (bplcon0_planes_limit) { + switch (bplcon0_planes_limit) { #ifdef AGA case 8: bplpt[7] += m2; bplptx[7] += m2; case 7: bplpt[6] += m1; bplptx[6] += m1; @@ -630,47 +630,47 @@ static void add_modulos (void) case 3: bplpt[2] += m1; bplptx[2] += m1; case 2: bplpt[1] += m2; bplptx[1] += m2; case 1: bplpt[0] += m1; bplptx[0] += m1; - } + } } static void finish_playfield_line (void) { - /* The latter condition might be able to happen in interlaced frames. */ - if (vpos >= minfirstline && (thisframe_first_drawn_line == -1 || vpos < thisframe_first_drawn_line)) - thisframe_first_drawn_line = vpos; - thisframe_last_drawn_line = vpos; + /* The latter condition might be able to happen in interlaced frames. */ + if (vpos >= minfirstline && (thisframe_first_drawn_line == -1 || vpos < thisframe_first_drawn_line)) + thisframe_first_drawn_line = vpos; + thisframe_last_drawn_line = vpos; #ifdef SMART_UPDATE - if (line_decisions[next_lineno].plflinelen != thisline_decision.plflinelen - || line_decisions[next_lineno].plfleft != thisline_decision.plfleft - || line_decisions[next_lineno].bplcon0 != thisline_decision.bplcon0 - || line_decisions[next_lineno].bplcon2 != thisline_decision.bplcon2 + if (line_decisions[next_lineno].plflinelen != thisline_decision.plflinelen + || line_decisions[next_lineno].plfleft != thisline_decision.plfleft + || line_decisions[next_lineno].bplcon0 != thisline_decision.bplcon0 + || line_decisions[next_lineno].bplcon2 != thisline_decision.bplcon2 #ifdef ECS_DENISE - || line_decisions[next_lineno].bplcon3 != thisline_decision.bplcon3 + || line_decisions[next_lineno].bplcon3 != thisline_decision.bplcon3 #endif #ifdef AGA - || line_decisions[next_lineno].bplcon4 != thisline_decision.bplcon4 + || line_decisions[next_lineno].bplcon4 != thisline_decision.bplcon4 #endif - ) + ) #endif /* SMART_UPDATE */ - thisline_changed = 1; + thisline_changed = 1; } /* The fetch unit mainly controls ddf stop. It's the number of cycles that - are contained in an indivisible block during which ddf is active. E.g. - if DDF starts at 0x30, and fetchunit is 8, then possible DDF stops are - 0x30 + n * 8. */ +are contained in an indivisible block during which ddf is active. E.g. +if DDF starts at 0x30, and fetchunit is 8, then possible DDF stops are +0x30 + n * 8. */ static int fetchunit, fetchunit_mask; /* The delay before fetching the same bitplane again. Can be larger than - the number of bitplanes; in that case there are additional empty cycles - with no data fetch (this happens for high fetchmodes and low - resolutions). */ +the number of bitplanes; in that case there are additional empty cycles +with no data fetch (this happens for high fetchmodes and low +resolutions). */ static int fetchstart, fetchstart_shift, fetchstart_mask; /* fm_maxplane holds the maximum number of planes possible with the current - fetch mode. This selects the cycle diagram: - 8 planes: 73516240 - 4 planes: 3120 - 2 planes: 10. */ +fetch mode. This selects the cycle diagram: +8 planes: 73516240 +4 planes: 3120 +2 planes: 10. */ static int fm_maxplane, fm_maxplane_shift; /* The corresponding values, by fetchmode and display resolution. */ @@ -686,68 +686,68 @@ static const int cycle_sequences[3 * 8] = { 2,1,2,1,2,1,2,1, 4,2,3,1,4,2,3,1, 8, static void debug_cycle_diagram (void) { - int fm, res, planes, cycle, v; - TCHAR aa; - - for (fm = 0; fm <= 2; fm++) { - write_log (L"FMODE %d\n=======\n", fm); - for (res = 0; res <= 2; res++) { - for (planes = 0; planes <= 8; planes++) { - write_log (L"%d: ",planes); - for (cycle = 0; cycle < 32; cycle++) { - v=cycle_diagram_table[fm][res][planes][cycle]; - if (v==0) aa='-'; else if(v>0) aa='1'; else aa='X'; - write_log (L"%c",aa); + int fm, res, planes, cycle, v; + TCHAR aa; + + for (fm = 0; fm <= 2; fm++) { + write_log (L"FMODE %d\n=======\n", fm); + for (res = 0; res <= 2; res++) { + for (planes = 0; planes <= 8; planes++) { + write_log (L"%d: ",planes); + for (cycle = 0; cycle < 32; cycle++) { + v=cycle_diagram_table[fm][res][planes][cycle]; + if (v==0) aa='-'; else if(v>0) aa='1'; else aa='X'; + write_log (L"%c",aa); + } + write_log (L" %d:%d\n", + cycle_diagram_free_cycles[fm][res][planes], cycle_diagram_total_cycles[fm][res][planes]); + } + write_log (L"\n"); } - write_log (L" %d:%d\n", - cycle_diagram_free_cycles[fm][res][planes], cycle_diagram_total_cycles[fm][res][planes]); - } - write_log (L"\n"); } - } - fm=0; + fm=0; } static void create_cycle_diagram_table (void) { - int fm, res, cycle, planes, rplanes, v; - int fetch_start, max_planes, freecycles; - const int *cycle_sequence; - - for (fm = 0; fm <= 2; fm++) { - for (res = 0; res <= 2; res++) { - max_planes = fm_maxplanes[fm * 4 + res]; - fetch_start = 1 << fetchstarts[fm * 4 + res]; - cycle_sequence = &cycle_sequences[(max_planes - 1) * 8]; - max_planes = 1 << max_planes; - for (planes = 0; planes <= 8; planes++) { - freecycles = 0; - for (cycle = 0; cycle < 32; cycle++) - cycle_diagram_table[fm][res][planes][cycle] = -1; - if (planes <= max_planes) { - for (cycle = 0; cycle < fetch_start; cycle++) { - if (cycle < max_planes && planes >= cycle_sequence[cycle & 7]) { - v = cycle_sequence[cycle & 7]; - } else { - v = 0; - freecycles++; + int fm, res, cycle, planes, rplanes, v; + int fetch_start, max_planes, freecycles; + const int *cycle_sequence; + + for (fm = 0; fm <= 2; fm++) { + for (res = 0; res <= 2; res++) { + max_planes = fm_maxplanes[fm * 4 + res]; + fetch_start = 1 << fetchstarts[fm * 4 + res]; + cycle_sequence = &cycle_sequences[(max_planes - 1) * 8]; + max_planes = 1 << max_planes; + for (planes = 0; planes <= 8; planes++) { + freecycles = 0; + for (cycle = 0; cycle < 32; cycle++) + cycle_diagram_table[fm][res][planes][cycle] = -1; + if (planes <= max_planes) { + for (cycle = 0; cycle < fetch_start; cycle++) { + if (cycle < max_planes && planes >= cycle_sequence[cycle & 7]) { + v = cycle_sequence[cycle & 7]; + } else { + v = 0; + freecycles++; + } + cycle_diagram_table[fm][res][planes][cycle] = v; + } + } + cycle_diagram_free_cycles[fm][res][planes] = freecycles; + cycle_diagram_total_cycles[fm][res][planes] = fetch_start; + rplanes = planes; + if (rplanes > max_planes) + rplanes = 0; + if (rplanes == 7 && fm == 0 && res == 0 && !(currprefs.chipset_mask & CSMASK_AGA)) + rplanes = 4; + real_bitplane_number[fm][res][planes] = rplanes; } - cycle_diagram_table[fm][res][planes][cycle] = v; - } } - cycle_diagram_free_cycles[fm][res][planes] = freecycles; - cycle_diagram_total_cycles[fm][res][planes] = fetch_start; - rplanes = planes; - if (rplanes > max_planes) - rplanes = 0; - if (rplanes == 7 && fm == 0 && res == 0 && !(currprefs.chipset_mask & CSMASK_AGA)) - rplanes = 4; - real_bitplane_number[fm][res][planes] = rplanes; - } - } - } + } #if 0 - debug_cycle_diagram (); + debug_cycle_diagram (); #endif } @@ -758,22 +758,22 @@ static int cycle_diagram_shift; static void estimate_last_fetch_cycle (int hpos) { - int fetchunit = fetchunits[fetchmode * 4 + bplcon0_res]; + int fetchunit = fetchunits[fetchmode * 4 + bplcon0_res]; - if (plf_state < plf_passed_stop) { - int stop = plfstop < hpos || plfstop > HARD_DDF_STOP ? HARD_DDF_STOP : plfstop; - /* We know that fetching is up-to-date up until hpos, so we can use fetch_cycle. */ - int fetch_cycle_at_stop = fetch_cycle + (stop - hpos); - int starting_last_block_at = (fetch_cycle_at_stop + fetchunit - 1) & ~(fetchunit - 1); + if (plf_state < plf_passed_stop) { + int stop = plfstop < hpos || plfstop > HARD_DDF_STOP ? HARD_DDF_STOP : plfstop; + /* We know that fetching is up-to-date up until hpos, so we can use fetch_cycle. */ + int fetch_cycle_at_stop = fetch_cycle + (stop - hpos); + int starting_last_block_at = (fetch_cycle_at_stop + fetchunit - 1) & ~(fetchunit - 1); - estimated_last_fetch_cycle = hpos + (starting_last_block_at - fetch_cycle) + fetchunit; - } else { - int starting_last_block_at = (fetch_cycle + fetchunit - 1) & ~(fetchunit - 1); - if (plf_state == plf_passed_stop2) - starting_last_block_at -= fetchunit; + estimated_last_fetch_cycle = hpos + (starting_last_block_at - fetch_cycle) + fetchunit; + } else { + int starting_last_block_at = (fetch_cycle + fetchunit - 1) & ~(fetchunit - 1); + if (plf_state == plf_passed_stop2) + starting_last_block_at -= fetchunit; - estimated_last_fetch_cycle = hpos + (starting_last_block_at - fetch_cycle) + fetchunit; - } + estimated_last_fetch_cycle = hpos + (starting_last_block_at - fetch_cycle) + fetchunit; + } } static uae_u32 outword[MAX_PLANES]; @@ -790,11 +790,11 @@ static int toscr_res, toscr_nr_planes, toscr_nr_planes2, fetchwidth; static int toscr_delay1, toscr_delay2; /* The number of bits left from the last fetched words. - This is an optimization - conceptually, we have to make sure the result is - the same as if toscr is called in each clock cycle. However, to speed this - up, we accumulate display data; this variable keeps track of how much. - Thus, once we do call toscr_nbits (which happens at least every 16 bits), - we can do more work at once. */ +This is an optimization - conceptually, we have to make sure the result is +the same as if toscr is called in each clock cycle. However, to speed this +up, we accumulate display data; this variable keeps track of how much. +Thus, once we do call toscr_nbits (which happens at least every 16 bits), +we can do more work at once. */ static int toscr_nbits; /* undocumented bitplane delay hardware feature */ @@ -802,93 +802,93 @@ static int delayoffset; STATIC_INLINE void compute_delay_offset (void) { - delayoffset = (16 << fetchmode) - (((plfstrt - HARD_DDF_START) & fetchstart_mask) << 1); + delayoffset = (16 << fetchmode) - (((plfstrt - HARD_DDF_START) & fetchstart_mask) << 1); #if 0 - /* maybe we can finally get rid of this stupid table.. */ - if (tmp == 4) - delayoffset = 4; // Loons Docs - else if (tmp == 8) - delayoffset = 8; - else if (tmp == 12) // Loons Docs - delayoffset = 4; - else if (tmp == 16) /* Overkill AGA */ - delayoffset = 48; - else if (tmp == 24) /* AB 2 */ - delayoffset = 8; - else if (tmp == 32) - delayoffset = 32; - else if (tmp == 48) /* Pinball Illusions AGA, ingame */ - delayoffset = 16; - else /* what about 40 and 56? */ - delayoffset = 0; - //write_log (L"%d:%d ", vpos, delayoffset); + /* maybe we can finally get rid of this stupid table.. */ + if (tmp == 4) + delayoffset = 4; // Loons Docs + else if (tmp == 8) + delayoffset = 8; + else if (tmp == 12) // Loons Docs + delayoffset = 4; + else if (tmp == 16) /* Overkill AGA */ + delayoffset = 48; + else if (tmp == 24) /* AB 2 */ + delayoffset = 8; + else if (tmp == 32) + delayoffset = 32; + else if (tmp == 48) /* Pinball Illusions AGA, ingame */ + delayoffset = 16; + else /* what about 40 and 56? */ + delayoffset = 0; + //write_log (L"%d:%d ", vpos, delayoffset); #endif } static void record_color_change2 (int hpos, int regno, unsigned long value) { - curr_color_changes[next_color_change].linepos = hpos * 2; + curr_color_changes[next_color_change].linepos = hpos * 2; #if 0 - // hpos >= 0xe0, add 2 lores pixels (should be in copper emul..) - //curr_color_changes[next_color_change].linepos += (hpos >= maxhpos - 3) ? 2 : 0; + // hpos >= 0xe0, add 2 lores pixels (should be in copper emul..) + //curr_color_changes[next_color_change].linepos += (hpos >= maxhpos - 3) ? 2 : 0; #endif - curr_color_changes[next_color_change].regno = regno; - curr_color_changes[next_color_change++].value = value; - curr_color_changes[next_color_change].regno = -1; + curr_color_changes[next_color_change].regno = regno; + curr_color_changes[next_color_change++].value = value; + curr_color_changes[next_color_change].regno = -1; } static int isehb (uae_u16 bplcon0, uae_u16 bplcon2) { - int bplehb; - if (currprefs.chipset_mask & CSMASK_AGA) - bplehb = (bplcon0 & 0x7010) == 0x6000; - else if (currprefs.chipset_mask & CSMASK_ECS_DENISE) - bplehb = ((bplcon0 & 0xFC00) == 0x6000 || (bplcon0 & 0xFC00) == 0x7000); - else - bplehb = ((bplcon0 & 0xFC00) == 0x6000 || (bplcon0 & 0xFC00) == 0x7000) && !currprefs.cs_denisenoehb; - return bplehb; + int bplehb; + if (currprefs.chipset_mask & CSMASK_AGA) + bplehb = (bplcon0 & 0x7010) == 0x6000; + else if (currprefs.chipset_mask & CSMASK_ECS_DENISE) + bplehb = ((bplcon0 & 0xFC00) == 0x6000 || (bplcon0 & 0xFC00) == 0x7000); + else + bplehb = ((bplcon0 & 0xFC00) == 0x6000 || (bplcon0 & 0xFC00) == 0x7000) && !currprefs.cs_denisenoehb; + return bplehb; } // OCS/ECS, lores, 7 planes = 4 "real" planes + BPL5DAT and BPL6DAT as 5th and 6th plane STATIC_INLINE int isocs7planes (void) { - return !(currprefs.chipset_mask & CSMASK_AGA) && bplcon0_res == 0 && bplcon0_planes == 7; + return !(currprefs.chipset_mask & CSMASK_AGA) && bplcon0_res == 0 && bplcon0_planes == 7; } int is_bitplane_dma (int hpos) { - if (fetch_state == fetch_not_started || hpos < plfstrt) - return 0; - if ((plf_state == plf_end && hpos >= thisline_decision.plfright) - || hpos >= estimated_last_fetch_cycle) - return 0; - return curr_diagram[(hpos - cycle_diagram_shift) & fetchstart_mask]; + if (fetch_state == fetch_not_started || hpos < plfstrt) + return 0; + if ((plf_state == plf_end && hpos >= thisline_decision.plfright) + || hpos >= estimated_last_fetch_cycle) + return 0; + return curr_diagram[(hpos - cycle_diagram_shift) & fetchstart_mask]; } STATIC_INLINE int is_bitplane_dma_inline (int hpos) { - if (fetch_state == fetch_not_started || hpos < plfstrt) - return 0; - if ((plf_state == plf_end && hpos >= thisline_decision.plfright) - || hpos >= estimated_last_fetch_cycle) - return 0; - return curr_diagram[(hpos - cycle_diagram_shift) & fetchstart_mask]; + if (fetch_state == fetch_not_started || hpos < plfstrt) + return 0; + if ((plf_state == plf_end && hpos >= thisline_decision.plfright) + || hpos >= estimated_last_fetch_cycle) + return 0; + return curr_diagram[(hpos - cycle_diagram_shift) & fetchstart_mask]; } static void update_denise (int hpos) { - toscr_res = GET_RES_DENISE (bplcon0d); - if (bplcon0dd != bplcon0d) { - record_color_change2 (hpos, 0x100 + 0x1000, bplcon0d); - bplcon0dd = bplcon0d; - } - toscr_nr_planes = GET_PLANES (bplcon0d); - if (isocs7planes ()) { - if (toscr_nr_planes2 < 6) - toscr_nr_planes2 = 6; - } else { - toscr_nr_planes2 = toscr_nr_planes; - } + toscr_res = GET_RES_DENISE (bplcon0d); + if (bplcon0dd != bplcon0d) { + record_color_change2 (hpos, 0x100 + 0x1000, bplcon0d); + bplcon0dd = bplcon0d; + } + toscr_nr_planes = GET_PLANES (bplcon0d); + if (isocs7planes ()) { + if (toscr_nr_planes2 < 6) + toscr_nr_planes2 = 6; + } else { + toscr_nr_planes2 = toscr_nr_planes; + } } static int bpldmasetuphpos; @@ -897,40 +897,40 @@ static int bpldmasetupphase; /* set currently active Agnus bitplane DMA sequence */ static void setup_fmodes (int hpos) { - switch (fmode & 3) - { + switch (fmode & 3) + { case 0: - fetchmode = 0; - break; + fetchmode = 0; + break; case 1: case 2: - fetchmode = 1; - break; + fetchmode = 1; + break; case 3: - fetchmode = 2; - break; - } - badmode = GET_RES_AGNUS (bplcon0) != GET_RES_DENISE (bplcon0); - bplcon0_res = GET_RES_AGNUS (bplcon0); - bplcon0_planes = GET_PLANES (bplcon0); - bplcon0_planes_limit = GET_PLANES_LIMIT (bplcon0); - fetchunit = fetchunits[fetchmode * 4 + bplcon0_res]; - fetchunit_mask = fetchunit - 1; - fetchstart_shift = fetchstarts[fetchmode * 4 + bplcon0_res]; - fetchstart = 1 << fetchstart_shift; - fetchstart_mask = fetchstart - 1; - fm_maxplane_shift = fm_maxplanes[fetchmode * 4 + bplcon0_res]; - fm_maxplane = 1 << fm_maxplane_shift; - fetch_modulo_cycle = fetchunit - fetchstart; - if (is_bitplane_dma (hpos - 1)) - cycle_line[hpos - 1] = 1; - curr_diagram = cycle_diagram_table[fetchmode][bplcon0_res][bplcon0_planes_limit]; - estimate_last_fetch_cycle (hpos); - if (bpldmasetuphpos >= 0 && debug_dma) - record_dma_event (DMA_EVENT_BPLFETCHUPDATE, hpos, vpos); - bpldmasetuphpos = -1; - bpldmasetupphase = 0; - ddf_change = vpos; + fetchmode = 2; + break; + } + badmode = GET_RES_AGNUS (bplcon0) != GET_RES_DENISE (bplcon0); + bplcon0_res = GET_RES_AGNUS (bplcon0); + bplcon0_planes = GET_PLANES (bplcon0); + bplcon0_planes_limit = GET_PLANES_LIMIT (bplcon0); + fetchunit = fetchunits[fetchmode * 4 + bplcon0_res]; + fetchunit_mask = fetchunit - 1; + fetchstart_shift = fetchstarts[fetchmode * 4 + bplcon0_res]; + fetchstart = 1 << fetchstart_shift; + fetchstart_mask = fetchstart - 1; + fm_maxplane_shift = fm_maxplanes[fetchmode * 4 + bplcon0_res]; + fm_maxplane = 1 << fm_maxplane_shift; + fetch_modulo_cycle = fetchunit - fetchstart; + if (is_bitplane_dma (hpos - 1)) + cycle_line[hpos - 1] = 1; + curr_diagram = cycle_diagram_table[fetchmode][bplcon0_res][bplcon0_planes_limit]; + estimate_last_fetch_cycle (hpos); + if (bpldmasetuphpos >= 0 && debug_dma) + record_dma_event (DMA_EVENT_BPLFETCHUPDATE, hpos, vpos); + bpldmasetuphpos = -1; + bpldmasetupphase = 0; + ddf_change = vpos; } static void BPLCON0_Denise (int hpos, uae_u16 v); @@ -944,229 +944,229 @@ static void BPLCON0_Denise (int hpos, uae_u16 v); static void maybe_setup_fmodes (int hpos) { - switch (bpldmasetupphase) - { - case 0: - BPLCON0_Denise (hpos, bplcon0); - bpldmasetupphase++; - bpldmasetuphpos += BPLCON_AGNUS_DELAY - BPLCON_DENISE_DELAY; - break; - case 1: - setup_fmodes (hpos); - break; - } + switch (bpldmasetupphase) + { + case 0: + BPLCON0_Denise (hpos, bplcon0); + bpldmasetupphase++; + bpldmasetuphpos += BPLCON_AGNUS_DELAY - BPLCON_DENISE_DELAY; + break; + case 1: + setup_fmodes (hpos); + break; + } } STATIC_INLINE maybe_check (int hpos) { - if (bpldmasetuphpos > 0 && hpos >= bpldmasetuphpos) - maybe_setup_fmodes (hpos); + if (bpldmasetuphpos > 0 && hpos >= bpldmasetuphpos) + maybe_setup_fmodes (hpos); } static void bpldmainitdelay (int hpos) { - int needdelay = 1; - int hposa; - - hposa = hpos + BPLCON_AGNUS_DELAY; - ddf_change = vpos; - if (hposa >= maxhpos - 1) - needdelay = 0; - if (hposa < 0x14) - needdelay = 0; - if (!needdelay) { - BPLCON0_Denise (hposa, bplcon0); - setup_fmodes (hposa); - return; - } - if (bpldmasetuphpos < 0) { - bpldmasetupphase = 0; - bpldmasetuphpos = hpos + BPLCON_DENISE_DELAY; - } + int needdelay = 1; + int hposa; + + hposa = hpos + BPLCON_AGNUS_DELAY; + ddf_change = vpos; + if (hposa >= maxhpos - 1) + needdelay = 0; + if (hposa < 0x14) + needdelay = 0; + if (!needdelay) { + BPLCON0_Denise (hposa, bplcon0); + setup_fmodes (hposa); + return; + } + if (bpldmasetuphpos < 0) { + bpldmasetupphase = 0; + bpldmasetuphpos = hpos + BPLCON_DENISE_DELAY; + } } /* Expand bplcon0/bplcon1 into the toscr_xxx variables. */ static void compute_toscr_delay_1 (void) { - int delay1 = (bplcon1 & 0x0f) | ((bplcon1 & 0x0c00) >> 6); - int delay2 = ((bplcon1 >> 4) & 0x0f) | (((bplcon1 >> 4) & 0x0c00) >> 6); - int shdelay1 = (bplcon1 >> 12) & 3; - int shdelay2 = (bplcon1 >> 8) & 3; - int delaymask; - int fetchwidth = 16 << fetchmode; + int delay1 = (bplcon1 & 0x0f) | ((bplcon1 & 0x0c00) >> 6); + int delay2 = ((bplcon1 >> 4) & 0x0f) | (((bplcon1 >> 4) & 0x0c00) >> 6); + int shdelay1 = (bplcon1 >> 12) & 3; + int shdelay2 = (bplcon1 >> 8) & 3; + int delaymask; + int fetchwidth = 16 << fetchmode; - delay1 += delayoffset; - delay2 += delayoffset; - delaymask = (fetchwidth - 1) >> toscr_res; - toscr_delay1 = (delay1 & delaymask) << toscr_res; - toscr_delay1 |= shdelay1 >> (RES_MAX - toscr_res); - toscr_delay2 = (delay2 & delaymask) << toscr_res; - toscr_delay2 |= shdelay2 >> (RES_MAX - toscr_res); + delay1 += delayoffset; + delay2 += delayoffset; + delaymask = (fetchwidth - 1) >> toscr_res; + toscr_delay1 = (delay1 & delaymask) << toscr_res; + toscr_delay1 |= shdelay1 >> (RES_MAX - toscr_res); + toscr_delay2 = (delay2 & delaymask) << toscr_res; + toscr_delay2 |= shdelay2 >> (RES_MAX - toscr_res); } static void compute_toscr_delay (int hpos) { - update_denise (hpos); - compute_toscr_delay_1 (); + update_denise (hpos); + compute_toscr_delay_1 (); } STATIC_INLINE void maybe_first_bpl1dat (int hpos) { - if (thisline_decision.plfleft == -1) { - thisline_decision.plfleft = hpos; - compute_delay_offset (); - } + if (thisline_decision.plfleft == -1) { + thisline_decision.plfleft = hpos; + compute_delay_offset (); + } } STATIC_INLINE void fetch (int nr, int fm, int hpos) { - if (nr < bplcon0_planes_limit) { - uaecptr p = bplpt[nr] + bpl_off[nr]; - bplpt[nr] += 2 << fm; - bplptx[nr] += 2 << fm; - if (nr == 0) - bpl1dat_written = 1; + if (nr < bplcon0_planes_limit) { + uaecptr p = bplpt[nr] + bpl_off[nr]; + bplpt[nr] += 2 << fm; + bplptx[nr] += 2 << fm; + if (nr == 0) + bpl1dat_written = 1; #ifdef DEBUGGER - if (debug_dma) - record_dma (0x110 + nr * 2, chipmem_agnus_wget (p), p, hpos, vpos, DMARECORD_BITPLANE); + if (debug_dma) + record_dma (0x110 + nr * 2, chipmem_agnus_wget (p), p, hpos, vpos, DMARECORD_BITPLANE); #endif - switch (fm) - { - case 0: - fetched[nr] = bplxdat[nr] = last_custom_value1 = chipmem_agnus_wget (p); - break; + switch (fm) + { + case 0: + fetched[nr] = bplxdat[nr] = last_custom_value1 = chipmem_agnus_wget (p); + break; #ifdef AGA - case 1: - fetched_aga0[nr] = chipmem_lget (p); - last_custom_value1 = (uae_u16)fetched_aga0[nr]; - break; - case 2: - fetched_aga1[nr] = chipmem_lget (p); - fetched_aga0[nr] = chipmem_lget (p + 4); - last_custom_value1 = (uae_u16)fetched_aga0[nr]; - break; + case 1: + fetched_aga0[nr] = chipmem_lget (p); + last_custom_value1 = (uae_u16)fetched_aga0[nr]; + break; + case 2: + fetched_aga1[nr] = chipmem_lget (p); + fetched_aga0[nr] = chipmem_lget (p + 4); + last_custom_value1 = (uae_u16)fetched_aga0[nr]; + break; #endif + } + if (plf_state == plf_passed_stop2 && fetch_cycle >= (fetch_cycle & ~fetchunit_mask) + fetch_modulo_cycle) { + int mod; + if (fmode & 0x4000) { + if (((diwstrt >> 8) ^ vpos) & 1) + mod = bpl2mod; + else + mod = bpl1mod; + } else if (nr & 1) + mod = bpl2mod; + else + mod = bpl1mod; + bplpt[nr] += mod; + bplptx[nr] += mod; + } + } else { + // use whatever left in BPLxDAT if no DMA + // normally useless but "7-planes" feature won't work without this + fetched[nr] = bplxdat[nr]; } - if (plf_state == plf_passed_stop2 && fetch_cycle >= (fetch_cycle & ~fetchunit_mask) + fetch_modulo_cycle) { - int mod; - if (fmode & 0x4000) { - if (((diwstrt >> 8) ^ vpos) & 1) - mod = bpl2mod; - else - mod = bpl1mod; - } else if (nr & 1) - mod = bpl2mod; - else - mod = bpl1mod; - bplpt[nr] += mod; - bplptx[nr] += mod; - } - } else { - // use whatever left in BPLxDAT if no DMA - // normally useless but "7-planes" feature won't work without this - fetched[nr] = bplxdat[nr]; - } } static void clear_fetchbuffer (uae_u32 *ptr, int nwords) { - int i; + int i; - if (! thisline_changed) - for (i = 0; i < nwords; i++) - if (ptr[i]) { - thisline_changed = 1; - break; - } + if (! thisline_changed) + for (i = 0; i < nwords; i++) + if (ptr[i]) { + thisline_changed = 1; + break; + } - memset (ptr, 0, nwords * 4); + memset (ptr, 0, nwords * 4); } static void update_toscr_planes (void) { - if (toscr_nr_planes2 > thisline_decision.nr_planes) { - int j; - for (j = thisline_decision.nr_planes; j < toscr_nr_planes2; j++) - clear_fetchbuffer ((uae_u32 *)(line_data[next_lineno] + 2 * MAX_WORDS_PER_LINE * j), out_offs); - thisline_decision.nr_planes = toscr_nr_planes2; - } + if (toscr_nr_planes2 > thisline_decision.nr_planes) { + int j; + for (j = thisline_decision.nr_planes; j < toscr_nr_planes2; j++) + clear_fetchbuffer ((uae_u32 *)(line_data[next_lineno] + 2 * MAX_WORDS_PER_LINE * j), out_offs); + thisline_decision.nr_planes = toscr_nr_planes2; + } } STATIC_INLINE void toscr_3_ecs (int nbits) { - int delay1 = toscr_delay1; - int delay2 = toscr_delay2; - int i; - uae_u32 mask = 0xFFFF >> (16 - nbits); + int delay1 = toscr_delay1; + int delay2 = toscr_delay2; + int i; + uae_u32 mask = 0xFFFF >> (16 - nbits); - for (i = 0; i < toscr_nr_planes2; i += 2) { - outword[i] <<= nbits; - outword[i] |= (todisplay[i][0] >> (16 - nbits + delay1)) & mask; - todisplay[i][0] <<= nbits; - } - for (i = 1; i < toscr_nr_planes2; i += 2) { - outword[i] <<= nbits; - outword[i] |= (todisplay[i][0] >> (16 - nbits + delay2)) & mask; - todisplay[i][0] <<= nbits; - } + for (i = 0; i < toscr_nr_planes2; i += 2) { + outword[i] <<= nbits; + outword[i] |= (todisplay[i][0] >> (16 - nbits + delay1)) & mask; + todisplay[i][0] <<= nbits; + } + for (i = 1; i < toscr_nr_planes2; i += 2) { + outword[i] <<= nbits; + outword[i] |= (todisplay[i][0] >> (16 - nbits + delay2)) & mask; + todisplay[i][0] <<= nbits; + } } STATIC_INLINE void shift32plus (uae_u32 *p, int n) { - uae_u32 t = p[1]; - t <<= n; - t |= p[0] >> (32 - n); - p[1] = t; + uae_u32 t = p[1]; + t <<= n; + t |= p[0] >> (32 - n); + p[1] = t; } #ifdef AGA STATIC_INLINE void aga_shift (uae_u32 *p, int n, int fm) { - if (fm == 2) { - shift32plus (p + 2, n); - shift32plus (p + 1, n); - } - shift32plus (p + 0, n); - p[0] <<= n; + if (fm == 2) { + shift32plus (p + 2, n); + shift32plus (p + 1, n); + } + shift32plus (p + 0, n); + p[0] <<= n; } STATIC_INLINE void toscr_3_aga (int nbits, int fm) { - int delay1 = toscr_delay1; - int delay2 = toscr_delay2; - int i; - uae_u32 mask = 0xFFFF >> (16 - nbits); + int delay1 = toscr_delay1; + int delay2 = toscr_delay2; + int i; + uae_u32 mask = 0xFFFF >> (16 - nbits); - { - int offs = (16 << fm) - nbits + delay1; - int off1 = offs >> 5; - if (off1 == 3) - off1 = 2; - offs -= off1 * 32; - for (i = 0; i < toscr_nr_planes2; i += 2) { - uae_u32 t0 = todisplay[i][off1]; - uae_u32 t1 = todisplay[i][off1 + 1]; - uae_u64 t = (((uae_u64)t1) << 32) | t0; - outword[i] <<= nbits; - outword[i] |= (t >> offs) & mask; - aga_shift (todisplay[i], nbits, fm); - } - } - { - int offs = (16 << fm) - nbits + delay2; - int off1 = offs >> 5; - if (off1 == 3) - off1 = 2; - offs -= off1 * 32; - for (i = 1; i < toscr_nr_planes2; i += 2) { - uae_u32 t0 = todisplay[i][off1]; - uae_u32 t1 = todisplay[i][off1 + 1]; - uae_u64 t = (((uae_u64)t1) << 32) | t0; - outword[i] <<= nbits; - outword[i] |= (t >> offs) & mask; - aga_shift (todisplay[i], nbits, fm); + { + int offs = (16 << fm) - nbits + delay1; + int off1 = offs >> 5; + if (off1 == 3) + off1 = 2; + offs -= off1 * 32; + for (i = 0; i < toscr_nr_planes2; i += 2) { + uae_u32 t0 = todisplay[i][off1]; + uae_u32 t1 = todisplay[i][off1 + 1]; + uae_u64 t = (((uae_u64)t1) << 32) | t0; + outword[i] <<= nbits; + outword[i] |= (t >> offs) & mask; + aga_shift (todisplay[i], nbits, fm); + } + } + { + int offs = (16 << fm) - nbits + delay2; + int off1 = offs >> 5; + if (off1 == 3) + off1 = 2; + offs -= off1 * 32; + for (i = 1; i < toscr_nr_planes2; i += 2) { + uae_u32 t0 = todisplay[i][off1]; + uae_u32 t1 = todisplay[i][off1 + 1]; + uae_u64 t = (((uae_u64)t1) << 32) | t0; + outword[i] <<= nbits; + outword[i] |= (t >> offs) & mask; + aga_shift (todisplay[i], nbits, fm); + } } - } } #endif @@ -1179,35 +1179,35 @@ static void toscr_2_2 (int nbits) { toscr_3_aga (nbits, 2); } STATIC_INLINE void toscr_1 (int nbits, int fm) { - switch (fm) { - case 0: - toscr_2_0 (nbits); - break; + switch (fm) { + case 0: + toscr_2_0 (nbits); + break; #ifdef AGA - case 1: - toscr_2_1 (nbits); - break; - case 2: - toscr_2_2 (nbits); - break; -#endif - } - out_nbits += nbits; - if (out_nbits == 32) { - int i; - uae_u8 *dataptr = line_data[next_lineno] + out_offs * 4; - for (i = 0; i < thisline_decision.nr_planes; i++) { - uae_u32 *dataptr32 = (uae_u32 *)dataptr; - if (*dataptr32 != outword[i]) { - thisline_changed = 1; - *dataptr32 = outword[i]; - } - outword[i] = 0; - dataptr += MAX_WORDS_PER_LINE * 2; + case 1: + toscr_2_1 (nbits); + break; + case 2: + toscr_2_2 (nbits); + break; +#endif + } + out_nbits += nbits; + if (out_nbits == 32) { + int i; + uae_u8 *dataptr = line_data[next_lineno] + out_offs * 4; + for (i = 0; i < thisline_decision.nr_planes; i++) { + uae_u32 *dataptr32 = (uae_u32 *)dataptr; + if (*dataptr32 != outword[i]) { + thisline_changed = 1; + *dataptr32 = outword[i]; + } + outword[i] = 0; + dataptr += MAX_WORDS_PER_LINE * 2; + } + out_offs++; + out_nbits = 0; } - out_offs++; - out_nbits = 0; - } } static void toscr_fm0 (int); @@ -1216,30 +1216,30 @@ static void toscr_fm2 (int); STATIC_INLINE void toscr (int nbits, int fm) { - switch (fm) { - case 0: toscr_fm0 (nbits); break; + switch (fm) { + case 0: toscr_fm0 (nbits); break; #ifdef AGA - case 1: toscr_fm1 (nbits); break; - case 2: toscr_fm2 (nbits); break; + case 1: toscr_fm1 (nbits); break; + case 2: toscr_fm2 (nbits); break; #endif - } + } } STATIC_INLINE void toscr_0 (int nbits, int fm) { - int t; + int t; - if (nbits > 16) { - toscr (16, fm); - nbits -= 16; - } + if (nbits > 16) { + toscr (16, fm); + nbits -= 16; + } - t = 32 - out_nbits; - if (t < nbits) { - toscr_1 (t, fm); - nbits -= t; - } - toscr_1 (nbits, fm); + t = 32 - out_nbits; + if (t < nbits) { + toscr_1 (t, fm); + nbits -= t; + } + toscr_1 (nbits, fm); } static void toscr_fm0 (int nbits) { toscr_0 (nbits, 0); } @@ -1248,76 +1248,76 @@ static void toscr_fm2 (int nbits) { toscr_0 (nbits, 2); } static int flush_plane_data (int fm) { - int i = 0; - int fetchwidth = 16 << fm; + int i = 0; + int fetchwidth = 16 << fm; - if (out_nbits <= 16) { - i += 16; - toscr_1 (16, fm); - } - if (out_nbits != 0) { - i += 32 - out_nbits; - toscr_1 (32 - out_nbits, fm); - } - i += 32; - - toscr_1 (16, fm); - toscr_1 (16, fm); - - if (fm == 2) { - /* flush AGA full 64-bit shift register */ + if (out_nbits <= 16) { + i += 16; + toscr_1 (16, fm); + } + if (out_nbits != 0) { + i += 32 - out_nbits; + toscr_1 (32 - out_nbits, fm); + } i += 32; + toscr_1 (16, fm); toscr_1 (16, fm); - } - return i >> (1 + toscr_res); + if (fm == 2) { + /* flush AGA full 64-bit shift register */ + i += 32; + toscr_1 (16, fm); + toscr_1 (16, fm); + } + + return i >> (1 + toscr_res); } STATIC_INLINE void flush_display (int fm) { - if (toscr_nbits > 0 && thisline_decision.plfleft != -1) - toscr (toscr_nbits, fm); - toscr_nbits = 0; + if (toscr_nbits > 0 && thisline_decision.plfleft != -1) + toscr (toscr_nbits, fm); + toscr_nbits = 0; } STATIC_INLINE void fetch_start (int hpos) { - fetch_state = fetch_started; + fetch_state = fetch_started; } /* Called when all planes have been fetched, i.e. when a new block - of data is available to be displayed. The data in fetched[] is - moved into todisplay[]. */ +of data is available to be displayed. The data in fetched[] is +moved into todisplay[]. */ STATIC_INLINE void beginning_of_plane_block (int hpos, int fm) { - int i; - int oleft = thisline_decision.plfleft; + int i; + int oleft = thisline_decision.plfleft; - flush_display (fm); + flush_display (fm); - if (fm == 0) - for (i = 0; i < MAX_PLANES; i++) { - todisplay[i][0] |= fetched[i]; - } + if (fm == 0) + for (i = 0; i < MAX_PLANES; i++) { + todisplay[i][0] |= fetched[i]; + } #ifdef AGA - else - for (i = 0; i < MAX_PLANES; i++) { - if (fm == 2) - todisplay[i][1] = fetched_aga1[i]; - todisplay[i][0] = fetched_aga0[i]; - } + else + for (i = 0; i < MAX_PLANES; i++) { + if (fm == 2) + todisplay[i][1] = fetched_aga1[i]; + todisplay[i][0] = fetched_aga0[i]; + } #endif - update_denise (hpos); - maybe_first_bpl1dat (hpos); + update_denise (hpos); + maybe_first_bpl1dat (hpos); - // writing to BPLCON1 1 cycle after BPL1DAT access will - // not (except first BPL1DAT write) affect the display - // until next display block - if (bplcon1_hpos != hpos || oleft < 0) - compute_toscr_delay (hpos); + // writing to BPLCON1 1 cycle after BPL1DAT access will + // not (except first BPL1DAT write) affect the display + // until next display block + if (bplcon1_hpos != hpos || oleft < 0) + compute_toscr_delay (hpos); } #ifdef SPEEDUP @@ -1325,140 +1325,140 @@ STATIC_INLINE void beginning_of_plane_block (int hpos, int fm) /* The usual inlining tricks - don't touch unless you know what you are doing. */ STATIC_INLINE void long_fetch_ecs (int plane, int nwords, int weird_number_of_bits, int dma) { - uae_u16 *real_pt = (uae_u16 *)pfield_xlateptr (bplpt[plane] + bpl_off[plane], nwords * 2); - int delay = (plane & 1) ? toscr_delay2 : toscr_delay1; - int tmp_nbits = out_nbits; - uae_u32 shiftbuffer = todisplay[plane][0]; - uae_u32 outval = outword[plane]; - uae_u32 fetchval = fetched[plane]; - uae_u32 *dataptr = (uae_u32 *)(line_data[next_lineno] + 2 * plane * MAX_WORDS_PER_LINE + 4 * out_offs); + uae_u16 *real_pt = (uae_u16 *)pfield_xlateptr (bplpt[plane] + bpl_off[plane], nwords * 2); + int delay = (plane & 1) ? toscr_delay2 : toscr_delay1; + int tmp_nbits = out_nbits; + uae_u32 shiftbuffer = todisplay[plane][0]; + uae_u32 outval = outword[plane]; + uae_u32 fetchval = fetched[plane]; + uae_u32 *dataptr = (uae_u32 *)(line_data[next_lineno] + 2 * plane * MAX_WORDS_PER_LINE + 4 * out_offs); - if (dma) { - bplpt[plane] += nwords * 2; - bplptx[plane] += nwords * 2; - } + if (dma) { + bplpt[plane] += nwords * 2; + bplptx[plane] += nwords * 2; + } - if (real_pt == 0) - /* @@@ Don't do this, fall back on chipmem_wget instead. */ - return; + if (real_pt == 0) + /* @@@ Don't do this, fall back on chipmem_wget instead. */ + return; - while (nwords > 0) { - int bits_left = 32 - tmp_nbits; - uae_u32 t; + while (nwords > 0) { + int bits_left = 32 - tmp_nbits; + uae_u32 t; - shiftbuffer |= fetchval; + shiftbuffer |= fetchval; - t = (shiftbuffer >> delay) & 0xFFFF; + t = (shiftbuffer >> delay) & 0xFFFF; - if (weird_number_of_bits && bits_left < 16) { - outval <<= bits_left; - outval |= t >> (16 - bits_left); - thisline_changed |= *dataptr ^ outval; - *dataptr++ = outval; + if (weird_number_of_bits && bits_left < 16) { + outval <<= bits_left; + outval |= t >> (16 - bits_left); + thisline_changed |= *dataptr ^ outval; + *dataptr++ = outval; - outval = t; - tmp_nbits = 16 - bits_left; - shiftbuffer <<= 16; - } else { - outval = (outval << 16) | t; - shiftbuffer <<= 16; - tmp_nbits += 16; - if (tmp_nbits == 32) { - thisline_changed |= *dataptr ^ outval; - *dataptr++ = outval; - tmp_nbits = 0; - } - } - nwords--; - if (dma) { - fetchval = do_get_mem_word (real_pt); - real_pt++; + outval = t; + tmp_nbits = 16 - bits_left; + shiftbuffer <<= 16; + } else { + outval = (outval << 16) | t; + shiftbuffer <<= 16; + tmp_nbits += 16; + if (tmp_nbits == 32) { + thisline_changed |= *dataptr ^ outval; + *dataptr++ = outval; + tmp_nbits = 0; + } + } + nwords--; + if (dma) { + fetchval = do_get_mem_word (real_pt); + real_pt++; + } } - } - fetched[plane] = fetchval; - todisplay[plane][0] = shiftbuffer; - outword[plane] = outval; + fetched[plane] = fetchval; + todisplay[plane][0] = shiftbuffer; + outword[plane] = outval; } #ifdef AGA STATIC_INLINE void long_fetch_aga (int plane, int nwords, int weird_number_of_bits, int fm, int dma) { - uae_u32 *real_pt = (uae_u32 *)pfield_xlateptr (bplpt[plane] + bpl_off[plane], nwords * 2); - int delay = (plane & 1) ? toscr_delay2 : toscr_delay1; - int tmp_nbits = out_nbits; - uae_u32 *shiftbuffer = todisplay[plane]; - uae_u32 outval = outword[plane]; - uae_u32 fetchval0 = fetched_aga0[plane]; - uae_u32 fetchval1 = fetched_aga1[plane]; - uae_u32 *dataptr = (uae_u32 *)(line_data[next_lineno] + 2 * plane * MAX_WORDS_PER_LINE + 4 * out_offs); - int offs = (16 << fm) - 16 + delay; - int off1 = offs >> 5; - if (off1 == 3) - off1 = 2; - offs -= off1 * 32; - - if (dma) { - bplpt[plane] += nwords * 2; - bplptx[plane] += nwords * 2; - } - - if (real_pt == 0) - /* @@@ Don't do this, fall back on chipmem_wget instead. */ - return; - - while (nwords > 0) { - int i; + uae_u32 *real_pt = (uae_u32 *)pfield_xlateptr (bplpt[plane] + bpl_off[plane], nwords * 2); + int delay = (plane & 1) ? toscr_delay2 : toscr_delay1; + int tmp_nbits = out_nbits; + uae_u32 *shiftbuffer = todisplay[plane]; + uae_u32 outval = outword[plane]; + uae_u32 fetchval0 = fetched_aga0[plane]; + uae_u32 fetchval1 = fetched_aga1[plane]; + uae_u32 *dataptr = (uae_u32 *)(line_data[next_lineno] + 2 * plane * MAX_WORDS_PER_LINE + 4 * out_offs); + int offs = (16 << fm) - 16 + delay; + int off1 = offs >> 5; + if (off1 == 3) + off1 = 2; + offs -= off1 * 32; - shiftbuffer[0] = fetchval0; - if (fm == 2) - shiftbuffer[1] = fetchval1; - - for (i = 0; i < (1 << fm); i++) { - int bits_left = 32 - tmp_nbits; - - uae_u32 t0 = shiftbuffer[off1]; - uae_u32 t1 = shiftbuffer[off1 + 1]; - uae_u64 t = (((uae_u64)t1) << 32) | t0; - - t0 = (uae_u32)((t >> offs) & 0xFFFF); - - if (weird_number_of_bits && bits_left < 16) { - outval <<= bits_left; - outval |= t0 >> (16 - bits_left); - - thisline_changed |= *dataptr ^ outval; - *dataptr++ = outval; - - outval = t0; - tmp_nbits = 16 - bits_left; - aga_shift (shiftbuffer, 16, fm); - } else { - outval = (outval << 16) | t0; - aga_shift (shiftbuffer, 16, fm); - tmp_nbits += 16; - if (tmp_nbits == 32) { - thisline_changed |= *dataptr ^ outval; - *dataptr++ = outval; - tmp_nbits = 0; - } - } + if (dma) { + bplpt[plane] += nwords * 2; + bplptx[plane] += nwords * 2; } - nwords -= 1 << fm; + if (real_pt == 0) + /* @@@ Don't do this, fall back on chipmem_wget instead. */ + return; + + while (nwords > 0) { + int i; - if (dma) { - if (fm == 1) - fetchval0 = do_get_mem_long (real_pt); - else { - fetchval1 = do_get_mem_long (real_pt); - fetchval0 = do_get_mem_long (real_pt + 1); - } - real_pt += fm; + shiftbuffer[0] = fetchval0; + if (fm == 2) + shiftbuffer[1] = fetchval1; + + for (i = 0; i < (1 << fm); i++) { + int bits_left = 32 - tmp_nbits; + + uae_u32 t0 = shiftbuffer[off1]; + uae_u32 t1 = shiftbuffer[off1 + 1]; + uae_u64 t = (((uae_u64)t1) << 32) | t0; + + t0 = (uae_u32)((t >> offs) & 0xFFFF); + + if (weird_number_of_bits && bits_left < 16) { + outval <<= bits_left; + outval |= t0 >> (16 - bits_left); + + thisline_changed |= *dataptr ^ outval; + *dataptr++ = outval; + + outval = t0; + tmp_nbits = 16 - bits_left; + aga_shift (shiftbuffer, 16, fm); + } else { + outval = (outval << 16) | t0; + aga_shift (shiftbuffer, 16, fm); + tmp_nbits += 16; + if (tmp_nbits == 32) { + thisline_changed |= *dataptr ^ outval; + *dataptr++ = outval; + tmp_nbits = 0; + } + } + } + + nwords -= 1 << fm; + + if (dma) { + if (fm == 1) + fetchval0 = do_get_mem_long (real_pt); + else { + fetchval1 = do_get_mem_long (real_pt); + fetchval0 = do_get_mem_long (real_pt + 1); + } + real_pt += fm; + } } - } - fetched_aga0[plane] = fetchval0; - fetched_aga1[plane] = fetchval1; - outword[plane] = outval; + fetched_aga0[plane] = fetchval0; + fetched_aga1[plane] = fetchval1; + outword[plane] = outval; } #endif @@ -1473,47 +1473,47 @@ static void long_fetch_aga_2_1 (int hpos, int nwords, int dma) { long_fetch_aga static void do_long_fetch (int hpos, int nwords, int dma, int fm) { - int i; + int i; - flush_display (fm); - switch (fm) { - case 0: - if (out_nbits & 15) { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_ecs_1 (i, nwords, dma); - } else { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_ecs_0 (i, nwords, dma); - } - break; + flush_display (fm); + switch (fm) { + case 0: + if (out_nbits & 15) { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_ecs_1 (i, nwords, dma); + } else { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_ecs_0 (i, nwords, dma); + } + break; #ifdef AGA - case 1: - if (out_nbits & 15) { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_aga_1_1 (i, nwords, dma); - } else { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_aga_1_0 (i, nwords, dma); - } - break; - case 2: - if (out_nbits & 15) { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_aga_2_1 (i, nwords, dma); - } else { - for (i = 0; i < toscr_nr_planes; i++) - long_fetch_aga_2_0 (i, nwords, dma); - } - break; + case 1: + if (out_nbits & 15) { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_aga_1_1 (i, nwords, dma); + } else { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_aga_1_0 (i, nwords, dma); + } + break; + case 2: + if (out_nbits & 15) { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_aga_2_1 (i, nwords, dma); + } else { + for (i = 0; i < toscr_nr_planes; i++) + long_fetch_aga_2_0 (i, nwords, dma); + } + break; #endif - } + } - out_nbits += nwords * 16; - out_offs += out_nbits >> 5; - out_nbits &= 31; + out_nbits += nwords * 16; + out_offs += out_nbits >> 5; + out_nbits &= 31; - if (dma && toscr_nr_planes > 0) - fetch_state = fetch_was_plane0; + if (dma && toscr_nr_planes > 0) + fetch_state = fetch_was_plane0; } #endif @@ -1521,89 +1521,89 @@ static void do_long_fetch (int hpos, int nwords, int dma, int fm) /* make sure fetch that goes beyond maxhpos is finished */ static void finish_final_fetch (int pos, int fm) { - if (thisline_decision.plfleft == -1) - return; - if (plf_state == plf_end) - return; - plf_state = plf_end; - ddfstate = DIW_waiting_start; - pos += flush_plane_data (fm); - thisline_decision.plfright = pos; - thisline_decision.plflinelen = out_offs; - finish_playfield_line (); + if (thisline_decision.plfleft == -1) + return; + if (plf_state == plf_end) + return; + plf_state = plf_end; + ddfstate = DIW_waiting_start; + pos += flush_plane_data (fm); + thisline_decision.plfright = pos; + thisline_decision.plflinelen = out_offs; + finish_playfield_line (); } STATIC_INLINE int one_fetch_cycle_0 (int pos, int ddfstop_to_test, int dma, int fm) { - if (plf_state < plf_passed_stop && pos == ddfstop_to_test) - plf_state = plf_passed_stop; - - if ((fetch_cycle & fetchunit_mask) == 0) { - if (plf_state == plf_passed_stop2) { - finish_final_fetch (pos, fm); - return 1; - } - if (plf_state >= plf_passed_stop) - plf_state++; - } - - maybe_check (pos); - - if (dma) { - /* fetchstart_mask can be larger than fm_maxplane if FMODE > 0. This means - that the remaining cycles are idle; we'll fall through the whole switch - without doing anything. */ - int cycle_start = fetch_cycle & fetchstart_mask; - switch (fm_maxplane) { - case 8: - switch (cycle_start) { - case 0: fetch (7, fm, pos); break; - case 1: fetch (3, fm, pos); break; - case 2: fetch (5, fm, pos); break; - case 3: fetch (1, fm, pos); break; - case 4: fetch (6, fm, pos); break; - case 5: fetch (2, fm, pos); break; - case 6: fetch (4, fm, pos); break; - case 7: fetch (0, fm, pos); break; - } - break; - case 4: - switch (cycle_start) { - case 0: fetch (3, fm, pos); break; - case 1: fetch (1, fm, pos); break; - case 2: fetch (2, fm, pos); break; - case 3: fetch (0, fm, pos); break; - } - break; - case 2: - switch (cycle_start) { - case 0: fetch (1, fm, pos); break; - case 1: fetch (0, fm, pos); break; - } - break; - } - } - - if (bpl1dat_written) { - // do this here because if program plays with BPLCON0 during scanline - // it is possible that one DMA BPL1DAT write is completely missed - // and we must not draw anything at all in next dma block if this happens - // (Disposable Hero titlescreen) - fetch_state = fetch_was_plane0; - bpl1dat_written = 0; - } + if (plf_state < plf_passed_stop && pos == ddfstop_to_test) + plf_state = plf_passed_stop; - fetch_cycle++; - toscr_nbits += 2 << toscr_res; + if ((fetch_cycle & fetchunit_mask) == 0) { + if (plf_state == plf_passed_stop2) { + finish_final_fetch (pos, fm); + return 1; + } + if (plf_state >= plf_passed_stop) + plf_state++; + } - if (toscr_nbits > 16) { - uae_abort (L"toscr_nbits > 16 (%d)", toscr_nbits); - toscr_nbits = 0; - } - if (toscr_nbits == 16) - flush_display (fm); + maybe_check (pos); + + if (dma) { + /* fetchstart_mask can be larger than fm_maxplane if FMODE > 0. This means + that the remaining cycles are idle; we'll fall through the whole switch + without doing anything. */ + int cycle_start = fetch_cycle & fetchstart_mask; + switch (fm_maxplane) { + case 8: + switch (cycle_start) { + case 0: fetch (7, fm, pos); break; + case 1: fetch (3, fm, pos); break; + case 2: fetch (5, fm, pos); break; + case 3: fetch (1, fm, pos); break; + case 4: fetch (6, fm, pos); break; + case 5: fetch (2, fm, pos); break; + case 6: fetch (4, fm, pos); break; + case 7: fetch (0, fm, pos); break; + } + break; + case 4: + switch (cycle_start) { + case 0: fetch (3, fm, pos); break; + case 1: fetch (1, fm, pos); break; + case 2: fetch (2, fm, pos); break; + case 3: fetch (0, fm, pos); break; + } + break; + case 2: + switch (cycle_start) { + case 0: fetch (1, fm, pos); break; + case 1: fetch (0, fm, pos); break; + } + break; + } + } + + if (bpl1dat_written) { + // do this here because if program plays with BPLCON0 during scanline + // it is possible that one DMA BPL1DAT write is completely missed + // and we must not draw anything at all in next dma block if this happens + // (Disposable Hero titlescreen) + fetch_state = fetch_was_plane0; + bpl1dat_written = 0; + } + + fetch_cycle++; + toscr_nbits += 2 << toscr_res; + + if (toscr_nbits > 16) { + uae_abort (L"toscr_nbits > 16 (%d)", toscr_nbits); + toscr_nbits = 0; + } + if (toscr_nbits == 16) + flush_display (fm); - return 0; + return 0; } static int one_fetch_cycle_fm0 (int pos, int ddfstop_to_test, int dma) { return one_fetch_cycle_0 (pos, ddfstop_to_test, dma, 0); } @@ -1612,126 +1612,126 @@ static int one_fetch_cycle_fm2 (int pos, int ddfstop_to_test, int dma) { return STATIC_INLINE int one_fetch_cycle (int pos, int ddfstop_to_test, int dma, int fm) { - switch (fm) { - case 0: return one_fetch_cycle_fm0 (pos, ddfstop_to_test, dma); + switch (fm) { + case 0: return one_fetch_cycle_fm0 (pos, ddfstop_to_test, dma); #ifdef AGA - case 1: return one_fetch_cycle_fm1 (pos, ddfstop_to_test, dma); - case 2: return one_fetch_cycle_fm2 (pos, ddfstop_to_test, dma); + case 1: return one_fetch_cycle_fm1 (pos, ddfstop_to_test, dma); + case 2: return one_fetch_cycle_fm2 (pos, ddfstop_to_test, dma); #endif - default: uae_abort (L"fm corrupt"); return 0; - } + default: uae_abort (L"fm corrupt"); return 0; + } } STATIC_INLINE void update_fetch (int until, int fm) { - int pos; - int dma = dmaen (DMA_BITPLANE); + int pos; + int dma = dmaen (DMA_BITPLANE); - int ddfstop_to_test; + int ddfstop_to_test; - if (nodraw() || plf_state == plf_end) - return; - - /* We need an explicit test against HARD_DDF_STOP here to guard against - programs that move the DDFSTOP before our current position before we - reach it. */ - ddfstop_to_test = HARD_DDF_STOP; - if (ddfstop >= last_fetch_hpos && plfstop < ddfstop_to_test) - ddfstop_to_test = plfstop; + if (nodraw() || plf_state == plf_end) + return; - update_toscr_planes (); + /* We need an explicit test against HARD_DDF_STOP here to guard against + programs that move the DDFSTOP before our current position before we + reach it. */ + ddfstop_to_test = HARD_DDF_STOP; + if (ddfstop >= last_fetch_hpos && plfstop < ddfstop_to_test) + ddfstop_to_test = plfstop; - pos = last_fetch_hpos; - cycle_diagram_shift = last_fetch_hpos - fetch_cycle; + update_toscr_planes (); - /* First, a loop that prepares us for the speedup code. We want to enter - the SPEEDUP case with fetch_state == fetch_was_plane0, and then unroll - whole blocks, so that we end on the same fetch_state again. */ - for (; ; pos++) { - if (pos == until) { - if (until >= maxhpos) { - finish_final_fetch (pos, fm); - return; - } - flush_display (fm); - return; - } + pos = last_fetch_hpos; + cycle_diagram_shift = last_fetch_hpos - fetch_cycle; + + /* First, a loop that prepares us for the speedup code. We want to enter + the SPEEDUP case with fetch_state == fetch_was_plane0, and then unroll + whole blocks, so that we end on the same fetch_state again. */ + for (; ; pos++) { + if (pos == until) { + if (until >= maxhpos) { + finish_final_fetch (pos, fm); + return; + } + flush_display (fm); + return; + } - if (fetch_state == fetch_was_plane0) - break; + if (fetch_state == fetch_was_plane0) + break; - fetch_start (pos); - if (one_fetch_cycle (pos, ddfstop_to_test, dma, fm)) - return; - } + fetch_start (pos); + if (one_fetch_cycle (pos, ddfstop_to_test, dma, fm)) + return; + } #ifdef SPEEDUP - /* Unrolled version of the for loop below. */ - if (plf_state < plf_passed_stop && ddf_change != vpos && ddf_change + 1 != vpos - && dma - && (fetch_cycle & fetchstart_mask) == (fm_maxplane & fetchstart_mask) - && !badmode && !debug_dma - # if 0 - /* @@@ We handle this case, but the code would be simpler if we - * disallowed it - it may even be possible to guarantee that - * this condition never is false. Later. */ - && (out_nbits & 15) == 0 + /* Unrolled version of the for loop below. */ + if (plf_state < plf_passed_stop && ddf_change != vpos && ddf_change + 1 != vpos + && dma + && (fetch_cycle & fetchstart_mask) == (fm_maxplane & fetchstart_mask) + && !badmode && !debug_dma +# if 0 + /* @@@ We handle this case, but the code would be simpler if we + * disallowed it - it may even be possible to guarantee that + * this condition never is false. Later. */ + && (out_nbits & 15) == 0 # endif - && toscr_nr_planes == thisline_decision.nr_planes) - { - int offs = (pos - fetch_cycle) & fetchunit_mask; - int ddf2 = ((ddfstop_to_test - offs + fetchunit - 1) & ~fetchunit_mask) + offs; - int ddf3 = ddf2 + fetchunit; - int stop = until < ddf2 ? until : until < ddf3 ? ddf2 : ddf3; - int count; - - count = stop - pos; - - if (count >= fetchstart) { - count &= ~fetchstart_mask; + && toscr_nr_planes == thisline_decision.nr_planes) + { + int offs = (pos - fetch_cycle) & fetchunit_mask; + int ddf2 = ((ddfstop_to_test - offs + fetchunit - 1) & ~fetchunit_mask) + offs; + int ddf3 = ddf2 + fetchunit; + int stop = until < ddf2 ? until : until < ddf3 ? ddf2 : ddf3; + int count; - if (thisline_decision.plfleft == -1) { - compute_delay_offset (); - compute_toscr_delay_1 (); - } + count = stop - pos; - do_long_fetch (pos, count >> (3 - toscr_res), dma, fm); + if (count >= fetchstart) { + count &= ~fetchstart_mask; - /* This must come _after_ do_long_fetch so as not to confuse flush_display - into thinking the first fetch has produced any output worth emitting to - the screen. But the calculation of delay_offset must happen _before_. */ - maybe_first_bpl1dat (pos); + if (thisline_decision.plfleft == -1) { + compute_delay_offset (); + compute_toscr_delay_1 (); + } - if (pos <= ddfstop_to_test && pos + count > ddfstop_to_test) - plf_state = plf_passed_stop; - if (pos <= ddfstop_to_test && pos + count > ddf2) - plf_state = plf_passed_stop2; - if (pos <= ddf2 && pos + count >= ddf2 + fm_maxplane) - add_modulos (); - pos += count; - fetch_cycle += count; - } - } else { + do_long_fetch (pos, count >> (3 - toscr_res), dma, fm); + + /* This must come _after_ do_long_fetch so as not to confuse flush_display + into thinking the first fetch has produced any output worth emitting to + the screen. But the calculation of delay_offset must happen _before_. */ + maybe_first_bpl1dat (pos); + + if (pos <= ddfstop_to_test && pos + count > ddfstop_to_test) + plf_state = plf_passed_stop; + if (pos <= ddfstop_to_test && pos + count > ddf2) + plf_state = plf_passed_stop2; + if (pos <= ddf2 && pos + count >= ddf2 + fm_maxplane) + add_modulos (); + pos += count; + fetch_cycle += count; + } + } else { #endif #ifdef SPEEDUP - } -#endif - for (; pos < until; pos++) { - if (fetch_state == fetch_was_plane0) { - beginning_of_plane_block (pos, fm); - estimate_last_fetch_cycle (pos); } - fetch_start (pos); +#endif + for (; pos < until; pos++) { + if (fetch_state == fetch_was_plane0) { + beginning_of_plane_block (pos, fm); + estimate_last_fetch_cycle (pos); + } + fetch_start (pos); - if (one_fetch_cycle (pos, ddfstop_to_test, dma, fm)) - return; - } - if (until >= maxhpos) { - finish_final_fetch (pos, fm); - return; - } - flush_display (fm); -} + if (one_fetch_cycle (pos, ddfstop_to_test, dma, fm)) + return; + } + if (until >= maxhpos) { + finish_final_fetch (pos, fm); + return; + } + flush_display (fm); +} static void update_fetch_0 (int hpos) { update_fetch (hpos, 0); } static void update_fetch_1 (int hpos) { update_fetch (hpos, 1); } @@ -1739,1086 +1739,1097 @@ static void update_fetch_2 (int hpos) { update_fetch (hpos, 2); } STATIC_INLINE void decide_fetch (int hpos) { - if (hpos > last_fetch_hpos) { - if (fetch_state != fetch_not_started) { - switch (fetchmode) { - case 0: update_fetch_0 (hpos); break; - #ifdef AGA - case 1: update_fetch_1 (hpos); break; - case 2: update_fetch_2 (hpos); break; - #endif - default: uae_abort (L"fetchmode corrupt"); - } + if (hpos > last_fetch_hpos) { + if (fetch_state != fetch_not_started) { + switch (fetchmode) { + case 0: update_fetch_0 (hpos); break; +#ifdef AGA + case 1: update_fetch_1 (hpos); break; + case 2: update_fetch_2 (hpos); break; +#endif + default: uae_abort (L"fetchmode corrupt"); + } + } + maybe_check (hpos); + last_fetch_hpos = hpos; } - maybe_check (hpos); - last_fetch_hpos = hpos; - } } static void start_bpl_dma (int hpos, int hstart) { - if (first_bpl_vpos < 0) - first_bpl_vpos = vpos; + if (first_bpl_vpos < 0) + first_bpl_vpos = vpos; + + if (doflickerfix () && interlace_seen && !scandoubled_line) { + int i; + for (i = 0; i < 8; i++) { + prevbpl[lof][vpos][i] = bplptx[i]; + if (!lof && (bplcon0 & 4)) + bplpt[i] = prevbpl[1 - lof][vpos][i]; + if (!(bplcon0 & 4) || interlace_seen < 0) + prevbpl[1 - lof][vpos][i] = prevbpl[lof][vpos][i] = 0; + } + } - if (doflickerfix () && interlace_seen && !scandoubled_line) { - int i; - for (i = 0; i < 8; i++) { - prevbpl[lof][vpos][i] = bplptx[i]; - if (!lof && (bplcon0 & 4)) - bplpt[i] = prevbpl[1 - lof][vpos][i]; - if (!(bplcon0 & 4) || interlace_seen < 0) - prevbpl[1 - lof][vpos][i] = prevbpl[lof][vpos][i] = 0; - } - } - - fetch_start (hpos); - fetch_cycle = 0; - last_fetch_hpos = hstart; - out_nbits = 0; - out_offs = 0; - toscr_nbits = 0; - thisline_decision.bplres = bplcon0_res; - - ddfstate = DIW_waiting_stop; - compute_toscr_delay (last_fetch_hpos); - - /* If someone already wrote BPL1DAT, clear the area between that point and - the real fetch start. */ - if (!nodraw ()) { - if (thisline_decision.plfleft != -1) { - out_nbits = (plfstrt - thisline_decision.plfleft) << (1 + toscr_res); - out_offs = out_nbits >> 5; - out_nbits &= 31; + fetch_start (hpos); + fetch_cycle = 0; + last_fetch_hpos = hstart; + out_nbits = 0; + out_offs = 0; + toscr_nbits = 0; + thisline_decision.bplres = bplcon0_res; + + ddfstate = DIW_waiting_stop; + compute_toscr_delay (last_fetch_hpos); + + /* If someone already wrote BPL1DAT, clear the area between that point and + the real fetch start. */ + if (!nodraw ()) { + if (thisline_decision.plfleft != -1) { + out_nbits = (plfstrt - thisline_decision.plfleft) << (1 + toscr_res); + out_offs = out_nbits >> 5; + out_nbits &= 31; + } + update_toscr_planes (); } - update_toscr_planes (); - } } /* this may turn on datafetch if program turns dma on during the ddf */ static void maybe_start_bpl_dma (int hpos) { - /* OCS: BPL DMA never restarts if DMA is turned on during DDF - * ECS/AGA: BPL DMA restarts but only if DMA was turned off - outside of DDF or during current line, otherwise display - processing jumps immediately to "DDFSTOP passed"-condition */ - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - return; - if (fetch_state != fetch_not_started) - return; - if (diwstate != DIW_waiting_stop) - return; - if (hpos <= plfstrt) - return; - if (hpos > plfstop - fetchunit) - return; - if (ddfstate != DIW_waiting_start) - plf_state = plf_passed_stop; - start_bpl_dma (hpos, hpos); + /* OCS: BPL DMA never restarts if DMA is turned on during DDF + * ECS/AGA: BPL DMA restarts but only if DMA was turned off + outside of DDF or during current line, otherwise display + processing jumps immediately to "DDFSTOP passed"-condition */ + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + if (fetch_state != fetch_not_started) + return; + if (diwstate != DIW_waiting_stop) + return; + if (hpos <= plfstrt) + return; + if (hpos > plfstop - fetchunit) + return; + if (ddfstate != DIW_waiting_start) + plf_state = plf_passed_stop; + start_bpl_dma (hpos, hpos); } /* This function is responsible for turning on datafetch if necessary. */ STATIC_INLINE void decide_line (int hpos) { - /* Take care of the vertical DIW. */ - if (vpos == plffirstline) { - diwstate = DIW_waiting_stop; - ddf_change = vpos; - } - if (vpos == plflastline) { - diwstate = DIW_waiting_start; - ddf_change = vpos; - } - - if (hpos <= last_decide_line_hpos) - return; - if (fetch_state != fetch_not_started) - return; - - if (diwstate == DIW_waiting_stop) { - int ok = 0; - if (last_decide_line_hpos < plfstrt_start && hpos >= plfstrt_start) { - if (plf_state == plf_idle) - plf_state = plf_start; - } - if (last_decide_line_hpos < plfstrt && hpos >= plfstrt) { - if (plf_state == plf_start) - plf_state = plf_active; - if (plf_state == plf_active) - ok = 1; - /* hack warning.. Writing to DDFSTRT when DMA should start must be ignored - * (correct fix would be emulate this delay for every custom register, but why bother..) */ - if (ddfstrt_old_vpos == vpos) - if (hpos - 2 == ddfstrt_old_hpos) - ok = 0; - } - if (ok && dmaen (DMA_BITPLANE)) { - start_bpl_dma (hpos, plfstrt); - estimate_last_fetch_cycle (plfstrt); - last_decide_line_hpos = hpos; + /* Take care of the vertical DIW. */ + if (vpos == plffirstline) { + diwstate = DIW_waiting_stop; + ddf_change = vpos; + } + if (vpos == plflastline) { + diwstate = DIW_waiting_start; + ddf_change = vpos; + } + + if (hpos <= last_decide_line_hpos) + return; + if (fetch_state != fetch_not_started) + return; + + if (diwstate == DIW_waiting_stop) { + int ok = 0; + if (last_decide_line_hpos < plfstrt_start && hpos >= plfstrt_start) { + if (plf_state == plf_idle) + plf_state = plf_start; + } + if (last_decide_line_hpos < plfstrt && hpos >= plfstrt) { + if (plf_state == plf_start) + plf_state = plf_active; + if (plf_state == plf_active) + ok = 1; + /* hack warning.. Writing to DDFSTRT when DMA should start must be ignored + * (correct fix would be emulate this delay for every custom register, but why bother..) */ + if (ddfstrt_old_vpos == vpos) + if (hpos - 2 == ddfstrt_old_hpos) + ok = 0; + } + if (ok && dmaen (DMA_BITPLANE)) { + start_bpl_dma (hpos, plfstrt); + estimate_last_fetch_cycle (plfstrt); + last_decide_line_hpos = hpos; #ifndef CUSTOM_SIMPLE - do_sprites (plfstrt); + do_sprites (plfstrt); #endif - return; + return; + } } - } #ifndef CUSTOM_SIMPLE - if (last_sprite_decide_line_hpos < SPR0_HPOS + 4 * MAX_SPRITES) - do_sprites (hpos); + if (last_sprite_decide_line_hpos < SPR0_HPOS + 4 * MAX_SPRITES) + do_sprites (hpos); #endif - last_sprite_decide_line_hpos = hpos; + last_sprite_decide_line_hpos = hpos; - last_decide_line_hpos = hpos; + last_decide_line_hpos = hpos; } /* Called when a color is about to be changed (write to a color register), - * but the new color has not been entered into the table yet. */ +* but the new color has not been entered into the table yet. */ static void record_color_change (int hpos, int regno, unsigned long value) { - if (regno < 0x1000 && nodraw ()) - return; - /* Early positions don't appear on-screen. */ - if (vpos < minfirstline) - return; + if (regno < 0x1000 && nodraw ()) + return; + /* Early positions don't appear on-screen. */ + if (vpos < minfirstline) + return; - decide_diw (hpos); - decide_line (hpos); + decide_diw (hpos); + decide_line (hpos); - if (thisline_decision.ctable == -1) - remember_ctable (); + if (thisline_decision.ctable == -1) + remember_ctable (); #ifdef OS_WITHOUT_MEMORY_MANAGEMENT - if (next_color_change >= max_color_change) { - ++delta_color_change; - return; - } -#endif - if (regno < 0x1000 && hpos < HBLANK_OFFSET && !(beamcon0 & 0x80) && prev_lineno >= 0) { - struct draw_info *pdip = curr_drawinfo + prev_lineno; - int idx = pdip->last_color_change; - /* Move color changes in horizontal cycles 0 to HBLANK_OFFSET to end of previous line. - * Cycles 0 to HBLANK_OFFSET are visible in right border on real Amigas. (because of late hsync) - */ - pdip->last_color_change++; - pdip->nr_color_changes++; - curr_color_changes[idx].linepos = (hpos + maxhpos) * 2; - curr_color_changes[idx].regno = regno; - curr_color_changes[idx].value = value; - curr_color_changes[idx + 1].regno = -1; - } - record_color_change2 (hpos, regno, value); + if (next_color_change >= max_color_change) { + ++delta_color_change; + return; + } +#endif + if (regno < 0x1000 && hpos < HBLANK_OFFSET && !(beamcon0 & 0x80) && prev_lineno >= 0) { + struct draw_info *pdip = curr_drawinfo + prev_lineno; + int idx = pdip->last_color_change; + /* Move color changes in horizontal cycles 0 to HBLANK_OFFSET to end of previous line. + * Cycles 0 to HBLANK_OFFSET are visible in right border on real Amigas. (because of late hsync) + */ + pdip->last_color_change++; + pdip->nr_color_changes++; + curr_color_changes[idx].linepos = (hpos + maxhpos) * 2; + curr_color_changes[idx].regno = regno; + curr_color_changes[idx].value = value; + curr_color_changes[idx + 1].regno = -1; + } + record_color_change2 (hpos, regno, value); } static void record_register_change (int hpos, int regno, unsigned long value) { - if (regno == 0x100) { // BPLCON0 - if (value & 0x800) - thisline_decision.ham_seen = 1; - thisline_decision.ehb_seen = !! isehb (value, bplcon2); - } else if (regno == 0x104) { // BPLCON2 - thisline_decision.ehb_seen = !! isehb (value, bplcon2); - } - record_color_change (hpos, regno + 0x1000, value); + if (regno == 0x100) { // BPLCON0 + if (value & 0x800) + thisline_decision.ham_seen = 1; + thisline_decision.ehb_seen = !! isehb (value, bplcon2); + } else if (regno == 0x104) { // BPLCON2 + thisline_decision.ehb_seen = !! isehb (value, bplcon2); + } + record_color_change (hpos, regno + 0x1000, value); } typedef int sprbuf_res_t, cclockres_t, hwres_t, bplres_t; static int expand_sprres (uae_u16 con0, uae_u16 con3) { - int res; + int res; - switch ((con3 >> 6) & 3) - { - default: - res = RES_LORES; - break; + switch ((con3 >> 6) & 3) + { + default: + res = RES_LORES; + break; #ifdef ECS_DENISE - case 0: /* ECS defaults (LORES,HIRES=LORES sprite,SHRES=HIRES sprite) */ - if ((currprefs.chipset_mask & CSMASK_ECS_DENISE) && GET_RES_DENISE (con0) == RES_SUPERHIRES) - res = RES_HIRES; - else - res = RES_LORES; - break; + case 0: /* ECS defaults (LORES,HIRES=LORES sprite,SHRES=HIRES sprite) */ + if ((currprefs.chipset_mask & CSMASK_ECS_DENISE) && GET_RES_DENISE (con0) == RES_SUPERHIRES) + res = RES_HIRES; + else + res = RES_LORES; + break; #endif #ifdef AGA - case 1: - res = RES_LORES; - break; - case 2: - res = RES_HIRES; - break; - case 3: - res = RES_SUPERHIRES; - break; + case 1: + res = RES_LORES; + break; + case 2: + res = RES_HIRES; + break; + case 3: + res = RES_SUPERHIRES; + break; #endif - } - return res; + } + return res; } /* handle very rarely needed playfield collision (CLXDAT bit 0) */ static void do_playfield_collisions (void) { - int bplres = bplcon0_res; - hwres_t ddf_left = thisline_decision.plfleft * 2 << bplres; - hwres_t hw_diwlast = coord_window_to_diw_x (thisline_decision.diwlastword); - hwres_t hw_diwfirst = coord_window_to_diw_x (thisline_decision.diwfirstword); - int i, collided, minpos, maxpos; + int bplres = bplcon0_res; + hwres_t ddf_left = thisline_decision.plfleft * 2 << bplres; + hwres_t hw_diwlast = coord_window_to_diw_x (thisline_decision.diwlastword); + hwres_t hw_diwfirst = coord_window_to_diw_x (thisline_decision.diwfirstword); + int i, collided, minpos, maxpos; #ifdef AGA - int planes = (currprefs.chipset_mask & CSMASK_AGA) ? 8 : 6; + int planes = (currprefs.chipset_mask & CSMASK_AGA) ? 8 : 6; #else - int planes = 6; -#endif - - if (clxcon_bpl_enable == 0) { - clxdat |= 1; - return; - } - if (clxdat & 1) - return; - - collided = 0; - minpos = thisline_decision.plfleft * 2; - if (minpos < hw_diwfirst) - minpos = hw_diwfirst; - maxpos = thisline_decision.plfright * 2; - if (maxpos > hw_diwlast) - maxpos = hw_diwlast; - for (i = minpos; i < maxpos && !collided; i+= 32) { - int offs = ((i << bplres) - ddf_left) >> 3; - int j; - uae_u32 total = 0xffffffff; - for (j = 0; j < planes; j++) { - int ena = (clxcon_bpl_enable >> j) & 1; - int match = (clxcon_bpl_match >> j) & 1; - uae_u32 t = 0xffffffff; - if (ena) { - if (j < thisline_decision.nr_planes) { - t = *(uae_u32 *)(line_data[next_lineno] + offs + 2 * j * MAX_WORDS_PER_LINE); - t ^= (match & 1) - 1; - } else { - t = (match & 1) - 1; - } - } - total &= t; + int planes = 6; +#endif + + if (clxcon_bpl_enable == 0) { + clxdat |= 1; + return; } - if (total) { - collided = 1; -#if 0 - { - int k; - for (k = 0; k < 1; k++) { - uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + offs + 2 * k * MAX_WORDS_PER_LINE); - *ldata ^= 0x5555555555; + if (clxdat & 1) + return; + + collided = 0; + minpos = thisline_decision.plfleft * 2; + if (minpos < hw_diwfirst) + minpos = hw_diwfirst; + maxpos = thisline_decision.plfright * 2; + if (maxpos > hw_diwlast) + maxpos = hw_diwlast; + for (i = minpos; i < maxpos && !collided; i+= 32) { + int offs = ((i << bplres) - ddf_left) >> 3; + int j; + uae_u32 total = 0xffffffff; + for (j = 0; j < planes; j++) { + int ena = (clxcon_bpl_enable >> j) & 1; + int match = (clxcon_bpl_match >> j) & 1; + uae_u32 t = 0xffffffff; + if (ena) { + if (j < thisline_decision.nr_planes) { + t = *(uae_u32 *)(line_data[next_lineno] + offs + 2 * j * MAX_WORDS_PER_LINE); + t ^= (match & 1) - 1; + } else { + t = (match & 1) - 1; + } + } + total &= t; } - } + if (total) { + collided = 1; +#if 0 + { + int k; + for (k = 0; k < 1; k++) { + uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + offs + 2 * k * MAX_WORDS_PER_LINE); + *ldata ^= 0x5555555555; + } + } #endif + } } - } - if (collided) - clxdat |= 1; + if (collided) + clxdat |= 1; } /* Sprite-to-sprite collisions are taken care of in record_sprite. This one does - playfield/sprite collisions. */ +playfield/sprite collisions. */ static void do_sprite_collisions (void) { - int nr_sprites = curr_drawinfo[next_lineno].nr_sprites; - int first = curr_drawinfo[next_lineno].first_sprite_entry; - int i; - unsigned int collision_mask = clxmask[clxcon >> 12]; - int bplres = bplcon0_res; - hwres_t ddf_left = thisline_decision.plfleft * 2 << bplres; - hwres_t hw_diwlast = coord_window_to_diw_x (thisline_decision.diwlastword); - hwres_t hw_diwfirst = coord_window_to_diw_x (thisline_decision.diwfirstword); - - if (clxcon_bpl_enable == 0) { - clxdat |= 0x1FE; - return; - } - - for (i = 0; i < nr_sprites; i++) { - struct sprite_entry *e = curr_sprite_entries + first + i; - sprbuf_res_t j; - sprbuf_res_t minpos = e->pos; - sprbuf_res_t maxpos = e->max; - hwres_t minp1 = minpos >> sprite_buffer_res; - hwres_t maxp1 = maxpos >> sprite_buffer_res; - - if (maxp1 > hw_diwlast) - maxpos = hw_diwlast << sprite_buffer_res; - if (maxp1 > thisline_decision.plfright * 2) - maxpos = thisline_decision.plfright * 2 << sprite_buffer_res; - if (minp1 < hw_diwfirst) - minpos = hw_diwfirst << sprite_buffer_res; - if (minp1 < thisline_decision.plfleft * 2) - minpos = thisline_decision.plfleft * 2 << sprite_buffer_res; - - for (j = minpos; j < maxpos; j++) { - int sprpix = spixels[e->first_pixel + j - e->pos] & collision_mask; - int k, offs, match = 1; - - if (sprpix == 0) - continue; - - offs = ((j << bplres) >> sprite_buffer_res) - ddf_left; - sprpix = sprite_ab_merge[sprpix & 255] | (sprite_ab_merge[sprpix >> 8] << 2); - sprpix <<= 1; - - /* Loop over number of playfields. */ - for (k = 1; k >= 0; k--) { - int l; + int nr_sprites = curr_drawinfo[next_lineno].nr_sprites; + int first = curr_drawinfo[next_lineno].first_sprite_entry; + int i; + unsigned int collision_mask = clxmask[clxcon >> 12]; + int bplres = bplcon0_res; + hwres_t ddf_left = thisline_decision.plfleft * 2 << bplres; + hwres_t hw_diwlast = coord_window_to_diw_x (thisline_decision.diwlastword); + hwres_t hw_diwfirst = coord_window_to_diw_x (thisline_decision.diwfirstword); + + if (clxcon_bpl_enable == 0) { + clxdat |= 0x1FE; + return; + } + + for (i = 0; i < nr_sprites; i++) { + struct sprite_entry *e = curr_sprite_entries + first + i; + sprbuf_res_t j; + sprbuf_res_t minpos = e->pos; + sprbuf_res_t maxpos = e->max; + hwres_t minp1 = minpos >> sprite_buffer_res; + hwres_t maxp1 = maxpos >> sprite_buffer_res; + + if (maxp1 > hw_diwlast) + maxpos = hw_diwlast << sprite_buffer_res; + if (maxp1 > thisline_decision.plfright * 2) + maxpos = thisline_decision.plfright * 2 << sprite_buffer_res; + if (minp1 < hw_diwfirst) + minpos = hw_diwfirst << sprite_buffer_res; + if (minp1 < thisline_decision.plfleft * 2) + minpos = thisline_decision.plfleft * 2 << sprite_buffer_res; + + for (j = minpos; j < maxpos; j++) { + int sprpix = spixels[e->first_pixel + j - e->pos] & collision_mask; + int k, offs, match = 1; + + if (sprpix == 0) + continue; + + offs = ((j << bplres) >> sprite_buffer_res) - ddf_left; + sprpix = sprite_ab_merge[sprpix & 255] | (sprite_ab_merge[sprpix >> 8] << 2); + sprpix <<= 1; + + /* Loop over number of playfields. */ + for (k = 1; k >= 0; k--) { + int l; #ifdef AGA - int planes = (currprefs.chipset_mask & CSMASK_AGA) ? 8 : 6; + int planes = (currprefs.chipset_mask & CSMASK_AGA) ? 8 : 6; #else - int planes = 6; -#endif - if (bplcon0 & 0x400) - match = 1; - for (l = k; match && l < planes; l += 2) { - int t = 0; - if (l < thisline_decision.nr_planes) { - uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + 2 * l * MAX_WORDS_PER_LINE); - uae_u32 word = ldata[offs >> 5]; - t = (word >> (31 - (offs & 31))) & 1; + int planes = 6; +#endif + if (bplcon0 & 0x400) + match = 1; + for (l = k; match && l < planes; l += 2) { + int t = 0; + if (l < thisline_decision.nr_planes) { + uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + 2 * l * MAX_WORDS_PER_LINE); + uae_u32 word = ldata[offs >> 5]; + t = (word >> (31 - (offs & 31))) & 1; #if 0 /* debug: draw collision mask */ - if (1) { - int m; - for (m = 0; m < 5; m++) { - ldata = (uae_u32 *)(line_data[next_lineno] + 2 * m * MAX_WORDS_PER_LINE); - ldata[(offs >> 5) + 1] |= 15 << (31 - (offs & 31)); - } - } -#endif - } - if (clxcon_bpl_enable & (1 << l)) { - if (t != ((clxcon_bpl_match >> l) & 1)) - match = 0; - } - } - if (match) { + if (1) { + int m; + for (m = 0; m < 5; m++) { + ldata = (uae_u32 *)(line_data[next_lineno] + 2 * m * MAX_WORDS_PER_LINE); + ldata[(offs >> 5) + 1] |= 15 << (31 - (offs & 31)); + } + } +#endif + } + if (clxcon_bpl_enable & (1 << l)) { + if (t != ((clxcon_bpl_match >> l) & 1)) + match = 0; + } + } + if (match) { #if 0 /* debug: mark lines where collisions are detected */ - if (0) { - int l; - for (l = 0; l < 5; l++) { - uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + 2 * l * MAX_WORDS_PER_LINE); - ldata[(offs >> 5) + 1] |= 15 << (31 - (offs & 31)); + if (0) { + int l; + for (l = 0; l < 5; l++) { + uae_u32 *ldata = (uae_u32 *)(line_data[next_lineno] + 2 * l * MAX_WORDS_PER_LINE); + ldata[(offs >> 5) + 1] |= 15 << (31 - (offs & 31)); + } + } +#endif + clxdat |= sprpix << (k * 4); + } } - } -#endif - clxdat |= sprpix << (k * 4); } - } } - } #if 0 - { - static int olx; - if (clxdat != olx) - write_log (L"%d: %04X\n", vpos, clxdat); - olx = clxdat; - } + { + static int olx; + if (clxdat != olx) + write_log (L"%d: %04X\n", vpos, clxdat); + olx = clxdat; + } #endif } STATIC_INLINE void record_sprite_1 (int sprxp, uae_u16 *buf, uae_u32 datab, int num, int dbl, - unsigned int mask, int do_collisions, uae_u32 collision_mask) + unsigned int mask, int do_collisions, uae_u32 collision_mask) { - int j = 0; - while (datab) { - unsigned int col = 0; - unsigned coltmp = 0; + int j = 0; + while (datab) { + unsigned int col = 0; + unsigned coltmp = 0; - if ((sprxp >= sprite_minx && sprxp < sprite_maxx) || (bplcon3 & 2)) - col = (datab & 3) << (2 * num); + if ((sprxp >= sprite_minx && sprxp < sprite_maxx) || (bplcon3 & 2)) + col = (datab & 3) << (2 * num); #if 0 - if (sprxp == sprite_minx || sprxp == sprite_maxx - 1) - col ^= (rand () << 16) | rand (); -#endif - if ((j & mask) == 0) { - unsigned int tmp = (*buf) | col; - *buf++ = tmp; - if (do_collisions) - coltmp |= tmp; - sprxp++; - } - if (dbl > 0) { - unsigned int tmp = (*buf) | col; - *buf++ = tmp; - if (do_collisions) - coltmp |= tmp; - sprxp++; - } - if (dbl > 1) { - unsigned int tmp; - tmp = (*buf) | col; - *buf++ = tmp; - if (do_collisions) - coltmp |= tmp; - tmp = (*buf) | col; - *buf++ = tmp; - if (do_collisions) - coltmp |= tmp; - sprxp++; - sprxp++; - } - j++; - datab >>= 2; - if (do_collisions) { - coltmp &= collision_mask; - if (coltmp) { - unsigned int shrunk_tmp = sprite_ab_merge[coltmp & 255] | (sprite_ab_merge[coltmp >> 8] << 2); - clxdat |= sprclx[shrunk_tmp]; - } - } - } + if (sprxp == sprite_minx || sprxp == sprite_maxx - 1) + col ^= (rand () << 16) | rand (); +#endif + if ((j & mask) == 0) { + unsigned int tmp = (*buf) | col; + *buf++ = tmp; + if (do_collisions) + coltmp |= tmp; + sprxp++; + } + if (dbl > 0) { + unsigned int tmp = (*buf) | col; + *buf++ = tmp; + if (do_collisions) + coltmp |= tmp; + sprxp++; + } + if (dbl > 1) { + unsigned int tmp; + tmp = (*buf) | col; + *buf++ = tmp; + if (do_collisions) + coltmp |= tmp; + tmp = (*buf) | col; + *buf++ = tmp; + if (do_collisions) + coltmp |= tmp; + sprxp++; + sprxp++; + } + j++; + datab >>= 2; + if (do_collisions) { + coltmp &= collision_mask; + if (coltmp) { + unsigned int shrunk_tmp = sprite_ab_merge[coltmp & 255] | (sprite_ab_merge[coltmp >> 8] << 2); + clxdat |= sprclx[shrunk_tmp]; + } + } + } } /* DATAB contains the sprite data; 16 pixels in two-bit packets. Bits 0/1 - determine the color of the leftmost pixel, bits 2/3 the color of the next - etc. - This function assumes that for all sprites in a given line, SPRXP either - stays equal or increases between successive calls. +determine the color of the leftmost pixel, bits 2/3 the color of the next +etc. +This function assumes that for all sprites in a given line, SPRXP either +stays equal or increases between successive calls. - The data is recorded either in lores pixels (if OCS/ECS), or in hires or - superhires pixels (if AGA). */ +The data is recorded either in lores pixels (if OCS/ECS), or in hires or +superhires pixels (if AGA). */ static void record_sprite (int line, int num, int sprxp, uae_u16 *data, uae_u16 *datb, unsigned int ctl) { - struct sprite_entry *e = curr_sprite_entries + next_sprite_entry; - int i; - int word_offs; - uae_u32 collision_mask; - int width, dbl, half; - unsigned int mask = 0; - int attachment; - - half = 0; - dbl = sprite_buffer_res - sprres; - if (dbl < 0) { - half = -dbl; - dbl = 0; - mask = 1 << half; - } - width = (sprite_width << sprite_buffer_res) >> sprres; - attachment = sprctl[num | 1] & 0x80; - - /* Try to coalesce entries if they aren't too far apart */ - if (!next_sprite_forced && e[-1].max + sprite_width >= sprxp) { - e--; - } else { - next_sprite_entry++; - e->pos = sprxp; - e->has_attached = 0; - } - - if (sprxp < e->pos) - uae_abort (L"sprxp < e->pos"); - - e->max = sprxp + width; - e[1].first_pixel = e->first_pixel + ((e->max - e->pos + 3) & ~3); - next_sprite_forced = 0; - - collision_mask = clxmask[clxcon >> 12]; - word_offs = e->first_pixel + sprxp - e->pos; - - for (i = 0; i < sprite_width; i += 16) { - unsigned int da = *data; - unsigned int db = *datb; - uae_u32 datab = ((sprtaba[da & 0xFF] << 16) | sprtaba[da >> 8] - | (sprtabb[db & 0xFF] << 16) | sprtabb[db >> 8]); - int off = (i << dbl) >> half; - uae_u16 *buf = spixels + word_offs + off; - if (currprefs.collision_level > 0 && collision_mask) - record_sprite_1 (sprxp + off, buf, datab, num, dbl, mask, 1, collision_mask); - else - record_sprite_1 (sprxp + off, buf, datab, num, dbl, mask, 0, collision_mask); - data++; - datb++; - } - - /* We have 8 bits per pixel in spixstate, two for every sprite pair. The - low order bit records whether the attach bit was set for this pair. */ - if (attachment && !ecsshres ()) { - uae_u32 state = 0x01010101 << (num & ~1); - uae_u8 *stb1 = spixstate.bytes + word_offs; - for (i = 0; i < width; i += 8) { - stb1[0] |= state; - stb1[1] |= state; - stb1[2] |= state; - stb1[3] |= state; - stb1[4] |= state; - stb1[5] |= state; - stb1[6] |= state; - stb1[7] |= state; - stb1 += 8; - } - e->has_attached = 1; - } + struct sprite_entry *e = curr_sprite_entries + next_sprite_entry; + int i; + int word_offs; + uae_u32 collision_mask; + int width, dbl, half; + unsigned int mask = 0; + int attachment; + + half = 0; + dbl = sprite_buffer_res - sprres; + if (dbl < 0) { + half = -dbl; + dbl = 0; + mask = 1 << half; + } + width = (sprite_width << sprite_buffer_res) >> sprres; + attachment = sprctl[num | 1] & 0x80; + + /* Try to coalesce entries if they aren't too far apart */ + if (!next_sprite_forced && e[-1].max + sprite_width >= sprxp) { + e--; + } else { + next_sprite_entry++; + e->pos = sprxp; + e->has_attached = 0; + } + + if (sprxp < e->pos) + uae_abort (L"sprxp < e->pos"); + + e->max = sprxp + width; + e[1].first_pixel = e->first_pixel + ((e->max - e->pos + 3) & ~3); + next_sprite_forced = 0; + + collision_mask = clxmask[clxcon >> 12]; + word_offs = e->first_pixel + sprxp - e->pos; + + for (i = 0; i < sprite_width; i += 16) { + unsigned int da = *data; + unsigned int db = *datb; + uae_u32 datab = ((sprtaba[da & 0xFF] << 16) | sprtaba[da >> 8] + | (sprtabb[db & 0xFF] << 16) | sprtabb[db >> 8]); + int off = (i << dbl) >> half; + uae_u16 *buf = spixels + word_offs + off; + if (currprefs.collision_level > 0 && collision_mask) + record_sprite_1 (sprxp + off, buf, datab, num, dbl, mask, 1, collision_mask); + else + record_sprite_1 (sprxp + off, buf, datab, num, dbl, mask, 0, collision_mask); + data++; + datb++; + } + + /* We have 8 bits per pixel in spixstate, two for every sprite pair. The + low order bit records whether the attach bit was set for this pair. */ + if (attachment && !ecsshres ()) { + uae_u32 state = 0x01010101 << (num & ~1); + uae_u8 *stb1 = spixstate.bytes + word_offs; + for (i = 0; i < width; i += 8) { + stb1[0] |= state; + stb1[1] |= state; + stb1[2] |= state; + stb1[3] |= state; + stb1[4] |= state; + stb1[5] |= state; + stb1[6] |= state; + stb1[7] |= state; + stb1 += 8; + } + e->has_attached = 1; + } } static void add_sprite (int *countp, int num, int sprxp, int posns[], int nrs[]) { - int count = *countp; - int j, bestp; - - /* Sort the sprites in order of ascending X position before recording them. */ - for (bestp = 0; bestp < count; bestp++) { - if (posns[bestp] > sprxp) - break; - if (posns[bestp] == sprxp && nrs[bestp] < num) - break; - } - for (j = count; j > bestp; j--) { - posns[j] = posns[j - 1]; - nrs[j] = nrs[j - 1]; - } - posns[j] = sprxp; - nrs[j] = num; - count++; - *countp = count; + int count = *countp; + int j, bestp; + + /* Sort the sprites in order of ascending X position before recording them. */ + for (bestp = 0; bestp < count; bestp++) { + if (posns[bestp] > sprxp) + break; + if (posns[bestp] == sprxp && nrs[bestp] < num) + break; + } + for (j = count; j > bestp; j--) { + posns[j] = posns[j - 1]; + nrs[j] = nrs[j - 1]; + } + posns[j] = sprxp; + nrs[j] = num; + count++; + *countp = count; } static int tospritexdiw (int diw) { - return coord_window_to_hw_x (diw - (DIW_DDF_OFFSET << lores_shift)) << sprite_buffer_res; + return coord_window_to_hw_x (diw - (DIW_DDF_OFFSET << lores_shift)) << sprite_buffer_res; } static int tospritexddf (int ddf) { - return (ddf * 2) << sprite_buffer_res; + return (ddf * 2) << sprite_buffer_res; } static int fromspritexdiw (int ddf) { - return coord_hw_to_window_x (ddf >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); + return coord_hw_to_window_x (ddf >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); } static void calcsprite (void) { - sprite_maxx = 0x7fff; - sprite_minx = 0; - if (thisline_decision.diwlastword >= 0) - sprite_maxx = tospritexdiw (thisline_decision.diwlastword); - if (thisline_decision.diwfirstword >= 0) - sprite_minx = tospritexdiw (thisline_decision.diwfirstword); - if (thisline_decision.plfleft >= 0) { - int min, max; - min = tospritexddf (thisline_decision.plfleft); - max = tospritexddf (thisline_decision.plfright); - if (min > sprite_minx && min < max) /* min < max = full line ddf */ - sprite_minx = min; - /* sprites are visible from first BPL0DAT write to end of line - * (another undocumented feature) - */ - } + sprite_maxx = 0x7fff; + sprite_minx = 0; + if (thisline_decision.diwlastword >= 0) + sprite_maxx = tospritexdiw (thisline_decision.diwlastword); + if (thisline_decision.diwfirstword >= 0) + sprite_minx = tospritexdiw (thisline_decision.diwfirstword); + if (thisline_decision.plfleft >= 0) { + int min, max; + min = tospritexddf (thisline_decision.plfleft); + max = tospritexddf (thisline_decision.plfright); + if (min > sprite_minx && min < max) /* min < max = full line ddf */ + sprite_minx = min; + /* sprites are visible from first BPL0DAT write to end of line + * (another undocumented feature) + */ + } } static void decide_sprites (int hpos) { - int nrs[MAX_SPRITES * 2], posns[MAX_SPRITES * 2]; - int count, i; - /* apparantly writes to custom registers happen in the 3/4th of cycle - * and sprite xpos comparator sees it immediately */ - int point = hpos * 2 - 3; - int width = sprite_width; - int sscanmask = 0x100 << sprite_buffer_res; - int gotdata = 0; + int nrs[MAX_SPRITES * 2], posns[MAX_SPRITES * 2]; + int count, i; + /* apparantly writes to custom registers happen in the 3/4th of cycle + * and sprite xpos comparator sees it immediately */ + int point = hpos * 2 - 3; + int width = sprite_width; + int sscanmask = 0x100 << sprite_buffer_res; + int gotdata = 0; - if (thisline_decision.nr_planes == 0 && !(bplcon3 & 2)) - return; + if (thisline_decision.nr_planes == 0 && !(bplcon3 & 2)) + return; - if (nodraw () || hpos < 0x14 || nr_armed == 0 || point == last_sprite_point) - return; + if (nodraw () || hpos < 0x14 || nr_armed == 0 || point == last_sprite_point) + return; - decide_diw (hpos); - decide_line (hpos); - calcsprite (); + decide_diw (hpos); + decide_line (hpos); + calcsprite (); - count = 0; - for (i = 0; i < MAX_SPRITES; i++) { - int sprxp = (fmode & 0x8000) ? (spr[i].xpos & ~sscanmask) : spr[i].xpos; - int hw_xp = sprxp >> sprite_buffer_res; + count = 0; + for (i = 0; i < MAX_SPRITES; i++) { + int sprxp = (fmode & 0x8000) ? (spr[i].xpos & ~sscanmask) : spr[i].xpos; + int hw_xp = sprxp >> sprite_buffer_res; - if (spr[i].xpos < 0) - continue; + if (spr[i].xpos < 0) + continue; - if (!((debug_sprite_mask & magic_sprite_mask) & (1 << i))) - continue; + if (!((debug_sprite_mask & magic_sprite_mask) & (1 << i))) + continue; - if (! spr[i].armed) - continue; + if (! spr[i].armed) + continue; - if (hw_xp > last_sprite_point && hw_xp <= point) - add_sprite (&count, i, sprxp, posns, nrs); + if (hw_xp > last_sprite_point && hw_xp <= point) + add_sprite (&count, i, sprxp, posns, nrs); - /* SSCAN2-bit is fun.. */ - if ((fmode & 0x8000) && !(sprxp & sscanmask)) { - sprxp |= sscanmask; - hw_xp = sprxp >> sprite_buffer_res; - if (hw_xp > last_sprite_point && hw_xp <= point) - add_sprite (&count, MAX_SPRITES + i, sprxp, posns, nrs); + /* SSCAN2-bit is fun.. */ + if ((fmode & 0x8000) && !(sprxp & sscanmask)) { + sprxp |= sscanmask; + hw_xp = sprxp >> sprite_buffer_res; + if (hw_xp > last_sprite_point && hw_xp <= point) + add_sprite (&count, MAX_SPRITES + i, sprxp, posns, nrs); + } } - } - for (i = 0; i < count; i++) { - int nr = nrs[i] & (MAX_SPRITES - 1); - record_sprite (next_lineno, nr, posns[i], sprdata[nr], sprdatb[nr], sprctl[nr]); - /* get left and right sprite edge if brdsprt enabled */ + for (i = 0; i < count; i++) { + int nr = nrs[i] & (MAX_SPRITES - 1); + record_sprite (next_lineno, nr, posns[i], sprdata[nr], sprdatb[nr], sprctl[nr]); + /* get left and right sprite edge if brdsprt enabled */ #if AUTOSCALE_SPRITES - if (dmaen (DMA_SPRITE) && (bplcon0 & 1) && (bplcon3 & 0x02) && !(bplcon3 & 0x20)) { - int j, jj; - for (j = 0, jj = 0; j < sprite_width; j+= 16, jj++) { - int nx = fromspritexdiw (posns[i] + j); - if (sprdata[nr][jj] || sprdatb[nr][jj]) { - if (diwfirstword_total > nx && nx >= (48 << currprefs.gfx_resolution)) - diwfirstword_total = nx; - if (diwlastword_total < nx + 16 && nx <= (448 << currprefs.gfx_resolution)) - diwlastword_total = nx + 16; + if (dmaen (DMA_SPRITE) && (bplcon0 & 1) && (bplcon3 & 0x02) && !(bplcon3 & 0x20)) { + int j, jj; + for (j = 0, jj = 0; j < sprite_width; j+= 16, jj++) { + int nx = fromspritexdiw (posns[i] + j); + if (sprdata[nr][jj] || sprdatb[nr][jj]) { + if (diwfirstword_total > nx && nx >= (48 << currprefs.gfx_resolution)) + diwfirstword_total = nx; + if (diwlastword_total < nx + 16 && nx <= (448 << currprefs.gfx_resolution)) + diwlastword_total = nx + 16; + } + } + gotdata = 1; } - } - gotdata = 1; - } #endif - } - last_sprite_point = point; + } + last_sprite_point = point; #if AUTOSCALE_SPRITES - /* get upper and lower sprite position if brdsprt enabled */ - if (gotdata) { - if (vpos < first_planes_vpos) - first_planes_vpos = vpos; - if (vpos < plffirstline_total) - plffirstline_total = vpos; - if (vpos > last_planes_vpos) - last_planes_vpos = vpos; - if (vpos > plflastline_total) - plflastline_total = vpos; - } + /* get upper and lower sprite position if brdsprt enabled */ + if (gotdata) { + if (vpos < first_planes_vpos) + first_planes_vpos = vpos; + if (vpos < plffirstline_total) + plffirstline_total = vpos; + if (vpos > last_planes_vpos) + last_planes_vpos = vpos; + if (vpos > plflastline_total) + plflastline_total = vpos; + } #endif } STATIC_INLINE int sprites_differ (struct draw_info *dip, struct draw_info *dip_old) { - struct sprite_entry *this_first = curr_sprite_entries + dip->first_sprite_entry; - struct sprite_entry *this_last = curr_sprite_entries + dip->last_sprite_entry; - struct sprite_entry *prev_first = prev_sprite_entries + dip_old->first_sprite_entry; - int npixels; - int i; + struct sprite_entry *this_first = curr_sprite_entries + dip->first_sprite_entry; + struct sprite_entry *this_last = curr_sprite_entries + dip->last_sprite_entry; + struct sprite_entry *prev_first = prev_sprite_entries + dip_old->first_sprite_entry; + int npixels; + int i; - if (dip->nr_sprites != dip_old->nr_sprites) - return 1; + if (dip->nr_sprites != dip_old->nr_sprites) + return 1; - if (dip->nr_sprites == 0) - return 0; + if (dip->nr_sprites == 0) + return 0; - for (i = 0; i < dip->nr_sprites; i++) - if (this_first[i].pos != prev_first[i].pos - || this_first[i].max != prev_first[i].max - || this_first[i].has_attached != prev_first[i].has_attached) - return 1; + for (i = 0; i < dip->nr_sprites; i++) + if (this_first[i].pos != prev_first[i].pos + || this_first[i].max != prev_first[i].max + || this_first[i].has_attached != prev_first[i].has_attached) + return 1; - npixels = this_last->first_pixel + (this_last->max - this_last->pos) - this_first->first_pixel; - if (memcmp (spixels + this_first->first_pixel, spixels + prev_first->first_pixel, + npixels = this_last->first_pixel + (this_last->max - this_last->pos) - this_first->first_pixel; + if (memcmp (spixels + this_first->first_pixel, spixels + prev_first->first_pixel, npixels * sizeof (uae_u16)) != 0) - return 1; - if (memcmp (spixstate.bytes + this_first->first_pixel, spixstate.bytes + prev_first->first_pixel, npixels) != 0) - return 1; - return 0; + return 1; + if (memcmp (spixstate.bytes + this_first->first_pixel, spixstate.bytes + prev_first->first_pixel, npixels) != 0) + return 1; + return 0; } STATIC_INLINE int color_changes_differ (struct draw_info *dip, struct draw_info *dip_old) { - if (dip->nr_color_changes != dip_old->nr_color_changes) - return 1; + if (dip->nr_color_changes != dip_old->nr_color_changes) + return 1; - if (dip->nr_color_changes == 0) - return 0; - if (memcmp (curr_color_changes + dip->first_color_change, + if (dip->nr_color_changes == 0) + return 0; + if (memcmp (curr_color_changes + dip->first_color_change, prev_color_changes + dip_old->first_color_change, dip->nr_color_changes * sizeof *curr_color_changes) != 0) - return 1; - return 0; + return 1; + return 0; } /* End of a horizontal scan line. Finish off all decisions that were not - * made yet. */ +* made yet. */ static void finish_decisions (void) { - struct draw_info *dip; - struct draw_info *dip_old; - struct decision *dp; - int changed; - int hpos = maxhpos; - - if (nodraw ()) - return; - - decide_diw (hpos); - decide_line (hpos); - decide_fetch (hpos); - - if (thisline_decision.plfleft != -1 && thisline_decision.plflinelen == -1) { - if (fetch_state != fetch_not_started) { - write_log (L"fetch_state=%d plfleft=%d,len=%d,vpos=%d,hpos=%d\n", - fetch_state, thisline_decision.plfleft, thisline_decision.plflinelen, - vpos, hpos); - uae_abort (L"fetch_state != fetch_not_started"); - } - thisline_decision.plfright = thisline_decision.plfleft; - thisline_decision.plflinelen = 0; - thisline_decision.bplres = RES_LORES; - } - - /* Large DIWSTOP values can cause the stop position never to be - * reached, so the state machine always stays in the same state and - * there's a more-or-less full-screen DIW. */ - if (hdiwstate == DIW_waiting_stop || thisline_decision.diwlastword > max_diwlastword) - thisline_decision.diwlastword = max_diwlastword; - - if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED; - if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) - MARK_LINE_CHANGED; - - dip = curr_drawinfo + next_lineno; - dip_old = prev_drawinfo + next_lineno; - dp = line_decisions + next_lineno; - changed = thisline_changed; - if (thisline_decision.plfleft != -1 && thisline_decision.nr_planes > 0) - record_diw_line (thisline_decision.plfleft, diwfirstword, diwlastword); - - decide_sprites (hpos + 1); - - dip->last_sprite_entry = next_sprite_entry; - dip->last_color_change = next_color_change; - - if (thisline_decision.ctable == -1) { - if (thisline_decision.plfleft == -1) - remember_ctable_for_border (); - else - remember_ctable (); - } + struct draw_info *dip; + struct draw_info *dip_old; + struct decision *dp; + int changed; + int hpos = maxhpos; + + if (nodraw ()) + return; + + decide_diw (hpos); + decide_line (hpos); + decide_fetch (hpos); + + if (thisline_decision.plfleft != -1 && thisline_decision.plflinelen == -1) { + if (fetch_state != fetch_not_started) { + write_log (L"fetch_state=%d plfleft=%d,len=%d,vpos=%d,hpos=%d\n", + fetch_state, thisline_decision.plfleft, thisline_decision.plflinelen, + vpos, hpos); + uae_abort (L"fetch_state != fetch_not_started"); + } + thisline_decision.plfright = thisline_decision.plfleft; + thisline_decision.plflinelen = 0; + thisline_decision.bplres = RES_LORES; + } + + /* Large DIWSTOP values can cause the stop position never to be + * reached, so the state machine always stays in the same state and + * there's a more-or-less full-screen DIW. */ + if (hdiwstate == DIW_waiting_stop || thisline_decision.diwlastword > max_diwlastword) + thisline_decision.diwlastword = max_diwlastword; + + if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) + MARK_LINE_CHANGED; + if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) + MARK_LINE_CHANGED; - dip->nr_color_changes = next_color_change - dip->first_color_change; - dip->nr_sprites = next_sprite_entry - dip->first_sprite_entry; + dip = curr_drawinfo + next_lineno; + dip_old = prev_drawinfo + next_lineno; + dp = line_decisions + next_lineno; + changed = thisline_changed; + if (thisline_decision.plfleft != -1 && thisline_decision.nr_planes > 0) + record_diw_line (thisline_decision.plfleft, diwfirstword, diwlastword); - if (thisline_decision.plfleft != line_decisions[next_lineno].plfleft) - changed = 1; - if (! changed && color_changes_differ (dip, dip_old)) - changed = 1; - if (!changed && thisline_decision.plfleft != -1 && sprites_differ (dip, dip_old)) - changed = 1; + decide_sprites (hpos + 1); + + dip->last_sprite_entry = next_sprite_entry; + dip->last_color_change = next_color_change; + + if (thisline_decision.ctable == -1) { + if (thisline_decision.plfleft == -1) + remember_ctable_for_border (); + else + remember_ctable (); + } + + dip->nr_color_changes = next_color_change - dip->first_color_change; + dip->nr_sprites = next_sprite_entry - dip->first_sprite_entry; + + if (thisline_decision.plfleft != line_decisions[next_lineno].plfleft) + changed = 1; + if (! changed && color_changes_differ (dip, dip_old)) + changed = 1; + if (!changed && thisline_decision.plfleft != -1 && sprites_differ (dip, dip_old)) + changed = 1; - if (changed) { - thisline_changed = 1; - *dp = thisline_decision; - } else - /* The only one that may differ: */ - dp->ctable = thisline_decision.ctable; + if (changed) { + thisline_changed = 1; + *dp = thisline_decision; + } else + /* The only one that may differ: */ + dp->ctable = thisline_decision.ctable; - /* leave free space for possible extra color changes at the end of line */ - next_color_change += (HBLANK_OFFSET + 1) / 2; + /* leave free space for possible extra color changes at the end of line */ + next_color_change += (HBLANK_OFFSET + 1) / 2; } /* Set the state of all decisions to "undecided" for a new scanline. */ static void reset_decisions (void) { - if (nodraw ()) - return; - - toscr_nr_planes = toscr_nr_planes2 = 0; - thisline_decision.bplres = bplcon0_res; - thisline_decision.nr_planes = 0; - bpl1dat_written = 0; - - thisline_decision.plfleft = -1; - thisline_decision.plflinelen = -1; - thisline_decision.ham_seen = !! (bplcon0 & 0x800); - thisline_decision.ehb_seen = !! isehb (bplcon0, bplcon2); - thisline_decision.ham_at_start = !! (bplcon0 & 0x800); - - /* decided_res shouldn't be touched before it's initialized by decide_line(). */ - thisline_decision.diwfirstword = -1; - thisline_decision.diwlastword = -1; - if (hdiwstate == DIW_waiting_stop) { - thisline_decision.diwfirstword = 0; - if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED; - } - thisline_decision.ctable = -1; - - thisline_changed = 0; - curr_drawinfo[next_lineno].first_color_change = next_color_change; - curr_drawinfo[next_lineno].first_sprite_entry = next_sprite_entry; - next_sprite_forced = 1; - - last_sprite_point = 0; - fetch_state = fetch_not_started; - bplcon1_hpos = -1; - if (bpldmasetuphpos >= 0) { - // this can happen in "too fast" modes - BPLCON0_Denise (0, bplcon0); - setup_fmodes (0); - } - bpldmasetuphpos = -1; - bpldmasetupphase = 0; + if (nodraw ()) + return; + + toscr_nr_planes = toscr_nr_planes2 = 0; + thisline_decision.bplres = bplcon0_res; + thisline_decision.nr_planes = 0; + bpl1dat_written = 0; - if (plf_state > plf_active) - plf_state = plf_idle; - if (plf_state == plf_active && !(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - plf_state = plf_idle; + thisline_decision.plfleft = -1; + thisline_decision.plflinelen = -1; + thisline_decision.ham_seen = !! (bplcon0 & 0x800); + thisline_decision.ehb_seen = !! isehb (bplcon0, bplcon2); + thisline_decision.ham_at_start = !! (bplcon0 & 0x800); + + /* decided_res shouldn't be touched before it's initialized by decide_line(). */ + thisline_decision.diwfirstword = -1; + thisline_decision.diwlastword = -1; + if (hdiwstate == DIW_waiting_stop) { + thisline_decision.diwfirstword = 0; + if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) + MARK_LINE_CHANGED; + } + thisline_decision.ctable = -1; + + thisline_changed = 0; + curr_drawinfo[next_lineno].first_color_change = next_color_change; + curr_drawinfo[next_lineno].first_sprite_entry = next_sprite_entry; + next_sprite_forced = 1; + + last_sprite_point = 0; + fetch_state = fetch_not_started; + bplcon1_hpos = -1; + if (bpldmasetuphpos >= 0) { + // this can happen in "too fast" modes + BPLCON0_Denise (0, bplcon0); + setup_fmodes (0); + } + bpldmasetuphpos = -1; + bpldmasetupphase = 0; + + if (plf_state > plf_active) + plf_state = plf_idle; + if (plf_state == plf_active && !(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + plf_state = plf_idle; - memset (todisplay, 0, sizeof todisplay); - memset (fetched, 0, sizeof fetched); + memset (todisplay, 0, sizeof todisplay); + memset (fetched, 0, sizeof fetched); #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) { - memset (fetched_aga0, 0, sizeof fetched_aga0); - memset (fetched_aga1, 0, sizeof fetched_aga1); - } -#endif - memset (outword, 0, sizeof outword); - - last_decide_line_hpos = -1; - last_sprite_decide_line_hpos = -1; - last_diw_pix_hpos = -1; - last_ddf_pix_hpos = -1; - last_sprite_hpos = -1; - last_fetch_hpos = -1; - - /* These are for comparison. */ - thisline_decision.bplcon0 = bplcon0; - thisline_decision.bplcon2 = bplcon2; + if (currprefs.chipset_mask & CSMASK_AGA) { + memset (fetched_aga0, 0, sizeof fetched_aga0); + memset (fetched_aga1, 0, sizeof fetched_aga1); + } +#endif + memset (outword, 0, sizeof outword); + + last_decide_line_hpos = -1; + last_sprite_decide_line_hpos = -1; + last_diw_pix_hpos = -1; + last_ddf_pix_hpos = -1; + last_sprite_hpos = -1; + last_fetch_hpos = -1; + + /* These are for comparison. */ + thisline_decision.bplcon0 = bplcon0; + thisline_decision.bplcon2 = bplcon2; #ifdef ECS_DENISE - thisline_decision.bplcon3 = bplcon3; + thisline_decision.bplcon3 = bplcon3; #endif #ifdef AGA - thisline_decision.bplcon4 = bplcon4; + thisline_decision.bplcon4 = bplcon4; #endif } +static int islinetoggle (void) +{ + int linetoggle = 0; + if (!(beamcon0 & 0x0800) && !(beamcon0 & 0x0020) && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) { + linetoggle = 1; // NTSC and !LOLDIS -> LOL toggles every line + } else if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS) && currprefs.ntscmode) { + linetoggle = 1; // hardwired NTSC Agnus + } + return linetoggle; +} + static int isvsync (void) { - if (!currprefs.gfx_afullscreen || picasso_on || !currprefs.gfx_avsync) - return 0; - return currprefs.gfx_avsync; + if (!currprefs.gfx_afullscreen || picasso_on || !currprefs.gfx_avsync) + return 0; + return currprefs.gfx_avsync; } int vsynctime_orig; void compute_vsynctime (void) { - fake_vblank_hz = 0; - if (currprefs.chipset_refreshrate) { - vblank_hz = currprefs.chipset_refreshrate; - if (isvsync ()) { - vblank_skip = 1; - if (!fake_vblank_hz && getvsyncrate (vblank_hz) != vblank_hz) { - vblank_hz = getvsyncrate (vblank_hz); - vblank_skip = -1; - } - } - } - if (!fake_vblank_hz) - fake_vblank_hz = vblank_hz; - if (currprefs.turbo_emulation) - vsynctime = vsynctime_orig = 1; - else - vsynctime = vsynctime_orig = syncbase / fake_vblank_hz; - if (!picasso_on) { + fake_vblank_hz = 0; + if (currprefs.chipset_refreshrate) { + vblank_hz = currprefs.chipset_refreshrate; + if (isvsync ()) { + vblank_skip = 1; + if (!fake_vblank_hz && getvsyncrate (vblank_hz) != vblank_hz) { + vblank_hz = getvsyncrate (vblank_hz); + vblank_skip = -1; + } + } + } + if (!fake_vblank_hz) + fake_vblank_hz = vblank_hz; + if (currprefs.turbo_emulation) + vsynctime = vsynctime_orig = 1; + else + vsynctime = vsynctime_orig = syncbase / fake_vblank_hz; + if (!picasso_on) { #ifdef OPENGL - OGL_refresh (); + OGL_refresh (); #endif #ifdef D3D - D3D_refresh (); + D3D_refresh (); #endif - } - if (currprefs.produce_sound > 1) - update_sound (fake_vblank_hz, (bplcon0 & 4) ? -1 : lof); + } + if (currprefs.produce_sound > 1) + update_sound (fake_vblank_hz, (bplcon0 & 4) ? -1 : lof, islinetoggle ()); } static void dumpsync (void) { - static int cnt = 100; - if (cnt < 0) - return; - cnt--; - write_log (L"BEAMCON0=%04X VTOTAL=%04X HTOTAL=%04X\n", new_beamcon0, vtotal, htotal); - write_log (L"HSSTOP=%04X HBSTRT=%04X HBSTOP=%04X\n", hsstop, hbstrt, hbstop); - write_log (L"VSSTOP=%04X VBSTRT=%04X VBSTOP=%04X\n", vsstop, vbstrt, vbstop); - write_log (L"HSSTRT=%04X VSSTRT=%04X HCENTER=%04X\n", hsstrt, vsstrt, hcenter); + static int cnt = 100; + if (cnt < 0) + return; + cnt--; + write_log (L"BEAMCON0=%04X VTOTAL=%04X HTOTAL=%04X\n", new_beamcon0, vtotal, htotal); + write_log (L"HSSTOP=%04X HBSTRT=%04X HBSTOP=%04X\n", hsstop, hbstrt, hbstop); + write_log (L"VSSTOP=%04X VBSTRT=%04X VBSTOP=%04X\n", vsstop, vbstrt, vbstop); + write_log (L"HSSTRT=%04X VSSTRT=%04X HCENTER=%04X\n", hsstrt, vsstrt, hcenter); } /* set PAL/NTSC or custom timing variables */ void init_hz (void) { - int isntsc; - int odbl = doublescan, omaxvpos = maxvpos; - int hzc = 0; + int isntsc; + int odbl = doublescan, omaxvpos = maxvpos; + int hzc = 0; - if (vsync_switchmode (-1, 0) > 0) - currprefs.gfx_avsync = changed_prefs.gfx_avsync = vsync_switchmode (-1, 0); + if (vsync_switchmode (-1, 0) > 0) + currprefs.gfx_avsync = changed_prefs.gfx_avsync = vsync_switchmode (-1, 0); - if (!isvsync () && ((currprefs.chipset_refreshrate == 50 && !currprefs.ntscmode) || - (currprefs.chipset_refreshrate == 60 && currprefs.ntscmode))) { - currprefs.chipset_refreshrate = changed_prefs.chipset_refreshrate = 0; - } + if (!isvsync () && ((currprefs.chipset_refreshrate == 50 && !currprefs.ntscmode) || + (currprefs.chipset_refreshrate == 60 && currprefs.ntscmode))) { + currprefs.chipset_refreshrate = changed_prefs.chipset_refreshrate = 0; + } - doublescan = 0; - if ((beamcon0 & 0xA0) != (new_beamcon0 & 0xA0)) - hzc = 1; - if (beamcon0 != new_beamcon0) { - hack_vpos = 0; - write_log (L"BEAMCON0 %04x -> %04x\n", beamcon0, new_beamcon0); - } - if (beamcon0 & 0x80) - hack_vpos = -1; - beamcon0 = new_beamcon0; - isntsc = (beamcon0 & 0x20) ? 0 : 1; - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - isntsc = currprefs.ntscmode ? 1 : 0; - if (hack_vpos > 0) { - if (maxvpos == hack_vpos) - return; - maxvpos = hack_vpos; - vblank_hz = 15600 / hack_vpos; - hack_vpos = -1; - } else if (hack_vpos < 0) { - hack_vpos = 0; - } - if (hack_vpos == 0) { - if (!isntsc) { - maxvpos = MAXVPOS_PAL; - maxhpos = MAXHPOS_PAL; - minfirstline = VBLANK_ENDLINE_PAL; - vblank_hz = VBLANK_HZ_PAL; - sprite_vblank_endline = VBLANK_SPRITE_PAL; - } else { - maxvpos = MAXVPOS_NTSC; - maxhpos = MAXHPOS_NTSC; - minfirstline = VBLANK_ENDLINE_NTSC; - vblank_hz = VBLANK_HZ_NTSC; - sprite_vblank_endline = VBLANK_SPRITE_NTSC; - } - maxvpos_max = maxvpos; - } - if (beamcon0 & 0x80) { - if (vtotal >= MAXVPOS) - vtotal = MAXVPOS - 1; - maxvpos = vtotal + 1; - if (htotal >= MAXHPOS) - htotal = MAXHPOS - 1; - maxhpos = htotal + 1; - vblank_hz = 227 * 312 * 50 / (maxvpos * maxhpos); - minfirstline = vsstop; - if (minfirstline < 2) - minfirstline = 2; - if (minfirstline >= maxvpos) - minfirstline = maxvpos - 1; - sprite_vblank_endline = minfirstline - 2; - maxvpos_max = maxvpos; - doublescan = htotal <= 164 ? 1 : 0; - dumpsync (); - hzc = 1; - } - if (currprefs.gfx_scandoubler && doublescan == 0) - doublescan = -1; - if (doublescan != odbl || maxvpos != omaxvpos) - hzc = 1; - /* limit to sane values */ - if (vblank_hz < 10) - vblank_hz = 10; - if (vblank_hz > 300) - vblank_hz = 300; - maxhpos_short = maxhpos; - eventtab[ev_hsync].oldcycles = get_cycles (); - eventtab[ev_hsync].evtime = get_cycles() + HSYNCTIME; - events_schedule (); - if (hzc) { - interlace_seen = (bplcon0 & 4) ? 1 : 0; - reset_drawing (); - } - if ((vblank_hz == 50 || vblank_hz == 60) && isvsync () == 2) { - if (getvsyncrate (currprefs.gfx_refreshrate) != vblank_hz) - vsync_switchmode (vblank_hz, currprefs.gfx_refreshrate); - } - if (isvsync ()) { - changed_prefs.chipset_refreshrate = currprefs.chipset_refreshrate = abs (currprefs.gfx_refreshrate); - } - - compute_vsynctime (); + doublescan = 0; + if ((beamcon0 & 0xA0) != (new_beamcon0 & 0xA0)) + hzc = 1; + if (beamcon0 != new_beamcon0) { + hack_vpos = 0; + write_log (L"BEAMCON0 %04x -> %04x\n", beamcon0, new_beamcon0); + } + if (beamcon0 & 0x80) + hack_vpos = -1; + beamcon0 = new_beamcon0; + isntsc = (beamcon0 & 0x20) ? 0 : 1; + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + isntsc = currprefs.ntscmode ? 1 : 0; + if (hack_vpos > 0) { + if (maxvpos == hack_vpos) + return; + maxvpos = hack_vpos; + vblank_hz = 15600 / hack_vpos; + hack_vpos = -1; + } else if (hack_vpos < 0) { + hack_vpos = 0; + } + if (hack_vpos == 0) { + if (!isntsc) { + maxvpos = MAXVPOS_PAL; + maxhpos = MAXHPOS_PAL; + minfirstline = VBLANK_ENDLINE_PAL; + vblank_hz = VBLANK_HZ_PAL; + sprite_vblank_endline = VBLANK_SPRITE_PAL; + } else { + maxvpos = MAXVPOS_NTSC; + maxhpos = MAXHPOS_NTSC; + minfirstline = VBLANK_ENDLINE_NTSC; + vblank_hz = VBLANK_HZ_NTSC; + sprite_vblank_endline = VBLANK_SPRITE_NTSC; + } + maxvpos_max = maxvpos; + } + if (beamcon0 & 0x80) { + if (vtotal >= MAXVPOS) + vtotal = MAXVPOS - 1; + maxvpos = vtotal + 1; + if (htotal >= MAXHPOS) + htotal = MAXHPOS - 1; + maxhpos = htotal + 1; + vblank_hz = 227 * 312 * 50 / (maxvpos * maxhpos); + minfirstline = vsstop; + if (minfirstline < 2) + minfirstline = 2; + if (minfirstline >= maxvpos) + minfirstline = maxvpos - 1; + sprite_vblank_endline = minfirstline - 2; + maxvpos_max = maxvpos; + doublescan = htotal <= 164 ? 1 : 0; + dumpsync (); + hzc = 1; + } + if (currprefs.gfx_scandoubler && doublescan == 0) + doublescan = -1; + if (doublescan != odbl || maxvpos != omaxvpos) + hzc = 1; + /* limit to sane values */ + if (vblank_hz < 10) + vblank_hz = 10; + if (vblank_hz > 300) + vblank_hz = 300; + maxhpos_short = maxhpos; + eventtab[ev_hsync].oldcycles = get_cycles (); + eventtab[ev_hsync].evtime = get_cycles() + HSYNCTIME; + events_schedule (); + if (hzc) { + interlace_seen = (bplcon0 & 4) ? 1 : 0; + reset_drawing (); + } + if ((vblank_hz == 50 || vblank_hz == 60) && isvsync () == 2) { + if (getvsyncrate (currprefs.gfx_refreshrate) != vblank_hz) + vsync_switchmode (vblank_hz, currprefs.gfx_refreshrate); + } + if (isvsync ()) { + changed_prefs.chipset_refreshrate = currprefs.chipset_refreshrate = abs (currprefs.gfx_refreshrate); + } + + compute_vsynctime (); #ifdef OPENGL - OGL_refresh (); + OGL_refresh (); #endif #ifdef PICASSO96 - init_hz_p96 (); + init_hz_p96 (); #endif - inputdevice_tablet_strobe (); - write_log (L"%s mode%s%s V=%dHz H=%dHz (%dx%d)\n", - isntsc ? L"NTSC" : L"PAL", - (bplcon0 & 4) ? L" interlaced" : L"", - doublescan > 0 ? L" dblscan" : L"", - vblank_hz, vblank_hz * maxvpos, - maxhpos, maxvpos); + inputdevice_tablet_strobe (); + write_log (L"%s mode%s%s V=%dHz H=%dHz (%dx%d)\n", + isntsc ? L"NTSC" : L"PAL", + (bplcon0 & 4) ? L" interlaced" : L"", + doublescan > 0 ? L" dblscan" : L"", + vblank_hz, vblank_hz * maxvpos, + maxhpos, maxvpos); } static void calcdiw (void) { - int hstrt = diwstrt & 0xFF; - int hstop = diwstop & 0xFF; - int vstrt = diwstrt >> 8; - int vstop = diwstop >> 8; - - if (diwhigh_written) { - hstrt |= ((diwhigh >> 5) & 1) << 8; - hstop |= ((diwhigh >> 13) & 1) << 8; - vstrt |= (diwhigh & 7) << 8; - vstop |= ((diwhigh >> 8) & 7) << 8; - } else { - hstop += 0x100; - if ((vstop & 0x80) == 0) - vstop |= 0x100; - } - - diwfirstword = coord_diw_to_window_x (hstrt); - diwlastword = coord_diw_to_window_x (hstop); - if (diwfirstword >= diwlastword) { - diwfirstword = 0; - diwlastword = max_diwlastword; - } - if (diwfirstword < 0) - diwfirstword = 0; - - plffirstline = vstrt; - plflastline = vstop; - - plfstrt = ddfstrt; - plfstop = ddfstop; - /* probably not the correct place.. should use plf_state instead */ - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { - /* ECS/AGA and ddfstop > maxhpos == always-on display */ - if (plfstop > maxhpos) - plfstrt = 0; - if (plfstrt < HARD_DDF_START) - plfstrt = HARD_DDF_START; - plfstrt_start = plfstrt - 4; - } else { - /* OCS and ddfstrt >= ddfstop == ddfstop = max */ - if (plfstrt >= plfstop && plfstrt >= HARD_DDF_START) - plfstop = 0xff; - plfstrt_start = HARD_DDF_START - 2; - } - diw_change = 2; + int hstrt = diwstrt & 0xFF; + int hstop = diwstop & 0xFF; + int vstrt = diwstrt >> 8; + int vstop = diwstop >> 8; + + if (diwhigh_written) { + hstrt |= ((diwhigh >> 5) & 1) << 8; + hstop |= ((diwhigh >> 13) & 1) << 8; + vstrt |= (diwhigh & 7) << 8; + vstop |= ((diwhigh >> 8) & 7) << 8; + } else { + hstop += 0x100; + if ((vstop & 0x80) == 0) + vstop |= 0x100; + } + + diwfirstword = coord_diw_to_window_x (hstrt); + diwlastword = coord_diw_to_window_x (hstop); + if (diwfirstword >= diwlastword) { + diwfirstword = 0; + diwlastword = max_diwlastword; + } + if (diwfirstword < 0) + diwfirstword = 0; + + plffirstline = vstrt; + plflastline = vstop; + + plfstrt = ddfstrt; + plfstop = ddfstop; + /* probably not the correct place.. should use plf_state instead */ + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { + /* ECS/AGA and ddfstop > maxhpos == always-on display */ + if (plfstop > maxhpos) + plfstrt = 0; + if (plfstrt < HARD_DDF_START) + plfstrt = HARD_DDF_START; + plfstrt_start = plfstrt - 4; + } else { + /* OCS and ddfstrt >= ddfstop == ddfstop = max */ + if (plfstrt >= plfstop && plfstrt >= HARD_DDF_START) + plfstop = 0xff; + plfstrt_start = HARD_DDF_START - 2; + } + diw_change = 2; } /* display mode changed (lores, doubling etc..), recalculate everything */ void init_custom (void) { - update_mirrors(); - create_cycle_diagram_table (); - reset_drawing (); - init_hz (); - calcdiw (); + update_mirrors(); + create_cycle_diagram_table (); + reset_drawing (); + init_hz (); + calcdiw (); } static int timehack_alive = 0; @@ -2826,248 +2837,248 @@ static int timehack_alive = 0; static uae_u32 REGPARAM2 timehack_helper (TrapContext *context) { #ifdef HAVE_GETTIMEOFDAY - struct timeval tv; - if (m68k_dreg (regs, 0) == 0) - return timehack_alive; + struct timeval tv; + if (m68k_dreg (regs, 0) == 0) + return timehack_alive; - timehack_alive = 10; + timehack_alive = 10; - gettimeofday (&tv, NULL); - put_long (m68k_areg (regs, 0), tv.tv_sec - (((365 * 8 + 2) * 24) * 60 * 60)); - put_long (m68k_areg (regs, 0) + 4, tv.tv_usec); - return 0; + gettimeofday (&tv, NULL); + put_long (m68k_areg (regs, 0), tv.tv_sec - (((365 * 8 + 2) * 24) * 60 * 60)); + put_long (m68k_areg (regs, 0) + 4, tv.tv_usec); + return 0; #else - return 2; + return 2; #endif } - /* - * register functions - */ +/* +* register functions +*/ STATIC_INLINE uae_u16 DENISEID (void) { - if (currprefs.cs_deniserev >= 0) - return currprefs.cs_deniserev; + if (currprefs.cs_deniserev >= 0) + return currprefs.cs_deniserev; #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) - return 0xF8; + if (currprefs.chipset_mask & CSMASK_AGA) + return 0xF8; #endif - if (currprefs.chipset_mask & CSMASK_ECS_DENISE) - return 0xFC; - return 0xffff; + if (currprefs.chipset_mask & CSMASK_ECS_DENISE) + return 0xFC; + return 0xffff; } STATIC_INLINE uae_u16 DMACONR (int hpos) { - decide_line (hpos); - decide_fetch (hpos); - decide_blitter (hpos); - dmacon &= ~(0x4000 | 0x2000); - dmacon |= (blit_interrupt || (!blit_interrupt && currprefs.cs_agnusbltbusybug && !blt_info.got_cycle) ? 0 : 0x4000) - | (blt_info.blitzero ? 0x2000 : 0); - return dmacon; + decide_line (hpos); + decide_fetch (hpos); + decide_blitter (hpos); + dmacon &= ~(0x4000 | 0x2000); + dmacon |= (blit_interrupt || (!blit_interrupt && currprefs.cs_agnusbltbusybug && !blt_info.got_cycle) ? 0 : 0x4000) + | (blt_info.blitzero ? 0x2000 : 0); + return dmacon; } STATIC_INLINE uae_u16 INTENAR (void) { - return intena; + return intena; } uae_u16 INTREQR (void) { - return intreqr; + return intreqr; } STATIC_INLINE uae_u16 ADKCONR (void) { - return adkcon; + return adkcon; } STATIC_INLINE int islightpentriggered (void) { - if (beamcon0 & 0x2000) // LPENDIS - return 0; - return lightpen_triggered > 0; + if (beamcon0 & 0x2000) // LPENDIS + return 0; + return lightpen_triggered > 0; } STATIC_INLINE int issyncstopped (void) { - return (bplcon0 & 2) && !currprefs.genlock; + return (bplcon0 & 2) && !currprefs.genlock; } STATIC_INLINE int GETVPOS (void) { - return islightpentriggered () ? vpos_lpen : (issyncstopped () ? vpos_previous : vpos); + return islightpentriggered () ? vpos_lpen : (issyncstopped () ? vpos_previous : vpos); } STATIC_INLINE int GETHPOS (void) { - return islightpentriggered () ? hpos_lpen : (issyncstopped () ? hpos_previous : current_hpos ()); + return islightpentriggered () ? hpos_lpen : (issyncstopped () ? hpos_previous : current_hpos ()); } STATIC_INLINE uae_u16 VPOSR (void) { - unsigned int csbit = 0; - int vp = (GETVPOS () >> 8) & 7; + unsigned int csbit = 0; + int vp = (GETVPOS () >> 8) & 7; - if (currprefs.cs_agnusrev >= 0) { - csbit |= currprefs.cs_agnusrev << 8; - } else { + if (currprefs.cs_agnusrev >= 0) { + csbit |= currprefs.cs_agnusrev << 8; + } else { #ifdef AGA - csbit |= (currprefs.chipset_mask & CSMASK_AGA) ? 0x2300 : 0; -#endif - csbit |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x2000 : 0; - if (currprefs.chipmem_size > 1024 * 1024 && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - csbit |= 0x2100; - if (currprefs.ntscmode) - csbit |= 0x1000; - } - - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - vp &= 1; - vp = vp | (lof ? 0x8000 : 0) | csbit; - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) - vp |= lol ? 0x80 : 0; + csbit |= (currprefs.chipset_mask & CSMASK_AGA) ? 0x2300 : 0; +#endif + csbit |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x2000 : 0; + if (currprefs.chipmem_size > 1024 * 1024 && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + csbit |= 0x2100; + if (currprefs.ntscmode) + csbit |= 0x1000; + } + + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + vp &= 1; + vp = vp | (lof ? 0x8000 : 0) | csbit; + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) + vp |= lol ? 0x80 : 0; #if 0 - if (M68K_GETPC < 0xf00000) - write_log (L"VPOSR %04x at %08x\n", vp, M68K_GETPC); + if (M68K_GETPC < 0xf00000) + write_log (L"VPOSR %04x at %08x\n", vp, M68K_GETPC); #endif - if (currprefs.cpu_model >= 68020) - hsyncdelay (); - return vp; + if (currprefs.cpu_model >= 68020) + hsyncdelay (); + return vp; } static void VPOSW (uae_u16 v) { #if 0 - if (M68K_GETPC < 0xf00000) - write_log (L"VPOSW %04X PC=%08x\n", v, M68K_GETPC); -#endif - if (lof != ((v & 0x8000) ? 1 : 0)) - lof_changed = 1; - lof = (v & 0x8000) ? 1 : 0; - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) - lol = (v & 0x0080) ? 1 : 0; - hack_vpos2 = (vpos & 0xff); - if (v & 1) - hack_vpos2 |= 0x100; - hack_vpos2vpos = vpos; - if (hack_vpos2 > maxvpos) - hack_vpos2 = maxvpos; - vpos = hack_vpos2; + if (M68K_GETPC < 0xf00000) + write_log (L"VPOSW %04X PC=%08x\n", v, M68K_GETPC); +#endif + if (lof != ((v & 0x8000) ? 1 : 0)) + lof_changed = 1; + lof = (v & 0x8000) ? 1 : 0; + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) + lol = (v & 0x0080) ? 1 : 0; + hack_vpos2 = (vpos & 0xff); + if (v & 1) + hack_vpos2 |= 0x100; + hack_vpos2vpos = vpos; + if (hack_vpos2 > maxvpos) + hack_vpos2 = maxvpos; + vpos = hack_vpos2; } static void VHPOSW (uae_u16 v) { #if 0 - if (M68K_GETPC < 0xf00000) - write_log (L"VHPOSW %04X PC=%08x\n", v, M68K_GETPC); + if (M68K_GETPC < 0xf00000) + write_log (L"VHPOSW %04X PC=%08x\n", v, M68K_GETPC); #endif - v >>= 8; - if (hack_vpos2 & 0x100) - v |= 0x100; - else if (vpos & 0x100) - v |= 0x100; - hack_vpos2 = v; - hack_vpos2vpos = vpos; - if (hack_vpos2 > maxvpos) - hack_vpos2 = maxvpos; - vpos = hack_vpos2; + v >>= 8; + if (hack_vpos2 & 0x100) + v |= 0x100; + else if (vpos & 0x100) + v |= 0x100; + hack_vpos2 = v; + hack_vpos2vpos = vpos; + if (hack_vpos2 > maxvpos) + hack_vpos2 = maxvpos; + vpos = hack_vpos2; } STATIC_INLINE uae_u16 VHPOSR (void) { - uae_u16 vp = GETVPOS (); - uae_u16 hp = GETHPOS (); - - hp += 3; - if (hp >= maxhpos) { - hp -= maxhpos; - vp++; - if (vp >= maxvpos) - vp = 0; - } - hp += 1; - if (hp >= maxhpos) - hp -= maxhpos; - - vp <<= 8; - vp |= hp; - if (currprefs.cpu_model >= 68020) - hsyncdelay (); + uae_u16 vp = GETVPOS (); + uae_u16 hp = GETHPOS (); + + hp += 3; + if (hp >= maxhpos) { + hp -= maxhpos; + vp++; + if (vp >= maxvpos) + vp = 0; + } + hp += 1; + if (hp >= maxhpos) + hp -= maxhpos; + + vp <<= 8; + vp |= hp; + if (currprefs.cpu_model >= 68020) + hsyncdelay (); #if 0 - if (M68K_GETPC < 0xf00000) - write_log (L"VPOS %04x %04x at %08x\n", VPOSR (), vp, M68K_GETPC); + if (M68K_GETPC < 0xf00000) + write_log (L"VPOS %04x %04x at %08x\n", VPOSR (), vp, M68K_GETPC); #endif - return vp; + return vp; } static int test_copper_dangerous (unsigned int address) { - if ((address & 0x1fe) < ((copcon & 2) ? ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0 : 0x40) : 0x80)) { - cop_state.state = COP_stop; - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); - return 1; - } - return 0; + if ((address & 0x1fe) < ((copcon & 2) ? ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0 : 0x40) : 0x80)) { + cop_state.state = COP_stop; + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + return 1; + } + return 0; } static void immediate_copper (int num) { - int pos = 0; - int oldpos = 0; - - cop_state.state = COP_stop; - cop_state.vpos = vpos; - cop_state.hpos = current_hpos () & ~1; - cop_state.ip = num == 1 ? cop1lc : cop2lc; - - while (pos < (maxvpos << 5)) { - if (oldpos > pos) - pos = oldpos; - if (!dmaen(DMA_COPPER)) - break; - if (cop_state.ip >= currprefs.chipmem_size) - break; - pos++; - oldpos = pos; - cop_state.i1 = chipmem_agnus_wget (cop_state.ip); - cop_state.i2 = chipmem_agnus_wget (cop_state.ip + 2); - cop_state.ip += 4; - if (!(cop_state.i1 & 1)) { // move - cop_state.i1 &= 0x1fe; - if (cop_state.i1 == 0x88) { - cop_state.ip = cop1lc; - continue; - } - if (cop_state.i1 == 0x8a) { - cop_state.ip = cop2lc; - continue; - } - if (test_copper_dangerous (cop_state.i1)) - break; - custom_wput_1 (0, cop_state.i1, cop_state.i2, 0); - } else { // wait or skip - if ((cop_state.i1 >> 8) > ((pos >> 5) & 0xff)) - pos = (((pos >> 5) & 0x100) | ((cop_state.i1 >> 8)) << 5) | ((cop_state.i1 & 0xff) >> 3); - if (cop_state.i1 >= 0xffdf && cop_state.i2 == 0xfffe) - break; + int pos = 0; + int oldpos = 0; + + cop_state.state = COP_stop; + cop_state.vpos = vpos; + cop_state.hpos = current_hpos () & ~1; + cop_state.ip = num == 1 ? cop1lc : cop2lc; + + while (pos < (maxvpos << 5)) { + if (oldpos > pos) + pos = oldpos; + if (!dmaen(DMA_COPPER)) + break; + if (cop_state.ip >= currprefs.chipmem_size) + break; + pos++; + oldpos = pos; + cop_state.i1 = chipmem_agnus_wget (cop_state.ip); + cop_state.i2 = chipmem_agnus_wget (cop_state.ip + 2); + cop_state.ip += 4; + if (!(cop_state.i1 & 1)) { // move + cop_state.i1 &= 0x1fe; + if (cop_state.i1 == 0x88) { + cop_state.ip = cop1lc; + continue; + } + if (cop_state.i1 == 0x8a) { + cop_state.ip = cop2lc; + continue; + } + if (test_copper_dangerous (cop_state.i1)) + break; + custom_wput_1 (0, cop_state.i1, cop_state.i2, 0); + } else { // wait or skip + if ((cop_state.i1 >> 8) > ((pos >> 5) & 0xff)) + pos = (((pos >> 5) & 0x100) | ((cop_state.i1 >> 8)) << 5) | ((cop_state.i1 & 0xff) >> 3); + if (cop_state.i1 >= 0xffdf && cop_state.i2 == 0xfffe) + break; + } } - } - cop_state.state = COP_stop; - unset_special (SPCFLAG_COPPER); + cop_state.state = COP_stop; + unset_special (SPCFLAG_COPPER); } STATIC_INLINE void COP1LCH (uae_u16 v) { - cop1lc = (cop1lc & 0xffff) | ((uae_u32)v << 16); + cop1lc = (cop1lc & 0xffff) | ((uae_u32)v << 16); } STATIC_INLINE void COP1LCL (uae_u16 v) { - cop1lc = (cop1lc & ~0xffff) | (v & 0xfffe); + cop1lc = (cop1lc & ~0xffff) | (v & 0xfffe); } STATIC_INLINE void COP2LCH (uae_u16 v) { - cop2lc = (cop2lc & 0xffff) | ((uae_u32)v << 16); + cop2lc = (cop2lc & 0xffff) | ((uae_u32)v << 16); } STATIC_INLINE void COP2LCL (uae_u16 v) { - cop2lc = (cop2lc & ~0xffff) | (v & 0xfffe); + cop2lc = (cop2lc & ~0xffff) | (v & 0xfffe); } static void compute_spcflag_copper (int hpos); @@ -3076,197 +3087,197 @@ static void compute_spcflag_copper (int hpos); // normal COPJMP write: takes 2 more cycles static void COPJMP (int num, int vblank) { - int oldstrobe = cop_state.strobe; + int oldstrobe = cop_state.strobe; #if CUSTOM_DEBUG > 0 - if (dmaen (DMA_COPPER) && (cop_state.saved_i1 != 0xffff || cop_state.saved_i2 != 0xfffe)) - write_log (L"vblank without copper ending %08x (%08x %08x)\n", cop_state.ip, cop1lc, cop2lc); -#endif - - unset_special (SPCFLAG_COPPER); - cop_state.ignore_next = 0; - if (!oldstrobe) - cop_state.state_prev = cop_state.state; - cop_state.state = vblank ? COP_start_delay : COP_strobe_delay1; - cop_state.vpos = vpos; - cop_state.hpos = current_hpos () & ~1; - copper_enabled_thisline = 0; - cop_state.strobe = num; - - if (nocustom ()) { - immediate_copper (num); - return; - } - - if (dmaen (DMA_COPPER)) { - compute_spcflag_copper (current_hpos ()); - } else if (oldstrobe > 0 && oldstrobe != num && cop_state.state_prev == COP_wait) { - /* dma disabled, copper idle and accessed both COPxJMPs -> copper stops! */ - cop_state.state = COP_stop; - } + if (dmaen (DMA_COPPER) && (cop_state.saved_i1 != 0xffff || cop_state.saved_i2 != 0xfffe)) + write_log (L"vblank without copper ending %08x (%08x %08x)\n", cop_state.ip, cop1lc, cop2lc); +#endif + + unset_special (SPCFLAG_COPPER); + cop_state.ignore_next = 0; + if (!oldstrobe) + cop_state.state_prev = cop_state.state; + cop_state.state = vblank ? COP_start_delay : COP_strobe_delay1; + cop_state.vpos = vpos; + cop_state.hpos = current_hpos () & ~1; + copper_enabled_thisline = 0; + cop_state.strobe = num; + + if (nocustom ()) { + immediate_copper (num); + return; + } + + if (dmaen (DMA_COPPER)) { + compute_spcflag_copper (current_hpos ()); + } else if (oldstrobe > 0 && oldstrobe != num && cop_state.state_prev == COP_wait) { + /* dma disabled, copper idle and accessed both COPxJMPs -> copper stops! */ + cop_state.state = COP_stop; + } } STATIC_INLINE void COPCON (uae_u16 a) { - copcon = a; + copcon = a; } static void DMACON (int hpos, uae_u16 v) { - int oldcop, newcop; - uae_u16 changed; + int oldcop, newcop; + uae_u16 changed; - uae_u16 oldcon = dmacon; + uae_u16 oldcon = dmacon; - decide_line (hpos); - decide_fetch (hpos); - decide_blitter (hpos); + decide_line (hpos); + decide_fetch (hpos); + decide_blitter (hpos); - setclr (&dmacon, v); - dmacon &= 0x1FFF; + setclr (&dmacon, v); + dmacon &= 0x1FFF; - changed = dmacon ^ oldcon; + changed = dmacon ^ oldcon; - oldcop = (oldcon & DMA_COPPER) && (oldcon & DMA_MASTER); - newcop = (dmacon & DMA_COPPER) && (dmacon & DMA_MASTER); + oldcop = (oldcon & DMA_COPPER) && (oldcon & DMA_MASTER); + newcop = (dmacon & DMA_COPPER) && (dmacon & DMA_MASTER); - if (oldcop != newcop) { - if (newcop && !oldcop) { - compute_spcflag_copper (hpos); - } else if (!newcop) { - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); + if (oldcop != newcop) { + if (newcop && !oldcop) { + compute_spcflag_copper (hpos); + } else if (!newcop) { + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + } } - } - if ((dmacon & DMA_BLITPRI) > (oldcon & DMA_BLITPRI) && bltstate != BLT_done) - set_special (SPCFLAG_BLTNASTY); - - if (dmaen (DMA_BLITTER) && bltstate == BLT_init) - bltstate = BLT_work; - - if ((dmacon & (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) != (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) - unset_special (SPCFLAG_BLTNASTY); + if ((dmacon & DMA_BLITPRI) > (oldcon & DMA_BLITPRI) && bltstate != BLT_done) + set_special (SPCFLAG_BLTNASTY); - if (changed & (DMA_MASTER | 0x0f)) - audio_hsync (hpos); + if (dmaen (DMA_BLITTER) && bltstate == BLT_init) + bltstate = BLT_work; - if (changed & (DMA_MASTER | DMA_BITPLANE)) { - ddf_change = vpos; - if (dmaen (DMA_BITPLANE)) - maybe_start_bpl_dma (hpos); - } + if ((dmacon & (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) != (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) + unset_special (SPCFLAG_BLTNASTY); - events_schedule(); + if (changed & (DMA_MASTER | 0x0f)) + audio_hsync (hpos); + + if (changed & (DMA_MASTER | DMA_BITPLANE)) { + ddf_change = vpos; + if (dmaen (DMA_BITPLANE)) + maybe_start_bpl_dma (hpos); + } + + events_schedule(); } static int irq_nmi; void NMI_delayed (void) { - irq_nmi = 1; + irq_nmi = 1; } int intlev (void) { - uae_u16 imask = intreq & intena; - if (irq_nmi) { - irq_nmi = 0; - return 7; - } - if (!(imask && (intena & 0x4000))) + uae_u16 imask = intreq & intena; + if (irq_nmi) { + irq_nmi = 0; + return 7; + } + if (!(imask && (intena & 0x4000))) + return -1; + if (imask & (0x4000 | 0x2000)) // 13 14 + return 6; + if (imask & (0x1000 | 0x0800)) // 11 12 + return 5; + if (imask & (0x0400 | 0x0200 | 0x0100 | 0x0080)) // 7 8 9 10 + return 4; + if (imask & (0x0040 | 0x0020 | 0x0010)) // 4 5 6 + return 3; + if (imask & 0x0008) // 3 + return 2; + if (imask & (0x0001 | 0x0002 | 0x0004)) // 0 1 2 + return 1; return -1; - if (imask & (0x4000 | 0x2000)) // 13 14 - return 6; - if (imask & (0x1000 | 0x0800)) // 11 12 - return 5; - if (imask & (0x0400 | 0x0200 | 0x0100 | 0x0080)) // 7 8 9 10 - return 4; - if (imask & (0x0040 | 0x0020 | 0x0010)) // 4 5 6 - return 3; - if (imask & 0x0008) // 3 - return 2; - if (imask & (0x0001 | 0x0002 | 0x0004)) // 0 1 2 - return 1; - return -1; } STATIC_INLINE int use_eventmode (void) { - return currprefs.cpu_cycle_exact != 0; + return currprefs.cpu_cycle_exact != 0; } STATIC_INLINE void INTENA (uae_u16 v) { - setclr (&intena,v); + setclr (&intena,v); #if 0 - if (v & 0x40) - write_log (L"INTENA %04X (%04X) %p\n", intena, v, M68K_GETPC); + if (v & 0x40) + write_log (L"INTENA %04X (%04X) %p\n", intena, v, M68K_GETPC); #endif - if (v & 0x8000) { - if (use_eventmode ()) - prepare_interrupt (); - doint (); - } + if (v & 0x8000) { + if (use_eventmode ()) + prepare_interrupt (); + doint (); + } } void INTREQ_0 (uae_u16 v) { - intreqr = intreq; - /* data in intreq is immediately available (vsync only currently because there is something unknown..) */ - setclr (&intreqr, v & (0x8000 | 0x20)); + intreqr = intreq; + /* data in intreq is immediately available (vsync only currently because there is something unknown..) */ + setclr (&intreqr, v & (0x8000 | 0x20)); - if (use_eventmode ()) - prepare_interrupt (); - if (v & (0x80 | 0x100 | 0x200 | 0x400)) - audio_update_irq (v); - setclr (&intreq, v); - intreqr = intreq; - doint (); + if (use_eventmode ()) + prepare_interrupt (); + if (v & (0x80 | 0x100 | 0x200 | 0x400)) + audio_update_irq (v); + setclr (&intreq, v); + intreqr = intreq; + doint (); } void INTREQ (uae_u16 data) { - INTREQ_0 (data); - serial_check_irq (); - rethink_cias (); + INTREQ_0 (data); + serial_check_irq (); + rethink_cias (); #ifdef A2065 - rethink_a2065 (); + rethink_a2065 (); #endif #ifdef A2091 - rethink_a2091 (); + rethink_a2091 (); #endif #ifdef CDTV - rethink_cdtv (); + rethink_cdtv (); #endif #ifdef CD32 - rethink_akiko (); + rethink_akiko (); #endif - rethink_gayle (); + rethink_gayle (); } static void ADKCON (int hpos, uae_u16 v) { - if (currprefs.produce_sound > 0) - update_audio (); + if (currprefs.produce_sound > 0) + update_audio (); - setclr (&adkcon,v); - audio_update_adkmasks (); - DISK_update (hpos); - if ((v >> 11) & 1) - serial_uartbreak ((adkcon >> 11) & 1); + setclr (&adkcon,v); + audio_update_adkmasks (); + DISK_update (hpos); + if ((v >> 11) & 1) + serial_uartbreak ((adkcon >> 11) & 1); } static void BEAMCON0 (uae_u16 v) { - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { - if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) - v &= 0x20; - if (v != new_beamcon0) { - new_beamcon0 = v; - if (v & ~0x20) - write_log (L"warning: %04X written to BEAMCON0 PC=%08X\n", v, M68K_GETPC); + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { + if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) + v &= 0x20; + if (v != new_beamcon0) { + new_beamcon0 = v; + if (v & ~0x20) + write_log (L"warning: %04X written to BEAMCON0 PC=%08X\n", v, M68K_GETPC); + } } - } } #ifndef CUSTOM_SIMPLE @@ -3274,309 +3285,309 @@ static void BEAMCON0 (uae_u16 v) static void varsync (void) { #ifdef PICASSO96 - if (p96refresh_active) - { - extern int p96hack_vpos2; - static int p96hack_vpos_old; - if (p96hack_vpos_old == p96hack_vpos2) return; - vtotal = p96hack_vpos2; - p96hack_vpos_old = p96hack_vpos2; - hack_vpos = -1; - return; - } + if (p96refresh_active) + { + extern int p96hack_vpos2; + static int p96hack_vpos_old; + if (p96hack_vpos_old == p96hack_vpos2) return; + vtotal = p96hack_vpos2; + p96hack_vpos_old = p96hack_vpos2; + hack_vpos = -1; + return; + } #endif - if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) - return; - if (!(beamcon0 & 0x80)) - return; - hack_vpos = -1; - dumpsync (); + if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) + return; + if (!(beamcon0 & 0x80)) + return; + hack_vpos = -1; + dumpsync (); } #endif static void BPLxPTH (int hpos, uae_u16 v, int num) { - decide_line (hpos); - decide_fetch (hpos); - bplpt[num] = (bplpt[num] & 0x0000ffff) | ((uae_u32)v << 16); - bplptx[num] = (bplptx[num] & 0x0000ffff) | ((uae_u32)v << 16); - //write_log (L"%d:%d:BPL%dPTH %08X COP=%08x\n", hpos, vpos, num, bplpt[num], cop_state.ip); + decide_line (hpos); + decide_fetch (hpos); + bplpt[num] = (bplpt[num] & 0x0000ffff) | ((uae_u32)v << 16); + bplptx[num] = (bplptx[num] & 0x0000ffff) | ((uae_u32)v << 16); + //write_log (L"%d:%d:BPL%dPTH %08X COP=%08x\n", hpos, vpos, num, bplpt[num], cop_state.ip); } static void BPLxPTL (int hpos, uae_u16 v, int num) { - decide_line (hpos); - decide_fetch (hpos); - bplpt[num] = (bplpt[num] & 0xffff0000) | (v & 0x0000fffe); - bplptx[num] = (bplptx[num] & 0xffff0000) | (v & 0x0000fffe); - //write_log (L"%d:%d:BPL%dPTL %08X COP=%08x\n", hpos, vpos, num, bplpt[num], cop_state.ip); + decide_line (hpos); + decide_fetch (hpos); + bplpt[num] = (bplpt[num] & 0xffff0000) | (v & 0x0000fffe); + bplptx[num] = (bplptx[num] & 0xffff0000) | (v & 0x0000fffe); + //write_log (L"%d:%d:BPL%dPTL %08X COP=%08x\n", hpos, vpos, num, bplpt[num], cop_state.ip); } static void BPLCON0_Denise (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_ECS_DENISE)) - v &= ~0x00F1; - else if (! (currprefs.chipset_mask & CSMASK_AGA)) - v &= ~0x00B1; - v &= ~(0x0200 | 0x0100 | 0x0080 | 0x0020); + if (! (currprefs.chipset_mask & CSMASK_ECS_DENISE)) + v &= ~0x00F1; + else if (! (currprefs.chipset_mask & CSMASK_AGA)) + v &= ~0x00B1; + v &= ~(0x0200 | 0x0100 | 0x0080 | 0x0020); #if SPRBORDER - v |= 1; + v |= 1; #endif - if (bplcon0d == v) - return; + if (bplcon0d == v) + return; - bplcon0dd = -1; - // fake unused 0x0080 bit as an EHB bit (see below) - if (isehb (bplcon0d, bplcon2)) - v |= 0x80; + bplcon0dd = -1; + // fake unused 0x0080 bit as an EHB bit (see below) + if (isehb (bplcon0d, bplcon2)) + v |= 0x80; - record_register_change (hpos, 0x100, (bplcon0d & ~(0x800 | 0x400 | 0x80)) | (v & (0x0800 | 0x400 | 0x80))); + record_register_change (hpos, 0x100, (bplcon0d & ~(0x800 | 0x400 | 0x80)) | (v & (0x0800 | 0x400 | 0x80))); - bplcon0d = v & ~0x80; + bplcon0d = v & ~0x80; #ifdef ECS_DENISE - if (currprefs.chipset_mask & CSMASK_ECS_DENISE) { - decide_sprites (hpos); - sprres = expand_sprres (v, bplcon3); - } + if (currprefs.chipset_mask & CSMASK_ECS_DENISE) { + decide_sprites (hpos); + sprres = expand_sprres (v, bplcon3); + } #endif - if (thisline_decision.plfleft == -1) - update_denise (hpos); + if (thisline_decision.plfleft == -1) + update_denise (hpos); } static void BPLCON0 (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_ECS_DENISE)) - v &= ~0x00F1; - else if (! (currprefs.chipset_mask & CSMASK_AGA)) - v &= ~0x00B1; - v &= ~(0x0200 | 0x0100 | 0x0080 | 0x0020); + if (! (currprefs.chipset_mask & CSMASK_ECS_DENISE)) + v &= ~0x00F1; + else if (! (currprefs.chipset_mask & CSMASK_AGA)) + v &= ~0x00B1; + v &= ~(0x0200 | 0x0100 | 0x0080 | 0x0020); #if SPRBORDER - v |= 1; + v |= 1; #endif - if (bplcon0 == v) - return; + if (bplcon0 == v) + return; - if (!issyncstopped ()) { - vpos_previous = vpos; - hpos_previous = hpos; - } + if (!issyncstopped ()) { + vpos_previous = vpos; + hpos_previous = hpos; + } - bplcon0 = v; + bplcon0 = v; - bpldmainitdelay (hpos); + bpldmainitdelay (hpos); - if (thisline_decision.plfleft == -1) - BPLCON0_Denise (hpos, v); + if (thisline_decision.plfleft == -1) + BPLCON0_Denise (hpos, v); } #if 0 - ddf_change = vpos; - decide_line (hpos); - decide_fetch (hpos); - decide_blitter (hpos); +ddf_change = vpos; +decide_line (hpos); +decide_fetch (hpos); +decide_blitter (hpos); - bplcon0 = v; +bplcon0 = v; - badmode = GET_RES_AGNUS (bplcon0) != GET_RES_DENISE (bplcon0); +badmode = GET_RES_AGNUS (bplcon0) != GET_RES_DENISE (bplcon0); - // fake unused 0x0080 bit as an EHB bit (see above) - if (isehb (bplcon0, bplcon2)) +// fake unused 0x0080 bit as an EHB bit (see above) +if (isehb (bplcon0, bplcon2)) v |= 0x80; - BPLCON0_Denise (hpos, v); +BPLCON0_Denise (hpos, v); - expand_fmodes (); +expand_fmodes (); - record_register_change (hpos, 0x100, v); +record_register_change (hpos, 0x100, v); - calcdiw (); - estimate_last_fetch_cycle (hpos); +calcdiw (); +estimate_last_fetch_cycle (hpos); } #endif STATIC_INLINE void BPLCON1 (int hpos, uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_AGA)) - v &= 0xff; - if (bplcon1 == v) - return; - ddf_change = vpos; - decide_line (hpos); - decide_fetch (hpos); - bplcon1_hpos = hpos; - bplcon1 = v; + if (!(currprefs.chipset_mask & CSMASK_AGA)) + v &= 0xff; + if (bplcon1 == v) + return; + ddf_change = vpos; + decide_line (hpos); + decide_fetch (hpos); + bplcon1_hpos = hpos; + bplcon1 = v; } STATIC_INLINE void BPLCON2 (int hpos, uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_AGA)) - v &= 0x7f; - if (bplcon2 == v) - return; - decide_line (hpos); - bplcon2 = v; - record_register_change (hpos, 0x104, v); + if (!(currprefs.chipset_mask & CSMASK_AGA)) + v &= 0x7f; + if (bplcon2 == v) + return; + decide_line (hpos); + bplcon2 = v; + record_register_change (hpos, 0x104, v); } #ifdef ECS_DENISE STATIC_INLINE void BPLCON3 (int hpos, uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) - return; - if (!(currprefs.chipset_mask & CSMASK_AGA)) { - v &= 0x003f; - v |= 0x0c00; - } + if (!(currprefs.chipset_mask & CSMASK_ECS_DENISE)) + return; + if (!(currprefs.chipset_mask & CSMASK_AGA)) { + v &= 0x003f; + v |= 0x0c00; + } #if SPRBORDER - v |= 2; + v |= 2; #endif - if (bplcon3 == v) - return; - decide_line (hpos); - decide_sprites (hpos); - bplcon3 = v; - sprres = expand_sprres (bplcon0, bplcon3); - record_register_change (hpos, 0x106, v); + if (bplcon3 == v) + return; + decide_line (hpos); + decide_sprites (hpos); + bplcon3 = v; + sprres = expand_sprres (bplcon0, bplcon3); + record_register_change (hpos, 0x106, v); } #endif #ifdef AGA STATIC_INLINE void BPLCON4 (int hpos, uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_AGA)) - return; - if (bplcon4 == v) - return; - decide_line (hpos); - bplcon4 = v; - record_register_change (hpos, 0x10c, v); + if (!(currprefs.chipset_mask & CSMASK_AGA)) + return; + if (bplcon4 == v) + return; + decide_line (hpos); + bplcon4 = v; + record_register_change (hpos, 0x10c, v); } #endif static void BPL1MOD (int hpos, uae_u16 v) { - v &= ~1; - if ((uae_s16)bpl1mod == (uae_s16)v) - return; - decide_line (hpos); - decide_fetch (hpos); - bpl1mod = v; + v &= ~1; + if ((uae_s16)bpl1mod == (uae_s16)v) + return; + decide_line (hpos); + decide_fetch (hpos); + bpl1mod = v; } static void BPL2MOD (int hpos, uae_u16 v) { - v &= ~1; - if ((uae_s16)bpl2mod == (uae_s16)v) - return; - decide_line (hpos); - decide_fetch (hpos); - bpl2mod = v; + v &= ~1; + if ((uae_s16)bpl2mod == (uae_s16)v) + return; + decide_line (hpos); + decide_fetch (hpos); + bpl2mod = v; } /* needed in special OCS/ECS "7-plane" mode. */ /* (in reality only BPL5DAT and BPL6DAT needed) */ static void BPLxDAT (int hpos, int num, uae_u16 v) { - decide_line (hpos); - decide_fetch (hpos); - bplxdat[num] = v; - if (num == 0) { - bpl1dat_written = 1; - maybe_first_bpl1dat (hpos); - } + decide_line (hpos); + decide_fetch (hpos); + bplxdat[num] = v; + if (num == 0) { + bpl1dat_written = 1; + maybe_first_bpl1dat (hpos); + } } static void DIWSTRT (int hpos, uae_u16 v) { - if (diwstrt == v && ! diwhigh_written) - return; - decide_line (hpos); - diwhigh_written = 0; - diwstrt = v; - calcdiw (); + if (diwstrt == v && ! diwhigh_written) + return; + decide_line (hpos); + diwhigh_written = 0; + diwstrt = v; + calcdiw (); } static void DIWSTOP (int hpos, uae_u16 v) { - if (diwstop == v && ! diwhigh_written) - return; - decide_line (hpos); - diwhigh_written = 0; - diwstop = v; - calcdiw (); + if (diwstop == v && ! diwhigh_written) + return; + decide_line (hpos); + diwhigh_written = 0; + diwstop = v; + calcdiw (); } static void DIWHIGH (int hpos, uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - return; - v &= ~(0x8000 | 0x4000 | 0x0080 | 0x0040); - if (diwhigh_written && diwhigh == v) - return; - decide_line (hpos); - diwhigh_written = 1; - diwhigh = v; - calcdiw (); + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + v &= ~(0x8000 | 0x4000 | 0x0080 | 0x0040); + if (diwhigh_written && diwhigh == v) + return; + decide_line (hpos); + diwhigh_written = 1; + diwhigh = v; + calcdiw (); } static void DDFSTRT (int hpos, uae_u16 v) { - v &= 0xfe; - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - v &= 0xfc; - if (ddfstrt == v && hpos + 2 != ddfstrt) - return; - ddf_change = vpos; - decide_line (hpos); - ddfstrt_old_hpos = hpos; - ddfstrt_old_vpos = vpos; - ddfstrt = v; - calcdiw (); - if (ddfstop > 0xD4 && (ddfstrt & 4) == 4) { - static int last_warned; - last_warned = (last_warned + 1) & 4095; - if (last_warned == 0) - write_log (L"WARNING! Very strange DDF values (%x %x).\n", ddfstrt, ddfstop); - } + v &= 0xfe; + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + v &= 0xfc; + if (ddfstrt == v && hpos + 2 != ddfstrt) + return; + ddf_change = vpos; + decide_line (hpos); + ddfstrt_old_hpos = hpos; + ddfstrt_old_vpos = vpos; + ddfstrt = v; + calcdiw (); + if (ddfstop > 0xD4 && (ddfstrt & 4) == 4) { + static int last_warned; + last_warned = (last_warned + 1) & 4095; + if (last_warned == 0) + write_log (L"WARNING! Very strange DDF values (%x %x).\n", ddfstrt, ddfstop); + } } static void DDFSTOP (int hpos, uae_u16 v) { - v &= 0xfe; - if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - v &= 0xfc; - if (ddfstop == v && hpos + 2 != ddfstop) - return; - ddf_change = vpos; - decide_line (hpos); - decide_fetch (hpos); - decide_blitter (hpos); - ddfstop = v; - calcdiw (); - if (fetch_state != fetch_not_started) - estimate_last_fetch_cycle (hpos); - if (ddfstop > 0xD4 && (ddfstrt & 4) == 4) { - static int last_warned; - if (last_warned == 0) - write_log (L"WARNING! Very strange DDF values (%x).\n", ddfstop); - last_warned = (last_warned + 1) & 4095; - } + v &= 0xfe; + if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + v &= 0xfc; + if (ddfstop == v && hpos + 2 != ddfstop) + return; + ddf_change = vpos; + decide_line (hpos); + decide_fetch (hpos); + decide_blitter (hpos); + ddfstop = v; + calcdiw (); + if (fetch_state != fetch_not_started) + estimate_last_fetch_cycle (hpos); + if (ddfstop > 0xD4 && (ddfstrt & 4) == 4) { + static int last_warned; + if (last_warned == 0) + write_log (L"WARNING! Very strange DDF values (%x).\n", ddfstop); + last_warned = (last_warned + 1) & 4095; + } } static void FMODE (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_AGA)) - v = 0; - v &= 0xC00F; - if (fmode == v) - return; - ddf_change = vpos; - fmode = v; - sprite_width = GET_SPRITEWIDTH (fmode); - bpldmainitdelay (hpos); + if (! (currprefs.chipset_mask & CSMASK_AGA)) + v = 0; + v &= 0xC00F; + if (fmode == v) + return; + ddf_change = vpos; + fmode = v; + sprite_width = GET_SPRITEWIDTH (fmode); + bpldmainitdelay (hpos); } static void FNULL (uae_u16 v) @@ -3586,24 +3597,24 @@ static void FNULL (uae_u16 v) static void BLTADAT (int hpos, uae_u16 v) { - maybe_blit (hpos, 0); + maybe_blit (hpos, 0); - blt_info.bltadat = v; + blt_info.bltadat = v; } /* - * "Loading data shifts it immediately" says the HRM. Well, that may - * be true for BLTBDAT, but not for BLTADAT - it appears the A data must be - * loaded for every word so that AFWM and ALWM can be applied. - */ +* "Loading data shifts it immediately" says the HRM. Well, that may +* be true for BLTBDAT, but not for BLTADAT - it appears the A data must be +* loaded for every word so that AFWM and ALWM can be applied. +*/ static void BLTBDAT (int hpos, uae_u16 v) { - maybe_blit (hpos, 0); + maybe_blit (hpos, 0); - if (bltcon1 & 2) - blt_info.bltbhold = v << (bltcon1 >> 12); - else - blt_info.bltbhold = v >> (bltcon1 >> 12); - blt_info.bltbdat = v; + if (bltcon1 & 2) + blt_info.bltbhold = v << (bltcon1 >> 12); + else + blt_info.bltbhold = v >> (bltcon1 >> 12); + blt_info.bltbdat = v; } static void BLTCDAT (int hpos, uae_u16 v) { maybe_blit (hpos, 0); blt_info.bltcdat = v; reset_blit (0); } @@ -3614,13 +3625,13 @@ static void BLTDMOD (int hpos, uae_u16 v) { maybe_blit (hpos, 1); blt_info.bltdm static void BLTCON0 (int hpos, uae_u16 v) { maybe_blit (hpos, 2); bltcon0 = v; reset_blit (1); } /* The next category is "Most useless hardware register". - * And the winner is... */ +* And the winner is... */ static void BLTCON0L (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - return; - maybe_blit (hpos, 2); bltcon0 = (bltcon0 & 0xFF00) | (v & 0xFF); - reset_blit (1); + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + maybe_blit (hpos, 2); bltcon0 = (bltcon0 & 0xFF00) | (v & 0xFF); + reset_blit (1); } static void BLTCON1 (int hpos, uae_u16 v) { maybe_blit (hpos, 2); bltcon1 = v; reset_blit (2); } @@ -3638,147 +3649,147 @@ static void BLTDPTL (int hpos, uae_u16 v) { maybe_blit (hpos, 0); bltdpt = (bltd static void BLTSIZE (int hpos, uae_u16 v) { - maybe_blit (hpos, 0); + maybe_blit (hpos, 0); - blt_info.vblitsize = v >> 6; - blt_info.hblitsize = v & 0x3F; - if (!blt_info.vblitsize) - blt_info.vblitsize = 1024; - if (!blt_info.hblitsize) - blt_info.hblitsize = 64; - do_blitter (hpos, copper_access); + blt_info.vblitsize = v >> 6; + blt_info.hblitsize = v & 0x3F; + if (!blt_info.vblitsize) + blt_info.vblitsize = 1024; + if (!blt_info.hblitsize) + blt_info.hblitsize = 64; + do_blitter (hpos, copper_access); } static void BLTSIZV (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - return; - maybe_blit (hpos, 0); - blt_info.vblitsize = v & 0x7FFF; + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + maybe_blit (hpos, 0); + blt_info.vblitsize = v & 0x7FFF; } static void BLTSIZH (int hpos, uae_u16 v) { - if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) - return; - maybe_blit (hpos, 0); - blt_info.hblitsize = v & 0x7FF; - if (!blt_info.vblitsize) - blt_info.vblitsize = 32768; - if (!blt_info.hblitsize) - blt_info.hblitsize = 0x800; - do_blitter (hpos, copper_access); + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + maybe_blit (hpos, 0); + blt_info.hblitsize = v & 0x7FF; + if (!blt_info.vblitsize) + blt_info.vblitsize = 32768; + if (!blt_info.hblitsize) + blt_info.hblitsize = 0x800; + do_blitter (hpos, copper_access); } STATIC_INLINE void spr_arm (int num, int state) { - switch (state) { - case 0: - nr_armed -= spr[num].armed; - spr[num].armed = 0; - break; - default: - nr_armed += 1 - spr[num].armed; - spr[num].armed = 1; - break; - } + switch (state) { + case 0: + nr_armed -= spr[num].armed; + spr[num].armed = 0; + break; + default: + nr_armed += 1 - spr[num].armed; + spr[num].armed = 1; + break; + } } STATIC_INLINE void sprstartstop (struct sprite *s) { - if (vpos == s->vstart) - s->dmastate = 1; - if (vpos == s->vstop) - s->dmastate = 0; + if (vpos == s->vstart) + s->dmastate = 1; + if (vpos == s->vstop) + s->dmastate = 0; } STATIC_INLINE void SPRxCTLPOS (int num) { - int sprxp; - struct sprite *s = &spr[num]; + int sprxp; + struct sprite *s = &spr[num]; - sprstartstop (s); - sprxp = (sprpos[num] & 0xFF) * 2 + (sprctl[num] & 1); - sprxp <<= sprite_buffer_res; - /* Quite a bit salad in this register... */ - if (0) { - } + sprstartstop (s); + sprxp = (sprpos[num] & 0xFF) * 2 + (sprctl[num] & 1); + sprxp <<= sprite_buffer_res; + /* Quite a bit salad in this register... */ + if (0) { + } #ifdef AGA - else if (currprefs.chipset_mask & CSMASK_AGA) { - sprxp |= ((sprctl[num] >> 3) & 3) >> (RES_MAX - sprite_buffer_res); - s->dblscan = sprpos[num] & 0x80; - } + else if (currprefs.chipset_mask & CSMASK_AGA) { + sprxp |= ((sprctl[num] >> 3) & 3) >> (RES_MAX - sprite_buffer_res); + s->dblscan = sprpos[num] & 0x80; + } #endif #ifdef ECS_DENISE - else if (currprefs.chipset_mask & CSMASK_ECS_DENISE) { - sprxp |= ((sprctl[num] >> 3) & 2) >> (RES_MAX - sprite_buffer_res); - } + else if (currprefs.chipset_mask & CSMASK_ECS_DENISE) { + sprxp |= ((sprctl[num] >> 3) & 2) >> (RES_MAX - sprite_buffer_res); + } #endif - s->xpos = sprxp; - s->vstart = (sprpos[num] >> 8) | ((sprctl[num] << 6) & 0x100); - s->vstop = (sprctl[num] >> 8) | ((sprctl[num] << 7) & 0x100); - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { - s->vstart |= (sprctl[num] << 3) & 0x200; - s->vstop |= (sprctl[num] << 4) & 0x200; - } - sprstartstop (s); + s->xpos = sprxp; + s->vstart = (sprpos[num] >> 8) | ((sprctl[num] << 6) & 0x100); + s->vstop = (sprctl[num] >> 8) | ((sprctl[num] << 7) & 0x100); + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { + s->vstart |= (sprctl[num] << 3) & 0x200; + s->vstop |= (sprctl[num] << 4) & 0x200; + } + sprstartstop (s); } STATIC_INLINE void SPRxCTL_1 (uae_u16 v, int num, int hpos) { - struct sprite *s = &spr[num]; - sprctl[num] = v; - spr_arm (num, 0); - SPRxCTLPOS (num); + struct sprite *s = &spr[num]; + sprctl[num] = v; + spr_arm (num, 0); + SPRxCTLPOS (num); #if SPRITE_DEBUG > 0 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dCTL %04X P=%06X VSTRT=%d VSTOP=%d HSTRT=%d D=%d A=%d CP=%x PC=%x\n", - vpos, hpos, num, v, s->pt, s->vstart, s->vstop, s->xpos, spr[num].dmastate, spr[num].armed, cop_state.ip, M68K_GETPC); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dCTL %04X P=%06X VSTRT=%d VSTOP=%d HSTRT=%d D=%d A=%d CP=%x PC=%x\n", + vpos, hpos, num, v, s->pt, s->vstart, s->vstop, s->xpos, spr[num].dmastate, spr[num].armed, cop_state.ip, M68K_GETPC); + } #endif } STATIC_INLINE void SPRxPOS_1 (uae_u16 v, int num, int hpos) { - struct sprite *s = &spr[num]; - sprpos[num] = v; - SPRxCTLPOS (num); + struct sprite *s = &spr[num]; + sprpos[num] = v; + SPRxCTLPOS (num); #if SPRITE_DEBUG > 0 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dPOS %04X P=%06X VSTRT=%d VSTOP=%d HSTRT=%d D=%d A=%d CP=%x PC=%x\n", - vpos, hpos, num, v, s->pt, s->vstart, s->vstop, s->xpos, spr[num].dmastate, spr[num].armed, cop_state.ip, M68K_GETPC); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dPOS %04X P=%06X VSTRT=%d VSTOP=%d HSTRT=%d D=%d A=%d CP=%x PC=%x\n", + vpos, hpos, num, v, s->pt, s->vstart, s->vstop, s->xpos, spr[num].dmastate, spr[num].armed, cop_state.ip, M68K_GETPC); + } #endif } STATIC_INLINE void SPRxDATA_1 (uae_u16 v, int num, int hpos) { - sprdata[num][0] = v; + sprdata[num][0] = v; #ifdef AGA - sprdata[num][1] = v; - sprdata[num][2] = v; - sprdata[num][3] = v; + sprdata[num][1] = v; + sprdata[num][2] = v; + sprdata[num][3] = v; #endif - spr_arm (num, 1); + spr_arm (num, 1); #if SPRITE_DEBUG > 1 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dDATA %04X P=%06X D=%d A=%d PC=%x\n", - vpos, hpos, num, v, spr[num].pt, spr[num].dmastate, spr[num].armed, M68K_GETPC); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dDATA %04X P=%06X D=%d A=%d PC=%x\n", + vpos, hpos, num, v, spr[num].pt, spr[num].dmastate, spr[num].armed, M68K_GETPC); + } #endif } STATIC_INLINE void SPRxDATB_1 (uae_u16 v, int num, int hpos) { - sprdatb[num][0] = v; + sprdatb[num][0] = v; #ifdef AGA - sprdatb[num][1] = v; - sprdatb[num][2] = v; - sprdatb[num][3] = v; + sprdatb[num][1] = v; + sprdatb[num][2] = v; + sprdatb[num][3] = v; #endif #if SPRITE_DEBUG > 1 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dDATB %04X P=%06X D=%d A=%d PC=%x\n", - vpos, hpos, num, v, spr[num].pt, spr[num].dmastate, spr[num].armed, M68K_GETPC); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dDATB %04X P=%06X D=%d A=%d PC=%x\n", + vpos, hpos, num, v, spr[num].pt, spr[num].dmastate, spr[num].armed, M68K_GETPC); + } #endif } static void SPRxDATA (int hpos, uae_u16 v, int num) { decide_sprites (hpos); SPRxDATA_1 (v, num, hpos); } @@ -3787,1143 +3798,1143 @@ static void SPRxCTL (int hpos, uae_u16 v, int num) { decide_sprites (hpos); SPRx static void SPRxPOS (int hpos, uae_u16 v, int num) { decide_sprites (hpos); SPRxPOS_1 (v, num, hpos); } static void SPRxPTH (int hpos, uae_u16 v, int num) { - decide_sprites (hpos); - spr[num].pt &= 0xffff; - spr[num].pt |= (uae_u32)v << 16; + decide_sprites (hpos); + spr[num].pt &= 0xffff; + spr[num].pt |= (uae_u32)v << 16; #if SPRITE_DEBUG > 0 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dPTH %06X\n", vpos, hpos, num, spr[num].pt); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dPTH %06X\n", vpos, hpos, num, spr[num].pt); + } #endif } static void SPRxPTL (int hpos, uae_u16 v, int num) { - decide_sprites (hpos); - spr[num].pt &= ~0xffff; - spr[num].pt |= v; + decide_sprites (hpos); + spr[num].pt &= ~0xffff; + spr[num].pt |= v; #if SPRITE_DEBUG > 0 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:SPR%dPTL %06X\n", vpos, hpos, num, spr[num].pt); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:SPR%dPTL %06X\n", vpos, hpos, num, spr[num].pt); + } #endif } static void CLXCON (uae_u16 v) { - clxcon = v; - clxcon_bpl_enable = (v >> 6) & 63; - clxcon_bpl_match = v & 63; + clxcon = v; + clxcon_bpl_enable = (v >> 6) & 63; + clxcon_bpl_match = v & 63; } static void CLXCON2 (uae_u16 v) { - if (!(currprefs.chipset_mask & CSMASK_AGA)) - return; - clxcon2 = v; - clxcon_bpl_enable |= v & (0x40|0x80); - clxcon_bpl_match |= (v & (0x01|0x02)) << 6; + if (!(currprefs.chipset_mask & CSMASK_AGA)) + return; + clxcon2 = v; + clxcon_bpl_enable |= v & (0x40|0x80); + clxcon_bpl_match |= (v & (0x01|0x02)) << 6; } static uae_u16 CLXDAT (void) { - uae_u16 v = clxdat | 0x8000; - clxdat = 0; - return v; + uae_u16 v = clxdat | 0x8000; + clxdat = 0; + return v; } #ifdef AGA void dump_aga_custom (void) { - int c1, c2, c3, c4; - uae_u32 rgb1, rgb2, rgb3, rgb4; - - for (c1 = 0; c1 < 64; c1++) { - c2 = c1 + 64; - c3 = c2 + 64; - c4 = c3 + 64; - rgb1 = current_colors.color_regs_aga[c1] | (color_regs_aga_genlock[c1] << 31); - rgb2 = current_colors.color_regs_aga[c2] | (color_regs_aga_genlock[c2] << 31); - rgb3 = current_colors.color_regs_aga[c3] | (color_regs_aga_genlock[c3] << 31); - rgb4 = current_colors.color_regs_aga[c4] | (color_regs_aga_genlock[c4] << 31); - console_out_f (L"%3d %08X %3d %08X %3d %08X %3d %08X\n", - c1, rgb1, c2, rgb2, c3, rgb3, c4, rgb4); - } + int c1, c2, c3, c4; + uae_u32 rgb1, rgb2, rgb3, rgb4; + + for (c1 = 0; c1 < 64; c1++) { + c2 = c1 + 64; + c3 = c2 + 64; + c4 = c3 + 64; + rgb1 = current_colors.color_regs_aga[c1] | (color_regs_aga_genlock[c1] << 31); + rgb2 = current_colors.color_regs_aga[c2] | (color_regs_aga_genlock[c2] << 31); + rgb3 = current_colors.color_regs_aga[c3] | (color_regs_aga_genlock[c3] << 31); + rgb4 = current_colors.color_regs_aga[c4] | (color_regs_aga_genlock[c4] << 31); + console_out_f (L"%3d %08X %3d %08X %3d %08X %3d %08X\n", + c1, rgb1, c2, rgb2, c3, rgb3, c4, rgb4); + } } static uae_u16 COLOR_READ (int num) { - int cr, cg, cb, colreg; - uae_u16 cval; - - if (!(currprefs.chipset_mask & CSMASK_AGA) || !(bplcon2 & 0x0100)) - return 0xffff; - - colreg = ((bplcon3 >> 13) & 7) * 32 + num; - cr = current_colors.color_regs_aga[colreg] >> 16; - cg = (current_colors.color_regs_aga[colreg] >> 8) & 0xFF; - cb = current_colors.color_regs_aga[colreg] & 0xFF; - if (bplcon3 & 0x200) { - cval = ((cr & 15) << 8) | ((cg & 15) << 4) | ((cb & 15) << 0); - } else { - cval = ((cr >> 4) << 8) | ((cg >> 4) << 4) | ((cb >> 4) << 0); - if (color_regs_aga_genlock[num]) - cval |= 0x8000; - } - return cval; -} -#endif - -static void COLOR_WRITE (int hpos, uae_u16 v, int num) -{ - v &= 0xFFF; -#ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) { - int r,g,b; - int cr,cg,cb; - int colreg; - uae_u32 cval; + int cr, cg, cb, colreg; + uae_u16 cval; - /* writing is disabled when RDRAM=1 */ - if (bplcon2 & 0x0100) - return; + if (!(currprefs.chipset_mask & CSMASK_AGA) || !(bplcon2 & 0x0100)) + return 0xffff; colreg = ((bplcon3 >> 13) & 7) * 32 + num; - r = (v & 0xF00) >> 8; - g = (v & 0xF0) >> 4; - b = (v & 0xF) >> 0; cr = current_colors.color_regs_aga[colreg] >> 16; cg = (current_colors.color_regs_aga[colreg] >> 8) & 0xFF; cb = current_colors.color_regs_aga[colreg] & 0xFF; - if (bplcon3 & 0x200) { - cr &= 0xF0; cr |= r; - cg &= 0xF0; cg |= g; - cb &= 0xF0; cb |= b; + cval = ((cr & 15) << 8) | ((cg & 15) << 4) | ((cb & 15) << 0); } else { - cr = r + (r << 4); - cg = g + (g << 4); - cb = b + (b << 4); - color_regs_aga_genlock[colreg] = v >> 15; + cval = ((cr >> 4) << 8) | ((cg >> 4) << 4) | ((cb >> 4) << 0); + if (color_regs_aga_genlock[num]) + cval |= 0x8000; } - cval = (cr << 16) | (cg << 8) | cb; - if (cval == current_colors.color_regs_aga[colreg]) - return; + return cval; +} +#endif - /* Call this with the old table still intact. */ - record_color_change (hpos, colreg, cval); - remembered_color_entry = -1; - current_colors.color_regs_aga[colreg] = cval; - current_colors.acolors[colreg] = getxcolor (cval); - } else { -#endif - if (current_colors.color_regs_ecs[num] == v) - return; - /* Call this with the old table still intact. */ - record_color_change (hpos, num, v); - remembered_color_entry = -1; - current_colors.color_regs_ecs[num] = v; - current_colors.acolors[num] = getxcolor (v); +static void COLOR_WRITE (int hpos, uae_u16 v, int num) +{ + v &= 0xFFF; +#ifdef AGA + if (currprefs.chipset_mask & CSMASK_AGA) { + int r,g,b; + int cr,cg,cb; + int colreg; + uae_u32 cval; + + /* writing is disabled when RDRAM=1 */ + if (bplcon2 & 0x0100) + return; + + colreg = ((bplcon3 >> 13) & 7) * 32 + num; + r = (v & 0xF00) >> 8; + g = (v & 0xF0) >> 4; + b = (v & 0xF) >> 0; + cr = current_colors.color_regs_aga[colreg] >> 16; + cg = (current_colors.color_regs_aga[colreg] >> 8) & 0xFF; + cb = current_colors.color_regs_aga[colreg] & 0xFF; + + if (bplcon3 & 0x200) { + cr &= 0xF0; cr |= r; + cg &= 0xF0; cg |= g; + cb &= 0xF0; cb |= b; + } else { + cr = r + (r << 4); + cg = g + (g << 4); + cb = b + (b << 4); + color_regs_aga_genlock[colreg] = v >> 15; + } + cval = (cr << 16) | (cg << 8) | cb; + if (cval == current_colors.color_regs_aga[colreg]) + return; + + /* Call this with the old table still intact. */ + record_color_change (hpos, colreg, cval); + remembered_color_entry = -1; + current_colors.color_regs_aga[colreg] = cval; + current_colors.acolors[colreg] = getxcolor (cval); + } else { +#endif + if (current_colors.color_regs_ecs[num] == v) + return; + /* Call this with the old table still intact. */ + record_color_change (hpos, num, v); + remembered_color_entry = -1; + current_colors.color_regs_ecs[num] = v; + current_colors.acolors[num] = getxcolor (v); #ifdef AGA - } + } #endif } /* The copper code. The biggest nightmare in the whole emulator. - Alright. The current theory: - 1. Copper moves happen 2 cycles after state READ2 is reached. - It can't happen immediately when we reach READ2, because the - data needs time to get back from the bus. An additional 2 - cycles are needed for non-Agnus registers, to take into account - the delay for moving data from chip to chip. - 2. As stated in the HRM, a WAIT really does need an extra cycle - to wake up. This is implemented by _not_ falling through from - a successful wait to READ1, but by starting the next cycle. - (Note: the extra cycle for the WAIT apparently really needs a - free cycle; i.e. contention with the bitplane fetch can slow - it down). - 3. Apparently, to compensate for the extra wake up cycle, a WAIT - will use the _incremented_ horizontal position, so the WAIT - cycle normally finishes two clocks earlier than the position - it was waiting for. The extra cycle then takes us to the - position that was waited for. - If the earlier cycle is busy with a bitplane, things change a bit. - E.g., waiting for position 0x50 in a 6 plane display: In cycle - 0x4e, we fetch BPL5, so the wait wakes up in 0x50, the extra cycle - takes us to 0x54 (since 0x52 is busy), then we have READ1/READ2, - and the next register write is at 0x5c. - 4. The last cycle in a line is not usable for the copper. - 5. A 4 cycle delay also applies to the WAIT instruction. This means - that the second of two back-to-back WAITs (or a WAIT whose - condition is immediately true) takes 8 cycles. - 6. This also applies to a SKIP instruction. The copper does not - fetch the next instruction while waiting for the second word of - a WAIT or a SKIP to arrive. - 7. A SKIP also seems to need an unexplained additional two cycles - after its second word arrives; this is _not_ a memory cycle (I - think, the documentation is pretty clear on this). - 8. Two additional cycles are inserted when writing to COPJMP1/2. */ +Alright. The current theory: +1. Copper moves happen 2 cycles after state READ2 is reached. +It can't happen immediately when we reach READ2, because the +data needs time to get back from the bus. An additional 2 +cycles are needed for non-Agnus registers, to take into account +the delay for moving data from chip to chip. +2. As stated in the HRM, a WAIT really does need an extra cycle +to wake up. This is implemented by _not_ falling through from +a successful wait to READ1, but by starting the next cycle. +(Note: the extra cycle for the WAIT apparently really needs a +free cycle; i.e. contention with the bitplane fetch can slow +it down). +3. Apparently, to compensate for the extra wake up cycle, a WAIT +will use the _incremented_ horizontal position, so the WAIT +cycle normally finishes two clocks earlier than the position +it was waiting for. The extra cycle then takes us to the +position that was waited for. +If the earlier cycle is busy with a bitplane, things change a bit. +E.g., waiting for position 0x50 in a 6 plane display: In cycle +0x4e, we fetch BPL5, so the wait wakes up in 0x50, the extra cycle +takes us to 0x54 (since 0x52 is busy), then we have READ1/READ2, +and the next register write is at 0x5c. +4. The last cycle in a line is not usable for the copper. +5. A 4 cycle delay also applies to the WAIT instruction. This means +that the second of two back-to-back WAITs (or a WAIT whose +condition is immediately true) takes 8 cycles. +6. This also applies to a SKIP instruction. The copper does not +fetch the next instruction while waiting for the second word of +a WAIT or a SKIP to arrive. +7. A SKIP also seems to need an unexplained additional two cycles +after its second word arrives; this is _not_ a memory cycle (I +think, the documentation is pretty clear on this). +8. Two additional cycles are inserted when writing to COPJMP1/2. */ /* Determine which cycles are available for the copper in a display - * with a agiven number of planes. */ +* with a agiven number of planes. */ STATIC_INLINE int copper_cant_read (int hpos, int alloc) { - if (hpos + 1 >= maxhpos) // first refresh slot - return 1; - if ((hpos == maxhpos - 3) && (maxhpos & 1)) { - if (alloc) - alloc_cycle (hpos, CYCLE_COPPER); - return -1; - } - return is_bitplane_dma_inline (hpos); + if (hpos + 1 >= maxhpos) // first refresh slot + return 1; + if ((hpos == maxhpos - 3) && (maxhpos & 1)) { + if (alloc) + alloc_cycle (hpos, CYCLE_COPPER); + return -1; + } + return is_bitplane_dma_inline (hpos); } static int custom_wput_copper (int hpos, uaecptr addr, uae_u32 value, int noget) { - int v; + int v; - debug_wputpeek (0xdff000 + addr, value); - copper_access = 1; - v = custom_wput_1 (hpos, addr, value, noget); - copper_access = 0; - return v; + debug_wputpeek (0xdff000 + addr, value); + copper_access = 1; + v = custom_wput_1 (hpos, addr, value, noget); + copper_access = 0; + return v; } static void dump_copper (TCHAR *error, int until_hpos) { - write_log (L"%s: vpos=%d until_hpos=%d\n", - error, vpos, until_hpos); - write_log (L"cvcmp=%d chcmp=%d chpos=%d cvpos=%d ci1=%04X ci2=%04X\n", - cop_state.vcmp,cop_state.hcmp,cop_state.hpos,cop_state.vpos,cop_state.saved_i1,cop_state.saved_i2); - write_log (L"cstate=%d ip=%x SPCFLAGS=%x\n", - cop_state.state, cop_state.ip, regs.spcflags); + write_log (L"%s: vpos=%d until_hpos=%d\n", + error, vpos, until_hpos); + write_log (L"cvcmp=%d chcmp=%d chpos=%d cvpos=%d ci1=%04X ci2=%04X\n", + cop_state.vcmp,cop_state.hcmp,cop_state.hpos,cop_state.vpos,cop_state.saved_i1,cop_state.saved_i2); + write_log (L"cstate=%d ip=%x SPCFLAGS=%x\n", + cop_state.state, cop_state.ip, regs.spcflags); } // "emulate" chip internal delays, not the right place but fast and 99.9% programs // use only copper to write BPLCON1 etc.. (exception is HulkaMania/TSP..) // this table should be filled with zeros and done somewhere else.. static int customdelay[]= { - 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* 32 0x00 - 0x3e */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x40 - 0x5e */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x60 - 0x7e */ - 0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, /* 0x80 - 0x9e */ - 1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0, /* 32 0xa0 - 0xde */ - /* BPLxPTH/BPLxPTL */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 16 */ - /* BPLCON0-3,BPLMOD1-2 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 16 */ - /* SPRxPTH/SPRxPTL */ - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 16 */ - /* SPRxPOS/SPRxCTL/SPRxDATA/SPRxDATB */ - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - /* COLORxx */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - /* RESERVED */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* 32 0x00 - 0x3e */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x40 - 0x5e */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x60 - 0x7e */ + 0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, /* 0x80 - 0x9e */ + 1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0, /* 32 0xa0 - 0xde */ + /* BPLxPTH/BPLxPTL */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 16 */ + /* BPLCON0-3,BPLMOD1-2 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 16 */ + /* SPRxPTH/SPRxPTL */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 16 */ + /* SPRxPOS/SPRxCTL/SPRxDATA/SPRxDATB */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + /* COLORxx */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + /* RESERVED */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; static void update_copper (int until_hpos) { - int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); - int c_hpos = cop_state.hpos; - - if (nocustom ()) - return; + int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); + int c_hpos = cop_state.hpos; - if (cop_state.state == COP_wait && vp < cop_state.vcmp) { - dump_copper (L"error2", until_hpos); - copper_enabled_thisline = 0; - cop_state.state = COP_stop; - unset_special (SPCFLAG_COPPER); - return; - } + if (nocustom ()) + return; - if (until_hpos <= last_copper_hpos) - return; + if (cop_state.state == COP_wait && vp < cop_state.vcmp) { + dump_copper (L"error2", until_hpos); + copper_enabled_thisline = 0; + cop_state.state = COP_stop; + unset_special (SPCFLAG_COPPER); + return; + } - if (until_hpos > (maxhpos & ~1)) - until_hpos = maxhpos & ~1; + if (until_hpos <= last_copper_hpos) + return; - for (;;) { - int old_hpos = c_hpos; - int hp; + if (until_hpos > (maxhpos & ~1)) + until_hpos = maxhpos & ~1; - if (c_hpos >= until_hpos) - break; + for (;;) { + int old_hpos = c_hpos; + int hp; + if (c_hpos >= until_hpos) + break; - /* So we know about the fetch state. */ - decide_line (c_hpos); - decide_fetch (c_hpos); - if (cop_state.movedelay > 0) { - cop_state.movedelay--; - if (cop_state.movedelay == 0) { - custom_wput_copper (c_hpos, cop_state.moveaddr, cop_state.movedata, 0); - } - } -#if 0 - if (cop_state.movedelay100 > 0) { - cop_state.movedelay100--; - if (cop_state.movedelay100 == 1) { - // Denise reacts to BPLCON0 change a bit earlier than Agnus - BPLCON0_Denise (c_hpos, cop_state.movedata100); - } - if (cop_state.movedelay100 == 0) { + /* So we know about the fetch state. */ decide_line (c_hpos); decide_fetch (c_hpos); - custom_wput_copper (c_hpos, 0x100, cop_state.movedata100, 0); - } - } + + if (cop_state.movedelay > 0) { + cop_state.movedelay--; + if (cop_state.movedelay == 0) { + custom_wput_copper (c_hpos, cop_state.moveaddr, cop_state.movedata, 0); + } + } +#if 0 + if (cop_state.movedelay100 > 0) { + cop_state.movedelay100--; + if (cop_state.movedelay100 == 1) { + // Denise reacts to BPLCON0 change a bit earlier than Agnus + BPLCON0_Denise (c_hpos, cop_state.movedata100); + } + if (cop_state.movedelay100 == 0) { + decide_line (c_hpos); + decide_fetch (c_hpos); + custom_wput_copper (c_hpos, 0x100, cop_state.movedata100, 0); + } + } #endif - if ((c_hpos == maxhpos - 3) && (maxhpos & 1)) - c_hpos += 1; - else - c_hpos += 2; + if ((c_hpos == maxhpos - 3) && (maxhpos & 1)) + c_hpos += 1; + else + c_hpos += 2; - if (cop_state.strobe) { - if (cop_state.strobe > 0) - cop_state.ip = cop_state.strobe == 1 ? cop1lc : cop2lc; - cop_state.strobe = 0; - } + if (cop_state.strobe) { + if (cop_state.strobe > 0) + cop_state.ip = cop_state.strobe == 1 ? cop1lc : cop2lc; + cop_state.strobe = 0; + } - switch (cop_state.state) - { - case COP_wait_in2: - if (copper_cant_read (old_hpos, 0)) - continue; - cop_state.state = COP_wait1; - break; - case COP_skip_in2: - if (copper_cant_read (old_hpos, 0)) - continue; - cop_state.state = COP_skip1; - break; - case COP_strobe_delay1: - // first cycle after COPJMP is just like normal first read cycle - if (copper_cant_read (old_hpos, 1)) - continue; - cop_state.state = COP_strobe_delay2; - alloc_cycle (old_hpos, CYCLE_COPPER); + switch (cop_state.state) + { + case COP_wait_in2: + if (copper_cant_read (old_hpos, 0)) + continue; + cop_state.state = COP_wait1; + break; + case COP_skip_in2: + if (copper_cant_read (old_hpos, 0)) + continue; + cop_state.state = COP_skip1; + break; + case COP_strobe_delay1: + // first cycle after COPJMP is just like normal first read cycle + if (copper_cant_read (old_hpos, 1)) + continue; + cop_state.state = COP_strobe_delay2; + alloc_cycle (old_hpos, CYCLE_COPPER); #ifdef DEBUGGER - if (debug_dma) - record_dma (0x8c, chipmem_agnus_wget (cop_state.ip), cop_state.ip, old_hpos, vpos, DMARECORD_COPPER); -#endif - break; - case COP_strobe_delay2: - // second cycle after COPJMP is like second read cycle except - // there is 0x1FE as a target register - // (following word is still read normally and tossed away) - if (copper_cant_read (old_hpos, 1)) - continue; - cop_state.state = COP_read1; - alloc_cycle (old_hpos, CYCLE_COPPER); - if (debug_dma) - record_dma (0x1fe, chipmem_agnus_wget (cop_state.ip + 2), cop_state.ip + 2, old_hpos, vpos, DMARECORD_COPPER); - break; - case COP_start_delay: - if (copper_cant_read (old_hpos, 1)) - continue; - cop_state.state = COP_read1; - alloc_cycle (old_hpos, CYCLE_COPPER); - if (debug_dma) - record_dma (0x1fe, 0, 0xffffffff, old_hpos, vpos, DMARECORD_COPPER); - break; - - case COP_read1: - if (copper_cant_read (old_hpos, 1)) - continue; - cop_state.i1 = last_custom_value1 = chipmem_agnus_wget (cop_state.ip); - alloc_cycle (old_hpos, CYCLE_COPPER); + if (debug_dma) + record_dma (0x8c, chipmem_agnus_wget (cop_state.ip), cop_state.ip, old_hpos, vpos, DMARECORD_COPPER); +#endif + break; + case COP_strobe_delay2: + // second cycle after COPJMP is like second read cycle except + // there is 0x1FE as a target register + // (following word is still read normally and tossed away) + if (copper_cant_read (old_hpos, 1)) + continue; + cop_state.state = COP_read1; + alloc_cycle (old_hpos, CYCLE_COPPER); + if (debug_dma) + record_dma (0x1fe, chipmem_agnus_wget (cop_state.ip + 2), cop_state.ip + 2, old_hpos, vpos, DMARECORD_COPPER); + break; + case COP_start_delay: + if (copper_cant_read (old_hpos, 1)) + continue; + cop_state.state = COP_read1; + alloc_cycle (old_hpos, CYCLE_COPPER); + if (debug_dma) + record_dma (0x1fe, 0, 0xffffffff, old_hpos, vpos, DMARECORD_COPPER); + break; + + case COP_read1: + if (copper_cant_read (old_hpos, 1)) + continue; + cop_state.i1 = last_custom_value1 = chipmem_agnus_wget (cop_state.ip); + alloc_cycle (old_hpos, CYCLE_COPPER); #ifdef DEBUGGER - if (debug_dma) - record_dma (0x8c, cop_state.i1, cop_state.ip, old_hpos, vpos, DMARECORD_COPPER); -#endif - cop_state.ip += 2; - cop_state.state = COP_read2; - break; - - case COP_read2: - if (copper_cant_read (old_hpos, 1)) - continue; - cop_state.i2 = last_custom_value1 = chipmem_agnus_wget (cop_state.ip); - alloc_cycle (old_hpos, CYCLE_COPPER); - cop_state.ip += 2; - cop_state.saved_i1 = cop_state.i1; - cop_state.saved_i2 = cop_state.i2; - cop_state.saved_ip = cop_state.ip; - - if (cop_state.i1 & 1) { // WAIT or SKIP - cop_state.ignore_next = 0; - if (cop_state.i2 & 1) - cop_state.state = COP_skip_in2; - else - cop_state.state = COP_wait_in2; + if (debug_dma) + record_dma (0x8c, cop_state.i1, cop_state.ip, old_hpos, vpos, DMARECORD_COPPER); +#endif + cop_state.ip += 2; + cop_state.state = COP_read2; + break; + + case COP_read2: + if (copper_cant_read (old_hpos, 1)) + continue; + cop_state.i2 = last_custom_value1 = chipmem_agnus_wget (cop_state.ip); + alloc_cycle (old_hpos, CYCLE_COPPER); + cop_state.ip += 2; + cop_state.saved_i1 = cop_state.i1; + cop_state.saved_i2 = cop_state.i2; + cop_state.saved_ip = cop_state.ip; + + if (cop_state.i1 & 1) { // WAIT or SKIP + cop_state.ignore_next = 0; + if (cop_state.i2 & 1) + cop_state.state = COP_skip_in2; + else + cop_state.state = COP_wait_in2; #ifdef DEBUGGER - if (debug_dma) - record_dma (0x8c, cop_state.i2, cop_state.ip - 2, old_hpos, vpos, DMARECORD_COPPER); + if (debug_dma) + record_dma (0x8c, cop_state.i2, cop_state.ip - 2, old_hpos, vpos, DMARECORD_COPPER); #endif - } else { // MOVE - unsigned int reg = cop_state.i1 & 0x1FE; - uae_u16 data = cop_state.i2; - cop_state.state = COP_read1; + } else { // MOVE + unsigned int reg = cop_state.i1 & 0x1FE; + uae_u16 data = cop_state.i2; + cop_state.state = COP_read1; #ifdef DEBUGGER - if (debug_dma) - record_dma (reg, data, cop_state.ip - 2, old_hpos, vpos, DMARECORD_COPPER); -#endif - test_copper_dangerous (reg); - if (! copper_enabled_thisline) - goto out; // was "dangerous" register -> copper stopped - if (cop_state.ignore_next) { - reg = 0x1fe; - cop_state.ignore_next = 0; - } - - cop_state.last_write = reg; - cop_state.last_write_hpos = old_hpos; - if (reg == 0x88) { - cop_state.ip = cop1lc; - cop_state.state = COP_strobe_delay1; - } else if (reg == 0x8A) { - cop_state.ip = cop2lc; - cop_state.state = COP_strobe_delay1; - } else { - // FIX: all copper writes happen 1 cycle later than CPU writes - if (customdelay[reg / 2]) { - cop_state.moveaddr = reg; - cop_state.movedata = data; - cop_state.movedelay = customdelay[cop_state.moveaddr / 2]; - } else { - int hpos2 = old_hpos; - custom_wput_copper (hpos2, reg, data, 0); - hpos2++; - if (!nocustom () && reg >= 0x140 && reg < 0x180 && hpos2 >= SPR0_HPOS && hpos2 < SPR0_HPOS + 4 * MAX_SPRITES) { - do_sprites (hpos2); - } - } - } + if (debug_dma) + record_dma (reg, data, cop_state.ip - 2, old_hpos, vpos, DMARECORD_COPPER); +#endif + test_copper_dangerous (reg); + if (! copper_enabled_thisline) + goto out; // was "dangerous" register -> copper stopped + if (cop_state.ignore_next) { + reg = 0x1fe; + cop_state.ignore_next = 0; + } + + cop_state.last_write = reg; + cop_state.last_write_hpos = old_hpos; + if (reg == 0x88) { + cop_state.ip = cop1lc; + cop_state.state = COP_strobe_delay1; + } else if (reg == 0x8A) { + cop_state.ip = cop2lc; + cop_state.state = COP_strobe_delay1; + } else { + // FIX: all copper writes happen 1 cycle later than CPU writes + if (customdelay[reg / 2]) { + cop_state.moveaddr = reg; + cop_state.movedata = data; + cop_state.movedelay = customdelay[cop_state.moveaddr / 2]; + } else { + int hpos2 = old_hpos; + custom_wput_copper (hpos2, reg, data, 0); + hpos2++; + if (!nocustom () && reg >= 0x140 && reg < 0x180 && hpos2 >= SPR0_HPOS && hpos2 < SPR0_HPOS + 4 * MAX_SPRITES) { + do_sprites (hpos2); + } + } + } #ifdef DEBUGGER - if (debug_copper) - record_copper (cop_state.ip - 4, old_hpos, vpos); -#endif - } - break; - - case COP_wait1: - /* There's a nasty case here. As stated in the "Theory" comment above, we - test against the incremented copper position. I believe this means that - we have to increment the _vertical_ position at the last cycle in the line, - and set the horizontal position to 0. - Normally, this isn't going to make a difference, since we consider these - last cycles unavailable for the copper, so waking up in the last cycle has - the same effect as waking up at the start of the line. However, there is - one possible problem: If we're at 0xFFE0, any wait for an earlier position - must _not_ complete (since, in effect, the current position will be back - at 0/0). This can be seen in the Superfrog copper list. - Things get monstrously complicated if we try to handle this "properly" by - incrementing vpos and setting c_hpos to 0. Especially the various speedup - hacks really assume that vpos remains constant during one line. Hence, - this hack: defer the entire decision until the next line if necessary. */ - if (c_hpos >= (maxhpos & ~1)) - break; - - cop_state.state = COP_wait; - - cop_state.vcmp = (cop_state.saved_i1 & (cop_state.saved_i2 | 0x8000)) >> 8; - cop_state.hcmp = (cop_state.saved_i1 & cop_state.saved_i2 & 0xFE); - - vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); - - if (cop_state.saved_i1 == 0xFFFF && cop_state.saved_i2 == 0xFFFE) { - cop_state.state = COP_stop; - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); - goto out; - } - if (vp < cop_state.vcmp) { - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); - goto out; - } - - /* fall through */ - case COP_wait: - if (copper_cant_read (old_hpos, 0)) - continue; - - hp = c_hpos & (cop_state.saved_i2 & 0xFE); - if (vp == cop_state.vcmp && hp < cop_state.hcmp) - break; + if (debug_copper) + record_copper (cop_state.ip - 4, old_hpos, vpos); +#endif + } + break; + + case COP_wait1: + /* There's a nasty case here. As stated in the "Theory" comment above, we + test against the incremented copper position. I believe this means that + we have to increment the _vertical_ position at the last cycle in the line, + and set the horizontal position to 0. + Normally, this isn't going to make a difference, since we consider these + last cycles unavailable for the copper, so waking up in the last cycle has + the same effect as waking up at the start of the line. However, there is + one possible problem: If we're at 0xFFE0, any wait for an earlier position + must _not_ complete (since, in effect, the current position will be back + at 0/0). This can be seen in the Superfrog copper list. + Things get monstrously complicated if we try to handle this "properly" by + incrementing vpos and setting c_hpos to 0. Especially the various speedup + hacks really assume that vpos remains constant during one line. Hence, + this hack: defer the entire decision until the next line if necessary. */ + if (c_hpos >= (maxhpos & ~1)) + break; + + cop_state.state = COP_wait; + + cop_state.vcmp = (cop_state.saved_i1 & (cop_state.saved_i2 | 0x8000)) >> 8; + cop_state.hcmp = (cop_state.saved_i1 & cop_state.saved_i2 & 0xFE); + + vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); + + if (cop_state.saved_i1 == 0xFFFF && cop_state.saved_i2 == 0xFFFE) { + cop_state.state = COP_stop; + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + goto out; + } + if (vp < cop_state.vcmp) { + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + goto out; + } - /* Now we know that the comparisons were successful. We might still - have to wait for the blitter though. */ - if ((cop_state.saved_i2 & 0x8000) == 0) { - decide_blitter (old_hpos); - if (bltstate != BLT_done) { - /* We need to wait for the blitter. */ - cop_state.state = COP_bltwait; - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); - goto out; - } else { - if (debug_dma) - record_dma_event (DMA_EVENT_COPPERWAKE, old_hpos, vp); - } - } + /* fall through */ + case COP_wait: + if (copper_cant_read (old_hpos, 0)) + continue; + + hp = c_hpos & (cop_state.saved_i2 & 0xFE); + if (vp == cop_state.vcmp && hp < cop_state.hcmp) + break; + + /* Now we know that the comparisons were successful. We might still + have to wait for the blitter though. */ + if ((cop_state.saved_i2 & 0x8000) == 0) { + decide_blitter (old_hpos); + if (bltstate != BLT_done) { + /* We need to wait for the blitter. */ + cop_state.state = COP_bltwait; + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + goto out; + } else { + if (debug_dma) + record_dma_event (DMA_EVENT_COPPERWAKE, old_hpos, vp); + } + } #ifdef DEBUGGER - if (debug_copper) - record_copper (cop_state.ip - 4, old_hpos, vpos); + if (debug_copper) + record_copper (cop_state.ip - 4, old_hpos, vpos); #endif - cop_state.state = COP_read1; - break; + cop_state.state = COP_read1; + break; - case COP_skip1: - { - unsigned int vcmp, hcmp, vp1, hp1; + case COP_skip1: + { + unsigned int vcmp, hcmp, vp1, hp1; - if (c_hpos >= (maxhpos & ~1)) - break; - if (copper_cant_read (old_hpos, 0)) - continue; + if (c_hpos >= (maxhpos & ~1)) + break; + if (copper_cant_read (old_hpos, 0)) + continue; - vcmp = (cop_state.saved_i1 & (cop_state.saved_i2 | 0x8000)) >> 8; - hcmp = (cop_state.saved_i1 & cop_state.saved_i2 & 0xFE); - vp1 = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); - hp1 = c_hpos & (cop_state.saved_i2 & 0xFE); + vcmp = (cop_state.saved_i1 & (cop_state.saved_i2 | 0x8000)) >> 8; + hcmp = (cop_state.saved_i1 & cop_state.saved_i2 & 0xFE); + vp1 = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); + hp1 = c_hpos & (cop_state.saved_i2 & 0xFE); - if ((vp1 > vcmp || (vp1 == vcmp && hp1 >= hcmp)) && ((cop_state.saved_i2 & 0x8000) != 0 || bltstate == BLT_done)) - cop_state.ignore_next = 1; + if ((vp1 > vcmp || (vp1 == vcmp && hp1 >= hcmp)) && ((cop_state.saved_i2 & 0x8000) != 0 || bltstate == BLT_done)) + cop_state.ignore_next = 1; - cop_state.state = COP_read1; + cop_state.state = COP_read1; #ifdef DEBUGGER - if (debug_copper) - record_copper (cop_state.ip - 4, old_hpos, vpos); + if (debug_copper) + record_copper (cop_state.ip - 4, old_hpos, vpos); #endif - break; - } - default: - break; + break; + } + default: + break; + } } - } - out: - cop_state.hpos = c_hpos; - last_copper_hpos = until_hpos; +out: + cop_state.hpos = c_hpos; + last_copper_hpos = until_hpos; } static void compute_spcflag_copper (int hpos) { - int wasenabled = copper_enabled_thisline; + int wasenabled = copper_enabled_thisline; - copper_enabled_thisline = 0; - unset_special (SPCFLAG_COPPER); - if (!dmaen (DMA_COPPER) || cop_state.state == COP_stop || cop_state.state == COP_bltwait || nocustom ()) - return; + copper_enabled_thisline = 0; + unset_special (SPCFLAG_COPPER); + if (!dmaen (DMA_COPPER) || cop_state.state == COP_stop || cop_state.state == COP_bltwait || nocustom ()) + return; - if (cop_state.state == COP_wait) { - int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); + if (cop_state.state == COP_wait) { + int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); - if (vp < cop_state.vcmp) - return; - } - // do not use past cycles if starting for the first time in this line - // (write to DMACON for example) hpos+1 for long lines - if (!wasenabled && cop_state.hpos < hpos && hpos + 1 < maxhpos) { - hpos = (hpos + 2) & ~1; - if (hpos > (maxhpos & ~1)) - hpos = maxhpos & ~1; - cop_state.hpos = hpos; - } - copper_enabled_thisline = 1; - set_special (SPCFLAG_COPPER); + if (vp < cop_state.vcmp) + return; + } + // do not use past cycles if starting for the first time in this line + // (write to DMACON for example) hpos+1 for long lines + if (!wasenabled && cop_state.hpos < hpos && hpos + 1 < maxhpos) { + hpos = (hpos + 2) & ~1; + if (hpos > (maxhpos & ~1)) + hpos = maxhpos & ~1; + cop_state.hpos = hpos; + } + copper_enabled_thisline = 1; + set_special (SPCFLAG_COPPER); } /* - Copper writes to BLTSIZE: 3 blitter idle cycles, blitter normal cycle starts - (CPU write to BLTSIZE only have 2 idle cycles at start) +Copper writes to BLTSIZE: 3 blitter idle cycles, blitter normal cycle starts +(CPU write to BLTSIZE only have 2 idle cycles at start) - BFD=0 wait: 1 cycle (or 2 if hpos is not aligned) delay before wait ends +BFD=0 wait: 1 cycle (or 2 if hpos is not aligned) delay before wait ends */ void blitter_done_notify (int hpos) { - int vp = vpos; + int vp = vpos; - if (cop_state.state != COP_bltwait) - return; + if (cop_state.state != COP_bltwait) + return; - hpos += 3; - hpos &= ~1; - if (hpos >= maxhpos) { - hpos -= maxhpos; - vp++; - } - cop_state.hpos = hpos; - cop_state.vpos = vp; - cop_state.state = COP_read1; - if (debug_dma) - record_dma_event (DMA_EVENT_COPPERWAKE, hpos, vp); + hpos += 3; + hpos &= ~1; + if (hpos >= maxhpos) { + hpos -= maxhpos; + vp++; + } + cop_state.hpos = hpos; + cop_state.vpos = vp; + cop_state.state = COP_read1; + if (debug_dma) + record_dma_event (DMA_EVENT_COPPERWAKE, hpos, vp); - if (dmaen (DMA_COPPER) && vp == vpos) { - copper_enabled_thisline = 1; - set_special (SPCFLAG_COPPER); - } + if (dmaen (DMA_COPPER) && vp == vpos) { + copper_enabled_thisline = 1; + set_special (SPCFLAG_COPPER); + } } void do_copper (void) { - int hpos = current_hpos (); - update_copper (hpos); + int hpos = current_hpos (); + update_copper (hpos); } /* ADDR is the address that is going to be read/written; this access is - the reason why we want to update the copper. This function is also - used from hsync_handler to finish up the line; for this case, we check - hpos against maxhpos. */ +the reason why we want to update the copper. This function is also +used from hsync_handler to finish up the line; for this case, we check +hpos against maxhpos. */ STATIC_INLINE void sync_copper_with_cpu (int hpos, int do_schedule) { - /* Need to let the copper advance to the current position. */ - if (copper_enabled_thisline) - update_copper (hpos); + /* Need to let the copper advance to the current position. */ + if (copper_enabled_thisline) + update_copper (hpos); } static void cursorsprite (void) { - if (!dmaen (DMA_SPRITE) || first_planes_vpos == 0) - return; - sprite_0 = spr[0].pt; - sprite_0_height = spr[0].vstop - spr[0].vstart; - sprite_0_colors[0] = 0; - sprite_0_doubled = 0; - if (sprres == 0) - sprite_0_doubled = 1; - if (currprefs.chipset_mask & CSMASK_AGA) { - int sbasecol = ((bplcon4 >> 4) & 15) << 4; - sprite_0_colors[1] = current_colors.color_regs_aga[sbasecol + 1]; - sprite_0_colors[2] = current_colors.color_regs_aga[sbasecol + 2]; - sprite_0_colors[3] = current_colors.color_regs_aga[sbasecol + 3]; - } else { - sprite_0_colors[1] = xcolors[current_colors.color_regs_ecs[17]]; - sprite_0_colors[2] = xcolors[current_colors.color_regs_ecs[18]]; - sprite_0_colors[3] = xcolors[current_colors.color_regs_ecs[19]]; - } - sprite_0_width = sprite_width; - if (currprefs.input_tablet && currprefs.input_magic_mouse) { - if (currprefs.input_magic_mouse_cursor == MAGICMOUSE_HOST_ONLY && mousehack_alive ()) - magic_sprite_mask &= ~1; - else - magic_sprite_mask |= 1; - } + if (!dmaen (DMA_SPRITE) || first_planes_vpos == 0) + return; + sprite_0 = spr[0].pt; + sprite_0_height = spr[0].vstop - spr[0].vstart; + sprite_0_colors[0] = 0; + sprite_0_doubled = 0; + if (sprres == 0) + sprite_0_doubled = 1; + if (currprefs.chipset_mask & CSMASK_AGA) { + int sbasecol = ((bplcon4 >> 4) & 15) << 4; + sprite_0_colors[1] = current_colors.color_regs_aga[sbasecol + 1]; + sprite_0_colors[2] = current_colors.color_regs_aga[sbasecol + 2]; + sprite_0_colors[3] = current_colors.color_regs_aga[sbasecol + 3]; + } else { + sprite_0_colors[1] = xcolors[current_colors.color_regs_ecs[17]]; + sprite_0_colors[2] = xcolors[current_colors.color_regs_ecs[18]]; + sprite_0_colors[3] = xcolors[current_colors.color_regs_ecs[19]]; + } + sprite_0_width = sprite_width; + if (currprefs.input_tablet && currprefs.input_magic_mouse) { + if (currprefs.input_magic_mouse_cursor == MAGICMOUSE_HOST_ONLY && mousehack_alive ()) + magic_sprite_mask &= ~1; + else + magic_sprite_mask |= 1; + } } STATIC_INLINE uae_u16 sprite_fetch (struct sprite *s, int dma, int hpos, int cycle, int mode) { - uae_u16 data = last_custom_value1; - if (dma) { - data = last_custom_value1 = chipmem_agnus_wget (s->pt); - alloc_cycle (hpos, CYCLE_SPRITE); + uae_u16 data = last_custom_value1; + if (dma) { + data = last_custom_value1 = chipmem_agnus_wget (s->pt); + alloc_cycle (hpos, CYCLE_SPRITE); #ifdef DEBUGGER - if (debug_dma) - record_dma ((s - &spr[0]) * 2 + 0x120, data, s->pt, hpos, vpos, DMARECORD_SPRITE); + if (debug_dma) + record_dma ((s - &spr[0]) * 2 + 0x120, data, s->pt, hpos, vpos, DMARECORD_SPRITE); #endif - } - s->pt += 2; - return data; + } + s->pt += 2; + return data; } STATIC_INLINE uae_u16 sprite_fetch2 (struct sprite *s, int dma, int hpos, int cycle, int mode) { - uae_u16 data = last_custom_value1; - if (dma) { - data = last_custom_value1 = chipmem_agnus_wget (s->pt); - } - s->pt += 2; - return data; + uae_u16 data = last_custom_value1; + if (dma) { + data = last_custom_value1 = chipmem_agnus_wget (s->pt); + } + s->pt += 2; + return data; } STATIC_INLINE void do_sprites_1 (int num, int cycle, int hpos) { - struct sprite *s = &spr[num]; - int dma, posctl = 0; - uae_u16 data; - int isdma = dmaen (DMA_SPRITE); + struct sprite *s = &spr[num]; + int dma, posctl = 0; + uae_u16 data; + int isdma = dmaen (DMA_SPRITE); - if (isdma && vpos == sprite_vblank_endline) - spr_arm (num, 0); + if (isdma && vpos == sprite_vblank_endline) + spr_arm (num, 0); #ifdef AGA - if (isdma && s->dblscan && (fmode & 0x8000) && (vpos & 1) != (s->vstart & 1) && s->dmastate) { - spr_arm (num, 1); - return; - } + if (isdma && s->dblscan && (fmode & 0x8000) && (vpos & 1) != (s->vstart & 1) && s->dmastate) { + spr_arm (num, 1); + return; + } #endif #if SPRITE_DEBUG > 3 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) - write_log (L"%d:%d:slot%d:%d\n", vpos, hpos, num, cycle); + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) + write_log (L"%d:%d:slot%d:%d\n", vpos, hpos, num, cycle); #endif - if (vpos == s->vstart) { + if (vpos == s->vstart) { #if SPRITE_DEBUG > 0 - if (!s->dmastate && vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) - write_log (L"%d:%d:SPR%d START\n", vpos, hpos, num); -#endif - s->dmastate = 1; - if (num == 0 && cycle == 0) - cursorsprite (); - } - if (vpos == s->vstop || vpos == sprite_vblank_endline) { + if (!s->dmastate && vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) + write_log (L"%d:%d:SPR%d START\n", vpos, hpos, num); +#endif + s->dmastate = 1; + if (num == 0 && cycle == 0) + cursorsprite (); + } + if (vpos == s->vstop || vpos == sprite_vblank_endline) { #if SPRITE_DEBUG > 0 - if (s->dmastate && vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) - write_log (L"%d:%d:SPR%d STOP\n", vpos, hpos, num); + if (s->dmastate && vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) + write_log (L"%d:%d:SPR%d STOP\n", vpos, hpos, num); #endif - s->dmastate = 0; + s->dmastate = 0; #if 1 - if (vpos == s->vstop) { - spr_arm (num, 0); - //return; - } + if (vpos == s->vstop) { + spr_arm (num, 0); + //return; + } #endif - } + } - if (!isdma) - return; - if (cycle && !s->dmacycle) - return; /* Superfrog intro flashing bee fix */ + if (!isdma) + return; + if (cycle && !s->dmacycle) + return; /* Superfrog intro flashing bee fix */ - dma = hpos < plfstrt || diwstate != DIW_waiting_stop; - if (vpos == s->vstop || vpos == sprite_vblank_endline) { - s->dmastate = 0; - posctl = 1; - if (dma) { - data = sprite_fetch (s, dma, hpos, cycle, 0); - switch (sprite_width) - { - case 64: - sprite_fetch2 (s, dma, hpos, cycle, 0); - sprite_fetch2 (s, dma, hpos, cycle, 0); - case 32: - sprite_fetch2 (s, dma, hpos, cycle, 0); - break; - } - } else { - data = cycle == 0 ? sprpos[num] : sprctl[num]; - } + dma = hpos < plfstrt || diwstate != DIW_waiting_stop; + if (vpos == s->vstop || vpos == sprite_vblank_endline) { + s->dmastate = 0; + posctl = 1; + if (dma) { + data = sprite_fetch (s, dma, hpos, cycle, 0); + switch (sprite_width) + { + case 64: + sprite_fetch2 (s, dma, hpos, cycle, 0); + sprite_fetch2 (s, dma, hpos, cycle, 0); + case 32: + sprite_fetch2 (s, dma, hpos, cycle, 0); + break; + } + } else { + data = cycle == 0 ? sprpos[num] : sprctl[num]; + } #if SPRITE_DEBUG > 1 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:dma:P=%06X ", vpos, hpos, s->pt); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:dma:P=%06X ", vpos, hpos, s->pt); + } #endif - //write_log (L"%d:%d: %04X=%04X\n", vpos, hpos, 0x140 + cycle * 2 + num * 8, data); - if (cycle == 0) { - SPRxPOS_1 (data, num, hpos); - s->dmacycle = 1; - } else { - SPRxCTL_1 (data, num, hpos); - s->dmastate = 0; - sprstartstop (s); + //write_log (L"%d:%d: %04X=%04X\n", vpos, hpos, 0x140 + cycle * 2 + num * 8, data); + if (cycle == 0) { + SPRxPOS_1 (data, num, hpos); + s->dmacycle = 1; + } else { + SPRxCTL_1 (data, num, hpos); + s->dmastate = 0; + sprstartstop (s); + } } - } - if (s->dmastate && !posctl) { - uae_u16 data; + if (s->dmastate && !posctl) { + uae_u16 data; - data = sprite_fetch (s, dma, hpos, cycle, 1); + data = sprite_fetch (s, dma, hpos, cycle, 1); #if SPRITE_DEBUG > 1 - if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { - write_log (L"%d:%d:dma:P=%06X ", vpos, hpos, s->pt); - } + if (vpos >= SPRITE_DEBUG_MINY && vpos <= SPRITE_DEBUG_MAXY) { + write_log (L"%d:%d:dma:P=%06X ", vpos, hpos, s->pt); + } #endif - if (cycle == 0) { - SPRxDATA_1 (dma ? data : sprdata[num][0], num, hpos); - s->dmacycle = 1; - } else { - SPRxDATB_1 (dma ? data : sprdatb[num][0], num, hpos); - spr_arm (num, 1); - } -#ifdef AGA - switch (sprite_width) - { - case 64: - { - uae_u16 data32 = sprite_fetch2 (s, dma, hpos, cycle, 1); - uae_u16 data641 = sprite_fetch2 (s, dma, hpos, cycle, 1); - uae_u16 data642 = sprite_fetch2 (s, dma, hpos, cycle, 1); - if (dma) { - if (cycle == 0) { - sprdata[num][3] = data642; - sprdata[num][2] = data641; - sprdata[num][1] = data32; - } else { - sprdatb[num][3] = data642; - sprdatb[num][2] = data641; - sprdatb[num][1] = data32; - } + if (cycle == 0) { + SPRxDATA_1 (dma ? data : sprdata[num][0], num, hpos); + s->dmacycle = 1; + } else { + SPRxDATB_1 (dma ? data : sprdatb[num][0], num, hpos); + spr_arm (num, 1); } - } - break; - case 32: - { - uae_u16 data32 = sprite_fetch2 (s, dma, hpos, cycle, 1); - if (dma) { - if (cycle == 0) - sprdata[num][1] = data32; - else - sprdatb[num][1] = data32; +#ifdef AGA + switch (sprite_width) + { + case 64: + { + uae_u16 data32 = sprite_fetch2 (s, dma, hpos, cycle, 1); + uae_u16 data641 = sprite_fetch2 (s, dma, hpos, cycle, 1); + uae_u16 data642 = sprite_fetch2 (s, dma, hpos, cycle, 1); + if (dma) { + if (cycle == 0) { + sprdata[num][3] = data642; + sprdata[num][2] = data641; + sprdata[num][1] = data32; + } else { + sprdatb[num][3] = data642; + sprdatb[num][2] = data641; + sprdatb[num][1] = data32; + } + } + } + break; + case 32: + { + uae_u16 data32 = sprite_fetch2 (s, dma, hpos, cycle, 1); + if (dma) { + if (cycle == 0) + sprdata[num][1] = data32; + else + sprdatb[num][1] = data32; + } + } + break; } - } - break; - } #endif - } + } } static void do_sprites (int hpos) { - int maxspr, minspr; - int i; + int maxspr, minspr; + int i; - if (vpos < sprite_vblank_endline) - return; - if (doflickerfix () && interlace_seen && (next_lineno & 1)) - return; + if (vpos < sprite_vblank_endline) + return; + if (doflickerfix () && interlace_seen && (next_lineno & 1)) + return; #ifndef CUSTOM_SIMPLE - maxspr = hpos; - minspr = last_sprite_hpos + 1; + maxspr = hpos; + minspr = last_sprite_hpos + 1; - if (minspr >= SPR0_HPOS + MAX_SPRITES * 4 || maxspr < SPR0_HPOS) - return; + if (minspr >= SPR0_HPOS + MAX_SPRITES * 4 || maxspr < SPR0_HPOS) + return; - if (maxspr > SPR0_HPOS + MAX_SPRITES * 4) - maxspr = SPR0_HPOS + MAX_SPRITES * 4; - if (minspr < SPR0_HPOS) - minspr = SPR0_HPOS; + if (maxspr > SPR0_HPOS + MAX_SPRITES * 4) + maxspr = SPR0_HPOS + MAX_SPRITES * 4; + if (minspr < SPR0_HPOS) + minspr = SPR0_HPOS; + + for (i = minspr; i <= maxspr; i++) { + int cycle = -1; + int num = (i - SPR0_HPOS) / 4; + switch ((i - SPR0_HPOS) & 3) + { + case 0: + cycle = 0; + spr[num].dmacycle = 0; + break; + case 2: + cycle = 1; + break; + } + if (cycle >= 0 && num >= 0 && num < MAX_SPRITES) + do_sprites_1 (num, cycle, i); + } - for (i = minspr; i <= maxspr; i++) { - int cycle = -1; - int num = (i - SPR0_HPOS) / 4; - switch ((i - SPR0_HPOS) & 3) - { - case 0: - cycle = 0; - spr[num].dmacycle = 0; - break; - case 2: - cycle = 1; - break; - } - if (cycle >= 0 && num >= 0 && num < MAX_SPRITES) - do_sprites_1 (num, cycle, i); - } - - last_sprite_hpos = hpos; + last_sprite_hpos = hpos; #else - for (i = 0; i < MAX_SPRITES * 2; i++) { - spr[i / 2].dmacycle = 1; - do_sprites_1 (i / 2, i & 1, 0); - } + for (i = 0; i < MAX_SPRITES * 2; i++) { + spr[i / 2].dmacycle = 1; + do_sprites_1 (i / 2, i & 1, 0); + } #endif } static void init_sprites (void) { - memset (sprpos, 0, sizeof sprpos); - memset (sprctl, 0, sizeof sprctl); + memset (sprpos, 0, sizeof sprpos); + memset (sprctl, 0, sizeof sprctl); } /* - * On systems without virtual memory or with low memory, we allocate the - * sprite_entries and color_changes tables dynamically rather than having - * them declared static. We don't initially allocate at their maximum sizes; - * we start the tables off small and grow them as required. - * - * This function expands the tables if necessary. - */ +* On systems without virtual memory or with low memory, we allocate the +* sprite_entries and color_changes tables dynamically rather than having +* them declared static. We don't initially allocate at their maximum sizes; +* we start the tables off small and grow them as required. +* +* This function expands the tables if necessary. +*/ static void adjust_array_sizes (void) { #ifdef OS_WITHOUT_MEMORY_MANAGEMENT - if (delta_sprite_entry) { - void *p1; - void *p2; - int mcc = max_sprite_entry + 50 + delta_sprite_entry; + if (delta_sprite_entry) { + void *p1; + void *p2; + int mcc = max_sprite_entry + 50 + delta_sprite_entry; - delta_sprite_entry = 0; + delta_sprite_entry = 0; - p1 = realloc (sprite_entries[0], mcc * sizeof (struct sprite_entry)); - p2 = realloc (sprite_entries[1], mcc * sizeof (struct sprite_entry)); + p1 = realloc (sprite_entries[0], mcc * sizeof (struct sprite_entry)); + p2 = realloc (sprite_entries[1], mcc * sizeof (struct sprite_entry)); - if (p1 && p2) { - sprite_entries[0] = p1; - sprite_entries[1] = p2; + if (p1 && p2) { + sprite_entries[0] = p1; + sprite_entries[1] = p2; - memset (&sprite_entries[0][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0); - memset (&sprite_entries[1][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0); + memset (&sprite_entries[0][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0); + memset (&sprite_entries[1][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0); - write_log (L"New max_sprite_entry=%d\n", mcc); + write_log (L"New max_sprite_entry=%d\n", mcc); - max_sprite_entry = mcc; - } else - write_log (L"WARNING: Failed to enlarge sprite_entries table\n"); - } - if (delta_color_change) { - void *p1; - void *p2; - int mcc = max_color_change + 200 + delta_color_change; + max_sprite_entry = mcc; + } else + write_log (L"WARNING: Failed to enlarge sprite_entries table\n"); + } + if (delta_color_change) { + void *p1; + void *p2; + int mcc = max_color_change + 200 + delta_color_change; - delta_color_change = 0; + delta_color_change = 0; - p1 = realloc (color_changes[0], mcc * sizeof (struct color_change)); - p2 = realloc (color_changes[1], mcc * sizeof (struct color_change)); + p1 = realloc (color_changes[0], mcc * sizeof (struct color_change)); + p2 = realloc (color_changes[1], mcc * sizeof (struct color_change)); - if (p1 && p2) { - color_changes[0] = p1; - color_changes[1] = p2; + if (p1 && p2) { + color_changes[0] = p1; + color_changes[1] = p2; - write_log (L"New max_color_change=%d\n", mcc); + write_log (L"New max_color_change=%d\n", mcc); - max_color_change = mcc; - } else - write_log (L"WARNING: Failed to enlarge color_changes table\n"); - } + max_color_change = mcc; + } else + write_log (L"WARNING: Failed to enlarge color_changes table\n"); + } #endif } static void init_hardware_frame (void) { - first_bpl_vpos = -1; - next_lineno = 0; - prev_lineno = -1; - nextline_how = nln_normal; - diwstate = DIW_waiting_start; - hdiwstate = DIW_waiting_start; - ddfstate = DIW_waiting_start; - first_planes_vpos = 0; - last_planes_vpos = 0; - diwfirstword_total = max_diwlastword; - diwlastword_total = 0; - ddffirstword_total = max_diwlastword; - ddflastword_total = 0; - plflastline_total = 0; - plffirstline_total = maxvpos; + first_bpl_vpos = -1; + next_lineno = 0; + prev_lineno = -1; + nextline_how = nln_normal; + diwstate = DIW_waiting_start; + hdiwstate = DIW_waiting_start; + ddfstate = DIW_waiting_start; + first_planes_vpos = 0; + last_planes_vpos = 0; + diwfirstword_total = max_diwlastword; + diwlastword_total = 0; + ddffirstword_total = max_diwlastword; + ddflastword_total = 0; + plflastline_total = 0; + plffirstline_total = maxvpos; } void init_hardware_for_drawing_frame (void) { - /* Avoid this code in the first frame after a customreset. */ - if (prev_sprite_entries) { - int first_pixel = prev_sprite_entries[0].first_pixel; - int npixels = prev_sprite_entries[prev_next_sprite_entry].first_pixel - first_pixel; - memset (spixels + first_pixel, 0, npixels * sizeof *spixels); - memset (spixstate.bytes + first_pixel, 0, npixels * sizeof *spixstate.bytes); - } - prev_next_sprite_entry = next_sprite_entry; + /* Avoid this code in the first frame after a customreset. */ + if (prev_sprite_entries) { + int first_pixel = prev_sprite_entries[0].first_pixel; + int npixels = prev_sprite_entries[prev_next_sprite_entry].first_pixel - first_pixel; + memset (spixels + first_pixel, 0, npixels * sizeof *spixels); + memset (spixstate.bytes + first_pixel, 0, npixels * sizeof *spixstate.bytes); + } + prev_next_sprite_entry = next_sprite_entry; - next_color_change = 0; - next_sprite_entry = 0; - next_color_entry = 0; - remembered_color_entry = -1; + next_color_change = 0; + next_sprite_entry = 0; + next_color_entry = 0; + remembered_color_entry = -1; - adjust_array_sizes (); + adjust_array_sizes (); - prev_sprite_entries = sprite_entries[current_change_set]; - curr_sprite_entries = sprite_entries[current_change_set ^ 1]; - prev_color_changes = color_changes[current_change_set]; - curr_color_changes = color_changes[current_change_set ^ 1]; - prev_color_tables = color_tables[current_change_set]; - curr_color_tables = color_tables[current_change_set ^ 1]; + prev_sprite_entries = sprite_entries[current_change_set]; + curr_sprite_entries = sprite_entries[current_change_set ^ 1]; + prev_color_changes = color_changes[current_change_set]; + curr_color_changes = color_changes[current_change_set ^ 1]; + prev_color_tables = color_tables[current_change_set]; + curr_color_tables = color_tables[current_change_set ^ 1]; - prev_drawinfo = line_drawinfo[current_change_set]; - curr_drawinfo = line_drawinfo[current_change_set ^ 1]; - current_change_set ^= 1; + prev_drawinfo = line_drawinfo[current_change_set]; + curr_drawinfo = line_drawinfo[current_change_set ^ 1]; + current_change_set ^= 1; - color_src_match = color_dest_match = -1; + color_src_match = color_dest_match = -1; - /* Use both halves of the array in alternating fashion. */ - curr_sprite_entries[0].first_pixel = current_change_set * MAX_SPR_PIXELS; - next_sprite_forced = 1; + /* Use both halves of the array in alternating fashion. */ + curr_sprite_entries[0].first_pixel = current_change_set * MAX_SPR_PIXELS; + next_sprite_forced = 1; } static void do_savestate(void); static int rpt_vsync (void) { - int v = read_processor_time () - vsyncmintime; - if (v > (int)syncbase || v < -((int)syncbase)) { - vsyncmintime = read_processor_time (); - v = 0; - } - return v; + int v = read_processor_time () - vsyncmintime; + if (v > (int)syncbase || v < -((int)syncbase)) { + vsyncmintime = read_processor_time (); + v = 0; + } + return v; } static void framewait (void) { - frame_time_t curr_time; - frame_time_t start; - - if (isvsync ()) { - vsyncmintime = vsynctime; - return; - } - for (;;) { - double v = rpt_vsync () / (syncbase / 1000.0); - if (v >= -4) - break; - sleep_millis (2); - } - curr_time = start = read_processor_time (); - while (rpt_vsync () < 0); - curr_time = read_processor_time (); - vsyncmintime = curr_time + vsynctime; - idletime += read_processor_time() - start; + frame_time_t curr_time; + frame_time_t start; + + if (isvsync ()) { + vsyncmintime = vsynctime; + return; + } + for (;;) { + double v = rpt_vsync () / (syncbase / 1000.0); + if (v >= -4) + break; + sleep_millis (2); + } + curr_time = start = read_processor_time (); + while (rpt_vsync () < 0); + curr_time = read_processor_time (); + vsyncmintime = curr_time + vsynctime; + idletime += read_processor_time() - start; } static frame_time_t frametime2; void fpscounter_reset (void) { - timeframes = 0; - frametime2 = 0; - bogusframe = 2; - lastframetime = read_processor_time (); - idletime = 0; + timeframes = 0; + frametime2 = 0; + bogusframe = 2; + lastframetime = read_processor_time (); + idletime = 0; } static void fpscounter (void) { - frame_time_t now, last; - int mcnt = 10; - - now = read_processor_time (); - last = now - lastframetime; - lastframetime = now; - - if (bogusframe) - return; - - frametime += last; - frametime2 += last; - timeframes++; - if ((timeframes % mcnt) == 0) { - double idle = 1000 - (idletime == 0 ? 0.0 : (double)idletime * 1000.0 / (vsynctime * mcnt)); - int fps = frametime2 == 0 ? 0 : (syncbase * mcnt) / (frametime2 / 10); - if (fps > 9999) - fps = 9999; - if (idle < 0) - idle = 0; - if (idle > 100 * 10) - idle = 100 * 10; - if (fake_vblank_hz * 10 > fps) { - double mult = (double)fake_vblank_hz * 10.0 / fps; - idle *= mult; - } - if (currprefs.turbo_emulation && idle < 100 * 10) - idle = 100 * 10; - gui_fps (fps, (int)idle); - frametime2 = 0; - idletime = 0; - } + frame_time_t now, last; + int mcnt = 10; + + now = read_processor_time (); + last = now - lastframetime; + lastframetime = now; + + if (bogusframe) + return; + + frametime += last; + frametime2 += last; + timeframes++; + if ((timeframes % mcnt) == 0) { + double idle = 1000 - (idletime == 0 ? 0.0 : (double)idletime * 1000.0 / (vsynctime * mcnt)); + int fps = frametime2 == 0 ? 0 : (syncbase * mcnt) / (frametime2 / 10); + if (fps > 9999) + fps = 9999; + if (idle < 0) + idle = 0; + if (idle > 100 * 10) + idle = 100 * 10; + if (fake_vblank_hz * 10 > fps) { + double mult = (double)fake_vblank_hz * 10.0 / fps; + idle *= mult; + } + if (currprefs.turbo_emulation && idle < 100 * 10) + idle = 100 * 10; + gui_fps (fps, (int)idle); + frametime2 = 0; + idletime = 0; + } } static void vsync_handler (void) { - fpscounter (); + fpscounter (); - if (!isvsync () + if (!isvsync () #ifdef AVIOUTPUT - && ((avioutput_framelimiter && avioutput_enabled) || !avioutput_enabled) + && ((avioutput_framelimiter && avioutput_enabled) || !avioutput_enabled) #endif - ) { + ) { #ifdef JIT - if (!compiled_code) { -#endif - if (currprefs.m68k_speed == -1) { - frame_time_t curr_time = read_processor_time (); - vsyncmintime += vsynctime; - /* @@@ Mathias? How do you think we should do this? */ - /* If we are too far behind, or we just did a reset, adjust the - * needed time. */ - if ((long int)(curr_time - vsyncmintime) > 0 || rpt_did_reset) - vsyncmintime = curr_time + vsynctime; - rpt_did_reset = 0; - } else if (rpt_available) { - framewait (); - } + if (!compiled_code) { +#endif + if (currprefs.m68k_speed == -1) { + frame_time_t curr_time = read_processor_time (); + vsyncmintime += vsynctime; + /* @@@ Mathias? How do you think we should do this? */ + /* If we are too far behind, or we just did a reset, adjust the + * needed time. */ + if ((long int)(curr_time - vsyncmintime) > 0 || rpt_did_reset) + vsyncmintime = curr_time + vsynctime; + rpt_did_reset = 0; + } else if (rpt_available) { + framewait (); + } #ifdef JIT + } else { + if (rpt_available && currprefs.m68k_speed == 0) { + framewait (); + } + } +#endif } else { - if (rpt_available && currprefs.m68k_speed == 0) { framewait (); - } } -#endif - } else { - framewait (); - } - if (bogusframe > 0) - bogusframe--; + if (bogusframe > 0) + bogusframe--; - handle_events (); + handle_events (); - INTREQ (0x8000 | 0x0020); - if (bplcon0 & 4) - lof ^= 1; + INTREQ (0x8000 | 0x0020); + if (bplcon0 & 4) + lof ^= 1; #ifdef PICASSO96 - picasso_handle_vsync (); + picasso_handle_vsync (); #endif - audio_vsync (); + audio_vsync (); - if (quit_program > 0) { - /* prevent possible infinite loop at wait_cycles().. */ - framecnt = 0; - reset_decisions (); - return; - } + if (quit_program > 0) { + /* prevent possible infinite loop at wait_cycles().. */ + framecnt = 0; + reset_decisions (); + return; + } - { - static int cnt = 0; - if (cnt == 0) { - /* resolution_check_change (); */ - DISK_check_change (); - cnt = 5; + { + static int cnt = 0; + if (cnt == 0) { + /* resolution_check_change (); */ + DISK_check_change (); + cnt = 5; + } + cnt--; } - cnt--; - } - - if (debug_copper) - record_copper_reset (); - if (debug_dma) - record_dma_reset (); - - vsync_handle_redraw (lof, lof_changed); - - /* For now, let's only allow this to change at vsync time. It gets too - * hairy otherwise. */ - if (hack_vpos2) { - hack_vpos = hack_vpos2vpos + 1; - if (hack_vpos2 < maxvpos) - hack_vpos += maxvpos - hack_vpos2; - if (hack_vpos > maxvpos) - hack_vpos = maxvpos; - if (hack_vpos < 10) - hack_vpos = 10; - hack_vpos2 = 0; - } - if ((beamcon0 & (0x20|0x80)) != (new_beamcon0 & (0x20|0x80)) || hack_vpos) - init_hz (); - lof_changed = 0; + if (debug_copper) + record_copper_reset (); + if (debug_dma) + record_dma_reset (); + + vsync_handle_redraw (lof, lof_changed); + + /* For now, let's only allow this to change at vsync time. It gets too + * hairy otherwise. */ + if (hack_vpos2) { + hack_vpos = hack_vpos2vpos + 1; + if (hack_vpos2 < maxvpos) + hack_vpos += maxvpos - hack_vpos2; + if (hack_vpos > maxvpos) + hack_vpos = maxvpos; + if (hack_vpos < 10) + hack_vpos = 10; + hack_vpos2 = 0; + } + if ((beamcon0 & (0x20|0x80)) != (new_beamcon0 & (0x20|0x80)) || hack_vpos) + init_hz (); - COPJMP (1, 1); + lof_changed = 0; + + COPJMP (1, 1); - if (timehack_alive > 0) - timehack_alive--; - inputdevice_vsync (); - filesys_vsync (); + if (timehack_alive > 0) + timehack_alive--; + inputdevice_vsync (); + filesys_vsync (); - init_hardware_frame (); + init_hardware_frame (); } @@ -4933,65 +4944,65 @@ static void vsync_handler (void) STATIC_INLINE int trigger_frh (int v) { - return (v & (N_LINES - 1)) == 0; + return (v & (N_LINES - 1)) == 0; } static long int diff32 (frame_time_t x, frame_time_t y) { - return (long int)(x - y); + return (long int)(x - y); } static void frh_handler (void) { - if (currprefs.m68k_speed == -1) { - frame_time_t curr_time = read_processor_time (); - vsyncmintime += vsynctime * N_LINES / maxvpos; - /* @@@ Mathias? How do you think we should do this? */ - /* If we are too far behind, or we just did a reset, adjust the - * needed time. */ - if (rpt_did_reset) { - vsyncmintime = curr_time + vsynctime; - rpt_did_reset = 0; - } - /* Allow this to be one frame's worth of cycles out */ - while (diff32 (curr_time, vsyncmintime + vsynctime) > 0) { - vsyncmintime += vsynctime * N_LINES / maxvpos; - if (currprefs.turbo_emulation) - break; + if (currprefs.m68k_speed == -1) { + frame_time_t curr_time = read_processor_time (); + vsyncmintime += vsynctime * N_LINES / maxvpos; + /* @@@ Mathias? How do you think we should do this? */ + /* If we are too far behind, or we just did a reset, adjust the + * needed time. */ + if (rpt_did_reset) { + vsyncmintime = curr_time + vsynctime; + rpt_did_reset = 0; + } + /* Allow this to be one frame's worth of cycles out */ + while (diff32 (curr_time, vsyncmintime + vsynctime) > 0) { + vsyncmintime += vsynctime * N_LINES / maxvpos; + if (currprefs.turbo_emulation) + break; + } } - } } #endif static void copper_check (int n) { - if (cop_state.state == COP_wait) { - int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); - if (vp < cop_state.vcmp) { - if (copper_enabled_thisline) - write_log (L"COPPER BUG %d: vp=%d vpos=%d vcmp=%d act=%d thisline=%d\n", n, vp, vpos, cop_state.vcmp, copper_enabled_thisline); + if (cop_state.state == COP_wait) { + int vp = vpos & (((cop_state.saved_i2 >> 8) & 0x7F) | 0x80); + if (vp < cop_state.vcmp) { + if (copper_enabled_thisline) + write_log (L"COPPER BUG %d: vp=%d vpos=%d vcmp=%d act=%d thisline=%d\n", n, vp, vpos, cop_state.vcmp, copper_enabled_thisline); + } } - } } static void CIA_vsync_prehandler (int dotod) { - CIA_vsync_handler (dotod); + CIA_vsync_handler (dotod); #if 0 - if (input_recording > 0) { - inprec_rstart(INPREC_CIAVSYNC); - inprec_ru32(ciavsync_counter); - inprec_rend(); - } else if (input_recording < 0) { - uae_u32 v = -1; - while (inprec_pstart(INPREC_CIAVSYNC)) { - v = inprec_pu32(); - inprec_pend(); + if (input_recording > 0) { + inprec_rstart(INPREC_CIAVSYNC); + inprec_ru32(ciavsync_counter); + inprec_rend(); + } else if (input_recording < 0) { + uae_u32 v = -1; + while (inprec_pstart(INPREC_CIAVSYNC)) { + v = inprec_pu32(); + inprec_pend(); + } + if (v != ciavsync_counter) + write_log (L"INPREC: ciavsync sync error %d <> %d\n", v, ciavsync_counter); } - if (v != ciavsync_counter) - write_log (L"INPREC: ciavsync sync error %d <> %d\n", v, ciavsync_counter); - } #endif - ciavsync_counter++; + ciavsync_counter++; } /* @@ -5014,760 +5025,758 @@ static void CIA_vsync_prehandler (int dotod) static void hsync_scandoubler (void) { - int i, idx1; - struct draw_info *dip1; - uaecptr bpltmp[8], bpltmpx[8]; - - next_lineno++; - scandoubled_line = 1; - debug_dma = 0; - - for (i = 0; i < 8; i++) { - int diff; - bpltmp[i] = bplpt[i]; - bpltmpx[i] = bplptx[i]; - if (prevbpl[lof][vpos][i] && prevbpl[1 - lof][vpos][i]) { - diff = prevbpl[lof][vpos][i] - prevbpl[1 - lof][vpos][i]; - if (lof) { - if (bplcon0 & 4) - bplpt[i] = prevbpl[lof][vpos][i] - diff; - } else { - if (bplcon0 & 4) - bplpt[i] = prevbpl[lof][vpos][i]; - else - bplpt[i] = bplpt[i] - diff; - - } - } - } - - reset_decisions (); - plf_state = plf_idle; - - // copy color changes - dip1 = curr_drawinfo + next_lineno - 1; - for (idx1 = dip1->first_color_change; idx1 < dip1->last_color_change; idx1++) { - struct color_change *cs2 = &curr_color_changes[idx1]; - int regno = cs2->regno; - int hpos = cs2->linepos; - if (regno < 0x1000 && hpos < HBLANK_OFFSET && !(beamcon0 & 0x80) && prev_lineno >= 0) { - struct draw_info *pdip = curr_drawinfo + next_lineno - 1; - int idx = pdip->last_color_change; - pdip->last_color_change++; - pdip->nr_color_changes++; - curr_color_changes[idx].linepos = hpos + maxhpos + 1; - curr_color_changes[idx].regno = regno; - curr_color_changes[idx].value = cs2->value; - curr_color_changes[idx + 1].regno = -1; - } else { - struct color_change *cs1 = &curr_color_changes[next_color_change]; - memcpy (cs1, cs2, sizeof (struct color_change)); - next_color_change++; + int i, idx1; + struct draw_info *dip1; + uaecptr bpltmp[8], bpltmpx[8]; + + next_lineno++; + scandoubled_line = 1; + debug_dma = 0; + + for (i = 0; i < 8; i++) { + int diff; + bpltmp[i] = bplpt[i]; + bpltmpx[i] = bplptx[i]; + if (prevbpl[lof][vpos][i] && prevbpl[1 - lof][vpos][i]) { + diff = prevbpl[lof][vpos][i] - prevbpl[1 - lof][vpos][i]; + if (lof) { + if (bplcon0 & 4) + bplpt[i] = prevbpl[lof][vpos][i] - diff; + } else { + if (bplcon0 & 4) + bplpt[i] = prevbpl[lof][vpos][i]; + else + bplpt[i] = bplpt[i] - diff; + + } + } + } + + reset_decisions (); + plf_state = plf_idle; + + // copy color changes + dip1 = curr_drawinfo + next_lineno - 1; + for (idx1 = dip1->first_color_change; idx1 < dip1->last_color_change; idx1++) { + struct color_change *cs2 = &curr_color_changes[idx1]; + int regno = cs2->regno; + int hpos = cs2->linepos; + if (regno < 0x1000 && hpos < HBLANK_OFFSET && !(beamcon0 & 0x80) && prev_lineno >= 0) { + struct draw_info *pdip = curr_drawinfo + next_lineno - 1; + int idx = pdip->last_color_change; + pdip->last_color_change++; + pdip->nr_color_changes++; + curr_color_changes[idx].linepos = hpos + maxhpos + 1; + curr_color_changes[idx].regno = regno; + curr_color_changes[idx].value = cs2->value; + curr_color_changes[idx + 1].regno = -1; + } else { + struct color_change *cs1 = &curr_color_changes[next_color_change]; + memcpy (cs1, cs2, sizeof (struct color_change)); + next_color_change++; + } } - } - curr_color_changes[next_color_change].regno = -1; + curr_color_changes[next_color_change].regno = -1; - finish_decisions (); - hsync_record_line_state (next_lineno, nln_normal, thisline_changed); - hardware_line_completed (next_lineno); - scandoubled_line = 0; + finish_decisions (); + hsync_record_line_state (next_lineno, nln_normal, thisline_changed); + hardware_line_completed (next_lineno); + scandoubled_line = 0; - for (i = 0; i < 8; i++) { - bplpt[i] = bpltmp[i]; - bplptx[i] = bpltmpx[i]; - } + for (i = 0; i < 8; i++) { + bplpt[i] = bpltmp[i]; + bplptx[i] = bpltmpx[i]; + } } static void hsync_handler (void) { - int hpos = current_hpos (); - - if (!nocustom ()) { - sync_copper_with_cpu (maxhpos, 0); - last_copper_hpos = 0; - finish_decisions (); - if (thisline_decision.plfleft != -1) { - if (currprefs.collision_level > 1) - do_sprite_collisions (); - if (currprefs.collision_level > 2) - do_playfield_collisions (); - } - hsync_record_line_state (next_lineno, nextline_how, thisline_changed); - /* reset light pen latch */ - if (vpos == sprite_vblank_endline) { - lightpen_triggered = 0; - sprite_0 = 0; - } - if (lightpen_cx > 0 && (bplcon0 & 8) && !lightpen_triggered && lightpen_cy == vpos) { - vpos_lpen = vpos; - hpos_lpen = lightpen_cx; - lightpen_triggered = 1; - } - } + int hpos = current_hpos (); + + if (!nocustom ()) { + sync_copper_with_cpu (maxhpos, 0); + last_copper_hpos = 0; + finish_decisions (); + if (thisline_decision.plfleft != -1) { + if (currprefs.collision_level > 1) + do_sprite_collisions (); + if (currprefs.collision_level > 2) + do_playfield_collisions (); + } + hsync_record_line_state (next_lineno, nextline_how, thisline_changed); + /* reset light pen latch */ + if (vpos == sprite_vblank_endline) { + lightpen_triggered = 0; + sprite_0 = 0; + } + if (lightpen_cx > 0 && (bplcon0 & 8) && !lightpen_triggered && lightpen_cy == vpos) { + vpos_lpen = vpos; + hpos_lpen = lightpen_cx; + lightpen_triggered = 1; + } + } #ifdef A2065 - a2065_hsync_handler (); + a2065_hsync_handler (); #endif #ifdef CD32 - AKIKO_hsync_handler (); + AKIKO_hsync_handler (); #endif #ifdef CDTV - CDTV_hsync_handler (); + CDTV_hsync_handler (); #endif #ifdef CPUEMU_12 - if (currprefs.cpu_cycle_exact || currprefs.blitter_cycle_exact) { - decide_blitter (-1); - memset (cycle_line, 0, sizeof cycle_line); - } + if (currprefs.cpu_cycle_exact || currprefs.blitter_cycle_exact) { + decide_blitter (-1); + memset (cycle_line, 0, sizeof cycle_line); + } #endif - if (!(beamcon0 & 0x0800) && !(beamcon0 & 0x0020) && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) { - lol ^= 1; // NTSC and !LOLDIS -> LOL toggles every line - } else if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS) && currprefs.ntscmode) { - lol ^= 1; - } - maxhpos = maxhpos_short + lol; - eventtab[ev_hsync].evtime = get_cycles () + HSYNCTIME; - eventtab[ev_hsync].oldcycles = get_cycles (); + if (islinetoggle ()) + lol ^= 1; - CIA_hsync_handler (!(bplcon0 & 2) || ((bplcon0 & 2) && currprefs.genlock)); - if (currprefs.cs_ciaatod > 0) { - static int cia_hsync; - cia_hsync -= 256; - if (cia_hsync <= 0) { - CIA_vsync_prehandler (1); - cia_hsync += ((MAXVPOS_PAL * MAXHPOS_PAL * 50 * 256) / (maxhpos * (currprefs.cs_ciaatod == 2 ? 60 : 50))); + maxhpos = maxhpos_short + lol; + eventtab[ev_hsync].evtime = get_cycles () + HSYNCTIME; + eventtab[ev_hsync].oldcycles = get_cycles (); + + CIA_hsync_handler (!(bplcon0 & 2) || ((bplcon0 & 2) && currprefs.genlock)); + if (currprefs.cs_ciaatod > 0) { + static int cia_hsync; + cia_hsync -= 256; + if (cia_hsync <= 0) { + CIA_vsync_prehandler (1); + cia_hsync += ((MAXVPOS_PAL * MAXHPOS_PAL * 50 * 256) / (maxhpos * (currprefs.cs_ciaatod == 2 ? 60 : 50))); + } } - } #ifdef PICASSO96 - picasso_handle_hsync (); + picasso_handle_hsync (); #endif - { - void ahi_hsync (void); - ahi_hsync (); - } + { + void ahi_hsync (void); + ahi_hsync (); + } - last_custom_value1 = 0xffff; // refresh slots should set this to 0xffff + last_custom_value1 = 0xffff; // refresh slots should set this to 0xffff - if (!nocustom()) { - if (!currprefs.blitter_cycle_exact && bltstate != BLT_done && dmaen (DMA_BITPLANE) && diwstate == DIW_waiting_stop) { - blitter_slowdown (thisline_decision.plfleft, thisline_decision.plfright - (16 << fetchmode), - cycle_diagram_total_cycles[fetchmode][GET_RES_AGNUS (bplcon0)][GET_PLANES_LIMIT (bplcon0)], - cycle_diagram_free_cycles[fetchmode][GET_RES_AGNUS (bplcon0)][GET_PLANES_LIMIT (bplcon0)]); - } - hardware_line_completed (next_lineno); - if (doflickerfix () && interlace_seen) - hsync_scandoubler (); - } - - /* In theory only an equality test is needed here - but if a program - goes haywire with the VPOSW register, it can cause us to miss this, - with vpos going into the thousands (and all the nasty consequences - this has). */ - if (++vpos >= maxvpos + lof) { - if ((bplcon0 & 8) && !lightpen_triggered) { - vpos_lpen = vpos - 1; - hpos_lpen = maxhpos; - lightpen_triggered = 1; + if (!nocustom()) { + if (!currprefs.blitter_cycle_exact && bltstate != BLT_done && dmaen (DMA_BITPLANE) && diwstate == DIW_waiting_stop) { + blitter_slowdown (thisline_decision.plfleft, thisline_decision.plfright - (16 << fetchmode), + cycle_diagram_total_cycles[fetchmode][GET_RES_AGNUS (bplcon0)][GET_PLANES_LIMIT (bplcon0)], + cycle_diagram_free_cycles[fetchmode][GET_RES_AGNUS (bplcon0)][GET_PLANES_LIMIT (bplcon0)]); + } + hardware_line_completed (next_lineno); + if (doflickerfix () && interlace_seen) + hsync_scandoubler (); } - vpos = 0; - vsync_handler (); + + /* In theory only an equality test is needed here - but if a program + goes haywire with the VPOSW register, it can cause us to miss this, + with vpos going into the thousands (and all the nasty consequences + this has). */ + if (++vpos >= maxvpos + lof) { + if ((bplcon0 & 8) && !lightpen_triggered) { + vpos_lpen = vpos - 1; + hpos_lpen = maxhpos; + lightpen_triggered = 1; + } + vpos = 0; + vsync_handler (); #if 0 - if (input_recording > 0) { - inprec_rstart (INPREC_VSYNC); - inprec_ru32 (vsync_counter); - inprec_rend (); - } else if (input_recording < 0) { - uae_u32 v = -1; - while (inprec_pstart(INPREC_VSYNC)) { - v = inprec_pu32(); - inprec_pend(); - } - if (v != vsync_counter) - write_log (L"INPREC: vsync sync error %d <> %d\n", v, vsync_counter); - } + if (input_recording > 0) { + inprec_rstart (INPREC_VSYNC); + inprec_ru32 (vsync_counter); + inprec_rend (); + } else if (input_recording < 0) { + uae_u32 v = -1; + while (inprec_pstart(INPREC_VSYNC)) { + v = inprec_pu32(); + inprec_pend(); + } + if (v != vsync_counter) + write_log (L"INPREC: vsync sync error %d <> %d\n", v, vsync_counter); + } #endif - vsync_counter++; - if (currprefs.cs_ciaatod == 0) - CIA_vsync_prehandler (!(bplcon0 & 2) || ((bplcon0 & 2) && currprefs.genlock)); - } + vsync_counter++; + if (currprefs.cs_ciaatod == 0) + CIA_vsync_prehandler (!(bplcon0 & 2) || ((bplcon0 & 2) && currprefs.genlock)); + } #ifdef CPUEMU_12 - if (currprefs.cpu_cycle_exact || currprefs.blitter_cycle_exact) { - int hp = maxhpos - 1, i; - for (i = 0; i < 4; i++) { - alloc_cycle (hp, i == 0 ? CYCLE_STROBE : CYCLE_REFRESH); /* strobe */ + if (currprefs.cpu_cycle_exact || currprefs.blitter_cycle_exact) { + int hp = maxhpos - 1, i; + for (i = 0; i < 4; i++) { + alloc_cycle (hp, i == 0 ? CYCLE_STROBE : CYCLE_REFRESH); /* strobe */ #ifdef DEBUGGER - if (debug_dma) - record_dma (i == 0 ? (vpos + 1 == maxvpos + lof ? 0x38 : 0x3c) : 0x1fe, 0xffff, 0xffffffff, hp, vpos, DMARECORD_REFRESH); + if (debug_dma) + record_dma (i == 0 ? (vpos + 1 == maxvpos + lof ? 0x38 : 0x3c) : 0x1fe, 0xffff, 0xffffffff, hp, vpos, DMARECORD_REFRESH); #endif - hp += 2; - if (hp >= maxhpos) - hp -= maxhpos; + hp += 2; + if (hp >= maxhpos) + hp -= maxhpos; + } } - } #endif - DISK_hsync (maxhpos); - if (currprefs.produce_sound) - audio_hsync (-1); + DISK_hsync (maxhpos); + if (currprefs.produce_sound) + audio_hsync (-1); #ifdef JIT - if (compiled_code) { - if (currprefs.m68k_speed == -1) { - static int count = 0; - count++; - if (trigger_frh (count)) { - frh_handler (); - } - is_lastline = trigger_frh (count + 1) && ! rpt_did_reset; + if (compiled_code) { + if (currprefs.m68k_speed == -1) { + static int count = 0; + count++; + if (trigger_frh (count)) { + frh_handler (); + } + is_lastline = trigger_frh (count + 1) && ! rpt_did_reset; + } else { + is_lastline = 0; + } } else { - is_lastline = 0; - } - } else { #endif - is_lastline = vpos + 1 == maxvpos + lof && currprefs.m68k_speed == -1; + is_lastline = vpos + 1 == maxvpos + lof && currprefs.m68k_speed == -1; #ifdef JIT - } + } #endif - if (!nocustom ()) { - int lineno = vpos; - if ((bplcon0 & 4) && currprefs.gfx_linedbl) - notice_interlace_seen (); - nextline_how = nln_normal; - if (doflickerfix () && interlace_seen) { - lineno *= 2; - } else if (currprefs.gfx_linedbl && (doublescan <= 0 || interlace_seen > 0)) { - lineno *= 2; - nextline_how = currprefs.gfx_linedbl == 1 ? nln_doubled : nln_nblack; - if ((bplcon0 & 4) || (interlace_seen > 0 && !lof)) { - if (!lof) { - lineno++; - nextline_how = nln_lower; - } else { - nextline_how = nln_upper; + if (!nocustom ()) { + int lineno = vpos; + if ((bplcon0 & 4) && currprefs.gfx_linedbl) + notice_interlace_seen (); + nextline_how = nln_normal; + if (doflickerfix () && interlace_seen) { + lineno *= 2; + } else if (currprefs.gfx_linedbl && (doublescan <= 0 || interlace_seen > 0)) { + lineno *= 2; + nextline_how = currprefs.gfx_linedbl == 1 ? nln_doubled : nln_nblack; + if ((bplcon0 & 4) || (interlace_seen > 0 && !lof)) { + if (!lof) { + lineno++; + nextline_how = nln_lower; + } else { + nextline_how = nln_upper; + } + } } - } + prev_lineno = next_lineno; + next_lineno = lineno; + reset_decisions (); } - prev_lineno = next_lineno; - next_lineno = lineno; - reset_decisions (); - } - - if (uae_int_requested) { - INTREQ (0x8000 | 0x0008); - } - - { - extern int volatile uaenet_int_requested; - extern int volatile uaenet_vsync_requested; - if (uaenet_int_requested || (uaenet_vsync_requested && vpos == 10)) { - INTREQ (0x8000 | 0x2000); - } - } - - { - extern void bsdsock_fake_int_handler (void); - extern int volatile bsd_int_requested; - if (bsd_int_requested) - bsdsock_fake_int_handler (); - } - - /* See if there's a chance of a copper wait ending this line. */ - cop_state.hpos = 0; - cop_state.last_write = 0; - compute_spcflag_copper (hpos); - serial_hsynchandler (); + + if (uae_int_requested) { + INTREQ (0x8000 | 0x0008); + } + + { + extern int volatile uaenet_int_requested; + extern int volatile uaenet_vsync_requested; + if (uaenet_int_requested || (uaenet_vsync_requested && vpos == 10)) { + INTREQ (0x8000 | 0x2000); + } + } + + { + extern void bsdsock_fake_int_handler (void); + extern int volatile bsd_int_requested; + if (bsd_int_requested) + bsdsock_fake_int_handler (); + } + + /* See if there's a chance of a copper wait ending this line. */ + cop_state.hpos = 0; + cop_state.last_write = 0; + compute_spcflag_copper (hpos); + serial_hsynchandler (); #ifdef CUSTOM_SIMPLE - do_sprites (0); -#endif - - while (input_recording < 0 && inprec_pstart (INPREC_KEY)) { - record_key_direct (inprec_pu8 ()); - inprec_pend (); - } - while (input_recording < 0 && inprec_pstart (INPREC_DISKREMOVE)) { - disk_eject (inprec_pu8 ()); - inprec_pend (); - } - while (input_recording < 0 && inprec_pstart (INPREC_DISKINSERT)) { - int drv = inprec_pu8 (); - inprec_pstr (currprefs.df[drv]); - _tcscpy (changed_prefs.df[drv], currprefs.df[drv]); - disk_insert_force (drv, currprefs.df[drv]); - inprec_pend (); - } - - inputdevice_hsync (); - gayle_hsync (); - scsi_hsync (); - - hsync_counter++; - //copper_check (2); - - if (GET_PLANES (bplcon0) > 0 && dmaen (DMA_BITPLANE)) { - if (vpos > last_planes_vpos) - last_planes_vpos = vpos; - if (vpos >= minfirstline && first_planes_vpos == 0) { - first_planes_vpos = vpos; - } else if (vpos == maxvpos - 1) { - last_planes_vpos = vpos - 1; - } - } - if (diw_change == 0) { - if (vpos >= first_planes_vpos && vpos <= last_planes_vpos) { - if (diwlastword > diwlastword_total) - diwlastword_total = diwlastword; - if (diwfirstword < diwfirstword_total) { - diwfirstword_total = diwfirstword; - firstword_bplcon1 = bplcon1; - } + do_sprites (0); +#endif + + while (input_recording < 0 && inprec_pstart (INPREC_KEY)) { + record_key_direct (inprec_pu8 ()); + inprec_pend (); } - if (diwstate == DIW_waiting_stop) { - int f = 8 << fetchmode; - if (plfstrt + f < ddffirstword_total + f) - ddffirstword_total = plfstrt + f; - if (plfstop + 2 * f > ddflastword_total + 2 * f) - ddflastword_total = plfstop + 2 * f; - } - if ((plffirstline < plffirstline_total || (plffirstline_total == minfirstline && vpos > minfirstline)) && plffirstline < vpos / 2) { - firstword_bplcon1 = bplcon1; - if (plffirstline < minfirstline) - plffirstline_total = minfirstline; - else - plffirstline_total = plffirstline; - } - if (plflastline > plflastline_total && plflastline > plffirstline_total && plflastline > maxvpos / 2) - plflastline_total = plflastline; - } - if (diw_change > 0) - diw_change--; + while (input_recording < 0 && inprec_pstart (INPREC_DISKREMOVE)) { + disk_eject (inprec_pu8 ()); + inprec_pend (); + } + while (input_recording < 0 && inprec_pstart (INPREC_DISKINSERT)) { + int drv = inprec_pu8 (); + inprec_pstr (currprefs.df[drv]); + _tcscpy (changed_prefs.df[drv], currprefs.df[drv]); + disk_insert_force (drv, currprefs.df[drv]); + inprec_pend (); + } + + inputdevice_hsync (); + gayle_hsync (); + scsi_hsync (); + + hsync_counter++; + //copper_check (2); + + if (GET_PLANES (bplcon0) > 0 && dmaen (DMA_BITPLANE)) { + if (vpos > last_planes_vpos) + last_planes_vpos = vpos; + if (vpos >= minfirstline && first_planes_vpos == 0) { + first_planes_vpos = vpos; + } else if (vpos == maxvpos - 1) { + last_planes_vpos = vpos - 1; + } + } + if (diw_change == 0) { + if (vpos >= first_planes_vpos && vpos <= last_planes_vpos) { + if (diwlastword > diwlastword_total) + diwlastword_total = diwlastword; + if (diwfirstword < diwfirstword_total) { + diwfirstword_total = diwfirstword; + firstword_bplcon1 = bplcon1; + } + } + if (diwstate == DIW_waiting_stop) { + int f = 8 << fetchmode; + if (plfstrt + f < ddffirstword_total + f) + ddffirstword_total = plfstrt + f; + if (plfstop + 2 * f > ddflastword_total + 2 * f) + ddflastword_total = plfstop + 2 * f; + } + if ((plffirstline < plffirstline_total || (plffirstline_total == minfirstline && vpos > minfirstline)) && plffirstline < vpos / 2) { + firstword_bplcon1 = bplcon1; + if (plffirstline < minfirstline) + plffirstline_total = minfirstline; + else + plffirstline_total = plffirstline; + } + if (plflastline > plflastline_total && plflastline > plffirstline_total && plflastline > maxvpos / 2) + plflastline_total = plflastline; + } + if (diw_change > 0) + diw_change--; #if 0 - { - static int skip; - if (M68K_GETPC >= 0x0C0D7A2 && M68K_GETPC < 0x00C0D7B2 && vpos == 0xf3) { - if (!skip) - activate_debugger (); - skip = 1; + { + static int skip; + if (M68K_GETPC >= 0x0C0D7A2 && M68K_GETPC < 0x00C0D7B2 && vpos == 0xf3) { + if (!skip) + activate_debugger (); + skip = 1; + } + if (vpos != 0xf3) + skip = 0; } - if (vpos != 0xf3) - skip = 0; - } #endif } static void MISC_handler (void) { - int i, recheck; - evt mintime; - evt ct = get_cycles (); - static int recursive; - - if (recursive) - return; - recursive++; - eventtab[ev_misc].active = 0; - recheck = 1; - while (recheck) { - recheck = 0; - mintime = ~0L; - for (i = 0; i < ev2_max; i++) { - if (eventtab2[i].active) { - if (eventtab2[i].evtime == ct) { - eventtab2[i].active = 0; - eventtab2[i].handler (eventtab2[i].data); - if (eventtab2[i].active) - recheck = 1; - } else { - evt eventtime = eventtab2[i].evtime - ct; - if (eventtime < mintime) - mintime = eventtime; + int i, recheck; + evt mintime; + evt ct = get_cycles (); + static int recursive; + + if (recursive) + return; + recursive++; + eventtab[ev_misc].active = 0; + recheck = 1; + while (recheck) { + recheck = 0; + mintime = ~0L; + for (i = 0; i < ev2_max; i++) { + if (eventtab2[i].active) { + if (eventtab2[i].evtime == ct) { + eventtab2[i].active = 0; + eventtab2[i].handler (eventtab2[i].data); + if (eventtab2[i].active) + recheck = 1; + } else { + evt eventtime = eventtab2[i].evtime - ct; + if (eventtime < mintime) + mintime = eventtime; + } + } } - } } - } - if (mintime != ~0L) { - eventtab[ev_misc].active = 1; - eventtab[ev_misc].oldcycles = ct; - eventtab[ev_misc].evtime = ct + mintime; - events_schedule (); - } - recursive--; + if (mintime != ~0L) { + eventtab[ev_misc].active = 1; + eventtab[ev_misc].oldcycles = ct; + eventtab[ev_misc].evtime = ct + mintime; + events_schedule (); + } + recursive--; } STATIC_INLINE void event2_newevent_x (int no, evt t, uae_u32 data, evfunc2 func) { - evt et; + evt et; - if (((int)t) <= 0) { - func (data); - return; - } + if (((int)t) <= 0) { + func (data); + return; + } - et = t * CYCLE_UNIT + get_cycles (); + et = t * CYCLE_UNIT + get_cycles (); - if (no < 0) { - for (no = ev2_misc; no < ev2_max; no++) { - if (!eventtab2[no].active) - break; - if (eventtab2[no].evtime == et && eventtab2[no].handler == func) { - eventtab2[no].handler (eventtab2[no].data); - break; - } - } - if (no == ev2_max) { - write_log (L"out of event2's! PC=%x\n", M68K_GETPC); - return; + if (no < 0) { + for (no = ev2_misc; no < ev2_max; no++) { + if (!eventtab2[no].active) + break; + if (eventtab2[no].evtime == et && eventtab2[no].handler == func) { + eventtab2[no].handler (eventtab2[no].data); + break; + } + } + if (no == ev2_max) { + write_log (L"out of event2's! PC=%x\n", M68K_GETPC); + return; + } } - } - eventtab2[no].active = 1; - eventtab2[no].evtime = et; - eventtab2[no].handler = func; - eventtab2[no].data = data; - MISC_handler (); + eventtab2[no].active = 1; + eventtab2[no].evtime = et; + eventtab2[no].handler = func; + eventtab2[no].data = data; + MISC_handler (); } void event2_newevent (int no, evt t) { - event2_newevent_x (no, t, 0, eventtab2[no].handler); + event2_newevent_x (no, t, 0, eventtab2[no].handler); } void event2_newevent2 (evt t, uae_u32 data, evfunc2 func) { - event2_newevent_x (-1, t, data, func); + event2_newevent_x (-1, t, data, func); } void event2_remevent (int no) { - eventtab2[no].active = 0; + eventtab2[no].active = 0; } void init_eventtab (void) { - int i; + int i; - nextevent = 0; - set_cycles (0); - for (i = 0; i < ev_max; i++) { - eventtab[i].active = 0; - eventtab[i].oldcycles = 0; - } - for (i = 0; i < ev2_max; i++) { - eventtab2[i].active = 0; - } + nextevent = 0; + set_cycles (0); + for (i = 0; i < ev_max; i++) { + eventtab[i].active = 0; + eventtab[i].oldcycles = 0; + } + for (i = 0; i < ev2_max; i++) { + eventtab2[i].active = 0; + } - eventtab[ev_cia].handler = CIA_handler; - eventtab[ev_hsync].handler = hsync_handler; - eventtab[ev_hsync].evtime = get_cycles () + HSYNCTIME; - eventtab[ev_hsync].active = 1; - eventtab[ev_misc].handler = MISC_handler; - eventtab[ev_audio].handler = audio_evhandler; + eventtab[ev_cia].handler = CIA_handler; + eventtab[ev_hsync].handler = hsync_handler; + eventtab[ev_hsync].evtime = get_cycles () + HSYNCTIME; + eventtab[ev_hsync].active = 1; + eventtab[ev_misc].handler = MISC_handler; + eventtab[ev_audio].handler = audio_evhandler; - eventtab2[ev2_blitter].handler = blitter_handler; - eventtab2[ev2_disk].handler = DISK_handler; + eventtab2[ev2_blitter].handler = blitter_handler; + eventtab2[ev2_disk].handler = DISK_handler; - events_schedule (); + events_schedule (); } void customreset (int hardreset) { - int i; - int zero = 0; - - target_reset (); - reset_all_systems (); - write_log (L"Reset at %08X\n", M68K_GETPC); - memory_map_dump (); - - hsync_counter = 0; - vsync_counter = 0; - ciavsync_counter = 0; - lightpen_x = lightpen_y = -1; - lightpen_triggered = 0; - lightpen_cx = lightpen_cy = -1; - if (! savestate_state) { - currprefs.chipset_mask = changed_prefs.chipset_mask; - update_mirrors (); - if (!aga_mode) { - for (i = 0; i < 32; i++) { - current_colors.color_regs_ecs[i] = 0; - current_colors.acolors[i] = getxcolor (0); - } + int i; + int zero = 0; + + target_reset (); + reset_all_systems (); + write_log (L"Reset at %08X\n", M68K_GETPC); + memory_map_dump (); + + hsync_counter = 0; + vsync_counter = 0; + ciavsync_counter = 0; + lightpen_x = lightpen_y = -1; + lightpen_triggered = 0; + lightpen_cx = lightpen_cy = -1; + if (! savestate_state) { + currprefs.chipset_mask = changed_prefs.chipset_mask; + update_mirrors (); + if (!aga_mode) { + for (i = 0; i < 32; i++) { + current_colors.color_regs_ecs[i] = 0; + current_colors.acolors[i] = getxcolor (0); + } #ifdef AGA - } else { - for (i = 0; i < 256; i++) { - current_colors.color_regs_aga[i] = 0; - current_colors.acolors[i] = getxcolor (0); - } + } else { + for (i = 0; i < 256; i++) { + current_colors.color_regs_aga[i] = 0; + current_colors.acolors[i] = getxcolor (0); + } #endif - } + } - clxdat = 0; + clxdat = 0; - /* Clear the armed flags of all sprites. */ - memset (spr, 0, sizeof spr); - nr_armed = 0; + /* Clear the armed flags of all sprites. */ + memset (spr, 0, sizeof spr); + nr_armed = 0; - dmacon = intena = 0; + dmacon = intena = 0; - copcon = 0; - DSKLEN (0, 0); + copcon = 0; + DSKLEN (0, 0); - bplcon0 = 0; - bplcon4 = 0x0011; /* Get AGA chipset into ECS compatibility mode */ - bplcon3 = 0x0C00; + bplcon0 = 0; + bplcon4 = 0x0011; /* Get AGA chipset into ECS compatibility mode */ + bplcon3 = 0x0C00; - diwhigh = 0; - diwhigh_written = 0; + diwhigh = 0; + diwhigh_written = 0; - FMODE (0, 0); - CLXCON (0); - setup_fmodes (0); - sprite_width = GET_SPRITEWIDTH (fmode); - new_beamcon0 = currprefs.ntscmode ? 0x00 : 0x20; - } + FMODE (0, 0); + CLXCON (0); + setup_fmodes (0); + sprite_width = GET_SPRITEWIDTH (fmode); + new_beamcon0 = currprefs.ntscmode ? 0x00 : 0x20; + } - gayle_reset (hardreset); + gayle_reset (hardreset); #ifdef AUTOCONFIG - expamem_reset (); + expamem_reset (); #endif - a1000_reset (); - DISK_reset (); - CIA_reset (); - gayle_reset (0); + a1000_reset (); + DISK_reset (); + CIA_reset (); + gayle_reset (0); #ifdef A2091 - a2091_reset (); + a2091_reset (); #endif #ifdef NCR - ncr_reset (); + ncr_reset (); #endif #ifdef JIT - compemu_reset (); -#endif - unset_special (~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)); - - vpos = 0; - - inputdevice_reset (); - timehack_alive = 0; - - curr_sprite_entries = 0; - prev_sprite_entries = 0; - sprite_entries[0][0].first_pixel = 0; - sprite_entries[1][0].first_pixel = MAX_SPR_PIXELS; - sprite_entries[0][1].first_pixel = 0; - sprite_entries[1][1].first_pixel = MAX_SPR_PIXELS; - memset (spixels, 0, 2 * MAX_SPR_PIXELS * sizeof *spixels); - memset (&spixstate, 0, sizeof spixstate); - - bltstate = BLT_done; - cop_state.state = COP_stop; - diwstate = DIW_waiting_start; - hdiwstate = DIW_waiting_start; - set_cycles (0); - - hack_vpos = 0; - init_hz (); - vpos_lpen = -1; - - audio_reset (); - if (savestate_state != STATE_RESTORE) { - /* must be called after audio_reset */ - adkcon = 0; - serial_uartbreak (0); - audio_update_adkmasks (); - } + compemu_reset (); +#endif + unset_special (~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)); - init_sprites (); + vpos = 0; - init_hardware_frame (); - drawing_init (); + inputdevice_reset (); + timehack_alive = 0; - reset_decisions (); + curr_sprite_entries = 0; + prev_sprite_entries = 0; + sprite_entries[0][0].first_pixel = 0; + sprite_entries[1][0].first_pixel = MAX_SPR_PIXELS; + sprite_entries[0][1].first_pixel = 0; + sprite_entries[1][1].first_pixel = MAX_SPR_PIXELS; + memset (spixels, 0, 2 * MAX_SPR_PIXELS * sizeof *spixels); + memset (&spixstate, 0, sizeof spixstate); - bogusframe = 1; + bltstate = BLT_done; + cop_state.state = COP_stop; + diwstate = DIW_waiting_start; + hdiwstate = DIW_waiting_start; + set_cycles (0); - if (savestate_state == STATE_RESTORE) { - uae_u16 v; - uae_u32 vv; + hack_vpos = 0; + init_hz (); + vpos_lpen = -1; + + audio_reset (); + if (savestate_state != STATE_RESTORE) { + /* must be called after audio_reset */ + adkcon = 0; + serial_uartbreak (0); + audio_update_adkmasks (); + } - audio_update_adkmasks (); - INTENA (0); - INTREQ (0); - COPJMP (1, 1); - v = bplcon0; - BPLCON0 (0, 0); - BPLCON0 (0, v); - FMODE (0, fmode); - if (!(currprefs.chipset_mask & CSMASK_AGA)) { - for(i = 0 ; i < 32 ; i++) { - vv = current_colors.color_regs_ecs[i]; - current_colors.color_regs_ecs[i] = -1; - record_color_change (0, i, vv); - remembered_color_entry = -1; - current_colors.color_regs_ecs[i] = vv; - current_colors.acolors[i] = xcolors[vv]; - } + init_sprites (); + + init_hardware_frame (); + drawing_init (); + + reset_decisions (); + + bogusframe = 1; + + if (savestate_state == STATE_RESTORE) { + uae_u16 v; + uae_u32 vv; + + audio_update_adkmasks (); + INTENA (0); + INTREQ (0); + COPJMP (1, 1); + v = bplcon0; + BPLCON0 (0, 0); + BPLCON0 (0, v); + FMODE (0, fmode); + if (!(currprefs.chipset_mask & CSMASK_AGA)) { + for(i = 0 ; i < 32 ; i++) { + vv = current_colors.color_regs_ecs[i]; + current_colors.color_regs_ecs[i] = -1; + record_color_change (0, i, vv); + remembered_color_entry = -1; + current_colors.color_regs_ecs[i] = vv; + current_colors.acolors[i] = xcolors[vv]; + } #ifdef AGA - } else { - for(i = 0 ; i < 256 ; i++) { - vv = current_colors.color_regs_aga[i]; - current_colors.color_regs_aga[i] = -1; - record_color_change (0, i, vv); - remembered_color_entry = -1; - current_colors.color_regs_aga[i] = vv; - current_colors.acolors[i] = CONVERT_RGB (vv); - } + } else { + for(i = 0 ; i < 256 ; i++) { + vv = current_colors.color_regs_aga[i]; + current_colors.color_regs_aga[i] = -1; + record_color_change (0, i, vv); + remembered_color_entry = -1; + current_colors.color_regs_aga[i] = vv; + current_colors.acolors[i] = CONVERT_RGB (vv); + } #endif + } + CLXCON (clxcon); + CLXCON2 (clxcon2); + calcdiw (); + write_log (L"State restored\n"); + for (i = 0; i < 8; i++) + nr_armed += spr[i].armed != 0; + if (! currprefs.produce_sound) { + eventtab[ev_audio].active = 0; + events_schedule (); + } } - CLXCON (clxcon); - CLXCON2 (clxcon2); - calcdiw (); - write_log (L"State restored\n"); - for (i = 0; i < 8; i++) - nr_armed += spr[i].armed != 0; - if (! currprefs.produce_sound) { - eventtab[ev_audio].active = 0; - events_schedule (); - } - } - sprres = expand_sprres (bplcon0, bplcon3); - sprite_width = GET_SPRITEWIDTH (fmode); - setup_fmodes (0); + sprres = expand_sprres (bplcon0, bplcon3); + sprite_width = GET_SPRITEWIDTH (fmode); + setup_fmodes (0); - #ifdef ACTION_REPLAY - /* Doing this here ensures we can use the 'reset' command from within AR */ - action_replay_reset (); - #endif - #if defined(ENFORCER) - enforcer_disable (); - #endif +#ifdef ACTION_REPLAY + /* Doing this here ensures we can use the 'reset' command from within AR */ + action_replay_reset (); +#endif +#if defined(ENFORCER) + enforcer_disable (); +#endif - if (hardreset) - rtc_hardreset(); + if (hardreset) + rtc_hardreset(); - picasso_reset (); + picasso_reset (); } void dumpcustom (void) { - console_out_f (L"DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR (current_hpos ()), - (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); - console_out_f (L"COP1LC: %08lx, COP2LC: %08lx COPPTR: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc, cop_state.ip); - console_out_f (L"DIWSTRT: %04x DIWSTOP: %04x DDFSTRT: %04x DDFSTOP: %04x\n", - (unsigned int)diwstrt, (unsigned int)diwstop, (unsigned int)ddfstrt, (unsigned int)ddfstop); - console_out_f (L"BPLCON 0: %04x 1: %04x 2: %04x 3: %04x 4: %04x\n", bplcon0, bplcon1, bplcon2, bplcon3, bplcon4); - if (timeframes) { - console_out_f (L"Average frame time: %.2f ms [frames: %d time: %d]\n", - (double)frametime / timeframes, timeframes, frametime); - if (total_skipped) - console_out_f (L"Skipped frames: %d\n", total_skipped); - } + console_out_f (L"DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR (current_hpos ()), + (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); + console_out_f (L"COP1LC: %08lx, COP2LC: %08lx COPPTR: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc, cop_state.ip); + console_out_f (L"DIWSTRT: %04x DIWSTOP: %04x DDFSTRT: %04x DDFSTOP: %04x\n", + (unsigned int)diwstrt, (unsigned int)diwstop, (unsigned int)ddfstrt, (unsigned int)ddfstop); + console_out_f (L"BPLCON 0: %04x 1: %04x 2: %04x 3: %04x 4: %04x\n", bplcon0, bplcon1, bplcon2, bplcon3, bplcon4); + if (timeframes) { + console_out_f (L"Average frame time: %.2f ms [frames: %d time: %d]\n", + (double)frametime / timeframes, timeframes, frametime); + if (total_skipped) + console_out_f (L"Skipped frames: %d\n", total_skipped); + } } static void gen_custom_tables (void) { - int i; - for (i = 0; i < 256; i++) { - sprtaba[i] = ((((i >> 7) & 1) << 0) - | (((i >> 6) & 1) << 2) - | (((i >> 5) & 1) << 4) - | (((i >> 4) & 1) << 6) - | (((i >> 3) & 1) << 8) - | (((i >> 2) & 1) << 10) - | (((i >> 1) & 1) << 12) - | (((i >> 0) & 1) << 14)); - sprtabb[i] = sprtaba[i] * 2; - sprite_ab_merge[i] = (((i & 15) ? 1 : 0) - | ((i & 240) ? 2 : 0)); - } - for (i = 0; i < 16; i++) { - clxmask[i] = (((i & 1) ? 0xF : 0x3) - | ((i & 2) ? 0xF0 : 0x30) - | ((i & 4) ? 0xF00 : 0x300) - | ((i & 8) ? 0xF000 : 0x3000)); - sprclx[i] = (((i & 0x3) == 0x3 ? 1 : 0) - | ((i & 0x5) == 0x5 ? 2 : 0) - | ((i & 0x9) == 0x9 ? 4 : 0) - | ((i & 0x6) == 0x6 ? 8 : 0) - | ((i & 0xA) == 0xA ? 16 : 0) - | ((i & 0xC) == 0xC ? 32 : 0)) << 9; - } + int i; + for (i = 0; i < 256; i++) { + sprtaba[i] = ((((i >> 7) & 1) << 0) + | (((i >> 6) & 1) << 2) + | (((i >> 5) & 1) << 4) + | (((i >> 4) & 1) << 6) + | (((i >> 3) & 1) << 8) + | (((i >> 2) & 1) << 10) + | (((i >> 1) & 1) << 12) + | (((i >> 0) & 1) << 14)); + sprtabb[i] = sprtaba[i] * 2; + sprite_ab_merge[i] = (((i & 15) ? 1 : 0) + | ((i & 240) ? 2 : 0)); + } + for (i = 0; i < 16; i++) { + clxmask[i] = (((i & 1) ? 0xF : 0x3) + | ((i & 2) ? 0xF0 : 0x30) + | ((i & 4) ? 0xF00 : 0x300) + | ((i & 8) ? 0xF000 : 0x3000)); + sprclx[i] = (((i & 0x3) == 0x3 ? 1 : 0) + | ((i & 0x5) == 0x5 ? 2 : 0) + | ((i & 0x9) == 0x9 ? 4 : 0) + | ((i & 0x6) == 0x6 ? 8 : 0) + | ((i & 0xA) == 0xA ? 16 : 0) + | ((i & 0xC) == 0xC ? 32 : 0)) << 9; + } } /* mousehack is now in "filesys boot rom" */ static uae_u32 REGPARAM2 mousehack_helper_old (struct TrapContext *ctx) { - return 0; + return 0; } static int allocate_sprite_tables (void) { #ifdef OS_WITHOUT_MEMORY_MANAGEMENT - int num; + int num; - delta_sprite_entry = 0; - delta_color_change = 0; + delta_sprite_entry = 0; + delta_color_change = 0; - if (!sprite_entries[0]) { - max_sprite_entry = DEFAULT_MAX_SPRITE_ENTRY; - max_color_change = DEFAULT_MAX_COLOR_CHANGE; + if (!sprite_entries[0]) { + max_sprite_entry = DEFAULT_MAX_SPRITE_ENTRY; + max_color_change = DEFAULT_MAX_COLOR_CHANGE; - for (num = 0; num < 2; num++) { - sprite_entries[num] = xmalloc (max_sprite_entry * sizeof (struct sprite_entry)); - color_changes[num] = xmalloc (max_color_change * sizeof (struct color_change)); + for (num = 0; num < 2; num++) { + sprite_entries[num] = xmalloc (max_sprite_entry * sizeof (struct sprite_entry)); + color_changes[num] = xmalloc (max_color_change * sizeof (struct color_change)); - if (sprite_entries[num] && color_changes[num]) { - memset (sprite_entries[num], 0, max_sprite_entry * sizeof (struct sprite_entry)); - memset (color_changes[num], 0, max_color_change * sizeof (struct color_change)); - } else - return 0; + if (sprite_entries[num] && color_changes[num]) { + memset (sprite_entries[num], 0, max_sprite_entry * sizeof (struct sprite_entry)); + memset (color_changes[num], 0, max_color_change * sizeof (struct color_change)); + } else + return 0; + } } - } - if (!spixels) { - spixels = xmalloc (2 * MAX_SPR_PIXELS * sizeof *spixels); - if (!spixels) - return 0; - } + if (!spixels) { + spixels = xmalloc (2 * MAX_SPR_PIXELS * sizeof *spixels); + if (!spixels) + return 0; + } #endif - return 1; + return 1; } int custom_init (void) { - if (!allocate_sprite_tables ()) - return 0; + if (!allocate_sprite_tables ()) + return 0; #ifdef AUTOCONFIG - if (uae_boot_rom) { - uaecptr pos; - pos = here (); + if (uae_boot_rom) { + uaecptr pos; + pos = here (); - org (rtarea_base + 0xFF70); - calltrap (deftrap (mousehack_helper_old)); - dw (RTS); + org (rtarea_base + 0xFF70); + calltrap (deftrap (mousehack_helper_old)); + dw (RTS); - org (rtarea_base + 0xFFA0); - calltrap (deftrap (timehack_helper)); - dw (RTS); + org (rtarea_base + 0xFFA0); + calltrap (deftrap (timehack_helper)); + dw (RTS); - org (pos); - } + org (pos); + } #endif - gen_custom_tables (); - build_blitfilltable (); + gen_custom_tables (); + build_blitfilltable (); - drawing_init (); + drawing_init (); - create_cycle_diagram_table (); + create_cycle_diagram_table (); - return 1; + return 1; } /* Custom chip memory bank */ @@ -5782,445 +5791,445 @@ static void REGPARAM3 custom_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 custom_bput (uaecptr, uae_u32) REGPARAM; addrbank custom_bank = { - custom_lget, custom_wget, custom_bget, - custom_lput, custom_wput, custom_bput, - default_xlate, default_check, NULL, L"Custom chipset", - custom_lgeti, custom_wgeti, ABFLAG_IO + custom_lget, custom_wget, custom_bget, + custom_lput, custom_wput, custom_bput, + default_xlate, default_check, NULL, L"Custom chipset", + custom_lgeti, custom_wgeti, ABFLAG_IO }; static uae_u32 REGPARAM2 custom_wgeti (uaecptr addr) { - if (currprefs.cpu_model >= 68020) - return dummy_wgeti (addr); - return custom_wget (addr); + if (currprefs.cpu_model >= 68020) + return dummy_wgeti (addr); + return custom_wget (addr); } static uae_u32 REGPARAM2 custom_lgeti (uaecptr addr) { - if (currprefs.cpu_model >= 68020) - return dummy_lgeti (addr); - return custom_lget (addr); + if (currprefs.cpu_model >= 68020) + return dummy_lgeti (addr); + return custom_lget (addr); } STATIC_INLINE uae_u32 REGPARAM2 custom_wget_1 (int hpos, uaecptr addr, int noput) { - uae_u16 v; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xfff; + addr &= 0xfff; #if CUSTOM_DEBUG > 2 - write_log (L"%d:%d:wget: %04X=%04X pc=%p\n", current_hpos(), vpos, addr, addr & 0x1fe, m68k_getpc ()); -#endif - switch (addr & 0x1fe) { - case 0x002: v = DMACONR (hpos); break; - case 0x004: v = VPOSR (); break; - case 0x006: v = VHPOSR (); break; - - case 0x00A: v = JOY0DAT (); break; - case 0x00C: v = JOY1DAT (); break; - case 0x00E: v = CLXDAT (); break; - case 0x010: v = ADKCONR (); break; - - case 0x012: v = POT0DAT (); break; - case 0x014: v = POT1DAT (); break; - case 0x016: v = POTGOR (); break; - case 0x018: v = SERDATR (); break; - case 0x01A: v = DSKBYTR (hpos); break; - case 0x01C: v = INTENAR (); break; - case 0x01E: v = INTREQR (); break; - case 0x07C: v = DENISEID (); break; + write_log (L"%d:%d:wget: %04X=%04X pc=%p\n", current_hpos(), vpos, addr, addr & 0x1fe, m68k_getpc ()); +#endif + switch (addr & 0x1fe) { + case 0x002: v = DMACONR (hpos); break; + case 0x004: v = VPOSR (); break; + case 0x006: v = VHPOSR (); break; + + case 0x00A: v = JOY0DAT (); break; + case 0x00C: v = JOY1DAT (); break; + case 0x00E: v = CLXDAT (); break; + case 0x010: v = ADKCONR (); break; + + case 0x012: v = POT0DAT (); break; + case 0x014: v = POT1DAT (); break; + case 0x016: v = POTGOR (); break; + case 0x018: v = SERDATR (); break; + case 0x01A: v = DSKBYTR (hpos); break; + case 0x01C: v = INTENAR (); break; + case 0x01E: v = INTREQR (); break; + case 0x07C: v = DENISEID (); break; #ifdef AGA - case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: - case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: - case 0x198: case 0x19A: case 0x19C: case 0x19E: case 0x1A0: case 0x1A2: - case 0x1A4: case 0x1A6: case 0x1A8: case 0x1AA: case 0x1AC: case 0x1AE: - case 0x1B0: case 0x1B2: case 0x1B4: case 0x1B6: case 0x1B8: case 0x1BA: - case 0x1BC: case 0x1BE: - v = COLOR_READ ((addr & 0x3E) / 2); - break; -#endif - - default: - /* OCS/ECS: - * reading write-only register causes write with last value in chip - * bus (custom registers, chipram, slowram) - * and finally returns either all ones or something weird if DMA happens - * in next (or previous) cycle.. FIXME. - * - * OCS-only special case: DFF000 (BLTDAT) will always return whatever was left in bus - * - * AGA: - * only writes to custom registers change last value, read returns - * last value which then changes to all ones (following read will return - * all ones) - */ - v = last_custom_value1; - if (!noput) { - int r; - uae_u16 old = last_custom_value1; - uae_u16 l = currprefs.cpu_compatible && currprefs.cpu_model == 68000 ? regs.irc : 0xffff;//last_custom_value; - decide_line (hpos); - decide_fetch (hpos); - decide_blitter (hpos); - r = custom_wput_copper (hpos, addr, l, 1); - if (currprefs.chipset_mask & CSMASK_AGA) { - v = l; - last_custom_value1 = 0xffff; - } else if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { - v = old; - } else { - if ((addr & 0x1fe) == 0) { - if (is_cycle_ce ()) - v = old; - else - v = l; - } else { - v = old; - } - } + case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: + case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: + case 0x198: case 0x19A: case 0x19C: case 0x19E: case 0x1A0: case 0x1A2: + case 0x1A4: case 0x1A6: case 0x1A8: case 0x1AA: case 0x1AC: case 0x1AE: + case 0x1B0: case 0x1B2: case 0x1B4: case 0x1B6: case 0x1B8: case 0x1BA: + case 0x1BC: case 0x1BE: + v = COLOR_READ ((addr & 0x3E) / 2); + break; +#endif + + default: + /* OCS/ECS: + * reading write-only register causes write with last value in chip + * bus (custom registers, chipram, slowram) + * and finally returns either all ones or something weird if DMA happens + * in next (or previous) cycle.. FIXME. + * + * OCS-only special case: DFF000 (BLTDAT) will always return whatever was left in bus + * + * AGA: + * only writes to custom registers change last value, read returns + * last value which then changes to all ones (following read will return + * all ones) + */ + v = last_custom_value1; + if (!noput) { + int r; + uae_u16 old = last_custom_value1; + uae_u16 l = currprefs.cpu_compatible && currprefs.cpu_model == 68000 ? regs.irc : 0xffff;//last_custom_value; + decide_line (hpos); + decide_fetch (hpos); + decide_blitter (hpos); + r = custom_wput_copper (hpos, addr, l, 1); + if (currprefs.chipset_mask & CSMASK_AGA) { + v = l; + last_custom_value1 = 0xffff; + } else if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { + v = old; + } else { + if ((addr & 0x1fe) == 0) { + if (is_cycle_ce ()) + v = old; + else + v = l; + } else { + v = old; + } + } #if CUSTOM_DEBUG > 0 - write_log (L"%08X read = %04X. Value written=%04X PC=%08x\n", 0xdff000 | addr, v, l, M68K_GETPC); + write_log (L"%08X read = %04X. Value written=%04X PC=%08x\n", 0xdff000 | addr, v, l, M68K_GETPC); #endif + } + return v; } return v; - } - return v; } - STATIC_INLINE uae_u32 custom_wget2 (uaecptr addr) - { - uae_u32 v; - int hpos = current_hpos (); +STATIC_INLINE uae_u32 custom_wget2 (uaecptr addr) +{ + uae_u32 v; + int hpos = current_hpos (); - sync_copper_with_cpu (hpos, 1); - v = custom_wget_1 (hpos, addr, 0); + sync_copper_with_cpu (hpos, 1); + v = custom_wget_1 (hpos, addr, 0); #ifdef ACTION_REPLAY #ifdef ACTION_REPLAY_COMMON - addr &= 0x1ff; - ar_custom[addr + 0] = (uae_u8)(v >> 8); - ar_custom[addr + 1] = (uae_u8)(v); + addr &= 0x1ff; + ar_custom[addr + 0] = (uae_u8)(v >> 8); + ar_custom[addr + 1] = (uae_u8)(v); #endif #endif - return v; + return v; } static uae_u32 REGPARAM2 custom_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; - if (addr & 1) { - /* think about move.w $dff005,d0.. (68020+ only) */ - addr &= ~1; - v = custom_wget2 (addr) << 8; - v |= custom_wget2 (addr + 2) >> 8; - return v; - } - return custom_wget2 (addr); - } + if (addr & 1) { + /* think about move.w $dff005,d0.. (68020+ only) */ + addr &= ~1; + v = custom_wget2 (addr) << 8; + v |= custom_wget2 (addr + 2) >> 8; + return v; + } + return custom_wget2 (addr); +} static uae_u32 REGPARAM2 custom_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return custom_wget2 (addr & ~1) >> (addr & 1 ? 0 : 8); + return custom_wget2 (addr & ~1) >> (addr & 1 ? 0 : 8); } static uae_u32 REGPARAM2 custom_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return ((uae_u32)custom_wget (addr) << 16) | custom_wget (addr + 2); + return ((uae_u32)custom_wget (addr) << 16) | custom_wget (addr + 2); } static int REGPARAM2 custom_wput_1 (int hpos, uaecptr addr, uae_u32 value, int noget) { - addr &= 0x1FE; - value &= 0xffff; + addr &= 0x1FE; + value &= 0xffff; #ifdef ACTION_REPLAY #ifdef ACTION_REPLAY_COMMON - ar_custom[addr+0]=(uae_u8)(value>>8); - ar_custom[addr+1]=(uae_u8)(value); -#endif -#endif - switch (addr) { - case 0x00E: CLXDAT (); break; - - case 0x020: DSKPTH (value); break; - case 0x022: DSKPTL (value); break; - case 0x024: DSKLEN (value, hpos); break; - case 0x026: DSKDAT (value); break; - - case 0x02A: VPOSW (value); break; - case 0x02C: VHPOSW (value); break; - case 0x02E: COPCON (value); break; - case 0x030: SERDAT (value); break; - case 0x032: SERPER (value); break; - case 0x034: POTGO (value); break; - - case 0x040: BLTCON0 (hpos, value); break; - case 0x042: BLTCON1 (hpos, value); break; - - case 0x044: BLTAFWM (hpos, value); break; - case 0x046: BLTALWM (hpos, value); break; - - case 0x050: BLTAPTH (hpos, value); break; - case 0x052: BLTAPTL (hpos, value); break; - case 0x04C: BLTBPTH (hpos, value); break; - case 0x04E: BLTBPTL (hpos, value); break; - case 0x048: BLTCPTH (hpos, value); break; - case 0x04A: BLTCPTL (hpos, value); break; - case 0x054: BLTDPTH (hpos, value); break; - case 0x056: BLTDPTL (hpos, value); break; - - case 0x058: BLTSIZE (hpos, value); break; - - case 0x064: BLTAMOD (hpos, value); break; - case 0x062: BLTBMOD (hpos, value); break; - case 0x060: BLTCMOD (hpos, value); break; - case 0x066: BLTDMOD (hpos, value); break; - - case 0x070: BLTCDAT (hpos, value); break; - case 0x072: BLTBDAT (hpos, value); break; - case 0x074: BLTADAT (hpos, value); break; - - case 0x07E: DSKSYNC (hpos, value); break; - - case 0x080: COP1LCH (value); break; - case 0x082: COP1LCL (value); break; - case 0x084: COP2LCH (value); break; - case 0x086: COP2LCL (value); break; - - case 0x088: COPJMP (1, 0); break; - case 0x08A: COPJMP (2, 0); break; - - case 0x08E: DIWSTRT (hpos, value); break; - case 0x090: DIWSTOP (hpos, value); break; - case 0x092: DDFSTRT (hpos, value); break; - case 0x094: DDFSTOP (hpos, value); break; - - case 0x096: DMACON (hpos, value); break; - case 0x098: CLXCON (value); break; - case 0x09A: INTENA (value); break; - case 0x09C: INTREQ (value); break; - case 0x09E: ADKCON (hpos, value); break; - - case 0x0A0: AUDxLCH (0, value); break; - case 0x0A2: AUDxLCL (0, value); break; - case 0x0A4: AUDxLEN (0, value); break; - case 0x0A6: AUDxPER (0, value); break; - case 0x0A8: AUDxVOL (0, value); break; - case 0x0AA: AUDxDAT (0, value); break; - - case 0x0B0: AUDxLCH (1, value); break; - case 0x0B2: AUDxLCL (1, value); break; - case 0x0B4: AUDxLEN (1, value); break; - case 0x0B6: AUDxPER (1, value); break; - case 0x0B8: AUDxVOL (1, value); break; - case 0x0BA: AUDxDAT (1, value); break; - - case 0x0C0: AUDxLCH (2, value); break; - case 0x0C2: AUDxLCL (2, value); break; - case 0x0C4: AUDxLEN (2, value); break; - case 0x0C6: AUDxPER (2, value); break; - case 0x0C8: AUDxVOL (2, value); break; - case 0x0CA: AUDxDAT (2, value); break; - - case 0x0D0: AUDxLCH (3, value); break; - case 0x0D2: AUDxLCL (3, value); break; - case 0x0D4: AUDxLEN (3, value); break; - case 0x0D6: AUDxPER (3, value); break; - case 0x0D8: AUDxVOL (3, value); break; - case 0x0DA: AUDxDAT (3, value); break; - - case 0x0E0: BPLxPTH (hpos, value, 0); break; - case 0x0E2: BPLxPTL (hpos, value, 0); break; - case 0x0E4: BPLxPTH (hpos, value, 1); break; - case 0x0E6: BPLxPTL (hpos, value, 1); break; - case 0x0E8: BPLxPTH (hpos, value, 2); break; - case 0x0EA: BPLxPTL (hpos, value, 2); break; - case 0x0EC: BPLxPTH (hpos, value, 3); break; - case 0x0EE: BPLxPTL (hpos, value, 3); break; - case 0x0F0: BPLxPTH (hpos, value, 4); break; - case 0x0F2: BPLxPTL (hpos, value, 4); break; - case 0x0F4: BPLxPTH (hpos, value, 5); break; - case 0x0F6: BPLxPTL (hpos, value, 5); break; - case 0x0F8: BPLxPTH (hpos, value, 6); break; - case 0x0FA: BPLxPTL (hpos, value, 6); break; - case 0x0FC: BPLxPTH (hpos, value, 7); break; - case 0x0FE: BPLxPTL (hpos, value, 7); break; - - case 0x100: BPLCON0 (hpos, value); break; - case 0x102: BPLCON1 (hpos, value); break; - case 0x104: BPLCON2 (hpos, value); break; + ar_custom[addr+0]=(uae_u8)(value>>8); + ar_custom[addr+1]=(uae_u8)(value); +#endif +#endif + switch (addr) { + case 0x00E: CLXDAT (); break; + + case 0x020: DSKPTH (value); break; + case 0x022: DSKPTL (value); break; + case 0x024: DSKLEN (value, hpos); break; + case 0x026: DSKDAT (value); break; + + case 0x02A: VPOSW (value); break; + case 0x02C: VHPOSW (value); break; + case 0x02E: COPCON (value); break; + case 0x030: SERDAT (value); break; + case 0x032: SERPER (value); break; + case 0x034: POTGO (value); break; + + case 0x040: BLTCON0 (hpos, value); break; + case 0x042: BLTCON1 (hpos, value); break; + + case 0x044: BLTAFWM (hpos, value); break; + case 0x046: BLTALWM (hpos, value); break; + + case 0x050: BLTAPTH (hpos, value); break; + case 0x052: BLTAPTL (hpos, value); break; + case 0x04C: BLTBPTH (hpos, value); break; + case 0x04E: BLTBPTL (hpos, value); break; + case 0x048: BLTCPTH (hpos, value); break; + case 0x04A: BLTCPTL (hpos, value); break; + case 0x054: BLTDPTH (hpos, value); break; + case 0x056: BLTDPTL (hpos, value); break; + + case 0x058: BLTSIZE (hpos, value); break; + + case 0x064: BLTAMOD (hpos, value); break; + case 0x062: BLTBMOD (hpos, value); break; + case 0x060: BLTCMOD (hpos, value); break; + case 0x066: BLTDMOD (hpos, value); break; + + case 0x070: BLTCDAT (hpos, value); break; + case 0x072: BLTBDAT (hpos, value); break; + case 0x074: BLTADAT (hpos, value); break; + + case 0x07E: DSKSYNC (hpos, value); break; + + case 0x080: COP1LCH (value); break; + case 0x082: COP1LCL (value); break; + case 0x084: COP2LCH (value); break; + case 0x086: COP2LCL (value); break; + + case 0x088: COPJMP (1, 0); break; + case 0x08A: COPJMP (2, 0); break; + + case 0x08E: DIWSTRT (hpos, value); break; + case 0x090: DIWSTOP (hpos, value); break; + case 0x092: DDFSTRT (hpos, value); break; + case 0x094: DDFSTOP (hpos, value); break; + + case 0x096: DMACON (hpos, value); break; + case 0x098: CLXCON (value); break; + case 0x09A: INTENA (value); break; + case 0x09C: INTREQ (value); break; + case 0x09E: ADKCON (hpos, value); break; + + case 0x0A0: AUDxLCH (0, value); break; + case 0x0A2: AUDxLCL (0, value); break; + case 0x0A4: AUDxLEN (0, value); break; + case 0x0A6: AUDxPER (0, value); break; + case 0x0A8: AUDxVOL (0, value); break; + case 0x0AA: AUDxDAT (0, value); break; + + case 0x0B0: AUDxLCH (1, value); break; + case 0x0B2: AUDxLCL (1, value); break; + case 0x0B4: AUDxLEN (1, value); break; + case 0x0B6: AUDxPER (1, value); break; + case 0x0B8: AUDxVOL (1, value); break; + case 0x0BA: AUDxDAT (1, value); break; + + case 0x0C0: AUDxLCH (2, value); break; + case 0x0C2: AUDxLCL (2, value); break; + case 0x0C4: AUDxLEN (2, value); break; + case 0x0C6: AUDxPER (2, value); break; + case 0x0C8: AUDxVOL (2, value); break; + case 0x0CA: AUDxDAT (2, value); break; + + case 0x0D0: AUDxLCH (3, value); break; + case 0x0D2: AUDxLCL (3, value); break; + case 0x0D4: AUDxLEN (3, value); break; + case 0x0D6: AUDxPER (3, value); break; + case 0x0D8: AUDxVOL (3, value); break; + case 0x0DA: AUDxDAT (3, value); break; + + case 0x0E0: BPLxPTH (hpos, value, 0); break; + case 0x0E2: BPLxPTL (hpos, value, 0); break; + case 0x0E4: BPLxPTH (hpos, value, 1); break; + case 0x0E6: BPLxPTL (hpos, value, 1); break; + case 0x0E8: BPLxPTH (hpos, value, 2); break; + case 0x0EA: BPLxPTL (hpos, value, 2); break; + case 0x0EC: BPLxPTH (hpos, value, 3); break; + case 0x0EE: BPLxPTL (hpos, value, 3); break; + case 0x0F0: BPLxPTH (hpos, value, 4); break; + case 0x0F2: BPLxPTL (hpos, value, 4); break; + case 0x0F4: BPLxPTH (hpos, value, 5); break; + case 0x0F6: BPLxPTL (hpos, value, 5); break; + case 0x0F8: BPLxPTH (hpos, value, 6); break; + case 0x0FA: BPLxPTL (hpos, value, 6); break; + case 0x0FC: BPLxPTH (hpos, value, 7); break; + case 0x0FE: BPLxPTL (hpos, value, 7); break; + + case 0x100: BPLCON0 (hpos, value); break; + case 0x102: BPLCON1 (hpos, value); break; + case 0x104: BPLCON2 (hpos, value); break; #ifdef ECS_DENISE - case 0x106: BPLCON3 (hpos, value); break; + case 0x106: BPLCON3 (hpos, value); break; #endif - case 0x108: BPL1MOD (hpos, value); break; - case 0x10A: BPL2MOD (hpos, value); break; + case 0x108: BPL1MOD (hpos, value); break; + case 0x10A: BPL2MOD (hpos, value); break; #ifdef AGA - case 0x10E: CLXCON2 (value); break; -#endif - - case 0x110: BPLxDAT (hpos, 0, value); break; - case 0x112: BPLxDAT (hpos, 1, value); break; - case 0x114: BPLxDAT (hpos, 2, value); break; - case 0x116: BPLxDAT (hpos, 3, value); break; - case 0x118: BPLxDAT (hpos, 4, value); break; - case 0x11A: BPLxDAT (hpos, 5, value); break; - case 0x11C: BPLxDAT (hpos, 6, value); break; - case 0x11E: BPLxDAT (hpos, 7, value); break; - - case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: - case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: - case 0x198: case 0x19A: case 0x19C: case 0x19E: case 0x1A0: case 0x1A2: - case 0x1A4: case 0x1A6: case 0x1A8: case 0x1AA: case 0x1AC: case 0x1AE: - case 0x1B0: case 0x1B2: case 0x1B4: case 0x1B6: case 0x1B8: case 0x1BA: - case 0x1BC: case 0x1BE: - COLOR_WRITE (hpos, value & 0xFFF, (addr & 0x3E) / 2); - break; - case 0x120: case 0x124: case 0x128: case 0x12C: - case 0x130: case 0x134: case 0x138: case 0x13C: - SPRxPTH (hpos, value, (addr - 0x120) / 4); - break; - case 0x122: case 0x126: case 0x12A: case 0x12E: - case 0x132: case 0x136: case 0x13A: case 0x13E: - SPRxPTL (hpos, value, (addr - 0x122) / 4); - break; - case 0x140: case 0x148: case 0x150: case 0x158: - case 0x160: case 0x168: case 0x170: case 0x178: - SPRxPOS (hpos, value, (addr - 0x140) / 8); - break; - case 0x142: case 0x14A: case 0x152: case 0x15A: - case 0x162: case 0x16A: case 0x172: case 0x17A: - SPRxCTL (hpos, value, (addr - 0x142) / 8); - break; - case 0x144: case 0x14C: case 0x154: case 0x15C: - case 0x164: case 0x16C: case 0x174: case 0x17C: - SPRxDATA (hpos, value, (addr - 0x144) / 8); - break; - case 0x146: case 0x14E: case 0x156: case 0x15E: - case 0x166: case 0x16E: case 0x176: case 0x17E: - SPRxDATB (hpos, value, (addr - 0x146) / 8); - break; - - case 0x36: JOYTEST (value); break; - case 0x5A: BLTCON0L (hpos, value); break; - case 0x5C: BLTSIZV (hpos, value); break; - case 0x5E: BLTSIZH (hpos, value); break; - case 0x1E4: DIWHIGH (hpos, value); break; + case 0x10E: CLXCON2 (value); break; +#endif + + case 0x110: BPLxDAT (hpos, 0, value); break; + case 0x112: BPLxDAT (hpos, 1, value); break; + case 0x114: BPLxDAT (hpos, 2, value); break; + case 0x116: BPLxDAT (hpos, 3, value); break; + case 0x118: BPLxDAT (hpos, 4, value); break; + case 0x11A: BPLxDAT (hpos, 5, value); break; + case 0x11C: BPLxDAT (hpos, 6, value); break; + case 0x11E: BPLxDAT (hpos, 7, value); break; + + case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: + case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: + case 0x198: case 0x19A: case 0x19C: case 0x19E: case 0x1A0: case 0x1A2: + case 0x1A4: case 0x1A6: case 0x1A8: case 0x1AA: case 0x1AC: case 0x1AE: + case 0x1B0: case 0x1B2: case 0x1B4: case 0x1B6: case 0x1B8: case 0x1BA: + case 0x1BC: case 0x1BE: + COLOR_WRITE (hpos, value & 0xFFF, (addr & 0x3E) / 2); + break; + case 0x120: case 0x124: case 0x128: case 0x12C: + case 0x130: case 0x134: case 0x138: case 0x13C: + SPRxPTH (hpos, value, (addr - 0x120) / 4); + break; + case 0x122: case 0x126: case 0x12A: case 0x12E: + case 0x132: case 0x136: case 0x13A: case 0x13E: + SPRxPTL (hpos, value, (addr - 0x122) / 4); + break; + case 0x140: case 0x148: case 0x150: case 0x158: + case 0x160: case 0x168: case 0x170: case 0x178: + SPRxPOS (hpos, value, (addr - 0x140) / 8); + break; + case 0x142: case 0x14A: case 0x152: case 0x15A: + case 0x162: case 0x16A: case 0x172: case 0x17A: + SPRxCTL (hpos, value, (addr - 0x142) / 8); + break; + case 0x144: case 0x14C: case 0x154: case 0x15C: + case 0x164: case 0x16C: case 0x174: case 0x17C: + SPRxDATA (hpos, value, (addr - 0x144) / 8); + break; + case 0x146: case 0x14E: case 0x156: case 0x15E: + case 0x166: case 0x16E: case 0x176: case 0x17E: + SPRxDATB (hpos, value, (addr - 0x146) / 8); + break; + + case 0x36: JOYTEST (value); break; + case 0x5A: BLTCON0L (hpos, value); break; + case 0x5C: BLTSIZV (hpos, value); break; + case 0x5E: BLTSIZH (hpos, value); break; + case 0x1E4: DIWHIGH (hpos, value); break; #ifdef AGA - case 0x10C: BPLCON4 (hpos, value); break; + case 0x10C: BPLCON4 (hpos, value); break; #endif #ifndef CUSTOM_SIMPLE - case 0x1DC: BEAMCON0 (value); break; + case 0x1DC: BEAMCON0 (value); break; #ifdef ECS_DENISE - case 0x1C0: if (htotal != value) { htotal = value; varsync (); } break; - case 0x1C2: if (hsstop != value) { hsstop = value; varsync (); } break; - case 0x1C4: if (hbstrt != value) { hbstrt = value; varsync (); } break; - case 0x1C6: if (hbstop != value) { hbstop = value; varsync (); } break; - case 0x1C8: if (vtotal != value) { vtotal = value; varsync (); } break; - case 0x1CA: if (vsstop != value) { vsstop = value; varsync (); } break; - case 0x1CC: if (vbstrt < value || vbstrt > value + 1) { vbstrt = value; varsync (); } break; - case 0x1CE: if (vbstop < value || vbstop > value + 1) { vbstop = value; varsync (); } break; - case 0x1DE: if (hsstrt != value) { hsstrt = value; varsync (); } break; - case 0x1E0: if (vsstrt != value) { vsstrt = value; varsync (); } break; - case 0x1E2: if (hcenter != value) { hcenter = value; varsync (); } break; + case 0x1C0: if (htotal != value) { htotal = value; varsync (); } break; + case 0x1C2: if (hsstop != value) { hsstop = value; varsync (); } break; + case 0x1C4: if (hbstrt != value) { hbstrt = value; varsync (); } break; + case 0x1C6: if (hbstop != value) { hbstop = value; varsync (); } break; + case 0x1C8: if (vtotal != value) { vtotal = value; varsync (); } break; + case 0x1CA: if (vsstop != value) { vsstop = value; varsync (); } break; + case 0x1CC: if (vbstrt < value || vbstrt > value + 1) { vbstrt = value; varsync (); } break; + case 0x1CE: if (vbstop < value || vbstop > value + 1) { vbstop = value; varsync (); } break; + case 0x1DE: if (hsstrt != value) { hsstrt = value; varsync (); } break; + case 0x1E0: if (vsstrt != value) { vsstrt = value; varsync (); } break; + case 0x1E2: if (hcenter != value) { hcenter = value; varsync (); } break; #endif #endif #ifdef AGA - case 0x1FC: FMODE (hpos, value); break; + case 0x1FC: FMODE (hpos, value); break; #endif - case 0x1FE: FNULL (value); break; + case 0x1FE: FNULL (value); break; - /* writing to read-only register causes read access */ - default: - if (!noget) { + /* writing to read-only register causes read access */ + default: + if (!noget) { #if CUSTOM_DEBUG > 0 - write_log (L"%04X written %08x\n", addr, M68K_GETPC); + write_log (L"%04X written %08x\n", addr, M68K_GETPC); #endif - custom_wget_1 (hpos, addr, 1); - } - return 1; - } - return 0; + custom_wget_1 (hpos, addr, 1); + } + return 1; + } + return 0; } static void REGPARAM2 custom_wput (uaecptr addr, uae_u32 value) { - int hpos = current_hpos (); + int hpos = current_hpos (); #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif #if CUSTOM_DEBUG > 2 - write_log (L"%d:%d:wput: %04X %04X pc=%p\n", hpos, vpos, addr & 0x01fe, value & 0xffff, m68k_getpc ()); + write_log (L"%d:%d:wput: %04X %04X pc=%p\n", hpos, vpos, addr & 0x01fe, value & 0xffff, m68k_getpc ()); #endif - sync_copper_with_cpu (hpos, 1); - if (addr & 1) { - addr &= ~1; - custom_wput_1 (hpos, addr, (value >> 8) | (value & 0xff00), 0); - custom_wput_1 (hpos, addr + 2, (value << 8) | (value & 0x00ff), 0); - return; - } - custom_wput_1 (hpos, addr, value, 0); + sync_copper_with_cpu (hpos, 1); + if (addr & 1) { + addr &= ~1; + custom_wput_1 (hpos, addr, (value >> 8) | (value & 0xff00), 0); + custom_wput_1 (hpos, addr + 2, (value << 8) | (value & 0x00ff), 0); + return; + } + custom_wput_1 (hpos, addr, value, 0); } static void REGPARAM2 custom_bput (uaecptr addr, uae_u32 value) { - static int warned; - uae_u16 rval; + static int warned; + uae_u16 rval; - if (addr & 1) { - rval = value & 0xff; - } else { - rval = (value << 8) | (value & 0xFF); - } + if (addr & 1) { + rval = value & 0xff; + } else { + rval = (value << 8) | (value & 0xFF); + } #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.cpu_model == 68060) { - if (addr & 1) - custom_wput (addr & ~1, rval); - else - custom_wput (addr, value << 8); - } else { - custom_wput (addr & ~1, rval); - } - if (warned < 10) { - if (M68K_GETPC < 0xe00000 || M68K_GETPC >= 0x10000000) { - write_log (L"Byte put to custom register %04X PC=%08X\n", addr, M68K_GETPC); - warned++; + if (currprefs.cpu_model == 68060) { + if (addr & 1) + custom_wput (addr & ~1, rval); + else + custom_wput (addr, value << 8); + } else { + custom_wput (addr & ~1, rval); + } + if (warned < 10) { + if (M68K_GETPC < 0xe00000 || M68K_GETPC >= 0x10000000) { + write_log (L"Byte put to custom register %04X PC=%08X\n", addr, M68K_GETPC); + warned++; + } } - } } static void REGPARAM2 custom_lput(uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - custom_wput (addr & 0xfffe, value >> 16); - custom_wput ((addr + 2) & 0xfffe, (uae_u16)value); + custom_wput (addr & 0xfffe, value >> 16); + custom_wput ((addr + 2) & 0xfffe, (uae_u16)value); } #ifdef SAVESTATE void custom_prepare_savestate (void) { - int i; + int i; - for (i = 0; i < ev2_max; i++) { - if (eventtab2[i].active) { - eventtab2[i].active = 0; - eventtab2[i].handler (eventtab2[i].data); + for (i = 0; i < ev2_max; i++) { + if (eventtab2[i].active) { + eventtab2[i].active = 0; + eventtab2[i].handler (eventtab2[i].data); + } } - } } #define RB restore_u8 () @@ -6229,139 +6238,139 @@ void custom_prepare_savestate (void) uae_u8 *restore_custom (uae_u8 *src) { - uae_u16 dsklen, dskbytr; - int dskpt; - int i; - - audio_reset (); - - changed_prefs.chipset_mask = currprefs.chipset_mask = RL; - update_mirrors (); - RW; /* 000 BLTDDAT */ - RW; /* 002 DMACONR */ - RW; /* 004 VPOSR */ - RW; /* 006 VHPOSR */ - RW; /* 008 DSKDATR (dummy register) */ - RW; /* 00A JOY0DAT */ - RW; /* 00C JOY1DAT */ - clxdat = RW; /* 00E CLXDAT */ - RW; /* 010 ADKCONR */ - RW; /* 012 POT0DAT* */ - RW; /* 014 POT1DAT* */ - RW; /* 016 POTINP* */ - RW; /* 018 SERDATR* */ - dskbytr = RW; /* 01A DSKBYTR */ - RW; /* 01C INTENAR */ - RW; /* 01E INTREQR */ - dskpt = RL; /* 020-022 DSKPT */ - dsklen = RW; /* 024 DSKLEN */ - RW; /* 026 DSKDAT */ - RW; /* 028 REFPTR */ - i = RW; lof = (i & 0x8000) ? 1 : 0; lol = (i & 0x0080); /* 02A VPOSW */ - RW; /* 02C VHPOSW */ - COPCON (RW); /* 02E COPCON */ - RW; /* 030 SERDAT* */ - RW; /* 032 SERPER* */ - POTGO (RW); /* 034 POTGO */ - RW; /* 036 JOYTEST* */ - RW; /* 038 STREQU */ - RW; /* 03A STRVHBL */ - RW; /* 03C STRHOR */ - RW; /* 03E STRLONG */ - BLTCON0 (0, RW); /* 040 BLTCON0 */ - BLTCON1 (0, RW); /* 042 BLTCON1 */ - BLTAFWM (0, RW); /* 044 BLTAFWM */ - BLTALWM (0, RW); /* 046 BLTALWM */ - BLTCPTH (0, RL); /* 048-04B BLTCPT */ - BLTBPTH (0, RL); /* 04C-04F BLTBPT */ - BLTAPTH (0, RL); /* 050-053 BLTAPT */ - BLTDPTH (0, RL); /* 054-057 BLTDPT */ - RW; /* 058 BLTSIZE */ - RW; /* 05A BLTCON0L */ - blt_info.vblitsize = RW; /* 05C BLTSIZV */ - blt_info.hblitsize = RW; /* 05E BLTSIZH */ - BLTCMOD (0, RW); /* 060 BLTCMOD */ - BLTBMOD (0, RW); /* 062 BLTBMOD */ - BLTAMOD (0, RW); /* 064 BLTAMOD */ - BLTDMOD (0, RW); /* 066 BLTDMOD */ - RW; /* 068 ? */ - RW; /* 06A ? */ - RW; /* 06C ? */ - RW; /* 06E ? */ - BLTCDAT (0, RW); /* 070 BLTCDAT */ - BLTBDAT (0, RW); /* 072 BLTBDAT */ - BLTADAT (0, RW); /* 074 BLTADAT */ - RW; /* 076 ? */ - RW; /* 078 ? */ - RW; /* 07A ? */ - RW; /* 07C LISAID */ - DSKSYNC (-1, RW); /* 07E DSKSYNC */ - cop1lc = RL; /* 080/082 COP1LC */ - cop2lc = RL; /* 084/086 COP2LC */ - RW; /* 088 ? */ - RW; /* 08A ? */ - RW; /* 08C ? */ - diwstrt = RW; /* 08E DIWSTRT */ - diwstop = RW; /* 090 DIWSTOP */ - ddfstrt = RW; /* 092 DDFSTRT */ - ddfstop = RW; /* 094 DDFSTOP */ - dmacon = RW & ~(0x2000|0x4000); /* 096 DMACON */ - CLXCON (RW); /* 098 CLXCON */ - intena = RW; /* 09A INTENA */ - intreq = intreqr = RW | 0x20; /* 09C INTREQ */ - adkcon = RW; /* 09E ADKCON */ - for (i = 0; i < 8; i++) - bplptx[i] = bplpt[i] = RL; - bplcon0 = RW; /* 100 BPLCON0 */ - bplcon1 = RW; /* 102 BPLCON1 */ - bplcon2 = RW; /* 104 BPLCON2 */ - bplcon3 = RW; /* 106 BPLCON3 */ - bpl1mod = RW; /* 108 BPL1MOD */ - bpl2mod = RW; /* 10A BPL2MOD */ - bplcon4 = RW; /* 10C BPLCON4 */ - clxcon2 = RW; /* 10E CLXCON2* */ - for(i = 0; i < 8; i++) - bplxdat[i] = RW; /* BPLXDAT */ - for(i = 0; i < 32; i++) - current_colors.color_regs_ecs[i] = RW; /* 180 COLORxx */ - htotal = RW; /* 1C0 HTOTAL */ - hsstop = RW; /* 1C2 HSTOP ? */ - hbstrt = RW; /* 1C4 HBSTRT ? */ - hbstop = RW; /* 1C6 HBSTOP ? */ - vtotal = RW; /* 1C8 VTOTAL */ - vsstop = RW; /* 1CA VSSTOP */ - vbstrt = RW; /* 1CC VBSTRT */ - vbstop = RW; /* 1CE VBSTOP */ - RW; /* 1D0 ? */ - RW; /* 1D2 ? */ - RW; /* 1D4 ? */ - RW; /* 1D6 ? */ - RW; /* 1D8 ? */ - RW; /* 1DA ? */ - new_beamcon0 = RW; /* 1DC BEAMCON0 */ - hsstrt = RW; /* 1DE HSSTRT */ - vsstrt = RW; /* 1E0 VSSTT */ - hcenter = RW; /* 1E2 HCENTER */ - diwhigh = RW; /* 1E4 DIWHIGH */ - diwhigh_written = (diwhigh & 0x8000) ? 1 : 0; - diwhigh &= 0x7fff; - RW; /* 1E6 ? */ - RW; /* 1E8 ? */ - RW; /* 1EA ? */ - RW; /* 1EC ? */ - RW; /* 1EE ? */ - RW; /* 1F0 ? */ - RW; /* 1F2 ? */ - RW; /* 1F4 ? */ - RW; /* 1F6 ? */ - RW; /* 1F8 ? */ - RW; /* 1FA ? */ - fmode = RW; /* 1FC FMODE */ - last_custom_value1 = RW; /* 1FE ? */ - - DISK_restore_custom (dskpt, dsklen, dskbytr); - - return src; + uae_u16 dsklen, dskbytr; + int dskpt; + int i; + + audio_reset (); + + changed_prefs.chipset_mask = currprefs.chipset_mask = RL; + update_mirrors (); + RW; /* 000 BLTDDAT */ + RW; /* 002 DMACONR */ + RW; /* 004 VPOSR */ + RW; /* 006 VHPOSR */ + RW; /* 008 DSKDATR (dummy register) */ + RW; /* 00A JOY0DAT */ + RW; /* 00C JOY1DAT */ + clxdat = RW; /* 00E CLXDAT */ + RW; /* 010 ADKCONR */ + RW; /* 012 POT0DAT* */ + RW; /* 014 POT1DAT* */ + RW; /* 016 POTINP* */ + RW; /* 018 SERDATR* */ + dskbytr = RW; /* 01A DSKBYTR */ + RW; /* 01C INTENAR */ + RW; /* 01E INTREQR */ + dskpt = RL; /* 020-022 DSKPT */ + dsklen = RW; /* 024 DSKLEN */ + RW; /* 026 DSKDAT */ + RW; /* 028 REFPTR */ + i = RW; lof = (i & 0x8000) ? 1 : 0; lol = (i & 0x0080); /* 02A VPOSW */ + RW; /* 02C VHPOSW */ + COPCON (RW); /* 02E COPCON */ + RW; /* 030 SERDAT* */ + RW; /* 032 SERPER* */ + POTGO (RW); /* 034 POTGO */ + RW; /* 036 JOYTEST* */ + RW; /* 038 STREQU */ + RW; /* 03A STRVHBL */ + RW; /* 03C STRHOR */ + RW; /* 03E STRLONG */ + BLTCON0 (0, RW); /* 040 BLTCON0 */ + BLTCON1 (0, RW); /* 042 BLTCON1 */ + BLTAFWM (0, RW); /* 044 BLTAFWM */ + BLTALWM (0, RW); /* 046 BLTALWM */ + BLTCPTH (0, RW);BLTCPTL(0, RW); /* 048-04B BLTCPT */ + BLTBPTH (0, RW);BLTBPTL(0, RW); /* 04C-04F BLTBPT */ + BLTAPTH (0, RW);BLTAPTL(0, RW); /* 050-053 BLTAPT */ + BLTDPTH (0, RW);BLTDPTL(0, RW); /* 054-057 BLTDPT */ + RW; /* 058 BLTSIZE */ + RW; /* 05A BLTCON0L */ + blt_info.vblitsize = RW; /* 05C BLTSIZV */ + blt_info.hblitsize = RW; /* 05E BLTSIZH */ + BLTCMOD (0, RW); /* 060 BLTCMOD */ + BLTBMOD (0, RW); /* 062 BLTBMOD */ + BLTAMOD (0, RW); /* 064 BLTAMOD */ + BLTDMOD (0, RW); /* 066 BLTDMOD */ + RW; /* 068 ? */ + RW; /* 06A ? */ + RW; /* 06C ? */ + RW; /* 06E ? */ + BLTCDAT (0, RW); /* 070 BLTCDAT */ + BLTBDAT (0, RW); /* 072 BLTBDAT */ + BLTADAT (0, RW); /* 074 BLTADAT */ + RW; /* 076 ? */ + RW; /* 078 ? */ + RW; /* 07A ? */ + RW; /* 07C LISAID */ + DSKSYNC (-1, RW); /* 07E DSKSYNC */ + cop1lc = RL; /* 080/082 COP1LC */ + cop2lc = RL; /* 084/086 COP2LC */ + RW; /* 088 ? */ + RW; /* 08A ? */ + RW; /* 08C ? */ + diwstrt = RW; /* 08E DIWSTRT */ + diwstop = RW; /* 090 DIWSTOP */ + ddfstrt = RW; /* 092 DDFSTRT */ + ddfstop = RW; /* 094 DDFSTOP */ + dmacon = RW & ~(0x2000|0x4000); /* 096 DMACON */ + CLXCON (RW); /* 098 CLXCON */ + intena = RW; /* 09A INTENA */ + intreq = intreqr = RW | 0x20; /* 09C INTREQ */ + adkcon = RW; /* 09E ADKCON */ + for (i = 0; i < 8; i++) + bplptx[i] = bplpt[i] = RL; + bplcon0 = RW; /* 100 BPLCON0 */ + bplcon1 = RW; /* 102 BPLCON1 */ + bplcon2 = RW; /* 104 BPLCON2 */ + bplcon3 = RW; /* 106 BPLCON3 */ + bpl1mod = RW; /* 108 BPL1MOD */ + bpl2mod = RW; /* 10A BPL2MOD */ + bplcon4 = RW; /* 10C BPLCON4 */ + clxcon2 = RW; /* 10E CLXCON2* */ + for(i = 0; i < 8; i++) + bplxdat[i] = RW; /* BPLXDAT */ + for(i = 0; i < 32; i++) + current_colors.color_regs_ecs[i] = RW; /* 180 COLORxx */ + htotal = RW; /* 1C0 HTOTAL */ + hsstop = RW; /* 1C2 HSTOP ? */ + hbstrt = RW; /* 1C4 HBSTRT ? */ + hbstop = RW; /* 1C6 HBSTOP ? */ + vtotal = RW; /* 1C8 VTOTAL */ + vsstop = RW; /* 1CA VSSTOP */ + vbstrt = RW; /* 1CC VBSTRT */ + vbstop = RW; /* 1CE VBSTOP */ + RW; /* 1D0 ? */ + RW; /* 1D2 ? */ + RW; /* 1D4 ? */ + RW; /* 1D6 ? */ + RW; /* 1D8 ? */ + RW; /* 1DA ? */ + new_beamcon0 = RW; /* 1DC BEAMCON0 */ + hsstrt = RW; /* 1DE HSSTRT */ + vsstrt = RW; /* 1E0 VSSTT */ + hcenter = RW; /* 1E2 HCENTER */ + diwhigh = RW; /* 1E4 DIWHIGH */ + diwhigh_written = (diwhigh & 0x8000) ? 1 : 0; + diwhigh &= 0x7fff; + RW; /* 1E6 ? */ + RW; /* 1E8 ? */ + RW; /* 1EA ? */ + RW; /* 1EC ? */ + RW; /* 1EE ? */ + RW; /* 1F0 ? */ + RW; /* 1F2 ? */ + RW; /* 1F4 ? */ + RW; /* 1F6 ? */ + RW; /* 1F8 ? */ + RW; /* 1FA ? */ + fmode = RW; /* 1FC FMODE */ + last_custom_value1 = RW; /* 1FE ? */ + + DISK_restore_custom (dskpt, dsklen, dskbytr); + + return src; } #endif /* SAVESTATE */ @@ -6376,163 +6385,163 @@ extern uae_u16 serper; uae_u8 *save_custom (int *len, uae_u8 *dstptr, int full) { - uae_u8 *dstbak, *dst; - int i; - uae_u32 dskpt; - uae_u16 dsklen, dsksync, dskbytr; - - DISK_save_custom (&dskpt, &dsklen, &dsksync, &dskbytr); - - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = malloc (8 + 256 * 2); - - SL (currprefs.chipset_mask); - SW (0); /* 000 BLTDDAT */ - SW (dmacon); /* 002 DMACONR */ - SW (VPOSR ()); /* 004 VPOSR */ - SW (VHPOSR ()); /* 006 VHPOSR */ - SW (0); /* 008 DSKDATR */ - SW (JOY0DAT ()); /* 00A JOY0DAT */ - SW (JOY1DAT ()); /* 00C JOY1DAT */ - SW (clxdat | 0x8000); /* 00E CLXDAT */ - SW (ADKCONR ()); /* 010 ADKCONR */ - SW (POT0DAT ()); /* 012 POT0DAT */ - SW (POT0DAT ()); /* 014 POT1DAT */ - SW (0) ; /* 016 POTINP * */ - SW (0); /* 018 SERDATR * */ - SW (dskbytr); /* 01A DSKBYTR */ - SW (INTENAR ()); /* 01C INTENAR */ - SW (INTREQR ()); /* 01E INTREQR */ - SL (dskpt); /* 020-023 DSKPT */ - SW (dsklen); /* 024 DSKLEN */ - SW (0); /* 026 DSKDAT */ - SW (0); /* 028 REFPTR */ - SW ((lof ? 0x8001 : 0) | (lol ? 0x0080 : 0));/* 02A VPOSW */ - SW (0); /* 02C VHPOSW */ - SW (copcon); /* 02E COPCON */ - SW (serper); /* 030 SERDAT * */ - SW (serdat); /* 032 SERPER * */ - SW (potgo_value); /* 034 POTGO */ - SW (0); /* 036 JOYTEST * */ - SW (0); /* 038 STREQU */ - SW (0); /* 03A STRVBL */ - SW (0); /* 03C STRHOR */ - SW (0); /* 03E STRLONG */ - SW (bltcon0); /* 040 BLTCON0 */ - SW (bltcon1); /* 042 BLTCON1 */ - SW (blt_info.bltafwm); /* 044 BLTAFWM */ - SW (blt_info.bltalwm); /* 046 BLTALWM */ - SL (bltcpt); /* 048-04B BLTCPT */ - SL (bltbpt); /* 04C-04F BLTCPT */ - SL (bltapt); /* 050-053 BLTCPT */ - SL (bltdpt); /* 054-057 BLTCPT */ - SW (0); /* 058 BLTSIZE */ - SW (0); /* 05A BLTCON0L (use BLTCON0 instead) */ - SW (blt_info.vblitsize); /* 05C BLTSIZV */ - SW (blt_info.hblitsize); /* 05E BLTSIZH */ - SW (blt_info.bltcmod); /* 060 BLTCMOD */ - SW (blt_info.bltbmod); /* 062 BLTBMOD */ - SW (blt_info.bltamod); /* 064 BLTAMOD */ - SW (blt_info.bltdmod); /* 066 BLTDMOD */ - SW (0); /* 068 ? */ - SW (0); /* 06A ? */ - SW (0); /* 06C ? */ - SW (0); /* 06E ? */ - SW (blt_info.bltcdat); /* 070 BLTCDAT */ - SW (blt_info.bltbdat); /* 072 BLTBDAT */ - SW (blt_info.bltadat); /* 074 BLTADAT */ - SW (0); /* 076 ? */ - SW (0); /* 078 ? */ - SW (0); /* 07A ? */ - SW (DENISEID ()); /* 07C DENISEID/LISAID */ - SW (dsksync); /* 07E DSKSYNC */ - SL (cop1lc); /* 080-083 COP1LC */ - SL (cop2lc); /* 084-087 COP2LC */ - SW (0); /* 088 ? */ - SW (0); /* 08A ? */ - SW (0); /* 08C ? */ - SW (diwstrt); /* 08E DIWSTRT */ - SW (diwstop); /* 090 DIWSTOP */ - SW (ddfstrt); /* 092 DDFSTRT */ - SW (ddfstop); /* 094 DDFSTOP */ - SW (dmacon); /* 096 DMACON */ - SW (clxcon); /* 098 CLXCON */ - SW (intena); /* 09A INTENA */ - SW (intreq); /* 09C INTREQ */ - SW (adkcon); /* 09E ADKCON */ - for (i = 0; full && i < 32; i++) - SW (0); - for (i = 0; i < 8; i++) - SL (bplpt[i]); /* 0E0-0FE BPLxPT */ - SW (bplcon0); /* 100 BPLCON0 */ - SW (bplcon1); /* 102 BPLCON1 */ - SW (bplcon2); /* 104 BPLCON2 */ - SW (bplcon3); /* 106 BPLCON3 */ - SW (bpl1mod); /* 108 BPL1MOD */ - SW (bpl2mod); /* 10A BPL2MOD */ - SW (bplcon4); /* 10C BPLCON4 */ - SW (clxcon2); /* 10E CLXCON2 */ - for (i = 0;i < 8; i++) - SW (bplxdat[i]); /* 110 BPLxDAT */ - if (full) { - for (i = 0; i < 8; i++) { - SL (spr[i].pt); /* 120-13E SPRxPT */ - SW (sprpos[i]); /* 1x0 SPRxPOS */ - SW (sprctl[i]); /* 1x2 SPRxPOS */ - SW (sprdata[i][0]); /* 1x4 SPRxDATA */ - SW (sprdatb[i][0]); /* 1x6 SPRxDATB */ - } - } - for ( i = 0; i < 32; i++) { - if (currprefs.chipset_mask & CSMASK_AGA) { - uae_u32 v = current_colors.color_regs_aga[i]; - uae_u16 v2; - v &= 0x00f0f0f0; - v2 = (v >> 4) & 15; - v2 |= ((v >> 12) & 15) << 4; - v2 |= ((v >> 20) & 15) << 8; - SW (v2); - } else { - SW (current_colors.color_regs_ecs[i]); /* 180-1BE COLORxx */ - } - } - SW (htotal); /* 1C0 HTOTAL */ - SW (hsstop); /* 1C2 HSTOP*/ - SW (hbstrt); /* 1C4 HBSTRT */ - SW (hbstop); /* 1C6 HBSTOP */ - SW (vtotal); /* 1C8 VTOTAL */ - SW (vsstop); /* 1CA VSSTOP */ - SW (vbstrt); /* 1CC VBSTRT */ - SW (vbstop); /* 1CE VBSTOP */ - SW (0); /* 1D0 */ - SW (0); /* 1D2 */ - SW (0); /* 1D4 */ - SW (0); /* 1D6 */ - SW (0); /* 1D8 */ - SW (0); /* 1DA */ - SW (beamcon0); /* 1DC BEAMCON0 */ - SW (hsstrt); /* 1DE HSSTRT */ - SW (vsstrt); /* 1E0 VSSTRT */ - SW (hcenter); /* 1E2 HCENTER */ - SW (diwhigh | (diwhigh_written ? 0x8000 : 0)); /* 1E4 DIWHIGH */ - SW (0); /* 1E6 */ - SW (0); /* 1E8 */ - SW (0); /* 1EA */ - SW (0); /* 1EC */ - SW (0); /* 1EE */ - SW (0); /* 1F0 */ - SW (0); /* 1F2 */ - SW (0); /* 1F4 */ - SW (0); /* 1F6 */ - SW (0); /* 1F8 */ - SW (0); /* 1FA */ - SW (fmode); /* 1FC FMODE */ - SW (last_custom_value1); /* 1FE */ - - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + int i; + uae_u32 dskpt; + uae_u16 dsklen, dsksync, dskbytr; + + DISK_save_custom (&dskpt, &dsklen, &dsksync, &dskbytr); + + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (8 + 256 * 2); + + SL (currprefs.chipset_mask); + SW (0); /* 000 BLTDDAT */ + SW (dmacon); /* 002 DMACONR */ + SW (VPOSR ()); /* 004 VPOSR */ + SW (VHPOSR ()); /* 006 VHPOSR */ + SW (0); /* 008 DSKDATR */ + SW (JOY0DAT ()); /* 00A JOY0DAT */ + SW (JOY1DAT ()); /* 00C JOY1DAT */ + SW (clxdat | 0x8000); /* 00E CLXDAT */ + SW (ADKCONR ()); /* 010 ADKCONR */ + SW (POT0DAT ()); /* 012 POT0DAT */ + SW (POT0DAT ()); /* 014 POT1DAT */ + SW (0) ; /* 016 POTINP * */ + SW (0); /* 018 SERDATR * */ + SW (dskbytr); /* 01A DSKBYTR */ + SW (INTENAR ()); /* 01C INTENAR */ + SW (INTREQR ()); /* 01E INTREQR */ + SL (dskpt); /* 020-023 DSKPT */ + SW (dsklen); /* 024 DSKLEN */ + SW (0); /* 026 DSKDAT */ + SW (0); /* 028 REFPTR */ + SW ((lof ? 0x8001 : 0) | (lol ? 0x0080 : 0));/* 02A VPOSW */ + SW (0); /* 02C VHPOSW */ + SW (copcon); /* 02E COPCON */ + SW (serper); /* 030 SERDAT * */ + SW (serdat); /* 032 SERPER * */ + SW (potgo_value); /* 034 POTGO */ + SW (0); /* 036 JOYTEST * */ + SW (0); /* 038 STREQU */ + SW (0); /* 03A STRVBL */ + SW (0); /* 03C STRHOR */ + SW (0); /* 03E STRLONG */ + SW (bltcon0); /* 040 BLTCON0 */ + SW (bltcon1); /* 042 BLTCON1 */ + SW (blt_info.bltafwm); /* 044 BLTAFWM */ + SW (blt_info.bltalwm); /* 046 BLTALWM */ + SL (bltcpt); /* 048-04B BLTCPT */ + SL (bltbpt); /* 04C-04F BLTCPT */ + SL (bltapt); /* 050-053 BLTCPT */ + SL (bltdpt); /* 054-057 BLTCPT */ + SW (0); /* 058 BLTSIZE */ + SW (0); /* 05A BLTCON0L (use BLTCON0 instead) */ + SW (blt_info.vblitsize); /* 05C BLTSIZV */ + SW (blt_info.hblitsize); /* 05E BLTSIZH */ + SW (blt_info.bltcmod); /* 060 BLTCMOD */ + SW (blt_info.bltbmod); /* 062 BLTBMOD */ + SW (blt_info.bltamod); /* 064 BLTAMOD */ + SW (blt_info.bltdmod); /* 066 BLTDMOD */ + SW (0); /* 068 ? */ + SW (0); /* 06A ? */ + SW (0); /* 06C ? */ + SW (0); /* 06E ? */ + SW (blt_info.bltcdat); /* 070 BLTCDAT */ + SW (blt_info.bltbdat); /* 072 BLTBDAT */ + SW (blt_info.bltadat); /* 074 BLTADAT */ + SW (0); /* 076 ? */ + SW (0); /* 078 ? */ + SW (0); /* 07A ? */ + SW (DENISEID ()); /* 07C DENISEID/LISAID */ + SW (dsksync); /* 07E DSKSYNC */ + SL (cop1lc); /* 080-083 COP1LC */ + SL (cop2lc); /* 084-087 COP2LC */ + SW (0); /* 088 ? */ + SW (0); /* 08A ? */ + SW (0); /* 08C ? */ + SW (diwstrt); /* 08E DIWSTRT */ + SW (diwstop); /* 090 DIWSTOP */ + SW (ddfstrt); /* 092 DDFSTRT */ + SW (ddfstop); /* 094 DDFSTOP */ + SW (dmacon); /* 096 DMACON */ + SW (clxcon); /* 098 CLXCON */ + SW (intena); /* 09A INTENA */ + SW (intreq); /* 09C INTREQ */ + SW (adkcon); /* 09E ADKCON */ + for (i = 0; full && i < 32; i++) + SW (0); + for (i = 0; i < 8; i++) + SL (bplpt[i]); /* 0E0-0FE BPLxPT */ + SW (bplcon0); /* 100 BPLCON0 */ + SW (bplcon1); /* 102 BPLCON1 */ + SW (bplcon2); /* 104 BPLCON2 */ + SW (bplcon3); /* 106 BPLCON3 */ + SW (bpl1mod); /* 108 BPL1MOD */ + SW (bpl2mod); /* 10A BPL2MOD */ + SW (bplcon4); /* 10C BPLCON4 */ + SW (clxcon2); /* 10E CLXCON2 */ + for (i = 0;i < 8; i++) + SW (bplxdat[i]); /* 110 BPLxDAT */ + if (full) { + for (i = 0; i < 8; i++) { + SL (spr[i].pt); /* 120-13E SPRxPT */ + SW (sprpos[i]); /* 1x0 SPRxPOS */ + SW (sprctl[i]); /* 1x2 SPRxPOS */ + SW (sprdata[i][0]); /* 1x4 SPRxDATA */ + SW (sprdatb[i][0]); /* 1x6 SPRxDATB */ + } + } + for ( i = 0; i < 32; i++) { + if (currprefs.chipset_mask & CSMASK_AGA) { + uae_u32 v = current_colors.color_regs_aga[i]; + uae_u16 v2; + v &= 0x00f0f0f0; + v2 = (v >> 4) & 15; + v2 |= ((v >> 12) & 15) << 4; + v2 |= ((v >> 20) & 15) << 8; + SW (v2); + } else { + SW (current_colors.color_regs_ecs[i]); /* 180-1BE COLORxx */ + } + } + SW (htotal); /* 1C0 HTOTAL */ + SW (hsstop); /* 1C2 HSTOP*/ + SW (hbstrt); /* 1C4 HBSTRT */ + SW (hbstop); /* 1C6 HBSTOP */ + SW (vtotal); /* 1C8 VTOTAL */ + SW (vsstop); /* 1CA VSSTOP */ + SW (vbstrt); /* 1CC VBSTRT */ + SW (vbstop); /* 1CE VBSTOP */ + SW (0); /* 1D0 */ + SW (0); /* 1D2 */ + SW (0); /* 1D4 */ + SW (0); /* 1D6 */ + SW (0); /* 1D8 */ + SW (0); /* 1DA */ + SW (beamcon0); /* 1DC BEAMCON0 */ + SW (hsstrt); /* 1DE HSSTRT */ + SW (vsstrt); /* 1E0 VSSTRT */ + SW (hcenter); /* 1E2 HCENTER */ + SW (diwhigh | (diwhigh_written ? 0x8000 : 0)); /* 1E4 DIWHIGH */ + SW (0); /* 1E6 */ + SW (0); /* 1E8 */ + SW (0); /* 1EA */ + SW (0); /* 1EC */ + SW (0); /* 1EE */ + SW (0); /* 1F0 */ + SW (0); /* 1F2 */ + SW (0); /* 1F4 */ + SW (0); /* 1F6 */ + SW (0); /* 1F8 */ + SW (0); /* 1FA */ + SW (fmode); /* 1FC FMODE */ + SW (last_custom_value1); /* 1FE */ + + *len = dst - dstbak; + return dstbak; } #endif /* SAVESTATE || DEBUGGER */ @@ -6541,131 +6550,131 @@ uae_u8 *save_custom (int *len, uae_u8 *dstptr, int full) uae_u8 *restore_custom_agacolors (uae_u8 *src) { - int i; + int i; - for (i = 0; i < 256; i++) { + for (i = 0; i < 256; i++) { #ifdef AGA - uae_u32 v = RL; - color_regs_aga_genlock[i] = 0; - if (v & 0x80000000) - color_regs_aga_genlock[i] = 1; - v &= 0x00ffffff; - current_colors.color_regs_aga[i] = v; + uae_u32 v = RL; + color_regs_aga_genlock[i] = 0; + if (v & 0x80000000) + color_regs_aga_genlock[i] = 1; + v &= 0x00ffffff; + current_colors.color_regs_aga[i] = v; #else - RL; + RL; #endif - } - return src; + } + return src; } uae_u8 *save_custom_agacolors (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; - int i; + uae_u8 *dstbak, *dst; + int i; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (256*4); - for (i = 0; i < 256; i++) + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (256*4); + for (i = 0; i < 256; i++) #ifdef AGA - SL (current_colors.color_regs_aga[i] | (color_regs_aga_genlock[i] ? 0x80000000 : 0)); + SL (current_colors.color_regs_aga[i] | (color_regs_aga_genlock[i] ? 0x80000000 : 0)); #else - SL (0); + SL (0); #endif - *len = dst - dstbak; - return dstbak; + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_custom_sprite (int num, uae_u8 *src) { - spr[num].pt = RL; /* 120-13E SPRxPT */ - sprpos[num] = RW; /* 1x0 SPRxPOS */ - sprctl[num] = RW; /* 1x2 SPRxPOS */ - sprdata[num][0] = RW; /* 1x4 SPRxDATA */ - sprdatb[num][0] = RW; /* 1x6 SPRxDATB */ - sprdata[num][1] = RW; - sprdatb[num][1] = RW; - sprdata[num][2] = RW; - sprdatb[num][2] = RW; - sprdata[num][3] = RW; - sprdatb[num][3] = RW; - spr[num].armed = RB; - return src; + spr[num].pt = RL; /* 120-13E SPRxPT */ + sprpos[num] = RW; /* 1x0 SPRxPOS */ + sprctl[num] = RW; /* 1x2 SPRxPOS */ + sprdata[num][0] = RW; /* 1x4 SPRxDATA */ + sprdatb[num][0] = RW; /* 1x6 SPRxDATB */ + sprdata[num][1] = RW; + sprdatb[num][1] = RW; + sprdata[num][2] = RW; + sprdatb[num][2] = RW; + sprdata[num][3] = RW; + sprdatb[num][3] = RW; + spr[num].armed = RB; + return src; } uae_u8 *save_custom_sprite(int num, int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; - - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (30); - SL (spr[num].pt); /* 120-13E SPRxPT */ - SW (sprpos[num]); /* 1x0 SPRxPOS */ - SW (sprctl[num]); /* 1x2 SPRxPOS */ - SW (sprdata[num][0]); /* 1x4 SPRxDATA */ - SW (sprdatb[num][0]); /* 1x6 SPRxDATB */ - SW (sprdata[num][1]); - SW (sprdatb[num][1]); - SW (sprdata[num][2]); - SW (sprdatb[num][2]); - SW (sprdata[num][3]); - SW (sprdatb[num][3]); - SB (spr[num].armed ? 1 : 0); - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (30); + SL (spr[num].pt); /* 120-13E SPRxPT */ + SW (sprpos[num]); /* 1x0 SPRxPOS */ + SW (sprctl[num]); /* 1x2 SPRxPOS */ + SW (sprdata[num][0]); /* 1x4 SPRxDATA */ + SW (sprdatb[num][0]); /* 1x6 SPRxDATB */ + SW (sprdata[num][1]); + SW (sprdatb[num][1]); + SW (sprdata[num][2]); + SW (sprdatb[num][2]); + SW (sprdata[num][3]); + SW (sprdatb[num][3]); + SB (spr[num].armed ? 1 : 0); + *len = dst - dstbak; + return dstbak; } #endif /* SAVESTATE */ void check_prefs_changed_custom (void) { - currprefs.gfx_framerate = changed_prefs.gfx_framerate; - if (inputdevice_config_change_test ()) - inputdevice_copyconfig (&changed_prefs, &currprefs); - currprefs.immediate_blits = changed_prefs.immediate_blits; - currprefs.collision_level = changed_prefs.collision_level; - - currprefs.cs_ciaatod = changed_prefs.cs_ciaatod; - currprefs.cs_rtc = changed_prefs.cs_rtc; - currprefs.cs_cd32cd = changed_prefs.cs_cd32cd; - currprefs.cs_cd32c2p = changed_prefs.cs_cd32c2p; - currprefs.cs_cd32nvram = changed_prefs.cs_cd32nvram; - currprefs.cs_cdtvcd = changed_prefs.cs_cdtvcd; - currprefs.cs_ide = changed_prefs.cs_ide; - currprefs.cs_pcmcia = changed_prefs.cs_pcmcia; - currprefs.cs_fatgaryrev = changed_prefs.cs_fatgaryrev; - currprefs.cs_ramseyrev = changed_prefs.cs_ramseyrev; - currprefs.cs_agnusrev = changed_prefs.cs_agnusrev; - currprefs.cs_deniserev = changed_prefs.cs_deniserev; - currprefs.cs_mbdmac = changed_prefs.cs_mbdmac; - currprefs.cs_df0idhw = changed_prefs.cs_df0idhw; - currprefs.cs_slowmemisfast = changed_prefs.cs_slowmemisfast; - - if (currprefs.chipset_mask != changed_prefs.chipset_mask || - currprefs.gfx_avsync != changed_prefs.gfx_avsync || - currprefs.gfx_pvsync != changed_prefs.gfx_pvsync || - currprefs.picasso96_nocustom != changed_prefs.picasso96_nocustom || - currprefs.ntscmode != changed_prefs.ntscmode) { - currprefs.picasso96_nocustom = changed_prefs.picasso96_nocustom; - currprefs.gfx_avsync = changed_prefs.gfx_avsync; - currprefs.gfx_pvsync = changed_prefs.gfx_pvsync; - currprefs.chipset_mask = changed_prefs.chipset_mask; - if (currprefs.ntscmode != changed_prefs.ntscmode) { - currprefs.ntscmode = changed_prefs.ntscmode; - new_beamcon0 = currprefs.ntscmode ? 0x00 : 0x20; - } - init_custom (); - } + currprefs.gfx_framerate = changed_prefs.gfx_framerate; + if (inputdevice_config_change_test ()) + inputdevice_copyconfig (&changed_prefs, &currprefs); + currprefs.immediate_blits = changed_prefs.immediate_blits; + currprefs.collision_level = changed_prefs.collision_level; + + currprefs.cs_ciaatod = changed_prefs.cs_ciaatod; + currprefs.cs_rtc = changed_prefs.cs_rtc; + currprefs.cs_cd32cd = changed_prefs.cs_cd32cd; + currprefs.cs_cd32c2p = changed_prefs.cs_cd32c2p; + currprefs.cs_cd32nvram = changed_prefs.cs_cd32nvram; + currprefs.cs_cdtvcd = changed_prefs.cs_cdtvcd; + currprefs.cs_ide = changed_prefs.cs_ide; + currprefs.cs_pcmcia = changed_prefs.cs_pcmcia; + currprefs.cs_fatgaryrev = changed_prefs.cs_fatgaryrev; + currprefs.cs_ramseyrev = changed_prefs.cs_ramseyrev; + currprefs.cs_agnusrev = changed_prefs.cs_agnusrev; + currprefs.cs_deniserev = changed_prefs.cs_deniserev; + currprefs.cs_mbdmac = changed_prefs.cs_mbdmac; + currprefs.cs_df0idhw = changed_prefs.cs_df0idhw; + currprefs.cs_slowmemisfast = changed_prefs.cs_slowmemisfast; + + if (currprefs.chipset_mask != changed_prefs.chipset_mask || + currprefs.gfx_avsync != changed_prefs.gfx_avsync || + currprefs.gfx_pvsync != changed_prefs.gfx_pvsync || + currprefs.picasso96_nocustom != changed_prefs.picasso96_nocustom || + currprefs.ntscmode != changed_prefs.ntscmode) { + currprefs.picasso96_nocustom = changed_prefs.picasso96_nocustom; + currprefs.gfx_avsync = changed_prefs.gfx_avsync; + currprefs.gfx_pvsync = changed_prefs.gfx_pvsync; + currprefs.chipset_mask = changed_prefs.chipset_mask; + if (currprefs.ntscmode != changed_prefs.ntscmode) { + currprefs.ntscmode = changed_prefs.ntscmode; + new_beamcon0 = currprefs.ntscmode ? 0x00 : 0x20; + } + init_custom (); + } #ifdef GFXFILTER - currprefs.gfx_filter_horiz_zoom = changed_prefs.gfx_filter_horiz_zoom; - currprefs.gfx_filter_vert_zoom = changed_prefs.gfx_filter_vert_zoom; - currprefs.gfx_filter_horiz_offset = changed_prefs.gfx_filter_horiz_offset; - currprefs.gfx_filter_vert_offset = changed_prefs.gfx_filter_vert_offset; - currprefs.gfx_filter_scanlines = changed_prefs.gfx_filter_scanlines; - currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode; + currprefs.gfx_filter_horiz_zoom = changed_prefs.gfx_filter_horiz_zoom; + currprefs.gfx_filter_vert_zoom = changed_prefs.gfx_filter_vert_zoom; + currprefs.gfx_filter_horiz_offset = changed_prefs.gfx_filter_horiz_offset; + currprefs.gfx_filter_vert_offset = changed_prefs.gfx_filter_vert_offset; + currprefs.gfx_filter_scanlines = changed_prefs.gfx_filter_scanlines; + currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode; #endif } @@ -6673,14 +6682,14 @@ void check_prefs_changed_custom (void) STATIC_INLINE void sync_copper (int hpos) { - if (copper_enabled_thisline) - update_copper (hpos); + if (copper_enabled_thisline) + update_copper (hpos); } STATIC_INLINE void decide_fetch_ce (int hpos) { - if ((ddf_change == vpos || ddf_change + 1 == vpos) && vpos < maxvpos) - decide_fetch (hpos); + if ((ddf_change == vpos || ddf_change + 1 == vpos) && vpos < maxvpos) + decide_fetch (hpos); } #define BLIT_NASTY 4 @@ -6691,112 +6700,125 @@ STATIC_INLINE void decide_fetch_ce (int hpos) STATIC_INLINE int dma_cycle (void) { - int hpos, hpos_old; - - blitter_nasty = 1; - for (;;) { - int bpldma; - int blitpri = dmacon & DMA_BLITPRI; - hpos_old = current_hpos (); - hpos = hpos_old + 1; - sync_copper (hpos); - decide_line (hpos); - decide_fetch_ce (hpos); - bpldma = is_bitplane_dma (hpos_old); - if (bltstate != BLT_done) { - if (!blitpri && blitter_nasty >= BLIT_NASTY && cycle_line[hpos_old] == 0 && !bpldma) { - alloc_cycle (hpos_old, CYCLE_CPUNASTY); - break; - } - decide_blitter (hpos); - // copper may have been waiting for the blitter - sync_copper (hpos); - } - if (cycle_line[hpos_old] == 0 && !bpldma) { - alloc_cycle (hpos_old, CYCLE_CPU); - break; + int hpos, hpos_old; + + blitter_nasty = 1; + for (;;) { + int bpldma; + int blitpri = dmacon & DMA_BLITPRI; + hpos_old = current_hpos (); + hpos = hpos_old + 1; + sync_copper (hpos); + decide_line (hpos); + decide_fetch_ce (hpos); + bpldma = is_bitplane_dma (hpos_old); + if (bltstate != BLT_done) { + if (!blitpri && blitter_nasty >= BLIT_NASTY && cycle_line[hpos_old] == 0 && !bpldma) { + alloc_cycle (hpos_old, CYCLE_CPUNASTY); + break; + } + decide_blitter (hpos); + // copper may have been waiting for the blitter + sync_copper (hpos); + } + if (cycle_line[hpos_old] == 0 && !bpldma) { + alloc_cycle (hpos_old, CYCLE_CPU); + break; + } + regs.ce020memcycles -= CYCLE_UNIT; + do_cycles (1 * CYCLE_UNIT); + /* bus was allocated to dma channel, wait for next cycle.. */ } - do_cycles (1 * CYCLE_UNIT); - /* bus was allocated to dma channel, wait for next cycle.. */ - } - return hpos_old; + return hpos_old; } STATIC_INLINE void checknasty (int hpos, int vpos) { - if (blitter_nasty >= BLIT_NASTY && !(dmacon & DMA_BLITPRI)) - record_dma_event (DMA_EVENT_BLITNASTY, hpos, vpos); + if (blitter_nasty >= BLIT_NASTY && !(dmacon & DMA_BLITPRI)) + record_dma_event (DMA_EVENT_BLITNASTY, hpos, vpos); } uae_u32 wait_cpu_cycle_read (uaecptr addr, int mode) { - uae_u32 v = 0; - int hpos; - struct dma_rec *dr; + uae_u32 v = 0; + int hpos; + struct dma_rec *dr; - hpos = dma_cycle (); + hpos = dma_cycle (); #ifdef DEBUGGER - if (debug_dma) { - dr = record_dma (0x1000, v, addr, hpos, vpos, DMARECORD_CPU); - checknasty (hpos, vpos); - } -#endif - if (mode < 0) - v = get_long (addr); - else if (mode > 0) - v = get_word (addr); - else if (mode == 0) - v = get_byte (addr); + if (debug_dma) { + dr = record_dma (0x1000, v, addr, hpos, vpos, DMARECORD_CPU); + checknasty (hpos, vpos); + } +#endif + if (mode < 0) + v = get_long (addr); + else if (mode > 0) + v = get_word (addr); + else if (mode == 0) + v = get_byte (addr); #ifdef DEBUGGER - if (debug_dma) - dr->dat = v; + if (debug_dma) + dr->dat = v; #endif - do_cycles_ce (2 * CYCLE_UNIT); - return v; + do_cycles_ce (2 * CYCLE_UNIT); + regs.ce020memcycles -= 2 * CYCLE_UNIT; + return v; +} + +uae_u32 wait_cpu_cycle_read_ce020 (uaecptr addr, int mode) +{ + return wait_cpu_cycle_read (addr, mode); } void wait_cpu_cycle_write (uaecptr addr, int mode, uae_u32 v) { - int hpos; - - hpos = dma_cycle (); + int hpos; + + hpos = dma_cycle (); #ifdef DEBUGGER - if (debug_dma) { - record_dma (0x1001, v, addr, hpos, vpos, DMARECORD_CPU); - checknasty (hpos, vpos); - } + if (debug_dma) { + record_dma (0x1001, v, addr, hpos, vpos, DMARECORD_CPU); + checknasty (hpos, vpos); + } #endif - if (mode < 0) - put_long (addr, v); - else if (mode > 0) - put_word (addr, v); - else if (mode == 0) - put_byte (addr, v); - do_cycles_ce (2 * CYCLE_UNIT); + if (mode < 0) + put_long (addr, v); + else if (mode > 0) + put_word (addr, v); + else if (mode == 0) + put_byte (addr, v); + do_cycles_ce (2 * CYCLE_UNIT); + regs.ce020memcycles -= 2 * CYCLE_UNIT; } -void do_cycles_ce (long cycles) +void wait_cpu_cycle_write_ce020 (uaecptr addr, int mode, uae_u32 v) { - static int extra; + wait_cpu_cycle_write (addr, mode, v); +} - cycles += extra; - while (cycles >= CYCLE_UNIT) { - int hpos = current_hpos () + 1; - sync_copper (hpos); - decide_line (hpos); - decide_fetch_ce (hpos); - if (bltstate != BLT_done) - decide_blitter (hpos); - do_cycles (1 * CYCLE_UNIT); - cycles -= CYCLE_UNIT; - } - extra = cycles; +void do_cycles_ce (long cycles) +{ + static int extra; + + cycles += extra; + while (cycles >= CYCLE_UNIT) { + int hpos = current_hpos () + 1; + sync_copper (hpos); + decide_line (hpos); + decide_fetch_ce (hpos); + if (bltstate != BLT_done) + decide_blitter (hpos); + do_cycles (1 * CYCLE_UNIT); + cycles -= CYCLE_UNIT; + } + extra = cycles; } int is_cycle_ce (void) { - int hpos = current_hpos (); - return cycle_line[hpos]; + int hpos = current_hpos (); + return cycle_line[hpos]; } #endif diff --git a/debug.c b/debug.c index c8246649..799962a3 100644 --- a/debug.c +++ b/debug.c @@ -1,12 +1,12 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Debugger - * - * (c) 1995 Bernd Schmidt - * (c) 2006 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Debugger +* +* (c) 1995 Bernd Schmidt +* (c) 2006 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -58,23 +58,23 @@ extern int inputdevice_logging; void deactivate_debugger (void) { - debugger_active = 0; - debugging = 0; - exception_debugging = 0; - processptr = 0; - xfree (processname); - processname = NULL; + debugger_active = 0; + debugging = 0; + exception_debugging = 0; + processptr = 0; + xfree (processname); + processname = NULL; } void activate_debugger (void) { - do_skip = 0; - if (debugger_active) - return; - debugger_active = 1; - set_special (SPCFLAG_BRK); - debugging = 1; - mmu_triggered = 0; + do_skip = 0; + if (debugger_active) + return; + debugger_active = 1; + set_special (SPCFLAG_BRK); + debugging = 1; + mmu_triggered = 0; } int firsthist = 0; @@ -82,73 +82,73 @@ int lasthist = 0; static struct regstruct history[MAX_HIST]; static TCHAR help[] = { - L" HELP for UAE Debugger\n" - L" -----------------------\n\n" - L" g [
] Start execution at the current address or
\n" - L" c Dump state of the CIA, disk drives and custom registers\n" - L" r Dump state of the CPU\n" - L" r Modify CPU registers (Dx,Ax,USP,ISP,VBR,...)\n" - L" m
[] Memory dump starting at
\n" - L" m r Memory dump starting at \n" - L" d
[] Disassembly starting at
\n" - L" t [instructions] Step one or more instructions\n" - L" z Step through one instruction - useful for JSR, DBRA etc\n" - L" f Step forward until PC in RAM (\"boot block finder\")\n" - L" f
Add/remove breakpoint\n" - L" fa
[] []\n" - L" Find effective address
\n" - L" fi Step forward until PC points to RTS/RTD or RTE\n" - L" fi Step forward until PC points to \n" - L" fp \"\"/ Step forward until process or is active\n" - L" fl List breakpoints\n" - L" fd Remove all breakpoints\n" - L" fs Break when (SR & mask) = val\n" - L" f Step forward until <= PC <= \n" - L" e Dump contents of all custom registers, ea = AGA colors\n" - L" i [] Dump contents of interrupt and trap vectors\n" - L" o <0-2|addr> []View memory as Copper instructions\n" - L" od Enable/disable Copper vpos/hpos tracing\n" - L" ot Copper single step trace\n" - L" ob Copper breakpoint\n" - L" O Display bitplane offsets\n" - L" O Offset a bitplane\n" - L" H[H] Show PC history (HH=full CPU info) instructions\n" - L" C Search for values like energy or lifes in games\n" - L" Cl List currently found trainer addresses\n" - L" D[idxzs <[max diff]>] Deep trainer. i=new value must be larger, d=smaller,\n" - L" x = must be same, z = must be different, s = restart.\n" - L" W
Write into Amiga memory\n" - L" w
[] (read/write/opcode/freeze/mustchange)\n" - L" Add/remove memory watchpoints\n" - L" wd [<0-1>] Enable illegal access logger. 1 = enable break.\n" - L" S Save a block of Amiga memory\n" - L" s \"\"/ [] []\n" - L" Search for string/bytes\n" - L" T or Tt Show exec tasks and their PCs\n" - L" Td,Tl,Tr Show devices, libraries or resources\n" - L" b Step to previous state capture position\n" - L" M Enable or disable audio channels, bitplanes or sprites\n" - L" sp [] Dump sprite information\n" - L" di [] Break on disk access. R=DMA read,W=write,RW=both,P=PIO\n" - L" Also enables level 1 disk logging\n" - L" did Enable disk logging\n" - L" dj [] Enable joystick/mouse input debugging\n" - L" smc [<0-1>] Enable self-modifying code detector. 1 = enable break.\n" - L" dm Dump current address space map\n" - L" v [] Show DMA data (accurate only in cycle-exact mode)\n" - L" ? Hex/Bin/Dec converter\n" + L" HELP for UAE Debugger\n" + L" -----------------------\n\n" + L" g [
] Start execution at the current address or
\n" + L" c Dump state of the CIA, disk drives and custom registers\n" + L" r Dump state of the CPU\n" + L" r Modify CPU registers (Dx,Ax,USP,ISP,VBR,...)\n" + L" m
[] Memory dump starting at
\n" + L" m r Memory dump starting at \n" + L" d
[] Disassembly starting at
\n" + L" t [instructions] Step one or more instructions\n" + L" z Step through one instruction - useful for JSR, DBRA etc\n" + L" f Step forward until PC in RAM (\"boot block finder\")\n" + L" f
Add/remove breakpoint\n" + L" fa
[] []\n" + L" Find effective address
\n" + L" fi Step forward until PC points to RTS/RTD or RTE\n" + L" fi Step forward until PC points to \n" + L" fp \"\"/ Step forward until process or is active\n" + L" fl List breakpoints\n" + L" fd Remove all breakpoints\n" + L" fs Break when (SR & mask) = val\n" + L" f Step forward until <= PC <= \n" + L" e Dump contents of all custom registers, ea = AGA colors\n" + L" i [] Dump contents of interrupt and trap vectors\n" + L" o <0-2|addr> []View memory as Copper instructions\n" + L" od Enable/disable Copper vpos/hpos tracing\n" + L" ot Copper single step trace\n" + L" ob Copper breakpoint\n" + L" O Display bitplane offsets\n" + L" O Offset a bitplane\n" + L" H[H] Show PC history (HH=full CPU info) instructions\n" + L" C Search for values like energy or lifes in games\n" + L" Cl List currently found trainer addresses\n" + L" D[idxzs <[max diff]>] Deep trainer. i=new value must be larger, d=smaller,\n" + L" x = must be same, z = must be different, s = restart.\n" + L" W
Write into Amiga memory\n" + L" w
[] (read/write/opcode/freeze/mustchange)\n" + L" Add/remove memory watchpoints\n" + L" wd [<0-1>] Enable illegal access logger. 1 = enable break.\n" + L" S Save a block of Amiga memory\n" + L" s \"\"/ [] []\n" + L" Search for string/bytes\n" + L" T or Tt Show exec tasks and their PCs\n" + L" Td,Tl,Tr Show devices, libraries or resources\n" + L" b Step to previous state capture position\n" + L" M Enable or disable audio channels, bitplanes or sprites\n" + L" sp [] Dump sprite information\n" + L" di [] Break on disk access. R=DMA read,W=write,RW=both,P=PIO\n" + L" Also enables level 1 disk logging\n" + L" did Enable disk logging\n" + L" dj [] Enable joystick/mouse input debugging\n" + L" smc [<0-1>] Enable self-modifying code detector. 1 = enable break.\n" + L" dm Dump current address space map\n" + L" v [] Show DMA data (accurate only in cycle-exact mode)\n" + L" ? Hex/Bin/Dec converter\n" #ifdef _WIN32 - L" x Close debugger.\n" - L" xx Switch between console and GUI debugger.\n" - L" mg
Memory dump starting at
in GUI\n" - L" dg
Disassembly starting at
in GUI\n" + L" x Close debugger.\n" + L" xx Switch between console and GUI debugger.\n" + L" mg
Memory dump starting at
in GUI\n" + L" dg
Disassembly starting at
in GUI\n" #endif - L" q Quit the emulator. You don't want to use this command.\n\n" + L" q Quit the emulator. You don't want to use this command.\n\n" }; void debug_help (void) { - console_out (help); + console_out (help); } static int debug_linecounter; @@ -156,25 +156,25 @@ static int debug_linecounter; static int debug_out (const TCHAR *format, ...) { - va_list parms; - TCHAR buffer[4000]; + va_list parms; + TCHAR buffer[4000]; - va_start (parms, format); - _vsntprintf (buffer, 4000 - 1, format, parms); - va_end (parms); + va_start (parms, format); + _vsntprintf (buffer, 4000 - 1, format, parms); + va_end (parms); - console_out (buffer); - if (debug_linecounter < MAX_LINECOUNTER) - debug_linecounter++; - if (debug_linecounter >= MAX_LINECOUNTER) - return 0; - return 1; + console_out (buffer); + if (debug_linecounter < MAX_LINECOUNTER) + debug_linecounter++; + if (debug_linecounter >= MAX_LINECOUNTER) + return 0; + return 1; } static void ignore_ws (TCHAR **c) { - while (**c && _istspace(**c)) - (*c)++; + while (**c && _istspace(**c)) + (*c)++; } static uae_u32 readint (TCHAR **c); @@ -183,516 +183,516 @@ static uae_u32 readhex (TCHAR **c); static int readregx (TCHAR **c, uae_u32 *valp) { - int i; - uae_u32 addr; - TCHAR *p = *c; - TCHAR tmp[10]; - int extra = 0; - - addr = 0; - i = 0; - while (p[i]) { - tmp[i] = _totupper (p[i]); - if (i >= sizeof (tmp) / sizeof (TCHAR) - 1) - break; - i++; - } - tmp[i] = 0; - if (_totupper (tmp[0]) == 'R') { - memmove (tmp, tmp + 1, sizeof (tmp) - sizeof (TCHAR)); - extra = 1; - } - if (!_tcscmp (tmp, L"USP")) { - addr = regs.usp; - (*c) += 3; - } else if (!_tcscmp (tmp, L"VBR")) { - addr = regs.vbr; - (*c) += 3; - } else if (!_tcscmp (tmp, L"MSP")) { - addr = regs.msp; - (*c) += 3; - } else if (!_tcscmp (tmp, L"ISP")) { - addr = regs.isp; - (*c) += 3; - } else if (!_tcscmp (tmp, L"PC")) { - addr = regs.pc; - (*c) += 2; - } else if (tmp[0] == 'A' || tmp[0] == 'D') { - int reg = 0; - if (tmp[0] == 'A') - reg += 8; - reg += tmp[1] - '0'; - if (reg < 0 || reg > 15) - return 0; - addr = regs.regs[reg]; - (*c) += 2; - } else { - return 0; - } - *valp = addr; - (*c) += extra; - return 1; + int i; + uae_u32 addr; + TCHAR *p = *c; + TCHAR tmp[10]; + int extra = 0; + + addr = 0; + i = 0; + while (p[i]) { + tmp[i] = _totupper (p[i]); + if (i >= sizeof (tmp) / sizeof (TCHAR) - 1) + break; + i++; + } + tmp[i] = 0; + if (_totupper (tmp[0]) == 'R') { + memmove (tmp, tmp + 1, sizeof (tmp) - sizeof (TCHAR)); + extra = 1; + } + if (!_tcscmp (tmp, L"USP")) { + addr = regs.usp; + (*c) += 3; + } else if (!_tcscmp (tmp, L"VBR")) { + addr = regs.vbr; + (*c) += 3; + } else if (!_tcscmp (tmp, L"MSP")) { + addr = regs.msp; + (*c) += 3; + } else if (!_tcscmp (tmp, L"ISP")) { + addr = regs.isp; + (*c) += 3; + } else if (!_tcscmp (tmp, L"PC")) { + addr = regs.pc; + (*c) += 2; + } else if (tmp[0] == 'A' || tmp[0] == 'D') { + int reg = 0; + if (tmp[0] == 'A') + reg += 8; + reg += tmp[1] - '0'; + if (reg < 0 || reg > 15) + return 0; + addr = regs.regs[reg]; + (*c) += 2; + } else { + return 0; + } + *valp = addr; + (*c) += extra; + return 1; } static uae_u32 readbinx (TCHAR **c) { - uae_u32 val = 0; + uae_u32 val = 0; - ignore_ws (c); - for (;;) { - TCHAR nc = **c; - if (nc != '1' && nc != '0') - break; - (*c)++; - val <<= 1; - if (nc == '1') - val |= 1; - } - return val; + ignore_ws (c); + for (;;) { + TCHAR nc = **c; + if (nc != '1' && nc != '0') + break; + (*c)++; + val <<= 1; + if (nc == '1') + val |= 1; + } + return val; } static uae_u32 readhexx (TCHAR **c) { - uae_u32 val = 0; - TCHAR nc; + uae_u32 val = 0; + TCHAR nc; - ignore_ws (c); - while (isxdigit (nc = **c)) { - (*c)++; - val *= 16; - nc = _totupper (nc); - if (isdigit (nc)) { - val += nc - '0'; - } else { - val += nc - 'A' + 10; + ignore_ws (c); + while (isxdigit (nc = **c)) { + (*c)++; + val *= 16; + nc = _totupper (nc); + if (isdigit (nc)) { + val += nc - '0'; + } else { + val += nc - 'A' + 10; + } } - } - return val; + return val; } static uae_u32 readintx (TCHAR **c) { - uae_u32 val = 0; - TCHAR nc; - int negative = 0; + uae_u32 val = 0; + TCHAR nc; + int negative = 0; - ignore_ws (c); - if (**c == '-') - negative = 1, (*c)++; - while (isdigit (nc = **c)) { - (*c)++; - val *= 10; - val += nc - '0'; - } - return val * (negative ? -1 : 1); + ignore_ws (c); + if (**c == '-') + negative = 1, (*c)++; + while (isdigit (nc = **c)) { + (*c)++; + val *= 10; + val += nc - '0'; + } + return val * (negative ? -1 : 1); } static int checkvaltype (TCHAR **c, uae_u32 *val) { - TCHAR nc; + TCHAR nc; - ignore_ws (c); - nc = _totupper (**c); - if (nc == '!') { - (*c)++; - *val = readintx (c); - return 1; - } - if (nc == '$') { - (*c)++; - *val = readhexx (c); - return 1; - } - if (nc == '0' && _totupper ((*c)[1]) == 'X') { - (*c)+= 2; - *val = readhexx (c); - return 1; - } - if (nc == '%') { - (*c)++; - *val = readbinx (c); - return 1; - } - if (nc >= 'A' && nc <= 'Z' && nc != 'A' && nc != 'D') { - if (readregx (c, val)) - return 1; - } - return 0; + ignore_ws (c); + nc = _totupper (**c); + if (nc == '!') { + (*c)++; + *val = readintx (c); + return 1; + } + if (nc == '$') { + (*c)++; + *val = readhexx (c); + return 1; + } + if (nc == '0' && _totupper ((*c)[1]) == 'X') { + (*c)+= 2; + *val = readhexx (c); + return 1; + } + if (nc == '%') { + (*c)++; + *val = readbinx (c); + return 1; + } + if (nc >= 'A' && nc <= 'Z' && nc != 'A' && nc != 'D') { + if (readregx (c, val)) + return 1; + } + return 0; } static uae_u32 readint (TCHAR **c) { - uae_u32 val; - if (checkvaltype (c, &val)) - return val; - return readintx (c); + uae_u32 val; + if (checkvaltype (c, &val)) + return val; + return readintx (c); } static uae_u32 readhex (TCHAR **c) { - uae_u32 val; - if (checkvaltype (c, &val)) - return val; - return readhexx (c); + uae_u32 val; + if (checkvaltype (c, &val)) + return val; + return readhexx (c); } static uae_u32 readbin (TCHAR **c) { - uae_u32 val; - if (checkvaltype (c, &val)) - return val; - return readbinx (c); + uae_u32 val; + if (checkvaltype (c, &val)) + return val; + return readbinx (c); } static TCHAR next_char(TCHAR **c) { - ignore_ws (c); - return *(*c)++; + ignore_ws (c); + return *(*c)++; } static TCHAR peek_next_char(TCHAR **c) { - TCHAR *pc = *c; - return pc[1]; + TCHAR *pc = *c; + return pc[1]; } static int more_params (TCHAR **c) { - ignore_ws (c); - return (**c) != 0; + ignore_ws (c); + return (**c) != 0; } static int next_string (TCHAR **c, TCHAR *out, int max, int forceupper) { - TCHAR *p = out; - int startmarker = 0; - - if (**c == '\"') { - startmarker = 1; - (*c)++; - } - *p = 0; - while (**c != 0) { - if (**c == '\"' && startmarker) - break; - if (**c == 32 && !startmarker) { - ignore_ws (c); - break; - } - *p = next_char (c); - if (forceupper) - *p = _totupper(*p); - *++p = 0; - max--; - if (max <= 1) - break; - } - return _tcslen (out); + TCHAR *p = out; + int startmarker = 0; + + if (**c == '\"') { + startmarker = 1; + (*c)++; + } + *p = 0; + while (**c != 0) { + if (**c == '\"' && startmarker) + break; + if (**c == 32 && !startmarker) { + ignore_ws (c); + break; + } + *p = next_char (c); + if (forceupper) + *p = _totupper(*p); + *++p = 0; + max--; + if (max <= 1) + break; + } + return _tcslen (out); } static void converter (TCHAR **c) { - uae_u32 v = readint (c); - TCHAR s[100]; - TCHAR *p = s; - int i; + uae_u32 v = readint (c); + TCHAR s[100]; + TCHAR *p = s; + int i; - for (i = 0; i < 32; i++) - s[i] = (v & (1 << (31 - i))) ? '1' : '0'; - s[i] = 0; - console_out_f (L"0x%08X = %%%s = %u = %d\n", v, s, v, (uae_s32)v); + for (i = 0; i < 32; i++) + s[i] = (v & (1 << (31 - i))) ? '1' : '0'; + s[i] = 0; + console_out_f (L"0x%08X = %%%s = %u = %d\n", v, s, v, (uae_s32)v); } int notinrom (void) { - uaecptr pc = munge24 (m68k_getpc ()); - if (pc < 0x00e00000 || pc > 0x00ffffff) - return 1; - return 0; + uaecptr pc = munge24 (m68k_getpc ()); + if (pc < 0x00e00000 || pc > 0x00ffffff) + return 1; + return 0; } static uae_u32 lastaddr (void) { - if (currprefs.z3fastmem_size) - return z3fastmem_start + currprefs.z3fastmem_size; - if (currprefs.mbresmem_high_size) - return a3000hmem_start + currprefs.mbresmem_high_size; - if (currprefs.mbresmem_low_size) - return a3000lmem_start + currprefs.mbresmem_low_size; - if (currprefs.bogomem_size) - return bogomem_start + currprefs.bogomem_size; - if (currprefs.fastmem_size) - return fastmem_start + currprefs.fastmem_size; - return currprefs.chipmem_size; + if (currprefs.z3fastmem_size) + return z3fastmem_start + currprefs.z3fastmem_size; + if (currprefs.mbresmem_high_size) + return a3000hmem_start + currprefs.mbresmem_high_size; + if (currprefs.mbresmem_low_size) + return a3000lmem_start + currprefs.mbresmem_low_size; + if (currprefs.bogomem_size) + return bogomem_start + currprefs.bogomem_size; + if (currprefs.fastmem_size) + return fastmem_start + currprefs.fastmem_size; + return currprefs.chipmem_size; } static uaecptr nextaddr2 (uaecptr addr, int *next) { - uaecptr prev, prevx; - int size, sizex; + uaecptr prev, prevx; + int size, sizex; - if (addr >= lastaddr()) { - *next = -1; - return 0xffffffff; - } - prev = currprefs.z3fastmem_start; - size = currprefs.z3fastmem_size; + if (addr >= lastaddr()) { + *next = -1; + return 0xffffffff; + } + prev = currprefs.z3fastmem_start; + size = currprefs.z3fastmem_size; - if (currprefs.mbresmem_high_size) { - sizex = size; - prevx = prev; - size = currprefs.mbresmem_high_size; - prev = a3000hmem_start; - if (addr == prev + size) { - *next = prevx + sizex; - return prevx; - } - } - if (currprefs.mbresmem_low_size) { - prevx = prev; - sizex = size; - size = currprefs.mbresmem_low_size; - prev = a3000lmem_start; - if (addr == prev + size) { - *next = prevx + sizex; - return prevx; - } - } - if (currprefs.bogomem_size) { - sizex = size; - prevx = prev; - size = currprefs.bogomem_size; - prev = bogomem_start; - if (addr == prev + size) { - *next = prevx + sizex; - return prevx; - } - } - if (currprefs.fastmem_size) { + if (currprefs.mbresmem_high_size) { + sizex = size; + prevx = prev; + size = currprefs.mbresmem_high_size; + prev = a3000hmem_start; + if (addr == prev + size) { + *next = prevx + sizex; + return prevx; + } + } + if (currprefs.mbresmem_low_size) { + prevx = prev; + sizex = size; + size = currprefs.mbresmem_low_size; + prev = a3000lmem_start; + if (addr == prev + size) { + *next = prevx + sizex; + return prevx; + } + } + if (currprefs.bogomem_size) { + sizex = size; + prevx = prev; + size = currprefs.bogomem_size; + prev = bogomem_start; + if (addr == prev + size) { + *next = prevx + sizex; + return prevx; + } + } + if (currprefs.fastmem_size) { + sizex = size; + prevx = prev; + size = currprefs.fastmem_size; + prev = fastmem_start; + if (addr == prev + size) { + *next = prevx + sizex; + return prevx; + } + } sizex = size; prevx = prev; - size = currprefs.fastmem_size; - prev = fastmem_start; - if (addr == prev + size) { - *next = prevx + sizex; - return prevx; - } - } - sizex = size; - prevx = prev; - size = currprefs.chipmem_size; - if (addr == size) { - *next = prevx + sizex; - return prevx; - } - if (addr == 1) - *next = size; - return addr; + size = currprefs.chipmem_size; + if (addr == size) { + *next = prevx + sizex; + return prevx; + } + if (addr == 1) + *next = size; + return addr; } static uaecptr nextaddr (uaecptr addr, uaecptr *end) { - uaecptr paddr = addr; - int next; - if (addr == 0xffffffff) { + uaecptr paddr = addr; + int next; + if (addr == 0xffffffff) { + if (end) + *end = currprefs.chipmem_size; + return 0; + } if (end) - *end = currprefs.chipmem_size; - return 0; - } - if (end) - next = *end; - addr = nextaddr2(addr + 1, &next); - if (end) - *end = next; + next = *end; + addr = nextaddr2(addr + 1, &next); + if (end) + *end = next; #if 0 - if (next && addr != 0xffffffff) { - uaecptr xa = addr; - if (xa == 1) - xa = 0; - console_out_f ("%08X -> %08X (%08X)...\n", xa, xa + next - 1, next); - } + if (next && addr != 0xffffffff) { + uaecptr xa = addr; + if (xa == 1) + xa = 0; + console_out_f ("%08X -> %08X (%08X)...\n", xa, xa + next - 1, next); + } #endif - return addr; + return addr; } int safe_addr(uaecptr addr, int size) { - addrbank *ab = &get_mem_bank (addr); - if (!ab) - return 0; - if (ab->flags & ABFLAG_SAFE) - return 1; - if (!ab->check (addr, size)) + addrbank *ab = &get_mem_bank (addr); + if (!ab) + return 0; + if (ab->flags & ABFLAG_SAFE) + return 1; + if (!ab->check (addr, size)) + return 0; + if (ab->flags & (ABFLAG_RAM | ABFLAG_ROM | ABFLAG_ROMIN | ABFLAG_SAFE)) + return 1; return 0; - if (ab->flags & (ABFLAG_RAM | ABFLAG_ROM | ABFLAG_ROMIN | ABFLAG_SAFE)) - return 1; - return 0; } uaecptr dumpmem2 (uaecptr addr, TCHAR *out, int osize) { - int i, cols = 8; - int nonsafe = 0; - - if (osize <= (9 + cols * 5 + 1 + 2 * cols)) + int i, cols = 8; + int nonsafe = 0; + + if (osize <= (9 + cols * 5 + 1 + 2 * cols)) + return addr; + _stprintf (out, L"%08lX ", addr); + for (i = 0; i < cols; i++) { + uae_u8 b1, b2; + b1 = b2 = 0; + if (safe_addr(addr, 2)) { + b1 = get_byte (addr + 0); + b2 = get_byte (addr + 1); + _stprintf (out + 9 + i * 5, L"%02X%02X ", b1, b2); + out[9 + cols * 5 + 1 + i * 2 + 0] = b1 >= 32 && b1 < 127 ? b1 : '.'; + out[9 + cols * 5 + 1 + i * 2 + 1] = b2 >= 32 && b2 < 127 ? b2 : '.'; + } else { + nonsafe++; + _tcscpy (out + 9 + i * 5, L"**** "); + out[9 + cols * 5 + 1 + i * 2 + 0] = '*'; + out[9 + cols * 5 + 1 + i * 2 + 1] = '*'; + } + addr += 2; + } + out[9 + cols * 5] = ' '; + out[9 + cols * 5 + 1 + 2 * cols] = 0; + if (nonsafe == cols) { + addrbank *ab = &get_mem_bank (addr); + if (ab->name) + memcpy (out + (9 + 4 + 1) * sizeof (TCHAR), ab->name, _tcslen (ab->name) * sizeof (TCHAR)); + } return addr; - _stprintf (out, L"%08lX ", addr); - for (i = 0; i < cols; i++) { - uae_u8 b1, b2; - b1 = b2 = 0; - if (safe_addr(addr, 2)) { - b1 = get_byte (addr + 0); - b2 = get_byte (addr + 1); - _stprintf (out + 9 + i * 5, L"%02X%02X ", b1, b2); - out[9 + cols * 5 + 1 + i * 2 + 0] = b1 >= 32 && b1 < 127 ? b1 : '.'; - out[9 + cols * 5 + 1 + i * 2 + 1] = b2 >= 32 && b2 < 127 ? b2 : '.'; - } else { - nonsafe++; - _tcscpy (out + 9 + i * 5, L"**** "); - out[9 + cols * 5 + 1 + i * 2 + 0] = '*'; - out[9 + cols * 5 + 1 + i * 2 + 1] = '*'; - } - addr += 2; - } - out[9 + cols * 5] = ' '; - out[9 + cols * 5 + 1 + 2 * cols] = 0; - if (nonsafe == cols) { - addrbank *ab = &get_mem_bank (addr); - if (ab->name) - memcpy (out + (9 + 4 + 1) * sizeof (TCHAR), ab->name, _tcslen (ab->name) * sizeof (TCHAR)); - } - return addr; } static void dumpmem (uaecptr addr, uaecptr *nxmem, int lines) { - TCHAR line[MAX_LINEWIDTH + 1]; - for (;lines--;) { - addr = dumpmem2 (addr, line, sizeof(line)); - debug_out (L"%s", line); - if (!debug_out (L"\n")) - break; - } - *nxmem = addr; + TCHAR line[MAX_LINEWIDTH + 1]; + for (;lines--;) { + addr = dumpmem2 (addr, line, sizeof(line)); + debug_out (L"%s", line); + if (!debug_out (L"\n")) + break; + } + *nxmem = addr; } static void dump_custom_regs (int aga) { - int len, i, j, end; - uae_u8 *p1, *p2, *p3, *p4; + int len, i, j, end; + uae_u8 *p1, *p2, *p3, *p4; - if (aga) { - dump_aga_custom(); - return; - } - - p1 = p2 = save_custom (&len, 0, 1); - p1 += 4; // skip chipset type - for (i = 0; i < 4; i++) { - p4 = p1 + 0xa0 + i * 16; - p3 = save_audio (i, &len, 0); - p4[0] = p3[12]; - p4[1] = p3[13]; - p4[2] = p3[14]; - p4[3] = p3[15]; - p4[4] = p3[4]; - p4[5] = p3[5]; - p4[6] = p3[8]; - p4[7] = p3[9]; - p4[8] = 0; - p4[9] = p3[1]; - p4[10] = p3[10]; - p4[11] = p3[11]; - free (p3); - } - end = 0; - while (custd[end].name) + if (aga) { + dump_aga_custom(); + return; + } + + p1 = p2 = save_custom (&len, 0, 1); + p1 += 4; // skip chipset type + for (i = 0; i < 4; i++) { + p4 = p1 + 0xa0 + i * 16; + p3 = save_audio (i, &len, 0); + p4[0] = p3[12]; + p4[1] = p3[13]; + p4[2] = p3[14]; + p4[3] = p3[15]; + p4[4] = p3[4]; + p4[5] = p3[5]; + p4[6] = p3[8]; + p4[7] = p3[9]; + p4[8] = 0; + p4[9] = p3[1]; + p4[10] = p3[10]; + p4[11] = p3[11]; + free (p3); + } + end = 0; + while (custd[end].name) + end++; end++; - end++; - end /= 2; - for (i = 0; i < end; i++) { - uae_u16 v1, v2; - int addr1, addr2; - j = end + i; - addr1 = custd[i].adr & 0x1ff; - addr2 = custd[j].adr & 0x1ff; - v1 = (p1[addr1 + 0] << 8) | p1[addr1 + 1]; - v2 = (p1[addr2 + 0] << 8) | p1[addr2 + 1]; - console_out_f (L"%03X %s\t%04X\t%03X %s\t%04X\n", - addr1, custd[i].name, v1, - addr2, custd[j].name, v2); - } - free (p2); + end /= 2; + for (i = 0; i < end; i++) { + uae_u16 v1, v2; + int addr1, addr2; + j = end + i; + addr1 = custd[i].adr & 0x1ff; + addr2 = custd[j].adr & 0x1ff; + v1 = (p1[addr1 + 0] << 8) | p1[addr1 + 1]; + v2 = (p1[addr2 + 0] << 8) | p1[addr2 + 1]; + console_out_f (L"%03X %s\t%04X\t%03X %s\t%04X\n", + addr1, custd[i].name, v1, + addr2, custd[j].name, v2); + } + free (p2); } static void dump_vectors (uaecptr addr) { - int i = 0, j = 0; + int i = 0, j = 0; - if (addr == 0xffffffff) - addr = regs.vbr; + if (addr == 0xffffffff) + addr = regs.vbr; - while (int_labels[i].name || trap_labels[j].name) { - if (int_labels[i].name) { - console_out_f (L"$%08X %02d: %12s $%08X ", int_labels[i].adr + addr, int_labels[i].adr / 4, - int_labels[i].name, get_long (int_labels[i].adr + addr)); - i++; - } - if (trap_labels[j].name) { - console_out_f (L"$%08X %02d: %12s $%08X", trap_labels[j].adr + addr, trap_labels[j].adr / 4, - trap_labels[j].name, get_long (trap_labels[j].adr + addr)); - j++; + while (int_labels[i].name || trap_labels[j].name) { + if (int_labels[i].name) { + console_out_f (L"$%08X %02d: %12s $%08X ", int_labels[i].adr + addr, int_labels[i].adr / 4, + int_labels[i].name, get_long (int_labels[i].adr + addr)); + i++; + } + if (trap_labels[j].name) { + console_out_f (L"$%08X %02d: %12s $%08X", trap_labels[j].adr + addr, trap_labels[j].adr / 4, + trap_labels[j].name, get_long (trap_labels[j].adr + addr)); + j++; + } + console_out (L"\n"); } - console_out (L"\n"); - } } static void disassemble_wait (FILE *file, unsigned long insn) { - int vp, hp, ve, he, bfd, v_mask, h_mask; - int doout = 0; - - vp = (insn & 0xff000000) >> 24; - hp = (insn & 0x00fe0000) >> 16; - ve = (insn & 0x00007f00) >> 8; - he = (insn & 0x000000fe); - bfd = (insn & 0x00008000) >> 15; - - /* bit15 can never be masked out*/ - v_mask = vp & (ve | 0x80); - h_mask = hp & he; - if (v_mask > 0) { - doout = 1; - console_out (L"vpos "); - if (ve != 0x7f) { - console_out_f (L"& 0x%02x ", ve); - } - console_out_f (L">= 0x%02x", v_mask); - } - if (he > 0) { + int vp, hp, ve, he, bfd, v_mask, h_mask; + int doout = 0; + + vp = (insn & 0xff000000) >> 24; + hp = (insn & 0x00fe0000) >> 16; + ve = (insn & 0x00007f00) >> 8; + he = (insn & 0x000000fe); + bfd = (insn & 0x00008000) >> 15; + + /* bit15 can never be masked out*/ + v_mask = vp & (ve | 0x80); + h_mask = hp & he; if (v_mask > 0) { - console_out (L" and"); + doout = 1; + console_out (L"vpos "); + if (ve != 0x7f) { + console_out_f (L"& 0x%02x ", ve); + } + console_out_f (L">= 0x%02x", v_mask); } - console_out (L" hpos "); - if (he != 0xfe) { - console_out_f (L"& 0x%02x ", he); + if (he > 0) { + if (v_mask > 0) { + console_out (L" and"); + } + console_out (L" hpos "); + if (he != 0xfe) { + console_out_f (L"& 0x%02x ", he); + } + console_out_f (L">= 0x%02x", h_mask); + } else { + if (doout) + console_out (L", "); + console_out (L", ignore horizontal"); } - console_out_f (L">= 0x%02x", h_mask); - } else { - if (doout) - console_out (L", "); - console_out (L", ignore horizontal"); - } - console_out_f (L"\n \t; VP %02x, VE %02x; HP %02x, HE %02x; BFD %d\n", - vp, ve, hp, he, bfd); + console_out_f (L"\n \t; VP %02x, VE %02x; HP %02x, HE %02x; BFD %d\n", + vp, ve, hp, he, bfd); } #define NR_COPPER_RECORDS 100000 /* Record copper activity for the debugger. */ struct cop_rec { - int hpos, vpos; - uaecptr addr; + int hpos, vpos; + uaecptr addr; }; static struct cop_rec *cop_record[2]; static int nr_cop_records[2], curr_cop_set; @@ -704,114 +704,116 @@ static int dma_record_toggle; void record_dma_reset (void) { - int v, h; - struct dma_rec *dr, *dr2; + int v, h; + struct dma_rec *dr, *dr2; - if (!dma_record[0]) - return; - dma_record_toggle ^= 1; - dr = dma_record[dma_record_toggle]; - for (v = 0; v < NR_DMA_REC_VPOS; v++) { - for (h = 0; h < NR_DMA_REC_HPOS; h++) { - dr2 = &dr[v * NR_DMA_REC_HPOS + h]; - memset (dr2, 0, sizeof (struct dma_rec)); - dr2->reg = 0xffff; - dr2->addr = 0xffffffff; + if (!dma_record[0]) + return; + dma_record_toggle ^= 1; + dr = dma_record[dma_record_toggle]; + for (v = 0; v < NR_DMA_REC_VPOS; v++) { + for (h = 0; h < NR_DMA_REC_HPOS; h++) { + dr2 = &dr[v * NR_DMA_REC_HPOS + h]; + memset (dr2, 0, sizeof (struct dma_rec)); + dr2->reg = 0xffff; + dr2->addr = 0xffffffff; + } } - } } void record_copper_reset (void) { - /* Start a new set of copper records. */ - curr_cop_set ^= 1; - nr_cop_records[curr_cop_set] = 0; + /* Start a new set of copper records. */ + curr_cop_set ^= 1; + nr_cop_records[curr_cop_set] = 0; } STATIC_INLINE uae_u32 ledcolor (uae_u32 c, uae_u32 *rc, uae_u32 *gc, uae_u32 *bc, uae_u32 *a) { - uae_u32 v = rc[(c >> 16) & 0xff] | gc[(c >> 8) & 0xff] | bc[(c >> 0) & 0xff]; - if (a) - v |= a[255 - ((c >> 24) & 0xff)]; - return v; + uae_u32 v = rc[(c >> 16) & 0xff] | gc[(c >> 8) & 0xff] | bc[(c >> 0) & 0xff]; + if (a) + v |= a[255 - ((c >> 24) & 0xff)]; + return v; } STATIC_INLINE void putpixel (uae_u8 *buf, int bpp, int x, xcolnr c8) { - if (x <= 0) - return; + if (x <= 0) + return; - switch (bpp) { - case 1: - buf[x] = (uae_u8)c8; - break; - case 2: - { - uae_u16 *p = (uae_u16*)buf + x; - *p = (uae_u16)c8; - break; - } - case 3: - /* no 24 bit yet */ - break; - case 4: - { - uae_u32 *p = (uae_u32*)buf + x; - *p = c8; - break; - } - } + switch (bpp) { + case 1: + buf[x] = (uae_u8)c8; + break; + case 2: + { + uae_u16 *p = (uae_u16*)buf + x; + *p = (uae_u16)c8; + break; + } + case 3: + /* no 24 bit yet */ + break; + case 4: + { + uae_u32 *p = (uae_u32*)buf + x; + *p = c8; + break; + } + } } #define lc(x) ledcolor (x, xredcolors, xgreencolors, xbluecolors, NULL); void debug_draw_cycles (uae_u8 *buf, int bpp, int line, int width, int height, uae_u32 *xredcolors, uae_u32 *xgreencolors, uae_u32 *xbluescolors) { - int y, x, xx, dx, xplus, yplus; - struct dma_rec *dr; - int t; - uae_u32 cc[DMARECORD_MAX]; - - if (debug_dma >= 4) - yplus = 2; - else - yplus = 1; - if (debug_dma >= 3) - xplus = 2; - else - xplus = 1; + int y, x, xx, dx, xplus, yplus; + struct dma_rec *dr; + int t; + uae_u32 cc[DMARECORD_MAX]; - t = dma_record_toggle ^ 1; - y = line / yplus; - - if (y > maxvpos) - return; - if (y >= height) - return; + if (debug_dma >= 4) + yplus = 2; + else + yplus = 1; + if (debug_dma >= 3) + xplus = 2; + else + xplus = 1; - dx = width - xplus * ((maxhpos + 1) & ~1) - 16; + t = dma_record_toggle ^ 1; + y = line / yplus - 8; - cc[0] = lc(0x222222); - cc[DMARECORD_REFRESH] = lc(0x444444); - cc[DMARECORD_CPU] = lc(0x888888); - cc[DMARECORD_COPPER] = lc(0xeeee00); - cc[DMARECORD_AUDIO] = lc(0xff0000); - cc[DMARECORD_BLITTER] = lc(0x00ff00); - cc[DMARECORD_BLITTER_LINE] = lc(0x008800); - cc[DMARECORD_BITPLANE] = lc(0x0000ff); - cc[DMARECORD_SPRITE] = lc(0xff00ff); - cc[DMARECORD_DISK] = lc(0xffffff); + if (y < 0) + return; + if (y > maxvpos) + return; + if (y >= height) + return; - for (x = 0; x < maxhpos; x++) { - uae_u32 c = cc[0]; - xx = x * xplus + dx; - dr = &dma_record[t][y * NR_DMA_REC_HPOS + x]; - if (dr->reg != 0xffff) { - c = cc[dr->type]; + dx = width - xplus * ((maxhpos + 1) & ~1) - 16; + + cc[0] = lc(0x222222); + cc[DMARECORD_REFRESH] = lc(0x444444); + cc[DMARECORD_CPU] = lc(0x888888); + cc[DMARECORD_COPPER] = lc(0xeeee00); + cc[DMARECORD_AUDIO] = lc(0xff0000); + cc[DMARECORD_BLITTER] = lc(0x00ff00); + cc[DMARECORD_BLITTER_LINE] = lc(0x008800); + cc[DMARECORD_BITPLANE] = lc(0x0000ff); + cc[DMARECORD_SPRITE] = lc(0xff00ff); + cc[DMARECORD_DISK] = lc(0xffffff); + + for (x = 0; x < maxhpos; x++) { + uae_u32 c = cc[0]; + xx = x * xplus + dx; + dr = &dma_record[t][y * NR_DMA_REC_HPOS + x]; + if (dr->reg != 0xffff) { + c = cc[dr->type]; + } + putpixel (buf, bpp, xx, c); + if (xplus) + putpixel (buf, bpp, xx + 1, c); } - putpixel (buf, bpp, xx, c); - if (xplus) - putpixel (buf, bpp, xx + 1, c); - } } @@ -819,259 +821,259 @@ void debug_draw_cycles (uae_u8 *buf, int bpp, int line, int width, int height, u void record_dma_event (int evt, int hpos, int vpos) { - struct dma_rec *dr; + struct dma_rec *dr; - if (!dma_record[0]) - return; - if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS) - return; - dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos]; - dr->evt |= evt; + if (!dma_record[0]) + return; + if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS) + return; + dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos]; + dr->evt |= evt; } struct dma_rec *record_dma (uae_u16 reg, uae_u16 dat, uae_u32 addr, int hpos, int vpos, int type) { - struct dma_rec *dr; - - if (!dma_record[0]) { - dma_record[0] = xmalloc (NR_DMA_REC_HPOS * NR_DMA_REC_VPOS * sizeof (struct dma_rec)); - dma_record[1] = xmalloc (NR_DMA_REC_HPOS * NR_DMA_REC_VPOS * sizeof (struct dma_rec)); - dma_record_toggle = 0; - record_dma_reset (); - } - if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS) - return NULL; - dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos]; - if (dr->reg != 0xffff) { - write_log (L"DMA conflict: v=%d h=%d OREG=%04X NREG=%04X\n", vpos, hpos, dr->reg, reg); + struct dma_rec *dr; + + if (!dma_record[0]) { + dma_record[0] = xmalloc (NR_DMA_REC_HPOS * NR_DMA_REC_VPOS * sizeof (struct dma_rec)); + dma_record[1] = xmalloc (NR_DMA_REC_HPOS * NR_DMA_REC_VPOS * sizeof (struct dma_rec)); + dma_record_toggle = 0; + record_dma_reset (); + } + if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS) + return NULL; + dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos]; + if (dr->reg != 0xffff) { + write_log (L"DMA conflict: v=%d h=%d OREG=%04X NREG=%04X\n", vpos, hpos, dr->reg, reg); + return dr; + } + dr->reg = reg; + dr->dat = dat; + dr->addr = addr; + dr->type = type; return dr; - } - dr->reg = reg; - dr->dat = dat; - dr->addr = addr; - dr->type = type; - return dr; } static void decode_dma_record (int hpos, int vpos, int toggle) { - struct dma_rec *dr; - int h, i, maxh; + struct dma_rec *dr; + int h, i, maxh; - if (!dma_record[0]) - return; - dr = &dma_record[dma_record_toggle ^ toggle][vpos * NR_DMA_REC_HPOS]; - console_out_f (L"Line: %02X %3d HPOS %02X %3d:\n", vpos, vpos, hpos, hpos); - h = hpos; - dr += hpos; - maxh = hpos + 80; - if (maxh > maxhpos) - maxh = maxhpos; - while (h < maxh) { - int col = 9; - int cols = 8; - TCHAR l1[81]; - TCHAR l2[81]; - TCHAR l3[81]; - TCHAR l4[81]; - for (i = 0; i < cols && h < maxh; i++, h++, dr++) { - int cl = i * col, cl2; - - _stprintf (l1 + cl, L"[%02X %3d]", h, h); - _tcscpy (l4 + cl, L" "); - if (dr->reg != 0xffff) { - if ((dr->reg & 0x1001) == 0x1000) - _tcscpy (l2 + cl, L" CPU-R "); - else if ((dr->reg & 0x1001) == 0x1001) - _tcscpy (l2 + cl, L" CPU-W "); - else - _stprintf (l2 + cl, L" %03X", dr->reg); - _stprintf (l3 + cl, L" %04X", dr->dat); - if (dr->addr != 0xffffffff) - _stprintf (l4 + cl, L"%08X", dr->addr & 0x00ffffff); - } else { - _tcscpy (l2 + cl, L" "); - _tcscpy (l3 + cl, L" "); - } - cl2 = cl; - if (dr->evt & DMA_EVENT_BLITNASTY) - l2[cl2++] = 'N'; - if (dr->evt & DMA_EVENT_BLITFINISHED) - l2[cl2++] = 'B'; - if (dr->evt & DMA_EVENT_BLITIRQ) - l2[cl2++] = 'b'; - if (dr->evt & DMA_EVENT_BPLFETCHUPDATE) - l2[cl2++] = 'p'; - if (dr->evt & DMA_EVENT_COPPERWAKE) - l2[cl2++] = 'W'; - if (i < cols - 1 && h < maxh - 1) { - l1[cl + col - 1] = 32; - l2[cl + col - 1] = 32; - l3[cl + col - 1] = 32; - l4[cl + col - 1] = 32; - } - } - console_out_f (L"%s\n", l1); - console_out_f (L"%s\n", l2); - console_out_f (L"%s\n", l3); - console_out_f (L"%s\n", l4); - console_out_f (L"\n"); - } + if (!dma_record[0]) + return; + dr = &dma_record[dma_record_toggle ^ toggle][vpos * NR_DMA_REC_HPOS]; + console_out_f (L"Line: %02X %3d HPOS %02X %3d:\n", vpos, vpos, hpos, hpos); + h = hpos; + dr += hpos; + maxh = hpos + 80; + if (maxh > maxhpos) + maxh = maxhpos; + while (h < maxh) { + int col = 9; + int cols = 8; + TCHAR l1[81]; + TCHAR l2[81]; + TCHAR l3[81]; + TCHAR l4[81]; + for (i = 0; i < cols && h < maxh; i++, h++, dr++) { + int cl = i * col, cl2; + + _stprintf (l1 + cl, L"[%02X %3d]", h, h); + _tcscpy (l4 + cl, L" "); + if (dr->reg != 0xffff) { + if ((dr->reg & 0x1001) == 0x1000) + _tcscpy (l2 + cl, L" CPU-R "); + else if ((dr->reg & 0x1001) == 0x1001) + _tcscpy (l2 + cl, L" CPU-W "); + else + _stprintf (l2 + cl, L" %03X", dr->reg); + _stprintf (l3 + cl, L" %04X", dr->dat); + if (dr->addr != 0xffffffff) + _stprintf (l4 + cl, L"%08X", dr->addr & 0x00ffffff); + } else { + _tcscpy (l2 + cl, L" "); + _tcscpy (l3 + cl, L" "); + } + cl2 = cl; + if (dr->evt & DMA_EVENT_BLITNASTY) + l2[cl2++] = 'N'; + if (dr->evt & DMA_EVENT_BLITFINISHED) + l2[cl2++] = 'B'; + if (dr->evt & DMA_EVENT_BLITIRQ) + l2[cl2++] = 'b'; + if (dr->evt & DMA_EVENT_BPLFETCHUPDATE) + l2[cl2++] = 'p'; + if (dr->evt & DMA_EVENT_COPPERWAKE) + l2[cl2++] = 'W'; + if (i < cols - 1 && h < maxh - 1) { + l1[cl + col - 1] = 32; + l2[cl + col - 1] = 32; + l3[cl + col - 1] = 32; + l4[cl + col - 1] = 32; + } + } + console_out_f (L"%s\n", l1); + console_out_f (L"%s\n", l2); + console_out_f (L"%s\n", l3); + console_out_f (L"%s\n", l4); + console_out_f (L"\n"); + } } void record_copper (uaecptr addr, int hpos, int vpos) { - int t = nr_cop_records[curr_cop_set]; - if (!cop_record[0]) { - cop_record[0] = xmalloc (NR_COPPER_RECORDS * sizeof (struct cop_rec)); - cop_record[1] = xmalloc (NR_COPPER_RECORDS * sizeof (struct cop_rec)); - } - if (t < NR_COPPER_RECORDS) { - cop_record[curr_cop_set][t].addr = addr; - cop_record[curr_cop_set][t].hpos = hpos; - cop_record[curr_cop_set][t].vpos = vpos; - nr_cop_records[curr_cop_set] = t + 1; - } - if (debug_copper & 2) { /* trace */ - debug_copper &= ~2; - activate_debugger (); - } - if ((debug_copper & 4) && addr >= debug_copper_pc && addr <= debug_copper_pc + 3) { - debug_copper &= ~4; - activate_debugger (); - } + int t = nr_cop_records[curr_cop_set]; + if (!cop_record[0]) { + cop_record[0] = xmalloc (NR_COPPER_RECORDS * sizeof (struct cop_rec)); + cop_record[1] = xmalloc (NR_COPPER_RECORDS * sizeof (struct cop_rec)); + } + if (t < NR_COPPER_RECORDS) { + cop_record[curr_cop_set][t].addr = addr; + cop_record[curr_cop_set][t].hpos = hpos; + cop_record[curr_cop_set][t].vpos = vpos; + nr_cop_records[curr_cop_set] = t + 1; + } + if (debug_copper & 2) { /* trace */ + debug_copper &= ~2; + activate_debugger (); + } + if ((debug_copper & 4) && addr >= debug_copper_pc && addr <= debug_copper_pc + 3) { + debug_copper &= ~4; + activate_debugger (); + } } static struct cop_rec *find_copper_records (uaecptr addr) { - int s = curr_cop_set ^ 1; - int t = nr_cop_records[s]; - int i; - for (i = 0; i < t; i++) { - if (cop_record[s][i].addr == addr) - return &cop_record[s][i]; - } - return 0; + int s = curr_cop_set ^ 1; + int t = nr_cop_records[s]; + int i; + for (i = 0; i < t; i++) { + if (cop_record[s][i].addr == addr) + return &cop_record[s][i]; + } + return 0; } /* simple decode copper by Mark Cox */ static void decode_copper_insn (FILE* file, unsigned long insn, unsigned long addr) { - struct cop_rec *cr = NULL; - uae_u32 insn_type = insn & 0x00010001; - TCHAR here = ' '; - TCHAR record[] = L" "; + struct cop_rec *cr = NULL; + uae_u32 insn_type = insn & 0x00010001; + TCHAR here = ' '; + TCHAR record[] = L" "; - if ((cr = find_copper_records (addr))) { - _stprintf (record, L" [%03x %03x]", cr->vpos, cr->hpos); - } + if ((cr = find_copper_records (addr))) { + _stprintf (record, L" [%03x %03x]", cr->vpos, cr->hpos); + } - if (get_copper_address (-1) >= addr && get_copper_address(-1) <= addr + 3) - here = '*'; + if (get_copper_address (-1) >= addr && get_copper_address(-1) <= addr + 3) + here = '*'; - console_out_f (L"%c%08lx: %04lx %04lx%s\t; ", here, addr, insn >> 16, insn & 0xFFFF, record); + console_out_f (L"%c%08lx: %04lx %04lx%s\t; ", here, addr, insn >> 16, insn & 0xFFFF, record); - switch (insn_type) { - case 0x00010000: /* WAIT insn */ - console_out (L"Wait for "); - disassemble_wait (file, insn); + switch (insn_type) { + case 0x00010000: /* WAIT insn */ + console_out (L"Wait for "); + disassemble_wait (file, insn); - if (insn == 0xfffffffe) - console_out (L" \t; End of Copperlist\n"); + if (insn == 0xfffffffe) + console_out (L" \t; End of Copperlist\n"); - break; + break; - case 0x00010001: /* SKIP insn */ - console_out (L"Skip if "); - disassemble_wait (file, insn); - break; + case 0x00010001: /* SKIP insn */ + console_out (L"Skip if "); + disassemble_wait (file, insn); + break; - case 0x00000000: - case 0x00000001: /* MOVE insn */ - { - int addr = (insn >> 16) & 0x1fe; - int i = 0; - while (custd[i].name) { - if (custd[i].adr == addr + 0xdff000) - break; - i++; - } - if (custd[i].name) - console_out_f (L"%s := 0x%04lx\n", custd[i].name, insn & 0xffff); - else - console_out_f (L"%04x := 0x%04lx\n", addr, insn & 0xffff); - } - break; + case 0x00000000: + case 0x00000001: /* MOVE insn */ + { + int addr = (insn >> 16) & 0x1fe; + int i = 0; + while (custd[i].name) { + if (custd[i].adr == addr + 0xdff000) + break; + i++; + } + if (custd[i].name) + console_out_f (L"%s := 0x%04lx\n", custd[i].name, insn & 0xffff); + else + console_out_f (L"%04x := 0x%04lx\n", addr, insn & 0xffff); + } + break; - default: - abort (); - } + default: + abort (); + } } static uaecptr decode_copperlist (FILE* file, uaecptr address, int nolines) { - uae_u32 insn; - while (nolines-- > 0) { - insn = (chipmem_agnus_wget (address) << 16) | chipmem_agnus_wget (address + 2); - decode_copper_insn (file, insn, address); - address += 4; - } - return address; - /* You may wonder why I don't stop this at the end of the copperlist? - * Well, often nice things are hidden at the end and it is debatable the actual - * values that mean the end of the copperlist */ + uae_u32 insn; + while (nolines-- > 0) { + insn = (chipmem_agnus_wget (address) << 16) | chipmem_agnus_wget (address + 2); + decode_copper_insn (file, insn, address); + address += 4; + } + return address; + /* You may wonder why I don't stop this at the end of the copperlist? + * Well, often nice things are hidden at the end and it is debatable the actual + * values that mean the end of the copperlist */ } static int copper_debugger (TCHAR **c) { - static uaecptr nxcopper; - uae_u32 maddr; - int lines; + static uaecptr nxcopper; + uae_u32 maddr; + int lines; - if (**c == 'd') { - next_char (c); - if (debug_copper) - debug_copper = 0; - else - debug_copper = 1; - console_out_f (L"Copper debugger %s.\n", debug_copper ? L"enabled" : L"disabled"); - } else if (**c == 't') { - debug_copper = 1|2; - return 1; - } else if (**c == 'b') { - (*c)++; - debug_copper = 1|4; - if (more_params (c)) { - debug_copper_pc = readhex (c); - console_out_f (L"Copper breakpoint @0x%08x\n", debug_copper_pc); + if (**c == 'd') { + next_char (c); + if (debug_copper) + debug_copper = 0; + else + debug_copper = 1; + console_out_f (L"Copper debugger %s.\n", debug_copper ? L"enabled" : L"disabled"); + } else if (**c == 't') { + debug_copper = 1|2; + return 1; + } else if (**c == 'b') { + (*c)++; + debug_copper = 1|4; + if (more_params (c)) { + debug_copper_pc = readhex (c); + console_out_f (L"Copper breakpoint @0x%08x\n", debug_copper_pc); + } else { + debug_copper &= ~4; + } } else { - debug_copper &= ~4; - } - } else { - if (more_params (c)) { - maddr = readhex (c); - if (maddr == 1 || maddr == 2) - maddr = get_copper_address (maddr); - else if (maddr == 0) - maddr = get_copper_address (-1); - } else - maddr = nxcopper; + if (more_params (c)) { + maddr = readhex (c); + if (maddr == 1 || maddr == 2) + maddr = get_copper_address (maddr); + else if (maddr == 0) + maddr = get_copper_address (-1); + } else + maddr = nxcopper; - if (more_params (c)) - lines = readhex (c); - else - lines = 20; + if (more_params (c)) + lines = readhex (c); + else + lines = 20; - nxcopper = decode_copperlist (stdout, maddr, lines); - } - return 0; + nxcopper = decode_copperlist (stdout, maddr, lines); + } + return 0; } #define MAX_CHEAT_VIEW 100 struct trainerstruct { - uaecptr addr; - int size; + uaecptr addr; + int size; }; static struct trainerstruct *trainerdata; @@ -1079,288 +1081,288 @@ static int totaltrainers; static void clearcheater(void) { - if (!trainerdata) - trainerdata = xmalloc(MAX_CHEAT_VIEW * sizeof (struct trainerstruct)); - memset(trainerdata, 0, sizeof (struct trainerstruct) * MAX_CHEAT_VIEW); - totaltrainers = 0; + if (!trainerdata) + trainerdata = xmalloc(MAX_CHEAT_VIEW * sizeof (struct trainerstruct)); + memset(trainerdata, 0, sizeof (struct trainerstruct) * MAX_CHEAT_VIEW); + totaltrainers = 0; } static int addcheater(uaecptr addr, int size) { - if (totaltrainers >= MAX_CHEAT_VIEW) - return 0; - trainerdata[totaltrainers].addr = addr; - trainerdata[totaltrainers].size = size; - totaltrainers++; - return 1; + if (totaltrainers >= MAX_CHEAT_VIEW) + return 0; + trainerdata[totaltrainers].addr = addr; + trainerdata[totaltrainers].size = size; + totaltrainers++; + return 1; } static void listcheater(int mode, int size) { - int i, skip; + int i, skip; - if (!trainerdata) - return; - if (mode) - skip = 6; - else - skip = 8; - for(i = 0; i < totaltrainers; i++) { - struct trainerstruct *ts = &trainerdata[i]; - uae_u16 b; - - if (size) { - b = get_byte (ts->addr); - } else { - b = get_word (ts->addr); - } + if (!trainerdata) + return; if (mode) - console_out_f (L"%08X=%04X ", ts->addr, b); + skip = 6; else - console_out_f (L"%08X ", ts->addr); - if ((i % skip) == skip) - console_out (L"\n"); - } + skip = 8; + for(i = 0; i < totaltrainers; i++) { + struct trainerstruct *ts = &trainerdata[i]; + uae_u16 b; + + if (size) { + b = get_byte (ts->addr); + } else { + b = get_word (ts->addr); + } + if (mode) + console_out_f (L"%08X=%04X ", ts->addr, b); + else + console_out_f (L"%08X ", ts->addr); + if ((i % skip) == skip) + console_out (L"\n"); + } } static void deepcheatsearch (TCHAR **c) { - static int first = 1; - static uae_u8 *memtmp; - static int memsize, memsize2; - uae_u8 *p1, *p2; - uaecptr addr, end; - int i, wasmodified, nonmodified; - static int size; - static int inconly, deconly, maxdiff; - int addrcnt, cnt; - TCHAR v; - - v = _totupper (**c); - - if(!memtmp || v == 'S') { - maxdiff = 0x10000; - inconly = 0; - deconly = 0; - size = 1; - } - - if (**c) - (*c)++; - ignore_ws (c); - if ((**c) == '1' || (**c) == '2') { - size = **c - '0'; - (*c)++; - } - if (more_params (c)) - maxdiff = readint(c); - - if (!memtmp || v == 'S') { - first = 1; - xfree (memtmp); - memsize = 0; - addr = 0xffffffff; - while ((addr = nextaddr (addr, &end)) != 0xffffffff) { - memsize += end - addr; - addr = end - 1; - } - memsize2 = (memsize + 7) / 8; - memtmp = xmalloc (memsize + memsize2); - if (!memtmp) - return; - memset (memtmp + memsize, 0xff, memsize2); + static int first = 1; + static uae_u8 *memtmp; + static int memsize, memsize2; + uae_u8 *p1, *p2; + uaecptr addr, end; + int i, wasmodified, nonmodified; + static int size; + static int inconly, deconly, maxdiff; + int addrcnt, cnt; + TCHAR v; + + v = _totupper (**c); + + if(!memtmp || v == 'S') { + maxdiff = 0x10000; + inconly = 0; + deconly = 0; + size = 1; + } + + if (**c) + (*c)++; + ignore_ws (c); + if ((**c) == '1' || (**c) == '2') { + size = **c - '0'; + (*c)++; + } + if (more_params (c)) + maxdiff = readint(c); + + if (!memtmp || v == 'S') { + first = 1; + xfree (memtmp); + memsize = 0; + addr = 0xffffffff; + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { + memsize += end - addr; + addr = end - 1; + } + memsize2 = (memsize + 7) / 8; + memtmp = xmalloc (memsize + memsize2); + if (!memtmp) + return; + memset (memtmp + memsize, 0xff, memsize2); + p1 = memtmp; + addr = 0xffffffff; + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { + for (i = addr; i < end; i++) + *p1++ = get_byte (i); + addr = end - 1; + } + console_out (L"Deep trainer first pass complete.\n"); + return; + } + inconly = deconly = 0; + wasmodified = v == 'X' ? 0 : 1; + nonmodified = v == 'Z' ? 1 : 0; + if (v == 'I') + inconly = 1; + if (v == 'D') + deconly = 1; p1 = memtmp; + p2 = memtmp + memsize; + addrcnt = 0; + cnt = 0; addr = 0xffffffff; - while ((addr = nextaddr (addr, &end)) != 0xffffffff) { - for (i = addr; i < end; i++) - *p1++ = get_byte (i); - addr = end - 1; + while ((addr = nextaddr (addr, NULL)) != 0xffffffff) { + uae_s32 b, b2; + int doremove = 0; + int addroff = addrcnt >> 3; + int addrmask ; + + if (size == 1) { + b = (uae_s8)get_byte (addr); + b2 = (uae_s8)p1[addrcnt]; + addrmask = 1 << (addrcnt & 7); + } else { + b = (uae_s16)get_word (addr); + b2 = (uae_s16)((p1[addrcnt] << 8) | p1[addrcnt + 1]); + addrmask = 3 << (addrcnt & 7); + } + + if (p2[addroff] & addrmask) { + if (wasmodified && !nonmodified) { + int diff = b - b2; + if (b == b2) + doremove = 1; + if (abs(diff) > maxdiff) + doremove = 1; + if (inconly && diff < 0) + doremove = 1; + if (deconly && diff > 0) + doremove = 1; + } else if (nonmodified && b != b2) { + doremove = 1; + } else if (!wasmodified && b != b2) { + doremove = 1; + } + if (doremove) + p2[addroff] &= ~addrmask; + else + cnt++; + } + if (size == 1) { + p1[addrcnt] = b; + addrcnt++; + } else { + p1[addrcnt] = b >> 8; + p1[addrcnt + 1] = b >> 0; + addr = nextaddr (addr, NULL); + if (addr == 0xffffffff) + break; + addrcnt += 2; + } } - console_out (L"Deep trainer first pass complete.\n"); - return; - } - inconly = deconly = 0; - wasmodified = v == 'X' ? 0 : 1; - nonmodified = v == 'Z' ? 1 : 0; - if (v == 'I') - inconly = 1; - if (v == 'D') - deconly = 1; - p1 = memtmp; - p2 = memtmp + memsize; - addrcnt = 0; - cnt = 0; - addr = 0xffffffff; - while ((addr = nextaddr (addr, NULL)) != 0xffffffff) { - uae_s32 b, b2; - int doremove = 0; - int addroff = addrcnt >> 3; - int addrmask ; - - if (size == 1) { - b = (uae_s8)get_byte (addr); - b2 = (uae_s8)p1[addrcnt]; - addrmask = 1 << (addrcnt & 7); - } else { - b = (uae_s16)get_word (addr); - b2 = (uae_s16)((p1[addrcnt] << 8) | p1[addrcnt + 1]); - addrmask = 3 << (addrcnt & 7); - } - - if (p2[addroff] & addrmask) { - if (wasmodified && !nonmodified) { - int diff = b - b2; - if (b == b2) - doremove = 1; - if (abs(diff) > maxdiff) - doremove = 1; - if (inconly && diff < 0) - doremove = 1; - if (deconly && diff > 0) - doremove = 1; - } else if (nonmodified && b != b2) { - doremove = 1; - } else if (!wasmodified && b != b2) { - doremove = 1; - } - if (doremove) - p2[addroff] &= ~addrmask; - else - cnt++; - } - if (size == 1) { - p1[addrcnt] = b; - addrcnt++; + + console_out_f (L"%d addresses found\n", cnt); + if (cnt <= MAX_CHEAT_VIEW) { + clearcheater (); + cnt = 0; + addrcnt = 0; + addr = 0xffffffff; + while ((addr = nextaddr(addr, NULL)) != 0xffffffff) { + int addroff = addrcnt >> 3; + int addrmask = (size == 1 ? 1 : 3) << (addrcnt & 7); + if (p2[addroff] & addrmask) + addcheater (addr, size); + addrcnt += size; + cnt++; + } + if (cnt > 0) + console_out (L"\n"); + listcheater (1, size); } else { - p1[addrcnt] = b >> 8; - p1[addrcnt + 1] = b >> 0; - addr = nextaddr (addr, NULL); - if (addr == 0xffffffff) - break; - addrcnt += 2; + console_out (L"Now continue with 'g' and use 'D' again after you have lost another life\n"); } - } - - console_out_f (L"%d addresses found\n", cnt); - if (cnt <= MAX_CHEAT_VIEW) { - clearcheater (); - cnt = 0; - addrcnt = 0; - addr = 0xffffffff; - while ((addr = nextaddr(addr, NULL)) != 0xffffffff) { - int addroff = addrcnt >> 3; - int addrmask = (size == 1 ? 1 : 3) << (addrcnt & 7); - if (p2[addroff] & addrmask) - addcheater (addr, size); - addrcnt += size; - cnt++; - } - if (cnt > 0) - console_out (L"\n"); - listcheater (1, size); - } else { - console_out (L"Now continue with 'g' and use 'D' again after you have lost another life\n"); - } } /* cheat-search by Toni Wilen (originally by Holger Jakob) */ static void cheatsearch (TCHAR **c) { - static uae_u8 *vlist; - static int listsize; - static int first = 1; - static int size = 1; - uae_u32 val, memcnt, prevmemcnt; - int i, count, vcnt, memsize; - uaecptr addr, end; - - memsize = 0; - addr = 0xffffffff; - while ((addr = nextaddr (addr, &end)) != 0xffffffff) { - memsize += end - addr; - addr = end - 1; - } - - if (_totupper (**c) == 'L') { - listcheater (1, size); - return; - } - ignore_ws (c); - if (!more_params (c)) { - first = 1; - console_out (L"Search reset\n"); - xfree (vlist); - listsize = memsize; - vlist = xcalloc (listsize >> 3, 1); - return; - } - val = readint (c); - if (first) { - if (val > 255) - size = 2; - if (val > 65535) - size = 3; - if (val > 16777215) - size = 4; - } - ignore_ws (c); - if (more_params (c)) - size = readint (c); - if (size > 4) - size = 4; - if (size < 1) - size = 1; + static uae_u8 *vlist; + static int listsize; + static int first = 1; + static int size = 1; + uae_u32 val, memcnt, prevmemcnt; + int i, count, vcnt, memsize; + uaecptr addr, end; + + memsize = 0; + addr = 0xffffffff; + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { + memsize += end - addr; + addr = end - 1; + } + + if (_totupper (**c) == 'L') { + listcheater (1, size); + return; + } + ignore_ws (c); + if (!more_params (c)) { + first = 1; + console_out (L"Search reset\n"); + xfree (vlist); + listsize = memsize; + vlist = xcalloc (listsize >> 3, 1); + return; + } + val = readint (c); + if (first) { + if (val > 255) + size = 2; + if (val > 65535) + size = 3; + if (val > 16777215) + size = 4; + } + ignore_ws (c); + if (more_params (c)) + size = readint (c); + if (size > 4) + size = 4; + if (size < 1) + size = 1; + + if (vlist == NULL) { + listsize = memsize; + vlist = xcalloc (listsize >> 3, 1); + } + + count = 0; + vcnt = 0; - if (vlist == NULL) { - listsize = memsize; - vlist = xcalloc (listsize >> 3, 1); - } - - count = 0; - vcnt = 0; - - clearcheater (); - addr = 0xffffffff; - prevmemcnt = memcnt = 0; - while ((addr = nextaddr (addr, &end)) != 0xffffffff) { - if (addr + size < end) { - for (i = 0; i < size; i++) { - int shift = (size - i - 1) * 8; - if (get_byte (addr + i) != ((val >> shift) & 0xff)) - break; - } - if (i == size) { - int voffset = memcnt >> 3; - int vmask = 1 << (memcnt & 7); - if (!first) { - while (prevmemcnt < memcnt) { + clearcheater (); + addr = 0xffffffff; + prevmemcnt = memcnt = 0; + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { + if (addr + size < end) { + for (i = 0; i < size; i++) { + int shift = (size - i - 1) * 8; + if (get_byte (addr + i) != ((val >> shift) & 0xff)) + break; + } + if (i == size) { + int voffset = memcnt >> 3; + int vmask = 1 << (memcnt & 7); + if (!first) { + while (prevmemcnt < memcnt) { + vlist[prevmemcnt >> 3] &= ~(1 << (prevmemcnt & 7)); + prevmemcnt++; + } + if (vlist[voffset] & vmask) { + count++; + addcheater(addr, size); + } else { + vlist[voffset] &= ~vmask; + } + prevmemcnt = memcnt + 1; + } else { + vlist[voffset] |= vmask; + count++; + } + } + } + memcnt++; + } + if (!first) { + while (prevmemcnt < memcnt) { vlist[prevmemcnt >> 3] &= ~(1 << (prevmemcnt & 7)); prevmemcnt++; - } - if (vlist[voffset] & vmask) { - count++; - addcheater(addr, size); - } else { - vlist[voffset] &= ~vmask; - } - prevmemcnt = memcnt + 1; - } else { - vlist[voffset] |= vmask; - count++; } - } - } - memcnt++; - } - if (!first) { - while (prevmemcnt < memcnt) { - vlist[prevmemcnt >> 3] &= ~(1 << (prevmemcnt & 7)); - prevmemcnt++; + listcheater (0, size); } - listcheater (0, size); - } - console_out_f (L"Found %d possible addresses with 0x%X (%u) (%d bytes)\n", count, val, val, size); - if (count > 0) - console_out (L"Now continue with 'g' and use 'C' with a different value\n"); - first = 0; + console_out_f (L"Found %d possible addresses with 0x%X (%u) (%d bytes)\n", count, val, val, size); + if (count > 0) + console_out (L"Now continue with 'g' and use 'C' with a different value\n"); + first = 0; } struct breakpoint_node bpnodes[BREAKPOINT_TOTAL]; @@ -1374,127 +1376,127 @@ static int illgdebug_break; static void illg_free (void) { - xfree (illgdebug); - illgdebug = NULL; - xfree (illghdebug); - illghdebug = NULL; + xfree (illgdebug); + illgdebug = NULL; + xfree (illghdebug); + illghdebug = NULL; } static void illg_init (void) { - int i; - uae_u8 c = 3; - uaecptr addr, end; + int i; + uae_u8 c = 3; + uaecptr addr, end; - illgdebug = xcalloc (0x01000000, 1); - illghdebug = xcalloc (65536, 1); - if (!illgdebug || !illghdebug) { - illg_free(); - return; - } - addr = 0xffffffff; - while ((addr = nextaddr (addr, &end)) != 0xffffffff) { - if (end < 0x01000000) { - memset (illgdebug + addr, c, end - addr); - } else { - uae_u32 s = addr >> 16; - uae_u32 e = end >> 16; - memset (illghdebug + s, c, e - s); - } - addr = end - 1; - } - if (currprefs.gfxmem_size) - memset (illghdebug + (p96ram_start >> 16), 3, currprefs.gfxmem_size >> 16); - - i = 0; - while (custd[i].name) { - int rw = custd[i].rw; - illgdebug[custd[i].adr] = rw; - illgdebug[custd[i].adr + 1] = rw; - i++; - } - for (i = 0; i < 16; i++) { /* CIAs */ - if (i == 11) - continue; - illgdebug[0xbfe001 + i * 0x100] = c; - illgdebug[0xbfd000 + i * 0x100] = c; - } - memset (illgdebug + 0xf80000, 1, 512 * 1024); /* KS ROM */ - memset (illgdebug + 0xdc0000, c, 0x3f); /* clock */ + illgdebug = xcalloc (0x01000000, 1); + illghdebug = xcalloc (65536, 1); + if (!illgdebug || !illghdebug) { + illg_free(); + return; + } + addr = 0xffffffff; + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { + if (end < 0x01000000) { + memset (illgdebug + addr, c, end - addr); + } else { + uae_u32 s = addr >> 16; + uae_u32 e = end >> 16; + memset (illghdebug + s, c, e - s); + } + addr = end - 1; + } + if (currprefs.gfxmem_size) + memset (illghdebug + (p96ram_start >> 16), 3, currprefs.gfxmem_size >> 16); + + i = 0; + while (custd[i].name) { + int rw = custd[i].rw; + illgdebug[custd[i].adr] = rw; + illgdebug[custd[i].adr + 1] = rw; + i++; + } + for (i = 0; i < 16; i++) { /* CIAs */ + if (i == 11) + continue; + illgdebug[0xbfe001 + i * 0x100] = c; + illgdebug[0xbfd000 + i * 0x100] = c; + } + memset (illgdebug + 0xf80000, 1, 512 * 1024); /* KS ROM */ + memset (illgdebug + 0xdc0000, c, 0x3f); /* clock */ #ifdef CDTV - if (currprefs.cs_cdtvram) { - memset (illgdebug + 0xdc8000, c, 4096); /* CDTV batt RAM */ - memset (illgdebug + 0xf00000, 1, 256 * 1024); /* CDTV ext ROM */ - } + if (currprefs.cs_cdtvram) { + memset (illgdebug + 0xdc8000, c, 4096); /* CDTV batt RAM */ + memset (illgdebug + 0xf00000, 1, 256 * 1024); /* CDTV ext ROM */ + } #endif #ifdef CD32 - if (currprefs.cs_cd32cd) { - memset (illgdebug + AKIKO_BASE, c, AKIKO_BASE_END - AKIKO_BASE); - memset (illgdebug + 0xe00000, 1, 512 * 1024); /* CD32 ext ROM */ - } + if (currprefs.cs_cd32cd) { + memset (illgdebug + AKIKO_BASE, c, AKIKO_BASE_END - AKIKO_BASE); + memset (illgdebug + 0xe00000, 1, 512 * 1024); /* CD32 ext ROM */ + } #endif - if (currprefs.cs_ksmirror_e0) - memset (illgdebug + 0xe00000, 1, 512 * 1024); - if (currprefs.cs_ksmirror_a8) - memset (illgdebug + 0xa80000, 1, 2 * 512 * 1024); + if (currprefs.cs_ksmirror_e0) + memset (illgdebug + 0xe00000, 1, 512 * 1024); + if (currprefs.cs_ksmirror_a8) + memset (illgdebug + 0xa80000, 1, 2 * 512 * 1024); #ifdef FILESYS - if (uae_boot_rom) /* filesys "rom" */ - memset (illgdebug + rtarea_base, 1, 0x10000); + if (uae_boot_rom) /* filesys "rom" */ + memset (illgdebug + rtarea_base, 1, 0x10000); #endif - if (currprefs.cs_ide > 0) - memset (illgdebug + 0xdd0000, 3, 65536); + if (currprefs.cs_ide > 0) + memset (illgdebug + 0xdd0000, 3, 65536); } /* add special custom register check here */ static void illg_debug_check (uaecptr addr, int rwi, int size, uae_u32 val) { - return; + return; } static void illg_debug_do (uaecptr addr, int rwi, int size, uae_u32 val) { - uae_u8 mask; - uae_u32 pc = m68k_getpc (); - int i; + uae_u8 mask; + uae_u32 pc = m68k_getpc (); + int i; - for (i = size - 1; i >= 0; i--) { - uae_u8 v = val >> (i * 8); - uae_u32 ad = addr + i; - if (ad >= 0x01000000) - mask = illghdebug[ad >> 16]; - else - mask = illgdebug[ad]; - if ((mask & 3) == 3) - return; - if (mask & 0x80) { - illg_debug_check (ad, rwi, size, val); - } else if ((mask & 3) == 0) { - if (rwi & 2) - console_out_f (L"W: %08X=%02X PC=%08X\n", ad, v, pc); - else if (rwi & 1) - console_out_f (L"R: %08X PC=%08X\n", ad, pc); - if (illgdebug_break) - activate_debugger (); - } else if (!(mask & 1) && (rwi & 1)) { - console_out_f (L"RO: %08X=%02X PC=%08X\n", ad, v, pc); - if (illgdebug_break) - activate_debugger (); - } else if (!(mask & 2) && (rwi & 2)) { - console_out_f (L"WO: %08X PC=%08X\n", ad, pc); - if (illgdebug_break) - activate_debugger (); + for (i = size - 1; i >= 0; i--) { + uae_u8 v = val >> (i * 8); + uae_u32 ad = addr + i; + if (ad >= 0x01000000) + mask = illghdebug[ad >> 16]; + else + mask = illgdebug[ad]; + if ((mask & 3) == 3) + return; + if (mask & 0x80) { + illg_debug_check (ad, rwi, size, val); + } else if ((mask & 3) == 0) { + if (rwi & 2) + console_out_f (L"W: %08X=%02X PC=%08X\n", ad, v, pc); + else if (rwi & 1) + console_out_f (L"R: %08X PC=%08X\n", ad, pc); + if (illgdebug_break) + activate_debugger (); + } else if (!(mask & 1) && (rwi & 1)) { + console_out_f (L"RO: %08X=%02X PC=%08X\n", ad, v, pc); + if (illgdebug_break) + activate_debugger (); + } else if (!(mask & 2) && (rwi & 2)) { + console_out_f (L"WO: %08X PC=%08X\n", ad, pc); + if (illgdebug_break) + activate_debugger (); + } } - } } static int debug_mem_off (uaecptr addr) { - return munge24 (addr) >> 16; + return munge24 (addr) >> 16; } struct smc_item { - uae_u32 addr; - uae_u8 cnt; + uae_u32 addr; + uae_u8 cnt; }; static int smc_size, smc_mode; @@ -1502,817 +1504,817 @@ static struct smc_item *smc_table; static void smc_free (void) { - if (smc_table) - console_out (L"SMCD disabled\n"); - xfree(smc_table); - smc_mode = 0; - smc_table = NULL; + if (smc_table) + console_out (L"SMCD disabled\n"); + xfree(smc_table); + smc_mode = 0; + smc_table = NULL; } static void initialize_memwatch (int mode); static void smc_detect_init (TCHAR **c) { - int v, i; - - ignore_ws (c); - v = readint (c); - smc_free (); - smc_size = 1 << 24; - if (currprefs.z3fastmem_size) - smc_size = currprefs.z3fastmem_start + currprefs.z3fastmem_size; - smc_size += 4; - smc_table = xmalloc (smc_size * sizeof (struct smc_item)); - if (!smc_table) - return; - for (i = 0; i < smc_size; i++) { - smc_table[i].addr = 0xffffffff; - smc_table[i].cnt = 0; - } - if (!memwatch_enabled) - initialize_memwatch (0); - if (v) - smc_mode = 1; - console_out_f (L"SMCD enabled. Break=%d\n", smc_mode); + int v, i; + + ignore_ws (c); + v = readint (c); + smc_free (); + smc_size = 1 << 24; + if (currprefs.z3fastmem_size) + smc_size = currprefs.z3fastmem_start + currprefs.z3fastmem_size; + smc_size += 4; + smc_table = xmalloc (smc_size * sizeof (struct smc_item)); + if (!smc_table) + return; + for (i = 0; i < smc_size; i++) { + smc_table[i].addr = 0xffffffff; + smc_table[i].cnt = 0; + } + if (!memwatch_enabled) + initialize_memwatch (0); + if (v) + smc_mode = 1; + console_out_f (L"SMCD enabled. Break=%d\n", smc_mode); } #define SMC_MAXHITS 8 static void smc_detector (uaecptr addr, int rwi, int size, uae_u32 *valp) { - int i, hitcnt; - uaecptr hitaddr, hitpc; + int i, hitcnt; + uaecptr hitaddr, hitpc; - if (!smc_table) - return; - if (addr >= smc_size) - return; - if (rwi == 2) { - for (i = 0; i < size; i++) { - if (smc_table[addr + i].cnt < SMC_MAXHITS) { - smc_table[addr + i].addr = m68k_getpc (); - } + if (!smc_table) + return; + if (addr >= smc_size) + return; + if (rwi == 2) { + for (i = 0; i < size; i++) { + if (smc_table[addr + i].cnt < SMC_MAXHITS) { + smc_table[addr + i].addr = m68k_getpc (); + } + } + return; + } + hitpc = smc_table[addr].addr; + if (hitpc == 0xffffffff) + return; + hitaddr = addr; + hitcnt = 0; + while (addr < smc_size && smc_table[addr].addr != 0xffffffff) { + smc_table[addr++].addr = 0xffffffff; + hitcnt++; + } + if ((hitpc & 0xFFF80000) == 0xF80000) + return; + if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) { + /* ignore single-word unconditional jump instructions + * (instruction prefetch from PC+2 can cause false positives) */ + if (regs.irc == 0x4e75 || regs.irc == 4e74 || regs.irc == 0x4e72 || regs.irc == 0x4e77) + return; /* RTS, RTD, RTE, RTR */ + if ((regs.irc & 0xff00) == 0x6000 && (regs.irc & 0x00ff) != 0 && (regs.irc & 0x00ff) != 0xff) + return; /* BRA.B */ + } + if (hitcnt < 100) { + smc_table[hitaddr].cnt++; + console_out_f (L"SMC at %08X - %08X (%d) from %08X\n", + hitaddr, hitaddr + hitcnt, hitcnt, hitpc); + if (smc_mode) + activate_debugger (); + if (smc_table[hitaddr].cnt >= SMC_MAXHITS) + console_out_f (L"* hit count >= %d, future hits ignored\n", SMC_MAXHITS); } - return; - } - hitpc = smc_table[addr].addr; - if (hitpc == 0xffffffff) - return; - hitaddr = addr; - hitcnt = 0; - while (addr < smc_size && smc_table[addr].addr != 0xffffffff) { - smc_table[addr++].addr = 0xffffffff; - hitcnt++; - } - if ((hitpc & 0xFFF80000) == 0xF80000) - return; - if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) { - /* ignore single-word unconditional jump instructions - * (instruction prefetch from PC+2 can cause false positives) */ - if (regs.irc == 0x4e75 || regs.irc == 4e74 || regs.irc == 0x4e72 || regs.irc == 0x4e77) - return; /* RTS, RTD, RTE, RTR */ - if ((regs.irc & 0xff00) == 0x6000 && (regs.irc & 0x00ff) != 0 && (regs.irc & 0x00ff) != 0xff) - return; /* BRA.B */ - } - if (hitcnt < 100) { - smc_table[hitaddr].cnt++; - console_out_f (L"SMC at %08X - %08X (%d) from %08X\n", - hitaddr, hitaddr + hitcnt, hitcnt, hitpc); - if (smc_mode) - activate_debugger (); - if (smc_table[hitaddr].cnt >= SMC_MAXHITS) - console_out_f (L"* hit count >= %d, future hits ignored\n", SMC_MAXHITS); - } } static int memwatch_func (uaecptr addr, int rwi, int size, uae_u32 *valp) { - int i, brk; - uae_u32 val = *valp; - - if (illgdebug) - illg_debug_do (addr, rwi, size, val); - addr = munge24 (addr); - if (smc_table && (rwi >= 2)) - smc_detector (addr, rwi, size, valp); - for (i = 0; i < MEMWATCH_TOTAL; i++) { - struct memwatch_node *m = &mwnodes[i]; - uaecptr addr2 = m->addr; - uaecptr addr3 = addr2 + m->size; - int rwi2 = m->rwi; - uae_u32 oldval = 0; - int isoldval = 0; - - brk = 0; - if (m->size == 0) - continue; - if (!(rwi & rwi2)) - continue; - if (addr >= addr2 && addr < addr3) - brk = 1; - if (!brk && size == 2 && (addr + 1 >= addr2 && addr + 1 < addr3)) - brk = 1; - if (!brk && size == 4 && ((addr + 2 >= addr2 && addr + 2 < addr3) || (addr + 3 >= addr2 && addr + 3 < addr3))) - brk = 1; - - if (!brk) - continue; - if (mem_banks[addr >> 16]->check (addr, size)) { - uae_u8 *p = mem_banks[addr >> 16]->xlateaddr (addr); - if (size == 1) - oldval = p[0]; - else if (size == 2) - oldval = (p[0] << 8) | p[1]; - else - oldval = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); - isoldval = 1; - } - - if (!m->frozen && m->val_enabled) { - int trigger = 0; - uae_u32 mask = (1 << (m->size * 8)) - 1; - int scnt = size; - for (;;) { - if (((m->val & mask) & m->valmask) == ((val & mask) & m->valmask)) - trigger = 1; - if (mask & 0x80000000) - break; - if (m->size == 1) { - mask <<= 8; - scnt--; - } else if (m->size == 2) { - mask <<= 16; - scnt -= 2; + int i, brk; + uae_u32 val = *valp; + + if (illgdebug) + illg_debug_do (addr, rwi, size, val); + addr = munge24 (addr); + if (smc_table && (rwi >= 2)) + smc_detector (addr, rwi, size, valp); + for (i = 0; i < MEMWATCH_TOTAL; i++) { + struct memwatch_node *m = &mwnodes[i]; + uaecptr addr2 = m->addr; + uaecptr addr3 = addr2 + m->size; + int rwi2 = m->rwi; + uae_u32 oldval = 0; + int isoldval = 0; + + brk = 0; + if (m->size == 0) + continue; + if (!(rwi & rwi2)) + continue; + if (addr >= addr2 && addr < addr3) + brk = 1; + if (!brk && size == 2 && (addr + 1 >= addr2 && addr + 1 < addr3)) + brk = 1; + if (!brk && size == 4 && ((addr + 2 >= addr2 && addr + 2 < addr3) || (addr + 3 >= addr2 && addr + 3 < addr3))) + brk = 1; + + if (!brk) + continue; + if (mem_banks[addr >> 16]->check (addr, size)) { + uae_u8 *p = mem_banks[addr >> 16]->xlateaddr (addr); + if (size == 1) + oldval = p[0]; + else if (size == 2) + oldval = (p[0] << 8) | p[1]; + else + oldval = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); + isoldval = 1; } - if (scnt <= 0) - break; - } - if (!trigger) - continue; - } - if (m->mustchange && rwi == 2 && isoldval) { - if (oldval == *valp) - continue; - } + if (!m->frozen && m->val_enabled) { + int trigger = 0; + uae_u32 mask = (1 << (m->size * 8)) - 1; + int scnt = size; + for (;;) { + if (((m->val & mask) & m->valmask) == ((val & mask) & m->valmask)) + trigger = 1; + if (mask & 0x80000000) + break; + if (m->size == 1) { + mask <<= 8; + scnt--; + } else if (m->size == 2) { + mask <<= 16; + scnt -= 2; + } + if (scnt <= 0) + break; + } + if (!trigger) + continue; + } - if (m->modval_written) { - if (!rwi) { - brk = 0; - } else if (m->modval_written == 1) { - m->modval_written = 2; - m->modval = val; - brk = 0; - } else if (m->modval == val) { - brk = 0; - } - } - if (m->frozen) { - if (m->val_enabled) { - int shift = addr - m->addr; - int max = 0; - if (m->val > 256) - max = 1; - if (m->val > 65536) - max = 3; - shift &= max; - *valp = m->val >> ((max - shift) * 8); - } - return 0; - } -// if (!notinrom ()) -// return 1; - mwhit.pc = M68K_GETPC; - mwhit.addr = addr; - mwhit.rwi = rwi; - mwhit.size = size; - mwhit.val = 0; - if (mwhit.rwi & 2) - mwhit.val = val; - memwatch_triggered = i + 1; - debugging = 1; - set_special (SPCFLAG_BRK); + if (m->mustchange && rwi == 2 && isoldval) { + if (oldval == *valp) + continue; + } + + if (m->modval_written) { + if (!rwi) { + brk = 0; + } else if (m->modval_written == 1) { + m->modval_written = 2; + m->modval = val; + brk = 0; + } else if (m->modval == val) { + brk = 0; + } + } + if (m->frozen) { + if (m->val_enabled) { + int shift = addr - m->addr; + int max = 0; + if (m->val > 256) + max = 1; + if (m->val > 65536) + max = 3; + shift &= max; + *valp = m->val >> ((max - shift) * 8); + } + return 0; + } + // if (!notinrom ()) + // return 1; + mwhit.pc = M68K_GETPC; + mwhit.addr = addr; + mwhit.rwi = rwi; + mwhit.size = size; + mwhit.val = 0; + if (mwhit.rwi & 2) + mwhit.val = val; + memwatch_triggered = i + 1; + debugging = 1; + set_special (SPCFLAG_BRK); + return 1; + } return 1; - } - return 1; } static int mmu_hit (uaecptr addr, int size, int rwi, uae_u32 *v); static uae_u32 REGPARAM2 mmu_lget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v = 0; - if (!mmu_hit (addr, 4, 0, &v)) - v = debug_mem_banks[off]->lget (addr); - return v; + int off = debug_mem_off (addr); + uae_u32 v = 0; + if (!mmu_hit (addr, 4, 0, &v)) + v = debug_mem_banks[off]->lget (addr); + return v; } static uae_u32 REGPARAM2 mmu_wget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v = 0; - if (!mmu_hit (addr, 2, 0, &v)) - v = debug_mem_banks[off]->wget (addr); - return v; + int off = debug_mem_off (addr); + uae_u32 v = 0; + if (!mmu_hit (addr, 2, 0, &v)) + v = debug_mem_banks[off]->wget (addr); + return v; } static uae_u32 REGPARAM2 mmu_bget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v = 0; - if (!mmu_hit(addr, 1, 0, &v)) - v = debug_mem_banks[off]->bget (addr); - return v; + int off = debug_mem_off (addr); + uae_u32 v = 0; + if (!mmu_hit(addr, 1, 0, &v)) + v = debug_mem_banks[off]->bget (addr); + return v; } static void REGPARAM2 mmu_lput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (!mmu_hit (addr, 4, 1, &v)) - debug_mem_banks[off]->lput (addr, v); + int off = debug_mem_off (addr); + if (!mmu_hit (addr, 4, 1, &v)) + debug_mem_banks[off]->lput (addr, v); } static void REGPARAM2 mmu_wput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (!mmu_hit (addr, 2, 1, &v)) - debug_mem_banks[off]->wput (addr, v); + int off = debug_mem_off (addr); + if (!mmu_hit (addr, 2, 1, &v)) + debug_mem_banks[off]->wput (addr, v); } static void REGPARAM2 mmu_bput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (!mmu_hit (addr, 1, 1, &v)) - debug_mem_banks[off]->bput (addr, v); + int off = debug_mem_off (addr); + if (!mmu_hit (addr, 1, 1, &v)) + debug_mem_banks[off]->bput (addr, v); } static uae_u32 REGPARAM2 debug_lget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v; - v = debug_mem_banks[off]->lget (addr); - memwatch_func (addr, 1, 4, &v); - return v; + int off = debug_mem_off (addr); + uae_u32 v; + v = debug_mem_banks[off]->lget (addr); + memwatch_func (addr, 1, 4, &v); + return v; } static uae_u32 REGPARAM2 mmu_lgeti (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v = 0; - if (!mmu_hit (addr, 4, 4, &v)) - v = debug_mem_banks[off]->lgeti (addr); - return v; + int off = debug_mem_off (addr); + uae_u32 v = 0; + if (!mmu_hit (addr, 4, 4, &v)) + v = debug_mem_banks[off]->lgeti (addr); + return v; } static uae_u32 REGPARAM2 mmu_wgeti (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v = 0; - if (!mmu_hit (addr, 2, 4, &v)) - v = debug_mem_banks[off]->wgeti (addr); - return v; + int off = debug_mem_off (addr); + uae_u32 v = 0; + if (!mmu_hit (addr, 2, 4, &v)) + v = debug_mem_banks[off]->wgeti (addr); + return v; } static uae_u32 REGPARAM2 debug_wget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v; - v = debug_mem_banks[off]->wget (addr); - memwatch_func (addr, 1, 2, &v); - return v; + int off = debug_mem_off (addr); + uae_u32 v; + v = debug_mem_banks[off]->wget (addr); + memwatch_func (addr, 1, 2, &v); + return v; } static uae_u32 REGPARAM2 debug_bget (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v; - v = debug_mem_banks[off]->bget (addr); - memwatch_func (addr, 1, 1, &v); - return v; + int off = debug_mem_off (addr); + uae_u32 v; + v = debug_mem_banks[off]->bget (addr); + memwatch_func (addr, 1, 1, &v); + return v; } static uae_u32 REGPARAM2 debug_lgeti (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v; - v = debug_mem_banks[off]->lgeti (addr); - memwatch_func (addr, 4, 4, &v); - return v; + int off = debug_mem_off (addr); + uae_u32 v; + v = debug_mem_banks[off]->lgeti (addr); + memwatch_func (addr, 4, 4, &v); + return v; } static uae_u32 REGPARAM2 debug_wgeti (uaecptr addr) { - int off = debug_mem_off (addr); - uae_u32 v; - v = debug_mem_banks[off]->wgeti (addr); - memwatch_func (addr, 4, 2, &v); - return v; + int off = debug_mem_off (addr); + uae_u32 v; + v = debug_mem_banks[off]->wgeti (addr); + memwatch_func (addr, 4, 2, &v); + return v; } static void REGPARAM2 debug_lput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (memwatch_func (addr, 2, 4, &v)) - debug_mem_banks[off]->lput (addr, v); + int off = debug_mem_off (addr); + if (memwatch_func (addr, 2, 4, &v)) + debug_mem_banks[off]->lput (addr, v); } static void REGPARAM2 debug_wput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (memwatch_func (addr, 2, 2, &v)) - debug_mem_banks[off]->wput (addr, v); + int off = debug_mem_off (addr); + if (memwatch_func (addr, 2, 2, &v)) + debug_mem_banks[off]->wput (addr, v); } static void REGPARAM2 debug_bput (uaecptr addr, uae_u32 v) { - int off = debug_mem_off (addr); - if (memwatch_func (addr, 2, 1, &v)) - debug_mem_banks[off]->bput (addr, v); + int off = debug_mem_off (addr); + if (memwatch_func (addr, 2, 1, &v)) + debug_mem_banks[off]->bput (addr, v); } static int REGPARAM2 debug_check (uaecptr addr, uae_u32 size) { - return debug_mem_banks[munge24 (addr) >> 16]->check (addr, size); + return debug_mem_banks[munge24 (addr) >> 16]->check (addr, size); } static uae_u8 *REGPARAM2 debug_xlate (uaecptr addr) { - return debug_mem_banks[munge24 (addr) >> 16]->xlateaddr (addr); + return debug_mem_banks[munge24 (addr) >> 16]->xlateaddr (addr); } void debug_putlpeek(uaecptr addr, uae_u32 v) { - if (!memwatch_enabled) - return; - memwatch_func (addr, 2, 4, &v); + if (!memwatch_enabled) + return; + memwatch_func (addr, 2, 4, &v); } void debug_wputpeek(uaecptr addr, uae_u32 v) { - if (!memwatch_enabled) - return; - memwatch_func (addr, 2, 2, &v); + if (!memwatch_enabled) + return; + memwatch_func (addr, 2, 2, &v); } void debug_bputpeek(uaecptr addr, uae_u32 v) { - if (!memwatch_enabled) - return; - memwatch_func (addr, 2, 1, &v); + if (!memwatch_enabled) + return; + memwatch_func (addr, 2, 1, &v); } void debug_bgetpeek (uaecptr addr, uae_u32 v) { - uae_u32 vv = v; - if (!memwatch_enabled) - return; - memwatch_func (addr, 1, 1, &vv); + uae_u32 vv = v; + if (!memwatch_enabled) + return; + memwatch_func (addr, 1, 1, &vv); } void debug_wgetpeek (uaecptr addr, uae_u32 v) { - uae_u32 vv = v; - if (!memwatch_enabled) - return; - memwatch_func (addr, 1, 2, &vv); + uae_u32 vv = v; + if (!memwatch_enabled) + return; + memwatch_func (addr, 1, 2, &vv); } void debug_lgetpeek (uaecptr addr, uae_u32 v) { - uae_u32 vv = v; - if (!memwatch_enabled) - return; - memwatch_func (addr, 1, 4, &vv); + uae_u32 vv = v; + if (!memwatch_enabled) + return; + memwatch_func (addr, 1, 4, &vv); } struct membank_store { - addrbank *addr; - addrbank store; + addrbank *addr; + addrbank store; }; static struct membank_store *membank_stores; static int deinitialize_memwatch (void) { - int i, oldmode; + int i, oldmode; - if (!memwatch_enabled && !mmu_enabled) - return -1; - for (i = 0; membank_stores[i].addr; i++) { - memcpy (membank_stores[i].addr, &membank_stores[i].store, sizeof (addrbank)); - } - oldmode = mmu_enabled ? 1 : 0; - xfree (debug_mem_banks); - debug_mem_banks = NULL; - xfree (debug_mem_area); - debug_mem_area = NULL; - xfree (membank_stores); - membank_stores = NULL; - memwatch_enabled = 0; - mmu_enabled = 0; - xfree (illgdebug); - illgdebug = 0; - return oldmode; + if (!memwatch_enabled && !mmu_enabled) + return -1; + for (i = 0; membank_stores[i].addr; i++) { + memcpy (membank_stores[i].addr, &membank_stores[i].store, sizeof (addrbank)); + } + oldmode = mmu_enabled ? 1 : 0; + xfree (debug_mem_banks); + debug_mem_banks = NULL; + xfree (debug_mem_area); + debug_mem_area = NULL; + xfree (membank_stores); + membank_stores = NULL; + memwatch_enabled = 0; + mmu_enabled = 0; + xfree (illgdebug); + illgdebug = 0; + return oldmode; } static void initialize_memwatch (int mode) { - int i, j, as; - addrbank *a1, *a2, *oa; - - deinitialize_memwatch (); - as = currprefs.address_space_24 ? 256 : 65536; - debug_mem_banks = xmalloc (sizeof (addrbank*) * as); - debug_mem_area = xmalloc (sizeof (addrbank) * as); - membank_stores = xcalloc (sizeof (struct membank_store), 32); - oa = NULL; - for (i = 0; i < as; i++) { - a1 = debug_mem_banks[i] = debug_mem_area + i; - a2 = mem_banks[i]; - if (a2 != oa) { - for (j = 0; membank_stores[j].addr; j++) { - if (membank_stores[j].addr == a2) - break; - } - if (membank_stores[j].addr == NULL) { - membank_stores[j].addr = a2; - memcpy (&membank_stores[j].store, a2, sizeof (addrbank)); - } - } - memcpy (a1, a2, sizeof (addrbank)); - } - for (i = 0; i < as; i++) { - a2 = mem_banks[i]; - a2->bget = mode ? mmu_bget : debug_bget; - a2->wget = mode ? mmu_wget : debug_wget; - a2->lget = mode ? mmu_lget : debug_lget; - a2->bput = mode ? mmu_bput : debug_bput; - a2->wput = mode ? mmu_wput : debug_wput; - a2->lput = mode ? mmu_lput : debug_lput; - a2->check = debug_check; - a2->xlateaddr = debug_xlate; - a2->wgeti = mode ? mmu_wgeti : debug_wgeti; - a2->lgeti = mode ? mmu_lgeti : debug_lgeti; - } - if (mode) - mmu_enabled = 1; - else - memwatch_enabled = 1; + int i, j, as; + addrbank *a1, *a2, *oa; + + deinitialize_memwatch (); + as = currprefs.address_space_24 ? 256 : 65536; + debug_mem_banks = xmalloc (sizeof (addrbank*) * as); + debug_mem_area = xmalloc (sizeof (addrbank) * as); + membank_stores = xcalloc (sizeof (struct membank_store), 32); + oa = NULL; + for (i = 0; i < as; i++) { + a1 = debug_mem_banks[i] = debug_mem_area + i; + a2 = mem_banks[i]; + if (a2 != oa) { + for (j = 0; membank_stores[j].addr; j++) { + if (membank_stores[j].addr == a2) + break; + } + if (membank_stores[j].addr == NULL) { + membank_stores[j].addr = a2; + memcpy (&membank_stores[j].store, a2, sizeof (addrbank)); + } + } + memcpy (a1, a2, sizeof (addrbank)); + } + for (i = 0; i < as; i++) { + a2 = mem_banks[i]; + a2->bget = mode ? mmu_bget : debug_bget; + a2->wget = mode ? mmu_wget : debug_wget; + a2->lget = mode ? mmu_lget : debug_lget; + a2->bput = mode ? mmu_bput : debug_bput; + a2->wput = mode ? mmu_wput : debug_wput; + a2->lput = mode ? mmu_lput : debug_lput; + a2->check = debug_check; + a2->xlateaddr = debug_xlate; + a2->wgeti = mode ? mmu_wgeti : debug_wgeti; + a2->lgeti = mode ? mmu_lgeti : debug_lgeti; + } + if (mode) + mmu_enabled = 1; + else + memwatch_enabled = 1; } int debug_bankchange (int mode) { - if (mode == -1) { - int v = deinitialize_memwatch (); - if (v < 0) - return -2; - return v; - } - if (mode >= 0) - initialize_memwatch (mode); - return -1; + if (mode == -1) { + int v = deinitialize_memwatch (); + if (v < 0) + return -2; + return v; + } + if (mode >= 0) + initialize_memwatch (mode); + return -1; } void memwatch_dump2 (TCHAR *buf, int bufsize, int num) { - int i; - struct memwatch_node *mwn; - - if (buf) - memset (buf, 0, bufsize); - for (i = 0; i < MEMWATCH_TOTAL; i++) { - if ((num >= 0 && num == i) || (num < 0)) { - mwn = &mwnodes[i]; - if (mwn->size == 0) - continue; - buf = buf_out (buf, &bufsize, L"%d: %08X - %08X (%d) %c%c%c", - i, mwn->addr, mwn->addr + (mwn->size - 1), mwn->size, - (mwn->rwi & 1) ? 'R' : ' ', (mwn->rwi & 2) ? 'W' : ' ', (mwn->rwi & 4) ? 'I' : ' '); - if (mwn->frozen) - buf = buf_out (buf, &bufsize, L"F"); - if (mwn->val_enabled) - buf = buf_out (buf, &bufsize, L" =%X", mwn->val); - if (mwn->modval_written) - buf = buf_out (buf, &bufsize, L" =M"); - if (mwn->mustchange) - buf = buf_out (buf, &bufsize, L" C"); - buf = buf_out (buf, &bufsize, L"\n"); - } - } + int i; + struct memwatch_node *mwn; + + if (buf) + memset (buf, 0, bufsize); + for (i = 0; i < MEMWATCH_TOTAL; i++) { + if ((num >= 0 && num == i) || (num < 0)) { + mwn = &mwnodes[i]; + if (mwn->size == 0) + continue; + buf = buf_out (buf, &bufsize, L"%d: %08X - %08X (%d) %c%c%c", + i, mwn->addr, mwn->addr + (mwn->size - 1), mwn->size, + (mwn->rwi & 1) ? 'R' : ' ', (mwn->rwi & 2) ? 'W' : ' ', (mwn->rwi & 4) ? 'I' : ' '); + if (mwn->frozen) + buf = buf_out (buf, &bufsize, L"F"); + if (mwn->val_enabled) + buf = buf_out (buf, &bufsize, L" =%X", mwn->val); + if (mwn->modval_written) + buf = buf_out (buf, &bufsize, L" =M"); + if (mwn->mustchange) + buf = buf_out (buf, &bufsize, L" C"); + buf = buf_out (buf, &bufsize, L"\n"); + } + } } static void memwatch_dump (int num) { - TCHAR *buf; - int multiplier = num < 0 ? MEMWATCH_TOTAL : 1; + TCHAR *buf; + int multiplier = num < 0 ? MEMWATCH_TOTAL : 1; - buf = malloc (50 * multiplier * sizeof (TCHAR)); - if (!buf) - return; - memwatch_dump2 (buf, 50 * multiplier, num); - f_out (stdout, L"%s", buf); - xfree (buf); + buf = malloc (50 * multiplier * sizeof (TCHAR)); + if (!buf) + return; + memwatch_dump2 (buf, 50 * multiplier, num); + f_out (stdout, L"%s", buf); + xfree (buf); } static void memwatch (TCHAR **c) { - int num; - struct memwatch_node *mwn; - TCHAR nc; + int num; + struct memwatch_node *mwn; + TCHAR nc; - if (!memwatch_enabled) { - initialize_memwatch (0); - console_out (L"Memwatch breakpoints enabled\n"); - } + if (!memwatch_enabled) { + initialize_memwatch (0); + console_out (L"Memwatch breakpoints enabled\n"); + } - ignore_ws (c); - if (!more_params (c)) { - memwatch_dump (-1); - return; - } - nc = next_char (c); - if (nc == '-') { - deinitialize_memwatch (); - console_out (L"Memwatch breakpoints disabled\n"); - return; - } - if (nc == 'd') { - if (illgdebug) { - ignore_ws (c); - if (more_params (c)) { - uae_u32 addr = readhex (c); - uae_u32 len = 1; - if (more_params (c)) - len = readhex (c); - console_out_f (L"Cleared logging addresses %08X - %08X\n", addr, addr + len); - while (len > 0) { - addr &= 0xffffff; - illgdebug[addr] = 7; - addr++; - len--; + ignore_ws (c); + if (!more_params (c)) { + memwatch_dump (-1); + return; + } + nc = next_char (c); + if (nc == '-') { + deinitialize_memwatch (); + console_out (L"Memwatch breakpoints disabled\n"); + return; + } + if (nc == 'd') { + if (illgdebug) { + ignore_ws (c); + if (more_params (c)) { + uae_u32 addr = readhex (c); + uae_u32 len = 1; + if (more_params (c)) + len = readhex (c); + console_out_f (L"Cleared logging addresses %08X - %08X\n", addr, addr + len); + while (len > 0) { + addr &= 0xffffff; + illgdebug[addr] = 7; + addr++; + len--; + } + } else { + illg_free(); + console_out (L"Illegal memory access logging disabled\n"); + } + } else { + illg_init (); + ignore_ws (c); + illgdebug_break = 0; + if (more_params (c)) + illgdebug_break = 1; + console_out_f (L"Illegal memory access logging enabled. Break=%d\n", illgdebug_break); } - } else { - illg_free(); - console_out (L"Illegal memory access logging disabled\n"); - } - } else { - illg_init (); - ignore_ws (c); - illgdebug_break = 0; - if (more_params (c)) - illgdebug_break = 1; - console_out_f (L"Illegal memory access logging enabled. Break=%d\n", illgdebug_break); + return; } - return; - } - num = nc - '0'; - if (num < 0 || num >= MEMWATCH_TOTAL) - return; - mwn = &mwnodes[num]; - mwn->size = 0; - ignore_ws (c); - if (!more_params (c)) { - console_out_f (L"Memwatch %d removed\n", num); - return; - } - mwn->addr = readhex (c); - mwn->size = 1; - mwn->rwi = 7; - mwn->val_enabled = 0; - mwn->valmask = 0xffffffff; - mwn->frozen = 0; - mwn->modval_written = 0; - ignore_ws (c); - if (more_params (c)) { - mwn->size = readhex (c); + num = nc - '0'; + if (num < 0 || num >= MEMWATCH_TOTAL) + return; + mwn = &mwnodes[num]; + mwn->size = 0; + ignore_ws (c); + if (!more_params (c)) { + console_out_f (L"Memwatch %d removed\n", num); + return; + } + mwn->addr = readhex (c); + mwn->size = 1; + mwn->rwi = 7; + mwn->val_enabled = 0; + mwn->valmask = 0xffffffff; + mwn->frozen = 0; + mwn->modval_written = 0; ignore_ws (c); if (more_params (c)) { - for (;;) { - TCHAR ncc = peek_next_char(c); - TCHAR nc = _totupper (next_char (c)); - if (mwn->rwi == 7) - mwn->rwi = 0; - if (nc == 'F') - mwn->frozen = 1; - if (nc == 'W') - mwn->rwi |= 2; - if (nc == 'I') - mwn->rwi |= 4; - if (nc == 'R') - mwn->rwi |= 1; - if (ncc == ' ') - break; - if (!more_params(c)) - break; - } - ignore_ws (c); - if (more_params (c)) { - if (_totupper (**c) == 'M') { - mwn->modval_written = 1; - } else if (_totupper (**c) == 'C') { - mwn->mustchange = 1; - } else { - mwn->val = readhex (c); - mwn->val_enabled = 1; + mwn->size = readhex (c); + ignore_ws (c); + if (more_params (c)) { + for (;;) { + TCHAR ncc = peek_next_char(c); + TCHAR nc = _totupper (next_char (c)); + if (mwn->rwi == 7) + mwn->rwi = 0; + if (nc == 'F') + mwn->frozen = 1; + if (nc == 'W') + mwn->rwi |= 2; + if (nc == 'I') + mwn->rwi |= 4; + if (nc == 'R') + mwn->rwi |= 1; + if (ncc == ' ') + break; + if (!more_params(c)) + break; + } + ignore_ws (c); + if (more_params (c)) { + if (_totupper (**c) == 'M') { + mwn->modval_written = 1; + } else if (_totupper (**c) == 'C') { + mwn->mustchange = 1; + } else { + mwn->val = readhex (c); + mwn->val_enabled = 1; + } + } } - } } - } - if (mwn->frozen && mwn->rwi == 0) - mwn->rwi = 3; - memwatch_dump (num); + if (mwn->frozen && mwn->rwi == 0) + mwn->rwi = 3; + memwatch_dump (num); } static void writeintomem (TCHAR **c) { - uae_u32 addr = 0; - uae_u32 val = 0; - TCHAR cc; - int len = 1; - - ignore_ws(c); - addr = readhex (c); - ignore_ws(c); - val = readhex (c); - if (val > 0xffff) - len = 4; - else if (val > 0xff) - len = 2; - else - len = 1; - if (more_params (c)) { - ignore_ws (c); - len = readint (c); - } - if (len == 4) { - put_long (addr, val); - cc = 'L'; - } else if (len == 2) { - put_word (addr, val); - cc = 'W'; - } else { - put_byte (addr, val); - cc = 'B'; - } - console_out_f (L"Wrote %X (%u) at %08X.%c\n", val, val, addr, cc); + uae_u32 addr = 0; + uae_u32 val = 0; + TCHAR cc; + int len = 1; + + ignore_ws(c); + addr = readhex (c); + ignore_ws(c); + val = readhex (c); + if (val > 0xffff) + len = 4; + else if (val > 0xff) + len = 2; + else + len = 1; + if (more_params (c)) { + ignore_ws (c); + len = readint (c); + } + if (len == 4) { + put_long (addr, val); + cc = 'L'; + } else if (len == 2) { + put_word (addr, val); + cc = 'W'; + } else { + put_byte (addr, val); + cc = 'B'; + } + console_out_f (L"Wrote %X (%u) at %08X.%c\n", val, val, addr, cc); } static uae_u8 *dump_xlate (uae_u32 addr) { - if (!mem_banks[addr >> 16]->check (addr, 1)) - return NULL; - return mem_banks[addr >> 16]->xlateaddr (addr); + if (!mem_banks[addr >> 16]->check (addr, 1)) + return NULL; + return mem_banks[addr >> 16]->xlateaddr (addr); } static void memory_map_dump_2 (int log) { - int i, j, max, im; - addrbank *a1 = mem_banks[0]; - TCHAR txt[256]; - - im = currprefs.illegal_mem; - currprefs.illegal_mem = 0; - max = currprefs.address_space_24 ? 256 : 65536; - j = 0; - for (i = 0; i < max + 1; i++) { - addrbank *a2 = NULL; - if (i < max) - a2 = mem_banks[i]; - if (a1 != a2) { - int k, mirrored, size, size_out; - TCHAR size_ext; - uae_u8 *caddr; - TCHAR *name; - TCHAR tmp[MAX_DPATH]; - - name = a1->name; - if (name == NULL) - name = L""; - - k = j; - caddr = dump_xlate (k << 16); - mirrored = caddr ? 1 : 0; - k++; - while (k < i && caddr) { - if (dump_xlate (k << 16) == caddr) - mirrored++; - k++; - } - size = (i - j) << (16 - 10); - size_out = size; - size_ext = 'K'; - if (j >= 256) { - size_out /= 1024; - size_ext = 'M'; - } - _stprintf (txt, L"%08X %7d%c/%d = %7d%c %s", j << 16, size_out, size_ext, - mirrored, mirrored ? size_out / mirrored : size_out, size_ext, name); - - tmp[0] = 0; - if (a1->flags == ABFLAG_ROM && mirrored) { - TCHAR *p = txt + _tcslen (txt); - uae_u32 crc = get_crc32 (a1->xlateaddr(j << 16), (size * 1024) / mirrored); - struct romdata *rd = getromdatabycrc (crc); - _stprintf (p, L" (%08X)", crc); - if (rd) { - tmp[0] = '='; - getromname (rd, tmp + 1); - _tcscat (tmp, L"\n"); + int i, j, max, im; + addrbank *a1 = mem_banks[0]; + TCHAR txt[256]; + + im = currprefs.illegal_mem; + currprefs.illegal_mem = 0; + max = currprefs.address_space_24 ? 256 : 65536; + j = 0; + for (i = 0; i < max + 1; i++) { + addrbank *a2 = NULL; + if (i < max) + a2 = mem_banks[i]; + if (a1 != a2) { + int k, mirrored, size, size_out; + TCHAR size_ext; + uae_u8 *caddr; + TCHAR *name; + TCHAR tmp[MAX_DPATH]; + + name = a1->name; + if (name == NULL) + name = L""; + + k = j; + caddr = dump_xlate (k << 16); + mirrored = caddr ? 1 : 0; + k++; + while (k < i && caddr) { + if (dump_xlate (k << 16) == caddr) + mirrored++; + k++; + } + size = (i - j) << (16 - 10); + size_out = size; + size_ext = 'K'; + if (j >= 256) { + size_out /= 1024; + size_ext = 'M'; + } + _stprintf (txt, L"%08X %7d%c/%d = %7d%c %s", j << 16, size_out, size_ext, + mirrored, mirrored ? size_out / mirrored : size_out, size_ext, name); + + tmp[0] = 0; + if (a1->flags == ABFLAG_ROM && mirrored) { + TCHAR *p = txt + _tcslen (txt); + uae_u32 crc = get_crc32 (a1->xlateaddr(j << 16), (size * 1024) / mirrored); + struct romdata *rd = getromdatabycrc (crc); + _stprintf (p, L" (%08X)", crc); + if (rd) { + tmp[0] = '='; + getromname (rd, tmp + 1); + _tcscat (tmp, L"\n"); + } + } + _tcscat (txt, L"\n"); + if (log) + write_log (txt); + else + console_out (txt); + if (tmp[0]) { + if (log) + write_log (tmp); + else + console_out (tmp); + } + j = i; + a1 = a2; } - } - _tcscat (txt, L"\n"); - if (log) - write_log (txt); - else - console_out (txt); - if (tmp[0]) { - if (log) - write_log (tmp); - else - console_out (tmp); - } - j = i; - a1 = a2; } - } - currprefs.illegal_mem = im; + currprefs.illegal_mem = im; } void memory_map_dump (void) { - memory_map_dump_2 (1); + memory_map_dump_2 (1); } STATIC_INLINE uaecptr BPTR2APTR (uaecptr addr) { - return addr << 2; + return addr << 2; } static TCHAR *BSTR2CSTR (uae_u8 *bstr) { - WCHAR *s; - char *cstr = xmalloc (bstr[0] + 1); - if (cstr) { - memcpy (cstr, bstr + 1, bstr[0]); - cstr[bstr[0]] = 0; - } - s = au (cstr); - xfree (cstr); - return s; + WCHAR *s; + char *cstr = xmalloc (bstr[0] + 1); + if (cstr) { + memcpy (cstr, bstr + 1, bstr[0]); + cstr[bstr[0]] = 0; + } + s = au (cstr); + xfree (cstr); + return s; } static void print_task_info (uaecptr node) { - TCHAR *s; - int process = get_byte (node + 8) == 13 ? 1 : 0; - - console_out_f (L"%08X: ", node); - s = au (get_real_address (get_long (node + 10))); - console_out_f (process ? L" PROCESS '%s'" : L" TASK '%s'\n", s); - xfree (s); - if (process) { - uaecptr cli = BPTR2APTR (get_long (node + 172)); - int tasknum = get_long (node + 140); - if (cli && tasknum) { - uae_u8 *command_bstr = get_real_address (BPTR2APTR (get_long (cli + 16))); - TCHAR *command = BSTR2CSTR (command_bstr); - console_out_f (L" [%d, '%s']\n", tasknum, command); - xfree (command); - } else { - console_out (L"\n"); + TCHAR *s; + int process = get_byte (node + 8) == 13 ? 1 : 0; + + console_out_f (L"%08X: ", node); + s = au (get_real_address (get_long (node + 10))); + console_out_f (process ? L" PROCESS '%s'" : L" TASK '%s'\n", s); + xfree (s); + if (process) { + uaecptr cli = BPTR2APTR (get_long (node + 172)); + int tasknum = get_long (node + 140); + if (cli && tasknum) { + uae_u8 *command_bstr = get_real_address (BPTR2APTR (get_long (cli + 16))); + TCHAR *command = BSTR2CSTR (command_bstr); + console_out_f (L" [%d, '%s']\n", tasknum, command); + xfree (command); + } else { + console_out (L"\n"); + } } - } } static void show_exec_tasks (void) { - uaecptr execbase = get_long (4); - uaecptr taskready = get_long (execbase + 406); - uaecptr taskwait = get_long (execbase + 420); - uaecptr node, end; - console_out_f (L"Execbase at 0x%08X\n", execbase); - console_out (L"Current:\n"); - node = get_long (execbase + 276); - print_task_info (node); - console_out_f (L"Ready:\n"); - node = get_long (taskready); - end = get_long (taskready + 4); - while (node) { - print_task_info (node); - node = get_long (node); - } - console_out (L"Waiting:\n"); - node = get_long (taskwait); - end = get_long (taskwait + 4); - while (node) { + uaecptr execbase = get_long (4); + uaecptr taskready = get_long (execbase + 406); + uaecptr taskwait = get_long (execbase + 420); + uaecptr node, end; + console_out_f (L"Execbase at 0x%08X\n", execbase); + console_out (L"Current:\n"); + node = get_long (execbase + 276); print_task_info (node); - node = get_long (node); - } + console_out_f (L"Ready:\n"); + node = get_long (taskready); + end = get_long (taskready + 4); + while (node) { + print_task_info (node); + node = get_long (node); + } + console_out (L"Waiting:\n"); + node = get_long (taskwait); + end = get_long (taskwait + 4); + while (node) { + print_task_info (node); + node = get_long (node); + } } static void show_exec_lists (TCHAR t) { - uaecptr execbase = get_long (4); - uaecptr list = 0, node; + uaecptr execbase = get_long (4); + uaecptr list = 0, node; - switch (_totupper (t)) - { + switch (_totupper (t)) + { case 'R': - list = execbase + 336; - break; + list = execbase + 336; + break; case 'D': - list = execbase + 350; - break; + list = execbase + 350; + break; case 'L': - list = execbase + 378; - break; - } - if (list == 0) - return; - node = get_long (list); - while (get_long (node)) { - TCHAR *name = au (get_real_address (get_long (node + 10))); - console_out_f (L"%08x %s\n", node, name); - xfree (name); - node = get_long (node); - } + list = execbase + 378; + break; + } + if (list == 0) + return; + node = get_long (list); + while (get_long (node)) { + TCHAR *name = au (get_real_address (get_long (node + 10))); + console_out_f (L"%08x %s\n", node, name); + xfree (name); + node = get_long (node); + } } #if 0 @@ -2324,1100 +2326,1100 @@ static uaecptr nextpc; int instruction_breakpoint (TCHAR **c) { - struct breakpoint_node *bpn; - int i; - - if (more_params (c)) { - TCHAR nc = _totupper ((*c)[0]); - if (nc == 'S') { - next_char (c); - sr_bpvalue = sr_bpmask = 0; - if (more_params (c)) { - sr_bpmask = 0xffff; - sr_bpvalue = readhex (c); - if (more_params (c)) - sr_bpmask = readhex (c); - } - console_out_f (L"SR breakpoint, value=%04X, mask=%04X\n", sr_bpvalue, sr_bpmask); - return 0; - } else if (nc == 'I') { - next_char (c); - if (more_params (c)) - skipins = readhex (c); - else - skipins = 0x10000; - do_skip = 1; - skipaddr_doskip = 1; - return 1; - } else if (nc == 'D' && (*c)[1] == 0) { - for (i = 0; i < BREAKPOINT_TOTAL; i++) - bpnodes[i].enabled = 0; - console_out (L"All breakpoints removed\n"); - return 0; - } else if (nc == 'L') { - int got = 0; - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - bpn = &bpnodes[i]; - if (!bpn->enabled) - continue; - console_out_f (L"%8X ", bpn->addr); - got = 1; - } - if (!got) - console_out (L"No breakpoints\n"); - else - console_out (L"\n"); - return 0; - } - skipaddr_doskip = 1; - skipaddr_start = readhex (c); + struct breakpoint_node *bpn; + int i; + if (more_params (c)) { - skipaddr_end = readhex (c); - } else { - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - bpn = &bpnodes[i]; - if (bpn->enabled && bpn->addr == skipaddr_start) { - bpn->enabled = 0; - console_out (L"Breakpoint removed\n"); - skipaddr_start = 0xffffffff; - skipaddr_doskip = 0; - return 0; + TCHAR nc = _totupper ((*c)[0]); + if (nc == 'S') { + next_char (c); + sr_bpvalue = sr_bpmask = 0; + if (more_params (c)) { + sr_bpmask = 0xffff; + sr_bpvalue = readhex (c); + if (more_params (c)) + sr_bpmask = readhex (c); + } + console_out_f (L"SR breakpoint, value=%04X, mask=%04X\n", sr_bpvalue, sr_bpmask); + return 0; + } else if (nc == 'I') { + next_char (c); + if (more_params (c)) + skipins = readhex (c); + else + skipins = 0x10000; + do_skip = 1; + skipaddr_doskip = 1; + return 1; + } else if (nc == 'D' && (*c)[1] == 0) { + for (i = 0; i < BREAKPOINT_TOTAL; i++) + bpnodes[i].enabled = 0; + console_out (L"All breakpoints removed\n"); + return 0; + } else if (nc == 'L') { + int got = 0; + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + bpn = &bpnodes[i]; + if (!bpn->enabled) + continue; + console_out_f (L"%8X ", bpn->addr); + got = 1; + } + if (!got) + console_out (L"No breakpoints\n"); + else + console_out (L"\n"); + return 0; + } + skipaddr_doskip = 1; + skipaddr_start = readhex (c); + if (more_params (c)) { + skipaddr_end = readhex (c); + } else { + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + bpn = &bpnodes[i]; + if (bpn->enabled && bpn->addr == skipaddr_start) { + bpn->enabled = 0; + console_out (L"Breakpoint removed\n"); + skipaddr_start = 0xffffffff; + skipaddr_doskip = 0; + return 0; + } + } + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + bpn = &bpnodes[i]; + if (bpn->enabled) + continue; + bpn->addr = skipaddr_start; + bpn->enabled = 1; + console_out (L"Breakpoint added\n"); + skipaddr_start = 0xffffffff; + skipaddr_doskip = 0; + break; + } + return 0; } - } - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - bpn = &bpnodes[i]; - if (bpn->enabled) - continue; - bpn->addr = skipaddr_start; - bpn->enabled = 1; - console_out (L"Breakpoint added\n"); - skipaddr_start = 0xffffffff; - skipaddr_doskip = 0; - break; - } - return 0; } - } #if 0 - if (skipaddr_start == 0xC0DEDBAD) { - trace_same_insn_count = 0; - logfile = fopen ("uae.trace", "w"); - memcpy (trace_insn_copy, regs.pc_p, 10); - memcpy (&trace_prev_regs, ®s, sizeof regs); - } + if (skipaddr_start == 0xC0DEDBAD) { + trace_same_insn_count = 0; + logfile = fopen ("uae.trace", "w"); + memcpy (trace_insn_copy, regs.pc_p, 10); + memcpy (&trace_prev_regs, ®s, sizeof regs); + } #endif - do_skip = 1; - skipaddr_doskip = -1; - return 1; + do_skip = 1; + skipaddr_doskip = -1; + return 1; } static int process_breakpoint(TCHAR **c) { - processptr = 0; - xfree (processname); - processname = NULL; - if (!more_params (c)) - return 0; - if (**c == '\"') { - TCHAR pn[200]; - next_string (c, pn, 200, 0); - processname = ua (pn); - } else { - processptr = readhex (c); - } - do_skip = 1; - skipaddr_doskip = 1; - skipaddr_start = 0; - return 1; + processptr = 0; + xfree (processname); + processname = NULL; + if (!more_params (c)) + return 0; + if (**c == '\"') { + TCHAR pn[200]; + next_string (c, pn, 200, 0); + processname = ua (pn); + } else { + processptr = readhex (c); + } + do_skip = 1; + skipaddr_doskip = 1; + skipaddr_start = 0; + return 1; } static void savemem (TCHAR **cc) { - uae_u8 b; - uae_u32 src, src2, len, len2; - TCHAR *name; - FILE *fp; + uae_u8 b; + uae_u32 src, src2, len, len2; + TCHAR *name; + FILE *fp; + + if (!more_params (cc)) + goto S_argh; - if (!more_params (cc)) - goto S_argh; + name = *cc; + while (**cc != '\0' && !isspace (**cc)) + (*cc)++; + if (!isspace (**cc)) + goto S_argh; - name = *cc; - while (**cc != '\0' && !isspace (**cc)) + **cc = '\0'; (*cc)++; - if (!isspace (**cc)) - goto S_argh; - - **cc = '\0'; - (*cc)++; - if (!more_params (cc)) - goto S_argh; - src2 = src = readhex (cc); - if (!more_params (cc)) - goto S_argh; - len2 = len = readhex (cc); - fp = _tfopen (name, L"wb"); - if (fp == NULL) { - console_out_f (L"Couldn't open file '%s'\n", name); + if (!more_params (cc)) + goto S_argh; + src2 = src = readhex (cc); + if (!more_params (cc)) + goto S_argh; + len2 = len = readhex (cc); + fp = _tfopen (name, L"wb"); + if (fp == NULL) { + console_out_f (L"Couldn't open file '%s'\n", name); + return; + } + while (len > 0) { + b = get_byte (src); + src++; + len--; + if (fwrite (&b, 1, 1, fp) != 1) { + console_out (L"Error writing file\n"); + break; + } + } + fclose (fp); + if (len == 0) + console_out_f (L"Wrote %08X - %08X (%d bytes) to '%s'\n", + src2, src2 + len2, len2, name); return; - } - while (len > 0) { - b = get_byte (src); - src++; - len--; - if (fwrite (&b, 1, 1, fp) != 1) { - console_out (L"Error writing file\n"); - break; - } - } - fclose (fp); - if (len == 0) - console_out_f (L"Wrote %08X - %08X (%d bytes) to '%s'\n", - src2, src2 + len2, len2, name); - return; S_argh: - console_out (L"S-command needs more arguments!\n"); + console_out (L"S-command needs more arguments!\n"); } static void searchmem (TCHAR **cc) { - int i, sslen, got, val, stringmode; - uae_u8 ss[256]; - uae_u32 addr, endaddr; - TCHAR nc; - - got = 0; - sslen = 0; - stringmode = 0; - ignore_ws (cc); - if (**cc == '"') { - stringmode = 1; - (*cc)++; - while (**cc != '"' && **cc != 0) { - ss[sslen++] = tolower (**cc); - (*cc)++; + int i, sslen, got, val, stringmode; + uae_u8 ss[256]; + uae_u32 addr, endaddr; + TCHAR nc; + + got = 0; + sslen = 0; + stringmode = 0; + ignore_ws (cc); + if (**cc == '"') { + stringmode = 1; + (*cc)++; + while (**cc != '"' && **cc != 0) { + ss[sslen++] = tolower (**cc); + (*cc)++; + } + if (**cc != 0) + (*cc)++; + } else { + for (;;) { + if (**cc == 32 || **cc == 0) + break; + nc = _totupper (next_char (cc)); + if (isspace (nc)) + break; + if (isdigit(nc)) + val = nc - '0'; + else + val = nc - 'A' + 10; + if (val < 0 || val > 15) + return; + val *= 16; + if (**cc == 32 || **cc == 0) + break; + nc = _totupper (next_char (cc)); + if (isspace (nc)) + break; + if (isdigit(nc)) + val += nc - '0'; + else + val += nc - 'A' + 10; + if (val < 0 || val > 255) + return; + ss[sslen++] = (uae_u8)val; + } } - if (**cc != 0) - (*cc)++; - } else { - for (;;) { - if (**cc == 32 || **cc == 0) - break; - nc = _totupper (next_char (cc)); - if (isspace (nc)) - break; - if (isdigit(nc)) - val = nc - '0'; - else - val = nc - 'A' + 10; - if (val < 0 || val > 15) + if (sslen == 0) return; - val *= 16; - if (**cc == 32 || **cc == 0) - break; - nc = _totupper (next_char (cc)); - if (isspace (nc)) - break; - if (isdigit(nc)) - val += nc - '0'; - else - val += nc - 'A' + 10; - if (val < 0 || val > 255) - return; - ss[sslen++] = (uae_u8)val; - } - } - if (sslen == 0) - return; - ignore_ws (cc); - addr = 0; - endaddr = lastaddr (); - if (more_params (cc)) { - addr = readhex (cc); - if (more_params (cc)) - endaddr = readhex (cc); - } - console_out_f (L"Searching from %08X to %08X..\n", addr, endaddr); - while ((addr = nextaddr (addr, NULL)) != 0xffffffff) { - if (addr == endaddr) - break; - for (i = 0; i < sslen; i++) { - uae_u8 b = get_byte (addr + i); - if (stringmode) { - if (tolower (b) != ss[i]) - break; - } else { - if (b != ss[i]) - break; - } - } - if (i == sslen) { - got++; - console_out_f (L" %08X", addr); - if (got > 100) { - console_out (L"\nMore than 100 results, aborting.."); - break; - } + ignore_ws (cc); + addr = 0; + endaddr = lastaddr (); + if (more_params (cc)) { + addr = readhex (cc); + if (more_params (cc)) + endaddr = readhex (cc); + } + console_out_f (L"Searching from %08X to %08X..\n", addr, endaddr); + while ((addr = nextaddr (addr, NULL)) != 0xffffffff) { + if (addr == endaddr) + break; + for (i = 0; i < sslen; i++) { + uae_u8 b = get_byte (addr + i); + if (stringmode) { + if (tolower (b) != ss[i]) + break; + } else { + if (b != ss[i]) + break; + } + } + if (i == sslen) { + got++; + console_out_f (L" %08X", addr); + if (got > 100) { + console_out (L"\nMore than 100 results, aborting.."); + break; + } + } } - } - if (!got) - console_out (L"nothing found"); - console_out (L"\n"); + if (!got) + console_out (L"nothing found"); + console_out (L"\n"); } static int staterecorder (TCHAR **cc) { - TCHAR nc; + TCHAR nc; - if (!more_params (cc)) { - if (savestate_dorewind (1)) { - debug_rewind = 1; - return 1; + if (!more_params (cc)) { + if (savestate_dorewind (1)) { + debug_rewind = 1; + return 1; + } + return 0; + } + nc = next_char (cc); + if (nc == 'l') { + savestate_listrewind (); + return 0; } return 0; - } - nc = next_char (cc); - if (nc == 'l') { - savestate_listrewind (); - return 0; - } - return 0; } static int debugtest_modes[DEBUGTEST_MAX]; static const TCHAR *debugtest_names[] = { - L"Blitter", L"Keyboard", L"Floppy" + L"Blitter", L"Keyboard", L"Floppy" }; void debugtest (enum debugtest_item di, const TCHAR *format, ...) { - va_list parms; - TCHAR buffer[1000]; + va_list parms; + TCHAR buffer[1000]; - if (!debugtest_modes[di]) - return; - va_start (parms, format); - _vsntprintf (buffer, 1000 - 1, format, parms); - va_end (parms); - write_log (L"%s PC=%08X: %s\n", debugtest_names[di], M68K_GETPC, buffer); - if (debugtest_modes[di] == 2) - activate_debugger (); + if (!debugtest_modes[di]) + return; + va_start (parms, format); + _vsntprintf (buffer, 1000 - 1, format, parms); + va_end (parms); + write_log (L"%s PC=%08X: %s\n", debugtest_names[di], M68K_GETPC, buffer); + if (debugtest_modes[di] == 2) + activate_debugger (); } static void debugtest_set (TCHAR **inptr) { - int i, val, val2; - ignore_ws (inptr); + int i, val, val2; + ignore_ws (inptr); - val2 = 1; - if (!more_params (inptr)) { - for (i = 0; i < DEBUGTEST_MAX; i++) - debugtest_modes[i] = 0; - console_out (L"All debugtests disabled\n"); - return; - } - val = readint (inptr); - if (more_params (inptr)) { - val2 = readint (inptr); - if (val2 > 0) - val2 = 2; - } - if (val < 0) { - for (i = 0; i < DEBUGTEST_MAX; i++) - debugtest_modes[i] = val2; - console_out (L"All debugtests enabled\n"); - return; - } - if (val >= 0 && val < DEBUGTEST_MAX) { - if (debugtest_modes[val]) - debugtest_modes[val] = 0; - else - debugtest_modes[val] = val2; - console_out_f (L"Debugtest '%s': %s. break = %s\n", - debugtest_names[val], debugtest_modes[val] ? L"on" :L"off", val2 == 2 ? L"on" : L"off"); - } + val2 = 1; + if (!more_params (inptr)) { + for (i = 0; i < DEBUGTEST_MAX; i++) + debugtest_modes[i] = 0; + console_out (L"All debugtests disabled\n"); + return; + } + val = readint (inptr); + if (more_params (inptr)) { + val2 = readint (inptr); + if (val2 > 0) + val2 = 2; + } + if (val < 0) { + for (i = 0; i < DEBUGTEST_MAX; i++) + debugtest_modes[i] = val2; + console_out (L"All debugtests enabled\n"); + return; + } + if (val >= 0 && val < DEBUGTEST_MAX) { + if (debugtest_modes[val]) + debugtest_modes[val] = 0; + else + debugtest_modes[val] = val2; + console_out_f (L"Debugtest '%s': %s. break = %s\n", + debugtest_names[val], debugtest_modes[val] ? L"on" :L"off", val2 == 2 ? L"on" : L"off"); + } } static void debug_sprite (TCHAR **inptr) { - uaecptr saddr, addr, addr2; - int xpos, xpos_ecs; - int ypos, ypos_ecs; - int ypose, ypose_ecs; - int attach; - uae_u64 w1, w2, ww1, ww2; - int size = 1, width; - int ecs, sh10; - int y, i; - TCHAR tmp[80]; - int max = 2; - - addr2 = 0; - ignore_ws (inptr); - addr = readhex (inptr); - ignore_ws (inptr); - if (more_params (inptr)) - size = readhex (inptr); - if (size != 1 && size != 2 && size != 4) { - addr2 = size; + uaecptr saddr, addr, addr2; + int xpos, xpos_ecs; + int ypos, ypos_ecs; + int ypose, ypose_ecs; + int attach; + uae_u64 w1, w2, ww1, ww2; + int size = 1, width; + int ecs, sh10; + int y, i; + TCHAR tmp[80]; + int max = 2; + + addr2 = 0; + ignore_ws (inptr); + addr = readhex (inptr); ignore_ws (inptr); if (more_params (inptr)) - size = readint (inptr); - if (size != 1 && size != 2 && size != 4) - size = 1; - } - for (;;) { - ecs = 0; - sh10 = 0; - saddr = addr; - width = size * 16; - w1 = get_word (addr); - w2 = get_word (addr + size * 2); - console_out_f (L" %06X ", addr); - for (i = 0; i < size * 2; i++) - console_out_f (L"%04X ", get_word (addr + i * 2)); - console_out_f (L"\n"); - - ypos = w1 >> 8; - xpos = w1 & 255; - ypose = w2 >> 8; - attach = (w2 & 0x80) ? 1 : 0; - if (w2 & 4) - ypos |= 256; - if (w2 & 2) - ypose |= 256; - ypos_ecs = ypos; - ypose_ecs = ypose; - if (w2 & 0x40) - ypos_ecs |= 512; - if (w2 & 0x20) - ypose_ecs |= 512; - xpos <<= 1; - if (w2 & 0x01) - xpos |= 1; - xpos_ecs = xpos << 2; - if (w2 & 0x10) - xpos_ecs |= 2; - if (w2 & 0x08) - xpos_ecs |= 1; - if (w2 & (0x40 | 0x20 | 0x10 | 0x08)) - ecs = 1; - if (w1 & 0x80) - sh10 = 1; - if (ypose < ypos) - ypose += 256; - - for (y = ypos; y < ypose; y++) { - int x; - addr += size * 4; - if (addr2) - addr2 += size * 4; - if (size == 1) { + size = readhex (inptr); + if (size != 1 && size != 2 && size != 4) { + addr2 = size; + ignore_ws (inptr); + if (more_params (inptr)) + size = readint (inptr); + if (size != 1 && size != 2 && size != 4) + size = 1; + } + for (;;) { + ecs = 0; + sh10 = 0; + saddr = addr; + width = size * 16; w1 = get_word (addr); - w2 = get_word (addr + 2); - if (addr2) { - ww1 = get_word (addr2); - ww2 = get_word (addr2 + 2); - } - } else if (size == 2) { - w1 = get_long (addr); - w2 = get_long (addr + 4); - if (addr2) { - ww1 = get_long (addr2); - ww2 = get_long (addr2 + 4); - } - } else if (size == 4) { - w1 = get_long (addr) << 16; - w2 = get_long (addr + 4) << 16; - w1 <<= 16; - w2 <<= 16; - w1 |= get_long (addr); - w2 |= get_long (addr2 + 4); - if (addr2) { - ww1 = get_long (addr2) << 16; - ww2 = get_long (addr2 + 4) << 16; - ww1 <<= 16; - ww2 <<= 16; - ww1 |= get_long (addr2); - ww2 |= get_long (addr2 + 4); - } - } - width = size * 16; - for (x = 0; x < width; x++) { - int v1 = (w1 >> (width - x)) & 1; - int v2 = (w2 >> (width - x)) & 1; - int v = v1 * 2 + v2; - if (addr2) { - int vv1 = (ww1 >> (width - x)) & 1; - int vv2 = (ww2 >> (width - x)) & 1; - int vv = vv1 * 2 + vv2; - v *= 4; - v += vv; - tmp[x] = v >= 10 ? 'A' + v - 10 : v + '0'; - } else { - tmp[x] = v + '0'; + w2 = get_word (addr + size * 2); + console_out_f (L" %06X ", addr); + for (i = 0; i < size * 2; i++) + console_out_f (L"%04X ", get_word (addr + i * 2)); + console_out_f (L"\n"); + + ypos = w1 >> 8; + xpos = w1 & 255; + ypose = w2 >> 8; + attach = (w2 & 0x80) ? 1 : 0; + if (w2 & 4) + ypos |= 256; + if (w2 & 2) + ypose |= 256; + ypos_ecs = ypos; + ypose_ecs = ypose; + if (w2 & 0x40) + ypos_ecs |= 512; + if (w2 & 0x20) + ypose_ecs |= 512; + xpos <<= 1; + if (w2 & 0x01) + xpos |= 1; + xpos_ecs = xpos << 2; + if (w2 & 0x10) + xpos_ecs |= 2; + if (w2 & 0x08) + xpos_ecs |= 1; + if (w2 & (0x40 | 0x20 | 0x10 | 0x08)) + ecs = 1; + if (w1 & 0x80) + sh10 = 1; + if (ypose < ypos) + ypose += 256; + + for (y = ypos; y < ypose; y++) { + int x; + addr += size * 4; + if (addr2) + addr2 += size * 4; + if (size == 1) { + w1 = get_word (addr); + w2 = get_word (addr + 2); + if (addr2) { + ww1 = get_word (addr2); + ww2 = get_word (addr2 + 2); + } + } else if (size == 2) { + w1 = get_long (addr); + w2 = get_long (addr + 4); + if (addr2) { + ww1 = get_long (addr2); + ww2 = get_long (addr2 + 4); + } + } else if (size == 4) { + w1 = get_long (addr) << 16; + w2 = get_long (addr + 4) << 16; + w1 <<= 16; + w2 <<= 16; + w1 |= get_long (addr); + w2 |= get_long (addr2 + 4); + if (addr2) { + ww1 = get_long (addr2) << 16; + ww2 = get_long (addr2 + 4) << 16; + ww1 <<= 16; + ww2 <<= 16; + ww1 |= get_long (addr2); + ww2 |= get_long (addr2 + 4); + } + } + width = size * 16; + for (x = 0; x < width; x++) { + int v1 = (w1 >> (width - x)) & 1; + int v2 = (w2 >> (width - x)) & 1; + int v = v1 * 2 + v2; + if (addr2) { + int vv1 = (ww1 >> (width - x)) & 1; + int vv2 = (ww2 >> (width - x)) & 1; + int vv = vv1 * 2 + vv2; + v *= 4; + v += vv; + tmp[x] = v >= 10 ? 'A' + v - 10 : v + '0'; + } else { + tmp[x] = v + '0'; + } + } + tmp[width] = 0; + console_out_f (L"%3d %06X %s\n", y, addr, tmp); } - } - tmp[width] = 0; - console_out_f (L"%3d %06X %s\n", y, addr, tmp); - } - console_out_f (L"Sprite address %08X, width = %d\n", saddr, size * 16); - console_out_f (L"OCS: StartX=%d StartY=%d EndY=%d\n", xpos, ypos, ypose); - console_out_f (L"ECS: StartX=%d (%d.%d) StartY=%d EndY=%d%s\n", xpos_ecs, xpos_ecs / 4, xpos_ecs & 3, ypos_ecs, ypose_ecs, ecs ? " (*)" : ""); - console_out_f (L"Attach: %d. AGA SSCAN/SH10 bit: %d\n", attach, sh10); + console_out_f (L"Sprite address %08X, width = %d\n", saddr, size * 16); + console_out_f (L"OCS: StartX=%d StartY=%d EndY=%d\n", xpos, ypos, ypose); + console_out_f (L"ECS: StartX=%d (%d.%d) StartY=%d EndY=%d%s\n", xpos_ecs, xpos_ecs / 4, xpos_ecs & 3, ypos_ecs, ypose_ecs, ecs ? " (*)" : ""); + console_out_f (L"Attach: %d. AGA SSCAN/SH10 bit: %d\n", attach, sh10); - addr += size * 4; - if (get_word (addr) == 0 && get_word (addr + size * 4) == 0) - break; - max--; - if (max <= 0) - break; - } + addr += size * 4; + if (get_word (addr) == 0 && get_word (addr + size * 4) == 0) + break; + max--; + if (max <= 0) + break; + } } static void disk_debug (TCHAR **inptr) { - TCHAR parm[10]; - int i; + TCHAR parm[10]; + int i; - if (**inptr == 'd') { - (*inptr)++; - ignore_ws (inptr); - disk_debug_logging = readint (inptr); - console_out_f (L"Disk logging level %d\n", disk_debug_logging); - return; - } - disk_debug_mode = 0; - disk_debug_track = -1; - ignore_ws (inptr); - if (!next_string (inptr, parm, sizeof (parm) / sizeof (TCHAR), 1)) - goto end; - for (i = 0; i < _tcslen(parm); i++) { - if (parm[i] == 'R') - disk_debug_mode |= DISK_DEBUG_DMA_READ; - if (parm[i] == 'W') - disk_debug_mode |= DISK_DEBUG_DMA_WRITE; - if (parm[i] == 'P') - disk_debug_mode |= DISK_DEBUG_PIO; - } - if (more_params(inptr)) - disk_debug_track = readint(inptr); - if (disk_debug_track < 0 || disk_debug_track > 2 * 83) + if (**inptr == 'd') { + (*inptr)++; + ignore_ws (inptr); + disk_debug_logging = readint (inptr); + console_out_f (L"Disk logging level %d\n", disk_debug_logging); + return; + } + disk_debug_mode = 0; disk_debug_track = -1; - if (disk_debug_logging == 0) - disk_debug_logging = 1; + ignore_ws (inptr); + if (!next_string (inptr, parm, sizeof (parm) / sizeof (TCHAR), 1)) + goto end; + for (i = 0; i < _tcslen(parm); i++) { + if (parm[i] == 'R') + disk_debug_mode |= DISK_DEBUG_DMA_READ; + if (parm[i] == 'W') + disk_debug_mode |= DISK_DEBUG_DMA_WRITE; + if (parm[i] == 'P') + disk_debug_mode |= DISK_DEBUG_PIO; + } + if (more_params(inptr)) + disk_debug_track = readint(inptr); + if (disk_debug_track < 0 || disk_debug_track > 2 * 83) + disk_debug_track = -1; + if (disk_debug_logging == 0) + disk_debug_logging = 1; end: - console_out_f (L"Disk breakpoint mode %c%c%c track %d\n", - disk_debug_mode & DISK_DEBUG_DMA_READ ? 'R' : '-', - disk_debug_mode & DISK_DEBUG_DMA_WRITE ? 'W' : '-', - disk_debug_mode & DISK_DEBUG_PIO ? 'P' : '-', - disk_debug_track); + console_out_f (L"Disk breakpoint mode %c%c%c track %d\n", + disk_debug_mode & DISK_DEBUG_DMA_READ ? 'R' : '-', + disk_debug_mode & DISK_DEBUG_DMA_WRITE ? 'W' : '-', + disk_debug_mode & DISK_DEBUG_PIO ? 'P' : '-', + disk_debug_track); } static void find_ea (TCHAR **inptr) { - uae_u32 ea, sea, dea; - uaecptr addr, end; - int hits = 0; - - addr = 0; - end = lastaddr(); - ea = readhex (inptr); - if (more_params(inptr)) { - addr = readhex (inptr); - if (more_params(inptr)) - end = readhex (inptr); - } - console_out_f (L"Searching from %08X to %08X\n", addr, end); - while((addr = nextaddr(addr, &end)) != 0xffffffff) { - if ((addr & 1) == 0 && addr + 6 <= end) { - sea = 0xffffffff; - dea = 0xffffffff; - m68k_disasm_ea (NULL, addr, NULL, 1, &sea, &dea); - if (ea == sea || ea == dea) { - m68k_disasm (stdout, addr, NULL, 1); - hits++; - if (hits > 100) { - write_log (L"Too many hits. End addr = %08X\n", addr); - break; + uae_u32 ea, sea, dea; + uaecptr addr, end; + int hits = 0; + + addr = 0; + end = lastaddr(); + ea = readhex (inptr); + if (more_params(inptr)) { + addr = readhex (inptr); + if (more_params(inptr)) + end = readhex (inptr); + } + console_out_f (L"Searching from %08X to %08X\n", addr, end); + while((addr = nextaddr(addr, &end)) != 0xffffffff) { + if ((addr & 1) == 0 && addr + 6 <= end) { + sea = 0xffffffff; + dea = 0xffffffff; + m68k_disasm_ea (NULL, addr, NULL, 1, &sea, &dea); + if (ea == sea || ea == dea) { + m68k_disasm (stdout, addr, NULL, 1); + hits++; + if (hits > 100) { + write_log (L"Too many hits. End addr = %08X\n", addr); + break; + } + } } - } } - } } static void m68k_modify (TCHAR **inptr) { - uae_u32 v; - TCHAR parm[10]; - TCHAR c1, c2; - int i; + uae_u32 v; + TCHAR parm[10]; + TCHAR c1, c2; + int i; - if (!next_string (inptr, parm, sizeof (parm) / sizeof (TCHAR), 1)) - return; - c1 = _totupper (parm[0]); - c2 = 99; - if (c1 == 'A' || c1 == 'D' || c1 == 'P') { - c2 = _totupper (parm[1]); - if (isdigit (c2)) - c2 -= '0'; - else - c2 = 99; - } - v = readhex (inptr); - if (c1 == 'A' && c2 < 8) - regs.regs[8 + c2] = v; - else if (c1 == 'D' && c2 < 8) - regs.regs[c2] = v; - else if (c1 == 'P' && c2 == 0) - regs.irc = v; - else if (c1 == 'P' && c2 == 1) - regs.ir = v; - else if (!_tcscmp (parm, L"SR")) { - regs.sr = v; - MakeFromSR (); - } else if (!_tcscmp (parm, L"CCR")) { - regs.sr = (regs.sr & ~31) | (v & 31); - MakeFromSR (); - } else if (!_tcscmp (parm, L"USP")) { - regs.usp = v; - } else if (!_tcscmp (parm, L"ISP")) { - regs.isp = v; - } else if (!_tcscmp (parm, L"PC")) { - m68k_setpc (v); - fill_prefetch_slow (); - } else { - for (i = 0; m2cregs[i].regname; i++) { - if (!_tcscmp (parm, m2cregs[i].regname)) - val_move2c2 (m2cregs[i].regno, v); + if (!next_string (inptr, parm, sizeof (parm) / sizeof (TCHAR), 1)) + return; + c1 = _totupper (parm[0]); + c2 = 99; + if (c1 == 'A' || c1 == 'D' || c1 == 'P') { + c2 = _totupper (parm[1]); + if (isdigit (c2)) + c2 -= '0'; + else + c2 = 99; + } + v = readhex (inptr); + if (c1 == 'A' && c2 < 8) + regs.regs[8 + c2] = v; + else if (c1 == 'D' && c2 < 8) + regs.regs[c2] = v; + else if (c1 == 'P' && c2 == 0) + regs.irc = v; + else if (c1 == 'P' && c2 == 1) + regs.ir = v; + else if (!_tcscmp (parm, L"SR")) { + regs.sr = v; + MakeFromSR (); + } else if (!_tcscmp (parm, L"CCR")) { + regs.sr = (regs.sr & ~31) | (v & 31); + MakeFromSR (); + } else if (!_tcscmp (parm, L"USP")) { + regs.usp = v; + } else if (!_tcscmp (parm, L"ISP")) { + regs.isp = v; + } else if (!_tcscmp (parm, L"PC")) { + m68k_setpc (v); + fill_prefetch_slow (); + } else { + for (i = 0; m2cregs[i].regname; i++) { + if (!_tcscmp (parm, m2cregs[i].regname)) + val_move2c2 (m2cregs[i].regno, v); + } } - } } static void debug_1 (void) { - TCHAR input[MAX_LINEWIDTH]; - uaecptr nxdis, nxmem, addr; - - m68k_dumpstate (stdout, &nextpc); - nxdis = nextpc; nxmem = 0; - debugger_active = 1; - - for (;;) { - TCHAR cmd, *inptr; - int v; - - if (!debugger_active) - return; - update_debug_info (); - console_out (L">"); - console_flush (); - debug_linecounter = 0; - v = console_get (input, MAX_LINEWIDTH); - if (v < 0) - return; - if (v == 0) - continue; - - inptr = input; - cmd = next_char (&inptr); - switch (cmd) - { - case 'c': dumpcia (); dumpdisk (); dumpcustom (); break; - case 'i': - addr = 0xffffffff; - if (more_params (&inptr)) - addr = readhex (&inptr); - dump_vectors (addr); - break; - case 'e': dump_custom_regs (tolower(*inptr) == 'a'); break; - case 'r': - { - if (more_params(&inptr)) - m68k_modify (&inptr); - else - m68k_dumpstate (stdout, &nextpc); - } - break; - case 'D': deepcheatsearch (&inptr); break; - case 'C': cheatsearch (&inptr); break; - case 'W': writeintomem (&inptr); break; - case 'w': memwatch (&inptr); break; - case 'S': savemem (&inptr); break; - case 's': - if (*inptr == 'c') { - screenshot (1, 1); - } else if (*inptr == 'p') { - inptr++; - debug_sprite (&inptr); - } else if (*inptr == 'm') { - if (*(inptr + 1) == 'c') { - next_char (&inptr); - next_char (&inptr); - if (!smc_table) - smc_detect_init (&inptr); - else - smc_free (); - } - } else { - searchmem (&inptr); - } - break; - case 'd': - { - if (*inptr == 'i') { - next_char (&inptr); - disk_debug (&inptr); - } else if (*inptr == 'j') { - inptr++; - inputdevice_logging = 1 | 2; - if (more_params (&inptr)) - inputdevice_logging = readint(&inptr); - console_out_f (L"Input logging level %d\n", inputdevice_logging); - } else if (*inptr == 'm') { - memory_map_dump_2 (0); - } 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; - if (more_params(&inptr)) - daddr = readhex(&inptr); - else - daddr = nxdis; - if (more_params(&inptr)) - count = readhex(&inptr); - else - count = 10; - m68k_disasm (stdout, daddr, &nxdis, count); - } - } - break; - case 'T': - if (inptr[0] == 't' || inptr[0] == 0) - show_exec_tasks (); - else - show_exec_lists (inptr[0]); - break; - case 't': - if (more_params (&inptr)) - skipaddr_doskip = readint (&inptr); - if (skipaddr_doskip <= 0 || skipaddr_doskip > 10000) - skipaddr_doskip = 1; - set_special (SPCFLAG_BRK); - exception_debugging = 1; - return; - case 'z': - skipaddr_start = nextpc; - skipaddr_doskip = 1; - do_skip = 1; - exception_debugging = 1; - return; - - case 'f': - if (inptr[0] == 'a') { - next_char(&inptr); - find_ea (&inptr); - } else if (inptr[0] == 'p') { - inptr++; - if (process_breakpoint(&inptr)) - return; - } else { - if (instruction_breakpoint (&inptr)) - return; - } - break; - - case 'q': - uae_quit(); - deactivate_debugger(); - return; - - case 'g': - if (more_params (&inptr)) { - m68k_setpc (readhex (&inptr)); - fill_prefetch_slow (); - } - deactivate_debugger(); - return; - - case 'x': - if (_totupper(inptr[0]) == 'X') { - debugger_change(-1); - } else { - deactivate_debugger(); - close_console(); - return; - } - break; + TCHAR input[MAX_LINEWIDTH]; + uaecptr nxdis, nxmem, addr; - case 'H': - { - int count, temp, badly, skip; - uae_u32 oldpc = m68k_getpc (); - struct regstruct save_regs = regs; - - badly = 0; - if (inptr[0] == 'H') { - badly = 1; - inptr++; - } - - if (more_params(&inptr)) - count = readint (&inptr); - else - count = 10; - if (count < 0) - break; - skip = count; - if (more_params (&inptr)) - skip = count - readint (&inptr); - - temp = lasthist; - while (count-- > 0 && temp != firsthist) { - if (temp == 0) - temp = MAX_HIST - 1; - else - temp--; - } - while (temp != lasthist) { - regs = history[temp]; - m68k_setpc (history[temp].pc); - if (badly) - m68k_dumpstate (stdout, NULL); - else - m68k_disasm (stdout, history[temp].pc, NULL, 1); - if (skip-- < 0) - break; - if (++temp == MAX_HIST) - temp = 0; - } - regs = save_regs; - m68k_setpc (oldpc); - } - break; - case 'M': - if (more_params (&inptr)) { - switch (next_char (&inptr)) + m68k_dumpstate (stdout, &nextpc); + nxdis = nextpc; nxmem = 0; + debugger_active = 1; + + for (;;) { + TCHAR cmd, *inptr; + int v; + + if (!debugger_active) + return; + update_debug_info (); + console_out (L">"); + console_flush (); + debug_linecounter = 0; + v = console_get (input, MAX_LINEWIDTH); + if (v < 0) + return; + if (v == 0) + continue; + + inptr = input; + cmd = next_char (&inptr); + switch (cmd) { - case 'a': - if (more_params (&inptr)) - audio_channel_mask = readhex (&inptr); - console_out_f (L"Audio mask = %02X\n", audio_channel_mask); - break; - case 's': - if (more_params (&inptr)) - debug_sprite_mask = readhex (&inptr); - console_out_f (L"Sprite mask: %02X\n", debug_sprite_mask); - break; - case 'b': - if (more_params (&inptr)) { - debug_bpl_mask = readhex (&inptr) & 0xff; + case 'c': dumpcia (); dumpdisk (); dumpcustom (); break; + case 'i': + addr = 0xffffffff; if (more_params (&inptr)) - debug_bpl_mask_one = readhex (&inptr) & 0xff; - notice_screen_contents_lost (); - } - console_out_f (L"Bitplane mask: %02X (%02X)\n", debug_bpl_mask, debug_bpl_mask_one); - break; - } - } - break; - case 'm': - { - uae_u32 maddr; - int lines; + addr = readhex (&inptr); + dump_vectors (addr); + break; + case 'e': dump_custom_regs (tolower(*inptr) == 'a'); break; + case 'r': + { + if (more_params(&inptr)) + m68k_modify (&inptr); + else + m68k_dumpstate (stdout, &nextpc); + } + break; + case 'D': deepcheatsearch (&inptr); break; + case 'C': cheatsearch (&inptr); break; + case 'W': writeintomem (&inptr); break; + case 'w': memwatch (&inptr); break; + case 'S': savemem (&inptr); break; + case 's': + if (*inptr == 'c') { + screenshot (1, 1); + } else if (*inptr == 'p') { + inptr++; + debug_sprite (&inptr); + } else if (*inptr == 'm') { + if (*(inptr + 1) == 'c') { + next_char (&inptr); + next_char (&inptr); + if (!smc_table) + smc_detect_init (&inptr); + else + smc_free (); + } + } else { + searchmem (&inptr); + } + break; + case 'd': + { + if (*inptr == 'i') { + next_char (&inptr); + disk_debug (&inptr); + } else if (*inptr == 'j') { + inptr++; + inputdevice_logging = 1 | 2; + if (more_params (&inptr)) + inputdevice_logging = readint(&inptr); + console_out_f (L"Input logging level %d\n", inputdevice_logging); + } else if (*inptr == 'm') { + memory_map_dump_2 (0); + } else if (*inptr == 't') { + next_char (&inptr); + debugtest_set (&inptr); #ifdef _WIN32 - if (*inptr == 'g') { - extern void update_memdump (uae_u32); - next_char (&inptr); - if (more_params (&inptr)) - update_memdump (readhex (&inptr)); - break; - } + } else if (*inptr == 'g') { + extern void update_disassembly (uae_u32); + next_char (&inptr); + if (more_params (&inptr)) + update_disassembly (readhex (&inptr)); #endif - if (more_params (&inptr)) { - maddr = readhex (&inptr); - } else { - maddr = nxmem; - } - if (more_params (&inptr)) - lines = readhex (&inptr); - else - lines = 20; - dumpmem (maddr, &nxmem, lines); - } - break; - case 'v': - case 'V': - { - int v1 = vpos, v2 = 0; - if (more_params (&inptr)) - v1 = readint (&inptr); - if (more_params (&inptr)) - v2 = readint (&inptr); - if (debug_dma) { - decode_dma_record (v2, v1, cmd == 'v'); - } else { - debug_dma = v1 < 0 ? -v1 : 1; - console_out_f (L"DMA debugger enabled, mode=%d.\n", debug_dma); - } - } - break; - case 'o': - { - if (copper_debugger (&inptr)) { - debugger_active = 0; - debugging = 0; - return; - } - break; - } - case 'O': - if (more_params (&inptr)) { - int plane = readint (&inptr); - int offs = readint (&inptr); - if (plane >= 0 && plane < 8) - bpl_off[plane] = offs; - } else { - int i; - for (i = 0; i < 8; i++) - console_out_f (L"Plane %d offset %d\n", i, bpl_off[i]); - } - break; - case 'b': - if (staterecorder (&inptr)) - return; - break; - case 'U': - if (currprefs.cpu_model && more_params (&inptr)) { - int super, data, i; - uaecptr addrl = readhex (&inptr); - uaecptr addrp; - console_out_f (L"%08X translates to:\n", addrl); - for (i = 0; i < 4; i++) { - super = (i & 2) ? 1 : 0; - data = (i & 1) ? 1 : 0; - console_out_f (L"S%dD%d=", super, data); - TRY(prb) { - addrp = mmu_translate (addrl, super, data, 0); - console_out_f (L"%08X", addrp); - TRY(prb2) { - addrp = mmu_translate (addrl, super, data, 1); - console_out_f (L" RW"); - } CATCH(prb2) { - console_out_f (L" RO"); + } else { + uae_u32 daddr; + int count; + if (more_params(&inptr)) + daddr = readhex(&inptr); + else + daddr = nxdis; + if (more_params(&inptr)) + count = readhex(&inptr); + else + count = 10; + m68k_disasm (stdout, daddr, &nxdis, count); + } + } + break; + case 'T': + if (inptr[0] == 't' || inptr[0] == 0) + show_exec_tasks (); + else + show_exec_lists (inptr[0]); + break; + case 't': + if (more_params (&inptr)) + skipaddr_doskip = readint (&inptr); + if (skipaddr_doskip <= 0 || skipaddr_doskip > 10000) + skipaddr_doskip = 1; + set_special (SPCFLAG_BRK); + exception_debugging = 1; + return; + case 'z': + skipaddr_start = nextpc; + skipaddr_doskip = 1; + do_skip = 1; + exception_debugging = 1; + return; + + case 'f': + if (inptr[0] == 'a') { + next_char(&inptr); + find_ea (&inptr); + } else if (inptr[0] == 'p') { + inptr++; + if (process_breakpoint(&inptr)) + return; + } else { + if (instruction_breakpoint (&inptr)) + return; + } + break; + + case 'q': + uae_quit(); + deactivate_debugger(); + return; + + case 'g': + if (more_params (&inptr)) { + m68k_setpc (readhex (&inptr)); + fill_prefetch_slow (); + } + deactivate_debugger(); + return; + + case 'x': + if (_totupper(inptr[0]) == 'X') { + debugger_change(-1); + } else { + deactivate_debugger(); + close_console(); + return; + } + break; + + case 'H': + { + int count, temp, badly, skip; + uae_u32 oldpc = m68k_getpc (); + struct regstruct save_regs = regs; + + badly = 0; + if (inptr[0] == 'H') { + badly = 1; + inptr++; + } + + if (more_params(&inptr)) + count = readint (&inptr); + else + count = 10; + if (count < 0) + break; + skip = count; + if (more_params (&inptr)) + skip = count - readint (&inptr); + + temp = lasthist; + while (count-- > 0 && temp != firsthist) { + if (temp == 0) + temp = MAX_HIST - 1; + else + temp--; + } + while (temp != lasthist) { + regs = history[temp]; + m68k_setpc (history[temp].pc); + if (badly) + m68k_dumpstate (stdout, NULL); + else + m68k_disasm (stdout, history[temp].pc, NULL, 1); + if (skip-- < 0) + break; + if (++temp == MAX_HIST) + temp = 0; + } + regs = save_regs; + m68k_setpc (oldpc); + } + break; + case 'M': + if (more_params (&inptr)) { + switch (next_char (&inptr)) + { + case 'a': + if (more_params (&inptr)) + audio_channel_mask = readhex (&inptr); + console_out_f (L"Audio mask = %02X\n", audio_channel_mask); + break; + case 's': + if (more_params (&inptr)) + debug_sprite_mask = readhex (&inptr); + console_out_f (L"Sprite mask: %02X\n", debug_sprite_mask); + break; + case 'b': + if (more_params (&inptr)) { + debug_bpl_mask = readhex (&inptr) & 0xff; + if (more_params (&inptr)) + debug_bpl_mask_one = readhex (&inptr) & 0xff; + notice_screen_contents_lost (); + } + console_out_f (L"Bitplane mask: %02X (%02X)\n", debug_bpl_mask, debug_bpl_mask_one); + break; + } + } + break; + case 'm': + { + 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 { + maddr = nxmem; + } + if (more_params (&inptr)) + lines = readhex (&inptr); + else + lines = 20; + dumpmem (maddr, &nxmem, lines); } - } CATCH(prb) { - console_out_f (L"***********"); - } - console_out_f (L" "); + break; + case 'v': + case 'V': + { + int v1 = vpos, v2 = 0; + if (more_params (&inptr)) + v1 = readint (&inptr); + if (more_params (&inptr)) + v2 = readint (&inptr); + if (debug_dma) { + decode_dma_record (v2, v1, cmd == 'v'); + } else { + debug_dma = v1 < 0 ? -v1 : 1; + console_out_f (L"DMA debugger enabled, mode=%d.\n", debug_dma); + } + } + break; + case 'o': + { + if (copper_debugger (&inptr)) { + debugger_active = 0; + debugging = 0; + return; + } + break; + } + case 'O': + if (more_params (&inptr)) { + int plane = readint (&inptr); + int offs = readint (&inptr); + if (plane >= 0 && plane < 8) + bpl_off[plane] = offs; + } else { + int i; + for (i = 0; i < 8; i++) + console_out_f (L"Plane %d offset %d\n", i, bpl_off[i]); + } + break; + case 'b': + if (staterecorder (&inptr)) + return; + break; + case 'U': + if (currprefs.cpu_model && more_params (&inptr)) { + int super, data, i; + uaecptr addrl = readhex (&inptr); + uaecptr addrp; + console_out_f (L"%08X translates to:\n", addrl); + for (i = 0; i < 4; i++) { + super = (i & 2) ? 1 : 0; + data = (i & 1) ? 1 : 0; + console_out_f (L"S%dD%d=", super, data); + TRY(prb) { + addrp = mmu_translate (addrl, super, data, 0); + console_out_f (L"%08X", addrp); + TRY(prb2) { + addrp = mmu_translate (addrl, super, data, 1); + console_out_f (L" RW"); + } CATCH(prb2) { + console_out_f (L" RO"); + } + } CATCH(prb) { + console_out_f (L"***********"); + } + console_out_f (L" "); + } + console_out_f (L"\n"); + } + break; + case 'h': + case '?': + if (more_params (&inptr)) + converter (&inptr); + else + debug_help (); + break; } - console_out_f (L"\n"); - } - break; - case 'h': - case '?': - if (more_params (&inptr)) - converter (&inptr); - else - debug_help (); - break; } - } } static void addhistory (void) { - uae_u32 pc = m68k_getpc (); -// if (!notinrom()) -// return; - history[lasthist] = regs; - history[lasthist].pc = m68k_getpc (); - if (++lasthist == MAX_HIST) - lasthist = 0; - if (lasthist == firsthist) { - if (++firsthist == MAX_HIST) firsthist = 0; - } + uae_u32 pc = m68k_getpc (); + // if (!notinrom()) + // return; + history[lasthist] = regs; + history[lasthist].pc = m68k_getpc (); + if (++lasthist == MAX_HIST) + lasthist = 0; + if (lasthist == firsthist) { + if (++firsthist == MAX_HIST) firsthist = 0; + } } void debug (void) { - int i; + int i; - if (savestate_state) - return; + if (savestate_state) + return; - bogusframe = 1; - addhistory (); + bogusframe = 1; + addhistory (); #if 0 - if (do_skip && skipaddr_start == 0xC0DEDBAD) { - if (trace_same_insn_count > 0) { - if (memcmp (trace_insn_copy, regs.pc_p, 10) == 0 - && memcmp (trace_prev_regs.regs, regs.regs, sizeof regs.regs) == 0) - { - trace_same_insn_count++; - return; - } - } - if (trace_same_insn_count > 1) - fprintf (logfile, "[ repeated %d times ]\n", trace_same_insn_count); - m68k_dumpstate (logfile, &nextpc); - trace_same_insn_count = 1; - memcpy (trace_insn_copy, regs.pc_p, 10); - memcpy (&trace_prev_regs, ®s, sizeof regs); - } + if (do_skip && skipaddr_start == 0xC0DEDBAD) { + if (trace_same_insn_count > 0) { + if (memcmp (trace_insn_copy, regs.pc_p, 10) == 0 + && memcmp (trace_prev_regs.regs, regs.regs, sizeof regs.regs) == 0) + { + trace_same_insn_count++; + return; + } + } + if (trace_same_insn_count > 1) + fprintf (logfile, "[ repeated %d times ]\n", trace_same_insn_count); + m68k_dumpstate (logfile, &nextpc); + trace_same_insn_count = 1; + memcpy (trace_insn_copy, regs.pc_p, 10); + memcpy (&trace_prev_regs, ®s, sizeof regs); + } #endif - if (!memwatch_triggered) { - if (do_skip) { - uae_u32 pc; - uae_u16 opcode; - int bp = 0; - - pc = munge24 (m68k_getpc ()); - opcode = (currprefs.cpu_compatible || currprefs.cpu_cycle_exact) ? regs.ir : get_word (pc); - - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - if (!bpnodes[i].enabled) - continue; - if (bpnodes[i].addr == pc) { - bp = 1; - console_out_f (L"Breakpoint at %08X\n", pc); - break; - } - } - - if (skipaddr_doskip) { - if (skipaddr_start == pc) - bp = 1; - if ((processptr || processname) && notinrom()) { - uaecptr execbase = get_long (4); - uaecptr activetask = get_long (execbase + 276); - int process = get_byte (activetask + 8) == 13 ? 1 : 0; - uae_u8 *name = get_real_address (get_long (activetask + 10)); - if (process) { - uaecptr cli = BPTR2APTR(get_long (activetask + 172)); - uaecptr seglist = 0; - - uae_char *command = NULL; - if (cli) { - if (processname) - command = get_real_address (BPTR2APTR(get_long (cli + 16))); - seglist = BPTR2APTR(get_long (cli + 60)); - } else { - seglist = BPTR2APTR(get_long (activetask + 128)); - seglist = BPTR2APTR(get_long (seglist + 12)); + if (!memwatch_triggered) { + if (do_skip) { + uae_u32 pc; + uae_u16 opcode; + int bp = 0; + + pc = munge24 (m68k_getpc ()); + opcode = (currprefs.cpu_compatible || currprefs.cpu_cycle_exact) ? regs.ir : get_word (pc); + + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + if (!bpnodes[i].enabled) + continue; + if (bpnodes[i].addr == pc) { + bp = 1; + console_out_f (L"Breakpoint at %08X\n", pc); + break; + } } - if (activetask == processptr || (processname && (!stricmp(name, processname) || (command && command[0] && !strnicmp(command + 1, processname, command[0]) && processname[command[0]] == 0)))) { - while (seglist) { - uae_u32 size = get_long (seglist - 4) - 4; - if (pc >= (seglist + 4) && pc < (seglist + size)) { - bp = 1; - break; + + if (skipaddr_doskip) { + if (skipaddr_start == pc) + bp = 1; + if ((processptr || processname) && notinrom()) { + uaecptr execbase = get_long (4); + uaecptr activetask = get_long (execbase + 276); + int process = get_byte (activetask + 8) == 13 ? 1 : 0; + uae_u8 *name = get_real_address (get_long (activetask + 10)); + if (process) { + uaecptr cli = BPTR2APTR(get_long (activetask + 172)); + uaecptr seglist = 0; + + uae_char *command = NULL; + if (cli) { + if (processname) + command = get_real_address (BPTR2APTR(get_long (cli + 16))); + seglist = BPTR2APTR(get_long (cli + 60)); + } else { + seglist = BPTR2APTR(get_long (activetask + 128)); + seglist = BPTR2APTR(get_long (seglist + 12)); + } + if (activetask == processptr || (processname && (!stricmp(name, processname) || (command && command[0] && !strnicmp(command + 1, processname, command[0]) && processname[command[0]] == 0)))) { + while (seglist) { + uae_u32 size = get_long (seglist - 4) - 4; + if (pc >= (seglist + 4) && pc < (seglist + size)) { + bp = 1; + break; + } + seglist = BPTR2APTR(get_long (seglist)); + } + } + } + } else if (skipins != 0xffffffff) { + if (skipins == 0x10000) { + if (opcode == 0x4e75 || opcode == 0x4e73 || opcode == 0x4e77) + bp = 1; + } else if (opcode == skipins) + bp = 1; + } else if (skipaddr_start == 0xffffffff && skipaddr_doskip < 0) { + if ((pc < 0xe00000 || pc >= 0x1000000) && opcode != 0x4ef9) + bp = 1; + } else if (skipaddr_start == 0xffffffff && skipaddr_doskip > 0) { + bp = 1; + } else if (skipaddr_end != 0xffffffff) { + if (pc >= skipaddr_start && pc < skipaddr_end) + bp = 1; } - seglist = BPTR2APTR(get_long (seglist)); - } } - } - } else if (skipins != 0xffffffff) { - if (skipins == 0x10000) { - if (opcode == 0x4e75 || opcode == 0x4e73 || opcode == 0x4e77) - bp = 1; - } else if (opcode == skipins) - bp = 1; - } else if (skipaddr_start == 0xffffffff && skipaddr_doskip < 0) { - if ((pc < 0xe00000 || pc >= 0x1000000) && opcode != 0x4ef9) - bp = 1; - } else if (skipaddr_start == 0xffffffff && skipaddr_doskip > 0) { - bp = 1; - } else if (skipaddr_end != 0xffffffff) { - if (pc >= skipaddr_start && pc < skipaddr_end) - bp = 1; - } - } - if (sr_bpmask || sr_bpvalue) { - MakeSR (); - if ((regs.sr & sr_bpmask) == sr_bpvalue) { - console_out (L"SR breakpoint\n"); - bp = 1; + if (sr_bpmask || sr_bpvalue) { + MakeSR (); + if ((regs.sr & sr_bpmask) == sr_bpvalue) { + console_out (L"SR breakpoint\n"); + bp = 1; + } + } + if (!bp) { + set_special (SPCFLAG_BRK); + return; + } } - } - if (!bp) { - set_special (SPCFLAG_BRK); - return; - } - } - } else { - console_out_f (L"Memwatch %d: break at %08X.%c %c%c%c %08X PC=%08X\n", memwatch_triggered - 1, mwhit.addr, - mwhit.size == 1 ? 'B' : (mwhit.size == 2 ? 'W' : 'L'), - (mwhit.rwi & 1) ? 'R' : ' ', (mwhit.rwi & 2) ? 'W' : ' ', (mwhit.rwi & 4) ? 'I' : ' ', - mwhit.val, mwhit.pc); - memwatch_triggered = 0; - } - if (skipaddr_doskip > 0) { - skipaddr_doskip--; + } else { + console_out_f (L"Memwatch %d: break at %08X.%c %c%c%c %08X PC=%08X\n", memwatch_triggered - 1, mwhit.addr, + mwhit.size == 1 ? 'B' : (mwhit.size == 2 ? 'W' : 'L'), + (mwhit.rwi & 1) ? 'R' : ' ', (mwhit.rwi & 2) ? 'W' : ' ', (mwhit.rwi & 4) ? 'I' : ' ', + mwhit.val, mwhit.pc); + memwatch_triggered = 0; + } if (skipaddr_doskip > 0) { - set_special (SPCFLAG_BRK); - return; - } - } - - inputdevice_unacquire (); - pause_sound (); - do_skip = 0; - skipaddr_start = 0xffffffff; - skipaddr_end = 0xffffffff; - skipins = 0xffffffff; - skipaddr_doskip = 0; - exception_debugging = 0; - debug_rewind = 0; - processptr = 0; + skipaddr_doskip--; + if (skipaddr_doskip > 0) { + set_special (SPCFLAG_BRK); + return; + } + } + + inputdevice_unacquire (); + pause_sound (); + do_skip = 0; + skipaddr_start = 0xffffffff; + skipaddr_end = 0xffffffff; + skipins = 0xffffffff; + skipaddr_doskip = 0; + exception_debugging = 0; + debug_rewind = 0; + processptr = 0; #if 0 - if (!currprefs.statecapture) { - changed_prefs.statecapture = currprefs.statecapture = 1; - savestate_init (); - } + if (!currprefs.statecapture) { + changed_prefs.statecapture = currprefs.statecapture = 1; + savestate_init (); + } #endif - debug_1 (); - if (!debug_rewind && !currprefs.cachesize + debug_1 (); + if (!debug_rewind && !currprefs.cachesize #ifdef FILESYS - && nr_units () == 0 + && nr_units () == 0 #endif - ) { - savestate_capture (1); - } - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - if (bpnodes[i].enabled) - do_skip = 1; - } - if (sr_bpmask || sr_bpvalue) - do_skip = 1; - if (do_skip) { - set_special (SPCFLAG_BRK); - m68k_resumestopped (); - debugging = 1; - } - resume_sound (); - inputdevice_acquire (TRUE); + ) { + savestate_capture (1); + } + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + if (bpnodes[i].enabled) + do_skip = 1; + } + if (sr_bpmask || sr_bpvalue) + do_skip = 1; + if (do_skip) { + set_special (SPCFLAG_BRK); + m68k_resumestopped (); + debugging = 1; + } + resume_sound (); + inputdevice_acquire (TRUE); } const TCHAR *debuginfo (int mode) { - static TCHAR txt[100]; - uae_u32 pc = M68K_GETPC; - _stprintf (txt, L"PC=%08X INS=%04X %04X %04X", - pc, get_word (pc), get_word (pc + 2), get_word (pc + 4)); - return txt; + static TCHAR txt[100]; + uae_u32 pc = M68K_GETPC; + _stprintf (txt, L"PC=%08X INS=%04X %04X %04X", + pc, get_word (pc), get_word (pc + 2), get_word (pc + 4)); + return txt; } static int mmu_logging; @@ -3425,11 +3427,11 @@ static int mmu_logging; #define MMU_PAGE_SHIFT 16 struct mmudata { - uae_u32 flags; - uae_u32 addr; - uae_u32 len; - uae_u32 remap; - uae_u32 p_addr; + uae_u32 flags; + uae_u32 addr; + uae_u32 len; + uae_u32 remap; + uae_u32 p_addr; }; static struct mmudata *mmubanks; @@ -3440,8 +3442,8 @@ static int mmu_slots; static struct regstruct mmur; struct mmunode { - struct mmudata *mmubank; - struct mmunode *next; + struct mmudata *mmubank; + struct mmunode *next; }; static struct mmunode **mmunl; @@ -3461,317 +3463,317 @@ static struct mmunode **mmunl; void mmu_do_hit (void) { - int i; - uaecptr p; - uae_u32 pc; - - mmu_triggered = 0; - pc = m68k_getpc (); - p = mmu_regs + 18 * 4; - put_long (p, pc); - regs = mmu_backup_regs; - regs.intmask = 7; - regs.t0 = regs.t1 = 0; - if (!regs.s) { - regs.usp = m68k_areg (regs, 7); - if (currprefs.cpu_model >= 68020) - m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; - else - m68k_areg (regs, 7) = regs.isp; - regs.s = 1; - } - MakeSR (); - m68k_setpc (mmu_callback); - fill_prefetch_slow (); - - if (currprefs.cpu_model > 68000) { - for (i = 0 ; i < 9; i++) { - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), 0); + int i; + uaecptr p; + uae_u32 pc; + + mmu_triggered = 0; + pc = m68k_getpc (); + p = mmu_regs + 18 * 4; + put_long (p, pc); + regs = mmu_backup_regs; + regs.intmask = 7; + regs.t0 = regs.t1 = 0; + if (!regs.s) { + regs.usp = m68k_areg (regs, 7); + if (currprefs.cpu_model >= 68020) + m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; + else + m68k_areg (regs, 7) = regs.isp; + regs.s = 1; + } + MakeSR (); + m68k_setpc (mmu_callback); + fill_prefetch_slow (); + + if (currprefs.cpu_model > 68000) { + for (i = 0 ; i < 9; i++) { + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), mmu_fault_addr); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); /* WB1S */ + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); /* WB2S */ + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); /* WB3S */ + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), + (mmu_fault_rw ? 0 : 0x100) | (mmu_fault_size << 5)); /* SSW */ + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), mmu_fault_bank_addr); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0x7002); } m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), mmu_fault_addr); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); /* WB1S */ - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); /* WB2S */ - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); /* WB3S */ - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), - (mmu_fault_rw ? 0 : 0x100) | (mmu_fault_size << 5)); /* SSW */ - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), mmu_fault_bank_addr); + put_long (m68k_areg (regs, 7), get_long (p - 4)); m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x7002); - } - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), get_long (p - 4)); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), mmur.sr); + put_word (m68k_areg (regs, 7), mmur.sr); - set_special(SPCFLAG_END_COMPILE); + set_special(SPCFLAG_END_COMPILE); } static void mmu_do_hit_pre (struct mmudata *md, uaecptr addr, int size, int rwi, uae_u32 v) { - uae_u32 p, pc; - int i; - - mmur = regs; - pc = m68k_getpc (); - if (mmu_logging) - console_out_f (L"MMU: hit %08X SZ=%d RW=%d V=%08X PC=%08X\n", addr, size, rwi, v, pc); - - p = mmu_regs; - put_long (p, 0); p += 4; - for (i = 0; i < 16; i++) { - put_long (p, regs.regs[i]); - p += 4; - } - put_long (p, pc); p += 4; - put_long (p, 0); p += 4; - put_long (p, regs.usp); p += 4; - put_long (p, regs.isp); p += 4; - put_long (p, regs.msp); p += 4; - put_word (p, regs.sr); p += 2; - put_word (p, (size << 1) | ((rwi & 2) ? 1 : 0)); /* size and rw */ p += 2; - put_long (p, addr); /* fault address */ p += 4; - put_long (p, md->p_addr); /* bank address */ p += 4; - put_long (p, v); p += 4; - mmu_fault_addr = addr; - mmu_fault_bank_addr = md->p_addr; - mmu_fault_size = size; - mmu_fault_rw = rwi; - mmu_triggered = 1; + uae_u32 p, pc; + int i; + + mmur = regs; + pc = m68k_getpc (); + if (mmu_logging) + console_out_f (L"MMU: hit %08X SZ=%d RW=%d V=%08X PC=%08X\n", addr, size, rwi, v, pc); + + p = mmu_regs; + put_long (p, 0); p += 4; + for (i = 0; i < 16; i++) { + put_long (p, regs.regs[i]); + p += 4; + } + put_long (p, pc); p += 4; + put_long (p, 0); p += 4; + put_long (p, regs.usp); p += 4; + put_long (p, regs.isp); p += 4; + put_long (p, regs.msp); p += 4; + put_word (p, regs.sr); p += 2; + put_word (p, (size << 1) | ((rwi & 2) ? 1 : 0)); /* size and rw */ p += 2; + put_long (p, addr); /* fault address */ p += 4; + put_long (p, md->p_addr); /* bank address */ p += 4; + put_long (p, v); p += 4; + mmu_fault_addr = addr; + mmu_fault_bank_addr = md->p_addr; + mmu_fault_size = size; + mmu_fault_rw = rwi; + mmu_triggered = 1; } static int mmu_hit (uaecptr addr, int size, int rwi, uae_u32 *v) { - int s, trig; - uae_u32 flags; - struct mmudata *md; - struct mmunode *mn; + int s, trig; + uae_u32 flags; + struct mmudata *md; + struct mmunode *mn; - if (mmu_triggered) - return 1; + if (mmu_triggered) + return 1; - mn = mmunl[addr >> MMU_PAGE_SHIFT]; - if (mn == NULL) - return 0; + mn = mmunl[addr >> MMU_PAGE_SHIFT]; + if (mn == NULL) + return 0; - s = regs.s; - while (mn) { - md = mn->mmubank; - if (addr >= md->addr && addr < md->addr + md->len) { - flags = md->flags; - if (flags & (MMU_MAP_READ_U | MMU_MAP_WRITE_U | MMU_MAP_READ_S | MMU_MAP_WRITE_S | MMU_MAP_READI_U | MMU_MAP_READI_S)) { - trig = 0; - if (!s && (flags & MMU_MAP_READ_U) && (rwi & 1)) - trig = 1; - if (!s && (flags & MMU_MAP_WRITE_U) && (rwi & 2)) - trig = 1; - if (s && (flags & MMU_MAP_READ_S) && (rwi & 1)) - trig = 1; - if (s && (flags & MMU_MAP_WRITE_S) && (rwi & 2)) - trig = 1; - if (!s && (flags & MMU_MAP_READI_U) && (rwi & 4)) - trig = 1; - if (s && (flags & MMU_MAP_READI_S) && (rwi & 4)) - trig = 1; - if (trig) { - uaecptr maddr = md->remap + (addr - md->addr); - if (maddr == addr) /* infinite mmu hit loop? no thanks.. */ - return 1; - if (mmu_logging) - console_out_f (L"MMU: remap %08X -> %08X SZ=%d RW=%d\n", addr, maddr, size, rwi); - if ((rwi & 2)) { - switch (size) - { - case 4: - put_long (maddr, *v); - break; - case 2: - put_word (maddr, *v); - break; - case 1: - put_byte (maddr, *v); - break; + s = regs.s; + while (mn) { + md = mn->mmubank; + if (addr >= md->addr && addr < md->addr + md->len) { + flags = md->flags; + if (flags & (MMU_MAP_READ_U | MMU_MAP_WRITE_U | MMU_MAP_READ_S | MMU_MAP_WRITE_S | MMU_MAP_READI_U | MMU_MAP_READI_S)) { + trig = 0; + if (!s && (flags & MMU_MAP_READ_U) && (rwi & 1)) + trig = 1; + if (!s && (flags & MMU_MAP_WRITE_U) && (rwi & 2)) + trig = 1; + if (s && (flags & MMU_MAP_READ_S) && (rwi & 1)) + trig = 1; + if (s && (flags & MMU_MAP_WRITE_S) && (rwi & 2)) + trig = 1; + if (!s && (flags & MMU_MAP_READI_U) && (rwi & 4)) + trig = 1; + if (s && (flags & MMU_MAP_READI_S) && (rwi & 4)) + trig = 1; + if (trig) { + uaecptr maddr = md->remap + (addr - md->addr); + if (maddr == addr) /* infinite mmu hit loop? no thanks.. */ + return 1; + if (mmu_logging) + console_out_f (L"MMU: remap %08X -> %08X SZ=%d RW=%d\n", addr, maddr, size, rwi); + if ((rwi & 2)) { + switch (size) + { + case 4: + put_long (maddr, *v); + break; + case 2: + put_word (maddr, *v); + break; + case 1: + put_byte (maddr, *v); + break; + } + } else { + switch (size) + { + case 4: + *v = get_long (maddr); + break; + case 2: + *v = get_word (maddr); + break; + case 1: + *v = get_byte (maddr); + break; + } + } + return 1; + } } - } else { - switch (size) - { - case 4: - *v = get_long (maddr); - break; - case 2: - *v = get_word (maddr); - break; - case 1: - *v = get_byte (maddr); - break; + if (flags & (MMU_READ_U | MMU_WRITE_U | MMU_READ_S | MMU_WRITE_S | MMU_READI_U | MMU_READI_S)) { + trig = 0; + if (!s && (flags & MMU_READ_U) && (rwi & 1)) + trig = 1; + if (!s && (flags & MMU_WRITE_U) && (rwi & 2)) + trig = 1; + if (s && (flags & MMU_READ_S) && (rwi & 1)) + trig = 1; + if (s && (flags & MMU_WRITE_S) && (rwi & 2)) + trig = 1; + if (!s && (flags & MMU_READI_U) && (rwi & 4)) + trig = 1; + if (s && (flags & MMU_READI_S) && (rwi & 4)) + trig = 1; + if (trig) { + mmu_do_hit_pre (md, addr, size, rwi, *v); + return 1; + } } - } - return 1; - } - } - if (flags & (MMU_READ_U | MMU_WRITE_U | MMU_READ_S | MMU_WRITE_S | MMU_READI_U | MMU_READI_S)) { - trig = 0; - if (!s && (flags & MMU_READ_U) && (rwi & 1)) - trig = 1; - if (!s && (flags & MMU_WRITE_U) && (rwi & 2)) - trig = 1; - if (s && (flags & MMU_READ_S) && (rwi & 1)) - trig = 1; - if (s && (flags & MMU_WRITE_S) && (rwi & 2)) - trig = 1; - if (!s && (flags & MMU_READI_U) && (rwi & 4)) - trig = 1; - if (s && (flags & MMU_READI_S) && (rwi & 4)) - trig = 1; - if (trig) { - mmu_do_hit_pre (md, addr, size, rwi, *v); - return 1; } - } + mn = mn->next; } - mn = mn->next; - } - return 0; + return 0; } static void mmu_free_node(struct mmunode *mn) { - if (!mn) - return; - mmu_free_node (mn->next); - xfree (mn); + if (!mn) + return; + mmu_free_node (mn->next); + xfree (mn); } static void mmu_free(void) { - struct mmunode *mn; - int i; + struct mmunode *mn; + int i; - for (i = 0; i < mmu_slots; i++) { - mn = mmunl[i]; - mmu_free_node (mn); - } - xfree (mmunl); - mmunl = NULL; - xfree (mmubanks); - mmubanks = NULL; + for (i = 0; i < mmu_slots; i++) { + mn = mmunl[i]; + mmu_free_node (mn); + } + xfree (mmunl); + mmunl = NULL; + xfree (mmubanks); + mmubanks = NULL; } static int getmmubank(struct mmudata *snptr, uaecptr p) { - snptr->flags = get_long (p); - if (snptr->flags == 0xffffffff) - return 1; - snptr->addr = get_long (p + 4); - snptr->len = get_long (p + 8); - snptr->remap = get_long (p + 12); - snptr->p_addr = p; - return 0; + snptr->flags = get_long (p); + if (snptr->flags == 0xffffffff) + return 1; + snptr->addr = get_long (p + 4); + snptr->len = get_long (p + 8); + snptr->remap = get_long (p + 12); + snptr->p_addr = p; + return 0; } int mmu_init(int mode, uaecptr parm, uaecptr parm2) { - uaecptr p, p2, banks; - int size; - struct mmudata *snptr; - struct mmunode *mn; - static int wasjit; - - if (currprefs.cachesize) { - wasjit = currprefs.cachesize; - changed_prefs.cachesize = 0; - console_out (L"MMU: JIT disabled\n"); - check_prefs_changed_comp (); - } - - if (mode == 0) { - if (mmu_enabled) { - mmu_free (); - deinitialize_memwatch (); - console_out (L"MMU: disabled\n"); - changed_prefs.cachesize = wasjit; - } - mmu_logging = 0; - return 1; - } - - if (mode == 1) { - if (!mmu_enabled) - return 0xffffffff; - return mmu_struct; - } - - p = parm; - mmu_struct = p; - if (get_long (p) != 1) { - console_out_f (L"MMU: version mismatch %d <> %d\n", get_long (p), 1); - return 0; - } - p += 4; - mmu_logging = get_long (p) & 1; - p += 4; - mmu_callback = get_long (p); - p += 4; - mmu_regs = get_long (p); - p += 4; - - if (mode == 3) { - int off; - uaecptr addr = get_long (parm2 + 4); - if (!mmu_enabled) - return 0; - off = addr >> MMU_PAGE_SHIFT; - mn = mmunl[off]; - while (mn) { - if (mn->mmubank->p_addr == parm2) { - getmmubank(mn->mmubank, parm2); - if (mmu_logging) - console_out_f (L"MMU: bank update %08X: %08X - %08X %08X\n", - mn->mmubank->flags, mn->mmubank->addr, mn->mmubank->len + mn->mmubank->addr, - mn->mmubank->remap); - } - mn = mn->next; + uaecptr p, p2, banks; + int size; + struct mmudata *snptr; + struct mmunode *mn; + static int wasjit; + + if (currprefs.cachesize) { + wasjit = currprefs.cachesize; + changed_prefs.cachesize = 0; + console_out (L"MMU: JIT disabled\n"); + check_prefs_changed_comp (); + } + + if (mode == 0) { + if (mmu_enabled) { + mmu_free (); + deinitialize_memwatch (); + console_out (L"MMU: disabled\n"); + changed_prefs.cachesize = wasjit; + } + mmu_logging = 0; + return 1; } - return 1; - } - - mmu_slots = 1 << ((currprefs.address_space_24 ? 24 : 32) - MMU_PAGE_SHIFT); - mmunl = xcalloc (sizeof (struct mmunode*) * mmu_slots, 1); - size = 1; - p2 = get_long (p); - while (get_long (p2) != 0xffffffff) { - p2 += 16; - size++; - } - p = banks = get_long (p); - snptr = mmubanks = xmalloc (sizeof (struct mmudata) * size); - for (;;) { - int off; - if (getmmubank(snptr, p)) - break; - p += 16; - off = snptr->addr >> MMU_PAGE_SHIFT; - if (mmunl[off] == NULL) { - mn = mmunl[off] = xcalloc (sizeof (struct mmunode), 1); - } else { - mn = mmunl[off]; - while (mn->next) - mn = mn->next; - mn = mn->next = xcalloc (sizeof (struct mmunode), 1); + + if (mode == 1) { + if (!mmu_enabled) + return 0xffffffff; + return mmu_struct; } - mn->mmubank = snptr; - snptr++; - } - initialize_memwatch (1); - console_out_f (L"MMU: enabled, %d banks, CB=%08X S=%08X BNK=%08X SF=%08X, %d*%d\n", - size - 1, mmu_callback, parm, banks, mmu_regs, mmu_slots, 1 << MMU_PAGE_SHIFT); - set_special (SPCFLAG_BRK); - return 1; + p = parm; + mmu_struct = p; + if (get_long (p) != 1) { + console_out_f (L"MMU: version mismatch %d <> %d\n", get_long (p), 1); + return 0; + } + p += 4; + mmu_logging = get_long (p) & 1; + p += 4; + mmu_callback = get_long (p); + p += 4; + mmu_regs = get_long (p); + p += 4; + + if (mode == 3) { + int off; + uaecptr addr = get_long (parm2 + 4); + if (!mmu_enabled) + return 0; + off = addr >> MMU_PAGE_SHIFT; + mn = mmunl[off]; + while (mn) { + if (mn->mmubank->p_addr == parm2) { + getmmubank(mn->mmubank, parm2); + if (mmu_logging) + console_out_f (L"MMU: bank update %08X: %08X - %08X %08X\n", + mn->mmubank->flags, mn->mmubank->addr, mn->mmubank->len + mn->mmubank->addr, + mn->mmubank->remap); + } + mn = mn->next; + } + return 1; + } + + mmu_slots = 1 << ((currprefs.address_space_24 ? 24 : 32) - MMU_PAGE_SHIFT); + mmunl = xcalloc (sizeof (struct mmunode*) * mmu_slots, 1); + size = 1; + p2 = get_long (p); + while (get_long (p2) != 0xffffffff) { + p2 += 16; + size++; + } + p = banks = get_long (p); + snptr = mmubanks = xmalloc (sizeof (struct mmudata) * size); + for (;;) { + int off; + if (getmmubank(snptr, p)) + break; + p += 16; + off = snptr->addr >> MMU_PAGE_SHIFT; + if (mmunl[off] == NULL) { + mn = mmunl[off] = xcalloc (sizeof (struct mmunode), 1); + } else { + mn = mmunl[off]; + while (mn->next) + mn = mn->next; + mn = mn->next = xcalloc (sizeof (struct mmunode), 1); + } + mn->mmubank = snptr; + snptr++; + } + + initialize_memwatch (1); + console_out_f (L"MMU: enabled, %d banks, CB=%08X S=%08X BNK=%08X SF=%08X, %d*%d\n", + size - 1, mmu_callback, parm, banks, mmu_regs, mmu_slots, 1 << MMU_PAGE_SHIFT); + set_special (SPCFLAG_BRK); + return 1; } diff --git a/disk.c b/disk.c index 6466c372..1950a724 100644 --- a/disk.c +++ b/disk.c @@ -1,15 +1,15 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Floppy disk emulation - * - * Copyright 1995 Hannu Rummukainen - * Copyright 1995-2001 Bernd Schmidt - * Copyright 2000-2003 Toni Wilen - * - * High Density Drive Handling by Dr. Adil Temel (C) 2001 [atemel1@hotmail.com] - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Floppy disk emulation +* +* Copyright 1995 Hannu Rummukainen +* Copyright 1995-2001 Bernd Schmidt +* Copyright 2000-2003 Toni Wilen +* +* High Density Drive Handling by Dr. Adil Temel (C) 2001 [atemel1@hotmail.com] +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -70,14 +70,14 @@ static int longwritemode = 0; #undef DEBUG_DRIVE_ID /* UAE-1ADF (ADF_EXT2) - * W reserved - * W number of tracks (default 2*80=160) - * - * W reserved - * W type, 0=normal AmigaDOS track, 1 = raw MFM - * L available space for track in bytes (must be even) - * L track length in bits - */ +* W reserved +* W number of tracks (default 2*80=160) +* +* W reserved +* W type, 0=normal AmigaDOS track, 1 = raw MFM +* L available space for track in bytes (must be even) +* L track length in bits +*/ static int side, direction; static uae_u8 selected = 15, disabled; @@ -107,26 +107,26 @@ static uae_u16 word, dsksync; static int disk_hpos; static int disk_jitter; -typedef enum { TRACK_AMIGADOS, TRACK_RAW, TRACK_RAW1, TRACK_PCDOS, TRACK_DISKSPARE } image_tracktype; +typedef enum { TRACK_AMIGADOS, TRACK_RAW, TRACK_RAW1, TRACK_PCDOS, TRACK_DISKSPARE, TRACK_NONE } image_tracktype; typedef struct { - uae_u16 len; - uae_u32 offs; - int bitlen, track; - unsigned int sync; - image_tracktype type; + uae_u16 len; + uae_u32 offs; + int bitlen, track; + unsigned int sync; + image_tracktype type; } trackid; #define MAX_TRACKS (2 * 83) /* We have three kinds of Amiga floppy drives - * - internal A500/A2000 drive: - * ID is always DRIVE_ID_NONE (S.T.A.G expects this) - * - HD drive (A3000/A4000): - * ID is DRIVE_ID_35DD if DD floppy is inserted or drive is empty - * ID is DRIVE_ID_35HD if HD floppy is inserted - * - regular external drive: - * ID is always DRIVE_ID_35DD - */ +* - internal A500/A2000 drive: +* ID is always DRIVE_ID_NONE (S.T.A.G expects this) +* - HD drive (A3000/A4000): +* ID is DRIVE_ID_35DD if DD floppy is inserted or drive is empty +* ID is DRIVE_ID_35HD if HD floppy is inserted +* - regular external drive: +* ID is always DRIVE_ID_35DD +*/ #define DRIVE_ID_NONE 0x00000000 #define DRIVE_ID_35DD 0xFFFFFFFF @@ -135,54 +135,54 @@ typedef struct { typedef enum { ADF_NORMAL, ADF_EXT1, ADF_EXT2, ADF_FDI, ADF_IPF, ADF_CATWEASEL, ADF_PCDOS } drive_filetype; typedef struct { - struct zfile *diskfile; - struct zfile *writediskfile; - drive_filetype filetype; - trackid trackdata[MAX_TRACKS]; - trackid writetrackdata[MAX_TRACKS]; - int buffered_cyl, buffered_side; - int cyl; - int motoroff; - int motordelay; /* dskrdy needs some clock cycles before it changes after switching off motor */ - int state; - int wrprot; - uae_u16 bigmfmbuf[0x4000 * DDHDMULT]; - uae_u16 tracktiming[0x4000 * DDHDMULT]; - int multi_revolution; - int skipoffset; - int mfmpos; - int indexoffset; - int tracklen; - int prevtracklen; - int trackspeed; - int dmalen; - int num_tracks, write_num_tracks, num_secs; - int hard_num_cyls; - int dskchange; - int dskchange_time; - int dskready; - int dskready_time; - int dskready_down_time; - int writtento; - int steplimit; - frame_time_t steplimitcycle; - int indexhack, indexhackmode; - int ddhd; /* 1=DD 2=HD */ - int drive_id_scnt; /* drive id shift counter */ - int idbit; - unsigned long drive_id; /* drive id to be reported */ - TCHAR newname[256]; /* storage space for new filename during eject delay */ - uae_u32 crc32; + struct zfile *diskfile; + struct zfile *writediskfile; + drive_filetype filetype; + trackid trackdata[MAX_TRACKS]; + trackid writetrackdata[MAX_TRACKS]; + int buffered_cyl, buffered_side; + int cyl; + int motoroff; + int motordelay; /* dskrdy needs some clock cycles before it changes after switching off motor */ + int state; + int wrprot; + uae_u16 bigmfmbuf[0x4000 * DDHDMULT]; + uae_u16 tracktiming[0x4000 * DDHDMULT]; + int multi_revolution; + int skipoffset; + int mfmpos; + int indexoffset; + int tracklen; + int prevtracklen; + int trackspeed; + int dmalen; + int num_tracks, write_num_tracks, num_secs; + int hard_num_cyls; + int dskchange; + int dskchange_time; + int dskready; + int dskready_time; + int dskready_down_time; + int writtento; + int steplimit; + frame_time_t steplimitcycle; + int indexhack, indexhackmode; + int ddhd; /* 1=DD 2=HD */ + int drive_id_scnt; /* drive id shift counter */ + int idbit; + unsigned long drive_id; /* drive id to be reported */ + TCHAR newname[256]; /* storage space for new filename during eject delay */ + uae_u32 crc32; #ifdef FDI2RAW - FDI *fdi; + FDI *fdi; #endif - int useturbo; - int floppybitcounter; /* number of bits left */ + int useturbo; + int floppybitcounter; /* number of bits left */ #ifdef CATWEASEL - catweasel_drive *catweasel; + catweasel_drive *catweasel; #else - int catweasel; - int amax; + int catweasel; + int amax; #endif } drive; @@ -198,10 +198,10 @@ static TCHAR dfxhistory[MAX_PREVIOUS_FLOPPIES][MAX_DPATH]; static uae_u8 exeheader[]={0x00,0x00,0x03,0xf3,0x00,0x00,0x00,0x00}; static uae_u8 bootblock[]={ - 0x44,0x4f,0x53,0x00,0xc0,0x20,0x0f,0x19,0x00,0x00,0x03,0x70,0x43,0xfa,0x00,0x18, - 0x4e,0xae,0xff,0xa0,0x4a,0x80,0x67,0x0a,0x20,0x40,0x20,0x68,0x00,0x16,0x70,0x00, - 0x4e,0x75,0x70,0xff,0x60,0xfa,0x64,0x6f,0x73,0x2e,0x6c,0x69,0x62,0x72,0x61,0x72, - 0x79 + 0x44,0x4f,0x53,0x00,0xc0,0x20,0x0f,0x19,0x00,0x00,0x03,0x70,0x43,0xfa,0x00,0x18, + 0x4e,0xae,0xff,0xa0,0x4a,0x80,0x67,0x0a,0x20,0x40,0x20,0x68,0x00,0x16,0x70,0x00, + 0x4e,0x75,0x70,0xff,0x60,0xfa,0x64,0x6f,0x73,0x2e,0x6c,0x69,0x62,0x72,0x61,0x72, + 0x79 }; #define FS_OFS_DATABLOCKSIZE 488 @@ -212,2353 +212,2381 @@ static uae_u8 bootblock[]={ static void writeimageblock (struct zfile *dst, uae_u8 *sector, int offset) { - zfile_fseek (dst, offset, SEEK_SET); - zfile_fwrite (sector, FS_FLOPPY_BLOCKSIZE, 1, dst); + zfile_fseek (dst, offset, SEEK_SET); + zfile_fwrite (sector, FS_FLOPPY_BLOCKSIZE, 1, dst); } static void disk_checksum(uae_u8 *p, uae_u8 *c) { - uae_u32 cs = 0; - int i; - for (i = 0; i < FS_FLOPPY_BLOCKSIZE; i+= 4) - cs += (p[i] << 24) | (p[i+1] << 16) | (p[i+2] << 8) | (p[i+3] << 0); - cs = -cs; - c[0] = cs >> 24; c[1] = cs >> 16; c[2] = cs >> 8; c[3] = cs >> 0; + uae_u32 cs = 0; + int i; + for (i = 0; i < FS_FLOPPY_BLOCKSIZE; i+= 4) + cs += (p[i] << 24) | (p[i+1] << 16) | (p[i+2] << 8) | (p[i+3] << 0); + cs = -cs; + c[0] = cs >> 24; c[1] = cs >> 16; c[2] = cs >> 8; c[3] = cs >> 0; } static int dirhash (const uae_char *name) { - unsigned long hash; - int i; + unsigned long hash; + int i; - hash = strlen (name); - for(i = 0; i < strlen (name); i++) { - hash = hash * 13; - hash = hash + toupper (name[i]); - hash = hash & 0x7ff; - } - hash = hash % ((FS_FLOPPY_BLOCKSIZE / 4) - 56); - return hash; + hash = strlen (name); + for(i = 0; i < strlen (name); i++) { + hash = hash * 13; + hash = hash + toupper (name[i]); + hash = hash & 0x7ff; + } + hash = hash % ((FS_FLOPPY_BLOCKSIZE / 4) - 56); + return hash; } static void disk_date (uae_u8 *p) { - time_t t; - struct tm *today; - int year, days, minutes, ticks; - TCHAR tmp[10]; - - time (&t); - today = localtime( &t ); - _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%Y", today); - year = _tstoi (tmp); - _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%j", today); - days = _tstoi (tmp) - 1; - _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%H", today); - minutes = _tstoi (tmp) * 60; - _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%M", today); - minutes += _tstoi (tmp); - _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%S", today); - ticks = _tstoi (tmp) * 50; - while (year > 1978) { - if ( !(year % 100) ? !(year % 400) : !(year % 4) ) days++; - days += 365; - year--; - } - p[0] = days >> 24; p[1] = days >> 16; p[2] = days >> 8; p[3] = days >> 0; - p[4] = minutes >> 24; p[5] = minutes >> 16; p[6] = minutes >> 8; p[7] = minutes >> 0; - p[8] = ticks >> 24; p[9] = ticks >> 16; p[10] = ticks >> 8; p[11] = ticks >> 0; + time_t t; + struct tm *today; + int year, days, minutes, ticks; + TCHAR tmp[10]; + + time (&t); + today = localtime( &t ); + _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%Y", today); + year = _tstoi (tmp); + _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%j", today); + days = _tstoi (tmp) - 1; + _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%H", today); + minutes = _tstoi (tmp) * 60; + _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%M", today); + minutes += _tstoi (tmp); + _tcsftime (tmp, sizeof (tmp) / sizeof (TCHAR), L"%S", today); + ticks = _tstoi (tmp) * 50; + while (year > 1978) { + if ( !(year % 100) ? !(year % 400) : !(year % 4) ) days++; + days += 365; + year--; + } + p[0] = days >> 24; p[1] = days >> 16; p[2] = days >> 8; p[3] = days >> 0; + p[4] = minutes >> 24; p[5] = minutes >> 16; p[6] = minutes >> 8; p[7] = minutes >> 0; + p[8] = ticks >> 24; p[9] = ticks >> 16; p[10] = ticks >> 8; p[11] = ticks >> 0; } static void createbootblock (uae_u8 *sector, int bootable) { - memset (sector, 0, FS_FLOPPY_BLOCKSIZE); - memcpy (sector, "DOS", 3); - if (bootable) - memcpy (sector, bootblock, sizeof (bootblock)); + memset (sector, 0, FS_FLOPPY_BLOCKSIZE); + memcpy (sector, "DOS", 3); + if (bootable) + memcpy (sector, bootblock, sizeof (bootblock)); } static void createrootblock (uae_u8 *sector, uae_u8 *disk_name) { - memset (sector, 0, FS_FLOPPY_BLOCKSIZE); - sector[0+3] = 2; - sector[12+3] = 0x48; - sector[312] = sector[313] = sector[314] = sector[315] = (uae_u8)0xff; - sector[316+2] = 881 >> 8; sector[316+3] = 881 & 255; - sector[432] = strlen (disk_name); - strcpy (sector + 433, disk_name); - sector[508 + 3] = 1; - disk_date (sector + 420); - memcpy (sector + 472, sector + 420, 3 * 4); - memcpy (sector + 484, sector + 420, 3 * 4); + memset (sector, 0, FS_FLOPPY_BLOCKSIZE); + sector[0+3] = 2; + sector[12+3] = 0x48; + sector[312] = sector[313] = sector[314] = sector[315] = (uae_u8)0xff; + sector[316+2] = 881 >> 8; sector[316+3] = 881 & 255; + sector[432] = strlen (disk_name); + strcpy (sector + 433, disk_name); + sector[508 + 3] = 1; + disk_date (sector + 420); + memcpy (sector + 472, sector + 420, 3 * 4); + memcpy (sector + 484, sector + 420, 3 * 4); } static int getblock (uae_u8 *bitmap) { - int i = 0; - while (bitmap[i] != 0xff) { - if (bitmap[i] == 0) { - bitmap[i] = 1; - return i; + int i = 0; + while (bitmap[i] != 0xff) { + if (bitmap[i] == 0) { + bitmap[i] = 1; + return i; + } + i++; } - i++; - } - return -1; + return -1; } static void pl (uae_u8 *sector, int offset, uae_u32 v) { - sector[offset + 0] = v >> 24; - sector[offset + 1] = v >> 16; - sector[offset + 2] = v >> 8; - sector[offset + 3] = v >> 0; + sector[offset + 0] = v >> 24; + sector[offset + 1] = v >> 16; + sector[offset + 2] = v >> 8; + sector[offset + 3] = v >> 0; } static int createdirheaderblock (uae_u8 *sector, int parent, const char *filename, uae_u8 *bitmap) { - int block = getblock (bitmap); + int block = getblock (bitmap); - memset (sector, 0, FS_FLOPPY_BLOCKSIZE); - pl (sector, 0, 2); - pl (sector, 4, block); - disk_date (sector + 512 - 92); - sector[512 - 80] = strlen (filename); - strcpy (sector + 512 - 79, filename); - pl (sector, 512 - 12, parent); - pl (sector, 512 - 4, 2); - return block; + memset (sector, 0, FS_FLOPPY_BLOCKSIZE); + pl (sector, 0, 2); + pl (sector, 4, block); + disk_date (sector + 512 - 92); + sector[512 - 80] = strlen (filename); + strcpy (sector + 512 - 79, filename); + pl (sector, 512 - 12, parent); + pl (sector, 512 - 4, 2); + return block; } static int createfileheaderblock (struct zfile *z,uae_u8 *sector, int parent, const char *filename, struct zfile *src, uae_u8 *bitmap) { - uae_u8 sector2[FS_FLOPPY_BLOCKSIZE]; - uae_u8 sector3[FS_FLOPPY_BLOCKSIZE]; - int block = getblock (bitmap); - int datablock = getblock (bitmap); - int datasec = 1; - int extensions; - int extensionblock, extensioncounter, headerextension = 1; - int size; - - zfile_fseek (src, 0, SEEK_END); - size = zfile_ftell (src); - zfile_fseek (src, 0, SEEK_SET); - extensions = (size + FS_OFS_DATABLOCKSIZE - 1) / FS_OFS_DATABLOCKSIZE; - - memset (sector, 0, FS_FLOPPY_BLOCKSIZE); - pl (sector, 0, 2); - pl (sector, 4, block); - pl (sector, 8, extensions > FS_EXTENSION_BLOCKS ? FS_EXTENSION_BLOCKS : extensions); - pl (sector, 16, datablock); - pl (sector, FS_FLOPPY_BLOCKSIZE - 188, size); - disk_date (sector + FS_FLOPPY_BLOCKSIZE - 92); - sector[FS_FLOPPY_BLOCKSIZE - 80] = strlen (filename); - strcpy (sector + FS_FLOPPY_BLOCKSIZE - 79, filename); - pl (sector, FS_FLOPPY_BLOCKSIZE - 12, parent); - pl (sector, FS_FLOPPY_BLOCKSIZE - 4, -3); - extensioncounter = 0; - extensionblock = 0; - - while (size > 0) { - int datablock2 = datablock; - int extensionblock2 = extensionblock; - if (extensioncounter == FS_EXTENSION_BLOCKS) { - extensioncounter = 0; - extensionblock = getblock (bitmap); - if (datasec > FS_EXTENSION_BLOCKS + 1) { - pl (sector3, 8, FS_EXTENSION_BLOCKS); - pl (sector3, FS_FLOPPY_BLOCKSIZE - 8, extensionblock); - pl (sector3, 4, extensionblock2); + uae_u8 sector2[FS_FLOPPY_BLOCKSIZE]; + uae_u8 sector3[FS_FLOPPY_BLOCKSIZE]; + int block = getblock (bitmap); + int datablock = getblock (bitmap); + int datasec = 1; + int extensions; + int extensionblock, extensioncounter, headerextension = 1; + int size; + + zfile_fseek (src, 0, SEEK_END); + size = zfile_ftell (src); + zfile_fseek (src, 0, SEEK_SET); + extensions = (size + FS_OFS_DATABLOCKSIZE - 1) / FS_OFS_DATABLOCKSIZE; + + memset (sector, 0, FS_FLOPPY_BLOCKSIZE); + pl (sector, 0, 2); + pl (sector, 4, block); + pl (sector, 8, extensions > FS_EXTENSION_BLOCKS ? FS_EXTENSION_BLOCKS : extensions); + pl (sector, 16, datablock); + pl (sector, FS_FLOPPY_BLOCKSIZE - 188, size); + disk_date (sector + FS_FLOPPY_BLOCKSIZE - 92); + sector[FS_FLOPPY_BLOCKSIZE - 80] = strlen (filename); + strcpy (sector + FS_FLOPPY_BLOCKSIZE - 79, filename); + pl (sector, FS_FLOPPY_BLOCKSIZE - 12, parent); + pl (sector, FS_FLOPPY_BLOCKSIZE - 4, -3); + extensioncounter = 0; + extensionblock = 0; + + while (size > 0) { + int datablock2 = datablock; + int extensionblock2 = extensionblock; + if (extensioncounter == FS_EXTENSION_BLOCKS) { + extensioncounter = 0; + extensionblock = getblock (bitmap); + if (datasec > FS_EXTENSION_BLOCKS + 1) { + pl (sector3, 8, FS_EXTENSION_BLOCKS); + pl (sector3, FS_FLOPPY_BLOCKSIZE - 8, extensionblock); + pl (sector3, 4, extensionblock2); + disk_checksum(sector3, sector3 + 20); + writeimageblock (z, sector3, extensionblock2 * FS_FLOPPY_BLOCKSIZE); + } else { + pl (sector, 512 - 8, extensionblock); + } + memset (sector3, 0, FS_FLOPPY_BLOCKSIZE); + pl (sector3, 0, 16); + pl (sector3, FS_FLOPPY_BLOCKSIZE - 12, block); + pl (sector3, FS_FLOPPY_BLOCKSIZE - 4, -3); + } + memset (sector2, 0, FS_FLOPPY_BLOCKSIZE); + pl (sector2, 0, 8); + pl (sector2, 4, block); + pl (sector2, 8, datasec++); + pl (sector2, 12, size > FS_OFS_DATABLOCKSIZE ? FS_OFS_DATABLOCKSIZE : size); + zfile_fread (sector2 + 24, size > FS_OFS_DATABLOCKSIZE ? FS_OFS_DATABLOCKSIZE : size, 1, src); + size -= FS_OFS_DATABLOCKSIZE; + datablock = 0; + if (size > 0) datablock = getblock (bitmap); + pl (sector2, 16, datablock); + disk_checksum(sector2, sector2 + 20); + writeimageblock (z, sector2, datablock2 * FS_FLOPPY_BLOCKSIZE); + if (datasec <= FS_EXTENSION_BLOCKS + 1) + pl (sector, 512 - 204 - extensioncounter * 4, datablock2); + else + pl (sector3, 512 - 204 - extensioncounter * 4, datablock2); + extensioncounter++; + } + if (datasec > FS_EXTENSION_BLOCKS) { + pl (sector3, 8, extensioncounter); disk_checksum(sector3, sector3 + 20); - writeimageblock (z, sector3, extensionblock2 * FS_FLOPPY_BLOCKSIZE); - } else { - pl (sector, 512 - 8, extensionblock); - } - memset (sector3, 0, FS_FLOPPY_BLOCKSIZE); - pl (sector3, 0, 16); - pl (sector3, FS_FLOPPY_BLOCKSIZE - 12, block); - pl (sector3, FS_FLOPPY_BLOCKSIZE - 4, -3); - } - memset (sector2, 0, FS_FLOPPY_BLOCKSIZE); - pl (sector2, 0, 8); - pl (sector2, 4, block); - pl (sector2, 8, datasec++); - pl (sector2, 12, size > FS_OFS_DATABLOCKSIZE ? FS_OFS_DATABLOCKSIZE : size); - zfile_fread (sector2 + 24, size > FS_OFS_DATABLOCKSIZE ? FS_OFS_DATABLOCKSIZE : size, 1, src); - size -= FS_OFS_DATABLOCKSIZE; - datablock = 0; - if (size > 0) datablock = getblock (bitmap); - pl (sector2, 16, datablock); - disk_checksum(sector2, sector2 + 20); - writeimageblock (z, sector2, datablock2 * FS_FLOPPY_BLOCKSIZE); - if (datasec <= FS_EXTENSION_BLOCKS + 1) - pl (sector, 512 - 204 - extensioncounter * 4, datablock2); - else - pl (sector3, 512 - 204 - extensioncounter * 4, datablock2); - extensioncounter++; - } - if (datasec > FS_EXTENSION_BLOCKS) { - pl (sector3, 8, extensioncounter); - disk_checksum(sector3, sector3 + 20); - writeimageblock (z, sector3, extensionblock * FS_FLOPPY_BLOCKSIZE); - } - disk_checksum(sector, sector + 20); - writeimageblock (z, sector, block * FS_FLOPPY_BLOCKSIZE); - return block; + writeimageblock (z, sector3, extensionblock * FS_FLOPPY_BLOCKSIZE); + } + disk_checksum(sector, sector + 20); + writeimageblock (z, sector, block * FS_FLOPPY_BLOCKSIZE); + return block; } static void createbitmapblock (uae_u8 *sector, uae_u8 *bitmap) { - uae_u8 mask; - int i, j; - memset (sector, 0, FS_FLOPPY_BLOCKSIZE); - for (i = FS_FLOPPY_RESERVED; i < FS_FLOPPY_TOTALBLOCKS; i += 8) { - mask = 0; - for (j = 0; j < 8; j++) { - if (bitmap[i + j]) mask |= 1 << j; + uae_u8 mask; + int i, j; + memset (sector, 0, FS_FLOPPY_BLOCKSIZE); + for (i = FS_FLOPPY_RESERVED; i < FS_FLOPPY_TOTALBLOCKS; i += 8) { + mask = 0; + for (j = 0; j < 8; j++) { + if (bitmap[i + j]) mask |= 1 << j; + } + sector[4 + i / 8] = mask; } - sector[4 + i / 8] = mask; - } - disk_checksum(sector, sector + 0); + disk_checksum(sector, sector + 0); } static int createimagefromexe (struct zfile *src, struct zfile *dst) { - uae_u8 sector1[FS_FLOPPY_BLOCKSIZE], sector2[FS_FLOPPY_BLOCKSIZE]; - uae_u8 bitmap[FS_FLOPPY_TOTALBLOCKS + 8]; - int exesize; - int blocksize = FS_OFS_DATABLOCKSIZE; - int blocks, extensionblocks; - int totalblocks; - int fblock1, dblock1; - char *fname1 = "runme.exe"; - TCHAR *fname1b = L"runme.adf"; - char *fname2 = "startup-sequence"; - char *dirname1 = "s"; - struct zfile *ss; - - memset (bitmap, 0, sizeof (bitmap)); - zfile_fseek (src, 0, SEEK_END); - exesize = zfile_ftell (src); - blocks = (exesize + blocksize - 1) / blocksize; - extensionblocks = (blocks + FS_EXTENSION_BLOCKS - 1) / FS_EXTENSION_BLOCKS; - /* bootblock=2, root=1, bitmap=1, startup-sequence=1+1, exefileheader=1 */ - totalblocks = 2 + 1 + 1 + 2 + 1 + blocks + extensionblocks; - if (totalblocks > FS_FLOPPY_TOTALBLOCKS) - return 0; - - bitmap[880] = 1; - bitmap[881] = 1; - bitmap[0] = 1; - bitmap[1] = 1; + uae_u8 sector1[FS_FLOPPY_BLOCKSIZE], sector2[FS_FLOPPY_BLOCKSIZE]; + uae_u8 bitmap[FS_FLOPPY_TOTALBLOCKS + 8]; + int exesize; + int blocksize = FS_OFS_DATABLOCKSIZE; + int blocks, extensionblocks; + int totalblocks; + int fblock1, dblock1; + char *fname1 = "runme.exe"; + TCHAR *fname1b = L"runme.adf"; + char *fname2 = "startup-sequence"; + char *dirname1 = "s"; + struct zfile *ss; + + memset (bitmap, 0, sizeof (bitmap)); + zfile_fseek (src, 0, SEEK_END); + exesize = zfile_ftell (src); + blocks = (exesize + blocksize - 1) / blocksize; + extensionblocks = (blocks + FS_EXTENSION_BLOCKS - 1) / FS_EXTENSION_BLOCKS; + /* bootblock=2, root=1, bitmap=1, startup-sequence=1+1, exefileheader=1 */ + totalblocks = 2 + 1 + 1 + 2 + 1 + blocks + extensionblocks; + if (totalblocks > FS_FLOPPY_TOTALBLOCKS) + return 0; - dblock1 = createdirheaderblock (sector2, 880, dirname1, bitmap); - ss = zfile_fopen_empty (src, fname1b, strlen (fname1)); - zfile_fwrite (fname1, strlen(fname1), 1, ss); - fblock1 = createfileheaderblock (dst, sector1, dblock1, fname2, ss, bitmap); - zfile_fclose (ss); - pl (sector2, 24 + dirhash (fname2) * 4, fblock1); - disk_checksum(sector2, sector2 + 20); - writeimageblock (dst, sector2, dblock1 * FS_FLOPPY_BLOCKSIZE); + bitmap[880] = 1; + bitmap[881] = 1; + bitmap[0] = 1; + bitmap[1] = 1; + + dblock1 = createdirheaderblock (sector2, 880, dirname1, bitmap); + ss = zfile_fopen_empty (src, fname1b, strlen (fname1)); + zfile_fwrite (fname1, strlen(fname1), 1, ss); + fblock1 = createfileheaderblock (dst, sector1, dblock1, fname2, ss, bitmap); + zfile_fclose (ss); + pl (sector2, 24 + dirhash (fname2) * 4, fblock1); + disk_checksum(sector2, sector2 + 20); + writeimageblock (dst, sector2, dblock1 * FS_FLOPPY_BLOCKSIZE); - fblock1 = createfileheaderblock (dst, sector1, 880, fname1, src, bitmap); + fblock1 = createfileheaderblock (dst, sector1, 880, fname1, src, bitmap); - createrootblock (sector1, "empty"); - pl (sector1, 24 + dirhash (fname1) * 4, fblock1); - pl (sector1, 24 + dirhash (dirname1) * 4, dblock1); - disk_checksum(sector1, sector1 + 20); - writeimageblock (dst, sector1, 880 * FS_FLOPPY_BLOCKSIZE); + createrootblock (sector1, "empty"); + pl (sector1, 24 + dirhash (fname1) * 4, fblock1); + pl (sector1, 24 + dirhash (dirname1) * 4, dblock1); + disk_checksum(sector1, sector1 + 20); + writeimageblock (dst, sector1, 880 * FS_FLOPPY_BLOCKSIZE); - createbitmapblock (sector1, bitmap); - writeimageblock (dst, sector1, 881 * FS_FLOPPY_BLOCKSIZE); + createbitmapblock (sector1, bitmap); + writeimageblock (dst, sector1, 881 * FS_FLOPPY_BLOCKSIZE); - createbootblock (sector1, 1); - writeimageblock (dst, sector1, 0 * FS_FLOPPY_BLOCKSIZE); + createbootblock (sector1, 1); + writeimageblock (dst, sector1, 0 * FS_FLOPPY_BLOCKSIZE); - return 1; + return 1; } static int get_floppy_speed (void) { - int m = currprefs.floppy_speed; - if (m <= 10) - m = 100; - m = NORMAL_FLOPPY_SPEED * 100 / m; - return m; + int m = currprefs.floppy_speed; + if (m <= 10) + m = 100; + m = NORMAL_FLOPPY_SPEED * 100 / m; + return m; } static int get_floppy_speed2 (drive *drv) { - int m = get_floppy_speed () * drv->tracklen / (2 * 8 * FLOPPY_WRITE_LEN * drv->ddhd); - if (m <= 0) - m = 1; - return m; + int m = get_floppy_speed () * drv->tracklen / (2 * 8 * FLOPPY_WRITE_LEN * drv->ddhd); + if (m <= 0) + m = 1; + return m; } static TCHAR *drive_id_name(drive *drv) { - switch(drv->drive_id) - { - case DRIVE_ID_35HD : return L"3.5HD"; - case DRIVE_ID_525SD: return L"5.25SD"; - case DRIVE_ID_35DD : return L"3.5DD"; - case DRIVE_ID_NONE : return L"NONE"; - } - return L"UNKNOWN"; + switch(drv->drive_id) + { + case DRIVE_ID_35HD : return L"3.5HD"; + case DRIVE_ID_525SD: return L"5.25SD"; + case DRIVE_ID_35DD : return L"3.5DD"; + case DRIVE_ID_NONE : return L"NONE"; + } + return L"UNKNOWN"; } /* Simulate exact behaviour of an A3000T 3.5 HD disk drive. - * The drive reports to be a 3.5 DD drive whenever there is no - * disk or a 3.5 DD disk is inserted. Only 3.5 HD drive id is reported - * when a real 3.5 HD disk is inserted. -Adil - */ +* The drive reports to be a 3.5 DD drive whenever there is no +* disk or a 3.5 DD disk is inserted. Only 3.5 HD drive id is reported +* when a real 3.5 HD disk is inserted. -Adil +*/ static void drive_settype_id (drive *drv) { - int t = currprefs.dfxtype[drv - &floppy[0]]; + int t = currprefs.dfxtype[drv - &floppy[0]]; - switch (t) - { + switch (t) + { case DRV_35_HD: #ifdef FLOPPY_DRIVE_HD - if (!drv->diskfile || drv->ddhd <= 1) - drv->drive_id = DRIVE_ID_35DD; - else - drv->drive_id = DRIVE_ID_35HD; + if (!drv->diskfile || drv->ddhd <= 1) + drv->drive_id = DRIVE_ID_35DD; + else + drv->drive_id = DRIVE_ID_35HD; #else - drv->drive_id = DRIVE_ID_35DD; + drv->drive_id = DRIVE_ID_35DD; #endif - break; + break; case DRV_35_DD_ESCOM: case DRV_35_DD: default: - drv->drive_id = DRIVE_ID_35DD; - break; + drv->drive_id = DRIVE_ID_35DD; + break; case DRV_525_SD: - drv->drive_id = DRIVE_ID_525SD; - break; + drv->drive_id = DRIVE_ID_525SD; + break; case DRV_NONE: - drv->drive_id = DRIVE_ID_NONE; - break; - } + drv->drive_id = DRIVE_ID_NONE; + break; + } #ifdef DEBUG_DRIVE_ID - write_log (L"drive_settype_id: DF%d: set to %s\n", drv-floppy, drive_id_name(drv)); + write_log (L"drive_settype_id: DF%d: set to %s\n", drv-floppy, drive_id_name(drv)); #endif } static void drive_image_free (drive *drv) { - switch (drv->filetype) - { + switch (drv->filetype) + { case ADF_IPF: #ifdef CAPS - caps_unloadimage (drv - floppy); + caps_unloadimage (drv - floppy); #endif - break; + break; case ADF_FDI: #ifdef FDI2RAW - fdi2raw_header_free (drv->fdi); - drv->fdi = 0; + fdi2raw_header_free (drv->fdi); + drv->fdi = 0; #endif - break; - } - drv->filetype = -1; - zfile_fclose (drv->diskfile); - drv->diskfile = 0; - zfile_fclose (drv->writediskfile); - drv->writediskfile = 0; + break; + } + drv->filetype = -1; + zfile_fclose (drv->diskfile); + drv->diskfile = 0; + zfile_fclose (drv->writediskfile); + drv->writediskfile = 0; } static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR *fname); -static void reset_drive_gui(int i) +static void reset_drive_gui (int i) { - gui_data.drive_disabled[i] = 0; - gui_data.df[i][0] = 0; - gui_data.crc32[i] = 0; - if (currprefs.dfxtype[i] < 0) - gui_data.drive_disabled[i] = 1; + gui_data.drive_disabled[i] = 0; + gui_data.df[i][0] = 0; + gui_data.crc32[i] = 0; + if (currprefs.dfxtype[i] < 0) + gui_data.drive_disabled[i] = 1; } -static void setamax(void) +static void setamax (void) { #ifdef AMAX - if (currprefs.amaxromfile[0]) { - /* Put A-Max as last drive in drive chain */ - int j; - for (j = 0; j < MAX_FLOPPY_DRIVES; j++) - if (floppy[j].amax) - return; - for (j = 0; j < MAX_FLOPPY_DRIVES; j++) { - if ((1 << j) & disabled) { - floppy[j].amax = 1; - write_log (L"AMAX: drive %d\n", j); - return; - } + if (currprefs.amaxromfile[0]) { + /* Put A-Max as last drive in drive chain */ + int j; + for (j = 0; j < MAX_FLOPPY_DRIVES; j++) + if (floppy[j].amax) + return; + for (j = 0; j < MAX_FLOPPY_DRIVES; j++) { + if ((1 << j) & disabled) { + floppy[j].amax = 1; + write_log (L"AMAX: drive %d\n", j); + return; + } + } } - } #endif } static void reset_drive(int i) { - drive *drv = &floppy[i]; - - drv->amax = 0; - drive_image_free (drv); - drv->motoroff = 1; - disabled &= ~(1 << i); - if (currprefs.dfxtype[i] < 0) - disabled |= 1 << i; - reset_drive_gui(i); - /* most internal Amiga floppy drives won't enable - * diskready until motor is running at full speed - * and next indexsync has been passed - */ - drv->indexhackmode = 0; - if (i == 0 && currprefs.dfxtype[i] == 0) - drv->indexhackmode = 1; - drv->dskchange_time = 0; - drv->buffered_cyl = -1; - drv->buffered_side = -1; - gui_led (i + 1, 0); - drive_settype_id (drv); - _tcscpy (currprefs.df[i], changed_prefs.df[i]); - drv->newname[0] = 0; - if (!drive_insert (drv, &currprefs, i, currprefs.df[i])) - disk_eject (i); + drive *drv = &floppy[i]; + + drv->amax = 0; + drive_image_free (drv); + drv->motoroff = 1; + disabled &= ~(1 << i); + if (currprefs.dfxtype[i] < 0) + disabled |= 1 << i; + reset_drive_gui(i); + /* most internal Amiga floppy drives won't enable + * diskready until motor is running at full speed + * and next indexsync has been passed + */ + drv->indexhackmode = 0; + if (i == 0 && currprefs.dfxtype[i] == 0) + drv->indexhackmode = 1; + drv->dskchange_time = 0; + drv->buffered_cyl = -1; + drv->buffered_side = -1; + gui_led (i + 1, 0); + drive_settype_id (drv); + _tcscpy (currprefs.df[i], changed_prefs.df[i]); + drv->newname[0] = 0; + if (!drive_insert (drv, &currprefs, i, currprefs.df[i])) + disk_eject (i); } /* code for track display */ static void update_drive_gui (int num) { - drive *drv = floppy + num; - int writ = dskdmaen == 3 && drv->state && !(selected & (1 << num)); + drive *drv = floppy + num; + int writ = dskdmaen == 3 && drv->state && !(selected & (1 << num)); - if (drv->state == gui_data.drive_motor[num] + if (drv->state == gui_data.drive_motor[num] && drv->cyl == gui_data.drive_track[num] && side == gui_data.drive_side - && drv->crc32 == gui_data.crc32[num] - && writ == gui_data.drive_writing[num]) - return; - _tcscpy (gui_data.df[num], currprefs.df[num]); - gui_data.crc32[num] = drv->crc32; - gui_data.drive_motor[num] = drv->state; - gui_data.drive_track[num] = drv->cyl; - gui_data.drive_side = side; - gui_data.drive_writing[num] = writ; - gui_led (num + 1, gui_data.drive_motor[num]); + && drv->crc32 == gui_data.crc32[num] + && writ == gui_data.drive_writing[num] + && !_tcscmp (gui_data.df[num], currprefs.df[num])) + return; + _tcscpy (gui_data.df[num], currprefs.df[num]); + gui_data.crc32[num] = drv->crc32; + gui_data.drive_motor[num] = drv->state; + gui_data.drive_track[num] = drv->cyl; + gui_data.drive_side = side; + gui_data.drive_writing[num] = writ; + gui_led (num + 1, gui_data.drive_motor[num]); } static void drive_fill_bigbuf (drive * drv,int); struct zfile *DISK_validate_filename (const TCHAR *fname, int leave_open, int *wrprot, uae_u32 *crc32) { - if (crc32) - *crc32 = 0; - if (leave_open) { - struct zfile *f = zfile_fopen (fname, L"r+b", ZFD_NORMAL | ZFD_DISKHISTORY); - if (f) { - if (wrprot) - *wrprot = 0; - } else { - if (wrprot) - *wrprot = 1; - f = zfile_fopen (fname, L"rb", ZFD_NORMAL | ZFD_DISKHISTORY); - } - if (f && crc32) - *crc32 = zfile_crc32 (f); - return f; - } else { - if (zfile_exists (fname)) { - if (wrprot) - *wrprot = 0; - if (crc32) { - struct zfile *f = zfile_fopen (fname, L"rb", ZFD_NORMAL | ZFD_DISKHISTORY); - if (f) - *crc32 = zfile_crc32 (f); - zfile_fclose (f); - } - return (void*)1; + if (crc32) + *crc32 = 0; + if (leave_open) { + struct zfile *f = zfile_fopen (fname, L"r+b", ZFD_NORMAL | ZFD_DISKHISTORY); + if (f) { + if (wrprot) + *wrprot = 0; + } else { + if (wrprot) + *wrprot = 1; + f = zfile_fopen (fname, L"rb", ZFD_NORMAL | ZFD_DISKHISTORY); + } + if (f && crc32) + *crc32 = zfile_crc32 (f); + return f; } else { - if (wrprot) - *wrprot = 1; - return 0; + if (zfile_exists (fname)) { + if (wrprot) + *wrprot = 0; + if (crc32) { + struct zfile *f = zfile_fopen (fname, L"rb", ZFD_NORMAL | ZFD_DISKHISTORY); + if (f) + *crc32 = zfile_crc32 (f); + zfile_fclose (f); + } + return (void*)1; + } else { + if (wrprot) + *wrprot = 1; + return 0; + } } - } } static void updatemfmpos (drive *drv) { - if (drv->prevtracklen) - drv->mfmpos = drv->mfmpos * (drv->tracklen * 1000 / drv->prevtracklen) / 1000; - drv->mfmpos %= drv->tracklen; - drv->prevtracklen = drv->tracklen; + if (drv->prevtracklen) + drv->mfmpos = drv->mfmpos * (drv->tracklen * 1000 / drv->prevtracklen) / 1000; + drv->mfmpos %= drv->tracklen; + drv->prevtracklen = drv->tracklen; } static void track_reset (drive *drv) { - drv->tracklen = FLOPPY_WRITE_LEN * drv->ddhd * 2 * 8; - drv->trackspeed = get_floppy_speed (); - drv->buffered_side = -1; - drv->skipoffset = -1; - drv->tracktiming[0] = 0; - memset (drv->bigmfmbuf, 0xaa, FLOPPY_WRITE_LEN * 2 * drv->ddhd); - updatemfmpos (drv); + drv->tracklen = FLOPPY_WRITE_LEN * drv->ddhd * 2 * 8; + drv->trackspeed = get_floppy_speed (); + drv->buffered_side = -1; + drv->skipoffset = -1; + drv->tracktiming[0] = 0; + memset (drv->bigmfmbuf, 0xaa, FLOPPY_WRITE_LEN * 2 * drv->ddhd); + updatemfmpos (drv); } static int read_header_ext2 (struct zfile *diskfile, trackid *trackdata, int *num_tracks, int *ddhd) { - uae_u8 buffer[2 + 2 + 4 + 4]; - trackid *tid; - int offs; - int i; + uae_u8 buffer[2 + 2 + 4 + 4]; + trackid *tid; + int offs; + int i; - zfile_fseek (diskfile, 0, SEEK_SET); - zfile_fread (buffer, 1, 8, diskfile); - if (strncmp (buffer, "UAE-1ADF", 8)) - return 0; - zfile_fread (buffer, 1, 4, diskfile); - *num_tracks = buffer[2] * 256 + buffer[3]; - offs = 8 + 2 + 2 + (*num_tracks) * (2 + 2 + 4 + 4); - - for (i = 0; i < (*num_tracks); i++) { - tid = trackdata + i; - zfile_fread (buffer, 2 + 2 + 4 + 4, 1, diskfile); - tid->type = buffer[2] * 256 + buffer[3]; - tid->len = buffer[5] * 65536 + buffer[6] * 256 + buffer[7]; - tid->bitlen = buffer[9] * 65536 + buffer[10] * 256 + buffer[11]; - tid->offs = offs; - if (tid->len > 20000 && ddhd) - *ddhd = 2; - tid->track = i; - offs += tid->len; - } - return 1; + zfile_fseek (diskfile, 0, SEEK_SET); + zfile_fread (buffer, 1, 8, diskfile); + if (strncmp (buffer, "UAE-1ADF", 8)) + return 0; + zfile_fread (buffer, 1, 4, diskfile); + *num_tracks = buffer[2] * 256 + buffer[3]; + offs = 8 + 2 + 2 + (*num_tracks) * (2 + 2 + 4 + 4); + + for (i = 0; i < (*num_tracks); i++) { + tid = trackdata + i; + zfile_fread (buffer, 2 + 2 + 4 + 4, 1, diskfile); + tid->type = buffer[2] * 256 + buffer[3]; + tid->len = buffer[5] * 65536 + buffer[6] * 256 + buffer[7]; + tid->bitlen = buffer[9] * 65536 + buffer[10] * 256 + buffer[11]; + tid->offs = offs; + if (tid->len > 20000 && ddhd) + *ddhd = 2; + tid->track = i; + offs += tid->len; + } + return 1; } TCHAR *DISK_get_saveimagepath (const TCHAR *name) { - static TCHAR name1[MAX_DPATH]; - TCHAR name2[MAX_DPATH]; - TCHAR path[MAX_DPATH]; - int i; + static TCHAR name1[MAX_DPATH]; + TCHAR name2[MAX_DPATH]; + TCHAR path[MAX_DPATH]; + int i; - _tcscpy (name2, name); - i = _tcslen (name2) - 1; - while (i > 0) { - if (name2[i] == '.') { - name2[i] = 0; - break; + _tcscpy (name2, name); + i = _tcslen (name2) - 1; + while (i > 0) { + if (name2[i] == '.') { + name2[i] = 0; + break; + } + i--; } - i--; - } - while (i > 0) { - if (name2[i] == '/' || name2[i] == '\\') { - i++; - break; + while (i > 0) { + if (name2[i] == '/' || name2[i] == '\\') { + i++; + break; + } + i--; } - i--; - } - fetch_saveimagepath (path, sizeof (path), 1); - _stprintf (name1, L"%s%s_save.adf", path, name2 + i); - return name1; + fetch_saveimagepath (path, sizeof (path), 1); + _stprintf (name1, L"%s%s_save.adf", path, name2 + i); + return name1; } static struct zfile *getwritefile (const TCHAR *name, int *wrprot) { - return DISK_validate_filename (DISK_get_saveimagepath (name), 1, wrprot, NULL); + return DISK_validate_filename (DISK_get_saveimagepath (name), 1, wrprot, NULL); } static int iswritefileempty (const TCHAR *name) { - struct zfile *zf; - int wrprot; - uae_char buffer[8]; - trackid td[MAX_TRACKS]; - int tracks, ddhd, i, ret; + struct zfile *zf; + int wrprot; + uae_char buffer[8]; + trackid td[MAX_TRACKS]; + int tracks, ddhd, i, ret; - zf = getwritefile (name, &wrprot); - if (!zf) return 1; - zfile_fread (buffer, sizeof (char), 8, zf); - if (strncmp ((uae_char*)buffer, "UAE-1ADF", 8)) - return 0; - ret = read_header_ext2 (zf, td, &tracks, &ddhd); - zfile_fclose (zf); - if (!ret) + zf = getwritefile (name, &wrprot); + if (!zf) return 1; + zfile_fread (buffer, sizeof (char), 8, zf); + if (strncmp ((uae_char*)buffer, "UAE-1ADF", 8)) + return 0; + ret = read_header_ext2 (zf, td, &tracks, &ddhd); + zfile_fclose (zf); + if (!ret) + return 1; + for (i = 0; i < tracks; i++) { + if (td[i].bitlen) return 0; + } return 1; - for (i = 0; i < tracks; i++) { - if (td[i].bitlen) return 0; - } - return 1; } static int openwritefile (drive *drv, int create) { - int wrprot = 0; + int wrprot = 0; - drv->writediskfile = getwritefile (currprefs.df[drv - &floppy[0]], &wrprot); - if (drv->writediskfile) { - drv->wrprot = wrprot; - if (!read_header_ext2 (drv->writediskfile, drv->writetrackdata, &drv->write_num_tracks, 0)) { - zfile_fclose (drv->writediskfile); - drv->writediskfile = 0; - drv->wrprot = 1; - } else { - if (drv->write_num_tracks > drv->num_tracks) - drv->num_tracks = drv->write_num_tracks; + drv->writediskfile = getwritefile (currprefs.df[drv - &floppy[0]], &wrprot); + if (drv->writediskfile) { + drv->wrprot = wrprot; + if (!read_header_ext2 (drv->writediskfile, drv->writetrackdata, &drv->write_num_tracks, 0)) { + zfile_fclose (drv->writediskfile); + drv->writediskfile = 0; + drv->wrprot = 1; + } else { + if (drv->write_num_tracks > drv->num_tracks) + drv->num_tracks = drv->write_num_tracks; + } + } else if (zfile_iscompressed (drv->diskfile)) { + drv->wrprot = 1; } - } else if (zfile_iscompressed (drv->diskfile)) { - drv->wrprot = 1; - } - return drv->writediskfile ? 1 : 0; + return drv->writediskfile ? 1 : 0; } static int diskfile_iswriteprotect (const TCHAR *fname, int *needwritefile, drive_type *drvtype) { - struct zfile *zf1, *zf2; - int wrprot1 = 0, wrprot2 = 1; - uae_char buffer[25]; + struct zfile *zf1, *zf2; + int wrprot1 = 0, wrprot2 = 1; + uae_char buffer[25]; - *needwritefile = 0; - *drvtype = DRV_35_DD; - zf1 = DISK_validate_filename (fname, 1, &wrprot1, NULL); - if (!zf1) - return 1; - if (zfile_iscompressed (zf1)) { - wrprot1 = 1; - *needwritefile = 1; - } - zf2 = getwritefile (fname, &wrprot2); - zfile_fclose (zf2); - zfile_fread (buffer, sizeof (char), 25, zf1); - zfile_fclose (zf1); - if (strncmp ((uae_char*) buffer, "CAPS", 4) == 0) { - *needwritefile = 1; - return wrprot2; - } - if (strncmp ((uae_char*) buffer, "Formatted Disk Image file", 25) == 0) { - *needwritefile = 1; - return wrprot2; - } - if (strncmp ((uae_char*) buffer, "UAE-1ADF", 8) == 0) { + *needwritefile = 0; + *drvtype = DRV_35_DD; + zf1 = DISK_validate_filename (fname, 1, &wrprot1, NULL); + if (!zf1) + return 1; + if (zfile_iscompressed (zf1)) { + wrprot1 = 1; + *needwritefile = 1; + } + zf2 = getwritefile (fname, &wrprot2); + zfile_fclose (zf2); + zfile_fread (buffer, sizeof (char), 25, zf1); + zfile_fclose (zf1); + if (strncmp ((uae_char*) buffer, "CAPS", 4) == 0) { + *needwritefile = 1; + return wrprot2; + } + if (strncmp ((uae_char*) buffer, "Formatted Disk Image file", 25) == 0) { + *needwritefile = 1; + return wrprot2; + } + if (strncmp ((uae_char*) buffer, "UAE-1ADF", 8) == 0) { + if (wrprot1) + return wrprot2; + return wrprot1; + } + if (strncmp ((uae_char*) buffer, "UAE--ADF", 8) == 0) { + *needwritefile = 1; + return wrprot2; + } + if (memcmp (exeheader, buffer, sizeof (exeheader)) == 0) + return 0; if (wrprot1) - return wrprot2; + return wrprot2; return wrprot1; - } - if (strncmp ((uae_char*) buffer, "UAE--ADF", 8) == 0) { - *needwritefile = 1; - return wrprot2; - } - if (memcmp (exeheader, buffer, sizeof (exeheader)) == 0) - return 0; - if (wrprot1) - return wrprot2; - return wrprot1; } static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR *fname) { - uae_char buffer[2 + 2 + 4 + 4]; - trackid *tid; - int num_tracks, size; - - gui_disk_image_change (dnum, fname); - drive_image_free (drv); - drv->diskfile = DISK_validate_filename (fname, 1, &drv->wrprot, &drv->crc32); - drv->ddhd = 1; - drv->num_secs = 0; - drv->hard_num_cyls = p->dfxtype[dnum] == DRV_525_SD ? 40 : 80; - drv->tracktiming[0] = 0; - drv->useturbo = 0; - drv->indexoffset = 0; - - if (!drv->motoroff) { - drv->dskready_time = DSKREADY_TIME; - drv->dskready_down_time = 0; - } + uae_char buffer[2 + 2 + 4 + 4]; + trackid *tid; + int num_tracks, size; - if (drv->diskfile == 0 && !drv->catweasel) { - track_reset (drv); - return 0; - } - - if (input_recording > 0) { - inprec_rstart (INPREC_DISKINSERT); - inprec_ru8 (dnum); - inprec_rstr (fname); - inprec_rend (); - } - - _tcsncpy (currprefs.df[dnum], fname, 255); - currprefs.df[dnum][255] = 0; - _tcsncpy (changed_prefs.df[dnum], fname, 255); - changed_prefs.df[dnum][255] = 0; - _tcscpy (drv->newname, fname); - gui_filename (dnum, fname); - - memset (buffer, 0, sizeof (buffer)); - size = 0; - if (drv->diskfile) { - zfile_fread (buffer, sizeof (char), 8, drv->diskfile); - zfile_fseek (drv->diskfile, 0, SEEK_END); - size = zfile_ftell (drv->diskfile); - zfile_fseek (drv->diskfile, 0, SEEK_SET); - } + gui_disk_image_change (dnum, fname); + drive_image_free (drv); + drv->diskfile = DISK_validate_filename (fname, 1, &drv->wrprot, &drv->crc32); + drv->ddhd = 1; + drv->num_secs = 0; + drv->hard_num_cyls = p->dfxtype[dnum] == DRV_525_SD ? 40 : 80; + drv->tracktiming[0] = 0; + drv->useturbo = 0; + drv->indexoffset = 0; + if (!drv->motoroff) { + drv->dskready_time = DSKREADY_TIME; + drv->dskready_down_time = 0; + } - if (drv->catweasel) { + if (drv->diskfile == 0 && !drv->catweasel) { + track_reset (drv); + return 0; + } - drv->wrprot = 1; - drv->filetype = ADF_CATWEASEL; - drv->num_tracks = 80; - drv->ddhd = 1; + if (input_recording > 0) { + inprec_rstart (INPREC_DISKINSERT); + inprec_ru8 (dnum); + inprec_rstr (fname); + inprec_rend (); + } -#ifdef CAPS - } else if (strncmp ((uae_char*)buffer, "CAPS", 4) == 0) { + _tcsncpy (currprefs.df[dnum], fname, 255); + currprefs.df[dnum][255] = 0; + _tcsncpy (changed_prefs.df[dnum], fname, 255); + changed_prefs.df[dnum][255] = 0; + _tcscpy (drv->newname, fname); + gui_filename (dnum, fname); - drv->wrprot = 1; - if (!caps_loadimage (drv->diskfile, drv - floppy, &num_tracks)) { - zfile_fclose (drv->diskfile); - drv->diskfile = 0; - return 0; + memset (buffer, 0, sizeof (buffer)); + size = 0; + if (drv->diskfile) { + zfile_fread (buffer, sizeof (char), 8, drv->diskfile); + zfile_fseek (drv->diskfile, 0, SEEK_END); + size = zfile_ftell (drv->diskfile); + zfile_fseek (drv->diskfile, 0, SEEK_SET); } - drv->num_tracks = num_tracks; - drv->filetype = ADF_IPF; + + if (drv->catweasel) { + + drv->wrprot = 1; + drv->filetype = ADF_CATWEASEL; + drv->num_tracks = 80; + drv->ddhd = 1; + +#ifdef CAPS + } else if (strncmp (buffer, "CAPS", 4) == 0) { + + drv->wrprot = 1; + if (!caps_loadimage (drv->diskfile, drv - floppy, &num_tracks)) { + zfile_fclose (drv->diskfile); + drv->diskfile = 0; + return 0; + } + drv->num_tracks = num_tracks; + drv->filetype = ADF_IPF; #endif #ifdef FDI2RAW - } else if (drv->fdi = fdi2raw_header (drv->diskfile)) { + } else if (drv->fdi = fdi2raw_header (drv->diskfile)) { - drv->wrprot = 1; - drv->num_tracks = fdi2raw_get_last_track (drv->fdi); - drv->num_secs = fdi2raw_get_num_sector (drv->fdi); - drv->filetype = ADF_FDI; + drv->wrprot = 1; + drv->num_tracks = fdi2raw_get_last_track (drv->fdi); + drv->num_secs = fdi2raw_get_num_sector (drv->fdi); + drv->filetype = ADF_FDI; #endif - } else if (strncmp ((uae_char*)buffer, "UAE-1ADF", 8) == 0) { + } else if (strncmp (buffer, "UAE-1ADF", 8) == 0) { + + read_header_ext2 (drv->diskfile, drv->trackdata, &drv->num_tracks, &drv->ddhd); + drv->filetype = ADF_EXT2; + drv->num_secs = 11; + if (drv->ddhd > 1) + drv->num_secs = 22; + + } else if (strncmp (buffer, "UAE--ADF", 8) == 0) { + int offs = 160 * 4 + 8; + int i; + + drv->wrprot = 1; + drv->filetype = ADF_EXT1; + drv->num_tracks = 160; + drv->num_secs = 11; + + zfile_fseek (drv->diskfile, 8, SEEK_SET); + for (i = 0; i < 160; i++) { + tid = &drv->trackdata[i]; + zfile_fread (buffer, 4, 1, drv->diskfile); + tid->sync = buffer[0] * 256 + buffer[1]; + tid->len = buffer[2] * 256 + buffer[3]; + tid->offs = offs; + if (tid->sync == 0) { + tid->type = TRACK_AMIGADOS; + tid->bitlen = 0; + } else { + tid->type = TRACK_RAW1; + tid->bitlen = tid->len * 8; + } + offs += tid->len; + } - read_header_ext2 (drv->diskfile, drv->trackdata, &drv->num_tracks, &drv->ddhd); - drv->filetype = ADF_EXT2; - drv->num_secs = 11; - if (drv->ddhd > 1) - drv->num_secs = 22; + } else if (memcmp (exeheader, buffer, sizeof (exeheader)) == 0) { + int i; + struct zfile *z = zfile_fopen_empty (NULL, L"", 512 * 1760); + createimagefromexe (drv->diskfile, z); + drv->filetype = ADF_NORMAL; + zfile_fclose (drv->diskfile); + drv->diskfile = z; + drv->num_tracks = 160; + drv->num_secs = 11; + for (i = 0; i < drv->num_tracks; i++) { + tid = &drv->trackdata[i]; + tid->type = TRACK_AMIGADOS; + tid->len = 512 * drv->num_secs; + tid->bitlen = 0; + tid->offs = i * 512 * drv->num_secs; + } + drv->useturbo = 1; + + } else if ( + // double sided + size == 9 * 80 * 2 * 512 || size == 18 * 80 * 2 * 512 || size == 10 * 80 * 2 * 512 || size == 20 * 80 * 2 * 512 || + size == 9 * 81 * 2 * 512 || size == 18 * 81 * 2 * 512 || size == 10 * 81 * 2 * 512 || size == 20 * 81 * 2 * 512 || + size == 9 * 82 * 2 * 512 || size == 18 * 82 * 2 * 512 || size == 10 * 82 * 2 * 512 || size == 20 * 82 * 2 * 512 || + // single sided + size == 9 * 80 * 1 * 512 || size == 18 * 80 * 1 * 512 || size == 10 * 80 * 1 * 512 || size == 20 * 80 * 1 * 512 || + size == 9 * 81 * 1 * 512 || size == 18 * 81 * 1 * 512 || size == 10 * 81 * 1 * 512 || size == 20 * 81 * 1 * 512 || + size == 9 * 82 * 1 * 512 || size == 18 * 82 * 1 * 512 || size == 10 * 82 * 1 * 512 || size == 20 * 82 * 1 * 512) { + /* PC formatted image */ + int i, side; + + for (side = 2; side > 0; side--) { + if ( size == 9 * 80 * side * 512 || size == 9 * 81 * side * 512 || size == 9 * 82 * side * 512) { + drv->num_secs = 9; + drv->ddhd = 1; + break; + } else if (size == 18 * 80 * side * 512 || size == 18 * 81 * side * 512 || size == 18 * 82 * side * 512) { + drv->num_secs = 18; + drv->ddhd = 2; + break; + } else if (size == 10 * 80 * side * 512 || size == 10 * 81 * side * 512 || size == 10 * 82 * side * 512) { + drv->num_secs = 10; + drv->ddhd = 1; + break; + } else if (size == 20 * 80 * side * 512 || size == 20 * 81 * side * 512 || size == 20 * 82 * side * 512) { + drv->num_secs = 20; + drv->ddhd = 2; + break; + } + } + drv->num_tracks = size / (drv->num_secs * 512); + + drv->filetype = ADF_PCDOS; + tid = &drv->trackdata[0]; + for (i = 0; i < drv->num_tracks; i++) { + tid->type = TRACK_PCDOS; + tid->len = 512 * drv->num_secs; + tid->bitlen = 0; + tid->offs = i * 512 * drv->num_secs; + if (side == 1) { + tid++; + tid->type = TRACK_NONE; + tid->len = 512 * drv->num_secs; + } + tid++; - } else if (strncmp ((uae_char*)buffer, "UAE--ADF", 8) == 0) { - int offs = 160 * 4 + 8; - int i; + } + if (side == 1) + drv->num_tracks *= 2; - drv->wrprot = 1; - drv->filetype = ADF_EXT1; - drv->num_tracks = 160; - drv->num_secs = 11; - - zfile_fseek (drv->diskfile, 8, SEEK_SET); - for (i = 0; i < 160; i++) { - tid = &drv->trackdata[i]; - zfile_fread (buffer, 4, 1, drv->diskfile); - tid->sync = buffer[0] * 256 + buffer[1]; - tid->len = buffer[2] * 256 + buffer[3]; - tid->offs = offs; - if (tid->sync == 0) { - tid->type = TRACK_AMIGADOS; - tid->bitlen = 0; - } else { - tid->type = TRACK_RAW1; - tid->bitlen = tid->len * 8; - } - offs += tid->len; - } - - } else if (memcmp (exeheader, buffer, sizeof (exeheader)) == 0) { - int i; - struct zfile *z = zfile_fopen_empty (NULL, L"", 512 * 1760); - createimagefromexe (drv->diskfile, z); - drv->filetype = ADF_NORMAL; - zfile_fclose (drv->diskfile); - drv->diskfile = z; - drv->num_tracks = 160; - drv->num_secs = 11; - for (i = 0; i < drv->num_tracks; i++) { - tid = &drv->trackdata[i]; - tid->type = TRACK_AMIGADOS; - tid->len = 512 * drv->num_secs; - tid->bitlen = 0; - tid->offs = i * 512 * drv->num_secs; - } - drv->useturbo = 1; - - } else if ( - size == 9 * 80 * 2 * 512 || size == 18 * 80 * 2 * 512 || size == 10 * 80 * 2 * 512 || size == 20 * 80 * 2 * 512 || - size == 9 * 81 * 2 * 512 || size == 18 * 81 * 2 * 512 || size == 10 * 81 * 2 * 512 || size == 20 * 81 * 2 * 512 || - size == 9 * 82 * 2 * 512 || size == 18 * 82 * 2 * 512 || size == 10 * 82 * 2 * 512 || size == 20 * 82 * 2 * 512) { - /* PC formatted image */ - int i; - - if ( size == 9 * 80 * 2 * 512 || size == 9 * 81 * 2 * 512 || size == 9 * 82 * 2 * 512) { - drv->num_secs = 9; - drv->ddhd = 1; - } else if (size == 18 * 80 * 2 * 512 || size == 18 * 81 * 2 * 512 || size == 18 * 82 * 2 * 512) { - drv->num_secs = 18; - drv->ddhd = 2; - } else if (size == 10 * 80 * 2 * 512 || size == 10 * 81 * 2 * 512 || size == 10 * 82 * 2 * 512) { - drv->num_secs = 10; - drv->ddhd = 1; - } else if (size == 20 * 80 * 2 * 512 || size == 20 * 81 * 2 * 512 || size == 20 * 82 * 2 * 512) { - drv->num_secs = 20; - drv->ddhd = 2; - } - drv->num_tracks = size / (drv->num_secs * 512); - - drv->filetype = ADF_PCDOS; - for (i = 0; i < drv->num_tracks; i++) { - tid = &drv->trackdata[i]; - tid->type = TRACK_PCDOS; - tid->len = 512 * drv->num_secs; - tid->bitlen = 0; - tid->offs = i * 512 * drv->num_secs; - } - - } else { - int i, ds; - - ds = 0; - drv->filetype = ADF_NORMAL; - - /* High-density or diskspare disk? */ - drv->num_tracks = 0; - if (size > 160 * 11 * 512) { // larger than standard adf? - for (i = 80; i <= 83; i++) { - if (size == i * 22 * 512 * 2) { // HD - drv->ddhd = 2; - drv->num_tracks = size / (512 * (drv->num_secs = 22)); - break; - } - if (size == i * 11 * 512 * 2) { // >80 cyl DD - drv->num_tracks = size / (512 * (drv->num_secs = 11)); - break; - } - if (size == i * 12 * 512 * 2) { // ds 12 sectors - drv->num_tracks = size / (512 * (drv->num_secs = 12)); - ds = 1; - break; - } - if (size == i * 24 * 512 * 2) { // ds 24 sectors - drv->num_tracks = size / (512 * (drv->num_secs = 24)); - drv->ddhd = 2; - ds = 1; - break; - } - } - if (drv->num_tracks == 0) { - drv->num_tracks = size / (512 * (drv->num_secs = 22)); - drv->ddhd = 2; - } } else { - drv->num_tracks = size / (512 * (drv->num_secs = 11)); - } - - if (!ds && drv->num_tracks > MAX_TRACKS) - write_log (L"Your diskfile is too big, %d bytes!\n", size); - for (i = 0; i < drv->num_tracks; i++) { - tid = &drv->trackdata[i]; - tid->type = ds ? TRACK_DISKSPARE : TRACK_AMIGADOS; - tid->len = 512 * drv->num_secs; - tid->bitlen = 0; - tid->offs = i * 512 * drv->num_secs; - } - } - openwritefile (drv, 0); - drive_settype_id (drv); /* Set DD or HD drive */ - drive_fill_bigbuf (drv, 1); - drv->mfmpos = uaerand (); - drv->mfmpos |= (uaerand () << 16); - drv->mfmpos %= drv->tracklen; - drv->prevtracklen = 0; + int i, ds; + + ds = 0; + drv->filetype = ADF_NORMAL; + + /* High-density or diskspare disk? */ + drv->num_tracks = 0; + if (size > 160 * 11 * 512) { // larger than standard adf? + for (i = 80; i <= 83; i++) { + if (size == i * 22 * 512 * 2) { // HD + drv->ddhd = 2; + drv->num_tracks = size / (512 * (drv->num_secs = 22)); + break; + } + if (size == i * 11 * 512 * 2) { // >80 cyl DD + drv->num_tracks = size / (512 * (drv->num_secs = 11)); + break; + } + if (size == i * 12 * 512 * 2) { // ds 12 sectors + drv->num_tracks = size / (512 * (drv->num_secs = 12)); + ds = 1; + break; + } + if (size == i * 24 * 512 * 2) { // ds 24 sectors + drv->num_tracks = size / (512 * (drv->num_secs = 24)); + drv->ddhd = 2; + ds = 1; + break; + } + } + if (drv->num_tracks == 0) { + drv->num_tracks = size / (512 * (drv->num_secs = 22)); + drv->ddhd = 2; + } + } else { + drv->num_tracks = size / (512 * (drv->num_secs = 11)); + } + + if (!ds && drv->num_tracks > MAX_TRACKS) + write_log (L"Your diskfile is too big, %d bytes!\n", size); + for (i = 0; i < drv->num_tracks; i++) { + tid = &drv->trackdata[i]; + tid->type = ds ? TRACK_DISKSPARE : TRACK_AMIGADOS; + tid->len = 512 * drv->num_secs; + tid->bitlen = 0; + tid->offs = i * 512 * drv->num_secs; + } + } + openwritefile (drv, 0); + drive_settype_id (drv); /* Set DD or HD drive */ + drive_fill_bigbuf (drv, 1); + drv->mfmpos = uaerand (); + drv->mfmpos |= (uaerand () << 16); + drv->mfmpos %= drv->tracklen; + drv->prevtracklen = 0; #ifdef DRIVESOUND - driveclick_insert (drv - floppy, 0); + driveclick_insert (drv - floppy, 0); #endif - return 1; + update_drive_gui (drv - floppy); + return 1; } static void rand_shifter (drive *drv) { - int r = ((uaerand () >> 4) & 7) + 1; - while (r-- > 0) { - word <<= 1; - word |= (uaerand () & 0x1000) ? 1 : 0; - bitoffset++; - bitoffset &= 15; - } + int r = ((uaerand () >> 4) & 7) + 1; + while (r-- > 0) { + word <<= 1; + word |= (uaerand () & 0x1000) ? 1 : 0; + bitoffset++; + bitoffset &= 15; + } } static void set_steplimit (drive *drv) { - drv->steplimit = 10; - drv->steplimitcycle = get_cycles (); + drv->steplimit = 10; + drv->steplimitcycle = get_cycles (); } static int drive_empty (drive * drv) { #ifdef CATWEASEL - if (drv->catweasel) - return catweasel_disk_changed (drv->catweasel) == 0; + if (drv->catweasel) + return catweasel_disk_changed (drv->catweasel) == 0; #endif - return drv->diskfile == 0; + return drv->diskfile == 0; } static void drive_step (drive * drv) { #ifdef CATWEASEL - if (drv->catweasel) { - int dir = direction ? -1 : 1; - catweasel_step (drv->catweasel, dir); - drv->cyl += dir; - if (drv->cyl < 0) - drv->cyl = 0; - write_log (L"%d -> %d\n", dir, drv->cyl); - return; - } + if (drv->catweasel) { + int dir = direction ? -1 : 1; + catweasel_step (drv->catweasel, dir); + drv->cyl += dir; + if (drv->cyl < 0) + drv->cyl = 0; + write_log (L"%d -> %d\n", dir, drv->cyl); + return; + } #endif - if (drv->steplimit && get_cycles() - drv->steplimitcycle < MIN_STEPLIMIT_CYCLE) { - if (disk_debug_logging > 1) - write_log (L" step ignored drive %d, %d", - drv - floppy, (get_cycles() - drv->steplimitcycle) / CYCLE_UNIT); - return; - } - /* A1200's floppy drive needs at least 30 raster lines between steps - * but we'll use very small value for better compatibility with faster CPU emulation - * (stupid trackloaders with CPU delay loops) - */ - set_steplimit (drv); - if (!drive_empty (drv)) - drv->dskchange = 0; - if (direction) { - if (drv->cyl) { - drv->cyl--; + if (drv->steplimit && get_cycles() - drv->steplimitcycle < MIN_STEPLIMIT_CYCLE) { + if (disk_debug_logging > 1) + write_log (L" step ignored drive %d, %d", + drv - floppy, (get_cycles() - drv->steplimitcycle) / CYCLE_UNIT); + return; + } + /* A1200's floppy drive needs at least 30 raster lines between steps + * but we'll use very small value for better compatibility with faster CPU emulation + * (stupid trackloaders with CPU delay loops) + */ + set_steplimit (drv); + if (!drive_empty (drv)) + drv->dskchange = 0; + if (direction) { + if (drv->cyl) { + drv->cyl--; #ifdef DRIVESOUND - driveclick_click (drv - floppy, drv->cyl); + driveclick_click (drv - floppy, drv->cyl); #endif - } -/* else - write_log (L"program tried to step beyond track zero\n"); - "no-click" programs does that -*/ - } else { - int maxtrack = drv->hard_num_cyls; - if (drv->cyl < maxtrack + 3) { - drv->cyl++; + } + /* else + write_log (L"program tried to step beyond track zero\n"); + "no-click" programs does that + */ + } else { + int maxtrack = drv->hard_num_cyls; + if (drv->cyl < maxtrack + 3) { + drv->cyl++; #ifdef CATWEASEL - if (drv->catweasel) - catweasel_step (drv->catweasel, 1); + if (drv->catweasel) + catweasel_step (drv->catweasel, 1); #endif - } - if (drv->cyl >= maxtrack) - write_log (L"program tried to step over track %d\n", maxtrack); + } + if (drv->cyl >= maxtrack) + write_log (L"program tried to step over track %d\n", maxtrack); #ifdef DRIVESOUND - driveclick_click (drv - floppy, drv->cyl); + driveclick_click (drv - floppy, drv->cyl); #endif - } - rand_shifter (drv); - if (disk_debug_logging > 1) - write_log (L" ->step %d", drv->cyl); + } + rand_shifter (drv); + if (disk_debug_logging > 1) + write_log (L" ->step %d", drv->cyl); } static int drive_track0 (drive * drv) { #ifdef CATWEASEL - if (drv->catweasel) - return catweasel_track0 (drv->catweasel); + if (drv->catweasel) + return catweasel_track0 (drv->catweasel); #endif - return drv->cyl == 0; + return drv->cyl == 0; } static int drive_writeprotected (drive * drv) { #ifdef CATWEASEL - if (drv->catweasel) - return 1; + if (drv->catweasel) + return 1; #endif - return drv->wrprot || drv->diskfile == NULL; + return drv->wrprot || drv->diskfile == NULL; } static int drive_running (drive * drv) { - return !drv->motoroff; + return !drv->motoroff; } static void motordelay_func (uae_u32 v) { - floppy[v].motordelay = 0; + floppy[v].motordelay = 0; } static void drive_motor (drive * drv, int off) { - if (drv->motoroff && !off) { - drv->dskready_time = DSKREADY_TIME; - rand_shifter (drv); + if (drv->motoroff && !off) { + drv->dskready_time = DSKREADY_TIME; + rand_shifter (drv); #ifdef DRIVESOUND - driveclick_motor (drv - floppy, drv->dskready_down_time == 0 ? 2 : 1); + driveclick_motor (drv - floppy, drv->dskready_down_time == 0 ? 2 : 1); #endif - if (disk_debug_logging > 1) - write_log (L" ->motor on"); - } - if (!drv->motoroff && off) { - drv->drive_id_scnt = 0; /* Reset id shift reg counter */ - drv->dskready_down_time = DSKREADY_DOWN_TIME; + if (disk_debug_logging > 1) + write_log (L" ->motor on"); + } + if (!drv->motoroff && off) { + drv->drive_id_scnt = 0; /* Reset id shift reg counter */ + drv->dskready_down_time = DSKREADY_DOWN_TIME; #ifdef DRIVESOUND - driveclick_motor (drv - floppy, 0); + driveclick_motor (drv - floppy, 0); #endif #ifdef DEBUG_DRIVE_ID - write_log (L"drive_motor: Selected DF%d: reset id shift reg.\n",drv-floppy); + write_log (L"drive_motor: Selected DF%d: reset id shift reg.\n",drv-floppy); #endif - if (disk_debug_logging > 1) - write_log (L" ->motor off"); - if (currprefs.cpu_model <= 68010 && currprefs.m68k_speed == 0) { - drv->motordelay = 1; - event2_newevent2 (30, drv - floppy, motordelay_func); - } - } - drv->motoroff = off; - if (drv->motoroff) { - drv->dskready = 0; - drv->dskready_time = 0; - } + if (disk_debug_logging > 1) + write_log (L" ->motor off"); + if (currprefs.cpu_model <= 68010 && currprefs.m68k_speed == 0) { + drv->motordelay = 1; + event2_newevent2 (30, drv - floppy, motordelay_func); + } + } + drv->motoroff = off; + if (drv->motoroff) { + drv->dskready = 0; + drv->dskready_time = 0; + } #ifdef CATWEASEL - if (drv->catweasel) - catweasel_set_motor (drv->catweasel, !drv->motoroff); + if (drv->catweasel) + catweasel_set_motor (drv->catweasel, !drv->motoroff); #endif } static void read_floppy_data (struct zfile *diskfile, trackid *tid, int offset, uae_u8 *dst, int len) { - if (len == 0) - return; - zfile_fseek (diskfile, tid->offs + offset, SEEK_SET); - zfile_fread (dst, 1, len, diskfile); + if (len == 0) + return; + zfile_fseek (diskfile, tid->offs + offset, SEEK_SET); + zfile_fread (dst, 1, len, diskfile); } /* Megalomania does not like zero MFM words... */ static void mfmcode (uae_u16 * mfm, int words) { - uae_u32 lastword = 0; - while (words--) { - uae_u32 v = *mfm; - uae_u32 lv = (lastword << 16) | v; - uae_u32 nlv = 0x55555555 & ~lv; - uae_u32 mfmbits = (nlv << 1) & (nlv >> 1); - *mfm++ = v | mfmbits; - lastword = v; - } + uae_u32 lastword = 0; + while (words--) { + uae_u32 v = *mfm; + uae_u32 lv = (lastword << 16) | v; + uae_u32 nlv = 0x55555555 & ~lv; + uae_u32 mfmbits = (nlv << 1) & (nlv >> 1); + *mfm++ = v | mfmbits; + lastword = v; + } } static uae_u8 mfmencodetable[16] = { - 0x2a, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, - 0x4a, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55 + 0x2a, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, + 0x4a, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55 }; static uae_u16 dos_encode_byte (uae_u8 byte) { - uae_u8 b2, b1; - uae_u16 word; + uae_u8 b2, b1; + uae_u16 word; - b1 = byte; - b2 = b1 >> 4; - b1 &= 15; - word = mfmencodetable[b2] <<8 | mfmencodetable[b1]; - return (word | ((word & (256 | 64)) ? 0 : 128)); + b1 = byte; + b2 = b1 >> 4; + b1 &= 15; + word = mfmencodetable[b2] <<8 | mfmencodetable[b1]; + return (word | ((word & (256 | 64)) ? 0 : 128)); } static uae_u16 *mfmcoder (uae_u8 *src, uae_u16 *dest, int len) { - int i; + int i; - for (i = 0; i < len; i++) { - *dest = dos_encode_byte (*src++); - *dest |= ((dest[-1] & 1)||(*dest & 0x4000)) ? 0: 0x8000; - dest++; - } - return dest; + for (i = 0; i < len; i++) { + *dest = dos_encode_byte (*src++); + *dest |= ((dest[-1] & 1)||(*dest & 0x4000)) ? 0: 0x8000; + dest++; + } + return dest; } static void decode_pcdos (drive *drv) { - int i, len; - int tr = drv->cyl * 2 + side; - uae_u16 *dstmfmbuf, *mfm2; - uae_u8 secbuf[1000]; - uae_u16 crc16; - trackid *ti = drv->trackdata + tr; - int tracklen = 12500; - - mfm2 = drv->bigmfmbuf; - *mfm2++ = 0x9254; - memset (secbuf, 0x4e, 40); - memset (secbuf + 40, 0x00, 12); - secbuf[52] = 0xc2; - secbuf[53] = 0xc2; - secbuf[54] = 0xc2; - secbuf[55] = 0xfc; - memset (secbuf + 56, 0x4e, 40); - dstmfmbuf = mfmcoder (secbuf, mfm2, 96); - mfm2[52] = 0x5224; - mfm2[53] = 0x5224; - mfm2[54] = 0x5224; - for (i = 0; i < drv->num_secs; i++) { - mfm2 = dstmfmbuf; - memset (secbuf, 0x00, 12); - secbuf[12] = 0xa1; - secbuf[13] = 0xa1; - secbuf[14] = 0xa1; - secbuf[15] = 0xfe; - secbuf[16] = drv->cyl; - secbuf[17] = side; - secbuf[18] = 1 + i; - secbuf[19] = 2; // 128 << 2 = 512 - crc16 = get_crc16(secbuf + 12, 3 + 1 + 4); - secbuf[20] = crc16 >> 8; - secbuf[21] = crc16 & 0xff; - memset(secbuf + 22, 0x4e, 22); - memset(secbuf + 44, 0x00, 12); - secbuf[56] = 0xa1; - secbuf[57] = 0xa1; - secbuf[58] = 0xa1; - secbuf[59] = 0xfb; - read_floppy_data (drv->diskfile, ti, i * 512, &secbuf[60], 512); - crc16 = get_crc16 (secbuf + 56, 3 + 1 + 512); - secbuf[60 + 512] = crc16 >> 8; - secbuf[61 + 512] = crc16 & 0xff; - len = (tracklen / 2 - 96) / drv->num_secs - 574 / drv->ddhd; - if (len > 0) - memset(secbuf + 512 + 62, 0x4e, len); - dstmfmbuf = mfmcoder (secbuf, mfm2, 60 + 512 + 2 + 76 / drv->ddhd); - mfm2[12] = 0x4489; - mfm2[13] = 0x4489; - mfm2[14] = 0x4489; - mfm2[56] = 0x4489; - mfm2[57] = 0x4489; - mfm2[58] = 0x4489; - } - while (dstmfmbuf - drv->bigmfmbuf < tracklen / 2) - *dstmfmbuf++ = 0x9254; - drv->skipoffset = 0; - drv->tracklen = (dstmfmbuf - drv->bigmfmbuf) * 16; - if (disk_debug_logging > 0) - write_log (L"pcdos read track %d\n", tr); + int i, len; + int tr = drv->cyl * 2 + side; + uae_u16 *dstmfmbuf, *mfm2; + uae_u8 secbuf[1000]; + uae_u16 crc16; + trackid *ti = drv->trackdata + tr; + int tracklen = 12500; + + mfm2 = drv->bigmfmbuf; + *mfm2++ = 0x9254; + memset (secbuf, 0x4e, 40); + memset (secbuf + 40, 0x00, 12); + secbuf[52] = 0xc2; + secbuf[53] = 0xc2; + secbuf[54] = 0xc2; + secbuf[55] = 0xfc; + memset (secbuf + 56, 0x4e, 40); + dstmfmbuf = mfmcoder (secbuf, mfm2, 96); + mfm2[52] = 0x5224; + mfm2[53] = 0x5224; + mfm2[54] = 0x5224; + for (i = 0; i < drv->num_secs; i++) { + mfm2 = dstmfmbuf; + memset (secbuf, 0x00, 12); + secbuf[12] = 0xa1; + secbuf[13] = 0xa1; + secbuf[14] = 0xa1; + secbuf[15] = 0xfe; + secbuf[16] = drv->cyl; + secbuf[17] = side; + secbuf[18] = 1 + i; + secbuf[19] = 2; // 128 << 2 = 512 + crc16 = get_crc16(secbuf + 12, 3 + 1 + 4); + secbuf[20] = crc16 >> 8; + secbuf[21] = crc16 & 0xff; + memset(secbuf + 22, 0x4e, 22); + memset(secbuf + 44, 0x00, 12); + secbuf[56] = 0xa1; + secbuf[57] = 0xa1; + secbuf[58] = 0xa1; + secbuf[59] = 0xfb; + read_floppy_data (drv->diskfile, ti, i * 512, &secbuf[60], 512); + crc16 = get_crc16 (secbuf + 56, 3 + 1 + 512); + secbuf[60 + 512] = crc16 >> 8; + secbuf[61 + 512] = crc16 & 0xff; + len = (tracklen / 2 - 96) / drv->num_secs - 574 / drv->ddhd; + if (len > 0) + memset(secbuf + 512 + 62, 0x4e, len); + dstmfmbuf = mfmcoder (secbuf, mfm2, 60 + 512 + 2 + 76 / drv->ddhd); + mfm2[12] = 0x4489; + mfm2[13] = 0x4489; + mfm2[14] = 0x4489; + mfm2[56] = 0x4489; + mfm2[57] = 0x4489; + mfm2[58] = 0x4489; + } + while (dstmfmbuf - drv->bigmfmbuf < tracklen / 2) + *dstmfmbuf++ = 0x9254; + drv->skipoffset = 0; + drv->tracklen = (dstmfmbuf - drv->bigmfmbuf) * 16; + if (disk_debug_logging > 0) + write_log (L"pcdos read track %d\n", tr); } static void decode_amigados (drive *drv) { - /* Normal AmigaDOS format track */ - int tr = drv->cyl * 2 + side; - int sec; - int dstmfmoffset = 0; - uae_u16 *dstmfmbuf = drv->bigmfmbuf; - int len = drv->num_secs * 544 + FLOPPY_GAP_LEN; + /* Normal AmigaDOS format track */ + int tr = drv->cyl * 2 + side; + int sec; + int dstmfmoffset = 0; + uae_u16 *dstmfmbuf = drv->bigmfmbuf; + int len = drv->num_secs * 544 + FLOPPY_GAP_LEN; + + trackid *ti = drv->trackdata + tr; + memset (dstmfmbuf, 0xaa, len * 2); + dstmfmoffset += FLOPPY_GAP_LEN; + drv->skipoffset = (FLOPPY_GAP_LEN * 8) / 3 * 2; + drv->tracklen = len * 2 * 8; + + for (sec = 0; sec < drv->num_secs; sec++) { + uae_u8 secbuf[544]; + uae_u16 mfmbuf[544]; + int i; + uae_u32 deven, dodd; + uae_u32 hck = 0, dck = 0; + + secbuf[0] = secbuf[1] = 0x00; + secbuf[2] = secbuf[3] = 0xa1; + secbuf[4] = 0xff; + secbuf[5] = tr; + secbuf[6] = sec; + secbuf[7] = drv->num_secs - sec; + + for (i = 8; i < 24; i++) + secbuf[i] = 0; + + read_floppy_data (drv->diskfile, ti, sec * 512, &secbuf[32], 512); + + mfmbuf[0] = mfmbuf[1] = 0xaaaa; + mfmbuf[2] = mfmbuf[3] = 0x4489; + + deven = ((secbuf[4] << 24) | (secbuf[5] << 16) + | (secbuf[6] << 8) | (secbuf[7])); + dodd = deven >> 1; + deven &= 0x55555555; + dodd &= 0x55555555; + + mfmbuf[4] = dodd >> 16; + mfmbuf[5] = dodd; + mfmbuf[6] = deven >> 16; + mfmbuf[7] = deven; + + for (i = 8; i < 48; i++) + mfmbuf[i] = 0xaaaa; + for (i = 0; i < 512; i += 4) { + deven = ((secbuf[i + 32] << 24) | (secbuf[i + 33] << 16) + | (secbuf[i + 34] << 8) | (secbuf[i + 35])); + dodd = deven >> 1; + deven &= 0x55555555; + dodd &= 0x55555555; + mfmbuf[(i >> 1) + 32] = dodd >> 16; + mfmbuf[(i >> 1) + 33] = dodd; + mfmbuf[(i >> 1) + 256 + 32] = deven >> 16; + mfmbuf[(i >> 1) + 256 + 33] = deven; + } - trackid *ti = drv->trackdata + tr; - memset (dstmfmbuf, 0xaa, len * 2); - dstmfmoffset += FLOPPY_GAP_LEN; - drv->skipoffset = (FLOPPY_GAP_LEN * 8) / 3 * 2; - drv->tracklen = len * 2 * 8; + for (i = 4; i < 24; i += 2) + hck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; + + deven = dodd = hck; + dodd >>= 1; + mfmbuf[24] = dodd >> 16; + mfmbuf[25] = dodd; + mfmbuf[26] = deven >> 16; + mfmbuf[27] = deven; + + for (i = 32; i < 544; i += 2) + dck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; + + deven = dodd = dck; + dodd >>= 1; + mfmbuf[28] = dodd >> 16; + mfmbuf[29] = dodd; + mfmbuf[30] = deven >> 16; + mfmbuf[31] = deven; + mfmcode (mfmbuf + 4, 544 - 4); + + for (i = 0; i < 544; i++) { + dstmfmbuf[dstmfmoffset % len] = mfmbuf[i]; + dstmfmoffset++; + } + } - for (sec = 0; sec < drv->num_secs; sec++) { - uae_u8 secbuf[544]; - uae_u16 mfmbuf[544]; - int i; - uae_u32 deven, dodd; - uae_u32 hck = 0, dck = 0; - - secbuf[0] = secbuf[1] = 0x00; - secbuf[2] = secbuf[3] = 0xa1; - secbuf[4] = 0xff; - secbuf[5] = tr; - secbuf[6] = sec; - secbuf[7] = drv->num_secs - sec; - - for (i = 8; i < 24; i++) - secbuf[i] = 0; - - read_floppy_data (drv->diskfile, ti, sec * 512, &secbuf[32], 512); - - mfmbuf[0] = mfmbuf[1] = 0xaaaa; - mfmbuf[2] = mfmbuf[3] = 0x4489; - - deven = ((secbuf[4] << 24) | (secbuf[5] << 16) - | (secbuf[6] << 8) | (secbuf[7])); - dodd = deven >> 1; - deven &= 0x55555555; - dodd &= 0x55555555; - - mfmbuf[4] = dodd >> 16; - mfmbuf[5] = dodd; - mfmbuf[6] = deven >> 16; - mfmbuf[7] = deven; - - for (i = 8; i < 48; i++) - mfmbuf[i] = 0xaaaa; - for (i = 0; i < 512; i += 4) { - deven = ((secbuf[i + 32] << 24) | (secbuf[i + 33] << 16) - | (secbuf[i + 34] << 8) | (secbuf[i + 35])); - dodd = deven >> 1; - deven &= 0x55555555; - dodd &= 0x55555555; - mfmbuf[(i >> 1) + 32] = dodd >> 16; - mfmbuf[(i >> 1) + 33] = dodd; - mfmbuf[(i >> 1) + 256 + 32] = deven >> 16; - mfmbuf[(i >> 1) + 256 + 33] = deven; - } - - for (i = 4; i < 24; i += 2) - hck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; - - deven = dodd = hck; - dodd >>= 1; - mfmbuf[24] = dodd >> 16; - mfmbuf[25] = dodd; - mfmbuf[26] = deven >> 16; - mfmbuf[27] = deven; - - for (i = 32; i < 544; i += 2) - dck ^= (mfmbuf[i] << 16) | mfmbuf[i + 1]; - - deven = dodd = dck; - dodd >>= 1; - mfmbuf[28] = dodd >> 16; - mfmbuf[29] = dodd; - mfmbuf[30] = deven >> 16; - mfmbuf[31] = deven; - mfmcode (mfmbuf + 4, 544 - 4); - - for (i = 0; i < 544; i++) { - dstmfmbuf[dstmfmoffset % len] = mfmbuf[i]; - dstmfmoffset++; - } - } - - if (disk_debug_logging > 0) - write_log (L"amigados read track %d\n", tr); + if (disk_debug_logging > 0) + write_log (L"amigados read track %d\n", tr); } /* - * diskspare format - * - * 0 <4489> <4489> 0 track sector crchi, crclo, data[512] (520 bytes per sector) - * - * 0xAAAA 0x4489 0x4489 0x2AAA oddhi, oddlo, evenhi, evenlo, ... - * - * NOTE: data is MFM encoded using same method as ADOS header, not like ADOS data! - * - */ +* diskspare format +* +* 0 <4489> <4489> 0 track sector crchi, crclo, data[512] (520 bytes per sector) +* +* 0xAAAA 0x4489 0x4489 0x2AAA oddhi, oddlo, evenhi, evenlo, ... +* +* NOTE: data is MFM encoded using same method as ADOS header, not like ADOS data! +* +*/ static void decode_diskspare (drive *drv) { - int tr = drv->cyl * 2 + side; - int sec; - int dstmfmoffset = 0; - int size = 512 + 8; - uae_u16 *dstmfmbuf = drv->bigmfmbuf; - int len = drv->num_secs * size + FLOPPY_GAP_LEN; - - trackid *ti = drv->trackdata + tr; - memset (dstmfmbuf, 0xaa, len * 2); - dstmfmoffset += FLOPPY_GAP_LEN; - drv->skipoffset = (FLOPPY_GAP_LEN * 8) / 3 * 2; - drv->tracklen = len * 2 * 8; - - for (sec = 0; sec < drv->num_secs; sec++) { - uae_u8 secbuf[512 + 8]; - uae_u16 mfmbuf[512 + 8]; - int i; - uae_u32 deven, dodd; - uae_u16 chk; - - secbuf[0] = tr; - secbuf[1] = sec; - secbuf[2] = 0; - secbuf[3] = 0; - - read_floppy_data (drv->diskfile, ti, sec * 512, &secbuf[4], 512); - - mfmbuf[0] = 0xaaaa; - mfmbuf[1] = 0x4489; - mfmbuf[2] = 0x4489; - mfmbuf[3] = 0x2aaa; - - for (i = 0; i < 512; i += 4) { - deven = ((secbuf[i + 4] << 24) | (secbuf[i + 5] << 16) - | (secbuf[i + 6] << 8) | (secbuf[i + 7])); - dodd = deven >> 1; - deven &= 0x55555555; - dodd &= 0x55555555; - mfmbuf[i + 8 + 0] = dodd >> 16; - mfmbuf[i + 8 + 1] = dodd; - mfmbuf[i + 8 + 2] = deven >> 16; - mfmbuf[i + 8 + 3] = deven; - } - mfmcode (mfmbuf + 8, 512); - - i = 8; - chk = mfmbuf[i++] & 0x7fff; - while (i < 512 + 8) - chk ^= mfmbuf[i++]; - secbuf[2] = chk >> 8; - secbuf[3] = chk; - - deven = ((secbuf[0] << 24) | (secbuf[1] << 16) - | (secbuf[2] << 8) | (secbuf[3])); - dodd = deven >> 1; - deven &= 0x55555555; - dodd &= 0x55555555; - - mfmbuf[4] = dodd >> 16; - mfmbuf[5] = dodd; - mfmbuf[6] = deven >> 16; - mfmbuf[7] = deven; - mfmcode (mfmbuf + 4, 4); - - for (i = 0; i < 512 + 8; i++) { - dstmfmbuf[dstmfmoffset % len] = mfmbuf[i]; - dstmfmoffset++; - } - } - - if (disk_debug_logging > 0) - write_log (L"diskspare read track %d\n", tr); + int tr = drv->cyl * 2 + side; + int sec; + int dstmfmoffset = 0; + int size = 512 + 8; + uae_u16 *dstmfmbuf = drv->bigmfmbuf; + int len = drv->num_secs * size + FLOPPY_GAP_LEN; + + trackid *ti = drv->trackdata + tr; + memset (dstmfmbuf, 0xaa, len * 2); + dstmfmoffset += FLOPPY_GAP_LEN; + drv->skipoffset = (FLOPPY_GAP_LEN * 8) / 3 * 2; + drv->tracklen = len * 2 * 8; + + for (sec = 0; sec < drv->num_secs; sec++) { + uae_u8 secbuf[512 + 8]; + uae_u16 mfmbuf[512 + 8]; + int i; + uae_u32 deven, dodd; + uae_u16 chk; + + secbuf[0] = tr; + secbuf[1] = sec; + secbuf[2] = 0; + secbuf[3] = 0; + + read_floppy_data (drv->diskfile, ti, sec * 512, &secbuf[4], 512); + + mfmbuf[0] = 0xaaaa; + mfmbuf[1] = 0x4489; + mfmbuf[2] = 0x4489; + mfmbuf[3] = 0x2aaa; + + for (i = 0; i < 512; i += 4) { + deven = ((secbuf[i + 4] << 24) | (secbuf[i + 5] << 16) + | (secbuf[i + 6] << 8) | (secbuf[i + 7])); + dodd = deven >> 1; + deven &= 0x55555555; + dodd &= 0x55555555; + mfmbuf[i + 8 + 0] = dodd >> 16; + mfmbuf[i + 8 + 1] = dodd; + mfmbuf[i + 8 + 2] = deven >> 16; + mfmbuf[i + 8 + 3] = deven; + } + mfmcode (mfmbuf + 8, 512); + + i = 8; + chk = mfmbuf[i++] & 0x7fff; + while (i < 512 + 8) + chk ^= mfmbuf[i++]; + secbuf[2] = chk >> 8; + secbuf[3] = chk; + + deven = ((secbuf[0] << 24) | (secbuf[1] << 16) + | (secbuf[2] << 8) | (secbuf[3])); + dodd = deven >> 1; + deven &= 0x55555555; + dodd &= 0x55555555; + + mfmbuf[4] = dodd >> 16; + mfmbuf[5] = dodd; + mfmbuf[6] = deven >> 16; + mfmbuf[7] = deven; + mfmcode (mfmbuf + 4, 4); + + for (i = 0; i < 512 + 8; i++) { + dstmfmbuf[dstmfmoffset % len] = mfmbuf[i]; + dstmfmoffset++; + } + } + + if (disk_debug_logging > 0) + write_log (L"diskspare read track %d\n", tr); } static void drive_fill_bigbuf (drive * drv, int force) { - int tr = drv->cyl * 2 + side; - trackid *ti = drv->trackdata + tr; - - if ((!drv->diskfile && !drv->catweasel) || tr >= drv->num_tracks) { - track_reset (drv); - return; - } - - if (!force && drv->catweasel) { - drv->buffered_cyl = -1; - return; - } + int tr = drv->cyl * 2 + side; + trackid *ti = drv->trackdata + tr; - if (!force && drv->buffered_cyl == drv->cyl && drv->buffered_side == side) - return; - drv->indexoffset = 0; - drv->multi_revolution = 0; - drv->tracktiming[0] = 0; - drv->skipoffset = -1; + if ((!drv->diskfile && !drv->catweasel) || tr >= drv->num_tracks) { + track_reset (drv); + return; + } - if (drv->writediskfile && drv->writetrackdata[tr].bitlen > 0) { - int i; - trackid *wti = &drv->writetrackdata[tr]; - drv->tracklen = wti->bitlen; - read_floppy_data (drv->writediskfile, wti, 0, (uae_u8*)drv->bigmfmbuf, (wti->bitlen + 7) / 8); - for (i = 0; i < (drv->tracklen + 15) / 16; i++) { - uae_u16 *mfm = drv->bigmfmbuf + i; - uae_u8 *data = (uae_u8 *) mfm; - *mfm = 256 * *data + *(data + 1); + if (!force && drv->catweasel) { + drv->buffered_cyl = -1; + return; } - if (disk_debug_logging > 0) - write_log (L"track %d, length %d read from \"saveimage\"\n", tr, drv->tracklen); - } else if (drv->filetype == ADF_CATWEASEL) { + + if (!force && drv->buffered_cyl == drv->cyl && drv->buffered_side == side) + return; + drv->indexoffset = 0; + drv->multi_revolution = 0; + drv->tracktiming[0] = 0; + drv->skipoffset = -1; + + if (drv->writediskfile && drv->writetrackdata[tr].bitlen > 0) { + int i; + trackid *wti = &drv->writetrackdata[tr]; + drv->tracklen = wti->bitlen; + read_floppy_data (drv->writediskfile, wti, 0, (uae_u8*)drv->bigmfmbuf, (wti->bitlen + 7) / 8); + for (i = 0; i < (drv->tracklen + 15) / 16; i++) { + uae_u16 *mfm = drv->bigmfmbuf + i; + uae_u8 *data = (uae_u8 *) mfm; + *mfm = 256 * *data + *(data + 1); + } + if (disk_debug_logging > 0) + write_log (L"track %d, length %d read from \"saveimage\"\n", tr, drv->tracklen); + } else if (drv->filetype == ADF_CATWEASEL) { #ifdef CATWEASEL - drv->tracklen = 0; - if (!catweasel_disk_changed (drv->catweasel)) { - drv->tracklen = catweasel_fillmfm (drv->catweasel, drv->bigmfmbuf, side, drv->ddhd, 0); - } - drv->buffered_cyl = -1; - if (!drv->tracklen) { - track_reset (drv); - return; - } + drv->tracklen = 0; + if (!catweasel_disk_changed (drv->catweasel)) { + drv->tracklen = catweasel_fillmfm (drv->catweasel, drv->bigmfmbuf, side, drv->ddhd, 0); + } + drv->buffered_cyl = -1; + if (!drv->tracklen) { + track_reset (drv); + return; + } #endif - } else if (drv->filetype == ADF_IPF) { + } else if (drv->filetype == ADF_IPF) { #ifdef CAPS - caps_loadtrack (drv->bigmfmbuf, drv->tracktiming, drv - floppy, tr, &drv->tracklen, &drv->multi_revolution, &drv->skipoffset); + caps_loadtrack (drv->bigmfmbuf, drv->tracktiming, drv - floppy, tr, &drv->tracklen, &drv->multi_revolution, &drv->skipoffset); #endif - } else if (drv->filetype == ADF_FDI) { + } else if (drv->filetype == ADF_FDI) { #ifdef FDI2RAW - fdi2raw_loadtrack (drv->fdi, drv->bigmfmbuf, drv->tracktiming, tr, &drv->tracklen, &drv->indexoffset, &drv->multi_revolution, 1); + fdi2raw_loadtrack (drv->fdi, drv->bigmfmbuf, drv->tracktiming, tr, &drv->tracklen, &drv->indexoffset, &drv->multi_revolution, 1); #endif - } else if (ti->type == TRACK_PCDOS) { + } else if (ti->type == TRACK_PCDOS) { - decode_pcdos (drv); + decode_pcdos (drv); - } else if (ti->type == TRACK_AMIGADOS) { + } else if (ti->type == TRACK_AMIGADOS) { - decode_amigados (drv); + decode_amigados (drv); - } else if (ti->type == TRACK_DISKSPARE) { + } else if (ti->type == TRACK_DISKSPARE) { - decode_diskspare (drv); + decode_diskspare (drv); - } else { - int i; - int base_offset = ti->type == TRACK_RAW ? 0 : 1; - drv->tracklen = ti->bitlen + 16 * base_offset; - drv->bigmfmbuf[0] = ti->sync; - read_floppy_data (drv->diskfile, ti, 0, (uae_u8*)(drv->bigmfmbuf + base_offset), (ti->bitlen + 7) / 8); - for (i = base_offset; i < (drv->tracklen + 15) / 16; i++) { - uae_u16 *mfm = drv->bigmfmbuf + i; - uae_u8 *data = (uae_u8 *) mfm; - *mfm = 256 * *data + *(data + 1); + } else if (ti->type == TRACK_NONE) { + + ; + + } else { + int i; + int base_offset = ti->type == TRACK_RAW ? 0 : 1; + drv->tracklen = ti->bitlen + 16 * base_offset; + drv->bigmfmbuf[0] = ti->sync; + read_floppy_data (drv->diskfile, ti, 0, (uae_u8*)(drv->bigmfmbuf + base_offset), (ti->bitlen + 7) / 8); + for (i = base_offset; i < (drv->tracklen + 15) / 16; i++) { + uae_u16 *mfm = drv->bigmfmbuf + i; + uae_u8 *data = (uae_u8 *) mfm; + *mfm = 256 * *data + *(data + 1); + } + if (disk_debug_logging > 1) + write_log (L"rawtrack %d image offset=%x\n", tr, ti->offs); + } + drv->buffered_side = side; + drv->buffered_cyl = drv->cyl; + if (drv->tracklen == 0) { + drv->tracklen = FLOPPY_WRITE_LEN * drv->ddhd * 2 * 8; + memset (drv->bigmfmbuf, 0, FLOPPY_WRITE_LEN * 2 * drv->ddhd); } - if (disk_debug_logging > 1) - write_log (L"rawtrack %d image offset=%x\n", tr, ti->offs); - } - drv->buffered_side = side; - drv->buffered_cyl = drv->cyl; - if (drv->tracklen == 0) { - drv->tracklen = FLOPPY_WRITE_LEN * drv->ddhd * 2 * 8; - memset (drv->bigmfmbuf, 0, FLOPPY_WRITE_LEN * 2 * drv->ddhd); - } - drv->trackspeed = get_floppy_speed2 (drv); - updatemfmpos (drv); + drv->trackspeed = get_floppy_speed2 (drv); + updatemfmpos (drv); } /* Update ADF_EXT2 track header */ static void diskfile_update (struct zfile *diskfile, trackid *ti, int len, uae_u8 type) { - uae_u8 buf[2 + 2 + 4 + 4], *zerobuf; - - ti->bitlen = len; - zfile_fseek (diskfile, 8 + 4 + (2 + 2 + 4 + 4) * ti->track, SEEK_SET); - memset (buf, 0, sizeof buf); - ti->type = type; - buf[3] = ti->type; - do_put_mem_long ((uae_u32 *) (buf + 4), ti->len); - do_put_mem_long ((uae_u32 *) (buf + 8), ti->bitlen); - zfile_fwrite (buf, sizeof (buf), 1, diskfile); - if (ti->len > (len + 7) / 8) { - zerobuf = malloc (ti->len); - memset (zerobuf, 0, ti->len); - zfile_fseek (diskfile, ti->offs, SEEK_SET); - zfile_fwrite (zerobuf, 1, ti->len, diskfile); - free (zerobuf); - } - if (disk_debug_logging > 0) - write_log (L"track %d, raw track length %d written (total size %d)\n", ti->track, (ti->bitlen + 7) / 8, ti->len); + uae_u8 buf[2 + 2 + 4 + 4], *zerobuf; + + ti->bitlen = len; + zfile_fseek (diskfile, 8 + 4 + (2 + 2 + 4 + 4) * ti->track, SEEK_SET); + memset (buf, 0, sizeof buf); + ti->type = type; + buf[3] = ti->type; + do_put_mem_long ((uae_u32 *) (buf + 4), ti->len); + do_put_mem_long ((uae_u32 *) (buf + 8), ti->bitlen); + zfile_fwrite (buf, sizeof (buf), 1, diskfile); + if (ti->len > (len + 7) / 8) { + zerobuf = malloc (ti->len); + memset (zerobuf, 0, ti->len); + zfile_fseek (diskfile, ti->offs, SEEK_SET); + zfile_fwrite (zerobuf, 1, ti->len, diskfile); + free (zerobuf); + } + if (disk_debug_logging > 0) + write_log (L"track %d, raw track length %d written (total size %d)\n", ti->track, (ti->bitlen + 7) / 8, ti->len); } #define MFMMASK 0x55555555 static uae_u16 getmfmword (uae_u16 *mbuf, int shift) { - return (mbuf[0] << shift) | (mbuf[1] >> (16 - shift)); + return (mbuf[0] << shift) | (mbuf[1] >> (16 - shift)); } static uae_u32 getmfmlong (uae_u16 *mbuf, int shift) { - return ((getmfmword (mbuf, shift) << 16) | getmfmword (mbuf + 1, shift)) & MFMMASK; + return ((getmfmword (mbuf, shift) << 16) | getmfmword (mbuf + 1, shift)) & MFMMASK; } static int decode_buffer (uae_u16 *mbuf, int cyl, int drvsec, int ddhd, int filetype, int *drvsecp, int *sectable, int checkmode) { - int i, secwritten = 0; - int fwlen = FLOPPY_WRITE_LEN * ddhd; - int length = 2 * fwlen; - uae_u32 odd, even, chksum, id, dlong; - uae_u8 *secdata; - uae_u8 secbuf[544]; - uae_u16 *mend = mbuf + length; - int shift = 0; - - memset (sectable, 0, MAX_SECTORS * sizeof (int)); - memcpy (mbuf + fwlen, mbuf, fwlen * sizeof (uae_u16)); - mend -= (4 + 16 + 8 + 512); - while (secwritten < drvsec) { - int trackoffs; - - while (getmfmword (mbuf, shift) != 0x4489) { - if (mbuf >= mend) - return 1; - shift++; - if (shift == 16) { - shift = 0; - mbuf++; - } - } - while (getmfmword (mbuf, shift) == 0x4489) { - if (mbuf >= mend) - return 1; - mbuf++; - } + int i, secwritten = 0; + int fwlen = FLOPPY_WRITE_LEN * ddhd; + int length = 2 * fwlen; + uae_u32 odd, even, chksum, id, dlong; + uae_u8 *secdata; + uae_u8 secbuf[544]; + uae_u16 *mend = mbuf + length; + int shift = 0; + + memset (sectable, 0, MAX_SECTORS * sizeof (int)); + memcpy (mbuf + fwlen, mbuf, fwlen * sizeof (uae_u16)); + mend -= (4 + 16 + 8 + 512); + while (secwritten < drvsec) { + int trackoffs; + + while (getmfmword (mbuf, shift) != 0x4489) { + if (mbuf >= mend) + return 1; + shift++; + if (shift == 16) { + shift = 0; + mbuf++; + } + } + while (getmfmword (mbuf, shift) == 0x4489) { + if (mbuf >= mend) + return 1; + mbuf++; + } - odd = getmfmlong (mbuf, shift); - even = getmfmlong (mbuf + 2, shift); - mbuf += 4; - id = (odd << 1) | even; + odd = getmfmlong (mbuf, shift); + even = getmfmlong (mbuf + 2, shift); + mbuf += 4; + id = (odd << 1) | even; - trackoffs = (id & 0xff00) >> 8; - if (trackoffs + 1 > drvsec) { - write_log (L"Disk decode: weird sector number %d (%04x)\n", trackoffs, id); - if (filetype == ADF_EXT2) - return 2; - continue; - } - chksum = odd ^ even; - for (i = 0; i < 4; i++) { - odd = getmfmlong (mbuf, shift); - even = getmfmlong (mbuf + 8, shift); - mbuf += 2; - - dlong = (odd << 1) | even; - if (dlong && !checkmode) { - if (filetype == ADF_EXT2) - return 6; - secwritten = -200; - } - chksum ^= odd ^ even; - } /* could check here if the label is nonstandard */ - mbuf += 8; - odd = getmfmlong (mbuf, shift); - even = getmfmlong (mbuf + 2, shift); - mbuf += 4; - if (((odd << 1) | even) != chksum || ((id & 0x00ff0000) >> 16) != cyl * 2 + side) { - write_log (L"Disk decode: checksum error on sector %d header\n", trackoffs); - if (filetype == ADF_EXT2) - return 3; - continue; - } - odd = getmfmlong (mbuf, shift); - even = getmfmlong (mbuf + 2, shift); - mbuf += 4; - chksum = (odd << 1) | even; - secdata = secbuf + 32; - for (i = 0; i < 128; i++) { - odd = getmfmlong (mbuf, shift); - even = getmfmlong (mbuf + 256, shift); - mbuf += 2; - dlong = (odd << 1) | even; - *secdata++ = dlong >> 24; - *secdata++ = dlong >> 16; - *secdata++ = dlong >> 8; - *secdata++ = dlong; - chksum ^= odd ^ even; - } - if (chksum) { - write_log (L"Disk decode: sector %d, data checksum error\n", trackoffs); - if (filetype == ADF_EXT2) - return 4; - continue; - } - mbuf += 256; - sectable[trackoffs] = 1; - secwritten++; - memcpy (writebuffer + trackoffs * 512, secbuf + 32, 512); - } - if (filetype == ADF_EXT2 && (secwritten == 0 || secwritten < 0)) - return 5; - if (secwritten == 0) - write_log (L"Disk decode: unsupported format\n"); - if (secwritten < 0) - write_log (L"Disk decode: sector labels ignored\n"); - *drvsecp = drvsec; - return 0; + trackoffs = (id & 0xff00) >> 8; + if (trackoffs + 1 > drvsec) { + write_log (L"Disk decode: weird sector number %d (%04x)\n", trackoffs, id); + if (filetype == ADF_EXT2) + return 2; + continue; + } + chksum = odd ^ even; + for (i = 0; i < 4; i++) { + odd = getmfmlong (mbuf, shift); + even = getmfmlong (mbuf + 8, shift); + mbuf += 2; + + dlong = (odd << 1) | even; + if (dlong && !checkmode) { + if (filetype == ADF_EXT2) + return 6; + secwritten = -200; + } + chksum ^= odd ^ even; + } /* could check here if the label is nonstandard */ + mbuf += 8; + odd = getmfmlong (mbuf, shift); + even = getmfmlong (mbuf + 2, shift); + mbuf += 4; + if (((odd << 1) | even) != chksum || ((id & 0x00ff0000) >> 16) != cyl * 2 + side) { + write_log (L"Disk decode: checksum error on sector %d header\n", trackoffs); + if (filetype == ADF_EXT2) + return 3; + continue; + } + odd = getmfmlong (mbuf, shift); + even = getmfmlong (mbuf + 2, shift); + mbuf += 4; + chksum = (odd << 1) | even; + secdata = secbuf + 32; + for (i = 0; i < 128; i++) { + odd = getmfmlong (mbuf, shift); + even = getmfmlong (mbuf + 256, shift); + mbuf += 2; + dlong = (odd << 1) | even; + *secdata++ = dlong >> 24; + *secdata++ = dlong >> 16; + *secdata++ = dlong >> 8; + *secdata++ = dlong; + chksum ^= odd ^ even; + } + if (chksum) { + write_log (L"Disk decode: sector %d, data checksum error\n", trackoffs); + if (filetype == ADF_EXT2) + return 4; + continue; + } + mbuf += 256; + sectable[trackoffs] = 1; + secwritten++; + memcpy (writebuffer + trackoffs * 512, secbuf + 32, 512); + } + if (filetype == ADF_EXT2 && (secwritten == 0 || secwritten < 0)) + return 5; + if (secwritten == 0) + write_log (L"Disk decode: unsupported format\n"); + if (secwritten < 0) + write_log (L"Disk decode: sector labels ignored\n"); + *drvsecp = drvsec; + return 0; } static uae_u8 mfmdecode (uae_u16 **mfmp, int shift) { - uae_u16 mfm = getmfmword (*mfmp, shift); - uae_u8 out = 0; - int i; + uae_u16 mfm = getmfmword (*mfmp, shift); + uae_u8 out = 0; + int i; - (*mfmp)++; - mfm &= 0x5555; - for (i = 0; i < 8; i++) { - out >>= 1; - if (mfm & 1) - out |= 0x80; - mfm >>= 2; - } - return out; + (*mfmp)++; + mfm &= 0x5555; + for (i = 0; i < 8; i++) { + out >>= 1; + if (mfm & 1) + out |= 0x80; + mfm >>= 2; + } + return out; } static int drive_write_pcdos (drive *drv) { - int i; - int drvsec = drv->num_secs; - int fwlen = FLOPPY_WRITE_LEN * drv->ddhd; - int length = 2 * fwlen; - uae_u16 *mbuf = drv->bigmfmbuf; - uae_u16 *mend = mbuf + length; - int secwritten = 0, shift = 0, sector = -1; - int sectable[18]; - uae_u8 secbuf[3 + 1 + 512]; - uae_u8 mark; - uae_u16 crc; - - memset (sectable, 0, sizeof (sectable)); - memcpy (mbuf + fwlen, mbuf, fwlen * sizeof (uae_u16)); - mend -= 518; - secbuf[0] = secbuf[1] = secbuf[2] = 0xa1; - secbuf[3] = 0xfb; - - while (secwritten < drvsec) { - while (getmfmword (mbuf, shift) != 0x4489) { - if (mbuf >= mend) - return 1; - shift++; - if (shift == 16) { - shift = 0; - mbuf++; - } - } - while (getmfmword (mbuf, shift) == 0x4489) { - if (mbuf >= mend) - return 1; - mbuf++; - } - mark = mfmdecode(&mbuf, shift); - if (mark == 0xfe) { - uae_u8 tmp[8]; - uae_u8 cyl, head, size; - - cyl = mfmdecode (&mbuf, shift); - head = mfmdecode (&mbuf, shift); - sector = mfmdecode (&mbuf, shift); - size = mfmdecode (&mbuf, shift); - crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); - - tmp[0] = 0xa1; tmp[1] = 0xa1; tmp[2] = 0xa1; tmp[3] = mark; - tmp[4] = cyl; tmp[5] = head; tmp[6] = sector; tmp[7] = size; - if (get_crc16 (tmp, 8) != crc || cyl != drv->cyl || head != side || size != 2 || sector < 1 || sector > drv->num_secs) { - write_log (L"PCDOS: track %d, corrupted sector header\n", drv->cyl * 2 + side); - return 1; - } - sector--; - continue; - } - if (mark != 0xfb) { - write_log (L"PCDOS: track %d: unknown address mark %02X\n", drv->cyl * 2 + side, mark); - continue; - } - if (sector < 0) - continue; - for (i = 0; i < 512; i++) - secbuf[i + 4] = mfmdecode (&mbuf, shift); - crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); - if (get_crc16 (secbuf, 3 + 1 + 512) != crc) { - write_log (L"PCDOS: track %d, sector %d data checksum error\n", - drv->cyl * 2 + side, sector + 1); - continue; - } - sectable[sector] = 1; - secwritten++; - zfile_fseek (drv->diskfile, drv->trackdata[drv->cyl * 2 + side].offs + sector * 512, SEEK_SET); - zfile_fwrite (secbuf + 4, sizeof (uae_u8), 512, drv->diskfile); - write_log (L"PCDOS: track %d sector %d written\n", drv->cyl * 2 + side, sector + 1); - sector = -1; - } - if (secwritten != drv->num_secs) - write_log (L"PCDOS: track %d, %d corrupted sectors ignored\n", - drv->cyl * 2 + side, drv->num_secs - secwritten); - return 0; + int i; + int drvsec = drv->num_secs; + int fwlen = FLOPPY_WRITE_LEN * drv->ddhd; + int length = 2 * fwlen; + uae_u16 *mbuf = drv->bigmfmbuf; + uae_u16 *mend = mbuf + length; + int secwritten = 0, shift = 0, sector = -1; + int sectable[18]; + uae_u8 secbuf[3 + 1 + 512]; + uae_u8 mark; + uae_u16 crc; + + memset (sectable, 0, sizeof (sectable)); + memcpy (mbuf + fwlen, mbuf, fwlen * sizeof (uae_u16)); + mend -= 518; + secbuf[0] = secbuf[1] = secbuf[2] = 0xa1; + secbuf[3] = 0xfb; + + while (secwritten < drvsec) { + while (getmfmword (mbuf, shift) != 0x4489) { + if (mbuf >= mend) + return 1; + shift++; + if (shift == 16) { + shift = 0; + mbuf++; + } + } + while (getmfmword (mbuf, shift) == 0x4489) { + if (mbuf >= mend) + return 1; + mbuf++; + } + mark = mfmdecode(&mbuf, shift); + if (mark == 0xfe) { + uae_u8 tmp[8]; + uae_u8 cyl, head, size; + + cyl = mfmdecode (&mbuf, shift); + head = mfmdecode (&mbuf, shift); + sector = mfmdecode (&mbuf, shift); + size = mfmdecode (&mbuf, shift); + crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); + + tmp[0] = 0xa1; tmp[1] = 0xa1; tmp[2] = 0xa1; tmp[3] = mark; + tmp[4] = cyl; tmp[5] = head; tmp[6] = sector; tmp[7] = size; + if (get_crc16 (tmp, 8) != crc || cyl != drv->cyl || head != side || size != 2 || sector < 1 || sector > drv->num_secs) { + write_log (L"PCDOS: track %d, corrupted sector header\n", drv->cyl * 2 + side); + return 1; + } + sector--; + continue; + } + if (mark != 0xfb) { + write_log (L"PCDOS: track %d: unknown address mark %02X\n", drv->cyl * 2 + side, mark); + continue; + } + if (sector < 0) + continue; + for (i = 0; i < 512; i++) + secbuf[i + 4] = mfmdecode (&mbuf, shift); + crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); + if (get_crc16 (secbuf, 3 + 1 + 512) != crc) { + write_log (L"PCDOS: track %d, sector %d data checksum error\n", + drv->cyl * 2 + side, sector + 1); + continue; + } + sectable[sector] = 1; + secwritten++; + zfile_fseek (drv->diskfile, drv->trackdata[drv->cyl * 2 + side].offs + sector * 512, SEEK_SET); + zfile_fwrite (secbuf + 4, sizeof (uae_u8), 512, drv->diskfile); + write_log (L"PCDOS: track %d sector %d written\n", drv->cyl * 2 + side, sector + 1); + sector = -1; + } + if (secwritten != drv->num_secs) + write_log (L"PCDOS: track %d, %d corrupted sectors ignored\n", + drv->cyl * 2 + side, drv->num_secs - secwritten); + return 0; } static int drive_write_adf_amigados (drive *drv) { - int drvsec, i; - int sectable[MAX_SECTORS]; + int drvsec, i; + int sectable[MAX_SECTORS]; - if (decode_buffer (drv->bigmfmbuf, drv->cyl, drv->num_secs, drv->ddhd, drv->filetype, &drvsec, sectable, 0)) - return 2; - if (!drvsec) - return 2; + if (decode_buffer (drv->bigmfmbuf, drv->cyl, drv->num_secs, drv->ddhd, drv->filetype, &drvsec, sectable, 0)) + return 2; + if (!drvsec) + return 2; - if (drv->filetype == ADF_EXT2) - diskfile_update (drv->diskfile, &drv->trackdata[drv->cyl * 2 + side], drvsec * 512 * 8, TRACK_AMIGADOS); - for (i = 0; i < drvsec; i++) { - zfile_fseek (drv->diskfile, drv->trackdata[drv->cyl * 2 + side].offs + i * 512, SEEK_SET); - zfile_fwrite (writebuffer + i * 512, sizeof (uae_u8), 512, drv->diskfile); - } + if (drv->filetype == ADF_EXT2) + diskfile_update (drv->diskfile, &drv->trackdata[drv->cyl * 2 + side], drvsec * 512 * 8, TRACK_AMIGADOS); + for (i = 0; i < drvsec; i++) { + zfile_fseek (drv->diskfile, drv->trackdata[drv->cyl * 2 + side].offs + i * 512, SEEK_SET); + zfile_fwrite (writebuffer + i * 512, sizeof (uae_u8), 512, drv->diskfile); + } - return 0; + return 0; } /* write raw track to disk file */ static int drive_write_ext2 (uae_u16 *bigmfmbuf, struct zfile *diskfile, trackid *ti, int tracklen) { - int len, i; - - len = (tracklen + 7) / 8; - if (len > ti->len) { - write_log (L"disk raw write: image file's track %d is too small (%d < %d)!\n", ti->track, ti->len, len); - len = ti->len; - } - diskfile_update (diskfile, ti, tracklen, TRACK_RAW); - for (i = 0; i < ti->len / 2; i++) { - uae_u16 *mfm = bigmfmbuf + i; - uae_u16 *mfmw = bigmfmbufw + i; - uae_u8 *data = (uae_u8 *) mfm; - *mfmw = 256 * *data + *(data + 1); - } - zfile_fseek (diskfile, ti->offs, SEEK_SET); - zfile_fwrite (bigmfmbufw, 1, len, diskfile); - return 1; + int len, i; + + len = (tracklen + 7) / 8; + if (len > ti->len) { + write_log (L"disk raw write: image file's track %d is too small (%d < %d)!\n", ti->track, ti->len, len); + len = ti->len; + } + diskfile_update (diskfile, ti, tracklen, TRACK_RAW); + for (i = 0; i < ti->len / 2; i++) { + uae_u16 *mfm = bigmfmbuf + i; + uae_u16 *mfmw = bigmfmbufw + i; + uae_u8 *data = (uae_u8 *) mfm; + *mfmw = 256 * *data + *(data + 1); + } + zfile_fseek (diskfile, ti->offs, SEEK_SET); + zfile_fwrite (bigmfmbufw, 1, len, diskfile); + return 1; } static void drive_write_data (drive * drv) { - int ret = -1; - static int warned; - - if (drive_writeprotected (drv)) { - /* read original track back because we didn't really write anything */ - drv->buffered_side = 2; - return; - } - if (drv->writediskfile) { - drive_write_ext2 (drv->bigmfmbuf, drv->writediskfile, &drv->writetrackdata[drv->cyl * 2 + side], - longwritemode ? dsklength2 * 8 : drv->tracklen); - } - switch (drv->filetype) { - case ADF_NORMAL: - if (drive_write_adf_amigados (drv)) { - if (!warned) - notify_user (NUMSG_NEEDEXT2); - warned = 1; - } - return; - case ADF_EXT1: - break; - case ADF_EXT2: - if (!longwritemode) - ret = drive_write_adf_amigados (drv); - if (ret) { - write_log (L"not an amigados track %d (error %d), writing as raw track\n", drv->cyl * 2 + side, ret); - drive_write_ext2 (drv->bigmfmbuf, drv->diskfile, &drv->trackdata[drv->cyl * 2 + side], - longwritemode ? dsklength2 * 8 : drv->tracklen); - } - return; - case ADF_IPF: - break; - case ADF_PCDOS: - ret = drive_write_pcdos (drv); - if (ret) - write_log (L"not a PC formatted track %d (error %d)\n", drv->cyl * 2 + side, ret); - break; - } - drv->tracktiming[0] = 0; + int ret = -1; + int tr = drv->cyl * 2 + side; + static int warned; + + if (drive_writeprotected (drv) || drv->trackdata[tr].type == TRACK_NONE) { + /* read original track back because we didn't really write anything */ + drv->buffered_side = 2; + return; + } + if (drv->writediskfile) { + drive_write_ext2 (drv->bigmfmbuf, drv->writediskfile, &drv->writetrackdata[tr], + longwritemode ? dsklength2 * 8 : drv->tracklen); + } + switch (drv->filetype) { + case ADF_NORMAL: + if (drive_write_adf_amigados (drv)) { + if (!warned) + notify_user (NUMSG_NEEDEXT2); + warned = 1; + } + return; + case ADF_EXT1: + break; + case ADF_EXT2: + if (!longwritemode) + ret = drive_write_adf_amigados (drv); + if (ret) { + write_log (L"not an amigados track %d (error %d), writing as raw track\n", drv->cyl * 2 + side, ret); + drive_write_ext2 (drv->bigmfmbuf, drv->diskfile, &drv->trackdata[drv->cyl * 2 + side], + longwritemode ? dsklength2 * 8 : drv->tracklen); + } + return; + case ADF_IPF: + break; + case ADF_PCDOS: + ret = drive_write_pcdos (drv); + if (ret) + write_log (L"not a PC formatted track %d (error %d)\n", drv->cyl * 2 + side, ret); + break; + } + drv->tracktiming[0] = 0; } static void drive_eject (drive * drv) { #ifdef DRIVESOUND - driveclick_insert (drv - floppy, 1); + driveclick_insert (drv - floppy, 1); #endif - gui_disk_image_change (drv - floppy, NULL); - drive_image_free (drv); - drv->dskchange = 1; - drv->ddhd = 1; - drv->dskchange_time = 0; - drv->dskready = 0; - drv->dskready_time = 0; - drv->dskready_down_time = 0; - drv->crc32 = 0; - drive_settype_id (drv); /* Back to 35 DD */ - if (disk_debug_logging > 0) - write_log (L"eject drive %d\n", drv - &floppy[0]); - if (input_recording > 0) { - inprec_rstart (INPREC_DISKREMOVE); - inprec_ru8 (drv - floppy); - inprec_rend (); - } + gui_disk_image_change (drv - floppy, NULL); + drive_image_free (drv); + drv->dskchange = 1; + drv->ddhd = 1; + drv->dskchange_time = 0; + drv->dskready = 0; + drv->dskready_time = 0; + drv->dskready_down_time = 0; + drv->crc32 = 0; + drive_settype_id (drv); /* Back to 35 DD */ + if (disk_debug_logging > 0) + write_log (L"eject drive %d\n", drv - &floppy[0]); + if (input_recording > 0) { + inprec_rstart (INPREC_DISKREMOVE); + inprec_ru8 (drv - floppy); + inprec_rend (); + } } /* We use this function if we have no Kickstart ROM. - * No error checking - we trust our luck. */ +* No error checking - we trust our luck. */ void DISK_ersatz_read (int tr, int sec, uaecptr dest) { - uae_u8 *dptr = get_real_address (dest); - zfile_fseek (floppy[0].diskfile, floppy[0].trackdata[tr].offs + sec * 512, SEEK_SET); - zfile_fread (dptr, 1, 512, floppy[0].diskfile); + uae_u8 *dptr = get_real_address (dest); + zfile_fseek (floppy[0].diskfile, floppy[0].trackdata[tr].offs + sec * 512, SEEK_SET); + zfile_fread (dptr, 1, 512, floppy[0].diskfile); } /* type: 0=regular, 1=ext2adf */ /* adftype: 0=DD,1=HD,2=DD PC,3=HD PC,4=525SD */ void disk_creatediskfile (TCHAR *name, int type, drive_type adftype, TCHAR *disk_name) { - struct zfile *f; - int i, l, file_size, tracks, track_len, sectors; - uae_u8 *chunk = NULL; - uae_u8 tmp[3*4]; - uae_char *s; - - if (disk_name == NULL || _tcslen (disk_name) == 0) - disk_name = L"empty"; - - if (type == 1) - tracks = 2 * 83; - else - tracks = 2 * 80; - file_size = 880 * 1024; - sectors = 11; - if (adftype == 2 || adftype == 3) { - file_size = 720 * 1024; - sectors = 9; - } - track_len = FLOPPY_WRITE_LEN * 2; - if (adftype == 1 || adftype == 3) { - file_size *= 2; - track_len *= 2; - } else if (adftype == 4) { - file_size /= 2; - tracks /= 2; - } - - f = zfile_fopen (name, L"wb", 0); - chunk = xmalloc (32768); - if (f && chunk) { - int cylsize = sectors * 2 * 512; - memset (chunk, 0, 32768); - if (type == 0) { - for (i = 0; i < file_size; i += cylsize) { - memset(chunk, 0, cylsize); - if (adftype <= 1) { - if (i == 0) { - /* boot block */ - strcpy (chunk, "DOS"); - } else if (i == file_size / 2) { - int block = file_size / 1024; - /* root block */ - chunk[0+3] = 2; - chunk[12+3] = 0x48; - chunk[312] = chunk[313] = chunk[314] = chunk[315] = (uae_u8)0xff; - chunk[316+2] = (block + 1) >> 8; chunk[316+3] = (block + 1) & 255; - s = ua (disk_name); - chunk[432] = strlen (s); - strcpy (chunk + 433, s); - xfree (s); - chunk[508 + 3] = 1; - disk_date (chunk + 420); - memcpy (chunk + 472, chunk + 420, 3 * 4); - memcpy (chunk + 484, chunk + 420, 3 * 4); - disk_checksum(chunk, chunk + 20); - /* bitmap block */ - memset (chunk + 512 + 4, 0xff, 2 * file_size / (1024 * 8)); - if (adftype == 0) - chunk[512 + 0x72] = 0x3f; - else - chunk[512 + 0xdc] = 0x3f; - disk_checksum(chunk + 512, chunk + 512); - } + struct zfile *f; + int i, l, file_size, tracks, track_len, sectors; + uae_u8 *chunk = NULL; + uae_u8 tmp[3*4]; + uae_char *s; + + if (disk_name == NULL || _tcslen (disk_name) == 0) + disk_name = L"empty"; + + if (type == 1) + tracks = 2 * 83; + else + tracks = 2 * 80; + file_size = 880 * 1024; + sectors = 11; + if (adftype == 2 || adftype == 3) { + file_size = 720 * 1024; + sectors = 9; + } + track_len = FLOPPY_WRITE_LEN * 2; + if (adftype == 1 || adftype == 3) { + file_size *= 2; + track_len *= 2; + } else if (adftype == 4) { + file_size /= 2; + tracks /= 2; + } + + f = zfile_fopen (name, L"wb", 0); + chunk = xmalloc (32768); + if (f && chunk) { + int cylsize = sectors * 2 * 512; + memset (chunk, 0, 32768); + if (type == 0) { + for (i = 0; i < file_size; i += cylsize) { + memset(chunk, 0, cylsize); + if (adftype <= 1) { + if (i == 0) { + /* boot block */ + strcpy (chunk, "DOS"); + } else if (i == file_size / 2) { + int block = file_size / 1024; + /* root block */ + chunk[0+3] = 2; + chunk[12+3] = 0x48; + chunk[312] = chunk[313] = chunk[314] = chunk[315] = (uae_u8)0xff; + chunk[316+2] = (block + 1) >> 8; chunk[316+3] = (block + 1) & 255; + s = ua (disk_name); + chunk[432] = strlen (s); + strcpy (chunk + 433, s); + xfree (s); + chunk[508 + 3] = 1; + disk_date (chunk + 420); + memcpy (chunk + 472, chunk + 420, 3 * 4); + memcpy (chunk + 484, chunk + 420, 3 * 4); + disk_checksum(chunk, chunk + 20); + /* bitmap block */ + memset (chunk + 512 + 4, 0xff, 2 * file_size / (1024 * 8)); + if (adftype == 0) + chunk[512 + 0x72] = 0x3f; + else + chunk[512 + 0xdc] = 0x3f; + disk_checksum(chunk + 512, chunk + 512); + } + } + zfile_fwrite (chunk, cylsize, 1, f); + } + } else { + l = track_len; + zfile_fwrite ("UAE-1ADF", 8, 1, f); + tmp[0] = 0; tmp[1] = 0; /* flags (reserved) */ + tmp[2] = 0; tmp[3] = tracks; /* number of tracks */ + zfile_fwrite (tmp, 4, 1, f); + tmp[0] = 0; tmp[1] = 0; /* flags (reserved) */ + tmp[2] = 0; tmp[3] = 1; /* track type */ + tmp[4] = 0; tmp[5] = 0; tmp[6]=(uae_u8)(l >> 8); tmp[7] = (uae_u8)l; + tmp[8] = 0; tmp[9] = 0; tmp[10] = 0; tmp[11] = 0; + for (i = 0; i < tracks; i++) + zfile_fwrite (tmp, sizeof (tmp), 1, f); + for (i = 0; i < tracks; i++) + zfile_fwrite (chunk, l, 1, f); } - zfile_fwrite (chunk, cylsize, 1, f); - } - } else { - l = track_len; - zfile_fwrite ("UAE-1ADF", 8, 1, f); - tmp[0] = 0; tmp[1] = 0; /* flags (reserved) */ - tmp[2] = 0; tmp[3] = tracks; /* number of tracks */ - zfile_fwrite (tmp, 4, 1, f); - tmp[0] = 0; tmp[1] = 0; /* flags (reserved) */ - tmp[2] = 0; tmp[3] = 1; /* track type */ - tmp[4] = 0; tmp[5] = 0; tmp[6]=(uae_u8)(l >> 8); tmp[7] = (uae_u8)l; - tmp[8] = 0; tmp[9] = 0; tmp[10] = 0; tmp[11] = 0; - for (i = 0; i < tracks; i++) - zfile_fwrite (tmp, sizeof (tmp), 1, f); - for (i = 0; i < tracks; i++) - zfile_fwrite (chunk, l, 1, f); - } - } - xfree (chunk); - zfile_fclose (f); - if (f) - DISK_history_add (name, -1, 0); + } + xfree (chunk); + zfile_fclose (f); + if (f) + DISK_history_add (name, -1, 0); } int disk_getwriteprotect (const TCHAR *name) { - int needwritefile; - drive_type drvtype; - return diskfile_iswriteprotect (name, &needwritefile, &drvtype); + int needwritefile; + drive_type drvtype; + return diskfile_iswriteprotect (name, &needwritefile, &drvtype); } static void diskfile_readonly (const TCHAR *name, int readonly) { - struct _stat64 st; - int mode, oldmode; + struct _stat64 st; + int mode, oldmode; - if (stat (name, &st)) - return; - oldmode = mode = st.st_mode; - mode &= ~FILEFLAG_WRITE; - if (!readonly) mode |= FILEFLAG_WRITE; - if (mode != oldmode) - chmod (name, mode); + if (stat (name, &st)) + return; + oldmode = mode = st.st_mode; + mode &= ~FILEFLAG_WRITE; + if (!readonly) mode |= FILEFLAG_WRITE; + if (mode != oldmode) + chmod (name, mode); } -static void setdskchangetime(drive *drv, int dsktime) +static void setdskchangetime (drive *drv, int dsktime) { - int i; - /* prevent multiple disk insertions at the same time */ - if (drv->dskchange_time > 0) - return; - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - if (&floppy[i] != drv && floppy[i].dskchange_time > 0 && floppy[i].dskchange_time + 5 >= dsktime) { - dsktime = floppy[i].dskchange_time + 5; + int i; + /* prevent multiple disk insertions at the same time */ + if (drv->dskchange_time > 0) + return; + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { + if (&floppy[i] != drv && floppy[i].dskchange_time > 0 && floppy[i].dskchange_time + 5 >= dsktime) { + dsktime = floppy[i].dskchange_time + 5; + } } - } - drv->dskchange_time = dsktime; - if (disk_debug_logging > 0) - write_log (L"delayed insert enable %d\n", dsktime); + drv->dskchange_time = dsktime; + if (disk_debug_logging > 0) + write_log (L"delayed insert enable %d\n", dsktime); } void DISK_reinsert (int num) { - drive_eject (&floppy[num]); - setdskchangetime (&floppy[num], 20); + drive_eject (&floppy[num]); + setdskchangetime (&floppy[num], 20); } int disk_setwriteprotect (int num, const TCHAR *name, int protect) { - int needwritefile, oldprotect; - struct zfile *zf1, *zf2; - int wrprot1, wrprot2, i; - TCHAR *name2; - drive_type drvtype; + int needwritefile, oldprotect; + struct zfile *zf1, *zf2; + int wrprot1, wrprot2, i; + TCHAR *name2; + drive_type drvtype; - oldprotect = diskfile_iswriteprotect (name, &needwritefile, &drvtype); - zf1 = DISK_validate_filename (name, 1, &wrprot1, NULL); - if (!zf1) - return 0; - if (zfile_iscompressed (zf1)) - wrprot1 = 1; - zfile_fclose (zf1); - zf2 = getwritefile (name, &wrprot2); - name2 = DISK_get_saveimagepath (name); - - if (needwritefile && zf2 == 0) - disk_creatediskfile (name2, 1, drvtype, NULL); - zfile_fclose (zf2); - if (protect && iswritefileempty (name)) { - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - if (!_tcscmp (name, floppy[i].newname)) - drive_eject (&floppy[i]); + oldprotect = diskfile_iswriteprotect (name, &needwritefile, &drvtype); + zf1 = DISK_validate_filename (name, 1, &wrprot1, NULL); + if (!zf1) + return 0; + if (zfile_iscompressed (zf1)) + wrprot1 = 1; + zfile_fclose (zf1); + zf2 = getwritefile (name, &wrprot2); + name2 = DISK_get_saveimagepath (name); + + if (needwritefile && zf2 == 0) + disk_creatediskfile (name2, 1, drvtype, NULL); + zfile_fclose (zf2); + if (protect && iswritefileempty (name)) { + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { + if (!_tcscmp (name, floppy[i].newname)) + drive_eject (&floppy[i]); + } + _wunlink (name2); } - _wunlink (name2); - } - if (!needwritefile) - diskfile_readonly (name, protect); - diskfile_readonly (name2, protect); - DISK_reinsert (num); - return 1; + if (!needwritefile) + diskfile_readonly (name, protect); + diskfile_readonly (name2, protect); + DISK_reinsert (num); + return 1; } void disk_eject (int num) { - gui_filename (num, L""); - drive_eject (floppy + num); - *currprefs.df[num] = *changed_prefs.df[num] = 0; - floppy[num].newname[0] = 0; - update_drive_gui (num); + gui_filename (num, L""); + drive_eject (floppy + num); + *currprefs.df[num] = *changed_prefs.df[num] = 0; + floppy[num].newname[0] = 0; + update_drive_gui (num); } int DISK_history_add (const TCHAR *name, int idx, int donotcheck) { - int i; + int i; - if (idx >= MAX_PREVIOUS_FLOPPIES) - return 0; - if (name == NULL) { - dfxhistory[idx][0] = 0; - return 1; - } - if (name[0] == 0) - return 0; - if (!donotcheck) { - if (!zfile_exists (name)) - return 0; - } - if (idx >= 0) { if (idx >= MAX_PREVIOUS_FLOPPIES) - return 0; - dfxhistory[idx][0] = 0; - for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) { - if (!_tcscmp (dfxhistory[i], name)) return 0; + if (name == NULL) { + dfxhistory[idx][0] = 0; + return 1; } - _tcscpy (dfxhistory[idx], name); - return 1; - } - for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) { - if (!_tcscmp (dfxhistory[i], name)) { - while (i < MAX_PREVIOUS_FLOPPIES - 1) { - _tcscpy (dfxhistory[i], dfxhistory[i + 1]); - i++; - } - dfxhistory[MAX_PREVIOUS_FLOPPIES - 1][0] = 0; - break; + if (name[0] == 0) + return 0; + if (!donotcheck) { + if (!zfile_exists (name)) + return 0; + } + if (idx >= 0) { + if (idx >= MAX_PREVIOUS_FLOPPIES) + return 0; + dfxhistory[idx][0] = 0; + for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) { + if (!_tcscmp (dfxhistory[i], name)) + return 0; + } + _tcscpy (dfxhistory[idx], name); + return 1; + } + for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) { + if (!_tcscmp (dfxhistory[i], name)) { + while (i < MAX_PREVIOUS_FLOPPIES - 1) { + _tcscpy (dfxhistory[i], dfxhistory[i + 1]); + i++; + } + dfxhistory[MAX_PREVIOUS_FLOPPIES - 1][0] = 0; + break; + } } - } - for (i = MAX_PREVIOUS_FLOPPIES - 2; i >= 0; i--) - _tcscpy (dfxhistory[i + 1], dfxhistory[i]); - _tcscpy (dfxhistory[0], name); - return 1; + for (i = MAX_PREVIOUS_FLOPPIES - 2; i >= 0; i--) + _tcscpy (dfxhistory[i + 1], dfxhistory[i]); + _tcscpy (dfxhistory[0], name); + return 1; } TCHAR *DISK_history_get (int idx) { - if (idx >= MAX_PREVIOUS_FLOPPIES) - return 0; - return dfxhistory[idx]; + if (idx >= MAX_PREVIOUS_FLOPPIES) + return 0; + return dfxhistory[idx]; } static void disk_insert_2 (int num, const TCHAR *name, int forced) { - drive *drv = floppy + num; - - if (forced) { - drive_insert (drv, &currprefs, num, name); - return; - } - if (!_tcscmp (currprefs.df[num], name)) - return; - _tcscpy (drv->newname, name); - _tcscpy (currprefs.df[num], name); - DISK_history_add (name, -1, 0); - if (name[0] == 0) { - disk_eject (num); - } else if (!drive_empty(drv) || drv->dskchange_time > 0) { - drive_eject (drv); - /* set dskchange_time, disk_insert() will be - * called from DISK_check_change() after 2 second delay - * this makes sure that all programs detect disk change correctly - */ - setdskchangetime (drv, 20); - } else { - setdskchangetime (drv, 1); - } + drive *drv = floppy + num; + + if (forced) { + drive_insert (drv, &currprefs, num, name); + return; + } + if (!_tcscmp (currprefs.df[num], name)) + return; + _tcscpy (drv->newname, name); + _tcscpy (currprefs.df[num], name); + DISK_history_add (name, -1, 0); + if (name[0] == 0) { + disk_eject (num); + } else if (!drive_empty(drv) || drv->dskchange_time > 0) { + drive_eject (drv); + /* set dskchange_time, disk_insert() will be + * called from DISK_check_change() after 2 second delay + * this makes sure that all programs detect disk change correctly + */ + setdskchangetime (drv, 20); + } else { + setdskchangetime (drv, 1); + } } void disk_insert (int num, const TCHAR *name) { - target_addtorecent (name, 0); - disk_insert_2 (num, name, 0); + target_addtorecent (name, 0); + disk_insert_2 (num, name, 0); } void disk_insert_force (int num, const TCHAR *name) { - disk_insert_2 (num, name, 1); + disk_insert_2 (num, name, 1); } void DISK_check_change (void) { - int i; + int i; - if (currprefs.floppy_speed != changed_prefs.floppy_speed) - currprefs.floppy_speed = changed_prefs.floppy_speed; - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - drive *drv = floppy + i; - gui_lock (); - if (currprefs.dfxtype[i] != changed_prefs.dfxtype[i]) { - currprefs.dfxtype[i] = changed_prefs.dfxtype[i]; - reset_drive (i); + if (currprefs.floppy_speed != changed_prefs.floppy_speed) + currprefs.floppy_speed = changed_prefs.floppy_speed; + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { + drive *drv = floppy + i; + gui_lock (); + if (currprefs.dfxtype[i] != changed_prefs.dfxtype[i]) { + currprefs.dfxtype[i] = changed_prefs.dfxtype[i]; + reset_drive (i); #ifdef RETROPLATFORM - rp_floppydrive_change (i, currprefs.dfxtype[i] >= 0 ? 1 : 0); + rp_floppydrive_change (i, currprefs.dfxtype[i] >= 0 ? 1 : 0); #endif - } - if (drv->dskchange_time == 0 && _tcscmp (currprefs.df[i], changed_prefs.df[i])) - disk_insert (i, changed_prefs.df[i]); - gui_unlock (); - if (drv->dskready_down_time > 0) - drv->dskready_down_time--; - /* emulate drive motor turn on time */ - if (drv->dskready_time > 0 && !drive_empty(drv)) { - drv->dskready_time--; - if (drv->dskready_time == 0) - drv->dskready = 1; - } - /* delay until new disk image is inserted */ - if (drv->dskchange_time) { - drv->dskchange_time--; - if (drv->dskchange_time == 0) { - drive_insert (drv, &currprefs, i, drv->newname); - if (disk_debug_logging > 0) - write_log (L"delayed insert, drive %d, image '%s'\n", i, drv->newname); - update_drive_gui (i); + } + if (drv->dskchange_time == 0 && _tcscmp (currprefs.df[i], changed_prefs.df[i])) + disk_insert (i, changed_prefs.df[i]); + gui_unlock (); + if (drv->dskready_down_time > 0) + drv->dskready_down_time--; + /* emulate drive motor turn on time */ + if (drv->dskready_time > 0 && !drive_empty(drv)) { + drv->dskready_time--; + if (drv->dskready_time == 0) + drv->dskready = 1; + } + /* delay until new disk image is inserted */ + if (drv->dskchange_time) { + drv->dskchange_time--; + if (drv->dskchange_time == 0) { + drive_insert (drv, &currprefs, i, drv->newname); + if (disk_debug_logging > 0) + write_log (L"delayed insert, drive %d, image '%s'\n", i, drv->newname); + update_drive_gui (i); - } + } + } } - } } int disk_empty (int num) { - return drive_empty (floppy + num); + return drive_empty (floppy + num); } static TCHAR *tobin(uae_u8 v) { - int i; - static TCHAR buf[10]; - for( i = 7; i >= 0; i--) - buf[7 - i] = v & (1 << i) ? '1' : '0'; - buf[i] = 0; - return buf; + int i; + static TCHAR buf[10]; + for( i = 7; i >= 0; i--) + buf[7 - i] = v & (1 << i) ? '1' : '0'; + buf[i] = 0; + return buf; } void DISK_select (uae_u8 data) { - int step_pulse, lastselected, dr; - static uae_u8 prevdata; - static int step; + int step_pulse, lastselected, dr; + static uae_u8 prevdata; + static int step; - lastselected = selected; - selected = (data >> 3) & 15; - side = 1 - ((data >> 2) & 1); - direction = (data >> 1) & 1; - step_pulse = data & 1; + lastselected = selected; + selected = (data >> 3) & 15; + side = 1 - ((data >> 2) & 1); + direction = (data >> 1) & 1; + step_pulse = data & 1; - if (disk_debug_logging > 1) - write_log (L"%08X %02X %s drvmask=%x", M68K_GETPC, data, tobin(data), selected ^ 15); + if (disk_debug_logging > 1) + write_log (L"%08X %02X %s drvmask=%x", M68K_GETPC, data, tobin(data), selected ^ 15); #ifdef AMAX - if (currprefs.amaxromfile[0]) - amax_disk_select (data, prevdata); + if (currprefs.amaxromfile[0]) + amax_disk_select (data, prevdata); #endif - if ((prevdata & 0x80) != (data & 0x80)) { - for (dr = 0; dr < 4; dr++) { - if (floppy[dr].indexhackmode > 1 && !(selected & (1 << dr))) { - floppy[dr].indexhack = 1; + if ((prevdata & 0x80) != (data & 0x80)) { + for (dr = 0; dr < 4; dr++) { + if (floppy[dr].indexhackmode > 1 && !(selected & (1 << dr))) { + floppy[dr].indexhack = 1; + if (disk_debug_logging > 1) + write_log (L" indexhack!"); + } + } + } + + if (disk_debug_logging > 1) { + write_log (L" %d%d%d%d% ", (selected & 1) ? 0 : 1, (selected & 2) ? 0 : 1, (selected & 4) ? 0 : 1, (selected & 8) ? 0 : 1); + if ((prevdata & 0x80) != (data & 0x80)) + write_log (L" dskmotor %d ", (data & 0x80) ? 1 : 0); + if ((prevdata & 0x02) != (data & 0x02)) + write_log (L" direct %d ", (data & 0x02) ? 1 : 0); + if ((prevdata & 0x04) != (data & 0x04)) + write_log (L" side %d ", (data & 0x04) ? 1 : 0); + } + + if (step != step_pulse) { if (disk_debug_logging > 1) - write_log (L" indexhack!"); - } - } - } - - if (disk_debug_logging > 1) { - write_log (L" %d%d%d%d% ", (selected & 1) ? 0 : 1, (selected & 2) ? 0 : 1, (selected & 4) ? 0 : 1, (selected & 8) ? 0 : 1); - if ((prevdata & 0x80) != (data & 0x80)) - write_log (L" dskmotor %d ", (data & 0x80) ? 1 : 0); - if ((prevdata & 0x02) != (data & 0x02)) - write_log (L" direct %d ", (data & 0x02) ? 1 : 0); - if ((prevdata & 0x04) != (data & 0x04)) - write_log (L" side %d ", (data & 0x04) ? 1 : 0); - } - - if (step != step_pulse) { - if (disk_debug_logging > 1) - write_log (L" dskstep %d ", step_pulse); - step = step_pulse; - if (step && !savestate_state) { - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - if (!((selected | disabled) & (1 << dr))) { - drive_step (floppy + dr); - if (floppy[dr].indexhackmode > 1 && (data & 0x80)) - floppy[dr].indexhack = 1; - } - } - } - } - if (!savestate_state) { - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = floppy + dr; - /* motor on/off workings tested with small assembler code on real Amiga 1200. */ - /* motor/id flipflop is set only when drive select goes from high to low */ - if (!(selected & (1 << dr)) && (lastselected & (1 << dr)) ) { - drv->drive_id_scnt++; - drv->drive_id_scnt &= 31; - drv->idbit = (drv->drive_id & (1L << (31 - drv->drive_id_scnt))) ? 1 : 0; - if (!(disabled & (1 << dr))) { - if ((prevdata & 0x80) == 0 || (data & 0x80) == 0) { - /* motor off: if motor bit = 0 in prevdata or data -> turn motor on */ - drive_motor (drv, 0); - } else if (prevdata & 0x80) { - /* motor on: if motor bit = 1 in prevdata only (motor flag state in data has no effect) - -> turn motor off */ - drive_motor (drv, 1); - } - } - if (!currprefs.cs_df0idhw && dr == 0) - drv->idbit = 0; + write_log (L" dskstep %d ", step_pulse); + step = step_pulse; + if (step && !savestate_state) { + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + if (!((selected | disabled) & (1 << dr))) { + drive_step (floppy + dr); + if (floppy[dr].indexhackmode > 1 && (data & 0x80)) + floppy[dr].indexhack = 1; + } + } + } + } + if (!savestate_state) { + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = floppy + dr; + /* motor on/off workings tested with small assembler code on real Amiga 1200. */ + /* motor/id flipflop is set only when drive select goes from high to low */ + if (!(selected & (1 << dr)) && (lastselected & (1 << dr)) ) { + drv->drive_id_scnt++; + drv->drive_id_scnt &= 31; + drv->idbit = (drv->drive_id & (1L << (31 - drv->drive_id_scnt))) ? 1 : 0; + if (!(disabled & (1 << dr))) { + if ((prevdata & 0x80) == 0 || (data & 0x80) == 0) { + /* motor off: if motor bit = 0 in prevdata or data -> turn motor on */ + drive_motor (drv, 0); + } else if (prevdata & 0x80) { + /* motor on: if motor bit = 1 in prevdata only (motor flag state in data has no effect) + -> turn motor off */ + drive_motor (drv, 1); + } + } + if (!currprefs.cs_df0idhw && dr == 0) + drv->idbit = 0; #ifdef DEBUG_DRIVE_ID - write_log (L"DISK_status: sel %d id %s (%08X) [0x%08lx, bit #%02d: %d]\n", - dr, drive_id_name(drv), drv->drive_id, drv->drive_id << drv->drive_id_scnt, 31 - drv->drive_id_scnt, drv->idbit); + write_log (L"DISK_status: sel %d id %s (%08X) [0x%08lx, bit #%02d: %d]\n", + dr, drive_id_name(drv), drv->drive_id, drv->drive_id << drv->drive_id_scnt, 31 - drv->drive_id_scnt, drv->idbit); #endif - } + } + } } - } - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - floppy[dr].state = (!(selected & (1 << dr))) | !floppy[dr].motoroff; - update_drive_gui (dr); - } - prevdata = data; - if (disk_debug_logging > 1) - write_log (L"\n"); + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + floppy[dr].state = (!(selected & (1 << dr))) | !floppy[dr].motoroff; + update_drive_gui (dr); + } + prevdata = data; + if (disk_debug_logging > 1) + write_log (L"\n"); } uae_u8 DISK_status (void) { - uae_u8 st = 0x3c; - int dr; + uae_u8 st = 0x3c; + int dr; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = floppy + dr; - if (drv->amax) { - st = amax_disk_status (); - } else if (!((selected | disabled) & (1 << dr))) { - if (drive_running (drv)) { - if (drv->catweasel) { + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = floppy + dr; + if (drv->amax) { + st = amax_disk_status (); + } else if (!((selected | disabled) & (1 << dr))) { + if (drive_running (drv)) { + if (drv->catweasel) { #ifdef CATWEASEL - if (catweasel_diskready (drv->catweasel)) - st &= ~0x20; + if (catweasel_diskready (drv->catweasel)) + st &= ~0x20; #endif - } else { - if (drv->dskready && !drv->indexhack && currprefs.dfxtype[dr] != DRV_35_DD_ESCOM) - st &= ~0x20; - } - } else { - if (currprefs.cs_df0idhw || dr > 0) { - /* report drive ID */ - if (drv->idbit && currprefs.dfxtype[dr] != DRV_35_DD_ESCOM) - st &= ~0x20; - } else { - /* non-ID internal drive: mirror real dskready */ - if (drv->dskready) - st &= ~0x20; - } - /* dskrdy needs some cycles after switching the motor off.. (Pro Tennis Tour) */ - if (!currprefs.cs_df0idhw && dr == 0 && drv->motordelay) - st &= ~0x20; - } - if (drive_track0 (drv)) - st &= ~0x10; - if (drive_writeprotected (drv)) - st &= ~8; - if (drv->catweasel) { + } else { + if (drv->dskready && !drv->indexhack && currprefs.dfxtype[dr] != DRV_35_DD_ESCOM) + st &= ~0x20; + } + } else { + if (currprefs.cs_df0idhw || dr > 0) { + /* report drive ID */ + if (drv->idbit && currprefs.dfxtype[dr] != DRV_35_DD_ESCOM) + st &= ~0x20; + } else { + /* non-ID internal drive: mirror real dskready */ + if (drv->dskready) + st &= ~0x20; + } + /* dskrdy needs some cycles after switching the motor off.. (Pro Tennis Tour) */ + if (!currprefs.cs_df0idhw && dr == 0 && drv->motordelay) + st &= ~0x20; + } + if (drive_track0 (drv)) + st &= ~0x10; + if (drive_writeprotected (drv)) + st &= ~8; + if (drv->catweasel) { #ifdef CATWEASEL - if (catweasel_disk_changed (drv->catweasel)) - st &= ~4; + if (catweasel_disk_changed (drv->catweasel)) + st &= ~4; #endif - } else if (drv->dskchange && currprefs.dfxtype[dr] != DRV_525_SD) { - st &= ~4; - } - } else if (!(selected & (1 << dr))) { - if (drv->idbit) - st &= ~0x20; + } else if (drv->dskchange && currprefs.dfxtype[dr] != DRV_525_SD) { + st &= ~4; + } + } else if (!(selected & (1 << dr))) { + if (drv->idbit) + st &= ~0x20; + } } - } - return st; + return st; } static int unformatted (drive *drv) { - int tr = drv->cyl * 2 + side; - if (tr >= drv->num_tracks) - return 1; - if (drv->filetype == ADF_EXT2 && drv->trackdata[tr].bitlen == 0) - return 1; - return 0; + int tr = drv->cyl * 2 + side; + if (tr >= drv->num_tracks) + return 1; + if (drv->filetype == ADF_EXT2 && drv->trackdata[tr].bitlen == 0) + return 1; + if (drv->trackdata[tr].type == TRACK_NONE) + return 1; + return 0; } /* get one bit from MFM bit stream */ STATIC_INLINE uae_u32 getonebit (uae_u16 * mfmbuf, int mfmpos) { - uae_u16 *buf; + uae_u16 *buf; - buf = &mfmbuf[mfmpos >> 4]; - return (buf[0] & (1 << (15 - (mfmpos & 15)))) ? 1 : 0; + buf = &mfmbuf[mfmpos >> 4]; + return (buf[0] & (1 << (15 - (mfmpos & 15)))) ? 1 : 0; } void dumpdisk (void) { - int i, j, k; - uae_u16 w; + int i, j, k; + uae_u16 w; - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - drive *drv = &floppy[i]; - if (!(disabled & (1 << i))) { - console_out_f (L"Drive %d: motor %s cylinder %2d sel %s %s mfmpos %d/%d\n", - i, drv->motoroff ? L"off" : L" on", drv->cyl, (selected & (1 << i)) ? L"no" : L"yes", - drive_writeprotected(drv) ? L"ro" : L"rw", drv->mfmpos, drv->tracklen); - w = word; - for (j = 0; j < 15; j++) { - console_out_f (L"%04X ", w); - for (k = 0; k < 16; k++) { - w <<= 1; - w |= getonebit (drv->bigmfmbuf, drv->mfmpos + j * 16 + k); + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { + drive *drv = &floppy[i]; + if (!(disabled & (1 << i))) { + console_out_f (L"Drive %d: motor %s cylinder %2d sel %s %s mfmpos %d/%d\n", + i, drv->motoroff ? L"off" : L" on", drv->cyl, (selected & (1 << i)) ? L"no" : L"yes", + drive_writeprotected(drv) ? L"ro" : L"rw", drv->mfmpos, drv->tracklen); + w = word; + for (j = 0; j < 15; j++) { + console_out_f (L"%04X ", w); + for (k = 0; k < 16; k++) { + w <<= 1; + w |= getonebit (drv->bigmfmbuf, drv->mfmpos + j * 16 + k); + } + } + console_out (L"\n"); } - } - console_out (L"\n"); } - } - console_out_f (L"side %d, dma %d, bitoffset %d, word %04X, dskbytr %04X adkcon %04X dsksync %04X\n", side, dskdmaen, bitoffset, word, dskbytr_val, adkcon, dsksync); + console_out_f (L"side %d, dma %d, bitoffset %d, word %04X, dskbytr %04X adkcon %04X dsksync %04X\n", side, dskdmaen, bitoffset, word, dskbytr_val, adkcon, dsksync); } static void disk_dmafinished (void) { - INTREQ (0x8000 | 0x0002); - longwritemode = 0; - dskdmaen = 0; - if (disk_debug_logging > 0) { - int dr, mfmpos = -1; - write_log (L"disk dma finished %08X MFMpos=", dskpt); - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) - write_log (L"%d%s", floppy[dr].mfmpos, dr < MAX_FLOPPY_DRIVES - 1 ? L"," : L""); - write_log (L"\n"); - } + INTREQ (0x8000 | 0x0002); + longwritemode = 0; + dskdmaen = 0; + if (disk_debug_logging > 0) { + int dr, mfmpos = -1; + write_log (L"disk dma finished %08X MFMpos=", dskpt); + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) + write_log (L"%d%s", floppy[dr].mfmpos, dr < MAX_FLOPPY_DRIVES - 1 ? L"," : L""); + write_log (L"\n"); + } } static void fetchnextrevolution (drive *drv) { - drv->trackspeed = get_floppy_speed2 (drv); - if (!drv->multi_revolution) - return; - switch (drv->filetype) - { + drv->trackspeed = get_floppy_speed2 (drv); + if (!drv->multi_revolution) + return; + switch (drv->filetype) + { case ADF_IPF: #ifdef CAPS - caps_loadrevolution (drv->bigmfmbuf, drv - floppy, drv->cyl * 2 + side, &drv->tracklen); + caps_loadrevolution (drv->bigmfmbuf, drv - floppy, drv->cyl * 2 + side, &drv->tracklen); #endif - break; + break; case ADF_FDI: #ifdef FDI2RAW - fdi2raw_loadrevolution (drv->fdi, drv->bigmfmbuf, drv->tracktiming, drv->cyl * 2 + side, &drv->tracklen, 1); + fdi2raw_loadrevolution (drv->fdi, drv->bigmfmbuf, drv->tracktiming, drv->cyl * 2 + side, &drv->tracklen, 1); #endif - break; - } + break; + } } void DISK_handler (uae_u32 data) { - int flag = diskevent_flag; - - event2_remevent(ev2_disk); - DISK_update (disk_sync_cycle); - if (flag & (DISK_REVOLUTION << 0)) - fetchnextrevolution (&floppy[0]); - if (flag & (DISK_REVOLUTION << 1)) - fetchnextrevolution (&floppy[1]); - if (flag & (DISK_REVOLUTION << 2)) - fetchnextrevolution (&floppy[2]); - if (flag & (DISK_REVOLUTION << 3)) - fetchnextrevolution (&floppy[3]); - if (flag & DISK_WORDSYNC) - INTREQ (0x8000 | 0x1000); - if (flag & DISK_INDEXSYNC) - cia_diskindex (); + int flag = diskevent_flag; + + event2_remevent(ev2_disk); + DISK_update (disk_sync_cycle); + if (flag & (DISK_REVOLUTION << 0)) + fetchnextrevolution (&floppy[0]); + if (flag & (DISK_REVOLUTION << 1)) + fetchnextrevolution (&floppy[1]); + if (flag & (DISK_REVOLUTION << 2)) + fetchnextrevolution (&floppy[2]); + if (flag & (DISK_REVOLUTION << 3)) + fetchnextrevolution (&floppy[3]); + if (flag & DISK_WORDSYNC) + INTREQ (0x8000 | 0x1000); + if (flag & DISK_INDEXSYNC) + cia_diskindex (); #if 0 { - int i; - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - drive *drv = &floppy[i]; - if (drv->dskready_time) { - drv->dskready_time--; - if (drv->dskready_time == 0) { - drv->dskready = 1; - if (disk_debug_logging > 0) - write_log (L"%d: %d\n", i, drv->mfmpos); + int i; + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { + drive *drv = &floppy[i]; + if (drv->dskready_time) { + drv->dskready_time--; + if (drv->dskready_time == 0) { + drv->dskready = 1; + if (disk_debug_logging > 0) + write_log (L"%d: %d\n", i, drv->mfmpos); + } + } } - } - } } #endif } @@ -2568,292 +2596,292 @@ extern uae_u8 cycle_line[256]; static void diskdma (uae_u32 pt, uae_u16 w, int write) { - int i, got; + int i, got; - got = 0; - for (i = 7; i <= 11; i += 2) { - if (!cycle_line[i]) { - cycle_line[i] = CYCLE_MISC; - if (debug_dma) - record_dma (write ? 0x26 : 0x08, w, pt, i, vpos, DMARECORD_DISK); - got = 1; - break; + got = 0; + for (i = 7; i <= 11; i += 2) { + if (!cycle_line[i]) { + cycle_line[i] = CYCLE_MISC; + if (debug_dma) + record_dma (write ? 0x26 : 0x08, w, pt, i, vpos, DMARECORD_DISK); + got = 1; + break; + } + // if (cycle_line[i] != CYCLE_MISC) + // write_log (L"%d!?\n", cycle_line[i]); } -// if (cycle_line[i] != CYCLE_MISC) -// write_log (L"%d!?\n", cycle_line[i]); - } -// if (!got) -// write_log (L"disk dma cycle overflow!?\n"); + // if (!got) + // write_log (L"disk dma cycle overflow!?\n"); } #endif static void disk_doupdate_write (drive * drv, int floppybits) { - int dr; - int drives[4]; - - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv2 = &floppy[dr]; - drives[dr] = 0; - if (drv2->motoroff) - continue; - if (selected & (1 << dr)) - continue; - drives[dr] = 1; - } + int dr; + int drives[4]; - while (floppybits >= drv->trackspeed) { for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - if (drives[dr]) { - floppy[dr].mfmpos++; - floppy[dr].mfmpos %= drv->tracklen; - } - } - if ((dmacon & 0x210) == 0x210 && dskdmaen == 3 && dsklength > 0 && (!(adkcon &0x400) || dma_enable)) { - bitoffset++; - bitoffset &= 15; - if (!bitoffset) { - for (dr = 0; dr < MAX_FLOPPY_DRIVES ; dr++) { - drive *drv2 = &floppy[dr]; - uae_u16 w = get_word (dskpt); + drive *drv2 = &floppy[dr]; + drives[dr] = 0; + if (drv2->motoroff) + continue; + if (selected & (1 << dr)) + continue; + drives[dr] = 1; + } + + while (floppybits >= drv->trackspeed) { + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + if (drives[dr]) { + floppy[dr].mfmpos++; + floppy[dr].mfmpos %= drv->tracklen; + } + } + if ((dmacon & 0x210) == 0x210 && dskdmaen == 3 && dsklength > 0 && (!(adkcon &0x400) || dma_enable)) { + bitoffset++; + bitoffset &= 15; + if (!bitoffset) { + for (dr = 0; dr < MAX_FLOPPY_DRIVES ; dr++) { + drive *drv2 = &floppy[dr]; + uae_u16 w = get_word (dskpt); #ifdef CPUEMU_12 - diskdma (dskpt, w, 1); + diskdma (dskpt, w, 1); #endif - if (drives[dr]) { - drv2->bigmfmbuf[drv2->mfmpos >> 4] = w; - drv2->bigmfmbuf[(drv2->mfmpos >> 4) + 1] = 0x5555; - drv2->writtento = 1; - } + if (drives[dr]) { + drv2->bigmfmbuf[drv2->mfmpos >> 4] = w; + drv2->bigmfmbuf[(drv2->mfmpos >> 4) + 1] = 0x5555; + drv2->writtento = 1; + } #ifdef AMAX - if (currprefs.amaxromfile[0]) - amax_diskwrite (w); + if (currprefs.amaxromfile[0]) + amax_diskwrite (w); #endif - } - dskpt += 2; - dsklength--; - if (dsklength == 0) { - disk_dmafinished (); - for (dr = 0; dr < MAX_FLOPPY_DRIVES ; dr++) { - drive *drv2 = &floppy[dr]; - drv2->writtento = 0; - if (drives[dr]) { - drive_write_data (drv2); - //set_steplimit (drv2); + } + dskpt += 2; + dsklength--; + if (dsklength == 0) { + disk_dmafinished (); + for (dr = 0; dr < MAX_FLOPPY_DRIVES ; dr++) { + drive *drv2 = &floppy[dr]; + drv2->writtento = 0; + if (drives[dr]) { + drive_write_data (drv2); + //set_steplimit (drv2); + } + } + } } - } } - } + floppybits -= drv->trackspeed; } - floppybits -= drv->trackspeed; - } } static void updatetrackspeed (drive *drv, int mfmpos) { - if (dskdmaen < 3) { - uae_u16 *p = drv->tracktiming; - p += mfmpos / 8; - drv->trackspeed = get_floppy_speed2 (drv); - drv->trackspeed = drv->trackspeed * p[0] / 1000; - if (drv->trackspeed < 700 || drv->trackspeed > 3000) { - static int warned; - warned++; - if (warned < 50) - write_log (L"corrupted trackspeed value %d\n", drv->trackspeed); - drv->trackspeed = 1000; + if (dskdmaen < 3) { + uae_u16 *p = drv->tracktiming; + p += mfmpos / 8; + drv->trackspeed = get_floppy_speed2 (drv); + drv->trackspeed = drv->trackspeed * p[0] / 1000; + if (drv->trackspeed < 700 || drv->trackspeed > 3000) { + static int warned; + warned++; + if (warned < 50) + write_log (L"corrupted trackspeed value %d\n", drv->trackspeed); + drv->trackspeed = 1000; + } } - } } static void disk_doupdate_predict (drive * drv, int startcycle) { - int is_sync = 0; - int firstcycle = startcycle; - uae_u32 tword = word; - int mfmpos = drv->mfmpos; - int indexhack = drv->indexhack; - - diskevent_flag = 0; - while (startcycle < (maxhpos << 8) && !diskevent_flag) { - int cycle = startcycle >> 8; - if (drv->tracktiming[0]) - updatetrackspeed (drv, mfmpos); - if (dskdmaen != 3) { - tword <<= 1; - if (!drive_empty (drv)) { - if (unformatted (drv)) - tword |= (uaerand() & 0x1000) ? 1 : 0; - else - tword |= getonebit (drv->bigmfmbuf, mfmpos); - } - if ((tword & 0xffff) == dsksync && dsksync != 0) - diskevent_flag |= DISK_WORDSYNC; - } - mfmpos++; - mfmpos %= drv->tracklen; - if (mfmpos == 0) - diskevent_flag |= DISK_REVOLUTION << (drv - floppy); - if (mfmpos == drv->indexoffset) { - diskevent_flag |= DISK_INDEXSYNC; - indexhack = 0; - } - if (dskdmaen != 3 && mfmpos == drv->skipoffset) { - int skipcnt = disk_jitter; - while (skipcnt-- > 0) { + int is_sync = 0; + int firstcycle = startcycle; + uae_u32 tword = word; + int mfmpos = drv->mfmpos; + int indexhack = drv->indexhack; + + diskevent_flag = 0; + while (startcycle < (maxhpos << 8) && !diskevent_flag) { + int cycle = startcycle >> 8; + if (drv->tracktiming[0]) + updatetrackspeed (drv, mfmpos); + if (dskdmaen != 3) { + tword <<= 1; + if (!drive_empty (drv)) { + if (unformatted (drv)) + tword |= (uaerand() & 0x1000) ? 1 : 0; + else + tword |= getonebit (drv->bigmfmbuf, mfmpos); + } + if ((tword & 0xffff) == dsksync && dsksync != 0) + diskevent_flag |= DISK_WORDSYNC; + } mfmpos++; mfmpos %= drv->tracklen; if (mfmpos == 0) - diskevent_flag |= DISK_REVOLUTION << (drv - floppy); + diskevent_flag |= DISK_REVOLUTION << (drv - floppy); if (mfmpos == drv->indexoffset) { - diskevent_flag |= DISK_INDEXSYNC; - indexhack = 0; + diskevent_flag |= DISK_INDEXSYNC; + indexhack = 0; } - } + if (dskdmaen != 3 && mfmpos == drv->skipoffset) { + int skipcnt = disk_jitter; + while (skipcnt-- > 0) { + mfmpos++; + mfmpos %= drv->tracklen; + if (mfmpos == 0) + diskevent_flag |= DISK_REVOLUTION << (drv - floppy); + if (mfmpos == drv->indexoffset) { + diskevent_flag |= DISK_INDEXSYNC; + indexhack = 0; + } + } + } + startcycle += drv->trackspeed; + } + if (drv->tracktiming[0]) + updatetrackspeed (drv, drv->mfmpos); + if (diskevent_flag) { + disk_sync_cycle = startcycle >> 8; + event2_newevent(ev2_disk, (startcycle - firstcycle) / CYCLE_UNIT); } - startcycle += drv->trackspeed; - } - if (drv->tracktiming[0]) - updatetrackspeed (drv, drv->mfmpos); - if (diskevent_flag) { - disk_sync_cycle = startcycle >> 8; - event2_newevent(ev2_disk, (startcycle - firstcycle) / CYCLE_UNIT); - } } static void disk_doupdate_read_nothing (int floppybits) { - int j = 0, k = 1, l = 0; + int j = 0, k = 1, l = 0; - while (floppybits >= get_floppy_speed()) { - word <<= 1; - if (bitoffset == 15 && dma_enable && dskdmaen == 2 && dsklength >= 0) { - if (dsklength > 0) { - put_word (dskpt, word); + while (floppybits >= get_floppy_speed()) { + word <<= 1; + if (bitoffset == 15 && dma_enable && dskdmaen == 2 && dsklength >= 0) { + if (dsklength > 0) { + put_word (dskpt, word); #ifdef CPUEMU_12 - diskdma (dskpt, word, 0); + diskdma (dskpt, word, 0); #endif - dskpt += 2; - } - dsklength--; - if (dsklength <= 0) - disk_dmafinished (); - } - if ((bitoffset & 7) == 7) { - dskbytr_val = word & 0xff; - dskbytr_val |= 0x8000; + dskpt += 2; + } + dsklength--; + if (dsklength <= 0) + disk_dmafinished (); + } + if ((bitoffset & 7) == 7) { + dskbytr_val = word & 0xff; + dskbytr_val |= 0x8000; + } + bitoffset++; + bitoffset &= 15; + floppybits -= get_floppy_speed(); } - bitoffset++; - bitoffset &= 15; - floppybits -= get_floppy_speed(); - } } static void disk_doupdate_read (drive * drv, int floppybits) { - int j = 0, k = 1, l = 0; - -/* - uae_u16 *mfmbuf = drv->bigmfmbuf; - dsksync = 0x4444; - adkcon |= 0x400; - drv->mfmpos = 0; - memset (mfmbuf, 0, 1000); - cycles = 0x1000000; - // 4444 4444 4444 aaaa aaaaa 4444 4444 4444 - // 4444 aaaa aaaa 4444 - mfmbuf[0] = 0x4444; - mfmbuf[1] = 0x4444; - mfmbuf[2] = 0x4444; - mfmbuf[3] = 0xaaaa; - mfmbuf[4] = 0xaaaa; - mfmbuf[5] = 0x4444; - mfmbuf[6] = 0x4444; - mfmbuf[7] = 0x4444; -*/ - while (floppybits >= drv->trackspeed) { - if (drv->tracktiming[0]) - updatetrackspeed (drv, drv->mfmpos); - word <<= 1; - if (!drive_empty (drv)) { - if (unformatted (drv)) - word |= (uaerand() & 0x1000) ? 1 : 0; - else - word |= getonebit (drv->bigmfmbuf, drv->mfmpos); - } - //write_log (L"%08X bo=%d so=%d mfmpos=%d dma=%d\n", (word & 0xffffff), bitoffset, syncoffset, drv->mfmpos,dma_enable); - drv->mfmpos++; - drv->mfmpos %= drv->tracklen; - if (drv->mfmpos == drv->indexoffset) { - if (disk_debug_logging > 1 && drv->indexhack) - write_log (L"indexhack cleared\n"); - drv->indexhack = 0; - } - if (drv->mfmpos == drv->skipoffset) { - drv->mfmpos += disk_jitter; - drv->mfmpos %= drv->tracklen; - } - if (bitoffset == 15 && dma_enable && dskdmaen == 2 && dsklength >= 0) { - if (dsklength > 0) { - put_word (dskpt, word); + int j = 0, k = 1, l = 0; + + /* + uae_u16 *mfmbuf = drv->bigmfmbuf; + dsksync = 0x4444; + adkcon |= 0x400; + drv->mfmpos = 0; + memset (mfmbuf, 0, 1000); + cycles = 0x1000000; + // 4444 4444 4444 aaaa aaaaa 4444 4444 4444 + // 4444 aaaa aaaa 4444 + mfmbuf[0] = 0x4444; + mfmbuf[1] = 0x4444; + mfmbuf[2] = 0x4444; + mfmbuf[3] = 0xaaaa; + mfmbuf[4] = 0xaaaa; + mfmbuf[5] = 0x4444; + mfmbuf[6] = 0x4444; + mfmbuf[7] = 0x4444; + */ + while (floppybits >= drv->trackspeed) { + if (drv->tracktiming[0]) + updatetrackspeed (drv, drv->mfmpos); + word <<= 1; + if (!drive_empty (drv)) { + if (unformatted (drv)) + word |= (uaerand() & 0x1000) ? 1 : 0; + else + word |= getonebit (drv->bigmfmbuf, drv->mfmpos); + } + //write_log (L"%08X bo=%d so=%d mfmpos=%d dma=%d\n", (word & 0xffffff), bitoffset, syncoffset, drv->mfmpos,dma_enable); + drv->mfmpos++; + drv->mfmpos %= drv->tracklen; + if (drv->mfmpos == drv->indexoffset) { + if (disk_debug_logging > 1 && drv->indexhack) + write_log (L"indexhack cleared\n"); + drv->indexhack = 0; + } + if (drv->mfmpos == drv->skipoffset) { + drv->mfmpos += disk_jitter; + drv->mfmpos %= drv->tracklen; + } + if (bitoffset == 15 && dma_enable && dskdmaen == 2 && dsklength >= 0) { + if (dsklength > 0) { + put_word (dskpt, word); #ifdef CPUEMU_12 - diskdma (dskpt, word, 0); + diskdma (dskpt, word, 0); #endif - dskpt += 2; - } + dskpt += 2; + } #if 0 - dma_tab[j++] = word; - if (j == MAX_DISK_WORDS_PER_LINE - 1) { - write_log (L"Bug: Disk DMA buffer overflow!\n"); - j--; - } + dma_tab[j++] = word; + if (j == MAX_DISK_WORDS_PER_LINE - 1) { + write_log (L"Bug: Disk DMA buffer overflow!\n"); + j--; + } #endif - dsklength--; - if (dsklength <= 0) - disk_dmafinished (); - } - if ((bitoffset & 7) == 7) { - dskbytr_val = word & 0xff; - dskbytr_val |= 0x8000; - } - if (word == dsksync) { - if (adkcon & 0x400) - bitoffset = 15; - if (dskdmaen) { - if (disk_debug_logging && dma_enable == 0) - write_log (L"Sync match, DMA started at %d\n", drv->mfmpos); - dma_enable = 1; - } - } - bitoffset++; - bitoffset &= 15; - floppybits -= drv->trackspeed; - } + dsklength--; + if (dsklength <= 0) + disk_dmafinished (); + } + if ((bitoffset & 7) == 7) { + dskbytr_val = word & 0xff; + dskbytr_val |= 0x8000; + } + if (word == dsksync) { + if (adkcon & 0x400) + bitoffset = 15; + if (dskdmaen) { + if (disk_debug_logging && dma_enable == 0) + write_log (L"Sync match, DMA started at %d\n", drv->mfmpos); + dma_enable = 1; + } + } + bitoffset++; + bitoffset &= 15; + floppybits -= drv->trackspeed; + } #if 0 - dma_tab[j] = 0xffffffff; + dma_tab[j] = 0xffffffff; #endif } static void disk_dma_debugmsg (void) { - write_log (L"LEN=%04X (%d) SYNC=%04X PT=%08X ADKCON=%04X PC=%08X\n", - dsklength, dsklength, (adkcon & 0x400) ? dsksync : 0xffff, dskpt, adkcon, M68K_GETPC); + write_log (L"LEN=%04X (%d) SYNC=%04X PT=%08X ADKCON=%04X PC=%08X\n", + dsklength, dsklength, (adkcon & 0x400) ? dsksync : 0xffff, dskpt, adkcon, M68K_GETPC); } #if 0 /* disk DMA fetch happens on real Amiga at the beginning of next horizontal line - (cycles 9, 11 and 13 according to hardware manual) We transfer all DMA'd - data at cycle 0. I don't think any program cares about this small difference. +(cycles 9, 11 and 13 according to hardware manual) We transfer all DMA'd +data at cycle 0. I don't think any program cares about this small difference. */ static void dodmafetch (void) { - int i; + int i; - i = 0; - while (dma_tab[i] != 0xffffffff && dskdmaen != 3 && (dmacon & 0x210) == 0x210) { - put_word (dskpt, dma_tab[i++]); - dskpt += 2; - } - dma_tab[0] = 0xffffffff; + i = 0; + while (dma_tab[i] != 0xffffffff && dskdmaen != 3 && (dmacon & 0x210) == 0x210) { + put_word (dskpt, dma_tab[i++]); + dskpt += 2; + } + dma_tab[0] = 0xffffffff; } #endif @@ -2861,476 +2889,476 @@ static void dodmafetch (void) uae_u16 DSKBYTR (int hpos) { - uae_u16 v; - - DISK_update (hpos); - v = dskbytr_val; - dskbytr_val &= ~0x8000; - if (word == dsksync) - v |= 0x1000; - if (dskdmaen && (dmacon & 0x210) == 0x210) - v |= 0x4000; - if (dsklen & 0x4000) - v |= 0x2000; - if (disk_debug_logging > 1) - write_log (L"DSKBYTR=%04X hpos=%d\n", v, hpos); - if (disk_debug_mode & DISK_DEBUG_PIO) { - int dr; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (drv->motoroff) - continue; - if (!(selected & (1 << dr))) { - if (disk_debug_track < 0 || disk_debug_track == 2 * drv->cyl + side) { - disk_dma_debugmsg (); - write_log (L"DSKBYTR=%04X\n", v); - activate_debugger (); - break; + uae_u16 v; + + DISK_update (hpos); + v = dskbytr_val; + dskbytr_val &= ~0x8000; + if (word == dsksync) + v |= 0x1000; + if (dskdmaen && (dmacon & 0x210) == 0x210) + v |= 0x4000; + if (dsklen & 0x4000) + v |= 0x2000; + if (disk_debug_logging > 1) + write_log (L"DSKBYTR=%04X hpos=%d\n", v, hpos); + if (disk_debug_mode & DISK_DEBUG_PIO) { + int dr; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (drv->motoroff) + continue; + if (!(selected & (1 << dr))) { + if (disk_debug_track < 0 || disk_debug_track == 2 * drv->cyl + side) { + disk_dma_debugmsg (); + write_log (L"DSKBYTR=%04X\n", v); + activate_debugger (); + break; + } + } } - } } - } - return v; + return v; } static void DISK_start (void) { - int dr; - - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (!(selected & (1 << dr))) { - int tr = drv->cyl * 2 + side; - trackid *ti = drv->trackdata + tr; + int dr; - if (dskdmaen == 3) { - drv->tracklen = longwritemode ? FLOPPY_WRITE_MAXLEN : FLOPPY_WRITE_LEN * drv->ddhd * 8 * 2; - drv->trackspeed = get_floppy_speed (); - drv->skipoffset = -1; - updatemfmpos (drv); - } - /* Ugh. A nasty hack. Assume ADF_EXT1 tracks are always read - from the start. */ - if (ti->type == TRACK_RAW1) - drv->mfmpos = 0; - if (drv->catweasel) - drive_fill_bigbuf (drv, 1); + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (!(selected & (1 << dr))) { + int tr = drv->cyl * 2 + side; + trackid *ti = drv->trackdata + tr; + + if (dskdmaen == 3) { + drv->tracklen = longwritemode ? FLOPPY_WRITE_MAXLEN : FLOPPY_WRITE_LEN * drv->ddhd * 8 * 2; + drv->trackspeed = get_floppy_speed (); + drv->skipoffset = -1; + updatemfmpos (drv); + } + /* Ugh. A nasty hack. Assume ADF_EXT1 tracks are always read + from the start. */ + if (ti->type == TRACK_RAW1) + drv->mfmpos = 0; + if (drv->catweasel) + drive_fill_bigbuf (drv, 1); + } + drv->floppybitcounter = 0; } - drv->floppybitcounter = 0; - } } static int linecounter; void DISK_hsync (int tohpos) { - int dr; + int dr; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (drv->steplimit) - drv->steplimit--; - } - if (linecounter) { - linecounter--; - if (! linecounter) - disk_dmafinished (); - return; - } - DISK_update (tohpos); + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (drv->steplimit) + drv->steplimit--; + } + if (linecounter) { + linecounter--; + if (! linecounter) + disk_dmafinished (); + return; + } + DISK_update (tohpos); } void DISK_update (int tohpos) { - int dr; - int cycles = (tohpos << 8) - disk_hpos; - int startcycle = disk_hpos; - int didread; - - disk_jitter = ((uaerand () >> 4) & 3) + 1; - if (disk_jitter > 2) - disk_jitter = 1; - if (cycles <= 0) - return; - disk_hpos += cycles; - if (disk_hpos >= (maxhpos << 8)) - disk_hpos -= maxhpos << 8; + int dr; + int cycles = (tohpos << 8) - disk_hpos; + int startcycle = disk_hpos; + int didread; + + disk_jitter = ((uaerand () >> 4) & 3) + 1; + if (disk_jitter > 2) + disk_jitter = 1; + if (cycles <= 0) + return; + disk_hpos += cycles; + if (disk_hpos >= (maxhpos << 8)) + disk_hpos -= maxhpos << 8; #if 0 - dodmafetch (); + dodmafetch (); #endif - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; - if (drv->motoroff || !drv->tracklen || !drv->trackspeed) - continue; - drv->floppybitcounter += cycles; - if (selected & (1 << dr)) { - drv->mfmpos += drv->floppybitcounter / drv->trackspeed; - drv->mfmpos %= drv->tracklen; - drv->floppybitcounter %= drv->trackspeed; - continue; + if (drv->motoroff || !drv->tracklen || !drv->trackspeed) + continue; + drv->floppybitcounter += cycles; + if (selected & (1 << dr)) { + drv->mfmpos += drv->floppybitcounter / drv->trackspeed; + drv->mfmpos %= drv->tracklen; + drv->floppybitcounter %= drv->trackspeed; + continue; + } + if (drv->diskfile) + drive_fill_bigbuf (drv, 0); + drv->mfmpos %= drv->tracklen; + } + didread = 0; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (drv->motoroff || !drv->trackspeed) + continue; + if (selected & (1 << dr)) + continue; + if (dskdmaen == 3) + disk_doupdate_write (drv, drv->floppybitcounter); + else + disk_doupdate_read (drv, drv->floppybitcounter); + disk_doupdate_predict (drv, disk_hpos); + drv->floppybitcounter %= drv->trackspeed; + didread = 1; + break; + } + /* no floppy selected but read dma */ + if (!didread && dskdmaen == 2) { + disk_doupdate_read_nothing (cycles); } - if (drv->diskfile) - drive_fill_bigbuf (drv, 0); - drv->mfmpos %= drv->tracklen; - } - didread = 0; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (drv->motoroff || !drv->trackspeed) - continue; - if (selected & (1 << dr)) - continue; - if (dskdmaen == 3) - disk_doupdate_write (drv, drv->floppybitcounter); - else - disk_doupdate_read (drv, drv->floppybitcounter); - disk_doupdate_predict (drv, disk_hpos); - drv->floppybitcounter %= drv->trackspeed; - didread = 1; - break; - } - /* no floppy selected but read dma */ - if (!didread && dskdmaen == 2) { - disk_doupdate_read_nothing (cycles); - } } void DSKLEN (uae_u16 v, int hpos) { - int dr, prev = dsklen; - int noselected = 0; - int motormask; - - DISK_update (hpos); - if ((v & 0x8000) && (dsklen & 0x8000)) { - dskdmaen = 2; - DISK_start (); - if (!(v & 0x4000)) - dma_enable = (adkcon & 0x400) ? 0 : 1; - } - if (!(v & 0x8000)) { - if (dskdmaen) { - /* Megalomania and Knightmare does this */ - if (disk_debug_logging > 0 && dskdmaen == 2) - write_log (L"warning: Disk read DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC); - if (dskdmaen == 3) { - write_log (L"warning: Disk write DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC); - // did program write something that needs to be stored to file? - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv2 = &floppy[dr]; - if (!drv2->writtento) - continue; - drive_write_data (drv2); + int dr, prev = dsklen; + int noselected = 0; + int motormask; + + DISK_update (hpos); + if ((v & 0x8000) && (dsklen & 0x8000)) { + dskdmaen = 2; + DISK_start (); + if (!(v & 0x4000)) + dma_enable = (adkcon & 0x400) ? 0 : 1; + } + if (!(v & 0x8000)) { + if (dskdmaen) { + /* Megalomania and Knightmare does this */ + if (disk_debug_logging > 0 && dskdmaen == 2) + write_log (L"warning: Disk read DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC); + if (dskdmaen == 3) { + write_log (L"warning: Disk write DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC); + // did program write something that needs to be stored to file? + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv2 = &floppy[dr]; + if (!drv2->writtento) + continue; + drive_write_data (drv2); + } + } + dskdmaen = 0; } - } - dskdmaen = 0; } - } - dsklen = v; - dsklength2 = dsklength = dsklen & 0x3fff; + dsklen = v; + dsklength2 = dsklength = dsklen & 0x3fff; - if (dskdmaen == 0) - return; + if (dskdmaen == 0) + return; - if ((v & 0x4000) && (prev & 0x4000)) { - if (dsklength == 0) - return; - if (dsklength == 1) { - disk_dmafinished (); - return; + if ((v & 0x4000) && (prev & 0x4000)) { + if (dsklength == 0) + return; + if (dsklength == 1) { + disk_dmafinished (); + return; + } + dskdmaen = 3; + DISK_start (); } - dskdmaen = 3; - DISK_start (); - } - if (dsklength == 1) - dsklength = 0; + if (dsklength == 1) + dsklength = 0; - if (((disk_debug_mode & DISK_DEBUG_DMA_READ) && dskdmaen == 2) || - ((disk_debug_mode & DISK_DEBUG_DMA_WRITE) && dskdmaen == 3)) - { - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (drv->motoroff) - continue; - if (!(selected & (1 << dr))) { - if (disk_debug_track < 0 || disk_debug_track == 2 * drv->cyl + side) { - disk_dma_debugmsg (); - activate_debugger (); - break; - } - } - } - } - - motormask = 0; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - drv->writtento = 0; - if (drv->motoroff) - continue; - motormask |= 1 << dr; - if ((selected & (1 << dr)) == 0) - break; - } - if (dr == 4) { - write_log (L"disk %s DMA started, drvmask=%x motormask=%x\n", - dskdmaen == 3 ? L"write" : L"read", selected ^ 15, motormask); - noselected = 1; - } else { - if (disk_debug_logging > 0) { - write_log (L"disk %s DMA started, drvmask=%x track %d mfmpos %d dmaen=%d\n", - dskdmaen == 3 ? L"write" : L"read", selected ^ 15, - floppy[dr].cyl * 2 + side, floppy[dr].mfmpos, dma_enable); - disk_dma_debugmsg (); - } - } - - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) - update_drive_gui (dr); - - /* Try to make floppy access from Kickstart faster. */ - if (dskdmaen != 2 && dskdmaen != 3) - return; - - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - if (selected & (1 << dr)) - continue; - if (drv->filetype != ADF_NORMAL) - break; - } - if (dr < MAX_FLOPPY_DRIVES) /* no turbo mode if any selected drive has non-standard ADF */ - return; - { - int done = 0; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - int pos, i; - - if (drv->motoroff) - continue; - if (!drv->useturbo && currprefs.floppy_speed > 0) - continue; - if (selected & (1 << dr)) - continue; - - pos = drv->mfmpos & ~15; - drive_fill_bigbuf (drv, 0); - - if (dskdmaen == 2) { /* TURBO read */ - - if (adkcon & 0x400) { - for (i = 0; i < drv->tracklen; i += 16) { - pos += 16; - pos %= drv->tracklen; - if (drv->bigmfmbuf[pos >> 4] == dsksync) { - /* must skip first disk sync marker */ - pos += 16; - pos %= drv->tracklen; - break; + if (((disk_debug_mode & DISK_DEBUG_DMA_READ) && dskdmaen == 2) || + ((disk_debug_mode & DISK_DEBUG_DMA_WRITE) && dskdmaen == 3)) + { + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (drv->motoroff) + continue; + if (!(selected & (1 << dr))) { + if (disk_debug_track < 0 || disk_debug_track == 2 * drv->cyl + side) { + disk_dma_debugmsg (); + activate_debugger (); + break; + } } - } - if (i >= drv->tracklen) - return; } - while (dsklength-- > 0) { - put_word (dskpt, drv->bigmfmbuf[pos >> 4]); - dskpt += 2; - pos += 16; - pos %= drv->tracklen; + } + + motormask = 0; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + drv->writtento = 0; + if (drv->motoroff) + continue; + motormask |= 1 << dr; + if ((selected & (1 << dr)) == 0) + break; + } + if (dr == 4) { + write_log (L"disk %s DMA started, drvmask=%x motormask=%x\n", + dskdmaen == 3 ? L"write" : L"read", selected ^ 15, motormask); + noselected = 1; + } else { + if (disk_debug_logging > 0) { + write_log (L"disk %s DMA started, drvmask=%x track %d mfmpos %d dmaen=%d\n", + dskdmaen == 3 ? L"write" : L"read", selected ^ 15, + floppy[dr].cyl * 2 + side, floppy[dr].mfmpos, dma_enable); + disk_dma_debugmsg (); } - INTREQ (0x8000 | 0x1000); - done = 1; + } + + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) + update_drive_gui (dr); - } else if (dskdmaen == 3) { /* TURBO write */ + /* Try to make floppy access from Kickstart faster. */ + if (dskdmaen != 2 && dskdmaen != 3) + return; - for (i = 0; i < dsklength; i++) { - uae_u16 w = get_word (dskpt + i * 2); - drv->bigmfmbuf[pos >> 4] = w; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + if (selected & (1 << dr)) + continue; + if (drv->filetype != ADF_NORMAL) + break; + } + if (dr < MAX_FLOPPY_DRIVES) /* no turbo mode if any selected drive has non-standard ADF */ + return; + { + int done = 0; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + int pos, i; + + if (drv->motoroff) + continue; + if (!drv->useturbo && currprefs.floppy_speed > 0) + continue; + if (selected & (1 << dr)) + continue; + + pos = drv->mfmpos & ~15; + drive_fill_bigbuf (drv, 0); + + if (dskdmaen == 2) { /* TURBO read */ + + if (adkcon & 0x400) { + for (i = 0; i < drv->tracklen; i += 16) { + pos += 16; + pos %= drv->tracklen; + if (drv->bigmfmbuf[pos >> 4] == dsksync) { + /* must skip first disk sync marker */ + pos += 16; + pos %= drv->tracklen; + break; + } + } + if (i >= drv->tracklen) + return; + } + while (dsklength-- > 0) { + put_word (dskpt, drv->bigmfmbuf[pos >> 4]); + dskpt += 2; + pos += 16; + pos %= drv->tracklen; + } + INTREQ (0x8000 | 0x1000); + done = 1; + + } else if (dskdmaen == 3) { /* TURBO write */ + + for (i = 0; i < dsklength; i++) { + uae_u16 w = get_word (dskpt + i * 2); + drv->bigmfmbuf[pos >> 4] = w; #ifdef AMAX - if (currprefs.amaxromfile[0]) - amax_diskwrite (w); + if (currprefs.amaxromfile[0]) + amax_diskwrite (w); #endif - pos += 16; - pos %= drv->tracklen; + pos += 16; + pos %= drv->tracklen; + } + drive_write_data (drv); + done = 1; + } } - drive_write_data (drv); - done = 1; - } - } - if (!done && noselected) { - while (dsklength-- > 0) { - if (dskdmaen == 3) { - uae_u16 w = get_word (dskpt); + if (!done && noselected) { + while (dsklength-- > 0) { + if (dskdmaen == 3) { + uae_u16 w = get_word (dskpt); #ifdef AMAX - if (currprefs.amaxromfile[0]) - amax_diskwrite (w); + if (currprefs.amaxromfile[0]) + amax_diskwrite (w); #endif - } else { - put_word (dskpt, 0); + } else { + put_word (dskpt, 0); + } + dskpt += 2; + } + INTREQ (0x8000 | 0x1000); + done = 1; } - dskpt += 2; - } - INTREQ (0x8000 | 0x1000); - done = 1; - } - if (done) { - linecounter = 2; - dskdmaen = 0; - return; + if (done) { + linecounter = 2; + dskdmaen = 0; + return; + } } - } } void DSKSYNC (int hpos, uae_u16 v) { - if (v == dsksync) - return; - DISK_update (hpos); - dsksync = v; + if (v == dsksync) + return; + DISK_update (hpos); + dsksync = v; } void DSKDAT (uae_u16 v) { - static int count = 0; + static int count = 0; #if 0 - if (dsklen == 0x8000) { - if (v == 1) - longwritemode = 1; - return; - } + if (dsklen == 0x8000) { + if (v == 1) + longwritemode = 1; + return; + } #endif - if (count < 5) { - count++; - write_log (L"%04X written to DSKDAT. Not good. PC=%08X", v, M68K_GETPC); - if (count == 5) - write_log (L"(further messages suppressed)"); + if (count < 5) { + count++; + write_log (L"%04X written to DSKDAT. Not good. PC=%08X", v, M68K_GETPC); + if (count == 5) + write_log (L"(further messages suppressed)"); - write_log (L"\n"); - } + write_log (L"\n"); + } } void DSKPTH (uae_u16 v) { - dskpt = (dskpt & 0xffff) | ((uae_u32) v << 16); + dskpt = (dskpt & 0xffff) | ((uae_u32) v << 16); } void DSKPTL (uae_u16 v) { - dskpt = (dskpt & ~0xffff) | (v); + dskpt = (dskpt & ~0xffff) | (v); } void DISK_free (void) { - int dr; - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - drive_image_free (drv); - } + int dr; + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + drive_image_free (drv); + } } void DISK_init (void) { - int dr; + int dr; #if 0 - dma_tab[0] = 0xffffffff; + dma_tab[0] = 0xffffffff; #endif - for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { - drive *drv = &floppy[dr]; - /* reset all drive types to 3.5 DD */ - drive_settype_id (drv); - if (!drive_insert (drv, &currprefs, dr, currprefs.df[dr])) - disk_eject (dr); - } - if (disk_empty (0)) - write_log (L"No disk in drive 0.\n"); - amax_init (); + for (dr = 0; dr < MAX_FLOPPY_DRIVES; dr++) { + drive *drv = &floppy[dr]; + /* reset all drive types to 3.5 DD */ + drive_settype_id (drv); + if (!drive_insert (drv, &currprefs, dr, currprefs.df[dr])) + disk_eject (dr); + } + if (disk_empty (0)) + write_log (L"No disk in drive 0.\n"); + amax_init (); } void DISK_reset (void) { - int i; + int i; - if (savestate_state) - return; + if (savestate_state) + return; - //floppy[0].catweasel = &cwc.drives[0]; - disk_hpos = 0; - dskdmaen = 0; - disabled = 0; - for (i = 0; i < MAX_FLOPPY_DRIVES; i++) - reset_drive (i); - setamax (); + //floppy[0].catweasel = &cwc.drives[0]; + disk_hpos = 0; + dskdmaen = 0; + disabled = 0; + for (i = 0; i < MAX_FLOPPY_DRIVES; i++) + reset_drive (i); + setamax (); } int DISK_examine_image (struct uae_prefs *p, int num, uae_u32 *crc32) { - int drvsec; - int ret, i; - drive *drv = &floppy[num]; - uae_u32 dos, crc, crc2; - int wasdelayed = drv->dskchange_time; - int sectable[MAX_SECTORS]; - - ret = 0; - drv->cyl = 0; - side = 0; - *crc32 = 0; - if (!drive_insert (drv, p, num, p->df[num])) - return 1; - if (!drv->diskfile) - return 1; - *crc32 = zfile_crc32 (drv->diskfile); - decode_buffer (drv->bigmfmbuf, drv->cyl, 11, drv->ddhd, drv->filetype, &drvsec, sectable, 1); - if (sectable[0] == 0 || sectable[1] == 0) { - ret = 2; - goto end; - } - crc = crc2 = 0; - for (i = 0; i < 1024; i += 4) { - uae_u32 v = (writebuffer[i] << 24) | (writebuffer[i + 1] << 16) | (writebuffer[i + 2] << 8) | writebuffer[i + 3]; - if (i == 0) - dos = v; - if (i == 4) { - crc2 = v; - v = 0; - } - if (crc + v < crc) - crc++; - crc += v; - } - if (dos == 0x4b49434b) { /* KICK */ - ret = 10; - goto end; - } - crc ^= 0xffffffff; - if (crc != crc2) { - ret = 3; - goto end; - } - if (dos == 0x444f5300) - ret = 10; - else if (dos == 0x444f5301 || dos == 0x444f5302 || dos == 0x444f5303) - ret = 11; - else if (dos == 0x444f5304 || dos == 0x444f5305 || dos == 0x444f5306 || dos == 0x444f5307) - ret = 12; - else - ret = 4; + int drvsec; + int ret, i; + drive *drv = &floppy[num]; + uae_u32 dos, crc, crc2; + int wasdelayed = drv->dskchange_time; + int sectable[MAX_SECTORS]; + + ret = 0; + drv->cyl = 0; + side = 0; + *crc32 = 0; + if (!drive_insert (drv, p, num, p->df[num])) + return 1; + if (!drv->diskfile) + return 1; + *crc32 = zfile_crc32 (drv->diskfile); + decode_buffer (drv->bigmfmbuf, drv->cyl, 11, drv->ddhd, drv->filetype, &drvsec, sectable, 1); + if (sectable[0] == 0 || sectable[1] == 0) { + ret = 2; + goto end; + } + crc = crc2 = 0; + for (i = 0; i < 1024; i += 4) { + uae_u32 v = (writebuffer[i] << 24) | (writebuffer[i + 1] << 16) | (writebuffer[i + 2] << 8) | writebuffer[i + 3]; + if (i == 0) + dos = v; + if (i == 4) { + crc2 = v; + v = 0; + } + if (crc + v < crc) + crc++; + crc += v; + } + if (dos == 0x4b49434b) { /* KICK */ + ret = 10; + goto end; + } + crc ^= 0xffffffff; + if (crc != crc2) { + ret = 3; + goto end; + } + if (dos == 0x444f5300) + ret = 10; + else if (dos == 0x444f5301 || dos == 0x444f5302 || dos == 0x444f5303) + ret = 11; + else if (dos == 0x444f5304 || dos == 0x444f5305 || dos == 0x444f5306 || dos == 0x444f5307) + ret = 12; + else + ret = 4; end: - drive_image_free (drv); - if (wasdelayed > 1) { - drive_eject (drv); - currprefs.df[num][0] = 0; - drv->dskchange_time = wasdelayed; - disk_insert (num, drv->newname); - } - return ret; + drive_image_free (drv); + if (wasdelayed > 1) { + drive_eject (drv); + currprefs.df[num][0] = 0; + drv->dskchange_time = wasdelayed; + disk_insert (num, drv->newname); + } + return ret; } @@ -3340,10 +3368,10 @@ end: void DISK_save_custom (uae_u32 *pdskpt, uae_u16 *pdsklength, uae_u16 *pdsksync, uae_u16 *pdskbytr) { - if(pdskpt) *pdskpt = dskpt; - if(pdsklength) *pdsklength = dsklength; - if(pdsksync) *pdsksync = dsksync; - if(pdskbytr) *pdskbytr = dskbytr_val; + if(pdskpt) *pdskpt = dskpt; + if(pdsklength) *pdsklength = dsklength; + if(pdsksync) *pdsksync = dsksync; + if(pdskbytr) *pdskbytr = dskbytr_val; } #endif /* SAVESTATE || DEBUGGER */ @@ -3352,169 +3380,169 @@ void DISK_save_custom (uae_u32 *pdskpt, uae_u16 *pdsklength, uae_u16 *pdsksync, void DISK_restore_custom (uae_u32 pdskpt, uae_u16 pdsklength, uae_u16 pdskbytr) { - dskpt = pdskpt; - dsklength = pdsklength; - dskbytr_val = pdskbytr; + dskpt = pdskpt; + dsklength = pdsklength; + dskbytr_val = pdskbytr; } void restore_disk_finish (void) { - setamax(); + setamax(); } uae_u8 *restore_disk (int num,uae_u8 *src) { - drive *drv; - int state, dfxtype; - TCHAR old[MAX_DPATH]; - TCHAR *s; - int newis; - - drv = &floppy[num]; - disabled &= ~(1 << num); - drv->drive_id = restore_u32 (); - drv->motoroff = 1; - drv->idbit = 0; - state = restore_u8 (); - if (state & 2) { - disabled |= 1 << num; - if (changed_prefs.nr_floppies > num) - changed_prefs.nr_floppies = num; - changed_prefs.dfxtype[num] = -1; - } else { - drv->motoroff = (state & 1) ? 0 : 1; - drv->idbit = (state & 4) ? 1 : 0; - if (changed_prefs.nr_floppies < num) - changed_prefs.nr_floppies = num; - switch (drv->drive_id) - { - case DRIVE_ID_35HD: - dfxtype = DRV_35_HD; - break; - case DRIVE_ID_525SD: - dfxtype = DRV_525_SD; - break; - default: - dfxtype = DRV_35_DD; - break; - } - changed_prefs.dfxtype[num] = dfxtype; - } - drv->indexhackmode = 0; - if (num == 0 && currprefs.dfxtype[num] == 0) - drv->indexhackmode = 1; - drv->buffered_cyl = -1; - drv->buffered_side = -1; - drv->cyl = restore_u8 (); - drv->dskready = restore_u8 (); - drv->drive_id_scnt = restore_u8 (); - drv->mfmpos = restore_u32 (); - drv->dskchange = 0; - drv->dskchange_time = 0; - restore_u32 (); - s = restore_string (); - _tcscpy (old, currprefs.df[num]); - _tcsncpy (changed_prefs.df[num], s, 255); - xfree (s); - newis = changed_prefs.df[num][0] ? 1 : 0; - if (!(disabled & (1 << num))) { - if (!newis) { - drv->dskchange = 1; + drive *drv; + int state, dfxtype; + TCHAR old[MAX_DPATH]; + TCHAR *s; + int newis; + + drv = &floppy[num]; + disabled &= ~(1 << num); + drv->drive_id = restore_u32 (); + drv->motoroff = 1; + drv->idbit = 0; + state = restore_u8 (); + if (state & 2) { + disabled |= 1 << num; + if (changed_prefs.nr_floppies > num) + changed_prefs.nr_floppies = num; + changed_prefs.dfxtype[num] = -1; } else { - drive_insert (floppy + num, &currprefs, num, changed_prefs.df[num]); - if (drive_empty (floppy + num)) { - if (newis && old[0]) { - _tcscpy (changed_prefs.df[num], old); - drive_insert (floppy + num, &currprefs, num, changed_prefs.df[num]); - if (drive_empty (floppy + num)) + drv->motoroff = (state & 1) ? 0 : 1; + drv->idbit = (state & 4) ? 1 : 0; + if (changed_prefs.nr_floppies < num) + changed_prefs.nr_floppies = num; + switch (drv->drive_id) + { + case DRIVE_ID_35HD: + dfxtype = DRV_35_HD; + break; + case DRIVE_ID_525SD: + dfxtype = DRV_525_SD; + break; + default: + dfxtype = DRV_35_DD; + break; + } + changed_prefs.dfxtype[num] = dfxtype; + } + drv->indexhackmode = 0; + if (num == 0 && currprefs.dfxtype[num] == 0) + drv->indexhackmode = 1; + drv->buffered_cyl = -1; + drv->buffered_side = -1; + drv->cyl = restore_u8 (); + drv->dskready = restore_u8 (); + drv->drive_id_scnt = restore_u8 (); + drv->mfmpos = restore_u32 (); + drv->dskchange = 0; + drv->dskchange_time = 0; + restore_u32 (); + s = restore_string (); + _tcscpy (old, currprefs.df[num]); + _tcsncpy (changed_prefs.df[num], s, 255); + xfree (s); + newis = changed_prefs.df[num][0] ? 1 : 0; + if (!(disabled & (1 << num))) { + if (!newis) { drv->dskchange = 1; + } else { + drive_insert (floppy + num, &currprefs, num, changed_prefs.df[num]); + if (drive_empty (floppy + num)) { + if (newis && old[0]) { + _tcscpy (changed_prefs.df[num], old); + drive_insert (floppy + num, &currprefs, num, changed_prefs.df[num]); + if (drive_empty (floppy + num)) + drv->dskchange = 1; + } + } } - } } - } - reset_drive_gui (num); - return src; + reset_drive_gui (num); + return src; } static uae_u32 getadfcrc (drive *drv) { - uae_u8 *b; - uae_u32 crc32; - int size; + uae_u8 *b; + uae_u32 crc32; + int size; - if (!drv->diskfile) - return 0; - zfile_fseek (drv->diskfile, 0, SEEK_END); - size = zfile_ftell (drv->diskfile); - b = (uae_u8*)malloc (size); - if (!b) - return 0; - zfile_fseek (drv->diskfile, 0, SEEK_SET); - zfile_fread (b, 1, size, drv->diskfile); - crc32 = get_crc32 (b, size); - free (b); - return crc32; + if (!drv->diskfile) + return 0; + zfile_fseek (drv->diskfile, 0, SEEK_END); + size = zfile_ftell (drv->diskfile); + b = (uae_u8*)malloc (size); + if (!b) + return 0; + zfile_fseek (drv->diskfile, 0, SEEK_SET); + zfile_fread (b, 1, size, drv->diskfile); + crc32 = get_crc32 (b, size); + free (b); + return crc32; } uae_u8 *save_disk (int num, int *len, uae_u8 *dstptr) { - uae_u8 *dstbak,*dst; - drive *drv; + uae_u8 *dstbak,*dst; + drive *drv; - drv = &floppy[num]; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = malloc (2+1+1+1+1+4+4+256); - save_u32 (drv->drive_id); /* drive type ID */ - save_u8 ((drv->motoroff ? 0:1) | ((disabled & (1 << num)) ? 2 : 0) | (drv->idbit ? 4 : 0) | (drv->dskchange ? 8 : 0)); - save_u8 (drv->cyl); /* cylinder */ - save_u8 (drv->dskready); /* dskready */ - save_u8 (drv->drive_id_scnt); /* id mode position */ - save_u32 (drv->mfmpos); /* disk position */ - save_u32 (getadfcrc (drv)); /* CRC of disk image */ - save_string (currprefs.df[num]);/* image name */ + drv = &floppy[num]; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (2+1+1+1+1+4+4+256); + save_u32 (drv->drive_id); /* drive type ID */ + save_u8 ((drv->motoroff ? 0:1) | ((disabled & (1 << num)) ? 2 : 0) | (drv->idbit ? 4 : 0) | (drv->dskchange ? 8 : 0)); + save_u8 (drv->cyl); /* cylinder */ + save_u8 (drv->dskready); /* dskready */ + save_u8 (drv->drive_id_scnt); /* id mode position */ + save_u32 (drv->mfmpos); /* disk position */ + save_u32 (getadfcrc (drv)); /* CRC of disk image */ + save_string (currprefs.df[num]);/* image name */ - *len = dst - dstbak; - return dstbak; + *len = dst - dstbak; + return dstbak; } /* internal floppy controller variables */ uae_u8 *restore_floppy (uae_u8 *src) { - word = restore_u16(); - bitoffset = restore_u8(); - dma_enable = restore_u8(); - disk_hpos = restore_u8() << 8; - dskdmaen = restore_u8(); - restore_u16 (); - //word |= restore_u16() << 16; + word = restore_u16(); + bitoffset = restore_u8(); + dma_enable = restore_u8(); + disk_hpos = restore_u8() << 8; + dskdmaen = restore_u8(); + restore_u16 (); + //word |= restore_u16() << 16; - return src; + return src; } uae_u8 *save_floppy(int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; + uae_u8 *dstbak, *dst; - /* flush dma buffer before saving */ + /* flush dma buffer before saving */ #if 0 - dodmafetch(); + dodmafetch(); #endif - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = (uae_u8*)malloc(2+1+1+1+1+2); - save_u16 (word); /* current fifo (low word) */ - save_u8 (bitoffset); /* dma bit offset */ - save_u8 (dma_enable); /* disk sync found */ - save_u8 (disk_hpos >> 8); /* next bit read position */ - save_u8 (dskdmaen); /* dma status */ - save_u16 (0); /* was current fifo (high word), but it was wrong???? */ - - *len = dst - dstbak; - return dstbak; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = (uae_u8*)malloc(2+1+1+1+1+2); + save_u16 (word); /* current fifo (low word) */ + save_u8 (bitoffset); /* dma bit offset */ + save_u8 (dma_enable); /* disk sync found */ + save_u8 (disk_hpos >> 8); /* next bit read position */ + save_u8 (dskdmaen); /* dma status */ + save_u16 (0); /* was current fifo (high word), but it was wrong???? */ + + *len = dst - dstbak; + return dstbak; } #endif /* SAVESTATE */ diff --git a/diskutil.c b/diskutil.c index 543d124b..1940fb84 100644 --- a/diskutil.c +++ b/diskutil.c @@ -23,7 +23,7 @@ static int drive_write_adf_amigados (uae_u16 *mbuf, uae_u16 *mend, uae_u8 *write for (;;) { int trackoffs; - /* all sectors complete? */ + /* all sectors complete? */ for (i = 0; i < 11; i++) { if (!writebuffer_ok[i]) break; @@ -137,121 +137,121 @@ int isamigatrack(uae_u16 *amigamfmbuffer, uae_u8 *mfmdata, int len, uae_u8 *writ static uae_u16 getmfmword (uae_u16 *mbuf, int shift) { - return (mbuf[0] << shift) | (mbuf[1] >> (16 - shift)); + return (mbuf[0] << shift) | (mbuf[1] >> (16 - shift)); } static uae_u8 mfmdecode (uae_u16 **mfmp, int shift) { - uae_u16 mfm = getmfmword (*mfmp, shift); - uae_u8 out = 0; - int i; + uae_u16 mfm = getmfmword (*mfmp, shift); + uae_u8 out = 0; + int i; - (*mfmp)++; - mfm &= 0x5555; - for (i = 0; i < 8; i++) { - out >>= 1; - if (mfm & 1) - out |= 0x80; - mfm >>= 2; - } - return out; + (*mfmp)++; + mfm &= 0x5555; + for (i = 0; i < 8; i++) { + out >>= 1; + if (mfm & 1) + out |= 0x80; + mfm >>= 2; + } + return out; } static int drive_write_adf_pc (uae_u16 *mbuf, uae_u16 *mend, uae_u8 *writebuffer, uae_u8 *writebuffer_ok, int track, int *outsize) { - int sectors, shift, sector, i; - uae_u8 mark; - uae_u8 secbuf[3 + 1 + 512]; - uae_u16 crc; - int mfmcount; + int sectors, shift, sector, i; + uae_u8 mark; + uae_u8 secbuf[3 + 1 + 512]; + uae_u16 crc; + int mfmcount; - secbuf[0] = secbuf[1] = secbuf[2] = 0xa1; - secbuf[3] = 0xfb; + secbuf[0] = secbuf[1] = secbuf[2] = 0xa1; + secbuf[3] = 0xfb; - sectors = 0; - sector = -1; - shift = 0; - mend -= (4 + 16 + 8 + 512); - mfmcount = 0; - for (;;) { + sectors = 0; + sector = -1; + shift = 0; + mend -= (4 + 16 + 8 + 512); + mfmcount = 0; + for (;;) { - *outsize = sectors * 512; - while (getmfmword (mbuf, shift) != 0x4489) { - if (mbuf >= mend) { - if (sectors >= 7) { - *outsize = sectors * 512; - return 0; + *outsize = sectors * 512; + while (getmfmword (mbuf, shift) != 0x4489) { + if (mbuf >= mend) { + if (sectors >= 7) { + *outsize = sectors * 512; + return 0; + } + write_log (L"* track %d, unexpected end of data\n", track); + return 1; + } + shift++; + if (shift == 16) { + shift = 0; + mbuf++; + } } - write_log (L"* track %d, unexpected end of data\n", track); - return 1; - } - shift++; - if (shift == 16) { - shift = 0; - mbuf++; - } - } - mfmcount++; - while (getmfmword (mbuf, shift) == 0x4489) { - mfmcount++; - if (mbuf >= mend) { - if (sectors >= 7) { - *outsize = sectors * 512; - return 0; + mfmcount++; + while (getmfmword (mbuf, shift) == 0x4489) { + mfmcount++; + if (mbuf >= mend) { + if (sectors >= 7) { + *outsize = sectors * 512; + return 0; + } + return 1; + } + mbuf++; } - return 1; - } - mbuf++; - } - mfmcount = 0; - mark = mfmdecode (&mbuf, shift); - if (mark == 0xfe) { - uae_u8 tmp[8]; - uae_u8 cyl, head, size; + mfmcount = 0; + mark = mfmdecode (&mbuf, shift); + if (mark == 0xfe) { + uae_u8 tmp[8]; + uae_u8 cyl, head, size; - cyl = mfmdecode (&mbuf, shift); - head = mfmdecode (&mbuf, shift); - sector = mfmdecode (&mbuf, shift); - size = mfmdecode (&mbuf, shift); - crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); + cyl = mfmdecode (&mbuf, shift); + head = mfmdecode (&mbuf, shift); + sector = mfmdecode (&mbuf, shift); + size = mfmdecode (&mbuf, shift); + crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); - tmp[0] = 0xa1; tmp[1] = 0xa1; tmp[2] = 0xa1; tmp[3] = mark; - tmp[4] = cyl; tmp[5] = head; tmp[6] = sector; tmp[7] = size; - if (get_crc16 (tmp, 8) != crc || cyl != track / 2 || head != (track & 1) || size != 2 || sector < 1 || sector > 20) { - write_log (L"PCDOS: track %d, corrupted sector header\n", track); - continue; - } - sector--; - continue; - } - if (mark != 0xfb) { - write_log (L"PCDOS: track %d: unknown address mark %02X\n", track, mark); - continue; - } - if (sector < 0) - continue; - for (i = 0; i < 512; i++) - secbuf[i + 4] = mfmdecode (&mbuf, shift); - sectors++; - memcpy (writebuffer + sector * 512, secbuf + 4, 512); - sector = 0; - crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); - if (get_crc16 (secbuf, 3 + 1 + 512) != crc) { - write_log (L"PCDOS: track %d, sector %d data checksum error\n", - track, sector + 1); - continue; - } + tmp[0] = 0xa1; tmp[1] = 0xa1; tmp[2] = 0xa1; tmp[3] = mark; + tmp[4] = cyl; tmp[5] = head; tmp[6] = sector; tmp[7] = size; + if (get_crc16 (tmp, 8) != crc || cyl != track / 2 || head != (track & 1) || size != 2 || sector < 1 || sector > 20) { + write_log (L"PCDOS: track %d, corrupted sector header\n", track); + continue; + } + sector--; + continue; + } + if (mark != 0xfb) { + write_log (L"PCDOS: track %d: unknown address mark %02X\n", track, mark); + continue; + } + if (sector < 0) + continue; + for (i = 0; i < 512; i++) + secbuf[i + 4] = mfmdecode (&mbuf, shift); + sectors++; + memcpy (writebuffer + sector * 512, secbuf + 4, 512); + sector = 0; + crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift); + if (get_crc16 (secbuf, 3 + 1 + 512) != crc) { + write_log (L"PCDOS: track %d, sector %d data checksum error\n", + track, sector + 1); + continue; + } - } + } } int ispctrack(uae_u16 *amigamfmbuffer, uae_u8 *mfmdata, int len, uae_u8 *writebuffer, uae_u8 *writebuffer_ok, int track, int *outsize) { - int i; - for (i = 0; i < len / 2; i++) - amigamfmbuffer[i] = mfmdata[i * 2 + 1] | (mfmdata[i * 2 + 0] << 8); - i = drive_write_adf_pc (amigamfmbuffer, amigamfmbuffer + len / 2, writebuffer, writebuffer_ok, track, outsize); - if (*outsize < 9 * 512) - *outsize = 9 * 512; - return i; + int i; + for (i = 0; i < len / 2; i++) + amigamfmbuffer[i] = mfmdata[i * 2 + 1] | (mfmdata[i * 2 + 0] << 8); + i = drive_write_adf_pc (amigamfmbuffer, amigamfmbuffer + len / 2, writebuffer, writebuffer_ok, track, outsize); + if (*outsize < 9 * 512) + *outsize = 9 * 512; + return i; } diff --git a/dongle.c b/dongle.c index fead7542..e9742c94 100644 --- a/dongle.c +++ b/dongle.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Emulates simple protection dongles - * - * Copyright 2009 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Emulates simple protection dongles +* +* Copyright 2009 Toni Wilen +*/ #include "sysconfig.h" @@ -29,48 +29,48 @@ static int flag; static unsigned int cycles; /* - Robocop 3 - - set firebutton as output - - read JOY1DAT - - pulse firebutton (high->low) - - read JOY1DAT - - JOY1DAT bit 8 must toggle - - Leaderboard - - JOY1DAT, both up and down active (0x0101) - - B.A.T. II - - set all serial pins as output except CTS - - game pulses DTR (high->low) - - CTS must be one - - delay - - CTS must be zero - - Italy'90 Soccer - - 220k resistor between pins 5 (+5v) and 7 (POTX) - - POT1DAT POTX must be between 0x32 and 0x60 - - Dames Grand Maitre - - read POT1 - - POT1X != POT1Y - - POT1Y * 256 / POT1X must be between 450 and 500 - - Rugby Coach - - JOY1DAT, left, up and down active (0x0301) - - Cricket Captain - - JOY0DAT bits 0 and 1: - - 10 01 11 allowed - - must continuously change state - - Leviathan - - same as Leaderboard but in mouse port - - Logistix/SuperBase - - second button must be high - - POT1X = 150k - - POT1Y = 100k - - POT1X * 10 / POT1Y must be between 12 and 33 +Robocop 3 +- set firebutton as output +- read JOY1DAT +- pulse firebutton (high->low) +- read JOY1DAT +- JOY1DAT bit 8 must toggle + +Leaderboard +- JOY1DAT, both up and down active (0x0101) + +B.A.T. II +- set all serial pins as output except CTS +- game pulses DTR (high->low) +- CTS must be one +- delay +- CTS must be zero + +Italy'90 Soccer +- 220k resistor between pins 5 (+5v) and 7 (POTX) +- POT1DAT POTX must be between 0x32 and 0x60 + +Dames Grand Maitre +- read POT1 +- POT1X != POT1Y +- POT1Y * 256 / POT1X must be between 450 and 500 + +Rugby Coach +- JOY1DAT, left, up and down active (0x0301) + +Cricket Captain +- JOY0DAT bits 0 and 1: +- 10 01 11 allowed +- must continuously change state + +Leviathan +- same as Leaderboard but in mouse port + +Logistix/SuperBase +- second button must be high +- POT1X = 150k +- POT1Y = 100k +- POT1X * 10 / POT1Y must be between 12 and 33 */ @@ -79,48 +79,48 @@ static uae_u8 oldcia[2][16]; void dongle_reset (void) { - flag = 0; - memset (oldcia, 0, sizeof oldcia); + flag = 0; + memset (oldcia, 0, sizeof oldcia); } uae_u8 dongle_cia_read (int cia, int reg, uae_u8 val) { - if (!currprefs.dongle) - return val; - switch (currprefs.dongle) - { + if (!currprefs.dongle) + return val; + switch (currprefs.dongle) + { case BAT2: - if (cia == 1 && reg == 0) { - if (!flag || get_cycles () > cycles + CYCLE_UNIT * 200) { - val &= ~0x10; - flag = 0; - } else { - val |= 0x10; - } + if (cia == 1 && reg == 0) { + if (!flag || get_cycles () > cycles + CYCLE_UNIT * 200) { + val &= ~0x10; + flag = 0; + } else { + val |= 0x10; + } + } + break; } - break; - } - return val; + return val; } void dongle_cia_write (int cia, int reg, uae_u8 val) { - if (!currprefs.dongle) - return; - switch (currprefs.dongle) - { + if (!currprefs.dongle) + return; + switch (currprefs.dongle) + { case ROBOCOP3: - if (cia == 0 && reg == 0 && (val & 0x80)) - flag ^= 1; - break; + if (cia == 0 && reg == 0 && (val & 0x80)) + flag ^= 1; + break; case BAT2: - if (cia == 1 && reg == 0 && !(val & 0x80)) { - flag = 1; - cycles = get_cycles (); + if (cia == 1 && reg == 0 && !(val & 0x80)) { + flag = 1; + cycles = get_cycles (); + } + break; } - break; - } - oldcia[cia][reg] = val; + oldcia[cia][reg] = val; } void dongle_joytest (uae_u16 val) @@ -129,107 +129,107 @@ void dongle_joytest (uae_u16 val) uae_u16 dongle_joydat (int port, uae_u16 val) { - if (!currprefs.dongle) - return val; - switch (currprefs.dongle) - { + if (!currprefs.dongle) + return val; + switch (currprefs.dongle) + { case ROBOCOP3: - if (port == 1 && flag) - val += 0x100; - break; + if (port == 1 && flag) + val += 0x100; + break; case LEADERBOARD: - if (port == 1) { - val &= ~0x0303; - val |= 0x0101; - } - break; + if (port == 1) { + val &= ~0x0303; + val |= 0x0101; + } + break; case LEVIATHAN: - if (port == 0) { - val &= ~0x0303; - val |= 0x0101; - } - break; + if (port == 0) { + val &= ~0x0303; + val |= 0x0101; + } + break; case RUGBYCOACH: - if (port == 1) { - val &= ~0x0303; - val|= 0x0301; - } - break; + if (port == 1) { + val &= ~0x0303; + val|= 0x0301; + } + break; case CRICKETCAPTAIN: - if (port == 0) { - val &= ~0x0003; - if (flag == 0) - val |= 0x0001; - else - val |= 0x0002; + if (port == 0) { + val &= ~0x0003; + if (flag == 0) + val |= 0x0001; + else + val |= 0x0002; + } + flag ^= 1; + break; } - flag ^= 1; - break; - } - return val; + return val; } void dongle_potgo (uae_u16 val) { - if (!currprefs.dongle) - return; - switch (currprefs.dongle) - { + if (!currprefs.dongle) + return; + switch (currprefs.dongle) + { case ITALY90: case LOGISTIX: case DAMESGRANDMAITRE: - flag = (uaerand () & 7) - 3; - break; - } + flag = (uaerand () & 7) - 3; + break; + } } uae_u16 dongle_potgor (uae_u16 val) { - if (!currprefs.dongle) - return val; - switch (currprefs.dongle) - { + if (!currprefs.dongle) + return val; + switch (currprefs.dongle) + { case LOGISTIX: - val |= 1 << 14; - break; - } - return val; + val |= 1 << 14; + break; + } + return val; } int dongle_analogjoy (int joy, int axis) { - int v = -1; - if (!currprefs.dongle) - return -1; - switch (currprefs.dongle) - { + int v = -1; + if (!currprefs.dongle) + return -1; + switch (currprefs.dongle) + { case ITALY90: - if (joy == 1 && axis == 0) - v = 73; - break; + if (joy == 1 && axis == 0) + v = 73; + break; case LOGISTIX: - if (joy == 1) { - if (axis == 0) - v = 21; - if (axis == 1) - v = 10; - } - break; + if (joy == 1) { + if (axis == 0) + v = 21; + if (axis == 1) + v = 10; + } + break; case DAMESGRANDMAITRE: - if (joy == 1) { - if (axis == 1) - v = 80; - if (axis == 0) - v = 43; + if (joy == 1) { + if (axis == 1) + v = 80; + if (axis == 0) + v = 43; + } + break; + + } + if (v >= 0) { + v += flag; + if (v < 0) + v = 0; } - break; - - } - if (v >= 0) { - v += flag; - if (v < 0) - v = 0; - } - return v; + return v; } \ No newline at end of file diff --git a/drawing.c b/drawing.c index d9a985b5..3f5bf95c 100644 --- a/drawing.c +++ b/drawing.c @@ -1,32 +1,32 @@ //#define XLINECHECK - /* - * UAE - The Un*x Amiga Emulator - * - * Screen drawing functions - * - * Copyright 1995-2000 Bernd Schmidt - * Copyright 1995 Alessandro Bissacco - * Copyright 2000-2008 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Screen drawing functions +* +* Copyright 1995-2000 Bernd Schmidt +* Copyright 1995 Alessandro Bissacco +* Copyright 2000-2008 Toni Wilen +*/ /* There are a couple of concepts of "coordinates" in this file. - - DIW coordinates - - DDF coordinates (essentially cycles, resolution lower than lores by a factor of 2) - - Pixel coordinates - * in the Amiga's resolution as determined by BPLCON0 ("Amiga coordinates") - * in the window resolution as determined by the preferences ("window coordinates"). - * in the window resolution, and with the origin being the topmost left corner of - the window ("native coordinates") - One note about window coordinates. The visible area depends on the width of the - window, and the centering code. The first visible horizontal window coordinate is - often _not_ 0, but the value of VISIBLE_LEFT_BORDER instead. - - One important thing to remember: DIW coordinates are in the lowest possible - resolution. - - To prevent extremely bad things (think pixels cut in half by window borders) from - happening, all ports should restrict window widths to be multiples of 16 pixels. */ +- DIW coordinates +- DDF coordinates (essentially cycles, resolution lower than lores by a factor of 2) +- Pixel coordinates +* in the Amiga's resolution as determined by BPLCON0 ("Amiga coordinates") +* in the window resolution as determined by the preferences ("window coordinates"). +* in the window resolution, and with the origin being the topmost left corner of +the window ("native coordinates") +One note about window coordinates. The visible area depends on the width of the +window, and the centering code. The first visible horizontal window coordinate is +often _not_ 0, but the value of VISIBLE_LEFT_BORDER instead. + +One important thing to remember: DIW coordinates are in the lowest possible +resolution. + +To prevent extremely bad things (think pixels cut in half by window borders) from +happening, all ports should restrict window widths to be multiples of 16 pixels. */ #include "sysconfig.h" #include "sysdeps.h" @@ -57,25 +57,25 @@ int debug_bpl_mask = 0xff, debug_bpl_mask_one; static void lores_reset (void) { - lores_factor = currprefs.gfx_resolution ? 2 : 1; - lores_shift = currprefs.gfx_resolution; - if (doublescan > 0) { - if (lores_shift < 2) - lores_shift++; - lores_factor = 2; - } - sprite_buffer_res = currprefs.gfx_resolution; - if (doublescan > 0 && sprite_buffer_res < RES_SUPERHIRES) - sprite_buffer_res++; + lores_factor = currprefs.gfx_resolution ? 2 : 1; + lores_shift = currprefs.gfx_resolution; + if (doublescan > 0) { + if (lores_shift < 2) + lores_shift++; + lores_factor = 2; + } + sprite_buffer_res = currprefs.gfx_resolution; + if (doublescan > 0 && sprite_buffer_res < RES_SUPERHIRES) + sprite_buffer_res++; } int aga_mode; /* mirror of chipset_mask & CSMASK_AGA */ int direct_rgb; /* The shift factor to apply when converting between Amiga coordinates and window - coordinates. Zero if the resolution is the same, positive if window coordinates - have a higher resolution (i.e. we're stretching the image), negative if window - coordinates have a lower resolution (i.e. we're shrinking the image). */ +coordinates. Zero if the resolution is the same, positive if window coordinates +have a higher resolution (i.e. we're stretching the image), negative if window +coordinates have a lower resolution (i.e. we're shrinking the image). */ static int res_shift; static int linedbl, linedbld; @@ -85,12 +85,12 @@ int interlace_seen = 0; static int can_use_lores = 0, frame_res, frame_res_lace, last_max_ypos; /* Lookup tables for dual playfields. The dblpf_*1 versions are for the case - that playfield 1 has the priority, dbplpf_*2 are used if playfield 2 has - priority. If we need an array for non-dual playfield mode, it has no number. */ +that playfield 1 has the priority, dbplpf_*2 are used if playfield 2 has +priority. If we need an array for non-dual playfield mode, it has no number. */ /* The dbplpf_ms? arrays contain a shift value. plf_spritemask is initialized - to contain two 16 bit words, with the appropriate mask if pf1 is in the - foreground being at bit offset 0, the one used if pf2 is in front being at - offset 16. */ +to contain two 16 bit words, with the appropriate mask if pf1 is in the +foreground being at bit offset 0, the one used if pf2 is in front being at +offset 16. */ static int dblpf_ms1[256], dblpf_ms2[256], dblpf_ms[256]; static int dblpf_ind1[256], dblpf_ind2[256]; @@ -104,7 +104,7 @@ static int sprite_offs[256]; static uae_u32 clxtab[256]; /* Video buffer description structure. Filled in by the graphics system - * dependent code. */ +* dependent code. */ struct vidbuf_description gfxvidinfo; @@ -112,9 +112,9 @@ struct vidbuf_description gfxvidinfo; xcolnr xcolors[4096]; struct spritepixelsbuf { - uae_u8 attach; - uae_u8 stdata; - uae_u16 data; + uae_u8 attach; + uae_u8 stdata; + uae_u16 data; }; static struct spritepixelsbuf spritepixels[MAX_PIXELS_PER_LINE]; static int sprite_first_x, sprite_last_x; @@ -134,15 +134,15 @@ int xbluecolor_s, xbluecolor_b, xbluecolor_m; struct color_entry colors_for_drawing; /* The size of these arrays is pretty arbitrary; it was chosen to be "more - than enough". The coordinates used for indexing into these arrays are - almost, but not quite, Amiga coordinates (there's a constant offset). */ +than enough". The coordinates used for indexing into these arrays are +almost, but not quite, Amiga coordinates (there's a constant offset). */ union { - /* Let's try to align this thing. */ - double uupzuq; - long int cruxmedo; - uae_u8 apixels[MAX_PIXELS_PER_LINE * 2]; - uae_u16 apixels_w[MAX_PIXELS_PER_LINE * 2 / sizeof (uae_u16)]; - uae_u32 apixels_l[MAX_PIXELS_PER_LINE * 2 / sizeof (uae_u32)]; + /* Let's try to align this thing. */ + double uupzuq; + long int cruxmedo; + uae_u8 apixels[MAX_PIXELS_PER_LINE * 2]; + uae_u16 apixels_w[MAX_PIXELS_PER_LINE * 2 / sizeof (uae_u16)]; + uae_u32 apixels_l[MAX_PIXELS_PER_LINE * 2 / sizeof (uae_u32)]; } pixdata; #ifdef OS_WITHOUT_MEMORY_MANAGEMENT @@ -187,7 +187,7 @@ uae_u8 line_data[(MAXVPOS + 1) * 2][MAX_PLANES * MAX_WORDS_PER_LINE * 2]; /* Centering variables. */ static int min_diwstart, max_diwstop; /* The visible window: VISIBLE_LEFT_BORDER contains the left border of the visible - area, VISIBLE_RIGHT_BORDER the right border. These are in window coordinates. */ +area, VISIBLE_RIGHT_BORDER the right border. These are in window coordinates. */ int visible_left_border, visible_right_border; static int linetoscr_x_adjust_bytes; static int thisframe_y_adjust; @@ -196,7 +196,7 @@ static int extra_y_adjust; int thisframe_first_drawn_line, thisframe_last_drawn_line; /* A frame counter that forces a redraw after at least one skipped frame in - interlace mode. */ +interlace mode. */ static int last_redraw_point; static int first_drawn_line, last_drawn_line; @@ -205,8 +205,8 @@ static int first_block_line, last_block_line; #define NO_BLOCK -3 /* These are generated by the drawing code from the line_decisions array for - each line that needs to be drawn. These are basically extracted out of - bit fields in the hardware registers. */ +each line that needs to be drawn. These are basically extracted out of +bit fields in the hardware registers. */ static int bplehb, bplham, bpldualpf, bpldualpfpri, bpldualpf2of, bplplanecnt, ecsshres, issprites; static int bplres; static int plf1pri, plf2pri, bplxor; @@ -227,37 +227,37 @@ static int picasso_redraw_necessary; #ifdef XLINECHECK static void xlinecheck (unsigned int start, unsigned int end) { - unsigned int xstart = (unsigned int)xlinebuffer + start * gfxvidinfo.pixbytes; - unsigned int xend = (unsigned int)xlinebuffer + end * gfxvidinfo.pixbytes; - unsigned int end1 = (unsigned int)gfxvidinfo.bufmem + gfxvidinfo.rowbytes * gfxvidinfo.height; - int min = linetoscr_x_adjust_bytes / gfxvidinfo.pixbytes; - int ok = 1; - - if (xstart >= gfxvidinfo.emergmem && xstart < gfxvidinfo.emergmem + 4096 * gfxvidinfo.pixbytes && - xend >= gfxvidinfo.emergmem && xend < gfxvidinfo.emergmem + 4096 * gfxvidinfo.pixbytes) - return; - - if (xstart < (unsigned int)gfxvidinfo.bufmem || xend < (unsigned int)gfxvidinfo.bufmem) - ok = 0; - if (xend > end1 || xstart >= end1) - ok = 0; - xstart -= (unsigned int)gfxvidinfo.bufmem; - xend -= (unsigned int)gfxvidinfo.bufmem; - if ((xstart % gfxvidinfo.rowbytes) >= gfxvidinfo.width * gfxvidinfo.pixbytes) - ok = 0; - if ((xend % gfxvidinfo.rowbytes) >= gfxvidinfo.width * gfxvidinfo.pixbytes) - ok = 0; - if (xstart >= xend) - ok = 0; - if (xend - xstart > gfxvidinfo.width * gfxvidinfo.pixbytes) - ok = 0; - - if (!ok) { - write_log (L"*** %d-%d (%dx%dx%d %d) %p\n", - start - min, end - min, gfxvidinfo.width, gfxvidinfo.height, - gfxvidinfo.pixbytes, gfxvidinfo.rowbytes, - xlinebuffer); - } + unsigned int xstart = (unsigned int)xlinebuffer + start * gfxvidinfo.pixbytes; + unsigned int xend = (unsigned int)xlinebuffer + end * gfxvidinfo.pixbytes; + unsigned int end1 = (unsigned int)gfxvidinfo.bufmem + gfxvidinfo.rowbytes * gfxvidinfo.height; + int min = linetoscr_x_adjust_bytes / gfxvidinfo.pixbytes; + int ok = 1; + + if (xstart >= gfxvidinfo.emergmem && xstart < gfxvidinfo.emergmem + 4096 * gfxvidinfo.pixbytes && + xend >= gfxvidinfo.emergmem && xend < gfxvidinfo.emergmem + 4096 * gfxvidinfo.pixbytes) + return; + + if (xstart < (unsigned int)gfxvidinfo.bufmem || xend < (unsigned int)gfxvidinfo.bufmem) + ok = 0; + if (xend > end1 || xstart >= end1) + ok = 0; + xstart -= (unsigned int)gfxvidinfo.bufmem; + xend -= (unsigned int)gfxvidinfo.bufmem; + if ((xstart % gfxvidinfo.rowbytes) >= gfxvidinfo.width * gfxvidinfo.pixbytes) + ok = 0; + if ((xend % gfxvidinfo.rowbytes) >= gfxvidinfo.width * gfxvidinfo.pixbytes) + ok = 0; + if (xstart >= xend) + ok = 0; + if (xend - xstart > gfxvidinfo.width * gfxvidinfo.pixbytes) + ok = 0; + + if (!ok) { + write_log (L"*** %d-%d (%dx%dx%d %d) %p\n", + start - min, end - min, gfxvidinfo.width, gfxvidinfo.height, + gfxvidinfo.pixbytes, gfxvidinfo.rowbytes, + xlinebuffer); + } } #else #define xlinecheck @@ -266,51 +266,51 @@ static void xlinecheck (unsigned int start, unsigned int end) STATIC_INLINE void count_frame (void) { - framecnt++; - if (framecnt >= currprefs.gfx_framerate) - framecnt = 0; - if (inhibit_frame) - framecnt = 1; + framecnt++; + if (framecnt >= currprefs.gfx_framerate) + framecnt = 0; + if (inhibit_frame) + framecnt = 1; } STATIC_INLINE int xshift (int x, int shift) { - if (shift < 0) - return x >> (-shift); - else - return x << shift; + if (shift < 0) + return x >> (-shift); + else + return x << shift; } int coord_native_to_amiga_x (int x) { - x += visible_left_border; - x = xshift (x, 1 - lores_shift); - return x + 2 * DISPLAY_LEFT_SHIFT - 2 * DIW_DDF_OFFSET; + x += visible_left_border; + x = xshift (x, 1 - lores_shift); + return x + 2 * DISPLAY_LEFT_SHIFT - 2 * DIW_DDF_OFFSET; } int coord_native_to_amiga_y (int y) { - return native2amiga_line_map[y] + thisframe_y_adjust - minfirstline; + return native2amiga_line_map[y] + thisframe_y_adjust - minfirstline; } STATIC_INLINE int res_shift_from_window (int x) { - if (res_shift >= 0) - return x >> res_shift; - return x << -res_shift; + if (res_shift >= 0) + return x >> res_shift; + return x << -res_shift; } STATIC_INLINE int res_shift_from_amiga (int x) { - if (res_shift >= 0) - return x >> res_shift; - return x << -res_shift; + if (res_shift >= 0) + return x >> res_shift; + return x << -res_shift; } void notice_screen_contents_lost (void) { - picasso_redraw_necessary = 1; - frame_redraw_necessary = 2; + picasso_redraw_necessary = 1; + frame_redraw_necessary = 2; } @@ -329,189 +329,189 @@ static int gclow, gcloh, gclox, gcloy; static void reset_custom_limits (void) { - gclow = gcloh = gclox = gcloy = 0; + gclow = gcloh = gclox = gcloy = 0; } int get_custom_limits (int *pw, int *ph, int *pdx, int *pdy) { - int w, h, dx, dy, y1, y2, dbl1, dbl2; - int ret = 0; + int w, h, dx, dy, y1, y2, dbl1, dbl2; + int ret = 0; - if (!pw || !ph || !pdx || !pdy) { - reset_custom_limits (); - return 0; - } - *pw = gclow; - *ph = gcloh; - *pdx = gclox; - *pdy = gcloy; - - if (gclow > 0 && gcloh > 0) - ret = -1; - - if (doublescan <= 0) { - if (diwfirstword_total < (48 << currprefs.gfx_resolution)) - diwfirstword_total = 48 << currprefs.gfx_resolution; - if (diwlastword_total > (448 << currprefs.gfx_resolution)) - diwlastword_total = 448 << currprefs.gfx_resolution; - ddffirstword_total = coord_hw_to_window_x (ddffirstword_total * 2 + DIW_DDF_OFFSET); - ddflastword_total = coord_hw_to_window_x (ddflastword_total * 2 + DIW_DDF_OFFSET); - if (ddffirstword_total < (48 << currprefs.gfx_resolution)) - ddffirstword_total = 48 << currprefs.gfx_resolution; - if (ddflastword_total > (448 << currprefs.gfx_resolution)) - ddflastword_total = 448 << currprefs.gfx_resolution; - if (0 && !(currprefs.chipset_mask & CSMASK_AGA)) { - if (ddffirstword_total > diwfirstword_total) - diwfirstword_total = ddffirstword_total; - if (ddflastword_total < diwlastword_total) - diwlastword_total = ddflastword_total; - } - } - - w = diwlastword_total - diwfirstword_total; - dx = diwfirstword_total - visible_left_border; - - y2 = plflastline_total; - if (y2 > last_planes_vpos) - y2 = last_planes_vpos; - y1 = plffirstline_total; - if (first_planes_vpos > y1) - y1 = first_planes_vpos; - if (minfirstline > y1) - y1 = minfirstline; - - dbl2 = dbl1 = currprefs.gfx_linedbl ? 1 : 0; - if (doublescan > 0 && interlace_seen <= 0) { - dbl1--; - dbl2--; - } - - h = y2 - y1; - dy = y1 - minfirstline; - - if (first_planes_vpos == 0) { - // no planes enabled during frame - if (ret < 0) - return 1; - h = currprefs.ntscmode ? 200 : 240; - w = 320 << currprefs.gfx_resolution; - dy = 36 / 2; - dx = 58; - } - - if (dx < 0) - dx = 1; - - dy = xshift (dy, dbl2); - h = xshift (h, dbl1); - - if (w == 0 || h == 0) - return 0; + if (!pw || !ph || !pdx || !pdy) { + reset_custom_limits (); + return 0; + } + *pw = gclow; + *ph = gcloh; + *pdx = gclox; + *pdy = gcloy; + + if (gclow > 0 && gcloh > 0) + ret = -1; + + if (doublescan <= 0) { + if (diwfirstword_total < (48 << currprefs.gfx_resolution)) + diwfirstword_total = 48 << currprefs.gfx_resolution; + if (diwlastword_total > (448 << currprefs.gfx_resolution)) + diwlastword_total = 448 << currprefs.gfx_resolution; + ddffirstword_total = coord_hw_to_window_x (ddffirstword_total * 2 + DIW_DDF_OFFSET); + ddflastword_total = coord_hw_to_window_x (ddflastword_total * 2 + DIW_DDF_OFFSET); + if (ddffirstword_total < (48 << currprefs.gfx_resolution)) + ddffirstword_total = 48 << currprefs.gfx_resolution; + if (ddflastword_total > (448 << currprefs.gfx_resolution)) + ddflastword_total = 448 << currprefs.gfx_resolution; + if (0 && !(currprefs.chipset_mask & CSMASK_AGA)) { + if (ddffirstword_total > diwfirstword_total) + diwfirstword_total = ddffirstword_total; + if (ddflastword_total < diwlastword_total) + diwlastword_total = ddflastword_total; + } + } + + w = diwlastword_total - diwfirstword_total; + dx = diwfirstword_total - visible_left_border; + + y2 = plflastline_total; + if (y2 > last_planes_vpos) + y2 = last_planes_vpos; + y1 = plffirstline_total; + if (first_planes_vpos > y1) + y1 = first_planes_vpos; + if (minfirstline > y1) + y1 = minfirstline; + + dbl2 = dbl1 = currprefs.gfx_linedbl ? 1 : 0; + if (doublescan > 0 && interlace_seen <= 0) { + dbl1--; + dbl2--; + } + + h = y2 - y1; + dy = y1 - minfirstline; + + if (first_planes_vpos == 0) { + // no planes enabled during frame + if (ret < 0) + return 1; + h = currprefs.ntscmode ? 200 : 240; + w = 320 << currprefs.gfx_resolution; + dy = 36 / 2; + dx = 58; + } + + if (dx < 0) + dx = 1; + + dy = xshift (dy, dbl2); + h = xshift (h, dbl1); - if (doublescan <= 0) { - if ((w >> currprefs.gfx_resolution) < MIN_DISPLAY_W) { - dx += (w - (MIN_DISPLAY_W << currprefs.gfx_resolution)) / 2; - w = MIN_DISPLAY_W << currprefs.gfx_resolution; - } - if ((h >> dbl1) < MIN_DISPLAY_H) { - dy += (h - (MIN_DISPLAY_H << dbl1)) / 2; - h = MIN_DISPLAY_H << dbl1; - } - if ((w >> currprefs.gfx_resolution) > MAX_DISPLAY_W) { - dx += (w - (MAX_DISPLAY_W << currprefs.gfx_resolution)) / 2; - w = MAX_DISPLAY_W << currprefs.gfx_resolution; - } - if ((h >> dbl1) > MAX_DISPLAY_H) { - dy += (h - (MAX_DISPLAY_H << dbl1)) / 2; - h = MAX_DISPLAY_H << dbl1; - } - } - - if (gclow == w && gcloh == h && gclox == dx && gcloy == dy) - return ret; - - if (w <= 0 || h <= 0 || dx <= 0 || dy <= 0) - return ret; - if (doublescan <= 0) { - if (dx > gfxvidinfo.width / 3) - return ret; - if (dy > gfxvidinfo.height / 3) - return ret; - } - - gclow = w; - gcloh = h; - gclox = dx; - gcloy = dy; - *pw = w; - *ph = h; - *pdx = dx; - *pdy = dy; - - write_log (L"Display Size: %dx%d Offset: %dx%d\n", w, h, dx, dy); - write_log (L"First: %d Last: %d MinV: %d MaxV: %d Min: %d\n", - plffirstline_total, plflastline_total, - first_planes_vpos, last_planes_vpos, minfirstline); - return 1; + if (w == 0 || h == 0) + return 0; + + if (doublescan <= 0) { + if ((w >> currprefs.gfx_resolution) < MIN_DISPLAY_W) { + dx += (w - (MIN_DISPLAY_W << currprefs.gfx_resolution)) / 2; + w = MIN_DISPLAY_W << currprefs.gfx_resolution; + } + if ((h >> dbl1) < MIN_DISPLAY_H) { + dy += (h - (MIN_DISPLAY_H << dbl1)) / 2; + h = MIN_DISPLAY_H << dbl1; + } + if ((w >> currprefs.gfx_resolution) > MAX_DISPLAY_W) { + dx += (w - (MAX_DISPLAY_W << currprefs.gfx_resolution)) / 2; + w = MAX_DISPLAY_W << currprefs.gfx_resolution; + } + if ((h >> dbl1) > MAX_DISPLAY_H) { + dy += (h - (MAX_DISPLAY_H << dbl1)) / 2; + h = MAX_DISPLAY_H << dbl1; + } + } + + if (gclow == w && gcloh == h && gclox == dx && gcloy == dy) + return ret; + + if (w <= 0 || h <= 0 || dx <= 0 || dy <= 0) + return ret; + if (doublescan <= 0) { + if (dx > gfxvidinfo.width / 3) + return ret; + if (dy > gfxvidinfo.height / 3) + return ret; + } + + gclow = w; + gcloh = h; + gclox = dx; + gcloy = dy; + *pw = w; + *ph = h; + *pdx = dx; + *pdy = dy; + + write_log (L"Display Size: %dx%d Offset: %dx%d\n", w, h, dx, dy); + write_log (L"First: %d Last: %d MinV: %d MaxV: %d Min: %d\n", + plffirstline_total, plflastline_total, + first_planes_vpos, last_planes_vpos, minfirstline); + return 1; } void get_custom_mouse_limits (int *pw, int *ph, int *pdx, int *pdy, int dbl) { - int delay1, delay2; - int w, h, dx, dy, dbl1, dbl2, y1, y2; - - w = diwlastword_total - diwfirstword_total; - dx = diwfirstword_total - visible_left_border; - - y2 = plflastline_total; - if (y2 > last_planes_vpos) - y2 = last_planes_vpos; - y1 = plffirstline_total; - if (first_planes_vpos > y1) - y1 = first_planes_vpos; - if (minfirstline > y1) - y1 = minfirstline; - - h = y2 - y1; - dy = y1 - minfirstline; - - if (*pw > 0) - w = *pw; - - w = xshift (w, res_shift); - - if (*ph > 0) - h = *ph; - - delay1 = (firstword_bplcon1 & 0x0f) | ((firstword_bplcon1 & 0x0c00) >> 6); - delay2 = ((firstword_bplcon1 >> 4) & 0x0f) | (((firstword_bplcon1 >> 4) & 0x0c00) >> 6); - if (delay1 == delay2) - ;//dx += delay1; - - dx = xshift (dx, res_shift); - - dbl2 = dbl1 = currprefs.gfx_linedbl ? 1 : 0; - if ((doublescan > 0 || interlace_seen > 0) && !dbl) { - dbl1--; - dbl2--; - } - if (interlace_seen > 0) - dbl2++; - if (interlace_seen <= 0 && dbl) - dbl2--; - h = xshift (h, dbl1); - dy = xshift (dy, dbl2); - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - if (dx < 0) - dx = 0; - if (dy < 0) - dy = 0; - *pw = w; *ph = h; - *pdx = dx; *pdy = dy; + int delay1, delay2; + int w, h, dx, dy, dbl1, dbl2, y1, y2; + + w = diwlastword_total - diwfirstword_total; + dx = diwfirstword_total - visible_left_border; + + y2 = plflastline_total; + if (y2 > last_planes_vpos) + y2 = last_planes_vpos; + y1 = plffirstline_total; + if (first_planes_vpos > y1) + y1 = first_planes_vpos; + if (minfirstline > y1) + y1 = minfirstline; + + h = y2 - y1; + dy = y1 - minfirstline; + + if (*pw > 0) + w = *pw; + + w = xshift (w, res_shift); + + if (*ph > 0) + h = *ph; + + delay1 = (firstword_bplcon1 & 0x0f) | ((firstword_bplcon1 & 0x0c00) >> 6); + delay2 = ((firstword_bplcon1 >> 4) & 0x0f) | (((firstword_bplcon1 >> 4) & 0x0c00) >> 6); + if (delay1 == delay2) + ;//dx += delay1; + + dx = xshift (dx, res_shift); + + dbl2 = dbl1 = currprefs.gfx_linedbl ? 1 : 0; + if ((doublescan > 0 || interlace_seen > 0) && !dbl) { + dbl1--; + dbl2--; + } + if (interlace_seen > 0) + dbl2++; + if (interlace_seen <= 0 && dbl) + dbl2--; + h = xshift (h, dbl1); + dy = xshift (dy, dbl2); + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + if (dx < 0) + dx = 0; + if (dy < 0) + dy = 0; + *pw = w; *ph = h; + *pdx = dx; *pdy = dy; } static struct decision *dp_for_drawing; @@ -520,25 +520,25 @@ static struct draw_info *dip_for_drawing; /* Record DIW of the current line for use by centering code. */ void record_diw_line (int plfstrt, int first, int last) { - if (last > max_diwstop) - max_diwstop = last; - if (first < min_diwstart) { - min_diwstart = first; -/* - if (plfstrt * 2 > min_diwstart) - min_diwstart = plfstrt * 2; -*/ - } + if (last > max_diwstop) + max_diwstop = last; + if (first < min_diwstart) { + min_diwstart = first; + /* + if (plfstrt * 2 > min_diwstart) + min_diwstart = plfstrt * 2; + */ + } } /* - * Screen update macros/functions - */ +* Screen update macros/functions +*/ /* The important positions in the line: where do we start drawing the left border, - where do we start drawing the playfield, where do we start drawing the right border. - All of these are forced into the visible window (VISIBLE_LEFT_BORDER .. VISIBLE_RIGHT_BORDER). - PLAYFIELD_START and PLAYFIELD_END are in window coordinates. */ +where do we start drawing the playfield, where do we start drawing the right border. +All of these are forced into the visible window (VISIBLE_LEFT_BORDER .. VISIBLE_RIGHT_BORDER). +PLAYFIELD_START and PLAYFIELD_END are in window coordinates. */ static int playfield_start, playfield_end; static int real_playfield_start, real_playfield_end; static int linetoscr_diw_start, linetoscr_diw_end; @@ -551,311 +551,311 @@ static int unpainted; static int seen_sprites; /* Initialize the variables necessary for drawing a line. - * This involves setting up start/stop positions and display window - * borders. */ +* This involves setting up start/stop positions and display window +* borders. */ static void pfield_init_linetoscr (void) { - /* First, get data fetch start/stop in DIW coordinates. */ - int ddf_left = dp_for_drawing->plfleft * 2 + DIW_DDF_OFFSET; - int ddf_right = dp_for_drawing->plfright * 2 + DIW_DDF_OFFSET; + /* First, get data fetch start/stop in DIW coordinates. */ + int ddf_left = dp_for_drawing->plfleft * 2 + DIW_DDF_OFFSET; + int ddf_right = dp_for_drawing->plfright * 2 + DIW_DDF_OFFSET; - /* Compute datafetch start/stop in pixels; native display coordinates. */ - native_ddf_left = coord_hw_to_window_x (ddf_left); - native_ddf_right = coord_hw_to_window_x (ddf_right); + /* Compute datafetch start/stop in pixels; native display coordinates. */ + native_ddf_left = coord_hw_to_window_x (ddf_left); + native_ddf_right = coord_hw_to_window_x (ddf_right); - linetoscr_diw_start = dp_for_drawing->diwfirstword; - linetoscr_diw_end = dp_for_drawing->diwlastword; + linetoscr_diw_start = dp_for_drawing->diwfirstword; + linetoscr_diw_end = dp_for_drawing->diwlastword; - res_shift = lores_shift - bplres; + res_shift = lores_shift - bplres; - if (dip_for_drawing->nr_sprites == 0) { - if (linetoscr_diw_start < native_ddf_left) - linetoscr_diw_start = native_ddf_left; - if (linetoscr_diw_end > native_ddf_right) - linetoscr_diw_end = native_ddf_right; - } - - /* Perverse cases happen. */ - if (linetoscr_diw_end < linetoscr_diw_start) - linetoscr_diw_end = linetoscr_diw_start; + if (dip_for_drawing->nr_sprites == 0) { + if (linetoscr_diw_start < native_ddf_left) + linetoscr_diw_start = native_ddf_left; + if (linetoscr_diw_end > native_ddf_right) + linetoscr_diw_end = native_ddf_right; + } - playfield_start = linetoscr_diw_start; - playfield_end = linetoscr_diw_end; + /* Perverse cases happen. */ + if (linetoscr_diw_end < linetoscr_diw_start) + linetoscr_diw_end = linetoscr_diw_start; - unpainted = visible_left_border < playfield_start ? 0 : visible_left_border - playfield_start; - ham_src_pixel = MAX_PIXELS_PER_LINE + res_shift_from_window (playfield_start - native_ddf_left); - unpainted = res_shift_from_window (unpainted); + playfield_start = linetoscr_diw_start; + playfield_end = linetoscr_diw_end; - if (playfield_start < visible_left_border) - playfield_start = visible_left_border; - if (playfield_start > visible_right_border) - playfield_start = visible_right_border; - if (playfield_end < visible_left_border) - playfield_end = visible_left_border; - if (playfield_end > visible_right_border) - playfield_end = visible_right_border; + unpainted = visible_left_border < playfield_start ? 0 : visible_left_border - playfield_start; + ham_src_pixel = MAX_PIXELS_PER_LINE + res_shift_from_window (playfield_start - native_ddf_left); + unpainted = res_shift_from_window (unpainted); - real_playfield_end = playfield_end; - real_playfield_start = playfield_start; -#ifdef AGA - if (brdsprt && dip_for_drawing->nr_sprites) { - int min = visible_right_border, max = visible_left_border, i; - for (i = 0; i < dip_for_drawing->nr_sprites; i++) { - int x; - x = curr_sprite_entries[dip_for_drawing->first_sprite_entry + i].pos; - if (x < min) - min = x; - x = curr_sprite_entries[dip_for_drawing->first_sprite_entry + i].max; - if (x > max) - max = x; - } - min = coord_hw_to_window_x (min >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); - max = coord_hw_to_window_x (max >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); - if (min < playfield_start) - playfield_start = min; if (playfield_start < visible_left_border) - playfield_start = visible_left_border; - if (max > playfield_end) - playfield_end = max; + playfield_start = visible_left_border; + if (playfield_start > visible_right_border) + playfield_start = visible_right_border; + if (playfield_end < visible_left_border) + playfield_end = visible_left_border; if (playfield_end > visible_right_border) - playfield_end = visible_right_border; - } -#endif - - if (sprite_first_x < sprite_last_x) - memset (spritepixels + sprite_first_x, 0, sizeof (struct spritepixelsbuf) * (sprite_last_x - sprite_first_x + 1)); - sprite_last_x = 0; - sprite_first_x = MAX_PIXELS_PER_LINE - 1; + playfield_end = visible_right_border; - /* Now, compute some offsets. */ - ddf_left -= DISPLAY_LEFT_SHIFT; - pixels_offset = MAX_PIXELS_PER_LINE - (ddf_left << bplres); - ddf_left <<= bplres; - src_pixel = MAX_PIXELS_PER_LINE + res_shift_from_window (playfield_start - native_ddf_left); + real_playfield_end = playfield_end; + real_playfield_start = playfield_start; +#ifdef AGA + if (brdsprt && dip_for_drawing->nr_sprites) { + int min = visible_right_border, max = visible_left_border, i; + for (i = 0; i < dip_for_drawing->nr_sprites; i++) { + int x; + x = curr_sprite_entries[dip_for_drawing->first_sprite_entry + i].pos; + if (x < min) + min = x; + x = curr_sprite_entries[dip_for_drawing->first_sprite_entry + i].max; + if (x > max) + max = x; + } + min = coord_hw_to_window_x (min >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); + max = coord_hw_to_window_x (max >> sprite_buffer_res) + (DIW_DDF_OFFSET << lores_shift); + if (min < playfield_start) + playfield_start = min; + if (playfield_start < visible_left_border) + playfield_start = visible_left_border; + if (max > playfield_end) + playfield_end = max; + if (playfield_end > visible_right_border) + playfield_end = visible_right_border; + } +#endif - seen_sprites = 0; - if (dip_for_drawing->nr_sprites == 0) - return; - seen_sprites = 1; - /* Must clear parts of apixels. */ - if (linetoscr_diw_start < native_ddf_left) { - int size = res_shift_from_window (native_ddf_left - linetoscr_diw_start); - linetoscr_diw_start = native_ddf_left; - memset (pixdata.apixels + MAX_PIXELS_PER_LINE - size, 0, size); - } - if (linetoscr_diw_end > native_ddf_right) { - int pos = res_shift_from_window (native_ddf_right - native_ddf_left); - int size = res_shift_from_window (linetoscr_diw_end - native_ddf_right); - linetoscr_diw_start = native_ddf_left; - memset (pixdata.apixels + MAX_PIXELS_PER_LINE + pos, 0, size); - } + if (sprite_first_x < sprite_last_x) + memset (spritepixels + sprite_first_x, 0, sizeof (struct spritepixelsbuf) * (sprite_last_x - sprite_first_x + 1)); + sprite_last_x = 0; + sprite_first_x = MAX_PIXELS_PER_LINE - 1; + + /* Now, compute some offsets. */ + ddf_left -= DISPLAY_LEFT_SHIFT; + pixels_offset = MAX_PIXELS_PER_LINE - (ddf_left << bplres); + ddf_left <<= bplres; + src_pixel = MAX_PIXELS_PER_LINE + res_shift_from_window (playfield_start - native_ddf_left); + + seen_sprites = 0; + if (dip_for_drawing->nr_sprites == 0) + return; + seen_sprites = 1; + /* Must clear parts of apixels. */ + if (linetoscr_diw_start < native_ddf_left) { + int size = res_shift_from_window (native_ddf_left - linetoscr_diw_start); + linetoscr_diw_start = native_ddf_left; + memset (pixdata.apixels + MAX_PIXELS_PER_LINE - size, 0, size); + } + if (linetoscr_diw_end > native_ddf_right) { + int pos = res_shift_from_window (native_ddf_right - native_ddf_left); + int size = res_shift_from_window (linetoscr_diw_end - native_ddf_right); + linetoscr_diw_start = native_ddf_left; + memset (pixdata.apixels + MAX_PIXELS_PER_LINE + pos, 0, size); + } } STATIC_INLINE uae_u8 merge_2pixel8 (uae_u8 p1, uae_u8 p2) { - return p1; + return p1; } STATIC_INLINE uae_u16 merge_2pixel16 (uae_u16 p1, uae_u16 p2) { - uae_u16 v = ((((p1 >> xredcolor_s) & xredcolor_m) + ((p2 >> xredcolor_s) & xredcolor_m)) / 2) << xredcolor_s; - v |= ((((p1 >> xbluecolor_s) & xbluecolor_m) + ((p2 >> xbluecolor_s) & xbluecolor_m)) / 2) << xbluecolor_s; - v |= ((((p1 >> xgreencolor_s) & xgreencolor_m) + ((p2 >> xgreencolor_s) & xgreencolor_m)) / 2) << xgreencolor_s; - return v; + uae_u16 v = ((((p1 >> xredcolor_s) & xredcolor_m) + ((p2 >> xredcolor_s) & xredcolor_m)) / 2) << xredcolor_s; + v |= ((((p1 >> xbluecolor_s) & xbluecolor_m) + ((p2 >> xbluecolor_s) & xbluecolor_m)) / 2) << xbluecolor_s; + v |= ((((p1 >> xgreencolor_s) & xgreencolor_m) + ((p2 >> xgreencolor_s) & xgreencolor_m)) / 2) << xgreencolor_s; + return v; } STATIC_INLINE uae_u32 merge_2pixel32 (uae_u32 p1, uae_u32 p2) { - uae_u32 v = ((((p1 >> 16) & 0xff) + ((p2 >> 16) & 0xff)) / 2) << 16; - v |= ((((p1 >> 8) & 0xff) + ((p2 >> 8) & 0xff)) / 2) << 8; - v |= ((((p1 >> 0) & 0xff) + ((p2 >> 0) & 0xff)) / 2) << 0; - return v; + uae_u32 v = ((((p1 >> 16) & 0xff) + ((p2 >> 16) & 0xff)) / 2) << 16; + v |= ((((p1 >> 8) & 0xff) + ((p2 >> 8) & 0xff)) / 2) << 8; + v |= ((((p1 >> 0) & 0xff) + ((p2 >> 0) & 0xff)) / 2) << 0; + return v; } static void fill_line_8 (uae_u8 *buf, unsigned int start, unsigned int stop) { - uae_u8 *b = (uae_u8 *)buf; - unsigned int i; - unsigned int rem = 0; - xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; - while (((long)&b[start]) & 3) { - b[start++] = (uae_u8)col; - if (start == stop) - return; - } - if (((long)&b[stop]) & 3) { - rem = ((long)&b[stop]) & 3; - stop -= rem; - } - for (i = start; i < stop; i += 4) { - uae_u32 *b2 = (uae_u32 *)&b[i]; - *b2 = col; - } - while (rem--) - b[stop++] = (uae_u8) col; + uae_u8 *b = (uae_u8 *)buf; + unsigned int i; + unsigned int rem = 0; + xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; + while (((long)&b[start]) & 3) { + b[start++] = (uae_u8)col; + if (start == stop) + return; + } + if (((long)&b[stop]) & 3) { + rem = ((long)&b[stop]) & 3; + stop -= rem; + } + for (i = start; i < stop; i += 4) { + uae_u32 *b2 = (uae_u32 *)&b[i]; + *b2 = col; + } + while (rem--) + b[stop++] = (uae_u8) col; } static void fill_line_16 (uae_u8 *buf, unsigned int start, unsigned int stop) { - uae_u16 *b = (uae_u16 *)buf; - unsigned int i; - unsigned int rem = 0; - xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; - if (((long)&b[start]) & 1) - b[start++] = (uae_u16) col; - if (start >= stop) - return; - if (((long)&b[stop]) & 1) { - rem++; - stop--; - } - for (i = start; i < stop; i += 2) { - uae_u32 *b2 = (uae_u32 *)&b[i]; - *b2 = col; - } - if (rem) - b[stop] = (uae_u16)col; + uae_u16 *b = (uae_u16 *)buf; + unsigned int i; + unsigned int rem = 0; + xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; + if (((long)&b[start]) & 1) + b[start++] = (uae_u16) col; + if (start >= stop) + return; + if (((long)&b[stop]) & 1) { + rem++; + stop--; + } + for (i = start; i < stop; i += 2) { + uae_u32 *b2 = (uae_u32 *)&b[i]; + *b2 = col; + } + if (rem) + b[stop] = (uae_u16)col; } static void fill_line_32 (uae_u8 *buf, unsigned int start, unsigned int stop) { - uae_u32 *b = (uae_u32 *)buf; - unsigned int i; - xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; - for (i = start; i < stop; i++) - b[i] = col; + uae_u32 *b = (uae_u32 *)buf; + unsigned int i; + xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0]; + for (i = start; i < stop; i++) + b[i] = col; } static void pfield_do_fill_line (int start, int stop) { - xlinecheck(start, stop); - switch (gfxvidinfo.pixbytes) { - case 1: fill_line_8 (xlinebuffer, start, stop); break; - case 2: fill_line_16 (xlinebuffer, start, stop); break; - case 4: fill_line_32 (xlinebuffer, start, stop); break; - } + xlinecheck(start, stop); + switch (gfxvidinfo.pixbytes) { + case 1: fill_line_8 (xlinebuffer, start, stop); break; + case 2: fill_line_16 (xlinebuffer, start, stop); break; + case 4: fill_line_32 (xlinebuffer, start, stop); break; + } } STATIC_INLINE void fill_line (void) { - int shift; - int nints, nrem; - int *start; - xcolnr val; - - shift = 0; - if (gfxvidinfo.pixbytes == 2) - shift = 1; - if (gfxvidinfo.pixbytes == 4) - shift = 2; - - nints = gfxvidinfo.width >> (2 - shift); - nrem = nints & 7; - nints &= ~7; - start = (int *)(((uae_u8*)xlinebuffer) + (visible_left_border << shift)); + int shift; + int nints, nrem; + int *start; + xcolnr val; + + shift = 0; + if (gfxvidinfo.pixbytes == 2) + shift = 1; + if (gfxvidinfo.pixbytes == 4) + shift = 2; + + nints = gfxvidinfo.width >> (2 - shift); + nrem = nints & 7; + nints &= ~7; + start = (int *)(((uae_u8*)xlinebuffer) + (visible_left_border << shift)); #ifdef ECS_DENISE - val = brdblank ? 0 : colors_for_drawing.acolors[0]; + val = brdblank ? 0 : colors_for_drawing.acolors[0]; #else - val = colors_for_drawing.acolors[0]; + val = colors_for_drawing.acolors[0]; #endif - for (; nints > 0; nints -= 8, start += 8) { - *start = val; - *(start+1) = val; - *(start+2) = val; - *(start+3) = val; - *(start+4) = val; - *(start+5) = val; - *(start+6) = val; - *(start+7) = val; - } - - switch (nrem) { - case 7: - *start++ = val; - case 6: - *start++ = val; - case 5: - *start++ = val; - case 4: - *start++ = val; - case 3: - *start++ = val; - case 2: - *start++ = val; - case 1: - *start = val; - } + for (; nints > 0; nints -= 8, start += 8) { + *start = val; + *(start+1) = val; + *(start+2) = val; + *(start+3) = val; + *(start+4) = val; + *(start+5) = val; + *(start+6) = val; + *(start+7) = val; + } + + switch (nrem) { + case 7: + *start++ = val; + case 6: + *start++ = val; + case 5: + *start++ = val; + case 4: + *start++ = val; + case 3: + *start++ = val; + case 2: + *start++ = val; + case 1: + *start = val; + } } #define SPRITE_DEBUG 0 STATIC_INLINE uae_u8 render_sprites (int pos, int dualpf, uae_u8 apixel, int aga) { - struct spritepixelsbuf *spb = &spritepixels[pos]; - unsigned int v = spb->data; - int *shift_lookup = dualpf ? (bpldualpfpri ? dblpf_ms2 : dblpf_ms1) : dblpf_ms; - int maskshift, plfmask; - - /* The value in the shift lookup table is _half_ the shift count we - need. This is because we can't shift 32 bits at once (undefined - behaviour in C). */ - maskshift = shift_lookup[apixel]; - plfmask = (plf_sprite_mask >> maskshift) >> maskshift; - v &= ~plfmask; - if (v != 0 || SPRITE_DEBUG) { - unsigned int vlo, vhi, col; - unsigned int v1 = v & 255; - /* OFFS determines the sprite pair with the highest priority that has - any bits set. E.g. if we have 0xFF00 in the buffer, we have sprite - pairs 01 and 23 cleared, and pairs 45 and 67 set, so OFFS will - have a value of 4. - 2 * OFFS is the bit number in V of the sprite pair, and it also - happens to be the color offset for that pair. - */ - int offs; - if (v1 == 0) - offs = 4 + sprite_offs[v >> 8]; - else - offs = sprite_offs[v1]; + struct spritepixelsbuf *spb = &spritepixels[pos]; + unsigned int v = spb->data; + int *shift_lookup = dualpf ? (bpldualpfpri ? dblpf_ms2 : dblpf_ms1) : dblpf_ms; + int maskshift, plfmask; + + /* The value in the shift lookup table is _half_ the shift count we + need. This is because we can't shift 32 bits at once (undefined + behaviour in C). */ + maskshift = shift_lookup[apixel]; + plfmask = (plf_sprite_mask >> maskshift) >> maskshift; + v &= ~plfmask; + if (v != 0 || SPRITE_DEBUG) { + unsigned int vlo, vhi, col; + unsigned int v1 = v & 255; + /* OFFS determines the sprite pair with the highest priority that has + any bits set. E.g. if we have 0xFF00 in the buffer, we have sprite + pairs 01 and 23 cleared, and pairs 45 and 67 set, so OFFS will + have a value of 4. + 2 * OFFS is the bit number in V of the sprite pair, and it also + happens to be the color offset for that pair. + */ + int offs; + if (v1 == 0) + offs = 4 + sprite_offs[v >> 8]; + else + offs = sprite_offs[v1]; - /* Shift highest priority sprite pair down to bit zero. */ - v >>= offs * 2; - v &= 15; + /* Shift highest priority sprite pair down to bit zero. */ + v >>= offs * 2; + v &= 15; #if SPRITE_DEBUG > 0 - v ^= 8; + v ^= 8; #endif - if (spb->attach && (spb->stdata & (3 << offs))) { - col = v; - if (aga) - col += sbasecol[1]; - else - col += 16; - } else { - /* This sequence computes the correct color value. We have to select - either the lower-numbered or the higher-numbered sprite in the pair. - We have to select the high one if the low one has all bits zero. - If the lower-numbered sprite has any bits nonzero, (VLO - 1) is in - the range of 0..2, and with the mask and shift, VHI will be zero. - If the lower-numbered sprite is zero, (VLO - 1) is a mask of - 0xFFFFFFFF, and we select the bits of the higher numbered sprite - in VHI. - This is _probably_ more efficient than doing it with branches. */ - vlo = v & 3; - vhi = (v & (vlo - 1)) >> 2; - col = (vlo | vhi); - if (aga) { - if (vhi > 0) - col += sbasecol[1]; - else - col += sbasecol[0]; - } else { - col += 16; - } - col += offs * 2; + if (spb->attach && (spb->stdata & (3 << offs))) { + col = v; + if (aga) + col += sbasecol[1]; + else + col += 16; + } else { + /* This sequence computes the correct color value. We have to select + either the lower-numbered or the higher-numbered sprite in the pair. + We have to select the high one if the low one has all bits zero. + If the lower-numbered sprite has any bits nonzero, (VLO - 1) is in + the range of 0..2, and with the mask and shift, VHI will be zero. + If the lower-numbered sprite is zero, (VLO - 1) is a mask of + 0xFFFFFFFF, and we select the bits of the higher numbered sprite + in VHI. + This is _probably_ more efficient than doing it with branches. */ + vlo = v & 3; + vhi = (v & (vlo - 1)) >> 2; + col = (vlo | vhi); + if (aga) { + if (vhi > 0) + col += sbasecol[1]; + else + col += sbasecol[0]; + } else { + col += 16; + } + col += offs * 2; + } + + return col; } - - return col; - } - return 0; + return 0; } #include "linetoscr.c" @@ -865,440 +865,440 @@ STATIC_INLINE uae_u8 render_sprites (int pos, int dualpf, uae_u8 apixel, int aga STATIC_INLINE uae_u32 shsprite (int dpix, uae_u32 spix_val, uae_u32 v, int spr) { - uae_u8 sprcol; - if (!spr) + uae_u8 sprcol; + if (!spr) + return v; + sprcol = render_sprites (dpix, 0, spix_val, 0); + if (sprcol) + return colors_for_drawing.color_regs_ecs[sprcol]; return v; - sprcol = render_sprites (dpix, 0, spix_val, 0); - if (sprcol) - return colors_for_drawing.color_regs_ecs[sprcol]; - return v; } static int NOINLINE linetoscr_16_sh (int spix, int dpix, int stoppos, int spr) { - uae_u16 *buf = (uae_u16 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u16 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - dpix++; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val2, xcolors[v], spr); - dpix++; - } - return spix; + uae_u16 *buf = (uae_u16 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u16 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + dpix++; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val2, xcolors[v], spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_32_sh (int spix, int dpix, int stoppos, int spr) { - uae_u32 *buf = (uae_u32 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u32 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - dpix++; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val2, xcolors[v], spr); - dpix++; - } - return spix; + uae_u32 *buf = (uae_u32 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u32 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + dpix++; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val2, xcolors[v], spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_32_shrink1_sh (int spix, int dpix, int stoppos, int spr) { - uae_u32 *buf = (uae_u32 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u32 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - dpix++; - } - return spix; + uae_u32 *buf = (uae_u32 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u32 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_32_shrink1f_sh (int spix, int dpix, int stoppos, int spr) { - uae_u32 *buf = (uae_u32 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u32 spix_val1, spix_val2, dpix_val1, dpix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel32 (dpix_val1, dpix_val2), spr); - dpix++; - } - return spix; + uae_u32 *buf = (uae_u32 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u32 spix_val1, spix_val2, dpix_val1, dpix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel32 (dpix_val1, dpix_val2), spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_16_shrink1_sh (int spix, int dpix, int stoppos, int spr) { - uae_u16 *buf = (uae_u16 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u16 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - dpix++; - } - return spix; + uae_u16 *buf = (uae_u16 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u16 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_16_shrink1f_sh (int spix, int dpix, int stoppos, int spr) { - uae_u16 *buf = (uae_u16 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u16 spix_val1, spix_val2, dpix_val1, dpix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel16 (dpix_val1, dpix_val2), spr); - dpix++; - } - return spix; + uae_u16 *buf = (uae_u16 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u16 spix_val1, spix_val2, dpix_val1, dpix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel16 (dpix_val1, dpix_val2), spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_32_shrink2_sh (int spix, int dpix, int stoppos, int spr) { - uae_u32 *buf = (uae_u32 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u32 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - spix+=2; - dpix++; - } - return spix; + uae_u32 *buf = (uae_u32 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u32 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + spix+=2; + dpix++; + } + return spix; } static int NOINLINE linetoscr_32_shrink2f_sh (int spix, int dpix, int stoppos, int spr) { - uae_u32 *buf = (uae_u32 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u32 spix_val1, spix_val2, dpix_val1, dpix_val2, dpix_val3, dpix_val4; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - dpix_val3 = merge_2pixel32 (dpix_val1, dpix_val2); - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - dpix_val4 = merge_2pixel32 (dpix_val1, dpix_val2); - buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel32 (dpix_val3, dpix_val4), spr); - dpix++; - } - return spix; + uae_u32 *buf = (uae_u32 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u32 spix_val1, spix_val2, dpix_val1, dpix_val2, dpix_val3, dpix_val4; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + dpix_val3 = merge_2pixel32 (dpix_val1, dpix_val2); + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + dpix_val4 = merge_2pixel32 (dpix_val1, dpix_val2); + buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel32 (dpix_val3, dpix_val4), spr); + dpix++; + } + return spix; } static int NOINLINE linetoscr_16_shrink2_sh (int spix, int dpix, int stoppos, int spr) { - uae_u16 *buf = (uae_u16 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u16 spix_val1, spix_val2; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); - spix+=2; - dpix++; - } - return spix; + uae_u16 *buf = (uae_u16 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u16 spix_val1, spix_val2; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + buf[dpix] = shsprite (dpix, spix_val1, xcolors[v], spr); + spix+=2; + dpix++; + } + return spix; } static int NOINLINE linetoscr_16_shrink2f_sh (int spix, int dpix, int stoppos, int spr) { - uae_u16 *buf = (uae_u16 *) xlinebuffer; - - while (dpix < stoppos) { - uae_u16 spix_val1, spix_val2, dpix_val1, dpix_val2, dpix_val3, dpix_val4; - uae_u16 v; - int off; - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - dpix_val3 = merge_2pixel32 (dpix_val1, dpix_val2); - spix_val1 = pixdata.apixels[spix++]; - spix_val2 = pixdata.apixels[spix++]; - off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); - v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; - v |= v >> 2; - dpix_val1 = xcolors[v]; - v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; - v |= v >> 2; - dpix_val2 = xcolors[v]; - dpix_val4 = merge_2pixel32 (dpix_val1, dpix_val2); - buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel16 (dpix_val3, dpix_val4), spr); - dpix++; - } - return spix; + uae_u16 *buf = (uae_u16 *) xlinebuffer; + + while (dpix < stoppos) { + uae_u16 spix_val1, spix_val2, dpix_val1, dpix_val2, dpix_val3, dpix_val4; + uae_u16 v; + int off; + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + dpix_val3 = merge_2pixel32 (dpix_val1, dpix_val2); + spix_val1 = pixdata.apixels[spix++]; + spix_val2 = pixdata.apixels[spix++]; + off = ((spix_val2 & 3) * 4) + (spix_val1 & 3) + ((spix_val1 | spix_val2) & 16); + v = (colors_for_drawing.color_regs_ecs[off] & 0xccc) << 0; + v |= v >> 2; + dpix_val1 = xcolors[v]; + v = (colors_for_drawing.color_regs_ecs[off] & 0x333) << 2; + v |= v >> 2; + dpix_val2 = xcolors[v]; + dpix_val4 = merge_2pixel32 (dpix_val1, dpix_val2); + buf[dpix] = shsprite (dpix, spix_val1, merge_2pixel16 (dpix_val3, dpix_val4), spr); + dpix++; + } + return spix; } #endif static void pfield_do_linetoscr (int start, int stop) { - xlinecheck(start, stop); - if (issprites && (currprefs.chipset_mask & CSMASK_AGA)) { - if (res_shift == 0) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_aga_spr (src_pixel, start, stop); break; - } - } else if (res_shift == 2) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_stretch2_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch2_aga_spr (src_pixel, start, stop); break; - } - } else if (res_shift == 1) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_stretch1_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch1_aga_spr (src_pixel, start, stop); break; - } - } else if (res_shift == -1) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1f_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1f_aga_spr (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1_aga_spr (src_pixel, start, stop); break; - } - } - } else if (res_shift == -2) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2f_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink2f_aga_spr (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2_aga_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink2_aga_spr (src_pixel, start, stop); break; + xlinecheck(start, stop); + if (issprites && (currprefs.chipset_mask & CSMASK_AGA)) { + if (res_shift == 0) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_aga_spr (src_pixel, start, stop); break; + } + } else if (res_shift == 2) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_stretch2_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch2_aga_spr (src_pixel, start, stop); break; + } + } else if (res_shift == 1) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_stretch1_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch1_aga_spr (src_pixel, start, stop); break; + } + } else if (res_shift == -1) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1f_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1f_aga_spr (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1_aga_spr (src_pixel, start, stop); break; + } + } + } else if (res_shift == -2) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2f_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink2f_aga_spr (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2_aga_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink2_aga_spr (src_pixel, start, stop); break; + } + } } - } - } - } else + } else #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) { - if (res_shift == 0) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_aga (src_pixel, start, stop); break; - } - } else if (res_shift == 2) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_stretch2_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch2_aga (src_pixel, start, stop); break; - } - } else if (res_shift == 1) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_stretch1_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch1_aga (src_pixel, start, stop); break; - } - } else if (res_shift == -1) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1f_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1f_aga (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1_aga (src_pixel, start, stop); break; - } - } - } else if (res_shift == -2) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2f_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink2f_aga (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2_aga (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink2_aga (src_pixel, start, stop); break; - } - } - } - } else + if (currprefs.chipset_mask & CSMASK_AGA) { + if (res_shift == 0) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_aga (src_pixel, start, stop); break; + } + } else if (res_shift == 2) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_stretch2_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch2_aga (src_pixel, start, stop); break; + } + } else if (res_shift == 1) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_stretch1_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch1_aga (src_pixel, start, stop); break; + } + } else if (res_shift == -1) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1f_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1f_aga (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1_aga (src_pixel, start, stop); break; + } + } + } else if (res_shift == -2) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2f_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink2f_aga (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2_aga (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink2_aga (src_pixel, start, stop); break; + } + } + } + } else #endif #ifdef ECS_DENISE - if (ecsshres) { - if (res_shift == 0) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_sh (src_pixel, start, stop, issprites); break; - case 4: src_pixel = linetoscr_32_sh (src_pixel, start, stop, issprites); break; - } - } else if (res_shift == -1) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1f_sh (src_pixel, start, stop, issprites); break; - case 4: src_pixel = linetoscr_32_shrink1f_sh (src_pixel, start, stop, issprites); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink1_sh (src_pixel, start, stop, issprites); break; - case 4: src_pixel = linetoscr_32_shrink1_sh (src_pixel, start, stop, issprites); break; - } - } - } else if (res_shift == -2) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2f_sh (src_pixel, start, stop, issprites); break; - case 4: src_pixel = linetoscr_32_shrink2f_sh (src_pixel, start, stop, issprites); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 2: src_pixel = linetoscr_16_shrink2_sh (src_pixel, start, stop, issprites); break; - case 4: src_pixel = linetoscr_32_shrink2_sh (src_pixel, start, stop, issprites); break; - } - } - } - } else + if (ecsshres) { + if (res_shift == 0) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_sh (src_pixel, start, stop, issprites); break; + case 4: src_pixel = linetoscr_32_sh (src_pixel, start, stop, issprites); break; + } + } else if (res_shift == -1) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1f_sh (src_pixel, start, stop, issprites); break; + case 4: src_pixel = linetoscr_32_shrink1f_sh (src_pixel, start, stop, issprites); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink1_sh (src_pixel, start, stop, issprites); break; + case 4: src_pixel = linetoscr_32_shrink1_sh (src_pixel, start, stop, issprites); break; + } + } + } else if (res_shift == -2) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2f_sh (src_pixel, start, stop, issprites); break; + case 4: src_pixel = linetoscr_32_shrink2f_sh (src_pixel, start, stop, issprites); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 2: src_pixel = linetoscr_16_shrink2_sh (src_pixel, start, stop, issprites); break; + case 4: src_pixel = linetoscr_32_shrink2_sh (src_pixel, start, stop, issprites); break; + } + } + } + } else #endif - if (issprites) { - if (res_shift == 0) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_spr (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_spr (src_pixel, start, stop); break; - } - } else if (res_shift == 2) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_stretch2_spr (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_stretch2_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch2_spr (src_pixel, start, stop); break; - } - } else if (res_shift == 1) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_stretch1_spr (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_stretch1_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch1_spr (src_pixel, start, stop); break; - } - } else if (res_shift == -1) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_shrink1f_spr (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_shrink1f_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1f_spr (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_shrink1_spr (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_shrink1_spr (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1_spr (src_pixel, start, stop); break; - } - } - } - } else { - if (res_shift == 0) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8 (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16 (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32 (src_pixel, start, stop); break; - } - } else if (res_shift == 2) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_stretch2 (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_stretch2 (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch2 (src_pixel, start, stop); break; - } - } else if (res_shift == 1) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_stretch1 (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_stretch1 (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_stretch1 (src_pixel, start, stop); break; - } - } else if (res_shift == -1) { - if (currprefs.gfx_lores_mode) { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_shrink1f (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_shrink1f (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1f (src_pixel, start, stop); break; - } - } else { - switch (gfxvidinfo.pixbytes) { - case 1: src_pixel = linetoscr_8_shrink1 (src_pixel, start, stop); break; - case 2: src_pixel = linetoscr_16_shrink1 (src_pixel, start, stop); break; - case 4: src_pixel = linetoscr_32_shrink1 (src_pixel, start, stop); break; - } - } - } - } + if (issprites) { + if (res_shift == 0) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_spr (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_spr (src_pixel, start, stop); break; + } + } else if (res_shift == 2) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_stretch2_spr (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_stretch2_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch2_spr (src_pixel, start, stop); break; + } + } else if (res_shift == 1) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_stretch1_spr (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_stretch1_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch1_spr (src_pixel, start, stop); break; + } + } else if (res_shift == -1) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_shrink1f_spr (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_shrink1f_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1f_spr (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_shrink1_spr (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_shrink1_spr (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1_spr (src_pixel, start, stop); break; + } + } + } + } else { + if (res_shift == 0) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8 (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16 (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32 (src_pixel, start, stop); break; + } + } else if (res_shift == 2) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_stretch2 (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_stretch2 (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch2 (src_pixel, start, stop); break; + } + } else if (res_shift == 1) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_stretch1 (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_stretch1 (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_stretch1 (src_pixel, start, stop); break; + } + } else if (res_shift == -1) { + if (currprefs.gfx_lores_mode) { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_shrink1f (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_shrink1f (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1f (src_pixel, start, stop); break; + } + } else { + switch (gfxvidinfo.pixbytes) { + case 1: src_pixel = linetoscr_8_shrink1 (src_pixel, start, stop); break; + case 2: src_pixel = linetoscr_16_shrink1 (src_pixel, start, stop); break; + case 4: src_pixel = linetoscr_32_shrink1 (src_pixel, start, stop); break; + } + } + } + } } @@ -1310,201 +1310,201 @@ static int ham_decode_pixel; static unsigned int ham_lastcolor; /* Decode HAM in the invisible portion of the display (left of VISIBLE_LEFT_BORDER), - but don't draw anything in. This is done to prepare HAM_LASTCOLOR for later, - when decode_ham runs. */ +but don't draw anything in. This is done to prepare HAM_LASTCOLOR for later, +when decode_ham runs. */ static void init_ham_decoding (void) { - int unpainted_amiga = unpainted; + int unpainted_amiga = unpainted; - ham_decode_pixel = ham_src_pixel; - ham_lastcolor = color_reg_get (&colors_for_drawing, 0); + ham_decode_pixel = ham_src_pixel; + ham_lastcolor = color_reg_get (&colors_for_drawing, 0); - if (!bplham) { - if (unpainted_amiga > 0) { - int pv = pixdata.apixels[ham_decode_pixel + unpainted_amiga - 1]; + if (!bplham) { + if (unpainted_amiga > 0) { + int pv = pixdata.apixels[ham_decode_pixel + unpainted_amiga - 1]; #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) - ham_lastcolor = colors_for_drawing.color_regs_aga[pv ^ bplxor]; - else + if (currprefs.chipset_mask & CSMASK_AGA) + ham_lastcolor = colors_for_drawing.color_regs_aga[pv ^ bplxor]; + else #endif - ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; - } -#ifdef AGA - } else if (currprefs.chipset_mask & CSMASK_AGA) { - if (bplplanecnt >= 7) { /* AGA mode HAM8 */ - while (unpainted_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel++] ^ bplxor; - switch (pv & 0x3) - { - case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break; - case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break; - case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break; - case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break; + ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; } - } - } else { /* AGA mode HAM6 */ - while (unpainted_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel++] ^ bplxor; - switch (pv & 0x30) - { - case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break; - case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break; - case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break; - case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break; +#ifdef AGA + } else if (currprefs.chipset_mask & CSMASK_AGA) { + if (bplplanecnt >= 7) { /* AGA mode HAM8 */ + while (unpainted_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel++] ^ bplxor; + switch (pv & 0x3) + { + case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break; + case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break; + case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break; + case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break; + } + } + } else { /* AGA mode HAM6 */ + while (unpainted_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel++] ^ bplxor; + switch (pv & 0x30) + { + case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break; + case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break; + case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break; + case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break; + } + } } - } - } #endif - } else { - /* OCS/ECS mode HAM6 */ - while (unpainted_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel++]; - switch (pv & 0x30) - { - case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break; - case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break; - case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break; - case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break; - } + } else { + /* OCS/ECS mode HAM6 */ + while (unpainted_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel++]; + switch (pv & 0x30) + { + case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break; + case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break; + case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break; + case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break; + } + } } - } } static void decode_ham (int pix, int stoppos) { - int todraw_amiga = res_shift_from_window (stoppos - pix); + int todraw_amiga = res_shift_from_window (stoppos - pix); - if (!bplham) { - while (todraw_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel]; + if (!bplham) { + while (todraw_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel]; #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) - ham_lastcolor = colors_for_drawing.color_regs_aga[pv ^ bplxor]; - else + if (currprefs.chipset_mask & CSMASK_AGA) + ham_lastcolor = colors_for_drawing.color_regs_aga[pv ^ bplxor]; + else #endif - ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; + ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; - ham_linebuf[ham_decode_pixel++] = ham_lastcolor; - } + ham_linebuf[ham_decode_pixel++] = ham_lastcolor; + } #ifdef AGA - } else if (currprefs.chipset_mask & CSMASK_AGA) { - if (bplplanecnt >= 7) { /* AGA mode HAM8 */ - while (todraw_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel] ^ bplxor; - switch (pv & 0x3) - { - case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break; - case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break; - case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break; - case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break; + } else if (currprefs.chipset_mask & CSMASK_AGA) { + if (bplplanecnt >= 7) { /* AGA mode HAM8 */ + while (todraw_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel] ^ bplxor; + switch (pv & 0x3) + { + case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break; + case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break; + case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break; + case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break; + } + ham_linebuf[ham_decode_pixel++] = ham_lastcolor; + } + } else { /* AGA mode HAM6 */ + while (todraw_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel] ^ bplxor; + switch (pv & 0x30) + { + case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break; + case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break; + case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break; + case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break; + } + ham_linebuf[ham_decode_pixel++] = ham_lastcolor; + } } - ham_linebuf[ham_decode_pixel++] = ham_lastcolor; - } - } else { /* AGA mode HAM6 */ - while (todraw_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel] ^ bplxor; - switch (pv & 0x30) - { - case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break; - case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break; - case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break; - case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break; +#endif + } else { + /* OCS/ECS mode HAM6 */ + while (todraw_amiga-- > 0) { + int pv = pixdata.apixels[ham_decode_pixel]; + switch (pv & 0x30) + { + case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break; + case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break; + case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break; + case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break; + } + ham_linebuf[ham_decode_pixel++] = ham_lastcolor; } - ham_linebuf[ham_decode_pixel++] = ham_lastcolor; - } } -#endif - } else { - /* OCS/ECS mode HAM6 */ - while (todraw_amiga-- > 0) { - int pv = pixdata.apixels[ham_decode_pixel]; - switch (pv & 0x30) - { - case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break; - case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break; - case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break; - case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break; - } - ham_linebuf[ham_decode_pixel++] = ham_lastcolor; - } - } } static void gen_pfield_tables (void) { - int i; + int i; - /* For now, the AGA stuff is broken in the dual playfield case. We encode - * sprites in dpf mode by ORing the pixel value with 0x80. To make dual - * playfield rendering easy, the lookup tables contain are made linear for - * values >= 128. That only works for OCS/ECS, though. */ + /* For now, the AGA stuff is broken in the dual playfield case. We encode + * sprites in dpf mode by ORing the pixel value with 0x80. To make dual + * playfield rendering easy, the lookup tables contain are made linear for + * values >= 128. That only works for OCS/ECS, though. */ - for (i = 0; i < 256; i++) { - int plane1 = (i & 1) | ((i >> 1) & 2) | ((i >> 2) & 4) | ((i >> 3) & 8); - int plane2 = ((i >> 1) & 1) | ((i >> 2) & 2) | ((i >> 3) & 4) | ((i >> 4) & 8); + for (i = 0; i < 256; i++) { + int plane1 = (i & 1) | ((i >> 1) & 2) | ((i >> 2) & 4) | ((i >> 3) & 8); + int plane2 = ((i >> 1) & 1) | ((i >> 2) & 2) | ((i >> 3) & 4) | ((i >> 4) & 8); - dblpf_2nd1[i] = plane1 == 0 ? (plane2 == 0 ? 0 : 2) : 1; - dblpf_2nd2[i] = plane2 == 0 ? (plane1 == 0 ? 0 : 1) : 2; + dblpf_2nd1[i] = plane1 == 0 ? (plane2 == 0 ? 0 : 2) : 1; + dblpf_2nd2[i] = plane2 == 0 ? (plane1 == 0 ? 0 : 1) : 2; #ifdef AGA - dblpf_ind1_aga[i] = plane1 == 0 ? plane2 : plane1; - dblpf_ind2_aga[i] = plane2 == 0 ? plane1 : plane2; + dblpf_ind1_aga[i] = plane1 == 0 ? plane2 : plane1; + dblpf_ind2_aga[i] = plane2 == 0 ? plane1 : plane2; #endif - dblpf_ms1[i] = plane1 == 0 ? (plane2 == 0 ? 16 : 8) : 0; - dblpf_ms2[i] = plane2 == 0 ? (plane1 == 0 ? 16 : 0) : 8; - dblpf_ms[i] = i == 0 ? 16 : 8; - if (plane2 > 0) - plane2 += 8; - dblpf_ind1[i] = i >= 128 ? i & 0x7F : (plane1 == 0 ? plane2 : plane1); - dblpf_ind2[i] = i >= 128 ? i & 0x7F : (plane2 == 0 ? plane1 : plane2); + dblpf_ms1[i] = plane1 == 0 ? (plane2 == 0 ? 16 : 8) : 0; + dblpf_ms2[i] = plane2 == 0 ? (plane1 == 0 ? 16 : 0) : 8; + dblpf_ms[i] = i == 0 ? 16 : 8; + if (plane2 > 0) + plane2 += 8; + dblpf_ind1[i] = i >= 128 ? i & 0x7F : (plane1 == 0 ? plane2 : plane1); + dblpf_ind2[i] = i >= 128 ? i & 0x7F : (plane2 == 0 ? plane1 : plane2); - sprite_offs[i] = (i & 15) ? 0 : 2; + sprite_offs[i] = (i & 15) ? 0 : 2; - clxtab[i] = ((((i & 3) && (i & 12)) << 9) - | (((i & 3) && (i & 48)) << 10) - | (((i & 3) && (i & 192)) << 11) - | (((i & 12) && (i & 48)) << 12) - | (((i & 12) && (i & 192)) << 13) - | (((i & 48) && (i & 192)) << 14)); + clxtab[i] = ((((i & 3) && (i & 12)) << 9) + | (((i & 3) && (i & 48)) << 10) + | (((i & 3) && (i & 192)) << 11) + | (((i & 12) && (i & 48)) << 12) + | (((i & 12) && (i & 192)) << 13) + | (((i & 48) && (i & 192)) << 14)); - } + } - memset (all_ones, 0xff, MAX_PIXELS_PER_LINE); + memset (all_ones, 0xff, MAX_PIXELS_PER_LINE); } /* When looking at this function and the ones that inline it, bear in mind - what an optimizing compiler will do with this code. All callers of this - function only pass in constant arguments (except for E). This means - that many of the if statements will go away completely after inlining. */ +what an optimizing compiler will do with this code. All callers of this +function only pass in constant arguments (except for E). This means +that many of the if statements will go away completely after inlining. */ STATIC_INLINE void draw_sprites_1 (struct sprite_entry *e, int dualpf, int has_attach) { - uae_u16 *buf = spixels + e->first_pixel; - uae_u8 *stbuf = spixstate.bytes + e->first_pixel; - int spr_pos, pos; + uae_u16 *buf = spixels + e->first_pixel; + uae_u8 *stbuf = spixstate.bytes + e->first_pixel; + int spr_pos, pos; - buf -= e->pos; - stbuf -= e->pos; + buf -= e->pos; + stbuf -= e->pos; - spr_pos = e->pos + ((DIW_DDF_OFFSET - DISPLAY_LEFT_SHIFT) << sprite_buffer_res); + spr_pos = e->pos + ((DIW_DDF_OFFSET - DISPLAY_LEFT_SHIFT) << sprite_buffer_res); - if (spr_pos < sprite_first_x) - sprite_first_x = spr_pos; + if (spr_pos < sprite_first_x) + sprite_first_x = spr_pos; - for (pos = e->pos; pos < e->max; pos++) { - spritepixels[spr_pos].data = buf[pos]; - spritepixels[spr_pos].stdata = stbuf[pos]; - spritepixels[spr_pos].attach = has_attach; - spr_pos++; - } + for (pos = e->pos; pos < e->max; pos++) { + spritepixels[spr_pos].data = buf[pos]; + spritepixels[spr_pos].stdata = stbuf[pos]; + spritepixels[spr_pos].attach = has_attach; + spr_pos++; + } - if (spr_pos > sprite_last_x) - sprite_last_x = spr_pos; + if (spr_pos > sprite_last_x) + sprite_last_x = spr_pos; } /* See comments above. Do not touch if you don't know what's going on. - * (We do _not_ want the following to be inlined themselves). */ +* (We do _not_ want the following to be inlined themselves). */ /* lores bitplane, lores sprites */ static void NOINLINE draw_sprites_normal_sp_nat (struct sprite_entry *e) { draw_sprites_1 (e, 0, 0); } static void NOINLINE draw_sprites_normal_dp_nat (struct sprite_entry *e) { draw_sprites_1 (e, 1, 0); } @@ -1515,128 +1515,128 @@ static void NOINLINE draw_sprites_normal_dp_at (struct sprite_entry *e) { draw_s /* not very optimized */ STATIC_INLINE void draw_sprites_aga (struct sprite_entry *e, int aga) { - draw_sprites_1 (e, bpldualpf, e->has_attached); + draw_sprites_1 (e, bpldualpf, e->has_attached); } #endif STATIC_INLINE void draw_sprites_ecs (struct sprite_entry *e) { - if (e->has_attached) { - if (bpldualpf) - draw_sprites_normal_dp_at (e); - else - draw_sprites_normal_sp_at (e); - } else { - if (bpldualpf) - draw_sprites_normal_dp_nat (e); - else - draw_sprites_normal_sp_nat (e); - } + if (e->has_attached) { + if (bpldualpf) + draw_sprites_normal_dp_at (e); + else + draw_sprites_normal_sp_at (e); + } else { + if (bpldualpf) + draw_sprites_normal_dp_nat (e); + else + draw_sprites_normal_sp_nat (e); + } } #ifdef AGA /* clear possible bitplane data outside DIW area */ static void clear_bitplane_border_aga (void) { - int len, shift = res_shift; - uae_u8 v = 0; - - if (shift < 0) { - shift = -shift; - len = (real_playfield_start - playfield_start) << shift; - memset (pixdata.apixels + pixels_offset + (playfield_start << shift), v, len); - len = (playfield_end - real_playfield_end) << shift; - memset (pixdata.apixels + pixels_offset + (real_playfield_end << shift), v, len); - } else { - len = (real_playfield_start - playfield_start) >> shift; - memset (pixdata.apixels + pixels_offset + (playfield_start >> shift), v, len); - len = (playfield_end - real_playfield_end) >> shift; - memset (pixdata.apixels + pixels_offset + (real_playfield_end >> shift), v, len); - } + int len, shift = res_shift; + uae_u8 v = 0; + + if (shift < 0) { + shift = -shift; + len = (real_playfield_start - playfield_start) << shift; + memset (pixdata.apixels + pixels_offset + (playfield_start << shift), v, len); + len = (playfield_end - real_playfield_end) << shift; + memset (pixdata.apixels + pixels_offset + (real_playfield_end << shift), v, len); + } else { + len = (real_playfield_start - playfield_start) >> shift; + memset (pixdata.apixels + pixels_offset + (playfield_start >> shift), v, len); + len = (playfield_end - real_playfield_end) >> shift; + memset (pixdata.apixels + pixels_offset + (real_playfield_end >> shift), v, len); + } } #endif /* emulate OCS/ECS only undocumented "SWIV" hardware feature */ static void weird_bitplane_fix (void) { - int i; - int sh = lores_shift; - uae_u8 *p = pixdata.apixels + pixels_offset; + int i; + int sh = lores_shift; + uae_u8 *p = pixdata.apixels + pixels_offset; - for (i = playfield_start >> sh; i < playfield_end >> sh; i++) { - if (p[i] > 16) - p[i] = 16; - } + for (i = playfield_start >> sh; i < playfield_end >> sh; i++) { + if (p[i] > 16) + p[i] = 16; + } } #define MERGE(a,b,mask,shift) do {\ - uae_u32 tmp = mask & (a ^ (b >> shift)); \ - a ^= tmp; \ - b ^= (tmp << shift); \ + uae_u32 tmp = mask & (a ^ (b >> shift)); \ + a ^= tmp; \ + b ^= (tmp << shift); \ } while (0) #define GETLONG(P) (*(uae_u32 *)P) /* We use the compiler's inlining ability to ensure that PLANES is in effect a compile time - constant. That will cause some unnecessary code to be optimized away. - Don't touch this if you don't know what you are doing. */ +constant. That will cause some unnecessary code to be optimized away. +Don't touch this if you don't know what you are doing. */ STATIC_INLINE void pfield_doline_1 (uae_u32 *pixels, int wordcount, int planes) { - while (wordcount-- > 0) { - uae_u32 b0, b1, b2, b3, b4, b5, b6, b7; + while (wordcount-- > 0) { + uae_u32 b0, b1, b2, b3, b4, b5, b6, b7; - b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0, b7 = 0; - switch (planes) { + b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0, b7 = 0; + switch (planes) { #ifdef AGA - case 8: b0 = GETLONG (real_bplpt[7]); real_bplpt[7] += 4; - case 7: b1 = GETLONG (real_bplpt[6]); real_bplpt[6] += 4; + case 8: b0 = GETLONG (real_bplpt[7]); real_bplpt[7] += 4; + case 7: b1 = GETLONG (real_bplpt[6]); real_bplpt[6] += 4; #endif - case 6: b2 = GETLONG (real_bplpt[5]); real_bplpt[5] += 4; - case 5: b3 = GETLONG (real_bplpt[4]); real_bplpt[4] += 4; - case 4: b4 = GETLONG (real_bplpt[3]); real_bplpt[3] += 4; - case 3: b5 = GETLONG (real_bplpt[2]); real_bplpt[2] += 4; - case 2: b6 = GETLONG (real_bplpt[1]); real_bplpt[1] += 4; - case 1: b7 = GETLONG (real_bplpt[0]); real_bplpt[0] += 4; - } - - MERGE (b0, b1, 0x55555555, 1); - MERGE (b2, b3, 0x55555555, 1); - MERGE (b4, b5, 0x55555555, 1); - MERGE (b6, b7, 0x55555555, 1); - - MERGE (b0, b2, 0x33333333, 2); - MERGE (b1, b3, 0x33333333, 2); - MERGE (b4, b6, 0x33333333, 2); - MERGE (b5, b7, 0x33333333, 2); - - MERGE (b0, b4, 0x0f0f0f0f, 4); - MERGE (b1, b5, 0x0f0f0f0f, 4); - MERGE (b2, b6, 0x0f0f0f0f, 4); - MERGE (b3, b7, 0x0f0f0f0f, 4); - - MERGE (b0, b1, 0x00ff00ff, 8); - MERGE (b2, b3, 0x00ff00ff, 8); - MERGE (b4, b5, 0x00ff00ff, 8); - MERGE (b6, b7, 0x00ff00ff, 8); - - MERGE (b0, b2, 0x0000ffff, 16); - do_put_mem_long (pixels, b0); - do_put_mem_long (pixels + 4, b2); - MERGE (b1, b3, 0x0000ffff, 16); - do_put_mem_long (pixels + 2, b1); - do_put_mem_long (pixels + 6, b3); - MERGE (b4, b6, 0x0000ffff, 16); - do_put_mem_long (pixels + 1, b4); - do_put_mem_long (pixels + 5, b6); - MERGE (b5, b7, 0x0000ffff, 16); - do_put_mem_long (pixels + 3, b5); - do_put_mem_long (pixels + 7, b7); - pixels += 8; - } + case 6: b2 = GETLONG (real_bplpt[5]); real_bplpt[5] += 4; + case 5: b3 = GETLONG (real_bplpt[4]); real_bplpt[4] += 4; + case 4: b4 = GETLONG (real_bplpt[3]); real_bplpt[3] += 4; + case 3: b5 = GETLONG (real_bplpt[2]); real_bplpt[2] += 4; + case 2: b6 = GETLONG (real_bplpt[1]); real_bplpt[1] += 4; + case 1: b7 = GETLONG (real_bplpt[0]); real_bplpt[0] += 4; + } + + MERGE (b0, b1, 0x55555555, 1); + MERGE (b2, b3, 0x55555555, 1); + MERGE (b4, b5, 0x55555555, 1); + MERGE (b6, b7, 0x55555555, 1); + + MERGE (b0, b2, 0x33333333, 2); + MERGE (b1, b3, 0x33333333, 2); + MERGE (b4, b6, 0x33333333, 2); + MERGE (b5, b7, 0x33333333, 2); + + MERGE (b0, b4, 0x0f0f0f0f, 4); + MERGE (b1, b5, 0x0f0f0f0f, 4); + MERGE (b2, b6, 0x0f0f0f0f, 4); + MERGE (b3, b7, 0x0f0f0f0f, 4); + + MERGE (b0, b1, 0x00ff00ff, 8); + MERGE (b2, b3, 0x00ff00ff, 8); + MERGE (b4, b5, 0x00ff00ff, 8); + MERGE (b6, b7, 0x00ff00ff, 8); + + MERGE (b0, b2, 0x0000ffff, 16); + do_put_mem_long (pixels, b0); + do_put_mem_long (pixels + 4, b2); + MERGE (b1, b3, 0x0000ffff, 16); + do_put_mem_long (pixels + 2, b1); + do_put_mem_long (pixels + 6, b3); + MERGE (b4, b6, 0x0000ffff, 16); + do_put_mem_long (pixels + 1, b4); + do_put_mem_long (pixels + 5, b6); + MERGE (b5, b7, 0x0000ffff, 16); + do_put_mem_long (pixels + 3, b5); + do_put_mem_long (pixels + 7, b7); + pixels += 8; + } } /* See above for comments on inlining. These functions should _not_ - be inlined themselves. */ +be inlined themselves. */ static void NOINLINE pfield_doline_n1 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 1); } static void NOINLINE pfield_doline_n2 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 2); } static void NOINLINE pfield_doline_n3 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 3); } @@ -1650,1296 +1650,1310 @@ static void NOINLINE pfield_doline_n8 (uae_u32 *data, int count) { pfield_doline static void pfield_doline (int lineno) { - int wordcount = dp_for_drawing->plflinelen; - uae_u32 *data = pixdata.apixels_l + MAX_PIXELS_PER_LINE / 4; + int wordcount = dp_for_drawing->plflinelen; + uae_u32 *data = pixdata.apixels_l + MAX_PIXELS_PER_LINE / 4; #ifdef SMART_UPDATE #define DATA_POINTER(n) ((debug_bpl_mask & (1 << n)) ? (line_data[lineno] + (n) * MAX_WORDS_PER_LINE * 2) : (debug_bpl_mask_one ? all_ones : all_zeros)) - real_bplpt[0] = DATA_POINTER (0); - real_bplpt[1] = DATA_POINTER (1); - real_bplpt[2] = DATA_POINTER (2); - real_bplpt[3] = DATA_POINTER (3); - real_bplpt[4] = DATA_POINTER (4); - real_bplpt[5] = DATA_POINTER (5); + real_bplpt[0] = DATA_POINTER (0); + real_bplpt[1] = DATA_POINTER (1); + real_bplpt[2] = DATA_POINTER (2); + real_bplpt[3] = DATA_POINTER (3); + real_bplpt[4] = DATA_POINTER (4); + real_bplpt[5] = DATA_POINTER (5); #ifdef AGA - real_bplpt[6] = DATA_POINTER (6); - real_bplpt[7] = DATA_POINTER (7); + real_bplpt[6] = DATA_POINTER (6); + real_bplpt[7] = DATA_POINTER (7); #endif #endif - switch (bplplanecnt) { - default: break; - case 0: memset (data, 0, wordcount * 32); break; - case 1: pfield_doline_n1 (data, wordcount); break; - case 2: pfield_doline_n2 (data, wordcount); break; - case 3: pfield_doline_n3 (data, wordcount); break; - case 4: pfield_doline_n4 (data, wordcount); break; - case 5: pfield_doline_n5 (data, wordcount); break; - case 6: pfield_doline_n6 (data, wordcount); break; + switch (bplplanecnt) { + default: break; + case 0: memset (data, 0, wordcount * 32); break; + case 1: pfield_doline_n1 (data, wordcount); break; + case 2: pfield_doline_n2 (data, wordcount); break; + case 3: pfield_doline_n3 (data, wordcount); break; + case 4: pfield_doline_n4 (data, wordcount); break; + case 5: pfield_doline_n5 (data, wordcount); break; + case 6: pfield_doline_n6 (data, wordcount); break; #ifdef AGA - case 7: pfield_doline_n7 (data, wordcount); break; - case 8: pfield_doline_n8 (data, wordcount); break; + case 7: pfield_doline_n7 (data, wordcount); break; + case 8: pfield_doline_n8 (data, wordcount); break; #endif - } + } } void init_row_map (void) { - int i, j; - if (gfxvidinfo.height > MAX_VIDHEIGHT) { - write_log (L"Resolution too high, aborting\n"); - abort (); - } - j = 0; - for (i = gfxvidinfo.height; i < MAX_VIDHEIGHT + 1; i++) - row_map[i] = row_tmp; - for (i = 0; i < gfxvidinfo.height; i++, j += gfxvidinfo.rowbytes) - row_map[i] = gfxvidinfo.bufmem + j; + int i, j; + if (gfxvidinfo.height > MAX_VIDHEIGHT) { + write_log (L"Resolution too high, aborting\n"); + abort (); + } + j = 0; + for (i = gfxvidinfo.height; i < MAX_VIDHEIGHT + 1; i++) + row_map[i] = row_tmp; + for (i = 0; i < gfxvidinfo.height; i++, j += gfxvidinfo.rowbytes) + row_map[i] = gfxvidinfo.bufmem + j; } static void init_aspect_maps (void) { - int i, maxl; + int i, maxl; - if (gfxvidinfo.height == 0) - /* Do nothing if the gfx driver hasn't initialized the screen yet */ - return; + if (gfxvidinfo.height == 0) + /* Do nothing if the gfx driver hasn't initialized the screen yet */ + return; - linedbld = linedbl = currprefs.gfx_linedbl; - if (doublescan > 0 && interlace_seen <= 0) { - linedbl = 0; - linedbld = 1; - } - - if (native2amiga_line_map) - xfree (native2amiga_line_map); - if (amiga2aspect_line_map) - xfree (amiga2aspect_line_map); - - /* At least for this array the +1 is necessary. */ - amiga2aspect_line_map = xmalloc (sizeof (int) * (MAXVPOS + 1) * 2 + 1); - native2amiga_line_map = xmalloc (sizeof (int) * gfxvidinfo.height); - - maxl = (MAXVPOS + 1) * (linedbld ? 2 : 1); - min_ypos_for_screen = minfirstline << (linedbl ? 1 : 0); - max_drawn_amiga_line = -1; - for (i = 0; i < maxl; i++) { - int v = i - min_ypos_for_screen; - if (v >= gfxvidinfo.height && max_drawn_amiga_line == -1) - max_drawn_amiga_line = i - min_ypos_for_screen; - if (i < min_ypos_for_screen || v >= gfxvidinfo.height) - v = -1; - amiga2aspect_line_map[i] = v; - } - if (linedbl) - max_drawn_amiga_line >>= 1; - - if (currprefs.gfx_ycenter && !currprefs.gfx_filter_autoscale) { - /* @@@ verify maxvpos vs. MAXVPOS */ - extra_y_adjust = (gfxvidinfo.height - (maxvpos_max << (linedbl ? 1 : 0))) >> 1; - if (extra_y_adjust < 0) - extra_y_adjust = 0; - } - - for (i = 0; i < gfxvidinfo.height; i++) - native2amiga_line_map[i] = -1; - - for (i = maxl - 1; i >= min_ypos_for_screen; i--) { - int j; - if (amiga2aspect_line_map[i] == -1) - continue; - for (j = amiga2aspect_line_map[i]; j < gfxvidinfo.height && native2amiga_line_map[j] == -1; j++) - native2amiga_line_map[j] = i >> (linedbl ? 1 : 0); - } + linedbld = linedbl = currprefs.gfx_linedbl; + if (doublescan > 0 && interlace_seen <= 0) { + linedbl = 0; + linedbld = 1; + } + + if (native2amiga_line_map) + xfree (native2amiga_line_map); + if (amiga2aspect_line_map) + xfree (amiga2aspect_line_map); + + /* At least for this array the +1 is necessary. */ + amiga2aspect_line_map = xmalloc (sizeof (int) * (MAXVPOS + 1) * 2 + 1); + native2amiga_line_map = xmalloc (sizeof (int) * gfxvidinfo.height); + + maxl = (MAXVPOS + 1) * (linedbld ? 2 : 1); + min_ypos_for_screen = minfirstline << (linedbl ? 1 : 0); + max_drawn_amiga_line = -1; + for (i = 0; i < maxl; i++) { + int v = i - min_ypos_for_screen; + if (v >= gfxvidinfo.height && max_drawn_amiga_line == -1) + max_drawn_amiga_line = i - min_ypos_for_screen; + if (i < min_ypos_for_screen || v >= gfxvidinfo.height) + v = -1; + amiga2aspect_line_map[i] = v; + } + if (linedbl) + max_drawn_amiga_line >>= 1; + + if (currprefs.gfx_ycenter && !currprefs.gfx_filter_autoscale) { + /* @@@ verify maxvpos vs. MAXVPOS */ + extra_y_adjust = (gfxvidinfo.height - (maxvpos_max << (linedbl ? 1 : 0))) >> 1; + if (extra_y_adjust < 0) + extra_y_adjust = 0; + } + + for (i = 0; i < gfxvidinfo.height; i++) + native2amiga_line_map[i] = -1; + + for (i = maxl - 1; i >= min_ypos_for_screen; i--) { + int j; + if (amiga2aspect_line_map[i] == -1) + continue; + for (j = amiga2aspect_line_map[i]; j < gfxvidinfo.height && native2amiga_line_map[j] == -1; j++) + native2amiga_line_map[j] = i >> (linedbl ? 1 : 0); + } } /* - * A raster line has been built in the graphics buffer. Tell the graphics code - * to do anything necessary to display it. - */ +* A raster line has been built in the graphics buffer. Tell the graphics code +* to do anything necessary to display it. +*/ static void do_flush_line_1 (int lineno) { - if (lineno < first_drawn_line) - first_drawn_line = lineno; - if (lineno > last_drawn_line) - last_drawn_line = lineno; - - if (gfxvidinfo.maxblocklines == 0) - flush_line (lineno); - else { - if ((last_block_line + 2) < lineno) { - if (first_block_line != NO_BLOCK) - flush_block (first_block_line, last_block_line); - first_block_line = lineno; - } - last_block_line = lineno; - if (last_block_line - first_block_line >= gfxvidinfo.maxblocklines) { - flush_block (first_block_line, last_block_line); - first_block_line = last_block_line = NO_BLOCK; + if (lineno < first_drawn_line) + first_drawn_line = lineno; + if (lineno > last_drawn_line) + last_drawn_line = lineno; + + if (gfxvidinfo.maxblocklines == 0) + flush_line (lineno); + else { + if ((last_block_line + 2) < lineno) { + if (first_block_line != NO_BLOCK) + flush_block (first_block_line, last_block_line); + first_block_line = lineno; + } + last_block_line = lineno; + if (last_block_line - first_block_line >= gfxvidinfo.maxblocklines) { + flush_block (first_block_line, last_block_line); + first_block_line = last_block_line = NO_BLOCK; + } } - } } STATIC_INLINE void do_flush_line (int lineno) { - do_flush_line_1 (lineno); + do_flush_line_1 (lineno); } /* - * One drawing frame has been finished. Tell the graphics code about it. - * Note that the actual flush_screen() call is a no-op for all reasonable - * systems. - */ +* One drawing frame has been finished. Tell the graphics code about it. +* Note that the actual flush_screen() call is a no-op for all reasonable +* systems. +*/ STATIC_INLINE void do_flush_screen (int start, int stop) { - /* TODO: this flush operation is executed outside locked state! - Should be corrected. - (sjo 26.9.99) */ + /* TODO: this flush operation is executed outside locked state! + Should be corrected. + (sjo 26.9.99) */ - xlinecheck (start, stop); - if (gfxvidinfo.maxblocklines != 0 && first_block_line != NO_BLOCK) { - flush_block (first_block_line, last_block_line); - } - unlockscr (); - if (start <= stop) - flush_screen (start, stop); - else if ((currprefs.gfx_afullscreen && currprefs.gfx_avsync) || currprefs.gfx_filter == 8) - flush_screen (0, 0); /* vsync mode */ + xlinecheck (start, stop); + if (gfxvidinfo.maxblocklines != 0 && first_block_line != NO_BLOCK) { + flush_block (first_block_line, last_block_line); + } + unlockscr (); + if (start <= stop) + flush_screen (start, stop); + else if ((currprefs.gfx_afullscreen && currprefs.gfx_avsync) || currprefs.gfx_filter == 8) + flush_screen (0, 0); /* vsync mode */ } /* We only save hardware registers during the hardware frame. Now, when - * drawing the frame, we expand the data into a slightly more useful - * form. */ +* drawing the frame, we expand the data into a slightly more useful +* form. */ static void pfield_expand_dp_bplcon (void) { - int brdblank_2; - static int b2; + int brdblank_2; + static int b2; - bplres = dp_for_drawing->bplres; - bplplanecnt = dp_for_drawing->nr_planes; - bplham = dp_for_drawing->ham_seen; - bplehb = dp_for_drawing->ehb_seen; - if ((currprefs.chipset_mask & CSMASK_AGA) && (dp_for_drawing->bplcon2 & 0x0200)) - bplehb = 0; - issprites = dip_for_drawing->nr_sprites; + bplres = dp_for_drawing->bplres; + bplplanecnt = dp_for_drawing->nr_planes; + bplham = dp_for_drawing->ham_seen; + bplehb = dp_for_drawing->ehb_seen; + if ((currprefs.chipset_mask & CSMASK_AGA) && (dp_for_drawing->bplcon2 & 0x0200)) + bplehb = 0; + issprites = dip_for_drawing->nr_sprites; #ifdef ECS_DENISE - ecsshres = bplres == RES_SUPERHIRES && (currprefs.chipset_mask & CSMASK_ECS_DENISE) && !(currprefs.chipset_mask & CSMASK_AGA); + ecsshres = bplres == RES_SUPERHIRES && (currprefs.chipset_mask & CSMASK_ECS_DENISE) && !(currprefs.chipset_mask & CSMASK_AGA); #endif - if (bplres > 0) - frame_res = 1; - if (bplres > 0) - can_use_lores = 0; + if (bplres > 0) + frame_res = 1; + if (bplres > 0) + can_use_lores = 0; - plf1pri = dp_for_drawing->bplcon2 & 7; - plf2pri = (dp_for_drawing->bplcon2 >> 3) & 7; - plf_sprite_mask = 0xFFFF0000 << (4 * plf2pri); - plf_sprite_mask |= (0x0000FFFF << (4 * plf1pri)) & 0xFFFF; - bpldualpf = (dp_for_drawing->bplcon0 & 0x400) == 0x400; - bpldualpfpri = (dp_for_drawing->bplcon2 & 0x40) == 0x40; + plf1pri = dp_for_drawing->bplcon2 & 7; + plf2pri = (dp_for_drawing->bplcon2 >> 3) & 7; + plf_sprite_mask = 0xFFFF0000 << (4 * plf2pri); + plf_sprite_mask |= (0x0000FFFF << (4 * plf1pri)) & 0xFFFF; + bpldualpf = (dp_for_drawing->bplcon0 & 0x400) == 0x400; + bpldualpfpri = (dp_for_drawing->bplcon2 & 0x40) == 0x40; #ifdef ECS_DENISE - brdblank_2 = (currprefs.chipset_mask & CSMASK_ECS_DENISE) && (dp_for_drawing->bplcon0 & 1) && (dp_for_drawing->bplcon3 & 0x20); - if (brdblank_2 != brdblank) - brdblank_changed = 1; - brdblank = brdblank_2; + brdblank_2 = (currprefs.chipset_mask & CSMASK_ECS_DENISE) && (dp_for_drawing->bplcon0 & 1) && (dp_for_drawing->bplcon3 & 0x20); + if (brdblank_2 != brdblank) + brdblank_changed = 1; + brdblank = brdblank_2; #endif #ifdef AGA - bpldualpf2of = (dp_for_drawing->bplcon3 >> 10) & 7; - sbasecol[0] = ((dp_for_drawing->bplcon4 >> 4) & 15) << 4; - sbasecol[1] = ((dp_for_drawing->bplcon4 >> 0) & 15) << 4; - brdsprt = !brdblank && (currprefs.chipset_mask & CSMASK_AGA) && (dp_for_drawing->bplcon0 & 1) && (dp_for_drawing->bplcon3 & 0x02); - bplxor = dp_for_drawing->bplcon4 >> 8; + bpldualpf2of = (dp_for_drawing->bplcon3 >> 10) & 7; + sbasecol[0] = ((dp_for_drawing->bplcon4 >> 4) & 15) << 4; + sbasecol[1] = ((dp_for_drawing->bplcon4 >> 0) & 15) << 4; + brdsprt = !brdblank && (currprefs.chipset_mask & CSMASK_AGA) && (dp_for_drawing->bplcon0 & 1) && (dp_for_drawing->bplcon3 & 0x02); + bplxor = dp_for_drawing->bplcon4 >> 8; #endif } static int isham (uae_u16 bplcon0) { - int p = GET_PLANES (bplcon0); - if (!(bplcon0 & 0x800)) + int p = GET_PLANES (bplcon0); + if (!(bplcon0 & 0x800)) + return 0; + if (currprefs.chipset_mask & CSMASK_AGA) { + // AGA only has 6 or 8 plane HAM + if (p == 6 || p == 8) + return 1; + } else { + // OCS/ECS also supports 5 plane HAM + if (GET_RES_DENISE (bplcon0) > 0) + return 0; + if (p >= 5) + return 1; + } return 0; - if (currprefs.chipset_mask & CSMASK_AGA) { - // AGA only has 6 or 8 plane HAM - if (p == 6 || p == 8) - return 1; - } else { - // OCS/ECS also supports 5 plane HAM - if (GET_RES_DENISE (bplcon0) > 0) - return 0; - if (p >= 5) - return 1; - } - return 0; } static void pfield_expand_dp_bplcon2 (int regno, int v) { - regno -= 0x1000; - switch (regno) - { + regno -= 0x1000; + switch (regno) + { case 0x100: - dp_for_drawing->bplcon0 = v; - dp_for_drawing->bplres = GET_RES_DENISE (v); - dp_for_drawing->nr_planes = GET_PLANES (v); - dp_for_drawing->ham_seen = isham (v); - break; + dp_for_drawing->bplcon0 = v; + dp_for_drawing->bplres = GET_RES_DENISE (v); + dp_for_drawing->nr_planes = GET_PLANES (v); + dp_for_drawing->ham_seen = isham (v); + break; case 0x104: - dp_for_drawing->bplcon2 = v; - break; + dp_for_drawing->bplcon2 = v; + break; #ifdef ECS_DENISE case 0x106: - dp_for_drawing->bplcon3 = v; - break; + dp_for_drawing->bplcon3 = v; + break; #endif #ifdef AGA case 0x10c: - dp_for_drawing->bplcon4 = v; - break; + dp_for_drawing->bplcon4 = v; + break; #endif - } - pfield_expand_dp_bplcon (); - res_shift = lores_shift - bplres; + } + pfield_expand_dp_bplcon (); + res_shift = lores_shift - bplres; } static int drawing_color_matches; static enum { color_match_acolors, color_match_full } color_match_type; /* Set up colors_for_drawing to the state at the beginning of the currently drawn - line. Try to avoid copying color tables around whenever possible. */ +line. Try to avoid copying color tables around whenever possible. */ static void adjust_drawing_colors (int ctable, int need_full) { - if (drawing_color_matches != ctable) { - if (need_full) { - color_reg_cpy (&colors_for_drawing, curr_color_tables + ctable); - color_match_type = color_match_full; - } else { - memcpy (colors_for_drawing.acolors, curr_color_tables[ctable].acolors, - sizeof colors_for_drawing.acolors); - color_match_type = color_match_acolors; + if (drawing_color_matches != ctable) { + if (need_full) { + color_reg_cpy (&colors_for_drawing, curr_color_tables + ctable); + color_match_type = color_match_full; + } else { + memcpy (colors_for_drawing.acolors, curr_color_tables[ctable].acolors, + sizeof colors_for_drawing.acolors); + color_match_type = color_match_acolors; + } + drawing_color_matches = ctable; + } else if (need_full && color_match_type != color_match_full) { + color_reg_cpy (&colors_for_drawing, &curr_color_tables[ctable]); + color_match_type = color_match_full; } - drawing_color_matches = ctable; - } else if (need_full && color_match_type != color_match_full) { - color_reg_cpy (&colors_for_drawing, &curr_color_tables[ctable]); - color_match_type = color_match_full; - } } STATIC_INLINE void do_color_changes (line_draw_func worker_border, line_draw_func worker_pfield) { - int i; - int lastpos = visible_left_border; - int endpos = visible_left_border + gfxvidinfo.width; - int diff = 1 << lores_shift; + int i; + int lastpos = visible_left_border; + int endpos = visible_left_border + gfxvidinfo.width; + int diff = 1 << lores_shift; - for (i = dip_for_drawing->first_color_change; i <= dip_for_drawing->last_color_change; i++) { - int regno = curr_color_changes[i].regno; - unsigned int value = curr_color_changes[i].value; - int nextpos, nextpos_in_range; + for (i = dip_for_drawing->first_color_change; i <= dip_for_drawing->last_color_change; i++) { + int regno = curr_color_changes[i].regno; + unsigned int value = curr_color_changes[i].value; + int nextpos, nextpos_in_range; - if (i == dip_for_drawing->last_color_change) - nextpos = endpos; - else - nextpos = coord_hw_to_window_x (curr_color_changes[i].linepos); - - nextpos_in_range = nextpos; - if (nextpos > endpos) - nextpos_in_range = endpos; - - if (nextpos_in_range > lastpos) { - if (lastpos < playfield_start) { - int t = nextpos_in_range <= playfield_start ? nextpos_in_range : playfield_start; - (*worker_border) (lastpos, t); - lastpos = t; - } - } - if (nextpos_in_range > lastpos) { - if (lastpos >= playfield_start && lastpos < playfield_end) { - int t = nextpos_in_range <= playfield_end ? nextpos_in_range : playfield_end; - (*worker_pfield) (lastpos, t); - lastpos = t; - } - } - if (nextpos_in_range > lastpos) { - if (lastpos >= playfield_end) - (*worker_border) (lastpos, nextpos_in_range); - lastpos = nextpos_in_range; - } - if (i != dip_for_drawing->last_color_change) { - if (regno >= 0x1000) { - pfield_expand_dp_bplcon2 (regno, value); - } else { - color_reg_set (&colors_for_drawing, regno, value); - colors_for_drawing.acolors[regno] = getxcolor (value); - } - } - if (lastpos >= endpos) - break; - } + if (i == dip_for_drawing->last_color_change) + nextpos = endpos; + else + nextpos = coord_hw_to_window_x (curr_color_changes[i].linepos); + + nextpos_in_range = nextpos; + if (nextpos > endpos) + nextpos_in_range = endpos; + + if (nextpos_in_range > lastpos) { + if (lastpos < playfield_start) { + int t = nextpos_in_range <= playfield_start ? nextpos_in_range : playfield_start; + (*worker_border) (lastpos, t); + lastpos = t; + } + } + if (nextpos_in_range > lastpos) { + if (lastpos >= playfield_start && lastpos < playfield_end) { + int t = nextpos_in_range <= playfield_end ? nextpos_in_range : playfield_end; + (*worker_pfield) (lastpos, t); + lastpos = t; + } + } + if (nextpos_in_range > lastpos) { + if (lastpos >= playfield_end) + (*worker_border) (lastpos, nextpos_in_range); + lastpos = nextpos_in_range; + } + if (i != dip_for_drawing->last_color_change) { + if (regno >= 0x1000) { + pfield_expand_dp_bplcon2 (regno, value); + } else { + color_reg_set (&colors_for_drawing, regno, value); + colors_for_drawing.acolors[regno] = getxcolor (value); + } + } + if (lastpos >= endpos) + break; + } } enum double_how { - dh_buf, - dh_line, - dh_emerg + dh_buf, + dh_line, + dh_emerg }; static void pfield_draw_line (int lineno, int gfx_ypos, int follow_ypos) { - static int warned = 0; - int border = 0; - int do_double = 0; - enum double_how dh; - - dp_for_drawing = line_decisions + lineno; - dip_for_drawing = curr_drawinfo + lineno; - - switch (linestate[lineno]) - { - case LINE_REMEMBERED_AS_PREVIOUS: - if (!warned) - write_log (L"Shouldn't get here... this is a bug.\n"), warned++; - return; - - case LINE_BLACK: - linestate[lineno] = LINE_REMEMBERED_AS_BLACK; - border = 2; - break; - - case LINE_REMEMBERED_AS_BLACK: - return; - - case LINE_AS_PREVIOUS: - dp_for_drawing--; - dip_for_drawing--; - linestate[lineno] = LINE_DONE_AS_PREVIOUS; - if (dp_for_drawing->plfleft == -1) - border = 1; - break; - - case LINE_DONE_AS_PREVIOUS: - /* fall through */ - case LINE_DONE: - return; + static int warned = 0; + int border = 0; + int do_double = 0; + enum double_how dh; + + dp_for_drawing = line_decisions + lineno; + dip_for_drawing = curr_drawinfo + lineno; + + switch (linestate[lineno]) + { + case LINE_REMEMBERED_AS_PREVIOUS: + if (!warned) + write_log (L"Shouldn't get here... this is a bug.\n"), warned++; + return; + + case LINE_BLACK: + linestate[lineno] = LINE_REMEMBERED_AS_BLACK; + border = 2; + break; + + case LINE_REMEMBERED_AS_BLACK: + return; + + case LINE_AS_PREVIOUS: + dp_for_drawing--; + dip_for_drawing--; + linestate[lineno] = LINE_DONE_AS_PREVIOUS; + if (dp_for_drawing->plfleft == -1) + border = 1; + break; + + case LINE_DONE_AS_PREVIOUS: + /* fall through */ + case LINE_DONE: + return; + + case LINE_DECIDED_DOUBLE: + if (follow_ypos != -1) { + do_double = 1; + linestate[lineno + 1] = LINE_DONE_AS_PREVIOUS; + } - case LINE_DECIDED_DOUBLE: - if (follow_ypos != -1) { - do_double = 1; - linestate[lineno + 1] = LINE_DONE_AS_PREVIOUS; + /* fall through */ + default: + if (dp_for_drawing->plfleft == -1) + border = 1; + linestate[lineno] = LINE_DONE; + break; } - /* fall through */ - default: - if (dp_for_drawing->plfleft == -1) - border = 1; - linestate[lineno] = LINE_DONE; - break; - } + dh = dh_line; + xlinebuffer = gfxvidinfo.linemem; + if (xlinebuffer == 0 && do_double + && (border == 0 || dip_for_drawing->nr_color_changes > 0)) + xlinebuffer = gfxvidinfo.emergmem, dh = dh_emerg; + if (xlinebuffer == 0) + xlinebuffer = row_map[gfx_ypos], dh = dh_buf; + xlinebuffer -= linetoscr_x_adjust_bytes; - dh = dh_line; - xlinebuffer = gfxvidinfo.linemem; - if (xlinebuffer == 0 && do_double - && (border == 0 || dip_for_drawing->nr_color_changes > 0)) - xlinebuffer = gfxvidinfo.emergmem, dh = dh_emerg; - if (xlinebuffer == 0) - xlinebuffer = row_map[gfx_ypos], dh = dh_buf; - xlinebuffer -= linetoscr_x_adjust_bytes; + if (border == 0) { + + pfield_expand_dp_bplcon (); + pfield_init_linetoscr (); + pfield_doline (lineno); + + adjust_drawing_colors (dp_for_drawing->ctable, dp_for_drawing->ham_seen || bplehb || ecsshres); + + /* The problem is that we must call decode_ham() BEFORE we do the + sprites. */ + if (dp_for_drawing->ham_seen) { + init_ham_decoding (); + if (dip_for_drawing->nr_color_changes == 0) { + /* The easy case: need to do HAM decoding only once for the + * full line. */ + decode_ham (visible_left_border, visible_right_border); + } else /* Argh. */ { + do_color_changes (dummy_worker, decode_ham); + adjust_drawing_colors (dp_for_drawing->ctable, dp_for_drawing->ham_seen || bplehb); + } + bplham = dp_for_drawing->ham_at_start; + } - if (border == 0) { + if (plf2pri > 5 && bplplanecnt == 5 && !(currprefs.chipset_mask & CSMASK_AGA)) + weird_bitplane_fix (); - pfield_expand_dp_bplcon (); - pfield_init_linetoscr (); - pfield_doline (lineno); - - adjust_drawing_colors (dp_for_drawing->ctable, dp_for_drawing->ham_seen || bplehb || ecsshres); - - /* The problem is that we must call decode_ham() BEFORE we do the - sprites. */ - if (dp_for_drawing->ham_seen) { - init_ham_decoding (); - if (dip_for_drawing->nr_color_changes == 0) { - /* The easy case: need to do HAM decoding only once for the - * full line. */ - decode_ham (visible_left_border, visible_right_border); - } else /* Argh. */ { - do_color_changes (dummy_worker, decode_ham); - adjust_drawing_colors (dp_for_drawing->ctable, dp_for_drawing->ham_seen || bplehb); - } - bplham = dp_for_drawing->ham_at_start; - } - - if (plf2pri > 5 && bplplanecnt == 5 && !(currprefs.chipset_mask & CSMASK_AGA)) - weird_bitplane_fix (); - - if (dip_for_drawing->nr_sprites) { - int i; + if (dip_for_drawing->nr_sprites) { + int i; #ifdef AGA - if (brdsprt) - clear_bitplane_border_aga (); + if (brdsprt) + clear_bitplane_border_aga (); #endif - for (i = 0; i < dip_for_drawing->nr_sprites; i++) { + for (i = 0; i < dip_for_drawing->nr_sprites; i++) { #ifdef AGA - if (currprefs.chipset_mask & CSMASK_AGA) - draw_sprites_aga (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i, 1); - else + if (currprefs.chipset_mask & CSMASK_AGA) + draw_sprites_aga (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i, 1); + else #endif - draw_sprites_ecs (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i); - } - } + draw_sprites_ecs (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i); + } + } - do_color_changes (pfield_do_fill_line, pfield_do_linetoscr); + do_color_changes (pfield_do_fill_line, pfield_do_linetoscr); - if (dh == dh_emerg) - memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); + if (dh == dh_emerg) + memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); - do_flush_line (gfx_ypos); - if (do_double) { - if (dh == dh_emerg) - memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); - else if (dh == dh_buf) - memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width); - do_flush_line (follow_ypos); - } + do_flush_line (gfx_ypos); + if (do_double) { + if (dh == dh_emerg) + memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); + else if (dh == dh_buf) + memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width); + do_flush_line (follow_ypos); + } - } else if (border == 1) { - int dosprites = 0; + } else if (border == 1) { + int dosprites = 0; - adjust_drawing_colors (dp_for_drawing->ctable, 0); + adjust_drawing_colors (dp_for_drawing->ctable, 0); #ifdef AGA /* this makes things complex.. */ - if (brdsprt && dip_for_drawing->nr_sprites > 0) { - dosprites = 1; - pfield_expand_dp_bplcon (); - pfield_init_linetoscr (); - memset (pixdata.apixels + MAX_PIXELS_PER_LINE, brdblank ? 0 : colors_for_drawing.acolors[0], MAX_PIXELS_PER_LINE); - } + if (brdsprt && dip_for_drawing->nr_sprites > 0) { + dosprites = 1; + pfield_expand_dp_bplcon (); + pfield_init_linetoscr (); + memset (pixdata.apixels + MAX_PIXELS_PER_LINE, brdblank ? 0 : colors_for_drawing.acolors[0], MAX_PIXELS_PER_LINE); + } #endif - if (!dosprites && dip_for_drawing->nr_color_changes == 0) { - fill_line (); - do_flush_line (gfx_ypos); - - if (do_double) { - if (dh == dh_buf) { - xlinebuffer = row_map[follow_ypos] - linetoscr_x_adjust_bytes; - fill_line (); + if (!dosprites && dip_for_drawing->nr_color_changes == 0) { + fill_line (); + do_flush_line (gfx_ypos); + + if (do_double) { + if (dh == dh_buf) { + xlinebuffer = row_map[follow_ypos] - linetoscr_x_adjust_bytes; + fill_line (); + } + /* If dh == dh_line, do_flush_line will re-use the rendered line + * from linemem. */ + do_flush_line (follow_ypos); + } + return; } - /* If dh == dh_line, do_flush_line will re-use the rendered line - * from linemem. */ - do_flush_line (follow_ypos); - } - return; - } - if (dosprites) { + if (dosprites) { - int i; - for (i = 0; i < dip_for_drawing->nr_sprites; i++) - draw_sprites_aga (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i, 1); - do_color_changes (pfield_do_fill_line, pfield_do_linetoscr); + int i; + for (i = 0; i < dip_for_drawing->nr_sprites; i++) + draw_sprites_aga (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i, 1); + do_color_changes (pfield_do_fill_line, pfield_do_linetoscr); - } else { + } else { - playfield_start = visible_right_border; - playfield_end = visible_right_border; - do_color_changes (pfield_do_fill_line, pfield_do_fill_line); + playfield_start = visible_right_border; + playfield_end = visible_right_border; + do_color_changes (pfield_do_fill_line, pfield_do_fill_line); - } + } - if (dh == dh_emerg) - memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); + if (dh == dh_emerg) + memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); - do_flush_line (gfx_ypos); - if (do_double) { - if (dh == dh_emerg) - memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); - else if (dh == dh_buf) - memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width); - do_flush_line (follow_ypos); - } + do_flush_line (gfx_ypos); + if (do_double) { + if (dh == dh_emerg) + memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width); + else if (dh == dh_buf) + memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width); + do_flush_line (follow_ypos); + } - } else { + } else { - xcolnr tmp = colors_for_drawing.acolors[0]; - colors_for_drawing.acolors[0] = getxcolor (0); - fill_line (); - do_flush_line (gfx_ypos); - colors_for_drawing.acolors[0] = tmp; + xcolnr tmp = colors_for_drawing.acolors[0]; + colors_for_drawing.acolors[0] = getxcolor (0); + fill_line (); + do_flush_line (gfx_ypos); + colors_for_drawing.acolors[0] = tmp; - } + } } static void center_image (void) { - int prev_x_adjust = visible_left_border; - int prev_y_adjust = thisframe_y_adjust; - int tmp; - - if (currprefs.gfx_xcenter && !currprefs.gfx_filter_autoscale) { - int w = gfxvidinfo.width; + int prev_x_adjust = visible_left_border; + int prev_y_adjust = thisframe_y_adjust; + int tmp; - if (max_diwstop - min_diwstart < w && currprefs.gfx_xcenter == 2) - /* Try to center. */ - visible_left_border = (max_diwstop - min_diwstart - w) / 2 + min_diwstart; - else - visible_left_border = max_diwstop - w - (max_diwstop - min_diwstart - w) / 2; - visible_left_border &= ~((xshift (1, lores_shift)) - 1); + if (currprefs.gfx_xcenter && !currprefs.gfx_filter_autoscale) { + int w = gfxvidinfo.width; - /* Would the old value be good enough? If so, leave it as it is if we want to - * be clever. */ - if (currprefs.gfx_xcenter == 2) { - if (visible_left_border < prev_x_adjust && prev_x_adjust < min_diwstart && min_diwstart - visible_left_border <= 32) - visible_left_border = prev_x_adjust; - } - } else { - if (beamcon0 & 0x80) { - int w = gfxvidinfo.width; - if (max_diwstop - min_diwstart < w) - visible_left_border = (max_diwstop - min_diwstart - w) / 2 + min_diwstart; - else - visible_left_border = max_diwstop - w - (max_diwstop - min_diwstart - w) / 2; + if (max_diwstop - min_diwstart < w && currprefs.gfx_xcenter == 2) + /* Try to center. */ + visible_left_border = (max_diwstop - min_diwstart - w) / 2 + min_diwstart; + else + visible_left_border = max_diwstop - w - (max_diwstop - min_diwstart - w) / 2; + visible_left_border &= ~((xshift (1, lores_shift)) - 1); + + /* Would the old value be good enough? If so, leave it as it is if we want to + * be clever. */ + if (currprefs.gfx_xcenter == 2) { + if (visible_left_border < prev_x_adjust && prev_x_adjust < min_diwstart && min_diwstart - visible_left_border <= 32) + visible_left_border = prev_x_adjust; + } } else { - visible_left_border = max_diwlastword - gfxvidinfo.width; + if (beamcon0 & 0x80) { + int w = gfxvidinfo.width; + if (max_diwstop - min_diwstart < w) + visible_left_border = (max_diwstop - min_diwstart - w) / 2 + min_diwstart; + else + visible_left_border = max_diwstop - w - (max_diwstop - min_diwstart - w) / 2; + } else { + visible_left_border = max_diwlastword - gfxvidinfo.width; + } } - } - if (currprefs.gfx_xcenter_pos >= 0) { - int val = currprefs.gfx_xcenter_pos >> RES_MAX; + if (currprefs.gfx_xcenter_pos >= 0) { + int val = currprefs.gfx_xcenter_pos >> RES_MAX; #if 0 - if (currprefs.gfx_xcenter_size > 0) { - int diff = ((gfxvidinfo.width << (RES_MAX - currprefs.gfx_resolution)) - currprefs.gfx_xcenter_size) / 1; - write_log (L"%d %d\n", currprefs.gfx_xcenter_size, gfxvidinfo.width); - val -= diff >> RES_MAX; - } + if (currprefs.gfx_xcenter_size > 0) { + int diff = ((gfxvidinfo.width << (RES_MAX - currprefs.gfx_resolution)) - currprefs.gfx_xcenter_size) / 1; + write_log (L"%d %d\n", currprefs.gfx_xcenter_size, gfxvidinfo.width); + val -= diff >> RES_MAX; + } #endif - if (val < 56) - val = 56; - visible_left_border = val + (DIW_DDF_OFFSET << currprefs.gfx_resolution) - (DISPLAY_LEFT_SHIFT * 2 - (DISPLAY_LEFT_SHIFT << currprefs.gfx_resolution)); - } + if (val < 56) + val = 56; + visible_left_border = val + (DIW_DDF_OFFSET << currprefs.gfx_resolution) - (DISPLAY_LEFT_SHIFT * 2 - (DISPLAY_LEFT_SHIFT << currprefs.gfx_resolution)); + } - if (visible_left_border > max_diwlastword - 32) - visible_left_border = max_diwlastword - 32; - if (visible_left_border < 0) - visible_left_border = 0; - visible_left_border &= ~((xshift (1, lores_shift)) - 1); + if (visible_left_border > max_diwlastword - 32) + visible_left_border = max_diwlastword - 32; + if (visible_left_border < 0) + visible_left_border = 0; + visible_left_border &= ~((xshift (1, lores_shift)) - 1); - linetoscr_x_adjust_bytes = visible_left_border * gfxvidinfo.pixbytes; + linetoscr_x_adjust_bytes = visible_left_border * gfxvidinfo.pixbytes; - visible_right_border = visible_left_border + gfxvidinfo.width; - if (visible_right_border > max_diwlastword) - visible_right_border = max_diwlastword; + visible_right_border = visible_left_border + gfxvidinfo.width; + if (visible_right_border > max_diwlastword) + visible_right_border = max_diwlastword; - thisframe_y_adjust = minfirstline; - if (currprefs.gfx_ycenter && thisframe_first_drawn_line != -1 && !currprefs.gfx_filter_autoscale) { + thisframe_y_adjust = minfirstline; + if (currprefs.gfx_ycenter && thisframe_first_drawn_line != -1 && !currprefs.gfx_filter_autoscale) { - if (thisframe_last_drawn_line - thisframe_first_drawn_line < max_drawn_amiga_line && currprefs.gfx_ycenter == 2) - thisframe_y_adjust = (thisframe_last_drawn_line - thisframe_first_drawn_line - max_drawn_amiga_line) / 2 + thisframe_first_drawn_line; - else - thisframe_y_adjust = thisframe_first_drawn_line + ((thisframe_last_drawn_line - thisframe_first_drawn_line) - max_drawn_amiga_line) / 2; - - /* Would the old value be good enough? If so, leave it as it is if we want to - * be clever. */ - if (currprefs.gfx_ycenter == 2) { - if (thisframe_y_adjust != prev_y_adjust - && prev_y_adjust <= thisframe_first_drawn_line - && prev_y_adjust + max_drawn_amiga_line > thisframe_last_drawn_line) - thisframe_y_adjust = prev_y_adjust; - } - } - if (currprefs.gfx_ycenter_pos >= 0) { - thisframe_y_adjust = currprefs.gfx_ycenter_pos >> 1; -#if 0 - if (currprefs.gfx_ycenter_size > 0) { - int diff = (currprefs.gfx_ycenter_size - (gfxvidinfo.height << (linedbl ? 0 : 1))) / 2; - thisframe_y_adjust += diff >> 1; + if (thisframe_last_drawn_line - thisframe_first_drawn_line < max_drawn_amiga_line && currprefs.gfx_ycenter == 2) + thisframe_y_adjust = (thisframe_last_drawn_line - thisframe_first_drawn_line - max_drawn_amiga_line) / 2 + thisframe_first_drawn_line; + else + thisframe_y_adjust = thisframe_first_drawn_line + ((thisframe_last_drawn_line - thisframe_first_drawn_line) - max_drawn_amiga_line) / 2; + + /* Would the old value be good enough? If so, leave it as it is if we want to + * be clever. */ + if (currprefs.gfx_ycenter == 2) { + if (thisframe_y_adjust != prev_y_adjust + && prev_y_adjust <= thisframe_first_drawn_line + && prev_y_adjust + max_drawn_amiga_line > thisframe_last_drawn_line) + thisframe_y_adjust = prev_y_adjust; + } } + if (currprefs.gfx_ycenter_pos >= 0) { + thisframe_y_adjust = currprefs.gfx_ycenter_pos >> 1; +#if 0 + if (currprefs.gfx_ycenter_size > 0) { + int diff = (currprefs.gfx_ycenter_size - (gfxvidinfo.height << (linedbl ? 0 : 1))) / 2; + thisframe_y_adjust += diff >> 1; + } #endif - if (thisframe_y_adjust + max_drawn_amiga_line > 2 * maxvpos_max) - thisframe_y_adjust = 2 * maxvpos_max - max_drawn_amiga_line; - if (thisframe_y_adjust < 0) - thisframe_y_adjust = 0; - } else { - /* Make sure the value makes sense */ - if (thisframe_y_adjust + max_drawn_amiga_line > maxvpos_max) - thisframe_y_adjust = maxvpos_max - max_drawn_amiga_line; - if (thisframe_y_adjust < minfirstline) - thisframe_y_adjust = minfirstline; - } - thisframe_y_adjust_real = thisframe_y_adjust << (linedbl ? 1 : 0); - tmp = (maxvpos_max - thisframe_y_adjust) << (linedbl ? 1 : 0); - if (tmp != max_ypos_thisframe) { - last_max_ypos = tmp; - if (last_max_ypos < 0) - last_max_ypos = 0; - } - max_ypos_thisframe = tmp; - - /* @@@ interlace_seen used to be (bplcon0 & 4), but this is probably - * better. */ - if (prev_x_adjust != visible_left_border || prev_y_adjust != thisframe_y_adjust) - frame_redraw_necessary |= (interlace_seen > 0 && linedbl) ? 2 : 1; - - max_diwstop = 0; - min_diwstart = 10000; + if (thisframe_y_adjust + max_drawn_amiga_line > 2 * maxvpos_max) + thisframe_y_adjust = 2 * maxvpos_max - max_drawn_amiga_line; + if (thisframe_y_adjust < 0) + thisframe_y_adjust = 0; + } else { + /* Make sure the value makes sense */ + if (thisframe_y_adjust + max_drawn_amiga_line > maxvpos_max) + thisframe_y_adjust = maxvpos_max - max_drawn_amiga_line; + if (thisframe_y_adjust < minfirstline) + thisframe_y_adjust = minfirstline; + } + thisframe_y_adjust_real = thisframe_y_adjust << (linedbl ? 1 : 0); + tmp = (maxvpos_max - thisframe_y_adjust) << (linedbl ? 1 : 0); + if (tmp != max_ypos_thisframe) { + last_max_ypos = tmp; + if (last_max_ypos < 0) + last_max_ypos = 0; + } + max_ypos_thisframe = tmp; + + /* @@@ interlace_seen used to be (bplcon0 & 4), but this is probably + * better. */ + if (prev_x_adjust != visible_left_border || prev_y_adjust != thisframe_y_adjust) + frame_redraw_necessary |= (interlace_seen > 0 && linedbl) ? 2 : 1; + + max_diwstop = 0; + min_diwstart = 10000; } #define FRAMES_UNTIL_RES_SWITCH 5 static int frame_res_cnt; static void init_drawing_frame (void) { - int i, maxline; - static int frame_res_old; - - if (FRAMES_UNTIL_RES_SWITCH > 0 && frame_res_old == frame_res * 2 + frame_res_lace) { - frame_res_cnt--; - if (frame_res_cnt == 0) { - int m = frame_res * 2 + frame_res_lace; - struct wh *dst = currprefs.gfx_afullscreen ? &changed_prefs.gfx_size_fs : &changed_prefs.gfx_size_win; - while (m < 4) { - struct wh *src = currprefs.gfx_afullscreen ? &currprefs.gfx_size_fs_xtra[m] : &currprefs.gfx_size_win_xtra[m]; - if ((src->width > 0 && src->height > 0) || (currprefs.gfx_autoresolution && currprefs.gfx_filter > 0)) { - changed_prefs.gfx_resolution = (m & 2) == 0 ? 0 : 1; - changed_prefs.gfx_linedbl = (m & 1) == 0 ? 0 : 1; - if (currprefs.gfx_autoresolution) { - changed_prefs.gfx_filter_horiz_zoom_mult = 1000 >> changed_prefs.gfx_resolution; - changed_prefs.gfx_filter_vert_zoom_mult = (changed_prefs.gfx_linedbl + 1) * 500; - } else { - *dst = *src; - } - break; + int i, maxline; + static int frame_res_old; + + if (FRAMES_UNTIL_RES_SWITCH > 0 && frame_res_old == frame_res * 2 + frame_res_lace) { + frame_res_cnt--; + if (frame_res_cnt == 0) { + int m = frame_res * 2 + frame_res_lace; + struct wh *dst = currprefs.gfx_afullscreen ? &changed_prefs.gfx_size_fs : &changed_prefs.gfx_size_win; + while (m < 4) { + struct wh *src = currprefs.gfx_afullscreen ? &currprefs.gfx_size_fs_xtra[m] : &currprefs.gfx_size_win_xtra[m]; + if ((src->width > 0 && src->height > 0) || (currprefs.gfx_autoresolution && currprefs.gfx_filter > 0)) { + changed_prefs.gfx_resolution = (m & 2) == 0 ? 0 : 1; + changed_prefs.gfx_linedbl = (m & 1) == 0 ? 0 : 1; + if (currprefs.gfx_autoresolution) { + changed_prefs.gfx_filter_horiz_zoom_mult = 1000 >> changed_prefs.gfx_resolution; + changed_prefs.gfx_filter_vert_zoom_mult = (changed_prefs.gfx_linedbl + 1) * 500; + } else { + *dst = *src; + } + break; + } + m++; + } + frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; } - m++; - } - frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; + } else { + frame_res_old = frame_res * 2 + frame_res_lace; + frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; } - } else { - frame_res_old = frame_res * 2 + frame_res_lace; - frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; - } - frame_res = 0; - frame_res_lace = 0; - - if (can_use_lores > AUTO_LORES_FRAMES && 0) { - lores_factor = 1; - lores_shift = 0; - } else { - can_use_lores++; - lores_reset (); - } + frame_res = 0; + frame_res_lace = 0; - init_hardware_for_drawing_frame (); + if (can_use_lores > AUTO_LORES_FRAMES && 0) { + lores_factor = 1; + lores_shift = 0; + } else { + can_use_lores++; + lores_reset (); + } - if (thisframe_first_drawn_line == -1) - thisframe_first_drawn_line = minfirstline; - if (thisframe_first_drawn_line > thisframe_last_drawn_line) - thisframe_last_drawn_line = thisframe_first_drawn_line; + init_hardware_for_drawing_frame (); - maxline = linedbl ? (maxvpos_max + 1) * 2 + 1 : (maxvpos_max + 1) + 1; - maxline++; + if (thisframe_first_drawn_line == -1) + thisframe_first_drawn_line = minfirstline; + if (thisframe_first_drawn_line > thisframe_last_drawn_line) + thisframe_last_drawn_line = thisframe_first_drawn_line; + + maxline = linedbl ? (maxvpos_max + 1) * 2 + 1 : (maxvpos_max + 1) + 1; + maxline++; #ifdef SMART_UPDATE - for (i = 0; i < maxline; i++) { - switch (linestate[i]) { - case LINE_DONE_AS_PREVIOUS: - linestate[i] = LINE_REMEMBERED_AS_PREVIOUS; - break; - case LINE_REMEMBERED_AS_BLACK: - break; - default: - linestate[i] = LINE_UNDECIDED; - break; - } - } + for (i = 0; i < maxline; i++) { + switch (linestate[i]) { + case LINE_DONE_AS_PREVIOUS: + linestate[i] = LINE_REMEMBERED_AS_PREVIOUS; + break; + case LINE_REMEMBERED_AS_BLACK: + break; + default: + linestate[i] = LINE_UNDECIDED; + break; + } + } #else - memset (linestate, LINE_UNDECIDED, maxline); + memset (linestate, LINE_UNDECIDED, maxline); #endif - last_drawn_line = 0; - first_drawn_line = 32767; + last_drawn_line = 0; + first_drawn_line = 32767; - first_block_line = last_block_line = NO_BLOCK; - if (currprefs.test_drawing_speed) - frame_redraw_necessary = 1; - else if (frame_redraw_necessary) - frame_redraw_necessary--; + first_block_line = last_block_line = NO_BLOCK; + if (currprefs.test_drawing_speed) + frame_redraw_necessary = 1; + else if (frame_redraw_necessary) + frame_redraw_necessary--; - center_image (); + center_image (); - thisframe_first_drawn_line = -1; - thisframe_last_drawn_line = -1; + thisframe_first_drawn_line = -1; + thisframe_last_drawn_line = -1; - drawing_color_matches = -1; - seen_sprites = -1; + drawing_color_matches = -1; + seen_sprites = -1; } /* - * Some code to put status information on the screen. - */ +* Some code to put status information on the screen. +*/ static const char *numbers = { /* ugly 0123456789CHD%+- */ -"+++++++--++++-+++++++++++++++++-++++++++++++++++++++++++++++++++++++++++++++-++++++-++++----++---+--------------" -"+xxxxx+--+xx+-+xxxxx++xxxxx++x+-+x++xxxxx++xxxxx++xxxxx++xxxxx++xxxxx++xxxx+-+x++x+-+xxx++-+xx+-+x---+----------" -"+x+++x+--++x+-+++++x++++++x++x+++x++x++++++x++++++++++x++x+++x++x+++x++x++++-+x++x+-+x++x+--+x++x+--+x+----+++--" -"+x+-+x+---+x+-+xxxxx++xxxxx++xxxxx++xxxxx++xxxxx+--++x+-+xxxxx++xxxxx++x+----+xxxx+-+x++x+----+x+--+xxx+--+xxx+-" -"+x+++x+---+x+-+x++++++++++x++++++x++++++x++x+++x+--+x+--+x+++x++++++x++x++++-+x++x+-+x++x+---+x+x+--+x+----+++--" -"+xxxxx+---+x+-+xxxxx++xxxxx+----+x++xxxxx++xxxxx+--+x+--+xxxxx++xxxxx++xxxx+-+x++x+-+xxx+---+x++xx--------------" -"+++++++---+++-++++++++++++++----+++++++++++++++++--+++--++++++++++++++++++++-++++++-++++------------------------" + "+++++++--++++-+++++++++++++++++-++++++++++++++++++++++++++++++++++++++++++++-++++++-++++----++---+--------------" + "+xxxxx+--+xx+-+xxxxx++xxxxx++x+-+x++xxxxx++xxxxx++xxxxx++xxxxx++xxxxx++xxxx+-+x++x+-+xxx++-+xx+-+x---+----------" + "+x+++x+--++x+-+++++x++++++x++x+++x++x++++++x++++++++++x++x+++x++x+++x++x++++-+x++x+-+x++x+--+x++x+--+x+----+++--" + "+x+-+x+---+x+-+xxxxx++xxxxx++xxxxx++xxxxx++xxxxx+--++x+-+xxxxx++xxxxx++x+----+xxxx+-+x++x+----+x+--+xxx+--+xxx+-" + "+x+++x+---+x+-+x++++++++++x++++++x++++++x++x+++x+--+x+--+x+++x++++++x++x++++-+x++x+-+x++x+---+x+x+--+x+----+++--" + "+xxxxx+---+x+-+xxxxx++xxxxx+----+x++xxxxx++xxxxx+--+x+--+xxxxx++xxxxx++xxxx+-+x++x+-+xxx+---+x++xx--------------" + "+++++++---+++-++++++++++++++----+++++++++++++++++--+++--++++++++++++++++++++-++++++-++++------------------------" }; STATIC_INLINE void putpixel (uae_u8 *buf, int bpp, int x, xcolnr c8, int opaq) { - if (x <= 0) - return; + if (x <= 0) + return; - switch (bpp) { - case 1: - buf[x] = (uae_u8)c8; - break; - case 2: - { - uae_u16 *p = (uae_u16*)buf + x; - *p = (uae_u16)c8; - break; - } - case 3: - /* no 24 bit yet */ - break; - case 4: - { - int i; - if (1 || opaq || currprefs.gfx_filter == 0) { - uae_u32 *p = (uae_u32*)buf + x; - *p = c8; - } else { - for (i = 0; i < 4; i++) { - int v1 = buf[i + bpp * x]; - int v2 = (c8 >> (i * 8)) & 255; - v1 = (v1 * 2 + v2 * 3) / 5; - if (v1 > 255) - v1 = 255; - buf[i + bpp * x] = v1; - } + switch (bpp) { + case 1: + buf[x] = (uae_u8)c8; + break; + case 2: + { + uae_u16 *p = (uae_u16*)buf + x; + *p = (uae_u16)c8; + break; + } + case 3: + /* no 24 bit yet */ + break; + case 4: + { + int i; + if (1 || opaq || currprefs.gfx_filter == 0) { + uae_u32 *p = (uae_u32*)buf + x; + *p = c8; + } else { + for (i = 0; i < 4; i++) { + int v1 = buf[i + bpp * x]; + int v2 = (c8 >> (i * 8)) & 255; + v1 = (v1 * 2 + v2 * 3) / 5; + if (v1 > 255) + v1 = 255; + buf[i + bpp * x] = v1; + } + } + break; + } } - break; - } - } } STATIC_INLINE uae_u32 ledcolor (uae_u32 c, uae_u32 *rc, uae_u32 *gc, uae_u32 *bc, uae_u32 *a) { - uae_u32 v = rc[(c >> 16) & 0xff] | gc[(c >> 8) & 0xff] | bc[(c >> 0) & 0xff]; - if (a) - v |= a[255 - ((c >> 24) & 0xff)]; - return v; + uae_u32 v = rc[(c >> 16) & 0xff] | gc[(c >> 8) & 0xff] | bc[(c >> 0) & 0xff]; + if (a) + v |= a[255 - ((c >> 24) & 0xff)]; + return v; } static void write_tdnumber (uae_u8 *buf, int bpp, int x, int y, int num, uae_u32 c1, uae_u32 c2) { - int j; - const char *numptr; - - numptr = numbers + num * TD_NUM_WIDTH + NUMBERS_NUM * TD_NUM_WIDTH * y; - for (j = 0; j < TD_NUM_WIDTH; j++) { - if (*numptr == 'x') - putpixel (buf, bpp, x + j, c1, 1); - else if (*numptr == '+') - putpixel (buf, bpp, x + j, c2, 0); - numptr++; - } + int j; + const char *numptr; + + numptr = numbers + num * TD_NUM_WIDTH + NUMBERS_NUM * TD_NUM_WIDTH * y; + for (j = 0; j < TD_NUM_WIDTH; j++) { + if (*numptr == 'x') + putpixel (buf, bpp, x + j, c1, 1); + else if (*numptr == '+') + putpixel (buf, bpp, x + j, c2, 0); + numptr++; + } } void draw_status_line_single (uae_u8 *buf, int bpp, int y, int totalwidth, uae_u32 *rc, uae_u32 *gc, uae_u32 *bc, uae_u32 *alpha) { - int x_start, j, led, border; - uae_u32 c1, c2, cb; - - c1 = ledcolor (0x00ffffff, rc, gc, bc, alpha); - c2 = ledcolor (0x00000000, rc, gc, bc, alpha); - cb = ledcolor (TD_BORDER, rc, gc, bc, alpha); - - if (td_pos & TD_RIGHT) - x_start = totalwidth - TD_PADX - NUM_LEDS * TD_WIDTH; - else - x_start = TD_PADX; - - for (led = 0; led < NUM_LEDS; led++) { - int side, pos, num1 = -1, num2 = -1, num3 = -1, num4 = -1; - int x, c, on = 0, am = 2; - xcolnr on_rgb, off_rgb; - - if (led >= 1 && led <= 4) { - int pled = led - 1; - int track = gui_data.drive_track[pled]; - pos = 6 + pled; - on_rgb = 0x00cc00; - off_rgb = 0x003300; - if (!gui_data.drive_disabled[pled]) { - num1 = -1; - num2 = track / 10; - num3 = track % 10; - on = gui_data.drive_motor[pled]; - if (gui_data.drive_writing[pled]) - on_rgb = 0xcc0000; - } - side = gui_data.drive_side; - } else if (led == 0) { - pos = 3; - //on = gui_data.powerled_brightness > 0; - on_rgb = ((gui_data.powerled_brightness * 10 / 16) + 0x33) << 16; - on = gui_data.powerled; - //on_rgb = 0xcc0000; - off_rgb = 0x330000; - } else if (led == 5) { - pos = 5; - on = gui_data.cd & (LED_CD_AUDIO | LED_CD_ACTIVE); - on_rgb = (on & LED_CD_AUDIO) ? 0x00cc00 : 0x0000cc; - if ((gui_data.cd & LED_CD_ACTIVE2) && !(gui_data.cd & LED_CD_AUDIO)) { - on_rgb &= 0xfefefe; - on_rgb >>= 1; - } - off_rgb = 0x000033; - num1 = -1; - num2 = 10; - num3 = 12; - } else if (led == 6) { - pos = 4; - on = gui_data.hd; - on_rgb = on == 2 ? 0xcc0000 : 0x0000cc; - off_rgb = 0x000033; - num1 = -1; - num2 = 11; - num3 = 12; - } else if (led == 7) { - int fps = (gui_data.fps + 5) / 10; - pos = 2; - on_rgb = 0x000000; - off_rgb = 0x000000; - if (fps > 999) - fps = 999; - num1 = fps / 100; - num2 = (fps - num1 * 100) / 10; - num3 = fps % 10; - am = 3; - if (num1 == 0) - am = 2; - } else if (led == 8) { - int idle = (gui_data.idle + 5) / 10; - pos = 1; - on = framecnt && !picasso_on; - on_rgb = 0xcc0000; - off_rgb = 0x000000; - num1 = idle / 100; - num2 = (idle - num1 * 100) / 10; - num3 = idle % 10; - num4 = num1 == 0 ? 13 : -1; - am = 3; - } else if (led == 9) { - int snd = abs(gui_data.sndbuf + 5) / 10; - if (snd > 99) - snd = 99; - pos = 0; - on = gui_data.sndbuf_status; - if (on < 3) { - num1 = gui_data.sndbuf < 0 ? 15 : 14; - num2 = snd / 10; - num3 = snd % 10; - } - on_rgb = 0x000000; - if (on < 0) - on_rgb = 0xcccc00; // underflow - else if (on == 2) - on_rgb = 0xcc0000; // really big overflow - else if (on == 1) - on_rgb = 0x0000cc; // "normal" overflow - off_rgb = 0x000000; - am = 3; - } - on_rgb |= 0x33000000; - off_rgb |= 0x33000000; - c = ledcolor (on ? on_rgb : off_rgb, rc, gc, bc, alpha); - border = 0; - if (y == 0 || y == TD_TOTAL_HEIGHT - 1) { - c = ledcolor (TD_BORDER, rc, gc, bc, alpha); - border = 1; - } - - x = x_start + pos * TD_WIDTH; - if (!border) - putpixel (buf, bpp, x - 1, cb, 0); - for (j = 0; j < TD_LED_WIDTH; j++) - putpixel (buf, bpp, x + j, c, 0); - if (!border) - putpixel (buf, bpp, x + j, cb, 0); - - if (y >= TD_PADY && y - TD_PADY < TD_NUM_HEIGHT) { - if (num3 >= 0) { - x += (TD_LED_WIDTH - am * TD_NUM_WIDTH) / 2; - if (num1 > 0) { - write_tdnumber (buf, bpp, x, y - TD_PADY, num1, c1, c2); - x += TD_NUM_WIDTH; + int x_start, j, led, border; + uae_u32 c1, c2, cb; + + c1 = ledcolor (0x00ffffff, rc, gc, bc, alpha); + c2 = ledcolor (0x00000000, rc, gc, bc, alpha); + cb = ledcolor (TD_BORDER, rc, gc, bc, alpha); + + if (td_pos & TD_RIGHT) + x_start = totalwidth - TD_PADX - NUM_LEDS * TD_WIDTH; + else + x_start = TD_PADX; + + for (led = 0; led < NUM_LEDS; led++) { + int side, pos, num1 = -1, num2 = -1, num3 = -1, num4 = -1; + int x, c, on = 0, am = 2; + xcolnr on_rgb, on_rgb2, off_rgb, pen_rgb; + int half = 0; + + pen_rgb = c1; + if (led >= 1 && led <= 4) { + int pled = led - 1; + int track = gui_data.drive_track[pled]; + pos = 6 + pled; + on_rgb = 0x00cc00; + on_rgb2 = 0x006600; + off_rgb = 0x003300; + if (!gui_data.drive_disabled[pled]) { + num1 = -1; + num2 = track / 10; + num3 = track % 10; + on = gui_data.drive_motor[pled]; + if (gui_data.drive_writing[pled]) { + on_rgb = 0xcc0000; + on_rgb2 = 0x880000; + } + half = gui_data.drive_side ? 1 : -1; + if (gui_data.df[pled][0] == 0) + pen_rgb = ledcolor (0x00aaaaaa, rc, gc, bc, alpha); + } + side = gui_data.drive_side; + } else if (led == 0) { + pos = 3; + //on = gui_data.powerled_brightness > 0; + on_rgb = ((gui_data.powerled_brightness * 10 / 16) + 0x33) << 16; + on = gui_data.powerled; + //on_rgb = 0xcc0000; + off_rgb = 0x330000; + } else if (led == 5) { + pos = 5; + on = gui_data.cd & (LED_CD_AUDIO | LED_CD_ACTIVE); + on_rgb = (on & LED_CD_AUDIO) ? 0x00cc00 : 0x0000cc; + if ((gui_data.cd & LED_CD_ACTIVE2) && !(gui_data.cd & LED_CD_AUDIO)) { + on_rgb &= 0xfefefe; + on_rgb >>= 1; + } + off_rgb = 0x000033; + num1 = -1; + num2 = 10; + num3 = 12; + } else if (led == 6) { + pos = 4; + on = gui_data.hd; + on_rgb = on == 2 ? 0xcc0000 : 0x0000cc; + off_rgb = 0x000033; + num1 = -1; + num2 = 11; + num3 = 12; + } else if (led == 7) { + int fps = (gui_data.fps + 5) / 10; + pos = 2; + on_rgb = 0x000000; + off_rgb = 0x000000; + if (fps > 999) + fps = 999; + num1 = fps / 100; + num2 = (fps - num1 * 100) / 10; + num3 = fps % 10; + am = 3; + if (num1 == 0) + am = 2; + } else if (led == 8) { + int idle = (gui_data.idle + 5) / 10; + pos = 1; + on = framecnt && !picasso_on; + on_rgb = 0xcc0000; + off_rgb = 0x000000; + num1 = idle / 100; + num2 = (idle - num1 * 100) / 10; + num3 = idle % 10; + num4 = num1 == 0 ? 13 : -1; + am = 3; + } else if (led == 9) { + int snd = abs(gui_data.sndbuf + 5) / 10; + if (snd > 99) + snd = 99; + pos = 0; + on = gui_data.sndbuf_status; + if (on < 3) { + num1 = gui_data.sndbuf < 0 ? 15 : 14; + num2 = snd / 10; + num3 = snd % 10; + } + on_rgb = 0x000000; + if (on < 0) + on_rgb = 0xcccc00; // underflow + else if (on == 2) + on_rgb = 0xcc0000; // really big overflow + else if (on == 1) + on_rgb = 0x0000cc; // "normal" overflow + off_rgb = 0x000000; + am = 3; + } + on_rgb |= 0x33000000; + off_rgb |= 0x33000000; + if (half > 0) { + c = ledcolor (on ? (y > TD_TOTAL_HEIGHT / 2 ? on_rgb2 : on_rgb) : off_rgb, rc, gc, bc, alpha); + } else if (half < 0) { + c = ledcolor (on ? (y <= TD_TOTAL_HEIGHT / 2 ? on_rgb2 : on_rgb) : off_rgb, rc, gc, bc, alpha); + } else { + c = ledcolor (on ? on_rgb : off_rgb, rc, gc, bc, alpha); + } + border = 0; + if (y == 0 || y == TD_TOTAL_HEIGHT - 1) { + c = ledcolor (TD_BORDER, rc, gc, bc, alpha); + border = 1; + } + + x = x_start + pos * TD_WIDTH; + if (!border) + putpixel (buf, bpp, x - 1, cb, 0); + for (j = 0; j < TD_LED_WIDTH; j++) + putpixel (buf, bpp, x + j, c, 0); + if (!border) + putpixel (buf, bpp, x + j, cb, 0); + + if (y >= TD_PADY && y - TD_PADY < TD_NUM_HEIGHT) { + if (num3 >= 0) { + x += (TD_LED_WIDTH - am * TD_NUM_WIDTH) / 2; + if (num1 > 0) { + write_tdnumber (buf, bpp, x, y - TD_PADY, num1, pen_rgb, c2); + x += TD_NUM_WIDTH; + } + write_tdnumber (buf, bpp, x, y - TD_PADY, num2, pen_rgb, c2); + x += TD_NUM_WIDTH; + write_tdnumber (buf, bpp, x, y - TD_PADY, num3, pen_rgb, c2); + x += TD_NUM_WIDTH; + if (num4 > 0) + write_tdnumber (buf, bpp, x, y - TD_PADY, num4, pen_rgb, c2); + } } - write_tdnumber (buf, bpp, x, y - TD_PADY, num2, c1, c2); - x += TD_NUM_WIDTH; - write_tdnumber (buf, bpp, x, y - TD_PADY, num3, c1, c2); - x += TD_NUM_WIDTH; - if (num4 > 0) - write_tdnumber (buf, bpp, x, y - TD_PADY, num4, c1, c2); - } } - } } static void draw_status_line (int line) { - int bpp, y; - uae_u8 *buf; + int bpp, y; + uae_u8 *buf; - if (!(currprefs.leds_on_screen & STATUSLINE_CHIPSET) || (currprefs.leds_on_screen & STATUSLINE_TARGET)) - return; - bpp = gfxvidinfo.pixbytes; - y = line - (gfxvidinfo.height - TD_TOTAL_HEIGHT); - xlinebuffer = gfxvidinfo.linemem; - if (xlinebuffer == 0) - xlinebuffer = row_map[line]; - buf = xlinebuffer; - draw_status_line_single (buf, bpp, y, gfxvidinfo.width, xredcolors, xgreencolors, xbluecolors, NULL); + if (!(currprefs.leds_on_screen & STATUSLINE_CHIPSET) || (currprefs.leds_on_screen & STATUSLINE_TARGET)) + return; + bpp = gfxvidinfo.pixbytes; + y = line - (gfxvidinfo.height - TD_TOTAL_HEIGHT); + xlinebuffer = gfxvidinfo.linemem; + if (xlinebuffer == 0) + xlinebuffer = row_map[line]; + buf = xlinebuffer; + draw_status_line_single (buf, bpp, y, gfxvidinfo.width, xredcolors, xgreencolors, xbluecolors, NULL); } static void draw_debug_status_line (int line) { - xlinebuffer = gfxvidinfo.linemem; - if (xlinebuffer == 0) - xlinebuffer = row_map[line]; - debug_draw_cycles (xlinebuffer, gfxvidinfo.pixbytes, line, gfxvidinfo.width, gfxvidinfo.height, xredcolors, xgreencolors, xbluecolors); + xlinebuffer = gfxvidinfo.linemem; + if (xlinebuffer == 0) + xlinebuffer = row_map[line]; + debug_draw_cycles (xlinebuffer, gfxvidinfo.pixbytes, line, gfxvidinfo.width, gfxvidinfo.height, xredcolors, xgreencolors, xbluecolors); } #define LIGHTPEN_HEIGHT 12 #define LIGHTPEN_WIDTH 17 static const char *lightpen_cursor = { - "------.....------" - "------.xxx.------" - "------.xxx.------" - "------.xxx.------" - ".......xxx......." - ".xxxxxxxxxxxxxxx." - ".xxxxxxxxxxxxxxx." - ".......xxx......." - "------.xxx.------" - "------.xxx.------" - "------.xxx.------" - "------.....------" + "------.....------" + "------.xxx.------" + "------.xxx.------" + "------.xxx.------" + ".......xxx......." + ".xxxxxxxxxxxxxxx." + ".xxxxxxxxxxxxxxx." + ".......xxx......." + "------.xxx.------" + "------.xxx.------" + "------.xxx.------" + "------.....------" }; static void draw_lightpen_cursor (int x, int y, int line, int onscreen) { - int i; - const char *p; - int color1 = onscreen ? 0xff0 : 0xf00; - int color2 = 0x000; - - xlinebuffer = gfxvidinfo.linemem; - if (xlinebuffer == 0) - xlinebuffer = row_map[line]; + int i; + const char *p; + int color1 = onscreen ? 0xff0 : 0xf00; + int color2 = 0x000; - p = lightpen_cursor + y * LIGHTPEN_WIDTH; - for (i = 0; i < LIGHTPEN_WIDTH; i++) { - int xx = x + i - LIGHTPEN_WIDTH / 2; - if (*p != '-' && xx >= 0 && xx < gfxvidinfo.width) - putpixel(xlinebuffer, gfxvidinfo.pixbytes, xx, *p == 'x' ? xcolors[color1] : xcolors[color2], 1); - p++; - } + xlinebuffer = gfxvidinfo.linemem; + if (xlinebuffer == 0) + xlinebuffer = row_map[line]; + + p = lightpen_cursor + y * LIGHTPEN_WIDTH; + for (i = 0; i < LIGHTPEN_WIDTH; i++) { + int xx = x + i - LIGHTPEN_WIDTH / 2; + if (*p != '-' && xx >= 0 && xx < gfxvidinfo.width) + putpixel(xlinebuffer, gfxvidinfo.pixbytes, xx, *p == 'x' ? xcolors[color1] : xcolors[color2], 1); + p++; + } } static int lightpen_y1, lightpen_y2; static void lightpen_update (void) { - int i; - - if (lightpen_x < LIGHTPEN_WIDTH + 1) - lightpen_x = LIGHTPEN_WIDTH + 1; - if (lightpen_x >= gfxvidinfo.width - LIGHTPEN_WIDTH - 1) - lightpen_x = gfxvidinfo.width - LIGHTPEN_WIDTH - 2; - if (lightpen_y < LIGHTPEN_HEIGHT + 1) - lightpen_y = LIGHTPEN_HEIGHT + 1; - if (lightpen_y >= gfxvidinfo.height - LIGHTPEN_HEIGHT - 1) - lightpen_y = gfxvidinfo.height - LIGHTPEN_HEIGHT - 2; - if (lightpen_y >= max_ypos_thisframe - LIGHTPEN_HEIGHT - 1) - lightpen_y = max_ypos_thisframe - LIGHTPEN_HEIGHT - 2; - - lightpen_cx = (((lightpen_x + visible_left_border) >> lores_shift) >> 1) + DISPLAY_LEFT_SHIFT - DIW_DDF_OFFSET; - - lightpen_cy = lightpen_y; - if (linedbl) - lightpen_cy >>= 1; - lightpen_cy += minfirstline; - - if (lightpen_cx < 0x18) - lightpen_cx = 0x18; - if (lightpen_cx >= maxhpos) - lightpen_cx -= maxhpos; - if (lightpen_cy < minfirstline) - lightpen_cy = minfirstline; - if (lightpen_cy >= maxvpos_max) - lightpen_cy = maxvpos_max - 1; - - for (i = 0; i < LIGHTPEN_HEIGHT; i++) { - int line = lightpen_y + i - LIGHTPEN_HEIGHT / 2; - if (line >= 0 || line < max_ypos_thisframe) { - draw_lightpen_cursor(lightpen_x, i, line, lightpen_cx > 0); - flush_line (line); - } - } - lightpen_y1 = lightpen_y - LIGHTPEN_HEIGHT / 2 - 1 + min_ypos_for_screen; - lightpen_y2 = lightpen_y1 + LIGHTPEN_HEIGHT + 2; + int i; + + if (lightpen_x < LIGHTPEN_WIDTH + 1) + lightpen_x = LIGHTPEN_WIDTH + 1; + if (lightpen_x >= gfxvidinfo.width - LIGHTPEN_WIDTH - 1) + lightpen_x = gfxvidinfo.width - LIGHTPEN_WIDTH - 2; + if (lightpen_y < LIGHTPEN_HEIGHT + 1) + lightpen_y = LIGHTPEN_HEIGHT + 1; + if (lightpen_y >= gfxvidinfo.height - LIGHTPEN_HEIGHT - 1) + lightpen_y = gfxvidinfo.height - LIGHTPEN_HEIGHT - 2; + if (lightpen_y >= max_ypos_thisframe - LIGHTPEN_HEIGHT - 1) + lightpen_y = max_ypos_thisframe - LIGHTPEN_HEIGHT - 2; + + lightpen_cx = (((lightpen_x + visible_left_border) >> lores_shift) >> 1) + DISPLAY_LEFT_SHIFT - DIW_DDF_OFFSET; + + lightpen_cy = lightpen_y; + if (linedbl) + lightpen_cy >>= 1; + lightpen_cy += minfirstline; + + if (lightpen_cx < 0x18) + lightpen_cx = 0x18; + if (lightpen_cx >= maxhpos) + lightpen_cx -= maxhpos; + if (lightpen_cy < minfirstline) + lightpen_cy = minfirstline; + if (lightpen_cy >= maxvpos_max) + lightpen_cy = maxvpos_max - 1; + + for (i = 0; i < LIGHTPEN_HEIGHT; i++) { + int line = lightpen_y + i - LIGHTPEN_HEIGHT / 2; + if (line >= 0 || line < max_ypos_thisframe) { + draw_lightpen_cursor(lightpen_x, i, line, lightpen_cx > 0); + flush_line (line); + } + } + lightpen_y1 = lightpen_y - LIGHTPEN_HEIGHT / 2 - 1 + min_ypos_for_screen; + lightpen_y2 = lightpen_y1 + LIGHTPEN_HEIGHT + 2; } void finish_drawing_frame (void) { - int i; + int i; - if (! lockscr ()) { - notice_screen_contents_lost (); - return; - } + if (! lockscr ()) { + notice_screen_contents_lost (); + return; + } #ifndef SMART_UPDATE - /* @@@ This isn't exactly right yet. FIXME */ - if (!interlace_seen) - do_flush_screen (first_drawn_line, last_drawn_line); - else - unlockscr (); - return; + /* @@@ This isn't exactly right yet. FIXME */ + if (!interlace_seen) + do_flush_screen (first_drawn_line, last_drawn_line); + else + unlockscr (); + return; #endif - for (i = 0; i < max_ypos_thisframe; i++) { - int i1 = i + min_ypos_for_screen; - int line = i + thisframe_y_adjust_real; - int where2; - - if (linestate[line] == LINE_UNDECIDED) - break; - - where2 = amiga2aspect_line_map[i1]; - if (where2 >= gfxvidinfo.height) - break; - if (where2 < 0) - continue; - - pfield_draw_line (line, where2, amiga2aspect_line_map[i1 + 1]); - } - - /* clear possible old garbage at the bottom if emulated area become smaller */ - for (i = last_max_ypos; i < gfxvidinfo.height; i++) { - int i1 = i + min_ypos_for_screen; - int line = i + thisframe_y_adjust_real; - int where2 = amiga2aspect_line_map[i1]; - xcolnr tmp; - - if (where2 >= gfxvidinfo.height) - break; - if (where2 < 0) - continue; - tmp = colors_for_drawing.acolors[0]; - colors_for_drawing.acolors[0] = getxcolor (0); - xlinebuffer = gfxvidinfo.linemem; - if (xlinebuffer == 0) - xlinebuffer = row_map[where2]; - xlinebuffer -= linetoscr_x_adjust_bytes; - fill_line (); - linestate[line] = LINE_UNDECIDED; - do_flush_line (where2); - colors_for_drawing.acolors[0] = tmp; - } + for (i = 0; i < max_ypos_thisframe; i++) { + int i1 = i + min_ypos_for_screen; + int line = i + thisframe_y_adjust_real; + int where2; + + if (linestate[line] == LINE_UNDECIDED) + break; + + where2 = amiga2aspect_line_map[i1]; + if (where2 >= gfxvidinfo.height) + break; + if (where2 < 0) + continue; + + pfield_draw_line (line, where2, amiga2aspect_line_map[i1 + 1]); + } - if (currprefs.leds_on_screen) { - for (i = 0; i < TD_TOTAL_HEIGHT; i++) { - int line = gfxvidinfo.height - TD_TOTAL_HEIGHT + i; - draw_status_line (line); - do_flush_line (line); + /* clear possible old garbage at the bottom if emulated area become smaller */ + for (i = last_max_ypos; i < gfxvidinfo.height; i++) { + int i1 = i + min_ypos_for_screen; + int line = i + thisframe_y_adjust_real; + int where2 = amiga2aspect_line_map[i1]; + xcolnr tmp; + + if (where2 >= gfxvidinfo.height) + break; + if (where2 < 0) + continue; + tmp = colors_for_drawing.acolors[0]; + colors_for_drawing.acolors[0] = getxcolor (0); + xlinebuffer = gfxvidinfo.linemem; + if (xlinebuffer == 0) + xlinebuffer = row_map[where2]; + xlinebuffer -= linetoscr_x_adjust_bytes; + fill_line (); + linestate[line] = LINE_UNDECIDED; + do_flush_line (where2); + colors_for_drawing.acolors[0] = tmp; } - } - if (debug_dma > 1) { - for (i = 0; i < gfxvidinfo.height; i++) { - int line = i; - draw_debug_status_line (line); - do_flush_line (line); + + if (currprefs.leds_on_screen) { + for (i = 0; i < TD_TOTAL_HEIGHT; i++) { + int line = gfxvidinfo.height - TD_TOTAL_HEIGHT + i; + draw_status_line (line); + do_flush_line (line); + } + } + if (debug_dma > 1) { + for (i = 0; i < gfxvidinfo.height; i++) { + int line = i; + draw_debug_status_line (line); + do_flush_line (line); + } } - } - if (lightpen_x > 0 || lightpen_y > 0) - lightpen_update (); + if (lightpen_x > 0 || lightpen_y > 0) + lightpen_update (); - do_flush_screen (first_drawn_line, last_drawn_line); + do_flush_screen (first_drawn_line, last_drawn_line); #ifdef ECS_DENISE - if (brdblank_changed) { - last_max_ypos = max_ypos_thisframe; - notice_screen_contents_lost (); - brdblank_changed = 0; - } + if (brdblank_changed) { + last_max_ypos = max_ypos_thisframe; + notice_screen_contents_lost (); + brdblank_changed = 0; + } #endif } void hardware_line_completed (int lineno) { #ifndef SMART_UPDATE - { - int i, where; - /* l is the line that has been finished for drawing. */ - i = lineno - thisframe_y_adjust_real; - if (i >= 0 && i < max_ypos_thisframe) { - where = amiga2aspect_line_map[i+min_ypos_for_screen]; - if (where < gfxvidinfo.height && where != -1) - pfield_draw_line (lineno, where, amiga2aspect_line_map[i+min_ypos_for_screen+1]); - } - } + { + int i, where; + /* l is the line that has been finished for drawing. */ + i = lineno - thisframe_y_adjust_real; + if (i >= 0 && i < max_ypos_thisframe) { + where = amiga2aspect_line_map[i+min_ypos_for_screen]; + if (where < gfxvidinfo.height && where != -1) + pfield_draw_line (lineno, where, amiga2aspect_line_map[i+min_ypos_for_screen+1]); + } + } #endif } STATIC_INLINE void check_picasso (void) { #ifdef PICASSO96 - if (picasso_on && picasso_redraw_necessary) - picasso_refresh (); - picasso_redraw_necessary = 0; + if (picasso_on && picasso_redraw_necessary) + picasso_refresh (); + picasso_redraw_necessary = 0; - if (picasso_requested_on == picasso_on) - return; + if (picasso_requested_on == picasso_on) + return; - picasso_on = picasso_requested_on; + picasso_on = picasso_requested_on; - if (!picasso_on) - clear_inhibit_frame (IHF_PICASSO); - else - set_inhibit_frame (IHF_PICASSO); + if (!picasso_on) + clear_inhibit_frame (IHF_PICASSO); + else + set_inhibit_frame (IHF_PICASSO); - gfx_set_picasso_state (picasso_on); - picasso_enablescreen (picasso_requested_on); + gfx_set_picasso_state (picasso_on); + picasso_enablescreen (picasso_requested_on); - notice_screen_contents_lost (); - notice_new_xcolors (); - count_frame (); + notice_screen_contents_lost (); + notice_new_xcolors (); + count_frame (); #endif } void redraw_frame (void) { - last_drawn_line = 0; - first_drawn_line = 32767; - finish_drawing_frame (); - flush_screen (0, 0); + last_drawn_line = 0; + first_drawn_line = 32767; + finish_drawing_frame (); + flush_screen (0, 0); } void vsync_handle_redraw (int long_frame, int lof_changed) { - last_redraw_point++; - if (lof_changed || interlace_seen <= 0 || last_redraw_point >= 2 || long_frame || doublescan < 0) { - last_redraw_point = 0; - - if (framecnt == 0) - finish_drawing_frame (); - if (interlace_seen > 0) { - interlace_seen = -1; - } else if (interlace_seen == -1) { - interlace_seen = 0; - if (currprefs.gfx_scandoubler && currprefs.gfx_linedbl) - notice_screen_contents_lost (); - } + last_redraw_point++; + if (lof_changed || interlace_seen <= 0 || last_redraw_point >= 2 || long_frame || doublescan < 0) { + last_redraw_point = 0; + + if (framecnt == 0) + finish_drawing_frame (); + if (interlace_seen > 0) { + interlace_seen = -1; + } else if (interlace_seen == -1) { + interlace_seen = 0; + if (currprefs.gfx_scandoubler && currprefs.gfx_linedbl) + notice_screen_contents_lost (); + } - /* At this point, we have finished both the hardware and the - * drawing frame. Essentially, we are outside of all loops and - * can do some things which would cause confusion if they were - * done at other times. - */ + /* At this point, we have finished both the hardware and the + * drawing frame. Essentially, we are outside of all loops and + * can do some things which would cause confusion if they were + * done at other times. + */ #ifdef SAVESTATE - if (savestate_state == STATE_DORESTORE) { - savestate_state = STATE_RESTORE; - reset_drawing (); - uae_reset (0); - } else if (savestate_state == STATE_DOREWIND) { - savestate_state = STATE_REWIND; - reset_drawing (); - uae_reset (0); - } + if (savestate_state == STATE_DORESTORE) { + savestate_state = STATE_RESTORE; + reset_drawing (); + uae_reset (0); + } else if (savestate_state == STATE_DOREWIND) { + savestate_state = STATE_REWIND; + reset_drawing (); + uae_reset (0); + } #endif - if (quit_program < 0) { - quit_program = -quit_program; - set_inhibit_frame (IHF_QUIT_PROGRAM); - set_special (SPCFLAG_BRK); - return; - } + if (quit_program < 0) { + quit_program = -quit_program; + set_inhibit_frame (IHF_QUIT_PROGRAM); + set_special (SPCFLAG_BRK); + return; + } #ifdef SAVESTATE - savestate_capture (0); + savestate_capture (0); #endif - count_frame (); - check_picasso (); - - if (check_prefs_changed_gfx ()) { - reset_drawing (); - init_row_map (); - init_aspect_maps (); - notice_screen_contents_lost (); - notice_new_xcolors (); - } - - check_prefs_changed_audio (); - check_prefs_changed_custom (); - check_prefs_changed_cpu (); - - if (framecnt == 0) - init_drawing_frame (); - } else { - if (currprefs.gfx_afullscreen && currprefs.gfx_avsync) - flush_screen (0, 0); /* vsync mode */ - } - gui_hd_led (-1, 0); - gui_cd_led (-1, 0); + count_frame (); + check_picasso (); + + if (check_prefs_changed_gfx ()) { + reset_drawing (); + init_row_map (); + init_aspect_maps (); + notice_screen_contents_lost (); + notice_new_xcolors (); + } + + check_prefs_changed_audio (); + check_prefs_changed_custom (); + check_prefs_changed_cpu (); + + if (framecnt == 0) + init_drawing_frame (); + } else { + if (currprefs.gfx_afullscreen && currprefs.gfx_avsync) + flush_screen (0, 0); /* vsync mode */ + } + gui_hd_led (-1, 0); + gui_cd_led (-1, 0); #ifdef AVIOUTPUT - frame_drawn (); + frame_drawn (); #endif } void hsync_record_line_state (int lineno, enum nln_how how, int changed) { - uae_u8 *state; - - if (framecnt != 0) - return; - - state = linestate + lineno; - changed += frame_redraw_necessary + ((lineno >= lightpen_y1 && lineno <= lightpen_y2) ? 1 : 0); - - switch (how) { - case nln_normal: - *state = changed ? LINE_DECIDED : LINE_DONE; - break; - case nln_doubled: - *state = changed ? LINE_DECIDED_DOUBLE : LINE_DONE; - changed += state[1] != LINE_REMEMBERED_AS_PREVIOUS; - state[1] = changed ? LINE_AS_PREVIOUS : LINE_DONE_AS_PREVIOUS; - break; - case nln_nblack: - *state = changed ? LINE_DECIDED : LINE_DONE; - if (state[1] != LINE_REMEMBERED_AS_BLACK) - state[1] = LINE_BLACK; - break; - case nln_lower: - if (state[-1] == LINE_UNDECIDED) - state[-1] = LINE_BLACK; - *state = changed ? LINE_DECIDED : LINE_DONE; - break; - case nln_upper: - *state = changed ? LINE_DECIDED : LINE_DONE; - if (state[1] == LINE_UNDECIDED - || state[1] == LINE_REMEMBERED_AS_PREVIOUS - || state[1] == LINE_AS_PREVIOUS) - state[1] = LINE_BLACK; - break; - } + uae_u8 *state; + + if (framecnt != 0) + return; + + state = linestate + lineno; + changed += frame_redraw_necessary + ((lineno >= lightpen_y1 && lineno <= lightpen_y2) ? 1 : 0); + + switch (how) { + case nln_normal: + *state = changed ? LINE_DECIDED : LINE_DONE; + break; + case nln_doubled: + *state = changed ? LINE_DECIDED_DOUBLE : LINE_DONE; + changed += state[1] != LINE_REMEMBERED_AS_PREVIOUS; + state[1] = changed ? LINE_AS_PREVIOUS : LINE_DONE_AS_PREVIOUS; + break; + case nln_nblack: + *state = changed ? LINE_DECIDED : LINE_DONE; + if (state[1] != LINE_REMEMBERED_AS_BLACK) + state[1] = LINE_BLACK; + break; + case nln_lower: + if (state[-1] == LINE_UNDECIDED) + state[-1] = LINE_BLACK; + *state = changed ? LINE_DECIDED : LINE_DONE; + break; + case nln_upper: + *state = changed ? LINE_DECIDED : LINE_DONE; + if (state[1] == LINE_UNDECIDED + || state[1] == LINE_REMEMBERED_AS_PREVIOUS + || state[1] == LINE_AS_PREVIOUS) + state[1] = LINE_BLACK; + break; + } } static void dummy_flush_line (struct vidbuf_description *gfxinfo, int line_no) @@ -2960,7 +2974,7 @@ static void dummy_flush_clear_screen (struct vidbuf_description *gfxinfo) static int dummy_lock (struct vidbuf_description *gfxinfo) { - return 1; + return 1; } static void dummy_unlock (struct vidbuf_description *gfxinfo) @@ -2969,69 +2983,69 @@ static void dummy_unlock (struct vidbuf_description *gfxinfo) static void gfxbuffer_reset (void) { - gfxvidinfo.flush_line = dummy_flush_line; - gfxvidinfo.flush_block = dummy_flush_block; - gfxvidinfo.flush_screen = dummy_flush_screen; - gfxvidinfo.flush_clear_screen = dummy_flush_clear_screen; - gfxvidinfo.lockscr = dummy_lock; - gfxvidinfo.unlockscr = dummy_unlock; + gfxvidinfo.flush_line = dummy_flush_line; + gfxvidinfo.flush_block = dummy_flush_block; + gfxvidinfo.flush_screen = dummy_flush_screen; + gfxvidinfo.flush_clear_screen = dummy_flush_clear_screen; + gfxvidinfo.lockscr = dummy_lock; + gfxvidinfo.unlockscr = dummy_unlock; } void notice_interlace_seen (void) { - // non-lace to lace switch (non-lace active at least one frame)? - if (interlace_seen == 0) - frame_redraw_necessary = 2; - interlace_seen = 1; - frame_res_lace = 1; + // non-lace to lace switch (non-lace active at least one frame)? + if (interlace_seen == 0) + frame_redraw_necessary = 2; + interlace_seen = 1; + frame_res_lace = 1; } void reset_drawing (void) { - unsigned int i; + unsigned int i; - max_diwstop = 0; + max_diwstop = 0; - lores_reset (); + lores_reset (); - for (i = 0; i < sizeof linestate / sizeof *linestate; i++) - linestate[i] = LINE_UNDECIDED; + for (i = 0; i < sizeof linestate / sizeof *linestate; i++) + linestate[i] = LINE_UNDECIDED; - init_aspect_maps (); + init_aspect_maps (); - init_row_map(); + init_row_map(); - last_redraw_point = 0; + last_redraw_point = 0; - memset (spixels, 0, sizeof spixels); - memset (&spixstate, 0, sizeof spixstate); + memset (spixels, 0, sizeof spixels); + memset (&spixstate, 0, sizeof spixstate); - init_drawing_frame (); + init_drawing_frame (); - notice_screen_contents_lost (); - frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; - lightpen_y1 = lightpen_y2 = -1; + notice_screen_contents_lost (); + frame_res_cnt = FRAMES_UNTIL_RES_SWITCH; + lightpen_y1 = lightpen_y2 = -1; - reset_custom_limits (); + reset_custom_limits (); } void drawing_init (void) { - gen_pfield_tables (); + gen_pfield_tables (); - uae_sem_init (&gui_sem, 0, 1); + uae_sem_init (&gui_sem, 0, 1); #ifdef PICASSO96 - if (savestate_state != STATE_RESTORE) { - InitPicasso96 (); - picasso_on = 0; - picasso_requested_on = 0; - gfx_set_picasso_state (0); - } + if (savestate_state != STATE_RESTORE) { + InitPicasso96 (); + picasso_on = 0; + picasso_requested_on = 0; + gfx_set_picasso_state (0); + } #endif - xlinebuffer = gfxvidinfo.bufmem; - inhibit_frame = 0; + xlinebuffer = gfxvidinfo.bufmem; + inhibit_frame = 0; - gfxbuffer_reset (); - reset_drawing (); + gfxbuffer_reset (); + reset_drawing (); } diff --git a/driveclick.c b/driveclick.c index aabd48ef..f4e058da 100644 --- a/driveclick.c +++ b/driveclick.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Drive Click Emulation Support Functions - * - * Copyright 2004 James Bagg, Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Drive Click Emulation Support Functions +* +* Copyright 2004 James Bagg, Toni Wilen +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -33,443 +33,443 @@ static uae_s16 *clickbuffer; uae_s16 *decodewav (uae_u8 *s, int *lenp) { - uae_s16 *dst; - uae_u8 *src = s; - int len; - - if (memcmp (s, "RIFF", 4)) - return 0; - if (memcmp (s + 8, "WAVE", 4)) - return 0; - s += 12; - len = *lenp; - while (s < src + len) { - if (!memcmp (s, "fmt ", 4)) - freq = s[8 + 4] | (s[8 + 5] << 8); - if (!memcmp (s, "data", 4)) { - s += 4; - len = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); - dst = xmalloc (len); - memcpy (dst, s + 4, len); - *lenp = len / 2; - return dst; + uae_s16 *dst; + uae_u8 *src = s; + int len; + + if (memcmp (s, "RIFF", 4)) + return 0; + if (memcmp (s + 8, "WAVE", 4)) + return 0; + s += 12; + len = *lenp; + while (s < src + len) { + if (!memcmp (s, "fmt ", 4)) + freq = s[8 + 4] | (s[8 + 5] << 8); + if (!memcmp (s, "data", 4)) { + s += 4; + len = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); + dst = xmalloc (len); + memcpy (dst, s + 4, len); + *lenp = len / 2; + return dst; + } + s += 8 + (s[4] | (s[5] << 8) | (s[6] << 16) | (s[7] << 24)); } - s += 8 + (s[4] | (s[5] << 8) | (s[6] << 16) | (s[7] << 24)); - } - return 0; + return 0; } static int loadsample (TCHAR *path, struct drvsample *ds) { - struct zfile *f; - uae_u8 *buf; - int size; - TCHAR name[MAX_DPATH]; - - f = zfile_fopen (path, L"rb", ZFD_NORMAL); - if (!f) { - _tcscpy (name, path); - _tcscat (name, L".wav"); - f = zfile_fopen (name, L"rb", ZFD_NORMAL); + struct zfile *f; + uae_u8 *buf; + int size; + TCHAR name[MAX_DPATH]; + + f = zfile_fopen (path, L"rb", ZFD_NORMAL); if (!f) { - write_log (L"driveclick: can't open '%s' (or '%s')\n", path, name); - return 0; + _tcscpy (name, path); + _tcscat (name, L".wav"); + f = zfile_fopen (name, L"rb", ZFD_NORMAL); + if (!f) { + write_log (L"driveclick: can't open '%s' (or '%s')\n", path, name); + return 0; + } } - } - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f); - buf = xmalloc (size); - zfile_fseek (f, 0, SEEK_SET); - zfile_fread (buf, size, 1, f); - zfile_fclose (f); - ds->len = size; - ds->p = decodewav (buf, &ds->len); - xfree (buf); - return 1; + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f); + buf = xmalloc (size); + zfile_fseek (f, 0, SEEK_SET); + zfile_fread (buf, size, 1, f); + zfile_fclose (f); + ds->len = size; + ds->p = decodewav (buf, &ds->len); + xfree (buf); + return 1; } static void freesample (struct drvsample *s) { - xfree (s->p); - s->p = 0; + xfree (s->p); + s->p = 0; } static void processclicks(struct drvsample *ds) { - unsigned int n = 0; - unsigned int nClick = 0; - - for (n = 0; n < CLICK_TRACKS; n++) { - ds->indexes[n] = 0; - ds->lengths[n] = 0; - } - for(n = 0; n < ds->len; n++) { - uae_s16 smp = ds->p[n]; - if (smp > 0x6ff0 && nClick < CLICK_TRACKS) { - ds->indexes[nClick] = n - 128; - ds->lengths[nClick] = 2800; - nClick ++; - n += 3000; + unsigned int n = 0; + unsigned int nClick = 0; + + for (n = 0; n < CLICK_TRACKS; n++) { + ds->indexes[n] = 0; + ds->lengths[n] = 0; } - } - if (nClick == 0) { - for(n = 0; n < CLICK_TRACKS; n++) { - ds->indexes[n] = 0; - ds->lengths[n] = ds->len; + for(n = 0; n < ds->len; n++) { + uae_s16 smp = ds->p[n]; + if (smp > 0x6ff0 && nClick < CLICK_TRACKS) { + ds->indexes[nClick] = n - 128; + ds->lengths[nClick] = 2800; + nClick ++; + n += 3000; + } } - } else { - if (nClick == 1) { - ds->lengths[0] = ds->len - ds->indexes[0]; - for(n = 1; n < CLICK_TRACKS; n++) { - ds->indexes[n] = ds->indexes[0]; - ds->lengths[n] = ds->lengths[0]; - } - } else { - for(n = nClick; n < CLICK_TRACKS; n++) { - ds->indexes[n] = ds->indexes[nClick-1]; - ds->lengths[n] = ds->lengths[nClick-1]; - } + if (nClick == 0) { + for(n = 0; n < CLICK_TRACKS; n++) { + ds->indexes[n] = 0; + ds->lengths[n] = ds->len; + } + } else { + if (nClick == 1) { + ds->lengths[0] = ds->len - ds->indexes[0]; + for(n = 1; n < CLICK_TRACKS; n++) { + ds->indexes[n] = ds->indexes[0]; + ds->lengths[n] = ds->lengths[0]; + } + } else { + for(n = nClick; n < CLICK_TRACKS; n++) { + ds->indexes[n] = ds->indexes[nClick-1]; + ds->lengths[n] = ds->lengths[nClick-1]; + } + } } - } } void driveclick_init (void) { - int v, vv, i, j; - TCHAR tmp[MAX_DPATH]; - - driveclick_fdrawcmd_detect (); - driveclick_free (); - vv = 0; - for (i = 0; i < 4; i++) { - for (j = 0; j < CLICK_TRACKS; j++) { - drvs[i][DS_CLICK].indexes[j] = 0; - drvs[i][DS_CLICK].lengths[j] = 0; - } - if (currprefs.dfxclick[i]) { - if (currprefs.dfxclick[i] > 0) { - v = 0; - switch(currprefs.dfxclick[i]) - { - case 1: - if (driveclick_loadresource (drvs[i], currprefs.dfxclick[i])) - v = 3; - for (j = 0; j < CLICK_TRACKS; j++) - drvs[i][DS_CLICK].lengths[j] = drvs[i][DS_CLICK].len; - wave_initialized = 1; - break; - default: - if (driveclick_fdrawcmd_open (currprefs.dfxclick[i] - 2)) - v = 1; - break; + int v, vv, i, j; + TCHAR tmp[MAX_DPATH]; + + driveclick_fdrawcmd_detect (); + driveclick_free (); + vv = 0; + for (i = 0; i < 4; i++) { + for (j = 0; j < CLICK_TRACKS; j++) { + drvs[i][DS_CLICK].indexes[j] = 0; + drvs[i][DS_CLICK].lengths[j] = 0; } - } else if (currprefs.dfxclick[i] == -1) { - TCHAR path2[MAX_DPATH]; - wave_initialized = 1; - for (j = 0; j < CLICK_TRACKS; j++) - drvs[i][DS_CLICK].lengths[j] = drvs[i][DS_CLICK].len; - _stprintf (tmp, L"%splugins%cfloppysounds%c", start_path_data, FSDB_DIR_SEPARATOR, FSDB_DIR_SEPARATOR, FSDB_DIR_SEPARATOR); - if (my_existsdir (tmp)) - _tcscpy (path2, tmp); - else - _stprintf (path2, L"%suae_data%c", start_path_data, FSDB_DIR_SEPARATOR); - _stprintf (tmp, L"%sdrive_click_%s", - path2, currprefs.dfxclickexternal[i]); - v = loadsample (tmp, &drvs[i][DS_CLICK]); - if (v) - processclicks (&drvs[i][DS_CLICK]); - _stprintf (tmp, L"%sdrive_spin_%s", - path2, currprefs.dfxclickexternal[i]); - v += loadsample (tmp, &drvs[i][DS_SPIN]); - _stprintf (tmp, L"%sdrive_spinnd_%s", - path2, currprefs.dfxclickexternal[i]); - v += loadsample (tmp, &drvs[i][DS_SPINND]); - _stprintf (tmp, L"%sdrive_startup_%s", - path2, currprefs.dfxclickexternal[i]); - v += loadsample (tmp, &drvs[i][DS_START]); - _stprintf (tmp, L"%sdrive_snatch_%s", - path2, currprefs.dfxclickexternal[i]); - v += loadsample (tmp, &drvs[i][DS_SNATCH]); - } - if (v == 0) { - int j; - for (j = 0; j < DS_END; j++) - freesample (&drvs[i][j]); - currprefs.dfxclick[i] = changed_prefs.dfxclick[i] = 0; - } else { - vv++; - } - for (j = 0; j < DS_END; j++) - drvs[i][j].len <<= DS_SHIFT; - drvs[i][DS_CLICK].pos = drvs[i][DS_CLICK].len; - drvs[i][DS_SNATCH].pos = drvs[i][DS_SNATCH].len; + if (currprefs.dfxclick[i]) { + if (currprefs.dfxclick[i] > 0) { + v = 0; + switch(currprefs.dfxclick[i]) + { + case 1: + if (driveclick_loadresource (drvs[i], currprefs.dfxclick[i])) + v = 3; + for (j = 0; j < CLICK_TRACKS; j++) + drvs[i][DS_CLICK].lengths[j] = drvs[i][DS_CLICK].len; + wave_initialized = 1; + break; + default: + if (driveclick_fdrawcmd_open (currprefs.dfxclick[i] - 2)) + v = 1; + break; + } + } else if (currprefs.dfxclick[i] == -1) { + TCHAR path2[MAX_DPATH]; + wave_initialized = 1; + for (j = 0; j < CLICK_TRACKS; j++) + drvs[i][DS_CLICK].lengths[j] = drvs[i][DS_CLICK].len; + _stprintf (tmp, L"%splugins%cfloppysounds%c", start_path_data, FSDB_DIR_SEPARATOR, FSDB_DIR_SEPARATOR, FSDB_DIR_SEPARATOR); + if (my_existsdir (tmp)) + _tcscpy (path2, tmp); + else + _stprintf (path2, L"%suae_data%c", start_path_data, FSDB_DIR_SEPARATOR); + _stprintf (tmp, L"%sdrive_click_%s", + path2, currprefs.dfxclickexternal[i]); + v = loadsample (tmp, &drvs[i][DS_CLICK]); + if (v) + processclicks (&drvs[i][DS_CLICK]); + _stprintf (tmp, L"%sdrive_spin_%s", + path2, currprefs.dfxclickexternal[i]); + v += loadsample (tmp, &drvs[i][DS_SPIN]); + _stprintf (tmp, L"%sdrive_spinnd_%s", + path2, currprefs.dfxclickexternal[i]); + v += loadsample (tmp, &drvs[i][DS_SPINND]); + _stprintf (tmp, L"%sdrive_startup_%s", + path2, currprefs.dfxclickexternal[i]); + v += loadsample (tmp, &drvs[i][DS_START]); + _stprintf (tmp, L"%sdrive_snatch_%s", + path2, currprefs.dfxclickexternal[i]); + v += loadsample (tmp, &drvs[i][DS_SNATCH]); + } + if (v == 0) { + int j; + for (j = 0; j < DS_END; j++) + freesample (&drvs[i][j]); + currprefs.dfxclick[i] = changed_prefs.dfxclick[i] = 0; + } else { + vv++; + } + for (j = 0; j < DS_END; j++) + drvs[i][j].len <<= DS_SHIFT; + drvs[i][DS_CLICK].pos = drvs[i][DS_CLICK].len; + drvs[i][DS_SNATCH].pos = drvs[i][DS_SNATCH].len; + } + } + if (vv > 0) { + driveclick_reset (); + click_initialized = 1; } - } - if (vv > 0) { - driveclick_reset (); - click_initialized = 1; - } } void driveclick_reset (void) { - xfree (clickbuffer); - clickbuffer = NULL; - if (!wave_initialized) - return; - clickbuffer = xmalloc (paula_sndbufsize); - sample_step = (freq << DS_SHIFT) / currprefs.sound_freq; + xfree (clickbuffer); + clickbuffer = NULL; + if (!wave_initialized) + return; + clickbuffer = xmalloc (paula_sndbufsize); + sample_step = (freq << DS_SHIFT) / currprefs.sound_freq; } void driveclick_free (void) { - int i, j; - - driveclick_fdrawcmd_close (0); - driveclick_fdrawcmd_close (1); - for (i = 0; i < 4; i++) { - for (j = 0; j < DS_END; j++) - freesample (&drvs[i][j]); - drv_starting[i] = 0; - drv_spinning[i] = 0; - drv_has_spun[i] = 0; - drv_has_disk[i] = 0; - } - memset (drvs, 0, sizeof (drvs)); - xfree (clickbuffer); - clickbuffer = 0; - click_initialized = 0; - wave_initialized = 0; + int i, j; + + driveclick_fdrawcmd_close (0); + driveclick_fdrawcmd_close (1); + for (i = 0; i < 4; i++) { + for (j = 0; j < DS_END; j++) + freesample (&drvs[i][j]); + drv_starting[i] = 0; + drv_spinning[i] = 0; + drv_has_spun[i] = 0; + drv_has_disk[i] = 0; + } + memset (drvs, 0, sizeof (drvs)); + xfree (clickbuffer); + clickbuffer = 0; + click_initialized = 0; + wave_initialized = 0; } static int driveclick_active (void) { - int i; - for (i = 0; i < 4; i++) { - if (currprefs.dfxclick[i]) { - if (drv_spinning[i] || drv_starting[i]) - return 1; + int i; + for (i = 0; i < 4; i++) { + if (currprefs.dfxclick[i]) { + if (drv_spinning[i] || drv_starting[i]) + return 1; + } } - } - return 0; + return 0; } STATIC_INLINE uae_s16 getsample (void) { - uae_s32 smp = 0; - int div = 0, i; - - for (i = 0; i < 4; i++) { - if (currprefs.dfxclick[i]) { - struct drvsample *ds_start = &drvs[i][DS_START]; - struct drvsample *ds_spin = drv_has_disk[i] ? &drvs[i][DS_SPIN] : &drvs[i][DS_SPINND]; - struct drvsample *ds_click = &drvs[i][DS_CLICK]; - struct drvsample *ds_snatch = &drvs[i][DS_SNATCH]; - div += 2; - if (drv_spinning[i] || drv_starting[i]) { - if (drv_starting[i] && drv_has_spun[i]) { - if (ds_start->p && ds_start->pos < ds_start->len) { - smp = ds_start->p[ds_start->pos >> DS_SHIFT]; - ds_start->pos += sample_step; - } else { - drv_starting[i] = 0; - } - } else if (drv_starting[i] && drv_has_spun[i] == 0) { - if (ds_snatch->p && ds_snatch->pos < ds_snatch->len) { - smp = ds_snatch->p[ds_snatch->pos >> DS_SHIFT]; - ds_snatch->pos += sample_step; - } else { - drv_starting[i] = 0; - ds_start->pos = ds_start->len; - drv_has_spun[i] = 1; - } - } - if (ds_spin->p && drv_starting[i] == 0) { - if (ds_spin->pos >= ds_spin->len) - ds_spin->pos -= ds_spin->len; - smp = ds_spin->p[ds_spin->pos >> DS_SHIFT]; - ds_spin->pos += sample_step; + uae_s32 smp = 0; + int div = 0, i; + + for (i = 0; i < 4; i++) { + if (currprefs.dfxclick[i]) { + struct drvsample *ds_start = &drvs[i][DS_START]; + struct drvsample *ds_spin = drv_has_disk[i] ? &drvs[i][DS_SPIN] : &drvs[i][DS_SPINND]; + struct drvsample *ds_click = &drvs[i][DS_CLICK]; + struct drvsample *ds_snatch = &drvs[i][DS_SNATCH]; + div += 2; + if (drv_spinning[i] || drv_starting[i]) { + if (drv_starting[i] && drv_has_spun[i]) { + if (ds_start->p && ds_start->pos < ds_start->len) { + smp = ds_start->p[ds_start->pos >> DS_SHIFT]; + ds_start->pos += sample_step; + } else { + drv_starting[i] = 0; + } + } else if (drv_starting[i] && drv_has_spun[i] == 0) { + if (ds_snatch->p && ds_snatch->pos < ds_snatch->len) { + smp = ds_snatch->p[ds_snatch->pos >> DS_SHIFT]; + ds_snatch->pos += sample_step; + } else { + drv_starting[i] = 0; + ds_start->pos = ds_start->len; + drv_has_spun[i] = 1; + } + } + if (ds_spin->p && drv_starting[i] == 0) { + if (ds_spin->pos >= ds_spin->len) + ds_spin->pos -= ds_spin->len; + smp = ds_spin->p[ds_spin->pos >> DS_SHIFT]; + ds_spin->pos += sample_step; + } + } + if (ds_click->p && ds_click->pos < ds_click->len) { + smp += ds_click->p[ds_click->pos >> DS_SHIFT]; + ds_click->pos += sample_step; + } } - } - if (ds_click->p && ds_click->pos < ds_click->len) { - smp += ds_click->p[ds_click->pos >> DS_SHIFT]; - ds_click->pos += sample_step; - } } - } - if (!div) - return 0; - return smp / div; + if (!div) + return 0; + return smp / div; } static int clickcnt; static void mix (void) { - int total = ((uae_u8*)paula_sndbufpt - (uae_u8*)paula_sndbuffer) / (get_audio_nativechannels (currprefs.sound_stereo) * 2); + int total = ((uae_u8*)paula_sndbufpt - (uae_u8*)paula_sndbuffer) / (get_audio_nativechannels (currprefs.sound_stereo) * 2); - if (currprefs.dfxclickvolume > 0) { - while (clickcnt < total) { - clickbuffer[clickcnt++] = getsample () * (100 - currprefs.dfxclickvolume) / 100; - } - } else { - while (clickcnt < total) { - clickbuffer[clickcnt++] = getsample (); + if (currprefs.dfxclickvolume > 0) { + while (clickcnt < total) { + clickbuffer[clickcnt++] = getsample () * (100 - currprefs.dfxclickvolume) / 100; + } + } else { + while (clickcnt < total) { + clickbuffer[clickcnt++] = getsample (); + } } - } } STATIC_INLINE uae_s16 limit (uae_s32 v) { - if (v < -32768) - v = -32768; - if (v > 32767) - v = 32767; - return v; + if (v < -32768) + v = -32768; + if (v > 32767) + v = 32767; + return v; } void driveclick_mix (uae_s16 *sndbuffer, int size) { - int i; - - if (!wave_initialized) - return; - mix (); - clickcnt = 0; - switch (get_audio_nativechannels (currprefs.sound_stereo)) - { + int i; + + if (!wave_initialized) + return; + mix (); + clickcnt = 0; + switch (get_audio_nativechannels (currprefs.sound_stereo)) + { case 6: - for (i = 0; i < size / 6; i++) { - uae_s16 s = clickbuffer[i]; - sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); - sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); - sndbuffer[2] = limit (((sndbuffer[2] + s) * 2) / 3); - sndbuffer[3] = limit (((sndbuffer[3] + s) * 2) / 3); - sndbuffer[4] = limit (((sndbuffer[4] + s) * 2) / 3); - sndbuffer[5] = limit (((sndbuffer[5] + s) * 2) / 3); - sndbuffer += 6; - } - break; + for (i = 0; i < size / 6; i++) { + uae_s16 s = clickbuffer[i]; + sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); + sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); + sndbuffer[2] = limit (((sndbuffer[2] + s) * 2) / 3); + sndbuffer[3] = limit (((sndbuffer[3] + s) * 2) / 3); + sndbuffer[4] = limit (((sndbuffer[4] + s) * 2) / 3); + sndbuffer[5] = limit (((sndbuffer[5] + s) * 2) / 3); + sndbuffer += 6; + } + break; case 4: - for (i = 0; i < size / 4; i++) { - uae_s16 s = clickbuffer[i]; - sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); - sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); - sndbuffer[2] = limit (((sndbuffer[2] + s) * 2) / 3); - sndbuffer[3] = limit (((sndbuffer[3] + s) * 2) / 3); - sndbuffer += 4; - } - break; + for (i = 0; i < size / 4; i++) { + uae_s16 s = clickbuffer[i]; + sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); + sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); + sndbuffer[2] = limit (((sndbuffer[2] + s) * 2) / 3); + sndbuffer[3] = limit (((sndbuffer[3] + s) * 2) / 3); + sndbuffer += 4; + } + break; case 2: - for (i = 0; i < size / 2; i++) { - uae_s16 s = clickbuffer[i]; - sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); - sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); - sndbuffer += 2; - } - break; + for (i = 0; i < size / 2; i++) { + uae_s16 s = clickbuffer[i]; + sndbuffer[0] = limit (((sndbuffer[0] + s) * 2) / 3); + sndbuffer[1] = limit (((sndbuffer[1] + s) * 2) / 3); + sndbuffer += 2; + } + break; case 1: - for (i = 0; i < size; i++) { - sndbuffer[0] = limit (((sndbuffer[0] + clickbuffer[i]) * 2) / 3); - sndbuffer++; - } - break; - } + for (i = 0; i < size; i++) { + sndbuffer[0] = limit (((sndbuffer[0] + clickbuffer[i]) * 2) / 3); + sndbuffer++; + } + break; + } } static void dr_audio_activate (void) { - if (audio_activate ()) - clickcnt = 0; + if (audio_activate ()) + clickcnt = 0; } void driveclick_click (int drive, int cyl) { - static int prevcyl[4]; - - if (!click_initialized) - return; - if (!currprefs.dfxclick[drive]) - return; - if (prevcyl[drive] == 0 && cyl == 0) // "noclick" check - return; - dr_audio_activate (); - prevcyl[drive] = cyl; - if (!wave_initialized) { - driveclick_fdrawcmd_seek (currprefs.dfxclick[drive] - 2, cyl); - return; - } - mix (); - drvs[drive][DS_CLICK].pos = drvs[drive][DS_CLICK].indexes[cyl] << DS_SHIFT; - drvs[drive][DS_CLICK].len = (drvs[drive][DS_CLICK].indexes[cyl] + (drvs[drive][DS_CLICK].lengths[cyl] / 2)) << DS_SHIFT; + static int prevcyl[4]; + + if (!click_initialized) + return; + if (!currprefs.dfxclick[drive]) + return; + if (prevcyl[drive] == 0 && cyl == 0) // "noclick" check + return; + dr_audio_activate (); + prevcyl[drive] = cyl; + if (!wave_initialized) { + driveclick_fdrawcmd_seek (currprefs.dfxclick[drive] - 2, cyl); + return; + } + mix (); + drvs[drive][DS_CLICK].pos = drvs[drive][DS_CLICK].indexes[cyl] << DS_SHIFT; + drvs[drive][DS_CLICK].len = (drvs[drive][DS_CLICK].indexes[cyl] + (drvs[drive][DS_CLICK].lengths[cyl] / 2)) << DS_SHIFT; } void driveclick_motor (int drive, int running) { - if (!click_initialized) - return; - if (!currprefs.dfxclick[drive]) - return; - if (!wave_initialized) { - driveclick_fdrawcmd_motor (currprefs.dfxclick[drive] - 2, running); - return; - } - mix (); - if (running == 0) { - drv_starting[drive] = 0; - drv_spinning[drive] = 0; - } else { - if (drv_spinning[drive] == 0) { - dr_audio_activate(); - drv_starting[drive] = 1; - drv_spinning[drive] = 1; - if (drv_has_disk[drive] && drv_has_spun[drive] == 0 && drvs[drive][DS_SNATCH].pos >= drvs[drive][DS_SNATCH].len) - drvs[drive][DS_SNATCH].pos = 0; - if (running == 2) - drvs[drive][DS_START].pos = 0; - drvs[drive][DS_SPIN].pos = 0; + if (!click_initialized) + return; + if (!currprefs.dfxclick[drive]) + return; + if (!wave_initialized) { + driveclick_fdrawcmd_motor (currprefs.dfxclick[drive] - 2, running); + return; + } + mix (); + if (running == 0) { + drv_starting[drive] = 0; + drv_spinning[drive] = 0; + } else { + if (drv_spinning[drive] == 0) { + dr_audio_activate(); + drv_starting[drive] = 1; + drv_spinning[drive] = 1; + if (drv_has_disk[drive] && drv_has_spun[drive] == 0 && drvs[drive][DS_SNATCH].pos >= drvs[drive][DS_SNATCH].len) + drvs[drive][DS_SNATCH].pos = 0; + if (running == 2) + drvs[drive][DS_START].pos = 0; + drvs[drive][DS_SPIN].pos = 0; + } } - } } void driveclick_insert (int drive, int eject) { - if (!click_initialized) - return; - if (!wave_initialized) - return; - if (!currprefs.dfxclick[drive]) - return; - if (eject) - drv_has_spun[drive] = 0; - if (drv_has_disk[drive] == 0 && !eject) - dr_audio_activate (); - drv_has_disk[drive] = !eject; + if (!click_initialized) + return; + if (!wave_initialized) + return; + if (!currprefs.dfxclick[drive]) + return; + if (eject) + drv_has_spun[drive] = 0; + if (drv_has_disk[drive] == 0 && !eject) + dr_audio_activate (); + drv_has_disk[drive] = !eject; } void driveclick_check_prefs (void) { - int i; - - driveclick_fdrawcmd_vsync (); - if (driveclick_active ()) - dr_audio_activate (); - if (currprefs.dfxclickvolume != changed_prefs.dfxclickvolume || - currprefs.dfxclick[0] != changed_prefs.dfxclick[0] || - currprefs.dfxclick[1] != changed_prefs.dfxclick[1] || - currprefs.dfxclick[2] != changed_prefs.dfxclick[2] || - currprefs.dfxclick[3] != changed_prefs.dfxclick[3] || - _tcscmp (currprefs.dfxclickexternal[0], changed_prefs.dfxclickexternal[0]) || - _tcscmp (currprefs.dfxclickexternal[1], changed_prefs.dfxclickexternal[1]) || - _tcscmp (currprefs.dfxclickexternal[2], changed_prefs.dfxclickexternal[2]) || - _tcscmp (currprefs.dfxclickexternal[3], changed_prefs.dfxclickexternal[3])) - { - currprefs.dfxclickvolume = changed_prefs.dfxclickvolume; - for (i = 0; i < 4; i++) { - currprefs.dfxclick[i] = changed_prefs.dfxclick[i]; - _tcscpy (currprefs.dfxclickexternal[i], changed_prefs.dfxclickexternal[i]); + int i; + + driveclick_fdrawcmd_vsync (); + if (driveclick_active ()) + dr_audio_activate (); + if (currprefs.dfxclickvolume != changed_prefs.dfxclickvolume || + currprefs.dfxclick[0] != changed_prefs.dfxclick[0] || + currprefs.dfxclick[1] != changed_prefs.dfxclick[1] || + currprefs.dfxclick[2] != changed_prefs.dfxclick[2] || + currprefs.dfxclick[3] != changed_prefs.dfxclick[3] || + _tcscmp (currprefs.dfxclickexternal[0], changed_prefs.dfxclickexternal[0]) || + _tcscmp (currprefs.dfxclickexternal[1], changed_prefs.dfxclickexternal[1]) || + _tcscmp (currprefs.dfxclickexternal[2], changed_prefs.dfxclickexternal[2]) || + _tcscmp (currprefs.dfxclickexternal[3], changed_prefs.dfxclickexternal[3])) + { + currprefs.dfxclickvolume = changed_prefs.dfxclickvolume; + for (i = 0; i < 4; i++) { + currprefs.dfxclick[i] = changed_prefs.dfxclick[i]; + _tcscpy (currprefs.dfxclickexternal[i], changed_prefs.dfxclickexternal[i]); + } + driveclick_init (); } - driveclick_init (); - } } #endif diff --git a/enforcer.c b/enforcer.c index b836ff2a..835f9931 100644 --- a/enforcer.c +++ b/enforcer.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Enforcer Like Support - * - * Copyright 2000-2003 Bernd Roesch and Sebastian Bauer - */ +* UAE - The Un*x Amiga Emulator +* +* Enforcer Like Support +* +* Copyright 2000-2003 Bernd Roesch and Sebastian Bauer +*/ #include @@ -68,438 +68,438 @@ void (REGPARAM3 *saved_dummy_bput) (uaecptr addr, uae_u32 b); int (REGPARAM3 *saved_dummy_check) (uaecptr addr, uae_u32 size); /************************************************************* - Returns the first node entry of an exec list or 0 if - empty +Returns the first node entry of an exec list or 0 if +empty *************************************************************/ static uae_u32 amiga_list_first (uae_u32 list) { - uae_u32 node = get_long (list); /* lh_Head */ - if (!node) - return 0; - if (!get_long (node)) - return 0; /* ln_Succ */ - return node; + uae_u32 node = get_long (list); /* lh_Head */ + if (!node) + return 0; + if (!get_long (node)) + return 0; /* ln_Succ */ + return node; } /************************************************************* - Returns the next node of an exec node or 0 if it was the - last element +Returns the next node of an exec node or 0 if it was the +last element *************************************************************/ static uae_u32 amiga_node_next (uae_u32 node) { - uae_u32 next = get_long (node); /* ln_Succ */ - if (!next) - return 0; - if (!get_long (next)) - return 0; /* ln_Succ */ - return next; + uae_u32 next = get_long (node); /* ln_Succ */ + if (!next) + return 0; + if (!get_long (next)) + return 0; /* ln_Succ */ + return next; } /************************************************************* - Converts an amiga address to a native one or NULL if this - is not possible, Size specified the number of bytes you - want to access +Converts an amiga address to a native one or NULL if this +is not possible, Size specified the number of bytes you +want to access *************************************************************/ static uae_u8 *amiga2native (uae_u32 aptr, int size) { - addrbank bank = get_mem_bank (aptr); + addrbank bank = get_mem_bank (aptr); - /* Check if the address can be translated to native */ - if (bank.check (aptr, size)) { - return bank.xlateaddr (aptr); - } - return NULL; + /* Check if the address can be translated to native */ + if (bank.check (aptr, size)) { + return bank.xlateaddr (aptr); + } + return NULL; } /************************************************************* - Writes the Hunk and Offset of the given Address into buf +Writes the Hunk and Offset of the given Address into buf *************************************************************/ static int enforcer_decode_hunk_and_offset (TCHAR *buf, uae_u32 pc) { - uae_u32 sysbase = get_long (4); - uae_u32 semaphore_list = sysbase + 532; - - /* First step is searching for the SegTracker semaphore */ - uae_u32 node = amiga_list_first (semaphore_list); - while (node) { - uae_u32 string = get_long (node + 10); /* ln_Name */ - uae_u8 *native_string = amiga2native (string, 100); - - if (native_string) { - if (!strcmp (native_string, "SegTracker")) - break; - } - node = amiga_node_next (node); - } - - if (node) { - /* We have found the segtracker semaphore. Soon after the - * public documented semaphore structure Segtracker holds - * an own list of all segements. We will use this list to - * find out the hunk and offset (simliar to segtracker). - * - * Source of segtracker can be found at: - * http://www.sinz.org/Michael.Sinz/Enforcer/SegTracker.c.html - */ - - uae_u32 seg_list = node + 46 + 4; /* sizeof(struct SignalSemaphore) + seg find */ - - node = amiga_list_first (seg_list); + uae_u32 sysbase = get_long (4); + uae_u32 semaphore_list = sysbase + 532; + + /* First step is searching for the SegTracker semaphore */ + uae_u32 node = amiga_list_first (semaphore_list); while (node) { - uae_u32 seg_entry = node + 12; - uae_u32 address, size; - int hunk = 0; - - /* Go through all entries until an address is 0 - * or the segment has been found */ - while ((address = get_long (seg_entry))) { - size = get_long (seg_entry + 4); - - if (pc > address && pc < address + size) { - uae_u32 name, offset; - TCHAR *native_name; - - offset = pc - address - 4; - name = get_long (node + 8); /* ln_Name */ - if (name) { - native_name = au (amiga2native(name,100)); - if (!native_name) - native_name = my_strdup (L"Unknown"); - } else { - native_name = my_strdup (L"Unknown"); - } - _stprintf (buf, L"----> %08lx - \"%s\" Hunk %04lx Offset %08lx\n", pc, native_name, hunk, offset); - xfree (native_name); - return 1; + uae_u32 string = get_long (node + 10); /* ln_Name */ + uae_u8 *native_string = amiga2native (string, 100); + + if (native_string) { + if (!strcmp (native_string, "SegTracker")) + break; } + node = amiga_node_next (node); + } - seg_entry += 8; - hunk++; - } - node = amiga_node_next (node); + if (node) { + /* We have found the segtracker semaphore. Soon after the + * public documented semaphore structure Segtracker holds + * an own list of all segements. We will use this list to + * find out the hunk and offset (simliar to segtracker). + * + * Source of segtracker can be found at: + * http://www.sinz.org/Michael.Sinz/Enforcer/SegTracker.c.html + */ + + uae_u32 seg_list = node + 46 + 4; /* sizeof(struct SignalSemaphore) + seg find */ + + node = amiga_list_first (seg_list); + while (node) { + uae_u32 seg_entry = node + 12; + uae_u32 address, size; + int hunk = 0; + + /* Go through all entries until an address is 0 + * or the segment has been found */ + while ((address = get_long (seg_entry))) { + size = get_long (seg_entry + 4); + + if (pc > address && pc < address + size) { + uae_u32 name, offset; + TCHAR *native_name; + + offset = pc - address - 4; + name = get_long (node + 8); /* ln_Name */ + if (name) { + native_name = au (amiga2native(name,100)); + if (!native_name) + native_name = my_strdup (L"Unknown"); + } else { + native_name = my_strdup (L"Unknown"); + } + _stprintf (buf, L"----> %08lx - \"%s\" Hunk %04lx Offset %08lx\n", pc, native_name, hunk, offset); + xfree (native_name); + return 1; + } + + seg_entry += 8; + hunk++; + } + node = amiga_node_next (node); + } } - } - return 0; + return 0; } /************************************************************* - Display the enforcer hit +Display the enforcer hit *************************************************************/ static void enforcer_display_hit (const TCHAR *addressmode, uae_u32 pc, uaecptr addr) { - uae_u32 a7; - uae_u32 sysbase; - uae_u32 this_task; - uae_u32 task_name; - TCHAR *native_task_name = NULL; - int i, j; - static TCHAR buf[256],instrcode[256]; - static TCHAR lines[INSTRUCTIONLINES/2][256]; - static uaecptr bestpc_array[INSTRUCTIONLINES/2][5]; - static int bestpc_idxs[INSTRUCTIONLINES/2]; - TCHAR *enforcer_buf_ptr = enforcer_buf; - uaecptr bestpc, pospc, nextpc, temppc; - - if (enforcer_hit) - return; /* our function itself generated a hit ;), avoid endless loop */ - if (regs.vbr < 0x100 && addr >= 0x0c && addr < 0x80) - return; - - enforcer_hit = 1; - - if (!(sysbase = get_long (4))) - goto end; - if (!(this_task = get_long (sysbase + 276))) - goto end; - - task_name = get_long (this_task + 10); /* ln_Name */ - native_task_name = au (amiga2native (task_name, 100)); - /*if (strcmp(native_task_name,"c:MCP")!=0) - { - Exception (0x2d,0); - }*/ - _tcscpy (enforcer_buf_ptr, L"Enforcer Hit! Bad program\n"); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - - _stprintf (buf, L"Illegal %s: %08lx", addressmode, addr); - _stprintf (enforcer_buf_ptr, L"%-48sPC: %0lx\n", buf, pc); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - - /* Data registers */ - _stprintf (enforcer_buf_ptr, L"Data: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", - m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3), - m68k_dreg (regs, 4), m68k_dreg (regs, 5), m68k_dreg (regs, 6), m68k_dreg (regs, 7)); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - - /* Address registers */ - _stprintf (enforcer_buf_ptr, L"Addr: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", - m68k_areg (regs, 0), m68k_areg (regs, 1), m68k_areg (regs, 2), m68k_areg (regs, 3), - m68k_areg (regs, 4), m68k_areg (regs, 5), m68k_areg (regs, 6), m68k_areg (regs, 7)); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - - /* Stack */ - a7 = m68k_areg (regs, 7); - for (i = 0; i < 8 * STACKLINES; i++) { - a7 += 4; - if (!(i % 8)) { - _tcscpy (enforcer_buf_ptr, L"Stck:"); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - } - _stprintf (enforcer_buf_ptr, L" %08lx",get_long (a7)); + uae_u32 a7; + uae_u32 sysbase; + uae_u32 this_task; + uae_u32 task_name; + TCHAR *native_task_name = NULL; + int i, j; + static TCHAR buf[256],instrcode[256]; + static TCHAR lines[INSTRUCTIONLINES/2][256]; + static uaecptr bestpc_array[INSTRUCTIONLINES/2][5]; + static int bestpc_idxs[INSTRUCTIONLINES/2]; + TCHAR *enforcer_buf_ptr = enforcer_buf; + uaecptr bestpc, pospc, nextpc, temppc; + + if (enforcer_hit) + return; /* our function itself generated a hit ;), avoid endless loop */ + if (regs.vbr < 0x100 && addr >= 0x0c && addr < 0x80) + return; + + enforcer_hit = 1; + + if (!(sysbase = get_long (4))) + goto end; + if (!(this_task = get_long (sysbase + 276))) + goto end; + + task_name = get_long (this_task + 10); /* ln_Name */ + native_task_name = au (amiga2native (task_name, 100)); + /*if (strcmp(native_task_name,"c:MCP")!=0) + { + Exception (0x2d,0); + }*/ + _tcscpy (enforcer_buf_ptr, L"Enforcer Hit! Bad program\n"); enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - if (i%8 == 7) - *enforcer_buf_ptr++ = '\n'; - } + _stprintf (buf, L"Illegal %s: %08lx", addressmode, addr); + _stprintf (enforcer_buf_ptr, L"%-48sPC: %0lx\n", buf, pc); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - /* Segtracker output */ - a7 = m68k_areg (regs, 7); - if (get_long (a7 - 4) != pc) { - if (enforcer_decode_hunk_and_offset (buf, pc)) { - _tcscpy (enforcer_buf_ptr, buf); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - } - } + /* Data registers */ + _stprintf (enforcer_buf_ptr, L"Data: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", + m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3), + m68k_dreg (regs, 4), m68k_dreg (regs, 5), m68k_dreg (regs, 6), m68k_dreg (regs, 7)); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - for (i = 0; i < BACKTRACELONGS; i++) { - a7 += 4; - if (enforcer_decode_hunk_and_offset (buf, get_long (a7))) { - int l = _tcslen (buf); + /* Address registers */ + _stprintf (enforcer_buf_ptr, L"Addr: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", + m68k_areg (regs, 0), m68k_areg (regs, 1), m68k_areg (regs, 2), m68k_areg (regs, 3), + m68k_areg (regs, 4), m68k_areg (regs, 5), m68k_areg (regs, 6), m68k_areg (regs, 7)); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - if (ENFORCER_BUF_SIZE - (enforcer_buf_ptr - enforcer_buf) > l + 256) { - _tcscpy (enforcer_buf_ptr, buf); - enforcer_buf_ptr += l; - } - } - } - - /* Decode the instructions around the pc where the enforcer hit was caused. - * - * At first, the area before the pc, this not always done correctly because - * it's done backwards */ - temppc = pc; - - memset (bestpc_array, 0, sizeof (bestpc_array)); - for (i = 0; i < INSTRUCTIONLINES / 2; i++) - bestpc_idxs[i] = -1; - - for (i = 0; i < INSTRUCTIONLINES / 2; i++) { - pospc = temppc; - bestpc = 0; - - if (bestpc_idxs[i] == -1) { - for (j = 0; j < 5; j++) { - pospc -= 2; - sm68k_disasm (buf, NULL, pospc, &nextpc); - if (nextpc == temppc) { - bestpc_idxs[i] = j; - bestpc_array[i][j] = bestpc = pospc; + /* Stack */ + a7 = m68k_areg (regs, 7); + for (i = 0; i < 8 * STACKLINES; i++) { + a7 += 4; + if (!(i % 8)) { + _tcscpy (enforcer_buf_ptr, L"Stck:"); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); } - } - } else { - bestpc = bestpc_array[i][bestpc_idxs[i]]; + _stprintf (enforcer_buf_ptr, L" %08lx",get_long (a7)); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); + + if (i%8 == 7) + *enforcer_buf_ptr++ = '\n'; } - if (!bestpc) { - /* there was no best pc found, so it is high probable that - * a former used best pc was wrong. - * - * We trace back and use the former best pc instead - */ + /* Segtracker output */ + a7 = m68k_areg (regs, 7); + if (get_long (a7 - 4) != pc) { + if (enforcer_decode_hunk_and_offset (buf, pc)) { + _tcscpy (enforcer_buf_ptr, buf); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); + } + } - int former_idx; - int leave = 0; + for (i = 0; i < BACKTRACELONGS; i++) { + a7 += 4; + if (enforcer_decode_hunk_and_offset (buf, get_long (a7))) { + int l = _tcslen (buf); - do { - if (!i) { - leave = 1; - break; + if (ENFORCER_BUF_SIZE - (enforcer_buf_ptr - enforcer_buf) > l + 256) { + _tcscpy (enforcer_buf_ptr, buf); + enforcer_buf_ptr += l; + } } - i--; - former_idx = bestpc_idxs[i]; + } + + /* Decode the instructions around the pc where the enforcer hit was caused. + * + * At first, the area before the pc, this not always done correctly because + * it's done backwards */ + temppc = pc; + + memset (bestpc_array, 0, sizeof (bestpc_array)); + for (i = 0; i < INSTRUCTIONLINES / 2; i++) bestpc_idxs[i] = -1; - bestpc_array[i][former_idx] = 0; - for (j = former_idx - 1; j >= 0; j--) { - if (bestpc_array[i][j]) { - bestpc_idxs[i] = j; - break; - } + for (i = 0; i < INSTRUCTIONLINES / 2; i++) { + pospc = temppc; + bestpc = 0; + + if (bestpc_idxs[i] == -1) { + for (j = 0; j < 5; j++) { + pospc -= 2; + sm68k_disasm (buf, NULL, pospc, &nextpc); + if (nextpc == temppc) { + bestpc_idxs[i] = j; + bestpc_array[i][j] = bestpc = pospc; + } + } + } else { + bestpc = bestpc_array[i][bestpc_idxs[i]]; } - } while (bestpc_idxs[i] == -1); - if (leave) - break; - if (i) - temppc = bestpc_array[i-1][bestpc_idxs[i-1]]; - else - temppc = pc; - i--; /* will be increased in after continue */ - continue; + + if (!bestpc) { + /* there was no best pc found, so it is high probable that + * a former used best pc was wrong. + * + * We trace back and use the former best pc instead + */ + + int former_idx; + int leave = 0; + + do { + if (!i) { + leave = 1; + break; + } + i--; + former_idx = bestpc_idxs[i]; + bestpc_idxs[i] = -1; + bestpc_array[i][former_idx] = 0; + + for (j = former_idx - 1; j >= 0; j--) { + if (bestpc_array[i][j]) { + bestpc_idxs[i] = j; + break; + } + } + } while (bestpc_idxs[i] == -1); + if (leave) + break; + if (i) + temppc = bestpc_array[i-1][bestpc_idxs[i-1]]; + else + temppc = pc; + i--; /* will be increased in after continue */ + continue; + } + + sm68k_disasm (buf, instrcode, bestpc, NULL); + _stprintf (lines[i], L"%08lx : %-20s %s\n", bestpc, instrcode, buf); + temppc = bestpc; } - sm68k_disasm (buf, instrcode, bestpc, NULL); - _stprintf (lines[i], L"%08lx : %-20s %s\n", bestpc, instrcode, buf); - temppc = bestpc; - } + i--; + for (; i >= 0; i--) { + _tcscpy (enforcer_buf_ptr, lines[i]); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); + } - i--; - for (; i >= 0; i--) { - _tcscpy (enforcer_buf_ptr, lines[i]); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - } - - /* Now the instruction after the pc including the pc */ - temppc = pc; - for (i = 0; i < (INSTRUCTIONLINES + 1) / 2; i++) { - sm68k_disasm (buf, instrcode, temppc, &nextpc); - _stprintf (enforcer_buf_ptr, L"%08lx : %s %-20s %s\n", temppc, - (i == 0 ? L"*" : L" "), instrcode, buf); + /* Now the instruction after the pc including the pc */ + temppc = pc; + for (i = 0; i < (INSTRUCTIONLINES + 1) / 2; i++) { + sm68k_disasm (buf, instrcode, temppc, &nextpc); + _stprintf (enforcer_buf_ptr, L"%08lx : %s %-20s %s\n", temppc, + (i == 0 ? L"*" : L" "), instrcode, buf); + enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); + temppc = nextpc; + } + + if (!native_task_name) + native_task_name = L"Unknown"; + _stprintf (enforcer_buf_ptr, L"Name: \"%s\"\n\n", native_task_name); enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - temppc = nextpc; - } - - if (!native_task_name) - native_task_name = L"Unknown"; - _stprintf (enforcer_buf_ptr, L"Name: \"%s\"\n\n", native_task_name); - enforcer_buf_ptr += _tcslen (enforcer_buf_ptr); - - console_out (enforcer_buf); - write_log (enforcer_buf); - sleep_millis (5); - doflashscreen (); - - end: - xfree (native_task_name); - enforcer_hit = 0; + + console_out (enforcer_buf); + write_log (enforcer_buf); + sleep_millis (5); + doflashscreen (); + +end: + xfree (native_task_name); + enforcer_hit = 0; } uae_u32 REGPARAM2 chipmem_lget2 (uaecptr addr) { - uae_u32 *m; - - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - - if (ISILLEGAL_LONG (addr)) - { - enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - set_special (SPCFLAG_TRAP); - } - return do_get_mem_long (m); + uae_u32 *m; + + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + + if (ISILLEGAL_LONG (addr)) + { + enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + set_special (SPCFLAG_TRAP); + } + return do_get_mem_long (m); } uae_u32 REGPARAM2 chipmem_wget2(uaecptr addr) { - uae_u16 *m; + uae_u16 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); - if (ISILLEGAL_WORD (addr)) - { - enforcer_display_hit (L"WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - set_special (SPCFLAG_TRAP); - } - return do_get_mem_word (m); + if (ISILLEGAL_WORD (addr)) + { + enforcer_display_hit (L"WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + set_special (SPCFLAG_TRAP); + } + return do_get_mem_word (m); } uae_u32 REGPARAM2 chipmem_bget2 (uaecptr addr) { - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - - if (ISILLEGAL_BYTE (addr)) - { - enforcer_display_hit (L"BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - set_special (SPCFLAG_TRAP); - } + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + + if (ISILLEGAL_BYTE (addr)) + { + enforcer_display_hit (L"BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + set_special (SPCFLAG_TRAP); + } - return chipmemory[addr]; + return chipmemory[addr]; } void REGPARAM2 chipmem_lput2 (uaecptr addr, uae_u32 l) { - uae_u32 *m; - - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - - if (ISILLEGAL_LONG (addr)) - { - enforcer_display_hit (L"LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - if (addr != 0x100) - set_special (SPCFLAG_TRAP); - } - if (ISEXEC (addr) || ISEXEC (addr + 1) || ISEXEC (addr + 2) || ISEXEC (addr + 3)) - return; - do_put_mem_long (m, l); + uae_u32 *m; + + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + + if (ISILLEGAL_LONG (addr)) + { + enforcer_display_hit (L"LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + if (addr != 0x100) + set_special (SPCFLAG_TRAP); + } + if (ISEXEC (addr) || ISEXEC (addr + 1) || ISEXEC (addr + 2) || ISEXEC (addr + 3)) + return; + do_put_mem_long (m, l); } void REGPARAM2 chipmem_wput2 (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); - if (ISILLEGAL_WORD (addr)) - { - enforcer_display_hit (L"WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - set_special (SPCFLAG_TRAP); - } - if (ISEXEC (addr) || ISEXEC (addr + 1)) - return; - do_put_mem_word (m, w); + if (ISILLEGAL_WORD (addr)) + { + enforcer_display_hit (L"WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + set_special (SPCFLAG_TRAP); + } + if (ISEXEC (addr) || ISEXEC (addr + 1)) + return; + do_put_mem_word (m, w); } void REGPARAM2 chipmem_bput2 (uaecptr addr, uae_u32 b) { - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - - if (ISILLEGAL_BYTE (addr)) - { - enforcer_display_hit (L"BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) - set_special (SPCFLAG_TRAP); - } - if (ISEXEC (addr)) - return; - chipmemory[addr] = b; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + + if (ISILLEGAL_BYTE (addr)) + { + enforcer_display_hit (L"BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) + set_special (SPCFLAG_TRAP); + } + if (ISEXEC (addr)) + return; + chipmemory[addr] = b; } int REGPARAM2 chipmem_check2 (uaecptr addr, uae_u32 size) { - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - return (addr + size) <= allocated_chipmem; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + return (addr + size) <= allocated_chipmem; } uae_u8 * REGPARAM2 chipmem_xlate2 (uaecptr addr) { - addr -= chipmem_start & chipmem_mask; - addr &= chipmem_mask; - return chipmemory + addr; + addr -= chipmem_start & chipmem_mask; + addr &= chipmem_mask; + return chipmemory + addr; } uae_u32 REGPARAM2 dummy_lget2 (uaecptr addr) { - special_mem_r; - enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET), addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return 0; - } - return 0xbadedeef; + special_mem_r; + enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET), addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return 0; + } + return 0xbadedeef; } #ifdef JIT @@ -508,143 +508,143 @@ static int warned_JIT_0xF10000 = 0; uae_u32 REGPARAM2 dummy_wget2 (uaecptr addr) { - special_mem_r; + special_mem_r; #ifdef JIT - if (addr >= 0x00F10000 && addr <= 0x00F7FFFF) { - if (!warned_JIT_0xF10000) { - warned_JIT_0xF10000 = 1; - enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (addr >= 0x00F10000 && addr <= 0x00F7FFFF) { + if (!warned_JIT_0xF10000) { + warned_JIT_0xF10000 = 1; + enforcer_display_hit (L"LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + } + return 0; } - return 0; - } #endif - enforcer_display_hit (L"WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return 0; - } - return 0xbadf; + enforcer_display_hit (L"WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return 0; + } + return 0xbadf; } uae_u32 REGPARAM2 dummy_bget2 (uaecptr addr) { - special_mem_r; - enforcer_display_hit (L"BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return 0; - } - return 0xbadedeef; + special_mem_r; + enforcer_display_hit (L"BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return 0; + } + return 0xbadedeef; } void REGPARAM2 dummy_lput2 (uaecptr addr, uae_u32 l) { - special_mem_w; - enforcer_display_hit (L"LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return; - } + special_mem_w; + enforcer_display_hit (L"LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return; + } } void REGPARAM2 dummy_wput2 (uaecptr addr, uae_u32 w) { - special_mem_w; - enforcer_display_hit (L"WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return; - } + special_mem_w; + enforcer_display_hit (L"WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return; + } } void REGPARAM2 dummy_bput2 (uaecptr addr, uae_u32 b) { - special_mem_w; - enforcer_display_hit (L"BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - if (enforcermode & 1) { - set_special (SPCFLAG_TRAP); - return; - } + special_mem_w; + enforcer_display_hit (L"BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + if (enforcermode & 1) { + set_special (SPCFLAG_TRAP); + return; + } } int REGPARAM2 dummy_check2 (uaecptr addr, uae_u32 size) { - special_mem_r; - enforcer_display_hit (L"CHECK from ",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); - return 0; + special_mem_r; + enforcer_display_hit (L"CHECK from ",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr); + return 0; } /************************************************************* - enable the enforcer like support, maybe later this make MMU - exceptions so enforcer can use it. Returns 1 if enforcer - is enabled +enable the enforcer like support, maybe later this make MMU +exceptions so enforcer can use it. Returns 1 if enforcer +is enabled *************************************************************/ int enforcer_enable (int enfmode) { - extern addrbank chipmem_bank, dummy_bank; - enforcermode = enfmode; - if (!enforcer_installed) { - saved_dummy_lget = dummy_bank.lget; - saved_dummy_wget = dummy_bank.wget; - saved_dummy_bget = dummy_bank.bget; - saved_dummy_lput = dummy_bank.lput; - saved_dummy_wput = dummy_bank.wput; - saved_dummy_bput = dummy_bank.bput; - saved_chipmem_lget = chipmem_bank.lget; - saved_chipmem_wget = chipmem_bank.wget; - saved_chipmem_bget = chipmem_bank.bget; - saved_chipmem_lput = chipmem_bank.lput; - saved_chipmem_wput = chipmem_bank.wput; - saved_chipmem_bput = chipmem_bank.bput; - saved_chipmem_xlate = chipmem_bank.xlateaddr; - saved_chipmem_check = chipmem_bank.check; - - dummy_bank.lget = dummy_lget2; - dummy_bank.wget = dummy_wget2; - dummy_bank.bget = dummy_bget2; - dummy_bank.lput = dummy_lput2; - dummy_bank.wput = dummy_wput2; - dummy_bank.bput = dummy_bput2; - chipmem_bank.lget = chipmem_lget2; - chipmem_bank.wget = chipmem_wget2; - chipmem_bank.bget = chipmem_bget2; - chipmem_bank.lput = chipmem_lput2; - chipmem_bank.wput = chipmem_wput2; - chipmem_bank.bput = chipmem_bput2; - chipmem_bank.xlateaddr = chipmem_xlate2; - chipmem_bank.check = chipmem_check2; - - enforcer_installed = 1; - } - return 1; + extern addrbank chipmem_bank, dummy_bank; + enforcermode = enfmode; + if (!enforcer_installed) { + saved_dummy_lget = dummy_bank.lget; + saved_dummy_wget = dummy_bank.wget; + saved_dummy_bget = dummy_bank.bget; + saved_dummy_lput = dummy_bank.lput; + saved_dummy_wput = dummy_bank.wput; + saved_dummy_bput = dummy_bank.bput; + saved_chipmem_lget = chipmem_bank.lget; + saved_chipmem_wget = chipmem_bank.wget; + saved_chipmem_bget = chipmem_bank.bget; + saved_chipmem_lput = chipmem_bank.lput; + saved_chipmem_wput = chipmem_bank.wput; + saved_chipmem_bput = chipmem_bank.bput; + saved_chipmem_xlate = chipmem_bank.xlateaddr; + saved_chipmem_check = chipmem_bank.check; + + dummy_bank.lget = dummy_lget2; + dummy_bank.wget = dummy_wget2; + dummy_bank.bget = dummy_bget2; + dummy_bank.lput = dummy_lput2; + dummy_bank.wput = dummy_wput2; + dummy_bank.bput = dummy_bput2; + chipmem_bank.lget = chipmem_lget2; + chipmem_bank.wget = chipmem_wget2; + chipmem_bank.bget = chipmem_bget2; + chipmem_bank.lput = chipmem_lput2; + chipmem_bank.wput = chipmem_wput2; + chipmem_bank.bput = chipmem_bput2; + chipmem_bank.xlateaddr = chipmem_xlate2; + chipmem_bank.check = chipmem_check2; + + enforcer_installed = 1; + } + return 1; } /************************************************************* - Disable Enforcer like support +Disable Enforcer like support *************************************************************/ int enforcer_disable (void) { - if (enforcer_installed) { - dummy_bank.lget = saved_dummy_lget; - dummy_bank.wget = saved_dummy_wget; - dummy_bank.bget = saved_dummy_bget; - dummy_bank.lput = saved_dummy_lput; - dummy_bank.wput = saved_dummy_wput; - dummy_bank.bput = saved_dummy_bput; - chipmem_bank.lget = saved_chipmem_lget; - chipmem_bank.wget = saved_chipmem_wget; - chipmem_bank.bget = saved_chipmem_bget; - chipmem_bank.lput = saved_chipmem_lput; - chipmem_bank.wput = saved_chipmem_wput; - chipmem_bank.bput = saved_chipmem_bput; - chipmem_bank.xlateaddr = saved_chipmem_xlate; - chipmem_bank.check = saved_chipmem_check; - - enforcer_installed = 0; - } - return 1; + if (enforcer_installed) { + dummy_bank.lget = saved_dummy_lget; + dummy_bank.wget = saved_dummy_wget; + dummy_bank.bget = saved_dummy_bget; + dummy_bank.lput = saved_dummy_lput; + dummy_bank.wput = saved_dummy_wput; + dummy_bank.bput = saved_dummy_bput; + chipmem_bank.lget = saved_chipmem_lget; + chipmem_bank.wget = saved_chipmem_wget; + chipmem_bank.bget = saved_chipmem_bget; + chipmem_bank.lput = saved_chipmem_lput; + chipmem_bank.wput = saved_chipmem_wput; + chipmem_bank.bput = saved_chipmem_bput; + chipmem_bank.xlateaddr = saved_chipmem_xlate; + chipmem_bank.check = saved_chipmem_check; + + enforcer_installed = 0; + } + return 1; } #endif diff --git a/epsonprinter.c b/epsonprinter.c index 3c6d6cbc..27a986b2 100644 --- a/epsonprinter.c +++ b/epsonprinter.c @@ -1,24 +1,24 @@ /* - * Copyright (C) 2002-2004 The DOSBox Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ +* Copyright (C) 2002-2004 The DOSBox Team +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ /* - * Converted to WinUAE by Toni Wilen 2009 - */ +* Converted to WinUAE by Toni Wilen 2009 +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -95,269 +95,269 @@ static int pins = 24; // Various ASCII codepage to unicode maps static const Bit16u cp437Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp737Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x0391,0x0392,0x0393,0x0394,0x0395,0x0396,0x0397,0x0398,0x0399,0x039a,0x039b,0x039c,0x039d,0x039e,0x039f,0x03a0, -0x03a1,0x03a3,0x03a4,0x03a5,0x03a6,0x03a7,0x03a8,0x03a9,0x03b1,0x03b2,0x03b3,0x03b4,0x03b5,0x03b6,0x03b7,0x03b8, -0x03b9,0x03ba,0x03bb,0x03bc,0x03bd,0x03be,0x03bf,0x03c0,0x03c1,0x03c3,0x03c2,0x03c4,0x03c5,0x03c6,0x03c7,0x03c8, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03c9,0x03ac,0x03ad,0x03ae,0x03ca,0x03af,0x03cc,0x03cd,0x03cb,0x03ce,0x0386,0x0388,0x0389,0x038a,0x038c,0x038e, -0x038f,0x00b1,0x2265,0x2264,0x03aa,0x03ab,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0391,0x0392,0x0393,0x0394,0x0395,0x0396,0x0397,0x0398,0x0399,0x039a,0x039b,0x039c,0x039d,0x039e,0x039f,0x03a0, + 0x03a1,0x03a3,0x03a4,0x03a5,0x03a6,0x03a7,0x03a8,0x03a9,0x03b1,0x03b2,0x03b3,0x03b4,0x03b5,0x03b6,0x03b7,0x03b8, + 0x03b9,0x03ba,0x03bb,0x03bc,0x03bd,0x03be,0x03bf,0x03c0,0x03c1,0x03c3,0x03c2,0x03c4,0x03c5,0x03c6,0x03c7,0x03c8, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03c9,0x03ac,0x03ad,0x03ae,0x03ca,0x03af,0x03cc,0x03cd,0x03cb,0x03ce,0x0386,0x0388,0x0389,0x038a,0x038c,0x038e, + 0x038f,0x00b1,0x2265,0x2264,0x03aa,0x03ab,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp775Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x0106,0x00fc,0x00e9,0x0101,0x00e4,0x0123,0x00e5,0x0107,0x0142,0x0113,0x0156,0x0157,0x012b,0x0179,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x014d,0x00f6,0x0122,0x00a2,0x015a,0x015b,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x00d7,0x00a4, -0x0100,0x012a,0x00f3,0x017b,0x017c,0x017a,0x201d,0x00a6,0x00a9,0x00ae,0x00ac,0x00bd,0x00bc,0x0141,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x0104,0x010c,0x0118,0x0116,0x2563,0x2551,0x2557,0x255d,0x012e,0x0160,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x0172,0x016a,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x017d, -0x0105,0x010d,0x0119,0x0117,0x012f,0x0161,0x0173,0x016b,0x017e,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x00d3,0x00df,0x014c,0x0143,0x00f5,0x00d5,0x00b5,0x0144,0x0136,0x0137,0x013b,0x013c,0x0146,0x0112,0x0145,0x2019, -0x00ad,0x00b1,0x201c,0x00be,0x00b6,0x00a7,0x00f7,0x201e,0x00b0,0x2219,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0106,0x00fc,0x00e9,0x0101,0x00e4,0x0123,0x00e5,0x0107,0x0142,0x0113,0x0156,0x0157,0x012b,0x0179,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x014d,0x00f6,0x0122,0x00a2,0x015a,0x015b,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x00d7,0x00a4, + 0x0100,0x012a,0x00f3,0x017b,0x017c,0x017a,0x201d,0x00a6,0x00a9,0x00ae,0x00ac,0x00bd,0x00bc,0x0141,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x0104,0x010c,0x0118,0x0116,0x2563,0x2551,0x2557,0x255d,0x012e,0x0160,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x0172,0x016a,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x017d, + 0x0105,0x010d,0x0119,0x0117,0x012f,0x0161,0x0173,0x016b,0x017e,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x00d3,0x00df,0x014c,0x0143,0x00f5,0x00d5,0x00b5,0x0144,0x0136,0x0137,0x013b,0x013c,0x0146,0x0112,0x0145,0x2019, + 0x00ad,0x00b1,0x201c,0x00be,0x00b6,0x00a7,0x00f7,0x201e,0x00b0,0x2219,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp850Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x00d7,0x0192, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x00ae,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x00c0,0x00a9,0x2563,0x2551,0x2557,0x255d,0x00a2,0x00a5,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x00e3,0x00c3,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, -0x00f0,0x00d0,0x00ca,0x00cb,0x00c8,0x0131,0x00cd,0x00ce,0x00cf,0x2518,0x250c,0x2588,0x2584,0x00a6,0x00cc,0x2580, -0x00d3,0x00df,0x00d4,0x00d2,0x00f5,0x00d5,0x00b5,0x00fe,0x00de,0x00da,0x00db,0x00d9,0x00fd,0x00dd,0x00af,0x00b4, -0x00ad,0x00b1,0x2017,0x00be,0x00b6,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x00d7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x00ae,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x00c0,0x00a9,0x2563,0x2551,0x2557,0x255d,0x00a2,0x00a5,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x00e3,0x00c3,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, + 0x00f0,0x00d0,0x00ca,0x00cb,0x00c8,0x0131,0x00cd,0x00ce,0x00cf,0x2518,0x250c,0x2588,0x2584,0x00a6,0x00cc,0x2580, + 0x00d3,0x00df,0x00d4,0x00d2,0x00f5,0x00d5,0x00b5,0x00fe,0x00de,0x00da,0x00db,0x00d9,0x00fd,0x00dd,0x00af,0x00b4, + 0x00ad,0x00b1,0x2017,0x00be,0x00b6,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp852Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x016f,0x0107,0x00e7,0x0142,0x00eb,0x0150,0x0151,0x00ee,0x0179,0x00c4,0x0106, -0x00c9,0x0139,0x013a,0x00f4,0x00f6,0x013d,0x013e,0x015a,0x015b,0x00d6,0x00dc,0x0164,0x0165,0x0141,0x00d7,0x010d, -0x00e1,0x00ed,0x00f3,0x00fa,0x0104,0x0105,0x017d,0x017e,0x0118,0x0119,0x00ac,0x017a,0x010c,0x015f,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x011a,0x015e,0x2563,0x2551,0x2557,0x255d,0x017b,0x017c,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x0102,0x0103,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, -0x0111,0x0110,0x010e,0x00cb,0x010f,0x0147,0x00cd,0x00ce,0x011b,0x2518,0x250c,0x2588,0x2584,0x0162,0x016e,0x2580, -0x00d3,0x00df,0x00d4,0x0143,0x0144,0x0148,0x0160,0x0161,0x0154,0x00da,0x0155,0x0170,0x00fd,0x00dd,0x0163,0x00b4, -0x00ad,0x02dd,0x02db,0x02c7,0x02d8,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x02d9,0x0171,0x0158,0x0159,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x016f,0x0107,0x00e7,0x0142,0x00eb,0x0150,0x0151,0x00ee,0x0179,0x00c4,0x0106, + 0x00c9,0x0139,0x013a,0x00f4,0x00f6,0x013d,0x013e,0x015a,0x015b,0x00d6,0x00dc,0x0164,0x0165,0x0141,0x00d7,0x010d, + 0x00e1,0x00ed,0x00f3,0x00fa,0x0104,0x0105,0x017d,0x017e,0x0118,0x0119,0x00ac,0x017a,0x010c,0x015f,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x011a,0x015e,0x2563,0x2551,0x2557,0x255d,0x017b,0x017c,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x0102,0x0103,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, + 0x0111,0x0110,0x010e,0x00cb,0x010f,0x0147,0x00cd,0x00ce,0x011b,0x2518,0x250c,0x2588,0x2584,0x0162,0x016e,0x2580, + 0x00d3,0x00df,0x00d4,0x0143,0x0144,0x0148,0x0160,0x0161,0x0154,0x00da,0x0155,0x0170,0x00fd,0x00dd,0x0163,0x00b4, + 0x00ad,0x02dd,0x02db,0x02c7,0x02d8,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x02d9,0x0171,0x0158,0x0159,0x25a0,0x00a0 }; static const Bit16u cp855Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x0452,0x0402,0x0453,0x0403,0x0451,0x0401,0x0454,0x0404,0x0455,0x0405,0x0456,0x0406,0x0457,0x0407,0x0458,0x0408, -0x0459,0x0409,0x045a,0x040a,0x045b,0x040b,0x045c,0x040c,0x045e,0x040e,0x045f,0x040f,0x044e,0x042e,0x044a,0x042a, -0x0430,0x0410,0x0431,0x0411,0x0446,0x0426,0x0434,0x0414,0x0435,0x0415,0x0444,0x0424,0x0433,0x0413,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x0445,0x0425,0x0438,0x0418,0x2563,0x2551,0x2557,0x255d,0x0439,0x0419,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x043a,0x041a,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, -0x043b,0x041b,0x043c,0x041c,0x043d,0x041d,0x043e,0x041e,0x043f,0x2518,0x250c,0x2588,0x2584,0x041f,0x044f,0x2580, -0x042f,0x0440,0x0420,0x0441,0x0421,0x0442,0x0422,0x0443,0x0423,0x0436,0x0416,0x0432,0x0412,0x044c,0x042c,0x2116, -0x00ad,0x044b,0x042b,0x0437,0x0417,0x0448,0x0428,0x044d,0x042d,0x0449,0x0429,0x0447,0x0427,0x00a7,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0452,0x0402,0x0453,0x0403,0x0451,0x0401,0x0454,0x0404,0x0455,0x0405,0x0456,0x0406,0x0457,0x0407,0x0458,0x0408, + 0x0459,0x0409,0x045a,0x040a,0x045b,0x040b,0x045c,0x040c,0x045e,0x040e,0x045f,0x040f,0x044e,0x042e,0x044a,0x042a, + 0x0430,0x0410,0x0431,0x0411,0x0446,0x0426,0x0434,0x0414,0x0435,0x0415,0x0444,0x0424,0x0433,0x0413,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x0445,0x0425,0x0438,0x0418,0x2563,0x2551,0x2557,0x255d,0x0439,0x0419,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x043a,0x041a,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, + 0x043b,0x041b,0x043c,0x041c,0x043d,0x041d,0x043e,0x041e,0x043f,0x2518,0x250c,0x2588,0x2584,0x041f,0x044f,0x2580, + 0x042f,0x0440,0x0420,0x0441,0x0421,0x0442,0x0422,0x0443,0x0423,0x0436,0x0416,0x0432,0x0412,0x044c,0x042c,0x2116, + 0x00ad,0x044b,0x042b,0x0437,0x0417,0x0448,0x0428,0x044d,0x042d,0x0449,0x0429,0x0447,0x0427,0x00a7,0x25a0,0x00a0 }; static const Bit16u cp857Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x0131,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x0130,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x015e,0x015f, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x011e,0x011f,0x00bf,0x00ae,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x00c0,0x00a9,0x2563,0x2551,0x2557,0x255d,0x00a2,0x00a5,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x00e3,0x00c3,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, -0x00ba,0x00aa,0x00ca,0x00cb,0x00c8,0x0000,0x00cd,0x00ce,0x00cf,0x2518,0x250c,0x2588,0x2584,0x00a6,0x00cc,0x2580, -0x00d3,0x00df,0x00d4,0x00d2,0x00f5,0x00d5,0x00b5,0x0000,0x00d7,0x00da,0x00db,0x00d9,0x00ec,0x00ff,0x00af,0x00b4, -0x00ad,0x00b1,0x0000,0x00be,0x00b6,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x0131,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x0130,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x015e,0x015f, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x011e,0x011f,0x00bf,0x00ae,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x00c1,0x00c2,0x00c0,0x00a9,0x2563,0x2551,0x2557,0x255d,0x00a2,0x00a5,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x00e3,0x00c3,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x00a4, + 0x00ba,0x00aa,0x00ca,0x00cb,0x00c8,0x0000,0x00cd,0x00ce,0x00cf,0x2518,0x250c,0x2588,0x2584,0x00a6,0x00cc,0x2580, + 0x00d3,0x00df,0x00d4,0x00d2,0x00f5,0x00d5,0x00b5,0x0000,0x00d7,0x00da,0x00db,0x00d9,0x00ec,0x00ff,0x00af,0x00b4, + 0x00ad,0x00b1,0x0000,0x00be,0x00b6,0x00a7,0x00f7,0x00b8,0x00b0,0x00a8,0x00b7,0x00b9,0x00b3,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp860Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e3,0x00e0,0x00c1,0x00e7,0x00ea,0x00ca,0x00e8,0x00cd,0x00d4,0x00ec,0x00c3,0x00c2, -0x00c9,0x00c0,0x00c8,0x00f4,0x00f5,0x00f2,0x00da,0x00f9,0x00cc,0x00d5,0x00dc,0x00a2,0x00a3,0x00d9,0x20a7,0x00d3, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x00d2,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e3,0x00e0,0x00c1,0x00e7,0x00ea,0x00ca,0x00e8,0x00cd,0x00d4,0x00ec,0x00c3,0x00c2, + 0x00c9,0x00c0,0x00c8,0x00f4,0x00f5,0x00f2,0x00da,0x00f9,0x00cc,0x00d5,0x00dc,0x00a2,0x00a3,0x00d9,0x20a7,0x00d3, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x00d2,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp861Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00d0,0x00f0,0x00de,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00fe,0x00fb,0x00dd,0x00fd,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x20a7,0x0192, -0x00e1,0x00ed,0x00f3,0x00fa,0x00c1,0x00cd,0x00d3,0x00da,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00d0,0x00f0,0x00de,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00fe,0x00fb,0x00dd,0x00fd,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00c1,0x00cd,0x00d3,0x00da,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp862Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x05d0,0x05d1,0x05d2,0x05d3,0x05d4,0x05d5,0x05d6,0x05d7,0x05d8,0x05d9,0x05da,0x05db,0x05dc,0x05dd,0x05de,0x05df, -0x05e0,0x05e1,0x05e2,0x05e3,0x05e4,0x05e5,0x05e6,0x05e7,0x05e8,0x05e9,0x05ea,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x05d0,0x05d1,0x05d2,0x05d3,0x05d4,0x05d5,0x05d6,0x05d7,0x05d8,0x05d9,0x05da,0x05db,0x05dc,0x05dd,0x05de,0x05df, + 0x05e0,0x05e1,0x05e2,0x05e3,0x05e4,0x05e5,0x05e6,0x05e7,0x05e8,0x05e9,0x05ea,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp863Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00c2,0x00e0,0x00b6,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x2017,0x00c0,0x00a7, -0x00c9,0x00c8,0x00ca,0x00f4,0x00cb,0x00cf,0x00fb,0x00f9,0x00a4,0x00d4,0x00dc,0x00a2,0x00a3,0x00d9,0x00db,0x0192, -0x00a6,0x00b4,0x00f3,0x00fa,0x00a8,0x00b8,0x00b3,0x00af,0x00ce,0x2310,0x00ac,0x00bd,0x00bc,0x00be,0x00ab,0x00bb, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00c2,0x00e0,0x00b6,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x2017,0x00c0,0x00a7, + 0x00c9,0x00c8,0x00ca,0x00f4,0x00cb,0x00cf,0x00fb,0x00f9,0x00a4,0x00d4,0x00dc,0x00a2,0x00a3,0x00d9,0x00db,0x0192, + 0x00a6,0x00b4,0x00f3,0x00fa,0x00a8,0x00b8,0x00b3,0x00af,0x00ce,0x2310,0x00ac,0x00bd,0x00bc,0x00be,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp864Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x066a,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00b0,0x00b7,0x2219,0x221a,0x2592,0x2500,0x2502,0x253c,0x2524,0x252c,0x251c,0x2534,0x2510,0x250c,0x2514,0x2518, -0x03b2,0x221e,0x03c6,0x00b1,0x00bd,0x00bc,0x2248,0x00ab,0x00bb,0xfef7,0xfef8,0x0000,0x0000,0xfefb,0xfefc,0x0000, -0x00a0,0x00ad,0xfe82,0x00a3,0x00a4,0xfe84,0x0000,0x0000,0xfe8e,0xfe8f,0xfe95,0xfe99,0x060c,0xfe9d,0xfea1,0xfea5, -0x0660,0x0661,0x0662,0x0663,0x0664,0x0665,0x0666,0x0667,0x0668,0x0669,0xfed1,0x061b,0xfeb1,0xfeb5,0xfeb9,0x061f, -0x00a2,0xfe80,0xfe81,0xfe83,0xfe85,0xfeca,0xfe8b,0xfe8d,0xfe91,0xfe93,0xfe97,0xfe9b,0xfe9f,0xfea3,0xfea7,0xfea9, -0xfeab,0xfead,0xfeaf,0xfeb3,0xfeb7,0xfebb,0xfebf,0xfec1,0xfec5,0xfecb,0xfecf,0x00a6,0x00ac,0x00f7,0x00d7,0xfec9, -0x0640,0xfed3,0xfed7,0xfedb,0xfedf,0xfee3,0xfee7,0xfeeb,0xfeed,0xfeef,0xfef3,0xfebd,0xfecc,0xfece,0xfecd,0xfee1, -0xfe7d,0x0651,0xfee5,0xfee9,0xfeec,0xfef0,0xfef2,0xfed0,0xfed5,0xfef5,0xfef6,0xfedd,0xfed9,0xfef1,0x25a0, + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x066a,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00b0,0x00b7,0x2219,0x221a,0x2592,0x2500,0x2502,0x253c,0x2524,0x252c,0x251c,0x2534,0x2510,0x250c,0x2514,0x2518, + 0x03b2,0x221e,0x03c6,0x00b1,0x00bd,0x00bc,0x2248,0x00ab,0x00bb,0xfef7,0xfef8,0x0000,0x0000,0xfefb,0xfefc,0x0000, + 0x00a0,0x00ad,0xfe82,0x00a3,0x00a4,0xfe84,0x0000,0x0000,0xfe8e,0xfe8f,0xfe95,0xfe99,0x060c,0xfe9d,0xfea1,0xfea5, + 0x0660,0x0661,0x0662,0x0663,0x0664,0x0665,0x0666,0x0667,0x0668,0x0669,0xfed1,0x061b,0xfeb1,0xfeb5,0xfeb9,0x061f, + 0x00a2,0xfe80,0xfe81,0xfe83,0xfe85,0xfeca,0xfe8b,0xfe8d,0xfe91,0xfe93,0xfe97,0xfe9b,0xfe9f,0xfea3,0xfea7,0xfea9, + 0xfeab,0xfead,0xfeaf,0xfeb3,0xfeb7,0xfebb,0xfebf,0xfec1,0xfec5,0xfecb,0xfecf,0x00a6,0x00ac,0x00f7,0x00d7,0xfec9, + 0x0640,0xfed3,0xfed7,0xfedb,0xfedf,0xfee3,0xfee7,0xfeeb,0xfeed,0xfeef,0xfef3,0xfebd,0xfecc,0xfece,0xfecd,0xfee1, + 0xfe7d,0x0651,0xfee5,0xfee9,0xfeec,0xfef0,0xfef2,0xfed0,0xfed5,0xfef5,0xfef6,0xfedd,0xfed9,0xfef1,0x25a0, }; static const Bit16u cp865Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, -0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x20a7,0x0192, -0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00a4, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, -0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00f8,0x00a3,0x00d8,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00a4, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 }; static const Bit16u cp866Map[256] = { -0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, -0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, -0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, -0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, -0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, -0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, -0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, -0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, -0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,0x041f, -0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,0x0428,0x0429,0x042a,0x042b,0x042c,0x042d,0x042e,0x042f, -0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,0x043f, -0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, -0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, -0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, -0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,0x0448,0x0449,0x044a,0x044b,0x044c,0x044d,0x044e,0x044f, -0x0401,0x0451,0x0404,0x0454,0x0407,0x0457,0x040e,0x045e,0x00b0,0x2219,0x00b7,0x221a,0x2116,0x00a4,0x25a0,0x00a0 + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,0x041f, + 0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,0x0428,0x0429,0x042a,0x042b,0x042c,0x042d,0x042e,0x042f, + 0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,0x043f, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,0x0448,0x0449,0x044a,0x044b,0x044c,0x044d,0x044e,0x044f, + 0x0401,0x0451,0x0404,0x0454,0x0407,0x0457,0x040e,0x045e,0x00b0,0x2219,0x00b7,0x221a,0x2116,0x00a4,0x25a0,0x00a0 }; static const Bit16u codepages[15] = {0, 437, 932, 850, 851, 853, 855, 860, 863, 865, 852, 857, 862, 864, 866}; @@ -472,8 +472,8 @@ static void updateFont(void) } if (!ft) { - write_log(L"EPSONPRINTER: No freetype6.dll, unable to load font %s\n", fontName); - curFont = NULL; + write_log(L"EPSONPRINTER: No freetype6.dll, unable to load font %s\n", fontName); + curFont = NULL; } else if (FT_New_Face(FTlib, fontName, 0, &curFont)) { char windowsdir[MAX_DPATH]; GetWindowsDirectoryA (windowsdir, sizeof windowsdir); @@ -481,20 +481,20 @@ static void updateFont(void) strcat (windowsdir, fontName); if (FT_New_Face(FTlib, windowsdir, 0, &curFont)) { - GetWindowsDirectoryA (windowsdir, sizeof windowsdir); - strcat (windowsdir, "\\Fonts\\"); - strcat (windowsdir, "times.ttf"); - if (FT_New_Face(FTlib, windowsdir, 0, &curFont)) { - write_log(L"Unable to load font %s\n", fontName); - curFont = NULL; - } + GetWindowsDirectoryA (windowsdir, sizeof windowsdir); + strcat (windowsdir, "\\Fonts\\"); + strcat (windowsdir, "times.ttf"); + if (FT_New_Face(FTlib, windowsdir, 0, &curFont)) { + write_log(L"Unable to load font %s\n", fontName); + curFont = NULL; + } } } if (!multipoint) { actcpi = cpi; - + if (cpi != 10 && !(style & STYLE_CONDENSED)) { horizPoints *= (Real64)10/(Real64)cpi; @@ -509,7 +509,7 @@ static void updateFont(void) horizPoints *= (Real64)10/(Real64)17.14; vertPoints *= (Real64)10/(Real64)17.14; } - + if (cpi == 12 && (style & STYLE_CONDENSED)) { actcpi = 20.0; @@ -548,8 +548,8 @@ static void updateFont(void) if (curFont) - FT_Set_Char_Size(curFont, (Bit16u)horizPoints*64, (Bit16u)vertPoints*64, dpi, dpi); - + FT_Set_Char_Size(curFont, (Bit16u)horizPoints*64, (Bit16u)vertPoints*64, dpi, dpi); + if (style & STYLE_ITALICS || charTables[curCharTable] == 0) { FT_Matrix matrix; @@ -558,24 +558,24 @@ static void updateFont(void) matrix.yx = 0; matrix.yy = 0x10000L; if (curFont) - FT_Set_Transform(curFont, &matrix, 0); + FT_Set_Transform(curFont, &matrix, 0); } } static void getfname (TCHAR *fname) { - TCHAR tmp[MAX_DPATH]; - int number = 0; - - fetch_screenshotpath (tmp, sizeof tmp / sizeof (TCHAR)); - for (;;) { - FILE *fp; - _stprintf (fname, L"%sPRINT_%03d.png", tmp, number); - if ((fp = _tfopen (fname, L"rb")) == NULL) - return; - number++; - fclose (fp); - } + TCHAR tmp[MAX_DPATH]; + int number = 0; + + fetch_screenshotpath (tmp, sizeof tmp / sizeof (TCHAR)); + for (;;) { + FILE *fp; + _stprintf (fname, L"%sPRINT_%03d.png", tmp, number); + if ((fp = _tfopen (fname, L"rb")) == NULL) + return; + number++; + fclose (fp); + } } static void outputPage(void) @@ -594,14 +594,14 @@ static void outputPage(void) Bit32u topX, topY; if (page_w > physW) - scaleW = (Real64)page_w / (Real64)physW; + scaleW = (Real64)page_w / (Real64)physW; else - scaleW = (Real64)physW / (Real64)page_w; - + scaleW = (Real64)physW / (Real64)page_w; + if (page_h > physH) - scaleH = (Real64)page_h / (Real64)physH; + scaleH = (Real64)page_h / (Real64)physH; else - scaleH = (Real64)physH / (Real64)page_h; + scaleH = (Real64)physH / (Real64)page_h; memHDC = CreateCompatibleDC(printerDC); bitmap = CreateCompatibleBitmap(memHDC, page_w, page_h); @@ -635,7 +635,7 @@ static void outputPage(void) SetPixel(memHDC, x, y, color); } } - + StretchBlt(printerDC, 0, 0, physW, physH, memHDC, 0, 0, page_w, page_h, SRCCOPY); EndPage(printerDC); @@ -650,7 +650,7 @@ static void outputPage(void) EndDoc(printerDC); outputHandle = NULL; } - + DeleteDC(memHDC); #else write_log(L"EPSONPRINTER: Direct printing not supported under this OS\n"); @@ -688,7 +688,7 @@ static void outputPage(void) /* Finalize the initing of png library */ png_init_io(png_ptr, fp); png_set_compression_level(png_ptr,Z_BEST_COMPRESSION); - + /* set other zlib parameters */ png_set_compression_mem_level(png_ptr, 8); png_set_compression_strategy(png_ptr,Z_DEFAULT_STRATEGY); @@ -696,7 +696,7 @@ static void outputPage(void) png_set_compression_method(png_ptr, 8); png_set_compression_buffer_size(png_ptr, 8192); - + png_set_IHDR(png_ptr, info_ptr, page_w, page_h, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); @@ -707,7 +707,7 @@ static void outputPage(void) palette[i].blue = 255 - i; } png_set_PLTE(png_ptr, info_ptr, palette,256); - + // Allocate an array of scanline pointers row_pointers = (png_bytep*)malloc(page_h*sizeof(png_bytep)); for (i=0; i Each eight characters - for (i=0;i<32;i++) - horiztabs[i] = i*8*(1/(Real64)cpi); - numHorizTabs = 32; - - numVertTabs = 255; + Bitu i; + curX = curY = 0.0; + ESCSeen = false; + ESCCmd = 0; + numParam = neededParam = 0; + topMargin = 0.0; + leftMargin = 0.0; + rightMargin = pageWidth = defaultPageWidth; + bottomMargin = pageHeight = defaultPageHeight; + lineSpacing = (Real64)1/6; + cpi = 10.0; + curCharTable = 1; + style = 0; + extraIntraSpace = 0.0; + printUpperContr = true; + bitGraph.remBytes = 0; + densk = 0; + densl = 1; + densy = 2; + densz = 3; + charTables[0] = 0; // Italics + charTables[1] = charTables[2] = charTables[3] = 437; + definedUnit = -1; + multipoint = false; + multiPointSize = 0.0; + multicpi = 0.0; + hmi = -1.0; + msb = 255; + numPrintAsChar = 0; + LQtypeFace = roman; + + selectCodepage(charTables[curCharTable]); + + updateFont(); + + newPage(false); + + // Default tabs => Each eight characters + for (i=0;i<32;i++) + horiztabs[i] = i*8*(1/(Real64)cpi); + numHorizTabs = 32; + + numVertTabs = 255; } static void resetPrinterHard(void) @@ -864,7 +864,7 @@ static printer_close(void) xfree (page); page = NULL; if (ft) - FT_Done_FreeType(FTlib); + FT_Done_FreeType(FTlib); write_log (L"EPSONPRINTER: end\n"); } #if defined (WIN32) @@ -908,10 +908,10 @@ static void setupBitImage(Bit8u dens, Bit16u numCols) bitGraph.bytesColumn = 1; break; case 5: - bitGraph.horizDens = 80; - bitGraph.vertDens = 72; - bitGraph.adjacent = true; - bitGraph.bytesColumn = 1; + bitGraph.horizDens = 80; + bitGraph.vertDens = 72; + bitGraph.adjacent = true; + bitGraph.bytesColumn = 1; break; case 6: bitGraph.horizDens = 90; @@ -995,7 +995,7 @@ static void setupBitImage(Bit8u dens, Bit16u numCols) write_log(L"EPSONPRINTER: Unsupported bit image density %i\n", dens); } if (pins == 9) - bitGraph.vertDens = 72; + bitGraph.vertDens = 72; bitGraph.remBytes = numCols * bitGraph.bytesColumn; bitGraph.readBytesColumn = 0; } @@ -1218,19 +1218,19 @@ static int processCommandChar(Bit8u ch) if (params[0] & 0x02) style |= STYLE_PROP; if (params[0] & 0x04) - style |= STYLE_CONDENSED; + style |= STYLE_CONDENSED; if (params[0] & 0x08) - style |= STYLE_BOLD; + style |= STYLE_BOLD; if (params[0] & 0x10) - style |= STYLE_DOUBLESTRIKE; + style |= STYLE_DOUBLESTRIKE; if (params[0] & 0x20) - style |= STYLE_DOUBLEWIDTH; + style |= STYLE_DOUBLEWIDTH; if (params[0] & 0x40) - style |= STYLE_ITALICS; + style |= STYLE_ITALICS; if (params[0] & 0x80) { score = SCORE_SINGLE; - style |= STYLE_UNDERLINE; + style |= STYLE_UNDERLINE; } hmi = -1; @@ -1493,7 +1493,7 @@ static int processCommandChar(Bit8u ch) break; case 0x72: // Select printing color (ESC r) if (params[0] != 0) - write_log(L"EPSONPRINTER: Color printing not supported\n"); + write_log(L"EPSONPRINTER: Color printing not supported\n"); break; case 0x73: // Select low-speed mode (ESC s) // Ignore @@ -1747,9 +1747,9 @@ static int processCommandChar(Bit8u ch) static void printBitGraph(Bit8u ch) { - Bitu i; - Bitu pixsizeX, pixsizeY; - Real64 oldY = curY; + Bitu i; + Bitu pixsizeX, pixsizeY; + Real64 oldY = curY; bitGraph.column[bitGraph.readBytesColumn++] = ch; bitGraph.remBytes--; @@ -1790,9 +1790,9 @@ static void printBitGraph(Bit8u ch) // Advance to the left if (bitGraph.adjacent == false) - curX += (Real64)0.5/(Real64)bitGraph.horizDens; + curX += (Real64)0.5/(Real64)bitGraph.horizDens; else - curX += (Real64)1/(Real64)bitGraph.horizDens; + curX += (Real64)1/(Real64)bitGraph.horizDens; } @@ -1887,7 +1887,7 @@ static void printChar(Bit8u ch) // Find the glyph for the char to render index = FT_Get_Char_Index(curFont, curMap[ch]); - + // Load the glyph FT_Load_Glyph(curFont, index, FT_LOAD_DEFAULT); @@ -1962,34 +1962,34 @@ static int isBlank(void) static int epson_ft (void) { - if (!ft) - ft = WIN32_LoadLibrary (L"freetype6.dll"); - if (!ft) { - write_log (L"EPSONPRINTER: freetype6.dll not found. Text output disabled."); - return 0; - } - return 1; + if (!ft) + ft = WIN32_LoadLibrary (L"freetype6.dll"); + if (!ft) { + write_log (L"EPSONPRINTER: freetype6.dll not found. Text output disabled."); + return 0; + } + return 1; } void epson_printchar(uae_u8 c) { - printChar (c); + printChar (c); } int epson_init(int type) { - if (type == PARALLEL_MATRIX_EPSON9) - pins = 9; - else - pins = 48; - epson_ft (); - write_log (L"EPSONPRINTER%d: start\n", pins); - return printer_init(300, 83, 117, L"png", 0, pins); + if (type == PARALLEL_MATRIX_EPSON9) + pins = 9; + else + pins = 48; + epson_ft (); + write_log (L"EPSONPRINTER%d: start\n", pins); + return printer_init(300, 83, 117, L"png", 0, pins); } void epson_close(void) { - if (page && !isBlank ()) { - outputPage(); - } - printer_close(); + if (page && !isBlank ()) { + outputPage(); + } + printer_close(); } diff --git a/ersatz.c b/ersatz.c index 2d7c65ef..fdb9297e 100644 --- a/ersatz.c +++ b/ersatz.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * A "replacement" for a missing Kickstart - * Warning! Q&D - * - * (c) 1995 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* A "replacement" for a missing Kickstart +* Warning! Q&D +* +* (c) 1995 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -35,242 +35,242 @@ static int already_failed = 0; void init_ersatz_rom (uae_u8 *data) { - uae_u8 *end = data + 262144 - 16; - /* cpu emulation uses these now */ - end[1] = 0x18; - end[3] = 0x19; - end[5] = 0x1a; - end[7] = 0x1b; - end[9] = 0x1c; - end[11] = 0x1d; - end[13] = 0x1e; - end[15] = 0x1f; - - *data++ = 0x00; *data++ = 0x08; /* initial SP */ - *data++ = 0x00; *data++ = 0x00; - *data++ = 0x00; *data++ = 0xF8; /* initial PC */ - *data++ = 0x00; *data++ = 0x08; - - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_INIT; - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_NIMP; - - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_LOOP; - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_DOIO; - - *data++ = 0x4E; *data++ = 0x75; - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_SERVEINT; - *data++ = 0x4E; *data++ = 0x73; - - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_AVAILMEM; - *data++ = 0x4E; *data++ = 0x75; - *data++ = 0xFF; *data++ = 0x0D; - - *data++ = 0x00; *data++ = EOP_ALLOCMEM; - *data++ = 0x4E; *data++ = 0x75; - *data++ = 0xFF; *data++ = 0x0D; - *data++ = 0x00; *data++ = EOP_ALLOCABS; - - *data++ = 0x4E; *data++ = 0x75; + uae_u8 *end = data + 262144 - 16; + /* cpu emulation uses these now */ + end[1] = 0x18; + end[3] = 0x19; + end[5] = 0x1a; + end[7] = 0x1b; + end[9] = 0x1c; + end[11] = 0x1d; + end[13] = 0x1e; + end[15] = 0x1f; + + *data++ = 0x00; *data++ = 0x08; /* initial SP */ + *data++ = 0x00; *data++ = 0x00; + *data++ = 0x00; *data++ = 0xF8; /* initial PC */ + *data++ = 0x00; *data++ = 0x08; + + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_INIT; + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_NIMP; + + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_LOOP; + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_DOIO; + + *data++ = 0x4E; *data++ = 0x75; + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_SERVEINT; + *data++ = 0x4E; *data++ = 0x73; + + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_AVAILMEM; + *data++ = 0x4E; *data++ = 0x75; + *data++ = 0xFF; *data++ = 0x0D; + + *data++ = 0x00; *data++ = EOP_ALLOCMEM; + *data++ = 0x4E; *data++ = 0x75; + *data++ = 0xFF; *data++ = 0x0D; + *data++ = 0x00; *data++ = EOP_ALLOCABS; + + *data++ = 0x4E; *data++ = 0x75; } void ersatz_chipcopy (void) { - /* because CPU emulation is updated and retrieves SP and PC from chip ram */ - memcpy (chipmemory, kickmemory, 256); + /* because CPU emulation is updated and retrieves SP and PC from chip ram */ + memcpy (chipmemory, kickmemory, 256); } static void ersatz_failed (void) { - if (already_failed) - return; - already_failed = 1; - notify_user (NUMSG_KICKREPNO); - uae_restart (-1, NULL); + if (already_failed) + return; + already_failed = 1; + notify_user (NUMSG_KICKREPNO); + uae_restart (-1, NULL); } static void ersatz_doio (void) { - uaecptr request = m68k_areg (regs, 1); - switch (get_word (request + 0x1C)) { - case 9: /* TD_MOTOR is harmless */ - return; - case 2: case 0x8002: /* READ commands */ - break; - - default: - write_log (L"Only CMD_READ supported in DoIO()\n"); - ersatz_failed (); - } - { - uaecptr dest = get_long (request + 0x28); - int start = get_long (request + 0x2C) / 512; - int nsecs = get_long (request + 0x24) / 512; - int tr = start / 11; - int sec = start % 11; - while (nsecs--) { - DISK_ersatz_read (tr, sec, dest); - dest += 512; - if (++sec == 11) - sec = 0, tr++; + uaecptr request = m68k_areg (regs, 1); + switch (get_word (request + 0x1C)) { + case 9: /* TD_MOTOR is harmless */ + return; + case 2: case 0x8002: /* READ commands */ + break; + + default: + write_log (L"Only CMD_READ supported in DoIO()\n"); + ersatz_failed (); + } + { + uaecptr dest = get_long (request + 0x28); + int start = get_long (request + 0x2C) / 512; + int nsecs = get_long (request + 0x24) / 512; + int tr = start / 11; + int sec = start % 11; + while (nsecs--) { + DISK_ersatz_read (tr, sec, dest); + dest += 512; + if (++sec == 11) + sec = 0, tr++; + } } - } } static void ersatz_init (void) { - int f; - uaecptr request; - uaecptr a; - - already_failed = 0; - write_log (L"initializing kickstart replacement\n"); - if (disk_empty (0)) { - already_failed = 1; - notify_user (NUMSG_KICKREP); - uae_restart (-1, NULL); - return; - } - - regs.s = 0; - /* Set some interrupt vectors */ - for (a = 8; a < 0xC0; a += 4) { - put_long (a, 0xF8001A); - } - regs.isp = regs.msp = regs.usp = 0x800; - m68k_areg (regs, 7) = 0x80000; - regs.intmask = 0; - - /* Build a dummy execbase */ - put_long (4, m68k_areg (regs, 6) = 0x676); - put_byte (0x676 + 0x129, 0); - for (f = 1; f < 105; f++) { - put_word (0x676 - 6*f, 0x4EF9); - put_long (0x676 - 6*f + 2, 0xF8000C); - } - /* Some "supported" functions */ - put_long (0x676 - 456 + 2, 0xF80014); - put_long (0x676 - 216 + 2, 0xF80020); - put_long (0x676 - 198 + 2, 0xF80026); - put_long (0x676 - 204 + 2, 0xF8002c); - put_long (0x676 - 210 + 2, 0xF8002a); - - /* Build an IORequest */ - request = 0x800; - put_word (request + 0x1C, 2); - put_long (request + 0x28, 0x4000); - put_long (request + 0x2C, 0); - put_long (request + 0x24, 0x200 * 4); - m68k_areg (regs, 1) = request; - ersatz_doio (); - /* kickstart disk loader */ - if (get_long (0x4000) == 0x4b49434b) { - /* a kickstart disk was found in drive 0! */ - write_log (L"Loading Kickstart rom image from Kickstart disk\n"); - /* print some notes... */ - write_log (L"NOTE: if UAE crashes set CPU to 68000 and/or chipmem size to 512KB!\n"); - - /* read rom image from kickstart disk */ - put_word (request + 0x1C, 2); - put_long (request + 0x28, 0xF80000); - put_long (request + 0x2C, 0x200); - put_long (request + 0x24, 0x200 * 512); - m68k_areg (regs, 1) = request; - ersatz_doio (); + int f; + uaecptr request; + uaecptr a; + + already_failed = 0; + write_log (L"initializing kickstart replacement\n"); + if (disk_empty (0)) { + already_failed = 1; + notify_user (NUMSG_KICKREP); + uae_restart (-1, NULL); + return; + } - /* read rom image once again to mirror address space. - not elegant, but it works... */ + regs.s = 0; + /* Set some interrupt vectors */ + for (a = 8; a < 0xC0; a += 4) { + put_long (a, 0xF8001A); + } + regs.isp = regs.msp = regs.usp = 0x800; + m68k_areg (regs, 7) = 0x80000; + regs.intmask = 0; + + /* Build a dummy execbase */ + put_long (4, m68k_areg (regs, 6) = 0x676); + put_byte (0x676 + 0x129, 0); + for (f = 1; f < 105; f++) { + put_word (0x676 - 6*f, 0x4EF9); + put_long (0x676 - 6*f + 2, 0xF8000C); + } + /* Some "supported" functions */ + put_long (0x676 - 456 + 2, 0xF80014); + put_long (0x676 - 216 + 2, 0xF80020); + put_long (0x676 - 198 + 2, 0xF80026); + put_long (0x676 - 204 + 2, 0xF8002c); + put_long (0x676 - 210 + 2, 0xF8002a); + + /* Build an IORequest */ + request = 0x800; put_word (request + 0x1C, 2); - put_long (request + 0x28, 0xFC0000); - put_long (request + 0x2C, 0x200); - put_long (request + 0x24, 0x200 * 512); + put_long (request + 0x28, 0x4000); + put_long (request + 0x2C, 0); + put_long (request + 0x24, 0x200 * 4); m68k_areg (regs, 1) = request; ersatz_doio (); + /* kickstart disk loader */ + if (get_long (0x4000) == 0x4b49434b) { + /* a kickstart disk was found in drive 0! */ + write_log (L"Loading Kickstart rom image from Kickstart disk\n"); + /* print some notes... */ + write_log (L"NOTE: if UAE crashes set CPU to 68000 and/or chipmem size to 512KB!\n"); + + /* read rom image from kickstart disk */ + put_word (request + 0x1C, 2); + put_long (request + 0x28, 0xF80000); + put_long (request + 0x2C, 0x200); + put_long (request + 0x24, 0x200 * 512); + m68k_areg (regs, 1) = request; + ersatz_doio (); + + /* read rom image once again to mirror address space. + not elegant, but it works... */ + put_word (request + 0x1C, 2); + put_long (request + 0x28, 0xFC0000); + put_long (request + 0x2C, 0x200); + put_long (request + 0x24, 0x200 * 512); + m68k_areg (regs, 1) = request; + ersatz_doio (); + + disk_eject (0); + + m68k_setpc (0xFC0002); + fill_prefetch_slow (); + uae_reset (0); + ersatzkickfile = 0; + return; + } - disk_eject (0); - - m68k_setpc (0xFC0002); + m68k_setpc (0x400C); fill_prefetch_slow (); - uae_reset (0); - ersatzkickfile = 0; - return; - } - - m68k_setpc (0x400C); - fill_prefetch_slow (); - - /* Init the hardware */ - put_long (0x3000, 0xFFFFFFFEul); - put_long (0xDFF080, 0x3000); - put_word (0xDFF088, 0); - put_word (0xDFF096, 0xE390); - put_word (0xDFF09A, 0xE02C); - put_word (0xDFF09E, 0x0000); - put_word (0xDFF092, 0x0038); - put_word (0xDFF094, 0x00D0); - put_word (0xDFF08E, 0x2C81); - put_word (0xDFF090, 0xF4C1); - put_word (0xDFF02A, 0x8000); - - put_byte (0xBFD100, 0xF7); - put_byte (0xBFEE01, 0); - put_byte (0xBFEF01, 0x08); - put_byte (0xBFDE00, 0x04); - put_byte (0xBFDF00, 0x84); - put_byte (0xBFDD00, 0x9F); - put_byte (0xBFED01, 0x9F); + + /* Init the hardware */ + put_long (0x3000, 0xFFFFFFFEul); + put_long (0xDFF080, 0x3000); + put_word (0xDFF088, 0); + put_word (0xDFF096, 0xE390); + put_word (0xDFF09A, 0xE02C); + put_word (0xDFF09E, 0x0000); + put_word (0xDFF092, 0x0038); + put_word (0xDFF094, 0x00D0); + put_word (0xDFF08E, 0x2C81); + put_word (0xDFF090, 0xF4C1); + put_word (0xDFF02A, 0x8000); + + put_byte (0xBFD100, 0xF7); + put_byte (0xBFEE01, 0); + put_byte (0xBFEF01, 0x08); + put_byte (0xBFDE00, 0x04); + put_byte (0xBFDF00, 0x84); + put_byte (0xBFDD00, 0x9F); + put_byte (0xBFED01, 0x9F); } void ersatz_perform (uae_u16 what) { - switch (what) { - case EOP_INIT: - ersatz_init (); - break; - - case EOP_SERVEINT: - { - uae_u16 intreq = get_word (0xDFF01E); - /* Just reset all the interrupt request bits */ - if (intreq & 0x0008) - get_byte (0xbfed01); /* possible keyboard interrupt */ - put_word (0xDFF09C, intreq & 0x3FFF); - break; - } - - case EOP_DOIO: - ersatz_doio (); - break; - - case EOP_AVAILMEM: - m68k_dreg (regs, 0) = m68k_dreg (regs, 1) & 4 ? 0 : 0x70000; - break; - - case EOP_ALLOCMEM: - m68k_dreg (regs, 0) = m68k_dreg (regs, 1) & 4 ? 0 : 0x0F000; - break; - - case EOP_ALLOCABS: - m68k_dreg (regs, 0) = m68k_areg (regs, 1); - break; - - case EOP_NIMP: - write_log (L"Unimplemented Kickstart function called\n"); - ersatz_failed (); - - /* fall through */ - case EOP_LOOP: - m68k_setpc (0xF80010); - break; - - case EOP_OPENLIB: - default: - write_log (L"Internal error. Giving up.\n"); - ersatz_failed (); - } + switch (what) { + case EOP_INIT: + ersatz_init (); + break; + + case EOP_SERVEINT: + { + uae_u16 intreq = get_word (0xDFF01E); + /* Just reset all the interrupt request bits */ + if (intreq & 0x0008) + get_byte (0xbfed01); /* possible keyboard interrupt */ + put_word (0xDFF09C, intreq & 0x3FFF); + break; + } + + case EOP_DOIO: + ersatz_doio (); + break; + + case EOP_AVAILMEM: + m68k_dreg (regs, 0) = m68k_dreg (regs, 1) & 4 ? 0 : 0x70000; + break; + + case EOP_ALLOCMEM: + m68k_dreg (regs, 0) = m68k_dreg (regs, 1) & 4 ? 0 : 0x0F000; + break; + + case EOP_ALLOCABS: + m68k_dreg (regs, 0) = m68k_areg (regs, 1); + break; + + case EOP_NIMP: + write_log (L"Unimplemented Kickstart function called\n"); + ersatz_failed (); + + /* fall through */ + case EOP_LOOP: + m68k_setpc (0xF80010); + break; + + case EOP_OPENLIB: + default: + write_log (L"Internal error. Giving up.\n"); + ersatz_failed (); + } } diff --git a/expansion.c b/expansion.c index a2838f59..455e9610 100644 --- a/expansion.c +++ b/expansion.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * AutoConfig (tm) Expansions (ZorroII/III) - * - * Copyright 1996,1997 Stefan Reinauer - * Copyright 1997 Brian King - * - added gfxcard code - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* AutoConfig (tm) Expansions (ZorroII/III) +* +* Copyright 1996,1997 Stefan Reinauer +* Copyright 1997 Brian King +* - added gfxcard code +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -144,23 +144,23 @@ static uae_u16 uae_id; /* ********************************************************** */ /* Please note: ZorroIII implementation seems to work different - * than described in the HRM. This claims that ZorroIII config - * address is 0xff000000 while the ZorroII config space starts - * at 0x00e80000. In reality, both, Z2 and Z3 cards are - * configured in the ZorroII config space. Kickstart 3.1 doesn't - * even do a single read or write access to the ZorroIII space. - * The original Amiga include files tell the same as the HRM. - * ZorroIII: If you set ext_size in er_Flags and give a Z2-size - * in er_Type you can very likely add some ZorroII address space - * to a ZorroIII card on a real Amiga. This is not implemented - * yet. - * -- Stefan - * - * Surprising that 0xFF000000 isn't used. Maybe it depends on the - * ROM. Anyway, the HRM says that Z3 cards may appear in Z2 config - * space, so what we are doing here is correct. - * -- Bernd - */ +* than described in the HRM. This claims that ZorroIII config +* address is 0xff000000 while the ZorroII config space starts +* at 0x00e80000. In reality, both, Z2 and Z3 cards are +* configured in the ZorroII config space. Kickstart 3.1 doesn't +* even do a single read or write access to the ZorroIII space. +* The original Amiga include files tell the same as the HRM. +* ZorroIII: If you set ext_size in er_Flags and give a Z2-size +* in er_Type you can very likely add some ZorroII address space +* to a ZorroIII card on a real Amiga. This is not implemented +* yet. +* -- Stefan +* +* Surprising that 0xFF000000 isn't used. Maybe it depends on the +* ROM. Anyway, the HRM says that Z3 cards may appear in Z2 config +* space, so what we are doing here is correct. +* -- Bernd +*/ /* Autoconfig address space at 0xE80000 */ static uae_u8 expamem[65536]; @@ -176,212 +176,212 @@ static void REGPARAM3 expamem_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 expamem_bput (uaecptr, uae_u32) REGPARAM; addrbank expamem_bank = { - expamem_lget, expamem_wget, expamem_bget, - expamem_lput, expamem_wput, expamem_bput, - default_xlate, default_check, NULL, L"Autoconfig", - dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE + expamem_lget, expamem_wget, expamem_bget, + expamem_lput, expamem_wput, expamem_bput, + default_xlate, default_check, NULL, L"Autoconfig", + dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE }; static void expamem_map_clear (void) { - write_log (L"expamem_map_clear() got called. Shouldn't happen.\n"); + write_log (L"expamem_map_clear() got called. Shouldn't happen.\n"); } static void expamem_init_clear (void) { - memset (expamem, 0xff, sizeof expamem); + memset (expamem, 0xff, sizeof expamem); } /* autoconfig area is "non-existing" after last device */ static void expamem_init_clear_zero (void) { - map_banks (&dummy_bank, 0xe8, 1, 0); + map_banks (&dummy_bank, 0xe8, 1, 0); } static void expamem_init_clear2 (void) { - expamem_init_clear_zero (); - ecard = cardno; + expamem_init_clear_zero (); + ecard = cardno; } static void expamem_init_last (void) { - expamem_init_clear2 (); - write_log (L"Memory map after autoconfig:\n"); - memory_map_dump(); + expamem_init_clear2 (); + write_log (L"Memory map after autoconfig:\n"); + memory_map_dump(); } static uae_u32 REGPARAM2 expamem_lget (uaecptr addr) { - write_log (L"warning: READ.L from address $%lx PC=%x\n", addr, M68K_GETPC); - return (expamem_wget (addr) << 16) | expamem_wget (addr + 2); + write_log (L"warning: READ.L from address $%lx PC=%x\n", addr, M68K_GETPC); + return (expamem_wget (addr) << 16) | expamem_wget (addr + 2); } static uae_u32 REGPARAM2 expamem_wget (uaecptr addr) { - uae_u32 v = (expamem_bget (addr) << 8) | expamem_bget (addr + 1); - write_log (L"warning: READ.W from address $%lx=%04x PC=%x\n", addr, v & 0xffff, M68K_GETPC); - return v; + uae_u32 v = (expamem_bget (addr) << 8) | expamem_bget (addr + 1); + write_log (L"warning: READ.W from address $%lx=%04x PC=%x\n", addr, v & 0xffff, M68K_GETPC); + return v; } static uae_u32 REGPARAM2 expamem_bget (uaecptr addr) { - uae_u8 b; + uae_u8 b; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 0xFFFF; - b = expamem[addr]; - //write_log (L"%08x=%02X\n", addr, b); - return b; + addr &= 0xFFFF; + b = expamem[addr]; + //write_log (L"%08x=%02X\n", addr, b); + return b; } static void REGPARAM2 expamem_write (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= 0xffff; - if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { - expamem[addr] = (value & 0xf0); - expamem[addr + 2] = (value & 0x0f) << 4; - } else { - expamem[addr] = ~(value & 0xf0); - expamem[addr + 2] = ~((value & 0x0f) << 4); - } + addr &= 0xffff; + if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { + expamem[addr] = (value & 0xf0); + expamem[addr + 2] = (value & 0x0f) << 4; + } else { + expamem[addr] = ~(value & 0xf0); + expamem[addr + 2] = ~((value & 0x0f) << 4); + } } static int REGPARAM2 expamem_type (void) { - return ((expamem[0] | expamem[2] >> 4) & 0xc0); + return ((expamem[0] | expamem[2] >> 4) & 0xc0); } static void REGPARAM2 expamem_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - write_log (L"warning: WRITE.L to address $%lx : value $%lx\n", addr, value); + write_log (L"warning: WRITE.L to address $%lx : value $%lx\n", addr, value); } static void REGPARAM2 expamem_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - value &= 0xffff; - if (ecard >= cardno) - return; - if (expamem_type() != zorroIII) - write_log (L"warning: WRITE.W to address $%lx : value $%x\n", addr, value); - else { - switch (addr & 0xff) { - case 0x44: - if (expamem_type() == zorroIII) { - uae_u32 p1, p2; - // +Bernd Roesch & Toni Wilen - p1 = get_word (regs.regs[11] + 0x20); - if (expamem[0] & add_memory) { - // Z3 RAM expansion - if (z3num == 0) - p2 = z3fastmem_start >> 16; - else - p2 = z3fastmem2_start >> 16; - z3num++; - } else { - // Z3 P96 RAM - p2 = p96ram_start >> 16; + value &= 0xffff; + if (ecard >= cardno) + return; + if (expamem_type() != zorroIII) + write_log (L"warning: WRITE.W to address $%lx : value $%x\n", addr, value); + else { + switch (addr & 0xff) { + case 0x44: + if (expamem_type() == zorroIII) { + uae_u32 p1, p2; + // +Bernd Roesch & Toni Wilen + p1 = get_word (regs.regs[11] + 0x20); + if (expamem[0] & add_memory) { + // Z3 RAM expansion + if (z3num == 0) + p2 = z3fastmem_start >> 16; + else + p2 = z3fastmem2_start >> 16; + z3num++; + } else { + // Z3 P96 RAM + p2 = p96ram_start >> 16; + } + put_word (regs.regs[11] + 0x20, p2); + put_word (regs.regs[11] + 0x28, p2); + // -Bernd Roesch + expamem_hi = p2; + (*card_map[ecard]) (); + ecard++; + if (p1 != p2) + write_log (L" Card %d remapped %04x0000 -> %04x0000\n", ecard, p1, p2); + write_log (L" Card %d (Zorro%s) done.\n", ecard, expamem_type () == 0xc0 ? L"II" : L"III"); + if (ecard < cardno) + (*card_init[ecard]) (); + else + expamem_init_clear2 (); + } + break; } - put_word (regs.regs[11] + 0x20, p2); - put_word (regs.regs[11] + 0x28, p2); - // -Bernd Roesch - expamem_hi = p2; - (*card_map[ecard]) (); - ecard++; - if (p1 != p2) - write_log (L" Card %d remapped %04x0000 -> %04x0000\n", ecard, p1, p2); - write_log (L" Card %d (Zorro%s) done.\n", ecard, expamem_type () == 0xc0 ? L"II" : L"III"); - if (ecard < cardno) - (*card_init[ecard]) (); - else - expamem_init_clear2 (); - } - break; } - } } static void REGPARAM2 expamem_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (ecard >= cardno) - return; - value &= 0xff; - switch (addr & 0xff) { - case 0x30: - case 0x32: - expamem_hi = 0; - expamem_lo = 0; - expamem_write (0x48, 0x00); - break; - - case 0x48: - if (expamem_type () == zorroII) { - expamem_hi = value; - (*card_map[ecard]) (); - write_log (L" Card %d (Zorro%s) done.\n", ecard + 1, expamem_type () == 0xc0 ? L"II" : L"III"); - ++ecard; - if (ecard < cardno) - (*card_init[ecard]) (); - else - expamem_init_clear2 (); - } else if (expamem_type() == zorroIII) - expamem_lo = value; - break; - - case 0x4a: - if (expamem_type () == zorroII) - expamem_lo = value; - break; - - case 0x4c: - write_log (L" Card %d (Zorro%s) had no success.\n", ecard + 1, expamem_type () == 0xc0 ? L"II" : L"III"); - ++ecard; - if (ecard < cardno) - (*card_init[ecard]) (); - else - expamem_init_clear2 (); - break; - } + if (ecard >= cardno) + return; + value &= 0xff; + switch (addr & 0xff) { + case 0x30: + case 0x32: + expamem_hi = 0; + expamem_lo = 0; + expamem_write (0x48, 0x00); + break; + + case 0x48: + if (expamem_type () == zorroII) { + expamem_hi = value; + (*card_map[ecard]) (); + write_log (L" Card %d (Zorro%s) done.\n", ecard + 1, expamem_type () == 0xc0 ? L"II" : L"III"); + ++ecard; + if (ecard < cardno) + (*card_init[ecard]) (); + else + expamem_init_clear2 (); + } else if (expamem_type() == zorroIII) + expamem_lo = value; + break; + + case 0x4a: + if (expamem_type () == zorroII) + expamem_lo = value; + break; + + case 0x4c: + write_log (L" Card %d (Zorro%s) had no success.\n", ecard + 1, expamem_type () == 0xc0 ? L"II" : L"III"); + ++ecard; + if (ecard < cardno) + (*card_init[ecard]) (); + else + expamem_init_clear2 (); + break; + } } #ifdef CD32 static void expamem_map_cd32fmv (void) { - uaecptr start = ((expamem_hi | (expamem_lo >> 4)) << 16); - cd32_fmv_init (start); + uaecptr start = ((expamem_hi | (expamem_lo >> 4)) << 16); + cd32_fmv_init (start); } static void expamem_init_cd32fmv (void) { - int ids[] = { 23, -1 }; - struct romlist *rl = getromlistbyids (ids); - struct romdata *rd; - struct zfile *z; - - expamem_init_clear (); - if (!rl) - return; - write_log (L"CD32 FMV ROM '%s' %d.%d\n", rl->path, rl->rd->ver, rl->rd->rev); - rd = rl->rd; - z = read_rom (&rd); - if (z) { - zfile_fread (expamem, 128, 1, z); - zfile_fclose (z); - } + int ids[] = { 23, -1 }; + struct romlist *rl = getromlistbyids (ids); + struct romdata *rd; + struct zfile *z; + + expamem_init_clear (); + if (!rl) + return; + write_log (L"CD32 FMV ROM '%s' %d.%d\n", rl->path, rl->rd->ver, rl->rd->rev); + rd = rl->rd; + z = read_rom (&rd); + if (z) { + zfile_fread (expamem, 128, 1, z); + zfile_fclose (z); + } } #endif @@ -389,8 +389,8 @@ static void expamem_init_cd32fmv (void) /* ********************************************************** */ /* - * Fast Memory - */ +* Fast Memory +*/ static uae_u32 fastmem_mask; @@ -408,81 +408,81 @@ static uae_u8 *fastmemory; static uae_u32 REGPARAM2 fastmem_lget (uaecptr addr) { - uae_u8 *m; - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - m = fastmemory + addr; - return do_get_mem_long ((uae_u32 *)m); + uae_u8 *m; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + m = fastmemory + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 fastmem_wget (uaecptr addr) { - uae_u8 *m; - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - m = fastmemory + addr; - return do_get_mem_word ((uae_u16 *)m); + uae_u8 *m; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + m = fastmemory + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 fastmem_bget (uaecptr addr) { - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - return fastmemory[addr]; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + return fastmemory[addr]; } static void REGPARAM2 fastmem_lput (uaecptr addr, uae_u32 l) { - uae_u8 *m; - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - m = fastmemory + addr; - do_put_mem_long ((uae_u32 *)m, l); + uae_u8 *m; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + m = fastmemory + addr; + do_put_mem_long ((uae_u32 *)m, l); } static void REGPARAM2 fastmem_wput (uaecptr addr, uae_u32 w) { - uae_u8 *m; - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - m = fastmemory + addr; - do_put_mem_word ((uae_u16 *)m, w); + uae_u8 *m; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + m = fastmemory + addr; + do_put_mem_word ((uae_u16 *)m, w); } static void REGPARAM2 fastmem_bput (uaecptr addr, uae_u32 b) { - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - fastmemory[addr] = b; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + fastmemory[addr] = b; } static int REGPARAM2 fastmem_check (uaecptr addr, uae_u32 size) { - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - return (addr + size) <= allocated_fastmem; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + return (addr + size) <= allocated_fastmem; } static uae_u8 *REGPARAM2 fastmem_xlate (uaecptr addr) { - addr -= fastmem_start & fastmem_mask; - addr &= fastmem_mask; - return fastmemory + addr; + addr -= fastmem_start & fastmem_mask; + addr &= fastmem_mask; + return fastmemory + addr; } addrbank fastmem_bank = { - fastmem_lget, fastmem_wget, fastmem_bget, - fastmem_lput, fastmem_wput, fastmem_bput, - fastmem_xlate, fastmem_check, NULL, L"Fast memory", - fastmem_lget, fastmem_wget, ABFLAG_RAM + fastmem_lget, fastmem_wget, fastmem_bget, + fastmem_lput, fastmem_wput, fastmem_bput, + fastmem_xlate, fastmem_check, NULL, L"Fast memory", + fastmem_lget, fastmem_wget, ABFLAG_RAM }; #ifdef CATWEASEL /* - * Catweasel ZorroII - */ +* Catweasel ZorroII +*/ static uae_u32 REGPARAM3 catweasel_lget (uaecptr) REGPARAM; static uae_u32 REGPARAM3 catweasel_wget (uaecptr) REGPARAM; @@ -499,109 +499,109 @@ static uae_u32 catweasel_start; static uae_u32 REGPARAM2 catweasel_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - write_log (L"catweasel_lget @%08X!\n",addr); - return 0; + write_log (L"catweasel_lget @%08X!\n",addr); + return 0; } static uae_u32 REGPARAM2 catweasel_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - write_log (L"catweasel_wget @%08X!\n",addr); - return 0; + write_log (L"catweasel_wget @%08X!\n",addr); + return 0; } static uae_u32 REGPARAM2 catweasel_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= catweasel_start & catweasel_mask; - addr &= catweasel_mask; - return catweasel_do_bget (addr); + addr -= catweasel_start & catweasel_mask; + addr &= catweasel_mask; + return catweasel_do_bget (addr); } static void REGPARAM2 catweasel_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - write_log (L"catweasel_lput @%08X=%08X!\n",addr,l); + write_log (L"catweasel_lput @%08X=%08X!\n",addr,l); } static void REGPARAM2 catweasel_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - write_log (L"catweasel_wput @%08X=%04X!\n",addr,w); + write_log (L"catweasel_wput @%08X=%04X!\n",addr,w); } static void REGPARAM2 catweasel_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr -= catweasel_start & catweasel_mask; - addr &= catweasel_mask; - catweasel_do_bput (addr, b); + addr -= catweasel_start & catweasel_mask; + addr &= catweasel_mask; + catweasel_do_bput (addr, b); } static int REGPARAM2 catweasel_check (uaecptr addr, uae_u32 size) { - return 0; + return 0; } static uae_u8 *REGPARAM2 catweasel_xlate (uaecptr addr) { - write_log (L"catweasel_xlate @%08X size %08X\n", addr); - return 0; + write_log (L"catweasel_xlate @%08X size %08X\n", addr); + return 0; } static addrbank catweasel_bank = { - catweasel_lget, catweasel_wget, catweasel_bget, - catweasel_lput, catweasel_wput, catweasel_bput, - catweasel_xlate, catweasel_check, NULL, L"Catweasel", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + catweasel_lget, catweasel_wget, catweasel_bget, + catweasel_lput, catweasel_wput, catweasel_bput, + catweasel_xlate, catweasel_check, NULL, L"Catweasel", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static void expamem_map_catweasel (void) { - catweasel_start = ((expamem_hi | (expamem_lo >> 4)) << 16); - map_banks (&catweasel_bank, catweasel_start >> 16, 1, 0); - write_log (L"Catweasel MK%d: mapped @$%lx\n", cwc.type, catweasel_start); + catweasel_start = ((expamem_hi | (expamem_lo >> 4)) << 16); + map_banks (&catweasel_bank, catweasel_start >> 16, 1, 0); + write_log (L"Catweasel MK%d: mapped @$%lx\n", cwc.type, catweasel_start); } static void expamem_init_catweasel (void) { - uae_u8 productid = cwc.type >= CATWEASEL_TYPE_MK3 ? 66 : 200; - uae_u16 vendorid = cwc.type >= CATWEASEL_TYPE_MK3 ? 4626 : 5001; + uae_u8 productid = cwc.type >= CATWEASEL_TYPE_MK3 ? 66 : 200; + uae_u16 vendorid = cwc.type >= CATWEASEL_TYPE_MK3 ? 4626 : 5001; - catweasel_mask = (cwc.type >= CATWEASEL_TYPE_MK3) ? 0xffff : 0x1ffff; + catweasel_mask = (cwc.type >= CATWEASEL_TYPE_MK3) ? 0xffff : 0x1ffff; - expamem_init_clear (); + expamem_init_clear (); - expamem_write (0x00, (cwc.type >= CATWEASEL_TYPE_MK3 ? Z2_MEM_64KB : Z2_MEM_128KB) | zorroII); + expamem_write (0x00, (cwc.type >= CATWEASEL_TYPE_MK3 ? Z2_MEM_64KB : Z2_MEM_128KB) | zorroII); - expamem_write (0x04, productid); + expamem_write (0x04, productid); - expamem_write (0x08, no_shutup); + expamem_write (0x08, no_shutup); - expamem_write (0x10, vendorid >> 8); - expamem_write (0x14, vendorid & 0xff); + expamem_write (0x10, vendorid >> 8); + expamem_write (0x14, vendorid & 0xff); - expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ - expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ - expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ - expamem_write (0x24, 0x00); /* ser.no. Byte 3 */ + expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ + expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ + expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ + expamem_write (0x24, 0x00); /* ser.no. Byte 3 */ - expamem_write (0x28, 0x00); /* Rom-Offset hi */ - expamem_write (0x2c, 0x00); /* ROM-Offset lo */ + expamem_write (0x28, 0x00); /* Rom-Offset hi */ + expamem_write (0x2c, 0x00); /* ROM-Offset lo */ - expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ + expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ } #endif @@ -609,9 +609,9 @@ static void expamem_init_catweasel (void) #ifdef FILESYS /* - * Filesystem device ROM - * This is very simple, the Amiga shouldn't be doing things with it. - */ +* Filesystem device ROM +* This is very simple, the Amiga shouldn't be doing things with it. +*/ static uae_u32 REGPARAM3 filesys_lget (uaecptr) REGPARAM; static uae_u32 REGPARAM3 filesys_wget (uaecptr) REGPARAM; @@ -625,73 +625,73 @@ uae_u8 *filesysory; static uae_u32 REGPARAM2 filesys_lget (uaecptr addr) { - uae_u8 *m; + uae_u8 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= filesys_start & 65535; - addr &= 65535; - m = filesysory + addr; - return do_get_mem_long ((uae_u32 *)m); + addr -= filesys_start & 65535; + addr &= 65535; + m = filesysory + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 filesys_wget (uaecptr addr) { - uae_u8 *m; + uae_u8 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= filesys_start & 65535; - addr &= 65535; - m = filesysory + addr; - return do_get_mem_word ((uae_u16 *)m); + addr -= filesys_start & 65535; + addr &= 65535; + m = filesysory + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 filesys_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr -= filesys_start & 65535; - addr &= 65535; - return filesysory[addr]; + addr -= filesys_start & 65535; + addr &= 65535; + return filesysory[addr]; } static void REGPARAM2 filesys_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - write_log (L"filesys_lput called PC=%p\n", M68K_GETPC); + write_log (L"filesys_lput called PC=%p\n", M68K_GETPC); } static void REGPARAM2 filesys_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - write_log (L"filesys_wput called PC=%p\n", M68K_GETPC); + write_log (L"filesys_wput called PC=%p\n", M68K_GETPC); } static void REGPARAM2 filesys_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } static addrbank filesys_bank = { - filesys_lget, filesys_wget, filesys_bget, - filesys_lput, filesys_wput, filesys_bput, - default_xlate, default_check, NULL, L"Filesystem Autoconfig Area", - dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE + filesys_lget, filesys_wget, filesys_bget, + filesys_lput, filesys_wput, filesys_bput, + default_xlate, default_check, NULL, L"Filesystem Autoconfig Area", + dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE }; #endif /* FILESYS */ /* - * Z3fastmem Memory - */ +* Z3fastmem Memory +*/ static uae_u32 z3fastmem_mask, z3fastmem2_mask; uaecptr z3fastmem_start, z3fastmem2_start; @@ -699,129 +699,129 @@ static uae_u8 *z3fastmem, *z3fastmem2; static uae_u32 REGPARAM2 z3fastmem_lget (uaecptr addr) { - uae_u8 *m; - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - m = z3fastmem + addr; - return do_get_mem_long ((uae_u32 *)m); + uae_u8 *m; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + m = z3fastmem + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 z3fastmem_wget (uaecptr addr) { - uae_u8 *m; - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - m = z3fastmem + addr; - return do_get_mem_word ((uae_u16 *)m); + uae_u8 *m; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + m = z3fastmem + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 z3fastmem_bget (uaecptr addr) { - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - return z3fastmem[addr]; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + return z3fastmem[addr]; } static void REGPARAM2 z3fastmem_lput (uaecptr addr, uae_u32 l) { - uae_u8 *m; - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - m = z3fastmem + addr; - do_put_mem_long ((uae_u32 *)m, l); + uae_u8 *m; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + m = z3fastmem + addr; + do_put_mem_long ((uae_u32 *)m, l); } static void REGPARAM2 z3fastmem_wput (uaecptr addr, uae_u32 w) { - uae_u8 *m; - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - m = z3fastmem + addr; - do_put_mem_word ((uae_u16 *)m, w); + uae_u8 *m; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + m = z3fastmem + addr; + do_put_mem_word ((uae_u16 *)m, w); } static void REGPARAM2 z3fastmem_bput (uaecptr addr, uae_u32 b) { - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - z3fastmem[addr] = b; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + z3fastmem[addr] = b; } static int REGPARAM2 z3fastmem_check (uaecptr addr, uae_u32 size) { - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - return (addr + size) <= allocated_z3fastmem; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + return (addr + size) <= allocated_z3fastmem; } static uae_u8 *REGPARAM2 z3fastmem_xlate (uaecptr addr) { - addr -= z3fastmem_start & z3fastmem_mask; - addr &= z3fastmem_mask; - return z3fastmem + addr; + addr -= z3fastmem_start & z3fastmem_mask; + addr &= z3fastmem_mask; + return z3fastmem + addr; } static uae_u32 REGPARAM2 z3fastmem2_lget (uaecptr addr) { - uae_u8 *m; - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - m = z3fastmem2 + addr; - return do_get_mem_long ((uae_u32 *)m); + uae_u8 *m; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + m = z3fastmem2 + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 z3fastmem2_wget (uaecptr addr) { - uae_u8 *m; - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - m = z3fastmem2 + addr; - return do_get_mem_word ((uae_u16 *)m); + uae_u8 *m; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + m = z3fastmem2 + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 z3fastmem2_bget (uaecptr addr) { - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - return z3fastmem2[addr]; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + return z3fastmem2[addr]; } static void REGPARAM2 z3fastmem2_lput (uaecptr addr, uae_u32 l) { - uae_u8 *m; - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - m = z3fastmem2 + addr; - do_put_mem_long ((uae_u32 *)m, l); + uae_u8 *m; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + m = z3fastmem2 + addr; + do_put_mem_long ((uae_u32 *)m, l); } static void REGPARAM2 z3fastmem2_wput (uaecptr addr, uae_u32 w) { - uae_u8 *m; - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - m = z3fastmem2 + addr; - do_put_mem_word ((uae_u16 *)m, w); + uae_u8 *m; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + m = z3fastmem2 + addr; + do_put_mem_word ((uae_u16 *)m, w); } static void REGPARAM2 z3fastmem2_bput (uaecptr addr, uae_u32 b) { - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - z3fastmem2[addr] = b; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + z3fastmem2[addr] = b; } static int REGPARAM2 z3fastmem2_check (uaecptr addr, uae_u32 size) { - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - return (addr + size) <= allocated_z3fastmem2; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + return (addr + size) <= allocated_z3fastmem2; } static uae_u8 *REGPARAM2 z3fastmem2_xlate (uaecptr addr) { - addr -= z3fastmem2_start & z3fastmem2_mask; - addr &= z3fastmem2_mask; - return z3fastmem2 + addr; + addr -= z3fastmem2_start & z3fastmem2_mask; + addr &= z3fastmem2_mask; + return z3fastmem2 + addr; } addrbank z3fastmem_bank = { - z3fastmem_lget, z3fastmem_wget, z3fastmem_bget, - z3fastmem_lput, z3fastmem_wput, z3fastmem_bput, - z3fastmem_xlate, z3fastmem_check, NULL, L"ZorroIII Fast RAM", - z3fastmem_lget, z3fastmem_wget, ABFLAG_RAM + z3fastmem_lget, z3fastmem_wget, z3fastmem_bget, + z3fastmem_lput, z3fastmem_wput, z3fastmem_bput, + z3fastmem_xlate, z3fastmem_check, NULL, L"ZorroIII Fast RAM", + z3fastmem_lget, z3fastmem_wget, ABFLAG_RAM }; addrbank z3fastmem2_bank = { - z3fastmem2_lget, z3fastmem2_wget, z3fastmem2_bget, - z3fastmem2_lput, z3fastmem2_wput, z3fastmem2_bput, - z3fastmem2_xlate, z3fastmem2_check, NULL, L"ZorroIII Fast RAM #2", - z3fastmem2_lget, z3fastmem2_wget, ABFLAG_RAM + z3fastmem2_lget, z3fastmem2_wget, z3fastmem2_bget, + z3fastmem2_lput, z3fastmem2_wput, z3fastmem2_bput, + z3fastmem2_xlate, z3fastmem2_check, NULL, L"ZorroIII Fast RAM #2", + z3fastmem2_lget, z3fastmem2_wget, ABFLAG_RAM }; /* Z3-based UAEGFX-card */ @@ -832,47 +832,47 @@ uae_u32 gfxmem_start; /* ********************************************************** */ /* - * Expansion Card (ZORRO II) for 1/2/4/8 MB of Fast Memory - */ +* Expansion Card (ZORRO II) for 1/2/4/8 MB of Fast Memory +*/ static void expamem_map_fastcard (void) { - fastmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16); - map_banks (&fastmem_bank, fastmem_start >> 16, allocated_fastmem >> 16, 0); - write_log (L"Fastcard: mapped @$%lx: %dMB fast memory\n", fastmem_start, allocated_fastmem >> 20); + fastmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16); + map_banks (&fastmem_bank, fastmem_start >> 16, allocated_fastmem >> 16, 0); + write_log (L"Fastcard: mapped @$%lx: %dMB fast memory\n", fastmem_start, allocated_fastmem >> 20); } static void expamem_init_fastcard (void) { - uae_u16 mid = (currprefs.cs_a2091 || currprefs.uae_hide) ? commodore : uae_id; - uae_u8 pid = (currprefs.cs_a2091 || currprefs.uae_hide) ? commodore_a2091_ram : 1; + uae_u16 mid = (currprefs.cs_a2091 || currprefs.uae_hide) ? commodore : uae_id; + uae_u8 pid = (currprefs.cs_a2091 || currprefs.uae_hide) ? commodore_a2091_ram : 1; - expamem_init_clear (); - if (allocated_fastmem == 0x100000) - expamem_write (0x00, Z2_MEM_1MB + add_memory + zorroII); - else if (allocated_fastmem == 0x200000) - expamem_write (0x00, Z2_MEM_2MB + add_memory + zorroII); - else if (allocated_fastmem == 0x400000) - expamem_write (0x00, Z2_MEM_4MB + add_memory + zorroII); - else if (allocated_fastmem == 0x800000) - expamem_write (0x00, Z2_MEM_8MB + add_memory + zorroII); + expamem_init_clear (); + if (allocated_fastmem == 0x100000) + expamem_write (0x00, Z2_MEM_1MB + add_memory + zorroII); + else if (allocated_fastmem == 0x200000) + expamem_write (0x00, Z2_MEM_2MB + add_memory + zorroII); + else if (allocated_fastmem == 0x400000) + expamem_write (0x00, Z2_MEM_4MB + add_memory + zorroII); + else if (allocated_fastmem == 0x800000) + expamem_write (0x00, Z2_MEM_8MB + add_memory + zorroII); - expamem_write (0x08, care_addr); + expamem_write (0x08, care_addr); - expamem_write (0x04, pid); + expamem_write (0x04, pid); - expamem_write (0x10, mid >> 8); - expamem_write (0x14, mid & 0xff); + expamem_write (0x10, mid >> 8); + expamem_write (0x14, mid & 0xff); - expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ - expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ - expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ - expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ + expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ + expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ + expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ + expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ - expamem_write (0x28, 0x00); /* Rom-Offset hi */ - expamem_write (0x2c, 0x00); /* ROM-Offset lo */ + expamem_write (0x28, 0x00); /* Rom-Offset hi */ + expamem_write (0x2c, 0x00); /* ROM-Offset lo */ - expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ + expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ } /* ********************************************************** */ @@ -880,101 +880,101 @@ static void expamem_init_fastcard (void) #ifdef FILESYS /* - * Filesystem device - */ +* Filesystem device +*/ static void expamem_map_filesys (void) { - uaecptr a; + uaecptr a; - filesys_start = ((expamem_hi | (expamem_lo >> 4)) << 16); - map_banks (&filesys_bank, filesys_start >> 16, 1, 0); - write_log (L"Filesystem: mapped memory @$%lx.\n", filesys_start); - /* 68k code needs to know this. */ - a = here (); - org (rtarea_base + 0xFFFC); - dl (filesys_start + 0x2000); - org (a); + filesys_start = ((expamem_hi | (expamem_lo >> 4)) << 16); + map_banks (&filesys_bank, filesys_start >> 16, 1, 0); + write_log (L"Filesystem: mapped memory @$%lx.\n", filesys_start); + /* 68k code needs to know this. */ + a = here (); + org (rtarea_base + 0xFFFC); + dl (filesys_start + 0x2000); + org (a); } static void expamem_init_filesys (void) { - /* struct DiagArea - the size has to be large enough to store several device ROMTags */ - uae_u8 diagarea[] = { 0x90, 0x00, /* da_Config, da_Flags */ - 0x02, 0x00, /* da_Size */ - 0x01, 0x00, /* da_DiagPoint */ - 0x01, 0x06 /* da_BootPoint */ - }; + /* struct DiagArea - the size has to be large enough to store several device ROMTags */ + uae_u8 diagarea[] = { 0x90, 0x00, /* da_Config, da_Flags */ + 0x02, 0x00, /* da_Size */ + 0x01, 0x00, /* da_DiagPoint */ + 0x01, 0x06 /* da_BootPoint */ + }; - expamem_init_clear (); - expamem_write (0x00, Z2_MEM_64KB | rom_card | zorroII); + expamem_init_clear (); + expamem_write (0x00, Z2_MEM_64KB | rom_card | zorroII); - expamem_write (0x08, no_shutup); + expamem_write (0x08, no_shutup); - expamem_write (0x04, 2); - expamem_write (0x10, uae_id >> 8); - expamem_write (0x14, uae_id & 0xff); + expamem_write (0x04, 2); + expamem_write (0x10, uae_id >> 8); + expamem_write (0x14, uae_id & 0xff); - expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ - expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ - expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ - expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ + expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ + expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ + expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ + expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ - /* er_InitDiagVec */ - expamem_write (0x28, 0x10); /* Rom-Offset hi */ - expamem_write (0x2c, 0x00); /* ROM-Offset lo */ + /* er_InitDiagVec */ + expamem_write (0x28, 0x10); /* Rom-Offset hi */ + expamem_write (0x2c, 0x00); /* ROM-Offset lo */ - expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ + expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ - /* Build a DiagArea */ - memcpy (expamem + 0x1000, diagarea, sizeof diagarea); + /* Build a DiagArea */ + memcpy (expamem + 0x1000, diagarea, sizeof diagarea); - /* Call DiagEntry */ - do_put_mem_word ((uae_u16 *)(expamem + 0x1100), 0x4EF9); /* JMP */ - do_put_mem_long ((uae_u32 *)(expamem + 0x1102), ROM_filesys_diagentry); + /* Call DiagEntry */ + do_put_mem_word ((uae_u16 *)(expamem + 0x1100), 0x4EF9); /* JMP */ + do_put_mem_long ((uae_u32 *)(expamem + 0x1102), ROM_filesys_diagentry); - /* What comes next is a plain bootblock */ - do_put_mem_word ((uae_u16 *)(expamem + 0x1106), 0x4EF9); /* JMP */ - do_put_mem_long ((uae_u32 *)(expamem + 0x1108), EXPANSION_bootcode); + /* What comes next is a plain bootblock */ + do_put_mem_word ((uae_u16 *)(expamem + 0x1106), 0x4EF9); /* JMP */ + do_put_mem_long ((uae_u32 *)(expamem + 0x1108), EXPANSION_bootcode); - memcpy (filesysory, expamem, 0x3000); + memcpy (filesysory, expamem, 0x3000); } #endif /* - * Zorro III expansion memory - */ +* Zorro III expansion memory +*/ static void expamem_map_z3fastmem_2 (addrbank *bank, int *startp, uae_u32 size, uae_u32 allocated) { - int z3fs = ((expamem_hi | (expamem_lo >> 4)) << 16); - int start = *startp; + int z3fs = ((expamem_hi | (expamem_lo >> 4)) << 16); + int start = *startp; - if (start != z3fs) { - write_log (L"WARNING: Z3FAST mapping changed from $%08x to $%08x\n", start, z3fs); - map_banks (&dummy_bank, start >> 16, size >> 16, - allocated); - *startp = z3fs; - map_banks (bank, start >> 16, size >> 16, - allocated); - } - write_log (L"Fastmem (32bit): mapped @$%08x: %d MB Zorro III fast memory \n", - start, allocated / 0x100000); + if (start != z3fs) { + write_log (L"WARNING: Z3FAST mapping changed from $%08x to $%08x\n", start, z3fs); + map_banks (&dummy_bank, start >> 16, size >> 16, + allocated); + *startp = z3fs; + map_banks (bank, start >> 16, size >> 16, + allocated); + } + write_log (L"Fastmem (32bit): mapped @$%08x: %d MB Zorro III fast memory \n", + start, allocated / 0x100000); } static void expamem_map_z3fastmem (void) { - expamem_map_z3fastmem_2 (&z3fastmem_bank, &z3fastmem_start, currprefs.z3fastmem_size, allocated_z3fastmem); + expamem_map_z3fastmem_2 (&z3fastmem_bank, &z3fastmem_start, currprefs.z3fastmem_size, allocated_z3fastmem); } static void expamem_map_z3fastmem2 (void) { - expamem_map_z3fastmem_2 (&z3fastmem2_bank, &z3fastmem2_start, currprefs.z3fastmem2_size, allocated_z3fastmem2); + expamem_map_z3fastmem_2 (&z3fastmem2_bank, &z3fastmem2_start, currprefs.z3fastmem2_size, allocated_z3fastmem2); } static void expamem_init_z3fastmem_2 (addrbank *bank, uae_u32 start, uae_u32 size, uae_u32 allocated) { - int code = (allocated == 0x100000 ? Z2_MEM_1MB + int code = (allocated == 0x100000 ? Z2_MEM_1MB : allocated == 0x200000 ? Z2_MEM_2MB : allocated == 0x400000 ? Z2_MEM_4MB : allocated == 0x800000 ? Z2_MEM_8MB @@ -986,89 +986,89 @@ static void expamem_init_z3fastmem_2 (addrbank *bank, uae_u32 start, uae_u32 siz : allocated == 0x20000000 ? Z2_MEM_512MB : Z2_MEM_1GB); - expamem_init_clear (); - expamem_write (0x00, add_memory | zorroIII | code); + expamem_init_clear (); + expamem_write (0x00, add_memory | zorroIII | code); - expamem_write (0x08, care_addr | no_shutup | force_z3 | (allocated > 0x800000 ? ext_size : Z3_MEM_AUTO)); + expamem_write (0x08, care_addr | no_shutup | force_z3 | (allocated > 0x800000 ? ext_size : Z3_MEM_AUTO)); - expamem_write (0x04, 3); + expamem_write (0x04, 3); - expamem_write (0x10, uae_id >> 8); - expamem_write (0x14, uae_id & 0xff); + expamem_write (0x10, uae_id >> 8); + expamem_write (0x14, uae_id & 0xff); - expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ - expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ - expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ - expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ + expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ + expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ + expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ + expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ - expamem_write (0x28, 0x00); /* Rom-Offset hi */ - expamem_write (0x2c, 0x00); /* ROM-Offset lo */ + expamem_write (0x28, 0x00); /* Rom-Offset hi */ + expamem_write (0x2c, 0x00); /* ROM-Offset lo */ - expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ + expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ - map_banks (bank, start >> 16, size >> 16, allocated); + map_banks (bank, start >> 16, size >> 16, allocated); } static void expamem_init_z3fastmem (void) { - expamem_init_z3fastmem_2 (&z3fastmem_bank, z3fastmem_start, currprefs.z3fastmem_size, allocated_z3fastmem); + expamem_init_z3fastmem_2 (&z3fastmem_bank, z3fastmem_start, currprefs.z3fastmem_size, allocated_z3fastmem); } static void expamem_init_z3fastmem2 (void) { - expamem_init_z3fastmem_2 (&z3fastmem2_bank, z3fastmem2_start, currprefs.z3fastmem2_size, allocated_z3fastmem2); + expamem_init_z3fastmem_2 (&z3fastmem2_bank, z3fastmem2_start, currprefs.z3fastmem2_size, allocated_z3fastmem2); } #ifdef PICASSO96 /* - * Fake Graphics Card (ZORRO III) - BDK - */ +* Fake Graphics Card (ZORRO III) - BDK +*/ uaecptr p96ram_start; static void expamem_map_gfxcard (void) { - gfxmem_start = (expamem_hi | (expamem_lo >> 4)) << 16; - map_banks (&gfxmem_bankx, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem); - write_log (L"UAEGFX-card: mapped @$%lx, %d MB RTG RAM\n", gfxmem_start, allocated_gfxmem / 0x100000); + gfxmem_start = (expamem_hi | (expamem_lo >> 4)) << 16; + map_banks (&gfxmem_bankx, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem); + write_log (L"UAEGFX-card: mapped @$%lx, %d MB RTG RAM\n", gfxmem_start, allocated_gfxmem / 0x100000); } static void expamem_init_gfxcard (void) { - int code = (allocated_gfxmem == 0x100000 ? Z2_MEM_1MB - : allocated_gfxmem == 0x200000 ? Z2_MEM_2MB - : allocated_gfxmem == 0x400000 ? Z2_MEM_4MB - : allocated_gfxmem == 0x800000 ? Z2_MEM_8MB - : allocated_gfxmem == 0x1000000 ? Z2_MEM_16MB - : allocated_gfxmem == 0x2000000 ? Z2_MEM_32MB - : allocated_gfxmem == 0x4000000 ? Z2_MEM_64MB - : allocated_gfxmem == 0x8000000 ? Z2_MEM_128MB - : allocated_gfxmem == 0x10000000 ? Z2_MEM_256MB - : allocated_gfxmem == 0x20000000 ? Z2_MEM_512MB - : Z2_MEM_1GB); - int subsize = (allocated_gfxmem == 0x100000 ? Z3_MEM_1MB - : allocated_gfxmem == 0x200000 ? Z3_MEM_2MB - : allocated_gfxmem == 0x400000 ? Z3_MEM_4MB - : allocated_gfxmem == 0x800000 ? Z3_MEM_8MB - : 0); - - expamem_init_clear (); - expamem_write (0x00, zorroIII | code); - - expamem_write (0x08, care_addr | no_shutup | force_z3 | ext_size | subsize); - expamem_write (0x04, 96); - - expamem_write (0x10, uae_id >> 8); - expamem_write (0x14, uae_id & 0xff); - - expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ - expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ - expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ - expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ - - expamem_write (0x28, 0x00); /* Rom-Offset hi */ - expamem_write (0x2c, 0x00); /* ROM-Offset lo */ - - expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ + int code = (allocated_gfxmem == 0x100000 ? Z2_MEM_1MB + : allocated_gfxmem == 0x200000 ? Z2_MEM_2MB + : allocated_gfxmem == 0x400000 ? Z2_MEM_4MB + : allocated_gfxmem == 0x800000 ? Z2_MEM_8MB + : allocated_gfxmem == 0x1000000 ? Z2_MEM_16MB + : allocated_gfxmem == 0x2000000 ? Z2_MEM_32MB + : allocated_gfxmem == 0x4000000 ? Z2_MEM_64MB + : allocated_gfxmem == 0x8000000 ? Z2_MEM_128MB + : allocated_gfxmem == 0x10000000 ? Z2_MEM_256MB + : allocated_gfxmem == 0x20000000 ? Z2_MEM_512MB + : Z2_MEM_1GB); + int subsize = (allocated_gfxmem == 0x100000 ? Z3_MEM_1MB + : allocated_gfxmem == 0x200000 ? Z3_MEM_2MB + : allocated_gfxmem == 0x400000 ? Z3_MEM_4MB + : allocated_gfxmem == 0x800000 ? Z3_MEM_8MB + : 0); + + expamem_init_clear (); + expamem_write (0x00, zorroIII | code); + + expamem_write (0x08, care_addr | no_shutup | force_z3 | ext_size | subsize); + expamem_write (0x04, 96); + + expamem_write (0x10, uae_id >> 8); + expamem_write (0x14, uae_id & 0xff); + + expamem_write (0x18, 0x00); /* ser.no. Byte 0 */ + expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */ + expamem_write (0x20, 0x00); /* ser.no. Byte 2 */ + expamem_write (0x24, 0x01); /* ser.no. Byte 3 */ + + expamem_write (0x28, 0x00); /* Rom-Offset hi */ + expamem_write (0x2c, 0x00); /* ROM-Offset lo */ + + expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ } #endif @@ -1079,397 +1079,397 @@ static size_t fast_filepos, z3_filepos, z3_filepos2, p96_filepos; void free_fastmemory (void) { - if (fastmemory) - mapped_free (fastmemory); - fastmemory = 0; + if (fastmemory) + mapped_free (fastmemory); + fastmemory = 0; } static void allocate_expamem (void) { - currprefs.fastmem_size = changed_prefs.fastmem_size; - currprefs.z3fastmem_size = changed_prefs.z3fastmem_size; - currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size; - currprefs.gfxmem_size = changed_prefs.gfxmem_size; - - if (allocated_fastmem != currprefs.fastmem_size) { - free_fastmemory (); - allocated_fastmem = currprefs.fastmem_size; - fastmem_mask = allocated_fastmem - 1; - - if (allocated_fastmem) { - fastmemory = mapped_malloc (allocated_fastmem, L"fast"); - if (fastmemory == 0) { - write_log (L"Out of memory for fastmem card.\n"); - allocated_fastmem = 0; - } + currprefs.fastmem_size = changed_prefs.fastmem_size; + currprefs.z3fastmem_size = changed_prefs.z3fastmem_size; + currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size; + currprefs.gfxmem_size = changed_prefs.gfxmem_size; + + if (allocated_fastmem != currprefs.fastmem_size) { + free_fastmemory (); + allocated_fastmem = currprefs.fastmem_size; + fastmem_mask = allocated_fastmem - 1; + + if (allocated_fastmem) { + fastmemory = mapped_malloc (allocated_fastmem, L"fast"); + if (fastmemory == 0) { + write_log (L"Out of memory for fastmem card.\n"); + allocated_fastmem = 0; + } + } + memory_hardreset (); } - memory_hardreset (); - } - if (allocated_z3fastmem != currprefs.z3fastmem_size) { - if (z3fastmem) - mapped_free (z3fastmem); - z3fastmem = 0; - - allocated_z3fastmem = currprefs.z3fastmem_size; - z3fastmem_mask = allocated_z3fastmem - 1; - - if (allocated_z3fastmem) { - z3fastmem = mapped_malloc (allocated_z3fastmem, L"z3"); - if (z3fastmem == 0) { - write_log (L"Out of memory for 32 bit fast memory.\n"); - allocated_z3fastmem = 0; - } + if (allocated_z3fastmem != currprefs.z3fastmem_size) { + if (z3fastmem) + mapped_free (z3fastmem); + z3fastmem = 0; + + allocated_z3fastmem = currprefs.z3fastmem_size; + z3fastmem_mask = allocated_z3fastmem - 1; + + if (allocated_z3fastmem) { + z3fastmem = mapped_malloc (allocated_z3fastmem, L"z3"); + if (z3fastmem == 0) { + write_log (L"Out of memory for 32 bit fast memory.\n"); + allocated_z3fastmem = 0; + } + } + memory_hardreset (); } - memory_hardreset (); - } - if (allocated_z3fastmem2 != currprefs.z3fastmem2_size) { - if (z3fastmem2) - mapped_free (z3fastmem2); - z3fastmem2 = 0; - - allocated_z3fastmem2 = currprefs.z3fastmem2_size; - z3fastmem2_mask = allocated_z3fastmem2 - 1; - - if (allocated_z3fastmem2) { - z3fastmem2 = mapped_malloc (allocated_z3fastmem2, L"z3_2"); - if (z3fastmem2 == 0) { - write_log (L"Out of memory for 32 bit fast memory #2.\n"); - allocated_z3fastmem2 = 0; - } + if (allocated_z3fastmem2 != currprefs.z3fastmem2_size) { + if (z3fastmem2) + mapped_free (z3fastmem2); + z3fastmem2 = 0; + + allocated_z3fastmem2 = currprefs.z3fastmem2_size; + z3fastmem2_mask = allocated_z3fastmem2 - 1; + + if (allocated_z3fastmem2) { + z3fastmem2 = mapped_malloc (allocated_z3fastmem2, L"z3_2"); + if (z3fastmem2 == 0) { + write_log (L"Out of memory for 32 bit fast memory #2.\n"); + allocated_z3fastmem2 = 0; + } + } + memory_hardreset (); } - memory_hardreset (); - } #ifdef PICASSO96 - if (allocated_gfxmem != currprefs.gfxmem_size) { - if (gfxmemory) - mapped_free (gfxmemory); - gfxmemory = 0; - - allocated_gfxmem = currprefs.gfxmem_size; - gfxmem_mask = allocated_gfxmem - 1; - - if (allocated_gfxmem) { - gfxmemory = mapped_malloc (allocated_gfxmem, L"gfx"); - if (gfxmemory == 0) { - write_log (L"Out of memory for graphics card memory\n"); - allocated_gfxmem = 0; - } + if (allocated_gfxmem != currprefs.gfxmem_size) { + if (gfxmemory) + mapped_free (gfxmemory); + gfxmemory = 0; + + allocated_gfxmem = currprefs.gfxmem_size; + gfxmem_mask = allocated_gfxmem - 1; + + if (allocated_gfxmem) { + gfxmemory = mapped_malloc (allocated_gfxmem, L"gfx"); + if (gfxmemory == 0) { + write_log (L"Out of memory for graphics card memory\n"); + allocated_gfxmem = 0; + } + } + memory_hardreset (); } - memory_hardreset (); - } #endif - z3fastmem_bank.baseaddr = z3fastmem; - z3fastmem2_bank.baseaddr = z3fastmem2; - fastmem_bank.baseaddr = fastmemory; - gfxmem_bankx.baseaddr = gfxmemory; + z3fastmem_bank.baseaddr = z3fastmem; + z3fastmem2_bank.baseaddr = z3fastmem2; + fastmem_bank.baseaddr = fastmemory; + gfxmem_bankx.baseaddr = gfxmemory; #ifdef SAVESTATE - if (savestate_state == STATE_RESTORE) { - if (allocated_fastmem > 0) { - restore_ram (fast_filepos, fastmemory); - map_banks (&fastmem_bank, fastmem_start >> 16, currprefs.fastmem_size >> 16, - allocated_fastmem); - } - if (allocated_z3fastmem > 0) { - restore_ram (z3_filepos, z3fastmem); - map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, - allocated_z3fastmem); - } - if (allocated_z3fastmem2 > 0) { - restore_ram (z3_filepos2, z3fastmem2); - map_banks (&z3fastmem2_bank, z3fastmem2_start >> 16, currprefs.z3fastmem2_size >> 16, - allocated_z3fastmem2); - } + if (savestate_state == STATE_RESTORE) { + if (allocated_fastmem > 0) { + restore_ram (fast_filepos, fastmemory); + map_banks (&fastmem_bank, fastmem_start >> 16, currprefs.fastmem_size >> 16, + allocated_fastmem); + } + if (allocated_z3fastmem > 0) { + restore_ram (z3_filepos, z3fastmem); + map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, + allocated_z3fastmem); + } + if (allocated_z3fastmem2 > 0) { + restore_ram (z3_filepos2, z3fastmem2); + map_banks (&z3fastmem2_bank, z3fastmem2_start >> 16, currprefs.z3fastmem2_size >> 16, + allocated_z3fastmem2); + } #ifdef PICASSO96 - if (allocated_gfxmem > 0 && gfxmem_start > 0) { - restore_ram (p96_filepos, gfxmemory); - map_banks (&gfxmem_bankx, gfxmem_start >> 16, currprefs.gfxmem_size >> 16, - allocated_gfxmem); - } + if (allocated_gfxmem > 0 && gfxmem_start > 0) { + restore_ram (p96_filepos, gfxmemory); + map_banks (&gfxmem_bankx, gfxmem_start >> 16, currprefs.gfxmem_size >> 16, + allocated_gfxmem); + } #endif - } + } #endif /* SAVESTATE */ } static uaecptr check_boot_rom (void) { - uaecptr b = RTAREA_DEFAULT; - addrbank *ab; - - if (currprefs.cs_cdtvcd || currprefs.cs_cdtvscsi || currprefs.uae_hide > 1) - b = RTAREA_BACKUP; - if (currprefs.cs_mbdmac == 1) - b = RTAREA_BACKUP; - ab = &get_mem_bank (RTAREA_DEFAULT); - if (ab) { - if (valid_address (RTAREA_DEFAULT, 65536)) - b = RTAREA_BACKUP; - } - if (nr_directory_units (NULL)) - return b; - if (nr_directory_units (&currprefs)) - return b; - if (currprefs.socket_emu) - return b; - if (currprefs.uaeserial) - return b; - if (currprefs.scsi == 1) - return b; - if (currprefs.sana2) - return b; - if (currprefs.input_tablet > 0) - return b; - if (currprefs.gfxmem_size) - return b; - if (currprefs.win32_automount_removable) - return b; - if (currprefs.chipmem_size > 2 * 1024 * 1024) - return b; - return 0; + uaecptr b = RTAREA_DEFAULT; + addrbank *ab; + + if (currprefs.cs_cdtvcd || currprefs.cs_cdtvscsi || currprefs.uae_hide > 1) + b = RTAREA_BACKUP; + if (currprefs.cs_mbdmac == 1) + b = RTAREA_BACKUP; + ab = &get_mem_bank (RTAREA_DEFAULT); + if (ab) { + if (valid_address (RTAREA_DEFAULT, 65536)) + b = RTAREA_BACKUP; + } + if (nr_directory_units (NULL)) + return b; + if (nr_directory_units (&currprefs)) + return b; + if (currprefs.socket_emu) + return b; + if (currprefs.uaeserial) + return b; + if (currprefs.scsi == 1) + return b; + if (currprefs.sana2) + return b; + if (currprefs.input_tablet > 0) + return b; + if (currprefs.gfxmem_size) + return b; + if (currprefs.win32_automount_removable) + return b; + if (currprefs.chipmem_size > 2 * 1024 * 1024) + return b; + return 0; } uaecptr need_uae_boot_rom (void) { - uaecptr v; + uaecptr v; - uae_boot_rom = 0; - v = check_boot_rom (); - if (v) - uae_boot_rom = 1; - if (!rtarea_base) { uae_boot_rom = 0; - v = 0; - } - return v; + v = check_boot_rom (); + if (v) + uae_boot_rom = 1; + if (!rtarea_base) { + uae_boot_rom = 0; + v = 0; + } + return v; } void expamem_next (void) { - expamem_init_clear (); - map_banks (&expamem_bank, 0xE8, 1, 0); - ++ecard; - if (ecard < cardno) - (*card_init[ecard]) (); - else - expamem_init_clear2 (); + expamem_init_clear (); + map_banks (&expamem_bank, 0xE8, 1, 0); + ++ecard; + if (ecard < cardno) + (*card_init[ecard]) (); + else + expamem_init_clear2 (); } static void expamem_init_a2065 (void) { - a2065_init (); + a2065_init (); } static void expamem_init_cdtv (void) { - cdtv_init (); + cdtv_init (); } static void expamem_init_a2091 (void) { - a2091_init (); + a2091_init (); } static void expamem_init_a4091 (void) { - ncr_init (); + ncr_init (); } void p96memstart(void) { - /* make sure there is always empty space between Z3 and P96 RAM */ - p96ram_start = currprefs.z3fastmem_start + ((currprefs.z3fastmem_size + currprefs.z3fastmem2_size + 0xffffff) & ~0xffffff); - if (p96ram_start == currprefs.z3fastmem_start + currprefs.z3fastmem_size + currprefs.z3fastmem2_size && - (currprefs.z3fastmem_size + currprefs.z3fastmem2_size < 512 * 1024 * 1024 || currprefs.gfxmem_size < 128 * 1024 * 1024)) - p96ram_start += 0x1000000; + /* make sure there is always empty space between Z3 and P96 RAM */ + p96ram_start = currprefs.z3fastmem_start + ((currprefs.z3fastmem_size + currprefs.z3fastmem2_size + 0xffffff) & ~0xffffff); + if (p96ram_start == currprefs.z3fastmem_start + currprefs.z3fastmem_size + currprefs.z3fastmem2_size && + (currprefs.z3fastmem_size + currprefs.z3fastmem2_size < 512 * 1024 * 1024 || currprefs.gfxmem_size < 128 * 1024 * 1024)) + p96ram_start += 0x1000000; } void expamem_reset (void) { - int do_mount = 1; - - ecard = 0; - cardno = 0; - - if (currprefs.uae_hide) - uae_id = commodore; - else - uae_id = hackers_id; - - allocate_expamem (); - - /* check if Kickstart version is below 1.3 */ - if (! ersatzkickfile && kickstart_version - && (/* Kickstart 1.0 & 1.1! */ - kickstart_version == 0xFFFF - /* Kickstart < 1.3 */ - || kickstart_version < 34)) - { - /* warn user */ - write_log (L"Kickstart version is below 1.3! Disabling autoconfig devices.\n"); - do_mount = 0; - } - if (need_uae_boot_rom() == 0) - do_mount = 0; - if (fastmemory != NULL) { - card_init[cardno] = expamem_init_fastcard; - card_map[cardno++] = expamem_map_fastcard; - } - - z3fastmem_start = currprefs.z3fastmem_start; - z3fastmem2_start = currprefs.z3fastmem_start + currprefs.z3fastmem_size; - if (z3fastmem != NULL) { - z3num = 0; - card_init[cardno] = expamem_init_z3fastmem; - card_map[cardno++] = expamem_map_z3fastmem; - map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, allocated_z3fastmem); - if (z3fastmem2 != NULL) { - card_init[cardno] = expamem_init_z3fastmem2; - card_map[cardno++] = expamem_map_z3fastmem2; - map_banks (&z3fastmem2_bank, z3fastmem2_start >> 16, currprefs.z3fastmem2_size >> 16, allocated_z3fastmem2); + int do_mount = 1; + + ecard = 0; + cardno = 0; + + if (currprefs.uae_hide) + uae_id = commodore; + else + uae_id = hackers_id; + + allocate_expamem (); + + /* check if Kickstart version is below 1.3 */ + if (! ersatzkickfile && kickstart_version + && (/* Kickstart 1.0 & 1.1! */ + kickstart_version == 0xFFFF + /* Kickstart < 1.3 */ + || kickstart_version < 34)) + { + /* warn user */ + write_log (L"Kickstart version is below 1.3! Disabling autoconfig devices.\n"); + do_mount = 0; + } + if (need_uae_boot_rom() == 0) + do_mount = 0; + if (fastmemory != NULL) { + card_init[cardno] = expamem_init_fastcard; + card_map[cardno++] = expamem_map_fastcard; + } + + z3fastmem_start = currprefs.z3fastmem_start; + z3fastmem2_start = currprefs.z3fastmem_start + currprefs.z3fastmem_size; + if (z3fastmem != NULL) { + z3num = 0; + card_init[cardno] = expamem_init_z3fastmem; + card_map[cardno++] = expamem_map_z3fastmem; + map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, allocated_z3fastmem); + if (z3fastmem2 != NULL) { + card_init[cardno] = expamem_init_z3fastmem2; + card_map[cardno++] = expamem_map_z3fastmem2; + map_banks (&z3fastmem2_bank, z3fastmem2_start >> 16, currprefs.z3fastmem2_size >> 16, allocated_z3fastmem2); + } } - } #ifdef CDTV - if (currprefs.cs_cdtvcd) { - card_init[cardno] = expamem_init_cdtv; - card_map[cardno++] = NULL; - } + if (currprefs.cs_cdtvcd) { + card_init[cardno] = expamem_init_cdtv; + card_map[cardno++] = NULL; + } #endif #ifdef CD32 - if (currprefs.cs_cd32cd && currprefs.fastmem_size == 0 && currprefs.chipmem_size <= 0x200000) { - int ids[] = { 23, -1 }; - struct romlist *rl = getromlistbyids (ids); - if (rl && !_tcscmp (rl->path, currprefs.cartfile)) { - card_init[cardno] = expamem_init_cd32fmv; - card_map[cardno++] = expamem_map_cd32fmv; + if (currprefs.cs_cd32cd && currprefs.fastmem_size == 0 && currprefs.chipmem_size <= 0x200000) { + int ids[] = { 23, -1 }; + struct romlist *rl = getromlistbyids (ids); + if (rl && !_tcscmp (rl->path, currprefs.cartfile)) { + card_init[cardno] = expamem_init_cd32fmv; + card_map[cardno++] = expamem_map_cd32fmv; + } } - } #endif #ifdef NCR - if (currprefs.cs_a4091) { - card_init[cardno] = expamem_init_a4091; - card_map[cardno++] = NULL; - } + if (currprefs.cs_a4091) { + card_init[cardno] = expamem_init_a4091; + card_map[cardno++] = NULL; + } #endif #ifdef A2091 - if (currprefs.cs_a2091) { - card_init[cardno] = expamem_init_a2091; - card_map[cardno++] = NULL; - } + if (currprefs.cs_a2091) { + card_init[cardno] = expamem_init_a2091; + card_map[cardno++] = NULL; + } #endif #ifdef A2065 - if (currprefs.a2065name[0]) { - card_init[cardno] = expamem_init_a2065; - card_map[cardno++] = NULL; - } + if (currprefs.a2065name[0]) { + card_init[cardno] = expamem_init_a2065; + card_map[cardno++] = NULL; + } #endif #ifdef PICASSO96 - if (gfxmemory != NULL) { - card_init[cardno] = expamem_init_gfxcard; - card_map[cardno++] = expamem_map_gfxcard; - } + if (gfxmemory != NULL) { + card_init[cardno] = expamem_init_gfxcard; + card_map[cardno++] = expamem_map_gfxcard; + } #endif #ifdef FILESYS - if (do_mount && ! ersatzkickfile) { - card_init[cardno] = expamem_init_filesys; - card_map[cardno++] = expamem_map_filesys; - } + if (do_mount && ! ersatzkickfile) { + card_init[cardno] = expamem_init_filesys; + card_map[cardno++] = expamem_map_filesys; + } #endif #ifdef CATWEASEL - if (currprefs.catweasel && catweasel_init ()) { - card_init[cardno] = expamem_init_catweasel; - card_map[cardno++] = expamem_map_catweasel; - } + if (currprefs.catweasel && catweasel_init ()) { + card_init[cardno] = expamem_init_catweasel; + card_map[cardno++] = expamem_map_catweasel; + } #endif - if (cardno > 0 && cardno < MAX_EXPANSION_BOARDS) { - card_init[cardno] = expamem_init_last; - card_map[cardno++] = expamem_map_clear; - } + if (cardno > 0 && cardno < MAX_EXPANSION_BOARDS) { + card_init[cardno] = expamem_init_last; + card_map[cardno++] = expamem_map_clear; + } - if (cardno == 0) - expamem_init_clear_zero (); - else - (*card_init[0]) (); + if (cardno == 0) + expamem_init_clear_zero (); + else + (*card_init[0]) (); } void expansion_init (void) { - allocated_fastmem = 0; - fastmem_mask = fastmem_start = 0; - fastmemory = 0; + allocated_fastmem = 0; + fastmem_mask = fastmem_start = 0; + fastmemory = 0; #ifdef PICASSO96 - allocated_gfxmem = 0; - gfxmem_mask = gfxmem_start = 0; - gfxmemory = 0; + allocated_gfxmem = 0; + gfxmem_mask = gfxmem_start = 0; + gfxmemory = 0; #endif #ifdef CATWEASEL - catweasel_mask = catweasel_start = 0; + catweasel_mask = catweasel_start = 0; #endif #ifdef FILESYS - filesys_start = 0; - filesysory = 0; + filesys_start = 0; + filesysory = 0; #endif - allocated_z3fastmem = 0; - z3fastmem_mask = z3fastmem_start = 0; - z3fastmem = 0; - allocated_z3fastmem2 = 0; - z3fastmem2_mask = z3fastmem2_start = 0; - z3fastmem2 = 0; + allocated_z3fastmem = 0; + z3fastmem_mask = z3fastmem_start = 0; + z3fastmem = 0; + allocated_z3fastmem2 = 0; + z3fastmem2_mask = z3fastmem2_start = 0; + z3fastmem2 = 0; - allocate_expamem (); + allocate_expamem (); #ifdef FILESYS - filesysory = mapped_malloc (0x10000, L"filesys"); - if (!filesysory) { - write_log (L"virtual memory exhausted (filesysory)!\n"); - exit (0); - } - filesys_bank.baseaddr = filesysory; + filesysory = mapped_malloc (0x10000, L"filesys"); + if (!filesysory) { + write_log (L"virtual memory exhausted (filesysory)!\n"); + exit (0); + } + filesys_bank.baseaddr = filesysory; #endif } void expansion_cleanup (void) { - if (fastmemory) - mapped_free (fastmemory); - fastmemory = 0; + if (fastmemory) + mapped_free (fastmemory); + fastmemory = 0; - if (z3fastmem) - mapped_free (z3fastmem); - z3fastmem = 0; - if (z3fastmem2) - mapped_free (z3fastmem2); - z3fastmem2 = 0; + if (z3fastmem) + mapped_free (z3fastmem); + z3fastmem = 0; + if (z3fastmem2) + mapped_free (z3fastmem2); + z3fastmem2 = 0; #ifdef PICASSO96 - if (gfxmemory) - mapped_free (gfxmemory); - gfxmemory = 0; + if (gfxmemory) + mapped_free (gfxmemory); + gfxmemory = 0; #endif #ifdef FILESYS - if (filesysory) - mapped_free (filesysory); - filesysory = 0; + if (filesysory) + mapped_free (filesysory); + filesysory = 0; #endif #ifdef CATWEASEL - catweasel_free (); + catweasel_free (); #endif } void expansion_clear(void) { - if (fastmemory) - memset (fastmemory, 0, allocated_fastmem); - if (z3fastmem) - memset (z3fastmem, 0, allocated_z3fastmem > 0x800000 ? 0x800000 : allocated_z3fastmem); - if (z3fastmem2) - memset (z3fastmem2, 0, allocated_z3fastmem2 > 0x800000 ? 0x800000 : allocated_z3fastmem2); - if (gfxmemory) - memset (gfxmemory, 0, allocated_gfxmem); + if (fastmemory) + memset (fastmemory, 0, allocated_fastmem); + if (z3fastmem) + memset (z3fastmem, 0, allocated_z3fastmem > 0x800000 ? 0x800000 : allocated_z3fastmem); + if (z3fastmem2) + memset (z3fastmem2, 0, allocated_z3fastmem2 > 0x800000 ? 0x800000 : allocated_z3fastmem2); + if (gfxmemory) + memset (gfxmemory, 0, allocated_gfxmem); } #ifdef SAVESTATE @@ -1478,68 +1478,68 @@ void expansion_clear(void) uae_u8 *save_fram (int *len) { - *len = allocated_fastmem; - return fastmemory; + *len = allocated_fastmem; + return fastmemory; } uae_u8 *save_zram (int *len, int num) { - *len = num ? allocated_z3fastmem2 : allocated_z3fastmem; - return num ? z3fastmem2 : z3fastmem; + *len = num ? allocated_z3fastmem2 : allocated_z3fastmem; + return num ? z3fastmem2 : z3fastmem; } uae_u8 *save_pram (int *len) { - *len = allocated_gfxmem; - return gfxmemory; + *len = allocated_gfxmem; + return gfxmemory; } void restore_fram (int len, size_t filepos) { - fast_filepos = filepos; - changed_prefs.fastmem_size = len; + fast_filepos = filepos; + changed_prefs.fastmem_size = len; } void restore_zram (int len, size_t filepos, int num) { - if (num) { - z3_filepos2 = filepos; - changed_prefs.z3fastmem2_size = len; - } else { - z3_filepos = filepos; - changed_prefs.z3fastmem_size = len; - } + if (num) { + z3_filepos2 = filepos; + changed_prefs.z3fastmem2_size = len; + } else { + z3_filepos = filepos; + changed_prefs.z3fastmem_size = len; + } } void restore_pram (int len, size_t filepos) { - p96_filepos = filepos; - changed_prefs.gfxmem_size = len; + p96_filepos = filepos; + changed_prefs.gfxmem_size = len; } uae_u8 *save_expansion (int *len, uae_u8 *dstptr) { - static uae_u8 t[20]; - uae_u8 *dst = t, *dstbak = t; - if (dstptr) - dst = dstbak = dstptr; - save_u32 (fastmem_start); - save_u32 (z3fastmem_start); - save_u32 (gfxmem_start); - save_u32 (rtarea_base); - *len = 4 + 4 + 4 + 4; - return dstbak; + static uae_u8 t[20]; + uae_u8 *dst = t, *dstbak = t; + if (dstptr) + dst = dstbak = dstptr; + save_u32 (fastmem_start); + save_u32 (z3fastmem_start); + save_u32 (gfxmem_start); + save_u32 (rtarea_base); + *len = 4 + 4 + 4 + 4; + return dstbak; } uae_u8 *restore_expansion (uae_u8 *src) { - fastmem_start = restore_u32 (); - z3fastmem_start = restore_u32 (); - gfxmem_start = restore_u32 (); - rtarea_base = restore_u32 (); - if (rtarea_base != 0 && rtarea_base != RTAREA_DEFAULT && rtarea_base != RTAREA_BACKUP) - rtarea_base = 0; - return src; + fastmem_start = restore_u32 (); + z3fastmem_start = restore_u32 (); + gfxmem_start = restore_u32 (); + rtarea_base = restore_u32 (); + if (rtarea_base != 0 && rtarea_base != RTAREA_DEFAULT && rtarea_base != RTAREA_BACKUP) + rtarea_base = 0; + return src; } #endif /* SAVESTATE */ diff --git a/fdi2raw.c b/fdi2raw.c index 247c3ef2..c567a71c 100644 --- a/fdi2raw.c +++ b/fdi2raw.c @@ -1,31 +1,31 @@ /* - FDI to raw bit stream converter - Copyright (c) 2001 by Toni Wilen - FDI 2.0 support - Copyright (c) 2003-2004 by Toni Wilen - and Vincent Joguin +FDI to raw bit stream converter +Copyright (c) 2001 by Toni Wilen +FDI 2.0 support +Copyright (c) 2003-2004 by Toni Wilen +and Vincent Joguin - FDI format created by Vincent "ApH" Joguin +FDI format created by Vincent "ApH" Joguin - Tiny changes - function type fixes, multiple drives, addition of - get_last_head and C++ callability - by Thomas Harte, 2001, - T.Harte@excite.co.uk +Tiny changes - function type fixes, multiple drives, addition of +get_last_head and C++ callability - by Thomas Harte, 2001, +T.Harte@excite.co.uk - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) +any later version. - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ @@ -330,18 +330,18 @@ static int decode_raw_track (FDI *fdi) static void zxx (FDI *fdi) { outlog (L"track %d: unknown track type 0x%02X\n", fdi->current_track, fdi->track_type); -// return -1; + // return -1; } /* unsupported track */ static void zyy (FDI *fdi) { outlog (L"track %d: unsupported track type 0x%02X\n", fdi->current_track, fdi->track_type); -// return -1; + // return -1; } /* empty track */ static void track_empty (FDI *fdi) { -// return 0; + // return 0; } /* unknown sector described type */ @@ -661,7 +661,7 @@ static int amiga_check_track (FDI *fdi) mbuf[0] = 0x44; mbuf[1] = 0x89; } -// check_offset++; + // check_offset++; if (check_offset > 7) { check_offset = 0; mbuf++; @@ -790,7 +790,7 @@ static void amiga_data (FDI *fdi, uae_u8 *secbuf) for (i = 0; i < 512; i += 4) { deven = ((secbuf[i + 0] << 24) | (secbuf[i + 1] << 16) - | (secbuf[i + 2] << 8) | (secbuf[i + 3])); + | (secbuf[i + 2] << 8) | (secbuf[i + 3])); dodd = deven >> 1; deven &= 0x55555555; dodd &= 0x55555555; @@ -1182,10 +1182,10 @@ static void track_atari_st (struct fdi *fdi, int max_sector) uae_u8 *p = fdi->track_src; switch (max_sector) { - case 9: + case 9: gap3 = 40; break; - case 10: + case 10: gap3 = 24; break; } @@ -1206,13 +1206,13 @@ static void track_pc (struct fdi *fdi, int max_sector) uae_u8 *p = fdi->track_src; switch (max_sector) { - case 8: + case 8: gap3 = 116; break; - case 9: + case 9: gap3 = 54; break; - default: + default: gap3 = 100; /* fixme */ break; } @@ -1370,13 +1370,13 @@ static uae_u8 *fdi_decompress (int pulses, uae_u8 *sizep, uae_u8 *src, int *dofr static void dumpstream(int track, uae_u8 *stream, int len) { #if 0 - TCHAR name[100]; - FILE *f; + TCHAR name[100]; + FILE *f; - _stprintf (name, "track_%d.raw", track); - f = fopen(name, "wb"); - fwrite (stream, 1, len * 4, f); - fclose (f); + _stprintf (name, "track_%d.raw", track); + f = fopen(name, "wb"); + fwrite (stream, 1, len * 4, f); + fclose (f); #endif } @@ -1436,7 +1436,7 @@ static void fdi2_decode (FDI *fdi, unsigned long totalavg, uae_u32 *avgp, uae_u3 while ( (i < pulses) && ( (idx[i] < maxidx) || (idx[i - 1] < maxidx) || (avgp[i] < (standard_MFM_2_bit_cell_size - (standard_MFM_2_bit_cell_size / 4))) ) ) - i++; + i++; if (i == pulses) { outlog (L"No stable and long-enough pulse in track.\n"); return; @@ -1483,7 +1483,7 @@ static void fdi2_decode (FDI *fdi, unsigned long totalavg, uae_u32 *avgp, uae_u3 if (i == eodat) outstep++; if (outstep == 1 && indexoffset == i) - *indexoffsetp = bitoffset; + *indexoffsetp = bitoffset; } /* gets the size in bits from the pulse width, considering the current average bitrate */ @@ -1564,7 +1564,7 @@ static void fdi2_decode (FDI *fdi, unsigned long totalavg, uae_u32 *avgp, uae_u3 while ( (i < pulses) && ( (idx[i] < maxidx) || (idx[i - 1] < maxidx) || (minp[i] < (standard_MFM_2_bit_cell_size - (standard_MFM_2_bit_cell_size / 4))) ) ) - i++; + i++; if (i == pulses) { outlog (L"FDI: No stable and long-enough pulse in track.\n"); return; @@ -1683,84 +1683,84 @@ static void fdi2_decode (FDI *fdi, unsigned long totalavg, uae_u32 *avgp, uae_u3 } } if (outstep == 1 && indexoffset == i) - *indexoffsetp = bitoffset; + *indexoffsetp = bitoffset; } /* gets the size in bits from the pulse width, considering the current average bitrate */ adjusted_pulse = pulse; real_size = 0; if (mfm) { - while (adjusted_pulse >= avg_size) { - real_size += 4; - adjusted_pulse -= avg_size / 2; - } - adjusted_pulse <<= 3; - while (adjusted_pulse >= ((avg_size * 4) + (avg_size / 4))) { - real_size += 2; - adjusted_pulse -= avg_size * 2; - } - if (adjusted_pulse >= ((avg_size * 3) + (avg_size / 4))) { - if (adjusted_pulse <= ((avg_size * 4) - (avg_size / 4))) { - if ((2 * ((adjusted_pulse >> 2) - adjust)) <= ((2 * avg_size) - (avg_size / 4))) - real_size += 3; - else - real_size += 4; - } else - real_size += 4; - } else { - if (adjusted_pulse > ((avg_size * 3) - (avg_size / 4))) { - real_size += 3; - } else { - if (adjusted_pulse >= ((avg_size * 2) + (avg_size / 4))) { - if ((2 * ((adjusted_pulse >> 2) - adjust)) < (avg_size + (avg_size / 4))) - real_size += 2; - else - real_size += 3; - } else - real_size += 2; - } - } + while (adjusted_pulse >= avg_size) { + real_size += 4; + adjusted_pulse -= avg_size / 2; + } + adjusted_pulse <<= 3; + while (adjusted_pulse >= ((avg_size * 4) + (avg_size / 4))) { + real_size += 2; + adjusted_pulse -= avg_size * 2; + } + if (adjusted_pulse >= ((avg_size * 3) + (avg_size / 4))) { + if (adjusted_pulse <= ((avg_size * 4) - (avg_size / 4))) { + if ((2 * ((adjusted_pulse >> 2) - adjust)) <= ((2 * avg_size) - (avg_size / 4))) + real_size += 3; + else + real_size += 4; + } else + real_size += 4; + } else { + if (adjusted_pulse > ((avg_size * 3) - (avg_size / 4))) { + real_size += 3; + } else { + if (adjusted_pulse >= ((avg_size * 2) + (avg_size / 4))) { + if ((2 * ((adjusted_pulse >> 2) - adjust)) < (avg_size + (avg_size / 4))) + real_size += 2; + else + real_size += 3; + } else + real_size += 2; + } + } } else { - while (adjusted_pulse >= (2*avg_size)) - { - real_size+=4; - adjusted_pulse-=avg_size; - } - adjusted_pulse<<=2; - while (adjusted_pulse >= ((avg_size*3)+(avg_size/4))) - { - real_size+=2; - adjusted_pulse-=avg_size*2; - } - if (adjusted_pulse >= ((avg_size*2)+(avg_size/4))) - { - if (adjusted_pulse <= ((avg_size*3)-(avg_size/4))) - { - if (((adjusted_pulse>>1)-adjust) < (avg_size+(avg_size/4))) - real_size+=2; - else - real_size+=3; - } - else - real_size+=3; - } - else - { - if (adjusted_pulse > ((avg_size*2)-(avg_size/4))) - real_size+=2; - else - { - if (adjusted_pulse >= (avg_size+(avg_size/4))) - { - if (((adjusted_pulse>>1)-adjust) <= (avg_size-(avg_size/4))) - real_size++; - else - real_size+=2; - } - else - real_size++; - } - } + while (adjusted_pulse >= (2*avg_size)) + { + real_size+=4; + adjusted_pulse-=avg_size; + } + adjusted_pulse<<=2; + while (adjusted_pulse >= ((avg_size*3)+(avg_size/4))) + { + real_size+=2; + adjusted_pulse-=avg_size*2; + } + if (adjusted_pulse >= ((avg_size*2)+(avg_size/4))) + { + if (adjusted_pulse <= ((avg_size*3)-(avg_size/4))) + { + if (((adjusted_pulse>>1)-adjust) < (avg_size+(avg_size/4))) + real_size+=2; + else + real_size+=3; + } + else + real_size+=3; + } + else + { + if (adjusted_pulse > ((avg_size*2)-(avg_size/4))) + real_size+=2; + else + { + if (adjusted_pulse >= (avg_size+(avg_size/4))) + { + if (((adjusted_pulse>>1)-adjust) <= (avg_size-(avg_size/4))) + real_size++; + else + real_size+=2; + } + else + real_size++; + } + } } /* after one pass to correctly initialize the average bitrate, outputs the bits */ @@ -1797,7 +1797,7 @@ static void fdi2_celltiming (FDI *fdi, unsigned long totalavg, int bitoffset, ua int i; if (out == NULL) - return; + return; avg_bit_len = (double)totalavg / (double)bitoffset; pt2 = fdi->track_dst_buffer_timing; pt = out; @@ -2186,7 +2186,7 @@ int fdi2raw_loadtrack (FDI *fdi, uae_u16 *mfmbuf, uae_u16 *tracktiming, int trac } -// amiga_check_track (fdi); + // amiga_check_track (fdi); if (fdi->err) return 0; diff --git a/filesys.c b/filesys.c index ee88d129..7ef9dd35 100644 --- a/filesys.c +++ b/filesys.c @@ -1,26 +1,26 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Unix file system handler for AmigaDOS - * - * Copyright 1996 Ed Hanway - * Copyright 1996, 1997 Bernd Schmidt - * - * Version 0.4: 970308 - * - * Based on example code (c) 1988 The Software Distillery - * and published in Transactor for the Amiga, Volume 2, Issues 2-5. - * (May - August 1989) - * - * Known limitations: - * Does not support several (useless) 2.0+ packet types. - * May not return the correct error code in some cases. - * Does not check for sane values passed by AmigaDOS. May crash the emulation - * if passed garbage values. - * Could do tighter checks on malloc return values. - * Will probably fail spectacularly in some cases if the filesystem is - * modified at the same time by another process while UAE is running. - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Unix file system handler for AmigaDOS +* +* Copyright 1996 Ed Hanway +* Copyright 1996, 1997 Bernd Schmidt +* +* Version 0.4: 970308 +* +* Based on example code (c) 1988 The Software Distillery +* and published in Transactor for the Amiga, Volume 2, Issues 2-5. +* (May - August 1989) +* +* Known limitations: +* Does not support several (useless) 2.0+ packet types. +* May not return the correct error code in some cases. +* Does not check for sane values passed by AmigaDOS. May crash the emulation +* if passed garbage values. +* Could do tighter checks on malloc return values. +* Will probably fail spectacularly in some cases if the filesystem is +* modified at the same time by another process while UAE is running. +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -66,52 +66,52 @@ static uae_sem_t test_sem; int bootrom_header, bootrom_items; static uae_u32 dlg (uae_u32 a) { - return (dbg (a + 0) << 24) | (dbg (a + 1) << 16) | (dbg (a + 2) << 8) | (dbg (a + 3) << 0); + return (dbg (a + 0) << 24) | (dbg (a + 1) << 16) | (dbg (a + 2) << 8) | (dbg (a + 3) << 0); } static char *ua_fs (const TCHAR *src) { - return uacp (src, currprefs.win32_fscodepage); + return uacp (src, currprefs.win32_fscodepage); } static TCHAR *au_fs (const char *src) { - return aucp (src, currprefs.win32_fscodepage); + return aucp (src, currprefs.win32_fscodepage); } static TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src) { - return aucp_copy (dst, maxlen, src, currprefs.win32_fscodepage); + return aucp_copy (dst, maxlen, src, currprefs.win32_fscodepage); } static char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src) { - return uacp_copy (dst, maxlen, src, currprefs.win32_fscodepage); + return uacp_copy (dst, maxlen, src, currprefs.win32_fscodepage); } static void aino_test (a_inode *aino) { #ifdef AINO_DEBUG - a_inode *aino2 = aino, *aino3; - for (;;) { - if (!aino || !aino->next) - return; - if ((aino->checksum1 ^ aino->checksum2) != 0xaaaa5555) { - write_log (L"PANIC: corrupted or freed but used aino detected!", aino); - } - aino3 = aino; - aino = aino->next; - if (aino->prev != aino3) { - write_log (L"PANIC: corrupted aino linking!\n"); - break; - } - if (aino == aino2) break; - } + a_inode *aino2 = aino, *aino3; + for (;;) { + if (!aino || !aino->next) + return; + if ((aino->checksum1 ^ aino->checksum2) != 0xaaaa5555) { + write_log (L"PANIC: corrupted or freed but used aino detected!", aino); + } + aino3 = aino; + aino = aino->next; + if (aino->prev != aino3) { + write_log (L"PANIC: corrupted aino linking!\n"); + break; + } + if (aino == aino2) break; + } #endif } static void aino_test_init (a_inode *aino) { #ifdef AINO_DEBUG - aino->checksum1 = (uae_u32)aino; - aino->checksum2 = aino->checksum1 ^ 0xaaaa5555; + aino->checksum1 = (uae_u32)aino; + aino->checksum2 = aino->checksum1 ^ 0xaaaa5555; #endif } @@ -128,441 +128,441 @@ static int automountunit = -1; #define DEVNAMES_PER_HDF 32 typedef struct { - int open; - TCHAR *devname; /* device name, e.g. UAE0: */ - uaecptr devname_amiga; - uaecptr startup; - TCHAR *volname; /* volume name, e.g. CDROM, WORK, etc. */ - int volflags; /* volume flags, readonly, stream uaefsdb support */ - TCHAR *rootdir; /* root native directory/hdf. empty drive if invalid path */ - struct zvolume *zarchive; - TCHAR *rootdirdiff; /* "diff" file/directory */ - int readonly; /* disallow write access? */ - int bootpri; /* boot priority. -128 = no autoboot, -129 = no mount */ - int devno; - int controller; - int wasisempty; /* if true, this unit was created empty */ - int canremove; /* if true, this unit can be safely ejected and remounted */ - int configureddrive; /* if true, this is drive that was manually configured */ - - struct hardfiledata hf; - - /* Threading stuff */ - smp_comm_pipe *volatile unit_pipe, *volatile back_pipe; - uae_thread_id tid; - struct _unit *self; - /* Reset handling */ - volatile uae_sem_t reset_sync_sem; - volatile int reset_state; - - /* RDB stuff */ - uaecptr rdb_devname_amiga[DEVNAMES_PER_HDF]; - int rdb_lowcyl; - int rdb_highcyl; - int rdb_cylblocks; - uae_u8 *rdb_filesysstore; - int rdb_filesyssize; - TCHAR *filesysdir; + int open; + TCHAR *devname; /* device name, e.g. UAE0: */ + uaecptr devname_amiga; + uaecptr startup; + TCHAR *volname; /* volume name, e.g. CDROM, WORK, etc. */ + int volflags; /* volume flags, readonly, stream uaefsdb support */ + TCHAR *rootdir; /* root native directory/hdf. empty drive if invalid path */ + struct zvolume *zarchive; + TCHAR *rootdirdiff; /* "diff" file/directory */ + int readonly; /* disallow write access? */ + int bootpri; /* boot priority. -128 = no autoboot, -129 = no mount */ + int devno; + int controller; + int wasisempty; /* if true, this unit was created empty */ + int canremove; /* if true, this unit can be safely ejected and remounted */ + int configureddrive; /* if true, this is drive that was manually configured */ + + struct hardfiledata hf; + + /* Threading stuff */ + smp_comm_pipe *volatile unit_pipe, *volatile back_pipe; + uae_thread_id tid; + struct _unit *self; + /* Reset handling */ + volatile uae_sem_t reset_sync_sem; + volatile int reset_state; + + /* RDB stuff */ + uaecptr rdb_devname_amiga[DEVNAMES_PER_HDF]; + int rdb_lowcyl; + int rdb_highcyl; + int rdb_cylblocks; + uae_u8 *rdb_filesysstore; + int rdb_filesyssize; + TCHAR *filesysdir; } UnitInfo; struct uaedev_mount_info { - UnitInfo ui[MAX_FILESYSTEM_UNITS]; + UnitInfo ui[MAX_FILESYSTEM_UNITS]; }; static struct uaedev_mount_info mountinfo; int nr_units (void) { - int i, cnt = 0; - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - if (mountinfo.ui[i].open) - cnt++; - } - return cnt; + int i, cnt = 0; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + if (mountinfo.ui[i].open) + cnt++; + } + return cnt; } int nr_directory_units (struct uae_prefs *p) { - int i, cnt = 0; - if (p) { - for (i = 0; i < p->mountitems; i++) { - if (p->mountconfig[i].controller == 0) - cnt++; - } - } else { - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - if (mountinfo.ui[i].open && mountinfo.ui[i].controller == 0) - cnt++; + int i, cnt = 0; + if (p) { + for (i = 0; i < p->mountitems; i++) { + if (p->mountconfig[i].controller == 0) + cnt++; + } + } else { + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + if (mountinfo.ui[i].open && mountinfo.ui[i].controller == 0) + cnt++; + } } - } - return cnt; + return cnt; } int is_hardfile (int unit_no) { - if (mountinfo.ui[unit_no].volname || mountinfo.ui[unit_no].wasisempty) - return FILESYS_VIRTUAL; - if (mountinfo.ui[unit_no].hf.secspertrack == 0) { - if (mountinfo.ui[unit_no].hf.flags & 1) - return FILESYS_HARDDRIVE; - return FILESYS_HARDFILE_RDB; - } - return FILESYS_HARDFILE; + if (mountinfo.ui[unit_no].volname || mountinfo.ui[unit_no].wasisempty) + return FILESYS_VIRTUAL; + if (mountinfo.ui[unit_no].hf.secspertrack == 0) { + if (mountinfo.ui[unit_no].hf.flags & 1) + return FILESYS_HARDDRIVE; + return FILESYS_HARDFILE_RDB; + } + return FILESYS_HARDFILE; } static void close_filesys_unit (UnitInfo *uip) { - if (!uip->open) - return; - if (uip->hf.handle_valid) - hdf_close (&uip->hf); - if (uip->volname != 0) - xfree (uip->volname); - if (uip->devname != 0) - xfree (uip->devname); - if (uip->rootdir != 0) - xfree (uip->rootdir); - if (uip->unit_pipe) - xfree (uip->unit_pipe); - if (uip->back_pipe) - xfree (uip->back_pipe); - - uip->unit_pipe = 0; - uip->back_pipe = 0; - - uip->hf.handle_valid = 0; - uip->volname = 0; - uip->devname = 0; - uip->rootdir = 0; - uip->open = 0; + if (!uip->open) + return; + if (uip->hf.handle_valid) + hdf_close (&uip->hf); + if (uip->volname != 0) + xfree (uip->volname); + if (uip->devname != 0) + xfree (uip->devname); + if (uip->rootdir != 0) + xfree (uip->rootdir); + if (uip->unit_pipe) + xfree (uip->unit_pipe); + if (uip->back_pipe) + xfree (uip->back_pipe); + + uip->unit_pipe = 0; + uip->back_pipe = 0; + + uip->hf.handle_valid = 0; + uip->volname = 0; + uip->devname = 0; + uip->rootdir = 0; + uip->open = 0; } static UnitInfo *getuip(struct uae_prefs *p, int index) { - if (index < 0) - return NULL; - index = p->mountconfig[index].configoffset; - if (index < 0) - return NULL; - return &mountinfo.ui[index]; + if (index < 0) + return NULL; + index = p->mountconfig[index].configoffset; + if (index < 0) + return NULL; + return &mountinfo.ui[index]; } int get_filesys_unitconfig (struct uae_prefs *p, int index, struct mountedinfo *mi) { - UnitInfo *ui = getuip(p, index); - struct uaedev_config_info *uci = &p->mountconfig[index]; - UnitInfo uitmp; - - memset (mi, 0, sizeof (struct mountedinfo)); - memset (&uitmp, 0, sizeof uitmp); - if (!ui) { - ui = &uitmp; - if (!uci->ishdf) { - mi->ismounted = 1; - if (uci->rootdir && _tcslen(uci->rootdir) == 0) - return FILESYS_VIRTUAL; - if (my_existsfile (uci->rootdir)) { - mi->ismedia = 1; - return FILESYS_VIRTUAL; - } - if (my_getvolumeinfo (uci->rootdir) < 0) - return -1; - mi->ismedia = 1; - return FILESYS_VIRTUAL; + UnitInfo *ui = getuip(p, index); + struct uaedev_config_info *uci = &p->mountconfig[index]; + UnitInfo uitmp; + + memset (mi, 0, sizeof (struct mountedinfo)); + memset (&uitmp, 0, sizeof uitmp); + if (!ui) { + ui = &uitmp; + if (!uci->ishdf) { + mi->ismounted = 1; + if (uci->rootdir && _tcslen(uci->rootdir) == 0) + return FILESYS_VIRTUAL; + if (my_existsfile (uci->rootdir)) { + mi->ismedia = 1; + return FILESYS_VIRTUAL; + } + if (my_getvolumeinfo (uci->rootdir) < 0) + return -1; + mi->ismedia = 1; + return FILESYS_VIRTUAL; + } else { + ui->hf.readonly = 1; + ui->hf.blocksize = uci->blocksize; + if (!hdf_open (&ui->hf, uci->rootdir)) { + mi->ismedia = 0; + mi->ismounted = 1; + if (uci->reserved == 0 && uci->sectors == 0 && uci->surfaces == 0) { + if (ui->hf.flags & 1) + return FILESYS_HARDDRIVE; + return FILESYS_HARDFILE_RDB; + } + return -1; + } + mi->ismedia = 1; + if (ui->hf.drive_empty) + mi->ismedia = 0; + hdf_close (&ui->hf); + } } else { - ui->hf.readonly = 1; - ui->hf.blocksize = uci->blocksize; - if (!hdf_open (&ui->hf, uci->rootdir)) { - mi->ismedia = 0; - mi->ismounted = 1; - if (uci->reserved == 0 && uci->sectors == 0 && uci->surfaces == 0) { - if (ui->hf.flags & 1) - return FILESYS_HARDDRIVE; - return FILESYS_HARDFILE_RDB; + if (!ui->controller || (ui->controller && p->cs_ide)) { + mi->ismounted = 1; + if (uci->ishdf) + mi->ismedia = ui->hf.drive_empty ? 0 : 1; + else + mi->ismedia = 1; } - return -1; - } - mi->ismedia = 1; - if (ui->hf.drive_empty) - mi->ismedia = 0; - hdf_close (&ui->hf); - } - } else { - if (!ui->controller || (ui->controller && p->cs_ide)) { - mi->ismounted = 1; - if (uci->ishdf) - mi->ismedia = ui->hf.drive_empty ? 0 : 1; - else - mi->ismedia = 1; - } - } - mi->size = ui->hf.virtsize; - mi->nrcyls = (int)(uci->sectors * uci->surfaces ? (ui->hf.virtsize / uci->blocksize) / (uci->sectors * uci->surfaces) : 0); - if (!uci->ishdf) - return FILESYS_VIRTUAL; - if (uci->reserved == 0 && uci->sectors == 0 && uci->surfaces == 0) { - if (ui->hf.flags & 1) - return FILESYS_HARDDRIVE; - return FILESYS_HARDFILE_RDB; - } - return FILESYS_HARDFILE; + } + mi->size = ui->hf.virtsize; + mi->nrcyls = (int)(uci->sectors * uci->surfaces ? (ui->hf.virtsize / uci->blocksize) / (uci->sectors * uci->surfaces) : 0); + if (!uci->ishdf) + return FILESYS_VIRTUAL; + if (uci->reserved == 0 && uci->sectors == 0 && uci->surfaces == 0) { + if (ui->hf.flags & 1) + return FILESYS_HARDDRIVE; + return FILESYS_HARDFILE_RDB; + } + return FILESYS_HARDFILE; } static void stripsemicolon (TCHAR *s) { - if (!s) - return; - while(_tcslen(s) > 0 && s[_tcslen(s) - 1] == ':') - s[_tcslen(s) - 1] = 0; + if (!s) + return; + while(_tcslen(s) > 0 && s[_tcslen(s) - 1] == ':') + s[_tcslen(s) - 1] = 0; } TCHAR *filesys_createvolname (const TCHAR *volname, const TCHAR *rootdir, const TCHAR *def) { - TCHAR *nvol = NULL; - int i, archivehd; - TCHAR *p = NULL; - - archivehd = -1; - if (my_existsfile (rootdir)) - archivehd = 1; - else if (my_existsdir (rootdir)) - archivehd = 0; - - if ((!volname || _tcslen (volname) == 0) && rootdir && archivehd >= 0) { - p = my_strdup (rootdir); - for (i = _tcslen (p) - 1; i >= 0; i--) { - TCHAR c = p[i]; - if (c == ':' || c == '/' || c == '\\') { - if (i == _tcslen (p) - 1) - continue; - if (!_tcscmp (p + i, L":\\")) { - xfree (p); - p = xmalloc (10 * sizeof (TCHAR)); - p[0] = rootdir[0]; - p[1] = 0; - i = 0; - } else { - i++; + TCHAR *nvol = NULL; + int i, archivehd; + TCHAR *p = NULL; + + archivehd = -1; + if (my_existsfile (rootdir)) + archivehd = 1; + else if (my_existsdir (rootdir)) + archivehd = 0; + + if ((!volname || _tcslen (volname) == 0) && rootdir && archivehd >= 0) { + p = my_strdup (rootdir); + for (i = _tcslen (p) - 1; i >= 0; i--) { + TCHAR c = p[i]; + if (c == ':' || c == '/' || c == '\\') { + if (i == _tcslen (p) - 1) + continue; + if (!_tcscmp (p + i, L":\\")) { + xfree (p); + p = xmalloc (10 * sizeof (TCHAR)); + p[0] = rootdir[0]; + p[1] = 0; + i = 0; + } else { + i++; + } + break; + } } - break; - } - } - if (i >= 0) - nvol = my_strdup (p + i); - } - if (!nvol && archivehd >= 0) { - TCHAR *s = NULL; - if (volname && _tcslen (volname) > 0) - nvol = my_strdup (volname); - else - nvol = my_strdup (def); - } - if (!nvol) { - if (volname && _tcslen (volname)) - nvol = my_strdup (volname); - else - nvol = my_strdup (L""); - } - stripsemicolon (nvol); - xfree (p); - return nvol; + if (i >= 0) + nvol = my_strdup (p + i); + } + if (!nvol && archivehd >= 0) { + TCHAR *s = NULL; + if (volname && _tcslen (volname) > 0) + nvol = my_strdup (volname); + else + nvol = my_strdup (def); + } + if (!nvol) { + if (volname && _tcslen (volname)) + nvol = my_strdup (volname); + else + nvol = my_strdup (L""); + } + stripsemicolon (nvol); + xfree (p); + return nvol; } static int set_filesys_volume (const TCHAR *rootdir, int *flags, int *readonly, int *emptydrive, struct zvolume **zvp) { - *emptydrive = 0; - if (my_existsfile (rootdir)) { - struct zvolume *zv; - zv = zfile_fopen_archive (rootdir); - if (!zv) { - write_log (L"'%s' is not a supported archive file\n", rootdir); - return -1; - } - *zvp = zv; - *flags = MYVOLUMEINFO_ARCHIVE; - *readonly = 1; - } else { - *flags = my_getvolumeinfo (rootdir); - if (*flags < 0) { - if (rootdir && rootdir[0]) - write_log (L"directory '%s' not found, mounting as empty drive\n", rootdir); - *emptydrive = 1; - *flags = 0; - } else if ((*flags) & MYVOLUMEINFO_READONLY) { - write_log (L"'%s' set to read-only\n", rootdir); - *readonly = 1; - } - } - return 1; + *emptydrive = 0; + if (my_existsfile (rootdir)) { + struct zvolume *zv; + zv = zfile_fopen_archive (rootdir); + if (!zv) { + write_log (L"'%s' is not a supported archive file\n", rootdir); + return -1; + } + *zvp = zv; + *flags = MYVOLUMEINFO_ARCHIVE; + *readonly = 1; + } else { + *flags = my_getvolumeinfo (rootdir); + if (*flags < 0) { + if (rootdir && rootdir[0]) + write_log (L"directory '%s' not found, mounting as empty drive\n", rootdir); + *emptydrive = 1; + *flags = 0; + } else if ((*flags) & MYVOLUMEINFO_READONLY) { + write_log (L"'%s' set to read-only\n", rootdir); + *readonly = 1; + } + } + return 1; } static int set_filesys_unit_1 (int nr, - TCHAR *devname, TCHAR *volname, const TCHAR *rootdir, int readonly, - int secspertrack, int surfaces, int reserved, - int blocksize, int bootpri, int donotmount, int autoboot, - TCHAR *filesysdir, int hdc, int flags) + TCHAR *devname, TCHAR *volname, const TCHAR *rootdir, int readonly, + int secspertrack, int surfaces, int reserved, + int blocksize, int bootpri, int donotmount, int autoboot, + TCHAR *filesysdir, int hdc, int flags) { - UnitInfo *ui; - int i; - int emptydrive = 0; + UnitInfo *ui; + int i; + int emptydrive = 0; - if (hdc) - return -1; - if (nr < 0) { - for (nr = 0; nr < MAX_FILESYSTEM_UNITS; nr++) { - if (!mountinfo.ui[nr].open) - break; - } - if (nr == MAX_FILESYSTEM_UNITS) { - write_log (L"No slot allocated for this unit\n"); - return -1; + if (hdc) + return -1; + if (nr < 0) { + for (nr = 0; nr < MAX_FILESYSTEM_UNITS; nr++) { + if (!mountinfo.ui[nr].open) + break; + } + if (nr == MAX_FILESYSTEM_UNITS) { + write_log (L"No slot allocated for this unit\n"); + return -1; + } } - } - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - if (nr == i || !mountinfo.ui[i].open) - continue; - if (rootdir && _tcslen (rootdir) > 0 && !_tcsicmp (mountinfo.ui[i].rootdir, rootdir)) { - write_log (L"directory/hardfile '%s' already added\n", rootdir); - return -1; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + if (nr == i || !mountinfo.ui[i].open) + continue; + if (rootdir && _tcslen (rootdir) > 0 && !_tcsicmp (mountinfo.ui[i].rootdir, rootdir)) { + write_log (L"directory/hardfile '%s' already added\n", rootdir); + return -1; + } } - } - - ui = &mountinfo.ui[nr]; - memset (ui, 0, sizeof (UnitInfo)); - if (volname != NULL) { - int flags = 0; - emptydrive = 1; - if (rootdir) { - if (set_filesys_volume (rootdir, &flags, &readonly, &emptydrive, &ui->zarchive) < 0) - return -1; + ui = &mountinfo.ui[nr]; + memset (ui, 0, sizeof (UnitInfo)); + + if (volname != NULL) { + int flags = 0; + emptydrive = 1; + if (rootdir) { + if (set_filesys_volume (rootdir, &flags, &readonly, &emptydrive, &ui->zarchive) < 0) + return -1; + } + ui->volname = filesys_createvolname (volname, rootdir, L"harddrive"); + ui->volflags = flags; + } else { + ui->hf.secspertrack = secspertrack; + ui->hf.surfaces = surfaces; + ui->hf.reservedblocks = reserved; + ui->hf.blocksize = blocksize; + ui->hf.unitnum = nr; + ui->volname = 0; + ui->hf.readonly = readonly; + if (!hdf_open (&ui->hf, rootdir) && !readonly) { + ui->hf.readonly = readonly = 1; + hdf_open (&ui->hf, rootdir); + } + ui->hf.readonly = readonly; + if (!ui->hf.drive_empty) { + if (ui->hf.handle_valid == 0) { + write_log (L"Hardfile %s not found\n", ui->hf.device_name); + goto err; + } + if ((ui->hf.blocksize & (ui->hf.blocksize - 1)) != 0 || ui->hf.blocksize == 0) { + write_log (L"Hardfile %s bad blocksize\n", ui->hf.device_name); + goto err; + } + if ((ui->hf.secspertrack || ui->hf.surfaces || ui->hf.reservedblocks) && + (ui->hf.secspertrack < 1 || ui->hf.surfaces < 1 || ui->hf.surfaces > 1023 || + ui->hf.reservedblocks < 0 || ui->hf.reservedblocks > 1023) != 0) { + write_log (L"Hardfile %s bad hardfile geometry\n", ui->hf.device_name); + goto err; + } + if (ui->hf.blocksize > ui->hf.virtsize || ui->hf.virtsize == 0) { + write_log (L"Hardfile %s too small\n", ui->hf.device_name); + goto err; + } + ui->hf.nrcyls = (int)(ui->hf.secspertrack * ui->hf.surfaces ? (ui->hf.virtsize / ui->hf.blocksize) / (ui->hf.secspertrack * ui->hf.surfaces) : 0); + } } - ui->volname = filesys_createvolname (volname, rootdir, L"harddrive"); - ui->volflags = flags; - } else { - ui->hf.secspertrack = secspertrack; - ui->hf.surfaces = surfaces; - ui->hf.reservedblocks = reserved; - ui->hf.blocksize = blocksize; - ui->hf.unitnum = nr; - ui->volname = 0; - ui->hf.readonly = readonly; - if (!hdf_open (&ui->hf, rootdir) && !readonly) { - ui->hf.readonly = readonly = 1; - hdf_open (&ui->hf, rootdir); - } - ui->hf.readonly = readonly; - if (!ui->hf.drive_empty) { - if (ui->hf.handle_valid == 0) { - write_log (L"Hardfile %s not found\n", ui->hf.device_name); - goto err; - } - if ((ui->hf.blocksize & (ui->hf.blocksize - 1)) != 0 || ui->hf.blocksize == 0) { - write_log (L"Hardfile %s bad blocksize\n", ui->hf.device_name); - goto err; - } - if ((ui->hf.secspertrack || ui->hf.surfaces || ui->hf.reservedblocks) && - (ui->hf.secspertrack < 1 || ui->hf.surfaces < 1 || ui->hf.surfaces > 1023 || - ui->hf.reservedblocks < 0 || ui->hf.reservedblocks > 1023) != 0) { - write_log (L"Hardfile %s bad hardfile geometry\n", ui->hf.device_name); - goto err; - } - if (ui->hf.blocksize > ui->hf.virtsize || ui->hf.virtsize == 0) { - write_log (L"Hardfile %s too small\n", ui->hf.device_name); - goto err; - } - ui->hf.nrcyls = (int)(ui->hf.secspertrack * ui->hf.surfaces ? (ui->hf.virtsize / ui->hf.blocksize) / (ui->hf.secspertrack * ui->hf.surfaces) : 0); - } - } - ui->self = 0; - ui->reset_state = FS_STARTUP; - ui->wasisempty = emptydrive; - ui->canremove = emptydrive && (flags & MYVOLUMEINFO_REUSABLE); - ui->rootdir = my_strdup (rootdir); - ui->devname = my_strdup (devname); - stripsemicolon(ui->devname); - if (filesysdir && filesysdir[0]) - ui->filesysdir = my_strdup (filesysdir); - ui->readonly = readonly; - if (!autoboot) - bootpri = -128; - if (donotmount) - bootpri = -129; - if (bootpri < -129) bootpri = -129; - if (bootpri > 127) bootpri = 127; - ui->bootpri = bootpri; - ui->open = 1; - - return nr; + ui->self = 0; + ui->reset_state = FS_STARTUP; + ui->wasisempty = emptydrive; + ui->canremove = emptydrive && (flags & MYVOLUMEINFO_REUSABLE); + ui->rootdir = my_strdup (rootdir); + ui->devname = my_strdup (devname); + stripsemicolon(ui->devname); + if (filesysdir && filesysdir[0]) + ui->filesysdir = my_strdup (filesysdir); + ui->readonly = readonly; + if (!autoboot) + bootpri = -128; + if (donotmount) + bootpri = -129; + if (bootpri < -129) bootpri = -129; + if (bootpri > 127) bootpri = 127; + ui->bootpri = bootpri; + ui->open = 1; + + return nr; err: - if (ui->hf.handle_valid) - hdf_close(&ui->hf); - return -1; + if (ui->hf.handle_valid) + hdf_close(&ui->hf); + return -1; } static int set_filesys_unit (int nr, - TCHAR *devname, TCHAR *volname, const TCHAR *rootdir, int readonly, - int secspertrack, int surfaces, int reserved, - int blocksize, int bootpri, int donotmount, int autoboot, - TCHAR *filesysdir, int hdc, int flags) + TCHAR *devname, TCHAR *volname, const TCHAR *rootdir, int readonly, + int secspertrack, int surfaces, int reserved, + int blocksize, int bootpri, int donotmount, int autoboot, + TCHAR *filesysdir, int hdc, int flags) { - int ret; + int ret; - ret = set_filesys_unit_1 (nr, devname, volname, rootdir, readonly, - secspertrack, surfaces, reserved, blocksize, bootpri, donotmount, autoboot, - filesysdir, hdc, flags); - return ret; + ret = set_filesys_unit_1 (nr, devname, volname, rootdir, readonly, + secspertrack, surfaces, reserved, blocksize, bootpri, donotmount, autoboot, + filesysdir, hdc, flags); + return ret; } static int add_filesys_unit (TCHAR *devname, TCHAR *volname, const TCHAR *rootdir, int readonly, - int secspertrack, int surfaces, int reserved, - int blocksize, int bootpri, int donotmount, int autoboot, - TCHAR *filesysdir, int hdc, int flags) + int secspertrack, int surfaces, int reserved, + int blocksize, int bootpri, int donotmount, int autoboot, + TCHAR *filesysdir, int hdc, int flags) { - int ret; + int ret; - if (nr_units() >= MAX_FILESYSTEM_UNITS) - return -1; + if (nr_units() >= MAX_FILESYSTEM_UNITS) + return -1; - ret = set_filesys_unit_1 (-1, devname, volname, rootdir, readonly, - secspertrack, surfaces, reserved, blocksize, - bootpri, donotmount, autoboot, filesysdir, hdc, flags); - return ret; + ret = set_filesys_unit_1 (-1, devname, volname, rootdir, readonly, + secspertrack, surfaces, reserved, blocksize, + bootpri, donotmount, autoboot, filesysdir, hdc, flags); + return ret; } int kill_filesys_unitconfig (struct uae_prefs *p, int nr) { - struct uaedev_config_info *uci; + struct uaedev_config_info *uci; - if (nr < 0) - return 0; - uci = &p->mountconfig[nr]; - hardfile_do_disk_change (uci, 0); - if (uci->configoffset >= 0 && uci->controller == 0) - filesys_media_change (uci->rootdir, 0, uci); - while (nr < MOUNT_CONFIG_SIZE) { - memmove (&p->mountconfig[nr], &p->mountconfig[nr + 1], sizeof (struct uaedev_config_info)); - nr++; - } - p->mountitems--; - memset (&p->mountconfig[MOUNT_CONFIG_SIZE - 1], 0, sizeof (struct uaedev_config_info)); - return 1; + if (nr < 0) + return 0; + uci = &p->mountconfig[nr]; + hardfile_do_disk_change (uci, 0); + if (uci->configoffset >= 0 && uci->controller == 0) + filesys_media_change (uci->rootdir, 0, uci); + while (nr < MOUNT_CONFIG_SIZE) { + memmove (&p->mountconfig[nr], &p->mountconfig[nr + 1], sizeof (struct uaedev_config_info)); + nr++; + } + p->mountitems--; + memset (&p->mountconfig[MOUNT_CONFIG_SIZE - 1], 0, sizeof (struct uaedev_config_info)); + return 1; } int move_filesys_unitconfig (struct uae_prefs *p, int nr, int to) { - struct uaedev_config_info *uci1, *uci2, tmpuci; + struct uaedev_config_info *uci1, *uci2, tmpuci; - uci1 = &p->mountconfig[nr]; - uci2 = &p->mountconfig[to]; - if (nr == to) - return 0; - memcpy (&tmpuci, uci1, sizeof (struct uaedev_config_info)); - memcpy (uci1, uci2, sizeof (struct uaedev_config_info)); - memcpy (uci2, &tmpuci, sizeof (struct uaedev_config_info)); - return 1; + uci1 = &p->mountconfig[nr]; + uci2 = &p->mountconfig[to]; + if (nr == to) + return 0; + memcpy (&tmpuci, uci1, sizeof (struct uaedev_config_info)); + memcpy (uci1, uci2, sizeof (struct uaedev_config_info)); + memcpy (uci2, &tmpuci, sizeof (struct uaedev_config_info)); + return 1; } @@ -570,76 +570,76 @@ static void filesys_addexternals (void); static void initialize_mountinfo (void) { - int i; - struct uaedev_config_info *uci; - UnitInfo *uip = &mountinfo.ui[0]; - - for (i = 0; i < currprefs.mountitems; i++) { - int idx; - uci = &currprefs.mountconfig[i]; - if (uci->controller == HD_CONTROLLER_UAE) { - idx = set_filesys_unit_1 (-1, uci->devname, uci->ishdf ? NULL : uci->volname, uci->rootdir, - uci->readonly, uci->sectors, uci->surfaces, uci->reserved, - uci->blocksize, uci->bootpri, uci->donotmount, uci->autoboot, uci->filesys, 0, MYVOLUMEINFO_REUSABLE); - if (idx >= 0) { - UnitInfo *ui; - uci->configoffset = idx; - ui = &mountinfo.ui[idx]; - ui->configureddrive = 1; - } - } else if (uci->controller <= HD_CONTROLLER_IDE3) { - gayle_add_ide_unit (uci->controller - HD_CONTROLLER_IDE0, uci->rootdir, uci->blocksize, uci->readonly, - uci->devname, uci->sectors, uci->surfaces, uci->reserved, - uci->bootpri, uci->filesys); - } else if (uci->controller <= HD_CONTROLLER_SCSI6) { - if (currprefs.cs_mbdmac) { - a3000_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, - uci->devname, uci->sectors, uci->surfaces, uci->reserved, - uci->bootpri, uci->filesys); - } else if (currprefs.cs_a2091) { - a2091_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, - uci->devname, uci->sectors, uci->surfaces, uci->reserved, - uci->bootpri, uci->filesys); - } else if (currprefs.cs_cdtvscsi) { - cdtv_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, - uci->devname, uci->sectors, uci->surfaces, uci->reserved, - uci->bootpri, uci->filesys); - } - } else if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { - gayle_add_pcmcia_sram_unit (uci->rootdir, uci->readonly); - } - } - filesys_addexternals (); + int i; + struct uaedev_config_info *uci; + UnitInfo *uip = &mountinfo.ui[0]; + + for (i = 0; i < currprefs.mountitems; i++) { + int idx; + uci = &currprefs.mountconfig[i]; + if (uci->controller == HD_CONTROLLER_UAE) { + idx = set_filesys_unit_1 (-1, uci->devname, uci->ishdf ? NULL : uci->volname, uci->rootdir, + uci->readonly, uci->sectors, uci->surfaces, uci->reserved, + uci->blocksize, uci->bootpri, uci->donotmount, uci->autoboot, uci->filesys, 0, MYVOLUMEINFO_REUSABLE); + if (idx >= 0) { + UnitInfo *ui; + uci->configoffset = idx; + ui = &mountinfo.ui[idx]; + ui->configureddrive = 1; + } + } else if (uci->controller <= HD_CONTROLLER_IDE3) { + gayle_add_ide_unit (uci->controller - HD_CONTROLLER_IDE0, uci->rootdir, uci->blocksize, uci->readonly, + uci->devname, uci->sectors, uci->surfaces, uci->reserved, + uci->bootpri, uci->filesys); + } else if (uci->controller <= HD_CONTROLLER_SCSI6) { + if (currprefs.cs_mbdmac) { + a3000_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, + uci->devname, uci->sectors, uci->surfaces, uci->reserved, + uci->bootpri, uci->filesys); + } else if (currprefs.cs_a2091) { + a2091_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, + uci->devname, uci->sectors, uci->surfaces, uci->reserved, + uci->bootpri, uci->filesys); + } else if (currprefs.cs_cdtvscsi) { + cdtv_add_scsi_unit (uci->controller - HD_CONTROLLER_SCSI0, uci->rootdir, uci->blocksize, uci->readonly, + uci->devname, uci->sectors, uci->surfaces, uci->reserved, + uci->bootpri, uci->filesys); + } + } else if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { + gayle_add_pcmcia_sram_unit (uci->rootdir, uci->readonly); + } + } + filesys_addexternals (); } int sprintf_filesys_unit (TCHAR *buffer, int num) { - UnitInfo *uip = mountinfo.ui; + UnitInfo *uip = mountinfo.ui; - if (uip[num].volname != 0) - _stprintf (buffer, L"(DH%d:) Filesystem, %s: %s %s", num, uip[num].volname, - uip[num].rootdir, uip[num].readonly ? "ro" : ""); - else - _stprintf (buffer, L"(DH%d:) Hardfile, \"%s\", size %d Mbytes", num, - uip[num].rootdir, uip[num].hf.virtsize / (1024 * 1024)); - return 0; + if (uip[num].volname != 0) + _stprintf (buffer, L"(DH%d:) Filesystem, %s: %s %s", num, uip[num].volname, + uip[num].rootdir, uip[num].readonly ? "ro" : ""); + else + _stprintf (buffer, L"(DH%d:) Hardfile, \"%s\", size %d Mbytes", num, + uip[num].rootdir, uip[num].hf.virtsize / (1024 * 1024)); + return 0; } void free_mountinfo (void) { - int i; - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) - close_filesys_unit (mountinfo.ui + i); - gayle_free_units (); + int i; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) + close_filesys_unit (mountinfo.ui + i); + gayle_free_units (); } struct hardfiledata *get_hardfile_data (int nr) { - UnitInfo *uip = mountinfo.ui; - if (nr < 0 || nr >= MAX_FILESYSTEM_UNITS || uip[nr].open == 0 || is_hardfile (nr) == FILESYS_VIRTUAL) - return 0; - return &uip[nr].hf; + UnitInfo *uip = mountinfo.ui; + if (nr < 0 || nr >= MAX_FILESYSTEM_UNITS || uip[nr].open == 0 || is_hardfile (nr) == FILESYS_VIRTUAL) + return 0; + return &uip[nr].hf; } /* minimal AmigaDOS definitions */ @@ -737,41 +737,41 @@ struct hardfiledata *get_hardfile_data (int nr) #define DISK_TYPE 0x444f5301 /* DOS\1 */ typedef struct { - uae_u32 uniq; - /* The directory we're going through. */ - a_inode *aino; - /* The file we're going to look up next. */ - a_inode *curr_file; + uae_u32 uniq; + /* The directory we're going through. */ + a_inode *aino; + /* The file we're going to look up next. */ + a_inode *curr_file; } ExamineKey; typedef struct key { - struct key *next; - a_inode *aino; - uae_u32 uniq; - void *fd; - uae_u64 file_pos; - int dosmode; - int createmode; - int notifyactive; + struct key *next; + a_inode *aino; + uae_u32 uniq; + void *fd; + uae_u64 file_pos; + int dosmode; + int createmode; + int notifyactive; } Key; typedef struct notify { - struct notify *next; - uaecptr notifyrequest; - TCHAR *fullname; - TCHAR *partname; + struct notify *next; + uaecptr notifyrequest; + TCHAR *fullname; + TCHAR *partname; } Notify; typedef struct exallkey { - uae_u32 id; - void *dirhandle; - TCHAR *fn; - uaecptr control; + uae_u32 id; + void *dirhandle; + TCHAR *fn; + uaecptr control; } ExAllKey; /* Since ACTION_EXAMINE_NEXT is so braindamaged, we have to keep - * some of these around - */ +* some of these around +*/ #define EXKEYS 128 #define EXALLKEYS 100 @@ -781,57 +781,57 @@ typedef struct exallkey { /* handler state info */ typedef struct _unit { - struct _unit *next; - - /* Amiga stuff */ - uaecptr dosbase; - uaecptr volume; - uaecptr port; /* Our port */ - uaecptr locklist; - - /* Native stuff */ - uae_s32 unit; /* unit number */ - UnitInfo ui; /* unit startup info */ - TCHAR tmpbuf3[256]; - - /* Dummy message processing */ - uaecptr dummy_message; - volatile unsigned int cmds_sent; - volatile unsigned int cmds_complete; - volatile unsigned int cmds_acked; - - /* ExKeys */ - ExamineKey examine_keys[EXKEYS]; - int next_exkey; - unsigned long total_locked_ainos; - - /* ExAll */ - ExAllKey exalls[EXALLKEYS]; - int exallid; - - /* Keys */ - struct key *keys; - - a_inode rootnode; - unsigned long aino_cache_size; - a_inode *aino_hash[MAX_AINO_HASH]; - unsigned long nr_cache_hits; - unsigned long nr_cache_lookups; - - struct notify *notifyhash[NOTIFY_HASH_SIZE]; - - int volflags; - uae_u32 lockkey; - int inhibited; - int canremovable; - int mountcount; - struct zvolume *zarchive; - - int reinsertdelay; - TCHAR *newvolume; - TCHAR *newrootdir; - int newreadonly; - int newflags; + struct _unit *next; + + /* Amiga stuff */ + uaecptr dosbase; + uaecptr volume; + uaecptr port; /* Our port */ + uaecptr locklist; + + /* Native stuff */ + uae_s32 unit; /* unit number */ + UnitInfo ui; /* unit startup info */ + TCHAR tmpbuf3[256]; + + /* Dummy message processing */ + uaecptr dummy_message; + volatile unsigned int cmds_sent; + volatile unsigned int cmds_complete; + volatile unsigned int cmds_acked; + + /* ExKeys */ + ExamineKey examine_keys[EXKEYS]; + int next_exkey; + unsigned long total_locked_ainos; + + /* ExAll */ + ExAllKey exalls[EXALLKEYS]; + int exallid; + + /* Keys */ + struct key *keys; + + a_inode rootnode; + unsigned long aino_cache_size; + a_inode *aino_hash[MAX_AINO_HASH]; + unsigned long nr_cache_hits; + unsigned long nr_cache_lookups; + + struct notify *notifyhash[NOTIFY_HASH_SIZE]; + + int volflags; + uae_u32 lockkey; + int inhibited; + int canremovable; + int mountcount; + struct zvolume *zarchive; + + int reinsertdelay; + TCHAR *newvolume; + TCHAR *newrootdir; + int newreadonly; + int newflags; } Unit; @@ -866,569 +866,569 @@ static int flush_cache (Unit *unit, int num); static TCHAR *char1 (uaecptr addr) { - static uae_char buf[1024]; - static TCHAR bufx[1024]; - unsigned int i = 0; - do { - buf[i] = get_byte (addr); - addr++; - } while (buf[i++] && i < sizeof (buf)); - return au_fs_copy (bufx, sizeof (bufx) / sizeof (TCHAR), buf); + static uae_char buf[1024]; + static TCHAR bufx[1024]; + unsigned int i = 0; + do { + buf[i] = get_byte (addr); + addr++; + } while (buf[i++] && i < sizeof (buf)); + return au_fs_copy (bufx, sizeof (bufx) / sizeof (TCHAR), buf); } static TCHAR *bstr1 (uaecptr addr) { - static TCHAR bufx[257]; - static uae_char buf[257]; - int i; - int n = get_byte (addr); - addr++; + static TCHAR bufx[257]; + static uae_char buf[257]; + int i; + int n = get_byte (addr); + addr++; - for (i = 0; i < n; i++, addr++) - buf[i] = get_byte (addr); - buf[i] = 0; - return au_fs_copy (bufx, sizeof (bufx) / sizeof (TCHAR), buf); + for (i = 0; i < n; i++, addr++) + buf[i] = get_byte (addr); + buf[i] = 0; + return au_fs_copy (bufx, sizeof (bufx) / sizeof (TCHAR), buf); } static TCHAR *bstr (Unit *unit, uaecptr addr) { - int i; - int n = get_byte (addr); - uae_char buf[257]; + int i; + int n = get_byte (addr); + uae_char buf[257]; - addr++; - for (i = 0; i < n; i++, addr++) - buf[i] = get_byte (addr); - buf[i] = 0; - au_fs_copy (unit->tmpbuf3, sizeof (unit->tmpbuf3) / sizeof (TCHAR), buf); - return unit->tmpbuf3; + addr++; + for (i = 0; i < n; i++, addr++) + buf[i] = get_byte (addr); + buf[i] = 0; + au_fs_copy (unit->tmpbuf3, sizeof (unit->tmpbuf3) / sizeof (TCHAR), buf); + return unit->tmpbuf3; } static TCHAR *bstr_cut (Unit *unit, uaecptr addr) { - TCHAR *p = unit->tmpbuf3; - int i, colon_seen = 0; - int n = get_byte (addr); + TCHAR *p = unit->tmpbuf3; + int i, colon_seen = 0; + int n = get_byte (addr); - addr++; - for (i = 0; i < n; i++, addr++) { - uae_u8 c = get_byte (addr); - unit->tmpbuf3[i] = c; - if (c == '/' || (c == ':' && colon_seen++ == 0)) - p = unit->tmpbuf3 + i + 1; - } - unit->tmpbuf3[i] = 0; - return p; + addr++; + for (i = 0; i < n; i++, addr++) { + uae_u8 c = get_byte (addr); + unit->tmpbuf3[i] = c; + if (c == '/' || (c == ':' && colon_seen++ == 0)) + p = unit->tmpbuf3 + i + 1; + } + unit->tmpbuf3[i] = 0; + return p; } static Unit *units = 0; static Unit* -find_unit (uaecptr port) + find_unit (uaecptr port) { - Unit* u; - for (u = units; u; u = u->next) - if (u->port == port) - break; + Unit* u; + for (u = units; u; u = u->next) + if (u->port == port) + break; - return u; + return u; } static void *fs_opendir (Unit *u, const TCHAR *nname) { - if (u->volflags & MYVOLUMEINFO_ARCHIVE) - return zfile_opendir_archive (nname); - else - return my_opendir (nname); + if (u->volflags & MYVOLUMEINFO_ARCHIVE) + return zfile_opendir_archive (nname); + else + return my_opendir (nname); } static void fs_closedir (Unit *u, void *d) { - if (u->volflags & MYVOLUMEINFO_ARCHIVE) - zfile_closedir_archive (d); - else - my_closedir (d); + if (u->volflags & MYVOLUMEINFO_ARCHIVE) + zfile_closedir_archive (d); + else + my_closedir (d); } static void *fs_open (Unit *unit, const TCHAR *name, int flags) { - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - if (isarch) - return zfile_open_archive (name, flags); - else - return my_open (name, flags); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + if (isarch) + return zfile_open_archive (name, flags); + else + return my_open (name, flags); } static void fs_close (Unit *unit, void *fd) { - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - if (isarch) - zfile_close_archive (fd); - else - my_close (fd); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + if (isarch) + zfile_close_archive (fd); + else + my_close (fd); } static unsigned int fs_read (Unit *unit, void *d, void *b, unsigned int size) { - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - if (isarch) - return zfile_read_archive (d, b, size); - else - return my_read (d, b, size); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + if (isarch) + return zfile_read_archive (d, b, size); + else + return my_read (d, b, size); } static uae_u64 fs_lseek64 (Unit *unit, void *d, uae_s64 offset, int whence) { - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - if (isarch) - return zfile_lseek_archive (d, offset, whence); - else - return my_lseek (d, offset, whence); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + if (isarch) + return zfile_lseek_archive (d, offset, whence); + else + return my_lseek (d, offset, whence); } static uae_u32 fs_lseek (Unit *unit, void *d, uae_s32 offset, int whence) { - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - if (isarch) - return (uae_u32)zfile_lseek_archive (d, (uae_s32)offset, whence); - else - return (uae_u32)my_lseek (d, (uae_s32)offset, whence); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + if (isarch) + return (uae_u32)zfile_lseek_archive (d, (uae_s32)offset, whence); + else + return (uae_u32)my_lseek (d, (uae_s32)offset, whence); } static void set_volume_name (Unit *unit) { - int namelen; - int i; - char *s; - - s = ua_fs (unit->ui.volname); - namelen = strlen (s); - put_byte (unit->volume + 44, namelen); - for (i = 0; i < namelen; i++) - put_byte (unit->volume + 45 + i, s[i]); - put_byte (unit->volume + 45 + namelen, 0); - xfree (s); - unit->rootnode.aname = unit->ui.volname; - unit->rootnode.nname = unit->ui.rootdir; - unit->rootnode.mountcount = unit->mountcount; + int namelen; + int i; + char *s; + + s = ua_fs (unit->ui.volname); + namelen = strlen (s); + put_byte (unit->volume + 44, namelen); + for (i = 0; i < namelen; i++) + put_byte (unit->volume + 45 + i, s[i]); + put_byte (unit->volume + 45 + namelen, 0); + xfree (s); + unit->rootnode.aname = unit->ui.volname; + unit->rootnode.nname = unit->ui.rootdir; + unit->rootnode.mountcount = unit->mountcount; } static int filesys_isvolume (Unit *unit) { - return get_byte (unit->volume + 44); + return get_byte (unit->volume + 44); } static void clear_exkeys (Unit *unit) { - int i; - a_inode *a; - for (i = 0; i < EXKEYS; i++) { - unit->examine_keys[i].aino = 0; - unit->examine_keys[i].curr_file = 0; - unit->examine_keys[i].uniq = 0; - } - for (i = 0; i < EXALLKEYS; i++) { - fs_closedir (unit, unit->exalls[i].dirhandle); - unit->exalls[i].dirhandle = NULL; - xfree (unit->exalls[i].fn); - unit->exalls[i].fn = NULL; - unit->exalls[i].id = 0; - } - unit->exallid = 0; - unit->next_exkey = 1; - a = &unit->rootnode; - while (a) { - a->exnext_count = 0; - if (a->locked_children) { - a->locked_children = 0; - unit->total_locked_ainos--; - } - a = a->next; - if (a == &unit->rootnode) - break; - } + int i; + a_inode *a; + for (i = 0; i < EXKEYS; i++) { + unit->examine_keys[i].aino = 0; + unit->examine_keys[i].curr_file = 0; + unit->examine_keys[i].uniq = 0; + } + for (i = 0; i < EXALLKEYS; i++) { + fs_closedir (unit, unit->exalls[i].dirhandle); + unit->exalls[i].dirhandle = NULL; + xfree (unit->exalls[i].fn); + unit->exalls[i].fn = NULL; + unit->exalls[i].id = 0; + } + unit->exallid = 0; + unit->next_exkey = 1; + a = &unit->rootnode; + while (a) { + a->exnext_count = 0; + if (a->locked_children) { + a->locked_children = 0; + unit->total_locked_ainos--; + } + a = a->next; + if (a == &unit->rootnode) + break; + } } int filesys_eject (int nr) { - UnitInfo *ui = &mountinfo.ui[nr]; - Unit *u = ui->self; + UnitInfo *ui = &mountinfo.ui[nr]; + Unit *u = ui->self; - if (!mountertask) - return 0; - if (!ui->open || u == NULL) - return 0; - if (is_hardfile (nr) != FILESYS_VIRTUAL) - return 0; - if (!filesys_isvolume (u)) - return 0; - zfile_fclose_archive (u->zarchive); - u->zarchive = NULL; - u->mountcount++; - write_log (L"FILESYS: removed volume '%s'\n", u->ui.volname); - flush_cache (u, -1); - put_byte (u->volume + 172 - 32, -2); - uae_Signal (get_long (u->volume + 176 - 32), 1 << 13); - return 1; + if (!mountertask) + return 0; + if (!ui->open || u == NULL) + return 0; + if (is_hardfile (nr) != FILESYS_VIRTUAL) + return 0; + if (!filesys_isvolume (u)) + return 0; + zfile_fclose_archive (u->zarchive); + u->zarchive = NULL; + u->mountcount++; + write_log (L"FILESYS: removed volume '%s'\n", u->ui.volname); + flush_cache (u, -1); + put_byte (u->volume + 172 - 32, -2); + uae_Signal (get_long (u->volume + 176 - 32), 1 << 13); + return 1; } void filesys_vsync (void) { - Unit *u; + Unit *u; - for (u = units; u; u = u->next) { - if (u->reinsertdelay > 0) { - u->reinsertdelay--; - if (u->reinsertdelay == 0) { - filesys_insert (u->unit, u->newvolume, u->newrootdir, u->newreadonly, u->newflags); - xfree (u->newvolume); - u->newvolume = NULL; - xfree (u->newrootdir); - u->newrootdir = NULL; - } + for (u = units; u; u = u->next) { + if (u->reinsertdelay > 0) { + u->reinsertdelay--; + if (u->reinsertdelay == 0) { + filesys_insert (u->unit, u->newvolume, u->newrootdir, u->newreadonly, u->newflags); + xfree (u->newvolume); + u->newvolume = NULL; + xfree (u->newrootdir); + u->newrootdir = NULL; + } + } } - } } static void filesys_delayed_change (Unit *u, int frames, const TCHAR *rootdir, const TCHAR *volume, int readonly, int flags) { - u->reinsertdelay = 50; - u->newflags = flags; - u->newreadonly = readonly; - u->newrootdir = my_strdup (rootdir); - if (volume) - u->newvolume = my_strdup (volume); - filesys_eject(u->unit); - if (!rootdir || _tcslen (rootdir) == 0) - u->reinsertdelay = 0; - if (u->reinsertdelay > 0) - write_log (L"FILESYS: delayed insert %d: '%s' ('%s')\n", u->unit, volume ? volume : L"", rootdir); + u->reinsertdelay = 50; + u->newflags = flags; + u->newreadonly = readonly; + u->newrootdir = my_strdup (rootdir); + if (volume) + u->newvolume = my_strdup (volume); + filesys_eject(u->unit); + if (!rootdir || _tcslen (rootdir) == 0) + u->reinsertdelay = 0; + if (u->reinsertdelay > 0) + write_log (L"FILESYS: delayed insert %d: '%s' ('%s')\n", u->unit, volume ? volume : L"", rootdir); } int filesys_media_change (const TCHAR *rootdir, int inserted, struct uaedev_config_info *uci) { - Unit *u; - UnitInfo *ui; - int nr = -1; - TCHAR volname[MAX_DPATH], *volptr; - TCHAR devname[MAX_DPATH]; + Unit *u; + UnitInfo *ui; + int nr = -1; + TCHAR volname[MAX_DPATH], *volptr; + TCHAR devname[MAX_DPATH]; - if (!mountertask) - return 0; - if (automountunit >= 0) - return -1; - nr = -1; - for (u = units; u; u = u->next) { - if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { - ui = &mountinfo.ui[u->unit]; - if (ui->rootdir && !memcmp (ui->rootdir, rootdir, _tcslen (rootdir)) && _tcslen (rootdir) + 3 >= _tcslen (ui->rootdir)) { - if (filesys_isvolume (u) && inserted) { - if (uci) - filesys_delayed_change (u, 50, rootdir, uci->volname, uci->readonly, 0); - return 0; + if (!mountertask) + return 0; + if (automountunit >= 0) + return -1; + nr = -1; + for (u = units; u; u = u->next) { + if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { + ui = &mountinfo.ui[u->unit]; + if (ui->rootdir && !memcmp (ui->rootdir, rootdir, _tcslen (rootdir)) && _tcslen (rootdir) + 3 >= _tcslen (ui->rootdir)) { + if (filesys_isvolume (u) && inserted) { + if (uci) + filesys_delayed_change (u, 50, rootdir, uci->volname, uci->readonly, 0); + return 0; + } + nr = u->unit; + break; + } } - nr = u->unit; - break; - } } - } - ui = NULL; - if (nr >= 0) - ui = &mountinfo.ui[nr]; - /* only configured drives have automount support if automount is disabled */ - if (!currprefs.win32_automount_removable && (!ui || !ui->configureddrive) && (inserted == 0 || inserted == 1)) - return 0; - if (nr < 0 && !inserted) + ui = NULL; + if (nr >= 0) + ui = &mountinfo.ui[nr]; + /* only configured drives have automount support if automount is disabled */ + if (!currprefs.win32_automount_removable && (!ui || !ui->configureddrive) && (inserted == 0 || inserted == 1)) + return 0; + if (nr < 0 && !inserted) + return 0; + /* already mounted volume was ejected? */ + if (nr >= 0 && !inserted) + return filesys_eject (nr); + if (inserted) { + if (uci) { + volptr = my_strdup (uci->volname); + } else { + volname[0] = 0; + target_get_volume_name (&mountinfo, rootdir, volname, MAX_DPATH, 1, 0); + volptr = volname; + if (!volname[0]) + volptr = NULL; + if (ui && ui->configureddrive && ui->volname) { + volptr = volname; + _tcscpy (volptr, ui->volname); + } + } + if (!volptr) { + volptr = filesys_createvolname (NULL, rootdir, L"removable"); + _tcscpy (volname, volptr); + xfree (volptr); + volptr = volname; + } + + /* new volume inserted and it was previously mounted? */ + if (nr >= 0) { + if (!filesys_isvolume (u)) /* not going to mount twice */ + return filesys_insert (nr, volptr, rootdir, -1, -1); + return 0; + } + if (inserted < 0) /* -1 = only mount if already exists */ + return 0; + /* new volume inserted and it was not previously mounted? + * perhaps we have some empty device slots? */ + nr = filesys_insert (-1, volptr, rootdir, 0, 0); + if (nr >= 100) { + if (uci) + uci->configoffset = nr - 100; + return nr; + } + /* nope, uh, need black magic now.. */ + if (uci) + _tcscpy (devname, uci->devname); + else + _stprintf (devname, L"RDH%d", nr_units()); + nr = add_filesys_unit (devname, volptr, rootdir, 0, 0, 0, 0, 0, 0, 0, 1, NULL, 0, MYVOLUMEINFO_REUSABLE); + if (nr < 0) + return 0; + if (inserted > 1) + mountinfo.ui[nr].canremove = 1; + automountunit = nr; + uae_Signal (mountertask, 1 << 13); + /* poof */ + if (uci) + uci->configoffset = nr; + return 100 + nr; + } return 0; - /* already mounted volume was ejected? */ - if (nr >= 0 && !inserted) - return filesys_eject (nr); - if (inserted) { - if (uci) { - volptr = my_strdup (uci->volname); - } else { - volname[0] = 0; - target_get_volume_name (&mountinfo, rootdir, volname, MAX_DPATH, 1, 0); - volptr = volname; - if (!volname[0]) - volptr = NULL; - if (ui && ui->configureddrive && ui->volname) { - volptr = volname; - _tcscpy (volptr, ui->volname); - } - } - if (!volptr) { - volptr = filesys_createvolname (NULL, rootdir, L"removable"); - _tcscpy (volname, volptr); - xfree (volptr); - volptr = volname; - } - - /* new volume inserted and it was previously mounted? */ - if (nr >= 0) { - if (!filesys_isvolume (u)) /* not going to mount twice */ - return filesys_insert (nr, volptr, rootdir, -1, -1); - return 0; - } - if (inserted < 0) /* -1 = only mount if already exists */ - return 0; - /* new volume inserted and it was not previously mounted? - * perhaps we have some empty device slots? */ - nr = filesys_insert (-1, volptr, rootdir, 0, 0); - if (nr >= 100) { - if (uci) - uci->configoffset = nr - 100; - return nr; - } - /* nope, uh, need black magic now.. */ - if (uci) - _tcscpy (devname, uci->devname); - else - _stprintf (devname, L"RDH%d", nr_units()); - nr = add_filesys_unit (devname, volptr, rootdir, 0, 0, 0, 0, 0, 0, 0, 1, NULL, 0, MYVOLUMEINFO_REUSABLE); - if (nr < 0) - return 0; - if (inserted > 1) - mountinfo.ui[nr].canremove = 1; - automountunit = nr; - uae_Signal (mountertask, 1 << 13); - /* poof */ - if (uci) - uci->configoffset = nr; - return 100 + nr; - } - return 0; } int hardfile_remount (int nr) { - /* this does work but every media reinsert duplicates the device.. */ + /* this does work but every media reinsert duplicates the device.. */ #if 0 - if (!mountertask) - return 0; - automountunit = nr; - uae_Signal (mountertask, 1 << 13); + if (!mountertask) + return 0; + automountunit = nr; + uae_Signal (mountertask, 1 << 13); #endif - return 1; + return 1; } int filesys_insert (int nr, TCHAR *volume, const TCHAR *rootdir, int readonly, int flags) { - struct uaedev_config_info *uci; - int emptydrive = 0; - UnitInfo *ui; - Unit *u; + struct uaedev_config_info *uci; + int emptydrive = 0; + UnitInfo *ui; + Unit *u; - if (!mountertask) - return 0; - if (nr < 0) { - for (u = units; u; u = u->next) { - if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { - if (!filesys_isvolume (u) && mountinfo.ui[u->unit].canremove) - break; - } - } - if (!u) { - for (u = units; u; u = u->next) { - if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { - if (mountinfo.ui[u->unit].canremove) - break; + if (!mountertask) + return 0; + if (nr < 0) { + for (u = units; u; u = u->next) { + if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { + if (!filesys_isvolume (u) && mountinfo.ui[u->unit].canremove) + break; + } } - } + if (!u) { + for (u = units; u; u = u->next) { + if (is_hardfile (u->unit) == FILESYS_VIRTUAL) { + if (mountinfo.ui[u->unit].canremove) + break; + } + } + } + if (!u) + return 0; + nr = u->unit; + ui = &mountinfo.ui[nr]; + } else { + ui = &mountinfo.ui[nr]; + u = ui->self; } - if (!u) - return 0; - nr = u->unit; - ui = &mountinfo.ui[nr]; - } else { - ui = &mountinfo.ui[nr]; - u = ui->self; - } - uci = &currprefs.mountconfig[nr]; + uci = &currprefs.mountconfig[nr]; - if (!ui->open || u == NULL) - return 0; - if (u->reinsertdelay) - return -1; - if (is_hardfile (nr) != FILESYS_VIRTUAL) - return 0; - if (filesys_isvolume (u)) { - filesys_delayed_change (u, 50, rootdir, volume, readonly, flags); - return -1; - } - u->mountcount++; - clear_exkeys (u); - xfree (u->ui.rootdir); - ui->rootdir = u->ui.rootdir = my_strdup (rootdir); - flush_cache (u, -1); - if (set_filesys_volume (rootdir, &flags, &readonly, &emptydrive, &u->zarchive) < 0) - return 0; - if (emptydrive) - return 0; - xfree (u->ui.volname); - ui->volname = u->ui.volname = filesys_createvolname (volume, rootdir, L"removable"); - set_volume_name (u); - write_log (L"FILESYS: inserted volume NR=%d RO=%d '%s' ('%s')\n", nr, readonly, ui->volname, rootdir); - if (flags >= 0) - ui->volflags = u->volflags = u->ui.volflags = flags; - _tcscpy (uci->volname, ui->volname); - _tcscpy (uci->rootdir, rootdir); - if (readonly >= 0) - uci->readonly = ui->readonly = u->ui.readonly = readonly; - put_byte (u->volume + 44, 0); - put_byte (u->volume + 172 - 32, 1); - uae_Signal (get_long (u->volume + 176 - 32), 1 << 13); - return 100 + nr; + if (!ui->open || u == NULL) + return 0; + if (u->reinsertdelay) + return -1; + if (is_hardfile (nr) != FILESYS_VIRTUAL) + return 0; + if (filesys_isvolume (u)) { + filesys_delayed_change (u, 50, rootdir, volume, readonly, flags); + return -1; + } + u->mountcount++; + clear_exkeys (u); + xfree (u->ui.rootdir); + ui->rootdir = u->ui.rootdir = my_strdup (rootdir); + flush_cache (u, -1); + if (set_filesys_volume (rootdir, &flags, &readonly, &emptydrive, &u->zarchive) < 0) + return 0; + if (emptydrive) + return 0; + xfree (u->ui.volname); + ui->volname = u->ui.volname = filesys_createvolname (volume, rootdir, L"removable"); + set_volume_name (u); + write_log (L"FILESYS: inserted volume NR=%d RO=%d '%s' ('%s')\n", nr, readonly, ui->volname, rootdir); + if (flags >= 0) + ui->volflags = u->volflags = u->ui.volflags = flags; + _tcscpy (uci->volname, ui->volname); + _tcscpy (uci->rootdir, rootdir); + if (readonly >= 0) + uci->readonly = ui->readonly = u->ui.readonly = readonly; + put_byte (u->volume + 44, 0); + put_byte (u->volume + 172 - 32, 1); + uae_Signal (get_long (u->volume + 176 - 32), 1 << 13); + return 100 + nr; } /* flags and comments supported? */ static int fsdb_cando (Unit *unit) { - if (unit->volflags & MYVOLUMEINFO_ARCHIVE) - return 1; - if (currprefs.filesys_custom_uaefsdb && (unit->volflags & MYVOLUMEINFO_STREAMS)) - return 1; - if (!currprefs.filesys_no_uaefsdb) - return 1; - return 0; + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) + return 1; + if (currprefs.filesys_custom_uaefsdb && (unit->volflags & MYVOLUMEINFO_STREAMS)) + return 1; + if (!currprefs.filesys_no_uaefsdb) + return 1; + return 0; } static void prepare_for_open (TCHAR *name) { #if 0 - struct _stat64 statbuf; - int mode; + struct _stat64 statbuf; + int mode; - if (-1 == stat (name, &statbuf)) - return; + if (-1 == stat (name, &statbuf)) + return; - mode = statbuf.st_mode; - mode |= S_IRUSR; - mode |= S_IWUSR; - mode |= S_IXUSR; - chmod (name, mode); + mode = statbuf.st_mode; + mode |= S_IRUSR; + mode |= S_IWUSR; + mode |= S_IXUSR; + chmod (name, mode); #endif } static void de_recycle_aino (Unit *unit, a_inode *aino) { - aino_test (aino); - if (aino->next == 0 || aino == &unit->rootnode) - return; - aino->next->prev = aino->prev; - aino->prev->next = aino->next; - aino->next = aino->prev = 0; - unit->aino_cache_size--; + aino_test (aino); + if (aino->next == 0 || aino == &unit->rootnode) + return; + aino->next->prev = aino->prev; + aino->prev->next = aino->next; + aino->next = aino->prev = 0; + unit->aino_cache_size--; } static void dispose_aino (Unit *unit, a_inode **aip, a_inode *aino) { - int hash = aino->uniq % MAX_AINO_HASH; - if (unit->aino_hash[hash] == aino) - unit->aino_hash[hash] = 0; + int hash = aino->uniq % MAX_AINO_HASH; + if (unit->aino_hash[hash] == aino) + unit->aino_hash[hash] = 0; - if (aino->dirty && aino->parent) - fsdb_dir_writeback (aino->parent); + if (aino->dirty && aino->parent) + fsdb_dir_writeback (aino->parent); - *aip = aino->sibling; - xfree (aino->aname); - xfree (aino->comment); - xfree (aino->nname); - xfree (aino); + *aip = aino->sibling; + xfree (aino->aname); + xfree (aino->comment); + xfree (aino->nname); + xfree (aino); } static void free_all_ainos (Unit *u, a_inode *parent) { - a_inode *a; - while (a = parent->child) { - free_all_ainos (u, a); - dispose_aino (u, &parent->child, a); - } + a_inode *a; + while (a = parent->child) { + free_all_ainos (u, a); + dispose_aino (u, &parent->child, a); + } } static int flush_cache (Unit *unit, int num) { - int i = 0; - int cnt = 100; - - write_log (L"FILESYS: flushing cache unit %d (max %d items)\n", unit->unit, num); - if (num == 0) - num = -1; - while (i < num || num < 0) { - int ii = i; - a_inode *parent = unit->rootnode.prev->parent; - a_inode **aip; - - aip = &parent->child; - aino_test (parent); - if (parent && !parent->locked_children) { - for (;;) { - a_inode *aino = *aip; - aino_test (aino); - if (aino == 0) - break; - /* Not recyclable if next == 0 (i.e., not chained into - recyclable list), or if parent directory is being - ExNext()ed. */ - if (aino->next == 0) { - aip = &aino->sibling; - } else { - if (aino->shlock > 0 || aino->elock) - write_log (L"panic: freeing locked a_inode!\n"); - de_recycle_aino (unit, aino); - dispose_aino (unit, aip, aino); - i++; + int i = 0; + int cnt = 100; + + write_log (L"FILESYS: flushing cache unit %d (max %d items)\n", unit->unit, num); + if (num == 0) + num = -1; + while (i < num || num < 0) { + int ii = i; + a_inode *parent = unit->rootnode.prev->parent; + a_inode **aip; + + aip = &parent->child; + aino_test (parent); + if (parent && !parent->locked_children) { + for (;;) { + a_inode *aino = *aip; + aino_test (aino); + if (aino == 0) + break; + /* Not recyclable if next == 0 (i.e., not chained into + recyclable list), or if parent directory is being + ExNext()ed. */ + if (aino->next == 0) { + aip = &aino->sibling; + } else { + if (aino->shlock > 0 || aino->elock) + write_log (L"panic: freeing locked a_inode!\n"); + de_recycle_aino (unit, aino); + dispose_aino (unit, aip, aino); + i++; + } + } + } + { //if (unit->rootnode.next != unit->rootnode.prev) { + /* In the previous loop, we went through all children of one + parent. Re-arrange the recycled list so that we'll find a + different parent the next time around. + (infinite loop if there is only one parent?) + */ + int maxloop = 10000; + do { + unit->rootnode.next->prev = unit->rootnode.prev; + unit->rootnode.prev->next = unit->rootnode.next; + unit->rootnode.next = unit->rootnode.prev; + unit->rootnode.prev = unit->rootnode.prev->prev; + unit->rootnode.prev->next = unit->rootnode.next->prev = &unit->rootnode; + } while (unit->rootnode.prev->parent == parent && maxloop-- > 0); } - } - } - { //if (unit->rootnode.next != unit->rootnode.prev) { - /* In the previous loop, we went through all children of one - parent. Re-arrange the recycled list so that we'll find a - different parent the next time around. - (infinite loop if there is only one parent?) - */ - int maxloop = 10000; - do { - unit->rootnode.next->prev = unit->rootnode.prev; - unit->rootnode.prev->next = unit->rootnode.next; - unit->rootnode.next = unit->rootnode.prev; - unit->rootnode.prev = unit->rootnode.prev->prev; - unit->rootnode.prev->next = unit->rootnode.next->prev = &unit->rootnode; - } while (unit->rootnode.prev->parent == parent && maxloop-- > 0); - } - if (i == ii) - cnt--; - if (cnt <= 0) - break; - } - return unit->aino_cache_size > 0 ? 0 : 1; + if (i == ii) + cnt--; + if (cnt <= 0) + break; + } + return unit->aino_cache_size > 0 ? 0 : 1; } static void recycle_aino (Unit *unit, a_inode *new_aino) { - aino_test (new_aino); - if (new_aino->dir || new_aino->shlock > 0 - || new_aino->elock || new_aino == &unit->rootnode) - /* Still in use */ - return; + aino_test (new_aino); + if (new_aino->dir || new_aino->shlock > 0 + || new_aino->elock || new_aino == &unit->rootnode) + /* Still in use */ + return; - TRACE ((L"Recycling; cache size %d, total_locked %d\n", - unit->aino_cache_size, unit->total_locked_ainos)); - if (unit->aino_cache_size > 5000 + unit->total_locked_ainos) { - /* Reap a few. */ - flush_cache (unit, 50); + TRACE ((L"Recycling; cache size %d, total_locked %d\n", + unit->aino_cache_size, unit->total_locked_ainos)); + if (unit->aino_cache_size > 5000 + unit->total_locked_ainos) { + /* Reap a few. */ + flush_cache (unit, 50); #if 0 - { - TCHAR buffer[40]; - _stprintf (buffer, "%d ainos reaped.\n", i); - TRACE ((buffer)); - } + { + TCHAR buffer[40]; + _stprintf (buffer, "%d ainos reaped.\n", i); + TRACE ((buffer)); + } #endif - } + } - aino_test (new_aino); - /* Chain it into circular list. */ - new_aino->next = unit->rootnode.next; - new_aino->prev = &unit->rootnode; - new_aino->prev->next = new_aino; - new_aino->next->prev = new_aino; - aino_test (new_aino->next); - aino_test (new_aino->prev); + aino_test (new_aino); + /* Chain it into circular list. */ + new_aino->next = unit->rootnode.next; + new_aino->prev = &unit->rootnode; + new_aino->prev->next = new_aino; + new_aino->next->prev = new_aino; + aino_test (new_aino->next); + aino_test (new_aino->prev); - unit->aino_cache_size++; + unit->aino_cache_size++; } void filesys_flush_cache (void) @@ -1437,613 +1437,613 @@ void filesys_flush_cache (void) static void update_child_names (Unit *unit, a_inode *a, a_inode *parent) { - int l0 = _tcslen (parent->nname) + 2; + int l0 = _tcslen (parent->nname) + 2; - while (a != 0) { - TCHAR *name_start; - TCHAR *new_name; - TCHAR dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' }; + while (a != 0) { + TCHAR *name_start; + TCHAR *new_name; + TCHAR dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' }; - a->parent = parent; - name_start = _tcsrchr (a->nname, FSDB_DIR_SEPARATOR); - if (name_start == 0) { - write_log (L"malformed file name"); + a->parent = parent; + name_start = _tcsrchr (a->nname, FSDB_DIR_SEPARATOR); + if (name_start == 0) { + write_log (L"malformed file name"); + } + name_start++; + new_name = xmalloc ((_tcslen (name_start) + l0) * sizeof (TCHAR)); + _tcscpy (new_name, parent->nname); + _tcscat (new_name, dirsep); + _tcscat (new_name, name_start); + xfree (a->nname); + a->nname = new_name; + if (a->child) + update_child_names (unit, a->child, a); + a = a->sibling; } - name_start++; - new_name = xmalloc ((_tcslen (name_start) + l0) * sizeof (TCHAR)); - _tcscpy (new_name, parent->nname); - _tcscat (new_name, dirsep); - _tcscat (new_name, name_start); - xfree (a->nname); - a->nname = new_name; - if (a->child) - update_child_names (unit, a->child, a); - a = a->sibling; - } } static void move_aino_children (Unit *unit, a_inode *from, a_inode *to) { - aino_test (from); - aino_test (to); - to->child = from->child; - from->child = 0; - update_child_names (unit, to->child, to); + aino_test (from); + aino_test (to); + to->child = from->child; + from->child = 0; + update_child_names (unit, to->child, to); } static void delete_aino (Unit *unit, a_inode *aino) { - a_inode **aip; - - TRACE((L"deleting aino %x\n", aino->uniq)); - - aino_test (aino); - aino->dirty = 1; - aino->deleted = 1; - de_recycle_aino (unit, aino); + a_inode **aip; - /* If any ExKeys are currently pointing at us, advance them. */ - if (aino->parent->exnext_count > 0) { - int i; - TRACE((L"entering exkey validation\n")); - for (i = 0; i < EXKEYS; i++) { - ExamineKey *k = unit->examine_keys + i; - if (k->uniq == 0) - continue; - if (k->aino == aino->parent) { - TRACE((L"Same parent found for %d\n", i)); - if (k->curr_file == aino) { - k->curr_file = aino->sibling; - TRACE((L"Advancing curr_file\n")); + TRACE((L"deleting aino %x\n", aino->uniq)); + + aino_test (aino); + aino->dirty = 1; + aino->deleted = 1; + de_recycle_aino (unit, aino); + + /* If any ExKeys are currently pointing at us, advance them. */ + if (aino->parent->exnext_count > 0) { + int i; + TRACE((L"entering exkey validation\n")); + for (i = 0; i < EXKEYS; i++) { + ExamineKey *k = unit->examine_keys + i; + if (k->uniq == 0) + continue; + if (k->aino == aino->parent) { + TRACE((L"Same parent found for %d\n", i)); + if (k->curr_file == aino) { + k->curr_file = aino->sibling; + TRACE((L"Advancing curr_file\n")); + } + } } - } } - } - aip = &aino->parent->child; - while (*aip != aino && *aip != 0) - aip = &(*aip)->sibling; - if (*aip != aino) { - write_log (L"Couldn't delete aino.\n"); - return; - } - dispose_aino (unit, aip, aino); + aip = &aino->parent->child; + while (*aip != aino && *aip != 0) + aip = &(*aip)->sibling; + if (*aip != aino) { + write_log (L"Couldn't delete aino.\n"); + return; + } + dispose_aino (unit, aip, aino); } static a_inode *lookup_sub (a_inode *dir, uae_u32 uniq) { - a_inode **cp = &dir->child; - a_inode *c, *retval; + a_inode **cp = &dir->child; + a_inode *c, *retval; - for (;;) { - c = *cp; - if (c == 0) - return 0; + for (;;) { + c = *cp; + if (c == 0) + return 0; - if (c->uniq == uniq) { - retval = c; - break; + if (c->uniq == uniq) { + retval = c; + break; + } + if (c->dir) { + a_inode *a = lookup_sub (c, uniq); + if (a != 0) { + retval = a; + break; + } + } + cp = &c->sibling; } - if (c->dir) { - a_inode *a = lookup_sub (c, uniq); - if (a != 0) { - retval = a; - break; - } + if (! dir->locked_children) { + /* Move to the front to speed up repeated lookups. Don't do this if + an ExNext is going on in this directory, or we'll terminally + confuse it. */ + *cp = c->sibling; + c->sibling = dir->child; + dir->child = c; } - cp = &c->sibling; - } - if (! dir->locked_children) { - /* Move to the front to speed up repeated lookups. Don't do this if - an ExNext is going on in this directory, or we'll terminally - confuse it. */ - *cp = c->sibling; - c->sibling = dir->child; - dir->child = c; - } - return retval; + return retval; } static a_inode *lookup_aino (Unit *unit, uae_u32 uniq) { - a_inode *a; - int hash = uniq % MAX_AINO_HASH; + a_inode *a; + int hash = uniq % MAX_AINO_HASH; - if (uniq == 0) - return &unit->rootnode; - a = unit->aino_hash[hash]; - if (a == 0 || a->uniq != uniq) - a = lookup_sub (&unit->rootnode, uniq); - else - unit->nr_cache_hits++; - unit->nr_cache_lookups++; - unit->aino_hash[hash] = a; - aino_test (a); - return a; + if (uniq == 0) + return &unit->rootnode; + a = unit->aino_hash[hash]; + if (a == 0 || a->uniq != uniq) + a = lookup_sub (&unit->rootnode, uniq); + else + unit->nr_cache_hits++; + unit->nr_cache_lookups++; + unit->aino_hash[hash] = a; + aino_test (a); + return a; } TCHAR *build_nname (const TCHAR *d, const TCHAR *n) { - TCHAR dsep[2] = { FSDB_DIR_SEPARATOR, 0 }; - TCHAR *p = xmalloc ((_tcslen (d) + 1 + _tcslen (n) + 1) * sizeof (TCHAR)); - _tcscpy (p, d); - _tcscat (p, dsep); - _tcscat (p, n); - return p; + TCHAR dsep[2] = { FSDB_DIR_SEPARATOR, 0 }; + TCHAR *p = xmalloc ((_tcslen (d) + 1 + _tcslen (n) + 1) * sizeof (TCHAR)); + _tcscpy (p, d); + _tcscat (p, dsep); + _tcscat (p, n); + return p; } TCHAR *build_aname (const TCHAR *d, const TCHAR *n) { - TCHAR *p = xmalloc ((_tcslen (d) + 1 + _tcslen (n) + 1) * sizeof (TCHAR)); - _tcscpy (p, d); - _tcscat (p, L"/"); - _tcscat (p, n); - return p; + TCHAR *p = xmalloc ((_tcslen (d) + 1 + _tcslen (n) + 1) * sizeof (TCHAR)); + _tcscpy (p, d); + _tcscat (p, L"/"); + _tcscat (p, n); + return p; } /* This gets called to translate an Amiga name that some program used to - * a name that we can use on the native filesystem. */ +* a name that we can use on the native filesystem. */ static TCHAR *get_nname (Unit *unit, a_inode *base, TCHAR *rel, - TCHAR **modified_rel) + TCHAR **modified_rel) { - TCHAR *found; - TCHAR *p = 0; + TCHAR *found; + TCHAR *p = 0; - *modified_rel = 0; + *modified_rel = 0; - if (unit->volflags & MYVOLUMEINFO_ARCHIVE) { - if (zfile_exists_archive(base->nname, rel)) - return build_nname(base->nname, rel); - return 0; - } - - aino_test (base); - - /* If we have a mapping of some other aname to "rel", we must pretend - * it does not exist. - * This can happen for example if an Amiga program creates a - * file called ".". We can't represent this in our filesystem, - * so we create a special file "uae_xxx" and record the mapping - * aname "." -> nname "uae_xxx" in the database. Then, the Amiga - * program looks up "uae_xxx" (yes, it's contrived). The filesystem - * should not make the uae_xxx file visible to the Amiga side. */ - if (fsdb_used_as_nname (base, rel)) - return 0; - /* A file called "." (or whatever else is invalid on this filesystem) + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) { + if (zfile_exists_archive(base->nname, rel)) + return build_nname(base->nname, rel); + return 0; + } + + aino_test (base); + + /* If we have a mapping of some other aname to "rel", we must pretend + * it does not exist. + * This can happen for example if an Amiga program creates a + * file called ".". We can't represent this in our filesystem, + * so we create a special file "uae_xxx" and record the mapping + * aname "." -> nname "uae_xxx" in the database. Then, the Amiga + * program looks up "uae_xxx" (yes, it's contrived). The filesystem + * should not make the uae_xxx file visible to the Amiga side. */ + if (fsdb_used_as_nname (base, rel)) + return 0; + /* A file called "." (or whatever else is invalid on this filesystem) * does not exist, as far as the Amiga side is concerned. */ - if (fsdb_name_invalid (rel)) - return 0; + if (fsdb_name_invalid (rel)) + return 0; - /* See if we have a file that has the same name as the aname we are - * looking for. */ - found = fsdb_search_dir (base->nname, rel); - if (found == 0) - return found; - if (found == rel) - return build_nname (base->nname, rel); + /* See if we have a file that has the same name as the aname we are + * looking for. */ + found = fsdb_search_dir (base->nname, rel); + if (found == 0) + return found; + if (found == rel) + return build_nname (base->nname, rel); - *modified_rel = found; - return build_nname (base->nname, found); + *modified_rel = found; + return build_nname (base->nname, found); } static TCHAR *create_nname (Unit *unit, a_inode *base, TCHAR *rel) { - TCHAR *p; + TCHAR *p; - aino_test (base); - /* We are trying to create a file called REL. */ + aino_test (base); + /* We are trying to create a file called REL. */ - /* If the name is used otherwise in the directory (or globally), we - * need a new unique nname. */ - if (fsdb_name_invalid (rel) || fsdb_used_as_nname (base, rel)) { + /* If the name is used otherwise in the directory (or globally), we + * need a new unique nname. */ + if (fsdb_name_invalid (rel) || fsdb_used_as_nname (base, rel)) { #if 0 - oh_dear: +oh_dear: #endif - if (currprefs.filesys_no_uaefsdb && !(base->volflags & MYVOLUMEINFO_STREAMS)) { - write_log (L"illegal filename '%s', no stream supporting filesystem and uaefsdb disabled\n", rel); - return 0; + if (currprefs.filesys_no_uaefsdb && !(base->volflags & MYVOLUMEINFO_STREAMS)) { + write_log (L"illegal filename '%s', no stream supporting filesystem and uaefsdb disabled\n", rel); + return 0; + } + p = fsdb_create_unique_nname (base, rel); + return p; } - p = fsdb_create_unique_nname (base, rel); - return p; - } - p = build_nname (base->nname, rel); + p = build_nname (base->nname, rel); #if 0 - /* Delete this code once we know everything works. */ - if (access (p, R_OK) >= 0 || errno != ENOENT) { - write_log (L"Filesystem in trouble... please report.\n"); - xfree (p); - goto oh_dear; - } + /* Delete this code once we know everything works. */ + if (access (p, R_OK) >= 0 || errno != ENOENT) { + write_log (L"Filesystem in trouble... please report.\n"); + xfree (p); + goto oh_dear; + } #endif - return p; + return p; } static int fill_file_attrs (Unit *u, a_inode *base, a_inode *c) { - if (u->volflags & MYVOLUMEINFO_ARCHIVE) { - int isdir, flags; - TCHAR *comment; - zfile_fill_file_attrs_archive (c->nname, &isdir, &flags, &comment); - c->dir = isdir; - c->amigaos_mode = 0; - if (flags >= 0) - c->amigaos_mode = flags; - c->comment = comment; - return 1; - } else { - return fsdb_fill_file_attrs (base, c); - } - return 0; + if (u->volflags & MYVOLUMEINFO_ARCHIVE) { + int isdir, flags; + TCHAR *comment; + zfile_fill_file_attrs_archive (c->nname, &isdir, &flags, &comment); + c->dir = isdir; + c->amigaos_mode = 0; + if (flags >= 0) + c->amigaos_mode = flags; + c->comment = comment; + return 1; + } else { + return fsdb_fill_file_attrs (base, c); + } + return 0; } /* - * This gets called if an ACTION_EXAMINE_NEXT happens and we hit an object - * for which we know the name on the native filesystem, but no corresponding - * Amiga filesystem name. - * @@@ For DOS filesystems, it might make sense to declare the new name - * "weak", so that it can get overriden by a subsequent call to get_nname(). - * That way, if someone does "dir :" and there is a file "foobar.inf", and - * someone else tries to open "foobar.info", get_nname() could maybe made to - * figure out that this is supposed to be the file "foobar.inf". - * DOS sucks... - */ +* This gets called if an ACTION_EXAMINE_NEXT happens and we hit an object +* for which we know the name on the native filesystem, but no corresponding +* Amiga filesystem name. +* @@@ For DOS filesystems, it might make sense to declare the new name +* "weak", so that it can get overriden by a subsequent call to get_nname(). +* That way, if someone does "dir :" and there is a file "foobar.inf", and +* someone else tries to open "foobar.info", get_nname() could maybe made to +* figure out that this is supposed to be the file "foobar.inf". +* DOS sucks... +*/ static TCHAR *get_aname (Unit *unit, a_inode *base, TCHAR *rel) { - return my_strdup (rel); + return my_strdup (rel); } static void init_child_aino_tree(Unit *unit, a_inode *base, a_inode *aino) { - /* Update tree structure */ - aino->parent = base; - aino->child = 0; - aino->sibling = base->child; - base->child = aino; - aino->next = aino->prev = 0; - aino->volflags = unit->volflags; + /* Update tree structure */ + aino->parent = base; + aino->child = 0; + aino->sibling = base->child; + base->child = aino; + aino->next = aino->prev = 0; + aino->volflags = unit->volflags; } static void init_child_aino (Unit *unit, a_inode *base, a_inode *aino) { - aino->uniq = ++a_uniq; - if (a_uniq == 0xFFFFFFFF) { - write_log (L"Running out of a_inodes (prepare for big trouble)!\n"); - } - aino->shlock = 0; - aino->elock = 0; - - aino->dirty = 0; - aino->deleted = 0; - aino->mountcount = unit->mountcount; - - /* For directories - this one isn't being ExNext()ed yet. */ - aino->locked_children = 0; - aino->exnext_count = 0; - /* But the parent might be. */ - if (base->exnext_count) { - unit->total_locked_ainos++; - base->locked_children++; - } - init_child_aino_tree (unit, base, aino); + aino->uniq = ++a_uniq; + if (a_uniq == 0xFFFFFFFF) { + write_log (L"Running out of a_inodes (prepare for big trouble)!\n"); + } + aino->shlock = 0; + aino->elock = 0; + + aino->dirty = 0; + aino->deleted = 0; + aino->mountcount = unit->mountcount; + + /* For directories - this one isn't being ExNext()ed yet. */ + aino->locked_children = 0; + aino->exnext_count = 0; + /* But the parent might be. */ + if (base->exnext_count) { + unit->total_locked_ainos++; + base->locked_children++; + } + init_child_aino_tree (unit, base, aino); - aino_test_init (aino); - aino_test (aino); + aino_test_init (aino); + aino_test (aino); } static a_inode *new_child_aino (Unit *unit, a_inode *base, TCHAR *rel) { - TCHAR *modified_rel; - TCHAR *nn; - a_inode *aino = NULL; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + TCHAR *modified_rel; + TCHAR *nn; + a_inode *aino = NULL; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - TRACE((L"new_child_aino %s, %s\n", base->aname, rel)); + TRACE((L"new_child_aino %s, %s\n", base->aname, rel)); - if (!isarch) - aino = fsdb_lookup_aino_aname (base, rel); - if (aino == 0) { - nn = get_nname (unit, base, rel, &modified_rel); - if (nn == 0) - return 0; + if (!isarch) + aino = fsdb_lookup_aino_aname (base, rel); + if (aino == 0) { + nn = get_nname (unit, base, rel, &modified_rel); + if (nn == 0) + return 0; - aino = xcalloc (sizeof (a_inode), 1); - if (aino == 0) - return 0; - aino->aname = modified_rel ? modified_rel : my_strdup (rel); - aino->nname = nn; + aino = xcalloc (sizeof (a_inode), 1); + if (aino == 0) + return 0; + aino->aname = modified_rel ? modified_rel : my_strdup (rel); + aino->nname = nn; - aino->comment = 0; - aino->has_dbentry = 0; + aino->comment = 0; + aino->has_dbentry = 0; - if (!fill_file_attrs (unit, base, aino)) { - xfree (aino); - return 0; + if (!fill_file_attrs (unit, base, aino)) { + xfree (aino); + return 0; + } + if (aino->dir) + fsdb_clean_dir (aino); } - if (aino->dir) - fsdb_clean_dir (aino); - } - init_child_aino (unit, base, aino); + init_child_aino (unit, base, aino); - recycle_aino (unit, aino); - TRACE((L"created aino %x, lookup, amigaos_mode %d\n", aino->uniq, aino->amigaos_mode)); - return aino; + recycle_aino (unit, aino); + TRACE((L"created aino %x, lookup, amigaos_mode %d\n", aino->uniq, aino->amigaos_mode)); + return aino; } static a_inode *create_child_aino (Unit *unit, a_inode *base, TCHAR *rel, int isdir) { - a_inode *aino = xcalloc (sizeof (a_inode), 1); - if (aino == 0) - return 0; + a_inode *aino = xcalloc (sizeof (a_inode), 1); + if (aino == 0) + return 0; - aino->nname = create_nname (unit, base, rel); - if (!aino->nname) { - free (aino); - return 0; - } - aino->aname = my_strdup (rel); + aino->nname = create_nname (unit, base, rel); + if (!aino->nname) { + free (aino); + return 0; + } + aino->aname = my_strdup (rel); - init_child_aino (unit, base, aino); - aino->amigaos_mode = 0; - aino->dir = isdir; + init_child_aino (unit, base, aino); + aino->amigaos_mode = 0; + aino->dir = isdir; - aino->comment = 0; - aino->has_dbentry = 0; - aino->dirty = 1; + aino->comment = 0; + aino->has_dbentry = 0; + aino->dirty = 1; - recycle_aino (unit, aino); - TRACE((L"created aino %x, create\n", aino->uniq)); - return aino; + recycle_aino (unit, aino); + TRACE((L"created aino %x, create\n", aino->uniq)); + return aino; } static a_inode *lookup_child_aino (Unit *unit, a_inode *base, TCHAR *rel, uae_u32 *err) { - a_inode *c = base->child; - int l0 = _tcslen (rel); + a_inode *c = base->child; + int l0 = _tcslen (rel); - aino_test (base); - aino_test (c); + aino_test (base); + aino_test (c); - if (base->dir == 0) { - *err = ERROR_OBJECT_WRONG_TYPE; - return 0; - } - - while (c != 0) { - int l1 = _tcslen (c->aname); - if (l0 <= l1 && same_aname (rel, c->aname + l1 - l0) - && (l0 == l1 || c->aname[l1-l0-1] == '/') && c->mountcount == unit->mountcount) - break; - c = c->sibling; - } - if (c != 0) + if (base->dir == 0) { + *err = ERROR_OBJECT_WRONG_TYPE; + return 0; + } + + while (c != 0) { + int l1 = _tcslen (c->aname); + if (l0 <= l1 && same_aname (rel, c->aname + l1 - l0) + && (l0 == l1 || c->aname[l1-l0-1] == '/') && c->mountcount == unit->mountcount) + break; + c = c->sibling; + } + if (c != 0) + return c; + c = new_child_aino (unit, base, rel); + if (c == 0) + *err = ERROR_OBJECT_NOT_AROUND; return c; - c = new_child_aino (unit, base, rel); - if (c == 0) - *err = ERROR_OBJECT_NOT_AROUND; - return c; } /* Different version because for this one, REL is an nname. */ static a_inode *lookup_child_aino_for_exnext (Unit *unit, a_inode *base, TCHAR *rel, uae_u32 *err) { - a_inode *c = base->child; - int l0 = _tcslen (rel); - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - - aino_test (base); - aino_test (c); - - *err = 0; - while (c != 0) { - int l1 = _tcslen (c->nname); - /* Note: using _tcscmp here. */ - if (l0 <= l1 && _tcscmp (rel, c->nname + l1 - l0) == 0 - && (l0 == l1 || c->nname[l1-l0-1] == FSDB_DIR_SEPARATOR) && c->mountcount == unit->mountcount) - break; - c = c->sibling; - } - if (c != 0) - return c; - if (!isarch) - c = fsdb_lookup_aino_nname (base, rel); - if (c == 0) { - c = xcalloc (sizeof (a_inode), 1); - if (c == 0) { - *err = ERROR_NO_FREE_STORE; - return 0; + a_inode *c = base->child; + int l0 = _tcslen (rel); + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + + aino_test (base); + aino_test (c); + + *err = 0; + while (c != 0) { + int l1 = _tcslen (c->nname); + /* Note: using _tcscmp here. */ + if (l0 <= l1 && _tcscmp (rel, c->nname + l1 - l0) == 0 + && (l0 == l1 || c->nname[l1-l0-1] == FSDB_DIR_SEPARATOR) && c->mountcount == unit->mountcount) + break; + c = c->sibling; } + if (c != 0) + return c; + if (!isarch) + c = fsdb_lookup_aino_nname (base, rel); + if (c == 0) { + c = xcalloc (sizeof (a_inode), 1); + if (c == 0) { + *err = ERROR_NO_FREE_STORE; + return 0; + } - c->nname = build_nname (base->nname, rel); - c->aname = get_aname (unit, base, rel); - c->comment = 0; - c->has_dbentry = 0; - if (!fill_file_attrs (unit, base, c)) { - xfree (c); - *err = ERROR_NO_FREE_STORE; - return 0; + c->nname = build_nname (base->nname, rel); + c->aname = get_aname (unit, base, rel); + c->comment = 0; + c->has_dbentry = 0; + if (!fill_file_attrs (unit, base, c)) { + xfree (c); + *err = ERROR_NO_FREE_STORE; + return 0; + } + if (c->dir && !isarch) + fsdb_clean_dir (c); } - if (c->dir && !isarch) - fsdb_clean_dir (c); - } - init_child_aino (unit, base, c); + init_child_aino (unit, base, c); - recycle_aino (unit, c); - TRACE((L"created aino %x, exnext\n", c->uniq)); + recycle_aino (unit, c); + TRACE((L"created aino %x, exnext\n", c->uniq)); - return c; + return c; } static a_inode *get_aino (Unit *unit, a_inode *base, const TCHAR *rel, uae_u32 *err) { - TCHAR *tmp; - TCHAR *p; - a_inode *curr; - int i; + TCHAR *tmp; + TCHAR *p; + a_inode *curr; + int i; - aino_test (base); + aino_test (base); - *err = 0; - TRACE((L"get_path(%s,%s)\n", base->aname, rel)); + *err = 0; + TRACE((L"get_path(%s,%s)\n", base->aname, rel)); - /* root-relative path? */ - for (i = 0; rel[i] && rel[i] != '/' && rel[i] != ':'; i++) - ; - if (':' == rel[i]) - rel += i+1; + /* root-relative path? */ + for (i = 0; rel[i] && rel[i] != '/' && rel[i] != ':'; i++) + ; + if (':' == rel[i]) + rel += i+1; - tmp = my_strdup (rel); - p = tmp; - curr = base; + tmp = my_strdup (rel); + p = tmp; + curr = base; - while (*p) { - /* start with a slash? go up a level. */ - if (*p == '/') { - if (curr->parent != 0) - curr = curr->parent; - p++; - } else { - a_inode *next; - - TCHAR *component_end; - component_end = _tcschr (p, '/'); - if (component_end != 0) - *component_end = '\0'; - next = lookup_child_aino (unit, curr, p, err); - if (next == 0) { - /* if only last component not found, return parent dir. */ - if (*err != ERROR_OBJECT_NOT_AROUND || component_end != 0) - curr = 0; - /* ? what error is appropriate? */ - break; - } - curr = next; - if (component_end) - p = component_end+1; - else - break; + while (*p) { + /* start with a slash? go up a level. */ + if (*p == '/') { + if (curr->parent != 0) + curr = curr->parent; + p++; + } else { + a_inode *next; + + TCHAR *component_end; + component_end = _tcschr (p, '/'); + if (component_end != 0) + *component_end = '\0'; + next = lookup_child_aino (unit, curr, p, err); + if (next == 0) { + /* if only last component not found, return parent dir. */ + if (*err != ERROR_OBJECT_NOT_AROUND || component_end != 0) + curr = 0; + /* ? what error is appropriate? */ + break; + } + curr = next; + if (component_end) + p = component_end+1; + else + break; + } } - } - xfree (tmp); - return curr; + xfree (tmp); + return curr; } static uae_u32 notifyhash (TCHAR *s) { - uae_u32 hash = 0; - while (*s) - hash = (hash << 5) + *s++; - return hash % NOTIFY_HASH_SIZE; + uae_u32 hash = 0; + while (*s) + hash = (hash << 5) + *s++; + return hash % NOTIFY_HASH_SIZE; } static Notify *new_notify (Unit *unit, TCHAR *name) { - Notify *n = xmalloc (sizeof (Notify)); - uae_u32 hash = notifyhash (name); - n->next = unit->notifyhash[hash]; - unit->notifyhash[hash] = n; - n->partname = name; - return n; + Notify *n = xmalloc (sizeof (Notify)); + uae_u32 hash = notifyhash (name); + n->next = unit->notifyhash[hash]; + unit->notifyhash[hash] = n; + n->partname = name; + return n; } static void free_notify_item (Notify *n) { - xfree (n->fullname); - xfree (n->partname); - xfree (n); + xfree (n->fullname); + xfree (n->partname); + xfree (n); } static void free_notify (Unit *unit, int hash, Notify *n) { - Notify *n1, *prev = 0; - for (n1 = unit->notifyhash[hash]; n1; n1 = n1->next) { - if (n == n1) { - if (prev) - prev->next = n->next; - else - unit->notifyhash[hash] = n->next; - break; + Notify *n1, *prev = 0; + for (n1 = unit->notifyhash[hash]; n1; n1 = n1->next) { + if (n == n1) { + if (prev) + prev->next = n->next; + else + unit->notifyhash[hash] = n->next; + break; + } + prev = n1; } - prev = n1; - } } static void startup_update_unit (Unit *unit, UnitInfo *uinfo) { - if (!unit) - return; - unit->ui.devname = uinfo->devname; - xfree (unit->ui.volname); - unit->ui.volname = my_strdup (uinfo->volname); /* might free later for rename */ - unit->ui.rootdir = uinfo->rootdir; - unit->ui.readonly = uinfo->readonly; - unit->ui.unit_pipe = uinfo->unit_pipe; - unit->ui.back_pipe = uinfo->back_pipe; - unit->ui.wasisempty = uinfo->wasisempty; - unit->ui.canremove = uinfo->canremove; + if (!unit) + return; + unit->ui.devname = uinfo->devname; + xfree (unit->ui.volname); + unit->ui.volname = my_strdup (uinfo->volname); /* might free later for rename */ + unit->ui.rootdir = uinfo->rootdir; + unit->ui.readonly = uinfo->readonly; + unit->ui.unit_pipe = uinfo->unit_pipe; + unit->ui.back_pipe = uinfo->back_pipe; + unit->ui.wasisempty = uinfo->wasisempty; + unit->ui.canremove = uinfo->canremove; } static Unit *startup_create_unit (UnitInfo *uinfo, int num) { - int i; - Unit *unit, *u; - - unit = xcalloc (sizeof (Unit), 1); - /* keep list in insertion order */ - u = units; - if (u) { - while (u->next) - u = u->next; - u->next = unit; - } else { - units = unit; - } - uinfo->self = unit; - - unit->volume = 0; - unit->port = m68k_areg (regs, 5); - unit->unit = num; - - startup_update_unit (unit, uinfo); - - unit->cmds_complete = 0; - unit->cmds_sent = 0; - unit->cmds_acked = 0; - clear_exkeys (unit); - unit->total_locked_ainos = 0; - unit->keys = 0; - for (i = 0; i < NOTIFY_HASH_SIZE; i++) { - Notify *n = unit->notifyhash[i]; - while (n) { - Notify *n2 = n; - n = n->next; - xfree (n2->fullname); - xfree (n2->partname); - xfree (n2); - } - unit->notifyhash[i] = 0; - } - - unit->rootnode.aname = uinfo->volname; - unit->rootnode.nname = uinfo->rootdir; - unit->rootnode.sibling = 0; - unit->rootnode.next = unit->rootnode.prev = &unit->rootnode; - unit->rootnode.uniq = 0; - unit->rootnode.parent = 0; - unit->rootnode.child = 0; - unit->rootnode.dir = 1; - unit->rootnode.amigaos_mode = 0; - unit->rootnode.shlock = 0; - unit->rootnode.elock = 0; - unit->rootnode.comment = 0; - unit->rootnode.has_dbentry = 0; - unit->rootnode.volflags = uinfo->volflags; - aino_test_init (&unit->rootnode); - unit->aino_cache_size = 0; - for (i = 0; i < MAX_AINO_HASH; i++) - unit->aino_hash[i] = 0; - return unit; + int i; + Unit *unit, *u; + + unit = xcalloc (sizeof (Unit), 1); + /* keep list in insertion order */ + u = units; + if (u) { + while (u->next) + u = u->next; + u->next = unit; + } else { + units = unit; + } + uinfo->self = unit; + + unit->volume = 0; + unit->port = m68k_areg (regs, 5); + unit->unit = num; + + startup_update_unit (unit, uinfo); + + unit->cmds_complete = 0; + unit->cmds_sent = 0; + unit->cmds_acked = 0; + clear_exkeys (unit); + unit->total_locked_ainos = 0; + unit->keys = 0; + for (i = 0; i < NOTIFY_HASH_SIZE; i++) { + Notify *n = unit->notifyhash[i]; + while (n) { + Notify *n2 = n; + n = n->next; + xfree (n2->fullname); + xfree (n2->partname); + xfree (n2); + } + unit->notifyhash[i] = 0; + } + + unit->rootnode.aname = uinfo->volname; + unit->rootnode.nname = uinfo->rootdir; + unit->rootnode.sibling = 0; + unit->rootnode.next = unit->rootnode.prev = &unit->rootnode; + unit->rootnode.uniq = 0; + unit->rootnode.parent = 0; + unit->rootnode.child = 0; + unit->rootnode.dir = 1; + unit->rootnode.amigaos_mode = 0; + unit->rootnode.shlock = 0; + unit->rootnode.elock = 0; + unit->rootnode.comment = 0; + unit->rootnode.has_dbentry = 0; + unit->rootnode.volflags = uinfo->volflags; + aino_test_init (&unit->rootnode); + unit->aino_cache_size = 0; + for (i = 0; i < MAX_AINO_HASH; i++) + unit->aino_hash[i] = 0; + return unit; } #ifdef UAE_FILESYS_THREADS @@ -2051,279 +2051,279 @@ static void *filesys_thread (void *unit_v); #endif static void filesys_start_thread (UnitInfo *ui, int nr) { - ui->unit_pipe = 0; - ui->back_pipe = 0; - ui->reset_state = FS_STARTUP; - if (savestate_state != STATE_RESTORE) { - ui->startup = 0; - ui->self = 0; - } + ui->unit_pipe = 0; + ui->back_pipe = 0; + ui->reset_state = FS_STARTUP; + if (savestate_state != STATE_RESTORE) { + ui->startup = 0; + ui->self = 0; + } #ifdef UAE_FILESYS_THREADS - if (is_hardfile (nr) == FILESYS_VIRTUAL) { - ui->unit_pipe = xmalloc (sizeof (smp_comm_pipe)); - ui->back_pipe = xmalloc (sizeof (smp_comm_pipe)); - init_comm_pipe (ui->unit_pipe, 100, 3); - init_comm_pipe (ui->back_pipe, 100, 1); - uae_start_thread (L"filesys", filesys_thread, (void *)ui, &ui->tid); - } + if (is_hardfile (nr) == FILESYS_VIRTUAL) { + ui->unit_pipe = xmalloc (sizeof (smp_comm_pipe)); + ui->back_pipe = xmalloc (sizeof (smp_comm_pipe)); + init_comm_pipe (ui->unit_pipe, 100, 3); + init_comm_pipe (ui->back_pipe, 100, 1); + uae_start_thread (L"filesys", filesys_thread, (void *)ui, &ui->tid); + } #endif - if (savestate_state == STATE_RESTORE) - startup_update_unit (ui->self, ui); + if (savestate_state == STATE_RESTORE) + startup_update_unit (ui->self, ui); } static uae_u32 REGPARAM2 startup_handler (TrapContext *context) { - /* Just got the startup packet. It's in A4. DosBase is in A2, - * our allocated volume structure is in A3, A5 is a pointer to - * our port. */ - uaecptr rootnode = get_long (m68k_areg (regs, 2) + 34); - uaecptr dos_info = get_long (rootnode + 24) << 2; - uaecptr pkt = m68k_dreg (regs, 3); - uaecptr arg2 = get_long (pkt + dp_Arg2); - uaecptr devnode; - int i; - TCHAR *devname = bstr1 (get_long (pkt + dp_Arg1) << 2); - TCHAR *s; - Unit *unit; - UnitInfo *uinfo; - int late = 0; - - /* find UnitInfo with correct device name */ - s = _tcschr (devname, ':'); - if (s) - *s = '\0'; - - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - /* Hardfile volume name? */ - if (!mountinfo.ui[i].open) - continue; - if (is_hardfile(i) != FILESYS_VIRTUAL) - continue; - if (mountinfo.ui[i].startup == arg2) - break; - } - - if (i == MAX_FILESYSTEM_UNITS) { - write_log (L"Failed attempt to mount device '%s'\n", devname); - put_long (pkt + dp_Res1, DOS_FALSE); - put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED); - return 0; - } + /* Just got the startup packet. It's in A4. DosBase is in A2, + * our allocated volume structure is in A3, A5 is a pointer to + * our port. */ + uaecptr rootnode = get_long (m68k_areg (regs, 2) + 34); + uaecptr dos_info = get_long (rootnode + 24) << 2; + uaecptr pkt = m68k_dreg (regs, 3); + uaecptr arg2 = get_long (pkt + dp_Arg2); + uaecptr devnode; + int i; + TCHAR *devname = bstr1 (get_long (pkt + dp_Arg1) << 2); + TCHAR *s; + Unit *unit; + UnitInfo *uinfo; + int late = 0; - if (!mountinfo.ui[i].wasisempty && !my_existsdir (mountinfo.ui[i].rootdir) && !my_existsfile (mountinfo.ui[i].rootdir)) - { - write_log (L"Failed attempt to mount device '%s'\n", devname); - put_long (pkt + dp_Res1, DOS_FALSE); - put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED); - return 0; - } + /* find UnitInfo with correct device name */ + s = _tcschr (devname, ':'); + if (s) + *s = '\0'; - uinfo = mountinfo.ui + i; - if (!uinfo->unit_pipe) { - late = 1; - filesys_start_thread (uinfo, i); - } - unit = startup_create_unit (uinfo, i); - unit->volflags = uinfo->volflags; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + /* Hardfile volume name? */ + if (!mountinfo.ui[i].open) + continue; + if (is_hardfile(i) != FILESYS_VIRTUAL) + continue; + if (mountinfo.ui[i].startup == arg2) + break; + } -/* write_comm_pipe_int (unit->ui.unit_pipe, -1, 1);*/ + if (i == MAX_FILESYSTEM_UNITS) { + write_log (L"Failed attempt to mount device '%s'\n", devname); + put_long (pkt + dp_Res1, DOS_FALSE); + put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED); + return 0; + } - write_log (L"FS: %s (flags=%08X) starting..\n", unit->ui.volname, unit->volflags); + if (!mountinfo.ui[i].wasisempty && !my_existsdir (mountinfo.ui[i].rootdir) && !my_existsfile (mountinfo.ui[i].rootdir)) + { + write_log (L"Failed attempt to mount device '%s'\n", devname); + put_long (pkt + dp_Res1, DOS_FALSE); + put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED); + return 0; + } - /* fill in our process in the device node */ - devnode = get_long (pkt + dp_Arg3) << 2; - put_long (devnode + 8, unit->port); - unit->dosbase = m68k_areg (regs, 2); + uinfo = mountinfo.ui + i; + if (!uinfo->unit_pipe) { + late = 1; + filesys_start_thread (uinfo, i); + } + unit = startup_create_unit (uinfo, i); + unit->volflags = uinfo->volflags; - /* make new volume */ - unit->volume = m68k_areg (regs, 3) + 32; - put_long (unit->volume + 180 - 32, devnode); -#ifdef UAE_FILESYS_THREADS - unit->locklist = m68k_areg (regs, 3) + 8; -#else - unit->locklist = m68k_areg (regs, 3); -#endif - unit->dummy_message = m68k_areg (regs, 3) + 12; + /* write_comm_pipe_int (unit->ui.unit_pipe, -1, 1);*/ - put_long (unit->dummy_message + 10, 0); + write_log (L"FS: %s (flags=%08X) starting..\n", unit->ui.volname, unit->volflags); - put_long (unit->volume + 4, 2); /* Type = dt_volume */ - put_long (unit->volume + 12, 0); /* Lock */ - put_long (unit->volume + 16, 3800 + i); /* Creation Date */ - put_long (unit->volume + 20, 0); - put_long (unit->volume + 24, 0); - put_long (unit->volume + 28, 0); /* lock list */ - put_long (unit->volume + 40, (unit->volume + 44) >> 2); /* Name */ + /* fill in our process in the device node */ + devnode = get_long (pkt + dp_Arg3) << 2; + put_long (devnode + 8, unit->port); + unit->dosbase = m68k_areg (regs, 2); - put_byte (unit->volume + 44, 0); - if (!uinfo->wasisempty) { - set_volume_name (unit); - fsdb_clean_dir (&unit->rootnode); - } + /* make new volume */ + unit->volume = m68k_areg (regs, 3) + 32; + put_long (unit->volume + 180 - 32, devnode); +#ifdef UAE_FILESYS_THREADS + unit->locklist = m68k_areg (regs, 3) + 8; +#else + unit->locklist = m68k_areg (regs, 3); +#endif + unit->dummy_message = m68k_areg (regs, 3) + 12; + + put_long (unit->dummy_message + 10, 0); + + put_long (unit->volume + 4, 2); /* Type = dt_volume */ + put_long (unit->volume + 12, 0); /* Lock */ + put_long (unit->volume + 16, 3800 + i); /* Creation Date */ + put_long (unit->volume + 20, 0); + put_long (unit->volume + 24, 0); + put_long (unit->volume + 28, 0); /* lock list */ + put_long (unit->volume + 40, (unit->volume + 44) >> 2); /* Name */ + + put_byte (unit->volume + 44, 0); + if (!uinfo->wasisempty) { + set_volume_name (unit); + fsdb_clean_dir (&unit->rootnode); + } - put_long (unit->volume + 8, unit->port); - put_long (unit->volume + 32, DISK_TYPE); + put_long (unit->volume + 8, unit->port); + put_long (unit->volume + 32, DISK_TYPE); - put_long (pkt + dp_Res1, DOS_TRUE); + put_long (pkt + dp_Res1, DOS_TRUE); - return 1 | (late ? 2 : 0); + return 1 | (late ? 2 : 0); } static void -do_info (Unit *unit, dpacket packet, uaecptr info) + do_info (Unit *unit, dpacket packet, uaecptr info) { - struct fs_usage fsu; - int ret; + struct fs_usage fsu; + int ret; - if (unit->volflags & MYVOLUMEINFO_ARCHIVE) - ret = zfile_fs_usage_archive (unit->ui.rootdir, 0, &fsu); - else - ret = get_fs_usage (unit->ui.rootdir, 0, &fsu); - if (ret != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - put_long (info, 0); /* errors */ - put_long (info + 4, unit->unit); /* unit number */ - put_long (info + 8, unit->ui.readonly ? 80 : 82); /* state */ - put_long (info + 12, fsu.fsu_blocks ); /* numblocks */ - put_long (info + 16, fsu.fsu_blocks - fsu.fsu_bavail); /* inuse */ - put_long (info + 20, 1024); /* bytesperblock */ - put_long (info + 24, DISK_TYPE); /* disk type */ - put_long (info + 28, unit->volume >> 2); /* volume node */ - put_long (info + 32, 0); /* inuse */ - PUT_PCK_RES1 (packet, DOS_TRUE); + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) + ret = zfile_fs_usage_archive (unit->ui.rootdir, 0, &fsu); + else + ret = get_fs_usage (unit->ui.rootdir, 0, &fsu); + if (ret != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + put_long (info, 0); /* errors */ + put_long (info + 4, unit->unit); /* unit number */ + put_long (info + 8, unit->ui.readonly ? 80 : 82); /* state */ + put_long (info + 12, fsu.fsu_blocks ); /* numblocks */ + put_long (info + 16, fsu.fsu_blocks - fsu.fsu_bavail); /* inuse */ + put_long (info + 20, 1024); /* bytesperblock */ + put_long (info + 24, DISK_TYPE); /* disk type */ + put_long (info + 28, unit->volume >> 2); /* volume node */ + put_long (info + 32, 0); /* inuse */ + PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_disk_info (Unit *unit, dpacket packet) + action_disk_info (Unit *unit, dpacket packet) { - TRACE((L"ACTION_DISK_INFO\n")); - do_info (unit, packet, GET_PCK_ARG1 (packet) << 2); + TRACE((L"ACTION_DISK_INFO\n")); + do_info (unit, packet, GET_PCK_ARG1 (packet) << 2); } static void -action_info (Unit *unit, dpacket packet) + action_info (Unit *unit, dpacket packet) { - TRACE((L"ACTION_INFO\n")); - do_info (unit, packet, GET_PCK_ARG2 (packet) << 2); + TRACE((L"ACTION_INFO\n")); + do_info (unit, packet, GET_PCK_ARG2 (packet) << 2); } static void free_key (Unit *unit, Key *k) { - Key *k1; - Key *prev = 0; - for (k1 = unit->keys; k1; k1 = k1->next) { - if (k == k1) { - if (prev) - prev->next = k->next; - else - unit->keys = k->next; - break; + Key *k1; + Key *prev = 0; + for (k1 = unit->keys; k1; k1 = k1->next) { + if (k == k1) { + if (prev) + prev->next = k->next; + else + unit->keys = k->next; + break; + } + prev = k1; } - prev = k1; - } - if (k->fd != NULL) - fs_close (unit, k->fd); + if (k->fd != NULL) + fs_close (unit, k->fd); - xfree(k); + xfree(k); } static Key *lookup_key (Unit *unit, uae_u32 uniq) { - Key *k; - unsigned int total = 0; - /* It's hardly worthwhile to optimize this - most of the time there are - * only one or zero keys. */ - for (k = unit->keys; k; k = k->next) { - total++; - if (uniq == k->uniq) - return k; - } - write_log (L"Error: couldn't find key %u / %u!\n", uniq, total); - return 0; + Key *k; + unsigned int total = 0; + /* It's hardly worthwhile to optimize this - most of the time there are + * only one or zero keys. */ + for (k = unit->keys; k; k = k->next) { + total++; + if (uniq == k->uniq) + return k; + } + write_log (L"Error: couldn't find key %u / %u!\n", uniq, total); + return 0; } static Key *new_key (Unit *unit) { - Key *k = xcalloc (sizeof (Key), 1); - k->uniq = ++key_uniq; - k->fd = NULL; - k->file_pos = 0; - k->next = unit->keys; - unit->keys = k; + Key *k = xcalloc (sizeof (Key), 1); + k->uniq = ++key_uniq; + k->fd = NULL; + k->file_pos = 0; + k->next = unit->keys; + unit->keys = k; - return k; + return k; } static void -dumplock (Unit *unit, uaecptr lock) + dumplock (Unit *unit, uaecptr lock) { - a_inode *a; - TRACE((L"LOCK: 0x%lx", lock)); - if (!lock) { - TRACE((L"\n")); - return; - } - TRACE((L"{ next=0x%lx, mode=%ld, handler=0x%lx, volume=0x%lx, aino %lx ", - get_long (lock) << 2, get_long (lock+8), - get_long (lock+12), get_long (lock+16), - get_long (lock + 4))); - a = lookup_aino (unit, get_long (lock + 4)); - if (a == 0) { - TRACE((L"not found!")); - } else { - TRACE((L"%s", a->nname)); - } - TRACE((L" }\n")); + a_inode *a; + TRACE((L"LOCK: 0x%lx", lock)); + if (!lock) { + TRACE((L"\n")); + return; + } + TRACE((L"{ next=0x%lx, mode=%ld, handler=0x%lx, volume=0x%lx, aino %lx ", + get_long (lock) << 2, get_long (lock+8), + get_long (lock+12), get_long (lock+16), + get_long (lock + 4))); + a = lookup_aino (unit, get_long (lock + 4)); + if (a == 0) { + TRACE((L"not found!")); + } else { + TRACE((L"%s", a->nname)); + } + TRACE((L" }\n")); } static a_inode *find_aino (Unit *unit, uaecptr lock, const TCHAR *name, uae_u32 *err) { - a_inode *a; + a_inode *a; - if (lock) { - a_inode *olda = lookup_aino (unit, get_long (lock + 4)); - if (olda == 0) { - /* That's the best we can hope to do. */ - a = get_aino (unit, &unit->rootnode, name, err); + if (lock) { + a_inode *olda = lookup_aino (unit, get_long (lock + 4)); + if (olda == 0) { + /* That's the best we can hope to do. */ + a = get_aino (unit, &unit->rootnode, name, err); + } else { + TRACE((L"aino: 0x%08lx", (unsigned long int)olda->uniq)); + TRACE((L" \"%s\"\n", olda->nname)); + a = get_aino (unit, olda, name, err); + } } else { - TRACE((L"aino: 0x%08lx", (unsigned long int)olda->uniq)); - TRACE((L" \"%s\"\n", olda->nname)); - a = get_aino (unit, olda, name, err); + a = get_aino (unit, &unit->rootnode, name, err); + } + if (a) { + TRACE((L"aino=\"%s\"\n", a->nname)); } - } else { - a = get_aino (unit, &unit->rootnode, name, err); - } - if (a) { - TRACE((L"aino=\"%s\"\n", a->nname)); - } - aino_test (a); - return a; + aino_test (a); + return a; } static uaecptr make_lock (Unit *unit, uae_u32 uniq, long mode) { - /* allocate lock from the list kept by the assembly code */ - uaecptr lock; + /* allocate lock from the list kept by the assembly code */ + uaecptr lock; - lock = get_long (unit->locklist); - put_long (unit->locklist, get_long (lock)); - lock += 4; + lock = get_long (unit->locklist); + put_long (unit->locklist, get_long (lock)); + lock += 4; - put_long (lock + 4, uniq); - put_long (lock + 8, mode); - put_long (lock + 12, unit->port); - put_long (lock + 16, unit->volume >> 2); + put_long (lock + 4, uniq); + put_long (lock + 8, mode); + put_long (lock + 12, unit->port); + put_long (lock + 16, unit->volume >> 2); - /* prepend to lock chain */ - put_long (lock, get_long (unit->volume + 28)); - put_long (unit->volume + 28, lock >> 2); + /* prepend to lock chain */ + put_long (lock, get_long (unit->volume + 28)); + put_long (unit->volume + 28, lock >> 2); - DUMPLOCK(unit, lock); - return lock; + DUMPLOCK(unit, lock); + return lock; } #define NOTIFY_CLASS 0x40000000 @@ -2337,259 +2337,259 @@ static uaecptr make_lock (Unit *unit, uae_u32 uniq, long mode) static void notify_send (Unit *unit, Notify *n) { - uaecptr nr = n->notifyrequest; - int flags = get_long (nr + 12); + uaecptr nr = n->notifyrequest; + int flags = get_long (nr + 12); - if (flags & NRF_SEND_MESSAGE) { - if (!(flags & NRF_WAIT_REPLY) || ((flags & NRF_WAIT_REPLY) && !(flags & NRF_MAGIC))) { - uae_NotificationHack (unit->port, nr); - } else if (flags & NRF_WAIT_REPLY) { - put_long (nr + 12, get_long (nr + 12) | NRF_MAGIC); + if (flags & NRF_SEND_MESSAGE) { + if (!(flags & NRF_WAIT_REPLY) || ((flags & NRF_WAIT_REPLY) && !(flags & NRF_MAGIC))) { + uae_NotificationHack (unit->port, nr); + } else if (flags & NRF_WAIT_REPLY) { + put_long (nr + 12, get_long (nr + 12) | NRF_MAGIC); + } + } else if (flags & NRF_SEND_SIGNAL) { + uae_Signal (get_long (nr + 16), 1 << get_byte (nr + 20)); } - } else if (flags & NRF_SEND_SIGNAL) { - uae_Signal (get_long (nr + 16), 1 << get_byte (nr + 20)); - } } static void notify_check (Unit *unit, a_inode *a) { - Notify *n; - int hash = notifyhash (a->aname); - for (n = unit->notifyhash[hash]; n; n = n->next) { - uaecptr nr = n->notifyrequest; - if (same_aname(n->partname, a->aname)) { - uae_u32 err; - a_inode *a2 = find_aino (unit, 0, n->fullname, &err); - if (err == 0 && a == a2) - notify_send (unit, n); - } - } - if (a->parent) { - hash = notifyhash (a->parent->aname); + Notify *n; + int hash = notifyhash (a->aname); for (n = unit->notifyhash[hash]; n; n = n->next) { - uaecptr nr = n->notifyrequest; - if (same_aname(n->partname, a->parent->aname)) { - uae_u32 err; - a_inode *a2 = find_aino (unit, 0, n->fullname, &err); - if (err == 0 && a->parent == a2) - notify_send (unit, n); - } + uaecptr nr = n->notifyrequest; + if (same_aname(n->partname, a->aname)) { + uae_u32 err; + a_inode *a2 = find_aino (unit, 0, n->fullname, &err); + if (err == 0 && a == a2) + notify_send (unit, n); + } + } + if (a->parent) { + hash = notifyhash (a->parent->aname); + for (n = unit->notifyhash[hash]; n; n = n->next) { + uaecptr nr = n->notifyrequest; + if (same_aname(n->partname, a->parent->aname)) { + uae_u32 err; + a_inode *a2 = find_aino (unit, 0, n->fullname, &err); + if (err == 0 && a->parent == a2) + notify_send (unit, n); + } + } } - } } static void -action_add_notify (Unit *unit, dpacket packet) + action_add_notify (Unit *unit, dpacket packet) { - uaecptr nr = GET_PCK_ARG1 (packet); - int flags; - Notify *n; - TCHAR *name, *p, *partname; + uaecptr nr = GET_PCK_ARG1 (packet); + int flags; + Notify *n; + TCHAR *name, *p, *partname; - TRACE((L"ACTION_ADD_NOTIFY\n")); + TRACE((L"ACTION_ADD_NOTIFY\n")); - name = my_strdup (char1 (get_long (nr + 4))); - flags = get_long (nr + 12); + name = my_strdup (char1 (get_long (nr + 4))); + flags = get_long (nr + 12); - if (!(flags & (NRF_SEND_MESSAGE | NRF_SEND_SIGNAL))) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_BAD_NUMBER); - return; - } + if (!(flags & (NRF_SEND_MESSAGE | NRF_SEND_SIGNAL))) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_BAD_NUMBER); + return; + } #if 0 - write_log (L"Notify:\n"); - write_log (L"nr_Name '%s'\n", char1 (get_long (nr + 0))); - write_log (L"nr_FullName '%s'\n", name); - write_log (L"nr_UserData %08X\n", get_long (nr + 8)); - write_log (L"nr_Flags %08X\n", flags); - if (flags & NRF_SEND_MESSAGE) { - write_log (L"Message NotifyRequest, port = %08X\n", get_long (nr + 16)); - } else if (flags & NRF_SEND_SIGNAL) { - write_log (L"Signal NotifyRequest, Task = %08X signal = %d\n", get_long (nr + 16), get_long (nr + 20)); - } else { - write_log (L"corrupt NotifyRequest\n"); - } + write_log (L"Notify:\n"); + write_log (L"nr_Name '%s'\n", char1 (get_long (nr + 0))); + write_log (L"nr_FullName '%s'\n", name); + write_log (L"nr_UserData %08X\n", get_long (nr + 8)); + write_log (L"nr_Flags %08X\n", flags); + if (flags & NRF_SEND_MESSAGE) { + write_log (L"Message NotifyRequest, port = %08X\n", get_long (nr + 16)); + } else if (flags & NRF_SEND_SIGNAL) { + write_log (L"Signal NotifyRequest, Task = %08X signal = %d\n", get_long (nr + 16), get_long (nr + 20)); + } else { + write_log (L"corrupt NotifyRequest\n"); + } #endif - p = name + _tcslen (name) - 1; - if (p[0] == ':') - p--; - while (p > name && p[0] != ':' && p[0] != '/') - p--; - if (p[0] == ':' || p[0] == '/') - p++; - partname = my_strdup (p); - n = new_notify (unit, partname); - n->notifyrequest = nr; - n->fullname = name; - if (flags & NRF_NOTIFY_INITIAL) { - uae_u32 err; - a_inode *a = find_aino (unit, 0, n->fullname, &err); - if (err == 0) - notify_send (unit, n); - } - PUT_PCK_RES1 (packet, DOS_TRUE); + p = name + _tcslen (name) - 1; + if (p[0] == ':') + p--; + while (p > name && p[0] != ':' && p[0] != '/') + p--; + if (p[0] == ':' || p[0] == '/') + p++; + partname = my_strdup (p); + n = new_notify (unit, partname); + n->notifyrequest = nr; + n->fullname = name; + if (flags & NRF_NOTIFY_INITIAL) { + uae_u32 err; + a_inode *a = find_aino (unit, 0, n->fullname, &err); + if (err == 0) + notify_send (unit, n); + } + PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_remove_notify (Unit *unit, dpacket packet) -{ - uaecptr nr = GET_PCK_ARG1 (packet); - Notify *n; - int hash; - - TRACE((L"ACTION_REMOVE_NOTIFY\n")); - for (hash = 0; hash < NOTIFY_HASH_SIZE; hash++) { - for (n = unit->notifyhash[hash]; n; n = n->next) { - if (n->notifyrequest == nr) { - //write_log (L"NotifyRequest %08X freed\n", n->notifyrequest); - xfree (n->fullname); - xfree (n->partname); - free_notify (unit, hash, n); - PUT_PCK_RES1 (packet, DOS_TRUE); - return; - } + action_remove_notify (Unit *unit, dpacket packet) +{ + uaecptr nr = GET_PCK_ARG1 (packet); + Notify *n; + int hash; + + TRACE((L"ACTION_REMOVE_NOTIFY\n")); + for (hash = 0; hash < NOTIFY_HASH_SIZE; hash++) { + for (n = unit->notifyhash[hash]; n; n = n->next) { + if (n->notifyrequest == nr) { + //write_log (L"NotifyRequest %08X freed\n", n->notifyrequest); + xfree (n->fullname); + xfree (n->partname); + free_notify (unit, hash, n); + PUT_PCK_RES1 (packet, DOS_TRUE); + return; + } + } } - } - //write_log (L"Tried to free non-existing NotifyRequest %08X\n", nr); - PUT_PCK_RES1 (packet, DOS_TRUE); + //write_log (L"Tried to free non-existing NotifyRequest %08X\n", nr); + PUT_PCK_RES1 (packet, DOS_TRUE); } static void free_lock (Unit *unit, uaecptr lock) { - if (! lock) - return; + if (! lock) + return; - if (lock == get_long (unit->volume + 28) << 2) { - put_long (unit->volume + 28, get_long (lock)); - } else { - uaecptr current = get_long (unit->volume + 28); - uaecptr next = 0; - while (current) { - next = get_long (current << 2); - if (lock == next << 2) - break; - current = next; - } - if (!current) { - write_log (L"tried to unlock non-existing lock %x\n", lock); - return; + if (lock == get_long (unit->volume + 28) << 2) { + put_long (unit->volume + 28, get_long (lock)); + } else { + uaecptr current = get_long (unit->volume + 28); + uaecptr next = 0; + while (current) { + next = get_long (current << 2); + if (lock == next << 2) + break; + current = next; + } + if (!current) { + write_log (L"tried to unlock non-existing lock %x\n", lock); + return; + } + put_long (current << 2, get_long (lock)); } - put_long (current << 2, get_long (lock)); - } - lock -= 4; - put_long (lock, get_long (unit->locklist)); - put_long (unit->locklist, lock); + lock -= 4; + put_long (lock, get_long (unit->locklist)); + put_long (unit->locklist, lock); } static void -action_lock (Unit *unit, dpacket packet) -{ - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr name = GET_PCK_ARG2 (packet) << 2; - long mode = GET_PCK_ARG3 (packet); - a_inode *a; - uae_u32 err; - - if (mode != SHARED_LOCK && mode != EXCLUSIVE_LOCK) { - TRACE((L"Bad mode %d (should be %d or %d).\n", mode, SHARED_LOCK, EXCLUSIVE_LOCK)); - mode = SHARED_LOCK; - } - - TRACE((L"ACTION_LOCK(0x%lx, \"%s\", %d)\n", lock, bstr (unit, name), mode)); - DUMPLOCK(unit, lock); - - a = find_aino (unit, lock, bstr (unit, name), &err); - if (err == 0 && (a->elock || (mode != SHARED_LOCK && a->shlock > 0))) { - err = ERROR_OBJECT_IN_USE; - } - /* Lock() doesn't do access checks. */ - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } - if (mode == SHARED_LOCK) - a->shlock++; - else - a->elock = 1; - de_recycle_aino (unit, a); - PUT_PCK_RES1 (packet, make_lock (unit, a->uniq, mode) >> 2); + action_lock (Unit *unit, dpacket packet) +{ + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr name = GET_PCK_ARG2 (packet) << 2; + long mode = GET_PCK_ARG3 (packet); + a_inode *a; + uae_u32 err; + + if (mode != SHARED_LOCK && mode != EXCLUSIVE_LOCK) { + TRACE((L"Bad mode %d (should be %d or %d).\n", mode, SHARED_LOCK, EXCLUSIVE_LOCK)); + mode = SHARED_LOCK; + } + + TRACE((L"ACTION_LOCK(0x%lx, \"%s\", %d)\n", lock, bstr (unit, name), mode)); + DUMPLOCK(unit, lock); + + a = find_aino (unit, lock, bstr (unit, name), &err); + if (err == 0 && (a->elock || (mode != SHARED_LOCK && a->shlock > 0))) { + err = ERROR_OBJECT_IN_USE; + } + /* Lock() doesn't do access checks. */ + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + return; + } + if (mode == SHARED_LOCK) + a->shlock++; + else + a->elock = 1; + de_recycle_aino (unit, a); + PUT_PCK_RES1 (packet, make_lock (unit, a->uniq, mode) >> 2); } static void action_free_lock (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - a_inode *a; - TRACE((L"ACTION_FREE_LOCK(0x%lx)\n", lock)); - DUMPLOCK(unit, lock); + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + a_inode *a; + TRACE((L"ACTION_FREE_LOCK(0x%lx)\n", lock)); + DUMPLOCK(unit, lock); - a = lookup_aino (unit, get_long (lock + 4)); - if (a == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return; - } - if (a->elock) - a->elock = 0; - else - a->shlock--; - recycle_aino (unit, a); - free_lock(unit, lock); + a = lookup_aino (unit, get_long (lock + 4)); + if (a == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return; + } + if (a->elock) + a->elock = 0; + else + a->shlock--; + recycle_aino (unit, a); + free_lock(unit, lock); - PUT_PCK_RES1 (packet, DOS_TRUE); + PUT_PCK_RES1 (packet, DOS_TRUE); } static uaecptr -action_dup_lock_2 (Unit *unit, dpacket packet, uae_u32 uniq) + action_dup_lock_2 (Unit *unit, dpacket packet, uae_u32 uniq) { - uaecptr out; - a_inode *a; + uaecptr out; + a_inode *a; - a = lookup_aino (unit, uniq); - if (a == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return 0; - } - /* DupLock()ing exclusive locks isn't possible, says the Autodoc, but - * at least the RAM-Handler seems to allow it. Let's see what happens - * if we don't. */ - if (a->elock) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); - return 0; - } - a->shlock++; - de_recycle_aino (unit, a); - out = make_lock (unit, a->uniq, -2) >> 2; - PUT_PCK_RES1 (packet, out); - return out; + a = lookup_aino (unit, uniq); + if (a == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return 0; + } + /* DupLock()ing exclusive locks isn't possible, says the Autodoc, but + * at least the RAM-Handler seems to allow it. Let's see what happens + * if we don't. */ + if (a->elock) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); + return 0; + } + a->shlock++; + de_recycle_aino (unit, a); + out = make_lock (unit, a->uniq, -2) >> 2; + PUT_PCK_RES1 (packet, out); + return out; } static void -action_dup_lock (Unit *unit, dpacket packet) + action_dup_lock (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - TRACE((L"ACTION_DUP_LOCK(0x%lx)\n", lock)); - if (!lock) { - PUT_PCK_RES1 (packet, 0); - return; - } - action_dup_lock_2 (unit, packet, get_long (lock + 4)); + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + TRACE((L"ACTION_DUP_LOCK(0x%lx)\n", lock)); + if (!lock) { + PUT_PCK_RES1 (packet, 0); + return; + } + action_dup_lock_2 (unit, packet, get_long (lock + 4)); } static void -action_lock_from_fh (Unit *unit, dpacket packet) + action_lock_from_fh (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); - TRACE((L"ACTION_COPY_DIR_FH(0x%lx)\n", GET_PCK_ARG1 (packet))); - if (k == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - return; - } - action_dup_lock_2 (unit, packet, k->aino->uniq); + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); + TRACE((L"ACTION_COPY_DIR_FH(0x%lx)\n", GET_PCK_ARG1 (packet))); + if (k == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + return; + } + action_dup_lock_2 (unit, packet, k->aino->uniq); } /* convert time_t to/from AmigaDOS time */ @@ -2597,224 +2597,224 @@ static const int secs_per_day = 24 * 60 * 60; static const int diff = (8 * 365 + 2) * (24 * 60 * 60); static void -get_time (time_t t, long* days, long* mins, long* ticks) + get_time (time_t t, long* days, long* mins, long* ticks) { - /* time_t is secs since 1-1-1970 */ - /* days since 1-1-1978 */ - /* mins since midnight */ - /* ticks past minute @ 50Hz */ + /* time_t is secs since 1-1-1970 */ + /* days since 1-1-1978 */ + /* mins since midnight */ + /* ticks past minute @ 50Hz */ - t -= diff; - if (t < 0) - t = 0; - *days = t / secs_per_day; - t -= *days * secs_per_day; - *mins = t / 60; - t -= *mins * 60; - *ticks = t * 50; + t -= diff; + if (t < 0) + t = 0; + *days = t / secs_per_day; + t -= *days * secs_per_day; + *mins = t / 60; + t -= *mins * 60; + *ticks = t * 50; } static time_t -put_time (long days, long mins, long ticks) + put_time (long days, long mins, long ticks) { - time_t t; + time_t t; - if (days < 0) - days = 0; - if (days > 9900 * 365) - days = 9900 * 365; // in future far enough? - if (mins < 0 || mins >= 24 * 60) - mins = 0; - if (ticks < 0 || ticks >= 60 * 50) - ticks = 0; + if (days < 0) + days = 0; + if (days > 9900 * 365) + days = 9900 * 365; // in future far enough? + if (mins < 0 || mins >= 24 * 60) + mins = 0; + if (ticks < 0 || ticks >= 60 * 50) + ticks = 0; - t = ticks / 50; - t += mins * 60; - t += ((uae_u64)days) * secs_per_day; - t += diff; + t = ticks / 50; + t += mins * 60; + t += ((uae_u64)days) * secs_per_day; + t += diff; - return t; + return t; } static void free_exkey (Unit *unit, ExamineKey *ek) { - if (--ek->aino->exnext_count == 0) { - TRACE ((L"Freeing ExKey and reducing total_locked from %d by %d\n", - unit->total_locked_ainos, ek->aino->locked_children)); - unit->total_locked_ainos -= ek->aino->locked_children; - ek->aino->locked_children = 0; - } - ek->aino = 0; - ek->uniq = 0; + if (--ek->aino->exnext_count == 0) { + TRACE ((L"Freeing ExKey and reducing total_locked from %d by %d\n", + unit->total_locked_ainos, ek->aino->locked_children)); + unit->total_locked_ainos -= ek->aino->locked_children; + ek->aino->locked_children = 0; + } + ek->aino = 0; + ek->uniq = 0; } static ExamineKey *lookup_exkey (Unit *unit, uae_u32 uniq) { - ExamineKey *ek; - int i; + ExamineKey *ek; + int i; - ek = unit->examine_keys; - for (i = 0; i < EXKEYS; i++, ek++) { - /* Did we find a free one? */ - if (ek->uniq == uniq) - return ek; - } - write_log (L"Houston, we have a BIG problem.\n"); - return 0; + ek = unit->examine_keys; + for (i = 0; i < EXKEYS; i++, ek++) { + /* Did we find a free one? */ + if (ek->uniq == uniq) + return ek; + } + write_log (L"Houston, we have a BIG problem.\n"); + return 0; } /* This is so sick... who invented ACTION_EXAMINE_NEXT? What did he THINK??? */ static ExamineKey *new_exkey (Unit *unit, a_inode *aino) { - uae_u32 uniq; - uae_u32 oldest = 0xFFFFFFFE; - ExamineKey *ek, *oldest_ek = 0; - int i; - - ek = unit->examine_keys; - for (i = 0; i < EXKEYS; i++, ek++) { - /* Did we find a free one? */ - if (ek->aino == 0) - continue; - if (ek->uniq < oldest) - oldest = (oldest_ek = ek)->uniq; - } - ek = unit->examine_keys; - for (i = 0; i < EXKEYS; i++, ek++) { - /* Did we find a free one? */ - if (ek->aino == 0) - goto found; - } - /* This message should usually be harmless. */ - write_log (L"Houston, we have a problem (%s).\n", aino->nname); - free_exkey (unit, oldest_ek); - ek = oldest_ek; - found: - - uniq = unit->next_exkey; - if (uniq >= 0xFFFFFFFE) { - /* Things will probably go wrong, but most likely the Amiga will crash - * before this happens because of something else. */ - uniq = 1; - } - unit->next_exkey = uniq + 1; - ek->aino = aino; - ek->curr_file = 0; - ek->uniq = uniq; - return ek; + uae_u32 uniq; + uae_u32 oldest = 0xFFFFFFFE; + ExamineKey *ek, *oldest_ek = 0; + int i; + + ek = unit->examine_keys; + for (i = 0; i < EXKEYS; i++, ek++) { + /* Did we find a free one? */ + if (ek->aino == 0) + continue; + if (ek->uniq < oldest) + oldest = (oldest_ek = ek)->uniq; + } + ek = unit->examine_keys; + for (i = 0; i < EXKEYS; i++, ek++) { + /* Did we find a free one? */ + if (ek->aino == 0) + goto found; + } + /* This message should usually be harmless. */ + write_log (L"Houston, we have a problem (%s).\n", aino->nname); + free_exkey (unit, oldest_ek); + ek = oldest_ek; +found: + + uniq = unit->next_exkey; + if (uniq >= 0xFFFFFFFE) { + /* Things will probably go wrong, but most likely the Amiga will crash + * before this happens because of something else. */ + uniq = 1; + } + unit->next_exkey = uniq + 1; + ek->aino = aino; + ek->curr_file = 0; + ek->uniq = uniq; + return ek; } static void move_exkeys (Unit *unit, a_inode *from, a_inode *to) { - int i; - unsigned long tmp = 0; - for (i = 0; i < EXKEYS; i++) { - ExamineKey *k = unit->examine_keys + i; - if (k->uniq == 0) - continue; - if (k->aino == from) { - k->aino = to; - tmp++; - } - } - if (tmp != from->exnext_count) - write_log (L"filesys.c: Bug in ExNext bookkeeping. BAD.\n"); - to->exnext_count = from->exnext_count; - to->locked_children = from->locked_children; - from->exnext_count = 0; - from->locked_children = 0; + int i; + unsigned long tmp = 0; + for (i = 0; i < EXKEYS; i++) { + ExamineKey *k = unit->examine_keys + i; + if (k->uniq == 0) + continue; + if (k->aino == from) { + k->aino = to; + tmp++; + } + } + if (tmp != from->exnext_count) + write_log (L"filesys.c: Bug in ExNext bookkeeping. BAD.\n"); + to->exnext_count = from->exnext_count; + to->locked_children = from->locked_children; + from->exnext_count = 0; + from->locked_children = 0; } static void -get_fileinfo (Unit *unit, dpacket packet, uaecptr info, a_inode *aino) -{ - struct _stat64 statbuf; - long days, mins, ticks; - int i, n, entrytype; - int fsdb_can = fsdb_cando (unit); - TCHAR *xs; - char *x, *x2; - - memset (&statbuf, 0, sizeof statbuf); - /* No error checks - this had better work. */ - if (unit->volflags & MYVOLUMEINFO_ARCHIVE) - zfile_stat_archive (aino->nname, &statbuf); - else - stat (aino->nname, &statbuf); - - if (aino->parent == 0) { - /* Guru book says ST_ROOT = 1 (root directory, not currently used) - * but some programs really expect 2 from root dir.. - */ - entrytype = 2; - xs = unit->ui.volname; - } else { - entrytype = aino->dir ? 2 : -3; - xs = aino->aname; - } - put_long (info + 4, entrytype); - /* AmigaOS docs say these have to contain the same value. */ - put_long (info + 120, entrytype); - - TRACE((L"name=\"%s\"\n", xs)); - x2 = x = ua_fs (xs); - n = strlen (x); - if (n > 106) - n = 106; - i = 8; - put_byte (info + i, n); i++; - while (n--) - put_byte (info + i, *x), i++, x++; - while (i < 108) - put_byte (info + i, 0), i++; - xfree (x2); - - put_long (info + 116, fsdb_can ? aino->amigaos_mode : fsdb_mode_supported (aino)); - put_long (info + 124, statbuf.st_size > MAXFILESIZE32 ? MAXFILESIZE32 : statbuf.st_size); -#ifdef HAVE_ST_BLOCKS - put_long (info + 128, statbuf.st_blocks); -#else - put_long (info + 128, (statbuf.st_size + 511) / 512); -#endif - get_time (statbuf.st_mtime, &days, &mins, &ticks); - put_long (info + 132, days); - put_long (info + 136, mins); - put_long (info + 140, ticks); - if (aino->comment == 0 || !fsdb_can) - put_long (info + 144, 0); - else { - TRACE((L"comment=\"%s\"\n", aino->comment)); - i = 144; - xs = aino->comment; - if (!xs) - xs= L""; + get_fileinfo (Unit *unit, dpacket packet, uaecptr info, a_inode *aino) +{ + struct _stat64 statbuf; + long days, mins, ticks; + int i, n, entrytype; + int fsdb_can = fsdb_cando (unit); + TCHAR *xs; + char *x, *x2; + + memset (&statbuf, 0, sizeof statbuf); + /* No error checks - this had better work. */ + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) + zfile_stat_archive (aino->nname, &statbuf); + else + stat (aino->nname, &statbuf); + + if (aino->parent == 0) { + /* Guru book says ST_ROOT = 1 (root directory, not currently used) + * but some programs really expect 2 from root dir.. + */ + entrytype = 2; + xs = unit->ui.volname; + } else { + entrytype = aino->dir ? 2 : -3; + xs = aino->aname; + } + put_long (info + 4, entrytype); + /* AmigaOS docs say these have to contain the same value. */ + put_long (info + 120, entrytype); + + TRACE((L"name=\"%s\"\n", xs)); x2 = x = ua_fs (xs); n = strlen (x); - if (n > 78) - n = 78; + if (n > 106) + n = 106; + i = 8; put_byte (info + i, n); i++; while (n--) - put_byte (info + i, *x), i++, x++; - while (i < 224) - put_byte (info + i, 0), i++; + put_byte (info + i, *x), i++, x++; + while (i < 108) + put_byte (info + i, 0), i++; xfree (x2); - } - PUT_PCK_RES1 (packet, DOS_TRUE); + + put_long (info + 116, fsdb_can ? aino->amigaos_mode : fsdb_mode_supported (aino)); + put_long (info + 124, statbuf.st_size > MAXFILESIZE32 ? MAXFILESIZE32 : statbuf.st_size); +#ifdef HAVE_ST_BLOCKS + put_long (info + 128, statbuf.st_blocks); +#else + put_long (info + 128, (statbuf.st_size + 511) / 512); +#endif + get_time (statbuf.st_mtime, &days, &mins, &ticks); + put_long (info + 132, days); + put_long (info + 136, mins); + put_long (info + 140, ticks); + if (aino->comment == 0 || !fsdb_can) + put_long (info + 144, 0); + else { + TRACE((L"comment=\"%s\"\n", aino->comment)); + i = 144; + xs = aino->comment; + if (!xs) + xs= L""; + x2 = x = ua_fs (xs); + n = strlen (x); + if (n > 78) + n = 78; + put_byte (info + i, n); i++; + while (n--) + put_byte (info + i, *x), i++, x++; + while (i < 224) + put_byte (info + i, 0), i++; + xfree (x2); + } + PUT_PCK_RES1 (packet, DOS_TRUE); } int get_native_path (uae_u32 lock, TCHAR *out) { - int i = 0; - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - if (mountinfo.ui[i].self) { - a_inode *a = lookup_aino (mountinfo.ui[i].self, get_long ((lock << 2) + 4)); - if (a) { - _tcscpy (out, a->nname); - return 0; - } + int i = 0; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + if (mountinfo.ui[i].self) { + a_inode *a = lookup_aino (mountinfo.ui[i].self, get_long ((lock << 2) + 4)); + if (a) { + _tcscpy (out, a->nname); + return 0; + } + } } - } - return -1; + return -1; } #define EXALL_DEBUG 0 @@ -2822,2309 +2822,2309 @@ int get_native_path (uae_u32 lock, TCHAR *out) static ExAllKey *getexall (Unit *unit, uaecptr control, int id) { - int i; - if (id < 0) { - for (i = 0; i < EXALLKEYS; i++) { - if (unit->exalls[i].id == 0) { - unit->exallid++; - if (unit->exallid == EXALL_END) - unit->exallid++; - unit->exalls[i].id = unit->exallid; - unit->exalls[i].control = control; - return &unit->exalls[i]; - } - } - } else if (id > 0) { - for (i = 0; i < EXALLKEYS; i++) { - if (unit->exalls[i].id == id) - return &unit->exalls[i]; + int i; + if (id < 0) { + for (i = 0; i < EXALLKEYS; i++) { + if (unit->exalls[i].id == 0) { + unit->exallid++; + if (unit->exallid == EXALL_END) + unit->exallid++; + unit->exalls[i].id = unit->exallid; + unit->exalls[i].control = control; + return &unit->exalls[i]; + } + } + } else if (id > 0) { + for (i = 0; i < EXALLKEYS; i++) { + if (unit->exalls[i].id == id) + return &unit->exalls[i]; + } } - } - return NULL; + return NULL; } static int exalldo (uaecptr exalldata, uae_u32 exalldatasize, uae_u32 type, uaecptr control, Unit *unit, a_inode *aino) { - uaecptr exp = exalldata; - int i; - int size, size2; - int entrytype; - TCHAR *xs = NULL, *commentx = NULL; - uae_u32 flags = 15, days, mins, ticks; - struct _stat64 statbuf; - int fsdb_can = fsdb_cando (unit); - uae_u16 uid = 0, gid = 0; - char *x = NULL, *comment = NULL; - int ret = 0; - - memset (&statbuf, 0, sizeof statbuf); - if (unit->volflags & MYVOLUMEINFO_ARCHIVE) - zfile_stat_archive (aino->nname, &statbuf); - else - stat (aino->nname, &statbuf); - - if (aino->parent == 0) { - entrytype = 2; - xs = unit->ui.volname; - } else { - entrytype = aino->dir ? 2 : -3; - xs = aino->aname; - } - x = ua_fs (xs); - - size = 0; - size2 = 4; - if (type >= 1) { - size2 += 4; - size += strlen (x) + 1; - size = (size + 3) & ~3; - } - if (type >= 2) - size2 += 4; - if (type >= 3) - size2 += 4; - if (type >= 4) { - flags = fsdb_can ? aino->amigaos_mode : fsdb_mode_supported (aino); - size2 += 4; - } - if (type >= 5) { - get_time (statbuf.st_mtime, &days, &mins, &ticks); - size2 += 12; - } - if (type >= 6) { - size2 += 4; - if (aino->comment == 0 || !fsdb_can) - commentx = L""; + uaecptr exp = exalldata; + int i; + int size, size2; + int entrytype; + TCHAR *xs = NULL, *commentx = NULL; + uae_u32 flags = 15, days, mins, ticks; + struct _stat64 statbuf; + int fsdb_can = fsdb_cando (unit); + uae_u16 uid = 0, gid = 0; + char *x = NULL, *comment = NULL; + int ret = 0; + + memset (&statbuf, 0, sizeof statbuf); + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) + zfile_stat_archive (aino->nname, &statbuf); else - commentx = aino->comment; - comment = ua_fs (commentx); - size += strlen (comment) + 1; - size = (size + 3) & ~3; - } - if (type >= 7) { - size2 += 4; - uid = 0; - gid = 0; - } - - i = get_long (control + 0); - while (i > 0) { - exp = get_long (exp); /* ed_Next */ - i--; - } - - if (exalldata + exalldatasize - exp < size + size2) - goto end; /* not enough space */ + stat (aino->nname, &statbuf); + + if (aino->parent == 0) { + entrytype = 2; + xs = unit->ui.volname; + } else { + entrytype = aino->dir ? 2 : -3; + xs = aino->aname; + } + x = ua_fs (xs); + + size = 0; + size2 = 4; + if (type >= 1) { + size2 += 4; + size += strlen (x) + 1; + size = (size + 3) & ~3; + } + if (type >= 2) + size2 += 4; + if (type >= 3) + size2 += 4; + if (type >= 4) { + flags = fsdb_can ? aino->amigaos_mode : fsdb_mode_supported (aino); + size2 += 4; + } + if (type >= 5) { + get_time (statbuf.st_mtime, &days, &mins, &ticks); + size2 += 12; + } + if (type >= 6) { + size2 += 4; + if (aino->comment == 0 || !fsdb_can) + commentx = L""; + else + commentx = aino->comment; + comment = ua_fs (commentx); + size += strlen (comment) + 1; + size = (size + 3) & ~3; + } + if (type >= 7) { + size2 += 4; + uid = 0; + gid = 0; + } + + i = get_long (control + 0); + while (i > 0) { + exp = get_long (exp); /* ed_Next */ + i--; + } + + if (exalldata + exalldatasize - exp < size + size2) + goto end; /* not enough space */ #if EXALL_DEBUG > 0 - write_log (L"ID=%d, %d, %08x: '%s'%s\n", - get_long (control + 4), get_long (control + 0), exp, xs, aino->dir ? L" [DIR]" : L""); + write_log (L"ID=%d, %d, %08x: '%s'%s\n", + get_long (control + 4), get_long (control + 0), exp, xs, aino->dir ? L" [DIR]" : L""); #endif - put_long (exp, exp + size + size2); /* ed_Next */ - if (type >= 1) { - put_long (exp + 4, exp + size2); - for (i = 0; i <= strlen (x); i++) { - put_byte (exp + size2, x[i]); - size2++; - } - } - if (type >= 2) - put_long (exp + 8, entrytype); - if (type >= 3) - put_long (exp + 12, statbuf.st_size > MAXFILESIZE32 ? MAXFILESIZE32 : statbuf.st_size); - if (type >= 4) - put_long (exp + 16, flags); - if (type >= 5) { - put_long (exp + 20, days); - put_long (exp + 24, mins); - put_long (exp + 28, ticks); - } - if (type >= 6) { - put_long (exp + 32, exp + size2); - put_byte (exp + size2, strlen (comment)); - for (i = 0; i <= strlen (comment); i++) { - put_byte (exp + size2, comment[i]); - size2++; - } - } - if (type >= 7) { - put_word (exp + 36, uid); - put_word (exp + 38, gid); - } - put_long (control + 0, get_long (control + 0) + 1); - ret = 1; + put_long (exp, exp + size + size2); /* ed_Next */ + if (type >= 1) { + put_long (exp + 4, exp + size2); + for (i = 0; i <= strlen (x); i++) { + put_byte (exp + size2, x[i]); + size2++; + } + } + if (type >= 2) + put_long (exp + 8, entrytype); + if (type >= 3) + put_long (exp + 12, statbuf.st_size > MAXFILESIZE32 ? MAXFILESIZE32 : statbuf.st_size); + if (type >= 4) + put_long (exp + 16, flags); + if (type >= 5) { + put_long (exp + 20, days); + put_long (exp + 24, mins); + put_long (exp + 28, ticks); + } + if (type >= 6) { + put_long (exp + 32, exp + size2); + put_byte (exp + size2, strlen (comment)); + for (i = 0; i <= strlen (comment); i++) { + put_byte (exp + size2, comment[i]); + size2++; + } + } + if (type >= 7) { + put_word (exp + 36, uid); + put_word (exp + 38, gid); + } + put_long (control + 0, get_long (control + 0) + 1); + ret = 1; end: - xfree (x); - xfree (comment); - return ret; + xfree (x); + xfree (comment); + return ret; } static int action_examine_all_do (Unit *unit, uaecptr lock, ExAllKey *eak, uaecptr exalldata, uae_u32 exalldatasize, uae_u32 type, uaecptr control) { - a_inode *aino, *base; - int ok; - uae_u32 err; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - void *d; - TCHAR fn[MAX_DPATH]; - - if (lock != 0) - base = lookup_aino (unit, get_long (lock + 4)); - if (base == 0) - base = &unit->rootnode; - for (;;) { - d = eak->dirhandle; - if (!eak->fn) { - do { - if (isarch) - ok = zfile_readdir_archive (d, fn); - else - ok = my_readdir (d, fn); - } while (ok && !isarch && fsdb_name_invalid (fn)); - if (!ok) - return 0; - } else { - _tcscpy (fn, eak->fn); - xfree (eak->fn); - eak->fn = NULL; - } - aino = lookup_child_aino_for_exnext (unit, base, fn, &err); - if (!aino) - return 0; - eak->id = unit->exallid++; - put_long (control + 4, eak->id); - if (!exalldo (exalldata, exalldatasize, type, control, unit, aino)) { - eak->fn = my_strdup (fn); /* no space in exallstruct, save current entry */ - break; + a_inode *aino, *base; + int ok; + uae_u32 err; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + void *d; + TCHAR fn[MAX_DPATH]; + + if (lock != 0) + base = lookup_aino (unit, get_long (lock + 4)); + if (base == 0) + base = &unit->rootnode; + for (;;) { + d = eak->dirhandle; + if (!eak->fn) { + do { + if (isarch) + ok = zfile_readdir_archive (d, fn); + else + ok = my_readdir (d, fn); + } while (ok && !isarch && fsdb_name_invalid (fn)); + if (!ok) + return 0; + } else { + _tcscpy (fn, eak->fn); + xfree (eak->fn); + eak->fn = NULL; + } + aino = lookup_child_aino_for_exnext (unit, base, fn, &err); + if (!aino) + return 0; + eak->id = unit->exallid++; + put_long (control + 4, eak->id); + if (!exalldo (exalldata, exalldatasize, type, control, unit, aino)) { + eak->fn = my_strdup (fn); /* no space in exallstruct, save current entry */ + break; + } } - } - return 1; + return 1; } static int action_examine_all_end (Unit *unit, dpacket packet) { - uae_u32 id; - uae_u32 doserr = 0; - ExAllKey *eak; - uaecptr control = GET_PCK_ARG5 (packet); + uae_u32 id; + uae_u32 doserr = 0; + ExAllKey *eak; + uaecptr control = GET_PCK_ARG5 (packet); - if (kickstart_version < 36) - return 0; - id = get_long (control + 4); - eak = getexall (unit, control, id); + if (kickstart_version < 36) + return 0; + id = get_long (control + 4); + eak = getexall (unit, control, id); #if EXALL_DEBUG > 0 - write_log (L"EXALL_END ID=%d %x\n", id, eak); + write_log (L"EXALL_END ID=%d %x\n", id, eak); #endif - if (!eak) { - write_log (L"FILESYS: EXALL_END non-existing ID %d\n", id); - doserr = ERROR_OBJECT_WRONG_TYPE; - } else { - eak->id = 0; - fs_closedir (unit, eak->dirhandle); - xfree (eak->fn); - eak->fn = NULL; - eak->dirhandle = NULL; - } - if (doserr) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, doserr); - } else { - PUT_PCK_RES1 (packet, DOS_TRUE); - } - return 1; + if (!eak) { + write_log (L"FILESYS: EXALL_END non-existing ID %d\n", id); + doserr = ERROR_OBJECT_WRONG_TYPE; + } else { + eak->id = 0; + fs_closedir (unit, eak->dirhandle); + xfree (eak->fn); + eak->fn = NULL; + eak->dirhandle = NULL; + } + if (doserr) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, doserr); + } else { + PUT_PCK_RES1 (packet, DOS_TRUE); + } + return 1; } static int action_examine_all (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr exalldata = GET_PCK_ARG2 (packet); - uae_u32 exalldatasize = GET_PCK_ARG3 (packet); - uae_u32 type = GET_PCK_ARG4 (packet); - uaecptr control = GET_PCK_ARG5 (packet); + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr exalldata = GET_PCK_ARG2 (packet); + uae_u32 exalldatasize = GET_PCK_ARG3 (packet); + uae_u32 type = GET_PCK_ARG4 (packet); + uaecptr control = GET_PCK_ARG5 (packet); - ExAllKey *eak = NULL; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - a_inode *base; - void *d; - int ok, i; - uaecptr exp; - uae_u32 id, doserr = ERROR_NO_MORE_ENTRIES; + ExAllKey *eak = NULL; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + a_inode *base; + void *d; + int ok, i; + uaecptr exp; + uae_u32 id, doserr = ERROR_NO_MORE_ENTRIES; - ok = 0; + ok = 0; #if EXALL_DEBUG > 0 - write_log (L"exall: %08x %08x-%08x %d %d %08x\n", - lock, exalldata, exalldata + exalldatasize, exalldatasize, type, control); - write_log (L"exall: MatchString %08x, MatchFunc %08x\n", - get_long (control + 8), get_long (control + 12)); + write_log (L"exall: %08x %08x-%08x %d %d %08x\n", + lock, exalldata, exalldata + exalldatasize, exalldatasize, type, control); + write_log (L"exall: MatchString %08x, MatchFunc %08x\n", + get_long (control + 8), get_long (control + 12)); #endif - put_long (control + 0, 0); /* eac_Entries */ + put_long (control + 0, 0); /* eac_Entries */ - /* EXAMINE ALL might use dos.library MatchPatternNoCase() which is >=36 */ - if (kickstart_version < 36) - return 0; + /* EXAMINE ALL might use dos.library MatchPatternNoCase() which is >=36 */ + if (kickstart_version < 36) + return 0; - if (type == 0 || type > 7) { - doserr = ERROR_BAD_NUMBER; - goto fail; - } - - PUT_PCK_RES1 (packet, DOS_TRUE); - id = get_long (control + 4); - if (id == EXALL_END) { - write_log (L"FILESYS: EXALL called twice with ERROR_NO_MORE_ENTRIES\n"); - goto fail; /* already ended exall() */ - } - if (id) { - eak = getexall (unit, control, id); - if (!eak) { - write_log (L"FILESYS: EXALL non-existing ID %d\n", id); - doserr = ERROR_OBJECT_WRONG_TYPE; - goto fail; - } - if (!action_examine_all_do (unit, lock, eak, exalldata, exalldatasize, type, control)) - goto fail; - if (get_long (control + 0) == 0) { - /* uh, no space for first entry.. */ - doserr = ERROR_NO_FREE_STORE; - goto fail; + if (type == 0 || type > 7) { + doserr = ERROR_BAD_NUMBER; + goto fail; } - } else { + PUT_PCK_RES1 (packet, DOS_TRUE); + id = get_long (control + 4); + if (id == EXALL_END) { + write_log (L"FILESYS: EXALL called twice with ERROR_NO_MORE_ENTRIES\n"); + goto fail; /* already ended exall() */ + } + if (id) { + eak = getexall (unit, control, id); + if (!eak) { + write_log (L"FILESYS: EXALL non-existing ID %d\n", id); + doserr = ERROR_OBJECT_WRONG_TYPE; + goto fail; + } + if (!action_examine_all_do (unit, lock, eak, exalldata, exalldatasize, type, control)) + goto fail; + if (get_long (control + 0) == 0) { + /* uh, no space for first entry.. */ + doserr = ERROR_NO_FREE_STORE; + goto fail; + } - eak = getexall (unit, control, -1); - if (!eak) - goto fail; - if (lock != 0) - base = lookup_aino (unit, get_long (lock + 4)); - if (base == 0) - base = &unit->rootnode; + } else { + + eak = getexall (unit, control, -1); + if (!eak) + goto fail; + if (lock != 0) + base = lookup_aino (unit, get_long (lock + 4)); + if (base == 0) + base = &unit->rootnode; #if EXALL_DEBUG > 0 - write_log("exall: ID=%d '%s'\n", eak->id, base->nname); + write_log("exall: ID=%d '%s'\n", eak->id, base->nname); #endif - d = fs_opendir (unit, base->nname); - if (!d) - goto fail; - eak->dirhandle = d; - put_long (control + 4, eak->id); - if (!action_examine_all_do (unit, lock, eak, exalldata, exalldatasize, type, control)) - goto fail; - if (get_long (control + 0) == 0) { - /* uh, no space for first entry.. */ - doserr = ERROR_NO_FREE_STORE; - goto fail; - } + d = fs_opendir (unit, base->nname); + if (!d) + goto fail; + eak->dirhandle = d; + put_long (control + 4, eak->id); + if (!action_examine_all_do (unit, lock, eak, exalldata, exalldatasize, type, control)) + goto fail; + if (get_long (control + 0) == 0) { + /* uh, no space for first entry.. */ + doserr = ERROR_NO_FREE_STORE; + goto fail; + } - } - ok = 1; + } + ok = 1; fail: - /* Clear last ed_Next. This "list" is quite non-Amiga like.. */ - exp = exalldata; - i = get_long (control + 0); - for (;;) { - if (i <= 1) { - if (exp) - put_long (exp, 0); - break; - } - exp = get_long (exp); /* ed_Next */ - i--; - } + /* Clear last ed_Next. This "list" is quite non-Amiga like.. */ + exp = exalldata; + i = get_long (control + 0); + for (;;) { + if (i <= 1) { + if (exp) + put_long (exp, 0); + break; + } + exp = get_long (exp); /* ed_Next */ + i--; + } #if EXALL_DEBUG > 0 - write_log("ok=%d, err=%d, eac_Entries = %d\n", ok, ok ? -1 : doserr, get_long (control + 0)); + write_log("ok=%d, err=%d, eac_Entries = %d\n", ok, ok ? -1 : doserr, get_long (control + 0)); #endif - if (!ok) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, doserr); - if (eak) { - eak->id = 0; - fs_closedir (unit, eak->dirhandle); - eak->dirhandle = NULL; - xfree (eak->fn); - eak->fn = NULL; + if (!ok) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, doserr); + if (eak) { + eak->id = 0; + fs_closedir (unit, eak->dirhandle); + eak->dirhandle = NULL; + xfree (eak->fn); + eak->fn = NULL; + } + if (doserr == ERROR_NO_MORE_ENTRIES) + put_long (control + 4, EXALL_END); } - if (doserr == ERROR_NO_MORE_ENTRIES) - put_long (control + 4, EXALL_END); - } - return 1; + return 1; } static uae_u32 REGPARAM2 exall_helper (TrapContext *context) { - int i; - Unit *u; - uaecptr packet = m68k_areg (regs, 4); - uaecptr control = get_long (packet + dp_Arg5); - uae_u32 id = get_long (control + 4); + int i; + Unit *u; + uaecptr packet = m68k_areg (regs, 4); + uaecptr control = get_long (packet + dp_Arg5); + uae_u32 id = get_long (control + 4); #if EXALL_DEBUG > 0 - write_log (L"FILESYS: EXALL extra round ID=%d\n", id); + write_log (L"FILESYS: EXALL extra round ID=%d\n", id); #endif - if (id == EXALL_END) - return 1; - for (u = units; u; u = u->next) { - for (i = 0; i < EXALLKEYS; i++) { - if (u->exalls[i].id == id && u->exalls[i].control == control) { - action_examine_all (u, get_real_address (packet)); - } + if (id == EXALL_END) + return 1; + for (u = units; u; u = u->next) { + for (i = 0; i < EXALLKEYS; i++) { + if (u->exalls[i].id == id && u->exalls[i].control == control) { + action_examine_all (u, get_real_address (packet)); + } + } } - } - return 1; + return 1; } static void action_examine_object (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr info = GET_PCK_ARG2 (packet) << 2; - a_inode *aino = 0; + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr info = GET_PCK_ARG2 (packet) << 2; + a_inode *aino = 0; - TRACE((L"ACTION_EXAMINE_OBJECT(0x%lx,0x%lx)\n", lock, info)); - DUMPLOCK(unit, lock); + TRACE((L"ACTION_EXAMINE_OBJECT(0x%lx,0x%lx)\n", lock, info)); + DUMPLOCK(unit, lock); - if (lock != 0) - aino = lookup_aino (unit, get_long (lock + 4)); - if (aino == 0) - aino = &unit->rootnode; + if (lock != 0) + aino = lookup_aino (unit, get_long (lock + 4)); + if (aino == 0) + aino = &unit->rootnode; - get_fileinfo (unit, packet, info, aino); - if (aino->dir) { - put_long (info, 0xFFFFFFFF); - } else - put_long (info, 0); + get_fileinfo (unit, packet, info, aino); + if (aino->dir) { + put_long (info, 0xFFFFFFFF); + } else + put_long (info, 0); } /* Read a directory's contents, create a_inodes for each file, and - mark them as locked in memory so that recycle_aino will not reap - them. - We do this to avoid problems with the host OS: we don't want to - leave the directory open on the host side until all ExNext()s have - finished - they may never finish! */ +mark them as locked in memory so that recycle_aino will not reap +them. +We do this to avoid problems with the host OS: we don't want to +leave the directory open on the host side until all ExNext()s have +finished - they may never finish! */ static void populate_directory (Unit *unit, a_inode *base) { - void *d; - a_inode *aino; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + void *d; + a_inode *aino; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - d = fs_opendir (unit, base->nname); - if (!d) - return; - for (aino = base->child; aino; aino = aino->sibling) { - base->locked_children++; - unit->total_locked_ainos++; - } - TRACE((L"Populating directory, child %p, locked_children %d\n", - base->child, base->locked_children)); - for (;;) { - TCHAR fn[MAX_DPATH]; - int ok; - uae_u32 err; + d = fs_opendir (unit, base->nname); + if (!d) + return; + for (aino = base->child; aino; aino = aino->sibling) { + base->locked_children++; + unit->total_locked_ainos++; + } + TRACE((L"Populating directory, child %p, locked_children %d\n", + base->child, base->locked_children)); + for (;;) { + TCHAR fn[MAX_DPATH]; + int ok; + uae_u32 err; - /* Find next file that belongs to the Amiga fs (skipping things - like "..", "." etc. */ - do { - if (isarch) - ok = zfile_readdir_archive(d, fn); - else - ok = my_readdir (d, fn); - } while (ok && !isarch && fsdb_name_invalid (fn)); - if (!ok) - break; - /* This calls init_child_aino, which will notice that the parent is - being ExNext()ed, and it will increment the locked counts. */ - aino = lookup_child_aino_for_exnext (unit, base, fn, &err); - } - fs_closedir (unit, d); + /* Find next file that belongs to the Amiga fs (skipping things + like "..", "." etc. */ + do { + if (isarch) + ok = zfile_readdir_archive(d, fn); + else + ok = my_readdir (d, fn); + } while (ok && !isarch && fsdb_name_invalid (fn)); + if (!ok) + break; + /* This calls init_child_aino, which will notice that the parent is + being ExNext()ed, and it will increment the locked counts. */ + aino = lookup_child_aino_for_exnext (unit, base, fn, &err); + } + fs_closedir (unit, d); } static void do_examine (Unit *unit, dpacket packet, ExamineKey *ek, uaecptr info) { - for (;;) { - TCHAR *name; - if (ek->curr_file == 0) - break; - name = ek->curr_file->nname; - get_fileinfo (unit, packet, info, ek->curr_file); - ek->curr_file = ek->curr_file->sibling; - if (!(unit->volflags & MYVOLUMEINFO_ARCHIVE) && !fsdb_exists(name)) { - TRACE ((L"%s orphaned", name)); - continue; - } - TRACE ((L"curr_file set to %p %s\n", ek->curr_file, - ek->curr_file ? ek->curr_file->aname : L"NULL")); - return; - } - TRACE((L"no more entries\n")); - free_exkey (unit, ek); - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES); + for (;;) { + TCHAR *name; + if (ek->curr_file == 0) + break; + name = ek->curr_file->nname; + get_fileinfo (unit, packet, info, ek->curr_file); + ek->curr_file = ek->curr_file->sibling; + if (!(unit->volflags & MYVOLUMEINFO_ARCHIVE) && !fsdb_exists(name)) { + TRACE ((L"%s orphaned", name)); + continue; + } + TRACE ((L"curr_file set to %p %s\n", ek->curr_file, + ek->curr_file ? ek->curr_file->aname : L"NULL")); + return; + } + TRACE((L"no more entries\n")); + free_exkey (unit, ek); + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES); } static void action_examine_next (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr info = GET_PCK_ARG2 (packet) << 2; - a_inode *aino = 0; - ExamineKey *ek; - uae_u32 uniq; + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr info = GET_PCK_ARG2 (packet) << 2; + a_inode *aino = 0; + ExamineKey *ek; + uae_u32 uniq; - TRACE((L"ACTION_EXAMINE_NEXT(0x%lx,0x%lx)\n", lock, info)); - gui_hd_led (unit->unit, 1); - DUMPLOCK(unit, lock); + TRACE((L"ACTION_EXAMINE_NEXT(0x%lx,0x%lx)\n", lock, info)); + gui_hd_led (unit->unit, 1); + DUMPLOCK(unit, lock); - if (lock != 0) - aino = lookup_aino (unit, get_long (lock + 4)); - if (aino == 0) - aino = &unit->rootnode; -for(;;) { - uniq = get_long (info); - if (uniq == 0) { - write_log (L"ExNext called for a file! (Houston?)\n"); - goto no_more_entries; - } else if (uniq == 0xFFFFFFFE) - goto no_more_entries; - else if (uniq == 0xFFFFFFFF) { - TRACE((L"Creating new ExKey\n")); - ek = new_exkey (unit, aino); - if (ek) { - if (aino->exnext_count++ == 0) - populate_directory (unit, aino); - ek->curr_file = aino->child; - TRACE((L"Initial curr_file: %p %s\n", ek->curr_file, - ek->curr_file ? ek->curr_file->aname : L"NULL")); - } - } else { - TRACE((L"Looking up ExKey\n")); - ek = lookup_exkey (unit, get_long (info)); - } - if (ek == 0) { - write_log (L"Couldn't find a matching ExKey. Prepare for trouble.\n"); - goto no_more_entries; - } - put_long (info, ek->uniq); - if (!ek->curr_file || ek->curr_file->mountcount == unit->mountcount) - break; - ek->curr_file = ek->curr_file->sibling; - if (!ek->curr_file) - goto no_more_entries; -} - do_examine (unit, packet, ek, info); - return; - - no_more_entries: - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES); + if (lock != 0) + aino = lookup_aino (unit, get_long (lock + 4)); + if (aino == 0) + aino = &unit->rootnode; + for(;;) { + uniq = get_long (info); + if (uniq == 0) { + write_log (L"ExNext called for a file! (Houston?)\n"); + goto no_more_entries; + } else if (uniq == 0xFFFFFFFE) + goto no_more_entries; + else if (uniq == 0xFFFFFFFF) { + TRACE((L"Creating new ExKey\n")); + ek = new_exkey (unit, aino); + if (ek) { + if (aino->exnext_count++ == 0) + populate_directory (unit, aino); + ek->curr_file = aino->child; + TRACE((L"Initial curr_file: %p %s\n", ek->curr_file, + ek->curr_file ? ek->curr_file->aname : L"NULL")); + } + } else { + TRACE((L"Looking up ExKey\n")); + ek = lookup_exkey (unit, get_long (info)); + } + if (ek == 0) { + write_log (L"Couldn't find a matching ExKey. Prepare for trouble.\n"); + goto no_more_entries; + } + put_long (info, ek->uniq); + if (!ek->curr_file || ek->curr_file->mountcount == unit->mountcount) + break; + ek->curr_file = ek->curr_file->sibling; + if (!ek->curr_file) + goto no_more_entries; + } + do_examine (unit, packet, ek, info); + return; + +no_more_entries: + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES); } static void do_find (Unit *unit, dpacket packet, int mode, int create, int fallback) { - uaecptr fh = GET_PCK_ARG1 (packet) << 2; - uaecptr lock = GET_PCK_ARG2 (packet) << 2; - uaecptr name = GET_PCK_ARG3 (packet) << 2; - a_inode *aino; - Key *k; - void *fd; - uae_u32 err; - mode_t openmode; - int aino_created = 0; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + uaecptr fh = GET_PCK_ARG1 (packet) << 2; + uaecptr lock = GET_PCK_ARG2 (packet) << 2; + uaecptr name = GET_PCK_ARG3 (packet) << 2; + a_inode *aino; + Key *k; + void *fd; + uae_u32 err; + mode_t openmode; + int aino_created = 0; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - TRACE((L"ACTION_FIND_*(0x%lx,0x%lx,\"%s\",%d,%d)\n", fh, lock, bstr (unit, name), mode, create)); - DUMPLOCK(unit, lock); + TRACE((L"ACTION_FIND_*(0x%lx,0x%lx,\"%s\",%d,%d)\n", fh, lock, bstr (unit, name), mode, create)); + DUMPLOCK(unit, lock); - aino = find_aino (unit, lock, bstr (unit, name), &err); + aino = find_aino (unit, lock, bstr (unit, name), &err); - if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { - /* Whatever it is, we can't handle it. */ - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } - if (err == 0) { - /* Object exists. */ - if (aino->dir) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_WRONG_TYPE); - return; - } - if (aino->elock || (create == 2 && aino->shlock > 0)) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); - return; - } - if (create == 2 && (aino->amigaos_mode & A_FIBF_DELETE) != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED); - return; - } - if (create != 2) { - if ((((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0 || unit->ui.readonly) - && fallback) - { - mode &= ~A_FIBF_WRITE; - } - /* Kick 1.3 doesn't check read and write access bits - maybe it would be - * simpler just not to do that either. */ - if ((mode & A_FIBF_WRITE) != 0 && unit->ui.readonly) { + if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { + /* Whatever it is, we can't handle it. */ PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + PUT_PCK_RES2 (packet, err); return; - } - if (((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0 - || mode == 0) - { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_WRITE_PROTECTED); - return; - } - if (((mode & aino->amigaos_mode) & A_FIBF_READ) != 0) { + } + if (err == 0) { + /* Object exists. */ + if (aino->dir) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_WRONG_TYPE); + return; + } + if (aino->elock || (create == 2 && aino->shlock > 0)) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); + return; + } + if (create == 2 && (aino->amigaos_mode & A_FIBF_DELETE) != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED); + return; + } + if (create != 2) { + if ((((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0 || unit->ui.readonly) + && fallback) + { + mode &= ~A_FIBF_WRITE; + } + /* Kick 1.3 doesn't check read and write access bits - maybe it would be + * simpler just not to do that either. */ + if ((mode & A_FIBF_WRITE) != 0 && unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } + if (((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0 + || mode == 0) + { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_WRITE_PROTECTED); + return; + } + if (((mode & aino->amigaos_mode) & A_FIBF_READ) != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_READ_PROTECTED); + return; + } + } + } else if (create == 0) { PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_READ_PROTECTED); + PUT_PCK_RES2 (packet, err); return; - } - } - } else if (create == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } else { - /* Object does not exist. aino points to containing directory. */ - aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 0); - if (aino == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ - return; + } else { + /* Object does not exist. aino points to containing directory. */ + aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 0); + if (aino == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ + return; + } + aino_created = 1; } - aino_created = 1; - } - prepare_for_open (aino->nname); + prepare_for_open (aino->nname); - openmode = (((mode & A_FIBF_READ) == 0 ? O_WRONLY - : (mode & A_FIBF_WRITE) == 0 ? O_RDONLY - : O_RDWR) + openmode = (((mode & A_FIBF_READ) == 0 ? O_WRONLY + : (mode & A_FIBF_WRITE) == 0 ? O_RDONLY + : O_RDWR) | (create ? O_CREAT : 0) | (create == 2 ? O_TRUNC : 0)); - fd = fs_open (unit, aino->nname, openmode | O_BINARY); - if (fd == NULL) { - if (aino_created) - delete_aino (unit, aino); - PUT_PCK_RES1 (packet, DOS_FALSE); - /* archive and fd == NULL = corrupt archive or out of memory */ - PUT_PCK_RES2 (packet, isarch ? ERROR_OBJECT_NOT_AROUND : dos_errno ()); - return; - } - - k = new_key (unit); - k->fd = fd; - k->aino = aino; - k->dosmode = mode; - k->createmode = create; - k->notifyactive = create ? 1 : 0; - - if (create && isarch) - fsdb_set_file_attrs (aino); + fd = fs_open (unit, aino->nname, openmode | O_BINARY); + if (fd == NULL) { + if (aino_created) + delete_aino (unit, aino); + PUT_PCK_RES1 (packet, DOS_FALSE); + /* archive and fd == NULL = corrupt archive or out of memory */ + PUT_PCK_RES2 (packet, isarch ? ERROR_OBJECT_NOT_AROUND : dos_errno ()); + return; + } - put_long (fh + 36, k->uniq); - if (create == 2) { - aino->elock = 1; - // clear comment if file already existed - if (aino->comment) { - xfree (aino->comment); - aino->comment = 0; + k = new_key (unit); + k->fd = fd; + k->aino = aino; + k->dosmode = mode; + k->createmode = create; + k->notifyactive = create ? 1 : 0; + + if (create && isarch) + fsdb_set_file_attrs (aino); + + put_long (fh + 36, k->uniq); + if (create == 2) { + aino->elock = 1; + // clear comment if file already existed + if (aino->comment) { + xfree (aino->comment); + aino->comment = 0; + } + fsdb_set_file_attrs (aino); + } else { + aino->shlock++; } - fsdb_set_file_attrs (aino); - } else { - aino->shlock++; - } - de_recycle_aino (unit, aino); - PUT_PCK_RES1 (packet, DOS_TRUE); + de_recycle_aino (unit, aino); + PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_fh_from_lock (Unit *unit, dpacket packet) + action_fh_from_lock (Unit *unit, dpacket packet) { - uaecptr fh = GET_PCK_ARG1 (packet) << 2; - uaecptr lock = GET_PCK_ARG2 (packet) << 2; - a_inode *aino; - Key *k; - void *fd; - mode_t openmode; - int mode; - int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; + uaecptr fh = GET_PCK_ARG1 (packet) << 2; + uaecptr lock = GET_PCK_ARG2 (packet) << 2; + a_inode *aino; + Key *k; + void *fd; + mode_t openmode; + int mode; + int isarch = unit->volflags & MYVOLUMEINFO_ARCHIVE; - TRACE((L"ACTION_FH_FROM_LOCK(0x%lx,0x%lx)\n", fh, lock)); - DUMPLOCK(unit,lock); + TRACE((L"ACTION_FH_FROM_LOCK(0x%lx,0x%lx)\n", fh, lock)); + DUMPLOCK(unit,lock); - if (!lock) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, 0); - return; - } + if (!lock) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, 0); + return; + } - aino = lookup_aino (unit, get_long (lock + 4)); - if (aino == 0) - aino = &unit->rootnode; - mode = aino->amigaos_mode; /* Use same mode for opened filehandle as existing Lock() */ + aino = lookup_aino (unit, get_long (lock + 4)); + if (aino == 0) + aino = &unit->rootnode; + mode = aino->amigaos_mode; /* Use same mode for opened filehandle as existing Lock() */ - prepare_for_open (aino->nname); + prepare_for_open (aino->nname); - TRACE ((L" mode is %d\n", mode)); - openmode = (((mode & A_FIBF_READ) ? O_WRONLY - : (mode & A_FIBF_WRITE) ? O_RDONLY - : O_RDWR)); + TRACE ((L" mode is %d\n", mode)); + openmode = (((mode & A_FIBF_READ) ? O_WRONLY + : (mode & A_FIBF_WRITE) ? O_RDONLY + : O_RDWR)); - /* the files on CD really can have the write-bit set. */ - if (unit->ui.readonly) - openmode = O_RDONLY; + /* the files on CD really can have the write-bit set. */ + if (unit->ui.readonly) + openmode = O_RDONLY; - fd = fs_open (unit, aino->nname, openmode | O_BINARY); + fd = fs_open (unit, aino->nname, openmode | O_BINARY); - if (fd == NULL) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - k = new_key (unit); - k->fd = fd; - k->aino = aino; + if (fd == NULL) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + k = new_key (unit); + k->fd = fd; + k->aino = aino; - put_long (fh + 36, k->uniq); - /* I don't think I need to play with shlock count here, because I'm - opening from an existing lock ??? */ + put_long (fh + 36, k->uniq); + /* I don't think I need to play with shlock count here, because I'm + opening from an existing lock ??? */ - de_recycle_aino (unit, aino); - free_lock (unit, lock); /* lock must be unlocked */ - PUT_PCK_RES1 (packet, DOS_TRUE); - /* PUT_PCK_RES2 (packet, k->uniq); - this shouldn't be necessary, try without it */ + de_recycle_aino (unit, aino); + free_lock (unit, lock); /* lock must be unlocked */ + PUT_PCK_RES1 (packet, DOS_TRUE); + /* PUT_PCK_RES2 (packet, k->uniq); - this shouldn't be necessary, try without it */ } static void -action_find_input (Unit *unit, dpacket packet) + action_find_input (Unit *unit, dpacket packet) { - do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 0, 1); + do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 0, 1); } static void -action_find_output (Unit *unit, dpacket packet) + action_find_output (Unit *unit, dpacket packet) { - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } - do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 2, 0); + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } + do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 2, 0); } static void -action_find_write (Unit *unit, dpacket packet) + action_find_write (Unit *unit, dpacket packet) { - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } - do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 1, 0); + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } + do_find (unit, packet, A_FIBF_READ | A_FIBF_WRITE, 1, 0); } /* change file/dir's parent dir modification time */ static void updatedirtime (a_inode *a1, int now) { - struct _stat64 statbuf; - struct utimbuf ut; - long days, mins, ticks; + struct _stat64 statbuf; + struct utimbuf ut; + long days, mins, ticks; - if (!a1->parent) - return; - if (!now) { - if (stat (a1->nname, &statbuf) == -1) - return; - get_time (statbuf.st_mtime, &days, &mins, &ticks); - ut.actime = ut.modtime = put_time (days, mins, ticks); - utime (a1->parent->nname, &ut); - } else { - utime (a1->parent->nname, NULL); - } + if (!a1->parent) + return; + if (!now) { + if (stat (a1->nname, &statbuf) == -1) + return; + get_time (statbuf.st_mtime, &days, &mins, &ticks); + ut.actime = ut.modtime = put_time (days, mins, ticks); + utime (a1->parent->nname, &ut); + } else { + utime (a1->parent->nname, NULL); + } } static void -action_end (Unit *unit, dpacket packet) + action_end (Unit *unit, dpacket packet) { - Key *k; - TRACE((L"ACTION_END(0x%lx)\n", GET_PCK_ARG1 (packet))); + Key *k; + TRACE((L"ACTION_END(0x%lx)\n", GET_PCK_ARG1 (packet))); - k = lookup_key (unit, GET_PCK_ARG1 (packet)); - if (k != 0) { - if (k->notifyactive) { - notify_check (unit, k->aino); - updatedirtime (k->aino, 1); + k = lookup_key (unit, GET_PCK_ARG1 (packet)); + if (k != 0) { + if (k->notifyactive) { + notify_check (unit, k->aino); + updatedirtime (k->aino, 1); + } + if (k->aino->elock) + k->aino->elock = 0; + else + k->aino->shlock--; + recycle_aino (unit, k->aino); + free_key (unit, k); } - if (k->aino->elock) - k->aino->elock = 0; - else - k->aino->shlock--; - recycle_aino (unit, k->aino); - free_key (unit, k); - } - PUT_PCK_RES1 (packet, DOS_TRUE); - PUT_PCK_RES2 (packet, 0); + PUT_PCK_RES1 (packet, DOS_TRUE); + PUT_PCK_RES2 (packet, 0); } static void -action_read (Unit *unit, dpacket packet) + action_read (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); - uaecptr addr = GET_PCK_ARG2 (packet); - long size = (uae_s32)GET_PCK_ARG3 (packet); - int actual; + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); + uaecptr addr = GET_PCK_ARG2 (packet); + long size = (uae_s32)GET_PCK_ARG3 (packet); + int actual; - if (k == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - /* PUT_PCK_RES2 (packet, EINVAL); */ - return; - } - TRACE((L"ACTION_READ(%s,0x%lx,%ld)\n", k->aino->nname, addr, size)); - gui_hd_led (unit->unit, 1); + if (k == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + /* PUT_PCK_RES2 (packet, EINVAL); */ + return; + } + TRACE((L"ACTION_READ(%s,0x%lx,%ld)\n", k->aino->nname, addr, size)); + gui_hd_led (unit->unit, 1); #ifdef RELY_ON_LOADSEG_DETECTION - /* HACK HACK HACK HACK - * Try to detect a LoadSeg() */ - if (k->file_pos == 0 && size >= 4) { - unsigned TCHAR buf[4]; - off_t currpos = fs_lseek (unit, k->fd, 0, SEEK_CUR); - my_read (k->fd, buf, 4); - fs_lseek (unit, k->fd, currpos, SEEK_SET); - if (buf[0] == 0 && buf[1] == 0 && buf[2] == 3 && buf[3] == 0xF3) - possible_loadseg(); - } + /* HACK HACK HACK HACK + * Try to detect a LoadSeg() */ + if (k->file_pos == 0 && size >= 4) { + unsigned TCHAR buf[4]; + off_t currpos = fs_lseek (unit, k->fd, 0, SEEK_CUR); + my_read (k->fd, buf, 4); + fs_lseek (unit, k->fd, currpos, SEEK_SET); + if (buf[0] == 0 && buf[1] == 0 && buf[2] == 3 && buf[3] == 0xF3) + possible_loadseg(); + } #endif - if (valid_address (addr, size)) { - uae_u8 *realpt; - realpt = get_real_address (addr); - actual = fs_read (unit, k->fd, realpt, size); - - if (actual == 0) { - PUT_PCK_RES1 (packet, 0); - PUT_PCK_RES2 (packet, 0); - } else if (actual < 0) { - PUT_PCK_RES1 (packet, 0); - PUT_PCK_RES2 (packet, dos_errno ()); + if (valid_address (addr, size)) { + uae_u8 *realpt; + realpt = get_real_address (addr); + actual = fs_read (unit, k->fd, realpt, size); + + if (actual == 0) { + PUT_PCK_RES1 (packet, 0); + PUT_PCK_RES2 (packet, 0); + } else if (actual < 0) { + PUT_PCK_RES1 (packet, 0); + PUT_PCK_RES2 (packet, dos_errno ()); + } else { + PUT_PCK_RES1 (packet, actual); + k->file_pos += actual; + } } else { - PUT_PCK_RES1 (packet, actual); - k->file_pos += actual; - } - } else { - uae_u8 *buf; - off_t old, filesize; - - write_log (L"unixfs warning: Bad pointer passed for read: %08x, size %d\n", addr, size); - /* ugh this is inefficient but easy */ + uae_u8 *buf; + off_t old, filesize; + + write_log (L"unixfs warning: Bad pointer passed for read: %08x, size %d\n", addr, size); + /* ugh this is inefficient but easy */ + + old = fs_lseek (unit, k->fd, 0, SEEK_CUR); + filesize = fs_lseek (unit, k->fd, 0, SEEK_END); + fs_lseek (unit, k->fd, old, SEEK_SET); + if (size > filesize) + size = filesize; + + buf = xmalloc (size); + if (!buf) { + PUT_PCK_RES1 (packet, -1); + PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE); + return; + } + actual = fs_read (unit, k->fd, buf, size); - old = fs_lseek (unit, k->fd, 0, SEEK_CUR); - filesize = fs_lseek (unit, k->fd, 0, SEEK_END); - fs_lseek (unit, k->fd, old, SEEK_SET); - if (size > filesize) - size = filesize; - - buf = xmalloc (size); - if (!buf) { - PUT_PCK_RES1 (packet, -1); - PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE); - return; - } - actual = fs_read (unit, k->fd, buf, size); - - if (actual < 0) { - PUT_PCK_RES1 (packet, 0); - PUT_PCK_RES2 (packet, dos_errno ()); - } else { - int i; - PUT_PCK_RES1 (packet, actual); - for (i = 0; i < actual; i++) - put_byte (addr + i, buf[i]); - k->file_pos += actual; + if (actual < 0) { + PUT_PCK_RES1 (packet, 0); + PUT_PCK_RES2 (packet, dos_errno ()); + } else { + int i; + PUT_PCK_RES1 (packet, actual); + for (i = 0; i < actual; i++) + put_byte (addr + i, buf[i]); + k->file_pos += actual; + } + xfree (buf); } - xfree (buf); - } - TRACE((L"=%d\n", actual)); + TRACE((L"=%d\n", actual)); } static void -action_write (Unit *unit, dpacket packet) + action_write (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); - uaecptr addr = GET_PCK_ARG2 (packet); - long size = GET_PCK_ARG3 (packet); - long actual; - TCHAR *buf; - int i; + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); + uaecptr addr = GET_PCK_ARG2 (packet); + long size = GET_PCK_ARG3 (packet); + long actual; + TCHAR *buf; + int i; - if (k == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - /* PUT_PCK_RES2 (packet, EINVAL); */ - return; - } + if (k == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + /* PUT_PCK_RES2 (packet, EINVAL); */ + return; + } - gui_hd_led (unit->unit, 2); - TRACE((L"ACTION_WRITE(%s,0x%lx,%ld)\n", k->aino->nname, addr, size)); + gui_hd_led (unit->unit, 2); + TRACE((L"ACTION_WRITE(%s,0x%lx,%ld)\n", k->aino->nname, addr, size)); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - if (valid_address (addr, size)) { - uae_u8 *realpt = get_real_address (addr); - actual = my_write (k->fd, realpt, size); + if (valid_address (addr, size)) { + uae_u8 *realpt = get_real_address (addr); + actual = my_write (k->fd, realpt, size); - } else { + } else { - write_log (L"unixfs warning: Bad pointer passed for write: %08x, size %d\n", addr, size); - /* ugh this is inefficient but easy */ - buf = (TCHAR *)malloc(size); - if (!buf) { - PUT_PCK_RES1 (packet, -1); - PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE); - return; - } + write_log (L"unixfs warning: Bad pointer passed for write: %08x, size %d\n", addr, size); + /* ugh this is inefficient but easy */ + buf = (TCHAR *)malloc(size); + if (!buf) { + PUT_PCK_RES1 (packet, -1); + PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE); + return; + } - for (i = 0; i < size; i++) - buf[i] = get_byte (addr + i); + for (i = 0; i < size; i++) + buf[i] = get_byte (addr + i); - actual = my_write (k->fd, buf, size); - xfree (buf); - } + actual = my_write (k->fd, buf, size); + xfree (buf); + } - TRACE((L"=%d\n", actual)); - PUT_PCK_RES1 (packet, actual); - if (actual != size) - PUT_PCK_RES2 (packet, dos_errno ()); - if (actual >= 0) - k->file_pos += actual; + TRACE((L"=%d\n", actual)); + PUT_PCK_RES1 (packet, actual); + if (actual != size) + PUT_PCK_RES2 (packet, dos_errno ()); + if (actual >= 0) + k->file_pos += actual; - k->notifyactive = 1; + k->notifyactive = 1; } static void -action_seek (Unit *unit, dpacket packet) -{ - Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); - long pos = (uae_s32)GET_PCK_ARG2 (packet); - long mode = (uae_s32)GET_PCK_ARG3 (packet); - uae_s64 res; - uae_s64 old; - int whence = SEEK_CUR; - - if (k == 0) { - PUT_PCK_RES1 (packet, -1); - PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); - return; - } - - if (mode > 0) - whence = SEEK_END; - if (mode < 0) - whence = SEEK_SET; - - TRACE((L"ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode)); - gui_hd_led (unit->unit, 1); - - old = fs_lseek (unit, k->fd, 0, SEEK_CUR); - { - uae_s64 temppos; - uae_s64 filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); - fs_lseek (unit, k->fd, old, SEEK_SET); - - if (whence == SEEK_CUR) - temppos = old + pos; - if (whence == SEEK_SET) - temppos = pos; - if (whence == SEEK_END) - temppos = filesize + pos; - if (filesize < temppos) { - res = -1; - PUT_PCK_RES1 (packet, res); - PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR); - return; - } - } - res = fs_lseek64 (unit, k->fd, pos, whence); - - if (-1 == res || old > MAXFILESIZE32) { - PUT_PCK_RES1 (packet, -1); - PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR); - fs_lseek64 (unit, k->fd, old, SEEK_SET); - res = old; - } else { - PUT_PCK_RES1 (packet, old); - } - k->file_pos = res; + action_seek (Unit *unit, dpacket packet) +{ + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); + long pos = (uae_s32)GET_PCK_ARG2 (packet); + long mode = (uae_s32)GET_PCK_ARG3 (packet); + uae_s64 res; + uae_s64 old; + int whence = SEEK_CUR; + + if (k == 0) { + PUT_PCK_RES1 (packet, -1); + PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); + return; + } + + if (mode > 0) + whence = SEEK_END; + if (mode < 0) + whence = SEEK_SET; + + TRACE((L"ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode)); + gui_hd_led (unit->unit, 1); + + old = fs_lseek (unit, k->fd, 0, SEEK_CUR); + { + uae_s64 temppos; + uae_s64 filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); + fs_lseek (unit, k->fd, old, SEEK_SET); + + if (whence == SEEK_CUR) + temppos = old + pos; + if (whence == SEEK_SET) + temppos = pos; + if (whence == SEEK_END) + temppos = filesize + pos; + if (filesize < temppos) { + res = -1; + PUT_PCK_RES1 (packet, res); + PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR); + return; + } + } + res = fs_lseek64 (unit, k->fd, pos, whence); + + if (-1 == res || old > MAXFILESIZE32) { + PUT_PCK_RES1 (packet, -1); + PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR); + fs_lseek64 (unit, k->fd, old, SEEK_SET); + res = old; + } else { + PUT_PCK_RES1 (packet, old); + } + k->file_pos = res; } static void -action_set_protect (Unit *unit, dpacket packet) + action_set_protect (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG2 (packet) << 2; - uaecptr name = GET_PCK_ARG3 (packet) << 2; - uae_u32 mask = GET_PCK_ARG4 (packet); - a_inode *a; - uae_u32 err; + uaecptr lock = GET_PCK_ARG2 (packet) << 2; + uaecptr name = GET_PCK_ARG3 (packet) << 2; + uae_u32 mask = GET_PCK_ARG4 (packet); + a_inode *a; + uae_u32 err; - TRACE((L"ACTION_SET_PROTECT(0x%lx,\"%s\",0x%lx)\n", lock, bstr (unit, name), mask)); + TRACE((L"ACTION_SET_PROTECT(0x%lx,\"%s\",0x%lx)\n", lock, bstr (unit, name), mask)); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - a = find_aino (unit, lock, bstr (unit, name), &err); - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } + a = find_aino (unit, lock, bstr (unit, name), &err); + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + return; + } - a->amigaos_mode = mask; - if (!fsdb_cando (unit)) - a->amigaos_mode = fsdb_mode_supported (a); - err = fsdb_set_file_attrs (a); - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - } else { - PUT_PCK_RES1 (packet, DOS_TRUE); - } - notify_check (unit, a); - gui_hd_led (unit->unit, 2); + a->amigaos_mode = mask; + if (!fsdb_cando (unit)) + a->amigaos_mode = fsdb_mode_supported (a); + err = fsdb_set_file_attrs (a); + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + } else { + PUT_PCK_RES1 (packet, DOS_TRUE); + } + notify_check (unit, a); + gui_hd_led (unit->unit, 2); } static void action_set_comment (Unit * unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG2 (packet) << 2; - uaecptr name = GET_PCK_ARG3 (packet) << 2; - uaecptr comment = GET_PCK_ARG4 (packet) << 2; - TCHAR *commented = NULL; - a_inode *a; - uae_u32 err; + uaecptr lock = GET_PCK_ARG2 (packet) << 2; + uaecptr name = GET_PCK_ARG3 (packet) << 2; + uaecptr comment = GET_PCK_ARG4 (packet) << 2; + TCHAR *commented = NULL; + a_inode *a; + uae_u32 err; - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } - - if (fsdb_cando (unit)) { - commented = bstr (unit, comment); - if (_tcslen (commented) > 80) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_COMMENT_TOO_BIG); - return; - } - if (_tcslen (commented) > 0) { - TCHAR *p = commented; - commented = xmalloc (81 * sizeof (TCHAR)); - _tcsncpy (commented, p, 80); - commented[80] = 0; - } else { - commented = NULL; + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; } - } - TRACE ((L"ACTION_SET_COMMENT(0x%lx,\"%s\")\n", lock, commented)); - a = find_aino (unit, lock, bstr (unit, name), &err); - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); + if (fsdb_cando (unit)) { + commented = bstr (unit, comment); + if (_tcslen (commented) > 80) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_COMMENT_TOO_BIG); + return; + } + if (_tcslen (commented) > 0) { + TCHAR *p = commented; + commented = xmalloc (81 * sizeof (TCHAR)); + _tcsncpy (commented, p, 80); + commented[80] = 0; + } else { + commented = NULL; + } + } + TRACE ((L"ACTION_SET_COMMENT(0x%lx,\"%s\")\n", lock, commented)); - maybe_free_and_out: - if (commented) - xfree (commented); - return; - } - PUT_PCK_RES1 (packet, DOS_TRUE); - PUT_PCK_RES2 (packet, 0); - if (a->comment == 0 && commented == 0) - goto maybe_free_and_out; - if (a->comment != 0 && commented != 0 && _tcscmp (a->comment, commented) == 0) - goto maybe_free_and_out; - if (a->comment) - xfree (a->comment); - a->comment = commented; - fsdb_set_file_attrs (a); - notify_check (unit, a); - gui_hd_led (unit->unit, 2); + a = find_aino (unit, lock, bstr (unit, name), &err); + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + +maybe_free_and_out: + if (commented) + xfree (commented); + return; + } + PUT_PCK_RES1 (packet, DOS_TRUE); + PUT_PCK_RES2 (packet, 0); + if (a->comment == 0 && commented == 0) + goto maybe_free_and_out; + if (a->comment != 0 && commented != 0 && _tcscmp (a->comment, commented) == 0) + goto maybe_free_and_out; + if (a->comment) + xfree (a->comment); + a->comment = commented; + fsdb_set_file_attrs (a); + notify_check (unit, a); + gui_hd_led (unit->unit, 2); } static void -action_same_lock (Unit *unit, dpacket packet) + action_same_lock (Unit *unit, dpacket packet) { - uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; - uaecptr lock2 = GET_PCK_ARG2 (packet) << 2; + uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; + uaecptr lock2 = GET_PCK_ARG2 (packet) << 2; - TRACE((L"ACTION_SAME_LOCK(0x%lx,0x%lx)\n", lock1, lock2)); - DUMPLOCK(unit, lock1); DUMPLOCK(unit, lock2); + TRACE((L"ACTION_SAME_LOCK(0x%lx,0x%lx)\n", lock1, lock2)); + DUMPLOCK(unit, lock1); DUMPLOCK(unit, lock2); - if (!lock1 || !lock2) { - PUT_PCK_RES1 (packet, lock1 == lock2 ? DOS_TRUE : DOS_FALSE); - } else { - PUT_PCK_RES1 (packet, get_long (lock1 + 4) == get_long (lock2 + 4) ? DOS_TRUE : DOS_FALSE); - } + if (!lock1 || !lock2) { + PUT_PCK_RES1 (packet, lock1 == lock2 ? DOS_TRUE : DOS_FALSE); + } else { + PUT_PCK_RES1 (packet, get_long (lock1 + 4) == get_long (lock2 + 4) ? DOS_TRUE : DOS_FALSE); + } } static void -action_change_mode (Unit *unit, dpacket packet) + action_change_mode (Unit *unit, dpacket packet) { #define CHANGE_LOCK 0 #define CHANGE_FH 1 - /* will be CHANGE_FH or CHANGE_LOCK value */ - long type = GET_PCK_ARG1 (packet); - /* either a file-handle or lock */ - uaecptr object = GET_PCK_ARG2 (packet) << 2; - /* will be EXCLUSIVE_LOCK/SHARED_LOCK if CHANGE_LOCK, - * or MODE_OLDFILE/MODE_NEWFILE/MODE_READWRITE if CHANGE_FH * - * Above is wrong, it is always *_LOCK. TW. */ - long mode = GET_PCK_ARG3 (packet); - unsigned long uniq; - a_inode *a = NULL, *olda = NULL; - uae_u32 err = 0; - TRACE((L"ACTION_CHANGE_MODE(0x%lx,%d,%d)\n", object, type, mode)); - - if (! object || (type != CHANGE_FH && type != CHANGE_LOCK)) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); - return; - } + /* will be CHANGE_FH or CHANGE_LOCK value */ + long type = GET_PCK_ARG1 (packet); + /* either a file-handle or lock */ + uaecptr object = GET_PCK_ARG2 (packet) << 2; + /* will be EXCLUSIVE_LOCK/SHARED_LOCK if CHANGE_LOCK, + * or MODE_OLDFILE/MODE_NEWFILE/MODE_READWRITE if CHANGE_FH * + * Above is wrong, it is always *_LOCK. TW. */ + long mode = GET_PCK_ARG3 (packet); + unsigned long uniq; + a_inode *a = NULL, *olda = NULL; + uae_u32 err = 0; + TRACE((L"ACTION_CHANGE_MODE(0x%lx,%d,%d)\n", object, type, mode)); + + if (! object || (type != CHANGE_FH && type != CHANGE_LOCK)) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); + return; + } - if (type == CHANGE_LOCK) { - uniq = get_long (object + 4); - } else { - Key *k = lookup_key (unit, get_long (object + 36)); - if (!k) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return; - } - uniq = k->aino->uniq; - } - a = lookup_aino (unit, uniq); - - if (! a) { - err = ERROR_INVALID_LOCK; - } else { - if (mode == -1) { - if (a->shlock > 1) { - err = ERROR_OBJECT_IN_USE; - } else { - a->shlock = 0; - a->elock = 1; - } - } else { /* Must be SHARED_LOCK == -2 */ - a->elock = 0; - a->shlock++; + if (type == CHANGE_LOCK) { + uniq = get_long (object + 4); + } else { + Key *k = lookup_key (unit, get_long (object + 36)); + if (!k) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return; + } + uniq = k->aino->uniq; } - } + a = lookup_aino (unit, uniq); - if (err) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } else { - de_recycle_aino (unit, a); - PUT_PCK_RES1 (packet, DOS_TRUE); - } + if (! a) { + err = ERROR_INVALID_LOCK; + } else { + if (mode == -1) { + if (a->shlock > 1) { + err = ERROR_OBJECT_IN_USE; + } else { + a->shlock = 0; + a->elock = 1; + } + } else { /* Must be SHARED_LOCK == -2 */ + a->elock = 0; + a->shlock++; + } + } + + if (err) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + return; + } else { + de_recycle_aino (unit, a); + PUT_PCK_RES1 (packet, DOS_TRUE); + } } static void -action_parent_common (Unit *unit, dpacket packet, unsigned long uniq) + action_parent_common (Unit *unit, dpacket packet, unsigned long uniq) { - a_inode *olda = lookup_aino (unit, uniq); - if (olda == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); - return; - } + a_inode *olda = lookup_aino (unit, uniq); + if (olda == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); + return; + } - if (olda->parent == 0) { - PUT_PCK_RES1 (packet, 0); - PUT_PCK_RES2 (packet, 0); - return; - } - if (olda->parent->elock) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); - return; - } - olda->parent->shlock++; - de_recycle_aino (unit, olda->parent); - PUT_PCK_RES1 (packet, make_lock (unit, olda->parent->uniq, -2) >> 2); + if (olda->parent == 0) { + PUT_PCK_RES1 (packet, 0); + PUT_PCK_RES2 (packet, 0); + return; + } + if (olda->parent->elock) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); + return; + } + olda->parent->shlock++; + de_recycle_aino (unit, olda->parent); + PUT_PCK_RES1 (packet, make_lock (unit, olda->parent->uniq, -2) >> 2); } static void -action_parent_fh (Unit *unit, dpacket packet) + action_parent_fh (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); - if (!k) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return; - } - action_parent_common (unit, packet, k->aino->uniq); + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); + if (!k) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return; + } + action_parent_common (unit, packet, k->aino->uniq); } static void -action_parent (Unit *unit, dpacket packet) + action_parent (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr lock = GET_PCK_ARG1 (packet) << 2; - TRACE((L"ACTION_PARENT(0x%lx)\n",lock)); + TRACE((L"ACTION_PARENT(0x%lx)\n",lock)); - if (!lock) { - PUT_PCK_RES1 (packet, 0); - PUT_PCK_RES2 (packet, 0); - } else { - action_parent_common (unit, packet, get_long (lock + 4)); - } - TRACE((L"=%x %d\n", GET_PCK_RES1 (packet), GET_PCK_RES2 (packet))); + if (!lock) { + PUT_PCK_RES1 (packet, 0); + PUT_PCK_RES2 (packet, 0); + } else { + action_parent_common (unit, packet, get_long (lock + 4)); + } + TRACE((L"=%x %d\n", GET_PCK_RES1 (packet), GET_PCK_RES2 (packet))); } static void -action_create_dir (Unit *unit, dpacket packet) + action_create_dir (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr name = GET_PCK_ARG2 (packet) << 2; - a_inode *aino; - uae_u32 err; + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr name = GET_PCK_ARG2 (packet) << 2; + a_inode *aino; + uae_u32 err; - TRACE((L"ACTION_CREATE_DIR(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE((L"ACTION_CREATE_DIR(0x%lx,\"%s\")\n", lock, bstr (unit, name))); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - aino = find_aino (unit, lock, bstr (unit, name), &err); - if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } - if (err == 0) { - /* Object exists. */ - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_EXISTS); - return; - } - /* Object does not exist. aino points to containing directory. */ - aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 1); - if (aino == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ - return; - } + aino = find_aino (unit, lock, bstr (unit, name), &err); + if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + return; + } + if (err == 0) { + /* Object exists. */ + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_EXISTS); + return; + } + /* Object does not exist. aino points to containing directory. */ + aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 1); + if (aino == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ + return; + } - if (my_mkdir (aino->nname) == -1) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - aino->shlock = 1; - fsdb_set_file_attrs (aino); - de_recycle_aino (unit, aino); - notify_check (unit, aino); - updatedirtime (aino, 0); - PUT_PCK_RES1 (packet, make_lock (unit, aino->uniq, -2) >> 2); - gui_hd_led (unit->unit, 2); + if (my_mkdir (aino->nname) == -1) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + aino->shlock = 1; + fsdb_set_file_attrs (aino); + de_recycle_aino (unit, aino); + notify_check (unit, aino); + updatedirtime (aino, 0); + PUT_PCK_RES1 (packet, make_lock (unit, aino->uniq, -2) >> 2); + gui_hd_led (unit->unit, 2); } static void -action_examine_fh (Unit *unit, dpacket packet) + action_examine_fh (Unit *unit, dpacket packet) { - Key *k; - a_inode *aino = 0; - uaecptr info = GET_PCK_ARG2 (packet) << 2; + Key *k; + a_inode *aino = 0; + uaecptr info = GET_PCK_ARG2 (packet) << 2; - TRACE((L"ACTION_EXAMINE_FH(0x%lx,0x%lx)\n", - GET_PCK_ARG1 (packet), GET_PCK_ARG2 (packet) )); + TRACE((L"ACTION_EXAMINE_FH(0x%lx,0x%lx)\n", + GET_PCK_ARG1 (packet), GET_PCK_ARG2 (packet) )); - k = lookup_key (unit, GET_PCK_ARG1 (packet)); - if (k != 0) - aino = k->aino; - if (aino == 0) - aino = &unit->rootnode; + k = lookup_key (unit, GET_PCK_ARG1 (packet)); + if (k != 0) + aino = k->aino; + if (aino == 0) + aino = &unit->rootnode; - get_fileinfo (unit, packet, info, aino); - if (aino->dir) - put_long (info, 0xFFFFFFFF); - else - put_long (info, 0); + get_fileinfo (unit, packet, info, aino); + if (aino->dir) + put_long (info, 0xFFFFFFFF); + else + put_long (info, 0); } /* For a nice example of just how contradictory documentation can be, see the - * Autodoc for DOS:SetFileSize and the Packets.txt description of this packet... - * This implementation tries to mimic the behaviour of the Kick 3.1 ramdisk - * (which seems to match the Autodoc description). */ +* Autodoc for DOS:SetFileSize and the Packets.txt description of this packet... +* This implementation tries to mimic the behaviour of the Kick 3.1 ramdisk +* (which seems to match the Autodoc description). */ static void -action_set_file_size (Unit *unit, dpacket packet) + action_set_file_size (Unit *unit, dpacket packet) { - Key *k, *k1; - off_t offset = GET_PCK_ARG2 (packet); - long mode = (uae_s32)GET_PCK_ARG3 (packet); - int whence = SEEK_CUR; + Key *k, *k1; + off_t offset = GET_PCK_ARG2 (packet); + long mode = (uae_s32)GET_PCK_ARG3 (packet); + int whence = SEEK_CUR; - if (mode > 0) - whence = SEEK_END; - if (mode < 0) - whence = SEEK_SET; + if (mode > 0) + whence = SEEK_END; + if (mode < 0) + whence = SEEK_SET; - TRACE((L"ACTION_SET_FILE_SIZE(0x%lx, %d, 0x%x)\n", GET_PCK_ARG1 (packet), offset, mode)); + TRACE((L"ACTION_SET_FILE_SIZE(0x%lx, %d, 0x%x)\n", GET_PCK_ARG1 (packet), offset, mode)); - k = lookup_key (unit, GET_PCK_ARG1 (packet)); - if (k == 0) { - PUT_PCK_RES1 (packet, DOS_TRUE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return; - } - - gui_hd_led (unit->unit, 1); - k->notifyactive = 1; - /* If any open files have file pointers beyond this size, truncate only - * so far that these pointers do not become invalid. */ - for (k1 = unit->keys; k1; k1 = k1->next) { - if (k != k1 && k->aino == k1->aino) { - if (k1->file_pos > offset) - offset = (off_t)k1->file_pos; - } - } - - /* Write one then truncate: that should give the right size in all cases. */ - offset = fs_lseek (unit, k->fd, offset, whence); - my_write (k->fd, /* whatever */(uae_u8*)&k1, 1); - if (k->file_pos > offset) - k->file_pos = offset; - fs_lseek (unit, k->fd, (off_t)k->file_pos, SEEK_SET); - - /* Brian: no bug here; the file _must_ be one byte too large after writing - The write is supposed to guarantee that the file can't be smaller than - the requested size, the truncate guarantees that it can't be larger. - If we were to write one byte earlier we'd clobber file data. */ - if (my_truncate (k->aino->nname, offset) == -1) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } + k = lookup_key (unit, GET_PCK_ARG1 (packet)); + if (k == 0) { + PUT_PCK_RES1 (packet, DOS_TRUE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return; + } - PUT_PCK_RES1 (packet, offset); - PUT_PCK_RES2 (packet, 0); + gui_hd_led (unit->unit, 1); + k->notifyactive = 1; + /* If any open files have file pointers beyond this size, truncate only + * so far that these pointers do not become invalid. */ + for (k1 = unit->keys; k1; k1 = k1->next) { + if (k != k1 && k->aino == k1->aino) { + if (k1->file_pos > offset) + offset = (off_t)k1->file_pos; + } + } + + /* Write one then truncate: that should give the right size in all cases. */ + offset = fs_lseek (unit, k->fd, offset, whence); + my_write (k->fd, /* whatever */(uae_u8*)&k1, 1); + if (k->file_pos > offset) + k->file_pos = offset; + fs_lseek (unit, k->fd, (off_t)k->file_pos, SEEK_SET); + + /* Brian: no bug here; the file _must_ be one byte too large after writing + The write is supposed to guarantee that the file can't be smaller than + the requested size, the truncate guarantees that it can't be larger. + If we were to write one byte earlier we'd clobber file data. */ + if (my_truncate (k->aino->nname, offset) == -1) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + + PUT_PCK_RES1 (packet, offset); + PUT_PCK_RES2 (packet, 0); } static int relock_do(Unit *unit, a_inode *a1) { - Key *k1, *knext; - int wehavekeys = 0; - - for (k1 = unit->keys; k1; k1 = knext) { - knext = k1->next; - if (k1->aino == a1 && k1->fd) { - wehavekeys++; - fs_close (unit, k1->fd); - write_log (L"handle %p freed\n", k1->fd); + Key *k1, *knext; + int wehavekeys = 0; + + for (k1 = unit->keys; k1; k1 = knext) { + knext = k1->next; + if (k1->aino == a1 && k1->fd) { + wehavekeys++; + fs_close (unit, k1->fd); + write_log (L"handle %p freed\n", k1->fd); + } } - } - return wehavekeys; + return wehavekeys; } static void relock_re (Unit *unit, a_inode *a1, a_inode *a2, int failed) { - Key *k1, *knext; - - for (k1 = unit->keys; k1; k1 = knext) { - knext = k1->next; - if (k1->aino == a1 && k1->fd) { - int mode = (k1->dosmode & A_FIBF_READ) == 0 ? O_WRONLY : (k1->dosmode & A_FIBF_WRITE) == 0 ? O_RDONLY : O_RDWR; - mode |= O_BINARY; - if (failed) { - /* rename still failed, restore fd */ - k1->fd = fs_open (unit, a1->nname, mode); - write_log (L"restoring old handle '%s' %d\n", a1->nname, k1->dosmode); - } else { - /* transfer fd to new name */ - if (a2) { - k1->aino = a2; - k1->fd = fs_open (unit, a2->nname, mode); - write_log (L"restoring new handle '%s' %d\n", a2->nname, k1->dosmode); - } else { - write_log (L"no new handle, deleting old lock(s).\n"); + Key *k1, *knext; + + for (k1 = unit->keys; k1; k1 = knext) { + knext = k1->next; + if (k1->aino == a1 && k1->fd) { + int mode = (k1->dosmode & A_FIBF_READ) == 0 ? O_WRONLY : (k1->dosmode & A_FIBF_WRITE) == 0 ? O_RDONLY : O_RDWR; + mode |= O_BINARY; + if (failed) { + /* rename still failed, restore fd */ + k1->fd = fs_open (unit, a1->nname, mode); + write_log (L"restoring old handle '%s' %d\n", a1->nname, k1->dosmode); + } else { + /* transfer fd to new name */ + if (a2) { + k1->aino = a2; + k1->fd = fs_open (unit, a2->nname, mode); + write_log (L"restoring new handle '%s' %d\n", a2->nname, k1->dosmode); + } else { + write_log (L"no new handle, deleting old lock(s).\n"); + } + } + if (k1->fd == NULL) { + write_log (L"relocking failed '%s' -> '%s'\n", a1->nname, a2->nname); + free_key (unit, k1); + } else { + fs_lseek64 (unit, k1->fd, k1->file_pos, SEEK_SET); + } } - } - if (k1->fd == NULL) { - write_log (L"relocking failed '%s' -> '%s'\n", a1->nname, a2->nname); - free_key (unit, k1); - } else { - fs_lseek64 (unit, k1->fd, k1->file_pos, SEEK_SET); - } } - } } static void -action_delete_object (Unit *unit, dpacket packet) + action_delete_object (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG1 (packet) << 2; - uaecptr name = GET_PCK_ARG2 (packet) << 2; - a_inode *a; - uae_u32 err; + uaecptr lock = GET_PCK_ARG1 (packet) << 2; + uaecptr name = GET_PCK_ARG2 (packet) << 2; + a_inode *a; + uae_u32 err; - TRACE((L"ACTION_DELETE_OBJECT(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE((L"ACTION_DELETE_OBJECT(0x%lx,\"%s\")\n", lock, bstr (unit, name))); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - a = find_aino (unit, lock, bstr (unit, name), &err); + a = find_aino (unit, lock, bstr (unit, name), &err); - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - return; - } - if (a->amigaos_mode & A_FIBF_DELETE) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED); - return; - } - if (a->shlock > 0 || a->elock) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); - return; - } - if (a->dir) { - /* This should take care of removing the fsdb if no files remain. */ - fsdb_dir_writeback (a); - if (my_rmdir (a->nname) == -1) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - } else { - if (my_unlink (a->nname) == -1) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - } - notify_check (unit, a); - updatedirtime (a, 1); - if (a->child != 0) { - write_log (L"Serious error in action_delete_object.\n"); - a->deleted = 1; - } else { - delete_aino (unit, a); - } - PUT_PCK_RES1 (packet, DOS_TRUE); - gui_hd_led (unit->unit, 2); + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + return; + } + if (a->amigaos_mode & A_FIBF_DELETE) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED); + return; + } + if (a->shlock > 0 || a->elock) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); + return; + } + if (a->dir) { + /* This should take care of removing the fsdb if no files remain. */ + fsdb_dir_writeback (a); + if (my_rmdir (a->nname) == -1) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + } else { + if (my_unlink (a->nname) == -1) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + } + notify_check (unit, a); + updatedirtime (a, 1); + if (a->child != 0) { + write_log (L"Serious error in action_delete_object.\n"); + a->deleted = 1; + } else { + delete_aino (unit, a); + } + PUT_PCK_RES1 (packet, DOS_TRUE); + gui_hd_led (unit->unit, 2); } static void -action_set_date (Unit *unit, dpacket packet) + action_set_date (Unit *unit, dpacket packet) { - uaecptr lock = GET_PCK_ARG2 (packet) << 2; - uaecptr name = GET_PCK_ARG3 (packet) << 2; - uaecptr date = GET_PCK_ARG4 (packet); - a_inode *a; - struct utimbuf ut; - uae_u32 err; + uaecptr lock = GET_PCK_ARG2 (packet) << 2; + uaecptr name = GET_PCK_ARG3 (packet) << 2; + uaecptr date = GET_PCK_ARG4 (packet); + a_inode *a; + struct utimbuf ut; + uae_u32 err; - TRACE((L"ACTION_SET_DATE(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE((L"ACTION_SET_DATE(0x%lx,\"%s\")\n", lock, bstr (unit, name))); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } - - ut.actime = ut.modtime = put_time (get_long (date), get_long (date + 4), - get_long (date + 8)); - a = find_aino (unit, lock, bstr (unit, name), &err); - if (err == 0 && utime (a->nname, &ut) == -1) - err = dos_errno (); - if (err != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err); - } else { - notify_check (unit, a); - PUT_PCK_RES1 (packet, DOS_TRUE); - } - gui_hd_led (unit->unit, 2); + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } + + ut.actime = ut.modtime = put_time (get_long (date), get_long (date + 4), + get_long (date + 8)); + a = find_aino (unit, lock, bstr (unit, name), &err); + if (err == 0 && utime (a->nname, &ut) == -1) + err = dos_errno (); + if (err != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err); + } else { + notify_check (unit, a); + PUT_PCK_RES1 (packet, DOS_TRUE); + } + gui_hd_led (unit->unit, 2); } static void -action_rename_object (Unit *unit, dpacket packet) -{ - uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; - uaecptr name1 = GET_PCK_ARG2 (packet) << 2; - uaecptr lock2 = GET_PCK_ARG3 (packet) << 2; - uaecptr name2 = GET_PCK_ARG4 (packet) << 2; - a_inode *a1, *a2; - uae_u32 err1, err2; - Key *k1, *knext; - int wehavekeys = 0; + action_rename_object (Unit *unit, dpacket packet) +{ + uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; + uaecptr name1 = GET_PCK_ARG2 (packet) << 2; + uaecptr lock2 = GET_PCK_ARG3 (packet) << 2; + uaecptr name2 = GET_PCK_ARG4 (packet) << 2; + a_inode *a1, *a2; + uae_u32 err1, err2; + Key *k1, *knext; + int wehavekeys = 0; - TRACE((L"ACTION_RENAME_OBJECT(0x%lx,\"%s\",", lock1, bstr (unit, name1))); - TRACE((L"0x%lx,\"%s\")\n", lock2, bstr (unit, name2))); + TRACE((L"ACTION_RENAME_OBJECT(0x%lx,\"%s\",", lock1, bstr (unit, name1))); + TRACE((L"0x%lx,\"%s\")\n", lock2, bstr (unit, name2))); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - a1 = find_aino (unit, lock1, bstr (unit, name1), &err1); - if (err1 != 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err1); - return; - } - - /* rename always fails if file is open for writing */ - for (k1 = unit->keys; k1; k1 = knext) { - knext = k1->next; - if (k1->aino == a1 && k1->fd && k1->createmode == 2) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); - return; - } - } - - /* See whether the other name already exists in the filesystem. */ - a2 = find_aino (unit, lock2, bstr (unit, name2), &err2); - - if (a2 == a1) { - /* Renaming to the same name, but possibly different case. */ - if (_tcscmp (a1->aname, bstr_cut (unit, name2)) == 0) { - /* Exact match -> do nothing. */ - notify_check (unit, a1); - updatedirtime (a1, 1); - PUT_PCK_RES1 (packet, DOS_TRUE); - return; - } - a2 = a2->parent; - } else if (a2 == 0 || err2 != ERROR_OBJECT_NOT_AROUND) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, err2 == 0 ? ERROR_OBJECT_EXISTS : err2); - return; - } + a1 = find_aino (unit, lock1, bstr (unit, name1), &err1); + if (err1 != 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err1); + return; + } - a2 = create_child_aino (unit, a2, bstr_cut (unit, name2), a1->dir); - if (a2 == 0) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ - return; - } + /* rename always fails if file is open for writing */ + for (k1 = unit->keys; k1; k1 = knext) { + knext = k1->next; + if (k1->aino == a1 && k1->fd && k1->createmode == 2) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE); + return; + } + } - if (-1 == my_rename (a1->nname, a2->nname)) { - int ret = -1; - /* maybe we have open file handles that caused failure? */ - write_log (L"rename '%s' -> '%s' failed, trying relocking..\n", a1->nname, a2->nname); - wehavekeys = relock_do (unit, a1); - /* try again... */ - ret = my_rename (a1->nname, a2->nname); - /* restore locks */ - relock_re (unit, a1, a2, ret == -1 ? 1 : 0); - if (ret == -1) { - delete_aino (unit, a2); - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, dos_errno ()); - return; - } - } - - notify_check (unit, a1); - notify_check (unit, a2); - a2->comment = a1->comment; - a1->comment = 0; - a2->amigaos_mode = a1->amigaos_mode; - a2->uniq = a1->uniq; - a2->elock = a1->elock; - a2->shlock = a1->shlock; - a2->has_dbentry = a1->has_dbentry; - a2->db_offset = a1->db_offset; - a2->dirty = 0; - move_exkeys (unit, a1, a2); - move_aino_children (unit, a1, a2); - delete_aino (unit, a1); - a2->dirty = 1; - if (a2->parent) - fsdb_dir_writeback (a2->parent); - updatedirtime (a2, 1); - fsdb_set_file_attrs (a2); - if (a2->elock > 0 || a2->shlock > 0 || wehavekeys > 0) - de_recycle_aino (unit, a2); - PUT_PCK_RES1 (packet, DOS_TRUE); - gui_hd_led (unit->unit, 2); + /* See whether the other name already exists in the filesystem. */ + a2 = find_aino (unit, lock2, bstr (unit, name2), &err2); + + if (a2 == a1) { + /* Renaming to the same name, but possibly different case. */ + if (_tcscmp (a1->aname, bstr_cut (unit, name2)) == 0) { + /* Exact match -> do nothing. */ + notify_check (unit, a1); + updatedirtime (a1, 1); + PUT_PCK_RES1 (packet, DOS_TRUE); + return; + } + a2 = a2->parent; + } else if (a2 == 0 || err2 != ERROR_OBJECT_NOT_AROUND) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, err2 == 0 ? ERROR_OBJECT_EXISTS : err2); + return; + } + + a2 = create_child_aino (unit, a2, bstr_cut (unit, name2), a1->dir); + if (a2 == 0) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */ + return; + } + + if (-1 == my_rename (a1->nname, a2->nname)) { + int ret = -1; + /* maybe we have open file handles that caused failure? */ + write_log (L"rename '%s' -> '%s' failed, trying relocking..\n", a1->nname, a2->nname); + wehavekeys = relock_do (unit, a1); + /* try again... */ + ret = my_rename (a1->nname, a2->nname); + /* restore locks */ + relock_re (unit, a1, a2, ret == -1 ? 1 : 0); + if (ret == -1) { + delete_aino (unit, a2); + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, dos_errno ()); + return; + } + } + + notify_check (unit, a1); + notify_check (unit, a2); + a2->comment = a1->comment; + a1->comment = 0; + a2->amigaos_mode = a1->amigaos_mode; + a2->uniq = a1->uniq; + a2->elock = a1->elock; + a2->shlock = a1->shlock; + a2->has_dbentry = a1->has_dbentry; + a2->db_offset = a1->db_offset; + a2->dirty = 0; + move_exkeys (unit, a1, a2); + move_aino_children (unit, a1, a2); + delete_aino (unit, a1); + a2->dirty = 1; + if (a2->parent) + fsdb_dir_writeback (a2->parent); + updatedirtime (a2, 1); + fsdb_set_file_attrs (a2); + if (a2->elock > 0 || a2->shlock > 0 || wehavekeys > 0) + de_recycle_aino (unit, a2); + PUT_PCK_RES1 (packet, DOS_TRUE); + gui_hd_led (unit->unit, 2); } static void -action_current_volume (Unit *unit, dpacket packet) + action_current_volume (Unit *unit, dpacket packet) { - if (filesys_isvolume(unit)) - PUT_PCK_RES1 (packet, unit->volume >> 2); - else - PUT_PCK_RES1 (packet, 0); + if (filesys_isvolume(unit)) + PUT_PCK_RES1 (packet, unit->volume >> 2); + else + PUT_PCK_RES1 (packet, 0); } static void -action_rename_disk (Unit *unit, dpacket packet) + action_rename_disk (Unit *unit, dpacket packet) { - uaecptr name = GET_PCK_ARG1 (packet) << 2; + uaecptr name = GET_PCK_ARG1 (packet) << 2; - TRACE((L"ACTION_RENAME_DISK(\"%s\")\n", bstr (unit, name))); + TRACE((L"ACTION_RENAME_DISK(\"%s\")\n", bstr (unit, name))); - if (unit->ui.readonly) { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); - return; - } + if (unit->ui.readonly) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); + return; + } - /* get volume name */ - xfree (unit->ui.volname); - unit->ui.volname = bstr1 (name); - set_volume_name (unit); + /* get volume name */ + xfree (unit->ui.volname); + unit->ui.volname = bstr1 (name); + set_volume_name (unit); - PUT_PCK_RES1 (packet, DOS_TRUE); + PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_is_filesystem (Unit *unit, dpacket packet) + action_is_filesystem (Unit *unit, dpacket packet) { - TRACE((L"ACTION_IS_FILESYSTEM()\n")); - PUT_PCK_RES1 (packet, DOS_TRUE); + TRACE((L"ACTION_IS_FILESYSTEM()\n")); + PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_flush (Unit *unit, dpacket packet) + action_flush (Unit *unit, dpacket packet) { - TRACE((L"ACTION_FLUSH()\n")); - PUT_PCK_RES1 (packet, DOS_TRUE); - flush_cache (unit, 0); + TRACE((L"ACTION_FLUSH()\n")); + PUT_PCK_RES1 (packet, DOS_TRUE); + flush_cache (unit, 0); } static void -action_more_cache (Unit *unit, dpacket packet) + action_more_cache (Unit *unit, dpacket packet) { - TRACE((L"ACTION_MORE_CACHE()\n")); - PUT_PCK_RES1 (packet, 50); /* bug but AmigaOS expects it */ - if (GET_PCK_ARG1 (packet) != 0) - flush_cache (unit, 0); + TRACE((L"ACTION_MORE_CACHE()\n")); + PUT_PCK_RES1 (packet, 50); /* bug but AmigaOS expects it */ + if (GET_PCK_ARG1 (packet) != 0) + flush_cache (unit, 0); } static void -action_inhibit (Unit *unit, dpacket packet) + action_inhibit (Unit *unit, dpacket packet) { - PUT_PCK_RES1 (packet, DOS_TRUE); - flush_cache (unit, 0); - unit->inhibited = GET_PCK_ARG1 (packet); - TRACE((L"ACTION_INHIBIT(%d:%d)\n", unit->unit, unit->inhibited)); + PUT_PCK_RES1 (packet, DOS_TRUE); + flush_cache (unit, 0); + unit->inhibited = GET_PCK_ARG1 (packet); + TRACE((L"ACTION_INHIBIT(%d:%d)\n", unit->unit, unit->inhibited)); } static void -action_write_protect (Unit *unit, dpacket packet) -{ - TRACE((L"ACTION_WRITE_PROTECT()\n")); - PUT_PCK_RES1 (packet, DOS_TRUE); - if (GET_PCK_ARG1 (packet)) { - if (!(unit->ui.readonly & 2)) { - unit->ui.readonly |= 2; - unit->lockkey = GET_PCK_ARG2 (packet); - } - } else { - if (unit->ui.readonly & 2) { - if (unit->lockkey == GET_PCK_ARG2 (packet) || unit->lockkey == 0) { - unit->ui.readonly &= ~2; - } else { - PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, 0); - } + action_write_protect (Unit *unit, dpacket packet) +{ + TRACE((L"ACTION_WRITE_PROTECT()\n")); + PUT_PCK_RES1 (packet, DOS_TRUE); + if (GET_PCK_ARG1 (packet)) { + if (!(unit->ui.readonly & 2)) { + unit->ui.readonly |= 2; + unit->lockkey = GET_PCK_ARG2 (packet); + } + } else { + if (unit->ui.readonly & 2) { + if (unit->lockkey == GET_PCK_ARG2 (packet) || unit->lockkey == 0) { + unit->ui.readonly &= ~2; + } else { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, 0); + } + } } - } } static void action_change_file_position64 (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); - uae_s64 pos = GET_PCK64_ARG2 (packet); - long mode = GET_PCK64_ARG3 (packet); - long whence = SEEK_CUR; - uae_s64 res, old; + Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); + uae_s64 pos = GET_PCK64_ARG2 (packet); + long mode = GET_PCK64_ARG3 (packet); + long whence = SEEK_CUR; + uae_s64 res, old; - PUT_PCK64_RES0 (packet, DP64_INIT); + PUT_PCK64_RES0 (packet, DP64_INIT); - if (k == 0) { - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); - return; - } - - if (mode > 0) - whence = SEEK_END; - if (mode < 0) - whence = SEEK_SET; - - TRACE((L"ACTION_CHANGE_FILE_POSITION64(%s,%I64d,%d)\n", k->aino->nname, pos, mode)); - gui_hd_led (unit->unit, 1); - - old = fs_lseek64 (unit, k->fd, 0, SEEK_CUR); - { - uae_s64 temppos; - uae_s64 filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); - fs_lseek64 (unit, k->fd, old, SEEK_SET); - - if (whence == SEEK_CUR) - temppos = old + pos; - if (whence == SEEK_SET) - temppos = pos; - if (whence == SEEK_END) - temppos = filesize + pos; - if (filesize < temppos) { - res = -1; - PUT_PCK64_RES1 (packet, res); - PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); - return; - } - } - res = fs_lseek64 (unit, k->fd, pos, whence); - - if (-1 == res) { - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); - } else { - PUT_PCK64_RES1 (packet, TRUE); - PUT_PCK64_RES2 (packet, 0); - k->file_pos = res; - } + if (k == 0) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); + return; + } + + if (mode > 0) + whence = SEEK_END; + if (mode < 0) + whence = SEEK_SET; + + TRACE((L"ACTION_CHANGE_FILE_POSITION64(%s,%I64d,%d)\n", k->aino->nname, pos, mode)); + gui_hd_led (unit->unit, 1); + + old = fs_lseek64 (unit, k->fd, 0, SEEK_CUR); + { + uae_s64 temppos; + uae_s64 filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); + fs_lseek64 (unit, k->fd, old, SEEK_SET); + + if (whence == SEEK_CUR) + temppos = old + pos; + if (whence == SEEK_SET) + temppos = pos; + if (whence == SEEK_END) + temppos = filesize + pos; + if (filesize < temppos) { + res = -1; + PUT_PCK64_RES1 (packet, res); + PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); + return; + } + } + res = fs_lseek64 (unit, k->fd, pos, whence); + + if (-1 == res) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); + } else { + PUT_PCK64_RES1 (packet, TRUE); + PUT_PCK64_RES2 (packet, 0); + k->file_pos = res; + } } static void action_get_file_position64 (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); + Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); - PUT_PCK64_RES0 (packet, DP64_INIT); + PUT_PCK64_RES0 (packet, DP64_INIT); - if (k == 0) { - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); - return; - } - TRACE((L"ACTION_GET_FILE_POSITION64(%s)\n", k->aino->nname)); - PUT_PCK64_RES1 (packet, k->file_pos); - PUT_PCK64_RES2 (packet, 0); + if (k == 0) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); + return; + } + TRACE((L"ACTION_GET_FILE_POSITION64(%s)\n", k->aino->nname)); + PUT_PCK64_RES1 (packet, k->file_pos); + PUT_PCK64_RES2 (packet, 0); } static void action_change_file_size64 (Unit *unit, dpacket packet) { - Key *k, *k1; - uae_s64 offset = GET_PCK64_ARG2 (packet); - long mode = (uae_s32)GET_PCK64_ARG3 (packet); - int whence = SEEK_CUR; + Key *k, *k1; + uae_s64 offset = GET_PCK64_ARG2 (packet); + long mode = (uae_s32)GET_PCK64_ARG3 (packet); + int whence = SEEK_CUR; - PUT_PCK64_RES0 (packet, DP64_INIT); + PUT_PCK64_RES0 (packet, DP64_INIT); - if (mode > 0) - whence = SEEK_END; - if (mode < 0) - whence = SEEK_SET; + if (mode > 0) + whence = SEEK_END; + if (mode < 0) + whence = SEEK_SET; - TRACE((L"ACTION_CHANGE_FILE_SIZE64(0x%lx, %I64d, 0x%x)\n", GET_PCK64_ARG1 (packet), offset, mode)); + TRACE((L"ACTION_CHANGE_FILE_SIZE64(0x%lx, %I64d, 0x%x)\n", GET_PCK64_ARG1 (packet), offset, mode)); - k = lookup_key (unit, GET_PCK64_ARG1 (packet)); - if (k == 0) { - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_OBJECT_NOT_AROUND); - return; - } - - gui_hd_led (unit->unit, 1); - k->notifyactive = 1; - /* If any open files have file pointers beyond this size, truncate only - * so far that these pointers do not become invalid. */ - for (k1 = unit->keys; k1; k1 = k1->next) { - if (k != k1 && k->aino == k1->aino) { - if (k1->file_pos > offset) - offset = k1->file_pos; - } - } - - /* Write one then truncate: that should give the right size in all cases. */ - offset = fs_lseek (unit, k->fd, offset, whence); - my_write (k->fd, /* whatever */(uae_u8*)&k1, 1); - if (k->file_pos > offset) - k->file_pos = offset; - fs_lseek (unit, k->fd, k->file_pos, SEEK_SET); - - if (my_truncate (k->aino->nname, offset) == -1) { - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, dos_errno ()); - return; - } + k = lookup_key (unit, GET_PCK64_ARG1 (packet)); + if (k == 0) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, ERROR_OBJECT_NOT_AROUND); + return; + } + + gui_hd_led (unit->unit, 1); + k->notifyactive = 1; + /* If any open files have file pointers beyond this size, truncate only + * so far that these pointers do not become invalid. */ + for (k1 = unit->keys; k1; k1 = k1->next) { + if (k != k1 && k->aino == k1->aino) { + if (k1->file_pos > offset) + offset = k1->file_pos; + } + } + + /* Write one then truncate: that should give the right size in all cases. */ + offset = fs_lseek (unit, k->fd, offset, whence); + my_write (k->fd, /* whatever */(uae_u8*)&k1, 1); + if (k->file_pos > offset) + k->file_pos = offset; + fs_lseek (unit, k->fd, k->file_pos, SEEK_SET); + + if (my_truncate (k->aino->nname, offset) == -1) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, dos_errno ()); + return; + } - PUT_PCK64_RES1 (packet, DOS_TRUE); - PUT_PCK64_RES2 (packet, 0); + PUT_PCK64_RES1 (packet, DOS_TRUE); + PUT_PCK64_RES2 (packet, 0); } static void action_get_file_size64 (Unit *unit, dpacket packet) { - Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); - uae_s64 old, filesize; + Key *k = lookup_key (unit, GET_PCK64_ARG1 (packet)); + uae_s64 old, filesize; - PUT_PCK64_RES0 (packet, DP64_INIT); + PUT_PCK64_RES0 (packet, DP64_INIT); - if (k == 0) { + if (k == 0) { + PUT_PCK64_RES1 (packet, DOS_FALSE); + PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); + return; + } + TRACE((L"ACTION_GET_FILE_SIZE64(%s)\n", k->aino->nname)); + old = fs_lseek64 (unit, k->fd, 0, SEEK_CUR); + if (old >= 0) { + filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); + if (filesize >= 0) { + fs_lseek64 (unit, k->fd, old, SEEK_SET); + PUT_PCK64_RES1 (packet, filesize); + PUT_PCK64_RES2 (packet, 0); + return; + } + } PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_INVALID_LOCK); - return; - } - TRACE((L"ACTION_GET_FILE_SIZE64(%s)\n", k->aino->nname)); - old = fs_lseek64 (unit, k->fd, 0, SEEK_CUR); - if (old >= 0) { - filesize = fs_lseek64 (unit, k->fd, 0, SEEK_END); - if (filesize >= 0) { - fs_lseek64 (unit, k->fd, old, SEEK_SET); - PUT_PCK64_RES1 (packet, filesize); - PUT_PCK64_RES2 (packet, 0); - return; - } - } - PUT_PCK64_RES1 (packet, DOS_FALSE); - PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); + PUT_PCK64_RES2 (packet, ERROR_SEEK_ERROR); } /* We don't want multiple interrupts to be active at the same time. I don't - * know whether AmigaOS takes care of that, but this does. */ +* know whether AmigaOS takes care of that, but this does. */ static uae_sem_t singlethread_int_sem; static uae_u32 REGPARAM2 exter_int_helper (TrapContext *context) { - UnitInfo *uip = mountinfo.ui; - uaecptr port; - int n = m68k_dreg (regs, 0); - static int unit_no; - - switch (n) { - case 0: - /* Determine whether a given EXTER interrupt is for us. */ - if (uae_int_requested & 1) { - if (uae_sem_trywait (&singlethread_int_sem) != 0) - /* Pretend it isn't for us. We might get it again later. */ + UnitInfo *uip = mountinfo.ui; + uaecptr port; + int n = m68k_dreg (regs, 0); + static int unit_no; + + switch (n) { + case 0: + /* Determine whether a given EXTER interrupt is for us. */ + if (uae_int_requested & 1) { + if (uae_sem_trywait (&singlethread_int_sem) != 0) + /* Pretend it isn't for us. We might get it again later. */ + return 0; + /* Clear the interrupt flag _before_ we do any processing. + * That way, we can get too many interrupts, but never not + * enough. */ + filesys_in_interrupt++; + uae_int_requested &= ~1; + unit_no = 0; + return 1; + } return 0; - /* Clear the interrupt flag _before_ we do any processing. - * That way, we can get too many interrupts, but never not - * enough. */ - filesys_in_interrupt++; - uae_int_requested &= ~1; - unit_no = 0; - return 1; - } - return 0; - case 1: - /* Release a message_lock. This is called as soon as the message is - * received by the assembly code. We use the opportunity to check - * whether we have some locks that we can give back to the assembler - * code. - * Note that this is called from the main loop, unlike the other cases - * in this switch statement which are called from the interrupt handler. - */ + case 1: + /* Release a message_lock. This is called as soon as the message is + * received by the assembly code. We use the opportunity to check + * whether we have some locks that we can give back to the assembler + * code. + * Note that this is called from the main loop, unlike the other cases + * in this switch statement which are called from the interrupt handler. + */ #ifdef UAE_FILESYS_THREADS - { - Unit *unit = find_unit (m68k_areg (regs, 5)); - uaecptr msg = m68k_areg (regs, 4); - unit->cmds_complete = unit->cmds_acked; - while (comm_pipe_has_data (unit->ui.back_pipe)) { - uaecptr locks, lockend; - int cnt = 0; - locks = read_comm_pipe_int_blocking (unit->ui.back_pipe); - lockend = locks; - while (get_long (lockend) != 0) { - if (get_long (lockend) == lockend) { - write_log (L"filesystem lock queue corrupted!\n"); - break; - } - lockend = get_long (lockend); - cnt++; + { + Unit *unit = find_unit (m68k_areg (regs, 5)); + uaecptr msg = m68k_areg (regs, 4); + unit->cmds_complete = unit->cmds_acked; + while (comm_pipe_has_data (unit->ui.back_pipe)) { + uaecptr locks, lockend; + int cnt = 0; + locks = read_comm_pipe_int_blocking (unit->ui.back_pipe); + lockend = locks; + while (get_long (lockend) != 0) { + if (get_long (lockend) == lockend) { + write_log (L"filesystem lock queue corrupted!\n"); + break; + } + lockend = get_long (lockend); + cnt++; + } + TRACE((L"%d %x %x %x\n", cnt, locks, lockend, m68k_areg (regs, 3))); + put_long (lockend, get_long (m68k_areg (regs, 3))); + put_long (m68k_areg (regs, 3), locks); + } } - TRACE((L"%d %x %x %x\n", cnt, locks, lockend, m68k_areg (regs, 3))); - put_long (lockend, get_long (m68k_areg (regs, 3))); - put_long (m68k_areg (regs, 3), locks); - } - } #else - write_log (L"exter_int_helper should not be called with arg 1!\n"); + write_log (L"exter_int_helper should not be called with arg 1!\n"); #endif - break; - case 2: - /* Find work that needs to be done: - * return d0 = 0: none - * d0 = 1: PutMsg(), port in a0, message in a1 - * d0 = 2: Signal(), task in a1, signal set in d1 - * d0 = 3: ReplyMsg(), message in a1 - * d0 = 4: Cause(), interrupt in a1 - * d0 = 5: Send FileNofication message, port in a0, notifystruct in a1 - */ + break; + case 2: + /* Find work that needs to be done: + * return d0 = 0: none + * d0 = 1: PutMsg(), port in a0, message in a1 + * d0 = 2: Signal(), task in a1, signal set in d1 + * d0 = 3: ReplyMsg(), message in a1 + * d0 = 4: Cause(), interrupt in a1 + * d0 = 5: Send FileNofication message, port in a0, notifystruct in a1 + */ #ifdef SUPPORT_THREADS - /* First, check signals/messages */ - while (comm_pipe_has_data (&native2amiga_pending)) { - int cmd = read_comm_pipe_int_blocking (&native2amiga_pending); - switch (cmd) { - case 0: /* Signal() */ - m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - m68k_dreg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - return 2; - - case 1: /* PutMsg() */ - m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending); - m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - return 1; - - case 2: /* ReplyMsg() */ - m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - return 3; - - case 3: /* Cause() */ - m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - return 4; - - case 4: /* NotifyHack() */ - m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending); - m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); - return 5; - - default: - write_log (L"exter_int_helper: unknown native action %X\n", cmd); - break; - } - } + /* First, check signals/messages */ + while (comm_pipe_has_data (&native2amiga_pending)) { + int cmd = read_comm_pipe_int_blocking (&native2amiga_pending); + switch (cmd) { + case 0: /* Signal() */ + m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + m68k_dreg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + return 2; + + case 1: /* PutMsg() */ + m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending); + m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + return 1; + + case 2: /* ReplyMsg() */ + m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + return 3; + + case 3: /* Cause() */ + m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + return 4; + + case 4: /* NotifyHack() */ + m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending); + m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending); + return 5; + + default: + write_log (L"exter_int_helper: unknown native action %X\n", cmd); + break; + } + } #endif - /* Find some unit that needs a message sent, and return its port, - * or zero if all are done. - * Take care not to dereference self for units that didn't have their - * startup packet sent. */ - for (;;) { - if (unit_no >= MAX_FILESYSTEM_UNITS) - return 0; + /* Find some unit that needs a message sent, and return its port, + * or zero if all are done. + * Take care not to dereference self for units that didn't have their + * startup packet sent. */ + for (;;) { + if (unit_no >= MAX_FILESYSTEM_UNITS) + return 0; + + if (uip[unit_no].open && uip[unit_no].self != 0 + && uip[unit_no].self->cmds_acked == uip[unit_no].self->cmds_complete + && uip[unit_no].self->cmds_acked != uip[unit_no].self->cmds_sent) + break; + unit_no++; + } + uip[unit_no].self->cmds_acked = uip[unit_no].self->cmds_sent; + port = uip[unit_no].self->port; + if (port) { + m68k_areg (regs, 0) = port; + m68k_areg (regs, 1) = find_unit (port)->dummy_message; + unit_no++; + return 1; + } + break; + case 3: + uae_sem_wait (&singlethread_int_sem); + break; + case 4: + /* Exit the interrupt, and release the single-threading lock. */ + filesys_in_interrupt--; + uae_sem_post (&singlethread_int_sem); + break; - if (uip[unit_no].open && uip[unit_no].self != 0 - && uip[unit_no].self->cmds_acked == uip[unit_no].self->cmds_complete - && uip[unit_no].self->cmds_acked != uip[unit_no].self->cmds_sent) + default: + write_log (L"Shouldn't happen in exter_int_helper.\n"); break; - unit_no++; - } - uip[unit_no].self->cmds_acked = uip[unit_no].self->cmds_sent; - port = uip[unit_no].self->port; - if (port) { - m68k_areg (regs, 0) = port; - m68k_areg (regs, 1) = find_unit (port)->dummy_message; - unit_no++; - return 1; - } - break; - case 3: - uae_sem_wait (&singlethread_int_sem); - break; - case 4: - /* Exit the interrupt, and release the single-threading lock. */ - filesys_in_interrupt--; - uae_sem_post (&singlethread_int_sem); - break; - - default: - write_log (L"Shouldn't happen in exter_int_helper.\n"); - break; - } - return 0; + } + return 0; } static int handle_packet (Unit *unit, dpacket pck) { - uae_s32 type = GET_PCK_TYPE (pck); - PUT_PCK_RES2 (pck, 0); + uae_s32 type = GET_PCK_TYPE (pck); + PUT_PCK_RES2 (pck, 0); - if (unit->inhibited && filesys_isvolume(unit) - && type != ACTION_INHIBIT && type != ACTION_MORE_CACHE - && type != ACTION_DISK_INFO) { - PUT_PCK_RES1 (pck, DOS_FALSE); - PUT_PCK_RES2 (pck, ERROR_NOT_A_DOS_DISK); - return 1; - } - if (type != ACTION_INHIBIT && type != ACTION_CURRENT_VOLUME - && type != ACTION_IS_FILESYSTEM && type != ACTION_MORE_CACHE - && type != ACTION_WRITE_PROTECT - && !filesys_isvolume(unit)) { - PUT_PCK_RES1 (pck, DOS_FALSE); - PUT_PCK_RES2 (pck, ERROR_NO_DISK); + if (unit->inhibited && filesys_isvolume(unit) + && type != ACTION_INHIBIT && type != ACTION_MORE_CACHE + && type != ACTION_DISK_INFO) { + PUT_PCK_RES1 (pck, DOS_FALSE); + PUT_PCK_RES2 (pck, ERROR_NOT_A_DOS_DISK); + return 1; + } + if (type != ACTION_INHIBIT && type != ACTION_CURRENT_VOLUME + && type != ACTION_IS_FILESYSTEM && type != ACTION_MORE_CACHE + && type != ACTION_WRITE_PROTECT + && !filesys_isvolume(unit)) { + PUT_PCK_RES1 (pck, DOS_FALSE); + PUT_PCK_RES2 (pck, ERROR_NO_DISK); + return 1; + } + + switch (type) { + case ACTION_LOCATE_OBJECT: action_lock (unit, pck); break; + case ACTION_FREE_LOCK: action_free_lock (unit, pck); break; + case ACTION_COPY_DIR: action_dup_lock (unit, pck); break; + case ACTION_DISK_INFO: action_disk_info (unit, pck); break; + case ACTION_INFO: action_info (unit, pck); break; + case ACTION_EXAMINE_OBJECT: action_examine_object (unit, pck); break; + case ACTION_EXAMINE_NEXT: action_examine_next (unit, pck); break; + case ACTION_FIND_INPUT: action_find_input (unit, pck); break; + case ACTION_FIND_WRITE: action_find_write (unit, pck); break; + case ACTION_FIND_OUTPUT: action_find_output (unit, pck); break; + case ACTION_END: action_end (unit, pck); break; + case ACTION_READ: action_read (unit, pck); break; + case ACTION_WRITE: action_write (unit, pck); break; + case ACTION_SEEK: action_seek (unit, pck); break; + case ACTION_SET_PROTECT: action_set_protect (unit, pck); break; + case ACTION_SET_COMMENT: action_set_comment (unit, pck); break; + case ACTION_SAME_LOCK: action_same_lock (unit, pck); break; + case ACTION_PARENT: action_parent (unit, pck); break; + case ACTION_CREATE_DIR: action_create_dir (unit, pck); break; + case ACTION_DELETE_OBJECT: action_delete_object (unit, pck); break; + case ACTION_RENAME_OBJECT: action_rename_object (unit, pck); break; + case ACTION_SET_DATE: action_set_date (unit, pck); break; + case ACTION_CURRENT_VOLUME: action_current_volume (unit, pck); break; + case ACTION_RENAME_DISK: action_rename_disk (unit, pck); break; + case ACTION_IS_FILESYSTEM: action_is_filesystem (unit, pck); break; + case ACTION_FLUSH: action_flush (unit, pck); break; + case ACTION_MORE_CACHE: action_more_cache (unit, pck); break; + case ACTION_INHIBIT: action_inhibit (unit, pck); break; + case ACTION_WRITE_PROTECT: action_write_protect (unit, pck); break; + + /* 2.0+ packet types */ + case ACTION_SET_FILE_SIZE: action_set_file_size (unit, pck); break; + case ACTION_EXAMINE_FH: action_examine_fh (unit, pck); break; + case ACTION_FH_FROM_LOCK: action_fh_from_lock (unit, pck); break; + case ACTION_COPY_DIR_FH: action_lock_from_fh (unit, pck); break; + case ACTION_CHANGE_MODE: action_change_mode (unit, pck); break; + case ACTION_PARENT_FH: action_parent_fh (unit, pck); break; + case ACTION_ADD_NOTIFY: action_add_notify (unit, pck); break; + case ACTION_REMOVE_NOTIFY: action_remove_notify (unit, pck); break; + case ACTION_EXAMINE_ALL: return action_examine_all (unit, pck); + case ACTION_EXAMINE_ALL_END: return action_examine_all_end (unit, pck); + + /* OS4+ packet types */ + case ACTION_CHANGE_FILE_POSITION64: action_change_file_position64 (unit, pck); break; + case ACTION_GET_FILE_POSITION64: action_get_file_position64 (unit, pck); break; + case ACTION_CHANGE_FILE_SIZE64: action_change_file_size64 (unit, pck); break; + case ACTION_GET_FILE_SIZE64: action_get_file_size64 (unit, pck); break; + + /* unsupported packets */ + case ACTION_LOCK_RECORD: + case ACTION_FREE_RECORD: + case ACTION_MAKE_LINK: + case ACTION_READ_LINK: + case ACTION_FORMAT: + return 0; + default: + write_log (L"FILESYS: UNKNOWN PACKET %x\n", type); + return 0; + } return 1; - } - - switch (type) { - case ACTION_LOCATE_OBJECT: action_lock (unit, pck); break; - case ACTION_FREE_LOCK: action_free_lock (unit, pck); break; - case ACTION_COPY_DIR: action_dup_lock (unit, pck); break; - case ACTION_DISK_INFO: action_disk_info (unit, pck); break; - case ACTION_INFO: action_info (unit, pck); break; - case ACTION_EXAMINE_OBJECT: action_examine_object (unit, pck); break; - case ACTION_EXAMINE_NEXT: action_examine_next (unit, pck); break; - case ACTION_FIND_INPUT: action_find_input (unit, pck); break; - case ACTION_FIND_WRITE: action_find_write (unit, pck); break; - case ACTION_FIND_OUTPUT: action_find_output (unit, pck); break; - case ACTION_END: action_end (unit, pck); break; - case ACTION_READ: action_read (unit, pck); break; - case ACTION_WRITE: action_write (unit, pck); break; - case ACTION_SEEK: action_seek (unit, pck); break; - case ACTION_SET_PROTECT: action_set_protect (unit, pck); break; - case ACTION_SET_COMMENT: action_set_comment (unit, pck); break; - case ACTION_SAME_LOCK: action_same_lock (unit, pck); break; - case ACTION_PARENT: action_parent (unit, pck); break; - case ACTION_CREATE_DIR: action_create_dir (unit, pck); break; - case ACTION_DELETE_OBJECT: action_delete_object (unit, pck); break; - case ACTION_RENAME_OBJECT: action_rename_object (unit, pck); break; - case ACTION_SET_DATE: action_set_date (unit, pck); break; - case ACTION_CURRENT_VOLUME: action_current_volume (unit, pck); break; - case ACTION_RENAME_DISK: action_rename_disk (unit, pck); break; - case ACTION_IS_FILESYSTEM: action_is_filesystem (unit, pck); break; - case ACTION_FLUSH: action_flush (unit, pck); break; - case ACTION_MORE_CACHE: action_more_cache (unit, pck); break; - case ACTION_INHIBIT: action_inhibit (unit, pck); break; - case ACTION_WRITE_PROTECT: action_write_protect (unit, pck); break; - - /* 2.0+ packet types */ - case ACTION_SET_FILE_SIZE: action_set_file_size (unit, pck); break; - case ACTION_EXAMINE_FH: action_examine_fh (unit, pck); break; - case ACTION_FH_FROM_LOCK: action_fh_from_lock (unit, pck); break; - case ACTION_COPY_DIR_FH: action_lock_from_fh (unit, pck); break; - case ACTION_CHANGE_MODE: action_change_mode (unit, pck); break; - case ACTION_PARENT_FH: action_parent_fh (unit, pck); break; - case ACTION_ADD_NOTIFY: action_add_notify (unit, pck); break; - case ACTION_REMOVE_NOTIFY: action_remove_notify (unit, pck); break; - case ACTION_EXAMINE_ALL: return action_examine_all (unit, pck); - case ACTION_EXAMINE_ALL_END: return action_examine_all_end (unit, pck); - - /* OS4+ packet types */ - case ACTION_CHANGE_FILE_POSITION64: action_change_file_position64 (unit, pck); break; - case ACTION_GET_FILE_POSITION64: action_get_file_position64 (unit, pck); break; - case ACTION_CHANGE_FILE_SIZE64: action_change_file_size64 (unit, pck); break; - case ACTION_GET_FILE_SIZE64: action_get_file_size64 (unit, pck); break; - - /* unsupported packets */ - case ACTION_LOCK_RECORD: - case ACTION_FREE_RECORD: - case ACTION_MAKE_LINK: - case ACTION_READ_LINK: - case ACTION_FORMAT: - return 0; - default: - write_log (L"FILESYS: UNKNOWN PACKET %x\n", type); - return 0; - } - return 1; } #ifdef UAE_FILESYS_THREADS static void *filesys_thread (void *unit_v) { - UnitInfo *ui = (UnitInfo *)unit_v; - - uae_set_thread_priority (NULL, 1); - for (;;) { - uae_u8 *pck; - uae_u8 *msg; - uae_u32 morelocks; + UnitInfo *ui = (UnitInfo *)unit_v; - pck = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe); - msg = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe); - morelocks = (uae_u32)read_comm_pipe_int_blocking (ui->unit_pipe); + uae_set_thread_priority (NULL, 1); + for (;;) { + uae_u8 *pck; + uae_u8 *msg; + uae_u32 morelocks; + + pck = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe); + msg = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe); + morelocks = (uae_u32)read_comm_pipe_int_blocking (ui->unit_pipe); + + if (ui->reset_state == FS_GO_DOWN) { + if (pck != 0) + continue; + /* Death message received. */ + uae_sem_post (&ui->reset_sync_sem); + /* Die. */ + return 0; + } - if (ui->reset_state == FS_GO_DOWN) { - if (pck != 0) - continue; - /* Death message received. */ - uae_sem_post (&ui->reset_sync_sem); - /* Die. */ - return 0; - } + put_long (get_long (morelocks), get_long (ui->self->locklist)); + put_long (ui->self->locklist, morelocks); + if (! handle_packet (ui->self, pck)) { + PUT_PCK_RES1 (pck, DOS_FALSE); + PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN); + } + /* Mark the packet as processed for the list scan in the assembly code. */ + do_put_mem_long ((uae_u32 *)(msg + 4), -1); + /* Acquire the message lock, so that we know we can safely send the + * message. */ + ui->self->cmds_sent++; + /* The message is sent by our interrupt handler, so make sure an interrupt + * happens. */ + do_uae_int_requested(); + /* Send back the locks. */ + if (get_long (ui->self->locklist) != 0) + write_comm_pipe_int (ui->back_pipe, (int)(get_long (ui->self->locklist)), 0); + put_long (ui->self->locklist, 0); - put_long (get_long (morelocks), get_long (ui->self->locklist)); - put_long (ui->self->locklist, morelocks); - if (! handle_packet (ui->self, pck)) { - PUT_PCK_RES1 (pck, DOS_FALSE); - PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN); } - /* Mark the packet as processed for the list scan in the assembly code. */ - do_put_mem_long ((uae_u32 *)(msg + 4), -1); - /* Acquire the message lock, so that we know we can safely send the - * message. */ - ui->self->cmds_sent++; - /* The message is sent by our interrupt handler, so make sure an interrupt - * happens. */ - do_uae_int_requested(); - /* Send back the locks. */ - if (get_long (ui->self->locklist) != 0) - write_comm_pipe_int (ui->back_pipe, (int)(get_long (ui->self->locklist)), 0); - put_long (ui->self->locklist, 0); - - } - return 0; + return 0; } #endif /* Talk about spaghetti code... */ static uae_u32 REGPARAM2 filesys_handler (TrapContext *context) { - Unit *unit = find_unit (m68k_areg (regs, 5)); - uaecptr packet_addr = m68k_dreg (regs, 3); - uaecptr message_addr = m68k_areg (regs, 4); - uae_u8 *pck; - uae_u8 *msg; - if (! valid_address (packet_addr, 36) || ! valid_address (message_addr, 14)) { - write_log (L"FILESYS: Bad address %x/%x passed for packet.\n", packet_addr, message_addr); - goto error2; - } - pck = get_real_address (packet_addr); - msg = get_real_address (message_addr); - - do_put_mem_long ((uae_u32 *)(msg + 4), -1); - if (!unit || !unit->volume) { - write_log (L"FILESYS: was not initialized.\n"); - goto error; - } + Unit *unit = find_unit (m68k_areg (regs, 5)); + uaecptr packet_addr = m68k_dreg (regs, 3); + uaecptr message_addr = m68k_areg (regs, 4); + uae_u8 *pck; + uae_u8 *msg; + if (! valid_address (packet_addr, 36) || ! valid_address (message_addr, 14)) { + write_log (L"FILESYS: Bad address %x/%x passed for packet.\n", packet_addr, message_addr); + goto error2; + } + pck = get_real_address (packet_addr); + msg = get_real_address (message_addr); + + do_put_mem_long ((uae_u32 *)(msg + 4), -1); + if (!unit || !unit->volume) { + write_log (L"FILESYS: was not initialized.\n"); + goto error; + } #ifdef UAE_FILESYS_THREADS - { - uae_u32 morelocks; - if (!unit->ui.unit_pipe) - goto error; - /* Get two more locks and hand them over to the other thread. */ - morelocks = get_long (m68k_areg (regs, 3)); - put_long (m68k_areg (regs, 3), get_long (get_long (morelocks))); - put_long (get_long (morelocks), 0); - - /* The packet wasn't processed yet. */ - do_put_mem_long ((uae_u32 *)(msg + 4), 0); - write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)pck, 0); - write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)msg, 0); - write_comm_pipe_int (unit->ui.unit_pipe, (int)morelocks, 1); - /* Don't reply yet. */ - return 1; - } + { + uae_u32 morelocks; + if (!unit->ui.unit_pipe) + goto error; + /* Get two more locks and hand them over to the other thread. */ + morelocks = get_long (m68k_areg (regs, 3)); + put_long (m68k_areg (regs, 3), get_long (get_long (morelocks))); + put_long (get_long (morelocks), 0); + + /* The packet wasn't processed yet. */ + do_put_mem_long ((uae_u32 *)(msg + 4), 0); + write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)pck, 0); + write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)msg, 0); + write_comm_pipe_int (unit->ui.unit_pipe, (int)morelocks, 1); + /* Don't reply yet. */ + return 1; + } #endif - if (! handle_packet (unit, pck)) { - error: - PUT_PCK_RES1 (pck, DOS_FALSE); - PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN); - } - TRACE((L"reply: %8lx, %ld\n", GET_PCK_RES1 (pck), GET_PCK_RES2 (pck))); + if (! handle_packet (unit, pck)) { +error: + PUT_PCK_RES1 (pck, DOS_FALSE); + PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN); + } + TRACE((L"reply: %8lx, %ld\n", GET_PCK_RES1 (pck), GET_PCK_RES2 (pck))); - error2: +error2: - return 0; + return 0; } static void init_filesys_diagentry (void) { - do_put_mem_long ((uae_u32 *)(filesysory + 0x2100), EXPANSION_explibname); - do_put_mem_long ((uae_u32 *)(filesysory + 0x2104), filesys_configdev); - do_put_mem_long ((uae_u32 *)(filesysory + 0x2108), EXPANSION_doslibname); - do_put_mem_long ((uae_u32 *)(filesysory + 0x210c), nr_units ()); - native2amiga_startup (); + do_put_mem_long ((uae_u32 *)(filesysory + 0x2100), EXPANSION_explibname); + do_put_mem_long ((uae_u32 *)(filesysory + 0x2104), filesys_configdev); + do_put_mem_long ((uae_u32 *)(filesysory + 0x2108), EXPANSION_doslibname); + do_put_mem_long ((uae_u32 *)(filesysory + 0x210c), nr_units ()); + native2amiga_startup (); } void filesys_start_threads (void) { - int i; + int i; - filesys_in_interrupt = 0; - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - UnitInfo *ui = &mountinfo.ui[i]; - if (!ui->open) - continue; - filesys_start_thread (ui, i); - } + filesys_in_interrupt = 0; + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + UnitInfo *ui = &mountinfo.ui[i]; + if (!ui->open) + continue; + filesys_start_thread (ui, i); + } } void filesys_cleanup (void) { - filesys_free_handles (); - free_mountinfo (); + filesys_free_handles (); + free_mountinfo (); } void filesys_free_handles (void) { - Unit *u, *u1; - for (u = units; u; u = u1) { - Key *k1, *knext; - u1 = u->next; - for (k1 = u->keys; k1; k1 = knext) { - knext = k1->next; - if (k1->fd) - fs_close (u, k1->fd); - xfree (k1); - } - u->keys = NULL; - free_all_ainos (u, &u->rootnode); - u->rootnode.next = u->rootnode.prev = &u->rootnode; - u->aino_cache_size = 0; - xfree (u->newrootdir); - xfree (u->newvolume); - u->newrootdir = NULL; - u->newvolume = NULL; - } + Unit *u, *u1; + for (u = units; u; u = u1) { + Key *k1, *knext; + u1 = u->next; + for (k1 = u->keys; k1; k1 = knext) { + knext = k1->next; + if (k1->fd) + fs_close (u, k1->fd); + xfree (k1); + } + u->keys = NULL; + free_all_ainos (u, &u->rootnode); + u->rootnode.next = u->rootnode.prev = &u->rootnode; + u->aino_cache_size = 0; + xfree (u->newrootdir); + xfree (u->newvolume); + u->newrootdir = NULL; + u->newvolume = NULL; + } } static void filesys_reset2 (void) { - Unit *u, *u1; + Unit *u, *u1; - filesys_free_handles (); - for (u = units; u; u = u1) { - u1 = u->next; - xfree (u); - } - units = 0; - key_uniq = 0; - a_uniq = 0; - free_mountinfo (); + filesys_free_handles (); + for (u = units; u; u = u1) { + u1 = u->next; + xfree (u); + } + units = 0; + key_uniq = 0; + a_uniq = 0; + free_mountinfo (); } void filesys_reset (void) { - if (savestate_state == STATE_RESTORE) - return; - filesys_reset2 (); - initialize_mountinfo (); + if (savestate_state == STATE_RESTORE) + return; + filesys_reset2 (); + initialize_mountinfo (); } static void filesys_prepare_reset2 (void) { - UnitInfo *uip; -// Unit *u; - int i; + UnitInfo *uip; + // Unit *u; + int i; - uip = mountinfo.ui; + uip = mountinfo.ui; #ifdef UAE_FILESYS_THREADS - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - if (uip[i].open && uip[i].unit_pipe != 0) { - uae_sem_init (&uip[i].reset_sync_sem, 0, 0); - uip[i].reset_state = FS_GO_DOWN; - /* send death message */ - write_comm_pipe_int (uip[i].unit_pipe, 0, 0); - write_comm_pipe_int (uip[i].unit_pipe, 0, 0); - write_comm_pipe_int (uip[i].unit_pipe, 0, 1); - uae_sem_wait (&uip[i].reset_sync_sem); - uae_end_thread (&uip[i].tid); - } - } + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + if (uip[i].open && uip[i].unit_pipe != 0) { + uae_sem_init (&uip[i].reset_sync_sem, 0, 0); + uip[i].reset_state = FS_GO_DOWN; + /* send death message */ + write_comm_pipe_int (uip[i].unit_pipe, 0, 0); + write_comm_pipe_int (uip[i].unit_pipe, 0, 0); + write_comm_pipe_int (uip[i].unit_pipe, 0, 1); + uae_sem_wait (&uip[i].reset_sync_sem); + uae_end_thread (&uip[i].tid); + } + } #endif - filesys_free_handles(); + filesys_free_handles(); #if 0 - u = units; - while (u != 0) { - free_all_ainos (u, &u->rootnode); - u->rootnode.next = u->rootnode.prev = &u->rootnode; - u->aino_cache_size = 0; - u = u->next; - } + u = units; + while (u != 0) { + free_all_ainos (u, &u->rootnode); + u->rootnode.next = u->rootnode.prev = &u->rootnode; + u->aino_cache_size = 0; + u = u->next; + } #endif } void filesys_prepare_reset (void) { - if (savestate_state == STATE_RESTORE) - return; - filesys_prepare_reset2 (); + if (savestate_state == STATE_RESTORE) + return; + filesys_prepare_reset2 (); } static uae_u32 REGPARAM2 filesys_diagentry (TrapContext *context) { - uaecptr resaddr = m68k_areg (regs, 2) + 0x10; - uaecptr start = resaddr; - uaecptr residents, tmp; - - TRACE ((L"filesystem: diagentry called\n")); - - filesys_configdev = m68k_areg (regs, 3); - init_filesys_diagentry (); - - if (ROM_hardfile_resid != 0) { - /* Build a struct Resident. This will set up and initialize - * the uae.device */ - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, ROM_hardfile_resname); - put_long (resaddr + 0x12, ROM_hardfile_resid); - put_long (resaddr + 0x16, ROM_hardfile_init); /* calls filesys_init */ - } - resaddr += 0x1A; - tmp = resaddr; - /* The good thing about this function is that it always gets called - * when we boot. So we could put all sorts of stuff that wants to be done - * here. - * We can simply add more Resident structures here. Although the Amiga OS - * only knows about the one at address DiagArea + 0x10, we scan for other - * Resident structures and call InitResident() for them at the end of the - * diag entry. */ - - resaddr = uaeres_startup (resaddr); + uaecptr resaddr = m68k_areg (regs, 2) + 0x10; + uaecptr start = resaddr; + uaecptr residents, tmp; + + TRACE ((L"filesystem: diagentry called\n")); + + filesys_configdev = m68k_areg (regs, 3); + init_filesys_diagentry (); + + if (ROM_hardfile_resid != 0) { + /* Build a struct Resident. This will set up and initialize + * the uae.device */ + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, ROM_hardfile_resname); + put_long (resaddr + 0x12, ROM_hardfile_resid); + put_long (resaddr + 0x16, ROM_hardfile_init); /* calls filesys_init */ + } + resaddr += 0x1A; + tmp = resaddr; + /* The good thing about this function is that it always gets called + * when we boot. So we could put all sorts of stuff that wants to be done + * here. + * We can simply add more Resident structures here. Although the Amiga OS + * only knows about the one at address DiagArea + 0x10, we scan for other + * Resident structures and call InitResident() for them at the end of the + * diag entry. */ + + resaddr = uaeres_startup (resaddr); #ifdef BSDSOCKET - resaddr = bsdlib_startup (resaddr); + resaddr = bsdlib_startup (resaddr); #endif #ifdef SCSIEMU - resaddr = scsidev_startup (resaddr); + resaddr = scsidev_startup (resaddr); #endif #ifdef SANA2 - resaddr = netdev_startup (resaddr); + resaddr = netdev_startup (resaddr); #endif #ifdef UAESERIAL - resaddr = uaeserialdev_startup (resaddr); + resaddr = uaeserialdev_startup (resaddr); #endif - /* scan for Residents and return pointer to array of them */ - residents = resaddr; - while (tmp < residents && tmp > start) { - if (get_word (tmp) == 0x4AFC && - get_long (tmp + 0x2) == tmp) { - put_word (resaddr, 0x227C); /* movea.l #tmp,a1 */ - put_long (resaddr + 2, tmp); - put_word (resaddr + 6, 0x7200); /* moveq.l #0,d1 */ - put_long (resaddr + 8, 0x4EAEFF9A); /* jsr -$66(a6) ; InitResident */ - resaddr += 12; - tmp = get_long (tmp + 0x6); - } else { - tmp++; + /* scan for Residents and return pointer to array of them */ + residents = resaddr; + while (tmp < residents && tmp > start) { + if (get_word (tmp) == 0x4AFC && + get_long (tmp + 0x2) == tmp) { + put_word (resaddr, 0x227C); /* movea.l #tmp,a1 */ + put_long (resaddr + 2, tmp); + put_word (resaddr + 6, 0x7200); /* moveq.l #0,d1 */ + put_long (resaddr + 8, 0x4EAEFF9A); /* jsr -$66(a6) ; InitResident */ + resaddr += 12; + tmp = get_long (tmp + 0x6); + } else { + tmp++; + } } - } - /* call setup_exter */ - put_word (resaddr + 0, 0x2079); - put_long (resaddr + 2, rtarea_base + bootrom_header + 4 + 5 * 4); /* move.l RTAREA_BASE+setup_exter,a0 */ - put_word (resaddr + 6, 0xd1fc); - put_long (resaddr + 8, rtarea_base + bootrom_header); /* add.l #RTAREA_BASE+bootrom_header,a0 */ - put_word (resaddr + 12, 0x4e90); /* jsr (a0) */ - put_word (resaddr + 14, 0x7001); /* moveq.l #1,d0 */ - put_word (resaddr + 16, RTS); - - m68k_areg (regs, 0) = residents; - return 1; + /* call setup_exter */ + put_word (resaddr + 0, 0x2079); + put_long (resaddr + 2, rtarea_base + bootrom_header + 4 + 5 * 4); /* move.l RTAREA_BASE+setup_exter,a0 */ + put_word (resaddr + 6, 0xd1fc); + put_long (resaddr + 8, rtarea_base + bootrom_header); /* add.l #RTAREA_BASE+bootrom_header,a0 */ + put_word (resaddr + 12, 0x4e90); /* jsr (a0) */ + put_word (resaddr + 14, 0x7001); /* moveq.l #1,d0 */ + put_word (resaddr + 16, RTS); + + m68k_areg (regs, 0) = residents; + return 1; } /* don't forget filesys.asm! */ @@ -5137,1291 +5137,1293 @@ static uae_u32 REGPARAM2 filesys_diagentry (TrapContext *context) static uae_u32 REGPARAM2 filesys_dev_bootfilesys (TrapContext *context) { - uaecptr devicenode = m68k_areg (regs, 3); - uaecptr parmpacket = m68k_areg (regs, 1); - uaecptr fsres = get_long (parmpacket + PP_FSRES); - uaecptr fsnode; - uae_u32 dostype, dostype2; - UnitInfo *uip = mountinfo.ui; - int no = m68k_dreg (regs, 6); - int unit_no = no & 65535; - int type = is_hardfile (unit_no); - - if (type == FILESYS_VIRTUAL) + uaecptr devicenode = m68k_areg (regs, 3); + uaecptr parmpacket = m68k_areg (regs, 1); + uaecptr fsres = get_long (parmpacket + PP_FSRES); + uaecptr fsnode; + uae_u32 dostype, dostype2; + UnitInfo *uip = mountinfo.ui; + int no = m68k_dreg (regs, 6); + int unit_no = no & 65535; + int type = is_hardfile (unit_no); + + if (type == FILESYS_VIRTUAL) + return 0; + dostype = get_long (parmpacket + 80); + fsnode = get_long (fsres + 18); + while (get_long (fsnode)) { + dostype2 = get_long (fsnode + 14); + if (dostype2 == dostype) { + int i; + uae_u32 pf = get_long (fsnode + 22); // fse_PatchFlags + for (i = 0; i < 32; i++) { + if (pf & (1 << i)) + put_long (devicenode + 4 + i * 4, get_long (fsnode + 22 + 4 + i * 4)); + } + return 1; + } + fsnode = get_long (fsnode); + } return 0; - dostype = get_long (parmpacket + 80); - fsnode = get_long (fsres + 18); - while (get_long (fsnode)) { - dostype2 = get_long (fsnode + 14); - if (dostype2 == dostype) { - int i; - uae_u32 pf = get_long (fsnode + 22); // fse_PatchFlags - for (i = 0; i < 32; i++) { - if (pf & (1 << i)) - put_long (devicenode + 4 + i * 4, get_long (fsnode + 22 + 4 + i * 4)); - } - return 1; - } - fsnode = get_long (fsnode); - } - return 0; } extern void picasso96_alloc (TrapContext*); static uae_u32 REGPARAM2 filesys_init_storeinfo (TrapContext *context) { - int ret = -1; - switch (m68k_dreg (regs, 1)) - { + int ret = -1; + switch (m68k_dreg (regs, 1)) + { case 1: - mountertask = m68k_areg (regs, 1); - picasso96_alloc (context); - break; + mountertask = m68k_areg (regs, 1); + picasso96_alloc (context); + break; case 2: - ret = automountunit; - automountunit = -1; - break; + ret = automountunit; + automountunit = -1; + break; case 3: - return 0; - } - return ret; + return 0; + } + return ret; } /* Remember a pointer AmigaOS gave us so we can later use it to identify - * which unit a given startup message belongs to. */ +* which unit a given startup message belongs to. */ static uae_u32 REGPARAM2 filesys_dev_remember (TrapContext *context) { - int no = m68k_dreg (regs, 6); - int unit_no = no & 65535; - int sub_no = no >> 16; - UnitInfo *uip = &mountinfo.ui[unit_no]; - int i; - uaecptr devicenode = m68k_areg (regs, 3); - uaecptr parmpacket = m68k_areg (regs, 1); - - /* copy filesystem loaded from RDB */ - if (get_long (parmpacket + PP_FSPTR)) { - for (i = 0; i < uip->rdb_filesyssize; i++) - put_byte (get_long (parmpacket + PP_FSPTR) + i, uip->rdb_filesysstore[i]); - xfree (uip->rdb_filesysstore); - uip->rdb_filesysstore = 0; - uip->rdb_filesyssize = 0; - } - if (m68k_dreg (regs, 3) >= 0) - uip->startup = get_long (devicenode + 28); - return devicenode; + int no = m68k_dreg (regs, 6); + int unit_no = no & 65535; + int sub_no = no >> 16; + UnitInfo *uip = &mountinfo.ui[unit_no]; + int i; + uaecptr devicenode = m68k_areg (regs, 3); + uaecptr parmpacket = m68k_areg (regs, 1); + + /* copy filesystem loaded from RDB */ + if (get_long (parmpacket + PP_FSPTR)) { + for (i = 0; i < uip->rdb_filesyssize; i++) + put_byte (get_long (parmpacket + PP_FSPTR) + i, uip->rdb_filesysstore[i]); + xfree (uip->rdb_filesysstore); + uip->rdb_filesysstore = 0; + uip->rdb_filesyssize = 0; + } + if (m68k_dreg (regs, 3) >= 0) + uip->startup = get_long (devicenode + 28); + return devicenode; } static int legalrdbblock (UnitInfo *uip, int block) { - if (block <= 0) - return 0; - if (block >= uip->hf.virtsize / uip->hf.blocksize) - return 0; - return 1; + if (block <= 0) + return 0; + if (block >= uip->hf.virtsize / uip->hf.blocksize) + return 0; + return 1; } static int rl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); } int rdb_checksum (uae_char *id, uae_u8 *p, int block) { - uae_u32 sum = 0; - int i, blocksize; + uae_u32 sum = 0; + int i, blocksize; - if (memcmp (id, p, 4)) - return 0; - blocksize = rl (p + 4); - if (blocksize < 1 || blocksize * 4 > FILESYS_MAX_BLOCKSIZE) - return 0; - for (i = 0; i < blocksize; i++) - sum += rl (p + i * 4); - sum = -sum; - if (sum) { - TCHAR *s = au (id); - write_log (L"RDB: block %d ('%s') checksum error\n", block, s); - xfree (s); - return 0; - } - return 1; + if (memcmp (id, p, 4)) + return 0; + blocksize = rl (p + 4); + if (blocksize < 1 || blocksize * 4 > FILESYS_MAX_BLOCKSIZE) + return 0; + for (i = 0; i < blocksize; i++) + sum += rl (p + i * 4); + sum = -sum; + if (sum) { + TCHAR *s = au (id); + write_log (L"RDB: block %d ('%s') checksum error\n", block, s); + xfree (s); + return 0; + } + return 1; } static int device_isdup (uaecptr expbase, TCHAR *devname) { - uaecptr bnode, dnode, name; - int len, i; - TCHAR dname[256]; - - bnode = get_long (expbase + 74); /* expansion.library bootnode list */ - while (get_long (bnode)) { - dnode = get_long (bnode + 16); /* device node */ - name = get_long (dnode + 40) << 2; /* device name BSTR */ - len = get_byte (name); - for (i = 0; i < len; i++) - dname[i] = get_byte (name + 1 + i); - dname[len] = 0; - if (!_tcsicmp (devname, dname)) - return 1; - bnode = get_long (bnode); - } - return 0; + uaecptr bnode, dnode, name; + int len, i; + TCHAR dname[256]; + + bnode = get_long (expbase + 74); /* expansion.library bootnode list */ + while (get_long (bnode)) { + dnode = get_long (bnode + 16); /* device node */ + name = get_long (dnode + 40) << 2; /* device name BSTR */ + len = get_byte (name); + for (i = 0; i < len; i++) + dname[i] = get_byte (name + 1 + i); + dname[len] = 0; + if (!_tcsicmp (devname, dname)) + return 1; + bnode = get_long (bnode); + } + return 0; } static TCHAR *device_dupfix (uaecptr expbase, TCHAR *devname) { - int modified; - TCHAR newname[256]; - - _tcscpy (newname, devname); - modified = 1; - while (modified) { - modified = 0; - if (device_isdup (expbase, newname)) { - if (_tcslen (newname) > 2 && newname[_tcslen (newname) - 2] == '_') { - newname[_tcslen (newname) - 1]++; - } else { - _tcscat (newname, L"_0"); - } - modified = 1; + int modified; + TCHAR newname[256]; + + _tcscpy (newname, devname); + modified = 1; + while (modified) { + modified = 0; + if (device_isdup (expbase, newname)) { + if (_tcslen (newname) > 2 && newname[_tcslen (newname) - 2] == '_') { + newname[_tcslen (newname) - 1]++; + } else { + _tcscat (newname, L"_0"); + } + modified = 1; + } } - } - return my_strdup (newname); + return my_strdup (newname); } static void dump_partinfo (uae_char *name, int num, uaecptr pp, int partblock) { - TCHAR *s = au (name); - uae_u32 dostype = get_long (pp + 80); - write_log (L"RDB: '%s' dostype=%08X. PartBlock=%d\n", s, dostype, partblock); - write_log (L"BlockSize: %d, Surfaces: %d, SectorsPerBlock %d\n", - get_long (pp + 20) * 4, get_long (pp + 28), get_long (pp + 32)); - write_log (L"SectorsPerTrack: %d, Reserved: %d, LowCyl %d, HighCyl %d\n", - get_long (pp + 36), get_long (pp + 40), get_long (pp + 52), get_long (pp + 56)); - write_log (L"Buffers: %d, BufMemType: %08x, MaxTransfer: %08x, BootPri: %d\n", - get_long (pp + 60), get_long (pp + 64), get_long (pp + 68), get_long (pp + 76)); - xfree (s); + TCHAR *s = au (name); + uae_u32 dostype = get_long (pp + 80); + write_log (L"RDB: '%s' dostype=%08X. PartBlock=%d\n", s, dostype, partblock); + write_log (L"BlockSize: %d, Surfaces: %d, SectorsPerBlock %d\n", + get_long (pp + 20) * 4, get_long (pp + 28), get_long (pp + 32)); + write_log (L"SectorsPerTrack: %d, Reserved: %d, LowCyl %d, HighCyl %d\n", + get_long (pp + 36), get_long (pp + 40), get_long (pp + 52), get_long (pp + 56)); + write_log (L"Buffers: %d, BufMemType: %08x, MaxTransfer: %08x, BootPri: %d\n", + get_long (pp + 60), get_long (pp + 64), get_long (pp + 68), get_long (pp + 76)); + xfree (s); } #define rdbmnt write_log (L"Mounting uaehf.device %d (%d) (size=%I64u):\n", unit_no, partnum, hfd->virtsize); static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacket) { - int lastblock = 63, blocksize, readblocksize, badblock, driveinitblock; - uae_u8 bufrdb[FILESYS_MAX_BLOCKSIZE], *buf = 0; - uae_u8 *fsmem = 0; - int rdblock, partblock, fileblock, lsegblock, i; - uae_u32 flags; - struct hardfiledata *hfd = &uip->hf; - uae_u32 dostype; - uaecptr fsres, fsnode; - int err = 0; - int oldversion, oldrevision; - int newversion, newrevision; - TCHAR *s; - - write_log (L"%s:\n", uip->rootdir); - if (hfd->drive_empty) { - rdbmnt - write_log (L"ignored, drive is empty\n"); - return -2; - } - if (hfd->blocksize == 0) { - rdbmnt - write_log (L"failed, blocksize == 0\n"); - return -1; - } - if (lastblock * hfd->blocksize > hfd->virtsize) { - rdbmnt - write_log (L"failed, too small (%d*%d > %I64u)\n", lastblock, hfd->blocksize, hfd->virtsize); - return -2; - } - for (rdblock = 0; rdblock < lastblock; rdblock++) { - hdf_read (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); - if (rdb_checksum ("RDSK", bufrdb, rdblock)) - break; - hdf_read (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); - if (!memcmp ("RDSK", bufrdb, 4)) { - bufrdb[0xdc] = 0; - bufrdb[0xdd] = 0; - bufrdb[0xde] = 0; - bufrdb[0xdf] = 0; - if (rdb_checksum ("RDSK", bufrdb, rdblock)) { - write_log (L"Windows 95/98/ME trashed RDB detected, fixing..\n"); - hdf_write (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); - break; - } + int lastblock = 63, blocksize, readblocksize, badblock, driveinitblock; + uae_u8 bufrdb[FILESYS_MAX_BLOCKSIZE], *buf = 0; + uae_u8 *fsmem = 0; + int rdblock, partblock, fileblock, lsegblock, i; + uae_u32 flags; + struct hardfiledata *hfd = &uip->hf; + uae_u32 dostype; + uaecptr fsres, fsnode; + int err = 0; + int oldversion, oldrevision; + int newversion, newrevision; + TCHAR *s; + + write_log (L"%s:\n", uip->rootdir); + if (hfd->drive_empty) { + rdbmnt + write_log (L"ignored, drive is empty\n"); + return -2; } - } - if (rdblock == lastblock) { - rdbmnt - write_log (L"failed, no RDB detected\n"); - return -2; - } - blocksize = rl (bufrdb + 16); - readblocksize = blocksize > hfd->blocksize ? blocksize : hfd->blocksize; - badblock = rl (bufrdb + 24); - if (badblock != -1) { - rdbmnt - write_log (L"RDB: badblock list is not yet supported. Contact the author.\n"); - return -2; - } - driveinitblock = rl (bufrdb + 36); - if (driveinitblock != -1) { + if (hfd->blocksize == 0) { + rdbmnt + write_log (L"failed, blocksize == 0\n"); + return -1; + } + if (lastblock * hfd->blocksize > hfd->virtsize) { + rdbmnt + write_log (L"failed, too small (%d*%d > %I64u)\n", lastblock, hfd->blocksize, hfd->virtsize); + return -2; + } + for (rdblock = 0; rdblock < lastblock; rdblock++) { + hdf_read (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); + if (rdb_checksum ("RDSK", bufrdb, rdblock)) + break; + hdf_read (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); + if (!memcmp ("RDSK", bufrdb, 4)) { + bufrdb[0xdc] = 0; + bufrdb[0xdd] = 0; + bufrdb[0xde] = 0; + bufrdb[0xdf] = 0; + if (rdb_checksum ("RDSK", bufrdb, rdblock)) { + write_log (L"Windows 95/98/ME trashed RDB detected, fixing..\n"); + hdf_write (hfd, bufrdb, rdblock * hfd->blocksize, hfd->blocksize); + break; + } + } + } + if (rdblock == lastblock) { + rdbmnt + write_log (L"failed, no RDB detected\n"); + return -2; + } + blocksize = rl (bufrdb + 16); + readblocksize = blocksize > hfd->blocksize ? blocksize : hfd->blocksize; + badblock = rl (bufrdb + 24); + if (badblock != -1) { + rdbmnt + write_log (L"RDB: badblock list is not yet supported. Contact the author.\n"); + return -2; + } + driveinitblock = rl (bufrdb + 36); + if (driveinitblock != -1) { + rdbmnt + write_log (L"RDB: driveinit is not yet supported. Contact the author.\n"); + return -2; + } + hfd->cylinders = rl (bufrdb + 64); + hfd->sectors = rl (bufrdb + 68); + hfd->heads = rl (bufrdb + 72); + fileblock = rl (bufrdb + 32); + + if (partnum == 0) { + write_log (L"RDB: RDSK detected at %d, FSHD=%d, C=%d S=%d H=%d\n", + rdblock, fileblock, hfd->cylinders, hfd->sectors, hfd->heads); + } + + buf = xmalloc (readblocksize); + for (i = 0; i <= partnum; i++) { + if (i == 0) + partblock = rl (bufrdb + 28); + else + partblock = rl (buf + 4 * 4); + if (!legalrdbblock (uip, partblock)) { + err = -2; + goto error; + } + memset (buf, 0, readblocksize); + hdf_read (hfd, buf, partblock * hfd->blocksize, readblocksize); + if (!rdb_checksum ("PART", buf, partblock)) { + err = -2; + goto error; + } + } + rdbmnt - write_log (L"RDB: driveinit is not yet supported. Contact the author.\n"); - return -2; - } - hfd->cylinders = rl (bufrdb + 64); - hfd->sectors = rl (bufrdb + 68); - hfd->heads = rl (bufrdb + 72); - fileblock = rl (bufrdb + 32); - - if (partnum == 0) { - write_log (L"RDB: RDSK detected at %d, FSHD=%d, C=%d S=%d H=%d\n", - rdblock, fileblock, hfd->cylinders, hfd->sectors, hfd->heads); - } - - buf = xmalloc (readblocksize); - for (i = 0; i <= partnum; i++) { - if (i == 0) - partblock = rl (bufrdb + 28); - else - partblock = rl (buf + 4 * 4); - if (!legalrdbblock (uip, partblock)) { - err = -2; - goto error; - } - memset (buf, 0, readblocksize); - hdf_read (hfd, buf, partblock * hfd->blocksize, readblocksize); - if (!rdb_checksum ("PART", buf, partblock)) { - err = -2; - goto error; - } - } - - rdbmnt - flags = rl (buf + 20); - if (flags & 2) { /* do not mount */ - err = -1; - write_log (L"RDB: Automount disabled, not mounting\n"); - goto error; - } - - if (!(flags & 1)) /* not bootable */ - m68k_dreg (regs, 7) = m68k_dreg (regs, 7) & ~1; - - buf[37 + buf[36]] = 0; /* zero terminate BSTR */ - s = au (buf + 37); - uip->rdb_devname_amiga[partnum] = ds (device_dupfix (get_long (parmpacket + PP_EXPLIB), s)); - xfree (s); - put_long (parmpacket, uip->rdb_devname_amiga[partnum]); /* name */ - put_long (parmpacket + 4, ROM_hardfile_resname); - put_long (parmpacket + 8, uip->devno); - put_long (parmpacket + 12, 0); /* Device flags */ - for (i = 0; i < PP_MAXSIZE; i++) - put_byte (parmpacket + 16 + i, buf[128 + i]); - dump_partinfo (buf + 37, uip->devno, parmpacket, partblock); - dostype = get_long (parmpacket + 80); - - if (dostype == 0) { - write_log (L"RDB: mount failed, dostype=0\n"); - err = -1; - goto error; - } - - if (hfd->cylinders * hfd->sectors * hfd->heads * blocksize > hfd->virtsize) - write_log (L"RDB: WARNING: end of partition > size of disk!\n"); - - err = 2; - - /* load custom filesystems if needed */ - if (fileblock == -1 || !legalrdbblock (uip, fileblock)) - goto error; - - fsres = get_long (parmpacket + PP_FSRES); - if (!fsres) { - write_log (L"RDB: FileSystem.resource not found, this shouldn't happen!\n"); - goto error; - } - fsnode = get_long (fsres + 18); - while (get_long (fsnode)) { - if (get_long (fsnode + 14) == dostype) - break; - fsnode = get_long (fsnode); - } - oldversion = oldrevision = -1; - if (get_long (fsnode)) { - oldversion = get_word (fsnode + 18); - oldrevision = get_word (fsnode + 20); - } else { - fsnode = 0; - } - - for (;;) { - if (fileblock == -1) { - if (!fsnode) - write_log (L"RDB: required FS %08X not in FileSystem.resource or in RDB\n", dostype); - goto error; - } - if (!legalrdbblock (uip, fileblock)) { - write_log (L"RDB: corrupt FSHD pointer %d\n", fileblock); - goto error; - } - memset (buf, 0, readblocksize); - hdf_read (hfd, buf, fileblock * hfd->blocksize, readblocksize); - if (!rdb_checksum ("FSHD", buf, fileblock)) { - write_log (L"RDB: checksum error in FSHD block %d\n", fileblock); - goto error; - } - fileblock = rl (buf + 16); - if ((dostype >> 8) == (rl (buf + 32) >> 8)) - break; - } - newversion = (buf[36] << 8) | buf[37]; - newrevision = (buf[38] << 8) | buf[39]; - - write_log (L"RDB: RDB filesystem %08X version %d.%d\n", dostype, newversion, newrevision); - if (fsnode) { - write_log (L"RDB: %08X in FileSystem.resource version %d.%d\n", dostype, oldversion, oldrevision); - } - if (newversion * 65536 + newrevision <= oldversion * 65536 + oldrevision && oldversion >= 0) { - write_log (L"RDB: FS in FileSystem.resource is newer or same, ignoring RDB filesystem\n"); - goto error; - } - - for (i = 0; i < 140; i++) - put_byte (parmpacket + PP_FSHDSTART + i, buf[32 + i]); - put_long (parmpacket + PP_FSHDSTART, dostype); - /* we found required FSHD block */ - fsmem = xmalloc (262144); - lsegblock = rl (buf + 72); - i = 0; - for (;;) { - int pb = lsegblock; - if (!legalrdbblock (uip, lsegblock)) - goto error; - memset (buf, 0, readblocksize); - hdf_read (hfd, buf, lsegblock * hfd->blocksize, readblocksize); - if (!rdb_checksum ("LSEG", buf, lsegblock)) - goto error; - lsegblock = rl (buf + 16); - if (lsegblock == pb) - goto error; - memcpy (fsmem + i * (blocksize - 20), buf + 20, blocksize - 20); - i++; - if (lsegblock == -1) - break; - } - write_log (L"RDB: Filesystem loaded, %d bytes\n", i * (blocksize - 20)); - put_long (parmpacket + PP_FSSIZE, i * (blocksize - 20)); /* RDB filesystem size hack */ - uip->rdb_filesysstore = fsmem; - uip->rdb_filesyssize = i * (blocksize - 20); - xfree (buf); - return 2; + flags = rl (buf + 20); + if (flags & 2) { /* do not mount */ + err = -1; + write_log (L"RDB: Automount disabled, not mounting\n"); + goto error; + } + + if (!(flags & 1)) /* not bootable */ + m68k_dreg (regs, 7) = m68k_dreg (regs, 7) & ~1; + + buf[37 + buf[36]] = 0; /* zero terminate BSTR */ + s = au (buf + 37); + uip->rdb_devname_amiga[partnum] = ds (device_dupfix (get_long (parmpacket + PP_EXPLIB), s)); + xfree (s); + put_long (parmpacket, uip->rdb_devname_amiga[partnum]); /* name */ + put_long (parmpacket + 4, ROM_hardfile_resname); + put_long (parmpacket + 8, uip->devno); + put_long (parmpacket + 12, 0); /* Device flags */ + for (i = 0; i < PP_MAXSIZE; i++) + put_byte (parmpacket + 16 + i, buf[128 + i]); + dump_partinfo (buf + 37, uip->devno, parmpacket, partblock); + dostype = get_long (parmpacket + 80); + + if (dostype == 0) { + write_log (L"RDB: mount failed, dostype=0\n"); + err = -1; + goto error; + } + + if (hfd->cylinders * hfd->sectors * hfd->heads * blocksize > hfd->virtsize) + write_log (L"RDB: WARNING: end of partition > size of disk!\n"); + + err = 2; + + /* load custom filesystems if needed */ + if (fileblock == -1 || !legalrdbblock (uip, fileblock)) + goto error; + + fsres = get_long (parmpacket + PP_FSRES); + if (!fsres) { + write_log (L"RDB: FileSystem.resource not found, this shouldn't happen!\n"); + goto error; + } + fsnode = get_long (fsres + 18); + while (get_long (fsnode)) { + if (get_long (fsnode + 14) == dostype) + break; + fsnode = get_long (fsnode); + } + oldversion = oldrevision = -1; + if (get_long (fsnode)) { + oldversion = get_word (fsnode + 18); + oldrevision = get_word (fsnode + 20); + } else { + fsnode = 0; + } + + for (;;) { + if (fileblock == -1) { + if (!fsnode) + write_log (L"RDB: required FS %08X not in FileSystem.resource or in RDB\n", dostype); + goto error; + } + if (!legalrdbblock (uip, fileblock)) { + write_log (L"RDB: corrupt FSHD pointer %d\n", fileblock); + goto error; + } + memset (buf, 0, readblocksize); + hdf_read (hfd, buf, fileblock * hfd->blocksize, readblocksize); + if (!rdb_checksum ("FSHD", buf, fileblock)) { + write_log (L"RDB: checksum error in FSHD block %d\n", fileblock); + goto error; + } + fileblock = rl (buf + 16); + if ((dostype >> 8) == (rl (buf + 32) >> 8)) + break; + } + newversion = (buf[36] << 8) | buf[37]; + newrevision = (buf[38] << 8) | buf[39]; + + write_log (L"RDB: RDB filesystem %08X version %d.%d\n", dostype, newversion, newrevision); + if (fsnode) { + write_log (L"RDB: %08X in FileSystem.resource version %d.%d\n", dostype, oldversion, oldrevision); + } + if (newversion * 65536 + newrevision <= oldversion * 65536 + oldrevision && oldversion >= 0) { + write_log (L"RDB: FS in FileSystem.resource is newer or same, ignoring RDB filesystem\n"); + goto error; + } + + for (i = 0; i < 140; i++) + put_byte (parmpacket + PP_FSHDSTART + i, buf[32 + i]); + put_long (parmpacket + PP_FSHDSTART, dostype); + /* we found required FSHD block */ + fsmem = xmalloc (262144); + lsegblock = rl (buf + 72); + i = 0; + for (;;) { + int pb = lsegblock; + if (!legalrdbblock (uip, lsegblock)) + goto error; + memset (buf, 0, readblocksize); + hdf_read (hfd, buf, lsegblock * hfd->blocksize, readblocksize); + if (!rdb_checksum ("LSEG", buf, lsegblock)) + goto error; + lsegblock = rl (buf + 16); + if (lsegblock == pb) + goto error; + memcpy (fsmem + i * (blocksize - 20), buf + 20, blocksize - 20); + i++; + if (lsegblock == -1) + break; + } + write_log (L"RDB: Filesystem loaded, %d bytes\n", i * (blocksize - 20)); + put_long (parmpacket + PP_FSSIZE, i * (blocksize - 20)); /* RDB filesystem size hack */ + uip->rdb_filesysstore = fsmem; + uip->rdb_filesyssize = i * (blocksize - 20); + xfree (buf); + return 2; error: - xfree (buf); - xfree (fsmem); - return err; + xfree (buf); + xfree (fsmem); + return err; } static void addfakefilesys (uaecptr parmpacket, uae_u32 dostype) { - int i; + int i; - for (i = 0; i < 140; i++) - put_byte (parmpacket + PP_FSHDSTART + i, 0); - put_long (parmpacket + 80, dostype); - put_long (parmpacket + PP_FSHDSTART, dostype); - put_long (parmpacket + PP_FSHDSTART + 8, 0x100 | (dostype == 0x444f5300 ? 0x0 : 0x80)); - put_long (parmpacket + PP_FSHDSTART + 44, 0xffffffff); + for (i = 0; i < 140; i++) + put_byte (parmpacket + PP_FSHDSTART + i, 0); + put_long (parmpacket + 80, dostype); + put_long (parmpacket + PP_FSHDSTART, dostype); + put_long (parmpacket + PP_FSHDSTART + 8, 0x100 | (dostype == 0x444f5300 ? 0x0 : 0x80)); + put_long (parmpacket + PP_FSHDSTART + 44, 0xffffffff); } static int dofakefilesys (UnitInfo *uip, uaecptr parmpacket) { - int i, size; - TCHAR tmp[MAX_DPATH]; - uae_u8 buf[512]; - struct zfile *zf; - uae_u32 dostype, fsres, fsnode; + int i, size; + TCHAR tmp[MAX_DPATH]; + uae_u8 buf[512]; + struct zfile *zf; + uae_u32 dostype, fsres, fsnode; + + memset (buf, 0, 4); + hdf_read (&uip->hf, buf, 0, 512); + dostype = (buf[0] << 24) | (buf[1] << 16) |(buf[2] << 8) | buf[3]; + if (dostype == 0) + return FILESYS_HARDFILE; + fsres = get_long (parmpacket + PP_FSRES); + fsnode = get_long (fsres + 18); + while (get_long (fsnode)) { + if (get_long (fsnode + 14) == dostype) { + if (kickstart_version < 36) { + addfakefilesys (parmpacket, dostype); + } else if ((dostype & 0xffffff00) != 0x444f5300) { + addfakefilesys (parmpacket, dostype); + } + return FILESYS_HARDFILE; + } + fsnode = get_long (fsnode); + } + + tmp[0] = 0; + if (uip->filesysdir && _tcslen (uip->filesysdir) > 0) { + _tcscpy (tmp, uip->filesysdir); + } else if ((dostype & 0xffffff00) == 0x444f5300) { + _tcscpy (tmp, currprefs.romfile); + i = _tcslen (tmp); + while (i > 0 && tmp[i - 1] != '/' && tmp[i - 1] != '\\') + i--; + _tcscpy (tmp + i, L"FastFileSystem"); + } + if (tmp[0] == 0) { + write_log (L"RDB: no filesystem for dostype 0x%08X\n", dostype); + if ((dostype & 0xffffff00) == 0x444f5300) + return FILESYS_HARDFILE; + write_log (L"RDB: mounted without filesys\n"); + return FILESYS_HARDFILE; + } + write_log (L"RDB: fakefilesys, trying to load '%s', dostype 0x%08X\n", tmp, dostype); + zf = zfile_fopen (tmp, L"rb", ZFD_NORMAL); + if (!zf) { + write_log (L"RDB: filesys not found\n"); + if ((dostype & 0xffffff00) == 0x444f5300) + return FILESYS_HARDFILE; + write_log (L"RDB: mounted without filesys\n"); + return FILESYS_HARDFILE; + } - memset (buf, 0, 4); - hdf_read (&uip->hf, buf, 0, 512); - dostype = (buf[0] << 24) | (buf[1] << 16) |(buf[2] << 8) | buf[3]; - if (dostype == 0) + zfile_fseek (zf, 0, SEEK_END); + size = zfile_ftell (zf); + if (size > 0) { + zfile_fseek (zf, 0, SEEK_SET); + uip->rdb_filesysstore = xmalloc (size); + zfile_fread (uip->rdb_filesysstore, size, 1, zf); + } + zfile_fclose (zf); + uip->rdb_filesyssize = size; + put_long (parmpacket + PP_FSSIZE, uip->rdb_filesyssize); + addfakefilesys (parmpacket, dostype); + write_log (L"HDF: faked RDB filesystem %08X loaded\n", dostype); return FILESYS_HARDFILE; - fsres = get_long (parmpacket + PP_FSRES); - fsnode = get_long (fsres + 18); - while (get_long (fsnode)) { - if (get_long (fsnode + 14) == dostype) { - if (kickstart_version < 36) { - addfakefilesys (parmpacket, dostype); - } else if ((dostype & 0xffffff00) != 0x444f5300) { - addfakefilesys (parmpacket, dostype); - } - return FILESYS_HARDFILE; - } - fsnode = get_long (fsnode); - } - - tmp[0] = 0; - if (uip->filesysdir && _tcslen (uip->filesysdir) > 0) { - _tcscpy (tmp, uip->filesysdir); - } else if ((dostype & 0xffffff00) == 0x444f5300) { - _tcscpy (tmp, currprefs.romfile); - i = _tcslen (tmp); - while (i > 0 && tmp[i - 1] != '/' && tmp[i - 1] != '\\') - i--; - _tcscpy (tmp + i, L"FastFileSystem"); - } - if (tmp[0] == 0) { - write_log (L"RDB: no filesystem for dostype 0x%08X\n", dostype); - if ((dostype & 0xffffff00) == 0x444f5300) - return FILESYS_HARDFILE; - return -1; - } - write_log (L"RDB: fakefilesys, trying to load '%s', dostype 0x%08X\n", tmp, dostype); - zf = zfile_fopen (tmp, L"rb", ZFD_NORMAL); - if (!zf) { - write_log (L"RDB: filesys not found\n"); - if ((dostype & 0xffffff00) == 0x444f5300) - return FILESYS_HARDFILE; - return -1; - } - - zfile_fseek (zf, 0, SEEK_END); - size = zfile_ftell (zf); - if (size > 0) { - zfile_fseek (zf, 0, SEEK_SET); - uip->rdb_filesysstore = xmalloc (size); - zfile_fread (uip->rdb_filesysstore, size, 1, zf); - } - zfile_fclose (zf); - uip->rdb_filesyssize = size; - put_long (parmpacket + PP_FSSIZE, uip->rdb_filesyssize); - addfakefilesys (parmpacket, dostype); - write_log (L"HDF: faked RDB filesystem %08X loaded\n", dostype); - return FILESYS_HARDFILE; } static void get_new_device (int type, uaecptr parmpacket, TCHAR **devname, uaecptr *devname_amiga, int unit_no) { - TCHAR buffer[80]; - uaecptr expbase = get_long (parmpacket + PP_EXPLIB); + TCHAR buffer[80]; + uaecptr expbase = get_long (parmpacket + PP_EXPLIB); - if (*devname == 0 || _tcslen (*devname) == 0) { - int un = unit_no; - for (;;) { - _stprintf (buffer, L"DH%d", un++); - if (!device_isdup (expbase, buffer)) - break; + if (*devname == 0 || _tcslen (*devname) == 0) { + int un = unit_no; + for (;;) { + _stprintf (buffer, L"DH%d", un++); + if (!device_isdup (expbase, buffer)) + break; + } + } else { + _tcscpy (buffer, *devname); } - } else { - _tcscpy (buffer, *devname); - } - *devname_amiga = ds (device_dupfix (expbase, buffer)); - if (type == FILESYS_VIRTUAL) - write_log (L"FS: mounted virtual unit %s (%s)\n", buffer, mountinfo.ui[unit_no].rootdir); - else - write_log (L"FS: mounted HDF unit %s (%04x-%08x, %s)\n", buffer, - (uae_u32)(mountinfo.ui[unit_no].hf.virtsize >> 32), - (uae_u32)(mountinfo.ui[unit_no].hf.virtsize), - mountinfo.ui[unit_no].rootdir); + *devname_amiga = ds (device_dupfix (expbase, buffer)); + if (type == FILESYS_VIRTUAL) + write_log (L"FS: mounted virtual unit %s (%s)\n", buffer, mountinfo.ui[unit_no].rootdir); + else + write_log (L"FS: mounted HDF unit %s (%04x-%08x, %s)\n", buffer, + (uae_u32)(mountinfo.ui[unit_no].hf.virtsize >> 32), + (uae_u32)(mountinfo.ui[unit_no].hf.virtsize), + mountinfo.ui[unit_no].rootdir); } /* Fill in per-unit fields of a parampacket */ static uae_u32 REGPARAM2 filesys_dev_storeinfo (TrapContext *context) { - UnitInfo *uip = mountinfo.ui; - int no = m68k_dreg (regs, 6); - int unit_no = no & 65535; - int sub_no = no >> 16; - int type = is_hardfile (unit_no); - uaecptr parmpacket = m68k_areg (regs, 0); - - if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE) { - /* RDB hardfile */ + UnitInfo *uip = mountinfo.ui; + int no = m68k_dreg (regs, 6); + int unit_no = no & 65535; + int sub_no = no >> 16; + int type = is_hardfile (unit_no); + uaecptr parmpacket = m68k_areg (regs, 0); + + if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE) { + /* RDB hardfile */ + uip[unit_no].devno = unit_no; + return rdb_mount (&uip[unit_no], unit_no, sub_no, parmpacket); + } + if (sub_no) + return -2; + write_log (L"Mounting uaehf.device %d (%d):\n", unit_no, sub_no); + get_new_device (type, parmpacket, &uip[unit_no].devname, &uip[unit_no].devname_amiga, unit_no); uip[unit_no].devno = unit_no; - return rdb_mount (&uip[unit_no], unit_no, sub_no, parmpacket); - } - if (sub_no) - return -2; - write_log (L"Mounting uaehf.device %d (%d):\n", unit_no, sub_no); - get_new_device (type, parmpacket, &uip[unit_no].devname, &uip[unit_no].devname_amiga, unit_no); - uip[unit_no].devno = unit_no; - put_long (parmpacket, uip[unit_no].devname_amiga); - put_long (parmpacket + 4, type != FILESYS_VIRTUAL ? ROM_hardfile_resname : fsdevname); - put_long (parmpacket + 8, uip[unit_no].devno); - put_long (parmpacket + 12, 0); /* Device flags */ - put_long (parmpacket + 16, 16); /* Env. size */ - put_long (parmpacket + 20, uip[unit_no].hf.blocksize >> 2); /* longwords per block */ - put_long (parmpacket + 24, 0); /* unused */ - put_long (parmpacket + 28, uip[unit_no].hf.surfaces); /* heads */ - put_long (parmpacket + 32, 1); /* sectors per block */ - put_long (parmpacket + 36, uip[unit_no].hf.secspertrack); /* sectors per track */ - put_long (parmpacket + 40, uip[unit_no].hf.reservedblocks); /* reserved blocks */ - put_long (parmpacket + 44, 0); /* unused */ - put_long (parmpacket + 48, 0); /* interleave */ - put_long (parmpacket + 52, 0); /* lowCyl */ - put_long (parmpacket + 56, uip[unit_no].hf.nrcyls <= 0 ? 0 : uip[unit_no].hf.nrcyls - 1); /* hiCyl */ - put_long (parmpacket + 60, 50); /* Number of buffers */ - put_long (parmpacket + 64, 0); /* Buffer mem type */ - put_long (parmpacket + 68, 0x7FFFFFFF); /* largest transfer */ - put_long (parmpacket + 72, ~1); /* addMask (?) */ - put_long (parmpacket + 76, uip[unit_no].bootpri); /* bootPri */ - put_long (parmpacket + 80, 0x444f5300); /* DOS\0 */ - if (type == FILESYS_HARDFILE) - type = dofakefilesys (&uip[unit_no], parmpacket); - if (uip[unit_no].bootpri < -127) - m68k_dreg (regs, 7) = m68k_dreg (regs, 7) & ~1; /* do not boot */ - if (uip[unit_no].bootpri < -128) - return -1; /* do not mount */ - return type; + put_long (parmpacket, uip[unit_no].devname_amiga); + put_long (parmpacket + 4, type != FILESYS_VIRTUAL ? ROM_hardfile_resname : fsdevname); + put_long (parmpacket + 8, uip[unit_no].devno); + put_long (parmpacket + 12, 0); /* Device flags */ + put_long (parmpacket + 16, 16); /* Env. size */ + put_long (parmpacket + 20, uip[unit_no].hf.blocksize >> 2); /* longwords per block */ + put_long (parmpacket + 24, 0); /* unused */ + put_long (parmpacket + 28, uip[unit_no].hf.surfaces); /* heads */ + put_long (parmpacket + 32, 1); /* sectors per block */ + put_long (parmpacket + 36, uip[unit_no].hf.secspertrack); /* sectors per track */ + put_long (parmpacket + 40, uip[unit_no].hf.reservedblocks); /* reserved blocks */ + put_long (parmpacket + 44, 0); /* unused */ + put_long (parmpacket + 48, 0); /* interleave */ + put_long (parmpacket + 52, 0); /* lowCyl */ + put_long (parmpacket + 56, uip[unit_no].hf.nrcyls <= 0 ? 0 : uip[unit_no].hf.nrcyls - 1); /* hiCyl */ + put_long (parmpacket + 60, 50); /* Number of buffers */ + put_long (parmpacket + 64, 0); /* Buffer mem type */ + put_long (parmpacket + 68, 0x7FFFFFFF); /* largest transfer */ + put_long (parmpacket + 72, ~1); /* addMask (?) */ + put_long (parmpacket + 76, uip[unit_no].bootpri); /* bootPri */ + put_long (parmpacket + 80, 0x444f5300); /* DOS\0 */ + if (type == FILESYS_HARDFILE) + type = dofakefilesys (&uip[unit_no], parmpacket); + if (uip[unit_no].bootpri < -127) + m68k_dreg (regs, 7) = m68k_dreg (regs, 7) & ~1; /* do not boot */ + if (uip[unit_no].bootpri < -128) + return -1; /* do not mount */ + return type; } static uae_u32 REGPARAM2 mousehack_done (TrapContext *context) { - int mode = m68k_dreg (regs, 1); - if (mode < 10) { - uaecptr diminfo = m68k_areg (regs, 2); - uaecptr dispinfo = m68k_areg (regs, 3); - uaecptr vp = m68k_areg (regs, 4); - input_mousehack_status (mode, diminfo, dispinfo, vp, m68k_dreg (regs, 2)); - } else if (mode == 10) { - amiga_clipboard_die (); - } else if (mode == 11) { - amiga_clipboard_got_data (m68k_areg (regs, 2), m68k_dreg (regs, 2), m68k_dreg (regs, 0) + 8); - } else if (mode == 12) { - amiga_clipboard_want_data (); - } else if (mode == 13) { - return amiga_clipboard_proc_start (); - } else if (mode == 14) { - amiga_clipboard_task_start (m68k_dreg (regs, 0)); - } else if (mode == 15) { - amiga_clipboard_init (); - } else if (mode == 16) { - uaecptr a2 = m68k_areg (regs, 2); - input_mousehack_mouseoffset (a2); - } - return 1; + int mode = m68k_dreg (regs, 1); + if (mode < 10) { + uaecptr diminfo = m68k_areg (regs, 2); + uaecptr dispinfo = m68k_areg (regs, 3); + uaecptr vp = m68k_areg (regs, 4); + input_mousehack_status (mode, diminfo, dispinfo, vp, m68k_dreg (regs, 2)); + } else if (mode == 10) { + amiga_clipboard_die (); + } else if (mode == 11) { + amiga_clipboard_got_data (m68k_areg (regs, 2), m68k_dreg (regs, 2), m68k_dreg (regs, 0) + 8); + } else if (mode == 12) { + amiga_clipboard_want_data (); + } else if (mode == 13) { + return amiga_clipboard_proc_start (); + } else if (mode == 14) { + amiga_clipboard_task_start (m68k_dreg (regs, 0)); + } else if (mode == 15) { + amiga_clipboard_init (); + } else if (mode == 16) { + uaecptr a2 = m68k_areg (regs, 2); + input_mousehack_mouseoffset (a2); + } + return 1; } void filesys_install (void) { - uaecptr loop; + uaecptr loop; - TRACE ((L"Installing filesystem\n")); + TRACE ((L"Installing filesystem\n")); - uae_sem_init (&singlethread_int_sem, 0, 1); - uae_sem_init (&test_sem, 0, 1); + uae_sem_init (&singlethread_int_sem, 0, 1); + uae_sem_init (&test_sem, 0, 1); - ROM_filesys_resname = ds(L"UAEunixfs.resource"); - ROM_filesys_resid = ds(L"UAE unixfs 0.4"); + ROM_filesys_resname = ds(L"UAEunixfs.resource"); + ROM_filesys_resid = ds(L"UAE unixfs 0.4"); - fsdevname = ds (L"uae.device"); /* does not really exist */ + fsdevname = ds (L"uae.device"); /* does not really exist */ - ROM_filesys_diagentry = here (); - calltrap (deftrap2 (filesys_diagentry, 0, L"filesys_diagentry")); - dw(0x4ED0); /* JMP (a0) - jump to code that inits Residents */ + ROM_filesys_diagentry = here (); + calltrap (deftrap2 (filesys_diagentry, 0, L"filesys_diagentry")); + dw(0x4ED0); /* JMP (a0) - jump to code that inits Residents */ - loop = here (); + loop = here (); - org (rtarea_base + 0xFF18); - calltrap (deftrap2 (filesys_dev_bootfilesys, 0, L"filesys_dev_bootfilesys")); - dw (RTS); + org (rtarea_base + 0xFF18); + calltrap (deftrap2 (filesys_dev_bootfilesys, 0, L"filesys_dev_bootfilesys")); + dw (RTS); - /* Special trap for the assembly make_dev routine */ - org (rtarea_base + 0xFF20); - calltrap (deftrap2 (filesys_dev_remember, 0, L"filesys_dev_remember")); - dw (RTS); + /* Special trap for the assembly make_dev routine */ + org (rtarea_base + 0xFF20); + calltrap (deftrap2 (filesys_dev_remember, 0, L"filesys_dev_remember")); + dw (RTS); - org (rtarea_base + 0xFF28); - calltrap (deftrap2 (filesys_dev_storeinfo, 0, L"filesys_dev_storeinfo")); - dw (RTS); + org (rtarea_base + 0xFF28); + calltrap (deftrap2 (filesys_dev_storeinfo, 0, L"filesys_dev_storeinfo")); + dw (RTS); - org (rtarea_base + 0xFF30); - calltrap (deftrap2 (filesys_handler, 0, L"filesys_handler")); - dw (RTS); + org (rtarea_base + 0xFF30); + calltrap (deftrap2 (filesys_handler, 0, L"filesys_handler")); + dw (RTS); - org (rtarea_base + 0xFF38); - calltrap (deftrap2 (mousehack_done, 0, L"mousehack_done")); - dw (RTS); + org (rtarea_base + 0xFF38); + calltrap (deftrap2 (mousehack_done, 0, L"mousehack_done")); + dw (RTS); - org (rtarea_base + 0xFF40); - calltrap (deftrap2 (startup_handler, 0, L"startup_handler")); - dw (RTS); + org (rtarea_base + 0xFF40); + calltrap (deftrap2 (startup_handler, 0, L"startup_handler")); + dw (RTS); - org (rtarea_base + 0xFF48); - calltrap (deftrap2 (filesys_init_storeinfo, TRAPFLAG_EXTRA_STACK, L"filesys_init_storeinfo")); - dw (RTS); + org (rtarea_base + 0xFF48); + calltrap (deftrap2 (filesys_init_storeinfo, TRAPFLAG_EXTRA_STACK, L"filesys_init_storeinfo")); + dw (RTS); - org (rtarea_base + 0xFF50); - calltrap (deftrap2 (exter_int_helper, 0, L"exter_int_helper")); - dw (RTS); + org (rtarea_base + 0xFF50); + calltrap (deftrap2 (exter_int_helper, 0, L"exter_int_helper")); + dw (RTS); - org (rtarea_base + 0xFF58); - calltrap (deftrap2 (exall_helper, 0, L"exall_helper")); - dw (RTS); + org (rtarea_base + 0xFF58); + calltrap (deftrap2 (exall_helper, 0, L"exall_helper")); + dw (RTS); - org (loop); + org (loop); } void filesys_install_code (void) { - uae_u32 a, b; + uae_u32 a, b; - bootrom_header = 3 * 4; - align(4); - a = here (); - #include "filesys_bootrom.c" + bootrom_header = 3 * 4; + align(4); + a = here (); +#include "filesys_bootrom.c" - bootrom_items = dlg (a + 8); - /* The last offset comes from the code itself, look for it near the top. */ - EXPANSION_bootcode = a + bootrom_header + bootrom_items * 4 - 4; - b = a + bootrom_header + 3 * 4 - 4; - filesys_initcode = a + dlg (b) + bootrom_header - 4; + bootrom_items = dlg (a + 8); + /* The last offset comes from the code itself, look for it near the top. */ + EXPANSION_bootcode = a + bootrom_header + bootrom_items * 4 - 4; + b = a + bootrom_header + 3 * 4 - 4; + filesys_initcode = a + dlg (b) + bootrom_header - 4; } #include "od-win32/win32_filesys.c" static uae_u8 *restore_filesys_hardfile (UnitInfo *ui, uae_u8 *src) { - struct hardfiledata *hfd = &ui->hf; - TCHAR *s; - - hfd->virtsize = restore_u64(); - hfd->offset = restore_u64(); - hfd->nrcyls = restore_u32(); - hfd->secspertrack = restore_u32(); - hfd->surfaces = restore_u32(); - hfd->reservedblocks = restore_u32(); - hfd->blocksize = restore_u32(); - hfd->readonly = restore_u32(); - hfd->flags = restore_u32(); - hfd->cylinders = restore_u32(); - hfd->sectors = restore_u32(); - hfd->heads = restore_u32(); - s = restore_string(); - _tcscpy (hfd->vendor_id, s); - xfree(s); - s = restore_string(); - _tcscpy (hfd->product_id, s); - xfree(s); - s = restore_string(); - _tcscpy (hfd->product_rev, s); - xfree(s); - s = restore_string(); - _tcscpy (hfd->device_name, s); - xfree(s); - return src; + struct hardfiledata *hfd = &ui->hf; + TCHAR *s; + + hfd->virtsize = restore_u64(); + hfd->offset = restore_u64(); + hfd->nrcyls = restore_u32(); + hfd->secspertrack = restore_u32(); + hfd->surfaces = restore_u32(); + hfd->reservedblocks = restore_u32(); + hfd->blocksize = restore_u32(); + hfd->readonly = restore_u32(); + hfd->flags = restore_u32(); + hfd->cylinders = restore_u32(); + hfd->sectors = restore_u32(); + hfd->heads = restore_u32(); + s = restore_string(); + _tcscpy (hfd->vendor_id, s); + xfree(s); + s = restore_string(); + _tcscpy (hfd->product_id, s); + xfree(s); + s = restore_string(); + _tcscpy (hfd->product_rev, s); + xfree(s); + s = restore_string(); + _tcscpy (hfd->device_name, s); + xfree(s); + return src; } static uae_u8 *save_filesys_hardfile (UnitInfo *ui, uae_u8 *dst) { - struct hardfiledata *hfd = &ui->hf; - - save_u64 (hfd->virtsize); - save_u64 (hfd->offset); - save_u32 (hfd->nrcyls); - save_u32 (hfd->secspertrack); - save_u32 (hfd->surfaces); - save_u32 (hfd->reservedblocks); - save_u32 (hfd->blocksize); - save_u32 (hfd->readonly); - save_u32 (hfd->flags); - save_u32 (hfd->cylinders); - save_u32 (hfd->sectors); - save_u32 (hfd->heads); - save_string (hfd->vendor_id); - save_string (hfd->product_id); - save_string (hfd->product_rev); - save_string (hfd->device_name); - return dst; + struct hardfiledata *hfd = &ui->hf; + + save_u64 (hfd->virtsize); + save_u64 (hfd->offset); + save_u32 (hfd->nrcyls); + save_u32 (hfd->secspertrack); + save_u32 (hfd->surfaces); + save_u32 (hfd->reservedblocks); + save_u32 (hfd->blocksize); + save_u32 (hfd->readonly); + save_u32 (hfd->flags); + save_u32 (hfd->cylinders); + save_u32 (hfd->sectors); + save_u32 (hfd->heads); + save_string (hfd->vendor_id); + save_string (hfd->product_id); + save_string (hfd->product_rev); + save_string (hfd->device_name); + return dst; } static a_inode *restore_filesys_get_base (Unit *u, TCHAR *npath) { - TCHAR *path, *p, *p2; - a_inode *a; - int cnt, err, i; + TCHAR *path, *p, *p2; + a_inode *a; + int cnt, err, i; - /* no '/' = parent is root */ - if (!_tcschr (npath, '/')) - return &u->rootnode; + /* no '/' = parent is root */ + if (!_tcschr (npath, '/')) + return &u->rootnode; + + /* iterate from root to last to previous path part, + * create ainos if not already created. + */ + path = xcalloc((_tcslen (npath) + 2) * sizeof (TCHAR), 1); + cnt = 1; + for (;;) { + _tcscpy (path, npath); + _tcscat (path, L"/"); + p = path; + for (i = 0; i < cnt ;i++) { + if (i > 0) + p++; + while (*p != '/' && *p != 0) + p++; + } + if (*p) { + *p = 0; + err = 0; + get_aino (u, &u->rootnode, path, &err); + if (err) { + write_log (L"*** FS: missing path '%s'!\n", path); + return NULL; + } + cnt++; + } else { + break; + } + } - /* iterate from root to last to previous path part, - * create ainos if not already created. - */ - path = xcalloc((_tcslen (npath) + 2) * sizeof (TCHAR), 1); - cnt = 1; - for (;;) { + /* find base (parent) of last path part */ _tcscpy (path, npath); - _tcscat (path, L"/"); p = path; - for (i = 0; i < cnt ;i++) { - if (i > 0) - p++; - while (*p != '/' && *p != 0) - p++; - } - if (*p) { - *p = 0; - err = 0; - get_aino (u, &u->rootnode, path, &err); - if (err) { - write_log (L"*** FS: missing path '%s'!\n", path); - return NULL; - } - cnt++; - } else { - break; - } - } - - /* find base (parent) of last path part */ - _tcscpy (path, npath); - p = path; - a = u->rootnode.child; - for (;;) { - if (*p == 0) { - write_log (L"*** FS: base aino NOT found '%s' ('%s')\n", a->nname, npath); - xfree (path); - return NULL; - } - p2 = p; - while(*p2 != '/' && *p2 != '\\' && *p2 != 0) - p2++; - *p2 = 0; - while (a) { - if (!same_aname(p, a->aname)) { - a = a->sibling; - continue; - } - p = p2 + 1; - if (*p == 0) { - write_log (L"FS: base aino found '%s' ('%s')\n", a->nname, npath); - xfree (path); - return a; - } - a = a->child; - break; - } - if (!a) { - write_log (L"*** FS: path part '%s' not found ('%s')\n", p, npath); - xfree (path); - return NULL; + a = u->rootnode.child; + for (;;) { + if (*p == 0) { + write_log (L"*** FS: base aino NOT found '%s' ('%s')\n", a->nname, npath); + xfree (path); + return NULL; + } + p2 = p; + while(*p2 != '/' && *p2 != '\\' && *p2 != 0) + p2++; + *p2 = 0; + while (a) { + if (!same_aname(p, a->aname)) { + a = a->sibling; + continue; + } + p = p2 + 1; + if (*p == 0) { + write_log (L"FS: base aino found '%s' ('%s')\n", a->nname, npath); + xfree (path); + return a; + } + a = a->child; + break; + } + if (!a) { + write_log (L"*** FS: path part '%s' not found ('%s')\n", p, npath); + xfree (path); + return NULL; + } } - } } static TCHAR *makenativepath (UnitInfo *ui, TCHAR *apath) { - int i; - TCHAR *pn; - /* create native path. FIXME: handle 'illegal' characters */ - pn = xcalloc ((_tcslen (apath) + 1 + _tcslen (ui->rootdir) + 1) * sizeof (TCHAR), 1); - _stprintf (pn, L"%s/%s", ui->rootdir, apath); - if (FSDB_DIR_SEPARATOR != '/') { - for (i = 0; i < _tcslen (pn); i++) { - if (pn[i] == '/') - pn[i] = FSDB_DIR_SEPARATOR; + int i; + TCHAR *pn; + /* create native path. FIXME: handle 'illegal' characters */ + pn = xcalloc ((_tcslen (apath) + 1 + _tcslen (ui->rootdir) + 1) * sizeof (TCHAR), 1); + _stprintf (pn, L"%s/%s", ui->rootdir, apath); + if (FSDB_DIR_SEPARATOR != '/') { + for (i = 0; i < _tcslen (pn); i++) { + if (pn[i] == '/') + pn[i] = FSDB_DIR_SEPARATOR; + } } - } - return pn; + return pn; } static uae_u8 *restore_aino (UnitInfo *ui, Unit *u, uae_u8 *src) { - TCHAR *p, *p2, *pn; - uae_u32 flags; - int missing; - a_inode *base, *a; - - missing = 0; - a = xcalloc (sizeof (a_inode), 1); - a->uniq = restore_u64 (); - a->locked_children = restore_u32 (); - a->exnext_count = restore_u32 (); - a->shlock = restore_u32 (); - flags = restore_u32 (); - if (flags & 1) - a->elock = 1; - /* full Amiga-side path without drive, eg. "C/SetPatch" */ - p = restore_string (); - /* root (p = volume label) */ - if (a->uniq == 0) { - a->nname = my_strdup (ui->rootdir); - a->aname = p; - a->dir = 1; - if (ui->volflags < 0) { - write_log (L"FS: Volume '%s' ('%s') missing!\n", a->aname, a->nname); + TCHAR *p, *p2, *pn; + uae_u32 flags; + int missing; + a_inode *base, *a; + + missing = 0; + a = xcalloc (sizeof (a_inode), 1); + a->uniq = restore_u64 (); + a->locked_children = restore_u32 (); + a->exnext_count = restore_u32 (); + a->shlock = restore_u32 (); + flags = restore_u32 (); + if (flags & 1) + a->elock = 1; + /* full Amiga-side path without drive, eg. "C/SetPatch" */ + p = restore_string (); + /* root (p = volume label) */ + if (a->uniq == 0) { + a->nname = my_strdup (ui->rootdir); + a->aname = p; + a->dir = 1; + if (ui->volflags < 0) { + write_log (L"FS: Volume '%s' ('%s') missing!\n", a->aname, a->nname); + } else { + a->volflags = ui->volflags; + recycle_aino (u, a); + write_log (L"FS: Lock (root) '%s' ('%s')\n", a->aname, a->nname); + } + return src; + } + p2 = _tcsrchr(p, '/'); + if (p2) + p2++; + else + p2 = p; + pn = makenativepath (ui, p); + a->nname = pn; + a->aname = my_strdup (p2); + /* find parent of a->aname (Already restored previously. I hope..) */ + if (p2 != p) + p2[-1] = 0; + base = restore_filesys_get_base (u, p); + xfree(p); + if (flags & 2) { + a->dir = 1; + if (!my_existsdir(a->nname)) + write_log (L"*** FS: Directory '%s' missing!\n", a->nname); + else + fsdb_clean_dir (a); + } else { + if (!my_existsfile(a->nname)) + write_log (L"*** FS: File '%s' missing!\n", a->nname); + } + if (base) { + fill_file_attrs (u, base, a); + init_child_aino_tree (u, base, a); + } else { + write_log (L"*** FS: parent directory missing '%s' ('%s')\n", a->aname, a->nname); + missing = 1; + } + if (missing) { + write_log (L"*** FS: Lock restore failed '%s' ('%s')\n", a->aname, a->nname); + xfree (a->nname); + xfree (a->aname); + xfree (a); } else { - a->volflags = ui->volflags; - recycle_aino (u, a); - write_log (L"FS: Lock (root) '%s' ('%s')\n", a->aname, a->nname); + write_log (L"FS: Lock '%s' ('%s')\n", a->aname, a->nname); + recycle_aino (u, a); } return src; - } - p2 = _tcsrchr(p, '/'); - if (p2) - p2++; - else - p2 = p; - pn = makenativepath (ui, p); - a->nname = pn; - a->aname = my_strdup (p2); - /* find parent of a->aname (Already restored previously. I hope..) */ - if (p2 != p) - p2[-1] = 0; - base = restore_filesys_get_base (u, p); - xfree(p); - if (flags & 2) { - a->dir = 1; - if (!my_existsdir(a->nname)) - write_log (L"*** FS: Directory '%s' missing!\n", a->nname); - else - fsdb_clean_dir (a); - } else { - if (!my_existsfile(a->nname)) - write_log (L"*** FS: File '%s' missing!\n", a->nname); - } - if (base) { - fill_file_attrs (u, base, a); - init_child_aino_tree (u, base, a); - } else { - write_log (L"*** FS: parent directory missing '%s' ('%s')\n", a->aname, a->nname); - missing = 1; - } - if (missing) { - write_log (L"*** FS: Lock restore failed '%s' ('%s')\n", a->aname, a->nname); - xfree (a->nname); - xfree (a->aname); - xfree (a); - } else { - write_log (L"FS: Lock '%s' ('%s')\n", a->aname, a->nname); - recycle_aino (u, a); - } - return src; } static uae_u8 *restore_key (UnitInfo *ui, Unit *u, uae_u8 *src) { - int savedsize, uniq; - TCHAR *p, *pn; - mode_t openmode; - DWORD err; - int missing; - a_inode *a; - Key *k; - - missing = 0; - k = xcalloc (sizeof (Key), 1); - k->uniq = restore_u64 (); - k->file_pos = restore_u32 (); - k->createmode = restore_u32 (); - k->dosmode = restore_u32 (); - savedsize = restore_u32 (); - uniq = restore_u64 (); - p = restore_string (); - restore_u64 (); - restore_u64 (); - pn = makenativepath (ui, p); - openmode = ((k->dosmode & A_FIBF_READ) == 0 ? O_WRONLY - : (k->dosmode & A_FIBF_WRITE) == 0 ? O_RDONLY - : O_RDWR); - write_log (L"FS: open file '%s' ('%s'), pos=%d\n", p, pn, k->file_pos); - a = get_aino (u, &u->rootnode, p, &err); - if (!a) - write_log (L"*** FS: Open file aino creation failed '%s'\n", p); - missing = 1; - if (a) { + int savedsize, uniq; + TCHAR *p, *pn; + mode_t openmode; + DWORD err; + int missing; + a_inode *a; + Key *k; + missing = 0; - k->aino = a; - if (a->uniq != uniq) - write_log (L"*** FS: Open file '%s' aino id %d != %d\n", p, uniq, a->uniq); - if (!my_existsfile(pn)) { - write_log (L"*** FS: Open file '%s' is missing, creating dummy file!\n", p); - k->fd = fs_open (u, pn, openmode | O_CREAT |O_BINARY); - if (k->fd) { - uae_u8 *buf = xcalloc (10000, 1); - int sp = savedsize; - while (sp) { - int s = sp >= 10000 ? 10000 : sp; - my_write(k->fd, buf, s); - sp -= s; + k = xcalloc (sizeof (Key), 1); + k->uniq = restore_u64 (); + k->file_pos = restore_u32 (); + k->createmode = restore_u32 (); + k->dosmode = restore_u32 (); + savedsize = restore_u32 (); + uniq = restore_u64 (); + p = restore_string (); + restore_u64 (); + restore_u64 (); + pn = makenativepath (ui, p); + openmode = ((k->dosmode & A_FIBF_READ) == 0 ? O_WRONLY + : (k->dosmode & A_FIBF_WRITE) == 0 ? O_RDONLY + : O_RDWR); + write_log (L"FS: open file '%s' ('%s'), pos=%d\n", p, pn, k->file_pos); + a = get_aino (u, &u->rootnode, p, &err); + if (!a) + write_log (L"*** FS: Open file aino creation failed '%s'\n", p); + missing = 1; + if (a) { + missing = 0; + k->aino = a; + if (a->uniq != uniq) + write_log (L"*** FS: Open file '%s' aino id %d != %d\n", p, uniq, a->uniq); + if (!my_existsfile(pn)) { + write_log (L"*** FS: Open file '%s' is missing, creating dummy file!\n", p); + k->fd = fs_open (u, pn, openmode | O_CREAT |O_BINARY); + if (k->fd) { + uae_u8 *buf = xcalloc (10000, 1); + int sp = savedsize; + while (sp) { + int s = sp >= 10000 ? 10000 : sp; + my_write(k->fd, buf, s); + sp -= s; + } + xfree(buf); + write_log (L"*** FS: dummy file created\n"); + } else { + write_log (L"*** FS: Open file '%s', couldn't create dummy file!\n", p); + } + } else { + k->fd = fs_open (u, pn, openmode | O_BINARY); + } + if (!k->fd) { + write_log (L"*** FS: Open file '%s' failed to open!\n", p); + missing = 1; + } else { + uae_s64 s; + s = fs_lseek64 (u, k->fd, 0, SEEK_END); + if (s != savedsize) + write_log (L"FS: restored file '%s' size changed! orig=%d, now=%d!!\n", p, savedsize, s); + if (k->file_pos > s) { + write_log (L"FS: restored filepos larger than size of file '%s'!! %d > %d\n", p, k->file_pos, s); + k->file_pos = s; + } + fs_lseek64 (u,k->fd, k->file_pos, SEEK_SET); } - xfree(buf); - write_log (L"*** FS: dummy file created\n"); - } else { - write_log (L"*** FS: Open file '%s', couldn't create dummy file!\n", p); - } - } else { - k->fd = fs_open (u, pn, openmode | O_BINARY); } - if (!k->fd) { - write_log (L"*** FS: Open file '%s' failed to open!\n", p); - missing = 1; + xfree (p); + if (missing) { + xfree(k); } else { - uae_s64 s; - s = fs_lseek64 (u, k->fd, 0, SEEK_END); - if (s != savedsize) - write_log (L"FS: restored file '%s' size changed! orig=%d, now=%d!!\n", p, savedsize, s); - if (k->file_pos > s) { - write_log (L"FS: restored filepos larger than size of file '%s'!! %d > %d\n", p, k->file_pos, s); - k->file_pos = s; - } - fs_lseek64 (u,k->fd, k->file_pos, SEEK_SET); - } - } - xfree (p); - if (missing) { - xfree(k); - } else { - k->next = u->keys; - u->keys = k; - } - return src; + k->next = u->keys; + u->keys = k; + } + return src; } static uae_u8 *restore_notify (UnitInfo *ui, Unit *u, uae_u8 *src) { - Notify *n = xcalloc (sizeof (Notify), 1); - uae_u32 hash; - TCHAR *s; - - n->notifyrequest = restore_u32 (); - s = restore_string (); - n->fullname = xmalloc ((_tcslen (ui->volname) + 2 + _tcslen (s) + 1) * sizeof (TCHAR)); - _stprintf (n->fullname, L"%s:%s", ui->volname, s); - xfree(s); - s = _tcsrchr (n->fullname, '/'); - if (s) - s++; - else - s = n->fullname; - n->partname = my_strdup (s); - hash = notifyhash (n->fullname); - n->next = u->notifyhash[hash]; - u->notifyhash[hash] = n; - write_log (L"FS: notify %08X '%s' '%s'\n", n->notifyrequest, n->fullname, n->partname); - return src; + Notify *n = xcalloc (sizeof (Notify), 1); + uae_u32 hash; + TCHAR *s; + + n->notifyrequest = restore_u32 (); + s = restore_string (); + n->fullname = xmalloc ((_tcslen (ui->volname) + 2 + _tcslen (s) + 1) * sizeof (TCHAR)); + _stprintf (n->fullname, L"%s:%s", ui->volname, s); + xfree(s); + s = _tcsrchr (n->fullname, '/'); + if (s) + s++; + else + s = n->fullname; + n->partname = my_strdup (s); + hash = notifyhash (n->fullname); + n->next = u->notifyhash[hash]; + u->notifyhash[hash] = n; + write_log (L"FS: notify %08X '%s' '%s'\n", n->notifyrequest, n->fullname, n->partname); + return src; } static uae_u8 *restore_exkey (UnitInfo *ui, Unit *u, uae_u8 *src) { - restore_u64 (); - restore_u64 (); - restore_u64 (); - return src; + restore_u64 (); + restore_u64 (); + restore_u64 (); + return src; } static uae_u8 *restore_filesys_virtual (UnitInfo *ui, uae_u8 *src, int num) { - Unit *u = startup_create_unit (ui, num); - int cnt; - - u->dosbase = restore_u32 (); - u->volume = restore_u32 (); - u->port = restore_u32 (); - u->locklist = restore_u32 (); - u->dummy_message = restore_u32 (); - u->cmds_sent = restore_u64 (); - u->cmds_complete = restore_u64 (); - u->cmds_acked = restore_u64 (); - u->next_exkey = restore_u32 (); - u->total_locked_ainos = restore_u32 (); - u->volflags = ui->volflags; + Unit *u = startup_create_unit (ui, num); + int cnt; + + u->dosbase = restore_u32 (); + u->volume = restore_u32 (); + u->port = restore_u32 (); + u->locklist = restore_u32 (); + u->dummy_message = restore_u32 (); + u->cmds_sent = restore_u64 (); + u->cmds_complete = restore_u64 (); + u->cmds_acked = restore_u64 (); + u->next_exkey = restore_u32 (); + u->total_locked_ainos = restore_u32 (); + u->volflags = ui->volflags; + + cnt = restore_u32 (); + write_log (L"FS: restoring %d locks\n", cnt); + while (cnt-- > 0) + src = restore_aino(ui, u, src); + + cnt = restore_u32 (); + write_log (L"FS: restoring %d open files\n", cnt); + while (cnt-- > 0) + src = restore_key(ui, u, src); + + cnt = restore_u32 (); + write_log (L"FS: restoring %d notifications\n", cnt); + while (cnt-- > 0) + src = restore_notify (ui, u, src); + + cnt = restore_u32 (); + write_log (L"FS: restoring %d exkeys\n", cnt); + while (cnt-- > 0) + src = restore_exkey (ui, u, src); - cnt = restore_u32 (); - write_log (L"FS: restoring %d locks\n", cnt); - while (cnt-- > 0) - src = restore_aino(ui, u, src); - - cnt = restore_u32 (); - write_log (L"FS: restoring %d open files\n", cnt); - while (cnt-- > 0) - src = restore_key(ui, u, src); - - cnt = restore_u32 (); - write_log (L"FS: restoring %d notifications\n", cnt); - while (cnt-- > 0) - src = restore_notify (ui, u, src); - - cnt = restore_u32 (); - write_log (L"FS: restoring %d exkeys\n", cnt); - while (cnt-- > 0) - src = restore_exkey (ui, u, src); - - return src; + return src; } static TCHAR *getfullaname(a_inode *a) { - TCHAR *p; - int first = 1; + TCHAR *p; + int first = 1; - p = xcalloc (2000 * sizeof (TCHAR), 1); - while (a) { - int len = _tcslen (a->aname); - memmove (p + len + 1, p, (_tcslen (p) + 1) * sizeof (TCHAR)); - memcpy (p, a->aname, _tcslen (a->aname) * sizeof (TCHAR)); - if (!first) - p[len] = '/'; - first = 0; - a = a->parent; - if (a && a->uniq == 0) - return p; - } - return p; + p = xcalloc (2000 * sizeof (TCHAR), 1); + while (a) { + int len = _tcslen (a->aname); + memmove (p + len + 1, p, (_tcslen (p) + 1) * sizeof (TCHAR)); + memcpy (p, a->aname, _tcslen (a->aname) * sizeof (TCHAR)); + if (!first) + p[len] = '/'; + first = 0; + a = a->parent; + if (a && a->uniq == 0) + return p; + } + return p; } /* scan and save all Lock()'d files */ static int recurse_aino (UnitInfo *ui, a_inode *a, int cnt, uae_u8 **dstp) { - uae_u8 *dst = NULL; - int dirty = 0; - a_inode *a2 = a; - - if (dstp) - dst = *dstp; - while (a) { - //write_log("recurse '%s' '%s' %d %08x\n", a->aname, a->nname, a->uniq, a->parent); - if (a->elock || a->shlock || a->uniq == 0) { - if (dst) { - TCHAR *fn; - write_log (L"%04x s=%d e=%d d=%d '%s' '%s'\n", a->uniq, a->shlock, a->elock, a->dir, a->aname, a->nname); - fn = getfullaname(a); - write_log (L"->'%s'\n", fn); - save_u64 (a->uniq); - save_u32 (a->locked_children); - save_u32 (a->exnext_count); - save_u32 (a->shlock); - save_u32 ((a->elock ? 1 : 0) | (a->dir ? 2 : 0)); - save_string (fn); - xfree(fn); - } - cnt++; - } - if (a->dirty) - dirty = 1; - if (a->child) - cnt = recurse_aino (ui, a->child, cnt, &dst); - a = a->sibling; - } - if (dirty && a2->parent) - fsdb_dir_writeback (a2->parent); - if (dst) - *dstp = dst; - return cnt; + uae_u8 *dst = NULL; + int dirty = 0; + a_inode *a2 = a; + + if (dstp) + dst = *dstp; + while (a) { + //write_log("recurse '%s' '%s' %d %08x\n", a->aname, a->nname, a->uniq, a->parent); + if (a->elock || a->shlock || a->uniq == 0) { + if (dst) { + TCHAR *fn; + write_log (L"%04x s=%d e=%d d=%d '%s' '%s'\n", a->uniq, a->shlock, a->elock, a->dir, a->aname, a->nname); + fn = getfullaname(a); + write_log (L"->'%s'\n", fn); + save_u64 (a->uniq); + save_u32 (a->locked_children); + save_u32 (a->exnext_count); + save_u32 (a->shlock); + save_u32 ((a->elock ? 1 : 0) | (a->dir ? 2 : 0)); + save_string (fn); + xfree(fn); + } + cnt++; + } + if (a->dirty) + dirty = 1; + if (a->child) + cnt = recurse_aino (ui, a->child, cnt, &dst); + a = a->sibling; + } + if (dirty && a2->parent) + fsdb_dir_writeback (a2->parent); + if (dst) + *dstp = dst; + return cnt; } static uae_u8 *save_key (uae_u8 *dst, Key *k) { - TCHAR *fn = getfullaname (k->aino); - uae_u64 size; - save_u64 (k->uniq); - save_u32 ((uae_u32)k->file_pos); - save_u32 (k->createmode); - save_u32 (k->dosmode); - size = my_lseek (k->fd, 0, SEEK_END); - save_u32 ((uae_u32)size); - save_u64 (k->aino->uniq); - my_lseek (k->fd, k->file_pos, SEEK_SET); - save_string (fn); - save_u64 (k->file_pos); - save_u64 (size); - write_log (L"'%s' uniq=%d size=%d seekpos=%d mode=%d dosmode=%d\n", - fn, k->uniq, size, k->file_pos, k->createmode, k->dosmode); - xfree (fn); - return dst; + TCHAR *fn = getfullaname (k->aino); + uae_u64 size; + save_u64 (k->uniq); + save_u32 ((uae_u32)k->file_pos); + save_u32 (k->createmode); + save_u32 (k->dosmode); + size = my_lseek (k->fd, 0, SEEK_END); + save_u32 ((uae_u32)size); + save_u64 (k->aino->uniq); + my_lseek (k->fd, k->file_pos, SEEK_SET); + save_string (fn); + save_u64 (k->file_pos); + save_u64 (size); + write_log (L"'%s' uniq=%d size=%d seekpos=%d mode=%d dosmode=%d\n", + fn, k->uniq, size, k->file_pos, k->createmode, k->dosmode); + xfree (fn); + return dst; } static uae_u8 *save_notify (UnitInfo *ui, uae_u8 *dst, Notify *n) { - TCHAR *s; - save_u32 (n->notifyrequest); - s = n->fullname; - if (_tcslen (s) >= _tcslen (ui->volname) && !_tcsncmp (n->fullname, ui->volname, _tcslen (ui->volname))) - s = n->fullname + _tcslen (ui->volname) + 1; - save_string (s); - write_log (L"FS: notify %08X '%s'\n", n->notifyrequest, n->fullname); - return dst; + TCHAR *s; + save_u32 (n->notifyrequest); + s = n->fullname; + if (_tcslen (s) >= _tcslen (ui->volname) && !_tcsncmp (n->fullname, ui->volname, _tcslen (ui->volname))) + s = n->fullname + _tcslen (ui->volname) + 1; + save_string (s); + write_log (L"FS: notify %08X '%s'\n", n->notifyrequest, n->fullname); + return dst; } static uae_u8 *save_exkey (uae_u8 *dst, ExamineKey *ek) { - save_u64 (ek->uniq); - save_u64 (ek->aino->uniq); - save_u64 (ek->curr_file->uniq); - return dst; + save_u64 (ek->uniq); + save_u64 (ek->aino->uniq); + save_u64 (ek->curr_file->uniq); + return dst; } static uae_u8 *save_filesys_virtual (UnitInfo *ui, uae_u8 *dst) { - Unit *u = ui->self; - Key *k; - int cnt, i, j; - - write_log (L"FSSAVE: '%s'\n", ui->devname); - save_u32 (u->dosbase); - save_u32 (u->volume); - save_u32 (u->port); - save_u32 (u->locklist); - save_u32 (u->dummy_message); - save_u64 (u->cmds_sent); - save_u64 (u->cmds_complete); - save_u64 (u->cmds_acked); - save_u32 (u->next_exkey); - save_u32 (u->total_locked_ainos); - cnt = recurse_aino (ui, &u->rootnode, 0, NULL); - save_u32 (cnt); - write_log (L"%d open locks\n", cnt); - cnt = recurse_aino (ui, &u->rootnode, 0, &dst); - cnt = 0; - for (k = u->keys; k; k = k->next) - cnt++; - save_u32 (cnt); - write_log (L"%d open files\n", cnt); - for (k = u->keys; k; k = k->next) - dst = save_key (dst, k); - for (j = 0; j < 2; j++) { - cnt = 0; - for (i = 0; i < NOTIFY_HASH_SIZE; i++) { - Notify *n = u->notifyhash[i]; - while (n) { - if (j > 0) - dst = save_notify (ui, dst, n); - cnt++; - n = n->next; - } - } - if (j == 0) { - save_u32 (cnt); - write_log (L"%d notify requests\n", cnt); - } - } - for (j = 0; j < 2; j++) { + Unit *u = ui->self; + Key *k; + int cnt, i, j; + + write_log (L"FSSAVE: '%s'\n", ui->devname); + save_u32 (u->dosbase); + save_u32 (u->volume); + save_u32 (u->port); + save_u32 (u->locklist); + save_u32 (u->dummy_message); + save_u64 (u->cmds_sent); + save_u64 (u->cmds_complete); + save_u64 (u->cmds_acked); + save_u32 (u->next_exkey); + save_u32 (u->total_locked_ainos); + cnt = recurse_aino (ui, &u->rootnode, 0, NULL); + save_u32 (cnt); + write_log (L"%d open locks\n", cnt); + cnt = recurse_aino (ui, &u->rootnode, 0, &dst); cnt = 0; - for (i = 0; i < EXKEYS; i++) { - ExamineKey *ek = &u->examine_keys[i]; - if (ek->uniq) { + for (k = u->keys; k; k = k->next) cnt++; - if (j > 0) - dst = save_exkey (dst, ek); - } + save_u32 (cnt); + write_log (L"%d open files\n", cnt); + for (k = u->keys; k; k = k->next) + dst = save_key (dst, k); + for (j = 0; j < 2; j++) { + cnt = 0; + for (i = 0; i < NOTIFY_HASH_SIZE; i++) { + Notify *n = u->notifyhash[i]; + while (n) { + if (j > 0) + dst = save_notify (ui, dst, n); + cnt++; + n = n->next; + } + } + if (j == 0) { + save_u32 (cnt); + write_log (L"%d notify requests\n", cnt); + } } - if (j == 0) { - save_u32 (cnt); - write_log (L"%d exkeys\n", cnt); + for (j = 0; j < 2; j++) { + cnt = 0; + for (i = 0; i < EXKEYS; i++) { + ExamineKey *ek = &u->examine_keys[i]; + if (ek->uniq) { + cnt++; + if (j > 0) + dst = save_exkey (dst, ek); + } + } + if (j == 0) { + save_u32 (cnt); + write_log (L"%d exkeys\n", cnt); + } } - } - write_log (L"END\n"); - return dst; + write_log (L"END\n"); + return dst; } uae_u8 *save_filesys_common (int *len) { - uae_u8 *dstbak, *dst; - if (nr_units () == 0) - return NULL; - dstbak = dst = xmalloc (1000); - save_u32 (2); - save_u64 (a_uniq); - save_u64 (key_uniq); - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + if (nr_units () == 0) + return NULL; + dstbak = dst = xmalloc (1000); + save_u32 (2); + save_u64 (a_uniq); + save_u64 (key_uniq); + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_filesys_common (uae_u8 *src) { - if (restore_u32 () != 2) + if (restore_u32 () != 2) + return src; + filesys_prepare_reset2 (); + filesys_reset2 (); + a_uniq = restore_u64 (); + key_uniq = restore_u64 (); return src; - filesys_prepare_reset2 (); - filesys_reset2 (); - a_uniq = restore_u64 (); - key_uniq = restore_u64 (); - return src; } uae_u8 *save_filesys (int num, int *len) { - uae_u8 *dstbak, *dst; - UnitInfo *ui; - int type = is_hardfile (num); + uae_u8 *dstbak, *dst; + UnitInfo *ui; + int type = is_hardfile (num); - ui = &mountinfo.ui[num]; - if (!ui->open) - return NULL; - /* not initialized yet, do not save */ - if (type == FILESYS_VIRTUAL && (ui->self == NULL || ui->volname == NULL)) - return NULL; - write_log (L"FS_FILESYS: '%s' '%s'\n", ui->devname, ui->volname); - dstbak = dst = xmalloc (100000); - save_u32 (2); /* version */ - save_u32 (ui->devno); - save_u16 (type); - save_string (ui->rootdir); - save_string (ui->devname); - save_string (ui->volname); - save_string (ui->filesysdir); - save_u8 (ui->bootpri); - save_u8 (ui->readonly); - save_u32 (ui->startup); - save_u32 (filesys_configdev); - if (type == FILESYS_VIRTUAL) - dst = save_filesys_virtual (ui, dst); - if (type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) - dst = save_filesys_hardfile (ui, dst); - *len = dst - dstbak; - return dstbak; + ui = &mountinfo.ui[num]; + if (!ui->open) + return NULL; + /* not initialized yet, do not save */ + if (type == FILESYS_VIRTUAL && (ui->self == NULL || ui->volname == NULL)) + return NULL; + write_log (L"FS_FILESYS: '%s' '%s'\n", ui->devname, ui->volname); + dstbak = dst = xmalloc (100000); + save_u32 (2); /* version */ + save_u32 (ui->devno); + save_u16 (type); + save_string (ui->rootdir); + save_string (ui->devname); + save_string (ui->volname); + save_string (ui->filesysdir); + save_u8 (ui->bootpri); + save_u8 (ui->readonly); + save_u32 (ui->startup); + save_u32 (filesys_configdev); + if (type == FILESYS_VIRTUAL) + dst = save_filesys_virtual (ui, dst); + if (type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) + dst = save_filesys_hardfile (ui, dst); + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_filesys (uae_u8 *src) { - int type, devno; - UnitInfo *ui; - TCHAR *devname = 0, *volname = 0, *rootdir = 0, *filesysdir = 0; - int bootpri, readonly; - - if (restore_u32 () != 2) - return src; - devno = restore_u32 (); - type = restore_u16 (); - rootdir = restore_string (); - devname = restore_string (); - volname = restore_string (); - filesysdir = restore_string (); - bootpri = restore_u8 (); - readonly = restore_u8 (); - ui = &mountinfo.ui[devno]; - ui->startup = restore_u32 (); - filesys_configdev = restore_u32 (); - if (type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) { - src = restore_filesys_hardfile (ui, src); - xfree (volname); - volname = NULL; - } - if (set_filesys_unit (devno, devname, volname, rootdir, readonly, - ui->hf.secspertrack, ui->hf.surfaces, ui->hf.reservedblocks, ui->hf.blocksize, - bootpri, 0, 1, filesysdir[0] ? filesysdir : NULL, 0, 0) < 0) { - write_log (L"filesys '%s' failed to restore\n", rootdir); - goto end; - } - if (type == FILESYS_VIRTUAL) - src = restore_filesys_virtual (ui, src, devno); - write_log (L"'%s' restored\n", rootdir); + int type, devno; + UnitInfo *ui; + TCHAR *devname = 0, *volname = 0, *rootdir = 0, *filesysdir = 0; + int bootpri, readonly; + + if (restore_u32 () != 2) + return src; + devno = restore_u32 (); + type = restore_u16 (); + rootdir = restore_string (); + devname = restore_string (); + volname = restore_string (); + filesysdir = restore_string (); + bootpri = restore_u8 (); + readonly = restore_u8 (); + ui = &mountinfo.ui[devno]; + ui->startup = restore_u32 (); + filesys_configdev = restore_u32 (); + if (type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) { + src = restore_filesys_hardfile (ui, src); + xfree (volname); + volname = NULL; + } + if (set_filesys_unit (devno, devname, volname, rootdir, readonly, + ui->hf.secspertrack, ui->hf.surfaces, ui->hf.reservedblocks, ui->hf.blocksize, + bootpri, 0, 1, filesysdir[0] ? filesysdir : NULL, 0, 0) < 0) { + write_log (L"filesys '%s' failed to restore\n", rootdir); + goto end; + } + if (type == FILESYS_VIRTUAL) + src = restore_filesys_virtual (ui, src, devno); + write_log (L"'%s' restored\n", rootdir); end: - xfree (rootdir); - xfree (devname); - xfree (volname); - xfree (filesysdir); - return src; + xfree (rootdir); + xfree (devname); + xfree (volname); + xfree (filesysdir); + return src; } int save_filesys_cando (void) { - if (nr_units () == 0) - return -1; - return filesys_in_interrupt ? 0 : 1; + if (nr_units () == 0) + return -1; + return filesys_in_interrupt ? 0 : 1; } diff --git a/fpp.c b/fpp.c index 11ce071e..e608532a 100644 --- a/fpp.c +++ b/fpp.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * MC68881 emulation - * - * Copyright 1996 Herman ten Brugge - * Modified 2005 Peter Keunecke - */ +/* +* UAE - The Un*x Amiga Emulator +* +* MC68881 emulation +* +* Copyright 1996 Herman ten Brugge +* Modified 2005 Peter Keunecke +*/ #define __USE_ISOC9X /* We might be able to pick up a NaN */ @@ -30,7 +30,7 @@ STATIC_INLINE int isinrom (void) { - return (munge24 (m68k_getpc ()) & 0xFFF80000) == 0xF80000 && !currprefs.mmu_model; + return (munge24 (m68k_getpc ()) & 0xFFF80000) == 0xF80000 && !currprefs.mmu_model; } static uae_u32 xhex_pi[] ={0x2168c235, 0xc90fdaa2, 0x4000}; @@ -114,1646 +114,1646 @@ float fp_1e0 = 1, fp_1e1 = 10, fp_1e2 = 100, fp_1e4 = 10000; #define MAKE_FPSR(r) (regs).fp_result=(r) static uae_u16 x87_cw_tab[] = { - 0x137f, 0x1f7f, 0x177f, 0x1b7f, /* Extended */ - 0x107f, 0x1c7f, 0x147f, 0x187f, /* Single */ - 0x127f, 0x1e7f, 0x167f, 0x1a7f, /* Double */ - 0x137f, 0x1f7f, 0x177f, 0x1b7f}; /* undefined */ - /* Nearest, toZero, Down, Up */ -static __inline__ void native_set_fpucw (uae_u32 m68k_cw) -{ + 0x137f, 0x1f7f, 0x177f, 0x1b7f, /* Extended */ + 0x107f, 0x1c7f, 0x147f, 0x187f, /* Single */ + 0x127f, 0x1e7f, 0x167f, 0x1a7f, /* Double */ + 0x137f, 0x1f7f, 0x177f, 0x1b7f}; /* undefined */ + /* Nearest, toZero, Down, Up */ + static __inline__ void native_set_fpucw (uae_u32 m68k_cw) + { #if USE_X86_FPUCW - uae_u16 x87_cw = x87_cw_tab[(m68k_cw >> 4) & 0xf]; + uae_u16 x87_cw = x87_cw_tab[(m68k_cw >> 4) & 0xf]; #if defined(X86_MSVC_ASSEMBLY) - __asm { - fldcw word ptr x87_cw - } + __asm { + fldcw word ptr x87_cw + } #elif defined(X86_ASSEMBLY) - __asm__ ("fldcw %0" : : "m" (*&x87_cw)); + __asm__ ("fldcw %0" : : "m" (*&x87_cw)); #endif #endif -} + } #if defined(uae_s64) /* Close enough for government work? */ -typedef uae_s64 tointtype; + typedef uae_s64 tointtype; #else -typedef uae_s32 tointtype; + typedef uae_s32 tointtype; #endif -STATIC_INLINE uae_u32 next_ilong_fpu (void) -{ - if (currprefs.mmu_model) - return next_ilong_mmu (); - else if (currprefs.cpu_cycle_exact) - return next_ilong_020ce (); - else - return next_ilong (); -} -STATIC_INLINE uae_u32 next_iword_fpu (void) -{ - if (currprefs.mmu_model) - return next_iword_mmu (); - else if (currprefs.cpu_cycle_exact) - return next_iword_020ce (); - else - return next_iword (); -} -STATIC_INLINE void put_long_fpu (uaecptr addr, uae_u32 v) -{ - if (currprefs.mmu_model) - put_long_mmu (addr, v); - else if (currprefs.cpu_cycle_exact) - put_long_ce020 (addr, v); - else - put_long (addr, v); -} -STATIC_INLINE uae_u32 get_long_fpu (uaecptr addr) -{ - if (currprefs.mmu_model) - return get_long_mmu (addr); - else if (currprefs.cpu_cycle_exact) - return get_long_ce020 (addr); - else - return get_long (addr); -} -STATIC_INLINE void put_word_fpu (uaecptr addr, uae_u32 v) -{ - if (currprefs.mmu_model) - put_word_mmu (addr, v); - else if (currprefs.cpu_cycle_exact) - put_word_ce020 (addr, v); - else - put_word (addr, v); -} -STATIC_INLINE uae_u32 get_word_fpu (uaecptr addr) -{ - if (currprefs.mmu_model) - return get_word_mmu (addr); - else if (currprefs.cpu_cycle_exact) - return get_word_ce020 (addr); - else - return get_word (addr); -} -STATIC_INLINE void put_byte_fpu (uaecptr addr, uae_u32 v) -{ - if (currprefs.mmu_model) - put_byte_mmu (addr, v); - else if (currprefs.cpu_cycle_exact) - put_byte_ce020 (addr, v); - else - put_byte (addr, v); -} -STATIC_INLINE uae_u32 get_byte_fpu (uaecptr addr) -{ - if (currprefs.mmu_model) - return get_byte_mmu (addr); - else if (currprefs.cpu_cycle_exact) - return get_byte_ce020 (addr); - else - return get_byte (addr); -} + STATIC_INLINE uae_u32 next_ilong_fpu (void) + { + if (currprefs.mmu_model) + return next_ilong_mmu (); + else if (currprefs.cpu_cycle_exact) + return next_ilong_020ce (); + else + return next_ilong (); + } + STATIC_INLINE uae_u32 next_iword_fpu (void) + { + if (currprefs.mmu_model) + return next_iword_mmu (); + else if (currprefs.cpu_cycle_exact) + return next_iword_020ce (); + else + return next_iword (); + } + STATIC_INLINE void put_long_fpu (uaecptr addr, uae_u32 v) + { + if (currprefs.mmu_model) + put_long_mmu (addr, v); + else if (currprefs.cpu_cycle_exact) + put_long_ce020 (addr, v); + else + put_long (addr, v); + } + STATIC_INLINE uae_u32 get_long_fpu (uaecptr addr) + { + if (currprefs.mmu_model) + return get_long_mmu (addr); + else if (currprefs.cpu_cycle_exact) + return get_long_ce020 (addr); + else + return get_long (addr); + } + STATIC_INLINE void put_word_fpu (uaecptr addr, uae_u32 v) + { + if (currprefs.mmu_model) + put_word_mmu (addr, v); + else if (currprefs.cpu_cycle_exact) + put_word_ce020 (addr, v); + else + put_word (addr, v); + } + STATIC_INLINE uae_u32 get_word_fpu (uaecptr addr) + { + if (currprefs.mmu_model) + return get_word_mmu (addr); + else if (currprefs.cpu_cycle_exact) + return get_word_ce020 (addr); + else + return get_word (addr); + } + STATIC_INLINE void put_byte_fpu (uaecptr addr, uae_u32 v) + { + if (currprefs.mmu_model) + put_byte_mmu (addr, v); + else if (currprefs.cpu_cycle_exact) + put_byte_ce020 (addr, v); + else + put_byte (addr, v); + } + STATIC_INLINE uae_u32 get_byte_fpu (uaecptr addr) + { + if (currprefs.mmu_model) + return get_byte_mmu (addr); + else if (currprefs.cpu_cycle_exact) + return get_byte_ce020 (addr); + else + return get_byte (addr); + } -static void fpu_op_illg (uae_u32 opcode, int pcoffset) -{ - if ((currprefs.cpu_model == 68060 && (currprefs.fpu_model == 0 || (regs.pcr & 2))) - || (currprefs.cpu_model == 68040 && currprefs.fpu_model == 0)) { - /* 68040 unimplemented/68060 FPU disabled exception. - * Line F exception with different stack frame.. */ - uaecptr newpc = m68k_getpc (); - uaecptr oldpc = newpc - pcoffset; - regs.t0 = regs.t1 = 0; - MakeSR (); - if (!regs.s) { - regs.usp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; + static void fpu_op_illg (uae_u32 opcode, int pcoffset) + { + if ((currprefs.cpu_model == 68060 && (currprefs.fpu_model == 0 || (regs.pcr & 2))) + || (currprefs.cpu_model == 68040 && currprefs.fpu_model == 0)) { + /* 68040 unimplemented/68060 FPU disabled exception. + * Line F exception with different stack frame.. */ + uaecptr newpc = m68k_getpc (); + uaecptr oldpc = newpc - pcoffset; + regs.t0 = regs.t1 = 0; + MakeSR (); + if (!regs.s) { + regs.usp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + } + regs.s = 1; + m68k_areg (regs, 7) -= 4; + put_long_fpu (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 4; + put_long_fpu (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 2; + put_word_fpu (m68k_areg (regs, 7), 0x4000 + 11 * 4); + m68k_areg (regs, 7) -= 4; + put_long_fpu (m68k_areg (regs, 7), newpc); + m68k_areg (regs, 7) -= 2; + put_word_fpu (m68k_areg (regs, 7), regs.sr); + write_log (L"68040/060 FPU disabled exception PC=%x\n", newpc); + newpc = get_long_fpu (regs.vbr + 11 * 4); + m68k_setpc (newpc); + set_special (SPCFLAG_END_COMPILE); + return; + } + op_illg (opcode); } - regs.s = 1; - m68k_areg (regs, 7) -= 4; - put_long_fpu (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 4; - put_long_fpu (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 2; - put_word_fpu (m68k_areg (regs, 7), 0x4000 + 11 * 4); - m68k_areg (regs, 7) -= 4; - put_long_fpu (m68k_areg (regs, 7), newpc); - m68k_areg (regs, 7) -= 2; - put_word_fpu (m68k_areg (regs, 7), regs.sr); - write_log (L"68040/060 FPU disabled exception PC=%x\n", newpc); - newpc = get_long_fpu (regs.vbr + 11 * 4); - m68k_setpc (newpc); - set_special (SPCFLAG_END_COMPILE); - return; - } - op_illg (opcode); -} -STATIC_INLINE int fault_if_no_fpu (uae_u32 opcode, int pcoffset) -{ - if ((regs.pcr & 2) || currprefs.fpu_model <= 0) { - fpu_op_illg (opcode, pcoffset); - return 1; - } - return 0; -} + STATIC_INLINE int fault_if_no_fpu (uae_u32 opcode, int pcoffset) + { + if ((regs.pcr & 2) || currprefs.fpu_model <= 0) { + fpu_op_illg (opcode, pcoffset); + return 1; + } + return 0; + } -static int get_fpu_version (void) -{ - int v = 0; - - if (currprefs.fpu_revision >= 0) - return currprefs.fpu_revision; - switch (currprefs.fpu_model) - { - case 68881: - v = 0x1f; - break; - case 68882: - v = 0x20; /* ??? */ - break; - case 68040: - v = 0x41; - break; - } - return v; -} + static int get_fpu_version (void) + { + int v = 0; + + if (currprefs.fpu_revision >= 0) + return currprefs.fpu_revision; + switch (currprefs.fpu_model) + { + case 68881: + v = 0x1f; + break; + case 68882: + v = 0x20; /* ??? */ + break; + case 68040: + v = 0x41; + break; + } + return v; + } #define fp_round_to_minus_infinity(x) fp_floor(x) #define fp_round_to_plus_infinity(x) fp_ceil(x) #define fp_round_to_zero(x) ((int)(x)) #define fp_round_to_nearest(x) ((int)((x) + 0.5)) -STATIC_INLINE tointtype toint (fptype src, fptype minval, fptype maxval) -{ - if (src < minval) - src = minval; - if (src > maxval) - src = maxval; + STATIC_INLINE tointtype toint (fptype src, fptype minval, fptype maxval) + { + if (src < minval) + src = minval; + if (src > maxval) + src = maxval; #if defined(X86_MSVC_ASSEMBLY) - { - fptype tmp_fp; - __asm { - fld LDPTR src - frndint - fstp LDPTR tmp_fp - } - return (tointtype)tmp_fp; - } + { + fptype tmp_fp; + __asm { + fld LDPTR src + frndint + fstp LDPTR tmp_fp + } + return (tointtype)tmp_fp; + } #else /* no X86_MSVC */ - switch (get_fpcr() & 0x30) { - case FPCR_ROUND_ZERO: - result = fp_round_to_zero(src); - break; - case FPCR_ROUND_MINF: - result = fp_round_to_minus_infinity(src); - break; - case FPCR_ROUND_NEAR: - result = fp_round_to_nearest(src); - break; - case FPCR_ROUND_PINF: - result = fp_round_to_plus_infinity(src); - break; - default: - result = src; /* should never be reached */ - break; - } - return result; + switch (get_fpcr() & 0x30) { + case FPCR_ROUND_ZERO: + result = fp_round_to_zero(src); + break; + case FPCR_ROUND_MINF: + result = fp_round_to_minus_infinity(src); + break; + case FPCR_ROUND_NEAR: + result = fp_round_to_nearest(src); + break; + case FPCR_ROUND_PINF: + result = fp_round_to_plus_infinity(src); + break; + default: + result = src; /* should never be reached */ + break; + } + return result; #endif -} + } -uae_u32 get_fpsr (void) -{ - uae_u32 answer = regs.fpsr & 0x00ffffff; + uae_u32 get_fpsr (void) + { + uae_u32 answer = regs.fpsr & 0x00ffffff; #ifdef HAVE_ISNAN - if (isnan (regs.fp_result)) - answer |= 0x01000000; - else + if (isnan (regs.fp_result)) + answer |= 0x01000000; + else #endif - { - if (regs.fp_result == 0) - answer |= 0x04000000; - else if (regs.fp_result < 0) - answer |= 0x08000000; + { + if (regs.fp_result == 0) + answer |= 0x04000000; + else if (regs.fp_result < 0) + answer |= 0x08000000; #ifdef HAVE_ISINF - if (isinf (regs.fp_result)) - answer |= 0x02000000; + if (isinf (regs.fp_result)) + answer |= 0x02000000; #endif - } - return answer; -} + } + return answer; + } -STATIC_INLINE void set_fpsr (uae_u32 x) -{ - 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_INLINE void set_fpsr (uae_u32 x) + { + regs.fpsr = x; -/* single : S 8*E 23*F */ -/* double : S 11*E 52*F */ -/* extended : S 15*E 64*F */ -/* E = 0 & F = 0 -> 0 */ -/* E = MAX & F = 0 -> Infin */ -/* E = MAX & F # 0 -> NotANumber */ -/* E = biased by 127 (single) ,1023 (double) ,16383 (extended) */ + 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_INLINE fptype to_pack (uae_u32 wrd1, uae_u32 wrd2, uae_u32 wrd3) -{ - fptype d; - char *cp; - char str[100]; - - cp = str; - if (wrd1 & 0x80000000) - *cp++ = '-'; - *cp++ = (wrd1 & 0xf) + '0'; - *cp++ = '.'; - *cp++ = ((wrd2 >> 28) & 0xf) + '0'; - *cp++ = ((wrd2 >> 24) & 0xf) + '0'; - *cp++ = ((wrd2 >> 20) & 0xf) + '0'; - *cp++ = ((wrd2 >> 16) & 0xf) + '0'; - *cp++ = ((wrd2 >> 12) & 0xf) + '0'; - *cp++ = ((wrd2 >> 8) & 0xf) + '0'; - *cp++ = ((wrd2 >> 4) & 0xf) + '0'; - *cp++ = ((wrd2 >> 0) & 0xf) + '0'; - *cp++ = ((wrd3 >> 28) & 0xf) + '0'; - *cp++ = ((wrd3 >> 24) & 0xf) + '0'; - *cp++ = ((wrd3 >> 20) & 0xf) + '0'; - *cp++ = ((wrd3 >> 16) & 0xf) + '0'; - *cp++ = ((wrd3 >> 12) & 0xf) + '0'; - *cp++ = ((wrd3 >> 8) & 0xf) + '0'; - *cp++ = ((wrd3 >> 4) & 0xf) + '0'; - *cp++ = ((wrd3 >> 0) & 0xf) + '0'; - *cp++ = 'E'; - if (wrd1 & 0x40000000) - *cp++ = '-'; - *cp++ = ((wrd1 >> 24) & 0xf) + '0'; - *cp++ = ((wrd1 >> 20) & 0xf) + '0'; - *cp++ = ((wrd1 >> 16) & 0xf) + '0'; - *cp = 0; - sscanf (str, "%le", &d); - return d; -} + /* single : S 8*E 23*F */ + /* double : S 11*E 52*F */ + /* extended : S 15*E 64*F */ + /* E = 0 & F = 0 -> 0 */ + /* E = MAX & F = 0 -> Infin */ + /* E = MAX & F # 0 -> NotANumber */ + /* E = biased by 127 (single) ,1023 (double) ,16383 (extended) */ -STATIC_INLINE void from_pack (fptype src, uae_u32 * wrd1, uae_u32 * wrd2, uae_u32 * wrd3) -{ - int i; - int t; - char *cp; - char str[100]; - - sprintf (str, "%.16e", src); - cp = str; - *wrd1 = *wrd2 = *wrd3 = 0; - if (*cp == '-') { - cp++; - *wrd1 = 0x80000000; - } - if (*cp == '+') - cp++; - *wrd1 |= (*cp++ - '0'); - if (*cp == '.') - cp++; - for (i = 0; i < 8; i++) { - *wrd2 <<= 4; - if (*cp >= '0' && *cp <= '9') - *wrd2 |= *cp++ - '0'; - } - for (i = 0; i < 8; i++) { - *wrd3 <<= 4; - if (*cp >= '0' && *cp <= '9') - *wrd3 |= *cp++ - '0'; - } - if (*cp == 'e' || *cp == 'E') { - cp++; - if (*cp == '-') { - cp++; - *wrd1 |= 0x40000000; - } - if (*cp == '+') - cp++; - t = 0; - for (i = 0; i < 3; i++) { - if (*cp >= '0' && *cp <= '9') - t = (t << 4) | (*cp++ - '0'); + STATIC_INLINE fptype to_pack (uae_u32 wrd1, uae_u32 wrd2, uae_u32 wrd3) + { + fptype d; + char *cp; + char str[100]; + + cp = str; + if (wrd1 & 0x80000000) + *cp++ = '-'; + *cp++ = (wrd1 & 0xf) + '0'; + *cp++ = '.'; + *cp++ = ((wrd2 >> 28) & 0xf) + '0'; + *cp++ = ((wrd2 >> 24) & 0xf) + '0'; + *cp++ = ((wrd2 >> 20) & 0xf) + '0'; + *cp++ = ((wrd2 >> 16) & 0xf) + '0'; + *cp++ = ((wrd2 >> 12) & 0xf) + '0'; + *cp++ = ((wrd2 >> 8) & 0xf) + '0'; + *cp++ = ((wrd2 >> 4) & 0xf) + '0'; + *cp++ = ((wrd2 >> 0) & 0xf) + '0'; + *cp++ = ((wrd3 >> 28) & 0xf) + '0'; + *cp++ = ((wrd3 >> 24) & 0xf) + '0'; + *cp++ = ((wrd3 >> 20) & 0xf) + '0'; + *cp++ = ((wrd3 >> 16) & 0xf) + '0'; + *cp++ = ((wrd3 >> 12) & 0xf) + '0'; + *cp++ = ((wrd3 >> 8) & 0xf) + '0'; + *cp++ = ((wrd3 >> 4) & 0xf) + '0'; + *cp++ = ((wrd3 >> 0) & 0xf) + '0'; + *cp++ = 'E'; + if (wrd1 & 0x40000000) + *cp++ = '-'; + *cp++ = ((wrd1 >> 24) & 0xf) + '0'; + *cp++ = ((wrd1 >> 20) & 0xf) + '0'; + *cp++ = ((wrd1 >> 16) & 0xf) + '0'; + *cp = 0; + sscanf (str, "%le", &d); + return d; } - *wrd1 |= t << 16; - } -} -STATIC_INLINE int get_fp_value (uae_u32 opcode, uae_u16 extra, fptype *src) -{ - uaecptr tmppc; - uae_u16 tmp; - int size, mode, reg; - uae_u32 ad = 0; - static const int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 }; - static const int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 }; - - if (!(extra & 0x4000)) { - *src = regs.fp[(extra >> 10) & 7]; - return 1; - } - mode = (opcode >> 3) & 7; - reg = opcode & 7; - size = (extra >> 10) & 7; - - switch (mode) { - case 0: - switch (size) { - case 6: - *src = (fptype) (uae_s8) m68k_dreg (regs, reg); - break; - case 4: - *src = (fptype) (uae_s16) m68k_dreg (regs, reg); - break; - case 0: - *src = (fptype) (uae_s32) m68k_dreg (regs, reg); - break; - case 1: - *src = to_single (m68k_dreg (regs, reg)); - break; - default: - return 0; - } - return 1; - case 1: - return 0; - case 2: - ad = m68k_areg (regs, reg); - break; - case 3: - ad = m68k_areg (regs, reg); - m68k_areg (regs, reg) += reg == 7 ? sz2[size] : sz1[size]; - break; - case 4: - m68k_areg (regs, reg) -= reg == 7 ? sz2[size] : sz1[size]; - ad = m68k_areg (regs, reg); - break; - case 5: - ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 6: - ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); - break; - case 7: - switch (reg) { - case 0: - ad = (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 1: - ad = next_ilong_fpu (); - break; - case 2: - ad = m68k_getpc (); - ad += (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 3: - tmppc = m68k_getpc (); - tmp = next_iword_fpu (); - ad = get_disp_ea_020 (tmppc, tmp); - break; - case 4: - ad = m68k_getpc (); - m68k_setpc (ad + sz2[size]); - if (size == 6) - ad++; - break; - default: - return 0; - } - } - switch (size) { - case 0: - *src = (fptype) (uae_s32) get_long_fpu (ad); - break; - case 1: - *src = to_single (get_long_fpu (ad)); - break; - case 2:{ - uae_u32 wrd1, wrd2, wrd3; - wrd1 = get_long_fpu (ad); - ad += 4; - wrd2 = get_long_fpu (ad); - ad += 4; - wrd3 = get_long_fpu (ad); - *src = to_exten (wrd1, wrd2, wrd3); - } - break; - case 3:{ - uae_u32 wrd1, wrd2, wrd3; - wrd1 = get_long_fpu (ad); - ad += 4; - wrd2 = get_long_fpu (ad); - ad += 4; - wrd3 = get_long_fpu (ad); - *src = to_pack (wrd1, wrd2, wrd3); + STATIC_INLINE void from_pack (fptype src, uae_u32 * wrd1, uae_u32 * wrd2, uae_u32 * wrd3) + { + int i; + int t; + char *cp; + char str[100]; + + sprintf (str, "%.16e", src); + cp = str; + *wrd1 = *wrd2 = *wrd3 = 0; + if (*cp == '-') { + cp++; + *wrd1 = 0x80000000; + } + if (*cp == '+') + cp++; + *wrd1 |= (*cp++ - '0'); + if (*cp == '.') + cp++; + for (i = 0; i < 8; i++) { + *wrd2 <<= 4; + if (*cp >= '0' && *cp <= '9') + *wrd2 |= *cp++ - '0'; + } + for (i = 0; i < 8; i++) { + *wrd3 <<= 4; + if (*cp >= '0' && *cp <= '9') + *wrd3 |= *cp++ - '0'; + } + if (*cp == 'e' || *cp == 'E') { + cp++; + if (*cp == '-') { + cp++; + *wrd1 |= 0x40000000; + } + if (*cp == '+') + cp++; + t = 0; + for (i = 0; i < 3; i++) { + if (*cp >= '0' && *cp <= '9') + t = (t << 4) | (*cp++ - '0'); + } + *wrd1 |= t << 16; + } } - break; - case 4: - *src = (fptype) (uae_s16) get_word_fpu (ad); - break; - case 5:{ - uae_u32 wrd1, wrd2; - wrd1 = get_long_fpu (ad); - ad += 4; - wrd2 = get_long_fpu (ad); - *src = to_double (wrd1, wrd2); + + STATIC_INLINE int get_fp_value (uae_u32 opcode, uae_u16 extra, fptype *src) + { + uaecptr tmppc; + uae_u16 tmp; + int size, mode, reg; + uae_u32 ad = 0; + static const int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 }; + static const int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 }; + + if (!(extra & 0x4000)) { + *src = regs.fp[(extra >> 10) & 7]; + return 1; + } + mode = (opcode >> 3) & 7; + reg = opcode & 7; + size = (extra >> 10) & 7; + + switch (mode) { + case 0: + switch (size) { + case 6: + *src = (fptype) (uae_s8) m68k_dreg (regs, reg); + break; + case 4: + *src = (fptype) (uae_s16) m68k_dreg (regs, reg); + break; + case 0: + *src = (fptype) (uae_s32) m68k_dreg (regs, reg); + break; + case 1: + *src = to_single (m68k_dreg (regs, reg)); + break; + default: + return 0; + } + return 1; + case 1: + return 0; + case 2: + ad = m68k_areg (regs, reg); + break; + case 3: + ad = m68k_areg (regs, reg); + m68k_areg (regs, reg) += reg == 7 ? sz2[size] : sz1[size]; + break; + case 4: + m68k_areg (regs, reg) -= reg == 7 ? sz2[size] : sz1[size]; + ad = m68k_areg (regs, reg); + break; + case 5: + ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 6: + ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); + break; + case 7: + switch (reg) { + case 0: + ad = (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 1: + ad = next_ilong_fpu (); + break; + case 2: + ad = m68k_getpc (); + ad += (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 3: + tmppc = m68k_getpc (); + tmp = next_iword_fpu (); + ad = get_disp_ea_020 (tmppc, tmp); + break; + case 4: + ad = m68k_getpc (); + m68k_setpc (ad + sz2[size]); + if (size == 6) + ad++; + break; + default: + return 0; + } + } + switch (size) { + case 0: + *src = (fptype) (uae_s32) get_long_fpu (ad); + break; + case 1: + *src = to_single (get_long_fpu (ad)); + break; + case 2:{ + uae_u32 wrd1, wrd2, wrd3; + wrd1 = get_long_fpu (ad); + ad += 4; + wrd2 = get_long_fpu (ad); + ad += 4; + wrd3 = get_long_fpu (ad); + *src = to_exten (wrd1, wrd2, wrd3); + } + break; + case 3:{ + uae_u32 wrd1, wrd2, wrd3; + wrd1 = get_long_fpu (ad); + ad += 4; + wrd2 = get_long_fpu (ad); + ad += 4; + wrd3 = get_long_fpu (ad); + *src = to_pack (wrd1, wrd2, wrd3); + } + break; + case 4: + *src = (fptype) (uae_s16) get_word_fpu (ad); + break; + case 5:{ + uae_u32 wrd1, wrd2; + wrd1 = get_long_fpu (ad); + ad += 4; + wrd2 = get_long_fpu (ad); + *src = to_double (wrd1, wrd2); + } + break; + case 6: + *src = (fptype) (uae_s8) get_byte_fpu (ad); + break; + default: + return 0; + } + return 1; } - break; - case 6: - *src = (fptype) (uae_s8) get_byte_fpu (ad); - break; - default: - return 0; - } - return 1; -} -STATIC_INLINE int put_fp_value (fptype value, uae_u32 opcode, uae_u16 extra) -{ - uae_u16 tmp; - uaecptr tmppc; - int size, mode, reg; - uae_u32 ad; - static int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 }; - static int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 }; + STATIC_INLINE int put_fp_value (fptype value, uae_u32 opcode, uae_u16 extra) + { + uae_u16 tmp; + uaecptr tmppc; + int size, mode, reg; + uae_u32 ad; + static int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 }; + static int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 }; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"PUTFP: %f %04X %04X\n", value, opcode, extra); + if (!isinrom ()) + write_log (L"PUTFP: %f %04X %04X\n", value, opcode, extra); #endif - if (!(extra & 0x4000)) { - regs.fp[(extra >> 10) & 7] = value; - return 1; - } - reg = opcode & 7; - mode = (opcode >> 3) & 7; - size = (extra >> 10) & 7; - ad = -1; - switch (mode) { - case 0: - switch (size) { - case 6: - m68k_dreg (regs, reg) = (uae_u32)(((toint (value, -128.0, 127.0) & 0xff) - | (m68k_dreg (regs, reg) & ~0xff))); - break; - case 4: - m68k_dreg (regs, reg) = (uae_u32)(((toint (value, -32768.0, 32767.0) & 0xffff) - | (m68k_dreg (regs, reg) & ~0xffff))); - break; - case 0: - m68k_dreg (regs, reg) = (uae_u32)toint (value, -2147483648.0, 2147483647.0); - break; - case 1: - m68k_dreg (regs, reg) = from_single (value); - break; - default: - return 0; - } - return 1; - case 1: - return 0; - case 2: - ad = m68k_areg (regs, reg); - break; - case 3: - ad = m68k_areg (regs, reg); - m68k_areg (regs, reg) += reg == 7 ? sz2[size] : sz1[size]; - break; - case 4: - m68k_areg (regs, reg) -= reg == 7 ? sz2[size] : sz1[size]; - ad = m68k_areg (regs, reg); - break; - case 5: - ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 6: - ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); - break; - case 7: - switch (reg) { - case 0: - ad = (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 1: - ad = next_ilong_fpu (); - break; - case 2: - ad = m68k_getpc (); - ad += (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 3: - tmppc = m68k_getpc (); - tmp = next_iword_fpu (); - ad = get_disp_ea_020 (tmppc, tmp); - break; - case 4: - ad = m68k_getpc (); - m68k_setpc (ad + sz2[size]); - break; - default: - return 0; - } - } - switch (size) { - case 0: - put_long_fpu (ad, (uae_u32)toint (value, -2147483648.0, 2147483647.0)); - break; - case 1: - put_long_fpu (ad, from_single (value)); - break; - case 2: - { - uae_u32 wrd1, wrd2, wrd3; - from_exten (value, &wrd1, &wrd2, &wrd3); - put_long_fpu (ad, wrd1); - ad += 4; - put_long_fpu (ad, wrd2); - ad += 4; - put_long_fpu (ad, wrd3); - } - break; - case 3: - { - uae_u32 wrd1, wrd2, wrd3; - from_pack (value, &wrd1, &wrd2, &wrd3); - put_long_fpu (ad, wrd1); - ad += 4; - put_long_fpu (ad, wrd2); - ad += 4; - put_long_fpu (ad, wrd3); - } - break; - case 4: - put_word_fpu (ad, (uae_s16) toint (value, -32768.0, 32767.0)); - break; - case 5:{ - uae_u32 wrd1, wrd2; - from_double (value, &wrd1, &wrd2); - put_long_fpu (ad, wrd1); - ad += 4; - put_long_fpu (ad, wrd2); + if (!(extra & 0x4000)) { + regs.fp[(extra >> 10) & 7] = value; + return 1; + } + reg = opcode & 7; + mode = (opcode >> 3) & 7; + size = (extra >> 10) & 7; + ad = -1; + switch (mode) { + case 0: + switch (size) { + case 6: + m68k_dreg (regs, reg) = (uae_u32)(((toint (value, -128.0, 127.0) & 0xff) + | (m68k_dreg (regs, reg) & ~0xff))); + break; + case 4: + m68k_dreg (regs, reg) = (uae_u32)(((toint (value, -32768.0, 32767.0) & 0xffff) + | (m68k_dreg (regs, reg) & ~0xffff))); + break; + case 0: + m68k_dreg (regs, reg) = (uae_u32)toint (value, -2147483648.0, 2147483647.0); + break; + case 1: + m68k_dreg (regs, reg) = from_single (value); + break; + default: + return 0; + } + return 1; + case 1: + return 0; + case 2: + ad = m68k_areg (regs, reg); + break; + case 3: + ad = m68k_areg (regs, reg); + m68k_areg (regs, reg) += reg == 7 ? sz2[size] : sz1[size]; + break; + case 4: + m68k_areg (regs, reg) -= reg == 7 ? sz2[size] : sz1[size]; + ad = m68k_areg (regs, reg); + break; + case 5: + ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 6: + ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); + break; + case 7: + switch (reg) { + case 0: + ad = (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 1: + ad = next_ilong_fpu (); + break; + case 2: + ad = m68k_getpc (); + ad += (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 3: + tmppc = m68k_getpc (); + tmp = next_iword_fpu (); + ad = get_disp_ea_020 (tmppc, tmp); + break; + case 4: + ad = m68k_getpc (); + m68k_setpc (ad + sz2[size]); + break; + default: + return 0; + } + } + switch (size) { + case 0: + put_long_fpu (ad, (uae_u32)toint (value, -2147483648.0, 2147483647.0)); + break; + case 1: + put_long_fpu (ad, from_single (value)); + break; + case 2: + { + uae_u32 wrd1, wrd2, wrd3; + from_exten (value, &wrd1, &wrd2, &wrd3); + put_long_fpu (ad, wrd1); + ad += 4; + put_long_fpu (ad, wrd2); + ad += 4; + put_long_fpu (ad, wrd3); + } + break; + case 3: + { + uae_u32 wrd1, wrd2, wrd3; + from_pack (value, &wrd1, &wrd2, &wrd3); + put_long_fpu (ad, wrd1); + ad += 4; + put_long_fpu (ad, wrd2); + ad += 4; + put_long_fpu (ad, wrd3); + } + break; + case 4: + put_word_fpu (ad, (uae_s16) toint (value, -32768.0, 32767.0)); + break; + case 5:{ + uae_u32 wrd1, wrd2; + from_double (value, &wrd1, &wrd2); + put_long_fpu (ad, wrd1); + ad += 4; + put_long_fpu (ad, wrd2); + } + break; + case 6: + put_byte_fpu (ad, (uae_s8)toint (value, -128.0, 127.0)); + break; + default: + return 0; + } + return 1; } - break; - case 6: - put_byte_fpu (ad, (uae_s8)toint (value, -128.0, 127.0)); - break; - default: - return 0; - } - return 1; -} -STATIC_INLINE int get_fp_ad (uae_u32 opcode, uae_u32 * ad) -{ - uae_u16 tmp; - uaecptr tmppc; - int mode; - int reg; - - mode = (opcode >> 3) & 7; - reg = opcode & 7; - switch (mode) { - case 0: - case 1: - return 0; - case 2: - *ad = m68k_areg (regs, reg); - break; - case 3: - *ad = m68k_areg (regs, reg); - break; - case 4: - *ad = m68k_areg (regs, reg); - break; - case 5: - *ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 6: - *ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); - break; - case 7: - switch (reg) { - case 0: - *ad = (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 1: - *ad = next_ilong_fpu (); - break; - case 2: - *ad = m68k_getpc (); - *ad += (uae_s32) (uae_s16) next_iword_fpu (); - break; - case 3: - tmppc = m68k_getpc (); - tmp = next_iword_fpu (); - *ad = get_disp_ea_020 (tmppc, tmp); - break; - default: - return 0; + STATIC_INLINE int get_fp_ad (uae_u32 opcode, uae_u32 * ad) + { + uae_u16 tmp; + uaecptr tmppc; + int mode; + int reg; + + mode = (opcode >> 3) & 7; + reg = opcode & 7; + switch (mode) { + case 0: + case 1: + return 0; + case 2: + *ad = m68k_areg (regs, reg); + break; + case 3: + *ad = m68k_areg (regs, reg); + break; + case 4: + *ad = m68k_areg (regs, reg); + break; + case 5: + *ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 6: + *ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword_fpu ()); + break; + case 7: + switch (reg) { + case 0: + *ad = (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 1: + *ad = next_ilong_fpu (); + break; + case 2: + *ad = m68k_getpc (); + *ad += (uae_s32) (uae_s16) next_iword_fpu (); + break; + case 3: + tmppc = m68k_getpc (); + tmp = next_iword_fpu (); + *ad = get_disp_ea_020 (tmppc, tmp); + break; + default: + return 0; + } + } + return 1; } - } - return 1; -} -STATIC_INLINE int fpp_cond (int condition) -{ - int N = (regs.fp_result < 0.0); - int Z = (regs.fp_result == 0.0); - int NotANumber = 0; + STATIC_INLINE int fpp_cond (int condition) + { + int N = (regs.fp_result < 0.0); + int Z = (regs.fp_result == 0.0); + int NotANumber = 0; #ifdef HAVE_ISNAN - NotANumber = isnan (regs.fp_result); + NotANumber = isnan (regs.fp_result); #endif - if (NotANumber) - N=Z=0; - - switch (condition) { - case 0x00: - return 0; - case 0x01: - return Z; - case 0x02: - return !(NotANumber || Z || N); - case 0x03: - return Z || !(NotANumber || N); - case 0x04: - return N && !(NotANumber || Z); - case 0x05: - return Z || (N && !NotANumber); - case 0x06: - return !(NotANumber || Z); - case 0x07: - return !NotANumber; - case 0x08: - return NotANumber; - case 0x09: - return NotANumber || Z; - case 0x0a: - return NotANumber || !(N || Z); - case 0x0b: - return NotANumber || Z || !N; - case 0x0c: - return NotANumber || (N && !Z); - case 0x0d: - return NotANumber || Z || N; - case 0x0e: - return !Z; - case 0x0f: - return 1; - case 0x10: - return 0; - case 0x11: - return Z; - case 0x12: - return !(NotANumber || Z || N); - case 0x13: - return Z || !(NotANumber || N); - case 0x14: - return N && !(NotANumber || Z); - case 0x15: - return Z || (N && !NotANumber); - case 0x16: - return !(NotANumber || Z); - case 0x17: - return !NotANumber; - case 0x18: - return NotANumber; - case 0x19: - return NotANumber || Z; - case 0x1a: - return NotANumber || !(N || Z); - case 0x1b: - return NotANumber || Z || !N; - case 0x1c: - return NotANumber || (N && !Z); - case 0x1d: - return NotANumber || Z || N; - case 0x1e: - return !Z; - case 0x1f: - return 1; - } - return -1; -} + if (NotANumber) + N=Z=0; + + switch (condition) { + case 0x00: + return 0; + case 0x01: + return Z; + case 0x02: + return !(NotANumber || Z || N); + case 0x03: + return Z || !(NotANumber || N); + case 0x04: + return N && !(NotANumber || Z); + case 0x05: + return Z || (N && !NotANumber); + case 0x06: + return !(NotANumber || Z); + case 0x07: + return !NotANumber; + case 0x08: + return NotANumber; + case 0x09: + return NotANumber || Z; + case 0x0a: + return NotANumber || !(N || Z); + case 0x0b: + return NotANumber || Z || !N; + case 0x0c: + return NotANumber || (N && !Z); + case 0x0d: + return NotANumber || Z || N; + case 0x0e: + return !Z; + case 0x0f: + return 1; + case 0x10: + return 0; + case 0x11: + return Z; + case 0x12: + return !(NotANumber || Z || N); + case 0x13: + return Z || !(NotANumber || N); + case 0x14: + return N && !(NotANumber || Z); + case 0x15: + return Z || (N && !NotANumber); + case 0x16: + return !(NotANumber || Z); + case 0x17: + return !NotANumber; + case 0x18: + return NotANumber; + case 0x19: + return NotANumber || Z; + case 0x1a: + return NotANumber || !(N || Z); + case 0x1b: + return NotANumber || Z || !N; + case 0x1c: + return NotANumber || (N && !Z); + case 0x1d: + return NotANumber || Z || N; + case 0x1e: + return !Z; + case 0x1f: + return 1; + } + return -1; + } -void fpuop_dbcc (uae_u32 opcode, uae_u16 extra) -{ - uaecptr pc = (uae_u32) m68k_getpc (); - uae_s32 disp; - int cc; + void fpuop_dbcc (uae_u32 opcode, uae_u16 extra) + { + uaecptr pc = (uae_u32) m68k_getpc (); + uae_s32 disp; + int cc; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"fdbcc_opp at %08lx\n", m68k_getpc ()); + if (!isinrom ()) + write_log (L"fdbcc_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, 4)) - return; - - disp = (uae_s32) (uae_s16) next_iword_fpu (); - cc = fpp_cond (extra & 0x3f); - if (cc == -1) { - fpu_op_illg (opcode, 4); - } else if (!cc) { - int reg = opcode & 0x7; - - m68k_dreg (regs, reg) = ((m68k_dreg (regs, reg) & 0xffff0000) - | (((m68k_dreg (regs, reg) & 0xffff) - 1) & 0xffff)); - if ((m68k_dreg (regs, reg) & 0xffff) != 0xffff) - m68k_setpc (pc + disp); - } -} + if (fault_if_no_fpu (opcode, 4)) + return; + + disp = (uae_s32) (uae_s16) next_iword_fpu (); + cc = fpp_cond (extra & 0x3f); + if (cc == -1) { + fpu_op_illg (opcode, 4); + } else if (!cc) { + int reg = opcode & 0x7; + + m68k_dreg (regs, reg) = ((m68k_dreg (regs, reg) & 0xffff0000) + | (((m68k_dreg (regs, reg) & 0xffff) - 1) & 0xffff)); + if ((m68k_dreg (regs, reg) & 0xffff) != 0xffff) + m68k_setpc (pc + disp); + } + } -void fpuop_scc (uae_u32 opcode, uae_u16 extra) -{ - uae_u32 ad; - int cc; + void fpuop_scc (uae_u32 opcode, uae_u16 extra) + { + uae_u32 ad; + int cc; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"fscc_opp at %08lx\n", m68k_getpc ()); + if (!isinrom ()) + write_log (L"fscc_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, 4)) - return; - - cc = fpp_cond (extra & 0x3f); - if (cc == -1) { - fpu_op_illg (opcode, 4); - } else if ((opcode & 0x38) == 0) { - m68k_dreg (regs, opcode & 7) = (m68k_dreg (regs, opcode & 7) & ~0xff) | (cc ? 0xff : 0x00); - } else { - if (get_fp_ad (opcode, &ad) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - } else - put_byte_fpu (ad, cc ? 0xff : 0x00); - } -} + if (fault_if_no_fpu (opcode, 4)) + return; + + cc = fpp_cond (extra & 0x3f); + if (cc == -1) { + fpu_op_illg (opcode, 4); + } else if ((opcode & 0x38) == 0) { + m68k_dreg (regs, opcode & 7) = (m68k_dreg (regs, opcode & 7) & ~0xff) | (cc ? 0xff : 0x00); + } else { + if (get_fp_ad (opcode, &ad) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + } else + put_byte_fpu (ad, cc ? 0xff : 0x00); + } + } -void fpuop_trapcc (uae_u32 opcode, uaecptr oldpc, uae_u16 extra) -{ - int cc; + void fpuop_trapcc (uae_u32 opcode, uaecptr oldpc, uae_u16 extra) + { + int cc; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"ftrapcc_opp at %08lx\n", m68k_getpc ()); + if (!isinrom ()) + write_log (L"ftrapcc_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, m68k_getpc() - oldpc)) - return; - - cc = fpp_cond (extra & 0x3f); - if (cc == -1) { - fpu_op_illg (opcode, m68k_getpc () - oldpc); - } - if (cc) - Exception (7, oldpc - 2); -} + if (fault_if_no_fpu (opcode, m68k_getpc() - oldpc)) + return; -void fpuop_bcc (uae_u32 opcode, uaecptr pc, uae_u32 extra) -{ - int cc; - -#if DEBUG_FPP - if (!isinrom ()) - write_log (L"fbcc_opp at %08lx\n", m68k_getpc ()); -#endif - if (fault_if_no_fpu (opcode, m68k_getpc () - pc)) - return; - - cc = fpp_cond (opcode & 0x3f); - if (cc == -1) { - fpu_op_illg (opcode, m68k_getpc () - pc); - } else if (cc) { - if ((opcode & 0x40) == 0) - extra = (uae_s32) (uae_s16) extra; - m68k_setpc (pc + extra); - } -} + cc = fpp_cond (extra & 0x3f); + if (cc == -1) { + fpu_op_illg (opcode, m68k_getpc () - oldpc); + } + if (cc) + Exception (7, oldpc - 2); + } -void fpuop_save (uae_u32 opcode) -{ - uae_u32 ad; - int incr = (opcode & 0x38) == 0x20 ? -1 : 1; - int fpu_version = get_fpu_version(); - int i; + void fpuop_bcc (uae_u32 opcode, uaecptr pc, uae_u32 extra) + { + int cc; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"fsave_opp at %08lx\n", m68k_getpc ()); + if (!isinrom ()) + write_log (L"fbcc_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, 2)) - return; - - if (get_fp_ad (opcode, &ad) == 0) { - fpu_op_illg (opcode, 2); - return; - } - - if (currprefs.fpu_model == 68060) { - /* 12 byte 68060 IDLE frame. */ - if (incr < 0) { - ad -= 4; - put_long_fpu (ad, 0x00000000); - ad -= 4; - put_long_fpu (ad, 0x00000000); - ad -= 4; - put_long_fpu (ad, 0x00006000); - } else { - put_long_fpu (ad, 0x00006000); - ad += 4; - put_long_fpu (ad, 0x00000000); - ad += 4; - put_long_fpu (ad, 0x00000000); - ad += 4; - } - } else if (currprefs.fpu_model == 68040) { - /* 4 byte 68040 IDLE frame. */ - if (incr < 0) { - ad -= 4; - put_long_fpu (ad, fpu_version << 24); - } else { - put_long_fpu (ad, fpu_version << 24); - ad += 4; - } - } else { /* 68881/68882 */ - int idle_size = currprefs.fpu_model == 68882 ? 0x38 : 0x18; - if (incr < 0) { - ad -= 4; - put_long_fpu (ad, 0x70000000); - for (i = 0; i < (idle_size - 1) / 4; i++) { - ad -= 4; - put_long_fpu (ad, 0x00000000); - } - ad -= 4; - put_long_fpu (ad, (fpu_version << 24) | (idle_size << 16)); - } else { - put_long_fpu (ad, (fpu_version << 24) | (idle_size << 16)); - ad += 4; - for (i = 0; i < (idle_size - 1) / 4; i++) { - put_long_fpu (ad, 0x00000000); - ad += 4; - } - put_long_fpu (ad, 0x70000000); - ad += 4; + if (fault_if_no_fpu (opcode, m68k_getpc () - pc)) + return; + + cc = fpp_cond (opcode & 0x3f); + if (cc == -1) { + fpu_op_illg (opcode, m68k_getpc () - pc); + } else if (cc) { + if ((opcode & 0x40) == 0) + extra = (uae_s32) (uae_s16) extra; + m68k_setpc (pc + extra); + } } - } - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad; -} -void fpuop_restore (uae_u32 opcode) -{ - uae_u32 ad; - uae_u32 d; - int incr = (opcode & 0x38) == 0x20 ? -1 : 1; + void fpuop_save (uae_u32 opcode) + { + uae_u32 ad; + int incr = (opcode & 0x38) == 0x20 ? -1 : 1; + int fpu_version = get_fpu_version(); + int i; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"frestore_opp at %08lx\n", m68k_getpc ()); + if (!isinrom ()) + write_log (L"fsave_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, 2)) - return; - - if (get_fp_ad (opcode, &ad) == 0) { - fpu_op_illg (opcode, 2); - return; - } - - if (currprefs.fpu_model == 68060) { - /* all 68060 FPU frames are 12 bytes */ - if (incr < 0) { - ad -= 4; - d = get_long_fpu (ad); - ad -= 8; - } else { - d = get_long_fpu (ad); - ad += 4; - ad += 8; - } + if (fault_if_no_fpu (opcode, 2)) + return; - } else if (currprefs.fpu_model == 68040) { - /* 68040 */ - if (incr < 0) { - /* @@@ This may be wrong. */ - ad -= 4; - d = get_long_fpu (ad); - if ((d & 0xff000000) != 0) { /* Not a NULL frame? */ - if ((d & 0x00ff0000) == 0) { /* IDLE */ - } else if ((d & 0x00ff0000) == 0x00300000) { /* UNIMP */ - ad -= 44; - } else if ((d & 0x00ff0000) == 0x00600000) { /* BUSY */ - ad -= 92; + if (get_fp_ad (opcode, &ad) == 0) { + fpu_op_illg (opcode, 2); + return; } - } - } else { - d = get_long_fpu (ad); - ad += 4; - if ((d & 0xff000000) != 0) { /* Not a NULL frame? */ - if ((d & 0x00ff0000) == 0) { /* IDLE */ - } else if ((d & 0x00ff0000) == 0x00300000) { /* UNIMP */ - ad += 44; - } else if ((d & 0x00ff0000) == 0x00600000) { /* BUSY */ - ad += 92; + + if (currprefs.fpu_model == 68060) { + /* 12 byte 68060 IDLE frame. */ + if (incr < 0) { + ad -= 4; + put_long_fpu (ad, 0x00000000); + ad -= 4; + put_long_fpu (ad, 0x00000000); + ad -= 4; + put_long_fpu (ad, 0x00006000); + } else { + put_long_fpu (ad, 0x00006000); + ad += 4; + put_long_fpu (ad, 0x00000000); + ad += 4; + put_long_fpu (ad, 0x00000000); + ad += 4; + } + } else if (currprefs.fpu_model == 68040) { + /* 4 byte 68040 IDLE frame. */ + if (incr < 0) { + ad -= 4; + put_long_fpu (ad, fpu_version << 24); + } else { + put_long_fpu (ad, fpu_version << 24); + ad += 4; + } + } else { /* 68881/68882 */ + int idle_size = currprefs.fpu_model == 68882 ? 0x38 : 0x18; + if (incr < 0) { + ad -= 4; + put_long_fpu (ad, 0x70000000); + for (i = 0; i < (idle_size - 1) / 4; i++) { + ad -= 4; + put_long_fpu (ad, 0x00000000); + } + ad -= 4; + put_long_fpu (ad, (fpu_version << 24) | (idle_size << 16)); + } else { + put_long_fpu (ad, (fpu_version << 24) | (idle_size << 16)); + ad += 4; + for (i = 0; i < (idle_size - 1) / 4; i++) { + put_long_fpu (ad, 0x00000000); + ad += 4; + } + put_long_fpu (ad, 0x70000000); + ad += 4; + } } - } - } - } else { /* 68881/68882 */ - if (incr < 0) { - ad -= 4; - d = get_long_fpu (ad); - if ((d & 0xff000000) != 0) { - if ((d & 0x00ff0000) == 0x00180000) - ad -= 6 * 4; - else if ((d & 0x00ff0000) == 0x00380000) - ad -= 14 * 4; - else if ((d & 0x00ff0000) == 0x00b40000) - ad -= 45 * 4; - } - } else { - d = get_long_fpu (ad); - ad += 4; - if ((d & 0xff000000) != 0) { - if ((d & 0x00ff0000) == 0x00180000) - ad += 6 * 4; - else if ((d & 0x00ff0000) == 0x00380000) - ad += 14 * 4; - else if ((d & 0x00ff0000) == 0x00b40000) - ad += 45 * 4; - } + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad; } - } - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad; -} -static void fround (int reg) -{ - regs.fp[reg] = (float)regs.fp[reg]; -} - -void fpuop_arithmetic (uae_u32 opcode, uae_u16 extra) -{ - int reg; - fptype src; + void fpuop_restore (uae_u32 opcode) + { + uae_u32 ad; + uae_u32 d; + int incr = (opcode & 0x38) == 0x20 ? -1 : 1; #if DEBUG_FPP - if (!isinrom ()) - write_log (L"FPP %04lx %04x at %08lx\n", opcode & 0xffff, extra, m68k_getpc () - 4); + if (!isinrom ()) + write_log (L"frestore_opp at %08lx\n", m68k_getpc ()); #endif - if (fault_if_no_fpu (opcode, 4)) - return; - - switch ((extra >> 13) & 0x7) { + if (fault_if_no_fpu (opcode, 2)) + return; - case 3: - if (put_fp_value (regs.fp[(extra >> 7) & 7], opcode, extra) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - } - return; - - case 4: - case 5: - if ((opcode & 0x38) == 0) { - if (extra & 0x2000) { - if (extra & 0x1000) - m68k_dreg (regs, opcode & 7) = regs.fpcr & 0xffff; - if (extra & 0x0800) - m68k_dreg (regs, opcode & 7) = get_fpsr (); - if (extra & 0x0400) - m68k_dreg (regs, opcode & 7) = regs.fpiar; - } else { - if (extra & 0x1000) { - regs.fpcr = m68k_dreg (regs, opcode & 7); - native_set_fpucw (regs.fpcr); - } - if (extra & 0x0800) - set_fpsr (m68k_dreg (regs, opcode & 7)); - if (extra & 0x0400) - regs.fpiar = m68k_dreg (regs, opcode & 7); - } - } else if ((opcode & 0x38) == 0x08) { - if (extra & 0x2000) { - if (extra & 0x1000) - m68k_areg (regs, opcode & 7) = regs.fpcr & 0xffff; - if (extra & 0x0800) - m68k_areg (regs, opcode & 7) = get_fpsr (); - if (extra & 0x0400) - m68k_areg (regs, opcode & 7) = regs.fpiar; - } else { - if (extra & 0x1000) { - regs.fpcr = m68k_areg (regs, opcode & 7); - native_set_fpucw (regs.fpcr); - } - if (extra & 0x0800) - set_fpsr (m68k_areg (regs, opcode & 7)); - if (extra & 0x0400) - regs.fpiar = m68k_areg (regs, opcode & 7); - } - } else if ((opcode & 0x3f) == 0x3c) { - if ((extra & 0x2000) == 0) { - if (extra & 0x1000) { - regs.fpcr = next_ilong_fpu (); - native_set_fpucw (regs.fpcr); - } - if (extra & 0x0800) - set_fpsr (next_ilong_fpu ()); - if (extra & 0x0400) - regs.fpiar = next_ilong_fpu (); - } - } else if (extra & 0x2000) { - /* FMOVEM FPP->memory */ - uae_u32 ad; - int incr = 0; - - if (get_fp_ad (opcode, &ad) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; - } - if ((opcode & 0x38) == 0x20) { - if (extra & 0x1000) - incr += 4; - if (extra & 0x0800) - incr += 4; - if (extra & 0x0400) - incr += 4; - } - ad -= incr; - if (extra & 0x1000) { - put_long_fpu (ad, regs.fpcr & 0xffff); - ad += 4; - } - if (extra & 0x0800) { - put_long_fpu (ad, get_fpsr()); - ad += 4; - } - if (extra & 0x0400) { - put_long_fpu (ad, regs.fpiar); - ad += 4; - } - ad -= incr; - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad; - } else { - /* FMOVEM memory->FPP */ - uae_u32 ad; - int incr = 0; - - if (get_fp_ad (opcode, &ad) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; - } - if((opcode & 0x38) == 0x20) { - if (extra & 0x1000) - incr += 4; - if (extra & 0x0800) - incr += 4; - if (extra & 0x0400) - incr += 4; - ad = ad - incr; - } - if (extra & 0x1000) { - regs.fpcr = get_long_fpu (ad); - native_set_fpucw (regs.fpcr); - ad += 4; - } - if (extra & 0x0800) { - set_fpsr(get_long_fpu (ad)); - ad += 4; - } - if (extra & 0x0400) { - regs.fpiar = get_long_fpu (ad); - ad += 4; - } - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad - incr; - } - return; - - case 6: - case 7: - { - uae_u32 ad, list = 0; - int incr = 0; - if (extra & 0x2000) { - /* FMOVEM FPP->memory */ - if (get_fp_ad (opcode, &ad) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; - } - switch ((extra >> 11) & 3) { - case 0: /* static pred */ - list = extra & 0xff; - incr = -1; - break; - case 1: /* dynamic pred */ - list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; - incr = -1; - break; - case 2: /* static postinc */ - list = extra & 0xff; - incr = 1; - break; - case 3: /* dynamic postinc */ - list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; - incr = 1; - break; - } - if (incr < 0) { - for (reg = 7; reg >= 0; reg--) { - uae_u32 wrd1, wrd2, wrd3; - if (list & 0x80) { - from_exten (regs.fp[reg], &wrd1, &wrd2, &wrd3); - ad -= 4; - put_long_fpu (ad, wrd3); - ad -= 4; - put_long_fpu (ad, wrd2); - ad -= 4; - put_long_fpu (ad, wrd1); - } - list <<= 1; + if (get_fp_ad (opcode, &ad) == 0) { + fpu_op_illg (opcode, 2); + return; } - } else { - for (reg = 0; reg <= 7; reg++) { - uae_u32 wrd1, wrd2, wrd3; - if (list & 0x80) { - from_exten (regs.fp[reg], &wrd1, &wrd2, &wrd3); - put_long_fpu (ad, wrd1); - ad += 4; - put_long_fpu (ad, wrd2); - ad += 4; - put_long_fpu (ad, wrd3); - ad += 4; - } - list <<= 1; - } - } - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad; - } else { - /* FMOVEM memory->FPP */ - if (get_fp_ad (opcode, &ad) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; - } - switch ((extra >> 11) & 3) { - case 0: /* static pred */ - list = extra & 0xff; - incr = -1; - break; - case 1: /* dynamic pred */ - list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; - incr = -1; - break; - case 2: /* static postinc */ - list = extra & 0xff; - incr = 1; - break; - case 3: /* dynamic postinc */ - list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; - incr = 1; - break; - } - if (incr < 0) { - for (reg = 7; reg >= 0; reg--) { - uae_u32 wrd1, wrd2, wrd3; - if (list & 0x80) { - ad -= 4; - wrd3 = get_long_fpu (ad); - ad -= 4; - wrd2 = get_long_fpu (ad); - ad -= 4; - wrd1 = get_long_fpu (ad); - regs.fp[reg] = to_exten(wrd1, wrd2, wrd3); - } - list <<= 1; - } - } else { - for (reg = 0; reg <= 7; reg++) { - uae_u32 wrd1, wrd2, wrd3; - if (list & 0x80) { - wrd1 = get_long_fpu (ad); - ad += 4; - wrd2 = get_long_fpu (ad); - ad += 4; - wrd3 = get_long_fpu (ad); - ad += 4; - regs.fp[reg] = to_exten(wrd1, wrd2, wrd3); - } - list <<= 1; + + if (currprefs.fpu_model == 68060) { + /* all 68060 FPU frames are 12 bytes */ + if (incr < 0) { + ad -= 4; + d = get_long_fpu (ad); + ad -= 8; + } else { + d = get_long_fpu (ad); + ad += 4; + ad += 8; + } + + } else if (currprefs.fpu_model == 68040) { + /* 68040 */ + if (incr < 0) { + /* @@@ This may be wrong. */ + ad -= 4; + d = get_long_fpu (ad); + if ((d & 0xff000000) != 0) { /* Not a NULL frame? */ + if ((d & 0x00ff0000) == 0) { /* IDLE */ + } else if ((d & 0x00ff0000) == 0x00300000) { /* UNIMP */ + ad -= 44; + } else if ((d & 0x00ff0000) == 0x00600000) { /* BUSY */ + ad -= 92; + } + } + } else { + d = get_long_fpu (ad); + ad += 4; + if ((d & 0xff000000) != 0) { /* Not a NULL frame? */ + if ((d & 0x00ff0000) == 0) { /* IDLE */ + } else if ((d & 0x00ff0000) == 0x00300000) { /* UNIMP */ + ad += 44; + } else if ((d & 0x00ff0000) == 0x00600000) { /* BUSY */ + ad += 92; + } + } + } + } else { /* 68881/68882 */ + if (incr < 0) { + ad -= 4; + d = get_long_fpu (ad); + if ((d & 0xff000000) != 0) { + if ((d & 0x00ff0000) == 0x00180000) + ad -= 6 * 4; + else if ((d & 0x00ff0000) == 0x00380000) + ad -= 14 * 4; + else if ((d & 0x00ff0000) == 0x00b40000) + ad -= 45 * 4; + } + } else { + d = get_long_fpu (ad); + ad += 4; + if ((d & 0xff000000) != 0) { + if ((d & 0x00ff0000) == 0x00180000) + ad += 6 * 4; + else if ((d & 0x00ff0000) == 0x00380000) + ad += 14 * 4; + else if ((d & 0x00ff0000) == 0x00b40000) + ad += 45 * 4; + } + } } - } - if ((opcode & 0x38) == 0x18) - m68k_areg (regs, opcode & 7) = ad; - if ((opcode & 0x38) == 0x20) - m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad; } - } - return; - - case 0: - case 2: /* Extremely common */ - reg = (extra >> 7) & 7; - if ((extra & 0xfc00) == 0x5c00) { - switch (extra & 0x7f) { - case 0x00: - regs.fp[reg] = *fp_pi; - break; - case 0x0b: - regs.fp[reg] = *fp_l10_2; - break; - case 0x0c: - regs.fp[reg] = *fp_exp_1; - break; - case 0x0d: - regs.fp[reg] = *fp_l2_e; - break; - case 0x0e: - regs.fp[reg] = *fp_l10_e; - break; - case 0x0f: - regs.fp[reg] = 0.0; - break; - case 0x30: - regs.fp[reg] = *fp_ln_2; - break; - case 0x31: - regs.fp[reg] = *fp_ln_10; - break; - case 0x32: - regs.fp[reg] = (fptype)fp_1e0; - break; - case 0x33: - regs.fp[reg] = (fptype)fp_1e1; - break; - case 0x34: - regs.fp[reg] = (fptype)fp_1e2; - break; - case 0x35: - regs.fp[reg] = (fptype)fp_1e4; - break; - case 0x36: - regs.fp[reg] = (fptype)fp_1e8; - break; - case 0x37: - regs.fp[reg] = *fp_1e16; - break; - case 0x38: - regs.fp[reg] = *fp_1e32; - break; - case 0x39: - regs.fp[reg] = *fp_1e64; - break; - case 0x3a: - regs.fp[reg] = *fp_1e128; - break; - case 0x3b: - regs.fp[reg] = *fp_1e256; - break; - case 0x3c: - regs.fp[reg] = *fp_1e512; - break; - case 0x3d: - regs.fp[reg] = *fp_1e1024; - break; - case 0x3e: - regs.fp[reg] = *fp_1e2048; - break; - case 0x3f: - regs.fp[reg] = *fp_1e4096; - break; - default: - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; - } - MAKE_FPSR (regs.fp[reg]); - return; - } - if (get_fp_value (opcode, extra, &src) == 0) { - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; + + static void fround (int reg) + { + regs.fp[reg] = (float)regs.fp[reg]; } - switch (extra & 0x7f) { - - case 0x00: /* FMOVE */ - case 0x40: /* Explicit rounding. This is just a quick fix. */ - case 0x44: /* Same for all other cases that have three choices */ - regs.fp[reg] = src; /* Brian King was here. */ - /* to register needs FPSR updated. See Motorola 68K Manual. */ - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x01: /* FINT */ - /* need to take the current rounding mode into account */ + void fpuop_arithmetic (uae_u32 opcode, uae_u16 extra) + { + int reg; + fptype src; + +#if DEBUG_FPP + if (!isinrom ()) + write_log (L"FPP %04lx %04x at %08lx\n", opcode & 0xffff, extra, m68k_getpc () - 4); +#endif + if (fault_if_no_fpu (opcode, 4)) + return; + + switch ((extra >> 13) & 0x7) { + + case 3: + if (put_fp_value (regs.fp[(extra >> 7) & 7], opcode, extra) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + } + return; + + case 4: + case 5: + if ((opcode & 0x38) == 0) { + if (extra & 0x2000) { + if (extra & 0x1000) + m68k_dreg (regs, opcode & 7) = regs.fpcr & 0xffff; + if (extra & 0x0800) + m68k_dreg (regs, opcode & 7) = get_fpsr (); + if (extra & 0x0400) + m68k_dreg (regs, opcode & 7) = regs.fpiar; + } else { + if (extra & 0x1000) { + regs.fpcr = m68k_dreg (regs, opcode & 7); + native_set_fpucw (regs.fpcr); + } + if (extra & 0x0800) + set_fpsr (m68k_dreg (regs, opcode & 7)); + if (extra & 0x0400) + regs.fpiar = m68k_dreg (regs, opcode & 7); + } + } else if ((opcode & 0x38) == 0x08) { + if (extra & 0x2000) { + if (extra & 0x1000) + m68k_areg (regs, opcode & 7) = regs.fpcr & 0xffff; + if (extra & 0x0800) + m68k_areg (regs, opcode & 7) = get_fpsr (); + if (extra & 0x0400) + m68k_areg (regs, opcode & 7) = regs.fpiar; + } else { + if (extra & 0x1000) { + regs.fpcr = m68k_areg (regs, opcode & 7); + native_set_fpucw (regs.fpcr); + } + if (extra & 0x0800) + set_fpsr (m68k_areg (regs, opcode & 7)); + if (extra & 0x0400) + regs.fpiar = m68k_areg (regs, opcode & 7); + } + } else if ((opcode & 0x3f) == 0x3c) { + if ((extra & 0x2000) == 0) { + if (extra & 0x1000) { + regs.fpcr = next_ilong_fpu (); + native_set_fpucw (regs.fpcr); + } + if (extra & 0x0800) + set_fpsr (next_ilong_fpu ()); + if (extra & 0x0400) + regs.fpiar = next_ilong_fpu (); + } + } else if (extra & 0x2000) { + /* FMOVEM FPP->memory */ + uae_u32 ad; + int incr = 0; + + if (get_fp_ad (opcode, &ad) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + if ((opcode & 0x38) == 0x20) { + if (extra & 0x1000) + incr += 4; + if (extra & 0x0800) + incr += 4; + if (extra & 0x0400) + incr += 4; + } + ad -= incr; + if (extra & 0x1000) { + put_long_fpu (ad, regs.fpcr & 0xffff); + ad += 4; + } + if (extra & 0x0800) { + put_long_fpu (ad, get_fpsr()); + ad += 4; + } + if (extra & 0x0400) { + put_long_fpu (ad, regs.fpiar); + ad += 4; + } + ad -= incr; + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad; + } else { + /* FMOVEM memory->FPP */ + uae_u32 ad; + int incr = 0; + + if (get_fp_ad (opcode, &ad) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + if((opcode & 0x38) == 0x20) { + if (extra & 0x1000) + incr += 4; + if (extra & 0x0800) + incr += 4; + if (extra & 0x0400) + incr += 4; + ad = ad - incr; + } + if (extra & 0x1000) { + regs.fpcr = get_long_fpu (ad); + native_set_fpucw (regs.fpcr); + ad += 4; + } + if (extra & 0x0800) { + set_fpsr(get_long_fpu (ad)); + ad += 4; + } + if (extra & 0x0400) { + regs.fpiar = get_long_fpu (ad); + ad += 4; + } + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad - incr; + } + return; + + case 6: + case 7: + { + uae_u32 ad, list = 0; + int incr = 0; + if (extra & 0x2000) { + /* FMOVEM FPP->memory */ + if (get_fp_ad (opcode, &ad) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + switch ((extra >> 11) & 3) { + case 0: /* static pred */ + list = extra & 0xff; + incr = -1; + break; + case 1: /* dynamic pred */ + list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; + incr = -1; + break; + case 2: /* static postinc */ + list = extra & 0xff; + incr = 1; + break; + case 3: /* dynamic postinc */ + list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; + incr = 1; + break; + } + if (incr < 0) { + for (reg = 7; reg >= 0; reg--) { + uae_u32 wrd1, wrd2, wrd3; + if (list & 0x80) { + from_exten (regs.fp[reg], &wrd1, &wrd2, &wrd3); + ad -= 4; + put_long_fpu (ad, wrd3); + ad -= 4; + put_long_fpu (ad, wrd2); + ad -= 4; + put_long_fpu (ad, wrd1); + } + list <<= 1; + } + } else { + for (reg = 0; reg <= 7; reg++) { + uae_u32 wrd1, wrd2, wrd3; + if (list & 0x80) { + from_exten (regs.fp[reg], &wrd1, &wrd2, &wrd3); + put_long_fpu (ad, wrd1); + ad += 4; + put_long_fpu (ad, wrd2); + ad += 4; + put_long_fpu (ad, wrd3); + ad += 4; + } + list <<= 1; + } + } + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad; + } else { + /* FMOVEM memory->FPP */ + if (get_fp_ad (opcode, &ad) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + switch ((extra >> 11) & 3) { + case 0: /* static pred */ + list = extra & 0xff; + incr = -1; + break; + case 1: /* dynamic pred */ + list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; + incr = -1; + break; + case 2: /* static postinc */ + list = extra & 0xff; + incr = 1; + break; + case 3: /* dynamic postinc */ + list = m68k_dreg (regs, (extra >> 4) & 3) & 0xff; + incr = 1; + break; + } + if (incr < 0) { + for (reg = 7; reg >= 0; reg--) { + uae_u32 wrd1, wrd2, wrd3; + if (list & 0x80) { + ad -= 4; + wrd3 = get_long_fpu (ad); + ad -= 4; + wrd2 = get_long_fpu (ad); + ad -= 4; + wrd1 = get_long_fpu (ad); + regs.fp[reg] = to_exten(wrd1, wrd2, wrd3); + } + list <<= 1; + } + } else { + for (reg = 0; reg <= 7; reg++) { + uae_u32 wrd1, wrd2, wrd3; + if (list & 0x80) { + wrd1 = get_long_fpu (ad); + ad += 4; + wrd2 = get_long_fpu (ad); + ad += 4; + wrd3 = get_long_fpu (ad); + ad += 4; + regs.fp[reg] = to_exten(wrd1, wrd2, wrd3); + } + list <<= 1; + } + } + if ((opcode & 0x38) == 0x18) + m68k_areg (regs, opcode & 7) = ad; + if ((opcode & 0x38) == 0x20) + m68k_areg (regs, opcode & 7) = ad; + } + } + return; + + case 0: + case 2: /* Extremely common */ + reg = (extra >> 7) & 7; + if ((extra & 0xfc00) == 0x5c00) { + switch (extra & 0x7f) { + case 0x00: + regs.fp[reg] = *fp_pi; + break; + case 0x0b: + regs.fp[reg] = *fp_l10_2; + break; + case 0x0c: + regs.fp[reg] = *fp_exp_1; + break; + case 0x0d: + regs.fp[reg] = *fp_l2_e; + break; + case 0x0e: + regs.fp[reg] = *fp_l10_e; + break; + case 0x0f: + regs.fp[reg] = 0.0; + break; + case 0x30: + regs.fp[reg] = *fp_ln_2; + break; + case 0x31: + regs.fp[reg] = *fp_ln_10; + break; + case 0x32: + regs.fp[reg] = (fptype)fp_1e0; + break; + case 0x33: + regs.fp[reg] = (fptype)fp_1e1; + break; + case 0x34: + regs.fp[reg] = (fptype)fp_1e2; + break; + case 0x35: + regs.fp[reg] = (fptype)fp_1e4; + break; + case 0x36: + regs.fp[reg] = (fptype)fp_1e8; + break; + case 0x37: + regs.fp[reg] = *fp_1e16; + break; + case 0x38: + regs.fp[reg] = *fp_1e32; + break; + case 0x39: + regs.fp[reg] = *fp_1e64; + break; + case 0x3a: + regs.fp[reg] = *fp_1e128; + break; + case 0x3b: + regs.fp[reg] = *fp_1e256; + break; + case 0x3c: + regs.fp[reg] = *fp_1e512; + break; + case 0x3d: + regs.fp[reg] = *fp_1e1024; + break; + case 0x3e: + regs.fp[reg] = *fp_1e2048; + break; + case 0x3f: + regs.fp[reg] = *fp_1e4096; + break; + default: + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + MAKE_FPSR (regs.fp[reg]); + return; + } + if (get_fp_value (opcode, extra, &src) == 0) { + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + + switch (extra & 0x7f) { + + case 0x00: /* FMOVE */ + case 0x40: /* Explicit rounding. This is just a quick fix. */ + case 0x44: /* Same for all other cases that have three choices */ + regs.fp[reg] = src; /* Brian King was here. */ + /* to register needs FPSR updated. See Motorola 68K Manual. */ + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x01: /* FINT */ + /* need to take the current rounding mode into account */ #if defined(X86_MSVC_ASSEMBLY) - { - fptype tmp_fp; - - __asm { - fld LDPTR src - frndint - fstp LDPTR tmp_fp - } - regs.fp[reg] = tmp_fp; - } + { + fptype tmp_fp; + + __asm { + fld LDPTR src + frndint + fstp LDPTR tmp_fp + } + regs.fp[reg] = tmp_fp; + } #else /* no X86_MSVC */ - switch ((regs.fpcr >> 4) & 3) { - case 0: /* to nearest */ - regs.fp[reg] = floor (src + 0.5); - break; - case 1: /* to zero */ - if (src >= 0.0) - regs.fp[reg] = floor (src); - else - regs.fp[reg] = ceil (src); - break; - case 2: /* down */ - regs.fp[reg] = floor (src); - break; - case 3: /* up */ - regs.fp[reg] = ceil (src); - break; - default: /* never reached */ - regs.fp[reg] = src; - } + switch ((regs.fpcr >> 4) & 3) { + case 0: /* to nearest */ + regs.fp[reg] = floor (src + 0.5); + break; + case 1: /* to zero */ + if (src >= 0.0) + regs.fp[reg] = floor (src); + else + regs.fp[reg] = ceil (src); + break; + case 2: /* down */ + regs.fp[reg] = floor (src); + break; + case 3: /* up */ + regs.fp[reg] = ceil (src); + break; + default: /* never reached */ + regs.fp[reg] = src; + } #endif /* X86_MSVC */ - break; - case 0x02: /* FSINH */ - regs.fp[reg] = sinh (src); - break; - case 0x03: /* FINTRZ */ - regs.fp[reg] = fp_round_to_zero(src); - break; - case 0x04: /* FSQRT */ - case 0x41: - case 0x45: - regs.fp[reg] = sqrt (src); - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x06: /* FLOGNP1 */ - regs.fp[reg] = log (src + 1.0); - break; - case 0x08: /* FETOXM1 */ - regs.fp[reg] = exp (src) - 1.0; - break; - case 0x09: /* FTANH */ - regs.fp[reg] = tanh (src); - break; - case 0x0a: /* FATAN */ - regs.fp[reg] = atan (src); - break; - case 0x0c: /* FASIN */ - regs.fp[reg] = asin (src); - break; - case 0x0d: /* FATANH */ + break; + case 0x02: /* FSINH */ + regs.fp[reg] = sinh (src); + break; + case 0x03: /* FINTRZ */ + regs.fp[reg] = fp_round_to_zero(src); + break; + case 0x04: /* FSQRT */ + case 0x41: + case 0x45: + regs.fp[reg] = sqrt (src); + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x06: /* FLOGNP1 */ + regs.fp[reg] = log (src + 1.0); + break; + case 0x08: /* FETOXM1 */ + regs.fp[reg] = exp (src) - 1.0; + break; + case 0x09: /* FTANH */ + regs.fp[reg] = tanh (src); + break; + case 0x0a: /* FATAN */ + regs.fp[reg] = atan (src); + break; + case 0x0c: /* FASIN */ + regs.fp[reg] = asin (src); + break; + case 0x0d: /* FATANH */ #if 1 /* The BeBox doesn't have atanh, and it isn't in the HPUX libm either */ - regs.fp[reg] = 0.5 * log ((1 + src) / (1 - src)); + regs.fp[reg] = 0.5 * log ((1 + src) / (1 - src)); #else - regs.fp[reg] = atanh (src); + regs.fp[reg] = atanh (src); #endif - break; - case 0x0e: /* FSIN */ - regs.fp[reg] = sin (src); - break; - case 0x0f: /* FTAN */ - regs.fp[reg] = tan (src); - break; - case 0x10: /* FETOX */ - regs.fp[reg] = exp (src); - break; - case 0x11: /* FTWOTOX */ - regs.fp[reg] = pow (2.0, src); - break; - case 0x12: /* FTENTOX */ - regs.fp[reg] = pow (10.0, src); - break; - case 0x14: /* FLOGN */ - regs.fp[reg] = log (src); - break; - case 0x15: /* FLOG10 */ - regs.fp[reg] = log10 (src); - break; - case 0x16: /* FLOG2 */ - regs.fp[reg] = *fp_l2_e * log (src); - break; - case 0x18: /* FABS */ - case 0x58: - case 0x5c: - regs.fp[reg] = src < 0 ? -src : src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x19: /* FCOSH */ - regs.fp[reg] = cosh (src); - break; - case 0x1a: /* FNEG */ - case 0x5a: - case 0x5e: - regs.fp[reg] = -src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x1c: /* FACOS */ - regs.fp[reg] = acos (src); - break; - case 0x1d: /* FCOS */ - regs.fp[reg] = cos (src); - break; - case 0x1e: /* FGETEXP */ - { - if (src == 0) { - regs.fp[reg] = 0; - } else { - int expon; - frexp (src, &expon); - regs.fp[reg] = (double) (expon - 1); - } - } - break; - case 0x1f: /* FGETMAN */ - { - if (src == 0) { - regs.fp[reg] = 0; - } else { - int expon; - regs.fp[reg] = frexp (src, &expon) * 2.0; - } - } - break; - case 0x20: /* FDIV */ - case 0x60: - case 0x64: - regs.fp[reg] /= src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x21: /* FMOD */ - { - fptype quot = fp_round_to_zero(regs.fp[reg] / src); - regs.fp[reg] = regs.fp[reg] - quot * src; - } - break; - case 0x22: /* FADD */ - case 0x62: - case 0x66: - regs.fp[reg] += src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x23: /* FMUL */ - case 0x63: - case 0x67: - regs.fp[reg] *= src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x24: /* FSGLDIV */ - regs.fp[reg] /= src; - break; - case 0x25: /* FREM */ - { - fptype quot = fp_round_to_nearest(regs.fp[reg] / src); - regs.fp[reg] = regs.fp[reg] - quot * src; - } - break; - case 0x26: /* FSCALE */ - if (src != 0) { + break; + case 0x0e: /* FSIN */ + regs.fp[reg] = sin (src); + break; + case 0x0f: /* FTAN */ + regs.fp[reg] = tan (src); + break; + case 0x10: /* FETOX */ + regs.fp[reg] = exp (src); + break; + case 0x11: /* FTWOTOX */ + regs.fp[reg] = pow (2.0, src); + break; + case 0x12: /* FTENTOX */ + regs.fp[reg] = pow (10.0, src); + break; + case 0x14: /* FLOGN */ + regs.fp[reg] = log (src); + break; + case 0x15: /* FLOG10 */ + regs.fp[reg] = log10 (src); + break; + case 0x16: /* FLOG2 */ + regs.fp[reg] = *fp_l2_e * log (src); + break; + case 0x18: /* FABS */ + case 0x58: + case 0x5c: + regs.fp[reg] = src < 0 ? -src : src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x19: /* FCOSH */ + regs.fp[reg] = cosh (src); + break; + case 0x1a: /* FNEG */ + case 0x5a: + case 0x5e: + regs.fp[reg] = -src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x1c: /* FACOS */ + regs.fp[reg] = acos (src); + break; + case 0x1d: /* FCOS */ + regs.fp[reg] = cos (src); + break; + case 0x1e: /* FGETEXP */ + { + if (src == 0) { + regs.fp[reg] = 0; + } else { + int expon; + frexp (src, &expon); + regs.fp[reg] = (double) (expon - 1); + } + } + break; + case 0x1f: /* FGETMAN */ + { + if (src == 0) { + regs.fp[reg] = 0; + } else { + int expon; + regs.fp[reg] = frexp (src, &expon) * 2.0; + } + } + break; + case 0x20: /* FDIV */ + case 0x60: + case 0x64: + regs.fp[reg] /= src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x21: /* FMOD */ + { + fptype quot = fp_round_to_zero(regs.fp[reg] / src); + regs.fp[reg] = regs.fp[reg] - quot * src; + } + break; + case 0x22: /* FADD */ + case 0x62: + case 0x66: + regs.fp[reg] += src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x23: /* FMUL */ + case 0x63: + case 0x67: + regs.fp[reg] *= src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x24: /* FSGLDIV */ + regs.fp[reg] /= src; + break; + case 0x25: /* FREM */ + { + fptype quot = fp_round_to_nearest(regs.fp[reg] / src); + regs.fp[reg] = regs.fp[reg] - quot * src; + } + break; + case 0x26: /* FSCALE */ + if (src != 0) { #ifdef ldexp - regs.fp[reg] = ldexp (regs.fp[reg], (int) src); + regs.fp[reg] = ldexp (regs.fp[reg], (int) src); #else - regs.fp[reg] *= exp (*fp_ln_2 * (int) src); + regs.fp[reg] *= exp (*fp_ln_2 * (int) src); #endif - } - break; - case 0x27: /* FSGLMUL */ - regs.fp[reg] *= src; - break; - case 0x28: /* FSUB */ - case 0x68: - case 0x6c: - regs.fp[reg] -= src; - if ((extra & 0x44) == 0x40) - fround (reg); - break; - case 0x30: /* FSINCOS */ - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - regs.fp[extra & 7] = cos (src); - regs.fp[reg] = sin (src); - break; - case 0x38: /* FCMP */ - { - fptype tmp = regs.fp[reg] - src; - regs.fpsr = 0; - MAKE_FPSR (tmp); - } - return; - case 0x3a: /* FTST */ - regs.fpsr = 0; - MAKE_FPSR (src); - return; - default: - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); - return; + } + break; + case 0x27: /* FSGLMUL */ + regs.fp[reg] *= src; + break; + case 0x28: /* FSUB */ + case 0x68: + case 0x6c: + regs.fp[reg] -= src; + if ((extra & 0x44) == 0x40) + fround (reg); + break; + case 0x30: /* FSINCOS */ + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + regs.fp[extra & 7] = cos (src); + regs.fp[reg] = sin (src); + break; + case 0x38: /* FCMP */ + { + fptype tmp = regs.fp[reg] - src; + regs.fpsr = 0; + MAKE_FPSR (tmp); + } + return; + case 0x3a: /* FTST */ + regs.fpsr = 0; + MAKE_FPSR (src); + return; + default: + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); + return; + } + MAKE_FPSR (regs.fp[reg]); + return; + } + m68k_setpc (m68k_getpc () - 4); + op_illg (opcode); } - MAKE_FPSR (regs.fp[reg]); - return; - } - m68k_setpc (m68k_getpc () - 4); - op_illg (opcode); -} -void fpu_reset (void) -{ - regs.fpcr = regs.fpsr = regs.fpiar = 0; - regs.fp_result = 1; - fpux_restore (NULL); -} + void fpu_reset (void) + { + regs.fpcr = regs.fpsr = regs.fpiar = 0; + regs.fp_result = 1; + fpux_restore (NULL); + } -uae_u8 *restore_fpu (uae_u8 *src) -{ - int i; - uae_u32 flags; - - changed_prefs.fpu_model = currprefs.fpu_model = restore_u32 (); - flags = restore_u32 (); - for (i = 0; i < 8; i++) { - uae_u32 w1 = restore_u32 (); - uae_u32 w2 = restore_u32 (); - uae_u32 w3 = restore_u16 (); - regs.fp[i] = to_exten (w1, w2, w3); - } - regs.fpcr = restore_u32 (); - native_set_fpucw (regs.fpcr); - regs.fpsr = restore_u32 (); - regs.fpiar = restore_u32 (); - if (flags & 0x80000000) { - restore_u32(); - restore_u32(); - } - write_log (L"FPU: %d\n", currprefs.fpu_model); - return src; -} + uae_u8 *restore_fpu (uae_u8 *src) + { + int i; + uae_u32 flags; + + changed_prefs.fpu_model = currprefs.fpu_model = restore_u32 (); + flags = restore_u32 (); + for (i = 0; i < 8; i++) { + uae_u32 w1 = restore_u32 (); + uae_u32 w2 = restore_u32 (); + uae_u32 w3 = restore_u16 (); + regs.fp[i] = to_exten (w1, w2, w3); + } + regs.fpcr = restore_u32 (); + native_set_fpucw (regs.fpcr); + regs.fpsr = restore_u32 (); + regs.fpiar = restore_u32 (); + if (flags & 0x80000000) { + restore_u32(); + restore_u32(); + } + write_log (L"FPU: %d\n", currprefs.fpu_model); + return src; + } -uae_u8 *save_fpu (int *len, uae_u8 *dstptr) -{ - uae_u8 *dstbak,*dst; - int i; - - *len = 0; - if (currprefs.fpu_model == 0) - return 0; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = malloc (4+4+8*10+4+4+4+4+4); - save_u32 (currprefs.fpu_model); - save_u32 (0x80000000); - for (i = 0; i < 8; i++) { - uae_u32 w1, w2, w3; - from_exten (regs.fp[i], &w1, &w2, &w3); - save_u32 (w1); - save_u32 (w2); - save_u16 (w3); - } - save_u32 (regs.fpcr); - save_u32 (regs.fpsr); - save_u32 (regs.fpiar); - save_u32 (-1); - save_u32 (0); - *len = dst - dstbak; - return dstbak; -} + uae_u8 *save_fpu (int *len, uae_u8 *dstptr) + { + uae_u8 *dstbak,*dst; + int i; + + *len = 0; + if (currprefs.fpu_model == 0) + return 0; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (4+4+8*10+4+4+4+4+4); + save_u32 (currprefs.fpu_model); + save_u32 (0x80000000); + for (i = 0; i < 8; i++) { + uae_u32 w1, w2, w3; + from_exten (regs.fp[i], &w1, &w2, &w3); + save_u32 (w1); + save_u32 (w2); + save_u16 (w3); + } + save_u32 (regs.fpcr); + save_u32 (regs.fpsr); + save_u32 (regs.fpiar); + save_u32 (-1); + save_u32 (0); + *len = dst - dstbak; + return dstbak; + } diff --git a/fsdb.c b/fsdb.c index c1741050..b8af475a 100644 --- a/fsdb.c +++ b/fsdb.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Library of functions to make emulated filesystem as independent as - * possible of the host filesystem's capabilities. - * - * Copyright 1999 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Library of functions to make emulated filesystem as independent as +* possible of the host filesystem's capabilities. +* +* Copyright 1999 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -22,12 +22,12 @@ #include "fsdb.h" /* The on-disk format is as follows: - * Offset 0, 1 byte, valid - * Offset 1, 4 bytes, mode - * Offset 5, 257 bytes, aname - * Offset 263, 257 bytes, nname - * Offset 519, 81 bytes, comment - */ +* Offset 0, 1 byte, valid +* Offset 1, 4 bytes, mode +* Offset 5, 257 bytes, aname +* Offset 263, 257 bytes, nname +* Offset 519, 81 bytes, comment +*/ #define TRACING_ENABLED 0 #if TRACING_ENABLED @@ -38,345 +38,345 @@ TCHAR *nname_begin (TCHAR *nname) { - TCHAR *p = _tcsrchr (nname, FSDB_DIR_SEPARATOR); - if (p) - return p + 1; - return nname; + TCHAR *p = _tcsrchr (nname, FSDB_DIR_SEPARATOR); + if (p) + return p + 1; + return nname; } #ifndef _WIN32 /* Find the name REL in directory DIRNAME. If we find a file that - * has exactly the same name, return REL. If we find a file that - * has the same name when compared case-insensitively, return a - * malloced string that contains the name we found. If no file - * exists that compares equal to REL, return 0. */ +* has exactly the same name, return REL. If we find a file that +* has the same name when compared case-insensitively, return a +* malloced string that contains the name we found. If no file +* exists that compares equal to REL, return 0. */ TCHAR *fsdb_search_dir (const TCHAR *dirname, TCHAR *rel) { - TCHAR *p = 0; - int de; - void *dir; - TCHAR fn[MAX_DPATH]; - - dir = my_opendir (dirname); - /* This really shouldn't happen... */ - if (! dir) - return 0; - - while (p == 0 && (de = my_readdir (dir, fn)) != 0) { - if (strcmp (fn, rel) == 0) - p = rel; - else if (strcasecmp (fn, rel) == 0) - p = my_strdup (fn); - } - my_closedir (dir); - return p; + TCHAR *p = 0; + int de; + void *dir; + TCHAR fn[MAX_DPATH]; + + dir = my_opendir (dirname); + /* This really shouldn't happen... */ + if (! dir) + return 0; + + while (p == 0 && (de = my_readdir (dir, fn)) != 0) { + if (strcmp (fn, rel) == 0) + p = rel; + else if (strcasecmp (fn, rel) == 0) + p = my_strdup (fn); + } + my_closedir (dir); + return p; } #endif static FILE *get_fsdb (a_inode *dir, const TCHAR *mode) { - TCHAR *n; - FILE *f; + TCHAR *n; + FILE *f; - n = build_nname (dir->nname, FSDB_FILE); - f = _tfopen (n, mode); - xfree (n); - return f; + n = build_nname (dir->nname, FSDB_FILE); + f = _tfopen (n, mode); + xfree (n); + return f; } static void kill_fsdb (a_inode *dir) { - TCHAR *n = build_nname (dir->nname, FSDB_FILE); - _wunlink (n); - xfree (n); + TCHAR *n = build_nname (dir->nname, FSDB_FILE); + _wunlink (n); + xfree (n); } static void fsdb_fixup (FILE *f, TCHAR *buf, int size, a_inode *base) { - TCHAR *nname; - int ret; - - if (buf[0] == 0) - return; - nname = build_nname (base->nname, buf + 5 + 257); - ret = fsdb_exists (nname); - if (ret) { + TCHAR *nname; + int ret; + + if (buf[0] == 0) + return; + nname = build_nname (base->nname, buf + 5 + 257); + ret = fsdb_exists (nname); + if (ret) { + xfree (nname); + return; + } + TRACE ((L"uaefsdb '%s' deleted\n", nname)); + /* someone deleted this file/dir outside of emulation.. */ + buf[0] = 0; xfree (nname); - return; - } - TRACE ((L"uaefsdb '%s' deleted\n", nname)); - /* someone deleted this file/dir outside of emulation.. */ - buf[0] = 0; - xfree (nname); } /* Prune the db file the first time this directory is opened in a session. */ void fsdb_clean_dir (a_inode *dir) { - TCHAR buf[1 + 4 + 257 + 257 + 81]; - TCHAR *n; - FILE *f; - off_t pos1 = 0, pos2; - - n = build_nname (dir->nname, FSDB_FILE); - f = _tfopen (n, L"r+b"); - if (f == 0) { - xfree (n); - return; - } - for (;;) { - pos2 = ftell (f); - if (fread (buf, 1, sizeof buf, f) < sizeof buf) - break; - fsdb_fixup (f, buf, sizeof buf, dir); - if (buf[0] == 0) - continue; - if (pos1 != pos2) { - fseek (f, pos1, SEEK_SET); - fwrite (buf, 1, sizeof buf, f); - fseek (f, pos2 + sizeof buf, SEEK_SET); + TCHAR buf[1 + 4 + 257 + 257 + 81]; + TCHAR *n; + FILE *f; + off_t pos1 = 0, pos2; + + n = build_nname (dir->nname, FSDB_FILE); + f = _tfopen (n, L"r+b"); + if (f == 0) { + xfree (n); + return; + } + for (;;) { + pos2 = ftell (f); + if (fread (buf, 1, sizeof buf, f) < sizeof buf) + break; + fsdb_fixup (f, buf, sizeof buf, dir); + if (buf[0] == 0) + continue; + if (pos1 != pos2) { + fseek (f, pos1, SEEK_SET); + fwrite (buf, 1, sizeof buf, f); + fseek (f, pos2 + sizeof buf, SEEK_SET); + } + pos1 += sizeof buf; } - pos1 += sizeof buf; - } - fclose (f); - my_truncate (n, pos1); - xfree (n); + fclose (f); + my_truncate (n, pos1); + xfree (n); } static a_inode *aino_from_buf (a_inode *base, uae_u8 *buf, long off) { - uae_u32 mode; - a_inode *aino = (a_inode *) xcalloc (sizeof (a_inode), 1); - TCHAR *s; - - mode = do_get_mem_long ((uae_u32 *)(buf + 1)); - buf += 5; - aino->aname = au (buf); - buf += 257; - s = au (buf); - aino->nname = build_nname (base->nname, s); - xfree (s); - buf += 257; - aino->comment = *buf != '\0' ? au (buf) : 0; - fsdb_fill_file_attrs (base, aino); - aino->amigaos_mode = mode; - aino->has_dbentry = 1; - aino->dirty = 0; - aino->db_offset = off; - return aino; + uae_u32 mode; + a_inode *aino = (a_inode *) xcalloc (sizeof (a_inode), 1); + TCHAR *s; + + mode = do_get_mem_long ((uae_u32 *)(buf + 1)); + buf += 5; + aino->aname = au (buf); + buf += 257; + s = au (buf); + aino->nname = build_nname (base->nname, s); + xfree (s); + buf += 257; + aino->comment = *buf != '\0' ? au (buf) : 0; + fsdb_fill_file_attrs (base, aino); + aino->amigaos_mode = mode; + aino->has_dbentry = 1; + aino->dirty = 0; + aino->db_offset = off; + return aino; } a_inode *fsdb_lookup_aino_aname (a_inode *base, const TCHAR *aname) { - FILE *f; + FILE *f; - f = get_fsdb (base, L"r+b"); - if (f == 0) { - if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) - return custom_fsdb_lookup_aino_aname (base, aname); - return 0; - } - for (;;) { - uae_u8 buf[1 + 4 + 257 + 257 + 81]; - TCHAR *s; - if (fread (buf, 1, sizeof buf, f) < sizeof buf) - break; - s = au (buf + 5); - if (buf[0] != 0 && same_aname (s, aname)) { - long pos = ftell (f) - sizeof buf; - fclose (f); - xfree (s); - return aino_from_buf (base, buf, pos); + f = get_fsdb (base, L"r+b"); + if (f == 0) { + if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) + return custom_fsdb_lookup_aino_aname (base, aname); + return 0; } - xfree (s); - } - fclose (f); - return 0; + for (;;) { + uae_u8 buf[1 + 4 + 257 + 257 + 81]; + TCHAR *s; + if (fread (buf, 1, sizeof buf, f) < sizeof buf) + break; + s = au (buf + 5); + if (buf[0] != 0 && same_aname (s, aname)) { + long pos = ftell (f) - sizeof buf; + fclose (f); + xfree (s); + return aino_from_buf (base, buf, pos); + } + xfree (s); + } + fclose (f); + return 0; } a_inode *fsdb_lookup_aino_nname (a_inode *base, const TCHAR *nname) { - FILE *f; - char *s; + FILE *f; + char *s; - f = get_fsdb (base, L"r+b"); - if (f == 0) { - if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) - return custom_fsdb_lookup_aino_nname (base, nname); - return 0; - } - s = ua (nname); - for (;;) { - uae_u8 buf[1 + 4 + 257 + 257 + 81]; - if (fread (buf, 1, sizeof buf, f) < sizeof buf) - break; - if (buf[0] != 0 && strcmp (buf + 5 + 257, s) == 0) { - long pos = ftell (f) - sizeof buf; - fclose (f); - xfree (s); - return aino_from_buf (base, buf, pos); + f = get_fsdb (base, L"r+b"); + if (f == 0) { + if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) + return custom_fsdb_lookup_aino_nname (base, nname); + return 0; } - } - xfree (s); - fclose (f); - return 0; + s = ua (nname); + for (;;) { + uae_u8 buf[1 + 4 + 257 + 257 + 81]; + if (fread (buf, 1, sizeof buf, f) < sizeof buf) + break; + if (buf[0] != 0 && strcmp (buf + 5 + 257, s) == 0) { + long pos = ftell (f) - sizeof buf; + fclose (f); + xfree (s); + return aino_from_buf (base, buf, pos); + } + } + xfree (s); + fclose (f); + return 0; } int fsdb_used_as_nname (a_inode *base, const TCHAR *nname) { - FILE *f; - uae_u8 buf[1 + 4 + 257 + 257 + 81]; + FILE *f; + uae_u8 buf[1 + 4 + 257 + 257 + 81]; - f = get_fsdb (base, L"r+b"); - if (f == 0) { - if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) - return custom_fsdb_used_as_nname (base, nname); - return 0; - } - for (;;) { - TCHAR *s; - if (fread (buf, 1, sizeof buf, f) < sizeof buf) - break; - if (buf[0] == 0) - continue; - s = au (buf + 5 + 257); - if (_tcscmp (s, nname) == 0) { - xfree (s); - fclose (f); - return 1; + f = get_fsdb (base, L"r+b"); + if (f == 0) { + if (currprefs.filesys_custom_uaefsdb && (base->volflags & MYVOLUMEINFO_STREAMS)) + return custom_fsdb_used_as_nname (base, nname); + return 0; } - xfree (s); - } - fclose (f); - return 0; + for (;;) { + TCHAR *s; + if (fread (buf, 1, sizeof buf, f) < sizeof buf) + break; + if (buf[0] == 0) + continue; + s = au (buf + 5 + 257); + if (_tcscmp (s, nname) == 0) { + xfree (s); + fclose (f); + return 1; + } + xfree (s); + } + fclose (f); + return 0; } static int needs_dbentry (a_inode *aino) { - const TCHAR *nn_begin; + const TCHAR *nn_begin; - if (aino->deleted) - return 0; + if (aino->deleted) + return 0; - if (! fsdb_mode_representable_p (aino, aino->amigaos_mode) || aino->comment != 0) - return 1; + if (! fsdb_mode_representable_p (aino, aino->amigaos_mode) || aino->comment != 0) + return 1; - nn_begin = nname_begin (aino->nname); - return _tcscmp (nn_begin, aino->aname) != 0; + nn_begin = nname_begin (aino->nname); + return _tcscmp (nn_begin, aino->aname) != 0; } static void write_aino (FILE *f, a_inode *aino) { - uae_u8 buf[1 + 4 + 257 + 257 + 81] = { 0 }; - - buf[0] = aino->needs_dbentry; - do_put_mem_long ((uae_u32 *)(buf + 1), aino->amigaos_mode); - ua_copy (buf + 5, 256, aino->aname); - buf[5 + 256] = '\0'; - ua_copy (buf + 5 + 257, 256, nname_begin (aino->nname)); - buf[5 + 257 + 256] = '\0'; - ua_copy (buf + 5 + 2 * 257, 80, aino->comment ? aino->comment : L""); - buf[5 + 2 * 257 + 80] = '\0'; - aino->db_offset = ftell (f); - fwrite (buf, 1, sizeof buf, f); - aino->has_dbentry = aino->needs_dbentry; - TRACE ((L"%d '%s' '%s' written\n", aino->db_offset, aino->aname, aino->nname)); + uae_u8 buf[1 + 4 + 257 + 257 + 81] = { 0 }; + + buf[0] = aino->needs_dbentry; + do_put_mem_long ((uae_u32 *)(buf + 1), aino->amigaos_mode); + ua_copy (buf + 5, 256, aino->aname); + buf[5 + 256] = '\0'; + ua_copy (buf + 5 + 257, 256, nname_begin (aino->nname)); + buf[5 + 257 + 256] = '\0'; + ua_copy (buf + 5 + 2 * 257, 80, aino->comment ? aino->comment : L""); + buf[5 + 2 * 257 + 80] = '\0'; + aino->db_offset = ftell (f); + fwrite (buf, 1, sizeof buf, f); + aino->has_dbentry = aino->needs_dbentry; + TRACE ((L"%d '%s' '%s' written\n", aino->db_offset, aino->aname, aino->nname)); } /* Write back the db file for a directory. */ void fsdb_dir_writeback (a_inode *dir) { - FILE *f; - int changes_needed = 0; - int entries_needed = 0; - a_inode *aino; - uae_u8 *tmpbuf; - int size, i; - - TRACE ((L"fsdb writeback %s\n", dir->aname)); - /* First pass: clear dirty bits where unnecessary, and see if any work - * needs to be done. */ - for (aino = dir->child; aino; aino = aino->sibling) { -/* - int old_needs_dbentry = aino->needs_dbentry || aino->has_dbentry; - aino->needs_dbentry = needs_dbentry (aino); - entries_needed |= aino->has_dbentry | aino->needs_dbentry; -*/ - int old_needs_dbentry = aino->has_dbentry; - int need = needs_dbentry (aino); - aino->needs_dbentry = need; - entries_needed |= need; - if (! aino->dirty) - continue; - if (! aino->needs_dbentry && ! old_needs_dbentry) - aino->dirty = 0; - else - changes_needed = 1; - } - if (! entries_needed) { - kill_fsdb (dir); - TRACE ((L"fsdb removed\n")); - return; - } - - if (! changes_needed) { - TRACE ((L"not modified\n")); - return; - } - - f = get_fsdb (dir, L"r+b"); - if (f == 0) { - if ((currprefs.filesys_custom_uaefsdb && (dir->volflags & MYVOLUMEINFO_STREAMS)) || currprefs.filesys_no_uaefsdb) { - for (aino = dir->child; aino; aino = aino->sibling) { - aino->dirty = 0; - aino->has_dbentry = 0; - aino->needs_dbentry = 0; - } - return; + FILE *f; + int changes_needed = 0; + int entries_needed = 0; + a_inode *aino; + uae_u8 *tmpbuf; + int size, i; + + TRACE ((L"fsdb writeback %s\n", dir->aname)); + /* First pass: clear dirty bits where unnecessary, and see if any work + * needs to be done. */ + for (aino = dir->child; aino; aino = aino->sibling) { + /* + int old_needs_dbentry = aino->needs_dbentry || aino->has_dbentry; + aino->needs_dbentry = needs_dbentry (aino); + entries_needed |= aino->has_dbentry | aino->needs_dbentry; + */ + int old_needs_dbentry = aino->has_dbentry; + int need = needs_dbentry (aino); + aino->needs_dbentry = need; + entries_needed |= need; + if (! aino->dirty) + continue; + if (! aino->needs_dbentry && ! old_needs_dbentry) + aino->dirty = 0; + else + changes_needed = 1; } - f = get_fsdb (dir, L"w+b"); - if (f == 0) { - TRACE ((L"failed\n")); - /* This shouldn't happen... */ - return; + if (! entries_needed) { + kill_fsdb (dir); + TRACE ((L"fsdb removed\n")); + return; } - } - fseek (f, 0, SEEK_END); - size = ftell (f); - fseek (f, 0, SEEK_SET); - tmpbuf = 0; - if (size > 0) { - tmpbuf = (uae_u8*)malloc (size); - fread (tmpbuf, 1, size, f); - } - TRACE ((L"**** updating '%s' %d\n", dir->aname, size)); - - for (aino = dir->child; aino; aino = aino->sibling) { - if (! aino->dirty) - continue; - aino->dirty = 0; - i = 0; - while (!aino->has_dbentry && i < size) { - TCHAR *s = au (tmpbuf + i + 5); - if (!_tcscmp (s, aino->aname)) { - aino->has_dbentry = 1; - aino->db_offset = i; - } - xfree (s); - i += 1 + 4 + 257 + 257 + 81; + if (! changes_needed) { + TRACE ((L"not modified\n")); + return; } - if (! aino->has_dbentry) { - fseek (f, 0, SEEK_END); - aino->has_dbentry = 1; - } else { - fseek (f, aino->db_offset, SEEK_SET); + f = get_fsdb (dir, L"r+b"); + if (f == 0) { + if ((currprefs.filesys_custom_uaefsdb && (dir->volflags & MYVOLUMEINFO_STREAMS)) || currprefs.filesys_no_uaefsdb) { + for (aino = dir->child; aino; aino = aino->sibling) { + aino->dirty = 0; + aino->has_dbentry = 0; + aino->needs_dbentry = 0; + } + return; + } + f = get_fsdb (dir, L"w+b"); + if (f == 0) { + TRACE ((L"failed\n")); + /* This shouldn't happen... */ + return; + } + } + fseek (f, 0, SEEK_END); + size = ftell (f); + fseek (f, 0, SEEK_SET); + tmpbuf = 0; + if (size > 0) { + tmpbuf = (uae_u8*)malloc (size); + fread (tmpbuf, 1, size, f); + } + TRACE ((L"**** updating '%s' %d\n", dir->aname, size)); + + for (aino = dir->child; aino; aino = aino->sibling) { + if (! aino->dirty) + continue; + aino->dirty = 0; + + i = 0; + while (!aino->has_dbentry && i < size) { + TCHAR *s = au (tmpbuf + i + 5); + if (!_tcscmp (s, aino->aname)) { + aino->has_dbentry = 1; + aino->db_offset = i; + } + xfree (s); + i += 1 + 4 + 257 + 257 + 81; + } + + if (! aino->has_dbentry) { + fseek (f, 0, SEEK_END); + aino->has_dbentry = 1; + } else { + fseek (f, aino->db_offset, SEEK_SET); + } + write_aino (f, aino); } - write_aino (f, aino); - } - TRACE ((L"end\n")); - fclose (f); - xfree (tmpbuf); + TRACE ((L"end\n")); + fclose (f); + xfree (tmpbuf); } diff --git a/fsusage.c b/fsusage.c index 7515653b..2e418f4d 100644 --- a/fsusage.c +++ b/fsusage.c @@ -1,19 +1,19 @@ /* fsusage.c -- return space usage of mounted filesystems - Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. +Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "sysconfig.h" @@ -27,22 +27,22 @@ #include "fsusage.h" /* Return the number of TOSIZE-byte blocks used by - BLOCKS FROMSIZE-byte blocks, rounding away from zero. - TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */ +BLOCKS FROMSIZE-byte blocks, rounding away from zero. +TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */ static long adjust_blocks (long blocks, int fromsize, int tosize) { - if (tosize <= 0) - abort (); - if (fromsize <= 0) - return -1; - - if (fromsize == tosize) /* e.g., from 512 to 512 */ - return blocks; - else if (fromsize > tosize) /* e.g., from 2048 to 512 */ - return blocks * (fromsize / tosize); - else /* e.g., from 256 to 512 */ - return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); + if (tosize <= 0) + abort (); + if (fromsize <= 0) + return -1; + + if (fromsize == tosize) /* e.g., from 512 to 512 */ + return blocks; + else if (fromsize > tosize) /* e.g., from 2048 to 512 */ + return blocks * (fromsize / tosize); + else /* e.g., from 256 to 512 */ + return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); } #ifdef _WIN32 @@ -51,40 +51,40 @@ static long adjust_blocks (long blocks, int fromsize, int tosize) #include int get_fs_usage (const TCHAR *path, const TCHAR *disk, struct fs_usage *fsp) { - TCHAR buf2[MAX_DPATH]; - ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes; - - if (!GetFullPathName (path, sizeof buf2 / sizeof (TCHAR), buf2, NULL)) { - write_log (L"GetFullPathName() failed err=%d\n", GetLastError()); - return -1; - } - - if (!_tcsncmp (buf2, L"\\\\", 2)) { - TCHAR *p; - _tcscat (buf2, L"\\"); - p = _tcschr (buf2 + 2, '\\'); - if (!p) - return -1; - p = _tcschr (p + 1, '\\'); - if (!p) - return -1; - p[1] = 0; - } else { - buf2[3] = 0; - } - - if (!GetDiskFreeSpaceEx (buf2, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes)) { - write_log (L"GetDiskFreeSpaceEx() failed err=%d\n", GetLastError()); - return -1; - } - - fsp->fsu_blocks = 0x7fffffff; - fsp->fsu_bavail = 0x7fffffff; - if (TotalNumberOfBytes.QuadPart / 1024 < (1 << 31)) - fsp->fsu_blocks = (unsigned long)(TotalNumberOfBytes.QuadPart / 1024); - if (FreeBytesAvailable.QuadPart / 1024 < (1 << 31)) - fsp->fsu_bavail = (unsigned long)(FreeBytesAvailable.QuadPart / 1024); - return 0; + TCHAR buf2[MAX_DPATH]; + ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes; + + if (!GetFullPathName (path, sizeof buf2 / sizeof (TCHAR), buf2, NULL)) { + write_log (L"GetFullPathName() failed err=%d\n", GetLastError()); + return -1; + } + + if (!_tcsncmp (buf2, L"\\\\", 2)) { + TCHAR *p; + _tcscat (buf2, L"\\"); + p = _tcschr (buf2 + 2, '\\'); + if (!p) + return -1; + p = _tcschr (p + 1, '\\'); + if (!p) + return -1; + p[1] = 0; + } else { + buf2[3] = 0; + } + + if (!GetDiskFreeSpaceEx (buf2, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes)) { + write_log (L"GetDiskFreeSpaceEx() failed err=%d\n", GetLastError()); + return -1; + } + + fsp->fsu_blocks = 0x7fffffff; + fsp->fsu_bavail = 0x7fffffff; + if (TotalNumberOfBytes.QuadPart / 1024 < (1 << 31)) + fsp->fsu_blocks = (unsigned long)(TotalNumberOfBytes.QuadPart / 1024); + if (FreeBytesAvailable.QuadPart / 1024 < (1 << 31)) + fsp->fsu_bavail = (unsigned long)(FreeBytesAvailable.QuadPart / 1024); + return 0; } #else /* ! _WIN32 */ @@ -133,68 +133,68 @@ int statvfs (); #endif /* Read LEN bytes at PTR from descriptor DESC, retrying if interrupted. - Return the actual number of bytes read, zero for EOF, or negative - for an error. */ +Return the actual number of bytes read, zero for EOF, or negative +for an error. */ int -safe_read (desc, ptr, len) - int desc; - TCHAR *ptr; - int len; + safe_read (desc, ptr, len) + int desc; +TCHAR *ptr; +int len; { - int n_chars; + int n_chars; - if (len <= 0) - return len; + if (len <= 0) + return len; #ifdef EINTR - do - { - n_chars = read (desc, ptr, len); - } - while (n_chars < 0 && errno == EINTR); + do + { + n_chars = read (desc, ptr, len); + } + while (n_chars < 0 && errno == EINTR); #else - n_chars = read (desc, ptr, len); + n_chars = read (desc, ptr, len); #endif - return n_chars; + return n_chars; } /* Fill in the fields of FSP with information about space usage for - the filesystem on which PATH resides. - DISK is the device on which PATH is mounted, for space-getting - methods that need to know it. - Return 0 if successful, -1 if not. When returning -1, ensure that - ERRNO is either a system error value, or zero if DISK is NULL - on a system that requires a non-NULL value. */ +the filesystem on which PATH resides. +DISK is the device on which PATH is mounted, for space-getting +methods that need to know it. +Return 0 if successful, -1 if not. When returning -1, ensure that +ERRNO is either a system error value, or zero if DISK is NULL +on a system that requires a non-NULL value. */ int -get_fs_usage (path, disk, fsp) - const TCHAR *path; - const TCHAR *disk; - struct fs_usage *fsp; + get_fs_usage (path, disk, fsp) + const TCHAR *path; +const TCHAR *disk; +struct fs_usage *fsp; { #ifdef STAT_STATFS3_OSF1 # define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512) - struct statfs fsd; + struct statfs fsd; - if (statfs (path, &fsd, sizeof (struct statfs)) != 0) - return -1; + if (statfs (path, &fsd, sizeof (struct statfs)) != 0) + return -1; #endif /* STAT_STATFS3_OSF1 */ #ifdef STAT_STATFS2_FS_DATA /* Ultrix */ # define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512) - struct fs_data fsd; + struct fs_data fsd; - if (statfs (path, &fsd) != 1) - return -1; - fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot); - fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree); - fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen); - fsp->fsu_files = fsd.fd_req.gtot; - fsp->fsu_ffree = fsd.fd_req.gfree; + if (statfs (path, &fsd) != 1) + return -1; + fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot); + fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree); + fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen); + fsp->fsu_files = fsd.fd_req.gtot; + fsp->fsu_ffree = fsd.fd_req.gfree; #endif /* STAT_STATFS2_FS_DATA */ @@ -203,56 +203,56 @@ get_fs_usage (path, disk, fsp) # define SUPERBOFF (SUPERB * 512) # endif # define CONVERT_BLOCKS(B) \ - adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512) - - struct filsys fsd; - int fd; - - if (! disk) - { - errno = 0; - return -1; - } - - fd = open (disk, O_RDONLY); - if (fd < 0) - return -1; - lseek (fd, (long) SUPERBOFF, 0); - if (safe_read (fd, (TCHAR *) &fsd, sizeof fsd) != sizeof fsd) - { - close (fd); - return -1; - } - close (fd); - fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize); - fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree); - fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree); - fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1); - fsp->fsu_ffree = fsd.s_tinode; + adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512) + + struct filsys fsd; + int fd; + + if (! disk) + { + errno = 0; + return -1; + } + + fd = open (disk, O_RDONLY); + if (fd < 0) + return -1; + lseek (fd, (long) SUPERBOFF, 0); + if (safe_read (fd, (TCHAR *) &fsd, sizeof fsd) != sizeof fsd) + { + close (fd); + return -1; + } + close (fd); + fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize); + fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree); + fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree); + fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1); + fsp->fsu_ffree = fsd.s_tinode; #endif /* STAT_READ_FILSYS */ #ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ # define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512) - struct statfs fsd; + struct statfs fsd; - if (statfs (path, &fsd) < 0) - return -1; + if (statfs (path, &fsd) < 0) + return -1; # ifdef STATFS_TRUNCATES_BLOCK_COUNTS - /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the - struct statfs are truncated to 2GB. These conditions detect that - truncation, presumably without botching the 4.1.1 case, in which - the values are not truncated. The correct counts are stored in - undocumented spare fields. */ - if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0) - { - fsd.f_blocks = fsd.f_spare[0]; - fsd.f_bfree = fsd.f_spare[1]; - fsd.f_bavail = fsd.f_spare[2]; - } + /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the + struct statfs are truncated to 2GB. These conditions detect that + truncation, presumably without botching the 4.1.1 case, in which + the values are not truncated. The correct counts are stored in + undocumented spare fields. */ + if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0) + { + fsd.f_blocks = fsd.f_spare[0]; + fsd.f_bfree = fsd.f_spare[1]; + fsd.f_bavail = fsd.f_spare[2]; + } # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ #endif /* STAT_STATFS2_BSIZE */ @@ -260,10 +260,10 @@ get_fs_usage (path, disk, fsp) #ifdef STAT_STATFS2_FSIZE /* 4.4BSD */ # define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512) - struct statfs fsd; + struct statfs fsd; - if (statfs (path, &fsd) < 0) - return -1; + if (statfs (path, &fsd) < 0) + return -1; #endif /* STAT_STATFS2_FSIZE */ @@ -282,67 +282,67 @@ get_fs_usage (path, disk, fsp) # endif # endif - struct statfs fsd; + struct statfs fsd; - if (statfs (path, &fsd, sizeof fsd, 0) < 0) - return -1; - /* Empirically, the block counts on most SVR3 and SVR3-derived - systems seem to always be in terms of 512-byte blocks, - no matter what value f_bsize has. */ + if (statfs (path, &fsd, sizeof fsd, 0) < 0) + return -1; + /* Empirically, the block counts on most SVR3 and SVR3-derived + systems seem to always be in terms of 512-byte blocks, + no matter what value f_bsize has. */ #endif /* STAT_STATFS4 */ #ifdef STAT_STATVFS /* SVR4 */ # define CONVERT_BLOCKS(B) \ - adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512) + adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512) - struct statvfs fsd; + struct statvfs fsd; - if (statvfs (path, &fsd) < 0) - return -1; - /* f_frsize isn't guaranteed to be supported. */ + if (statvfs (path, &fsd) < 0) + return -1; + /* f_frsize isn't guaranteed to be supported. */ #endif /* STAT_STATVFS */ #if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS) - /* !Ultrix && !SVR2 */ + /* !Ultrix && !SVR2 */ - fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks); - fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree); - fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail); - fsp->fsu_files = fsd.f_files; - fsp->fsu_ffree = fsd.f_ffree; + fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks); + fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree); + fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail); + fsp->fsu_files = fsd.f_files; + fsp->fsu_ffree = fsd.f_ffree; #endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */ - return 0; + return 0; } #if defined(_AIX) && defined(_I386) /* AIX PS/2 does not supply statfs. */ int -statfs (path, fsb) - TCHAR *path; - struct statfs *fsb; + statfs (path, fsb) + TCHAR *path; +struct statfs *fsb; { - struct stat stats; - struct dustat fsd; - - if (stat (path, &stats)) - return -1; - if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) - return -1; - fsb->f_type = 0; - fsb->f_bsize = fsd.du_bsize; - fsb->f_blocks = fsd.du_fsize - fsd.du_isize; - fsb->f_bfree = fsd.du_tfree; - fsb->f_bavail = fsd.du_tfree; - fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; - fsb->f_ffree = fsd.du_tinode; - fsb->f_fsid.val[0] = fsd.du_site; - fsb->f_fsid.val[1] = fsd.du_pckno; - return 0; + struct stat stats; + struct dustat fsd; + + if (stat (path, &stats)) + return -1; + if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) + return -1; + fsb->f_type = 0; + fsb->f_bsize = fsd.du_bsize; + fsb->f_blocks = fsd.du_fsize - fsd.du_isize; + fsb->f_bfree = fsd.du_tfree; + fsb->f_bavail = fsd.du_tfree; + fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; + fsb->f_ffree = fsd.du_tinode; + fsb->f_fsid.val[0] = fsd.du_site; + fsb->f_fsid.val[1] = fsd.du_pckno; + return 0; } #endif /* _AIX && _I386 */ diff --git a/gayle.c b/gayle.c index 7ca4b89c..8e5ccffd 100644 --- a/gayle.c +++ b/gayle.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Gayle (and motherboard resources) memory bank - * - * (c) 2006 - 2008 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Gayle (and motherboard resources) memory bank +* +* (c) 2006 - 2008 Toni Wilen +*/ #define GAYLE_LOG 0 #define IDE_LOG 0 @@ -63,7 +63,7 @@ DE0000 to DEFFFF 64 KB Motherboard resources #define GAYLE_ADDRESS 0xda8000 /* gayle main registers base address */ #define GAYLE_RESET 0xa40000 /* write 0x00 to start reset, - read 1 byte to stop reset */ +read 1 byte to stop reset */ /* IDE stuff */ /* Bases of the IDE interfaces */ @@ -96,8 +96,8 @@ DE0000 to DEFFFF 64 KB Motherboard resources #define IDE_ERR_NM 0x02 /* - * These are at different offsets from the base - */ +* These are at different offsets from the base +*/ #define GAYLE_IRQ_4000 0x3020 /* MSB = 1, Harddisk is source of interrupt */ #define GAYLE_CS_1200 0x8000 #define GAYLE_IRQ_1200 0x9000 @@ -160,20 +160,20 @@ DE0000 to DEFFFF 64 KB Motherboard resources struct ide_hdf { - struct hd_hardfiledata hdhfd; - - uae_u8 secbuf[SECBUF_SIZE]; - int data_offset; - int data_size; - int data_multi; - int lba48; - uae_u8 multiple_mode; - uae_u8 status; - int irq_delay; - int irq; - int num; - int type; - int blocksize; + struct hd_hardfiledata hdhfd; + + uae_u8 secbuf[SECBUF_SIZE]; + int data_offset; + int data_size; + int data_multi; + int lba48; + uae_u8 multiple_mode; + uae_u8 status; + int irq_delay; + int irq; + int num; + int type; + int blocksize; }; static struct ide_hdf *idedrive[4]; @@ -191,884 +191,884 @@ static struct ide_hdf *ide; STATIC_INLINE void pw (int offset, uae_u16 w) { - ide->secbuf[offset * 2 + 0] = (uae_u8)w; - ide->secbuf[offset * 2 + 1] = w >> 8; + ide->secbuf[offset * 2 + 0] = (uae_u8)w; + ide->secbuf[offset * 2 + 1] = w >> 8; } static void ps (int offset, TCHAR *src, int max) { - int i, len; - char *s; - - offset *= 2; - s = ua (src); - len = strlen (s); - for (i = 0; i < max; i++) { - char c = ' '; - if (i < len) - c = s[i]; - ide->secbuf[offset ^ 1] = c; - offset++; - } - xfree (s); + int i, len; + char *s; + + offset *= 2; + s = ua (src); + len = strlen (s); + for (i = 0; i < max; i++) { + char c = ' '; + if (i < len) + c = s[i]; + ide->secbuf[offset ^ 1] = c; + offset++; + } + xfree (s); } static int isideirq (void) { - if (!idedrive) - return 0; - if (ide_devcon & 2) - return 0; - if (idedrive[ide_drv] == NULL) + if (!idedrive) + return 0; + if (ide_devcon & 2) + return 0; + if (idedrive[ide_drv] == NULL) + return 0; + if (idedrive[ide_drv]->irq || idedrive[ide_drv + 2]->irq) { + /* IDE killer feature. Do not eat interrupt to make booting faster. */ + if (idedrive[ide_drv]->irq && idedrive[ide_drv]->hdhfd.size == 0) + idedrive[ide_drv]->irq = 0; + return 1; + } return 0; - if (idedrive[ide_drv]->irq || idedrive[ide_drv + 2]->irq) { - /* IDE killer feature. Do not eat interrupt to make booting faster. */ - if (idedrive[ide_drv]->irq && idedrive[ide_drv]->hdhfd.size == 0) - idedrive[ide_drv]->irq = 0; - return 1; - } - return 0; } void rethink_gayle (void) { - int lev2 = 0; - int lev6 = 0; - uae_u8 mask; + int lev2 = 0; + int lev6 = 0; + uae_u8 mask; + + if (currprefs.cs_ide == IDE_A4000) { + if (isideirq ()) + gayle_irq |= GAYLE_IRQ_IDE; + if ((gayle_irq & GAYLE_IRQ_IDE) && !(intreq & 0x0008)) + INTREQ_0 (0x8000 | 0x0008); + } - if (currprefs.cs_ide == IDE_A4000) { + if (currprefs.cs_ide != IDE_A600A1200 && !currprefs.cs_pcmcia) + return; if (isideirq ()) - gayle_irq |= GAYLE_IRQ_IDE; - if ((gayle_irq & GAYLE_IRQ_IDE) && !(intreq & 0x0008)) - INTREQ_0 (0x8000 | 0x0008); - } - - if (currprefs.cs_ide != IDE_A600A1200 && !currprefs.cs_pcmcia) - return; - if (isideirq ()) - gayle_irq |= GAYLE_IRQ_IDE; - mask = gayle_int & gayle_irq; - if (mask & (GAYLE_IRQ_IDE | GAYLE_IRQ_WR)) - lev2 = 1; - if (mask & GAYLE_IRQ_CCDET) - lev6 = 1; - if (mask & (GAYLE_IRQ_BVD1 | GAYLE_IRQ_BVD2)) { - if (gayle_int & GAYLE_INT_BVD_LEV) - lev6 = 1; - else - lev2 = 1; - } - if (mask & GAYLE_IRQ_BSY) { - if (gayle_int & GAYLE_INT_BSY_LEV) - lev6 = 1; - else - lev2 = 1; - } - if (lev2 && !(intreq & 0x0008)) - INTREQ_0 (0x8000 | 0x0008); - if (lev6 && !(intreq & 0x2000)) - INTREQ_0 (0x8000 | 0x2000); + gayle_irq |= GAYLE_IRQ_IDE; + mask = gayle_int & gayle_irq; + if (mask & (GAYLE_IRQ_IDE | GAYLE_IRQ_WR)) + lev2 = 1; + if (mask & GAYLE_IRQ_CCDET) + lev6 = 1; + if (mask & (GAYLE_IRQ_BVD1 | GAYLE_IRQ_BVD2)) { + if (gayle_int & GAYLE_INT_BVD_LEV) + lev6 = 1; + else + lev2 = 1; + } + if (mask & GAYLE_IRQ_BSY) { + if (gayle_int & GAYLE_INT_BSY_LEV) + lev6 = 1; + else + lev2 = 1; + } + if (lev2 && !(intreq & 0x0008)) + INTREQ_0 (0x8000 | 0x0008); + if (lev6 && !(intreq & 0x2000)) + INTREQ_0 (0x8000 | 0x2000); } static void gayle_cs_change (uae_u8 mask, int onoff) { - int changed = 0; - if ((gayle_cs & mask) && !onoff) { - gayle_cs &= ~mask; - changed = 1; - } else if (!(gayle_cs & mask) && onoff) { - gayle_cs |= mask; - changed = 1; - } - if (changed) { - gayle_irq |= mask; - rethink_gayle (); - if (mask & GAYLE_CS_CCDET) { - if (gayle_irq & GAYLE_IRQ_RESET) - uae_reset (0); - if (gayle_irq & GAYLE_IRQ_BERR) - Exception (2, 0); + int changed = 0; + if ((gayle_cs & mask) && !onoff) { + gayle_cs &= ~mask; + changed = 1; + } else if (!(gayle_cs & mask) && onoff) { + gayle_cs |= mask; + changed = 1; + } + if (changed) { + gayle_irq |= mask; + rethink_gayle (); + if (mask & GAYLE_CS_CCDET) { + if (gayle_irq & GAYLE_IRQ_RESET) + uae_reset (0); + if (gayle_irq & GAYLE_IRQ_BERR) + Exception (2, 0); + } } - } } static void card_trigger (int insert) { - if (insert) { - if (pcmcia_card) { - gayle_cs_change (GAYLE_CS_CCDET, 1); - gayle_cfg = GAYLE_CFG_100NS; - if (!pcmcia_readonly) - gayle_cs_change (GAYLE_CS_WR, 1); + if (insert) { + if (pcmcia_card) { + gayle_cs_change (GAYLE_CS_CCDET, 1); + gayle_cfg = GAYLE_CFG_100NS; + if (!pcmcia_readonly) + gayle_cs_change (GAYLE_CS_WR, 1); + } + } else { + gayle_cfg = 0; + gayle_cs_change (GAYLE_CS_CCDET, 0); + gayle_cs_change (GAYLE_CS_BVD2, 0); + gayle_cs_change (GAYLE_CS_BVD1, 0); + gayle_cs_change (GAYLE_CS_WR, 0); + gayle_cs_change (GAYLE_CS_BSY, 0); } - } else { - gayle_cfg = 0; - gayle_cs_change (GAYLE_CS_CCDET, 0); - gayle_cs_change (GAYLE_CS_BVD2, 0); - gayle_cs_change (GAYLE_CS_BVD1, 0); - gayle_cs_change (GAYLE_CS_WR, 0); - gayle_cs_change (GAYLE_CS_BSY, 0); - } - rethink_gayle (); + rethink_gayle (); } static void write_gayle_cfg (uae_u8 val) { - gayle_cfg = val; + gayle_cfg = val; } static uae_u8 read_gayle_cfg (void) { - return gayle_cfg & 0x0f; + return gayle_cfg & 0x0f; } static void write_gayle_irq (uae_u8 val) { - gayle_irq = (gayle_irq & val) | (val & 3); + gayle_irq = (gayle_irq & val) | (val & 3); } static uae_u8 read_gayle_irq (void) { - return gayle_irq; + return gayle_irq; } static void write_gayle_int (uae_u8 val) { - gayle_int = val; + gayle_int = val; } static uae_u8 read_gayle_int (void) { - return gayle_int; + return gayle_int; } static void write_gayle_cs (uae_u8 val) { - int ov = gayle_cs; - - gayle_cs_mask = val & ~3; - gayle_cs &= ~3; - gayle_cs |= val & 3; - if ((ov & 1) != (gayle_cs & 1)) { - gayle_map_pcmcia (); - /* PCMCIA disable -> enable */ - card_trigger (!(gayle_cs & GAYLE_CS_DIS) ? 1 : 0); - if (PCMCIA_LOG) - write_log (L"PCMCIA slot: %s PC=%08X\n", !(gayle_cs & 1) ? L"enabled" : L"disabled", M68K_GETPC); - } + int ov = gayle_cs; + + gayle_cs_mask = val & ~3; + gayle_cs &= ~3; + gayle_cs |= val & 3; + if ((ov & 1) != (gayle_cs & 1)) { + gayle_map_pcmcia (); + /* PCMCIA disable -> enable */ + card_trigger (!(gayle_cs & GAYLE_CS_DIS) ? 1 : 0); + if (PCMCIA_LOG) + write_log (L"PCMCIA slot: %s PC=%08X\n", !(gayle_cs & 1) ? L"enabled" : L"disabled", M68K_GETPC); + } } static uae_u8 read_gayle_cs (void) { - uae_u8 v; - - v = gayle_cs_mask | gayle_cs; - if (isideirq ()) - v |= GAYLE_CS_IDE; - return v; + uae_u8 v; + + v = gayle_cs_mask | gayle_cs; + if (isideirq ()) + v |= GAYLE_CS_IDE; + return v; } static void ide_interrupt (void) { - if (ide_devcon & 2) - return; - //ide->status |= IDE_STATUS_BSY; - ide->irq_delay = 2; + if (ide_devcon & 2) + return; + //ide->status |= IDE_STATUS_BSY; + ide->irq_delay = 2; } static void ide_interrupt_do (struct ide_hdf *ide) { - ide->status &= ~IDE_STATUS_BSY; - ide->irq_delay = 0; - ide->irq = 1; - rethink_gayle (); + ide->status &= ~IDE_STATUS_BSY; + ide->irq_delay = 0; + ide->irq = 1; + rethink_gayle (); } static void ide_fail_err (uae_u8 err) { - ide_error |= err; - if (ide_drv == 1 && idedrive[ide2 + 1]->hdhfd.size == 0) - idedrive[ide2]->status |= IDE_STATUS_ERR; - ide->status |= IDE_STATUS_ERR; - ide_interrupt (); + ide_error |= err; + if (ide_drv == 1 && idedrive[ide2 + 1]->hdhfd.size == 0) + idedrive[ide2]->status |= IDE_STATUS_ERR; + ide->status |= IDE_STATUS_ERR; + ide_interrupt (); } static void ide_fail (void) { - ide_fail_err (IDE_ERR_ABRT); + ide_fail_err (IDE_ERR_ABRT); } static void ide_data_ready (void) { - memset (ide->secbuf, 0, ide->blocksize); - ide->data_offset = 0; - ide->status |= IDE_STATUS_DRQ; - ide->data_size = ide->blocksize; - ide->data_multi = 1; - ide_interrupt (); + memset (ide->secbuf, 0, ide->blocksize); + ide->data_offset = 0; + ide->status |= IDE_STATUS_DRQ; + ide->data_size = ide->blocksize; + ide->data_multi = 1; + ide_interrupt (); } static void ide_recalibrate (void) { - write_log (L"IDE%d recalibrate\n", ide->num); - ide_sector = 0; - ide_lcyl = ide_hcyl = 0; - ide_interrupt (); + write_log (L"IDE%d recalibrate\n", ide->num); + ide_sector = 0; + ide_lcyl = ide_hcyl = 0; + ide_interrupt (); } static void ide_identify_drive (void) { - uae_u64 totalsecs; - int v; - uae_u8 *buf = ide->secbuf; - TCHAR tmp[100]; + uae_u64 totalsecs; + int v; + uae_u8 *buf = ide->secbuf; + TCHAR tmp[100]; - if (ide->hdhfd.size == 0) { - ide_fail (); - return; - } - memset (buf, 0, ide->blocksize); - if (IDE_LOG > 0) - write_log (L"IDE%d identify drive\n", ide->num); - ide_data_ready (); - ide->data_size *= -1; - pw (0, 1 << 6); - pw (1, ide->hdhfd.cyls_def); - pw (2, 0xc837); - pw (3, ide->hdhfd.heads_def); - pw (4, ide->blocksize * ide->hdhfd.secspertrack_def); - pw (5, ide->blocksize); - pw (6, ide->hdhfd.secspertrack_def); - ps (10, L"68000", 20); /* serial */ - pw (20, 3); - pw (21, ide->blocksize); - pw (22, 4); - ps (23, L"0.3", 8); /* firmware revision */ - _stprintf (tmp, L"UAE-IDE %s", ide->hdhfd.hfd.product_id); - ps (27, tmp, 40); /* model */ - pw (47, MAX_IDE_MULTIPLE_SECTORS >> (ide->blocksize / 512 - 1)); /* max sectors in multiple mode */ - pw (48, 1); - pw (49, (1 << 9) | (1 << 8)); /* LBA and DMA supported */ - pw (51, 0x200); /* PIO cycles */ - pw (52, 0x200); /* DMA cycles */ - pw (53, 1 | 2 | 4); - pw (54, ide->hdhfd.cyls); - pw (55, ide->hdhfd.heads); - pw (56, ide->hdhfd.secspertrack); - totalsecs = ide->hdhfd.cyls * ide->hdhfd.heads * ide->hdhfd.secspertrack; - pw (57, (uae_u16)totalsecs); - pw (58, (uae_u16)(totalsecs >> 16)); - v = idedrive[ide_drv]->multiple_mode; - pw (59, (v > 0 ? 0x100 : 0) | v); - totalsecs = ide->hdhfd.size / ide->blocksize; - if (totalsecs > 0x0fffffff) - totalsecs = 0x0fffffff; - pw (60, (uae_u16)totalsecs); - pw (61, (uae_u16)(totalsecs >> 16)); - pw (62, 0x0f); - pw (63, 0x0f); - pw (64, 0x03); /* PIO3 and PIO4 */ - pw (65, 120); /* MDMA2 supported */ - pw (66, 120); - pw (67, 120); - pw (68, 120); - pw (80, (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6)); /* ATA-1 to ATA-6 */ - pw (81, 0x1c); /* ATA revision */ - pw (82, (1 << 14)); /* NOP command supported */ - pw (83, (1 << 14) | (1 << 13) | (1 << 12) | (ide->lba48 ? (1 << 10) : 0)); /* cache flushes, LBA 48 supported */ - pw (84, 1 << 14); - pw (85, 1 << 14); - pw (86, (1 << 14) | (1 << 13) | (1 << 12) | (ide->lba48 ? (1 << 10) : 0)); /* cache flushes, LBA 48 enabled */ - pw (87, 1 << 14); - pw (88, (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); /* UDMA modes */ - pw (93, (1 << 14) | (1 << 13) | (1 << 0)); - if (ide->lba48) { + if (ide->hdhfd.size == 0) { + ide_fail (); + return; + } + memset (buf, 0, ide->blocksize); + if (IDE_LOG > 0) + write_log (L"IDE%d identify drive\n", ide->num); + ide_data_ready (); + ide->data_size *= -1; + pw (0, 1 << 6); + pw (1, ide->hdhfd.cyls_def); + pw (2, 0xc837); + pw (3, ide->hdhfd.heads_def); + pw (4, ide->blocksize * ide->hdhfd.secspertrack_def); + pw (5, ide->blocksize); + pw (6, ide->hdhfd.secspertrack_def); + ps (10, L"68000", 20); /* serial */ + pw (20, 3); + pw (21, ide->blocksize); + pw (22, 4); + ps (23, L"0.3", 8); /* firmware revision */ + _stprintf (tmp, L"UAE-IDE %s", ide->hdhfd.hfd.product_id); + ps (27, tmp, 40); /* model */ + pw (47, MAX_IDE_MULTIPLE_SECTORS >> (ide->blocksize / 512 - 1)); /* max sectors in multiple mode */ + pw (48, 1); + pw (49, (1 << 9) | (1 << 8)); /* LBA and DMA supported */ + pw (51, 0x200); /* PIO cycles */ + pw (52, 0x200); /* DMA cycles */ + pw (53, 1 | 2 | 4); + pw (54, ide->hdhfd.cyls); + pw (55, ide->hdhfd.heads); + pw (56, ide->hdhfd.secspertrack); + totalsecs = ide->hdhfd.cyls * ide->hdhfd.heads * ide->hdhfd.secspertrack; + pw (57, (uae_u16)totalsecs); + pw (58, (uae_u16)(totalsecs >> 16)); + v = idedrive[ide_drv]->multiple_mode; + pw (59, (v > 0 ? 0x100 : 0) | v); totalsecs = ide->hdhfd.size / ide->blocksize; - pw (100, (uae_u16)(totalsecs >> 0)); - pw (101, (uae_u16)(totalsecs >> 16)); - pw (102, (uae_u16)(totalsecs >> 32)); - pw (103, (uae_u16)(totalsecs >> 48)); - } + if (totalsecs > 0x0fffffff) + totalsecs = 0x0fffffff; + pw (60, (uae_u16)totalsecs); + pw (61, (uae_u16)(totalsecs >> 16)); + pw (62, 0x0f); + pw (63, 0x0f); + pw (64, 0x03); /* PIO3 and PIO4 */ + pw (65, 120); /* MDMA2 supported */ + pw (66, 120); + pw (67, 120); + pw (68, 120); + pw (80, (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6)); /* ATA-1 to ATA-6 */ + pw (81, 0x1c); /* ATA revision */ + pw (82, (1 << 14)); /* NOP command supported */ + pw (83, (1 << 14) | (1 << 13) | (1 << 12) | (ide->lba48 ? (1 << 10) : 0)); /* cache flushes, LBA 48 supported */ + pw (84, 1 << 14); + pw (85, 1 << 14); + pw (86, (1 << 14) | (1 << 13) | (1 << 12) | (ide->lba48 ? (1 << 10) : 0)); /* cache flushes, LBA 48 enabled */ + pw (87, 1 << 14); + pw (88, (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); /* UDMA modes */ + pw (93, (1 << 14) | (1 << 13) | (1 << 0)); + if (ide->lba48) { + totalsecs = ide->hdhfd.size / ide->blocksize; + pw (100, (uae_u16)(totalsecs >> 0)); + pw (101, (uae_u16)(totalsecs >> 16)); + pw (102, (uae_u16)(totalsecs >> 32)); + pw (103, (uae_u16)(totalsecs >> 48)); + } } static void ide_initialize_drive_parameters (void) { - if (ide->hdhfd.size) { - ide->hdhfd.secspertrack = ide_nsector == 0 ? 256 : ide_nsector; - ide->hdhfd.heads = (ide_select & 15) + 1; - ide->hdhfd.cyls = (ide->hdhfd.size / ide->blocksize) / (ide->hdhfd.secspertrack * ide->hdhfd.heads); - if (ide->hdhfd.heads * ide->hdhfd.cyls * ide->hdhfd.secspertrack > 16515072 || ide->lba48) { - ide->hdhfd.cyls = ide->hdhfd.cyls_def; - ide->hdhfd.heads = ide->hdhfd.heads_def; - ide->hdhfd.secspertrack = ide->hdhfd.secspertrack_def; - } - } else { - ide_error |= IDE_ERR_ABRT; - ide->status |= IDE_STATUS_ERR; - } - write_log (L"IDE%d initialize drive parameters, CYL=%d,SPT=%d,HEAD=%d\n", - ide->num, ide->hdhfd.cyls, ide->hdhfd.secspertrack, ide->hdhfd.heads); - ide_interrupt (); + if (ide->hdhfd.size) { + ide->hdhfd.secspertrack = ide_nsector == 0 ? 256 : ide_nsector; + ide->hdhfd.heads = (ide_select & 15) + 1; + ide->hdhfd.cyls = (ide->hdhfd.size / ide->blocksize) / (ide->hdhfd.secspertrack * ide->hdhfd.heads); + if (ide->hdhfd.heads * ide->hdhfd.cyls * ide->hdhfd.secspertrack > 16515072 || ide->lba48) { + ide->hdhfd.cyls = ide->hdhfd.cyls_def; + ide->hdhfd.heads = ide->hdhfd.heads_def; + ide->hdhfd.secspertrack = ide->hdhfd.secspertrack_def; + } + } else { + ide_error |= IDE_ERR_ABRT; + ide->status |= IDE_STATUS_ERR; + } + write_log (L"IDE%d initialize drive parameters, CYL=%d,SPT=%d,HEAD=%d\n", + ide->num, ide->hdhfd.cyls, ide->hdhfd.secspertrack, ide->hdhfd.heads); + ide_interrupt (); } static void ide_set_multiple_mode (void) { - write_log (L"IDE%d drive multiple mode = %d\n", ide->num, ide_nsector); - ide->multiple_mode = ide_nsector; - ide_interrupt (); + write_log (L"IDE%d drive multiple mode = %d\n", ide->num, ide_nsector); + ide->multiple_mode = ide_nsector; + ide_interrupt (); } static void ide_set_features (void) { - int type = ide_nsector >> 3; - int mode = ide_nsector & 7; + int type = ide_nsector >> 3; + int mode = ide_nsector & 7; - write_log (L"IDE%d set features %02X (%02X)\n", ide->num, ide_feat, ide_nsector); - ide_fail (); + write_log (L"IDE%d set features %02X (%02X)\n", ide->num, ide_feat, ide_nsector); + ide_fail (); } static void get_lbachs (struct ide_hdf *ide, uae_u64 *lbap, unsigned int *cyl, unsigned int *head, unsigned int *sec, int lba48) { - if (lba48 && (ide_select & 0x40)) { - uae_u64 lba; - lba = (ide_hcyl << 16) | (ide_lcyl << 8) | ide_sector; - lba |= ((ide_hcyl2 << 16) | (ide_lcyl2 << 8) | ide_sector2) << 24; - *lbap = lba; - } else { - if (ide_select & 0x40) { - *lbap = ((ide_select & 15) << 24) | (ide_hcyl << 16) | (ide_lcyl << 8) | ide_sector; + if (lba48 && (ide_select & 0x40)) { + uae_u64 lba; + lba = (ide_hcyl << 16) | (ide_lcyl << 8) | ide_sector; + lba |= ((ide_hcyl2 << 16) | (ide_lcyl2 << 8) | ide_sector2) << 24; + *lbap = lba; } else { - *cyl = (ide_hcyl << 8) | ide_lcyl; - *head = ide_select & 15; - *sec = ide_sector; - *lbap = (((*cyl) * ide->hdhfd.heads + (*head)) * ide->hdhfd.secspertrack) + (*sec) - 1; + if (ide_select & 0x40) { + *lbap = ((ide_select & 15) << 24) | (ide_hcyl << 16) | (ide_lcyl << 8) | ide_sector; + } else { + *cyl = (ide_hcyl << 8) | ide_lcyl; + *head = ide_select & 15; + *sec = ide_sector; + *lbap = (((*cyl) * ide->hdhfd.heads + (*head)) * ide->hdhfd.secspertrack) + (*sec) - 1; + } } - } } static int get_nsec (int lba48) { - if (lba48) - return (ide_nsector == 0 && ide_nsector2 == 0) ? 65536 : (ide_nsector2 * 256 + ide_nsector); - else - return ide_nsector == 0 ? 256 : ide_nsector; + if (lba48) + return (ide_nsector == 0 && ide_nsector2 == 0) ? 65536 : (ide_nsector2 * 256 + ide_nsector); + else + return ide_nsector == 0 ? 256 : ide_nsector; } static void dec_nsec (int lba48, int v) { - if (lba48) { - uae_u16 nsec; - nsec = ide_nsector2 * 256 + ide_nsector; - ide_nsector -= v; - ide_nsector2 = nsec >> 8; - ide_nsector = nsec & 0xff; - } else { - ide_nsector -= v; - } + if (lba48) { + uae_u16 nsec; + nsec = ide_nsector2 * 256 + ide_nsector; + ide_nsector -= v; + ide_nsector2 = nsec >> 8; + ide_nsector = nsec & 0xff; + } else { + ide_nsector -= v; + } } static void put_lbachs (struct ide_hdf *ide, uae_u64 lba, unsigned int cyl, unsigned int head, unsigned int sec, unsigned int inc, int lba48) { - if (lba48) { - lba += inc; - ide_hcyl = (lba >> 16) & 0xff; - ide_lcyl = (lba >> 8) & 0xff; - ide_sector = lba & 0xff; - lba >>= 24; - ide_hcyl2 = (lba >> 16) & 0xff; - ide_lcyl2 = (lba >> 8) & 0xff; - ide_sector2 = lba & 0xff; - } else { - if (ide_select & 0x40) { - lba += inc; - ide_select &= ~15; - ide_select |= (lba >> 24) & 15; - ide_hcyl = (lba >> 16) & 0xff; - ide_lcyl = (lba >> 8) & 0xff; - ide_sector = lba & 0xff; + if (lba48) { + lba += inc; + ide_hcyl = (lba >> 16) & 0xff; + ide_lcyl = (lba >> 8) & 0xff; + ide_sector = lba & 0xff; + lba >>= 24; + ide_hcyl2 = (lba >> 16) & 0xff; + ide_lcyl2 = (lba >> 8) & 0xff; + ide_sector2 = lba & 0xff; } else { - sec += inc; - while (sec >= ide->hdhfd.secspertrack) { - sec -= ide->hdhfd.secspertrack; - head++; - if (head >= ide->hdhfd.heads) { - head -= ide->hdhfd.heads; - cyl++; + if (ide_select & 0x40) { + lba += inc; + ide_select &= ~15; + ide_select |= (lba >> 24) & 15; + ide_hcyl = (lba >> 16) & 0xff; + ide_lcyl = (lba >> 8) & 0xff; + ide_sector = lba & 0xff; + } else { + sec += inc; + while (sec >= ide->hdhfd.secspertrack) { + sec -= ide->hdhfd.secspertrack; + head++; + if (head >= ide->hdhfd.heads) { + head -= ide->hdhfd.heads; + cyl++; + } + } + ide_select &= ~15; + ide_select |= head; + ide_sector = sec; + ide_hcyl = cyl >> 8; + ide_lcyl = (uae_u8)cyl; } - } - ide_select &= ~15; - ide_select |= head; - ide_sector = sec; - ide_hcyl = cyl >> 8; - ide_lcyl = (uae_u8)cyl; } - } } static void ide_read_sectors (int flags) { - unsigned int cyl, head, sec, nsec; - uae_u64 lba; - int multi = flags & 1; - int lba48 = flags & 2; + unsigned int cyl, head, sec, nsec; + uae_u64 lba; + int multi = flags & 1; + int lba48 = flags & 2; - if (multi && ide->multiple_mode == 0) { - ide_fail (); - return; - } - gui_hd_led (ide->num, 1); - nsec = get_nsec (lba48); - get_lbachs (ide, &lba, &cyl, &head, &sec, lba48); - if (IDE_LOG > 0) - write_log (L"IDE%d read off=%d, sec=%d (%d) lba%d\n", ide->num, (uae_u32)lba, nsec, ide->multiple_mode, lba48 ? 48 : 28); - if (lba * ide->blocksize >= ide->hdhfd.size) { - ide_data_ready (); - ide_fail_err (IDE_ERR_IDNF); - return; - } - ide->data_multi = multi ? ide->multiple_mode : 1; - ide->data_offset = 0; - ide->status |= IDE_STATUS_DRQ; - ide->data_size = nsec * ide->blocksize; - ide_interrupt (); + if (multi && ide->multiple_mode == 0) { + ide_fail (); + return; + } + gui_hd_led (ide->num, 1); + nsec = get_nsec (lba48); + get_lbachs (ide, &lba, &cyl, &head, &sec, lba48); + if (IDE_LOG > 0) + write_log (L"IDE%d read off=%d, sec=%d (%d) lba%d\n", ide->num, (uae_u32)lba, nsec, ide->multiple_mode, lba48 ? 48 : 28); + if (lba * ide->blocksize >= ide->hdhfd.size) { + ide_data_ready (); + ide_fail_err (IDE_ERR_IDNF); + return; + } + ide->data_multi = multi ? ide->multiple_mode : 1; + ide->data_offset = 0; + ide->status |= IDE_STATUS_DRQ; + ide->data_size = nsec * ide->blocksize; + ide_interrupt (); } static void ide_write_sectors (int flags) { - unsigned int cyl, head, sec, nsec; - uae_u64 lba; - int multi = flags & 1; - int lba48 = flags & 2; + unsigned int cyl, head, sec, nsec; + uae_u64 lba; + int multi = flags & 1; + int lba48 = flags & 2; - if (multi && ide->multiple_mode == 0) { - ide_fail (); - return; - } - gui_hd_led (ide->num, 2); - nsec = get_nsec (lba48); - get_lbachs (ide, &lba, &cyl, &head, &sec, lba48); - if (lba * ide->blocksize >= ide->hdhfd.size) { - ide_data_ready (); - ide_fail_err (IDE_ERR_IDNF); - return; - } - if (IDE_LOG > 0) - write_log (L"IDE%d write off=%d, sec=%d (%d) lba%d\n", ide->num, (uae_u32)lba, nsec, ide->multiple_mode, lba48 ? 48 : 28); - if (nsec * ide->blocksize > ide->hdhfd.size - lba * ide->blocksize) - nsec = (ide->hdhfd.size - lba * ide->blocksize) / ide->blocksize; - if (nsec <= 0) { - ide_data_ready (); - ide_fail_err (IDE_ERR_IDNF); - return; - } - ide->data_multi = multi ? ide->multiple_mode : 1; - ide->data_offset = 0; - ide->status |= IDE_STATUS_DRQ; - ide->data_size = nsec * ide->blocksize; - ide->data_multi = 1; + if (multi && ide->multiple_mode == 0) { + ide_fail (); + return; + } + gui_hd_led (ide->num, 2); + nsec = get_nsec (lba48); + get_lbachs (ide, &lba, &cyl, &head, &sec, lba48); + if (lba * ide->blocksize >= ide->hdhfd.size) { + ide_data_ready (); + ide_fail_err (IDE_ERR_IDNF); + return; + } + if (IDE_LOG > 0) + write_log (L"IDE%d write off=%d, sec=%d (%d) lba%d\n", ide->num, (uae_u32)lba, nsec, ide->multiple_mode, lba48 ? 48 : 28); + if (nsec * ide->blocksize > ide->hdhfd.size - lba * ide->blocksize) + nsec = (ide->hdhfd.size - lba * ide->blocksize) / ide->blocksize; + if (nsec <= 0) { + ide_data_ready (); + ide_fail_err (IDE_ERR_IDNF); + return; + } + ide->data_multi = multi ? ide->multiple_mode : 1; + ide->data_offset = 0; + ide->status |= IDE_STATUS_DRQ; + ide->data_size = nsec * ide->blocksize; + ide->data_multi = 1; } static void ide_do_command (uae_u8 cmd) { - int lba48 = ide->lba48; - - if (IDE_LOG > 1) - write_log (L"**** IDE%d command %02X\n", ide->num, cmd); - ide->status &= ~ (IDE_STATUS_DRDY | IDE_STATUS_DRQ | IDE_STATUS_ERR); - ide_error = 0; - - if (cmd == 0x10) { /* recalibrate */ - ide_recalibrate (); - } else if (cmd == 0xec) { /* identify drive */ - ide_identify_drive (); - } else if (cmd == 0x91) { /* initialize drive parameters */ - ide_initialize_drive_parameters (); - } else if (cmd == 0xc6) { /* set multiple mode */ - ide_set_multiple_mode (); - } else if (cmd == 0x20 || cmd == 0x21) { /* read sectors */ - ide_read_sectors (0); - } else if (cmd == 0x24 && lba48) { /* read sectors ext */ - ide_read_sectors (2); - } else if (cmd == 0xc4) { /* read multiple */ - ide_read_sectors (1); - } else if (cmd == 0x29 && lba48) { /* read multiple ext */ - ide_read_sectors (1|2); - } else if (cmd == 0x30 || cmd == 0x31) { /* write sectors */ - ide_write_sectors (0); - } else if (cmd == 0x34 && lba48) { /* write sectors ext */ - ide_write_sectors (2); - } else if (cmd == 0xc5) { /* write multiple */ - ide_write_sectors (1); - } else if (cmd == 0x39 && lba48) { /* write multiple ext */ - ide_write_sectors (1|2); - } else if (cmd == 0x50) { /* format track (nop) */ - ide_interrupt (); - } else if (cmd == 0xa1) { /* ATAPI identify (IDE HD is not ATAPI) */ - ide_fail (); - } else if (cmd == 0xef) { /* set features */ - ide_set_features (); - } else if (cmd == 0x00) { /* nop */ - ide_fail (); - } else if (cmd == 0xe0 || cmd == 0xe1 || cmd == 0xe7 || cmd == 0xea) { /* standby now/idle/flush cache/flush cache ext */ - ide_interrupt (); - } else if (cmd == 0xe5) { /* check power mode */ - ide_nsector = 0xff; - ide_interrupt (); - } else { - ide_fail (); - write_log (L"IDE%d: unknown command %x\n", ide->num, cmd); - } + int lba48 = ide->lba48; + + if (IDE_LOG > 1) + write_log (L"**** IDE%d command %02X\n", ide->num, cmd); + ide->status &= ~ (IDE_STATUS_DRDY | IDE_STATUS_DRQ | IDE_STATUS_ERR); + ide_error = 0; + + if (cmd == 0x10) { /* recalibrate */ + ide_recalibrate (); + } else if (cmd == 0xec) { /* identify drive */ + ide_identify_drive (); + } else if (cmd == 0x91) { /* initialize drive parameters */ + ide_initialize_drive_parameters (); + } else if (cmd == 0xc6) { /* set multiple mode */ + ide_set_multiple_mode (); + } else if (cmd == 0x20 || cmd == 0x21) { /* read sectors */ + ide_read_sectors (0); + } else if (cmd == 0x24 && lba48) { /* read sectors ext */ + ide_read_sectors (2); + } else if (cmd == 0xc4) { /* read multiple */ + ide_read_sectors (1); + } else if (cmd == 0x29 && lba48) { /* read multiple ext */ + ide_read_sectors (1|2); + } else if (cmd == 0x30 || cmd == 0x31) { /* write sectors */ + ide_write_sectors (0); + } else if (cmd == 0x34 && lba48) { /* write sectors ext */ + ide_write_sectors (2); + } else if (cmd == 0xc5) { /* write multiple */ + ide_write_sectors (1); + } else if (cmd == 0x39 && lba48) { /* write multiple ext */ + ide_write_sectors (1|2); + } else if (cmd == 0x50) { /* format track (nop) */ + ide_interrupt (); + } else if (cmd == 0xa1) { /* ATAPI identify (IDE HD is not ATAPI) */ + ide_fail (); + } else if (cmd == 0xef) { /* set features */ + ide_set_features (); + } else if (cmd == 0x00) { /* nop */ + ide_fail (); + } else if (cmd == 0xe0 || cmd == 0xe1 || cmd == 0xe7 || cmd == 0xea) { /* standby now/idle/flush cache/flush cache ext */ + ide_interrupt (); + } else if (cmd == 0xe5) { /* check power mode */ + ide_nsector = 0xff; + ide_interrupt (); + } else { + ide_fail (); + write_log (L"IDE%d: unknown command %x\n", ide->num, cmd); + } } static uae_u16 ide_get_data (void) { - int irq = 0; - uae_u16 v; + int irq = 0; + uae_u16 v; + + if (IDE_LOG > 4) + write_log (L"IDE%d DATA read\n", ide->num); + if (ide->data_size == 0) { + if (IDE_LOG > 0) + write_log (L"IDE%d DATA read without DRQ!?\n", ide->num); + if (ide->hdhfd.size == 0) + return 0xffff; + return 0; + } + if (ide->data_offset == 0 && ide->data_size >= 0) { + unsigned int cyl, head, sec, nsec; + uae_u64 lba; + + nsec = get_nsec (ide->lba48); + get_lbachs (ide, &lba, &cyl, &head, &sec, ide->lba48); + if (nsec * ide->blocksize > ide->hdhfd.size - lba * ide->blocksize) + nsec = (ide->hdhfd.size - lba * ide->blocksize) / ide->blocksize; + if (nsec <= 0) { + ide_data_ready (); + ide_fail_err (IDE_ERR_IDNF); + return 0; + } + if (nsec > ide->data_multi) + nsec = ide->data_multi; + hdf_read (&ide->hdhfd.hfd, ide->secbuf, lba * ide->blocksize, nsec * ide->blocksize); + put_lbachs (ide, lba, cyl, head, sec, nsec, ide->lba48); + dec_nsec (ide->lba48, nsec); + if (IDE_LOG > 1) + write_log (L"IDE%d read, read %d bytes to buffer\n", ide->num, nsec * ide->blocksize); + } - if (IDE_LOG > 4) - write_log (L"IDE%d DATA read\n", ide->num); - if (ide->data_size == 0) { - if (IDE_LOG > 0) - write_log (L"IDE%d DATA read without DRQ!?\n", ide->num); - if (ide->hdhfd.size == 0) - return 0xffff; - return 0; - } - if (ide->data_offset == 0 && ide->data_size >= 0) { + v = ide->secbuf[ide->data_offset + 1] | (ide->secbuf[ide->data_offset + 0] << 8); + ide->data_offset += 2; + if (ide->data_size >= 0) + ide->data_size -= 2; + else + ide->data_size += 2; + if (((ide->data_offset % ide->blocksize) == 0) && ((ide->data_offset / ide->blocksize) % ide->data_multi) == 0) { + irq = 1; + ide->data_offset = 0; + } + if (ide->data_size == 0) { + irq = 1; + ide->status &= ~IDE_STATUS_DRQ; + if (IDE_LOG > 1) + write_log (L"IDE%d read finished\n", ide->num); + } + if (irq) { + ide_interrupt (); + } + return v; +} + +static void ide_write_drive (void) +{ unsigned int cyl, head, sec, nsec; uae_u64 lba; - nsec = get_nsec (ide->lba48); + nsec = ide->data_offset / ide->blocksize; + if (!nsec) + return; get_lbachs (ide, &lba, &cyl, &head, &sec, ide->lba48); - if (nsec * ide->blocksize > ide->hdhfd.size - lba * ide->blocksize) - nsec = (ide->hdhfd.size - lba * ide->blocksize) / ide->blocksize; - if (nsec <= 0) { - ide_data_ready (); - ide_fail_err (IDE_ERR_IDNF); - return 0; - } - if (nsec > ide->data_multi) - nsec = ide->data_multi; - hdf_read (&ide->hdhfd.hfd, ide->secbuf, lba * ide->blocksize, nsec * ide->blocksize); + hdf_write (&ide->hdhfd.hfd, ide->secbuf, lba * ide->blocksize, ide->data_offset); put_lbachs (ide, lba, cyl, head, sec, nsec, ide->lba48); dec_nsec (ide->lba48, nsec); if (IDE_LOG > 1) - write_log (L"IDE%d read, read %d bytes to buffer\n", ide->num, nsec * ide->blocksize); - } - - v = ide->secbuf[ide->data_offset + 1] | (ide->secbuf[ide->data_offset + 0] << 8); - ide->data_offset += 2; - if (ide->data_size >= 0) - ide->data_size -= 2; - else - ide->data_size += 2; - if (((ide->data_offset % ide->blocksize) == 0) && ((ide->data_offset / ide->blocksize) % ide->data_multi) == 0) { - irq = 1; + write_log (L"IDE%d write interrupt, %d bytes written\n", ide->num, ide->data_offset); ide->data_offset = 0; - } - if (ide->data_size == 0) { - irq = 1; - ide->status &= ~IDE_STATUS_DRQ; - if (IDE_LOG > 1) - write_log (L"IDE%d read finished\n", ide->num); - } - if (irq) { - ide_interrupt (); - } - return v; -} - -static void ide_write_drive (void) -{ - unsigned int cyl, head, sec, nsec; - uae_u64 lba; - - nsec = ide->data_offset / ide->blocksize; - if (!nsec) - return; - get_lbachs (ide, &lba, &cyl, &head, &sec, ide->lba48); - hdf_write (&ide->hdhfd.hfd, ide->secbuf, lba * ide->blocksize, ide->data_offset); - put_lbachs (ide, lba, cyl, head, sec, nsec, ide->lba48); - dec_nsec (ide->lba48, nsec); - if (IDE_LOG > 1) - write_log (L"IDE%d write interrupt, %d bytes written\n", ide->num, ide->data_offset); - ide->data_offset = 0; } static void ide_put_data (uae_u16 v) { - int irq = 0; + int irq = 0; - if (IDE_LOG > 4) - write_log (L"IDE%d DATA write %04x %d/%d\n", ide->num, v, ide->data_offset, ide->data_size); - if (ide->data_size == 0) { - if (IDE_LOG > 0) - write_log (L"IDE%d DATA write without DRQ!?\n", ide->num); - return; - } - ide->secbuf[ide->data_offset + 1] = v & 0xff; - ide->secbuf[ide->data_offset + 0] = v >> 8; - ide->data_offset += 2; - ide->data_size -= 2; - if (((ide->data_offset % ide->blocksize) == 0) && ((ide->data_offset / ide->blocksize) % ide->data_multi) == 0) { - irq = 1; - ide_write_drive (); - } - if (ide->data_size == 0) { - ide_write_drive (); - ide->status &= ~IDE_STATUS_DRQ; - if (IDE_LOG > 1) - write_log (L"IDE%d write finished\n", ide->num); - irq = 1; - } - if (irq) - ide_interrupt (); + if (IDE_LOG > 4) + write_log (L"IDE%d DATA write %04x %d/%d\n", ide->num, v, ide->data_offset, ide->data_size); + if (ide->data_size == 0) { + if (IDE_LOG > 0) + write_log (L"IDE%d DATA write without DRQ!?\n", ide->num); + return; + } + ide->secbuf[ide->data_offset + 1] = v & 0xff; + ide->secbuf[ide->data_offset + 0] = v >> 8; + ide->data_offset += 2; + ide->data_size -= 2; + if (((ide->data_offset % ide->blocksize) == 0) && ((ide->data_offset / ide->blocksize) % ide->data_multi) == 0) { + irq = 1; + ide_write_drive (); + } + if (ide->data_size == 0) { + ide_write_drive (); + ide->status &= ~IDE_STATUS_DRQ; + if (IDE_LOG > 1) + write_log (L"IDE%d write finished\n", ide->num); + irq = 1; + } + if (irq) + ide_interrupt (); } static int get_ide_reg (uaecptr addr) { - uaecptr a = addr; - addr &= 0xffff; - if (addr >= 0x3020 && addr <= 0x3021 && currprefs.cs_ide == IDE_A4000) - return -1; - addr &= ~0x2020; - addr >>= 2; - ide2 = 0; - if (addr & 0x400) { - if (ide_splitter) { - ide2 = 2; - addr &= ~0x400; + uaecptr a = addr; + addr &= 0xffff; + if (addr >= 0x3020 && addr <= 0x3021 && currprefs.cs_ide == IDE_A4000) + return -1; + addr &= ~0x2020; + addr >>= 2; + ide2 = 0; + if (addr & 0x400) { + if (ide_splitter) { + ide2 = 2; + addr &= ~0x400; + } } - } - ide = idedrive[ide_drv + ide2]; - return addr; + ide = idedrive[ide_drv + ide2]; + return addr; } static uae_u32 ide_read (uaecptr addr) { - int ide_reg; - uae_u8 v = 0; - - addr &= 0xffff; - if ((IDE_LOG > 2 && (addr != 0x2000 && addr != 0x2001 && addr != 0x2020 && addr != 0x2021 && addr != GAYLE_IRQ_1200)) || IDE_LOG > 4) - write_log (L"IDE_READ %08X PC=%X\n", addr, M68K_GETPC); - if (currprefs.cs_ide <= 0) { - if (addr == 0x201c) // AR1200 IDE detection hack - return 0x7f; - return 0xff; - } - if (addr >= GAYLE_IRQ_4000 && addr <= GAYLE_IRQ_4000 + 1 && currprefs.cs_ide == IDE_A4000) { - uae_u8 v = gayle_irq; - gayle_irq = 0; - return v; - } - if (addr >= 0x4000) { - if (addr == GAYLE_IRQ_1200) { - if (currprefs.cs_ide == IDE_A600A1200) - return read_gayle_irq (); - return 0; - } else if (addr == GAYLE_INT_1200) { - if (currprefs.cs_ide == IDE_A600A1200) - return read_gayle_int (); - return 0; + int ide_reg; + uae_u8 v = 0; + + addr &= 0xffff; + if ((IDE_LOG > 2 && (addr != 0x2000 && addr != 0x2001 && addr != 0x2020 && addr != 0x2021 && addr != GAYLE_IRQ_1200)) || IDE_LOG > 4) + write_log (L"IDE_READ %08X PC=%X\n", addr, M68K_GETPC); + if (currprefs.cs_ide <= 0) { + if (addr == 0x201c) // AR1200 IDE detection hack + return 0x7f; + return 0xff; } - return 0; - } - ide_reg = get_ide_reg (addr); - /* Emulated "ide killer". Prevents long KS boot delay if no drives installed */ - if (idedrive[0]->hdhfd.size == 0 && idedrive[2]->hdhfd.size == 0) { - if (ide_reg == IDE_STATUS) - return 0x7f; - return 0xff; - } - switch (ide_reg) - { + if (addr >= GAYLE_IRQ_4000 && addr <= GAYLE_IRQ_4000 + 1 && currprefs.cs_ide == IDE_A4000) { + uae_u8 v = gayle_irq; + gayle_irq = 0; + return v; + } + if (addr >= 0x4000) { + if (addr == GAYLE_IRQ_1200) { + if (currprefs.cs_ide == IDE_A600A1200) + return read_gayle_irq (); + return 0; + } else if (addr == GAYLE_INT_1200) { + if (currprefs.cs_ide == IDE_A600A1200) + return read_gayle_int (); + return 0; + } + return 0; + } + ide_reg = get_ide_reg (addr); + /* Emulated "ide killer". Prevents long KS boot delay if no drives installed */ + if (idedrive[0]->hdhfd.size == 0 && idedrive[2]->hdhfd.size == 0) { + if (ide_reg == IDE_STATUS) + return 0x7f; + return 0xff; + } + switch (ide_reg) + { case IDE_DRVADDR: - v = ((ide_drv ? 2 : 1) | ((ide_select & 15) << 2)) ^ 0xff; - break; + v = ((ide_drv ? 2 : 1) | ((ide_select & 15) << 2)) ^ 0xff; + break; case IDE_DATA: - break; + break; case IDE_ERROR: - v = ide_error; - break; + v = ide_error; + break; case IDE_NSECTOR: - if (ide_devcon & 0x80) - v = ide_nsector2; - else - v = ide_nsector; - break; + if (ide_devcon & 0x80) + v = ide_nsector2; + else + v = ide_nsector; + break; case IDE_SECTOR: - if (ide_devcon & 0x80) - v = ide_sector2; - else - v = ide_sector; - break; + if (ide_devcon & 0x80) + v = ide_sector2; + else + v = ide_sector; + break; case IDE_LCYL: - if (ide_devcon & 0x80) - v = ide_lcyl2; - else - v = ide_lcyl; - break; + if (ide_devcon & 0x80) + v = ide_lcyl2; + else + v = ide_lcyl; + break; case IDE_HCYL: - if (ide_devcon & 0x80) - v = ide_hcyl2; - else - v = ide_hcyl; - break; + if (ide_devcon & 0x80) + v = ide_hcyl2; + else + v = ide_hcyl; + break; case IDE_SELECT: - v = ide_select; - break; + v = ide_select; + break; case IDE_STATUS: - ide->irq = 0; /* fall through */ + ide->irq = 0; /* fall through */ case IDE_DEVCON: /* ALTSTATUS when reading */ - if (ide->hdhfd.size == 0) { - v = 0; - if (ide_error) - v |= IDE_STATUS_ERR; - } else { - v = ide->status; - v |= IDE_STATUS_DRDY | IDE_STATUS_DSC; - } - break; - } - if (IDE_LOG > 2 && ide_reg > 0) - write_log (L"IDE%d register %d->%02X\n", ide->num, ide_reg, (uae_u32)v & 0xff); - return v; + if (ide->hdhfd.size == 0) { + v = 0; + if (ide_error) + v |= IDE_STATUS_ERR; + } else { + v = ide->status; + v |= IDE_STATUS_DRDY | IDE_STATUS_DSC; + } + break; + } + if (IDE_LOG > 2 && ide_reg > 0) + write_log (L"IDE%d register %d->%02X\n", ide->num, ide_reg, (uae_u32)v & 0xff); + return v; } static void ide_write (uaecptr addr, uae_u32 val) { - int ide_reg; - - if ((IDE_LOG > 2 && (addr != 0x2000 && addr != 0x2001 && addr != 0x2020 && addr != 0x2021 && addr != GAYLE_IRQ_1200)) || IDE_LOG > 4) - write_log (L"IDE_WRITE %08X=%02X PC=%X\n", addr, (uae_u32)val & 0xff, M68K_GETPC); - if (currprefs.cs_ide <= 0) - return; - if (currprefs.cs_ide == IDE_A600A1200) { - if (addr == GAYLE_IRQ_1200) { - write_gayle_irq (val); - return; - } - if (addr == GAYLE_INT_1200) { - write_gayle_int (val); - return; - } - } - if (addr >= 0x4000) - return; - ide_devcon &= ~0x80; /* clear HOB */ - ide_reg = get_ide_reg (addr); - if (IDE_LOG > 2 && ide_reg > 0) - write_log (L"IDE%d register %d=%02X\n", ide->num, ide_reg, (uae_u32)val & 0xff); - switch (ide_reg) - { + int ide_reg; + + if ((IDE_LOG > 2 && (addr != 0x2000 && addr != 0x2001 && addr != 0x2020 && addr != 0x2021 && addr != GAYLE_IRQ_1200)) || IDE_LOG > 4) + write_log (L"IDE_WRITE %08X=%02X PC=%X\n", addr, (uae_u32)val & 0xff, M68K_GETPC); + if (currprefs.cs_ide <= 0) + return; + if (currprefs.cs_ide == IDE_A600A1200) { + if (addr == GAYLE_IRQ_1200) { + write_gayle_irq (val); + return; + } + if (addr == GAYLE_INT_1200) { + write_gayle_int (val); + return; + } + } + if (addr >= 0x4000) + return; + ide_devcon &= ~0x80; /* clear HOB */ + ide_reg = get_ide_reg (addr); + if (IDE_LOG > 2 && ide_reg > 0) + write_log (L"IDE%d register %d=%02X\n", ide->num, ide_reg, (uae_u32)val & 0xff); + switch (ide_reg) + { case IDE_DRVADDR: - break; + break; case IDE_DEVCON: - ide_devcon = val; - break; + ide_devcon = val; + break; case IDE_DATA: - break; + break; case IDE_ERROR: - ide_feat2 = ide_feat; - ide_feat = val; - break; + ide_feat2 = ide_feat; + ide_feat = val; + break; case IDE_NSECTOR: - ide_nsector2 = ide_nsector; - ide_nsector = val; - break; + ide_nsector2 = ide_nsector; + ide_nsector = val; + break; case IDE_SECTOR: - ide_sector2 = ide_sector; - ide_sector = val; - break; + ide_sector2 = ide_sector; + ide_sector = val; + break; case IDE_LCYL: - ide_lcyl2 = ide_lcyl; - ide_lcyl = val; - break; + ide_lcyl2 = ide_lcyl; + ide_lcyl = val; + break; case IDE_HCYL: - ide_hcyl2 = ide_hcyl; - ide_hcyl = val; - break; + ide_hcyl2 = ide_hcyl; + ide_hcyl = val; + break; case IDE_SELECT: - ide_select = val; - ide_drv = (val & 0x10) ? 1 : 0; - break; + ide_select = val; + ide_drv = (val & 0x10) ? 1 : 0; + break; case IDE_STATUS: - ide->irq = 0; - ide_do_command (val); - break; - } + ide->irq = 0; + ide_do_command (val); + break; + } } static int gayle_read (uaecptr addr) { - uaecptr oaddr = addr; - uae_u32 v = 0; - int got = 0; + uaecptr oaddr = addr; + uae_u32 v = 0; + int got = 0; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.cs_ide == IDE_A600A1200) { - if ((addr & 0xA0000) != 0xA0000) - return 0; - } - addr &= 0xffff; - if (currprefs.cs_pcmcia) { - if (currprefs.cs_ide != IDE_A600A1200) { - if (addr == GAYLE_IRQ_1200) { - v = read_gayle_irq (); - got = 1; - } else if (addr == GAYLE_INT_1200) { - v = read_gayle_int (); - got = 1; - } - } - if (addr == GAYLE_CS_1200) { - v = read_gayle_cs (); - got = 1; - if (PCMCIA_LOG) - write_log (L"PCMCIA STATUS READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); - } else if (addr == GAYLE_CFG_1200) { - v = read_gayle_cfg (); - got = 1; - if (PCMCIA_LOG) - write_log (L"PCMCIA CONFIG READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); - } - } - if (!got) - v = ide_read (addr); - if (GAYLE_LOG) - write_log (L"GAYLE_READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); - return v; + if (currprefs.cs_ide == IDE_A600A1200) { + if ((addr & 0xA0000) != 0xA0000) + return 0; + } + addr &= 0xffff; + if (currprefs.cs_pcmcia) { + if (currprefs.cs_ide != IDE_A600A1200) { + if (addr == GAYLE_IRQ_1200) { + v = read_gayle_irq (); + got = 1; + } else if (addr == GAYLE_INT_1200) { + v = read_gayle_int (); + got = 1; + } + } + if (addr == GAYLE_CS_1200) { + v = read_gayle_cs (); + got = 1; + if (PCMCIA_LOG) + write_log (L"PCMCIA STATUS READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); + } else if (addr == GAYLE_CFG_1200) { + v = read_gayle_cfg (); + got = 1; + if (PCMCIA_LOG) + write_log (L"PCMCIA CONFIG READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); + } + } + if (!got) + v = ide_read (addr); + if (GAYLE_LOG) + write_log (L"GAYLE_READ %08X=%02X PC=%08X\n", oaddr, (uae_u32)v & 0xff, M68K_GETPC); + return v; } static void gayle_write (uaecptr addr, int val) { - uaecptr oaddr = addr; - int got = 0; + uaecptr oaddr = addr; + int got = 0; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.cs_ide == IDE_A600A1200) { - if ((addr & 0xA0000) != 0xA0000) - return; - } - addr &= 0xffff; - if (currprefs.cs_pcmcia) { - if (currprefs.cs_ide != IDE_A600A1200) { - if (addr == GAYLE_IRQ_1200) { - write_gayle_irq (val); - got = 1; - } else if (addr == GAYLE_INT_1200) { - write_gayle_int (val); - got = 1; - } - } - if (addr == GAYLE_CS_1200) { - write_gayle_cs (val); - got = 1; - if (PCMCIA_LOG > 1) - write_log (L"PCMCIA STATUS WRITE %08X=%02X PC=%08X\n", oaddr, (uae_u32)val & 0xff, M68K_GETPC); - } else if (addr == GAYLE_CFG_1200) { - write_gayle_cfg (val); - got = 1; - if (PCMCIA_LOG > 1) - write_log (L"PCMCIA CONFIG WRITE %08X=%02X PC=%08X\n", oaddr, (uae_u32)val & 0xff, M68K_GETPC); - } - } - - if (GAYLE_LOG) - write_log (L"GAYLE_WRITE %08X=%02X PC=%08X\n", addr, (uae_u32)val & 0xff, M68K_GETPC); - if (!got) - ide_write (addr, val); + if (currprefs.cs_ide == IDE_A600A1200) { + if ((addr & 0xA0000) != 0xA0000) + return; + } + addr &= 0xffff; + if (currprefs.cs_pcmcia) { + if (currprefs.cs_ide != IDE_A600A1200) { + if (addr == GAYLE_IRQ_1200) { + write_gayle_irq (val); + got = 1; + } else if (addr == GAYLE_INT_1200) { + write_gayle_int (val); + got = 1; + } + } + if (addr == GAYLE_CS_1200) { + write_gayle_cs (val); + got = 1; + if (PCMCIA_LOG > 1) + write_log (L"PCMCIA STATUS WRITE %08X=%02X PC=%08X\n", oaddr, (uae_u32)val & 0xff, M68K_GETPC); + } else if (addr == GAYLE_CFG_1200) { + write_gayle_cfg (val); + got = 1; + if (PCMCIA_LOG > 1) + write_log (L"PCMCIA CONFIG WRITE %08X=%02X PC=%08X\n", oaddr, (uae_u32)val & 0xff, M68K_GETPC); + } + } + + if (GAYLE_LOG) + write_log (L"GAYLE_WRITE %08X=%02X PC=%08X\n", addr, (uae_u32)val & 0xff, M68K_GETPC); + if (!got) + ide_write (addr, val); } static uae_u32 REGPARAM3 gayle_lget (uaecptr) REGPARAM; @@ -1079,121 +1079,121 @@ static void REGPARAM3 gayle_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 gayle_bput (uaecptr, uae_u32) REGPARAM; addrbank gayle_bank = { - gayle_lget, gayle_wget, gayle_bget, - gayle_lput, gayle_wput, gayle_bput, - default_xlate, default_check, NULL, L"Gayle (low)", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + gayle_lget, gayle_wget, gayle_bget, + gayle_lput, gayle_wput, gayle_bput, + default_xlate, default_check, NULL, L"Gayle (low)", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static int isa4000t (uaecptr addr) { - if (currprefs.cs_mbdmac != 2) - return 0; - if ((addr & 0xffff) >= (GAYLE_BASE_4000 & 0xffff)) - return 0; - return 1; + if (currprefs.cs_mbdmac != 2) + return 0; + if ((addr & 0xffff) >= (GAYLE_BASE_4000 & 0xffff)) + return 0; + return 1; } static uae_u32 REGPARAM2 gayle_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle_wget (addr) << 16; - v |= gayle_wget (addr + 2); - return v; + v = gayle_wget (addr) << 16; + v |= gayle_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 gayle_wget (uaecptr addr) { - int ide_reg; - uae_u16 v; + int ide_reg; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (isa4000t (addr)) { - addr -= NCR_OFFSET; - return (ncr_bget2 (addr) << 8) | ncr_bget2 (addr + 1); - } - ide_reg = get_ide_reg (addr); - if (ide_reg == IDE_DATA) - return ide_get_data (); - v = gayle_bget (addr) << 8; - v |= gayle_bget (addr + 1); - return v; + if (isa4000t (addr)) { + addr -= NCR_OFFSET; + return (ncr_bget2 (addr) << 8) | ncr_bget2 (addr + 1); + } + ide_reg = get_ide_reg (addr); + if (ide_reg == IDE_DATA) + return ide_get_data (); + v = gayle_bget (addr) << 8; + v |= gayle_bget (addr + 1); + return v; } static uae_u32 REGPARAM2 gayle_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (isa4000t (addr)) { - addr -= NCR_OFFSET; - return ncr_bget2 (addr); - } - return gayle_read (addr); + if (isa4000t (addr)) { + addr -= NCR_OFFSET; + return ncr_bget2 (addr); + } + return gayle_read (addr); } static void REGPARAM2 gayle_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_wput (addr, value >> 16); - gayle_wput (addr + 2, value & 0xffff); + gayle_wput (addr, value >> 16); + gayle_wput (addr + 2, value & 0xffff); } static void REGPARAM2 gayle_wput (uaecptr addr, uae_u32 value) { - int ide_reg; + int ide_reg; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (isa4000t (addr)) { - addr -= NCR_OFFSET; - ncr_bput2 (addr, value >> 8); - ncr_bput2 (addr + 1, value); - return; - } - ide_reg = get_ide_reg (addr); - if (ide_reg == IDE_DATA) { - ide_put_data (value); - return; - } - gayle_bput (addr, value >> 8); - gayle_bput (addr + 1, value & 0xff); + if (isa4000t (addr)) { + addr -= NCR_OFFSET; + ncr_bput2 (addr, value >> 8); + ncr_bput2 (addr + 1, value); + return; + } + ide_reg = get_ide_reg (addr); + if (ide_reg == IDE_DATA) { + ide_put_data (value); + return; + } + gayle_bput (addr, value >> 8); + gayle_bput (addr + 1, value & 0xff); } static void REGPARAM2 gayle_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (isa4000t (addr)) { - addr -= NCR_OFFSET; - ncr_bput2 (addr, value); - return; - } - gayle_write (addr, value); + if (isa4000t (addr)) { + addr -= NCR_OFFSET; + ncr_bput2 (addr, value); + return; + } + gayle_write (addr, value); } static void gayle2_write (uaecptr addr, uae_u32 v) { - gayle_id_cnt = 0; + gayle_id_cnt = 0; } static uae_u32 gayle2_read (uaecptr addr) { - uae_u8 v = 0; - addr &= 0xffff; - if (addr == 0x1000) { - /* Gayle ID */ - if ((gayle_id_cnt & 3) == 2) - v = 0x7f; - else - v = 0x80; - gayle_id_cnt++; - } - return v; + uae_u8 v = 0; + addr &= 0xffff; + if (addr == 0x1000) { + /* Gayle ID */ + if ((gayle_id_cnt & 3) == 2) + v = 0x7f; + else + v = 0x80; + gayle_id_cnt++; + } + return v; } static uae_u32 REGPARAM3 gayle2_lget (uaecptr) REGPARAM; @@ -1204,64 +1204,64 @@ static void REGPARAM3 gayle2_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 gayle2_bput (uaecptr, uae_u32) REGPARAM; addrbank gayle2_bank = { - gayle2_lget, gayle2_wget, gayle2_bget, - gayle2_lput, gayle2_wput, gayle2_bput, - default_xlate, default_check, NULL, L"Gayle (high)", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + gayle2_lget, gayle2_wget, gayle2_bget, + gayle2_lput, gayle2_wput, gayle2_bput, + default_xlate, default_check, NULL, L"Gayle (high)", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static uae_u32 REGPARAM2 gayle2_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle2_wget (addr) << 16; - v |= gayle2_wget (addr + 2); - return v; + v = gayle2_wget (addr) << 16; + v |= gayle2_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 gayle2_wget (uaecptr addr) { - uae_u16 v; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle2_bget (addr) << 8; - v |= gayle2_bget (addr + 1); - return v; + v = gayle2_bget (addr) << 8; + v |= gayle2_bget (addr + 1); + return v; } static uae_u32 REGPARAM2 gayle2_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return gayle2_read (addr); + return gayle2_read (addr); } static void REGPARAM2 gayle2_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle2_wput (addr, value >> 16); - gayle2_wput (addr + 2, value & 0xffff); + gayle2_wput (addr, value >> 16); + gayle2_wput (addr + 2, value & 0xffff); } static void REGPARAM2 gayle2_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle2_bput (addr, value >> 8); - gayle2_bput (addr + 1, value & 0xff); + gayle2_bput (addr, value >> 8); + gayle2_bput (addr + 1, value & 0xff); } static void REGPARAM2 gayle2_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle2_write (addr, value); + gayle2_write (addr, value); } static uae_u8 ramsey_config; @@ -1270,64 +1270,64 @@ static int garyidoffset; static void mbres_write (uaecptr addr, uae_u32 val, int size) { - addr &= 0xffff; - - if (MBRES_LOG > 0) - write_log (L"MBRES_WRITE %08X=%08X (%d) PC=%08X S=%d\n", addr, val, size, M68K_GETPC, regs.s); - if (regs.s) { /* CPU FC = supervisor only */ - if (addr == 0x1002) - garyidoffset = -1; - if (addr == 0x03) - ramsey_config = val; - if (addr == 0x02) - gary_coldboot = (val & 0x80) ? 1 : 0; - if (addr == 0x01) - gary_toenb = (val & 0x80) ? 1 : 0; - if (addr == 0x00) - gary_timeout = (val & 0x80) ? 1 : 0; - } else { - custom_bank.wput (addr, val); - } + addr &= 0xffff; + + if (MBRES_LOG > 0) + write_log (L"MBRES_WRITE %08X=%08X (%d) PC=%08X S=%d\n", addr, val, size, M68K_GETPC, regs.s); + if (regs.s) { /* CPU FC = supervisor only */ + if (addr == 0x1002) + garyidoffset = -1; + if (addr == 0x03) + ramsey_config = val; + if (addr == 0x02) + gary_coldboot = (val & 0x80) ? 1 : 0; + if (addr == 0x01) + gary_toenb = (val & 0x80) ? 1 : 0; + if (addr == 0x00) + gary_timeout = (val & 0x80) ? 1 : 0; + } else { + custom_bank.wput (addr, val); + } } static uae_u32 mbres_read (uaecptr addr, int size) { - uae_u32 v = 0; - addr &= 0xffff; + uae_u32 v = 0; + addr &= 0xffff; - if (regs.s) { /* CPU FC = supervisor only */ - /* Gary ID (I don't think this exists in real chips..) */ - if (addr == 0x1002 && currprefs.cs_fatgaryrev >= 0) { - garyidoffset++; - garyidoffset &= 7; - v = (currprefs.cs_fatgaryrev << garyidoffset) & 0x80; - } - if (addr == 0x43) { /* RAMSEY revision */ - if (currprefs.cs_ramseyrev >= 0) - v = currprefs.cs_ramseyrev; - } - if (addr == 0x03) { /* RAMSEY config */ - if (currprefs.cs_ramseyrev >= 0) - v = ramsey_config; - } - if (addr == 0x02) { /* coldreboot flag */ - if (currprefs.cs_fatgaryrev >= 0) - v = gary_coldboot ? 0x80 : 0x00; - } - if (addr == 0x01) { /* toenb flag */ - if (currprefs.cs_fatgaryrev >= 0) - v = gary_toenb ? 0x80 : 0x00; - } - if (addr == 0x00) { /* timeout flag */ - if (currprefs.cs_fatgaryrev >= 0) - v = gary_timeout ? 0x80 : 0x00; + if (regs.s) { /* CPU FC = supervisor only */ + /* Gary ID (I don't think this exists in real chips..) */ + if (addr == 0x1002 && currprefs.cs_fatgaryrev >= 0) { + garyidoffset++; + garyidoffset &= 7; + v = (currprefs.cs_fatgaryrev << garyidoffset) & 0x80; + } + if (addr == 0x43) { /* RAMSEY revision */ + if (currprefs.cs_ramseyrev >= 0) + v = currprefs.cs_ramseyrev; + } + if (addr == 0x03) { /* RAMSEY config */ + if (currprefs.cs_ramseyrev >= 0) + v = ramsey_config; + } + if (addr == 0x02) { /* coldreboot flag */ + if (currprefs.cs_fatgaryrev >= 0) + v = gary_coldboot ? 0x80 : 0x00; + } + if (addr == 0x01) { /* toenb flag */ + if (currprefs.cs_fatgaryrev >= 0) + v = gary_toenb ? 0x80 : 0x00; + } + if (addr == 0x00) { /* timeout flag */ + if (currprefs.cs_fatgaryrev >= 0) + v = gary_timeout ? 0x80 : 0x00; + } + } else { + v = custom_bank.wget (addr); } - } else { - v = custom_bank.wget (addr); - } - if (MBRES_LOG > 0) - write_log (L"MBRES_READ %08X=%08X (%d) PC=%08X S=%d\n", addr, v, size, M68K_GETPC, regs.s); - return v; + if (MBRES_LOG > 0) + write_log (L"MBRES_READ %08X=%08X (%d) PC=%08X S=%d\n", addr, v, size, M68K_GETPC, regs.s); + return v; } static uae_u32 REGPARAM3 mbres_lget (uaecptr) REGPARAM; @@ -1339,73 +1339,73 @@ static void REGPARAM3 mbres_bput (uaecptr, uae_u32) REGPARAM; static uae_u32 REGPARAM2 mbres_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = mbres_wget (addr) << 16; - v |= mbres_wget (addr + 2); - return v; + v = mbres_wget (addr) << 16; + v |= mbres_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 mbres_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return mbres_read (addr, 2); + return mbres_read (addr, 2); } static uae_u32 REGPARAM2 mbres_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return mbres_read (addr, 1); + return mbres_read (addr, 1); } static void REGPARAM2 mbres_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbres_wput (addr, value >> 16); - mbres_wput (addr + 2, value & 0xffff); + mbres_wput (addr, value >> 16); + mbres_wput (addr + 2, value & 0xffff); } static void REGPARAM2 mbres_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbres_write (addr, value, 2); + mbres_write (addr, value, 2); } static void REGPARAM2 mbres_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - mbres_write (addr, value, 1); + mbres_write (addr, value, 1); } addrbank mbres_bank = { - mbres_lget, mbres_wget, mbres_bget, - mbres_lput, mbres_wput, mbres_bput, - default_xlate, default_check, NULL, L"Motherboard Resources", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + mbres_lget, mbres_wget, mbres_bget, + mbres_lput, mbres_wput, mbres_bput, + default_xlate, default_check, NULL, L"Motherboard Resources", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; void gayle_hsync (void) { - int i; + int i; - for (i = 0; i < 4; i++) { - struct ide_hdf *ide = idedrive[i]; - if (ide->irq_delay > 0) { - ide->irq_delay--; - if (ide->irq_delay == 0) - ide_interrupt_do (ide); + for (i = 0; i < 4; i++) { + struct ide_hdf *ide = idedrive[i]; + if (ide->irq_delay > 0) { + ide->irq_delay--; + if (ide->irq_delay == 0) + ide_interrupt_do (ide); + } } - } } static int pcmcia_common_size, pcmcia_attrs_size; @@ -1416,238 +1416,238 @@ static int pcmcia_write_min, pcmcia_write_max; static uae_u32 gayle_attr_read (uaecptr addr) { - uae_u8 v = 0; + uae_u8 v = 0; - if (PCMCIA_LOG > 1) - write_log (L"PCMCIA ATTR R: %x %x\n", addr, M68K_GETPC); - addr &= 0x80000 - 1; - if (addr >= 0x40000) { - if (PCMCIA_LOG > 0) - write_log (L"GAYLE: Reset disabled\n"); - return v; - } - if (addr >= pcmcia_attrs_size) + if (PCMCIA_LOG > 1) + write_log (L"PCMCIA ATTR R: %x %x\n", addr, M68K_GETPC); + addr &= 0x80000 - 1; + if (addr >= 0x40000) { + if (PCMCIA_LOG > 0) + write_log (L"GAYLE: Reset disabled\n"); + return v; + } + if (addr >= pcmcia_attrs_size) + return v; + v = pcmcia_attrs[addr / 2]; return v; - v = pcmcia_attrs[addr / 2]; - return v; } static void gayle_attr_write (uaecptr addr, uae_u32 v) { - if (PCMCIA_LOG > 1) - write_log (L"PCMCIA ATTR W: %x=%x %x\n", addr, v, M68K_GETPC); - addr &= 0x80000 - 1; - if (addr >= 0x40000) { - if (PCMCIA_LOG > 0) - write_log (L"GAYLE: Reset active\n"); - } else if (addr < pcmcia_attrs_size) { - ; - } + if (PCMCIA_LOG > 1) + write_log (L"PCMCIA ATTR W: %x=%x %x\n", addr, v, M68K_GETPC); + addr &= 0x80000 - 1; + if (addr >= 0x40000) { + if (PCMCIA_LOG > 0) + write_log (L"GAYLE: Reset active\n"); + } else if (addr < pcmcia_attrs_size) { + ; + } } static void initsramattr (int size, int readonly) { - uae_u8 *rp; - uae_u8 *p = pcmcia_attrs; - int sm, su, code, units; - struct hardfiledata *hfd = &pcmcia_sram->hfd; - int real = hfd->flags & HFD_FLAGS_REALDRIVE; - - code = 0; - su = 512; - sm = 16384; - while (size > sm) { - sm *= 4; - su *= 4; - code++; - } - units = 31 - ((sm - size) / su); - - /* CISTPL_DEVICE */ - *p++ = 0x01; - *p++ = 3; - *p++ = (6 /* DTYPE_SRAM */ << 4) | (readonly ? 8 : 0) | (4 /* SPEED_100NS */); - *p++ = (units << 3) | code; /* memory card size in weird units */ - *p++ = 0xff; - - /* CISTPL_DEVICEGEO */ - *p++ = 0x1e; - *p++ = 7; - *p++ = 2; /* 16-bit PCMCIA */ - *p++ = 0; - *p++ = 1; - *p++ = 1; - *p++ = 1; - *p++ = 1; - *p++ = 0xff; - - /* CISTPL_VERS_1 */ - *p++= 0x15; - rp = p++; - *p++= 4; /* PCMCIA 2.1 */ - *p++= 1; - if (real) { - ua_copy (p, -1, hfd->product_id); + uae_u8 *rp; + uae_u8 *p = pcmcia_attrs; + int sm, su, code, units; + struct hardfiledata *hfd = &pcmcia_sram->hfd; + int real = hfd->flags & HFD_FLAGS_REALDRIVE; + + code = 0; + su = 512; + sm = 16384; + while (size > sm) { + sm *= 4; + su *= 4; + code++; + } + units = 31 - ((sm - size) / su); + + /* CISTPL_DEVICE */ + *p++ = 0x01; + *p++ = 3; + *p++ = (6 /* DTYPE_SRAM */ << 4) | (readonly ? 8 : 0) | (4 /* SPEED_100NS */); + *p++ = (units << 3) | code; /* memory card size in weird units */ + *p++ = 0xff; + + /* CISTPL_DEVICEGEO */ + *p++ = 0x1e; + *p++ = 7; + *p++ = 2; /* 16-bit PCMCIA */ + *p++ = 0; + *p++ = 1; + *p++ = 1; + *p++ = 1; + *p++ = 1; + *p++ = 0xff; + + /* CISTPL_VERS_1 */ + *p++= 0x15; + rp = p++; + *p++= 4; /* PCMCIA 2.1 */ + *p++= 1; + if (real) { + ua_copy (p, -1, hfd->product_id); + p += strlen (p) + 1; + ua_copy(p, -1, hfd->product_rev); + } else { + strcpy (p, "UAE"); + p += strlen (p) + 1; + strcpy (p, "68000"); + } p += strlen (p) + 1; - ua_copy(p, -1, hfd->product_rev); - } else { - strcpy (p, "UAE"); + sprintf (p, "Generic Emulated %dKB PCMCIA SRAM Card", size >> 10); p += strlen (p) + 1; - strcpy (p, "68000"); - } - p += strlen (p) + 1; - sprintf (p, "Generic Emulated %dKB PCMCIA SRAM Card", size >> 10); - p += strlen (p) + 1; - *p++= 0; - *p++= 0xff; - *rp = p - rp; - - /* CISTPL_FUNCID */ - *p++ = 0x21; - *p++ = 2; - *p++ = 1; /* Memory Card */ - *p++ = 0; - - /* CISTPL_MANFID */ - *p++ = 0x20; - *p++ = 4; - *p++ = 0xff; - *p++ = 0xff; - *p++ = 1; - *p++ = 1; - - /* CISTPL_END */ - *p++ = 0xff; + *p++= 0; + *p++= 0xff; + *rp = p - rp; + + /* CISTPL_FUNCID */ + *p++ = 0x21; + *p++ = 2; + *p++ = 1; /* Memory Card */ + *p++ = 0; + + /* CISTPL_MANFID */ + *p++ = 0x20; + *p++ = 4; + *p++ = 0xff; + *p++ = 0xff; + *p++ = 1; + *p++ = 1; + + /* CISTPL_END */ + *p++ = 0xff; } static void checkflush (int addr) { - if (pcmcia_card == 0 || pcmcia_sram == 0) - return; - if (addr >= 0 && pcmcia_common[0] == 0 && pcmcia_common[1] == 0 && pcmcia_common[2] == 0) - return; // do not flush periodically if used as a ram expension - if (addr < 0) { - pcmcia_write_min = 0; - pcmcia_write_max = pcmcia_common_size; - } - if (pcmcia_write_min >= 0) { - if (abs (pcmcia_write_min - addr) >= 512 || abs (pcmcia_write_max - addr) >= 512) { - int blocksize = pcmcia_sram->hfd.blocksize; - int mask = ~(blocksize - 1); - int start = pcmcia_write_min & mask; - int end = (pcmcia_write_max + blocksize - 1) & mask; - int len = end - start; - if (len > 0) { - hdf_write (&pcmcia_sram->hfd, pcmcia_common + start, start, len); - pcmcia_write_min = -1; - pcmcia_write_max = -1; - } - } - } - if (pcmcia_write_min < 0 || pcmcia_write_min > addr) - pcmcia_write_min = addr; - if (pcmcia_write_max < 0 || pcmcia_write_max < addr) - pcmcia_write_max = addr; + if (pcmcia_card == 0 || pcmcia_sram == 0) + return; + if (addr >= 0 && pcmcia_common[0] == 0 && pcmcia_common[1] == 0 && pcmcia_common[2] == 0) + return; // do not flush periodically if used as a ram expension + if (addr < 0) { + pcmcia_write_min = 0; + pcmcia_write_max = pcmcia_common_size; + } + if (pcmcia_write_min >= 0) { + if (abs (pcmcia_write_min - addr) >= 512 || abs (pcmcia_write_max - addr) >= 512) { + int blocksize = pcmcia_sram->hfd.blocksize; + int mask = ~(blocksize - 1); + int start = pcmcia_write_min & mask; + int end = (pcmcia_write_max + blocksize - 1) & mask; + int len = end - start; + if (len > 0) { + hdf_write (&pcmcia_sram->hfd, pcmcia_common + start, start, len); + pcmcia_write_min = -1; + pcmcia_write_max = -1; + } + } + } + if (pcmcia_write_min < 0 || pcmcia_write_min > addr) + pcmcia_write_min = addr; + if (pcmcia_write_max < 0 || pcmcia_write_max < addr) + pcmcia_write_max = addr; } static int freepcmcia (int reset) { - if (pcmcia_sram) { - checkflush (-1); - if (reset) { - hdf_hd_close (pcmcia_sram); - xfree (pcmcia_sram); - pcmcia_sram = NULL; - } else { - pcmcia_sram->hfd.drive_empty = 1; + if (pcmcia_sram) { + checkflush (-1); + if (reset) { + hdf_hd_close (pcmcia_sram); + xfree (pcmcia_sram); + pcmcia_sram = NULL; + } else { + pcmcia_sram->hfd.drive_empty = 1; + } } - } - if (pcmcia_card) - gayle_cs_change (GAYLE_CS_CCDET, 0); - pcmcia_card = 0; + if (pcmcia_card) + gayle_cs_change (GAYLE_CS_CCDET, 0); + pcmcia_card = 0; + + xfree (pcmcia_common); + xfree (pcmcia_attrs); + pcmcia_common = NULL; + pcmcia_attrs = NULL; + pcmcia_common_size = 0; + pcmcia_attrs_size = 0; - xfree (pcmcia_common); - xfree (pcmcia_attrs); - pcmcia_common = NULL; - pcmcia_attrs = NULL; - pcmcia_common_size = 0; - pcmcia_attrs_size = 0; - - gayle_cfg = 0; - gayle_cs = 0; - return 1; + gayle_cfg = 0; + gayle_cs = 0; + return 1; } static int initpcmcia (const TCHAR *path, int readonly, int reset) { - if (currprefs.cs_pcmcia == 0) - return 0; - freepcmcia (reset); - if (!pcmcia_sram) - pcmcia_sram = xcalloc (sizeof (struct hd_hardfiledata), 1); - if (!pcmcia_sram->hfd.handle_valid) - reset = 1; - if (reset) { - if (path) - hdf_hd_open (pcmcia_sram, path, 512, readonly, NULL, 0, 0, 0, 0, NULL); - } else { - pcmcia_sram->hfd.drive_empty = 0; - } - if (pcmcia_sram->hfd.readonly) - readonly = 1; - pcmcia_common_size = 0; - pcmcia_readonly = readonly; - pcmcia_attrs_size = 256; - pcmcia_attrs = xcalloc (pcmcia_attrs_size, 1); - if (!pcmcia_sram->hfd.drive_empty) { - pcmcia_common_size = pcmcia_sram->hfd.virtsize; - if (pcmcia_sram->hfd.virtsize > 4 * 1024 * 1024) { - write_log (L"PCMCIA SRAM: too large device, %d bytes\n", pcmcia_sram->hfd.virtsize); - pcmcia_common_size = 4 * 1024 * 1024; - } - pcmcia_common = xcalloc (pcmcia_common_size, 1); - write_log (L"PCMCIA SRAM: '%s' open, size=%d\n", path, pcmcia_common_size); - hdf_read (&pcmcia_sram->hfd, pcmcia_common, 0, pcmcia_common_size); - pcmcia_card = 1; - initsramattr (pcmcia_common_size, readonly); - if (!(gayle_cs & GAYLE_CS_DIS)) { - gayle_map_pcmcia (); - card_trigger (1); - } - } - pcmcia_write_min = -1; - pcmcia_write_max = -1; - return 1; + if (currprefs.cs_pcmcia == 0) + return 0; + freepcmcia (reset); + if (!pcmcia_sram) + pcmcia_sram = xcalloc (sizeof (struct hd_hardfiledata), 1); + if (!pcmcia_sram->hfd.handle_valid) + reset = 1; + if (reset) { + if (path) + hdf_hd_open (pcmcia_sram, path, 512, readonly, NULL, 0, 0, 0, 0, NULL); + } else { + pcmcia_sram->hfd.drive_empty = 0; + } + if (pcmcia_sram->hfd.readonly) + readonly = 1; + pcmcia_common_size = 0; + pcmcia_readonly = readonly; + pcmcia_attrs_size = 256; + pcmcia_attrs = xcalloc (pcmcia_attrs_size, 1); + if (!pcmcia_sram->hfd.drive_empty) { + pcmcia_common_size = pcmcia_sram->hfd.virtsize; + if (pcmcia_sram->hfd.virtsize > 4 * 1024 * 1024) { + write_log (L"PCMCIA SRAM: too large device, %d bytes\n", pcmcia_sram->hfd.virtsize); + pcmcia_common_size = 4 * 1024 * 1024; + } + pcmcia_common = xcalloc (pcmcia_common_size, 1); + write_log (L"PCMCIA SRAM: '%s' open, size=%d\n", path, pcmcia_common_size); + hdf_read (&pcmcia_sram->hfd, pcmcia_common, 0, pcmcia_common_size); + pcmcia_card = 1; + initsramattr (pcmcia_common_size, readonly); + if (!(gayle_cs & GAYLE_CS_DIS)) { + gayle_map_pcmcia (); + card_trigger (1); + } + } + pcmcia_write_min = -1; + pcmcia_write_max = -1; + return 1; } static uae_u32 gayle_common_read (uaecptr addr) { - uae_u8 v = 0; - if (PCMCIA_LOG > 2) - write_log (L"PCMCIA COMMON R: %x %x\n", addr, M68K_GETPC); - if (!pcmcia_common_size) - return 0; - addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); - addr &= PCMCIA_COMMON_SIZE - 1; - if (addr < pcmcia_common_size) - v = pcmcia_common[addr]; - return v; + uae_u8 v = 0; + if (PCMCIA_LOG > 2) + write_log (L"PCMCIA COMMON R: %x %x\n", addr, M68K_GETPC); + if (!pcmcia_common_size) + return 0; + addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); + addr &= PCMCIA_COMMON_SIZE - 1; + if (addr < pcmcia_common_size) + v = pcmcia_common[addr]; + return v; } static void gayle_common_write (uaecptr addr, uae_u32 v) { - if (PCMCIA_LOG > 2) - write_log (L"PCMCIA COMMON W: %x=%x %x\n", addr, v, M68K_GETPC); - if (!pcmcia_common_size) - return; - if (pcmcia_readonly) - return; - addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); - addr &= PCMCIA_COMMON_SIZE - 1; - if (addr < pcmcia_common_size) { - if (pcmcia_common[addr] != v) { - checkflush (addr); - pcmcia_common[addr] = v; + if (PCMCIA_LOG > 2) + write_log (L"PCMCIA COMMON W: %x=%x %x\n", addr, v, M68K_GETPC); + if (!pcmcia_common_size) + return; + if (pcmcia_readonly) + return; + addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); + addr &= PCMCIA_COMMON_SIZE - 1; + if (addr < pcmcia_common_size) { + if (pcmcia_common[addr] != v) { + checkflush (addr); + pcmcia_common[addr] = v; + } } - } } static uae_u32 REGPARAM3 gayle_common_lget (uaecptr) REGPARAM; @@ -1659,25 +1659,25 @@ static void REGPARAM3 gayle_common_bput (uaecptr, uae_u32) REGPARAM; static int REGPARAM2 gayle_common_check (uaecptr addr, uae_u32 size) { - if (!pcmcia_common_size) - return 0; - addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); - addr &= PCMCIA_COMMON_SIZE - 1; - return (addr + size) <= PCMCIA_COMMON_SIZE; + if (!pcmcia_common_size) + return 0; + addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); + addr &= PCMCIA_COMMON_SIZE - 1; + return (addr + size) <= PCMCIA_COMMON_SIZE; } static uae_u8 *REGPARAM2 gayle_common_xlate (uaecptr addr) { - addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); - addr &= PCMCIA_COMMON_SIZE - 1; - return pcmcia_common + addr; + addr -= PCMCIA_COMMON_START & (PCMCIA_COMMON_SIZE - 1); + addr &= PCMCIA_COMMON_SIZE - 1; + return pcmcia_common + addr; } static addrbank gayle_common_bank = { - gayle_common_lget, gayle_common_wget, gayle_common_bget, - gayle_common_lput, gayle_common_wput, gayle_common_bput, - gayle_common_xlate, gayle_common_check, NULL, L"Gayle PCMCIA Common", - gayle_common_lget, gayle_common_wget, ABFLAG_RAM | ABFLAG_SAFE + gayle_common_lget, gayle_common_wget, gayle_common_bget, + gayle_common_lput, gayle_common_wput, gayle_common_bput, + gayle_common_xlate, gayle_common_check, NULL, L"Gayle PCMCIA Common", + gayle_common_lget, gayle_common_wget, ABFLAG_RAM | ABFLAG_SAFE }; @@ -1689,373 +1689,373 @@ static void REGPARAM3 gayle_attr_wput (uaecptr, uae_u32) REGPARAM; static void REGPARAM3 gayle_attr_bput (uaecptr, uae_u32) REGPARAM; addrbank gayle_attr_bank = { - gayle_attr_lget, gayle_attr_wget, gayle_attr_bget, - gayle_attr_lput, gayle_attr_wput, gayle_attr_bput, - default_xlate, default_check, NULL, L"Gayle PCMCIA Attribute/Misc", - dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE + gayle_attr_lget, gayle_attr_wget, gayle_attr_bget, + gayle_attr_lput, gayle_attr_wput, gayle_attr_bput, + default_xlate, default_check, NULL, L"Gayle PCMCIA Attribute/Misc", + dummy_lgeti, dummy_wgeti, ABFLAG_IO | ABFLAG_SAFE }; static uae_u32 REGPARAM2 gayle_attr_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle_attr_wget (addr) << 16; - v |= gayle_attr_wget (addr + 2); - return v; + v = gayle_attr_wget (addr) << 16; + v |= gayle_attr_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 gayle_attr_wget (uaecptr addr) { - uae_u16 v; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle_attr_bget (addr) << 8; - v |= gayle_attr_bget (addr + 1); - return v; + v = gayle_attr_bget (addr) << 8; + v |= gayle_attr_bget (addr + 1); + return v; } static uae_u32 REGPARAM2 gayle_attr_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return gayle_attr_read (addr); + return gayle_attr_read (addr); } static void REGPARAM2 gayle_attr_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_attr_wput (addr, value >> 16); - gayle_attr_wput (addr + 2, value & 0xffff); + gayle_attr_wput (addr, value >> 16); + gayle_attr_wput (addr + 2, value & 0xffff); } static void REGPARAM2 gayle_attr_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_attr_bput (addr, value >> 8); - gayle_attr_bput (addr + 1, value & 0xff); + gayle_attr_bput (addr, value >> 8); + gayle_attr_bput (addr + 1, value & 0xff); } static void REGPARAM2 gayle_attr_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_attr_write (addr, value); + gayle_attr_write (addr, value); } static uae_u32 REGPARAM2 gayle_common_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle_common_wget (addr) << 16; - v |= gayle_common_wget (addr + 2); - return v; + v = gayle_common_wget (addr) << 16; + v |= gayle_common_wget (addr + 2); + return v; } static uae_u32 REGPARAM2 gayle_common_wget (uaecptr addr) { - uae_u16 v; + uae_u16 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - v = gayle_common_bget (addr) << 8; - v |= gayle_common_bget (addr + 1); - return v; + v = gayle_common_bget (addr) << 8; + v |= gayle_common_bget (addr + 1); + return v; } static uae_u32 REGPARAM2 gayle_common_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return gayle_common_read (addr); + return gayle_common_read (addr); } static void REGPARAM2 gayle_common_lput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_common_wput (addr, value >> 16); - gayle_common_wput (addr + 2, value & 0xffff); + gayle_common_wput (addr, value >> 16); + gayle_common_wput (addr + 2, value & 0xffff); } static void REGPARAM2 gayle_common_wput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_common_bput (addr, value >> 8); - gayle_common_bput (addr + 1, value & 0xff); + gayle_common_bput (addr, value >> 8); + gayle_common_bput (addr + 1, value & 0xff); } static void REGPARAM2 gayle_common_bput (uaecptr addr, uae_u32 value) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - gayle_common_write (addr, value); + gayle_common_write (addr, value); } void gayle_map_pcmcia (void) { - if (currprefs.cs_pcmcia == 0) - return; - if (pcmcia_card == 0 || (gayle_cs & GAYLE_CS_DIS)) { - map_banks (&dummy_bank, 0xa0, 8, 0); - if (currprefs.chipmem_size <= 4 * 1024 * 1024 && currprefs.fastmem_size <= 4 * 1024 * 1024) - map_banks (&dummy_bank, PCMCIA_COMMON_START >> 16, PCMCIA_COMMON_SIZE >> 16, 0); - } else { - map_banks (&gayle_attr_bank, 0xa0, 8, 0); - if (currprefs.chipmem_size <= 4 * 1024 * 1024 && currprefs.fastmem_size <= 4 * 1024 * 1024) - map_banks (&gayle_common_bank, PCMCIA_COMMON_START >> 16, PCMCIA_COMMON_SIZE >> 16, 0); - } + if (currprefs.cs_pcmcia == 0) + return; + if (pcmcia_card == 0 || (gayle_cs & GAYLE_CS_DIS)) { + map_banks (&dummy_bank, 0xa0, 8, 0); + if (currprefs.chipmem_size <= 4 * 1024 * 1024 && currprefs.fastmem_size <= 4 * 1024 * 1024) + map_banks (&dummy_bank, PCMCIA_COMMON_START >> 16, PCMCIA_COMMON_SIZE >> 16, 0); + } else { + map_banks (&gayle_attr_bank, 0xa0, 8, 0); + if (currprefs.chipmem_size <= 4 * 1024 * 1024 && currprefs.fastmem_size <= 4 * 1024 * 1024) + map_banks (&gayle_common_bank, PCMCIA_COMMON_START >> 16, PCMCIA_COMMON_SIZE >> 16, 0); + } } static int rl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); } void gayle_free_units (void) { - int i; + int i; - for (i = 0; i < 4; i++) { - struct ide_hdf *ide = idedrive[i]; - if (ide) { - hdf_hd_close (&ide->hdhfd); - memset (ide, 0, sizeof (struct ide_hdf)); + for (i = 0; i < 4; i++) { + struct ide_hdf *ide = idedrive[i]; + if (ide) { + hdf_hd_close (&ide->hdhfd); + memset (ide, 0, sizeof (struct ide_hdf)); + } } - } - freepcmcia (1); + freepcmcia (1); } static void alloc_ide_mem (struct ide_hdf **ide, int max) { - int i; + int i; - for (i = 0; i < max; i++) { - if (!ide[i]) - ide[i] = xcalloc (sizeof (struct ide_hdf), 1); - } + for (i = 0; i < max; i++) { + if (!ide[i]) + ide[i] = xcalloc (sizeof (struct ide_hdf), 1); + } } #if 0 #include "zfile.h" static void dumphdf (struct hardfiledata *hfd) { - int i; - uae_u8 buf[512]; - int off; - struct zfile *zf; - - zf = zfile_fopen ("c:\\d\\tmp.dmp", "wb"); - off = 0; - for (i = 0; i < 128; i++) { - hdf_read (hfd, buf, off, 512); - zfile_fwrite (buf, 1, 512, zf); - off += 512; - } - zfile_fclose (zf); + int i; + uae_u8 buf[512]; + int off; + struct zfile *zf; + + zf = zfile_fopen ("c:\\d\\tmp.dmp", "wb"); + off = 0; + for (i = 0; i < 128; i++) { + hdf_read (hfd, buf, off, 512); + zfile_fwrite (buf, 1, 512, zf); + off += 512; + } + zfile_fclose (zf); } #endif int gayle_add_ide_unit (int ch, TCHAR *path, int blocksize, int readonly, - TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, TCHAR *filesys) -{ - struct ide_hdf *ide; - - if (ch >= 4) - return -1; - alloc_ide_mem (idedrive, 4); - ide = idedrive[ch]; - if (!hdf_hd_open (&ide->hdhfd, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys)) - return -1; - ide->blocksize = blocksize; - ide->lba48 = ide->hdhfd.size >= 128 * (uae_u64)0x40000000 ? 1 : 0; - write_log (L"GAYLE_IDE%d '%s', CHS=%d,%d,%d. %uM. LBA48=%d\n", - ch, path, ide->hdhfd.cyls, ide->hdhfd.heads, ide->hdhfd.secspertrack, (int)(ide->hdhfd.size / (1024 * 1024)), ide->lba48); - ide->status = 0; - ide->data_offset = 0; - ide->data_size = 0; - ide->type = IDE_GAYLE; - //dumphdf (&ide->hdhfd.hfd); - return 1; + TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, TCHAR *filesys) +{ + struct ide_hdf *ide; + + if (ch >= 4) + return -1; + alloc_ide_mem (idedrive, 4); + ide = idedrive[ch]; + if (!hdf_hd_open (&ide->hdhfd, path, blocksize, readonly, devname, sectors, surfaces, reserved, bootpri, filesys)) + return -1; + ide->blocksize = blocksize; + ide->lba48 = ide->hdhfd.size >= 128 * (uae_u64)0x40000000 ? 1 : 0; + write_log (L"GAYLE_IDE%d '%s', CHS=%d,%d,%d. %uM. LBA48=%d\n", + ch, path, ide->hdhfd.cyls, ide->hdhfd.heads, ide->hdhfd.secspertrack, (int)(ide->hdhfd.size / (1024 * 1024)), ide->lba48); + ide->status = 0; + ide->data_offset = 0; + ide->data_size = 0; + ide->type = IDE_GAYLE; + //dumphdf (&ide->hdhfd.hfd); + return 1; } int gayle_add_pcmcia_sram_unit (const TCHAR *path, int readonly) { - return initpcmcia (path, readonly, 1); + return initpcmcia (path, readonly, 1); } int gayle_modify_pcmcia_sram_unit (const TCHAR *path, int readonly, int insert) { - if (insert) - return initpcmcia (path, readonly, pcmcia_sram ? 0 : 1); - else - return freepcmcia (0); + if (insert) + return initpcmcia (path, readonly, pcmcia_sram ? 0 : 1); + else + return freepcmcia (0); } static void initide (void) { - int i; - - alloc_ide_mem (idedrive, 4); - if (savestate_state == STATE_RESTORE) - return; - ide_error = 1; - ide_sector = ide_nsector = 1; - ide_select = 0; - ide_lcyl = ide_hcyl = ide_devcon = ide_feat = 0; - ide_drv = 0; - ide_splitter = 0; - if (idedrive[2]->hdhfd.size) { - ide_splitter = 1; - write_log (L"IDE splitter enabled\n"); - } - for (i = 0; i < 4; i++) - idedrive[i]->num = i; - gayle_irq = gayle_int = 0; + int i; + + alloc_ide_mem (idedrive, 4); + if (savestate_state == STATE_RESTORE) + return; + ide_error = 1; + ide_sector = ide_nsector = 1; + ide_select = 0; + ide_lcyl = ide_hcyl = ide_devcon = ide_feat = 0; + ide_drv = 0; + ide_splitter = 0; + if (idedrive[2]->hdhfd.size) { + ide_splitter = 1; + write_log (L"IDE splitter enabled\n"); + } + for (i = 0; i < 4; i++) + idedrive[i]->num = i; + gayle_irq = gayle_int = 0; } void gayle_reset (int hardreset) { - static TCHAR bankname[100]; - - initide (); - if (hardreset) { - ramsey_config = 0; - gary_coldboot = 1; - gary_timeout = 0; - gary_toenb = 0; - } - _tcscpy (bankname, L"Gayle (low)"); - if (currprefs.cs_ide == IDE_A4000) - _tcscpy (bankname, L"A4000 IDE"); - if (currprefs.cs_mbdmac == 2) { - _tcscat (bankname, L" + NCR53C710 SCSI"); - ncr_reset (); - } - gayle_bank.name = bankname; + static TCHAR bankname[100]; + + initide (); + if (hardreset) { + ramsey_config = 0; + gary_coldboot = 1; + gary_timeout = 0; + gary_toenb = 0; + } + _tcscpy (bankname, L"Gayle (low)"); + if (currprefs.cs_ide == IDE_A4000) + _tcscpy (bankname, L"A4000 IDE"); + if (currprefs.cs_mbdmac == 2) { + _tcscat (bankname, L" + NCR53C710 SCSI"); + ncr_reset (); + } + gayle_bank.name = bankname; } uae_u8 *restore_gayle (uae_u8 *src) { - changed_prefs.cs_ide = restore_u8 (); - gayle_int = restore_u8 (); - gayle_irq = restore_u8 (); - gayle_cs = restore_u8 (); - gayle_cs_mask = restore_u8 (); - gayle_cfg = restore_u8 (); - ide_error = 0; - return src; + changed_prefs.cs_ide = restore_u8 (); + gayle_int = restore_u8 (); + gayle_irq = restore_u8 (); + gayle_cs = restore_u8 (); + gayle_cs_mask = restore_u8 (); + gayle_cfg = restore_u8 (); + ide_error = 0; + return src; } uae_u8 *save_gayle (int *len) { - uae_u8 *dstbak, *dst; + uae_u8 *dstbak, *dst; - if (currprefs.cs_ide <= 0) - return NULL; - dstbak = dst = malloc (1000); - save_u8 (currprefs.cs_ide); - save_u8 (gayle_int); - save_u8 (gayle_irq); - save_u8 (gayle_cs); - save_u8 (gayle_cs_mask); - save_u8 (gayle_cfg); - *len = dst - dstbak; - return dstbak; + if (currprefs.cs_ide <= 0) + return NULL; + dstbak = dst = malloc (1000); + save_u8 (currprefs.cs_ide); + save_u8 (gayle_int); + save_u8 (gayle_irq); + save_u8 (gayle_cs); + save_u8 (gayle_cs_mask); + save_u8 (gayle_cfg); + *len = dst - dstbak; + return dstbak; } uae_u8 *save_ide (int num, int *len) { - uae_u8 *dstbak, *dst; - struct ide_hdf *ide; - - if (idedrive[num] == NULL) - return NULL; - if (currprefs.cs_ide <= 0) - return NULL; - ide = idedrive[num]; - if (ide->hdhfd.size == 0) - return NULL; - dstbak = dst = malloc (1000); - save_u32 (num); - save_u64 (ide->hdhfd.size); - save_string (ide->hdhfd.path); - save_u32 (ide->hdhfd.hfd.blocksize); - save_u32 (ide->hdhfd.hfd.readonly); - save_u8 (ide->multiple_mode); - save_u32 (ide->hdhfd.cyls); - save_u32 (ide->hdhfd.heads); - save_u32 (ide->hdhfd.secspertrack); - save_u8 (ide_select); - save_u8 (ide_nsector); - save_u8 (ide_nsector2); - save_u8 (ide_sector); - save_u8 (ide_sector2); - save_u8 (ide_lcyl); - save_u8 (ide_lcyl2); - save_u8 (ide_hcyl); - save_u8 (ide_hcyl2); - save_u8 (ide_feat); - save_u8 (ide_feat2); - save_u8 (ide_error); - save_u8 (ide_devcon); - save_u64 (ide->hdhfd.hfd.virtual_size); - save_u32 (ide->hdhfd.hfd.secspertrack); - save_u32 (ide->hdhfd.hfd.heads); - save_u32 (ide->hdhfd.hfd.reservedblocks); - save_u32 (ide->hdhfd.bootpri); - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + struct ide_hdf *ide; + + if (idedrive[num] == NULL) + return NULL; + if (currprefs.cs_ide <= 0) + return NULL; + ide = idedrive[num]; + if (ide->hdhfd.size == 0) + return NULL; + dstbak = dst = malloc (1000); + save_u32 (num); + save_u64 (ide->hdhfd.size); + save_string (ide->hdhfd.path); + save_u32 (ide->hdhfd.hfd.blocksize); + save_u32 (ide->hdhfd.hfd.readonly); + save_u8 (ide->multiple_mode); + save_u32 (ide->hdhfd.cyls); + save_u32 (ide->hdhfd.heads); + save_u32 (ide->hdhfd.secspertrack); + save_u8 (ide_select); + save_u8 (ide_nsector); + save_u8 (ide_nsector2); + save_u8 (ide_sector); + save_u8 (ide_sector2); + save_u8 (ide_lcyl); + save_u8 (ide_lcyl2); + save_u8 (ide_hcyl); + save_u8 (ide_hcyl2); + save_u8 (ide_feat); + save_u8 (ide_feat2); + save_u8 (ide_error); + save_u8 (ide_devcon); + save_u64 (ide->hdhfd.hfd.virtual_size); + save_u32 (ide->hdhfd.hfd.secspertrack); + save_u32 (ide->hdhfd.hfd.heads); + save_u32 (ide->hdhfd.hfd.reservedblocks); + save_u32 (ide->hdhfd.bootpri); + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_ide (uae_u8 *src) { - int num, readonly, blocksize; - uae_u64 size; - TCHAR *path; - struct ide_hdf *ide; - - alloc_ide_mem (idedrive, 4); - num = restore_u32 (); - ide = idedrive[num]; - size = restore_u64 (); - path = restore_string (); - blocksize = restore_u32 (); - readonly = restore_u32 (); - ide->multiple_mode = restore_u8 (); - ide->hdhfd.cyls = restore_u32 (); - ide->hdhfd.heads = restore_u32 (); - ide->hdhfd.secspertrack = restore_u32 (); - ide_select = restore_u8 (); - ide_nsector = restore_u8 (); - ide_sector = restore_u8 (); - ide_lcyl = restore_u8 (); - ide_hcyl = restore_u8 (); - ide_feat = restore_u8 (); - ide_nsector2 = restore_u8 (); - ide_sector2 = restore_u8 (); - ide_lcyl2 = restore_u8 (); - ide_hcyl2 = restore_u8 (); - ide_feat2 = restore_u8 (); - ide_error = restore_u8 (); - ide_devcon = restore_u8 (); - ide->hdhfd.hfd.virtual_size = restore_u64 (); - ide->hdhfd.hfd.secspertrack = restore_u32 (); - ide->hdhfd.hfd.heads = restore_u32 (); - ide->hdhfd.hfd.reservedblocks = restore_u32 (); - ide->hdhfd.bootpri = restore_u32 (); - if (ide->hdhfd.hfd.virtual_size) - gayle_add_ide_unit (num, path, blocksize, readonly, ide->hdhfd.hfd.device_name, - ide->hdhfd.hfd.secspertrack, ide->hdhfd.hfd.heads, ide->hdhfd.hfd.reservedblocks, ide->hdhfd.bootpri, NULL); - else - gayle_add_ide_unit (num, path, blocksize, readonly, 0, 0, 0, 0, 0, 0); - xfree (path); - return src; + int num, readonly, blocksize; + uae_u64 size; + TCHAR *path; + struct ide_hdf *ide; + + alloc_ide_mem (idedrive, 4); + num = restore_u32 (); + ide = idedrive[num]; + size = restore_u64 (); + path = restore_string (); + blocksize = restore_u32 (); + readonly = restore_u32 (); + ide->multiple_mode = restore_u8 (); + ide->hdhfd.cyls = restore_u32 (); + ide->hdhfd.heads = restore_u32 (); + ide->hdhfd.secspertrack = restore_u32 (); + ide_select = restore_u8 (); + ide_nsector = restore_u8 (); + ide_sector = restore_u8 (); + ide_lcyl = restore_u8 (); + ide_hcyl = restore_u8 (); + ide_feat = restore_u8 (); + ide_nsector2 = restore_u8 (); + ide_sector2 = restore_u8 (); + ide_lcyl2 = restore_u8 (); + ide_hcyl2 = restore_u8 (); + ide_feat2 = restore_u8 (); + ide_error = restore_u8 (); + ide_devcon = restore_u8 (); + ide->hdhfd.hfd.virtual_size = restore_u64 (); + ide->hdhfd.hfd.secspertrack = restore_u32 (); + ide->hdhfd.hfd.heads = restore_u32 (); + ide->hdhfd.hfd.reservedblocks = restore_u32 (); + ide->hdhfd.bootpri = restore_u32 (); + if (ide->hdhfd.hfd.virtual_size) + gayle_add_ide_unit (num, path, blocksize, readonly, ide->hdhfd.hfd.device_name, + ide->hdhfd.hfd.secspertrack, ide->hdhfd.hfd.heads, ide->hdhfd.hfd.reservedblocks, ide->hdhfd.bootpri, NULL); + else + gayle_add_ide_unit (num, path, blocksize, readonly, 0, 0, 0, 0, 0, 0); + xfree (path); + return src; } diff --git a/gencpu.c b/gencpu.c index 054ebb81..240620e0 100644 --- a/gencpu.c +++ b/gencpu.c @@ -1,22 +1,22 @@ /* - * UAE - The Un*x Amiga Emulator - * - * MC68000 emulation generator - * - * This is a fairly stupid program that generates a lot of case labels that - * can be #included in a switch statement. - * As an alternative, it can generate functions that handle specific - * MC68000 instructions, plus a prototype header file and a function pointer - * array to look up the function for an opcode. - * Error checking is bad, an illegal table68k file will cause the program to - * call abort(). - * The generated code is sometimes sub-optimal, an optimizing compiler should - * take care of this. - * - * The source for the insn timings is Markt & Technik's Amiga Magazin 8/1992. - * - * Copyright 1995, 1996, 1997, 1998, 1999, 2000 Bernd Schmidt - */ +* UAE - The Un*x Amiga Emulator +* +* MC68000 emulation generator +* +* This is a fairly stupid program that generates a lot of case labels that +* can be #included in a switch statement. +* As an alternative, it can generate functions that handle specific +* MC68000 instructions, plus a prototype header file and a function pointer +* array to look up the function for an opcode. +* Error checking is bad, an illegal table68k file will cause the program to +* call abort(). +* The generated code is sometimes sub-optimal, an optimizing compiler should +* take care of this. +* +* The source for the insn timings is Markt & Technik's Amiga Magazin 8/1992. +* +* Copyright 1995, 1996, 1997, 1998, 1999, 2000 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -50,8 +50,8 @@ static int optimized_flags; #define GF_FC 32 /* For the current opcode, the next lower level that will have different code. - * Initialized to -1 for each opcode. If it remains unchanged, indicates we - * are done with that opcode. */ +* Initialized to -1 for each opcode. If it remains unchanged, indicates we +* are done with that opcode. */ static int next_cpu_level; static int *opcode_map; @@ -70,38 +70,38 @@ static int fixupcnt; static void read_counts (void) { - FILE *file; - unsigned long opcode, count, total; - char name[20]; - int nr = 0; - memset (counts, 0, 65536 * sizeof *counts); - - count = 0; - file = fopen ("frequent.68k", "r"); - if (file) { - fscanf (file, "Total: %lu\n", &total); - while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) { - opcode_next_clev[nr] = 5; - opcode_last_postfix[nr] = -1; - opcode_map[nr++] = opcode; - counts[opcode] = count; - } - fclose (file); - } - if (nr == nr_cpuop_funcs) - return; - for (opcode = 0; opcode < 0x10000; opcode++) { - if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG - && counts[opcode] == 0) - { - opcode_next_clev[nr] = 5; - opcode_last_postfix[nr] = -1; - opcode_map[nr++] = opcode; - counts[opcode] = count; + FILE *file; + unsigned long opcode, count, total; + char name[20]; + int nr = 0; + memset (counts, 0, 65536 * sizeof *counts); + + count = 0; + file = fopen ("frequent.68k", "r"); + if (file) { + fscanf (file, "Total: %lu\n", &total); + while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) { + opcode_next_clev[nr] = 5; + opcode_last_postfix[nr] = -1; + opcode_map[nr++] = opcode; + counts[opcode] = count; + } + fclose (file); + } + if (nr == nr_cpuop_funcs) + return; + for (opcode = 0; opcode < 0x10000; opcode++) { + if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG + && counts[opcode] == 0) + { + opcode_next_clev[nr] = 5; + opcode_last_postfix[nr] = -1; + opcode_map[nr++] = opcode; + counts[opcode] = count; + } } - } - if (nr != nr_cpuop_funcs) - abort (); + if (nr != nr_cpuop_funcs) + abort (); } static char endlabelstr[80]; @@ -114,3287 +114,3283 @@ static int insn_n_cycles, insn_n_cycles020; static void fpulimit (void) { - if (limit_braces) - return; - printf ("\n#ifdef FPUEMU\n"); - limit_braces = n_braces; - n_braces = 0; + if (limit_braces) + return; + printf ("\n#ifdef FPUEMU\n"); + limit_braces = n_braces; + n_braces = 0; } static void cpulimit (void) { - printf ("#ifndef CPUEMU_68000_ONLY\n"); + printf ("#ifndef CPUEMU_68000_ONLY\n"); } static void returncycles (char *s, int cycles) { - if (using_ce) - return; - if (using_ce020) - printf ("%sreturn;\n", s); - else - printf ("%sreturn %d * CYCLE_UNIT / 2;\n", s, cycles); + if (using_ce) + return; + if (using_ce020) + printf ("%sreturn;\n", s); + else + printf ("%sreturn %d * CYCLE_UNIT / 2;\n", s, cycles); } static void addcycles_ce020 (int cycles) { - if (!using_ce020) - return; - cycles--; - if (cycles > 0) - printf ("\tdo_cycles_ce020 (%d);\n", cycles); - count_cycles += cycles; - insn_n_cycles020 -= cycles; - if (insn_n_cycles020 < 0) - insn_n_cycles020 = 0; + if (!using_ce020) + return; + if (cycles > 0) + printf ("\tregs.ce020memcycles += %d * cpucycleunit;\n", cycles); + count_cycles += cycles; } static void addcycles000 (int cycles) { - if (!using_ce) - return; - printf ("\tdo_cycles_ce000 (%d);\n", cycles); - count_cycles += cycles; + if (!using_ce) + return; + printf ("\tdo_cycles_ce000 (%d);\n", cycles); + count_cycles += cycles; } static void addcycles000_2 (char *s, int cycles) { - if (!using_ce) - return; - printf ("%sdo_cycles_ce000 (%d);\n", s, cycles); - count_cycles += cycles; + if (!using_ce) + return; + printf ("%sdo_cycles_ce000 (%d);\n", s, cycles); + count_cycles += cycles; } static void addcycles000_3 (char *s) { - if (!using_ce) - return; - printf ("%sif (cycles > 0) do_cycles_ce000 (cycles);\n", s); - count_ncycles++; + if (!using_ce) + return; + printf ("%sif (cycles > 0) do_cycles_ce000 (cycles);\n", s); + count_ncycles++; } static int isreg (amodes mode) { - if (mode == Dreg || mode == Areg) - return 1; - return 0; + if (mode == Dreg || mode == Areg) + return 1; + return 0; } static void start_brace (void) { - n_braces++; - printf ("{"); + n_braces++; + printf ("{"); } static void close_brace (void) { - assert (n_braces > 0); - n_braces--; - printf ("}"); + assert (n_braces > 0); + n_braces--; + printf ("}"); } static void finish_braces (void) { - while (n_braces > 0) - close_brace (); + while (n_braces > 0) + close_brace (); } static void pop_braces (int to) { - while (n_braces > to) - close_brace (); + while (n_braces > to) + close_brace (); } static int bit_size (int size) { - switch (size) { - case sz_byte: return 8; - case sz_word: return 16; - case sz_long: return 32; - default: abort (); - } - return 0; + switch (size) { + case sz_byte: return 8; + case sz_word: return 16; + case sz_long: return 32; + default: abort (); + } + return 0; } static const char *bit_mask (int size) { - switch (size) { - case sz_byte: return "0xff"; - case sz_word: return "0xffff"; - case sz_long: return "0xffffffff"; - default: abort (); - } - return 0; + switch (size) { + case sz_byte: return "0xff"; + case sz_word: return "0xffff"; + case sz_long: return "0xffffffff"; + default: abort (); + } + return 0; } static void gen_nextilong (char *type, char *name, int norefill) { - int r = m68k_pc_offset; - m68k_pc_offset += 4; - - if (using_ce020) { - printf ("\t%s %s = get_long_ce020_prefetch (%d);\n", type, name, r); - count_read += 2; - } else if (using_ce) { - printf ("\t%s %s;\n", type, name); - /* we must do this because execution order of (something | something2) is not defined */ - if (norefill) { - printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2); - count_read++; - printf ("\t%s |= regs.irc;\n", name); - } else { - printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2); - count_read++; - printf ("\t%s |= get_word_ce_prefetch (%d);\n", name, r + 4); - count_read++; - } - } else { - if (using_prefetch) { - if (norefill) { + int r = m68k_pc_offset; + m68k_pc_offset += 4; + + if (using_ce020) { + printf ("\t%s %s = get_long_ce020_prefetch (%d);\n", type, name, r); + count_read += 2; + } else if (using_ce) { printf ("\t%s %s;\n", type, name); - printf ("\t%s = get_word_prefetch (%d) << 16;\n", name, r + 2); - count_read++; - printf ("\t%s |= regs.irc;\n", name); - insn_n_cycles += 4; - } else { - printf ("\t%s %s = get_long_prefetch (%d);\n", type, name, r + 2); - count_read++; - count_read++; - insn_n_cycles += 8; - } - } else if (using_indirect) { - insn_n_cycles += 8; - printf ("\t%s %s = get_ilongi (%d);\n", type, name, r); - } else if (using_mmu) { - insn_n_cycles += 8; - printf ("\t%s %s = get_ilong_mmu (%d);\n", type, name, r); + /* we must do this because execution order of (something | something2) is not defined */ + if (norefill) { + printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2); + count_read++; + printf ("\t%s |= regs.irc;\n", name); + } else { + printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2); + count_read++; + printf ("\t%s |= get_word_ce_prefetch (%d);\n", name, r + 4); + count_read++; + } } else { - insn_n_cycles += 8; - printf ("\t%s %s = get_ilong (%d);\n", type, name, r); + if (using_prefetch) { + if (norefill) { + printf ("\t%s %s;\n", type, name); + printf ("\t%s = get_word_prefetch (%d) << 16;\n", name, r + 2); + count_read++; + printf ("\t%s |= regs.irc;\n", name); + insn_n_cycles += 4; + } else { + printf ("\t%s %s = get_long_prefetch (%d);\n", type, name, r + 2); + count_read++; + count_read++; + insn_n_cycles += 8; + } + } else if (using_indirect) { + insn_n_cycles += 8; + printf ("\t%s %s = get_ilongi (%d);\n", type, name, r); + } else if (using_mmu) { + insn_n_cycles += 8; + printf ("\t%s %s = get_ilong_mmu (%d);\n", type, name, r); + } else { + insn_n_cycles += 8; + printf ("\t%s %s = get_ilong (%d);\n", type, name, r); + } } - } } static const char *gen_nextiword (int norefill) { - static char buffer[80]; - int r = m68k_pc_offset; - m68k_pc_offset += 2; - - if (using_ce020) { - sprintf (buffer, "get_word_ce020_prefetch (%d)", r); - count_read++; - } else if (using_ce) { - if (norefill) { - strcpy (buffer, "regs.irc"); - } else { - sprintf (buffer, "get_word_ce_prefetch (%d)", r + 2); - count_read++; - } - } else { - if (using_prefetch) { - if (norefill) { - sprintf (buffer, "regs.irc", r); - } else { - sprintf (buffer, "get_word_prefetch (%d)", r + 2); + static char buffer[80]; + int r = m68k_pc_offset; + m68k_pc_offset += 2; + + if (using_ce020) { + sprintf (buffer, "get_word_ce020_prefetch (%d)", r); count_read++; - insn_n_cycles += 4; - } - } else if (using_indirect) { - sprintf (buffer, "get_iwordi(%d)", r); - insn_n_cycles += 4; - } else if (using_mmu) { - sprintf (buffer, "get_iword_mmu (%d)", r); - insn_n_cycles += 4; + } else if (using_ce) { + if (norefill) { + strcpy (buffer, "regs.irc"); + } else { + sprintf (buffer, "get_word_ce_prefetch (%d)", r + 2); + count_read++; + } } else { - sprintf (buffer, "get_iword (%d)", r); - insn_n_cycles += 4; + if (using_prefetch) { + if (norefill) { + sprintf (buffer, "regs.irc", r); + } else { + sprintf (buffer, "get_word_prefetch (%d)", r + 2); + count_read++; + insn_n_cycles += 4; + } + } else if (using_indirect) { + sprintf (buffer, "get_iwordi(%d)", r); + insn_n_cycles += 4; + } else if (using_mmu) { + sprintf (buffer, "get_iword_mmu (%d)", r); + insn_n_cycles += 4; + } else { + sprintf (buffer, "get_iword (%d)", r); + insn_n_cycles += 4; + } } - } - return buffer; + return buffer; } static const char *gen_nextibyte (int norefill) { - static char buffer[80]; - int r = m68k_pc_offset; - m68k_pc_offset += 2; - - if (using_ce020) { - sprintf (buffer, "(uae_u8)get_word_ce020_prefetch (%d)", r); - count_read++; - } else if (using_ce) { - if (norefill) { - strcpy (buffer, "(uae_u8)regs.irc"); - } else { - sprintf (buffer, "(uae_u8)get_word_ce_prefetch (%d)", r + 2); - count_read++; - } - } else { - insn_n_cycles += 4; - if (using_prefetch) { - if (norefill) { - sprintf (buffer, "(uae_u8)regs.irc", r); - } else { - sprintf (buffer, "(uae_u8)get_word_prefetch (%d)", r + 2); - insn_n_cycles += 4; + static char buffer[80]; + int r = m68k_pc_offset; + m68k_pc_offset += 2; + + if (using_ce020) { + sprintf (buffer, "(uae_u8)get_word_ce020_prefetch (%d)", r); count_read++; - } - } else if (using_indirect) { - sprintf (buffer, "get_ibytei (%d)", r); - insn_n_cycles += 4; - } else if (using_mmu) { - sprintf (buffer, "get_ibyte_mmu (%d)", r); - insn_n_cycles += 4; + } else if (using_ce) { + if (norefill) { + strcpy (buffer, "(uae_u8)regs.irc"); + } else { + sprintf (buffer, "(uae_u8)get_word_ce_prefetch (%d)", r + 2); + count_read++; + } } else { - sprintf (buffer, "get_ibyte (%d)", r); - insn_n_cycles += 4; + insn_n_cycles += 4; + if (using_prefetch) { + if (norefill) { + sprintf (buffer, "(uae_u8)regs.irc", r); + } else { + sprintf (buffer, "(uae_u8)get_word_prefetch (%d)", r + 2); + insn_n_cycles += 4; + count_read++; + } + } else if (using_indirect) { + sprintf (buffer, "get_ibytei (%d)", r); + insn_n_cycles += 4; + } else if (using_mmu) { + sprintf (buffer, "get_ibyte_mmu (%d)", r); + insn_n_cycles += 4; + } else { + sprintf (buffer, "get_ibyte (%d)", r); + insn_n_cycles += 4; + } } - } - return buffer; + return buffer; } static void irc2ir (void) { - if (!using_prefetch) - return; - printf ("\tregs.ir = regs.irc;\n"); + if (!using_prefetch) + return; + printf ("\tregs.ir = regs.irc;\n"); } static int did_prefetch; static void fill_prefetch_2 (void) { - if (!using_prefetch) - return; - if (using_ce) - printf ("\tget_word_ce_prefetch (%d);\n", m68k_pc_offset + 2); - else - printf ("\tget_word_prefetch (%d);\n", m68k_pc_offset + 2); - did_prefetch = 1; - count_read++; - insn_n_cycles += 4; + if (!using_prefetch) + return; + if (using_ce) + printf ("\tget_word_ce_prefetch (%d);\n", m68k_pc_offset + 2); + else + printf ("\tget_word_prefetch (%d);\n", m68k_pc_offset + 2); + did_prefetch = 1; + count_read++; + insn_n_cycles += 4; } static void fill_prefetch_1 (int o) { - if (!using_prefetch) - return; - if (using_ce) { - printf ("\tget_word_ce_prefetch (%d);\n", o); - } else { - printf ("\tget_word_prefetch (%d);\n", o); - } - did_prefetch = 1; - count_read++; - insn_n_cycles += 4; + if (!using_prefetch) + return; + if (using_ce) { + printf ("\tget_word_ce_prefetch (%d);\n", o); + } else { + printf ("\tget_word_prefetch (%d);\n", o); + } + did_prefetch = 1; + count_read++; + insn_n_cycles += 4; } static void fill_prefetch_full (void) { - fill_prefetch_1 (0); - irc2ir (); - fill_prefetch_1 (2); + fill_prefetch_1 (0); + irc2ir (); + fill_prefetch_1 (2); } static void fill_prefetch_0 (void) { - if (!using_prefetch) - return; - if (using_ce) - printf ("\tget_word_ce_prefetch (0);\n"); - else - printf ("\tget_word_prefetch (0);\n"); - did_prefetch = 1; - count_read++; - insn_n_cycles += 4; + if (!using_prefetch) + return; + if (using_ce) + printf ("\tget_word_ce_prefetch (0);\n"); + else + printf ("\tget_word_prefetch (0);\n"); + did_prefetch = 1; + count_read++; + insn_n_cycles += 4; } static void fill_prefetch_next_1 (void) { - irc2ir (); - fill_prefetch_1 (m68k_pc_offset + 2); + irc2ir (); + fill_prefetch_1 (m68k_pc_offset + 2); } static void fill_prefetch_next (void) { - fill_prefetch_next_1 (); + fill_prefetch_next_1 (); } #if 0 static void fill_prefetch_next_delay (int extracycles) { - if (!using_prefetch) - return; - if (using_ce) { - if (extracycles > 0) { - printf("\t{\n"); - fill_prefetch_next (); - printf("\tif (%d > 0) do_cycles(%d * CYCLE_UNIT / 2);\n", - extracycles, extracycles); - printf("\t}\n"); + if (!using_prefetch) + return; + if (using_ce) { + if (extracycles > 0) { + printf("\t{\n"); + fill_prefetch_next (); + printf("\tif (%d > 0) do_cycles(%d * CYCLE_UNIT / 2);\n", + extracycles, extracycles); + printf("\t}\n"); + } else { + fill_prefetch_next (); + } } else { - fill_prefetch_next (); + fill_prefetch_next (); } - } else { - fill_prefetch_next (); - } } #endif static void fill_prefetch_finish (void) { - if (did_prefetch || !using_prefetch) - return; - fill_prefetch_1 (m68k_pc_offset); + if (did_prefetch || !using_prefetch) + return; + fill_prefetch_1 (m68k_pc_offset); } static void setpc (const char *format, ...) { - va_list parms; - char buffer[1000]; + va_list parms; + char buffer[1000]; - va_start (parms, format); - _vsnprintf (buffer, 1000 - 1, format, parms); - va_end (parms); + va_start (parms, format); + _vsnprintf (buffer, 1000 - 1, format, parms); + va_end (parms); - if (using_mmu) - printf ("\tm68k_setpc_mmu (%s);\n", buffer); - else - printf ("\tm68k_setpc (%s);\n", buffer); + if (using_mmu) + printf ("\tm68k_setpc_mmu (%s);\n", buffer); + else + printf ("\tm68k_setpc (%s);\n", buffer); } static void incpc (const char *format, ...) { - va_list parms; - char buffer[1000]; + va_list parms; + char buffer[1000]; - va_start (parms, format); - _vsnprintf (buffer, 1000 - 1, format, parms); - va_end (parms); + va_start (parms, format); + _vsnprintf (buffer, 1000 - 1, format, parms); + va_end (parms); - if (using_mmu) - printf ("\tm68k_incpci (%s);\n", buffer); - else - printf ("\tm68k_incpc (%s);\n", buffer); + if (using_mmu) + printf ("\tm68k_incpci (%s);\n", buffer); + else + printf ("\tm68k_incpc (%s);\n", buffer); } static void sync_m68k_pc (void) { - if (m68k_pc_offset == 0) - return; - incpc ("%d", m68k_pc_offset); - m68k_pc_offset = 0; + if (m68k_pc_offset == 0) + return; + incpc ("%d", m68k_pc_offset); + m68k_pc_offset = 0; } static void gen_set_fault_pc (void) { - if (!using_mmu) - return; - sync_m68k_pc (); - printf ("\tregs.fault_pc = m68k_getpci ();\n"); - m68k_pc_offset = 0; + if (!using_mmu) + return; + sync_m68k_pc (); + printf ("\tregs.fault_pc = m68k_getpci ();\n"); + m68k_pc_offset = 0; } /* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0, - * the calling routine handles Apdi and Aipi modes. - * gb-- movem == 2 means the same thing but for a MOVE16 instruction */ +* the calling routine handles Apdi and Aipi modes. +* gb-- movem == 2 means the same thing but for a MOVE16 instruction */ /* fixup indicates if we want to fix up adress registers in pre decrement - * or post increment mode now (0) or later (1). A value of 2 will then be - * used to do the actual fix up. This allows to do all memory readings - * before any register is modified, and so to rerun operation without - * side effect in case a bus fault is generated by any memory access. - * XJ - 2006/11/13 */ +* or post increment mode now (0) or later (1). A value of 2 will then be +* used to do the actual fix up. This allows to do all memory readings +* before any register is modified, and so to rerun operation without +* side effect in case a bus fault is generated by any memory access. +* XJ - 2006/11/13 */ static void genamode2 (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags, int fixup, int e3fudge) { - char namea[100]; - int m68k_pc_offset_last = m68k_pc_offset; - - sprintf (namea, "%sa", name); - - start_brace (); - switch (mode) { - case Dreg: - if (movem) - abort (); - if (getv == 1) - switch (size) { - case sz_byte: + char namea[100]; + int m68k_pc_offset_last = m68k_pc_offset; + + sprintf (namea, "%sa", name); + + start_brace (); + switch (mode) { + case Dreg: + if (movem) + abort (); + if (getv == 1) + switch (size) { + case sz_byte: #ifdef USE_DUBIOUS_BIGENDIAN_OPTIMIZATION - /* This causes the target compiler to generate better code on few systems */ - printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg (regs, %s))[3];\n", name, reg); + /* This causes the target compiler to generate better code on few systems */ + printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg (regs, %s))[3];\n", name, reg); #else - printf ("\tuae_s8 %s = m68k_dreg (regs, %s);\n", name, reg); + printf ("\tuae_s8 %s = m68k_dreg (regs, %s);\n", name, reg); #endif - break; - case sz_word: + break; + case sz_word: #ifdef USE_DUBIOUS_BIGENDIAN_OPTIMIZATION - printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg (regs, %s))[1];\n", name, reg); + printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg (regs, %s))[1];\n", name, reg); #else - printf ("\tuae_s16 %s = m68k_dreg (regs, %s);\n", name, reg); + printf ("\tuae_s16 %s = m68k_dreg (regs, %s);\n", name, reg); #endif + break; + case sz_long: + printf ("\tuae_s32 %s = m68k_dreg (regs, %s);\n", name, reg); + break; + default: + abort (); + } + return; + case Areg: + if (movem) + abort (); + if (getv == 1) + switch (size) { + case sz_word: + printf ("\tuae_s16 %s = m68k_areg (regs, %s);\n", name, reg); + break; + case sz_long: + printf ("\tuae_s32 %s = m68k_areg (regs, %s);\n", name, reg); + break; + default: + abort (); + } + return; + case Aind: // (An) + printf ("\tuaecptr %sa = m68k_areg (regs, %s);\n", name, reg); break; - case sz_long: - printf ("\tuae_s32 %s = m68k_dreg (regs, %s);\n", name, reg); + case Aipi: // (An)+ + printf ("\tuaecptr %sa = m68k_areg (regs, %s);\n", name, reg); break; - default: - abort (); - } - return; - case Areg: - if (movem) - abort (); - if (getv == 1) - switch (size) { - case sz_word: - printf ("\tuae_s16 %s = m68k_areg (regs, %s);\n", name, reg); - break; - case sz_long: - printf ("\tuae_s32 %s = m68k_areg (regs, %s);\n", name, reg); - break; - default: - abort (); - } - return; - case Aind: // (An) - printf ("\tuaecptr %sa = m68k_areg (regs, %s);\n", name, reg); - break; - case Aipi: // (An)+ - printf ("\tuaecptr %sa = m68k_areg (regs, %s);\n", name, reg); - break; - case Apdi: // -(An) - printf ("\tuaecptr %sa;\n", name); - switch (size) { - case sz_byte: - if (movem) - printf ("\t%sa = m68k_areg (regs, %s);\n", name, reg); - else - printf ("\t%sa = m68k_areg (regs, %s) - areg_byteinc[%s];\n", name, reg, reg); - break; - case sz_word: - printf ("\t%sa = m68k_areg (regs, %s) - %d;\n", name, reg, movem ? 0 : 2); - break; - case sz_long: - printf ("\t%sa = m68k_areg (regs, %s) - %d;\n", name, reg, movem ? 0 : 4); - break; + case Apdi: // -(An) + printf ("\tuaecptr %sa;\n", name); + switch (size) { + case sz_byte: + if (movem) + printf ("\t%sa = m68k_areg (regs, %s);\n", name, reg); + else + printf ("\t%sa = m68k_areg (regs, %s) - areg_byteinc[%s];\n", name, reg, reg); + break; + case sz_word: + printf ("\t%sa = m68k_areg (regs, %s) - %d;\n", name, reg, movem ? 0 : 2); + break; + case sz_long: + printf ("\t%sa = m68k_areg (regs, %s) - %d;\n", name, reg, movem ? 0 : 4); + break; + default: + abort (); + } + if (!(flags & GF_APDI)) { + addcycles000 (2); + insn_n_cycles += 2; + count_cycles_ea += 2; + } + break; + case Ad16: // (d16,An) + printf ("\tuaecptr %sa = m68k_areg (regs, %s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword (flags & GF_NOREFILL)); + count_read_ea++; + break; + case Ad8r: // (d8,An,Xn) + printf ("\tuaecptr %sa;\n", name); + if (cpu_level > 1) { + if (next_cpu_level < 1) + next_cpu_level = 1; + sync_m68k_pc (); + start_brace (); + /* This would ordinarily be done in gen_nextiword, which we bypass. */ + insn_n_cycles += 4; + if (using_ce020) + printf ("\t%sa = get_disp_ea_020ce (m68k_areg (regs, %s), next_iword_020ce ());\n", name, reg); + else if (using_mmu) + printf ("\t%sa = get_disp_ea_040mmu (m68k_areg (regs, %s), next_iword_mmu ());\n", name, reg); + else + printf ("\t%sa = get_disp_ea_020 (m68k_areg (regs, %s), next_iword ());\n", name, reg); + } else { + printf ("\t%sa = get_disp_ea_000 (m68k_areg (regs, %s), %s);\n", name, reg, gen_nextiword (flags & GF_NOREFILL)); + count_read_ea++; + } + if (!(flags & GF_AD8R)) { + addcycles000 (2); + insn_n_cycles += 2; + count_cycles_ea += 2; + } + break; + case PC16: // (d16,PC,Xn) + printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset); + printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword (flags & GF_NOREFILL)); + break; + case PC8r: // (d8,PC,Xn) + printf ("\tuaecptr tmppc;\n"); + printf ("\tuaecptr %sa;\n", name); + if (cpu_level > 1) { + if (next_cpu_level < 1) + next_cpu_level = 1; + sync_m68k_pc (); + start_brace (); + /* This would ordinarily be done in gen_nextiword, which we bypass. */ + insn_n_cycles += 4; + printf ("\ttmppc = m68k_getpc ();\n"); + if (using_ce020) + printf ("\t%sa = get_disp_ea_020ce (tmppc, next_iword_020ce ());\n", name); + else if (using_mmu) + printf ("\t%sa = get_disp_ea_040mmu (tmppc, next_iword_mmu ());\n", name); + else + printf ("\t%sa = get_disp_ea_020 (tmppc, next_iword ());\n", name); + } else { + printf ("\ttmppc = m68k_getpc () + %d;\n", m68k_pc_offset); + printf ("\t%sa = get_disp_ea_000 (tmppc, %s);\n", name, gen_nextiword (flags & GF_NOREFILL)); + } + if (!(flags & GF_PC8R)) { + addcycles000 (2); + insn_n_cycles += 2; + count_cycles_ea += 2; + } + + break; + case absw: + printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword (flags & GF_NOREFILL)); + break; + case absl: + gen_nextilong ("uaecptr", namea, flags & GF_NOREFILL); + count_read_ea += 2; + break; + case imm: + if (getv != 1) + abort (); + insn_n_cycles020++; + switch (size) { + case sz_byte: + printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte (flags & GF_NOREFILL)); + count_read_ea++; + break; + case sz_word: + printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword (flags & GF_NOREFILL)); + count_read_ea++; + break; + case sz_long: + gen_nextilong ("uae_s32", name, flags & GF_NOREFILL); + count_read_ea += 2; + break; + default: + abort (); + } + return; + case imm0: + if (getv != 1) + abort (); + printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte (flags & GF_NOREFILL)); + count_read_ea++; + return; + case imm1: + if (getv != 1) + abort (); + printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword (flags & GF_NOREFILL)); + count_read_ea++; + return; + case imm2: + if (getv != 1) + abort (); + gen_nextilong ("uae_s32", name, flags & GF_NOREFILL); + count_read_ea += 2; + return; + case immi: + if (getv != 1) + abort (); + printf ("\tuae_u32 %s = %s;\n", name, reg); + return; default: - abort (); - } - if (!(flags & GF_APDI)) { - addcycles000 (2); - insn_n_cycles += 2; - count_cycles_ea += 2; - } - break; - case Ad16: // (d16,An) - printf ("\tuaecptr %sa = m68k_areg (regs, %s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword (flags & GF_NOREFILL)); - count_read_ea++; - break; - case Ad8r: // (d8,An,Xn) - printf ("\tuaecptr %sa;\n", name); - if (cpu_level > 1) { - if (next_cpu_level < 1) - next_cpu_level = 1; - sync_m68k_pc (); - start_brace (); - /* This would ordinarily be done in gen_nextiword, which we bypass. */ - insn_n_cycles += 4; - if (using_ce020) - printf ("\t%sa = get_disp_ea_020ce (m68k_areg (regs, %s), next_iword_020ce ());\n", name, reg); - else if (using_mmu) - printf ("\t%sa = get_disp_ea_040mmu (m68k_areg (regs, %s), next_iword_mmu ());\n", name, reg); - else - printf ("\t%sa = get_disp_ea_020 (m68k_areg (regs, %s), next_iword ());\n", name, reg); - } else { - printf ("\t%sa = get_disp_ea_000 (m68k_areg (regs, %s), %s);\n", name, reg, gen_nextiword (flags & GF_NOREFILL)); - count_read_ea++; - } - if (!(flags & GF_AD8R)) { - addcycles000 (2); - insn_n_cycles += 2; - count_cycles_ea += 2; - } - break; - case PC16: // (d16,PC,Xn) - printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset); - printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword (flags & GF_NOREFILL)); - break; - case PC8r: // (d8,PC,Xn) - printf ("\tuaecptr tmppc;\n"); - printf ("\tuaecptr %sa;\n", name); - if (cpu_level > 1) { - if (next_cpu_level < 1) - next_cpu_level = 1; - sync_m68k_pc (); - start_brace (); - /* This would ordinarily be done in gen_nextiword, which we bypass. */ - insn_n_cycles += 4; - printf ("\ttmppc = m68k_getpc ();\n"); - if (using_ce020) - printf ("\t%sa = get_disp_ea_020ce (tmppc, next_iword_020ce ());\n", name); - else if (using_mmu) - printf ("\t%sa = get_disp_ea_040mmu (tmppc, next_iword_mmu ());\n", name); - else - printf ("\t%sa = get_disp_ea_020 (tmppc, next_iword ());\n", name); - } else { - printf ("\ttmppc = m68k_getpc () + %d;\n", m68k_pc_offset); - printf ("\t%sa = get_disp_ea_000 (tmppc, %s);\n", name, gen_nextiword (flags & GF_NOREFILL)); - } - if (!(flags & GF_PC8R)) { - addcycles000 (2); - insn_n_cycles += 2; - count_cycles_ea += 2; + abort (); } - break; - case absw: - printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword (flags & GF_NOREFILL)); - break; - case absl: - gen_nextilong ("uaecptr", namea, flags & GF_NOREFILL); - count_read_ea += 2; - break; - case imm: - if (getv != 1) - abort (); - insn_n_cycles020++; - switch (size) { - case sz_byte: - printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte (flags & GF_NOREFILL)); - count_read_ea++; - break; - case sz_word: - printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword (flags & GF_NOREFILL)); - count_read_ea++; - break; - case sz_long: - gen_nextilong ("uae_s32", name, flags & GF_NOREFILL); - count_read_ea += 2; - break; - default: - abort (); + /* We get here for all non-reg non-immediate addressing modes to + * actually fetch the value. */ + + if ((using_prefetch || using_ce) && using_exception_3 && getv != 0 && size != sz_byte) { + printf ("\tif (%sa & 1) {\n", name); + printf ("\t\texception3 (opcode, m68k_getpc () + %d, %sa);\n", + m68k_pc_offset_last + e3fudge, name); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + need_endlabel = 1; + start_brace (); } - return; - case imm0: - if (getv != 1) - abort (); - printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte (flags & GF_NOREFILL)); - count_read_ea++; - return; - case imm1: - if (getv != 1) - abort (); - printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword (flags & GF_NOREFILL)); - count_read_ea++; - return; - case imm2: - if (getv != 1) - abort (); - gen_nextilong ("uae_s32", name, flags & GF_NOREFILL); - count_read_ea += 2; - return; - case immi: - if (getv != 1) - abort (); - printf ("\tuae_u32 %s = %s;\n", name, reg); - return; - default: - abort (); - } - - /* We get here for all non-reg non-immediate addressing modes to - * actually fetch the value. */ - - if ((using_prefetch || using_ce) && using_exception_3 && getv != 0 && size != sz_byte) { - printf ("\tif (%sa & 1) {\n", name); - printf ("\t\texception3 (opcode, m68k_getpc () + %d, %sa);\n", - m68k_pc_offset_last + e3fudge, name); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - start_brace (); - } - if (flags & GF_PREFETCH) - fill_prefetch_next (); + if (flags & GF_PREFETCH) + fill_prefetch_next (); - if (getv == 1) { - start_brace (); - if (using_ce020) { - switch (size) { - case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte_ce020 (%sa);\n", name, name); count_read++; break; - case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word_ce020 (%sa);\n", name, name); count_read++; break; - case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long_ce020 (%sa);\n", name, name); count_read += 2; break; - default: abort (); - } - } else if (using_ce) { - switch (size) { - case sz_byte: printf ("\tuae_s8 %s = get_byte_ce (%sa);\n", name, name); count_read++; break; - case sz_word: printf ("\tuae_s16 %s = get_word_ce (%sa);\n", name, name); count_read++; break; - case sz_long: printf ("\tuae_s32 %s = get_word_ce (%sa) << 16; %s |= get_word_ce (%sa + 2);\n", name, name, name, name); count_read += 2; break; - default: abort (); - } - } else if (using_mmu) { - if (flags & GF_FC) { - switch (size) { - case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = sfc_get_byte (%sa);\n", name, name); break; - case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = sfc_get_word (%sa);\n", name, name); break; - case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = sfc_get_long (%sa);\n", name, name); break; - default: abort (); - } - } else { - switch (size) { - case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte_mmu (%sa);\n", name, name); break; - case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word_mmu (%sa);\n", name, name); break; - case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long_mmu (%sa);\n", name, name); break; - default: abort (); + if (getv == 1) { + start_brace (); + if (using_ce020) { + switch (size) { + case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte_ce020 (%sa);\n", name, name); count_read++; break; + case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word_ce020 (%sa);\n", name, name); count_read++; break; + case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long_ce020 (%sa);\n", name, name); count_read += 2; break; + default: abort (); + } + } else if (using_ce) { + switch (size) { + case sz_byte: printf ("\tuae_s8 %s = get_byte_ce (%sa);\n", name, name); count_read++; break; + case sz_word: printf ("\tuae_s16 %s = get_word_ce (%sa);\n", name, name); count_read++; break; + case sz_long: printf ("\tuae_s32 %s = get_word_ce (%sa) << 16; %s |= get_word_ce (%sa + 2);\n", name, name, name, name); count_read += 2; break; + default: abort (); + } + } else if (using_mmu) { + if (flags & GF_FC) { + switch (size) { + case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = sfc_get_byte (%sa);\n", name, name); break; + case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = sfc_get_word (%sa);\n", name, name); break; + case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = sfc_get_long (%sa);\n", name, name); break; + default: abort (); + } + } else { + switch (size) { + case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte_mmu (%sa);\n", name, name); break; + case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word_mmu (%sa);\n", name, name); break; + case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long_mmu (%sa);\n", name, name); break; + default: abort (); + } + } + } else { + switch (size) { + case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte (%sa);\n", name, name); count_read++; break; + case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word (%sa);\n", name, name); count_read++; break; + case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long (%sa);\n", name, name); count_read += 2; break; + default: abort (); + } } - } - } else { - switch (size) { - case sz_byte: insn_n_cycles += 4; printf ("\tuae_s8 %s = get_byte (%sa);\n", name, name); count_read++; break; - case sz_word: insn_n_cycles += 4; printf ("\tuae_s16 %s = get_word (%sa);\n", name, name); count_read++; break; - case sz_long: insn_n_cycles += 8; printf ("\tuae_s32 %s = get_long (%sa);\n", name, name); count_read += 2; break; - default: abort (); - } } - } - /* We now might have to fix up the register for pre-dec or post-inc - * addressing modes. */ - if (!movem) - switch (mode) { - case Aipi: - if (fixup == 1) { - printf ("\tmmufixup[%d].reg = %s;\n", fixupcnt, reg); - printf ("\tmmufixup[%d].value = m68k_areg (regs, %s);\n", fixupcnt, reg); - } - switch (size) { - case sz_byte: - printf ("\tm68k_areg (regs, %s) += areg_byteinc[%s];\n", reg, reg); - break; - case sz_word: - printf ("\tm68k_areg (regs, %s) += 2;\n", reg); - break; - case sz_long: - printf ("\tm68k_areg (regs, %s) += 4;\n", reg); - break; - default: - abort (); - } - break; - case Apdi: - if (fixup == 1) { - printf ("\tmmufixup[%d].reg = %s;\n", fixupcnt, reg); - printf ("\tmmufixup[%d].value = m68k_areg (regs, %s);\n", fixupcnt, reg); - } - printf ("\tm68k_areg (regs, %s) = %sa;\n", reg, name); - break; - default: - break; + /* We now might have to fix up the register for pre-dec or post-inc + * addressing modes. */ + if (!movem) + switch (mode) { + case Aipi: + if (fixup == 1) { + printf ("\tmmufixup[%d].reg = %s;\n", fixupcnt, reg); + printf ("\tmmufixup[%d].value = m68k_areg (regs, %s);\n", fixupcnt, reg); + } + switch (size) { + case sz_byte: + printf ("\tm68k_areg (regs, %s) += areg_byteinc[%s];\n", reg, reg); + break; + case sz_word: + printf ("\tm68k_areg (regs, %s) += 2;\n", reg); + break; + case sz_long: + printf ("\tm68k_areg (regs, %s) += 4;\n", reg); + break; + default: + abort (); + } + break; + case Apdi: + if (fixup == 1) { + printf ("\tmmufixup[%d].reg = %s;\n", fixupcnt, reg); + printf ("\tmmufixup[%d].value = m68k_areg (regs, %s);\n", fixupcnt, reg); + } + printf ("\tm68k_areg (regs, %s) = %sa;\n", reg, name); + break; + default: + break; } } static void genamode_fixup (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags, int fixup) { - if (fixup != 2) { - genamode2 (mode, reg, size, name, getv, movem, flags, fixup, 0); - } else { - if (!movem) { - switch (mode) - { - case Aipi: - case Apdi: - printf ("\tmmufixup[0].reg = -1;\n", fixupcnt); - break; - } + if (fixup != 2) { + genamode2 (mode, reg, size, name, getv, movem, flags, fixup, 0); + } else { + if (!movem) { + switch (mode) + { + case Aipi: + case Apdi: + printf ("\tmmufixup[0].reg = -1;\n", fixupcnt); + break; + } + } } - } } static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags) { - genamode2 (mode, reg, size, name, getv, movem, flags, 0, 0); + genamode2 (mode, reg, size, name, getv, movem, flags, 0, 0); } static void genamode_pre (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags) { - genamode_fixup (mode, reg, size, name, getv, movem, flags, using_mmu ? 1 : 0); + genamode_fixup (mode, reg, size, name, getv, movem, flags, using_mmu ? 1 : 0); } static void genamode_post (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags) { - if (using_mmu) - genamode_fixup (mode, reg, size, name, getv, movem, flags, 2); + if (using_mmu) + genamode_fixup (mode, reg, size, name, getv, movem, flags, 2); } static void genamode_e3 (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem, int flags, int e3fudge) { - genamode2 (mode, reg, size, name, getv, movem, flags, 0, e3fudge); + genamode2 (mode, reg, size, name, getv, movem, flags, 0, e3fudge); } static void genastore_2 (char *from, amodes mode, char *reg, wordsizes size, char *to, int store_dir, int flags) { - switch (mode) { - case Dreg: - switch (size) { - case sz_byte: - printf ("\tm68k_dreg (regs, %s) = (m68k_dreg (regs, %s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from); - break; - case sz_word: - printf ("\tm68k_dreg (regs, %s) = (m68k_dreg (regs, %s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from); - break; - case sz_long: - printf ("\tm68k_dreg (regs, %s) = (%s);\n", reg, from); - break; - default: - abort (); - } - break; - case Areg: - switch (size) { - case sz_word: - printf ("\tm68k_areg (regs, %s) = (uae_s32)(uae_s16)(%s);\n", reg, from); - break; - case sz_long: - printf ("\tm68k_areg (regs, %s) = (%s);\n", reg, from); - break; - default: - abort (); - } - break; - case Aind: - case Aipi: - case Apdi: - case Ad16: - case Ad8r: - case absw: - case absl: - case PC16: - case PC8r: - gen_set_fault_pc (); - if (using_ce020) { - switch (size) { - case sz_byte: - printf ("\tput_byte_ce020 (%sa,%s);\n", to, from); - count_write++; - break; - case sz_word: - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - printf ("\tput_word_ce020 (%sa,%s);\n", to, from); - count_write++; - break; - case sz_long: - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - printf ("\tput_long_ce020 (%sa, %s);\n", to, from); - count_write += 2; - break; - default: - abort (); - } - } else if (using_ce) { - switch (size) { - case sz_byte: - printf ("\tput_byte_ce (%sa,%s);\n", to, from); - count_write++; - break; - case sz_word: - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - printf ("\tput_word_ce (%sa,%s);\n", to, from); - count_write++; - break; - case sz_long: - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - if (store_dir) - printf ("\tput_word_ce (%sa + 2, %s); put_word_ce (%sa, %s >> 16);\n", to, from, to, from); - else - printf ("\tput_word_ce (%sa, %s >> 16); put_word_ce (%sa + 2, %s);\n", to, from, to, from); - count_write += 2; + switch (mode) { + case Dreg: + switch (size) { + case sz_byte: + printf ("\tm68k_dreg (regs, %s) = (m68k_dreg (regs, %s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from); + break; + case sz_word: + printf ("\tm68k_dreg (regs, %s) = (m68k_dreg (regs, %s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from); + break; + case sz_long: + printf ("\tm68k_dreg (regs, %s) = (%s);\n", reg, from); + break; + default: + abort (); + } break; - default: - abort (); - } - } else if (using_mmu) { - switch (size) { - case sz_byte: - insn_n_cycles += 4; - if (flags & GF_FC) - printf ("\tdfc_put_byte (%sa,%s);\n", to, from); - else - printf ("\tput_byte_mmu (%sa,%s);\n", to, from); + case Areg: + switch (size) { + case sz_word: + printf ("\tm68k_areg (regs, %s) = (uae_s32)(uae_s16)(%s);\n", reg, from); + break; + case sz_long: + printf ("\tm68k_areg (regs, %s) = (%s);\n", reg, from); + break; + default: + abort (); + } break; - case sz_word: - insn_n_cycles += 4; - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - if (flags & GF_FC) - printf ("\tdfc_put_word (%sa,%s);\n", to, from); - else - printf ("\tput_word_mmu (%sa,%s);\n", to, from); - break; - case sz_long: - insn_n_cycles += 8; - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - if (flags & GF_FC) - printf ("\tdfc_put_long (%sa,%s);\n", to, from); - else - printf ("\tput_long_mmu (%sa,%s);\n", to, from); + case Aind: + case Aipi: + case Apdi: + case Ad16: + case Ad8r: + case absw: + case absl: + case PC16: + case PC8r: + gen_set_fault_pc (); + if (using_ce020) { + switch (size) { + case sz_byte: + printf ("\tput_byte_ce020 (%sa,%s);\n", to, from); + count_write++; + break; + case sz_word: + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + printf ("\tput_word_ce020 (%sa,%s);\n", to, from); + count_write++; + break; + case sz_long: + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + printf ("\tput_long_ce020 (%sa, %s);\n", to, from); + count_write += 2; + break; + default: + abort (); + } + } else if (using_ce) { + switch (size) { + case sz_byte: + printf ("\tput_byte_ce (%sa,%s);\n", to, from); + count_write++; + break; + case sz_word: + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + printf ("\tput_word_ce (%sa,%s);\n", to, from); + count_write++; + break; + case sz_long: + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + if (store_dir) + printf ("\tput_word_ce (%sa + 2, %s); put_word_ce (%sa, %s >> 16);\n", to, from, to, from); + else + printf ("\tput_word_ce (%sa, %s >> 16); put_word_ce (%sa + 2, %s);\n", to, from, to, from); + count_write += 2; + break; + default: + abort (); + } + } else if (using_mmu) { + switch (size) { + case sz_byte: + insn_n_cycles += 4; + if (flags & GF_FC) + printf ("\tdfc_put_byte (%sa,%s);\n", to, from); + else + printf ("\tput_byte_mmu (%sa,%s);\n", to, from); + break; + case sz_word: + insn_n_cycles += 4; + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + if (flags & GF_FC) + printf ("\tdfc_put_word (%sa,%s);\n", to, from); + else + printf ("\tput_word_mmu (%sa,%s);\n", to, from); + break; + case sz_long: + insn_n_cycles += 8; + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + if (flags & GF_FC) + printf ("\tdfc_put_long (%sa,%s);\n", to, from); + else + printf ("\tput_long_mmu (%sa,%s);\n", to, from); + break; + default: + abort (); + } + } else { + switch (size) { + case sz_byte: + insn_n_cycles += 4; + printf ("\tput_byte (%sa,%s);\n", to, from); + count_write++; + break; + case sz_word: + insn_n_cycles += 4; + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + printf ("\tput_word (%sa,%s);\n", to, from); + count_write++; + break; + case sz_long: + insn_n_cycles += 8; + if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) + abort (); + printf ("\tput_long (%sa,%s);\n", to, from); + count_write += 2; + break; + default: + abort (); + } + } break; - default: + case imm: + case imm0: + case imm1: + case imm2: + case immi: abort (); - } - } else { - switch (size) { - case sz_byte: - insn_n_cycles += 4; - printf ("\tput_byte (%sa,%s);\n", to, from); - count_write++; - break; - case sz_word: - insn_n_cycles += 4; - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - printf ("\tput_word (%sa,%s);\n", to, from); - count_write++; - break; - case sz_long: - insn_n_cycles += 8; - if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) - abort (); - printf ("\tput_long (%sa,%s);\n", to, from); - count_write += 2; break; - default: + default: abort (); - } } - break; - case imm: - case imm0: - case imm1: - case imm2: - case immi: - abort (); - break; - default: - abort (); - } } static void genastore (char *from, amodes mode, char *reg, wordsizes size, char *to) { - genastore_2 (from, mode, reg, size, to, 0, 0); + genastore_2 (from, mode, reg, size, to, 0, 0); } static void genastore_rev (char *from, amodes mode, char *reg, wordsizes size, char *to) { - genastore_2 (from, mode, reg, size, to, 1, 0); + genastore_2 (from, mode, reg, size, to, 1, 0); } static void genastore_fc (char *from, amodes mode, char *reg, wordsizes size, char *to) { - genastore_2 (from, mode, reg, size, to, 1, GF_FC); + genastore_2 (from, mode, reg, size, to, 1, GF_FC); } static void genmovemel (uae_u16 opcode) { - char getcode[100]; - int size = table68k[opcode].size == sz_long ? 4 : 2; + char getcode[100]; + int size = table68k[opcode].size == sz_long ? 4 : 2; - if (using_mmu) { - if (table68k[opcode].size == sz_long) { - strcpy (getcode, "get_long_mmu (srca)"); + if (using_mmu) { + if (table68k[opcode].size == sz_long) { + strcpy (getcode, "get_long_mmu (srca)"); + } else { + strcpy (getcode, "(uae_s32)(uae_s16)get_word_mmu (srca)"); + } } else { - strcpy (getcode, "(uae_s32)(uae_s16)get_word_mmu (srca)"); + if (table68k[opcode].size == sz_long) { + strcpy (getcode, "get_long (srca)"); + } else { + strcpy (getcode, "(uae_s32)(uae_s16)get_word (srca)"); + } } - } else { - if (table68k[opcode].size == sz_long) { - strcpy (getcode, "get_long (srca)"); - } else { - strcpy (getcode, "(uae_s32)(uae_s16)get_word (srca)"); + count_read += table68k[opcode].size == sz_long ? 2 : 1; + printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); + printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); + genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, 0); + start_brace (); + printf ("\twhile (dmask) { m68k_dreg (regs, movem_index1[dmask]) = %s; srca += %d; dmask = movem_next[dmask]; }\n", + getcode, size); + printf ("\twhile (amask) { m68k_areg (regs, movem_index1[amask]) = %s; srca += %d; amask = movem_next[amask]; }\n", + getcode, size); + + if (table68k[opcode].dmode == Aipi) { + printf ("\tm68k_areg (regs, dstreg) = srca;\n"); + count_read++; } - } - count_read += table68k[opcode].size == sz_long ? 2 : 1; - printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); - printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); - genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, 0); - start_brace (); - printf ("\twhile (dmask) { m68k_dreg (regs, movem_index1[dmask]) = %s; srca += %d; dmask = movem_next[dmask]; }\n", - getcode, size); - printf ("\twhile (amask) { m68k_areg (regs, movem_index1[amask]) = %s; srca += %d; amask = movem_next[amask]; }\n", - getcode, size); - - if (table68k[opcode].dmode == Aipi) { - printf ("\tm68k_areg (regs, dstreg) = srca;\n"); - count_read++; - } - fill_prefetch_next (); - count_ncycles++; + fill_prefetch_next (); + count_ncycles++; } static void genmovemel_ce (uae_u16 opcode) { - int size = table68k[opcode].size == sz_long ? 4 : 2; - printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); - printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); - printf ("\tuae_u32 v;\n"); - genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, GF_AA); - if (table68k[opcode].dmode == Ad8r || table68k[opcode].dmode == PC8r) - addcycles000 (2); - start_brace (); - if (table68k[opcode].size == sz_long) { - printf ("\twhile (dmask) { v = get_word_ce(srca) << 16; v |= get_word_ce(srca + 2); m68k_dreg (regs, movem_index1[dmask]) = v; srca += %d; dmask = movem_next[dmask]; }\n", - size); - printf ("\twhile (amask) { v = get_word_ce(srca) << 16; v |= get_word_ce(srca + 2); m68k_areg (regs, movem_index1[amask]) = v; srca += %d; amask = movem_next[amask]; }\n", - size); - } else { - printf ("\twhile (dmask) { m68k_dreg (regs, movem_index1[dmask]) = (uae_s32)(uae_s16)get_word_ce(srca); srca += %d; dmask = movem_next[dmask]; }\n", - size); - printf ("\twhile (amask) { m68k_areg (regs, movem_index1[amask]) = (uae_s32)(uae_s16)get_word_ce(srca); srca += %d; amask = movem_next[amask]; }\n", - size); - } - printf ("\tget_word_ce (srca);\n"); // and final extra word fetch that goes nowhere.. - count_read++; - if (table68k[opcode].dmode == Aipi) - printf ("\tm68k_areg (regs, dstreg) = srca;\n"); - fill_prefetch_next (); - count_ncycles++; + int size = table68k[opcode].size == sz_long ? 4 : 2; + printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); + printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); + printf ("\tuae_u32 v;\n"); + genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, GF_AA); + if (table68k[opcode].dmode == Ad8r || table68k[opcode].dmode == PC8r) + addcycles000 (2); + start_brace (); + if (table68k[opcode].size == sz_long) { + printf ("\twhile (dmask) { v = get_word_ce(srca) << 16; v |= get_word_ce(srca + 2); m68k_dreg (regs, movem_index1[dmask]) = v; srca += %d; dmask = movem_next[dmask]; }\n", + size); + printf ("\twhile (amask) { v = get_word_ce(srca) << 16; v |= get_word_ce(srca + 2); m68k_areg (regs, movem_index1[amask]) = v; srca += %d; amask = movem_next[amask]; }\n", + size); + } else { + printf ("\twhile (dmask) { m68k_dreg (regs, movem_index1[dmask]) = (uae_s32)(uae_s16)get_word_ce(srca); srca += %d; dmask = movem_next[dmask]; }\n", + size); + printf ("\twhile (amask) { m68k_areg (regs, movem_index1[amask]) = (uae_s32)(uae_s16)get_word_ce(srca); srca += %d; amask = movem_next[amask]; }\n", + size); + } + printf ("\tget_word_ce (srca);\n"); // and final extra word fetch that goes nowhere.. + count_read++; + if (table68k[opcode].dmode == Aipi) + printf ("\tm68k_areg (regs, dstreg) = srca;\n"); + fill_prefetch_next (); + count_ncycles++; } static void genmovemle (uae_u16 opcode) { - char *putcode; - int size = table68k[opcode].size == sz_long ? 4 : 2; + char *putcode; + int size = table68k[opcode].size == sz_long ? 4 : 2; - if (using_mmu) { - if (table68k[opcode].size == sz_long) { - putcode = "put_long_mmu (srca"; + if (using_mmu) { + if (table68k[opcode].size == sz_long) { + putcode = "put_long_mmu (srca"; + } else { + putcode = "put_word_mmu (srca"; + } } else { - putcode = "put_word_mmu (srca"; + if (table68k[opcode].size == sz_long) { + putcode = "put_long (srca"; + } else { + putcode = "put_word (srca"; + } } - } else { - if (table68k[opcode].size == sz_long) { - putcode = "put_long (srca"; + count_write += table68k[opcode].size == sz_long ? 2 : 1; + + printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); + genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, 0); + start_brace (); + if (table68k[opcode].dmode == Apdi) { + printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); + if (!using_mmu) + printf ("\tint type = get_cpu_model() >= 68020;\n"); + printf ("\twhile (amask) {\n"); + printf ("\t\tsrca -= %d;\n", size); + if (!using_mmu) + printf ("\t\tif (type) m68k_areg (regs, dstreg) = srca;\n"); + printf ("\t\t%s, m68k_areg (regs, movem_index2[amask]));\n", putcode); + printf ("\t\tamask = movem_next[amask];\n"); + printf ("\t}\n"); + printf ("\twhile (dmask) { srca -= %d; %s, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", + size, putcode); + printf ("\tm68k_areg (regs, dstreg) = srca;\n"); } else { - putcode = "put_word (srca"; + printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); + printf ("\twhile (dmask) { %s, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", + putcode, size); + printf ("\twhile (amask) { %s, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", + putcode, size); } - } - count_write += table68k[opcode].size == sz_long ? 2 : 1; - - printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); - genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, 0); - start_brace (); - if (table68k[opcode].dmode == Apdi) { - printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); - if (!using_mmu) - printf ("\tint type = get_cpu_model() >= 68020;\n"); - printf ("\twhile (amask) {\n"); - printf ("\t\tsrca -= %d;\n", size); - if (!using_mmu) - printf ("\t\tif (type) m68k_areg (regs, dstreg) = srca;\n"); - printf ("\t\t%s, m68k_areg (regs, movem_index2[amask]));\n", putcode); - printf ("\t\tamask = movem_next[amask];\n"); - printf ("\t}\n"); - printf ("\twhile (dmask) { srca -= %d; %s, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", - size, putcode); - printf ("\tm68k_areg (regs, dstreg) = srca;\n"); - } else { - printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); - printf ("\twhile (dmask) { %s, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", - putcode, size); - printf ("\twhile (amask) { %s, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", - putcode, size); - } - if (using_prefetch) { - sync_m68k_pc (); - fill_prefetch_next (); - } - count_ncycles++; + if (using_prefetch) { + sync_m68k_pc (); + fill_prefetch_next (); + } + count_ncycles++; } static void genmovemle_ce (uae_u16 opcode) { - int size = table68k[opcode].size == sz_long ? 4 : 2; - printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); - genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, GF_AA); - - if (table68k[opcode].dmode == Ad8r || table68k[opcode].dmode == PC8r) { - addcycles000 (2); - } - start_brace (); - if (table68k[opcode].size == sz_long) { - if (table68k[opcode].dmode == Apdi) { - printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); - printf ("\twhile (amask) { srca -= %d; put_word_ce (srca, m68k_areg (regs, movem_index2[amask]) >> 16); put_word_ce (srca + 2, m68k_areg (regs, movem_index2[amask])); amask = movem_next[amask]; }\n", - size); - printf ("\twhile (dmask) { srca -= %d; put_word_ce (srca, m68k_dreg (regs, movem_index2[dmask]) >> 16); put_word_ce (srca + 2, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", - size); - printf ("\tm68k_areg (regs, dstreg) = srca;\n"); - } else { - printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); - printf ("\twhile (dmask) { put_word_ce (srca, m68k_dreg (regs, movem_index1[dmask]) >> 16); put_word_ce (srca + 2, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", - size); - printf ("\twhile (amask) { put_word_ce (srca, m68k_areg (regs, movem_index1[amask]) >> 16); put_word_ce (srca + 2, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", - size); + int size = table68k[opcode].size == sz_long ? 4 : 2; + printf ("\tuae_u16 mask = %s;\n", gen_nextiword (0)); + genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1, GF_AA); + + if (table68k[opcode].dmode == Ad8r || table68k[opcode].dmode == PC8r) { + addcycles000 (2); } - } else { - if (table68k[opcode].dmode == Apdi) { - printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); - printf ("\twhile (amask) { srca -= %d; put_word_ce (srca, m68k_areg (regs, movem_index2[amask])); amask = movem_next[amask]; }\n", - size); - printf ("\twhile (dmask) { srca -= %d; put_word_ce (srca, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", - size); - printf ("\tm68k_areg (regs, dstreg) = srca;\n"); + start_brace (); + if (table68k[opcode].size == sz_long) { + if (table68k[opcode].dmode == Apdi) { + printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); + printf ("\twhile (amask) { srca -= %d; put_word_ce (srca, m68k_areg (regs, movem_index2[amask]) >> 16); put_word_ce (srca + 2, m68k_areg (regs, movem_index2[amask])); amask = movem_next[amask]; }\n", + size); + printf ("\twhile (dmask) { srca -= %d; put_word_ce (srca, m68k_dreg (regs, movem_index2[dmask]) >> 16); put_word_ce (srca + 2, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", + size); + printf ("\tm68k_areg (regs, dstreg) = srca;\n"); + } else { + printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); + printf ("\twhile (dmask) { put_word_ce (srca, m68k_dreg (regs, movem_index1[dmask]) >> 16); put_word_ce (srca + 2, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", + size); + printf ("\twhile (amask) { put_word_ce (srca, m68k_areg (regs, movem_index1[amask]) >> 16); put_word_ce (srca + 2, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", + size); + } } else { - printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); - printf ("\twhile (dmask) { put_word_ce (srca, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", - size); - printf ("\twhile (amask) { put_word_ce (srca, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", - size); + if (table68k[opcode].dmode == Apdi) { + printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); + printf ("\twhile (amask) { srca -= %d; put_word_ce (srca, m68k_areg (regs, movem_index2[amask])); amask = movem_next[amask]; }\n", + size); + printf ("\twhile (dmask) { srca -= %d; put_word_ce (srca, m68k_dreg (regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", + size); + printf ("\tm68k_areg (regs, dstreg) = srca;\n"); + } else { + printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); + printf ("\twhile (dmask) { put_word_ce (srca, m68k_dreg (regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", + size); + printf ("\twhile (amask) { put_word_ce (srca, m68k_areg (regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", + size); + } } - } - fill_prefetch_next (); - count_ncycles++; + fill_prefetch_next (); + count_ncycles++; } static void duplicate_carry (int n) { - int i; - for (i = 0; i <= n; i++) - printf ("\t"); - printf ("COPY_CARRY ();\n"); + int i; + for (i = 0; i <= n; i++) + printf ("\t"); + printf ("COPY_CARRY ();\n"); } typedef enum { - flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_z, flag_zn, - flag_av, flag_sv + flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_z, flag_zn, + flag_av, flag_sv } flagtypes; static void genflags_normal (flagtypes type, wordsizes size, char *value, char *src, char *dst) { - char vstr[100], sstr[100], dstr[100]; - char usstr[100], udstr[100]; - char unsstr[100], undstr[100]; - - switch (size) { - case sz_byte: - strcpy (vstr, "((uae_s8)("); - strcpy (usstr, "((uae_u8)("); - break; - case sz_word: - strcpy (vstr, "((uae_s16)("); - strcpy (usstr, "((uae_u16)("); - break; - case sz_long: - strcpy (vstr, "((uae_s32)("); - strcpy (usstr, "((uae_u32)("); - break; - default: - abort (); - } - strcpy (unsstr, usstr); - - strcpy (sstr, vstr); - strcpy (dstr, vstr); - strcat (vstr, value); - strcat (vstr, "))"); - strcat (dstr, dst); - strcat (dstr, "))"); - strcat (sstr, src); - strcat (sstr, "))"); - - strcpy (udstr, usstr); - strcat (udstr, dst); - strcat (udstr, "))"); - strcat (usstr, src); - strcat (usstr, "))"); - - strcpy (undstr, unsstr); - strcat (unsstr, "-"); - strcat (undstr, "~"); - strcat (undstr, dst); - strcat (undstr, "))"); - strcat (unsstr, src); - strcat (unsstr, "))"); - - switch (type) { - case flag_logical_noclobber: - case flag_logical: - case flag_z: - case flag_zn: - case flag_av: - case flag_sv: - case flag_addx: - case flag_subx: - break; - - case flag_add: - start_brace (); - printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr); - break; - case flag_sub: - case flag_cmp: - start_brace (); - printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr); - break; - } - - switch (type) { - case flag_logical_noclobber: - case flag_logical: - case flag_zn: - break; - - case flag_add: - case flag_sub: - case flag_addx: - case flag_subx: - case flag_cmp: - case flag_av: - case flag_sv: - start_brace (); - printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr); - printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr); - printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr); - break; - } - - switch (type) { - case flag_logical: - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tSET_ZFLG (%s == 0);\n", vstr); - printf ("\tSET_NFLG (%s < 0);\n", vstr); - break; - case flag_logical_noclobber: - printf ("\tSET_ZFLG (%s == 0);\n", vstr); - printf ("\tSET_NFLG (%s < 0);\n", vstr); - break; - case flag_av: - printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); - break; - case flag_sv: - printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); - break; - case flag_z: - printf ("\tSET_ZFLG (GET_ZFLG () & (%s == 0));\n", vstr); - break; - case flag_zn: - printf ("\tSET_ZFLG (GET_ZFLG () & (%s == 0));\n", vstr); - printf ("\tSET_NFLG (%s < 0);\n", vstr); - break; - case flag_add: - printf ("\tSET_ZFLG (%s == 0);\n", vstr); - printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); - printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr); - duplicate_carry (0); - printf ("\tSET_NFLG (flgn != 0);\n"); - break; - case flag_sub: - printf ("\tSET_ZFLG (%s == 0);\n", vstr); - printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); - printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); - duplicate_carry (0); - printf ("\tSET_NFLG (flgn != 0);\n"); - break; - case flag_addx: - printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */ - printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */ - duplicate_carry (0); - break; - case flag_subx: - printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */ - printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */ - duplicate_carry (0); - break; - case flag_cmp: - printf ("\tSET_ZFLG (%s == 0);\n", vstr); - printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n"); - printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); - printf ("\tSET_NFLG (flgn != 0);\n"); - break; - } -} - -static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst) -{ - /* Temporarily deleted 68k/ARM flag optimizations. I'd prefer to have - them in the appropriate m68k.h files and use just one copy of this - code here. The API can be changed if necessary. */ - if (optimized_flags) { - switch (type) { - case flag_add: - case flag_sub: - start_brace (); - printf ("\tuae_u32 %s;\n", value); - break; - - default: - break; - } - - /* At least some of those casts are fairly important! */ - switch (type) { - case flag_logical_noclobber: - printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n"); - if (strcmp (value, "0") == 0) { - printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n"); - } else { - switch (size) { - case sz_byte: printf ("\toptflag_testb (regs, (uae_s8)(%s));\n", value); break; - case sz_word: printf ("\toptflag_testw (regs, (uae_s16)(%s));\n", value); break; - case sz_long: printf ("\toptflag_testl (regs, (uae_s32)(%s));\n", value); break; - } - printf ("\tIOR_CZNV (oldcznv);\n"); - } - printf ("\t}\n"); - return; - case flag_logical: - if (strcmp (value, "0") == 0) { - printf ("\tSET_CZNV (FLAGVAL_Z);\n"); - } else { - switch (size) { - case sz_byte: printf ("\toptflag_testb (regs, (uae_s8)(%s));\n", value); break; - case sz_word: printf ("\toptflag_testw (regs, (uae_s16)(%s));\n", value); break; - case sz_long: printf ("\toptflag_testl (regs, (uae_s32)(%s));\n", value); break; - } - } - return; + char vstr[100], sstr[100], dstr[100]; + char usstr[100], udstr[100]; + char unsstr[100], undstr[100]; - case flag_add: switch (size) { - case sz_byte: printf ("\toptflag_addb (regs, %s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; - case sz_word: printf ("\toptflag_addw (regs, %s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; - case sz_long: printf ("\toptflag_addl (regs, %s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; - } - return; - - case flag_sub: - switch (size) { - case sz_byte: printf ("\toptflag_subb (regs, %s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; - case sz_word: printf ("\toptflag_subw (regs, %s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; - case sz_long: printf ("\toptflag_subl (regs, %s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; - } - return; + case sz_byte: + strcpy (vstr, "((uae_s8)("); + strcpy (usstr, "((uae_u8)("); + break; + case sz_word: + strcpy (vstr, "((uae_s16)("); + strcpy (usstr, "((uae_u16)("); + break; + case sz_long: + strcpy (vstr, "((uae_s32)("); + strcpy (usstr, "((uae_u32)("); + break; + default: + abort (); + } + strcpy (unsstr, usstr); + + strcpy (sstr, vstr); + strcpy (dstr, vstr); + strcat (vstr, value); + strcat (vstr, "))"); + strcat (dstr, dst); + strcat (dstr, "))"); + strcat (sstr, src); + strcat (sstr, "))"); + + strcpy (udstr, usstr); + strcat (udstr, dst); + strcat (udstr, "))"); + strcat (usstr, src); + strcat (usstr, "))"); + + strcpy (undstr, unsstr); + strcat (unsstr, "-"); + strcat (undstr, "~"); + strcat (undstr, dst); + strcat (undstr, "))"); + strcat (unsstr, src); + strcat (unsstr, "))"); + + switch (type) { + case flag_logical_noclobber: + case flag_logical: + case flag_z: + case flag_zn: + case flag_av: + case flag_sv: + case flag_addx: + case flag_subx: + break; - case flag_cmp: - switch (size) { - case sz_byte: printf ("\toptflag_cmpb (regs, (uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break; - case sz_word: printf ("\toptflag_cmpw (regs, (uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break; - case sz_long: printf ("\toptflag_cmpl (regs, (uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break; + case flag_add: + start_brace (); + printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr); + break; + case flag_sub: + case flag_cmp: + start_brace (); + printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr); + break; + } + + switch (type) { + case flag_logical_noclobber: + case flag_logical: + case flag_zn: + break; + + case flag_add: + case flag_sub: + case flag_addx: + case flag_subx: + case flag_cmp: + case flag_av: + case flag_sv: + start_brace (); + printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr); + printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr); + printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr); + break; + } + + switch (type) { + case flag_logical: + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tSET_ZFLG (%s == 0);\n", vstr); + printf ("\tSET_NFLG (%s < 0);\n", vstr); + break; + case flag_logical_noclobber: + printf ("\tSET_ZFLG (%s == 0);\n", vstr); + printf ("\tSET_NFLG (%s < 0);\n", vstr); + break; + case flag_av: + printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); + break; + case flag_sv: + printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); + break; + case flag_z: + printf ("\tSET_ZFLG (GET_ZFLG () & (%s == 0));\n", vstr); + break; + case flag_zn: + printf ("\tSET_ZFLG (GET_ZFLG () & (%s == 0));\n", vstr); + printf ("\tSET_NFLG (%s < 0);\n", vstr); + break; + case flag_add: + printf ("\tSET_ZFLG (%s == 0);\n", vstr); + printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); + printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr); + duplicate_carry (0); + printf ("\tSET_NFLG (flgn != 0);\n"); + break; + case flag_sub: + printf ("\tSET_ZFLG (%s == 0);\n", vstr); + printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); + printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); + duplicate_carry (0); + printf ("\tSET_NFLG (flgn != 0);\n"); + break; + case flag_addx: + printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */ + printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */ + duplicate_carry (0); + break; + case flag_subx: + printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */ + printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */ + duplicate_carry (0); + break; + case flag_cmp: + printf ("\tSET_ZFLG (%s == 0);\n", vstr); + printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n"); + printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); + printf ("\tSET_NFLG (flgn != 0);\n"); + break; } - return; +} - default: - break; - } - } +static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst) +{ + /* Temporarily deleted 68k/ARM flag optimizations. I'd prefer to have + them in the appropriate m68k.h files and use just one copy of this + code here. The API can be changed if necessary. */ + if (optimized_flags) { + switch (type) { + case flag_add: + case flag_sub: + start_brace (); + printf ("\tuae_u32 %s;\n", value); + break; + + default: + break; + } + + /* At least some of those casts are fairly important! */ + switch (type) { + case flag_logical_noclobber: + printf ("\t{uae_u32 oldcznv = GET_CZNV & ~(FLAGVAL_Z | FLAGVAL_N);\n"); + if (strcmp (value, "0") == 0) { + printf ("\tSET_CZNV (olcznv | FLAGVAL_Z);\n"); + } else { + switch (size) { + case sz_byte: printf ("\toptflag_testb (regs, (uae_s8)(%s));\n", value); break; + case sz_word: printf ("\toptflag_testw (regs, (uae_s16)(%s));\n", value); break; + case sz_long: printf ("\toptflag_testl (regs, (uae_s32)(%s));\n", value); break; + } + printf ("\tIOR_CZNV (oldcznv);\n"); + } + printf ("\t}\n"); + return; + case flag_logical: + if (strcmp (value, "0") == 0) { + printf ("\tSET_CZNV (FLAGVAL_Z);\n"); + } else { + switch (size) { + case sz_byte: printf ("\toptflag_testb (regs, (uae_s8)(%s));\n", value); break; + case sz_word: printf ("\toptflag_testw (regs, (uae_s16)(%s));\n", value); break; + case sz_long: printf ("\toptflag_testl (regs, (uae_s32)(%s));\n", value); break; + } + } + return; + + case flag_add: + switch (size) { + case sz_byte: printf ("\toptflag_addb (regs, %s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; + case sz_word: printf ("\toptflag_addw (regs, %s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; + case sz_long: printf ("\toptflag_addl (regs, %s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; + } + return; + + case flag_sub: + switch (size) { + case sz_byte: printf ("\toptflag_subb (regs, %s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; + case sz_word: printf ("\toptflag_subw (regs, %s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; + case sz_long: printf ("\toptflag_subl (regs, %s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; + } + return; + + case flag_cmp: + switch (size) { + case sz_byte: printf ("\toptflag_cmpb (regs, (uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break; + case sz_word: printf ("\toptflag_cmpw (regs, (uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break; + case sz_long: printf ("\toptflag_cmpl (regs, (uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break; + } + return; + + default: + break; + } + } - genflags_normal (type, size, value, src, dst); + genflags_normal (type, size, value, src, dst); } static void force_range_for_rox (const char *var, wordsizes size) { - /* Could do a modulo operation here... which one is faster? */ - switch (size) { - case sz_long: - printf ("\tif (%s >= 33) %s -= 33;\n", var, var); - break; - case sz_word: - printf ("\tif (%s >= 34) %s -= 34;\n", var, var); - printf ("\tif (%s >= 17) %s -= 17;\n", var, var); - break; - case sz_byte: - printf ("\tif (%s >= 36) %s -= 36;\n", var, var); - printf ("\tif (%s >= 18) %s -= 18;\n", var, var); - printf ("\tif (%s >= 9) %s -= 9;\n", var, var); - break; - } + /* Could do a modulo operation here... which one is faster? */ + switch (size) { + case sz_long: + printf ("\tif (%s >= 33) %s -= 33;\n", var, var); + break; + case sz_word: + printf ("\tif (%s >= 34) %s -= 34;\n", var, var); + printf ("\tif (%s >= 17) %s -= 17;\n", var, var); + break; + case sz_byte: + printf ("\tif (%s >= 36) %s -= 36;\n", var, var); + printf ("\tif (%s >= 18) %s -= 18;\n", var, var); + printf ("\tif (%s >= 9) %s -= 9;\n", var, var); + break; + } } static const char *cmask (wordsizes size) { - switch (size) { - case sz_byte: return "0x80"; - case sz_word: return "0x8000"; - case sz_long: return "0x80000000"; - default: abort (); - } + switch (size) { + case sz_byte: return "0x80"; + case sz_word: return "0x8000"; + case sz_long: return "0x80000000"; + default: abort (); + } } static int source_is_imm1_8 (struct instr *i) { - return i->stype == 3; + return i->stype == 3; } static void shift_ce (amodes dmode, int size) { - if (using_ce && isreg (dmode)) { - int c = size == sz_long ? 4 : 2; - printf ("\t{\n"); - printf ("\t\tint cycles = %d;\n", c); - printf ("\t\tcycles += 2 * ccnt;\n"); - addcycles000_3 ("\t\t"); - printf ("\t}\n"); - count_cycles += c; - } + if (using_ce && isreg (dmode)) { + int c = size == sz_long ? 4 : 2; + printf ("\t{\n"); + printf ("\t\tint cycles = %d;\n", c); + printf ("\t\tcycles += 2 * ccnt;\n"); + addcycles000_3 ("\t\t"); + printf ("\t}\n"); + count_cycles += c; + } } // BCHG/BSET/BCLR Dx,Dx or #xx,Dx adds 2 cycles if bit number > 15 static void bsetcycles (struct instr *curi) { - if (curi->size == sz_byte) { - printf ("\tsrc &= 7;\n"); - } else { - printf ("\tsrc &= 31;\n"); - if (isreg (curi->dmode)) { - addcycles000 (2); - if (curi->mnemo != i_BTST && using_ce) { - printf ("\tif (src > 15) do_cycles_ce000 (2);\n"); - count_ncycles++; - } + if (curi->size == sz_byte) { + printf ("\tsrc &= 7;\n"); + } else { + printf ("\tsrc &= 31;\n"); + if (isreg (curi->dmode)) { + addcycles000 (2); + if (curi->mnemo != i_BTST && using_ce) { + printf ("\tif (src > 15) do_cycles_ce000 (2);\n"); + count_ncycles++; + } + } } - } } static int islongimm (struct instr *curi) { - return (curi->size == sz_long && (curi->smode == Dreg || curi->smode == imm)); + return (curi->size == sz_long && (curi->smode == Dreg || curi->smode == imm)); } static void gen_opcode (unsigned long int opcode) { - struct instr *curi = table68k + opcode; - char *srcl, *dstl; - char *srcw, *dstw; - char *srcb, *dstb; - - insn_n_cycles = using_prefetch ? 0 : 4; - - if (using_ce020) { - srcl = "get_long_ce020"; - dstl = "put_long_ce020"; - srcw = "get_word_ce020"; - dstw = "put_word_ce020"; - srcb = "get_byte_ce020"; - dstb = "put_byte_ce020"; - } else if (using_mmu) { - srcl = "get_long_mmu"; - dstl = "put_long_mmu"; - srcw = "get_word_mmu"; - dstw = "put_word_mmu"; - srcb = "get_byte_mmu"; - dstb = "put_byte_mmu"; - } else if (using_ce) { - srcl = "get_long_ce"; - dstl = "put_long_ce"; - srcw = "get_word_ce"; - dstw = "put_word_ce"; - srcb = "get_byte_ce"; - dstb = "put_byte_ce"; - } else { - srcl = "get_long"; - dstl = "put_long"; - srcw = "get_word"; - dstw = "put_word"; - srcb = "get_byte"; - dstb = "put_byte"; - } - - insn_n_cycles020 = 0; - - start_brace (); - m68k_pc_offset = 2; - switch (curi->plev) { - case 0: /* not privileged */ - break; - case 1: /* unprivileged only on 68000 */ - if (cpu_level == 0) - break; - if (next_cpu_level < 0) - next_cpu_level = 0; - - /* fall through */ - case 2: /* priviledged */ - printf ("if (!regs.s) { Exception (8, 0); goto %s; }\n", endlabelstr); - need_endlabel = 1; - start_brace (); - break; - case 3: /* privileged if size == word */ - if (curi->size == sz_byte) - break; - printf ("if (!regs.s) { Exception (8, 0); goto %s; }\n", endlabelstr); - need_endlabel = 1; - start_brace (); - break; - } - switch (curi->mnemo) { - case i_OR: - case i_AND: - case i_EOR: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^'); - genflags (flag_logical, curi->size, "src", "", ""); - if (curi->smode == imm) { - int c = 0; - if (curi->size == sz_long && curi->dmode == Dreg) { - // op.L #,Dn = +2 cycles (AND), +4 cycles (EOR,OR) - if (curi->mnemo == i_EOR || curi->mnemo == i_OR) - c += 4; - else - c += 2; - } - if (c > 0) - addcycles000 (c); - } else if (curi->smode == Dreg) { - int c = 0; - if (curi->dmode == Dreg) { - if (curi->size == sz_long) - c += 2; - if (curi->size == sz_long && curi->smode == Dreg) - c += 2; - } - if (c > 0) - addcycles000 (c); - } - fill_prefetch_next (); - genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_ORSR: - case i_EORSR: - printf ("\tMakeSR ();\n"); - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (curi->size == sz_byte) { - printf ("\tsrc &= 0xFF;\n"); - } - addcycles000 (4); - fill_prefetch_next (); - printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|'); - printf ("\tMakeFromSR ();\n"); - break; - case i_ANDSR: - printf ("\tMakeSR ();\n"); - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (curi->size == sz_byte) { - printf ("\tsrc |= 0xFF00;\n"); - } - addcycles000 (4); - fill_prefetch_next (); - printf ("\tregs.sr &= src;\n"); - printf ("\tMakeFromSR ();\n"); - break; - case i_SUB: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - if (curi->dmode == Dreg) { - int c = 0; - if (curi->size == sz_long) { - c += 2; - if (curi->smode == imm || curi->smode == immi || curi->smode == Dreg) - c += 2; - } - if (c > 0) - addcycles000 (c); - } - fill_prefetch_next (); - start_brace (); - genflags (flag_sub, curi->size, "newv", "src", "dst"); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_SUBA: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); - if (curi->smode == immi) { - int c = 4; - if (c > 0) - addcycles000 (c); - } else { - int c = curi->size == sz_long ? 2 : 4; - if (islongimm (curi)) - c += 2; - if (c > 0) - addcycles000 (c); - } - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 newv = dst - src;\n"); - genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - break; - case i_SUBX: - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - if (curi->size == sz_long && isreg (curi->smode)) - addcycles000 (4); - if (!isreg (curi->smode)) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 newv = dst - src - (GET_XFLG () ? 1 : 0);\n"); - genflags (flag_subx, curi->size, "newv", "src", "dst"); - genflags (flag_zn, curi->size, "newv", "", ""); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_SBCD: - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG () ? 1 : 0);\n"); - printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n"); - printf ("\tuae_u16 newv, tmp_newv;\n"); - printf ("\tint bcd = 0;\n"); - printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n"); - printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n"); - printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG () ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n"); - printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG () ? 1 : 0)) & 0x300) > 0xFF);\n"); - duplicate_carry (0); - /* Manual says bits NV are undefined though a real 68040/060 don't change them */ - if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { - if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) - next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; - genflags (flag_z, curi->size, "newv", "", ""); - } else { - genflags (flag_zn, curi->size, "newv", "", ""); - printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n"); - } - addcycles000 (2); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_ADD: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - if (curi->dmode == Dreg) { - int c = 0; - if (curi->size == sz_long) { - c += 2; - if (curi->smode == imm || curi->smode == immi || curi->smode == Dreg) - c += 2; - } - if (c > 0) - addcycles000 (c); - } - fill_prefetch_next (); - start_brace (); - genflags (flag_add, curi->size, "newv", "src", "dst"); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_ADDA: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); - if (curi->smode == immi) { - int c = curi->size == sz_long ? 4 : 0; - if (islongimm (curi)) - c += 2; - if (c > 0) - addcycles000 (c); + struct instr *curi = table68k + opcode; + char *srcl, *dstl; + char *srcw, *dstw; + char *srcb, *dstb; + + insn_n_cycles = using_prefetch ? 0 : 4; + + if (using_ce020) { + srcl = "get_long_ce020"; + dstl = "put_long_ce020"; + srcw = "get_word_ce020"; + dstw = "put_word_ce020"; + srcb = "get_byte_ce020"; + dstb = "put_byte_ce020"; + } else if (using_mmu) { + srcl = "get_long_mmu"; + dstl = "put_long_mmu"; + srcw = "get_word_mmu"; + dstw = "put_word_mmu"; + srcb = "get_byte_mmu"; + dstb = "put_byte_mmu"; + } else if (using_ce) { + srcl = "get_long_ce"; + dstl = "put_long_ce"; + srcw = "get_word_ce"; + dstw = "put_word_ce"; + srcb = "get_byte_ce"; + dstb = "put_byte_ce"; } else { - int c = curi->size == sz_long ? 2 : 4; - if (islongimm (curi)) - c += 2; - if (c > 0) - addcycles000 (c); - } - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 newv = dst + src;\n"); - genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - break; - case i_ADDX: - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - if (curi->size == sz_long && isreg (curi->smode)) - addcycles000 (4); - if (!isreg (curi->smode)) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 newv = dst + src + (GET_XFLG () ? 1 : 0);\n"); - genflags (flag_addx, curi->size, "newv", "src", "dst"); - genflags (flag_zn, curi->size, "newv", "", ""); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_ABCD: - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG () ? 1 : 0);\n"); - printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n"); - printf ("\tuae_u16 newv, tmp_newv;\n"); - printf ("\tint cflg;\n"); - printf ("\tnewv = tmp_newv = newv_hi + newv_lo;"); - printf ("\tif (newv_lo > 9) { newv += 6; }\n"); - printf ("\tcflg = (newv & 0x3F0) > 0x90;\n"); - printf ("\tif (cflg) newv += 0x60;\n"); - printf ("\tSET_CFLG (cflg);\n"); - duplicate_carry (0); - /* Manual says bits NV are undefined though a real 68040 don't change them */ - if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { - if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) - next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; - genflags (flag_z, curi->size, "newv", "", ""); - } - else { - genflags (flag_zn, curi->size, "newv", "", ""); - printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n"); - } - addcycles000 (2); - genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_NEG: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (isreg (curi->smode) && curi->size == sz_long) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - genflags (flag_sub, curi->size, "dst", "src", "0"); - genastore_rev ("dst", curi->smode, "srcreg", curi->size, "src"); - break; - case i_NEGX: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (isreg (curi->smode) && curi->size == sz_long) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 newv = 0 - src - (GET_XFLG () ? 1 : 0);\n"); - genflags (flag_subx, curi->size, "newv", "src", "0"); - genflags (flag_zn, curi->size, "newv", "", ""); - genastore_rev ("newv", curi->smode, "srcreg", curi->size, "src"); - break; - case i_NBCD: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (isreg (curi->smode)) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG () ? 1 : 0);\n"); - printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n"); - printf ("\tuae_u16 newv;\n"); - printf ("\tint cflg;\n"); - printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n"); - printf ("\tnewv = newv_hi + newv_lo;"); - printf ("\tcflg = (newv & 0x1F0) > 0x90;\n"); - printf ("\tif (cflg) newv -= 0x60;\n"); - printf ("\tSET_CFLG (cflg);\n"); - duplicate_carry(0); - /* Manual says bits NV are undefined though a real 68040 don't change them */ - if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { - if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) - next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; - genflags (flag_z, curi->size, "newv", "", ""); - } - else { - genflags (flag_zn, curi->size, "newv", "", ""); - } - genastore ("newv", curi->smode, "srcreg", curi->size, "src"); - break; - case i_CLR: - genamode (curi->smode, "srcreg", curi->size, "src", cpu_level == 0 ? 1 : 2, 0, 0); - if (isreg (curi->smode) && curi->size == sz_long) - addcycles000 (2); - fill_prefetch_next (); - genflags (flag_logical, curi->size, "0", "", ""); - genastore_rev ("0", curi->smode, "srcreg", curi->size, "src"); - break; - case i_NOT: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (isreg (curi->smode) && curi->size == sz_long) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 dst = ~src;\n"); - genflags (flag_logical, curi->size, "dst", "", ""); - genastore_rev ("dst", curi->smode, "srcreg", curi->size, "src"); - break; - case i_TST: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - fill_prefetch_next (); - genflags (flag_logical, curi->size, "src", "", ""); - break; - case i_BTST: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - fill_prefetch_next (); - bsetcycles (curi); - printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); - break; - case i_BCHG: - case i_BCLR: - case i_BSET: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - bsetcycles (curi); - if (curi->mnemo == i_BCLR && curi->dmode == Dreg) - addcycles000 (2); - fill_prefetch_next (); - if (curi->mnemo == i_BCHG) { - printf ("\tdst ^= (1 << src);\n"); - printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n"); - } else if (curi->mnemo == i_BCLR) { - printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); - printf ("\tdst &= ~(1 << src);\n"); - } else if (curi->mnemo == i_BSET) { - printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); - printf ("\tdst |= (1 << src);\n"); + srcl = "get_long"; + dstl = "put_long"; + srcw = "get_word"; + dstw = "put_word"; + srcb = "get_byte"; + dstb = "put_byte"; } - genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_CMPM: - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); - fill_prefetch_next (); - start_brace (); - genflags (flag_cmp, curi->size, "newv", "src", "dst"); - break; - case i_CMP: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - if (curi->dmode == Dreg && curi->size == sz_long) - addcycles000 (2); - fill_prefetch_next (); - start_brace (); - genflags (flag_cmp, curi->size, "newv", "src", "dst"); - break; - case i_CMPA: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); - addcycles000 (2); - fill_prefetch_next (); + + insn_n_cycles020 = 0; + start_brace (); - genflags (flag_cmp, sz_long, "newv", "src", "dst"); - break; - /* The next two are coded a little unconventional, but they are doing - * weird things... */ - case i_MVPRM: // MOVEP R->M - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - printf ("\tuaecptr memp = m68k_areg (regs, dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword (0)); - if (curi->size == sz_word) { - printf ("\t%s (memp, src >> 8); %s (memp + 2, src);\n", dstb, dstb); - count_write += 2; - } else { - printf ("\t%s (memp, src >> 24); %s (memp + 2, src >> 16);\n", dstb, dstb); - printf ("\t%s (memp + 4, src >> 8); %s (memp + 6, src);\n", dstb, dstb); - count_write += 4; - } - fill_prefetch_next (); - break; - case i_MVPMR: // MOVEP M->R - printf ("\tuaecptr memp = m68k_areg (regs, srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword (0)); - genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); - if (curi->size == sz_word) { - printf ("\tuae_u16 val = (%s (memp) << 8) + %s (memp + 2);\n", srcb, srcb); - count_read += 2; - } else { - printf ("\tuae_u32 val = (%s (memp) << 24) + (%s (memp + 2) << 16)\n", srcb, srcb); - printf (" + (%s (memp + 4) << 8) + %s (memp + 6);\n", srcb, srcb); - count_read += 4; + m68k_pc_offset = 2; + switch (curi->plev) { + case 0: /* not privileged */ + break; + case 1: /* unprivileged only on 68000 */ + if (cpu_level == 0) + break; + if (next_cpu_level < 0) + next_cpu_level = 0; + + /* fall through */ + case 2: /* priviledged */ + printf ("if (!regs.s) { Exception (8, 0); goto %s; }\n", endlabelstr); + need_endlabel = 1; + start_brace (); + break; + case 3: /* privileged if size == word */ + if (curi->size == sz_byte) + break; + printf ("if (!regs.s) { Exception (8, 0); goto %s; }\n", endlabelstr); + need_endlabel = 1; + start_brace (); + break; } - fill_prefetch_next (); - genastore ("val", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_MOVE: - case i_MOVEA: - { - /* 2 MOVE instructions have special prefetch sequence: - * - MOVE ,-(An) = prefetch is before writes (Apdi) - * - MOVE memory,(xxx).L, the most stupid ever. 2 prefetches after write - * - all others = prefetch is done after writes - */ - int prefetch_done = 0; - int dualprefetch = curi->dmode == absl && (curi->smode != Dreg && curi->smode != Areg && curi->smode != imm); - genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - /* MOVE.L dx,(ax) exception3 PC points to next instruction. hackhackhack */ - genamode_e3 (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 1 | (dualprefetch ? GF_NOREFILL : 0), curi->smode == Dreg && curi->dmode == Aind ? 2 : 0); - genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - if (curi->mnemo == i_MOVEA && curi->size == sz_word) - printf ("\tsrc = (uae_s32)(uae_s16)src;\n"); - if (curi->dmode == Apdi) { + switch (curi->mnemo) { + case i_OR: + case i_AND: + case i_EOR: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^'); + genflags (flag_logical, curi->size, "src", "", ""); + if (curi->smode == imm) { + int c = 0; + if (curi->size == sz_long && curi->dmode == Dreg) { + // op.L #,Dn = +2 cycles (AND), +4 cycles (EOR,OR) + if (curi->mnemo == i_EOR || curi->mnemo == i_OR) + c += 4; + else + c += 2; + } + if (c > 0) + addcycles000 (c); + } else if (curi->smode == Dreg) { + int c = 0; + if (curi->dmode == Dreg) { + if (curi->size == sz_long) + c += 2; + if (curi->size == sz_long && curi->smode == Dreg) + c += 2; + } + if (c > 0) + addcycles000 (c); + } + fill_prefetch_next (); + genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_ORSR: + case i_EORSR: + printf ("\tMakeSR ();\n"); + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (curi->size == sz_byte) { + printf ("\tsrc &= 0xFF;\n"); + } + addcycles000 (4); + fill_prefetch_next (); + printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|'); + printf ("\tMakeFromSR ();\n"); + break; + case i_ANDSR: + printf ("\tMakeSR ();\n"); + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (curi->size == sz_byte) { + printf ("\tsrc |= 0xFF00;\n"); + } + addcycles000 (4); + fill_prefetch_next (); + printf ("\tregs.sr &= src;\n"); + printf ("\tMakeFromSR ();\n"); + break; + case i_SUB: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + if (curi->dmode == Dreg) { + int c = 0; + if (curi->size == sz_long) { + c += 2; + if (curi->smode == imm || curi->smode == immi || curi->smode == Dreg) + c += 2; + } + if (c > 0) + addcycles000 (c); + } + fill_prefetch_next (); + start_brace (); + genflags (flag_sub, curi->size, "newv", "src", "dst"); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_SUBA: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); + if (curi->smode == immi) { + int c = 4; + if (c > 0) + addcycles000 (c); + } else { + int c = curi->size == sz_long ? 2 : 4; + if (islongimm (curi)) + c += 2; + if (c > 0) + addcycles000 (c); + } + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 newv = dst - src;\n"); + genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + break; + case i_SUBX: + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + if (curi->size == sz_long && isreg (curi->smode)) + addcycles000 (4); + if (!isreg (curi->smode)) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 newv = dst - src - (GET_XFLG () ? 1 : 0);\n"); + genflags (flag_subx, curi->size, "newv", "src", "dst"); + genflags (flag_zn, curi->size, "newv", "", ""); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_SBCD: + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG () ? 1 : 0);\n"); + printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n"); + printf ("\tuae_u16 newv, tmp_newv;\n"); + printf ("\tint bcd = 0;\n"); + printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n"); + printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n"); + printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG () ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n"); + printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG () ? 1 : 0)) & 0x300) > 0xFF);\n"); + duplicate_carry (0); + /* Manual says bits NV are undefined though a real 68040/060 don't change them */ + if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { + if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) + next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; + genflags (flag_z, curi->size, "newv", "", ""); + } else { + genflags (flag_zn, curi->size, "newv", "", ""); + printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n"); + } + addcycles000 (2); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_ADD: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + if (curi->dmode == Dreg) { + int c = 0; + if (curi->size == sz_long) { + c += 2; + if (curi->smode == imm || curi->smode == immi || curi->smode == Dreg) + c += 2; + } + if (c > 0) + addcycles000 (c); + } + fill_prefetch_next (); + start_brace (); + genflags (flag_add, curi->size, "newv", "src", "dst"); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_ADDA: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); + if (curi->smode == immi) { + int c = curi->size == sz_long ? 4 : 0; + if (islongimm (curi)) + c += 2; + if (c > 0) + addcycles000 (c); + } else { + int c = curi->size == sz_long ? 2 : 4; + if (islongimm (curi)) + c += 2; + if (c > 0) + addcycles000 (c); + } + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 newv = dst + src;\n"); + genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + break; + case i_ADDX: + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + if (curi->size == sz_long && isreg (curi->smode)) + addcycles000 (4); + if (!isreg (curi->smode)) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 newv = dst + src + (GET_XFLG () ? 1 : 0);\n"); + genflags (flag_addx, curi->size, "newv", "src", "dst"); + genflags (flag_zn, curi->size, "newv", "", ""); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_ABCD: + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG () ? 1 : 0);\n"); + printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n"); + printf ("\tuae_u16 newv, tmp_newv;\n"); + printf ("\tint cflg;\n"); + printf ("\tnewv = tmp_newv = newv_hi + newv_lo;"); + printf ("\tif (newv_lo > 9) { newv += 6; }\n"); + printf ("\tcflg = (newv & 0x3F0) > 0x90;\n"); + printf ("\tif (cflg) newv += 0x60;\n"); + printf ("\tSET_CFLG (cflg);\n"); + duplicate_carry (0); + /* Manual says bits NV are undefined though a real 68040 don't change them */ + if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { + if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) + next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; + genflags (flag_z, curi->size, "newv", "", ""); + } + else { + genflags (flag_zn, curi->size, "newv", "", ""); + printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n"); + } + addcycles000 (2); + genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_NEG: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (isreg (curi->smode) && curi->size == sz_long) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + genflags (flag_sub, curi->size, "dst", "src", "0"); + genastore_rev ("dst", curi->smode, "srcreg", curi->size, "src"); + break; + case i_NEGX: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (isreg (curi->smode) && curi->size == sz_long) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 newv = 0 - src - (GET_XFLG () ? 1 : 0);\n"); + genflags (flag_subx, curi->size, "newv", "src", "0"); + genflags (flag_zn, curi->size, "newv", "", ""); + genastore_rev ("newv", curi->smode, "srcreg", curi->size, "src"); + break; + case i_NBCD: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (isreg (curi->smode)) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG () ? 1 : 0);\n"); + printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n"); + printf ("\tuae_u16 newv;\n"); + printf ("\tint cflg;\n"); + printf ("\tif (newv_lo > 9) { newv_lo -= 6; }\n"); + printf ("\tnewv = newv_hi + newv_lo;"); + printf ("\tcflg = (newv & 0x1F0) > 0x90;\n"); + printf ("\tif (cflg) newv -= 0x60;\n"); + printf ("\tSET_CFLG (cflg);\n"); + duplicate_carry(0); + /* Manual says bits NV are undefined though a real 68040 don't change them */ + if (cpu_level >= xBCD_KEEPS_NV_FLAGS) { + if (next_cpu_level < xBCD_KEEPS_NV_FLAGS) + next_cpu_level = xBCD_KEEPS_NV_FLAGS - 1; + genflags (flag_z, curi->size, "newv", "", ""); + } + else { + genflags (flag_zn, curi->size, "newv", "", ""); + } + genastore ("newv", curi->smode, "srcreg", curi->size, "src"); + break; + case i_CLR: + genamode (curi->smode, "srcreg", curi->size, "src", cpu_level == 0 ? 1 : 2, 0, 0); + if (isreg (curi->smode) && curi->size == sz_long) + addcycles000 (2); + fill_prefetch_next (); + genflags (flag_logical, curi->size, "0", "", ""); + genastore_rev ("0", curi->smode, "srcreg", curi->size, "src"); + break; + case i_NOT: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (isreg (curi->smode) && curi->size == sz_long) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 dst = ~src;\n"); + genflags (flag_logical, curi->size, "dst", "", ""); + genastore_rev ("dst", curi->smode, "srcreg", curi->size, "src"); + break; + case i_TST: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); fill_prefetch_next (); - prefetch_done = 1; - } - if (curi->mnemo == i_MOVE) genflags (flag_logical, curi->size, "src", "", ""); - genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); - sync_m68k_pc (); - if (dualprefetch) { - fill_prefetch_full (); - prefetch_done = 1; - } - if (!prefetch_done) + break; + case i_BTST: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); fill_prefetch_next (); - } - break; - case i_MVSR2: // MOVE FROM SR (like CLR, does dummy read first on 68000) - genamode (curi->smode, "srcreg", sz_word, "src", cpu_level == 0 ? 1 : 2, 0, 0); - if (isreg (curi->smode)) - addcycles000 (2); - fill_prefetch_next (); - printf ("\tMakeSR ();\n"); - if (curi->size == sz_byte) - genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src"); - else - genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src"); - break; - case i_MV2SR: // MOVE TO SR - genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); - if (curi->size == sz_byte) { - addcycles000 (8); - printf ("\tMakeSR ();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n"); - } else { - addcycles000 (4); - printf ("\tregs.sr = src;\n"); - } - fill_prefetch_next (); - printf ("\tMakeFromSR ();\n"); - break; - case i_SWAP: - genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n"); - genflags (flag_logical, sz_long, "dst", "", ""); - genastore ("dst", curi->smode, "srcreg", sz_long, "src"); - break; - case i_EXG: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - addcycles000 (2); - fill_prefetch_next (); - genastore ("dst", curi->smode, "srcreg", curi->size, "src"); - genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_EXT: - genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break; - case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break; - case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break; - default: abort (); - } - genflags (flag_logical, - curi->size == sz_word ? sz_word : sz_long, "dst", "", ""); - genastore ("dst", curi->smode, "srcreg", - curi->size == sz_word ? sz_word : sz_long, "src"); - break; - case i_MVMEL: - if (using_ce) - genmovemel_ce (opcode); - else - genmovemel (opcode); - break; - case i_MVMLE: - if (using_ce) - genmovemle_ce (opcode); - else - genmovemle (opcode); - break; - case i_TRAP: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - gen_set_fault_pc (); - sync_m68k_pc (); - printf ("\tException (src + 32, 0);\n"); - did_prefetch = 1; - m68k_pc_offset = 0; - break; - case i_MVR2USP: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - fill_prefetch_next (); - printf ("\tregs.usp = src;\n"); - break; - case i_MVUSP2R: - genamode (curi->smode, "srcreg", curi->size, "src", 2, 0, 0); - fill_prefetch_next (); - genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src"); - break; - case i_RESET: - fill_prefetch_next (); - printf ("\tcpureset ();\n"); - addcycles000 (128); - if (using_prefetch) - printf ("\tregs.irc = get_iword (4);\n"); - break; - case i_NOP: - fill_prefetch_next (); - break; - case i_STOP: - if (using_prefetch) { - printf ("\tregs.sr = regs.irc;\n"); - m68k_pc_offset += 2; - } else { - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - printf ("\tregs.sr = src;\n"); - } - printf ("\tMakeFromSR ();\n"); - printf ("\tm68k_setstopped ();\n"); - sync_m68k_pc (); - // STOP does not prefetch anything - did_prefetch = -1; - break; - case i_LPSTOP: /* 68060 */ - printf ("\tuae_u16 sw = get_iword (2);\n"); - printf ("\tuae_u16 sr;\n"); - printf ("\tif (sw != (0x100|0x80|0x40)) { Exception (4, 0); goto %s; }\n", endlabelstr); - printf ("\tsr = get_iword (4);\n"); - printf ("\tif (!(sr & 0x8000)) { Exception (8, 0); goto %s; }\n", endlabelstr); - printf ("\tregs.sr = sr;\n"); - printf ("\tMakeFromSR ();\n"); - printf ("\tm68k_setstopped();\n"); - m68k_pc_offset += 4; - sync_m68k_pc (); - fill_prefetch_full (); - break; - case i_RTE: - if (cpu_level == 0) { - genamode (Aipi, "7", sz_word, "sr", 1, 0, GF_NOREFILL); - genamode (Aipi, "7", sz_long, "pc", 1, 0, GF_NOREFILL); - printf ("\tregs.sr = sr;\n"); - setpc ("pc"); - printf ("\tMakeFromSR ();\n"); - } else { - int old_brace_level = n_braces; - if (next_cpu_level < 0) - next_cpu_level = 0; - genamode (Aipi, "7", sz_word, "sr", 1, 0, 0); - genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); - genamode (Aipi, "7", sz_word, "format", 1, 0, 0); - printf ("\tm68k_do_rte (pc, sr, format, 0x%04x);\n", opcode); - } - /* PC is set and prefetch filled. */ - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_RTD: - if (using_mmu) { - genamode (curi->smode, "srcreg", curi->size, "offs", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); - genamode (Aipi, "7", sz_long, "pc", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); - printf ("\tm68k_areg(regs, 7) += offs;\n"); - setpc ("pc"); - } else { - genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); - genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0, 0); - printf ("\tm68k_areg (regs, 7) += offs;\n"); - printf ("\tif (pc & 1)\n"); - printf ("\t\texception3 (0x%04X, m68k_getpc (), pc);\n", opcode); - printf ("\telse\n"); - setpc ("pc"); - } - /* PC is set and prefetch filled. */ - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_LINK: - if (using_mmu) { - genamode (curi->dmode, "dstreg", curi->size, "offs", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); - genamode (Apdi, "7", sz_long, "old", GENA_GETV_FETCH_ALIGN, GENA_MOVEM_DO_INC, 0); - genamode (curi->smode, "srcreg", sz_long, "src", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); - genastore ("m68k_areg(regs, 7)", curi->smode, "srcreg", sz_long, "src"); - printf ("\tm68k_areg(regs, 7) += offs;\n"); - genastore ("src", Apdi, "7", sz_long, "old"); - } else { - genamode (Apdi, "7", sz_long, "old", 2, 0, GF_AA); - genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0, 0); - genastore ("src", Apdi, "7", sz_long, "old"); - genastore ("m68k_areg (regs, 7)", curi->smode, "srcreg", sz_long, "src"); - printf ("\tm68k_areg (regs, 7) += offs;\n"); - fill_prefetch_next (); - } - break; - case i_UNLK: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - printf ("\tm68k_areg (regs, 7) = src;\n"); - genamode (Aipi, "7", sz_long, "old", 1, 0, 0); - fill_prefetch_next (); - genastore ("old", curi->smode, "srcreg", curi->size, "src"); - break; - case i_RTS: - if (using_ce) - printf ("\tm68k_do_rts_ce ();\n"); - else if (using_indirect) - printf ("\tm68k_do_rtsi ();\n"); - else if (using_mmu) - printf ("\tm68k_do_rts_mmu ();\n"); - else - printf ("\tm68k_do_rts ();\n"); - count_read += 2; - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_TRAPV: - sync_m68k_pc (); - fill_prefetch_next (); - printf ("\tif (GET_VFLG ()) {\n"); - printf ("\t\tException (7, m68k_getpc ());\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - break; - case i_RTR: - printf ("\tMakeSR ();\n"); - genamode_pre (Aipi, "7", sz_word, "sr", 1, 0, 0); - genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); - genamode_post (Aipi, "7", sz_word, "sr", 1, 0, 0); - printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n"); - printf ("\tregs.sr |= sr;\n"); - setpc ("pc"); - printf ("\tMakeFromSR ();\n"); - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_JSR: // TODO: check stack write order - genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA|GF_NOREFILL); - start_brace (); - printf ("\tuaecptr oldpc = m68k_getpc () + %d;\n", m68k_pc_offset); - if (using_exception_3) { - printf ("\tif (srca & 1) {\n"); - printf ("\t\texception3i (opcode, oldpc, srca);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - } - if (curi->smode == Ad16 || curi->smode == absw || curi->smode == PC16) - addcycles000 (2); - setpc ("srca"); - m68k_pc_offset = 0; - fill_prefetch_1 (0); - if (curi->smode == Ad8r || curi->smode == PC8r) - addcycles000 (6); - printf ("\tm68k_areg (regs, 7) -= 4;\n"); - if (using_ce) { - printf ("\tput_word_ce (m68k_areg (regs, 7), oldpc >> 16);\n"); - printf ("\tput_word_ce (m68k_areg (regs, 7) + 2, oldpc);\n"); - } else { - printf ("\t%s (m68k_areg (regs, 7), oldpc);\n", dstl); - } - count_write += 2; - fill_prefetch_next (); - break; - case i_JMP: - genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA | ((curi->smode == Ad8r || curi->smode == PC8r) ? 0 : GF_NOREFILL)); - if (using_exception_3) { - printf ("\tif (srca & 1) {\n"); - printf ("\t\texception3i (opcode, m68k_getpc () + 6, srca);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - } - if (curi->smode == Ad16 || curi->smode == Ad8r || curi->smode == absw || curi->smode == PC16 || curi->smode == PC8r) - addcycles000 (2); - setpc ("srca"); - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_BSR: - printf ("\tuae_s32 s;\n"); - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA|GF_NOREFILL); - printf ("\ts = (uae_s32)src + 2;\n"); - if (using_exception_3) { - printf ("\tif (src & 1) {\n"); - printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + s);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - } - addcycles000 (2); - if (using_ce) { - printf ("\tm68k_do_bsr_ce (m68k_getpc () + %d, s);\n", m68k_pc_offset); - } else if (using_indirect) { - printf ("\tm68k_do_bsri (m68k_getpc () + %d, s);\n", m68k_pc_offset); - } else if (using_mmu) { - printf ("\tm68k_do_bsr_mmu (m68k_getpc () + %d, s);\n", m68k_pc_offset); - } else { - printf ("\tm68k_do_bsr (m68k_getpc () + %d, s);\n", m68k_pc_offset); - } - count_write += 2; - m68k_pc_offset = 0; - fill_prefetch_full (); - break; - case i_Bcc: - if (curi->size == sz_long) { - if (cpu_level < 2) { + bsetcycles (curi); + printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); + break; + case i_BCHG: + case i_BCLR: + case i_BSET: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + bsetcycles (curi); + if (curi->mnemo == i_BCLR && curi->dmode == Dreg) + addcycles000 (2); + fill_prefetch_next (); + if (curi->mnemo == i_BCHG) { + printf ("\tdst ^= (1 << src);\n"); + printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n"); + } else if (curi->mnemo == i_BCLR) { + printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); + printf ("\tdst &= ~(1 << src);\n"); + } else if (curi->mnemo == i_BSET) { + printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); + printf ("\tdst |= (1 << src);\n"); + } + genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_CMPM: + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA); + fill_prefetch_next (); + start_brace (); + genflags (flag_cmp, curi->size, "newv", "src", "dst"); + break; + case i_CMP: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + if (curi->dmode == Dreg && curi->size == sz_long) + addcycles000 (2); + fill_prefetch_next (); + start_brace (); + genflags (flag_cmp, curi->size, "newv", "src", "dst"); + break; + case i_CMPA: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); addcycles000 (2); - printf ("\tif (cctrue (%d)) {\n", curi->cc); - printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 1);\n"); + fill_prefetch_next (); + start_brace (); + genflags (flag_cmp, sz_long, "newv", "src", "dst"); + break; + /* The next two are coded a little unconventional, but they are doing + * weird things... */ + case i_MVPRM: // MOVEP R->M + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + printf ("\tuaecptr memp = m68k_areg (regs, dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword (0)); + if (curi->size == sz_word) { + printf ("\t%s (memp, src >> 8); %s (memp + 2, src);\n", dstb, dstb); + count_write += 2; + } else { + printf ("\t%s (memp, src >> 24); %s (memp + 2, src >> 16);\n", dstb, dstb); + printf ("\t%s (memp + 4, src >> 8); %s (memp + 6, src);\n", dstb, dstb); + count_write += 4; + } + fill_prefetch_next (); + break; + case i_MVPMR: // MOVEP M->R + printf ("\tuaecptr memp = m68k_areg (regs, srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword (0)); + genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); + if (curi->size == sz_word) { + printf ("\tuae_u16 val = (%s (memp) << 8) + %s (memp + 2);\n", srcb, srcb); + count_read += 2; + } else { + printf ("\tuae_u32 val = (%s (memp) << 24) + (%s (memp + 2) << 16)\n", srcb, srcb); + printf (" + (%s (memp + 4) << 8) + %s (memp + 6);\n", srcb, srcb); + count_read += 4; + } + fill_prefetch_next (); + genastore ("val", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_MOVE: + case i_MOVEA: + { + /* 2 MOVE instructions have special prefetch sequence: + * - MOVE ,-(An) = prefetch is before writes (Apdi) + * - MOVE memory,(xxx).L, the most stupid ever. 2 prefetches after write + * - all others = prefetch is done after writes + */ + int prefetch_done = 0; + int dualprefetch = curi->dmode == absl && (curi->smode != Dreg && curi->smode != Areg && curi->smode != imm); + genamode_pre (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + /* MOVE.L dx,(ax) exception3 PC points to next instruction. hackhackhack */ + genamode_e3 (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 1 | (dualprefetch ? GF_NOREFILL : 0), curi->smode == Dreg && curi->dmode == Aind ? 2 : 0); + genamode_post (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + if (curi->mnemo == i_MOVEA && curi->size == sz_word) + printf ("\tsrc = (uae_s32)(uae_s16)src;\n"); + if (curi->dmode == Apdi) { + fill_prefetch_next (); + prefetch_done = 1; + } + if (curi->mnemo == i_MOVE) + genflags (flag_logical, curi->size, "src", "", ""); + genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); + sync_m68k_pc (); + if (dualprefetch) { + fill_prefetch_full (); + prefetch_done = 1; + } + if (!prefetch_done) + fill_prefetch_next (); + } + break; + case i_MVSR2: // MOVE FROM SR (like CLR, does dummy read first on 68000) + genamode (curi->smode, "srcreg", sz_word, "src", cpu_level == 0 ? 1 : 2, 0, 0); + if (isreg (curi->smode)) + addcycles000 (2); + fill_prefetch_next (); + printf ("\tMakeSR ();\n"); + if (curi->size == sz_byte) + genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src"); + else + genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src"); + break; + case i_MV2SR: // MOVE TO SR + genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); + if (curi->size == sz_byte) { + addcycles000 (8); + printf ("\tMakeSR ();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n"); + } else { + addcycles000 (4); + printf ("\tregs.sr = src;\n"); + } + fill_prefetch_next (); + printf ("\tMakeFromSR ();\n"); + break; + case i_SWAP: + genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n"); + genflags (flag_logical, sz_long, "dst", "", ""); + genastore ("dst", curi->smode, "srcreg", sz_long, "src"); + break; + case i_EXG: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + addcycles000 (2); + fill_prefetch_next (); + genastore ("dst", curi->smode, "srcreg", curi->size, "src"); + genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_EXT: + genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break; + case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break; + case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break; + default: abort (); + } + genflags (flag_logical, + curi->size == sz_word ? sz_word : sz_long, "dst", "", ""); + genastore ("dst", curi->smode, "srcreg", + curi->size == sz_word ? sz_word : sz_long, "src"); + break; + case i_MVMEL: + if (using_ce) + genmovemel_ce (opcode); + else + genmovemel (opcode); + break; + case i_MVMLE: + if (using_ce) + genmovemle_ce (opcode); + else + genmovemle (opcode); + break; + case i_TRAP: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + gen_set_fault_pc (); + sync_m68k_pc (); + printf ("\tException (src + 32, 0);\n"); + did_prefetch = 1; + m68k_pc_offset = 0; + break; + case i_MVR2USP: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + fill_prefetch_next (); + printf ("\tregs.usp = src;\n"); + break; + case i_MVUSP2R: + genamode (curi->smode, "srcreg", curi->size, "src", 2, 0, 0); + fill_prefetch_next (); + genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src"); + break; + case i_RESET: + fill_prefetch_next (); + printf ("\tcpureset ();\n"); + addcycles000 (128); + if (using_prefetch) + printf ("\tregs.irc = get_iword (4);\n"); + break; + case i_NOP: + fill_prefetch_next (); + break; + case i_STOP: + if (using_prefetch) { + printf ("\tregs.sr = regs.irc;\n"); + m68k_pc_offset += 2; + } else { + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + printf ("\tregs.sr = src;\n"); + } + printf ("\tMakeFromSR ();\n"); + printf ("\tm68k_setstopped ();\n"); + sync_m68k_pc (); + // STOP does not prefetch anything + did_prefetch = -1; + break; + case i_LPSTOP: /* 68060 */ + printf ("\tuae_u16 sw = get_iword (2);\n"); + printf ("\tuae_u16 sr;\n"); + printf ("\tif (sw != (0x100|0x80|0x40)) { Exception (4, 0); goto %s; }\n", endlabelstr); + printf ("\tsr = get_iword (4);\n"); + printf ("\tif (!(sr & 0x8000)) { Exception (8, 0); goto %s; }\n", endlabelstr); + printf ("\tregs.sr = sr;\n"); + printf ("\tMakeFromSR ();\n"); + printf ("\tm68k_setstopped();\n"); + m68k_pc_offset += 4; + sync_m68k_pc (); + fill_prefetch_full (); + break; + case i_RTE: + if (cpu_level == 0) { + genamode (Aipi, "7", sz_word, "sr", 1, 0, GF_NOREFILL); + genamode (Aipi, "7", sz_long, "pc", 1, 0, GF_NOREFILL); + printf ("\tregs.sr = sr;\n"); + setpc ("pc"); + printf ("\tMakeFromSR ();\n"); + } else { + int old_brace_level = n_braces; + if (next_cpu_level < 0) + next_cpu_level = 0; + genamode (Aipi, "7", sz_word, "sr", 1, 0, 0); + genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); + genamode (Aipi, "7", sz_word, "format", 1, 0, 0); + printf ("\tm68k_do_rte (pc, sr, format, 0x%04x);\n", opcode); + } + /* PC is set and prefetch filled. */ + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_RTD: + if (using_mmu) { + genamode (curi->smode, "srcreg", curi->size, "offs", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); + genamode (Aipi, "7", sz_long, "pc", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); + printf ("\tm68k_areg(regs, 7) += offs;\n"); + setpc ("pc"); + } else { + genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); + genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0, 0); + printf ("\tm68k_areg (regs, 7) += offs;\n"); + printf ("\tif (pc & 1)\n"); + printf ("\t\texception3 (0x%04X, m68k_getpc (), pc);\n", opcode); + printf ("\telse\n"); + setpc ("pc"); + } + /* PC is set and prefetch filled. */ + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_LINK: + if (using_mmu) { + genamode (curi->dmode, "dstreg", curi->size, "offs", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); + genamode (Apdi, "7", sz_long, "old", GENA_GETV_FETCH_ALIGN, GENA_MOVEM_DO_INC, 0); + genamode (curi->smode, "srcreg", sz_long, "src", GENA_GETV_FETCH, GENA_MOVEM_DO_INC, 0); + genastore ("m68k_areg(regs, 7)", curi->smode, "srcreg", sz_long, "src"); + printf ("\tm68k_areg(regs, 7) += offs;\n"); + genastore ("src", Apdi, "7", sz_long, "old"); + } else { + genamode (Apdi, "7", sz_long, "old", 2, 0, GF_AA); + genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0, 0); + genastore ("src", Apdi, "7", sz_long, "old"); + genastore ("m68k_areg (regs, 7)", curi->smode, "srcreg", sz_long, "src"); + printf ("\tm68k_areg (regs, 7) += offs;\n"); + fill_prefetch_next (); + } + break; + case i_UNLK: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + printf ("\tm68k_areg (regs, 7) = src;\n"); + genamode (Aipi, "7", sz_long, "old", 1, 0, 0); + fill_prefetch_next (); + genastore ("old", curi->smode, "srcreg", curi->size, "src"); + break; + case i_RTS: + if (using_ce) + printf ("\tm68k_do_rts_ce ();\n"); + else if (using_indirect) + printf ("\tm68k_do_rtsi ();\n"); + else if (using_mmu) + printf ("\tm68k_do_rts_mmu ();\n"); + else + printf ("\tm68k_do_rts ();\n"); + count_read += 2; + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_TRAPV: + sync_m68k_pc (); + fill_prefetch_next (); + printf ("\tif (GET_VFLG ()) {\n"); + printf ("\t\tException (7, m68k_getpc ());\n"); printf ("\t\tgoto %s;\n", endlabelstr); printf ("\t}\n"); + need_endlabel = 1; + break; + case i_RTR: + printf ("\tMakeSR ();\n"); + genamode_pre (Aipi, "7", sz_word, "sr", 1, 0, 0); + genamode (Aipi, "7", sz_long, "pc", 1, 0, 0); + genamode_post (Aipi, "7", sz_word, "sr", 1, 0, 0); + printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n"); + printf ("\tregs.sr |= sr;\n"); + setpc ("pc"); + printf ("\tMakeFromSR ();\n"); + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_JSR: // TODO: check stack write order + genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA|GF_NOREFILL); + start_brace (); + printf ("\tuaecptr oldpc = m68k_getpc () + %d;\n", m68k_pc_offset); + if (using_exception_3) { + printf ("\tif (srca & 1) {\n"); + printf ("\t\texception3i (opcode, oldpc, srca);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + need_endlabel = 1; + } + if (curi->smode == Ad16 || curi->smode == absw || curi->smode == PC16) + addcycles000 (2); + setpc ("srca"); + m68k_pc_offset = 0; + fill_prefetch_1 (0); + if (curi->smode == Ad8r || curi->smode == PC8r) + addcycles000 (6); + printf ("\tm68k_areg (regs, 7) -= 4;\n"); + if (using_ce) { + printf ("\tput_word_ce (m68k_areg (regs, 7), oldpc >> 16);\n"); + printf ("\tput_word_ce (m68k_areg (regs, 7) + 2, oldpc);\n"); + } else { + printf ("\t%s (m68k_areg (regs, 7), oldpc);\n", dstl); + } + count_write += 2; + fill_prefetch_next (); + break; + case i_JMP: + genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA | ((curi->smode == Ad8r || curi->smode == PC8r) ? 0 : GF_NOREFILL)); + if (using_exception_3) { + printf ("\tif (srca & 1) {\n"); + printf ("\t\texception3i (opcode, m68k_getpc () + 6, srca);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + need_endlabel = 1; + } + if (curi->smode == Ad16 || curi->smode == Ad8r || curi->smode == absw || curi->smode == PC16 || curi->smode == PC8r) + addcycles000 (2); + setpc ("srca"); + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_BSR: + printf ("\tuae_s32 s;\n"); + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA|GF_NOREFILL); + printf ("\ts = (uae_s32)src + 2;\n"); + if (using_exception_3) { + printf ("\tif (src & 1) {\n"); + printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + s);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + need_endlabel = 1; + } + addcycles000 (2); + if (using_ce) { + printf ("\tm68k_do_bsr_ce (m68k_getpc () + %d, s);\n", m68k_pc_offset); + } else if (using_indirect) { + printf ("\tm68k_do_bsri (m68k_getpc () + %d, s);\n", m68k_pc_offset); + } else if (using_mmu) { + printf ("\tm68k_do_bsr_mmu (m68k_getpc () + %d, s);\n", m68k_pc_offset); + } else { + printf ("\tm68k_do_bsr (m68k_getpc () + %d, s);\n", m68k_pc_offset); + } + count_write += 2; + m68k_pc_offset = 0; + fill_prefetch_full (); + break; + case i_Bcc: + if (curi->size == sz_long) { + if (cpu_level < 2) { + addcycles000 (2); + printf ("\tif (cctrue (%d)) {\n", curi->cc); + printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 1);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + sync_m68k_pc (); + irc2ir (); + fill_prefetch_2 (); + printf ("\tgoto %s;\n", endlabelstr); + need_endlabel = 1; + } else { + if (next_cpu_level < 1) + next_cpu_level = 1; + } + } + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL); + addcycles000 (2); + printf ("\tif (!cctrue (%d)) goto didnt_jump;\n", curi->cc); + if (using_exception_3) { + printf ("\tif (src & 1) {\n"); + printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 2 + (uae_s32)src);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + need_endlabel = 1; + } + if (using_prefetch) { + incpc ("(uae_s32)src + 2"); + fill_prefetch_full (); + if (using_ce) + printf ("\treturn;\n"); + else + printf ("\treturn 10 * CYCLE_UNIT / 2;\n"); + } else { + incpc ("(uae_s32)src + 2"); + returncycles ("\t", 10); + } + printf ("didnt_jump:;\n"); + need_endlabel = 1; sync_m68k_pc (); + if (curi->size == sz_byte) { + addcycles000 (2); + irc2ir (); + fill_prefetch_2 (); + } else if (curi->size == sz_word) { + addcycles000 (2); + fill_prefetch_full (); + } else { + fill_prefetch_full (); + } + insn_n_cycles = curi->size == sz_byte ? 8 : 12; + break; + case i_LEA: + genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA); + genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, GF_AA); + if (curi->smode == Ad8r || curi->smode == PC8r) + addcycles000 (2); + fill_prefetch_next (); + if (curi->smode == Ad8r || curi->smode == PC8r) + addcycles000 (2); + genastore ("srca", curi->dmode, "dstreg", curi->size, "dst"); + break; + case i_PEA: + genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA); + genamode (Apdi, "7", sz_long, "dst", 2, 0, GF_AA); + if (curi->smode == Ad8r || curi->smode == PC8r) + addcycles000 (2); + if (!(curi->smode == absw || curi->smode == absl)) + fill_prefetch_next (); + if (curi->smode == Ad8r || curi->smode == PC8r) + addcycles000 (2); + genastore ("srca", Apdi, "7", sz_long, "dst"); + if ((curi->smode == absw || curi->smode == absl)) + fill_prefetch_next (); + break; + case i_DBcc: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL); + genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0, GF_AA | GF_NOREFILL); + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + addcycles000 (2); + printf ("\tif (!cctrue (%d)) {\n", curi->cc); + incpc ("(uae_s32)offs + 2"); + printf ("\t"); fill_prefetch_1 (0); + printf ("\t"); genastore ("(src - 1)", curi->smode, "srcreg", curi->size, "src"); + + printf ("\t\tif (src) {\n"); + addcycles_ce020 (4); + if (using_exception_3) { + printf ("\t\t\tif (offs & 1) {\n"); + printf ("\t\t\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 2 + (uae_s32)offs + 2);\n"); + printf ("\t\t\t\tgoto %s;\n", endlabelstr); + printf ("\t\t\t}\n"); + need_endlabel = 1; + } irc2ir (); - fill_prefetch_2 (); - printf ("\tgoto %s;\n", endlabelstr); + fill_prefetch_1 (2); + returncycles ("\t\t\t", 12); + if (using_ce) + printf ("\t\t\treturn;\n"); + printf ("\t\t}\n"); + addcycles_ce020 (8); + printf ("\t} else {\n"); + addcycles000_2 ("\t\t", 2); + addcycles_ce020 (4); + printf ("\t}\n"); + setpc ("oldpc + %d", m68k_pc_offset); + m68k_pc_offset = 0; + fill_prefetch_full (); + insn_n_cycles = 12; need_endlabel = 1; - } else { - if (next_cpu_level < 1) - next_cpu_level = 1; - } - } - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL); - addcycles000 (2); - printf ("\tif (!cctrue (%d)) goto didnt_jump;\n", curi->cc); - if (using_exception_3) { - printf ("\tif (src & 1) {\n"); - printf ("\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 2 + (uae_s32)src);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - need_endlabel = 1; - } - if (using_prefetch) { - incpc ("(uae_s32)src + 2"); - fill_prefetch_full (); - if (using_ce) - printf ("\treturn;\n"); - else - printf ("\treturn 10 * CYCLE_UNIT / 2;\n"); - } else { - incpc ("(uae_s32)src + 2"); - returncycles ("\t", 10); - } - printf ("didnt_jump:;\n"); - need_endlabel = 1; - sync_m68k_pc (); - if (curi->size == sz_byte) { - addcycles000 (2); - irc2ir (); - fill_prefetch_2 (); - } else if (curi->size == sz_word) { - addcycles000 (2); - fill_prefetch_full (); - } else { - fill_prefetch_full (); - } - insn_n_cycles = curi->size == sz_byte ? 8 : 12; - break; - case i_LEA: - genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA); - genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, GF_AA); - if (curi->smode == Ad8r || curi->smode == PC8r) - addcycles000 (2); - fill_prefetch_next (); - if (curi->smode == Ad8r || curi->smode == PC8r) - addcycles000 (2); - genastore ("srca", curi->dmode, "dstreg", curi->size, "dst"); - break; - case i_PEA: - genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA); - genamode (Apdi, "7", sz_long, "dst", 2, 0, GF_AA); - if (curi->smode == Ad8r || curi->smode == PC8r) - addcycles000 (2); - if (!(curi->smode == absw || curi->smode == absl)) - fill_prefetch_next (); - if (curi->smode == Ad8r || curi->smode == PC8r) - addcycles000 (2); - genastore ("srca", Apdi, "7", sz_long, "dst"); - if ((curi->smode == absw || curi->smode == absl)) - fill_prefetch_next (); - break; - case i_DBcc: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL); - genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0, GF_AA | GF_NOREFILL); - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - addcycles000 (2); - printf ("\tif (!cctrue (%d)) {\n", curi->cc); - incpc ("(uae_s32)offs + 2"); - printf ("\t"); fill_prefetch_1 (0); - printf ("\t"); genastore ("(src - 1)", curi->smode, "srcreg", curi->size, "src"); - - printf ("\t\tif (src) {\n"); - addcycles_ce020 (3); - if (using_exception_3) { - printf ("\t\t\tif (offs & 1) {\n"); - printf ("\t\t\t\texception3i (opcode, m68k_getpc () + 2, m68k_getpc () + 2 + (uae_s32)offs + 2);\n"); - printf ("\t\t\t\tgoto %s;\n", endlabelstr); - printf ("\t\t\t}\n"); - need_endlabel = 1; - } - irc2ir (); - fill_prefetch_1 (2); - returncycles ("\t\t\t", 12); - if (using_ce) - printf ("\t\t\treturn;\n"); - printf ("\t\t}\n"); - addcycles_ce020 (7); - printf ("\t} else {\n"); - addcycles000_2 ("\t\t", 2); - addcycles_ce020 (3); - printf ("\t}\n"); - setpc ("oldpc + %d", m68k_pc_offset); - m68k_pc_offset = 0; - fill_prefetch_full (); - insn_n_cycles = 12; - need_endlabel = 1; - break; - case i_Scc: - genamode (curi->smode, "srcreg", curi->size, "src", cpu_level == 0 ? 1 : 2, 0, 0); - start_brace (); - fill_prefetch_next(); - start_brace (); - printf ("\tint val = cctrue (%d) ? 0xff : 0;\n", curi->cc); - if (using_ce) { - printf ("\tint cycles = 0;\n"); - if (isreg (curi->smode)) - printf ("\tif (val) cycles += 2;\n"); - addcycles000_3 ("\t"); - } - genastore ("val", curi->smode, "srcreg", curi->size, "src"); - break; - case i_DIVU: - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (src == 0) {\n"); - if (cpu_level > 0) { - /* 68020 sets V when dividing by zero and N if dst is negative - * 68000 clears both - */ - printf("\t\tSET_VFLG (1);\n"); - printf("\t\tif (dst < 0) SET_NFLG (1);\n"); - } - incpc ("%d", m68k_pc_offset); - printf ("\t\tException (5, oldpc);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t} else {\n"); - printf ("\t\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n"); - printf ("\t\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n"); - fill_prefetch_next (); - if (using_ce) { - start_brace (); - printf ("\t\tint cycles = (getDivu68kCycles((uae_u32)dst, (uae_u16)src) - 4);\n"); - addcycles000_3 ("\t\t"); - } else if (using_ce020) { - addcycles_ce020 (40); - } - /* The N flag appears to be set each time there is an overflow. - * Weird. but 68020 only sets N when dst is negative.. */ - printf ("\t\tif (newv > 0xffff) {\n"); - printf ("\t\t\tSET_VFLG (1);\n"); + break; + case i_Scc: + genamode (curi->smode, "srcreg", curi->size, "src", cpu_level == 0 ? 1 : 2, 0, 0); + start_brace (); + fill_prefetch_next(); + start_brace (); + printf ("\tint val = cctrue (%d) ? 0xff : 0;\n", curi->cc); + if (using_ce) { + printf ("\tint cycles = 0;\n"); + if (isreg (curi->smode)) + printf ("\tif (val) cycles += 2;\n"); + addcycles000_3 ("\t"); + } + genastore ("val", curi->smode, "srcreg", curi->size, "src"); + break; + case i_DIVU: + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (src == 0) {\n"); + if (cpu_level > 0) { + /* 68020 sets V when dividing by zero and N if dst is negative + * 68000 clears both + */ + printf("\t\tSET_VFLG (1);\n"); + printf("\t\tif (dst < 0) SET_NFLG (1);\n"); + } + incpc ("%d", m68k_pc_offset); + printf ("\t\tException (5, oldpc);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t} else {\n"); + printf ("\t\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n"); + printf ("\t\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n"); + fill_prefetch_next (); + if (using_ce) { + start_brace (); + printf ("\t\tint cycles = (getDivu68kCycles((uae_u32)dst, (uae_u16)src) - 4);\n"); + addcycles000_3 ("\t\t"); + } else if (using_ce020) { + addcycles_ce020 (36); + } + /* The N flag appears to be set each time there is an overflow. + * Weird. but 68020 only sets N when dst is negative.. */ + printf ("\t\tif (newv > 0xffff) {\n"); + printf ("\t\t\tSET_VFLG (1);\n"); #ifdef UNDEF68020 - if (cpu_level >= 2) - printf ("\t\t\tif (currprefs.cpu_level == 0 || dst < 0) SET_NFLG (®s, 1);\n"); - else /* ??? some 68000 revisions may not set NFLG when overflow happens.. */ + if (cpu_level >= 2) + printf ("\t\t\tif (currprefs.cpu_level == 0 || dst < 0) SET_NFLG (®s, 1);\n"); + else /* ??? some 68000 revisions may not set NFLG when overflow happens.. */ #endif - printf ("\t\t\tSET_NFLG (1);\n"); - printf ("\t\t} else {\n"); - printf ("\t\t"); genflags (flag_logical, sz_word, "newv", "", ""); - printf ("\t\t\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); - printf ("\t\t"); genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - printf ("\t\t}\n"); - sync_m68k_pc (); - printf ("\t}\n"); - count_ncycles++; - insn_n_cycles += 136 - (136 - 76) / 2; /* average */ - need_endlabel = 1; - break; - case i_DIVS: - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (src == 0) {\n"); - if (cpu_level > 0) { - /* 68020 sets V when dividing by zero. Z is also set. - * 68000 clears both - */ - printf("\t\tSET_VFLG (1);\n"); - printf("\t\tSET_ZFLG (1);\n"); - } - incpc ("%d", m68k_pc_offset); - printf ("\t\tException (5, oldpc);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t} else {\n"); - printf ("\t\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n"); - printf ("\t\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n"); - fill_prefetch_next (); - if (using_ce) { - start_brace (); - printf ("\t\tint cycles = (getDivs68kCycles((uae_s32)dst, (uae_s16)src) - 4);\n"); - addcycles000_3 ("\t\t"); - } else if (using_ce020) { - addcycles_ce020 (50); - } - printf ("\t\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) {\n"); - printf ("\t\t\tSET_VFLG (1);\n"); + printf ("\t\t\tSET_NFLG (1);\n"); + printf ("\t\t} else {\n"); + printf ("\t\t"); genflags (flag_logical, sz_word, "newv", "", ""); + printf ("\t\t\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); + printf ("\t\t"); genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + printf ("\t\t}\n"); + sync_m68k_pc (); + printf ("\t}\n"); + count_ncycles++; + insn_n_cycles += 136 - (136 - 76) / 2; /* average */ + need_endlabel = 1; + break; + case i_DIVS: + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (src == 0) {\n"); + if (cpu_level > 0) { + /* 68020 sets V when dividing by zero. Z is also set. + * 68000 clears both + */ + printf("\t\tSET_VFLG (1);\n"); + printf("\t\tSET_ZFLG (1);\n"); + } + incpc ("%d", m68k_pc_offset); + printf ("\t\tException (5, oldpc);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t} else {\n"); + printf ("\t\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n"); + printf ("\t\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n"); + fill_prefetch_next (); + if (using_ce) { + start_brace (); + printf ("\t\tint cycles = (getDivs68kCycles((uae_s32)dst, (uae_s16)src) - 4);\n"); + addcycles000_3 ("\t\t"); + } else if (using_ce020) { + addcycles_ce020 (46); + } + printf ("\t\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) {\n"); + printf ("\t\t\tSET_VFLG (1);\n"); #ifdef UNDEF68020 - if (cpu_level > 0) - printf ("\t\t\tif (currprefs.cpu_level == 0) SET_NFLG (®s, 1);\n"); - else -#endif - printf ("\t\t\tSET_NFLG (1);\n"); - printf ("\t\t} else {\n"); - printf ("\t\t\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n"); - genflags (flag_logical, sz_word, "newv", "", ""); - printf ("\t\t\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); - printf ("\t\t"); genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - printf ("\t\t}\n"); - sync_m68k_pc (); - printf ("\t}\n"); - count_ncycles++; - insn_n_cycles += 156 - (156 - 120) / 2; /* average */ - need_endlabel = 1; - break; - case i_MULU: - genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n"); - if (using_ce) - printf ("\tint cycles = 38 - 4, bits;\n"); - genflags (flag_logical, sz_long, "newv", "", ""); - if (using_ce) { - printf ("\tfor(bits = 0; bits < 16 && src; bits++, src >>= 1)\n"); - printf ("\t\tif (src & 1) cycles += 2;\n"); - addcycles000_3 ("\t"); - } else if (using_ce020) { - addcycles_ce020 (20); - } - genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - sync_m68k_pc (); - count_cycles += 38 - 4; - count_ncycles++; - insn_n_cycles += (70 - 38) / 2 + 38; /* average */ - break; - case i_MULS: - genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n"); - if (using_ce) { - printf ("\tint cycles = 38 - 4, bits;\n"); - printf ("\tuae_u32 usrc;\n"); - } - genflags (flag_logical, sz_long, "newv", "", ""); - if (using_ce) { - printf ("\tusrc = ((uae_u32)src) << 1;\n"); - printf ("\tfor(bits = 0; bits < 16 && usrc; bits++, usrc >>= 1)\n"); - printf ("\t\tif ((usrc & 3) == 1 || (usrc & 3) == 2) cycles += 2;\n"); - addcycles000_3 ("\t"); - } else if (using_ce020) { - addcycles_ce020 (20); - } - genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); - count_cycles += 38 - 4; - count_ncycles++; - insn_n_cycles += (70 - 38) / 2 + 38; /* average */ - break; - case i_CHK: - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - sync_m68k_pc (); - addcycles000 (4); - printf ("\tif (dst > src) {\n"); - printf ("\t\tSET_NFLG (0);\n"); - printf ("\t\tException (6, oldpc);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - addcycles000 (2); - printf ("\tif ((uae_s32)dst < 0) {\n"); - printf ("\t\tSET_NFLG (1);\n"); - printf ("\t\tException (6, oldpc);\n"); - printf ("\t\tgoto %s;\n", endlabelstr); - printf ("\t}\n"); - fill_prefetch_next (); - need_endlabel = 1; - break; - case i_CHK2: - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); - fill_prefetch_0 (); - printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n"); - switch (curi->size) { - case sz_byte: - printf ("\tlower = (uae_s32)(uae_s8)%s (dsta); upper = (uae_s32)(uae_s8)%s (dsta + 1);\n", srcb, srcb); - printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n"); - break; - case sz_word: - printf ("\tlower = (uae_s32)(uae_s16)%s (dsta); upper = (uae_s32)(uae_s16)%s (dsta + 2);\n", srcw, srcw); - printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n"); - break; - case sz_long: - printf ("\tlower = %s (dsta); upper = %s (dsta + 4);\n", srcl, srcl); - break; - default: - abort (); - } - printf ("\tSET_ZFLG (upper == reg || lower == reg);\n"); - printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n"); - printf ("\tif ((extra & 0x800) && GET_CFLG ()) { Exception (6, oldpc); goto %s; }\n}\n", endlabelstr); - need_endlabel = 1; - break; - - case i_ASR: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1); - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); - printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size)); - printf ("\t\tSET_CFLG (sign);\n"); - duplicate_carry (1); - if (source_is_imm1_8 (curi)) - printf ("\t} else {\n"); - else - printf ("\t} else if (cnt > 0) {\n"); - printf ("\t\tval >>= cnt - 1;\n"); - printf ("\t\tSET_CFLG (val & 1);\n"); - duplicate_carry (1); - printf ("\t\tval >>= 1;\n"); - printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n", - bit_mask (curi->size), - bit_size (curi->size)); - printf ("\t\tval &= %s;\n", bit_mask (curi->size)); - printf ("\t}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ASL: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); - printf ("\t\tSET_VFLG (val != 0);\n"); - printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", - bit_size (curi->size)); - duplicate_carry (1); - printf ("\t\tval = 0;\n"); - if (source_is_imm1_8 (curi)) - printf ("\t} else {\n"); - else - printf ("\t} else if (cnt > 0) {\n"); - printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n", - bit_mask (curi->size), - bit_size (curi->size) - 1, - bit_mask (curi->size)); - printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n"); - printf ("\t\tval <<= cnt - 1;\n"); - printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); - duplicate_carry (1); - printf ("\t\tval <<= 1;\n"); - printf ("\t\tval &= %s;\n", bit_mask (curi->size)); - printf ("\t}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_LSR: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); - printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n", - bit_size (curi->size), bit_size (curi->size) - 1); - duplicate_carry (1); - printf ("\t\tval = 0;\n"); - if (source_is_imm1_8 (curi)) - printf ("\t} else {\n"); - else - printf ("\t} else if (cnt > 0) {\n"); - printf ("\t\tval >>= cnt - 1;\n"); - printf ("\t\tSET_CFLG (val & 1);\n"); - duplicate_carry (1); - printf ("\t\tval >>= 1;\n"); - printf ("\t}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_LSL: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next(); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); - printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", bit_size (curi->size)); - duplicate_carry (1); - printf ("\t\tval = 0;\n"); - if (source_is_imm1_8 (curi)) - printf ("\t} else {\n"); - else - printf ("\t} else if (cnt > 0) {\n"); - printf ("\t\tval <<= (cnt - 1);\n"); - printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); - duplicate_carry (1); - printf ("\t\tval <<= 1;\n"); - printf ("\tval &= %s;\n", bit_mask (curi->size)); - printf ("\t}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ROL: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - if (source_is_imm1_8 (curi)) - printf ("{"); - else - printf ("\tif (cnt > 0) {\n"); - printf ("\tuae_u32 loval;\n"); - printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); - printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size)); - printf ("\tval <<= cnt;\n"); - printf ("\tval |= loval;\n"); - printf ("\tval &= %s;\n", bit_mask (curi->size)); - printf ("\tSET_CFLG (val & 1);\n"); - printf ("}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ROR: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - if (source_is_imm1_8 (curi)) - printf ("{"); - else - printf ("\tif (cnt > 0) {"); - printf ("\tuae_u32 hival;\n"); - printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); - printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size)); - printf ("\tval >>= cnt;\n"); - printf ("\tval |= hival;\n"); - printf ("\tval &= %s;\n", bit_mask (curi->size)); - printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); - printf ("\t}\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ROXL: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - if (source_is_imm1_8 (curi)) - printf ("{"); - else { - force_range_for_rox ("cnt", curi->size); - printf ("\tif (cnt > 0) {\n"); - } - printf ("\tcnt--;\n"); - printf ("\t{\n\tuae_u32 carry;\n"); - printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1); - printf ("\tcarry = loval & 1;\n"); - printf ("\tval = (((val << 1) | GET_XFLG ()) << cnt) | (loval >> 1);\n"); - printf ("\tSET_XFLG (carry);\n"); - printf ("\tval &= %s;\n", bit_mask (curi->size)); - printf ("\t} }\n"); - printf ("\tSET_CFLG (GET_XFLG ());\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ROXR: - genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tint ccnt = cnt & 63;\n"); - printf ("\tcnt &= 63;\n"); - printf ("\tCLEAR_CZNV ();\n"); - if (source_is_imm1_8 (curi)) - printf ("{"); - else { - force_range_for_rox ("cnt", curi->size); - printf ("\tif (cnt > 0) {\n"); - } - printf ("\tcnt--;\n"); - printf ("\t{\n\tuae_u32 carry;\n"); - printf ("\tuae_u32 hival = (val << 1) | GET_XFLG ();\n"); - printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1); - printf ("\tval >>= cnt;\n"); - printf ("\tcarry = val & 1;\n"); - printf ("\tval >>= 1;\n"); - printf ("\tval |= hival;\n"); - printf ("\tSET_XFLG (carry);\n"); - printf ("\tval &= %s;\n", bit_mask (curi->size)); - printf ("\t} }\n"); - printf ("\tSET_CFLG (GET_XFLG ());\n"); - genflags (flag_logical_noclobber, curi->size, "val", "", ""); - shift_ce (curi->dmode, curi->size); - genastore ("val", curi->dmode, "dstreg", curi->size, "data"); - break; - case i_ASRW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); - printf ("\tuae_u32 cflg = val & 1;\n"); - printf ("\tval = (val >> 1) | sign;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (cflg);\n"); - duplicate_carry (0); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_ASLW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); - printf ("\tuae_u32 sign2;\n"); - printf ("\tval <<= 1;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tsign2 = %s & val;\n", cmask (curi->size)); - printf ("\tSET_CFLG (sign != 0);\n"); - duplicate_carry (0); - - printf ("\tSET_VFLG (GET_VFLG () | (sign2 != sign));\n"); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_LSRW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; - case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & 1;\n"); - printf ("\tval >>= 1;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry);\n"); - duplicate_carry (0); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_LSLW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u8 val = data;\n"); break; - case sz_word: printf ("\tuae_u16 val = data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); - printf ("\tval <<= 1;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); - duplicate_carry (0); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_ROLW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u8 val = data;\n"); break; - case sz_word: printf ("\tuae_u16 val = data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); - printf ("\tval <<= 1;\n"); - printf ("\tif (carry) val |= 1;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_RORW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u8 val = data;\n"); break; - case sz_word: printf ("\tuae_u16 val = data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & 1;\n"); - printf ("\tval >>= 1;\n"); - printf ("\tif (carry) val |= %s;\n", cmask (curi->size)); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry);\n"); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_ROXLW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u8 val = data;\n"); break; - case sz_word: printf ("\tuae_u16 val = data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); - printf ("\tval <<= 1;\n"); - printf ("\tif (GET_XFLG ()) val |= 1;\n"); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); - duplicate_carry (0); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_ROXRW: - genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - switch (curi->size) { - case sz_byte: printf ("\tuae_u8 val = data;\n"); break; - case sz_word: printf ("\tuae_u16 val = data;\n"); break; - case sz_long: printf ("\tuae_u32 val = data;\n"); break; - default: abort (); - } - printf ("\tuae_u32 carry = val & 1;\n"); - printf ("\tval >>= 1;\n"); - printf ("\tif (GET_XFLG ()) val |= %s;\n", cmask (curi->size)); - genflags (flag_logical, curi->size, "val", "", ""); - printf ("\tSET_CFLG (carry);\n"); - duplicate_carry (0); - genastore ("val", curi->smode, "srcreg", curi->size, "data"); - break; - case i_MOVEC2: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - printf ("\tint regno = (src >> 12) & 15;\n"); - printf ("\tuae_u32 *regp = regs.regs + regno;\n"); - printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr); - break; - case i_MOVE2C: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - fill_prefetch_next (); - start_brace (); - printf ("\tint regno = (src >> 12) & 15;\n"); - printf ("\tuae_u32 *regp = regs.regs + regno;\n"); - printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr); - break; - case i_CAS: - { - int old_brace_level; - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - fill_prefetch_0 (); - start_brace (); - printf ("\tint ru = (src >> 6) & 7;\n"); - printf ("\tint rc = src & 7;\n"); - genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, rc)", "dst"); - printf ("\tif (GET_ZFLG ())"); - old_brace_level = n_braces; - start_brace (); - genastore ("(m68k_dreg (regs, ru))", curi->dmode, "dstreg", curi->size, "dst"); - pop_braces (old_brace_level); - printf ("else"); - start_brace (); - printf ("m68k_dreg (regs, rc) = dst;\n"); - pop_braces (old_brace_level); - } - break; - case i_CAS2: - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n"); - printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n"); - if (curi->size == sz_word) { - int old_brace_level = n_braces; - printf ("\tuae_u16 dst1 = %s (rn1), dst2 = %s (rn2);\n", srcw, srcw); - genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, (extra >> 16) & 7)", "dst1"); - printf ("\tif (GET_ZFLG ()) {\n"); - genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, extra & 7)", "dst2"); - printf ("\tif (GET_ZFLG ()) {\n"); - printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 22) & 7));\n", dstw); - printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 6) & 7));\n", dstw); - printf ("\t}}\n"); - pop_braces (old_brace_level); - printf ("\tif (! GET_ZFLG ()) {\n"); - printf ("\tm68k_dreg (regs, (extra >> 22) & 7) = (m68k_dreg (regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n"); - printf ("\tm68k_dreg (regs, (extra >> 6) & 7) = (m68k_dreg (regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n"); - printf ("\t}\n"); - } else { - int old_brace_level = n_braces; - printf ("\tuae_u32 dst1 = %s (rn1), dst2 = %s (rn2);\n", srcl, srcl); - genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, (extra >> 16) & 7)", "dst1"); - printf ("\tif (GET_ZFLG ()) {\n"); - genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, extra & 7)", "dst2"); - printf ("\tif (GET_ZFLG ()) {\n"); - printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 22) & 7));\n", dstl); - printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 6) & 7));\n", dstl); - printf ("\t}}\n"); - pop_braces (old_brace_level); - printf ("\tif (! GET_ZFLG ()) {\n"); - printf ("\tm68k_dreg (regs, (extra >> 22) & 7) = dst1;\n"); - printf ("\tm68k_dreg (regs, (extra >> 6) & 7) = dst2;\n"); - printf ("\t}\n"); - } - break; - case i_MOVES: /* ignore DFC and SFC when using_mmu == false */ - { - int old_brace_level; - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - printf ("\tif (extra & 0x800)\n"); - { - int old_m68k_pc_offset = m68k_pc_offset; - old_brace_level = n_braces; - start_brace (); - printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n"); - genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); - genastore_fc ("src", curi->dmode, "dstreg", curi->size, "dst"); - pop_braces (old_brace_level); - m68k_pc_offset = old_m68k_pc_offset; - } - printf ("else"); - { - start_brace (); - genamode (curi->dmode, "dstreg", curi->size, "src", 1, 0, GF_FC); - printf ("\tif (extra & 0x8000) {\n"); - switch (curi->size) { - case sz_byte: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = (uae_s32)(uae_s8)src;\n"); break; - case sz_word: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = (uae_s32)(uae_s16)src;\n"); break; - case sz_long: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = src;\n"); break; - default: abort (); - } - printf ("\t} else {\n"); - genastore ("src", Dreg, "(extra >> 12) & 7", curi->size, ""); - printf ("\t}\n"); - sync_m68k_pc (); - pop_braces (old_brace_level); - } - } - break; - case i_BKPT: /* only needed for hardware emulators */ - sync_m68k_pc (); - printf ("\top_illg (opcode);\n"); - break; - case i_CALLM: /* not present in 68030 */ - sync_m68k_pc (); - printf ("\top_illg (opcode);\n"); - break; - case i_RTM: /* not present in 68030 */ - sync_m68k_pc (); - printf ("\top_illg (opcode);\n"); - break; - case i_TRAPcc: - if (curi->smode != am_unknown && curi->smode != am_illg) - genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0); - fill_prefetch_0 (); - printf ("\tif (cctrue (%d)) { Exception (7, m68k_getpc ()); goto %s; }\n", curi->cc, endlabelstr); - need_endlabel = 1; - break; - case i_DIVL: - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - if (using_ce020) { - addcycles_ce020 (70); - } - sync_m68k_pc (); - printf ("\tm68k_divl(opcode, dst, extra, oldpc);\n"); - break; - case i_MULL: - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); - if (using_ce020) { - addcycles_ce020 (40); - } - sync_m68k_pc (); - printf ("\tm68k_mull(opcode, dst, extra);\n"); - break; - case i_BFTST: - case i_BFEXTU: - case i_BFCHG: - case i_BFEXTS: - case i_BFCLR: - case i_BFFFO: - case i_BFSET: - case i_BFINS: - { - char *getb, *putb; - - if (using_mmu) { - getb = "get_bitfield_040mmu"; - putb = "put_bitfield_040mmu"; - } else if (using_ce020) { - getb = "get_bitfield_020ce"; - putb = "put_bitfield_020ce"; - } else { - getb = "get_bitfield"; - putb = "put_bitfield"; - } + if (cpu_level > 0) + printf ("\t\t\tif (currprefs.cpu_level == 0) SET_NFLG (®s, 1);\n"); + else +#endif + printf ("\t\t\tSET_NFLG (1);\n"); + printf ("\t\t} else {\n"); + printf ("\t\t\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n"); + genflags (flag_logical, sz_word, "newv", "", ""); + printf ("\t\t\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); + printf ("\t\t"); genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + printf ("\t\t}\n"); + sync_m68k_pc (); + printf ("\t}\n"); + count_ncycles++; + insn_n_cycles += 156 - (156 - 120) / 2; /* average */ + need_endlabel = 1; + break; + case i_MULU: + genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n"); + if (using_ce) + printf ("\tint cycles = 38 - 4, bits;\n"); + genflags (flag_logical, sz_long, "newv", "", ""); + if (using_ce) { + printf ("\tfor(bits = 0; bits < 16 && src; bits++, src >>= 1)\n"); + printf ("\t\tif (src & 1) cycles += 2;\n"); + addcycles000_3 ("\t"); + } else if (using_ce020) { + addcycles_ce020 (20); + } + genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + sync_m68k_pc (); + count_cycles += 38 - 4; + count_ncycles++; + insn_n_cycles += (70 - 38) / 2 + 38; /* average */ + break; + case i_MULS: + genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n"); + if (using_ce) { + printf ("\tint cycles = 38 - 4, bits;\n"); + printf ("\tuae_u32 usrc;\n"); + } + genflags (flag_logical, sz_long, "newv", "", ""); + if (using_ce) { + printf ("\tusrc = ((uae_u32)src) << 1;\n"); + printf ("\tfor(bits = 0; bits < 16 && usrc; bits++, usrc >>= 1)\n"); + printf ("\t\tif ((usrc & 3) == 1 || (usrc & 3) == 2) cycles += 2;\n"); + addcycles000_3 ("\t"); + } else if (using_ce020) { + addcycles_ce020 (20); + } + genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); + count_cycles += 38 - 4; + count_ncycles++; + insn_n_cycles += (70 - 38) / 2 + 38; /* average */ + break; + case i_CHK: + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + sync_m68k_pc (); + addcycles000 (4); + printf ("\tif (dst > src) {\n"); + printf ("\t\tSET_NFLG (0);\n"); + printf ("\t\tException (6, oldpc);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + addcycles000 (2); + printf ("\tif ((uae_s32)dst < 0) {\n"); + printf ("\t\tSET_NFLG (1);\n"); + printf ("\t\tException (6, oldpc);\n"); + printf ("\t\tgoto %s;\n", endlabelstr); + printf ("\t}\n"); + fill_prefetch_next (); + need_endlabel = 1; + break; + case i_CHK2: + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); + fill_prefetch_0 (); + printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n"); + switch (curi->size) { + case sz_byte: + printf ("\tlower = (uae_s32)(uae_s8)%s (dsta); upper = (uae_s32)(uae_s8)%s (dsta + 1);\n", srcb, srcb); + printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n"); + break; + case sz_word: + printf ("\tlower = (uae_s32)(uae_s16)%s (dsta); upper = (uae_s32)(uae_s16)%s (dsta + 2);\n", srcw, srcw); + printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n"); + break; + case sz_long: + printf ("\tlower = %s (dsta); upper = %s (dsta + 4);\n", srcl, srcl); + break; + default: + abort (); + } + printf ("\tSET_ZFLG (upper == reg || lower == reg);\n"); + printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n"); + printf ("\tif ((extra & 0x800) && GET_CFLG ()) { Exception (6, oldpc); goto %s; }\n}\n", endlabelstr); + need_endlabel = 1; + break; - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - genamode (curi->dmode, "dstreg", sz_long, "dst", 2, 0, 0); - start_brace (); - printf ("\tuae_u32 bdata[2];\n"); - printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n"); - printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n"); - if (curi->dmode == Dreg) { - printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg);\n"); - printf ("\toffset &= 0x1f;\n"); - printf ("\ttmp = (tmp << offset) | (tmp >> (32 - offset));\n"); - printf ("\tbdata[0] = tmp & ((1 << (32 - width)) - 1);\n"); - } else { - printf ("\tuae_u32 tmp;\n"); - printf ("\tdsta += offset >> 3;\n"); - printf ("\ttmp = %s (dsta, bdata, offset, width);\n", getb); - } - printf ("\tSET_NFLG_ALWAYS (((uae_s32)tmp) < 0 ? 1 : 0);\n"); - if (curi->mnemo == i_BFEXTS) - printf ("\ttmp = (uae_s32)tmp >> (32 - width);\n"); - else - printf ("\ttmp >>= (32 - width);\n"); - printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n"); - switch (curi->mnemo) { + case i_ASR: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1); + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); + printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size)); + printf ("\t\tSET_CFLG (sign);\n"); + duplicate_carry (1); + if (source_is_imm1_8 (curi)) + printf ("\t} else {\n"); + else + printf ("\t} else if (cnt > 0) {\n"); + printf ("\t\tval >>= cnt - 1;\n"); + printf ("\t\tSET_CFLG (val & 1);\n"); + duplicate_carry (1); + printf ("\t\tval >>= 1;\n"); + printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n", + bit_mask (curi->size), + bit_size (curi->size)); + printf ("\t\tval &= %s;\n", bit_mask (curi->size)); + printf ("\t}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ASL: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); + printf ("\t\tSET_VFLG (val != 0);\n"); + printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", + bit_size (curi->size)); + duplicate_carry (1); + printf ("\t\tval = 0;\n"); + if (source_is_imm1_8 (curi)) + printf ("\t} else {\n"); + else + printf ("\t} else if (cnt > 0) {\n"); + printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n", + bit_mask (curi->size), + bit_size (curi->size) - 1, + bit_mask (curi->size)); + printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n"); + printf ("\t\tval <<= cnt - 1;\n"); + printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); + duplicate_carry (1); + printf ("\t\tval <<= 1;\n"); + printf ("\t\tval &= %s;\n", bit_mask (curi->size)); + printf ("\t}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_LSR: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); + printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n", + bit_size (curi->size), bit_size (curi->size) - 1); + duplicate_carry (1); + printf ("\t\tval = 0;\n"); + if (source_is_imm1_8 (curi)) + printf ("\t} else {\n"); + else + printf ("\t} else if (cnt > 0) {\n"); + printf ("\t\tval >>= cnt - 1;\n"); + printf ("\t\tSET_CFLG (val & 1);\n"); + duplicate_carry (1); + printf ("\t\tval >>= 1;\n"); + printf ("\t}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_LSL: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next(); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); + printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", bit_size (curi->size)); + duplicate_carry (1); + printf ("\t\tval = 0;\n"); + if (source_is_imm1_8 (curi)) + printf ("\t} else {\n"); + else + printf ("\t} else if (cnt > 0) {\n"); + printf ("\t\tval <<= (cnt - 1);\n"); + printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); + duplicate_carry (1); + printf ("\t\tval <<= 1;\n"); + printf ("\tval &= %s;\n", bit_mask (curi->size)); + printf ("\t}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ROL: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + if (source_is_imm1_8 (curi)) + printf ("{"); + else + printf ("\tif (cnt > 0) {\n"); + printf ("\tuae_u32 loval;\n"); + printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); + printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size)); + printf ("\tval <<= cnt;\n"); + printf ("\tval |= loval;\n"); + printf ("\tval &= %s;\n", bit_mask (curi->size)); + printf ("\tSET_CFLG (val & 1);\n"); + printf ("}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ROR: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + if (source_is_imm1_8 (curi)) + printf ("{"); + else + printf ("\tif (cnt > 0) {"); + printf ("\tuae_u32 hival;\n"); + printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); + printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size)); + printf ("\tval >>= cnt;\n"); + printf ("\tval |= hival;\n"); + printf ("\tval &= %s;\n", bit_mask (curi->size)); + printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); + printf ("\t}\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ROXL: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + if (source_is_imm1_8 (curi)) + printf ("{"); + else { + force_range_for_rox ("cnt", curi->size); + printf ("\tif (cnt > 0) {\n"); + } + printf ("\tcnt--;\n"); + printf ("\t{\n\tuae_u32 carry;\n"); + printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1); + printf ("\tcarry = loval & 1;\n"); + printf ("\tval = (((val << 1) | GET_XFLG ()) << cnt) | (loval >> 1);\n"); + printf ("\tSET_XFLG (carry);\n"); + printf ("\tval &= %s;\n", bit_mask (curi->size)); + printf ("\t} }\n"); + printf ("\tSET_CFLG (GET_XFLG ());\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ROXR: + genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tint ccnt = cnt & 63;\n"); + printf ("\tcnt &= 63;\n"); + printf ("\tCLEAR_CZNV ();\n"); + if (source_is_imm1_8 (curi)) + printf ("{"); + else { + force_range_for_rox ("cnt", curi->size); + printf ("\tif (cnt > 0) {\n"); + } + printf ("\tcnt--;\n"); + printf ("\t{\n\tuae_u32 carry;\n"); + printf ("\tuae_u32 hival = (val << 1) | GET_XFLG ();\n"); + printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1); + printf ("\tval >>= cnt;\n"); + printf ("\tcarry = val & 1;\n"); + printf ("\tval >>= 1;\n"); + printf ("\tval |= hival;\n"); + printf ("\tSET_XFLG (carry);\n"); + printf ("\tval &= %s;\n", bit_mask (curi->size)); + printf ("\t} }\n"); + printf ("\tSET_CFLG (GET_XFLG ());\n"); + genflags (flag_logical_noclobber, curi->size, "val", "", ""); + shift_ce (curi->dmode, curi->size); + genastore ("val", curi->dmode, "dstreg", curi->size, "data"); + break; + case i_ASRW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); + printf ("\tuae_u32 cflg = val & 1;\n"); + printf ("\tval = (val >> 1) | sign;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (cflg);\n"); + duplicate_carry (0); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_ASLW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); + printf ("\tuae_u32 sign2;\n"); + printf ("\tval <<= 1;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tsign2 = %s & val;\n", cmask (curi->size)); + printf ("\tSET_CFLG (sign != 0);\n"); + duplicate_carry (0); + + printf ("\tSET_VFLG (GET_VFLG () | (sign2 != sign));\n"); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_LSRW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; + case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & 1;\n"); + printf ("\tval >>= 1;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry);\n"); + duplicate_carry (0); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_LSLW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u8 val = data;\n"); break; + case sz_word: printf ("\tuae_u16 val = data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); + printf ("\tval <<= 1;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); + duplicate_carry (0); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_ROLW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u8 val = data;\n"); break; + case sz_word: printf ("\tuae_u16 val = data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); + printf ("\tval <<= 1;\n"); + printf ("\tif (carry) val |= 1;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_RORW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u8 val = data;\n"); break; + case sz_word: printf ("\tuae_u16 val = data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & 1;\n"); + printf ("\tval >>= 1;\n"); + printf ("\tif (carry) val |= %s;\n", cmask (curi->size)); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry);\n"); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_ROXLW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u8 val = data;\n"); break; + case sz_word: printf ("\tuae_u16 val = data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); + printf ("\tval <<= 1;\n"); + printf ("\tif (GET_XFLG ()) val |= 1;\n"); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); + duplicate_carry (0); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_ROXRW: + genamode (curi->smode, "srcreg", curi->size, "data", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + switch (curi->size) { + case sz_byte: printf ("\tuae_u8 val = data;\n"); break; + case sz_word: printf ("\tuae_u16 val = data;\n"); break; + case sz_long: printf ("\tuae_u32 val = data;\n"); break; + default: abort (); + } + printf ("\tuae_u32 carry = val & 1;\n"); + printf ("\tval >>= 1;\n"); + printf ("\tif (GET_XFLG ()) val |= %s;\n", cmask (curi->size)); + genflags (flag_logical, curi->size, "val", "", ""); + printf ("\tSET_CFLG (carry);\n"); + duplicate_carry (0); + genastore ("val", curi->smode, "srcreg", curi->size, "data"); + break; + case i_MOVEC2: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + printf ("\tint regno = (src >> 12) & 15;\n"); + printf ("\tuae_u32 *regp = regs.regs + regno;\n"); + printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr); + break; + case i_MOVE2C: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + fill_prefetch_next (); + start_brace (); + printf ("\tint regno = (src >> 12) & 15;\n"); + printf ("\tuae_u32 *regp = regs.regs + regno;\n"); + printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr); + break; + case i_CAS: + { + int old_brace_level; + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + fill_prefetch_0 (); + start_brace (); + printf ("\tint ru = (src >> 6) & 7;\n"); + printf ("\tint rc = src & 7;\n"); + genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, rc)", "dst"); + printf ("\tif (GET_ZFLG ())"); + old_brace_level = n_braces; + start_brace (); + genastore ("(m68k_dreg (regs, ru))", curi->dmode, "dstreg", curi->size, "dst"); + pop_braces (old_brace_level); + printf ("else"); + start_brace (); + printf ("m68k_dreg (regs, rc) = dst;\n"); + pop_braces (old_brace_level); + } + break; + case i_CAS2: + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n"); + printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n"); + if (curi->size == sz_word) { + int old_brace_level = n_braces; + printf ("\tuae_u16 dst1 = %s (rn1), dst2 = %s (rn2);\n", srcw, srcw); + genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, (extra >> 16) & 7)", "dst1"); + printf ("\tif (GET_ZFLG ()) {\n"); + genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, extra & 7)", "dst2"); + printf ("\tif (GET_ZFLG ()) {\n"); + printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 22) & 7));\n", dstw); + printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 6) & 7));\n", dstw); + printf ("\t}}\n"); + pop_braces (old_brace_level); + printf ("\tif (! GET_ZFLG ()) {\n"); + printf ("\tm68k_dreg (regs, (extra >> 22) & 7) = (m68k_dreg (regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n"); + printf ("\tm68k_dreg (regs, (extra >> 6) & 7) = (m68k_dreg (regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n"); + printf ("\t}\n"); + } else { + int old_brace_level = n_braces; + printf ("\tuae_u32 dst1 = %s (rn1), dst2 = %s (rn2);\n", srcl, srcl); + genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, (extra >> 16) & 7)", "dst1"); + printf ("\tif (GET_ZFLG ()) {\n"); + genflags (flag_cmp, curi->size, "newv", "m68k_dreg (regs, extra & 7)", "dst2"); + printf ("\tif (GET_ZFLG ()) {\n"); + printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 22) & 7));\n", dstl); + printf ("\t%s (rn1, m68k_dreg (regs, (extra >> 6) & 7));\n", dstl); + printf ("\t}}\n"); + pop_braces (old_brace_level); + printf ("\tif (! GET_ZFLG ()) {\n"); + printf ("\tm68k_dreg (regs, (extra >> 22) & 7) = dst1;\n"); + printf ("\tm68k_dreg (regs, (extra >> 6) & 7) = dst2;\n"); + printf ("\t}\n"); + } + break; + case i_MOVES: /* ignore DFC and SFC when using_mmu == false */ + { + int old_brace_level; + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + printf ("\tif (extra & 0x800)\n"); + { + int old_m68k_pc_offset = m68k_pc_offset; + old_brace_level = n_braces; + start_brace (); + printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n"); + genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0); + genastore_fc ("src", curi->dmode, "dstreg", curi->size, "dst"); + pop_braces (old_brace_level); + m68k_pc_offset = old_m68k_pc_offset; + } + printf ("else"); + { + start_brace (); + genamode (curi->dmode, "dstreg", curi->size, "src", 1, 0, GF_FC); + printf ("\tif (extra & 0x8000) {\n"); + switch (curi->size) { + case sz_byte: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = (uae_s32)(uae_s8)src;\n"); break; + case sz_word: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = (uae_s32)(uae_s16)src;\n"); break; + case sz_long: printf ("\tm68k_areg (regs, (extra >> 12) & 7) = src;\n"); break; + default: abort (); + } + printf ("\t} else {\n"); + genastore ("src", Dreg, "(extra >> 12) & 7", curi->size, ""); + printf ("\t}\n"); + sync_m68k_pc (); + pop_braces (old_brace_level); + } + } + break; + case i_BKPT: /* only needed for hardware emulators */ + sync_m68k_pc (); + printf ("\top_illg (opcode);\n"); + break; + case i_CALLM: /* not present in 68030 */ + sync_m68k_pc (); + printf ("\top_illg (opcode);\n"); + break; + case i_RTM: /* not present in 68030 */ + sync_m68k_pc (); + printf ("\top_illg (opcode);\n"); + break; + case i_TRAPcc: + if (curi->smode != am_unknown && curi->smode != am_illg) + genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0); + fill_prefetch_0 (); + printf ("\tif (cctrue (%d)) { Exception (7, m68k_getpc ()); goto %s; }\n", curi->cc, endlabelstr); + need_endlabel = 1; + break; + case i_DIVL: + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + if (using_ce020) { + addcycles_ce020 (70); + } + sync_m68k_pc (); + printf ("\tm68k_divl(opcode, dst, extra, oldpc);\n"); + break; + case i_MULL: + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0); + if (using_ce020) { + addcycles_ce020 (40); + } + sync_m68k_pc (); + printf ("\tm68k_mull(opcode, dst, extra);\n"); + break; case i_BFTST: - break; case i_BFEXTU: - case i_BFEXTS: - printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = tmp;\n"); - break; case i_BFCHG: - printf ("\ttmp = tmp ^ (0xffffffffu >> (32 - width));\n"); - break; + case i_BFEXTS: case i_BFCLR: - printf ("\ttmp = 0;\n"); - break; case i_BFFFO: - printf ("\t{ uae_u32 mask = 1 << (width - 1);\n"); - printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n"); - printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = offset;\n"); - break; case i_BFSET: - printf ("\ttmp = 0xffffffffu >> (32 - width);\n"); - break; case i_BFINS: - printf ("\ttmp = m68k_dreg (regs, (extra >> 12) & 7);\n"); - printf ("\ttmp = tmp & (0xffffffffu >> (32 - width));\n"); - printf ("\tSET_NFLG (tmp & (1 << (width - 1)) ? 1 : 0);\n"); - printf ("\tSET_ZFLG (tmp == 0);\n"); - break; + { + char *getb, *putb; + + if (using_mmu) { + getb = "get_bitfield_040mmu"; + putb = "put_bitfield_040mmu"; + } else if (using_ce020) { + getb = "get_bitfield_020ce"; + putb = "put_bitfield_020ce"; + } else { + getb = "get_bitfield"; + putb = "put_bitfield"; + } + + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + genamode (curi->dmode, "dstreg", sz_long, "dst", 2, 0, 0); + start_brace (); + printf ("\tuae_u32 bdata[2];\n"); + printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n"); + printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n"); + if (curi->dmode == Dreg) { + printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg);\n"); + printf ("\toffset &= 0x1f;\n"); + printf ("\ttmp = (tmp << offset) | (tmp >> (32 - offset));\n"); + printf ("\tbdata[0] = tmp & ((1 << (32 - width)) - 1);\n"); + } else { + printf ("\tuae_u32 tmp;\n"); + printf ("\tdsta += offset >> 3;\n"); + printf ("\ttmp = %s (dsta, bdata, offset, width);\n", getb); + } + printf ("\tSET_NFLG_ALWAYS (((uae_s32)tmp) < 0 ? 1 : 0);\n"); + if (curi->mnemo == i_BFEXTS) + printf ("\ttmp = (uae_s32)tmp >> (32 - width);\n"); + else + printf ("\ttmp >>= (32 - width);\n"); + printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n"); + switch (curi->mnemo) { + case i_BFTST: + break; + case i_BFEXTU: + case i_BFEXTS: + printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = tmp;\n"); + break; + case i_BFCHG: + printf ("\ttmp = tmp ^ (0xffffffffu >> (32 - width));\n"); + break; + case i_BFCLR: + printf ("\ttmp = 0;\n"); + break; + case i_BFFFO: + printf ("\t{ uae_u32 mask = 1 << (width - 1);\n"); + printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n"); + printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = offset;\n"); + break; + case i_BFSET: + printf ("\ttmp = 0xffffffffu >> (32 - width);\n"); + break; + case i_BFINS: + printf ("\ttmp = m68k_dreg (regs, (extra >> 12) & 7);\n"); + printf ("\ttmp = tmp & (0xffffffffu >> (32 - width));\n"); + printf ("\tSET_NFLG (tmp & (1 << (width - 1)) ? 1 : 0);\n"); + printf ("\tSET_ZFLG (tmp == 0);\n"); + break; + default: + break; + } + if (curi->mnemo == i_BFCHG + || curi->mnemo == i_BFCLR + || curi->mnemo == i_BFSET + || curi->mnemo == i_BFINS) { + if (curi->dmode == Dreg) { + printf ("\ttmp = bdata[0] | (tmp << (32 - width));\n"); + printf ("\tm68k_dreg(regs, dstreg) = (tmp >> offset) | (tmp << (32 - offset));\n"); + } else { + printf ("\t%s(dsta, bdata, tmp, offset, width);\n", putb); + } + } + } + break; + case i_PACK: + if (curi->smode == Dreg) { + printf ("\tuae_u16 val = m68k_dreg (regs, srcreg) + %s;\n", gen_nextiword (0)); + printf ("\tm68k_dreg (regs, dstreg) = (m68k_dreg (regs, dstreg) & 0xffffff00) | ((val >> 4) & 0xf0) | (val & 0xf);\n"); + } else { + printf ("\tuae_u16 val;\n"); + printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); + printf ("\tval = (uae_u16)%s (m68k_areg (regs, srcreg));\n", srcb); + printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); + printf ("\tval = (val | ((uae_u16)%s (m68k_areg (regs, srcreg)) << 8)) + %s;\n", srcb, gen_nextiword (0)); + printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); + gen_set_fault_pc (); + printf ("\t%s (m68k_areg (regs, dstreg),((val >> 4) & 0xf0) | (val & 0xf));\n", dstb); + } + break; + case i_UNPK: + if (curi->smode == Dreg) { + printf ("\tuae_u16 val = m68k_dreg (regs, srcreg);\n"); + printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword (0)); + printf ("\tm68k_dreg (regs, dstreg) = (m68k_dreg (regs, dstreg) & 0xffff0000) | (val & 0xffff);\n"); + } else { + printf ("\tuae_u16 val;\n"); + printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); + printf ("\tval = (uae_u16)%s (m68k_areg (regs, srcreg));\n", srcb); + printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword (0)); + if (cpu_level >= 2) { + printf ("\tm68k_areg (regs, dstreg) -= 2 * areg_byteinc[dstreg];\n"); + printf ("\t%s (m68k_areg (regs, dstreg) + areg_byteinc[dstreg], val);\n", dstb); + printf ("\t%s (m68k_areg (regs, dstreg), val >> 8);\n", dstb); + } else { + printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); + printf ("\t%s (m68k_areg (regs, dstreg),val);\n", dstb); + printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); + gen_set_fault_pc (); + printf ("\t%s (m68k_areg (regs, dstreg),val >> 8);\n", dstb); + } + } + break; + case i_TAS: + genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); + genflags (flag_logical, curi->size, "src", "", ""); + if (!isreg (curi->smode)) + addcycles000 (2); + fill_prefetch_next (); + printf ("\tsrc |= 0x80;\n"); + if (cpu_level >= 2 || curi->smode == Dreg || !using_ce) { + if (next_cpu_level < 2) + next_cpu_level = 2 - 1; + genastore ("src", curi->smode, "srcreg", curi->size, "src"); + } else { + printf ("\tif (!is_cycle_ce ()) {\n"); + genastore ("src", curi->smode, "srcreg", curi->size, "src"); + printf ("\t} else {\n"); + printf ("\t\tdo_cycles_ce000 (4);\n"); + printf ("\t}\n"); + } + break; + case i_FPP: + fpulimit(); + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + sync_m68k_pc (); + printf ("\tfpuop_arithmetic(opcode, extra);\n"); + break; + case i_FDBcc: + fpulimit(); + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + sync_m68k_pc (); + printf ("\tfpuop_dbcc (opcode, extra);\n"); + break; + case i_FScc: + fpulimit(); + genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); + sync_m68k_pc (); + printf ("\tfpuop_scc (opcode, extra);\n"); + break; + case i_FTRAPcc: + fpulimit(); + printf ("\tuaecptr oldpc = m68k_getpc ();\n"); + printf ("\tuae_u16 extra = %s;\n", gen_nextiword (0)); + if (curi->smode != am_unknown && curi->smode != am_illg) + genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0); + sync_m68k_pc (); + printf ("\tfpuop_trapcc (opcode, oldpc, extra);\n"); + break; + case i_FBcc: + fpulimit(); + sync_m68k_pc (); + start_brace (); + printf ("\tuaecptr pc = m68k_getpc ();\n"); + genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0, 0); + sync_m68k_pc (); + printf ("\tfpuop_bcc (opcode, pc,extra);\n"); + break; + case i_FSAVE: + fpulimit(); + sync_m68k_pc (); + printf ("\tfpuop_save (opcode);\n"); + break; + case i_FRESTORE: + fpulimit(); + sync_m68k_pc (); + printf ("\tfpuop_restore (opcode);\n"); + break; + + case i_CINVL: + case i_CINVP: + case i_CINVA: + case i_CPUSHL: + case i_CPUSHP: + case i_CPUSHA: + if (using_mmu) + printf ("\tflush_mmu(m68k_areg (regs, opcode & 3), (opcode >> 6) & 3);\n"); + printf ("\tif (opcode & 0x80)\n"); + printf ("\t\tflush_icache(m68k_areg (regs, opcode & 3), (opcode >> 6) & 3);\n"); + break; + + case i_MOVE16: + { + if ((opcode & 0xfff8) == 0xf620) { + /* MOVE16 (Ax)+,(Ay)+ */ + printf ("\tuae_u32 v1, v2, v3, v4;\n"); + printf ("\tuaecptr mems = m68k_areg (regs, srcreg) & ~15, memd;\n"); + printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword (0)); + printf ("\tmemd = m68k_areg (regs, dstreg) & ~15;\n"); + printf ("\tv1 = %s (mems);\n", srcl); + printf ("\tv2 = %s (mems + 4);\n", srcl); + printf ("\tv3 = %s (mems + 8);\n", srcl); + printf ("\tv4 = %s (mems + 12);\n", srcl); + printf ("\t%s (memd , v1);\n", dstl); + printf ("\t%s (memd + 4, v2);\n", dstl); + printf ("\t%s (memd + 8, v3);\n", dstl); + printf ("\t%s (memd + 12, v4);\n", dstl); + printf ("\tif (srcreg != dstreg)\n"); + printf ("\t\tm68k_areg (regs, srcreg) += 16;\n"); + printf ("\tm68k_areg (regs, dstreg) += 16;\n"); + } else { + /* Other variants */ + printf ("\tuae_u32 v1, v2, v3, v4;\n"); + genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2, 0); + genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2, 0); + printf ("\tmemsa &= ~15;\n"); + printf ("\tmemda &= ~15;\n"); + printf ("\tv1 = %s (memsa);\n", srcl); + printf ("\tv2 = %s (memsa + 4);\n", srcl); + printf ("\tv3 = %s (memsa + 8);\n", srcl); + printf ("\tv4 = %s (memsa + 12);\n", srcl); + printf ("\t%s (memda , v1);\n", dstl); + printf ("\t%s (memda + 4, v2);\n", dstl); + printf ("\t%s (memda + 8, v3);\n", dstl); + printf ("\t%s (memda + 12, v4);\n", dstl); + if ((opcode & 0xfff8) == 0xf600) + printf ("\tm68k_areg (regs, srcreg) += 16;\n"); + else if ((opcode & 0xfff8) == 0xf608) + printf ("\tm68k_areg (regs, dstreg) += 16;\n"); + } + } + break; + + case i_PFLUSHN: + case i_PFLUSH: + case i_PFLUSHAN: + case i_PFLUSHA: + case i_PLPAR: + case i_PLPAW: + case i_PTESTR: + case i_PTESTW: + sync_m68k_pc (); + printf ("\tmmu_op (opcode, 0);\n"); + break; + case i_MMUOP030: + printf ("\tuaecptr pc = m68k_getpc ();\n"); + printf ("\tuae_u16 extra = get_word (pc + 2);\n"); + m68k_pc_offset += 2; + sync_m68k_pc (); + if (curi->smode == Areg || curi->smode == Dreg) + printf("\tuae_u16 extraa = 0;\n"); + else + genamode (curi->smode, "srcreg", curi->size, "extra", 0, 0, 0); + sync_m68k_pc (); + printf ("\tmmu_op30 (pc, opcode, extra, extraa);\n"); + break; default: - break; - } - if (curi->mnemo == i_BFCHG - || curi->mnemo == i_BFCLR - || curi->mnemo == i_BFSET - || curi->mnemo == i_BFINS) { - if (curi->dmode == Dreg) { - printf ("\ttmp = bdata[0] | (tmp << (32 - width));\n"); - printf ("\tm68k_dreg(regs, dstreg) = (tmp >> offset) | (tmp << (32 - offset));\n"); - } else { - printf ("\t%s(dsta, bdata, tmp, offset, width);\n", putb); - } - } - } - break; - case i_PACK: - if (curi->smode == Dreg) { - printf ("\tuae_u16 val = m68k_dreg (regs, srcreg) + %s;\n", gen_nextiword (0)); - printf ("\tm68k_dreg (regs, dstreg) = (m68k_dreg (regs, dstreg) & 0xffffff00) | ((val >> 4) & 0xf0) | (val & 0xf);\n"); - } else { - printf ("\tuae_u16 val;\n"); - printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); - printf ("\tval = (uae_u16)%s (m68k_areg (regs, srcreg));\n", srcb); - printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); - printf ("\tval = (val | ((uae_u16)%s (m68k_areg (regs, srcreg)) << 8)) + %s;\n", srcb, gen_nextiword (0)); - printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); - gen_set_fault_pc (); - printf ("\t%s (m68k_areg (regs, dstreg),((val >> 4) & 0xf0) | (val & 0xf));\n", dstb); - } - break; - case i_UNPK: - if (curi->smode == Dreg) { - printf ("\tuae_u16 val = m68k_dreg (regs, srcreg);\n"); - printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword (0)); - printf ("\tm68k_dreg (regs, dstreg) = (m68k_dreg (regs, dstreg) & 0xffff0000) | (val & 0xffff);\n"); - } else { - printf ("\tuae_u16 val;\n"); - printf ("\tm68k_areg (regs, srcreg) -= areg_byteinc[srcreg];\n"); - printf ("\tval = (uae_u16)%s (m68k_areg (regs, srcreg));\n", srcb); - printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword (0)); - if (cpu_level >= 2) { - printf ("\tm68k_areg (regs, dstreg) -= 2 * areg_byteinc[dstreg];\n"); - printf ("\t%s (m68k_areg (regs, dstreg) + areg_byteinc[dstreg], val);\n", dstb); - printf ("\t%s (m68k_areg (regs, dstreg), val >> 8);\n", dstb); - } else { - printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); - printf ("\t%s (m68k_areg (regs, dstreg),val);\n", dstb); - printf ("\tm68k_areg (regs, dstreg) -= areg_byteinc[dstreg];\n"); - gen_set_fault_pc (); - printf ("\t%s (m68k_areg (regs, dstreg),val >> 8);\n", dstb); - } - } - break; - case i_TAS: - genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0); - genflags (flag_logical, curi->size, "src", "", ""); - if (!isreg (curi->smode)) - addcycles000 (2); - fill_prefetch_next (); - printf ("\tsrc |= 0x80;\n"); - if (cpu_level >= 2 || curi->smode == Dreg || !using_ce) { - if (next_cpu_level < 2) - next_cpu_level = 2 - 1; - genastore ("src", curi->smode, "srcreg", curi->size, "src"); - } else { - printf ("\tif (!is_cycle_ce ()) {\n"); - genastore ("src", curi->smode, "srcreg", curi->size, "src"); - printf ("\t} else {\n"); - printf ("\t\tdo_cycles_ce000 (4);\n"); - printf ("\t}\n"); - } - break; - case i_FPP: - fpulimit(); - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - sync_m68k_pc (); - printf ("\tfpuop_arithmetic(opcode, extra);\n"); - break; - case i_FDBcc: - fpulimit(); - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - sync_m68k_pc (); - printf ("\tfpuop_dbcc (opcode, extra);\n"); - break; - case i_FScc: - fpulimit(); - genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0); - sync_m68k_pc (); - printf ("\tfpuop_scc (opcode, extra);\n"); - break; - case i_FTRAPcc: - fpulimit(); - printf ("\tuaecptr oldpc = m68k_getpc ();\n"); - printf ("\tuae_u16 extra = %s;\n", gen_nextiword (0)); - if (curi->smode != am_unknown && curi->smode != am_illg) - genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0); - sync_m68k_pc (); - printf ("\tfpuop_trapcc (opcode, oldpc, extra);\n"); - break; - case i_FBcc: - fpulimit(); - sync_m68k_pc (); - start_brace (); - printf ("\tuaecptr pc = m68k_getpc ();\n"); - genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0, 0); - sync_m68k_pc (); - printf ("\tfpuop_bcc (opcode, pc,extra);\n"); - break; - case i_FSAVE: - fpulimit(); - sync_m68k_pc (); - printf ("\tfpuop_save (opcode);\n"); - break; - case i_FRESTORE: - fpulimit(); - sync_m68k_pc (); - printf ("\tfpuop_restore (opcode);\n"); - break; - - case i_CINVL: - case i_CINVP: - case i_CINVA: - case i_CPUSHL: - case i_CPUSHP: - case i_CPUSHA: - if (using_mmu) - printf ("\tflush_mmu(m68k_areg (regs, opcode & 3), (opcode >> 6) & 3);\n"); - printf ("\tif (opcode & 0x80)\n"); - printf ("\t\tflush_icache(m68k_areg (regs, opcode & 3), (opcode >> 6) & 3);\n"); - break; - - case i_MOVE16: - { - if ((opcode & 0xfff8) == 0xf620) { - /* MOVE16 (Ax)+,(Ay)+ */ - printf ("\tuae_u32 v1, v2, v3, v4;\n"); - printf ("\tuaecptr mems = m68k_areg (regs, srcreg) & ~15, memd;\n"); - printf ("\tdstreg = (%s >> 12) & 7;\n", gen_nextiword (0)); - printf ("\tmemd = m68k_areg (regs, dstreg) & ~15;\n"); - printf ("\tv1 = %s (mems);\n", srcl); - printf ("\tv2 = %s (mems + 4);\n", srcl); - printf ("\tv3 = %s (mems + 8);\n", srcl); - printf ("\tv4 = %s (mems + 12);\n", srcl); - printf ("\t%s (memd , v1);\n", dstl); - printf ("\t%s (memd + 4, v2);\n", dstl); - printf ("\t%s (memd + 8, v3);\n", dstl); - printf ("\t%s (memd + 12, v4);\n", dstl); - printf ("\tif (srcreg != dstreg)\n"); - printf ("\t\tm68k_areg (regs, srcreg) += 16;\n"); - printf ("\tm68k_areg (regs, dstreg) += 16;\n"); - } else { - /* Other variants */ - printf ("\tuae_u32 v1, v2, v3, v4;\n"); - genamode (curi->smode, "srcreg", curi->size, "mems", 0, 2, 0); - genamode (curi->dmode, "dstreg", curi->size, "memd", 0, 2, 0); - printf ("\tmemsa &= ~15;\n"); - printf ("\tmemda &= ~15;\n"); - printf ("\tv1 = %s (memsa);\n", srcl); - printf ("\tv2 = %s (memsa + 4);\n", srcl); - printf ("\tv3 = %s (memsa + 8);\n", srcl); - printf ("\tv4 = %s (memsa + 12);\n", srcl); - printf ("\t%s (memda , v1);\n", dstl); - printf ("\t%s (memda + 4, v2);\n", dstl); - printf ("\t%s (memda + 8, v3);\n", dstl); - printf ("\t%s (memda + 12, v4);\n", dstl); - if ((opcode & 0xfff8) == 0xf600) - printf ("\tm68k_areg (regs, srcreg) += 16;\n"); - else if ((opcode & 0xfff8) == 0xf608) - printf ("\tm68k_areg (regs, dstreg) += 16;\n"); + abort (); + break; } - } - break; - - case i_PFLUSHN: - case i_PFLUSH: - case i_PFLUSHAN: - case i_PFLUSHA: - case i_PLPAR: - case i_PLPAW: - case i_PTESTR: - case i_PTESTW: - sync_m68k_pc (); - printf ("\tmmu_op (opcode, 0);\n"); - break; - case i_MMUOP030: - printf ("\tuaecptr pc = m68k_getpc ();\n"); - printf ("\tuae_u16 extra = get_word (pc + 2);\n"); - m68k_pc_offset += 2; - sync_m68k_pc (); - if (curi->smode == Areg || curi->smode == Dreg) - printf("\tuae_u16 extraa = 0;\n"); - else - genamode (curi->smode, "srcreg", curi->size, "extra", 0, 0, 0); - sync_m68k_pc (); - printf ("\tmmu_op30 (pc, opcode, extra, extraa);\n"); - break; - default: - abort (); - break; - } - finish_braces (); - if (limit_braces) { - printf ("\n#endif\n"); - n_braces = limit_braces; - limit_braces = 0; finish_braces (); - } - if (did_prefetch >= 0) - fill_prefetch_finish (); - if (insn_n_cycles020 > 0) - addcycles_ce020 (insn_n_cycles020 + 1); - sync_m68k_pc (); - did_prefetch = 0; + if (limit_braces) { + printf ("\n#endif\n"); + n_braces = limit_braces; + limit_braces = 0; + finish_braces (); + } + if (did_prefetch >= 0) + fill_prefetch_finish (); + if (!count_cycles) + addcycles_ce020 (2); + sync_m68k_pc (); + did_prefetch = 0; } static void generate_includes (FILE * f) { - fprintf (f, "#include \"sysconfig.h\"\n"); - fprintf (f, "#include \"sysdeps.h\"\n"); - fprintf (f, "#include \"options.h\"\n"); - fprintf (f, "#include \"memory.h\"\n"); - fprintf (f, "#include \"custom.h\"\n"); - fprintf (f, "#include \"events.h\"\n"); - fprintf (f, "#include \"newcpu.h\"\n"); - fprintf (f, "#include \"cpu_prefetch.h\"\n"); - fprintf (f, "#include \"cputbl.h\"\n"); - fprintf (f, "#include \"cpummu.h\"\n"); - - - fprintf (f, "#define CPUFUNC(x) x##_ff\n" - "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n" - "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n" - "#ifdef NOFLAGS\n" - "#include \"noflags.h\"\n" - "#endif\n"); + fprintf (f, "#include \"sysconfig.h\"\n"); + fprintf (f, "#include \"sysdeps.h\"\n"); + fprintf (f, "#include \"options.h\"\n"); + fprintf (f, "#include \"memory.h\"\n"); + fprintf (f, "#include \"custom.h\"\n"); + fprintf (f, "#include \"events.h\"\n"); + fprintf (f, "#include \"newcpu.h\"\n"); + fprintf (f, "#include \"cpu_prefetch.h\"\n"); + fprintf (f, "#include \"cputbl.h\"\n"); + fprintf (f, "#include \"cpummu.h\"\n"); + + + fprintf (f, "#define CPUFUNC(x) x##_ff\n" + "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n" + "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n" + "#ifdef NOFLAGS\n" + "#include \"noflags.h\"\n" + "#endif\n"); } static int postfix; @@ -3402,258 +3398,258 @@ static int postfix; static char *decodeEA (amodes mode, wordsizes size) { - static char buffer[80]; - - buffer[0] = 0; - switch (mode){ - case Dreg: - strcpy (buffer,"Dn"); - break; - case Areg: - strcpy (buffer,"An"); - break; - case Aind: - strcpy (buffer,"(An)"); - break; - case Aipi: - strcpy (buffer,"(An)+"); - break; - case Apdi: - strcpy (buffer,"-(An)"); - break; - case Ad16: - strcpy (buffer,"(d16,An)"); - break; - case Ad8r: - strcpy (buffer,"(d8,An,Xn)"); - break; - case PC16: - strcpy (buffer,"(d16,PC)"); - break; - case PC8r: - strcpy (buffer,"(d8,PC,Xn)"); - break; - case absw: - strcpy (buffer,"(xxx).W"); - break; - case absl: - strcpy (buffer,"(xxx).L"); - break; - case imm: - switch (size){ - case sz_byte: - strcpy (buffer,"#.B"); - break; - case sz_word: - strcpy (buffer,"#.W"); - break; - case sz_long: - strcpy (buffer,"#.L"); - break; - default: - break; + static char buffer[80]; + + buffer[0] = 0; + switch (mode){ + case Dreg: + strcpy (buffer,"Dn"); + break; + case Areg: + strcpy (buffer,"An"); + break; + case Aind: + strcpy (buffer,"(An)"); + break; + case Aipi: + strcpy (buffer,"(An)+"); + break; + case Apdi: + strcpy (buffer,"-(An)"); + break; + case Ad16: + strcpy (buffer,"(d16,An)"); + break; + case Ad8r: + strcpy (buffer,"(d8,An,Xn)"); + break; + case PC16: + strcpy (buffer,"(d16,PC)"); + break; + case PC8r: + strcpy (buffer,"(d8,PC,Xn)"); + break; + case absw: + strcpy (buffer,"(xxx).W"); + break; + case absl: + strcpy (buffer,"(xxx).L"); + break; + case imm: + switch (size){ + case sz_byte: + strcpy (buffer,"#.B"); + break; + case sz_word: + strcpy (buffer,"#.W"); + break; + case sz_long: + strcpy (buffer,"#.L"); + break; + default: + break; + } + break; + case imm0: + strcpy (buffer,"#.B"); + break; + case imm1: + strcpy (buffer,"#.W"); + break; + case imm2: + strcpy (buffer,"#.L"); + break; + case immi: + strcpy (buffer,"#"); + break; + + default: + break; } - break; - case imm0: - strcpy (buffer,"#.B"); - break; - case imm1: - strcpy (buffer,"#.W"); - break; - case imm2: - strcpy (buffer,"#.L"); - break; - case immi: - strcpy (buffer,"#"); - break; - - default: - break; - } - return buffer; + return buffer; } static char *outopcode (int opcode) { - static char out[100]; - struct instr *ins; - int i; - - ins = &table68k[opcode]; - for (i = 0; lookuptab[i].name[0]; i++) { - if (ins->mnemo == lookuptab[i].mnemo) - break; - } - { - char *s = ua (lookuptab[i].name); - strcpy (out, s); - xfree (s); - } - if (ins->smode == immi) - strcat (out, "Q"); - if (ins->size == sz_byte) - strcat (out,".B"); - if (ins->size == sz_word) - strcat (out,".W"); - if (ins->size == sz_long) - strcat (out,".L"); - strcat (out," "); - if (ins->suse) - strcat (out, decodeEA (ins->smode, ins->size)); - if (ins->duse) { - if (ins->suse) strcat (out,","); - strcat (out, decodeEA (ins->dmode, ins->size)); - } - return out; + static char out[100]; + struct instr *ins; + int i; + + ins = &table68k[opcode]; + for (i = 0; lookuptab[i].name[0]; i++) { + if (ins->mnemo == lookuptab[i].mnemo) + break; + } + { + char *s = ua (lookuptab[i].name); + strcpy (out, s); + xfree (s); + } + if (ins->smode == immi) + strcat (out, "Q"); + if (ins->size == sz_byte) + strcat (out,".B"); + if (ins->size == sz_word) + strcat (out,".W"); + if (ins->size == sz_long) + strcat (out,".L"); + strcat (out," "); + if (ins->suse) + strcat (out, decodeEA (ins->smode, ins->size)); + if (ins->duse) { + if (ins->suse) strcat (out,","); + strcat (out, decodeEA (ins->dmode, ins->size)); + } + return out; } static void generate_one_opcode (int rp) { - int idx; - uae_u16 smsk, dmsk; - long int opcode = opcode_map[rp]; - int i68000 = table68k[opcode].clev > 0; - - if (table68k[opcode].mnemo == i_ILLG - || table68k[opcode].clev > cpu_level) - return; - - for (idx = 0; lookuptab[idx].name[0]; idx++) { - if (table68k[opcode].mnemo == lookuptab[idx].mnemo) - break; - } - - if (table68k[opcode].handler != -1) - return; + int idx; + uae_u16 smsk, dmsk; + long int opcode = opcode_map[rp]; + int i68000 = table68k[opcode].clev > 0; + + if (table68k[opcode].mnemo == i_ILLG + || table68k[opcode].clev > cpu_level) + return; + + for (idx = 0; lookuptab[idx].name[0]; idx++) { + if (table68k[opcode].mnemo == lookuptab[idx].mnemo) + break; + } + + if (table68k[opcode].handler != -1) + return; + + if (opcode_next_clev[rp] != cpu_level) { + char *name = ua (lookuptab[idx].name); + if (generate_stbl) + fprintf (stblfile, "{ %sCPUFUNC(op_%04x_%d), %d }, /* %s */\n", + (using_ce || using_ce020) ? "(cpuop_func*)" : "", + opcode, opcode_last_postfix[rp], + opcode, name); + xfree (name); + return; + } + fprintf (headerfile, "extern %s op_%04lx_%d_nf;\n", + (using_ce || using_ce020) ? "cpuop_func_ce" : "cpuop_func", opcode, postfix); + fprintf (headerfile, "extern %s op_%04lx_%d_ff;\n", + (using_ce || using_ce020) ? "cpuop_func_ce" : "cpuop_func", opcode, postfix); + printf ("/* %s */\n", outopcode (opcode)); + if (i68000) + printf("#ifndef CPUEMU_68000_ONLY\n"); + printf ("%s REGPARAM2 CPUFUNC(op_%04lx_%d)(uae_u32 opcode)\n{\n", (using_ce || using_ce020) ? "void" : "unsigned long", opcode, postfix); + + switch (table68k[opcode].stype) { + case 0: smsk = 7; break; + case 1: smsk = 255; break; + case 2: smsk = 15; break; + case 3: smsk = 7; break; + case 4: smsk = 7; break; + case 5: smsk = 63; break; + case 7: smsk = 3; break; + default: abort (); + } + dmsk = 7; - if (opcode_next_clev[rp] != cpu_level) { - char *name = ua (lookuptab[idx].name); - if (generate_stbl) - fprintf (stblfile, "{ %sCPUFUNC(op_%04x_%d), %d }, /* %s */\n", - (using_ce || using_ce020) ? "(cpuop_func*)" : "", - opcode, opcode_last_postfix[rp], - opcode, name); - xfree (name); - return; - } - fprintf (headerfile, "extern %s op_%04lx_%d_nf;\n", - (using_ce || using_ce020) ? "cpuop_func_ce" : "cpuop_func", opcode, postfix); - fprintf (headerfile, "extern %s op_%04lx_%d_ff;\n", - (using_ce || using_ce020) ? "cpuop_func_ce" : "cpuop_func", opcode, postfix); - printf ("/* %s */\n", outopcode (opcode)); - if (i68000) - printf("#ifndef CPUEMU_68000_ONLY\n"); - printf ("%s REGPARAM2 CPUFUNC(op_%04lx_%d)(uae_u32 opcode)\n{\n", (using_ce || using_ce020) ? "void" : "unsigned long", opcode, postfix); - - switch (table68k[opcode].stype) { - case 0: smsk = 7; break; - case 1: smsk = 255; break; - case 2: smsk = 15; break; - case 3: smsk = 7; break; - case 4: smsk = 7; break; - case 5: smsk = 63; break; - case 7: smsk = 3; break; - default: abort (); - } - dmsk = 7; - - next_cpu_level = -1; - if (table68k[opcode].suse - && table68k[opcode].smode != imm && table68k[opcode].smode != imm0 - && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2 - && table68k[opcode].smode != absw && table68k[opcode].smode != absl - && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16) - { - if (table68k[opcode].spos == -1) { - if (((int) table68k[opcode].sreg) >= 128) - printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg); - else - printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg); - } else { - char source[100]; - int pos = table68k[opcode].spos; - - if (pos) - sprintf (source, "((opcode >> %d) & %d)", pos, smsk); - else - sprintf (source, "(opcode & %d)", smsk); - - if (table68k[opcode].stype == 3) - printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source); - else if (table68k[opcode].stype == 1) - printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source); - else - printf ("\tuae_u32 srcreg = %s;\n", source); + next_cpu_level = -1; + if (table68k[opcode].suse + && table68k[opcode].smode != imm && table68k[opcode].smode != imm0 + && table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2 + && table68k[opcode].smode != absw && table68k[opcode].smode != absl + && table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16) + { + if (table68k[opcode].spos == -1) { + if (((int) table68k[opcode].sreg) >= 128) + printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg); + else + printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg); + } else { + char source[100]; + int pos = table68k[opcode].spos; + + if (pos) + sprintf (source, "((opcode >> %d) & %d)", pos, smsk); + else + sprintf (source, "(opcode & %d)", smsk); + + if (table68k[opcode].stype == 3) + printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source); + else if (table68k[opcode].stype == 1) + printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source); + else + printf ("\tuae_u32 srcreg = %s;\n", source); + } + } + if (table68k[opcode].duse + /* Yes, the dmode can be imm, in case of LINK or DBcc */ + && table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0 + && table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2 + && table68k[opcode].dmode != absw && table68k[opcode].dmode != absl) + { + if (table68k[opcode].dpos == -1) { + if (((int) table68k[opcode].dreg) >= 128) + printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg); + else + printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg); + } else { + int pos = table68k[opcode].dpos; + if (pos) + printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n", + pos, dmsk); + else + printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk); + } } - } - if (table68k[opcode].duse - /* Yes, the dmode can be imm, in case of LINK or DBcc */ - && table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0 - && table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2 - && table68k[opcode].dmode != absw && table68k[opcode].dmode != absl) - { - if (table68k[opcode].dpos == -1) { - if (((int) table68k[opcode].dreg) >= 128) - printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg); - else - printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg); + need_endlabel = 0; + endlabelno++; + sprintf (endlabelstr, "endlabel%d", endlabelno); + count_read = count_write = count_ncycles = count_cycles = 0; + count_read_ea = count_write_ea = count_cycles_ea = 0; + gen_opcode (opcode); + if (need_endlabel) + printf ("%s: ;\n", endlabelstr); + returncycles ("", insn_n_cycles); + printf ("}"); + if (using_ce || using_prefetch) { + if (count_read + count_write + count_cycles == 0) + count_cycles = 4; + printf (" /* %d%s (%d/%d)", + (count_read + count_write) * 4 + count_cycles, count_ncycles ? "+" : "", count_read, count_write); + printf (" */\n"); } else { - int pos = table68k[opcode].dpos; - if (pos) - printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n", - pos, dmsk); - else - printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk); + printf("\n"); } - } - need_endlabel = 0; - endlabelno++; - sprintf (endlabelstr, "endlabel%d", endlabelno); - count_read = count_write = count_ncycles = count_cycles = 0; - count_read_ea = count_write_ea = count_cycles_ea = 0; - gen_opcode (opcode); - if (need_endlabel) - printf ("%s: ;\n", endlabelstr); - returncycles ("", insn_n_cycles); - printf ("}"); - if (using_ce || using_prefetch) { - if (count_read + count_write + count_cycles == 0) - count_cycles = 4; - printf (" /* %d%s (%d/%d)", - (count_read + count_write) * 4 + count_cycles, count_ncycles ? "+" : "", count_read, count_write); - printf (" */\n"); - } else { - printf("\n"); - } - printf ("\n"); - if (i68000) - printf("#endif\n"); - opcode_next_clev[rp] = next_cpu_level; - opcode_last_postfix[rp] = postfix; - - if (generate_stbl) { - char *name = ua (lookuptab[idx].name); + printf ("\n"); if (i68000) - fprintf (stblfile, "#ifndef CPUEMU_68000_ONLY\n"); - fprintf (stblfile, "{ %sCPUFUNC(op_%04x_%d), %d }, /* %s */\n", - (using_ce || using_ce020) ? "(cpuop_func*)" : "", - opcode, postfix, opcode, name); - if (i68000) - fprintf (stblfile, "#endif\n"); - xfree (name); - } + printf("#endif\n"); + opcode_next_clev[rp] = next_cpu_level; + opcode_last_postfix[rp] = postfix; + + if (generate_stbl) { + char *name = ua (lookuptab[idx].name); + if (i68000) + fprintf (stblfile, "#ifndef CPUEMU_68000_ONLY\n"); + fprintf (stblfile, "{ %sCPUFUNC(op_%04x_%d), %d }, /* %s */\n", + (using_ce || using_ce020) ? "(cpuop_func*)" : "", + opcode, postfix, opcode, name); + if (i68000) + fprintf (stblfile, "#endif\n"); + xfree (name); + } } static void generate_func (void) { - int j, rp; + int j, rp; /* sam: this is for people with low memory (eg. me :)) */ printf ("\n" "#if !defined(PART_1) && !defined(PART_2) && " - "!defined(PART_3) && !defined(PART_4) && " - "!defined(PART_5) && !defined(PART_6) && " - "!defined(PART_7) && !defined(PART_8)" + "!defined(PART_3) && !defined(PART_4) && " + "!defined(PART_5) && !defined(PART_6) && " + "!defined(PART_7) && !defined(PART_8)" "\n" "#define PART_1 1\n" "#define PART_2 1\n" @@ -3670,99 +3666,99 @@ static void generate_func (void) int k = (j * nr_cpuop_funcs) / 8; printf ("#ifdef PART_%d\n",j); for (; rp < k; rp++) - generate_one_opcode (rp); + generate_one_opcode (rp); printf ("#endif\n\n"); } if (generate_stbl) - fprintf (stblfile, "{ 0, 0 }};\n"); + fprintf (stblfile, "{ 0, 0 }};\n"); } int main (int argc, char **argv) { - int i, rp, postfix2; - char fname[100]; - - read_table68k (); - do_merges (); - - opcode_map = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); - opcode_last_postfix = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); - opcode_next_clev = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); - counts = (unsigned long *) xmalloc (65536 * sizeof (unsigned long)); - read_counts (); - - /* It would be a lot nicer to put all in one file (we'd also get rid of - * cputbl.h that way), but cpuopti can't cope. That could be fixed, but - * I don't dare to touch the 68k version. */ - - headerfile = fopen ("cputbl.h", "wb"); - - stblfile = fopen ("cpustbl.c", "wb"); - generate_includes (stblfile); - - using_prefetch = 0; - using_indirect = 0; - using_exception_3 = 1; - using_ce = 0; - - postfix2 = -1; - for (i = 0; i < 32; i++) { - postfix = i; - if ((i >= 6 && i < 11) || (i > 12 && i < 20) || (i > 23 && i < 31)) - continue; - generate_stbl = 1; - if (i == 0 || i == 11 || i == 12 || i == 20 || i == 31) { - if (generate_stbl) - fprintf (stblfile, "#ifdef CPUEMU_%d\n", postfix); - postfix2 = postfix; - sprintf (fname, "cpuemu_%d.c", postfix); - freopen (fname, "wb", stdout); - generate_includes (stdout); - } - using_mmu = 0; + int i, rp, postfix2; + char fname[100]; + + read_table68k (); + do_merges (); + + opcode_map = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); + opcode_last_postfix = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); + opcode_next_clev = (int *) xmalloc (sizeof (int) * nr_cpuop_funcs); + counts = (unsigned long *) xmalloc (65536 * sizeof (unsigned long)); + read_counts (); + + /* It would be a lot nicer to put all in one file (we'd also get rid of + * cputbl.h that way), but cpuopti can't cope. That could be fixed, but + * I don't dare to touch the 68k version. */ + + headerfile = fopen ("cputbl.h", "wb"); + + stblfile = fopen ("cpustbl.c", "wb"); + generate_includes (stblfile); + using_prefetch = 0; + using_indirect = 0; + using_exception_3 = 1; using_ce = 0; - using_ce020 = 0; - using_mmu = 0; - cpu_level = 5 - i; - if (i == 11 || i == 12) { - cpu_level = 0; - using_prefetch = 1; - using_exception_3 = 1; - if (i == 12) - using_ce = 1; - for (rp = 0; rp < nr_cpuop_funcs; rp++) - opcode_next_clev[rp] = 0; - } else if (i >= 20 && i < 30) { - cpu_level = 25 - i; - using_ce020 = 1; - if (i == 20) - read_counts (); - } else if (i >= 31 && i < 40) { - cpu_level = 4; - using_mmu = 1; - if (i == 31) - read_counts (); - for (rp = 0; rp < nr_cpuop_funcs; rp++) - opcode_next_clev[rp] = 4; - } - if (generate_stbl) { - if ((i > 0 && i < 10) || (i >= 20)) - fprintf (stblfile, "#ifndef CPUEMU_68000_ONLY\n"); - fprintf (stblfile, "const struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix); - } - generate_func (); - if (generate_stbl) { - if ((i > 0 && i < 10) || (i >= 20)) - fprintf (stblfile, "#endif /* CPUEMU_68000_ONLY */\n"); - if (postfix2 >= 0) - fprintf (stblfile, "#endif /* CPUEMU_%d */\n", postfix2); - } postfix2 = -1; - } + for (i = 0; i < 32; i++) { + postfix = i; + if ((i >= 6 && i < 11) || (i > 12 && i < 20) || (i > 23 && i < 31)) + continue; + generate_stbl = 1; + if (i == 0 || i == 11 || i == 12 || i == 20 || i == 31) { + if (generate_stbl) + fprintf (stblfile, "#ifdef CPUEMU_%d\n", postfix); + postfix2 = postfix; + sprintf (fname, "cpuemu_%d.c", postfix); + freopen (fname, "wb", stdout); + generate_includes (stdout); + } + using_mmu = 0; + using_prefetch = 0; + using_ce = 0; + using_ce020 = 0; + using_mmu = 0; + cpu_level = 5 - i; + if (i == 11 || i == 12) { + cpu_level = 0; + using_prefetch = 1; + using_exception_3 = 1; + if (i == 12) + using_ce = 1; + for (rp = 0; rp < nr_cpuop_funcs; rp++) + opcode_next_clev[rp] = 0; + } else if (i >= 20 && i < 30) { + cpu_level = 25 - i; + using_ce020 = 1; + if (i == 20) + read_counts (); + } else if (i >= 31 && i < 40) { + cpu_level = 4; + using_mmu = 1; + if (i == 31) + read_counts (); + for (rp = 0; rp < nr_cpuop_funcs; rp++) + opcode_next_clev[rp] = 4; + } + + if (generate_stbl) { + if ((i > 0 && i < 10) || (i >= 20)) + fprintf (stblfile, "#ifndef CPUEMU_68000_ONLY\n"); + fprintf (stblfile, "const struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix); + } + generate_func (); + if (generate_stbl) { + if ((i > 0 && i < 10) || (i >= 20)) + fprintf (stblfile, "#endif /* CPUEMU_68000_ONLY */\n"); + if (postfix2 >= 0) + fprintf (stblfile, "#endif /* CPUEMU_%d */\n", postfix2); + } + postfix2 = -1; + } - free (table68k); - return 0; + free (table68k); + return 0; } diff --git a/gfxutil.c b/gfxutil.c index 66684073..3c8488ef 100644 --- a/gfxutil.c +++ b/gfxutil.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Common code needed by all the various graphics systems. - * - * (c) 1996 Bernd Schmidt, Ed Hanway, Samuel Devulder - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Common code needed by all the various graphics systems. +* +* (c) 1996 Bernd Schmidt, Ed Hanway, Samuel Devulder +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -18,9 +18,9 @@ int getvsyncrate (int hz) { - if (hz > 85) - return hz / 2; - return hz; + if (hz > 85) + return hz / 2; + return hz; } #define RED 0 @@ -28,101 +28,101 @@ int getvsyncrate (int hz) #define BLU 2 /* - * dither matrix - */ +* dither matrix +*/ static uae_u8 dither[4][4] = { - { 0, 8, 2, 10 }, - { 12, 4, 14, 6 }, - { 3, 11, 1, 9 }, - { 14 /* 15 */, 7, 13, 5 } + { 0, 8, 2, 10 }, + { 12, 4, 14, 6 }, + { 3, 11, 1, 9 }, + { 14 /* 15 */, 7, 13, 5 } }; unsigned int doMask (int p, int bits, int shift) { - /* scale to 0..255, shift to align msb with mask, and apply mask */ - unsigned long val; - - if (flashscreen) - p ^= 0xff; - val = p << 24; - if (!bits) - return 0; - val >>= (32 - bits); - val <<= shift; - - return val; + /* scale to 0..255, shift to align msb with mask, and apply mask */ + unsigned long val; + + if (flashscreen) + p ^= 0xff; + val = p << 24; + if (!bits) + return 0; + val >>= (32 - bits); + val <<= shift; + + return val; } int bits_in_mask (unsigned long mask) { - int n = 0; - while (mask) { - n += mask & 1; - mask >>= 1; - } - return n; + int n = 0; + while (mask) { + n += mask & 1; + mask >>= 1; + } + return n; } int mask_shift (unsigned long mask) { - int n = 0; - while (!(mask & 1)) { - n++; - mask >>= 1; - } - return n; + int n = 0; + while (!(mask & 1)) { + n++; + mask >>= 1; + } + return n; } unsigned int doMask256 (int p, int bits, int shift) { - /* p is a value from 0 to 255 (Amiga color value) - * shift to align msb with mask, and apply mask */ + /* p is a value from 0 to 255 (Amiga color value) + * shift to align msb with mask, and apply mask */ - unsigned long val = p * 0x01010101UL; - val >>= (32 - bits); - val <<= shift; + unsigned long val = p * 0x01010101UL; + val >>= (32 - bits); + val <<= shift; - return val; + return val; } static unsigned int doColor (int i, int bits, int shift) { - int shift2; - - if (flashscreen) - i ^= 0xffffffff; - if(bits >= 8) - shift2 = 0; - else - shift2 = 8 - bits; - return (i >> shift2) << shift; + int shift2; + + if (flashscreen) + i ^= 0xffffffff; + if(bits >= 8) + shift2 = 0; + else + shift2 = 8 - bits; + return (i >> shift2) << shift; } static unsigned int doAlpha (int alpha, int bits, int shift) { - return (alpha & ((1 << bits) - 1)) << shift; + return (alpha & ((1 << bits) - 1)) << shift; } static float video_gamma (float value, float gamma, float bri, float con) { - double factor; - float ret; + double factor; + float ret; - value += bri; - value *= con; + value += bri; + value *= con; - if (value <= 0.0f) - return 0.0f; + if (value <= 0.0f) + return 0.0f; - factor = pow(255.0f, 1.0f - gamma); - ret = (float)(factor * pow(value, gamma)); + factor = pow(255.0f, 1.0f - gamma); + ret = (float)(factor * pow(value, gamma)); - if (ret < 0.0f) - ret = 0.0f; + if (ret < 0.0f) + ret = 0.0f; - return ret; + return ret; } static uae_u32 gamma[256 * 3]; @@ -130,69 +130,69 @@ static int lf, hf; static void video_calc_gammatable (void) { - int i; - float bri, con, gam, v; - uae_u32 vi; + int i; + float bri, con, gam, v; + uae_u32 vi; - bri = ((float)(currprefs.gfx_luminance)) - * (128.0f / 1000.0f); - con = ((float)(currprefs.gfx_contrast + 1000)) / 1000.0f; - gam = ((float)(1000 - currprefs.gfx_gamma)) / 1000.0f; + bri = ((float)(currprefs.gfx_luminance)) + * (128.0f / 1000.0f); + con = ((float)(currprefs.gfx_contrast + 1000)) / 1000.0f; + gam = ((float)(1000 - currprefs.gfx_gamma)) / 1000.0f; - lf = 64 * currprefs.gfx_filter_blur / 1000; - hf = 256 - lf * 2; + lf = 64 * currprefs.gfx_filter_blur / 1000; + hf = 256 - lf * 2; - for (i = 0; i < (256 * 3); i++) { - v = video_gamma((float)(i - 256), gam, bri, con); + for (i = 0; i < (256 * 3); i++) { + v = video_gamma((float)(i - 256), gam, bri, con); - vi = (uae_u32)v; - if (vi > 255) - vi = 255; + vi = (uae_u32)v; + if (vi > 255) + vi = 255; - if (currprefs.gfx_luminance == 0 && currprefs.gfx_contrast == 0 && currprefs.gfx_gamma == 0) - vi = i & 0xff; + if (currprefs.gfx_luminance == 0 && currprefs.gfx_contrast == 0 && currprefs.gfx_gamma == 0) + vi = i & 0xff; - gamma[i] = vi; - } + gamma[i] = vi; + } } static uae_u32 limit256 (double v) { - v = v * (double)(currprefs.gfx_filter_contrast + 1000) / 1000.0 + currprefs.gfx_filter_luminance / 10.0; - if (v < 0) - v = 0; - if (v > 255) - v = 255; - return ((uae_u32)v) & 0xff; + v = v * (double)(currprefs.gfx_filter_contrast + 1000) / 1000.0 + currprefs.gfx_filter_luminance / 10.0; + if (v < 0) + v = 0; + if (v > 255) + v = 255; + return ((uae_u32)v) & 0xff; } static uae_u32 limit256rb (double v) { - v *= (double)(currprefs.gfx_filter_saturation + 1000) / 1000.0; - if (v < -128) - v = -128; - if (v > 127) - v = 127; - return ((uae_u32)v) & 0xff; + v *= (double)(currprefs.gfx_filter_saturation + 1000) / 1000.0; + if (v < -128) + v = -128; + if (v > 127) + v = 127; + return ((uae_u32)v) & 0xff; } static double get_y (int r, int g, int b) { - return 0.2989f * r + 0.5866f * g + 0.1145f * b; + return 0.2989f * r + 0.5866f * g + 0.1145f * b; } static uae_u32 get_yh (int r, int g, int b) { - return limit256 (get_y (r, g, b) * hf / 256); + return limit256 (get_y (r, g, b) * hf / 256); } static uae_u32 get_yl (int r, int g, int b) { - return limit256 (get_y (r, g, b) * lf / 256); + return limit256 (get_y (r, g, b) * lf / 256); } static uae_u32 get_cb (int r, int g, int b) { - return limit256rb (-0.168736f * r - 0.331264f * g + 0.5f * b); + return limit256rb (-0.168736f * r - 0.331264f * g + 0.5f * b); } static uae_u32 get_cr (int r, int g, int b) { - return limit256rb (0.5f * r - 0.418688f * g - 0.081312f * b); + return limit256rb (0.5f * r - 0.418688f * g - 0.081312f * b); } extern uae_s32 tyhrgb[65536]; @@ -203,242 +203,242 @@ extern uae_u32 redc[3 * 256], grec[3 * 256], bluc[3 * 256]; static uae_u32 lowbits (int v, int shift, int lsize) { - v >>= shift; - v &= (1 << lsize) - 1; - return v; + v >>= shift; + v &= (1 << lsize) - 1; + return v; } void alloc_colors_picasso (int rw, int gw, int bw, int rs, int gs, int bs, int rgbfmt) { - int byte_swap = 0; - int i; - int red_bits = 0, green_bits, blue_bits; - int red_shift, green_shift, blue_shift; - int bpp = rw + gw + bw; - - switch (rgbfmt) - { + int byte_swap = 0; + int i; + int red_bits = 0, green_bits, blue_bits; + int red_shift, green_shift, blue_shift; + int bpp = rw + gw + bw; + + switch (rgbfmt) + { case RGBFB_R5G6B5PC: - red_bits = 5; - green_bits = 6; - blue_bits = 5; - red_shift = 11; - green_shift = 5; - blue_shift = 0; - break; + red_bits = 5; + green_bits = 6; + blue_bits = 5; + red_shift = 11; + green_shift = 5; + blue_shift = 0; + break; case RGBFB_R5G5B5PC: - red_bits = green_bits = blue_bits = 5; - red_shift = 10; - green_shift = 5; - blue_shift = 0; - break; + red_bits = green_bits = blue_bits = 5; + red_shift = 10; + green_shift = 5; + blue_shift = 0; + break; case RGBFB_R5G6B5: - red_bits = 5; - green_bits = 6; - blue_bits = 5; - red_shift = 11; - green_shift = 5; - blue_shift = 0; - byte_swap = 1; - break; + red_bits = 5; + green_bits = 6; + blue_bits = 5; + red_shift = 11; + green_shift = 5; + blue_shift = 0; + byte_swap = 1; + break; case RGBFB_R5G5B5: - red_bits = green_bits = blue_bits = 5; - red_shift = 10; - green_shift = 5; - blue_shift = 0; - byte_swap = 1; - break; + red_bits = green_bits = blue_bits = 5; + red_shift = 10; + green_shift = 5; + blue_shift = 0; + byte_swap = 1; + break; case RGBFB_B5G6R5PC: - red_bits = 5; - green_bits = 6; - blue_bits = 5; - red_shift = 0; - green_shift = 5; - blue_shift = 11; - break; + red_bits = 5; + green_bits = 6; + blue_bits = 5; + red_shift = 0; + green_shift = 5; + blue_shift = 11; + break; case RGBFB_B5G5R5PC: - red_bits = 5; - green_bits = 5; - blue_bits = 5; - red_shift = 0; - green_shift = 5; - blue_shift = 10; - break; + red_bits = 5; + green_bits = 5; + blue_bits = 5; + red_shift = 0; + green_shift = 5; + blue_shift = 10; + break; default: - red_bits = rw; - green_bits = gw; - blue_bits = bw; - red_shift = rs; - green_shift = gs; - blue_shift = bs; - break; - } - - memset (p96_rgbx16, 0, sizeof p96_rgbx16); - - if (red_bits) { - int lrbits = 8 - red_bits; - int lgbits = 8 - green_bits; - int lbbits = 8 - blue_bits; - int lrmask = (1 << red_bits) - 1; - int lgmask = (1 << green_bits) - 1; - int lbmask = (1 << blue_bits) - 1; - for (i = 65535; i >= 0; i--) { - uae_u32 r, g, b, c; - uae_u32 j = byte_swap ? bswap_16 (i) : i; - r = (((j >> red_shift) & lrmask) << lrbits) | lowbits (j, red_shift, lrbits); - g = (((j >> green_shift) & lgmask) << lgbits) | lowbits (j, green_shift, lgbits); - b = (((j >> blue_shift) & lbmask) << lbbits) | lowbits (j, blue_shift, lbbits); - c = doMask(r, rw, rs) | doMask(g, gw, gs) | doMask(b, bw, bs); - if (bpp <= 16) - c *= 0x00010001; - p96_rgbx16[i] = c; + red_bits = rw; + green_bits = gw; + blue_bits = bw; + red_shift = rs; + green_shift = gs; + blue_shift = bs; + break; + } + + memset (p96_rgbx16, 0, sizeof p96_rgbx16); + + if (red_bits) { + int lrbits = 8 - red_bits; + int lgbits = 8 - green_bits; + int lbbits = 8 - blue_bits; + int lrmask = (1 << red_bits) - 1; + int lgmask = (1 << green_bits) - 1; + int lbmask = (1 << blue_bits) - 1; + for (i = 65535; i >= 0; i--) { + uae_u32 r, g, b, c; + uae_u32 j = byte_swap ? bswap_16 (i) : i; + r = (((j >> red_shift) & lrmask) << lrbits) | lowbits (j, red_shift, lrbits); + g = (((j >> green_shift) & lgmask) << lgbits) | lowbits (j, green_shift, lgbits); + b = (((j >> blue_shift) & lbmask) << lbbits) | lowbits (j, blue_shift, lbbits); + c = doMask(r, rw, rs) | doMask(g, gw, gs) | doMask(b, bw, bs); + if (bpp <= 16) + c *= 0x00010001; + p96_rgbx16[i] = c; + } } - } } void alloc_colors_rgb (int rw, int gw, int bw, int rs, int gs, int bs, int aw, int as, int alpha, int byte_swap, - uae_u32 *rc, uae_u32 *gc, uae_u32 *bc) + uae_u32 *rc, uae_u32 *gc, uae_u32 *bc) { - int bpp = rw + gw + bw + aw; - int i; - for(i = 0; i < 256; i++) { - int j; - - if (currprefs.gfx_blackerthanblack) { - j = i * 15 / 16; - } else { - j = i; - } - j += 256; - - rc[i] = doColor (gamma[j], rw, rs) | doAlpha (alpha, aw, as); - gc[i] = doColor (gamma[j], gw, gs) | doAlpha (alpha, aw, as); - bc[i] = doColor (gamma[j], bw, bs) | doAlpha (alpha, aw, as); - if (byte_swap) { - if (bpp <= 16) { - rc[i] = bswap_16 (rc[i]); - gc[i] = bswap_16 (gc[i]); - bc[i] = bswap_16 (bc[i]); - } else { - rc[i] = bswap_32 (rc[i]); - gc[i] = bswap_32 (gc[i]); - bc[i] = bswap_32 (bc[i]); - } - } - if (bpp <= 16) { - /* Fill upper 16 bits of each colour value with - * a copy of the colour. */ - rc[i] = rc[i] * 0x00010001; - gc[i] = gc[i] * 0x00010001; - bc[i] = bc[i] * 0x00010001; + int bpp = rw + gw + bw + aw; + int i; + for(i = 0; i < 256; i++) { + int j; + + if (currprefs.gfx_blackerthanblack) { + j = i * 15 / 16; + } else { + j = i; + } + j += 256; + + rc[i] = doColor (gamma[j], rw, rs) | doAlpha (alpha, aw, as); + gc[i] = doColor (gamma[j], gw, gs) | doAlpha (alpha, aw, as); + bc[i] = doColor (gamma[j], bw, bs) | doAlpha (alpha, aw, as); + if (byte_swap) { + if (bpp <= 16) { + rc[i] = bswap_16 (rc[i]); + gc[i] = bswap_16 (gc[i]); + bc[i] = bswap_16 (bc[i]); + } else { + rc[i] = bswap_32 (rc[i]); + gc[i] = bswap_32 (gc[i]); + bc[i] = bswap_32 (bc[i]); + } + } + if (bpp <= 16) { + /* Fill upper 16 bits of each colour value with + * a copy of the colour. */ + rc[i] = rc[i] * 0x00010001; + gc[i] = gc[i] * 0x00010001; + bc[i] = bc[i] * 0x00010001; + } } - } } void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, int as, int alpha, int byte_swap) { - int bpp = rw + gw + bw + aw; - int i, j; - - video_calc_gammatable(); - j = 256; - for (i = 0; i < 4096; i++) { - int r = ((i >> 8) << 4) | (i >> 8); - int g = (((i >> 4) & 0xf) << 4) | ((i >> 4) & 0x0f); - int b = ((i & 0xf) << 4) | (i & 0x0f); - r = gamma[r + j]; - g = gamma[g + j]; - b = gamma[b + j]; - xcolors[i] = doMask(r, rw, rs) | doMask(g, gw, gs) | doMask(b, bw, bs) | doAlpha (alpha, aw, as); - if (byte_swap) { - if (bpp <= 16) - xcolors[i] = bswap_16 (xcolors[i]); - else - xcolors[i] = bswap_32 (xcolors[i]); - } - if (bpp <= 16) { - /* Fill upper 16 bits of each colour value - * with a copy of the colour. */ - xcolors[i] |= xcolors[i] * 0x00010001; + int bpp = rw + gw + bw + aw; + int i, j; + + video_calc_gammatable(); + j = 256; + for (i = 0; i < 4096; i++) { + int r = ((i >> 8) << 4) | (i >> 8); + int g = (((i >> 4) & 0xf) << 4) | ((i >> 4) & 0x0f); + int b = ((i & 0xf) << 4) | (i & 0x0f); + r = gamma[r + j]; + g = gamma[g + j]; + b = gamma[b + j]; + xcolors[i] = doMask(r, rw, rs) | doMask(g, gw, gs) | doMask(b, bw, bs) | doAlpha (alpha, aw, as); + if (byte_swap) { + if (bpp <= 16) + xcolors[i] = bswap_16 (xcolors[i]); + else + xcolors[i] = bswap_32 (xcolors[i]); + } + if (bpp <= 16) { + /* Fill upper 16 bits of each colour value + * with a copy of the colour. */ + xcolors[i] |= xcolors[i] * 0x00010001; + } } - } #if defined(AGA) || defined(GFXFILTER) - alloc_colors_rgb (rw, gw, bw, rs, gs, bs, aw, as, alpha, byte_swap, xredcolors, xgreencolors, xbluecolors); - /* copy original color table */ - for (i = 0; i < 256; i++) { - redc[0 * 256 + i] = xredcolors[0]; - grec[0 * 256 + i] = xgreencolors[0]; - bluc[0 * 256 + i] = xbluecolors[0]; - redc[1 * 256 + i] = xredcolors[i]; - grec[1 * 256 + i] = xgreencolors[i]; - bluc[1 * 256 + i] = xbluecolors[i]; - redc[2 * 256 + i] = xredcolors[255]; - grec[2 * 256 + i] = xgreencolors[255]; - bluc[2 * 256 + i] = xbluecolors[255]; - } - if (usedfilter && usedfilter->yuv) { - /* create internal 5:6:5 color tables */ + alloc_colors_rgb (rw, gw, bw, rs, gs, bs, aw, as, alpha, byte_swap, xredcolors, xgreencolors, xbluecolors); + /* copy original color table */ for (i = 0; i < 256; i++) { - j = i + 256; - xredcolors[i] = doColor (gamma[j], 5, 11); - xgreencolors[i] = doColor (gamma[j], 6, 5); - xbluecolors[i] = doColor (gamma[j], 5, 0); - if (bpp <= 16) { - /* Fill upper 16 bits of each colour value with - * a copy of the colour. */ - xredcolors [i] = xredcolors [i] * 0x00010001; - xgreencolors[i] = xgreencolors[i] * 0x00010001; - xbluecolors [i] = xbluecolors [i] * 0x00010001; - } - } - for (i = 0; i < 4096; i++) { - int r = ((i >> 8) << 4) | (i >> 8); - int g = (((i >> 4) & 0xf) << 4) | ((i >> 4) & 0x0f); - int b = ((i & 0xf) << 4) | (i & 0x0f); - r = gamma[r + 256]; - g = gamma[g + 256]; - b = gamma[b + 256]; - xcolors[i] = doMask(r, 5, 11) | doMask(g, 6, 5) | doMask(b, 5, 0); - if (byte_swap) { - if (bpp <= 16) - xcolors[i] = bswap_16 (xcolors[i]); - else - xcolors[i] = bswap_32 (xcolors[i]); - } - if (bpp <= 16) { - /* Fill upper 16 bits of each colour value - * with a copy of the colour. */ - xcolors[i] |= xcolors[i] * 0x00010001; - } + redc[0 * 256 + i] = xredcolors[0]; + grec[0 * 256 + i] = xgreencolors[0]; + bluc[0 * 256 + i] = xbluecolors[0]; + redc[1 * 256 + i] = xredcolors[i]; + grec[1 * 256 + i] = xgreencolors[i]; + bluc[1 * 256 + i] = xbluecolors[i]; + redc[2 * 256 + i] = xredcolors[255]; + grec[2 * 256 + i] = xgreencolors[255]; + bluc[2 * 256 + i] = xbluecolors[255]; } + if (usedfilter && usedfilter->yuv) { + /* create internal 5:6:5 color tables */ + for (i = 0; i < 256; i++) { + j = i + 256; + xredcolors[i] = doColor (gamma[j], 5, 11); + xgreencolors[i] = doColor (gamma[j], 6, 5); + xbluecolors[i] = doColor (gamma[j], 5, 0); + if (bpp <= 16) { + /* Fill upper 16 bits of each colour value with + * a copy of the colour. */ + xredcolors [i] = xredcolors [i] * 0x00010001; + xgreencolors[i] = xgreencolors[i] * 0x00010001; + xbluecolors [i] = xbluecolors [i] * 0x00010001; + } + } + for (i = 0; i < 4096; i++) { + int r = ((i >> 8) << 4) | (i >> 8); + int g = (((i >> 4) & 0xf) << 4) | ((i >> 4) & 0x0f); + int b = ((i & 0xf) << 4) | (i & 0x0f); + r = gamma[r + 256]; + g = gamma[g + 256]; + b = gamma[b + 256]; + xcolors[i] = doMask(r, 5, 11) | doMask(g, 6, 5) | doMask(b, 5, 0); + if (byte_swap) { + if (bpp <= 16) + xcolors[i] = bswap_16 (xcolors[i]); + else + xcolors[i] = bswap_32 (xcolors[i]); + } + if (bpp <= 16) { + /* Fill upper 16 bits of each colour value + * with a copy of the colour. */ + xcolors[i] |= xcolors[i] * 0x00010001; + } + } - /* create RGB 5:6:5 -> YUV tables */ - for (i = 0; i < 65536; i++) { - uae_u32 r, g, b; - r = (((i >> 11) & 31) << 3) | lowbits (i, 11, 3); - r = gamma[r + 256]; - g = (((i >> 5) & 63) << 2) | lowbits (i, 5, 2); - g = gamma[g + 256]; - b = (((i >> 0) & 31) << 3) | lowbits (i, 0, 3); - b = gamma[b + 256]; - tyhrgb[i] = get_yh (r, g, b) * 256 * 256; - tylrgb[i] = get_yl (r, g, b) * 256 * 256; - tcbrgb[i] = ((uae_s8)get_cb (r, g, b)) * 256; - tcrrgb[i] = ((uae_s8)get_cr (r, g, b)) * 256; + /* create RGB 5:6:5 -> YUV tables */ + for (i = 0; i < 65536; i++) { + uae_u32 r, g, b; + r = (((i >> 11) & 31) << 3) | lowbits (i, 11, 3); + r = gamma[r + 256]; + g = (((i >> 5) & 63) << 2) | lowbits (i, 5, 2); + g = gamma[g + 256]; + b = (((i >> 0) & 31) << 3) | lowbits (i, 0, 3); + b = gamma[b + 256]; + tyhrgb[i] = get_yh (r, g, b) * 256 * 256; + tylrgb[i] = get_yl (r, g, b) * 256 * 256; + tcbrgb[i] = ((uae_s8)get_cb (r, g, b)) * 256; + tcrrgb[i] = ((uae_s8)get_cr (r, g, b)) * 256; + } } - } #endif - xredcolor_b = rw; - xgreencolor_b = gw; - xbluecolor_b = bw; - xredcolor_s = rs; - xgreencolor_s = gs; - xbluecolor_s = bs; - xredcolor_m = (1 << rw) - 1; - xgreencolor_m = (1 << gw) - 1; - xbluecolor_m = (1 << bw) - 1; + xredcolor_b = rw; + xgreencolor_b = gw; + xbluecolor_b = bw; + xredcolor_s = rs; + xgreencolor_s = gs; + xbluecolor_s = bs; + xredcolor_m = (1 << rw) - 1; + xgreencolor_m = (1 << gw) - 1; + xbluecolor_m = (1 << bw) - 1; } static int color_diff[4096]; @@ -446,396 +446,396 @@ static int newmaxcol = 0; void setup_maxcol (int max) { - newmaxcol = max; + newmaxcol = max; } void alloc_colors256 (allocfunc_type allocfunc) { - int nb_cols[3]; /* r,g,b */ - int maxcol = newmaxcol == 0 ? 256 : newmaxcol; - int i,j,k,l; - xcolnr *map; - - map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); - if (!map) { - write_log (L"Not enough mem for colormap!\n"); - abort (); - } - - /* - * compute #cols per components - */ - for (i = 1; i*i*i <= maxcol; ++i) - ; - --i; - - nb_cols[RED] = i; - nb_cols[GRN] = i; - nb_cols[BLU] = i; - - /* - * set the colormap - */ - l = 0; - for (i = 0; i < nb_cols[RED]; ++i) { - int r = (i * 15) / (nb_cols[RED] - 1); - for (j = 0; j < nb_cols[GRN]; ++j) { - int g = (j * 15) / (nb_cols[GRN] - 1); - for (k = 0; k < nb_cols[BLU]; ++k) { - int b = (k * 15) / (nb_cols[BLU] - 1); - int result; - result = allocfunc (r, g, b, map + l); - l++; - } - } - } -/* printf("%d color(s) lost\n",maxcol - l);*/ - - /* - * for each component compute the mapping - */ - { - int diffr, diffg, diffb, maxdiff = 0, won = 0, lost; - int r, d = 8; - for (r = 0; r < 16; ++r) { - int cr, g, q; - - k = nb_cols[RED]-1; - cr = (r * k) / 15; - q = (r * k) % 15; - if (q > d && cr < k) ++cr; - diffr = abs (cr*k - r); - for (g = 0; g < 16; ++g) { - int cg, b; - - k = nb_cols[GRN]-1; - cg = (g * k) / 15; - q = (g * k) % 15; - if (q > d && cg < k) ++cg; - diffg = abs (cg*k - g); - for (b = 0; b < 16; ++b) { - int cb, rgb = (r << 8) | (g << 4) | b; - - k = nb_cols[BLU]-1; - cb = (b * k) / 15; - q = (b * k) % 15; - if (q > d && cb < k) ++cb; - diffb = abs (cb*k - b); - xcolors[rgb] = map[(cr * nb_cols[GRN] + cg) * nb_cols[BLU] + cb]; - color_diff[rgb] = diffr + diffg + diffb; - if (color_diff[rgb] > maxdiff) - maxdiff = color_diff[rgb]; - } - } + int nb_cols[3]; /* r,g,b */ + int maxcol = newmaxcol == 0 ? 256 : newmaxcol; + int i,j,k,l; + xcolnr *map; + + map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); + if (!map) { + write_log (L"Not enough mem for colormap!\n"); + abort (); } - while (maxdiff > 0 && l < maxcol) { - int newmaxdiff = 0; - lost = 0; won++; - for (r = 15; r >= 0; r--) { - int g; - - for (g = 15; g >= 0; g--) { - int b; - - for (b = 15; b >= 0; b--) { - int rgb = (r << 8) | (g << 4) | b; - if (color_diff[rgb] == maxdiff) { - int result; + /* + * compute #cols per components + */ + for (i = 1; i*i*i <= maxcol; ++i) + ; + --i; - if (l >= maxcol) - lost++; - else { - result = allocfunc (r, g, b, xcolors + rgb); + nb_cols[RED] = i; + nb_cols[GRN] = i; + nb_cols[BLU] = i; + + /* + * set the colormap + */ + l = 0; + for (i = 0; i < nb_cols[RED]; ++i) { + int r = (i * 15) / (nb_cols[RED] - 1); + for (j = 0; j < nb_cols[GRN]; ++j) { + int g = (j * 15) / (nb_cols[GRN] - 1); + for (k = 0; k < nb_cols[BLU]; ++k) { + int b = (k * 15) / (nb_cols[BLU] - 1); + int result; + result = allocfunc (r, g, b, map + l); l++; - } - color_diff[rgb] = 0; - } else if (color_diff[rgb] > newmaxdiff) - newmaxdiff = color_diff[rgb]; - - } + } } - } - maxdiff = newmaxdiff; } -/* printf("%d color(s) lost, %d stages won\n",lost, won);*/ - } - free (map); + /* printf("%d color(s) lost\n",maxcol - l);*/ + + /* + * for each component compute the mapping + */ + { + int diffr, diffg, diffb, maxdiff = 0, won = 0, lost; + int r, d = 8; + for (r = 0; r < 16; ++r) { + int cr, g, q; + + k = nb_cols[RED]-1; + cr = (r * k) / 15; + q = (r * k) % 15; + if (q > d && cr < k) ++cr; + diffr = abs (cr*k - r); + for (g = 0; g < 16; ++g) { + int cg, b; + + k = nb_cols[GRN]-1; + cg = (g * k) / 15; + q = (g * k) % 15; + if (q > d && cg < k) ++cg; + diffg = abs (cg*k - g); + for (b = 0; b < 16; ++b) { + int cb, rgb = (r << 8) | (g << 4) | b; + + k = nb_cols[BLU]-1; + cb = (b * k) / 15; + q = (b * k) % 15; + if (q > d && cb < k) ++cb; + diffb = abs (cb*k - b); + xcolors[rgb] = map[(cr * nb_cols[GRN] + cg) * nb_cols[BLU] + cb]; + color_diff[rgb] = diffr + diffg + diffb; + if (color_diff[rgb] > maxdiff) + maxdiff = color_diff[rgb]; + } + } + } + while (maxdiff > 0 && l < maxcol) { + int newmaxdiff = 0; + lost = 0; won++; + for (r = 15; r >= 0; r--) { + int g; + + for (g = 15; g >= 0; g--) { + int b; + + for (b = 15; b >= 0; b--) { + int rgb = (r << 8) | (g << 4) | b; + + if (color_diff[rgb] == maxdiff) { + int result; + + if (l >= maxcol) + lost++; + else { + result = allocfunc (r, g, b, xcolors + rgb); + l++; + } + color_diff[rgb] = 0; + } else if (color_diff[rgb] > newmaxdiff) + newmaxdiff = color_diff[rgb]; + + } + } + } + maxdiff = newmaxdiff; + } + /* printf("%d color(s) lost, %d stages won\n",lost, won);*/ + } + free (map); } /* - * This dithering process works by letting UAE run internaly in 12bit - * mode and doing the dithering on the fly when rendering to the display. - * The dithering algorithm is quite fast but uses lot of memory (4*8*2^12 = - * 128Kb). I don't think that is a trouble right now, but when UAE will - * emulate AGA and work internaly in 24bit mode, that dithering algorithm - * will need 4*8*2^24 = 512Mb. Obviously that fast algorithm will not be - * tractable. However, we could then use an other algorithm, slower, but - * far more reasonable (I am thinking about the one that is used in DJPEG). - */ +* This dithering process works by letting UAE run internaly in 12bit +* mode and doing the dithering on the fly when rendering to the display. +* The dithering algorithm is quite fast but uses lot of memory (4*8*2^12 = +* 128Kb). I don't think that is a trouble right now, but when UAE will +* emulate AGA and work internaly in 24bit mode, that dithering algorithm +* will need 4*8*2^24 = 512Mb. Obviously that fast algorithm will not be +* tractable. However, we could then use an other algorithm, slower, but +* far more reasonable (I am thinking about the one that is used in DJPEG). +*/ uae_u8 cidx[4][8*4096]; /* fast, but memory hungry =:-( */ /* - * Compute dithering structures - */ +* Compute dithering structures +*/ void setup_greydither_maxcol (int maxcol, allocfunc_type allocfunc) { - int i,j,k; - xcolnr *map; - - for (i = 0; i < 4096; i++) - xcolors[i] = i << 16 | i; - - map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); - if (!map) { - write_log (L"Not enough mem for colormap!\n"); - abort(); - } - - /* - * set the colormap - */ - for (i = 0; i < maxcol; ++i) { - int c, result; - c = (15 * i + (maxcol-1)/2) / (maxcol - 1); - result = allocfunc(c, c, c, map + i); - /* @@@ check for errors */ - } - - /* - * for each componant compute the mapping - */ - for (i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) { - int r, d = dither[i][j]*17; - for (r = 0; r<16; ++r) { - int g; - for (g = 0; g < 16; ++g) { - int b; - for (b = 0; b < 16; ++b) { - int rgb = (r << 8) | (g << 4) | b; - int c,p,q; - - c = (77 * r + - 151 * g + - 28 * b) / 15; /* c in 0..256 */ - - k = maxcol-1; - p = (c * k) / 256; - q = (c * k) % 256; - if (q /*/ k*/> d /*/ k*/ && p < k) ++p; -/* sam: ^^^^^^^ */ -/* It seems that produces better output */ - cidx[i][rgb + (j+4)*4096] = - cidx[i][rgb + j*4096] = (uae_u8)map[p]; - } + int i,j,k; + xcolnr *map; + + for (i = 0; i < 4096; i++) + xcolors[i] = i << 16 | i; + + map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); + if (!map) { + write_log (L"Not enough mem for colormap!\n"); + abort(); + } + + /* + * set the colormap + */ + for (i = 0; i < maxcol; ++i) { + int c, result; + c = (15 * i + (maxcol-1)/2) / (maxcol - 1); + result = allocfunc(c, c, c, map + i); + /* @@@ check for errors */ + } + + /* + * for each componant compute the mapping + */ + for (i = 0; i < 4; ++i) { + for (j = 0; j < 4; ++j) { + int r, d = dither[i][j]*17; + for (r = 0; r<16; ++r) { + int g; + for (g = 0; g < 16; ++g) { + int b; + for (b = 0; b < 16; ++b) { + int rgb = (r << 8) | (g << 4) | b; + int c,p,q; + + c = (77 * r + + 151 * g + + 28 * b) / 15; /* c in 0..256 */ + + k = maxcol-1; + p = (c * k) / 256; + q = (c * k) % 256; + if (q /*/ k*/> d /*/ k*/ && p < k) ++p; + /* sam: ^^^^^^^ */ + /* It seems that produces better output */ + cidx[i][rgb + (j+4)*4096] = + cidx[i][rgb + j*4096] = (uae_u8)map[p]; + } + } + } } - } } - } - free (map); + free (map); } void setup_greydither (int bits, allocfunc_type allocfunc) { - setup_greydither_maxcol(1 << bits, allocfunc); + setup_greydither_maxcol(1 << bits, allocfunc); } void setup_dither (int bits, allocfunc_type allocfunc) { - int nb_cols[3]; /* r,g,b */ - int maxcol = 1 << bits; - int i,j,k,l; - - xcolnr *map; - int *redvals, *grnvals, *bluvals; - - map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); - if (!map) { - write_log (L"Not enough mem for colormap!\n"); - abort(); - } - - for (i = 0; i < 4096; i++) - xcolors[i] = i << 16 | i; - - /* - * compute #cols per components - */ - for (i = 1; i*i*i <= maxcol; ++i) - ; - --i; - - nb_cols[RED] = i; - nb_cols[GRN] = i; - nb_cols[BLU] = i; - - if (nb_cols[RED]*(++i)*nb_cols[BLU] <= maxcol) { + int nb_cols[3]; /* r,g,b */ + int maxcol = 1 << bits; + int i,j,k,l; + + xcolnr *map; + int *redvals, *grnvals, *bluvals; + + map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol); + if (!map) { + write_log (L"Not enough mem for colormap!\n"); + abort(); + } + + for (i = 0; i < 4096; i++) + xcolors[i] = i << 16 | i; + + /* + * compute #cols per components + */ + for (i = 1; i*i*i <= maxcol; ++i) + ; + --i; + + nb_cols[RED] = i; nb_cols[GRN] = i; - if ((i)*nb_cols[GRN]*nb_cols[BLU] <= maxcol) - nb_cols[RED] = i; - } - - redvals = (int *)malloc (sizeof(int) * maxcol); - grnvals = redvals + nb_cols[RED]; - bluvals = grnvals + nb_cols[GRN]; - /* - * set the colormap - */ - l = 0; - for (i = 0; i < nb_cols[RED]; ++i) { - int r = (i * 15) / (nb_cols[RED] - 1); - redvals[i] = r; - for (j = 0; j < nb_cols[GRN]; ++j) { - int g = (j * 15) / (nb_cols[GRN] - 1); - grnvals[j] = g; - for (k = 0; k < nb_cols[BLU]; ++k) { - int b = (k * 15) / (nb_cols[BLU] - 1); - int result; - bluvals[k] = b; - result = allocfunc(r, g, b, map + l); - l++; - } + nb_cols[BLU] = i; + + if (nb_cols[RED]*(++i)*nb_cols[BLU] <= maxcol) { + nb_cols[GRN] = i; + if ((i)*nb_cols[GRN]*nb_cols[BLU] <= maxcol) + nb_cols[RED] = i; + } + + redvals = (int *)malloc (sizeof(int) * maxcol); + grnvals = redvals + nb_cols[RED]; + bluvals = grnvals + nb_cols[GRN]; + /* + * set the colormap + */ + l = 0; + for (i = 0; i < nb_cols[RED]; ++i) { + int r = (i * 15) / (nb_cols[RED] - 1); + redvals[i] = r; + for (j = 0; j < nb_cols[GRN]; ++j) { + int g = (j * 15) / (nb_cols[GRN] - 1); + grnvals[j] = g; + for (k = 0; k < nb_cols[BLU]; ++k) { + int b = (k * 15) / (nb_cols[BLU] - 1); + int result; + bluvals[k] = b; + result = allocfunc(r, g, b, map + l); + l++; + } + } } - } -/* write_log (L"%d color(s) lost\n",maxcol - l);*/ - - /* - * for each component compute the mapping - */ - { - int r; - for (r = 0; r < 16; ++r) { - int g; - for (g = 0; g < 16; ++g) { - int b; - for (b = 0; b < 16; ++b) { - int rgb = (r << 8) | (g << 4) | b; - - for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) { - int d = dither[i][j]; - int cr, cg, cb, k, q; + /* write_log (L"%d color(s) lost\n",maxcol - l);*/ + + /* + * for each component compute the mapping + */ + { + int r; + for (r = 0; r < 16; ++r) { + int g; + for (g = 0; g < 16; ++g) { + int b; + for (b = 0; b < 16; ++b) { + int rgb = (r << 8) | (g << 4) | b; + + for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) { + int d = dither[i][j]; + int cr, cg, cb, k, q; #if 0 /* Slightly different algorithm. Needs some tuning. */ - int rederr = 0, grnerr = 0, bluerr = 0; - - k = nb_cols[RED]-1; - cr = r * k / 15; - q = r * k - 15*cr; - if (cr < 0) - cr = 0; - else if (q / k > d / k && rederr <= 0) - ++cr; - if (cr > k) cr = k; - rederr += redvals[cr]-r; - - k = nb_cols[GRN]-1; - cg = g * k / 15; - q = g * k - 15*cg; - if (cg < 0) - cg = 0; - else if (q / k > d / k && grnerr <= 0) - ++cg; - if (cg > k) cg = k; - grnerr += grnvals[cg]-g; - - k = nb_cols[BLU]-1; - cb = b * k / 15; - q = b * k - 15*cb; - if (cb < 0) - cb = 0; - else if (q / k > d / k && bluerr <= 0) - ++cb; - if (cb > k) cb = k; - bluerr += bluvals[cb]-b; + int rederr = 0, grnerr = 0, bluerr = 0; + + k = nb_cols[RED]-1; + cr = r * k / 15; + q = r * k - 15*cr; + if (cr < 0) + cr = 0; + else if (q / k > d / k && rederr <= 0) + ++cr; + if (cr > k) cr = k; + rederr += redvals[cr]-r; + + k = nb_cols[GRN]-1; + cg = g * k / 15; + q = g * k - 15*cg; + if (cg < 0) + cg = 0; + else if (q / k > d / k && grnerr <= 0) + ++cg; + if (cg > k) cg = k; + grnerr += grnvals[cg]-g; + + k = nb_cols[BLU]-1; + cb = b * k / 15; + q = b * k - 15*cb; + if (cb < 0) + cb = 0; + else if (q / k > d / k && bluerr <= 0) + ++cb; + if (cb > k) cb = k; + bluerr += bluvals[cb]-b; #else - k = nb_cols[RED]-1; - cr = r * k / 15; - q = r * k - 15*cr; - if (cr < 0) - cr = 0; - else if (q /*/ k*/ > d /*/ k*/) - ++cr; - if (cr > k) cr = k; - - k = nb_cols[GRN]-1; - cg = g * k / 15; - q = g * k - 15*cg; - if (cg < 0) - cg = 0; - else if (q /*/ k*/ > d /*/ k*/) - ++cg; - if (cg > k) cg = k; - - k = nb_cols[BLU]-1; - cb = b * k / 15; - q = b * k - 15*cb; - if (cb < 0) - cb = 0; - else if (q /*/ k*/ > d /*/ k*/) - ++cb; - if (cb > k) cb = k; + k = nb_cols[RED]-1; + cr = r * k / 15; + q = r * k - 15*cr; + if (cr < 0) + cr = 0; + else if (q /*/ k*/ > d /*/ k*/) + ++cr; + if (cr > k) cr = k; + + k = nb_cols[GRN]-1; + cg = g * k / 15; + q = g * k - 15*cg; + if (cg < 0) + cg = 0; + else if (q /*/ k*/ > d /*/ k*/) + ++cg; + if (cg > k) cg = k; + + k = nb_cols[BLU]-1; + cb = b * k / 15; + q = b * k - 15*cb; + if (cb < 0) + cb = 0; + else if (q /*/ k*/ > d /*/ k*/) + ++cb; + if (cb > k) cb = k; #endif - cidx[i][rgb + (j+4)*4096] = cidx[i][rgb + j*4096] = (uae_u8)map[(cr*nb_cols[GRN]+cg)*nb_cols[BLU]+cb]; - } + cidx[i][rgb + (j+4)*4096] = cidx[i][rgb + j*4096] = (uae_u8)map[(cr*nb_cols[GRN]+cg)*nb_cols[BLU]+cb]; + } + } + } } - } } - } - free (redvals); - free (map); + free (redvals); + free (map); } #if !defined X86_ASSEMBLY /* - * Dither the line. - * Make sure you call this only with (len & 3) == 0, or you'll just make - * yourself unhappy. - */ +* Dither the line. +* Make sure you call this only with (len & 3) == 0, or you'll just make +* yourself unhappy. +*/ void DitherLine (uae_u8 *l, uae_u16 *r4g4b4, int x, int y, uae_s16 len, int bits) { - uae_u8 *dith = cidx[y&3]+(x&3)*4096; - uae_u8 d = 0; - int bitsleft = 8; - - if (bits == 8) { - while (len > 0) { - *l++ = dith[0*4096 + *r4g4b4++]; - *l++ = dith[1*4096 + *r4g4b4++]; - *l++ = dith[2*4096 + *r4g4b4++]; - *l++ = dith[3*4096 + *r4g4b4++]; - len -= 4; + uae_u8 *dith = cidx[y&3]+(x&3)*4096; + uae_u8 d = 0; + int bitsleft = 8; + + if (bits == 8) { + while (len > 0) { + *l++ = dith[0*4096 + *r4g4b4++]; + *l++ = dith[1*4096 + *r4g4b4++]; + *l++ = dith[2*4096 + *r4g4b4++]; + *l++ = dith[3*4096 + *r4g4b4++]; + len -= 4; + } + return; + } + + while (len) { + int v; + v = dith[0*4096 + *r4g4b4++]; + bitsleft -= bits; + d |= (v << bitsleft); + if (!bitsleft) + *l++ = d, bitsleft = 8, d = 0; + + v = dith[1*4096 + *r4g4b4++]; + bitsleft -= bits; + d |= (v << bitsleft); + if (!bitsleft) + *l++ = d, bitsleft = 8, d = 0; + + v = dith[2*4096 + *r4g4b4++]; + bitsleft -= bits; + d |= (v << bitsleft); + if (!bitsleft) + *l++ = d, bitsleft = 8, d = 0; + + v = dith[3*4096 + *r4g4b4++]; + bitsleft -= bits; + d |= (v << bitsleft); + if (!bitsleft) + *l++ = d, bitsleft = 8, d = 0; + len -= 4; } - return; - } - - while (len) { - int v; - v = dith[0*4096 + *r4g4b4++]; - bitsleft -= bits; - d |= (v << bitsleft); - if (!bitsleft) - *l++ = d, bitsleft = 8, d = 0; - - v = dith[1*4096 + *r4g4b4++]; - bitsleft -= bits; - d |= (v << bitsleft); - if (!bitsleft) - *l++ = d, bitsleft = 8, d = 0; - - v = dith[2*4096 + *r4g4b4++]; - bitsleft -= bits; - d |= (v << bitsleft); - if (!bitsleft) - *l++ = d, bitsleft = 8, d = 0; - - v = dith[3*4096 + *r4g4b4++]; - bitsleft -= bits; - d |= (v << bitsleft); - if (!bitsleft) - *l++ = d, bitsleft = 8, d = 0; - len -= 4; - } } #endif diff --git a/hardfile.c b/hardfile.c index d2d9b92a..9a943554 100644 --- a/hardfile.c +++ b/hardfile.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Hardfile emulation - * - * Copyright 1995 Bernd Schmidt - * 2002 Toni Wilen (scsi emulation, 64-bit support) - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Hardfile emulation +* +* Copyright 1995 Bernd Schmidt +* 2002 Toni Wilen (scsi emulation, 64-bit support) +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -52,15 +52,15 @@ #define ASYNC_REQUEST_CHANGEINT 10 struct hardfileprivdata { - volatile uaecptr d_request[MAX_ASYNC_REQUESTS]; - volatile int d_request_type[MAX_ASYNC_REQUESTS]; - volatile uae_u32 d_request_data[MAX_ASYNC_REQUESTS]; - smp_comm_pipe requests; - int thread_running; - uae_sem_t sync_sem; - uaecptr base; - int changenum; - uaecptr changeint; + volatile uaecptr d_request[MAX_ASYNC_REQUESTS]; + volatile int d_request_type[MAX_ASYNC_REQUESTS]; + volatile uae_u32 d_request_data[MAX_ASYNC_REQUESTS]; + smp_comm_pipe requests; + int thread_running; + uae_sem_t sync_sem; + uaecptr base; + int changenum; + uaecptr changeint; }; #define VHD_DYNAMIC 3 @@ -68,7 +68,7 @@ struct hardfileprivdata { STATIC_INLINE uae_u32 gl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); } static uae_sem_t change_sem; @@ -79,1673 +79,1696 @@ static uae_u32 nscmd_cmd; static void wl (uae_u8 *p, int v) { - p[0] = v >> 24; - p[1] = v >> 16; - p[2] = v >> 8; - p[3] = v; + p[0] = v >> 24; + p[1] = v >> 16; + p[2] = v >> 8; + p[3] = v; } static void ww (uae_u8 *p, int v) { - p[0] = v >> 8; - p[1] = v; + p[0] = v >> 8; + p[1] = v; } static int rl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); } static void getchs2 (struct hardfiledata *hfd, int *cyl, int *cylsec, int *head, int *tracksec) { - unsigned int total = (unsigned int)(hfd->virtsize / 1024); - int heads; - int sectors = 63; - - /* do we have RDB values? */ - if (hfd->cylinders) { - *cyl = hfd->cylinders; - *tracksec = hfd->sectors; - *head = hfd->heads; - *cylsec = hfd->sectors * hfd->heads; - return; - } - /* what about HDF settings? */ - if (hfd->surfaces && hfd->secspertrack) { - *head = hfd->surfaces; - *tracksec = hfd->secspertrack; - *cylsec = (*head) * (*tracksec); - *cyl = (unsigned int)(hfd->virtsize / hfd->blocksize) / ((*tracksec) * (*head)); - return; - } - /* no, lets guess something.. */ - if (total <= 504 * 1024) - heads = 16; - else if (total <= 1008 * 1024) - heads = 32; - else if (total <= 2016 * 1024) - heads = 64; - else if (total <= 4032 * 1024) - heads = 128; - else - heads = 255; - *cyl = (unsigned int)(hfd->virtsize / hfd->blocksize) / (sectors * heads); - *cylsec = sectors * heads; - *tracksec = sectors; - *head = heads; + unsigned int total = (unsigned int)(hfd->virtsize / 1024); + int heads; + int sectors = 63; + + /* do we have RDB values? */ + if (hfd->cylinders) { + *cyl = hfd->cylinders; + *tracksec = hfd->sectors; + *head = hfd->heads; + *cylsec = hfd->sectors * hfd->heads; + return; + } + /* what about HDF settings? */ + if (hfd->surfaces && hfd->secspertrack) { + *head = hfd->surfaces; + *tracksec = hfd->secspertrack; + *cylsec = (*head) * (*tracksec); + *cyl = (unsigned int)(hfd->virtsize / hfd->blocksize) / ((*tracksec) * (*head)); + return; + } + /* no, lets guess something.. */ + if (total <= 504 * 1024) + heads = 16; + else if (total <= 1008 * 1024) + heads = 32; + else if (total <= 2016 * 1024) + heads = 64; + else if (total <= 4032 * 1024) + heads = 128; + else + heads = 255; + *cyl = (unsigned int)(hfd->virtsize / hfd->blocksize) / (sectors * heads); + *cylsec = sectors * heads; + *tracksec = sectors; + *head = heads; } static void getchs (struct hardfiledata *hfd, int *cyl, int *cylsec, int *head, int *tracksec) { - getchs2 (hfd, cyl, cylsec, head, tracksec); - hf_log ("CHS: %08X-%08X %d %d %d %d %d\n", - (uae_u32)(hfd->virtsize >> 32),(uae_u32)hfd->virtsize, - *cyl, *cylsec, *head, *tracksec); + getchs2 (hfd, cyl, cylsec, head, tracksec); + hf_log ("CHS: %08X-%08X %d %d %d %d %d\n", + (uae_u32)(hfd->virtsize >> 32),(uae_u32)hfd->virtsize, + *cyl, *cylsec, *head, *tracksec); } -void getchshd (struct hardfiledata *hfd, int *pcyl, int *phead, int *psectorspertrack) +void getchsgeometry (uae_u64 size, int *pcyl, int *phead, int *psectorspertrack) { - unsigned int total = (unsigned int)(hfd->virtsize / 512); - int i, head , cyl, spt; - int sptt[] = { 63, 127, 255, -1 }; - - if (total > 16515072) { - /* >8G, CHS=16383/16/63 */ - *pcyl = 16383; - *phead = 16; - *psectorspertrack = 63; - return; - } - - for (i = 0; sptt[i] >= 0; i++) { - spt = sptt[i]; - for (head = 4; head <= 16;head++) { - cyl = total / (head * spt); - if (hfd->virtsize <= 512 * 1024 * 1024) { - if (cyl <= 1023) - break; - } else { - if (cyl < 16383) - break; - if (cyl < 32767 && head >= 5) - break; - if (cyl <= 65535) - break; - } + int sptt[] = { 63, 127, 255, -1 }; + int i, spt, head, cyl; + uae_u64 total = (unsigned int)(size / 512); + + for (i = 0; sptt[i] >= 0; i++) { + spt = sptt[i]; + for (head = 4; head <= 16;head++) { + cyl = total / (head * spt); + if (size <= 512 * 1024 * 1024) { + if (cyl <= 1023) + break; + } else { + if (cyl < 16383) + break; + if (cyl < 32767 && head >= 5) + break; + if (cyl <= 65535) + break; + } + } + if (head <= 16) + break; } - if (head <= 16) - break; - } - *pcyl = cyl; - *phead = head; - *psectorspertrack = spt; + *pcyl = cyl; + *phead = head; + *psectorspertrack = spt; +} + +static void getchshd (struct hardfiledata *hfd, int *pcyl, int *phead, int *psectorspertrack) +{ + uae_u64 total = hfd->virtsize / 512; + + if (total > 16515072) { + /* >8G, CHS=16383/16/63 */ + *pcyl = 16383; + *phead = 16; + *psectorspertrack = 63; + return; + } + getchsgeometry (hfd->virtsize, pcyl, phead, psectorspertrack); } static void pl (uae_u8 *p, int off, uae_u32 v) { - p += off * 4; - p[0] = v >> 24; - p[1] = v >> 16; - p[2] = v >> 8; - p[3] = v >> 0; + p += off * 4; + p[0] = v >> 24; + p[1] = v >> 16; + p[2] = v >> 8; + p[3] = v >> 0; } static void rdb_crc (uae_u8 *p) { - uae_u32 sum; - int i, blocksize; - - sum =0; - blocksize = rl (p + 1 * 4); - for (i = 0; i < blocksize; i++) - sum += rl (p + i * 4); - sum = -sum; - pl (p, 2, sum); + uae_u32 sum; + int i, blocksize; + + sum =0; + blocksize = rl (p + 1 * 4); + for (i = 0; i < blocksize; i++) + sum += rl (p + i * 4); + sum = -sum; + pl (p, 2, sum); } static void create_virtual_rdb (struct hardfiledata *hfd, uae_u32 dostype, int bootpri, const TCHAR *filesys) { - uae_u8 *rdb, *part, *denv; - int cyl = hfd->heads * hfd->secspertrack; - int cyls = 262144 / (cyl * 512); - int size = cyl * cyls * 512; - - rdb = (uae_u8*)xcalloc (size, 1); - hfd->virtual_rdb = rdb; - hfd->virtual_size = size; - part = rdb + 512; - pl(rdb, 0, 0x5244534b); - pl(rdb, 1, 64); - pl(rdb, 2, 0); // chksum - pl(rdb, 3, 0); // hostid - pl(rdb, 4, 512); // blockbytes - pl(rdb, 5, 0); // flags - pl(rdb, 6, -1); // badblock - pl(rdb, 7, 1); // part - pl(rdb, 8, -1); // fs - pl(rdb, 9, -1); // driveinit - pl(rdb, 10, -1); // reserved - pl(rdb, 11, -1); // reserved - pl(rdb, 12, -1); // reserved - pl(rdb, 13, -1); // reserved - pl(rdb, 14, -1); // reserved - pl(rdb, 15, -1); // reserved - pl(rdb, 16, hfd->nrcyls); - pl(rdb, 17, hfd->secspertrack); - pl(rdb, 18, hfd->heads); - pl(rdb, 19, 0); // interleave - pl(rdb, 20, 0); // park - pl(rdb, 21, -1); // res - pl(rdb, 22, -1); // res - pl(rdb, 23, -1); // res - pl(rdb, 24, 0); // writeprecomp - pl(rdb, 25, 0); // reducedwrite - pl(rdb, 26, 0); // steprate - pl(rdb, 27, -1); // res - pl(rdb, 28, -1); // res - pl(rdb, 29, -1); // res - pl(rdb, 30, -1); // res - pl(rdb, 31, -1); // res - pl(rdb, 32, 0); // rdbblockslo - pl(rdb, 33, cyl * cyls); // rdbblockshi - pl(rdb, 34, cyls); // locyl - pl(rdb, 35, hfd->nrcyls + cyls); // hicyl - pl(rdb, 36, cyl); // cylblocks - pl(rdb, 37, 0); // autopark - pl(rdb, 38, 2); // highrdskblock - pl(rdb, 39, -1); // res - ua_copy (rdb + 40 * 4, -1, hfd->vendor_id); - ua_copy (rdb + 42 * 4, -1, hfd->product_id); - ua_copy (rdb + 46 * 4, -1, L"UAE"); - rdb_crc (rdb); - - pl(part, 0, 0x50415254); - pl(part, 1, 64); - pl(part, 2, 0); - pl(part, 3, 0); - pl(part, 4, -1); - pl(part, 5, 1); // bootable - pl(part, 6, -1); - pl(part, 7, -1); - pl(part, 8, 0); // devflags - part[9 * 4] = _tcslen (hfd->device_name); - ua_copy (part + 9 * 4 + 1, -1, hfd->device_name); - - denv = part + 128; - pl(denv, 0, 80); - pl(denv, 1, 512 / 4); - pl(denv, 2, 0); // secorg - pl(denv, 3, hfd->heads); - pl(denv, 4, hfd->blocksize / 512); - pl(denv, 5, hfd->secspertrack); - pl(denv, 6, hfd->reservedblocks); - pl(denv, 7, 0); // prealloc - pl(denv, 8, 0); // interleave - pl(denv, 9, cyls); // lowcyl - pl(denv, 10, hfd->nrcyls + cyls - 1); - pl(denv, 11, 50); - pl(denv, 12, 0); - pl(denv, 13, 0x00ffffff); - pl(denv, 14, 0x7ffffffe); - pl(denv, 15, bootpri); - pl(denv, 16, dostype); - rdb_crc (part); - - hfd->virtsize += size; + uae_u8 *rdb, *part, *denv; + int cyl = hfd->heads * hfd->secspertrack; + int cyls = 262144 / (cyl * 512); + int size = cyl * cyls * 512; + + rdb = (uae_u8*)xcalloc (size, 1); + hfd->virtual_rdb = rdb; + hfd->virtual_size = size; + part = rdb + 512; + pl(rdb, 0, 0x5244534b); + pl(rdb, 1, 64); + pl(rdb, 2, 0); // chksum + pl(rdb, 3, 0); // hostid + pl(rdb, 4, 512); // blockbytes + pl(rdb, 5, 0); // flags + pl(rdb, 6, -1); // badblock + pl(rdb, 7, 1); // part + pl(rdb, 8, -1); // fs + pl(rdb, 9, -1); // driveinit + pl(rdb, 10, -1); // reserved + pl(rdb, 11, -1); // reserved + pl(rdb, 12, -1); // reserved + pl(rdb, 13, -1); // reserved + pl(rdb, 14, -1); // reserved + pl(rdb, 15, -1); // reserved + pl(rdb, 16, hfd->nrcyls); + pl(rdb, 17, hfd->secspertrack); + pl(rdb, 18, hfd->heads); + pl(rdb, 19, 0); // interleave + pl(rdb, 20, 0); // park + pl(rdb, 21, -1); // res + pl(rdb, 22, -1); // res + pl(rdb, 23, -1); // res + pl(rdb, 24, 0); // writeprecomp + pl(rdb, 25, 0); // reducedwrite + pl(rdb, 26, 0); // steprate + pl(rdb, 27, -1); // res + pl(rdb, 28, -1); // res + pl(rdb, 29, -1); // res + pl(rdb, 30, -1); // res + pl(rdb, 31, -1); // res + pl(rdb, 32, 0); // rdbblockslo + pl(rdb, 33, cyl * cyls); // rdbblockshi + pl(rdb, 34, cyls); // locyl + pl(rdb, 35, hfd->nrcyls + cyls); // hicyl + pl(rdb, 36, cyl); // cylblocks + pl(rdb, 37, 0); // autopark + pl(rdb, 38, 2); // highrdskblock + pl(rdb, 39, -1); // res + ua_copy (rdb + 40 * 4, -1, hfd->vendor_id); + ua_copy (rdb + 42 * 4, -1, hfd->product_id); + ua_copy (rdb + 46 * 4, -1, L"UAE"); + rdb_crc (rdb); + + pl(part, 0, 0x50415254); + pl(part, 1, 64); + pl(part, 2, 0); + pl(part, 3, 0); + pl(part, 4, -1); + pl(part, 5, 1); // bootable + pl(part, 6, -1); + pl(part, 7, -1); + pl(part, 8, 0); // devflags + part[9 * 4] = _tcslen (hfd->device_name); + ua_copy (part + 9 * 4 + 1, -1, hfd->device_name); + + denv = part + 128; + pl(denv, 0, 80); + pl(denv, 1, 512 / 4); + pl(denv, 2, 0); // secorg + pl(denv, 3, hfd->heads); + pl(denv, 4, hfd->blocksize / 512); + pl(denv, 5, hfd->secspertrack); + pl(denv, 6, hfd->reservedblocks); + pl(denv, 7, 0); // prealloc + pl(denv, 8, 0); // interleave + pl(denv, 9, cyls); // lowcyl + pl(denv, 10, hfd->nrcyls + cyls - 1); + pl(denv, 11, 50); + pl(denv, 12, 0); + pl(denv, 13, 0x00ffffff); + pl(denv, 14, 0x7ffffffe); + pl(denv, 15, bootpri); + pl(denv, 16, dostype); + rdb_crc (part); + + hfd->virtsize += size; } void hdf_hd_close (struct hd_hardfiledata *hfd) { - if (!hfd) - return; - hdf_close (&hfd->hfd); - xfree (hfd->path); + if (!hfd) + return; + hdf_close (&hfd->hfd); + xfree (hfd->path); } int hdf_hd_open (struct hd_hardfiledata *hfd, const TCHAR *path, int blocksize, int readonly, - const TCHAR *devname, int sectors, int surfaces, int reserved, - int bootpri, const TCHAR *filesys) + const TCHAR *devname, int sectors, int surfaces, int reserved, + int bootpri, const TCHAR *filesys) { - memset (hfd, 0, sizeof (struct hd_hardfiledata)); - hfd->bootpri = bootpri; - hfd->hfd.blocksize = blocksize; - if (!hdf_open (&hfd->hfd, path)) - return 0; - hfd->path = my_strdup(path); - hfd->hfd.heads = surfaces; - hfd->hfd.reservedblocks = reserved; - hfd->hfd.secspertrack = sectors; - if (devname) - _tcscpy (hfd->hfd.device_name, devname); - getchshd (&hfd->hfd, &hfd->cyls, &hfd->heads, &hfd->secspertrack); - hfd->cyls_def = hfd->cyls; - hfd->secspertrack_def = hfd->secspertrack; - hfd->heads_def = hfd->heads; - if (hfd->hfd.heads && hfd->hfd.secspertrack) { - uae_u8 buf[512] = { 0 }; - hdf_read (&hfd->hfd, buf, 0, 512); - if (buf[0] != 0 && memcmp (buf, L"RDSK", 4)) { - hfd->hfd.nrcyls = (hfd->hfd.virtsize / blocksize) / (sectors * surfaces); - create_virtual_rdb (&hfd->hfd, rl (buf), hfd->bootpri, filesys); - while (hfd->hfd.nrcyls * surfaces * sectors > hfd->cyls_def * hfd->secspertrack_def * hfd->heads_def) { - hfd->cyls_def++; - } + memset (hfd, 0, sizeof (struct hd_hardfiledata)); + hfd->bootpri = bootpri; + hfd->hfd.blocksize = blocksize; + if (!hdf_open (&hfd->hfd, path)) + return 0; + hfd->path = my_strdup(path); + hfd->hfd.heads = surfaces; + hfd->hfd.reservedblocks = reserved; + hfd->hfd.secspertrack = sectors; + if (devname) + _tcscpy (hfd->hfd.device_name, devname); + getchshd (&hfd->hfd, &hfd->cyls, &hfd->heads, &hfd->secspertrack); + hfd->cyls_def = hfd->cyls; + hfd->secspertrack_def = hfd->secspertrack; + hfd->heads_def = hfd->heads; + if (hfd->hfd.heads && hfd->hfd.secspertrack) { + uae_u8 buf[512] = { 0 }; + hdf_read (&hfd->hfd, buf, 0, 512); + if (buf[0] != 0 && memcmp (buf, L"RDSK", 4)) { + hfd->hfd.nrcyls = (hfd->hfd.virtsize / blocksize) / (sectors * surfaces); + create_virtual_rdb (&hfd->hfd, rl (buf), hfd->bootpri, filesys); + while (hfd->hfd.nrcyls * surfaces * sectors > hfd->cyls_def * hfd->secspertrack_def * hfd->heads_def) { + hfd->cyls_def++; + } + } } - } - hfd->size = hfd->hfd.virtsize; - return 1; + hfd->size = hfd->hfd.virtsize; + return 1; } static uae_u32 vhd_checksum (uae_u8 *p, int offset) { - int i; - uae_u32 sum; - - sum = 0; - for (i = 0; i < 512; i++) { - if (offset >= 0 && i >= offset && i < offset + 4) - continue; - sum += p[i]; - } - return ~sum; + int i; + uae_u32 sum; + + sum = 0; + for (i = 0; i < 512; i++) { + if (offset >= 0 && i >= offset && i < offset + 4) + continue; + sum += p[i]; + } + return ~sum; } static int hdf_open2 (struct hardfiledata *hfd, const TCHAR *pname) { - uae_u8 tmp[512], tmp2[512]; - uae_u32 v; + uae_u8 tmp[512], tmp2[512]; + uae_u32 v; - hfd->adide = 0; - hfd->byteswap = 0; - if (!hdf_open_target (hfd, pname)) - return 0; - if (hdf_read_target (hfd, tmp, 0, 512) != 512) - goto nonvhd; - v = gl (tmp + 8); // features - if ((v & 3) != 2) - goto nonvhd; - v = gl (tmp + 8 + 4); // version - if ((v >> 16) != 1) - goto nonvhd; - hfd->vhd_type = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4); - if (hfd->vhd_type != VHD_FIXED && hfd->vhd_type != VHD_DYNAMIC) - goto nonvhd; - v = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4); - if (v == 0) - goto nonvhd; - if (vhd_checksum (tmp, 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4) != v) - goto nonvhd; - if (hdf_read_target (hfd, tmp2, hfd->physsize - sizeof tmp2, 512) != 512) - goto end; - if (memcmp (tmp, tmp2, sizeof tmp)) - goto nonvhd; - hfd->vhd_footerblock = hfd->physsize - 512; - hfd->virtsize = (uae_u64)(gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8)) << 32; - hfd->virtsize |= gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8 + 4); - if (hfd->vhd_type == VHD_DYNAMIC) { - uae_u32 size; - hfd->vhd_bamoffset = gl (tmp + 8 + 4 + 4 + 4); - if (hfd->vhd_bamoffset == 0 || hfd->vhd_bamoffset >= hfd->physsize) - goto end; - if (hdf_read_target (hfd, tmp, hfd->vhd_bamoffset, 512) != 512) - goto end; - v = gl (tmp + 8 + 8 + 8 + 4 + 4 + 4); - if (vhd_checksum (tmp, 8 + 8 + 8 + 4 + 4 + 4) != v) - goto end; - v = gl (tmp + 8 + 8 + 8); + hfd->adide = 0; + hfd->byteswap = 0; + if (!hdf_open_target (hfd, pname)) + return 0; + if (hdf_read_target (hfd, tmp, 0, 512) != 512) + goto nonvhd; + v = gl (tmp + 8); // features + if ((v & 3) != 2) + goto nonvhd; + v = gl (tmp + 8 + 4); // version if ((v >> 16) != 1) - goto end; - hfd->vhd_blocksize = gl (tmp + 8 + 8 + 8 + 4 + 4); - hfd->vhd_bamoffset = gl (tmp + 8 + 8 + 4); - hfd->vhd_bamsize = (((hfd->virtsize + hfd->vhd_blocksize - 1) / hfd->vhd_blocksize) * 4 + 511) & ~511; - size = hfd->vhd_bamoffset + hfd->vhd_bamsize; - hfd->vhd_header = xmalloc (size); - if (hdf_read_target (hfd, hfd->vhd_header, 0, size) != size) - goto end; - hfd->vhd_sectormap = xmalloc (512); - hfd->vhd_sectormapblock = -1; - hfd->vhd_bitmapsize = ((hfd->vhd_blocksize / (8 * 512)) + 511) & ~511; - } - write_log (L"HDF is VHD %s image, virtual size=%dK\n", - hfd->vhd_type == 2 ? L"fixed" : L"dynamic", - hfd->virtsize / 1024); - return 1; + goto nonvhd; + hfd->vhd_type = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4); + if (hfd->vhd_type != VHD_FIXED && hfd->vhd_type != VHD_DYNAMIC) + goto nonvhd; + v = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4); + if (v == 0) + goto nonvhd; + if (vhd_checksum (tmp, 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4) != v) + goto nonvhd; + if (hdf_read_target (hfd, tmp2, hfd->physsize - sizeof tmp2, 512) != 512) + goto end; + if (memcmp (tmp, tmp2, sizeof tmp)) + goto nonvhd; + hfd->vhd_footerblock = hfd->physsize - 512; + hfd->virtsize = (uae_u64)(gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8)) << 32; + hfd->virtsize |= gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8 + 4); + if (hfd->vhd_type == VHD_DYNAMIC) { + uae_u32 size; + hfd->vhd_bamoffset = gl (tmp + 8 + 4 + 4 + 4); + if (hfd->vhd_bamoffset == 0 || hfd->vhd_bamoffset >= hfd->physsize) + goto end; + if (hdf_read_target (hfd, tmp, hfd->vhd_bamoffset, 512) != 512) + goto end; + v = gl (tmp + 8 + 8 + 8 + 4 + 4 + 4); + if (vhd_checksum (tmp, 8 + 8 + 8 + 4 + 4 + 4) != v) + goto end; + v = gl (tmp + 8 + 8 + 8); + if ((v >> 16) != 1) + goto end; + hfd->vhd_blocksize = gl (tmp + 8 + 8 + 8 + 4 + 4); + hfd->vhd_bamoffset = gl (tmp + 8 + 8 + 4); + hfd->vhd_bamsize = (((hfd->virtsize + hfd->vhd_blocksize - 1) / hfd->vhd_blocksize) * 4 + 511) & ~511; + size = hfd->vhd_bamoffset + hfd->vhd_bamsize; + hfd->vhd_header = xmalloc (size); + if (hdf_read_target (hfd, hfd->vhd_header, 0, size) != size) + goto end; + hfd->vhd_sectormap = xmalloc (512); + hfd->vhd_sectormapblock = -1; + hfd->vhd_bitmapsize = ((hfd->vhd_blocksize / (8 * 512)) + 511) & ~511; + } + write_log (L"HDF is VHD %s image, virtual size=%dK\n", + hfd->vhd_type == 2 ? L"fixed" : L"dynamic", + hfd->virtsize / 1024); + return 1; nonvhd: - hfd->vhd_type = 0; - return 1; + hfd->vhd_type = 0; + return 1; end: - hdf_close_target (hfd); - return 0; + hdf_close_target (hfd); + return 0; } int hdf_open (struct hardfiledata *hfd, const TCHAR *pname) { - int v; - uae_u8 buf[512]; - - v = hdf_open2 (hfd, pname); - if (!v) + int v; + uae_u8 buf[512]; + + v = hdf_open2 (hfd, pname); + if (!v) + return v; + memset (buf, 0, sizeof buf); + hdf_read (hfd, buf, 0, sizeof buf); + if (buf[0] == 0x39 && buf[1] == 0x10 && buf[2] == 0xd3 && buf[3] == 0x12) { // AdIDE encoded "CPRM" + hfd->adide = 1; + } + if (!memcmp (buf, "DRKS", 4)) { + hfd->byteswap = 1; + } return v; - memset (buf, 0, sizeof buf); - hdf_read (hfd, buf, 0, sizeof buf); - if (buf[0] == 0x39 && buf[1] == 0x10 && buf[2] == 0xd3 && buf[3] == 0x12) { // AdIDE encoded "CPRM" - hfd->adide = 1; - } - if (!memcmp (buf, "DRKS", 4)) { - hfd->byteswap = 1; - } - return v; } void hdf_close (struct hardfiledata *hfd) { - hdf_close_target (hfd); - hfd->vhd_type = 0; - xfree (hfd->vhd_header); - hfd->vhd_header = NULL; - xfree (hfd->vhd_sectormap); - hfd->vhd_sectormap = NULL; + hdf_close_target (hfd); + hfd->vhd_type = 0; + xfree (hfd->vhd_header); + hfd->vhd_header = NULL; + xfree (hfd->vhd_sectormap); + hfd->vhd_sectormap = NULL; } int hdf_dup (struct hardfiledata *dhfd, const struct hardfiledata *shfd) { - return hdf_dup_target (dhfd, shfd); + return hdf_dup_target (dhfd, shfd); } extern int get_guid_target (uae_u8 *out); int vhd_create (const TCHAR *name, uae_u64 size) { - struct hardfiledata hfd; - struct zfile *zf; - uae_u8 *b; - int cyl, cylsec, head, tracksec; - uae_u32 crc, blocksize, batsize, batentrysize; - int ret, i; - time_t tm; - - if (size >= (uae_u64)10 * 1024 * 1024 * 1024) - blocksize = 2 * 1024 * 1024; - else - blocksize = 512 * 1024; - batsize = (size + blocksize - 1) / blocksize; - batentrysize = batsize; - batsize *= 4; - batsize += 511; - batsize &= ~511; - ret = 0; - b = NULL; - zf = zfile_fopen (name, L"wb", 0); - if (!zf) - goto end; - b = xcalloc (512 + 1024 + batsize + 512, 1); - if (zfile_fwrite (b, 512 + 1024 + batsize + 512, 1, zf) != 1) - goto end; - - memset (&hfd, 0, sizeof hfd); - hfd.virtsize = hfd.physsize = size; - hfd.blocksize = 512; - strcpy (b, "conectix"); // cookie - b[0x0b] = 2; // features - b[0x0d] = 1; // version - b[0x10 + 6] = 2; // data offset - // time stamp - tm = time (NULL) - 946684800; - b[0x18] = tm >> 24; - b[0x19] = tm >> 16; - b[0x1a] = tm >> 8; - b[0x1b] = tm >> 0; - strcpy (b + 0x1c, "vpc "); // creator application - b[0x21] = 5; // creator version - strcpy (b + 0x24, "Wi2k"); // creator host os - // original and current size - b[0x28] = b[0x30] = size >> 56; - b[0x29] = b[0x31] = size >> 48; - b[0x2a] = b[0x32] = size >> 40; - b[0x2b] = b[0x33] = size >> 32; - b[0x2c] = b[0x34] = size >> 24; - b[0x2d] = b[0x35] = size >> 16; - b[0x2e] = b[0x36] = size >> 8; - b[0x2f] = b[0x37] = size >> 0; - getchs2 (&hfd, &cyl, &cylsec, &head, &tracksec); - // cylinders - b[0x38] = cyl >> 8; - b[0x39] = cyl; - // heads - b[0x3a] = head; - // sectors per track - b[0x3b] = tracksec; - // disk type - b[0x3c + 3] = VHD_DYNAMIC; - get_guid_target (b + 0x44); - crc = vhd_checksum (b, -1); - b[0x40] = crc >> 24; - b[0x41] = crc >> 16; - b[0x42] = crc >> 8; - b[0x43] = crc >> 0; - - // write header - zfile_fseek (zf, 0, SEEK_SET); - zfile_fwrite (b, 512, 1, zf); - // write footer - zfile_fseek (zf, 512 + 1024 + batsize, SEEK_SET); - zfile_fwrite (b, 512, 1, zf); - - // dynamic disk header - memset (b, 0, 1024); - // cookie - strcpy (b, "cxsparse"); - // data offset - for (i = 0; i < 8; i++) - b[0x08 + i] = 0xff; - // table offset (bat) - b[0x10 + 6] = 0x06; - // version - b[0x19] = 1; - // max table entries - b[0x1c] = batentrysize >> 24; - b[0x1d] = batentrysize >> 16; - b[0x1e] = batentrysize >> 8; - b[0x1f] = batentrysize >> 0; - b[0x20] = blocksize >> 24; - b[0x21] = blocksize >> 16; - b[0x22] = blocksize >> 8; - b[0x23] = blocksize >> 0; - crc = vhd_checksum (b, -1); - b[0x24] = crc >> 24; - b[0x25] = crc >> 16; - b[0x26] = crc >> 8; - b[0x27] = crc >> 0; - - // write dynamic header - zfile_fseek (zf, 512, SEEK_SET); - zfile_fwrite (b, 1024, 1, zf); - - // bat - memset (b, 0, batsize); - memset (b, 0xff, batentrysize * 4); - zfile_fwrite (b, batsize, 1, zf); - - ret = 1; + struct hardfiledata hfd; + struct zfile *zf; + uae_u8 *b; + int cyl, cylsec, head, tracksec; + uae_u32 crc, blocksize, batsize, batentrysize; + int ret, i; + time_t tm; + + if (size >= (uae_u64)10 * 1024 * 1024 * 1024) + blocksize = 2 * 1024 * 1024; + else + blocksize = 512 * 1024; + batsize = (size + blocksize - 1) / blocksize; + batentrysize = batsize; + batsize *= 4; + batsize += 511; + batsize &= ~511; + ret = 0; + b = NULL; + zf = zfile_fopen (name, L"wb", 0); + if (!zf) + goto end; + b = xcalloc (512 + 1024 + batsize + 512, 1); + if (zfile_fwrite (b, 512 + 1024 + batsize + 512, 1, zf) != 1) + goto end; + + memset (&hfd, 0, sizeof hfd); + hfd.virtsize = hfd.physsize = size; + hfd.blocksize = 512; + strcpy (b, "conectix"); // cookie + b[0x0b] = 2; // features + b[0x0d] = 1; // version + b[0x10 + 6] = 2; // data offset + // time stamp + tm = time (NULL) - 946684800; + b[0x18] = tm >> 24; + b[0x19] = tm >> 16; + b[0x1a] = tm >> 8; + b[0x1b] = tm >> 0; + strcpy (b + 0x1c, "vpc "); // creator application + b[0x21] = 5; // creator version + strcpy (b + 0x24, "Wi2k"); // creator host os + // original and current size + b[0x28] = b[0x30] = size >> 56; + b[0x29] = b[0x31] = size >> 48; + b[0x2a] = b[0x32] = size >> 40; + b[0x2b] = b[0x33] = size >> 32; + b[0x2c] = b[0x34] = size >> 24; + b[0x2d] = b[0x35] = size >> 16; + b[0x2e] = b[0x36] = size >> 8; + b[0x2f] = b[0x37] = size >> 0; + getchs2 (&hfd, &cyl, &cylsec, &head, &tracksec); + // cylinders + b[0x38] = cyl >> 8; + b[0x39] = cyl; + // heads + b[0x3a] = head; + // sectors per track + b[0x3b] = tracksec; + // disk type + b[0x3c + 3] = VHD_DYNAMIC; + get_guid_target (b + 0x44); + crc = vhd_checksum (b, -1); + b[0x40] = crc >> 24; + b[0x41] = crc >> 16; + b[0x42] = crc >> 8; + b[0x43] = crc >> 0; + + // write header + zfile_fseek (zf, 0, SEEK_SET); + zfile_fwrite (b, 512, 1, zf); + // write footer + zfile_fseek (zf, 512 + 1024 + batsize, SEEK_SET); + zfile_fwrite (b, 512, 1, zf); + + // dynamic disk header + memset (b, 0, 1024); + // cookie + strcpy (b, "cxsparse"); + // data offset + for (i = 0; i < 8; i++) + b[0x08 + i] = 0xff; + // table offset (bat) + b[0x10 + 6] = 0x06; + // version + b[0x19] = 1; + // max table entries + b[0x1c] = batentrysize >> 24; + b[0x1d] = batentrysize >> 16; + b[0x1e] = batentrysize >> 8; + b[0x1f] = batentrysize >> 0; + b[0x20] = blocksize >> 24; + b[0x21] = blocksize >> 16; + b[0x22] = blocksize >> 8; + b[0x23] = blocksize >> 0; + crc = vhd_checksum (b, -1); + b[0x24] = crc >> 24; + b[0x25] = crc >> 16; + b[0x26] = crc >> 8; + b[0x27] = crc >> 0; + + // write dynamic header + zfile_fseek (zf, 512, SEEK_SET); + zfile_fwrite (b, 1024, 1, zf); + + // bat + memset (b, 0, batsize); + memset (b, 0xff, batentrysize * 4); + zfile_fwrite (b, batsize, 1, zf); + + ret = 1; end: - xfree (b); - zfile_fclose (zf); - return ret; + xfree (b); + zfile_fclose (zf); + return ret; } static uae_u64 vhd_read (struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { - uae_u32 bamoffset; - uae_u32 sectoroffset; - uae_u64 read; - - //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); - read = 0; - if (offset & 511) - return read; - if (len & 511) - return read; - while (len > 0) { - bamoffset = (offset / hfd->vhd_blocksize) * 4 + hfd->vhd_bamoffset; - sectoroffset = gl (hfd->vhd_header + bamoffset); - if (sectoroffset == 0xffffffff) { - memset (dataptr, 0, 512); - read += 512; - } else { - int bitmapoffsetbits; - int bitmapoffsetbytes; - int sectormapblock; - - bitmapoffsetbits = (offset / 512) % (hfd->vhd_blocksize / 512); - bitmapoffsetbytes = bitmapoffsetbits / 8; - sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); - if (hfd->vhd_sectormapblock != sectormapblock) { - // read sector bitmap - //write_log (L"BM %08x\n", sectormapblock); - if (hdf_read_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) - return read; - hfd->vhd_sectormapblock = sectormapblock; - } - // block allocated in bitmap? - if (hfd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7)))) { - // read data block - int block = sectoroffset * 512 + hfd->vhd_bitmapsize + bitmapoffsetbits * 512; - //write_log (L"DB %08x\n", block); - if (hdf_read_target (hfd, dataptr, block, 512) != 512) - return read; - } else { - memset (dataptr, 0, 512); - } - read += 512; + uae_u32 bamoffset; + uae_u32 sectoroffset; + uae_u64 read; + + //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); + read = 0; + if (offset & 511) + return read; + if (len & 511) + return read; + while (len > 0) { + bamoffset = (offset / hfd->vhd_blocksize) * 4 + hfd->vhd_bamoffset; + sectoroffset = gl (hfd->vhd_header + bamoffset); + if (sectoroffset == 0xffffffff) { + memset (dataptr, 0, 512); + read += 512; + } else { + int bitmapoffsetbits; + int bitmapoffsetbytes; + int sectormapblock; + + bitmapoffsetbits = (offset / 512) % (hfd->vhd_blocksize / 512); + bitmapoffsetbytes = bitmapoffsetbits / 8; + sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); + if (hfd->vhd_sectormapblock != sectormapblock) { + // read sector bitmap + //write_log (L"BM %08x\n", sectormapblock); + if (hdf_read_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) { + write_log (L"vhd_read: bitmap read error\n"); + return read; + } + hfd->vhd_sectormapblock = sectormapblock; + } + // block allocated in bitmap? + if (hfd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7)))) { + // read data block + int block = sectoroffset * 512 + hfd->vhd_bitmapsize + bitmapoffsetbits * 512; + //write_log (L"DB %08x\n", block); + if (hdf_read_target (hfd, dataptr, block, 512) != 512) { + write_log (L"vhd_read: data read error\n"); + return read; + } + } else { + memset (dataptr, 0, 512); + } + read += 512; + } + len -= 512; + dataptr += 512; + offset += 512; } - len -= 512; - dataptr += 512; - offset += 512; - } - return read; + return read; } static int vhd_write_enlarge (struct hardfiledata *hfd, uae_u32 bamoffset) { - uae_u8 *buf, *p; - int len = hfd->vhd_blocksize + hfd->vhd_bitmapsize + 512; - uae_u32 block; - int v; - - buf = xcalloc (len, 1); - if (!hdf_resize_target (hfd, hfd->physsize + len - 512)) - return 0; - // add footer (same as 512 byte header) - memcpy (buf + hfd->vhd_bitmapsize + hfd->vhd_blocksize, hfd->vhd_header, 512); - v = hdf_write_target (hfd, buf, hfd->vhd_footerblock, len); - xfree (buf); - if (v != len) - return 0; - // write new offset to BAM - p = hfd->vhd_header + bamoffset; - block = hfd->vhd_footerblock / 512; - p[0] = block >> 24; - p[1] = block >> 16; - p[2] = block >> 8; - p[3] = block >> 0; - // write to disk - if (hdf_write_target (hfd, hfd->vhd_header + hfd->vhd_bamoffset, hfd->vhd_bamoffset, hfd->vhd_bamsize) != hfd->vhd_bamsize) - return 0; - hfd->vhd_footerblock += len - 512; - return 1; + uae_u8 *buf, *p; + int len; + uae_u32 block; + int v; + + len = hfd->vhd_blocksize + hfd->vhd_bitmapsize + 512; + buf = xcalloc (len, 1); + if (!hdf_resize_target (hfd, hfd->physsize + len - 512)) { + write_log (L"vhd_enlarge: failure\n"); + return 0; + } + // add footer (same as 512 byte header) + memcpy (buf + len - 512, hfd->vhd_header, 512); + v = hdf_write_target (hfd, buf, hfd->vhd_footerblock, len); + xfree (buf); + if (v != len) { + write_log (L"vhd_enlarge: footer write error\n"); + return 0; + } + // write new offset to BAM + p = hfd->vhd_header + bamoffset; + block = hfd->vhd_footerblock / 512; + p[0] = block >> 24; + p[1] = block >> 16; + p[2] = block >> 8; + p[3] = block >> 0; + // write to disk + if (hdf_write_target (hfd, hfd->vhd_header + hfd->vhd_bamoffset, hfd->vhd_bamoffset, hfd->vhd_bamsize) != hfd->vhd_bamsize) { + write_log (L"vhd_enlarge: bam write error\n"); + return 0; + } + hfd->vhd_footerblock += len - 512; + return 1; } static uae_u64 vhd_write (struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { - uae_u32 bamoffset; - uae_u32 sectoroffset; - uae_u64 written; + uae_u32 bamoffset; + uae_u32 sectoroffset; + uae_u64 written; - //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); - written = 0; - if (offset & 511) - return written; - if (len & 511) - return written; - while (len > 0) { - bamoffset = (offset / hfd->vhd_blocksize) * 4 + hfd->vhd_bamoffset; - sectoroffset = gl (hfd->vhd_header + bamoffset); - if (sectoroffset == 0xffffffff) { - if (!vhd_write_enlarge (hfd, bamoffset)) + //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); + written = 0; + if (offset & 511) return written; - continue; - } else { - int bitmapoffsetbits; - int bitmapoffsetbytes; - int sectormapblock; - - bitmapoffsetbits = (offset / 512) % (hfd->vhd_blocksize / 512); - bitmapoffsetbytes = bitmapoffsetbits / 8; - sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); - if (hfd->vhd_sectormapblock != sectormapblock) { - // read sector bitmap - if (hdf_read_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) - return written; - hfd->vhd_sectormapblock = sectormapblock; - } - // write data - if (hdf_write_target (hfd, dataptr, sectoroffset * 512 + hfd->vhd_bitmapsize + bitmapoffsetbits * 512, 512) != 512) - return written; - // block already allocated in bitmap? - if (!(hfd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7))))) { - // no, we need to mark it allocated and write the modified bitmap back to the disk - int j; - for (j = 0; j < 512 / 4; j++) { - if (((uae_u32*)dataptr)[j]) - break; - } - if (j < 512 / 4) { - // only mark it if there was non-zero data written - hfd->vhd_sectormap[bitmapoffsetbytes & 511] |= (1 << (7 - (bitmapoffsetbits & 7))); - if (hdf_write_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) - return written; + if (len & 511) + return written; + while (len > 0) { + bamoffset = (offset / hfd->vhd_blocksize) * 4 + hfd->vhd_bamoffset; + sectoroffset = gl (hfd->vhd_header + bamoffset); + if (sectoroffset == 0xffffffff) { + if (!vhd_write_enlarge (hfd, bamoffset)) + return written; + continue; + } else { + int bitmapoffsetbits; + int bitmapoffsetbytes; + int sectormapblock; + + bitmapoffsetbits = (offset / 512) % (hfd->vhd_blocksize / 512); + bitmapoffsetbytes = bitmapoffsetbits / 8; + sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); + if (hfd->vhd_sectormapblock != sectormapblock) { + // read sector bitmap + if (hdf_read_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) { + write_log (L"vhd_write: bitmap read error\n"); + return written; + } + hfd->vhd_sectormapblock = sectormapblock; + } + // write data + if (hdf_write_target (hfd, dataptr, sectoroffset * 512 + hfd->vhd_bitmapsize + bitmapoffsetbits * 512, 512) != 512) { + write_log (L"vhd_write: data write error\n"); + return written; + } + // block already allocated in bitmap? + if (!(hfd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7))))) { + // no, we need to mark it allocated and write the modified bitmap back to the disk + int j; + for (j = 0; j < 512 / 4; j++) { + if (((uae_u32*)dataptr)[j]) + break; + } + if (j < 512 / 4) { + // only mark it if there was non-zero data written + hfd->vhd_sectormap[bitmapoffsetbytes & 511] |= (1 << (7 - (bitmapoffsetbits & 7))); + if (hdf_write_target (hfd, hfd->vhd_sectormap, sectormapblock, 512) != 512) { + write_log (L"vhd_write: bam write error\n"); + return written; + } + } + } + written += 512; } - } - written += 512; + len -= 512; + dataptr += 512; + offset += 512; } - len -= 512; - dataptr += 512; - offset += 512; - } - return written; + return written; } static int hdf_read2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - if (hfd->vhd_type == VHD_DYNAMIC) - return vhd_read (hfd, buffer, offset, len); - else if (hfd->vhd_type == VHD_FIXED) - return hdf_read_target (hfd, buffer, offset + 512, len); - else - return hdf_read_target (hfd, buffer, offset, len); + if (hfd->vhd_type == VHD_DYNAMIC) + return vhd_read (hfd, buffer, offset, len); + else if (hfd->vhd_type == VHD_FIXED) + return hdf_read_target (hfd, buffer, offset + 512, len); + else + return hdf_read_target (hfd, buffer, offset, len); } static void adide_decode (uae_u8 *buffer, int len) { - int i; - for (i = 0; i < len; i += 2) { - uae_u8 *b = buffer + i; - uae_u16 w = (b[0] << 8) | (b[1] << 0); - uae_u16 o = 0; - - if (w & 0x8000) - o |= 0x0001; - if (w & 0x0001) - o |= 0x0002; - - if (w & 0x4000) - o |= 0x0004; - if (w & 0x0002) - o |= 0x0008; - - if (w & 0x2000) - o |= 0x0010; - if (w & 0x0004) - o |= 0x0020; - - if (w & 0x1000) - o |= 0x0040; - if (w & 0x0008) - o |= 0x0080; - - if (w & 0x0800) - o |= 0x0100; - if (w & 0x0010) - o |= 0x0200; - - if (w & 0x0400) - o |= 0x0400; - if (w & 0x0020) - o |= 0x0800; - - if (w & 0x0200) - o |= 0x1000; - if (w & 0x0040) - o |= 0x2000; - - if (w & 0x0100) - o |= 0x4000; - if (w & 0x0080) - o |= 0x8000; - - b[0] = o >> 8; - b[1] = o >> 0; - } + int i; + for (i = 0; i < len; i += 2) { + uae_u8 *b = buffer + i; + uae_u16 w = (b[0] << 8) | (b[1] << 0); + uae_u16 o = 0; + + if (w & 0x8000) + o |= 0x0001; + if (w & 0x0001) + o |= 0x0002; + + if (w & 0x4000) + o |= 0x0004; + if (w & 0x0002) + o |= 0x0008; + + if (w & 0x2000) + o |= 0x0010; + if (w & 0x0004) + o |= 0x0020; + + if (w & 0x1000) + o |= 0x0040; + if (w & 0x0008) + o |= 0x0080; + + if (w & 0x0800) + o |= 0x0100; + if (w & 0x0010) + o |= 0x0200; + + if (w & 0x0400) + o |= 0x0400; + if (w & 0x0020) + o |= 0x0800; + + if (w & 0x0200) + o |= 0x1000; + if (w & 0x0040) + o |= 0x2000; + + if (w & 0x0100) + o |= 0x4000; + if (w & 0x0080) + o |= 0x8000; + + b[0] = o >> 8; + b[1] = o >> 0; + } } static void adide_encode (uae_u8 *buffer, int len) { - int i; - for (i = 0; i < len; i += 2) { - uae_u8 *b = buffer + i; - uae_u16 w = (b[0] << 8) | (b[1] << 0); - uae_u16 o = 0; - - if (w & 0x0001) - o |= 0x8000; - if (w & 0x0002) - o |= 0x0001; - - if (w & 0x0004) - o |= 0x4000; - if (w & 0x0008) - o |= 0x0002; - - if (w & 0x0010) - o |= 0x2000; - if (w & 0x0020) - o |= 0x0004; - - if (w & 0x0040) - o |= 0x1000; - if (w & 0x0080) - o |= 0x0008; - - if (w & 0x0100) - o |= 0x0800; - if (w & 0x0200) - o |= 0x0010; - - if (w & 0x0400) - o |= 0x0400; - if (w & 0x0800) - o |= 0x0020; - - if (w & 0x1000) - o |= 0x0200; - if (w & 0x2000) - o |= 0x0040; - - if (w & 0x4000) - o |= 0x0100; - if (w & 0x8000) - o |= 0x0080; - - b[0] = o >> 8; - b[1] = o >> 0; - } + int i; + for (i = 0; i < len; i += 2) { + uae_u8 *b = buffer + i; + uae_u16 w = (b[0] << 8) | (b[1] << 0); + uae_u16 o = 0; + + if (w & 0x0001) + o |= 0x8000; + if (w & 0x0002) + o |= 0x0001; + + if (w & 0x0004) + o |= 0x4000; + if (w & 0x0008) + o |= 0x0002; + + if (w & 0x0010) + o |= 0x2000; + if (w & 0x0020) + o |= 0x0004; + + if (w & 0x0040) + o |= 0x1000; + if (w & 0x0080) + o |= 0x0008; + + if (w & 0x0100) + o |= 0x0800; + if (w & 0x0200) + o |= 0x0010; + + if (w & 0x0400) + o |= 0x0400; + if (w & 0x0800) + o |= 0x0020; + + if (w & 0x1000) + o |= 0x0200; + if (w & 0x2000) + o |= 0x0040; + + if (w & 0x4000) + o |= 0x0100; + if (w & 0x8000) + o |= 0x0080; + + b[0] = o >> 8; + b[1] = o >> 0; + } } static void hdf_byteswap (uae_u8 *b, int len) { - int i; - for (i = 0; i < len; i += 2) { - uae_u8 tmp = b[i]; - b[i] = b[i + 1]; - b[i + 1] = tmp; - } + int i; + for (i = 0; i < len; i += 2) { + uae_u8 tmp = b[i]; + b[i] = b[i + 1]; + b[i + 1] = tmp; + } } int hdf_read (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - int v; - - if (!hfd->adide) { - v = hdf_read2 (hfd, buffer, offset, len); - } else { - offset += 512; - v = hdf_read2 (hfd, buffer, offset, len); - adide_decode (buffer, len); - } - if (hfd->byteswap) - hdf_byteswap (buffer, len); - return v; + int v; + + if (!hfd->adide) { + v = hdf_read2 (hfd, buffer, offset, len); + } else { + offset += 512; + v = hdf_read2 (hfd, buffer, offset, len); + adide_decode (buffer, len); + } + if (hfd->byteswap) + hdf_byteswap (buffer, len); + return v; } static int hdf_write2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - if (hfd->vhd_type == VHD_DYNAMIC) - return vhd_write (hfd, buffer, offset, len); - else if (hfd->vhd_type == VHD_FIXED) - return hdf_write_target (hfd, buffer, offset + 512, len); - else - return hdf_write_target (hfd, buffer, offset, len); + if (hfd->vhd_type == VHD_DYNAMIC) + return vhd_write (hfd, buffer, offset, len); + else if (hfd->vhd_type == VHD_FIXED) + return hdf_write_target (hfd, buffer, offset + 512, len); + else + return hdf_write_target (hfd, buffer, offset, len); } int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - int v; - - if (hfd->byteswap) - hdf_byteswap (buffer, len); - if (!hfd->adide) { - v = hdf_write2 (hfd, buffer, offset, len); - } else { - offset += 512; - adide_encode (buffer, len); - v = hdf_write2 (hfd, buffer, offset, len); - adide_decode (buffer, len); - } - if (hfd->byteswap) - hdf_byteswap (buffer, len); - return v; + int v; + + if (hfd->byteswap) + hdf_byteswap (buffer, len); + if (!hfd->adide) { + v = hdf_write2 (hfd, buffer, offset, len); + } else { + offset += 512; + adide_encode (buffer, len); + v = hdf_write2 (hfd, buffer, offset, len); + adide_decode (buffer, len); + } + if (hfd->byteswap) + hdf_byteswap (buffer, len); + return v; } static uae_u64 cmd_readx (struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { - gui_hd_led (hfd->unitnum, 1); - hf_log3 ("cmd_read: %p %04x-%08x (%d) %08x (%d)\n", - dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)(offset / hfd->blocksize), (uae_u32)len, (uae_u32)(len / hfd->blocksize)); - return hdf_read (hfd, dataptr, offset, len); + gui_hd_led (hfd->unitnum, 1); + hf_log3 ("cmd_read: %p %04x-%08x (%d) %08x (%d)\n", + dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)(offset / hfd->blocksize), (uae_u32)len, (uae_u32)(len / hfd->blocksize)); + return hdf_read (hfd, dataptr, offset, len); } static uae_u64 cmd_read (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 offset, uae_u64 len) { - addrbank *bank_data = &get_mem_bank (dataptr); - if (!bank_data || !bank_data->check (dataptr, len)) - return 0; - return cmd_readx (hfd, bank_data->xlateaddr (dataptr), offset, len); + addrbank *bank_data = &get_mem_bank (dataptr); + if (!bank_data || !bank_data->check (dataptr, len)) + return 0; + return cmd_readx (hfd, bank_data->xlateaddr (dataptr), offset, len); } static uae_u64 cmd_writex (struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { - gui_hd_led (hfd->unitnum, 2); - hf_log3 ("cmd_write: %p %04x-%08x (%d) %08x (%d)\n", - dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)(offset / hfd->blocksize), (uae_u32)len, (uae_u32)(len / hfd->blocksize)); - return hdf_write (hfd, dataptr, offset, len); + gui_hd_led (hfd->unitnum, 2); + hf_log3 ("cmd_write: %p %04x-%08x (%d) %08x (%d)\n", + dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)(offset / hfd->blocksize), (uae_u32)len, (uae_u32)(len / hfd->blocksize)); + return hdf_write (hfd, dataptr, offset, len); } static uae_u64 cmd_write (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 offset, uae_u64 len) { - addrbank *bank_data = &get_mem_bank (dataptr); - if (!bank_data || !bank_data->check (dataptr, len)) - return 0; - return cmd_writex (hfd, bank_data->xlateaddr (dataptr), offset, len); + addrbank *bank_data = &get_mem_bank (dataptr); + if (!bank_data || !bank_data->check (dataptr, len)) + return 0; + return cmd_writex (hfd, bank_data->xlateaddr (dataptr), offset, len); } static int checkbounds(struct hardfiledata *hfd, uae_u64 offset, uae_u64 len) { - if (offset >= hfd->physsize) - return 0; - if (offset + len > hfd->physsize) - return 0; - return 1; + if (offset >= hfd->physsize) + return 0; + if (offset + len > hfd->physsize) + return 0; + return 1; } static int nodisk (struct hardfiledata *hfd) { - if (hfd->drive_empty) - return 1; - return 0; + if (hfd->drive_empty) + return 1; + return 0; } int scsi_emulate (struct hardfiledata *hfd, struct hd_hardfiledata *hdhfd, uae_u8 *cmdbuf, int scsi_cmd_len, - uae_u8 *scsi_data, int *data_len, uae_u8 *r, int *reply_len, uae_u8 *s, int *sense_len) + uae_u8 *scsi_data, int *data_len, uae_u8 *r, int *reply_len, uae_u8 *s, int *sense_len) { - uae_u64 len, offset; - int lr = 0, ls = 0; - int scsi_len = -1; - int status = 0; - int i; - char *ss; - - *reply_len = *sense_len = 0; - memset (r, 0, 256); - memset (s, 0, 256); - switch (cmdbuf[0]) - { + uae_u64 len, offset; + int lr = 0, ls = 0; + int scsi_len = -1; + int status = 0; + int i; + char *ss; + + *reply_len = *sense_len = 0; + memset (r, 0, 256); + memset (s, 0, 256); + switch (cmdbuf[0]) + { case 0x00: /* TEST UNIT READY */ - if (nodisk (hfd)) - goto nodisk; - break; + if (nodisk (hfd)) + goto nodisk; + break; case 0x08: /* READ (6) */ - if (nodisk (hfd)) - goto nodisk; - offset = ((cmdbuf[1] & 31) << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; - offset *= hfd->blocksize; - len = cmdbuf[4]; - if (!len) - len = 256; - len *= hfd->blocksize; - if (checkbounds(hfd, offset, len)) - scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + offset = ((cmdbuf[1] & 31) << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; + offset *= hfd->blocksize; + len = cmdbuf[4]; + if (!len) + len = 256; + len *= hfd->blocksize; + if (checkbounds(hfd, offset, len)) + scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); + break; case 0x0a: /* WRITE (6) */ - if (nodisk (hfd)) - goto nodisk; - if (hfd->readonly || hfd->dangerous) - goto readprot; - offset = ((cmdbuf[1] & 31) << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; - offset *= hfd->blocksize; - len = cmdbuf[4]; - if (!len) - len = 256; - len *= hfd->blocksize; - if (checkbounds(hfd, offset, len)) - scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + if (hfd->readonly || hfd->dangerous) + goto readprot; + offset = ((cmdbuf[1] & 31) << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; + offset *= hfd->blocksize; + len = cmdbuf[4]; + if (!len) + len = 256; + len *= hfd->blocksize; + if (checkbounds(hfd, offset, len)) + scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); + break; case 0x12: /* INQUIRY */ - if ((cmdbuf[1] & 1) || cmdbuf[2] != 0) - goto err; - len = cmdbuf[4]; - if (cmdbuf[1] >> 5) - goto err;//r[0] = 0x7f; /* no lun supported */ - if (hfd->drive_empty) - r[1] |= 0x80; // removable.. - r[2] = 2; /* supports SCSI-2 */ - r[3] = 2; /* response data format */ - r[4] = 32; /* additional length */ - r[7] = 0x20; /* 16 bit bus */ - scsi_len = lr = len < 36 ? (uae_u32)len : 36; - if (hdhfd) { - r[2] = hdhfd->ansi_version; - r[3] = hdhfd->ansi_version >= 2 ? 2 : 0; - } - ss = ua (hfd->vendor_id); - i = 0; /* vendor id */ - while (i < 8 && ss[i]) { - r[8 + i] = ss[i]; - i++; - } - while (i < 8) { - r[8 + i] = 32; - i++; - } - xfree (ss); - ss = ua (hfd->product_id); - i = 0; /* product id */ - while (i < 16 && ss[i]) { - r[16 + i] = ss[i]; - i++; - } - while (i < 16) { - r[16 + i] = 32; - i++; - } - xfree (ss); - ss = ua (hfd->product_rev); - i = 0; /* product revision */ - while (i < 4 && ss[i]) { - r[32 + i] = ss[i]; - i++; - } - while (i < 4) { - r[32 + i] = 32; - i++; - } - xfree (ss); - break; + if ((cmdbuf[1] & 1) || cmdbuf[2] != 0) + goto err; + len = cmdbuf[4]; + if (cmdbuf[1] >> 5) + goto err;//r[0] = 0x7f; /* no lun supported */ + if (hfd->drive_empty) + r[1] |= 0x80; // removable.. + r[2] = 2; /* supports SCSI-2 */ + r[3] = 2; /* response data format */ + r[4] = 32; /* additional length */ + r[7] = 0x20; /* 16 bit bus */ + scsi_len = lr = len < 36 ? (uae_u32)len : 36; + if (hdhfd) { + r[2] = hdhfd->ansi_version; + r[3] = hdhfd->ansi_version >= 2 ? 2 : 0; + } + ss = ua (hfd->vendor_id); + i = 0; /* vendor id */ + while (i < 8 && ss[i]) { + r[8 + i] = ss[i]; + i++; + } + while (i < 8) { + r[8 + i] = 32; + i++; + } + xfree (ss); + ss = ua (hfd->product_id); + i = 0; /* product id */ + while (i < 16 && ss[i]) { + r[16 + i] = ss[i]; + i++; + } + while (i < 16) { + r[16 + i] = 32; + i++; + } + xfree (ss); + ss = ua (hfd->product_rev); + i = 0; /* product revision */ + while (i < 4 && ss[i]) { + r[32 + i] = ss[i]; + i++; + } + while (i < 4) { + r[32 + i] = 32; + i++; + } + xfree (ss); + break; case 0x1a: /* MODE SENSE(6) */ - { - uae_u8 *p; - int pc = cmdbuf[2] >> 6; - int pcode = cmdbuf[2] & 0x3f; - int dbd = cmdbuf[1] & 8; - int cyl, cylsec, head, tracksec; - if (nodisk (hfd)) - goto nodisk; - if (hdhfd) { - cyl = hdhfd->cyls; - head = hdhfd->heads; - tracksec = hdhfd->secspertrack; - cylsec = 0; - } else { - getchs (hfd, &cyl, &cylsec, &head, &tracksec); - } - //write_log (L"MODE SENSE PC=%d CODE=%d DBD=%d\n", pc, pcode, dbd); - p = r; - p[0] = 4 - 1; - p[1] = 0; - p[2] = 0; - p[3] = 0; - p += 4; - if (!dbd) { - uae_u32 blocks = (uae_u32)(hfd->virtsize / hfd->blocksize); - p[-1] = 8; - wl(p + 0, blocks); - wl(p + 4, hfd->blocksize); - p += 8; - } - if (pcode == 0) { - p[0] = 0; - p[1] = 0; - p[2] = 0x20; - p[3] = 0; - r[0] += 4; - } else if (pcode == 3) { - p[0] = 3; - p[1] = 24; - p[3] = 1; - p[10] = tracksec >> 8; - p[11] = tracksec; - p[12] = hfd->blocksize >> 8; - p[13] = hfd->blocksize; - p[15] = 1; // interleave - p[20] = 0x80; - r[0] += p[1]; - } else if (pcode == 4) { - p[0] = 4; - wl(p + 1, cyl); - p[1] = 24; - p[5] = head; - wl(p + 13, cyl); - ww(p + 20, 5400); - r[0] += p[1]; - } else { - goto err; - } - r[0] += r[3]; - scsi_len = lr = r[0] + 1; - break; - } - break; + { + uae_u8 *p; + int pc = cmdbuf[2] >> 6; + int pcode = cmdbuf[2] & 0x3f; + int dbd = cmdbuf[1] & 8; + int cyl, cylsec, head, tracksec; + if (nodisk (hfd)) + goto nodisk; + if (hdhfd) { + cyl = hdhfd->cyls; + head = hdhfd->heads; + tracksec = hdhfd->secspertrack; + cylsec = 0; + } else { + getchs (hfd, &cyl, &cylsec, &head, &tracksec); + } + //write_log (L"MODE SENSE PC=%d CODE=%d DBD=%d\n", pc, pcode, dbd); + p = r; + p[0] = 4 - 1; + p[1] = 0; + p[2] = 0; + p[3] = 0; + p += 4; + if (!dbd) { + uae_u32 blocks = (uae_u32)(hfd->virtsize / hfd->blocksize); + p[-1] = 8; + wl(p + 0, blocks); + wl(p + 4, hfd->blocksize); + p += 8; + } + if (pcode == 0) { + p[0] = 0; + p[1] = 0; + p[2] = 0x20; + p[3] = 0; + r[0] += 4; + } else if (pcode == 3) { + p[0] = 3; + p[1] = 24; + p[3] = 1; + p[10] = tracksec >> 8; + p[11] = tracksec; + p[12] = hfd->blocksize >> 8; + p[13] = hfd->blocksize; + p[15] = 1; // interleave + p[20] = 0x80; + r[0] += p[1]; + } else if (pcode == 4) { + p[0] = 4; + wl(p + 1, cyl); + p[1] = 24; + p[5] = head; + wl(p + 13, cyl); + ww(p + 20, 5400); + r[0] += p[1]; + } else { + goto err; + } + r[0] += r[3]; + scsi_len = lr = r[0] + 1; + break; + } + break; case 0x1d: /* SEND DIAGNOSTICS */ - break; + break; case 0x25: /* READ_CAPACITY */ - { - int pmi = cmdbuf[8] & 1; - uae_u32 lba = (cmdbuf[2] << 24) | (cmdbuf[3] << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; - uae_u32 blocks; - int cyl, cylsec, head, tracksec; - if (nodisk (hfd)) - goto nodisk; - blocks = (uae_u32)(hfd->virtsize / hfd->blocksize - 1); - if (hdhfd) { - cyl = hdhfd->cyls; - head = hdhfd->heads; - tracksec = hdhfd->secspertrack; - cylsec = 0; - } else { - getchs (hfd, &cyl, &cylsec, &head, &tracksec); - } - if (pmi) { - lba += tracksec * head; - lba /= tracksec * head; - lba *= tracksec * head; - if (lba > blocks) - lba = blocks; - blocks = lba; - } - wl (r, blocks); - wl (r + 4, hfd->blocksize); - scsi_len = lr = 8; - } - break; + { + int pmi = cmdbuf[8] & 1; + uae_u32 lba = (cmdbuf[2] << 24) | (cmdbuf[3] << 16) | (cmdbuf[2] << 8) | cmdbuf[3]; + uae_u32 blocks; + int cyl, cylsec, head, tracksec; + if (nodisk (hfd)) + goto nodisk; + blocks = (uae_u32)(hfd->virtsize / hfd->blocksize - 1); + if (hdhfd) { + cyl = hdhfd->cyls; + head = hdhfd->heads; + tracksec = hdhfd->secspertrack; + cylsec = 0; + } else { + getchs (hfd, &cyl, &cylsec, &head, &tracksec); + } + if (pmi) { + lba += tracksec * head; + lba /= tracksec * head; + lba *= tracksec * head; + if (lba > blocks) + lba = blocks; + blocks = lba; + } + wl (r, blocks); + wl (r + 4, hfd->blocksize); + scsi_len = lr = 8; + } + break; case 0x28: /* READ (10) */ - if (nodisk (hfd)) - goto nodisk; - offset = rl (cmdbuf + 2); - offset *= hfd->blocksize; - len = rl (cmdbuf + 7 - 2) & 0xffff; - len *= hfd->blocksize; - if (checkbounds (hfd, offset, len)) - scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + offset = rl (cmdbuf + 2); + offset *= hfd->blocksize; + len = rl (cmdbuf + 7 - 2) & 0xffff; + len *= hfd->blocksize; + if (checkbounds (hfd, offset, len)) + scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); + break; case 0x2a: /* WRITE (10) */ - if (nodisk (hfd)) - goto nodisk; - if (hfd->readonly || hfd->dangerous) - goto readprot; - offset = rl (cmdbuf + 2); - offset *= hfd->blocksize; - len = rl (cmdbuf + 7 - 2) & 0xffff; - len *= hfd->blocksize; - if (checkbounds (hfd, offset, len)) - scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + if (hfd->readonly || hfd->dangerous) + goto readprot; + offset = rl (cmdbuf + 2); + offset *= hfd->blocksize; + len = rl (cmdbuf + 7 - 2) & 0xffff; + len *= hfd->blocksize; + if (checkbounds (hfd, offset, len)) + scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); + break; #if 0 case 0x2f: /* VERIFY */ - { - int bytchk = cmdbuf[1] & 2; - if (nodisk (hfd)) - goto nodisk; - offset = rl (cmdbuf + 2); - offset *= hfd->blocksize; - len = rl (cmdbuf + 7 - 2) & 0xffff; - len *= hfd->blocksize; - if (checkbounds (hfd, offset, len)) { - uae_u8 *vb = xmalloc (hfd->blocksize); - while (len > 0) { - int len = cmd_readx (hfd, vb, offset, hfd->blocksize); - if (bytchk) { - if (memcmp (vb, scsi_data, hfd->blocksize)) - goto miscompare; - scsi_data += hfd->blocksize; - } - offset += hfd->blocksize; + { + int bytchk = cmdbuf[1] & 2; + if (nodisk (hfd)) + goto nodisk; + offset = rl (cmdbuf + 2); + offset *= hfd->blocksize; + len = rl (cmdbuf + 7 - 2) & 0xffff; + len *= hfd->blocksize; + if (checkbounds (hfd, offset, len)) { + uae_u8 *vb = xmalloc (hfd->blocksize); + while (len > 0) { + int len = cmd_readx (hfd, vb, offset, hfd->blocksize); + if (bytchk) { + if (memcmp (vb, scsi_data, hfd->blocksize)) + goto miscompare; + scsi_data += hfd->blocksize; + } + offset += hfd->blocksize; + } + xfree (vb); + } } - xfree (vb); - } - } - break; + break; #endif case 0x35: /* SYNCRONIZE CACHE (10) */ - if (nodisk (hfd)) - goto nodisk; - break; + if (nodisk (hfd)) + goto nodisk; + break; case 0xa8: /* READ (12) */ - if (nodisk (hfd)) - goto nodisk; - offset = rl (cmdbuf + 2); - offset *= hfd->blocksize; - len = rl (cmdbuf + 6); - len *= hfd->blocksize; - if (checkbounds(hfd, offset, len)) - scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + offset = rl (cmdbuf + 2); + offset *= hfd->blocksize; + len = rl (cmdbuf + 6); + len *= hfd->blocksize; + if (checkbounds(hfd, offset, len)) + scsi_len = (uae_u32)cmd_readx (hfd, scsi_data, offset, len); + break; case 0xaa: /* WRITE (12) */ - if (nodisk (hfd)) - goto nodisk; - if (hfd->readonly || hfd->dangerous) - goto readprot; - offset = rl (cmdbuf + 2); - offset *= hfd->blocksize; - len = rl (cmdbuf + 6); - len *= hfd->blocksize; - if (checkbounds(hfd, offset, len)) - scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); - break; + if (nodisk (hfd)) + goto nodisk; + if (hfd->readonly || hfd->dangerous) + goto readprot; + offset = rl (cmdbuf + 2); + offset *= hfd->blocksize; + len = rl (cmdbuf + 6); + len *= hfd->blocksize; + if (checkbounds(hfd, offset, len)) + scsi_len = (uae_u32)cmd_writex (hfd, scsi_data, offset, len); + break; case 0x37: /* READ DEFECT DATA */ - if (nodisk (hfd)) - goto nodisk; - status = 2; /* CHECK CONDITION */ - s[0] = 0x70; - s[2] = 0; /* NO SENSE */ - s[12] = 0x1c; /* DEFECT LIST NOT FOUND */ - ls = 12; - break; + if (nodisk (hfd)) + goto nodisk; + status = 2; /* CHECK CONDITION */ + s[0] = 0x70; + s[2] = 0; /* NO SENSE */ + s[12] = 0x1c; /* DEFECT LIST NOT FOUND */ + ls = 12; + break; readprot: - status = 2; /* CHECK CONDITION */ - s[0] = 0x70; - s[2] = 7; /* DATA PROTECT */ - s[12] = 0x27; /* WRITE PROTECTED */ - ls = 12; - break; + status = 2; /* CHECK CONDITION */ + s[0] = 0x70; + s[2] = 7; /* DATA PROTECT */ + s[12] = 0x27; /* WRITE PROTECTED */ + ls = 12; + break; nodisk: - status = 2; /* CHECK CONDITION */ - s[0] = 0x70; - s[2] = 2; /* NOT READY */ - s[12] = 0x3A; /* MEDIUM NOT PRESENT */ - ls = 12; - break; + status = 2; /* CHECK CONDITION */ + s[0] = 0x70; + s[2] = 2; /* NOT READY */ + s[12] = 0x3A; /* MEDIUM NOT PRESENT */ + ls = 12; + break; default: err: - lr = -1; - write_log (L"UAEHF: unsupported scsi command 0x%02X\n", cmdbuf[0]); - status = 2; /* CHECK CONDITION */ - s[0] = 0x70; - s[2] = 5; /* ILLEGAL REQUEST */ - s[12] = 0x24; /* ILLEGAL FIELD IN CDB */ - ls = 12; - break; + lr = -1; + write_log (L"UAEHF: unsupported scsi command 0x%02X\n", cmdbuf[0]); + status = 2; /* CHECK CONDITION */ + s[0] = 0x70; + s[2] = 5; /* ILLEGAL REQUEST */ + s[12] = 0x24; /* ILLEGAL FIELD IN CDB */ + ls = 12; + break; miscompare: - lr = -1; - status = 2; /* CHECK CONDITION */ - s[0] = 0x70; - s[2] = 5; /* ILLEGAL REQUEST */ - s[12] = 0x1d; /* MISCOMPARE DURING VERIFY OPERATION */ - ls = 12; - break; - } - *data_len = scsi_len; - *reply_len = lr; - *sense_len = ls; - return status; + lr = -1; + status = 2; /* CHECK CONDITION */ + s[0] = 0x70; + s[2] = 5; /* ILLEGAL REQUEST */ + s[12] = 0x1d; /* MISCOMPARE DURING VERIFY OPERATION */ + ls = 12; + break; + } + *data_len = scsi_len; + *reply_len = lr; + *sense_len = ls; + return status; } static int handle_scsi (uaecptr request, struct hardfiledata *hfd) { - uae_u32 acmd = get_long (request + 40); - uaecptr scsi_data = get_long (acmd + 0); - uae_u32 scsi_len = get_long (acmd + 4); - uaecptr scsi_cmd = get_long (acmd + 12); - uae_u16 scsi_cmd_len = get_word (acmd + 16); - uae_u8 scsi_flags = get_byte (acmd + 20); - uaecptr scsi_sense = get_long (acmd + 22); - uae_u16 scsi_sense_len = get_word (acmd + 26); - uae_u8 cmd = get_byte (scsi_cmd); - uae_u8 cmdbuf[256]; - int status, ret = 0, reply_len, sense_len; - uae_u32 i; - uae_u8 reply[256], sense[256]; - uae_u8 *scsi_data_ptr = NULL; - addrbank *bank_data = &get_mem_bank (scsi_data); - - if (bank_data && bank_data->check (scsi_data, scsi_len)) - scsi_data_ptr = bank_data->xlateaddr (scsi_data); - scsi_sense_len = (scsi_flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ - (scsi_flags & 2) ? scsi_sense_len : /* SCSIF_AUTOSENSE */ - 32; - status = 0; - memset (reply, 0, sizeof reply); - reply_len = 0; sense_len = 0; - scsi_log ("hdf scsiemu: cmd=%02X,%d flags=%02X sense=%p,%d data=%p,%d\n", - cmd, scsi_cmd_len, scsi_flags, scsi_sense, scsi_sense_len, scsi_data, scsi_len); - for (i = 0; i < scsi_cmd_len; i++) { - cmdbuf[i] = get_byte (scsi_cmd + i); - scsi_log ("%02X%c", get_byte (scsi_cmd + i), i < scsi_cmd_len - 1 ? '.' : ' '); - } - scsi_log ("\n"); - - status = scsi_emulate (hfd, NULL, cmdbuf, scsi_cmd_len, scsi_data_ptr, &scsi_len, reply, &reply_len, sense, &sense_len); - - put_word (acmd + 18, status != 0 ? 0 : scsi_cmd_len); /* fake scsi_CmdActual */ - put_byte (acmd + 21, status); /* scsi_Status */ - if (reply_len > 0) { - scsi_log ("RD:"); - i = 0; - while (i < reply_len) { - if (i < 24) - scsi_log ("%02X%c", reply[i], i < reply_len - 1 ? '.' : ' '); - put_byte (scsi_data + i, reply[i]); - i++; + uae_u32 acmd = get_long (request + 40); + uaecptr scsi_data = get_long (acmd + 0); + uae_u32 scsi_len = get_long (acmd + 4); + uaecptr scsi_cmd = get_long (acmd + 12); + uae_u16 scsi_cmd_len = get_word (acmd + 16); + uae_u8 scsi_flags = get_byte (acmd + 20); + uaecptr scsi_sense = get_long (acmd + 22); + uae_u16 scsi_sense_len = get_word (acmd + 26); + uae_u8 cmd = get_byte (scsi_cmd); + uae_u8 cmdbuf[256]; + int status, ret = 0, reply_len, sense_len; + uae_u32 i; + uae_u8 reply[256], sense[256]; + uae_u8 *scsi_data_ptr = NULL; + addrbank *bank_data = &get_mem_bank (scsi_data); + + if (bank_data && bank_data->check (scsi_data, scsi_len)) + scsi_data_ptr = bank_data->xlateaddr (scsi_data); + scsi_sense_len = (scsi_flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ + (scsi_flags & 2) ? scsi_sense_len : /* SCSIF_AUTOSENSE */ + 32; + status = 0; + memset (reply, 0, sizeof reply); + reply_len = 0; sense_len = 0; + scsi_log ("hdf scsiemu: cmd=%02X,%d flags=%02X sense=%p,%d data=%p,%d\n", + cmd, scsi_cmd_len, scsi_flags, scsi_sense, scsi_sense_len, scsi_data, scsi_len); + for (i = 0; i < scsi_cmd_len; i++) { + cmdbuf[i] = get_byte (scsi_cmd + i); + scsi_log ("%02X%c", get_byte (scsi_cmd + i), i < scsi_cmd_len - 1 ? '.' : ' '); } scsi_log ("\n"); - } - i = 0; - if (scsi_sense) { - while (i < sense_len && i < scsi_sense_len) { - put_byte (scsi_sense + i, sense[i]); - i++; + + status = scsi_emulate (hfd, NULL, cmdbuf, scsi_cmd_len, scsi_data_ptr, &scsi_len, reply, &reply_len, sense, &sense_len); + + put_word (acmd + 18, status != 0 ? 0 : scsi_cmd_len); /* fake scsi_CmdActual */ + put_byte (acmd + 21, status); /* scsi_Status */ + if (reply_len > 0) { + scsi_log ("RD:"); + i = 0; + while (i < reply_len) { + if (i < 24) + scsi_log ("%02X%c", reply[i], i < reply_len - 1 ? '.' : ' '); + put_byte (scsi_data + i, reply[i]); + i++; + } + scsi_log ("\n"); + } + i = 0; + if (scsi_sense) { + while (i < sense_len && i < scsi_sense_len) { + put_byte (scsi_sense + i, sense[i]); + i++; + } + } + while (i < scsi_sense_len && scsi_sense) { + put_byte (scsi_sense + i, 0); + i++; } - } - while (i < scsi_sense_len && scsi_sense) { - put_byte (scsi_sense + i, 0); - i++; - } - if (scsi_len < 0) { - put_long (acmd + 8, 0); /* scsi_Actual */ - ret = 20; - } else { - put_long (acmd + 8, scsi_len); /* scsi_Actual */ - } - return ret; + if (scsi_len < 0) { + put_long (acmd + 8, 0); /* scsi_Actual */ + ret = 20; + } else { + put_long (acmd + 8, scsi_len); /* scsi_Actual */ + } + return ret; } void hardfile_do_disk_change (struct uaedev_config_info *uci, int insert) { - int fsid = uci->configoffset; - int j; - int newstate = insert ? 0 : 1; - struct hardfiledata *hfd; - - if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { - gayle_modify_pcmcia_sram_unit (uci->rootdir, uci->readonly, insert); - return; - } - - hfd = get_hardfile_data (fsid); - if (!hfd) - return; - uae_sem_wait (&change_sem); - hardfpd[fsid].changenum++; - write_log (L"uaehf.device:%d media status=%d changenum=%d\n", fsid, insert, hardfpd[fsid].changenum); - hfd->drive_empty = newstate; - j = 0; - while (j < MAX_ASYNC_REQUESTS) { - if (hardfpd[fsid].d_request_type[j] == ASYNC_REQUEST_CHANGEINT) { - uae_Cause (hardfpd[fsid].d_request_data[j]); + int fsid = uci->configoffset; + int j; + int newstate = insert ? 0 : 1; + struct hardfiledata *hfd; + + if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { + gayle_modify_pcmcia_sram_unit (uci->rootdir, uci->readonly, insert); + return; } - j++; - } - if (hardfpd[fsid].changeint) - uae_Cause (hardfpd[fsid].changeint); - uae_sem_post (&change_sem); + + hfd = get_hardfile_data (fsid); + if (!hfd) + return; + uae_sem_wait (&change_sem); + hardfpd[fsid].changenum++; + write_log (L"uaehf.device:%d media status=%d changenum=%d\n", fsid, insert, hardfpd[fsid].changenum); + hfd->drive_empty = newstate; + j = 0; + while (j < MAX_ASYNC_REQUESTS) { + if (hardfpd[fsid].d_request_type[j] == ASYNC_REQUEST_CHANGEINT) { + uae_Cause (hardfpd[fsid].d_request_data[j]); + } + j++; + } + if (hardfpd[fsid].changeint) + uae_Cause (hardfpd[fsid].changeint); + uae_sem_post (&change_sem); } static int add_async_request (struct hardfileprivdata *hfpd, uaecptr request, int type, uae_u32 data) { - int i; - - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (hfpd->d_request[i] == request) { - hfpd->d_request_type[i] = type; - hfpd->d_request_data[i] = data; - hf_log ("old async request %p (%d) added\n", request, type); - return 0; + int i; + + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (hfpd->d_request[i] == request) { + hfpd->d_request_type[i] = type; + hfpd->d_request_data[i] = data; + hf_log ("old async request %p (%d) added\n", request, type); + return 0; + } + i++; } - i++; - } - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (hfpd->d_request[i] == 0) { - hfpd->d_request[i] = request; - hfpd->d_request_type[i] = type; - hfpd->d_request_data[i] = data; - hf_log ("async request %p (%d) added (total=%d)\n", request, type, i); - return 0; + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (hfpd->d_request[i] == 0) { + hfpd->d_request[i] = request; + hfpd->d_request_type[i] = type; + hfpd->d_request_data[i] = data; + hf_log ("async request %p (%d) added (total=%d)\n", request, type, i); + return 0; + } + i++; } - i++; - } - hf_log ("async request overflow %p!\n", request); - return -1; + hf_log ("async request overflow %p!\n", request); + return -1; } static int release_async_request (struct hardfileprivdata *hfpd, uaecptr request) { - int i = 0; - - while (i < MAX_ASYNC_REQUESTS) { - if (hfpd->d_request[i] == request) { - int type = hfpd->d_request_type[i]; - hfpd->d_request[i] = 0; - hfpd->d_request_data[i] = 0; - hfpd->d_request_type[i] = 0; - hf_log ("async request %p removed\n", request); - return type; + int i = 0; + + while (i < MAX_ASYNC_REQUESTS) { + if (hfpd->d_request[i] == request) { + int type = hfpd->d_request_type[i]; + hfpd->d_request[i] = 0; + hfpd->d_request_data[i] = 0; + hfpd->d_request_type[i] = 0; + hf_log ("async request %p removed\n", request); + return type; + } + i++; } - i++; - } - hf_log ("tried to remove non-existing request %p\n", request); - return -1; + hf_log ("tried to remove non-existing request %p\n", request); + return -1; } static void abort_async (struct hardfileprivdata *hfpd, uaecptr request, int errcode, int type) { - int i; - hf_log ("aborting async request %p\n", request); - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (hfpd->d_request[i] == request && hfpd->d_request_type[i] == ASYNC_REQUEST_TEMP) { - /* ASYNC_REQUEST_TEMP = request is processing */ - sleep_millis (1); - i = 0; - continue; + int i; + hf_log ("aborting async request %p\n", request); + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (hfpd->d_request[i] == request && hfpd->d_request_type[i] == ASYNC_REQUEST_TEMP) { + /* ASYNC_REQUEST_TEMP = request is processing */ + sleep_millis (1); + i = 0; + continue; + } + i++; } - i++; - } - i = release_async_request (hfpd, request); - if (i >= 0) - hf_log ("asyncronous request=%08X aborted, error=%d\n", request, errcode); + i = release_async_request (hfpd, request); + if (i >= 0) + hf_log ("asyncronous request=%08X aborted, error=%d\n", request, errcode); } static void *hardfile_thread (void *devs); static int start_thread (TrapContext *context, int unit) { - struct hardfileprivdata *hfpd = &hardfpd[unit]; + struct hardfileprivdata *hfpd = &hardfpd[unit]; - if (hfpd->thread_running) - return 1; - memset (hfpd, 0, sizeof (struct hardfileprivdata)); - hfpd->base = m68k_areg (regs, 6); - init_comm_pipe (&hfpd->requests, 100, 1); - uae_sem_init (&hfpd->sync_sem, 0, 0); - uae_start_thread (L"hardfile", hardfile_thread, hfpd, NULL); - uae_sem_wait (&hfpd->sync_sem); - return hfpd->thread_running; + if (hfpd->thread_running) + return 1; + memset (hfpd, 0, sizeof (struct hardfileprivdata)); + hfpd->base = m68k_areg (regs, 6); + init_comm_pipe (&hfpd->requests, 100, 1); + uae_sem_init (&hfpd->sync_sem, 0, 0); + uae_start_thread (L"hardfile", hardfile_thread, hfpd, NULL); + uae_sem_wait (&hfpd->sync_sem); + return hfpd->thread_running; } static int mangleunit (int unit) { - if (unit <= 99) - return unit; - if (unit == 100) - return 8; - if (unit == 110) - return 9; - return -1; + if (unit <= 99) + return unit; + if (unit == 100) + return 8; + if (unit == 110) + return 9; + return -1; } static uae_u32 REGPARAM2 hardfile_open (TrapContext *context) { - uaecptr ioreq = m68k_areg (regs, 1); /* IOReq */ - int unit = mangleunit (m68k_dreg (regs, 0)); - struct hardfileprivdata *hfpd = &hardfpd[unit]; - int err = IOERR_OPENFAIL; - int size = get_word (ioreq + 0x12); - - /* boot device port size == 0!? KS 1.x size = 12??? */ - if (size >= IOSTDREQ_SIZE || size == 0 || kickstart_version == 0xffff || kickstart_version < 39) { - /* Check unit number */ - if (unit >= 0) { - struct hardfiledata *hfd = get_hardfile_data (unit); - if (hfd && hfd->handle_valid && start_thread (context, unit)) { - put_word (hfpd->base + 32, get_word (hfpd->base + 32) + 1); - put_long (ioreq + 24, unit); /* io_Unit */ - put_byte (ioreq + 31, 0); /* io_Error */ - put_byte (ioreq + 8, 7); /* ln_type = NT_REPLYMSG */ - hf_log (L"hardfile_open, unit %d (%d), OK\n", unit, m68k_dreg (regs, 0)); - return 0; - } + uaecptr ioreq = m68k_areg (regs, 1); /* IOReq */ + int unit = mangleunit (m68k_dreg (regs, 0)); + struct hardfileprivdata *hfpd = &hardfpd[unit]; + int err = IOERR_OPENFAIL; + int size = get_word (ioreq + 0x12); + + /* boot device port size == 0!? KS 1.x size = 12??? */ + if (size >= IOSTDREQ_SIZE || size == 0 || kickstart_version == 0xffff || kickstart_version < 39) { + /* Check unit number */ + if (unit >= 0) { + struct hardfiledata *hfd = get_hardfile_data (unit); + if (hfd && hfd->handle_valid && start_thread (context, unit)) { + put_word (hfpd->base + 32, get_word (hfpd->base + 32) + 1); + put_long (ioreq + 24, unit); /* io_Unit */ + put_byte (ioreq + 31, 0); /* io_Error */ + put_byte (ioreq + 8, 7); /* ln_type = NT_REPLYMSG */ + hf_log (L"hardfile_open, unit %d (%d), OK\n", unit, m68k_dreg (regs, 0)); + return 0; + } + } + if (unit < 1000 || is_hardfile (unit) == FILESYS_VIRTUAL) + err = 50; /* HFERR_NoBoard */ + } else { + err = IOERR_BADLENGTH; } - if (unit < 1000 || is_hardfile (unit) == FILESYS_VIRTUAL) - err = 50; /* HFERR_NoBoard */ - } else { - err = IOERR_BADLENGTH; - } - hf_log (L"hardfile_open, unit %d (%d), ERR=%d\n", unit, m68k_dreg (regs, 0), err); - put_long (ioreq + 20, (uae_u32)err); - put_byte (ioreq + 31, (uae_u8)err); - return (uae_u32)err; + hf_log (L"hardfile_open, unit %d (%d), ERR=%d\n", unit, m68k_dreg (regs, 0), err); + put_long (ioreq + 20, (uae_u32)err); + put_byte (ioreq + 31, (uae_u8)err); + return (uae_u32)err; } static uae_u32 REGPARAM2 hardfile_close (TrapContext *context) { - uaecptr request = m68k_areg (regs, 1); /* IOReq */ - int unit = mangleunit (get_long (request + 24)); - struct hardfileprivdata *hfpd = &hardfpd[unit]; + uaecptr request = m68k_areg (regs, 1); /* IOReq */ + int unit = mangleunit (get_long (request + 24)); + struct hardfileprivdata *hfpd = &hardfpd[unit]; - if (!hfpd) + if (!hfpd) + return 0; + put_word (hfpd->base + 32, get_word (hfpd->base + 32) - 1); + if (get_word (hfpd->base + 32) == 0) + write_comm_pipe_u32 (&hfpd->requests, 0, 1); return 0; - put_word (hfpd->base + 32, get_word (hfpd->base + 32) - 1); - if (get_word (hfpd->base + 32) == 0) - write_comm_pipe_u32 (&hfpd->requests, 0, 1); - return 0; } static uae_u32 REGPARAM2 hardfile_expunge (TrapContext *context) { - return 0; /* Simply ignore this one... */ + return 0; /* Simply ignore this one... */ } static void outofbounds (int cmd, uae_u64 offset, uae_u64 len, uae_u64 max) { - write_log (L"UAEHF: cmd %d: out of bounds, %08X-%08X + %08X-%08X > %08X-%08X\n", cmd, - (uae_u32)(offset >> 32),(uae_u32)offset,(uae_u32)(len >> 32),(uae_u32)len, - (uae_u32)(max >> 32),(uae_u32)max); + write_log (L"UAEHF: cmd %d: out of bounds, %08X-%08X + %08X-%08X > %08X-%08X\n", cmd, + (uae_u32)(offset >> 32),(uae_u32)offset,(uae_u32)(len >> 32),(uae_u32)len, + (uae_u32)(max >> 32),(uae_u32)max); } static void unaligned (int cmd, uae_u64 offset, uae_u64 len, int blocksize) { - write_log (L"UAEHF: cmd %d: unaligned access, %08X-%08X, %08X-%08X, %08X\n", cmd, - (uae_u32)(offset >> 32),(uae_u32)offset,(uae_u32)(len >> 32),(uae_u32)len, - blocksize); + write_log (L"UAEHF: cmd %d: unaligned access, %08X-%08X, %08X-%08X, %08X\n", cmd, + (uae_u32)(offset >> 32),(uae_u32)offset,(uae_u32)(len >> 32),(uae_u32)len, + blocksize); } static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata *hfpd, uaecptr request) { - uae_u32 dataptr, offset, actual = 0, cmd; - uae_u64 offset64; - int unit = get_long (request + 24); - uae_u32 error = 0, len; - int async = 0; - int bmask = hfd->blocksize - 1; - - cmd = get_word (request + 28); /* io_Command */ - dataptr = get_long (request + 40); - switch (cmd) - { + uae_u32 dataptr, offset, actual = 0, cmd; + uae_u64 offset64; + int unit = get_long (request + 24); + uae_u32 error = 0, len; + int async = 0; + int bmask = hfd->blocksize - 1; + + cmd = get_word (request + 28); /* io_Command */ + dataptr = get_long (request + 40); + switch (cmd) + { case CMD_READ: - if (nodisk (hfd)) - goto no_disk; - offset = get_long (request + 44); - len = get_long (request + 36); /* io_Length */ - if ((offset & bmask) || dataptr == 0) { - unaligned (cmd, offset, len, hfd->blocksize); - goto bad_command; - } - if (len & bmask) { - unaligned (cmd, offset, len, hfd->blocksize); - goto bad_len; - } - if (len + offset > hfd->virtsize) { - outofbounds (cmd, offset, len, hfd->virtsize); - goto bad_len; - } - actual = (uae_u32)cmd_read (hfd, dataptr, offset, len); - break; + if (nodisk (hfd)) + goto no_disk; + offset = get_long (request + 44); + len = get_long (request + 36); /* io_Length */ + if ((offset & bmask) || dataptr == 0) { + unaligned (cmd, offset, len, hfd->blocksize); + goto bad_command; + } + if (len & bmask) { + unaligned (cmd, offset, len, hfd->blocksize); + goto bad_len; + } + if (len + offset > hfd->virtsize) { + outofbounds (cmd, offset, len, hfd->virtsize); + goto bad_len; + } + actual = (uae_u32)cmd_read (hfd, dataptr, offset, len); + break; case TD_READ64: case NSCMD_TD_READ64: - if (nodisk (hfd)) - goto no_disk; - offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); - len = get_long (request + 36); /* io_Length */ - if ((offset64 & bmask) || dataptr == 0) { - unaligned (cmd, offset64, len, hfd->blocksize); - goto bad_command; - } - if (len & bmask) { - unaligned (cmd, offset64, len, hfd->blocksize); - goto bad_len; - } - if (len + offset64 > hfd->virtsize) { - outofbounds (cmd, offset64, len, hfd->virtsize); - goto bad_len; - } - actual = (uae_u32)cmd_read (hfd, dataptr, offset64, len); - break; + if (nodisk (hfd)) + goto no_disk; + offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); + len = get_long (request + 36); /* io_Length */ + if ((offset64 & bmask) || dataptr == 0) { + unaligned (cmd, offset64, len, hfd->blocksize); + goto bad_command; + } + if (len & bmask) { + unaligned (cmd, offset64, len, hfd->blocksize); + goto bad_len; + } + if (len + offset64 > hfd->virtsize) { + outofbounds (cmd, offset64, len, hfd->virtsize); + goto bad_len; + } + actual = (uae_u32)cmd_read (hfd, dataptr, offset64, len); + break; case CMD_WRITE: case CMD_FORMAT: /* Format */ - if (nodisk (hfd)) - goto no_disk; - if (hfd->readonly || hfd->dangerous) { - error = 28; /* write protect */ - } else { - offset = get_long (request + 44); - len = get_long (request + 36); /* io_Length */ - if ((offset & bmask) || dataptr == 0) { - unaligned (cmd, offset, len, hfd->blocksize); - goto bad_command; - } - if (len & bmask) { - unaligned (cmd, offset, len, hfd->blocksize); - goto bad_len; - } - if (len + offset > hfd->virtsize) { - outofbounds (cmd, offset, len, hfd->virtsize); - goto bad_len; - } - actual = (uae_u32)cmd_write (hfd, dataptr, offset, len); - } - break; + if (nodisk (hfd)) + goto no_disk; + if (hfd->readonly || hfd->dangerous) { + error = 28; /* write protect */ + } else { + offset = get_long (request + 44); + len = get_long (request + 36); /* io_Length */ + if ((offset & bmask) || dataptr == 0) { + unaligned (cmd, offset, len, hfd->blocksize); + goto bad_command; + } + if (len & bmask) { + unaligned (cmd, offset, len, hfd->blocksize); + goto bad_len; + } + if (len + offset > hfd->virtsize) { + outofbounds (cmd, offset, len, hfd->virtsize); + goto bad_len; + } + actual = (uae_u32)cmd_write (hfd, dataptr, offset, len); + } + break; case TD_WRITE64: case TD_FORMAT64: case NSCMD_TD_WRITE64: case NSCMD_TD_FORMAT64: - if (nodisk (hfd)) - goto no_disk; - if (hfd->readonly || hfd->dangerous) { - error = 28; /* write protect */ - } else { - offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); - len = get_long (request + 36); /* io_Length */ - if ((offset64 & bmask) || dataptr == 0) { - unaligned (cmd, offset64, len, hfd->blocksize); - goto bad_command; - } - if (len & bmask) { - unaligned (cmd, offset64, len, hfd->blocksize); - goto bad_len; - } - if (len + offset64 > hfd->virtsize) { - outofbounds (cmd, offset64, len, hfd->virtsize); - goto bad_len; - } - put_long (request + 32, (uae_u32)cmd_write (hfd, dataptr, offset64, len)); - } - break; + if (nodisk (hfd)) + goto no_disk; + if (hfd->readonly || hfd->dangerous) { + error = 28; /* write protect */ + } else { + offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); + len = get_long (request + 36); /* io_Length */ + if ((offset64 & bmask) || dataptr == 0) { + unaligned (cmd, offset64, len, hfd->blocksize); + goto bad_command; + } + if (len & bmask) { + unaligned (cmd, offset64, len, hfd->blocksize); + goto bad_len; + } + if (len + offset64 > hfd->virtsize) { + outofbounds (cmd, offset64, len, hfd->virtsize); + goto bad_len; + } + put_long (request + 32, (uae_u32)cmd_write (hfd, dataptr, offset64, len)); + } + break; - bad_command: - error = IOERR_BADADDRESS; - break; - bad_len: - error = IOERR_BADLENGTH; - no_disk: - error = 29; /* no disk */ - break; +bad_command: + error = IOERR_BADADDRESS; + break; +bad_len: + error = IOERR_BADLENGTH; +no_disk: + error = 29; /* no disk */ + break; case NSCMD_DEVICEQUERY: - put_long (dataptr + 0, 0); - put_long (dataptr + 4, 16); /* size */ - put_word (dataptr + 8, NSDEVTYPE_TRACKDISK); - put_word (dataptr + 10, 0); - put_long (dataptr + 12, nscmd_cmd); - actual = 16; - break; + put_long (dataptr + 0, 0); + put_long (dataptr + 4, 16); /* size */ + put_word (dataptr + 8, NSDEVTYPE_TRACKDISK); + put_word (dataptr + 10, 0); + put_long (dataptr + 12, nscmd_cmd); + actual = 16; + break; case CMD_GETDRIVETYPE: - actual = DRIVE_NEWSTYLE; - break; + actual = DRIVE_NEWSTYLE; + break; case CMD_GETNUMTRACKS: - { - int cyl, cylsec, head, tracksec; - getchs (hfd, &cyl, &cylsec, &head, &tracksec); - actual = cyl * head; - break; - } + { + int cyl, cylsec, head, tracksec; + getchs (hfd, &cyl, &cylsec, &head, &tracksec); + actual = cyl * head; + break; + } case CMD_GETGEOMETRY: - { - int cyl, cylsec, head, tracksec; - uae_u64 size; - getchs (hfd, &cyl, &cylsec, &head, &tracksec); - put_long (dataptr + 0, hfd->blocksize); - size = hfd->virtsize / 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); - put_long (dataptr + 20, tracksec); - put_long (dataptr + 24, 0); /* bufmemtype */ - put_byte (dataptr + 28, 0); /* type = DG_DIRECT_ACCESS */ - put_byte (dataptr + 29, 0); /* flags */ - } - break; + { + int cyl, cylsec, head, tracksec; + uae_u64 size; + getchs (hfd, &cyl, &cylsec, &head, &tracksec); + put_long (dataptr + 0, hfd->blocksize); + size = hfd->virtsize / 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); + put_long (dataptr + 20, tracksec); + put_long (dataptr + 24, 0); /* bufmemtype */ + put_byte (dataptr + 28, 0); /* type = DG_DIRECT_ACCESS */ + put_byte (dataptr + 29, 0); /* flags */ + } + break; case CMD_PROTSTATUS: - if (hfd->readonly || hfd->dangerous) - actual = -1; - else - actual = 0; - break; + if (hfd->readonly || hfd->dangerous) + actual = -1; + else + actual = 0; + break; case CMD_CHANGESTATE: - actual = hfd->drive_empty ? 1 :0; - break; + actual = hfd->drive_empty ? 1 :0; + break; - /* Some commands that just do nothing and return zero */ + /* Some commands that just do nothing and return zero */ case CMD_UPDATE: case CMD_CLEAR: case CMD_MOTOR: case CMD_SEEK: case TD_SEEK64: case NSCMD_TD_SEEK64: - break; + break; case CMD_REMOVE: - hfpd->changeint = get_long (request + 40); - break; + hfpd->changeint = get_long (request + 40); + break; case CMD_CHANGENUM: - actual = hfpd->changenum; - break; + actual = hfpd->changenum; + break; case CMD_ADDCHANGEINT: - error = add_async_request (hfpd, request, ASYNC_REQUEST_CHANGEINT, get_long (request + 40)); - if (!error) - async = 1; - break; + error = add_async_request (hfpd, request, ASYNC_REQUEST_CHANGEINT, get_long (request + 40)); + if (!error) + async = 1; + break; case CMD_REMCHANGEINT: - release_async_request (hfpd, request); - break; + release_async_request (hfpd, request); + break; case HD_SCSICMD: /* SCSI */ - if (hfd->nrcyls == 0) { - error = handle_scsi (request, hfd); - } else { /* we don't want users trashing their "partition" hardfiles with hdtoolbox */ - error = IOERR_NOCMD; - write_log (L"UAEHF: HD_SCSICMD tried on regular HDF, unit %d\n", unit); - } - break; + if (hfd->nrcyls == 0) { + error = handle_scsi (request, hfd); + } else { /* we don't want users trashing their "partition" hardfiles with hdtoolbox */ + error = IOERR_NOCMD; + write_log (L"UAEHF: HD_SCSICMD tried on regular HDF, unit %d\n", unit); + } + break; default: - /* Command not understood. */ - error = IOERR_NOCMD; - break; - } - put_long (request + 32, actual); - put_byte (request + 31, error); + /* Command not understood. */ + error = IOERR_NOCMD; + break; + } + put_long (request + 32, actual); + put_byte (request + 31, error); - hf_log2 ("hf: unit=%d, request=%p, cmd=%d offset=%u len=%d, actual=%d error%=%d\n", unit, request, - get_word (request + 28), get_long (request + 44), get_long (request + 36), actual, error); + hf_log2 ("hf: unit=%d, request=%p, cmd=%d offset=%u len=%d, actual=%d error%=%d\n", unit, request, + get_word (request + 28), get_long (request + 44), get_long (request + 36), actual, error); - return async; + return async; } static uae_u32 REGPARAM2 hardfile_abortio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - int unit = mangleunit (get_long (request + 24)); - struct hardfiledata *hfd = get_hardfile_data (unit); - struct hardfileprivdata *hfpd = &hardfpd[unit]; - - hf_log2 ("uaehf.device abortio "); - start_thread (context, unit); - if (!hfd || !hfpd || !hfpd->thread_running) { - put_byte (request + 31, 32); - hf_log2 ("error\n"); - return get_byte (request + 31); - } - put_byte (request + 31, -2); - hf_log2 ("unit=%d, request=%08X\n", unit, request); - abort_async (hfpd, request, -2, 0); - return 0; + uae_u32 request = m68k_areg (regs, 1); + int unit = mangleunit (get_long (request + 24)); + struct hardfiledata *hfd = get_hardfile_data (unit); + struct hardfileprivdata *hfpd = &hardfpd[unit]; + + hf_log2 ("uaehf.device abortio "); + start_thread (context, unit); + if (!hfd || !hfpd || !hfpd->thread_running) { + put_byte (request + 31, 32); + hf_log2 ("error\n"); + return get_byte (request + 31); + } + put_byte (request + 31, -2); + hf_log2 ("unit=%d, request=%08X\n", unit, request); + abort_async (hfpd, request, -2, 0); + return 0; } static int hardfile_can_quick (uae_u32 command) { - switch (command) - { + switch (command) + { case CMD_RESET: case CMD_STOP: case CMD_START: @@ -1756,193 +1779,193 @@ static int hardfile_can_quick (uae_u32 command) case CMD_GETNUMTRACKS: case CMD_GETGEOMETRY: case NSCMD_DEVICEQUERY: - return 1; - } - return 0; + return 1; + } + return 0; } static int hardfile_canquick (struct hardfiledata *hfd, uaecptr request) { - uae_u32 command = get_word (request + 28); - return hardfile_can_quick (command); + uae_u32 command = get_word (request + 28); + return hardfile_can_quick (command); } static uae_u32 REGPARAM2 hardfile_beginio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - uae_u8 flags = get_byte (request + 30); - int cmd = get_word (request + 28); - int unit = mangleunit (get_long (request + 24)); - struct hardfiledata *hfd = get_hardfile_data (unit); - struct hardfileprivdata *hfpd = &hardfpd[unit]; - - put_byte (request + 8, NT_MESSAGE); - start_thread (context, unit); - if (!hfd || !hfpd || !hfpd->thread_running) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - put_byte (request + 31, 0); - if ((flags & 1) && hardfile_canquick (hfd, request)) { - hf_log ("hf quickio unit=%d request=%p cmd=%d\n", unit, request, cmd); - if (hardfile_do_io (hfd, hfpd, request)) - hf_log2 ("uaehf.device cmd %d bug with IO_QUICK\n", cmd); - return get_byte (request + 31); - } else { - hf_log2 ("hf asyncio unit=%d request=%p cmd=%d\n", unit, request, cmd); - add_async_request (hfpd, request, ASYNC_REQUEST_TEMP, 0); - put_byte (request + 30, get_byte (request + 30) & ~1); - write_comm_pipe_u32 (&hfpd->requests, request, 1); - return 0; - } + uae_u32 request = m68k_areg (regs, 1); + uae_u8 flags = get_byte (request + 30); + int cmd = get_word (request + 28); + int unit = mangleunit (get_long (request + 24)); + struct hardfiledata *hfd = get_hardfile_data (unit); + struct hardfileprivdata *hfpd = &hardfpd[unit]; + + put_byte (request + 8, NT_MESSAGE); + start_thread (context, unit); + if (!hfd || !hfpd || !hfpd->thread_running) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + put_byte (request + 31, 0); + if ((flags & 1) && hardfile_canquick (hfd, request)) { + hf_log ("hf quickio unit=%d request=%p cmd=%d\n", unit, request, cmd); + if (hardfile_do_io (hfd, hfpd, request)) + hf_log2 ("uaehf.device cmd %d bug with IO_QUICK\n", cmd); + return get_byte (request + 31); + } else { + hf_log2 ("hf asyncio unit=%d request=%p cmd=%d\n", unit, request, cmd); + add_async_request (hfpd, request, ASYNC_REQUEST_TEMP, 0); + put_byte (request + 30, get_byte (request + 30) & ~1); + write_comm_pipe_u32 (&hfpd->requests, request, 1); + return 0; + } } static void *hardfile_thread (void *devs) { - struct hardfileprivdata *hfpd = (struct hardfileprivdata*)devs; - - uae_set_thread_priority (NULL, 1); - hfpd->thread_running = 1; - uae_sem_post (&hfpd->sync_sem); - for (;;) { - uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&hfpd->requests); - uae_sem_wait (&change_sem); - if (!request) { - hfpd->thread_running = 0; - uae_sem_post (&hfpd->sync_sem); - uae_sem_post (&change_sem); - return 0; - } else if (hardfile_do_io (get_hardfile_data (hfpd - &hardfpd[0]), hfpd, request) == 0) { - put_byte (request + 30, get_byte (request + 30) & ~1); - release_async_request (hfpd, request); - uae_ReplyMsg (request); - } else { - hf_log2 ("async request %08X\n", request); + struct hardfileprivdata *hfpd = (struct hardfileprivdata*)devs; + + uae_set_thread_priority (NULL, 1); + hfpd->thread_running = 1; + uae_sem_post (&hfpd->sync_sem); + for (;;) { + uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&hfpd->requests); + uae_sem_wait (&change_sem); + if (!request) { + hfpd->thread_running = 0; + uae_sem_post (&hfpd->sync_sem); + uae_sem_post (&change_sem); + return 0; + } else if (hardfile_do_io (get_hardfile_data (hfpd - &hardfpd[0]), hfpd, request) == 0) { + put_byte (request + 30, get_byte (request + 30) & ~1); + release_async_request (hfpd, request); + uae_ReplyMsg (request); + } else { + hf_log2 ("async request %08X\n", request); + } + uae_sem_post (&change_sem); } - uae_sem_post (&change_sem); - } } void hardfile_reset (void) { - int i, j; - struct hardfileprivdata *hfpd; - - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - hfpd = &hardfpd[i]; - if (hfpd->base && valid_address (hfpd->base, 36) && get_word (hfpd->base + 32) > 0) { - for (j = 0; j < MAX_ASYNC_REQUESTS; j++) { - uaecptr request; - if ((request = hfpd->d_request[i])) - abort_async (hfpd, request, 0, 0); - } + int i, j; + struct hardfileprivdata *hfpd; + + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + hfpd = &hardfpd[i]; + if (hfpd->base && valid_address (hfpd->base, 36) && get_word (hfpd->base + 32) > 0) { + for (j = 0; j < MAX_ASYNC_REQUESTS; j++) { + uaecptr request; + if ((request = hfpd->d_request[i])) + abort_async (hfpd, request, 0, 0); + } + } + memset (hfpd, 0, sizeof (struct hardfileprivdata)); } - memset (hfpd, 0, sizeof (struct hardfileprivdata)); - } } void hardfile_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, openfunc, closefunc, expungefunc; - uae_u32 beginiofunc, abortiofunc; - - uae_sem_init (&change_sem, 0, 1); - - ROM_hardfile_resname = ds (L"uaehf.device"); - ROM_hardfile_resid = ds (L"UAE hardfile.device 0.2"); - - nscmd_cmd = here (); - dw (NSCMD_DEVICEQUERY); - dw (CMD_RESET); - dw (CMD_READ); - dw (CMD_WRITE); - dw (CMD_UPDATE); - dw (CMD_CLEAR); - dw (CMD_START); - dw (CMD_STOP); - dw (CMD_FLUSH); - dw (CMD_MOTOR); - dw (CMD_SEEK); - dw (CMD_FORMAT); - dw (CMD_REMOVE); - dw (CMD_CHANGENUM); - dw (CMD_CHANGESTATE); - dw (CMD_PROTSTATUS); - dw (CMD_GETDRIVETYPE); - dw (CMD_GETGEOMETRY); - dw (CMD_ADDCHANGEINT); - dw (CMD_REMCHANGEINT); - dw (HD_SCSICMD); - dw (NSCMD_TD_READ64); - dw (NSCMD_TD_WRITE64); - dw (NSCMD_TD_SEEK64); - dw (NSCMD_TD_FORMAT64); - dw (0); - - /* initcode */ + uae_u32 functable, datatable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; + + uae_sem_init (&change_sem, 0, 1); + + ROM_hardfile_resname = ds (L"uaehf.device"); + ROM_hardfile_resid = ds (L"UAE hardfile.device 0.2"); + + nscmd_cmd = here (); + dw (NSCMD_DEVICEQUERY); + dw (CMD_RESET); + dw (CMD_READ); + dw (CMD_WRITE); + dw (CMD_UPDATE); + dw (CMD_CLEAR); + dw (CMD_START); + dw (CMD_STOP); + dw (CMD_FLUSH); + dw (CMD_MOTOR); + dw (CMD_SEEK); + dw (CMD_FORMAT); + dw (CMD_REMOVE); + dw (CMD_CHANGENUM); + dw (CMD_CHANGESTATE); + dw (CMD_PROTSTATUS); + dw (CMD_GETDRIVETYPE); + dw (CMD_GETGEOMETRY); + dw (CMD_ADDCHANGEINT); + dw (CMD_REMCHANGEINT); + dw (HD_SCSICMD); + dw (NSCMD_TD_READ64); + dw (NSCMD_TD_WRITE64); + dw (NSCMD_TD_SEEK64); + dw (NSCMD_TD_FORMAT64); + dw (0); + + /* initcode */ #if 0 - initcode = here (); - calltrap (deftrap (hardfile_init)); dw (RTS); + initcode = here (); + calltrap (deftrap (hardfile_init)); dw (RTS); #else - initcode = filesys_initcode; + initcode = filesys_initcode; #endif - /* Open */ - openfunc = here (); - calltrap (deftrap (hardfile_open)); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap (hardfile_close)); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap (hardfile_expunge)); dw (RTS); - - /* BeginIO */ - beginiofunc = here (); - calltrap (deftrap (hardfile_beginio)); - dw (RTS); - - /* AbortIO */ - abortiofunc = here (); - calltrap (deftrap (hardfile_abortio)); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (openfunc); /* Open */ - dl (closefunc); /* Close */ - dl (expungefunc); /* Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - dl (beginiofunc); /* BeginIO */ - dl (abortiofunc); /* AbortIO */ - dl (0xFFFFFFFFul); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0300); /* NT_DEVICE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (ROM_hardfile_resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); /* 0.4 */ - dw (0xD000); - dw (0x0016); /* LIB_REVISION */ - dw (0x0000); - dw (0xC000); - dw (0x0018); /* LIB_IDSTRING */ - dl (ROM_hardfile_resid); - dw (0x0000); /* end of table */ - - ROM_hardfile_init = here (); - dl (0x00000100); /* ??? */ - dl (functable); - dl (datatable); - dl (initcode); + /* Open */ + openfunc = here (); + calltrap (deftrap (hardfile_open)); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap (hardfile_close)); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap (hardfile_expunge)); dw (RTS); + + /* BeginIO */ + beginiofunc = here (); + calltrap (deftrap (hardfile_beginio)); + dw (RTS); + + /* AbortIO */ + abortiofunc = here (); + calltrap (deftrap (hardfile_abortio)); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (openfunc); /* Open */ + dl (closefunc); /* Close */ + dl (expungefunc); /* Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + dl (beginiofunc); /* BeginIO */ + dl (abortiofunc); /* AbortIO */ + dl (0xFFFFFFFFul); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0300); /* NT_DEVICE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (ROM_hardfile_resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); /* 0.4 */ + dw (0xD000); + dw (0x0016); /* LIB_REVISION */ + dw (0x0000); + dw (0xC000); + dw (0x0018); /* LIB_IDSTRING */ + dl (ROM_hardfile_resid); + dw (0x0000); /* end of table */ + + ROM_hardfile_init = here (); + dl (0x00000100); /* ??? */ + dl (functable); + dl (datatable); + dl (initcode); } diff --git a/identify.c b/identify.c index 48f6431b..6172bb0d 100644 --- a/identify.c +++ b/identify.c @@ -1,9 +1,9 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Routines for labelling amiga internals. - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Routines for labelling amiga internals. +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -15,389 +15,389 @@ const struct mem_labels int_labels[] = { - { L"Reset:SSP", 0x0000 }, - { L"EXECBASE", 0x0004 }, - { L"BUS ERROR", 0x0008 }, - { L"ADR ERROR", 0x000C }, - { L"ILLEG OPC", 0x0010 }, - { L"DIV BY 0", 0x0014 }, - { L"CHK", 0x0018 }, - { L"TRAPV", 0x001C }, - { L"PRIVIL VIO", 0x0020 }, - { L"TRACE", 0x0024 }, - { L"LINEA EMU", 0x0028 }, - { L"LINEF EMU", 0x002C }, - { L"INT Uninit", 0x003C }, - { L"INT Unjust", 0x0060 }, - { L"Lvl 1 Int", 0x0064 }, - { L"Lvl 2 Int", 0x0068 }, - { L"Lvl 3 Int", 0x006C }, - { L"Lvl 4 Int", 0x0070 }, - { L"Lvl 5 Int", 0x0074 }, - { L"Lvl 6 Int", 0x0078 }, - { L"NMI", 0x007C }, - { 0, 0 } + { L"Reset:SSP", 0x0000 }, + { L"EXECBASE", 0x0004 }, + { L"BUS ERROR", 0x0008 }, + { L"ADR ERROR", 0x000C }, + { L"ILLEG OPC", 0x0010 }, + { L"DIV BY 0", 0x0014 }, + { L"CHK", 0x0018 }, + { L"TRAPV", 0x001C }, + { L"PRIVIL VIO", 0x0020 }, + { L"TRACE", 0x0024 }, + { L"LINEA EMU", 0x0028 }, + { L"LINEF EMU", 0x002C }, + { L"INT Uninit", 0x003C }, + { L"INT Unjust", 0x0060 }, + { L"Lvl 1 Int", 0x0064 }, + { L"Lvl 2 Int", 0x0068 }, + { L"Lvl 3 Int", 0x006C }, + { L"Lvl 4 Int", 0x0070 }, + { L"Lvl 5 Int", 0x0074 }, + { L"Lvl 6 Int", 0x0078 }, + { L"NMI", 0x007C }, + { 0, 0 } }; const struct mem_labels trap_labels[] = { - { L"TRAP 00", 0x0080 }, - { L"TRAP 01", 0x0084 }, - { L"TRAP 02", 0x0088 }, - { L"TRAP 03", 0x008C }, - { L"TRAP 04", 0x0090 }, - { L"TRAP 05", 0x0094 }, - { L"TRAP 06", 0x0098 }, - { L"TRAP 07", 0x009C }, - { L"TRAP 08", 0x00A0 }, - { L"TRAP 09", 0x00A4 }, - { L"TRAP 10", 0x00A8 }, - { L"TRAP 11", 0x00AC }, - { L"TRAP 12", 0x00B0 }, - { L"TRAP 13", 0x00B4 }, - { L"TRAP 14", 0x00B8 }, - { L"TRAP 15", 0x00BC }, - { 0, 0 } + { L"TRAP 00", 0x0080 }, + { L"TRAP 01", 0x0084 }, + { L"TRAP 02", 0x0088 }, + { L"TRAP 03", 0x008C }, + { L"TRAP 04", 0x0090 }, + { L"TRAP 05", 0x0094 }, + { L"TRAP 06", 0x0098 }, + { L"TRAP 07", 0x009C }, + { L"TRAP 08", 0x00A0 }, + { L"TRAP 09", 0x00A4 }, + { L"TRAP 10", 0x00A8 }, + { L"TRAP 11", 0x00AC }, + { L"TRAP 12", 0x00B0 }, + { L"TRAP 13", 0x00B4 }, + { L"TRAP 14", 0x00B8 }, + { L"TRAP 15", 0x00BC }, + { 0, 0 } }; const struct mem_labels mem_labels[] = { - { L"CIAB PRA", 0xBFD000 }, - { L"CIAB PRB", 0xBFD100 }, - { L"CIAB DDRA", 0xBFD200 }, - { L"CIAB DDRB", 0xBFD300 }, - { L"CIAB TALO", 0xBFD400 }, - { L"CIAB TAHI", 0xBFD500 }, - { L"CIAB TBLO", 0xBFD600 }, - { L"CIAB TBHI", 0xBFD700 }, - { L"CIAB TDLO", 0xBFD800 }, - { L"CIAB TDMD", 0xBFD900 }, - { L"CIAB TDHI", 0xBFDA00 }, - { L"CIAB SDR", 0xBFDC00 }, - { L"CIAB ICR", 0xBFDD00 }, - { L"CIAB CRA", 0xBFDE00 }, - { L"CIAB CRB", 0xBFDF00 }, - { L"CIAA PRA", 0xBFE001 }, - { L"CIAA PRB", 0xBFE101 }, - { L"CIAA DDRA", 0xBFE201 }, - { L"CIAA DDRB", 0xBFE301 }, - { L"CIAA TALO", 0xBFE401 }, - { L"CIAA TAHI", 0xBFE501 }, - { L"CIAA TBLO", 0xBFE601 }, - { L"CIAA TBHI", 0xBFE701 }, - { L"CIAA TDLO", 0xBFE801 }, - { L"CIAA TDMD", 0xBFE901 }, - { L"CIAA TDHI", 0xBFEA01 }, - { L"CIAA SDR", 0xBFEC01 }, - { L"CIAA ICR", 0xBFED01 }, - { L"CIAA CRA", 0xBFEE01 }, - { L"CIAA CRB", 0xBFEF01 }, - { L"CLK S1", 0xDC0000 }, - { L"CLK S10", 0xDC0004 }, - { L"CLK MI1", 0xDC0008 }, - { L"CLK MI10", 0xDC000C }, - { L"CLK H1", 0xDC0010 }, - { L"CLK H10", 0xDC0014 }, - { L"CLK D1", 0xDC0018 }, - { L"CLK D10", 0xDC001C }, - { L"CLK MO1", 0xDC0020 }, - { L"CLK MO10", 0xDC0024 }, - { L"CLK Y1", 0xDC0028 }, - { L"CLK Y10", 0xDC002E }, - { L"CLK WEEK", 0xDC0030 }, - { L"CLK CD", 0xDC0034 }, - { L"CLK CE", 0xDC0038 }, - { L"CLK CF", 0xDC003C }, - { NULL, 0 } + { L"CIAB PRA", 0xBFD000 }, + { L"CIAB PRB", 0xBFD100 }, + { L"CIAB DDRA", 0xBFD200 }, + { L"CIAB DDRB", 0xBFD300 }, + { L"CIAB TALO", 0xBFD400 }, + { L"CIAB TAHI", 0xBFD500 }, + { L"CIAB TBLO", 0xBFD600 }, + { L"CIAB TBHI", 0xBFD700 }, + { L"CIAB TDLO", 0xBFD800 }, + { L"CIAB TDMD", 0xBFD900 }, + { L"CIAB TDHI", 0xBFDA00 }, + { L"CIAB SDR", 0xBFDC00 }, + { L"CIAB ICR", 0xBFDD00 }, + { L"CIAB CRA", 0xBFDE00 }, + { L"CIAB CRB", 0xBFDF00 }, + { L"CIAA PRA", 0xBFE001 }, + { L"CIAA PRB", 0xBFE101 }, + { L"CIAA DDRA", 0xBFE201 }, + { L"CIAA DDRB", 0xBFE301 }, + { L"CIAA TALO", 0xBFE401 }, + { L"CIAA TAHI", 0xBFE501 }, + { L"CIAA TBLO", 0xBFE601 }, + { L"CIAA TBHI", 0xBFE701 }, + { L"CIAA TDLO", 0xBFE801 }, + { L"CIAA TDMD", 0xBFE901 }, + { L"CIAA TDHI", 0xBFEA01 }, + { L"CIAA SDR", 0xBFEC01 }, + { L"CIAA ICR", 0xBFED01 }, + { L"CIAA CRA", 0xBFEE01 }, + { L"CIAA CRB", 0xBFEF01 }, + { L"CLK S1", 0xDC0000 }, + { L"CLK S10", 0xDC0004 }, + { L"CLK MI1", 0xDC0008 }, + { L"CLK MI10", 0xDC000C }, + { L"CLK H1", 0xDC0010 }, + { L"CLK H10", 0xDC0014 }, + { L"CLK D1", 0xDC0018 }, + { L"CLK D10", 0xDC001C }, + { L"CLK MO1", 0xDC0020 }, + { L"CLK MO10", 0xDC0024 }, + { L"CLK Y1", 0xDC0028 }, + { L"CLK Y10", 0xDC002E }, + { L"CLK WEEK", 0xDC0030 }, + { L"CLK CD", 0xDC0034 }, + { L"CLK CE", 0xDC0038 }, + { L"CLK CF", 0xDC003C }, + { NULL, 0 } }; /* This table was generated from the list of AGA chip names in - * AGA.guide available on aminet. It could well have errors in it. */ +* AGA.guide available on aminet. It could well have errors in it. */ const struct customData custd[] = { #if 0 - { L"BLTDDAT", 0xdff000 }, /* Blitter dest. early read (dummy address) */ + { L"BLTDDAT", 0xdff000 }, /* Blitter dest. early read (dummy address) */ #endif - { L"DMACONR", 0xdff002, 1 }, /* Dma control (and blitter status) read */ - { L"VPOSR", 0xdff004, 1 }, /* Read vert most sig. bits (and frame flop */ - { L"VHPOSR", 0xdff006, 1 }, /* Read vert and horiz position of beam */ + { L"DMACONR", 0xdff002, 1 }, /* Dma control (and blitter status) read */ + { L"VPOSR", 0xdff004, 1 }, /* Read vert most sig. bits (and frame flop */ + { L"VHPOSR", 0xdff006, 1 }, /* Read vert and horiz position of beam */ #if 0 - { L"DSKDATR", 0xdff008 }, /* Disk data early read (dummy address) */ + { L"DSKDATR", 0xdff008 }, /* Disk data early read (dummy address) */ #endif - { L"JOY0DAT", 0xdff00A, 1 }, /* Joystick-mouse 0 data (vert,horiz) */ - { L"JOT1DAT", 0xdff00C, 1 }, /* Joystick-mouse 1 data (vert,horiz) */ - { L"CLXDAT", 0xdff00E, 1 }, /* Collision data reg. (read and clear) */ - { L"ADKCONR", 0xdff010, 1 }, /* Audio,disk control register read */ - { L"POT0DAT", 0xdff012, 1 }, /* Pot counter pair 0 data (vert,horiz) */ - { L"POT1DAT", 0xdff014, 1 }, /* Pot counter pair 1 data (vert,horiz) */ - { L"POTGOR", 0xdff016, 1 }, /* Pot pin data read */ - { L"SERDATR", 0xdff018, 1 }, /* Serial port data and status read */ - { L"DSKBYTR", 0xdff01A, 1 }, /* Disk data byte and status read */ - { L"INTENAR", 0xdff01C, 1 }, /* Interrupt enable bits read */ - { L"INTREQR", 0xdff01E, 1 }, /* Interrupt request bits read */ - { L"DSKPTH", 0xdff020, 2, 1 }, /* Disk pointer (high 5 bits) */ - { L"DSKPTL", 0xdff022, 2, 2 }, /* Disk pointer (low 15 bits) */ - { L"DSKLEN", 0xdff024, 2, 0 }, /* Disk lentgh */ + { L"JOY0DAT", 0xdff00A, 1 }, /* Joystick-mouse 0 data (vert,horiz) */ + { L"JOT1DAT", 0xdff00C, 1 }, /* Joystick-mouse 1 data (vert,horiz) */ + { L"CLXDAT", 0xdff00E, 1 }, /* Collision data reg. (read and clear) */ + { L"ADKCONR", 0xdff010, 1 }, /* Audio,disk control register read */ + { L"POT0DAT", 0xdff012, 1 }, /* Pot counter pair 0 data (vert,horiz) */ + { L"POT1DAT", 0xdff014, 1 }, /* Pot counter pair 1 data (vert,horiz) */ + { L"POTGOR", 0xdff016, 1 }, /* Pot pin data read */ + { L"SERDATR", 0xdff018, 1 }, /* Serial port data and status read */ + { L"DSKBYTR", 0xdff01A, 1 }, /* Disk data byte and status read */ + { L"INTENAR", 0xdff01C, 1 }, /* Interrupt enable bits read */ + { L"INTREQR", 0xdff01E, 1 }, /* Interrupt request bits read */ + { L"DSKPTH", 0xdff020, 2, 1 }, /* Disk pointer (high 5 bits) */ + { L"DSKPTL", 0xdff022, 2, 2 }, /* Disk pointer (low 15 bits) */ + { L"DSKLEN", 0xdff024, 2, 0 }, /* Disk lentgh */ #if 0 - { L"DSKDAT", 0xdff026 }, /* Disk DMA data write */ - { L"REFPTR", 0xdff028 }, /* Refresh pointer */ + { L"DSKDAT", 0xdff026 }, /* Disk DMA data write */ + { L"REFPTR", 0xdff028 }, /* Refresh pointer */ #endif - { L"VPOSW", 0xdff02A, 2, 0 }, /* Write vert most sig. bits(and frame flop) */ - { L"VHPOSW", 0xdff02C, 2, 0 }, /* Write vert and horiz pos of beam */ - { L"COPCON", 0xdff02e, 2, 0 }, /* Coprocessor control reg (CDANG) */ - { L"SERDAT", 0xdff030, 2, 0 }, /* Serial port data and stop bits write */ - { L"SERPER", 0xdff032, 2, 0 }, /* Serial port period and control */ - { L"POTGO", 0xdff034, 2, 0 }, /* Pot count start,pot pin drive enable data */ - { L"JOYTEST", 0xdff036, 2, 0 }, /* Write to all 4 joystick-mouse counters at once */ - { L"STREQU", 0xdff038, 2, 0 }, /* Strobe for horiz sync with VB and EQU */ - { L"STRVBL", 0xdff03A, 2, 0 }, /* Strobe for horiz sync with VB (vert blank) */ - { L"STRHOR", 0xdff03C, 2, 0 }, /* Strobe for horiz sync */ - { L"STRLONG", 0xdff03E, 2, 0 }, /* Strobe for identification of long horiz line */ - { L"BLTCON0", 0xdff040, 2, 0 }, /* Blitter control reg 0 */ - { L"BLTCON1", 0xdff042, 2, 0 }, /* Blitter control reg 1 */ - { L"BLTAFWM", 0xdff044, 2, 0 }, /* Blitter first word mask for source A */ - { L"BLTALWM", 0xdff046, 2, 0 }, /* Blitter last word mask for source A */ - { L"BLTCPTH", 0xdff048, 2, 1 }, /* Blitter pointer to source C (high 5 bits) */ - { L"BLTCPTL", 0xdff04A, 2, 2 }, /* Blitter pointer to source C (low 15 bits) */ - { L"BLTBPTH", 0xdff04C, 2, 1 }, /* Blitter pointer to source B (high 5 bits) */ - { L"BLTBPTL", 0xdff04E, 2, 2 }, /* Blitter pointer to source B (low 15 bits) */ - { L"BLTAPTH", 0xdff050, 2, 1 }, /* Blitter pointer to source A (high 5 bits) */ - { L"BLTAPTL", 0xdff052, 2, 2 }, /* Blitter pointer to source A (low 15 bits) */ - { L"BPTDPTH", 0xdff054, 2, 1 }, /* Blitter pointer to destn D (high 5 bits) */ - { L"BLTDPTL", 0xdff056, 2, 2 }, /* Blitter pointer to destn D (low 15 bits) */ - { L"BLTSIZE", 0xdff058, 2, 0 }, /* Blitter start and size (win/width,height) */ - { L"BLTCON0L", 0xdff05A, 2, 4 }, /* Blitter control 0 lower 8 bits (minterms) */ - { L"BLTSIZV", 0xdff05C, 2, 4 }, /* Blitter V size (for 15 bit vert size) */ - { L"BLTSIZH", 0xdff05E, 2, 4 }, /* Blitter H size & start (for 11 bit H size) */ - { L"BLTCMOD", 0xdff060, 2, 0 }, /* Blitter modulo for source C */ - { L"BLTBMOD", 0xdff062, 2, 0 }, /* Blitter modulo for source B */ - { L"BLTAMOD", 0xdff064, 2, 0 }, /* Blitter modulo for source A */ - { L"BLTDMOD", 0xdff066, 2, 0 }, /* Blitter modulo for destn D */ + { L"VPOSW", 0xdff02A, 2, 0 }, /* Write vert most sig. bits(and frame flop) */ + { L"VHPOSW", 0xdff02C, 2, 0 }, /* Write vert and horiz pos of beam */ + { L"COPCON", 0xdff02e, 2, 0 }, /* Coprocessor control reg (CDANG) */ + { L"SERDAT", 0xdff030, 2, 0 }, /* Serial port data and stop bits write */ + { L"SERPER", 0xdff032, 2, 0 }, /* Serial port period and control */ + { L"POTGO", 0xdff034, 2, 0 }, /* Pot count start,pot pin drive enable data */ + { L"JOYTEST", 0xdff036, 2, 0 }, /* Write to all 4 joystick-mouse counters at once */ + { L"STREQU", 0xdff038, 2, 0 }, /* Strobe for horiz sync with VB and EQU */ + { L"STRVBL", 0xdff03A, 2, 0 }, /* Strobe for horiz sync with VB (vert blank) */ + { L"STRHOR", 0xdff03C, 2, 0 }, /* Strobe for horiz sync */ + { L"STRLONG", 0xdff03E, 2, 0 }, /* Strobe for identification of long horiz line */ + { L"BLTCON0", 0xdff040, 2, 0 }, /* Blitter control reg 0 */ + { L"BLTCON1", 0xdff042, 2, 0 }, /* Blitter control reg 1 */ + { L"BLTAFWM", 0xdff044, 2, 0 }, /* Blitter first word mask for source A */ + { L"BLTALWM", 0xdff046, 2, 0 }, /* Blitter last word mask for source A */ + { L"BLTCPTH", 0xdff048, 2, 1 }, /* Blitter pointer to source C (high 5 bits) */ + { L"BLTCPTL", 0xdff04A, 2, 2 }, /* Blitter pointer to source C (low 15 bits) */ + { L"BLTBPTH", 0xdff04C, 2, 1 }, /* Blitter pointer to source B (high 5 bits) */ + { L"BLTBPTL", 0xdff04E, 2, 2 }, /* Blitter pointer to source B (low 15 bits) */ + { L"BLTAPTH", 0xdff050, 2, 1 }, /* Blitter pointer to source A (high 5 bits) */ + { L"BLTAPTL", 0xdff052, 2, 2 }, /* Blitter pointer to source A (low 15 bits) */ + { L"BPTDPTH", 0xdff054, 2, 1 }, /* Blitter pointer to destn D (high 5 bits) */ + { L"BLTDPTL", 0xdff056, 2, 2 }, /* Blitter pointer to destn D (low 15 bits) */ + { L"BLTSIZE", 0xdff058, 2, 0 }, /* Blitter start and size (win/width,height) */ + { L"BLTCON0L", 0xdff05A, 2, 4 }, /* Blitter control 0 lower 8 bits (minterms) */ + { L"BLTSIZV", 0xdff05C, 2, 4 }, /* Blitter V size (for 15 bit vert size) */ + { L"BLTSIZH", 0xdff05E, 2, 4 }, /* Blitter H size & start (for 11 bit H size) */ + { L"BLTCMOD", 0xdff060, 2, 0 }, /* Blitter modulo for source C */ + { L"BLTBMOD", 0xdff062, 2, 0 }, /* Blitter modulo for source B */ + { L"BLTAMOD", 0xdff064, 2, 0 }, /* Blitter modulo for source A */ + { L"BLTDMOD", 0xdff066, 2, 0 }, /* Blitter modulo for destn D */ #if 0 - { L"Unknown", 0xdff068 }, /* Unknown or Unused */ - { L"Unknown", 0xdff06a }, /* Unknown or Unused */ - { L"Unknown", 0xdff06c }, /* Unknown or Unused */ - { L"Unknown", 0xdff06e }, /* Unknown or Unused */ + { L"Unknown", 0xdff068 }, /* Unknown or Unused */ + { L"Unknown", 0xdff06a }, /* Unknown or Unused */ + { L"Unknown", 0xdff06c }, /* Unknown or Unused */ + { L"Unknown", 0xdff06e }, /* Unknown or Unused */ #endif - { L"BLTCDAT", 0xdff070, 2, 0 }, /* Blitter source C data reg */ - { L"BLTBDAT", 0xdff072, 2, 0 }, /* Blitter source B data reg */ - { L"BLTADAT", 0xdff074, 2, 0 }, /* Blitter source A data reg */ - { L"BLTDDAT", 0xdff076, 2, 0 }, /* Blitter destination reg */ + { L"BLTCDAT", 0xdff070, 2, 0 }, /* Blitter source C data reg */ + { L"BLTBDAT", 0xdff072, 2, 0 }, /* Blitter source B data reg */ + { L"BLTADAT", 0xdff074, 2, 0 }, /* Blitter source A data reg */ + { L"BLTDDAT", 0xdff076, 2, 0 }, /* Blitter destination reg */ #if 0 - { L"SPRHDAT", 0xdff078 }, /* Ext logic UHRES sprite pointer and data identifier */ - { L"BPLHDAT", 0xdff07A }, /* Ext logic UHRES bit plane identifier */ + { L"SPRHDAT", 0xdff078 }, /* Ext logic UHRES sprite pointer and data identifier */ + { L"BPLHDAT", 0xdff07A }, /* Ext logic UHRES bit plane identifier */ #endif - { L"LISAID", 0xdff07C, 1, 8 }, /* Chip revision level for Denise/Lisa */ - { L"DSKSYNC", 0xdff07E, 2 }, /* Disk sync pattern reg for disk read */ - { L"COP1LCH", 0xdff080, 2, 1 }, /* Coprocessor first location reg (high 5 bits) */ - { L"COP1LCL", 0xdff082, 2, 2 }, /* Coprocessor first location reg (low 15 bits) */ - { L"COP2LCH", 0xdff084, 2, 1 }, /* Coprocessor second reg (high 5 bits) */ - { L"COP2LCL", 0xdff086, 2, 2 }, /* Coprocessor second reg (low 15 bits) */ - { L"COPJMP1", 0xdff088, 2 }, /* Coprocessor restart at first location */ - { L"COPJMP2", 0xdff08A, 2 }, /* Coprocessor restart at second location */ + { L"LISAID", 0xdff07C, 1, 8 }, /* Chip revision level for Denise/Lisa */ + { L"DSKSYNC", 0xdff07E, 2 }, /* Disk sync pattern reg for disk read */ + { L"COP1LCH", 0xdff080, 2, 1 }, /* Coprocessor first location reg (high 5 bits) */ + { L"COP1LCL", 0xdff082, 2, 2 }, /* Coprocessor first location reg (low 15 bits) */ + { L"COP2LCH", 0xdff084, 2, 1 }, /* Coprocessor second reg (high 5 bits) */ + { L"COP2LCL", 0xdff086, 2, 2 }, /* Coprocessor second reg (low 15 bits) */ + { L"COPJMP1", 0xdff088, 2 }, /* Coprocessor restart at first location */ + { L"COPJMP2", 0xdff08A, 2 }, /* Coprocessor restart at second location */ #if 0 - { L"COPINS", 0xdff08C }, /* Coprocessor inst fetch identify */ + { L"COPINS", 0xdff08C }, /* Coprocessor inst fetch identify */ #endif - { L"DIWSTRT", 0xdff08E, 2 }, /* Display window start (upper left vert-hor pos) */ - { L"DIWSTOP", 0xdff090, 2 }, /* Display window stop (lower right vert-hor pos) */ - { L"DDFSTRT", 0xdff092, 2 }, /* Display bit plane data fetch start.hor pos */ - { L"DDFSTOP", 0xdff094, 2 }, /* Display bit plane data fetch stop.hor pos */ - { L"DMACON", 0xdff096, 2 }, /* DMA control write (clear or set) */ - { L"CLXCON", 0xdff098, 2 }, /* Collision control */ - { L"INTENA", 0xdff09A, 2 }, /* Interrupt enable bits (clear or set bits) */ - { L"INTREQ", 0xdff09C, 2 }, /* Interrupt request bits (clear or set bits) */ - { L"ADKCON", 0xdff09E, 2 }, /* Audio,disk,UART,control */ - { L"AUD0LCH", 0xdff0A0, 2, 1 }, /* Audio channel 0 location (high 5 bits) */ - { L"AUD0LCL", 0xdff0A2, 2, 2 }, /* Audio channel 0 location (low 15 bits) */ - { L"AUD0LEN", 0xdff0A4, 2 }, /* Audio channel 0 lentgh */ - { L"AUD0PER", 0xdff0A6, 2 }, /* Audio channel 0 period */ - { L"AUD0VOL", 0xdff0A8, 2 }, /* Audio channel 0 volume */ - { L"AUD0DAT", 0xdff0AA, 2 }, /* Audio channel 0 data */ + { L"DIWSTRT", 0xdff08E, 2 }, /* Display window start (upper left vert-hor pos) */ + { L"DIWSTOP", 0xdff090, 2 }, /* Display window stop (lower right vert-hor pos) */ + { L"DDFSTRT", 0xdff092, 2 }, /* Display bit plane data fetch start.hor pos */ + { L"DDFSTOP", 0xdff094, 2 }, /* Display bit plane data fetch stop.hor pos */ + { L"DMACON", 0xdff096, 2 }, /* DMA control write (clear or set) */ + { L"CLXCON", 0xdff098, 2 }, /* Collision control */ + { L"INTENA", 0xdff09A, 2 }, /* Interrupt enable bits (clear or set bits) */ + { L"INTREQ", 0xdff09C, 2 }, /* Interrupt request bits (clear or set bits) */ + { L"ADKCON", 0xdff09E, 2 }, /* Audio,disk,UART,control */ + { L"AUD0LCH", 0xdff0A0, 2, 1 }, /* Audio channel 0 location (high 5 bits) */ + { L"AUD0LCL", 0xdff0A2, 2, 2 }, /* Audio channel 0 location (low 15 bits) */ + { L"AUD0LEN", 0xdff0A4, 2 }, /* Audio channel 0 lentgh */ + { L"AUD0PER", 0xdff0A6, 2 }, /* Audio channel 0 period */ + { L"AUD0VOL", 0xdff0A8, 2 }, /* Audio channel 0 volume */ + { L"AUD0DAT", 0xdff0AA, 2 }, /* Audio channel 0 data */ #if 0 - { L"Unknown", 0xdff0AC }, /* Unknown or Unused */ - { L"Unknown", 0xdff0AE }, /* Unknown or Unused */ + { L"Unknown", 0xdff0AC }, /* Unknown or Unused */ + { L"Unknown", 0xdff0AE }, /* Unknown or Unused */ #endif - { L"AUD1LCH", 0xdff0B0, 2, 1 }, /* Audio channel 1 location (high 5 bits) */ - { L"AUD1LCL", 0xdff0B2, 2, 2 }, /* Audio channel 1 location (low 15 bits) */ - { L"AUD1LEN", 0xdff0B4, 2 }, /* Audio channel 1 lentgh */ - { L"AUD1PER", 0xdff0B6, 2 }, /* Audio channel 1 period */ - { L"AUD1VOL", 0xdff0B8, 2 }, /* Audio channel 1 volume */ - { L"AUD1DAT", 0xdff0BA, 2 }, /* Audio channel 1 data */ + { L"AUD1LCH", 0xdff0B0, 2, 1 }, /* Audio channel 1 location (high 5 bits) */ + { L"AUD1LCL", 0xdff0B2, 2, 2 }, /* Audio channel 1 location (low 15 bits) */ + { L"AUD1LEN", 0xdff0B4, 2 }, /* Audio channel 1 lentgh */ + { L"AUD1PER", 0xdff0B6, 2 }, /* Audio channel 1 period */ + { L"AUD1VOL", 0xdff0B8, 2 }, /* Audio channel 1 volume */ + { L"AUD1DAT", 0xdff0BA, 2 }, /* Audio channel 1 data */ #if 0 - { L"Unknown", 0xdff0BC }, /* Unknown or Unused */ - { L"Unknown", 0xdff0BE }, /* Unknown or Unused */ + { L"Unknown", 0xdff0BC }, /* Unknown or Unused */ + { L"Unknown", 0xdff0BE }, /* Unknown or Unused */ #endif - { L"AUD2LCH", 0xdff0C0, 2, 1 }, /* Audio channel 2 location (high 5 bits) */ - { L"AUD2LCL", 0xdff0C2, 2, 2 }, /* Audio channel 2 location (low 15 bits) */ - { L"AUD2LEN", 0xdff0C4, 2 }, /* Audio channel 2 lentgh */ - { L"AUD2PER", 0xdff0C6, 2 }, /* Audio channel 2 period */ - { L"AUD2VOL", 0xdff0C8, 2 }, /* Audio channel 2 volume */ - { L"AUD2DAT", 0xdff0CA, 2 }, /* Audio channel 2 data */ + { L"AUD2LCH", 0xdff0C0, 2, 1 }, /* Audio channel 2 location (high 5 bits) */ + { L"AUD2LCL", 0xdff0C2, 2, 2 }, /* Audio channel 2 location (low 15 bits) */ + { L"AUD2LEN", 0xdff0C4, 2 }, /* Audio channel 2 lentgh */ + { L"AUD2PER", 0xdff0C6, 2 }, /* Audio channel 2 period */ + { L"AUD2VOL", 0xdff0C8, 2 }, /* Audio channel 2 volume */ + { L"AUD2DAT", 0xdff0CA, 2 }, /* Audio channel 2 data */ #if 0 - { L"Unknown", 0xdff0CC }, /* Unknown or Unused */ - { L"Unknown", 0xdff0CE }, /* Unknown or Unused */ + { L"Unknown", 0xdff0CC }, /* Unknown or Unused */ + { L"Unknown", 0xdff0CE }, /* Unknown or Unused */ #endif - { L"AUD3LCH", 0xdff0D0, 2, 1 }, /* Audio channel 3 location (high 5 bits) */ - { L"AUD3LCL", 0xdff0D2, 2, 2 }, /* Audio channel 3 location (low 15 bits) */ - { L"AUD3LEN", 0xdff0D4, 2 }, /* Audio channel 3 lentgh */ - { L"AUD3PER", 0xdff0D6, 2 }, /* Audio channel 3 period */ - { L"AUD3VOL", 0xdff0D8, 2 }, /* Audio channel 3 volume */ - { L"AUD3DAT", 0xdff0DA, 2 }, /* Audio channel 3 data */ + { L"AUD3LCH", 0xdff0D0, 2, 1 }, /* Audio channel 3 location (high 5 bits) */ + { L"AUD3LCL", 0xdff0D2, 2, 2 }, /* Audio channel 3 location (low 15 bits) */ + { L"AUD3LEN", 0xdff0D4, 2 }, /* Audio channel 3 lentgh */ + { L"AUD3PER", 0xdff0D6, 2 }, /* Audio channel 3 period */ + { L"AUD3VOL", 0xdff0D8, 2 }, /* Audio channel 3 volume */ + { L"AUD3DAT", 0xdff0DA, 2 }, /* Audio channel 3 data */ #if 0 - { L"Unknown", 0xdff0DC }, /* Unknown or Unused */ - { L"Unknown", 0xdff0DE }, /* Unknown or Unused */ + { L"Unknown", 0xdff0DC }, /* Unknown or Unused */ + { L"Unknown", 0xdff0DE }, /* Unknown or Unused */ #endif - { L"BPL1PTH", 0xdff0E0, 2, 1 }, /* Bit plane pointer 1 (high 5 bits) */ - { L"BPL1PTL", 0xdff0E2, 2, 2 }, /* Bit plane pointer 1 (low 15 bits) */ - { L"BPL2PTH", 0xdff0E4, 2, 1 }, /* Bit plane pointer 2 (high 5 bits) */ - { L"BPL2PTL", 0xdff0E6, 2, 2 }, /* Bit plane pointer 2 (low 15 bits) */ - { L"BPL3PTH", 0xdff0E8, 2, 1 }, /* Bit plane pointer 3 (high 5 bits) */ - { L"BPL3PTL", 0xdff0EA, 2, 2 }, /* Bit plane pointer 3 (low 15 bits) */ - { L"BPL4PTH", 0xdff0EC, 2, 1 }, /* Bit plane pointer 4 (high 5 bits) */ - { L"BPL4PTL", 0xdff0EE, 2, 2 }, /* Bit plane pointer 4 (low 15 bits) */ - { L"BPL5PTH", 0xdff0F0, 2, 1 }, /* Bit plane pointer 5 (high 5 bits) */ - { L"BPL5PTL", 0xdff0F2, 2, 2 }, /* Bit plane pointer 5 (low 15 bits) */ - { L"BPL6PTH", 0xdff0F4, 2, 1|8 }, /* Bit plane pointer 6 (high 5 bits) */ - { L"BPL6PTL", 0xdff0F6, 2, 2|8 }, /* Bit plane pointer 6 (low 15 bits) */ - { L"BPL7PTH", 0xdff0F8, 2, 1|8 }, /* Bit plane pointer 7 (high 5 bits) */ - { L"BPL7PTL", 0xdff0FA, 2, 2|8 }, /* Bit plane pointer 7 (low 15 bits) */ - { L"BPL8PTH", 0xdff0FC, 2, 1|8 }, /* Bit plane pointer 8 (high 5 bits) */ - { L"BPL8PTL", 0xdff0FE, 2, 2|8 }, /* Bit plane pointer 8 (low 15 bits) */ - { L"BPLCON0", 0xdff100, 2 }, /* Bit plane control reg (misc control bits) */ - { L"BPLCON1", 0xdff102, 2 }, /* Bit plane control reg (scroll val PF1,PF2) */ - { L"BPLCON2", 0xdff104, 2 }, /* Bit plane control reg (priority control) */ - { L"BPLCON3", 0xdff106, 2|8 }, /* Bit plane control reg (enhanced features) */ - { L"BPL1MOD", 0xdff108, 2 }, /* Bit plane modulo (odd planes,or active- fetch lines if bitplane scan-doubling is enabled */ - { L"BPL2MOD", 0xdff10A, 2 }, /* Bit plane modulo (even planes or inactive- fetch lines if bitplane scan-doubling is enabled */ - { L"BPLCON4", 0xdff10C, 2|8 }, /* Bit plane control reg (bitplane and sprite masks) */ - { L"CLXCON2", 0xdff10e, 2|8 }, /* Extended collision control reg */ - { L"BPL1DAT", 0xdff110, 2 }, /* Bit plane 1 data (parallel to serial con- vert) */ - { L"BPL2DAT", 0xdff112, 2 }, /* Bit plane 2 data (parallel to serial con- vert) */ - { L"BPL3DAT", 0xdff114, 2 }, /* Bit plane 3 data (parallel to serial con- vert) */ - { L"BPL4DAT", 0xdff116, 2 }, /* Bit plane 4 data (parallel to serial con- vert) */ - { L"BPL5DAT", 0xdff118, 2 }, /* Bit plane 5 data (parallel to serial con- vert) */ - { L"BPL6DAT", 0xdff11a, 2 }, /* Bit plane 6 data (parallel to serial con- vert) */ - { L"BPL7DAT", 0xdff11c, 2|8 }, /* Bit plane 7 data (parallel to serial con- vert) */ - { L"BPL8DAT", 0xdff11e, 2|8 }, /* Bit plane 8 data (parallel to serial con- vert) */ - { L"SPR0PTH", 0xdff120, 2, 1 }, /* Sprite 0 pointer (high 5 bits) */ - { L"SPR0PTL", 0xdff122, 2, 2 }, /* Sprite 0 pointer (low 15 bits) */ - { L"SPR1PTH", 0xdff124, 2, 1 }, /* Sprite 1 pointer (high 5 bits) */ - { L"SPR1PTL", 0xdff126, 2, 2 }, /* Sprite 1 pointer (low 15 bits) */ - { L"SPR2PTH", 0xdff128, 2, 1 }, /* Sprite 2 pointer (high 5 bits) */ - { L"SPR2PTL", 0xdff12A, 2, 2 }, /* Sprite 2 pointer (low 15 bits) */ - { L"SPR3PTH", 0xdff12C, 2, 1 }, /* Sprite 3 pointer (high 5 bits) */ - { L"SPR3PTL", 0xdff12E, 2, 2 }, /* Sprite 3 pointer (low 15 bits) */ - { L"SPR4PTH", 0xdff130, 2, 1 }, /* Sprite 4 pointer (high 5 bits) */ - { L"SPR4PTL", 0xdff132, 2, 2 }, /* Sprite 4 pointer (low 15 bits) */ - { L"SPR5PTH", 0xdff134, 2, 1 }, /* Sprite 5 pointer (high 5 bits) */ - { L"SPR5PTL", 0xdff136, 2, 2 }, /* Sprite 5 pointer (low 15 bits) */ - { L"SPR6PTH", 0xdff138, 2, 1 }, /* Sprite 6 pointer (high 5 bits) */ - { L"SPR6PTL", 0xdff13A, 2, 2 }, /* Sprite 6 pointer (low 15 bits) */ - { L"SPR7PTH", 0xdff13C, 2, 1 }, /* Sprite 7 pointer (high 5 bits) */ - { L"SPR7PTL", 0xdff13E, 2, 2 }, /* Sprite 7 pointer (low 15 bits) */ - { L"SPR0POS", 0xdff140, 2 }, /* Sprite 0 vert-horiz start pos data */ - { L"SPR0CTL", 0xdff142, 2 }, /* Sprite 0 position and control data */ - { L"SPR0DATA", 0xdff144, 2 }, /* Sprite 0 image data register A */ - { L"SPR0DATB", 0xdff146, 2 }, /* Sprite 0 image data register B */ - { L"SPR1POS", 0xdff148, 2 }, /* Sprite 1 vert-horiz start pos data */ - { L"SPR1CTL", 0xdff14A, 2 }, /* Sprite 1 position and control data */ - { L"SPR1DATA", 0xdff14C, 2 }, /* Sprite 1 image data register A */ - { L"SPR1DATB", 0xdff14E, 2 }, /* Sprite 1 image data register B */ - { L"SPR2POS", 0xdff150, 2 }, /* Sprite 2 vert-horiz start pos data */ - { L"SPR2CTL", 0xdff152, 2 }, /* Sprite 2 position and control data */ - { L"SPR2DATA", 0xdff154, 2 }, /* Sprite 2 image data register A */ - { L"SPR2DATB", 0xdff156, 2 }, /* Sprite 2 image data register B */ - { L"SPR3POS", 0xdff158, 2 }, /* Sprite 3 vert-horiz start pos data */ - { L"SPR3CTL", 0xdff15A, 2 }, /* Sprite 3 position and control data */ - { L"SPR3DATA", 0xdff15C, 2 }, /* Sprite 3 image data register A */ - { L"SPR3DATB", 0xdff15E, 2 }, /* Sprite 3 image data register B */ - { L"SPR4POS", 0xdff160, 2 }, /* Sprite 4 vert-horiz start pos data */ - { L"SPR4CTL", 0xdff162, 2 }, /* Sprite 4 position and control data */ - { L"SPR4DATA", 0xdff164, 2 }, /* Sprite 4 image data register A */ - { L"SPR4DATB", 0xdff166, 2 }, /* Sprite 4 image data register B */ - { L"SPR5POS", 0xdff168, 2 }, /* Sprite 5 vert-horiz start pos data */ - { L"SPR5CTL", 0xdff16A, 2 }, /* Sprite 5 position and control data */ - { L"SPR5DATA", 0xdff16C, 2 }, /* Sprite 5 image data register A */ - { L"SPR5DATB", 0xdff16E, 2 }, /* Sprite 5 image data register B */ - { L"SPR6POS", 0xdff170, 2 }, /* Sprite 6 vert-horiz start pos data */ - { L"SPR6CTL", 0xdff172, 2 }, /* Sprite 6 position and control data */ - { L"SPR6DATA", 0xdff174, 2 }, /* Sprite 6 image data register A */ - { L"SPR6DATB", 0xdff176, 2 }, /* Sprite 6 image data register B */ - { L"SPR7POS", 0xdff178, 2 }, /* Sprite 7 vert-horiz start pos data */ - { L"SPR7CTL", 0xdff17A, 2 }, /* Sprite 7 position and control data */ - { L"SPR7DATA", 0xdff17C, 2 }, /* Sprite 7 image data register A */ - { L"SPR7DATB", 0xdff17E, 2 }, /* Sprite 7 image data register B */ - { L"COLOR00", 0xdff180, 2 }, /* Color table 00 */ - { L"COLOR01", 0xdff182, 2 }, /* Color table 01 */ - { L"COLOR02", 0xdff184, 2 }, /* Color table 02 */ - { L"COLOR03", 0xdff186, 2 }, /* Color table 03 */ - { L"COLOR04", 0xdff188, 2 }, /* Color table 04 */ - { L"COLOR05", 0xdff18A, 2 }, /* Color table 05 */ - { L"COLOR06", 0xdff18C, 2 }, /* Color table 06 */ - { L"COLOR07", 0xdff18E, 2 }, /* Color table 07 */ - { L"COLOR08", 0xdff190, 2 }, /* Color table 08 */ - { L"COLOR09", 0xdff192, 2 }, /* Color table 09 */ - { L"COLOR10", 0xdff194, 2 }, /* Color table 10 */ - { L"COLOR11", 0xdff196, 2 }, /* Color table 11 */ - { L"COLOR12", 0xdff198, 2 }, /* Color table 12 */ - { L"COLOR13", 0xdff19A, 2 }, /* Color table 13 */ - { L"COLOR14", 0xdff19C, 2 }, /* Color table 14 */ - { L"COLOR15", 0xdff19E, 2 }, /* Color table 15 */ - { L"COLOR16", 0xdff1A0, 2 }, /* Color table 16 */ - { L"COLOR17", 0xdff1A2, 2 }, /* Color table 17 */ - { L"COLOR18", 0xdff1A4, 2 }, /* Color table 18 */ - { L"COLOR19", 0xdff1A6, 2 }, /* Color table 19 */ - { L"COLOR20", 0xdff1A8, 2 }, /* Color table 20 */ - { L"COLOR21", 0xdff1AA, 2 }, /* Color table 21 */ - { L"COLOR22", 0xdff1AC, 2 }, /* Color table 22 */ - { L"COLOR23", 0xdff1AE, 2 }, /* Color table 23 */ - { L"COLOR24", 0xdff1B0, 2 }, /* Color table 24 */ - { L"COLOR25", 0xdff1B2, 2 }, /* Color table 25 */ - { L"COLOR26", 0xdff1B4, 2 }, /* Color table 26 */ - { L"COLOR27", 0xdff1B6, 2 }, /* Color table 27 */ - { L"COLOR28", 0xdff1B8, 2 }, /* Color table 28 */ - { L"COLOR29", 0xdff1BA, 2 }, /* Color table 29 */ - { L"COLOR30", 0xdff1BC, 2 }, /* Color table 30 */ - { L"COLOR31", 0xdff1BE, 2 }, /* Color table 31 */ - { L"HTOTAL", 0xdff1C0, 2|4 }, /* Highest number count in horiz line (VARBEAMEN = 1) */ - { L"HSSTOP", 0xdff1C2, 2|4 }, /* Horiz line pos for HSYNC stop */ - { L"HBSTRT", 0xdff1C4, 2|4 }, /* Horiz line pos for HBLANK start */ - { L"HBSTOP", 0xdff1C6, 2|4 }, /* Horiz line pos for HBLANK stop */ - { L"VTOTAL", 0xdff1C8, 2|4 }, /* Highest numbered vertical line (VARBEAMEN = 1) */ - { L"VSSTOP", 0xdff1CA, 2|4 }, /* Vert line for VBLANK start */ - { L"VBSTRT", 0xdff1CC, 2|4 }, /* Vert line for VBLANK start */ - { L"VBSTOP", 0xdff1CE, 2|4 }, /* Vert line for VBLANK stop */ + { L"BPL1PTH", 0xdff0E0, 2, 1 }, /* Bit plane pointer 1 (high 5 bits) */ + { L"BPL1PTL", 0xdff0E2, 2, 2 }, /* Bit plane pointer 1 (low 15 bits) */ + { L"BPL2PTH", 0xdff0E4, 2, 1 }, /* Bit plane pointer 2 (high 5 bits) */ + { L"BPL2PTL", 0xdff0E6, 2, 2 }, /* Bit plane pointer 2 (low 15 bits) */ + { L"BPL3PTH", 0xdff0E8, 2, 1 }, /* Bit plane pointer 3 (high 5 bits) */ + { L"BPL3PTL", 0xdff0EA, 2, 2 }, /* Bit plane pointer 3 (low 15 bits) */ + { L"BPL4PTH", 0xdff0EC, 2, 1 }, /* Bit plane pointer 4 (high 5 bits) */ + { L"BPL4PTL", 0xdff0EE, 2, 2 }, /* Bit plane pointer 4 (low 15 bits) */ + { L"BPL5PTH", 0xdff0F0, 2, 1 }, /* Bit plane pointer 5 (high 5 bits) */ + { L"BPL5PTL", 0xdff0F2, 2, 2 }, /* Bit plane pointer 5 (low 15 bits) */ + { L"BPL6PTH", 0xdff0F4, 2, 1|8 }, /* Bit plane pointer 6 (high 5 bits) */ + { L"BPL6PTL", 0xdff0F6, 2, 2|8 }, /* Bit plane pointer 6 (low 15 bits) */ + { L"BPL7PTH", 0xdff0F8, 2, 1|8 }, /* Bit plane pointer 7 (high 5 bits) */ + { L"BPL7PTL", 0xdff0FA, 2, 2|8 }, /* Bit plane pointer 7 (low 15 bits) */ + { L"BPL8PTH", 0xdff0FC, 2, 1|8 }, /* Bit plane pointer 8 (high 5 bits) */ + { L"BPL8PTL", 0xdff0FE, 2, 2|8 }, /* Bit plane pointer 8 (low 15 bits) */ + { L"BPLCON0", 0xdff100, 2 }, /* Bit plane control reg (misc control bits) */ + { L"BPLCON1", 0xdff102, 2 }, /* Bit plane control reg (scroll val PF1,PF2) */ + { L"BPLCON2", 0xdff104, 2 }, /* Bit plane control reg (priority control) */ + { L"BPLCON3", 0xdff106, 2|8 }, /* Bit plane control reg (enhanced features) */ + { L"BPL1MOD", 0xdff108, 2 }, /* Bit plane modulo (odd planes,or active- fetch lines if bitplane scan-doubling is enabled */ + { L"BPL2MOD", 0xdff10A, 2 }, /* Bit plane modulo (even planes or inactive- fetch lines if bitplane scan-doubling is enabled */ + { L"BPLCON4", 0xdff10C, 2|8 }, /* Bit plane control reg (bitplane and sprite masks) */ + { L"CLXCON2", 0xdff10e, 2|8 }, /* Extended collision control reg */ + { L"BPL1DAT", 0xdff110, 2 }, /* Bit plane 1 data (parallel to serial con- vert) */ + { L"BPL2DAT", 0xdff112, 2 }, /* Bit plane 2 data (parallel to serial con- vert) */ + { L"BPL3DAT", 0xdff114, 2 }, /* Bit plane 3 data (parallel to serial con- vert) */ + { L"BPL4DAT", 0xdff116, 2 }, /* Bit plane 4 data (parallel to serial con- vert) */ + { L"BPL5DAT", 0xdff118, 2 }, /* Bit plane 5 data (parallel to serial con- vert) */ + { L"BPL6DAT", 0xdff11a, 2 }, /* Bit plane 6 data (parallel to serial con- vert) */ + { L"BPL7DAT", 0xdff11c, 2|8 }, /* Bit plane 7 data (parallel to serial con- vert) */ + { L"BPL8DAT", 0xdff11e, 2|8 }, /* Bit plane 8 data (parallel to serial con- vert) */ + { L"SPR0PTH", 0xdff120, 2, 1 }, /* Sprite 0 pointer (high 5 bits) */ + { L"SPR0PTL", 0xdff122, 2, 2 }, /* Sprite 0 pointer (low 15 bits) */ + { L"SPR1PTH", 0xdff124, 2, 1 }, /* Sprite 1 pointer (high 5 bits) */ + { L"SPR1PTL", 0xdff126, 2, 2 }, /* Sprite 1 pointer (low 15 bits) */ + { L"SPR2PTH", 0xdff128, 2, 1 }, /* Sprite 2 pointer (high 5 bits) */ + { L"SPR2PTL", 0xdff12A, 2, 2 }, /* Sprite 2 pointer (low 15 bits) */ + { L"SPR3PTH", 0xdff12C, 2, 1 }, /* Sprite 3 pointer (high 5 bits) */ + { L"SPR3PTL", 0xdff12E, 2, 2 }, /* Sprite 3 pointer (low 15 bits) */ + { L"SPR4PTH", 0xdff130, 2, 1 }, /* Sprite 4 pointer (high 5 bits) */ + { L"SPR4PTL", 0xdff132, 2, 2 }, /* Sprite 4 pointer (low 15 bits) */ + { L"SPR5PTH", 0xdff134, 2, 1 }, /* Sprite 5 pointer (high 5 bits) */ + { L"SPR5PTL", 0xdff136, 2, 2 }, /* Sprite 5 pointer (low 15 bits) */ + { L"SPR6PTH", 0xdff138, 2, 1 }, /* Sprite 6 pointer (high 5 bits) */ + { L"SPR6PTL", 0xdff13A, 2, 2 }, /* Sprite 6 pointer (low 15 bits) */ + { L"SPR7PTH", 0xdff13C, 2, 1 }, /* Sprite 7 pointer (high 5 bits) */ + { L"SPR7PTL", 0xdff13E, 2, 2 }, /* Sprite 7 pointer (low 15 bits) */ + { L"SPR0POS", 0xdff140, 2 }, /* Sprite 0 vert-horiz start pos data */ + { L"SPR0CTL", 0xdff142, 2 }, /* Sprite 0 position and control data */ + { L"SPR0DATA", 0xdff144, 2 }, /* Sprite 0 image data register A */ + { L"SPR0DATB", 0xdff146, 2 }, /* Sprite 0 image data register B */ + { L"SPR1POS", 0xdff148, 2 }, /* Sprite 1 vert-horiz start pos data */ + { L"SPR1CTL", 0xdff14A, 2 }, /* Sprite 1 position and control data */ + { L"SPR1DATA", 0xdff14C, 2 }, /* Sprite 1 image data register A */ + { L"SPR1DATB", 0xdff14E, 2 }, /* Sprite 1 image data register B */ + { L"SPR2POS", 0xdff150, 2 }, /* Sprite 2 vert-horiz start pos data */ + { L"SPR2CTL", 0xdff152, 2 }, /* Sprite 2 position and control data */ + { L"SPR2DATA", 0xdff154, 2 }, /* Sprite 2 image data register A */ + { L"SPR2DATB", 0xdff156, 2 }, /* Sprite 2 image data register B */ + { L"SPR3POS", 0xdff158, 2 }, /* Sprite 3 vert-horiz start pos data */ + { L"SPR3CTL", 0xdff15A, 2 }, /* Sprite 3 position and control data */ + { L"SPR3DATA", 0xdff15C, 2 }, /* Sprite 3 image data register A */ + { L"SPR3DATB", 0xdff15E, 2 }, /* Sprite 3 image data register B */ + { L"SPR4POS", 0xdff160, 2 }, /* Sprite 4 vert-horiz start pos data */ + { L"SPR4CTL", 0xdff162, 2 }, /* Sprite 4 position and control data */ + { L"SPR4DATA", 0xdff164, 2 }, /* Sprite 4 image data register A */ + { L"SPR4DATB", 0xdff166, 2 }, /* Sprite 4 image data register B */ + { L"SPR5POS", 0xdff168, 2 }, /* Sprite 5 vert-horiz start pos data */ + { L"SPR5CTL", 0xdff16A, 2 }, /* Sprite 5 position and control data */ + { L"SPR5DATA", 0xdff16C, 2 }, /* Sprite 5 image data register A */ + { L"SPR5DATB", 0xdff16E, 2 }, /* Sprite 5 image data register B */ + { L"SPR6POS", 0xdff170, 2 }, /* Sprite 6 vert-horiz start pos data */ + { L"SPR6CTL", 0xdff172, 2 }, /* Sprite 6 position and control data */ + { L"SPR6DATA", 0xdff174, 2 }, /* Sprite 6 image data register A */ + { L"SPR6DATB", 0xdff176, 2 }, /* Sprite 6 image data register B */ + { L"SPR7POS", 0xdff178, 2 }, /* Sprite 7 vert-horiz start pos data */ + { L"SPR7CTL", 0xdff17A, 2 }, /* Sprite 7 position and control data */ + { L"SPR7DATA", 0xdff17C, 2 }, /* Sprite 7 image data register A */ + { L"SPR7DATB", 0xdff17E, 2 }, /* Sprite 7 image data register B */ + { L"COLOR00", 0xdff180, 2 }, /* Color table 00 */ + { L"COLOR01", 0xdff182, 2 }, /* Color table 01 */ + { L"COLOR02", 0xdff184, 2 }, /* Color table 02 */ + { L"COLOR03", 0xdff186, 2 }, /* Color table 03 */ + { L"COLOR04", 0xdff188, 2 }, /* Color table 04 */ + { L"COLOR05", 0xdff18A, 2 }, /* Color table 05 */ + { L"COLOR06", 0xdff18C, 2 }, /* Color table 06 */ + { L"COLOR07", 0xdff18E, 2 }, /* Color table 07 */ + { L"COLOR08", 0xdff190, 2 }, /* Color table 08 */ + { L"COLOR09", 0xdff192, 2 }, /* Color table 09 */ + { L"COLOR10", 0xdff194, 2 }, /* Color table 10 */ + { L"COLOR11", 0xdff196, 2 }, /* Color table 11 */ + { L"COLOR12", 0xdff198, 2 }, /* Color table 12 */ + { L"COLOR13", 0xdff19A, 2 }, /* Color table 13 */ + { L"COLOR14", 0xdff19C, 2 }, /* Color table 14 */ + { L"COLOR15", 0xdff19E, 2 }, /* Color table 15 */ + { L"COLOR16", 0xdff1A0, 2 }, /* Color table 16 */ + { L"COLOR17", 0xdff1A2, 2 }, /* Color table 17 */ + { L"COLOR18", 0xdff1A4, 2 }, /* Color table 18 */ + { L"COLOR19", 0xdff1A6, 2 }, /* Color table 19 */ + { L"COLOR20", 0xdff1A8, 2 }, /* Color table 20 */ + { L"COLOR21", 0xdff1AA, 2 }, /* Color table 21 */ + { L"COLOR22", 0xdff1AC, 2 }, /* Color table 22 */ + { L"COLOR23", 0xdff1AE, 2 }, /* Color table 23 */ + { L"COLOR24", 0xdff1B0, 2 }, /* Color table 24 */ + { L"COLOR25", 0xdff1B2, 2 }, /* Color table 25 */ + { L"COLOR26", 0xdff1B4, 2 }, /* Color table 26 */ + { L"COLOR27", 0xdff1B6, 2 }, /* Color table 27 */ + { L"COLOR28", 0xdff1B8, 2 }, /* Color table 28 */ + { L"COLOR29", 0xdff1BA, 2 }, /* Color table 29 */ + { L"COLOR30", 0xdff1BC, 2 }, /* Color table 30 */ + { L"COLOR31", 0xdff1BE, 2 }, /* Color table 31 */ + { L"HTOTAL", 0xdff1C0, 2|4 }, /* Highest number count in horiz line (VARBEAMEN = 1) */ + { L"HSSTOP", 0xdff1C2, 2|4 }, /* Horiz line pos for HSYNC stop */ + { L"HBSTRT", 0xdff1C4, 2|4 }, /* Horiz line pos for HBLANK start */ + { L"HBSTOP", 0xdff1C6, 2|4 }, /* Horiz line pos for HBLANK stop */ + { L"VTOTAL", 0xdff1C8, 2|4 }, /* Highest numbered vertical line (VARBEAMEN = 1) */ + { L"VSSTOP", 0xdff1CA, 2|4 }, /* Vert line for VBLANK start */ + { L"VBSTRT", 0xdff1CC, 2|4 }, /* Vert line for VBLANK start */ + { L"VBSTOP", 0xdff1CE, 2|4 }, /* Vert line for VBLANK stop */ #if 0 - { L"SPRHSTRT", 0xdff1D0 }, /* UHRES sprite vertical start */ - { L"SPRHSTOP", 0xdff1D2 }, /* UHRES sprite vertical stop */ - { L"BPLHSTRT", 0xdff1D4 }, /* UHRES bit plane vertical stop */ - { L"BPLHSTOP", 0xdff1D6 }, /* UHRES bit plane vertical stop */ - { L"HHPOSW", 0xdff1D8 }, /* DUAL mode hires H beam counter write */ - { L"HHPOSR", 0xdff1DA }, /* DUAL mode hires H beam counter read */ + { L"SPRHSTRT", 0xdff1D0 }, /* UHRES sprite vertical start */ + { L"SPRHSTOP", 0xdff1D2 }, /* UHRES sprite vertical stop */ + { L"BPLHSTRT", 0xdff1D4 }, /* UHRES bit plane vertical stop */ + { L"BPLHSTOP", 0xdff1D6 }, /* UHRES bit plane vertical stop */ + { L"HHPOSW", 0xdff1D8 }, /* DUAL mode hires H beam counter write */ + { L"HHPOSR", 0xdff1DA }, /* DUAL mode hires H beam counter read */ #endif - { L"BEAMCON0", 0xdff1DC, 2|4 }, /* Beam counter control register (SHRES,UHRES,PAL) */ - { L"HSSTRT", 0xdff1DE, 2|4 }, /* Horizontal sync start (VARHSY) */ - { L"VSSTRT", 0xdff1E0, 2|4 }, /* Vertical sync start (VARVSY) */ - { L"HCENTER", 0xdff1E2, 2|4 }, /* Horizontal pos for vsync on interlace */ - { L"DIWHIGH", 0xdff1E4, 2|4 }, /* Display window upper bits for start/stop */ + { L"BEAMCON0", 0xdff1DC, 2|4 }, /* Beam counter control register (SHRES,UHRES,PAL) */ + { L"HSSTRT", 0xdff1DE, 2|4 }, /* Horizontal sync start (VARHSY) */ + { L"VSSTRT", 0xdff1E0, 2|4 }, /* Vertical sync start (VARVSY) */ + { L"HCENTER", 0xdff1E2, 2|4 }, /* Horizontal pos for vsync on interlace */ + { L"DIWHIGH", 0xdff1E4, 2|4 }, /* Display window upper bits for start/stop */ #if 0 - { L"BPLHMOD", 0xdff1E6 }, /* UHRES bit plane modulo */ - { L"SPRHPTH", 0xdff1E8 }, /* UHRES sprite pointer (high 5 bits) */ - { L"SPRHPTL", 0xdff1EA }, /* UHRES sprite pointer (low 15 bits) */ - { L"BPLHPTH", 0xdff1EC }, /* VRam (UHRES) bitplane pointer (hi 5 bits) */ - { L"BPLHPTL", 0xdff1EE }, /* VRam (UHRES) bitplane pointer (lo 15 bits) */ - { L"RESERVED", 0xdff1F0 }, /* Reserved (forever i guess!) */ - { L"RESERVED", 0xdff1F2 }, /* Reserved (forever i guess!) */ - { L"RESERVED", 0xdff1F4 }, /* Reserved (forever i guess!) */ - { L"RESERVED", 0xdff1F6 }, /* Reserved (forever i guess!) */ - { L"RESERVED", 0xdff1F8 }, /* Reserved (forever i guess!) */ - { L"RESERVED", 0xdff1Fa }, /* Reserved (forever i guess!) */ + { L"BPLHMOD", 0xdff1E6 }, /* UHRES bit plane modulo */ + { L"SPRHPTH", 0xdff1E8 }, /* UHRES sprite pointer (high 5 bits) */ + { L"SPRHPTL", 0xdff1EA }, /* UHRES sprite pointer (low 15 bits) */ + { L"BPLHPTH", 0xdff1EC }, /* VRam (UHRES) bitplane pointer (hi 5 bits) */ + { L"BPLHPTL", 0xdff1EE }, /* VRam (UHRES) bitplane pointer (lo 15 bits) */ + { L"RESERVED", 0xdff1F0 }, /* Reserved (forever i guess!) */ + { L"RESERVED", 0xdff1F2 }, /* Reserved (forever i guess!) */ + { L"RESERVED", 0xdff1F4 }, /* Reserved (forever i guess!) */ + { L"RESERVED", 0xdff1F6 }, /* Reserved (forever i guess!) */ + { L"RESERVED", 0xdff1F8 }, /* Reserved (forever i guess!) */ + { L"RESERVED", 0xdff1Fa }, /* Reserved (forever i guess!) */ #endif - { L"FMODE", 0xdff1FC, 2|8 }, /* Fetch mode register */ - { L"NO-OP(NULL)", 0xdff1FE }, /* Can also indicate last 2 or 3 refresh - cycles or the restart of the COPPER after lockup.*/ - { NULL } + { L"FMODE", 0xdff1FC, 2|8 }, /* Fetch mode register */ + { L"NO-OP(NULL)", 0xdff1FE }, /* Can also indicate last 2 or 3 refresh + cycles or the restart of the COPPER after lockup.*/ + { NULL } }; #endif diff --git a/include/audio.h b/include/audio.h index 01286899..a987a7cf 100644 --- a/include/audio.h +++ b/include/audio.h @@ -29,7 +29,7 @@ extern void audio_evhandler (void); extern void audio_hsync (int); extern void audio_update_adkmasks (void); extern void audio_update_irq (uae_u16); -extern void update_sound (int freq, int longframe); +extern void update_sound (int freq, int longframe, int linetoggle); extern void led_filter_audio (void); extern void set_audio (void); extern int audio_activate (void); diff --git a/include/cpu_prefetch.h b/include/cpu_prefetch.h index a7dc9170..26f3dd84 100644 --- a/include/cpu_prefetch.h +++ b/include/cpu_prefetch.h @@ -1,254 +1,269 @@ STATIC_INLINE uae_u32 get_word_prefetch (int o) { - uae_u32 v = regs.irc; - regs.irc = get_wordi (m68k_getpc () + o); - return v; + uae_u32 v = regs.irc; + regs.irc = get_wordi (m68k_getpc () + o); + return v; } STATIC_INLINE uae_u32 get_long_prefetch (int o) { - uae_u32 v = get_word_prefetch (o) << 16; - v |= get_word_prefetch (o + 2); - return v; + uae_u32 v = get_word_prefetch (o) << 16; + v |= get_word_prefetch (o + 2); + return v; } #ifdef CPUEMU_20 -STATIC_INLINE uae_u32 mem_access_delay_long_read_020 (uaecptr addr) +STATIC_INLINE void checkcycles_ce020 (void) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + if (regs.ce020memcycles > 0) + do_cycles_ce (regs.ce020memcycles); + regs.ce020memcycles = 0; +} + +STATIC_INLINE uae_u32 mem_access_delay_long_read_ce020 (uaecptr addr) +{ + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - if ((addr & 3) != 0) { - uae_u32 v; - v = wait_cpu_cycle_read (addr + 0, 1) << 16; - v |= wait_cpu_cycle_read (addr + 2, 1) << 0; - return v; - } else { - return wait_cpu_cycle_read (addr, -1); - } + if ((addr & 3) != 0) { + uae_u32 v; + v = wait_cpu_cycle_read_ce020 (addr + 0, 1) << 16; + v |= wait_cpu_cycle_read_ce020 (addr + 2, 1) << 0; + return v; + } else { + return wait_cpu_cycle_read_ce020 (addr, -1); + } case CE_MEMBANK_FAST: - if ((addr & 3) != 0) - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - else - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; + if ((addr & 3) != 0) + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + else + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - break; - } - return get_long (addr); + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + break; + } + return get_long (addr); } -STATIC_INLINE uae_u32 mem_access_delay_longi_read_020 (uaecptr addr) +STATIC_INLINE uae_u32 mem_access_delay_longi_read_ce020 (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - if ((addr & 3) != 0) { - uae_u32 v; - v = wait_cpu_cycle_read (addr + 0, 1) << 16; - v |= wait_cpu_cycle_read (addr + 2, 1) << 0; - return v; - } else { - return wait_cpu_cycle_read (addr, -1); - } + if ((addr & 3) != 0) { + uae_u32 v; + v = wait_cpu_cycle_read_ce020 (addr + 0, 1) << 16; + v |= wait_cpu_cycle_read_ce020 (addr + 2, 1) << 0; + return v; + } else { + return wait_cpu_cycle_read_ce020 (addr, -1); + } case CE_MEMBANK_FAST: - if ((addr & 3) != 0) - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - else - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; + if ((addr & 3) != 0) + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + else + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - break; - } - return get_longi (addr); + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + break; + } + return get_longi (addr); } -STATIC_INLINE uae_u32 mem_access_delay_word_read_020 (uaecptr addr) +STATIC_INLINE uae_u32 mem_access_delay_word_read_ce020 (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - if ((addr & 3) == 3) { - uae_u16 v; - v = wait_cpu_cycle_read (addr + 0, 0) << 8; - v |= wait_cpu_cycle_read (addr + 1, 0) << 0; - return v; - } else { - return wait_cpu_cycle_read (addr, 1); - } + if ((addr & 3) == 3) { + uae_u16 v; + v = wait_cpu_cycle_read_ce020 (addr + 0, 0) << 8; + v |= wait_cpu_cycle_read_ce020 (addr + 1, 0) << 0; + return v; + } else { + return wait_cpu_cycle_read_ce020 (addr, 1); + } case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - if ((addr & 3) == 3) - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - else - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; - } - return get_word (addr); + if ((addr & 3) == 3) + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + else + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; + } + return get_word (addr); } -STATIC_INLINE uae_u32 mem_access_delay_wordi_read_020 (uaecptr addr) +STATIC_INLINE uae_u32 mem_access_delay_wordi_read_ce020 (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - return wait_cpu_cycle_read (addr, 1); + return wait_cpu_cycle_read_ce020 (addr, 1); case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; - } - return get_wordi (addr); + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; + } + return get_wordi (addr); } -STATIC_INLINE uae_u32 mem_access_delay_byte_read_020 (uaecptr addr) +STATIC_INLINE uae_u32 mem_access_delay_byte_read_ce020 (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - return wait_cpu_cycle_read (addr, 0); + return wait_cpu_cycle_read_ce020 (addr, 0); case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; - - } - return get_byte (addr); + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; + + } + return get_byte (addr); } -STATIC_INLINE void mem_access_delay_byte_write_020 (uaecptr addr, uae_u32 v) +STATIC_INLINE void mem_access_delay_byte_write_ce020 (uaecptr addr, uae_u32 v) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - wait_cpu_cycle_write (addr, 0, v); - return; + wait_cpu_cycle_write_ce020 (addr, 0, v); + return; case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; - } - put_byte (addr, v); + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; + } + put_byte (addr, v); } -STATIC_INLINE void mem_access_delay_word_write_020 (uaecptr addr, uae_u32 v) +STATIC_INLINE void mem_access_delay_word_write_ce020 (uaecptr addr, uae_u32 v) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - if ((addr & 3) == 3) { - wait_cpu_cycle_write (addr + 0, 0, (v >> 8) & 0xff); - wait_cpu_cycle_write (addr + 1, 0, (v >> 0) & 0xff); - } else { - wait_cpu_cycle_write (addr + 0, 1, v); - } - return; - break; + if ((addr & 3) == 3) { + wait_cpu_cycle_write_ce020 (addr + 0, 0, (v >> 8) & 0xff); + wait_cpu_cycle_write_ce020 (addr + 1, 0, (v >> 0) & 0xff); + } else { + wait_cpu_cycle_write_ce020 (addr + 0, 1, v); + } + return; + break; case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - if ((addr & 3) == 3) - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - else - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; - } - put_word (addr, v); + if ((addr & 3) == 3) + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + else + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; + } + put_word (addr, v); } -STATIC_INLINE void mem_access_delay_long_write_020 (uaecptr addr, uae_u32 v) +STATIC_INLINE void mem_access_delay_long_write_ce020 (uaecptr addr, uae_u32 v) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + checkcycles_ce020 (); + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - if ((addr & 3) == 3) { - wait_cpu_cycle_write (addr + 0, 1, (v >> 16) & 0xffff); - wait_cpu_cycle_write (addr + 2, 1, (v >> 0) & 0xffff); - } else { - wait_cpu_cycle_write (addr + 0, -1, v); - } - return; - break; + if ((addr & 3) == 3) { + wait_cpu_cycle_write_ce020 (addr + 0, 1, (v >> 16) & 0xffff); + wait_cpu_cycle_write_ce020 (addr + 2, 1, (v >> 0) & 0xffff); + } else { + wait_cpu_cycle_write_ce020 (addr + 0, -1, v); + } + return; + break; case CE_MEMBANK_FAST: - if ((addr & 3) != 0) - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - else - do_cycles_ce020 (1 * CPU020_MEM_CYCLE); - break; + if ((addr & 3) != 0) + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + else + do_cycles_ce020_mem (1 * CPU020_MEM_CYCLE); + break; case CE_MEMBANK_FAST16BIT: - do_cycles_ce020 (2 * CPU020_MEM_CYCLE); - break; - } - put_long (addr, v); + do_cycles_ce020_mem (2 * CPU020_MEM_CYCLE); + break; + } + put_long (addr, v); } STATIC_INLINE uae_u32 get_long_ce020 (uaecptr addr) { - return mem_access_delay_long_read_020 (addr); + return mem_access_delay_long_read_ce020 (addr); } STATIC_INLINE uae_u32 get_word_ce020 (uaecptr addr) { - return mem_access_delay_word_read_020 (addr); + return mem_access_delay_word_read_ce020 (addr); } STATIC_INLINE uae_u32 get_byte_ce020 (uaecptr addr) { - return mem_access_delay_byte_read_020 (addr); + return mem_access_delay_byte_read_ce020 (addr); } STATIC_INLINE void put_long_ce020 (uaecptr addr, uae_u32 v) { - mem_access_delay_long_write_020 (addr, v); + mem_access_delay_long_write_ce020 (addr, v); } STATIC_INLINE void put_word_ce020 (uaecptr addr, uae_u16 v) { - mem_access_delay_word_write_020 (addr, v); + mem_access_delay_word_write_ce020 (addr, v); } STATIC_INLINE void put_byte_ce020 (uaecptr addr, uae_u8 v) { - mem_access_delay_byte_write_020 (addr, v); + mem_access_delay_byte_write_ce020 (addr, v); } extern void fill_cache0x0 (uae_u32); STATIC_INLINE uae_u32 get_word_ce020_prefetch (int o) { - uae_u32 pc = m68k_getpc () + o; + uae_u32 pc = m68k_getpc () + o; - for (;;) { - if (pc == regs.prefetch020addr) { - uae_u32 v = regs.prefetch020data >> 16; - return v; - } - if (pc == regs.prefetch020addr + 2) { - uae_u32 v = regs.prefetch020data & 0xffff; - fill_cache0x0 (pc + 2); - return v; + for (;;) { + if (pc == regs.prefetch020addr) { + uae_u32 v = regs.prefetch020data >> 16; + return v; + } + if (pc == regs.prefetch020addr + 2) { + uae_u32 v = regs.prefetch020data & 0xffff; + fill_cache0x0 (pc + 2); + return v; + } + fill_cache0x0 (pc); } - fill_cache0x0 (pc); - } } STATIC_INLINE uae_u32 get_long_ce020_prefetch (int o) { - uae_u32 v; - v = get_word_ce020_prefetch (o) << 16; - v |= get_word_ce020_prefetch (o + 2); - return v; + uae_u32 v; + v = get_word_ce020_prefetch (o) << 16; + v |= get_word_ce020_prefetch (o + 2); + return v; } STATIC_INLINE uae_u32 next_iword_020ce (void) { - uae_u32 r = get_word_ce020_prefetch (0); - m68k_incpc (2); - return r; + uae_u32 r = get_word_ce020_prefetch (0); + m68k_incpc (2); + return r; } STATIC_INLINE uae_u32 next_ilong_020ce (void) { - uae_u32 r = get_long_ce020_prefetch (0); - m68k_incpc (4); - return r; + uae_u32 r = get_long_ce020_prefetch (0); + m68k_incpc (4); + return r; } #endif @@ -256,127 +271,127 @@ STATIC_INLINE uae_u32 next_ilong_020ce (void) STATIC_INLINE uae_u32 mem_access_delay_word_read (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - return wait_cpu_cycle_read (addr, 1); + return wait_cpu_cycle_read (addr, 1); case CE_MEMBANK_FAST: case CE_MEMBANK_FAST16BIT: - do_cycles_ce000 (4); - break; - } - return get_word (addr); + do_cycles_ce000 (4); + break; + } + return get_word (addr); } STATIC_INLINE uae_u32 mem_access_delay_wordi_read (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - return wait_cpu_cycle_read (addr, 1); + return wait_cpu_cycle_read (addr, 1); case CE_MEMBANK_FAST: - do_cycles_ce000 (4); - break; - } - return get_wordi (addr); + do_cycles_ce000 (4); + break; + } + return get_wordi (addr); } STATIC_INLINE uae_u32 mem_access_delay_byte_read (uaecptr addr) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - return wait_cpu_cycle_read (addr, 0); + return wait_cpu_cycle_read (addr, 0); case CE_MEMBANK_FAST: - do_cycles_ce000 (4); - break; - - } - return get_byte (addr); + do_cycles_ce000 (4); + break; + + } + return get_byte (addr); } STATIC_INLINE void mem_access_delay_byte_write (uaecptr addr, uae_u32 v) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - wait_cpu_cycle_write (addr, 0, v); - return; + wait_cpu_cycle_write (addr, 0, v); + return; case CE_MEMBANK_FAST: - do_cycles_ce000 (4); - break; - } - put_byte (addr, v); + do_cycles_ce000 (4); + break; + } + put_byte (addr, v); } STATIC_INLINE void mem_access_delay_word_write (uaecptr addr, uae_u32 v) { - switch (ce_banktype[(addr >> 16) & 0xff]) - { + switch (ce_banktype[(addr >> 16) & 0xff]) + { case CE_MEMBANK_CHIP: - wait_cpu_cycle_write (addr, 1, v); - return; - break; + wait_cpu_cycle_write (addr, 1, v); + return; + break; case CE_MEMBANK_FAST: - do_cycles_ce000 (4); - break; - } - put_word (addr, v); + do_cycles_ce000 (4); + break; + } + put_word (addr, v); } STATIC_INLINE uae_u32 get_word_ce (uaecptr addr) { - return mem_access_delay_word_read (addr); + return mem_access_delay_word_read (addr); } STATIC_INLINE uae_u32 get_wordi_ce (uaecptr addr) { - return mem_access_delay_wordi_read (addr); + return mem_access_delay_wordi_read (addr); } STATIC_INLINE uae_u32 get_byte_ce (uaecptr addr) { - return mem_access_delay_byte_read (addr); + return mem_access_delay_byte_read (addr); } STATIC_INLINE uae_u32 get_word_ce_prefetch (int o) { - uae_u32 v = regs.irc; - regs.irc = get_wordi_ce (m68k_getpc () + o); - return v; + uae_u32 v = regs.irc; + regs.irc = get_wordi_ce (m68k_getpc () + o); + return v; } STATIC_INLINE void put_word_ce (uaecptr addr, uae_u16 v) { - mem_access_delay_word_write (addr, v); + mem_access_delay_word_write (addr, v); } STATIC_INLINE void put_byte_ce (uaecptr addr, uae_u8 v) { - mem_access_delay_byte_write (addr, v); + mem_access_delay_byte_write (addr, v); } STATIC_INLINE void m68k_do_rts_ce (void) { - uaecptr pc; - pc = get_word_ce (m68k_areg (regs, 7)) << 16; - pc |= get_word_ce (m68k_areg (regs, 7) + 2); - m68k_areg (regs, 7) += 4; - if (pc & 1) - exception3 (0x4e75, m68k_getpc (), pc); - else - m68k_setpc (pc); + uaecptr pc; + pc = get_word_ce (m68k_areg (regs, 7)) << 16; + pc |= get_word_ce (m68k_areg (regs, 7) + 2); + m68k_areg (regs, 7) += 4; + if (pc & 1) + exception3 (0x4e75, m68k_getpc (), pc); + else + m68k_setpc (pc); } STATIC_INLINE void m68k_do_bsr_ce (uaecptr oldpc, uae_s32 offset) { - m68k_areg (regs, 7) -= 4; - put_word_ce (m68k_areg (regs, 7), oldpc >> 16); - put_word_ce (m68k_areg (regs, 7) + 2, oldpc); - m68k_incpc (offset); + m68k_areg (regs, 7) -= 4; + put_word_ce (m68k_areg (regs, 7), oldpc >> 16); + put_word_ce (m68k_areg (regs, 7) + 2, oldpc); + m68k_incpc (offset); } STATIC_INLINE void m68k_do_jsr_ce (uaecptr oldpc, uaecptr dest) { - m68k_areg (regs, 7) -= 4; - put_word_ce (m68k_areg (regs, 7), oldpc >> 16); - put_word_ce (m68k_areg (regs, 7) + 2, oldpc); - m68k_setpc (dest); + m68k_areg (regs, 7) -= 4; + put_word_ce (m68k_areg (regs, 7), oldpc >> 16); + put_word_ce (m68k_areg (regs, 7) + 2, oldpc); + m68k_setpc (dest); } #endif \ No newline at end of file diff --git a/include/custom.h b/include/custom.h index d86b2283..e447c98d 100644 --- a/include/custom.h +++ b/include/custom.h @@ -101,7 +101,9 @@ extern uae_u16 INTREQR (void); #define VBLANK_HZ_PAL 50 #define VBLANK_HZ_NTSC 60 -extern int maxhpos, maxvpos, maxvpos_max, minfirstline, vblank_endline, numscrlines; +extern int maxhpos, maxhpos_short; +extern int maxvpos, maxvpos_max; +extern int minfirstline, vblank_endline, numscrlines; extern int vblank_hz, fake_vblank_hz, vblank_skip, doublescan; extern frame_time_t syncbase; #define NUMSCRLINES (maxvpos + 1 - minfirstline + 1) diff --git a/include/events.h b/include/events.h index 5022ac03..f3c5be4f 100644 --- a/include/events.h +++ b/include/events.h @@ -25,6 +25,7 @@ extern void compute_vsynctime (void); extern void init_eventtab (void); extern void do_cycles_ce (long cycles); extern void do_cycles_ce020 (int clocks); +extern void do_cycles_ce020_mem (int clocks); extern void do_cycles_ce000 (int clocks); extern int is_cycle_ce (void); diff --git a/include/filesys.h b/include/filesys.h index 8d5a11ba..79682ccf 100644 --- a/include/filesys.h +++ b/include/filesys.h @@ -120,3 +120,4 @@ extern void hdf_close_target (struct hardfiledata *hfd); extern int hdf_read_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len); extern int hdf_write_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len); extern int hdf_resize_target (struct hardfiledata *hfd, uae_u64 newsize); +extern void getchsgeometry (uae_u64 size, int *pcyl, int *phead, int *psectorspertrack); diff --git a/include/memory.h b/include/memory.h index 42a4f586..e49578c7 100644 --- a/include/memory.h +++ b/include/memory.h @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * memory management - * - * Copyright 1995 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* memory management +* +* Copyright 1995 Bernd Schmidt +*/ extern void memory_reset (void); extern void a1000_reset (void); @@ -47,8 +47,9 @@ extern uae_u32 allocated_a3000mem; extern uae_u32 allocated_cardmem; extern uae_u32 wait_cpu_cycle_read (uaecptr addr, int mode); -extern uae_u32 wait_cpu_cycle_read_cycles (uaecptr addr, int mode, int *cycles); extern void wait_cpu_cycle_write (uaecptr addr, int mode, uae_u32 v); +extern uae_u32 wait_cpu_cycle_read_ce020 (uaecptr addr, int mode); +extern void wait_cpu_cycle_write_ce020 (uaecptr addr, int mode, uae_u32 v); #undef DIRECT_MEMFUNCS_SUCCESSFUL #include "machdep/maccess.h" @@ -72,28 +73,28 @@ extern uae_u8* baseaddr[]; enum { ABFLAG_UNK = 0, ABFLAG_RAM = 1, ABFLAG_ROM = 2, ABFLAG_ROMIN = 4, ABFLAG_IO = 8, ABFLAG_NONE = 16, ABFLAG_SAFE = 32 }; typedef struct { - /* These ones should be self-explanatory... */ - mem_get_func lget, wget, bget; - mem_put_func lput, wput, bput; - /* Use xlateaddr to translate an Amiga address to a uae_u8 * that can - * be used to address memory without calling the wget/wput functions. - * This doesn't work for all memory banks, so this function may call - * abort(). */ - xlate_func xlateaddr; - /* To prevent calls to abort(), use check before calling xlateaddr. - * It checks not only that the memory bank can do xlateaddr, but also - * that the pointer points to an area of at least the specified size. - * This is used for example to translate bitplane pointers in custom.c */ - check_func check; - /* For those banks that refer to real memory, we can save the whole trouble - of going through function calls, and instead simply grab the memory - ourselves. This holds the memory address where the start of memory is - for this particular bank. */ - uae_u8 *baseaddr; - TCHAR *name; - /* for instruction opcode/operand fetches */ - mem_get_func lgeti, wgeti; - int flags; + /* These ones should be self-explanatory... */ + mem_get_func lget, wget, bget; + mem_put_func lput, wput, bput; + /* Use xlateaddr to translate an Amiga address to a uae_u8 * that can + * be used to address memory without calling the wget/wput functions. + * This doesn't work for all memory banks, so this function may call + * abort(). */ + xlate_func xlateaddr; + /* To prevent calls to abort(), use check before calling xlateaddr. + * It checks not only that the memory bank can do xlateaddr, but also + * that the pointer points to an area of at least the specified size. + * This is used for example to translate bitplane pointers in custom.c */ + check_func check; + /* For those banks that refer to real memory, we can save the whole trouble + of going through function calls, and instead simply grab the memory + ourselves. This holds the memory address where the start of memory is + for this particular bank. */ + uae_u8 *baseaddr; + TCHAR *name; + /* for instruction opcode/operand fetches */ + mem_get_func lgeti, wgeti; + int flags; } addrbank; #define CE_MEMBANK_FAST 0 @@ -155,15 +156,15 @@ extern uae_u8 *baseaddr[MEMORY_BANKS]; #ifdef JIT #define put_mem_bank(addr, b, realstart) do { \ - (mem_banks[bankindex(addr)] = (b)); \ - if ((b)->baseaddr) \ + (mem_banks[bankindex(addr)] = (b)); \ + if ((b)->baseaddr) \ baseaddr[bankindex(addr)] = (b)->baseaddr - (realstart); \ - else \ + else \ baseaddr[bankindex(addr)] = (uae_u8*)(((uae_u8*)b)+1); \ } while (0) #else #define put_mem_bank(addr, b, realstart) \ - (mem_banks[bankindex(addr)] = (b)); + (mem_banks[bankindex(addr)] = (b)); #endif extern void memory_init (void); @@ -184,49 +185,49 @@ extern void free_fastmemory (void); STATIC_INLINE uae_u32 get_long (uaecptr addr) { - return longget (addr); + return longget (addr); } STATIC_INLINE uae_u32 get_word (uaecptr addr) { - return wordget (addr); + return wordget (addr); } STATIC_INLINE uae_u32 get_byte (uaecptr addr) { - return byteget (addr); + return byteget (addr); } STATIC_INLINE uae_u32 get_longi(uaecptr addr) { - return longgeti (addr); + return longgeti (addr); } STATIC_INLINE uae_u32 get_wordi(uaecptr addr) { - return wordgeti (addr); + return wordgeti (addr); } /* - * Read a host pointer from addr - */ +* Read a host pointer from addr +*/ #if SIZEOF_VOID_P == 4 # define get_pointer(addr) ((void *)get_long (addr)) #else # if SIZEOF_VOID_P == 8 STATIC_INLINE void *get_pointer (uaecptr addr) { - const unsigned int n = SIZEOF_VOID_P / 4; - union { - void *ptr; - uae_u32 longs[SIZEOF_VOID_P / 4]; - } p; - unsigned int i; - - for (i = 0; i < n; i++) { + const unsigned int n = SIZEOF_VOID_P / 4; + union { + void *ptr; + uae_u32 longs[SIZEOF_VOID_P / 4]; + } p; + unsigned int i; + + for (i = 0; i < n; i++) { #ifdef WORDS_BIGENDIAN - p.longs[i] = get_long (addr + i * 4); + p.longs[i] = get_long (addr + i * 4); #else - p.longs[n - 1 - i] = get_long (addr + i * 4); + p.longs[n - 1 - i] = get_long (addr + i * 4); #endif - } - return p.ptr; + } + return p.ptr; } # else # error "Unknown or unsupported pointer size." @@ -235,15 +236,15 @@ STATIC_INLINE void *get_pointer (uaecptr addr) STATIC_INLINE void put_long (uaecptr addr, uae_u32 l) { - longput(addr, l); + longput(addr, l); } STATIC_INLINE void put_word (uaecptr addr, uae_u32 w) { - wordput(addr, w); + wordput(addr, w); } STATIC_INLINE void put_byte (uaecptr addr, uae_u32 b) { - byteput(addr, b); + byteput(addr, b); } extern void put_long_slow (uaecptr addr, uae_u32 v); @@ -255,42 +256,42 @@ extern uae_u32 get_byte_slow (uaecptr addr); /* - * Store host pointer v at addr - */ +* Store host pointer v at addr +*/ #if SIZEOF_VOID_P == 4 # define put_pointer(addr, p) (put_long ((addr), (uae_u32)(p))) #else # if SIZEOF_VOID_P == 8 STATIC_INLINE void put_pointer (uaecptr addr, void *v) { - const unsigned int n = SIZEOF_VOID_P / 4; - union { - void *ptr; - uae_u32 longs[SIZEOF_VOID_P / 4]; - } p; - unsigned int i; + const unsigned int n = SIZEOF_VOID_P / 4; + union { + void *ptr; + uae_u32 longs[SIZEOF_VOID_P / 4]; + } p; + unsigned int i; - p.ptr = v; + p.ptr = v; - for (i = 0; i < n; i++) { + for (i = 0; i < n; i++) { #ifdef WORDS_BIGENDIAN - put_long (addr + i * 4, p.longs[i]); + put_long (addr + i * 4, p.longs[i]); #else - put_long (addr + i * 4, p.longs[n - 1 - i]); + put_long (addr + i * 4, p.longs[n - 1 - i]); #endif - } + } } # endif #endif STATIC_INLINE uae_u8 *get_real_address (uaecptr addr) { - return get_mem_bank (addr).xlateaddr(addr); + return get_mem_bank (addr).xlateaddr(addr); } STATIC_INLINE int valid_address (uaecptr addr, uae_u32 size) { - return get_mem_bank (addr).check(addr, size); + return get_mem_bank (addr).check(addr, size); } extern int addr_valid (TCHAR*, uaecptr,uae_u32); @@ -326,11 +327,11 @@ extern void REGPARAM3 chipmem_bput_c2 (uaecptr, uae_u32) REGPARAM; #ifdef NATMEM_OFFSET typedef struct shmpiece_reg { - uae_u8 *native_address; - int id; - uae_u32 size; - struct shmpiece_reg *next; - struct shmpiece_reg *prev; + uae_u8 *native_address; + int id; + uae_u32 size; + struct shmpiece_reg *next; + struct shmpiece_reg *prev; } shmpiece; extern shmpiece *shm_start; @@ -369,31 +370,31 @@ extern void a3000_fakekick (int); #define ROMTYPE_SCRAMBLED 0x400000 struct romheader { - TCHAR *name; - int id; + TCHAR *name; + int id; }; struct romdata { - TCHAR *name; - int ver, rev; - int subver, subrev; - TCHAR *model; - uae_u32 size; - int id; - int cpu; - int cloanto; - int type; - int group; - int title; - TCHAR *partnumber; - uae_u32 crc32; - uae_u32 sha1[5]; - TCHAR *configname; + TCHAR *name; + int ver, rev; + int subver, subrev; + TCHAR *model; + uae_u32 size; + int id; + int cpu; + int cloanto; + int type; + int group; + int title; + TCHAR *partnumber; + uae_u32 crc32; + uae_u32 sha1[5]; + TCHAR *configname; }; struct romlist { - TCHAR *path; - struct romdata *rd; + TCHAR *path; + struct romdata *rd; }; extern struct romdata *getromdatabypath (TCHAR *path); diff --git a/include/newcpu.h b/include/newcpu.h index 013f1c8a..3f250d08 100644 --- a/include/newcpu.h +++ b/include/newcpu.h @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * MC68000 emulation - * - * Copyright 1995 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* MC68000 emulation +* +* Copyright 1995 Bernd Schmidt +*/ #include "readcpu.h" #include "machdep/m68k.h" @@ -25,10 +25,10 @@ #define GET_XFLG() XFLG() #define CLEAR_CZNV() do { \ - SET_CFLG (0); \ - SET_ZFLG (0); \ - SET_NFLG (0); \ - SET_VFLG (0); \ + SET_CFLG (0); \ + SET_ZFLG (0); \ + SET_NFLG (0); \ + SET_VFLG (0); \ } while (0) #define COPY_CARRY() (SET_XFLG (GET_CFLG ())) @@ -53,17 +53,17 @@ typedef unsigned long REGPARAM3 cpuop_func (uae_u32) REGPARAM; typedef void REGPARAM3 cpuop_func_ce (uae_u32) REGPARAM; struct cputbl { - cpuop_func *handler; - uae_u16 opcode; + cpuop_func *handler; + uae_u16 opcode; }; #ifdef JIT typedef unsigned long REGPARAM3 compop_func (uae_u32) REGPARAM; struct comptbl { - compop_func *handler; - uae_u32 opcode; - int specific; + compop_func *handler; + uae_u32 opcode; + int specific; }; #endif @@ -73,8 +73,8 @@ typedef uae_u8 flagtype; #ifdef FPUEMU /* You can set this to long double to be more accurate. However, the - resulting alignment issues will cost a lot of performance in some - apps */ +resulting alignment issues will cost a lot of performance in some +apps */ #define USE_LONG_DOUBLE 0 #if USE_LONG_DOUBLE @@ -94,96 +94,98 @@ typedef double fptype; #define CACHELINES020 64 struct cache020 { - uae_u32 data; - uae_u32 tag; - uae_u32 valid:1; + uae_u32 data; + uae_u32 tag; + uae_u32 valid:1; }; #define CACHESETS040 64 struct cache040set { - uae_u32 data[4]; - int valid[4]; - uae_u32 tag; + uae_u32 data[4]; + int valid[4]; + uae_u32 tag; }; #define CACHELINES040 4 struct cache040 { - struct cache040set cs[4]; - int count; + struct cache040set cs[4]; + int count; }; struct flag_struct regflags; extern struct regstruct { - uae_u32 regs[16]; - - uae_u32 pc; - uae_u8 *pc_p; - uae_u8 *pc_oldp; - - uae_u16 irc, ir; - uae_u32 spcflags; - - uaecptr usp, isp, msp; - uae_u16 sr; - flagtype t1; - flagtype t0; - flagtype s; - flagtype m; - flagtype x; - flagtype stopped; - int intmask; - - uae_u32 vbr, sfc, dfc; + uae_u32 regs[16]; + + uae_u32 pc; + uae_u8 *pc_p; + uae_u8 *pc_oldp; + + uae_u16 irc, ir; + uae_u32 spcflags; + + uaecptr usp, isp, msp; + uae_u16 sr; + flagtype t1; + flagtype t0; + flagtype s; + flagtype m; + flagtype x; + flagtype stopped; + int intmask; + + uae_u32 vbr, sfc, dfc; #ifdef FPUEMU - fptype fp[8]; - fptype fp_result; + fptype fp[8]; + fptype fp_result; - uae_u32 fpcr, fpsr, fpiar; - uae_u32 fpsr_highbyte; + uae_u32 fpcr, fpsr, fpiar; + uae_u32 fpsr_highbyte; #endif #ifndef CPUEMU_68000_ONLY - uae_u32 cacr, caar; - uae_u32 itt0, itt1, dtt0, dtt1; - uae_u32 tcr, mmusr, urp, srp, buscr; - uae_u32 mmu_fslw, mmu_fault_addr; - uae_u16 mmu_ssw; - uae_u32 wb3_data; - uae_u16 wb3_status; - int mmu_enabled; - int mmu_pagesize_8k; - uae_u32 fault_pc; + uae_u32 cacr, caar; + uae_u32 itt0, itt1, dtt0, dtt1; + uae_u32 tcr, mmusr, urp, srp, buscr; + uae_u32 mmu_fslw, mmu_fault_addr; + uae_u16 mmu_ssw; + uae_u32 wb3_data; + uae_u16 wb3_status; + int mmu_enabled; + int mmu_pagesize_8k; + uae_u32 fault_pc; #endif - uae_u32 pcr; - uae_u32 address_space_mask; + uae_u32 pcr; + uae_u32 address_space_mask; - uae_u8 panic; - uae_u32 panic_pc, panic_addr; + uae_u8 panic; + uae_u32 panic_pc, panic_addr; - uae_u32 prefetch020data; - uae_u32 prefetch020addr; + uae_u32 prefetch020data; + uae_u32 prefetch020addr; + int ce020memcycles; } regs, lastint_regs, mmu_backup_regs; STATIC_INLINE uae_u32 munge24 (uae_u32 x) { - return x & regs.address_space_mask; + return x & regs.address_space_mask; } extern int mmu_enabled, mmu_triggered; extern int cpu_cycles; +extern int cpucycleunit; STATIC_INLINE void set_special (uae_u32 x) { - regs.spcflags |= x; - cycles_do_special (); + regs.spcflags |= x; + cycles_do_special (); } STATIC_INLINE void unset_special (uae_u32 x) { - regs.spcflags &= ~x; + regs.spcflags &= ~x; } #define m68k_dreg(r,num) ((r).regs[(num)]) @@ -191,63 +193,63 @@ STATIC_INLINE void unset_special (uae_u32 x) STATIC_INLINE void m68k_setpc (uaecptr newpc) { - regs.pc_p = regs.pc_oldp = get_real_address (newpc); - regs.fault_pc = regs.pc = newpc; + regs.pc_p = regs.pc_oldp = get_real_address (newpc); + regs.fault_pc = regs.pc = newpc; } STATIC_INLINE uaecptr m68k_getpc (void) { - return (uaecptr)(regs.pc + ((uae_u8*)regs.pc_p - (uae_u8*)regs.pc_oldp)); + return (uaecptr)(regs.pc + ((uae_u8*)regs.pc_p - (uae_u8*)regs.pc_oldp)); } #define M68K_GETPC m68k_getpc() STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p) { - return (uaecptr)(regs.pc + ((uae_u8*)p - (uae_u8*)regs.pc_oldp)); + return (uaecptr)(regs.pc + ((uae_u8*)p - (uae_u8*)regs.pc_oldp)); } #define m68k_incpc(o) ((regs).pc_p += (o)) STATIC_INLINE void m68k_setpc_mmu (uaecptr newpc) { - regs.fault_pc = regs.pc = newpc; - regs.pc_p = regs.pc_oldp = 0; + regs.fault_pc = regs.pc = newpc; + regs.pc_p = regs.pc_oldp = 0; } STATIC_INLINE void m68k_setpci (uaecptr newpc) { - regs.fault_pc = regs.pc = newpc; + regs.fault_pc = regs.pc = newpc; } STATIC_INLINE uaecptr m68k_getpci (void) { - return regs.pc; + return regs.pc; } STATIC_INLINE void m68k_incpci (int o) { - regs.pc += o; + regs.pc += o; } STATIC_INLINE void m68k_do_rts (void) { - m68k_setpc (get_long (m68k_areg (regs, 7))); - m68k_areg (regs, 7) += 4; + m68k_setpc (get_long (m68k_areg (regs, 7))); + m68k_areg (regs, 7) += 4; } STATIC_INLINE void m68k_do_rtsi (void) { - m68k_setpci (get_long (m68k_areg (regs, 7))); - m68k_areg (regs, 7) += 4; + m68k_setpci (get_long (m68k_areg (regs, 7))); + m68k_areg (regs, 7) += 4; } STATIC_INLINE void m68k_do_bsr (uaecptr oldpc, uae_s32 offset) { - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), oldpc); - m68k_incpc (offset); + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), oldpc); + m68k_incpc (offset); } STATIC_INLINE void m68k_do_bsri (uaecptr oldpc, uae_s32 offset) { - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), oldpc); - m68k_incpci (offset); + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), oldpc); + m68k_incpci (offset); } #define get_ibyte(o) do_get_mem_byte((uae_u8 *)((regs).pc_p + (o) + 1)) @@ -258,36 +260,36 @@ STATIC_INLINE void m68k_do_bsri (uaecptr oldpc, uae_s32 offset) #define get_ilongi(o) get_longi(o) /* These are only used by the 68020/68881 code, and therefore don't - * need to handle prefetch. */ +* need to handle prefetch. */ STATIC_INLINE uae_u32 next_ibyte (void) { - uae_u32 r = get_ibyte (0); - m68k_incpc (2); - return r; + uae_u32 r = get_ibyte (0); + m68k_incpc (2); + return r; } STATIC_INLINE uae_u32 next_iword (void) { - uae_u32 r = get_iword (0); - m68k_incpc (2); - return r; + uae_u32 r = get_iword (0); + m68k_incpc (2); + return r; } STATIC_INLINE uae_u32 next_iwordi (void) { - uae_u32 r = get_iwordi (m68k_getpci ()); - m68k_incpc (2); - return r; + uae_u32 r = get_iwordi (m68k_getpci ()); + m68k_incpc (2); + return r; } STATIC_INLINE uae_u32 next_ilong (void) { - uae_u32 r = get_ilong (0); - m68k_incpc (4); - return r; + uae_u32 r = get_ilong (0); + m68k_incpc (4); + return r; } STATIC_INLINE uae_u32 next_ilongi (void) { - uae_u32 r = get_ilongi (m68k_getpci ()); - m68k_incpc (4); - return r; + uae_u32 r = get_ilongi (m68k_getpci ()); + m68k_incpc (4); + return r; } extern void m68k_setstopped (void); @@ -393,7 +395,7 @@ extern int movec_illg (int regno); extern uae_u32 val_move2c (int regno); extern void val_move2c2 (int regno, uae_u32 val); struct cpum2c { - int regno; - TCHAR *regname; + int regno; + TCHAR *regname; }; extern struct cpum2c m2cregs[]; diff --git a/inputdevice.c b/inputdevice.c index 0f63cb2b..631e1b03 100644 --- a/inputdevice.c +++ b/inputdevice.c @@ -1,20 +1,20 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * joystick/mouse emulation - * - * Copyright 2001-2008 Toni Wilen - * - * new fetures: - * - very configurable (and very complex to configure :) - * - supports multiple native input devices (joysticks and mice) - * - supports mapping joystick/mouse buttons to keys and vice versa - * - joystick mouse emulation (supports both ports) - * - supports parallel port joystick adapter - * - full cd32 pad support (supports both ports) - * - fully backward compatible with old joystick/mouse configuration - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* joystick/mouse emulation +* +* Copyright 2001-2008 Toni Wilen +* +* new fetures: +* - very configurable (and very complex to configure :) +* - supports multiple native input devices (joysticks and mice) +* - supports mapping joystick/mouse buttons to keys and vice versa +* - joystick mouse emulation (supports both ports) +* - supports parallel port joystick adapter +* - full cd32 pad support (supports both ports) +* - fully backward compatible with old joystick/mouse configuration +* +*/ //#define DONGLE_DEBUG @@ -67,12 +67,12 @@ int inputdevice_logging = 0; #define IE_CDTV 0x100 struct inputevent { - const TCHAR *confname; - const TCHAR *name; - int allow_mask; - int type; - int unit; - int data; + const TCHAR *confname; + const TCHAR *name; + int allow_mask; + int type; + int unit; + int data; }; @@ -114,17 +114,17 @@ struct inputevent { #define DEFEVENT(A, B, C, D, E, F) {L#A, B, C, D, E, F }, struct inputevent events[] = { -{0, 0, AM_K,0,0,0}, + {0, 0, AM_K,0,0,0}, #include "inputevents.def" -{0, 0, 0, 0, 0, 0} + {0, 0, 0, 0, 0, 0} }; #undef DEFEVENT static int sublevdir[2][MAX_INPUT_SUB_EVENT]; struct uae_input_device2 { - uae_u32 buttonmask; - int states[MAX_INPUT_DEVICE_EVENTS / 2]; + uae_u32 buttonmask; + int states[MAX_INPUT_DEVICE_EVENTS / 2]; }; static struct uae_input_device2 joysticks2[MAX_INPUT_DEVICES]; @@ -145,248 +145,248 @@ static uae_u16 oldjoy[2]; int inprec_open (TCHAR *fname, int record) { - uae_u32 t = (uae_u32)time(0); - int i; + uae_u32 t = (uae_u32)time(0); + int i; - inprec_close(); - inprec_zf = zfile_fopen (fname, record > 0 ? L"wb" : L"rb", ZFD_NORMAL); - if (inprec_zf == NULL) - return 0; - inprec_size = 10000; - inprec_div = 1; - if (record < 0) { - uae_u32 id; - zfile_fseek (inprec_zf, 0, SEEK_END); - inprec_size = zfile_ftell (inprec_zf); - zfile_fseek (inprec_zf, 0, SEEK_SET); - inprec_buffer = inprec_p = xmalloc (inprec_size); - zfile_fread (inprec_buffer, inprec_size, 1, inprec_zf); - inprec_plastptr = inprec_buffer; - id = inprec_pu32(); - if (id != 'UAE\0') { - inprec_close (); - return 0; - } - inprec_pu32(); - t = inprec_pu32 (); - i = inprec_pu32 (); - while (i-- > 0) - inprec_pu8 (); - inprec_p = inprec_plastptr; - oldbuttons[0] = oldbuttons[1] = oldbuttons[2] = oldbuttons[3] = 0; - oldjoy[0] = oldjoy[1] = 0; - if (record < -1) - inprec_div = maxvpos; - } else if (record > 0) { - inprec_buffer = inprec_p = xmalloc (inprec_size); - inprec_ru32 ('UAE\0'); - inprec_ru8 (1); - inprec_ru8 (UAEMAJOR); - inprec_ru8 (UAEMINOR); - inprec_ru8 (UAESUBREV); - inprec_ru32 (t); - inprec_ru32 (0); // extra header size - } else { - return 0; - } - input_recording = record; - srand (t); - CIA_inprec_prepare (); - write_log (L"inprec initialized '%s', mode=%d\n", fname, input_recording); - return 1; + inprec_close(); + inprec_zf = zfile_fopen (fname, record > 0 ? L"wb" : L"rb", ZFD_NORMAL); + if (inprec_zf == NULL) + return 0; + inprec_size = 10000; + inprec_div = 1; + if (record < 0) { + uae_u32 id; + zfile_fseek (inprec_zf, 0, SEEK_END); + inprec_size = zfile_ftell (inprec_zf); + zfile_fseek (inprec_zf, 0, SEEK_SET); + inprec_buffer = inprec_p = xmalloc (inprec_size); + zfile_fread (inprec_buffer, inprec_size, 1, inprec_zf); + inprec_plastptr = inprec_buffer; + id = inprec_pu32(); + if (id != 'UAE\0') { + inprec_close (); + return 0; + } + inprec_pu32(); + t = inprec_pu32 (); + i = inprec_pu32 (); + while (i-- > 0) + inprec_pu8 (); + inprec_p = inprec_plastptr; + oldbuttons[0] = oldbuttons[1] = oldbuttons[2] = oldbuttons[3] = 0; + oldjoy[0] = oldjoy[1] = 0; + if (record < -1) + inprec_div = maxvpos; + } else if (record > 0) { + inprec_buffer = inprec_p = xmalloc (inprec_size); + inprec_ru32 ('UAE\0'); + inprec_ru8 (1); + inprec_ru8 (UAEMAJOR); + inprec_ru8 (UAEMINOR); + inprec_ru8 (UAESUBREV); + inprec_ru32 (t); + inprec_ru32 (0); // extra header size + } else { + return 0; + } + input_recording = record; + srand (t); + CIA_inprec_prepare (); + write_log (L"inprec initialized '%s', mode=%d\n", fname, input_recording); + return 1; } void inprec_close(void) { - if (!inprec_zf) - return; - if (inprec_buffer && input_recording > 0) { - hsync_counter++; - inprec_rstart(INPREC_END); - inprec_rend(); - hsync_counter--; - zfile_fwrite (inprec_buffer, inprec_p - inprec_buffer, 1, inprec_zf); - inprec_p = inprec_buffer; - } - zfile_fclose (inprec_zf); - inprec_zf = NULL; - xfree (inprec_buffer); - inprec_buffer = NULL; - input_recording = 0; - write_log (L"inprec finished\n"); + if (!inprec_zf) + return; + if (inprec_buffer && input_recording > 0) { + hsync_counter++; + inprec_rstart(INPREC_END); + inprec_rend(); + hsync_counter--; + zfile_fwrite (inprec_buffer, inprec_p - inprec_buffer, 1, inprec_zf); + inprec_p = inprec_buffer; + } + zfile_fclose (inprec_zf); + inprec_zf = NULL; + xfree (inprec_buffer); + inprec_buffer = NULL; + input_recording = 0; + write_log (L"inprec finished\n"); } void inprec_ru8(uae_u8 v) { - *inprec_p++= v; + *inprec_p++= v; } void inprec_ru16 (uae_u16 v) { - inprec_ru8 ((uae_u8)(v >> 8)); - inprec_ru8 ((uae_u8)v); + inprec_ru8 ((uae_u8)(v >> 8)); + inprec_ru8 ((uae_u8)v); } void inprec_ru32 (uae_u32 v) { - inprec_ru16 ((uae_u16)(v >> 16)); - inprec_ru16 ((uae_u16)v); + inprec_ru16 ((uae_u16)(v >> 16)); + inprec_ru16 ((uae_u16)v); } void inprec_rstr (const TCHAR *src) { - char *s = ua (src); - while(*s) { - inprec_ru8 (*s); - s++; - } - inprec_ru8 (0); - xfree (s); + char *s = ua (src); + while(*s) { + inprec_ru8 (*s); + s++; + } + inprec_ru8 (0); + xfree (s); } void inprec_rstart (uae_u8 type) { - write_log (L"INPREC: %08X: %d\n", hsync_counter, type); - inprec_ru32 (hsync_counter); - inprec_ru8 (0); - inprec_plast = inprec_p; - inprec_ru8 (0xff); - inprec_ru8 (type); + write_log (L"INPREC: %08X: %d\n", hsync_counter, type); + inprec_ru32 (hsync_counter); + inprec_ru8 (0); + inprec_plast = inprec_p; + inprec_ru8 (0xff); + inprec_ru8 (type); } void inprec_rend (void) { - *inprec_plast = inprec_p - (inprec_plast + 2); - if (inprec_p >= inprec_buffer + inprec_size - 256) { - zfile_fwrite (inprec_buffer, inprec_p - inprec_buffer, 1, inprec_zf); - inprec_p = inprec_buffer; - } + *inprec_plast = inprec_p - (inprec_plast + 2); + if (inprec_p >= inprec_buffer + inprec_size - 256) { + zfile_fwrite (inprec_buffer, inprec_p - inprec_buffer, 1, inprec_zf); + inprec_p = inprec_buffer; + } } int inprec_pstart (uae_u8 type) { - uae_u8 *p = inprec_p; - uae_u32 hc = hsync_counter; - static uae_u8 *lastp; - uae_u32 hc_orig, hc2_orig; + uae_u8 *p = inprec_p; + uae_u32 hc = hsync_counter; + static uae_u8 *lastp; + uae_u32 hc_orig, hc2_orig; - if (savestate_state) - return 0; - if (p[5 + 1] == INPREC_END) { - inprec_close (); + if (savestate_state) + return 0; + if (p[5 + 1] == INPREC_END) { + inprec_close (); + return 0; + } + hc_orig = hc; + hc /= inprec_div; + hc *= inprec_div; + for (;;) { + uae_u32 hc2 = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + if (p > lastp) { + write_log (L"INPREC: Next %08x (%08x=%d): %d (%d)\n", hc2, hc, hc2 - hc, p[5 + 1], p[5]); + lastp = p; + } + hc2_orig = hc2; + hc2 /= inprec_div; + hc2 *= inprec_div; + if (hc > hc2) { + write_log (L"INPREC: %08x > %08x: %d (%d) missed!\n", hc, hc2, p[5 + 1], p[5]); + inprec_close (); + return 0; + } + if (hc2 != hc) { + lastp = p; + break; + } + if (p[5 + 1] == type) { + write_log (L"INPREC: %08x: %d (%d) (%+d)\n", hc, type, p[5], hc_orig - hc2_orig); + inprec_plast = p; + inprec_plastptr = p + 5 + 2; + return 1; + } + p += 5 + 2 + p[5]; + } + inprec_plast = NULL; return 0; - } - hc_orig = hc; - hc /= inprec_div; - hc *= inprec_div; - for (;;) { - uae_u32 hc2 = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; - if (p > lastp) { - write_log (L"INPREC: Next %08x (%08x=%d): %d (%d)\n", hc2, hc, hc2 - hc, p[5 + 1], p[5]); - lastp = p; - } - hc2_orig = hc2; - hc2 /= inprec_div; - hc2 *= inprec_div; - if (hc > hc2) { - write_log (L"INPREC: %08x > %08x: %d (%d) missed!\n", hc, hc2, p[5 + 1], p[5]); - inprec_close (); - return 0; - } - if (hc2 != hc) { - lastp = p; - break; - } - if (p[5 + 1] == type) { - write_log (L"INPREC: %08x: %d (%d) (%+d)\n", hc, type, p[5], hc_orig - hc2_orig); - inprec_plast = p; - inprec_plastptr = p + 5 + 2; - return 1; - } - p += 5 + 2 + p[5]; - } - inprec_plast = NULL; - return 0; } void inprec_pend (void) { - uae_u8 *p = inprec_p; - uae_u32 hc = hsync_counter; - - if (!inprec_plast) - return; - inprec_plast[5 + 1] = 0; - inprec_plast = NULL; - inprec_plastptr = NULL; - hc /= inprec_div; - hc *= inprec_div; - for (;;) { - uae_u32 hc2 = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; - hc2 /= inprec_div; - hc2 *= inprec_div; - if (hc2 != hc) - break; - if (p[5 + 1] != 0) - return; - p += 5 + 2 + p[5]; - } - inprec_p = p; - if (p[5 + 1] == INPREC_END) - inprec_close (); + uae_u8 *p = inprec_p; + uae_u32 hc = hsync_counter; + + if (!inprec_plast) + return; + inprec_plast[5 + 1] = 0; + inprec_plast = NULL; + inprec_plastptr = NULL; + hc /= inprec_div; + hc *= inprec_div; + for (;;) { + uae_u32 hc2 = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + hc2 /= inprec_div; + hc2 *= inprec_div; + if (hc2 != hc) + break; + if (p[5 + 1] != 0) + return; + p += 5 + 2 + p[5]; + } + inprec_p = p; + if (p[5 + 1] == INPREC_END) + inprec_close (); } uae_u8 inprec_pu8 (void) { - return *inprec_plastptr++; + return *inprec_plastptr++; } uae_u16 inprec_pu16 (void) { - uae_u16 v = inprec_pu8 () << 8; - v |= inprec_pu8 (); - return v; + uae_u16 v = inprec_pu8 () << 8; + v |= inprec_pu8 (); + return v; } uae_u32 inprec_pu32 (void) { - uae_u32 v = inprec_pu16 () << 16; - v |= inprec_pu16 (); - return v; + uae_u32 v = inprec_pu16 () << 16; + v |= inprec_pu16 (); + return v; } int inprec_pstr (TCHAR *dst) { - char tmp[MAX_DPATH]; - char *s; - int len = 0; + char tmp[MAX_DPATH]; + char *s; + int len = 0; - s = tmp; - for(;;) { - uae_u8 v = inprec_pu8 (); - *s++ = v; - if (!v) - break; - len++; - } - au_copy (dst, MAX_DPATH, tmp); - return len; + s = tmp; + for(;;) { + uae_u8 v = inprec_pu8 (); + *s++ = v; + if (!v) + break; + len++; + } + au_copy (dst, MAX_DPATH, tmp); + return len; } static int isdevice (struct uae_input_device *id) { - int i, j; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - if (id->eventid[i][j] > 0) - return 1; + int i, j; + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + if (id->eventid[i][j] > 0) + return 1; + } } - } - return 0; + return 0; } int inputdevice_uaelib (TCHAR *s, TCHAR *parm) { - int i; + int i; - for (i = 1; events[i].name; i++) { - if (!_tcscmp (s, events[i].confname)) { - handle_input_event (i, _tstol (parm), 1, 0); - return 1; + for (i = 1; events[i].name; i++) { + if (!_tcscmp (s, events[i].confname)) { + handle_input_event (i, _tstol (parm), 1, 0); + return 1; + } } - } - return 0; + return 0; } static struct uae_input_device *joysticks; @@ -427,244 +427,244 @@ static int use_keyboards[MAX_INPUT_DEVICES]; #define INPUT_QUEUE_SIZE 16 struct input_queue_struct { - int event, storedstate, state, max, framecnt, nextframecnt; + int event, storedstate, state, max, framecnt, nextframecnt; }; static struct input_queue_struct input_queue[INPUT_QUEUE_SIZE]; static void freejport (struct uae_prefs *dst, int num) { - memset (&dst->jports[num], 0, sizeof (struct jport)); - dst->jports[num].id = -1; + memset (&dst->jports[num], 0, sizeof (struct jport)); + dst->jports[num].id = -1; } static void copyjport (const struct uae_prefs *src, struct uae_prefs *dst, int num) { - freejport (dst, num); - _tcscpy (dst->jports[num].configname, src->jports[num].configname); - _tcscpy (dst->jports[num].name, src->jports[num].name); - dst->jports[num].id = src->jports[num].id; - dst->jports[num].mode = src->jports[num].mode; + freejport (dst, num); + _tcscpy (dst->jports[num].configname, src->jports[num].configname); + _tcscpy (dst->jports[num].name, src->jports[num].name); + dst->jports[num].id = src->jports[num].id; + dst->jports[num].mode = src->jports[num].mode; } static void out_config (struct zfile *f, int id, int num, TCHAR *s1, TCHAR *s2) { - TCHAR tmp[MAX_DPATH]; - _stprintf (tmp, L"input.%d.%s%d", id, s1, num); - cfgfile_write_str (f, tmp, s2); + TCHAR tmp[MAX_DPATH]; + _stprintf (tmp, L"input.%d.%s%d", id, s1, num); + cfgfile_write_str (f, tmp, s2); } static void write_config2 (struct zfile *f, int idnum, int i, int offset, TCHAR *tmp1, struct uae_input_device *id) { - TCHAR tmp2[200], tmp3[200], *p; - int evt, got, j, k; - TCHAR *custom; - - p = tmp2; - got = 0; - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - evt = id->eventid[i + offset][j]; - custom = id->custom[i + offset][j]; - if (custom == NULL && evt <= 0) { - for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) { - if (id->eventid[i + offset][k] > 0 || id->custom[i + offset][k] != NULL) - break; - } - if (k == MAX_INPUT_SUB_EVENT) - break; + TCHAR tmp2[200], tmp3[200], *p; + int evt, got, j, k; + TCHAR *custom; + + p = tmp2; + got = 0; + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + evt = id->eventid[i + offset][j]; + custom = id->custom[i + offset][j]; + if (custom == NULL && evt <= 0) { + for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) { + if (id->eventid[i + offset][k] > 0 || id->custom[i + offset][k] != NULL) + break; + } + if (k == MAX_INPUT_SUB_EVENT) + break; + } + if (p > tmp2) { + *p++ = ','; + *p = 0; + } + if (custom && _tcslen (custom) > 0) + _stprintf (p, L"'%s'.%d", custom, id->flags[i + offset][j] & ID_FLAG_SAVE_MASK); + else if (evt <= 0) + _stprintf (p, L"NULL"); + else + _stprintf (p, L"%s.%d", events[evt].confname, id->flags[i + offset][j]); + p += _tcslen (p); } if (p > tmp2) { - *p++ = ','; - *p = 0; + _stprintf (tmp3, L"input.%d.%s%d", idnum, tmp1, i); + cfgfile_write_str (f, tmp3, tmp2); } - if (custom && _tcslen (custom) > 0) - _stprintf (p, L"'%s'.%d", custom, id->flags[i + offset][j] & ID_FLAG_SAVE_MASK); - else if (evt <= 0) - _stprintf (p, L"NULL"); - else - _stprintf (p, L"%s.%d", events[evt].confname, id->flags[i + offset][j]); - p += _tcslen (p); - } - if (p > tmp2) { - _stprintf (tmp3, L"input.%d.%s%d", idnum, tmp1, i); - cfgfile_write_str (f, tmp3, tmp2); - } } static struct inputdevice_functions *getidf (int devnum); static void write_config (struct zfile *f, int idnum, int devnum, TCHAR *name, struct uae_input_device *id, struct uae_input_device2 *id2, struct inputdevice_functions *idf) { - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH], *s; - int i; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH], *s; + int i; + + if (!isdevice (id)) { + _stprintf (tmp2, L"input.%d.%s.%d.empty", idnum, name, devnum); + cfgfile_write_bool (f, tmp2, 1); + if (id->enabled) { + _stprintf (tmp2, L"input.%d.%s.%d.disabled", idnum, name, devnum); + cfgfile_write (f, tmp2, L"%d", id->enabled ? 0 : 1); + } + return; + } - if (!isdevice (id)) { _stprintf (tmp2, L"input.%d.%s.%d.empty", idnum, name, devnum); - cfgfile_write_bool (f, tmp2, 1); - if (id->enabled) { - _stprintf (tmp2, L"input.%d.%s.%d.disabled", idnum, name, devnum); - cfgfile_write (f, tmp2, L"%d", id->enabled ? 0 : 1); - } - return; - } - - _stprintf (tmp2, L"input.%d.%s.%d.empty", idnum, name, devnum); - cfgfile_write_bool (f, tmp2, 0); - _stprintf (tmp2, L"input.%d.%s.%d.disabled", idnum, name, devnum); - cfgfile_write (f, tmp2, L"%d", id->enabled ? 0 : 1); - - s = NULL; - if (id->name) - s = id->name; - else if (devnum < idf->get_num ()) - s = idf->get_friendlyname (devnum); - if (s) { - _stprintf (tmp2, L"input.%d.%s.%d.friendlyname", idnum, name, devnum); - cfgfile_write_str (f, tmp2, s); - } - - s = NULL; - if (id->configname) - s = id->configname; - else if (devnum < idf->get_num ()) - s = idf->get_uniquename (devnum); - if (s) { - _stprintf (tmp2, L"input.%d.%s.%d.name", idnum, name, devnum); - cfgfile_write_str (f, tmp2, s); - } - - _stprintf (tmp1, L"%s.%d.axis.", name, devnum); - for (i = 0; i < ID_AXIS_TOTAL; i++) - write_config2 (f, idnum, i, ID_AXIS_OFFSET, tmp1, id); - _stprintf (tmp1, L"%s.%d.button." ,name, devnum); - for (i = 0; i < ID_BUTTON_TOTAL; i++) - write_config2 (f, idnum, i, ID_BUTTON_OFFSET, tmp1, id); + cfgfile_write_bool (f, tmp2, 0); + _stprintf (tmp2, L"input.%d.%s.%d.disabled", idnum, name, devnum); + cfgfile_write (f, tmp2, L"%d", id->enabled ? 0 : 1); + + s = NULL; + if (id->name) + s = id->name; + else if (devnum < idf->get_num ()) + s = idf->get_friendlyname (devnum); + if (s) { + _stprintf (tmp2, L"input.%d.%s.%d.friendlyname", idnum, name, devnum); + cfgfile_write_str (f, tmp2, s); + } + + s = NULL; + if (id->configname) + s = id->configname; + else if (devnum < idf->get_num ()) + s = idf->get_uniquename (devnum); + if (s) { + _stprintf (tmp2, L"input.%d.%s.%d.name", idnum, name, devnum); + cfgfile_write_str (f, tmp2, s); + } + + _stprintf (tmp1, L"%s.%d.axis.", name, devnum); + for (i = 0; i < ID_AXIS_TOTAL; i++) + write_config2 (f, idnum, i, ID_AXIS_OFFSET, tmp1, id); + _stprintf (tmp1, L"%s.%d.button." ,name, devnum); + for (i = 0; i < ID_BUTTON_TOTAL; i++) + write_config2 (f, idnum, i, ID_BUTTON_OFFSET, tmp1, id); } static void kbrlabel (TCHAR *s) { - while (*s) { - *s = _totupper (*s); - if (*s == ' ') - *s = '_'; - s++; - } + while (*s) { + *s = _totupper (*s); + if (*s == ' ') + *s = '_'; + s++; + } } static void write_kbr_config (struct zfile *f, int idnum, int devnum, struct uae_input_device *kbr, struct inputdevice_functions *idf) { - TCHAR tmp1[200], tmp2[200], tmp3[200], tmp4[200], *p; - int i, j, k, evt, skip; - - if (!keyboard_default) - return; - i = 0; - while (i < MAX_INPUT_DEVICE_EVENTS && kbr->extra[i][0] >= 0) { - skip = 0; - k = 0; - while (keyboard_default[k].scancode >= 0) { - if (keyboard_default[k].scancode == kbr->extra[i][0]) { - skip = 1; - for (j = 1; j < MAX_INPUT_SUB_EVENT; j++) { - if (kbr->flags[i][j] || kbr->eventid[i][j] > 0) - skip = 0; + TCHAR tmp1[200], tmp2[200], tmp3[200], tmp4[200], *p; + int i, j, k, evt, skip; + + if (!keyboard_default) + return; + i = 0; + while (i < MAX_INPUT_DEVICE_EVENTS && kbr->extra[i][0] >= 0) { + skip = 0; + k = 0; + while (keyboard_default[k].scancode >= 0) { + if (keyboard_default[k].scancode == kbr->extra[i][0]) { + skip = 1; + for (j = 1; j < MAX_INPUT_SUB_EVENT; j++) { + if (kbr->flags[i][j] || kbr->eventid[i][j] > 0) + skip = 0; + } + if (keyboard_default[k].event != kbr->eventid[i][0] || kbr->flags[i][0] != 0) + skip = 0; + break; + } + k++; } - if (keyboard_default[k].event != kbr->eventid[i][0] || kbr->flags[i][0] != 0) - skip = 0; - break; - } - k++; - } - if (kbr->eventid[i][0] == 0 && kbr->flags[i][0] == 0 && keyboard_default[k].scancode < 0) - skip = 1; - if (skip) { - i++; - continue; - } - p = tmp2; - p[0] = 0; - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - TCHAR *custom = kbr->custom[i][j]; - evt = kbr->eventid[i][j]; - if (custom == NULL && evt <= 0) { - for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) { - if (kbr->eventid[i][k] > 0 || kbr->custom[i][k] != NULL) - break; + if (kbr->eventid[i][0] == 0 && kbr->flags[i][0] == 0 && keyboard_default[k].scancode < 0) + skip = 1; + if (skip) { + i++; + continue; + } + p = tmp2; + p[0] = 0; + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + TCHAR *custom = kbr->custom[i][j]; + evt = kbr->eventid[i][j]; + if (custom == NULL && evt <= 0) { + for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) { + if (kbr->eventid[i][k] > 0 || kbr->custom[i][k] != NULL) + break; + } + if (k == MAX_INPUT_SUB_EVENT) + break; + } + if (p > tmp2) { + *p++ = ','; + *p = 0; + } + if (custom && _tcslen (custom) > 0) + _stprintf (p, L"'%s'.%d", custom, kbr->flags[i][j] & 0xff); + else if (evt > 0) + _stprintf (p, L"%s.%d", events[evt].confname, kbr->flags[i][j]); + else + _tcscat (p, L"NULL"); + p += _tcslen(p); } - if (k == MAX_INPUT_SUB_EVENT) - break; - } - if (p > tmp2) { - *p++ = ','; - *p = 0; - } - if (custom && _tcslen (custom) > 0) - _stprintf (p, L"'%s'.%d", custom, kbr->flags[i][j] & 0xff); - else if (evt > 0) - _stprintf (p, L"%s.%d", events[evt].confname, kbr->flags[i][j]); - else - _tcscat (p, L"NULL"); - p += _tcslen(p); - } - _stprintf (tmp3, L"%d", kbr->extra[i][0]); - kbrlabel (tmp3); - _stprintf (tmp1, L"keyboard.%d.button.%s", devnum, tmp3); - _stprintf (tmp4, L"input.%d.%s", idnum, tmp1); - cfgfile_write_str (f, tmp4, tmp2[0] ? tmp2 : L"NULL"); - i++; - } + _stprintf (tmp3, L"%d", kbr->extra[i][0]); + kbrlabel (tmp3); + _stprintf (tmp1, L"keyboard.%d.button.%s", devnum, tmp3); + _stprintf (tmp4, L"input.%d.%s", idnum, tmp1); + cfgfile_write_str (f, tmp4, tmp2[0] ? tmp2 : L"NULL"); + i++; + } } void write_inputdevice_config (struct uae_prefs *p, struct zfile *f) { - int i, id; - - cfgfile_write (f, L"input.config", L"%d", p->input_selected_setting); - cfgfile_write (f, L"input.joymouse_speed_analog", L"%d", p->input_joymouse_multiplier); - cfgfile_write (f, L"input.joymouse_speed_digital", L"%d", p->input_joymouse_speed); - cfgfile_write (f, L"input.joymouse_deadzone", L"%d", p->input_joymouse_deadzone); - cfgfile_write (f, L"input.joystick_deadzone", L"%d", p->input_joystick_deadzone); - cfgfile_write (f, L"input.analog_joystick_multiplier", L"%d", p->input_analog_joystick_mult); - cfgfile_write (f, L"input.analog_joystick_offset", L"%d", p->input_analog_joystick_offset); - cfgfile_write (f, L"input.mouse_speed", L"%d", p->input_mouse_speed); - cfgfile_write (f, L"input.autofire", L"%d", p->input_autofire_framecnt); - for (id = 1; id <= MAX_INPUT_SETTINGS; id++) { - for (i = 0; i < MAX_INPUT_DEVICES; i++) - write_config (f, id, i, L"joystick", &p->joystick_settings[id][i], &joysticks2[i], &idev[IDTYPE_JOYSTICK]); - for (i = 0; i < MAX_INPUT_DEVICES; i++) - write_config (f, id, i, L"mouse", &p->mouse_settings[id][i], &mice2[i], &idev[IDTYPE_MOUSE]); - for (i = 0; i < MAX_INPUT_DEVICES; i++) - write_kbr_config (f, id, i, &p->keyboard_settings[id][i], &idev[IDTYPE_KEYBOARD]); - } + int i, id; + + cfgfile_write (f, L"input.config", L"%d", p->input_selected_setting); + cfgfile_write (f, L"input.joymouse_speed_analog", L"%d", p->input_joymouse_multiplier); + cfgfile_write (f, L"input.joymouse_speed_digital", L"%d", p->input_joymouse_speed); + cfgfile_write (f, L"input.joymouse_deadzone", L"%d", p->input_joymouse_deadzone); + cfgfile_write (f, L"input.joystick_deadzone", L"%d", p->input_joystick_deadzone); + cfgfile_write (f, L"input.analog_joystick_multiplier", L"%d", p->input_analog_joystick_mult); + cfgfile_write (f, L"input.analog_joystick_offset", L"%d", p->input_analog_joystick_offset); + cfgfile_write (f, L"input.mouse_speed", L"%d", p->input_mouse_speed); + cfgfile_write (f, L"input.autofire", L"%d", p->input_autofire_framecnt); + for (id = 1; id <= MAX_INPUT_SETTINGS; id++) { + for (i = 0; i < MAX_INPUT_DEVICES; i++) + write_config (f, id, i, L"joystick", &p->joystick_settings[id][i], &joysticks2[i], &idev[IDTYPE_JOYSTICK]); + for (i = 0; i < MAX_INPUT_DEVICES; i++) + write_config (f, id, i, L"mouse", &p->mouse_settings[id][i], &mice2[i], &idev[IDTYPE_MOUSE]); + for (i = 0; i < MAX_INPUT_DEVICES; i++) + write_kbr_config (f, id, i, &p->keyboard_settings[id][i], &idev[IDTYPE_KEYBOARD]); + } } static int getnum (const TCHAR **pp) { - const TCHAR *p = *pp; - int v = _tstol (p); + const TCHAR *p = *pp; + int v = _tstol (p); - while (*p != 0 && *p !='.' && *p != ',') - p++; - if (*p == '.' || *p == ',') - p++; - *pp = p; - return v; + while (*p != 0 && *p !='.' && *p != ',') + p++; + if (*p == '.' || *p == ',') + p++; + *pp = p; + return v; } static TCHAR *getstring (const TCHAR **pp) { - int i; - static TCHAR str[1000]; - const TCHAR *p = *pp; + int i; + static TCHAR str[1000]; + const TCHAR *p = *pp; - if (*p == 0) - return 0; - i = 0; - while (*p != 0 && *p !='.' && *p != ',') - str[i++] = *p++; - if (*p == '.' || *p == ',') - p++; - str[i] = 0; - *pp = p; - return str; + if (*p == 0) + return 0; + i = 0; + while (*p != 0 && *p !='.' && *p != ',') + str[i++] = *p++; + if (*p == '.' || *p == ',') + p++; + str[i] = 0; + *pp = p; + return str; } void reset_inputdevice_config (struct uae_prefs *pr) @@ -674,199 +674,199 @@ void reset_inputdevice_config (struct uae_prefs *pr) static void clear_id (struct uae_input_device *id) { #ifndef _DEBUG - int i, j; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) - xfree (id->custom[i][j]); - } + int i, j; + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) + xfree (id->custom[i][j]); + } #endif - xfree (id->configname); - xfree (id->name); - memset (id, 0, sizeof (struct uae_input_device)); + xfree (id->configname); + xfree (id->name); + memset (id, 0, sizeof (struct uae_input_device)); } void read_inputdevice_config (struct uae_prefs *pr, TCHAR *option, TCHAR *value) { - struct uae_input_device *id = 0; - struct inputevent *ie; - int devnum, num, button, joystick, flags, i, subnum, idnum, keynum; - int mask; - TCHAR *p, *p2, *custom; - - option += 6; /* "input." */ - p = getstring (&option); - if (!strcasecmp (p, L"config")) - pr->input_selected_setting = _tstol (value); - if (!strcasecmp (p, L"joymouse_speed_analog")) - pr->input_joymouse_multiplier = _tstol (value); - if (!strcasecmp (p, L"joymouse_speed_digital")) - pr->input_joymouse_speed = _tstol (value); - if (!strcasecmp (p, L"joystick_deadzone")) - pr->input_joystick_deadzone = _tstol (value); - if (!strcasecmp (p, L"joymouse_deadzone")) - pr->input_joymouse_deadzone = _tstol (value); - if (!strcasecmp (p, L"mouse_speed")) - pr->input_mouse_speed = _tstol (value); - if (!strcasecmp (p, L"autofire")) - pr->input_autofire_framecnt = _tstol (value); - if (!strcasecmp (p, L"analog_joystick_multiplier")) - pr->input_analog_joystick_mult = _tstol (value); - if (!strcasecmp (p, L"analog_joystick_offset")) - pr->input_analog_joystick_offset = _tstol (value); - - idnum = _tstol (p); - if (idnum <= 0 || idnum > MAX_INPUT_SETTINGS) - return; - - if (_tcsncmp (option, L"mouse.", 6) == 0) { - p = option + 6; - } else if (_tcsncmp (option, L"joystick.", 9) == 0) { - p = option + 9; - } else if (_tcsncmp (option, L"keyboard.", 9) == 0) { - p = option + 9; - } else - return; - - devnum = getnum (&p); - if (devnum < 0 || devnum >= MAX_INPUT_DEVICES) - return; - - p2 = getstring (&p); - if (!p2) - return; - - if (_tcsncmp (option, L"mouse.", 6) == 0) { - id = &pr->mouse_settings[idnum][devnum]; - joystick = 0; - } else if (_tcsncmp (option, L"joystick.", 9) == 0) { - id = &pr->joystick_settings[idnum][devnum]; - joystick = 1; - } else if (_tcsncmp (option, L"keyboard.", 9) == 0) { - id = &pr->keyboard_settings[idnum][devnum]; - joystick = -1; - } - if (!id) - return; - - if (!_tcscmp (p2, L"name")) { - xfree (id->configname); - id->configname = my_strdup (value); - return; - } - if (!_tcscmp (p2, L"friendlyname")) { - xfree (id->name); - id->name = my_strdup (value); - return; - } - - if (!_tcscmp (p2, L"empty")) { - clear_id (id); - id->enabled = 1; - return; - } - - if (!_tcscmp (p2, L"disabled")) { - int disabled; - p = value; - disabled = getnum (&p); - id->enabled = disabled == 0 ? 1 : 0; - return; - } - - if (joystick < 0) { - num = getnum (&p); - keynum = 0; - while (id->extra[keynum][0] >= 0) { - if (id->extra[keynum][0] == num) - break; - keynum++; - } - if (id->extra[keynum][0] < 0) - return; - } else { - button = -1; - if (!_tcscmp (p2, L"axis")) - button = 0; - else if(!_tcscmp (p2, L"button")) - button = 1; - if (button < 0) - return; - num = getnum (&p); - } - p = value; - - custom = NULL; - for (subnum = 0; subnum < MAX_INPUT_SUB_EVENT; subnum++) { - xfree (custom); - custom = NULL; + struct uae_input_device *id = 0; + struct inputevent *ie; + int devnum, num, button, joystick, flags, i, subnum, idnum, keynum; + int mask; + TCHAR *p, *p2, *custom; + + option += 6; /* "input." */ + p = getstring (&option); + if (!strcasecmp (p, L"config")) + pr->input_selected_setting = _tstol (value); + if (!strcasecmp (p, L"joymouse_speed_analog")) + pr->input_joymouse_multiplier = _tstol (value); + if (!strcasecmp (p, L"joymouse_speed_digital")) + pr->input_joymouse_speed = _tstol (value); + if (!strcasecmp (p, L"joystick_deadzone")) + pr->input_joystick_deadzone = _tstol (value); + if (!strcasecmp (p, L"joymouse_deadzone")) + pr->input_joymouse_deadzone = _tstol (value); + if (!strcasecmp (p, L"mouse_speed")) + pr->input_mouse_speed = _tstol (value); + if (!strcasecmp (p, L"autofire")) + pr->input_autofire_framecnt = _tstol (value); + if (!strcasecmp (p, L"analog_joystick_multiplier")) + pr->input_analog_joystick_mult = _tstol (value); + if (!strcasecmp (p, L"analog_joystick_offset")) + pr->input_analog_joystick_offset = _tstol (value); + + idnum = _tstol (p); + if (idnum <= 0 || idnum > MAX_INPUT_SETTINGS) + return; + + if (_tcsncmp (option, L"mouse.", 6) == 0) { + p = option + 6; + } else if (_tcsncmp (option, L"joystick.", 9) == 0) { + p = option + 9; + } else if (_tcsncmp (option, L"keyboard.", 9) == 0) { + p = option + 9; + } else + return; + + devnum = getnum (&p); + if (devnum < 0 || devnum >= MAX_INPUT_DEVICES) + return; + p2 = getstring (&p); if (!p2) - break; - i = 1; - while (events[i].name) { - if (!_tcscmp (events[i].confname, p2)) - break; - i++; - } - ie = &events[i]; - if (!ie->name) { - ie = &events[0]; - if (_tcslen (p2) > 2 && p2[0] == '\'' && p2[_tcslen (p2) - 1] == '\'') { - custom = my_strdup (p2 + 1); - custom[_tcslen (custom) - 1] = 0; - } - } - flags = 0; - if (p[-1] == '.') - flags = getnum (&p); - if (custom == NULL && ie->name == NULL) { - if (!_tcscmp(p2, L"NULL")) { - if (joystick < 0) { - id->eventid[keynum][subnum] = 0; - id->flags[keynum][subnum] = 0; - } else if (button) { - id->eventid[num + ID_BUTTON_OFFSET][subnum] = 0; - id->flags[num + ID_BUTTON_OFFSET][subnum] = 0; - } else { - id->eventid[num + ID_AXIS_OFFSET][subnum] = 0; - id->flags[num + ID_AXIS_OFFSET][subnum] = 0; - } - } - continue; + return; + + if (_tcsncmp (option, L"mouse.", 6) == 0) { + id = &pr->mouse_settings[idnum][devnum]; + joystick = 0; + } else if (_tcsncmp (option, L"joystick.", 9) == 0) { + id = &pr->joystick_settings[idnum][devnum]; + joystick = 1; + } else if (_tcsncmp (option, L"keyboard.", 9) == 0) { + id = &pr->keyboard_settings[idnum][devnum]; + joystick = -1; } + if (!id) + return; + + if (!_tcscmp (p2, L"name")) { + xfree (id->configname); + id->configname = my_strdup (value); + return; + } + if (!_tcscmp (p2, L"friendlyname")) { + xfree (id->name); + id->name = my_strdup (value); + return; + } + + if (!_tcscmp (p2, L"empty")) { + clear_id (id); + id->enabled = 1; + return; + } + + if (!_tcscmp (p2, L"disabled")) { + int disabled; + p = value; + disabled = getnum (&p); + id->enabled = disabled == 0 ? 1 : 0; + return; + } + if (joystick < 0) { - if (!(ie->allow_mask & AM_K)) - continue; - id->eventid[keynum][subnum] = ie - events; - id->flags[keynum][subnum] = flags; - xfree (id->custom[keynum][subnum]); - id->custom[keynum][subnum] = custom; - } else if (button) { - if (joystick) - mask = AM_JOY_BUT; - else - mask = AM_MOUSE_BUT; - if (!(ie->allow_mask & mask)) - continue; - id->eventid[num + ID_BUTTON_OFFSET][subnum] = ie - events; - id->flags[num + ID_BUTTON_OFFSET][subnum] = flags; - xfree (id->custom[num + ID_BUTTON_OFFSET][subnum]); - id->custom[num + ID_BUTTON_OFFSET][subnum] = custom; + num = getnum (&p); + keynum = 0; + while (id->extra[keynum][0] >= 0) { + if (id->extra[keynum][0] == num) + break; + keynum++; + } + if (id->extra[keynum][0] < 0) + return; } else { - if (joystick) - mask = AM_JOY_AXIS; - else - mask = AM_MOUSE_AXIS; - if (!(ie->allow_mask & mask)) - continue; - id->eventid[num + ID_AXIS_OFFSET][subnum] = ie - events; - id->flags[num + ID_AXIS_OFFSET][subnum] = flags; - xfree (id->custom[num + ID_AXIS_OFFSET][subnum]); - id->custom[num + ID_AXIS_OFFSET][subnum] = custom; + button = -1; + if (!_tcscmp (p2, L"axis")) + button = 0; + else if(!_tcscmp (p2, L"button")) + button = 1; + if (button < 0) + return; + num = getnum (&p); } + p = value; + custom = NULL; - } - xfree (custom); + for (subnum = 0; subnum < MAX_INPUT_SUB_EVENT; subnum++) { + xfree (custom); + custom = NULL; + p2 = getstring (&p); + if (!p2) + break; + i = 1; + while (events[i].name) { + if (!_tcscmp (events[i].confname, p2)) + break; + i++; + } + ie = &events[i]; + if (!ie->name) { + ie = &events[0]; + if (_tcslen (p2) > 2 && p2[0] == '\'' && p2[_tcslen (p2) - 1] == '\'') { + custom = my_strdup (p2 + 1); + custom[_tcslen (custom) - 1] = 0; + } + } + flags = 0; + if (p[-1] == '.') + flags = getnum (&p); + if (custom == NULL && ie->name == NULL) { + if (!_tcscmp(p2, L"NULL")) { + if (joystick < 0) { + id->eventid[keynum][subnum] = 0; + id->flags[keynum][subnum] = 0; + } else if (button) { + id->eventid[num + ID_BUTTON_OFFSET][subnum] = 0; + id->flags[num + ID_BUTTON_OFFSET][subnum] = 0; + } else { + id->eventid[num + ID_AXIS_OFFSET][subnum] = 0; + id->flags[num + ID_AXIS_OFFSET][subnum] = 0; + } + } + continue; + } + if (joystick < 0) { + if (!(ie->allow_mask & AM_K)) + continue; + id->eventid[keynum][subnum] = ie - events; + id->flags[keynum][subnum] = flags; + xfree (id->custom[keynum][subnum]); + id->custom[keynum][subnum] = custom; + } else if (button) { + if (joystick) + mask = AM_JOY_BUT; + else + mask = AM_MOUSE_BUT; + if (!(ie->allow_mask & mask)) + continue; + id->eventid[num + ID_BUTTON_OFFSET][subnum] = ie - events; + id->flags[num + ID_BUTTON_OFFSET][subnum] = flags; + xfree (id->custom[num + ID_BUTTON_OFFSET][subnum]); + id->custom[num + ID_BUTTON_OFFSET][subnum] = custom; + } else { + if (joystick) + mask = AM_JOY_AXIS; + else + mask = AM_MOUSE_AXIS; + if (!(ie->allow_mask & mask)) + continue; + id->eventid[num + ID_AXIS_OFFSET][subnum] = ie - events; + id->flags[num + ID_AXIS_OFFSET][subnum] = flags; + xfree (id->custom[num + ID_AXIS_OFFSET][subnum]); + id->custom[num + ID_AXIS_OFFSET][subnum] = custom; + } + custom = NULL; + } + xfree (custom); } static int mouseedge_alive, mousehack_alive_cnt; @@ -878,64 +878,64 @@ static int tablet_maxx, tablet_maxy, tablet_data; int mousehack_alive (void) { - return mousehack_alive_cnt > 0 ? mousehack_alive_cnt : 0; + return mousehack_alive_cnt > 0 ? mousehack_alive_cnt : 0; } static uaecptr get_base (const uae_char *name) { - uaecptr v = get_long (4); - addrbank *b = &get_mem_bank(v); + uaecptr v = get_long (4); + addrbank *b = &get_mem_bank(v); - if (!b || !b->check (v, 400) || b->flags != ABFLAG_RAM) + if (!b || !b->check (v, 400) || b->flags != ABFLAG_RAM) + return 0; + v += 378; // liblist + while (v = get_long (v)) { + uae_u32 v2; + uae_u8 *p; + b = &get_mem_bank (v); + if (!b || !b->check (v, 32) || b->flags != ABFLAG_RAM) + goto fail; + v2 = get_long (v + 10); // name + b = &get_mem_bank (v2); + if (!b || !b->check (v2, 20)) + goto fail; + if (b->flags != ABFLAG_ROM && b->flags != ABFLAG_RAM) + return 0; + p = b->xlateaddr (v2); + if (!memcmp (p, name, strlen (name) + 1)) { + TCHAR *s = au (name); + write_log (L"get_base('%s')=%08x\n", s, v); + xfree (s); + return v; + } + } return 0; - v += 378; // liblist - while (v = get_long (v)) { - uae_u32 v2; - uae_u8 *p; - b = &get_mem_bank (v); - if (!b || !b->check (v, 32) || b->flags != ABFLAG_RAM) - goto fail; - v2 = get_long (v + 10); // name - b = &get_mem_bank (v2); - if (!b || !b->check (v2, 20)) - goto fail; - if (b->flags != ABFLAG_ROM && b->flags != ABFLAG_RAM) - return 0; - p = b->xlateaddr (v2); - if (!memcmp (p, name, strlen (name) + 1)) { - TCHAR *s = au (name); - write_log (L"get_base('%s')=%08x\n", s, v); - xfree (s); - return v; - } - } - return 0; fail: - { - TCHAR *s = au (name); - write_log (L"get_base('%s') failed, invalid library list\n", s); - xfree (s); - } - return 0xffffffff; + { + TCHAR *s = au (name); + write_log (L"get_base('%s') failed, invalid library list\n", s); + xfree (s); + } + return 0xffffffff; } static uaecptr get_intuitionbase (void) { - if (magicmouse_ibase == 0xffffffff) - return 0; - if (magicmouse_ibase) + if (magicmouse_ibase == 0xffffffff) + return 0; + if (magicmouse_ibase) + return magicmouse_ibase; + magicmouse_ibase = get_base ("intuition.library"); return magicmouse_ibase; - magicmouse_ibase = get_base ("intuition.library"); - return magicmouse_ibase; } static uaecptr get_gfxbase (void) { - if (magicmouse_gfxbase == 0xffffffff) - return 0; - if (magicmouse_gfxbase) + if (magicmouse_gfxbase == 0xffffffff) + return 0; + if (magicmouse_gfxbase) + return magicmouse_gfxbase; + magicmouse_gfxbase = get_base ("graphics.library"); return magicmouse_gfxbase; - magicmouse_gfxbase = get_base ("graphics.library"); - return magicmouse_gfxbase; } #define MH_E 0 @@ -965,246 +965,246 @@ static uaecptr get_gfxbase (void) int inputdevice_is_tablet (void) { - int v; - if (!uae_boot_rom) - return 0; - if (currprefs.input_tablet == TABLET_OFF) - return 0; - if (currprefs.input_tablet == TABLET_MOUSEHACK) - return -1; - v = is_tablet (); - if (!v) - return 0; - if (kickstart_version < 37) - return v ? -1 : 0; - return v ? 1 : 0; + int v; + if (!uae_boot_rom) + return 0; + if (currprefs.input_tablet == TABLET_OFF) + return 0; + if (currprefs.input_tablet == TABLET_MOUSEHACK) + return -1; + v = is_tablet (); + if (!v) + return 0; + if (kickstart_version < 37) + return v ? -1 : 0; + return v ? 1 : 0; } static int getmhoffset (void) { - if (!uae_boot_rom) - return 0; - return get_long (rtarea_base + bootrom_header + 7 * 4) + bootrom_header; + if (!uae_boot_rom) + return 0; + return get_long (rtarea_base + bootrom_header + 7 * 4) + bootrom_header; } static void mousehack_reset (void) { - int off; + int off; - dimensioninfo_width = dimensioninfo_height = 0; - mouseoffset_x = mouseoffset_y = 0; - dimensioninfo_dbl = 0; - mousehack_alive_cnt = 0; - vp_xoffset = vp_yoffset = 0; - tablet_data = 0; - off = getmhoffset (); - if (off) - rtarea[off + MH_E] = 0; + dimensioninfo_width = dimensioninfo_height = 0; + mouseoffset_x = mouseoffset_y = 0; + dimensioninfo_dbl = 0; + mousehack_alive_cnt = 0; + vp_xoffset = vp_yoffset = 0; + tablet_data = 0; + off = getmhoffset (); + if (off) + rtarea[off + MH_E] = 0; } static void mousehack_enable (void) { - int off, mode; + int off, mode; - if (!uae_boot_rom || currprefs.input_tablet == TABLET_OFF) - return; - off = getmhoffset (); - if (rtarea[off + MH_E]) - return; - mode = 0x80; - if (currprefs.input_tablet == TABLET_MOUSEHACK) - mode |= 1; - if (inputdevice_is_tablet () > 0) - mode |= 2; - write_log (L"Tablet driver enabled (%s)\n", ((mode & 3) == 3 ? "tablet+mousehack" : ((mode & 3) == 2) ? "tablet" : "mousehack")); - rtarea[off + MH_E] = 0x80; + if (!uae_boot_rom || currprefs.input_tablet == TABLET_OFF) + return; + off = getmhoffset (); + if (rtarea[off + MH_E]) + return; + mode = 0x80; + if (currprefs.input_tablet == TABLET_MOUSEHACK) + mode |= 1; + if (inputdevice_is_tablet () > 0) + mode |= 2; + write_log (L"Tablet driver enabled (%s)\n", ((mode & 3) == 3 ? "tablet+mousehack" : ((mode & 3) == 2) ? "tablet" : "mousehack")); + rtarea[off + MH_E] = 0x80; } void input_mousehack_mouseoffset (uaecptr pointerprefs) { - mouseoffset_x = (uae_s16)get_word (pointerprefs + 28); - mouseoffset_y = (uae_s16)get_word (pointerprefs + 30); + mouseoffset_x = (uae_s16)get_word (pointerprefs + 28); + mouseoffset_y = (uae_s16)get_word (pointerprefs + 30); } void input_mousehack_status (int mode, uaecptr diminfo, uaecptr dispinfo, uaecptr vp, uae_u32 moffset) { - if (mode == 0) { - uae_u8 v = rtarea[getmhoffset ()]; - v |= 0x40; - rtarea[getmhoffset ()] = v; - write_log (L"Tablet driver running (%02x)\n", v); - } else if (mode == 1) { - int x1 = -1, y1 = -1, x2 = -1, y2 = -1; - uae_u32 props = 0; - dimensioninfo_width = -1; - dimensioninfo_height = -1; - vp_xoffset = 0; - vp_yoffset = 0; - if (diminfo) { - x1 = get_word (diminfo + 50); - y1 = get_word (diminfo + 52); - x2 = get_word (diminfo + 54); - y2 = get_word (diminfo + 56); - dimensioninfo_width = x2 - x1 + 1; - dimensioninfo_height = y2 - y1 + 1; - } - if (vp) { - vp_xoffset = get_word (vp + 28); - vp_yoffset = get_word (vp + 30); - } - if (dispinfo) - props = get_long (dispinfo + 18); - dimensioninfo_dbl = (props & 0x00020000) ? 1 : 0; - write_log (L"%08x %08x %08x (%dx%d)-(%dx%d) d=%dx%d %s\n", - diminfo, props, vp, x1, y1, x2, y2, vp_xoffset, vp_yoffset, - (props & 0x00020000) ? "dbl" : ""); - } else if (mode == 2) { - if (mousehack_alive_cnt == 0) - mousehack_alive_cnt = -100; - else if (mousehack_alive_cnt > 0) - mousehack_alive_cnt = 100; - } + if (mode == 0) { + uae_u8 v = rtarea[getmhoffset ()]; + v |= 0x40; + rtarea[getmhoffset ()] = v; + write_log (L"Tablet driver running (%02x)\n", v); + } else if (mode == 1) { + int x1 = -1, y1 = -1, x2 = -1, y2 = -1; + uae_u32 props = 0; + dimensioninfo_width = -1; + dimensioninfo_height = -1; + vp_xoffset = 0; + vp_yoffset = 0; + if (diminfo) { + x1 = get_word (diminfo + 50); + y1 = get_word (diminfo + 52); + x2 = get_word (diminfo + 54); + y2 = get_word (diminfo + 56); + dimensioninfo_width = x2 - x1 + 1; + dimensioninfo_height = y2 - y1 + 1; + } + if (vp) { + vp_xoffset = get_word (vp + 28); + vp_yoffset = get_word (vp + 30); + } + if (dispinfo) + props = get_long (dispinfo + 18); + dimensioninfo_dbl = (props & 0x00020000) ? 1 : 0; + write_log (L"%08x %08x %08x (%dx%d)-(%dx%d) d=%dx%d %s\n", + diminfo, props, vp, x1, y1, x2, y2, vp_xoffset, vp_yoffset, + (props & 0x00020000) ? "dbl" : ""); + } else if (mode == 2) { + if (mousehack_alive_cnt == 0) + mousehack_alive_cnt = -100; + else if (mousehack_alive_cnt > 0) + mousehack_alive_cnt = 100; + } } void get_custom_mouse_limits (int *w, int *h, int *dx, int *dy, int dbl); void inputdevice_tablet_strobe (void) { - uae_u8 *p; - uae_u32 off; + uae_u8 *p; + uae_u32 off; - mousehack_enable (); - if (!uae_boot_rom) - return; - if (!tablet_data) - return; - off = getmhoffset (); - p = rtarea + off; - p[MH_CNT]++; + mousehack_enable (); + if (!uae_boot_rom) + return; + if (!tablet_data) + return; + off = getmhoffset (); + p = rtarea + off; + p[MH_CNT]++; } void inputdevice_tablet (int x, int y, int z, int pressure, uae_u32 buttonbits, int inproximity, int ax, int ay, int az) { - uae_u8 *p; - uae_u8 tmp[MH_END]; - uae_u32 off; + uae_u8 *p; + uae_u8 tmp[MH_END]; + uae_u32 off; - mousehack_enable (); - if (inputdevice_is_tablet () <= 0) - return; - //write_log (L"%d %d %d %d %08X %d %d %d %d\n", x, y, z, pressure, buttonbits, inproximity, ax, ay, az); - off = getmhoffset (); - p = rtarea + off; + mousehack_enable (); + if (inputdevice_is_tablet () <= 0) + return; + //write_log (L"%d %d %d %d %08X %d %d %d %d\n", x, y, z, pressure, buttonbits, inproximity, ax, ay, az); + off = getmhoffset (); + p = rtarea + off; - memcpy (tmp, p + MH_START, MH_END - MH_START); + memcpy (tmp, p + MH_START, MH_END - MH_START); #if 0 - if (currprefs.input_magic_mouse) { - int maxx, maxy, diffx, diffy; - int dw, dh, ax, ay, aw, ah; - float xmult, ymult; - float fx, fy; - - fx = (float)x; - fy = (float)y; - desktop_coords (&dw, &dh, &ax, &ay, &aw, &ah); - xmult = (float)tablet_maxx / dw; - ymult = (float)tablet_maxy / dh; - - diffx = 0; - diffy = 0; - if (picasso_on) { - maxx = gfxvidinfo.width; - maxy = gfxvidinfo.height; - } else { - get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy); - } - diffx += ax; - diffy += ah; - - fx -= diffx * xmult; - if (fx < 0) - fx = 0; - if (fx >= aw * xmult) - fx = aw * xmult - 1; - fy -= diffy * ymult; - if (fy < 0) - fy = 0; - if (fy >= ah * ymult) - fy = ah * ymult - 1; - - x = (int)(fx * (aw * xmult) / tablet_maxx + 0.5); - y = (int)(fy * (ah * ymult) / tablet_maxy + 0.5); - - } + if (currprefs.input_magic_mouse) { + int maxx, maxy, diffx, diffy; + int dw, dh, ax, ay, aw, ah; + float xmult, ymult; + float fx, fy; + + fx = (float)x; + fy = (float)y; + desktop_coords (&dw, &dh, &ax, &ay, &aw, &ah); + xmult = (float)tablet_maxx / dw; + ymult = (float)tablet_maxy / dh; + + diffx = 0; + diffy = 0; + if (picasso_on) { + maxx = gfxvidinfo.width; + maxy = gfxvidinfo.height; + } else { + get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy); + } + diffx += ax; + diffy += ah; + + fx -= diffx * xmult; + if (fx < 0) + fx = 0; + if (fx >= aw * xmult) + fx = aw * xmult - 1; + fy -= diffy * ymult; + if (fy < 0) + fy = 0; + if (fy >= ah * ymult) + fy = ah * ymult - 1; + + x = (int)(fx * (aw * xmult) / tablet_maxx + 0.5); + y = (int)(fy * (ah * ymult) / tablet_maxy + 0.5); + + } #endif - p[MH_X] = x >> 8; - p[MH_X + 1] = x; - p[MH_Y] = y >> 8; - p[MH_Y + 1] = y; - p[MH_Z] = z >> 8; - p[MH_Z + 1] = z; - - p[MH_AX] = ax >> 8; - p[MH_AX + 1] = ax; - p[MH_AY] = ay >> 8; - p[MH_AY + 1] = ay; - p[MH_AZ] = az >> 8; - p[MH_AZ + 1] = az; - - p[MH_MAXX] = tablet_maxx >> 8; - p[MH_MAXX + 1] = tablet_maxx; - p[MH_MAXY] = tablet_maxy >> 8; - p[MH_MAXY + 1] = tablet_maxy; - - p[MH_PRESSURE] = pressure >> 8; - p[MH_PRESSURE + 1] = pressure; - - p[MH_BUTTONBITS + 0] = buttonbits >> 24; - p[MH_BUTTONBITS + 1] = buttonbits >> 16; - p[MH_BUTTONBITS + 2] = buttonbits >> 8; - p[MH_BUTTONBITS + 3] = buttonbits >> 0; - - if (inproximity < 0) { - p[MH_INPROXIMITY] = p[MH_INPROXIMITY + 1] = 0xff; - } else { - p[MH_INPROXIMITY] = 0; - p[MH_INPROXIMITY + 1] = inproximity ? 1 : 0; - } + p[MH_X] = x >> 8; + p[MH_X + 1] = x; + p[MH_Y] = y >> 8; + p[MH_Y + 1] = y; + p[MH_Z] = z >> 8; + p[MH_Z + 1] = z; + + p[MH_AX] = ax >> 8; + p[MH_AX + 1] = ax; + p[MH_AY] = ay >> 8; + p[MH_AY + 1] = ay; + p[MH_AZ] = az >> 8; + p[MH_AZ + 1] = az; + + p[MH_MAXX] = tablet_maxx >> 8; + p[MH_MAXX + 1] = tablet_maxx; + p[MH_MAXY] = tablet_maxy >> 8; + p[MH_MAXY + 1] = tablet_maxy; + + p[MH_PRESSURE] = pressure >> 8; + p[MH_PRESSURE + 1] = pressure; + + p[MH_BUTTONBITS + 0] = buttonbits >> 24; + p[MH_BUTTONBITS + 1] = buttonbits >> 16; + p[MH_BUTTONBITS + 2] = buttonbits >> 8; + p[MH_BUTTONBITS + 3] = buttonbits >> 0; + + if (inproximity < 0) { + p[MH_INPROXIMITY] = p[MH_INPROXIMITY + 1] = 0xff; + } else { + p[MH_INPROXIMITY] = 0; + p[MH_INPROXIMITY + 1] = inproximity ? 1 : 0; + } - if (!memcmp (tmp, p + MH_START, MH_END - MH_START)) - return; - rtarea[off + MH_E] = 0xc0 | 2; - p[MH_CNT]++; + if (!memcmp (tmp, p + MH_START, MH_END - MH_START)) + return; + rtarea[off + MH_E] = 0xc0 | 2; + p[MH_CNT]++; } void inputdevice_tablet_info (int maxx, int maxy, int maxz, int maxax, int maxay, int maxaz, int xres, int yres) { - uae_u8 *p; + uae_u8 *p; - if (!uae_boot_rom) - return; - p = rtarea + getmhoffset (); + if (!uae_boot_rom) + return; + p = rtarea + getmhoffset (); - tablet_maxx = maxx; - tablet_maxy = maxy; - p[MH_MAXX] = maxx >> 8; - p[MH_MAXX + 1] = maxx; - p[MH_MAXY] = maxy >> 8; - p[MH_MAXY + 1] = maxy; - p[MH_MAXZ] = maxz >> 8; - p[MH_MAXZ + 1] = maxz; + tablet_maxx = maxx; + tablet_maxy = maxy; + p[MH_MAXX] = maxx >> 8; + p[MH_MAXX + 1] = maxx; + p[MH_MAXY] = maxy >> 8; + p[MH_MAXY + 1] = maxy; + p[MH_MAXZ] = maxz >> 8; + p[MH_MAXZ + 1] = maxz; - p[MH_RESX] = xres >> 8; - p[MH_RESX + 1] = xres; - p[MH_RESY] = yres >> 8; - p[MH_RESY + 1] = yres; + p[MH_RESX] = xres >> 8; + p[MH_RESX + 1] = xres; + p[MH_RESY] = yres >> 8; + p[MH_RESY + 1] = yres; - p[MH_MAXAX] = maxax >> 8; - p[MH_MAXAX + 1] = maxax; - p[MH_MAXAY] = maxay >> 8; - p[MH_MAXAY + 1] = maxay; - p[MH_MAXAZ] = maxaz >> 8; - p[MH_MAXAZ + 1] = maxaz; + p[MH_MAXAX] = maxax >> 8; + p[MH_MAXAX + 1] = maxax; + p[MH_MAXAY] = maxay >> 8; + p[MH_MAXAY + 1] = maxay; + p[MH_MAXAZ] = maxaz >> 8; + p[MH_MAXAZ + 1] = maxaz; } @@ -1212,188 +1212,188 @@ void getgfxoffset (int *dx, int *dy, int*,int*); static void inputdevice_mh_abs (int x, int y) { - uae_u8 *p; - uae_u8 tmp[4]; - uae_u32 off; + uae_u8 *p; + uae_u8 tmp[4]; + uae_u32 off; - mousehack_enable (); - off = getmhoffset (); - p = rtarea + off; + mousehack_enable (); + off = getmhoffset (); + p = rtarea + off; - memcpy (tmp, p + MH_ABSX, 4); + memcpy (tmp, p + MH_ABSX, 4); - x -= mouseoffset_x + 1; - y -= mouseoffset_y + 2; + x -= mouseoffset_x + 1; + y -= mouseoffset_y + 2; - p[MH_ABSX] = x >> 8; - p[MH_ABSX + 1] = x; - p[MH_ABSY] = y >> 8; - p[MH_ABSY + 1] = y; + p[MH_ABSX] = x >> 8; + p[MH_ABSX + 1] = x; + p[MH_ABSY] = y >> 8; + p[MH_ABSY + 1] = y; - if (!memcmp (tmp, p + MH_ABSX, 4)) - return; - rtarea[off + MH_E] = 0xc0 | 1; - p[MH_CNT]++; - tablet_data = 1; + if (!memcmp (tmp, p + MH_ABSX, 4)) + return; + rtarea[off + MH_E] = 0xc0 | 1; + p[MH_CNT]++; + tablet_data = 1; } #if 0 static void inputdevice_mh_abs_v36 (int x, int y) { - uae_u8 *p; - uae_u8 tmp[MH_END]; - uae_u32 off; - int maxx, maxy, diffx, diffy; - int fdy, fdx, fmx, fmy; - - mousehack_enable (); - off = getmhoffset (); - p = rtarea + off; - - memcpy (tmp, p + MH_START, MH_END - MH_START); - - getgfxoffset (&fdx, &fdy, &fmx, &fmy); - x -= fdx; - y -= fdy; - x += vp_xoffset; - y += vp_yoffset; - - diffx = diffy = 0; - maxx = maxy = 0; - - if (picasso_on) { - maxx = picasso96_state.Width; - maxy = picasso96_state.Height; - } else if (dimensioninfo_width > 0 && dimensioninfo_height > 0) { - maxx = dimensioninfo_width; - maxy = dimensioninfo_height; - get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy, dimensioninfo_dbl); - } else { - uaecptr gb = get_gfxbase (); - maxx = 0; maxy = 0; - if (gb) { - maxy = get_word (gb + 216); - maxx = get_word (gb + 218); - } - get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy, 0); - } + uae_u8 *p; + uae_u8 tmp[MH_END]; + uae_u32 off; + int maxx, maxy, diffx, diffy; + int fdy, fdx, fmx, fmy; + + mousehack_enable (); + off = getmhoffset (); + p = rtarea + off; + + memcpy (tmp, p + MH_START, MH_END - MH_START); + + getgfxoffset (&fdx, &fdy, &fmx, &fmy); + x -= fdx; + y -= fdy; + x += vp_xoffset; + y += vp_yoffset; + + diffx = diffy = 0; + maxx = maxy = 0; + + if (picasso_on) { + maxx = picasso96_state.Width; + maxy = picasso96_state.Height; + } else if (dimensioninfo_width > 0 && dimensioninfo_height > 0) { + maxx = dimensioninfo_width; + maxy = dimensioninfo_height; + get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy, dimensioninfo_dbl); + } else { + uaecptr gb = get_gfxbase (); + maxx = 0; maxy = 0; + if (gb) { + maxy = get_word (gb + 216); + maxx = get_word (gb + 218); + } + get_custom_mouse_limits (&maxx, &maxy, &diffx, &diffy, 0); + } #if 0 - { - uaecptr gb = get_intuitionbase (); - maxy = get_word (gb + 1344 + 2); - maxx = get_word (gb + 1348 + 2); - write_log (L"%d %d\n", maxx, maxy); - } + { + uaecptr gb = get_intuitionbase (); + maxy = get_word (gb + 1344 + 2); + maxx = get_word (gb + 1348 + 2); + write_log (L"%d %d\n", maxx, maxy); + } #endif #if 1 - { - uaecptr gb = get_gfxbase (); - uaecptr view = get_long (gb + 34); - if (view) { - uaecptr vp = get_long (view); - if (vp) { - int w, h, dw, dh; - w = get_word (vp + 24); - h = get_word (vp + 26) * 2; - dw = get_word (vp + 28); - dh = get_word (vp + 30); - //write_log (L"%d %d %d %d\n", w, h, dw, dh); - if (w < maxx) - maxx = w; - if (h < maxy) - maxy = h; - x -= dw; - y -= dh; - } - } - //write_log (L"* %d %d\n", get_word (gb + 218), get_word (gb + 216)); - } - //write_log (L"%d %d\n", maxx, maxy); + { + uaecptr gb = get_gfxbase (); + uaecptr view = get_long (gb + 34); + if (view) { + uaecptr vp = get_long (view); + if (vp) { + int w, h, dw, dh; + w = get_word (vp + 24); + h = get_word (vp + 26) * 2; + dw = get_word (vp + 28); + dh = get_word (vp + 30); + //write_log (L"%d %d %d %d\n", w, h, dw, dh); + if (w < maxx) + maxx = w; + if (h < maxy) + maxy = h; + x -= dw; + y -= dh; + } + } + //write_log (L"* %d %d\n", get_word (gb + 218), get_word (gb + 216)); + } + //write_log (L"%d %d\n", maxx, maxy); #endif - maxx = maxx * 1000 / fmx; - maxy = maxy * 1000 / fmy; - - if (maxx <= 0) - maxx = 1; - if (maxy <= 0) - maxy = 1; - - x -= diffx; - if (x < 0) - x = 0; - if (x >= maxx) - x = maxx - 1; - - y -= diffy; - if (y < 0) - y = 0; - if (y >= maxy) - y = maxy - 1; - - //write_log (L"%d %d %d %d\n", x, y, maxx, maxy); - - p[MH_X] = x >> 8; - p[MH_X + 1] = x; - p[MH_Y] = y >> 8; - p[MH_Y + 1] = y; - p[MH_MAXX] = maxx >> 8; - p[MH_MAXX + 1] = maxx; - p[MH_MAXY] = maxy >> 8; - p[MH_MAXY + 1] = maxy; - - p[MH_Z] = p[MH_Z + 1] = 0; - p[MH_MAXZ] = p[MH_MAXZ + 1] = 0; - p[MH_AX] = p[MH_AX + 1] = 0; - p[MH_AY] = p[MH_AY + 1] = 0; - p[MH_AZ] = p[MH_AZ + 1] = 0; - p[MH_PRESSURE] = p[MH_PRESSURE + 1] = 0; - p[MH_INPROXIMITY] = p[MH_INPROXIMITY + 1] = 0xff; - - if (!memcmp (tmp, p + MH_START, MH_END - MH_START)) - return; - p[MH_CNT]++; - tablet_data = 1; + maxx = maxx * 1000 / fmx; + maxy = maxy * 1000 / fmy; + + if (maxx <= 0) + maxx = 1; + if (maxy <= 0) + maxy = 1; + + x -= diffx; + if (x < 0) + x = 0; + if (x >= maxx) + x = maxx - 1; + + y -= diffy; + if (y < 0) + y = 0; + if (y >= maxy) + y = maxy - 1; + + //write_log (L"%d %d %d %d\n", x, y, maxx, maxy); + + p[MH_X] = x >> 8; + p[MH_X + 1] = x; + p[MH_Y] = y >> 8; + p[MH_Y + 1] = y; + p[MH_MAXX] = maxx >> 8; + p[MH_MAXX + 1] = maxx; + p[MH_MAXY] = maxy >> 8; + p[MH_MAXY + 1] = maxy; + + p[MH_Z] = p[MH_Z + 1] = 0; + p[MH_MAXZ] = p[MH_MAXZ + 1] = 0; + p[MH_AX] = p[MH_AX + 1] = 0; + p[MH_AY] = p[MH_AY + 1] = 0; + p[MH_AZ] = p[MH_AZ + 1] = 0; + p[MH_PRESSURE] = p[MH_PRESSURE + 1] = 0; + p[MH_INPROXIMITY] = p[MH_INPROXIMITY + 1] = 0xff; + + if (!memcmp (tmp, p + MH_START, MH_END - MH_START)) + return; + p[MH_CNT]++; + tablet_data = 1; } #endif static void mousehack_helper (void) { - int x, y; - int fdy, fdx, fmx, fmy; + int x, y; + int fdy, fdx, fmx, fmy; - if (currprefs.input_magic_mouse == 0 || currprefs.input_tablet < TABLET_MOUSEHACK) - return; + if (currprefs.input_magic_mouse == 0 || currprefs.input_tablet < TABLET_MOUSEHACK) + return; #if 0 - if (kickstart_version >= 36) { - inputdevice_mh_abs_v36 (lastmx, lastmy); - return; - } + if (kickstart_version >= 36) { + inputdevice_mh_abs_v36 (lastmx, lastmy); + return; + } #endif - x = lastmx; - y = lastmy; - getgfxoffset (&fdx, &fdy, &fmx, &fmy); + x = lastmx; + y = lastmy; + getgfxoffset (&fdx, &fdy, &fmx, &fmy); #ifdef PICASSO96 - if (picasso_on) { - x -= picasso96_state.XOffset; - y -= picasso96_state.YOffset; - x = x * fmx / 1000; - y = y * fmy / 1000; - x -= fdx * fmx / 1000; - y -= fdy * fmy / 1000; - } else + if (picasso_on) { + x -= picasso96_state.XOffset; + y -= picasso96_state.YOffset; + x = x * fmx / 1000; + y = y * fmy / 1000; + x -= fdx * fmx / 1000; + y -= fdy * fmy / 1000; + } else #endif - { - x = x * fmx / 1000; - y = y * fmy / 1000; - x -= fdx * fmx / 1000 - 1; - y -= fdy * fmy / 1000 - 2; - x = coord_native_to_amiga_x (x); - y = coord_native_to_amiga_y (y) << 1; - } - inputdevice_mh_abs (x, y); + { + x = x * fmx / 1000; + y = y * fmy / 1000; + x -= fdx * fmx / 1000 - 1; + y -= fdy * fmy / 1000 - 2; + x = coord_native_to_amiga_x (x); + y = coord_native_to_amiga_y (y) << 1; + } + inputdevice_mh_abs (x, y); } static int mouseedge_x, mouseedge_y, mouseedge_time; @@ -1404,544 +1404,544 @@ extern void setmouseactivexy (int,int,int); static int mouseedge (void) { - int x, y, dir; - uaecptr ib; - static int melast_x, melast_y; - static int isnonzero; + int x, y, dir; + uaecptr ib; + static int melast_x, melast_y; + static int isnonzero; - if (currprefs.input_magic_mouse == 0 || currprefs.input_tablet > 0) - return 0; - if (magicmouse_ibase == 0xffffffff) - return 0; - dir = 0; - if (!mouseedge_time) { - isnonzero = 0; - goto end; - } - ib = get_intuitionbase (); - if (!ib) - return 0; - x = get_word (ib + 70); - y = get_word (ib + 68); - if (x || y) - isnonzero = 1; - if (!isnonzero) - return 0; - if (melast_x == x) { - if (mouseedge_x < -MOUSEEDGE_RANGE) { - mouseedge_x = 0; - dir |= 1; - goto end; - } - if (mouseedge_x > MOUSEEDGE_RANGE) { - mouseedge_x = 0; - dir |= 2; - goto end; - } - } else { - mouseedge_x = 0; - melast_x = x; - } - if (melast_y == y) { - if (mouseedge_y < -MOUSEEDGE_RANGE) { - mouseedge_y = 0; - dir |= 4; - goto end; - } - if (mouseedge_y > MOUSEEDGE_RANGE) { - mouseedge_y = 0; - dir |= 8; - goto end; - } - } else { - mouseedge_y = 0; - melast_y = y; - } - return 1; + if (currprefs.input_magic_mouse == 0 || currprefs.input_tablet > 0) + return 0; + if (magicmouse_ibase == 0xffffffff) + return 0; + dir = 0; + if (!mouseedge_time) { + isnonzero = 0; + goto end; + } + ib = get_intuitionbase (); + if (!ib) + return 0; + x = get_word (ib + 70); + y = get_word (ib + 68); + if (x || y) + isnonzero = 1; + if (!isnonzero) + return 0; + if (melast_x == x) { + if (mouseedge_x < -MOUSEEDGE_RANGE) { + mouseedge_x = 0; + dir |= 1; + goto end; + } + if (mouseedge_x > MOUSEEDGE_RANGE) { + mouseedge_x = 0; + dir |= 2; + goto end; + } + } else { + mouseedge_x = 0; + melast_x = x; + } + if (melast_y == y) { + if (mouseedge_y < -MOUSEEDGE_RANGE) { + mouseedge_y = 0; + dir |= 4; + goto end; + } + if (mouseedge_y > MOUSEEDGE_RANGE) { + mouseedge_y = 0; + dir |= 8; + goto end; + } + } else { + mouseedge_y = 0; + melast_y = y; + } + return 1; end: - mouseedge_time = 0; - if (dir) { - if (!picasso_on) { - int aw = 0, ah = 0, dx, dy; - get_custom_mouse_limits (&aw, &ah, &dx, &dy, dimensioninfo_dbl); - x += dx; - y += dy; - } - if (!dmaen (DMA_SPRITE)) - setmouseactivexy (x, y, 0); - else - setmouseactivexy (x, y, dir); - } - return 1; + mouseedge_time = 0; + if (dir) { + if (!picasso_on) { + int aw = 0, ah = 0, dx, dy; + get_custom_mouse_limits (&aw, &ah, &dx, &dy, dimensioninfo_dbl); + x += dx; + y += dy; + } + if (!dmaen (DMA_SPRITE)) + setmouseactivexy (x, y, 0); + else + setmouseactivexy (x, y, dir); + } + return 1; } int magicmouse_alive (void) { - return mouseedge_alive > 0; + return mouseedge_alive > 0; } STATIC_INLINE int adjust (int val) { - if (val > 127) - return 127; - else if (val < -127) - return -127; - return val; + if (val > 127) + return 127; + else if (val < -127) + return -127; + return val; } int getbuttonstate (int joy, int button) { - int v; - - v = (joybutton[joy] & (1 << button)) ? 1 : 0; - if (input_recording > 0 && ((joybutton[joy] ^ oldbuttons[joy]) & (1 << button))) { - oldbuttons[joy] &= ~(1 << button); - if (v) - oldbuttons[joy] |= 1 << button; - inprec_rstart (INPREC_JOYBUTTON); - inprec_ru8 (joy); - inprec_ru8 (button); - inprec_ru8 (v); - inprec_rend (); - } else if (input_recording < 0) { - while(inprec_pstart (INPREC_JOYBUTTON)) { - uae_u8 j = inprec_pu8 (); - uae_u8 but = inprec_pu8 (); - uae_u8 vv = inprec_pu8 (); - inprec_pend (); - oldbuttons[j] &= ~(1 << but); - if (vv) - oldbuttons[j] |= 1 << but; - } - v = (oldbuttons[joy] & (1 << button)) ? 1 : 0; - } - return v; + int v; + + v = (joybutton[joy] & (1 << button)) ? 1 : 0; + if (input_recording > 0 && ((joybutton[joy] ^ oldbuttons[joy]) & (1 << button))) { + oldbuttons[joy] &= ~(1 << button); + if (v) + oldbuttons[joy] |= 1 << button; + inprec_rstart (INPREC_JOYBUTTON); + inprec_ru8 (joy); + inprec_ru8 (button); + inprec_ru8 (v); + inprec_rend (); + } else if (input_recording < 0) { + while(inprec_pstart (INPREC_JOYBUTTON)) { + uae_u8 j = inprec_pu8 (); + uae_u8 but = inprec_pu8 (); + uae_u8 vv = inprec_pu8 (); + inprec_pend (); + oldbuttons[j] &= ~(1 << but); + if (vv) + oldbuttons[j] |= 1 << but; + } + v = (oldbuttons[joy] & (1 << button)) ? 1 : 0; + } + return v; } static int getvelocity (int num, int subnum, int pct) { - int val; - int v; - - val = mouse_delta[num][subnum]; - v = val * pct / 1000; - if (!v) { - if (val < -maxvpos / 2) - v = -2; - else if (val < 0) - v = -1; - else if (val > maxvpos / 2) - v = 2; - else if (val > 0) - v = 1; - } - if (!mouse_deltanoreset[num][subnum]) - mouse_delta[num][subnum] -= v; - return v; + int val; + int v; + + val = mouse_delta[num][subnum]; + v = val * pct / 1000; + if (!v) { + if (val < -maxvpos / 2) + v = -2; + else if (val < 0) + v = -1; + else if (val > maxvpos / 2) + v = 2; + else if (val > 0) + v = 1; + } + if (!mouse_deltanoreset[num][subnum]) + mouse_delta[num][subnum] -= v; + return v; } static void mouseupdate (int pct, int vsync) { - int v, i; - int max = 127; - static int mxd, myd; + int v, i; + int max = 127; + static int mxd, myd; - if (pct > 1000) - pct = 1000; + if (pct > 1000) + pct = 1000; - if (vsync) { - if (mxd < 0) { - if (mouseedge_x > 0) - mouseedge_x = 0; - else - mouseedge_x += mxd; - mouseedge_time = MOUSEEDGE_TIME; - } - if (mxd > 0) { - if (mouseedge_x < 0) - mouseedge_x = 0; - else - mouseedge_x += mxd; - mouseedge_time = MOUSEEDGE_TIME; - } - if (myd < 0) { - if (mouseedge_y > 0) - mouseedge_y = 0; - else - mouseedge_y += myd; - mouseedge_time = MOUSEEDGE_TIME; - } - if (myd > 0) { - if (mouseedge_y < 0) - mouseedge_y = 0; - else - mouseedge_y += myd; - mouseedge_time = MOUSEEDGE_TIME; - } - if (mouseedge_time > 0) { - mouseedge_time--; - if (mouseedge_time == 0) { - mouseedge_x = 0; - mouseedge_y = 0; - } + if (vsync) { + if (mxd < 0) { + if (mouseedge_x > 0) + mouseedge_x = 0; + else + mouseedge_x += mxd; + mouseedge_time = MOUSEEDGE_TIME; + } + if (mxd > 0) { + if (mouseedge_x < 0) + mouseedge_x = 0; + else + mouseedge_x += mxd; + mouseedge_time = MOUSEEDGE_TIME; + } + if (myd < 0) { + if (mouseedge_y > 0) + mouseedge_y = 0; + else + mouseedge_y += myd; + mouseedge_time = MOUSEEDGE_TIME; + } + if (myd > 0) { + if (mouseedge_y < 0) + mouseedge_y = 0; + else + mouseedge_y += myd; + mouseedge_time = MOUSEEDGE_TIME; + } + if (mouseedge_time > 0) { + mouseedge_time--; + if (mouseedge_time == 0) { + mouseedge_x = 0; + mouseedge_y = 0; + } + } + mxd = 0; + myd = 0; } - mxd = 0; - myd = 0; - } - - for (i = 0; i < 2; i++) { - - v = getvelocity (i, 0, pct); - mxd += v; - mouse_x[i] += v; - - v = getvelocity (i, 1, pct); - myd += v; - mouse_y[i] += v; - - v = getvelocity (i, 2, pct); - if (v > 0) - record_key (0x7a << 1); - else if (v < 0) - record_key (0x7b << 1); - if (!mouse_deltanoreset[i][2]) - mouse_delta[i][2] = 0; - if (mouse_frame_x[i] - mouse_x[i] > max) - mouse_x[i] = mouse_frame_x[i] - max; - if (mouse_frame_x[i] - mouse_x[i] < -max) - mouse_x[i] = mouse_frame_x[i] + max; + for (i = 0; i < 2; i++) { - if (mouse_frame_y[i] - mouse_y[i] > max) - mouse_y[i] = mouse_frame_y[i] - max; - if (mouse_frame_y[i] - mouse_y[i] < -max) - mouse_y[i] = mouse_frame_y[i] + max; + v = getvelocity (i, 0, pct); + mxd += v; + mouse_x[i] += v; + + v = getvelocity (i, 1, pct); + myd += v; + mouse_y[i] += v; + + v = getvelocity (i, 2, pct); + if (v > 0) + record_key (0x7a << 1); + else if (v < 0) + record_key (0x7b << 1); + if (!mouse_deltanoreset[i][2]) + mouse_delta[i][2] = 0; + + if (mouse_frame_x[i] - mouse_x[i] > max) + mouse_x[i] = mouse_frame_x[i] - max; + if (mouse_frame_x[i] - mouse_x[i] < -max) + mouse_x[i] = mouse_frame_x[i] + max; + + if (mouse_frame_y[i] - mouse_y[i] > max) + mouse_y[i] = mouse_frame_y[i] - max; + if (mouse_frame_y[i] - mouse_y[i] < -max) + mouse_y[i] = mouse_frame_y[i] + max; + + if (!vsync) { + mouse_frame_x[i] = mouse_x[i]; + mouse_frame_y[i] = mouse_y[i]; + } - if (!vsync) { - mouse_frame_x[i] = mouse_x[i]; - mouse_frame_y[i] = mouse_y[i]; } - - } } static int input_vpos, input_frame; extern int vpos; static void readinput (void) { - uae_u32 totalvpos; + uae_u32 totalvpos; - totalvpos = input_frame * maxvpos + vpos; - mouseupdate ((totalvpos - input_vpos) * 1000 / maxvpos, 0); - input_vpos = totalvpos; + totalvpos = input_frame * maxvpos + vpos; + mouseupdate ((totalvpos - input_vpos) * 1000 / maxvpos, 0); + input_vpos = totalvpos; } int getjoystate (int joy) { - int left = 1, right = 1, top = 1, bot = 1; - uae_u16 v = 0; - - if (inputdevice_logging & 2) - write_log (L"JOY%dDAT %08x\n", joy, M68K_GETPC); - readinput (); - if (joydir[joy] & DIR_LEFT) - left = 0; - if (joydir[joy] & DIR_RIGHT) - right = 0; - if (joydir[joy] & DIR_UP) - top = 0; - if (joydir[joy] & DIR_DOWN) - bot = 0; - v = (uae_u8)mouse_x[joy] | (mouse_y[joy] << 8); - if (!left || !right || !top || !bot || !mouse_port[joy]) { - int b9, b8, b1, b0; - mouse_x[joy] &= ~3; - mouse_y[joy] &= ~3; - b0 = bot ^ right; - b1 = right ^ 1; - b8 = top ^ left; - b9 = left ^ 1; - v &= ~0x0303; - v |= (b0 << 0) | (b1 << 1) | (b8 << 8) | (b9 << 9); - } + int left = 1, right = 1, top = 1, bot = 1; + uae_u16 v = 0; + + if (inputdevice_logging & 2) + write_log (L"JOY%dDAT %08x\n", joy, M68K_GETPC); + readinput (); + if (joydir[joy] & DIR_LEFT) + left = 0; + if (joydir[joy] & DIR_RIGHT) + right = 0; + if (joydir[joy] & DIR_UP) + top = 0; + if (joydir[joy] & DIR_DOWN) + bot = 0; + v = (uae_u8)mouse_x[joy] | (mouse_y[joy] << 8); + if (!left || !right || !top || !bot || !mouse_port[joy]) { + int b9, b8, b1, b0; + mouse_x[joy] &= ~3; + mouse_y[joy] &= ~3; + b0 = bot ^ right; + b1 = right ^ 1; + b8 = top ^ left; + b9 = left ^ 1; + v &= ~0x0303; + v |= (b0 << 0) | (b1 << 1) | (b8 << 8) | (b9 << 9); + } #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"JOY%dDAT %04X %s\n", joy, v, debuginfo (0)); + if (notinrom ()) + write_log (L"JOY%dDAT %04X %s\n", joy, v, debuginfo (0)); #endif - if (input_recording > 0 && oldjoy[joy] != v) { - oldjoy[joy] = v; - inprec_rstart (INPREC_JOYPORT); - inprec_ru16 (v); - inprec_rend (); - } else if (input_recording < 0) { - v = oldjoy[joy]; - if (inprec_pstart (INPREC_JOYPORT)) { - v = inprec_pu16 (); - inprec_pend (); - } - oldjoy[joy] = v; - } - return v; + if (input_recording > 0 && oldjoy[joy] != v) { + oldjoy[joy] = v; + inprec_rstart (INPREC_JOYPORT); + inprec_ru16 (v); + inprec_rend (); + } else if (input_recording < 0) { + v = oldjoy[joy]; + if (inprec_pstart (INPREC_JOYPORT)) { + v = inprec_pu16 (); + inprec_pend (); + } + oldjoy[joy] = v; + } + return v; } uae_u16 JOY0DAT (void) { - uae_u16 v; - v = getjoystate (0); - v = dongle_joydat (0, v); - return v; + uae_u16 v; + v = getjoystate (0); + v = dongle_joydat (0, v); + return v; } uae_u16 JOY1DAT (void) { - uae_u16 v; - v = getjoystate (1); - v = dongle_joydat (1, v); - return v; + uae_u16 v; + v = getjoystate (1); + v = dongle_joydat (1, v); + return v; } void JOYTEST (uae_u16 v) { - mouse_x[0] &= 3; - mouse_y[0] &= 3; - mouse_x[1] &= 3; - mouse_y[1] &= 3; - mouse_x[0] |= v & 0xFC; - mouse_x[1] |= v & 0xFC; - mouse_y[0] |= (v >> 8) & 0xFC; - mouse_y[1] |= (v >> 8) & 0xFC; - mouse_frame_x[0] = mouse_x[0]; - mouse_frame_y[0] = mouse_y[0]; - mouse_frame_x[1] = mouse_x[1]; - mouse_frame_y[1] = mouse_y[1]; - dongle_joytest (v); - if (inputdevice_logging & 2) - write_log (L"JOYTEST: %04X PC=%x\n", v , M68K_GETPC); + mouse_x[0] &= 3; + mouse_y[0] &= 3; + mouse_x[1] &= 3; + mouse_y[1] &= 3; + mouse_x[0] |= v & 0xFC; + mouse_x[1] |= v & 0xFC; + mouse_y[0] |= (v >> 8) & 0xFC; + mouse_y[1] |= (v >> 8) & 0xFC; + mouse_frame_x[0] = mouse_x[0]; + mouse_frame_y[0] = mouse_y[0]; + mouse_frame_x[1] = mouse_x[1]; + mouse_frame_y[1] = mouse_y[1]; + dongle_joytest (v); + if (inputdevice_logging & 2) + write_log (L"JOYTEST: %04X PC=%x\n", v , M68K_GETPC); } static uae_u8 parconvert (uae_u8 v, int jd, int shift) { - if (jd & DIR_UP) - v &= ~(1 << shift); - if (jd & DIR_DOWN) - v &= ~(2 << shift); - if (jd & DIR_LEFT) - v &= ~(4 << shift); - if (jd & DIR_RIGHT) - v &= ~(8 << shift); - return v; + if (jd & DIR_UP) + v &= ~(1 << shift); + if (jd & DIR_DOWN) + v &= ~(2 << shift); + if (jd & DIR_LEFT) + v &= ~(4 << shift); + if (jd & DIR_RIGHT) + v &= ~(8 << shift); + return v; } /* io-pins floating: dir=1 -> return data, dir=0 -> always return 1 */ uae_u8 handle_parport_joystick (int port, uae_u8 pra, uae_u8 dra) { - uae_u8 v; - switch (port) - { + uae_u8 v; + switch (port) + { case 0: - v = (pra & dra) | (dra ^ 0xff); - if (parport_joystick_enabled) { - v = parconvert (v, joydir[2], 0); - v = parconvert (v, joydir[3], 4); - } - return v; + v = (pra & dra) | (dra ^ 0xff); + if (parport_joystick_enabled) { + v = parconvert (v, joydir[2], 0); + v = parconvert (v, joydir[3], 4); + } + return v; case 1: - v = ((pra & dra) | (dra ^ 0xff)) & 0x7; - if (parport_joystick_enabled) { - if (getbuttonstate (2, 0)) v &= ~4; - if (getbuttonstate (3, 0)) v &= ~1; - } - return v; + v = ((pra & dra) | (dra ^ 0xff)) & 0x7; + if (parport_joystick_enabled) { + if (getbuttonstate (2, 0)) v &= ~4; + if (getbuttonstate (3, 0)) v &= ~1; + } + return v; default: - abort (); - return 0; - } + abort (); + return 0; + } } static void charge_cap (int joy, int idx, int charge) { - if (charge < -1 || charge > 1) - charge = charge * 80; - pot_cap[joy][idx] += charge; - if (pot_cap[joy][idx] < 0) - pot_cap[joy][idx] = 0; - if (pot_cap[joy][idx] > 511) - pot_cap[joy][idx] = 511; + if (charge < -1 || charge > 1) + charge = charge * 80; + pot_cap[joy][idx] += charge; + if (pot_cap[joy][idx] < 0) + pot_cap[joy][idx] = 0; + if (pot_cap[joy][idx] > 511) + pot_cap[joy][idx] = 511; } static void cap_check (void) { - int joy, i; + int joy, i; + + for (joy = 0; joy < 2; joy++) { + for (i = 0; i < 2; i++) { + int charge = 0, dong, joypot; + uae_u16 pdir = 0x0200 << (joy * 4 + i * 2); /* output enable */ + uae_u16 pdat = 0x0100 << (joy * 4 + i * 2); /* data */ + int isbutton = getbuttonstate (joy, i == 0 ? JOYBUTTON_3 : JOYBUTTON_2); + + if (cd32_pad_enabled[joy]) + continue; + dong = dongle_analogjoy (joy, i); + if (dong >= 0) { + isbutton = 0; + joypot = dong; + if (pot_cap[joy][i] < joypot) + charge = 1; // slow charge via dongle resistor + } else { + joypot = joydirpot[joy][i]; + if (analog_port[joy][i] && pot_cap[joy][i] < joypot) + charge = 1; // slow charge via pot variable resistor + if ((digital_port[joy][i] || mouse_port[joy])) + charge = 1; // slow charge via pull-up resistor + } + if (!(potgo_value & pdir)) { // input? + if (pot_dat_act[joy][i]) + pot_dat[joy][i]++; + /* first 8 lines after potgo has been started = discharge cap */ + if (pot_dat_act[joy][i] == 1) { + if (pot_dat[joy][i] < (currprefs.ntscmode ? POTDAT_DELAY_NTSC : POTDAT_DELAY_PAL)) { + charge = -2; /* fast discharge delay */ + } else { + pot_dat_act[joy][i] = 2; + pot_dat[joy][i] = 0; + } + } + if (dong >= 0) { + if (pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot) + pot_dat_act[joy][i] = 0; + } else { + if (analog_port[joy][i] && pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot) + pot_dat_act[joy][i] = 0; + if ((digital_port[joy][i] || mouse_port[joy]) && pot_dat_act[joy][i] == 2) { + if (pot_cap[joy][i] >= 10 && !isbutton) + pot_dat_act[joy][i] = 0; + } + } + } else { // output? + charge = (potgo_value & pdat) ? 2 : -2; /* fast (dis)charge if output */ + if (potgo_value & pdat) + pot_dat_act[joy][i] = 0; // instant stop if output+high + if (isbutton) + pot_dat[joy][i]++; // "free running" if output+low + } - for (joy = 0; joy < 2; joy++) { - for (i = 0; i < 2; i++) { - int charge = 0, dong, joypot; - uae_u16 pdir = 0x0200 << (joy * 4 + i * 2); /* output enable */ - uae_u16 pdat = 0x0100 << (joy * 4 + i * 2); /* data */ - int isbutton = getbuttonstate (joy, i == 0 ? JOYBUTTON_3 : JOYBUTTON_2); - - if (cd32_pad_enabled[joy]) - continue; - dong = dongle_analogjoy (joy, i); - if (dong >= 0) { - isbutton = 0; - joypot = dong; - if (pot_cap[joy][i] < joypot) - charge = 1; // slow charge via dongle resistor - } else { - joypot = joydirpot[joy][i]; - if (analog_port[joy][i] && pot_cap[joy][i] < joypot) - charge = 1; // slow charge via pot variable resistor - if ((digital_port[joy][i] || mouse_port[joy])) - charge = 1; // slow charge via pull-up resistor - } - if (!(potgo_value & pdir)) { // input? - if (pot_dat_act[joy][i]) - pot_dat[joy][i]++; - /* first 8 lines after potgo has been started = discharge cap */ - if (pot_dat_act[joy][i] == 1) { - if (pot_dat[joy][i] < (currprefs.ntscmode ? POTDAT_DELAY_NTSC : POTDAT_DELAY_PAL)) { - charge = -2; /* fast discharge delay */ - } else { - pot_dat_act[joy][i] = 2; - pot_dat[joy][i] = 0; - } - } - if (dong >= 0) { - if (pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot) - pot_dat_act[joy][i] = 0; - } else { - if (analog_port[joy][i] && pot_dat_act[joy][i] == 2 && pot_cap[joy][i] >= joypot) - pot_dat_act[joy][i] = 0; - if ((digital_port[joy][i] || mouse_port[joy]) && pot_dat_act[joy][i] == 2) { - if (pot_cap[joy][i] >= 10 && !isbutton) - pot_dat_act[joy][i] = 0; - } + if (isbutton) + charge = -2; // button press overrides everything + + if (currprefs.cs_cdtvcd) { + /* CDTV P9 is not floating */ + if (!(potgo_value & pdir) && i == 1 && charge == 0) + charge = 2; + } + /* official Commodore mouse has pull-up resistors in button lines + * NOTE: 3rd party mice may not have pullups! */ + if (dong < 0 && mouse_port[joy] && charge == 0) + charge = 2; + /* emulate pullup resistor if button mapped because there too many broken + * programs that read second button in input-mode (and most 2+ button pads have + * pullups) + */ + if (dong < 0 && digital_port[joy][i] && charge == 0) + charge = 2; + + charge_cap (joy, i, charge); } - } else { // output? - charge = (potgo_value & pdat) ? 2 : -2; /* fast (dis)charge if output */ - if (potgo_value & pdat) - pot_dat_act[joy][i] = 0; // instant stop if output+high - if (isbutton) - pot_dat[joy][i]++; // "free running" if output+low - } - - if (isbutton) - charge = -2; // button press overrides everything - - if (currprefs.cs_cdtvcd) { - /* CDTV P9 is not floating */ - if (!(potgo_value & pdir) && i == 1 && charge == 0) - charge = 2; - } - /* official Commodore mouse has pull-up resistors in button lines - * NOTE: 3rd party mice may not have pullups! */ - if (dong < 0 && mouse_port[joy] && charge == 0) - charge = 2; - /* emulate pullup resistor if button mapped because there too many broken - * programs that read second button in input-mode (and most 2+ button pads have - * pullups) - */ - if (dong < 0 && digital_port[joy][i] && charge == 0) - charge = 2; - - charge_cap (joy, i, charge); - } - } + } } uae_u8 handle_joystick_buttons (uae_u8 dra) { - uae_u8 but = 0; - int i; - - cap_check (); - for (i = 0; i < 2; i++) { - if (cd32_pad_enabled[i]) { - uae_u16 p5dir = 0x0200 << (i * 4); - uae_u16 p5dat = 0x0100 << (i * 4); - but |= 0x40 << i; - /* Red button is connected to fire when p5 is 1 or floating */ - if (!(potgo_value & p5dir) || ((potgo_value & p5dat) && (potgo_value & p5dir))) { - if (getbuttonstate (i, JOYBUTTON_CD32_RED)) - but &= ~(0x40 << i); - } - } else if (!getbuttonstate (i, JOYBUTTON_1)) { - but |= 0x40 << i; - } - } - if (inputdevice_logging & 4) - write_log (L"BFE001: %02X:%02X %x\n", dra, but, M68K_GETPC); - return but; + uae_u8 but = 0; + int i; + + cap_check (); + for (i = 0; i < 2; i++) { + if (cd32_pad_enabled[i]) { + uae_u16 p5dir = 0x0200 << (i * 4); + uae_u16 p5dat = 0x0100 << (i * 4); + but |= 0x40 << i; + /* Red button is connected to fire when p5 is 1 or floating */ + if (!(potgo_value & p5dir) || ((potgo_value & p5dat) && (potgo_value & p5dir))) { + if (getbuttonstate (i, JOYBUTTON_CD32_RED)) + but &= ~(0x40 << i); + } + } else if (!getbuttonstate (i, JOYBUTTON_1)) { + but |= 0x40 << i; + } + } + if (inputdevice_logging & 4) + write_log (L"BFE001: %02X:%02X %x\n", dra, but, M68K_GETPC); + return but; } /* joystick 1 button 1 is used as a output for incrementing shift register */ void handle_cd32_joystick_cia (uae_u8 pra, uae_u8 dra) { - static int oldstate[2]; - int i; - - cap_check (); - for (i = 0; i < 2; i++) { - uae_u8 but = 0x40 << i; - uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ - uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ - if (!(potgo_value & p5dir) || !(potgo_value & p5dat)) { - if ((dra & but) && (pra & but) != oldstate[i]) { - if (!(pra & but)) { - cd32_shifter[i]--; - if (cd32_shifter[i] < 0) - cd32_shifter[i] = 0; + static int oldstate[2]; + int i; + + cap_check (); + for (i = 0; i < 2; i++) { + uae_u8 but = 0x40 << i; + uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ + uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ + if (!(potgo_value & p5dir) || !(potgo_value & p5dat)) { + if ((dra & but) && (pra & but) != oldstate[i]) { + if (!(pra & but)) { + cd32_shifter[i]--; + if (cd32_shifter[i] < 0) + cd32_shifter[i] = 0; + } + } } - } + oldstate[i] = pra & but; } - oldstate[i] = pra & but; - } } /* joystick port 1 button 2 is input for button state */ static uae_u16 handle_joystick_potgor (uae_u16 potgor) { - int i; - - cap_check (); - for (i = 0; i < 2; i++) { - uae_u16 p9dir = 0x0800 << (i * 4); /* output enable P9 */ - uae_u16 p9dat = 0x0400 << (i * 4); /* data P9 */ - uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ - uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ - - if (cd32_pad_enabled[i]) { - - /* p5 is floating in input-mode */ - potgor &= ~p5dat; - potgor |= potgo_value & p5dat; - if (!(potgo_value & p9dir)) - potgor |= p9dat; - /* P5 output and 1 -> shift register is kept reset (Blue button) */ - if ((potgo_value & p5dir) && (potgo_value & p5dat)) - cd32_shifter[i] = 8; - /* shift at 1 == return one, >1 = return button states */ - if (cd32_shifter[i] == 0) - potgor &= ~p9dat; /* shift at zero == return zero */ - if (cd32_shifter[i] >= 2 && (joybutton[i] & ((1 << JOYBUTTON_CD32_PLAY) << (cd32_shifter[i] - 2)))) - potgor &= ~p9dat; + int i; - } else { + cap_check (); + for (i = 0; i < 2; i++) { + uae_u16 p9dir = 0x0800 << (i * 4); /* output enable P9 */ + uae_u16 p9dat = 0x0400 << (i * 4); /* data P9 */ + uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ + uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ + + if (cd32_pad_enabled[i]) { + + /* p5 is floating in input-mode */ + potgor &= ~p5dat; + potgor |= potgo_value & p5dat; + if (!(potgo_value & p9dir)) + potgor |= p9dat; + /* P5 output and 1 -> shift register is kept reset (Blue button) */ + if ((potgo_value & p5dir) && (potgo_value & p5dat)) + cd32_shifter[i] = 8; + /* shift at 1 == return one, >1 = return button states */ + if (cd32_shifter[i] == 0) + potgor &= ~p9dat; /* shift at zero == return zero */ + if (cd32_shifter[i] >= 2 && (joybutton[i] & ((1 << JOYBUTTON_CD32_PLAY) << (cd32_shifter[i] - 2)))) + potgor &= ~p9dat; + + } else { - potgor &= ~p5dat; - if (pot_cap[i][0] > 100) - potgor |= p5dat; + potgor &= ~p5dat; + if (pot_cap[i][0] > 100) + potgor |= p5dat; - potgor &= ~p9dat; - if (pot_cap[i][1] > 100) - potgor |= p9dat; + potgor &= ~p9dat; + if (pot_cap[i][1] > 100) + potgor |= p9dat; + } } - } - return potgor; + return potgor; } @@ -1949,146 +1949,146 @@ static int inputdelay; void inputdevice_hsync (void) { - static int cnt; - cap_check (); + static int cnt; + cap_check (); #ifdef CATWEASEL - catweasel_hsync (); + catweasel_hsync (); #endif - if ((++cnt & 63) == 63 && handle_msgpump ()) { - idev[IDTYPE_MOUSE].read (); - idev[IDTYPE_JOYSTICK].read (); - idev[IDTYPE_KEYBOARD].read (); - } - if (inputdelay > 0) { - inputdelay--; - if (inputdelay == 0) { - idev[IDTYPE_JOYSTICK].read (); - idev[IDTYPE_KEYBOARD].read (); + if ((++cnt & 63) == 63 && handle_msgpump ()) { + idev[IDTYPE_MOUSE].read (); + idev[IDTYPE_JOYSTICK].read (); + idev[IDTYPE_KEYBOARD].read (); + } + if (inputdelay > 0) { + inputdelay--; + if (inputdelay == 0) { + idev[IDTYPE_JOYSTICK].read (); + idev[IDTYPE_KEYBOARD].read (); + } } - } } static uae_u16 POTDAT (int joy) { - uae_u16 v = (pot_dat[joy][1] << 8) | pot_dat[joy][0]; - if (inputdevice_logging & 16) - write_log (L"POTDAT%d: %04X %08X\n", joy, v, M68K_GETPC); - return v; + uae_u16 v = (pot_dat[joy][1] << 8) | pot_dat[joy][0]; + if (inputdevice_logging & 16) + write_log (L"POTDAT%d: %04X %08X\n", joy, v, M68K_GETPC); + return v; } uae_u16 POT0DAT (void) { - return POTDAT (0); + return POTDAT (0); } uae_u16 POT1DAT (void) { - return POTDAT (1); + return POTDAT (1); } /* direction=input, data pin floating, last connected logic level or previous status - * written when direction was ouput - * otherwise it is currently connected logic level. - * direction=output, data pin is current value, forced to zero if joystick button is pressed - * it takes some tens of microseconds before data pin changes state - */ +* written when direction was ouput +* otherwise it is currently connected logic level. +* direction=output, data pin is current value, forced to zero if joystick button is pressed +* it takes some tens of microseconds before data pin changes state +*/ void POTGO (uae_u16 v) { - int i, j; + int i, j; - if (inputdevice_logging & 16) - write_log (L"POTGO_W: %04X %08X\n", v, M68K_GETPC); + if (inputdevice_logging & 16) + write_log (L"POTGO_W: %04X %08X\n", v, M68K_GETPC); #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"POTGO %04X %s\n", v, debuginfo(0)); + if (notinrom ()) + write_log (L"POTGO %04X %s\n", v, debuginfo(0)); #endif - dongle_potgo (v); - potgo_value = potgo_value & 0x5500; /* keep state of data bits */ - potgo_value |= v & 0xaa00; /* get new direction bits */ - for (i = 0; i < 8; i += 2) { - uae_u16 dir = 0x0200 << i; - if (v & dir) { - uae_u16 data = 0x0100 << i; - potgo_value &= ~data; - potgo_value |= v & data; - } - } - for (i = 0; i < 2; i++) { - if (cd32_pad_enabled[i]) { - uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ - uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ - if ((potgo_value & p5dir) && (potgo_value & p5dat)) - cd32_shifter[i] = 8; - } - } - if (v & 1) { + dongle_potgo (v); + potgo_value = potgo_value & 0x5500; /* keep state of data bits */ + potgo_value |= v & 0xaa00; /* get new direction bits */ + for (i = 0; i < 8; i += 2) { + uae_u16 dir = 0x0200 << i; + if (v & dir) { + uae_u16 data = 0x0100 << i; + potgo_value &= ~data; + potgo_value |= v & data; + } + } for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - pot_dat_act[i][j] = 1; - pot_dat[i][j] = 0; - } + if (cd32_pad_enabled[i]) { + uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */ + uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */ + if ((potgo_value & p5dir) && (potgo_value & p5dat)) + cd32_shifter[i] = 8; + } + } + if (v & 1) { + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + pot_dat_act[i][j] = 1; + pot_dat[i][j] = 0; + } + } } - } } uae_u16 POTGOR (void) { - uae_u16 v; - - v = handle_joystick_potgor (potgo_value) & 0x5500; - v = dongle_potgor (v); + uae_u16 v; + + v = handle_joystick_potgor (potgo_value) & 0x5500; + v = dongle_potgor (v); #ifdef DONGLE_DEBUG - if (notinrom ()) - write_log (L"POTGOR %04X %s\n", v, debuginfo(0)); + if (notinrom ()) + write_log (L"POTGOR %04X %s\n", v, debuginfo(0)); #endif - if (inputdevice_logging & 16) - write_log (L"POTGO_R: %04X %08X %d\n", v, M68K_GETPC, cd32_shifter[1]); - return v; + if (inputdevice_logging & 16) + write_log (L"POTGO_R: %04X %08X %d\n", v, M68K_GETPC, cd32_shifter[1]); + return v; } static int check_input_queue (int event) { - struct input_queue_struct *iq; - int i; - for (i = 0; i < INPUT_QUEUE_SIZE; i++) { - iq = &input_queue[i]; - if (iq->event == event) - return i; - } - return -1; + struct input_queue_struct *iq; + int i; + for (i = 0; i < INPUT_QUEUE_SIZE; i++) { + iq = &input_queue[i]; + if (iq->event == event) + return i; + } + return -1; } static void queue_input_event (int event, int state, int max, int framecnt, int autofire) { - struct input_queue_struct *iq; - int i = check_input_queue (event); - - if (event <= 0) - return; - if (state < 0 && i >= 0) { - iq = &input_queue[i]; - iq->nextframecnt = -1; - iq->framecnt = -1; - iq->event = 0; - if (iq->state == 0) - handle_input_event (event, 0, 1, 0); - } else if (i < 0) { - for (i = 0; i < INPUT_QUEUE_SIZE; i++) { - iq = &input_queue[i]; - if (iq->framecnt < 0) - break; - } - if (i == INPUT_QUEUE_SIZE) { - write_log (L"input queue overflow\n"); - return; + struct input_queue_struct *iq; + int i = check_input_queue (event); + + if (event <= 0) + return; + if (state < 0 && i >= 0) { + iq = &input_queue[i]; + iq->nextframecnt = -1; + iq->framecnt = -1; + iq->event = 0; + if (iq->state == 0) + handle_input_event (event, 0, 1, 0); + } else if (i < 0) { + for (i = 0; i < INPUT_QUEUE_SIZE; i++) { + iq = &input_queue[i]; + if (iq->framecnt < 0) + break; + } + if (i == INPUT_QUEUE_SIZE) { + write_log (L"input queue overflow\n"); + return; + } + iq->event = event; + iq->state = iq->storedstate = state; + iq->max = max; + iq->framecnt = framecnt; + iq->nextframecnt = autofire > 0 ? framecnt : -1; } - iq->event = event; - iq->state = iq->storedstate = state; - iq->max = max; - iq->framecnt = framecnt; - iq->nextframecnt = autofire > 0 ? framecnt : -1; - } } static uae_u8 keybuf[256]; @@ -2096,964 +2096,964 @@ static int inputcode_pending, inputcode_pending_state; void inputdevice_release_all_keys (void) { - int i; + int i; - for (i = 0; i < 0x80; i++) { - if (keybuf[i] != 0) { - keybuf[i] = 0; - record_key (i << 1|1); + for (i = 0; i < 0x80; i++) { + if (keybuf[i] != 0) { + keybuf[i] = 0; + record_key (i << 1|1); + } } - } } void inputdevice_add_inputcode (int code, int state) { - inputcode_pending = code; - inputcode_pending_state = state; + inputcode_pending = code; + inputcode_pending_state = state; } void inputdevice_do_keyboard (int code, int state) { - if (code < 0x80) { - uae_u8 key = code | (state ? 0x00 : 0x80); - keybuf[key & 0x7f] = (key & 0x80) ? 0 : 1; - if (key == AK_RESETWARNING) { - resetwarning_do (0); - return; - } else if ((keybuf[AK_CTRL] || keybuf[AK_RCTRL]) && keybuf[AK_LAMI] && keybuf[AK_RAMI]) { - int r = keybuf[AK_LALT] | keybuf[AK_RALT]; - if (!r && currprefs.cs_resetwarning && resetwarning_do (1)) + if (code < 0x80) { + uae_u8 key = code | (state ? 0x00 : 0x80); + keybuf[key & 0x7f] = (key & 0x80) ? 0 : 1; + if (key == AK_RESETWARNING) { + resetwarning_do (0); + return; + } else if ((keybuf[AK_CTRL] || keybuf[AK_RCTRL]) && keybuf[AK_LAMI] && keybuf[AK_RAMI]) { + int r = keybuf[AK_LALT] | keybuf[AK_RALT]; + if (!r && currprefs.cs_resetwarning && resetwarning_do (1)) + return; + memset (keybuf, 0, sizeof (keybuf)); + uae_reset (r); + } + if (record_key ((uae_u8)((key << 1) | (key >> 7)))) { + if (inputdevice_logging & 1) + write_log (L"Amiga key %02X %d\n", key & 0x7f, key >> 7); + } return; - memset (keybuf, 0, sizeof (keybuf)); - uae_reset (r); - } - if (record_key ((uae_u8)((key << 1) | (key >> 7)))) { - if (inputdevice_logging & 1) - write_log (L"Amiga key %02X %d\n", key & 0x7f, key >> 7); } - return; - } - inputdevice_add_inputcode (code, state); + inputdevice_add_inputcode (code, state); } void inputdevice_handle_inputcode (void) { - static int swapperslot; - int code = inputcode_pending; - int state = inputcode_pending_state; + static int swapperslot; + int code = inputcode_pending; + int state = inputcode_pending_state; - inputcode_pending = 0; - if (code == 0) - return; - if (vpos != 0) - write_log (L"inputcode=%d but vpos = %d", code, vpos); + inputcode_pending = 0; + if (code == 0) + return; + if (vpos != 0) + write_log (L"inputcode=%d but vpos = %d", code, vpos); #ifdef ARCADIA - switch (code) - { - case AKS_ARCADIADIAGNOSTICS: - arcadia_flag &= ~1; - arcadia_flag |= state ? 1 : 0; - break; - case AKS_ARCADIAPLY1: - arcadia_flag &= ~4; - arcadia_flag |= state ? 4 : 0; - break; - case AKS_ARCADIAPLY2: - arcadia_flag &= ~2; - arcadia_flag |= state ? 2 : 0; - break; - case AKS_ARCADIACOIN1: - if (state) - arcadia_coin[0]++; - break; - case AKS_ARCADIACOIN2: - if (state) - arcadia_coin[1]++; - break; - } + switch (code) + { + case AKS_ARCADIADIAGNOSTICS: + arcadia_flag &= ~1; + arcadia_flag |= state ? 1 : 0; + break; + case AKS_ARCADIAPLY1: + arcadia_flag &= ~4; + arcadia_flag |= state ? 4 : 0; + break; + case AKS_ARCADIAPLY2: + arcadia_flag &= ~2; + arcadia_flag |= state ? 2 : 0; + break; + case AKS_ARCADIACOIN1: + if (state) + arcadia_coin[0]++; + break; + case AKS_ARCADIACOIN2: + if (state) + arcadia_coin[1]++; + break; + } #endif - if (!state) - return; - switch (code) - { - case AKS_ENTERGUI: - gui_display (-1); - break; - case AKS_SCREENSHOT: - screenshot (1, 1); - break; + if (!state) + return; + switch (code) + { + case AKS_ENTERGUI: + gui_display (-1); + break; + case AKS_SCREENSHOT: + screenshot (1, 1); + break; #ifdef ACTION_REPLAY - case AKS_FREEZEBUTTON: - action_replay_freeze (); - break; + case AKS_FREEZEBUTTON: + action_replay_freeze (); + break; #endif - case AKS_FLOPPY0: - gui_display (0); - break; - case AKS_FLOPPY1: - gui_display (1); - break; - case AKS_FLOPPY2: - gui_display (2); - break; - case AKS_FLOPPY3: - gui_display (3); - break; - case AKS_EFLOPPY0: - disk_eject (0); - break; - case AKS_EFLOPPY1: - disk_eject (1); - break; - case AKS_EFLOPPY2: - disk_eject (2); - break; - case AKS_EFLOPPY3: - disk_eject (3); - break; - case AKS_IRQ7: - NMI_delayed (); - break; - case AKS_PAUSE: - pausemode (-1); - break; - case AKS_WARP: - warpmode (-1); - break; - case AKS_INHIBITSCREEN: - toggle_inhibit_frame (IHF_SCROLLLOCK); - break; - case AKS_STATEREWIND: - savestate_dorewind(1); - break; - case AKS_VOLDOWN: - sound_volume (-1); - break; - case AKS_VOLUP: - sound_volume (1); - break; - case AKS_VOLMUTE: - sound_mute (-1); - break; - case AKS_MVOLDOWN: - master_sound_volume (-1); - break; - case AKS_MVOLUP: - master_sound_volume (1); - break; - case AKS_MVOLMUTE: - master_sound_volume (0); - break; - case AKS_QUIT: - uae_quit (); - break; - case AKS_SOFTRESET: - uae_reset (0); - break; - case AKS_HARDRESET: - uae_reset (1); - break; - case AKS_STATESAVEQUICK: - case AKS_STATESAVEQUICK1: - case AKS_STATESAVEQUICK2: - case AKS_STATESAVEQUICK3: - case AKS_STATESAVEQUICK4: - case AKS_STATESAVEQUICK5: - case AKS_STATESAVEQUICK6: - case AKS_STATESAVEQUICK7: - case AKS_STATESAVEQUICK8: - case AKS_STATESAVEQUICK9: - savestate_quick ((code - AKS_STATESAVEQUICK) / 2, 1); - break; - case AKS_STATERESTOREQUICK: - case AKS_STATERESTOREQUICK1: - case AKS_STATERESTOREQUICK2: - case AKS_STATERESTOREQUICK3: - case AKS_STATERESTOREQUICK4: - case AKS_STATERESTOREQUICK5: - case AKS_STATERESTOREQUICK6: - case AKS_STATERESTOREQUICK7: - case AKS_STATERESTOREQUICK8: - case AKS_STATERESTOREQUICK9: - savestate_quick ((code - AKS_STATERESTOREQUICK) / 2, 0); - break; - case AKS_TOGGLEFULLSCREEN: - toggle_fullscreen (); - break; - case AKS_TOGGLEMOUSEGRAB: - toggle_mousegrab (); - break; - case AKS_ENTERDEBUGGER: - activate_debugger (); - break; - case AKS_STATESAVEDIALOG: - gui_display (5); - break; + case AKS_FLOPPY0: + gui_display (0); + break; + case AKS_FLOPPY1: + gui_display (1); + break; + case AKS_FLOPPY2: + gui_display (2); + break; + case AKS_FLOPPY3: + gui_display (3); + break; + case AKS_EFLOPPY0: + disk_eject (0); + break; + case AKS_EFLOPPY1: + disk_eject (1); + break; + case AKS_EFLOPPY2: + disk_eject (2); + break; + case AKS_EFLOPPY3: + disk_eject (3); + break; + case AKS_IRQ7: + NMI_delayed (); + break; + case AKS_PAUSE: + pausemode (-1); + break; + case AKS_WARP: + warpmode (-1); + break; + case AKS_INHIBITSCREEN: + toggle_inhibit_frame (IHF_SCROLLLOCK); + break; + case AKS_STATEREWIND: + savestate_dorewind(1); + break; + case AKS_VOLDOWN: + sound_volume (-1); + break; + case AKS_VOLUP: + sound_volume (1); + break; + case AKS_VOLMUTE: + sound_mute (-1); + break; + case AKS_MVOLDOWN: + master_sound_volume (-1); + break; + case AKS_MVOLUP: + master_sound_volume (1); + break; + case AKS_MVOLMUTE: + master_sound_volume (0); + break; + case AKS_QUIT: + uae_quit (); + break; + case AKS_SOFTRESET: + uae_reset (0); + break; + case AKS_HARDRESET: + uae_reset (1); + break; + case AKS_STATESAVEQUICK: + case AKS_STATESAVEQUICK1: + case AKS_STATESAVEQUICK2: + case AKS_STATESAVEQUICK3: + case AKS_STATESAVEQUICK4: + case AKS_STATESAVEQUICK5: + case AKS_STATESAVEQUICK6: + case AKS_STATESAVEQUICK7: + case AKS_STATESAVEQUICK8: + case AKS_STATESAVEQUICK9: + savestate_quick ((code - AKS_STATESAVEQUICK) / 2, 1); + break; + case AKS_STATERESTOREQUICK: + case AKS_STATERESTOREQUICK1: + case AKS_STATERESTOREQUICK2: + case AKS_STATERESTOREQUICK3: + case AKS_STATERESTOREQUICK4: + case AKS_STATERESTOREQUICK5: + case AKS_STATERESTOREQUICK6: + case AKS_STATERESTOREQUICK7: + case AKS_STATERESTOREQUICK8: + case AKS_STATERESTOREQUICK9: + savestate_quick ((code - AKS_STATERESTOREQUICK) / 2, 0); + break; + case AKS_TOGGLEFULLSCREEN: + toggle_fullscreen (); + break; + case AKS_TOGGLEMOUSEGRAB: + toggle_mousegrab (); + break; + case AKS_ENTERDEBUGGER: + activate_debugger (); + break; + case AKS_STATESAVEDIALOG: + gui_display (5); + break; case AKS_STATERESTOREDIALOG: - gui_display (4); - break; - case AKS_DECREASEREFRESHRATE: - case AKS_INCREASEREFRESHRATE: - { - int dir = code == AKS_INCREASEREFRESHRATE ? 5 : -5; - if (currprefs.chipset_refreshrate == 0) - currprefs.chipset_refreshrate = currprefs.ntscmode ? 60 : 50; - changed_prefs.chipset_refreshrate = currprefs.chipset_refreshrate + dir; - if (changed_prefs.chipset_refreshrate < 10) - changed_prefs.chipset_refreshrate = 10; - if (changed_prefs.chipset_refreshrate > 900) - changed_prefs.chipset_refreshrate = 900; - } - break; - case AKS_DISKSWAPPER_NEXT: - swapperslot++; - if (swapperslot >= MAX_SPARE_DRIVES || currprefs.dfxlist[swapperslot][0] == 0) - swapperslot = 0; - break; - case AKS_DISKSWAPPER_PREV: - swapperslot--; - if (swapperslot < 0) - swapperslot = MAX_SPARE_DRIVES - 1; - while (swapperslot > 0) { - if (currprefs.dfxlist[swapperslot][0]) + gui_display (4); break; - swapperslot--; - } - break; - case AKS_DISKSWAPPER_INSERT0: - case AKS_DISKSWAPPER_INSERT1: - case AKS_DISKSWAPPER_INSERT2: - case AKS_DISKSWAPPER_INSERT3: - _tcscpy (changed_prefs.df[code - AKS_DISKSWAPPER_INSERT0], currprefs.dfxlist[swapperslot]); - break; - - break; - case AKS_INPUT_CONFIG_1: - case AKS_INPUT_CONFIG_2: - case AKS_INPUT_CONFIG_3: - case AKS_INPUT_CONFIG_4: - changed_prefs.input_selected_setting = currprefs.input_selected_setting = code - AKS_INPUT_CONFIG_1 + 1; - inputdevice_updateconfig (&currprefs); - break; - } + case AKS_DECREASEREFRESHRATE: + case AKS_INCREASEREFRESHRATE: + { + int dir = code == AKS_INCREASEREFRESHRATE ? 5 : -5; + if (currprefs.chipset_refreshrate == 0) + currprefs.chipset_refreshrate = currprefs.ntscmode ? 60 : 50; + changed_prefs.chipset_refreshrate = currprefs.chipset_refreshrate + dir; + if (changed_prefs.chipset_refreshrate < 10) + changed_prefs.chipset_refreshrate = 10; + if (changed_prefs.chipset_refreshrate > 900) + changed_prefs.chipset_refreshrate = 900; + } + break; + case AKS_DISKSWAPPER_NEXT: + swapperslot++; + if (swapperslot >= MAX_SPARE_DRIVES || currprefs.dfxlist[swapperslot][0] == 0) + swapperslot = 0; + break; + case AKS_DISKSWAPPER_PREV: + swapperslot--; + if (swapperslot < 0) + swapperslot = MAX_SPARE_DRIVES - 1; + while (swapperslot > 0) { + if (currprefs.dfxlist[swapperslot][0]) + break; + swapperslot--; + } + break; + case AKS_DISKSWAPPER_INSERT0: + case AKS_DISKSWAPPER_INSERT1: + case AKS_DISKSWAPPER_INSERT2: + case AKS_DISKSWAPPER_INSERT3: + _tcscpy (changed_prefs.df[code - AKS_DISKSWAPPER_INSERT0], currprefs.dfxlist[swapperslot]); + break; + + break; + case AKS_INPUT_CONFIG_1: + case AKS_INPUT_CONFIG_2: + case AKS_INPUT_CONFIG_3: + case AKS_INPUT_CONFIG_4: + changed_prefs.input_selected_setting = currprefs.input_selected_setting = code - AKS_INPUT_CONFIG_1 + 1; + inputdevice_updateconfig (&currprefs); + break; + } } int handle_custom_event (TCHAR *custom) { - TCHAR *p, *buf, *nextp; + TCHAR *p, *buf, *nextp; - if (custom == NULL) + if (custom == NULL) + return 0; + p = buf = my_strdup (custom); + while (p && *p) { + TCHAR *p2; + if (*p != '\"') + break; + p++; + p2 = p; + while (*p2 != '\"' && *p2 != 0) + p2++; + if (*p2 == '\"') { + *p2++ = 0; + nextp = p2 + 1; + while (*nextp == ' ') + nextp++; + } + cfgfile_parse_line (&changed_prefs, p, 0); + p = nextp; + } + xfree(buf); return 0; - p = buf = my_strdup (custom); - while (p && *p) { - TCHAR *p2; - if (*p != '\"') - break; - p++; - p2 = p; - while (*p2 != '\"' && *p2 != 0) - p2++; - if (*p2 == '\"') { - *p2++ = 0; - nextp = p2 + 1; - while (*nextp == ' ') - nextp++; - } - cfgfile_parse_line (&changed_prefs, p, 0); - p = nextp; - } - xfree(buf); - return 0; } int handle_input_event (int nr, int state, int max, int autofire) { - struct inputevent *ie; - int joy; + struct inputevent *ie; + int joy; - if (nr <= 0) - return 0; - ie = &events[nr]; - if (inputdevice_logging & 1) - write_log (L"'%s' %d %d\n", ie->name, state, max); - if (autofire) { - if (state) - queue_input_event (nr, state, max, currprefs.input_autofire_framecnt, 1); - else - queue_input_event (nr, -1, 0, 0, 1); - } - switch (ie->unit) - { - case 5: /* lightpen/gun */ - { - if (lightpen_x < 0 && lightpen_y < 0) { - lightpen_x = gfxvidinfo.width / 2; - lightpen_y = gfxvidinfo.height / 2; - } - if (ie->type == 0) { - int delta = 0; - if (max == 0) - delta = state * currprefs.input_mouse_speed / 100; - else if (state > 0) - delta = currprefs.input_joymouse_speed; - else if (state < 0) - delta = -currprefs.input_joymouse_speed; - if (ie->data) - lightpen_y += delta; + if (nr <= 0) + return 0; + ie = &events[nr]; + if (inputdevice_logging & 1) + write_log (L"'%s' %d %d\n", ie->name, state, max); + if (autofire) { + if (state) + queue_input_event (nr, state, max, currprefs.input_autofire_framecnt, 1); else - lightpen_x += delta; - } else { - int delta = currprefs.input_joymouse_speed; - if (ie->data & DIR_LEFT) - lightpen_x -= delta; - if (ie->data & DIR_RIGHT) - lightpen_x += delta; - if (ie->data & DIR_UP) - lightpen_y -= delta; - if (ie->data & DIR_DOWN) - lightpen_y += delta; - } - } - break; + queue_input_event (nr, -1, 0, 0, 1); + } + switch (ie->unit) + { + case 5: /* lightpen/gun */ + { + if (lightpen_x < 0 && lightpen_y < 0) { + lightpen_x = gfxvidinfo.width / 2; + lightpen_y = gfxvidinfo.height / 2; + } + if (ie->type == 0) { + int delta = 0; + if (max == 0) + delta = state * currprefs.input_mouse_speed / 100; + else if (state > 0) + delta = currprefs.input_joymouse_speed; + else if (state < 0) + delta = -currprefs.input_joymouse_speed; + if (ie->data) + lightpen_y += delta; + else + lightpen_x += delta; + } else { + int delta = currprefs.input_joymouse_speed; + if (ie->data & DIR_LEFT) + lightpen_x -= delta; + if (ie->data & DIR_RIGHT) + lightpen_x += delta; + if (ie->data & DIR_UP) + lightpen_y -= delta; + if (ie->data & DIR_DOWN) + lightpen_y += delta; + } + } + break; case 1: /* ->JOY1 */ case 2: /* ->JOY2 */ case 3: /* ->Parallel port joystick adapter port #1 */ case 4: /* ->Parallel port joystick adapter port #2 */ - joy = ie->unit - 1; - if (ie->type & 4) { + joy = ie->unit - 1; + if (ie->type & 4) { - if (state) - joybutton[joy] |= 1 << ie->data; - else - joybutton[joy] &= ~(1 << ie->data); - - } else if (ie->type & 8) { - - /* real mouse / analog stick mouse emulation */ - int delta; - int deadzone = currprefs.input_joymouse_deadzone * max / 100; - int unit = ie->data & 0x7f; - - if (max) { - if (state <= deadzone && state >= -deadzone) { - state = 0; - mouse_deltanoreset[joy][unit] = 0; - } else if (state < 0) { - state += deadzone; - mouse_deltanoreset[joy][unit] = 1; - } else { - state -= deadzone; - mouse_deltanoreset[joy][unit] = 1; - } - max -= deadzone; - delta = state * currprefs.input_joymouse_multiplier / max; - } else { - delta = state; - mouse_deltanoreset[joy][unit] = 0; - } - if (ie->data & IE_CDTV) { - delta = 0; - if (state > 0) - delta = JOYMOUSE_CDTV; - else if (state < 0) - delta = -JOYMOUSE_CDTV; - } + if (state) + joybutton[joy] |= 1 << ie->data; + else + joybutton[joy] &= ~(1 << ie->data); + + } else if (ie->type & 8) { + + /* real mouse / analog stick mouse emulation */ + int delta; + int deadzone = currprefs.input_joymouse_deadzone * max / 100; + int unit = ie->data & 0x7f; + + if (max) { + if (state <= deadzone && state >= -deadzone) { + state = 0; + mouse_deltanoreset[joy][unit] = 0; + } else if (state < 0) { + state += deadzone; + mouse_deltanoreset[joy][unit] = 1; + } else { + state -= deadzone; + mouse_deltanoreset[joy][unit] = 1; + } + max -= deadzone; + delta = state * currprefs.input_joymouse_multiplier / max; + } else { + delta = state; + mouse_deltanoreset[joy][unit] = 0; + } + if (ie->data & IE_CDTV) { + delta = 0; + if (state > 0) + delta = JOYMOUSE_CDTV; + else if (state < 0) + delta = -JOYMOUSE_CDTV; + } + + mouse_delta[joy][unit] += delta * ((ie->data & IE_INVERT) ? -1 : 1); + + } else if (ie->type & 32) { /* button mouse emulation vertical */ + + int speed = (ie->data & IE_CDTV) ? JOYMOUSE_CDTV : currprefs.input_joymouse_speed; + + if (state && (ie->data & DIR_UP)) { + mouse_delta[joy][1] = -speed; + mouse_deltanoreset[joy][1] = 1; + } else if (state && (ie->data & DIR_DOWN)) { + mouse_delta[joy][1] = speed; + mouse_deltanoreset[joy][1] = 1; + } else + mouse_deltanoreset[joy][1] = 0; + + } else if (ie->type & 64) { /* button mouse emulation horizontal */ + + int speed = (ie->data & IE_CDTV) ? JOYMOUSE_CDTV : currprefs.input_joymouse_speed; + + if (state && (ie->data & DIR_LEFT)) { + mouse_delta[joy][0] = -speed; + mouse_deltanoreset[joy][0] = 1; + } else if (state && (ie->data & DIR_RIGHT)) { + mouse_delta[joy][0] = speed; + mouse_deltanoreset[joy][0] = 1; + } else + mouse_deltanoreset[joy][0] = 0; + + } else if (ie->type & 128) { /* analog joystick / paddle */ + + int deadzone = currprefs.input_joymouse_deadzone * max / 100; + int unit = ie->data & 0x7f; + if (max) { + if (state <= deadzone && state >= -deadzone) { + state = 0; + } else if (state < 0) { + state += deadzone; + } else { + state -= deadzone; + } + state = state * max / (max - deadzone); + } + if (ie->data & IE_INVERT) + state = -state; + state = state * currprefs.input_analog_joystick_mult / max; + state += (128 * currprefs.input_analog_joystick_mult / 100) + currprefs.input_analog_joystick_offset; + if (state < 0) + state = 0; + if (state > 255) + state = 255; + joydirpot[joy][unit] = state; - mouse_delta[joy][unit] += delta * ((ie->data & IE_INVERT) ? -1 : 1); - - } else if (ie->type & 32) { /* button mouse emulation vertical */ - - int speed = (ie->data & IE_CDTV) ? JOYMOUSE_CDTV : currprefs.input_joymouse_speed; - - if (state && (ie->data & DIR_UP)) { - mouse_delta[joy][1] = -speed; - mouse_deltanoreset[joy][1] = 1; - } else if (state && (ie->data & DIR_DOWN)) { - mouse_delta[joy][1] = speed; - mouse_deltanoreset[joy][1] = 1; - } else - mouse_deltanoreset[joy][1] = 0; - - } else if (ie->type & 64) { /* button mouse emulation horizontal */ - - int speed = (ie->data & IE_CDTV) ? JOYMOUSE_CDTV : currprefs.input_joymouse_speed; - - if (state && (ie->data & DIR_LEFT)) { - mouse_delta[joy][0] = -speed; - mouse_deltanoreset[joy][0] = 1; - } else if (state && (ie->data & DIR_RIGHT)) { - mouse_delta[joy][0] = speed; - mouse_deltanoreset[joy][0] = 1; - } else - mouse_deltanoreset[joy][0] = 0; - - } else if (ie->type & 128) { /* analog joystick / paddle */ - - int deadzone = currprefs.input_joymouse_deadzone * max / 100; - int unit = ie->data & 0x7f; - if (max) { - if (state <= deadzone && state >= -deadzone) { - state = 0; - } else if (state < 0) { - state += deadzone; - } else { - state -= deadzone; - } - state = state * max / (max - deadzone); - } - if (ie->data & IE_INVERT) - state = -state; - state = state * currprefs.input_analog_joystick_mult / max; - state += (128 * currprefs.input_analog_joystick_mult / 100) + currprefs.input_analog_joystick_offset; - if (state < 0) - state = 0; - if (state > 255) - state = 255; - joydirpot[joy][unit] = state; - - } else { - - int left = oleft[joy], right = oright[joy], top = otop[joy], bot = obot[joy]; - if (ie->type & 16) { - /* button to axis mapping */ - if (ie->data & DIR_LEFT) - left = oleft[joy] = state ? 1 : 0; - if (ie->data & DIR_RIGHT) - right = oright[joy] = state ? 1 : 0; - if (ie->data & DIR_UP) - top = otop[joy] = state ? 1 : 0; - if (ie->data & DIR_DOWN) - bot = obot[joy] = state ? 1 : 0; } else { - /* "normal" joystick axis */ - int deadzone = currprefs.input_joystick_deadzone * max / 100; - int neg, pos; - if (state < deadzone && state > -deadzone) - state = 0; - neg = state < 0 ? 1 : 0; - pos = state > 0 ? 1 : 0; - if (ie->data & DIR_LEFT) - left = oleft[joy] = neg; - if (ie->data & DIR_RIGHT) - right = oright[joy] = pos; - if (ie->data & DIR_UP) - top = otop[joy] = neg; - if (ie->data & DIR_DOWN) - bot = obot[joy] = pos; + + int left = oleft[joy], right = oright[joy], top = otop[joy], bot = obot[joy]; + if (ie->type & 16) { + /* button to axis mapping */ + if (ie->data & DIR_LEFT) + left = oleft[joy] = state ? 1 : 0; + if (ie->data & DIR_RIGHT) + right = oright[joy] = state ? 1 : 0; + if (ie->data & DIR_UP) + top = otop[joy] = state ? 1 : 0; + if (ie->data & DIR_DOWN) + bot = obot[joy] = state ? 1 : 0; + } else { + /* "normal" joystick axis */ + int deadzone = currprefs.input_joystick_deadzone * max / 100; + int neg, pos; + if (state < deadzone && state > -deadzone) + state = 0; + neg = state < 0 ? 1 : 0; + pos = state > 0 ? 1 : 0; + if (ie->data & DIR_LEFT) + left = oleft[joy] = neg; + if (ie->data & DIR_RIGHT) + right = oright[joy] = pos; + if (ie->data & DIR_UP) + top = otop[joy] = neg; + if (ie->data & DIR_DOWN) + bot = obot[joy] = pos; + } + joydir[joy] = 0; + if (left) + joydir[joy] |= DIR_LEFT; + if (right) + joydir[joy] |= DIR_RIGHT; + if (top) + joydir[joy] |= DIR_UP; + if (bot) + joydir[joy] |= DIR_DOWN; + } - joydir[joy] = 0; - if (left) - joydir[joy] |= DIR_LEFT; - if (right) - joydir[joy] |= DIR_RIGHT; - if (top) - joydir[joy] |= DIR_UP; - if (bot) - joydir[joy] |= DIR_DOWN; - - } - break; + break; case 0: /* ->KEY */ - inputdevice_do_keyboard (ie->data, state); - break; - } - return 1; + inputdevice_do_keyboard (ie->data, state); + break; + } + return 1; } static void inputdevice_checkconfig (void) { - if (currprefs.jports[0].id != changed_prefs.jports[0].id || - currprefs.jports[1].id != changed_prefs.jports[1].id || - currprefs.jports[2].id != changed_prefs.jports[2].id || - currprefs.jports[3].id != changed_prefs.jports[3].id || - currprefs.input_selected_setting != changed_prefs.input_selected_setting || - currprefs.input_joymouse_multiplier != changed_prefs.input_joymouse_multiplier || - currprefs.input_joymouse_deadzone != changed_prefs.input_joymouse_deadzone || - currprefs.input_joystick_deadzone != changed_prefs.input_joystick_deadzone || - currprefs.input_joymouse_speed != changed_prefs.input_joymouse_speed || - currprefs.input_autofire_framecnt != changed_prefs.input_autofire_framecnt || - currprefs.input_mouse_speed != changed_prefs.input_mouse_speed) { - - currprefs.input_selected_setting = changed_prefs.input_selected_setting; - currprefs.input_joymouse_multiplier = changed_prefs.input_joymouse_multiplier; - currprefs.input_joymouse_deadzone = changed_prefs.input_joymouse_deadzone; - currprefs.input_joystick_deadzone = changed_prefs.input_joystick_deadzone; - currprefs.input_joymouse_speed = changed_prefs.input_joymouse_speed; - currprefs.input_autofire_framecnt = changed_prefs.input_autofire_framecnt; - currprefs.input_mouse_speed = changed_prefs.input_mouse_speed; - - inputdevice_updateconfig (&currprefs); - } - if (currprefs.dongle != changed_prefs.dongle) { - currprefs.dongle = changed_prefs.dongle; - dongle_reset (); - } + if (currprefs.jports[0].id != changed_prefs.jports[0].id || + currprefs.jports[1].id != changed_prefs.jports[1].id || + currprefs.jports[2].id != changed_prefs.jports[2].id || + currprefs.jports[3].id != changed_prefs.jports[3].id || + currprefs.input_selected_setting != changed_prefs.input_selected_setting || + currprefs.input_joymouse_multiplier != changed_prefs.input_joymouse_multiplier || + currprefs.input_joymouse_deadzone != changed_prefs.input_joymouse_deadzone || + currprefs.input_joystick_deadzone != changed_prefs.input_joystick_deadzone || + currprefs.input_joymouse_speed != changed_prefs.input_joymouse_speed || + currprefs.input_autofire_framecnt != changed_prefs.input_autofire_framecnt || + currprefs.input_mouse_speed != changed_prefs.input_mouse_speed) { + + currprefs.input_selected_setting = changed_prefs.input_selected_setting; + currprefs.input_joymouse_multiplier = changed_prefs.input_joymouse_multiplier; + currprefs.input_joymouse_deadzone = changed_prefs.input_joymouse_deadzone; + currprefs.input_joystick_deadzone = changed_prefs.input_joystick_deadzone; + currprefs.input_joymouse_speed = changed_prefs.input_joymouse_speed; + currprefs.input_autofire_framecnt = changed_prefs.input_autofire_framecnt; + currprefs.input_mouse_speed = changed_prefs.input_mouse_speed; + + inputdevice_updateconfig (&currprefs); + } + if (currprefs.dongle != changed_prefs.dongle) { + currprefs.dongle = changed_prefs.dongle; + dongle_reset (); + } } void inputdevice_vsync (void) { - struct input_queue_struct *iq; - int i; + struct input_queue_struct *iq; + int i; - if (inputdevice_logging & 32) - write_log (L"*\n"); + if (inputdevice_logging & 32) + write_log (L"*\n"); - for (i = 0; i < INPUT_QUEUE_SIZE; i++) { - iq = &input_queue[i]; - if (iq->framecnt > 0) { - iq->framecnt--; - if (iq->framecnt == 0) { - if (iq->state) - iq->state = 0; - else - iq->state = iq->storedstate; - handle_input_event (iq->event, iq->state, iq->max, 0); - iq->framecnt = iq->nextframecnt; - } - } - } - - input_frame++; - mouseupdate (0, 1); - idev[IDTYPE_MOUSE].read (); - idev[IDTYPE_JOYSTICK].read (); - - inputdelay = uaerand () % (maxvpos <= 1 ? 1 : maxvpos - 1); - inputdevice_handle_inputcode (); - if (mouseedge_alive > 0) - mouseedge_alive--; + for (i = 0; i < INPUT_QUEUE_SIZE; i++) { + iq = &input_queue[i]; + if (iq->framecnt > 0) { + iq->framecnt--; + if (iq->framecnt == 0) { + if (iq->state) + iq->state = 0; + else + iq->state = iq->storedstate; + handle_input_event (iq->event, iq->state, iq->max, 0); + iq->framecnt = iq->nextframecnt; + } + } + } + + input_frame++; + mouseupdate (0, 1); + idev[IDTYPE_MOUSE].read (); + idev[IDTYPE_JOYSTICK].read (); + + inputdelay = uaerand () % (maxvpos <= 1 ? 1 : maxvpos - 1); + inputdevice_handle_inputcode (); + if (mouseedge_alive > 0) + mouseedge_alive--; #ifdef ARCADIA - if (arcadia_bios) - arcadia_vsync (); + if (arcadia_bios) + arcadia_vsync (); #endif - if (mouseedge ()) - mouseedge_alive = 10; - if (mousehack_alive_cnt > 0) { - mousehack_alive_cnt--; - if (mousehack_alive_cnt == 0) - setmouseactive (-1); - } else if (mousehack_alive_cnt < 0) { - mousehack_alive_cnt++; - if (mousehack_alive_cnt == 0) { - mousehack_alive_cnt = 100; - setmouseactive (0); - setmouseactive (1); - } - } - inputdevice_checkconfig (); + if (mouseedge ()) + mouseedge_alive = 10; + if (mousehack_alive_cnt > 0) { + mousehack_alive_cnt--; + if (mousehack_alive_cnt == 0) + setmouseactive (-1); + } else if (mousehack_alive_cnt < 0) { + mousehack_alive_cnt++; + if (mousehack_alive_cnt == 0) { + mousehack_alive_cnt = 100; + setmouseactive (0); + setmouseactive (1); + } + } + inputdevice_checkconfig (); } void inputdevice_reset (void) { - magicmouse_ibase = 0; - magicmouse_gfxbase = 0; - mousehack_reset (); - if (inputdevice_is_tablet ()) - mousehack_enable (); + magicmouse_ibase = 0; + magicmouse_gfxbase = 0; + mousehack_reset (); + if (inputdevice_is_tablet ()) + mousehack_enable (); } static int getoldport (struct uae_input_device *id) { - int i, j; + int i, j; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - int evt = id->eventid[i][j]; - if (evt > 0) { - int unit = events[evt].unit; - if (unit >= 1 && unit <= 4) - return unit; - } + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + int evt = id->eventid[i][j]; + if (evt > 0) { + int unit = events[evt].unit; + if (unit >= 1 && unit <= 4) + return unit; + } + } } - } - return -1; + return -1; } static int switchdevice (struct uae_input_device *id, int num, int button) { - int i, j; - int ismouse = 0; - int newport = 0; - int flags = 0; - TCHAR *name = NULL; - int otherbuttonpressed = 0; + int i, j; + int ismouse = 0; + int newport = 0; + int flags = 0; + TCHAR *name = NULL; + int otherbuttonpressed = 0; - if (num >= 4) - return 0; - if (!button) - return 0; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (id == &joysticks[i]) { - name = idev[IDTYPE_JOYSTICK].get_uniquename (i); - newport = num == 0 ? 1 : 0; - flags = idev[IDTYPE_JOYSTICK].get_flags (i); - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - if (j != i) { - struct uae_input_device2 *id2 = &joysticks2[j]; - if (id2->buttonmask) - otherbuttonpressed = 1; + if (num >= 4) + return 0; + if (!button) + return 0; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + if (id == &joysticks[i]) { + name = idev[IDTYPE_JOYSTICK].get_uniquename (i); + newport = num == 0 ? 1 : 0; + flags = idev[IDTYPE_JOYSTICK].get_flags (i); + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + if (j != i) { + struct uae_input_device2 *id2 = &joysticks2[j]; + if (id2->buttonmask) + otherbuttonpressed = 1; + } + } + } + if (id == &mice[i]) { + ismouse = 1; + name = idev[IDTYPE_MOUSE].get_uniquename (i); + newport = num == 0 ? 0 : 1; + flags = idev[IDTYPE_MOUSE].get_flags (i); } - } - } - if (id == &mice[i]) { - ismouse = 1; - name = idev[IDTYPE_MOUSE].get_uniquename (i); - newport = num == 0 ? 0 : 1; - flags = idev[IDTYPE_MOUSE].get_flags (i); } - } - if (!name) - return 0; - if (num == 0 && otherbuttonpressed) - newport = newport ? 0 : 1; - if (!currprefs.input_selected_setting) { - if (num == 0 || num == 1) { - int om = jsem_ismouse (num, &currprefs); - int om1 = jsem_ismouse (0, &currprefs); - int om2 = jsem_ismouse (1, &currprefs); - if ((om1 >= 0 || om2 >= 0) && ismouse) + if (!name) return 0; - if (flags) + if (num == 0 && otherbuttonpressed) + newport = newport ? 0 : 1; + if (!currprefs.input_selected_setting) { + if (num == 0 || num == 1) { + int om = jsem_ismouse (num, &currprefs); + int om1 = jsem_ismouse (0, &currprefs); + int om2 = jsem_ismouse (1, &currprefs); + if ((om1 >= 0 || om2 >= 0) && ismouse) + return 0; + if (flags) + return 0; + if (name) { + write_log (L"inputdevice change '%s':%d->%d\n", name, num, newport); + inputdevice_joyport_config (&changed_prefs, name, newport, -1, 2); + inputdevice_copyconfig (&changed_prefs, &currprefs); + return 1; + } + } return 0; - if (name) { - write_log (L"inputdevice change '%s':%d->%d\n", name, num, newport); - inputdevice_joyport_config (&changed_prefs, name, newport, -1, 2); - inputdevice_copyconfig (&changed_prefs, &currprefs); - return 1; - } - } - return 0; - } else { - int oldport = getoldport (id); - int i, j, k, evt; - struct inputevent *ie, *ie2; - - if (flags) - return 0; - if (oldport <= 0) - return 0; - newport++; - /* do not switch if switching mouse and any "supermouse" mouse enabled */ - if (ismouse) { - for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { - if (mice[i].enabled && idev[IDTYPE_MOUSE].get_flags (i)) - return 0; - } - } - for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { - if (getoldport (&joysticks[i]) == newport) - joysticks[i].enabled = 0; - if (getoldport (&mice[i]) == newport) - mice[i].enabled = 0; - } - id->enabled = 1; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - evt = id->eventid[i][j]; - if (evt <= 0) - continue; - ie = &events[evt]; - if (ie->unit == oldport) { - k = 1; - while (events[k].confname) { - ie2 = &events[k]; - if (ie2->type == ie->type && ie2->data == ie->data && ie2->allow_mask == ie->allow_mask && ie2->unit == newport) { - id->eventid[i][j] = k; - break; + } else { + int oldport = getoldport (id); + int i, j, k, evt; + struct inputevent *ie, *ie2; + + if (flags) + return 0; + if (oldport <= 0) + return 0; + newport++; + /* do not switch if switching mouse and any "supermouse" mouse enabled */ + if (ismouse) { + for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { + if (mice[i].enabled && idev[IDTYPE_MOUSE].get_flags (i)) + return 0; } - k++; - } - } else if (ie->unit == newport) { - k = 1; - while (events[k].confname) { - ie2 = &events[k]; - if (ie2->type == ie->type && ie2->data == ie->data && ie2->allow_mask == ie->allow_mask && ie2->unit == oldport) { - id->eventid[i][j] = k; - break; + } + for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { + if (getoldport (&joysticks[i]) == newport) + joysticks[i].enabled = 0; + if (getoldport (&mice[i]) == newport) + mice[i].enabled = 0; + } + id->enabled = 1; + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + evt = id->eventid[i][j]; + if (evt <= 0) + continue; + ie = &events[evt]; + if (ie->unit == oldport) { + k = 1; + while (events[k].confname) { + ie2 = &events[k]; + if (ie2->type == ie->type && ie2->data == ie->data && ie2->allow_mask == ie->allow_mask && ie2->unit == newport) { + id->eventid[i][j] = k; + break; + } + k++; + } + } else if (ie->unit == newport) { + k = 1; + while (events[k].confname) { + ie2 = &events[k]; + if (ie2->type == ie->type && ie2->data == ie->data && ie2->allow_mask == ie->allow_mask && ie2->unit == oldport) { + id->eventid[i][j] = k; + break; + } + k++; + } + } } - k++; - } } - } + write_log (L"inputdevice change '%s':%d->%d\n", name, num, newport); + inputdevice_copyconfig (&currprefs, &changed_prefs); + inputdevice_copyconfig (&changed_prefs, &currprefs); + return 1; } - write_log (L"inputdevice change '%s':%d->%d\n", name, num, newport); - inputdevice_copyconfig (&currprefs, &changed_prefs); - inputdevice_copyconfig (&changed_prefs, &currprefs); - return 1; - } - return 0; + return 0; } static void process_custom_event (struct uae_input_device *id, int offset, int state) { - int idx = -1; - int custompos = (id->flags[offset][0] >> 15) & 1; - TCHAR *custom; - - if (state < 0) { - idx = 0; - custompos = 0; - } else { - idx = state > 0 ? 0 : 1; - if (custompos) - idx += 2; - if (state == 0) - custompos ^= 1; - } - custom = id->custom[offset][idx]; - if (custom == NULL) { - if (idx >= 2) - custom = id->custom[offset][idx - 2]; - } - handle_custom_event (custom); - id->flags[offset][0] &= ~0x8000; - id->flags[offset][0] |= custompos << 15; + int idx = -1; + int custompos = (id->flags[offset][0] >> 15) & 1; + TCHAR *custom; + + if (state < 0) { + idx = 0; + custompos = 0; + } else { + idx = state > 0 ? 0 : 1; + if (custompos) + idx += 2; + if (state == 0) + custompos ^= 1; + } + custom = id->custom[offset][idx]; + if (custom == NULL) { + if (idx >= 2) + custom = id->custom[offset][idx - 2]; + } + handle_custom_event (custom); + id->flags[offset][0] &= ~0x8000; + id->flags[offset][0] |= custompos << 15; } static void setbuttonstateall (struct uae_input_device *id, struct uae_input_device2 *id2, int button, int state) { - int i; - uae_u32 mask = 1 << button; - uae_u32 omask = id2->buttonmask & mask; - uae_u32 nmask = (state ? 1 : 0) << button; - - if (!id->enabled) { - if (state) - switchdevice (id, button, 1); - return; - } - if (button >= ID_BUTTON_TOTAL) - return; + int i; + uae_u32 mask = 1 << button; + uae_u32 omask = id2->buttonmask & mask; + uae_u32 nmask = (state ? 1 : 0) << button; - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { - int evt = evt = id->eventid[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]]; - int autofire = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_AUTOFIRE) ? 1 : 0; - int toggle = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_TOGGLE) ? 1 : 0; + if (!id->enabled) { + if (state) + switchdevice (id, button, 1); + return; + } + if (button >= ID_BUTTON_TOTAL) + return; - if (state < 0) { - handle_input_event (evt, 1, 1, 0); - queue_input_event (evt, 0, 1, 1, 0); /* send release event next frame */ - if (i == 0) - process_custom_event (id, ID_BUTTON_OFFSET + button, state); - } else if (toggle) { - int toggled; - if (!state) - continue; - if (omask & mask) - continue; - id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] ^= ID_FLAG_TOGGLED; - toggled = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_TOGGLED) ? 1 : 0; - handle_input_event (evt, toggled, 1, autofire); - if (i == 0) - process_custom_event (id, ID_BUTTON_OFFSET + button, toggled); - } else { - if ((omask ^ nmask) & mask) { - handle_input_event (evt, state, 1, autofire); - if (i == 0) - process_custom_event (id, ID_BUTTON_OFFSET + button, state); - } + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { + int evt = evt = id->eventid[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]]; + int autofire = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_AUTOFIRE) ? 1 : 0; + int toggle = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_TOGGLE) ? 1 : 0; + + if (state < 0) { + handle_input_event (evt, 1, 1, 0); + queue_input_event (evt, 0, 1, 1, 0); /* send release event next frame */ + if (i == 0) + process_custom_event (id, ID_BUTTON_OFFSET + button, state); + } else if (toggle) { + int toggled; + if (!state) + continue; + if (omask & mask) + continue; + id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] ^= ID_FLAG_TOGGLED; + toggled = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_TOGGLED) ? 1 : 0; + handle_input_event (evt, toggled, 1, autofire); + if (i == 0) + process_custom_event (id, ID_BUTTON_OFFSET + button, toggled); + } else { + if ((omask ^ nmask) & mask) { + handle_input_event (evt, state, 1, autofire); + if (i == 0) + process_custom_event (id, ID_BUTTON_OFFSET + button, state); + } + } } - } - if ((omask ^ nmask) & mask) { - if (state) - id2->buttonmask |= mask; - else - id2->buttonmask &= ~mask; - } + if ((omask ^ nmask) & mask) { + if (state) + id2->buttonmask |= mask; + else + id2->buttonmask &= ~mask; + } } /* - detect required number of joysticks and mice from configuration data - * - detect if CD32 pad emulation is needed - * - detect device type in ports (mouse or joystick) - */ +* - detect if CD32 pad emulation is needed +* - detect device type in ports (mouse or joystick) +*/ static int iscd32 (int ei) { - if (ei >= INPUTEVENT_JOY1_CD32_FIRST && ei <= INPUTEVENT_JOY1_CD32_LAST) { - cd32_pad_enabled[0] = 1; - return 1; - } - if (ei >= INPUTEVENT_JOY2_CD32_FIRST && ei <= INPUTEVENT_JOY2_CD32_LAST) { - cd32_pad_enabled[1] = 1; - return 2; - } - return 0; + if (ei >= INPUTEVENT_JOY1_CD32_FIRST && ei <= INPUTEVENT_JOY1_CD32_LAST) { + cd32_pad_enabled[0] = 1; + return 1; + } + if (ei >= INPUTEVENT_JOY2_CD32_FIRST && ei <= INPUTEVENT_JOY2_CD32_LAST) { + cd32_pad_enabled[1] = 1; + return 2; + } + return 0; } static int isparport (int ei) { - if (ei > INPUTEVENT_PAR_JOY1_START && ei < INPUTEVENT_PAR_JOY_END) { - parport_joystick_enabled = 1; - return 1; - } - return 0; + if (ei > INPUTEVENT_PAR_JOY1_START && ei < INPUTEVENT_PAR_JOY_END) { + parport_joystick_enabled = 1; + return 1; + } + return 0; } static int ismouse (int ei) { - if (ei >= INPUTEVENT_MOUSE1_FIRST && ei <= INPUTEVENT_MOUSE1_LAST) { - mouse_port[0] = 1; - return 1; - } - if (ei >= INPUTEVENT_MOUSE2_FIRST && ei <= INPUTEVENT_MOUSE2_LAST) { - mouse_port[1] = 1; - return 2; - } - return 0; + if (ei >= INPUTEVENT_MOUSE1_FIRST && ei <= INPUTEVENT_MOUSE1_LAST) { + mouse_port[0] = 1; + return 1; + } + if (ei >= INPUTEVENT_MOUSE2_FIRST && ei <= INPUTEVENT_MOUSE2_LAST) { + mouse_port[1] = 1; + return 2; + } + return 0; } static int isanalog (int ei) { - if (ei == INPUTEVENT_JOY1_HORIZ_POT || ei == INPUTEVENT_JOY1_HORIZ_POT_INV) { - analog_port[0][0] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY1_VERT_POT || ei == INPUTEVENT_JOY1_VERT_POT_INV) { - analog_port[0][1] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY2_HORIZ_POT || ei == INPUTEVENT_JOY2_HORIZ_POT_INV) { - analog_port[1][0] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY2_VERT_POT || ei == INPUTEVENT_JOY2_VERT_POT_INV) { - analog_port[1][1] = 1; - return 1; - } - return 0; + if (ei == INPUTEVENT_JOY1_HORIZ_POT || ei == INPUTEVENT_JOY1_HORIZ_POT_INV) { + analog_port[0][0] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY1_VERT_POT || ei == INPUTEVENT_JOY1_VERT_POT_INV) { + analog_port[0][1] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY2_HORIZ_POT || ei == INPUTEVENT_JOY2_HORIZ_POT_INV) { + analog_port[1][0] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY2_VERT_POT || ei == INPUTEVENT_JOY2_VERT_POT_INV) { + analog_port[1][1] = 1; + return 1; + } + return 0; } static int isdigitalbutton (int ei) { - if (ei == INPUTEVENT_JOY1_2ND_BUTTON) { - digital_port[0][0] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY1_3RD_BUTTON) { - digital_port[0][1] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY2_2ND_BUTTON) { - digital_port[1][0] = 1; - return 1; - } - if (ei == INPUTEVENT_JOY2_3RD_BUTTON) { - digital_port[1][1] = 1; - return 1; - } - return 0; + if (ei == INPUTEVENT_JOY1_2ND_BUTTON) { + digital_port[0][0] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY1_3RD_BUTTON) { + digital_port[0][1] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY2_2ND_BUTTON) { + digital_port[1][0] = 1; + return 1; + } + if (ei == INPUTEVENT_JOY2_3RD_BUTTON) { + digital_port[1][1] = 1; + return 1; + } + return 0; } static void scanevents (struct uae_prefs *p) { - int i, j, k, ei; - const struct inputevent *e; - int n_joy = idev[IDTYPE_JOYSTICK].get_num(); - int n_mouse = idev[IDTYPE_MOUSE].get_num(); - - cd32_pad_enabled[0] = cd32_pad_enabled[1] = 0; - parport_joystick_enabled = 0; - mouse_port[0] = mouse_port[1] = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - digital_port[i][j] = 0; - analog_port[i][j] = 0; - joydirpot[i][j] = 128 / (312 * 100 / currprefs.input_analog_joystick_mult) + (128 * currprefs.input_analog_joystick_mult / 100) + currprefs.input_analog_joystick_offset; - } - } - - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) - joydir[i] = 0; - - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - use_joysticks[i] = 0; - use_mice[i] = 0; - for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { - for (j = 0; j < ID_BUTTON_TOTAL; j++) { - - if ((joysticks[i].enabled && i < n_joy) || joysticks[i].enabled < 0) { - ei = joysticks[i].eventid[ID_BUTTON_OFFSET + j][k]; - e = &events[ei]; - iscd32 (ei); - isparport (ei); - ismouse (ei); - isdigitalbutton (ei); - if (joysticks[i].eventid[ID_BUTTON_OFFSET + j][k] > 0) - use_joysticks[i] = 1; - } - if ((mice[i].enabled && i < n_mouse) || mice[i].enabled < 0) { - ei = mice[i].eventid[ID_BUTTON_OFFSET + j][k]; - e = &events[ei]; - iscd32 (ei); - isparport (ei); - ismouse (ei); - isdigitalbutton (ei); - if (mice[i].eventid[ID_BUTTON_OFFSET + j][k] > 0) - use_mice[i] = 1; + int i, j, k, ei; + const struct inputevent *e; + int n_joy = idev[IDTYPE_JOYSTICK].get_num(); + int n_mouse = idev[IDTYPE_MOUSE].get_num(); + + cd32_pad_enabled[0] = cd32_pad_enabled[1] = 0; + parport_joystick_enabled = 0; + mouse_port[0] = mouse_port[1] = 0; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + digital_port[i][j] = 0; + analog_port[i][j] = 0; + joydirpot[i][j] = 128 / (312 * 100 / currprefs.input_analog_joystick_mult) + (128 * currprefs.input_analog_joystick_mult / 100) + currprefs.input_analog_joystick_offset; } + } - } + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) + joydir[i] = 0; - for (j = 0; j < ID_AXIS_TOTAL; j++) { + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + use_joysticks[i] = 0; + use_mice[i] = 0; + for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { + for (j = 0; j < ID_BUTTON_TOTAL; j++) { + + if ((joysticks[i].enabled && i < n_joy) || joysticks[i].enabled < 0) { + ei = joysticks[i].eventid[ID_BUTTON_OFFSET + j][k]; + e = &events[ei]; + iscd32 (ei); + isparport (ei); + ismouse (ei); + isdigitalbutton (ei); + if (joysticks[i].eventid[ID_BUTTON_OFFSET + j][k] > 0) + use_joysticks[i] = 1; + } + if ((mice[i].enabled && i < n_mouse) || mice[i].enabled < 0) { + ei = mice[i].eventid[ID_BUTTON_OFFSET + j][k]; + e = &events[ei]; + iscd32 (ei); + isparport (ei); + ismouse (ei); + isdigitalbutton (ei); + if (mice[i].eventid[ID_BUTTON_OFFSET + j][k] > 0) + use_mice[i] = 1; + } - if ((joysticks[i].enabled && i < n_joy) || joysticks[i].enabled < 0) { - ei = joysticks[i].eventid[ID_AXIS_OFFSET + j][k]; - iscd32 (ei); - isparport (ei); - ismouse (ei); - isanalog (ei); - isdigitalbutton (ei); - if (ei > 0) - use_joysticks[i] = 1; - } - if ((mice[i].enabled && i < n_mouse) || mice[i].enabled < 0) { - ei = mice[i].eventid[ID_AXIS_OFFSET + j][k]; - iscd32 (ei); - isparport (ei); - ismouse (ei); - isanalog (ei); - isdigitalbutton (ei); - if (ei > 0) - use_mice[i] = 1; + } + + for (j = 0; j < ID_AXIS_TOTAL; j++) { + + if ((joysticks[i].enabled && i < n_joy) || joysticks[i].enabled < 0) { + ei = joysticks[i].eventid[ID_AXIS_OFFSET + j][k]; + iscd32 (ei); + isparport (ei); + ismouse (ei); + isanalog (ei); + isdigitalbutton (ei); + if (ei > 0) + use_joysticks[i] = 1; + } + if ((mice[i].enabled && i < n_mouse) || mice[i].enabled < 0) { + ei = mice[i].eventid[ID_AXIS_OFFSET + j][k]; + iscd32 (ei); + isparport (ei); + ismouse (ei); + isanalog (ei); + isdigitalbutton (ei); + if (ei > 0) + use_mice[i] = 1; + } + } } - } - } - } - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - use_keyboards[i] = 0; - if (keyboards[i].enabled && i < idev[IDTYPE_KEYBOARD].get_num()) { - j = 0; - while (keyboards[i].extra[j][0] >= 0) { - use_keyboards[i] = 1; - for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { - ei = keyboards[i].eventid[j][k]; - iscd32 (ei); - isparport (ei); - ismouse (ei); - isdigitalbutton (ei); + } + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + use_keyboards[i] = 0; + if (keyboards[i].enabled && i < idev[IDTYPE_KEYBOARD].get_num()) { + j = 0; + while (keyboards[i].extra[j][0] >= 0) { + use_keyboards[i] = 1; + for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { + ei = keyboards[i].eventid[j][k]; + iscd32 (ei); + isparport (ei); + ismouse (ei); + isdigitalbutton (ei); + } + j++; + } } - j++; - } } - } } #ifdef CD32 static void setcd32 (int joy, int n) { - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = n ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = n ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = n ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 3][0] = n ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 4][0] = n ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 5][0] = n ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 6][0] = n ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = n ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = n ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = n ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 3][0] = n ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 4][0] = n ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 5][0] = n ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 6][0] = n ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY; } #endif @@ -3061,440 +3061,440 @@ int compatibility_device[MAX_JPORTS]; static void compatibility_mode (struct uae_prefs *prefs) { - int joy, i; - int used[MAX_INPUT_DEVICES] = { 0 }; - - prefs->jports[0].name[0] = prefs->jports[1].name[0] = 0; - prefs->jports[0].configname[0] = prefs->jports[1].configname[0] = 0; - prefs->jports[2].name[0] = prefs->jports[3].name[0] = 0; - prefs->jports[2].configname[0] = prefs->jports[3].configname[0] = 0; - compatibility_device[0] = -1; - compatibility_device[1] = -1; - compatibility_device[2] = -1; - compatibility_device[3] = -1; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - clear_id (&mice[i]); - clear_id (&joysticks[i]); - } - - for (i = 0; i < 2; i++) { - int mode = prefs->jports[i].mode; - if ((joy = jsem_ismouse (i, prefs)) >= 0) { - switch (mode) - { - case JSEM_MODE_DEFAULT: - case JSEM_MODE_MOUSE: - default: - input_get_default_mouse (mice, joy, i); - break; - case JSEM_MODE_LIGHTPEN: - input_get_default_lightpen (mice, joy, i); - break; - } - _tcsncpy (prefs->jports[i].name, idev[IDTYPE_MOUSE].get_friendlyname (joy), MAX_JPORTNAME - 1); - _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_MOUSE].get_uniquename (joy), MAX_JPORTNAME - 1); - mice[joy].enabled = 1; - } - } - for (i = 1; i >= 0; i--) { - int mode = prefs->jports[i].mode; - joy = jsem_isjoy (i, prefs); - if (joy >= 0) { - switch (mode) - { - case JSEM_MODE_DEFAULT: - case JSEM_MODE_JOYSTICK: - case JSEM_MODE_JOYSTICK_CD32: - default: - input_get_default_joystick (joysticks, joy, i, (mode == JSEM_MODE_JOYSTICK_CD32 || (mode == JSEM_MODE_DEFAULT && prefs->cs_cd32cd))); - break; - case JSEM_MODE_JOYSTICK_ANALOG: - input_get_default_joystick_analog (joysticks, joy, i); - break; - case JSEM_MODE_MOUSE: - input_get_default_mouse (joysticks, joy, i); - break; - case JSEM_MODE_LIGHTPEN: - input_get_default_lightpen (joysticks, joy, i); - break; - } - _tcsncpy (prefs->jports[i].name, idev[IDTYPE_JOYSTICK].get_friendlyname (joy), MAX_JPORTNAME - 1); - _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_JOYSTICK].get_uniquename (joy), MAX_JPORTNAME - 1); - joysticks[joy].enabled = 1; - used[joy] = 1; - } - } - for (i = 2; i < 4; i++) { - joy = jsem_isjoy (i, prefs); - if (joy >= 0) { - input_get_default_joystick (joysticks, joy, i, 0); - _tcsncpy (prefs->jports[i].name, idev[IDTYPE_JOYSTICK].get_friendlyname (joy), MAX_JPORTNAME - 1); - _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_JOYSTICK].get_uniquename (joy), MAX_JPORTNAME - 1); - joysticks[joy].enabled = 1; - used[joy] = 1; - } - } - - for (i = 0; i < 2; i++) { - int mode = prefs->jports[i].mode; - for (joy = 0; used[joy]; joy++); - if (JSEM_ISANYKBD (i, prefs)) { - switch (mode) - { - case JSEM_MODE_JOYSTICK: - case JSEM_MODE_JOYSTICK_CD32: - case JSEM_MODE_DEFAULT: - default: - joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ; - joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - if (mode == JSEM_MODE_JOYSTICK_CD32 || (mode == JSEM_MODE_DEFAULT && prefs->cs_cd32cd)) - setcd32 (joy, i); - break; - case JSEM_MODE_MOUSE_CDTV: - joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_MOUSE_CDTV_HORIZ; - joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_MOUSE_CDTV_VERT; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY1_FIRE_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY1_2ND_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY1_3RD_BUTTON; - break; - case JSEM_MODE_MOUSE: - joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; - joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - break; - case JSEM_MODE_LIGHTPEN: - joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_LIGHTPEN_HORIZ; - joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_LIGHTPEN_VERT; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - break; + int joy, i; + int used[MAX_INPUT_DEVICES] = { 0 }; + + prefs->jports[0].name[0] = prefs->jports[1].name[0] = 0; + prefs->jports[0].configname[0] = prefs->jports[1].configname[0] = 0; + prefs->jports[2].name[0] = prefs->jports[3].name[0] = 0; + prefs->jports[2].configname[0] = prefs->jports[3].configname[0] = 0; + compatibility_device[0] = -1; + compatibility_device[1] = -1; + compatibility_device[2] = -1; + compatibility_device[3] = -1; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + clear_id (&mice[i]); + clear_id (&joysticks[i]); + } + + for (i = 0; i < 2; i++) { + int mode = prefs->jports[i].mode; + if ((joy = jsem_ismouse (i, prefs)) >= 0) { + switch (mode) + { + case JSEM_MODE_DEFAULT: + case JSEM_MODE_MOUSE: + default: + input_get_default_mouse (mice, joy, i); + break; + case JSEM_MODE_LIGHTPEN: + input_get_default_lightpen (mice, joy, i); + break; + } + _tcsncpy (prefs->jports[i].name, idev[IDTYPE_MOUSE].get_friendlyname (joy), MAX_JPORTNAME - 1); + _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_MOUSE].get_uniquename (joy), MAX_JPORTNAME - 1); + mice[joy].enabled = 1; + } + } + for (i = 1; i >= 0; i--) { + int mode = prefs->jports[i].mode; + joy = jsem_isjoy (i, prefs); + if (joy >= 0) { + switch (mode) + { + case JSEM_MODE_DEFAULT: + case JSEM_MODE_JOYSTICK: + case JSEM_MODE_JOYSTICK_CD32: + default: + input_get_default_joystick (joysticks, joy, i, (mode == JSEM_MODE_JOYSTICK_CD32 || (mode == JSEM_MODE_DEFAULT && prefs->cs_cd32cd))); + break; + case JSEM_MODE_JOYSTICK_ANALOG: + input_get_default_joystick_analog (joysticks, joy, i); + break; + case JSEM_MODE_MOUSE: + input_get_default_mouse (joysticks, joy, i); + break; + case JSEM_MODE_LIGHTPEN: + input_get_default_lightpen (joysticks, joy, i); + break; + } + _tcsncpy (prefs->jports[i].name, idev[IDTYPE_JOYSTICK].get_friendlyname (joy), MAX_JPORTNAME - 1); + _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_JOYSTICK].get_uniquename (joy), MAX_JPORTNAME - 1); + joysticks[joy].enabled = 1; + used[joy] = 1; + } + } + for (i = 2; i < 4; i++) { + joy = jsem_isjoy (i, prefs); + if (joy >= 0) { + input_get_default_joystick (joysticks, joy, i, 0); + _tcsncpy (prefs->jports[i].name, idev[IDTYPE_JOYSTICK].get_friendlyname (joy), MAX_JPORTNAME - 1); + _tcsncpy (prefs->jports[i].configname, idev[IDTYPE_JOYSTICK].get_uniquename (joy), MAX_JPORTNAME - 1); + joysticks[joy].enabled = 1; + used[joy] = 1; + } + } - } - joysticks[joy].enabled = -1; - used[joy] = 1; - compatibility_device[i] = joy; + for (i = 0; i < 2; i++) { + int mode = prefs->jports[i].mode; + for (joy = 0; used[joy]; joy++); + if (JSEM_ISANYKBD (i, prefs)) { + switch (mode) + { + case JSEM_MODE_JOYSTICK: + case JSEM_MODE_JOYSTICK_CD32: + case JSEM_MODE_DEFAULT: + default: + joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ; + joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + if (mode == JSEM_MODE_JOYSTICK_CD32 || (mode == JSEM_MODE_DEFAULT && prefs->cs_cd32cd)) + setcd32 (joy, i); + break; + case JSEM_MODE_MOUSE_CDTV: + joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_MOUSE_CDTV_HORIZ; + joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_MOUSE_CDTV_VERT; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY1_FIRE_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY1_2ND_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY1_3RD_BUTTON; + break; + case JSEM_MODE_MOUSE: + joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; + joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = i ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + break; + case JSEM_MODE_LIGHTPEN: + joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_LIGHTPEN_HORIZ; + joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_LIGHTPEN_VERT; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + break; + + } + joysticks[joy].enabled = -1; + used[joy] = 1; + compatibility_device[i] = joy; + } } - } - for (i = 2; i < 4; i++) { - for (joy = 0; used[joy]; joy++); - if (JSEM_ISANYKBD (i, prefs)) { - joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i == 3 ? INPUTEVENT_PAR_JOY2_HORIZ : INPUTEVENT_PAR_JOY1_HORIZ; - joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i == 3 ? INPUTEVENT_PAR_JOY2_VERT : INPUTEVENT_PAR_JOY1_VERT; - joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i == 3 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON; - joysticks[joy].enabled = -1; - used[joy] = 1; - compatibility_device[i] = joy; + for (i = 2; i < 4; i++) { + for (joy = 0; used[joy]; joy++); + if (JSEM_ISANYKBD (i, prefs)) { + joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = i == 3 ? INPUTEVENT_PAR_JOY2_HORIZ : INPUTEVENT_PAR_JOY1_HORIZ; + joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = i == 3 ? INPUTEVENT_PAR_JOY2_VERT : INPUTEVENT_PAR_JOY1_VERT; + joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = i == 3 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON; + joysticks[joy].enabled = -1; + used[joy] = 1; + compatibility_device[i] = joy; + } } - } } static void matchdevices (struct inputdevice_functions *inf, struct uae_input_device *uid) { - int i, j; - - for (i = 0; i < inf->get_num (); i++) { - TCHAR *aname1 = inf->get_friendlyname (i); - TCHAR *aname2 = inf->get_uniquename (i); - int match = -1; - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - if (aname2 && uid[j].configname) { - TCHAR bname[MAX_DPATH]; - TCHAR bname2[MAX_DPATH]; - TCHAR *p1 ,*p2; - _tcscpy (bname, uid[j].configname); - _tcscpy (bname2, aname2); - p1 = _tcschr (bname, ' '); - p2 = _tcschr (bname2, ' '); - if (p1 && p2 && p1 - bname == p2 - bname2) { - *p1 = 0; - *p2 = 0; - if (bname && !_tcscmp (bname2, bname)) { - if (match >= 0) - match = -2; - else - match = j; - } + int i, j; + + for (i = 0; i < inf->get_num (); i++) { + TCHAR *aname1 = inf->get_friendlyname (i); + TCHAR *aname2 = inf->get_uniquename (i); + int match = -1; + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + if (aname2 && uid[j].configname) { + TCHAR bname[MAX_DPATH]; + TCHAR bname2[MAX_DPATH]; + TCHAR *p1 ,*p2; + _tcscpy (bname, uid[j].configname); + _tcscpy (bname2, aname2); + p1 = _tcschr (bname, ' '); + p2 = _tcschr (bname2, ' '); + if (p1 && p2 && p1 - bname == p2 - bname2) { + *p1 = 0; + *p2 = 0; + if (bname && !_tcscmp (bname2, bname)) { + if (match >= 0) + match = -2; + else + match = j; + } + } + if (match == -2) + break; + } + } + // multiple matches -> use complete local-only id string for comparisons + if (match == -2) { + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + TCHAR *bname = uid[j].configname; + if (aname2 && bname && !_tcscmp (aname2, bname)) + match = j; + } + } + if (match < 0) { + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + TCHAR *bname = uid[j].name; + if (aname2 && bname && !_tcscmp (aname2, bname)) + match = j; + } + } + if (match >= 0) { + j = match; + if (j != i) { + struct uae_input_device *tmp = xmalloc (sizeof (struct uae_input_device)); + memcpy (tmp, &uid[j], sizeof (struct uae_input_device)); + memcpy (&uid[j], &uid[i], sizeof (struct uae_input_device)); + memcpy (&uid[i], tmp, sizeof (struct uae_input_device)); + xfree (tmp); + } } - if (match == -2) - break; - } - } - // multiple matches -> use complete local-only id string for comparisons - if (match == -2) { - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - TCHAR *bname = uid[j].configname; - if (aname2 && bname && !_tcscmp (aname2, bname)) - match = j; - } - } - if (match < 0) { - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - TCHAR *bname = uid[j].name; - if (aname2 && bname && !_tcscmp (aname2, bname)) - match = j; - } - } - if (match >= 0) { - j = match; - if (j != i) { - struct uae_input_device *tmp = xmalloc (sizeof (struct uae_input_device)); - memcpy (tmp, &uid[j], sizeof (struct uae_input_device)); - memcpy (&uid[j], &uid[i], sizeof (struct uae_input_device)); - memcpy (&uid[i], tmp, sizeof (struct uae_input_device)); - xfree (tmp); - } - } - } - for (i = 0; i < inf->get_num (); i++) { - if (uid[i].name == NULL) - uid[i].name = my_strdup (inf->get_friendlyname (i)); - if (uid[i].configname == NULL) - uid[i].configname = my_strdup (inf->get_uniquename (i)); - } + } + for (i = 0; i < inf->get_num (); i++) { + if (uid[i].name == NULL) + uid[i].name = my_strdup (inf->get_friendlyname (i)); + if (uid[i].configname == NULL) + uid[i].configname = my_strdup (inf->get_uniquename (i)); + } } static void matchdevices_all (struct uae_prefs *prefs) { - int i; - for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { - matchdevices (&idev[IDTYPE_MOUSE], prefs->mouse_settings[i]); - matchdevices (&idev[IDTYPE_JOYSTICK], prefs->joystick_settings[i]); - matchdevices (&idev[IDTYPE_KEYBOARD], prefs->keyboard_settings[i]); - } + int i; + for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { + matchdevices (&idev[IDTYPE_MOUSE], prefs->mouse_settings[i]); + matchdevices (&idev[IDTYPE_JOYSTICK], prefs->joystick_settings[i]); + matchdevices (&idev[IDTYPE_KEYBOARD], prefs->keyboard_settings[i]); + } } void inputdevice_updateconfig (struct uae_prefs *prefs) { - int i; + int i; - copyjport (&changed_prefs, &currprefs, 0); - copyjport (&changed_prefs, &currprefs, 1); - copyjport (&changed_prefs, &currprefs, 2); - copyjport (&changed_prefs, &currprefs, 3); + copyjport (&changed_prefs, &currprefs, 0); + copyjport (&changed_prefs, &currprefs, 1); + copyjport (&changed_prefs, &currprefs, 2); + copyjport (&changed_prefs, &currprefs, 3); #ifdef RETROPLATFORM - rp_input_change (0); - rp_input_change (1); - rp_input_change (2); - rp_input_change (3); + rp_input_change (0); + rp_input_change (1); + rp_input_change (2); + rp_input_change (3); #endif - joybutton[0] = joybutton[1] = 0; - joydir[0] = joydir[1] = 0; - oldmx[0] = oldmx[1] = -1; - oldmy[0] = oldmy[1] = -1; - cd32_shifter[0] = cd32_shifter[1] = 8; - for (i = 0; i < 4; i++) { - oleft[i] = 0; - oright[i] = 0; - otop[i] = 0; - obot[i] = 0; - } - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - mouse_deltanoreset[i][0] = 0; - mouse_delta[i][0] = 0; - mouse_deltanoreset[i][1] = 0; - mouse_delta[i][1] = 0; - mouse_deltanoreset[i][2] = 0; - mouse_delta[i][2] = 0; - } - memset (keybuf, 0, sizeof (keybuf)); - - for (i = 0; i < INPUT_QUEUE_SIZE; i++) - input_queue[i].framecnt = input_queue[i].nextframecnt = -1; - - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { - sublevdir[0][i] = i; - sublevdir[1][i] = MAX_INPUT_SUB_EVENT - i - 1; - } - - joysticks = prefs->joystick_settings[prefs->input_selected_setting]; - mice = prefs->mouse_settings[prefs->input_selected_setting]; - keyboards = prefs->keyboard_settings[prefs->input_selected_setting]; - - matchdevices_all (prefs); - - memset (joysticks2, 0, sizeof (joysticks2)); - memset (mice2, 0, sizeof (mice2)); - if (prefs->input_selected_setting == 0) - compatibility_mode (prefs); - - joystick_setting_changed (); - - scanevents (prefs); + joybutton[0] = joybutton[1] = 0; + joydir[0] = joydir[1] = 0; + oldmx[0] = oldmx[1] = -1; + oldmy[0] = oldmy[1] = -1; + cd32_shifter[0] = cd32_shifter[1] = 8; + for (i = 0; i < 4; i++) { + oleft[i] = 0; + oright[i] = 0; + otop[i] = 0; + obot[i] = 0; + } + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + mouse_deltanoreset[i][0] = 0; + mouse_delta[i][0] = 0; + mouse_deltanoreset[i][1] = 0; + mouse_delta[i][1] = 0; + mouse_deltanoreset[i][2] = 0; + mouse_delta[i][2] = 0; + } + memset (keybuf, 0, sizeof (keybuf)); + + for (i = 0; i < INPUT_QUEUE_SIZE; i++) + input_queue[i].framecnt = input_queue[i].nextframecnt = -1; + + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { + sublevdir[0][i] = i; + sublevdir[1][i] = MAX_INPUT_SUB_EVENT - i - 1; + } + + joysticks = prefs->joystick_settings[prefs->input_selected_setting]; + mice = prefs->mouse_settings[prefs->input_selected_setting]; + keyboards = prefs->keyboard_settings[prefs->input_selected_setting]; + + matchdevices_all (prefs); + + memset (joysticks2, 0, sizeof (joysticks2)); + memset (mice2, 0, sizeof (mice2)); + if (prefs->input_selected_setting == 0) + compatibility_mode (prefs); + + joystick_setting_changed (); + + scanevents (prefs); #if 0 #ifdef CD32 - if (currprefs.input_selected_setting == 0 && currprefs.cs_cd32cd) - cd32_pad_enabled[1] = 1; + if (currprefs.input_selected_setting == 0 && currprefs.cs_cd32cd) + cd32_pad_enabled[1] = 1; #endif #endif } /* called when devices get inserted or removed - * store old devices temporarily, enumerate all devices - * restore old devices back (order may have changed) - */ +* store old devices temporarily, enumerate all devices +* restore old devices back (order may have changed) +*/ void inputdevice_devicechange (struct uae_prefs *prefs) { - int acc = input_acquired; - int i, idx; - TCHAR *jports[MAX_JPORTS]; - int jportskb[MAX_JPORTS], jportsmode[MAX_JPORTS]; - - for (i = 0; i < MAX_JPORTS; i++) { - jports[i] = NULL; - jportskb[i] = -1; - idx = inputdevice_getjoyportdevice (prefs->jports[i].id); - if (idx >= JSEM_LASTKBD) { - struct inputdevice_functions *idf; - int devidx; - idx -= JSEM_LASTKBD; - idf = getidf (idx); - devidx = inputdevice_get_device_index (idx); - jports[i] = my_strdup (idf->get_uniquename (devidx)); - } else { - jportskb[i] = idx; - } - jportsmode[i] = prefs->jports[i].mode; - } - - inputdevice_unacquire (); - idev[IDTYPE_JOYSTICK].close (); - idev[IDTYPE_MOUSE].close (); - idev[IDTYPE_KEYBOARD].close (); - idev[IDTYPE_JOYSTICK].init (); - idev[IDTYPE_MOUSE].init (); - idev[IDTYPE_KEYBOARD].init (); - matchdevices (&idev[IDTYPE_MOUSE], mice); - matchdevices (&idev[IDTYPE_JOYSTICK], joysticks); - matchdevices (&idev[IDTYPE_KEYBOARD], keyboards); - - for (i = 0; i < MAX_JPORTS; i++) { - freejport (prefs, i); - if (jports[i]) { - inputdevice_joyport_config (prefs, jports[i], i, jportsmode[i], 2); - xfree (jports[i]); - } else if (jportskb[i] >= 0) { - TCHAR tmp[10]; - _stprintf (tmp, L"kbd%d", jportskb[i]); - inputdevice_joyport_config (prefs, tmp, i, jportsmode[i], 0); - } - } - - if (prefs == &changed_prefs) - inputdevice_copyconfig (&changed_prefs, &currprefs); - if (acc) - inputdevice_acquire (TRUE); + int acc = input_acquired; + int i, idx; + TCHAR *jports[MAX_JPORTS]; + int jportskb[MAX_JPORTS], jportsmode[MAX_JPORTS]; + + for (i = 0; i < MAX_JPORTS; i++) { + jports[i] = NULL; + jportskb[i] = -1; + idx = inputdevice_getjoyportdevice (prefs->jports[i].id); + if (idx >= JSEM_LASTKBD) { + struct inputdevice_functions *idf; + int devidx; + idx -= JSEM_LASTKBD; + idf = getidf (idx); + devidx = inputdevice_get_device_index (idx); + jports[i] = my_strdup (idf->get_uniquename (devidx)); + } else { + jportskb[i] = idx; + } + jportsmode[i] = prefs->jports[i].mode; + } + + inputdevice_unacquire (); + idev[IDTYPE_JOYSTICK].close (); + idev[IDTYPE_MOUSE].close (); + idev[IDTYPE_KEYBOARD].close (); + idev[IDTYPE_JOYSTICK].init (); + idev[IDTYPE_MOUSE].init (); + idev[IDTYPE_KEYBOARD].init (); + matchdevices (&idev[IDTYPE_MOUSE], mice); + matchdevices (&idev[IDTYPE_JOYSTICK], joysticks); + matchdevices (&idev[IDTYPE_KEYBOARD], keyboards); + + for (i = 0; i < MAX_JPORTS; i++) { + freejport (prefs, i); + if (jports[i]) { + inputdevice_joyport_config (prefs, jports[i], i, jportsmode[i], 2); + xfree (jports[i]); + } else if (jportskb[i] >= 0) { + TCHAR tmp[10]; + _stprintf (tmp, L"kbd%d", jportskb[i]); + inputdevice_joyport_config (prefs, tmp, i, jportsmode[i], 0); + } + } + + if (prefs == &changed_prefs) + inputdevice_copyconfig (&changed_prefs, &currprefs); + if (acc) + inputdevice_acquire (TRUE); } static void set_kbr_default (struct uae_prefs *p, int index, int num) { - int i, j, k, l; - struct uae_input_device_kbr_default *trans = keyboard_default; - struct uae_input_device *kbr; - struct inputdevice_functions *id = &idev[IDTYPE_KEYBOARD]; - uae_u32 scancode; + int i, j, k, l; + struct uae_input_device_kbr_default *trans = keyboard_default; + struct uae_input_device *kbr; + struct inputdevice_functions *id = &idev[IDTYPE_KEYBOARD]; + uae_u32 scancode; - if (!trans) - return; - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - kbr = &p->keyboard_settings[index][j]; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - memset (kbr, 0, sizeof (struct uae_input_device)); - kbr->extra[i][0] = -1; - } - if (j < id->get_num ()) { - if (j == 0) - kbr->enabled = 1; - for (i = 0; i < id->get_widget_num (num); i++) { - id->get_widget_type (num, i, 0, &scancode); - kbr->extra[i][0] = scancode; - l = 0; - while (trans[l].scancode >= 0) { - if (kbr->extra[i][0] == trans[l].scancode) { - for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { - if (kbr->eventid[i][k] == 0) break; - } - if (k == MAX_INPUT_SUB_EVENT) { - write_log (L"corrupt default keyboard mappings\n"); - return; + if (!trans) + return; + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + kbr = &p->keyboard_settings[index][j]; + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + memset (kbr, 0, sizeof (struct uae_input_device)); + kbr->extra[i][0] = -1; + } + if (j < id->get_num ()) { + if (j == 0) + kbr->enabled = 1; + for (i = 0; i < id->get_widget_num (num); i++) { + id->get_widget_type (num, i, 0, &scancode); + kbr->extra[i][0] = scancode; + l = 0; + while (trans[l].scancode >= 0) { + if (kbr->extra[i][0] == trans[l].scancode) { + for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) { + if (kbr->eventid[i][k] == 0) break; + } + if (k == MAX_INPUT_SUB_EVENT) { + write_log (L"corrupt default keyboard mappings\n"); + return; + } + kbr->eventid[i][k] = trans[l].event; + break; + } + l++; + } } - kbr->eventid[i][k] = trans[l].event; - break; - } - l++; } - } } - } } void inputdevice_default_prefs (struct uae_prefs *p) { - int i, j; - - inputdevice_init (); - p->input_joymouse_multiplier = 20; - p->input_joymouse_deadzone = 33; - p->input_joystick_deadzone = 33; - p->input_joymouse_speed = 10; - p->input_analog_joystick_mult = 15; - p->input_analog_joystick_offset = -1; - p->input_mouse_speed = 100; - p->input_autofire_framecnt = 10; - for (i = 0; i <= MAX_INPUT_SETTINGS; i++) { - set_kbr_default (p, i, 0); - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - if (input_get_default_mouse (p->mouse_settings[i], j, j & 1)) - p->mouse_settings[i]->enabled = 1; - if (input_get_default_joystick (p->joystick_settings[i], j, j & 1, 0)) - p->joystick_settings[i]->enabled = 1; + int i, j; + + inputdevice_init (); + p->input_joymouse_multiplier = 20; + p->input_joymouse_deadzone = 33; + p->input_joystick_deadzone = 33; + p->input_joymouse_speed = 10; + p->input_analog_joystick_mult = 15; + p->input_analog_joystick_offset = -1; + p->input_mouse_speed = 100; + p->input_autofire_framecnt = 10; + for (i = 0; i <= MAX_INPUT_SETTINGS; i++) { + set_kbr_default (p, i, 0); + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + if (input_get_default_mouse (p->mouse_settings[i], j, j & 1)) + p->mouse_settings[i]->enabled = 1; + if (input_get_default_joystick (p->joystick_settings[i], j, j & 1, 0)) + p->joystick_settings[i]->enabled = 1; + } } - } } void inputdevice_setkeytranslation (struct uae_input_device_kbr_default *trans) { - keyboard_default = trans; + keyboard_default = trans; } static int inputdevice_translatekeycode_2 (int keyboard, int scancode, int state) { - struct uae_input_device *na = &keyboards[keyboard]; - int j, k; - int handled = 0; - - if (!keyboards || scancode < 0) - return handled; - j = 0; - while (na->extra[j][0] >= 0) { - if (na->extra[j][0] == scancode) { - for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {/* send key release events in reverse order */ - int autofire = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_AUTOFIRE) ? 1 : 0; - int toggle = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_TOGGLE) ? 1 : 0; - int evt = na->eventid[j][sublevdir[state == 0 ? 1 : 0][k]]; - int toggled; - - if (toggle) { - if (!state) - continue; - na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] ^= ID_FLAG_TOGGLED; - toggled = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_TOGGLED) ? 1 : 0; - handled |= handle_input_event (evt, toggled, 1, autofire); - } else { - handled |= handle_input_event (evt, state, 1, autofire); + struct uae_input_device *na = &keyboards[keyboard]; + int j, k; + int handled = 0; + + if (!keyboards || scancode < 0) + return handled; + j = 0; + while (na->extra[j][0] >= 0) { + if (na->extra[j][0] == scancode) { + for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {/* send key release events in reverse order */ + int autofire = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_AUTOFIRE) ? 1 : 0; + int toggle = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_TOGGLE) ? 1 : 0; + int evt = na->eventid[j][sublevdir[state == 0 ? 1 : 0][k]]; + int toggled; + + if (toggle) { + if (!state) + continue; + na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] ^= ID_FLAG_TOGGLED; + toggled = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_TOGGLED) ? 1 : 0; + handled |= handle_input_event (evt, toggled, 1, autofire); + } else { + handled |= handle_input_event (evt, state, 1, autofire); + } + } + process_custom_event (na, j, state); + return handled; } - } - process_custom_event (na, j, state); - return handled; + j++; } - j++; - } - return handled; + return handled; } #define IECODE_UP_PREFIX 0x80 @@ -3506,868 +3506,868 @@ static int inputdevice_translatekeycode_2 (int keyboard, int scancode, int state static void sendmmcodes(int code, int newstate) { - uae_u8 b; + uae_u8 b; - b = RAW_STEALTH | IECODE_UP_PREFIX; - record_key(((b << 1) | (b >> 7)) & 0xff); - b = IECODE_UP_PREFIX; - if ((code >> 8) == 0x01) - b |= STEALTHF_E0KEY; - if ((code >> 8) == 0x02) - b |= STEALTHF_E1KEY; - if (!newstate) - b |= STEALTHF_UPSTROKE; - record_key(((b << 1) | (b >> 7)) & 0xff); - b = ((code >> 4) & 0x0f) | IECODE_UP_PREFIX; - record_key(((b << 1) | (b >> 7)) & 0xff); - b = (code & 0x0f) | IECODE_UP_PREFIX; - record_key(((b << 1) | (b >> 7)) & 0xff); + b = RAW_STEALTH | IECODE_UP_PREFIX; + record_key(((b << 1) | (b >> 7)) & 0xff); + b = IECODE_UP_PREFIX; + if ((code >> 8) == 0x01) + b |= STEALTHF_E0KEY; + if ((code >> 8) == 0x02) + b |= STEALTHF_E1KEY; + if (!newstate) + b |= STEALTHF_UPSTROKE; + record_key(((b << 1) | (b >> 7)) & 0xff); + b = ((code >> 4) & 0x0f) | IECODE_UP_PREFIX; + record_key(((b << 1) | (b >> 7)) & 0xff); + b = (code & 0x0f) | IECODE_UP_PREFIX; + record_key(((b << 1) | (b >> 7)) & 0xff); } int inputdevice_translatekeycode (int keyboard, int scancode, int state) { - if (inputdevice_translatekeycode_2 (keyboard, scancode, state)) - return 1; - if (currprefs.mmkeyboard) - sendmmcodes (scancode, state); - return 0; + if (inputdevice_translatekeycode_2 (keyboard, scancode, state)) + return 1; + if (currprefs.mmkeyboard) + sendmmcodes (scancode, state); + return 0; } static struct inputdevice_functions idev[3]; void inputdevice_init (void) { - idev[IDTYPE_JOYSTICK] = inputdevicefunc_joystick; - idev[IDTYPE_JOYSTICK].init (); - idev[IDTYPE_MOUSE] = inputdevicefunc_mouse; - idev[IDTYPE_MOUSE].init (); - idev[IDTYPE_KEYBOARD] = inputdevicefunc_keyboard; - idev[IDTYPE_KEYBOARD].init (); + idev[IDTYPE_JOYSTICK] = inputdevicefunc_joystick; + idev[IDTYPE_JOYSTICK].init (); + idev[IDTYPE_MOUSE] = inputdevicefunc_mouse; + idev[IDTYPE_MOUSE].init (); + idev[IDTYPE_KEYBOARD] = inputdevicefunc_keyboard; + idev[IDTYPE_KEYBOARD].init (); } void inputdevice_close (void) { - idev[IDTYPE_JOYSTICK].close (); - idev[IDTYPE_MOUSE].close (); - idev[IDTYPE_KEYBOARD].close (); - inprec_close (); + idev[IDTYPE_JOYSTICK].close (); + idev[IDTYPE_MOUSE].close (); + idev[IDTYPE_KEYBOARD].close (); + inprec_close (); } static struct uae_input_device *get_uid (const struct inputdevice_functions *id, int devnum) { - struct uae_input_device *uid = 0; - if (id == &idev[IDTYPE_JOYSTICK]) { - uid = &joysticks[devnum]; - } else if (id == &idev[IDTYPE_MOUSE]) { - uid = &mice[devnum]; - } else if (id == &idev[IDTYPE_KEYBOARD]) { - uid = &keyboards[devnum]; - } - return uid; + struct uae_input_device *uid = 0; + if (id == &idev[IDTYPE_JOYSTICK]) { + uid = &joysticks[devnum]; + } else if (id == &idev[IDTYPE_MOUSE]) { + uid = &mice[devnum]; + } else if (id == &idev[IDTYPE_KEYBOARD]) { + uid = &keyboards[devnum]; + } + return uid; } static int get_event_data (const struct inputdevice_functions *id, int devnum, int num, int *eventid, TCHAR **custom, int *flags, int sub) { - const struct uae_input_device *uid = get_uid (id, devnum); - int type = id->get_widget_type (devnum, num, 0, 0); - int i; - if (type == IDEV_WIDGET_BUTTON) { - i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET; - *eventid = uid->eventid[i][sub]; - *flags = uid->flags[i][sub]; - *custom = uid->custom[i][sub]; - return i; - } else if (type == IDEV_WIDGET_AXIS) { - i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET; - *eventid = uid->eventid[i][sub]; - *flags = uid->flags[i][sub]; - *custom = uid->custom[i][sub]; - return i; - } else if (type == IDEV_WIDGET_KEY) { - i = num - id->get_widget_first (devnum, type); - *eventid = uid->eventid[i][sub]; - *flags = uid->flags[i][sub]; - *custom = uid->custom[i][sub]; - return i; - } - return -1; + const struct uae_input_device *uid = get_uid (id, devnum); + int type = id->get_widget_type (devnum, num, 0, 0); + int i; + if (type == IDEV_WIDGET_BUTTON) { + i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET; + *eventid = uid->eventid[i][sub]; + *flags = uid->flags[i][sub]; + *custom = uid->custom[i][sub]; + return i; + } else if (type == IDEV_WIDGET_AXIS) { + i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET; + *eventid = uid->eventid[i][sub]; + *flags = uid->flags[i][sub]; + *custom = uid->custom[i][sub]; + return i; + } else if (type == IDEV_WIDGET_KEY) { + i = num - id->get_widget_first (devnum, type); + *eventid = uid->eventid[i][sub]; + *flags = uid->flags[i][sub]; + *custom = uid->custom[i][sub]; + return i; + } + return -1; } static int put_event_data (const struct inputdevice_functions *id, int devnum, int num, int eventid, TCHAR *custom, int flags, int sub) { - struct uae_input_device *uid = get_uid (id, devnum); - int type = id->get_widget_type (devnum, num, 0, 0); - int i; - if (type == IDEV_WIDGET_BUTTON) { - i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET; - uid->eventid[i][sub] = eventid; - uid->flags[i][sub] = flags; - xfree (uid->custom[i][sub]); - uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; - return i; - } else if (type == IDEV_WIDGET_AXIS) { - i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET; - uid->eventid[i][sub] = eventid; - uid->flags[i][sub] = flags; - xfree (uid->custom[i][sub]); - uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; - return i; - } else if (type == IDEV_WIDGET_KEY) { - i = num - id->get_widget_first (devnum, type); - uid->eventid[i][sub] = eventid; - uid->flags[i][sub] = flags; - xfree (uid->custom[i][sub]); - uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; - return i; - } - return -1; + struct uae_input_device *uid = get_uid (id, devnum); + int type = id->get_widget_type (devnum, num, 0, 0); + int i; + if (type == IDEV_WIDGET_BUTTON) { + i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET; + uid->eventid[i][sub] = eventid; + uid->flags[i][sub] = flags; + xfree (uid->custom[i][sub]); + uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; + return i; + } else if (type == IDEV_WIDGET_AXIS) { + i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET; + uid->eventid[i][sub] = eventid; + uid->flags[i][sub] = flags; + xfree (uid->custom[i][sub]); + uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; + return i; + } else if (type == IDEV_WIDGET_KEY) { + i = num - id->get_widget_first (devnum, type); + uid->eventid[i][sub] = eventid; + uid->flags[i][sub] = flags; + xfree (uid->custom[i][sub]); + uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? my_strdup (custom) : NULL; + return i; + } + return -1; } static int is_event_used (const struct inputdevice_functions *id, int devnum, int isnum, int isevent) { - struct uae_input_device *uid = get_uid (id, devnum); - int num, evt, flag, sub; - TCHAR *custom; + struct uae_input_device *uid = get_uid (id, devnum); + int num, evt, flag, sub; + TCHAR *custom; - for (num = 0; num < id->get_widget_num (devnum); num++) { - for (sub = 0; sub < MAX_INPUT_SUB_EVENT; sub++) { - if (get_event_data (id, devnum, num, &evt, &custom, &flag, sub) >= 0) { - if (evt == isevent && isnum != num) - return 1; - } + for (num = 0; num < id->get_widget_num (devnum); num++) { + for (sub = 0; sub < MAX_INPUT_SUB_EVENT; sub++) { + if (get_event_data (id, devnum, num, &evt, &custom, &flag, sub) >= 0) { + if (evt == isevent && isnum != num) + return 1; + } + } } - } - return 0; + return 0; } int inputdevice_get_device_index (int devnum) { - if (devnum < idev[IDTYPE_JOYSTICK].get_num()) - return devnum; - else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num()) - return devnum - idev[IDTYPE_JOYSTICK].get_num(); - else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num()) - return devnum - idev[IDTYPE_JOYSTICK].get_num() - idev[IDTYPE_MOUSE].get_num(); - else - return -1; + if (devnum < idev[IDTYPE_JOYSTICK].get_num()) + return devnum; + else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num()) + return devnum - idev[IDTYPE_JOYSTICK].get_num(); + else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num()) + return devnum - idev[IDTYPE_JOYSTICK].get_num() - idev[IDTYPE_MOUSE].get_num(); + else + return -1; } static int gettype (int devnum) { - if (devnum < idev[IDTYPE_JOYSTICK].get_num()) - return IDTYPE_JOYSTICK; - else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num()) - return IDTYPE_MOUSE; - else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num()) - return IDTYPE_KEYBOARD; - else - return -1; + if (devnum < idev[IDTYPE_JOYSTICK].get_num()) + return IDTYPE_JOYSTICK; + else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num()) + return IDTYPE_MOUSE; + else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num()) + return IDTYPE_KEYBOARD; + else + return -1; } static struct inputdevice_functions *getidf (int devnum) { - int type = gettype (devnum); - if (type < 0) - return NULL; - return &idev[type]; + int type = gettype (devnum); + if (type < 0) + return NULL; + return &idev[type]; } /* returns number of devices of type "type" */ int inputdevice_get_device_total (int type) { - return idev[type].get_num (); + return idev[type].get_num (); } /* returns the name of device */ TCHAR *inputdevice_get_device_name (int type, int devnum) { - return idev[type].get_friendlyname (devnum); + return idev[type].get_friendlyname (devnum); } /* returns machine readable name of device */ TCHAR *inputdevice_get_device_unique_name (int type, int devnum) { - return idev[type].get_uniquename (devnum); + return idev[type].get_uniquename (devnum); } /* returns state (enabled/disabled) */ int inputdevice_get_device_status (int devnum) { - const struct inputdevice_functions *idf = getidf (devnum); - struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); - return uid->enabled; + const struct inputdevice_functions *idf = getidf (devnum); + struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); + return uid->enabled; } /* set state (enabled/disabled) */ void inputdevice_set_device_status (int devnum, int enabled) { - const struct inputdevice_functions *idf = getidf (devnum); - struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); - uid->enabled = enabled; + const struct inputdevice_functions *idf = getidf (devnum); + struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); + uid->enabled = enabled; } /* returns number of axis/buttons and keys from selected device */ int inputdevice_get_widget_num (int devnum) { - const struct inputdevice_functions *idf = getidf (devnum); - return idf->get_widget_num (inputdevice_get_device_index (devnum)); + const struct inputdevice_functions *idf = getidf (devnum); + return idf->get_widget_num (inputdevice_get_device_index (devnum)); } static void get_ename (const struct inputevent *ie, TCHAR *out) { - if (!out) - return; - if (ie->allow_mask == AM_K) - _stprintf (out, L"%s (0x%02X)", ie->name, ie->data); - else - _tcscpy (out, ie->name); + if (!out) + return; + if (ie->allow_mask == AM_K) + _stprintf (out, L"%s (0x%02X)", ie->name, ie->data); + else + _tcscpy (out, ie->name); } int inputdevice_iterate (int devnum, int num, TCHAR *name, int *af) { - const struct inputdevice_functions *idf = getidf (devnum); - static int id_iterator; - struct inputevent *ie; - int mask, data, flags, type; - int devindex = inputdevice_get_device_index (devnum); - TCHAR *custom; - - *af = 0; - *name = 0; - for (;;) { - ie = &events[++id_iterator]; - if (!ie->confname) { - id_iterator = 0; - return 0; - } - mask = 0; - type = idf->get_widget_type (devindex, num, 0, 0); - if (type == IDEV_WIDGET_BUTTON) { - if (idf == &idev[IDTYPE_JOYSTICK]) { - mask |= AM_JOY_BUT; - } else { - mask |= AM_MOUSE_BUT; - } - } else if (type == IDEV_WIDGET_AXIS) { - if (idf == &idev[IDTYPE_JOYSTICK]) { - mask |= AM_JOY_AXIS; - } else { - mask |= AM_MOUSE_AXIS; - } - } else if (type == IDEV_WIDGET_KEY) { - mask |= AM_K; - } - if (ie->allow_mask & AM_INFO) { - struct inputevent *ie2 = ie + 1; - while (!(ie2->allow_mask & AM_INFO)) { - if (is_event_used (idf, devindex, ie2 - ie, -1)) { - ie2++; - continue; + const struct inputdevice_functions *idf = getidf (devnum); + static int id_iterator; + struct inputevent *ie; + int mask, data, flags, type; + int devindex = inputdevice_get_device_index (devnum); + TCHAR *custom; + + *af = 0; + *name = 0; + for (;;) { + ie = &events[++id_iterator]; + if (!ie->confname) { + id_iterator = 0; + return 0; } - if (ie2->allow_mask & mask) - break; - ie2++; - } - if (!(ie2->allow_mask & AM_INFO)) - mask |= AM_INFO; - } - if (!(ie->allow_mask & mask)) - continue; - get_event_data (idf, devindex, num, &data, &custom, &flags, 0); - get_ename (ie, name); - *af = (flags & ID_FLAG_AUTOFIRE) ? 1 : 0; - return 1; - } + mask = 0; + type = idf->get_widget_type (devindex, num, 0, 0); + if (type == IDEV_WIDGET_BUTTON) { + if (idf == &idev[IDTYPE_JOYSTICK]) { + mask |= AM_JOY_BUT; + } else { + mask |= AM_MOUSE_BUT; + } + } else if (type == IDEV_WIDGET_AXIS) { + if (idf == &idev[IDTYPE_JOYSTICK]) { + mask |= AM_JOY_AXIS; + } else { + mask |= AM_MOUSE_AXIS; + } + } else if (type == IDEV_WIDGET_KEY) { + mask |= AM_K; + } + if (ie->allow_mask & AM_INFO) { + struct inputevent *ie2 = ie + 1; + while (!(ie2->allow_mask & AM_INFO)) { + if (is_event_used (idf, devindex, ie2 - ie, -1)) { + ie2++; + continue; + } + if (ie2->allow_mask & mask) + break; + ie2++; + } + if (!(ie2->allow_mask & AM_INFO)) + mask |= AM_INFO; + } + if (!(ie->allow_mask & mask)) + continue; + get_event_data (idf, devindex, num, &data, &custom, &flags, 0); + get_ename (ie, name); + *af = (flags & ID_FLAG_AUTOFIRE) ? 1 : 0; + return 1; + } } int inputdevice_get_mapped_name (int devnum, int num, int *pflags, TCHAR *name, TCHAR *custom, int sub) { - const struct inputdevice_functions *idf = getidf (devnum); - const struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); - int flags = 0, flag, data; - int devindex = inputdevice_get_device_index (devnum); - TCHAR *customp = NULL; - - if (name) - _tcscpy (name, L""); - if (custom) - custom[0] = 0; - if (pflags) - *pflags = 0; - if (uid == 0 || num < 0) - return 0; - if (get_event_data (idf, devindex, num, &data, &customp, &flag, sub) < 0) - return 0; - if (customp && custom) - _tcscpy (custom, customp); - if (flag & ID_FLAG_AUTOFIRE) - flags |= IDEV_MAPPED_AUTOFIRE_SET; - if (flag & ID_FLAG_TOGGLE) - flags |= IDEV_MAPPED_TOGGLE; - if (!data) - return 0; - if (events[data].allow_mask & AM_AF) - flags |= IDEV_MAPPED_AUTOFIRE_POSSIBLE; - if (pflags) - *pflags = flags; - get_ename (&events[data], name); - return data; + const struct inputdevice_functions *idf = getidf (devnum); + const struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); + int flags = 0, flag, data; + int devindex = inputdevice_get_device_index (devnum); + TCHAR *customp = NULL; + + if (name) + _tcscpy (name, L""); + if (custom) + custom[0] = 0; + if (pflags) + *pflags = 0; + if (uid == 0 || num < 0) + return 0; + if (get_event_data (idf, devindex, num, &data, &customp, &flag, sub) < 0) + return 0; + if (customp && custom) + _tcscpy (custom, customp); + if (flag & ID_FLAG_AUTOFIRE) + flags |= IDEV_MAPPED_AUTOFIRE_SET; + if (flag & ID_FLAG_TOGGLE) + flags |= IDEV_MAPPED_TOGGLE; + if (!data) + return 0; + if (events[data].allow_mask & AM_AF) + flags |= IDEV_MAPPED_AUTOFIRE_POSSIBLE; + if (pflags) + *pflags = flags; + get_ename (&events[data], name); + return data; } int inputdevice_set_mapping (int devnum, int num, TCHAR *name, TCHAR *custom, int flags, int sub) { - const struct inputdevice_functions *idf = getidf (devnum); - const struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); - int eid, data, flag, amask; - TCHAR ename[256]; - int devindex = inputdevice_get_device_index (devnum); - TCHAR *customp = NULL; + const struct inputdevice_functions *idf = getidf (devnum); + const struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); + int eid, data, flag, amask; + TCHAR ename[256]; + int devindex = inputdevice_get_device_index (devnum); + TCHAR *customp = NULL; - if (uid == 0 || num < 0) - return 0; - if (name) { - eid = 1; - while (events[eid].name) { - get_ename (&events[eid], ename); - if (!_tcscmp(ename, name)) break; - eid++; - } - if (!events[eid].name) - return 0; - if (events[eid].allow_mask & AM_INFO) - return 0; - } else { - eid = 0; - } - if (get_event_data (idf, devindex, num, &data, &customp, &flag, sub) < 0) + if (uid == 0 || num < 0) + return 0; + if (name) { + eid = 1; + while (events[eid].name) { + get_ename (&events[eid], ename); + if (!_tcscmp(ename, name)) break; + eid++; + } + if (!events[eid].name) + return 0; + if (events[eid].allow_mask & AM_INFO) + return 0; + } else { + eid = 0; + } + if (get_event_data (idf, devindex, num, &data, &customp, &flag, sub) < 0) + return 0; + if (data >= 0) { + amask = events[eid].allow_mask; + flag &= ~(ID_FLAG_AUTOFIRE | ID_FLAG_TOGGLE); + if (amask & AM_AF) { + flag |= (flags & IDEV_MAPPED_AUTOFIRE_SET) ? ID_FLAG_AUTOFIRE : 0; + flag |= (flags & IDEV_MAPPED_TOGGLE) ? ID_FLAG_TOGGLE : 0; + } + put_event_data (idf, devindex, num, eid, custom, flag, sub); + return 1; + } return 0; - if (data >= 0) { - amask = events[eid].allow_mask; - flag &= ~(ID_FLAG_AUTOFIRE | ID_FLAG_TOGGLE); - if (amask & AM_AF) { - flag |= (flags & IDEV_MAPPED_AUTOFIRE_SET) ? ID_FLAG_AUTOFIRE : 0; - flag |= (flags & IDEV_MAPPED_TOGGLE) ? ID_FLAG_TOGGLE : 0; - } - put_event_data (idf, devindex, num, eid, custom, flag, sub); - return 1; - } - return 0; } int inputdevice_get_widget_type (int devnum, int num, TCHAR *name) { - const struct inputdevice_functions *idf = getidf (devnum); - return idf->get_widget_type (inputdevice_get_device_index (devnum), num, name, 0); + const struct inputdevice_functions *idf = getidf (devnum); + return idf->get_widget_type (inputdevice_get_device_index (devnum), num, name, 0); } static int config_change; void inputdevice_config_change (void) { - config_change = 1; + config_change = 1; } int inputdevice_config_change_test (void) { - int v = config_change; - config_change = 0; - return v; + int v = config_change; + config_change = 0; + return v; } void inputdevice_copyconfig (const struct uae_prefs *src, struct uae_prefs *dst) { - int i, j; + int i, j; - dst->input_selected_setting = src->input_selected_setting; - dst->input_joymouse_multiplier = src->input_joymouse_multiplier; - dst->input_joymouse_deadzone = src->input_joymouse_deadzone; - dst->input_joystick_deadzone = src->input_joystick_deadzone; - dst->input_joymouse_speed = src->input_joymouse_speed; - dst->input_mouse_speed = src->input_mouse_speed; - dst->input_autofire_framecnt = src->input_autofire_framecnt; - copyjport (src, dst, 0); - copyjport (src, dst, 1); + dst->input_selected_setting = src->input_selected_setting; + dst->input_joymouse_multiplier = src->input_joymouse_multiplier; + dst->input_joymouse_deadzone = src->input_joymouse_deadzone; + dst->input_joystick_deadzone = src->input_joystick_deadzone; + dst->input_joymouse_speed = src->input_joymouse_speed; + dst->input_mouse_speed = src->input_mouse_speed; + dst->input_autofire_framecnt = src->input_autofire_framecnt; + copyjport (src, dst, 0); + copyjport (src, dst, 1); - for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - memcpy (&dst->joystick_settings[i][j], &src->joystick_settings[i][j], sizeof (struct uae_input_device)); - memcpy (&dst->mouse_settings[i][j], &src->mouse_settings[i][j], sizeof (struct uae_input_device)); - memcpy (&dst->keyboard_settings[i][j], &src->keyboard_settings[i][j], sizeof (struct uae_input_device)); + for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) { + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + memcpy (&dst->joystick_settings[i][j], &src->joystick_settings[i][j], sizeof (struct uae_input_device)); + memcpy (&dst->mouse_settings[i][j], &src->mouse_settings[i][j], sizeof (struct uae_input_device)); + memcpy (&dst->keyboard_settings[i][j], &src->keyboard_settings[i][j], sizeof (struct uae_input_device)); + } } - } - inputdevice_updateconfig (dst); + inputdevice_updateconfig (dst); } void inputdevice_swap_ports (struct uae_prefs *p, int devnum) { - const struct inputdevice_functions *idf = getidf (devnum); - struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); - int i, j, k, event, unit; - const struct inputevent *ie, *ie2; + const struct inputdevice_functions *idf = getidf (devnum); + struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum)); + int i, j, k, event, unit; + const struct inputevent *ie, *ie2; - for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { - for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { - event = uid->eventid[i][j]; - if (event <= 0) - continue; - ie = &events[event]; - if (ie->unit <= 0) - continue; - unit = ie->unit; - k = 1; - while (events[k].confname) { - ie2 = &events[k]; - if (ie2->type == ie->type && ie2->data == ie->data && ie2->unit - 1 == ((ie->unit - 1) ^ 1) && ie2->allow_mask == ie->allow_mask) { - uid->eventid[i][j] = k; - break; + for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { + for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) { + event = uid->eventid[i][j]; + if (event <= 0) + continue; + ie = &events[event]; + if (ie->unit <= 0) + continue; + unit = ie->unit; + k = 1; + while (events[k].confname) { + ie2 = &events[k]; + if (ie2->type == ie->type && ie2->data == ie->data && ie2->unit - 1 == ((ie->unit - 1) ^ 1) && ie2->allow_mask == ie->allow_mask) { + uid->eventid[i][j] = k; + break; + } + k++; + } } - k++; - } } - } } void inputdevice_copy_single_config (struct uae_prefs *p, int src, int dst, int devnum) { - if (src == dst) - return; - if (devnum < 0 || gettype (devnum) == IDTYPE_JOYSTICK) - memcpy (p->joystick_settings[dst], p->joystick_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); - if (devnum < 0 || gettype (devnum) == IDTYPE_MOUSE) - memcpy (p->mouse_settings[dst], p->mouse_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); - if (devnum < 0 || gettype (devnum) == IDTYPE_KEYBOARD) - memcpy (p->keyboard_settings[dst], p->keyboard_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); + if (src == dst) + return; + if (devnum < 0 || gettype (devnum) == IDTYPE_JOYSTICK) + memcpy (p->joystick_settings[dst], p->joystick_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); + if (devnum < 0 || gettype (devnum) == IDTYPE_MOUSE) + memcpy (p->mouse_settings[dst], p->mouse_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); + if (devnum < 0 || gettype (devnum) == IDTYPE_KEYBOARD) + memcpy (p->keyboard_settings[dst], p->keyboard_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES); } void inputdevice_acquire (int allmode) { - int i; - - inputdevice_unacquire (); - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (use_joysticks[i] || (allmode && !idev[IDTYPE_JOYSTICK].get_flags (i))) - idev[IDTYPE_JOYSTICK].acquire (i, 0); - } - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (use_mice[i] || (allmode && !idev[IDTYPE_MOUSE].get_flags (i))) - idev[IDTYPE_MOUSE].acquire (i, 0); - } - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (use_keyboards[i]) - idev[IDTYPE_KEYBOARD].acquire (i, 0); - } -// if (!input_acquired) -// write_log (L"input devices acquired (%s)\n", allmode ? "all" : "selected only"); - input_acquired = 1; + int i; + + inputdevice_unacquire (); + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + if (use_joysticks[i] || (allmode && !idev[IDTYPE_JOYSTICK].get_flags (i))) + idev[IDTYPE_JOYSTICK].acquire (i, 0); + } + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + if (use_mice[i] || (allmode && !idev[IDTYPE_MOUSE].get_flags (i))) + idev[IDTYPE_MOUSE].acquire (i, 0); + } + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + if (use_keyboards[i]) + idev[IDTYPE_KEYBOARD].acquire (i, 0); + } + // if (!input_acquired) + // write_log (L"input devices acquired (%s)\n", allmode ? "all" : "selected only"); + input_acquired = 1; } void inputdevice_unacquire (void) { - int i; + int i; -// if (input_acquired) -// write_log (L"input devices unacquired\n"); - input_acquired = 0; - for (i = 0; i < MAX_INPUT_DEVICES; i++) - idev[IDTYPE_JOYSTICK].unacquire (i); - for (i = 0; i < MAX_INPUT_DEVICES; i++) - idev[IDTYPE_MOUSE].unacquire (i); - for (i = 0; i < MAX_INPUT_DEVICES; i++) - idev[IDTYPE_KEYBOARD].unacquire (i); + // if (input_acquired) + // write_log (L"input devices unacquired\n"); + input_acquired = 0; + for (i = 0; i < MAX_INPUT_DEVICES; i++) + idev[IDTYPE_JOYSTICK].unacquire (i); + for (i = 0; i < MAX_INPUT_DEVICES; i++) + idev[IDTYPE_MOUSE].unacquire (i); + for (i = 0; i < MAX_INPUT_DEVICES; i++) + idev[IDTYPE_KEYBOARD].unacquire (i); } static void testrecord (int type, int num, int wtype, int wnum, int state) { - TCHAR tmp[2000]; - tmp[0] = 0; - wnum += idev[type].get_widget_first (num, wtype); - idev[type].get_widget_type (num, wnum, tmp, NULL); - write_log (L"%s: %s %d\n", idev[type].get_friendlyname (num), tmp, state); + TCHAR tmp[2000]; + tmp[0] = 0; + wnum += idev[type].get_widget_first (num, wtype); + idev[type].get_widget_type (num, wnum, tmp, NULL); + write_log (L"%s: %s %d\n", idev[type].get_friendlyname (num), tmp, state); } int inputdevice_istest (void) { - return testmode; + return testmode; } int inputdevice_testread (TCHAR *name) { - testmode = 1; - idev[IDTYPE_KEYBOARD].read (); - idev[IDTYPE_JOYSTICK].read (); - idev[IDTYPE_MOUSE].read (); - testmode = 0; - return 0; + testmode = 1; + idev[IDTYPE_KEYBOARD].read (); + idev[IDTYPE_JOYSTICK].read (); + idev[IDTYPE_MOUSE].read (); + testmode = 0; + return 0; } static int ignoreoldinput (int joy) { - if (!use_joysticks[joy]) + if (!use_joysticks[joy]) + return 0; + if (currprefs.input_selected_setting == 0) { + if (jsem_isjoy (0, &currprefs) != joy && jsem_isjoy (1, &currprefs) != joy && + jsem_isjoy (2, &currprefs) != joy && jsem_isjoy (3, &currprefs) != joy) + return 1; + } return 0; - if (currprefs.input_selected_setting == 0) { - if (jsem_isjoy (0, &currprefs) != joy && jsem_isjoy (1, &currprefs) != joy && - jsem_isjoy (2, &currprefs) != joy && jsem_isjoy (3, &currprefs) != joy) - return 1; - } - return 0; } void do_fake_joystick (int nr, int *fake) { - struct uae_input_device *id1; - struct uae_input_device2 *id2; - int state, i, axis; + struct uae_input_device *id1; + struct uae_input_device2 *id2; + int state, i, axis; - nr = compatibility_device[nr]; - id1 = &joysticks[nr]; - id2 = &joysticks2[nr]; + nr = compatibility_device[nr]; + id1 = &joysticks[nr]; + id2 = &joysticks2[nr]; - axis = 0; - state = fake[1] ? -1 : (fake[2] ? 1 : 0); - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) - handle_input_event (id1->eventid[ID_AXIS_OFFSET + axis][i], state, 1, - id1->flags[ID_AXIS_OFFSET + axis][i]); - id2->states[axis] = state; + axis = 0; + state = fake[1] ? -1 : (fake[2] ? 1 : 0); + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) + handle_input_event (id1->eventid[ID_AXIS_OFFSET + axis][i], state, 1, + id1->flags[ID_AXIS_OFFSET + axis][i]); + id2->states[axis] = state; - axis = 1; - state = fake[0] ? -1 : (fake[3] ? 1 : 0); - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) - handle_input_event (id1->eventid[ID_AXIS_OFFSET + axis][i], state, 1, - id1->flags[ID_AXIS_OFFSET + axis][i]); - id2->states[axis] = state; + axis = 1; + state = fake[0] ? -1 : (fake[3] ? 1 : 0); + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) + handle_input_event (id1->eventid[ID_AXIS_OFFSET + axis][i], state, 1, + id1->flags[ID_AXIS_OFFSET + axis][i]); + id2->states[axis] = state; - setbuttonstateall (id1, id2, 0, fake[4] ? 1 : 0); - setbuttonstateall (id1, id2, 1, fake[5] ? 1 : 0); - setbuttonstateall (id1, id2, 2, fake[6] ? 1 : 0); + setbuttonstateall (id1, id2, 0, fake[4] ? 1 : 0); + setbuttonstateall (id1, id2, 1, fake[5] ? 1 : 0); + setbuttonstateall (id1, id2, 2, fake[6] ? 1 : 0); } /* Call this function when host machine's joystick/joypad/etc button state changes - * This function translates button events to Amiga joybutton/joyaxis/keyboard events - */ +* This function translates button events to Amiga joybutton/joyaxis/keyboard events +*/ /* button states: - * state = -1 -> mouse wheel turned or similar (button without release) - * state = 1 -> button pressed - * state = 0 -> button released - */ +* state = -1 -> mouse wheel turned or similar (button without release) +* state = 1 -> button pressed +* state = 0 -> button released +*/ void setjoybuttonstate (int joy, int button, int state) { - if (ignoreoldinput (joy)) { - if (state) - switchdevice (&joysticks[joy], button, 1); - return; - } - setbuttonstateall (&joysticks[joy], &joysticks2[joy], button, state ? 1 : 0); + if (ignoreoldinput (joy)) { + if (state) + switchdevice (&joysticks[joy], button, 1); + return; + } + setbuttonstateall (&joysticks[joy], &joysticks2[joy], button, state ? 1 : 0); } /* buttonmask = 1 = normal toggle button, 0 = mouse wheel turn or similar - */ +*/ void setjoybuttonstateall (int joy, uae_u32 buttonbits, uae_u32 buttonmask) { - int i; + int i; - if (ignoreoldinput (joy)) - return; - for (i = 0; i < ID_BUTTON_TOTAL; i++) { - if (buttonmask & (1 << i)) - setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, (buttonbits & (1 << i)) ? 1 : 0); - else if (buttonbits & (1 << i)) - setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, -1); - } + if (ignoreoldinput (joy)) + return; + for (i = 0; i < ID_BUTTON_TOTAL; i++) { + if (buttonmask & (1 << i)) + setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, (buttonbits & (1 << i)) ? 1 : 0); + else if (buttonbits & (1 << i)) + setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, -1); + } } /* mouse buttons (just like joystick buttons) - */ +*/ void setmousebuttonstateall (int mouse, uae_u32 buttonbits, uae_u32 buttonmask) { - int i; + int i; - for (i = 0; i < ID_BUTTON_TOTAL; i++) { - if (buttonmask & (1 << i)) - setbuttonstateall (&mice[mouse], &mice2[mouse], i, (buttonbits & (1 << i)) ? 1 : 0); - else if (buttonbits & (1 << i)) - setbuttonstateall (&mice[mouse], &mice2[mouse], i, -1); - } + for (i = 0; i < ID_BUTTON_TOTAL; i++) { + if (buttonmask & (1 << i)) + setbuttonstateall (&mice[mouse], &mice2[mouse], i, (buttonbits & (1 << i)) ? 1 : 0); + else if (buttonbits & (1 << i)) + setbuttonstateall (&mice[mouse], &mice2[mouse], i, -1); + } } void setmousebuttonstate (int mouse, int button, int state) { - if (testmode) { - testrecord (IDTYPE_MOUSE, mouse, IDEV_WIDGET_BUTTON, button, state); - return; - } - setbuttonstateall (&mice[mouse], &mice2[mouse], button, state); + if (testmode) { + testrecord (IDTYPE_MOUSE, mouse, IDEV_WIDGET_BUTTON, button, state); + return; + } + setbuttonstateall (&mice[mouse], &mice2[mouse], button, state); } /* same for joystick axis (analog or digital) - * (0 = center, -max = full left/top, max = full right/bottom) - */ +* (0 = center, -max = full left/top, max = full right/bottom) +*/ void setjoystickstate (int joy, int axis, int state, int max) { - struct uae_input_device *id = &joysticks[joy]; - struct uae_input_device2 *id2 = &joysticks2[joy]; - int deadzone = currprefs.input_joymouse_deadzone * max / 100; - int i, v1, v2; - - if (testmode) { - testrecord (IDTYPE_JOYSTICK, joy, IDEV_WIDGET_AXIS, axis, state); - return; - } - v1 = state; - v2 = id2->states[axis]; - if (v1 < deadzone && v1 > -deadzone) - v1 = 0; - if (v2 < deadzone && v2 > -deadzone) - v2 = 0; - if (v1 == v2) - return; - if (!joysticks[joy].enabled || ignoreoldinput(joy)) { - if (v1) - switchdevice (&joysticks[joy], axis * 2 + (v1 < 0 ? 0 : 1), 0); - return; - } - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) - handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], state, max, - id->flags[ID_AXIS_OFFSET + axis][i]); - id2->states[axis] = state; + struct uae_input_device *id = &joysticks[joy]; + struct uae_input_device2 *id2 = &joysticks2[joy]; + int deadzone = currprefs.input_joymouse_deadzone * max / 100; + int i, v1, v2; + + if (testmode) { + testrecord (IDTYPE_JOYSTICK, joy, IDEV_WIDGET_AXIS, axis, state); + return; + } + v1 = state; + v2 = id2->states[axis]; + if (v1 < deadzone && v1 > -deadzone) + v1 = 0; + if (v2 < deadzone && v2 > -deadzone) + v2 = 0; + if (v1 == v2) + return; + if (!joysticks[joy].enabled || ignoreoldinput(joy)) { + if (v1) + switchdevice (&joysticks[joy], axis * 2 + (v1 < 0 ? 0 : 1), 0); + return; + } + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) + handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], state, max, + id->flags[ID_AXIS_OFFSET + axis][i]); + id2->states[axis] = state; } int getjoystickstate(int joy) { - if (testmode) - return 1; - return joysticks[joy].enabled; + if (testmode) + return 1; + return joysticks[joy].enabled; } void setmousestate (int mouse, int axis, int data, int isabs) { - int i, v, diff; - int *mouse_p, *oldm_p; - double d; - struct uae_input_device *id = &mice[mouse]; - static double fract[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS]; - - if (testmode) { - testrecord (IDTYPE_MOUSE, mouse, IDEV_WIDGET_AXIS, axis, data); - return; - } - if (!mice[mouse].enabled) { - if (isabs && currprefs.input_tablet > 0) { - if (axis == 0) - lastmx = data; - else - lastmy = data; - if (axis) - mousehack_helper (); - } - return; - } - d = 0; - mouse_p = &mouse_axis[mouse][axis]; - oldm_p = &oldm_axis[mouse][axis]; - if (!isabs) { - *oldm_p = *mouse_p; - *mouse_p += data; - d = (*mouse_p - *oldm_p) * currprefs.input_mouse_speed / 100.0; - } else { - d = data - *oldm_p; - *oldm_p = data; - *mouse_p += d; - if (axis == 0) - lastmx = data; - else - lastmy = data; - if (axis) - mousehack_helper (); - if (currprefs.input_tablet == TABLET_MOUSEHACK && mousehack_alive ()) - return; - } - v = (int)d; - fract[mouse][axis] += d - v; - diff = (int)fract[mouse][axis]; - v += diff; - fract[mouse][axis] -= diff; - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) - handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], v, 0, 0); + int i, v, diff; + int *mouse_p, *oldm_p; + double d; + struct uae_input_device *id = &mice[mouse]; + static double fract[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS]; + + if (testmode) { + testrecord (IDTYPE_MOUSE, mouse, IDEV_WIDGET_AXIS, axis, data); + return; + } + if (!mice[mouse].enabled) { + if (isabs && currprefs.input_tablet > 0) { + if (axis == 0) + lastmx = data; + else + lastmy = data; + if (axis) + mousehack_helper (); + } + return; + } + d = 0; + mouse_p = &mouse_axis[mouse][axis]; + oldm_p = &oldm_axis[mouse][axis]; + if (!isabs) { + *oldm_p = *mouse_p; + *mouse_p += data; + d = (*mouse_p - *oldm_p) * currprefs.input_mouse_speed / 100.0; + } else { + d = data - *oldm_p; + *oldm_p = data; + *mouse_p += d; + if (axis == 0) + lastmx = data; + else + lastmy = data; + if (axis) + mousehack_helper (); + if (currprefs.input_tablet == TABLET_MOUSEHACK && mousehack_alive ()) + return; + } + v = (int)d; + fract[mouse][axis] += d - v; + diff = (int)fract[mouse][axis]; + v += diff; + fract[mouse][axis] -= diff; + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) + handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], v, 0, 0); } int getmousestate (int joy) { - if (testmode) - return 1; - return mice[joy].enabled; + if (testmode) + return 1; + return mice[joy].enabled; } void warpmode (int mode) { - int fr, fr2; - - fr = currprefs.gfx_framerate; - if (fr == 0) - fr = -1; - fr2 = currprefs.turbo_emulation; - if (fr2 == -1) - fr2 = 0; + int fr, fr2; + + fr = currprefs.gfx_framerate; + if (fr == 0) + fr = -1; + fr2 = currprefs.turbo_emulation; + if (fr2 == -1) + fr2 = 0; - if (mode < 0) { + if (mode < 0) { + if (currprefs.turbo_emulation) { + changed_prefs.gfx_framerate = currprefs.gfx_framerate = fr2; + currprefs.turbo_emulation = 0; + } else { + currprefs.turbo_emulation = fr; + } + } else if (mode == 0 && currprefs.turbo_emulation) { + if (currprefs.turbo_emulation > 0) + changed_prefs.gfx_framerate = currprefs.gfx_framerate = fr2; + currprefs.turbo_emulation = 0; + } else if (mode > 0 && !currprefs.turbo_emulation) { + currprefs.turbo_emulation = fr; + } if (currprefs.turbo_emulation) { - changed_prefs.gfx_framerate = currprefs.gfx_framerate = fr2; - currprefs.turbo_emulation = 0; + if (!currprefs.cpu_cycle_exact && !currprefs.blitter_cycle_exact) + changed_prefs.gfx_framerate = currprefs.gfx_framerate = 10; + pause_sound (); } else { - currprefs.turbo_emulation = fr; - } - } else if (mode == 0 && currprefs.turbo_emulation) { - if (currprefs.turbo_emulation > 0) - changed_prefs.gfx_framerate = currprefs.gfx_framerate = fr2; - currprefs.turbo_emulation = 0; - } else if (mode > 0 && !currprefs.turbo_emulation) { - currprefs.turbo_emulation = fr; - } - if (currprefs.turbo_emulation) { - if (!currprefs.cpu_cycle_exact && !currprefs.blitter_cycle_exact) - changed_prefs.gfx_framerate = currprefs.gfx_framerate = 10; - pause_sound (); - } else { - resume_sound (); - } - compute_vsynctime (); + resume_sound (); + } + compute_vsynctime (); #ifdef RETROPLATFORM - rp_turbo (currprefs.turbo_emulation); + rp_turbo (currprefs.turbo_emulation); #endif } void pausemode (int mode) { - if (mode < 0) - pause_emulation = pause_emulation ? 0 : 1; - else - pause_emulation = mode; + if (mode < 0) + pause_emulation = pause_emulation ? 0 : 9; + else + pause_emulation = mode; } int jsem_isjoy (int port, const struct uae_prefs *p) { - int v = JSEM_DECODEVAL (port, p); - if (v < JSEM_JOYS) - return -1; - v -= JSEM_JOYS; - if (v >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) - return -1; - return v; + int v = JSEM_DECODEVAL (port, p); + if (v < JSEM_JOYS) + return -1; + v -= JSEM_JOYS; + if (v >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) + return -1; + return v; } int jsem_ismouse (int port, const struct uae_prefs *p) { - int v = JSEM_DECODEVAL (port, p); - if (v < JSEM_MICE) - return -1; - v -= JSEM_MICE; - if (v >= inputdevice_get_device_total (IDTYPE_MOUSE)) - return -1; - return v; + int v = JSEM_DECODEVAL (port, p); + if (v < JSEM_MICE) + return -1; + v -= JSEM_MICE; + if (v >= inputdevice_get_device_total (IDTYPE_MOUSE)) + return -1; + return v; } int jsem_iskbdjoy (int port, const struct uae_prefs *p) { - int v = JSEM_DECODEVAL (port, p); - if (v < JSEM_KBDLAYOUT) - return -1; - v -= JSEM_KBDLAYOUT; - if (v >= JSEM_LASTKBD) - return -1; - return v; + int v = JSEM_DECODEVAL (port, p); + if (v < JSEM_KBDLAYOUT) + return -1; + v -= JSEM_KBDLAYOUT; + if (v >= JSEM_LASTKBD) + return -1; + return v; } int inputdevice_joyport_config (struct uae_prefs *p, TCHAR *value, int portnum, int mode, int type) { - switch (type) - { + switch (type) + { case 1: case 2: - { - int i, j; - for (j = 0; j < MAX_JPORTS; j++) { - struct inputdevice_functions *idf; - int type = IDTYPE_MOUSE; - int idnum = JSEM_MICE; - if (j == 0) { - type = IDTYPE_JOYSTICK; - idnum = JSEM_JOYS; - } - idf = &idev[type]; - for (i = 0; i < idf->get_num (); i++) { - TCHAR *name1 = idf->get_friendlyname (i); - TCHAR *name2 = idf->get_uniquename (i); - if ((name1 && !_tcscmp (name1, value)) || (name2 && !_tcscmp (name2, value))) { - p->jports[portnum].id = idnum + i; - if (mode >= 0) - p->jports[portnum].mode = mode; - return 1; - } + { + int i, j; + for (j = 0; j < MAX_JPORTS; j++) { + struct inputdevice_functions *idf; + int type = IDTYPE_MOUSE; + int idnum = JSEM_MICE; + if (j == 0) { + type = IDTYPE_JOYSTICK; + idnum = JSEM_JOYS; + } + idf = &idev[type]; + for (i = 0; i < idf->get_num (); i++) { + TCHAR *name1 = idf->get_friendlyname (i); + TCHAR *name2 = idf->get_uniquename (i); + if ((name1 && !_tcscmp (name1, value)) || (name2 && !_tcscmp (name2, value))) { + p->jports[portnum].id = idnum + i; + if (mode >= 0) + p->jports[portnum].mode = mode; + return 1; + } + } + } } - } - } - break; + break; case 0: - { - int start = -1, got = 0; - TCHAR *pp = 0; - if (_tcsncmp (value, L"kbd", 3) == 0) { - start = JSEM_KBDLAYOUT; - pp = value + 3; - got = 1; - } else if (_tcsncmp (value, L"joy", 3) == 0) { - start = JSEM_JOYS; - pp = value + 3; - got = 1; - } else if (_tcsncmp (value, L"mouse", 5) == 0) { - start = JSEM_MICE; - pp = value + 5; - got = 1; - } else if (_tcscmp (value, L"none") == 0) { - got = 2; - } - if (got) { - if (pp) { - int v = _tstol (pp); - if (start >= 0) { - if (start == JSEM_KBDLAYOUT && v > 0) - v--; - if (v >= 0) { - start += v; - got = 2; + { + int start = -1, got = 0; + TCHAR *pp = 0; + if (_tcsncmp (value, L"kbd", 3) == 0) { + start = JSEM_KBDLAYOUT; + pp = value + 3; + got = 1; + } else if (_tcsncmp (value, L"joy", 3) == 0) { + start = JSEM_JOYS; + pp = value + 3; + got = 1; + } else if (_tcsncmp (value, L"mouse", 5) == 0) { + start = JSEM_MICE; + pp = value + 5; + got = 1; + } else if (_tcscmp (value, L"none") == 0) { + got = 2; + } + if (got) { + if (pp) { + int v = _tstol (pp); + if (start >= 0) { + if (start == JSEM_KBDLAYOUT && v > 0) + v--; + if (v >= 0) { + start += v; + got = 2; + } + } + } + if (got == 2) { + p->jports[portnum].id = start; + if (mode >= 0) + p->jports[portnum].mode = mode; + return 1; + } } - } - } - if (got == 2) { - p->jports[portnum].id = start; - if (mode >= 0) - p->jports[portnum].mode = mode; - return 1; } - } + break; } - break; - } - return 0; + return 0; } int inputdevice_getjoyportdevice (int jport) { - int idx; - if (jport < 0) { - idx = -1; - } else if (jport >= JSEM_MICE) { - idx = jport - JSEM_MICE; - if (idx >= inputdevice_get_device_total (IDTYPE_MOUSE)) - idx = 0; - else - idx += inputdevice_get_device_total (IDTYPE_JOYSTICK); - idx += JSEM_LASTKBD; - } else if (jport >= JSEM_JOYS) { - idx = jport - JSEM_JOYS; - if (idx >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) - idx = 0; - idx += JSEM_LASTKBD; - } else { - idx = jport - JSEM_KBDLAYOUT; - } - return idx; + int idx; + if (jport < 0) { + idx = -1; + } else if (jport >= JSEM_MICE) { + idx = jport - JSEM_MICE; + if (idx >= inputdevice_get_device_total (IDTYPE_MOUSE)) + idx = 0; + else + idx += inputdevice_get_device_total (IDTYPE_JOYSTICK); + idx += JSEM_LASTKBD; + } else if (jport >= JSEM_JOYS) { + idx = jport - JSEM_JOYS; + if (idx >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) + idx = 0; + idx += JSEM_LASTKBD; + } else { + idx = jport - JSEM_KBDLAYOUT; + } + return idx; } diff --git a/keybuf.c b/keybuf.c index 6e1ee819..b0c229f3 100644 --- a/keybuf.c +++ b/keybuf.c @@ -1,16 +1,16 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Keyboard buffer. Not really needed for X, but for SVGAlib and possibly - * Mac and DOS ports. - * - * Note: it's possible to have two threads in UAE, one reading keystrokes - * and the other one writing them. Despite this, no synchronization effort - * is needed. This code should be perfectly thread safe. At least if you - * assume that integer store instructions are atomic. - * - * Copyright 1995, 1997 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Keyboard buffer. Not really needed for X, but for SVGAlib and possibly +* Mac and DOS ports. +* +* Note: it's possible to have two threads in UAE, one reading keystrokes +* and the other one writing them. Despite this, no synchronization effort +* is needed. This code should be perfectly thread safe. At least if you +* assume that integer store instructions are atomic. +* +* Copyright 1995, 1997 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -36,209 +36,209 @@ static int keybuf[256]; int keys_available (void) { - int val; - val = kpb_first != kpb_last; - return val; + int val; + val = kpb_first != kpb_last; + return val; } int get_next_key (void) { - int key; - assert (kpb_first != kpb_last); + int key; + assert (kpb_first != kpb_last); - key = keybuf[kpb_last]; - if (++kpb_last == 256) - kpb_last = 0; - return key; + key = keybuf[kpb_last]; + if (++kpb_last == 256) + kpb_last = 0; + return key; } static void do_fake (int nr) { - int *fake = fakestate[nr]; - do_fake_joystick (nr, fake); + int *fake = fakestate[nr]; + do_fake_joystick (nr, fake); } int record_key (int kc) { - if (input_recording < 0 || pause_emulation) - return 0; - return record_key_direct (kc); + if (input_recording < 0 || pause_emulation) + return 0; + return record_key_direct (kc); } int record_key_direct (int kc) { - int fs = 0; - int kpb_next = kpb_first + 1; - int k = kc >> 1; - int b = !(kc & 1); - - //write_log (L"got kc %02X\n", ((kc << 7) | (kc >> 1)) & 0xff); - if (kpb_next == 256) - kpb_next = 0; - if (kpb_next == kpb_last) { - write_log (L"Keyboard buffer overrun. Congratulations.\n"); - return 0; - } - - if (fs_np != 0) { - switch (k) { - case AK_NP8: fs = 1; fs_np[0] = b; break; - case AK_NP4: fs = 1; fs_np[1] = b; break; - case AK_NP6: fs = 1; fs_np[2] = b; break; - case AK_NP2: fs = 1; fs_np[3] = b; break; - case AK_NP0: case AK_NP5: fs = 1; fs_np[4] = b; break; - case AK_NPDEL: case AK_NPDIV: case AK_ENT: fs = 1; fs_np[5] = b; break; + int fs = 0; + int kpb_next = kpb_first + 1; + int k = kc >> 1; + int b = !(kc & 1); + + //write_log (L"got kc %02X\n", ((kc << 7) | (kc >> 1)) & 0xff); + if (kpb_next == 256) + kpb_next = 0; + if (kpb_next == kpb_last) { + write_log (L"Keyboard buffer overrun. Congratulations.\n"); + return 0; } - } - if (fs_ck != 0) { - switch (k) { - case AK_UP: fs = 1; fs_ck[0] = b; break; - case AK_LF: fs = 1; fs_ck[1] = b; break; - case AK_RT: fs = 1; fs_ck[2] = b; break; - case AK_DN: fs = 1; fs_ck[3] = b; break; - case AK_RCTRL: case AK_RALT: fs = 1; fs_ck[4] = b; break; - case AK_RSH: fs = 1; fs_ck[5] = b; break; + + if (fs_np != 0) { + switch (k) { + case AK_NP8: fs = 1; fs_np[0] = b; break; + case AK_NP4: fs = 1; fs_np[1] = b; break; + case AK_NP6: fs = 1; fs_np[2] = b; break; + case AK_NP2: fs = 1; fs_np[3] = b; break; + case AK_NP0: case AK_NP5: fs = 1; fs_np[4] = b; break; + case AK_NPDEL: case AK_NPDIV: case AK_ENT: fs = 1; fs_np[5] = b; break; + } + } + if (fs_ck != 0) { + switch (k) { + case AK_UP: fs = 1; fs_ck[0] = b; break; + case AK_LF: fs = 1; fs_ck[1] = b; break; + case AK_RT: fs = 1; fs_ck[2] = b; break; + case AK_DN: fs = 1; fs_ck[3] = b; break; + case AK_RCTRL: case AK_RALT: fs = 1; fs_ck[4] = b; break; + case AK_RSH: fs = 1; fs_ck[5] = b; break; + } } - } - if (fs_se != 0) { - switch (k) { - case AK_W: fs = 1; fs_se[0] = b; break; - case AK_A: fs = 1; fs_se[1] = b; break; - case AK_D: fs = 1; fs_se[2] = b; break; - case AK_S: fs = 1; fs_se[3] = b; break; - case AK_LALT: fs = 1; fs_se[4] = b; break; - case AK_LSH: fs = 1; fs_se[5] = b; break; + if (fs_se != 0) { + switch (k) { + case AK_W: fs = 1; fs_se[0] = b; break; + case AK_A: fs = 1; fs_se[1] = b; break; + case AK_D: fs = 1; fs_se[2] = b; break; + case AK_S: fs = 1; fs_se[3] = b; break; + case AK_LALT: fs = 1; fs_se[4] = b; break; + case AK_LSH: fs = 1; fs_se[5] = b; break; + } } - } #ifdef ARCADIA - if (fs_xa1 != 0) { - switch (k) { - case AK_NP8: fs = 1; fs_xa1[0] = b; break; - case AK_NP4: fs = 1; fs_xa1[1] = b; break; - case AK_NP6: fs = 1; fs_xa1[2] = b; break; - case AK_NP2: case AK_NP5: fs = 1; fs_xa1[3] = b; break; - case AK_CTRL: fs = 1; fs_xa1[4] = b; break; - case AK_LALT: fs = 1; fs_xa1[5] = b; break; - case AK_SPC: fs = 1; fs_xa1[6] = b; break; + if (fs_xa1 != 0) { + switch (k) { + case AK_NP8: fs = 1; fs_xa1[0] = b; break; + case AK_NP4: fs = 1; fs_xa1[1] = b; break; + case AK_NP6: fs = 1; fs_xa1[2] = b; break; + case AK_NP2: case AK_NP5: fs = 1; fs_xa1[3] = b; break; + case AK_CTRL: fs = 1; fs_xa1[4] = b; break; + case AK_LALT: fs = 1; fs_xa1[5] = b; break; + case AK_SPC: fs = 1; fs_xa1[6] = b; break; + } } - } - if (fs_xa2 != 0) { - switch (k) { - case AK_R: fs = 1; fs_xa2[0] = b; break; - case AK_D: fs = 1; fs_xa2[1] = b; break; - case AK_G: fs = 1; fs_xa2[2] = b; break; - case AK_F: fs = 1; fs_xa2[3] = b; break; - case AK_A: fs = 1; fs_xa2[4] = b; break; - case AK_S: fs = 1; fs_xa2[5] = b; break; - case AK_Q: fs = 1; fs_xa2[6] = b; break; + if (fs_xa2 != 0) { + switch (k) { + case AK_R: fs = 1; fs_xa2[0] = b; break; + case AK_D: fs = 1; fs_xa2[1] = b; break; + case AK_G: fs = 1; fs_xa2[2] = b; break; + case AK_F: fs = 1; fs_xa2[3] = b; break; + case AK_A: fs = 1; fs_xa2[4] = b; break; + case AK_S: fs = 1; fs_xa2[5] = b; break; + case AK_Q: fs = 1; fs_xa2[6] = b; break; + } } - } #endif - if (fs && currprefs.input_selected_setting == 0) { - if (JSEM_ISANYKBD (0, &currprefs)) - do_fake (0); - if (JSEM_ISANYKBD (1, &currprefs)) - do_fake (1); - if (JSEM_ISANYKBD (2, &currprefs)) - do_fake (2); - if (JSEM_ISANYKBD (3, &currprefs)) - do_fake (3); - return 0; - } else { - if ((kc >> 1) == AK_RCTRL) { - kc ^= AK_RCTRL << 1; - kc ^= AK_CTRL << 1; - } + if (fs && currprefs.input_selected_setting == 0) { + if (JSEM_ISANYKBD (0, &currprefs)) + do_fake (0); + if (JSEM_ISANYKBD (1, &currprefs)) + do_fake (1); + if (JSEM_ISANYKBD (2, &currprefs)) + do_fake (2); + if (JSEM_ISANYKBD (3, &currprefs)) + do_fake (3); + return 0; + } else { + if ((kc >> 1) == AK_RCTRL) { + kc ^= AK_RCTRL << 1; + kc ^= AK_CTRL << 1; + } #ifdef ARCADIA - if (fs_xa1 || fs_xa2) { - int k2 = k; - if (k == AK_1) - k2 = AK_F1; - if (k == AK_2) - k2 = AK_F2; - if (k == AK_3) - k2 = AK_LALT; - if (k == AK_4) - k2 = AK_RALT; - if (k == AK_6) - k2 = AK_DN; - if (k == AK_LBRACKET || k == AK_LSH) - k2 = AK_SPC; - if (k == AK_RBRACKET) - k2 = AK_RET; - if (k == AK_C) - k2 = AK_1; - if (k == AK_5) - k2 = AK_2; - if (k == AK_Z) - k2 = AK_3; - if (k == AK_X) - k2 = AK_4; - if (k != k2) - kc = (k2 << 1) | (b ? 0 : 1); - } + if (fs_xa1 || fs_xa2) { + int k2 = k; + if (k == AK_1) + k2 = AK_F1; + if (k == AK_2) + k2 = AK_F2; + if (k == AK_3) + k2 = AK_LALT; + if (k == AK_4) + k2 = AK_RALT; + if (k == AK_6) + k2 = AK_DN; + if (k == AK_LBRACKET || k == AK_LSH) + k2 = AK_SPC; + if (k == AK_RBRACKET) + k2 = AK_RET; + if (k == AK_C) + k2 = AK_1; + if (k == AK_5) + k2 = AK_2; + if (k == AK_Z) + k2 = AK_3; + if (k == AK_X) + k2 = AK_4; + if (k != k2) + kc = (k2 << 1) | (b ? 0 : 1); + } #endif - } + } - if (input_recording > 0) { - inprec_rstart(INPREC_KEY); - inprec_ru8(kc); - inprec_rend(); - } + if (input_recording > 0) { + inprec_rstart(INPREC_KEY); + inprec_ru8(kc); + inprec_rend(); + } - keybuf[kpb_first] = kc; - kpb_first = kpb_next; - return 1; + keybuf[kpb_first] = kc; + kpb_first = kpb_next; + return 1; } void joystick_setting_changed (void) { - int i; + int i; - fs_np = fs_ck = fs_se = 0; + fs_np = fs_ck = fs_se = 0; #ifdef ARCADIA - fs_xa1 = fs_xa2 = 0; + fs_xa1 = fs_xa2 = 0; #endif - for (i = 0; i < MAX_JPORTS; i++) { - if (JSEM_ISNUMPAD (i, &currprefs)) - fs_np = fakestate[i]; - if (JSEM_ISCURSOR (i, &currprefs)) - fs_ck = fakestate[i]; - if (JSEM_ISSOMEWHEREELSE (i, &currprefs)) - fs_se = fakestate[i]; + for (i = 0; i < MAX_JPORTS; i++) { + if (JSEM_ISNUMPAD (i, &currprefs)) + fs_np = fakestate[i]; + if (JSEM_ISCURSOR (i, &currprefs)) + fs_ck = fakestate[i]; + if (JSEM_ISSOMEWHEREELSE (i, &currprefs)) + fs_se = fakestate[i]; #ifdef ARCADIA - if (JSEM_ISXARCADE1 (i, &currprefs)) - fs_xa1 = fakestate[i]; - if (JSEM_ISXARCADE2 (i, &currprefs)) - fs_xa2 = fakestate[i]; + if (JSEM_ISXARCADE1 (i, &currprefs)) + fs_xa1 = fakestate[i]; + if (JSEM_ISXARCADE2 (i, &currprefs)) + fs_xa2 = fakestate[i]; #endif - } + } } void keybuf_init (void) { - kpb_first = kpb_last = 0; - inputdevice_updateconfig (&currprefs); + kpb_first = kpb_last = 0; + inputdevice_updateconfig (&currprefs); } #ifdef SAVESTATE uae_u8 *save_keyboard (int *len) { - uae_u8 *dst, *t; - dst = t = xmalloc (8); - save_u32 (getcapslockstate () ? 1 : 0); - save_u32 (0); - *len = 8; - return t; + uae_u8 *dst, *t; + dst = t = xmalloc (8); + save_u32 (getcapslockstate () ? 1 : 0); + save_u32 (0); + *len = 8; + return t; } uae_u8 *restore_keyboard (uae_u8 *src) { - setcapslockstate (restore_u32 ()); - restore_u32 (); - return src; + setcapslockstate (restore_u32 ()); + restore_u32 (); + return src; } #endif /* SAVESTATE */ diff --git a/main.c b/main.c index 1dc4c69e..c5267e46 100644 --- a/main.c +++ b/main.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Main program - * - * Copyright 1995 Ed Hanway - * Copyright 1995, 1996, 1997 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Main program +* +* Copyright 1995 Ed Hanway +* Copyright 1995, 1996, 1997 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" #include @@ -72,325 +72,325 @@ TCHAR optionsfile[256]; int uaerand (void) { - return rand (); + return rand (); } void discard_prefs (struct uae_prefs *p, int type) { - struct strlist **ps = &p->all_lines; - while (*ps) { - struct strlist *s = *ps; - *ps = s->next; - xfree (s->value); - xfree (s->option); - xfree (s); - } + struct strlist **ps = &p->all_lines; + while (*ps) { + struct strlist *s = *ps; + *ps = s->next; + xfree (s->value); + xfree (s->option); + xfree (s); + } #ifdef FILESYS - filesys_cleanup (); + filesys_cleanup (); #endif } static void fixup_prefs_dim2 (struct wh *wh) { - if (wh->width < 160) - wh->width = 160; - if (wh->height < 128) - wh->height = 128; - if (wh->width > 3072) - wh->width = 3072; - if (wh->height > 2048) - wh->height = 2048; + if (wh->width < 160) + wh->width = 160; + if (wh->height < 128) + wh->height = 128; + if (wh->width > 3072) + wh->width = 3072; + if (wh->height > 2048) + wh->height = 2048; } void fixup_prefs_dimensions (struct uae_prefs *prefs) { - fixup_prefs_dim2 (&prefs->gfx_size_fs); - fixup_prefs_dim2 (&prefs->gfx_size_win); - if (prefs->gfx_filter == 0 && prefs->gfx_filter_autoscale) - prefs->gfx_filter = 1; - if (prefs->gfx_filter_autoscale) { - prefs->gfx_filter_horiz_zoom_mult = 0; - prefs->gfx_filter_vert_zoom_mult = 0; - } + fixup_prefs_dim2 (&prefs->gfx_size_fs); + fixup_prefs_dim2 (&prefs->gfx_size_win); + if (prefs->gfx_filter == 0 && prefs->gfx_filter_autoscale) + prefs->gfx_filter = 1; + if (prefs->gfx_filter_autoscale) { + prefs->gfx_filter_horiz_zoom_mult = 0; + prefs->gfx_filter_vert_zoom_mult = 0; + } } void fixup_cpu (struct uae_prefs *p) { - switch (p->cpu_model) - { - case 68000: - p->address_space_24 = 1; - if (p->cpu_compatible || p->cpu_cycle_exact) - p->fpu_model = 0; - break; - case 68010: - p->address_space_24 = 1; - if (p->cpu_compatible || p->cpu_cycle_exact) - p->fpu_model = 0; - break; - case 68020: - break; - case 68030: - p->address_space_24 = 0; - break; - case 68040: - p->address_space_24 = 0; - if (p->fpu_model) - p->fpu_model = 68040; - break; - case 68060: - p->address_space_24 = 0; - if (p->fpu_model) - p->fpu_model = 68060; - break; - } - if (p->cpu_model != 68040) - p->mmu_model = 0; + switch (p->cpu_model) + { + case 68000: + p->address_space_24 = 1; + if (p->cpu_compatible || p->cpu_cycle_exact) + p->fpu_model = 0; + break; + case 68010: + p->address_space_24 = 1; + if (p->cpu_compatible || p->cpu_cycle_exact) + p->fpu_model = 0; + break; + case 68020: + break; + case 68030: + p->address_space_24 = 0; + break; + case 68040: + p->address_space_24 = 0; + if (p->fpu_model) + p->fpu_model = 68040; + break; + case 68060: + p->address_space_24 = 0; + if (p->fpu_model) + p->fpu_model = 68060; + break; + } + if (p->cpu_model != 68040) + p->mmu_model = 0; } void fixup_prefs (struct uae_prefs *p) { - int err = 0; - - built_in_chipset_prefs (p); - fixup_cpu (p); - - if (((p->chipmem_size & (p->chipmem_size - 1)) != 0 && p->chipmem_size != 0x180000) - || p->chipmem_size < 0x20000 - || p->chipmem_size > 0x800000) - { - write_log (L"Unsupported chipmem size %x!\n", p->chipmem_size); - p->chipmem_size = 0x200000; - err = 1; - } - if ((p->fastmem_size & (p->fastmem_size - 1)) != 0 - || (p->fastmem_size != 0 && (p->fastmem_size < 0x100000 || p->fastmem_size > 0x800000))) - { - write_log (L"Unsupported fastmem size %x!\n", p->fastmem_size); - err = 1; - } - if ((p->gfxmem_size & (p->gfxmem_size - 1)) != 0 - || (p->gfxmem_size != 0 && (p->gfxmem_size < 0x100000 || p->gfxmem_size > max_z3fastmem / 2))) - { - write_log (L"Unsupported graphics card memory size %x (%x)!\n", p->gfxmem_size, max_z3fastmem / 2); - if (p->gfxmem_size > max_z3fastmem / 2) - p->gfxmem_size = max_z3fastmem / 2; - else - p->gfxmem_size = 0; - err = 1; - } - if ((p->z3fastmem_size & (p->z3fastmem_size - 1)) != 0 - || (p->z3fastmem_size != 0 && (p->z3fastmem_size < 0x100000 || p->z3fastmem_size > max_z3fastmem))) - { - write_log (L"Unsupported Zorro III fastmem size %x (%x)!\n", p->z3fastmem_size, max_z3fastmem); - if (p->z3fastmem_size > max_z3fastmem) - p->z3fastmem_size = max_z3fastmem; - else - p->z3fastmem_size = 0; - err = 1; - } - if ((p->z3fastmem2_size & (p->z3fastmem2_size - 1)) != 0 - || (p->z3fastmem2_size != 0 && (p->z3fastmem2_size < 0x100000 || p->z3fastmem2_size > max_z3fastmem))) - { - write_log (L"Unsupported Zorro III fastmem size %x (%x)!\n", p->z3fastmem2_size, max_z3fastmem); - if (p->z3fastmem2_size > max_z3fastmem) - p->z3fastmem2_size = max_z3fastmem; - else - p->z3fastmem2_size = 0; - err = 1; - } - p->z3fastmem_start &= ~0xffff; - if (p->z3fastmem_start < 0x1000000) - p->z3fastmem_start = 0x1000000; - - if (p->address_space_24 && (p->gfxmem_size != 0 || p->z3fastmem_size != 0)) { - p->z3fastmem_size = p->gfxmem_size = 0; - write_log (L"Can't use a graphics card or Zorro III fastmem when using a 24 bit\n" - L"address space - sorry.\n"); - } - if (p->bogomem_size != 0 && p->bogomem_size != 0x80000 && p->bogomem_size != 0x100000 && p->bogomem_size != 0x180000 && p->bogomem_size != 0x1c0000) { - p->bogomem_size = 0; - write_log (L"Unsupported bogomem size!\n"); - err = 1; - } - if (p->bogomem_size > 0x100000 && (p->cs_fatgaryrev >= 0 || p->cs_ide || p->cs_ramseyrev >= 0)) { - p->bogomem_size = 0x100000; - write_log (L"Possible Gayle bogomem conflict fixed\n"); - } - if (p->chipmem_size > 0x200000 && p->fastmem_size != 0) { - write_log (L"You can't use fastmem and more than 2MB chip at the same time!\n"); - p->fastmem_size = 0; - err = 1; - } - if (p->mbresmem_low_size > 0x04000000 || (p->mbresmem_low_size & 0xfffff)) { - p->mbresmem_low_size = 0; - write_log (L"Unsupported A3000 MB RAM size\n"); - } - if (p->mbresmem_high_size > 0x04000000 || (p->mbresmem_high_size & 0xfffff)) { - p->mbresmem_high_size = 0; - write_log (L"Unsupported Motherboard RAM size\n"); - } + int err = 0; + + built_in_chipset_prefs (p); + fixup_cpu (p); + + if (((p->chipmem_size & (p->chipmem_size - 1)) != 0 && p->chipmem_size != 0x180000) + || p->chipmem_size < 0x20000 + || p->chipmem_size > 0x800000) + { + write_log (L"Unsupported chipmem size %x!\n", p->chipmem_size); + p->chipmem_size = 0x200000; + err = 1; + } + if ((p->fastmem_size & (p->fastmem_size - 1)) != 0 + || (p->fastmem_size != 0 && (p->fastmem_size < 0x100000 || p->fastmem_size > 0x800000))) + { + write_log (L"Unsupported fastmem size %x!\n", p->fastmem_size); + err = 1; + } + if ((p->gfxmem_size & (p->gfxmem_size - 1)) != 0 + || (p->gfxmem_size != 0 && (p->gfxmem_size < 0x100000 || p->gfxmem_size > max_z3fastmem / 2))) + { + write_log (L"Unsupported graphics card memory size %x (%x)!\n", p->gfxmem_size, max_z3fastmem / 2); + if (p->gfxmem_size > max_z3fastmem / 2) + p->gfxmem_size = max_z3fastmem / 2; + else + p->gfxmem_size = 0; + err = 1; + } + if ((p->z3fastmem_size & (p->z3fastmem_size - 1)) != 0 + || (p->z3fastmem_size != 0 && (p->z3fastmem_size < 0x100000 || p->z3fastmem_size > max_z3fastmem))) + { + write_log (L"Unsupported Zorro III fastmem size %x (%x)!\n", p->z3fastmem_size, max_z3fastmem); + if (p->z3fastmem_size > max_z3fastmem) + p->z3fastmem_size = max_z3fastmem; + else + p->z3fastmem_size = 0; + err = 1; + } + if ((p->z3fastmem2_size & (p->z3fastmem2_size - 1)) != 0 + || (p->z3fastmem2_size != 0 && (p->z3fastmem2_size < 0x100000 || p->z3fastmem2_size > max_z3fastmem))) + { + write_log (L"Unsupported Zorro III fastmem size %x (%x)!\n", p->z3fastmem2_size, max_z3fastmem); + if (p->z3fastmem2_size > max_z3fastmem) + p->z3fastmem2_size = max_z3fastmem; + else + p->z3fastmem2_size = 0; + err = 1; + } + p->z3fastmem_start &= ~0xffff; + if (p->z3fastmem_start < 0x1000000) + p->z3fastmem_start = 0x1000000; + + if (p->address_space_24 && (p->gfxmem_size != 0 || p->z3fastmem_size != 0)) { + p->z3fastmem_size = p->gfxmem_size = 0; + write_log (L"Can't use a graphics card or Zorro III fastmem when using a 24 bit\n" + L"address space - sorry.\n"); + } + if (p->bogomem_size != 0 && p->bogomem_size != 0x80000 && p->bogomem_size != 0x100000 && p->bogomem_size != 0x180000 && p->bogomem_size != 0x1c0000) { + p->bogomem_size = 0; + write_log (L"Unsupported bogomem size!\n"); + err = 1; + } + if (p->bogomem_size > 0x100000 && (p->cs_fatgaryrev >= 0 || p->cs_ide || p->cs_ramseyrev >= 0)) { + p->bogomem_size = 0x100000; + write_log (L"Possible Gayle bogomem conflict fixed\n"); + } + if (p->chipmem_size > 0x200000 && p->fastmem_size != 0) { + write_log (L"You can't use fastmem and more than 2MB chip at the same time!\n"); + p->fastmem_size = 0; + err = 1; + } + if (p->mbresmem_low_size > 0x04000000 || (p->mbresmem_low_size & 0xfffff)) { + p->mbresmem_low_size = 0; + write_log (L"Unsupported A3000 MB RAM size\n"); + } + if (p->mbresmem_high_size > 0x04000000 || (p->mbresmem_high_size & 0xfffff)) { + p->mbresmem_high_size = 0; + write_log (L"Unsupported Motherboard RAM size\n"); + } #if 0 - if (p->m68k_speed < -1 || p->m68k_speed > 20) { - write_log (L"Bad value for -w parameter: must be -1, 0, or within 1..20.\n"); - p->m68k_speed = 4; - err = 1; - } -#endif - - if (p->produce_sound < 0 || p->produce_sound > 3) { - write_log (L"Bad value for -S parameter: enable value must be within 0..3\n"); - p->produce_sound = 0; - err = 1; - } - if (p->comptrustbyte < 0 || p->comptrustbyte > 3) { - write_log (L"Bad value for comptrustbyte parameter: value must be within 0..2\n"); - p->comptrustbyte = 1; - err = 1; - } - if (p->comptrustword < 0 || p->comptrustword > 3) { - write_log (L"Bad value for comptrustword parameter: value must be within 0..2\n"); - p->comptrustword = 1; - err = 1; - } - if (p->comptrustlong < 0 || p->comptrustlong > 3) { - write_log (L"Bad value for comptrustlong parameter: value must be within 0..2\n"); - p->comptrustlong = 1; - err = 1; - } - if (p->comptrustnaddr < 0 || p->comptrustnaddr > 3) { - write_log (L"Bad value for comptrustnaddr parameter: value must be within 0..2\n"); - p->comptrustnaddr = 1; - err = 1; - } - if (p->compnf < 0 || p->compnf > 1) { - write_log (L"Bad value for compnf parameter: value must be within 0..1\n"); - p->compnf = 1; - err = 1; - } - if (p->comp_hardflush < 0 || p->comp_hardflush > 1) { - write_log (L"Bad value for comp_hardflush parameter: value must be within 0..1\n"); - p->comp_hardflush = 1; - err = 1; - } - if (p->comp_constjump < 0 || p->comp_constjump > 1) { - write_log (L"Bad value for comp_constjump parameter: value must be within 0..1\n"); - p->comp_constjump = 1; - err = 1; - } - if (p->comp_oldsegv < 0 || p->comp_oldsegv > 1) { - write_log (L"Bad value for comp_oldsegv parameter: value must be within 0..1\n"); - p->comp_oldsegv = 1; - err = 1; - } - if (p->cachesize < 0 || p->cachesize > 16384) { - write_log (L"Bad value for cachesize parameter: value must be within 0..16384\n"); - p->cachesize = 0; - err = 1; - } - if (p->z3fastmem_size > 0 && (p->address_space_24 || p->cpu_model < 68020)) { - write_log (L"Z3 fast memory can't be used with a 68000/68010 emulation. It\n" - L"requires a 68020 emulation. Turning off Z3 fast memory.\n"); - p->z3fastmem_size = 0; - err = 1; - } - if (p->gfxmem_size > 0 && (p->cpu_model < 68020 || p->address_space_24)) { - write_log (L"Picasso96 can't be used with a 68000/68010 or 68EC020 emulation. It\n" - L"requires a 68020 emulation. Turning off Picasso96.\n"); - p->gfxmem_size = 0; - err = 1; - } + if (p->m68k_speed < -1 || p->m68k_speed > 20) { + write_log (L"Bad value for -w parameter: must be -1, 0, or within 1..20.\n"); + p->m68k_speed = 4; + err = 1; + } +#endif + + if (p->produce_sound < 0 || p->produce_sound > 3) { + write_log (L"Bad value for -S parameter: enable value must be within 0..3\n"); + p->produce_sound = 0; + err = 1; + } + if (p->comptrustbyte < 0 || p->comptrustbyte > 3) { + write_log (L"Bad value for comptrustbyte parameter: value must be within 0..2\n"); + p->comptrustbyte = 1; + err = 1; + } + if (p->comptrustword < 0 || p->comptrustword > 3) { + write_log (L"Bad value for comptrustword parameter: value must be within 0..2\n"); + p->comptrustword = 1; + err = 1; + } + if (p->comptrustlong < 0 || p->comptrustlong > 3) { + write_log (L"Bad value for comptrustlong parameter: value must be within 0..2\n"); + p->comptrustlong = 1; + err = 1; + } + if (p->comptrustnaddr < 0 || p->comptrustnaddr > 3) { + write_log (L"Bad value for comptrustnaddr parameter: value must be within 0..2\n"); + p->comptrustnaddr = 1; + err = 1; + } + if (p->compnf < 0 || p->compnf > 1) { + write_log (L"Bad value for compnf parameter: value must be within 0..1\n"); + p->compnf = 1; + err = 1; + } + if (p->comp_hardflush < 0 || p->comp_hardflush > 1) { + write_log (L"Bad value for comp_hardflush parameter: value must be within 0..1\n"); + p->comp_hardflush = 1; + err = 1; + } + if (p->comp_constjump < 0 || p->comp_constjump > 1) { + write_log (L"Bad value for comp_constjump parameter: value must be within 0..1\n"); + p->comp_constjump = 1; + err = 1; + } + if (p->comp_oldsegv < 0 || p->comp_oldsegv > 1) { + write_log (L"Bad value for comp_oldsegv parameter: value must be within 0..1\n"); + p->comp_oldsegv = 1; + err = 1; + } + if (p->cachesize < 0 || p->cachesize > 16384) { + write_log (L"Bad value for cachesize parameter: value must be within 0..16384\n"); + p->cachesize = 0; + err = 1; + } + if (p->z3fastmem_size > 0 && (p->address_space_24 || p->cpu_model < 68020)) { + write_log (L"Z3 fast memory can't be used with a 68000/68010 emulation. It\n" + L"requires a 68020 emulation. Turning off Z3 fast memory.\n"); + p->z3fastmem_size = 0; + err = 1; + } + if (p->gfxmem_size > 0 && (p->cpu_model < 68020 || p->address_space_24)) { + write_log (L"Picasso96 can't be used with a 68000/68010 or 68EC020 emulation. It\n" + L"requires a 68020 emulation. Turning off Picasso96.\n"); + p->gfxmem_size = 0; + err = 1; + } #if !defined (BSDSOCKET) - if (p->socket_emu) { - write_log (L"Compile-time option of BSDSOCKET_SUPPORTED was not enabled. You can't use bsd-socket emulation.\n"); - p->socket_emu = 0; - err = 1; - } -#endif - - if (p->nr_floppies < 0 || p->nr_floppies > 4) { - write_log (L"Invalid number of floppies. Using 4.\n"); - p->nr_floppies = 4; - p->dfxtype[0] = 0; - p->dfxtype[1] = 0; - p->dfxtype[2] = 0; - p->dfxtype[3] = 0; - err = 1; - } - if (p->floppy_speed > 0 && p->floppy_speed < 10) { - p->floppy_speed = 100; - } - if (p->input_mouse_speed < 1 || p->input_mouse_speed > 1000) { - p->input_mouse_speed = 100; - } - if (p->collision_level < 0 || p->collision_level > 3) { - write_log (L"Invalid collision support level. Using 1.\n"); - p->collision_level = 1; - err = 1; - } - if (p->parallel_postscript_emulation) - p->parallel_postscript_detection = 1; - if (p->cs_compatible == 1) { - p->cs_fatgaryrev = p->cs_ramseyrev = p->cs_mbdmac = -1; - p->cs_ide = 0; - if (p->cpu_model >= 68020) { - p->cs_fatgaryrev = 0; - p->cs_ide = -1; - p->cs_ramseyrev = 0x0f; - p->cs_mbdmac = 0; - } - } - fixup_prefs_dimensions (p); + if (p->socket_emu) { + write_log (L"Compile-time option of BSDSOCKET_SUPPORTED was not enabled. You can't use bsd-socket emulation.\n"); + p->socket_emu = 0; + err = 1; + } +#endif + + if (p->nr_floppies < 0 || p->nr_floppies > 4) { + write_log (L"Invalid number of floppies. Using 4.\n"); + p->nr_floppies = 4; + p->dfxtype[0] = 0; + p->dfxtype[1] = 0; + p->dfxtype[2] = 0; + p->dfxtype[3] = 0; + err = 1; + } + if (p->floppy_speed > 0 && p->floppy_speed < 10) { + p->floppy_speed = 100; + } + if (p->input_mouse_speed < 1 || p->input_mouse_speed > 1000) { + p->input_mouse_speed = 100; + } + if (p->collision_level < 0 || p->collision_level > 3) { + write_log (L"Invalid collision support level. Using 1.\n"); + p->collision_level = 1; + err = 1; + } + if (p->parallel_postscript_emulation) + p->parallel_postscript_detection = 1; + if (p->cs_compatible == 1) { + p->cs_fatgaryrev = p->cs_ramseyrev = p->cs_mbdmac = -1; + p->cs_ide = 0; + if (p->cpu_model >= 68020) { + p->cs_fatgaryrev = 0; + p->cs_ide = -1; + p->cs_ramseyrev = 0x0f; + p->cs_mbdmac = 0; + } + } + fixup_prefs_dimensions (p); #ifdef CPU_68000_ONLY - p->cpu_model = 68000; - p->fpu_model = 0; + p->cpu_model = 68000; + p->fpu_model = 0; #endif #ifndef CPUEMU_0 - p->cpu_compatible = 1; - p->address_space_24 = 1; + p->cpu_compatible = 1; + p->address_space_24 = 1; #endif #if !defined (CPUEMU_11) && !defined (CPUEMU_12) - p->cpu_compatible = 0; - p->address_space_24 = 0; + p->cpu_compatible = 0; + p->address_space_24 = 0; #endif #if !defined (CPUEMU_12) - p->cpu_cycle_exact = p->blitter_cycle_exact = 0; + p->cpu_cycle_exact = p->blitter_cycle_exact = 0; #endif #ifndef AGA - p->chipset_mask &= ~CSMASK_AGA; + p->chipset_mask &= ~CSMASK_AGA; #endif #ifndef AUTOCONFIG - p->z3fastmem_size = 0; - p->fastmem_size = 0; - p->gfxmem_size = 0; + p->z3fastmem_size = 0; + p->fastmem_size = 0; + p->gfxmem_size = 0; #endif #if !defined (BSDSOCKET) - p->socket_emu = 0; + p->socket_emu = 0; #endif #if !defined (SCSIEMU) - p->scsi = 0; - p->win32_aspi = 0; + p->scsi = 0; + p->win32_aspi = 0; #endif #if !defined (SANA2) - p->sana2 = 0; + p->sana2 = 0; #endif #if !defined (UAESERIAL) - p->uaeserial = 0; + p->uaeserial = 0; #endif #if defined (CPUEMU_12) - if (p->cpu_cycle_exact) { - p->gfx_framerate = 1; - p->cachesize = 0; - } -#endif - if (p->maprom && !p->address_space_24) - p->maprom = 0x0f000000; - if (p->tod_hack && p->cs_ciaatod == 0) - p->cs_ciaatod = p->ntscmode ? 2 : 1; - target_fixup_options (p); + if (p->cpu_cycle_exact) { + p->gfx_framerate = 1; + p->cachesize = 0; + } +#endif + if (p->maprom && !p->address_space_24) + p->maprom = 0x0f000000; + if (p->tod_hack && p->cs_ciaatod == 0) + p->cs_ciaatod = p->ntscmode ? 2 : 1; + target_fixup_options (p); } int quit_program = 0; @@ -400,31 +400,31 @@ static int default_config; void uae_reset (int hardreset) { - if (quit_program == 0) { - quit_program = -2; - if (hardreset) - quit_program = -3; - } + if (quit_program == 0) { + quit_program = -2; + if (hardreset) + quit_program = -3; + } } void uae_quit (void) { - deactivate_debugger (); - if (quit_program != -1) - quit_program = -1; - target_quit (); + deactivate_debugger (); + if (quit_program != -1) + quit_program = -1; + target_quit (); } /* 0 = normal, 1 = nogui, -1 = disable nogui */ void uae_restart (int opengui, TCHAR *cfgfile) { - uae_quit (); - restart_program = opengui > 0 ? 1 : (opengui == 0 ? 2 : 3); - restart_config[0] = 0; - default_config = 0; - if (cfgfile) - _tcscpy (restart_config, cfgfile); + uae_quit (); + restart_program = opengui > 0 ? 1 : (opengui == 0 ? 2 : 3); + restart_config[0] = 0; + default_config = 0; + if (cfgfile) + _tcscpy (restart_config, cfgfile); } #ifndef DONT_PARSE_CMDLINE @@ -434,443 +434,443 @@ void usage (void) } static void parse_cmdline_2 (int argc, TCHAR **argv) { - int i; - - cfgfile_addcfgparam (0); - for (i = 1; i < argc; i++) { - if (_tcsncmp (argv[i], L"-cfgparam=", 10) == 0) { - cfgfile_addcfgparam (argv[i] + 10); - } else if (_tcscmp (argv[i], L"-cfgparam") == 0) { - if (i + 1 == argc) - write_log (L"Missing argument for '-cfgparam' option.\n"); - else - cfgfile_addcfgparam (argv[++i]); - } - } + int i; + + cfgfile_addcfgparam (0); + for (i = 1; i < argc; i++) { + if (_tcsncmp (argv[i], L"-cfgparam=", 10) == 0) { + cfgfile_addcfgparam (argv[i] + 10); + } else if (_tcscmp (argv[i], L"-cfgparam") == 0) { + if (i + 1 == argc) + write_log (L"Missing argument for '-cfgparam' option.\n"); + else + cfgfile_addcfgparam (argv[++i]); + } + } } static void parse_diskswapper (TCHAR *s) { - TCHAR *tmp = my_strdup (s); - TCHAR *delim = L","; - TCHAR *p1, *p2; - int num = 0; - - p1 = tmp; - for (;;) { - p2 = _tcstok (p1, delim); - if (!p2) - break; - p1 = NULL; - if (num >= MAX_SPARE_DRIVES) - break; - _tcsncpy (currprefs.dfxlist[num], p2, 255); - num++; - } - free (tmp); + TCHAR *tmp = my_strdup (s); + TCHAR *delim = L","; + TCHAR *p1, *p2; + int num = 0; + + p1 = tmp; + for (;;) { + p2 = _tcstok (p1, delim); + if (!p2) + break; + p1 = NULL; + if (num >= MAX_SPARE_DRIVES) + break; + _tcsncpy (currprefs.dfxlist[num], p2, 255); + num++; + } + free (tmp); } static TCHAR *parsetext (const TCHAR *s) { - if (*s == '"' || *s == '\'') { - TCHAR *d; - TCHAR c = *s++; - int i; - d = my_strdup (s); - for (i = 0; i < _tcslen (d); i++) { - if (d[i] == c) { - d[i] = 0; - break; - } + if (*s == '"' || *s == '\'') { + TCHAR *d; + TCHAR c = *s++; + int i; + d = my_strdup (s); + for (i = 0; i < _tcslen (d); i++) { + if (d[i] == c) { + d[i] = 0; + break; + } + } + return d; + } else { + return my_strdup (s); } - return d; - } else { - return my_strdup (s); - } } static void parse_cmdline (int argc, TCHAR **argv) { - int i; - - for (i = 1; i < argc; i++) { - if (!_tcsncmp (argv[i], L"-diskswapper=", 13)) { - TCHAR *txt = parsetext (argv[i] + 13); - parse_diskswapper (txt); - xfree (txt); - } else if (_tcscmp (argv[i], L"-cfgparam") == 0) { - if (i + 1 < argc) - i++; - } else if (_tcsncmp (argv[i], L"-config=", 8) == 0) { - TCHAR *txt = parsetext (argv[i] + 8); - currprefs.mountitems = 0; - target_cfgfile_load (&currprefs, txt, -1, 0); - xfree (txt); - } else if (_tcsncmp (argv[i], L"-statefile=", 11) == 0) { - TCHAR *txt = parsetext (argv[i] + 11); - savestate_state = STATE_DORESTORE; - _tcscpy (savestate_fname, txt); - xfree (txt); - } else if (_tcscmp (argv[i], L"-f") == 0) { - /* Check for new-style "-f xxx" argument, where xxx is config-file */ - if (i + 1 == argc) { - write_log (L"Missing argument for '-f' option.\n"); - } else { - currprefs.mountitems = 0; - target_cfgfile_load (&currprefs, argv[++i], -1, 0); - } - } else if (_tcscmp (argv[i], L"-s") == 0) { - if (i + 1 == argc) - write_log (L"Missing argument for '-s' option.\n"); - else - cfgfile_parse_line (&currprefs, argv[++i], 0); - } else if (_tcscmp (argv[i], L"-h") == 0 || _tcscmp (argv[i], L"-help") == 0) { - usage (); - exit (0); - } else { - if (argv[i][0] == '-' && argv[i][1] != '\0') { - const TCHAR *arg = argv[i] + 2; - int extra_arg = *arg == '\0'; - if (extra_arg) - arg = i + 1 < argc ? argv[i + 1] : 0; - if (parse_cmdline_option (&currprefs, argv[i][1], arg) && extra_arg) - i++; - } - } - } + int i; + + for (i = 1; i < argc; i++) { + if (!_tcsncmp (argv[i], L"-diskswapper=", 13)) { + TCHAR *txt = parsetext (argv[i] + 13); + parse_diskswapper (txt); + xfree (txt); + } else if (_tcscmp (argv[i], L"-cfgparam") == 0) { + if (i + 1 < argc) + i++; + } else if (_tcsncmp (argv[i], L"-config=", 8) == 0) { + TCHAR *txt = parsetext (argv[i] + 8); + currprefs.mountitems = 0; + target_cfgfile_load (&currprefs, txt, -1, 0); + xfree (txt); + } else if (_tcsncmp (argv[i], L"-statefile=", 11) == 0) { + TCHAR *txt = parsetext (argv[i] + 11); + savestate_state = STATE_DORESTORE; + _tcscpy (savestate_fname, txt); + xfree (txt); + } else if (_tcscmp (argv[i], L"-f") == 0) { + /* Check for new-style "-f xxx" argument, where xxx is config-file */ + if (i + 1 == argc) { + write_log (L"Missing argument for '-f' option.\n"); + } else { + currprefs.mountitems = 0; + target_cfgfile_load (&currprefs, argv[++i], -1, 0); + } + } else if (_tcscmp (argv[i], L"-s") == 0) { + if (i + 1 == argc) + write_log (L"Missing argument for '-s' option.\n"); + else + cfgfile_parse_line (&currprefs, argv[++i], 0); + } else if (_tcscmp (argv[i], L"-h") == 0 || _tcscmp (argv[i], L"-help") == 0) { + usage (); + exit (0); + } else { + if (argv[i][0] == '-' && argv[i][1] != '\0') { + const TCHAR *arg = argv[i] + 2; + int extra_arg = *arg == '\0'; + if (extra_arg) + arg = i + 1 < argc ? argv[i + 1] : 0; + if (parse_cmdline_option (&currprefs, argv[i][1], arg) && extra_arg) + i++; + } + } + } } #endif static void parse_cmdline_and_init_file (int argc, TCHAR **argv) { - _tcscpy (optionsfile, L""); + _tcscpy (optionsfile, L""); #ifdef OPTIONS_IN_HOME - { - TCHAR *home = getenv ("HOME"); - if (home != NULL && strlen (home) < 240) { - _tcscpy (optionsfile, home); - _tcscat (optionsfile, L"/"); + TCHAR *home = getenv ("HOME"); + if (home != NULL && strlen (home) < 240) + { + _tcscpy (optionsfile, home); + _tcscat (optionsfile, L"/"); + } } - } #endif - parse_cmdline_2 (argc, argv); + parse_cmdline_2 (argc, argv); - _tcscat (optionsfile, restart_config); + _tcscat (optionsfile, restart_config); - if (! target_cfgfile_load (&currprefs, optionsfile, 0, default_config)) { - write_log (L"failed to load config '%s'\n", optionsfile); + if (! target_cfgfile_load (&currprefs, optionsfile, 0, default_config)) { + write_log (L"failed to load config '%s'\n", optionsfile); #ifdef OPTIONS_IN_HOME - /* sam: if not found in $HOME then look in current directory */ - _tcscpy (optionsfile, restart_config); - target_cfgfile_load (&currprefs, optionsfile, 0); + /* sam: if not found in $HOME then look in current directory */ + _tcscpy (optionsfile, restart_config); + target_cfgfile_load (&currprefs, optionsfile, 0); #endif - } - fixup_prefs (&currprefs); + } + fixup_prefs (&currprefs); - parse_cmdline (argc, argv); + parse_cmdline (argc, argv); } void reset_all_systems (void) { - init_eventtab (); + init_eventtab (); #ifdef PICASSO96 - picasso_reset (); + picasso_reset (); #endif #ifdef SCSIEMU - scsi_reset (); - scsidev_reset (); - scsidev_start_threads (); + scsi_reset (); + scsidev_reset (); + scsidev_start_threads (); #endif #ifdef A2065 - a2065_reset (); + a2065_reset (); #endif #ifdef SANA2 - netdev_reset (); - netdev_start_threads (); + netdev_reset (); + netdev_start_threads (); #endif #ifdef FILESYS - filesys_prepare_reset (); - filesys_reset (); + filesys_prepare_reset (); + filesys_reset (); #endif - memory_reset (); + memory_reset (); #if defined (BSDSOCKET) - bsdlib_reset (); + bsdlib_reset (); #endif #ifdef FILESYS - filesys_start_threads (); - hardfile_reset (); + filesys_start_threads (); + hardfile_reset (); #endif #ifdef UAESERIAL - uaeserialdev_reset (); - uaeserialdev_start_threads (); + uaeserialdev_reset (); + uaeserialdev_start_threads (); #endif #if defined (PARALLEL_PORT) - initparallel (); + initparallel (); #endif - native2amiga_reset (); - dongle_reset (); + native2amiga_reset (); + dongle_reset (); } /* Okay, this stuff looks strange, but it is here to encourage people who - * port UAE to re-use as much of this code as possible. Functions that you - * should be using are do_start_program () and do_leave_program (), as well - * as real_main (). Some OSes don't call main () (which is braindamaged IMHO, - * but unfortunately very common), so you need to call real_main () from - * whatever entry point you have. You may want to write your own versions - * of start_program () and leave_program () if you need to do anything special. - * Add #ifdefs around these as appropriate. - */ +* port UAE to re-use as much of this code as possible. Functions that you +* should be using are do_start_program () and do_leave_program (), as well +* as real_main (). Some OSes don't call main () (which is braindamaged IMHO, +* but unfortunately very common), so you need to call real_main () from +* whatever entry point you have. You may want to write your own versions +* of start_program () and leave_program () if you need to do anything special. +* Add #ifdefs around these as appropriate. +*/ void do_start_program (void) { - if (quit_program == -1) - return; - if (!canbang && candirect < 0) - candirect = 0; - if (canbang && candirect < 0) - candirect = 1; - /* Do a reset on startup. Whether this is elegant is debatable. */ - inputdevice_updateconfig (&currprefs); - if (quit_program >= 0) - quit_program = 2; - m68k_go (1); + if (quit_program == -1) + return; + if (!canbang && candirect < 0) + candirect = 0; + if (canbang && candirect < 0) + candirect = 1; + /* Do a reset on startup. Whether this is elegant is debatable. */ + inputdevice_updateconfig (&currprefs); + if (quit_program >= 0) + quit_program = 2; + m68k_go (1); } void do_leave_program (void) { - graphics_leave (); - inputdevice_close (); - DISK_free (); - close_sound (); - dump_counts (); + graphics_leave (); + inputdevice_close (); + DISK_free (); + close_sound (); + dump_counts (); #ifdef SERIAL_PORT - serial_exit (); + serial_exit (); #endif #ifdef CDTV - cdtv_free (); + cdtv_free (); #endif #ifdef A2091 - a2091_free (); + a2091_free (); #endif #ifdef NCR - ncr_free (); + ncr_free (); #endif #ifdef CD32 - akiko_free (); + akiko_free (); #endif - if (! no_gui) - gui_exit (); + if (! no_gui) + gui_exit (); #ifdef USE_SDL - SDL_Quit (); + SDL_Quit (); #endif #ifdef AUTOCONFIG - expansion_cleanup (); + expansion_cleanup (); #endif #ifdef FILESYS - filesys_cleanup (); + filesys_cleanup (); #endif #ifdef BSDSOCKET - bsdlib_reset (); + bsdlib_reset (); #endif - device_func_reset (); - savestate_free (); - memory_cleanup (); - cfgfile_addcfgparam (0); - machdep_free (); + device_func_reset (); + savestate_free (); + memory_cleanup (); + cfgfile_addcfgparam (0); + machdep_free (); } void start_program (void) { - do_start_program (); + do_start_program (); } void leave_program (void) { - do_leave_program (); + do_leave_program (); } static int real_main2 (int argc, TCHAR **argv) { #if defined (JIT) && (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) - extern int EvalException (LPEXCEPTION_POINTERS blah, int n_except); - __try + extern int EvalException (LPEXCEPTION_POINTERS blah, int n_except); + __try #endif - { + { #ifdef USE_SDL - SDL_Init (SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE); + SDL_Init (SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE); #endif - if (restart_config[0]) { - default_prefs (&currprefs, 0); - fixup_prefs (&currprefs); - } + if (restart_config[0]) { + default_prefs (&currprefs, 0); + fixup_prefs (&currprefs); + } - if (! graphics_setup ()) { - exit (1); - } + if (! graphics_setup ()) { + exit (1); + } #ifdef NATMEM_OFFSET - preinit_shm (); -#endif - - if (restart_config[0]) - parse_cmdline_and_init_file (argc, argv); - else - currprefs = changed_prefs; - - if (!machdep_init ()) { - restart_program = 0; - return -1; - } - - if (! setup_sound ()) { - write_log (L"Sound driver unavailable: Sound output disabled\n"); - currprefs.produce_sound = 0; - } - inputdevice_init (); - - changed_prefs = currprefs; - no_gui = ! currprefs.start_gui; - if (restart_program == 2) - no_gui = 1; - else if (restart_program == 3) - no_gui = 0; - restart_program = 0; - if (! no_gui) { - int err = gui_init (); - currprefs = changed_prefs; - if (err == -1) { - write_log (L"Failed to initialize the GUI\n"); - return -1; - } else if (err == -2) { - return 1; - } - } - - logging_init (); /* Yes, we call this twice - the first case handles when the user has loaded - a config using the cmd-line. This case handles loads through the GUI. */ + preinit_shm (); +#endif + + if (restart_config[0]) + parse_cmdline_and_init_file (argc, argv); + else + currprefs = changed_prefs; + + if (!machdep_init ()) { + restart_program = 0; + return -1; + } + + if (! setup_sound ()) { + write_log (L"Sound driver unavailable: Sound output disabled\n"); + currprefs.produce_sound = 0; + } + inputdevice_init (); + + changed_prefs = currprefs; + no_gui = ! currprefs.start_gui; + if (restart_program == 2) + no_gui = 1; + else if (restart_program == 3) + no_gui = 0; + restart_program = 0; + if (! no_gui) { + int err = gui_init (); + currprefs = changed_prefs; + if (err == -1) { + write_log (L"Failed to initialize the GUI\n"); + return -1; + } else if (err == -2) { + return 1; + } + } + + logging_init (); /* Yes, we call this twice - the first case handles when the user has loaded + a config using the cmd-line. This case handles loads through the GUI. */ #ifdef NATMEM_OFFSET - init_shm (); + init_shm (); #endif #ifdef JIT - if (!(currprefs.cpu_model >= 68020 && currprefs.address_space_24 == 0 && currprefs.cachesize)) - canbang = 0; + if (!(currprefs.cpu_model >= 68020 && currprefs.address_space_24 == 0 && currprefs.cachesize)) + canbang = 0; #endif - fixup_prefs (&currprefs); - changed_prefs = currprefs; - target_run (); - /* force sound settings change */ - currprefs.produce_sound = 0; + fixup_prefs (&currprefs); + changed_prefs = currprefs; + target_run (); + /* force sound settings change */ + currprefs.produce_sound = 0; #ifdef AUTOCONFIG - rtarea_setup (); + rtarea_setup (); #endif #ifdef FILESYS - rtarea_init (); - uaeres_install (); - hardfile_install (); + rtarea_init (); + uaeres_install (); + hardfile_install (); #endif - savestate_init (); + savestate_init (); #ifdef SCSIEMU - scsi_reset (); - scsidev_install (); + scsi_reset (); + scsidev_install (); #endif #ifdef SANA2 - netdev_install (); + netdev_install (); #endif #ifdef UAESERIAL - uaeserialdev_install (); + uaeserialdev_install (); #endif - keybuf_init (); /* Must come after init_joystick */ + keybuf_init (); /* Must come after init_joystick */ #ifdef AUTOCONFIG - expansion_init (); + expansion_init (); #endif #ifdef FILESYS - filesys_install (); + filesys_install (); #endif - memory_init (); - memory_reset (); + memory_init (); + memory_reset (); #ifdef AUTOCONFIG #if defined (BSDSOCKET) - bsdlib_install (); + bsdlib_install (); #endif - emulib_install (); - uaeexe_install (); - native2amiga_install (); + emulib_install (); + uaeexe_install (); + native2amiga_install (); #endif - custom_init (); /* Must come after memory_init */ + custom_init (); /* Must come after memory_init */ #ifdef SERIAL_PORT - serial_init (); + serial_init (); #endif - DISK_init (); + DISK_init (); - reset_frame_rate_hack (); - init_m68k (); /* must come after reset_frame_rate_hack (); */ + reset_frame_rate_hack (); + init_m68k (); /* must come after reset_frame_rate_hack (); */ - gui_update (); + gui_update (); - if (graphics_init ()) { - setup_brkhandler (); - if (currprefs.start_debugger && debuggable ()) - activate_debugger (); + if (graphics_init ()) { + setup_brkhandler (); + if (currprefs.start_debugger && debuggable ()) + activate_debugger (); - if (!init_audio ()) { - if (sound_available && currprefs.produce_sound > 1) { - write_log (L"Sound driver unavailable: Sound output disabled\n"); - } - currprefs.produce_sound = 0; - } + if (!init_audio ()) { + if (sound_available && currprefs.produce_sound > 1) { + write_log (L"Sound driver unavailable: Sound output disabled\n"); + } + currprefs.produce_sound = 0; + } - start_program (); - } + start_program (); + } - } + } #if defined (JIT) && (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) - __except (EvalException (GetExceptionInformation (), GetExceptionCode ())) - { - // EvalException does the good stuff... - } + __except (EvalException (GetExceptionInformation (), GetExceptionCode ())) + { + // EvalException does the good stuff... + } #endif - return 0; + return 0; } void real_main (int argc, TCHAR **argv) { - restart_program = 1; - - fetch_configurationpath (restart_config, sizeof (restart_config) / sizeof (TCHAR)); - _tcscat (restart_config, OPTIONSFILENAME); - default_config = 1; - - while (restart_program) { - int ret; - changed_prefs = currprefs; - ret = real_main2 (argc, argv); - if (ret == 0 && quit_to_gui) - restart_program = 1; - leave_program (); - quit_program = 0; - } - zfile_exit (); + restart_program = 1; + + fetch_configurationpath (restart_config, sizeof (restart_config) / sizeof (TCHAR)); + _tcscat (restart_config, OPTIONSFILENAME); + default_config = 1; + + while (restart_program) { + int ret; + changed_prefs = currprefs; + ret = real_main2 (argc, argv); + if (ret == 0 && quit_to_gui) + restart_program = 1; + leave_program (); + quit_program = 0; + } + zfile_exit (); } #ifndef NO_MAIN_IN_MAIN_C int main (int argc, TCHAR **argv) { - real_main (argc, argv); - return 0; + real_main (argc, argv); + return 0; } #endif diff --git a/memory.c b/memory.c index b6dd005e..1f268adc 100644 --- a/memory.c +++ b/memory.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Memory management - * - * (c) 1995 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Memory management +* +* (c) 1995 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -39,19 +39,19 @@ int special_mem; static int isdirectjit (void) { - return currprefs.cachesize && !currprefs.comptrustbyte; + return currprefs.cachesize && !currprefs.comptrustbyte; } static int canjit (void) { - if (currprefs.cpu_model < 68020 && currprefs.address_space_24) - return 0; - return 1; + if (currprefs.cpu_model < 68020 && currprefs.address_space_24) + return 0; + return 1; } static void nocanbang (void) { - canbang = 0; + canbang = 0; } int ersatzkickfile; @@ -75,8 +75,8 @@ uae_u32 max_z3fastmem = 512 * 1024 * 1024; static size_t bootrom_filepos, chip_filepos, bogo_filepos, rom_filepos, a3000lmem_filepos, a3000hmem_filepos; /* Set if we notice during initialization that settings changed, - and we must clear all memory to prevent bogus contents from confusing - the Kickstart. */ +and we must clear all memory to prevent bogus contents from confusing +the Kickstart. */ static int need_hardreset; /* The address space setting used during the last reset. */ @@ -87,998 +87,998 @@ static int romlist_cnt; TCHAR *romlist_get (struct romdata *rd) { - int i; + int i; - if (!rd) + if (!rd) + return 0; + for (i = 0; i < romlist_cnt; i++) { + if (rl[i].rd->id == rd->id) + return rl[i].path; + } return 0; - for (i = 0; i < romlist_cnt; i++) { - if (rl[i].rd->id == rd->id) - return rl[i].path; - } - return 0; } static struct romlist *romlist_getrl (struct romdata *rd) { - int i; + int i; - if (!rd) + if (!rd) + return 0; + for (i = 0; i < romlist_cnt; i++) { + if (rl[i].rd == rd) + return &rl[i]; + } return 0; - for (i = 0; i < romlist_cnt; i++) { - if (rl[i].rd == rd) - return &rl[i]; - } - return 0; } static void romlist_cleanup (void); void romlist_add (TCHAR *path, struct romdata *rd) { - struct romlist *rl2; + struct romlist *rl2; - if (path == NULL || rd == NULL) { - romlist_cleanup (); - return; - } - romlist_cnt++; - rl = realloc (rl, sizeof (struct romlist) * romlist_cnt); - rl2 = rl + romlist_cnt - 1; - rl2->path = my_strdup (path); - rl2->rd = rd; + if (path == NULL || rd == NULL) { + romlist_cleanup (); + return; + } + romlist_cnt++; + rl = realloc (rl, sizeof (struct romlist) * romlist_cnt); + rl2 = rl + romlist_cnt - 1; + rl2->path = my_strdup (path); + rl2->rd = rd; } struct romdata *getromdatabypath(TCHAR *path) { - int i; - for (i = 0; i < romlist_cnt; i++) { - struct romdata *rd = rl[i].rd; - if (rd->configname && path[0] == ':') { - if (!_tcscmp(path + 1, rd->configname)) - return rd; + int i; + for (i = 0; i < romlist_cnt; i++) { + struct romdata *rd = rl[i].rd; + if (rd->configname && path[0] == ':') { + if (!_tcscmp(path + 1, rd->configname)) + return rd; + } + if (!_tcscmp(rl[i].path, path)) + return rl[i].rd; } - if (!_tcscmp(rl[i].path, path)) - return rl[i].rd; - } - return NULL; + return NULL; } #define NEXT_ROM_ID 73 static struct romheader romheaders[] = { - { L"Freezer Cartridges", 1 }, - { L"Arcadia Games", 2 }, - { NULL, 0 } + { L"Freezer Cartridges", 1 }, + { L"Arcadia Games", 2 }, + { NULL, 0 } }; #define ALTROM(id,grp,num,size,flags,crc32,a,b,c,d,e) \ - { L"X", 0, 0, 0, 0, 0, size, id, 0, 0, flags, (grp << 16) | num, 0, NULL, crc32, a, b, c, d, e }, +{ L"X", 0, 0, 0, 0, 0, size, id, 0, 0, flags, (grp << 16) | num, 0, NULL, crc32, a, b, c, d, e }, #define ALTROMPN(id,grp,num,size,flags,pn,crc32,a,b,c,d,e) \ - { L"X", 0, 0, 0, 0, 0, size, id, 0, 0, flags, (grp << 16) | num, 0, pn, crc32, a, b, c, d, e }, +{ L"X", 0, 0, 0, 0, 0, size, id, 0, 0, flags, (grp << 16) | num, 0, pn, crc32, a, b, c, d, e }, static struct romdata roms[] = { - { L"Cloanto Amiga Forever ROM key", 0, 0, 0, 0, 0, 2069, 0, 0, 1, ROMTYPE_KEY, 0, 0, NULL, + { L"Cloanto Amiga Forever ROM key", 0, 0, 0, 0, 0, 2069, 0, 0, 1, ROMTYPE_KEY, 0, 0, NULL, 0x869ae1b1, 0x801bbab3,0x2e3d3738,0x6dd1636d,0x4f1d6fa7,0xe21d5874 }, - { L"Cloanto Amiga Forever 2006 ROM key", 0, 0, 0, 0, 0, 750, 48, 0, 1, ROMTYPE_KEY, 0, 0, NULL, + { L"Cloanto Amiga Forever 2006 ROM key", 0, 0, 0, 0, 0, 750, 48, 0, 1, ROMTYPE_KEY, 0, 0, NULL, 0xb01c4b56, 0xbba8e5cd,0x118b8d92,0xafed5693,0x5eeb9770,0x2a662d8f }, - { L"KS ROM v1.0 (A1000)(NTSC)", 1, 0, 1, 0, L"A1000\0", 262144, 1, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.0 (A1000)(NTSC)", 1, 0, 1, 0, L"A1000\0", 262144, 1, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0x299790ff, 0x00C15406,0xBEB4B8AB,0x1A16AA66,0xC05860E1,0xA7C1AD79 }, - { L"KS ROM v1.1 (A1000)(NTSC)", 1, 1, 31, 34, L"A1000\0", 262144, 2, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.1 (A1000)(NTSC)", 1, 1, 31, 34, L"A1000\0", 262144, 2, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0xd060572a, 0x4192C505,0xD130F446,0xB2ADA6BD,0xC91DAE73,0x0ACAFB4C}, - { L"KS ROM v1.1 (A1000)(PAL)", 1, 1, 31, 34, L"A1000\0", 262144, 3, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.1 (A1000)(PAL)", 1, 1, 31, 34, L"A1000\0", 262144, 3, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0xec86dae2, 0x16DF8B5F,0xD524C5A1,0xC7584B24,0x57AC15AF,0xF9E3AD6D }, - { L"KS ROM v1.2 (A1000)", 1, 2, 33, 166, L"A1000\0", 262144, 4, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.2 (A1000)", 1, 2, 33, 166, L"A1000\0", 262144, 4, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0x9ed783d0, 0x6A7BFB5D,0xBD6B8F17,0x9F03DA84,0xD8D95282,0x67B6273B }, - { L"KS ROM v1.2 (A500,A1000,A2000)", 1, 2, 33, 180, L"A500\0A1000\0A2000\0", 262144, 5, 0, 0, ROMTYPE_KICK, 0, 0, L"315093-01", + { L"KS ROM v1.2 (A500,A1000,A2000)", 1, 2, 33, 180, L"A500\0A1000\0A2000\0", 262144, 5, 0, 0, ROMTYPE_KICK, 0, 0, L"315093-01", 0xa6ce1636, 0x11F9E62C,0xF299F721,0x84835B7B,0x2A70A163,0x33FC0D88 }, - { L"KS ROM v1.3 (A500,A1000,A2000)", 1, 3, 34, 5, L"A500\0A1000\0A2000\0", 262144, 6, 0, 0, ROMTYPE_KICK, 0, 0, L"315093-02", + { L"KS ROM v1.3 (A500,A1000,A2000)", 1, 3, 34, 5, L"A500\0A1000\0A2000\0", 262144, 6, 0, 0, ROMTYPE_KICK, 0, 0, L"315093-02", 0xc4f0f55f, 0x891E9A54,0x7772FE0C,0x6C19B610,0xBAF8BC4E,0xA7FCB785 }, - { L"KS ROM v1.3 (A3000)(SK)", 1, 3, 34, 5, L"A3000\0", 262144, 32, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.3 (A3000)(SK)", 1, 3, 34, 5, L"A3000\0", 262144, 32, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0xe0f37258, 0xC39BD909,0x4D4E5F4E,0x28C1411F,0x30869504,0x06062E87 }, - { L"KS ROM v1.4 (A3000)", 1, 4, 36, 16, L"A3000\0", 524288, 59, 3, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v1.4 (A3000)", 1, 4, 36, 16, L"A3000\0", 524288, 59, 3, 0, ROMTYPE_KICK, 0, 0, NULL, 0xbc0ec13f, 0xF76316BF,0x36DFF14B,0x20FA349E,0xD02E4B11,0xDD932B07 }, - ALTROMPN(59, 1, 1, 262144, ROMTYPE_EVEN, L"390629-02", 0x58327536,0xd1713d7f,0x31474a59,0x48e6d488,0xe3368606,0x1cf3d1e2) - ALTROMPN(59, 1, 2, 262144, ROMTYPE_ODD , L"390630-02", 0xfe2f7fb9,0xc05c9c52,0xd014c66f,0x9019152b,0x3f2a2adc,0x2c678794) - { L"KS ROM v2.04 (A500+)", 2, 4, 37, 175, L"A500+\0", 524288, 7, 0, 0, ROMTYPE_KICK, 0, 0, L"390979-01", + ALTROMPN(59, 1, 1, 262144, ROMTYPE_EVEN, L"390629-02", 0x58327536,0xd1713d7f,0x31474a59,0x48e6d488,0xe3368606,0x1cf3d1e2) + ALTROMPN(59, 1, 2, 262144, ROMTYPE_ODD , L"390630-02", 0xfe2f7fb9,0xc05c9c52,0xd014c66f,0x9019152b,0x3f2a2adc,0x2c678794) + { L"KS ROM v2.04 (A500+)", 2, 4, 37, 175, L"A500+\0", 524288, 7, 0, 0, ROMTYPE_KICK, 0, 0, L"390979-01", 0xc3bdb240, 0xC5839F5C,0xB98A7A89,0x47065C3E,0xD2F14F5F,0x42E334A1 }, - { L"KS ROM v2.05 (A600)", 2, 5, 37, 299, L"A600\0", 524288, 8, 0, 0, ROMTYPE_KICK, 0, 0, L"391388-01", + { L"KS ROM v2.05 (A600)", 2, 5, 37, 299, L"A600\0", 524288, 8, 0, 0, ROMTYPE_KICK, 0, 0, L"391388-01", 0x83028fb5, 0x87508DE8,0x34DC7EB4,0x7359CEDE,0x72D2E3C8,0xA2E5D8DB }, - { L"KS ROM v2.05 (A600HD)", 2, 5, 37, 300, L"A600HD\0A600\0", 524288, 9, 0, 0, ROMTYPE_KICK, 0, 0, L"391304-01", + { L"KS ROM v2.05 (A600HD)", 2, 5, 37, 300, L"A600HD\0A600\0", 524288, 9, 0, 0, ROMTYPE_KICK, 0, 0, L"391304-01", 0x64466c2a, 0xF72D8914,0x8DAC39C6,0x96E30B10,0x859EBC85,0x9226637B }, - { L"KS ROM v2.05 (A600HD)", 2, 5, 37, 350, L"A600HD\0A600\0", 524288, 10, 0, 0, ROMTYPE_KICK, 0, 0, L"391304-02", + { L"KS ROM v2.05 (A600HD)", 2, 5, 37, 350, L"A600HD\0A600\0", 524288, 10, 0, 0, ROMTYPE_KICK, 0, 0, L"391304-02", 0x43b0df7b, 0x02843C42,0x53BBD29A,0xBA535B0A,0xA3BD9A85,0x034ECDE4 }, - { L"KS ROM v2.04 (A3000)", 2, 4, 37, 175, L"A3000\0", 524288, 71, 3, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v2.04 (A3000)", 2, 4, 37, 175, L"A3000\0", 524288, 71, 3, 0, ROMTYPE_KICK, 0, 0, NULL, 0x234a7233, 0xd82ebb59,0xafc53540,0xddf2d718,0x7ecf239b,0x7ea91590 }, - ALTROMPN(71, 1, 1, 262144, ROMTYPE_EVEN, L"390629-03", 0x7db1332b,0x48f14b31,0x279da675,0x7848df6f,0xeb531881,0x8f8f576c) - ALTROMPN(71, 1, 2, 262144, ROMTYPE_ODD , L"390630-03", 0xa245dbdf,0x83bab8e9,0x5d378b55,0xb0c6ae65,0x61385a96,0xf638598f) + ALTROMPN(71, 1, 1, 262144, ROMTYPE_EVEN, L"390629-03", 0x7db1332b,0x48f14b31,0x279da675,0x7848df6f,0xeb531881,0x8f8f576c) + ALTROMPN(71, 1, 2, 262144, ROMTYPE_ODD , L"390630-03", 0xa245dbdf,0x83bab8e9,0x5d378b55,0xb0c6ae65,0x61385a96,0xf638598f) - { L"KS ROM v3.0 (A1200)", 3, 0, 39, 106, L"A1200\0", 524288, 11, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v3.0 (A1200)", 3, 0, 39, 106, L"A1200\0", 524288, 11, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0x6c9b07d2, 0x70033828,0x182FFFC7,0xED106E53,0x73A8B89D,0xDA76FAA5 }, - ALTROMPN(11, 1, 1, 262144, ROMTYPE_EVEN, L"391523-01", 0xc742a412,0x999eb81c,0x65dfd07a,0x71ee1931,0x5d99c7eb,0x858ab186) - ALTROMPN(11, 1, 2, 262144, ROMTYPE_ODD , L"391524-01", 0xd55c6ec6,0x3341108d,0x3a402882,0xb5ef9d3b,0x242cbf3c,0x8ab1a3e9) - { L"KS ROM v3.0 (A4000)", 3, 0, 39, 106, L"A4000\0", 524288, 12, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROMPN(11, 1, 1, 262144, ROMTYPE_EVEN, L"391523-01", 0xc742a412,0x999eb81c,0x65dfd07a,0x71ee1931,0x5d99c7eb,0x858ab186) + ALTROMPN(11, 1, 2, 262144, ROMTYPE_ODD , L"391524-01", 0xd55c6ec6,0x3341108d,0x3a402882,0xb5ef9d3b,0x242cbf3c,0x8ab1a3e9) + { L"KS ROM v3.0 (A4000)", 3, 0, 39, 106, L"A4000\0", 524288, 12, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, 0x9e6ac152, 0xF0B4E9E2,0x9E12218C,0x2D5BD702,0x0E4E7852,0x97D91FD7 }, - ALTROMPN(12, 1, 1, 262144, ROMTYPE_EVEN, L"391513-02", 0x36f64dd0,0x196e9f3f,0x9cad934e,0x181c07da,0x33083b1f,0x0a3c702f) - ALTROMPN(12, 1, 2, 262144, ROMTYPE_ODD , L"391514-02", 0x17266a55,0x42fbed34,0x53d1f11c,0xcbde89a9,0x826f2d11,0x75cca5cc) - { L"KS ROM v3.1 (A4000)", 3, 1, 40, 70, L"A4000\0", 524288, 13, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROMPN(12, 1, 1, 262144, ROMTYPE_EVEN, L"391513-02", 0x36f64dd0,0x196e9f3f,0x9cad934e,0x181c07da,0x33083b1f,0x0a3c702f) + ALTROMPN(12, 1, 2, 262144, ROMTYPE_ODD , L"391514-02", 0x17266a55,0x42fbed34,0x53d1f11c,0xcbde89a9,0x826f2d11,0x75cca5cc) + { L"KS ROM v3.1 (A4000)", 3, 1, 40, 70, L"A4000\0", 524288, 13, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, 0x2b4566f1, 0x81c631dd,0x096bbb31,0xd2af9029,0x9c76b774,0xdb74076c }, - ALTROM(13, 1, 1, 262144, ROMTYPE_EVEN, 0xf9cbecc9,0x138d8cb4,0x3b8312fe,0x16d69070,0xde607469,0xb3d4078e) - ALTROM(13, 1, 2, 262144, ROMTYPE_ODD , 0xf8248355,0xc2379547,0x9fae3910,0xc185512c,0xa268b82f,0x1ae4fe05) - { L"KS ROM v3.1 (A500,A600,A2000)", 3, 1, 40, 63, L"A500\0A600\0A2000\0", 524288, 14, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROM(13, 1, 1, 262144, ROMTYPE_EVEN, 0xf9cbecc9,0x138d8cb4,0x3b8312fe,0x16d69070,0xde607469,0xb3d4078e) + ALTROM(13, 1, 2, 262144, ROMTYPE_ODD , 0xf8248355,0xc2379547,0x9fae3910,0xc185512c,0xa268b82f,0x1ae4fe05) + { L"KS ROM v3.1 (A500,A600,A2000)", 3, 1, 40, 63, L"A500\0A600\0A2000\0", 524288, 14, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0xfc24ae0d, 0x3B7F1493,0xB27E2128,0x30F989F2,0x6CA76C02,0x049F09CA }, - { L"KS ROM v3.1 (A1200)", 3, 1, 40, 68, L"A1200\0", 524288, 15, 1, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v3.1 (A1200)", 3, 1, 40, 68, L"A1200\0", 524288, 15, 1, 0, ROMTYPE_KICK, 0, 0, NULL, 0x1483a091, 0xE2154572,0x3FE8374E,0x91342617,0x604F1B3D,0x703094F1 }, - ALTROMPN(15, 1, 1, 262144, ROMTYPE_EVEN, L"391773-01", 0x08dbf275,0xb8800f5f,0x90929810,0x9ea69690,0xb1b8523f,0xa22ddb37) - ALTROMPN(15, 1, 2, 262144, ROMTYPE_ODD , L"391774-01", 0x16c07bf8,0x90e331be,0x1970b0e5,0x3f53a9b0,0x390b51b5,0x9b3869c2) - { L"KS ROM v3.1 (A3000)", 3, 1, 40, 68, L"A3000\0", 524288, 61, 2, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROMPN(15, 1, 1, 262144, ROMTYPE_EVEN, L"391773-01", 0x08dbf275,0xb8800f5f,0x90929810,0x9ea69690,0xb1b8523f,0xa22ddb37) + ALTROMPN(15, 1, 2, 262144, ROMTYPE_ODD , L"391774-01", 0x16c07bf8,0x90e331be,0x1970b0e5,0x3f53a9b0,0x390b51b5,0x9b3869c2) + { L"KS ROM v3.1 (A3000)", 3, 1, 40, 68, L"A3000\0", 524288, 61, 2, 0, ROMTYPE_KICK, 0, 0, NULL, 0xefb239cc, 0xF8E210D7,0x2B4C4853,0xE0C9B85D,0x223BA20E,0x3D1B36EE }, - ALTROM(61, 1, 1, 262144, ROMTYPE_EVEN, 0x286b9a0d,0x6763a225,0x8ec493f7,0x408cf663,0x110dae9a,0x17803ad1) - ALTROM(61, 1, 2, 262144, ROMTYPE_ODD , 0x0b8cde6a,0x5f02e97b,0x48ebbba8,0x7d516a56,0xb0400c6f,0xc3434d8d) - { L"KS ROM v3.1 (A4000)(Cloanto)", 3, 1, 40, 68, L"A4000\0", 524288, 31, 2 | 4, 1, ROMTYPE_KICK, 0, 0, NULL, + ALTROM(61, 1, 1, 262144, ROMTYPE_EVEN, 0x286b9a0d,0x6763a225,0x8ec493f7,0x408cf663,0x110dae9a,0x17803ad1) + ALTROM(61, 1, 2, 262144, ROMTYPE_ODD , 0x0b8cde6a,0x5f02e97b,0x48ebbba8,0x7d516a56,0xb0400c6f,0xc3434d8d) + { L"KS ROM v3.1 (A4000)(Cloanto)", 3, 1, 40, 68, L"A4000\0", 524288, 31, 2 | 4, 1, ROMTYPE_KICK, 0, 0, NULL, 0x43b6dd22, 0xC3C48116,0x0866E60D,0x085E436A,0x24DB3617,0xFF60B5F9 }, - { L"KS ROM v3.1 (A4000)", 3, 1, 40, 68, L"A4000\0", 524288, 16, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"KS ROM v3.1 (A4000)", 3, 1, 40, 68, L"A4000\0", 524288, 16, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, 0xd6bae334, 0x5FE04842,0xD04A4897,0x20F0F4BB,0x0E469481,0x99406F49 }, - ALTROM(16, 1, 1, 262144, ROMTYPE_EVEN, 0xb2af34f8,0x24e52b5e,0xfc020495,0x17387ab7,0xb1a1475f,0xc540350e) - ALTROM(16, 1, 2, 262144, ROMTYPE_ODD , 0xe65636a3,0x313c7cbd,0xa5779e56,0xf19a41d3,0x4e760f51,0x7626d882) - { L"KS ROM v3.1 (A4000T)", 3, 1, 40, 70, L"A4000T\0", 524288, 17, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROM(16, 1, 1, 262144, ROMTYPE_EVEN, 0xb2af34f8,0x24e52b5e,0xfc020495,0x17387ab7,0xb1a1475f,0xc540350e) + ALTROM(16, 1, 2, 262144, ROMTYPE_ODD , 0xe65636a3,0x313c7cbd,0xa5779e56,0xf19a41d3,0x4e760f51,0x7626d882) + { L"KS ROM v3.1 (A4000T)", 3, 1, 40, 70, L"A4000T\0", 524288, 17, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, 0x75932c3a, 0xB0EC8B84,0xD6768321,0xE01209F1,0x1E6248F2,0xF5281A21 }, - ALTROMPN(17, 1, 1, 262144, ROMTYPE_EVEN, L"391657-01", 0x0ca94f70,0xb3806eda,0xcb3362fc,0x16a154ce,0x1eeec5bf,0x5bc24789) - ALTROMPN(17, 1, 2, 262144, ROMTYPE_ODD , L"391658-01", 0xdfe03120,0xcd7a706c,0x431b04d8,0x7814d3a2,0xd8b39710,0x0cf44c0c) - { L"KS ROM v3.X (A4000)(Cloanto)", 3, 10, 45, 57, L"A4000\0", 524288, 46, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, + ALTROMPN(17, 1, 1, 262144, ROMTYPE_EVEN, L"391657-01", 0x0ca94f70,0xb3806eda,0xcb3362fc,0x16a154ce,0x1eeec5bf,0x5bc24789) + ALTROMPN(17, 1, 2, 262144, ROMTYPE_ODD , L"391658-01", 0xdfe03120,0xcd7a706c,0x431b04d8,0x7814d3a2,0xd8b39710,0x0cf44c0c) + { L"KS ROM v3.X (A4000)(Cloanto)", 3, 10, 45, 57, L"A4000\0", 524288, 46, 2 | 4, 0, ROMTYPE_KICK, 0, 0, NULL, 0x3ac99edc, 0x3cbfc9e1,0xfe396360,0x157bd161,0xde74fc90,0x1abee7ec }, - { L"CD32 KS ROM v3.1", 3, 1, 40, 60, L"CD32\0", 524288, 18, 1, 0, ROMTYPE_KICKCD32, 0, 0, NULL, + { L"CD32 KS ROM v3.1", 3, 1, 40, 60, L"CD32\0", 524288, 18, 1, 0, ROMTYPE_KICKCD32, 0, 0, NULL, 0x1e62d4a5, 0x3525BE88,0x87F79B59,0x29E017B4,0x2380A79E,0xDFEE542D }, - { L"CD32 extended ROM", 3, 1, 40, 60, L"CD32\0", 524288, 19, 1, 0, ROMTYPE_EXTCD32, 0, 0, NULL, + { L"CD32 extended ROM", 3, 1, 40, 60, L"CD32\0", 524288, 19, 1, 0, ROMTYPE_EXTCD32, 0, 0, NULL, 0x87746be2, 0x5BEF3D62,0x8CE59CC0,0x2A66E6E4,0xAE0DA48F,0x60E78F7F }, - /* plain CD32 rom */ - { L"CD32 ROM (KS + extended)", 3, 1, 40, 60, L"CD32\0", 2 * 524288, 64, 1, 0, ROMTYPE_KICKCD32 | ROMTYPE_EXTCD32 | ROMTYPE_CD32, 0, 0, NULL, + /* plain CD32 rom */ + { L"CD32 ROM (KS + extended)", 3, 1, 40, 60, L"CD32\0", 2 * 524288, 64, 1, 0, ROMTYPE_KICKCD32 | ROMTYPE_EXTCD32 | ROMTYPE_CD32, 0, 0, NULL, 0xf5d4f3c8, 0x9fa14825,0xc40a2475,0xa2eba5cf,0x325bd483,0xc447e7c1 }, - /* real CD32 rom dump 391640-03 */ - ALTROMPN(64, 1, 1, 2 * 524288, ROMTYPE_CD32, L"391640-03", 0xa4fbc94a, 0x816ce6c5,0x07787585,0x0c7d4345,0x2230a9ba,0x3a2902db ) - - { L"CD32 MPEG Cartridge ROM", 3, 1, 40, 30, L"CD32FMV\0", 262144, 23, 1, 0, ROMTYPE_CD32CART, 0, 0, NULL, + /* real CD32 rom dump 391640-03 */ + ALTROMPN(64, 1, 1, 2 * 524288, ROMTYPE_CD32, L"391640-03", 0xa4fbc94a, 0x816ce6c5,0x07787585,0x0c7d4345,0x2230a9ba,0x3a2902db ) + + { L"CD32 MPEG Cartridge ROM", 3, 1, 40, 30, L"CD32FMV\0", 262144, 23, 1, 0, ROMTYPE_CD32CART, 0, 0, NULL, 0xc35c37bf, 0x03ca81c7,0xa7b259cf,0x64bc9582,0x863eca0f,0x6529f435 }, - { L"CDTV extended ROM v1.00", 1, 0, 1, 0, L"CDTV\0", 262144, 20, 0, 0, ROMTYPE_EXTCDTV, 0, 0, NULL, + { L"CDTV extended ROM v1.00", 1, 0, 1, 0, L"CDTV\0", 262144, 20, 0, 0, ROMTYPE_EXTCDTV, 0, 0, NULL, 0x42baa124, 0x7BA40FFA,0x17E500ED,0x9FED041F,0x3424BD81,0xD9C907BE }, - ALTROMPN(20, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, L"252606-01", 0x791cb14b,0x277a1778,0x92449635,0x3ffe56be,0x68063d2a,0x334360e4) - ALTROMPN(20, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, L"252607-01", 0xaccbbc2e,0x41b06d16,0x79c6e693,0x3c3378b7,0x626025f7,0x641ebc5c) - { L"CDTV extended ROM v2.07", 2, 7, 2, 7, L"CDTV\0", 262144, 22, 0, 0, ROMTYPE_EXTCDTV, 0, 0, NULL, + ALTROMPN(20, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, L"252606-01", 0x791cb14b,0x277a1778,0x92449635,0x3ffe56be,0x68063d2a,0x334360e4) + ALTROMPN(20, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, L"252607-01", 0xaccbbc2e,0x41b06d16,0x79c6e693,0x3c3378b7,0x626025f7,0x641ebc5c) + { L"CDTV extended ROM v2.07", 2, 7, 2, 7, L"CDTV\0", 262144, 22, 0, 0, ROMTYPE_EXTCDTV, 0, 0, NULL, 0xceae68d2, 0x5BC114BB,0xA29F60A6,0x14A31174,0x5B3E2464,0xBFA06846 }, - ALTROM(22, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x36d73cb8,0x9574e546,0x4b390697,0xf28f9a43,0x4e604e5e,0xf5e5490a) - ALTROM(22, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x6e84dce7,0x01a0679e,0x895a1a0f,0x559c7253,0xf539606b,0xd447b54f) - { L"CDTV/A570 extended ROM v2.30", 2, 30, 2, 30, L"CDTV\0", 262144, 21, 0, 0, ROMTYPE_EXTCDTV, 0, 0, L"391298-01", + ALTROM(22, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x36d73cb8,0x9574e546,0x4b390697,0xf28f9a43,0x4e604e5e,0xf5e5490a) + ALTROM(22, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x6e84dce7,0x01a0679e,0x895a1a0f,0x559c7253,0xf539606b,0xd447b54f) + { L"CDTV/A570 extended ROM v2.30", 2, 30, 2, 30, L"CDTV\0", 262144, 21, 0, 0, ROMTYPE_EXTCDTV, 0, 0, L"391298-01", 0x30b54232, 0xED7E461D,0x1FFF3CDA,0x321631AE,0x42B80E3C,0xD4FA5EBB }, - ALTROM(21, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x48e4d74f,0x54946054,0x2269e410,0x36018402,0xe1f6b855,0xfd89092b) - ALTROM(21, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x8a54f362,0x03df800f,0x032046fd,0x892f6e7e,0xec08b76d,0x33981e8c) + ALTROM(21, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x48e4d74f,0x54946054,0x2269e410,0x36018402,0xe1f6b855,0xfd89092b) + ALTROM(21, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x8a54f362,0x03df800f,0x032046fd,0x892f6e7e,0xec08b76d,0x33981e8c) - { L"A1000 bootstrap ROM", 0, 0, 0, 0, L"A1000\0", 65536, 24, 0, 0, ROMTYPE_KICK, 0, 0, NULL, + { L"A1000 bootstrap ROM", 0, 0, 0, 0, L"A1000\0", 65536, 24, 0, 0, ROMTYPE_KICK, 0, 0, NULL, 0x0b1ad2d0, 0xBA93B8B8,0x5CA0D83A,0x68225CC3,0x3B95050D,0x72D2FDD7 }, - ALTROM(24, 1, 1, 8192, 0, 0x62f11c04, 0xC87F9FAD,0xA4EE4E69,0xF3CCA0C3,0x6193BE82,0x2B9F5FE6) - ALTROMPN(24, 2, 1, 4096, ROMTYPE_EVEN | ROMTYPE_8BIT, L"252179-01", 0x42553bc4,0x8855a97f,0x7a44e3f6,0x2d1c88d9,0x38fee1f4,0xc606af5b) - ALTROMPN(24, 2, 2, 4096, ROMTYPE_ODD | ROMTYPE_8BIT, L"252180-01", 0x8e5b9a37,0xd10f1564,0xb99f5ffe,0x108fa042,0x362e877f,0x569de2c3) + ALTROM(24, 1, 1, 8192, 0, 0x62f11c04, 0xC87F9FAD,0xA4EE4E69,0xF3CCA0C3,0x6193BE82,0x2B9F5FE6) + ALTROMPN(24, 2, 1, 4096, ROMTYPE_EVEN | ROMTYPE_8BIT, L"252179-01", 0x42553bc4,0x8855a97f,0x7a44e3f6,0x2d1c88d9,0x38fee1f4,0xc606af5b) + ALTROMPN(24, 2, 2, 4096, ROMTYPE_ODD | ROMTYPE_8BIT, L"252180-01", 0x8e5b9a37,0xd10f1564,0xb99f5ffe,0x108fa042,0x362e877f,0x569de2c3) - { L"The Diagnostic 2.0 (Logica)", 2, 0, 2, 0, L"LOGICA\0", 524288, 72, 0, 0, ROMTYPE_KICK | ROMTYPE_SPECIALKICK, 0, 0, NULL, + { L"The Diagnostic 2.0 (Logica)", 2, 0, 2, 0, L"LOGICA\0", 524288, 72, 0, 0, ROMTYPE_KICK | ROMTYPE_SPECIALKICK, 0, 0, NULL, 0x8484f426, 0xba10d161,0x66b2e2d6,0x177c979c,0x99edf846,0x2b21651e }, - { L"Freezer: Action Replay Mk I v1.00", 1, 0, 1, 0, L"AR\0", 65536, 52, 0, 0, ROMTYPE_AR, 0, 1, NULL, + { L"Freezer: Action Replay Mk I v1.00", 1, 0, 1, 0, L"AR\0", 65536, 52, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x2d921771, 0x1EAD9DDA,0x2DAD2914,0x6441F5EF,0x72183750,0x22E01248 }, - ALTROM(52, 1, 1, 32768, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x82d6eb87, 0x7c9bac11,0x28666017,0xeee6f019,0x63fb3890,0x7fbea355) - ALTROM(52, 1, 2, 32768, ROMTYPE_ODD | ROMTYPE_8BIT, 0x40ae490c, 0x81d8e432,0x01b73fd9,0x2e204ebd,0x68af8602,0xb62ce397) - { L"Freezer: Action Replay Mk I v1.50", 1, 50, 1, 50, L"AR\0", 65536, 25, 0, 0, ROMTYPE_AR, 0, 1, NULL, + ALTROM(52, 1, 1, 32768, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x82d6eb87, 0x7c9bac11,0x28666017,0xeee6f019,0x63fb3890,0x7fbea355) + ALTROM(52, 1, 2, 32768, ROMTYPE_ODD | ROMTYPE_8BIT, 0x40ae490c, 0x81d8e432,0x01b73fd9,0x2e204ebd,0x68af8602,0xb62ce397) + { L"Freezer: Action Replay Mk I v1.50", 1, 50, 1, 50, L"AR\0", 65536, 25, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0xd4ce0675, 0x843B433B,0x2C56640E,0x045D5FDC,0x854DC6B1,0xA4964E7C }, - ALTROM(25, 1, 1, 32768, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x7fbd6de2, 0xb5f71a5c,0x09d65ecc,0xa8a3bc93,0x93558461,0xca190228) - ALTROM(25, 1, 2, 32768, ROMTYPE_ODD | ROMTYPE_8BIT, 0x43018069, 0xad8ff242,0xb2cbf125,0x1fc53a73,0x581cf57a,0xb69cee00) - { L"Freezer: Action Replay Mk II v2.05", 2, 5, 2, 5, L"AR\0", 131072, 26, 0, 0, ROMTYPE_AR, 0, 1, NULL, + ALTROM(25, 1, 1, 32768, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x7fbd6de2, 0xb5f71a5c,0x09d65ecc,0xa8a3bc93,0x93558461,0xca190228) + ALTROM(25, 1, 2, 32768, ROMTYPE_ODD | ROMTYPE_8BIT, 0x43018069, 0xad8ff242,0xb2cbf125,0x1fc53a73,0x581cf57a,0xb69cee00) + { L"Freezer: Action Replay Mk II v2.05", 2, 5, 2, 5, L"AR\0", 131072, 26, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x1287301f, 0xF6601DE8,0x888F0050,0x72BF562B,0x9F533BBC,0xAF1B0074 }, - { L"Freezer: Action Replay Mk II v2.12", 2, 12, 2, 12, L"AR\0", 131072, 27, 0, 0, ROMTYPE_AR, 0, 1, NULL, + { L"Freezer: Action Replay Mk II v2.12", 2, 12, 2, 12, L"AR\0", 131072, 27, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x804d0361, 0x3194A07A,0x0A82D8B5,0xF2B6AEFA,0x3CA581D6,0x8BA8762B }, - { L"Freezer: Action Replay Mk II v2.14", 2, 14, 2, 14, L"AR\0", 131072, 28, 0, 0, ROMTYPE_AR, 0, 1, NULL, + { L"Freezer: Action Replay Mk II v2.14", 2, 14, 2, 14, L"AR\0", 131072, 28, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x49650e4f, 0x255D6DF6,0x3A4EAB0A,0x838EB1A1,0x6A267B09,0x59DFF634 }, - { L"Freezer: Action Replay Mk III v3.09", 3, 9, 3, 9, L"AR\0", 262144, 29, 0, 0, ROMTYPE_AR, 0, 1, NULL, + { L"Freezer: Action Replay Mk III v3.09", 3, 9, 3, 9, L"AR\0", 262144, 29, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x0ed9b5aa, 0x0FF3170A,0xBBF0CA64,0xC9DD93D6,0xEC0C7A01,0xB5436824 }, - ALTROM(29, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2b84519f, 0x7841873b,0xf009d834,0x1dfa2794,0xb3751bac,0xf86adcc8) - ALTROM(29, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x1d35bd56, 0x6464be16,0x26b51949,0x9e76e4e3,0x409e8016,0x515d48b6) - { L"Freezer: Action Replay Mk III v3.17", 3, 17, 3, 17, L"AR\0", 262144, 30, 0, 0, ROMTYPE_AR, 0, 1, NULL, + ALTROM(29, 1, 1, 131072, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2b84519f, 0x7841873b,0xf009d834,0x1dfa2794,0xb3751bac,0xf86adcc8) + ALTROM(29, 1, 2, 131072, ROMTYPE_ODD | ROMTYPE_8BIT, 0x1d35bd56, 0x6464be16,0x26b51949,0x9e76e4e3,0x409e8016,0x515d48b6) + { L"Freezer: Action Replay Mk III v3.17", 3, 17, 3, 17, L"AR\0", 262144, 30, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0xc8a16406, 0x5D4987C2,0xE3FFEA8B,0x1B02E314,0x30EF190F,0x2DB76542 }, - { L"Freezer: Action Replay 1200", 0, 0, 0, 0, L"AR\0", 262144, 47, 0, 0, ROMTYPE_AR, 0, 1, NULL, + { L"Freezer: Action Replay 1200", 0, 0, 0, 0, L"AR\0", 262144, 47, 0, 0, ROMTYPE_AR, 0, 1, NULL, 0x8d760101, 0x0F6AB834,0x2810094A,0xC0642F62,0xBA42F78B,0xC0B07E6A }, - { L"Freezer: Action Cartridge Super IV Professional", 0, 0, 0, 0, L"SUPERIV\0", 0, 62, 0, 0, ROMTYPE_SUPERIV, 0, 1, NULL, + { L"Freezer: Action Cartridge Super IV Professional", 0, 0, 0, 0, L"SUPERIV\0", 0, 62, 0, 0, ROMTYPE_SUPERIV, 0, 1, NULL, 0xffffffff, 0, 0, 0, 0, 0, L"SuperIV" }, - { L"Freezer: Action Cart. Super IV Pro (+ROM v4.3)", 4, 3, 4, 3, L"SUPERIV\0", 170368, 60, 0, 0, ROMTYPE_SUPERIV, 0, 1, NULL, + { L"Freezer: Action Cart. Super IV Pro (+ROM v4.3)", 4, 3, 4, 3, L"SUPERIV\0", 170368, 60, 0, 0, ROMTYPE_SUPERIV, 0, 1, NULL, 0xe668a0be, 0x633A6E65,0xA93580B8,0xDDB0BE9C,0x9A64D4A1,0x7D4B4801 }, - { L"Freezer: X-Power Professional 500 v1.2", 1, 2, 1, 2, L"XPOWER\0", 131072, 65, 0, 0, ROMTYPE_XPOWER, 0, 1, NULL, + { L"Freezer: X-Power Professional 500 v1.2", 1, 2, 1, 2, L"XPOWER\0", 131072, 65, 0, 0, ROMTYPE_XPOWER, 0, 1, NULL, 0x9e70c231, 0xa2977a1c,0x41a8ca7d,0x4af4a168,0x726da542,0x179d5963 }, - ALTROM(65, 1, 1, 65536, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xf98742e4,0xe8e683ba,0xd8b38d1f,0x79f3ad83,0xa9e67c6f,0xa91dc96c) - ALTROM(65, 1, 2, 65536, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xdfb9984b,0x8d6bdd49,0x469ec8e2,0x0143fbb3,0x72e92500,0x99f07910) - { L"Freezer: X-Power Professional 500 v1.3", 1, 2, 1, 2, L"XPOWER\0", 131072, 68, 0, 0, ROMTYPE_XPOWER, 0, 1, NULL, + ALTROM(65, 1, 1, 65536, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xf98742e4,0xe8e683ba,0xd8b38d1f,0x79f3ad83,0xa9e67c6f,0xa91dc96c) + ALTROM(65, 1, 2, 65536, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xdfb9984b,0x8d6bdd49,0x469ec8e2,0x0143fbb3,0x72e92500,0x99f07910) + { L"Freezer: X-Power Professional 500 v1.3", 1, 2, 1, 2, L"XPOWER\0", 131072, 68, 0, 0, ROMTYPE_XPOWER, 0, 1, NULL, 0x31e057f0, 0x84650266,0x465d1859,0x7fd71dee,0x00775930,0xb7e450ee }, - ALTROM(68, 1, 1, 65536, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x0b2ce0c7,0x45ad5456,0x89192404,0x956f47ce,0xf66a5274,0x57ace33b) - ALTROM(68, 1, 2, 65536, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x34580c35,0x8ad42566,0x7364f238,0x978f4381,0x08f8d5ec,0x470e72ea) - { L"Freezer: Nordic Power v1.5", 1, 5, 1, 5, L"NPOWER\0", 65536, 69, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, + ALTROM(68, 1, 1, 65536, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x0b2ce0c7,0x45ad5456,0x89192404,0x956f47ce,0xf66a5274,0x57ace33b) + ALTROM(68, 1, 2, 65536, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x34580c35,0x8ad42566,0x7364f238,0x978f4381,0x08f8d5ec,0x470e72ea) + { L"Freezer: Nordic Power v1.5", 1, 5, 1, 5, L"NPOWER\0", 65536, 69, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, 0x83b4b21c, 0xc56ced25,0x506a5aab,0x3fa13813,0x4fc9e5ae,0x0f9d3709 }, - ALTROM(69, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xdd207174,0xae67652d,0x64f5db20,0x0f4b2110,0xee59567f,0xfbd90a1b) - ALTROM(69, 1, 2, 32768, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x8f93d85d,0x73c62d21,0x40c0c092,0x6315b702,0xdd5d0f05,0x3dad7fab) - { L"Freezer: Nordic Power v2.0", 2, 0, 2, 0, L"NPOWER\0", 65536, 67, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, + ALTROM(69, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xdd207174,0xae67652d,0x64f5db20,0x0f4b2110,0xee59567f,0xfbd90a1b) + ALTROM(69, 1, 2, 32768, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x8f93d85d,0x73c62d21,0x40c0c092,0x6315b702,0xdd5d0f05,0x3dad7fab) + { L"Freezer: Nordic Power v2.0", 2, 0, 2, 0, L"NPOWER\0", 65536, 67, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, 0xa4db2906, 0x0aec68f7,0x25470c89,0x6b699ff4,0x6623dec5,0xc777466e }, - ALTROM(67, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xb21be46c,0x50dc607c,0xce976bbd,0x3841eaf0,0x591ddc7e,0xa1939ad2) - ALTROM(67, 1, 2, 32768, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x96057aed,0xdd9209e2,0x1d5edfc1,0xcdb52abe,0x93de0f35,0xc43da696) - { L"Freezer: Nordic Power v3.0", 3, 0, 3, 0, L"NPOWER\0", 65536, 70, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, + ALTROM(67, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xb21be46c,0x50dc607c,0xce976bbd,0x3841eaf0,0x591ddc7e,0xa1939ad2) + ALTROM(67, 1, 2, 32768, ROMTYPE_ODD |ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0x96057aed,0xdd9209e2,0x1d5edfc1,0xcdb52abe,0x93de0f35,0xc43da696) + { L"Freezer: Nordic Power v3.0", 3, 0, 3, 0, L"NPOWER\0", 65536, 70, 0, 0, ROMTYPE_NORDIC, 0, 1, NULL, 0x72850aef, 0x59c91d1f,0xa8f118f9,0x0bdba05a,0x9ae788d7,0x7a6cc7c9 }, - ALTROM(70, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xf3330e1f,0x3a597db2,0xb7d11b6c,0xb8e13496,0xc215f223,0x88c4ca3c) - ALTROM(70, 1, 2, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xee58e0f9,0x4148f4cb,0xb42cec33,0x8ca144de,0xd4f54118,0xe0f185dd) - { L"Freezer: HRTMon v2.32 (built-in)", 0, 0, 0, 0, L"HRTMON\0", 0, 63, 0, 0, ROMTYPE_HRTMON, 0, 1, NULL, + ALTROM(70, 1, 1, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xf3330e1f,0x3a597db2,0xb7d11b6c,0xb8e13496,0xc215f223,0x88c4ca3c) + ALTROM(70, 1, 2, 32768, ROMTYPE_EVEN|ROMTYPE_SCRAMBLED|ROMTYPE_8BIT, 0xee58e0f9,0x4148f4cb,0xb42cec33,0x8ca144de,0xd4f54118,0xe0f185dd) + { L"Freezer: HRTMon v2.32 (built-in)", 0, 0, 0, 0, L"HRTMON\0", 0, 63, 0, 0, ROMTYPE_HRTMON, 0, 1, NULL, 0xffffffff, 0, 0, 0, 0, 0, L"HRTMon" }, - { L"A590/A2091 SCSI boot ROM", 6, 0, 6, 0, L"A590\0A2091\0", 16384, 53, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, + { L"A590/A2091 SCSI boot ROM", 6, 0, 6, 0, L"A590\0A2091\0", 16384, 53, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, 0x8396cf4e, 0x5E03BC61,0x8C862ABE,0x7BF79723,0xB4EEF4D2,0x1859A0F2 }, - ALTROM(53, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xb0b8cf24,0xfcf40175,0x05f4d441,0x814b45d5,0x59c19eab,0x43816b30) - ALTROM(53, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2e77bbff,0x8a098845,0x068f32cf,0xa4d34a27,0x8cd290f6,0x1d35a52c) - { L"A590/A2091 SCSI boot ROM", 6, 6, 6, 6, L"A590\0A2091\0", 16384, 54, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, + ALTROM(53, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xb0b8cf24,0xfcf40175,0x05f4d441,0x814b45d5,0x59c19eab,0x43816b30) + ALTROM(53, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2e77bbff,0x8a098845,0x068f32cf,0xa4d34a27,0x8cd290f6,0x1d35a52c) + { L"A590/A2091 SCSI boot ROM", 6, 6, 6, 6, L"A590\0A2091\0", 16384, 54, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, 0x33e00a7a, 0x739BB828,0xE874F064,0x9360F59D,0x26B5ED3F,0xBC99BB66 }, - ALTROM(54, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xe536bbb2,0xfd7f8a6d,0xa18c1b02,0xd07eb990,0xc2467a24,0x183ede12) - ALTROM(54, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0xc0871d25,0xe155f18a,0xbb90cf82,0x0589c15e,0x70559d3b,0x6b391af8) - { L"A590/A2091 SCSI boot ROM", 7, 0, 7, 0, L"A590\0A2091\0", 16384, 55, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, + ALTROM(54, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xe536bbb2,0xfd7f8a6d,0xa18c1b02,0xd07eb990,0xc2467a24,0x183ede12) + ALTROM(54, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0xc0871d25,0xe155f18a,0xbb90cf82,0x0589c15e,0x70559d3b,0x6b391af8) + { L"A590/A2091 SCSI boot ROM", 7, 0, 7, 0, L"A590\0A2091\0", 16384, 55, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, 0x714a97a2, 0xE50F01BA,0xF2899892,0x85547863,0x72A82C33,0x3C91276E }, - ALTROM(55, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xa9ccffed,0x149f5bd5,0x2e2d2990,0x4e3de483,0xb9ad7724,0x48e9278e) - ALTROM(55, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2942747a,0xdbd7648e,0x79c75333,0x7ff3e4f4,0x91de224b,0xf05e6bb6) - { L"A590/A2091 SCSI Guru boot ROM", 6, 14, 6, 14, L"A590\0A2091\0", 32768, 56, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, + ALTROM(55, 1, 1, 8192, ROMTYPE_ODD | ROMTYPE_8BIT, 0xa9ccffed,0x149f5bd5,0x2e2d2990,0x4e3de483,0xb9ad7724,0x48e9278e) + ALTROM(55, 1, 2, 8192, ROMTYPE_EVEN | ROMTYPE_8BIT, 0x2942747a,0xdbd7648e,0x79c75333,0x7ff3e4f4,0x91de224b,0xf05e6bb6) + { L"A590/A2091 SCSI Guru boot ROM", 6, 14, 6, 14, L"A590\0A2091\0", 32768, 56, 0, 0, ROMTYPE_A2091BOOT, 0, 0, NULL, 0x04e52f93, 0x6DA21B6F,0x5E8F8837,0xD64507CD,0x8A4D5CDC,0xAC4F426B }, - { L"A4091 SCSI boot ROM", 40, 9, 40, 9, L"A4091\0", 32768, 57, 0, 0, ROMTYPE_A4091BOOT, 0, 0, NULL, + { L"A4091 SCSI boot ROM", 40, 9, 40, 9, L"A4091\0", 32768, 57, 0, 0, ROMTYPE_A4091BOOT, 0, 0, NULL, 0x00000000, 0, 0, 0, 0, 0 }, - { L"A4091 SCSI boot ROM", 40, 13, 40, 13, L"A4091\0", 32768, 58, 0, 0, ROMTYPE_A4091BOOT, 0, 0, NULL, + { L"A4091 SCSI boot ROM", 40, 13, 40, 13, L"A4091\0", 32768, 58, 0, 0, ROMTYPE_A4091BOOT, 0, 0, NULL, 0x54cb9e85, 0x3CE66919,0xF6FD6797,0x4923A12D,0x91B730F1,0xFFB4A7BA }, - { L"Arcadia OnePlay 2.11", 0, 0, 0, 0, L"ARCADIA\0", 0, 49, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, - { L"Arcadia TenPlay 2.11", 0, 0, 0, 0, L"ARCADIA\0", 0, 50, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, - { L"Arcadia OnePlay 3.00", 0, 0, 0, 0, L"ARCADIA\0", 0, 51, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, - - { L"Arcadia SportTime Table Hockey", 0, 0, 0, 0, L"ARCADIA\0", 0, 33, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia SportTime Bowling", 0, 0, 0, 0, L"ARCADIA\0", 0, 34, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia World Darts", 0, 0, 0, 0, L"ARCADIA\0", 0, 35, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Magic Johnson's Fast Break", 0, 0, 0, 0, L"ARCADIA\0", 0, 36, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Leader Board Golf", 0, 0, 0, 0, L"ARCADIA\0", 0, 37, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Leader Board Golf (alt)", 0, 0, 0, 0, L"ARCADIA\0", 0, 38, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Ninja Mission", 0, 0, 0, 0, L"ARCADIA\0", 0, 39, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Road Wars", 0, 0, 0, 0, L"ARCADIA\0", 0, 40, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Sidewinder", 0, 0, 0, 0, L"ARCADIA\0", 0, 41, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Spot", 0, 0, 0, 0, L"ARCADIA\0", 0, 42, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Space Ranger", 0, 0, 0, 0, L"ARCADIA\0", 0, 43, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia Xenon", 0, 0, 0, 0, L"ARCADIA\0", 0, 44, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - { L"Arcadia World Trophy Soccer", 0, 0, 0, 0, L"ARCADIA\0", 0, 45, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, - - { NULL } + { L"Arcadia OnePlay 2.11", 0, 0, 0, 0, L"ARCADIA\0", 0, 49, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, + { L"Arcadia TenPlay 2.11", 0, 0, 0, 0, L"ARCADIA\0", 0, 50, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, + { L"Arcadia OnePlay 3.00", 0, 0, 0, 0, L"ARCADIA\0", 0, 51, 0, 0, ROMTYPE_ARCADIABIOS, 0, 0 }, + + { L"Arcadia SportTime Table Hockey", 0, 0, 0, 0, L"ARCADIA\0", 0, 33, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia SportTime Bowling", 0, 0, 0, 0, L"ARCADIA\0", 0, 34, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia World Darts", 0, 0, 0, 0, L"ARCADIA\0", 0, 35, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Magic Johnson's Fast Break", 0, 0, 0, 0, L"ARCADIA\0", 0, 36, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Leader Board Golf", 0, 0, 0, 0, L"ARCADIA\0", 0, 37, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Leader Board Golf (alt)", 0, 0, 0, 0, L"ARCADIA\0", 0, 38, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Ninja Mission", 0, 0, 0, 0, L"ARCADIA\0", 0, 39, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Road Wars", 0, 0, 0, 0, L"ARCADIA\0", 0, 40, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Sidewinder", 0, 0, 0, 0, L"ARCADIA\0", 0, 41, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Spot", 0, 0, 0, 0, L"ARCADIA\0", 0, 42, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Space Ranger", 0, 0, 0, 0, L"ARCADIA\0", 0, 43, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia Xenon", 0, 0, 0, 0, L"ARCADIA\0", 0, 44, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + { L"Arcadia World Trophy Soccer", 0, 0, 0, 0, L"ARCADIA\0", 0, 45, 0, 0, ROMTYPE_ARCADIAGAME, 0, 2 }, + + { NULL } }; void romlist_clear (void) { - int i; - int mask = 0; - struct romdata *parent; - TCHAR *pn; - - xfree (rl); - rl = 0; - romlist_cnt = 0; - parent = 0; - pn = NULL; - for (i = 0; roms[i].name; i++) { - struct romdata *rd = &roms[i]; - if (rd->group == 0) { - parent = rd; - mask = rd->type; - pn = parent->partnumber; - } else { - rd->type &= ~ROMTYPE_MASK; - rd->type |= mask & ROMTYPE_MASK; - if (rd->partnumber && !pn) { - TCHAR *newpn; - if (parent->partnumber == NULL) - parent->partnumber = my_strdup (L""); - newpn = xcalloc ((_tcslen (parent->partnumber) + 1 + _tcslen (rd->partnumber) + 1) * sizeof (TCHAR), 1); - if (_tcslen (parent->partnumber) > 0) { - _tcscpy (newpn, parent->partnumber); - _tcscat (newpn, L"/"); + int i; + int mask = 0; + struct romdata *parent; + TCHAR *pn; + + xfree (rl); + rl = 0; + romlist_cnt = 0; + parent = 0; + pn = NULL; + for (i = 0; roms[i].name; i++) { + struct romdata *rd = &roms[i]; + if (rd->group == 0) { + parent = rd; + mask = rd->type; + pn = parent->partnumber; + } else { + rd->type &= ~ROMTYPE_MASK; + rd->type |= mask & ROMTYPE_MASK; + if (rd->partnumber && !pn) { + TCHAR *newpn; + if (parent->partnumber == NULL) + parent->partnumber = my_strdup (L""); + newpn = xcalloc ((_tcslen (parent->partnumber) + 1 + _tcslen (rd->partnumber) + 1) * sizeof (TCHAR), 1); + if (_tcslen (parent->partnumber) > 0) { + _tcscpy (newpn, parent->partnumber); + _tcscat (newpn, L"/"); + } + _tcscat (newpn, rd->partnumber); + xfree (parent->partnumber); + parent->partnumber = newpn; + } } - _tcscat (newpn, rd->partnumber); - xfree (parent->partnumber); - parent->partnumber = newpn; - } } - } } /* remove rom entries that need 2 or more roms but not everything required is present */ static void romlist_cleanup (void) { - int i = 0; - while (roms[i].name) { - struct romdata *rd = &roms[i]; - int grp = rd->group >> 16; - int ok = 1; - int j = i; - int k = i; - while (rd->name && (rd->group >> 16) == grp && grp > 0) { - struct romlist *rl = romlist_getrl (rd); - if (!rl) - ok = 0; - rd++; - j++; - } - if (ok == 0) { - while (i < j) { - struct romlist *rl = romlist_getrl (&roms[i]); - if (rl) { - int cnt = romlist_cnt - i - 1; - write_log (L"%s '%s' removed from romlist\n", roms[k].name, rl->path); - xfree (rl->path); - if (cnt > 0) - memmove (rl, rl + 1, cnt * sizeof (struct romlist)); - romlist_cnt--; + int i = 0; + while (roms[i].name) { + struct romdata *rd = &roms[i]; + int grp = rd->group >> 16; + int ok = 1; + int j = i; + int k = i; + while (rd->name && (rd->group >> 16) == grp && grp > 0) { + struct romlist *rl = romlist_getrl (rd); + if (!rl) + ok = 0; + rd++; + j++; + } + if (ok == 0) { + while (i < j) { + struct romlist *rl = romlist_getrl (&roms[i]); + if (rl) { + int cnt = romlist_cnt - i - 1; + write_log (L"%s '%s' removed from romlist\n", roms[k].name, rl->path); + xfree (rl->path); + if (cnt > 0) + memmove (rl, rl + 1, cnt * sizeof (struct romlist)); + romlist_cnt--; + } + i++; + } } i++; - } } - i++; - } - for (i = 0; i < romlist_cnt; i++) { - struct romlist *rll = &rl[i]; - //write_log (L"%s (%s)\n", rll->rd->name, rll->path); - } + for (i = 0; i < romlist_cnt; i++) { + struct romlist *rll = &rl[i]; + //write_log (L"%s (%s)\n", rll->rd->name, rll->path); + } } struct romlist **getromlistbyident(int ver, int rev, int subver, int subrev, TCHAR *model, int all) { - int i, j, ok, out, max; - struct romdata *rd; - struct romlist **rdout, *rltmp; - void *buf; - static struct romlist rlstatic; - - for (i = 0; roms[i].name; i++); - if (all) - max = i; - else - max = romlist_cnt; - buf = xmalloc ((sizeof (struct romlist*) + sizeof (struct romlist)) * (i + 1)); - rdout = (struct romlist**)buf; - rltmp = (struct romlist*)((uae_u8*)buf + (i + 1) * sizeof (struct romlist*)); - out = 0; - for (i = 0; i < max; i++) { - ok = 0; - if (!all) - rd = rl[i].rd; + int i, j, ok, out, max; + struct romdata *rd; + struct romlist **rdout, *rltmp; + void *buf; + static struct romlist rlstatic; + + for (i = 0; roms[i].name; i++); + if (all) + max = i; else - rd = &roms[i]; - if (rd->group) - continue; - if (model && !_tcsicmp (model, rd->name)) - ok = 2; - if (rd->ver == ver && (rev < 0 || rd->rev == rev)) { - if (subver >= 0) { - if (rd->subver == subver && (subrev < 0 || rd->subrev == subrev) && rd->subver > 0) - ok = 1; - } else { - ok = 1; - } - } - if (!ok) - continue; - if (model && ok < 2) { - TCHAR *p = rd->model; - ok = 0; - while (*p) { - if (!_tcscmp(rd->model, model)) { - ok = 1; - break; + max = romlist_cnt; + buf = xmalloc ((sizeof (struct romlist*) + sizeof (struct romlist)) * (i + 1)); + rdout = (struct romlist**)buf; + rltmp = (struct romlist*)((uae_u8*)buf + (i + 1) * sizeof (struct romlist*)); + out = 0; + for (i = 0; i < max; i++) { + ok = 0; + if (!all) + rd = rl[i].rd; + else + rd = &roms[i]; + if (rd->group) + continue; + if (model && !_tcsicmp (model, rd->name)) + ok = 2; + if (rd->ver == ver && (rev < 0 || rd->rev == rev)) { + if (subver >= 0) { + if (rd->subver == subver && (subrev < 0 || rd->subrev == subrev) && rd->subver > 0) + ok = 1; + } else { + ok = 1; + } + } + if (!ok) + continue; + if (model && ok < 2) { + TCHAR *p = rd->model; + ok = 0; + while (*p) { + if (!_tcscmp(rd->model, model)) { + ok = 1; + break; + } + p = p + _tcslen(p) + 1; + } + } + if (!model && rd->type != ROMTYPE_KICK) + ok = 0; + if (ok) { + if (all) { + rdout[out++] = rltmp; + rltmp->path = NULL; + rltmp->rd = rd; + rltmp++; + } else { + rdout[out++] = &rl[i]; + } } - p = p + _tcslen(p) + 1; - } } - if (!model && rd->type != ROMTYPE_KICK) - ok = 0; - if (ok) { - if (all) { - rdout[out++] = rltmp; - rltmp->path = NULL; - rltmp->rd = rd; - rltmp++; - } else { - rdout[out++] = &rl[i]; - } + if (out == 0) { + xfree (rdout); + return NULL; } - } - if (out == 0) { - xfree (rdout); - return NULL; - } - for (i = 0; i < out; i++) { - int v1 = rdout[i]->rd->subver * 1000 + rdout[i]->rd->subrev; - for (j = i + 1; j < out; j++) { - int v2 = rdout[j]->rd->subver * 1000 + rdout[j]->rd->subrev; - if (v1 < v2) { - struct romlist *rltmp = rdout[j]; - rdout[j] = rdout[i]; - rdout[i] = rltmp; - } + for (i = 0; i < out; i++) { + int v1 = rdout[i]->rd->subver * 1000 + rdout[i]->rd->subrev; + for (j = i + 1; j < out; j++) { + int v2 = rdout[j]->rd->subver * 1000 + rdout[j]->rd->subrev; + if (v1 < v2) { + struct romlist *rltmp = rdout[j]; + rdout[j] = rdout[i]; + rdout[i] = rltmp; + } + } } - } - rdout[out] = NULL; - return rdout; + rdout[out] = NULL; + return rdout; } struct romdata *getarcadiarombyname (TCHAR *name) { - int i; - for (i = 0; roms[i].name; i++) { - if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIAGAME || roms[i].type == ROMTYPE_ARCADIAGAME)) { - TCHAR *p = roms[i].name; - p = p + _tcslen (p) + 1; - if (_tcslen (name) >= _tcslen (p) + 4) { - TCHAR *p2 = name + _tcslen (name) - _tcslen (p) - 4; - if (!memcmp (p, p2, _tcslen (p)) && !memcmp (p2 + _tcslen (p2) - 4, ".zip", 4)) - return &roms[i]; - } + int i; + for (i = 0; roms[i].name; i++) { + if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIAGAME || roms[i].type == ROMTYPE_ARCADIAGAME)) { + TCHAR *p = roms[i].name; + p = p + _tcslen (p) + 1; + if (_tcslen (name) >= _tcslen (p) + 4) { + TCHAR *p2 = name + _tcslen (name) - _tcslen (p) - 4; + if (!memcmp (p, p2, _tcslen (p)) && !memcmp (p2 + _tcslen (p2) - 4, ".zip", 4)) + return &roms[i]; + } + } } - } - return NULL; + return NULL; } struct romlist **getarcadiaroms(void) { - int i, out, max; - void *buf; - struct romlist **rdout, *rltmp; - - max = 0; - for (i = 0; roms[i].name; i++) { - if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIABIOS || roms[i].type == ROMTYPE_ARCADIAGAME)) - max++; - } - buf = xmalloc ((sizeof (struct romlist*) + sizeof (struct romlist)) * (max + 1)); - rdout = (struct romlist**)buf; - rltmp = (struct romlist*)((uae_u8*)buf + (max + 1) * sizeof (struct romlist*)); - out = 0; - for (i = 0; roms[i].name; i++) { - if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIABIOS || roms[i].type == ROMTYPE_ARCADIAGAME)) { - rdout[out++] = rltmp; - rltmp->path = NULL; - rltmp->rd = &roms[i]; - rltmp++; + int i, out, max; + void *buf; + struct romlist **rdout, *rltmp; + + max = 0; + for (i = 0; roms[i].name; i++) { + if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIABIOS || roms[i].type == ROMTYPE_ARCADIAGAME)) + max++; + } + buf = xmalloc ((sizeof (struct romlist*) + sizeof (struct romlist)) * (max + 1)); + rdout = (struct romlist**)buf; + rltmp = (struct romlist*)((uae_u8*)buf + (max + 1) * sizeof (struct romlist*)); + out = 0; + for (i = 0; roms[i].name; i++) { + if (roms[i].group == 0 && (roms[i].type == ROMTYPE_ARCADIABIOS || roms[i].type == ROMTYPE_ARCADIAGAME)) { + rdout[out++] = rltmp; + rltmp->path = NULL; + rltmp->rd = &roms[i]; + rltmp++; + } } - } - rdout[out] = NULL; - return rdout; + rdout[out] = NULL; + return rdout; } static int kickstart_checksum_do (uae_u8 *mem, int size) { - uae_u32 cksum = 0, prevck = 0; - int i; - for (i = 0; i < size; i+=4) { - uae_u32 data = mem[i]*65536*256 + mem[i+1]*65536 + mem[i+2]*256 + mem[i+3]; - cksum += data; - if (cksum < prevck) - cksum++; - prevck = cksum; - } - return cksum == 0xffffffff; + uae_u32 cksum = 0, prevck = 0; + int i; + for (i = 0; i < size; i+=4) { + uae_u32 data = mem[i]*65536*256 + mem[i+1]*65536 + mem[i+2]*256 + mem[i+3]; + cksum += data; + if (cksum < prevck) + cksum++; + prevck = cksum; + } + return cksum == 0xffffffff; } #define ROM_KEY_NUM 3 struct rom_key { - uae_u8 *key; - int size; + uae_u8 *key; + int size; }; static struct rom_key keyring[ROM_KEY_NUM]; static void addkey (uae_u8 *key, int size, const TCHAR *name) { - int i; - - //write_log (L"addkey(%08x,%d,'%s')\n", key, size, name); - if (key == NULL || size == 0) { - xfree (key); - return; - } - for (i = 0; i < ROM_KEY_NUM; i++) { - if (keyring[i].key && keyring[i].size == size && !memcmp (keyring[i].key, key, size)) { - xfree (key); - //write_log (L"key already in keyring\n"); - return; + int i; + + //write_log (L"addkey(%08x,%d,'%s')\n", key, size, name); + if (key == NULL || size == 0) { + xfree (key); + return; + } + for (i = 0; i < ROM_KEY_NUM; i++) { + if (keyring[i].key && keyring[i].size == size && !memcmp (keyring[i].key, key, size)) { + xfree (key); + //write_log (L"key already in keyring\n"); + return; + } + } + for (i = 0; i < ROM_KEY_NUM; i++) { + if (keyring[i].key == NULL) + break; + } + if (i == ROM_KEY_NUM) { + xfree (key); + //write_log (L"keyring full\n"); + return; } - } - for (i = 0; i < ROM_KEY_NUM; i++) { - if (keyring[i].key == NULL) - break; - } - if (i == ROM_KEY_NUM) { - xfree (key); - //write_log (L"keyring full\n"); - return; - } - keyring[i].key = key; - keyring[i].size = size; - write_log (L"ROM KEY '%s' %d bytes loaded\n", name, size); + keyring[i].key = key; + keyring[i].size = size; + write_log (L"ROM KEY '%s' %d bytes loaded\n", name, size); } static void addkeyfile (const TCHAR *path) { - struct zfile *f; - int keysize; - uae_u8 *keybuf; + struct zfile *f; + int keysize; + uae_u8 *keybuf; - f = zfile_fopen (path, L"rb", ZFD_NORMAL); - if (!f) - return; - zfile_fseek (f, 0, SEEK_END); - keysize = zfile_ftell (f); - if (keysize > 0) { - zfile_fseek (f, 0, SEEK_SET); - keybuf = xmalloc (keysize); - zfile_fread (keybuf, 1, keysize, f); - addkey (keybuf, keysize, path); - } - zfile_fclose (f); + f = zfile_fopen (path, L"rb", ZFD_NORMAL); + if (!f) + return; + zfile_fseek (f, 0, SEEK_END); + keysize = zfile_ftell (f); + if (keysize > 0) { + zfile_fseek (f, 0, SEEK_SET); + keybuf = xmalloc (keysize); + zfile_fread (keybuf, 1, keysize, f); + addkey (keybuf, keysize, path); + } + zfile_fclose (f); } static void addkeydir (const TCHAR *path) { - TCHAR tmp[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, path); - if (zfile_exists (tmp)) { - int i; - for (i = _tcslen (tmp) - 1; i > 0; i--) { - if (tmp[i] == '\\' || tmp[i] == '/') - break; + _tcscpy (tmp, path); + if (zfile_exists (tmp)) { + int i; + for (i = _tcslen (tmp) - 1; i > 0; i--) { + if (tmp[i] == '\\' || tmp[i] == '/') + break; + } + tmp[i] = 0; } - tmp[i] = 0; - } - _tcscat (tmp, L"/"); - _tcscat (tmp, L"rom.key"); - addkeyfile (tmp); + _tcscat (tmp, L"/"); + _tcscat (tmp, L"rom.key"); + addkeyfile (tmp); } int get_keyring (void) { - int i, num = 0; - for (i = 0; i < ROM_KEY_NUM; i++) { - if (keyring[i].key) - num++; - } - return num; + int i, num = 0; + for (i = 0; i < ROM_KEY_NUM; i++) { + if (keyring[i].key) + num++; + } + return num; } int load_keyring (struct uae_prefs *p, TCHAR *path) { - uae_u8 *keybuf; - int keysize; - TCHAR tmp[MAX_PATH], *d; - int keyids[] = { 0, 48, -1 }; - int cnt, i; - - free_keyring (); - keybuf = target_load_keyfile (p, path, &keysize, tmp); - addkey (keybuf, keysize, tmp); - for (i = 0; keyids[i] >= 0; i++) { - struct romdata *rd = getromdatabyid (keyids[i]); - TCHAR *s; - if (rd) { - s = romlist_get (rd); - if (s) - addkeyfile (s); + uae_u8 *keybuf; + int keysize; + TCHAR tmp[MAX_PATH], *d; + int keyids[] = { 0, 48, -1 }; + int cnt, i; + + free_keyring (); + keybuf = target_load_keyfile (p, path, &keysize, tmp); + addkey (keybuf, keysize, tmp); + for (i = 0; keyids[i] >= 0; i++) { + struct romdata *rd = getromdatabyid (keyids[i]); + TCHAR *s; + if (rd) { + s = romlist_get (rd); + if (s) + addkeyfile (s); + } } - } - - cnt = 0; - for (;;) { - keybuf = NULL; - keysize = 0; - tmp[0] = 0; - switch (cnt) - { - case 0: - if (path) - _tcscpy (tmp, path); - break; - case 1: - _tcscat (tmp, L"rom.key"); - break; - case 2: - if (p) { - _tcscpy (tmp, p->path_rom); - _tcscat (tmp, L"rom.key"); - } - break; - case 3: - _tcscpy (tmp, L"roms/rom.key"); - break; - case 4: - _tcscpy (tmp, start_path_data); - _tcscat (tmp, L"rom.key"); - break; - case 5: - _stprintf (tmp, L"%s../shared/rom/rom.key", start_path_data); - break; - case 6: - if (p) { - for (i = 0; uae_archive_extensions[i]; i++) { - if (_tcsstr (p->romfile, uae_archive_extensions[i])) + + cnt = 0; + for (;;) { + keybuf = NULL; + keysize = 0; + tmp[0] = 0; + switch (cnt) + { + case 0: + if (path) + _tcscpy (tmp, path); break; + case 1: + _tcscat (tmp, L"rom.key"); + break; + case 2: + if (p) { + _tcscpy (tmp, p->path_rom); + _tcscat (tmp, L"rom.key"); + } + break; + case 3: + _tcscpy (tmp, L"roms/rom.key"); + break; + case 4: + _tcscpy (tmp, start_path_data); + _tcscat (tmp, L"rom.key"); + break; + case 5: + _stprintf (tmp, L"%s../shared/rom/rom.key", start_path_data); + break; + case 6: + if (p) { + for (i = 0; uae_archive_extensions[i]; i++) { + if (_tcsstr (p->romfile, uae_archive_extensions[i])) + break; + } + if (!uae_archive_extensions[i]) { + _tcscpy (tmp, p->romfile); + d = _tcsrchr (tmp, '/'); + if (!d) + d = _tcsrchr (tmp, '\\'); + if (d) + _tcscpy (d + 1, L"rom.key"); + } + } + break; + case 7: + return get_keyring (); } - if (!uae_archive_extensions[i]) { - _tcscpy (tmp, p->romfile); - d = _tcsrchr (tmp, '/'); - if (!d) - d = _tcsrchr (tmp, '\\'); - if (d) - _tcscpy (d + 1, L"rom.key"); - } - } - break; - case 7: - return get_keyring (); + cnt++; + if (!tmp[0]) + continue; + addkeyfile (tmp); } - cnt++; - if (!tmp[0]) - continue; - addkeyfile (tmp); - } } void free_keyring (void) { - int i; - for (i = 0; i < ROM_KEY_NUM; i++) - xfree (keyring[i].key); - memset(keyring, 0, sizeof (struct rom_key) * ROM_KEY_NUM); + int i; + for (i = 0; i < ROM_KEY_NUM; i++) + xfree (keyring[i].key); + memset(keyring, 0, sizeof (struct rom_key) * ROM_KEY_NUM); } struct romdata *getromdatabyname (TCHAR *name) { - TCHAR tmp[MAX_PATH]; - int i = 0; - while (roms[i].name) { - if (!roms[i].group) { - getromname (&roms[i], tmp); - if (!_tcscmp (tmp, name) || !_tcscmp (roms[i].name, name)) - return &roms[i]; + TCHAR tmp[MAX_PATH]; + int i = 0; + while (roms[i].name) { + if (!roms[i].group) { + getromname (&roms[i], tmp); + if (!_tcscmp (tmp, name) || !_tcscmp (roms[i].name, name)) + return &roms[i]; + } + i++; } - i++; - } - return 0; + return 0; } struct romdata *getromdatabyid (int id) { - int i = 0; - while (roms[i].name) { - if (id == roms[i].id && roms[i].group == 0) - return &roms[i]; - i++; - } - return 0; + int i = 0; + while (roms[i].name) { + if (id == roms[i].id && roms[i].group == 0) + return &roms[i]; + i++; + } + return 0; } struct romdata *getromdatabyidgroup (int id, int group, int subitem) { - int i = 0; - group = (group << 16) | subitem; - while (roms[i].name) { - if (id == roms[i].id && roms[i].group == group) - return &roms[i]; - i++; - } - return 0; + int i = 0; + group = (group << 16) | subitem; + while (roms[i].name) { + if (id == roms[i].id && roms[i].group == group) + return &roms[i]; + i++; + } + return 0; } STATIC_INLINE int notcrc32 (uae_u32 crc32) { - if (crc32 == 0xffffffff || crc32 == 0x00000000) - return 1; - return 0; + if (crc32 == 0xffffffff || crc32 == 0x00000000) + return 1; + return 0; } struct romdata *getromdatabycrc (uae_u32 crc32) { - int i = 0; - while (roms[i].name) { - if (roms[i].group == 0 && crc32 == roms[i].crc32 && !notcrc32(crc32)) - return &roms[i]; - i++; - } - return 0; + int i = 0; + while (roms[i].name) { + if (roms[i].group == 0 && crc32 == roms[i].crc32 && !notcrc32(crc32)) + return &roms[i]; + i++; + } + return 0; } static int cmpsha1 (uae_u8 *s1, struct romdata *rd) { - int i; + int i; - for (i = 0; i < SHA1_SIZE / 4; i++) { - uae_u32 v1 = (s1[0] << 24) | (s1[1] << 16) | (s1[2] << 8) | (s1[3] << 0); - uae_u32 v2 = rd->sha1[i]; - if (v1 != v2) - return -1; - s1 += 4; - } - return 0; + for (i = 0; i < SHA1_SIZE / 4; i++) { + uae_u32 v1 = (s1[0] << 24) | (s1[1] << 16) | (s1[2] << 8) | (s1[3] << 0); + uae_u32 v2 = rd->sha1[i]; + if (v1 != v2) + return -1; + s1 += 4; + } + return 0; } static struct romdata *checkromdata (uae_u8 *sha1, int size, uae_u32 mask) { - int i = 0; - while (roms[i].name) { - if (!notcrc32(roms[i].crc32) && roms[i].size >= size) { - if (roms[i].type & mask) { - if (!cmpsha1 (sha1, &roms[i])) - return &roms[i]; - } + int i = 0; + while (roms[i].name) { + if (!notcrc32(roms[i].crc32) && roms[i].size >= size) { + if (roms[i].type & mask) { + if (!cmpsha1 (sha1, &roms[i])) + return &roms[i]; + } + } + i++; } - i++; - } - return NULL; + return NULL; } int decode_cloanto_rom_do (uae_u8 *mem, int size, int real_size) { - int cnt, t, i; - - for (i = ROM_KEY_NUM - 1; i >= 0; i--) { - uae_u8 sha1[SHA1_SIZE]; - struct romdata *rd; - int keysize = keyring[i].size; - uae_u8 *key = keyring[i].key; - if (!key) - continue; - for (t = cnt = 0; cnt < size; cnt++, t = (t + 1) % keysize) { - mem[cnt] ^= key[t]; - if (real_size == cnt + 1) - t = keysize - 1; - } - if ((mem[2] == 0x4e && mem[3] == 0xf9) || (mem[0] == 0x11 && (mem[1] == 0x11 || mem[1] == 0x14))) { - cloanto_rom = 1; - return 1; - } - get_sha1 (mem, size, sha1); - rd = checkromdata (sha1, size, -1); - if (rd) { - if (rd->cloanto) - cloanto_rom = 1; - return 1; - } - if (i == 0) - break; - for (t = cnt = 0; cnt < size; cnt++, t = (t + 1) % keysize) { - mem[cnt] ^= key[t]; - if (real_size == cnt + 1) - t = keysize - 1; + int cnt, t, i; + + for (i = ROM_KEY_NUM - 1; i >= 0; i--) { + uae_u8 sha1[SHA1_SIZE]; + struct romdata *rd; + int keysize = keyring[i].size; + uae_u8 *key = keyring[i].key; + if (!key) + continue; + for (t = cnt = 0; cnt < size; cnt++, t = (t + 1) % keysize) { + mem[cnt] ^= key[t]; + if (real_size == cnt + 1) + t = keysize - 1; + } + if ((mem[2] == 0x4e && mem[3] == 0xf9) || (mem[0] == 0x11 && (mem[1] == 0x11 || mem[1] == 0x14))) { + cloanto_rom = 1; + return 1; + } + get_sha1 (mem, size, sha1); + rd = checkromdata (sha1, size, -1); + if (rd) { + if (rd->cloanto) + cloanto_rom = 1; + return 1; + } + if (i == 0) + break; + for (t = cnt = 0; cnt < size; cnt++, t = (t + 1) % keysize) { + mem[cnt] ^= key[t]; + if (real_size == cnt + 1) + t = keysize - 1; + } } - } - return 0; + return 0; } static int decode_rekick_rom_do (uae_u8 *mem, int size, int real_size) { - uae_u32 d1 = 0xdeadfeed, d0; - int i; - - for (i = 0; i < size / 8; i++) { - d0 = ((mem[i * 8 + 0] << 24) | (mem[i * 8 + 1] << 16) | (mem[i * 8 + 2] << 8) | mem[i * 8 + 3]); - d1 = d1 ^ d0; - mem[i * 8 + 0] = d1 >> 24; - mem[i * 8 + 1] = d1 >> 16; - mem[i * 8 + 2] = d1 >> 8; - mem[i * 8 + 3] = d1; - d1 = ((mem[i * 8 + 4] << 24) | (mem[i * 8 + 5] << 16) | (mem[i * 8 + 6] << 8) | mem[i * 8 + 7]); - d0 = d0 ^ d1; - mem[i * 8 + 4] = d0 >> 24; - mem[i * 8 + 5] = d0 >> 16; - mem[i * 8 + 6] = d0 >> 8; - mem[i * 8 + 7] = d0; - } - return 1; + uae_u32 d1 = 0xdeadfeed, d0; + int i; + + for (i = 0; i < size / 8; i++) { + d0 = ((mem[i * 8 + 0] << 24) | (mem[i * 8 + 1] << 16) | (mem[i * 8 + 2] << 8) | mem[i * 8 + 3]); + d1 = d1 ^ d0; + mem[i * 8 + 0] = d1 >> 24; + mem[i * 8 + 1] = d1 >> 16; + mem[i * 8 + 2] = d1 >> 8; + mem[i * 8 + 3] = d1; + d1 = ((mem[i * 8 + 4] << 24) | (mem[i * 8 + 5] << 16) | (mem[i * 8 + 6] << 8) | mem[i * 8 + 7]); + d0 = d0 ^ d1; + mem[i * 8 + 4] = d0 >> 24; + mem[i * 8 + 5] = d0 >> 16; + mem[i * 8 + 6] = d0 >> 8; + mem[i * 8 + 7] = d0; + } + return 1; } static int decode_rom (uae_u8 *mem, int size, int mode, int real_size) { - if (mode == 1) { - if (!decode_cloanto_rom_do (mem, size, real_size)) { - #ifndef SINGLEFILE - notify_user (NUMSG_NOROMKEY); - #endif - return 0; + if (mode == 1) { + if (!decode_cloanto_rom_do (mem, size, real_size)) { +#ifndef SINGLEFILE + notify_user (NUMSG_NOROMKEY); +#endif + return 0; + } + return 1; + } else if (mode == 2) { + decode_rekick_rom_do (mem, size, real_size); + return 1; } - return 1; - } else if (mode == 2) { - decode_rekick_rom_do (mem, size, real_size); - return 1; - } - return 0; + return 0; } struct romdata *getromdatabydata (uae_u8 *rom, int size) { - uae_u8 sha1[SHA1_SIZE]; - uae_u8 tmp[4]; - uae_u8 *tmpbuf = NULL; - struct romdata *ret = NULL; - - if (size > 11 && !memcmp (rom, "AMIROMTYPE1", 11)) { - uae_u8 *tmpbuf = xmalloc (size); - int tmpsize = size - 11; - memcpy (tmpbuf, rom + 11, tmpsize); - decode_rom (tmpbuf, tmpsize, 1, tmpsize); - rom = tmpbuf; - size = tmpsize; - } + uae_u8 sha1[SHA1_SIZE]; + uae_u8 tmp[4]; + uae_u8 *tmpbuf = NULL; + struct romdata *ret = NULL; + + if (size > 11 && !memcmp (rom, "AMIROMTYPE1", 11)) { + uae_u8 *tmpbuf = xmalloc (size); + int tmpsize = size - 11; + memcpy (tmpbuf, rom + 11, tmpsize); + decode_rom (tmpbuf, tmpsize, 1, tmpsize); + rom = tmpbuf; + size = tmpsize; + } #if 0 - if (size > 0x6c + 524288 && !memcmp (rom, "AMIG", 4)) { - uae_u8 *tmpbuf = (uae_u8*)xmalloc (size); - int tmpsize = size - 0x6c; - memcpy (tmpbuf, rom + 0x6c, tmpsize); - decode_rom (tmpbuf, tmpsize, 2, tmpsize); - rom = tmpbuf; - size = tmpsize; - } + if (size > 0x6c + 524288 && !memcmp (rom, "AMIG", 4)) { + uae_u8 *tmpbuf = (uae_u8*)xmalloc (size); + int tmpsize = size - 0x6c; + memcpy (tmpbuf, rom + 0x6c, tmpsize); + decode_rom (tmpbuf, tmpsize, 2, tmpsize); + rom = tmpbuf; + size = tmpsize; + } #endif - get_sha1 (rom, size, sha1); - ret = checkromdata(sha1, size, -1); - if (!ret) { - get_sha1 (rom, size / 2, sha1); - ret = checkromdata (sha1, size / 2, -1); + get_sha1 (rom, size, sha1); + ret = checkromdata(sha1, size, -1); if (!ret) { - /* ignore AR IO-port range until we have full dump */ - memcpy (tmp, rom, 4); - memset (rom, 0, 4); - get_sha1 (rom, size, sha1); - ret = checkromdata (sha1, size, ROMTYPE_AR); - memcpy (rom, tmp, 4); + get_sha1 (rom, size / 2, sha1); + ret = checkromdata (sha1, size / 2, -1); + if (!ret) { + /* ignore AR IO-port range until we have full dump */ + memcpy (tmp, rom, 4); + memset (rom, 0, 4); + get_sha1 (rom, size, sha1); + ret = checkromdata (sha1, size, ROMTYPE_AR); + memcpy (rom, tmp, 4); + } } - } - xfree (tmpbuf); - return ret; + xfree (tmpbuf); + return ret; } struct romdata *getromdatabyzfile (struct zfile *f) { - int pos, size; - uae_u8 *p; - struct romdata *rd; + int pos, size; + uae_u8 *p; + struct romdata *rd; - pos = zfile_ftell (f); - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f); - p = xmalloc (size); - if (!p) - return 0; - memset (p, 0, size); - zfile_fseek (f, 0, SEEK_SET); - zfile_fread (p, 1, size, f); - zfile_fseek (f, pos, SEEK_SET); - rd = getromdatabydata (p, size); - xfree (p); - return rd; + pos = zfile_ftell (f); + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f); + p = xmalloc (size); + if (!p) + return 0; + memset (p, 0, size); + zfile_fseek (f, 0, SEEK_SET); + zfile_fread (p, 1, size, f); + zfile_fseek (f, pos, SEEK_SET); + rd = getromdatabydata (p, size); + xfree (p); + return rd; } void getromname (struct romdata *rd, TCHAR *name) { - name[0] = 0; - if (!rd) - return; - while (rd->group) - rd--; - _tcscat (name, rd->name); - if ((rd->subrev || rd->subver) && rd->subver != rd->ver) - _stprintf (name + _tcslen (name), L" rev %d.%d", rd->subver, rd->subrev); - if (rd->size > 0) - _stprintf (name + _tcslen (name), L" (%dk)", (rd->size + 1023) / 1024); - if (rd->partnumber && _tcslen (rd->partnumber) > 0) - _stprintf (name + _tcslen (name), L" [%s]", rd->partnumber); + name[0] = 0; + if (!rd) + return; + while (rd->group) + rd--; + _tcscat (name, rd->name); + if ((rd->subrev || rd->subver) && rd->subver != rd->ver) + _stprintf (name + _tcslen (name), L" rev %d.%d", rd->subver, rd->subrev); + if (rd->size > 0) + _stprintf (name + _tcslen (name), L" (%dk)", (rd->size + 1023) / 1024); + if (rd->partnumber && _tcslen (rd->partnumber) > 0) + _stprintf (name + _tcslen (name), L" [%s]", rd->partnumber); } struct romlist *getromlistbyromdata (struct romdata *rd) { - int ids[2]; + int ids[2]; - ids[0] = rd->id; - ids[1] = 0; - return getromlistbyids(ids); + ids[0] = rd->id; + ids[1] = 0; + return getromlistbyids(ids); } struct romlist *getromlistbyids (int *ids) { - struct romdata *rd; - int i, j; - - i = 0; - while (ids[i] >= 0) { - rd = getromdatabyid (ids[i]); - if (rd) { - for (j = 0; j < romlist_cnt; j++) { - if (rl[j].rd->id == rd->id) - return &rl[j]; - } + struct romdata *rd; + int i, j; + + i = 0; + while (ids[i] >= 0) { + rd = getromdatabyid (ids[i]); + if (rd) { + for (j = 0; j < romlist_cnt; j++) { + if (rl[j].rd->id == rd->id) + return &rl[j]; + } + } + i++; } - i++; - } - return NULL; + return NULL; } void romwarning (int *ids) { - int i, exp; - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; - TCHAR tmp3[MAX_DPATH]; - - exp = 0; - tmp2[0] = 0; - i = 0; - while (ids[i] >= 0) { - struct romdata *rd = getromdatabyid (ids[i]); - getromname (rd, tmp1); - _tcscat (tmp2, L"- "); - _tcscat (tmp2, tmp1); - _tcscat (tmp2, L"\n"); - if (rd->type & (ROMTYPE_A2091BOOT | ROMTYPE_A4091BOOT)) - exp++; - i++; - } - translate_message (exp ? NUMSG_EXPROMNEED : NUMSG_ROMNEED, tmp3); - gui_message (tmp3, tmp2); + int i, exp; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; + TCHAR tmp3[MAX_DPATH]; + + exp = 0; + tmp2[0] = 0; + i = 0; + while (ids[i] >= 0) { + struct romdata *rd = getromdatabyid (ids[i]); + getromname (rd, tmp1); + _tcscat (tmp2, L"- "); + _tcscat (tmp2, tmp1); + _tcscat (tmp2, L"\n"); + if (rd->type & (ROMTYPE_A2091BOOT | ROMTYPE_A4091BOOT)) + exp++; + i++; + } + translate_message (exp ? NUMSG_EXPROMNEED : NUMSG_ROMNEED, tmp3); + gui_message (tmp3, tmp2); } addrbank *mem_banks[MEMORY_BANKS]; /* This has two functions. It either holds a host address that, when added - to the 68k address, gives the host address corresponding to that 68k - address (in which case the value in this array is even), OR it holds the - same value as mem_banks, for those banks that have baseaddr==0. In that - case, bit 0 is set (the memory access routines will take care of it). */ +to the 68k address, gives the host address corresponding to that 68k +address (in which case the value in this array is even), OR it holds the +same value as mem_banks, for those banks that have baseaddr==0. In that +case, bit 0 is set (the memory access routines will take care of it). */ uae_u8 *baseaddr[MEMORY_BANKS]; #ifdef NO_INLINE_MEMORY_ACCESS __inline__ uae_u32 longget (uaecptr addr) { - return call_mem_get_func (get_mem_bank (addr).lget, addr); + return call_mem_get_func (get_mem_bank (addr).lget, addr); } __inline__ uae_u32 wordget (uaecptr addr) { - return call_mem_get_func (get_mem_bank (addr).wget, addr); + return call_mem_get_func (get_mem_bank (addr).wget, addr); } __inline__ uae_u32 byteget (uaecptr addr) { - return call_mem_get_func (get_mem_bank (addr).bget, addr); + return call_mem_get_func (get_mem_bank (addr).bget, addr); } __inline__ void longput (uaecptr addr, uae_u32 l) { - call_mem_put_func (get_mem_bank (addr).lput, addr, l); + call_mem_put_func (get_mem_bank (addr).lput, addr, l); } __inline__ void wordput (uaecptr addr, uae_u32 w) { - call_mem_put_func (get_mem_bank (addr).wput, addr, w); + call_mem_put_func (get_mem_bank (addr).wput, addr, w); } __inline__ void byteput (uaecptr addr, uae_u32 b) { - call_mem_put_func (get_mem_bank (addr).bput, addr, b); + call_mem_put_func (get_mem_bank (addr).bput, addr, b); } #endif int addr_valid (TCHAR *txt, uaecptr addr, uae_u32 len) { - addrbank *ab = &get_mem_bank(addr); - if (ab == 0 || !(ab->flags & ABFLAG_RAM) || addr < 0x100 || len < 0 || len > 16777215 || !valid_address (addr, len)) { - write_log (L"corrupt %s pointer %x (%d) detected!\n", txt, addr, len); - return 0; - } - return 1; + addrbank *ab = &get_mem_bank(addr); + if (ab == 0 || !(ab->flags & ABFLAG_RAM) || addr < 0x100 || len < 0 || len > 16777215 || !valid_address (addr, len)) { + write_log (L"corrupt %s pointer %x (%d) detected!\n", txt, addr, len); + return 0; + } + return 1; } uae_u32 chipmem_mask, chipmem_full_mask, chipmem_full_size; @@ -1102,143 +1102,143 @@ static int REGPARAM3 dummy_check (uaecptr addr, uae_u32 size) REGPARAM; static void dummylog (int rw, uaecptr addr, int size, uae_u32 val, int ins) { - if (M68K_GETPC == 0xf81a16) - activate_debugger (); - if (illegal_count >= MAX_ILG) - return; - /* ignore Zorro3 expansion space */ - if (addr >= 0xff000000 && addr <= 0xff000200) - return; - /* autoconfig and extended rom */ - if (addr >= 0xe00000 && addr <= 0xf7ffff) - return; - /* motherboard ram */ - if (addr >= 0x08000000 && addr <= 0x08000007) - return; - if (addr >= 0x07f00000 && addr <= 0x07f00007) - return; - if (addr >= 0x07f7fff0 && addr <= 0x07ffffff) - return; - if (MAX_ILG >= 0) - illegal_count++; - if (ins) { - write_log (L"WARNING: Illegal opcode %cget at %08lx PC=%x\n", - size == 2 ? 'w' : 'l', addr, M68K_GETPC); - } else if (rw) { - write_log (L"Illegal %cput at %08lx=%08lx PC=%x\n", - size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, val, M68K_GETPC); - } else { - write_log (L"Illegal %cget at %08lx PC=%x\n", - size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, M68K_GETPC); - } + if (M68K_GETPC == 0xf81a16) + activate_debugger (); + if (illegal_count >= MAX_ILG) + return; + /* ignore Zorro3 expansion space */ + if (addr >= 0xff000000 && addr <= 0xff000200) + return; + /* autoconfig and extended rom */ + if (addr >= 0xe00000 && addr <= 0xf7ffff) + return; + /* motherboard ram */ + if (addr >= 0x08000000 && addr <= 0x08000007) + return; + if (addr >= 0x07f00000 && addr <= 0x07f00007) + return; + if (addr >= 0x07f7fff0 && addr <= 0x07ffffff) + return; + if (MAX_ILG >= 0) + illegal_count++; + if (ins) { + write_log (L"WARNING: Illegal opcode %cget at %08lx PC=%x\n", + size == 2 ? 'w' : 'l', addr, M68K_GETPC); + } else if (rw) { + write_log (L"Illegal %cput at %08lx=%08lx PC=%x\n", + size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, val, M68K_GETPC); + } else { + write_log (L"Illegal %cget at %08lx PC=%x\n", + size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, M68K_GETPC); + } } static uae_u32 dummy_get (uaecptr addr, int size) { - uae_u32 v; - if (currprefs.cpu_model >= 68020) - return NONEXISTINGDATA; - v = (regs.irc << 16) | regs.irc; - if (v == 4) - return v; - if (v == 2) - return v & 0xffff; - return (addr & 1) ? (v & 0xff) : ((v >> 8) & 0xff); + uae_u32 v; + if (currprefs.cpu_model >= 68020) + return NONEXISTINGDATA; + v = (regs.irc << 16) | regs.irc; + if (v == 4) + return v; + if (v == 2) + return v & 0xffff; + return (addr & 1) ? (v & 0xff) : ((v >> 8) & 0xff); } static uae_u32 REGPARAM2 dummy_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.illegal_mem) - dummylog (0, addr, 4, 0, 0); - return dummy_get (addr, 4); + if (currprefs.illegal_mem) + dummylog (0, addr, 4, 0, 0); + return dummy_get (addr, 4); } uae_u32 REGPARAM2 dummy_lgeti (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.illegal_mem) - dummylog (0, addr, 4, 0, 1); - return dummy_get (addr, 4); + if (currprefs.illegal_mem) + dummylog (0, addr, 4, 0, 1); + return dummy_get (addr, 4); } static uae_u32 REGPARAM2 dummy_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.illegal_mem) - dummylog (0, addr, 2, 0, 0); - return dummy_get (addr, 2); + if (currprefs.illegal_mem) + dummylog (0, addr, 2, 0, 0); + return dummy_get (addr, 2); } uae_u32 REGPARAM2 dummy_wgeti (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.illegal_mem) - dummylog (0, addr, 2, 0, 1); - return dummy_get (addr, 2); + if (currprefs.illegal_mem) + dummylog (0, addr, 2, 0, 1); + return dummy_get (addr, 2); } static uae_u32 REGPARAM2 dummy_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - if (currprefs.illegal_mem) - dummylog (0, addr, 1, 0, 0); - return dummy_get (addr, 1); + if (currprefs.illegal_mem) + dummylog (0, addr, 1, 0, 0); + return dummy_get (addr, 1); } static void REGPARAM2 dummy_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - dummylog (1, addr, 4, l, 0); + if (currprefs.illegal_mem) + dummylog (1, addr, 4, l, 0); } static void REGPARAM2 dummy_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - dummylog (1, addr, 2, w, 0); + if (currprefs.illegal_mem) + dummylog (1, addr, 2, w, 0); } static void REGPARAM2 dummy_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - dummylog (1, addr, 1, b, 0); + if (currprefs.illegal_mem) + dummylog (1, addr, 1, b, 0); } static int REGPARAM2 dummy_check (uaecptr addr, uae_u32 size) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return 0; + return 0; } static void REGPARAM2 none_put (uaecptr addr, uae_u32 v) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } static uae_u32 REGPARAM2 ones_get (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return 0xffffffff; + return 0xffffffff; } /* Chip memory */ @@ -1254,251 +1254,251 @@ static uae_u8 *REGPARAM3 chipmem_xlate (uaecptr addr) REGPARAM; static void ce2_timeout (void) { - wait_cpu_cycle_read (0, -1); + wait_cpu_cycle_read (0, -1); } static uae_u32 REGPARAM2 chipmem_lget_ce2 (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - ce2_timeout (); - return do_get_mem_long (m); + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + ce2_timeout (); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 chipmem_wget_ce2 (uaecptr addr) { - uae_u16 *m, v; + uae_u16 *m, v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); - ce2_timeout (); - v = do_get_mem_word (m); - //last_custom_value = v; - return v; + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); + ce2_timeout (); + v = do_get_mem_word (m); + //last_custom_value = v; + return v; } static uae_u32 REGPARAM2 chipmem_bget_ce2 (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= chipmem_mask; - ce2_timeout (); - return chipmemory[addr]; + addr &= chipmem_mask; + ce2_timeout (); + return chipmemory[addr]; } static void REGPARAM2 chipmem_lput_ce2 (uaecptr addr, uae_u32 l) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - ce2_timeout (); - do_put_mem_long (m, l); + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + ce2_timeout (); + do_put_mem_long (m, l); } static void REGPARAM2 chipmem_wput_ce2 (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); - ce2_timeout (); - //last_custom_value = w; - do_put_mem_word (m, w); + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); + ce2_timeout (); + //last_custom_value = w; + do_put_mem_word (m, w); } static void REGPARAM2 chipmem_bput_ce2 (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= chipmem_mask; - ce2_timeout (); - chipmemory[addr] = b; + addr &= chipmem_mask; + ce2_timeout (); + chipmemory[addr] = b; } #endif uae_u32 REGPARAM2 chipmem_lget (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - return do_get_mem_long (m); + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 chipmem_wget (uaecptr addr) { - uae_u16 *m, v; + uae_u16 *m, v; - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); - v = do_get_mem_word (m); - //last_custom_value = v; - return v; + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); + v = do_get_mem_word (m); + //last_custom_value = v; + return v; } static uae_u32 REGPARAM2 chipmem_bget (uaecptr addr) { - uae_u8 v; - addr &= chipmem_mask; - v = chipmemory[addr]; - //last_custom_value = (v << 8) | v; - return v; + uae_u8 v; + addr &= chipmem_mask; + v = chipmemory[addr]; + //last_custom_value = (v << 8) | v; + return v; } void REGPARAM2 chipmem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; + uae_u32 *m; - addr &= chipmem_mask; - m = (uae_u32 *)(chipmemory + addr); - do_put_mem_long (m, l); + addr &= chipmem_mask; + m = (uae_u32 *)(chipmemory + addr); + do_put_mem_long (m, l); } void REGPARAM2 chipmem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; - addr &= chipmem_mask; - m = (uae_u16 *)(chipmemory + addr); - //last_custom_value = w; - do_put_mem_word (m, w); + addr &= chipmem_mask; + m = (uae_u16 *)(chipmemory + addr); + //last_custom_value = w; + do_put_mem_word (m, w); } void REGPARAM2 chipmem_bput (uaecptr addr, uae_u32 b) { - addr &= chipmem_mask; - //last_custom_value = (b << 8) | b; - chipmemory[addr] = b; + addr &= chipmem_mask; + //last_custom_value = (b << 8) | b; + chipmemory[addr] = b; } /* cpu chipmem access inside agnus addressable ram but no ram available */ static uae_u32 chipmem_dummy (void) { - /* not really right but something random that has more ones than zeros.. */ - return 0xffff & ~((1 << (rand () & 31)) | (1 << (rand () & 31))); + /* not really right but something random that has more ones than zeros.. */ + return 0xffff & ~((1 << (rand () & 31)) | (1 << (rand () & 31))); } void REGPARAM2 chipmem_dummy_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } void REGPARAM2 chipmem_dummy_wput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } void REGPARAM2 chipmem_dummy_lput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif } static uae_u32 REGPARAM2 chipmem_dummy_bget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return chipmem_dummy (); + return chipmem_dummy (); } static uae_u32 REGPARAM2 chipmem_dummy_wget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return chipmem_dummy (); + return chipmem_dummy (); } static uae_u32 REGPARAM2 chipmem_dummy_lget (uaecptr addr) { #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - return (chipmem_dummy () << 16) | chipmem_dummy (); + return (chipmem_dummy () << 16) | chipmem_dummy (); } static uae_u32 REGPARAM2 chipmem_agnus_lget (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; - addr &= chipmem_full_mask; - m = (uae_u32 *)(chipmemory + addr); - return do_get_mem_long (m); + addr &= chipmem_full_mask; + m = (uae_u32 *)(chipmemory + addr); + return do_get_mem_long (m); } uae_u32 REGPARAM2 chipmem_agnus_wget (uaecptr addr) { - uae_u16 *m; + uae_u16 *m; - addr &= chipmem_full_mask; - m = (uae_u16 *)(chipmemory + addr); - return do_get_mem_word (m); + addr &= chipmem_full_mask; + m = (uae_u16 *)(chipmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 chipmem_agnus_bget (uaecptr addr) { - addr &= chipmem_full_mask; - return chipmemory[addr]; + addr &= chipmem_full_mask; + return chipmemory[addr]; } static void REGPARAM2 chipmem_agnus_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; + uae_u32 *m; - addr &= chipmem_full_mask; - if (addr >= chipmem_full_size) - return; - m = (uae_u32 *)(chipmemory + addr); - do_put_mem_long (m, l); + addr &= chipmem_full_mask; + if (addr >= chipmem_full_size) + return; + m = (uae_u32 *)(chipmemory + addr); + do_put_mem_long (m, l); } void REGPARAM2 chipmem_agnus_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; - addr &= chipmem_full_mask; - if (addr >= chipmem_full_size) - return; - m = (uae_u16 *)(chipmemory + addr); - do_put_mem_word (m, w); + addr &= chipmem_full_mask; + if (addr >= chipmem_full_size) + return; + m = (uae_u16 *)(chipmemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 chipmem_agnus_bput (uaecptr addr, uae_u32 b) { - addr &= chipmem_full_mask; - if (addr >= chipmem_full_size) - return; - chipmemory[addr] = b; + addr &= chipmem_full_mask; + if (addr >= chipmem_full_size) + return; + chipmemory[addr] = b; } static int REGPARAM2 chipmem_check (uaecptr addr, uae_u32 size) { - addr &= chipmem_mask; - return (addr + size) <= chipmem_full_size; + addr &= chipmem_mask; + return (addr + size) <= chipmem_full_size; } static uae_u8 *REGPARAM2 chipmem_xlate (uaecptr addr) { - addr &= chipmem_mask; - return chipmemory + addr; + addr &= chipmem_mask; + return chipmemory + addr; } /* Slow memory */ @@ -1517,58 +1517,58 @@ static uae_u8 *REGPARAM3 bogomem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 bogomem_lget (uaecptr addr) { - uae_u32 *m; - addr &= bogomem_mask; - m = (uae_u32 *)(bogomemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr &= bogomem_mask; + m = (uae_u32 *)(bogomemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 bogomem_wget (uaecptr addr) { - uae_u16 *m; - addr &= bogomem_mask; - m = (uae_u16 *)(bogomemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr &= bogomem_mask; + m = (uae_u16 *)(bogomemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 bogomem_bget (uaecptr addr) { - addr &= bogomem_mask; - return bogomemory[addr]; + addr &= bogomem_mask; + return bogomemory[addr]; } static void REGPARAM2 bogomem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr &= bogomem_mask; - m = (uae_u32 *)(bogomemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr &= bogomem_mask; + m = (uae_u32 *)(bogomemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 bogomem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr &= bogomem_mask; - m = (uae_u16 *)(bogomemory + addr); - do_put_mem_word (m, w); + uae_u16 *m; + addr &= bogomem_mask; + m = (uae_u16 *)(bogomemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 bogomem_bput (uaecptr addr, uae_u32 b) { - addr &= bogomem_mask; - bogomemory[addr] = b; + addr &= bogomem_mask; + bogomemory[addr] = b; } static int REGPARAM2 bogomem_check (uaecptr addr, uae_u32 size) { - addr &= bogomem_mask; - return (addr + size) <= allocated_bogomem; + addr &= bogomem_mask; + return (addr + size) <= allocated_bogomem; } static uae_u8 *REGPARAM2 bogomem_xlate (uaecptr addr) { - addr &= bogomem_mask; - return bogomemory + addr; + addr &= bogomem_mask; + return bogomemory + addr; } /* CDTV expension memory card memory */ @@ -1586,58 +1586,58 @@ static uae_u8 *REGPARAM3 cardmem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 cardmem_lget (uaecptr addr) { - uae_u32 *m; - addr &= cardmem_mask; - m = (uae_u32 *)(cardmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr &= cardmem_mask; + m = (uae_u32 *)(cardmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 cardmem_wget (uaecptr addr) { - uae_u16 *m; - addr &= cardmem_mask; - m = (uae_u16 *)(cardmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr &= cardmem_mask; + m = (uae_u16 *)(cardmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 cardmem_bget (uaecptr addr) { - addr &= cardmem_mask; - return cardmemory[addr]; + addr &= cardmem_mask; + return cardmemory[addr]; } static void REGPARAM2 cardmem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr &= cardmem_mask; - m = (uae_u32 *)(cardmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr &= cardmem_mask; + m = (uae_u32 *)(cardmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 cardmem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr &= cardmem_mask; - m = (uae_u16 *)(cardmemory + addr); - do_put_mem_word (m, w); + uae_u16 *m; + addr &= cardmem_mask; + m = (uae_u16 *)(cardmemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 cardmem_bput (uaecptr addr, uae_u32 b) { - addr &= cardmem_mask; - cardmemory[addr] = b; + addr &= cardmem_mask; + cardmemory[addr] = b; } static int REGPARAM2 cardmem_check (uaecptr addr, uae_u32 size) { - addr &= cardmem_mask; - return (addr + size) <= allocated_cardmem; + addr &= cardmem_mask; + return (addr + size) <= allocated_cardmem; } static uae_u8 *REGPARAM2 cardmem_xlate (uaecptr addr) { - addr &= cardmem_mask; - return cardmemory + addr; + addr &= cardmem_mask; + return cardmemory + addr; } /* A3000 motherboard fast memory */ @@ -1655,58 +1655,58 @@ static uae_u8 *REGPARAM3 a3000lmem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 a3000lmem_lget (uaecptr addr) { - uae_u32 *m; - addr &= a3000lmem_mask; - m = (uae_u32 *)(a3000lmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr &= a3000lmem_mask; + m = (uae_u32 *)(a3000lmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 a3000lmem_wget (uaecptr addr) { - uae_u16 *m; - addr &= a3000lmem_mask; - m = (uae_u16 *)(a3000lmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr &= a3000lmem_mask; + m = (uae_u16 *)(a3000lmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 a3000lmem_bget (uaecptr addr) { - addr &= a3000lmem_mask; - return a3000lmemory[addr]; + addr &= a3000lmem_mask; + return a3000lmemory[addr]; } static void REGPARAM2 a3000lmem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr &= a3000lmem_mask; - m = (uae_u32 *)(a3000lmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr &= a3000lmem_mask; + m = (uae_u32 *)(a3000lmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 a3000lmem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr &= a3000lmem_mask; - m = (uae_u16 *)(a3000lmemory + addr); - do_put_mem_word (m, w); + uae_u16 *m; + addr &= a3000lmem_mask; + m = (uae_u16 *)(a3000lmemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 a3000lmem_bput (uaecptr addr, uae_u32 b) { - addr &= a3000lmem_mask; - a3000lmemory[addr] = b; + addr &= a3000lmem_mask; + a3000lmemory[addr] = b; } static int REGPARAM2 a3000lmem_check (uaecptr addr, uae_u32 size) { - addr &= a3000lmem_mask; - return (addr + size) <= allocated_a3000lmem; + addr &= a3000lmem_mask; + return (addr + size) <= allocated_a3000lmem; } static uae_u8 *REGPARAM2 a3000lmem_xlate (uaecptr addr) { - addr &= a3000lmem_mask; - return a3000lmemory + addr; + addr &= a3000lmem_mask; + return a3000lmemory + addr; } static uae_u32 REGPARAM3 a3000hmem_lget (uaecptr) REGPARAM; @@ -1720,58 +1720,58 @@ static uae_u8 *REGPARAM3 a3000hmem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 a3000hmem_lget (uaecptr addr) { - uae_u32 *m; - addr &= a3000hmem_mask; - m = (uae_u32 *)(a3000hmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr &= a3000hmem_mask; + m = (uae_u32 *)(a3000hmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 a3000hmem_wget (uaecptr addr) { - uae_u16 *m; - addr &= a3000hmem_mask; - m = (uae_u16 *)(a3000hmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr &= a3000hmem_mask; + m = (uae_u16 *)(a3000hmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 a3000hmem_bget (uaecptr addr) { - addr &= a3000hmem_mask; - return a3000hmemory[addr]; + addr &= a3000hmem_mask; + return a3000hmemory[addr]; } static void REGPARAM2 a3000hmem_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr &= a3000hmem_mask; - m = (uae_u32 *)(a3000hmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr &= a3000hmem_mask; + m = (uae_u32 *)(a3000hmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 a3000hmem_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr &= a3000hmem_mask; - m = (uae_u16 *)(a3000hmemory + addr); - do_put_mem_word (m, w); + uae_u16 *m; + addr &= a3000hmem_mask; + m = (uae_u16 *)(a3000hmemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 a3000hmem_bput (uaecptr addr, uae_u32 b) { - addr &= a3000hmem_mask; - a3000hmemory[addr] = b; + addr &= a3000hmem_mask; + a3000hmemory[addr] = b; } static int REGPARAM2 a3000hmem_check (uaecptr addr, uae_u32 size) { - addr &= a3000hmem_mask; - return (addr + size) <= allocated_a3000hmem; + addr &= a3000hmem_mask; + return (addr + size) <= allocated_a3000hmem; } static uae_u8 *REGPARAM2 a3000hmem_xlate (uaecptr addr) { - addr &= a3000hmem_mask; - return a3000hmemory + addr; + addr &= a3000hmem_mask; + return a3000hmemory + addr; } /* Kick memory */ @@ -1781,34 +1781,34 @@ uae_u16 kickstart_version; static int kickmem_size; /* - * A1000 kickstart RAM handling - * - * RESET instruction unhides boot ROM and disables write protection - * write access to boot ROM hides boot ROM and enables write protection - * - */ +* A1000 kickstart RAM handling +* +* RESET instruction unhides boot ROM and disables write protection +* write access to boot ROM hides boot ROM and enables write protection +* +*/ static int a1000_kickstart_mode; static uae_u8 *a1000_bootrom; static void a1000_handle_kickstart (int mode) { - if (!a1000_bootrom) - return; - if (mode == 0) { - a1000_kickstart_mode = 0; - memcpy (kickmemory, kickmemory + 262144, 262144); - kickstart_version = (kickmemory[262144 + 12] << 8) | kickmemory[262144 + 13]; - } else { - a1000_kickstart_mode = 1; - memcpy (kickmemory, a1000_bootrom, 262144); - kickstart_version = 0; - } - if (kickstart_version == 0xffff) - kickstart_version = 0; + if (!a1000_bootrom) + return; + if (mode == 0) { + a1000_kickstart_mode = 0; + memcpy (kickmemory, kickmemory + 262144, 262144); + kickstart_version = (kickmemory[262144 + 12] << 8) | kickmemory[262144 + 13]; + } else { + a1000_kickstart_mode = 1; + memcpy (kickmemory, a1000_bootrom, 262144); + kickstart_version = 0; + } + if (kickstart_version == 0xffff) + kickstart_version = 0; } void a1000_reset (void) { - a1000_handle_kickstart (1); + a1000_handle_kickstart (1); } static uae_u32 REGPARAM3 kickmem_lget (uaecptr) REGPARAM; @@ -1822,119 +1822,119 @@ static uae_u8 *REGPARAM3 kickmem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 kickmem_lget (uaecptr addr) { - uae_u32 *m; - addr &= kickmem_mask; - m = (uae_u32 *)(kickmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr &= kickmem_mask; + m = (uae_u32 *)(kickmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 kickmem_wget (uaecptr addr) { - uae_u16 *m; - addr &= kickmem_mask; - m = (uae_u16 *)(kickmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr &= kickmem_mask; + m = (uae_u16 *)(kickmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 kickmem_bget (uaecptr addr) { - addr &= kickmem_mask; - return kickmemory[addr]; + addr &= kickmem_mask; + return kickmemory[addr]; } static void REGPARAM2 kickmem_lput (uaecptr addr, uae_u32 b) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (a1000_kickstart_mode) { - if (addr >= 0xfc0000) { - addr &= kickmem_mask; - m = (uae_u32 *)(kickmemory + addr); - do_put_mem_long (m, b); - return; - } else - a1000_handle_kickstart (0); - } else if (currprefs.illegal_mem) - write_log (L"Illegal kickmem lput at %08lx\n", addr); + if (a1000_kickstart_mode) { + if (addr >= 0xfc0000) { + addr &= kickmem_mask; + m = (uae_u32 *)(kickmemory + addr); + do_put_mem_long (m, b); + return; + } else + a1000_handle_kickstart (0); + } else if (currprefs.illegal_mem) + write_log (L"Illegal kickmem lput at %08lx\n", addr); } static void REGPARAM2 kickmem_wput (uaecptr addr, uae_u32 b) { - uae_u16 *m; + uae_u16 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (a1000_kickstart_mode) { - if (addr >= 0xfc0000) { - addr &= kickmem_mask; - m = (uae_u16 *)(kickmemory + addr); - do_put_mem_word (m, b); - return; - } else - a1000_handle_kickstart (0); - } else if (currprefs.illegal_mem) - write_log (L"Illegal kickmem wput at %08lx\n", addr); + if (a1000_kickstart_mode) { + if (addr >= 0xfc0000) { + addr &= kickmem_mask; + m = (uae_u16 *)(kickmemory + addr); + do_put_mem_word (m, b); + return; + } else + a1000_handle_kickstart (0); + } else if (currprefs.illegal_mem) + write_log (L"Illegal kickmem wput at %08lx\n", addr); } static void REGPARAM2 kickmem_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (a1000_kickstart_mode) { - if (addr >= 0xfc0000) { - addr &= kickmem_mask; - kickmemory[addr] = b; - return; - } else - a1000_handle_kickstart (0); - } else if (currprefs.illegal_mem) - write_log (L"Illegal kickmem lput at %08lx\n", addr); + if (a1000_kickstart_mode) { + if (addr >= 0xfc0000) { + addr &= kickmem_mask; + kickmemory[addr] = b; + return; + } else + a1000_handle_kickstart (0); + } else if (currprefs.illegal_mem) + write_log (L"Illegal kickmem lput at %08lx\n", addr); } static void REGPARAM2 kickmem2_lput (uaecptr addr, uae_u32 l) { - uae_u32 *m; + uae_u32 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= kickmem_mask; - m = (uae_u32 *)(kickmemory + addr); - do_put_mem_long (m, l); + addr &= kickmem_mask; + m = (uae_u32 *)(kickmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 kickmem2_wput (uaecptr addr, uae_u32 w) { - uae_u16 *m; + uae_u16 *m; #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= kickmem_mask; - m = (uae_u16 *)(kickmemory + addr); - do_put_mem_word (m, w); + addr &= kickmem_mask; + m = (uae_u16 *)(kickmemory + addr); + do_put_mem_word (m, w); } static void REGPARAM2 kickmem2_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= kickmem_mask; - kickmemory[addr] = b; + addr &= kickmem_mask; + kickmemory[addr] = b; } static int REGPARAM2 kickmem_check (uaecptr addr, uae_u32 size) { - addr &= kickmem_mask; - return (addr + size) <= kickmem_size; + addr &= kickmem_mask; + return (addr + size) <= kickmem_size; } static uae_u8 *REGPARAM2 kickmem_xlate (uaecptr addr) { - addr &= kickmem_mask; - return kickmemory + addr; + addr &= kickmem_mask; + return kickmemory + addr; } /* CD32/CDTV extended kick memory */ @@ -1959,61 +1959,61 @@ static int REGPARAM3 extendedkickmem_check (uaecptr addr, uae_u32 size) REGPARAM static uae_u8 *REGPARAM3 extendedkickmem_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 extendedkickmem_lget (uaecptr addr) { - uae_u32 *m; - addr -= extendedkickmem_start & extendedkickmem_mask; - addr &= extendedkickmem_mask; - m = (uae_u32 *)(extendedkickmemory + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr -= extendedkickmem_start & extendedkickmem_mask; + addr &= extendedkickmem_mask; + m = (uae_u32 *)(extendedkickmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 extendedkickmem_wget (uaecptr addr) { - uae_u16 *m; - addr -= extendedkickmem_start & extendedkickmem_mask; - addr &= extendedkickmem_mask; - m = (uae_u16 *)(extendedkickmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr -= extendedkickmem_start & extendedkickmem_mask; + addr &= extendedkickmem_mask; + m = (uae_u16 *)(extendedkickmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 extendedkickmem_bget (uaecptr addr) { - addr -= extendedkickmem_start & extendedkickmem_mask; - addr &= extendedkickmem_mask; - return extendedkickmemory[addr]; + addr -= extendedkickmem_start & extendedkickmem_mask; + addr &= extendedkickmem_mask; + return extendedkickmemory[addr]; } static void REGPARAM2 extendedkickmem_lput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem lput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem lput at %08lx\n", addr); } static void REGPARAM2 extendedkickmem_wput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem wput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem wput at %08lx\n", addr); } static void REGPARAM2 extendedkickmem_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem lput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem lput at %08lx\n", addr); } static int REGPARAM2 extendedkickmem_check (uaecptr addr, uae_u32 size) { - addr -= extendedkickmem_start & extendedkickmem_mask; - addr &= extendedkickmem_mask; - return (addr + size) <= extendedkickmem_size; + addr -= extendedkickmem_start & extendedkickmem_mask; + addr &= extendedkickmem_mask; + return (addr + size) <= extendedkickmem_size; } static uae_u8 *REGPARAM2 extendedkickmem_xlate (uaecptr addr) { - addr -= extendedkickmem_start & extendedkickmem_mask; - addr &= extendedkickmem_mask; - return extendedkickmemory + addr; + addr -= extendedkickmem_start & extendedkickmem_mask; + addr &= extendedkickmem_mask; + return extendedkickmemory + addr; } static uae_u32 REGPARAM3 extendedkickmem2_lget (uaecptr) REGPARAM; @@ -2026,61 +2026,61 @@ static int REGPARAM3 extendedkickmem2_check (uaecptr addr, uae_u32 size) REGPARA static uae_u8 *REGPARAM3 extendedkickmem2_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 extendedkickmem2_lget (uaecptr addr) { - uae_u32 *m; - addr -= extendedkickmem2_start & extendedkickmem2_mask; - addr &= extendedkickmem2_mask; - m = (uae_u32 *)(extendedkickmemory2 + addr); - return do_get_mem_long (m); + uae_u32 *m; + addr -= extendedkickmem2_start & extendedkickmem2_mask; + addr &= extendedkickmem2_mask; + m = (uae_u32 *)(extendedkickmemory2 + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 extendedkickmem2_wget (uaecptr addr) { - uae_u16 *m; - addr -= extendedkickmem2_start & extendedkickmem2_mask; - addr &= extendedkickmem2_mask; - m = (uae_u16 *)(extendedkickmemory2 + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr -= extendedkickmem2_start & extendedkickmem2_mask; + addr &= extendedkickmem2_mask; + m = (uae_u16 *)(extendedkickmemory2 + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 extendedkickmem2_bget (uaecptr addr) { - addr -= extendedkickmem2_start & extendedkickmem2_mask; - addr &= extendedkickmem2_mask; - return extendedkickmemory2[addr]; + addr -= extendedkickmem2_start & extendedkickmem2_mask; + addr &= extendedkickmem2_mask; + return extendedkickmemory2[addr]; } static void REGPARAM2 extendedkickmem2_lput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem2 lput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem2 lput at %08lx\n", addr); } static void REGPARAM2 extendedkickmem2_wput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem2 wput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem2 wput at %08lx\n", addr); } static void REGPARAM2 extendedkickmem2_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - if (currprefs.illegal_mem) - write_log (L"Illegal extendedkickmem2 lput at %08lx\n", addr); + if (currprefs.illegal_mem) + write_log (L"Illegal extendedkickmem2 lput at %08lx\n", addr); } static int REGPARAM2 extendedkickmem2_check (uaecptr addr, uae_u32 size) { - addr -= extendedkickmem2_start & extendedkickmem2_mask; - addr &= extendedkickmem2_mask; - return (addr + size) <= extendedkickmem2_size; + addr -= extendedkickmem2_start & extendedkickmem2_mask; + addr &= extendedkickmem2_mask; + return (addr + size) <= extendedkickmem2_size; } static uae_u8 *REGPARAM2 extendedkickmem2_xlate (uaecptr addr) { - addr -= extendedkickmem2_start & extendedkickmem2_mask; - addr &= extendedkickmem2_mask; - return extendedkickmemory2 + addr; + addr -= extendedkickmem2_start & extendedkickmem2_mask; + addr &= extendedkickmem2_mask; + return extendedkickmemory2 + addr; } @@ -2088,144 +2088,144 @@ static uae_u8 *REGPARAM2 extendedkickmem2_xlate (uaecptr addr) int REGPARAM2 default_check (uaecptr a, uae_u32 b) { - return 0; + return 0; } static int be_cnt; uae_u8 *REGPARAM2 default_xlate (uaecptr a) { - if (quit_program == 0) { - /* do this only in 68010+ mode, there are some tricky A500 programs.. */ - if ((currprefs.cpu_model > 68000 || !currprefs.cpu_compatible) && !currprefs.mmu_model) { + if (quit_program == 0) { + /* do this only in 68010+ mode, there are some tricky A500 programs.. */ + if ((currprefs.cpu_model > 68000 || !currprefs.cpu_compatible) && !currprefs.mmu_model) { #if defined(ENFORCER) - enforcer_disable (); + enforcer_disable (); #endif - if (be_cnt < 3) { - int i, j; - uaecptr a2 = a - 32; - uaecptr a3 = m68k_getpc () - 32; - write_log (L"Your Amiga program just did something terribly stupid %08X PC=%08X\n", a, M68K_GETPC); - m68k_dumpstate (0, 0); - for (i = 0; i < 10; i++) { - write_log (L"%08X ", i >= 5 ? a3 : a2); - for (j = 0; j < 16; j += 2) { - write_log (L" %04X", get_word (i >= 5 ? a3 : a2)); - if (i >= 5) a3 += 2; else a2 += 2; - } - write_log (L"\n"); + if (be_cnt < 3) { + int i, j; + uaecptr a2 = a - 32; + uaecptr a3 = m68k_getpc () - 32; + write_log (L"Your Amiga program just did something terribly stupid %08X PC=%08X\n", a, M68K_GETPC); + m68k_dumpstate (0, 0); + for (i = 0; i < 10; i++) { + write_log (L"%08X ", i >= 5 ? a3 : a2); + for (j = 0; j < 16; j += 2) { + write_log (L" %04X", get_word (i >= 5 ? a3 : a2)); + if (i >= 5) a3 += 2; else a2 += 2; + } + write_log (L"\n"); + } + memory_map_dump (); + } + be_cnt++; + if (be_cnt > 1000) { + uae_reset (0); + be_cnt = 0; + } else { + regs.panic = 1; + regs.panic_pc = m68k_getpc (); + regs.panic_addr = a; + set_special (SPCFLAG_BRK); + } } - memory_map_dump (); - } - be_cnt++; - if (be_cnt > 1000) { - uae_reset (0); - be_cnt = 0; - } else { - regs.panic = 1; - regs.panic_pc = m68k_getpc (); - regs.panic_addr = a; - set_special (SPCFLAG_BRK); - } } - } - return kickmem_xlate (2); /* So we don't crash. */ + return kickmem_xlate (2); /* So we don't crash. */ } /* Address banks */ addrbank dummy_bank = { - dummy_lget, dummy_wget, dummy_bget, - dummy_lput, dummy_wput, dummy_bput, - default_xlate, dummy_check, NULL, NULL, - dummy_lgeti, dummy_wgeti, ABFLAG_NONE + dummy_lget, dummy_wget, dummy_bget, + dummy_lput, dummy_wput, dummy_bput, + default_xlate, dummy_check, NULL, NULL, + dummy_lgeti, dummy_wgeti, ABFLAG_NONE }; addrbank ones_bank = { - ones_get, ones_get, ones_get, - none_put, none_put, none_put, - default_xlate, dummy_check, NULL, L"Ones", - dummy_lgeti, dummy_wgeti, ABFLAG_NONE + ones_get, ones_get, ones_get, + none_put, none_put, none_put, + default_xlate, dummy_check, NULL, L"Ones", + dummy_lgeti, dummy_wgeti, ABFLAG_NONE }; addrbank chipmem_bank = { - chipmem_lget, chipmem_wget, chipmem_bget, - chipmem_lput, chipmem_wput, chipmem_bput, - chipmem_xlate, chipmem_check, NULL, L"Chip memory", - chipmem_lget, chipmem_wget, ABFLAG_RAM + chipmem_lget, chipmem_wget, chipmem_bget, + chipmem_lput, chipmem_wput, chipmem_bput, + chipmem_xlate, chipmem_check, NULL, L"Chip memory", + chipmem_lget, chipmem_wget, ABFLAG_RAM }; addrbank chipmem_dummy_bank = { - chipmem_dummy_lget, chipmem_dummy_wget, chipmem_dummy_bget, - chipmem_dummy_lput, chipmem_dummy_wput, chipmem_dummy_bput, - default_xlate, dummy_check, NULL, L"Dummy Chip memory", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + chipmem_dummy_lget, chipmem_dummy_wget, chipmem_dummy_bget, + chipmem_dummy_lput, chipmem_dummy_wput, chipmem_dummy_bput, + default_xlate, dummy_check, NULL, L"Dummy Chip memory", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; #ifdef AGA addrbank chipmem_bank_ce2 = { - chipmem_lget_ce2, chipmem_wget_ce2, chipmem_bget_ce2, - chipmem_lput_ce2, chipmem_wput_ce2, chipmem_bput_ce2, - chipmem_xlate, chipmem_check, NULL, L"Chip memory (68020 'ce')", - chipmem_lget_ce2, chipmem_wget_ce2, ABFLAG_RAM + chipmem_lget_ce2, chipmem_wget_ce2, chipmem_bget_ce2, + chipmem_lput_ce2, chipmem_wput_ce2, chipmem_bput_ce2, + chipmem_xlate, chipmem_check, NULL, L"Chip memory (68020 'ce')", + chipmem_lget_ce2, chipmem_wget_ce2, ABFLAG_RAM }; #endif addrbank bogomem_bank = { - bogomem_lget, bogomem_wget, bogomem_bget, - bogomem_lput, bogomem_wput, bogomem_bput, - bogomem_xlate, bogomem_check, NULL, L"Slow memory", - bogomem_lget, bogomem_wget, ABFLAG_RAM + bogomem_lget, bogomem_wget, bogomem_bget, + bogomem_lput, bogomem_wput, bogomem_bput, + bogomem_xlate, bogomem_check, NULL, L"Slow memory", + bogomem_lget, bogomem_wget, ABFLAG_RAM }; addrbank cardmem_bank = { - cardmem_lget, cardmem_wget, cardmem_bget, - cardmem_lput, cardmem_wput, cardmem_bput, - cardmem_xlate, cardmem_check, NULL, L"CDTV memory card", - cardmem_lget, cardmem_wget, ABFLAG_RAM + cardmem_lget, cardmem_wget, cardmem_bget, + cardmem_lput, cardmem_wput, cardmem_bput, + cardmem_xlate, cardmem_check, NULL, L"CDTV memory card", + cardmem_lget, cardmem_wget, ABFLAG_RAM }; addrbank a3000lmem_bank = { - a3000lmem_lget, a3000lmem_wget, a3000lmem_bget, - a3000lmem_lput, a3000lmem_wput, a3000lmem_bput, - a3000lmem_xlate, a3000lmem_check, NULL, L"RAMSEY memory (low)", - a3000lmem_lget, a3000lmem_wget, ABFLAG_RAM + a3000lmem_lget, a3000lmem_wget, a3000lmem_bget, + a3000lmem_lput, a3000lmem_wput, a3000lmem_bput, + a3000lmem_xlate, a3000lmem_check, NULL, L"RAMSEY memory (low)", + a3000lmem_lget, a3000lmem_wget, ABFLAG_RAM }; addrbank a3000hmem_bank = { - a3000hmem_lget, a3000hmem_wget, a3000hmem_bget, - a3000hmem_lput, a3000hmem_wput, a3000hmem_bput, - a3000hmem_xlate, a3000hmem_check, NULL, L"RAMSEY memory (high)", - a3000hmem_lget, a3000hmem_wget, ABFLAG_RAM + a3000hmem_lget, a3000hmem_wget, a3000hmem_bget, + a3000hmem_lput, a3000hmem_wput, a3000hmem_bput, + a3000hmem_xlate, a3000hmem_check, NULL, L"RAMSEY memory (high)", + a3000hmem_lget, a3000hmem_wget, ABFLAG_RAM }; addrbank kickmem_bank = { - kickmem_lget, kickmem_wget, kickmem_bget, - kickmem_lput, kickmem_wput, kickmem_bput, - kickmem_xlate, kickmem_check, NULL, L"Kickstart ROM", - kickmem_lget, kickmem_wget, ABFLAG_ROM + kickmem_lget, kickmem_wget, kickmem_bget, + kickmem_lput, kickmem_wput, kickmem_bput, + kickmem_xlate, kickmem_check, NULL, L"Kickstart ROM", + kickmem_lget, kickmem_wget, ABFLAG_ROM }; addrbank kickram_bank = { - kickmem_lget, kickmem_wget, kickmem_bget, - kickmem2_lput, kickmem2_wput, kickmem2_bput, - kickmem_xlate, kickmem_check, NULL, L"Kickstart Shadow RAM", - kickmem_lget, kickmem_wget, ABFLAG_UNK | ABFLAG_SAFE + kickmem_lget, kickmem_wget, kickmem_bget, + kickmem2_lput, kickmem2_wput, kickmem2_bput, + kickmem_xlate, kickmem_check, NULL, L"Kickstart Shadow RAM", + kickmem_lget, kickmem_wget, ABFLAG_UNK | ABFLAG_SAFE }; addrbank extendedkickmem_bank = { - extendedkickmem_lget, extendedkickmem_wget, extendedkickmem_bget, - extendedkickmem_lput, extendedkickmem_wput, extendedkickmem_bput, - extendedkickmem_xlate, extendedkickmem_check, NULL, L"Extended Kickstart ROM", - extendedkickmem_lget, extendedkickmem_wget, ABFLAG_ROM + extendedkickmem_lget, extendedkickmem_wget, extendedkickmem_bget, + extendedkickmem_lput, extendedkickmem_wput, extendedkickmem_bput, + extendedkickmem_xlate, extendedkickmem_check, NULL, L"Extended Kickstart ROM", + extendedkickmem_lget, extendedkickmem_wget, ABFLAG_ROM }; addrbank extendedkickmem2_bank = { - extendedkickmem2_lget, extendedkickmem2_wget, extendedkickmem2_bget, - extendedkickmem2_lput, extendedkickmem2_wput, extendedkickmem2_bput, - extendedkickmem2_xlate, extendedkickmem2_check, NULL, L"Extended 2nd Kickstart ROM", - extendedkickmem2_lget, extendedkickmem2_wget, ABFLAG_ROM + extendedkickmem2_lget, extendedkickmem2_wget, extendedkickmem2_bget, + extendedkickmem2_lput, extendedkickmem2_wput, extendedkickmem2_bput, + extendedkickmem2_xlate, extendedkickmem2_check, NULL, L"Extended 2nd Kickstart ROM", + extendedkickmem2_lget, extendedkickmem2_wget, ABFLAG_ROM }; @@ -2244,59 +2244,59 @@ static uae_u8 *REGPARAM3 custmem1_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 custmem1_lget (uaecptr addr) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - m = custmem1 + addr; - return do_get_mem_long ((uae_u32 *)m); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + m = custmem1 + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 custmem1_wget (uaecptr addr) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - m = custmem1 + addr; - return do_get_mem_word ((uae_u16 *)m); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + m = custmem1 + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 custmem1_bget (uaecptr addr) { - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - return custmem1[addr]; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + return custmem1[addr]; } static void REGPARAM2 custmem1_lput (uaecptr addr, uae_u32 l) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - m = custmem1 + addr; - do_put_mem_long ((uae_u32 *)m, l); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + m = custmem1 + addr; + do_put_mem_long ((uae_u32 *)m, l); } static void REGPARAM2 custmem1_wput (uaecptr addr, uae_u32 w) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - m = custmem1 + addr; - do_put_mem_word ((uae_u16 *)m, w); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + m = custmem1 + addr; + do_put_mem_word ((uae_u16 *)m, w); } static void REGPARAM2 custmem1_bput (uaecptr addr, uae_u32 b) { - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - custmem1[addr] = b; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + custmem1[addr] = b; } static int REGPARAM2 custmem1_check (uaecptr addr, uae_u32 size) { - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - return (addr + size) <= currprefs.custom_memory_sizes[0]; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + return (addr + size) <= currprefs.custom_memory_sizes[0]; } static uae_u8 *REGPARAM2 custmem1_xlate (uaecptr addr) { - addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; - addr &= custmem1_mask; - return custmem1 + addr; + addr -= currprefs.custom_memory_addrs[0] & custmem1_mask; + addr &= custmem1_mask; + return custmem1 + addr; } static uae_u32 REGPARAM3 custmem2_lget (uaecptr) REGPARAM; @@ -2310,727 +2310,727 @@ static uae_u8 *REGPARAM3 custmem2_xlate (uaecptr addr) REGPARAM; static uae_u32 REGPARAM2 custmem2_lget (uaecptr addr) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - m = custmem2 + addr; - return do_get_mem_long ((uae_u32 *)m); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + m = custmem2 + addr; + return do_get_mem_long ((uae_u32 *)m); } static uae_u32 REGPARAM2 custmem2_wget (uaecptr addr) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - m = custmem2 + addr; - return do_get_mem_word ((uae_u16 *)m); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + m = custmem2 + addr; + return do_get_mem_word ((uae_u16 *)m); } static uae_u32 REGPARAM2 custmem2_bget (uaecptr addr) { - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - return custmem2[addr]; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + return custmem2[addr]; } static void REGPARAM2 custmem2_lput (uaecptr addr, uae_u32 l) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - m = custmem2 + addr; - do_put_mem_long ((uae_u32 *)m, l); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + m = custmem2 + addr; + do_put_mem_long ((uae_u32 *)m, l); } static void REGPARAM2 custmem2_wput (uaecptr addr, uae_u32 w) { - uae_u8 *m; - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - m = custmem2 + addr; - do_put_mem_word ((uae_u16 *)m, w); + uae_u8 *m; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + m = custmem2 + addr; + do_put_mem_word ((uae_u16 *)m, w); } static void REGPARAM2 custmem2_bput (uaecptr addr, uae_u32 b) { - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - custmem2[addr] = b; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + custmem2[addr] = b; } static int REGPARAM2 custmem2_check (uaecptr addr, uae_u32 size) { - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - return (addr + size) <= currprefs.custom_memory_sizes[1]; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + return (addr + size) <= currprefs.custom_memory_sizes[1]; } static uae_u8 *REGPARAM2 custmem2_xlate (uaecptr addr) { - addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; - addr &= custmem2_mask; - return custmem2 + addr; + addr -= currprefs.custom_memory_addrs[1] & custmem2_mask; + addr &= custmem2_mask; + return custmem2 + addr; } addrbank custmem1_bank = { - custmem1_lget, custmem1_wget, custmem1_bget, - custmem1_lput, custmem1_wput, custmem1_bput, - custmem1_xlate, custmem1_check, NULL, L"Non-autoconfig RAM #1", - custmem1_lget, custmem1_wget, ABFLAG_RAM + custmem1_lget, custmem1_wget, custmem1_bget, + custmem1_lput, custmem1_wput, custmem1_bput, + custmem1_xlate, custmem1_check, NULL, L"Non-autoconfig RAM #1", + custmem1_lget, custmem1_wget, ABFLAG_RAM }; addrbank custmem2_bank = { - custmem1_lget, custmem1_wget, custmem1_bget, - custmem1_lput, custmem1_wput, custmem1_bput, - custmem1_xlate, custmem1_check, NULL, L"Non-autoconfig RAM #2", - custmem1_lget, custmem1_wget, ABFLAG_RAM + custmem1_lget, custmem1_wget, custmem1_bget, + custmem1_lput, custmem1_wput, custmem1_bput, + custmem1_xlate, custmem1_check, NULL, L"Non-autoconfig RAM #2", + custmem1_lget, custmem1_wget, ABFLAG_RAM }; #define fkickmem_size 524288 static int a3000_f0; void a3000_fakekick (int map) { - static uae_u8 *kickstore; - - if (map) { - uae_u8 *fkickmemory = a3000lmemory + allocated_a3000lmem - fkickmem_size; - if (fkickmemory[2] == 0x4e && fkickmemory[3] == 0xf9 && fkickmemory[4] == 0x00) { - if (!kickstore) - kickstore = xmalloc (fkickmem_size); - memcpy (kickstore, kickmemory, fkickmem_size); - if (fkickmemory[5] == 0xfc) { - memcpy (kickmemory, fkickmemory, fkickmem_size / 2); - memcpy (kickmemory + fkickmem_size / 2, fkickmemory, fkickmem_size / 2); - extendedkickmem_size = 65536; - extendedkickmem_mask = extendedkickmem_size - 1; - extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); - extendedkickmem_bank.baseaddr = extendedkickmemory; - memcpy (extendedkickmemory, fkickmemory + fkickmem_size / 2, 65536); - map_banks (&extendedkickmem_bank, 0xf0, 1, 1); - a3000_f0 = 1; - } else { - memcpy (kickmemory, fkickmemory, fkickmem_size); - } - } - } else { - if (a3000_f0) { - map_banks (&dummy_bank, 0xf0, 1, 1); - mapped_free (extendedkickmemory); - extendedkickmemory = NULL; - a3000_f0 = 0; + static uae_u8 *kickstore; + + if (map) { + uae_u8 *fkickmemory = a3000lmemory + allocated_a3000lmem - fkickmem_size; + if (fkickmemory[2] == 0x4e && fkickmemory[3] == 0xf9 && fkickmemory[4] == 0x00) { + if (!kickstore) + kickstore = xmalloc (fkickmem_size); + memcpy (kickstore, kickmemory, fkickmem_size); + if (fkickmemory[5] == 0xfc) { + memcpy (kickmemory, fkickmemory, fkickmem_size / 2); + memcpy (kickmemory + fkickmem_size / 2, fkickmemory, fkickmem_size / 2); + extendedkickmem_size = 65536; + extendedkickmem_mask = extendedkickmem_size - 1; + extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); + extendedkickmem_bank.baseaddr = extendedkickmemory; + memcpy (extendedkickmemory, fkickmemory + fkickmem_size / 2, 65536); + map_banks (&extendedkickmem_bank, 0xf0, 1, 1); + a3000_f0 = 1; + } else { + memcpy (kickmemory, fkickmemory, fkickmem_size); + } + } + } else { + if (a3000_f0) { + map_banks (&dummy_bank, 0xf0, 1, 1); + mapped_free (extendedkickmemory); + extendedkickmemory = NULL; + a3000_f0 = 0; + } + if (kickstore) + memcpy (kickmemory, kickstore, fkickmem_size); + xfree (kickstore); + kickstore = NULL; } - if (kickstore) - memcpy (kickmemory, kickstore, fkickmem_size); - xfree (kickstore); - kickstore = NULL; - } } static int kickstart_checksum (uae_u8 *mem, int size) { - if (!kickstart_checksum_do (mem, size)) { + if (!kickstart_checksum_do (mem, size)) { #ifndef SINGLEFILE - notify_user (NUMSG_KSROMCRCERROR); + notify_user (NUMSG_KSROMCRCERROR); #endif - return 0; - } - return 1; + return 0; + } + return 1; } static int read_rom_file (uae_u8 *buf, struct romdata *rd) { - struct zfile *zf; - struct romlist *rl = romlist_getrl (rd); - uae_char tmp[11]; - - if (!rl || _tcslen (rl->path) == 0) - return 0; - zf = zfile_fopen (rl->path, L"rb", ZFD_NORMAL); - if (!zf) - return 0; - addkeydir (rl->path); - zfile_fread (tmp, sizeof tmp, 1, zf); - if (!memcmp (tmp, "AMIROMTYPE1", sizeof tmp)) { - zfile_fread (buf, rd->size, 1, zf); - decode_cloanto_rom_do (buf, rd->size, rd->size); - } else { - memcpy (buf, tmp, sizeof tmp); - zfile_fread (buf + sizeof tmp, rd->size - sizeof (tmp), 1, zf); - } - zfile_fclose (zf); - return 1; + struct zfile *zf; + struct romlist *rl = romlist_getrl (rd); + uae_char tmp[11]; + + if (!rl || _tcslen (rl->path) == 0) + return 0; + zf = zfile_fopen (rl->path, L"rb", ZFD_NORMAL); + if (!zf) + return 0; + addkeydir (rl->path); + zfile_fread (tmp, sizeof tmp, 1, zf); + if (!memcmp (tmp, "AMIROMTYPE1", sizeof tmp)) { + zfile_fread (buf, rd->size, 1, zf); + decode_cloanto_rom_do (buf, rd->size, rd->size); + } else { + memcpy (buf, tmp, sizeof tmp); + zfile_fread (buf + sizeof tmp, rd->size - sizeof (tmp), 1, zf); + } + zfile_fclose (zf); + return 1; } static void byteswap (uae_u8 *buf, int size) { - int i; - for (i = 0; i < size; i += 2) { - uae_u8 t = buf[i]; - buf[i] = buf[i + 1]; - buf[i + 1] = t; - } + int i; + for (i = 0; i < size; i += 2) { + uae_u8 t = buf[i]; + buf[i] = buf[i + 1]; + buf[i + 1] = t; + } } static void wordbyteswap (uae_u8 *buf, int size) { - int i; - for (i = 0; i < size; i += 4) { - uae_u8 t; - t = buf[i + 0]; - buf[i + 0] = buf[i + 2]; - buf[i + 2] = t; - t = buf[i + 1]; - buf[i + 1] = buf[i + 3]; - buf[i + 3] = t; - } + int i; + for (i = 0; i < size; i += 4) { + uae_u8 t; + t = buf[i + 0]; + buf[i + 0] = buf[i + 2]; + buf[i + 2] = t; + t = buf[i + 1]; + buf[i + 1] = buf[i + 3]; + buf[i + 3] = t; + } } static void mergecd32 (uae_u8 *dst, uae_u8 *src, int size) { - int i, k; - k = 0; - for (i = 0; i < size / 2; i += 2) { - int j = i + size / 2; - dst[k + 1] = src[i + 0]; - dst[k + 0] = src[i + 1]; - dst[k + 3] = src[j + 0]; - dst[k + 2] = src[j + 1]; - k += 4; - } + int i, k; + k = 0; + for (i = 0; i < size / 2; i += 2) { + int j = i + size / 2; + dst[k + 1] = src[i + 0]; + dst[k + 0] = src[i + 1]; + dst[k + 3] = src[j + 0]; + dst[k + 2] = src[j + 1]; + k += 4; + } #if 0 - { - struct zfile *f; - f = zfile_fopen ("c:\\d\\1.rom","wb", ZFD_NORMAL); - zfile_fwrite (dst, 1, size, f); - zfile_fclose(f); - } + { + struct zfile *f; + f = zfile_fopen ("c:\\d\\1.rom","wb", ZFD_NORMAL); + zfile_fwrite (dst, 1, size, f); + zfile_fclose(f); + } #endif } static void descramble (struct romdata *rd, uae_u8 *data, int size, int odd) { - int flags = rd->type; + int flags = rd->type; - if (flags & (ROMTYPE_NORDIC | ROMTYPE_XPOWER)) - descramble_nordicpro (data, size, odd); + if (flags & (ROMTYPE_NORDIC | ROMTYPE_XPOWER)) + descramble_nordicpro (data, size, odd); } struct zfile *read_rom (struct romdata **prd) { - struct romdata *rd2 = *prd; - struct romdata *rd = *prd; - TCHAR *name; - int id = rd->id; - uae_u32 crc32; - int size; - uae_u8 *buf, *buf2; - - /* find parent node */ - for (;;) { - if (rd2 == &roms[0]) - break; - if (rd2[-1].id != id) - break; - rd2--; - } - *prd = rd2; - size = rd2->size; - crc32 = rd2->crc32; - name = rd->name; - buf = xmalloc (size * 2); - memset (buf, 0xff, size * 2); - if (!buf) - return NULL; - buf2 = buf + size; - while (rd->id == id) { - int i, j, add; - int ok = 0; - uae_u32 flags = rd->type; - int odd = (flags & ROMTYPE_ODD) ? 1 : 0; - - add = 0; - for (i = 0; i < 2; i++) { - memset (buf, 0, size); - if (!(flags & (ROMTYPE_EVEN | ROMTYPE_ODD))) { - read_rom_file (buf, rd); - if (flags & ROMTYPE_CD32) { - memcpy (buf2, buf, size); - mergecd32 (buf, buf2, size); - } - add = 1; - i++; - } else { - int romsize = size / 2; - if (i) - odd = !odd; - if (flags & ROMTYPE_8BIT) { - read_rom_file (buf2, rd); - if (flags & ROMTYPE_BYTESWAP) - byteswap (buf2, romsize); - if (flags & ROMTYPE_SCRAMBLED) - descramble (rd, buf2, romsize, odd); - for (j = 0; j < size; j += 2) - buf[j + odd] = buf2[j / 2]; - read_rom_file (buf2, rd + 1); - if (flags & ROMTYPE_BYTESWAP) - byteswap (buf2, romsize); - if (flags & ROMTYPE_SCRAMBLED) - descramble (rd + 1, buf2, romsize, !odd); - for (j = 0; j < size; j += 2) - buf[j + (1 - odd)] = buf2[j / 2]; - } else { - read_rom_file (buf2, rd); - if (flags & ROMTYPE_BYTESWAP) - byteswap (buf2, romsize); - if (flags & ROMTYPE_SCRAMBLED) - descramble (rd, buf2, romsize, odd); - for (j = 0; j < size; j += 4) { - buf[j + 2 * odd + 0] = buf2[j / 2 + 0]; - buf[j + 2 * odd + 1] = buf2[j / 2 + 1]; - } - read_rom_file (buf2, rd + 1); - if (flags & ROMTYPE_BYTESWAP) - byteswap (buf2, romsize); - if (flags & ROMTYPE_SCRAMBLED) - descramble (rd + 1, buf2, romsize, !odd); - for (j = 0; j < size; j += 4) { - buf[j + 2 * (1 - odd) + 0] = buf2[j / 2 + 0]; - buf[j + 2 * (1 - odd) + 1] = buf2[j / 2 + 1]; - } - } - add = 2; - } - if (get_crc32 (buf, size) == crc32) { - ok = 1; - } else { - /* perhaps it is byteswapped without byteswap entry? */ - byteswap (buf, size); - if (get_crc32 (buf, size) == crc32) - ok = 1; - } - if (ok) { - struct zfile *zf = zfile_fopen_empty (NULL, name, size); - if (zf) { - zfile_fwrite (buf, size, 1, zf); - zfile_fseek (zf, 0, SEEK_SET); - } - xfree (buf); - return zf; - } + struct romdata *rd2 = *prd; + struct romdata *rd = *prd; + TCHAR *name; + int id = rd->id; + uae_u32 crc32; + int size; + uae_u8 *buf, *buf2; + + /* find parent node */ + for (;;) { + if (rd2 == &roms[0]) + break; + if (rd2[-1].id != id) + break; + rd2--; } - rd += add; + *prd = rd2; + size = rd2->size; + crc32 = rd2->crc32; + name = rd->name; + buf = xmalloc (size * 2); + memset (buf, 0xff, size * 2); + if (!buf) + return NULL; + buf2 = buf + size; + while (rd->id == id) { + int i, j, add; + int ok = 0; + uae_u32 flags = rd->type; + int odd = (flags & ROMTYPE_ODD) ? 1 : 0; + + add = 0; + for (i = 0; i < 2; i++) { + memset (buf, 0, size); + if (!(flags & (ROMTYPE_EVEN | ROMTYPE_ODD))) { + read_rom_file (buf, rd); + if (flags & ROMTYPE_CD32) { + memcpy (buf2, buf, size); + mergecd32 (buf, buf2, size); + } + add = 1; + i++; + } else { + int romsize = size / 2; + if (i) + odd = !odd; + if (flags & ROMTYPE_8BIT) { + read_rom_file (buf2, rd); + if (flags & ROMTYPE_BYTESWAP) + byteswap (buf2, romsize); + if (flags & ROMTYPE_SCRAMBLED) + descramble (rd, buf2, romsize, odd); + for (j = 0; j < size; j += 2) + buf[j + odd] = buf2[j / 2]; + read_rom_file (buf2, rd + 1); + if (flags & ROMTYPE_BYTESWAP) + byteswap (buf2, romsize); + if (flags & ROMTYPE_SCRAMBLED) + descramble (rd + 1, buf2, romsize, !odd); + for (j = 0; j < size; j += 2) + buf[j + (1 - odd)] = buf2[j / 2]; + } else { + read_rom_file (buf2, rd); + if (flags & ROMTYPE_BYTESWAP) + byteswap (buf2, romsize); + if (flags & ROMTYPE_SCRAMBLED) + descramble (rd, buf2, romsize, odd); + for (j = 0; j < size; j += 4) { + buf[j + 2 * odd + 0] = buf2[j / 2 + 0]; + buf[j + 2 * odd + 1] = buf2[j / 2 + 1]; + } + read_rom_file (buf2, rd + 1); + if (flags & ROMTYPE_BYTESWAP) + byteswap (buf2, romsize); + if (flags & ROMTYPE_SCRAMBLED) + descramble (rd + 1, buf2, romsize, !odd); + for (j = 0; j < size; j += 4) { + buf[j + 2 * (1 - odd) + 0] = buf2[j / 2 + 0]; + buf[j + 2 * (1 - odd) + 1] = buf2[j / 2 + 1]; + } + } + add = 2; + } + if (get_crc32 (buf, size) == crc32) { + ok = 1; + } else { + /* perhaps it is byteswapped without byteswap entry? */ + byteswap (buf, size); + if (get_crc32 (buf, size) == crc32) + ok = 1; + } + if (ok) { + struct zfile *zf = zfile_fopen_empty (NULL, name, size); + if (zf) { + zfile_fwrite (buf, size, 1, zf); + zfile_fseek (zf, 0, SEEK_SET); + } + xfree (buf); + return zf; + } + } + rd += add; - } - xfree (buf); - return NULL; + } + xfree (buf); + return NULL; } static struct zfile *rom_fopen (const TCHAR *name, const TCHAR *mode, int mask) { - struct zfile *f; - //write_log (L"attempting to load '%s'\n", name); - f = zfile_fopen (name, mode, mask); - //write_log (L"=%p\n", f); - return f; + struct zfile *f; + //write_log (L"attempting to load '%s'\n", name); + f = zfile_fopen (name, mode, mask); + //write_log (L"=%p\n", f); + return f; } struct zfile *read_rom_name (const TCHAR *filename) { - int i; - struct zfile *f; + int i; + struct zfile *f; - for (i = 0; i < romlist_cnt; i++) { - if (!_tcsicmp (filename, rl[i].path)) { - struct romdata *rd = rl[i].rd; - f = read_rom (&rd); - if (f) - return f; + for (i = 0; i < romlist_cnt; i++) { + if (!_tcsicmp (filename, rl[i].path)) { + struct romdata *rd = rl[i].rd; + f = read_rom (&rd); + if (f) + return f; + } } - } - f = rom_fopen (filename, L"rb", ZFD_NORMAL); - if (f) { - uae_u8 tmp[11]; - zfile_fread (tmp, sizeof tmp, 1, f); - if (!memcmp (tmp, "AMIROMTYPE1", sizeof tmp)) { - struct zfile *df; - int size; - uae_u8 *buf; - addkeydir (filename); - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f) - sizeof tmp; - zfile_fseek (f, sizeof tmp, SEEK_SET); - buf = xmalloc (size); - zfile_fread (buf, size, 1, f); - df = zfile_fopen_empty (f, L"tmp.rom", size); - decode_cloanto_rom_do (buf, size, size); - zfile_fwrite (buf, size, 1, df); - zfile_fclose (f); - xfree (buf); - zfile_fseek (df, 0, SEEK_SET); - f = df; - } else { - zfile_fseek (f, -((int)sizeof tmp), SEEK_CUR); + f = rom_fopen (filename, L"rb", ZFD_NORMAL); + if (f) { + uae_u8 tmp[11]; + zfile_fread (tmp, sizeof tmp, 1, f); + if (!memcmp (tmp, "AMIROMTYPE1", sizeof tmp)) { + struct zfile *df; + int size; + uae_u8 *buf; + addkeydir (filename); + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f) - sizeof tmp; + zfile_fseek (f, sizeof tmp, SEEK_SET); + buf = xmalloc (size); + zfile_fread (buf, size, 1, f); + df = zfile_fopen_empty (f, L"tmp.rom", size); + decode_cloanto_rom_do (buf, size, size); + zfile_fwrite (buf, size, 1, df); + zfile_fclose (f); + xfree (buf); + zfile_fseek (df, 0, SEEK_SET); + f = df; + } else { + zfile_fseek (f, -((int)sizeof tmp), SEEK_CUR); + } } - } - return f; + return f; } static void kickstart_fix_checksum (uae_u8 *mem, int size) { - uae_u32 cksum = 0, prevck = 0; - int i, ch = size == 524288 ? 0x7ffe8 : 0x3e; - - mem[ch] = 0; - mem[ch + 1] = 0; - mem[ch + 2] = 0; - mem[ch + 3] = 0; - for (i = 0; i < size; i+=4) { - uae_u32 data = (mem[i] << 24) | (mem[i + 1] << 16) | (mem[i + 2] << 8) | mem[i + 3]; - cksum += data; - if (cksum < prevck) - cksum++; - prevck = cksum; - } - cksum ^= 0xffffffff; - mem[ch++] = cksum >> 24; - mem[ch++] = cksum >> 16; - mem[ch++] = cksum >> 8; - mem[ch++] = cksum >> 0; + uae_u32 cksum = 0, prevck = 0; + int i, ch = size == 524288 ? 0x7ffe8 : 0x3e; + + mem[ch] = 0; + mem[ch + 1] = 0; + mem[ch + 2] = 0; + mem[ch + 3] = 0; + for (i = 0; i < size; i+=4) { + uae_u32 data = (mem[i] << 24) | (mem[i + 1] << 16) | (mem[i + 2] << 8) | mem[i + 3]; + cksum += data; + if (cksum < prevck) + cksum++; + prevck = cksum; + } + cksum ^= 0xffffffff; + mem[ch++] = cksum >> 24; + mem[ch++] = cksum >> 16; + mem[ch++] = cksum >> 8; + mem[ch++] = cksum >> 0; } static uae_char *kickstring = "exec.library"; static int read_kickstart (struct zfile *f, uae_u8 *mem, int size, int dochecksum, int noalias) { - uae_char buffer[20]; - int i, j, oldpos; - int cr = 0, kickdisk = 0; + uae_char buffer[20]; + int i, j, oldpos; + int cr = 0, kickdisk = 0; - if (size < 0) { - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f) & ~0x3ff; - zfile_fseek (f, 0, SEEK_SET); - } - oldpos = zfile_ftell (f); - i = zfile_fread (buffer, 1, 11, f); - if (!memcmp (buffer, "KICK", 4)) { - zfile_fseek (f, 512, SEEK_SET); - kickdisk = 1; + if (size < 0) { + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f) & ~0x3ff; + zfile_fseek (f, 0, SEEK_SET); + } + oldpos = zfile_ftell (f); + i = zfile_fread (buffer, 1, 11, f); + if (!memcmp (buffer, "KICK", 4)) { + zfile_fseek (f, 512, SEEK_SET); + kickdisk = 1; #if 0 - } else if (size >= 524288 && !memcmp (buffer, "AMIG", 4)) { - /* ReKick */ - zfile_fseek (f, oldpos + 0x6c, SEEK_SET); - cr = 2; + } else if (size >= 524288 && !memcmp (buffer, "AMIG", 4)) { + /* ReKick */ + zfile_fseek (f, oldpos + 0x6c, SEEK_SET); + cr = 2; #endif - } else if (memcmp ((uae_char*)buffer, "AMIROMTYPE1", 11) != 0) { - zfile_fseek (f, oldpos, SEEK_SET); - } else { - cloanto_rom = 1; - cr = 1; - } - - memset (mem, 0, size); - for (i = 0; i < 8; i++) - mem[size - 16 + i * 2 + 1] = 0x18 + i; - mem[size - 20] = size >> 24; - mem[size - 19] = size >> 16; - mem[size - 18] = size >> 8; - mem[size - 17] = size >> 0; - - i = zfile_fread (mem, 1, size, f); - - if (kickdisk && i > 262144) - i = 262144; + } else if (memcmp ((uae_char*)buffer, "AMIROMTYPE1", 11) != 0) { + zfile_fseek (f, oldpos, SEEK_SET); + } else { + cloanto_rom = 1; + cr = 1; + } + + memset (mem, 0, size); + for (i = 0; i < 8; i++) + mem[size - 16 + i * 2 + 1] = 0x18 + i; + mem[size - 20] = size >> 24; + mem[size - 19] = size >> 16; + mem[size - 18] = size >> 8; + mem[size - 17] = size >> 0; + + i = zfile_fread (mem, 1, size, f); + + if (kickdisk && i > 262144) + i = 262144; #if 0 - if (i >= 262144 && (i != 262144 && i != 524288 && i != 524288 * 2 && i != 524288 * 4)) { - notify_user (NUMSG_KSROMREADERROR); - return 0; - } + if (i >= 262144 && (i != 262144 && i != 524288 && i != 524288 * 2 && i != 524288 * 4)) { + notify_user (NUMSG_KSROMREADERROR); + return 0; + } #endif - if (i < size - 20) - kickstart_fix_checksum (mem, size); - - j = 1; - while (j < i) - j <<= 1; - i = j; - - if (!noalias && i == size / 2) - memcpy (mem + size / 2, mem, size / 2); - - if (cr) { - if (!decode_rom (mem, size, cr, i)) - return 0; - } - if (currprefs.cs_a1000ram) { - int off = 0; - a1000_bootrom = xcalloc (262144, 1); - while (off + i < 262144) { - memcpy (a1000_bootrom + off, kickmemory, i); - off += i; + if (i < size - 20) + kickstart_fix_checksum (mem, size); + + j = 1; + while (j < i) + j <<= 1; + i = j; + + if (!noalias && i == size / 2) + memcpy (mem + size / 2, mem, size / 2); + + if (cr) { + if (!decode_rom (mem, size, cr, i)) + return 0; + } + if (currprefs.cs_a1000ram) { + int off = 0; + a1000_bootrom = xcalloc (262144, 1); + while (off + i < 262144) { + memcpy (a1000_bootrom + off, kickmemory, i); + off += i; + } + memset (kickmemory, 0, kickmem_size); + a1000_handle_kickstart (1); + dochecksum = 0; + i = 524288; } - memset (kickmemory, 0, kickmem_size); - a1000_handle_kickstart (1); - dochecksum = 0; - i = 524288; - } - for (j = 0; j < 256 && i >= 262144; j++) { - if (!memcmp (mem + j, kickstring, strlen (kickstring) + 1)) - break; - } + for (j = 0; j < 256 && i >= 262144; j++) { + if (!memcmp (mem + j, kickstring, strlen (kickstring) + 1)) + break; + } - if (j == 256 || i < 262144) - dochecksum = 0; - if (dochecksum) - kickstart_checksum (mem, size); - return i; + if (j == 256 || i < 262144) + dochecksum = 0; + if (dochecksum) + kickstart_checksum (mem, size); + return i; } static int load_extendedkickstart (void) { - struct zfile *f; - int size, off; + struct zfile *f; + int size, off; - if (_tcslen (currprefs.romextfile) == 0) - return 0; - if (is_arcadia_rom (currprefs.romextfile) == ARCADIA_BIOS) { - extendedkickmem_type = EXTENDED_ROM_ARCADIA; - return 0; - } - f = read_rom_name (currprefs.romextfile); - if (!f) { - notify_user (NUMSG_NOEXTROM); - return 0; - } - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f); - extendedkickmem_size = 524288; - off = 0; - if (currprefs.cs_cd32cd) { - extendedkickmem_type = EXTENDED_ROM_CD32; - } else if (currprefs.cs_cdtvcd || currprefs.cs_cdtvram) { - extendedkickmem_type = EXTENDED_ROM_CDTV; - } else if (size > 300000) { - extendedkickmem_type = EXTENDED_ROM_CD32; - } else if (need_uae_boot_rom () != 0xf00000) { - extendedkickmem_type = EXTENDED_ROM_CDTV; - } else - return 0; + if (_tcslen (currprefs.romextfile) == 0) + return 0; + if (is_arcadia_rom (currprefs.romextfile) == ARCADIA_BIOS) { + extendedkickmem_type = EXTENDED_ROM_ARCADIA; + return 0; + } + f = read_rom_name (currprefs.romextfile); + if (!f) { + notify_user (NUMSG_NOEXTROM); + return 0; + } + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f); + extendedkickmem_size = 524288; + off = 0; + if (currprefs.cs_cd32cd) { + extendedkickmem_type = EXTENDED_ROM_CD32; + } else if (currprefs.cs_cdtvcd || currprefs.cs_cdtvram) { + extendedkickmem_type = EXTENDED_ROM_CDTV; + } else if (size > 300000) { + extendedkickmem_type = EXTENDED_ROM_CD32; + } else if (need_uae_boot_rom () != 0xf00000) { + extendedkickmem_type = EXTENDED_ROM_CDTV; + } else + return 0; - zfile_fseek (f, off, SEEK_SET); - switch (extendedkickmem_type) { - case EXTENDED_ROM_CDTV: - extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); - extendedkickmem_bank.baseaddr = extendedkickmemory; - break; - case EXTENDED_ROM_CD32: - extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_e0"); - extendedkickmem_bank.baseaddr = extendedkickmemory; - break; - } - read_kickstart (f, extendedkickmemory, extendedkickmem_size, 0, 1); - extendedkickmem_mask = extendedkickmem_size - 1; - zfile_fclose (f); - return 1; + zfile_fseek (f, off, SEEK_SET); + switch (extendedkickmem_type) { + case EXTENDED_ROM_CDTV: + extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); + extendedkickmem_bank.baseaddr = extendedkickmemory; + break; + case EXTENDED_ROM_CD32: + extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_e0"); + extendedkickmem_bank.baseaddr = extendedkickmemory; + break; + } + read_kickstart (f, extendedkickmemory, extendedkickmem_size, 0, 1); + extendedkickmem_mask = extendedkickmem_size - 1; + zfile_fclose (f); + return 1; } static int patch_shapeshifter (uae_u8 *kickmemory) { - /* Patch Kickstart ROM for ShapeShifter - from Christian Bauer. - * Changes 'lea $400,a0' and 'lea $1000,a0' to 'lea $3000,a0' for - * ShapeShifter compatability. - */ - int i, patched = 0; - uae_u8 kickshift1[] = { 0x41, 0xf8, 0x04, 0x00 }; - uae_u8 kickshift2[] = { 0x41, 0xf8, 0x10, 0x00 }; - uae_u8 kickshift3[] = { 0x43, 0xf8, 0x04, 0x00 }; - - for (i = 0x200; i < 0x300; i++) { - if (!memcmp (kickmemory + i, kickshift1, sizeof (kickshift1)) || - !memcmp (kickmemory + i, kickshift2, sizeof (kickshift2)) || - !memcmp (kickmemory + i, kickshift3, sizeof (kickshift3))) { - kickmemory[i + 2] = 0x30; - write_log (L"Kickstart KickShifted @%04X\n", i); - patched++; + /* Patch Kickstart ROM for ShapeShifter - from Christian Bauer. + * Changes 'lea $400,a0' and 'lea $1000,a0' to 'lea $3000,a0' for + * ShapeShifter compatability. + */ + int i, patched = 0; + uae_u8 kickshift1[] = { 0x41, 0xf8, 0x04, 0x00 }; + uae_u8 kickshift2[] = { 0x41, 0xf8, 0x10, 0x00 }; + uae_u8 kickshift3[] = { 0x43, 0xf8, 0x04, 0x00 }; + + for (i = 0x200; i < 0x300; i++) { + if (!memcmp (kickmemory + i, kickshift1, sizeof (kickshift1)) || + !memcmp (kickmemory + i, kickshift2, sizeof (kickshift2)) || + !memcmp (kickmemory + i, kickshift3, sizeof (kickshift3))) { + kickmemory[i + 2] = 0x30; + write_log (L"Kickstart KickShifted @%04X\n", i); + patched++; + } } - } - return patched; + return patched; } /* disable incompatible drivers */ static int patch_residents (uae_u8 *kickmemory, int size) { - int i, j, patched = 0; - uae_char *residents[] = { "NCR scsi.device", 0 }; - // "scsi.device", "carddisk.device", "card.resource" }; - uaecptr base = size == 524288 ? 0xf80000 : 0xfc0000; - - if (currprefs.cs_mbdmac == 2) - residents[0] = NULL; - for (i = 0; i < size - 100; i++) { - if (kickmemory[i] == 0x4a && kickmemory[i + 1] == 0xfc) { - uaecptr addr; - addr = (kickmemory[i + 2] << 24) | (kickmemory[i + 3] << 16) | (kickmemory[i + 4] << 8) | (kickmemory[i + 5] << 0); - if (addr != i + base) - continue; - addr = (kickmemory[i + 14] << 24) | (kickmemory[i + 15] << 16) | (kickmemory[i + 16] << 8) | (kickmemory[i + 17] << 0); - if (addr >= base && addr < base + size) { - j = 0; - while (residents[j]) { - if (!memcmp (residents[j], kickmemory + addr - base, strlen (residents[j]) + 1)) { - TCHAR *s = au (residents[j]); - write_log (L"KSPatcher: '%s' at %08X disabled\n", s, i + base); - xfree (s); - kickmemory[i] = 0x4b; /* destroy RTC_MATCHWORD */ - patched++; - break; - } - j++; + int i, j, patched = 0; + uae_char *residents[] = { "NCR scsi.device", 0 }; + // "scsi.device", "carddisk.device", "card.resource" }; + uaecptr base = size == 524288 ? 0xf80000 : 0xfc0000; + + if (currprefs.cs_mbdmac == 2) + residents[0] = NULL; + for (i = 0; i < size - 100; i++) { + if (kickmemory[i] == 0x4a && kickmemory[i + 1] == 0xfc) { + uaecptr addr; + addr = (kickmemory[i + 2] << 24) | (kickmemory[i + 3] << 16) | (kickmemory[i + 4] << 8) | (kickmemory[i + 5] << 0); + if (addr != i + base) + continue; + addr = (kickmemory[i + 14] << 24) | (kickmemory[i + 15] << 16) | (kickmemory[i + 16] << 8) | (kickmemory[i + 17] << 0); + if (addr >= base && addr < base + size) { + j = 0; + while (residents[j]) { + if (!memcmp (residents[j], kickmemory + addr - base, strlen (residents[j]) + 1)) { + TCHAR *s = au (residents[j]); + write_log (L"KSPatcher: '%s' at %08X disabled\n", s, i + base); + xfree (s); + kickmemory[i] = 0x4b; /* destroy RTC_MATCHWORD */ + patched++; + break; + } + j++; + } + } } - } } - } - return patched; + return patched; } static void patch_kick (void) { - int patched = 0; - if (kickmem_size >= 524288 && currprefs.kickshifter) - patched += patch_shapeshifter (kickmemory); - patched += patch_residents (kickmemory, kickmem_size); - if (extendedkickmemory) { - patched += patch_residents (extendedkickmemory, extendedkickmem_size); + int patched = 0; + if (kickmem_size >= 524288 && currprefs.kickshifter) + patched += patch_shapeshifter (kickmemory); + patched += patch_residents (kickmemory, kickmem_size); + if (extendedkickmemory) { + patched += patch_residents (extendedkickmemory, extendedkickmem_size); + if (patched) + kickstart_fix_checksum (extendedkickmemory, extendedkickmem_size); + } if (patched) - kickstart_fix_checksum (extendedkickmemory, extendedkickmem_size); - } - if (patched) - kickstart_fix_checksum (kickmemory, kickmem_size); + kickstart_fix_checksum (kickmemory, kickmem_size); } static int load_kickstart (void) { - struct zfile *f; - TCHAR tmprom[MAX_DPATH], tmprom2[MAX_DPATH]; - int patched = 0; + struct zfile *f; + TCHAR tmprom[MAX_DPATH], tmprom2[MAX_DPATH]; + int patched = 0; - cloanto_rom = 0; - f = read_rom_name (currprefs.romfile); - _tcscpy (tmprom, currprefs.romfile); - if (f == NULL) { - _stprintf (tmprom2, L"%s%s", start_path_data, currprefs.romfile); - f = rom_fopen (tmprom2, L"rb", ZFD_NORMAL); + cloanto_rom = 0; + f = read_rom_name (currprefs.romfile); + _tcscpy (tmprom, currprefs.romfile); if (f == NULL) { - _stprintf (currprefs.romfile, L"%sroms/kick.rom", start_path_data); - f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); - if (f == NULL) { - _stprintf (currprefs.romfile, L"%skick.rom", start_path_data); - f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); + _stprintf (tmprom2, L"%s%s", start_path_data, currprefs.romfile); + f = rom_fopen (tmprom2, L"rb", ZFD_NORMAL); if (f == NULL) { - _stprintf (currprefs.romfile, L"%s../shared/rom/kick.rom", start_path_data); - f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); - if (f == NULL) { - _stprintf (currprefs.romfile, L"%s../System/rom/kick.rom", start_path_data); + _stprintf (currprefs.romfile, L"%sroms/kick.rom", start_path_data); f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); - } + if (f == NULL) { + _stprintf (currprefs.romfile, L"%skick.rom", start_path_data); + f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); + if (f == NULL) { + _stprintf (currprefs.romfile, L"%s../shared/rom/kick.rom", start_path_data); + f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); + if (f == NULL) { + _stprintf (currprefs.romfile, L"%s../System/rom/kick.rom", start_path_data); + f = rom_fopen (currprefs.romfile, L"rb", ZFD_NORMAL); + } + } + } + } else { + _tcscpy (currprefs.romfile, tmprom2); } - } - } else { - _tcscpy (currprefs.romfile, tmprom2); } - } - addkeydir (currprefs.romfile); - if (f == NULL) { /* still no luck */ + addkeydir (currprefs.romfile); + if (f == NULL) { /* still no luck */ #if defined(AMIGA)||defined(__POS__) #define USE_UAE_ERSATZ "USE_UAE_ERSATZ" - if( !getenv(USE_UAE_ERSATZ)) - { - write_log (L"Using current ROM. (create ENV:%s to " - "use uae's ROM replacement)\n",USE_UAE_ERSATZ); - memcpy(kickmemory,(char*)0x1000000-kickmem_size,kickmem_size); - kickstart_checksum (kickmemory, kickmem_size); - goto chk_sum; - } + if( !getenv(USE_UAE_ERSATZ)) + { + write_log (L"Using current ROM. (create ENV:%s to " + "use uae's ROM replacement)\n",USE_UAE_ERSATZ); + memcpy(kickmemory,(char*)0x1000000-kickmem_size,kickmem_size); + kickstart_checksum (kickmemory, kickmem_size); + goto chk_sum; + } #else - goto err; + goto err; #endif - } - - if (f != NULL) { - int filesize, size, maxsize; - int kspos = 524288; - int extpos = 0; - - maxsize = 524288; - zfile_fseek (f, 0, SEEK_END); - filesize = zfile_ftell (f); - zfile_fseek (f, 0, SEEK_SET); - if (filesize == 1760 * 512) { - filesize = 262144; - maxsize = 262144; - } - if (filesize == 524288 + 8) { - /* GVP 0xf0 kickstart */ - zfile_fseek (f, 8, SEEK_SET); - } - if (filesize >= 524288 * 2) { - struct romdata *rd = getromdatabyzfile(f); - zfile_fseek (f, kspos, SEEK_SET); - } - if (filesize >= 524288 * 4) { - kspos = 524288 * 3; - extpos = 0; - zfile_fseek (f, kspos, SEEK_SET); - } - size = read_kickstart (f, kickmemory, maxsize, 1, 0); - if (size == 0) - goto err; - kickmem_mask = size - 1; - kickmem_size = size; - if (filesize >= 524288 * 2 && !extendedkickmem_type) { - extendedkickmem_size = 0x80000; - if (currprefs.cs_cdtvcd || currprefs.cs_cdtvram) { - extendedkickmem_type = EXTENDED_ROM_CDTV; - extendedkickmem_size *= 2; - extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); - } else { - extendedkickmem_type = EXTENDED_ROM_KS; - extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_e0"); - } - extendedkickmem_bank.baseaddr = extendedkickmemory; - zfile_fseek (f, extpos, SEEK_SET); - read_kickstart (f, extendedkickmemory, extendedkickmem_size, 0, 1); - extendedkickmem_mask = extendedkickmem_size - 1; } - if (filesize > 524288 * 2) { - extendedkickmem2_size = 524288 * 2; - extendedkickmemory2 = mapped_malloc (extendedkickmem2_size, L"rom_a8"); - extendedkickmem2_bank.baseaddr = extendedkickmemory2; - zfile_fseek (f, extpos + 524288, SEEK_SET); - read_kickstart (f, extendedkickmemory2, 524288, 0, 1); - zfile_fseek (f, extpos + 524288 * 2, SEEK_SET); - read_kickstart (f, extendedkickmemory2 + 524288, 524288, 0, 1); - extendedkickmem2_mask = extendedkickmem2_size - 1; + + if (f != NULL) { + int filesize, size, maxsize; + int kspos = 524288; + int extpos = 0; + + maxsize = 524288; + zfile_fseek (f, 0, SEEK_END); + filesize = zfile_ftell (f); + zfile_fseek (f, 0, SEEK_SET); + if (filesize == 1760 * 512) { + filesize = 262144; + maxsize = 262144; + } + if (filesize == 524288 + 8) { + /* GVP 0xf0 kickstart */ + zfile_fseek (f, 8, SEEK_SET); + } + if (filesize >= 524288 * 2) { + struct romdata *rd = getromdatabyzfile(f); + zfile_fseek (f, kspos, SEEK_SET); + } + if (filesize >= 524288 * 4) { + kspos = 524288 * 3; + extpos = 0; + zfile_fseek (f, kspos, SEEK_SET); + } + size = read_kickstart (f, kickmemory, maxsize, 1, 0); + if (size == 0) + goto err; + kickmem_mask = size - 1; + kickmem_size = size; + if (filesize >= 524288 * 2 && !extendedkickmem_type) { + extendedkickmem_size = 0x80000; + if (currprefs.cs_cdtvcd || currprefs.cs_cdtvram) { + extendedkickmem_type = EXTENDED_ROM_CDTV; + extendedkickmem_size *= 2; + extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_f0"); + } else { + extendedkickmem_type = EXTENDED_ROM_KS; + extendedkickmemory = mapped_malloc (extendedkickmem_size, L"rom_e0"); + } + extendedkickmem_bank.baseaddr = extendedkickmemory; + zfile_fseek (f, extpos, SEEK_SET); + read_kickstart (f, extendedkickmemory, extendedkickmem_size, 0, 1); + extendedkickmem_mask = extendedkickmem_size - 1; + } + if (filesize > 524288 * 2) { + extendedkickmem2_size = 524288 * 2; + extendedkickmemory2 = mapped_malloc (extendedkickmem2_size, L"rom_a8"); + extendedkickmem2_bank.baseaddr = extendedkickmemory2; + zfile_fseek (f, extpos + 524288, SEEK_SET); + read_kickstart (f, extendedkickmemory2, 524288, 0, 1); + zfile_fseek (f, extpos + 524288 * 2, SEEK_SET); + read_kickstart (f, extendedkickmemory2 + 524288, 524288, 0, 1); + extendedkickmem2_mask = extendedkickmem2_size - 1; + } } - } #if defined(AMIGA) - chk_sum: +chk_sum: #endif - kickstart_version = (kickmemory[12] << 8) | kickmemory[13]; - if (kickstart_version == 0xffff) - kickstart_version = 0; - zfile_fclose (f); - return 1; + kickstart_version = (kickmemory[12] << 8) | kickmemory[13]; + if (kickstart_version == 0xffff) + kickstart_version = 0; + zfile_fclose (f); + return 1; err: - _tcscpy (currprefs.romfile, tmprom); - zfile_fclose (f); - return 0; + _tcscpy (currprefs.romfile, tmprom); + zfile_fclose (f); + return 0; } #ifndef NATMEM_OFFSET uae_u8 *mapped_malloc (size_t s, TCHAR *file) { - return xmalloc (s); + return xmalloc (s); } void mapped_free (uae_u8 *p) { - xfree (p); + xfree (p); } #else @@ -3044,839 +3044,839 @@ shmpiece *shm_start; static void dumplist (void) { - shmpiece *x = shm_start; - write_log (L"Start Dump:\n"); - while (x) { - write_log (L"this=%p,Native %p,id %d,prev=%p,next=%p,size=0x%08x\n", - x, x->native_address, x->id, x->prev, x->next, x->size); - x = x->next; - } - write_log (L"End Dump:\n"); + shmpiece *x = shm_start; + write_log (L"Start Dump:\n"); + while (x) { + write_log (L"this=%p,Native %p,id %d,prev=%p,next=%p,size=0x%08x\n", + x, x->native_address, x->id, x->prev, x->next, x->size); + x = x->next; + } + write_log (L"End Dump:\n"); } static shmpiece *find_shmpiece (uae_u8 *base) { - shmpiece *x = shm_start; + shmpiece *x = shm_start; - while (x && x->native_address != base) - x = x->next; - if (!x) { - write_log (L"NATMEM: Failure to find mapping at %08X, %p\n", base - NATMEM_OFFSET, base); - nocanbang (); - return 0; - } - return x; + while (x && x->native_address != base) + x = x->next; + if (!x) { + write_log (L"NATMEM: Failure to find mapping at %08X, %p\n", base - NATMEM_OFFSET, base); + nocanbang (); + return 0; + } + return x; } static void delete_shmmaps (uae_u32 start, uae_u32 size) { - if (!canjit ()) - return; - - while (size) { - uae_u8 *base = mem_banks[bankindex (start)]->baseaddr; - if (base) { - shmpiece *x; - //base = ((uae_u8*)NATMEM_OFFSET)+start; - - x = find_shmpiece (base); - if (!x) + if (!canjit ()) return; - if (x->size > size) { - if (isdirectjit ()) - write_log (L"NATMEM WARNING: size mismatch mapping at %08x (size %08x, delsize %08x)\n",start,x->size,size); - size = x->size; - } + while (size) { + uae_u8 *base = mem_banks[bankindex (start)]->baseaddr; + if (base) { + shmpiece *x; + //base = ((uae_u8*)NATMEM_OFFSET)+start; + + x = find_shmpiece (base); + if (!x) + return; + + if (x->size > size) { + if (isdirectjit ()) + write_log (L"NATMEM WARNING: size mismatch mapping at %08x (size %08x, delsize %08x)\n",start,x->size,size); + size = x->size; + } #if 0 - dumplist (); - nocanbang (); - return; - } + dumplist (); + nocanbang (); + return; + } #endif - shmdt (x->native_address); - size -= x->size; - start += x->size; - if (x->next) - x->next->prev = x->prev; /* remove this one from the list */ - if (x->prev) - x->prev->next = x->next; - else - shm_start = x->next; - xfree (x); + shmdt (x->native_address); + size -= x->size; + start += x->size; + if (x->next) + x->next->prev = x->prev; /* remove this one from the list */ + if (x->prev) + x->prev->next = x->next; + else + shm_start = x->next; + xfree (x); } else { - size -= 0x10000; - start += 0x10000; + size -= 0x10000; + start += 0x10000; } - } +} } static void add_shmmaps (uae_u32 start, addrbank *what) { - shmpiece *x = shm_start; - shmpiece *y; - uae_u8 *base = what->baseaddr; - - if (!canjit ()) - return; - if (!base) - return; - - x = find_shmpiece (base); - if (!x) - return; - y = xmalloc (sizeof (shmpiece)); - *y = *x; - base = ((uae_u8 *) NATMEM_OFFSET) + start; - y->native_address = shmat (y->id, base, 0); - if (y->native_address == (void *) -1) { - write_log (L"NATMEM: Failure to map existing at %08x (%p)\n", start, base); - dumplist (); - nocanbang (); - return; - } - y->next = shm_start; - y->prev = NULL; - if (y->next) - y->next->prev = y; - shm_start = y; + shmpiece *x = shm_start; + shmpiece *y; + uae_u8 *base = what->baseaddr; + + if (!canjit ()) + return; + if (!base) + return; + + x = find_shmpiece (base); + if (!x) + return; + y = xmalloc (sizeof (shmpiece)); + *y = *x; + base = ((uae_u8 *) NATMEM_OFFSET) + start; + y->native_address = shmat (y->id, base, 0); + if (y->native_address == (void *) -1) { + write_log (L"NATMEM: Failure to map existing at %08x (%p)\n", start, base); + dumplist (); + nocanbang (); + return; + } + y->next = shm_start; + y->prev = NULL; + if (y->next) + y->next->prev = y; + shm_start = y; } uae_u8 *mapped_malloc (size_t s, const TCHAR *file) { - int id; - void *answer; - shmpiece *x; + int id; + void *answer; + shmpiece *x; - if (!canjit()) { - nocanbang (); - return xcalloc (s + 4, 1); - } + if (!canjit()) { + nocanbang (); + return xcalloc (s + 4, 1); + } - id = shmget (IPC_PRIVATE, s, 0x1ff, file); - if (id == -1) { - static int recurse; - uae_u8 *p; + id = shmget (IPC_PRIVATE, s, 0x1ff, file); + if (id == -1) { + static int recurse; + uae_u8 *p; + nocanbang (); + if (recurse) + return NULL; + recurse++; + p = mapped_malloc (s, file); + recurse--; + return p; + } + answer = shmat (id, 0, 0); + shmctl (id, IPC_RMID, NULL); + if (answer != (void *) -1) { + x = xmalloc (sizeof (shmpiece)); + x->native_address = (uae_u8*)answer; + x->id = id; + x->size = s; + x->next = shm_start; + x->prev = NULL; + if (x->next) + x->next->prev = x; + shm_start = x; + return answer; + } nocanbang (); - if (recurse) - return NULL; - recurse++; - p = mapped_malloc (s, file); - recurse--; - return p; - } - answer = shmat (id, 0, 0); - shmctl (id, IPC_RMID, NULL); - if (answer != (void *) -1) { - x = xmalloc (sizeof (shmpiece)); - x->native_address = (uae_u8*)answer; - x->id = id; - x->size = s; - x->next = shm_start; - x->prev = NULL; - if (x->next) - x->next->prev = x; - shm_start = x; - return answer; - } - nocanbang (); - return mapped_malloc (s, file); + return mapped_malloc (s, file); } #endif static void init_mem_banks (void) { - int i; + int i; - for (i = 0; i < MEMORY_BANKS; i++) - put_mem_bank (i << 16, &dummy_bank, 0); + for (i = 0; i < MEMORY_BANKS; i++) + put_mem_bank (i << 16, &dummy_bank, 0); #ifdef NATMEM_OFFSET - delete_shmmaps (0, 0xFFFF0000); + delete_shmmaps (0, 0xFFFF0000); #endif } static void allocate_memory (void) { - /* emulate 0.5M+0.5M with 1M Agnus chip ram aliasing */ - if ((allocated_chipmem != currprefs.chipmem_size || allocated_bogomem != currprefs.bogomem_size) && - currprefs.chipmem_size == 0x80000 && currprefs.bogomem_size >= 0x80000 && - (currprefs.chipset_mask & CSMASK_ECS_AGNUS) && !(currprefs.chipset_mask & CSMASK_AGA) && !canjit ()) { - int memsize1, memsize2; - if (chipmemory) - mapped_free (chipmemory); - chipmemory = 0; - if (bogomemory_allocated) - mapped_free (bogomemory); - bogomemory = 0; - bogomemory_allocated = 0; - memsize1 = allocated_chipmem = currprefs.chipmem_size; - memsize2 = allocated_bogomem = currprefs.bogomem_size; - chipmem_mask = allocated_chipmem - 1; - chipmem_full_mask = allocated_chipmem * 2 - 1; - chipmem_full_size = 0x80000 * 2; - chipmemory = mapped_malloc (memsize1 + memsize2, L"chip"); - bogomemory = chipmemory + memsize1; - bogomem_mask = allocated_bogomem - 1; - if (chipmemory == 0) { - write_log (L"Fatal error: out of memory for chipmem.\n"); - allocated_chipmem = 0; - } else { - need_hardreset = 1; + /* emulate 0.5M+0.5M with 1M Agnus chip ram aliasing */ + if ((allocated_chipmem != currprefs.chipmem_size || allocated_bogomem != currprefs.bogomem_size) && + currprefs.chipmem_size == 0x80000 && currprefs.bogomem_size >= 0x80000 && + (currprefs.chipset_mask & CSMASK_ECS_AGNUS) && !(currprefs.chipset_mask & CSMASK_AGA) && !canjit ()) { + int memsize1, memsize2; + if (chipmemory) + mapped_free (chipmemory); + chipmemory = 0; + if (bogomemory_allocated) + mapped_free (bogomemory); + bogomemory = 0; + bogomemory_allocated = 0; + memsize1 = allocated_chipmem = currprefs.chipmem_size; + memsize2 = allocated_bogomem = currprefs.bogomem_size; + chipmem_mask = allocated_chipmem - 1; + chipmem_full_mask = allocated_chipmem * 2 - 1; + chipmem_full_size = 0x80000 * 2; + chipmemory = mapped_malloc (memsize1 + memsize2, L"chip"); + bogomemory = chipmemory + memsize1; + bogomem_mask = allocated_bogomem - 1; + if (chipmemory == 0) { + write_log (L"Fatal error: out of memory for chipmem.\n"); + allocated_chipmem = 0; + } else { + need_hardreset = 1; + } } - } - if (allocated_chipmem != currprefs.chipmem_size) { - int memsize; - if (chipmemory) - mapped_free (chipmemory); - chipmemory = 0; - if (currprefs.chipmem_size > 2 * 1024 * 1024) - free_fastmemory (); - - memsize = allocated_chipmem = chipmem_full_size = currprefs.chipmem_size; - chipmem_full_mask = chipmem_mask = allocated_chipmem - 1; - if (memsize < 0x100000) - memsize = 0x100000; - if (memsize > 0x100000 && memsize < 0x200000) - memsize = 0x200000; - chipmemory = mapped_malloc (memsize, L"chip"); - if (chipmemory == 0) { - write_log (L"Fatal error: out of memory for chipmem.\n"); - allocated_chipmem = 0; - } else { - need_hardreset = 1; - if (memsize > allocated_chipmem) - memset (chipmemory + allocated_chipmem, 0xff, memsize - allocated_chipmem); - } - currprefs.chipset_mask = changed_prefs.chipset_mask; - chipmem_full_mask = allocated_chipmem - 1; - if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { - if (allocated_chipmem < 0x100000) - chipmem_full_mask = 0x100000 - 1; - if (allocated_chipmem > 0x100000 && allocated_chipmem < 0x200000) - chipmem_full_mask = chipmem_mask = 0x200000 - 1; + if (allocated_chipmem != currprefs.chipmem_size) { + int memsize; + if (chipmemory) + mapped_free (chipmemory); + chipmemory = 0; + if (currprefs.chipmem_size > 2 * 1024 * 1024) + free_fastmemory (); + + memsize = allocated_chipmem = chipmem_full_size = currprefs.chipmem_size; + chipmem_full_mask = chipmem_mask = allocated_chipmem - 1; + if (memsize < 0x100000) + memsize = 0x100000; + if (memsize > 0x100000 && memsize < 0x200000) + memsize = 0x200000; + chipmemory = mapped_malloc (memsize, L"chip"); + if (chipmemory == 0) { + write_log (L"Fatal error: out of memory for chipmem.\n"); + allocated_chipmem = 0; + } else { + need_hardreset = 1; + if (memsize > allocated_chipmem) + memset (chipmemory + allocated_chipmem, 0xff, memsize - allocated_chipmem); + } + currprefs.chipset_mask = changed_prefs.chipset_mask; + chipmem_full_mask = allocated_chipmem - 1; + if (currprefs.chipset_mask & CSMASK_ECS_AGNUS) { + if (allocated_chipmem < 0x100000) + chipmem_full_mask = 0x100000 - 1; + if (allocated_chipmem > 0x100000 && allocated_chipmem < 0x200000) + chipmem_full_mask = chipmem_mask = 0x200000 - 1; + } } - } - if (allocated_bogomem != currprefs.bogomem_size) { - if (bogomemory_allocated) - mapped_free (bogomemory); - bogomemory = 0; - bogomemory_allocated = 0; - - allocated_bogomem = currprefs.bogomem_size; - if (allocated_bogomem == 0x180000) - allocated_bogomem = 0x200000; - bogomem_mask = allocated_bogomem - 1; - - if (allocated_bogomem) { - bogomemory = mapped_malloc (allocated_bogomem, L"bogo"); - if (bogomemory == 0) { - write_log (L"Out of memory for bogomem.\n"); - allocated_bogomem = 0; - } + if (allocated_bogomem != currprefs.bogomem_size) { + if (bogomemory_allocated) + mapped_free (bogomemory); + bogomemory = 0; + bogomemory_allocated = 0; + + allocated_bogomem = currprefs.bogomem_size; + if (allocated_bogomem == 0x180000) + allocated_bogomem = 0x200000; + bogomem_mask = allocated_bogomem - 1; + + if (allocated_bogomem) { + bogomemory = mapped_malloc (allocated_bogomem, L"bogo"); + if (bogomemory == 0) { + write_log (L"Out of memory for bogomem.\n"); + allocated_bogomem = 0; + } + } + need_hardreset = 1; } - need_hardreset = 1; - } - if (allocated_a3000lmem != currprefs.mbresmem_low_size) { - if (a3000lmemory) - mapped_free (a3000lmemory); - a3000lmemory = 0; - - allocated_a3000lmem = currprefs.mbresmem_low_size; - a3000lmem_mask = allocated_a3000lmem - 1; - a3000lmem_start = 0x08000000 - allocated_a3000lmem; - if (allocated_a3000lmem) { - a3000lmemory = mapped_malloc (allocated_a3000lmem, L"ramsey_low"); - if (a3000lmemory == 0) { - write_log (L"Out of memory for a3000lowmem.\n"); - allocated_a3000lmem = 0; - } + if (allocated_a3000lmem != currprefs.mbresmem_low_size) { + if (a3000lmemory) + mapped_free (a3000lmemory); + a3000lmemory = 0; + + allocated_a3000lmem = currprefs.mbresmem_low_size; + a3000lmem_mask = allocated_a3000lmem - 1; + a3000lmem_start = 0x08000000 - allocated_a3000lmem; + if (allocated_a3000lmem) { + a3000lmemory = mapped_malloc (allocated_a3000lmem, L"ramsey_low"); + if (a3000lmemory == 0) { + write_log (L"Out of memory for a3000lowmem.\n"); + allocated_a3000lmem = 0; + } + } + need_hardreset = 1; } - need_hardreset = 1; - } - if (allocated_a3000hmem != currprefs.mbresmem_high_size) { - if (a3000hmemory) - mapped_free (a3000hmemory); - a3000hmemory = 0; - - allocated_a3000hmem = currprefs.mbresmem_high_size; - a3000hmem_mask = allocated_a3000hmem - 1; - a3000hmem_start = 0x08000000; - if (allocated_a3000hmem) { - a3000hmemory = mapped_malloc (allocated_a3000hmem, L"ramsey_high"); - if (a3000hmemory == 0) { - write_log (L"Out of memory for a3000highmem.\n"); - allocated_a3000hmem = 0; - } + if (allocated_a3000hmem != currprefs.mbresmem_high_size) { + if (a3000hmemory) + mapped_free (a3000hmemory); + a3000hmemory = 0; + + allocated_a3000hmem = currprefs.mbresmem_high_size; + a3000hmem_mask = allocated_a3000hmem - 1; + a3000hmem_start = 0x08000000; + if (allocated_a3000hmem) { + a3000hmemory = mapped_malloc (allocated_a3000hmem, L"ramsey_high"); + if (a3000hmemory == 0) { + write_log (L"Out of memory for a3000highmem.\n"); + allocated_a3000hmem = 0; + } + } + need_hardreset = 1; } - need_hardreset = 1; - } - if (allocated_cardmem != currprefs.cs_cdtvcard * 1024) { - if (cardmemory) - mapped_free (cardmemory); - cardmemory = 0; - - allocated_cardmem = currprefs.cs_cdtvcard * 1024; - cardmem_mask = allocated_cardmem - 1; - if (allocated_cardmem) { - cardmemory = mapped_malloc (allocated_cardmem, L"rom_e0"); - if (cardmemory == 0) { - write_log (L"Out of memory for cardmem.\n"); - allocated_cardmem = 0; - } + if (allocated_cardmem != currprefs.cs_cdtvcard * 1024) { + if (cardmemory) + mapped_free (cardmemory); + cardmemory = 0; + + allocated_cardmem = currprefs.cs_cdtvcard * 1024; + cardmem_mask = allocated_cardmem - 1; + if (allocated_cardmem) { + cardmemory = mapped_malloc (allocated_cardmem, L"rom_e0"); + if (cardmemory == 0) { + write_log (L"Out of memory for cardmem.\n"); + allocated_cardmem = 0; + } + } + cdtv_loadcardmem(cardmemory, allocated_cardmem); } - cdtv_loadcardmem(cardmemory, allocated_cardmem); - } - if (allocated_custmem1 != currprefs.custom_memory_sizes[0]) { - if (custmem1) - mapped_free (custmem1); - custmem1 = 0; - allocated_custmem1 = currprefs.custom_memory_sizes[0]; - custmem1_mask = allocated_custmem1 - 1; - if (allocated_custmem1) { - custmem1 = mapped_malloc (allocated_custmem1, L"custmem1"); - if (!custmem1) - allocated_custmem1 = 0; + if (allocated_custmem1 != currprefs.custom_memory_sizes[0]) { + if (custmem1) + mapped_free (custmem1); + custmem1 = 0; + allocated_custmem1 = currprefs.custom_memory_sizes[0]; + custmem1_mask = allocated_custmem1 - 1; + if (allocated_custmem1) { + custmem1 = mapped_malloc (allocated_custmem1, L"custmem1"); + if (!custmem1) + allocated_custmem1 = 0; + } } - } - if (allocated_custmem2 != currprefs.custom_memory_sizes[1]) { - if (custmem2) - mapped_free (custmem2); - custmem2 = 0; - allocated_custmem2 = currprefs.custom_memory_sizes[1]; - custmem2_mask = allocated_custmem2 - 1; - if (allocated_custmem2) { - custmem2 = mapped_malloc (allocated_custmem2, L"custmem2"); - if (!custmem2) - allocated_custmem2 = 0; + if (allocated_custmem2 != currprefs.custom_memory_sizes[1]) { + if (custmem2) + mapped_free (custmem2); + custmem2 = 0; + allocated_custmem2 = currprefs.custom_memory_sizes[1]; + custmem2_mask = allocated_custmem2 - 1; + if (allocated_custmem2) { + custmem2 = mapped_malloc (allocated_custmem2, L"custmem2"); + if (!custmem2) + allocated_custmem2 = 0; + } } - } - if (savestate_state == STATE_RESTORE) { - if (bootrom_filepos) { - restore_ram (bootrom_filepos, rtarea); + if (savestate_state == STATE_RESTORE) { + if (bootrom_filepos) { + restore_ram (bootrom_filepos, rtarea); + } + restore_ram (chip_filepos, chipmemory); + if (allocated_bogomem > 0) + restore_ram (bogo_filepos, bogomemory); + if (allocated_a3000lmem > 0) + restore_ram (a3000lmem_filepos, a3000lmemory); + if (allocated_a3000hmem > 0) + restore_ram (a3000hmem_filepos, a3000hmemory); } - restore_ram (chip_filepos, chipmemory); - if (allocated_bogomem > 0) - restore_ram (bogo_filepos, bogomemory); - if (allocated_a3000lmem > 0) - restore_ram (a3000lmem_filepos, a3000lmemory); - if (allocated_a3000hmem > 0) - restore_ram (a3000hmem_filepos, a3000hmemory); - } - chipmem_bank.baseaddr = chipmemory; + chipmem_bank.baseaddr = chipmemory; #ifdef AGA - chipmem_bank_ce2.baseaddr = chipmemory; + chipmem_bank_ce2.baseaddr = chipmemory; #endif - bogomem_bank.baseaddr = bogomemory; - a3000lmem_bank.baseaddr = a3000lmemory; - a3000hmem_bank.baseaddr = a3000hmemory; - cardmem_bank.baseaddr = cardmemory; - bootrom_filepos = 0; - chip_filepos = 0; - bogo_filepos = 0; - a3000lmem_filepos = 0; - a3000hmem_filepos = 0; + bogomem_bank.baseaddr = bogomemory; + a3000lmem_bank.baseaddr = a3000lmemory; + a3000hmem_bank.baseaddr = a3000hmemory; + cardmem_bank.baseaddr = cardmemory; + bootrom_filepos = 0; + chip_filepos = 0; + bogo_filepos = 0; + a3000lmem_filepos = 0; + a3000hmem_filepos = 0; } static void fill_ce_banks (void) { - int i; - - memset (ce_banktype, CE_MEMBANK_FAST, 256); - if (&get_mem_bank (0) == &chipmem_bank) { - for (i = 0; i < (0x200000 >> 16); i++) - ce_banktype[i] = CE_MEMBANK_CHIP; - } - if (!currprefs.cs_slowmemisfast) { - for (i = (0xc00000 >> 16); i < (0xe00000 >> 16); i++) - ce_banktype[i] = CE_MEMBANK_CHIP; - } - for (i = (0xd00000 >> 16); i < (0xe00000 >> 16); i++) - ce_banktype[i] = CE_MEMBANK_CHIP; - for (i = (0xa00000 >> 16); i < (0xc00000 >> 16); i++) { - addrbank *b; - ce_banktype[i] = CE_MEMBANK_CIA; - b = &get_mem_bank (i << 16); - if (b != &cia_bank) - ce_banktype[i] = CE_MEMBANK_FAST; - } - // CD32 ROM is 16-bit - if (currprefs.cs_cd32cd) { - for (i = (0xe00000 >> 16); i < (0xe80000 >> 16); i++) - ce_banktype[i] = CE_MEMBANK_FAST16BIT; - for (i = (0xf80000 >> 16); i <= (0xff0000 >> 16); i++) - ce_banktype[i] = CE_MEMBANK_FAST16BIT; - } + int i; + + memset (ce_banktype, CE_MEMBANK_FAST, 256); + if (&get_mem_bank (0) == &chipmem_bank) { + for (i = 0; i < (0x200000 >> 16); i++) + ce_banktype[i] = CE_MEMBANK_CHIP; + } + if (!currprefs.cs_slowmemisfast) { + for (i = (0xc00000 >> 16); i < (0xe00000 >> 16); i++) + ce_banktype[i] = CE_MEMBANK_CHIP; + } + for (i = (0xd00000 >> 16); i < (0xe00000 >> 16); i++) + ce_banktype[i] = CE_MEMBANK_CHIP; + for (i = (0xa00000 >> 16); i < (0xc00000 >> 16); i++) { + addrbank *b; + ce_banktype[i] = CE_MEMBANK_CIA; + b = &get_mem_bank (i << 16); + if (b != &cia_bank) + ce_banktype[i] = CE_MEMBANK_FAST; + } + // CD32 ROM is 16-bit + if (currprefs.cs_cd32cd) { + for (i = (0xe00000 >> 16); i < (0xe80000 >> 16); i++) + ce_banktype[i] = CE_MEMBANK_FAST16BIT; + for (i = (0xf80000 >> 16); i <= (0xff0000 >> 16); i++) + ce_banktype[i] = CE_MEMBANK_FAST16BIT; + } } void map_overlay (int chip) { - int size; - addrbank *cb; + int size; + addrbank *cb; - size = allocated_chipmem >= 0x180000 ? (allocated_chipmem >> 16) : 32; - cb = &chipmem_bank; + size = allocated_chipmem >= 0x180000 ? (allocated_chipmem >> 16) : 32; + cb = &chipmem_bank; #ifdef AGA #if 0 - if (currprefs.cpu_cycle_exact && currprefs.cpu_model >= 68020) - cb = &chipmem_bank_ce2; + if (currprefs.cpu_cycle_exact && currprefs.cpu_model >= 68020) + cb = &chipmem_bank_ce2; #endif #endif - if (chip) { - map_banks (&dummy_bank, 0, 32, 0); - if (!isdirectjit ()) { - map_banks (cb, 0, size, allocated_chipmem); - if ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) && allocated_bogomem == 0) { - int start = allocated_chipmem >> 16; - if (allocated_chipmem < 0x100000) { - int dummy = (0x100000 - allocated_chipmem) >> 16; - map_banks (&chipmem_dummy_bank, start, dummy, 0); - map_banks (&chipmem_dummy_bank, start + 16, dummy, 0); - } else if (allocated_chipmem < 0x200000 && allocated_chipmem > 0x100000) { - int dummy = (0x200000 - allocated_chipmem) >> 16; - map_banks (&chipmem_dummy_bank, start, dummy, 0); + if (chip) { + map_banks (&dummy_bank, 0, 32, 0); + if (!isdirectjit ()) { + map_banks (cb, 0, size, allocated_chipmem); + if ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) && allocated_bogomem == 0) { + int start = allocated_chipmem >> 16; + if (allocated_chipmem < 0x100000) { + int dummy = (0x100000 - allocated_chipmem) >> 16; + map_banks (&chipmem_dummy_bank, start, dummy, 0); + map_banks (&chipmem_dummy_bank, start + 16, dummy, 0); + } else if (allocated_chipmem < 0x200000 && allocated_chipmem > 0x100000) { + int dummy = (0x200000 - allocated_chipmem) >> 16; + map_banks (&chipmem_dummy_bank, start, dummy, 0); + } + } + } else { + map_banks (cb, 0, allocated_chipmem >> 16, 0); } - } } else { - map_banks (cb, 0, allocated_chipmem >> 16, 0); + addrbank *rb = NULL; + if (size < 32) + size = 32; + cb = &get_mem_bank (0xf00000); + if (!rb && cb && (cb->flags & ABFLAG_ROM) && get_word (0xf00000) == 0x1114) + rb = cb; + cb = &get_mem_bank (0xe00000); + if (!rb && cb && (cb->flags & ABFLAG_ROM) && get_word (0xe00000) == 0x1114) + rb = cb; + if (!rb) + rb = &kickmem_bank; + map_banks (rb, 0, size, 0x80000); } - } else { - addrbank *rb = NULL; - if (size < 32) - size = 32; - cb = &get_mem_bank (0xf00000); - if (!rb && cb && (cb->flags & ABFLAG_ROM) && get_word (0xf00000) == 0x1114) - rb = cb; - cb = &get_mem_bank (0xe00000); - if (!rb && cb && (cb->flags & ABFLAG_ROM) && get_word (0xe00000) == 0x1114) - rb = cb; - if (!rb) - rb = &kickmem_bank; - map_banks (rb, 0, size, 0x80000); - } - fill_ce_banks (); - if (savestate_state != STATE_RESTORE && savestate_state != STATE_REWIND && valid_address (regs.pc, 4)) - m68k_setpc (m68k_getpc ()); + fill_ce_banks (); + if (savestate_state != STATE_RESTORE && savestate_state != STATE_REWIND && valid_address (regs.pc, 4)) + m68k_setpc (m68k_getpc ()); } void memory_reset (void) { - int bnk, bnk_end; - int gayle; - - be_cnt = 0; - currprefs.chipmem_size = changed_prefs.chipmem_size; - currprefs.bogomem_size = changed_prefs.bogomem_size; - currprefs.mbresmem_low_size = changed_prefs.mbresmem_low_size; - currprefs.mbresmem_high_size = changed_prefs.mbresmem_high_size; - currprefs.cs_ksmirror_e0 = changed_prefs.cs_ksmirror_e0; - currprefs.cs_ksmirror_a8 = changed_prefs.cs_ksmirror_a8; - currprefs.cs_ciaoverlay = changed_prefs.cs_ciaoverlay; - currprefs.cs_cdtvram = changed_prefs.cs_cdtvram; - currprefs.cs_cdtvcard = changed_prefs.cs_cdtvcard; - currprefs.cs_a1000ram = changed_prefs.cs_a1000ram; - currprefs.cs_ide = changed_prefs.cs_ide; - currprefs.cs_fatgaryrev = changed_prefs.cs_fatgaryrev; - currprefs.cs_ramseyrev = changed_prefs.cs_ramseyrev; - - gayle = (currprefs.chipset_mask & CSMASK_AGA) || currprefs.cs_pcmcia || currprefs.cs_ide > 0; - - need_hardreset = 0; - /* Use changed_prefs, as m68k_reset is called later. */ - if (last_address_space_24 != changed_prefs.address_space_24) - need_hardreset = 1; - - last_address_space_24 = changed_prefs.address_space_24; - - init_mem_banks (); - allocate_memory (); - - if (_tcscmp (currprefs.romfile, changed_prefs.romfile) != 0 - || _tcscmp (currprefs.romextfile, changed_prefs.romextfile) != 0) - { - write_log (L"ROM loader..\n"); - kickstart_rom = 1; - ersatzkickfile = 0; - a1000_handle_kickstart (0); - xfree (a1000_bootrom); - a1000_bootrom = 0; - a1000_kickstart_mode = 0; - - memcpy (currprefs.romfile, changed_prefs.romfile, sizeof currprefs.romfile); - memcpy (currprefs.romextfile, changed_prefs.romextfile, sizeof currprefs.romextfile); - need_hardreset = 1; - mapped_free (extendedkickmemory); - extendedkickmemory = 0; - extendedkickmem_size = 0; - extendedkickmemory2 = 0; - extendedkickmem2_size = 0; - extendedkickmem_type = 0; - load_extendedkickstart (); - kickmem_mask = 524288 - 1; - if (!load_kickstart ()) { - if (_tcslen (currprefs.romfile) > 0) { - write_log (L"Failed to open '%s'\n", currprefs.romfile); - notify_user (NUMSG_NOROM); - } + int bnk, bnk_end; + int gayle; + + be_cnt = 0; + currprefs.chipmem_size = changed_prefs.chipmem_size; + currprefs.bogomem_size = changed_prefs.bogomem_size; + currprefs.mbresmem_low_size = changed_prefs.mbresmem_low_size; + currprefs.mbresmem_high_size = changed_prefs.mbresmem_high_size; + currprefs.cs_ksmirror_e0 = changed_prefs.cs_ksmirror_e0; + currprefs.cs_ksmirror_a8 = changed_prefs.cs_ksmirror_a8; + currprefs.cs_ciaoverlay = changed_prefs.cs_ciaoverlay; + currprefs.cs_cdtvram = changed_prefs.cs_cdtvram; + currprefs.cs_cdtvcard = changed_prefs.cs_cdtvcard; + currprefs.cs_a1000ram = changed_prefs.cs_a1000ram; + currprefs.cs_ide = changed_prefs.cs_ide; + currprefs.cs_fatgaryrev = changed_prefs.cs_fatgaryrev; + currprefs.cs_ramseyrev = changed_prefs.cs_ramseyrev; + + gayle = (currprefs.chipset_mask & CSMASK_AGA) || currprefs.cs_pcmcia || currprefs.cs_ide > 0; + + need_hardreset = 0; + /* Use changed_prefs, as m68k_reset is called later. */ + if (last_address_space_24 != changed_prefs.address_space_24) + need_hardreset = 1; + + last_address_space_24 = changed_prefs.address_space_24; + + init_mem_banks (); + allocate_memory (); + + if (_tcscmp (currprefs.romfile, changed_prefs.romfile) != 0 + || _tcscmp (currprefs.romextfile, changed_prefs.romextfile) != 0) + { + write_log (L"ROM loader..\n"); + kickstart_rom = 1; + ersatzkickfile = 0; + a1000_handle_kickstart (0); + xfree (a1000_bootrom); + a1000_bootrom = 0; + a1000_kickstart_mode = 0; + + memcpy (currprefs.romfile, changed_prefs.romfile, sizeof currprefs.romfile); + memcpy (currprefs.romextfile, changed_prefs.romextfile, sizeof currprefs.romextfile); + need_hardreset = 1; + mapped_free (extendedkickmemory); + extendedkickmemory = 0; + extendedkickmem_size = 0; + extendedkickmemory2 = 0; + extendedkickmem2_size = 0; + extendedkickmem_type = 0; + load_extendedkickstart (); + kickmem_mask = 524288 - 1; + if (!load_kickstart ()) { + if (_tcslen (currprefs.romfile) > 0) { + write_log (L"Failed to open '%s'\n", currprefs.romfile); + notify_user (NUMSG_NOROM); + } #ifdef AUTOCONFIG - init_ersatz_rom (kickmemory); - kickmem_mask = 262144 - 1; - kickmem_size = 262144; - ersatzkickfile = 1; + init_ersatz_rom (kickmemory); + kickmem_mask = 262144 - 1; + kickmem_size = 262144; + ersatzkickfile = 1; #else - uae_restart (-1, NULL); + uae_restart (-1, NULL); #endif - } else { - struct romdata *rd = getromdatabydata (kickmemory, kickmem_size); - if (rd) { - write_log (L"Known ROM '%s' loaded\n", rd->name); - if ((rd->cpu & 3) == 3 && changed_prefs.cpu_model != 68030) { - notify_user (NUMSG_KS68030); - uae_restart (-1, NULL); - } else if ((rd->cpu & 3) == 1 && changed_prefs.cpu_model < 68020) { - notify_user (NUMSG_KS68EC020); - uae_restart (-1, NULL); - } else if ((rd->cpu & 3) == 2 && (changed_prefs.cpu_model < 68020 || changed_prefs.address_space_24)) { - notify_user (NUMSG_KS68020); - uae_restart (-1, NULL); + } else { + struct romdata *rd = getromdatabydata (kickmemory, kickmem_size); + if (rd) { + write_log (L"Known ROM '%s' loaded\n", rd->name); + if ((rd->cpu & 3) == 3 && changed_prefs.cpu_model != 68030) { + notify_user (NUMSG_KS68030); + uae_restart (-1, NULL); + } else if ((rd->cpu & 3) == 1 && changed_prefs.cpu_model < 68020) { + notify_user (NUMSG_KS68EC020); + uae_restart (-1, NULL); + } else if ((rd->cpu & 3) == 2 && (changed_prefs.cpu_model < 68020 || changed_prefs.address_space_24)) { + notify_user (NUMSG_KS68020); + uae_restart (-1, NULL); + } + if (rd->cloanto) + cloanto_rom = 1; + kickstart_rom = 0; + if ((rd->type & ROMTYPE_SPECIALKICK | ROMTYPE_KICK) == ROMTYPE_KICK) + kickstart_rom = 1; + if ((rd->cpu & 4) && currprefs.cs_compatible) { + /* A4000 ROM = need ramsey, gary and ide */ + if (currprefs.cs_ramseyrev < 0) + changed_prefs.cs_ramseyrev = currprefs.cs_ramseyrev = 0x0f; + changed_prefs.cs_fatgaryrev = currprefs.cs_fatgaryrev = 0; + if (currprefs.cs_ide != IDE_A4000) + changed_prefs.cs_ide = currprefs.cs_ide = -1; + } + } else { + write_log (L"Unknown ROM '%s' loaded\n", currprefs.romfile); + } } - if (rd->cloanto) - cloanto_rom = 1; - kickstart_rom = 0; - if ((rd->type & ROMTYPE_SPECIALKICK | ROMTYPE_KICK) == ROMTYPE_KICK) - kickstart_rom = 1; - if ((rd->cpu & 4) && currprefs.cs_compatible) { - /* A4000 ROM = need ramsey, gary and ide */ - if (currprefs.cs_ramseyrev < 0) - changed_prefs.cs_ramseyrev = currprefs.cs_ramseyrev = 0x0f; - changed_prefs.cs_fatgaryrev = currprefs.cs_fatgaryrev = 0; - if (currprefs.cs_ide != IDE_A4000) - changed_prefs.cs_ide = currprefs.cs_ide = -1; + patch_kick (); + write_log (L"ROM loader end\n"); + } + + if (cloanto_rom && currprefs.maprom < 0x01000000) + currprefs.maprom = changed_prefs.maprom = 0; + + gayle = currprefs.cs_ksmirror_a8 || currprefs.cs_pcmcia || currprefs.cs_ide > 0; + + map_banks (&custom_bank, 0xC0, 0xE0 - 0xC0, 0); + map_banks (&cia_bank, 0xA0, 32, 0); + if (!currprefs.cs_a1000ram) + /* D80000 - DDFFFF not mapped (A1000 = custom chips) */ + map_banks (&dummy_bank, 0xD8, 6, 0); + + /* map "nothing" to 0x200000 - 0x9FFFFF (0xBEFFFF if Gayle) */ + bnk = allocated_chipmem >> 16; + if (bnk < 0x20 + (currprefs.fastmem_size >> 16)) + bnk = 0x20 + (currprefs.fastmem_size >> 16); + bnk_end = gayle ? 0xBF : 0xA0; + map_banks (&dummy_bank, bnk, bnk_end - bnk, 0); + if (gayle) + map_banks (&dummy_bank, 0xc0, 0xd8 - 0xc0, 0); + + if (bogomemory != 0) { + int t = currprefs.bogomem_size >> 16; + if (t > 0x1C) + t = 0x1C; + if (t > 0x10 && ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_model >= 68020)) + t = 0x10; + map_banks (&bogomem_bank, 0xC0, t, 0); + } + if (currprefs.cs_ide || currprefs.cs_pcmcia) { + if (currprefs.cs_ide == IDE_A600A1200 || currprefs.cs_pcmcia) { + map_banks (&gayle_bank, 0xD8, 6, 0); + map_banks (&gayle2_bank, 0xDD, 2, 0); } - } else { - write_log (L"Unknown ROM '%s' loaded\n", currprefs.romfile); - } + gayle_map_pcmcia (); + if (currprefs.cs_ide == IDE_A4000 || currprefs.cs_mbdmac == 2) + map_banks (&gayle_bank, 0xDD, 1, 0); + if (currprefs.cs_ide < 0 && !currprefs.cs_pcmcia) + map_banks (&gayle_bank, 0xD8, 6, 0); + if (currprefs.cs_ide < 0) + map_banks (&gayle_bank, 0xDD, 1, 0); } - patch_kick (); - write_log (L"ROM loader end\n"); - } - - if (cloanto_rom && currprefs.maprom < 0x01000000) - currprefs.maprom = changed_prefs.maprom = 0; - - gayle = currprefs.cs_ksmirror_a8 || currprefs.cs_pcmcia || currprefs.cs_ide > 0; - - map_banks (&custom_bank, 0xC0, 0xE0 - 0xC0, 0); - map_banks (&cia_bank, 0xA0, 32, 0); - if (!currprefs.cs_a1000ram) - /* D80000 - DDFFFF not mapped (A1000 = custom chips) */ - map_banks (&dummy_bank, 0xD8, 6, 0); - - /* map "nothing" to 0x200000 - 0x9FFFFF (0xBEFFFF if Gayle) */ - bnk = allocated_chipmem >> 16; - if (bnk < 0x20 + (currprefs.fastmem_size >> 16)) - bnk = 0x20 + (currprefs.fastmem_size >> 16); - bnk_end = gayle ? 0xBF : 0xA0; - map_banks (&dummy_bank, bnk, bnk_end - bnk, 0); - if (gayle) - map_banks (&dummy_bank, 0xc0, 0xd8 - 0xc0, 0); - - if (bogomemory != 0) { - int t = currprefs.bogomem_size >> 16; - if (t > 0x1C) - t = 0x1C; - if (t > 0x10 && ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_model >= 68020)) - t = 0x10; - map_banks (&bogomem_bank, 0xC0, t, 0); - } - if (currprefs.cs_ide || currprefs.cs_pcmcia) { - if (currprefs.cs_ide == IDE_A600A1200 || currprefs.cs_pcmcia) { - map_banks (&gayle_bank, 0xD8, 6, 0); - map_banks (&gayle2_bank, 0xDD, 2, 0); + if (currprefs.cs_rtc || currprefs.cs_cdtvram) + map_banks (&clock_bank, 0xDC, 1, 0); + else if (currprefs.cs_ksmirror_a8 || currprefs.cs_ide > 0 || currprefs.cs_pcmcia) + map_banks (&clock_bank, 0xDC, 1, 0); /* none clock */ + if (currprefs.cs_fatgaryrev >= 0 || currprefs.cs_ramseyrev >= 0) + map_banks (&mbres_bank, 0xDE, 1, 0); + if (currprefs.cs_cd32c2p || currprefs.cs_cd32cd || currprefs.cs_cd32nvram) + map_banks (&akiko_bank, AKIKO_BASE >> 16, 1, 0); + if (currprefs.cs_mbdmac == 1) + a3000scsi_reset (); + + if (a3000lmemory != 0) + map_banks (&a3000lmem_bank, a3000lmem_start >> 16, allocated_a3000lmem >> 16, 0); + if (a3000hmemory != 0) + map_banks (&a3000hmem_bank, a3000hmem_start >> 16, allocated_a3000hmem >> 16, 0); + if (cardmemory != 0) + map_banks (&cardmem_bank, cardmem_start >> 16, allocated_cardmem >> 16, 0); + + map_banks (&kickmem_bank, 0xF8, 8, 0); + if (currprefs.maprom) + map_banks (&kickram_bank, currprefs.maprom >> 16, 8, 0); + /* map beta Kickstarts at 0x200000/0xC00000/0xF00000 */ + if (kickmemory[0] == 0x11 && kickmemory[2] == 0x4e && kickmemory[3] == 0xf9 && kickmemory[4] == 0x00) { + uae_u32 addr = kickmemory[5]; + if (addr == 0x20 && currprefs.chipmem_size <= 0x200000 && currprefs.fastmem_size == 0) + map_banks (&kickmem_bank, addr, 8, 0); + if (addr == 0xC0 && currprefs.bogomem_size == 0) + map_banks (&kickmem_bank, addr, 8, 0); + if (addr == 0xF0) + map_banks (&kickmem_bank, addr, 8, 0); } - gayle_map_pcmcia (); - if (currprefs.cs_ide == IDE_A4000 || currprefs.cs_mbdmac == 2) - map_banks (&gayle_bank, 0xDD, 1, 0); - if (currprefs.cs_ide < 0 && !currprefs.cs_pcmcia) - map_banks (&gayle_bank, 0xD8, 6, 0); - if (currprefs.cs_ide < 0) - map_banks (&gayle_bank, 0xDD, 1, 0); - } - if (currprefs.cs_rtc || currprefs.cs_cdtvram) - map_banks (&clock_bank, 0xDC, 1, 0); - else if (currprefs.cs_ksmirror_a8 || currprefs.cs_ide > 0 || currprefs.cs_pcmcia) - map_banks (&clock_bank, 0xDC, 1, 0); /* none clock */ - if (currprefs.cs_fatgaryrev >= 0 || currprefs.cs_ramseyrev >= 0) - map_banks (&mbres_bank, 0xDE, 1, 0); - if (currprefs.cs_cd32c2p || currprefs.cs_cd32cd || currprefs.cs_cd32nvram) - map_banks (&akiko_bank, AKIKO_BASE >> 16, 1, 0); - if (currprefs.cs_mbdmac == 1) - a3000scsi_reset (); - - if (a3000lmemory != 0) - map_banks (&a3000lmem_bank, a3000lmem_start >> 16, allocated_a3000lmem >> 16, 0); - if (a3000hmemory != 0) - map_banks (&a3000hmem_bank, a3000hmem_start >> 16, allocated_a3000hmem >> 16, 0); - if (cardmemory != 0) - map_banks (&cardmem_bank, cardmem_start >> 16, allocated_cardmem >> 16, 0); - - map_banks (&kickmem_bank, 0xF8, 8, 0); - if (currprefs.maprom) - map_banks (&kickram_bank, currprefs.maprom >> 16, 8, 0); - /* map beta Kickstarts at 0x200000/0xC00000/0xF00000 */ - if (kickmemory[0] == 0x11 && kickmemory[2] == 0x4e && kickmemory[3] == 0xf9 && kickmemory[4] == 0x00) { - uae_u32 addr = kickmemory[5]; - if (addr == 0x20 && currprefs.chipmem_size <= 0x200000 && currprefs.fastmem_size == 0) - map_banks (&kickmem_bank, addr, 8, 0); - if (addr == 0xC0 && currprefs.bogomem_size == 0) - map_banks (&kickmem_bank, addr, 8, 0); - if (addr == 0xF0) - map_banks (&kickmem_bank, addr, 8, 0); - } - - if (a1000_bootrom) - a1000_handle_kickstart (1); + + if (a1000_bootrom) + a1000_handle_kickstart (1); #ifdef AUTOCONFIG - map_banks (&expamem_bank, 0xE8, 1, 0); + map_banks (&expamem_bank, 0xE8, 1, 0); #endif - if (a3000_f0) - map_banks (&extendedkickmem_bank, 0xf0, 1, 0); + if (a3000_f0) + map_banks (&extendedkickmem_bank, 0xf0, 1, 0); - /* Map the chipmem into all of the lower 8MB */ - map_overlay (1); + /* Map the chipmem into all of the lower 8MB */ + map_overlay (1); - switch (extendedkickmem_type) { - case EXTENDED_ROM_KS: - map_banks (&extendedkickmem_bank, 0xE0, 8, 0); - break; + switch (extendedkickmem_type) { + case EXTENDED_ROM_KS: + map_banks (&extendedkickmem_bank, 0xE0, 8, 0); + break; #ifdef CDTV - case EXTENDED_ROM_CDTV: - map_banks (&extendedkickmem_bank, 0xF0, extendedkickmem_size == 2 * 524288 ? 16 : 8, 0); - break; + case EXTENDED_ROM_CDTV: + map_banks (&extendedkickmem_bank, 0xF0, extendedkickmem_size == 2 * 524288 ? 16 : 8, 0); + break; #endif #ifdef CD32 - case EXTENDED_ROM_CD32: - map_banks (&extendedkickmem_bank, 0xE0, 8, 0); - break; + case EXTENDED_ROM_CD32: + map_banks (&extendedkickmem_bank, 0xE0, 8, 0); + break; #endif - } + } #ifdef AUTOCONFIG - if (need_uae_boot_rom ()) - map_banks (&rtarea_bank, rtarea_base >> 16, 1, 0); + if (need_uae_boot_rom ()) + map_banks (&rtarea_bank, rtarea_base >> 16, 1, 0); #endif - if ((cloanto_rom || currprefs.cs_ksmirror_e0) && (currprefs.maprom != 0xe00000) && !extendedkickmem_type) - map_banks (&kickmem_bank, 0xE0, 8, 0); - if (currprefs.cs_ksmirror_a8) { - if (extendedkickmem2_size) { - map_banks (&extendedkickmem2_bank, 0xa8, 16, 0); - } else { - struct romdata *rd = getromdatabypath (currprefs.cartfile); - if (!rd || rd->id != 63) { - if (extendedkickmem_type == EXTENDED_ROM_CD32 || extendedkickmem_type == EXTENDED_ROM_KS) - map_banks (&extendedkickmem_bank, 0xb0, 8, 0); - else - map_banks (&kickmem_bank, 0xb0, 8, 0); - map_banks (&kickmem_bank, 0xa8, 8, 0); - } + if ((cloanto_rom || currprefs.cs_ksmirror_e0) && (currprefs.maprom != 0xe00000) && !extendedkickmem_type) + map_banks (&kickmem_bank, 0xE0, 8, 0); + if (currprefs.cs_ksmirror_a8) { + if (extendedkickmem2_size) { + map_banks (&extendedkickmem2_bank, 0xa8, 16, 0); + } else { + struct romdata *rd = getromdatabypath (currprefs.cartfile); + if (!rd || rd->id != 63) { + if (extendedkickmem_type == EXTENDED_ROM_CD32 || extendedkickmem_type == EXTENDED_ROM_KS) + map_banks (&extendedkickmem_bank, 0xb0, 8, 0); + else + map_banks (&kickmem_bank, 0xb0, 8, 0); + map_banks (&kickmem_bank, 0xa8, 8, 0); + } + } + } + + if (currprefs.custom_memory_sizes[0]) { + map_banks (&custmem1_bank, + currprefs.custom_memory_addrs[0] >> 16, + currprefs.custom_memory_sizes[0] >> 16, 0); + } + if (currprefs.custom_memory_sizes[1]) { + map_banks (&custmem2_bank, + currprefs.custom_memory_addrs[1] >> 16, + currprefs.custom_memory_sizes[1] >> 16, 0); } - } - - if (currprefs.custom_memory_sizes[0]) { - map_banks (&custmem1_bank, - currprefs.custom_memory_addrs[0] >> 16, - currprefs.custom_memory_sizes[0] >> 16, 0); - } - if (currprefs.custom_memory_sizes[1]) { - map_banks (&custmem2_bank, - currprefs.custom_memory_addrs[1] >> 16, - currprefs.custom_memory_sizes[1] >> 16, 0); - } #ifdef ARCADIA - if (is_arcadia_rom (currprefs.romextfile) == ARCADIA_BIOS) { - if (_tcscmp (currprefs.romextfile, changed_prefs.romextfile) != 0) - memcpy (currprefs.romextfile, changed_prefs.romextfile, sizeof currprefs.romextfile); - if (_tcscmp (currprefs.cartfile, changed_prefs.cartfile) != 0) - memcpy (currprefs.cartfile, changed_prefs.cartfile, sizeof currprefs.cartfile); - arcadia_unmap (); - is_arcadia_rom (currprefs.romextfile); - is_arcadia_rom (currprefs.cartfile); - arcadia_map_banks (); - } + if (is_arcadia_rom (currprefs.romextfile) == ARCADIA_BIOS) { + if (_tcscmp (currprefs.romextfile, changed_prefs.romextfile) != 0) + memcpy (currprefs.romextfile, changed_prefs.romextfile, sizeof currprefs.romextfile); + if (_tcscmp (currprefs.cartfile, changed_prefs.cartfile) != 0) + memcpy (currprefs.cartfile, changed_prefs.cartfile, sizeof currprefs.cartfile); + arcadia_unmap (); + is_arcadia_rom (currprefs.romextfile); + is_arcadia_rom (currprefs.cartfile); + arcadia_map_banks (); + } #endif #ifdef ACTION_REPLAY #ifdef ARCADIA - if (!arcadia_bios) { + if (!arcadia_bios) { #endif - action_replay_memory_reset (); + action_replay_memory_reset (); #ifdef ARCADIA - } + } #endif #endif - write_log (L"memory init end\n"); + write_log (L"memory init end\n"); } void memory_init (void) { - allocated_chipmem = 0; - allocated_bogomem = 0; - kickmemory = 0; - extendedkickmemory = 0; - extendedkickmem_size = 0; - extendedkickmemory2 = 0; - extendedkickmem2_size = 0; - extendedkickmem_type = 0; - chipmemory = 0; - allocated_a3000lmem = allocated_a3000hmem = 0; - a3000lmemory = a3000hmemory = 0; - bogomemory = 0; - cardmemory = 0; - custmem1 = 0; - custmem2 = 0; - - init_mem_banks (); - - kickmemory = mapped_malloc (0x80000, L"kick"); - memset (kickmemory, 0, 0x80000); - kickmem_bank.baseaddr = kickmemory; - _tcscpy (currprefs.romfile, L""); - currprefs.romextfile[0] = 0; + allocated_chipmem = 0; + allocated_bogomem = 0; + kickmemory = 0; + extendedkickmemory = 0; + extendedkickmem_size = 0; + extendedkickmemory2 = 0; + extendedkickmem2_size = 0; + extendedkickmem_type = 0; + chipmemory = 0; + allocated_a3000lmem = allocated_a3000hmem = 0; + a3000lmemory = a3000hmemory = 0; + bogomemory = 0; + cardmemory = 0; + custmem1 = 0; + custmem2 = 0; + + init_mem_banks (); + + kickmemory = mapped_malloc (0x80000, L"kick"); + memset (kickmemory, 0, 0x80000); + kickmem_bank.baseaddr = kickmemory; + _tcscpy (currprefs.romfile, L""); + currprefs.romextfile[0] = 0; #ifdef ACTION_REPLAY - action_replay_load(); - action_replay_init(1); + action_replay_load(); + action_replay_init(1); #ifdef ACTION_REPLAY_HRTMON - hrtmon_load(); + hrtmon_load(); #endif #endif } void memory_cleanup (void) { - if (a3000lmemory) - mapped_free (a3000lmemory); - if (a3000hmemory) - mapped_free (a3000hmemory); - if (bogomemory) - mapped_free (bogomemory); - if (kickmemory) - mapped_free (kickmemory); - if (a1000_bootrom) - xfree (a1000_bootrom); - if (chipmemory) - mapped_free (chipmemory); - if (cardmemory) { - cdtv_savecardmem (cardmemory, allocated_cardmem); - mapped_free (cardmemory); - } - if (custmem1) - mapped_free (custmem1); - if (custmem2) - mapped_free (custmem2); - - bogomemory = 0; - kickmemory = 0; - a3000lmemory = a3000hmemory = 0; - a1000_bootrom = 0; - a1000_kickstart_mode = 0; - chipmemory = 0; - cardmemory = 0; - custmem1 = 0; - custmem2 = 0; - - #ifdef ACTION_REPLAY - action_replay_cleanup(); - #endif - #ifdef ARCADIA - arcadia_unmap (); - #endif + if (a3000lmemory) + mapped_free (a3000lmemory); + if (a3000hmemory) + mapped_free (a3000hmemory); + if (bogomemory) + mapped_free (bogomemory); + if (kickmemory) + mapped_free (kickmemory); + if (a1000_bootrom) + xfree (a1000_bootrom); + if (chipmemory) + mapped_free (chipmemory); + if (cardmemory) { + cdtv_savecardmem (cardmemory, allocated_cardmem); + mapped_free (cardmemory); + } + if (custmem1) + mapped_free (custmem1); + if (custmem2) + mapped_free (custmem2); + + bogomemory = 0; + kickmemory = 0; + a3000lmemory = a3000hmemory = 0; + a1000_bootrom = 0; + a1000_kickstart_mode = 0; + chipmemory = 0; + cardmemory = 0; + custmem1 = 0; + custmem2 = 0; + +#ifdef ACTION_REPLAY + action_replay_cleanup(); +#endif +#ifdef ARCADIA + arcadia_unmap (); +#endif } void memory_hardreset (void) { - if (savestate_state == STATE_RESTORE) - return; - if (chipmemory) - memset (chipmemory, 0, allocated_chipmem); - if (bogomemory) - memset (bogomemory, 0, allocated_bogomem); - if (a3000lmemory) - memset (a3000lmemory, 0, allocated_a3000lmem); - if (a3000hmemory) - memset (a3000hmemory, 0, allocated_a3000hmem); - expansion_clear (); + if (savestate_state == STATE_RESTORE) + return; + if (chipmemory) + memset (chipmemory, 0, allocated_chipmem); + if (bogomemory) + memset (bogomemory, 0, allocated_bogomem); + if (a3000lmemory) + memset (a3000lmemory, 0, allocated_a3000lmem); + if (a3000hmemory) + memset (a3000hmemory, 0, allocated_a3000hmem); + expansion_clear (); } void map_banks (addrbank *bank, int start, int size, int realsize) { - int bnr, old; - unsigned long int hioffs = 0, endhioffs = 0x100; - addrbank *orgbank = bank; - uae_u32 realstart = start; + int bnr, old; + unsigned long int hioffs = 0, endhioffs = 0x100; + addrbank *orgbank = bank; + uae_u32 realstart = start; - //write_log (L"MAP_BANK %04X0000 %d %s\n", start, size, bank->name); + //write_log (L"MAP_BANK %04X0000 %d %s\n", start, size, bank->name); - old = debug_bankchange (-1); - flush_icache (0, 3); /* Sure don't want to keep any old mappings around! */ + old = debug_bankchange (-1); + flush_icache (0, 3); /* Sure don't want to keep any old mappings around! */ #ifdef NATMEM_OFFSET - delete_shmmaps (start << 16, size << 16); + delete_shmmaps (start << 16, size << 16); #endif - if (!realsize) - realsize = size << 16; + if (!realsize) + realsize = size << 16; - if ((size << 16) < realsize) { - write_log (L"Broken mapping, size=%x, realsize=%x\nStart is %x\n", - size, realsize, start); - } + if ((size << 16) < realsize) { + write_log (L"Broken mapping, size=%x, realsize=%x\nStart is %x\n", + size, realsize, start); + } #ifndef ADDRESS_SPACE_24BIT - if (start >= 0x100) { - int real_left = 0; - for (bnr = start; bnr < start + size; bnr++) { - if (!real_left) { - realstart = bnr; - real_left = realsize >> 16; + if (start >= 0x100) { + int real_left = 0; + for (bnr = start; bnr < start + size; bnr++) { + if (!real_left) { + realstart = bnr; + real_left = realsize >> 16; #ifdef NATMEM_OFFSET - add_shmmaps (realstart << 16, bank); + add_shmmaps (realstart << 16, bank); #endif - } - put_mem_bank (bnr << 16, bank, realstart << 16); - real_left--; + } + put_mem_bank (bnr << 16, bank, realstart << 16); + real_left--; + } + debug_bankchange (old); + return; } - debug_bankchange (old); - return; - } #endif - if (last_address_space_24) - endhioffs = 0x10000; + if (last_address_space_24) + endhioffs = 0x10000; #ifdef ADDRESS_SPACE_24BIT - endhioffs = 0x100; + endhioffs = 0x100; #endif - for (hioffs = 0; hioffs < endhioffs; hioffs += 0x100) { - int real_left = 0; - for (bnr = start; bnr < start + size; bnr++) { - if (!real_left) { - realstart = bnr + hioffs; - real_left = realsize >> 16; + for (hioffs = 0; hioffs < endhioffs; hioffs += 0x100) { + int real_left = 0; + for (bnr = start; bnr < start + size; bnr++) { + if (!real_left) { + realstart = bnr + hioffs; + real_left = realsize >> 16; #ifdef NATMEM_OFFSET - add_shmmaps (realstart << 16, bank); + add_shmmaps (realstart << 16, bank); #endif - } - put_mem_bank ((bnr + hioffs) << 16, bank, realstart << 16); - real_left--; + } + put_mem_bank ((bnr + hioffs) << 16, bank, realstart << 16); + real_left--; + } } - } - debug_bankchange (old); - fill_ce_banks (); + debug_bankchange (old); + fill_ce_banks (); } #ifdef SAVESTATE @@ -3885,190 +3885,190 @@ void map_banks (addrbank *bank, int start, int size, int realsize) uae_u8 *save_bootrom (int *len) { - if (!uae_boot_rom) - return 0; - *len = uae_boot_rom_size; - return rtarea; + if (!uae_boot_rom) + return 0; + *len = uae_boot_rom_size; + return rtarea; } uae_u8 *save_cram (int *len) { - *len = allocated_chipmem; - return chipmemory; + *len = allocated_chipmem; + return chipmemory; } uae_u8 *save_bram (int *len) { - *len = allocated_bogomem; - return bogomemory; + *len = allocated_bogomem; + return bogomemory; } uae_u8 *save_a3000lram (int *len) { - *len = allocated_a3000lmem; - return a3000lmemory; + *len = allocated_a3000lmem; + return a3000lmemory; } uae_u8 *save_a3000hram (int *len) { - *len = allocated_a3000hmem; - return a3000hmemory; + *len = allocated_a3000hmem; + return a3000hmemory; } void restore_bootrom (int len, size_t filepos) { - bootrom_filepos = filepos; + bootrom_filepos = filepos; } void restore_cram (int len, size_t filepos) { - chip_filepos = filepos; - changed_prefs.chipmem_size = len; + chip_filepos = filepos; + changed_prefs.chipmem_size = len; } void restore_bram (int len, size_t filepos) { - bogo_filepos = filepos; - changed_prefs.bogomem_size = len; + bogo_filepos = filepos; + changed_prefs.bogomem_size = len; } void restore_a3000lram (int len, size_t filepos) { - a3000lmem_filepos = filepos; - changed_prefs.mbresmem_low_size = len; + a3000lmem_filepos = filepos; + changed_prefs.mbresmem_low_size = len; } void restore_a3000hram (int len, size_t filepos) { - a3000hmem_filepos = filepos; - changed_prefs.mbresmem_high_size = len; + a3000hmem_filepos = filepos; + changed_prefs.mbresmem_high_size = len; } uae_u8 *restore_rom (uae_u8 *src) { - uae_u32 crc32, mem_start, mem_size, mem_type, version; - TCHAR *s, *romn; - int i, crcdet; - - mem_start = restore_u32 (); - mem_size = restore_u32 (); - mem_type = restore_u32 (); - version = restore_u32 (); - crc32 = restore_u32 (); - romn = restore_string (); - crcdet = 0; - for (i = 0; i < romlist_cnt; i++) { - if (rl[i].rd->crc32 == crc32 && crc32) { - if (zfile_exists (rl[i].path)) { - switch (mem_type) - { - case 0: - _tcsncpy (changed_prefs.romfile, rl[i].path, 255); - break; - case 1: - _tcsncpy (changed_prefs.romextfile, rl[i].path, 255); - break; + uae_u32 crc32, mem_start, mem_size, mem_type, version; + TCHAR *s, *romn; + int i, crcdet; + + mem_start = restore_u32 (); + mem_size = restore_u32 (); + mem_type = restore_u32 (); + version = restore_u32 (); + crc32 = restore_u32 (); + romn = restore_string (); + crcdet = 0; + for (i = 0; i < romlist_cnt; i++) { + if (rl[i].rd->crc32 == crc32 && crc32) { + if (zfile_exists (rl[i].path)) { + switch (mem_type) + { + case 0: + _tcsncpy (changed_prefs.romfile, rl[i].path, 255); + break; + case 1: + _tcsncpy (changed_prefs.romextfile, rl[i].path, 255); + break; + } + write_log (L"ROM '%s' = '%s'\n", romn, rl[i].path); + crcdet = 1; + } else { + write_log (L"ROM '%s' = '%s' invalid rom scanner path!", romn, rl[i].path); + } + break; } - write_log (L"ROM '%s' = '%s'\n", romn, rl[i].path); - crcdet = 1; - } else { - write_log (L"ROM '%s' = '%s' invalid rom scanner path!", romn, rl[i].path); - } - break; } - } - s = restore_string (); - if (!crcdet) { - if (zfile_exists (s)) { - switch (mem_type) - { - case 0: - _tcsncpy (changed_prefs.romfile, s, 255); - break; - case 1: - _tcsncpy (changed_prefs.romextfile, s, 255); - break; - } - write_log (L"ROM detected (path) as '%s'\n", s); - crcdet = 1; + s = restore_string (); + if (!crcdet) { + if (zfile_exists (s)) { + switch (mem_type) + { + case 0: + _tcsncpy (changed_prefs.romfile, s, 255); + break; + case 1: + _tcsncpy (changed_prefs.romextfile, s, 255); + break; + } + write_log (L"ROM detected (path) as '%s'\n", s); + crcdet = 1; + } } - } - xfree (s); - if (!crcdet) - write_log (L"WARNING: ROM '%s' not found!\n", romn); - xfree (romn); - return src; + xfree (s); + if (!crcdet) + write_log (L"WARNING: ROM '%s' not found!\n", romn); + xfree (romn); + return src; } uae_u8 *save_rom (int first, int *len, uae_u8 *dstptr) { - static int count; - uae_u8 *dst, *dstbak; - uae_u8 *mem_real_start; - uae_u32 version; - TCHAR *path; - int mem_start, mem_size, mem_type, saverom; - int i; - TCHAR tmpname[1000]; - - version = 0; - saverom = 0; - if (first) - count = 0; - for (;;) { - mem_type = count; - mem_size = 0; - switch (count) { - case 0: /* Kickstart ROM */ - mem_start = 0xf80000; - mem_real_start = kickmemory; - mem_size = kickmem_size; - path = currprefs.romfile; - /* 256KB or 512KB ROM? */ - for (i = 0; i < mem_size / 2 - 4; i++) { - if (longget (i + mem_start) != longget (i + mem_start + mem_size / 2)) - break; - } - if (i == mem_size / 2 - 4) { - mem_size /= 2; - mem_start += 262144; - } - version = longget (mem_start + 12); /* version+revision */ - _stprintf (tmpname, L"Kickstart %d.%d", wordget (mem_start + 12), wordget (mem_start + 14)); - break; - case 1: /* Extended ROM */ - if (!extendedkickmem_type) - break; - mem_start = extendedkickmem_start; - mem_real_start = extendedkickmemory; - mem_size = extendedkickmem_size; - path = currprefs.romextfile; - _stprintf (tmpname, L"Extended"); - break; - default: - return 0; + static int count; + uae_u8 *dst, *dstbak; + uae_u8 *mem_real_start; + uae_u32 version; + TCHAR *path; + int mem_start, mem_size, mem_type, saverom; + int i; + TCHAR tmpname[1000]; + + version = 0; + saverom = 0; + if (first) + count = 0; + for (;;) { + mem_type = count; + mem_size = 0; + switch (count) { + case 0: /* Kickstart ROM */ + mem_start = 0xf80000; + mem_real_start = kickmemory; + mem_size = kickmem_size; + path = currprefs.romfile; + /* 256KB or 512KB ROM? */ + for (i = 0; i < mem_size / 2 - 4; i++) { + if (longget (i + mem_start) != longget (i + mem_start + mem_size / 2)) + break; + } + if (i == mem_size / 2 - 4) { + mem_size /= 2; + mem_start += 262144; + } + version = longget (mem_start + 12); /* version+revision */ + _stprintf (tmpname, L"Kickstart %d.%d", wordget (mem_start + 12), wordget (mem_start + 14)); + break; + case 1: /* Extended ROM */ + if (!extendedkickmem_type) + break; + mem_start = extendedkickmem_start; + mem_real_start = extendedkickmemory; + mem_size = extendedkickmem_size; + path = currprefs.romextfile; + _stprintf (tmpname, L"Extended"); + break; + default: + return 0; + } + count++; + if (mem_size) + break; + } + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (4 + 4 + 4 + 4 + 4 + 256 + 256 + mem_size); + save_u32 (mem_start); + save_u32 (mem_size); + save_u32 (mem_type); + save_u32 (version); + save_u32 (get_crc32 (mem_real_start, mem_size)); + save_string (tmpname); + save_string (path); + if (saverom) { + for (i = 0; i < mem_size; i++) + *dst++ = byteget (mem_start + i); } - count++; - if (mem_size) - break; - } - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (4 + 4 + 4 + 4 + 4 + 256 + 256 + mem_size); - save_u32 (mem_start); - save_u32 (mem_size); - save_u32 (mem_type); - save_u32 (version); - save_u32 (get_crc32 (mem_real_start, mem_size)); - save_string (tmpname); - save_string (path); - if (saverom) { - for (i = 0; i < mem_size; i++) - *dst++ = byteget (mem_start + i); - } - *len = dst - dstbak; - return dstbak; + *len = dst - dstbak; + return dstbak; } #endif /* SAVESTATE */ @@ -4077,54 +4077,54 @@ uae_u8 *save_rom (int first, int *len, uae_u8 *dstptr) void memcpyha_safe (uaecptr dst, const uae_u8 *src, int size) { - if (!addr_valid (L"memcpyha", dst, size)) - return; - while (size--) - put_byte (dst++, *src++); + if (!addr_valid (L"memcpyha", dst, size)) + return; + while (size--) + put_byte (dst++, *src++); } void memcpyha (uaecptr dst, const uae_u8 *src, int size) { - while (size--) - put_byte (dst++, *src++); + while (size--) + put_byte (dst++, *src++); } void memcpyah_safe (uae_u8 *dst, uaecptr src, int size) { - if (!addr_valid (L"memcpyah", src, size)) - return; - while (size--) - *dst++ = get_byte (src++); + if (!addr_valid (L"memcpyah", src, size)) + return; + while (size--) + *dst++ = get_byte (src++); } void memcpyah (uae_u8 *dst, uaecptr src, int size) { - while (size--) - *dst++ = get_byte (src++); + while (size--) + *dst++ = get_byte (src++); } uae_char *strcpyah_safe (uae_char *dst, uaecptr src, int maxsize) { - uae_char *res = dst; - uae_u8 b; - do { - if (!addr_valid (L"_tcscpyah", src, 1)) - return res; - b = get_byte (src++); - *dst++ = b; - maxsize--; - if (maxsize <= 1) { - *dst++= 0; - break; - } - } while (b); - return res; + uae_char *res = dst; + uae_u8 b; + do { + if (!addr_valid (L"_tcscpyah", src, 1)) + return res; + b = get_byte (src++); + *dst++ = b; + maxsize--; + if (maxsize <= 1) { + *dst++= 0; + break; + } + } while (b); + return res; } uaecptr strcpyha_safe (uaecptr dst, const uae_char *src) { - uaecptr res = dst; - uae_u8 b; - do { - if (!addr_valid (L"_tcscpyha", dst, 1)) - return res; - b = *src++; - put_byte (dst++, b); - } while (b); - return res; + uaecptr res = dst; + uae_u8 b; + do { + if (!addr_valid (L"_tcscpyha", dst, 1)) + return res; + b = *src++; + put_byte (dst++, b); + } while (b); + return res; } diff --git a/missing.c b/missing.c index a16c490b..2c26668d 100644 --- a/missing.c +++ b/missing.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Various stuff missing in some OSes. - * - * Copyright 1997 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Various stuff missing in some OSes. +* +* Copyright 1997 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -15,27 +15,27 @@ TCHAR *my_strdup (const TCHAR *s) { - TCHAR *x = (char*)xmalloc(strlen((TCHAR *)s) + 1); - strcpy(x, (TCHAR *)s); - return x; + TCHAR *x = (char*)xmalloc(strlen((TCHAR *)s) + 1); + strcpy(x, (TCHAR *)s); + return x; } #endif void *xmalloc (size_t n) { - void *a = malloc (n); - return a; + void *a = malloc (n); + return a; } void *xcalloc (size_t n, size_t size) { - void *a = calloc (n, size); - return a; + void *a = calloc (n, size); + return a; } void xfree (const void *p) { - free (p); + free (p); } diff --git a/native2amiga.c b/native2amiga.c index dd07e03a..216d78da 100644 --- a/native2amiga.c +++ b/native2amiga.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Call Amiga Exec functions outside the main UAE thread. - * - * Copyright 1999 Patrick Ohly - * - * Uses the EXTER interrupt that is setup in filesys.c - * and needs thread support. - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Call Amiga Exec functions outside the main UAE thread. +* +* Copyright 1999 Patrick Ohly +* +* Uses the EXTER interrupt that is setup in filesys.c +* and needs thread support. +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -25,104 +25,104 @@ smp_comm_pipe native2amiga_pending; static uae_sem_t n2asem; /* - * to be called when setting up the hardware - */ +* to be called when setting up the hardware +*/ void native2amiga_install (void) { - init_comm_pipe (&native2amiga_pending, 100, 2); - uae_sem_init (&n2asem, 0, 1); + init_comm_pipe (&native2amiga_pending, 100, 2); + uae_sem_init (&n2asem, 0, 1); } void native2amiga_reset (void) { - smp_comm_pipe *p = &native2amiga_pending; - p->rdp = p->wrp = 0; - p->reader_waiting = 0; - p->writer_waiting = 0; + smp_comm_pipe *p = &native2amiga_pending; + p->rdp = p->wrp = 0; + p->reader_waiting = 0; + p->writer_waiting = 0; }; /* - * to be called when the Amiga boots, i.e. by filesys_diagentry() - */ +* to be called when the Amiga boots, i.e. by filesys_diagentry() +*/ void native2amiga_startup (void) { } int native2amiga_isfree (void) { - return comm_pipe_has_data (&native2amiga_pending) == 0; + return comm_pipe_has_data (&native2amiga_pending) == 0; } #ifdef SUPPORT_THREADS void uae_Cause (uaecptr interrupt) { - uae_sem_wait (&n2asem); - write_comm_pipe_int (&native2amiga_pending, 3, 0); - write_comm_pipe_u32 (&native2amiga_pending, interrupt, 1); - do_uae_int_requested (); - uae_sem_post (&n2asem); + uae_sem_wait (&n2asem); + write_comm_pipe_int (&native2amiga_pending, 3, 0); + write_comm_pipe_u32 (&native2amiga_pending, interrupt, 1); + do_uae_int_requested (); + uae_sem_post (&n2asem); } void uae_ReplyMsg (uaecptr msg) { - uae_sem_wait (&n2asem); - write_comm_pipe_int (&native2amiga_pending, 2, 0); - write_comm_pipe_u32 (&native2amiga_pending, msg, 1); - do_uae_int_requested (); - uae_sem_post (&n2asem); + uae_sem_wait (&n2asem); + write_comm_pipe_int (&native2amiga_pending, 2, 0); + write_comm_pipe_u32 (&native2amiga_pending, msg, 1); + do_uae_int_requested (); + uae_sem_post (&n2asem); } void uae_PutMsg (uaecptr port, uaecptr msg) { - uae_sem_wait (&n2asem); - write_comm_pipe_int (&native2amiga_pending, 1, 0); - write_comm_pipe_u32 (&native2amiga_pending, port, 0); - write_comm_pipe_u32 (&native2amiga_pending, msg, 1); - do_uae_int_requested (); - uae_sem_post (&n2asem); + uae_sem_wait (&n2asem); + write_comm_pipe_int (&native2amiga_pending, 1, 0); + write_comm_pipe_u32 (&native2amiga_pending, port, 0); + write_comm_pipe_u32 (&native2amiga_pending, msg, 1); + do_uae_int_requested (); + uae_sem_post (&n2asem); } void uae_Signal (uaecptr task, uae_u32 mask) { - uae_sem_wait (&n2asem); - write_comm_pipe_int (&native2amiga_pending, 0, 0); - write_comm_pipe_u32 (&native2amiga_pending, task, 0); - write_comm_pipe_int (&native2amiga_pending, mask, 1); - do_uae_int_requested (); - uae_sem_post (&n2asem); + uae_sem_wait (&n2asem); + write_comm_pipe_int (&native2amiga_pending, 0, 0); + write_comm_pipe_u32 (&native2amiga_pending, task, 0); + write_comm_pipe_int (&native2amiga_pending, mask, 1); + do_uae_int_requested (); + uae_sem_post (&n2asem); } void uae_NotificationHack (uaecptr port, uaecptr nr) { - uae_sem_wait (&n2asem); - write_comm_pipe_int (&native2amiga_pending, 4, 0); - write_comm_pipe_int (&native2amiga_pending, port, 0); - write_comm_pipe_int (&native2amiga_pending, nr, 1); - do_uae_int_requested (); - uae_sem_post (&n2asem); + uae_sem_wait (&n2asem); + write_comm_pipe_int (&native2amiga_pending, 4, 0); + write_comm_pipe_int (&native2amiga_pending, port, 0); + write_comm_pipe_int (&native2amiga_pending, nr, 1); + do_uae_int_requested (); + uae_sem_post (&n2asem); } #endif void uae_NewList (uaecptr list) { - put_long_slow (list, list + 4); - put_long_slow (list + 4, 0); - put_long_slow (list + 8, list); + put_long_slow (list, list + 4); + put_long_slow (list + 4, 0); + put_long_slow (list + 8, list); } uaecptr uae_AllocMem (TrapContext *context, uae_u32 size, uae_u32 flags) { - m68k_dreg (regs, 0) = size; - m68k_dreg (regs, 1) = flags; - return CallLib (context, get_long (4), -198); /* AllocMem */ + m68k_dreg (regs, 0) = size; + m68k_dreg (regs, 1) = flags; + return CallLib (context, get_long (4), -198); /* AllocMem */ } void uae_FreeMem (TrapContext *context, uaecptr memory, uae_u32 size) { - m68k_dreg (regs, 0) = size; - m68k_areg (regs, 1) = memory; - CallLib (context, get_long (4), -0xD2); /* FreeMem */ + m68k_dreg (regs, 0) = size; + m68k_areg (regs, 1) = memory; + CallLib (context, get_long (4), -0xD2); /* FreeMem */ } diff --git a/ncr_scsi.c b/ncr_scsi.c index 37969c29..f6c8453b 100644 --- a/ncr_scsi.c +++ b/ncr_scsi.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * A4000T NCR 53C710 SCSI (nothing done yet) - * - * (c) 2007 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* A4000T NCR 53C710 SCSI (nothing done yet) +* +* (c) 2007 Toni Wilen +*/ #define NCR_LOG 1 #define NCR_DEBUG 1 @@ -37,88 +37,88 @@ static uae_u8 acmemory[100]; static uae_u8 ncrregs[NCR_REGS]; struct ncrscsi { - TCHAR *name; - int be, le; + TCHAR *name; + int be, le; }; static struct ncrscsi regsinfo[] = { - L"SCNTL0", 0, 3, - L"SCNTL1", 1, 2, - L"SDID", 2, 1, - L"SIEN", 3, 0, - L"SCID", 4, 7, - L"SXFER", 5, 6, - L"SODL", 6, 5, - L"SOCL", 7, 4, - L"SFBR", 8, 11, - L"SIDL", 9, 10, - L"SBDL", 10, -1, - L"SBCL", 11, 8, - L"DSTAT", 12, 15, - L"SSTAT0", 13, 14, - L"SSTAT1", 14, 13, - L"SSTAT2", 15, 12, - L"DSA0", 16, 19, - L"DSA1", 17, 18, - L"DSA2", 18, 17, - L"DSA3", 19, 16, - L"CTEST0", 20, 23, - L"CTEST1", 21, 22, - L"CTEST2", 22, 21, - L"CTEST3", 23, 20, - L"CTEST4", 24, 27, - L"CTEST5", 25, 26, - L"CTEST6", 26, 25, - L"CTEST7", 27, 24, - L"TEMP0", 28, 31, - L"TEMP1", 29, 30, - L"TEMP2", 30, 29, - L"TEMP3", 31, 28, - L"DFIFO", 32, 35, - L"ISTAT", 33, 34, - L"CTEST8", 34, 33, - L"LCRC", 35, 32, - L"DBC0", 36, 39, - L"DBC1", 37, 38, - L"DBC2", 38, 37, - L"DCMD", 39, 36, - L"DNAD0", 40, 43, - L"DNAD1", 41, 42, - L"DNAD2", 42, 41, - L"DNAD3", 43, 40, - L"DSP0", 44, 47, - L"DSP1", 45, 46, - L"DSP2", 46, 45, - L"DSP3", 47, 44, - L"DSPS0", 48, 51, - L"DSPS1", 49, 50, - L"DSPS2", 50, 49, - L"DSPS3", 51, 48, - L"SCRATCH0", 52, 55, - L"SCRATCH1", 53, 54, - L"SCRATCH2", 54, 53, - L"SCRATCH3", 55, 52, - L"DMODE", 56, 59, - L"DIEN", 57, 58, - L"DWT", 58, 57, - L"DCNTL", 59, 56, - L"ADDER0", 60, 63, - L"ADDER1", 61, 62, - L"ADDER2", 62, 61, - L"ADDER3", 63, 60, - NULL + L"SCNTL0", 0, 3, + L"SCNTL1", 1, 2, + L"SDID", 2, 1, + L"SIEN", 3, 0, + L"SCID", 4, 7, + L"SXFER", 5, 6, + L"SODL", 6, 5, + L"SOCL", 7, 4, + L"SFBR", 8, 11, + L"SIDL", 9, 10, + L"SBDL", 10, -1, + L"SBCL", 11, 8, + L"DSTAT", 12, 15, + L"SSTAT0", 13, 14, + L"SSTAT1", 14, 13, + L"SSTAT2", 15, 12, + L"DSA0", 16, 19, + L"DSA1", 17, 18, + L"DSA2", 18, 17, + L"DSA3", 19, 16, + L"CTEST0", 20, 23, + L"CTEST1", 21, 22, + L"CTEST2", 22, 21, + L"CTEST3", 23, 20, + L"CTEST4", 24, 27, + L"CTEST5", 25, 26, + L"CTEST6", 26, 25, + L"CTEST7", 27, 24, + L"TEMP0", 28, 31, + L"TEMP1", 29, 30, + L"TEMP2", 30, 29, + L"TEMP3", 31, 28, + L"DFIFO", 32, 35, + L"ISTAT", 33, 34, + L"CTEST8", 34, 33, + L"LCRC", 35, 32, + L"DBC0", 36, 39, + L"DBC1", 37, 38, + L"DBC2", 38, 37, + L"DCMD", 39, 36, + L"DNAD0", 40, 43, + L"DNAD1", 41, 42, + L"DNAD2", 42, 41, + L"DNAD3", 43, 40, + L"DSP0", 44, 47, + L"DSP1", 45, 46, + L"DSP2", 46, 45, + L"DSP3", 47, 44, + L"DSPS0", 48, 51, + L"DSPS1", 49, 50, + L"DSPS2", 50, 49, + L"DSPS3", 51, 48, + L"SCRATCH0", 52, 55, + L"SCRATCH1", 53, 54, + L"SCRATCH2", 54, 53, + L"SCRATCH3", 55, 52, + L"DMODE", 56, 59, + L"DIEN", 57, 58, + L"DWT", 58, 57, + L"DCNTL", 59, 56, + L"ADDER0", 60, 63, + L"ADDER1", 61, 62, + L"ADDER2", 62, 61, + L"ADDER3", 63, 60, + NULL }; static TCHAR *regname (uaecptr addr) { - int i; + int i; - for (i = 0; regsinfo[i].name; i++) { - if (regsinfo[i].le == addr) - return regsinfo[i].name; - } - return L"?"; + for (i = 0; regsinfo[i].name; i++) { + if (regsinfo[i].le == addr) + return regsinfo[i].name; + } + return L"?"; } #define SCNTL0_REG 0x03 @@ -249,192 +249,192 @@ static TCHAR *regname (uaecptr addr) static void INT2(void) { - if (ncrregs[SIEN_REG] == 0) - return; - INTREQ (0x8000 | 0x0008); - write_log (L"IRQ\n"); + if (ncrregs[SIEN_REG] == 0) + return; + INTREQ (0x8000 | 0x0008); + write_log (L"IRQ\n"); } static uae_u8 read_rombyte (uaecptr addr) { - uae_u8 v = rom[addr]; - //write_log (L"%08X = %02X PC=%08X\n", addr, v, M68K_GETPC); - return v; + uae_u8 v = rom[addr]; + //write_log (L"%08X = %02X PC=%08X\n", addr, v, M68K_GETPC); + return v; } void ncr_bput2 (uaecptr addr, uae_u32 val) { - uae_u32 v = val; - addr &= board_mask; - if (addr >= NCR_REGS) - return; - switch (addr) - { + uae_u32 v = val; + addr &= board_mask; + if (addr >= NCR_REGS) + return; + switch (addr) + { case ISTAT_REG: - if (val & 0x80) - val |= 1; - val &= ~0x80; - INT2(); - break; - } - write_log (L"%s write %04X (%s) = %02X PC=%08X\n", NCRNAME, addr, regname(addr), v & 0xff, M68K_GETPC); - ncrregs[addr] = val; + if (val & 0x80) + val |= 1; + val &= ~0x80; + INT2(); + break; + } + write_log (L"%s write %04X (%s) = %02X PC=%08X\n", NCRNAME, addr, regname(addr), v & 0xff, M68K_GETPC); + ncrregs[addr] = val; } uae_u32 ncr_bget2 (uaecptr addr) { - uae_u32 v = 0, v2; - - addr &= board_mask; - if (rom && addr >= ROM_VECTOR && addr >= ROM_OFFSET) - return read_rombyte (addr); - if (addr >= NCR_REGS) - return v; - v2 = v = ncrregs[addr]; - switch (addr) - { + uae_u32 v = 0, v2; + + addr &= board_mask; + if (rom && addr >= ROM_VECTOR && addr >= ROM_OFFSET) + return read_rombyte (addr); + if (addr >= NCR_REGS) + return v; + v2 = v = ncrregs[addr]; + switch (addr) + { case ISTAT_REG: - v2 &= ~3; - break; + v2 &= ~3; + break; case SSTAT2_REG: - v &= ~7; - v |= ncrregs[SBCL_REG] & 7; - break; + v &= ~7; + v |= ncrregs[SBCL_REG] & 7; + break; case CTEST8_REG: - v &= 0x0f; // revision 0 - break; - } - write_log (L"%s read %04X (%s) = %02X PC=%08X\n", NCRNAME, addr, regname(addr), v, M68K_GETPC); - if (v2 != v) - ncrregs[addr] = v2; - return v; + v &= 0x0f; // revision 0 + break; + } + write_log (L"%s read %04X (%s) = %02X PC=%08X\n", NCRNAME, addr, regname(addr), v, M68K_GETPC); + if (v2 != v) + ncrregs[addr] = v2; + return v; } static addrbank ncr_bank; static uae_u32 REGPARAM2 ncr_lget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= 65535; - v = (ncr_bget2 (addr) << 24) | (ncr_bget2 (addr + 1) << 16) | - (ncr_bget2 (addr + 2) << 8) | (ncr_bget2 (addr + 3)); + addr &= 65535; + v = (ncr_bget2 (addr) << 24) | (ncr_bget2 (addr + 1) << 16) | + (ncr_bget2 (addr + 2) << 8) | (ncr_bget2 (addr + 3)); #if NCR_DEBUG > 0 - if (addr < ROM_VECTOR) - write_log (L"ncr_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); + if (addr < ROM_VECTOR) + write_log (L"ncr_lget %08X=%08X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 ncr_wget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= board_mask; - v = (ncr_bget2 (addr) << 8) | ncr_bget2 (addr + 1); + addr &= board_mask; + v = (ncr_bget2 (addr) << 8) | ncr_bget2 (addr + 1); #if NCR_DEBUG > 0 - if (addr < ROM_VECTOR) - write_log (L"ncr_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); + if (addr < ROM_VECTOR) + write_log (L"ncr_wget %08X=%04X PC=%08X\n", addr, v, M68K_GETPC); #endif - return v; + return v; } static uae_u32 REGPARAM2 ncr_bget (uaecptr addr) { - uae_u32 v; + uae_u32 v; #ifdef JIT - special_mem |= S_READ; + special_mem |= S_READ; #endif - addr &= board_mask; - if (!configured) { - if (addr >= sizeof acmemory) - return 0; - return acmemory[addr]; - } - v = ncr_bget2 (addr); - return v; + addr &= board_mask; + if (!configured) { + if (addr >= sizeof acmemory) + return 0; + return acmemory[addr]; + } + v = ncr_bget2 (addr); + return v; } static void REGPARAM2 ncr_lput (uaecptr addr, uae_u32 l) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - addr &= board_mask; + addr &= board_mask; #if NCR_DEBUG > 0 - if (addr < ROM_VECTOR) - write_log (L"ncr_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); + if (addr < ROM_VECTOR) + write_log (L"ncr_lput %08X=%08X PC=%08X\n", addr, l, M68K_GETPC); #endif - ncr_bput2 (addr, l >> 24); - ncr_bput2 (addr + 1, l >> 16); - ncr_bput2 (addr + 2, l >> 8); - ncr_bput2 (addr + 3, l); + ncr_bput2 (addr, l >> 24); + ncr_bput2 (addr + 1, l >> 16); + ncr_bput2 (addr + 2, l >> 8); + ncr_bput2 (addr + 3, l); } static void REGPARAM2 ncr_wput (uaecptr addr, uae_u32 w) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - w &= 0xffff; - addr &= board_mask; + w &= 0xffff; + addr &= board_mask; #if NCR_DEBUG > 0 - if (addr < ROM_VECTOR) - write_log (L"ncr_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); + if (addr < ROM_VECTOR) + write_log (L"ncr_wput %04X=%04X PC=%08X\n", addr, w & 65535, M68K_GETPC); #endif - if (addr == 0x44 && !configured) { - uae_u32 value = (p96ram_start + ((currprefs.gfxmem_size + 0xffffff) & ~0xffffff)) >> 16; - chipmem_wput (regs.regs[11] + 0x20, value); - chipmem_wput (regs.regs[11] + 0x28, value); - map_banks (&ncr_bank, value, BOARD_SIZE >> 16, 0); - write_log (L"A4091 Z3 autoconfigured at %04X0000\n", value); - configured = 1; - expamem_next(); - return; - } - ncr_bput2 (addr, w >> 8); - ncr_bput2 (addr + 1, w); + if (addr == 0x44 && !configured) { + uae_u32 value = (p96ram_start + ((currprefs.gfxmem_size + 0xffffff) & ~0xffffff)) >> 16; + chipmem_wput (regs.regs[11] + 0x20, value); + chipmem_wput (regs.regs[11] + 0x28, value); + map_banks (&ncr_bank, value, BOARD_SIZE >> 16, 0); + write_log (L"A4091 Z3 autoconfigured at %04X0000\n", value); + configured = 1; + expamem_next(); + return; + } + ncr_bput2 (addr, w >> 8); + ncr_bput2 (addr + 1, w); } static void REGPARAM2 ncr_bput (uaecptr addr, uae_u32 b) { #ifdef JIT - special_mem |= S_WRITE; + special_mem |= S_WRITE; #endif - b &= 0xff; - addr &= board_mask; - if (addr == 0x4c && !configured) { - write_log (L"A4091 AUTOCONFIG SHUT-UP!\n"); - configured = 1; - expamem_next(); - return; - } - if (!configured) - return; - ncr_bput2 (addr, b); + b &= 0xff; + addr &= board_mask; + if (addr == 0x4c && !configured) { + write_log (L"A4091 AUTOCONFIG SHUT-UP!\n"); + configured = 1; + expamem_next(); + return; + } + if (!configured) + return; + ncr_bput2 (addr, b); } static addrbank ncr_bank = { - ncr_lget, ncr_wget, ncr_bget, - ncr_lput, ncr_wput, ncr_bput, - default_xlate, default_check, NULL, L"A4091", - dummy_lgeti, dummy_wgeti, ABFLAG_IO + ncr_lget, ncr_wget, ncr_bget, + ncr_lput, ncr_wput, ncr_bput, + default_xlate, default_check, NULL, L"A4091", + dummy_lgeti, dummy_wgeti, ABFLAG_IO }; static void ew (int addr, uae_u32 value) { - if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { - acmemory[addr] = (value & 0xf0); - acmemory[addr + 2] = (value & 0x0f) << 4; - } else { - acmemory[addr] = ~(value & 0xf0); - acmemory[addr + 2] = ~((value & 0x0f) << 4); - } + if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { + acmemory[addr] = (value & 0xf0); + acmemory[addr + 2] = (value & 0x0f) << 4; + } else { + acmemory[addr] = ~(value & 0xf0); + acmemory[addr + 2] = ~((value & 0x0f) << 4); + } } void ncr_free (void) @@ -443,62 +443,62 @@ void ncr_free (void) void ncr_reset (void) { - board_mask = 131072 - 1; - configured = 0; - if (currprefs.cs_mbdmac == 2) { - board_mask = 65535 - 1; - configured = -1; - } + board_mask = 131072 - 1; + configured = 0; + if (currprefs.cs_mbdmac == 2) { + board_mask = 65535 - 1; + configured = -1; + } } void ncr_init (void) { - struct zfile *z; - int roms[3]; - struct romlist *rl; - int i; - - configured = 0; - memset (acmemory, 0xff, 100); - ew (0x00, 0x80 | 0x10 | 0x00); - ew (0x08, 0x80 | 0x20 | 0x10); - - /* A4091 hardware id */ - ew (0x04, 0x54); - /* commodore's manufacturer id */ - ew (0x10, 0x02); - ew (0x14, 0x02); - /* rom vector */ - ew (0x28, ROM_VECTOR >> 8); - ew (0x2c, ROM_VECTOR); - - ew (0x18, 0x00); /* ser.no. Byte 0 */ - ew (0x1c, 0x00); /* ser.no. Byte 1 */ - ew (0x20, 0x00); /* ser.no. Byte 2 */ - ew (0x24, 0x00); /* ser.no. Byte 3 */ - - roms[0] = 58; - roms[1] = 57; - roms[2] = -1; - - rl = getromlistbyids(roms); - if (rl) { - struct romdata *rd = rl->rd; - z = read_rom (&rd); - if (z) { - write_log (L"A4091 BOOT ROM %d.%d\n", rd->ver, rd->rev); - rom = (uae_u8*)xmalloc (ROM_SIZE * 4); - for (i = 0; i < ROM_SIZE; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - rom[i * 4 + 0] = b; - rom[i * 4 + 2] = b << 4; - } - zfile_fclose(z); + struct zfile *z; + int roms[3]; + struct romlist *rl; + int i; + + configured = 0; + memset (acmemory, 0xff, 100); + ew (0x00, 0x80 | 0x10 | 0x00); + ew (0x08, 0x80 | 0x20 | 0x10); + + /* A4091 hardware id */ + ew (0x04, 0x54); + /* commodore's manufacturer id */ + ew (0x10, 0x02); + ew (0x14, 0x02); + /* rom vector */ + ew (0x28, ROM_VECTOR >> 8); + ew (0x2c, ROM_VECTOR); + + ew (0x18, 0x00); /* ser.no. Byte 0 */ + ew (0x1c, 0x00); /* ser.no. Byte 1 */ + ew (0x20, 0x00); /* ser.no. Byte 2 */ + ew (0x24, 0x00); /* ser.no. Byte 3 */ + + roms[0] = 58; + roms[1] = 57; + roms[2] = -1; + + rl = getromlistbyids(roms); + if (rl) { + struct romdata *rd = rl->rd; + z = read_rom (&rd); + if (z) { + write_log (L"A4091 BOOT ROM %d.%d\n", rd->ver, rd->rev); + rom = (uae_u8*)xmalloc (ROM_SIZE * 4); + for (i = 0; i < ROM_SIZE; i++) { + uae_u8 b; + zfile_fread(&b, 1, 1, z); + rom[i * 4 + 0] = b; + rom[i * 4 + 2] = b << 4; + } + zfile_fclose(z); + } + } else { + romwarning(roms); } - } else { - romwarning(roms); - } - map_banks (&ncr_bank, 0xe80000 >> 16, 65536 >> 16, 0); + map_banks (&ncr_bank, 0xe80000 >> 16, 65536 >> 16, 0); } diff --git a/newcpu.c b/newcpu.c index 1a272b06..204189ad 100644 --- a/newcpu.c +++ b/newcpu.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * MC68000 emulation - * - * (c) 1995 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* MC68000 emulation +* +* (c) 1995 Bernd Schmidt +*/ #define MOVEC_DEBUG 0 #define MMUOP_DEBUG 2 @@ -57,7 +57,8 @@ unsigned long irqcycles[15]; int irqdelay[15]; int mmu_enabled, mmu_triggered; int cpu_cycles; -static int baseclock, cpucycleunit; +static int baseclock; +int cpucycleunit; const int areg_byteinc[] = { 1, 1, 1, 1, 1, 1, 1, 2 }; const int imm8_table[] = { 8, 1, 2, 3, 4, 5, 6, 7 }; @@ -89,43 +90,43 @@ static uae_u16 opcodenums[65536]; static int compfn (const void *el1, const void *el2) { - return instrcount[*(const uae_u16 *)el1] < instrcount[*(const uae_u16 *)el2]; + return instrcount[*(const uae_u16 *)el1] < instrcount[*(const uae_u16 *)el2]; } static TCHAR *icountfilename (void) { - TCHAR *name = getenv ("INSNCOUNT"); - if (name) - return name; - return COUNT_INSTRS == 2 ? "frequent.68k" : "insncount"; + TCHAR *name = getenv ("INSNCOUNT"); + if (name) + return name; + return COUNT_INSTRS == 2 ? "frequent.68k" : "insncount"; } void dump_counts (void) { - FILE *f = fopen (icountfilename (), "w"); - unsigned long int total; - int i; - - write_log (L"Writing instruction count file...\n"); - for (i = 0; i < 65536; i++) { - opcodenums[i] = i; - total += instrcount[i]; - } - qsort (opcodenums, 65536, sizeof (uae_u16), compfn); - - fprintf (f, "Total: %lu\n", total); - for (i=0; i < 65536; i++) { - unsigned long int cnt = instrcount[opcodenums[i]]; - struct instr *dp; - struct mnemolookup *lookup; - if (!cnt) - break; - dp = table68k + opcodenums[i]; - for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) - ; - fprintf (f, "%04x: %lu %s\n", opcodenums[i], cnt, lookup->name); - } - fclose (f); + FILE *f = fopen (icountfilename (), "w"); + unsigned long int total; + int i; + + write_log (L"Writing instruction count file...\n"); + for (i = 0; i < 65536; i++) { + opcodenums[i] = i; + total += instrcount[i]; + } + qsort (opcodenums, 65536, sizeof (uae_u16), compfn); + + fprintf (f, "Total: %lu\n", total); + for (i=0; i < 65536; i++) { + unsigned long int cnt = instrcount[opcodenums[i]]; + struct instr *dp; + struct mnemolookup *lookup; + if (!cnt) + break; + dp = table68k + opcodenums[i]; + for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) + ; + fprintf (f, "%04x: %lu %s\n", opcodenums[i], cnt, lookup->name); + } + fclose (f); } #else void dump_counts (void) @@ -135,41 +136,41 @@ void dump_counts (void) static void set_cpu_caches (void) { - int i, j; + int i, j; - if (currprefs.cpu_model < 68040) { - if (regs.cacr & 0x08) { // Clear Cache - for (i = 0; i < CACHELINES020; i++) - caches020[i].valid = 0; - regs.prefetch020addr = 0xff000000; - } - if (regs.cacr & 0x04) { // Clear Entry - caches020[(regs.caar >> 2) & 0x3f].valid = 0; - regs.cacr &= ~0x04; - } + if (currprefs.cpu_model < 68040) { + if (regs.cacr & 0x08) { // Clear Cache + for (i = 0; i < CACHELINES020; i++) + caches020[i].valid = 0; + regs.prefetch020addr = 0xff000000; + } + if (regs.cacr & 0x04) { // Clear Entry + caches020[(regs.caar >> 2) & 0x3f].valid = 0; + regs.cacr &= ~0x04; + } #ifdef JIT - set_cache_state (regs.cacr & 1); - if (regs.cacr & 0x08) { - flush_icache (0, 3); - } + set_cache_state (regs.cacr & 1); + if (regs.cacr & 0x08) { + flush_icache (0, 3); + } #endif - regs.cacr &= ~0x08; - } else { + regs.cacr &= ~0x08; + } else { #ifdef JIT - set_cache_state ((regs.cacr & 0x8000) ? 1 : 0); + set_cache_state ((regs.cacr & 0x8000) ? 1 : 0); #endif - if (!(regs.cacr & 0x8000)) { - for (i = 0; i < CACHESETS040; i++) { - for (j = 0; j < CACHELINES040; j++) { - caches040[i].cs[j].valid[0] = 0; - caches040[i].cs[j].valid[1] = 0; - caches040[i].cs[j].valid[2] = 0; - caches040[i].cs[j].valid[3] = 0; + if (!(regs.cacr & 0x8000)) { + for (i = 0; i < CACHESETS040; i++) { + for (j = 0; j < CACHELINES040; j++) { + caches040[i].cs[j].valid[0] = 0; + caches040[i].cs[j].valid[1] = 0; + caches040[i].cs[j].valid[2] = 0; + caches040[i].cs[j].valid[3] = 0; + } + } + regs.prefetch020addr = 0xff000000; } - } - regs.prefetch020addr = 0xff000000; } - } } STATIC_INLINE void count_instr (unsigned int opcode) @@ -180,147 +181,147 @@ static unsigned long REGPARAM3 op_illg_1 (uae_u32 opcode) REGPARAM; static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode) { - op_illg (opcode); - return 4; + op_illg (opcode); + return 4; } static void build_cpufunctbl (void) { - int i, opcnt; - unsigned long opcode; - const struct cputbl *tbl = 0; - int lvl; + int i, opcnt; + unsigned long opcode; + const struct cputbl *tbl = 0; + int lvl; - switch (currprefs.cpu_model) - { + switch (currprefs.cpu_model) + { #ifdef CPUEMU_0 #ifndef CPUEMU_68000_ONLY case 68060: - lvl = 5; - tbl = op_smalltbl_0_ff; - if (currprefs.cpu_cycle_exact) - tbl = op_smalltbl_20_ff; - if (currprefs.mmu_model) - tbl = op_smalltbl_31_ff; - break; + lvl = 5; + tbl = op_smalltbl_0_ff; + if (currprefs.cpu_cycle_exact) + tbl = op_smalltbl_20_ff; + if (currprefs.mmu_model) + tbl = op_smalltbl_31_ff; + break; case 68040: - lvl = 4; - tbl = op_smalltbl_1_ff; - if (currprefs.cpu_cycle_exact) - tbl = op_smalltbl_21_ff; - if (currprefs.mmu_model) - tbl = op_smalltbl_31_ff; - break; + lvl = 4; + tbl = op_smalltbl_1_ff; + if (currprefs.cpu_cycle_exact) + tbl = op_smalltbl_21_ff; + if (currprefs.mmu_model) + tbl = op_smalltbl_31_ff; + break; case 68030: - lvl = 3; - tbl = op_smalltbl_2_ff; - if (currprefs.cpu_cycle_exact) - tbl = op_smalltbl_22_ff; - break; + lvl = 3; + tbl = op_smalltbl_2_ff; + if (currprefs.cpu_cycle_exact) + tbl = op_smalltbl_22_ff; + break; case 68020: - lvl = 2; - tbl = op_smalltbl_3_ff; - if (currprefs.cpu_cycle_exact) - tbl = op_smalltbl_23_ff; - break; + lvl = 2; + tbl = op_smalltbl_3_ff; + if (currprefs.cpu_cycle_exact) + tbl = op_smalltbl_23_ff; + break; case 68010: - lvl = 1; - tbl = op_smalltbl_4_ff; - break; + lvl = 1; + tbl = op_smalltbl_4_ff; + break; #endif #endif default: - changed_prefs.cpu_model = currprefs.cpu_model = 68000; + changed_prefs.cpu_model = currprefs.cpu_model = 68000; case 68000: - lvl = 0; - tbl = op_smalltbl_5_ff; + lvl = 0; + tbl = op_smalltbl_5_ff; #ifdef CPUEMU_11 - if (currprefs.cpu_compatible) - tbl = op_smalltbl_11_ff; /* prefetch */ + if (currprefs.cpu_compatible) + tbl = op_smalltbl_11_ff; /* prefetch */ #endif #ifdef CPUEMU_12 - if (currprefs.cpu_cycle_exact) - tbl = op_smalltbl_12_ff; /* prefetch and cycle-exact */ + if (currprefs.cpu_cycle_exact) + tbl = op_smalltbl_12_ff; /* prefetch and cycle-exact */ #endif - break; - } - - if (tbl == 0) { - write_log (L"no CPU emulation cores available CPU=%d!", currprefs.cpu_model); - abort (); - } - - for (opcode = 0; opcode < 65536; opcode++) - cpufunctbl[opcode] = op_illg_1; - for (i = 0; tbl[i].handler != NULL; i++) { - opcode = tbl[i].opcode; - cpufunctbl[opcode] = tbl[i].handler; - } - - /* hack fpu to 68000/68010 mode */ - if (currprefs.fpu_model && currprefs.cpu_model < 68020) { - tbl = op_smalltbl_3_ff; + break; + } + + if (tbl == 0) { + write_log (L"no CPU emulation cores available CPU=%d!", currprefs.cpu_model); + abort (); + } + + for (opcode = 0; opcode < 65536; opcode++) + cpufunctbl[opcode] = op_illg_1; for (i = 0; tbl[i].handler != NULL; i++) { - if ((tbl[i].opcode & 0xfe00) == 0xf200) - cpufunctbl[tbl[i].opcode] = tbl[i].handler; + opcode = tbl[i].opcode; + cpufunctbl[opcode] = tbl[i].handler; } - } - opcnt = 0; - for (opcode = 0; opcode < 65536; opcode++) { - cpuop_func *f; - if (table68k[opcode].mnemo == i_ILLG) - continue; + /* hack fpu to 68000/68010 mode */ if (currprefs.fpu_model && currprefs.cpu_model < 68020) { - /* more hack fpu to 68000/68010 mode */ - if (table68k[opcode].clev > lvl && (opcode & 0xfe00) != 0xf200) - continue; - } else if (table68k[opcode].clev > lvl) { - continue; + tbl = op_smalltbl_3_ff; + for (i = 0; tbl[i].handler != NULL; i++) { + if ((tbl[i].opcode & 0xfe00) == 0xf200) + cpufunctbl[tbl[i].opcode] = tbl[i].handler; + } } + opcnt = 0; + for (opcode = 0; opcode < 65536; opcode++) { + cpuop_func *f; + + if (table68k[opcode].mnemo == i_ILLG) + continue; + if (currprefs.fpu_model && currprefs.cpu_model < 68020) { + /* more hack fpu to 68000/68010 mode */ + if (table68k[opcode].clev > lvl && (opcode & 0xfe00) != 0xf200) + continue; + } else if (table68k[opcode].clev > lvl) { + continue; + } - if (table68k[opcode].handler != -1) { - int idx = table68k[opcode].handler; - f = cpufunctbl[idx]; - if (f == op_illg_1) - abort (); - cpufunctbl[opcode] = f; - opcnt++; - } - } - write_log (L"Building CPU, %d opcodes (%d %d %d)\n", - opcnt, lvl, - currprefs.cpu_cycle_exact ? -1 : currprefs.cpu_compatible ? 1 : 0, currprefs.address_space_24); - write_log (L"CPU=%d, FPU=%d, MMU=%d, JIT%s=%d.\n", - currprefs.cpu_model, currprefs.fpu_model, - currprefs.mmu_model, - currprefs.cachesize ? (currprefs.compfpu ? L"=CPU/FPU" : L"=CPU") : L"", - currprefs.cachesize); + if (table68k[opcode].handler != -1) { + int idx = table68k[opcode].handler; + f = cpufunctbl[idx]; + if (f == op_illg_1) + abort (); + cpufunctbl[opcode] = f; + opcnt++; + } + } + write_log (L"Building CPU, %d opcodes (%d %d %d)\n", + opcnt, lvl, + currprefs.cpu_cycle_exact ? -1 : currprefs.cpu_compatible ? 1 : 0, currprefs.address_space_24); + write_log (L"CPU=%d, FPU=%d, MMU=%d, JIT%s=%d.\n", + currprefs.cpu_model, currprefs.fpu_model, + currprefs.mmu_model, + currprefs.cachesize ? (currprefs.compfpu ? L"=CPU/FPU" : L"=CPU") : L"", + currprefs.cachesize); #ifdef JIT - build_comp (); + build_comp (); #endif - set_cpu_caches (); - if (currprefs.mmu_model) { - mmu_reset (); - mmu_set_tc (regs.tcr); - mmu_set_super (regs.s); - } + set_cpu_caches (); + if (currprefs.mmu_model) { + mmu_reset (); + mmu_set_tc (regs.tcr); + mmu_set_super (regs.s); + } } void fill_prefetch_slow (void) { - if (currprefs.mmu_model) - return; + if (currprefs.mmu_model) + return; #ifdef CPUEMU_12 - if (currprefs.cpu_cycle_exact) { - regs.ir = get_word_ce (m68k_getpc ()); - regs.irc = get_word_ce (m68k_getpc () + 2); - } else { + if (currprefs.cpu_cycle_exact) { + regs.ir = get_word_ce (m68k_getpc ()); + regs.irc = get_word_ce (m68k_getpc () + 2); + } else { #endif - regs.ir = get_word (m68k_getpc ()); - regs.irc = get_word (m68k_getpc () + 2); + regs.ir = get_word (m68k_getpc ()); + regs.irc = get_word (m68k_getpc () + 2); #ifdef CPUEMU_12 - } + } #endif } @@ -328,145 +329,145 @@ unsigned long cycles_mask, cycles_val; static void update_68k_cycles (void) { - cycles_mask = 0; - cycles_val = currprefs.m68k_speed; - if (currprefs.m68k_speed < 1) { - cycles_mask = 0xFFFFFFFF; - cycles_val = 0; - } - currprefs.cpu_clock_multiplier = changed_prefs.cpu_clock_multiplier; - currprefs.cpu_frequency = changed_prefs.cpu_frequency; - - baseclock = currprefs.ntscmode ? 28636360 : 28375160; - cpucycleunit = CYCLE_UNIT / 2; - if (currprefs.cpu_clock_multiplier) { - if (currprefs.cpu_clock_multiplier >= 256) { - cpucycleunit = CYCLE_UNIT / (currprefs.cpu_clock_multiplier >> 8); - } else { - cpucycleunit = CYCLE_UNIT * currprefs.cpu_clock_multiplier; - } - } else if (currprefs.cpu_frequency) { - cpucycleunit = CYCLE_UNIT * baseclock / (currprefs.cpu_frequency * 8); - } - if (cpucycleunit < 1) - cpucycleunit = 1; - write_log (L"CPU cycleunit: %d (%.3f)\n", cpucycleunit, (float)cpucycleunit / CYCLE_UNIT); + cycles_mask = 0; + cycles_val = currprefs.m68k_speed; + if (currprefs.m68k_speed < 1) { + cycles_mask = 0xFFFFFFFF; + cycles_val = 0; + } + currprefs.cpu_clock_multiplier = changed_prefs.cpu_clock_multiplier; + currprefs.cpu_frequency = changed_prefs.cpu_frequency; + + baseclock = currprefs.ntscmode ? 28636360 : 28375160; + cpucycleunit = CYCLE_UNIT / 2; + if (currprefs.cpu_clock_multiplier) { + if (currprefs.cpu_clock_multiplier >= 256) { + cpucycleunit = CYCLE_UNIT / (currprefs.cpu_clock_multiplier >> 8); + } else { + cpucycleunit = CYCLE_UNIT * currprefs.cpu_clock_multiplier; + } + } else if (currprefs.cpu_frequency) { + cpucycleunit = CYCLE_UNIT * baseclock / (currprefs.cpu_frequency * 8); + } + if (cpucycleunit < 1) + cpucycleunit = 1; + write_log (L"CPU cycleunit: %d (%.3f)\n", cpucycleunit, (float)cpucycleunit / CYCLE_UNIT); } static void prefs_changed_cpu (void) { - fixup_cpu (&changed_prefs); - currprefs.cpu_model = changed_prefs.cpu_model; - currprefs.fpu_model = changed_prefs.fpu_model; - currprefs.mmu_model = changed_prefs.mmu_model; - currprefs.cpu_compatible = changed_prefs.cpu_compatible; - currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact; - currprefs.blitter_cycle_exact = changed_prefs.cpu_cycle_exact; + fixup_cpu (&changed_prefs); + currprefs.cpu_model = changed_prefs.cpu_model; + currprefs.fpu_model = changed_prefs.fpu_model; + currprefs.mmu_model = changed_prefs.mmu_model; + currprefs.cpu_compatible = changed_prefs.cpu_compatible; + currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact; + currprefs.blitter_cycle_exact = changed_prefs.cpu_cycle_exact; } void check_prefs_changed_cpu (void) { - int changed = 0; + int changed = 0; #ifdef JIT - changed = check_prefs_changed_comp (); + changed = check_prefs_changed_comp (); #endif - if (changed - || currprefs.cpu_model != changed_prefs.cpu_model - || currprefs.fpu_model != changed_prefs.fpu_model - || currprefs.mmu_model != changed_prefs.mmu_model - || currprefs.cpu_compatible != changed_prefs.cpu_compatible - || currprefs.cpu_cycle_exact != changed_prefs.cpu_cycle_exact) { - - prefs_changed_cpu (); - if (!currprefs.cpu_compatible && changed_prefs.cpu_compatible) - fill_prefetch_slow (); - build_cpufunctbl (); - changed = 1; - } - if (changed - || currprefs.m68k_speed != changed_prefs.m68k_speed - || currprefs.cpu_clock_multiplier != changed_prefs.cpu_clock_multiplier - || currprefs.cpu_frequency != changed_prefs.cpu_frequency) { - currprefs.m68k_speed = changed_prefs.m68k_speed; - reset_frame_rate_hack (); - update_68k_cycles (); - changed = 1; - } + if (changed + || currprefs.cpu_model != changed_prefs.cpu_model + || currprefs.fpu_model != changed_prefs.fpu_model + || currprefs.mmu_model != changed_prefs.mmu_model + || currprefs.cpu_compatible != changed_prefs.cpu_compatible + || currprefs.cpu_cycle_exact != changed_prefs.cpu_cycle_exact) { + + prefs_changed_cpu (); + if (!currprefs.cpu_compatible && changed_prefs.cpu_compatible) + fill_prefetch_slow (); + build_cpufunctbl (); + changed = 1; + } + if (changed + || currprefs.m68k_speed != changed_prefs.m68k_speed + || currprefs.cpu_clock_multiplier != changed_prefs.cpu_clock_multiplier + || currprefs.cpu_frequency != changed_prefs.cpu_frequency) { + currprefs.m68k_speed = changed_prefs.m68k_speed; + reset_frame_rate_hack (); + update_68k_cycles (); + changed = 1; + } - if (currprefs.cpu_idle != changed_prefs.cpu_idle) { - currprefs.cpu_idle = changed_prefs.cpu_idle; - } - if (changed) - set_special (SPCFLAG_BRK); + if (currprefs.cpu_idle != changed_prefs.cpu_idle) { + currprefs.cpu_idle = changed_prefs.cpu_idle; + } + if (changed) + set_special (SPCFLAG_BRK); } void init_m68k (void) { - int i; + int i; - prefs_changed_cpu (); - update_68k_cycles (); + prefs_changed_cpu (); + update_68k_cycles (); - for (i = 0 ; i < 256 ; i++) { - int j; - for (j = 0 ; j < 8 ; j++) { - if (i & (1 << j)) break; + for (i = 0 ; i < 256 ; i++) { + int j; + for (j = 0 ; j < 8 ; j++) { + if (i & (1 << j)) break; + } + movem_index1[i] = j; + movem_index2[i] = 7-j; + movem_next[i] = i & (~(1 << j)); } - movem_index1[i] = j; - movem_index2[i] = 7-j; - movem_next[i] = i & (~(1 << j)); - } #if COUNT_INSTRS - { - FILE *f = fopen (icountfilename (), "r"); - memset (instrcount, 0, sizeof instrcount); - if (f) { - uae_u32 opcode, count, total; - TCHAR name[20]; - write_log (L"Reading instruction count file...\n"); - fscanf (f, "Total: %lu\n", &total); - while (fscanf (f, "%lx: %lu %s\n", &opcode, &count, name) == 3) { - instrcount[opcode] = count; - } - fclose (f); - } - } + { + FILE *f = fopen (icountfilename (), "r"); + memset (instrcount, 0, sizeof instrcount); + if (f) { + uae_u32 opcode, count, total; + TCHAR name[20]; + write_log (L"Reading instruction count file...\n"); + fscanf (f, "Total: %lu\n", &total); + while (fscanf (f, "%lx: %lu %s\n", &opcode, &count, name) == 3) { + instrcount[opcode] = count; + } + fclose (f); + } + } #endif - write_log (L"Building CPU table for configuration: %d", currprefs.cpu_model); - regs.address_space_mask = 0xffffffff; - if (currprefs.cpu_compatible > 0) { - if (currprefs.address_space_24 && currprefs.cpu_model >= 68030) - currprefs.address_space_24 = 0; - } - if (currprefs.fpu_model > 0) - write_log (L"/%d", currprefs.fpu_model); - if (currprefs.cpu_cycle_exact) { - if (currprefs.cpu_model == 68000) - write_log (L" prefetch and cycle-exact"); - else - write_log (L" ~cycle-exact"); - } else if (currprefs.cpu_compatible) - write_log (L" prefetch"); - if (currprefs.address_space_24) { - regs.address_space_mask = 0x00ffffff; - write_log (L" 24-bit"); - } - write_log (L"\n"); + write_log (L"Building CPU table for configuration: %d", currprefs.cpu_model); + regs.address_space_mask = 0xffffffff; + if (currprefs.cpu_compatible > 0) { + if (currprefs.address_space_24 && currprefs.cpu_model >= 68030) + currprefs.address_space_24 = 0; + } + if (currprefs.fpu_model > 0) + write_log (L"/%d", currprefs.fpu_model); + if (currprefs.cpu_cycle_exact) { + if (currprefs.cpu_model == 68000) + write_log (L" prefetch and cycle-exact"); + else + write_log (L" ~cycle-exact"); + } else if (currprefs.cpu_compatible) + write_log (L" prefetch"); + if (currprefs.address_space_24) { + regs.address_space_mask = 0x00ffffff; + write_log (L" 24-bit"); + } + write_log (L"\n"); - read_table68k (); - do_merges (); + read_table68k (); + do_merges (); - write_log (L"%d CPU functions\n", nr_cpuop_funcs); + write_log (L"%d CPU functions\n", nr_cpuop_funcs); - build_cpufunctbl (); + build_cpufunctbl (); #ifdef JIT - /* We need to check whether NATMEM settings have changed - * before starting the CPU */ - check_prefs_changed_comp (); + /* We need to check whether NATMEM settings have changed + * before starting the CPU */ + check_prefs_changed_comp (); #endif } @@ -481,330 +482,330 @@ static long int m68kpc_offset; static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes size, TCHAR *buf, uae_u32 *eaddr, int safemode) { - uae_u16 dp; - uae_s8 disp8; - uae_s16 disp16; - int r; - uae_u32 dispreg; - uaecptr addr = 0; - uae_s32 offset = 0; - TCHAR buffer[80]; - - switch (mode){ - case Dreg: - _stprintf (buffer, L"D%d", reg); - break; - case Areg: - _stprintf (buffer, L"A%d", reg); - break; - case Aind: - _stprintf (buffer, L"(A%d)", reg); - addr = regs.regs[reg + 8]; - break; - case Aipi: - _stprintf (buffer, L"(A%d)+", reg); - addr = regs.regs[reg + 8]; - break; - case Apdi: - _stprintf (buffer, L"-(A%d)", reg); - addr = regs.regs[reg + 8]; - break; - case Ad16: - { - TCHAR offtxt[80]; - disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - if (disp16 < 0) - _stprintf (offtxt, L"-$%04x", -disp16); - else - _stprintf (offtxt, L"$%04x", disp16); - addr = m68k_areg (regs, reg) + disp16; - _stprintf (buffer, L"(A%d, %s) == $%08lx", reg, offtxt, (unsigned long)addr); - } - break; - case Ad8r: - dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - disp8 = dp & 0xFF; - r = (dp & 0x7000) >> 12; - dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); - if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); - dispreg <<= (dp >> 9) & 3; - - if (dp & 0x100) { - uae_s32 outer = 0, disp = 0; - uae_s32 base = m68k_areg (regs, reg); - TCHAR name[10]; - _stprintf (name, L"A%d, ", reg); - if (dp & 0x80) { base = 0; name[0] = 0; } - if (dp & 0x40) dispreg = 0; - if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - base += disp; - - if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - - if (!(dp & 4)) base += dispreg; - if ((dp & 3) && !safemode) base = get_long (base); - if (dp & 4) base += dispreg; - - addr = base + outer; - _stprintf (buffer, L"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, - dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', - 1 << ((dp >> 9) & 3), - disp, outer, - (unsigned long)addr); - } else { - addr = m68k_areg (regs, reg) + (uae_s32)((uae_s8)disp8) + dispreg; - _stprintf (buffer, L"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg, - dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', - 1 << ((dp >> 9) & 3), disp8, - (unsigned long)addr); - } - break; - case PC16: - addr = m68k_getpc () + m68kpc_offset; - disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - addr += (uae_s16)disp16; - _stprintf (buffer, L"(PC,$%04x) == $%08lx", disp16 & 0xffff, (unsigned long)addr); - break; - case PC8r: - addr = m68k_getpc () + m68kpc_offset; - dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - disp8 = dp & 0xFF; - r = (dp & 0x7000) >> 12; - dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); - if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); - dispreg <<= (dp >> 9) & 3; - - if (dp & 0x100) { - uae_s32 outer = 0, disp = 0; - uae_s32 base = addr; - TCHAR name[10]; - _stprintf (name, L"PC, "); - if (dp & 0x80) { base = 0; name[0] = 0; } - if (dp & 0x40) dispreg = 0; - if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - base += disp; - - if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - - if (!(dp & 4)) base += dispreg; - if ((dp & 3) && !safemode) base = get_long (base); - if (dp & 4) base += dispreg; - - addr = base + outer; - _stprintf (buffer, L"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, - dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', - 1 << ((dp >> 9) & 3), - disp, outer, - (unsigned long)addr); - } else { - addr += (uae_s32)((uae_s8)disp8) + dispreg; - _stprintf (buffer, L"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D', - (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), - disp8, (unsigned long)addr); - } - break; - case absw: - addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); - _stprintf (buffer, L"$%08lx", (unsigned long)addr); - m68kpc_offset += 2; - break; - case absl: - addr = get_ilong_1 (m68kpc_offset); - _stprintf (buffer, L"$%08lx", (unsigned long)addr); - m68kpc_offset += 4; - break; - case imm: - switch (size){ - case sz_byte: - _stprintf (buffer, L"#$%02x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xff)); - m68kpc_offset += 2; - break; - case sz_word: - _stprintf (buffer, L"#$%04x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xffff)); - m68kpc_offset += 2; - break; - case sz_long: - _stprintf (buffer, L"#$%08lx", (unsigned long)(get_ilong_1 (m68kpc_offset))); - m68kpc_offset += 4; - break; - default: - break; - } - break; - case imm0: - offset = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); - m68kpc_offset += 2; - _stprintf (buffer, L"#$%02x", (unsigned int)(offset & 0xff)); - break; - case imm1: - offset = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); - m68kpc_offset += 2; - buffer[0] = 0; - _stprintf (buffer, L"#$%04x", (unsigned int)(offset & 0xffff)); - break; - case imm2: - offset = (uae_s32)get_ilong_1 (m68kpc_offset); - m68kpc_offset += 4; - _stprintf (buffer, L"#$%08lx", (unsigned long)offset); - break; - case immi: - offset = (uae_s32)(uae_s8)(reg & 0xff); - _stprintf (buffer, L"#$%08lx", (unsigned long)offset); - break; - default: - break; - } - if (buf == 0) - f_out (f, L"%s", buffer); - else - _tcscat (buf, buffer); - if (eaddr) - *eaddr = addr; - return offset; + uae_u16 dp; + uae_s8 disp8; + uae_s16 disp16; + int r; + uae_u32 dispreg; + uaecptr addr = 0; + uae_s32 offset = 0; + TCHAR buffer[80]; + + switch (mode){ + case Dreg: + _stprintf (buffer, L"D%d", reg); + break; + case Areg: + _stprintf (buffer, L"A%d", reg); + break; + case Aind: + _stprintf (buffer, L"(A%d)", reg); + addr = regs.regs[reg + 8]; + break; + case Aipi: + _stprintf (buffer, L"(A%d)+", reg); + addr = regs.regs[reg + 8]; + break; + case Apdi: + _stprintf (buffer, L"-(A%d)", reg); + addr = regs.regs[reg + 8]; + break; + case Ad16: + { + TCHAR offtxt[80]; + disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + if (disp16 < 0) + _stprintf (offtxt, L"-$%04x", -disp16); + else + _stprintf (offtxt, L"$%04x", disp16); + addr = m68k_areg (regs, reg) + disp16; + _stprintf (buffer, L"(A%d, %s) == $%08lx", reg, offtxt, (unsigned long)addr); + } + break; + case Ad8r: + dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + disp8 = dp & 0xFF; + r = (dp & 0x7000) >> 12; + dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); + if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); + dispreg <<= (dp >> 9) & 3; + + if (dp & 0x100) { + uae_s32 outer = 0, disp = 0; + uae_s32 base = m68k_areg (regs, reg); + TCHAR name[10]; + _stprintf (name, L"A%d, ", reg); + if (dp & 0x80) { base = 0; name[0] = 0; } + if (dp & 0x40) dispreg = 0; + if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + base += disp; + + if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + + if (!(dp & 4)) base += dispreg; + if ((dp & 3) && !safemode) base = get_long (base); + if (dp & 4) base += dispreg; + + addr = base + outer; + _stprintf (buffer, L"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, + dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', + 1 << ((dp >> 9) & 3), + disp, outer, + (unsigned long)addr); + } else { + addr = m68k_areg (regs, reg) + (uae_s32)((uae_s8)disp8) + dispreg; + _stprintf (buffer, L"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg, + dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', + 1 << ((dp >> 9) & 3), disp8, + (unsigned long)addr); + } + break; + case PC16: + addr = m68k_getpc () + m68kpc_offset; + disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + addr += (uae_s16)disp16; + _stprintf (buffer, L"(PC,$%04x) == $%08lx", disp16 & 0xffff, (unsigned long)addr); + break; + case PC8r: + addr = m68k_getpc () + m68kpc_offset; + dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + disp8 = dp & 0xFF; + r = (dp & 0x7000) >> 12; + dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); + if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); + dispreg <<= (dp >> 9) & 3; + + if (dp & 0x100) { + uae_s32 outer = 0, disp = 0; + uae_s32 base = addr; + TCHAR name[10]; + _stprintf (name, L"PC, "); + if (dp & 0x80) { base = 0; name[0] = 0; } + if (dp & 0x40) dispreg = 0; + if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + base += disp; + + if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + + if (!(dp & 4)) base += dispreg; + if ((dp & 3) && !safemode) base = get_long (base); + if (dp & 4) base += dispreg; + + addr = base + outer; + _stprintf (buffer, L"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, + dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', + 1 << ((dp >> 9) & 3), + disp, outer, + (unsigned long)addr); + } else { + addr += (uae_s32)((uae_s8)disp8) + dispreg; + _stprintf (buffer, L"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D', + (int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), + disp8, (unsigned long)addr); + } + break; + case absw: + addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); + _stprintf (buffer, L"$%08lx", (unsigned long)addr); + m68kpc_offset += 2; + break; + case absl: + addr = get_ilong_1 (m68kpc_offset); + _stprintf (buffer, L"$%08lx", (unsigned long)addr); + m68kpc_offset += 4; + break; + case imm: + switch (size){ + case sz_byte: + _stprintf (buffer, L"#$%02x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xff)); + m68kpc_offset += 2; + break; + case sz_word: + _stprintf (buffer, L"#$%04x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xffff)); + m68kpc_offset += 2; + break; + case sz_long: + _stprintf (buffer, L"#$%08lx", (unsigned long)(get_ilong_1 (m68kpc_offset))); + m68kpc_offset += 4; + break; + default: + break; + } + break; + case imm0: + offset = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); + m68kpc_offset += 2; + _stprintf (buffer, L"#$%02x", (unsigned int)(offset & 0xff)); + break; + case imm1: + offset = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); + m68kpc_offset += 2; + buffer[0] = 0; + _stprintf (buffer, L"#$%04x", (unsigned int)(offset & 0xffff)); + break; + case imm2: + offset = (uae_s32)get_ilong_1 (m68kpc_offset); + m68kpc_offset += 4; + _stprintf (buffer, L"#$%08lx", (unsigned long)offset); + break; + case immi: + offset = (uae_s32)(uae_s8)(reg & 0xff); + _stprintf (buffer, L"#$%08lx", (unsigned long)offset); + break; + default: + break; + } + if (buf == 0) + f_out (f, L"%s", buffer); + else + _tcscat (buf, buffer); + if (eaddr) + *eaddr = addr; + return offset; } #if 0 /* The plan is that this will take over the job of exception 3 handling - - * the CPU emulation functions will just do a longjmp to m68k_go whenever - * they hit an odd address. */ +* the CPU emulation functions will just do a longjmp to m68k_go whenever +* they hit an odd address. */ static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val) { - uae_u16 dp; - uae_s8 disp8; - uae_s16 disp16; - int r; - uae_u32 dispreg; - uaecptr addr; - uae_s32 offset = 0; - - switch (mode){ - case Dreg: - *val = m68k_dreg (regs, reg); - return 1; - case Areg: - *val = m68k_areg (regs, reg); - return 1; - - case Aind: - case Aipi: - addr = m68k_areg (regs, reg); - break; - case Apdi: - addr = m68k_areg (regs, reg); - break; - case Ad16: - disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - addr = m68k_areg (regs, reg) + (uae_s16)disp16; - break; - case Ad8r: - addr = m68k_areg (regs, reg); - d8r_common: - dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - disp8 = dp & 0xFF; - r = (dp & 0x7000) >> 12; - dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); - if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); - dispreg <<= (dp >> 9) & 3; - - if (dp & 0x100) { - uae_s32 outer = 0, disp = 0; - uae_s32 base = addr; - if (dp & 0x80) base = 0; - if (dp & 0x40) dispreg = 0; - if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - base += disp; - - if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } - if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } - - if (!(dp & 4)) base += dispreg; - if (dp & 3) base = get_long (base); - if (dp & 4) base += dispreg; - - addr = base + outer; - } else { - addr += (uae_s32)((uae_s8)disp8) + dispreg; - } - break; - case PC16: - addr = m68k_getpc () + m68kpc_offset; - disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - addr += (uae_s16)disp16; - break; - case PC8r: - addr = m68k_getpc () + m68kpc_offset; - goto d8r_common; - case absw: - addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); - m68kpc_offset += 2; - break; - case absl: - addr = get_ilong_1 (m68kpc_offset); - m68kpc_offset += 4; - break; - case imm: - switch (size){ - case sz_byte: - *val = get_iword_1 (m68kpc_offset) & 0xff; - m68kpc_offset += 2; - break; - case sz_word: - *val = get_iword_1 (m68kpc_offset) & 0xffff; - m68kpc_offset += 2; - break; - case sz_long: - *val = get_ilong_1 (m68kpc_offset); - m68kpc_offset += 4; - break; - default: - break; + uae_u16 dp; + uae_s8 disp8; + uae_s16 disp16; + int r; + uae_u32 dispreg; + uaecptr addr; + uae_s32 offset = 0; + + switch (mode){ + case Dreg: + *val = m68k_dreg (regs, reg); + return 1; + case Areg: + *val = m68k_areg (regs, reg); + return 1; + + case Aind: + case Aipi: + addr = m68k_areg (regs, reg); + break; + case Apdi: + addr = m68k_areg (regs, reg); + break; + case Ad16: + disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + addr = m68k_areg (regs, reg) + (uae_s16)disp16; + break; + case Ad8r: + addr = m68k_areg (regs, reg); +d8r_common: + dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + disp8 = dp & 0xFF; + r = (dp & 0x7000) >> 12; + dispreg = dp & 0x8000 ? m68k_areg (regs, r) : m68k_dreg (regs, r); + if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); + dispreg <<= (dp >> 9) & 3; + + if (dp & 0x100) { + uae_s32 outer = 0, disp = 0; + uae_s32 base = addr; + if (dp & 0x80) base = 0; + if (dp & 0x40) dispreg = 0; + if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + base += disp; + + if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } + if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } + + if (!(dp & 4)) base += dispreg; + if (dp & 3) base = get_long (base); + if (dp & 4) base += dispreg; + + addr = base + outer; + } else { + addr += (uae_s32)((uae_s8)disp8) + dispreg; + } + break; + case PC16: + addr = m68k_getpc () + m68kpc_offset; + disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; + addr += (uae_s16)disp16; + break; + case PC8r: + addr = m68k_getpc () + m68kpc_offset; + goto d8r_common; + case absw: + addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); + m68kpc_offset += 2; + break; + case absl: + addr = get_ilong_1 (m68kpc_offset); + m68kpc_offset += 4; + break; + case imm: + switch (size){ + case sz_byte: + *val = get_iword_1 (m68kpc_offset) & 0xff; + m68kpc_offset += 2; + break; + case sz_word: + *val = get_iword_1 (m68kpc_offset) & 0xffff; + m68kpc_offset += 2; + break; + case sz_long: + *val = get_ilong_1 (m68kpc_offset); + m68kpc_offset += 4; + break; + default: + break; + } + return 1; + case imm0: + *val = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); + m68kpc_offset += 2; + return 1; + case imm1: + *val = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); + m68kpc_offset += 2; + return 1; + case imm2: + *val = get_ilong_1 (m68kpc_offset); + m68kpc_offset += 4; + return 1; + case immi: + *val = (uae_s32)(uae_s8)(reg & 0xff); + return 1; + default: + addr = 0; + break; } - return 1; - case imm0: - *val = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); - m68kpc_offset += 2; - return 1; - case imm1: - *val = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); - m68kpc_offset += 2; - return 1; - case imm2: - *val = get_ilong_1 (m68kpc_offset); - m68kpc_offset += 4; - return 1; - case immi: - *val = (uae_s32)(uae_s8)(reg & 0xff); - return 1; - default: - addr = 0; - break; - } - if ((addr & 1) == 0) - return 1; + if ((addr & 1) == 0) + return 1; - last_addr_for_exception_3 = m68k_getpc () + m68kpc_offset; - last_fault_for_exception_3 = addr; - last_writeaccess_for_exception_3 = 0; - last_instructionaccess_for_exception_3 = 0; - return 0; + last_addr_for_exception_3 = m68k_getpc () + m68kpc_offset; + last_fault_for_exception_3 = addr; + last_writeaccess_for_exception_3 = 0; + last_instructionaccess_for_exception_3 = 0; + return 0; } #endif int get_cpu_model (void) { - return currprefs.cpu_model; + return currprefs.cpu_model; } /* - * extract bitfield data from memory and return it in the MSBs - * bdata caches the unmodified data for put_bitfield() - */ +* extract bitfield data from memory and return it in the MSBs +* bdata caches the unmodified data for put_bitfield() +*/ uae_u32 get_bitfield (uae_u32 src, uae_u32 bdata[2], uae_s32 offset, int width) { uae_u32 tmp, res, mask; @@ -851,9 +852,9 @@ uae_u32 get_bitfield (uae_u32 src, uae_u32 bdata[2], uae_s32 offset, int width) return res; } /* - * write bitfield data (in the LSBs) back to memory, upper bits - * must be cleared already. - */ +* write bitfield data (in the LSBs) back to memory, upper bits +* must be cleared already. +*/ void put_bitfield (uae_u32 dst, uae_u32 bdata[2], uae_u32 val, uae_s32 offset, int width) { offset = (offset & 7) + width; @@ -1021,239 +1022,239 @@ void put_bitfield_040mmu (uae_u32 dst, uae_u32 bdata[2], uae_u32 val, uae_s32 of uae_u32 REGPARAM2 get_disp_ea_020 (uae_u32 base, uae_u32 dp) { - int reg = (dp >> 12) & 15; - uae_s32 regd = regs.regs[reg]; - if ((dp & 0x800) == 0) - regd = (uae_s32)(uae_s16)regd; - regd <<= (dp >> 9) & 3; - if (dp & 0x100) { - uae_s32 outer = 0; - if (dp & 0x80) base = 0; - if (dp & 0x40) regd = 0; - - if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16) next_iword (); - if ((dp & 0x30) == 0x30) base += next_ilong (); - - if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16) next_iword (); - if ((dp & 0x3) == 0x3) outer = next_ilong (); - - if ((dp & 0x4) == 0) base += regd; - if (dp & 0x3) base = get_long (base); - if (dp & 0x4) base += regd; - - return base + outer; - } else { - return base + (uae_s32)((uae_s8)dp) + regd; - } + int reg = (dp >> 12) & 15; + uae_s32 regd = regs.regs[reg]; + if ((dp & 0x800) == 0) + regd = (uae_s32)(uae_s16)regd; + regd <<= (dp >> 9) & 3; + if (dp & 0x100) { + uae_s32 outer = 0; + if (dp & 0x80) base = 0; + if (dp & 0x40) regd = 0; + + if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16) next_iword (); + if ((dp & 0x30) == 0x30) base += next_ilong (); + + if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16) next_iword (); + if ((dp & 0x3) == 0x3) outer = next_ilong (); + + if ((dp & 0x4) == 0) base += regd; + if (dp & 0x3) base = get_long (base); + if (dp & 0x4) base += regd; + + return base + outer; + } else { + return base + (uae_s32)((uae_s8)dp) + regd; + } } uae_u32 REGPARAM2 get_disp_ea_020ce (uae_u32 base, uae_u32 dp) { - int reg = (dp >> 12) & 15; - int cycles = 0; - uae_u32 v; - - uae_s32 regd = regs.regs[reg]; - if ((dp & 0x800) == 0) - regd = (uae_s32)(uae_s16)regd; - regd <<= (dp >> 9) & 3; - if (dp & 0x100) { - uae_s32 outer = 0; - if (dp & 0x80) - base = 0; - if (dp & 0x40) - regd = 0; - - if ((dp & 0x30) == 0x20) { - base += (uae_s32)(uae_s16) next_iword_020ce (); - cycles++; - } - if ((dp & 0x30) == 0x30) { - base += next_ilong_020ce (); - cycles++; - } - - if ((dp & 0x3) == 0x2) { - outer = (uae_s32)(uae_s16) next_iword_020ce (); - cycles++; - } - if ((dp & 0x3) == 0x3) { - outer = next_ilong_020ce (); - cycles++; - } - - if ((dp & 0x4) == 0) { - base += regd; - cycles++; - } - if (dp & 0x3) { - base = get_long_ce020 (base); - cycles++; - } - if (dp & 0x4) { - base += regd; - cycles++; - } - v = base + outer; - } else { - v = base + (uae_s32)((uae_s8)dp) + regd; - } - if (cycles) - do_cycles_ce020 (cycles); - return v; + int reg = (dp >> 12) & 15; + int cycles = 0; + uae_u32 v; + + uae_s32 regd = regs.regs[reg]; + if ((dp & 0x800) == 0) + regd = (uae_s32)(uae_s16)regd; + regd <<= (dp >> 9) & 3; + if (dp & 0x100) { + uae_s32 outer = 0; + if (dp & 0x80) + base = 0; + if (dp & 0x40) + regd = 0; + + if ((dp & 0x30) == 0x20) { + base += (uae_s32)(uae_s16) next_iword_020ce (); + cycles++; + } + if ((dp & 0x30) == 0x30) { + base += next_ilong_020ce (); + cycles++; + } + + if ((dp & 0x3) == 0x2) { + outer = (uae_s32)(uae_s16) next_iword_020ce (); + cycles++; + } + if ((dp & 0x3) == 0x3) { + outer = next_ilong_020ce (); + cycles++; + } + + if ((dp & 0x4) == 0) { + base += regd; + cycles++; + } + if (dp & 0x3) { + base = get_long_ce020 (base); + cycles++; + } + if (dp & 0x4) { + base += regd; + cycles++; + } + v = base + outer; + } else { + v = base + (uae_s32)((uae_s8)dp) + regd; + } + if (cycles) + do_cycles_ce020 (cycles); + return v; } uae_u32 REGPARAM2 get_disp_ea_040mmu (uae_u32 base, uae_u32 dp) { - int reg = (dp >> 12) & 15; - uae_s32 regd = regs.regs[reg]; - if ((dp & 0x800) == 0) - regd = (uae_s32)(uae_s16)regd; - regd <<= (dp >> 9) & 3; - if (dp & 0x100) { - uae_s32 outer = 0; - if (dp & 0x80) base = 0; - if (dp & 0x40) regd = 0; - - if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16) next_iword_mmu (); - if ((dp & 0x30) == 0x30) base += next_ilong_mmu (); - - if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16) next_iword_mmu (); - if ((dp & 0x3) == 0x3) outer = next_ilong_mmu (); - - if ((dp & 0x4) == 0) base += regd; - if (dp & 0x3) base = get_long_mmu (base); - if (dp & 0x4) base += regd; - - return base + outer; - } else { - return base + (uae_s32)((uae_s8)dp) + regd; - } + int reg = (dp >> 12) & 15; + uae_s32 regd = regs.regs[reg]; + if ((dp & 0x800) == 0) + regd = (uae_s32)(uae_s16)regd; + regd <<= (dp >> 9) & 3; + if (dp & 0x100) { + uae_s32 outer = 0; + if (dp & 0x80) base = 0; + if (dp & 0x40) regd = 0; + + if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16) next_iword_mmu (); + if ((dp & 0x30) == 0x30) base += next_ilong_mmu (); + + if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16) next_iword_mmu (); + if ((dp & 0x3) == 0x3) outer = next_ilong_mmu (); + + if ((dp & 0x4) == 0) base += regd; + if (dp & 0x3) base = get_long_mmu (base); + if (dp & 0x4) base += regd; + + return base + outer; + } else { + return base + (uae_s32)((uae_s8)dp) + regd; + } } uae_u32 REGPARAM3 get_disp_ea_000 (uae_u32 base, uae_u32 dp) REGPARAM { - int reg = (dp >> 12) & 15; - uae_s32 regd = regs.regs[reg]; + int reg = (dp >> 12) & 15; + uae_s32 regd = regs.regs[reg]; #if 1 - if ((dp & 0x800) == 0) - regd = (uae_s32)(uae_s16)regd; - return base + (uae_s8)dp + regd; + if ((dp & 0x800) == 0) + regd = (uae_s32)(uae_s16)regd; + return base + (uae_s8)dp + regd; #else - /* Branch-free code... benchmark this again now that - * things are no longer inline. */ - uae_s32 regd16; - uae_u32 mask; - mask = ((dp & 0x800) >> 11) - 1; - regd16 = (uae_s32)(uae_s16)regd; - regd16 &= mask; - mask = ~mask; - base += (uae_s8)dp; - regd &= mask; - regd |= regd16; - return base + regd; + /* Branch-free code... benchmark this again now that + * things are no longer inline. */ + uae_s32 regd16; + uae_u32 mask; + mask = ((dp & 0x800) >> 11) - 1; + regd16 = (uae_s32)(uae_s16)regd; + regd16 &= mask; + mask = ~mask; + base += (uae_s8)dp; + regd &= mask; + regd |= regd16; + return base + regd; #endif } void REGPARAM2 MakeSR (void) { - regs.sr = ((regs.t1 << 15) | (regs.t0 << 14) - | (regs.s << 13) | (regs.m << 12) | (regs.intmask << 8) - | (GET_XFLG () << 4) | (GET_NFLG () << 3) - | (GET_ZFLG () << 2) | (GET_VFLG () << 1) - | GET_CFLG ()); + regs.sr = ((regs.t1 << 15) | (regs.t0 << 14) + | (regs.s << 13) | (regs.m << 12) | (regs.intmask << 8) + | (GET_XFLG () << 4) | (GET_NFLG () << 3) + | (GET_ZFLG () << 2) | (GET_VFLG () << 1) + | GET_CFLG ()); } void REGPARAM2 MakeFromSR (void) { - int oldm = regs.m; - int olds = regs.s; - - SET_XFLG ((regs.sr >> 4) & 1); - SET_NFLG ((regs.sr >> 3) & 1); - SET_ZFLG ((regs.sr >> 2) & 1); - SET_VFLG ((regs.sr >> 1) & 1); - SET_CFLG (regs.sr & 1); - if (regs.t1 == ((regs.sr >> 15) & 1) && - regs.t0 == ((regs.sr >> 14) & 1) && - regs.s == ((regs.sr >> 13) & 1) && - regs.m == ((regs.sr >> 12) & 1) && - regs.intmask == ((regs.sr >> 8) & 7)) - return; - regs.t1 = (regs.sr >> 15) & 1; - regs.t0 = (regs.sr >> 14) & 1; - regs.s = (regs.sr >> 13) & 1; - regs.m = (regs.sr >> 12) & 1; - regs.intmask = (regs.sr >> 8) & 7; - if (currprefs.cpu_model >= 68020) { - /* 68060 does not have MSP but does have M-bit.. */ - if (currprefs.cpu_model >= 68060) - regs.msp = regs.isp; - if (olds != regs.s) { - if (olds) { - if (oldm) - regs.msp = m68k_areg (regs, 7); - else - regs.isp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.usp; - } else { - regs.usp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; - } - } else if (olds && oldm != regs.m) { - if (oldm) { - regs.msp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; - } else { - regs.isp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.msp; - } - } - if (currprefs.cpu_model >= 68060) - regs.t0 = 0; - } else { - regs.t0 = regs.m = 0; - if (olds != regs.s) { - if (olds) { - regs.isp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.usp; - } else { - regs.usp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; - } - } - } - if (currprefs.mmu_model) - mmu_set_super (regs.s); - - doint (); - if (regs.t1 || regs.t0) - set_special (SPCFLAG_TRACE); - else - /* Keep SPCFLAG_DOTRACE, we still want a trace exception for - SR-modifying instructions (including STOP). */ - unset_special (SPCFLAG_TRACE); + int oldm = regs.m; + int olds = regs.s; + + SET_XFLG ((regs.sr >> 4) & 1); + SET_NFLG ((regs.sr >> 3) & 1); + SET_ZFLG ((regs.sr >> 2) & 1); + SET_VFLG ((regs.sr >> 1) & 1); + SET_CFLG (regs.sr & 1); + if (regs.t1 == ((regs.sr >> 15) & 1) && + regs.t0 == ((regs.sr >> 14) & 1) && + regs.s == ((regs.sr >> 13) & 1) && + regs.m == ((regs.sr >> 12) & 1) && + regs.intmask == ((regs.sr >> 8) & 7)) + return; + regs.t1 = (regs.sr >> 15) & 1; + regs.t0 = (regs.sr >> 14) & 1; + regs.s = (regs.sr >> 13) & 1; + regs.m = (regs.sr >> 12) & 1; + regs.intmask = (regs.sr >> 8) & 7; + if (currprefs.cpu_model >= 68020) { + /* 68060 does not have MSP but does have M-bit.. */ + if (currprefs.cpu_model >= 68060) + regs.msp = regs.isp; + if (olds != regs.s) { + if (olds) { + if (oldm) + regs.msp = m68k_areg (regs, 7); + else + regs.isp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.usp; + } else { + regs.usp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; + } + } else if (olds && oldm != regs.m) { + if (oldm) { + regs.msp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + } else { + regs.isp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.msp; + } + } + if (currprefs.cpu_model >= 68060) + regs.t0 = 0; + } else { + regs.t0 = regs.m = 0; + if (olds != regs.s) { + if (olds) { + regs.isp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.usp; + } else { + regs.usp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + } + } + } + if (currprefs.mmu_model) + mmu_set_super (regs.s); + + doint (); + if (regs.t1 || regs.t0) + set_special (SPCFLAG_TRACE); + else + /* Keep SPCFLAG_DOTRACE, we still want a trace exception for + SR-modifying instructions (including STOP). */ + unset_special (SPCFLAG_TRACE); } static void exception_trace (int nr) { - unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); - if (regs.t1 && !regs.t0) { - /* trace stays pending if exception is div by zero, chk, - * trapv or trap #x - */ - if (nr == 5 || nr == 6 || nr == 7 || (nr >= 32 && nr <= 47)) - set_special (SPCFLAG_DOTRACE); - } - regs.t1 = regs.t0 = regs.m = 0; + unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); + if (regs.t1 && !regs.t0) { + /* trace stays pending if exception is div by zero, chk, + * trapv or trap #x + */ + if (nr == 5 || nr == 6 || nr == 7 || (nr >= 32 && nr <= 47)) + set_special (SPCFLAG_DOTRACE); + } + regs.t1 = regs.t0 = regs.m = 0; } static void exception_debug (int nr) { #ifdef DEBUGGER - if (!exception_debugging) - return; - console_out_f (L"Exception %d, PC=%08X\n", nr, M68K_GETPC); + if (!exception_debugging) + return; + console_out_f (L"Exception %d, PC=%08X\n", nr, M68K_GETPC); #endif } @@ -1357,579 +1358,579 @@ Interrupt cycle diagram: static void Exception_ce (int nr, uaecptr oldpc) { - uae_u32 currpc = m68k_getpc (), newpc; - int sv = regs.s; - int start; - - start = 6; - if (nr == 7) // TRAPV - start = 0; - else if (nr >= 32 && nr < 32 + 16) // TRAP #x - start = 2; - else if (nr == 4 || nr == 8) // ILLG & PRIVIL VIOL - start = 2; - - if (start) - do_cycles_ce (start * CYCLE_UNIT / 2); - - if (nr >= 24 && nr < 24 + 8) { // fetch interrupt vector number - nr = get_byte_ce (0x00fffff1 | ((nr - 24) << 1)); - } - - exception_debug (nr); - MakeSR (); - - if (!regs.s) { - regs.usp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; - regs.s = 1; - } - if (nr == 2 || nr == 3) { /* 2=bus error, 3=address error */ - uae_u16 mode = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); - mode |= last_writeaccess_for_exception_3 ? 0 : 16; - m68k_areg (regs, 7) -= 14; - /* fixme: bit3=I/N */ - put_word_ce (m68k_areg (regs, 7) + 12, last_addr_for_exception_3); - put_word_ce (m68k_areg (regs, 7) + 8, regs.sr); - put_word_ce (m68k_areg (regs, 7) + 10, last_addr_for_exception_3 >> 16); - put_word_ce (m68k_areg (regs, 7) + 6, last_op_for_exception_3); - put_word_ce (m68k_areg (regs, 7) + 4, last_fault_for_exception_3); - put_word_ce (m68k_areg (regs, 7) + 0, mode); - put_word_ce (m68k_areg (regs, 7) + 2, last_fault_for_exception_3 >> 16); - do_cycles_ce (2 * CYCLE_UNIT / 2); - write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (4 * nr)); - goto kludge_me_do; - } - m68k_areg (regs, 7) -= 6; - put_word_ce (m68k_areg (regs, 7) + 4, currpc); // write low address - put_word_ce (m68k_areg (regs, 7) + 0, regs.sr); // write SR - put_word_ce (m68k_areg (regs, 7) + 2, currpc >> 16); // write high address + uae_u32 currpc = m68k_getpc (), newpc; + int sv = regs.s; + int start; + + start = 6; + if (nr == 7) // TRAPV + start = 0; + else if (nr >= 32 && nr < 32 + 16) // TRAP #x + start = 2; + else if (nr == 4 || nr == 8) // ILLG & PRIVIL VIOL + start = 2; + + if (start) + do_cycles_ce (start * CYCLE_UNIT / 2); + + if (nr >= 24 && nr < 24 + 8) { // fetch interrupt vector number + nr = get_byte_ce (0x00fffff1 | ((nr - 24) << 1)); + } + + exception_debug (nr); + MakeSR (); + + if (!regs.s) { + regs.usp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + regs.s = 1; + } + if (nr == 2 || nr == 3) { /* 2=bus error, 3=address error */ + uae_u16 mode = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); + mode |= last_writeaccess_for_exception_3 ? 0 : 16; + m68k_areg (regs, 7) -= 14; + /* fixme: bit3=I/N */ + put_word_ce (m68k_areg (regs, 7) + 12, last_addr_for_exception_3); + put_word_ce (m68k_areg (regs, 7) + 8, regs.sr); + put_word_ce (m68k_areg (regs, 7) + 10, last_addr_for_exception_3 >> 16); + put_word_ce (m68k_areg (regs, 7) + 6, last_op_for_exception_3); + put_word_ce (m68k_areg (regs, 7) + 4, last_fault_for_exception_3); + put_word_ce (m68k_areg (regs, 7) + 0, mode); + put_word_ce (m68k_areg (regs, 7) + 2, last_fault_for_exception_3 >> 16); + do_cycles_ce (2 * CYCLE_UNIT / 2); + write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (4 * nr)); + goto kludge_me_do; + } + m68k_areg (regs, 7) -= 6; + put_word_ce (m68k_areg (regs, 7) + 4, currpc); // write low address + put_word_ce (m68k_areg (regs, 7) + 0, regs.sr); // write SR + put_word_ce (m68k_areg (regs, 7) + 2, currpc >> 16); // write high address kludge_me_do: - newpc = get_word_ce (4 * nr) << 16; // read high address - newpc |= get_word_ce (4 * nr + 2); // read low address - if (newpc & 1) { - if (nr == 2 || nr == 3) - uae_reset (1); /* there is nothing else we can do.. */ - else - exception3 (regs.ir, m68k_getpc (), newpc); - return; - } - m68k_setpc (newpc); - regs.ir = get_word_ce (m68k_getpc ()); // prefetch 1 - do_cycles_ce (2 * CYCLE_UNIT / 2); - regs.irc = get_word_ce (m68k_getpc () + 2); // prefetch 2 - set_special (SPCFLAG_END_COMPILE); - exception_trace (nr); + newpc = get_word_ce (4 * nr) << 16; // read high address + newpc |= get_word_ce (4 * nr + 2); // read low address + if (newpc & 1) { + if (nr == 2 || nr == 3) + uae_reset (1); /* there is nothing else we can do.. */ + else + exception3 (regs.ir, m68k_getpc (), newpc); + return; + } + m68k_setpc (newpc); + regs.ir = get_word_ce (m68k_getpc ()); // prefetch 1 + do_cycles_ce (2 * CYCLE_UNIT / 2); + regs.irc = get_word_ce (m68k_getpc () + 2); // prefetch 2 + set_special (SPCFLAG_END_COMPILE); + exception_trace (nr); } #endif static void Exception_mmu (int nr, uaecptr oldpc) { - uae_u32 currpc = m68k_getpc (), newpc; - int sv = regs.s; - int i; - - exception_debug (nr); - MakeSR (); + uae_u32 currpc = m68k_getpc (), newpc; + int sv = regs.s; + int i; - if (!regs.s) { - regs.usp = m68k_areg (regs, 7); - if (currprefs.cpu_model >= 68020) - m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; - else - m68k_areg (regs, 7) = regs.isp; - regs.s = 1; - mmu_set_super (1); - } - if (nr == 2) { + exception_debug (nr); + MakeSR (); - // bus error - for (i = 0 ; i < 7 ; i++) { - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), 0); + if (!regs.s) { + regs.usp = m68k_areg (regs, 7); + if (currprefs.cpu_model >= 68020) + m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; + else + m68k_areg (regs, 7) = regs.isp; + regs.s = 1; + mmu_set_super (1); } - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.wb3_data); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.wb3_status); - regs.wb3_status = 0; - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.mmu_ssw); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + if (nr == 2) { - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0x7000 + nr * 4); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.sr); - goto kludge_me_do; + // bus error + for (i = 0 ; i < 7 ; i++) { + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.wb3_data); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.wb3_status); + regs.wb3_status = 0; + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.mmu_ssw); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - } else if (nr == 3) { + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0x7000 + nr * 4); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.sr); + goto kludge_me_do; - // address error - uae_u16 ssw = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); - ssw |= last_writeaccess_for_exception_3 ? 0 : 0x40; - ssw |= 0x20; - for (i = 0 ; i < 36; i++) { - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - } - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), last_fault_for_exception_3); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), ssw); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0xb000 + nr * 4); - write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); + } else if (nr == 3) { - } else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) { + // address error + uae_u16 ssw = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); + ssw |= last_writeaccess_for_exception_3 ? 0 : 0x40; + ssw |= 0x20; + for (i = 0 ; i < 36; i++) { + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), last_fault_for_exception_3); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), ssw); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0xb000 + nr * 4); + write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0x2000 + nr * 4); + } else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) { - } else if (regs.m && nr >= 24 && nr < 32) { /* M + Interrupt */ + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0x2000 + nr * 4); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), nr * 4); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), currpc); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.sr); - regs.sr |= (1 << 13); - regs.msp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0x1000 + nr * 4); - - } else { + } else if (regs.m && nr >= 24 && nr < 32) { /* M + Interrupt */ + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), nr * 4); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), currpc); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.sr); + regs.sr |= (1 << 13); + regs.msp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0x1000 + nr * 4); + + } else { + + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), nr * 4); + + } + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), currpc); m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), nr * 4); - - } - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), currpc); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.sr); + put_word_mmu (m68k_areg (regs, 7), regs.sr); kludge_me_do: - newpc = get_long_mmu (regs.vbr + 4 * nr); - if (newpc & 1) { - if (nr == 2 || nr == 3) - uae_reset (1); /* there is nothing else we can do.. */ - else - exception3 (regs.ir, m68k_getpc (), newpc); - return; - } - m68k_setpc (newpc); - set_special (SPCFLAG_END_COMPILE); - fill_prefetch_slow (); - exception_trace (nr); + newpc = get_long_mmu (regs.vbr + 4 * nr); + if (newpc & 1) { + if (nr == 2 || nr == 3) + uae_reset (1); /* there is nothing else we can do.. */ + else + exception3 (regs.ir, m68k_getpc (), newpc); + return; + } + m68k_setpc (newpc); + set_special (SPCFLAG_END_COMPILE); + fill_prefetch_slow (); + exception_trace (nr); } static void Exception_normal (int nr, uaecptr oldpc) { - uae_u32 currpc = m68k_getpc (), newpc; - int sv = regs.s; - - if (nr >= 24 && nr < 24 + 8 && currprefs.cpu_model <= 68010) - nr = get_byte (0x00fffff1 | (nr << 1)); - - exception_debug (nr); - MakeSR (); + uae_u32 currpc = m68k_getpc (), newpc; + int sv = regs.s; - if (!regs.s) { - regs.usp = m68k_areg (regs, 7); - if (currprefs.cpu_model >= 68020) - m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; - else - m68k_areg (regs, 7) = regs.isp; - regs.s = 1; - if (currprefs.mmu_model) - mmu_set_super (regs.s); - } - if (currprefs.cpu_model > 68000) { - if (nr == 2 || nr == 3) { - int i; - if (currprefs.cpu_model >= 68040) { - if (nr == 2) { - // bus error - if (currprefs.mmu_model) { - - for (i = 0 ; i < 7 ; i++) { - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), 0); - } - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.wb3_data); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.wb3_status); - regs.wb3_status = 0; - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.mmu_ssw); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); - - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), 0x7000 + nr * 4); - m68k_areg (regs, 7) -= 4; - put_long_mmu (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 2; - put_word_mmu (m68k_areg (regs, 7), regs.sr); - newpc = get_long_mmu (regs.vbr + 4 * nr); - if (newpc & 1) { - if (nr == 2 || nr == 3) - uae_reset (1); /* there is nothing else we can do.. */ - else - exception3 (regs.ir, m68k_getpc (), newpc); - return; - } - m68k_setpc (newpc); - set_special (SPCFLAG_END_COMPILE); - exception_trace (nr); - return; + if (nr >= 24 && nr < 24 + 8 && currprefs.cpu_model <= 68010) + nr = get_byte (0x00fffff1 | (nr << 1)); - } else { + exception_debug (nr); + MakeSR (); - for (i = 0 ; i < 18 ; i++) { - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); + if (!regs.s) { + regs.usp = m68k_areg (regs, 7); + if (currprefs.cpu_model >= 68020) + m68k_areg (regs, 7) = regs.m ? regs.msp : regs.isp; + else + m68k_areg (regs, 7) = regs.isp; + regs.s = 1; + if (currprefs.mmu_model) + mmu_set_super (regs.s); + } + if (currprefs.cpu_model > 68000) { + if (nr == 2 || nr == 3) { + int i; + if (currprefs.cpu_model >= 68040) { + if (nr == 2) { + // bus error + if (currprefs.mmu_model) { + + for (i = 0 ; i < 7 ; i++) { + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.wb3_data); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.wb3_status); + regs.wb3_status = 0; + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.mmu_ssw); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), regs.mmu_fault_addr); + + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), 0x7000 + nr * 4); + m68k_areg (regs, 7) -= 4; + put_long_mmu (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 2; + put_word_mmu (m68k_areg (regs, 7), regs.sr); + newpc = get_long_mmu (regs.vbr + 4 * nr); + if (newpc & 1) { + if (nr == 2 || nr == 3) + uae_reset (1); /* there is nothing else we can do.. */ + else + exception3 (regs.ir, m68k_getpc (), newpc); + return; + } + m68k_setpc (newpc); + set_special (SPCFLAG_END_COMPILE); + exception_trace (nr); + return; + + } else { + + for (i = 0 ; i < 18 ; i++) { + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), last_fault_for_exception_3); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0x0140 | (sv ? 6 : 2)); /* SSW */ + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), last_addr_for_exception_3); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0x7000 + nr * 4); + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), oldpc); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), regs.sr); + goto kludge_me_do; + + } + + } else { + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), last_fault_for_exception_3); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0x2000 + nr * 4); + } + } else { + // address error + uae_u16 ssw = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); + ssw |= last_writeaccess_for_exception_3 ? 0 : 0x40; + ssw |= 0x20; + for (i = 0 ; i < 36; i++) { + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + } + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), last_fault_for_exception_3); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), ssw); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0xb000 + nr * 4); } + write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); + } else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) { m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), last_fault_for_exception_3); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); + put_long (m68k_areg (regs, 7), oldpc); m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); + put_word (m68k_areg (regs, 7), 0x2000 + nr * 4); + } else if (regs.m && nr >= 24 && nr < 32) { /* M + Interrupt */ m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x0140 | (sv ? 6 : 2)); /* SSW */ + put_word (m68k_areg (regs, 7), nr * 4); m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), last_addr_for_exception_3); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x7000 + nr * 4); - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), oldpc); + put_long (m68k_areg (regs, 7), currpc); m68k_areg (regs, 7) -= 2; put_word (m68k_areg (regs, 7), regs.sr); - goto kludge_me_do; - - } - + regs.sr |= (1 << 13); + regs.msp = m68k_areg (regs, 7); + m68k_areg (regs, 7) = regs.isp; + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), 0x1000 + nr * 4); } else { - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), last_fault_for_exception_3); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x2000 + nr * 4); - } - } else { - // address error - uae_u16 ssw = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); - ssw |= last_writeaccess_for_exception_3 ? 0 : 0x40; - ssw |= 0x20; - for (i = 0 ; i < 36; i++) { - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), nr * 4); } - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), last_fault_for_exception_3); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), ssw); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0xb000 + nr * 4); - } - write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); - } else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) { - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), oldpc); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x2000 + nr * 4); - } else if (regs.m && nr >= 24 && nr < 32) { /* M + Interrupt */ - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), nr * 4); - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), currpc); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), regs.sr); - regs.sr |= (1 << 13); - regs.msp = m68k_areg (regs, 7); - m68k_areg (regs, 7) = regs.isp; - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), 0x1000 + nr * 4); - } else { - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), nr * 4); - } - } else if (nr == 2 || nr == 3) { - uae_u16 mode = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); - mode |= last_writeaccess_for_exception_3 ? 0 : 16; - m68k_areg (regs, 7) -= 14; - /* fixme: bit3=I/N */ - put_word (m68k_areg (regs, 7) + 0, mode); - put_long (m68k_areg (regs, 7) + 2, last_fault_for_exception_3); - put_word (m68k_areg (regs, 7) + 6, last_op_for_exception_3); - put_word (m68k_areg (regs, 7) + 8, regs.sr); - put_long (m68k_areg (regs, 7) + 10, last_addr_for_exception_3); - write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); - goto kludge_me_do; - } - m68k_areg (regs, 7) -= 4; - put_long (m68k_areg (regs, 7), currpc); - m68k_areg (regs, 7) -= 2; - put_word (m68k_areg (regs, 7), regs.sr); + } else if (nr == 2 || nr == 3) { + uae_u16 mode = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1); + mode |= last_writeaccess_for_exception_3 ? 0 : 16; + m68k_areg (regs, 7) -= 14; + /* fixme: bit3=I/N */ + put_word (m68k_areg (regs, 7) + 0, mode); + put_long (m68k_areg (regs, 7) + 2, last_fault_for_exception_3); + put_word (m68k_areg (regs, 7) + 6, last_op_for_exception_3); + put_word (m68k_areg (regs, 7) + 8, regs.sr); + put_long (m68k_areg (regs, 7) + 10, last_addr_for_exception_3); + write_log (L"Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr)); + goto kludge_me_do; + } + m68k_areg (regs, 7) -= 4; + put_long (m68k_areg (regs, 7), currpc); + m68k_areg (regs, 7) -= 2; + put_word (m68k_areg (regs, 7), regs.sr); kludge_me_do: - newpc = get_long (regs.vbr + 4 * nr); - if (newpc & 1) { - if (nr == 2 || nr == 3) - uae_reset (1); /* there is nothing else we can do.. */ - else - exception3 (regs.ir, m68k_getpc (), newpc); - return; - } - m68k_setpc (newpc); - set_special (SPCFLAG_END_COMPILE); - fill_prefetch_slow (); - exception_trace (nr); + newpc = get_long (regs.vbr + 4 * nr); + if (newpc & 1) { + if (nr == 2 || nr == 3) + uae_reset (1); /* there is nothing else we can do.. */ + else + exception3 (regs.ir, m68k_getpc (), newpc); + return; + } + m68k_setpc (newpc); + set_special (SPCFLAG_END_COMPILE); + fill_prefetch_slow (); + exception_trace (nr); } void REGPARAM2 Exception (int nr, uaecptr oldpc) { #ifdef CPUEMU_12 - if (currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000) - Exception_ce (nr, oldpc); - else + if (currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000) + Exception_ce (nr, oldpc); + else #endif - if (currprefs.mmu_model) - Exception_mmu (nr, oldpc); - else - Exception_normal (nr, oldpc); + if (currprefs.mmu_model) + Exception_mmu (nr, oldpc); + else + Exception_normal (nr, oldpc); } STATIC_INLINE void do_interrupt (int nr) { - regs.stopped = 0; - unset_special (SPCFLAG_STOP); - assert (nr < 8 && nr >= 0); + regs.stopped = 0; + unset_special (SPCFLAG_STOP); + assert (nr < 8 && nr >= 0); - Exception (nr + 24, 0); + Exception (nr + 24, 0); - regs.intmask = nr; - doint (); + regs.intmask = nr; + doint (); } void NMI (void) { - do_interrupt (7); + do_interrupt (7); } #ifndef CPUEMU_68000_ONLY int movec_illg (int regno) { - int regno2 = regno & 0x7ff; - - if (currprefs.cpu_model == 68060) { - if (regno <= 8) - return 0; - if (regno == 0x800 || regno == 0x801 || - regno == 0x806 || regno == 0x807 || regno == 0x808) - return 0; - return 1; - } else if (currprefs.cpu_model == 68010) { - if (regno2 < 2) - return 0; - return 1; - } else if (currprefs.cpu_model == 68020) { - if (regno == 3) - return 1; /* 68040/060 only */ - /* 4 is >=68040, but 0x804 is in 68020 */ - if (regno2 < 4 || regno == 0x804) - return 0; - return 1; - } else if (currprefs.cpu_model == 68030) { - if (regno2 <= 2) - return 0; - if (regno == 0x803 || regno == 0x804) - return 0; - return 1; - } else if (currprefs.cpu_model == 68040) { - if (regno == 0x802) - return 1; /* 68020 only */ - if (regno2 < 8) return 0; + int regno2 = regno & 0x7ff; + + if (currprefs.cpu_model == 68060) { + if (regno <= 8) + return 0; + if (regno == 0x800 || regno == 0x801 || + regno == 0x806 || regno == 0x807 || regno == 0x808) + return 0; + return 1; + } else if (currprefs.cpu_model == 68010) { + if (regno2 < 2) + return 0; + return 1; + } else if (currprefs.cpu_model == 68020) { + if (regno == 3) + return 1; /* 68040/060 only */ + /* 4 is >=68040, but 0x804 is in 68020 */ + if (regno2 < 4 || regno == 0x804) + return 0; + return 1; + } else if (currprefs.cpu_model == 68030) { + if (regno2 <= 2) + return 0; + if (regno == 0x803 || regno == 0x804) + return 0; + return 1; + } else if (currprefs.cpu_model == 68040) { + if (regno == 0x802) + return 1; /* 68020 only */ + if (regno2 < 8) return 0; + return 1; + } return 1; - } - return 1; } int m68k_move2c (int regno, uae_u32 *regp) { #if MOVEC_DEBUG > 0 - write_log (L"move2c %04X <- %08X PC=%x\n", regno, *regp, M68K_GETPC); + write_log (L"move2c %04X <- %08X PC=%x\n", regno, *regp, M68K_GETPC); #endif - if (movec_illg (regno)) { - op_illg (0x4E7B); - return 0; - } else { - switch (regno) { - case 0: regs.sfc = *regp & 7; break; - case 1: regs.dfc = *regp & 7; break; - case 2: - { - uae_u32 cacr_mask = 0; - if (currprefs.cpu_model == 68020) - cacr_mask = 0x0000000f; - else if (currprefs.cpu_model == 68030) - cacr_mask = 0x00003f1f; - else if (currprefs.cpu_model == 68040) - cacr_mask = 0x80008000; - else if (currprefs.cpu_model == 68060) - cacr_mask = 0xf8e0e000; - regs.cacr = *regp & cacr_mask; - set_cpu_caches (); - } - break; - /* 68040/060 only */ - case 3: - regs.tcr = *regp & (currprefs.cpu_model == 68060 ? 0xfffe : 0xc000); - if (currprefs.mmu_model) - mmu_set_tc (regs.tcr); - break; - - /* no differences between 68040 and 68060 */ - case 4: regs.itt0 = *regp & 0xffffe364; break; - case 5: regs.itt1 = *regp & 0xffffe364; break; - case 6: regs.dtt0 = *regp & 0xffffe364; break; - case 7: regs.dtt1 = *regp & 0xffffe364; break; - /* 68060 only */ - case 8: regs.buscr = *regp & 0xf0000000; break; - - case 0x800: regs.usp = *regp; break; - case 0x801: regs.vbr = *regp; break; - case 0x802: regs.caar = *regp & 0xfc; break; - case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg (regs, 7) = regs.msp; break; - case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg (regs, 7) = regs.isp; break; - /* 68040 only */ - case 0x805: regs.mmusr = *regp; break; - /* 68040/060 */ - case 0x806: regs.urp = *regp & 0xfffffe00; break; - case 0x807: regs.srp = *regp & 0xfffffe00; break; - /* 68060 only */ - case 0x808: - { - uae_u32 opcr = regs.pcr; - regs.pcr &= ~(0x40 | 2 | 1); - regs.pcr |= (*regp) & (0x40 | 2 | 1); - if (((opcr ^ regs.pcr) & 2) == 2) { - write_log (L"68060 FPU state: %s\n", regs.pcr & 2 ? L"disabled" : L"enabled"); - /* flush possible already translated FPU instructions */ - flush_icache (0, 3); - } - } - break; - default: - op_illg (0x4E7B); - return 0; + if (movec_illg (regno)) { + op_illg (0x4E7B); + return 0; + } else { + switch (regno) { + case 0: regs.sfc = *regp & 7; break; + case 1: regs.dfc = *regp & 7; break; + case 2: + { + uae_u32 cacr_mask = 0; + if (currprefs.cpu_model == 68020) + cacr_mask = 0x0000000f; + else if (currprefs.cpu_model == 68030) + cacr_mask = 0x00003f1f; + else if (currprefs.cpu_model == 68040) + cacr_mask = 0x80008000; + else if (currprefs.cpu_model == 68060) + cacr_mask = 0xf8e0e000; + regs.cacr = *regp & cacr_mask; + set_cpu_caches (); + } + break; + /* 68040/060 only */ + case 3: + regs.tcr = *regp & (currprefs.cpu_model == 68060 ? 0xfffe : 0xc000); + if (currprefs.mmu_model) + mmu_set_tc (regs.tcr); + break; + + /* no differences between 68040 and 68060 */ + case 4: regs.itt0 = *regp & 0xffffe364; break; + case 5: regs.itt1 = *regp & 0xffffe364; break; + case 6: regs.dtt0 = *regp & 0xffffe364; break; + case 7: regs.dtt1 = *regp & 0xffffe364; break; + /* 68060 only */ + case 8: regs.buscr = *regp & 0xf0000000; break; + + case 0x800: regs.usp = *regp; break; + case 0x801: regs.vbr = *regp; break; + case 0x802: regs.caar = *regp & 0xfc; break; + case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg (regs, 7) = regs.msp; break; + case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg (regs, 7) = regs.isp; break; + /* 68040 only */ + case 0x805: regs.mmusr = *regp; break; + /* 68040/060 */ + case 0x806: regs.urp = *regp & 0xfffffe00; break; + case 0x807: regs.srp = *regp & 0xfffffe00; break; + /* 68060 only */ + case 0x808: + { + uae_u32 opcr = regs.pcr; + regs.pcr &= ~(0x40 | 2 | 1); + regs.pcr |= (*regp) & (0x40 | 2 | 1); + if (((opcr ^ regs.pcr) & 2) == 2) { + write_log (L"68060 FPU state: %s\n", regs.pcr & 2 ? L"disabled" : L"enabled"); + /* flush possible already translated FPU instructions */ + flush_icache (0, 3); + } + } + break; + default: + op_illg (0x4E7B); + return 0; + } } - } - return 1; + return 1; } int m68k_movec2 (int regno, uae_u32 *regp) { #if MOVEC_DEBUG > 0 - write_log (L"movec2 %04X PC=%x\n", regno, M68K_GETPC); + write_log (L"movec2 %04X PC=%x\n", regno, M68K_GETPC); #endif - if (movec_illg (regno)) { - op_illg (0x4E7A); - return 0; - } else { - switch (regno) { - case 0: *regp = regs.sfc; break; - case 1: *regp = regs.dfc; break; - case 2: - { - uae_u32 v = regs.cacr; - uae_u32 cacr_mask = 0; - if (currprefs.cpu_model == 68020) - cacr_mask = 0x00000003; - else if (currprefs.cpu_model == 68030) - cacr_mask = 0x00003313; - else if (currprefs.cpu_model == 68040) - cacr_mask = 0x80008000; - else if (currprefs.cpu_model == 68060) - cacr_mask = 0xf880e000; - *regp = v & cacr_mask; - } - break; - case 3: *regp = regs.tcr; break; - case 4: *regp = regs.itt0; break; - case 5: *regp = regs.itt1; break; - case 6: *regp = regs.dtt0; break; - case 7: *regp = regs.dtt1; break; - case 8: *regp = regs.buscr; break; - - case 0x800: *regp = regs.usp; break; - case 0x801: *regp = regs.vbr; break; - case 0x802: *regp = regs.caar; break; - case 0x803: *regp = regs.m == 1 ? m68k_areg (regs, 7) : regs.msp; break; - case 0x804: *regp = regs.m == 0 ? m68k_areg (regs, 7) : regs.isp; break; - case 0x805: *regp = regs.mmusr; break; - case 0x806: *regp = regs.urp; break; - case 0x807: *regp = regs.srp; break; - case 0x808: *regp = regs.pcr; break; - - default: - op_illg (0x4E7A); - return 0; + if (movec_illg (regno)) { + op_illg (0x4E7A); + return 0; + } else { + switch (regno) { + case 0: *regp = regs.sfc; break; + case 1: *regp = regs.dfc; break; + case 2: + { + uae_u32 v = regs.cacr; + uae_u32 cacr_mask = 0; + if (currprefs.cpu_model == 68020) + cacr_mask = 0x00000003; + else if (currprefs.cpu_model == 68030) + cacr_mask = 0x00003313; + else if (currprefs.cpu_model == 68040) + cacr_mask = 0x80008000; + else if (currprefs.cpu_model == 68060) + cacr_mask = 0xf880e000; + *regp = v & cacr_mask; + } + break; + case 3: *regp = regs.tcr; break; + case 4: *regp = regs.itt0; break; + case 5: *regp = regs.itt1; break; + case 6: *regp = regs.dtt0; break; + case 7: *regp = regs.dtt1; break; + case 8: *regp = regs.buscr; break; + + case 0x800: *regp = regs.usp; break; + case 0x801: *regp = regs.vbr; break; + case 0x802: *regp = regs.caar; break; + case 0x803: *regp = regs.m == 1 ? m68k_areg (regs, 7) : regs.msp; break; + case 0x804: *regp = regs.m == 0 ? m68k_areg (regs, 7) : regs.isp; break; + case 0x805: *regp = regs.mmusr; break; + case 0x806: *regp = regs.urp; break; + case 0x807: *regp = regs.srp; break; + case 0x808: *regp = regs.pcr; break; + + default: + op_illg (0x4E7A); + return 0; + } } - } #if MOVEC_DEBUG > 0 - write_log (L"-> %08X\n", *regp); + write_log (L"-> %08X\n", *regp); #endif - return 1; + return 1; } STATIC_INLINE int -div_unsigned (uae_u32 src_hi, uae_u32 src_lo, uae_u32 div, uae_u32 *quot, uae_u32 *rem) + div_unsigned (uae_u32 src_hi, uae_u32 src_lo, uae_u32 div, uae_u32 *quot, uae_u32 *rem) { uae_u32 q = 0, cbit = 0; int i; if (div <= src_hi) { - return 1; + return 1; } for (i = 0 ; i < 32 ; i++) { cbit = src_hi & 0x80000000ul; @@ -1950,126 +1951,126 @@ div_unsigned (uae_u32 src_hi, uae_u32 src_lo, uae_u32 div, uae_u32 *quot, uae_u3 void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc) { #if defined (uae_s64) - if (src == 0) { - Exception (5, oldpc); - return; - } - if (extra & 0x800) { - /* signed variant */ - uae_s64 a = (uae_s64)(uae_s32)m68k_dreg (regs, (extra >> 12) & 7); - uae_s64 quot, rem; - - if (extra & 0x400) { - a &= 0xffffffffu; - a |= (uae_s64)m68k_dreg (regs, extra & 7) << 32; - } - rem = a % (uae_s64)(uae_s32)src; - quot = a / (uae_s64)(uae_s32)src; - if ((quot & UVAL64 (0xffffffff80000000)) != 0 - && (quot & UVAL64 (0xffffffff80000000)) != UVAL64 (0xffffffff80000000)) - { - SET_VFLG (1); - SET_NFLG (1); - SET_CFLG (0); - } else { - if (((uae_s32)rem < 0) != ((uae_s64)a < 0)) rem = -rem; - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (((uae_s32)quot) == 0); - SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg (regs, extra & 7) = (uae_u32)rem; - m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)quot; - } - } else { - /* unsigned */ - uae_u64 a = (uae_u64)(uae_u32)m68k_dreg (regs, (extra >> 12) & 7); - uae_u64 quot, rem; - - if (extra & 0x400) { - a &= 0xffffffffu; - a |= (uae_u64)m68k_dreg (regs, extra & 7) << 32; - } - rem = a % (uae_u64)src; - quot = a / (uae_u64)src; - if (quot > 0xffffffffu) { - SET_VFLG (1); - SET_NFLG (1); - SET_CFLG (0); + if (src == 0) { + Exception (5, oldpc); + return; + } + if (extra & 0x800) { + /* signed variant */ + uae_s64 a = (uae_s64)(uae_s32)m68k_dreg (regs, (extra >> 12) & 7); + uae_s64 quot, rem; + + if (extra & 0x400) { + a &= 0xffffffffu; + a |= (uae_s64)m68k_dreg (regs, extra & 7) << 32; + } + rem = a % (uae_s64)(uae_s32)src; + quot = a / (uae_s64)(uae_s32)src; + if ((quot & UVAL64 (0xffffffff80000000)) != 0 + && (quot & UVAL64 (0xffffffff80000000)) != UVAL64 (0xffffffff80000000)) + { + SET_VFLG (1); + SET_NFLG (1); + SET_CFLG (0); + } else { + if (((uae_s32)rem < 0) != ((uae_s64)a < 0)) rem = -rem; + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (((uae_s32)quot) == 0); + SET_NFLG (((uae_s32)quot) < 0); + m68k_dreg (regs, extra & 7) = (uae_u32)rem; + m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)quot; + } } else { - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (((uae_s32)quot) == 0); - SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg (regs, extra & 7) = (uae_u32)rem; - m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)quot; - } - } + /* unsigned */ + uae_u64 a = (uae_u64)(uae_u32)m68k_dreg (regs, (extra >> 12) & 7); + uae_u64 quot, rem; + + if (extra & 0x400) { + a &= 0xffffffffu; + a |= (uae_u64)m68k_dreg (regs, extra & 7) << 32; + } + rem = a % (uae_u64)src; + quot = a / (uae_u64)src; + if (quot > 0xffffffffu) { + SET_VFLG (1); + SET_NFLG (1); + SET_CFLG (0); + } else { + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (((uae_s32)quot) == 0); + SET_NFLG (((uae_s32)quot) < 0); + m68k_dreg (regs, extra & 7) = (uae_u32)rem; + m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)quot; + } + } #else - if (src == 0) { - Exception (5, oldpc); - return; - } - if (extra & 0x800) { - /* signed variant */ - uae_s32 lo = (uae_s32)m68k_dreg (regs, (extra >> 12) & 7); - uae_s32 hi = lo < 0 ? -1 : 0; - uae_s32 save_high; - uae_u32 quot, rem; - uae_u32 sign; - - if (extra & 0x400) { - hi = (uae_s32)m68k_dreg (regs, extra & 7); - } - save_high = hi; - sign = (hi ^ src); - if (hi < 0) { - hi = ~hi; - lo = -lo; - if (lo == 0) hi++; - } - if ((uae_s32)src < 0) src = -src; - if (div_unsigned (hi, lo, src, ", &rem) || - (sign & 0x80000000) ? quot > 0x80000000 : quot > 0x7fffffff) { - SET_VFLG (1); - SET_NFLG (1); - SET_CFLG (0); - } else { - if (sign & 0x80000000) quot = -quot; - if (((uae_s32)rem < 0) != (save_high < 0)) rem = -rem; - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (((uae_s32)quot) == 0); - SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg (regs, extra & 7) = rem; - m68k_dreg (regs, (extra >> 12) & 7) = quot; - } - } else { - /* unsigned */ - uae_u32 lo = (uae_u32)m68k_dreg (regs, (extra >> 12) & 7); - uae_u32 hi = 0; - uae_u32 quot, rem; - - if (extra & 0x400) { - hi = (uae_u32)m68k_dreg (regs, extra & 7); - } - if (div_unsigned (hi, lo, src, ", &rem)) { - SET_VFLG (1); - SET_NFLG (1); - SET_CFLG (0); + if (src == 0) { + Exception (5, oldpc); + return; + } + if (extra & 0x800) { + /* signed variant */ + uae_s32 lo = (uae_s32)m68k_dreg (regs, (extra >> 12) & 7); + uae_s32 hi = lo < 0 ? -1 : 0; + uae_s32 save_high; + uae_u32 quot, rem; + uae_u32 sign; + + if (extra & 0x400) { + hi = (uae_s32)m68k_dreg (regs, extra & 7); + } + save_high = hi; + sign = (hi ^ src); + if (hi < 0) { + hi = ~hi; + lo = -lo; + if (lo == 0) hi++; + } + if ((uae_s32)src < 0) src = -src; + if (div_unsigned (hi, lo, src, ", &rem) || + (sign & 0x80000000) ? quot > 0x80000000 : quot > 0x7fffffff) { + SET_VFLG (1); + SET_NFLG (1); + SET_CFLG (0); + } else { + if (sign & 0x80000000) quot = -quot; + if (((uae_s32)rem < 0) != (save_high < 0)) rem = -rem; + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (((uae_s32)quot) == 0); + SET_NFLG (((uae_s32)quot) < 0); + m68k_dreg (regs, extra & 7) = rem; + m68k_dreg (regs, (extra >> 12) & 7) = quot; + } } else { - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (((uae_s32)quot) == 0); - SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg (regs, extra & 7) = rem; - m68k_dreg (regs, (extra >> 12) & 7) = quot; - } - } + /* unsigned */ + uae_u32 lo = (uae_u32)m68k_dreg (regs, (extra >> 12) & 7); + uae_u32 hi = 0; + uae_u32 quot, rem; + + if (extra & 0x400) { + hi = (uae_u32)m68k_dreg (regs, extra & 7); + } + if (div_unsigned (hi, lo, src, ", &rem)) { + SET_VFLG (1); + SET_NFLG (1); + SET_CFLG (0); + } else { + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (((uae_s32)quot) == 0); + SET_NFLG (((uae_s32)quot) < 0); + m68k_dreg (regs, extra & 7) = rem; + m68k_dreg (regs, (extra >> 12) & 7) = quot; + } + } #endif } STATIC_INLINE void -mul_unsigned (uae_u32 src1, uae_u32 src2, uae_u32 *dst_hi, uae_u32 *dst_lo) + mul_unsigned (uae_u32 src1, uae_u32 src2, uae_u32 *dst_hi, uae_u32 *dst_lo) { uae_u32 r0 = (src1 & 0xffff) * (src2 & 0xffff); uae_u32 r1 = ((src1 >> 16) & 0xffff) * (src2 & 0xffff); @@ -2090,87 +2091,87 @@ mul_unsigned (uae_u32 src1, uae_u32 src2, uae_u32 *dst_hi, uae_u32 *dst_lo) void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra) { #if defined (uae_s64) - if (extra & 0x800) { - /* signed variant */ - uae_s64 a = (uae_s64)(uae_s32)m68k_dreg (regs, (extra >> 12) & 7); - - a *= (uae_s64)(uae_s32)src; - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (a == 0); - SET_NFLG (a < 0); - if (extra & 0x400) - m68k_dreg (regs, extra & 7) = (uae_u32)(a >> 32); - else if ((a & UVAL64 (0xffffffff80000000)) != 0 - && (a & UVAL64 (0xffffffff80000000)) != UVAL64 (0xffffffff80000000)) - { - SET_VFLG (1); + if (extra & 0x800) { + /* signed variant */ + uae_s64 a = (uae_s64)(uae_s32)m68k_dreg (regs, (extra >> 12) & 7); + + a *= (uae_s64)(uae_s32)src; + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (a == 0); + SET_NFLG (a < 0); + if (extra & 0x400) + m68k_dreg (regs, extra & 7) = (uae_u32)(a >> 32); + else if ((a & UVAL64 (0xffffffff80000000)) != 0 + && (a & UVAL64 (0xffffffff80000000)) != UVAL64 (0xffffffff80000000)) + { + SET_VFLG (1); + } + m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)a; + } else { + /* unsigned */ + uae_u64 a = (uae_u64)(uae_u32)m68k_dreg (regs, (extra >> 12) & 7); + + a *= (uae_u64)src; + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (a == 0); + SET_NFLG (((uae_s64)a) < 0); + if (extra & 0x400) + m68k_dreg (regs, extra & 7) = (uae_u32)(a >> 32); + else if ((a & UVAL64 (0xffffffff00000000)) != 0) { + SET_VFLG (1); + } + m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)a; } - m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)a; - } else { - /* unsigned */ - uae_u64 a = (uae_u64)(uae_u32)m68k_dreg (regs, (extra >> 12) & 7); - - a *= (uae_u64)src; - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (a == 0); - SET_NFLG (((uae_s64)a) < 0); - if (extra & 0x400) - m68k_dreg (regs, extra & 7) = (uae_u32)(a >> 32); - else if ((a & UVAL64 (0xffffffff00000000)) != 0) { - SET_VFLG (1); - } - m68k_dreg (regs, (extra >> 12) & 7) = (uae_u32)a; - } #else - if (extra & 0x800) { - /* signed variant */ - uae_s32 src1, src2; - uae_u32 dst_lo, dst_hi; - uae_u32 sign; - - src1 = (uae_s32)src; - src2 = (uae_s32)m68k_dreg (regs, (extra >> 12) & 7); - sign = (src1 ^ src2); - if (src1 < 0) src1 = -src1; - if (src2 < 0) src2 = -src2; - mul_unsigned ((uae_u32)src1, (uae_u32)src2, &dst_hi, &dst_lo); - if (sign & 0x80000000) { - dst_hi = ~dst_hi; - dst_lo = -dst_lo; - if (dst_lo == 0) dst_hi++; - } - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (dst_hi == 0 && dst_lo == 0); - SET_NFLG (((uae_s32)dst_hi) < 0); - if (extra & 0x400) - m68k_dreg (regs, extra & 7) = dst_hi; - else if ((dst_hi != 0 || (dst_lo & 0x80000000) != 0) - && ((dst_hi & 0xffffffff) != 0xffffffff - || (dst_lo & 0x80000000) != 0x80000000)) - { - SET_VFLG (1); + if (extra & 0x800) { + /* signed variant */ + uae_s32 src1, src2; + uae_u32 dst_lo, dst_hi; + uae_u32 sign; + + src1 = (uae_s32)src; + src2 = (uae_s32)m68k_dreg (regs, (extra >> 12) & 7); + sign = (src1 ^ src2); + if (src1 < 0) src1 = -src1; + if (src2 < 0) src2 = -src2; + mul_unsigned ((uae_u32)src1, (uae_u32)src2, &dst_hi, &dst_lo); + if (sign & 0x80000000) { + dst_hi = ~dst_hi; + dst_lo = -dst_lo; + if (dst_lo == 0) dst_hi++; + } + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (dst_hi == 0 && dst_lo == 0); + SET_NFLG (((uae_s32)dst_hi) < 0); + if (extra & 0x400) + m68k_dreg (regs, extra & 7) = dst_hi; + else if ((dst_hi != 0 || (dst_lo & 0x80000000) != 0) + && ((dst_hi & 0xffffffff) != 0xffffffff + || (dst_lo & 0x80000000) != 0x80000000)) + { + SET_VFLG (1); + } + m68k_dreg (regs, (extra >> 12) & 7) = dst_lo; + } else { + /* unsigned */ + uae_u32 dst_lo, dst_hi; + + mul_unsigned (src, (uae_u32)m68k_dreg (regs, (extra >> 12) & 7), &dst_hi, &dst_lo); + + SET_VFLG (0); + SET_CFLG (0); + SET_ZFLG (dst_hi == 0 && dst_lo == 0); + SET_NFLG (((uae_s32)dst_hi) < 0); + if (extra & 0x400) + m68k_dreg (regs, extra & 7) = dst_hi; + else if (dst_hi != 0) { + SET_VFLG (1); + } + m68k_dreg (regs, (extra >> 12) & 7) = dst_lo; } - m68k_dreg (regs, (extra >> 12) & 7) = dst_lo; - } else { - /* unsigned */ - uae_u32 dst_lo, dst_hi; - - mul_unsigned (src, (uae_u32)m68k_dreg (regs, (extra >> 12) & 7), &dst_hi, &dst_lo); - - SET_VFLG (0); - SET_CFLG (0); - SET_ZFLG (dst_hi == 0 && dst_lo == 0); - SET_NFLG (((uae_s32)dst_hi) < 0); - if (extra & 0x400) - m68k_dreg (regs, extra & 7) = dst_hi; - else if (dst_hi != 0) { - SET_VFLG (1); - } - m68k_dreg (regs, (extra >> 12) & 7) = dst_lo; - } #endif } @@ -2178,158 +2179,158 @@ void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra) void m68k_reset (int hardreset) { - regs.spcflags = 0; + regs.spcflags = 0; #ifdef SAVESTATE - if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) { - m68k_setpc (regs.pc); - /* MakeFromSR () must not swap stack pointer */ - regs.s = (regs.sr >> 13) & 1; - MakeFromSR (); - /* set stack pointer */ - if (regs.s) - m68k_areg (regs, 7) = regs.isp; - else - m68k_areg (regs, 7) = regs.usp; - return; - } + if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) { + m68k_setpc (regs.pc); + /* MakeFromSR () must not swap stack pointer */ + regs.s = (regs.sr >> 13) & 1; + MakeFromSR (); + /* set stack pointer */ + if (regs.s) + m68k_areg (regs, 7) = regs.isp; + else + m68k_areg (regs, 7) = regs.usp; + return; + } #endif - m68k_areg (regs, 7) = get_long (0); - m68k_setpc (get_long (4)); - regs.s = 1; - regs.m = 0; - regs.stopped = 0; - regs.t1 = 0; - regs.t0 = 0; - SET_ZFLG (0); - SET_XFLG (0); - SET_CFLG (0); - SET_VFLG (0); - SET_NFLG (0); - regs.intmask = 7; - regs.vbr = regs.sfc = regs.dfc = 0; - regs.irc = 0xffff; + m68k_areg (regs, 7) = get_long (0); + m68k_setpc (get_long (4)); + regs.s = 1; + regs.m = 0; + regs.stopped = 0; + regs.t1 = 0; + regs.t0 = 0; + SET_ZFLG (0); + SET_XFLG (0); + SET_CFLG (0); + SET_VFLG (0); + SET_NFLG (0); + regs.intmask = 7; + regs.vbr = regs.sfc = regs.dfc = 0; + regs.irc = 0xffff; #ifdef FPUEMU - fpu_reset (); + fpu_reset (); #endif - regs.caar = regs.cacr = 0; - regs.itt0 = regs.itt1 = regs.dtt0 = regs.dtt1 = 0; - regs.tcr = regs.mmusr = regs.urp = regs.srp = regs.buscr = 0; - if (currprefs.cpu_model == 68020) { - regs.cacr |= 8; - set_cpu_caches (); - } - - mmufixup[0].reg = -1; - mmufixup[1].reg = -1; - if (currprefs.mmu_model) { - mmu_reset (); - mmu_set_tc (regs.tcr); - mmu_set_super (regs.s); - } - - a3000_fakekick (0); - /* only (E)nable bit is zeroed when CPU is reset, A3000 SuperKickstart expects this */ - tc_030 &= ~0x80000000; - tt0_030 &= ~0x80000000; - tt1_030 &= ~0x80000000; - if (hardreset) { - srp_030 = crp_030 = 0; - tt0_030 = tt1_030 = tc_030 = 0; - } - mmusr_030 = 0; - - /* 68060 FPU is not compatible with 68040, - * 68060 accelerators' boot ROM disables the FPU - */ - regs.pcr = 0; - if (currprefs.cpu_model == 68060) { - regs.pcr = currprefs.fpu_model == 68060 ? MC68060_PCR : MC68EC060_PCR; - regs.pcr |= (currprefs.cpu060_revision & 0xff) << 8; - if (kickstart_rom) - regs.pcr |= 2; /* disable FPU */ - } - fill_prefetch_slow (); + regs.caar = regs.cacr = 0; + regs.itt0 = regs.itt1 = regs.dtt0 = regs.dtt1 = 0; + regs.tcr = regs.mmusr = regs.urp = regs.srp = regs.buscr = 0; + if (currprefs.cpu_model == 68020) { + regs.cacr |= 8; + set_cpu_caches (); + } + + mmufixup[0].reg = -1; + mmufixup[1].reg = -1; + if (currprefs.mmu_model) { + mmu_reset (); + mmu_set_tc (regs.tcr); + mmu_set_super (regs.s); + } + + a3000_fakekick (0); + /* only (E)nable bit is zeroed when CPU is reset, A3000 SuperKickstart expects this */ + tc_030 &= ~0x80000000; + tt0_030 &= ~0x80000000; + tt1_030 &= ~0x80000000; + if (hardreset) { + srp_030 = crp_030 = 0; + tt0_030 = tt1_030 = tc_030 = 0; + } + mmusr_030 = 0; + + /* 68060 FPU is not compatible with 68040, + * 68060 accelerators' boot ROM disables the FPU + */ + regs.pcr = 0; + if (currprefs.cpu_model == 68060) { + regs.pcr = currprefs.fpu_model == 68060 ? MC68060_PCR : MC68EC060_PCR; + regs.pcr |= (currprefs.cpu060_revision & 0xff) << 8; + if (kickstart_rom) + regs.pcr |= 2; /* disable FPU */ + } + fill_prefetch_slow (); } STATIC_INLINE int in_rom (uaecptr pc) { - return (munge24 (pc) & 0xFFF80000) == 0xF80000; + return (munge24 (pc) & 0xFFF80000) == 0xF80000; } STATIC_INLINE int in_rtarea (uaecptr pc) { - return (munge24 (pc) & 0xFFFF0000) == rtarea_base && uae_boot_rom; + return (munge24 (pc) & 0xFFFF0000) == rtarea_base && uae_boot_rom; } unsigned long REGPARAM2 op_illg (uae_u32 opcode) { - uaecptr pc = m68k_getpc (); - static int warned; - int inrom = in_rom (pc); - int inrt = in_rtarea (pc); - - if (cloanto_rom && (opcode & 0xF100) == 0x7100) { - m68k_dreg (regs, (opcode >> 9) & 7) = (uae_s8)(opcode & 0xFF); - m68k_incpc (2); - fill_prefetch_slow (); - return 4; - } + uaecptr pc = m68k_getpc (); + static int warned; + int inrom = in_rom (pc); + int inrt = in_rtarea (pc); + + if (cloanto_rom && (opcode & 0xF100) == 0x7100) { + m68k_dreg (regs, (opcode >> 9) & 7) = (uae_s8)(opcode & 0xFF); + m68k_incpc (2); + fill_prefetch_slow (); + return 4; + } - if (opcode == 0x4E7B && inrom && get_long (0x10) == 0) { - notify_user (NUMSG_KS68020); - uae_restart (-1, NULL); - } + if (opcode == 0x4E7B && inrom && get_long (0x10) == 0) { + notify_user (NUMSG_KS68020); + uae_restart (-1, NULL); + } #ifdef AUTOCONFIG - if (opcode == 0xFF0D) { - if (inrom) { - /* This is from the dummy Kickstart replacement */ - uae_u16 arg = get_iword (2); - m68k_incpc (4); - ersatz_perform (arg); - fill_prefetch_slow (); - return 4; - } else if (inrt) { - /* User-mode STOP replacement */ - m68k_setstopped (); - return 4; - } - } - - if ((opcode & 0xF000) == 0xA000 && inrt) { - /* Calltrap. */ - m68k_incpc (2); - m68k_handle_trap (opcode & 0xFFF); - fill_prefetch_slow (); - return 4; - } + if (opcode == 0xFF0D) { + if (inrom) { + /* This is from the dummy Kickstart replacement */ + uae_u16 arg = get_iword (2); + m68k_incpc (4); + ersatz_perform (arg); + fill_prefetch_slow (); + return 4; + } else if (inrt) { + /* User-mode STOP replacement */ + m68k_setstopped (); + return 4; + } + } + + if ((opcode & 0xF000) == 0xA000 && inrt) { + /* Calltrap. */ + m68k_incpc (2); + m68k_handle_trap (opcode & 0xFFF); + fill_prefetch_slow (); + return 4; + } #endif - if ((opcode & 0xF000) == 0xF000) { - if (warned < 20) { - write_log (L"B-Trap %x at %x (%p)\n", opcode, pc, regs.pc_p); - //activate_debugger (); - warned++; + if ((opcode & 0xF000) == 0xF000) { + if (warned < 20) { + write_log (L"B-Trap %x at %x (%p)\n", opcode, pc, regs.pc_p); + //activate_debugger (); + warned++; + } + Exception (0xB, 0); + return 4; + } + if ((opcode & 0xF000) == 0xA000) { + if (warned < 20) { + write_log (L"A-Trap %x at %x (%p)\n", opcode, pc, regs.pc_p); + warned++; + } + Exception (0xA, 0); + return 4; } - Exception (0xB, 0); - return 4; - } - if ((opcode & 0xF000) == 0xA000) { if (warned < 20) { - write_log (L"A-Trap %x at %x (%p)\n", opcode, pc, regs.pc_p); - warned++; + write_log (L"Illegal instruction: %04x at %08X -> %08X\n", opcode, pc, get_long (regs.vbr + 0x10)); + //activate_debugger (); + warned++; } - Exception (0xA, 0); + + Exception (4, 0); return 4; - } - if (warned < 20) { - write_log (L"Illegal instruction: %04x at %08X -> %08X\n", opcode, pc, get_long (regs.vbr + 0x10)); - //activate_debugger (); - warned++; - } - - Exception (4, 0); - return 4; } #ifdef CPUEMU_0 @@ -2338,179 +2339,179 @@ static TCHAR *mmu30regs[] = { L"TCR", L"", L"SRP", L"CRP", L"", L"", L"", L"" }; static void mmu_op30_pmove (uaecptr pc, uae_u32 opcode, uae_u16 next, uaecptr extra) { - int preg = (next >> 10) & 31; - int rw = (next >> 9) & 1; - int fd = (next >> 8) & 1; - TCHAR *reg = NULL; - uae_u32 otc = tc_030; - int siz; - - switch (preg) - { - case 0x10: // TC - reg = L"TC"; - siz = 4; - if (rw) - put_long (extra, tc_030); - else - tc_030 = get_long (extra); - break; - case 0x12: // SRP - reg = L"SRP"; - siz = 8; - if (rw) { - put_long (extra, srp_030 >> 32); - put_long (extra + 4, srp_030); - } else { - srp_030 = (uae_u64)get_long (extra) << 32; - srp_030 |= get_long (extra + 4); - } - break; - case 0x13: // CRP - reg = L"CRP"; - siz = 8; - if (rw) { - put_long (extra, crp_030 >> 32); - put_long (extra + 4, crp_030); - } else { - crp_030 = (uae_u64)get_long (extra) << 32; - crp_030 |= get_long (extra + 4); - } - break; - case 0x18: // MMUSR - reg = L"MMUSR"; - siz = 2; - if (rw) - put_word (extra, mmusr_030); - else - mmusr_030 = get_word (extra); - break; - case 0x02: // TT0 - reg = L"TT0"; - siz = 4; - if (rw) - put_long (extra, tt0_030); - else - tt0_030 = get_long (extra); - break; - case 0x03: // TT1 - reg = L"TT1"; - siz = 4; - if (rw) - put_long (extra, tt1_030); - else - tt1_030 = get_long (extra); - break; - } + int preg = (next >> 10) & 31; + int rw = (next >> 9) & 1; + int fd = (next >> 8) & 1; + TCHAR *reg = NULL; + uae_u32 otc = tc_030; + int siz; + + switch (preg) + { + case 0x10: // TC + reg = L"TC"; + siz = 4; + if (rw) + put_long (extra, tc_030); + else + tc_030 = get_long (extra); + break; + case 0x12: // SRP + reg = L"SRP"; + siz = 8; + if (rw) { + put_long (extra, srp_030 >> 32); + put_long (extra + 4, srp_030); + } else { + srp_030 = (uae_u64)get_long (extra) << 32; + srp_030 |= get_long (extra + 4); + } + break; + case 0x13: // CRP + reg = L"CRP"; + siz = 8; + if (rw) { + put_long (extra, crp_030 >> 32); + put_long (extra + 4, crp_030); + } else { + crp_030 = (uae_u64)get_long (extra) << 32; + crp_030 |= get_long (extra + 4); + } + break; + case 0x18: // MMUSR + reg = L"MMUSR"; + siz = 2; + if (rw) + put_word (extra, mmusr_030); + else + mmusr_030 = get_word (extra); + break; + case 0x02: // TT0 + reg = L"TT0"; + siz = 4; + if (rw) + put_long (extra, tt0_030); + else + tt0_030 = get_long (extra); + break; + case 0x03: // TT1 + reg = L"TT1"; + siz = 4; + if (rw) + put_long (extra, tt1_030); + else + tt1_030 = get_long (extra); + break; + } - if (!reg) { - op_illg (opcode); - return; - } + if (!reg) { + op_illg (opcode); + return; + } #if MMUOP_DEBUG > 0 - { - uae_u32 val; - if (siz == 8) { - uae_u32 val2 = get_long (extra); - val = get_long (extra + 4); - if (rw) - write_log (L"PMOVE %s,%08X%08X", reg, val2, val); - else - write_log (L"PMOVE %08X%08X,%s", val2, val, reg); - } else { - if (siz == 4) - val = get_long (extra); - else - val = get_word (extra); - if (rw) - write_log (L"PMOVE %s,%08X", reg, val); - else - write_log (L"PMOVE %08X,%s", val, reg); - } - write_log (L" PC=%08X\n", pc); - } + { + uae_u32 val; + if (siz == 8) { + uae_u32 val2 = get_long (extra); + val = get_long (extra + 4); + if (rw) + write_log (L"PMOVE %s,%08X%08X", reg, val2, val); + else + write_log (L"PMOVE %08X%08X,%s", val2, val, reg); + } else { + if (siz == 4) + val = get_long (extra); + else + val = get_word (extra); + if (rw) + write_log (L"PMOVE %s,%08X", reg, val); + else + write_log (L"PMOVE %08X,%s", val, reg); + } + write_log (L" PC=%08X\n", pc); + } #endif - if (currprefs.cs_mbdmac == 1 && currprefs.mbresmem_low_size > 0) { - if (otc != tc_030) { - a3000_fakekick (tc_030 & 0x80000000); + if (currprefs.cs_mbdmac == 1 && currprefs.mbresmem_low_size > 0) { + if (otc != tc_030) { + a3000_fakekick (tc_030 & 0x80000000); + } } - } } static void mmu_op30_ptest (uaecptr pc, uae_u32 opcode, uae_u16 next, uaecptr extra) { #if MMUOP_DEBUG > 0 - TCHAR tmp[10]; + TCHAR tmp[10]; - tmp[0] = 0; - if ((next >> 8) & 1) - _stprintf (tmp, L",A%d", (next >> 4) & 15); - write_log (L"PTEST%c %02X,%08X,#%X%s PC=%08X\n", - ((next >> 9) & 1) ? 'W' : 'R', (next & 15), extra, (next >> 10) & 7, tmp, pc); + tmp[0] = 0; + if ((next >> 8) & 1) + _stprintf (tmp, L",A%d", (next >> 4) & 15); + write_log (L"PTEST%c %02X,%08X,#%X%s PC=%08X\n", + ((next >> 9) & 1) ? 'W' : 'R', (next & 15), extra, (next >> 10) & 7, tmp, pc); #endif - mmusr_030 = 0; + mmusr_030 = 0; } static void mmu_op30_pflush (uaecptr pc, uae_u32 opcode, uae_u16 next, uaecptr extra) { #if MMUOP_DEBUG > 0 - write_log (L"PFLUSH PC=%08X\n", pc); + write_log (L"PFLUSH PC=%08X\n", pc); #endif } void mmu_op30 (uaecptr pc, uae_u32 opcode, uae_u16 extra, uaecptr extraa) { - if (currprefs.cpu_model != 68030) { - m68k_setpc (pc); - op_illg (opcode); - return; - } - if (extra & 0x8000) - mmu_op30_ptest (pc, opcode, extra, extraa); - else if (extra & 0x2000) - mmu_op30_pflush (pc, opcode, extra, extraa); - else - mmu_op30_pmove (pc, opcode, extra, extraa); + if (currprefs.cpu_model != 68030) { + m68k_setpc (pc); + op_illg (opcode); + return; + } + if (extra & 0x8000) + mmu_op30_ptest (pc, opcode, extra, extraa); + else if (extra & 0x2000) + mmu_op30_pflush (pc, opcode, extra, extraa); + else + mmu_op30_pmove (pc, opcode, extra, extraa); } void mmu_op (uae_u32 opcode, uae_u32 extra) { - if (currprefs.cpu_model) { - mmu_op_real (opcode, extra); - return; - } + if (currprefs.cpu_model) { + mmu_op_real (opcode, extra); + return; + } #if MMUOP_DEBUG > 1 - write_log (L"mmu_op %04X PC=%08X\n", opcode, m68k_getpc ()); + write_log (L"mmu_op %04X PC=%08X\n", opcode, m68k_getpc ()); #endif - if ((opcode & 0xFE0) == 0x0500) { - /* PFLUSH */ - regs.mmusr = 0; + if ((opcode & 0xFE0) == 0x0500) { + /* PFLUSH */ + regs.mmusr = 0; #if MMUOP_DEBUG > 0 - write_log (L"PFLUSH\n"); + write_log (L"PFLUSH\n"); #endif - return; - } else if ((opcode & 0x0FD8) == 0x548) { - if (currprefs.cpu_model < 68060) { /* PTEST not in 68060 */ - /* PTEST */ + return; + } else if ((opcode & 0x0FD8) == 0x548) { + if (currprefs.cpu_model < 68060) { /* PTEST not in 68060 */ + /* PTEST */ #if MMUOP_DEBUG > 0 - write_log (L"PTEST\n"); + write_log (L"PTEST\n"); #endif - return; - } - } else if ((opcode & 0x0FB8) == 0x588) { - /* PLPA */ - if (currprefs.cpu_model == 68060) { + return; + } + } else if ((opcode & 0x0FB8) == 0x588) { + /* PLPA */ + if (currprefs.cpu_model == 68060) { #if MMUOP_DEBUG > 0 - write_log (L"PLPA\n"); + write_log (L"PLPA\n"); #endif - return; + return; + } } - } #if MMUOP_DEBUG > 0 - write_log (L"Unknown MMU OP %04X\n", opcode); + write_log (L"Unknown MMU OP %04X\n", opcode); #endif - m68k_setpc (m68k_getpc () - 2); - op_illg (opcode); + m68k_setpc (m68k_getpc () - 2); + op_illg (opcode); } #endif @@ -2519,40 +2520,40 @@ static uaecptr last_trace_ad = 0; static void do_trace (void) { - if (regs.t0 && currprefs.cpu_model >= 68020) { - uae_u16 opcode; - /* should also include TRAP, CHK, SR modification FPcc */ - /* probably never used so why bother */ - /* We can afford this to be inefficient... */ - m68k_setpc (m68k_getpc ()); - fill_prefetch_slow (); - if (currprefs.mmu_model) - opcode = get_word_mmu (regs.pc); - else - opcode = get_word (regs.pc); - if (opcode == 0x4e73 /* RTE */ - || opcode == 0x4e74 /* RTD */ - || opcode == 0x4e75 /* RTS */ - || opcode == 0x4e77 /* RTR */ - || opcode == 0x4e76 /* TRAPV */ - || (opcode & 0xffc0) == 0x4e80 /* JSR */ - || (opcode & 0xffc0) == 0x4ec0 /* JMP */ - || (opcode & 0xff00) == 0x6100 /* BSR */ - || ((opcode & 0xf000) == 0x6000 /* Bcc */ - && cctrue ((opcode >> 8) & 0xf)) - || ((opcode & 0xf0f0) == 0x5050 /* DBcc */ - && !cctrue ((opcode >> 8) & 0xf) - && (uae_s16)m68k_dreg (regs, opcode & 7) != 0)) - { - last_trace_ad = m68k_getpc (); - unset_special (SPCFLAG_TRACE); - set_special (SPCFLAG_DOTRACE); - } - } else if (regs.t1) { - last_trace_ad = m68k_getpc (); - unset_special (SPCFLAG_TRACE); - set_special (SPCFLAG_DOTRACE); - } + if (regs.t0 && currprefs.cpu_model >= 68020) { + uae_u16 opcode; + /* should also include TRAP, CHK, SR modification FPcc */ + /* probably never used so why bother */ + /* We can afford this to be inefficient... */ + m68k_setpc (m68k_getpc ()); + fill_prefetch_slow (); + if (currprefs.mmu_model) + opcode = get_word_mmu (regs.pc); + else + opcode = get_word (regs.pc); + if (opcode == 0x4e73 /* RTE */ + || opcode == 0x4e74 /* RTD */ + || opcode == 0x4e75 /* RTS */ + || opcode == 0x4e77 /* RTR */ + || opcode == 0x4e76 /* TRAPV */ + || (opcode & 0xffc0) == 0x4e80 /* JSR */ + || (opcode & 0xffc0) == 0x4ec0 /* JMP */ + || (opcode & 0xff00) == 0x6100 /* BSR */ + || ((opcode & 0xf000) == 0x6000 /* Bcc */ + && cctrue ((opcode >> 8) & 0xf)) + || ((opcode & 0xf0f0) == 0x5050 /* DBcc */ + && !cctrue ((opcode >> 8) & 0xf) + && (uae_s16)m68k_dreg (regs, opcode & 7) != 0)) + { + last_trace_ad = m68k_getpc (); + unset_special (SPCFLAG_TRACE); + set_special (SPCFLAG_DOTRACE); + } + } else if (regs.t1) { + last_trace_ad = m68k_getpc (); + unset_special (SPCFLAG_TRACE); + set_special (SPCFLAG_DOTRACE); + } } @@ -2562,158 +2563,158 @@ static unsigned long interrupt_cycles; // handle interrupt delay (few cycles) STATIC_INLINE int time_for_interrupt (void) { - if (!interrupt_cycles_active) + if (!interrupt_cycles_active) + return 1; + if ((int)get_cycles () - (int)interrupt_cycles < 0) + return 0; + interrupt_cycles_active = 0; return 1; - if ((int)get_cycles () - (int)interrupt_cycles < 0) - return 0; - interrupt_cycles_active = 0; - return 1; } #define IDLETIME (currprefs.cpu_idle * sleep_resolution / 700) STATIC_INLINE int do_specialties (int cycles) { - #ifdef ACTION_REPLAY - #ifdef ACTION_REPLAY_HRTMON - if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && hrtmon_flag != ACTION_REPLAY_INACTIVE) { - int isinhrt = (m68k_getpc () >= hrtmem_start && m68k_getpc () < hrtmem_start + hrtmem_size); - /* exit from HRTMon? */ - if (hrtmon_flag == ACTION_REPLAY_ACTIVE && !isinhrt) - hrtmon_hide (); - /* HRTMon breakpoint? (not via IRQ7) */ - if (hrtmon_flag == ACTION_REPLAY_IDLE && isinhrt) - hrtmon_breakenter (); - if (hrtmon_flag == ACTION_REPLAY_ACTIVATE) - hrtmon_enter (); - if (!(regs.spcflags & ~SPCFLAG_ACTION_REPLAY)) - return 0; - } - #endif - if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && action_replay_flag != ACTION_REPLAY_INACTIVE) { - /*if (action_replay_flag == ACTION_REPLAY_ACTIVE && !is_ar_pc_in_rom ())*/ - /* write_log (L"PC:%p\n", m68k_getpc ());*/ - - if (action_replay_flag == ACTION_REPLAY_ACTIVATE || action_replay_flag == ACTION_REPLAY_DORESET) - action_replay_enter (); - if (action_replay_flag == ACTION_REPLAY_HIDE && !is_ar_pc_in_rom ()) { - action_replay_hide (); - unset_special (SPCFLAG_ACTION_REPLAY); - } - if (action_replay_flag == ACTION_REPLAY_WAIT_PC) { - /*write_log (L"Waiting for PC: %p, current PC= %p\n", wait_for_pc, m68k_getpc ());*/ - if (m68k_getpc () == wait_for_pc) { - action_replay_flag = ACTION_REPLAY_ACTIVATE; /* Activate after next instruction. */ - } - } - } - #endif - - if (regs.spcflags & SPCFLAG_COPPER) - do_copper (); - - /*n_spcinsns++;*/ -#ifdef JIT - unset_special (SPCFLAG_END_COMPILE); /* has done its job */ +#ifdef ACTION_REPLAY +#ifdef ACTION_REPLAY_HRTMON + if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && hrtmon_flag != ACTION_REPLAY_INACTIVE) { + int isinhrt = (m68k_getpc () >= hrtmem_start && m68k_getpc () < hrtmem_start + hrtmem_size); + /* exit from HRTMon? */ + if (hrtmon_flag == ACTION_REPLAY_ACTIVE && !isinhrt) + hrtmon_hide (); + /* HRTMon breakpoint? (not via IRQ7) */ + if (hrtmon_flag == ACTION_REPLAY_IDLE && isinhrt) + hrtmon_breakenter (); + if (hrtmon_flag == ACTION_REPLAY_ACTIVATE) + hrtmon_enter (); + if (!(regs.spcflags & ~SPCFLAG_ACTION_REPLAY)) + return 0; + } +#endif + if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && action_replay_flag != ACTION_REPLAY_INACTIVE) { + /*if (action_replay_flag == ACTION_REPLAY_ACTIVE && !is_ar_pc_in_rom ())*/ + /* write_log (L"PC:%p\n", m68k_getpc ());*/ + + if (action_replay_flag == ACTION_REPLAY_ACTIVATE || action_replay_flag == ACTION_REPLAY_DORESET) + action_replay_enter (); + if (action_replay_flag == ACTION_REPLAY_HIDE && !is_ar_pc_in_rom ()) { + action_replay_hide (); + unset_special (SPCFLAG_ACTION_REPLAY); + } + if (action_replay_flag == ACTION_REPLAY_WAIT_PC) { + /*write_log (L"Waiting for PC: %p, current PC= %p\n", wait_for_pc, m68k_getpc ());*/ + if (m68k_getpc () == wait_for_pc) { + action_replay_flag = ACTION_REPLAY_ACTIVATE; /* Activate after next instruction. */ + } + } + } #endif - while ((regs.spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && !currprefs.blitter_cycle_exact) { - int c = blitnasty (); - if (c > 0) { - cycles -= c * CYCLE_UNIT * 2; - if (cycles < CYCLE_UNIT) - cycles = 0; - } else - c = 4; - do_cycles (c * CYCLE_UNIT); if (regs.spcflags & SPCFLAG_COPPER) - do_copper (); - } + do_copper (); - if (regs.spcflags & SPCFLAG_DOTRACE) - Exception (9, last_trace_ad); + /*n_spcinsns++;*/ +#ifdef JIT + unset_special (SPCFLAG_END_COMPILE); /* has done its job */ +#endif - if (regs.spcflags & SPCFLAG_TRAP) { - unset_special (SPCFLAG_TRAP); - Exception (3, 0); - } + while ((regs.spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && !currprefs.blitter_cycle_exact) { + int c = blitnasty (); + if (c > 0) { + cycles -= c * CYCLE_UNIT * 2; + if (cycles < CYCLE_UNIT) + cycles = 0; + } else + c = 4; + do_cycles (c * CYCLE_UNIT); + if (regs.spcflags & SPCFLAG_COPPER) + do_copper (); + } - while (regs.spcflags & SPCFLAG_STOP) { - do_cycles (4 * CYCLE_UNIT); - if (regs.spcflags & SPCFLAG_COPPER) - do_copper (); - if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { - if (time_for_interrupt ()) { - int intr = intlev (); - unset_special (SPCFLAG_INT | SPCFLAG_DOINT); - if (intr != -1 && intr > regs.intmask) - do_interrupt (intr); - } + if (regs.spcflags & SPCFLAG_DOTRACE) + Exception (9, last_trace_ad); + + if (regs.spcflags & SPCFLAG_TRAP) { + unset_special (SPCFLAG_TRAP); + Exception (3, 0); } - if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) { - unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); - // SPCFLAG_BRK breaks STOP condition, need to prefetch - m68k_resumestopped (); - return 1; - } - - if (currprefs.cpu_idle && currprefs.m68k_speed != 0 && ((regs.spcflags & SPCFLAG_STOP)) == SPCFLAG_STOP) { - /* sleep 1ms if STOP-instruction is executed */ - if (1) { - static int sleepcnt, lvpos, zerocnt; - if (vpos != lvpos) { - sleepcnt--; + + while (regs.spcflags & SPCFLAG_STOP) { + do_cycles (4 * CYCLE_UNIT); + if (regs.spcflags & SPCFLAG_COPPER) + do_copper (); + if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { + if (time_for_interrupt ()) { + int intr = intlev (); + unset_special (SPCFLAG_INT | SPCFLAG_DOINT); + if (intr != -1 && intr > regs.intmask) + do_interrupt (intr); + } + } + if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) { + unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); + // SPCFLAG_BRK breaks STOP condition, need to prefetch + m68k_resumestopped (); + return 1; + } + + if (currprefs.cpu_idle && currprefs.m68k_speed != 0 && ((regs.spcflags & SPCFLAG_STOP)) == SPCFLAG_STOP) { + /* sleep 1ms if STOP-instruction is executed */ + if (1) { + static int sleepcnt, lvpos, zerocnt; + if (vpos != lvpos) { + sleepcnt--; #ifdef JIT - if (pissoff == 0 && compiled_code && --zerocnt < 0) { - sleepcnt = -1; - zerocnt = IDLETIME / 4; - } + if (pissoff == 0 && compiled_code && --zerocnt < 0) { + sleepcnt = -1; + zerocnt = IDLETIME / 4; + } #endif - lvpos = vpos; - if (sleepcnt < 0) { - sleepcnt = IDLETIME / 2; - sleep_millis (1); - } + lvpos = vpos; + if (sleepcnt < 0) { + sleepcnt = IDLETIME / 2; + sleep_millis (1); + } + } + } } - } } - } - if (regs.spcflags & SPCFLAG_TRACE) - do_trace (); + if (regs.spcflags & SPCFLAG_TRACE) + do_trace (); - if (regs.spcflags & SPCFLAG_INT) { - if (time_for_interrupt ()) { - int intr = intlev (); - unset_special (SPCFLAG_INT | SPCFLAG_DOINT); - if (intr != -1 && (intr > regs.intmask || intr == 7)) - do_interrupt (intr); + if (regs.spcflags & SPCFLAG_INT) { + if (time_for_interrupt ()) { + int intr = intlev (); + unset_special (SPCFLAG_INT | SPCFLAG_DOINT); + if (intr != -1 && (intr > regs.intmask || intr == 7)) + do_interrupt (intr); + } + } + if (regs.spcflags & SPCFLAG_DOINT) { + unset_special (SPCFLAG_DOINT); + set_special (SPCFLAG_INT); } - } - if (regs.spcflags & SPCFLAG_DOINT) { - unset_special (SPCFLAG_DOINT); - set_special (SPCFLAG_INT); - } - if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) { - unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); - return 1; - } - return 0; + if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) { + unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); + return 1; + } + return 0; } void prepare_interrupt (void) { - interrupt_cycles = get_cycles () + 6 * CYCLE_UNIT; - interrupt_cycles_active = 1; + interrupt_cycles = get_cycles () + 6 * CYCLE_UNIT; + interrupt_cycles_active = 1; } void doint (void) { - if (currprefs.cpu_compatible) - set_special (SPCFLAG_INT); - else - set_special (SPCFLAG_DOINT); + if (currprefs.cpu_compatible) + set_special (SPCFLAG_INT); + else + set_special (SPCFLAG_DOINT); } //static uae_u32 pcs[1000]; @@ -2724,68 +2725,68 @@ static uae_u32 cd32nextpc, cd32request; static void out_cd32io2 (void) { - uae_u32 request = cd32request; - write_log (L"%08x returned\n", request); - //write_log (L"ACTUAL=%d ERROR=%d\n", get_long (request + 32), get_byte (request + 31)); - cd32nextpc = 0; - cd32request = 0; + uae_u32 request = cd32request; + write_log (L"%08x returned\n", request); + //write_log (L"ACTUAL=%d ERROR=%d\n", get_long (request + 32), get_byte (request + 31)); + cd32nextpc = 0; + cd32request = 0; } static void out_cd32io (uae_u32 pc) { - TCHAR out[100]; - int ioreq = 0; - uae_u32 request = m68k_areg (regs, 1); - - if (pc == cd32nextpc) { - out_cd32io2 (); - return; - } - out[0] = 0; - switch (pc) - { + TCHAR out[100]; + int ioreq = 0; + uae_u32 request = m68k_areg (regs, 1); + + if (pc == cd32nextpc) { + out_cd32io2 (); + return; + } + out[0] = 0; + switch (pc) + { case 0xe57cc0: case 0xf04c34: - _stprintf (out, "opendevice"); - break; + _stprintf (out, "opendevice"); + break; case 0xe57ce6: case 0xf04c56: - _stprintf (out, "closedevice"); - break; + _stprintf (out, "closedevice"); + break; case 0xe57e44: case 0xf04f2c: - _stprintf (out, "beginio"); - ioreq = 1; - break; + _stprintf (out, "beginio"); + ioreq = 1; + break; case 0xe57ef2: case 0xf0500e: - _stprintf (out, "abortio"); - ioreq = -1; - break; - } - if (out[0] == 0) - return; - if (cd32request) - write_log (L"old request still not returned!\n"); - cd32request = request; - cd32nextpc = get_long (m68k_areg (regs, 7)); - write_log (L"%s A1=%08X\n", out, request); - if (ioreq) { - static int cnt = 0; - int cmd = get_word (request + 28); -#if 1 - if (cmd == 37) { - cnt--; - if (cnt <= 0) - activate_debugger (); + _stprintf (out, "abortio"); + ioreq = -1; + break; } + if (out[0] == 0) + return; + if (cd32request) + write_log (L"old request still not returned!\n"); + cd32request = request; + cd32nextpc = get_long (m68k_areg (regs, 7)); + write_log (L"%s A1=%08X\n", out, request); + if (ioreq) { + static int cnt = 0; + int cmd = get_word (request + 28); +#if 1 + if (cmd == 37) { + cnt--; + if (cnt <= 0) + activate_debugger (); + } #endif - write_log (L"CMD=%d DATA=%08X LEN=%d %OFF=%d PC=%x\n", - cmd, get_long (request + 40), - get_long (request + 36), get_long (request + 44), M68K_GETPC); - } - if (ioreq < 0) - ;//activate_debugger (); + write_log (L"CMD=%d DATA=%08X LEN=%d %OFF=%d PC=%x\n", + cmd, get_long (request + 40), + get_long (request + 36), get_long (request + 44), M68K_GETPC); + } + if (ioreq < 0) + ;//activate_debugger (); } #endif @@ -2799,43 +2800,43 @@ static void m68k_run_1 (void) #else /* It's really sad to have two almost identical functions for this, but we - do it all for performance... :( - This version emulates 68000's prefetch "cache" */ +do it all for performance... :( +This version emulates 68000's prefetch "cache" */ int cpu_cycles; static void m68k_run_1 (void) { - struct regstruct *r = ®s; + struct regstruct *r = ®s; - for (;;) { - uae_u32 opcode = r->ir; + for (;;) { + uae_u32 opcode = r->ir; - count_instr (opcode); + count_instr (opcode); #ifdef DEBUG_CD32IO - out_cd32io (m68k_getpc ()); + out_cd32io (m68k_getpc ()); #endif #if 0 - int pc = m68k_getpc (); - if (pc == 0xdff002) - write_log (L"hip\n"); - if (pc != pcs[0] && (pc < 0xd00000 || pc > 0x1000000)) { - memmove (pcs + 1, pcs, 998 * 4); - pcs[0] = pc; - //write_log (L"%08X-%04X ", pc, opcode); - } + int pc = m68k_getpc (); + if (pc == 0xdff002) + write_log (L"hip\n"); + if (pc != pcs[0] && (pc < 0xd00000 || pc > 0x1000000)) { + memmove (pcs + 1, pcs, 998 * 4); + pcs[0] = pc; + //write_log (L"%08X-%04X ", pc, opcode); + } #endif - do_cycles (cpu_cycles); - cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - if (r->spcflags) { - if (do_specialties (cpu_cycles)) - return; + do_cycles (cpu_cycles); + cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + if (r->spcflags) { + if (do_specialties (cpu_cycles)) + return; + } + if (!currprefs.cpu_compatible || (currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000)) + return; } - if (!currprefs.cpu_compatible || (currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000)) - return; - } } #endif /* CPUEMU_11 */ @@ -2852,19 +2853,19 @@ static void m68k_run_1_ce (void) static void m68k_run_1_ce (void) { - struct regstruct *r = ®s; + struct regstruct *r = ®s; - for (;;) { - uae_u32 opcode = r->ir; + for (;;) { + uae_u32 opcode = r->ir; - (*cpufunctbl[opcode])(opcode); - if (r->spcflags) { - if (do_specialties (0)) - return; + (*cpufunctbl[opcode])(opcode); + if (r->spcflags) { + if (do_specialties (0)) + return; + } + if (!currprefs.cpu_cycle_exact || currprefs.cpu_model > 68000) + return; } - if (!currprefs.cpu_cycle_exact || currprefs.cpu_model > 68000) - return; - } } #endif @@ -2872,29 +2873,29 @@ static void m68k_run_1_ce (void) void do_nothing (void) { - /* What did you expect this to do? */ - do_cycles (0); - /* I bet you didn't expect *that* ;-) */ + /* What did you expect this to do? */ + do_cycles (0); + /* I bet you didn't expect *that* ;-) */ } void exec_nostats (void) { - struct regstruct *r = ®s; + struct regstruct *r = ®s; - for (;;) - { - uae_u16 opcode = get_iword (0); + for (;;) + { + uae_u16 opcode = get_iword (0); - cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; - do_cycles (cpu_cycles); + do_cycles (cpu_cycles); - if (end_block (opcode) || r->spcflags || uae_int_requested) - return; /* We will deal with the spcflags in the caller */ - } + if (end_block (opcode) || r->spcflags || uae_int_requested) + return; /* We will deal with the spcflags in the caller */ + } } static int triggered; @@ -2903,60 +2904,60 @@ extern volatile int bsd_int_requested; void execute_normal (void) { - struct regstruct *r = ®s; - int blocklen; - cpu_history pc_hist[MAXRUN]; - int total_cycles; - - if (check_for_cache_miss ()) - return; - - total_cycles = 0; - blocklen = 0; - start_pc_p = r->pc_oldp; - start_pc = r->pc; - for (;;) { - /* Take note: This is the do-it-normal loop */ - uae_u16 opcode = get_iword (0); - - special_mem = DISTRUST_CONSISTENT_MEM; - pc_hist[blocklen].location = (uae_u16*)r->pc_p; - - cpu_cycles = (*cpufunctbl[opcode])(opcode); - - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - do_cycles (cpu_cycles); - total_cycles += cpu_cycles; - pc_hist[blocklen].specmem = special_mem; - blocklen++; - if (end_block (opcode) || blocklen >= MAXRUN || r->spcflags || uae_int_requested) { - compile_block (pc_hist, blocklen, total_cycles); - return; /* We will deal with the spcflags in the caller */ - } - /* No need to check regs.spcflags, because if they were set, - we'd have ended up inside that "if" */ - } + struct regstruct *r = ®s; + int blocklen; + cpu_history pc_hist[MAXRUN]; + int total_cycles; + + if (check_for_cache_miss ()) + return; + + total_cycles = 0; + blocklen = 0; + start_pc_p = r->pc_oldp; + start_pc = r->pc; + for (;;) { + /* Take note: This is the do-it-normal loop */ + uae_u16 opcode = get_iword (0); + + special_mem = DISTRUST_CONSISTENT_MEM; + pc_hist[blocklen].location = (uae_u16*)r->pc_p; + + cpu_cycles = (*cpufunctbl[opcode])(opcode); + + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + do_cycles (cpu_cycles); + total_cycles += cpu_cycles; + pc_hist[blocklen].specmem = special_mem; + blocklen++; + if (end_block (opcode) || blocklen >= MAXRUN || r->spcflags || uae_int_requested) { + compile_block (pc_hist, blocklen, total_cycles); + return; /* We will deal with the spcflags in the caller */ + } + /* No need to check regs.spcflags, because if they were set, + we'd have ended up inside that "if" */ + } } typedef void compiled_handler (void); static void m68k_run_2a (void) { - for (;;) { - ((compiled_handler*)(pushall_call_handler))(); - /* Whenever we return from that, we should check spcflags */ - if (uae_int_requested) { - intreq |= 0x0008; - intreqr = intreq; - set_special (SPCFLAG_INT); - } - if (regs.spcflags) { - if (do_specialties (0)) { - return; - } + for (;;) { + ((compiled_handler*)(pushall_call_handler))(); + /* Whenever we return from that, we should check spcflags */ + if (uae_int_requested) { + intreq |= 0x0008; + intreqr = intreq; + set_special (SPCFLAG_INT); + } + if (regs.spcflags) { + if (do_specialties (0)) { + return; + } + } } - } } #endif /* JIT */ @@ -2970,139 +2971,142 @@ static void m68k_run_2 (void) static void opcodedebug (uae_u32 pc, uae_u16 opcode) { - struct mnemolookup *lookup; - struct instr *dp; - uae_u32 addr; - int fault; - - if (cpufunctbl[opcode] == op_illg_1) - opcode = 0x4AFC; - dp = table68k + opcode; - for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) - ; - fault = 0; - TRY(prb) { - addr = mmu_translate (pc, (regs.mmu_ssw & 4) ? 1 : 0, 0, 0); - } CATCH (prb) { - fault = 1; - } - if (!fault) { - TCHAR buf[100]; - write_log (L"PC=%08x %04x %s\n", regs.fault_pc, opcode, lookup->name); - m68k_disasm_2 (buf, 100, addr, NULL, 1, NULL, NULL, 0); - write_log (L"%s\n", buf); - } + struct mnemolookup *lookup; + struct instr *dp; + uae_u32 addr; + int fault; + + if (cpufunctbl[opcode] == op_illg_1) + opcode = 0x4AFC; + dp = table68k + opcode; + for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) + ; + fault = 0; + TRY(prb) { + addr = mmu_translate (pc, (regs.mmu_ssw & 4) ? 1 : 0, 0, 0); + } CATCH (prb) { + fault = 1; + } + if (!fault) { + TCHAR buf[100]; + write_log (L"PC=%08x %04x %s\n", regs.fault_pc, opcode, lookup->name); + m68k_disasm_2 (buf, 100, addr, NULL, 1, NULL, NULL, 0); + write_log (L"%s\n", buf); + } } /* Aranym MMU 68040 */ static void m68k_run_mmu040 (void) { - uae_u32 opcode; - uaecptr pc; + uae_u32 opcode; + uaecptr pc; retry: - TRY (prb) { - for (;;) { - pc = regs.fault_pc = m68k_getpc (); - opcode = get_iword_mmu (0); - count_instr (opcode); - do_cycles (cpu_cycles); - cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - if (regs.spcflags) { - if (do_specialties (cpu_cycles)) - return; - } - } - } CATCH (prb) { - - //opcodedebug (regs.fault_pc, opcode); - - if (currprefs.mmu_model == 68060) { - regs.fault_pc = pc; - if (mmufixup[1].reg >= 0) { - m68k_areg (regs, mmufixup[1].reg) = mmufixup[1].value; - mmufixup[1].reg = -1; - } - } else { - if (regs.wb3_status & 0x80) { - // movem to memory? - if ((opcode & 0xff80) == 0x4880) { - regs.mmu_ssw |= MMU_SSW_CM; - //write_log (L"MMU_SSW_CM\n"); + TRY (prb) { + for (;;) { + pc = regs.fault_pc = m68k_getpc (); + opcode = get_iword_mmu (0); + count_instr (opcode); + do_cycles (cpu_cycles); + cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + if (regs.spcflags) { + if (do_specialties (cpu_cycles)) + return; + } + } + } CATCH (prb) { + + //opcodedebug (regs.fault_pc, opcode); + + if (currprefs.mmu_model == 68060) { + regs.fault_pc = pc; + if (mmufixup[1].reg >= 0) { + m68k_areg (regs, mmufixup[1].reg) = mmufixup[1].value; + mmufixup[1].reg = -1; + } + } else { + if (regs.wb3_status & 0x80) { + // movem to memory? + if ((opcode & 0xff80) == 0x4880) { + regs.mmu_ssw |= MMU_SSW_CM; + //write_log (L"MMU_SSW_CM\n"); + } + } } - } - } - if (mmufixup[0].reg >= 0) { - m68k_areg (regs, mmufixup[0].reg) = mmufixup[0].value; - mmufixup[0].reg = -1; - } - //activate_debugger (); - TRY (prb2) { - Exception (2, regs.fault_pc); - } CATCH (prb2) { - write_log (L"MMU: double bus error, rebooting..\n"); - uae_reset (1); + if (mmufixup[0].reg >= 0) { + m68k_areg (regs, mmufixup[0].reg) = mmufixup[0].value; + mmufixup[0].reg = -1; + } + //activate_debugger (); + TRY (prb2) { + Exception (2, regs.fault_pc); + } CATCH (prb2) { + write_log (L"MMU: double bus error, rebooting..\n"); + uae_reset (1); + } + goto retry; } - goto retry; - } } /* "cycle exact" 68020 */ static void m68k_run_2ce (void) { - struct regstruct *r = ®s; - - for (;;) { - uae_u32 opcode = get_word_ce020_prefetch (0); - do_cycles_ce020 (1); - (*cpufunctbl[opcode])(opcode); - if (r->spcflags) { - if (do_specialties (0)) - return; + struct regstruct *r = ®s; + + for (;;) { + uae_u32 opcode = get_word_ce020_prefetch (0); + (*cpufunctbl[opcode])(opcode); + if (r->ce020memcycles > 0) { + do_cycles_ce (r->ce020memcycles); + r->ce020memcycles = 0; + } + if (r->spcflags) { + if (do_specialties (0)) + return; + } } - } } /* emulate simple prefetch */ static void m68k_run_2p (void) { - uae_u32 prefetch, prefetch_pc; - struct regstruct *r = ®s; + uae_u32 prefetch, prefetch_pc; + struct regstruct *r = ®s; - prefetch_pc = m68k_getpc (); - prefetch = get_longi (prefetch_pc); - for (;;) { - uae_u32 opcode; - uae_u32 pc = m68k_getpc (); + prefetch_pc = m68k_getpc (); + prefetch = get_longi (prefetch_pc); + for (;;) { + uae_u32 opcode; + uae_u32 pc = m68k_getpc (); #ifdef DEBUG_CD32IO - out_cd32io (m68k_getpc ()); + out_cd32io (m68k_getpc ()); #endif - do_cycles (cpu_cycles); - - if (pc == prefetch_pc) - opcode = prefetch >> 16; - else if (pc == prefetch_pc + 2) - opcode = prefetch & 0xffff; - else - opcode = get_wordi (pc); - - count_instr (opcode); + do_cycles (cpu_cycles); - prefetch_pc = m68k_getpc () + 2; - prefetch = get_longi (prefetch_pc); - cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - if (r->spcflags) { - if (do_specialties (cpu_cycles)) - return; + if (pc == prefetch_pc) + opcode = prefetch >> 16; + else if (pc == prefetch_pc + 2) + opcode = prefetch & 0xffff; + else + opcode = get_wordi (pc); + + count_instr (opcode); + + prefetch_pc = m68k_getpc () + 2; + prefetch = get_longi (prefetch_pc); + cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + if (r->spcflags) { + if (do_specialties (cpu_cycles)) + return; + } } - } } //static int used[65536]; @@ -3110,45 +3114,45 @@ static void m68k_run_2p (void) /* Same thing, but don't use prefetch to get opcode. */ static void m68k_run_2 (void) { - struct regstruct *r = ®s; + struct regstruct *r = ®s; - for (;;) { - uae_u32 opcode = get_iword (0); - count_instr (opcode); + for (;;) { + uae_u32 opcode = get_iword (0); + count_instr (opcode); #if 0 - if (!used[opcode]) { - write_log (L"%04X ", opcode); - used[opcode] = 1; - } + if (!used[opcode]) { + write_log (L"%04X ", opcode); + used[opcode] = 1; + } #endif - do_cycles (cpu_cycles); - cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - if (r->spcflags) { - if (do_specialties (cpu_cycles)) - return; + do_cycles (cpu_cycles); + cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + if (r->spcflags) { + if (do_specialties (cpu_cycles)) + return; + } } - } } /* fake MMU 68k */ static void m68k_run_mmu (void) { - for (;;) { - uae_u32 opcode = get_iword (0); - do_cycles (cpu_cycles); - mmu_backup_regs = regs; - cpu_cycles = (*cpufunctbl[opcode])(opcode); - cpu_cycles &= cycles_mask; - cpu_cycles |= cycles_val; - if (mmu_triggered) - mmu_do_hit (); - if (regs.spcflags) { - if (do_specialties (cpu_cycles)) - return; + for (;;) { + uae_u32 opcode = get_iword (0); + do_cycles (cpu_cycles); + mmu_backup_regs = regs; + cpu_cycles = (*cpufunctbl[opcode])(opcode); + cpu_cycles &= cycles_mask; + cpu_cycles |= cycles_val; + if (mmu_triggered) + mmu_do_hit (); + if (regs.spcflags) { + if (do_specialties (cpu_cycles)) + return; + } } - } } #endif /* CPUEMU_0 */ @@ -3157,564 +3161,564 @@ int in_m68k_go = 0; static void exception2_handle (uaecptr addr, uaecptr fault) { - last_addr_for_exception_3 = addr; - last_fault_for_exception_3 = fault; - last_writeaccess_for_exception_3 = 0; - last_instructionaccess_for_exception_3 = 0; - Exception (2, m68k_getpc ()); + last_addr_for_exception_3 = addr; + last_fault_for_exception_3 = fault; + last_writeaccess_for_exception_3 = 0; + last_instructionaccess_for_exception_3 = 0; + Exception (2, m68k_getpc ()); } void m68k_go (int may_quit) { - int hardboot = 1; - - if (in_m68k_go || !may_quit) { - write_log (L"Bug! m68k_go is not reentrant.\n"); - abort (); - } - - reset_frame_rate_hack (); - update_68k_cycles (); - - in_m68k_go++; - for (;;) { - void (*run_func)(void); - if (quit_program > 0) { - int hardreset = (quit_program == 3 ? 1 : 0) | hardboot; - if (quit_program == 1) - break; + int hardboot = 1; + + if (in_m68k_go || !may_quit) { + write_log (L"Bug! m68k_go is not reentrant.\n"); + abort (); + } + + reset_frame_rate_hack (); + update_68k_cycles (); - quit_program = 0; - hardboot = 0; + in_m68k_go++; + for (;;) { + void (*run_func)(void); + if (quit_program > 0) { + int hardreset = (quit_program == 3 ? 1 : 0) | hardboot; + if (quit_program == 1) + break; + + quit_program = 0; + hardboot = 0; #ifdef SAVESTATE - if (savestate_state == STATE_RESTORE) - restore_state (savestate_fname); - else if (savestate_state == STATE_REWIND) - savestate_rewind (); + if (savestate_state == STATE_RESTORE) + restore_state (savestate_fname); + else if (savestate_state == STATE_REWIND) + savestate_rewind (); #endif - customreset (hardreset); - m68k_reset (hardreset); - if (hardreset) { - memory_hardreset (); - write_log (L"hardreset, memory cleared\n"); - } + customreset (hardreset); + m68k_reset (hardreset); + if (hardreset) { + memory_hardreset (); + write_log (L"hardreset, memory cleared\n"); + } #ifdef SAVESTATE - /* We may have been restoring state, but we're done now. */ - if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) { - map_overlay (1); - fill_prefetch_slow (); /* compatibility with old state saves */ - memory_map_dump (); - } - savestate_restore_finish (); + /* We may have been restoring state, but we're done now. */ + if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) { + map_overlay (1); + fill_prefetch_slow (); /* compatibility with old state saves */ + memory_map_dump (); + } + savestate_restore_finish (); #endif - fill_prefetch_slow (); - if (currprefs.produce_sound == 0) - eventtab[ev_audio].active = 0; - handle_active_events (); - if (regs.spcflags) - do_specialties (0); - m68k_setpc (regs.pc); - } + fill_prefetch_slow (); + if (currprefs.produce_sound == 0) + eventtab[ev_audio].active = 0; + handle_active_events (); + if (regs.spcflags) + do_specialties (0); + m68k_setpc (regs.pc); + } #ifdef DEBUGGER - if (debugging) - debug (); + if (debugging) + debug (); #endif - if (regs.panic) { - regs.panic = 0; - /* program jumped to non-existing memory and cpu was >= 68020 */ - get_real_address (regs.isp); /* stack in no one's land? -> reboot */ - if (regs.isp & 1) - regs.panic = 1; - if (!regs.panic) - exception2_handle (regs.panic_pc, regs.panic_addr); - if (regs.panic) { - /* system is very badly confused */ - write_log (L"double bus error or corrupted stack, forcing reboot..\n"); - regs.panic = 0; - uae_reset (1); - } - } + if (regs.panic) { + regs.panic = 0; + /* program jumped to non-existing memory and cpu was >= 68020 */ + get_real_address (regs.isp); /* stack in no one's land? -> reboot */ + if (regs.isp & 1) + regs.panic = 1; + if (!regs.panic) + exception2_handle (regs.panic_pc, regs.panic_addr); + if (regs.panic) { + /* system is very badly confused */ + write_log (L"double bus error or corrupted stack, forcing reboot..\n"); + regs.panic = 0; + uae_reset (1); + } + } #if 0 /* what was the meaning of this? this breaks trace emulation if debugger is used */ - if (regs.spcflags) { - uae_u32 of = regs.spcflags; - regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); - do_specialties (0); - regs.spcflags |= of & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); - } + if (regs.spcflags) { + uae_u32 of = regs.spcflags; + regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); + do_specialties (0); + regs.spcflags |= of & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); + } #endif #ifndef JIT - run_func = currprefs.cpu_model == 68000 && currprefs.cpu_cycle_exact ? m68k_run_1_ce : - currprefs.cpu_model == 68000 && currprefs.cpu_compatible ? m68k_run_1 : - currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2; + run_func = currprefs.cpu_model == 68000 && currprefs.cpu_cycle_exact ? m68k_run_1_ce : + currprefs.cpu_model == 68000 && currprefs.cpu_compatible ? m68k_run_1 : + currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2; #else - if (mmu_enabled && !currprefs.cachesize) { - run_func = m68k_run_mmu; - } else { - run_func = currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000 ? m68k_run_1_ce : - currprefs.cpu_compatible > 0 && currprefs.cpu_model == 68000 ? m68k_run_1 : - currprefs.cpu_model >= 68020 && currprefs.cachesize ? m68k_run_2a : - (currprefs.cpu_model == 68040 || currprefs.cpu_model == 68060) && currprefs.mmu_model ? m68k_run_mmu040 : - currprefs.cpu_model >= 68020 && currprefs.cpu_cycle_exact ? m68k_run_2ce : - currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2; - } + if (mmu_enabled && !currprefs.cachesize) { + run_func = m68k_run_mmu; + } else { + run_func = currprefs.cpu_cycle_exact && currprefs.cpu_model == 68000 ? m68k_run_1_ce : + currprefs.cpu_compatible > 0 && currprefs.cpu_model == 68000 ? m68k_run_1 : + currprefs.cpu_model >= 68020 && currprefs.cachesize ? m68k_run_2a : + (currprefs.cpu_model == 68040 || currprefs.cpu_model == 68060) && currprefs.mmu_model ? m68k_run_mmu040 : + currprefs.cpu_model >= 68020 && currprefs.cpu_cycle_exact ? m68k_run_2ce : + currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2; + } #endif - run_func (); - } - in_m68k_go--; + run_func (); + } + in_m68k_go--; } #if 0 static void m68k_verify (uaecptr addr, uaecptr *nextpc) { - uae_u32 opcode, val; - struct instr *dp; - - opcode = get_iword_1 (0); - last_op_for_exception_3 = opcode; - m68kpc_offset = 2; - - if (cpufunctbl[opcode] == op_illg_1) { - opcode = 0x4AFC; - } - dp = table68k + opcode; - - if (dp->suse) { - if (!verify_ea (dp->sreg, dp->smode, dp->size, &val)) { - Exception (3, 0); - return; - } - } - if (dp->duse) { - if (!verify_ea (dp->dreg, dp->dmode, dp->size, &val)) { - Exception (3, 0); - return; - } - } + uae_u32 opcode, val; + struct instr *dp; + + opcode = get_iword_1 (0); + last_op_for_exception_3 = opcode; + m68kpc_offset = 2; + + if (cpufunctbl[opcode] == op_illg_1) { + opcode = 0x4AFC; + } + dp = table68k + opcode; + + if (dp->suse) { + if (!verify_ea (dp->sreg, dp->smode, dp->size, &val)) { + Exception (3, 0); + return; + } + } + if (dp->duse) { + if (!verify_ea (dp->dreg, dp->dmode, dp->size, &val)) { + Exception (3, 0); + return; + } + } } #endif static const TCHAR *ccnames[] = { L"T ",L"F ",L"HI",L"LS",L"CC",L"CS",L"NE",L"EQ", - L"VC",L"VS",L"PL",L"MI",L"GE",L"LT",L"GT",L"LE" }; +L"VC",L"VS",L"PL",L"MI",L"GE",L"LT",L"GT",L"LE" }; static void addmovemreg (TCHAR *out, int *prevreg, int *lastreg, int *first, int reg) { - TCHAR *p = out + _tcslen (out); - if (*prevreg < 0) { + TCHAR *p = out + _tcslen (out); + if (*prevreg < 0) { + *prevreg = reg; + *lastreg = reg; + return; + } + if ((*prevreg) + 1 != reg || (reg & 8) != ((*prevreg & 8))) { + _stprintf (p, L"%s%c%d", (*first) ? L"" : L"/", (*lastreg) < 8 ? 'D' : 'A', (*lastreg) & 7); + p = p + _tcslen (p); + if ((*lastreg) + 2 == reg) { + _stprintf (p, L"/%c%d", (*prevreg) < 8 ? 'D' : 'A', (*prevreg) & 7); + } else if ((*lastreg) != (*prevreg)) { + _stprintf (p, L"-%c%d", (*prevreg) < 8 ? 'D' : 'A', (*prevreg) & 7); + } + *lastreg = reg; + *first = 0; + } *prevreg = reg; - *lastreg = reg; - return; - } - if ((*prevreg) + 1 != reg || (reg & 8) != ((*prevreg & 8))) { - _stprintf (p, L"%s%c%d", (*first) ? L"" : L"/", (*lastreg) < 8 ? 'D' : 'A', (*lastreg) & 7); - p = p + _tcslen (p); - if ((*lastreg) + 2 == reg) { - _stprintf (p, L"/%c%d", (*prevreg) < 8 ? 'D' : 'A', (*prevreg) & 7); - } else if ((*lastreg) != (*prevreg)) { - _stprintf (p, L"-%c%d", (*prevreg) < 8 ? 'D' : 'A', (*prevreg) & 7); - } - *lastreg = reg; - *first = 0; - } - *prevreg = reg; } static void movemout (TCHAR *out, uae_u16 mask, int mode) { - unsigned int dmask, amask; - int prevreg = -1, lastreg = -1, first = 1; - - if (mode == Apdi) { - int i; - uae_u8 dmask2 = (mask >> 8) & 0xff; - uae_u8 amask2 = mask & 0xff; - dmask = 0; - amask = 0; - for (i = 0; i < 8; i++) { - if (dmask2 & (1 << i)) - dmask |= 1 << (7 - i); - if (amask2 & (1 << i)) - amask |= 1 << (7 - i); - } - } else { - dmask = mask & 0xff; - amask = (mask >> 8) & 0xff; - } - while (dmask) { addmovemreg (out, &prevreg, &lastreg, &first, movem_index1[dmask]); dmask = movem_next[dmask]; } - while (amask) { addmovemreg (out, &prevreg, &lastreg, &first, movem_index1[amask] + 8); amask = movem_next[amask]; } - addmovemreg (out, &prevreg, &lastreg, &first, -1); + unsigned int dmask, amask; + int prevreg = -1, lastreg = -1, first = 1; + + if (mode == Apdi) { + int i; + uae_u8 dmask2 = (mask >> 8) & 0xff; + uae_u8 amask2 = mask & 0xff; + dmask = 0; + amask = 0; + for (i = 0; i < 8; i++) { + if (dmask2 & (1 << i)) + dmask |= 1 << (7 - i); + if (amask2 & (1 << i)) + amask |= 1 << (7 - i); + } + } else { + dmask = mask & 0xff; + amask = (mask >> 8) & 0xff; + } + while (dmask) { addmovemreg (out, &prevreg, &lastreg, &first, movem_index1[dmask]); dmask = movem_next[dmask]; } + while (amask) { addmovemreg (out, &prevreg, &lastreg, &first, movem_index1[amask] + 8); amask = movem_next[amask]; } + addmovemreg (out, &prevreg, &lastreg, &first, -1); } static void disasm_size (TCHAR *instrname, struct instr *dp) { #if 0 - int i, size; - uae_u16 mnemo = dp->mnemo; - - size = dp->size; - for (i = 0; i < 65536; i++) { - struct instr *in = &table68k[i]; - if (in->mnemo == mnemo && in != dp) { - if (size != in->size) - break; + int i, size; + uae_u16 mnemo = dp->mnemo; + + size = dp->size; + for (i = 0; i < 65536; i++) { + struct instr *in = &table68k[i]; + if (in->mnemo == mnemo && in != dp) { + if (size != in->size) + break; + } } - } - if (i == 65536) - size = -1; + if (i == 65536) + size = -1; #endif - switch (dp->size) - { + switch (dp->size) + { case sz_byte: - _tcscat (instrname, L".B "); - break; + _tcscat (instrname, L".B "); + break; case sz_word: - _tcscat (instrname, L".W "); - break; + _tcscat (instrname, L".W "); + break; case sz_long: - _tcscat (instrname, L".L "); - break; + _tcscat (instrname, L".L "); + break; default: - _tcscat (instrname, L" "); - break; - } + _tcscat (instrname, L" "); + break; + } } void m68k_disasm_2 (TCHAR *buf, int bufsize, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *seaddr, uae_u32 *deaddr, int safemode) { - uaecptr newpc = 0; - m68kpc_offset = addr - m68k_getpc (); - - if (buf) - memset (buf, 0, bufsize); - if (!table68k) - return; - while (cnt-- > 0) { - TCHAR instrname[100], *ccpt; - int i; - uae_u32 opcode; - struct mnemolookup *lookup; - struct instr *dp; - int oldpc; + uaecptr newpc = 0; + m68kpc_offset = addr - m68k_getpc (); - oldpc = m68kpc_offset; - opcode = get_iword_1 (m68kpc_offset); - if (cpufunctbl[opcode] == op_illg_1) { - opcode = 0x4AFC; - } - dp = table68k + opcode; - for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) - ; + if (buf) + memset (buf, 0, bufsize); + if (!table68k) + return; + while (cnt-- > 0) { + TCHAR instrname[100], *ccpt; + int i; + uae_u32 opcode; + struct mnemolookup *lookup; + struct instr *dp; + int oldpc; + + oldpc = m68kpc_offset; + opcode = get_iword_1 (m68kpc_offset); + if (cpufunctbl[opcode] == op_illg_1) { + opcode = 0x4AFC; + } + dp = table68k + opcode; + for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) + ; - buf = buf_out (buf, &bufsize, L"%08lX ", m68k_getpc () + m68kpc_offset); + buf = buf_out (buf, &bufsize, L"%08lX ", m68k_getpc () + m68kpc_offset); - m68kpc_offset += 2; + m68kpc_offset += 2; - if (lookup->friendlyname) - _tcscpy (instrname, lookup->friendlyname); - else - _tcscpy (instrname, lookup->name); - ccpt = _tcsstr (instrname, L"cc"); - if (ccpt != 0) { - _tcsncpy (ccpt, ccnames[dp->cc], 2); - } - disasm_size (instrname, dp); - - if (lookup->mnemo == i_MOVEC2 || lookup->mnemo == i_MOVE2C) { - uae_u16 imm = get_iword_1 (m68kpc_offset); - uae_u16 creg = imm & 0x0fff; - uae_u16 r = imm >> 12; - TCHAR regs[16], *cname = L"?"; - int i; - for (i = 0; m2cregs[i].regname; i++) { - if (m2cregs[i].regno == creg) - break; - } - _stprintf (regs, L"%c%d", r >= 8 ? 'A' : 'D', r >= 8 ? r - 8 : r); - if (m2cregs[i].regname) - cname = m2cregs[i].regname; - if (lookup->mnemo == i_MOVE2C) { - _tcscat (instrname, regs); - _tcscat (instrname, L","); - _tcscat (instrname, cname); - } else { - _tcscat (instrname, cname); - _tcscat (instrname, L","); - _tcscat (instrname, regs); - } - m68kpc_offset += 2; - } else if (lookup->mnemo == i_MVMEL) { - newpc = m68k_getpc () + m68kpc_offset; - m68kpc_offset += 2; - newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); - _tcscat (instrname, L","); - movemout (instrname, get_iword_1 (oldpc + 2), dp->dmode); - } else if (lookup->mnemo == i_MVMLE) { - m68kpc_offset += 2; - movemout (instrname, get_iword_1 (oldpc + 2), dp->dmode); - _tcscat (instrname, L","); - newpc = m68k_getpc () + m68kpc_offset; - newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); - } else { - if (dp->suse) { - newpc = m68k_getpc () + m68kpc_offset; - newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, seaddr, safemode); - } - if (dp->suse && dp->duse) - _tcscat (instrname, L","); - if (dp->duse) { - newpc = m68k_getpc () + m68kpc_offset; - newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); - } - } + if (lookup->friendlyname) + _tcscpy (instrname, lookup->friendlyname); + else + _tcscpy (instrname, lookup->name); + ccpt = _tcsstr (instrname, L"cc"); + if (ccpt != 0) { + _tcsncpy (ccpt, ccnames[dp->cc], 2); + } + disasm_size (instrname, dp); + + if (lookup->mnemo == i_MOVEC2 || lookup->mnemo == i_MOVE2C) { + uae_u16 imm = get_iword_1 (m68kpc_offset); + uae_u16 creg = imm & 0x0fff; + uae_u16 r = imm >> 12; + TCHAR regs[16], *cname = L"?"; + int i; + for (i = 0; m2cregs[i].regname; i++) { + if (m2cregs[i].regno == creg) + break; + } + _stprintf (regs, L"%c%d", r >= 8 ? 'A' : 'D', r >= 8 ? r - 8 : r); + if (m2cregs[i].regname) + cname = m2cregs[i].regname; + if (lookup->mnemo == i_MOVE2C) { + _tcscat (instrname, regs); + _tcscat (instrname, L","); + _tcscat (instrname, cname); + } else { + _tcscat (instrname, cname); + _tcscat (instrname, L","); + _tcscat (instrname, regs); + } + m68kpc_offset += 2; + } else if (lookup->mnemo == i_MVMEL) { + newpc = m68k_getpc () + m68kpc_offset; + m68kpc_offset += 2; + newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); + _tcscat (instrname, L","); + movemout (instrname, get_iword_1 (oldpc + 2), dp->dmode); + } else if (lookup->mnemo == i_MVMLE) { + m68kpc_offset += 2; + movemout (instrname, get_iword_1 (oldpc + 2), dp->dmode); + _tcscat (instrname, L","); + newpc = m68k_getpc () + m68kpc_offset; + newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); + } else { + if (dp->suse) { + newpc = m68k_getpc () + m68kpc_offset; + newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, seaddr, safemode); + } + if (dp->suse && dp->duse) + _tcscat (instrname, L","); + if (dp->duse) { + newpc = m68k_getpc () + m68kpc_offset; + newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); + } + } - for (i = 0; i < (m68kpc_offset - oldpc) / 2; i++) { - buf = buf_out (buf, &bufsize, L"%04x ", get_iword_1 (oldpc + i * 2)); + for (i = 0; i < (m68kpc_offset - oldpc) / 2; i++) { + buf = buf_out (buf, &bufsize, L"%04x ", get_iword_1 (oldpc + i * 2)); + } + while (i++ < 5) + buf = buf_out (buf, &bufsize, L" "); + + buf = buf_out (buf, &bufsize, instrname); + + if (ccpt != 0) { + if (deaddr) + *deaddr = newpc; + if (cctrue (dp->cc)) + buf = buf_out (buf, &bufsize, L" == $%08lX (T)", newpc); + else + buf = buf_out (buf, &bufsize, L" == $%08lX (F)", newpc); + } else if ((opcode & 0xff00) == 0x6100) { /* BSR */ + if (deaddr) + *deaddr = newpc; + buf = buf_out (buf, &bufsize, L" == $%08lX", newpc); + } + buf = buf_out (buf, &bufsize, L"\n"); } - while (i++ < 5) - buf = buf_out (buf, &bufsize, L" "); - - buf = buf_out (buf, &bufsize, instrname); - - if (ccpt != 0) { - if (deaddr) - *deaddr = newpc; - if (cctrue (dp->cc)) - buf = buf_out (buf, &bufsize, L" == $%08lX (T)", newpc); - else - buf = buf_out (buf, &bufsize, L" == $%08lX (F)", newpc); - } else if ((opcode & 0xff00) == 0x6100) { /* BSR */ - if (deaddr) - *deaddr = newpc; - buf = buf_out (buf, &bufsize, L" == $%08lX", newpc); - } - buf = buf_out (buf, &bufsize, L"\n"); - } - if (nextpc) - *nextpc = m68k_getpc () + m68kpc_offset; + if (nextpc) + *nextpc = m68k_getpc () + m68kpc_offset; } void m68k_disasm_ea (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *seaddr, uae_u32 *deaddr) { - TCHAR *buf; - - buf = malloc ((MAX_LINEWIDTH + 1) * cnt * sizeof (TCHAR)); - if (!buf) - return; - m68k_disasm_2 (buf, (MAX_LINEWIDTH + 1) * cnt, addr, nextpc, cnt, seaddr, deaddr, 1); - f_out (f, L"%s", buf); - xfree (buf); + TCHAR *buf; + + buf = malloc ((MAX_LINEWIDTH + 1) * cnt * sizeof (TCHAR)); + if (!buf) + return; + m68k_disasm_2 (buf, (MAX_LINEWIDTH + 1) * cnt, addr, nextpc, cnt, seaddr, deaddr, 1); + f_out (f, L"%s", buf); + xfree (buf); } void m68k_disasm (void *f, uaecptr addr, uaecptr *nextpc, int cnt) { - TCHAR *buf; - - buf = malloc ((MAX_LINEWIDTH + 1) * cnt * sizeof (TCHAR)); - if (!buf) - return; - m68k_disasm_2 (buf, (MAX_LINEWIDTH + 1) * cnt, addr, nextpc, cnt, NULL, NULL, 0); - f_out (f, L"%s", buf); - xfree (buf); + TCHAR *buf; + + buf = malloc ((MAX_LINEWIDTH + 1) * cnt * sizeof (TCHAR)); + if (!buf) + return; + m68k_disasm_2 (buf, (MAX_LINEWIDTH + 1) * cnt, addr, nextpc, cnt, NULL, NULL, 0); + f_out (f, L"%s", buf); + xfree (buf); } /************************************************************* - Disasm the m68kcode at the given address into instrname - and instrcode +Disasm the m68kcode at the given address into instrname +and instrcode *************************************************************/ void sm68k_disasm (TCHAR *instrname, TCHAR *instrcode, uaecptr addr, uaecptr *nextpc) { - TCHAR *ccpt; - uae_u32 opcode; - struct mnemolookup *lookup; - struct instr *dp; - int oldpc; - - uaecptr newpc = 0; - - m68kpc_offset = addr - m68k_getpc (); - - oldpc = m68kpc_offset; - opcode = get_iword_1 (m68kpc_offset); - if (cpufunctbl[opcode] == op_illg_1) { - opcode = 0x4AFC; - } - dp = table68k + opcode; - for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++); - - m68kpc_offset += 2; - - _tcscpy (instrname, lookup->name); - ccpt = _tcsstr (instrname, L"cc"); - if (ccpt != 0) { - _tcsncpy (ccpt, ccnames[dp->cc], 2); - } - switch (dp->size){ + TCHAR *ccpt; + uae_u32 opcode; + struct mnemolookup *lookup; + struct instr *dp; + int oldpc; + + uaecptr newpc = 0; + + m68kpc_offset = addr - m68k_getpc (); + + oldpc = m68kpc_offset; + opcode = get_iword_1 (m68kpc_offset); + if (cpufunctbl[opcode] == op_illg_1) { + opcode = 0x4AFC; + } + dp = table68k + opcode; + for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++); + + m68kpc_offset += 2; + + _tcscpy (instrname, lookup->name); + ccpt = _tcsstr (instrname, L"cc"); + if (ccpt != 0) { + _tcsncpy (ccpt, ccnames[dp->cc], 2); + } + switch (dp->size){ case sz_byte: _tcscat (instrname, L".B "); break; case sz_word: _tcscat (instrname, L".W "); break; case sz_long: _tcscat (instrname, L".L "); break; default: _tcscat (instrname, L" "); break; - } - - if (dp->suse) { - newpc = m68k_getpc () + m68kpc_offset; - newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, NULL, 0); - } - if (dp->suse && dp->duse) - _tcscat (instrname, L","); - if (dp->duse) { - newpc = m68k_getpc () + m68kpc_offset; - newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, NULL, 0); - } - - if (instrcode) - { - int i; - for (i = 0; i < (m68kpc_offset - oldpc) / 2; i++) + } + + if (dp->suse) { + newpc = m68k_getpc () + m68kpc_offset; + newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, NULL, 0); + } + if (dp->suse && dp->duse) + _tcscat (instrname, L","); + if (dp->duse) { + newpc = m68k_getpc () + m68kpc_offset; + newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, NULL, 0); + } + + if (instrcode) { - _stprintf (instrcode, L"%04x ", get_iword_1 (oldpc + i * 2)); - instrcode += _tcslen (instrcode); + int i; + for (i = 0; i < (m68kpc_offset - oldpc) / 2; i++) + { + _stprintf (instrcode, L"%04x ", get_iword_1 (oldpc + i * 2)); + instrcode += _tcslen (instrcode); + } } - } - if (nextpc) - *nextpc = m68k_getpc () + m68kpc_offset; + if (nextpc) + *nextpc = m68k_getpc () + m68kpc_offset; } struct cpum2c m2cregs[] = { - 0, L"SFC", - 1, L"DFC", - 2, L"CACR", - 3, L"TC", - 4, L"ITT0", - 5, L"ITT1", - 6, L"DTT0", - 7, L"DTT1", - 8, L"BUSC", - 0x800, L"USP", - 0x801, L"VBR", - 0x802, L"CAAR", - 0x803, L"MSP", - 0x804, L"ISP", - 0x805, L"MMUS", - 0x806, L"URP", - 0x807, L"SRP", - 0x808, L"PCR", - -1, NULL + 0, L"SFC", + 1, L"DFC", + 2, L"CACR", + 3, L"TC", + 4, L"ITT0", + 5, L"ITT1", + 6, L"DTT0", + 7, L"DTT1", + 8, L"BUSC", + 0x800, L"USP", + 0x801, L"VBR", + 0x802, L"CAAR", + 0x803, L"MSP", + 0x804, L"ISP", + 0x805, L"MMUS", + 0x806, L"URP", + 0x807, L"SRP", + 0x808, L"PCR", + -1, NULL }; void val_move2c2 (int regno, uae_u32 val) { - switch (regno) { - case 0: regs.sfc = val; break; - case 1: regs.dfc = val; break; - case 2: regs.cacr = val; break; - case 3: regs.tcr = val; break; - case 4: regs.itt0 = val; break; - case 5: regs.itt1 = val; break; - case 6: regs.dtt0 = val; break; - case 7: regs.dtt1 = val; break; - case 8: regs.buscr = val; break; - case 0x800: regs.usp = val; break; - case 0x801: regs.vbr = val; break; - case 0x802: regs.caar = val; break; - case 0x803: regs.msp = val; break; - case 0x804: regs.isp = val; break; - case 0x805: regs.mmusr = val; break; - case 0x806: regs.urp = val; break; - case 0x807: regs.srp = val; break; - case 0x808: regs.pcr = val; break; - } + switch (regno) { + case 0: regs.sfc = val; break; + case 1: regs.dfc = val; break; + case 2: regs.cacr = val; break; + case 3: regs.tcr = val; break; + case 4: regs.itt0 = val; break; + case 5: regs.itt1 = val; break; + case 6: regs.dtt0 = val; break; + case 7: regs.dtt1 = val; break; + case 8: regs.buscr = val; break; + case 0x800: regs.usp = val; break; + case 0x801: regs.vbr = val; break; + case 0x802: regs.caar = val; break; + case 0x803: regs.msp = val; break; + case 0x804: regs.isp = val; break; + case 0x805: regs.mmusr = val; break; + case 0x806: regs.urp = val; break; + case 0x807: regs.srp = val; break; + case 0x808: regs.pcr = val; break; + } } uae_u32 val_move2c (int regno) { - switch (regno) { - case 0: return regs.sfc; - case 1: return regs.dfc; - case 2: return regs.cacr; - case 3: return regs.tcr; - case 4: return regs.itt0; - case 5: return regs.itt1; - case 6: return regs.dtt0; - case 7: return regs.dtt1; - case 8: return regs.buscr; - case 0x800: return regs.usp; - case 0x801: return regs.vbr; - case 0x802: return regs.caar; - case 0x803: return regs.msp; - case 0x804: return regs.isp; - case 0x805: return regs.mmusr; - case 0x806: return regs.urp; - case 0x807: return regs.srp; - case 0x808: return regs.pcr; - default: return 0; - } + switch (regno) { + case 0: return regs.sfc; + case 1: return regs.dfc; + case 2: return regs.cacr; + case 3: return regs.tcr; + case 4: return regs.itt0; + case 5: return regs.itt1; + case 6: return regs.dtt0; + case 7: return regs.dtt1; + case 8: return regs.buscr; + case 0x800: return regs.usp; + case 0x801: return regs.vbr; + case 0x802: return regs.caar; + case 0x803: return regs.msp; + case 0x804: return regs.isp; + case 0x805: return regs.mmusr; + case 0x806: return regs.urp; + case 0x807: return regs.srp; + case 0x808: return regs.pcr; + default: return 0; + } } void m68k_dumpstate (void *f, uaecptr *nextpc) { - int i, j; - - for (i = 0; i < 8; i++){ - f_out (f, L" D%d %08lX ", i, m68k_dreg (regs, i)); - if ((i & 3) == 3) f_out (f, L"\n"); - } - for (i = 0; i < 8; i++){ - f_out (f, L" A%d %08lX ", i, m68k_areg (regs, i)); - if ((i & 3) == 3) f_out (f, L"\n"); - } - if (regs.s == 0) regs.usp = m68k_areg (regs, 7); - if (regs.s && regs.m) regs.msp = m68k_areg (regs, 7); - if (regs.s && regs.m == 0) regs.isp = m68k_areg (regs, 7); - j = 2; - f_out (f, L"USP %08X ISP %08X ", regs.usp, regs.isp); - for (i = 0; m2cregs[i].regno>= 0; i++) { - if (!movec_illg (m2cregs[i].regno)) { - if (!_tcscmp (m2cregs[i].regname, L"USP") || !_tcscmp (m2cregs[i].regname, L"ISP")) - continue; - if (j > 0 && (j % 4) == 0) - f_out (f, L"\n"); - f_out (f, L"%-4s %08X ", m2cregs[i].regname, val_move2c (m2cregs[i].regno)); - j++; - } - } - if (j > 0) - f_out (f, L"\n"); - f_out (f, L"T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d STP=%d\n", - regs.t1, regs.t0, regs.s, regs.m, - GET_XFLG (), GET_NFLG (), GET_ZFLG (), - GET_VFLG (), GET_CFLG (), - regs.intmask, regs.stopped); -#ifdef FPUEMU - if (currprefs.fpu_model) { - uae_u32 fpsr; + int i, j; + + for (i = 0; i < 8; i++){ + f_out (f, L" D%d %08lX ", i, m68k_dreg (regs, i)); + if ((i & 3) == 3) f_out (f, L"\n"); + } for (i = 0; i < 8; i++){ - f_out (f, L"FP%d: %g ", i, regs.fp[i]); - if ((i & 3) == 3) + f_out (f, L" A%d %08lX ", i, m68k_areg (regs, i)); + if ((i & 3) == 3) f_out (f, L"\n"); + } + if (regs.s == 0) regs.usp = m68k_areg (regs, 7); + if (regs.s && regs.m) regs.msp = m68k_areg (regs, 7); + if (regs.s && regs.m == 0) regs.isp = m68k_areg (regs, 7); + j = 2; + f_out (f, L"USP %08X ISP %08X ", regs.usp, regs.isp); + for (i = 0; m2cregs[i].regno>= 0; i++) { + if (!movec_illg (m2cregs[i].regno)) { + if (!_tcscmp (m2cregs[i].regname, L"USP") || !_tcscmp (m2cregs[i].regname, L"ISP")) + continue; + if (j > 0 && (j % 4) == 0) + f_out (f, L"\n"); + f_out (f, L"%-4s %08X ", m2cregs[i].regname, val_move2c (m2cregs[i].regno)); + j++; + } + } + if (j > 0) f_out (f, L"\n"); + f_out (f, L"T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d STP=%d\n", + regs.t1, regs.t0, regs.s, regs.m, + GET_XFLG (), GET_NFLG (), GET_ZFLG (), + GET_VFLG (), GET_CFLG (), + regs.intmask, regs.stopped); +#ifdef FPUEMU + if (currprefs.fpu_model) { + uae_u32 fpsr; + for (i = 0; i < 8; i++){ + f_out (f, L"FP%d: %g ", i, regs.fp[i]); + if ((i & 3) == 3) + f_out (f, L"\n"); + } + fpsr = get_fpsr (); + f_out (f, L"N=%d Z=%d I=%d NAN=%d\n", + (fpsr & 0x8000000) != 0, + (fpsr & 0x4000000) != 0, + (fpsr & 0x2000000) != 0, + (fpsr & 0x1000000) != 0); } - fpsr = get_fpsr (); - f_out (f, L"N=%d Z=%d I=%d NAN=%d\n", - (fpsr & 0x8000000) != 0, - (fpsr & 0x4000000) != 0, - (fpsr & 0x2000000) != 0, - (fpsr & 0x1000000) != 0); - } #endif - if (currprefs.cpu_compatible && currprefs.cpu_model == 68000) { - struct instr *dp; - struct mnemolookup *lookup1, *lookup2; - dp = table68k + regs.irc; - for (lookup1 = lookuptab; lookup1->mnemo != dp->mnemo; lookup1++); - dp = table68k + regs.ir; - for (lookup2 = lookuptab; lookup2->mnemo != dp->mnemo; lookup2++); - f_out (f, L"Prefetch %04x (%s) %04x (%s)\n", regs.irc, lookup1->name, regs.ir, lookup2->name); - } - - m68k_disasm (f, m68k_getpc (), nextpc, 1); - if (nextpc) - f_out (f, L"Next PC: %08lx\n", *nextpc); + if (currprefs.cpu_compatible && currprefs.cpu_model == 68000) { + struct instr *dp; + struct mnemolookup *lookup1, *lookup2; + dp = table68k + regs.irc; + for (lookup1 = lookuptab; lookup1->mnemo != dp->mnemo; lookup1++); + dp = table68k + regs.ir; + for (lookup2 = lookuptab; lookup2->mnemo != dp->mnemo; lookup2++); + f_out (f, L"Prefetch %04x (%s) %04x (%s)\n", regs.irc, lookup1->name, regs.ir, lookup2->name); + } + + m68k_disasm (f, m68k_getpc (), nextpc, 1); + if (nextpc) + f_out (f, L"Next PC: %08lx\n", *nextpc); } #ifdef SAVESTATE @@ -3726,543 +3730,548 @@ void m68k_dumpstate (void *f, uaecptr *nextpc) uae_u8 *restore_cpu (uae_u8 *src) { - int i, flags, model; - uae_u32 l; - - changed_prefs.cpu_model = model = restore_u32 (); - flags = restore_u32 (); - changed_prefs.address_space_24 = 0; - if (flags & CPUTYPE_EC) - changed_prefs.address_space_24 = 1; - if (model > 68000) - changed_prefs.cpu_compatible = 0; - currprefs.address_space_24 = changed_prefs.address_space_24; - currprefs.cpu_compatible = changed_prefs.cpu_compatible; - currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact; - currprefs.blitter_cycle_exact = changed_prefs.blitter_cycle_exact; - currprefs.cpu_frequency = changed_prefs.cpu_frequency = 0; - currprefs.cpu_clock_multiplier = changed_prefs.cpu_clock_multiplier = 0; - for (i = 0; i < 15; i++) - regs.regs[i] = restore_u32 (); - regs.pc = restore_u32 (); - regs.irc = restore_u16 (); - regs.ir = restore_u16 (); - regs.usp = restore_u32 (); - regs.isp = restore_u32 (); - regs.sr = restore_u16 (); - l = restore_u32 (); - if (l & CPUMODE_HALT) { - regs.stopped = 1; - set_special (SPCFLAG_STOP); - } else { - regs.stopped = 0; - } - if (model >= 68010) { - regs.dfc = restore_u32 (); - regs.sfc = restore_u32 (); - regs.vbr = restore_u32 (); - } - if (model >= 68020) { - regs.caar = restore_u32 (); - regs.cacr = restore_u32 (); - regs.msp = restore_u32 (); - /* A500 speed in 68020 mode isn't too logical.. */ - if (changed_prefs.m68k_speed == 0 && !(currprefs.cpu_cycle_exact)) - currprefs.m68k_speed = changed_prefs.m68k_speed = -1; - } - if (model >= 68030) { - crp_030 = restore_u64 (); - srp_030 = restore_u64 (); - tt0_030 =restore_u32 (); - tt1_030 = restore_u32 (); - tc_030 = restore_u32 (); - mmusr_030 = restore_u16 (); - } - if (model >= 68040) { - regs.itt0 = restore_u32 (); - regs.itt1 = restore_u32 (); - regs.dtt0 = restore_u32 (); - regs.dtt1 = restore_u32 (); - regs.tcr = restore_u32 (); - regs.urp = restore_u32 (); - regs.srp = restore_u32 (); - } - if (model >= 68060) { - regs.buscr = restore_u32 (); - regs.pcr = restore_u32 (); - } - if (flags & 0x80000000) { - int khz = restore_u32 (); - restore_u32 (); - if (khz > 0 && khz < 800000) - currprefs.m68k_speed = changed_prefs.m68k_speed = 0; - } - write_log (L"CPU: %d%s%03d, PC=%08X\n", - model / 1000, flags & 1 ? L"EC" : L"", model % 1000, regs.pc); - - return src; + int i, flags, model; + uae_u32 l; + + changed_prefs.cpu_model = model = restore_u32 (); + flags = restore_u32 (); + changed_prefs.address_space_24 = 0; + if (flags & CPUTYPE_EC) + changed_prefs.address_space_24 = 1; + if (model > 68000) + changed_prefs.cpu_compatible = 0; + currprefs.address_space_24 = changed_prefs.address_space_24; + currprefs.cpu_compatible = changed_prefs.cpu_compatible; + currprefs.cpu_cycle_exact = changed_prefs.cpu_cycle_exact; + currprefs.blitter_cycle_exact = changed_prefs.blitter_cycle_exact; + currprefs.cpu_frequency = changed_prefs.cpu_frequency = 0; + currprefs.cpu_clock_multiplier = changed_prefs.cpu_clock_multiplier = 0; + for (i = 0; i < 15; i++) + regs.regs[i] = restore_u32 (); + regs.pc = restore_u32 (); + regs.irc = restore_u16 (); + regs.ir = restore_u16 (); + regs.usp = restore_u32 (); + regs.isp = restore_u32 (); + regs.sr = restore_u16 (); + l = restore_u32 (); + if (l & CPUMODE_HALT) { + regs.stopped = 1; + set_special (SPCFLAG_STOP); + } else { + regs.stopped = 0; + } + if (model >= 68010) { + regs.dfc = restore_u32 (); + regs.sfc = restore_u32 (); + regs.vbr = restore_u32 (); + } + if (model >= 68020) { + regs.caar = restore_u32 (); + regs.cacr = restore_u32 (); + regs.msp = restore_u32 (); + /* A500 speed in 68020 mode isn't too logical.. */ + if (changed_prefs.m68k_speed == 0 && !(currprefs.cpu_cycle_exact)) + currprefs.m68k_speed = changed_prefs.m68k_speed = -1; + } + if (model >= 68030) { + crp_030 = restore_u64 (); + srp_030 = restore_u64 (); + tt0_030 =restore_u32 (); + tt1_030 = restore_u32 (); + tc_030 = restore_u32 (); + mmusr_030 = restore_u16 (); + } + if (model >= 68040) { + regs.itt0 = restore_u32 (); + regs.itt1 = restore_u32 (); + regs.dtt0 = restore_u32 (); + regs.dtt1 = restore_u32 (); + regs.tcr = restore_u32 (); + regs.urp = restore_u32 (); + regs.srp = restore_u32 (); + } + if (model >= 68060) { + regs.buscr = restore_u32 (); + regs.pcr = restore_u32 (); + } + if (flags & 0x80000000) { + int khz = restore_u32 (); + restore_u32 (); + if (khz > 0 && khz < 800000) + currprefs.m68k_speed = changed_prefs.m68k_speed = 0; + } + write_log (L"CPU: %d%s%03d, PC=%08X\n", + model / 1000, flags & 1 ? L"EC" : L"", model % 1000, regs.pc); + + return src; } void restore_cpu_finish (void) { - init_m68k (); - m68k_setpc (regs.pc); - set_cpu_caches (); + init_m68k (); + m68k_setpc (regs.pc); + set_cpu_caches (); } uae_u8 *save_cpu (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; - int model, i, khz; - - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (1000); - model = currprefs.cpu_model; - save_u32 (model); /* MODEL */ - save_u32 (0x80000000 | (currprefs.address_space_24 ? 1 : 0)); /* FLAGS */ - for (i = 0;i < 15; i++) - save_u32 (regs.regs[i]); /* D0-D7 A0-A6 */ - save_u32 (m68k_getpc ()); /* PC */ - save_u16 (regs.irc); /* prefetch */ - save_u16 (regs.ir); /* instruction prefetch */ - MakeSR (); - save_u32 (!regs.s ? regs.regs[15] : regs.usp); /* USP */ - save_u32 (regs.s ? regs.regs[15] : regs.isp); /* ISP */ - save_u16 (regs.sr); /* SR/CCR */ - save_u32 (regs.stopped ? CPUMODE_HALT : 0); /* flags */ - if (model >= 68010) { - save_u32 (regs.dfc); /* DFC */ - save_u32 (regs.sfc); /* SFC */ - save_u32 (regs.vbr); /* VBR */ - } - if (model >= 68020) { - save_u32 (regs.caar); /* CAAR */ - save_u32 (regs.cacr); /* CACR */ - save_u32 (regs.msp); /* MSP */ - } - if (model >= 68030) { - save_u64 (crp_030); /* CRP */ - save_u64 (srp_030); /* SRP */ - save_u32 (tt0_030); /* TT0/AC0 */ - save_u32 (tt1_030); /* TT1/AC1 */ - save_u32 (tc_030); /* TCR */ - save_u16 (mmusr_030); /* MMUSR/ACUSR */ - } - if (model >= 68040) { - save_u32 (regs.itt0); /* ITT0 */ - save_u32 (regs.itt1); /* ITT1 */ - save_u32 (regs.dtt0); /* DTT0 */ - save_u32 (regs.dtt1); /* DTT1 */ - save_u32 (regs.tcr); /* TCR */ - save_u32 (regs.urp); /* URP */ - save_u32 (regs.srp); /* SRP */ - } - if (model >= 68060) { - save_u32 (regs.buscr); /* BUSCR */ - save_u32 (regs.pcr); /* PCR */ - } - khz = -1; - if (currprefs.m68k_speed == 0) { - khz = currprefs.ntscmode ? 715909 : 709379; - if (currprefs.cpu_model >= 68020) - khz *= 2; - } - save_u32 (khz); // clock rate in KHz: -1 = fastest possible - save_u32 (0); // spare - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + int model, i, khz; + + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (1000); + model = currprefs.cpu_model; + save_u32 (model); /* MODEL */ + save_u32 (0x80000000 | (currprefs.address_space_24 ? 1 : 0)); /* FLAGS */ + for (i = 0;i < 15; i++) + save_u32 (regs.regs[i]); /* D0-D7 A0-A6 */ + save_u32 (m68k_getpc ()); /* PC */ + save_u16 (regs.irc); /* prefetch */ + save_u16 (regs.ir); /* instruction prefetch */ + MakeSR (); + save_u32 (!regs.s ? regs.regs[15] : regs.usp); /* USP */ + save_u32 (regs.s ? regs.regs[15] : regs.isp); /* ISP */ + save_u16 (regs.sr); /* SR/CCR */ + save_u32 (regs.stopped ? CPUMODE_HALT : 0); /* flags */ + if (model >= 68010) { + save_u32 (regs.dfc); /* DFC */ + save_u32 (regs.sfc); /* SFC */ + save_u32 (regs.vbr); /* VBR */ + } + if (model >= 68020) { + save_u32 (regs.caar); /* CAAR */ + save_u32 (regs.cacr); /* CACR */ + save_u32 (regs.msp); /* MSP */ + } + if (model >= 68030) { + save_u64 (crp_030); /* CRP */ + save_u64 (srp_030); /* SRP */ + save_u32 (tt0_030); /* TT0/AC0 */ + save_u32 (tt1_030); /* TT1/AC1 */ + save_u32 (tc_030); /* TCR */ + save_u16 (mmusr_030); /* MMUSR/ACUSR */ + } + if (model >= 68040) { + save_u32 (regs.itt0); /* ITT0 */ + save_u32 (regs.itt1); /* ITT1 */ + save_u32 (regs.dtt0); /* DTT0 */ + save_u32 (regs.dtt1); /* DTT1 */ + save_u32 (regs.tcr); /* TCR */ + save_u32 (regs.urp); /* URP */ + save_u32 (regs.srp); /* SRP */ + } + if (model >= 68060) { + save_u32 (regs.buscr); /* BUSCR */ + save_u32 (regs.pcr); /* PCR */ + } + khz = -1; + if (currprefs.m68k_speed == 0) { + khz = currprefs.ntscmode ? 715909 : 709379; + if (currprefs.cpu_model >= 68020) + khz *= 2; + } + save_u32 (khz); // clock rate in KHz: -1 = fastest possible + save_u32 (0); // spare + *len = dst - dstbak; + return dstbak; } uae_u8 *save_mmu (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; - int model; - - model = currprefs.mmu_model; - if (model != 68040 && model != 68060) - return NULL; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = xmalloc (1000); - save_u32 (model); /* MODEL */ - save_u32 (0); /* FLAGS */ - *len = dst - dstbak; - return dstbak; + uae_u8 *dstbak, *dst; + int model; + + model = currprefs.mmu_model; + if (model != 68040 && model != 68060) + return NULL; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = xmalloc (1000); + save_u32 (model); /* MODEL */ + save_u32 (0); /* FLAGS */ + *len = dst - dstbak; + return dstbak; } uae_u8 *restore_mmu (uae_u8 *src) { - int flags, model; + int flags, model; - changed_prefs.mmu_model = model = restore_u32 (); - flags = restore_u32 (); - write_log (L"MMU: %d\n", model); - return src; + changed_prefs.mmu_model = model = restore_u32 (); + flags = restore_u32 (); + write_log (L"MMU: %d\n", model); + return src; } #endif /* SAVESTATE */ static void exception3f (uae_u32 opcode, uaecptr addr, uaecptr fault, int writeaccess, int instructionaccess) { - if (currprefs.cpu_model >= 68040) - addr &= ~1; - last_addr_for_exception_3 = addr; - last_fault_for_exception_3 = fault; - last_op_for_exception_3 = opcode; - last_writeaccess_for_exception_3 = writeaccess; - last_instructionaccess_for_exception_3 = instructionaccess; - Exception (3, fault); + if (currprefs.cpu_model >= 68040) + addr &= ~1; + last_addr_for_exception_3 = addr; + last_fault_for_exception_3 = fault; + last_op_for_exception_3 = opcode; + last_writeaccess_for_exception_3 = writeaccess; + last_instructionaccess_for_exception_3 = instructionaccess; + Exception (3, fault); } void exception3 (uae_u32 opcode, uaecptr addr, uaecptr fault) { - exception3f (opcode, addr, fault, 0, 0); + exception3f (opcode, addr, fault, 0, 0); } void exception3i (uae_u32 opcode, uaecptr addr, uaecptr fault) { - exception3f (opcode, addr, fault, 0, 1); + exception3f (opcode, addr, fault, 0, 1); } void exception2 (uaecptr addr, uaecptr fault) { - write_log (L"delayed exception2!\n"); - regs.panic_pc = m68k_getpc (); - regs.panic_addr = addr; - regs.panic = 2; - set_special (SPCFLAG_BRK); - m68k_setpc (0xf80000); + write_log (L"delayed exception2!\n"); + regs.panic_pc = m68k_getpc (); + regs.panic_addr = addr; + regs.panic = 2; + set_special (SPCFLAG_BRK); + m68k_setpc (0xf80000); #ifdef JIT - set_special (SPCFLAG_END_COMPILE); + set_special (SPCFLAG_END_COMPILE); #endif - fill_prefetch_slow (); + fill_prefetch_slow (); } void cpureset (void) { - uaecptr pc; - uaecptr ksboot = 0xf80002 - 2; /* -2 = RESET hasn't increased PC yet */ - uae_u16 ins; + uaecptr pc; + uaecptr ksboot = 0xf80002 - 2; /* -2 = RESET hasn't increased PC yet */ + uae_u16 ins; - if (currprefs.cpu_compatible || currprefs.cpu_cycle_exact) { - customreset (0); - return; - } - pc = m68k_getpc (); - if (pc >= currprefs.chipmem_size) { - addrbank *b = &get_mem_bank (pc); - if (b->check (pc, 2 + 2)) { - /* We have memory, hope for the best.. */ - customreset (0); - return; + if (currprefs.cpu_compatible || currprefs.cpu_cycle_exact) { + customreset (0); + return; + } + pc = m68k_getpc (); + if (pc >= currprefs.chipmem_size) { + addrbank *b = &get_mem_bank (pc); + if (b->check (pc, 2 + 2)) { + /* We have memory, hope for the best.. */ + customreset (0); + return; + } + write_log (L"M68K RESET PC=%x, rebooting..\n", pc); + customreset (0); + m68k_setpc (ksboot); + return; + } + /* panic, RAM is going to disappear under PC */ + ins = get_word (pc + 2); + if ((ins & ~7) == 0x4ed0) { + int reg = ins & 7; + uae_u32 addr = m68k_areg (regs, reg); + write_log (L"reset/jmp (ax) combination emulated -> %x\n", addr); + customreset (0); + if (addr < 0x80000) + addr += 0xf80000; + m68k_setpc (addr - 2); + return; } write_log (L"M68K RESET PC=%x, rebooting..\n", pc); customreset (0); m68k_setpc (ksboot); - return; - } - /* panic, RAM is going to disappear under PC */ - ins = get_word (pc + 2); - if ((ins & ~7) == 0x4ed0) { - int reg = ins & 7; - uae_u32 addr = m68k_areg (regs, reg); - write_log (L"reset/jmp (ax) combination emulated -> %x\n", addr); - customreset (0); - if (addr < 0x80000) - addr += 0xf80000; - m68k_setpc (addr - 2); - return; - } - write_log (L"M68K RESET PC=%x, rebooting..\n", pc); - customreset (0); - m68k_setpc (ksboot); } void m68k_setstopped (void) { - regs.stopped = 1; - /* A traced STOP instruction drops through immediately without - actually stopping. */ - if ((regs.spcflags & SPCFLAG_DOTRACE) == 0) - set_special (SPCFLAG_STOP); - else - m68k_resumestopped (); + regs.stopped = 1; + /* A traced STOP instruction drops through immediately without + actually stopping. */ + if ((regs.spcflags & SPCFLAG_DOTRACE) == 0) + set_special (SPCFLAG_STOP); + else + m68k_resumestopped (); } void m68k_resumestopped (void) { - if (!regs.stopped) - return; - regs.stopped = 0; - fill_prefetch_slow (); - unset_special (SPCFLAG_STOP); + if (!regs.stopped) + return; + regs.stopped = 0; + fill_prefetch_slow (); + unset_special (SPCFLAG_STOP); } /* - * Compute exact number of CPU cycles taken - * by DIVU and DIVS on a 68000 processor. - * - * Copyright (c) 2005 by Jorge Cwik, pasti@fxatari.com - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ +* Compute exact number of CPU cycles taken +* by DIVU and DIVS on a 68000 processor. +* +* Copyright (c) 2005 by Jorge Cwik, pasti@fxatari.com +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this software; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +*/ /* - The routines below take dividend and divisor as parameters. - They return 0 if division by zero, or exact number of cycles otherwise. +The routines below take dividend and divisor as parameters. +They return 0 if division by zero, or exact number of cycles otherwise. + +The number of cycles returned assumes a register operand. +Effective address time must be added if memory operand. - The number of cycles returned assumes a register operand. - Effective address time must be added if memory operand. +For 68000 only (not 68010, 68012, 68020, etc). +Probably valid for 68008 after adding the extra prefetch cycle. - For 68000 only (not 68010, 68012, 68020, etc). - Probably valid for 68008 after adding the extra prefetch cycle. +Best and worst cases for register operand: +(Note the difference with the documented range.) - Best and worst cases for register operand: - (Note the difference with the documented range.) +DIVU: - DIVU: +Overflow (always): 10 cycles. +Worst case: 136 cycles. +Best case: 76 cycles. - Overflow (always): 10 cycles. - Worst case: 136 cycles. - Best case: 76 cycles. +DIVS: - DIVS: +Absolute overflow: 16-18 cycles. +Signed overflow is not detected prematurely. - Absolute overflow: 16-18 cycles. - Signed overflow is not detected prematurely. +Worst case: 156 cycles. +Best case without signed overflow: 122 cycles. +Best case with signed overflow: 120 cycles - Worst case: 156 cycles. - Best case without signed overflow: 122 cycles. - Best case with signed overflow: 120 cycles - - */ +*/ int getDivu68kCycles (uae_u32 dividend, uae_u16 divisor) { - int mcycles; - uae_u32 hdivisor; - int i; + int mcycles; + uae_u32 hdivisor; + int i; - if (divisor == 0) - return 0; + if (divisor == 0) + return 0; - // Overflow - if ((dividend >> 16) >= divisor) - return (mcycles = 5) * 2; + // Overflow + if ((dividend >> 16) >= divisor) + return (mcycles = 5) * 2; - mcycles = 38; - hdivisor = divisor << 16; + mcycles = 38; + hdivisor = divisor << 16; - for (i = 0; i < 15; i++) { - uae_u32 temp; - temp = dividend; + for (i = 0; i < 15; i++) { + uae_u32 temp; + temp = dividend; - dividend <<= 1; + dividend <<= 1; - // If carry from shift - if ((uae_s32)temp < 0) - dividend -= hdivisor; - else { - mcycles += 2; - if (dividend >= hdivisor) { - dividend -= hdivisor; - mcycles--; - } + // If carry from shift + if ((uae_s32)temp < 0) + dividend -= hdivisor; + else { + mcycles += 2; + if (dividend >= hdivisor) { + dividend -= hdivisor; + mcycles--; + } + } } - } - return mcycles * 2; + return mcycles * 2; } int getDivs68kCycles (uae_s32 dividend, uae_s16 divisor) { - int mcycles; - uae_u32 aquot; - int i; + int mcycles; + uae_u32 aquot; + int i; - if (divisor == 0) - return 0; + if (divisor == 0) + return 0; - mcycles = 6; + mcycles = 6; - if (dividend < 0) - mcycles++; + if (dividend < 0) + mcycles++; - // Check for absolute overflow - if (((uae_u32)abs (dividend) >> 16) >= (uae_u16)abs (divisor)) - return (mcycles + 2) * 2; + // Check for absolute overflow + if (((uae_u32)abs (dividend) >> 16) >= (uae_u16)abs (divisor)) + return (mcycles + 2) * 2; - // Absolute quotient - aquot = (uae_u32) abs (dividend) / (uae_u16)abs (divisor); + // Absolute quotient + aquot = (uae_u32) abs (dividend) / (uae_u16)abs (divisor); - mcycles += 55; + mcycles += 55; - if (divisor >= 0) { - if (dividend >= 0) - mcycles--; - else - mcycles++; - } + if (divisor >= 0) { + if (dividend >= 0) + mcycles--; + else + mcycles++; + } - // Count 15 msbits in absolute of quotient + // Count 15 msbits in absolute of quotient - for (i = 0; i < 15; i++) { - if ((uae_s16)aquot >= 0) - mcycles++; - aquot <<= 1; - } + for (i = 0; i < 15; i++) { + if ((uae_s16)aquot >= 0) + mcycles++; + aquot <<= 1; + } - return mcycles * 2; + return mcycles * 2; } #if 0 STATIC_INLINE void fill_cache040 (uae_u32 addr) { - int index, i, j; - uae_u32 tag; - uae_u32 data; - struct cache040 *c; - - addr &= ~15; - index = (addr >> 4) & (CACHESETS040 - 1); - tag = regs.s | (addr & ~((CACHESETS040 << 4) - 1)); - c = &caches040[index]; - for (i = 0; i < CACHELINES040; i++) { - struct cache040set *cs = &c->cs; - for (j = 0; j < 4; j++) { - if (cs->valid[j] && c->tag == tag[j]) { - // cache hit - regs.prefetch020addr = addr; - regs.prefetch020data = c->data[j]; - return; - } if (cs->valid[j] == 0) { - inv = &cs->valid[j]; - } - } - } - // cache miss - data = mem_access_delay_longi_read_020 (addr); - if (1) { - c->tag = tag; - c->valid = !!(regs.cacr & 0x8000); - c->data = data; - } - regs.prefetch020addr = addr; - regs.prefetch020data = data; + int index, i, j; + uae_u32 tag; + uae_u32 data; + struct cache040 *c; + + addr &= ~15; + index = (addr >> 4) & (CACHESETS040 - 1); + tag = regs.s | (addr & ~((CACHESETS040 << 4) - 1)); + c = &caches040[index]; + for (i = 0; i < CACHELINES040; i++) { + struct cache040set *cs = &c->cs; + for (j = 0; j < 4; j++) { + if (cs->valid[j] && c->tag == tag[j]) { + // cache hit + regs.prefetch020addr = addr; + regs.prefetch020data = c->data[j]; + return; + } if (cs->valid[j] == 0) { + inv = &cs->valid[j]; + } + } + } + // cache miss + data = mem_access_delay_longi_read_020 (addr); + if (1) { + c->tag = tag; + c->valid = !!(regs.cacr & 0x8000); + c->data = data; + } + regs.prefetch020addr = addr; + regs.prefetch020data = data; } #endif STATIC_INLINE void fill_cache020 (uae_u32 addr) { - int index; - uae_u32 tag; - uae_u32 data; - struct cache020 *c; - - addr &= ~3; - index = (addr >> 2) & (CACHELINES020 - 1); - tag = regs.s | (addr & ~((CACHELINES020 << 2) - 1)); - c = &caches020[index]; - if (c->valid && c->tag == tag) { - // cache hit + int index; + uae_u32 tag; + uae_u32 data; + struct cache020 *c; + + addr &= ~3; + index = (addr >> 2) & (CACHELINES020 - 1); + tag = regs.s | (addr & ~((CACHELINES020 << 2) - 1)); + c = &caches020[index]; + if (c->valid && c->tag == tag) { + // cache hit + regs.prefetch020addr = addr; + regs.prefetch020data = c->data; + return; + } + // cache miss + data = mem_access_delay_longi_read_ce020 (addr); + if (!(regs.cacr & 2)) { + c->tag = tag; + c->valid = !!(regs.cacr & 1); + c->data = data; + } regs.prefetch020addr = addr; - regs.prefetch020data = c->data; - return; - } - // cache miss - data = mem_access_delay_longi_read_020 (addr); - if (!(regs.cacr & 2)) { - c->tag = tag; - c->valid = !!(regs.cacr & 1); - c->data = data; - } - regs.prefetch020addr = addr; - regs.prefetch020data = data; + regs.prefetch020data = data; } void fill_cache0x0 (uae_u32 addr) { #if 0 - if (currprefs.cpu_model >= 68040) - fill_cache040 (addr); - else + if (currprefs.cpu_model >= 68040) + fill_cache040 (addr); + else #endif - fill_cache020 (addr); + fill_cache020 (addr); } void do_cycles_ce020 (int clocks) { - do_cycles_ce (clocks * cpucycleunit); + do_cycles_ce (clocks * cpucycleunit); +} +void do_cycles_ce020_mem (int clocks) +{ + regs.ce020memcycles -= clocks * cpucycleunit; + do_cycles_ce (clocks * cpucycleunit); } void do_cycles_ce000 (int clocks) { - do_cycles_ce (clocks * cpucycleunit); + do_cycles_ce (clocks * cpucycleunit); } void m68k_do_rte (uae_u32 pc, uae_u16 sr, uae_u16 format, uae_u16 opcode) { - int f; - - f = format >> 12; - if (f == 0) { - ; - } else if (f == 0x1) { - ; - } else if (f == 0x2) { - m68k_areg (regs, 7) += 4; - } else if (f == 0x4) { - m68k_areg (regs, 7) += 8; - } else if (f == 0x8) { - m68k_areg (regs, 7) += 50; - } else if (f == 0x7) { - uae_u16 ssr = get_word_mmu (m68k_areg (regs, 7) + 4); - if (ssr & MMU_SSW_CT) { - uaecptr src_a7 = m68k_areg (regs, 7) - 8; - uaecptr dst_a7 = m68k_areg (regs, 7) + 52; - put_word_mmu (dst_a7 + 0, get_word_mmu (src_a7 + 0)); - put_long_mmu (dst_a7 + 2, get_long_mmu (src_a7 + 2)); - // skip this word - put_long_mmu (dst_a7 + 8, get_long_mmu (src_a7 + 8)); - } - m68k_areg (regs, 7) += 52; - } else if (f == 0x9) { - m68k_areg (regs, 7) += 12; - } else if (f == 0xa) { - m68k_areg (regs, 7) += 24; - } else if (f == 0xb) { - m68k_areg (regs, 7) += 84; - } else { - Exception (14, 0); - return; - } - regs.sr = sr; - MakeFromSR (); - if (pc & 1) - exception3 (0x4E73, m68k_getpc (), pc); - else - m68k_setpc (pc); + int f; + + f = format >> 12; + if (f == 0) { + ; + } else if (f == 0x1) { + ; + } else if (f == 0x2) { + m68k_areg (regs, 7) += 4; + } else if (f == 0x4) { + m68k_areg (regs, 7) += 8; + } else if (f == 0x8) { + m68k_areg (regs, 7) += 50; + } else if (f == 0x7) { + uae_u16 ssr = get_word_mmu (m68k_areg (regs, 7) + 4); + if (ssr & MMU_SSW_CT) { + uaecptr src_a7 = m68k_areg (regs, 7) - 8; + uaecptr dst_a7 = m68k_areg (regs, 7) + 52; + put_word_mmu (dst_a7 + 0, get_word_mmu (src_a7 + 0)); + put_long_mmu (dst_a7 + 2, get_long_mmu (src_a7 + 2)); + // skip this word + put_long_mmu (dst_a7 + 8, get_long_mmu (src_a7 + 8)); + } + m68k_areg (regs, 7) += 52; + } else if (f == 0x9) { + m68k_areg (regs, 7) += 12; + } else if (f == 0xa) { + m68k_areg (regs, 7) += 24; + } else if (f == 0xb) { + m68k_areg (regs, 7) += 84; + } else { + Exception (14, 0); + return; + } + regs.sr = sr; + MakeFromSR (); + if (pc & 1) + exception3 (0x4E73, m68k_getpc (), pc); + else + m68k_setpc (pc); } void flush_mmu (uaecptr addr, int n) @@ -4271,56 +4280,56 @@ void flush_mmu (uaecptr addr, int n) void m68k_do_rts_mmu (void) { - m68k_setpc (get_long_mmu (m68k_areg (regs, 7))); - m68k_areg (regs, 7) += 4; + m68k_setpc (get_long_mmu (m68k_areg (regs, 7))); + m68k_areg (regs, 7) += 4; } void m68k_do_bsr_mmu (uaecptr oldpc, uae_s32 offset) { - put_long_mmu (m68k_areg (regs, 7) - 4, oldpc); - m68k_areg (regs, 7) -= 4; - m68k_incpci (offset); + put_long_mmu (m68k_areg (regs, 7) - 4, oldpc); + m68k_areg (regs, 7) -= 4; + m68k_incpci (offset); } void put_long_slow (uaecptr addr, uae_u32 v) { - if (currprefs.mmu_model) - put_long_mmu (addr, v); - else - put_long (addr, v); + if (currprefs.mmu_model) + put_long_mmu (addr, v); + else + put_long (addr, v); } void put_word_slow (uaecptr addr, uae_u32 v) { - if (currprefs.mmu_model) - put_word_mmu (addr, v); - else - put_word (addr, v); + if (currprefs.mmu_model) + put_word_mmu (addr, v); + else + put_word (addr, v); } void put_byte_slow (uaecptr addr, uae_u32 v) { - if (currprefs.mmu_model) - put_byte_mmu (addr, v); - else - put_byte (addr, v); + if (currprefs.mmu_model) + put_byte_mmu (addr, v); + else + put_byte (addr, v); } uae_u32 get_long_slow (uaecptr addr) { - if (currprefs.mmu_model) - return get_long_mmu (addr); - else - return get_long (addr); + if (currprefs.mmu_model) + return get_long_mmu (addr); + else + return get_long (addr); } uae_u32 get_word_slow (uaecptr addr) { - if (currprefs.mmu_model) - return get_word_mmu (addr); - else - return get_word (addr); + if (currprefs.mmu_model) + return get_word_mmu (addr); + else + return get_word (addr); } uae_u32 get_byte_slow (uaecptr addr) { - if (currprefs.mmu_model) - return get_byte_mmu (addr); - else - return get_byte (addr); + if (currprefs.mmu_model) + return get_byte_mmu (addr); + else + return get_byte (addr); } diff --git a/od-win32/ahidsound_dsonly.c b/od-win32/ahidsound_dsonly.c index 7cf81d27..5274470e 100644 --- a/od-win32/ahidsound_dsonly.c +++ b/od-win32/ahidsound_dsonly.c @@ -1,12 +1,12 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 interface - * - * Copyright 1997 Mathias Ortmann - * Copyright 1997-2001 Brian King - * Copyright 2000-2002 Bernd Roesch - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 interface +* +* Copyright 1997 Mathias Ortmann +* Copyright 1997-2001 Brian King +* Copyright 2000-2002 Bernd Roesch +*/ #define NATIVBUFFNUM 4 #define RECORDBUFFER 50 //survive 9 sec of blocking at 44100 @@ -73,11 +73,11 @@ static LPDIRECTSOUNDCAPTUREBUFFER lpDSBprimary2r = NULL; static LPDIRECTSOUNDCAPTUREBUFFER lpDSB2r = NULL; struct winuae //this struct is put in a6 if you call - //execute native function + //execute native function { - HWND amigawnd; //adress of amiga Window Windows Handle - unsigned int changenum; //number to detect screen close/open - unsigned int z3offset; //the offset to add to acsess Z3 mem from Dll side + HWND amigawnd; //adress of amiga Window Windows Handle + unsigned int changenum; //number to detect screen close/open + unsigned int z3offset; //the offset to add to acsess Z3 mem from Dll side }; static struct winuae uaevar; static struct winuae *a6; @@ -91,324 +91,324 @@ static struct winuae *a6; static uae_u32 REGPARAM2 emulib_ExecuteNativeCode2 (TrapContext *context) { - unsigned int espstore; - uae_u8* object_UAM = (uae_u8*) m68k_areg (regs, 0); - uae_u32 d1 = m68k_dreg (regs, 1); - uae_u32 d2 = m68k_dreg (regs, 2); - uae_u32 d3 = m68k_dreg (regs, 3); - uae_u32 d4 = m68k_dreg (regs, 4); - uae_u32 d5 = m68k_dreg (regs, 5); - uae_u32 d6 = m68k_dreg (regs, 6); - uae_u32 d7 = m68k_dreg (regs, 7); - uae_u32 a1 = m68k_areg (regs, 1); - uae_u32 a2 = m68k_areg (regs, 2); - uae_u32 a3 = m68k_areg (regs, 3); - uae_u32 a4 = m68k_areg (regs, 4); - uae_u32 a5 = m68k_areg (regs, 5); - uae_u32 a7 = m68k_areg (regs, 7); - uae_u32 regs_ = (uae_u32)®s; - CREATE_NATIVE_FUNC_PTR2; - uaevar.z3offset = (uae_u32)(get_real_address (0x10000000) - 0x10000000); - uaevar.amigawnd = hAmigaWnd; - a6 = &uaevar; - if (object_UAM) { - SET_NATIVE_FUNC2 (object_UAM); - __asm - { mov espstore,esp - push regs_ - push a7 - push a6 - push a5 - push a4 - push a3 - push a2 - push a1 - push d7 - push d6 - push d5 - push d4 - push d3 - push d2 - push d1 - call native_func - mov esp,espstore + unsigned int espstore; + uae_u8* object_UAM = (uae_u8*) m68k_areg (regs, 0); + uae_u32 d1 = m68k_dreg (regs, 1); + uae_u32 d2 = m68k_dreg (regs, 2); + uae_u32 d3 = m68k_dreg (regs, 3); + uae_u32 d4 = m68k_dreg (regs, 4); + uae_u32 d5 = m68k_dreg (regs, 5); + uae_u32 d6 = m68k_dreg (regs, 6); + uae_u32 d7 = m68k_dreg (regs, 7); + uae_u32 a1 = m68k_areg (regs, 1); + uae_u32 a2 = m68k_areg (regs, 2); + uae_u32 a3 = m68k_areg (regs, 3); + uae_u32 a4 = m68k_areg (regs, 4); + uae_u32 a5 = m68k_areg (regs, 5); + uae_u32 a7 = m68k_areg (regs, 7); + uae_u32 regs_ = (uae_u32)®s; + CREATE_NATIVE_FUNC_PTR2; + uaevar.z3offset = (uae_u32)(get_real_address (0x10000000) - 0x10000000); + uaevar.amigawnd = hAmigaWnd; + a6 = &uaevar; + if (object_UAM) { + SET_NATIVE_FUNC2 (object_UAM); + __asm + { mov espstore,esp + push regs_ + push a7 + push a6 + push a5 + push a4 + push a3 + push a2 + push a1 + push d7 + push d6 + push d5 + push d4 + push d3 + push d2 + push d1 + call native_func + mov esp,espstore + } + //CALL_NATIVE_FUNC2( d1, d2,d3, d4, d5, d6, d7, a1, a2, a3, a4 , a5 , a6 , a7); + } else { + return 0; } - //CALL_NATIVE_FUNC2( d1, d2,d3, d4, d5, d6, d7, a1, a2, a3, a4 , a5 , a6 , a7); - } else { - return 0; - } } #endif void ahi_close_sound (void) { - HRESULT hr = DS_OK; - - if (!ahi_on) - return; - ahi_on = 0; - record_enabled = 0; - ahisndbufpt = (int*)ahisndbuffer; - - if (lpDSB2) { - hr = IDirectSoundBuffer_Stop (lpDSB2); - if(FAILED (hr)) - write_log (L"AHI: SoundStop() failure: %s\n", DXError (hr)); - } else { - write_log (L"AHI: Sound Stopped...\n"); - } - - if (lpDSB2) - IDirectSoundBuffer_Release (lpDSB2); - lpDSB2 = NULL; - if (lpDSBprimary2) - IDirectSoundBuffer_Release (lpDSBprimary2); - lpDSBprimary2 = NULL; - if (lpDS2) - IDirectSound_Release (lpDS2); - lpDS2 = NULL; - - if (lpDSB2r) - IDirectSoundCaptureBuffer_Release (lpDSB2r); - lpDSB2r = NULL; - if (lpDS2r) - IDirectSound_Release (lpDS2r); - lpDS2r = NULL; - if (ahisndbuffer) - free (ahisndbuffer); - ahisndbuffer = NULL; + HRESULT hr = DS_OK; + + if (!ahi_on) + return; + ahi_on = 0; + record_enabled = 0; + ahisndbufpt = (int*)ahisndbuffer; + + if (lpDSB2) { + hr = IDirectSoundBuffer_Stop (lpDSB2); + if(FAILED (hr)) + write_log (L"AHI: SoundStop() failure: %s\n", DXError (hr)); + } else { + write_log (L"AHI: Sound Stopped...\n"); + } + + if (lpDSB2) + IDirectSoundBuffer_Release (lpDSB2); + lpDSB2 = NULL; + if (lpDSBprimary2) + IDirectSoundBuffer_Release (lpDSBprimary2); + lpDSBprimary2 = NULL; + if (lpDS2) + IDirectSound_Release (lpDS2); + lpDS2 = NULL; + + if (lpDSB2r) + IDirectSoundCaptureBuffer_Release (lpDSB2r); + lpDSB2r = NULL; + if (lpDS2r) + IDirectSound_Release (lpDS2r); + lpDS2r = NULL; + if (ahisndbuffer) + free (ahisndbuffer); + ahisndbuffer = NULL; } void ahi_updatesound(int force) { - HRESULT hr; - int pos; - unsigned int dwBytes1, dwBytes2; - LPVOID dwData1, dwData2; - static int oldpos; - - if (sound_flushes2 == 1) { - oldpos = 0; - intcount = 1; - INTREQ (0x8000 | 0x2000); - hr = IDirectSoundBuffer_Play (lpDSB2, 0, 0, DSBPLAY_LOOPING); - if(hr == DSERR_BUFFERLOST) { - IDirectSoundBuffer_Restore (lpDSB2); - hr = IDirectSoundBuffer_Play (lpDSB2, 0, 0, DSBPLAY_LOOPING); - } - } - - hr = IDirectSoundBuffer_GetCurrentPosition (lpDSB2, &pos, 0); - if (hr != DSERR_BUFFERLOST) { - pos -= ahitweak; - if (pos < 0) - pos += ahisndbufsize; - if (pos >= ahisndbufsize) - pos -= ahisndbufsize; - pos = (pos / (amigablksize * 4)) * (amigablksize * 4); - if (force == 1) { - if (oldpos != pos) { + HRESULT hr; + int pos; + unsigned int dwBytes1, dwBytes2; + LPVOID dwData1, dwData2; + static int oldpos; + + if (sound_flushes2 == 1) { + oldpos = 0; intcount = 1; INTREQ (0x8000 | 0x2000); - return; //to generate amiga ints every amigablksize - } else { - return; - } + hr = IDirectSoundBuffer_Play (lpDSB2, 0, 0, DSBPLAY_LOOPING); + if(hr == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (lpDSB2); + hr = IDirectSoundBuffer_Play (lpDSB2, 0, 0, DSBPLAY_LOOPING); + } + } + + hr = IDirectSoundBuffer_GetCurrentPosition (lpDSB2, &pos, 0); + if (hr != DSERR_BUFFERLOST) { + pos -= ahitweak; + if (pos < 0) + pos += ahisndbufsize; + if (pos >= ahisndbufsize) + pos -= ahisndbufsize; + pos = (pos / (amigablksize * 4)) * (amigablksize * 4); + if (force == 1) { + if (oldpos != pos) { + intcount = 1; + INTREQ (0x8000 | 0x2000); + return; //to generate amiga ints every amigablksize + } else { + return; + } + } } - } - hr = IDirectSoundBuffer_Lock (lpDSB2, oldpos, amigablksize * 4, &dwData1, &dwBytes1, &dwData2, &dwBytes2, 0); - if(hr == DSERR_BUFFERLOST) { - write_log (L"AHI: lostbuf %d %x\n", pos, amigablksize); - IDirectSoundBuffer_Restore (lpDSB2); hr = IDirectSoundBuffer_Lock (lpDSB2, oldpos, amigablksize * 4, &dwData1, &dwBytes1, &dwData2, &dwBytes2, 0); - } - if(FAILED(hr)) - return; - - if (currprefs.sound_stereo_swap_ahi) { - int i; - uae_s16 *p = (uae_s16*)ahisndbuffer; - for (i = 0; i < (dwBytes1 + dwBytes2) / 2; i += 2) { - uae_s16 tmp; - tmp = p[i + 0]; - p[i + 0] = p[i + 1]; - p[i + 1] = tmp; + if(hr == DSERR_BUFFERLOST) { + write_log (L"AHI: lostbuf %d %x\n", pos, amigablksize); + IDirectSoundBuffer_Restore (lpDSB2); + hr = IDirectSoundBuffer_Lock (lpDSB2, oldpos, amigablksize * 4, &dwData1, &dwBytes1, &dwData2, &dwBytes2, 0); } - } + if(FAILED(hr)) + return; - memcpy (dwData1, ahisndbuffer, dwBytes1); - if (dwData2) - memcpy (dwData2, (uae_u8*)ahisndbuffer + dwBytes1, dwBytes2); + if (currprefs.sound_stereo_swap_ahi) { + int i; + uae_s16 *p = (uae_s16*)ahisndbuffer; + for (i = 0; i < (dwBytes1 + dwBytes2) / 2; i += 2) { + uae_s16 tmp; + tmp = p[i + 0]; + p[i + 0] = p[i + 1]; + p[i + 1] = tmp; + } + } - sndptrmax = ahisndbuffer + ahisndbufsize; - ahisndbufpt = (int*)ahisndbuffer; + memcpy (dwData1, ahisndbuffer, dwBytes1); + if (dwData2) + memcpy (dwData2, (uae_u8*)ahisndbuffer + dwBytes1, dwBytes2); - IDirectSoundBuffer_Unlock (lpDSB2, dwData1, dwBytes1, dwData2, dwBytes2); + sndptrmax = ahisndbuffer + ahisndbufsize; + ahisndbufpt = (int*)ahisndbuffer; - oldpos += amigablksize * 4; - if (oldpos >= ahisndbufsize) - oldpos -= ahisndbufsize; - if (oldpos != pos) { - intcount = 1; - INTREQ (0x8000 | 0x2000); - } + IDirectSoundBuffer_Unlock (lpDSB2, dwData1, dwBytes1, dwData2, dwBytes2); + + oldpos += amigablksize * 4; + if (oldpos >= ahisndbufsize) + oldpos -= ahisndbufsize; + if (oldpos != pos) { + intcount = 1; + INTREQ (0x8000 | 0x2000); + } } void ahi_finish_sound_buffer (void) { - sound_flushes2++; - ahi_updatesound(2); + sound_flushes2++; + ahi_updatesound(2); } static WAVEFORMATEX wavfmt; static int ahi_init_record_win32 (void) { - HRESULT hr; - DSCBUFFERDESC sound_buffer_rec; - // Record begin - hr = DirectSoundCaptureCreate (NULL, &lpDS2r, NULL); - if (FAILED (hr)) { - write_log (L"AHI: DirectSoundCaptureCreate() failure: %s\n", DXError (hr)); - record_enabled = -1; - return 0; - } - memset (&sound_buffer_rec, 0, sizeof (DSCBUFFERDESC)); - sound_buffer_rec.dwSize = sizeof (DSCBUFFERDESC); - sound_buffer_rec.dwBufferBytes = amigablksize * 4 * RECORDBUFFER; - sound_buffer_rec.lpwfxFormat = &wavfmt; - sound_buffer_rec.dwFlags = 0 ; - - hr = IDirectSoundCapture_CreateCaptureBuffer (lpDS2r, &sound_buffer_rec, &lpDSB2r, NULL); - if (FAILED (hr)) { - write_log (L"AHI: CreateCaptureSoundBuffer() failure: %s\n", DXError(hr)); - record_enabled = -1; - return 0; - } + HRESULT hr; + DSCBUFFERDESC sound_buffer_rec; + // Record begin + hr = DirectSoundCaptureCreate (NULL, &lpDS2r, NULL); + if (FAILED (hr)) { + write_log (L"AHI: DirectSoundCaptureCreate() failure: %s\n", DXError (hr)); + record_enabled = -1; + return 0; + } + memset (&sound_buffer_rec, 0, sizeof (DSCBUFFERDESC)); + sound_buffer_rec.dwSize = sizeof (DSCBUFFERDESC); + sound_buffer_rec.dwBufferBytes = amigablksize * 4 * RECORDBUFFER; + sound_buffer_rec.lpwfxFormat = &wavfmt; + sound_buffer_rec.dwFlags = 0 ; + + hr = IDirectSoundCapture_CreateCaptureBuffer (lpDS2r, &sound_buffer_rec, &lpDSB2r, NULL); + if (FAILED (hr)) { + write_log (L"AHI: CreateCaptureSoundBuffer() failure: %s\n", DXError(hr)); + record_enabled = -1; + return 0; + } - hr = IDirectSoundCaptureBuffer_Start (lpDSB2r, DSCBSTART_LOOPING); - if (FAILED (hr)) { - write_log (L"AHI: DirectSoundCaptureBuffer_Start failed: %s\n", DXError (hr)); - record_enabled = -1; - return 0; - } - record_enabled = 1; - write_log (L"AHI: Init AHI Audio Recording \n"); - return 1; + hr = IDirectSoundCaptureBuffer_Start (lpDSB2r, DSCBSTART_LOOPING); + if (FAILED (hr)) { + write_log (L"AHI: DirectSoundCaptureBuffer_Start failed: %s\n", DXError (hr)); + record_enabled = -1; + return 0; + } + record_enabled = 1; + write_log (L"AHI: Init AHI Audio Recording \n"); + return 1; } void setvolume_ahi (LONG vol) { - HRESULT hr; - if (!lpDS2) - return; - hr = IDirectSoundBuffer_SetVolume (lpDSB2, vol); - if (FAILED (hr)) - write_log (L"AHI: SetVolume(%d) failed: %s\n", vol, DXError (hr)); + HRESULT hr; + if (!lpDS2) + return; + hr = IDirectSoundBuffer_SetVolume (lpDSB2, vol); + if (FAILED (hr)) + write_log (L"AHI: SetVolume(%d) failed: %s\n", vol, DXError (hr)); } static int ahi_init_sound_win32 (void) { - HRESULT hr; - DSBUFFERDESC sound_buffer; - DSCAPS DSCaps; + HRESULT hr; + DSBUFFERDESC sound_buffer; + DSCAPS DSCaps; - if (lpDS2) - return 0; + if (lpDS2) + return 0; - enumerate_sound_devices (); - wavfmt.wFormatTag = WAVE_FORMAT_PCM; - wavfmt.nChannels = sound_channels_ahi; - wavfmt.nSamplesPerSec = sound_freq_ahi; - wavfmt.wBitsPerSample = sound_bits_ahi; - wavfmt.nBlockAlign = wavfmt.wBitsPerSample / 8 * wavfmt.nChannels; - wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * sound_freq_ahi; - wavfmt.cbSize = 0; + enumerate_sound_devices (); + wavfmt.wFormatTag = WAVE_FORMAT_PCM; + wavfmt.nChannels = sound_channels_ahi; + wavfmt.nSamplesPerSec = sound_freq_ahi; + wavfmt.wBitsPerSample = sound_bits_ahi; + wavfmt.nBlockAlign = wavfmt.wBitsPerSample / 8 * wavfmt.nChannels; + wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * sound_freq_ahi; + wavfmt.cbSize = 0; - write_log (L"AHI: Init AHI Sound Rate %d, Channels %d, Bits %d, Buffsize %d\n", - sound_freq_ahi, sound_channels_ahi, sound_bits_ahi, amigablksize); + write_log (L"AHI: Init AHI Sound Rate %d, Channels %d, Bits %d, Buffsize %d\n", + sound_freq_ahi, sound_channels_ahi, sound_bits_ahi, amigablksize); - if (!amigablksize) - return 0; - soundneutral = 0; - ahisndbufsize = (amigablksize * 4) * NATIVBUFFNUM; // use 4 native buffer - ahisndbuffer = malloc (ahisndbufsize + 32); - if (!ahisndbuffer) - return 0; - if (sound_devices[currprefs.win32_soundcard].type != SOUND_DEVICE_DS) - hr = DirectSoundCreate (NULL, &lpDS2, NULL); - else - hr = DirectSoundCreate (&sound_devices[currprefs.win32_soundcard].guid, &lpDS2, NULL); - if (FAILED (hr)) { - write_log (L"AHI: DirectSoundCreate() failure: %s\n", DXError (hr)); - return 0; - } - memset (&sound_buffer, 0, sizeof (DSBUFFERDESC)); - sound_buffer.dwSize = sizeof (DSBUFFERDESC); - sound_buffer.dwFlags = DSBCAPS_PRIMARYBUFFER; - sound_buffer.dwBufferBytes = 0; - sound_buffer.lpwfxFormat = NULL; - - DSCaps.dwSize = sizeof(DSCAPS); - hr = IDirectSound_GetCaps (lpDS2, &DSCaps); - if (SUCCEEDED (hr)) { - if (DSCaps.dwFlags & DSCAPS_EMULDRIVER) - write_log (L"AHI: Your DirectSound Driver is emulated via WaveOut - yuck!\n"); - } - if (FAILED (IDirectSound_SetCooperativeLevel (lpDS2, hMainWnd, DSSCL_PRIORITY))) - return 0; - hr = IDirectSound_CreateSoundBuffer (lpDS2, &sound_buffer, &lpDSBprimary2, NULL); - if (FAILED (hr)) { - write_log (L"AHI: CreateSoundBuffer() failure: %s\n", DXError(hr)); - return 0; - } - hr = IDirectSoundBuffer_SetFormat (lpDSBprimary2, &wavfmt); - if (FAILED (hr)) { - write_log (L"AHI: SetFormat() failure: %s\n", DXError (hr)); - return 0; - } - sound_buffer.dwBufferBytes = ahisndbufsize; - sound_buffer.lpwfxFormat = &wavfmt; - sound_buffer.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLVOLUME - | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE; - sound_buffer.guid3DAlgorithm = GUID_NULL; - hr = IDirectSound_CreateSoundBuffer (lpDS2, &sound_buffer, &lpDSB2, NULL); - if (FAILED (hr)) { - write_log (L"AHI: CreateSoundBuffer() failure: %s\n", DXError (hr)); - return 0; - } + if (!amigablksize) + return 0; + soundneutral = 0; + ahisndbufsize = (amigablksize * 4) * NATIVBUFFNUM; // use 4 native buffer + ahisndbuffer = malloc (ahisndbufsize + 32); + if (!ahisndbuffer) + return 0; + if (sound_devices[currprefs.win32_soundcard].type != SOUND_DEVICE_DS) + hr = DirectSoundCreate (NULL, &lpDS2, NULL); + else + hr = DirectSoundCreate (&sound_devices[currprefs.win32_soundcard].guid, &lpDS2, NULL); + if (FAILED (hr)) { + write_log (L"AHI: DirectSoundCreate() failure: %s\n", DXError (hr)); + return 0; + } + memset (&sound_buffer, 0, sizeof (DSBUFFERDESC)); + sound_buffer.dwSize = sizeof (DSBUFFERDESC); + sound_buffer.dwFlags = DSBCAPS_PRIMARYBUFFER; + sound_buffer.dwBufferBytes = 0; + sound_buffer.lpwfxFormat = NULL; + + DSCaps.dwSize = sizeof(DSCAPS); + hr = IDirectSound_GetCaps (lpDS2, &DSCaps); + if (SUCCEEDED (hr)) { + if (DSCaps.dwFlags & DSCAPS_EMULDRIVER) + write_log (L"AHI: Your DirectSound Driver is emulated via WaveOut - yuck!\n"); + } + if (FAILED (IDirectSound_SetCooperativeLevel (lpDS2, hMainWnd, DSSCL_PRIORITY))) + return 0; + hr = IDirectSound_CreateSoundBuffer (lpDS2, &sound_buffer, &lpDSBprimary2, NULL); + if (FAILED (hr)) { + write_log (L"AHI: CreateSoundBuffer() failure: %s\n", DXError(hr)); + return 0; + } + hr = IDirectSoundBuffer_SetFormat (lpDSBprimary2, &wavfmt); + if (FAILED (hr)) { + write_log (L"AHI: SetFormat() failure: %s\n", DXError (hr)); + return 0; + } + sound_buffer.dwBufferBytes = ahisndbufsize; + sound_buffer.lpwfxFormat = &wavfmt; + sound_buffer.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLVOLUME + | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE; + sound_buffer.guid3DAlgorithm = GUID_NULL; + hr = IDirectSound_CreateSoundBuffer (lpDS2, &sound_buffer, &lpDSB2, NULL); + if (FAILED (hr)) { + write_log (L"AHI: CreateSoundBuffer() failure: %s\n", DXError (hr)); + return 0; + } - setvolume_ahi (0); + setvolume_ahi (0); - hr = IDirectSoundBuffer_GetFormat (lpDSBprimary2,&wavfmt,500,0); - if (FAILED (hr)) { - write_log (L"AHI: GetFormat() failure: %s\n", DXError (hr)); - return 0; - } + hr = IDirectSoundBuffer_GetFormat (lpDSBprimary2,&wavfmt,500,0); + if (FAILED (hr)) { + write_log (L"AHI: GetFormat() failure: %s\n", DXError (hr)); + return 0; + } - ahisndbufpt =(int*)ahisndbuffer; - sndptrmax = ahisndbuffer + ahisndbufsize; - memset (ahisndbuffer, soundneutral, amigablksize * 8); - ahi_on = 1; - return sound_freq_ahi; + ahisndbufpt =(int*)ahisndbuffer; + sndptrmax = ahisndbuffer + ahisndbufsize; + memset (ahisndbuffer, soundneutral, amigablksize * 8); + ahi_on = 1; + return sound_freq_ahi; } int ahi_open_sound (void) { - int rate; + int rate; - uaevar.changenum++; - if (!sound_freq_ahi) + uaevar.changenum++; + if (!sound_freq_ahi) + return 0; + if (ahi_on) + ahi_close_sound (); + sound_flushes2 = 1; + if ((rate = ahi_init_sound_win32 ())) + return rate; return 0; - if (ahi_on) - ahi_close_sound (); - sound_flushes2 = 1; - if ((rate = ahi_init_sound_win32 ())) - return rate; - return 0; } @@ -418,12 +418,12 @@ static double syncdivisor; uae_u32 REGPARAM2 ahi_demux (TrapContext *context) { -//use the extern int (6 #13) -// d0 0=opensound d1=unit d2=samplerate d3=blksize ret: sound frequency -// d0 6=opensound_new d1=unit d2=samplerate d3=blksize ret d4=channels d5=bits d6=zero: sound frequency -// d0 1=closesound d1=unit -// d0 2=writesamples d1=unit a0=addr write blksize samples to card -// d0 3=readsamples d1=unit a0=addr read samples from card ret: d0=samples read + //use the extern int (6 #13) + // d0 0=opensound d1=unit d2=samplerate d3=blksize ret: sound frequency + // d0 6=opensound_new d1=unit d2=samplerate d3=blksize ret d4=channels d5=bits d6=zero: sound frequency + // d0 1=closesound d1=unit + // d0 2=writesamples d1=unit a0=addr write blksize samples to card + // d0 3=readsamples d1=unit a0=addr read samples from card ret: d0=samples read // make sure you have from amigaside blksize*4 mem alloced // d0=-1 no data available d0=-2 no recording open // d0 > 0 there are more blksize Data in the que @@ -431,467 +431,467 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context) // if d0 is greater than 200 bring a message // that show the user that data is lost // maximum blocksbuffered are 250 (8,5 sec) -// d0 4=writeinterrupt d1=unit d0=0 no interrupt happen for this unit + // d0 4=writeinterrupt d1=unit d0=0 no interrupt happen for this unit // d0=-2 no playing open //note units for now not support use only unit 0 -// d0 5=? - // d0=10 get clipboard size d0=size in bytes -// d0=11 get clipboard data a0=clipboarddata - //Note: a get clipboard size must do before -// d0=12 write clipboard data a0=clipboarddata -// d0=13 setp96mouserate d1=hz value -// d0=100 open dll d1=dll name in windows name conventions -// d0=101 get dll function addr d1=dllhandle a0 function/var name -// d0=102 exec dllcode a0=addr of function (see 101) -// d0=103 close dll -// d0=104 screenlost -// d0=105 mem offset -// d0=106 16Bit byteswap -// d0=107 32Bit byteswap -// d0=108 free swap array -// d0=200 ahitweak d1=offset for dsound position pointer - - int opcode = m68k_dreg (regs, 0); - - switch (opcode) - { - uae_u32 src, num_vars; - static int cap_pos, clipsize; - static TCHAR *clipdat; + // d0 5=? + // d0=10 get clipboard size d0=size in bytes + // d0=11 get clipboard data a0=clipboarddata + //Note: a get clipboard size must do before + // d0=12 write clipboard data a0=clipboarddata + // d0=13 setp96mouserate d1=hz value + // d0=100 open dll d1=dll name in windows name conventions + // d0=101 get dll function addr d1=dllhandle a0 function/var name + // d0=102 exec dllcode a0=addr of function (see 101) + // d0=103 close dll + // d0=104 screenlost + // d0=105 mem offset + // d0=106 16Bit byteswap + // d0=107 32Bit byteswap + // d0=108 free swap array + // d0=200 ahitweak d1=offset for dsound position pointer + + int opcode = m68k_dreg (regs, 0); + + switch (opcode) + { + uae_u32 src, num_vars; + static int cap_pos, clipsize; + static TCHAR *clipdat; case 0: - cap_pos = 0; - sound_bits_ahi = 16; - sound_channels_ahi = 2; - sound_freq_ahi = m68k_dreg (regs, 2); - amigablksize = m68k_dreg (regs, 3); - sound_freq_ahi = ahi_open_sound(); - uaevar.changenum--; - return sound_freq_ahi; + cap_pos = 0; + sound_bits_ahi = 16; + sound_channels_ahi = 2; + sound_freq_ahi = m68k_dreg (regs, 2); + amigablksize = m68k_dreg (regs, 3); + sound_freq_ahi = ahi_open_sound(); + uaevar.changenum--; + return sound_freq_ahi; case 6: /* new open function */ - cap_pos = 0; - sound_freq_ahi = m68k_dreg (regs, 2); - amigablksize = m68k_dreg (regs, 3); - sound_channels_ahi = m68k_dreg (regs, 4); - sound_bits_ahi = m68k_dreg (regs, 5); - sound_freq_ahi = ahi_open_sound(); - uaevar.changenum--; - return sound_freq_ahi; + cap_pos = 0; + sound_freq_ahi = m68k_dreg (regs, 2); + amigablksize = m68k_dreg (regs, 3); + sound_channels_ahi = m68k_dreg (regs, 4); + sound_bits_ahi = m68k_dreg (regs, 5); + sound_freq_ahi = ahi_open_sound(); + uaevar.changenum--; + return sound_freq_ahi; case 1: - ahi_close_sound(); - sound_freq_ahi = 0; - return 0; + ahi_close_sound(); + sound_freq_ahi = 0; + return 0; case 2: - { - int i; - uaecptr addr = m68k_areg (regs, 0); - for (i = 0; i < amigablksize * 4; i += 4) - *ahisndbufpt++ = get_long (addr + i); - ahi_finish_sound_buffer(); - } - return amigablksize; + { + int i; + uaecptr addr = m68k_areg (regs, 0); + for (i = 0; i < amigablksize * 4; i += 4) + *ahisndbufpt++ = get_long (addr + i); + ahi_finish_sound_buffer(); + } + return amigablksize; case 3: - { - LPTSTR pos1,pos2; - uaecptr addr; - HRESULT hr; - int i, t, todo, byte1, byte2, cur_pos; - - if (!ahi_on) - return -2; - if (record_enabled == 0) - ahi_init_record_win32(); - if (record_enabled < 0) - return -2; - hr = IDirectSoundCaptureBuffer_GetCurrentPosition(lpDSB2r, &t, &cur_pos); - if (FAILED(hr)) - return -1; - - t = amigablksize * 4; - if (cap_pos <= cur_pos) - todo = cur_pos - cap_pos; - else - todo = cur_pos + (RECORDBUFFER * t) - cap_pos; - if (todo < t) //if no complete buffer ready exit - return -1; - hr = IDirectSoundCaptureBuffer_Lock(lpDSB2r, cap_pos, t, &pos1, &byte1, &pos2, &byte2, 0); - if (FAILED(hr)) - return -1; - if ((cap_pos + t) < (t * RECORDBUFFER)) - cap_pos = cap_pos + t; - else - cap_pos = 0; - addr = m68k_areg (regs, 0); - sndbufrecpt = (unsigned int*)pos1; - t /= 4; - for (i = 0; i < t; i++) { - put_long (addr, *sndbufrecpt++); - addr += 4; - } - t *= 4; - IDirectSoundCaptureBuffer_Unlock(lpDSB2r, pos1, byte1, pos2, byte2); - return (todo - t) / t; - } + { + LPTSTR pos1,pos2; + uaecptr addr; + HRESULT hr; + int i, t, todo, byte1, byte2, cur_pos; + + if (!ahi_on) + return -2; + if (record_enabled == 0) + ahi_init_record_win32(); + if (record_enabled < 0) + return -2; + hr = IDirectSoundCaptureBuffer_GetCurrentPosition(lpDSB2r, &t, &cur_pos); + if (FAILED(hr)) + return -1; + + t = amigablksize * 4; + if (cap_pos <= cur_pos) + todo = cur_pos - cap_pos; + else + todo = cur_pos + (RECORDBUFFER * t) - cap_pos; + if (todo < t) //if no complete buffer ready exit + return -1; + hr = IDirectSoundCaptureBuffer_Lock(lpDSB2r, cap_pos, t, &pos1, &byte1, &pos2, &byte2, 0); + if (FAILED(hr)) + return -1; + if ((cap_pos + t) < (t * RECORDBUFFER)) + cap_pos = cap_pos + t; + else + cap_pos = 0; + addr = m68k_areg (regs, 0); + sndbufrecpt = (unsigned int*)pos1; + t /= 4; + for (i = 0; i < t; i++) { + put_long (addr, *sndbufrecpt++); + addr += 4; + } + t *= 4; + IDirectSoundCaptureBuffer_Unlock(lpDSB2r, pos1, byte1, pos2, byte2); + return (todo - t) / t; + } case 4: - { - int i; - if (!ahi_on) - return -2; - i = intcount; - intcount = 0; - return i; - } + { + int i; + if (!ahi_on) + return -2; + i = intcount; + intcount = 0; + return i; + } case 5: - if (!ahi_on) - return 0; - ahi_updatesound ( 1 ); - return 1; + if (!ahi_on) + return 0; + ahi_updatesound ( 1 ); + return 1; case 10: #if 1 - if (OpenClipboard (0)) { - clipdat = GetClipboardData (CF_UNICODETEXT); - if (clipdat) { - clipsize = _tcslen (clipdat); - clipsize++; - return clipsize; + if (OpenClipboard (0)) { + clipdat = GetClipboardData (CF_UNICODETEXT); + if (clipdat) { + clipsize = _tcslen (clipdat); + clipsize++; + return clipsize; + } } - } #endif - return 0; + return 0; case 11: - { + { #if 1 - put_byte (m68k_areg (regs, 0), 0); - if (clipdat) { - char *tmp = ua (clipdat); - int i; - for (i = 0; i < clipsize && i < strlen (tmp); i++) - put_byte (m68k_areg (regs, 0) + i, tmp[i]); - put_byte (m68k_areg (regs, 0) + clipsize - 1, 0); - xfree (tmp); - } - CloseClipboard (); + put_byte (m68k_areg (regs, 0), 0); + if (clipdat) { + char *tmp = ua (clipdat); + int i; + for (i = 0; i < clipsize && i < strlen (tmp); i++) + put_byte (m68k_areg (regs, 0) + i, tmp[i]); + put_byte (m68k_areg (regs, 0) + clipsize - 1, 0); + xfree (tmp); + } + CloseClipboard (); #endif - } - return 0; + } + return 0; case 12: - { + { #if 1 - TCHAR *s = au (get_real_address (m68k_areg (regs, 0))); - static LPTSTR p; - int slen; - - if (OpenClipboard (0)) { - EmptyClipboard(); - slen = _tcslen (s); - if (p) - GlobalFree (p); - p = GlobalAlloc (GMEM_MOVEABLE, (slen + 1) * sizeof (TCHAR)); - if (p) { - TCHAR *p2 = GlobalLock (p); - if (p2) { - _tcscpy (p2, s); - GlobalUnlock (p); - SetClipboardData (CF_UNICODETEXT, p); - } - } - CloseClipboard (); - } - xfree (s); + TCHAR *s = au (get_real_address (m68k_areg (regs, 0))); + static LPTSTR p; + int slen; + + if (OpenClipboard (0)) { + EmptyClipboard(); + slen = _tcslen (s); + if (p) + GlobalFree (p); + p = GlobalAlloc (GMEM_MOVEABLE, (slen + 1) * sizeof (TCHAR)); + if (p) { + TCHAR *p2 = GlobalLock (p); + if (p2) { + _tcscpy (p2, s); + GlobalUnlock (p); + SetClipboardData (CF_UNICODETEXT, p); + } + } + CloseClipboard (); + } + xfree (s); #endif - } - return 0; + } + return 0; case 13: /* HACK */ - { //for higher P96 mouse draw rate - extern int p96hack_vpos2, hack_vpos ,p96refresh_active; - extern uae_u16 vtotal; - extern unsigned int new_beamcon0; - p96hack_vpos2 = 0; - if (m68k_dreg (regs, 1) > 0) - p96hack_vpos2 = 15625 / m68k_dreg (regs, 1); - if (!currprefs.cs_ciaatod) - changed_prefs.cs_ciaatod = currprefs.cs_ciaatod = currprefs.ntscmode ? 2 : 1; - p96refresh_active=1; - picasso_refresh (); - } //end for higher P96 mouse draw rate - return 0; + { //for higher P96 mouse draw rate + extern int p96hack_vpos2, hack_vpos ,p96refresh_active; + extern uae_u16 vtotal; + extern unsigned int new_beamcon0; + p96hack_vpos2 = 0; + if (m68k_dreg (regs, 1) > 0) + p96hack_vpos2 = 15625 / m68k_dreg (regs, 1); + if (!currprefs.cs_ciaatod) + changed_prefs.cs_ciaatod = currprefs.cs_ciaatod = currprefs.ntscmode ? 2 : 1; + p96refresh_active=1; + picasso_refresh (); + } //end for higher P96 mouse draw rate + return 0; case 20: - return enforcer_enable(m68k_dreg (regs, 1)); + return enforcer_enable(m68k_dreg (regs, 1)); case 21: - return enforcer_disable(); + return enforcer_disable(); case 25: - flushprinter (); - return 0; + flushprinter (); + return 0; #if defined(X86_MSVC_ASSEMBLY) case 100: // open dll - { - TCHAR *dlldir = TEXT ("winuae_dll"); - TCHAR *dllname; - uaecptr dllptr; - HMODULE h = NULL; - TCHAR dpath[MAX_DPATH]; - TCHAR newdllpath[MAX_DPATH]; - int ok = 0; - TCHAR *filepart; - - dllptr = m68k_areg (regs, 0); - dllname = au ((uae_char*)get_real_address (dllptr)); - dpath[0] = 0; - GetFullPathName (dllname, sizeof dpath / sizeof (TCHAR), dpath, &filepart); - if (_tcslen (dpath) > _tcslen (start_path_data) && !_tcsncmp (dpath, start_path_data, _tcslen (start_path_data))) { - /* path really is relative to winuae directory */ - ok = 1; - _tcscpy (newdllpath, dpath + _tcslen (start_path_data)); - if (!_tcsncmp (newdllpath, dlldir, _tcslen (dlldir))) /* remove "winuae_dll" */ - _tcscpy (newdllpath, dpath + _tcslen (start_path_data) + 1 + _tcslen (dlldir)); - _stprintf (dpath, L"%s%s%s", start_path_data, WIN32_PLUGINDIR, newdllpath); - h = LoadLibrary (dpath); - if (h == NULL) - write_log (L"native open: '%s' = %d\n", dpath, GetLastError ()); - if (h == NULL) { - _stprintf (dpath, L"%s%s\\%s", start_path_data, dlldir, newdllpath); - h = LoadLibrary (dllname); - if (h == NULL) - write_log (L"fallback native open: '%s' = %d\n", dpath, GetLastError ()); - } - } else { - write_log (L"native open outside of installation dir '%s'!\n", dpath); - } - xfree (dllname); + { + TCHAR *dlldir = TEXT ("winuae_dll"); + TCHAR *dllname; + uaecptr dllptr; + HMODULE h = NULL; + TCHAR dpath[MAX_DPATH]; + TCHAR newdllpath[MAX_DPATH]; + int ok = 0; + TCHAR *filepart; + + dllptr = m68k_areg (regs, 0); + dllname = au ((uae_char*)get_real_address (dllptr)); + dpath[0] = 0; + GetFullPathName (dllname, sizeof dpath / sizeof (TCHAR), dpath, &filepart); + if (_tcslen (dpath) > _tcslen (start_path_data) && !_tcsncmp (dpath, start_path_data, _tcslen (start_path_data))) { + /* path really is relative to winuae directory */ + ok = 1; + _tcscpy (newdllpath, dpath + _tcslen (start_path_data)); + if (!_tcsncmp (newdllpath, dlldir, _tcslen (dlldir))) /* remove "winuae_dll" */ + _tcscpy (newdllpath, dpath + _tcslen (start_path_data) + 1 + _tcslen (dlldir)); + _stprintf (dpath, L"%s%s%s", start_path_data, WIN32_PLUGINDIR, newdllpath); + h = LoadLibrary (dpath); + if (h == NULL) + write_log (L"native open: '%s' = %d\n", dpath, GetLastError ()); + if (h == NULL) { + _stprintf (dpath, L"%s%s\\%s", start_path_data, dlldir, newdllpath); + h = LoadLibrary (dllname); + if (h == NULL) + write_log (L"fallback native open: '%s' = %d\n", dpath, GetLastError ()); + } + } else { + write_log (L"native open outside of installation dir '%s'!\n", dpath); + } + xfree (dllname); #if 0 - if (h == NULL) { - h = LoadLibrary (filepart); - write_log (L"native file open: '%s' = %p\n", filepart, h); - if (h == NULL) { - _stprintf (dpath, "%s%s%s", start_path_data, WIN32_PLUGINDIR, filepart); - h = LoadLibrary (dpath); - write_log (L"native path open: '%s' = %p\n", dpath, h); - } - } + if (h == NULL) { + h = LoadLibrary (filepart); + write_log (L"native file open: '%s' = %p\n", filepart, h); + if (h == NULL) { + _stprintf (dpath, "%s%s%s", start_path_data, WIN32_PLUGINDIR, filepart); + h = LoadLibrary (dpath); + write_log (L"native path open: '%s' = %p\n", dpath, h); + } + } #endif - syncdivisor = (3580000.0 * CYCLE_UNIT) / (double)syncbase; - return (uae_u32)h; - } + syncdivisor = (3580000.0 * CYCLE_UNIT) / (double)syncbase; + return (uae_u32)h; + } case 101: //get dll label - { - HMODULE m; - uaecptr funcaddr; - char *funcname; - m = (HMODULE) m68k_dreg (regs, 1); - funcaddr = m68k_areg (regs, 0); - funcname = get_real_address (funcaddr); - return (uae_u32) GetProcAddress (m, funcname); - } + { + HMODULE m; + uaecptr funcaddr; + char *funcname; + m = (HMODULE) m68k_dreg (regs, 1); + funcaddr = m68k_areg (regs, 0); + funcname = get_real_address (funcaddr); + return (uae_u32) GetProcAddress (m, funcname); + } case 102: //execute native code - { - uae_u32 ret; - unsigned long rate1; - double v; - rate1 = read_processor_time (); - ret = emulib_ExecuteNativeCode2 (context); - rate1 = read_processor_time () - rate1; - v = syncdivisor * rate1; - if (v > 0) { - if (v > 1000000 * CYCLE_UNIT) - v = 1000000 * CYCLE_UNIT; - do_extra_cycles ((unsigned long)(syncdivisor * rate1)); //compensate the time stay in native func - } - return ret; - } + { + uae_u32 ret; + unsigned long rate1; + double v; + rate1 = read_processor_time (); + ret = emulib_ExecuteNativeCode2 (context); + rate1 = read_processor_time () - rate1; + v = syncdivisor * rate1; + if (v > 0) { + if (v > 1000000 * CYCLE_UNIT) + v = 1000000 * CYCLE_UNIT; + do_extra_cycles ((unsigned long)(syncdivisor * rate1)); //compensate the time stay in native func + } + return ret; + } case 103: //close dll - { - HMODULE libaddr; - libaddr = (HMODULE) m68k_dreg (regs, 1); - FreeLibrary (libaddr); - return 0; - } + { + HMODULE libaddr; + libaddr = (HMODULE) m68k_dreg (regs, 1); + FreeLibrary (libaddr); + return 0; + } #endif case 104: //screenlost - { - static int oldnum = 0; - if (uaevar.changenum == oldnum) - return 0; - oldnum = uaevar.changenum; - return 1; - } + { + static int oldnum = 0; + if (uaevar.changenum == oldnum) + return 0; + oldnum = uaevar.changenum; + return 1; + } #if defined(X86_MSVC_ASSEMBLY) case 105: //returns memory offset - return (uae_u32) get_real_address (0); + return (uae_u32) get_real_address (0); case 106: //byteswap 16bit vars - //a0 = start address - //d1 = number of 16bit vars - //returns address of new array - src = m68k_areg (regs, 0); - num_vars = m68k_dreg (regs, 1); - - if (bswap_buffer_size < num_vars * 2) { - bswap_buffer_size = (num_vars + 1024) * 2; - free(bswap_buffer); - bswap_buffer = (void*)malloc(bswap_buffer_size); - } - __asm { - mov esi, dword ptr [src] - mov edi, dword ptr [bswap_buffer] - mov ecx, num_vars - - mov ebx, ecx - and ecx, 3 - je BSWAP_WORD_4X - - BSWAP_WORD_LOOP: - mov ax, [esi] - mov dl, al - mov al, ah - mov ah, dl - mov [edi], ax - add esi, 2 - add edi, 2 - loopne BSWAP_WORD_LOOP - - BSWAP_WORD_4X: - mov ecx, ebx - shr ecx, 2 - je BSWAP_WORD_END - BSWAP_WORD_4X_LOOP: - mov ax, [esi] - mov dl, al - mov al, ah - mov ah, dl - mov [edi], ax - mov ax, [esi+2] - mov dl, al - mov al, ah - mov ah, dl - mov [edi+2], ax - mov ax, [esi+4] - mov dl, al - mov al, ah - mov ah, dl - mov [edi+4], ax - mov ax, [esi+6] - mov dl, al - mov al, ah - mov ah, dl - mov [edi+6], ax - add esi, 8 - add edi, 8 - loopne BSWAP_WORD_4X_LOOP - BSWAP_WORD_END: - } - return (uae_u32) bswap_buffer; + //a0 = start address + //d1 = number of 16bit vars + //returns address of new array + src = m68k_areg (regs, 0); + num_vars = m68k_dreg (regs, 1); + + if (bswap_buffer_size < num_vars * 2) { + bswap_buffer_size = (num_vars + 1024) * 2; + free(bswap_buffer); + bswap_buffer = (void*)malloc(bswap_buffer_size); + } + __asm { + mov esi, dword ptr [src] + mov edi, dword ptr [bswap_buffer] + mov ecx, num_vars + + mov ebx, ecx + and ecx, 3 + je BSWAP_WORD_4X + +BSWAP_WORD_LOOP: + mov ax, [esi] + mov dl, al + mov al, ah + mov ah, dl + mov [edi], ax + add esi, 2 + add edi, 2 + loopne BSWAP_WORD_LOOP + +BSWAP_WORD_4X: + mov ecx, ebx + shr ecx, 2 + je BSWAP_WORD_END +BSWAP_WORD_4X_LOOP: + mov ax, [esi] + mov dl, al + mov al, ah + mov ah, dl + mov [edi], ax + mov ax, [esi+2] + mov dl, al + mov al, ah + mov ah, dl + mov [edi+2], ax + mov ax, [esi+4] + mov dl, al + mov al, ah + mov ah, dl + mov [edi+4], ax + mov ax, [esi+6] + mov dl, al + mov al, ah + mov ah, dl + mov [edi+6], ax + add esi, 8 + add edi, 8 + loopne BSWAP_WORD_4X_LOOP +BSWAP_WORD_END: + } + return (uae_u32) bswap_buffer; case 107: //byteswap 32bit vars - see case 106 - //a0 = start address - //d1 = number of 32bit vars - //returns address of new array - src = m68k_areg (regs, 0); - num_vars = m68k_dreg (regs, 1); - if (bswap_buffer_size < num_vars * 4) { - bswap_buffer_size = (num_vars + 16384) * 4; - free(bswap_buffer); - bswap_buffer = (void*)malloc(bswap_buffer_size); - } - __asm { - mov esi, dword ptr [src] - mov edi, dword ptr [bswap_buffer] - mov ecx, num_vars - - mov ebx, ecx - and ecx, 3 - je BSWAP_DWORD_4X - - BSWAP_DWORD_LOOP: - mov eax, [esi] - bswap eax - mov [edi], eax - add esi, 4 - add edi, 4 - loopne BSWAP_DWORD_LOOP - - BSWAP_DWORD_4X: - mov ecx, ebx - shr ecx, 2 - je BSWAP_DWORD_END - BSWAP_DWORD_4X_LOOP: - mov eax, [esi] - bswap eax - mov [edi], eax - mov eax, [esi+4] - bswap eax - mov [edi+4], eax - mov eax, [esi+8] - bswap eax - mov [edi+8], eax - mov eax, [esi+12] - bswap eax - mov [edi+12], eax - add esi, 16 - add edi, 16 - loopne BSWAP_DWORD_4X_LOOP - - BSWAP_DWORD_END: - } - return (uae_u32) bswap_buffer; + //a0 = start address + //d1 = number of 32bit vars + //returns address of new array + src = m68k_areg (regs, 0); + num_vars = m68k_dreg (regs, 1); + if (bswap_buffer_size < num_vars * 4) { + bswap_buffer_size = (num_vars + 16384) * 4; + free(bswap_buffer); + bswap_buffer = (void*)malloc(bswap_buffer_size); + } + __asm { + mov esi, dword ptr [src] + mov edi, dword ptr [bswap_buffer] + mov ecx, num_vars + + mov ebx, ecx + and ecx, 3 + je BSWAP_DWORD_4X + +BSWAP_DWORD_LOOP: + mov eax, [esi] + bswap eax + mov [edi], eax + add esi, 4 + add edi, 4 + loopne BSWAP_DWORD_LOOP + +BSWAP_DWORD_4X: + mov ecx, ebx + shr ecx, 2 + je BSWAP_DWORD_END +BSWAP_DWORD_4X_LOOP: + mov eax, [esi] + bswap eax + mov [edi], eax + mov eax, [esi+4] + bswap eax + mov [edi+4], eax + mov eax, [esi+8] + bswap eax + mov [edi+8], eax + mov eax, [esi+12] + bswap eax + mov [edi+12], eax + add esi, 16 + add edi, 16 + loopne BSWAP_DWORD_4X_LOOP + +BSWAP_DWORD_END: + } + return (uae_u32) bswap_buffer; case 108: //frees swap array - bswap_buffer_size = 0; - free (bswap_buffer); - bswap_buffer = NULL; - return 0; + bswap_buffer_size = 0; + free (bswap_buffer); + bswap_buffer = NULL; + return 0; case 110: - { - LARGE_INTEGER p; - QueryPerformanceFrequency (&p); - put_long (m68k_areg (regs, 0), p.HighPart); - put_long (m68k_areg (regs, 0) + 4, p.LowPart); - } - return 1; + { + LARGE_INTEGER p; + QueryPerformanceFrequency (&p); + put_long (m68k_areg (regs, 0), p.HighPart); + put_long (m68k_areg (regs, 0) + 4, p.LowPart); + } + return 1; case 111: - { - LARGE_INTEGER p; - QueryPerformanceCounter (&p); - put_long (m68k_areg (regs, 0), p.HighPart); - put_long (m68k_areg (regs, 0) + 4, p.LowPart); - } - return 1; + { + LARGE_INTEGER p; + QueryPerformanceCounter (&p); + put_long (m68k_areg (regs, 0), p.HighPart); + put_long (m68k_areg (regs, 0) + 4, p.LowPart); + } + return 1; #endif case 200: - ahitweak = m68k_dreg (regs, 1); - ahi_pollrate = m68k_dreg (regs, 2); - if (ahi_pollrate < 10) - ahi_pollrate = 10; - if (ahi_pollrate > 60) - ahi_pollrate = 60; - return 1; + ahitweak = m68k_dreg (regs, 1); + ahi_pollrate = m68k_dreg (regs, 2); + if (ahi_pollrate < 10) + ahi_pollrate = 10; + if (ahi_pollrate > 60) + ahi_pollrate = 60; + return 1; default: - return 0x12345678; // Code for not supportet function - } + return 0x12345678; // Code for not supportet function + } } #endif diff --git a/od-win32/ahidsound_new.c b/od-win32/ahidsound_new.c index 58ec0b1c..944092cf 100644 --- a/od-win32/ahidsound_new.c +++ b/od-win32/ahidsound_new.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * OpenAL AHI 7.1 "wrapper" - * - * Copyright 2008 Toni Wilen - */ +* UAE - The Un*x Amiga Emulator +* +* OpenAL AHI 7.1 "wrapper" +* +* Copyright 2008 Toni Wilen +*/ #include "sysconfig.h" @@ -156,7 +156,7 @@ struct AHIAudioCtrlDrv #define ahiac_PreTimerFunc ahiac_AntiClickSamples + 4 #define ahiac_PostTimerFunc ahiac_PreTimerFunc + 4 -/* AHIsub_AllocAudio return flags */ + /* AHIsub_AllocAudio return flags */ #define AHISF_ERROR (1<<0) #define AHISF_MIXING (1<<1) #define AHISF_TIMING (1<<2) @@ -175,14 +175,14 @@ struct AHIAudioCtrlDrv #define AHISB_CANPOSTPROCESS (6) #define AHISB_KNOWMULTICHANNEL (7) - /* AHIsub_Start() and AHIsub_Stop() flags */ + /* AHIsub_Start() and AHIsub_Stop() flags */ #define AHISF_PLAY (1<<0) #define AHISF_RECORD (1<<1) #define AHISB_PLAY (0) #define AHISB_RECORD (1) - /* ahiac_Flags */ + /* ahiac_Flags */ #define AHIACF_VOL (1<<0) #define AHIACF_PAN (1<<1) #define AHIACF_STEREO (1<<2) @@ -216,7 +216,7 @@ struct AHIAudioCtrlDrv #define AHI_TagBase (0x80000000) #define AHI_TagBaseR (AHI_TagBase|0x8000) - /* AHI_AllocAudioA tags */ + /* AHI_AllocAudioA tags */ #define AHIA_AudioID (AHI_TagBase+1) /* Desired audio mode */ #define AHIA_MixFreq (AHI_TagBase+2) /* Suggested mixing frequency */ #define AHIA_Channels (AHI_TagBase+3) /* Suggested number of channels */ @@ -230,13 +230,13 @@ struct AHIAudioCtrlDrv #define AHIA_UserData (AHI_TagBase+11) /* What to put in ahiac_UserData */ #define AHIA_AntiClickSamples (AHI_TagBase+13) /* # of samples to smooth (V6) */ -/* AHI_ControlAudioA tags */ + /* AHI_ControlAudioA tags */ #define AHIC_Play (AHI_TagBase+80) /* Boolean */ #define AHIC_Record (AHI_TagBase+81) /* Boolean */ #define AHIC_MonitorVolume (AHI_TagBase+82) #define AHIC_MonitorVolume_Query (AHI_TagBase+83) /* ti_Data is pointer to Fixed (LONG) */ #define AHIC_MixFreq_Query (AHI_TagBase+84) /* ti_Data is pointer to ULONG */ -/* --- New for V2, they will be ignored by V1 --- */ + /* --- New for V2, they will be ignored by V1 --- */ #define AHIC_InputGain (AHI_TagBase+85) #define AHIC_InputGain_Query (AHI_TagBase+86) /* ti_Data is pointer to Fixed (LONG) */ #define AHIC_OutputVolume (AHI_TagBase+87) @@ -246,7 +246,7 @@ struct AHIAudioCtrlDrv #define AHIC_Output (AHI_TagBase+91) #define AHIC_Output_Query (AHI_TagBase+92) /* ti_Data is pointer to ULONG */ - /* AHI_GetAudioAttrsA tags */ + /* AHI_GetAudioAttrsA tags */ #define AHIDB_AudioID (AHI_TagBase+100) #define AHIDB_Driver (AHI_TagBaseR+101) /* Pointer to name of driver */ #define AHIDB_Flags (AHI_TagBase+102) /* Private! */ @@ -276,7 +276,7 @@ struct AHIAudioCtrlDrv #define AHIDB_MaxPlaySamples (AHI_TagBase+126) /* It's sample *frames* */ #define AHIDB_MaxRecordSamples (AHI_TagBase+127) /* It's sample *frames* */ #define AHIDB_FullDuplex (AHI_TagBase+129) /* Boolean */ -/* --- New for V2, they will be ignored by V1 --- */ + /* --- New for V2, they will be ignored by V1 --- */ #define AHIDB_MinMonitorVolume (AHI_TagBase+130) #define AHIDB_MaxMonitorVolume (AHI_TagBase+131) #define AHIDB_MinInputGain (AHI_TagBase+132) @@ -289,23 +289,23 @@ struct AHIAudioCtrlDrv #define AHIDB_Outputs (AHI_TagBase+139) #define AHIDB_OutputArg (AHI_TagBase+140) /* ti_Data is input index */ #define AHIDB_Output (AHI_TagBase+141) -/* --- New for V4, they will be ignored by V2 and earlier --- */ + /* --- New for V4, they will be ignored by V2 and earlier --- */ #define AHIDB_Data (AHI_TagBaseR+142) /* Private! */ #define AHIDB_DriverBaseName (AHI_TagBaseR+143) /* Private! */ -/* --- New for V6, they will be ignored by V4 and earlier --- */ + /* --- New for V6, they will be ignored by V4 and earlier --- */ #define AHIDB_MultiChannel (AHI_TagBase+144) /* Boolean */ -/* Sound Types */ + /* Sound Types */ #define AHIST_NOTYPE (~0UL) /* Private */ #define AHIST_SAMPLE (0UL) /* 8 or 16 bit sample */ #define AHIST_DYNAMICSAMPLE (1UL) /* Dynamic sample */ #define AHIST_INPUT (1UL<<29) /* The input from your sampler */ #define AHIST_BW (1UL<<30) /* Private */ - /* Sample types */ -/* Note that only AHIST_M8S, AHIST_S8S, AHIST_M16S and AHIST_S16S - (plus AHIST_M32S, AHIST_S32S and AHIST_L7_1 in V6) - are supported by AHI_LoadSound(). */ + /* Sample types */ + /* Note that only AHIST_M8S, AHIST_S8S, AHIST_M16S and AHIST_S16S + (plus AHIST_M32S, AHIST_S32S and AHIST_L7_1 in V6) + are supported by AHI_LoadSound(). */ #define AHIST_M8S (0UL) /* Mono, 8 bit signed (BYTE) */ #define AHIST_M16S (1UL) /* Mono, 16 bit signed (WORD) */ #define AHIST_S8S (2UL) /* Stereo, 8 bit signed (2×BYTE) */ @@ -315,7 +315,7 @@ struct AHIAudioCtrlDrv #define AHIST_M8U (4UL) /* OBSOLETE! */ #define AHIST_L7_1 (0x00c3000aUL) /* 7.1, 32 bit signed (8×LONG) */ - /* Error codes */ + /* Error codes */ #define AHIE_OK (0UL) /* No error */ #define AHIE_NOMEM (1UL) /* Out of memory */ #define AHIE_BADSOUNDTYPE (2UL) /* Unknown sound type */ @@ -324,90 +324,90 @@ struct AHIAudioCtrlDrv #define AHIE_UNKNOWN (5UL) /* Error, but unknown */ #define AHIE_HALFDUPLEX (6UL) /* CMD_WRITE/CMD_READ failure */ -struct dssample { - int num; - int ch; - int bitspersample; - int bytespersample; - int dynamic; - uae_u32 addr; - uae_u32 len; - uae_u32 type; - uae_u32 sampletype; - ALuint al_buffer[2]; -}; - -struct chsample { - int frequency; - int volume; - int panning; - int backwards; - struct dssample *ds; - int srcplayoffset; - int srcplaylen; -}; - -struct dschannel { - int num; - struct chsample cs; - struct chsample csnext; - int channelsignal; - int dsplaying; - ALuint al_source; - int samplecounter; - int buffertoggle; - int maxplaysamples; - int totalsamples; - int waitforack; -}; - -struct DSAHI { - uae_u32 audioctrl; - int chout; - int bits24; - int bitspersampleout; - int bytespersampleout; - int channellength; - int mixlength; - int input; - int output; - int channels; - int sounds; - int playerfreq; - uae_u32 audioid; - int enabledisable; - struct dssample *sample; - struct dschannel *channel; - int playing, recording; - evt evttime; - uae_u32 signalchannelmask; - - ALCdevice *al_dev, *al_recorddev; - ALCcontext *al_ctx; - int al_bufferformat; - uae_u8 *tmpbuffer; - int tmpbuffer_size; - int dsrecording; - int record_samples; - int record_ch; - int record_bytespersample; - int record_wait; - int maxplaysamples; -}; - -static struct DSAHI dsahi[1]; + struct dssample { + int num; + int ch; + int bitspersample; + int bytespersample; + int dynamic; + uae_u32 addr; + uae_u32 len; + uae_u32 type; + uae_u32 sampletype; + ALuint al_buffer[2]; + }; + + struct chsample { + int frequency; + int volume; + int panning; + int backwards; + struct dssample *ds; + int srcplayoffset; + int srcplaylen; + }; + + struct dschannel { + int num; + struct chsample cs; + struct chsample csnext; + int channelsignal; + int dsplaying; + ALuint al_source; + int samplecounter; + int buffertoggle; + int maxplaysamples; + int totalsamples; + int waitforack; + }; + + struct DSAHI { + uae_u32 audioctrl; + int chout; + int bits24; + int bitspersampleout; + int bytespersampleout; + int channellength; + int mixlength; + int input; + int output; + int channels; + int sounds; + int playerfreq; + uae_u32 audioid; + int enabledisable; + struct dssample *sample; + struct dschannel *channel; + int playing, recording; + evt evttime; + uae_u32 signalchannelmask; + + ALCdevice *al_dev, *al_recorddev; + ALCcontext *al_ctx; + int al_bufferformat; + uae_u8 *tmpbuffer; + int tmpbuffer_size; + int dsrecording; + int record_samples; + int record_ch; + int record_bytespersample; + int record_wait; + int maxplaysamples; + }; + + static struct DSAHI dsahi[1]; #define GETAHI (&dsahi[get_long(get_long(audioctrl + ahiac_DriverData) + pub_Index)]) #define GETSAMPLE (dsahip && sound >= 0 && sound < UAE_MAXSOUNDS ? &dsahip->sample[sound] : NULL) #define GETCHANNEL (dsahip && channel >= 0 && channel < UAE_MAXCHANNELS ? &dsahip->channel[channel] : NULL) -static int default_freq = 44100; -static int cansurround; -static uae_u32 xahi_author, xahi_copyright, xahi_version; -static uae_u32 xahi_output[MAX_SOUND_DEVICES], xahi_output_num; -static uae_u32 xahi_input[MAX_SOUND_DEVICES], xahi_input_num; -static int ahi_paused; -static int ahi_active; + static int default_freq = 44100; + static int cansurround; + static uae_u32 xahi_author, xahi_copyright, xahi_version; + static uae_u32 xahi_output[MAX_SOUND_DEVICES], xahi_output_num; + static uae_u32 xahi_input[MAX_SOUND_DEVICES], xahi_input_num; + static int ahi_paused; + static int ahi_active; #define TAG_DONE (0L) /* terminates array of TagItems. ti_Data unused */ #define TAG_IGNORE (1L) /* ignore this item, not end of array */ @@ -415,1524 +415,1524 @@ static int ahi_active; #define TAG_SKIP (3L) /* skip this and the next ti_Data items */ #define TAG_USER ((uae_u32)(1L << 31)) -static uae_u32 gettag (uae_u32 *tagpp, uae_u32 *datap) -{ - uae_u32 tagp = *tagpp; - for (;;) { - uae_u32 tag = get_long (tagp); - uae_u32 data = get_long (tagp + 4); - switch (tag) + static uae_u32 gettag (uae_u32 *tagpp, uae_u32 *datap) { - case TAG_DONE: - return 0; - case TAG_IGNORE: - tagp += 8; - break; - case TAG_MORE: - tagp = data; - break; - case TAG_SKIP: - tagp += data * 8; - break; - default: - tagp += 8; - *tagpp = tagp; - *datap = data; - return tag; + uae_u32 tagp = *tagpp; + for (;;) { + uae_u32 tag = get_long (tagp); + uae_u32 data = get_long (tagp + 4); + switch (tag) + { + case TAG_DONE: + return 0; + case TAG_IGNORE: + tagp += 8; + break; + case TAG_MORE: + tagp = data; + break; + case TAG_SKIP: + tagp += data * 8; + break; + default: + tagp += 8; + *tagpp = tagp; + *datap = data; + return tag; + } + } } - } -} -static int sendsignal (struct DSAHI *dsahip) -{ - uae_u32 audioctrl = dsahip->audioctrl; - uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); - uae_u32 channelinfo; - uae_u32 task, signalmask; - uae_s16 taskmode = get_word (puaebase + pub_TaskMode); - uae_s16 funcmode = get_word (puaebase + pub_FuncMode); - task = get_long (puaebase + pub_FuncTask); - signalmask = get_long (puaebase + pub_WaitMask); - - if ((!dsahip->playing && !dsahip->recording) || ahi_paused) - return 0; - if (taskmode <= 0) - return 0; - if (dsahip->enabledisable) { - // allocate Amiga-side recordingbuffer - funcmode &= FUNCMODE_RECORDALLOC; - put_word (puaebase + pub_FuncMode, funcmode); - } - - channelinfo = get_long (puaebase + pub_ChannelInfo); - if (channelinfo) { - int i, ch; - ch = get_word (channelinfo + ahieci_Channels); - if (ch > UAE_MAXCHANNELS) - ch = UAE_MAXCHANNELS; - for (i = 0; i < ch; i++) { - struct dschannel *dc = &dsahip->channel[i]; - int v; - alGetSourcei (dc->al_source, AL_SAMPLE_OFFSET, &v); - put_long (channelinfo + ahieci_Offset + i * 4, v + dc->samplecounter * dc->maxplaysamples); + static int sendsignal (struct DSAHI *dsahip) + { + uae_u32 audioctrl = dsahip->audioctrl; + uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); + uae_u32 channelinfo; + uae_u32 task, signalmask; + uae_s16 taskmode = get_word (puaebase + pub_TaskMode); + uae_s16 funcmode = get_word (puaebase + pub_FuncMode); + task = get_long (puaebase + pub_FuncTask); + signalmask = get_long (puaebase + pub_WaitMask); + + if ((!dsahip->playing && !dsahip->recording) || ahi_paused) + return 0; + if (taskmode <= 0) + return 0; + if (dsahip->enabledisable) { + // allocate Amiga-side recordingbuffer + funcmode &= FUNCMODE_RECORDALLOC; + put_word (puaebase + pub_FuncMode, funcmode); + } + + channelinfo = get_long (puaebase + pub_ChannelInfo); + if (channelinfo) { + int i, ch; + ch = get_word (channelinfo + ahieci_Channels); + if (ch > UAE_MAXCHANNELS) + ch = UAE_MAXCHANNELS; + for (i = 0; i < ch; i++) { + struct dschannel *dc = &dsahip->channel[i]; + int v; + alGetSourcei (dc->al_source, AL_SAMPLE_OFFSET, &v); + put_long (channelinfo + ahieci_Offset + i * 4, v + dc->samplecounter * dc->maxplaysamples); + } + } + + uae_Signal (task, signalmask); + return 1; } - } - uae_Signal (task, signalmask); - return 1; -} + static int setchannelevent (struct DSAHI *dsahip, struct dschannel *dc) + { + uae_u32 audioctrl = dsahip->audioctrl; + uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); + int ch = dc - &dsahip->channel[0]; + uae_u32 mask; + + if (!dsahip->playing || ahi_paused || !dc->al_source || !get_long (audioctrl + ahiac_SoundFunc)) + return 0; + mask = get_long (puaebase + pub_ChannelSignal); + if (mask & (1 << ch)) + return 0; + dc->channelsignal = 1; + put_long (puaebase + pub_ChannelSignal, mask | (1 << ch)); + sendsignal (dsahip); + return 1; + } -static int setchannelevent (struct DSAHI *dsahip, struct dschannel *dc) -{ - uae_u32 audioctrl = dsahip->audioctrl; - uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); - int ch = dc - &dsahip->channel[0]; - uae_u32 mask; - - if (!dsahip->playing || ahi_paused || !dc->al_source || !get_long (audioctrl + ahiac_SoundFunc)) - return 0; - mask = get_long (puaebase + pub_ChannelSignal); - if (mask & (1 << ch)) - return 0; - dc->channelsignal = 1; - put_long (puaebase + pub_ChannelSignal, mask | (1 << ch)); - sendsignal (dsahip); - return 1; -} - -static void evtfunc (uae_u32 v) -{ - if (ahi_active) { - struct DSAHI *dsahip = &dsahi[v]; - uae_u32 audioctrl = dsahip->audioctrl; - uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); - - put_word (puaebase + pub_FuncMode, get_word (puaebase + pub_FuncMode) | FUNCMODE_PLAY); - if (sendsignal (dsahip)) { - event2_newevent2 (dsahip->evttime, v, evtfunc); - } else { - dsahip->evttime = 0; + static void evtfunc (uae_u32 v) + { + if (ahi_active) { + struct DSAHI *dsahip = &dsahi[v]; + uae_u32 audioctrl = dsahip->audioctrl; + uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); + + put_word (puaebase + pub_FuncMode, get_word (puaebase + pub_FuncMode) | FUNCMODE_PLAY); + if (sendsignal (dsahip)) { + event2_newevent2 (dsahip->evttime, v, evtfunc); + } else { + dsahip->evttime = 0; + } + } } - } -} -static void setevent (struct DSAHI *dsahip) -{ - uae_u32 audioctrl = dsahip->audioctrl; - uae_u32 freq = get_long (audioctrl + ahiac_PlayerFreq); - double f; - uae_u32 cycles; - evt t; - - f = ((double)(freq >> 16)) + ((double)(freq & 0xffff)) / 65536.0; - if (f < 1) - return; - cycles = maxhpos * maxvpos * vblank_hz; - t = (evt)(cycles / f); - if (dsahip->evttime == t) - return; - write_log (L"AHI: playerfunc freq = %.2fHz\n", f); - dsahip->evttime = t; - if (t < 10) - return; - event2_newevent2 (t, dsahip - &dsahi[0], evtfunc); -} - -static void alClear (void) -{ - alGetError (); -} -static int alError (const TCHAR *format,...) -{ - TCHAR buffer[1000]; - va_list parms; - int err; - - err = alGetError (); - if (err == AL_NO_ERROR) - return 0; - va_start (parms, format); - _vsntprintf (buffer, sizeof buffer -1, format, parms); - _stprintf (buffer + _tcslen (buffer), L": ERR=%x\n", err); - write_log (L"%s", buffer); - return err; -} - -static void ds_freechannel (struct DSAHI *ahidsp, struct dschannel *dc) -{ - if (!dc) - return; - alDeleteSources (1, &dc->al_source); - memset (dc, 0, sizeof (struct dschannel)); - dc->al_source = -1; -} - -static void ds_freesample (struct DSAHI *ahidsp, struct dssample *ds) -{ - if (!ds) - return; - alDeleteBuffers (2, ds->al_buffer); - memset (ds, 0, sizeof (struct dssample)); - ds->al_buffer[0] = -1; - ds->al_buffer[1] = -1; -} - -static void ds_free (struct DSAHI *dsahip) -{ - int i; - - if (!ahi_active) - return; - for (i = 0; i < dsahip->channels; i++) { - struct dschannel *dc = &dsahip->channel[i]; - ds_freechannel (dsahip, dc); - } - for (i = 0; i < dsahip->sounds; i++) { - struct dssample *ds = &dsahip->sample[i]; - ds_freesample (dsahip, ds); - } - alcMakeContextCurrent (NULL); - alcDestroyContext (dsahip->al_ctx); - dsahip->al_ctx = 0; - alcCloseDevice (dsahip->al_dev); - dsahip->al_dev = 0; - if (ahi_debug && ahi_active) - write_log (L"AHI: OpenAL freed\n"); - ahi_active = 0; -} - -static void ds_free_record (struct DSAHI *dsahip) -{ - if (dsahip->al_recorddev) - alcCaptureCloseDevice (dsahip->al_recorddev); - dsahip->al_recorddev = NULL; -} + static void setevent (struct DSAHI *dsahip) + { + uae_u32 audioctrl = dsahip->audioctrl; + uae_u32 freq = get_long (audioctrl + ahiac_PlayerFreq); + double f; + uae_u32 cycles; + evt t; + + f = ((double)(freq >> 16)) + ((double)(freq & 0xffff)) / 65536.0; + if (f < 1) + return; + cycles = maxhpos * maxvpos * vblank_hz; + t = (evt)(cycles / f); + if (dsahip->evttime == t) + return; + write_log (L"AHI: playerfunc freq = %.2fHz\n", f); + dsahip->evttime = t; + if (t < 10) + return; + event2_newevent2 (t, dsahip - &dsahi[0], evtfunc); + } -static int ds_init_record (struct DSAHI *dsahip) -{ - uae_u32 pbase = get_long (dsahip->audioctrl + ahiac_DriverData); - int freq = get_long (dsahip->audioctrl + ahiac_MixFreq); - struct sound_device *sd; - int device; - char *s; - - if (!freq) - return 0; - device = dsahip->input; - sd = record_devices; - for (;;) { - if (sd->type == SOUND_DEVICE_AL) { - if (device <= 0) - break; - device--; + static void alClear (void) + { + alGetError (); + } + static int alError (const TCHAR *format,...) + { + TCHAR buffer[1000]; + va_list parms; + int err; + + err = alGetError (); + if (err == AL_NO_ERROR) + return 0; + va_start (parms, format); + _vsntprintf (buffer, sizeof buffer -1, format, parms); + _stprintf (buffer + _tcslen (buffer), L": ERR=%x\n", err); + write_log (L"%s", buffer); + return err; } - sd++; - if (sd->name == NULL) - return 0; - } - dsahip->record_samples = UAE_RECORDSAMPLES; - dsahip->record_ch = 2; - dsahip->record_bytespersample = 2; - alClear (); - s = ua (sd->alname); - dsahip->al_recorddev = alcCaptureOpenDevice (s, freq, AL_FORMAT_STEREO16, dsahip->record_samples); - xfree (s); - if (dsahip->al_recorddev == NULL) - goto error; - return 1; -error: - if (ahi_debug) - write_log (L"AHI: OPENAL recording initialization failed\n"); - return 0; -} -static int ds_init (struct DSAHI *dsahip) -{ - int freq = 44100; - int v; - struct sound_device *sd; - int device; - char *s; - - device = dsahip->output; - sd = sound_devices; - for (;;) { - if (sd->type == SOUND_DEVICE_AL) { - if (device <= 0) - break; - device--; + static void ds_freechannel (struct DSAHI *ahidsp, struct dschannel *dc) + { + if (!dc) + return; + alDeleteSources (1, &dc->al_source); + memset (dc, 0, sizeof (struct dschannel)); + dc->al_source = -1; + } + + static void ds_freesample (struct DSAHI *ahidsp, struct dssample *ds) + { + if (!ds) + return; + alDeleteBuffers (2, ds->al_buffer); + memset (ds, 0, sizeof (struct dssample)); + ds->al_buffer[0] = -1; + ds->al_buffer[1] = -1; } - sd++; - if (sd->name == NULL) - return 0; - } - s = ua (sd->alname); - dsahip->al_dev = alcOpenDevice (s); - xfree (s); - if (!dsahip->al_dev) - goto error; - dsahip->al_ctx = alcCreateContext (dsahip->al_dev, NULL); - if (!dsahip->al_ctx) - goto error; - alcMakeContextCurrent (dsahip->al_ctx); - - dsahip->chout = 2; - dsahip->al_bufferformat = AL_FORMAT_STEREO16; - cansurround = 0; - if ((dsahip->audioid & 0xff) == 2) { - if (v = alGetEnumValue ("AL_FORMAT_QUAD16")) { - dsahip->chout = 4; - cansurround = 1; - dsahip->al_bufferformat = v; + + static void ds_free (struct DSAHI *dsahip) + { + int i; + + if (!ahi_active) + return; + for (i = 0; i < dsahip->channels; i++) { + struct dschannel *dc = &dsahip->channel[i]; + ds_freechannel (dsahip, dc); + } + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + ds_freesample (dsahip, ds); + } + alcMakeContextCurrent (NULL); + alcDestroyContext (dsahip->al_ctx); + dsahip->al_ctx = 0; + alcCloseDevice (dsahip->al_dev); + dsahip->al_dev = 0; + if (ahi_debug && ahi_active) + write_log (L"AHI: OpenAL freed\n"); + ahi_active = 0; } - if (v = alGetEnumValue ("AL_FORMAT_51CHN16")) { - dsahip->chout = 6; - cansurround = 1; - dsahip->al_bufferformat = v; + + static void ds_free_record (struct DSAHI *dsahip) + { + if (dsahip->al_recorddev) + alcCaptureCloseDevice (dsahip->al_recorddev); + dsahip->al_recorddev = NULL; } - } - dsahip->bitspersampleout = dsahip->bits24 ? 24 : 16; - dsahip->bytespersampleout = dsahip->bitspersampleout / 8; - dsahip->channellength = 65536 * dsahip->chout * dsahip->bytespersampleout; - if (ahi_debug) - write_log (L"AHI: CH=%d BLEN=%d\n", - dsahip->chout, dsahip->channellength); - - dsahip->tmpbuffer_size = 1000000; - dsahip->tmpbuffer = xmalloc (dsahip->tmpbuffer_size); - if (ahi_debug) - write_log (L"AHI: OpenAL initialized: %s\n", sound_devices[dsahip->output].name); - - return 1; + + static int ds_init_record (struct DSAHI *dsahip) + { + uae_u32 pbase = get_long (dsahip->audioctrl + ahiac_DriverData); + int freq = get_long (dsahip->audioctrl + ahiac_MixFreq); + struct sound_device *sd; + int device; + char *s; + + if (!freq) + return 0; + device = dsahip->input; + sd = record_devices; + for (;;) { + if (sd->type == SOUND_DEVICE_AL) { + if (device <= 0) + break; + device--; + } + sd++; + if (sd->name == NULL) + return 0; + } + dsahip->record_samples = UAE_RECORDSAMPLES; + dsahip->record_ch = 2; + dsahip->record_bytespersample = 2; + alClear (); + s = ua (sd->alname); + dsahip->al_recorddev = alcCaptureOpenDevice (s, freq, AL_FORMAT_STEREO16, dsahip->record_samples); + xfree (s); + if (dsahip->al_recorddev == NULL) + goto error; + return 1; error: - if (ahi_debug) - write_log (L"AHI: OpenAL initialization failed\n"); - ds_free (dsahip); - return 0; -} + if (ahi_debug) + write_log (L"AHI: OPENAL recording initialization failed\n"); + return 0; + } -static int ds_reinit (struct DSAHI *dsahip) -{ - ds_free (dsahip); - return ds_init (dsahip); -} + static int ds_init (struct DSAHI *dsahip) + { + int freq = 44100; + int v; + struct sound_device *sd; + int device; + char *s; + + device = dsahip->output; + sd = sound_devices; + for (;;) { + if (sd->type == SOUND_DEVICE_AL) { + if (device <= 0) + break; + device--; + } + sd++; + if (sd->name == NULL) + return 0; + } + s = ua (sd->alname); + dsahip->al_dev = alcOpenDevice (s); + xfree (s); + if (!dsahip->al_dev) + goto error; + dsahip->al_ctx = alcCreateContext (dsahip->al_dev, NULL); + if (!dsahip->al_ctx) + goto error; + alcMakeContextCurrent (dsahip->al_ctx); + + dsahip->chout = 2; + dsahip->al_bufferformat = AL_FORMAT_STEREO16; + cansurround = 0; + if ((dsahip->audioid & 0xff) == 2) { + if (v = alGetEnumValue ("AL_FORMAT_QUAD16")) { + dsahip->chout = 4; + cansurround = 1; + dsahip->al_bufferformat = v; + } + if (v = alGetEnumValue ("AL_FORMAT_51CHN16")) { + dsahip->chout = 6; + cansurround = 1; + dsahip->al_bufferformat = v; + } + } + dsahip->bitspersampleout = dsahip->bits24 ? 24 : 16; + dsahip->bytespersampleout = dsahip->bitspersampleout / 8; + dsahip->channellength = 65536 * dsahip->chout * dsahip->bytespersampleout; + if (ahi_debug) + write_log (L"AHI: CH=%d BLEN=%d\n", + dsahip->chout, dsahip->channellength); -static void ds_setvolume (struct DSAHI *dsahip, struct dschannel *dc) -{ - if (dc->al_source != -1) { - if (abs (dc->cs.volume) != abs (dc->csnext.volume)) { - float vol = ((float)(abs (dc->csnext.volume))) / 65536.0; - alClear (); - alSourcef (dc->al_source, AL_GAIN, vol); - alError (L"AHI: SetVolume(%d,%d)", dc->num, vol); + dsahip->tmpbuffer_size = 1000000; + dsahip->tmpbuffer = xmalloc (dsahip->tmpbuffer_size); + if (ahi_debug) + write_log (L"AHI: OpenAL initialized: %s\n", sound_devices[dsahip->output].name); + + return 1; +error: + if (ahi_debug) + write_log (L"AHI: OpenAL initialization failed\n"); + ds_free (dsahip); + return 0; } - if (abs (dc->cs.panning) != abs (dc->csnext.panning)) { -;// pan = (abs (dc->csnext.panning) - 0x8000) * DSBPAN_RIGHT / 32768; + + static int ds_reinit (struct DSAHI *dsahip) + { + ds_free (dsahip); + return ds_init (dsahip); } - } - dc->cs.volume = dc->csnext.volume; - dc->cs.panning = dc->csnext.panning; -} -static void ds_setfreq (struct DSAHI *dsahip, struct dschannel *dc) -{ - if (dc->dsplaying && dc->cs.frequency != dc->csnext.frequency && dc->csnext.frequency > 0 && dc->al_source != -1) { - //alClear (); - //alSourcei (dc->al_source, AL_FREQUENCY, dc->csnext.frequency); - //alError (L"AHI: SetFrequency(%d,%d)", dc->num, dc->csnext.frequency); - } - dc->cs.frequency = dc->csnext.frequency; -} - -static int ds_allocchannel (struct DSAHI *dsahip, struct dschannel *dc) -{ - if (dc->al_source != -1) - return 1; - alClear (); - alGenSources (1, &dc->al_source); - if (alError (L"alGenSources()")) - goto error; - dc->cs.frequency = -1; - dc->cs.volume = -1; - dc->cs.panning = -1; - ds_setvolume (dsahip, dc); - ds_setfreq (dsahip, dc); - if (ahi_debug) - write_log (L"AHI: allocated OpenAL source for channel %d. vol=%d pan=%d freq=%d\n", - dc->num, dc->cs.volume, dc->cs.panning, dc->cs.frequency); - return 1; + static void ds_setvolume (struct DSAHI *dsahip, struct dschannel *dc) + { + if (dc->al_source != -1) { + if (abs (dc->cs.volume) != abs (dc->csnext.volume)) { + float vol = ((float)(abs (dc->csnext.volume))) / 65536.0; + alClear (); + alSourcef (dc->al_source, AL_GAIN, vol); + alError (L"AHI: SetVolume(%d,%d)", dc->num, vol); + } + if (abs (dc->cs.panning) != abs (dc->csnext.panning)) { + ;// pan = (abs (dc->csnext.panning) - 0x8000) * DSBPAN_RIGHT / 32768; + } + } + dc->cs.volume = dc->csnext.volume; + dc->cs.panning = dc->csnext.panning; + } + + static void ds_setfreq (struct DSAHI *dsahip, struct dschannel *dc) + { + if (dc->dsplaying && dc->cs.frequency != dc->csnext.frequency && dc->csnext.frequency > 0 && dc->al_source != -1) { + //alClear (); + //alSourcei (dc->al_source, AL_FREQUENCY, dc->csnext.frequency); + //alError (L"AHI: SetFrequency(%d,%d)", dc->num, dc->csnext.frequency); + } + dc->cs.frequency = dc->csnext.frequency; + } + + static int ds_allocchannel (struct DSAHI *dsahip, struct dschannel *dc) + { + if (dc->al_source != -1) + return 1; + alClear (); + alGenSources (1, &dc->al_source); + if (alError (L"alGenSources()")) + goto error; + dc->cs.frequency = -1; + dc->cs.volume = -1; + dc->cs.panning = -1; + ds_setvolume (dsahip, dc); + ds_setfreq (dsahip, dc); + if (ahi_debug) + write_log (L"AHI: allocated OpenAL source for channel %d. vol=%d pan=%d freq=%d\n", + dc->num, dc->cs.volume, dc->cs.panning, dc->cs.frequency); + return 1; error: - ds_freechannel (dsahip, dc); - return 0; -} + ds_freechannel (dsahip, dc); + return 0; + } #define MAKEXCH makexch (dsahip, dc, dst, i, och2, l, r) -STATIC_INLINE void makexch (struct DSAHI *dsahip, struct dschannel *dc, uae_u8 *dst, int idx, int och2, uae_s32 l, uae_s32 r) -{ - if (dsahip->bits24) { - } else { - uae_s16 *dst2 = (uae_u16*)(&dst[idx * och2]); - l >>= 8; - r >>= 8; - if (dc->cs.volume < 0) { - l = -l; - r = -r; + STATIC_INLINE void makexch (struct DSAHI *dsahip, struct dschannel *dc, uae_u8 *dst, int idx, int och2, uae_s32 l, uae_s32 r) + { + if (dsahip->bits24) { + } else { + uae_s16 *dst2 = (uae_u16*)(&dst[idx * och2]); + l >>= 8; + r >>= 8; + if (dc->cs.volume < 0) { + l = -l; + r = -r; + } + dst2[0] = l; + dst2[1] = r; + if (dsahip->chout <= 2) + return; + dst2[4] = dst2[0]; + dst2[5] = dst2[1]; + if (dc->cs.panning < 0) { + // surround only + dst2[2] = 0; // center + dst2[3] = (dst2[0] + dst2[1]) / 4; // lfe + dst2[0] = dst2[1] = 0; + return; + } + dst2[2] = dst2[3] = (dst2[0] + dst2[1]) / 4; + if (dsahip->chout <= 6) + return; + dst2[6] = dst2[4]; + dst2[7] = dst2[5]; + } } - dst2[0] = l; - dst2[1] = r; - if (dsahip->chout <= 2) - return; - dst2[4] = dst2[0]; - dst2[5] = dst2[1]; - if (dc->cs.panning < 0) { - // surround only - dst2[2] = 0; // center - dst2[3] = (dst2[0] + dst2[1]) / 4; // lfe - dst2[0] = dst2[1] = 0; - return; + + /* sample conversion routines */ + static int copysampledata (struct DSAHI *dsahip, struct dschannel *dc, struct dssample *ds, uae_u8 **psrcp, uae_u8 *srce, uae_u8 *srcp, void *dstp, int dstlen) + { + int i; + uae_u8 *src = *psrcp; + uae_u8 *dst = (uae_u8*)dstp; + int och = dsahip->chout; + int och2 = och * 2; + int ich = ds->ch; + int len; + + len = dstlen; + switch (ds->sampletype) + { + case AHIST_M8S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[0] << 16) | (src[0] << 8) | src[0] ; + uae_u32 r = (src[0] << 16) | (src[0] << 8) | src[0]; + src += 1; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_S8S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[0] << 16) | (src[0] << 8) | src[0] ; + uae_u32 r = (src[1] << 16) | (src[1] << 8) | src[1]; + src += 2; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_M16S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[0] << 16) | (src[1] << 8) | src[1]; + uae_u32 r = (src[0] << 16) | (src[1] << 8) | src[1]; + src += 2; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_S16S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[0] << 16) | (src[1] << 8) | src[1]; + uae_u32 r = (src[2] << 16) | (src[3] << 8) | src[3]; + src += 4; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_M32S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[3] << 16) | (src[2] << 8) | src[1]; + uae_u32 r = (src[3] << 16) | (src[2] << 8) | src[1]; + src += 4; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_S32S: + for (i = 0; i < len; i++) { + uae_u32 l = (src[3] << 16) | (src[2] << 8) | src[1]; + uae_u32 r = (src[7] << 16) | (src[6] << 8) | src[5]; + src += 8; + if (src >= srce) + src = srcp; + MAKEXCH; + } + break; + case AHIST_L7_1: + if (och == 8) { + for (i = 0; i < len; i++) { + if (dsahip->bits24) { + uae_u32 fl = (src[0 * 4 + 3] << 16) | (src[0 * 4 + 2] << 8) | src[0 * 4 + 1]; + uae_u32 fr = (src[1 * 4 + 3] << 16) | (src[1 * 4 + 2] << 8) | src[1 * 4 + 1]; + uae_u32 cc = (src[6 * 4 + 3] << 16) | (src[6 * 4 + 2] << 8) | src[6 * 4 + 1]; + uae_u32 lf = (src[7 * 4 + 3] << 16) | (src[7 * 4 + 2] << 8) | src[7 * 4 + 1]; + uae_u32 bl = (src[2 * 4 + 3] << 16) | (src[2 * 4 + 2] << 8) | src[2 * 4 + 1]; + uae_u32 br = (src[3 * 4 + 3] << 16) | (src[3 * 4 + 2] << 8) | src[3 * 4 + 1]; + uae_u32 sl = (src[4 * 4 + 3] << 16) | (src[4 * 4 + 2] << 8) | src[4 * 4 + 1]; + uae_u32 sr = (src[5 * 4 + 3] << 16) | (src[5 * 4 + 2] << 8) | src[5 * 4 + 1]; + uae_s32 *dst2 = (uae_s32*)(&dst[i * och2]); + dst2[0] = fl; + dst2[1] = fr; + dst2[2] = cc; + dst2[3] = lf; + dst2[4] = bl; + dst2[5] = br; + dst2[6] = sl; + dst2[7] = sr; + } else { + uae_u16 fl = (src[0 * 4 + 3] << 8) | src[0 * 4 + 2]; + uae_u16 fr = (src[1 * 4 + 3] << 8) | src[1 * 4 + 2]; + uae_u16 cc = (src[6 * 4 + 3] << 8) | src[6 * 4 + 2]; + uae_u16 lf = (src[7 * 4 + 3] << 8) | src[7 * 4 + 2]; + uae_u16 bl = (src[2 * 4 + 3] << 8) | src[2 * 4 + 2]; + uae_u16 br = (src[3 * 4 + 3] << 8) | src[3 * 4 + 2]; + uae_u16 sl = (src[4 * 4 + 3] << 8) | src[4 * 4 + 2]; + uae_u16 sr = (src[5 * 4 + 3] << 8) | src[5 * 4 + 2]; + uae_s16 *dst2 = (uae_s16*)(&dst[i * och2]); + dst2[0] = fl; + dst2[1] = fr; + dst2[2] = cc; + dst2[3] = lf; + dst2[4] = bl; + dst2[5] = br; + dst2[6] = sl; + dst2[7] = sr; + } + dst += och2; + src += 8 * 4; + if (src >= srce) + src = srcp; + } + } else if (och == 6) { /* 7.1 -> 5.1 */ + for (i = 0; i < len; i++) { + if (dsahip->bits24) { + uae_s32 *dst2 = (uae_s32*)(&dst[i * och2]); + uae_u32 fl = (src[0 * 4 + 3] << 16) | (src[0 * 4 + 2] << 8) | src[0 * 4 + 1]; + uae_u32 fr = (src[1 * 4 + 3] << 16) | (src[1 * 4 + 2] << 8) | src[1 * 4 + 1]; + uae_u32 cc = (src[6 * 4 + 3] << 16) | (src[6 * 4 + 2] << 8) | src[6 * 4 + 1]; + uae_u32 lf = (src[7 * 4 + 3] << 16) | (src[7 * 4 + 2] << 8) | src[7 * 4 + 1]; + uae_u32 bl = (src[2 * 4 + 3] << 16) | (src[2 * 4 + 2] << 8) | src[2 * 4 + 1]; + uae_u32 br = (src[3 * 4 + 3] << 16) | (src[3 * 4 + 2] << 8) | src[3 * 4 + 1]; + uae_u32 sl = (src[4 * 4 + 3] << 16) | (src[4 * 4 + 2] << 8) | src[4 * 4 + 1]; + uae_u32 sr = (src[5 * 4 + 3] << 16) | (src[5 * 4 + 2] << 8) | src[5 * 4 + 1]; + } else { + uae_s16 *dst2 = (uae_s16*)(&dst[i * och2]); + uae_u16 fl = (src[0 * 4 + 3] << 8) | src[0 * 4 + 2]; + uae_u16 fr = (src[1 * 4 + 3] << 8) | src[1 * 4 + 2]; + uae_u16 cc = (src[6 * 4 + 3] << 8) | src[6 * 4 + 2]; + uae_u16 lf = (src[7 * 4 + 3] << 8) | src[7 * 4 + 2]; + uae_u16 bl = (src[2 * 4 + 3] << 8) | src[2 * 4 + 2]; + uae_u16 br = (src[3 * 4 + 3] << 8) | src[3 * 4 + 2]; + uae_u16 sl = (src[4 * 4 + 3] << 8) | src[4 * 4 + 2]; + uae_u16 sr = (src[5 * 4 + 3] << 8) | src[5 * 4 + 2]; + dst2[0] = fl; + dst2[1] = fr; + dst2[2] = cc; + dst2[3] = lf; + dst2[4] = (bl + sl) / 2; + dst2[5] = (br + sr) / 2; + } + dst += och2; + src += 8 * 4; + if (src >= srce) + src = srcp; + } + } + break; + } + *psrcp = src; + return dstlen * och2; } - dst2[2] = dst2[3] = (dst2[0] + dst2[1]) / 4; - if (dsahip->chout <= 6) - return; - dst2[6] = dst2[4]; - dst2[7] = dst2[5]; - } -} - -/* sample conversion routines */ -static int copysampledata (struct DSAHI *dsahip, struct dschannel *dc, struct dssample *ds, uae_u8 **psrcp, uae_u8 *srce, uae_u8 *srcp, void *dstp, int dstlen) -{ - int i; - uae_u8 *src = *psrcp; - uae_u8 *dst = (uae_u8*)dstp; - int och = dsahip->chout; - int och2 = och * 2; - int ich = ds->ch; - int len; - - len = dstlen; - switch (ds->sampletype) - { - case AHIST_M8S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[0] << 16) | (src[0] << 8) | src[0] ; - uae_u32 r = (src[0] << 16) | (src[0] << 8) | src[0]; - src += 1; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_S8S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[0] << 16) | (src[0] << 8) | src[0] ; - uae_u32 r = (src[1] << 16) | (src[1] << 8) | src[1]; - src += 2; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_M16S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[0] << 16) | (src[1] << 8) | src[1]; - uae_u32 r = (src[0] << 16) | (src[1] << 8) | src[1]; - src += 2; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_S16S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[0] << 16) | (src[1] << 8) | src[1]; - uae_u32 r = (src[2] << 16) | (src[3] << 8) | src[3]; - src += 4; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_M32S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[3] << 16) | (src[2] << 8) | src[1]; - uae_u32 r = (src[3] << 16) | (src[2] << 8) | src[1]; - src += 4; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_S32S: - for (i = 0; i < len; i++) { - uae_u32 l = (src[3] << 16) | (src[2] << 8) | src[1]; - uae_u32 r = (src[7] << 16) | (src[6] << 8) | src[5]; - src += 8; - if (src >= srce) - src = srcp; - MAKEXCH; - } - break; - case AHIST_L7_1: - if (och == 8) { - for (i = 0; i < len; i++) { - if (dsahip->bits24) { - uae_u32 fl = (src[0 * 4 + 3] << 16) | (src[0 * 4 + 2] << 8) | src[0 * 4 + 1]; - uae_u32 fr = (src[1 * 4 + 3] << 16) | (src[1 * 4 + 2] << 8) | src[1 * 4 + 1]; - uae_u32 cc = (src[6 * 4 + 3] << 16) | (src[6 * 4 + 2] << 8) | src[6 * 4 + 1]; - uae_u32 lf = (src[7 * 4 + 3] << 16) | (src[7 * 4 + 2] << 8) | src[7 * 4 + 1]; - uae_u32 bl = (src[2 * 4 + 3] << 16) | (src[2 * 4 + 2] << 8) | src[2 * 4 + 1]; - uae_u32 br = (src[3 * 4 + 3] << 16) | (src[3 * 4 + 2] << 8) | src[3 * 4 + 1]; - uae_u32 sl = (src[4 * 4 + 3] << 16) | (src[4 * 4 + 2] << 8) | src[4 * 4 + 1]; - uae_u32 sr = (src[5 * 4 + 3] << 16) | (src[5 * 4 + 2] << 8) | src[5 * 4 + 1]; - uae_s32 *dst2 = (uae_s32*)(&dst[i * och2]); - dst2[0] = fl; - dst2[1] = fr; - dst2[2] = cc; - dst2[3] = lf; - dst2[4] = bl; - dst2[5] = br; - dst2[6] = sl; - dst2[7] = sr; - } else { - uae_u16 fl = (src[0 * 4 + 3] << 8) | src[0 * 4 + 2]; - uae_u16 fr = (src[1 * 4 + 3] << 8) | src[1 * 4 + 2]; - uae_u16 cc = (src[6 * 4 + 3] << 8) | src[6 * 4 + 2]; - uae_u16 lf = (src[7 * 4 + 3] << 8) | src[7 * 4 + 2]; - uae_u16 bl = (src[2 * 4 + 3] << 8) | src[2 * 4 + 2]; - uae_u16 br = (src[3 * 4 + 3] << 8) | src[3 * 4 + 2]; - uae_u16 sl = (src[4 * 4 + 3] << 8) | src[4 * 4 + 2]; - uae_u16 sr = (src[5 * 4 + 3] << 8) | src[5 * 4 + 2]; - uae_s16 *dst2 = (uae_s16*)(&dst[i * och2]); - dst2[0] = fl; - dst2[1] = fr; - dst2[2] = cc; - dst2[3] = lf; - dst2[4] = bl; - dst2[5] = br; - dst2[6] = sl; - dst2[7] = sr; - } - dst += och2; - src += 8 * 4; - if (src >= srce) - src = srcp; + + static void dorecord (struct DSAHI *dsahip) + { + uae_u32 pbase = get_long (dsahip->audioctrl + ahiac_DriverData); + uae_u32 recordbuf; + int bytes; + + if (dsahip->al_recorddev == NULL) + return; + if (dsahip->record_wait && !get_word (pbase + pub_RecordHookDone)) + return; + dsahip->record_wait = 0; + bytes = dsahip->record_samples * dsahip->record_ch * dsahip->record_bytespersample; + recordbuf = get_long (pbase + pub_RecordBuffer); + if (recordbuf == 0 || !valid_address (recordbuf, bytes)) + return; + alClear (); + alcCaptureSamples (dsahip->al_recorddev, (void*)recordbuf, dsahip->record_samples); + if (alGetError () != AL_NO_ERROR) + return; + put_word (pbase + pub_RecordHookDone, 0); + dsahip->record_wait = 1; + put_word (pbase + pub_FuncMode, get_word (pbase + pub_FuncMode) | FUNCMODE_RECORD); + sendsignal (dsahip); + } + + + static void al_setloop (struct dschannel *dc, int state) + { + alClear (); + alSourcei (dc->al_source, AL_LOOPING, state ? AL_TRUE : AL_FALSE); + alError (L"AHI: ds_play() alSourcei(AL_LOOPING)"); + } + + static void al_startplay (struct dschannel *dc) + { + alClear (); + alSourcePlay (dc->al_source); + alError (L"AHI: ds_play() alSourcePlay"); + } + + static void preparesample_single (struct DSAHI *dsahip, struct dschannel *dc) + { + uae_u8 *p, *ps, *pe; + struct dssample *ds; + int slen, dlen; + + dc->samplecounter = -1; + dc->buffertoggle = 0; + + ds = dc->cs.ds; + ps = p = get_real_address (ds->addr); + pe = ps + ds->len * ds->bytespersample * ds->ch; + + slen = ds->len; + p += dc->cs.srcplayoffset * ds->bytespersample * ds->ch; + dlen = copysampledata (dsahip, dc, ds, &p, pe, ps, dsahip->tmpbuffer, slen); + alClear (); + alBufferData (ds->al_buffer[dc->buffertoggle], dsahip->al_bufferformat, dsahip->tmpbuffer, dlen, dc->cs.frequency); + alError (L"AHI: preparesample_single:alBufferData(len=%d,freq=%d)", dlen, dc->cs.frequency); + alClear (); + alSourceQueueBuffers (dc->al_source, 1, &ds->al_buffer[dc->buffertoggle]); + alError (L"AHI: al_initsample_single:alSourceQueueBuffers(freq=%d)", dc->cs.frequency); + if (ahi_debug > 2) + write_log (L"AHI: sample queued %d: %d/%d\n", + dc->num, dc->samplecounter, dc->totalsamples); + } + + + static void preparesample_multi (struct DSAHI *dsahip, struct dschannel *dc) + { + uae_u8 *p, *ps, *pe; + struct dssample *ds; + int slen, dlen; + + ds = dc->cs.ds; + ps = p = get_real_address (ds->addr); + pe = ps + ds->len * ds->bytespersample * ds->ch; + + slen = dc->maxplaysamples; + if (dc->samplecounter == dc->totalsamples - 1) + slen = ds->len - dc->maxplaysamples * (dc->totalsamples - 1); + + p += (dc->maxplaysamples * dc->samplecounter + dc->cs.srcplayoffset) * ds->bytespersample * ds->ch; + dlen = copysampledata (dsahip, dc, ds, &p, pe, ps, dsahip->tmpbuffer, slen); + alClear (); + alBufferData (ds->al_buffer[dc->buffertoggle], dsahip->al_bufferformat, dsahip->tmpbuffer, dlen, dc->cs.frequency); + alError (L"AHI: preparesample:alBufferData(len=%d,freq=%d)", dlen, dc->cs.frequency); + alClear (); + alSourceQueueBuffers (dc->al_source, 1, &ds->al_buffer[dc->buffertoggle]); + alError (L"AHI: al_initsample:alSourceQueueBuffers(freq=%d)", dc->cs.frequency); + if (ahi_debug > 2) + write_log (L"AHI: sample queued %d: %d/%d\n", + dc->num, dc->samplecounter, dc->totalsamples); + dc->samplecounter++; + dc->buffertoggle ^= 1; + } + + /* called when sample is started for the first time */ + static void al_initsample (struct DSAHI *dsahip, struct dschannel *dc) + { + uae_u32 audioctrl = dsahip->audioctrl; + struct dssample *ds; + int single = 0; + + alSourceStop (dc->al_source); + alClear (); + alSourcei (dc->al_source, AL_BUFFER, AL_NONE); + alError (L"AHI: al_initsample:AL_BUFFER=AL_NONE"); + + memcpy (&dc->cs, &dc->csnext, sizeof (struct chsample)); + dc->csnext.ds = NULL; + dc->waitforack = 0; + ds = dc->cs.ds; + if (ds == NULL) + return; + + if (get_long (audioctrl + ahiac_SoundFunc)) { + dc->samplecounter = 0; + if (ds->dynamic) { + dc->maxplaysamples = dsahip->maxplaysamples / 2; + if (dc->maxplaysamples > ds->len / 2) + dc->maxplaysamples = ds->len / 2; + } else { + dc->maxplaysamples = ds->len / 2; + } + if (dc->maxplaysamples > dsahip->tmpbuffer_size) + dc->maxplaysamples = dsahip->tmpbuffer_size; + + dc->totalsamples = ds->len / dc->maxplaysamples; + if (dc->totalsamples <= 1) + dc->totalsamples = 2; + /* queue first half */ + preparesample_multi (dsahip, dc); + /* queue second half */ + preparesample_multi (dsahip, dc); + } else { + single = 1; + preparesample_single (dsahip, dc); } - } else if (och == 6) { /* 7.1 -> 5.1 */ - for (i = 0; i < len; i++) { - if (dsahip->bits24) { - uae_s32 *dst2 = (uae_s32*)(&dst[i * och2]); - uae_u32 fl = (src[0 * 4 + 3] << 16) | (src[0 * 4 + 2] << 8) | src[0 * 4 + 1]; - uae_u32 fr = (src[1 * 4 + 3] << 16) | (src[1 * 4 + 2] << 8) | src[1 * 4 + 1]; - uae_u32 cc = (src[6 * 4 + 3] << 16) | (src[6 * 4 + 2] << 8) | src[6 * 4 + 1]; - uae_u32 lf = (src[7 * 4 + 3] << 16) | (src[7 * 4 + 2] << 8) | src[7 * 4 + 1]; - uae_u32 bl = (src[2 * 4 + 3] << 16) | (src[2 * 4 + 2] << 8) | src[2 * 4 + 1]; - uae_u32 br = (src[3 * 4 + 3] << 16) | (src[3 * 4 + 2] << 8) | src[3 * 4 + 1]; - uae_u32 sl = (src[4 * 4 + 3] << 16) | (src[4 * 4 + 2] << 8) | src[4 * 4 + 1]; - uae_u32 sr = (src[5 * 4 + 3] << 16) | (src[5 * 4 + 2] << 8) | src[5 * 4 + 1]; - } else { - uae_s16 *dst2 = (uae_s16*)(&dst[i * och2]); - uae_u16 fl = (src[0 * 4 + 3] << 8) | src[0 * 4 + 2]; - uae_u16 fr = (src[1 * 4 + 3] << 8) | src[1 * 4 + 2]; - uae_u16 cc = (src[6 * 4 + 3] << 8) | src[6 * 4 + 2]; - uae_u16 lf = (src[7 * 4 + 3] << 8) | src[7 * 4 + 2]; - uae_u16 bl = (src[2 * 4 + 3] << 8) | src[2 * 4 + 2]; - uae_u16 br = (src[3 * 4 + 3] << 8) | src[3 * 4 + 2]; - uae_u16 sl = (src[4 * 4 + 3] << 8) | src[4 * 4 + 2]; - uae_u16 sr = (src[5 * 4 + 3] << 8) | src[5 * 4 + 2]; - dst2[0] = fl; - dst2[1] = fr; - dst2[2] = cc; - dst2[3] = lf; - dst2[4] = (bl + sl) / 2; - dst2[5] = (br + sr) / 2; - } - dst += och2; - src += 8 * 4; - if (src >= srce) - src = srcp; + al_setloop (dc, single); + + if (dc->dsplaying) { + dc->dsplaying = 1; + al_startplay (dc); + setchannelevent (dsahip, dc); } - } - break; - } - *psrcp = src; - return dstlen * och2; -} - -static void dorecord (struct DSAHI *dsahip) -{ - uae_u32 pbase = get_long (dsahip->audioctrl + ahiac_DriverData); - uae_u32 recordbuf; - int bytes; - - if (dsahip->al_recorddev == NULL) - return; - if (dsahip->record_wait && !get_word (pbase + pub_RecordHookDone)) - return; - dsahip->record_wait = 0; - bytes = dsahip->record_samples * dsahip->record_ch * dsahip->record_bytespersample; - recordbuf = get_long (pbase + pub_RecordBuffer); - if (recordbuf == 0 || !valid_address (recordbuf, bytes)) - return; - alClear (); - alcCaptureSamples (dsahip->al_recorddev, (void*)recordbuf, dsahip->record_samples); - if (alGetError () != AL_NO_ERROR) - return; - put_word (pbase + pub_RecordHookDone, 0); - dsahip->record_wait = 1; - put_word (pbase + pub_FuncMode, get_word (pbase + pub_FuncMode) | FUNCMODE_RECORD); - sendsignal (dsahip); -} - - -static void al_setloop (struct dschannel *dc, int state) -{ - alClear (); - alSourcei (dc->al_source, AL_LOOPING, state ? AL_TRUE : AL_FALSE); - alError (L"AHI: ds_play() alSourcei(AL_LOOPING)"); -} + } -static void al_startplay (struct dschannel *dc) -{ - alClear (); - alSourcePlay (dc->al_source); - alError (L"AHI: ds_play() alSourcePlay"); -} + /* called when previous sample is still playing */ + static void al_queuesample (struct DSAHI *dsahip, struct dschannel *dc) + { + int v, restart; -static void preparesample_single (struct DSAHI *dsahip, struct dschannel *dc) -{ - uae_u8 *p, *ps, *pe; - struct dssample *ds; - int slen, dlen; - - dc->samplecounter = -1; - dc->buffertoggle = 0; - - ds = dc->cs.ds; - ps = p = get_real_address (ds->addr); - pe = ps + ds->len * ds->bytespersample * ds->ch; - - slen = ds->len; - p += dc->cs.srcplayoffset * ds->bytespersample * ds->ch; - dlen = copysampledata (dsahip, dc, ds, &p, pe, ps, dsahip->tmpbuffer, slen); - alClear (); - alBufferData (ds->al_buffer[dc->buffertoggle], dsahip->al_bufferformat, dsahip->tmpbuffer, dlen, dc->cs.frequency); - alError (L"AHI: preparesample_single:alBufferData(len=%d,freq=%d)", dlen, dc->cs.frequency); - alClear (); - alSourceQueueBuffers (dc->al_source, 1, &ds->al_buffer[dc->buffertoggle]); - alError (L"AHI: al_initsample_single:alSourceQueueBuffers(freq=%d)", dc->cs.frequency); - if (ahi_debug > 2) - write_log (L"AHI: sample queued %d: %d/%d\n", - dc->num, dc->samplecounter, dc->totalsamples); -} - - -static void preparesample_multi (struct DSAHI *dsahip, struct dschannel *dc) -{ - uae_u8 *p, *ps, *pe; - struct dssample *ds; - int slen, dlen; - - ds = dc->cs.ds; - ps = p = get_real_address (ds->addr); - pe = ps + ds->len * ds->bytespersample * ds->ch; - - slen = dc->maxplaysamples; - if (dc->samplecounter == dc->totalsamples - 1) - slen = ds->len - dc->maxplaysamples * (dc->totalsamples - 1); - - p += (dc->maxplaysamples * dc->samplecounter + dc->cs.srcplayoffset) * ds->bytespersample * ds->ch; - dlen = copysampledata (dsahip, dc, ds, &p, pe, ps, dsahip->tmpbuffer, slen); - alClear (); - alBufferData (ds->al_buffer[dc->buffertoggle], dsahip->al_bufferformat, dsahip->tmpbuffer, dlen, dc->cs.frequency); - alError (L"AHI: preparesample:alBufferData(len=%d,freq=%d)", dlen, dc->cs.frequency); - alClear (); - alSourceQueueBuffers (dc->al_source, 1, &ds->al_buffer[dc->buffertoggle]); - alError (L"AHI: al_initsample:alSourceQueueBuffers(freq=%d)", dc->cs.frequency); - if (ahi_debug > 2) - write_log (L"AHI: sample queued %d: %d/%d\n", - dc->num, dc->samplecounter, dc->totalsamples); - dc->samplecounter++; - dc->buffertoggle ^= 1; -} - -/* called when sample is started for the first time */ -static void al_initsample (struct DSAHI *dsahip, struct dschannel *dc) -{ - uae_u32 audioctrl = dsahip->audioctrl; - struct dssample *ds; - int single = 0; - - alSourceStop (dc->al_source); - alClear (); - alSourcei (dc->al_source, AL_BUFFER, AL_NONE); - alError (L"AHI: al_initsample:AL_BUFFER=AL_NONE"); - - memcpy (&dc->cs, &dc->csnext, sizeof (struct chsample)); - dc->csnext.ds = NULL; - dc->waitforack = 0; - ds = dc->cs.ds; - if (ds == NULL) - return; - - if (get_long (audioctrl + ahiac_SoundFunc)) { - dc->samplecounter = 0; - if (ds->dynamic) { - dc->maxplaysamples = dsahip->maxplaysamples / 2; - if (dc->maxplaysamples > ds->len / 2) - dc->maxplaysamples = ds->len / 2; - } else { - dc->maxplaysamples = ds->len / 2; + if (!dc->cs.ds) + return; + if (dc->cs.ds->num < 0) { + dc->cs.ds = NULL; + return; + } + restart = 0; + if (dc->dsplaying) { + alClear (); + alGetSourcei (dc->al_source, AL_SOURCE_STATE, &v); + alError (L"AHI: queuesample AL_SOURCE_STATE"); + if (v != AL_PLAYING) { + alClear (); + alSourceRewind (dc->al_source); + alError (L"AHI: queuesample:restart"); + restart = 1; + if (ahi_debug > 2) + write_log (L"AHI: queuesample, play restart\n"); + preparesample_multi (dsahip, dc); + } + } + preparesample_multi (dsahip, dc); + if (dc->dsplaying) + dc->dsplaying = 1; + if (restart) + al_startplay (dc); + if (ahi_debug > 2) + write_log (L"AHI: sample %d queued to channel %d\n", dc->cs.ds->num, dc->num); } - if (dc->maxplaysamples > dsahip->tmpbuffer_size) - dc->maxplaysamples = dsahip->tmpbuffer_size; - - dc->totalsamples = ds->len / dc->maxplaysamples; - if (dc->totalsamples <= 1) - dc->totalsamples = 2; - /* queue first half */ - preparesample_multi (dsahip, dc); - /* queue second half */ - preparesample_multi (dsahip, dc); - } else { - single = 1; - preparesample_single (dsahip, dc); - } - al_setloop (dc, single); - - if (dc->dsplaying) { - dc->dsplaying = 1; - al_startplay (dc); - setchannelevent (dsahip, dc); - } -} - -/* called when previous sample is still playing */ -static void al_queuesample (struct DSAHI *dsahip, struct dschannel *dc) -{ - int v, restart; - - if (!dc->cs.ds) - return; - if (dc->cs.ds->num < 0) { - dc->cs.ds = NULL; - return; - } - restart = 0; - if (dc->dsplaying) { - alClear (); - alGetSourcei (dc->al_source, AL_SOURCE_STATE, &v); - alError (L"AHI: queuesample AL_SOURCE_STATE"); - if (v != AL_PLAYING) { - alClear (); - alSourceRewind (dc->al_source); - alError (L"AHI: queuesample:restart"); - restart = 1; - if (ahi_debug > 2) - write_log (L"AHI: queuesample, play restart\n"); - preparesample_multi (dsahip, dc); + + static int unqueuebuffers (struct dschannel *dc) + { + int v, cnt = 0; + for (;;) { + ALuint tmp; + alClear (); + alGetSourcei (dc->al_source, AL_BUFFERS_PROCESSED, &v); + if (alError (L"AHI: hsync AL_BUFFERS_PROCESSED %d", dc->num)) + return cnt; + if (v == 0) + return cnt; + alSourceUnqueueBuffers (dc->al_source, 1, &tmp); + cnt++; + } } - } - preparesample_multi (dsahip, dc); - if (dc->dsplaying) - dc->dsplaying = 1; - if (restart) - al_startplay (dc); - if (ahi_debug > 2) - write_log (L"AHI: sample %d queued to channel %d\n", dc->cs.ds->num, dc->num); -} - -static int unqueuebuffers (struct dschannel *dc) -{ - int v, cnt = 0; - for (;;) { - ALuint tmp; - alClear (); - alGetSourcei (dc->al_source, AL_BUFFERS_PROCESSED, &v); - if (alError (L"AHI: hsync AL_BUFFERS_PROCESSED %d", dc->num)) - return cnt; - if (v == 0) - return cnt; - alSourceUnqueueBuffers (dc->al_source, 1, &tmp); - cnt++; - } -} - -void ahi_hsync (void) -{ - struct DSAHI *dsahip = &dsahi[0]; - static int cnt; - uae_u32 pbase; - int i, flags; - - if (ahi_paused || !ahi_active) - return; - pbase = get_long (dsahip->audioctrl + ahiac_DriverData); - if (cnt >= 0) - cnt--; - if (cnt < 0) { - if (dsahip->dsrecording && dsahip->enabledisable == 0) { - dorecord (dsahip); - cnt = 100; + + void ahi_hsync (void) + { + struct DSAHI *dsahip = &dsahi[0]; + static int cnt; + uae_u32 pbase; + int i, flags; + + if (ahi_paused || !ahi_active) + return; + pbase = get_long (dsahip->audioctrl + ahiac_DriverData); + if (cnt >= 0) + cnt--; + if (cnt < 0) { + if (dsahip->dsrecording && dsahip->enabledisable == 0) { + dorecord (dsahip); + cnt = 100; + } + } + if (!dsahip->playing) + return; + flags = get_long (pbase + pub_ChannelSignalAck); + for (i = 0; i < UAE_MAXCHANNELS; i++) { + int v, removed; + struct dschannel *dc = &dsahip->channel[i]; + uae_u32 mask = 1 << (dc - &dsahip->channel[0]); + + if (dc->dsplaying != 1 || dc->al_source == -1) + continue; + + removed = unqueuebuffers (dc); + v = 0; + alClear (); + alGetSourcei (dc->al_source, AL_SOURCE_STATE, &v); + alError (L"AHI: hsync AL_SOURCE_STATE"); + if (v != AL_PLAYING) { + if (dc->cs.ds) { + setchannelevent (dsahip, dc); + if (ahi_debug) + write_log (L"AHI: ********* channel %d stopped state=%d!\n", dc->num, v); + removed = 1; + dc->dsplaying = 2; + dc->waitforack = 0; + } + } + if (!dc->waitforack && dc->samplecounter >= 0 && removed) { + int evt = 0; + if (ahi_debug > 2) + write_log (L"sample end channel %d: %d/%d\n", dc->num, dc->samplecounter, dc->totalsamples); + if (dc->samplecounter >= dc->totalsamples) { + evt = 1; + if (ahi_debug > 2) + write_log (L"sample finished channel %d: %d\n", dc->num, dc->totalsamples); + dc->samplecounter = 0; + if (dc->csnext.ds) { + memcpy (&dc->cs, &dc->csnext, sizeof (struct chsample)); + dc->csnext.ds = NULL; + } + } + if (evt) { + flags &= ~mask; + if (setchannelevent (dsahip, dc)) + dc->waitforack = 1; + } + if (!dc->waitforack) + al_queuesample (dsahip, dc); + } + if (dc->waitforack && (flags & mask)) { + al_queuesample (dsahip, dc); + dc->waitforack = 0; + flags &= ~mask; + } + } + put_long (pbase + pub_ChannelSignalAck, flags); + } + + static void ds_record (struct DSAHI *dsahip, int start) + { + alClear (); + if (start) { + if (!dsahip->dsrecording) + alcCaptureStart (dsahip->al_recorddev); + dsahip->dsrecording = 1; + } else { + alcCaptureStop (dsahip->al_recorddev); + dsahip->dsrecording = 0; + } + alError (L"AHI: alcCapture%s failed", start ? "Start" : "Stop"); } - } - if (!dsahip->playing) - return; - flags = get_long (pbase + pub_ChannelSignalAck); - for (i = 0; i < UAE_MAXCHANNELS; i++) { - int v, removed; - struct dschannel *dc = &dsahip->channel[i]; - uae_u32 mask = 1 << (dc - &dsahip->channel[0]); - - if (dc->dsplaying != 1 || dc->al_source == -1) - continue; - - removed = unqueuebuffers (dc); - v = 0; - alClear (); - alGetSourcei (dc->al_source, AL_SOURCE_STATE, &v); - alError (L"AHI: hsync AL_SOURCE_STATE"); - if (v != AL_PLAYING) { - if (dc->cs.ds) { - setchannelevent (dsahip, dc); + + static void ds_stop (struct DSAHI *dsahip, struct dschannel *dc) + { + dc->dsplaying = 0; + if (dc->al_source == -1) + return; if (ahi_debug) - write_log (L"AHI: ********* channel %d stopped state=%d!\n", dc->num, v); - removed = 1; - dc->dsplaying = 2; - dc->waitforack = 0; - } + write_log (L"AHI: ds_stop(%d)\n", dc->num); + alClear (); + alSourceStop (dc->al_source); + alError (L"AHI: alSourceStop"); + unqueuebuffers (dc); } - if (!dc->waitforack && dc->samplecounter >= 0 && removed) { - int evt = 0; - if (ahi_debug > 2) - write_log (L"sample end channel %d: %d/%d\n", dc->num, dc->samplecounter, dc->totalsamples); - if (dc->samplecounter >= dc->totalsamples) { - evt = 1; - if (ahi_debug > 2) - write_log (L"sample finished channel %d: %d\n", dc->num, dc->totalsamples); - dc->samplecounter = 0; - if (dc->csnext.ds) { - memcpy (&dc->cs, &dc->csnext, sizeof (struct chsample)); - dc->csnext.ds = NULL; + + static void ds_play (struct DSAHI *dsahip, struct dschannel *dc) + { + if (dc->dsplaying) { + dc->dsplaying = 1; + return; } - } - if (evt) { - flags &= ~mask; - if (setchannelevent (dsahip, dc)) - dc->waitforack = 1; - } - if (!dc->waitforack) - al_queuesample (dsahip, dc); + dc->dsplaying = 1; + if (dc->cs.frequency == 0) + return; + if (dc->al_source == -1) + return; + if (ahi_debug) + write_log (L"AHI: ds_play(%d)\n", dc->num); + al_startplay (dc); } - if (dc->waitforack && (flags & mask)) { - al_queuesample (dsahip, dc); - dc->waitforack = 0; - flags &= ~mask; + + void ahi2_pause_sound (int paused) + { + int i; + struct DSAHI *dsahip = &dsahi[0]; + + ahi_paused = paused; + if (!dsahip->playing && !dsahip->recording) + return; + for (i = 0; i < UAE_MAXCHANNELS; i++) { + struct dschannel *dc = &dsahip->channel[i]; + if (dc->al_source == -1) + continue; + if (paused) { + ds_stop (dsahip, dc); + } else { + ds_play (dsahip, dc); + setchannelevent (dsahip, dc); + } + } } - } - put_long (pbase + pub_ChannelSignalAck, flags); -} -static void ds_record (struct DSAHI *dsahip, int start) -{ - alClear (); - if (start) { - if (!dsahip->dsrecording) - alcCaptureStart (dsahip->al_recorddev); - dsahip->dsrecording = 1; - } else { - alcCaptureStop (dsahip->al_recorddev); - dsahip->dsrecording = 0; - } - alError (L"AHI: alcCapture%s failed", start ? "Start" : "Stop"); -} - -static void ds_stop (struct DSAHI *dsahip, struct dschannel *dc) -{ - dc->dsplaying = 0; - if (dc->al_source == -1) - return; - if (ahi_debug) - write_log (L"AHI: ds_stop(%d)\n", dc->num); - alClear (); - alSourceStop (dc->al_source); - alError (L"AHI: alSourceStop"); - unqueuebuffers (dc); -} - -static void ds_play (struct DSAHI *dsahip, struct dschannel *dc) -{ - if (dc->dsplaying) { - dc->dsplaying = 1; - return; - } - dc->dsplaying = 1; - if (dc->cs.frequency == 0) - return; - if (dc->al_source == -1) - return; - if (ahi_debug) - write_log (L"AHI: ds_play(%d)\n", dc->num); - al_startplay (dc); -} - -void ahi2_pause_sound (int paused) -{ - int i; - struct DSAHI *dsahip = &dsahi[0]; - - ahi_paused = paused; - if (!dsahip->playing && !dsahip->recording) - return; - for (i = 0; i < UAE_MAXCHANNELS; i++) { - struct dschannel *dc = &dsahip->channel[i]; - if (dc->al_source == -1) - continue; - if (paused) { - ds_stop (dsahip, dc); - } else { - ds_play (dsahip, dc); - setchannelevent (dsahip, dc); + static uae_u32 init (TrapContext *ctx) + { + int i, j; + + enumerate_sound_devices (); + xahi_author = ds (L"Toni Wilen"); + xahi_copyright = ds (L"GPL"); + xahi_version = ds (L"uae2 0.2 (xx.xx.2008)\r\n"); + j = 0; + for (i = 0; sound_devices[i].name; i++) { + if (sound_devices[i].type == SOUND_DEVICE_AL) + xahi_output[j++] = ds (sound_devices[i].name); + } + xahi_output_num = j; + j = 0; + for (i = 0; record_devices[i].name; i++) { + if (record_devices[i].type == SOUND_DEVICE_AL) + xahi_input[j++] = ds (record_devices[i].name); + } + xahi_input_num = j; + return 1; } - } -} -static uae_u32 init (TrapContext *ctx) -{ - int i, j; - - enumerate_sound_devices (); - xahi_author = ds (L"Toni Wilen"); - xahi_copyright = ds (L"GPL"); - xahi_version = ds (L"uae2 0.2 (xx.xx.2008)\r\n"); - j = 0; - for (i = 0; sound_devices[i].name; i++) { - if (sound_devices[i].type == SOUND_DEVICE_AL) - xahi_output[j++] = ds (sound_devices[i].name); - } - xahi_output_num = j; - j = 0; - for (i = 0; record_devices[i].name; i++) { - if (record_devices[i].type == SOUND_DEVICE_AL) - xahi_input[j++] = ds (record_devices[i].name); - } - xahi_input_num = j; - return 1; -} - -static uae_u32 AHIsub_AllocAudio (TrapContext *ctx) -{ - int i; - uae_u32 tags = m68k_areg (regs, 1); - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); - uae_u32 tag, data, v, ver, size; - uae_u32 ret = AHISF_KNOWSTEREO | AHISF_KNOWHIFI; - struct DSAHI *dsahip = &dsahi[0]; - - if (ahi_debug) - write_log (L"AHI: AllocAudio(%08x,%08x)\n", tags, audioctrl); - - ver = get_long (pbase + pub_Version); - size = get_long (pbase + pub_SizeOf); - if (ver != AHI_STRUCT_VERSION) { - gui_message (L"AHI: Incompatible DEVS:AHI/uae2.audio\nVersion mismatch %d<>%d.", ver, AHI_STRUCT_VERSION); - return AHISF_ERROR; - } - if (size < pub_End) { - gui_message (L"AHI: Incompatible DEVS:AHI/uae2.audio.\nInternal structure size %d<>%d.", size, pub_End); - return AHISF_ERROR; - } - - v = get_long (pbase + pub_Index); - if (v != -1) { - write_log (L"AHI: corrupted memory\n"); - return AHISF_ERROR; - } - put_long (pbase + pub_Index, dsahip - dsahi); - dsahip->audioctrl = audioctrl; - - dsahip->maxplaysamples = UAE_MAXPLAYSAMPLES; - dsahip->sounds = UAE_MAXSOUNDS; - dsahip->channels = UAE_MAXCHANNELS; - - dsahip->audioid = 0x003b0001; - while ((tag = gettag (&tags, &data))) { - if (ahi_debug) - write_log (L"- TAG %08x=%d: %08x=%u\n", tag, tag & 0x7fff, data, data); - switch (tag) + static uae_u32 AHIsub_AllocAudio (TrapContext *ctx) + { + int i; + uae_u32 tags = m68k_areg (regs, 1); + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); + uae_u32 tag, data, v, ver, size; + uae_u32 ret = AHISF_KNOWSTEREO | AHISF_KNOWHIFI; + struct DSAHI *dsahip = &dsahi[0]; + + if (ahi_debug) + write_log (L"AHI: AllocAudio(%08x,%08x)\n", tags, audioctrl); + + ver = get_long (pbase + pub_Version); + size = get_long (pbase + pub_SizeOf); + if (ver != AHI_STRUCT_VERSION) { + gui_message (L"AHI: Incompatible DEVS:AHI/uae2.audio\nVersion mismatch %d<>%d.", ver, AHI_STRUCT_VERSION); + return AHISF_ERROR; + } + if (size < pub_End) { + gui_message (L"AHI: Incompatible DEVS:AHI/uae2.audio.\nInternal structure size %d<>%d.", size, pub_End); + return AHISF_ERROR; + } + + v = get_long (pbase + pub_Index); + if (v != -1) { + write_log (L"AHI: corrupted memory\n"); + return AHISF_ERROR; + } + put_long (pbase + pub_Index, dsahip - dsahi); + dsahip->audioctrl = audioctrl; + + dsahip->maxplaysamples = UAE_MAXPLAYSAMPLES; + dsahip->sounds = UAE_MAXSOUNDS; + dsahip->channels = UAE_MAXCHANNELS; + + dsahip->audioid = 0x003b0001; + while ((tag = gettag (&tags, &data))) { + if (ahi_debug) + write_log (L"- TAG %08x=%d: %08x=%u\n", tag, tag & 0x7fff, data, data); + switch (tag) + { + case AHIA_AudioID: + dsahip->audioid = data; + break; + } + } + + if ((dsahip->audioid >> 16) != 0x3b) + return AHISF_ERROR; + + if (dsahip->sounds < 0 || dsahip->sounds > 1000) + return AHISF_ERROR; + + if (!ds_init (dsahip)) + return AHISF_ERROR; + + if (xahi_input_num) + ret |= AHISF_CANRECORD; + if (cansurround) + ret |= AHISF_KNOWMULTICHANNEL; + + dsahip->sample = xcalloc (sizeof (struct dssample), dsahip->sounds); + dsahip->channel = xcalloc (sizeof (struct dschannel), dsahip->channels); + for (i = 0; i < dsahip->channels; i++) { + struct dschannel *dc = &dsahip->channel[i]; + dc->num = i; + dc->al_source = -1; + } + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + ds->num = -1; + ds->al_buffer[0] = -1; + ds->al_buffer[1] = -1; + } + ahi_active = 1; + return ret; + } + + static void AHIsub_Disable (TrapContext *ctx) { - case AHIA_AudioID: - dsahip->audioid = data; - break; + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + if (ahi_debug > 1) + write_log (L"AHI: Disable(%08x)\n", audioctrl); + dsahip->enabledisable++; } - } - - if ((dsahip->audioid >> 16) != 0x3b) - return AHISF_ERROR; - - if (dsahip->sounds < 0 || dsahip->sounds > 1000) - return AHISF_ERROR; - - if (!ds_init (dsahip)) - return AHISF_ERROR; - - if (xahi_input_num) - ret |= AHISF_CANRECORD; - if (cansurround) - ret |= AHISF_KNOWMULTICHANNEL; - - dsahip->sample = xcalloc (sizeof (struct dssample), dsahip->sounds); - dsahip->channel = xcalloc (sizeof (struct dschannel), dsahip->channels); - for (i = 0; i < dsahip->channels; i++) { - struct dschannel *dc = &dsahip->channel[i]; - dc->num = i; - dc->al_source = -1; - } - for (i = 0; i < dsahip->sounds; i++) { - struct dssample *ds = &dsahip->sample[i]; - ds->num = -1; - ds->al_buffer[0] = -1; - ds->al_buffer[1] = -1; - } - ahi_active = 1; - return ret; -} - -static void AHIsub_Disable (TrapContext *ctx) -{ - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - if (ahi_debug > 1) - write_log (L"AHI: Disable(%08x)\n", audioctrl); - dsahip->enabledisable++; -} - -static void AHIsub_Enable (TrapContext *ctx) -{ - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - if (ahi_debug > 1) - write_log (L"AHI: Enable(%08x)\n", audioctrl); - dsahip->enabledisable--; - if (dsahip->enabledisable == 0 && dsahip->playing) - setevent (dsahip); -} - -static void AHIsub_FreeAudio (TrapContext *ctx) -{ - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); - struct DSAHI *dsahip = GETAHI; - if (ahi_debug) - write_log (L"AHI: FreeAudio(%08x)\n", audioctrl); - if (ahi_active == 0) - return; - ahi_active = 0; - put_long (pbase + pub_Index, -1); - if (dsahip) { - ds_free (dsahip); - ds_free_record (dsahip); - xfree (dsahip->channel); - xfree (dsahip->sample); - memset (dsahip, 0, sizeof (struct DSAHI)); - } -} - -static uae_u32 frequencies[] = { 48000, 44100 }; + + static void AHIsub_Enable (TrapContext *ctx) + { + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + if (ahi_debug > 1) + write_log (L"AHI: Enable(%08x)\n", audioctrl); + dsahip->enabledisable--; + if (dsahip->enabledisable == 0 && dsahip->playing) + setevent (dsahip); + } + + static void AHIsub_FreeAudio (TrapContext *ctx) + { + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); + struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log (L"AHI: FreeAudio(%08x)\n", audioctrl); + if (ahi_active == 0) + return; + ahi_active = 0; + put_long (pbase + pub_Index, -1); + if (dsahip) { + ds_free (dsahip); + ds_free_record (dsahip); + xfree (dsahip->channel); + xfree (dsahip->sample); + memset (dsahip, 0, sizeof (struct DSAHI)); + } + } + + static uae_u32 frequencies[] = { 48000, 44100 }; #define MAX_FREQUENCIES (sizeof (frequencies) / sizeof (uae_u32)) -static uae_u32 getattr2 (struct DSAHI *dsahip, uae_u32 attribute, uae_u32 argument, uae_u32 def) -{ - int i; - - switch (attribute) - { - case AHIDB_Bits: - return 32; - case AHIDB_Frequencies: - return MAX_FREQUENCIES; - case AHIDB_Frequency: - if (argument < 0 || argument >= MAX_FREQUENCIES) - argument = 0; - return frequencies[argument]; - case AHIDB_Index: - if (argument <= frequencies[0]) - return 0; - if (argument >= frequencies[MAX_FREQUENCIES - 1]) - return MAX_FREQUENCIES - 1; - for (i = 1; i < MAX_FREQUENCIES; i++) { - if (frequencies[i] > argument) { - if (argument - frequencies[i - 1] < frequencies[i] - argument) - return i - 1; - else - return i; - } + static uae_u32 getattr2 (struct DSAHI *dsahip, uae_u32 attribute, uae_u32 argument, uae_u32 def) + { + int i; + + switch (attribute) + { + case AHIDB_Bits: + return 32; + case AHIDB_Frequencies: + return MAX_FREQUENCIES; + case AHIDB_Frequency: + if (argument < 0 || argument >= MAX_FREQUENCIES) + argument = 0; + return frequencies[argument]; + case AHIDB_Index: + if (argument <= frequencies[0]) + return 0; + if (argument >= frequencies[MAX_FREQUENCIES - 1]) + return MAX_FREQUENCIES - 1; + for (i = 1; i < MAX_FREQUENCIES; i++) { + if (frequencies[i] > argument) { + if (argument - frequencies[i - 1] < frequencies[i] - argument) + return i - 1; + else + return i; + } + } + return 0; + case AHIDB_Author: + return xahi_author; + case AHIDB_Copyright: + return xahi_copyright; + case AHIDB_Version: + return xahi_version; + case AHIDB_Record: + return -1; + case AHIDB_Realtime: + return -1; + case AHIDB_MinOutputVolume: + return 0x00000; + case AHIDB_MaxOutputVolume: + return 0x10000; + case AHIDB_Outputs: + return xahi_output_num; + case AHIDB_Output: + if (argument >= 0 && argument < xahi_output_num) + return xahi_output[argument]; + return 0; + case AHIDB_Inputs: + return xahi_input_num; + case AHIDB_Input: + if (argument >= 0 && argument < xahi_input_num) + return xahi_input[argument]; + return 0; + case AHIDB_Volume: + return -1; + case AHIDB_Panning: + return -1; + case AHIDB_HiFi: + return -1; + case AHIDB_MultiChannel: + return cansurround ? -1 : 0; + case AHIDB_MaxChannels: + return UAE_MAXCHANNELS; + case AHIDB_FullDuplex: + return -1; + case AHIDB_MaxRecordSamples: + return UAE_RECORDSAMPLES; + case AHIDB_MaxPlaySamples: + if (def < dsahip->maxplaysamples) + def = dsahip->maxplaysamples; + return def; + default: + return def; + } } - return 0; - case AHIDB_Author: - return xahi_author; - case AHIDB_Copyright: - return xahi_copyright; - case AHIDB_Version: - return xahi_version; - case AHIDB_Record: - return -1; - case AHIDB_Realtime: - return -1; - case AHIDB_MinOutputVolume: - return 0x00000; - case AHIDB_MaxOutputVolume: - return 0x10000; - case AHIDB_Outputs: - return xahi_output_num; - case AHIDB_Output: - if (argument >= 0 && argument < xahi_output_num) - return xahi_output[argument]; - return 0; - case AHIDB_Inputs: - return xahi_input_num; - case AHIDB_Input: - if (argument >= 0 && argument < xahi_input_num) - return xahi_input[argument]; - return 0; - case AHIDB_Volume: - return -1; - case AHIDB_Panning: - return -1; - case AHIDB_HiFi: - return -1; - case AHIDB_MultiChannel: - return cansurround ? -1 : 0; - case AHIDB_MaxChannels: - return UAE_MAXCHANNELS; - case AHIDB_FullDuplex: - return -1; - case AHIDB_MaxRecordSamples: - return UAE_RECORDSAMPLES; - case AHIDB_MaxPlaySamples: - if (def < dsahip->maxplaysamples) - def = dsahip->maxplaysamples; - return def; - default: - return def; - } -} - -static uae_u32 AHIsub_GetAttr (TrapContext *ctx) -{ - uae_u32 attribute = m68k_dreg (regs, 0); - uae_u32 argument = m68k_dreg (regs, 1); - uae_u32 def = m68k_dreg (regs, 2); - uae_u32 taglist = m68k_areg (regs, 1); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - uae_u32 v; - - v = getattr2 (dsahip, attribute, argument, def); - if (ahi_debug) - write_log (L"AHI: GetAttr(%08x=%d,%08x,%08x)=%08x\n", attribute, attribute & 0x7fff, argument, def, v); - - return v; -} - -static uae_u32 AHIsub_HardwareControl (TrapContext *ctx) -{ - uae_u32 attribute = m68k_dreg (regs, 0); - uae_u32 argument = m68k_dreg (regs, 1); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - if (ahi_debug) - write_log (L"AHI: HardwareControl(%08x=%d,%08x,%08x)\n", attribute, attribute & 0x7fff, argument, audioctrl); - switch (attribute) - { - case AHIC_Input: - if (dsahip->input != argument) { - dsahip->input = argument; - if (dsahip->al_dev) { - ds_free_record (dsahip); - ds_init_record (dsahip); - if (dsahip->recording) - ds_record (dsahip, 1); - } + + static uae_u32 AHIsub_GetAttr (TrapContext *ctx) + { + uae_u32 attribute = m68k_dreg (regs, 0); + uae_u32 argument = m68k_dreg (regs, 1); + uae_u32 def = m68k_dreg (regs, 2); + uae_u32 taglist = m68k_areg (regs, 1); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + uae_u32 v; + + v = getattr2 (dsahip, attribute, argument, def); + if (ahi_debug) + write_log (L"AHI: GetAttr(%08x=%d,%08x,%08x)=%08x\n", attribute, attribute & 0x7fff, argument, def, v); + + return v; } - break; - case AHIC_Input_Query: - return dsahip->input; - case AHIC_Output: - if (dsahip->output != argument) { - dsahip->output = argument; - if (dsahip->al_dev) - ds_reinit (dsahip); + + static uae_u32 AHIsub_HardwareControl (TrapContext *ctx) + { + uae_u32 attribute = m68k_dreg (regs, 0); + uae_u32 argument = m68k_dreg (regs, 1); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log (L"AHI: HardwareControl(%08x=%d,%08x,%08x)\n", attribute, attribute & 0x7fff, argument, audioctrl); + switch (attribute) + { + case AHIC_Input: + if (dsahip->input != argument) { + dsahip->input = argument; + if (dsahip->al_dev) { + ds_free_record (dsahip); + ds_init_record (dsahip); + if (dsahip->recording) + ds_record (dsahip, 1); + } + } + break; + case AHIC_Input_Query: + return dsahip->input; + case AHIC_Output: + if (dsahip->output != argument) { + dsahip->output = argument; + if (dsahip->al_dev) + ds_reinit (dsahip); + } + break; + case AHIC_Output_Query: + return dsahip->output; + } + return 0; } - break; - case AHIC_Output_Query: - return dsahip->output; - } - return 0; -} - -static uae_u32 AHIsub_Start (TrapContext *ctx) -{ - uae_u32 flags = m68k_dreg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - int i; - - if (ahi_debug) - write_log (L"AHI: Play(%08x,%08x)\n", - flags, audioctrl); - if ((flags & AHISF_PLAY) && !dsahip->playing) { - dsahip->playing = 1; - setevent (dsahip); - for (i = 0; i < dsahip->channels; i++) { - struct dschannel *dc = &dsahip->channel[i]; - ds_play (dsahip, dc); + + static uae_u32 AHIsub_Start (TrapContext *ctx) + { + uae_u32 flags = m68k_dreg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + int i; + + if (ahi_debug) + write_log (L"AHI: Play(%08x,%08x)\n", + flags, audioctrl); + if ((flags & AHISF_PLAY) && !dsahip->playing) { + dsahip->playing = 1; + setevent (dsahip); + for (i = 0; i < dsahip->channels; i++) { + struct dschannel *dc = &dsahip->channel[i]; + ds_play (dsahip, dc); + } + } + if ((flags & AHISF_RECORD) && !dsahip->recording) { + dsahip->recording = 1; + ds_init_record (dsahip); + ds_record (dsahip, 1); + } + return 0; } - } - if ((flags & AHISF_RECORD) && !dsahip->recording) { - dsahip->recording = 1; - ds_init_record (dsahip); - ds_record (dsahip, 1); - } - return 0; -} - -static uae_u32 AHIsub_Stop (TrapContext *ctx) -{ - uae_u32 flags = m68k_dreg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - int i; - - if (ahi_debug) - write_log (L"AHI: Stop(%08x,%08x)\n", - flags, audioctrl); - if ((flags & AHISF_PLAY) && dsahip->playing) { - dsahip->playing = 0; - for (i = 0; i < dsahip->channels; i++) { - struct dschannel *dc = &dsahip->channel[i]; - ds_stop (dsahip, dc); + + static uae_u32 AHIsub_Stop (TrapContext *ctx) + { + uae_u32 flags = m68k_dreg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + int i; + + if (ahi_debug) + write_log (L"AHI: Stop(%08x,%08x)\n", + flags, audioctrl); + if ((flags & AHISF_PLAY) && dsahip->playing) { + dsahip->playing = 0; + for (i = 0; i < dsahip->channels; i++) { + struct dschannel *dc = &dsahip->channel[i]; + ds_stop (dsahip, dc); + } + } + if ((flags & AHISF_RECORD) && dsahip->recording) { + dsahip->recording = 0; + ds_record (dsahip, 0); + ds_free_record (dsahip); + } + return 0; } - } - if ((flags & AHISF_RECORD) && dsahip->recording) { - dsahip->recording = 0; - ds_record (dsahip, 0); - ds_free_record (dsahip); - } - return 0; -} - -static uae_u32 AHIsub_Update (TrapContext *ctx) -{ - uae_u32 flags = m68k_dreg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - if (ahi_debug) - write_log (L"AHI: Update(%08x,%08x)\n", flags, audioctrl); - setevent (dsahip); - return 0; -} - -static uae_u32 AHIsub_SetVol (TrapContext *ctx) -{ - uae_u16 channel = m68k_dreg (regs, 0); - uae_s32 volume = m68k_dreg (regs, 1); - uae_s32 pan = m68k_dreg (regs, 2); - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 flags = m68k_dreg (regs, 3); - struct DSAHI *dsahip = GETAHI; - struct dschannel *dc = GETCHANNEL; - - if (ahi_debug > 1) - write_log (L"AHI: SetVol(%d,%d,%d,%08x,%08x)\n", - channel, volume, pan, audioctrl, flags); - if (dc) { - if (volume < -65535) - volume = -65535; - if (volume > 65535) - volume = 65535; - if (pan < -65535) - pan = -65535; - if (pan > 65535) - pan = 65535; - dc->csnext.volume = volume; - dc->csnext.panning = pan; - if (flags & AHISF_IMM) { - ds_setvolume (dsahip, dc); + + static uae_u32 AHIsub_Update (TrapContext *ctx) + { + uae_u32 flags = m68k_dreg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log (L"AHI: Update(%08x,%08x)\n", flags, audioctrl); + setevent (dsahip); + return 0; } - } - return 0; -} -static uae_u32 AHIsub_SetFreq (TrapContext *ctx) -{ - uae_u16 channel = m68k_dreg (regs, 0); - uae_u32 frequency = m68k_dreg (regs, 1); - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 flags = m68k_dreg (regs, 3); - struct DSAHI *dsahip = GETAHI; - struct dschannel *dc = GETCHANNEL; - - if (ahi_debug > 1) - write_log (L"AHI: SetFreq(%d,%d,%08x,%08x)\n", - channel, frequency, audioctrl, flags); - if (dc) { - dc->csnext.frequency = frequency; - if (flags & AHISF_IMM) { - ds_setfreq (dsahip, dc); - ds_play (dsahip, dc); + static uae_u32 AHIsub_SetVol (TrapContext *ctx) + { + uae_u16 channel = m68k_dreg (regs, 0); + uae_s32 volume = m68k_dreg (regs, 1); + uae_s32 pan = m68k_dreg (regs, 2); + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 flags = m68k_dreg (regs, 3); + struct DSAHI *dsahip = GETAHI; + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug > 1) + write_log (L"AHI: SetVol(%d,%d,%d,%08x,%08x)\n", + channel, volume, pan, audioctrl, flags); + if (dc) { + if (volume < -65535) + volume = -65535; + if (volume > 65535) + volume = 65535; + if (pan < -65535) + pan = -65535; + if (pan > 65535) + pan = 65535; + dc->csnext.volume = volume; + dc->csnext.panning = pan; + if (flags & AHISF_IMM) { + ds_setvolume (dsahip, dc); + } + } + return 0; } - } - return 0; -} -static uae_u32 AHIsub_SetSound (TrapContext *ctx) -{ - uae_u16 channel = m68k_dreg (regs, 0); - uae_u16 sound = m68k_dreg (regs, 1); - uae_u32 offset = m68k_dreg (regs, 2); - uae_u32 length = m68k_dreg (regs, 3); - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 flags = m68k_dreg (regs, 4); - struct DSAHI *dsahip = GETAHI; - struct dssample *ds = GETSAMPLE; - struct dschannel *dc = GETCHANNEL; - - if (ahi_debug > 1) - write_log (L"AHI: SetSound(%d,%d,%08x,%d,%08x,%08x)\n", - channel, sound, offset, length, audioctrl, flags); - if (dc == NULL) - return AHIE_UNKNOWN; - if (sound == 0xffff) { - if (flags & AHISF_IMM) { - dc->cs.ds = NULL; - dc->csnext.ds = NULL; + static uae_u32 AHIsub_SetFreq (TrapContext *ctx) + { + uae_u16 channel = m68k_dreg (regs, 0); + uae_u32 frequency = m68k_dreg (regs, 1); + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 flags = m68k_dreg (regs, 3); + struct DSAHI *dsahip = GETAHI; + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug > 1) + write_log (L"AHI: SetFreq(%d,%d,%08x,%08x)\n", + channel, frequency, audioctrl, flags); + if (dc) { + dc->csnext.frequency = frequency; + if (flags & AHISF_IMM) { + ds_setfreq (dsahip, dc); + ds_play (dsahip, dc); + } + } + return 0; + } + + static uae_u32 AHIsub_SetSound (TrapContext *ctx) + { + uae_u16 channel = m68k_dreg (regs, 0); + uae_u16 sound = m68k_dreg (regs, 1); + uae_u32 offset = m68k_dreg (regs, 2); + uae_u32 length = m68k_dreg (regs, 3); + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 flags = m68k_dreg (regs, 4); + struct DSAHI *dsahip = GETAHI; + struct dssample *ds = GETSAMPLE; + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug > 1) + write_log (L"AHI: SetSound(%d,%d,%08x,%d,%08x,%08x)\n", + channel, sound, offset, length, audioctrl, flags); + if (dc == NULL) + return AHIE_UNKNOWN; + if (sound == 0xffff) { + if (flags & AHISF_IMM) { + dc->cs.ds = NULL; + dc->csnext.ds = NULL; + } + return 0; + } + if (ds == NULL || ds->num < 0) + return AHIE_UNKNOWN; + ds_allocchannel (dsahip, dc); + dc->cs.backwards = length < 0; + length = abs (length); + if (length == 0) + length = ds->len; + if (length > ds->len) + length = ds->len; + dc->csnext.ds = ds; + dc->csnext.srcplaylen = length; + dc->csnext.srcplayoffset = offset; + if (flags & AHISF_IMM) + dc->cs.ds = NULL; + ds_setfreq (dsahip, dc); + ds_setvolume (dsahip, dc); + if (dc->cs.ds == NULL) + al_initsample (dsahip, dc); + return 0; + } + + static uae_u32 AHIsub_SetEffect (TrapContext *ctx) + { + uae_u32 effect = m68k_areg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + uae_u32 effectype = get_long (effect); + uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); + struct DSAHI *dsahip = GETAHI; + + if (ahi_debug) + write_log (L"AHI: SetEffect(%08x (%08x),%08x)\n", effect, effectype, audioctrl); + switch (effectype) + { + case AHIET_CHANNELINFO: + put_long (puaebase + pub_ChannelInfo, effect); + break; + case AHIET_CHANNELINFO | AHIET_CANCEL: + put_long (puaebase + pub_ChannelInfo, 0); + break; + case AHIET_MASTERVOLUME: + write_log (L"AHI: SetEffect(MasterVolume=%08x)\n", get_long (effect + 4)); + case AHIET_MASTERVOLUME | AHIET_CANCEL: + break; + default: + return AHIE_UNKNOWN; + } + return AHIE_OK; + } + + static uae_u32 AHIsub_LoadSound (TrapContext *ctx) + { + uae_u16 sound = m68k_dreg (regs, 0); + uae_u32 type = m68k_dreg (regs, 1); + uae_u32 info = m68k_areg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + uae_u32 ret = AHIE_BADSOUNDTYPE; + int sampletype = get_long (info + ahisi_Type); + uae_u32 addr = get_long (info + ahisi_Address); + uae_u32 len = get_long (info + ahisi_Length); + struct dssample *ds = GETSAMPLE; + int ch; + int bps; + + if (ahi_debug > 1) + write_log (L"AHI: LoadSound(%d,%d,%08x,%08x,SMP=%d,ADDR=%08x,LEN=%d)\n", + sound, type, info, audioctrl, sampletype, addr, len); + + if (!ds) + return AHIE_BADSOUNDTYPE; + + ds->num = sound; + if (!cansurround && sampletype == AHIST_L7_1) + return AHIE_BADSOUNDTYPE; + ds->addr = addr; + ds->sampletype = sampletype; + ds->type = type; + ds->len = len; + ds->dynamic = type == AHIST_DYNAMICSAMPLE; + + switch (sampletype) + { + case AHIST_M8S: + case AHIST_M16S: + case AHIST_M32S: + ch = 1; + break; + case AHIST_S8S: + case AHIST_S16S: + case AHIST_S32S: + ch = 2; + break; + case AHIST_L7_1: + ch = 8; + break; + default: + return 0; + } + switch (sampletype) + { + case AHIST_M8S: + case AHIST_S8S: + bps = 8; + break; + case AHIST_M16S: + case AHIST_S16S: + bps = 16; + break; + case AHIST_M32S: + case AHIST_S32S: + case AHIST_L7_1: + bps = 24; + break; + default: + return 0; + } + ds->bitspersample = bps; + ds->ch = ch; + ds->bytespersample = bps / 8; + if (ds->al_buffer[0] == -1) { + alClear (); + alGenBuffers (2, ds->al_buffer); + if (alError (L"AHI: alGenBuffers")) + return AHIE_NOMEM; + if (ahi_debug > 1) + write_log (L"AHI:LoadSound:allocated OpenAL buffer\n"); + } + return AHIE_OK; + } + + static uae_u32 AHIsub_UnloadSound (TrapContext *ctx) + { + uae_u16 sound = m68k_dreg (regs, 0); + uae_u32 audioctrl = m68k_areg (regs, 2); + struct DSAHI *dsahip = GETAHI; + struct dssample *ds = GETSAMPLE; + + if (ahi_debug > 1) + write_log (L"AHI: UnloadSound(%d,%08x)\n", + sound, audioctrl); + ds->num = -1; + return AHIE_OK; + } + + static uae_u32 REGPARAM2 ahi_demux (TrapContext *ctx) + { + uae_u32 ret = 0; + uae_u32 sp = m68k_areg (regs, 7); + uae_u32 offset = get_long (sp + 4); + + if (0 && ahi_debug) + write_log (L"AHI: %d\n", offset); + + switch (offset) + { + case 0xffffffff: + ret = init (ctx); + break; + case 0: + ret = AHIsub_AllocAudio (ctx); + break; + case 1: + AHIsub_FreeAudio (ctx); + break; + case 2: + AHIsub_Disable (ctx); + break; + case 3: + AHIsub_Enable (ctx); + break; + case 4: + ret = AHIsub_Start (ctx); + break; + case 5: + ret = AHIsub_Update (ctx); + break; + case 6: + ret = AHIsub_Stop (ctx); + break; + case 7: + ret = AHIsub_SetVol (ctx); + break; + case 8: + ret = AHIsub_SetFreq (ctx); + break; + case 9: + ret = AHIsub_SetSound (ctx); + break; + case 10: + ret = AHIsub_SetEffect (ctx); + break; + case 11: + ret = AHIsub_LoadSound (ctx); + break; + case 12: + ret = AHIsub_UnloadSound (ctx); + break; + case 13: + ret = AHIsub_GetAttr (ctx); + break; + case 14: + ret = AHIsub_HardwareControl (ctx); + break; + } + return ret; + } + + void init_ahi_v2 (void) + { + uaecptr a = here (); + org (rtarea_base + 0xFFC8); + calltrap (deftrapres (ahi_demux, 0, L"ahi_v2")); + dw (RTS); + org (a); + } + + void free_ahi_v2 (void) + { + ds_free_record (&dsahi[0]); + ds_free (&dsahi[0]); } - return 0; - } - if (ds == NULL || ds->num < 0) - return AHIE_UNKNOWN; - ds_allocchannel (dsahip, dc); - dc->cs.backwards = length < 0; - length = abs (length); - if (length == 0) - length = ds->len; - if (length > ds->len) - length = ds->len; - dc->csnext.ds = ds; - dc->csnext.srcplaylen = length; - dc->csnext.srcplayoffset = offset; - if (flags & AHISF_IMM) - dc->cs.ds = NULL; - ds_setfreq (dsahip, dc); - ds_setvolume (dsahip, dc); - if (dc->cs.ds == NULL) - al_initsample (dsahip, dc); - return 0; -} - -static uae_u32 AHIsub_SetEffect (TrapContext *ctx) -{ - uae_u32 effect = m68k_areg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - uae_u32 effectype = get_long (effect); - uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); - struct DSAHI *dsahip = GETAHI; - - if (ahi_debug) - write_log (L"AHI: SetEffect(%08x (%08x),%08x)\n", effect, effectype, audioctrl); - switch (effectype) - { - case AHIET_CHANNELINFO: - put_long (puaebase + pub_ChannelInfo, effect); - break; - case AHIET_CHANNELINFO | AHIET_CANCEL: - put_long (puaebase + pub_ChannelInfo, 0); - break; - case AHIET_MASTERVOLUME: - write_log (L"AHI: SetEffect(MasterVolume=%08x)\n", get_long (effect + 4)); - case AHIET_MASTERVOLUME | AHIET_CANCEL: - break; - default: - return AHIE_UNKNOWN; - } - return AHIE_OK; -} - -static uae_u32 AHIsub_LoadSound (TrapContext *ctx) -{ - uae_u16 sound = m68k_dreg (regs, 0); - uae_u32 type = m68k_dreg (regs, 1); - uae_u32 info = m68k_areg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - uae_u32 ret = AHIE_BADSOUNDTYPE; - int sampletype = get_long (info + ahisi_Type); - uae_u32 addr = get_long (info + ahisi_Address); - uae_u32 len = get_long (info + ahisi_Length); - struct dssample *ds = GETSAMPLE; - int ch; - int bps; - - if (ahi_debug > 1) - write_log (L"AHI: LoadSound(%d,%d,%08x,%08x,SMP=%d,ADDR=%08x,LEN=%d)\n", - sound, type, info, audioctrl, sampletype, addr, len); - - if (!ds) - return AHIE_BADSOUNDTYPE; - - ds->num = sound; - if (!cansurround && sampletype == AHIST_L7_1) - return AHIE_BADSOUNDTYPE; - ds->addr = addr; - ds->sampletype = sampletype; - ds->type = type; - ds->len = len; - ds->dynamic = type == AHIST_DYNAMICSAMPLE; - - switch (sampletype) - { - case AHIST_M8S: - case AHIST_M16S: - case AHIST_M32S: - ch = 1; - break; - case AHIST_S8S: - case AHIST_S16S: - case AHIST_S32S: - ch = 2; - break; - case AHIST_L7_1: - ch = 8; - break; - default: - return 0; - } - switch (sampletype) - { - case AHIST_M8S: - case AHIST_S8S: - bps = 8; - break; - case AHIST_M16S: - case AHIST_S16S: - bps = 16; - break; - case AHIST_M32S: - case AHIST_S32S: - case AHIST_L7_1: - bps = 24; - break; - default: - return 0; - } - ds->bitspersample = bps; - ds->ch = ch; - ds->bytespersample = bps / 8; - if (ds->al_buffer[0] == -1) { - alClear (); - alGenBuffers (2, ds->al_buffer); - if (alError (L"AHI: alGenBuffers")) - return AHIE_NOMEM; - if (ahi_debug > 1) - write_log (L"AHI:LoadSound:allocated OpenAL buffer\n"); - } - return AHIE_OK; -} - -static uae_u32 AHIsub_UnloadSound (TrapContext *ctx) -{ - uae_u16 sound = m68k_dreg (regs, 0); - uae_u32 audioctrl = m68k_areg (regs, 2); - struct DSAHI *dsahip = GETAHI; - struct dssample *ds = GETSAMPLE; - - if (ahi_debug > 1) - write_log (L"AHI: UnloadSound(%d,%08x)\n", - sound, audioctrl); - ds->num = -1; - return AHIE_OK; -} - -static uae_u32 REGPARAM2 ahi_demux (TrapContext *ctx) -{ - uae_u32 ret = 0; - uae_u32 sp = m68k_areg (regs, 7); - uae_u32 offset = get_long (sp + 4); - - if (0 && ahi_debug) - write_log (L"AHI: %d\n", offset); - - switch (offset) - { - case 0xffffffff: - ret = init (ctx); - break; - case 0: - ret = AHIsub_AllocAudio (ctx); - break; - case 1: - AHIsub_FreeAudio (ctx); - break; - case 2: - AHIsub_Disable (ctx); - break; - case 3: - AHIsub_Enable (ctx); - break; - case 4: - ret = AHIsub_Start (ctx); - break; - case 5: - ret = AHIsub_Update (ctx); - break; - case 6: - ret = AHIsub_Stop (ctx); - break; - case 7: - ret = AHIsub_SetVol (ctx); - break; - case 8: - ret = AHIsub_SetFreq (ctx); - break; - case 9: - ret = AHIsub_SetSound (ctx); - break; - case 10: - ret = AHIsub_SetEffect (ctx); - break; - case 11: - ret = AHIsub_LoadSound (ctx); - break; - case 12: - ret = AHIsub_UnloadSound (ctx); - break; - case 13: - ret = AHIsub_GetAttr (ctx); - break; - case 14: - ret = AHIsub_HardwareControl (ctx); - break; - } - return ret; -} - -void init_ahi_v2 (void) -{ - uaecptr a = here (); - org (rtarea_base + 0xFFC8); - calltrap (deftrapres (ahi_demux, 0, L"ahi_v2")); - dw (RTS); - org (a); -} - -void free_ahi_v2 (void) -{ - ds_free_record (&dsahi[0]); - ds_free (&dsahi[0]); -} #endif diff --git a/od-win32/avioutput.c b/od-win32/avioutput.c index a8d64e69..7364930d 100644 --- a/od-win32/avioutput.c +++ b/od-win32/avioutput.c @@ -1,10 +1,10 @@ /* - UAE - The Ultimate Amiga Emulator +UAE - The Ultimate Amiga Emulator - avioutput.c +avioutput.c - Copyright(c) 2001 - 2002; §ane - 2005-2006; Toni Wilen +Copyright(c) 2001 - 2002; §ane +2005-2006; Toni Wilen */ @@ -79,10 +79,10 @@ static PAVIFILE pfile = NULL; // handle of our AVI file static PAVISTREAM AVIStreamInterface = NULL; // Address of stream interface struct avientry { - uae_u8 *lpVideo; - LPBITMAPINFOHEADER lpbi; - uae_u8 *lpAudio; - int sndsize; + uae_u8 *lpVideo; + LPBITMAPINFOHEADER lpbi; + uae_u8 *lpAudio; + int sndsize; }; #define AVIENTRY_MAX 10 @@ -110,699 +110,719 @@ static AVICOMPRESSOPTIONS FAR * aOptions[] = { &videoOptions }; // array of poin static LPBITMAPINFOHEADER lpbi; static PCOMPVARS pcompvars; + +void avi_message (const TCHAR *format,...) +{ + TCHAR msg[MAX_DPATH]; + va_list parms; + DWORD flags = MB_OK | MB_TASKMODAL; + + va_start (parms, format); + _vsntprintf (msg, sizeof msg / sizeof (TCHAR), format, parms); + va_end (parms); + + write_log (msg); + if (msg[_tcslen (msg) - 1] != '\n') + write_log (L"\n"); + + if (!MessageBox (NULL, msg, L"AVI", flags)) + write_log (L"MessageBox(%s) failed, err=%d\n", msg, GetLastError ()); +} + static int lpbisize (void) { - return sizeof(BITMAPINFOHEADER) + (((avioutput_bits <= 8) ? 1 << avioutput_bits : 0) * sizeof(RGBQUAD)); + return sizeof (BITMAPINFOHEADER) + (((avioutput_bits <= 8) ? 1 << avioutput_bits : 0) * sizeof (RGBQUAD)); } static void freeavientry (struct avientry *ae) { - if (!ae) - return; - xfree (ae->lpAudio); - xfree (ae->lpVideo); - xfree (ae->lpbi); - xfree (ae); + if (!ae) + return; + xfree (ae->lpAudio); + xfree (ae->lpVideo); + xfree (ae->lpbi); + xfree (ae); } static struct avientry *allocavientry_audio (uae_u8 *snd, int size) { - struct avientry *ae = xcalloc (sizeof (struct avientry), 1); - ae->lpAudio = xmalloc (size); - memcpy (ae->lpAudio, snd, size); - ae->sndsize = size; - return ae; + struct avientry *ae = xcalloc (sizeof (struct avientry), 1); + ae->lpAudio = xmalloc (size); + memcpy (ae->lpAudio, snd, size); + ae->sndsize = size; + return ae; } static struct avientry *allocavientry_video (void) { - struct avientry *ae = xcalloc (sizeof (struct avientry), 1); - ae->lpbi = xmalloc (lpbisize ()); - memcpy (ae->lpbi, lpbi, lpbisize ()); - ae->lpVideo = calloc (lpbi->biSizeImage, 1); - return ae; + struct avientry *ae = xcalloc (sizeof (struct avientry), 1); + ae->lpbi = xmalloc (lpbisize ()); + memcpy (ae->lpbi, lpbi, lpbisize ()); + ae->lpVideo = calloc (lpbi->biSizeImage, 1); + return ae; } static void queueavientry (struct avientry *ae) { - EnterCriticalSection (&AVIOutput_CriticalSection); - avientries[++avientryindex] = ae; - LeaveCriticalSection (&AVIOutput_CriticalSection); - write_comm_pipe_u32 (&workindex, 0, 1); + EnterCriticalSection (&AVIOutput_CriticalSection); + avientries[++avientryindex] = ae; + LeaveCriticalSection (&AVIOutput_CriticalSection); + write_comm_pipe_u32 (&workindex, 0, 1); } static struct avientry *getavientry (void) { - int i; - struct avientry *ae; - if (avientryindex < 0) - return NULL; - ae = avientries[0]; - for (i = 0; i < avientryindex; i++) - avientries[i] = avientries[i + 1]; - avientryindex--; - return ae; + int i; + struct avientry *ae; + if (avientryindex < 0) + return NULL; + ae = avientries[0]; + for (i = 0; i < avientryindex; i++) + avientries[i] = avientries[i + 1]; + avientryindex--; + return ae; } static void freequeue (void) { - struct avientry *ae; - while ((ae = getavientry ())) - freeavientry (ae); + struct avientry *ae; + while ((ae = getavientry ())) + freeavientry (ae); } static void waitqueuefull (void) { - for (;;) { - EnterCriticalSection (&AVIOutput_CriticalSection); - if (avientryindex < AVIENTRY_MAX) { - LeaveCriticalSection (&AVIOutput_CriticalSection); - while (comm_pipe_has_data (&queuefull)) + for (;;) { + EnterCriticalSection (&AVIOutput_CriticalSection); + if (avientryindex < AVIENTRY_MAX) { + LeaveCriticalSection (&AVIOutput_CriticalSection); + while (comm_pipe_has_data (&queuefull)) + read_comm_pipe_u32_blocking (&queuefull); + return; + } + LeaveCriticalSection (&AVIOutput_CriticalSection); read_comm_pipe_u32_blocking (&queuefull); - return; } - LeaveCriticalSection (&AVIOutput_CriticalSection); - read_comm_pipe_u32_blocking (&queuefull); - } } static UAEREG *openavikey (void) { - return regcreatetree (NULL, L"AVConfiguration"); + return regcreatetree (NULL, L"AVConfiguration"); } static void storesettings (UAEREG *avikey) { - regsetint (avikey, L"FrameLimiter", avioutput_framelimiter); - regsetint (avikey, L"NoSoundOutput", avioutput_nosoundoutput); - regsetint (avikey, L"FPS", avioutput_fps); + regsetint (avikey, L"FrameLimiter", avioutput_framelimiter); + regsetint (avikey, L"NoSoundOutput", avioutput_nosoundoutput); + regsetint (avikey, L"FPS", avioutput_fps); } static void getsettings (UAEREG *avikey) { - DWORD val; - if (regqueryint (avikey, L"NoSoundOutput", &val)) - avioutput_nosoundoutput = val; - if (regqueryint (avikey, L"FrameLimiter", &val)) - avioutput_framelimiter = val; - if (!avioutput_framelimiter) - avioutput_nosoundoutput = 1; - if (regqueryint (avikey, L"FPS", &val)) - avioutput_fps = val; + DWORD val; + if (regqueryint (avikey, L"NoSoundOutput", &val)) + avioutput_nosoundoutput = val; + if (regqueryint (avikey, L"FrameLimiter", &val)) + avioutput_framelimiter = val; + if (!avioutput_framelimiter) + avioutput_nosoundoutput = 1; + if (regqueryint (avikey, L"FPS", &val)) + avioutput_fps = val; } void AVIOutput_GetSettings (void) { - UAEREG *avikey = openavikey (); - if (avikey) - getsettings (avikey); - regclosetree (avikey); + UAEREG *avikey = openavikey (); + if (avikey) + getsettings (avikey); + regclosetree (avikey); } void AVIOutput_SetSettings (void) { - UAEREG *avikey = openavikey (); - if (avikey) - storesettings (avikey); - regclosetree (avikey); + UAEREG *avikey = openavikey (); + if (avikey) + storesettings (avikey); + regclosetree (avikey); } void AVIOutput_ReleaseAudio (void) { - if (pwfxDst) { - xfree (pwfxDst); - pwfxDst = NULL; - } + if (pwfxDst) { + xfree (pwfxDst); + pwfxDst = NULL; + } } static int AVIOutput_AudioAllocated (void) { - return pwfxDst ? 1 : 0; + return pwfxDst ? 1 : 0; } -const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010, - {0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}; +const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}; static int AVIOutput_AllocateAudio (void) { - MMRESULT err; + MMRESULT err; - AVIOutput_ReleaseAudio (); + AVIOutput_ReleaseAudio (); - if ((err = acmMetrics (NULL, ACM_METRIC_MAX_SIZE_FORMAT, &wfxMaxFmtSize))) { - gui_message (L"acmMetrics() FAILED (%X)\n", err); - return 0; - } - - // set the source format - memset (&wfxSrc, 0, sizeof (wfxSrc)); - wfxSrc.Format.wFormatTag = WAVE_FORMAT_PCM; - wfxSrc.Format.nChannels = get_audio_nativechannels (currprefs.sound_stereo) ? get_audio_nativechannels (currprefs.sound_stereo) : 2; - wfxSrc.Format.nSamplesPerSec = workprefs.sound_freq ? workprefs.sound_freq : 44100; - wfxSrc.Format.nBlockAlign = wfxSrc.Format.nChannels * 16 / 8; - wfxSrc.Format.nAvgBytesPerSec = wfxSrc.Format.nBlockAlign * wfxSrc.Format.nSamplesPerSec; - wfxSrc.Format.wBitsPerSample = 16; - wfxSrc.Format.cbSize = 0; - - if (wfxSrc.Format.nChannels > 2) { - wfxSrc.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); - wfxSrc.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - wfxSrc.Samples.wValidBitsPerSample = 16; - switch (wfxSrc.Format.nChannels) - { - case 4: - wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_SURROUND; - break; - case 6: - wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_5POINT1_SURROUND; - break; - case 8: - wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_7POINT1_SURROUND; - break; + if ((err = acmMetrics (NULL, ACM_METRIC_MAX_SIZE_FORMAT, &wfxMaxFmtSize))) { + gui_message (L"acmMetrics() FAILED (%X)\n", err); + return 0; } - } - if (!(pwfxDst = (LPWAVEFORMATEX) xmalloc (wfxMaxFmtSize))) - return 0; + // set the source format + memset (&wfxSrc, 0, sizeof (wfxSrc)); + wfxSrc.Format.wFormatTag = WAVE_FORMAT_PCM; + wfxSrc.Format.nChannels = get_audio_nativechannels (currprefs.sound_stereo) ? get_audio_nativechannels (currprefs.sound_stereo) : 2; + wfxSrc.Format.nSamplesPerSec = workprefs.sound_freq ? workprefs.sound_freq : 44100; + wfxSrc.Format.nBlockAlign = wfxSrc.Format.nChannels * 16 / 8; + wfxSrc.Format.nAvgBytesPerSec = wfxSrc.Format.nBlockAlign * wfxSrc.Format.nSamplesPerSec; + wfxSrc.Format.wBitsPerSample = 16; + wfxSrc.Format.cbSize = 0; + + if (wfxSrc.Format.nChannels > 2) { + wfxSrc.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); + wfxSrc.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + wfxSrc.Samples.wValidBitsPerSample = 16; + switch (wfxSrc.Format.nChannels) + { + case 4: + wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_SURROUND; + break; + case 6: + wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_5POINT1_SURROUND; + break; + case 8: + wfxSrc.dwChannelMask = KSAUDIO_SPEAKER_7POINT1_SURROUND; + break; + } + } + + if (!(pwfxDst = (LPWAVEFORMATEX) xmalloc (wfxMaxFmtSize))) + return 0; - // set the initial destination format to match source - memset (pwfxDst, 0, wfxMaxFmtSize); - memcpy (pwfxDst, &wfxSrc, sizeof (WAVEFORMATEX)); - pwfxDst->cbSize = (WORD) (wfxMaxFmtSize - sizeof (WAVEFORMATEX)); // shrugs + // set the initial destination format to match source + memset (pwfxDst, 0, wfxMaxFmtSize); + memcpy (pwfxDst, &wfxSrc, sizeof (WAVEFORMATEX)); + pwfxDst->cbSize = (WORD) (wfxMaxFmtSize - sizeof (WAVEFORMATEX)); // shrugs - memset(&acmopt, 0, sizeof (ACMFORMATCHOOSE)); - acmopt.cbStruct = sizeof (ACMFORMATCHOOSE); - acmopt.fdwStyle = ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT; - acmopt.pwfx = pwfxDst; - acmopt.cbwfx = wfxMaxFmtSize; - acmopt.pszTitle = L"Choose Audio Codec"; + memset(&acmopt, 0, sizeof (ACMFORMATCHOOSE)); + acmopt.cbStruct = sizeof (ACMFORMATCHOOSE); + acmopt.fdwStyle = ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT; + acmopt.pwfx = pwfxDst; + acmopt.cbwfx = wfxMaxFmtSize; + acmopt.pszTitle = L"Choose Audio Codec"; - //acmopt.szFormatTag =; // not valid until the format is chosen - //acmopt.szFormat =; // not valid until the format is chosen + //acmopt.szFormatTag =; // not valid until the format is chosen + //acmopt.szFormat =; // not valid until the format is chosen - //acmopt.pszName =; // can use later in config saving loading - //acmopt.cchName =; // size of pszName, as pszName can be non-null-terminated + //acmopt.pszName =; // can use later in config saving loading + //acmopt.cchName =; // size of pszName, as pszName can be non-null-terminated - acmopt.fdwEnum = ACM_FORMATENUMF_INPUT | ACM_FORMATENUMF_NCHANNELS | - ACM_FORMATENUMF_NSAMPLESPERSEC; - //ACM_FORMATENUMF_CONVERT // renders WinUAE unstable for some unknown reason - //ACM_FORMATENUMF_WBITSPERSAMPLE // MP3 doesn't apply so it will be removed from codec selection - //ACM_FORMATENUMF_SUGGEST // with this flag set, only MP3 320kbps is displayed, which is closest to the source format + acmopt.fdwEnum = ACM_FORMATENUMF_INPUT | ACM_FORMATENUMF_NCHANNELS | + ACM_FORMATENUMF_NSAMPLESPERSEC; + //ACM_FORMATENUMF_CONVERT // renders WinUAE unstable for some unknown reason + //ACM_FORMATENUMF_WBITSPERSAMPLE // MP3 doesn't apply so it will be removed from codec selection + //ACM_FORMATENUMF_SUGGEST // with this flag set, only MP3 320kbps is displayed, which is closest to the source format - acmopt.pwfxEnum = &wfxSrc.Format; - return 1; + acmopt.pwfxEnum = &wfxSrc.Format; + return 1; } static int AVIOutput_ValidateAudio (WAVEFORMATEX *wft, TCHAR *name, int len) { - DWORD ret; - ACMFORMATTAGDETAILS aftd; - ACMFORMATDETAILS afd; - - memset(&aftd, 0, sizeof (ACMFORMATTAGDETAILS)); - aftd.cbStruct = sizeof (ACMFORMATTAGDETAILS); - aftd.dwFormatTag = wft->wFormatTag; - ret = acmFormatTagDetails (NULL, &aftd, ACM_FORMATTAGDETAILSF_FORMATTAG); - if (ret) - return 0; - - memset (&afd, 0, sizeof (ACMFORMATDETAILS)); - afd.cbStruct = sizeof (ACMFORMATDETAILS); - afd.dwFormatTag = wft->wFormatTag; - afd.pwfx = wft; - afd.cbwfx = sizeof (WAVEFORMATEX) + wft->cbSize; - ret = acmFormatDetails (NULL, &afd, ACM_FORMATDETAILSF_FORMAT); - if (ret) - return 0; - - if (name) - _stprintf (name, L"%s %s", aftd.szFormatTag, afd.szFormat); - return 1; + DWORD ret; + ACMFORMATTAGDETAILS aftd; + ACMFORMATDETAILS afd; + + memset(&aftd, 0, sizeof (ACMFORMATTAGDETAILS)); + aftd.cbStruct = sizeof (ACMFORMATTAGDETAILS); + aftd.dwFormatTag = wft->wFormatTag; + ret = acmFormatTagDetails (NULL, &aftd, ACM_FORMATTAGDETAILSF_FORMATTAG); + if (ret) + return 0; + + memset (&afd, 0, sizeof (ACMFORMATDETAILS)); + afd.cbStruct = sizeof (ACMFORMATDETAILS); + afd.dwFormatTag = wft->wFormatTag; + afd.pwfx = wft; + afd.cbwfx = sizeof (WAVEFORMATEX) + wft->cbSize; + ret = acmFormatDetails (NULL, &afd, ACM_FORMATDETAILSF_FORMAT); + if (ret) + return 0; + + if (name) + _stprintf (name, L"%s %s", aftd.szFormatTag, afd.szFormat); + return 1; } static int AVIOutput_GetAudioFromRegistry (WAVEFORMATEX *wft) { - DWORD ss; - int ok = 0; - UAEREG *avikey; + DWORD ss; + int ok = 0; + UAEREG *avikey; - avikey = openavikey (); - if (!avikey) - return 0; - getsettings (avikey); - if (wft) { - ss = wfxMaxFmtSize; - if (regquerydata (avikey, L"AudioConfigurationVars", wft, &ss)) { - if (AVIOutput_ValidateAudio (wft, NULL, 0)) - ok = 1; + avikey = openavikey (); + if (!avikey) + return 0; + getsettings (avikey); + if (wft) { + ss = wfxMaxFmtSize; + if (regquerydata (avikey, L"AudioConfigurationVars", wft, &ss)) { + if (AVIOutput_ValidateAudio (wft, NULL, 0)) + ok = 1; + } } - } - if (!ok) - regdelete (avikey, L"AudioConfigurationVars"); - regclosetree (avikey); - return ok; + if (!ok) + regdelete (avikey, L"AudioConfigurationVars"); + regclosetree (avikey); + return ok; } static int AVIOutput_GetAudioCodecName (WAVEFORMATEX *wft, TCHAR *name, int len) { - return AVIOutput_ValidateAudio (wft, name, len); + return AVIOutput_ValidateAudio (wft, name, len); } int AVIOutput_GetAudioCodec (TCHAR *name, int len) { - AVIOutput_Initialize (); - if (AVIOutput_AudioAllocated ()) - return AVIOutput_GetAudioCodecName (pwfxDst, name, len); - if (!AVIOutput_AllocateAudio ()) + AVIOutput_Initialize (); + if (AVIOutput_AudioAllocated ()) + return AVIOutput_GetAudioCodecName (pwfxDst, name, len); + if (!AVIOutput_AllocateAudio ()) + return 0; + if (AVIOutput_GetAudioFromRegistry (pwfxDst)) { + AVIOutput_GetAudioCodecName (pwfxDst, name, len); + return 1; + } + AVIOutput_ReleaseAudio (); return 0; - if (AVIOutput_GetAudioFromRegistry (pwfxDst)) { - AVIOutput_GetAudioCodecName (pwfxDst, name, len); - return 1; - } - AVIOutput_ReleaseAudio (); - return 0; } int AVIOutput_ChooseAudioCodec (HWND hwnd, TCHAR *s, int len) { - AVIOutput_Initialize (); - AVIOutput_End(); - if (!AVIOutput_AllocateAudio ()) - return 0; + AVIOutput_Initialize (); + AVIOutput_End(); + if (!AVIOutput_AllocateAudio ()) + return 0; - acmopt.hwndOwner = hwnd; + acmopt.hwndOwner = hwnd; - switch (acmFormatChoose (&acmopt)) - { - case MMSYSERR_NOERROR: + switch (acmFormatChoose (&acmopt)) { - UAEREG *avikey; - _tcscpy (s, acmopt.szFormatTag); - avikey = openavikey (); - if (avikey) { - regsetdata (avikey, L"AudioConfigurationVars", pwfxDst, pwfxDst->cbSize + sizeof (WAVEFORMATEX)); - storesettings (avikey); - regclosetree (avikey); - } - return 1; - } + case MMSYSERR_NOERROR: + { + UAEREG *avikey; + _tcscpy (s, acmopt.szFormatTag); + avikey = openavikey (); + if (avikey) { + regsetdata (avikey, L"AudioConfigurationVars", pwfxDst, pwfxDst->cbSize + sizeof (WAVEFORMATEX)); + storesettings (avikey); + regclosetree (avikey); + } + return 1; + } case ACMERR_CANCELED: - AVIOutput_GetAudioFromRegistry (NULL); - AVIOutput_ReleaseAudio(); - break; + AVIOutput_GetAudioFromRegistry (NULL); + AVIOutput_ReleaseAudio(); + break; case ACMERR_NOTPOSSIBLE: - MessageBox (hwnd, L"The buffer identified by the pwfx member of the ACMFORMATCHOOSE structure is too small to contain the selected format.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; + MessageBox (hwnd, L"The buffer identified by the pwfx member of the ACMFORMATCHOOSE structure is too small to contain the selected format.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; case MMSYSERR_INVALFLAG: - MessageBox (hwnd, L"At least one flag is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; + MessageBox (hwnd, L"At least one flag is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; case MMSYSERR_INVALHANDLE: - MessageBox (hwnd, L"The specified handle is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; + MessageBox (hwnd, L"The specified handle is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; case MMSYSERR_INVALPARAM: - MessageBox (hwnd, L"At least one parameter is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; + MessageBox (hwnd, L"At least one parameter is invalid.", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; case MMSYSERR_NODRIVER: - MessageBox (hwnd, L"A suitable driver is not available to provide valid format selections.\n(Unsupported channel-mode selected in Sound-panel?)", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; + MessageBox (hwnd, L"A suitable driver is not available to provide valid format selections.\n(Unsupported channel-mode selected in Sound-panel?)", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; default: - MessageBox (hwnd, L"acmFormatChoose() FAILED", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - break; - } - return 0; + MessageBox (hwnd, L"acmFormatChoose() FAILED", VersionStr, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + break; + } + return 0; } static int AVIOutput_VideoAllocated(void) { - return videoallocated ? 1 : 0; + return videoallocated ? 1 : 0; } void AVIOutput_ReleaseVideo (void) { - videoallocated = 0; - freequeue (); - xfree (lpbi); - lpbi = NULL; + videoallocated = 0; + freequeue (); + xfree (lpbi); + lpbi = NULL; } static int AVIOutput_AllocateVideo (void) { - avioutput_width = WIN32GFX_GetWidth (); - avioutput_height = WIN32GFX_GetHeight (); - avioutput_bits = WIN32GFX_GetDepth (0); - - AVIOutput_Initialize (); - AVIOutput_ReleaseVideo (); - if (!avioutput_width || !avioutput_height || !avioutput_bits) { - avioutput_width = workprefs.gfx_size.width; - avioutput_height = workprefs.gfx_size.height; - avioutput_bits = 24; - } - lpbi = xcalloc (lpbisize (), 1); - lpbi->biSize = sizeof(BITMAPINFOHEADER); - lpbi->biWidth = avioutput_width; - lpbi->biHeight = avioutput_height; - lpbi->biPlanes = 1; - lpbi->biBitCount = avioutput_bits; - lpbi->biCompression = BI_RGB; // uncompressed format - lpbi->biSizeImage = (lpbi->biWidth * lpbi->biHeight) * (lpbi->biBitCount / 8); - lpbi->biXPelsPerMeter = 0; // ?? - lpbi->biYPelsPerMeter = 0; // ?? - lpbi->biClrUsed = (lpbi->biBitCount <= 8) ? 1 << lpbi->biBitCount : 0; - lpbi->biClrImportant = 0; - - videoallocated = 1; - return 1; + avioutput_width = WIN32GFX_GetWidth (); + avioutput_height = WIN32GFX_GetHeight (); + avioutput_bits = WIN32GFX_GetDepth (0); + + AVIOutput_Initialize (); + AVIOutput_ReleaseVideo (); + if (!avioutput_width || !avioutput_height || !avioutput_bits) { + avioutput_width = workprefs.gfx_size.width; + avioutput_height = workprefs.gfx_size.height; + avioutput_bits = 24; + } + if (avioutput_bits > 24) + avioutput_bits = 24; + lpbi = xcalloc (lpbisize (), 1); + lpbi->biSize = sizeof(BITMAPINFOHEADER); + lpbi->biWidth = avioutput_width; + lpbi->biHeight = avioutput_height; + lpbi->biPlanes = 1; + lpbi->biBitCount = avioutput_bits; + lpbi->biCompression = BI_RGB; // uncompressed format + lpbi->biSizeImage = (lpbi->biWidth * lpbi->biHeight) * (lpbi->biBitCount / 8); + lpbi->biXPelsPerMeter = 0; // ?? + lpbi->biYPelsPerMeter = 0; // ?? + lpbi->biClrUsed = (lpbi->biBitCount <= 8) ? 1 << lpbi->biBitCount : 0; + lpbi->biClrImportant = 0; + + videoallocated = 1; + return 1; } static int compressorallocated; static void AVIOutput_FreeCOMPVARS (COMPVARS *pcv) { - ICClose(pcv->hic); - if (compressorallocated) - ICCompressorFree(pcv); - compressorallocated = FALSE; - pcv->hic = NULL; + ICClose(pcv->hic); + if (compressorallocated) + ICCompressorFree(pcv); + compressorallocated = FALSE; + pcv->hic = NULL; } static int AVIOutput_GetCOMPVARSFromRegistry (COMPVARS *pcv) { - UAEREG *avikey; - DWORD ss; - int ok = 0; + UAEREG *avikey; + DWORD ss; + int ok = 0; - avikey = openavikey (); - if (!avikey) - return 0; - getsettings (avikey); - if (pcv) { - ss = pcv->cbSize; - pcv->hic = 0; - if (regquerydata (avikey, L"VideoConfigurationVars", pcv, &ss)) { - pcv->hic = 0; - pcv->lpbiIn = pcv->lpbiOut = 0; - pcv->cbState = 0; - if (regquerydatasize (avikey, L"VideoConfigurationState", &ss)) { - if (ss > 0) { - LPBYTE state = xmalloc (ss); - if (regquerydata (avikey, L"VideoConfigurationState", state, &ss)) { - pcv->hic = ICOpen (pcv->fccType, pcv->fccHandler, ICMODE_COMPRESS); - if (pcv->hic) { - ok = 1; - ICSetState (pcv->hic, state, ss); + avikey = openavikey (); + if (!avikey) + return 0; + getsettings (avikey); + if (pcv) { + ss = pcv->cbSize; + pcv->hic = 0; + if (regquerydata (avikey, L"VideoConfigurationVars", pcv, &ss)) { + pcv->hic = 0; + pcv->lpbiIn = pcv->lpbiOut = 0; + pcv->cbState = 0; + if (regquerydatasize (avikey, L"VideoConfigurationState", &ss)) { + if (ss > 0) { + LPBYTE state = xmalloc (ss); + if (regquerydata (avikey, L"VideoConfigurationState", state, &ss)) { + pcv->hic = ICOpen (pcv->fccType, pcv->fccHandler, ICMODE_COMPRESS); + if (pcv->hic) { + ok = 1; + ICSetState (pcv->hic, state, ss); + } + } + xfree (state); + } else { + ok = 1; + } } - } - xfree (state); - } else { - ok = 1; } - } } - } - if (!ok) { - regdelete (avikey, L"VideoConfigurationVars"); - regdelete (avikey, L"VideoConfigurationState"); - } - regclosetree (avikey); - return ok; + if (!ok) { + regdelete (avikey, L"VideoConfigurationVars"); + regdelete (avikey, L"VideoConfigurationState"); + } + regclosetree (avikey); + return ok; } static int AVIOutput_GetVideoCodecName (COMPVARS *pcv, TCHAR *name, int len) { - ICINFO icinfo = { 0 }; + ICINFO icinfo = { 0 }; - name[0] = 0; - if (pcv->fccHandler == mmioFOURCC ('D','I','B',' ')) { - _tcscpy (name, L"Full Frames (Uncompressed)"); - return 1; - } - if (ICGetInfo (pcv->hic, &icinfo, sizeof (ICINFO)) != 0) { - _tcsncpy (name, icinfo.szDescription, len); - return 1; - } - return 0; + name[0] = 0; + if (pcv->fccHandler == mmioFOURCC ('D','I','B',' ')) { + _tcscpy (name, L"Full Frames (Uncompressed)"); + return 1; + } + if (ICGetInfo (pcv->hic, &icinfo, sizeof (ICINFO)) != 0) { + _tcsncpy (name, icinfo.szDescription, len); + return 1; + } + return 0; } int AVIOutput_GetVideoCodec (TCHAR *name, int len) { - AVIOutput_Initialize (); + AVIOutput_Initialize (); - if (AVIOutput_VideoAllocated ()) - return AVIOutput_GetVideoCodecName (pcompvars, name, len); - if (!AVIOutput_AllocateVideo ()) + if (AVIOutput_VideoAllocated ()) + return AVIOutput_GetVideoCodecName (pcompvars, name, len); + if (!AVIOutput_AllocateVideo ()) + return 0; + AVIOutput_FreeCOMPVARS (pcompvars); + if (AVIOutput_GetCOMPVARSFromRegistry (pcompvars)) { + AVIOutput_GetVideoCodecName (pcompvars, name, len); + return 1; + } + AVIOutput_ReleaseVideo (); return 0; - AVIOutput_FreeCOMPVARS (pcompvars); - if (AVIOutput_GetCOMPVARSFromRegistry (pcompvars)) { - AVIOutput_GetVideoCodecName (pcompvars, name, len); - return 1; - } - AVIOutput_ReleaseVideo (); - return 0; } int AVIOutput_ChooseVideoCodec (HWND hwnd, TCHAR *s, int len) { - AVIOutput_Initialize (); + AVIOutput_Initialize (); - AVIOutput_End (); - if (!AVIOutput_AllocateVideo ()) - return 0; - AVIOutput_FreeCOMPVARS (pcompvars); + AVIOutput_End (); + if (!AVIOutput_AllocateVideo ()) + return 0; + AVIOutput_FreeCOMPVARS (pcompvars); - // we really should check first to see if the user has a particular compressor installed before we set one - // we could set one but we will leave it up to the operating system and the set priority levels for the compressors + // we really should check first to see if the user has a particular compressor installed before we set one + // we could set one but we will leave it up to the operating system and the set priority levels for the compressors - // default - //pcompvars->fccHandler = mmioFOURCC('C','V','I','D'); // "Cinepak Codec by Radius" - //pcompvars->fccHandler = mmioFOURCC('M','R','L','E'); // "Microsoft RLE" - //pcompvars->fccHandler = mmioFOURCC('D','I','B',' '); // "Full Frames (Uncompressed)" + // default + //pcompvars->fccHandler = mmioFOURCC('C','V','I','D'); // "Cinepak Codec by Radius" + //pcompvars->fccHandler = mmioFOURCC('M','R','L','E'); // "Microsoft RLE" + //pcompvars->fccHandler = mmioFOURCC('D','I','B',' '); // "Full Frames (Uncompressed)" - pcompvars->lQ = 10000; // 10000 is maximum quality setting or ICQUALITY_DEFAULT for default - pcompvars->lKey = avioutput_fps; // default to one key frame per second, every (FPS) frames - pcompvars->dwFlags = 0; - if (ICCompressorChoose (hwnd, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, lpbi, NULL, pcompvars, "Choose Video Codec") == TRUE) { - UAEREG *avikey; - int ss; - uae_u8 *state; - - compressorallocated = TRUE; - ss = ICGetState (pcompvars->hic, NULL, 0); - if (ss > 0) { - DWORD err; - state = xmalloc (ss); - err = ICGetState (pcompvars->hic, state, ss); - if (err < 0) { - ss = 0; + pcompvars->lQ = 10000; // 10000 is maximum quality setting or ICQUALITY_DEFAULT for default + pcompvars->lKey = avioutput_fps; // default to one key frame per second, every (FPS) frames + pcompvars->dwFlags = 0; + if (ICCompressorChoose (hwnd, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, lpbi, NULL, pcompvars, "Choose Video Codec") == TRUE) { + UAEREG *avikey; + int ss; + uae_u8 *state; + + compressorallocated = TRUE; + ss = ICGetState (pcompvars->hic, NULL, 0); + if (ss > 0) { + DWORD err; + state = xmalloc (ss); + err = ICGetState (pcompvars->hic, state, ss); + if (err < 0) { + ss = 0; + xfree (state); + } + } else { + ss = 0; + } + if (ss == 0) + state = xmalloc (1); + avikey = openavikey (); + if (avikey) { + regsetdata (avikey, L"VideoConfigurationState", state, ss); + regsetdata (avikey, L"VideoConfigurationVars", pcompvars, pcompvars->cbSize); + storesettings (avikey); + regclosetree (avikey); + } xfree (state); - } + return AVIOutput_GetVideoCodecName (pcompvars, s, len); } else { - ss = 0; + AVIOutput_GetCOMPVARSFromRegistry (NULL); + AVIOutput_ReleaseVideo (); + return 0; } - if (ss == 0) - state = xmalloc (1); - avikey = openavikey (); - if (avikey) { - regsetdata (avikey, L"VideoConfigurationState", state, ss); - regsetdata (avikey, L"VideoConfigurationVars", pcompvars, pcompvars->cbSize); - storesettings (avikey); - regclosetree (avikey); - } - xfree (state); - return AVIOutput_GetVideoCodecName (pcompvars, s, len); - } else { - AVIOutput_GetCOMPVARSFromRegistry (NULL); - AVIOutput_ReleaseVideo (); - return 0; - } } static void checkAVIsize (int force) { - int tmp_partcnt = partcnt + 1; - int tmp_avioutput_video = avioutput_video; - int tmp_avioutput_audio = avioutput_audio; - TCHAR fn[MAX_DPATH]; - - if (!force && total_avi_size < MAX_AVI_SIZE) - return; - if (total_avi_size == 0) - return; - _tcscpy (fn, avioutput_filename_tmp); - _stprintf (avioutput_filename, L"%s_%d.avi", fn, tmp_partcnt); - write_log (L"AVI split %d at %d bytes, %d frames\n", - tmp_partcnt, total_avi_size, frame_count); - AVIOutput_End (); - first_frame = 0; - total_avi_size = 0; - avioutput_video = tmp_avioutput_video; - avioutput_audio = tmp_avioutput_audio; - AVIOutput_Begin (); - _tcscpy (avioutput_filename_tmp, fn); - partcnt = tmp_partcnt; + int tmp_partcnt = partcnt + 1; + int tmp_avioutput_video = avioutput_video; + int tmp_avioutput_audio = avioutput_audio; + TCHAR fn[MAX_DPATH]; + + if (!force && total_avi_size < MAX_AVI_SIZE) + return; + if (total_avi_size == 0) + return; + _tcscpy (fn, avioutput_filename_tmp); + _stprintf (avioutput_filename, L"%s_%d.avi", fn, tmp_partcnt); + write_log (L"AVI split %d at %d bytes, %d frames\n", + tmp_partcnt, total_avi_size, frame_count); + AVIOutput_End (); + first_frame = 0; + total_avi_size = 0; + avioutput_video = tmp_avioutput_video; + avioutput_audio = tmp_avioutput_audio; + AVIOutput_Begin (); + _tcscpy (avioutput_filename_tmp, fn); + partcnt = tmp_partcnt; } static void dorestart (void) { - write_log (L"AVIOutput: parameters changed, restarting..\n"); - avioutput_needs_restart = 0; - checkAVIsize (1); + write_log (L"AVIOutput: parameters changed, restarting..\n"); + avioutput_needs_restart = 0; + checkAVIsize (1); } static void AVIOuput_AVIWriteAudio (uae_u8 *sndbuffer, int sndbufsize) { - struct avientry *ae; - - if (avioutput_failed) { - AVIOutput_End (); - return; - } - checkAVIsize (0); - if (avioutput_needs_restart) - dorestart (); - waitqueuefull (); - ae = allocavientry_audio (sndbuffer, sndbufsize); - queueavientry (ae); + struct avientry *ae; + + if (avioutput_failed) { + AVIOutput_End (); + return; + } + checkAVIsize (0); + if (avioutput_needs_restart) + dorestart (); + waitqueuefull (); + ae = allocavientry_audio (sndbuffer, sndbufsize); + queueavientry (ae); } static int AVIOutput_AVIWriteAudio_Thread (struct avientry *ae) { - DWORD dwOutputBytes = 0, written = 0, swritten = 0; - unsigned int err; - uae_u8 *lpAudio = NULL; + DWORD dwOutputBytes = 0, written = 0, swritten = 0; + unsigned int err; + uae_u8 *lpAudio = NULL; - if (avioutput_audio) { - if (!avioutput_init) - goto error; + if (avioutput_audio) { + if (!avioutput_init) + goto error; - if ((err = acmStreamSize (has, ae->sndsize, &dwOutputBytes, ACM_STREAMSIZEF_SOURCE) != 0)) { - gui_message (L"acmStreamSize() FAILED (%X)\n", err); - goto error; - } + if ((err = acmStreamSize (has, ae->sndsize, &dwOutputBytes, ACM_STREAMSIZEF_SOURCE) != 0)) { + gui_message (L"acmStreamSize() FAILED (%X)\n", err); + goto error; + } - if (!(lpAudio = xmalloc (dwOutputBytes))) - goto error; + if (!(lpAudio = xmalloc (dwOutputBytes))) + goto error; - ash.cbStruct = sizeof (ACMSTREAMHEADER); - ash.fdwStatus = 0; - ash.dwUser = 0; + ash.cbStruct = sizeof (ACMSTREAMHEADER); + ash.fdwStatus = 0; + ash.dwUser = 0; - // source - ash.pbSrc = ae->lpAudio; + // source + ash.pbSrc = ae->lpAudio; - ash.cbSrcLength = ae->sndsize; - ash.cbSrcLengthUsed = 0; // This member is not valid until the conversion is complete. + ash.cbSrcLength = ae->sndsize; + ash.cbSrcLengthUsed = 0; // This member is not valid until the conversion is complete. - ash.dwSrcUser = 0; + ash.dwSrcUser = 0; - // destination - ash.pbDst = lpAudio; + // destination + ash.pbDst = lpAudio; - ash.cbDstLength = dwOutputBytes; - ash.cbDstLengthUsed = 0; // This member is not valid until the conversion is complete. + ash.cbDstLength = dwOutputBytes; + ash.cbDstLengthUsed = 0; // This member is not valid until the conversion is complete. - ash.dwDstUser = 0; + ash.dwDstUser = 0; - if ((err = acmStreamPrepareHeader (has, &ash, 0))) { - gui_message (L"acmStreamPrepareHeader() FAILED (%X)\n", err); - goto error; - } + if ((err = acmStreamPrepareHeader (has, &ash, 0))) { + avi_message (L"acmStreamPrepareHeader() FAILED (%X)\n", err); + goto error; + } - if ((err = acmStreamConvert (has, &ash, ACM_STREAMCONVERTF_BLOCKALIGN))) { - gui_message (L"acmStreamConvert() FAILED (%X)\n", err); - goto error; - } + if ((err = acmStreamConvert (has, &ash, ACM_STREAMCONVERTF_BLOCKALIGN))) { + avi_message (L"acmStreamConvert() FAILED (%X)\n", err); + goto error; + } - if ((err = AVIStreamWrite (AVIAudioStream, StreamSizeAudio, ash.cbDstLengthUsed / pwfxDst->nBlockAlign, lpAudio, ash.cbDstLengthUsed, 0, &swritten, &written)) != 0) { - gui_message (L"AVIStreamWrite() FAILED (%X)\n", err); - goto error; - } + if ((err = AVIStreamWrite (AVIAudioStream, StreamSizeAudio, ash.cbDstLengthUsed / pwfxDst->nBlockAlign, lpAudio, ash.cbDstLengthUsed, 0, &swritten, &written)) != 0) { + avi_message (L"AVIStreamWrite() FAILED (%X)\n", err); + goto error; + } - StreamSizeAudio += swritten; - total_avi_size += written; + StreamSizeAudio += swritten; + total_avi_size += written; - acmStreamUnprepareHeader (has, &ash, 0); + acmStreamUnprepareHeader (has, &ash, 0); - free(lpAudio); - lpAudio = NULL; - } + free(lpAudio); + lpAudio = NULL; + } - return 1; + return 1; error: - xfree (lpAudio); - return 0; + xfree (lpAudio); + return 0; } static void AVIOuput_WAVWriteAudio (uae_u8 *sndbuffer, int sndbufsize) { - fwrite (sndbuffer, 1, sndbufsize, wavfile); + fwrite (sndbuffer, 1, sndbufsize, wavfile); } static int skipsample; void AVIOutput_WriteAudio (uae_u8 *sndbuffer, int sndbufsize) { - int size = sndbufsize; + int size = sndbufsize; - if (!avioutput_audio || !avioutput_enabled) - return; - if (skipsample > 0 && size > wfxSrc.Format.nBlockAlign) { - size -= wfxSrc.Format.nBlockAlign; - skipsample--; - } - if (avioutput_audio == AVIAUDIO_WAV) - AVIOuput_WAVWriteAudio (sndbuffer, size); - else - AVIOuput_AVIWriteAudio (sndbuffer, size); + if (!avioutput_audio || !avioutput_enabled) + return; + if (skipsample > 0 && size > wfxSrc.Format.nBlockAlign) { + size -= wfxSrc.Format.nBlockAlign; + skipsample--; + } + if (avioutput_audio == AVIAUDIO_WAV) + AVIOuput_WAVWriteAudio (sndbuffer, size); + else + AVIOuput_AVIWriteAudio (sndbuffer, size); } static int getFromDC (struct avientry *avie) { - HDC hdc; - HBITMAP hbitmap = NULL; - HBITMAP hbitmapOld = NULL; - HDC hdcMem = NULL; - int ok = 1; - - hdc = gethdc (); - if (!hdc) - return 0; - // create a memory device context compatible with the application's current screen - hdcMem = CreateCompatibleDC (hdc); - hbitmap = CreateCompatibleBitmap (hdc, avioutput_width, avioutput_height); - hbitmapOld = SelectObject (hdcMem, hbitmap); - // probably not the best idea to use slow GDI functions for this, - // locking the surfaces and copying them by hand would be more efficient perhaps - // draw centered in frame - BitBlt (hdcMem, (avioutput_width / 2) - (actual_width / 2), (avioutput_height / 2) - (actual_height / 2), actual_width, actual_height, hdc, 0, 0, SRCCOPY); - SelectObject (hdcMem, hbitmapOld); - if (GetDIBits (hdc, hbitmap, 0, avioutput_height, avie->lpVideo, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0) { - gui_message (L"GetDIBits() FAILED (%X)\n", GetLastError()); - ok = 0; - } - DeleteObject (hbitmap); - DeleteDC (hdcMem); - releasehdc (hdc); - return ok; + HDC hdc; + HBITMAP hbitmap = NULL; + HBITMAP hbitmapOld = NULL; + HDC hdcMem = NULL; + int ok = 1; + + hdc = gethdc (); + if (!hdc) + return 0; + // create a memory device context compatible with the application's current screen + hdcMem = CreateCompatibleDC (hdc); + hbitmap = CreateCompatibleBitmap (hdc, avioutput_width, avioutput_height); + hbitmapOld = SelectObject (hdcMem, hbitmap); + // probably not the best idea to use slow GDI functions for this, + // locking the surfaces and copying them by hand would be more efficient perhaps + // draw centered in frame + BitBlt (hdcMem, (avioutput_width / 2) - (actual_width / 2), (avioutput_height / 2) - (actual_height / 2), actual_width, actual_height, hdc, 0, 0, SRCCOPY); + SelectObject (hdcMem, hbitmapOld); + if (GetDIBits (hdc, hbitmap, 0, avioutput_height, avie->lpVideo, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0) { + gui_message (L"GetDIBits() FAILED (%X)\n", GetLastError ()); + ok = 0; + } + DeleteObject (hbitmap); + DeleteDC (hdcMem); + releasehdc (hdc); + return ok; } static int rgb_type; void AVIOutput_RGBinfo (int rb, int gb, int bb, int rs, int gs, int bs) { - if (bs == 0 && gs == 5 && rs == 11) - rgb_type = 1; - else if (bs == 0 && gs == 8 && rs == 16) - rgb_type = 2; - else - rgb_type = 0; + if (bs == 0 && gs == 5 && rs == 11) + rgb_type = 1; + else if (bs == 0 && gs == 8 && rs == 16) + rgb_type = 2; + else + rgb_type = 0; } #if defined (GFXFILTER) @@ -810,470 +830,474 @@ extern uae_u8 *bufmem_ptr; static int getFromBuffer (struct avientry *ae) { - int x, y; - uae_u8 *src; - uae_u8 *dst = ae->lpVideo; - - src = bufmem_ptr; - if (!src) - return 0; - dst += avioutput_width * avioutput_bits / 8 * avioutput_height; - for (y = 0; y < (gfxvidinfo.height > avioutput_height ? avioutput_height : gfxvidinfo.height); y++) { - uae_u8 *d; - dst -= avioutput_width * avioutput_bits / 8; - d = dst; - for (x = 0; x < (gfxvidinfo.width > avioutput_width ? avioutput_width : gfxvidinfo.width); x++) { - if (avioutput_bits == 8) { - *d++ = src[x]; - } else if (avioutput_bits == 16) { - uae_u16 v = ((uae_u16*)src)[x]; - uae_u16 v2 = v; - if (rgb_type) { - v2 = v & 31; - v2 |= (v >> 1) & (31 << 5); - v2 |= (v >> 1) & (31 << 10); + int x, y; + uae_u8 *src; + uae_u8 *dst = ae->lpVideo; + + src = bufmem_ptr; + if (!src) + return 0; + dst += avioutput_width * avioutput_bits / 8 * avioutput_height; + for (y = 0; y < (gfxvidinfo.height > avioutput_height ? avioutput_height : gfxvidinfo.height); y++) { + uae_u8 *d; + dst -= avioutput_width * avioutput_bits / 8; + d = dst; + for (x = 0; x < (gfxvidinfo.width > avioutput_width ? avioutput_width : gfxvidinfo.width); x++) { + if (avioutput_bits == 8) { + *d++ = src[x]; + } else if (avioutput_bits == 16) { + uae_u16 v = ((uae_u16*)src)[x]; + uae_u16 v2 = v; + if (rgb_type) { + v2 = v & 31; + v2 |= (v >> 1) & (31 << 5); + v2 |= (v >> 1) & (31 << 10); + } + ((uae_u16*)d)[0] = v2; + d += 2; + } else if (avioutput_bits == 32) { + uae_u32 v = ((uae_u32*)src)[x]; + ((uae_u32*)d)[0] = v; + d += 4; + } else if (avioutput_bits == 24) { + uae_u32 v = ((uae_u32*)src)[x]; + *d++ = v; + *d++ = v >> 8; + *d++ = v >> 16; + } } - ((uae_u16*)d)[0] = v2; - d += 2; - } else if (avioutput_bits == 32) { - uae_u32 v = ((uae_u32*)src)[x]; - ((uae_u32*)d)[0] = v; - d += 4; - } else if (avioutput_bits == 24) { - uae_u32 v = ((uae_u32*)src)[x]; - *d++ = v; - *d++ = v >> 8; - *d++ = v >> 16; - } + src += gfxvidinfo.rowbytes; } - src += gfxvidinfo.rowbytes; - } - return 1; + return 1; } #endif void AVIOutput_WriteVideo (void) { - struct avientry *ae; - int v; + struct avientry *ae; + int v; - if (avioutput_failed) { - AVIOutput_End (); - return; - } + if (avioutput_failed) { + AVIOutput_End (); + return; + } - checkAVIsize (0); - if (avioutput_needs_restart) - dorestart (); - waitqueuefull (); - ae = allocavientry_video (); + checkAVIsize (0); + if (avioutput_needs_restart) + dorestart (); + waitqueuefull (); + ae = allocavientry_video (); #if defined (GFXFILTER) - if (!usedfilter || (usedfilter && usedfilter->x[0]) || WIN32GFX_IsPicassoScreen ()) - v = getFromDC (ae); - else - v = getFromBuffer (ae); + if (!usedfilter || (usedfilter && usedfilter->x[0]) || WIN32GFX_IsPicassoScreen ()) + v = getFromDC (ae); + else + v = getFromBuffer (ae); #else - v = getFromDC (avie); + v = getFromDC (avie); #endif - if (v) - queueavientry (ae); - else - AVIOutput_End (); + if (v) + queueavientry (ae); + else + AVIOutput_End (); } static int AVIOutput_AVIWriteVideo_Thread (struct avientry *ae) { - DWORD written = 0; - unsigned int err; + DWORD written = 0; + unsigned int err; - if (avioutput_video) { + if (avioutput_video) { - if (!avioutput_init) - goto error; + if (!avioutput_init) + goto error; - actual_width = gfxvidinfo.width; - actual_height = gfxvidinfo.height; + actual_width = gfxvidinfo.width; + actual_height = gfxvidinfo.height; - // GetDIBits tends to change this and ruins palettized output - ae->lpbi->biClrUsed = (avioutput_bits <= 8) ? 1 << avioutput_bits : 0; + // GetDIBits tends to change this and ruins palettized output + ae->lpbi->biClrUsed = (avioutput_bits <= 8) ? 1 << avioutput_bits : 0; - if (!frame_count) { - if ((err = AVIStreamSetFormat (AVIVideoStream, frame_count, ae->lpbi, ae->lpbi->biSize + (ae->lpbi->biClrUsed * sizeof (RGBQUAD)))) != 0) { - gui_message (L"AVIStreamSetFormat() FAILED (%X)\n", err); - goto error; - } - } + if (!frame_count) { + if ((err = AVIStreamSetFormat (AVIVideoStream, frame_count, ae->lpbi, ae->lpbi->biSize + (ae->lpbi->biClrUsed * sizeof (RGBQUAD)))) != 0) { + avi_message (L"AVIStreamSetFormat() FAILED (%X)\n", err); + goto error; + } + } - if ((err = AVIStreamWrite (AVIVideoStream, frame_count, 1, ae->lpVideo, ae->lpbi->biSizeImage, 0, NULL, &written)) != 0) { - gui_message (L"AVIStreamWrite() FAILED (%X)\n", err); - goto error; - } + if ((err = AVIStreamWrite (AVIVideoStream, frame_count, 1, ae->lpVideo, ae->lpbi->biSizeImage, 0, NULL, &written)) != 0) { + avi_message (L"AVIStreamWrite() FAILED (%X)\n", err); + goto error; + } - frame_count++; - total_avi_size += written; + frame_count++; + total_avi_size += written; - } else { + } else { - gui_message (L"DirectDraw_GetDC() FAILED\n"); - goto error; + avi_message (L"DirectDraw_GetDC() FAILED\n"); + goto error; - } + } - if ((frame_count % (avioutput_fps * 10)) == 0) - write_log (L"AVIOutput: %d frames, (%d fps)\n", frame_count, avioutput_fps); - return 1; + if ((frame_count % (avioutput_fps * 10)) == 0) + write_log (L"AVIOutput: %d frames, (%d fps)\n", frame_count, avioutput_fps); + return 1; error: - return 0; + return 0; } static void writewavheader (uae_u32 size) { - uae_u16 tw; - uae_u32 tl; - int bits = 16; - int channels = get_audio_nativechannels (currprefs.sound_stereo); - - fseek (wavfile, 0, SEEK_SET); - fwrite ("RIFF", 1, 4, wavfile); - tl = 0; - if (size) - tl = size - 8; - fwrite (&tl, 1, 4, wavfile); - fwrite ("WAVEfmt ", 1, 8, wavfile); - tl = 16; - fwrite (&tl, 1, 4, wavfile); - tw = 1; - fwrite (&tw, 1, 2, wavfile); - tw = channels; - fwrite (&tw, 1, 2, wavfile); - tl = currprefs.sound_freq; - fwrite (&tl, 1, 4, wavfile); - tl = currprefs.sound_freq * channels * bits / 8; - fwrite (&tl, 1, 4, wavfile); - tw = channels * bits / 8; - fwrite (&tw, 1, 2, wavfile); - tw = bits; - fwrite (&tw, 1, 2, wavfile); - fwrite ("data", 1, 4, wavfile); - tl = 0; - if (size) - tl = size - 44; - fwrite (&tl, 1, 4, wavfile); + uae_u16 tw; + uae_u32 tl; + int bits = 16; + int channels = get_audio_nativechannels (currprefs.sound_stereo); + + fseek (wavfile, 0, SEEK_SET); + fwrite ("RIFF", 1, 4, wavfile); + tl = 0; + if (size) + tl = size - 8; + fwrite (&tl, 1, 4, wavfile); + fwrite ("WAVEfmt ", 1, 8, wavfile); + tl = 16; + fwrite (&tl, 1, 4, wavfile); + tw = 1; + fwrite (&tw, 1, 2, wavfile); + tw = channels; + fwrite (&tw, 1, 2, wavfile); + tl = currprefs.sound_freq; + fwrite (&tl, 1, 4, wavfile); + tl = currprefs.sound_freq * channels * bits / 8; + fwrite (&tl, 1, 4, wavfile); + tw = channels * bits / 8; + fwrite (&tw, 1, 2, wavfile); + tw = bits; + fwrite (&tw, 1, 2, wavfile); + fwrite ("data", 1, 4, wavfile); + tl = 0; + if (size) + tl = size - 44; + fwrite (&tl, 1, 4, wavfile); } void AVIOutput_Restart (void) { - avioutput_needs_restart = 1; + if (first_frame) + return; + avioutput_needs_restart = 1; } void AVIOutput_End (void) { - first_frame = 1; - avioutput_failed = 0; - avioutput_enabled = 0; - - if (alive) { - write_log (L"killing worker thread\n"); - write_comm_pipe_u32 (&workindex, 0xfffffffe, 1); - while (alive) { - while (comm_pipe_has_data (&queuefull)) - read_comm_pipe_u32_blocking (&queuefull); - Sleep (10); + first_frame = 1; + avioutput_enabled = 0; + + if (alive) { + write_log (L"killing worker thread\n"); + write_comm_pipe_u32 (&workindex, 0xfffffffe, 1); + while (alive) { + while (comm_pipe_has_data (&queuefull)) + read_comm_pipe_u32_blocking (&queuefull); + Sleep (10); + } + } + avioutput_failed = 0; + freequeue (); + destroy_comm_pipe (&workindex); + destroy_comm_pipe (&queuefull); + if (has) { + acmStreamUnprepareHeader (has, &ash, 0); + acmStreamClose (has, 0); + has = NULL; + } + + if (AVIAudioStream) { + AVIStreamRelease (AVIAudioStream); + AVIAudioStream = NULL; + } + + if (AVIVideoStream) { + AVIStreamRelease (AVIVideoStream); + AVIVideoStream = NULL; + } + + if (AVIStreamInterface) { + AVIStreamRelease (AVIStreamInterface); + AVIStreamInterface = NULL; + } + + if (pfile) { + AVIFileRelease (pfile); + pfile = NULL; + } + + StreamSizeAudio = frame_count = 0; + StreamSizeAudioExpected = 0; + partcnt = 0; + + if (wavfile) { + writewavheader (ftell (wavfile)); + fclose (wavfile); + wavfile = 0; } - } - freequeue (); - destroy_comm_pipe (&workindex); - destroy_comm_pipe (&queuefull); - if (has) { - acmStreamUnprepareHeader (has, &ash, 0); - acmStreamClose (has, 0); - has = NULL; - } - - if (AVIAudioStream) { - AVIStreamRelease (AVIAudioStream); - AVIAudioStream = NULL; - } - - if (AVIVideoStream) { - AVIStreamRelease (AVIVideoStream); - AVIVideoStream = NULL; - } - - if (AVIStreamInterface) { - AVIStreamRelease (AVIStreamInterface); - AVIStreamInterface = NULL; - } - - if (pfile) { - AVIFileRelease (pfile); - pfile = NULL; - } - - StreamSizeAudio = frame_count = 0; - StreamSizeAudioExpected = 0; - partcnt = 0; - - if (wavfile) { - writewavheader (ftell (wavfile)); - fclose (wavfile); - wavfile = 0; - } } static void *AVIOutput_worker (void *arg); void AVIOutput_Begin (void) { - AVISTREAMINFO avistreaminfo; // Structure containing information about the stream, including the stream type and its sample rate - int i, err; - TCHAR *ext1, *ext2; - struct avientry *ae = NULL; - - AVIOutput_Initialize (); - - avientryindex = -1; - if (avioutput_enabled) { + AVISTREAMINFO avistreaminfo; // Structure containing information about the stream, including the stream type and its sample rate + int i, err; + TCHAR *ext1, *ext2; + struct avientry *ae = NULL; + + AVIOutput_Initialize (); + + avientryindex = -1; + if (avioutput_enabled) { + if (!avioutput_requested) + AVIOutput_End (); + return; + } if (!avioutput_requested) - AVIOutput_End (); - return; - } - if (!avioutput_requested) - return; + return; + + changed_prefs.sound_auto = currprefs.sound_auto = 0; + reset_sound (); - changed_prefs.sound_auto = currprefs.sound_auto = 0; - reset_sound (); - - if (avioutput_audio == AVIAUDIO_WAV) { - ext1 = L".wav"; ext2 = L".avi"; - } else { - ext1 = L".avi"; ext2 = L".wav"; - } - if (_tcslen (avioutput_filename) >= 4 && !_tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, ext2)) - avioutput_filename[_tcslen (avioutput_filename) - 4] = 0; - if (_tcslen (avioutput_filename) >= 4 && _tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, ext1)) - _tcscat (avioutput_filename, ext1); - _tcscpy (avioutput_filename_tmp, avioutput_filename); - i = _tcslen (avioutput_filename_tmp) - 1; - while (i > 0 && avioutput_filename_tmp[i] != '.') i--; - if (i > 0) - avioutput_filename_tmp[i] = 0; - - avioutput_needs_restart = 0; - avioutput_enabled = avioutput_audio || avioutput_video; - if (!avioutput_init || !avioutput_enabled) - goto error; - - // delete any existing file before writing AVI - SetFileAttributes (avioutput_filename, FILE_ATTRIBUTE_ARCHIVE); - DeleteFile (avioutput_filename); - - if (avioutput_audio == AVIAUDIO_WAV) { - wavfile = _tfopen (avioutput_filename, L"wb"); - if (!wavfile) { - gui_message (L"Failed to open wave-file\n\nThis can happen if the path and or file name was entered incorrectly.\n"); - goto error; + if (avioutput_audio == AVIAUDIO_WAV) { + ext1 = L".wav"; ext2 = L".avi"; + } else { + ext1 = L".avi"; ext2 = L".wav"; } - writewavheader (0); - write_log (L"wave-output to '%s' started\n", avioutput_filename); - return; - } + if (_tcslen (avioutput_filename) >= 4 && !_tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, ext2)) + avioutput_filename[_tcslen (avioutput_filename) - 4] = 0; + if (_tcslen (avioutput_filename) >= 4 && _tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, ext1)) + _tcscat (avioutput_filename, ext1); + _tcscpy (avioutput_filename_tmp, avioutput_filename); + i = _tcslen (avioutput_filename_tmp) - 1; + while (i > 0 && avioutput_filename_tmp[i] != '.') i--; + if (i > 0) + avioutput_filename_tmp[i] = 0; + + avioutput_needs_restart = 0; + avioutput_enabled = avioutput_audio || avioutput_video; + if (!avioutput_init || !avioutput_enabled) + goto error; - if (((err = AVIFileOpen (&pfile, avioutput_filename, OF_CREATE | OF_WRITE, NULL)) != 0)) { - gui_message (L"AVIFileOpen() FAILED (Error %X)\n\nThis can happen if the path and or file name was entered incorrectly.\nRequired *.avi extension.\n", err); - goto error; - } + // delete any existing file before writing AVI + SetFileAttributes (avioutput_filename, FILE_ATTRIBUTE_ARCHIVE); + DeleteFile (avioutput_filename); - if (avioutput_audio) { - if (!AVIOutput_AllocateAudio ()) - goto error; - memset (&avistreaminfo, 0, sizeof (AVISTREAMINFO)); - avistreaminfo.fccType = streamtypeAUDIO; - avistreaminfo.fccHandler = 0; // This member is not used for audio streams. - avistreaminfo.dwFlags = 0; - //avistreaminfo.dwCaps =; // Capability flags; currently unused. - //avistreaminfo.wPriority =; - //avistreaminfo.wLanguage =; - avistreaminfo.dwScale = pwfxDst->nBlockAlign; - avistreaminfo.dwRate = pwfxDst->nAvgBytesPerSec; - avistreaminfo.dwStart = 0; - avistreaminfo.dwLength = -1; - avistreaminfo.dwInitialFrames = 0; - avistreaminfo.dwSuggestedBufferSize = 0; // Use zero if you do not know the correct buffer size. - avistreaminfo.dwQuality = -1; // -1 default quality value - avistreaminfo.dwSampleSize = pwfxDst->nBlockAlign; - //avistreaminfo.rcFrame; // doesn't apply to audio - //avistreaminfo.dwEditCount =; // Number of times the stream has been edited. The stream handler maintains this count. - //avistreaminfo.dwFormatChangeCount =; // Number of times the stream format has changed. The stream handler maintains this count. - _tcscpy (avistreaminfo.szName, L"Audiostream"); // description of the stream. - - // create the audio stream - if ((err = AVIFileCreateStream (pfile, &AVIAudioStream, &avistreaminfo)) != 0) { - gui_message (L"AVIFileCreateStream() FAILED (%X)\n", err); - goto error; + if (avioutput_audio == AVIAUDIO_WAV) { + wavfile = _tfopen (avioutput_filename, L"wb"); + if (!wavfile) { + gui_message (L"Failed to open wave-file\n\nThis can happen if the path and or file name was entered incorrectly.\n"); + goto error; + } + writewavheader (0); + write_log (L"wave-output to '%s' started\n", avioutput_filename); + return; } - if ((err = AVIStreamSetFormat (AVIAudioStream, 0, pwfxDst, sizeof (WAVEFORMATEX) + pwfxDst->cbSize)) != 0) { - gui_message (L"AVIStreamSetFormat() FAILED (%X)\n", err); - goto error; + if (((err = AVIFileOpen (&pfile, avioutput_filename, OF_CREATE | OF_WRITE, NULL)) != 0)) { + gui_message (L"AVIFileOpen() FAILED (Error %X)\n\nThis can happen if the path and or file name was entered incorrectly.\nRequired *.avi extension.\n", err); + goto error; } - if ((err = acmStreamOpen(&has, NULL, &wfxSrc.Format, pwfxDst, NULL, 0, 0, ACM_STREAMOPENF_NONREALTIME)) != 0) { - gui_message (L"acmStreamOpen() FAILED (%X)\n", err); - goto error; - } - } + if (avioutput_audio) { + if (!AVIOutput_AllocateAudio ()) + goto error; + memset (&avistreaminfo, 0, sizeof (AVISTREAMINFO)); + avistreaminfo.fccType = streamtypeAUDIO; + avistreaminfo.fccHandler = 0; // This member is not used for audio streams. + avistreaminfo.dwFlags = 0; + //avistreaminfo.dwCaps =; // Capability flags; currently unused. + //avistreaminfo.wPriority =; + //avistreaminfo.wLanguage =; + avistreaminfo.dwScale = pwfxDst->nBlockAlign; + avistreaminfo.dwRate = pwfxDst->nAvgBytesPerSec; + avistreaminfo.dwStart = 0; + avistreaminfo.dwLength = -1; + avistreaminfo.dwInitialFrames = 0; + avistreaminfo.dwSuggestedBufferSize = 0; // Use zero if you do not know the correct buffer size. + avistreaminfo.dwQuality = -1; // -1 default quality value + avistreaminfo.dwSampleSize = pwfxDst->nBlockAlign; + //avistreaminfo.rcFrame; // doesn't apply to audio + //avistreaminfo.dwEditCount =; // Number of times the stream has been edited. The stream handler maintains this count. + //avistreaminfo.dwFormatChangeCount =; // Number of times the stream format has changed. The stream handler maintains this count. + _tcscpy (avistreaminfo.szName, L"Audiostream"); // description of the stream. + + // create the audio stream + if ((err = AVIFileCreateStream (pfile, &AVIAudioStream, &avistreaminfo)) != 0) { + gui_message (L"AVIFileCreateStream() FAILED (%X)\n", err); + goto error; + } - if (avioutput_video) { - ae = allocavientry_video (); - if (!AVIOutput_AllocateVideo ()) - goto error; - - // fill in the header for the video stream - memset (&avistreaminfo, 0, sizeof(AVISTREAMINFO)); - avistreaminfo.fccType = streamtypeVIDEO; // stream type - - // unsure about this, as this is the uncompressed stream, not the compressed stream - //avistreaminfo.fccHandler = 0; - - // incase the amiga changes palette - if (ae->lpbi->biBitCount < 24) - avistreaminfo.dwFlags = AVISTREAMINFO_FORMATCHANGES; - //avistreaminfo.dwCaps =; // Capability flags; currently unused - //avistreaminfo.wPriority =; // Priority of the stream - //avistreaminfo.wLanguage =; // Language of the stream - avistreaminfo.dwScale = 1; - avistreaminfo.dwRate = avioutput_fps; // our playback speed default (PAL 50fps), (NTSC 60fps) - avistreaminfo.dwStart = 0; // no delay - avistreaminfo.dwLength = 1; // initial length - //avistreaminfo.dwInitialFrames =; // audio only - avistreaminfo.dwSuggestedBufferSize = ae->lpbi->biSizeImage; - avistreaminfo.dwQuality = -1; // drivers will use the default quality setting - avistreaminfo.dwSampleSize = 0; // variable video data samples - - SetRect (&avistreaminfo.rcFrame, 0, 0, ae->lpbi->biWidth, ae->lpbi->biHeight); // rectangle for stream - - //avistreaminfo.dwEditCount =; // Number of times the stream has been edited. The stream handler maintains this count. - //avistreaminfo.dwFormatChangeCount =; // Number of times the stream format has changed. The stream handler maintains this count. - _tcscpy (avistreaminfo.szName, L"Videostream"); // description of the stream. - - // create the stream - if ((err = AVIFileCreateStream (pfile, &AVIStreamInterface, &avistreaminfo)) != 0) { - gui_message (L"AVIFileCreateStream() FAILED (%X)\n", err); - goto error; + if ((err = AVIStreamSetFormat (AVIAudioStream, 0, pwfxDst, sizeof (WAVEFORMATEX) + pwfxDst->cbSize)) != 0) { + gui_message (L"AVIStreamSetFormat() FAILED (%X)\n", err); + goto error; + } + + if ((err = acmStreamOpen(&has, NULL, &wfxSrc.Format, pwfxDst, NULL, 0, 0, ACM_STREAMOPENF_NONREALTIME)) != 0) { + gui_message (L"acmStreamOpen() FAILED (%X)\n", err); + goto error; + } } - videoOptions.fccType = streamtypeVIDEO; - videoOptions.fccHandler = pcompvars->fccHandler; - videoOptions.dwKeyFrameEvery = pcompvars->lKey; - videoOptions.dwQuality = pcompvars->lQ; + if (avioutput_video) { + ae = allocavientry_video (); + if (!AVIOutput_AllocateVideo ()) + goto error; + + // fill in the header for the video stream + memset (&avistreaminfo, 0, sizeof(AVISTREAMINFO)); + avistreaminfo.fccType = streamtypeVIDEO; // stream type + + // unsure about this, as this is the uncompressed stream, not the compressed stream + //avistreaminfo.fccHandler = 0; + + // incase the amiga changes palette + if (ae->lpbi->biBitCount < 24) + avistreaminfo.dwFlags = AVISTREAMINFO_FORMATCHANGES; + //avistreaminfo.dwCaps =; // Capability flags; currently unused + //avistreaminfo.wPriority =; // Priority of the stream + //avistreaminfo.wLanguage =; // Language of the stream + avistreaminfo.dwScale = 1; + avistreaminfo.dwRate = avioutput_fps; // our playback speed default (PAL 50fps), (NTSC 60fps) + avistreaminfo.dwStart = 0; // no delay + avistreaminfo.dwLength = 1; // initial length + //avistreaminfo.dwInitialFrames =; // audio only + avistreaminfo.dwSuggestedBufferSize = ae->lpbi->biSizeImage; + avistreaminfo.dwQuality = -1; // drivers will use the default quality setting + avistreaminfo.dwSampleSize = 0; // variable video data samples + + SetRect (&avistreaminfo.rcFrame, 0, 0, ae->lpbi->biWidth, ae->lpbi->biHeight); // rectangle for stream + + //avistreaminfo.dwEditCount =; // Number of times the stream has been edited. The stream handler maintains this count. + //avistreaminfo.dwFormatChangeCount =; // Number of times the stream format has changed. The stream handler maintains this count. + _tcscpy (avistreaminfo.szName, L"Videostream"); // description of the stream. + + // create the stream + if ((err = AVIFileCreateStream (pfile, &AVIStreamInterface, &avistreaminfo)) != 0) { + gui_message (L"AVIFileCreateStream() FAILED (%X)\n", err); + goto error; + } + + videoOptions.fccType = streamtypeVIDEO; + videoOptions.fccHandler = pcompvars->fccHandler; + videoOptions.dwKeyFrameEvery = pcompvars->lKey; + videoOptions.dwQuality = pcompvars->lQ; - videoOptions.dwBytesPerSecond = pcompvars->lDataRate * 1024; - videoOptions.dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES | AVICOMPRESSF_INTERLEAVE | AVICOMPRESSF_DATARATE; + videoOptions.dwBytesPerSecond = pcompvars->lDataRate * 1024; + videoOptions.dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES | AVICOMPRESSF_INTERLEAVE | AVICOMPRESSF_DATARATE; - videoOptions.dwInterleaveEvery = 1; + videoOptions.dwInterleaveEvery = 1; - videoOptions.cbFormat = sizeof(BITMAPINFOHEADER); - videoOptions.lpFormat = lpbi; + videoOptions.cbFormat = sizeof(BITMAPINFOHEADER); + videoOptions.lpFormat = lpbi; - videoOptions.cbParms = pcompvars->cbState; - videoOptions.lpParms = pcompvars->lpState; + videoOptions.cbParms = pcompvars->cbState; + videoOptions.lpParms = pcompvars->lpState; - // create a compressed stream from our uncompressed stream and a compression filter - if ((err = AVIMakeCompressedStream (&AVIVideoStream, AVIStreamInterface, &videoOptions, NULL)) != AVIERR_OK) { - gui_message (L"AVIMakeCompressedStream() FAILED (%X)\n", err); - goto error; + // create a compressed stream from our uncompressed stream and a compression filter + if ((err = AVIMakeCompressedStream (&AVIVideoStream, AVIStreamInterface, &videoOptions, NULL)) != AVIERR_OK) { + gui_message (L"AVIMakeCompressedStream() FAILED (%X)\n", err); + goto error; + } } - } - freeavientry (ae); - init_comm_pipe (&workindex, 20, 1); - init_comm_pipe (&queuefull, 20, 1); - alive = -1; - uae_start_thread (L"aviworker", AVIOutput_worker, NULL, NULL); - write_log (L"AVIOutput enabled: video=%d audio=%d\n", avioutput_video, avioutput_audio); - return; + freeavientry (ae); + init_comm_pipe (&workindex, 20, 1); + init_comm_pipe (&queuefull, 20, 1); + alive = -1; + uae_start_thread (L"aviworker", AVIOutput_worker, NULL, NULL); + write_log (L"AVIOutput enabled: video=%d audio=%d\n", avioutput_video, avioutput_audio); + return; error: - freeavientry (ae); - AVIOutput_End (); + freeavientry (ae); + AVIOutput_End (); } void AVIOutput_Release (void) { - AVIOutput_End (); + AVIOutput_End (); - AVIOutput_ReleaseAudio (); - AVIOutput_ReleaseVideo (); + AVIOutput_ReleaseAudio (); + AVIOutput_ReleaseVideo (); - if (avioutput_init) { - AVIFileExit (); - avioutput_init = 0; - } + if (avioutput_init) { + AVIFileExit (); + avioutput_init = 0; + } - if (pcompvars) { - AVIOutput_FreeCOMPVARS (pcompvars); - xfree (pcompvars); - pcompvars = NULL; - } - - if (cs_allocated) { - DeleteCriticalSection (&AVIOutput_CriticalSection); - cs_allocated = 0; - } + if (pcompvars) { + AVIOutput_FreeCOMPVARS (pcompvars); + xfree (pcompvars); + pcompvars = NULL; + } + + if (cs_allocated) { + DeleteCriticalSection (&AVIOutput_CriticalSection); + cs_allocated = 0; + } } void AVIOutput_Initialize (void) { - if (avioutput_init) - return; - - InitializeCriticalSection (&AVIOutput_CriticalSection); - cs_allocated = 1; - - pcompvars = xcalloc (sizeof (COMPVARS), 1); - if (!pcompvars) - return; - pcompvars->cbSize = sizeof (COMPVARS); - AVIFileInit (); - avioutput_init = 1; + if (avioutput_init) + return; + + InitializeCriticalSection (&AVIOutput_CriticalSection); + cs_allocated = 1; + + pcompvars = xcalloc (sizeof (COMPVARS), 1); + if (!pcompvars) + return; + pcompvars->cbSize = sizeof (COMPVARS); + AVIFileInit (); + avioutput_init = 1; } static void *AVIOutput_worker (void *arg) { - write_log (L"AVIOutput worker thread started\n"); - alive = 1; - for (;;) { - uae_u32 idx = read_comm_pipe_u32_blocking (&workindex); - struct avientry *ae; - int r1 = 1; - int r2 = 1; - if (idx == 0xffffffff) - break; + write_log (L"AVIOutput worker thread started\n"); + alive = 1; for (;;) { - EnterCriticalSection (&AVIOutput_CriticalSection); - ae = getavientry (); - LeaveCriticalSection (&AVIOutput_CriticalSection); - if (ae == NULL) - break; - write_comm_pipe_u32 (&queuefull, 0, 1); - if (ae->lpAudio) - r1 = AVIOutput_AVIWriteAudio_Thread (ae); - if (ae->lpVideo) - r2 = AVIOutput_AVIWriteVideo_Thread (ae); - if (r1 == 0 || r2 == 0) - avioutput_failed = 1; - freeavientry (ae); - if (idx != 0xfffffffe) - break; + uae_u32 idx = read_comm_pipe_u32_blocking (&workindex); + struct avientry *ae; + int r1 = 1; + int r2 = 1; + if (idx == 0xffffffff) + break; + for (;;) { + EnterCriticalSection (&AVIOutput_CriticalSection); + ae = getavientry (); + LeaveCriticalSection (&AVIOutput_CriticalSection); + if (ae == NULL) + break; + write_comm_pipe_u32 (&queuefull, 0, 1); + if (!avioutput_failed) { + if (ae->lpAudio) + r1 = AVIOutput_AVIWriteAudio_Thread (ae); + if (ae->lpVideo) + r2 = AVIOutput_AVIWriteVideo_Thread (ae); + if (r1 == 0 || r2 == 0) + avioutput_failed = 1; + } + freeavientry (ae); + if (idx != 0xfffffffe) + break; + } + if (idx == 0xfffffffe || idx == 0xffffffff) + break; } - if (idx == 0xfffffffe || idx == 0xffffffff) - break; - } - write_log (L"AVIOutput worker thread killed\n"); - alive = 0; - return 0; + write_log (L"AVIOutput worker thread killed\n"); + alive = 0; + return 0; } @@ -1285,48 +1309,48 @@ static void *AVIOutput_worker (void *arg) void frame_drawn(void) { #if 0 - double diff, skipmode; + double diff, skipmode; #endif - int idiff; + int idiff; - if (!avioutput_video || !avioutput_enabled) - return; + if (!avioutput_video || !avioutput_enabled) + return; - if (first_frame) { - first_frame = 0; - return; - } + if (first_frame) { + first_frame = 0; + return; + } - AVIOutput_WriteVideo (); + AVIOutput_WriteVideo (); - if (!avioutput_audio) - return; + if (!avioutput_audio) + return; - StreamSizeAudioExpected += ((double)currprefs.sound_freq) / avioutput_fps; - idiff = StreamSizeAudio - StreamSizeAudioExpected; - if (idiff > 0) { - skipsample += idiff / 10; - if (skipsample > 4) - skipsample = 4; - } - sound_setadjust (0.0); + StreamSizeAudioExpected += ((double)currprefs.sound_freq) / avioutput_fps; + idiff = StreamSizeAudio - StreamSizeAudioExpected; + if (idiff > 0) { + skipsample += idiff / 10; + if (skipsample > 4) + skipsample = 4; + } + sound_setadjust (0.0); #if 0 - write_log (L"%d ", idiff); - diff = idiff / 20.0; - skipmode = pow (diff < 0 ? -diff : diff, EXP); - if (idiff < 0) - skipmode = -skipmode; - if (skipmode < -ADJUST_SIZE) - skipmode = -ADJUST_SIZE; - if (skipmode > ADJUST_SIZE) - skipmode = ADJUST_SIZE; - write_log (L"%d/%.2f\n", idiff, skipmode); - - sound_setadjust (skipmode); - - if (0 && !(frame_count % avioutput_fps)) - write_log (L"AVIOutput: diff=%.2f skip=%.2f (%d-%d=%d)\n", diff, skipmode, - StreamSizeAudio, StreamSizeAudioExpected, idiff); + write_log (L"%d ", idiff); + diff = idiff / 20.0; + skipmode = pow (diff < 0 ? -diff : diff, EXP); + if (idiff < 0) + skipmode = -skipmode; + if (skipmode < -ADJUST_SIZE) + skipmode = -ADJUST_SIZE; + if (skipmode > ADJUST_SIZE) + skipmode = ADJUST_SIZE; + write_log (L"%d/%.2f\n", idiff, skipmode); + + sound_setadjust (skipmode); + + if (0 && !(frame_count % avioutput_fps)) + write_log (L"AVIOutput: diff=%.2f skip=%.2f (%d-%d=%d)\n", diff, skipmode, + StreamSizeAudio, StreamSizeAudioExpected, idiff); #endif } diff --git a/od-win32/blkdev_win32_aspi.c b/od-win32/blkdev_win32_aspi.c index 7dfd4949..5b4f6d52 100644 --- a/od-win32/blkdev_win32_aspi.c +++ b/od-win32/blkdev_win32_aspi.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * WIN32 CDROM/HD low level access code (ASPI) - * - * Copyright 2002 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* WIN32 CDROM/HD low level access code (ASPI) +* +* Copyright 2002 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -35,319 +35,319 @@ static HANDLE hAspiLib; static int scanphase; struct scsi_info { - int scsibus,target,lun; - int type; - int mediainserted; - uae_u8 *buf; - TCHAR label[100]; - SCSI *handle; - int isatapi; - int removable; + int scsibus,target,lun; + int type; + int mediainserted; + uae_u8 *buf; + TCHAR label[100]; + SCSI *handle; + int isatapi; + int removable; }; static struct scsi_info si[MAX_TOTAL_DEVICES]; static int unitcnt; static int getversion(const TCHAR *name, VS_FIXEDFILEINFO *ver) { - int ok = FALSE; - DWORD dwVersionHandle, dwFileVersionInfoSize; - LPVOID lpFileVersionData = NULL; - - dwFileVersionInfoSize = GetFileVersionInfoSize(name, &dwVersionHandle); - if (dwFileVersionInfoSize) { - if (lpFileVersionData = calloc(1, dwFileVersionInfoSize)) { - if (GetFileVersionInfo(name, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { - VS_FIXEDFILEINFO *vsFileInfo = NULL; - UINT uLen; - if (VerQueryValue(lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { - if(vsFileInfo) { - memcpy (ver, vsFileInfo, sizeof (*ver)); - ok = TRUE; - write_log (L"%s version %d.%d.%d.%d\n", name, - vsFileInfo->dwFileVersionMS >> 16, - vsFileInfo->dwFileVersionMS & 0xffff, - vsFileInfo->dwFileVersionLS >> 16, - vsFileInfo->dwFileVersionLS & 0xffff); - } + int ok = FALSE; + DWORD dwVersionHandle, dwFileVersionInfoSize; + LPVOID lpFileVersionData = NULL; + + dwFileVersionInfoSize = GetFileVersionInfoSize(name, &dwVersionHandle); + if (dwFileVersionInfoSize) { + if (lpFileVersionData = calloc(1, dwFileVersionInfoSize)) { + if (GetFileVersionInfo(name, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { + VS_FIXEDFILEINFO *vsFileInfo = NULL; + UINT uLen; + if (VerQueryValue(lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { + if(vsFileInfo) { + memcpy (ver, vsFileInfo, sizeof (*ver)); + ok = TRUE; + write_log (L"%s version %d.%d.%d.%d\n", name, + vsFileInfo->dwFileVersionMS >> 16, + vsFileInfo->dwFileVersionMS & 0xffff, + vsFileInfo->dwFileVersionLS >> 16, + vsFileInfo->dwFileVersionLS & 0xffff); + } + } + } + xfree(lpFileVersionData); } - } - xfree(lpFileVersionData); } - } - return ok; + return ok; } const TCHAR *get_aspi_path(int aspitype) { - static int nero, adaptec, frog; - static TCHAR path_nero[MAX_DPATH]; - static TCHAR path_adaptec[MAX_DPATH]; - static const TCHAR *path_frog = L"FrogAspi.dll"; - VS_FIXEDFILEINFO ver; + static int nero, adaptec, frog; + static TCHAR path_nero[MAX_DPATH]; + static TCHAR path_adaptec[MAX_DPATH]; + static const TCHAR *path_frog = L"FrogAspi.dll"; + VS_FIXEDFILEINFO ver; - switch (aspitype) - { + switch (aspitype) + { case 2: // Frog - if (frog > 0) - return path_frog; - if (frog < 0) - return NULL; - frog = -1; - if (getversion(path_frog, &ver)) - frog = 1; - return path_frog; + if (frog > 0) + return path_frog; + if (frog < 0) + return NULL; + frog = -1; + if (getversion(path_frog, &ver)) + frog = 1; + return path_frog; case 1: // Nero - { - HKEY key; - DWORD type = REG_SZ; - DWORD size = sizeof (path_nero); - if (nero > 0) - return path_nero; - if (nero < 0) - return NULL; - nero = -1; - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Ahead\\shared", 0, KEY_READ, &key) == ERROR_SUCCESS) { - if (RegQueryValueEx (key, L"NeroAPI", 0, &type, (LPBYTE)path_nero, &size) == ERROR_SUCCESS) { - if (path_nero[_tcslen (path_nero) - 1] != '\\') - _tcscat (path_nero, L"\\"); - _tcscat (path_nero, L"wnaspi32.dll"); - RegCloseKey (key); - if (getversion(path_nero, &ver)) { - if (ver.dwFileVersionMS >= 0x20000) { - nero = 1; - return path_nero; + { + HKEY key; + DWORD type = REG_SZ; + DWORD size = sizeof (path_nero); + if (nero > 0) + return path_nero; + if (nero < 0) + return NULL; + nero = -1; + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Ahead\\shared", 0, KEY_READ, &key) == ERROR_SUCCESS) { + if (RegQueryValueEx (key, L"NeroAPI", 0, &type, (LPBYTE)path_nero, &size) == ERROR_SUCCESS) { + if (path_nero[_tcslen (path_nero) - 1] != '\\') + _tcscat (path_nero, L"\\"); + _tcscat (path_nero, L"wnaspi32.dll"); + RegCloseKey (key); + if (getversion(path_nero, &ver)) { + if (ver.dwFileVersionMS >= 0x20000) { + nero = 1; + return path_nero; + } + } + return NULL; + } + RegCloseKey (key); } - } - return NULL; } - RegCloseKey (key); - } - } - return NULL; + return NULL; case 0: // Adaptec - { - if (adaptec > 0) - return path_adaptec; - if (adaptec < 0) - return NULL; - adaptec = -1; - _tcscpy (path_adaptec, L"wnaspi32.dll"); - if (getversion(path_adaptec, &ver)) { - if (ver.dwFileVersionMS >= 0x40000 || ver.dwFileVersionMS < 0x10000) { - adaptec = 1; - return path_adaptec; + { + if (adaptec > 0) + return path_adaptec; + if (adaptec < 0) + return NULL; + adaptec = -1; + _tcscpy (path_adaptec, L"wnaspi32.dll"); + if (getversion(path_adaptec, &ver)) { + if (ver.dwFileVersionMS >= 0x40000 || ver.dwFileVersionMS < 0x10000) { + adaptec = 1; + return path_adaptec; + } + } } - } + return NULL; } return NULL; - } - return NULL; } static int ha_inquiry (SCSI *scgp, int id, SRB_HAInquiry *ip) { - DWORD Status; - - ip->SRB_Cmd = SC_HA_INQUIRY; - ip->SRB_HaId = id; - ip->SRB_Flags = 0; - ip->SRB_Hdr_Rsvd = 0; - - Status = pfnSendASPI32Command((LPSRB)ip); - if (log_scsi) { - TCHAR *s1 = au (ip->HA_ManagerId); - TCHAR *s2 = au (ip->HA_Identifier); - write_log (L"ASPI: S=%d ha=%d, ID=%d, M='%s', Id='%s'\n", - Status, ip->HA_Count, ip->HA_SCSI_ID, s1, s2); - xfree (s2); - xfree (s1); - } - if (ip->SRB_Status != SS_COMP) - return -1; - return 0; + DWORD Status; + + ip->SRB_Cmd = SC_HA_INQUIRY; + ip->SRB_HaId = id; + ip->SRB_Flags = 0; + ip->SRB_Hdr_Rsvd = 0; + + Status = pfnSendASPI32Command((LPSRB)ip); + if (log_scsi) { + TCHAR *s1 = au (ip->HA_ManagerId); + TCHAR *s2 = au (ip->HA_Identifier); + write_log (L"ASPI: S=%d ha=%d, ID=%d, M='%s', Id='%s'\n", + Status, ip->HA_Count, ip->HA_SCSI_ID, s1, s2); + xfree (s2); + xfree (s1); + } + if (ip->SRB_Status != SS_COMP) + return -1; + return 0; } static int open_driver (SCSI *scgp) { - TCHAR path[MAX_DPATH]; - DWORD astatus; - BYTE HACount; - BYTE ASPIStatus; - int i; - int nero, frog; - - /* - * Check if ASPI library is already loaded - */ - if (AspiLoaded == TRUE) - return TRUE; + TCHAR path[MAX_DPATH]; + DWORD astatus; + BYTE HACount; + BYTE ASPIStatus; + int i; + int nero, frog; + + /* + * Check if ASPI library is already loaded + */ + if (AspiLoaded == TRUE) + return TRUE; + + nero = frog = 0; + _tcscpy (path, L"WNASPI32"); + if (currprefs.win32_uaescsimode == UAESCSI_NEROASPI) { + const TCHAR *p = get_aspi_path(1); + if (p) { + _tcscpy (path, p); + nero = 1; + } + } else if (currprefs.win32_uaescsimode == UAESCSI_FROGASPI) { + const TCHAR *p = get_aspi_path(2); + if (p) { + _tcscpy (path, p); + frog = 1; + } + } + /* + * Load the ASPI library + */ + write_log (L"ASPI: driver location '%s'\n", path); + hAspiLib = LoadLibrary (path); + if (hAspiLib == NULL && (nero || frog)) { + write_log (L"ASPI: NERO/FROG ASPI failed to load, falling back to default\n"); + hAspiLib = LoadLibrary (L"WNASPI32"); + } + + /* + * Check if ASPI library is loaded correctly + */ + if (hAspiLib == NULL) { + write_log (L"ASPI: failed to load wnaspi32.dll\n"); + return FALSE; + } + /* + * Get a pointer to GetASPI32SupportInfo function + * and a pointer to SendASPI32Command function + */ + pfnGetASPI32SupportInfo = (DWORD(_cdecl *)(void))GetProcAddress (hAspiLib, "GetASPI32SupportInfo"); + pfnSendASPI32Command = (DWORD(_cdecl *)(LPSRB))GetProcAddress (hAspiLib, "SendASPI32Command"); + + if (pfnGetASPI32SupportInfo == NULL || pfnSendASPI32Command == NULL) { + write_log (L"ASPI: obsolete wnaspi32.dll found\n"); + return FALSE; + } + + pfnGetASPI32Buffer = (BOOL(_cdecl *)(PASPI32BUFF))GetProcAddress (hAspiLib, "GetASPI32Buffer"); + pfnFreeASPI32Buffer = (BOOL(_cdecl *)(PASPI32BUFF))GetProcAddress (hAspiLib, "FreeASPI32Buffer"); + pfnTranslateASPI32Address = (BOOL(_cdecl *)(PDWORD, PDWORD))GetProcAddress (hAspiLib, "TranslateASPI32Address"); + + /* + * Set AspiLoaded variable + */ + AspiLoaded = TRUE; + + astatus = pfnGetASPI32SupportInfo(); + + ASPIStatus = HIBYTE(LOWORD(astatus)); + HACount = LOBYTE(LOWORD(astatus)); - nero = frog = 0; - _tcscpy (path, L"WNASPI32"); - if (currprefs.win32_uaescsimode == UAESCSI_NEROASPI) { - const TCHAR *p = get_aspi_path(1); - if (p) { - _tcscpy (path, p); - nero = 1; + write_log (L"ASPI: open_driver %X HostASPIStatus=0x%x HACount=0x%x\n", astatus, ASPIStatus, HACount); + + if (ASPIStatus != SS_COMP && ASPIStatus != SS_NO_ADAPTERS) { + write_log (L"ASPI: Could not find any host adapters, ASPIStatus == 0x%02X\n", ASPIStatus); + return FALSE; } - } else if (currprefs.win32_uaescsimode == UAESCSI_FROGASPI) { - const TCHAR *p = get_aspi_path(2); - if (p) { - _tcscpy (path, p); - frog = 1; + busses = HACount; + + write_log (L"ASPI: open_driver HostASPIStatus=0x%x HACount=0x%x\n", ASPIStatus, HACount); + + for (i=0; i < busses; i++) { + SRB_HAInquiry s; + ha_inquiry(scgp, i, &s); } - } - /* - * Load the ASPI library - */ - write_log (L"ASPI: driver location '%s'\n", path); - hAspiLib = LoadLibrary (path); - if (hAspiLib == NULL && (nero || frog)) { - write_log (L"ASPI: NERO/FROG ASPI failed to load, falling back to default\n"); - hAspiLib = LoadLibrary (L"WNASPI32"); - } - - /* - * Check if ASPI library is loaded correctly - */ - if (hAspiLib == NULL) { - write_log (L"ASPI: failed to load wnaspi32.dll\n"); - return FALSE; - } - /* - * Get a pointer to GetASPI32SupportInfo function - * and a pointer to SendASPI32Command function - */ - pfnGetASPI32SupportInfo = (DWORD(_cdecl *)(void))GetProcAddress (hAspiLib, "GetASPI32SupportInfo"); - pfnSendASPI32Command = (DWORD(_cdecl *)(LPSRB))GetProcAddress (hAspiLib, "SendASPI32Command"); - - if (pfnGetASPI32SupportInfo == NULL || pfnSendASPI32Command == NULL) { - write_log (L"ASPI: obsolete wnaspi32.dll found\n"); - return FALSE; - } - - pfnGetASPI32Buffer = (BOOL(_cdecl *)(PASPI32BUFF))GetProcAddress (hAspiLib, "GetASPI32Buffer"); - pfnFreeASPI32Buffer = (BOOL(_cdecl *)(PASPI32BUFF))GetProcAddress (hAspiLib, "FreeASPI32Buffer"); - pfnTranslateASPI32Address = (BOOL(_cdecl *)(PDWORD, PDWORD))GetProcAddress (hAspiLib, "TranslateASPI32Address"); - - /* - * Set AspiLoaded variable - */ - AspiLoaded = TRUE; - - astatus = pfnGetASPI32SupportInfo(); - - ASPIStatus = HIBYTE(LOWORD(astatus)); - HACount = LOBYTE(LOWORD(astatus)); - - write_log (L"ASPI: open_driver %X HostASPIStatus=0x%x HACount=0x%x\n", astatus, ASPIStatus, HACount); - - if (ASPIStatus != SS_COMP && ASPIStatus != SS_NO_ADAPTERS) { - write_log (L"ASPI: Could not find any host adapters, ASPIStatus == 0x%02X\n", ASPIStatus); - return FALSE; - } - busses = HACount; - - write_log (L"ASPI: open_driver HostASPIStatus=0x%x HACount=0x%x\n", ASPIStatus, HACount); - - for (i=0; i < busses; i++) { - SRB_HAInquiry s; - ha_inquiry(scgp, i, &s); - } - return TRUE; + return TRUE; } static void close_driver (void) { - if (!AspiLoaded) - return; - AspiLoaded = FALSE; - pfnGetASPI32SupportInfo = NULL; - pfnSendASPI32Command = NULL; - pfnGetASPI32Buffer = NULL; - pfnFreeASPI32Buffer = NULL; - pfnTranslateASPI32Address = NULL; - FreeLibrary(hAspiLib); - hAspiLib = NULL; + if (!AspiLoaded) + return; + AspiLoaded = FALSE; + pfnGetASPI32SupportInfo = NULL; + pfnSendASPI32Command = NULL; + pfnGetASPI32Buffer = NULL; + pfnFreeASPI32Buffer = NULL; + pfnTranslateASPI32Address = NULL; + FreeLibrary(hAspiLib); + hAspiLib = NULL; } static int scsi_bufsize (SCSI *scgp, int amt) { - return 63*1024; + return 63*1024; } static int scsi_havebus (SCSI *scgp, int busno) { - if (busno < 0 || busno >= busses) - return FALSE; - return TRUE; + if (busno < 0 || busno >= busses) + return FALSE; + return TRUE; } static void *scgo_getbuf (SCSI *scgp, long amt) { - scgp->bufbase = malloc((size_t)(amt)); - return scgp->bufbase; + scgp->bufbase = malloc((size_t)(amt)); + return scgp->bufbase; } static void scsi_sfree (SCSI *scgp) { - if (scgp->cmdstart) - free(scgp->cmdstart); - if (scgp->cmdstop) - free(scgp->cmdstop); - if (scgp->scmd) - free(scgp->scmd); - if (scgp->inq) - free(scgp->inq); - if (scgp->cap) - free(scgp->cap); - if (scgp->local) - free(scgp->local); - if (scgp->errstr) - free(scgp->errstr); - free(scgp); + if (scgp->cmdstart) + free(scgp->cmdstart); + if (scgp->cmdstop) + free(scgp->cmdstop); + if (scgp->scmd) + free(scgp->scmd); + if (scgp->inq) + free(scgp->inq); + if (scgp->cap) + free(scgp->cap); + if (scgp->local) + free(scgp->local); + if (scgp->errstr) + free(scgp->errstr); + free(scgp); } static SCSI *scsi_smalloc(void) { - SCSI *scgp; - - scgp = (SCSI *)malloc(sizeof(*scgp)); - if (scgp == NULL) - return 0; - - memset (scgp, 0, sizeof (*scgp)); - scgp->deftimeout = 20; - scgp->running = FALSE; - - scgp->cmdstart = (struct timeval *)malloc(sizeof(struct timeval)); - if (scgp->cmdstart == NULL) - goto err; - scgp->cmdstop = (struct timeval *)malloc(sizeof(struct timeval)); - if (scgp->cmdstop == NULL) - goto err; - scgp->scmd = (struct scg_cmd *)malloc(sizeof(struct scg_cmd)); - if (scgp->scmd == NULL) - goto err; - scgp->errstr = malloc(SCSI_ERRSTR_SIZE); - if (scgp->errstr == NULL) - goto err; - scgp->errptr = scgp->errbeg = scgp->errstr; - scgp->errstr[0] = '\0'; - scgp->inq = (struct scsi_inquiry *)malloc(sizeof(struct scsi_inquiry)); - if (scgp->inq == NULL) - goto err; - scgp->cap = (struct scsi_capacity *)malloc(sizeof(struct scsi_capacity)); - if (scgp->cap == NULL) - goto err; - return scgp; + SCSI *scgp; + + scgp = (SCSI *)malloc(sizeof(*scgp)); + if (scgp == NULL) + return 0; + + memset (scgp, 0, sizeof (*scgp)); + scgp->deftimeout = 20; + scgp->running = FALSE; + + scgp->cmdstart = (struct timeval *)malloc(sizeof(struct timeval)); + if (scgp->cmdstart == NULL) + goto err; + scgp->cmdstop = (struct timeval *)malloc(sizeof(struct timeval)); + if (scgp->cmdstop == NULL) + goto err; + scgp->scmd = (struct scg_cmd *)malloc(sizeof(struct scg_cmd)); + if (scgp->scmd == NULL) + goto err; + scgp->errstr = malloc(SCSI_ERRSTR_SIZE); + if (scgp->errstr == NULL) + goto err; + scgp->errptr = scgp->errbeg = scgp->errstr; + scgp->errstr[0] = '\0'; + scgp->inq = (struct scsi_inquiry *)malloc(sizeof(struct scsi_inquiry)); + if (scgp->inq == NULL) + goto err; + scgp->cap = (struct scsi_capacity *)malloc(sizeof(struct scsi_capacity)); + if (scgp->cap == NULL) + goto err; + return scgp; err: - scsi_sfree(scgp); - return 0; + scsi_sfree(scgp); + return 0; } #define MAX_SCG 16 /* Max # of SCSI controllers */ @@ -355,105 +355,105 @@ err: #define MAX_LUN 8 /* Max # of SCSI LUNs */ struct scg_local { - int dummy; + int dummy; }; #define scglocal(p) ((struct scg_local *)((p)->local)) static SCSI *openscsi (int busno, int tgt, int tlun) { - SCSI *scgp = scsi_smalloc (); + SCSI *scgp = scsi_smalloc (); - if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) { - errno = EINVAL; - if (log_scsi) - write_log (L"ASPI: Illegal value for busno, target or lun '%d,%d,%d'\n", busno, tgt, tlun); - return 0; - } - /* - * Check if variables are within the range - */ - if (tgt >= 0 && tgt >= 0 && tlun >= 0) { + if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) { + errno = EINVAL; + if (log_scsi) + write_log (L"ASPI: Illegal value for busno, target or lun '%d,%d,%d'\n", busno, tgt, tlun); + return 0; + } /* - * This is the non -scanbus case. - */ - ; - } else if (tgt != -1 || tgt != -1 || tlun != -1) { - errno = EINVAL; - return 0; - } - if (scgp->local == NULL) { - scgp->local = malloc(sizeof(struct scg_local)); - if (scgp->local == NULL) - return 0; - } - /* - * Try to open ASPI-Router - */ - if (!open_driver(scgp)) - return 0; - /* - * More than we have ... - */ - if (busno >= busses) { - close_driver (); - return 0; - } - return scgp; + * Check if variables are within the range + */ + if (tgt >= 0 && tgt >= 0 && tlun >= 0) { + /* + * This is the non -scanbus case. + */ + ; + } else if (tgt != -1 || tgt != -1 || tlun != -1) { + errno = EINVAL; + return 0; + } + if (scgp->local == NULL) { + scgp->local = malloc(sizeof(struct scg_local)); + if (scgp->local == NULL) + return 0; + } + /* + * Try to open ASPI-Router + */ + if (!open_driver(scgp)) + return 0; + /* + * More than we have ... + */ + if (busno >= busses) { + close_driver (); + return 0; + } + return scgp; } static void closescsi (SCSI *scgp) { - close_driver (); + close_driver (); } static void scsi_debug (SCSI *scgp, SRB_ExecSCSICmd *s) { - if (!log_scsi) - return; - if (scanphase) - return; - write_log (L"ASPI EXEC_SCSI: bus=%d,target=%d,lun=%d\n", - s->SRB_HaId, s->SRB_Target, s->SRB_Lun); - scsi_log_before (scgp->scmd->cdb.cmd_cdb, scgp->scmd->cdb_len, - (s->SRB_Flags & SRB_DIR_OUT) ? s->SRB_BufPointer : 0, s->SRB_BufLen); + if (!log_scsi) + return; + if (scanphase) + return; + write_log (L"ASPI EXEC_SCSI: bus=%d,target=%d,lun=%d\n", + s->SRB_HaId, s->SRB_Target, s->SRB_Lun); + scsi_log_before (scgp->scmd->cdb.cmd_cdb, scgp->scmd->cdb_len, + (s->SRB_Flags & SRB_DIR_OUT) ? s->SRB_BufPointer : 0, s->SRB_BufLen); } static void copy_sensedata(SRB_ExecSCSICmd *cp, struct scg_cmd *sp) { - sp->sense_count = cp->SRB_SenseLen; - if (sp->sense_count > sp->sense_len) - sp->sense_count = sp->sense_len; - memset(&sp->u_sense.Sense, 0x00, sizeof(sp->u_sense.Sense)); - if(sp->sense_len > 0) { - int len = sp->sense_len; - if (len > sizeof(sp->u_sense.Sense)) len = sizeof(sp->u_sense.Sense); - memcpy(&sp->u_sense.Sense, cp->SenseArea, len); - } - sp->u_scb.cmd_scb[0] = cp->SRB_TargStat; + sp->sense_count = cp->SRB_SenseLen; + if (sp->sense_count > sp->sense_len) + sp->sense_count = sp->sense_len; + memset(&sp->u_sense.Sense, 0x00, sizeof(sp->u_sense.Sense)); + if(sp->sense_len > 0) { + int len = sp->sense_len; + if (len > sizeof(sp->u_sense.Sense)) len = sizeof(sp->u_sense.Sense); + memcpy(&sp->u_sense.Sense, cp->SenseArea, len); + } + sp->u_scb.cmd_scb[0] = cp->SRB_TargStat; } /* - * Set error flags - */ +* Set error flags +*/ static void set_error(SRB_ExecSCSICmd *cp, struct scg_cmd *sp) { - switch (cp->SRB_Status) { + switch (cp->SRB_Status) { case SS_COMP: /* 0x01 SRB completed without error */ - sp->error = SCG_NO_ERROR; - sp->ux_errno = 0; - break; + sp->error = SCG_NO_ERROR; + sp->ux_errno = 0; + break; case SS_PENDING: /* 0x00 SRB being processed */ - /* - * XXX Could SS_PENDING happen ??? - */ + /* + * XXX Could SS_PENDING happen ??? + */ case SS_ABORTED: /* 0x02 SRB aborted */ case SS_ABORT_FAIL: /* 0x03 Unable to abort SRB */ case SS_ERR: /* 0x04 SRB completed with error */ default: - sp->error = SCG_RETRYABLE; - sp->ux_errno = EIO; - break; + sp->error = SCG_RETRYABLE; + sp->ux_errno = EIO; + break; case SS_INVALID_CMD: /* 0x80 Invalid ASPI command */ case SS_INVALID_HA: /* 0x81 Invalid host adapter number */ case SS_NO_DEVICE: /* 0x82 SCSI device not installed */ @@ -462,551 +462,551 @@ static void set_error(SRB_ExecSCSICmd *cp, struct scg_cmd *sp) case SS_NO_ASPI: /* 0xE3 No ASPI managers */ case SS_FAILED_INIT: /* 0xE4 ASPI for windows failed init */ case SS_MISMATCHED_COMPONENTS: /* 0xE7 The DLLs/EXEs of ASPI don't */ - /* version check */ + /* version check */ case SS_NO_ADAPTERS: /* 0xE8 No host adapters to manager */ case SS_ASPI_IS_SHUTDOWN: /* 0xEA Call came to ASPI after */ - /* PROCESS_DETACH */ + /* PROCESS_DETACH */ case SS_BAD_INSTALL: /* 0xEB The DLL or other components */ - /* are installed wrong */ - sp->error = SCG_FATAL; - sp->ux_errno = EINVAL; - break; + /* are installed wrong */ + sp->error = SCG_FATAL; + sp->ux_errno = EINVAL; + break; case SS_BUFFER_ALIGN: /* 0xE1 Buffer not aligned (replaces */ - /* SS_OLD_MANAGER in Win32) */ - sp->error = SCG_FATAL; - sp->ux_errno = EFAULT; - break; + /* SS_OLD_MANAGER in Win32) */ + sp->error = SCG_FATAL; + sp->ux_errno = EFAULT; + break; case SS_ASPI_IS_BUSY: /* 0xE5 No resources available to */ - /* execute command */ - sp->error = SCG_RETRYABLE; - sp->ux_errno = EBUSY; - break; + /* execute command */ + sp->error = SCG_RETRYABLE; + sp->ux_errno = EBUSY; + break; case SS_BUFFER_TO_BIG: /* 0xE6 Correct spelling of 'too' */ case SS_INSUFFICIENT_RESOURCES: /* 0xE9 Couldn't allocate resources */ - /* needed to init */ - sp->error = SCG_RETRYABLE; - sp->ux_errno = ENOMEM; - break; - } + /* needed to init */ + sp->error = SCG_RETRYABLE; + sp->ux_errno = ENOMEM; + break; + } } static int scsiabort(SCSI *scgp, SRB_ExecSCSICmd *sp) { - DWORD Status = 0; - SRB_Abort s; - - if (log_scsi) - write_log (L"ASPI: Attempting to abort SCSI command\n"); - /* - * Set structure variables - */ - s.SRB_Cmd = SC_ABORT_SRB; /* ASPI command code = SC_ABORT_SRB */ - s.SRB_HaId = scg_scsibus(scgp); /* ASPI host adapter number */ - s.SRB_Flags = 0; /* Flags */ - s.SRB_ToAbort = (LPSRB)&sp; /* sp */ - /* - * Initiate SCSI abort - */ - Status = pfnSendASPI32Command((LPSRB)&s); - /* - * Check condition - */ - if (s.SRB_Status != SS_COMP) { + DWORD Status = 0; + SRB_Abort s; + + if (log_scsi) + write_log (L"ASPI: Attempting to abort SCSI command\n"); + /* + * Set structure variables + */ + s.SRB_Cmd = SC_ABORT_SRB; /* ASPI command code = SC_ABORT_SRB */ + s.SRB_HaId = scg_scsibus(scgp); /* ASPI host adapter number */ + s.SRB_Flags = 0; /* Flags */ + s.SRB_ToAbort = (LPSRB)&sp; /* sp */ + /* + * Initiate SCSI abort + */ + Status = pfnSendASPI32Command((LPSRB)&s); + /* + * Check condition + */ + if (s.SRB_Status != SS_COMP) { + if (log_scsi) + write_log (L"ASPI: Abort ERROR! 0x%08X\n", s.SRB_Status); + return FALSE; + } if (log_scsi) - write_log (L"ASPI: Abort ERROR! 0x%08X\n", s.SRB_Status); - return FALSE; - } - if (log_scsi) - write_log (L"ASPI: Abort SCSI command completed\n"); - /* - * Everything went OK - */ - return TRUE; + write_log (L"ASPI: Abort SCSI command completed\n"); + /* + * Everything went OK + */ + return TRUE; } static int scsicmd(SCSI *scgp) { - struct scg_cmd *sp = scgp->scmd; - DWORD Status = 0; - DWORD EventStatus = WAIT_OBJECT_0; - HANDLE Event = NULL; - SRB_ExecSCSICmd s; - - /* - * Initialize variables - */ - sp->error = SCG_NO_ERROR; - sp->sense_count = 0; - sp->u_scb.cmd_scb[0] = 0; - sp->resid = 0; - - memset(&s, 0, sizeof(s)); /* Clear SRB structure */ - - /* - * Check cbd_len > the maximum command pakket that can be handled by ASPI - */ - if (sp->cdb_len > 16) { - sp->error = SCG_FATAL; - sp->ux_errno = EINVAL; - if (log_scsi) - write_log (L"ASPI: sp->cdb_len > sizeof(SRB_ExecSCSICmd.CDBByte). Fatal error in scgo_send, exiting...\n"); - return -1; - } - /* - * copy command into SRB - */ - memcpy(&(s.CDBByte), &sp->cdb, sp->cdb_len); - - Event = CreateEvent(NULL, TRUE, FALSE, NULL); - - /* - * Fill ASPI structure - */ - s.SRB_Cmd = SC_EXEC_SCSI_CMD; /* SCSI Command */ - s.SRB_HaId = scg_scsibus(scgp); /* Host adapter number */ - s.SRB_Flags = SRB_EVENT_NOTIFY; /* Flags */ - s.SRB_Target = scg_target(scgp); /* Target SCSI ID */ - s.SRB_Lun = scg_lun(scgp); /* Target SCSI LUN */ - s.SRB_BufLen = sp->size; /* # of bytes transferred */ - s.SRB_BufPointer= sp->addr; /* pointer to data buffer */ - s.SRB_CDBLen = sp->cdb_len; /* SCSI command length */ - s.SRB_PostProc = Event; /* Post proc event */ - s.SRB_SenseLen = SENSE_LEN; /* Lenght of sense buffer */ - - /* - * Do we receive data from this ASPI command? - */ - if (sp->flags & SCG_RECV_DATA) { - s.SRB_Flags |= SRB_DIR_IN; - } else { + struct scg_cmd *sp = scgp->scmd; + DWORD Status = 0; + DWORD EventStatus = WAIT_OBJECT_0; + HANDLE Event = NULL; + SRB_ExecSCSICmd s; + + /* + * Initialize variables + */ + sp->error = SCG_NO_ERROR; + sp->sense_count = 0; + sp->u_scb.cmd_scb[0] = 0; + sp->resid = 0; + + memset(&s, 0, sizeof(s)); /* Clear SRB structure */ + + /* + * Check cbd_len > the maximum command pakket that can be handled by ASPI + */ + if (sp->cdb_len > 16) { + sp->error = SCG_FATAL; + sp->ux_errno = EINVAL; + if (log_scsi) + write_log (L"ASPI: sp->cdb_len > sizeof(SRB_ExecSCSICmd.CDBByte). Fatal error in scgo_send, exiting...\n"); + return -1; + } /* - * Set direction to output - */ - if (sp->size > 0) - s.SRB_Flags |= SRB_DIR_OUT; - } + * copy command into SRB + */ + memcpy(&(s.CDBByte), &sp->cdb, sp->cdb_len); - scsi_debug (scgp,&s); + Event = CreateEvent(NULL, TRUE, FALSE, NULL); - /* - * ------------ Send SCSI command -------------------------- - */ + /* + * Fill ASPI structure + */ + s.SRB_Cmd = SC_EXEC_SCSI_CMD; /* SCSI Command */ + s.SRB_HaId = scg_scsibus(scgp); /* Host adapter number */ + s.SRB_Flags = SRB_EVENT_NOTIFY; /* Flags */ + s.SRB_Target = scg_target(scgp); /* Target SCSI ID */ + s.SRB_Lun = scg_lun(scgp); /* Target SCSI LUN */ + s.SRB_BufLen = sp->size; /* # of bytes transferred */ + s.SRB_BufPointer= sp->addr; /* pointer to data buffer */ + s.SRB_CDBLen = sp->cdb_len; /* SCSI command length */ + s.SRB_PostProc = Event; /* Post proc event */ + s.SRB_SenseLen = SENSE_LEN; /* Lenght of sense buffer */ - ResetEvent (Event); /* Clear event handle */ - Status = pfnSendASPI32Command((LPSRB)&s);/* Initiate SCSI command */ + /* + * Do we receive data from this ASPI command? + */ + if (sp->flags & SCG_RECV_DATA) { + s.SRB_Flags |= SRB_DIR_IN; + } else { + /* + * Set direction to output + */ + if (sp->size > 0) + s.SRB_Flags |= SRB_DIR_OUT; + } + + scsi_debug (scgp,&s); - if (Status == SS_PENDING) { /* If in progress */ /* - * Wait until command completes, or times out. - */ - EventStatus = WaitForSingleObject(Event, sp->timeout * 1000); - if (EventStatus == WAIT_OBJECT_0) - ResetEvent(Event); /* Clear event, time out */ - if (s.SRB_Status == SS_PENDING) {/* Check if we got a timeout*/ - scsiabort(scgp, &s); - ResetEvent(Event); /* Clear event, time out */ - CloseHandle(Event); /* Close the event handle */ - sp->error = SCG_TIMEOUT; - return 1; /* Return error */ + * ------------ Send SCSI command -------------------------- + */ + + ResetEvent (Event); /* Clear event handle */ + Status = pfnSendASPI32Command((LPSRB)&s);/* Initiate SCSI command */ + + if (Status == SS_PENDING) { /* If in progress */ + /* + * Wait until command completes, or times out. + */ + EventStatus = WaitForSingleObject(Event, sp->timeout * 1000); + if (EventStatus == WAIT_OBJECT_0) + ResetEvent(Event); /* Clear event, time out */ + if (s.SRB_Status == SS_PENDING) {/* Check if we got a timeout*/ + scsiabort(scgp, &s); + ResetEvent(Event); /* Clear event, time out */ + CloseHandle(Event); /* Close the event handle */ + sp->error = SCG_TIMEOUT; + return 1; /* Return error */ + } } - } - CloseHandle (Event); /* Close the event handle */ - - /* - * Check ASPI command status - */ - - if (log_scsi && !scanphase) - scsi_log_after ((s.SRB_Flags & SRB_DIR_IN) ? s.SRB_BufPointer : 0, s.SRB_BufLen, - sp->u_sense.cmd_sense, sp->sense_len); - - if (s.SRB_Status != SS_COMP) { - if (log_scsi && s.SRB_Status != 0x82) - write_log (L"ASPI: Error in scgo_send: s.SRB_Status is 0x%x\n", s.SRB_Status); - set_error(&s, sp); /* Set error flags */ - copy_sensedata(&s, sp); /* Copy sense and status */ - if (log_scsi && s.SRB_Status != 0x82) - write_log (L"ASPI: Mapped to: error %d errno: %d\n", sp->error, sp->ux_errno); - return 1; - } - /* - * Return success - */ - return 0; + CloseHandle (Event); /* Close the event handle */ + + /* + * Check ASPI command status + */ + + if (log_scsi && !scanphase) + scsi_log_after ((s.SRB_Flags & SRB_DIR_IN) ? s.SRB_BufPointer : 0, s.SRB_BufLen, + sp->u_sense.cmd_sense, sp->sense_len); + + if (s.SRB_Status != SS_COMP) { + if (log_scsi && s.SRB_Status != 0x82) + write_log (L"ASPI: Error in scgo_send: s.SRB_Status is 0x%x\n", s.SRB_Status); + set_error(&s, sp); /* Set error flags */ + copy_sensedata(&s, sp); /* Copy sense and status */ + if (log_scsi && s.SRB_Status != 0x82) + write_log (L"ASPI: Mapped to: error %d errno: %d\n", sp->error, sp->ux_errno); + return 1; + } + /* + * Return success + */ + return 0; } static int inquiry (SCSI *scgp, void *bp, int cnt) { - struct scg_cmd *scmd = scgp->scmd; - - memset(bp, 0, cnt); - memset(scmd, 0, sizeof(struct scg_cmd)); - scmd->addr = bp; - scmd->size = cnt; - scmd->flags = SCG_RECV_DATA|SCG_DISRE_ENA; - scmd->cdb_len = SC_G0_CDBLEN; - scmd->sense_len = CCS_SENSE_LEN; - scmd->target = scgp->addr.target; - scmd->cdb.g0_cdb.cmd = SC_INQUIRY; - scmd->cdb.g0_cdb.lun = scgp->addr.lun; - scmd->cdb.g0_cdb.count = cnt; - scgp->scmd->timeout = 10 * 60; - if (scsicmd(scgp)) - return -1; - return 0; + struct scg_cmd *scmd = scgp->scmd; + + memset(bp, 0, cnt); + memset(scmd, 0, sizeof(struct scg_cmd)); + scmd->addr = bp; + scmd->size = cnt; + scmd->flags = SCG_RECV_DATA|SCG_DISRE_ENA; + scmd->cdb_len = SC_G0_CDBLEN; + scmd->sense_len = CCS_SENSE_LEN; + scmd->target = scgp->addr.target; + scmd->cdb.g0_cdb.cmd = SC_INQUIRY; + scmd->cdb.g0_cdb.lun = scgp->addr.lun; + scmd->cdb.g0_cdb.count = cnt; + scgp->scmd->timeout = 10 * 60; + if (scsicmd(scgp)) + return -1; + return 0; } static int scsierr(SCSI *scgp) { - register struct scg_cmd *cp = scgp->scmd; + register struct scg_cmd *cp = scgp->scmd; - if(cp->error != SCG_NO_ERROR || - cp->ux_errno != 0 || *(u_char*)&cp->scb != 0) - return -1; - return 0; + if(cp->error != SCG_NO_ERROR || + cp->ux_errno != 0 || *(u_char*)&cp->scb != 0) + return -1; + return 0; } static void scan_scsi_bus (SCSI *scgp, int flags) { - /* add all units we find */ - write_log (L"ASPI: SCSI scan starting..\n"); - scanphase = 1; - for (scgp->addr.scsibus=0; scgp->addr.scsibus < 8; scgp->addr.scsibus++) { - if (!scsi_havebus(scgp, scgp->addr.scsibus)) - continue; - for (scgp->addr.target=0; scgp->addr.target < 16; scgp->addr.target++) { - struct scsi_inquiry inq; - scgp->addr.lun = 0; - if (inquiry (scgp, &inq, sizeof(inq))) - continue; - for (scgp->addr.lun=0; scgp->addr.lun < 8; scgp->addr.lun++) { - if (!inquiry (scgp, &inq, sizeof(inq))) { - TCHAR *vend, *prod, *rev; - char tmp[20]; - - memcpy (tmp, inq.vendor_info, 8); - tmp[8] = 0; - vend = au (tmp); - memcpy (tmp, inq.prod_ident, 16); - tmp[16] = 0; - prod = au (tmp); - memcpy (tmp, inq.prod_revision, 4); - tmp[4] = 0; - rev = au (tmp); - - write_log (L"ASPI: %d:%d:%d '%s' '%s' '%s' ", - scgp->addr.scsibus,scgp->addr.target,scgp->addr.lun, vend, prod, rev); - if (unitcnt < MAX_TOTAL_DEVICES) { - struct scsi_info *cis = &si[unitcnt]; - int use = 0; - write_log (L"["); - if (inq.type == INQ_ROMD) { - write_log (L"CDROM"); - use = 1; - } else if ((inq.type >= INQ_SEQD && inq.type < INQ_COMM && aspi_allow_misc) || aspi_allow_all) { - write_log (L"%d", inq.type); - use = 1; - } else { - write_log (L"<%d>", inq.type); + /* add all units we find */ + write_log (L"ASPI: SCSI scan starting..\n"); + scanphase = 1; + for (scgp->addr.scsibus=0; scgp->addr.scsibus < 8; scgp->addr.scsibus++) { + if (!scsi_havebus(scgp, scgp->addr.scsibus)) + continue; + for (scgp->addr.target=0; scgp->addr.target < 16; scgp->addr.target++) { + struct scsi_inquiry inq; + scgp->addr.lun = 0; + if (inquiry (scgp, &inq, sizeof(inq))) + continue; + for (scgp->addr.lun=0; scgp->addr.lun < 8; scgp->addr.lun++) { + if (!inquiry (scgp, &inq, sizeof(inq))) { + TCHAR *vend, *prod, *rev; + char tmp[20]; + + memcpy (tmp, inq.vendor_info, 8); + tmp[8] = 0; + vend = au (tmp); + memcpy (tmp, inq.prod_ident, 16); + tmp[16] = 0; + prod = au (tmp); + memcpy (tmp, inq.prod_revision, 4); + tmp[4] = 0; + rev = au (tmp); + + write_log (L"ASPI: %d:%d:%d '%s' '%s' '%s' ", + scgp->addr.scsibus,scgp->addr.target,scgp->addr.lun, vend, prod, rev); + if (unitcnt < MAX_TOTAL_DEVICES) { + struct scsi_info *cis = &si[unitcnt]; + int use = 0; + write_log (L"["); + if (inq.type == INQ_ROMD) { + write_log (L"CDROM"); + use = 1; + } else if ((inq.type >= INQ_SEQD && inq.type < INQ_COMM && aspi_allow_misc) || aspi_allow_all) { + write_log (L"%d", inq.type); + use = 1; + } else { + write_log (L"<%d>", inq.type); + } + if (inq.ansi_version == 0) { + write_log (L",ATAPI"); + cis->isatapi = 1; + } else + write_log (L",SCSI"); + write_log (L"]"); + if (use) { + unitcnt++; + cis->buf = malloc (DEVICE_SCSI_BUFSIZE); + cis->scsibus = scgp->addr.scsibus; + cis->target = scgp->addr.target; + cis->lun = scgp->addr.lun; + cis->type = inq.type; + cis->removable = inq.removable; + _stprintf (cis->label, L"%s %s %s", vend, prod, rev); + } + } + write_log (L"\n"); + + xfree (rev); + xfree (prod); + xfree (vend); + } } - if (inq.ansi_version == 0) { - write_log (L",ATAPI"); - cis->isatapi = 1; - } else - write_log (L",SCSI"); - write_log (L"]"); - if (use) { - unitcnt++; - cis->buf = malloc (DEVICE_SCSI_BUFSIZE); - cis->scsibus = scgp->addr.scsibus; - cis->target = scgp->addr.target; - cis->lun = scgp->addr.lun; - cis->type = inq.type; - cis->removable = inq.removable; - _stprintf (cis->label, L"%s %s %s", vend, prod, rev); - } - } - write_log (L"\n"); - - xfree (rev); - xfree (prod); - xfree (vend); } - } } - } - write_log (L"ASPI: SCSI scan ended\n"); - scanphase = 0; + write_log (L"ASPI: SCSI scan ended\n"); + scanphase = 0; } static void aspi_led (int unitnum) { - int type = si[unitnum].type; + int type = si[unitnum].type; - if (type == INQ_ROMD) - gui_cd_led (unitnum, 1); - else if (type == INQ_DASD) - gui_hd_led (unitnum, 1); + if (type == INQ_ROMD) + gui_cd_led (unitnum, 1); + else if (type == INQ_DASD) + gui_hd_led (unitnum, 1); } static uae_sem_t scgp_sem; static uae_u8 *execscsicmd_out (int unitnum, uae_u8 *data, int len) { - SCSI *scgp = si[unitnum].handle; - int v; - - uae_sem_wait (&scgp_sem); - memset(scgp->scmd, 0, sizeof(struct scg_cmd)); - scgp->scmd->cdb_len = len; - memcpy (scgp->scmd->cdb.cmd_cdb, data, len); - scgp->scmd->addr = 0; - scgp->scmd->size = 0; - scgp->addr.scsibus = si[unitnum].scsibus; - scgp->addr.target = si[unitnum].target; - scgp->addr.lun = si[unitnum].lun; - scgp->scmd->timeout = 80 * 60; - scgp->scmd->sense_len = CCS_SENSE_LEN; - aspi_led (unitnum); - v = scsicmd (scgp); - aspi_led (unitnum); - uae_sem_post (&scgp_sem); - if (v) - return 0; - return data; + SCSI *scgp = si[unitnum].handle; + int v; + + uae_sem_wait (&scgp_sem); + memset(scgp->scmd, 0, sizeof(struct scg_cmd)); + scgp->scmd->cdb_len = len; + memcpy (scgp->scmd->cdb.cmd_cdb, data, len); + scgp->scmd->addr = 0; + scgp->scmd->size = 0; + scgp->addr.scsibus = si[unitnum].scsibus; + scgp->addr.target = si[unitnum].target; + scgp->addr.lun = si[unitnum].lun; + scgp->scmd->timeout = 80 * 60; + scgp->scmd->sense_len = CCS_SENSE_LEN; + aspi_led (unitnum); + v = scsicmd (scgp); + aspi_led (unitnum); + uae_sem_post (&scgp_sem); + if (v) + return 0; + return data; } static uae_u8 *execscsicmd_in (int unitnum, uae_u8 *data, int len, int *outlen) { - SCSI *scgp = si[unitnum].handle; - int v; - - uae_sem_wait (&scgp_sem); - memset(scgp->scmd, 0, sizeof(struct scg_cmd)); - scgp->scmd->cdb_len = len; - memcpy (scgp->scmd->cdb.cmd_cdb, data, len); - scgp->scmd->addr = si[unitnum].buf; - scgp->scmd->size = DEVICE_SCSI_BUFSIZE; - scgp->addr.scsibus = si[unitnum].scsibus; - scgp->addr.target = si[unitnum].target; - scgp->addr.lun = si[unitnum].lun; - scgp->scmd->timeout = 80 * 60; - scgp->scmd->flags = SCG_RECV_DATA; - scgp->scmd->sense_len = CCS_SENSE_LEN; - aspi_led (unitnum); - v = scsicmd (scgp); - aspi_led (unitnum); - uae_sem_post (&scgp_sem); - if (v) - return 0; - if (outlen) - *outlen = scgp->scmd->size; - return si[unitnum].buf; + SCSI *scgp = si[unitnum].handle; + int v; + + uae_sem_wait (&scgp_sem); + memset(scgp->scmd, 0, sizeof(struct scg_cmd)); + scgp->scmd->cdb_len = len; + memcpy (scgp->scmd->cdb.cmd_cdb, data, len); + scgp->scmd->addr = si[unitnum].buf; + scgp->scmd->size = DEVICE_SCSI_BUFSIZE; + scgp->addr.scsibus = si[unitnum].scsibus; + scgp->addr.target = si[unitnum].target; + scgp->addr.lun = si[unitnum].lun; + scgp->scmd->timeout = 80 * 60; + scgp->scmd->flags = SCG_RECV_DATA; + scgp->scmd->sense_len = CCS_SENSE_LEN; + aspi_led (unitnum); + v = scsicmd (scgp); + aspi_led (unitnum); + uae_sem_post (&scgp_sem); + if (v) + return 0; + if (outlen) + *outlen = scgp->scmd->size; + return si[unitnum].buf; } static SCSI *scsi_handle; static int open_scsi_bus (int flags) { - SCSI *scgp = openscsi (-1, -1, -1); - unitcnt = 0; - if (scgp) { - scan_scsi_bus (scgp, flags); - uae_sem_init (&scgp_sem, 0, 1); - } - scsi_handle = scgp; - return scgp ? 1 : 0; + SCSI *scgp = openscsi (-1, -1, -1); + unitcnt = 0; + if (scgp) { + scan_scsi_bus (scgp, flags); + uae_sem_init (&scgp_sem, 0, 1); + } + scsi_handle = scgp; + return scgp ? 1 : 0; } static int mediacheck (int unitnum) { - uae_u8 cmd [6] = { 0,0,0,0,0,0 }; /* TEST UNIT READY */ - if (si[unitnum].handle == 0) - return 0; - return execscsicmd_out(unitnum, cmd, sizeof(cmd)) ? 1 : 0; + uae_u8 cmd [6] = { 0,0,0,0,0,0 }; /* TEST UNIT READY */ + if (si[unitnum].handle == 0) + return 0; + return execscsicmd_out(unitnum, cmd, sizeof(cmd)) ? 1 : 0; } static int mediacheck_full (int unitnum, struct device_info *di) { - uae_u8 cmd1[10] = { 0x25,0,0,0,0,0,0,0,0,0 }; /* READ CAPACITY */ - int ok, outlen; - uae_u8 *p = si[unitnum].buf; - - 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->sectorspertrack = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]) + 1; - 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; + uae_u8 cmd1[10] = { 0x25,0,0,0,0,0,0,0,0,0 }; /* READ CAPACITY */ + int ok, outlen; + uae_u8 *p = si[unitnum].buf; + + 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->write_protected = (p[3] & 0x80) ? 1 : 0; + di->bytespersector = (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]; + di->sectorspertrack = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]) + 1; + 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; + } } - } - return 1; + return 1; } static int open_scsi_device (int unitnum) { - if (unitnum >= unitcnt) - return 0; - if (log_scsi) - write_log (L"ASPI: opening %d:%d:%d (%d)\n", si[unitnum].scsibus, si[unitnum].target, si[unitnum].lun, unitnum); - si[unitnum].handle = openscsi (si[unitnum].scsibus, si[unitnum].target, si[unitnum].lun); - if (si[unitnum].handle) - si[unitnum].mediainserted = mediacheck (unitnum); - if (log_scsi) - write_log (L"unit %d: %s\n", unitnum, si[unitnum].mediainserted ? L"CD inserted" : L"Drive empty"); - return si[unitnum].handle ? 1 : 0; + if (unitnum >= unitcnt) + return 0; + if (log_scsi) + write_log (L"ASPI: opening %d:%d:%d (%d)\n", si[unitnum].scsibus, si[unitnum].target, si[unitnum].lun, unitnum); + si[unitnum].handle = openscsi (si[unitnum].scsibus, si[unitnum].target, si[unitnum].lun); + if (si[unitnum].handle) + si[unitnum].mediainserted = mediacheck (unitnum); + if (log_scsi) + write_log (L"unit %d: %s\n", unitnum, si[unitnum].mediainserted ? L"CD inserted" : L"Drive empty"); + return si[unitnum].handle ? 1 : 0; } static void close_scsi_device (int unitnum) { - if (unitnum >= unitcnt) - return; - if (!si[unitnum].handle) - return; - scsi_sfree (si[unitnum].handle); - si[unitnum].handle = 0; + if (unitnum >= unitcnt) + return; + if (!si[unitnum].handle) + return; + scsi_sfree (si[unitnum].handle); + si[unitnum].handle = 0; } static void close_scsi_bus (void) { - closescsi (scsi_handle); - scsi_handle = 0; + closescsi (scsi_handle); + scsi_handle = 0; } static int execscsicmd_direct (int unitnum, struct amigascsi *as) { - int sactual = 0, i, parm; - SCSI *scgp = si[unitnum].handle; - struct scg_cmd *scmd = scgp->scmd; - int scsi_cmd_len_org = as->cmd_len; - int io_error = 0; - uae_u8 *scsi_datap, *scsi_datap_org; - - uae_sem_wait (&scgp_sem); - - /* the Amiga does not tell us how long the timeout shall be, so make it _very_ long (specified in seconds) */ - scmd->timeout = 80 * 60; - scsi_datap = scsi_datap_org = as->len ? as->data : 0; - scmd->flags = ((as->flags & 1) ? SCG_RECV_DATA : 0) | SCG_DISRE_ENA; - for (i = 0; i < as->cmd_len; i++) - scmd->cdb.cmd_cdb[i] = as->cmd[i]; - scmd->target = si[unitnum].target; - scmd->sense_len = (as->flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ - (as->flags & 2) ? as->sense_len : /* SCSIF_AUTOSENSE */ - -1; - scmd->sense_count = 0; - scmd->u_scb.cmd_scb[0] = 0; - scgp->addr.scsibus = si[unitnum].scsibus; - scgp->addr.target = si[unitnum].target; - scgp->addr.lun = si[unitnum].lun; - if (si[unitnum].isatapi) - scsi_atapi_fixup_pre (scmd->cdb.cmd_cdb, &as->cmd_len, &scsi_datap, &as->len, &parm); - scmd->addr = scsi_datap; - scmd->size = as->len; - scmd->cdb_len = as->cmd_len; - aspi_led (unitnum); - scsicmd (scgp); - aspi_led (unitnum); - - as->cmdactual = scmd->error == SCG_FATAL ? 0 : scsi_cmd_len_org; /* fake scsi_CmdActual */ - as->status = scmd->u_scb.cmd_scb[0]; /* scsi_Status */ - if (scmd->u_scb.cmd_scb[0]) { - io_error = 45; /* HFERR_BadStatus */ - /* copy sense? */ - for (sactual = 0; sactual < as->sense_len && sactual < scmd->sense_count; sactual++) - as->sensedata[sactual] = scmd->u_sense.cmd_sense[sactual]; - as->actual = 0; /* scsi_Actual */ - } else { - int i; - for (i = 0; i < as->sense_len; i++) - as->sensedata[i] = 0; - sactual = 0; - if (scmd->error != SCG_NO_ERROR) { - io_error = 20; /* io_Error, but not specified */ - as->actual = 0; /* scsi_Actual */ + int sactual = 0, i, parm; + SCSI *scgp = si[unitnum].handle; + struct scg_cmd *scmd = scgp->scmd; + int scsi_cmd_len_org = as->cmd_len; + int io_error = 0; + uae_u8 *scsi_datap, *scsi_datap_org; + + uae_sem_wait (&scgp_sem); + + /* the Amiga does not tell us how long the timeout shall be, so make it _very_ long (specified in seconds) */ + scmd->timeout = 80 * 60; + scsi_datap = scsi_datap_org = as->len ? as->data : 0; + scmd->flags = ((as->flags & 1) ? SCG_RECV_DATA : 0) | SCG_DISRE_ENA; + for (i = 0; i < as->cmd_len; i++) + scmd->cdb.cmd_cdb[i] = as->cmd[i]; + scmd->target = si[unitnum].target; + scmd->sense_len = (as->flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ + (as->flags & 2) ? as->sense_len : /* SCSIF_AUTOSENSE */ + -1; + scmd->sense_count = 0; + scmd->u_scb.cmd_scb[0] = 0; + scgp->addr.scsibus = si[unitnum].scsibus; + scgp->addr.target = si[unitnum].target; + scgp->addr.lun = si[unitnum].lun; + if (si[unitnum].isatapi) + scsi_atapi_fixup_pre (scmd->cdb.cmd_cdb, &as->cmd_len, &scsi_datap, &as->len, &parm); + scmd->addr = scsi_datap; + scmd->size = as->len; + scmd->cdb_len = as->cmd_len; + aspi_led (unitnum); + scsicmd (scgp); + aspi_led (unitnum); + + as->cmdactual = scmd->error == SCG_FATAL ? 0 : scsi_cmd_len_org; /* fake scsi_CmdActual */ + as->status = scmd->u_scb.cmd_scb[0]; /* scsi_Status */ + if (scmd->u_scb.cmd_scb[0]) { + io_error = 45; /* HFERR_BadStatus */ + /* copy sense? */ + for (sactual = 0; sactual < as->sense_len && sactual < scmd->sense_count; sactual++) + as->sensedata[sactual] = scmd->u_sense.cmd_sense[sactual]; + as->actual = 0; /* scsi_Actual */ } else { - io_error = 0; - if (si[unitnum].isatapi) - scsi_atapi_fixup_post (scmd->cdb.cmd_cdb, as->cmd_len, scsi_datap_org, scsi_datap, &as->len, parm); - as->actual = as->len - scmd->resid; /* scsi_Actual */ + int i; + for (i = 0; i < as->sense_len; i++) + as->sensedata[i] = 0; + sactual = 0; + if (scmd->error != SCG_NO_ERROR) { + io_error = 20; /* io_Error, but not specified */ + as->actual = 0; /* scsi_Actual */ + } else { + io_error = 0; + if (si[unitnum].isatapi) + scsi_atapi_fixup_post (scmd->cdb.cmd_cdb, as->cmd_len, scsi_datap_org, scsi_datap, &as->len, parm); + as->actual = as->len - scmd->resid; /* scsi_Actual */ + } } - } - as->sactual = sactual; + as->sactual = sactual; - uae_sem_post (&scgp_sem); + uae_sem_post (&scgp_sem); - if (scsi_datap != scsi_datap_org) - free (scsi_datap); + if (scsi_datap != scsi_datap_org) + free (scsi_datap); - return io_error; + return io_error; } 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 = sif->scsibus; - di->target = sif->target; - di->lun = sif->lun; - di->media_inserted = mediacheck (unitnum); - di->type = sif->type; - mediacheck_full (unitnum, di); - di->id = unitnum + 1; - di->removable = sif->removable; - _tcscpy (di->label, sif->label); - if (log_scsi) { - write_log (L"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); - } - return di; + struct scsi_info *sif = &si[unitnum]; + if (unitnum >= unitcnt) + return 0; + di->bus = sif->scsibus; + di->target = sif->target; + di->lun = sif->lun; + di->media_inserted = mediacheck (unitnum); + di->type = sif->type; + mediacheck_full (unitnum, di); + di->id = unitnum + 1; + di->removable = sif->removable; + _tcscpy (di->label, sif->label); + if (log_scsi) { + write_log (L"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); + } + return di; } void win32_aspi_media_change (TCHAR driveletter, int insert) { - int i, now; + int i, now; - for (i = 0; i < unitcnt; i++) { - if (si[i].type == INQ_ROMD) { - now = mediacheck (i); - if (now != si[i].mediainserted) { - write_log (L"ASPI: media change %c %d\n", driveletter, insert); - si[i].mediainserted = now; - scsi_do_disk_change (i + 1, insert); - } + for (i = 0; i < unitcnt; i++) { + if (si[i].type == INQ_ROMD) { + now = mediacheck (i); + if (now != si[i].mediainserted) { + write_log (L"ASPI: media change %c %d\n", driveletter, insert); + si[i].mediainserted = now; + scsi_do_disk_change (i + 1, insert); + } + } } - } } static int check_isatapi (int unitnum) { - return si[unitnum].isatapi; + return si[unitnum].isatapi; } static struct device_scsi_info *scsi_info (int unitnum, struct device_scsi_info *dsi) { - dsi->buffer = si[unitnum].buf; - dsi->bufsize = DEVICE_SCSI_BUFSIZE; - return dsi; + dsi->buffer = si[unitnum].buf; + dsi->bufsize = DEVICE_SCSI_BUFSIZE; + return dsi; } struct device_functions devicefunc_win32_aspi = { - open_scsi_bus, close_scsi_bus, open_scsi_device, close_scsi_device, info_device, - execscsicmd_out, execscsicmd_in, execscsicmd_direct, - 0, 0, 0, 0, 0, 0, 0, 0, check_isatapi, scsi_info, 0 + open_scsi_bus, close_scsi_bus, open_scsi_device, close_scsi_device, info_device, + execscsicmd_out, execscsicmd_in, execscsicmd_direct, + 0, 0, 0, 0, 0, 0, 0, 0, check_isatapi, scsi_info, 0 }; diff --git a/od-win32/blkdev_win32_ioctl.c b/od-win32/blkdev_win32_ioctl.c index 1a73c9e0..f8b04ff2 100644 --- a/od-win32/blkdev_win32_ioctl.c +++ b/od-win32/blkdev_win32_ioctl.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * WIN32 CDROM/HD low level access code (IOCTL) - * - * Copyright 2002 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* WIN32 CDROM/HD low level access code (IOCTL) +* +* Copyright 2002 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -30,18 +30,18 @@ #include struct dev_info_ioctl { - HANDLE h; - uae_u8 *tempbuffer; - TCHAR drvletter; - TCHAR devname[30]; - int mediainserted; - int type; - int blocksize; - int mciid; - CDROM_TOC toc; - UINT errormode; - int playend; - int fullaccess; + HANDLE h; + uae_u8 *tempbuffer; + TCHAR drvletter; + TCHAR devname[30]; + int mediainserted; + int type; + int blocksize; + int mciid; + CDROM_TOC toc; + UINT errormode; + int playend; + int fullaccess; }; #define IOCTL_DATA_BUFFER 4096 @@ -52,11 +52,11 @@ static struct dev_info_ioctl ciw32[MAX_TOTAL_DEVICES]; static void seterrormode (int unitnum) { - ciw32[unitnum].errormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + ciw32[unitnum].errormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); } static void reseterrormode (int unitnum) { - SetErrorMode (ciw32[unitnum].errormode); + SetErrorMode (ciw32[unitnum].errormode); } static void close_device (int unitnum); @@ -64,768 +64,768 @@ static int open_device (int unitnum); static int mcierr (TCHAR *str, DWORD err) { - TCHAR es[1000]; - if (err == MMSYSERR_NOERROR) - return MMSYSERR_NOERROR; - if (mciGetErrorString (err, es, sizeof es)) - write_log (L"MCIErr: %s: %d = '%s'\n", str, err, es); - return err; + TCHAR es[1000]; + if (err == MMSYSERR_NOERROR) + return MMSYSERR_NOERROR; + if (mciGetErrorString (err, es, sizeof es)) + write_log (L"MCIErr: %s: %d = '%s'\n", str, err, es); + return err; } static int win32_error (int unitnum, const TCHAR *format,...) { - LPVOID lpMsgBuf; - va_list arglist; - TCHAR buf[1000]; - DWORD err = GetLastError (); + LPVOID lpMsgBuf; + va_list arglist; + TCHAR buf[1000]; + DWORD err = GetLastError (); - if (err == ERROR_WRONG_DISK) { - write_log (L"IOCTL: media change, re-opening device\n"); - close_device (unitnum); - if (!open_device (unitnum)) - write_log (L"IOCTL: re-opening failed!\n"); - return -1; - } - va_start (arglist, format ); - _vstprintf (buf, format, arglist); - FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, 0, NULL); - if (log_scsi) - write_log (L"IOCTL: unit=%d %s,%d: %s\n", unitnum, buf, err, (TCHAR*)lpMsgBuf); - va_end (arglist); - return err; + if (err == ERROR_WRONG_DISK) { + write_log (L"IOCTL: media change, re-opening device\n"); + close_device (unitnum); + if (!open_device (unitnum)) + write_log (L"IOCTL: re-opening failed!\n"); + return -1; + } + va_start (arglist, format); + _vsntprintf (buf, sizeof buf / sizeof (TCHAR), format, arglist); + FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&lpMsgBuf, 0, NULL); + if (log_scsi) + write_log (L"IOCTL: unit=%d %s,%d: %s\n", unitnum, buf, err, (TCHAR*)lpMsgBuf); + va_end (arglist); + return err; } static int close_createfile (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - ciw->fullaccess = 0; - if (ciw->h != INVALID_HANDLE_VALUE) { - if (log_scsi) - write_log (L"IOCTL: IOCTL close\n"); - CloseHandle (ciw->h); - if (log_scsi) - write_log (L"IOCTL: IOCTL close completed\n"); - ciw->h = INVALID_HANDLE_VALUE; - return 1; - } - return 0; + ciw->fullaccess = 0; + if (ciw->h != INVALID_HANDLE_VALUE) { + if (log_scsi) + write_log (L"IOCTL: IOCTL close\n"); + CloseHandle (ciw->h); + if (log_scsi) + write_log (L"IOCTL: IOCTL close completed\n"); + ciw->h = INVALID_HANDLE_VALUE; + return 1; + } + return 0; } static int close_mci (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - MCI_GENERIC_PARMS gp = { 0 }; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; + MCI_GENERIC_PARMS gp = { 0 }; - ciw->playend = -1; - if (ciw->mciid > 0) { - if (log_scsi) - write_log (L"IOCTL: MCI close\n"); - mcierr (L"MCI_STOP", mciSendCommand (ciw->mciid, MCI_STOP, MCI_WAIT, (DWORD_PTR)&gp)); - mcierr (L"MCI_CLOSE", mciSendCommand (ciw->mciid, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)&gp)); - if (log_scsi) - write_log (L"IOCTL: MCI close completed\n"); - ciw->mciid = 0; - return 1; - } - return 0; + ciw->playend = -1; + if (ciw->mciid > 0) { + if (log_scsi) + write_log (L"IOCTL: MCI close\n"); + mcierr (L"MCI_STOP", mciSendCommand (ciw->mciid, MCI_STOP, MCI_WAIT, (DWORD_PTR)&gp)); + mcierr (L"MCI_CLOSE", mciSendCommand (ciw->mciid, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)&gp)); + if (log_scsi) + write_log (L"IOCTL: MCI close completed\n"); + ciw->mciid = 0; + return 1; + } + return 0; } static int open_createfile (int unitnum, int fullaccess) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - int closed = 0; - int cnt = 50; - DWORD len; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; + int closed = 0; + int cnt = 50; + DWORD len; - if (ciw->h != INVALID_HANDLE_VALUE) { - if (fullaccess && ciw->fullaccess == 0) { - close_createfile (unitnum); - } else { - return 1; + if (ciw->h != INVALID_HANDLE_VALUE) { + if (fullaccess && ciw->fullaccess == 0) { + close_createfile (unitnum); + } else { + return 1; + } } - } - closed = close_mci (unitnum); - if (log_scsi) - write_log (L"IOCTL: opening IOCTL %s\n", ciw->devname); - for (;;) { - if (fullaccess) { - ciw->h = CreateFile (ciw->devname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (ciw->h != INVALID_HANDLE_VALUE) - ciw->fullaccess = 1; - } else { - DWORD flags = GENERIC_READ; - ciw->h = CreateFile (ciw->devname, flags, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (ciw->h == INVALID_HANDLE_VALUE) { - ciw->h = CreateFile (ciw->devname, flags, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + closed = close_mci (unitnum); + if (log_scsi) + write_log (L"IOCTL: opening IOCTL %s\n", ciw->devname); + for (;;) { + if (fullaccess) { + ciw->h = CreateFile (ciw->devname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (ciw->h != INVALID_HANDLE_VALUE) + ciw->fullaccess = 1; + } else { + DWORD flags = GENERIC_READ; + ciw->h = CreateFile (ciw->devname, flags, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (ciw->h == INVALID_HANDLE_VALUE) { + ciw->h = CreateFile (ciw->devname, flags, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (ciw->h == INVALID_HANDLE_VALUE) { + flags |= GENERIC_WRITE; + ciw->h = CreateFile (ciw->devname, flags, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + } + } + } if (ciw->h == INVALID_HANDLE_VALUE) { - flags |= GENERIC_WRITE; - ciw->h = CreateFile (ciw->devname, flags, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - } - } - } - if (ciw->h == INVALID_HANDLE_VALUE) { - DWORD err = GetLastError (); - if (err == ERROR_SHARING_VIOLATION) { - if (closed && cnt > 0) { - cnt--; - Sleep (10); - continue; + DWORD err = GetLastError (); + if (err == ERROR_SHARING_VIOLATION) { + if (closed && cnt > 0) { + cnt--; + Sleep (10); + continue; + } + } + if (closed) + write_log (L"IOCTL: failed to re-open '%s', err=%d\n", ciw->devname, GetLastError ()); + return 0; } - } - if (closed) - write_log (L"IOCTL: failed to re-open '%s', err=%d\n", ciw->devname, GetLastError ()); - return 0; + break; } - break; - } - if (!DeviceIoControl (ciw->h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &len, NULL)) - write_log (L"IOCTL: FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", GetLastError ()); - if (log_scsi) - write_log (L"IOCTL: IOCTL open completed\n"); - return 1; + if (!DeviceIoControl (ciw->h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &len, NULL)) + write_log (L"IOCTL: FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", GetLastError ()); + if (log_scsi) + write_log (L"IOCTL: IOCTL open completed\n"); + return 1; } static int open_mci (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - TCHAR elname[10]; - TCHAR alname[100]; - MCI_OPEN_PARMS mciOpen; - DWORD err, flags; - int closed = 0; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; + TCHAR elname[10]; + TCHAR alname[100]; + MCI_OPEN_PARMS mciOpen; + DWORD err, flags; + int closed = 0; - if (ciw->mciid > 0 || MCICDA == 0) + if (ciw->mciid > 0 || MCICDA == 0) + return 1; + ciw->playend = -1; + closed = close_createfile (unitnum); + if (log_scsi) + write_log (L"IOCTL: MCI opening %c:\n", ciw->drvletter); + memset (&mciOpen, 0, sizeof (mciOpen)); + mciOpen.lpstrDeviceType = (LPWSTR)MCI_DEVTYPE_CD_AUDIO; + _stprintf (elname, L"%c:", ciw->drvletter); + _stprintf (alname, L"CD%u:", GetCurrentTime ()); + mciOpen.lpstrElementName = elname; + mciOpen.lpstrAlias = alname; + flags = MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE | MCI_OPEN_ALIAS | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT; + err = mciSendCommand (0, MCI_OPEN, flags, (DWORD_PTR)(LPVOID)&mciOpen); + ciw->mciid = mciOpen.wDeviceID; + if (err != MMSYSERR_NOERROR) { + if (closed) + mcierr (L"MCI_OPEN", err); + return 0; + } + if (log_scsi) + write_log (L"IOCTL: MCI open completed\n"); return 1; - ciw->playend = -1; - closed = close_createfile (unitnum); - if (log_scsi) - write_log (L"IOCTL: MCI opening %c:\n", ciw->drvletter); - memset (&mciOpen, 0, sizeof (mciOpen)); - mciOpen.lpstrDeviceType = (LPWSTR)MCI_DEVTYPE_CD_AUDIO; - _stprintf (elname, L"%c:", ciw->drvletter); - _stprintf (alname, L"CD%u:", GetCurrentTime ()); - mciOpen.lpstrElementName = elname; - mciOpen.lpstrAlias = alname; - flags = MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE | MCI_OPEN_ALIAS | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT; - err = mciSendCommand (0, MCI_OPEN, flags, (DWORD_PTR)(LPVOID)&mciOpen); - ciw->mciid = mciOpen.wDeviceID; - if (err != MMSYSERR_NOERROR) { - if (closed) - mcierr (L"MCI_OPEN", err); - return 0; - } - if (log_scsi) - write_log (L"IOCTL: MCI open completed\n"); - return 1; } /* pause/unpause CD audio */ static int ioctl_command_pause (int unitnum, int paused) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - if (ciw->mciid > 0) { + if (ciw->mciid > 0) { - MCI_GENERIC_PARMS gp = { 0 }; - if (paused) - mcierr(L"MCI_PAUSE", mciSendCommand (ciw->mciid, MCI_PAUSE, MCI_WAIT, (DWORD_PTR)&gp)); - else - mcierr(L"MCI_RESUME", mciSendCommand (ciw->mciid, MCI_RESUME, MCI_WAIT, (DWORD_PTR)&gp)); + MCI_GENERIC_PARMS gp = { 0 }; + if (paused) + mcierr(L"MCI_PAUSE", mciSendCommand (ciw->mciid, MCI_PAUSE, MCI_WAIT, (DWORD_PTR)&gp)); + else + mcierr(L"MCI_RESUME", mciSendCommand (ciw->mciid, MCI_RESUME, MCI_WAIT, (DWORD_PTR)&gp)); - } else { - - DWORD len; - int command = paused ? IOCTL_CDROM_PAUSE_AUDIO : IOCTL_CDROM_RESUME_AUDIO; - int cnt = 3; + } else { - while (cnt-- > 0) { - seterrormode (unitnum); - if (!DeviceIoControl(ciw32[unitnum].h, command, NULL, 0, NULL, 0, &len, NULL)) { - reseterrormode (unitnum); - if (win32_error (unitnum, paused ? L"IOCTL_CDROM_PAUSE_AUDIO" : L"IOCTL_CDROM_RESUME_AUDIO") < 0) - continue; - return 0; - } - reseterrormode (unitnum); - break; + DWORD len; + int command = paused ? IOCTL_CDROM_PAUSE_AUDIO : IOCTL_CDROM_RESUME_AUDIO; + int cnt = 3; + + while (cnt-- > 0) { + seterrormode (unitnum); + if (!DeviceIoControl(ciw32[unitnum].h, command, NULL, 0, NULL, 0, &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, paused ? L"IOCTL_CDROM_PAUSE_AUDIO" : L"IOCTL_CDROM_RESUME_AUDIO") < 0) + continue; + return 0; + } + reseterrormode (unitnum); + break; + } } - } - return 1; + return 1; } /* stop CD audio */ static int ioctl_command_stop (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - - if (ciw->mciid > 0) { + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - MCI_GENERIC_PARMS gp = { 0 }; - mcierr (L"MCI_STOP", mciSendCommand (ciw->mciid, MCI_STOP, MCI_WAIT, (DWORD_PTR)&gp)); - ciw->playend = -1; + if (ciw->mciid > 0) { - } else { + MCI_GENERIC_PARMS gp = { 0 }; + mcierr (L"MCI_STOP", mciSendCommand (ciw->mciid, MCI_STOP, MCI_WAIT, (DWORD_PTR)&gp)); + ciw->playend = -1; - DWORD len; - int cnt = 3; + } else { - while (cnt-- > 0) { - seterrormode (unitnum); - if(!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &len, NULL)) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"IOCTL_CDROM_STOP_AUDIO") < 0) - continue; - return 0; - } - reseterrormode (unitnum); - break; + DWORD len; + int cnt = 3; + + while (cnt-- > 0) { + seterrormode (unitnum); + if(!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"IOCTL_CDROM_STOP_AUDIO") < 0) + continue; + return 0; + } + reseterrormode (unitnum); + break; + } } - } - return 1; + return 1; } /* play CD audio */ static int ioctl_command_play (int unitnum, uae_u32 start, uae_u32 end, int scan) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - open_mci (unitnum); + open_mci (unitnum); - if (ciw->mciid > 0) { + if (ciw->mciid > 0) { - MCI_SET_PARMS setParms = {0}; - MCI_PLAY_PARMS playParms = {0}; + MCI_SET_PARMS setParms = {0}; + MCI_PLAY_PARMS playParms = {0}; - setParms.dwTimeFormat = MCI_FORMAT_MSF; - mcierr (L"MCI_SET", mciSendCommand (ciw->mciid, MCI_SET, MCI_SET_TIME_FORMAT | MCI_WAIT, (DWORD_PTR)&setParms)); - playParms.dwFrom = MCI_MAKE_MSF((start >> 16) & 0xff, (start >> 8) & 0xff, start & 0xff); - playParms.dwTo = MCI_MAKE_MSF((end >> 16) & 0xff, (end >> 8) & 0xff, end & 0xff); - mcierr (L"MCI_PLAY", mciSendCommand (ciw->mciid, MCI_PLAY, MCI_FROM | MCI_TO, (DWORD_PTR)&playParms)); - ciw->playend = end; + setParms.dwTimeFormat = MCI_FORMAT_MSF; + mcierr (L"MCI_SET", mciSendCommand (ciw->mciid, MCI_SET, MCI_SET_TIME_FORMAT | MCI_WAIT, (DWORD_PTR)&setParms)); + playParms.dwFrom = MCI_MAKE_MSF((start >> 16) & 0xff, (start >> 8) & 0xff, start & 0xff); + playParms.dwTo = MCI_MAKE_MSF((end >> 16) & 0xff, (end >> 8) & 0xff, end & 0xff); + mcierr (L"MCI_PLAY", mciSendCommand (ciw->mciid, MCI_PLAY, MCI_FROM | MCI_TO, (DWORD_PTR)&playParms)); + ciw->playend = end; - } else { + } else { - DWORD len; - CDROM_PLAY_AUDIO_MSF pa; - int cnt = 3; + DWORD len; + CDROM_PLAY_AUDIO_MSF pa; + int cnt = 3; #if 0 - { - VOLUME_CONTROL vc; - if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_GET_VOLUME, NULL, 0, &vc, sizeof(vc), &len, NULL)) - write_log (L"IOCTL_CDROM_GET_VOLUME %d\n", GetLastError()); - vc.PortVolume[0] = 0xff; - vc.PortVolume[1] = 0xff; - vc.PortVolume[2] = 0xff; - vc.PortVolume[3] = 0xff; - if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_SET_VOLUME, &vc, sizeof(vc), NULL, 0, &len, NULL)) - write_log (L"IOCTL_CDROM_SET_VOLUME %d\n", GetLastError()); - } + { + VOLUME_CONTROL vc; + if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_GET_VOLUME, NULL, 0, &vc, sizeof(vc), &len, NULL)) + write_log (L"IOCTL_CDROM_GET_VOLUME %d\n", GetLastError()); + vc.PortVolume[0] = 0xff; + vc.PortVolume[1] = 0xff; + vc.PortVolume[2] = 0xff; + vc.PortVolume[3] = 0xff; + if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_SET_VOLUME, &vc, sizeof(vc), NULL, 0, &len, NULL)) + write_log (L"IOCTL_CDROM_SET_VOLUME %d\n", GetLastError()); + } #endif - while (cnt-- > 0) { - pa.StartingM = start >> 16; - pa.StartingS = start >> 8; - pa.StartingF = start >> 0; - pa.EndingM = end >> 16; - pa.EndingS = end >> 8; - pa.EndingF = end >> 0; - seterrormode (unitnum); - if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_PLAY_AUDIO_MSF, &pa, sizeof(pa), NULL, 0, &len, NULL)) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"IOCTL_CDROM_PLAY_AUDIO_MSF %02.%02.%02-%02.%02.%02", - pa.StartingM, pa.StartingS, pa.StartingF, pa.EndingM, pa.EndingS, pa.EndingF ) < 0) continue; - return 0; - } - reseterrormode (unitnum); - break; + while (cnt-- > 0) { + pa.StartingM = start >> 16; + pa.StartingS = start >> 8; + pa.StartingF = start >> 0; + pa.EndingM = end >> 16; + pa.EndingS = end >> 8; + pa.EndingF = end >> 0; + seterrormode (unitnum); + if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_PLAY_AUDIO_MSF, &pa, sizeof(pa), NULL, 0, &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"IOCTL_CDROM_PLAY_AUDIO_MSF %02.%02.%02-%02.%02.%02", + pa.StartingM, pa.StartingS, pa.StartingF, pa.EndingM, pa.EndingS, pa.EndingF ) < 0) continue; + return 0; + } + reseterrormode (unitnum); + break; + } } - } - return 1; + return 1; } /* convert minutes, seconds and frames -> logical sector number */ static int msf2lsn (int msf) { - int sector = (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff)); - return sector; + int sector = (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff)); + return sector; } /* convert logical sector number -> minutes, seconds and frames */ static int lsn2msf (int sectors) { - int msf; - msf = (sectors / (75 * 60)) << 16; - msf |= ((sectors / 75) % 60) << 8; - msf |= (sectors % 75) << 0; - return msf; + int msf; + msf = (sectors / (75 * 60)) << 16; + msf |= ((sectors / 75) % 60) << 8; + msf |= (sectors % 75) << 0; + return msf; } /* read qcode */ static uae_u8 *ioctl_command_qcode (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - - if (ciw->mciid > 0) { - - static uae_u8 buf[4 + 12]; - MCI_STATUS_PARMS mciStatusParms; - DWORD err, mode; - uae_u8 *p; - uae_u32 pos, pos2; - int trk; - - memset (buf, 0, sizeof buf); - memset (&mciStatusParms, 0, sizeof mciStatusParms); - mciStatusParms.dwItem = MCI_STATUS_MODE; - err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); - if (err != MMSYSERR_NOERROR) - return 0; - mode = mciStatusParms.dwReturn; - mciStatusParms.dwItem = MCI_STATUS_CURRENT_TRACK; - err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); - if (err != MMSYSERR_NOERROR) - return 0; - trk = mciStatusParms.dwReturn - 1; - if (trk < 0) - trk = 0; - mciStatusParms.dwItem = MCI_STATUS_POSITION; - err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); - if (err != MMSYSERR_NOERROR) - return 0; - pos = (((mciStatusParms.dwReturn >> 16) & 0xff) << 0) | (((mciStatusParms.dwReturn >> 8) & 0xff) << 8) | (((mciStatusParms.dwReturn >> 0) & 0xff) << 16); - - p = buf; - p[1] = AUDIO_STATUS_NO_STATUS; - if (mode == MCI_MODE_PLAY) - p[1] = AUDIO_STATUS_IN_PROGRESS; - else if (mode == MCI_MODE_PAUSE) - p[1] = AUDIO_STATUS_PAUSED; - p[3] = 12; - - p = buf + 4; - p[1] = (ciw->toc.TrackData[trk].Control << 0) | (ciw->toc.TrackData[trk].Adr << 4); - p[2] = trk + 1; - p[3] = 1; - - p[5] = (pos >> 16) & 0xff; - p[6] = (pos >> 8) & 0xff; - p[7] = (pos >> 0) & 0xff; - - pos = msf2lsn (pos); - pos2 = (ciw->toc.TrackData[trk].Address[1] << 16) | (ciw->toc.TrackData[trk].Address[2] << 8) | (ciw->toc.TrackData[trk].Address[3] << 0); - pos -= msf2lsn (pos2); - if (pos < 0) - pos = 0; - pos = lsn2msf (pos); - - p[9] = (pos >> 16) & 0xff; - p[10] = (pos >> 8) & 0xff; - p[11] = (pos >> 0) & 0xff; - - return buf; - - } else { - - SUB_Q_CHANNEL_DATA qcd; - DWORD len; - ULONG in = 1; - uae_u8 *p = ciw32[unitnum].tempbuffer; - int cnt = 3; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - memset (p, 0, 4 + 12); - p[1] = 0x15; - p[3] = 12; - while (cnt-- > 0) { - reseterrormode (unitnum); - if(!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_READ_Q_CHANNEL, &in, sizeof(in), &qcd, sizeof (qcd), &len, NULL)) { + if (ciw->mciid > 0) { + + static uae_u8 buf[4 + 12]; + MCI_STATUS_PARMS mciStatusParms; + DWORD err, mode; + uae_u8 *p; + uae_u32 pos, pos2; + int trk; + + memset (buf, 0, sizeof buf); + memset (&mciStatusParms, 0, sizeof mciStatusParms); + mciStatusParms.dwItem = MCI_STATUS_MODE; + err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); + if (err != MMSYSERR_NOERROR) + return 0; + mode = mciStatusParms.dwReturn; + mciStatusParms.dwItem = MCI_STATUS_CURRENT_TRACK; + err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); + if (err != MMSYSERR_NOERROR) + return 0; + trk = mciStatusParms.dwReturn - 1; + if (trk < 0) + trk = 0; + mciStatusParms.dwItem = MCI_STATUS_POSITION; + err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); + if (err != MMSYSERR_NOERROR) + return 0; + pos = (((mciStatusParms.dwReturn >> 16) & 0xff) << 0) | (((mciStatusParms.dwReturn >> 8) & 0xff) << 8) | (((mciStatusParms.dwReturn >> 0) & 0xff) << 16); + + p = buf; + p[1] = AUDIO_STATUS_NO_STATUS; + if (mode == MCI_MODE_PLAY) + p[1] = AUDIO_STATUS_IN_PROGRESS; + else if (mode == MCI_MODE_PAUSE) + p[1] = AUDIO_STATUS_PAUSED; + p[3] = 12; + + p = buf + 4; + p[1] = (ciw->toc.TrackData[trk].Control << 0) | (ciw->toc.TrackData[trk].Adr << 4); + p[2] = trk + 1; + p[3] = 1; + + p[5] = (pos >> 16) & 0xff; + p[6] = (pos >> 8) & 0xff; + p[7] = (pos >> 0) & 0xff; + + pos = msf2lsn (pos); + pos2 = (ciw->toc.TrackData[trk].Address[1] << 16) | (ciw->toc.TrackData[trk].Address[2] << 8) | (ciw->toc.TrackData[trk].Address[3] << 0); + pos -= msf2lsn (pos2); + if (pos < 0) + pos = 0; + pos = lsn2msf (pos); + + p[9] = (pos >> 16) & 0xff; + p[10] = (pos >> 8) & 0xff; + p[11] = (pos >> 0) & 0xff; + + return buf; + + } else { + + SUB_Q_CHANNEL_DATA qcd; + DWORD len; + ULONG in = 1; + uae_u8 *p = ciw32[unitnum].tempbuffer; + int cnt = 3; + + memset (p, 0, 4 + 12); + p[1] = 0x15; + p[3] = 12; + while (cnt-- > 0) { + reseterrormode (unitnum); + if(!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_READ_Q_CHANNEL, &in, sizeof(in), &qcd, sizeof (qcd), &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"IOCTL_CDROM_READ_Q_CHANNEL") < 0) + continue; + return 0; + } + break; + } reseterrormode (unitnum); - if (win32_error (unitnum, L"IOCTL_CDROM_READ_Q_CHANNEL") < 0) - continue; - return 0; - } - break; + p[1] = qcd.CurrentPosition.Header.AudioStatus; + p += 4; + p[1] = (qcd.CurrentPosition.Control << 0) | (qcd.CurrentPosition.ADR << 4); + p[2] = qcd.CurrentPosition.TrackNumber; + p[3] = qcd.CurrentPosition.IndexNumber; + p[5] = qcd.CurrentPosition.AbsoluteAddress[1]; + p[6] = qcd.CurrentPosition.AbsoluteAddress[2]; + p[7] = qcd.CurrentPosition.AbsoluteAddress[3]; + p[9] = qcd.CurrentPosition.TrackRelativeAddress[1]; + p[10] = qcd.CurrentPosition.TrackRelativeAddress[2]; + p[11] = qcd.CurrentPosition.TrackRelativeAddress[3]; + return ciw32[unitnum].tempbuffer; } - reseterrormode (unitnum); - p[1] = qcd.CurrentPosition.Header.AudioStatus; - p += 4; - p[1] = (qcd.CurrentPosition.Control << 0) | (qcd.CurrentPosition.ADR << 4); - p[2] = qcd.CurrentPosition.TrackNumber; - p[3] = qcd.CurrentPosition.IndexNumber; - p[5] = qcd.CurrentPosition.AbsoluteAddress[1]; - p[6] = qcd.CurrentPosition.AbsoluteAddress[2]; - p[7] = qcd.CurrentPosition.AbsoluteAddress[3]; - p[9] = qcd.CurrentPosition.TrackRelativeAddress[1]; - p[10] = qcd.CurrentPosition.TrackRelativeAddress[2]; - p[11] = qcd.CurrentPosition.TrackRelativeAddress[3]; - return ciw32[unitnum].tempbuffer; - } } typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER { - SCSI_PASS_THROUGH_DIRECT spt; - ULONG Filler; - UCHAR SenseBuf[32]; + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[32]; } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER; static uae_u8 *spti_read (int unitnum, int sector, int sectorsize) { - DWORD status, returned; - SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; - uae_u8 *p = ciw32[unitnum].tempbuffer; - /* number of bytes returned depends on type of track: - * CDDA = 2352 - * Mode1 = 2048 - * Mode2 = 2336 - * Mode2 Form 1 = 2048 - * Mode2 Form 2 = 2328 - */ - uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; - int len = sizeof cmd; - - if (!open_createfile (unitnum, 1)) - return 0; - cmd[3] = (uae_u8)(sector >> 16); - cmd[4] = (uae_u8)(sector >> 8); - cmd[5] = (uae_u8)(sector >> 0); - gui_cd_led (unitnum, 1); - memset (&swb, 0, sizeof (swb)); - memcpy (swb.spt.Cdb, cmd, len); - swb.spt.Length = sizeof (SCSI_PASS_THROUGH); - swb.spt.CdbLength = len; - swb.spt.DataIn = SCSI_IOCTL_DATA_IN; - swb.spt.DataTransferLength = IOCTL_DATA_BUFFER; - swb.spt.DataBuffer = p; - memset (p, 0, IOCTL_DATA_BUFFER); - swb.spt.TimeOutValue = 80 * 60; - swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); - swb.spt.SenseInfoLength = 32; - - seterrormode (unitnum); - status = DeviceIoControl (ciw32[unitnum].h, IOCTL_SCSI_PASS_THROUGH_DIRECT, - &swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), - &swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), - &returned, NULL); - reseterrormode (unitnum); - if (!status) { - DWORD err = GetLastError (); - write_log (L"IOCTL_RAW_SCSI unit %d, ERR=%d ", unitnum, err); - return 0; - } - return p; -} - -uae_u8 *ioctl_command_rawread (int unitnum, int sector, int sectorsize) -{ - int cnt = 3; - RAW_READ_INFO rri; - DWORD len; - uae_u8 *p = ciw32[unitnum].tempbuffer; - - if (log_scsi) - write_log (L"IOCTL rawread unit=%d sector=%d blocksize=%d\n", unitnum, sector, sectorsize); - if (!os_vista) - return spti_read (unitnum, sector, sectorsize); - if (!open_createfile (unitnum, 1)) - return 0; - if (sectorsize != 2336 && sectorsize != 2352 && sectorsize != 2048) - return 0; - while (cnt-- > 0) { + DWORD status, returned; + SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; + uae_u8 *p = ciw32[unitnum].tempbuffer; + /* number of bytes returned depends on type of track: + * CDDA = 2352 + * Mode1 = 2048 + * Mode2 = 2336 + * Mode2 Form 1 = 2048 + * Mode2 Form 2 = 2328 + */ + uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 }; + int len = sizeof cmd; + + if (!open_createfile (unitnum, 1)) + return 0; + cmd[3] = (uae_u8)(sector >> 16); + cmd[4] = (uae_u8)(sector >> 8); + cmd[5] = (uae_u8)(sector >> 0); gui_cd_led (unitnum, 1); + memset (&swb, 0, sizeof (swb)); + memcpy (swb.spt.Cdb, cmd, len); + swb.spt.Length = sizeof (SCSI_PASS_THROUGH); + swb.spt.CdbLength = len; + swb.spt.DataIn = SCSI_IOCTL_DATA_IN; + swb.spt.DataTransferLength = IOCTL_DATA_BUFFER; + swb.spt.DataBuffer = p; + memset (p, 0, IOCTL_DATA_BUFFER); + swb.spt.TimeOutValue = 80 * 60; + swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); + swb.spt.SenseInfoLength = 32; + seterrormode (unitnum); - rri.DiskOffset.QuadPart = sector * 2048; - rri.SectorCount = 1; - rri.TrackMode = RawWithSubCode; - len = sectorsize; - memset (p, 0, sectorsize); - if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_RAW_READ, &rri, sizeof rri, - p, IOCTL_DATA_BUFFER, &len, NULL)) { - DWORD err = GetLastError (); - } + status = DeviceIoControl (ciw32[unitnum].h, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), + &swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), + &returned, NULL); reseterrormode (unitnum); - break; - } - if (sectorsize == 2352) + if (!status) { + DWORD err = GetLastError (); + write_log (L"IOCTL_RAW_SCSI unit %d, ERR=%d ", unitnum, err); + return 0; + } return p; - return p + 16; } -static int ioctl_command_readwrite (int unitnum, int sector, int write, int blocksize, uae_u8 **ptr) +uae_u8 *ioctl_command_rawread (int unitnum, int sector, int sectorsize) { - DWORD dtotal; - int cnt = 3; - uae_u8 *p = ciw32[unitnum].tempbuffer; + int cnt = 3; + RAW_READ_INFO rri; + DWORD len; + uae_u8 *p = ciw32[unitnum].tempbuffer; - *ptr = NULL; - if (!open_createfile (unitnum, 0)) - return 0; - while (cnt-- > 0) { - gui_cd_led (unitnum, 1); - seterrormode (unitnum); - if (SetFilePointer (ciw32[unitnum].h, sector * ciw32[unitnum].blocksize, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"SetFilePointer") < 0) - continue; - return 0; - } - reseterrormode (unitnum); - break; - } - cnt = 3; - while (cnt-- > 0) { - gui_cd_led (unitnum, 1); - seterrormode (unitnum); - if (write) { - if (!WriteFile (ciw32[unitnum].h, p, blocksize, &dtotal, 0)) { - int err; - reseterrormode (unitnum); - err = win32_error (unitnum, L"WriteFile"); - if (err < 0) - continue; - if (err == ERROR_WRITE_PROTECT) - return -1; + if (log_scsi) + write_log (L"IOCTL rawread unit=%d sector=%d blocksize=%d\n", unitnum, sector, sectorsize); + if (!os_vista) + return spti_read (unitnum, sector, sectorsize); + if (!open_createfile (unitnum, 1)) return 0; - } - } else { - dtotal = 0; - if (!ReadFile (ciw32[unitnum].h, p, blocksize, &dtotal, 0)) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"ReadFile") < 0) - continue; + if (sectorsize != 2336 && sectorsize != 2352 && sectorsize != 2048) return 0; - } - if (dtotal == 0) { - /* ESS Mega (CDTV) "fake" data area returns zero bytes and no error.. */ - *ptr = spti_read (unitnum, sector, 2048); - if (log_scsi) - write_log (L"IOCTL unit %d, sector %d: ReadFile()==0. SPTI=%d\n", unitnum, sector, *ptr == 0 ? GetLastError () : 0); - return 1; -#if 0 - DWORD len = CD_RAW_SECTOR_WITH_SUBCODE_SIZE, err = -1; - RAW_READ_INFO rri = { 0 }; + while (cnt-- > 0) { + gui_cd_led (unitnum, 1); + seterrormode (unitnum); rri.DiskOffset.QuadPart = sector * 2048; rri.SectorCount = 1; rri.TrackMode = RawWithSubCode; - memset (p, 0, blocksize); - if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_RAW_READ, &rri, sizeof rri, - p, len, &len, NULL)) { - err = GetLastError (); /* returns ERROR_IO_DEVICE and still succeeds?! */ + len = sectorsize; + memset (p, 0, sectorsize); + if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_RAW_READ, &rri, sizeof rri, + p, IOCTL_DATA_BUFFER, &len, NULL)) { + DWORD err = GetLastError (); + } + reseterrormode (unitnum); + break; + } + if (sectorsize == 2352) + return p; + return p + 16; +} + +static int ioctl_command_readwrite (int unitnum, int sector, int write, int blocksize, uae_u8 **ptr) +{ + DWORD dtotal; + int cnt = 3; + uae_u8 *p = ciw32[unitnum].tempbuffer; + + *ptr = NULL; + if (!open_createfile (unitnum, 0)) + return 0; + while (cnt-- > 0) { + gui_cd_led (unitnum, 1); + seterrormode (unitnum); + if (SetFilePointer (ciw32[unitnum].h, sector * ciw32[unitnum].blocksize, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"SetFilePointer") < 0) + continue; + return 0; } - p += 16; /* skip raw header */ - write_log (L"ioctl_command_read(%d,%d)==0, IOCTL_CDROM_RAW_READ = d\n", - sector, blocksize, err); + reseterrormode (unitnum); + break; + } + cnt = 3; + while (cnt-- > 0) { + gui_cd_led (unitnum, 1); + seterrormode (unitnum); + if (write) { + if (!WriteFile (ciw32[unitnum].h, p, blocksize, &dtotal, 0)) { + int err; + reseterrormode (unitnum); + err = win32_error (unitnum, L"WriteFile"); + if (err < 0) + continue; + if (err == ERROR_WRITE_PROTECT) + return -1; + return 0; + } + } else { + dtotal = 0; + if (!ReadFile (ciw32[unitnum].h, p, blocksize, &dtotal, 0)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"ReadFile") < 0) + continue; + return 0; + } + if (dtotal == 0) { + /* ESS Mega (CDTV) "fake" data area returns zero bytes and no error.. */ + *ptr = spti_read (unitnum, sector, 2048); + if (log_scsi) + write_log (L"IOCTL unit %d, sector %d: ReadFile()==0. SPTI=%d\n", unitnum, sector, *ptr == 0 ? GetLastError () : 0); + return 1; +#if 0 + DWORD len = CD_RAW_SECTOR_WITH_SUBCODE_SIZE, err = -1; + RAW_READ_INFO rri = { 0 }; + rri.DiskOffset.QuadPart = sector * 2048; + rri.SectorCount = 1; + rri.TrackMode = RawWithSubCode; + memset (p, 0, blocksize); + if (!DeviceIoControl(ciw32[unitnum].h, IOCTL_CDROM_RAW_READ, &rri, sizeof rri, + p, len, &len, NULL)) { + err = GetLastError (); /* returns ERROR_IO_DEVICE and still succeeds?! */ + } + p += 16; /* skip raw header */ + write_log (L"ioctl_command_read(%d,%d)==0, IOCTL_CDROM_RAW_READ = d\n", + sector, blocksize, err); #endif - } + } + } + reseterrormode (unitnum); + gui_cd_led (unitnum, 1); + break; } - reseterrormode (unitnum); - gui_cd_led (unitnum, 1); - break; - } - *ptr = p; - return 1; + *ptr = p; + return 1; } static int ioctl_command_write (int unitnum, int sector) { - uae_u8 *ptr; - return ioctl_command_readwrite (unitnum, sector, 1, ciw32[unitnum].blocksize, &ptr); + uae_u8 *ptr; + return ioctl_command_readwrite (unitnum, sector, 1, ciw32[unitnum].blocksize, &ptr); } static uae_u8 *ioctl_command_read (int unitnum, int sector) { - uae_u8 *ptr; - if (ioctl_command_readwrite (unitnum, sector, 0, ciw32[unitnum].blocksize, &ptr) > 0) - return ptr; - return NULL; + uae_u8 *ptr; + if (ioctl_command_readwrite (unitnum, sector, 0, ciw32[unitnum].blocksize, &ptr) > 0) + return ptr; + return NULL; } static int fetch_geometry (int unitnum, struct device_info *di) { - DISK_GEOMETRY geom; - DWORD len; - int cnt = 3; + DISK_GEOMETRY geom; + DWORD len; + int cnt = 3; - if (!open_createfile (unitnum, 0)) - return 0; - while (cnt-- > 0) { - seterrormode (unitnum); - if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &geom, sizeof(geom), &len, NULL)) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"IOCTL_CDROM_GET_DRIVE_GEOMETRY") < 0) - continue; - return 0; + if (!open_createfile (unitnum, 0)) + return 0; + while (cnt-- > 0) { + seterrormode (unitnum); + if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &geom, sizeof(geom), &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"IOCTL_CDROM_GET_DRIVE_GEOMETRY") < 0) + continue; + return 0; + } + reseterrormode (unitnum); + break; } - reseterrormode (unitnum); - break; - } - if (di) { - di->cylinders = geom.Cylinders.LowPart; - di->sectorspertrack = geom.SectorsPerTrack; - di->trackspercylinder = geom.TracksPerCylinder; - di->bytespersector = geom.BytesPerSector; - } - return 1; + if (di) { + di->cylinders = geom.Cylinders.LowPart; + di->sectorspertrack = geom.SectorsPerTrack; + di->trackspercylinder = geom.TracksPerCylinder; + di->bytespersector = geom.BytesPerSector; + } + return 1; } static int ismedia (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - if (ciw->mciid > 0) { + if (ciw->mciid > 0) { - DWORD err; - MCI_STATUS_PARMS mciStatusParms; + DWORD err; + MCI_STATUS_PARMS mciStatusParms; - memset (&mciStatusParms, 0, sizeof mciStatusParms); - mciStatusParms.dwItem = MCI_STATUS_MEDIA_PRESENT; - err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); - if (err != MMSYSERR_NOERROR) - return 0; - if (mciStatusParms.dwReturn) - return 1; - return 0; + memset (&mciStatusParms, 0, sizeof mciStatusParms); + mciStatusParms.dwItem = MCI_STATUS_MEDIA_PRESENT; + err = mciSendCommand (ciw->mciid, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatusParms); + if (err != MMSYSERR_NOERROR) + return 0; + if (mciStatusParms.dwReturn) + return 1; + return 0; - } else { + } else { - struct device_info di; - memset (&di, 0, sizeof di); - return fetch_geometry (unitnum, &di); + struct device_info di; + memset (&di, 0, sizeof di); + return fetch_geometry (unitnum, &di); - } + } } /* read toc */ static uae_u8 *ioctl_command_toc (int unitnum) { - DWORD len; - int i; - uae_u8 *p = ciw32[unitnum].tempbuffer; - int cnt = 3; - CDROM_TOC *toc = &ciw32[unitnum].toc; + DWORD len; + int i; + uae_u8 *p = ciw32[unitnum].tempbuffer; + int cnt = 3; + CDROM_TOC *toc = &ciw32[unitnum].toc; - if (!open_createfile (unitnum, 0)) - return 0; - gui_cd_led (unitnum, 1); - while (cnt-- > 0) { - seterrormode (unitnum); - if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_READ_TOC, NULL, 0, toc, sizeof(CDROM_TOC), &len, NULL)) { - reseterrormode (unitnum); - if (win32_error (unitnum, L"IOCTL_CDROM_READ_TOC") < 0) - continue; - return 0; + if (!open_createfile (unitnum, 0)) + return 0; + gui_cd_led (unitnum, 1); + while (cnt-- > 0) { + seterrormode (unitnum); + if (!DeviceIoControl (ciw32[unitnum].h, IOCTL_CDROM_READ_TOC, NULL, 0, toc, sizeof(CDROM_TOC), &len, NULL)) { + reseterrormode (unitnum); + if (win32_error (unitnum, L"IOCTL_CDROM_READ_TOC") < 0) + continue; + return 0; + } + reseterrormode (unitnum); + break; } - reseterrormode (unitnum); - break; - } - - p[0] = ((toc->LastTrack + 4) * 11) >> 8; - p[1] = ((toc->LastTrack + 4) * 11) & 0xff; - p[2] = 1; - p[3] = toc->LastTrack; - p += 4; - memset (p, 0, 11); - p[0] = 1; - p[1] = (toc->TrackData[0].Control << 0) | (toc->TrackData[0].Adr << 4); - p[3] = 0xa0; - p[8] = 1; - p += 11; - memset (p, 0, 11); - p[0] = 1; - p[1] = 0x10; - p[3] = 0xa1; - p[8] = toc->LastTrack; - p += 11; - memset (p, 0, 11); - p[0] = 1; - p[1] = 0x10; - p[3] = 0xa2; - p[8] = toc->TrackData[toc->LastTrack].Address[1]; - p[9] = toc->TrackData[toc->LastTrack].Address[2]; - p[10] = toc->TrackData[toc->LastTrack].Address[3]; - p += 11; - for (i = 0; i < toc->LastTrack; i++) { + + p[0] = ((toc->LastTrack + 4) * 11) >> 8; + p[1] = ((toc->LastTrack + 4) * 11) & 0xff; + p[2] = 1; + p[3] = toc->LastTrack; + p += 4; + memset (p, 0, 11); + p[0] = 1; + p[1] = (toc->TrackData[0].Control << 0) | (toc->TrackData[0].Adr << 4); + p[3] = 0xa0; + p[8] = 1; + p += 11; + memset (p, 0, 11); + p[0] = 1; + p[1] = 0x10; + p[3] = 0xa1; + p[8] = toc->LastTrack; + p += 11; memset (p, 0, 11); p[0] = 1; - p[1] = (toc->TrackData[i].Control << 0) | (toc->TrackData[i].Adr << 4); - p[2] = 0; - p[3] = i + 1; - p[8] = toc->TrackData[i].Address[1]; - p[9] = toc->TrackData[i].Address[2]; - p[10] = toc->TrackData[i].Address[3]; + p[1] = 0x10; + p[3] = 0xa2; + p[8] = toc->TrackData[toc->LastTrack].Address[1]; + p[9] = toc->TrackData[toc->LastTrack].Address[2]; + p[10] = toc->TrackData[toc->LastTrack].Address[3]; p += 11; - } - gui_cd_led (unitnum, 1); - return ciw32[unitnum].tempbuffer; + for (i = 0; i < toc->LastTrack; i++) { + memset (p, 0, 11); + p[0] = 1; + p[1] = (toc->TrackData[i].Control << 0) | (toc->TrackData[i].Adr << 4); + p[2] = 0; + p[3] = i + 1; + p[8] = toc->TrackData[i].Address[1]; + p[9] = toc->TrackData[i].Address[2]; + p[10] = toc->TrackData[i].Address[3]; + p += 11; + } + gui_cd_led (unitnum, 1); + return ciw32[unitnum].tempbuffer; } /* open device level access to cd rom drive */ static int sys_cddev_open (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - /* buffer must be page aligned for device access */ - ciw->tempbuffer = VirtualAlloc (NULL, IOCTL_DATA_BUFFER, MEM_COMMIT, PAGE_READWRITE); - if (!ciw->tempbuffer) { - write_log (L"IOCTL: failed to allocate buffer"); - return 1; - } - if (!open_createfile (unitnum, 0)) { - write_log (L"IOCTL: failed to open '%s', err=%d\n", ciw->devname, GetLastError ()); - goto error; - } - ciw->mediainserted = ioctl_command_toc (unitnum) ? 1 : 0; - write_log (L"IOCTL: device '%s' opened succesfully (unit number=%d,media=%d)\n", ciw->devname, unitnum, ciw->mediainserted); - ioctl_command_stop (unitnum); - return 0; + /* buffer must be page aligned for device access */ + ciw->tempbuffer = VirtualAlloc (NULL, IOCTL_DATA_BUFFER, MEM_COMMIT, PAGE_READWRITE); + if (!ciw->tempbuffer) { + write_log (L"IOCTL: failed to allocate buffer"); + return 1; + } + if (!open_createfile (unitnum, 0)) { + write_log (L"IOCTL: failed to open '%s', err=%d\n", ciw->devname, GetLastError ()); + goto error; + } + ciw->mediainserted = ioctl_command_toc (unitnum) ? 1 : 0; + write_log (L"IOCTL: device '%s' opened succesfully (unit number=%d,media=%d)\n", ciw->devname, unitnum, ciw->mediainserted); + ioctl_command_stop (unitnum); + return 0; error: - win32_error (unitnum, L"CreateFile"); - VirtualFree (ciw->tempbuffer, 0, MEM_RELEASE); - ciw->tempbuffer = NULL; - CloseHandle (ciw->h); - ciw->h = NULL; - return -1; + win32_error (unitnum, L"CreateFile"); + VirtualFree (ciw->tempbuffer, 0, MEM_RELEASE); + ciw->tempbuffer = NULL; + CloseHandle (ciw->h); + ciw->h = NULL; + return -1; } static int unitcheck (int unitnum) { - if (unitnum >= MAX_TOTAL_DEVICES) { - if (unitnum < 'A' || unitnum > 'Z') - return 0; + if (unitnum >= MAX_TOTAL_DEVICES) { + if (unitnum < 'A' || unitnum > 'Z') + return 0; + return 1; + } + if (ciw32[unitnum].drvletter == 0) + return 0; return 1; - } - if (ciw32[unitnum].drvletter == 0) - return 0; - return 1; } /* close device handle */ void sys_cddev_close (int unitnum) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; + struct dev_info_ioctl *ciw = &ciw32[unitnum]; - if (!unitcheck (unitnum)) - return; - close_createfile (unitnum); - close_mci (unitnum); - VirtualFree (ciw->tempbuffer, 0, MEM_RELEASE); - ciw->tempbuffer = NULL; + if (!unitcheck (unitnum)) + return; + close_createfile (unitnum); + close_mci (unitnum); + VirtualFree (ciw->tempbuffer, 0, MEM_RELEASE); + ciw->tempbuffer = NULL; } static int open_device (int unitnum) { - if (!unitcheck (unitnum)) + if (!unitcheck (unitnum)) + return 0; + if (sys_cddev_open (unitnum) == 0) + return 1; return 0; - if (sys_cddev_open (unitnum) == 0) - return 1; - return 0; } static void close_device (int unitnum) { - sys_cddev_close (unitnum); + sys_cddev_close (unitnum); } static void close_bus (void) @@ -836,99 +836,99 @@ static int total_devices; static int open_bus (int flags) { - int dwDriveMask; - int drive, i; - TCHAR tmp[10]; - - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - memset (&ciw32[i], 0, sizeof (struct dev_info_ioctl)); - ciw32[i].h = INVALID_HANDLE_VALUE; - } - MCICDA = 1;//os_vista ? 1 : 0; - total_devices = 0; - dwDriveMask = GetLogicalDrives (); - if (log_scsi) - write_log (L"IOCTL: drive mask = %08X\n", dwDriveMask); - dwDriveMask >>= 2; // Skip A and B drives... - for( drive = 'C'; drive <= 'Z'; drive++) { - if (dwDriveMask & 1) { - int dt; - _stprintf (tmp, L"%c:\\", drive); - dt = GetDriveType (tmp); - if (log_scsi) - write_log (L"IOCTL: drive %c type %d\n", drive, dt); - if (((flags & (1 << INQ_ROMD)) && dt == DRIVE_CDROM) || ((flags & (1 << INQ_DASD)) && dt == DRIVE_FIXED)) { - if (log_scsi) - write_log (L"IOCTL: drive %c: = unit %d\n", drive, total_devices); - ciw32[total_devices].drvletter = drive; - ciw32[total_devices].type = dt; - ciw32[total_devices].blocksize = 2048; - _stprintf (ciw32[total_devices].devname, L"\\\\.\\%c:", drive); - total_devices++; - } + int dwDriveMask; + int drive, i; + TCHAR tmp[10]; + + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + memset (&ciw32[i], 0, sizeof (struct dev_info_ioctl)); + ciw32[i].h = INVALID_HANDLE_VALUE; } - dwDriveMask >>= 1; - } - return total_devices; + MCICDA = 1;//os_vista ? 1 : 0; + total_devices = 0; + dwDriveMask = GetLogicalDrives (); + if (log_scsi) + write_log (L"IOCTL: drive mask = %08X\n", dwDriveMask); + dwDriveMask >>= 2; // Skip A and B drives... + for( drive = 'C'; drive <= 'Z'; drive++) { + if (dwDriveMask & 1) { + int dt; + _stprintf (tmp, L"%c:\\", drive); + dt = GetDriveType (tmp); + if (log_scsi) + write_log (L"IOCTL: drive %c type %d\n", drive, dt); + if (((flags & (1 << INQ_ROMD)) && dt == DRIVE_CDROM) || ((flags & (1 << INQ_DASD)) && dt == DRIVE_FIXED)) { + if (log_scsi) + write_log (L"IOCTL: drive %c: = unit %d\n", drive, total_devices); + ciw32[total_devices].drvletter = drive; + ciw32[total_devices].type = dt; + ciw32[total_devices].blocksize = 2048; + _stprintf (ciw32[total_devices].devname, L"\\\\.\\%c:", drive); + total_devices++; + } + } + dwDriveMask >>= 1; + } + return total_devices; } static int ioctl_ismedia (int unitnum, int quick) { - if (!unitcheck (unitnum)) - return 0; - if (quick) { - struct dev_info_ioctl *ciw = &ciw32[unitnum]; - return ciw->mediainserted; - } - return ismedia (unitnum); + if (!unitcheck (unitnum)) + return 0; + if (quick) { + struct dev_info_ioctl *ciw = &ciw32[unitnum]; + return ciw->mediainserted; + } + return ismedia (unitnum); } static struct device_info *info_device (int unitnum, struct device_info *di) { - if (!unitcheck (unitnum)) - return 0; - di->bus = unitnum; - di->target = 0; - di->lun = 0; - di->media_inserted = 0; - di->bytespersector = 2048; - if (fetch_geometry (unitnum, di)) { // || ioctl_command_toc (unitnum)) - di->media_inserted = 1; - ciw32[unitnum].blocksize = di->bytespersector; - } - di->write_protected = ciw32[unitnum].type == DRIVE_CDROM ? 1 : 0; - di->type = ciw32[unitnum].type == DRIVE_CDROM ? INQ_ROMD : INQ_DASD; - di->id = ciw32[unitnum].drvletter; - _stprintf (di->label, L"Drive %c:", ciw32[unitnum].drvletter); - return di; + if (!unitcheck (unitnum)) + return 0; + di->bus = unitnum; + di->target = 0; + di->lun = 0; + di->media_inserted = 0; + di->bytespersector = 2048; + if (fetch_geometry (unitnum, di)) { // || ioctl_command_toc (unitnum)) + di->media_inserted = 1; + ciw32[unitnum].blocksize = di->bytespersector; + } + di->write_protected = ciw32[unitnum].type == DRIVE_CDROM ? 1 : 0; + di->type = ciw32[unitnum].type == DRIVE_CDROM ? INQ_ROMD : INQ_DASD; + di->id = ciw32[unitnum].drvletter; + _stprintf (di->label, L"Drive %c:", ciw32[unitnum].drvletter); + return di; } void win32_ioctl_media_change (TCHAR driveletter, int insert) { - int i; + int i; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (ciw32[i].drvletter == driveletter && ciw32[i].mediainserted != insert) { - write_log (L"IOCTL: media change %c %d\n", driveletter, insert); - ciw32[i].mediainserted = insert; - scsi_do_disk_change (driveletter, insert); + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (ciw32[i].drvletter == driveletter && ciw32[i].mediainserted != insert) { + write_log (L"IOCTL: media change %c %d\n", driveletter, insert); + ciw32[i].mediainserted = insert; + scsi_do_disk_change (driveletter, insert); + } } - } } static struct device_scsi_info *ioctl_scsi_info (int unitnum, struct device_scsi_info *dsi) { - dsi->buffer = ciw32[unitnum].tempbuffer; - dsi->bufsize = IOCTL_DATA_BUFFER; - return dsi; + dsi->buffer = ciw32[unitnum].tempbuffer; + dsi->bufsize = IOCTL_DATA_BUFFER; + return dsi; } struct device_functions devicefunc_win32_ioctl = { - open_bus, close_bus, open_device, close_device, info_device, - 0, 0, 0, - ioctl_command_pause, ioctl_command_stop, ioctl_command_play, ioctl_command_qcode, - ioctl_command_toc, ioctl_command_read, ioctl_command_rawread, ioctl_command_write, - 0, ioctl_scsi_info, ioctl_ismedia + open_bus, close_bus, open_device, close_device, info_device, + 0, 0, 0, + ioctl_command_pause, ioctl_command_stop, ioctl_command_play, ioctl_command_qcode, + ioctl_command_toc, ioctl_command_read, ioctl_command_rawread, ioctl_command_write, + 0, ioctl_scsi_info, ioctl_ismedia }; #endif diff --git a/od-win32/blkdev_win32_spti.c b/od-win32/blkdev_win32_spti.c index 28013fca..f487b19a 100644 --- a/od-win32/blkdev_win32_spti.c +++ b/od-win32/blkdev_win32_spti.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * WIN32 CDROM/HD low level access code (SPTI) - * - * Copyright 2002-2005 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* WIN32 CDROM/HD low level access code (SPTI) +* +* Copyright 2002-2005 Toni Wilen +* +*/ #define WIN32_LEAN_AND_MEAN @@ -37,25 +37,25 @@ #define INQUIRY_SIZE 36 typedef struct _SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER { - SCSI_PASS_THROUGH_DIRECT spt; - ULONG Filler; - UCHAR SenseBuf[32]; + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[32]; } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER; static int unitcnt = 0; struct dev_info_spti { - TCHAR *drvpath; - TCHAR *name; - TCHAR *inquirydata; - int mediainserted; - HANDLE handle; - int isatapi; - int removable; - int type; - int bus, path, target, lun; - int scanmode; - uae_u8 *scsibuf; + TCHAR *drvpath; + TCHAR *name; + TCHAR *inquirydata; + int mediainserted; + HANDLE handle; + int isatapi; + int removable; + int type; + int bus, path, target, lun; + int scanmode; + uae_u8 *scsibuf; }; static uae_sem_t scgp_sem; @@ -63,43 +63,43 @@ static struct dev_info_spti dev_info[MAX_TOTAL_DEVICES]; static int doscsi (int unitnum, SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER *swb, int *err) { - DWORD status, returned; - struct dev_info_spti *di = &dev_info[unitnum]; - - *err = 0; - if (log_scsi) { - write_log (L"SCSI, H=%X:%d:%d:%d:%d: ", di->handle, di->bus, di->path, di->target, di->lun); - scsi_log_before (swb->spt.Cdb, swb->spt.CdbLength, - swb->spt.DataIn == SCSI_IOCTL_DATA_OUT ? swb->spt.DataBuffer : 0,swb->spt.DataTransferLength); - } - gui_cd_led (unitnum, 1); - swb->spt.ScsiStatus = 0; - if (di->bus >= 0) { - swb->spt.PathId = di->path; - swb->spt.TargetId = di->target; - swb->spt.Lun = di->lun; - } - status = DeviceIoControl (di->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, - swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), - swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), - &returned, NULL); - if (!status) { - int lasterror = GetLastError(); - *err = lasterror; - write_log (L"SCSI ERROR, H=%X:%d:%d:%d:%d: ", di->handle, di->bus, di->path, di->target, di->lun); - write_log (L"Status = %d, Error code = %d, LastError=%d\n", status, swb->spt.ScsiStatus, lasterror); - scsi_log_before (swb->spt.Cdb, swb->spt.CdbLength, - swb->spt.DataIn == SCSI_IOCTL_DATA_OUT ? swb->spt.DataBuffer : 0,swb->spt.DataTransferLength); - } - if (log_scsi) - scsi_log_after (swb->spt.DataIn == SCSI_IOCTL_DATA_IN ? swb->spt.DataBuffer : 0, swb->spt.DataTransferLength, - swb->SenseBuf, swb->spt.SenseInfoLength); - if (swb->spt.SenseInfoLength > 0 && (swb->SenseBuf[0] == 0 || swb->SenseBuf[0] == 1)) - swb->spt.SenseInfoLength = 0; /* 0 and 1 = success, not error.. */ - if (swb->spt.SenseInfoLength > 0) - return 0; - gui_cd_led (unitnum, 1); - return status; + DWORD status, returned; + struct dev_info_spti *di = &dev_info[unitnum]; + + *err = 0; + if (log_scsi) { + write_log (L"SCSI, H=%X:%d:%d:%d:%d: ", di->handle, di->bus, di->path, di->target, di->lun); + scsi_log_before (swb->spt.Cdb, swb->spt.CdbLength, + swb->spt.DataIn == SCSI_IOCTL_DATA_OUT ? swb->spt.DataBuffer : 0,swb->spt.DataTransferLength); + } + gui_cd_led (unitnum, 1); + swb->spt.ScsiStatus = 0; + if (di->bus >= 0) { + swb->spt.PathId = di->path; + swb->spt.TargetId = di->target; + swb->spt.Lun = di->lun; + } + status = DeviceIoControl (di->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), + swb, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER), + &returned, NULL); + if (!status) { + int lasterror = GetLastError(); + *err = lasterror; + write_log (L"SCSI ERROR, H=%X:%d:%d:%d:%d: ", di->handle, di->bus, di->path, di->target, di->lun); + write_log (L"Status = %d, Error code = %d, LastError=%d\n", status, swb->spt.ScsiStatus, lasterror); + scsi_log_before (swb->spt.Cdb, swb->spt.CdbLength, + swb->spt.DataIn == SCSI_IOCTL_DATA_OUT ? swb->spt.DataBuffer : 0,swb->spt.DataTransferLength); + } + if (log_scsi) + scsi_log_after (swb->spt.DataIn == SCSI_IOCTL_DATA_IN ? swb->spt.DataBuffer : 0, swb->spt.DataTransferLength, + swb->SenseBuf, swb->spt.SenseInfoLength); + if (swb->spt.SenseInfoLength > 0 && (swb->SenseBuf[0] == 0 || swb->SenseBuf[0] == 1)) + swb->spt.SenseInfoLength = 0; /* 0 and 1 = success, not error.. */ + if (swb->spt.SenseInfoLength > 0) + return 0; + gui_cd_led (unitnum, 1); + return status; } @@ -110,119 +110,119 @@ static int doscsi (int unitnum, SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER *swb, int * static int execscsicmd (int unitnum, uae_u8 *data, int len, uae_u8 *inbuf, int inlen) { - SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; - DWORD status; - int err, dolen; - - uae_sem_wait (&scgp_sem); - memset (&swb, 0, sizeof (swb)); - swb.spt.Length = sizeof (SCSI_PASS_THROUGH); - swb.spt.CdbLength = len; - if (inbuf) { - swb.spt.DataIn = SCSI_IOCTL_DATA_IN; - swb.spt.DataTransferLength = inlen; - swb.spt.DataBuffer = inbuf; - memset (inbuf, 0, inlen); - } else { - swb.spt.DataIn = SCSI_IOCTL_DATA_OUT; - } - swb.spt.TimeOutValue = 80 * 60; - swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); - swb.spt.SenseInfoLength = 32; - memcpy (swb.spt.Cdb, data, len); - status = doscsi (unitnum, &swb, &err); - uae_sem_post (&scgp_sem); - dolen = swb.spt.DataTransferLength; - if (!status) - return -1; - return dolen; + SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; + DWORD status; + int err, dolen; + + uae_sem_wait (&scgp_sem); + memset (&swb, 0, sizeof (swb)); + swb.spt.Length = sizeof (SCSI_PASS_THROUGH); + swb.spt.CdbLength = len; + if (inbuf) { + swb.spt.DataIn = SCSI_IOCTL_DATA_IN; + swb.spt.DataTransferLength = inlen; + swb.spt.DataBuffer = inbuf; + memset (inbuf, 0, inlen); + } else { + swb.spt.DataIn = SCSI_IOCTL_DATA_OUT; + } + swb.spt.TimeOutValue = 80 * 60; + swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); + swb.spt.SenseInfoLength = 32; + memcpy (swb.spt.Cdb, data, len); + status = doscsi (unitnum, &swb, &err); + uae_sem_post (&scgp_sem); + dolen = swb.spt.DataTransferLength; + if (!status) + return -1; + return dolen; } static int execscsicmd_direct (int unitnum, struct amigascsi *as) { - SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; - DWORD status; - int sactual = 0, i; - int io_error = 0, err, parm; - uae_u8 *scsi_datap, *scsi_datap_org; - uae_u32 scsi_cmd_len_orig = as->cmd_len; - - memset (&swb, 0, sizeof (swb)); - swb.spt.Length = sizeof (SCSI_PASS_THROUGH); - swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); - - uae_sem_wait (&scgp_sem); - - /* the Amiga does not tell us how long the timeout shall be, so make it _very_ long (specified in seconds) */ - swb.spt.TimeOutValue = 80 * 60; - scsi_datap = scsi_datap_org = as->len ? as->data : 0; - swb.spt.DataIn = (as->flags & 1) ? SCSI_IOCTL_DATA_IN : SCSI_IOCTL_DATA_OUT; - for (i = 0; i < as->cmd_len; i++) - swb.spt.Cdb[i] = as->cmd[i]; - if (as->sense_len > 32) - as->sense_len = 32; - swb.spt.SenseInfoLength = (as->flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ - (as->flags & 2) ? as->sense_len : /* SCSIF_AUTOSENSE */ - 32; - if (dev_info[unitnum].isatapi) - scsi_atapi_fixup_pre (swb.spt.Cdb, &as->cmd_len, &scsi_datap, &as->len, &parm); - swb.spt.CdbLength = (UCHAR)as->cmd_len; - swb.spt.DataTransferLength = as->len; - swb.spt.DataBuffer = scsi_datap; - - status = doscsi (unitnum, &swb, &err); - - as->cmdactual = status == 0 ? 0 : scsi_cmd_len_orig; /* fake scsi_CmdActual */ - as->status = swb.spt.ScsiStatus; /* scsi_Status */ - if (swb.spt.ScsiStatus) { - io_error = 45; /* HFERR_BadStatus */ - /* copy sense? */ - for (sactual = 0; sactual < as->sense_len && sactual < swb.spt.SenseInfoLength; sactual++) - as->sensedata[sactual] = swb.SenseBuf[sactual]; - as->actual = 0; /* scsi_Actual */ - } else { - int i; - for (i = 0; i < as->sense_len; i++) - as->sensedata[i] = 0; - sactual = 0; - if (status == 0) { - io_error = 20; /* io_Error, but not specified */ - as->actual = 0; /* scsi_Actual */ + SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb; + DWORD status; + int sactual = 0, i; + int io_error = 0, err, parm; + uae_u8 *scsi_datap, *scsi_datap_org; + uae_u32 scsi_cmd_len_orig = as->cmd_len; + + memset (&swb, 0, sizeof (swb)); + swb.spt.Length = sizeof (SCSI_PASS_THROUGH); + swb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, SenseBuf); + + uae_sem_wait (&scgp_sem); + + /* the Amiga does not tell us how long the timeout shall be, so make it _very_ long (specified in seconds) */ + swb.spt.TimeOutValue = 80 * 60; + scsi_datap = scsi_datap_org = as->len ? as->data : 0; + swb.spt.DataIn = (as->flags & 1) ? SCSI_IOCTL_DATA_IN : SCSI_IOCTL_DATA_OUT; + for (i = 0; i < as->cmd_len; i++) + swb.spt.Cdb[i] = as->cmd[i]; + if (as->sense_len > 32) + as->sense_len = 32; + swb.spt.SenseInfoLength = (as->flags & 4) ? 4 : /* SCSIF_OLDAUTOSENSE */ + (as->flags & 2) ? as->sense_len : /* SCSIF_AUTOSENSE */ + 32; + if (dev_info[unitnum].isatapi) + scsi_atapi_fixup_pre (swb.spt.Cdb, &as->cmd_len, &scsi_datap, &as->len, &parm); + swb.spt.CdbLength = (UCHAR)as->cmd_len; + swb.spt.DataTransferLength = as->len; + swb.spt.DataBuffer = scsi_datap; + + status = doscsi (unitnum, &swb, &err); + + as->cmdactual = status == 0 ? 0 : scsi_cmd_len_orig; /* fake scsi_CmdActual */ + as->status = swb.spt.ScsiStatus; /* scsi_Status */ + if (swb.spt.ScsiStatus) { + io_error = 45; /* HFERR_BadStatus */ + /* copy sense? */ + for (sactual = 0; sactual < as->sense_len && sactual < swb.spt.SenseInfoLength; sactual++) + as->sensedata[sactual] = swb.SenseBuf[sactual]; + as->actual = 0; /* scsi_Actual */ } else { - as->len = swb.spt.DataTransferLength; - if (dev_info[unitnum].isatapi) - scsi_atapi_fixup_post (swb.spt.Cdb, as->cmd_len, scsi_datap_org, scsi_datap, &as->len, parm); - io_error = 0; - as->actual = as->len; /* scsi_Actual */ + int i; + for (i = 0; i < as->sense_len; i++) + as->sensedata[i] = 0; + sactual = 0; + if (status == 0) { + io_error = 20; /* io_Error, but not specified */ + as->actual = 0; /* scsi_Actual */ + } else { + as->len = swb.spt.DataTransferLength; + if (dev_info[unitnum].isatapi) + scsi_atapi_fixup_post (swb.spt.Cdb, as->cmd_len, scsi_datap_org, scsi_datap, &as->len, parm); + io_error = 0; + as->actual = as->len; /* scsi_Actual */ + } } - } - as->sactual = sactual; - uae_sem_post (&scgp_sem); + as->sactual = sactual; + uae_sem_post (&scgp_sem); - if (scsi_datap != scsi_datap_org) - free (scsi_datap); + if (scsi_datap != scsi_datap_org) + free (scsi_datap); - return io_error; + return io_error; } static uae_u8 *execscsicmd_out (int unitnum, uae_u8 *data, int len) { - int v = execscsicmd (unitnum, data, len, 0, 0); - if (v < 0) - return 0; - return data; + int v = execscsicmd (unitnum, data, len, 0, 0); + if (v < 0) + return 0; + return data; } static uae_u8 *execscsicmd_in (int unitnum, uae_u8 *data, int len, int *outlen) { - int v = execscsicmd (unitnum, data, len, dev_info[unitnum].scsibuf, DEVICE_SCSI_BUFSIZE); - if (v < 0) - return 0; - if (v == 0) - return 0; - if (outlen) - *outlen = v; - return dev_info[unitnum].scsibuf; + int v = execscsicmd (unitnum, data, len, dev_info[unitnum].scsibuf, DEVICE_SCSI_BUFSIZE); + if (v < 0) + return 0; + if (v == 0) + return 0; + if (outlen) + *outlen = v; + return dev_info[unitnum].scsibuf; } static int total_devices; @@ -230,347 +230,347 @@ static int total_devices; static void close_scsi_device (int unitnum) { - if (dev_info[unitnum].handle != INVALID_HANDLE_VALUE) { - write_log (L"SPTI: unit %d closed\n", unitnum); - CloseHandle (dev_info[unitnum].handle); - } - dev_info[unitnum].handle = INVALID_HANDLE_VALUE; + if (dev_info[unitnum].handle != INVALID_HANDLE_VALUE) { + write_log (L"SPTI: unit %d closed\n", unitnum); + CloseHandle (dev_info[unitnum].handle); + } + dev_info[unitnum].handle = INVALID_HANDLE_VALUE; } static void free_scsi_device(int dev) { - close_scsi_device (dev); - xfree(dev_info[dev].name); - xfree(dev_info[dev].drvpath); - xfree(dev_info[dev].inquirydata); - VirtualFree (dev_info[dev].scsibuf, 0, MEM_RELEASE); - dev_info[dev].name = NULL; - dev_info[dev].drvpath = NULL; - dev_info[dev].inquirydata = NULL; - dev_info[dev].scsibuf = NULL; - memset(&dev_info[dev], 0, sizeof (struct dev_info_spti)); + close_scsi_device (dev); + xfree(dev_info[dev].name); + xfree(dev_info[dev].drvpath); + xfree(dev_info[dev].inquirydata); + VirtualFree (dev_info[dev].scsibuf, 0, MEM_RELEASE); + dev_info[dev].name = NULL; + dev_info[dev].drvpath = NULL; + dev_info[dev].inquirydata = NULL; + dev_info[dev].scsibuf = NULL; + memset(&dev_info[dev], 0, sizeof (struct dev_info_spti)); } static int rescan(void); static int open_scsi_bus (int flags) { - int i; - - total_devices = 0; - uae_sem_init (&scgp_sem, 0, 1); - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - memset (&dev_info[i], 0, sizeof (struct dev_info_spti)); - dev_info[i].handle = INVALID_HANDLE_VALUE; - } - rescan(); - return total_devices; + int i; + + total_devices = 0; + uae_sem_init (&scgp_sem, 0, 1); + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + memset (&dev_info[i], 0, sizeof (struct dev_info_spti)); + dev_info[i].handle = INVALID_HANDLE_VALUE; + } + rescan(); + return total_devices; } static void close_scsi_bus (void) { - int i; - for (i = 0; i < total_devices; i++) - free_scsi_device (i); + int i; + for (i = 0; i < total_devices; i++) + free_scsi_device (i); } static void checkcapabilities (int unitnum) { - struct dev_info_spti *di = &dev_info[unitnum]; - STORAGE_ADAPTER_DESCRIPTOR desc; - STORAGE_PROPERTY_QUERY query = { 0 }; - DWORD ret, status; - - query.PropertyId = StorageAdapterProperty; - query.QueryType = PropertyStandardQuery; - status = DeviceIoControl (di->handle, IOCTL_STORAGE_QUERY_PROPERTY, - &query, sizeof query, &desc, sizeof desc, &ret, NULL); - if (status) { - if (desc.Version > offsetof (STORAGE_ADAPTER_DESCRIPTOR, BusType)) - write_log (L"SCSI CAPS: BusType=%d, MaxTransfer=0x%08X, Mask=0x%08X\n", - desc.BusType, desc.MaximumTransferLength, desc.AlignmentMask); - } + struct dev_info_spti *di = &dev_info[unitnum]; + STORAGE_ADAPTER_DESCRIPTOR desc; + STORAGE_PROPERTY_QUERY query = { 0 }; + DWORD ret, status; + + query.PropertyId = StorageAdapterProperty; + query.QueryType = PropertyStandardQuery; + status = DeviceIoControl (di->handle, IOCTL_STORAGE_QUERY_PROPERTY, + &query, sizeof query, &desc, sizeof desc, &ret, NULL); + if (status) { + if (desc.Version > offsetof (STORAGE_ADAPTER_DESCRIPTOR, BusType)) + write_log (L"SCSI CAPS: BusType=%d, MaxTransfer=0x%08X, Mask=0x%08X\n", + desc.BusType, desc.MaximumTransferLength, desc.AlignmentMask); + } } 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 inqlen = 0; - - di->isatapi = 0; - di->removable = 0; - di->type = 0x1f; - if (!p) { - if (log_scsi) - write_log (L"SPTI: INQUIRY failed\n"); - return 0; - } - 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) - di->isatapi = 1; - memcpy (inquirydata, p, inqlen); - if (log_scsi) { - if (outlen >= INQUIRY_SIZE) { - char tmp[20]; - TCHAR *s1, *s2; - - memcpy (tmp, p + 8, 8); - tmp[8] = 0; - s1 = au (tmp); - memcpy (tmp, p + 16, 16); - tmp[16] = 0; - s2 = au (tmp); - write_log (L"SPTI: INQUIRY: %02X%02X%02X %d '%s' '%s'\n", - p[0], p[1], p[2], di->isatapi, s1, s2); - xfree (s2); - xfree (s1); + 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 inqlen = 0; + + di->isatapi = 0; + di->removable = 0; + di->type = 0x1f; + if (!p) { + if (log_scsi) + write_log (L"SPTI: INQUIRY failed\n"); + return 0; + } + 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) + di->isatapi = 1; + memcpy (inquirydata, p, inqlen); + if (log_scsi) { + if (outlen >= INQUIRY_SIZE) { + char tmp[20]; + TCHAR *s1, *s2; + + memcpy (tmp, p + 8, 8); + tmp[8] = 0; + s1 = au (tmp); + memcpy (tmp, p + 16, 16); + tmp[16] = 0; + s2 = au (tmp); + write_log (L"SPTI: INQUIRY: %02X%02X%02X %d '%s' '%s'\n", + p[0], p[1], p[2], di->isatapi, s1, s2); + xfree (s2); + xfree (s1); + } } - } - return inqlen; + return inqlen; } static int mediacheck (int unitnum) { - uae_u8 cmd [6] = { 0,0,0,0,0,0 }; /* TEST UNIT READY */ - int v; - if (dev_info[unitnum].handle == INVALID_HANDLE_VALUE) - return 0; - v = execscsicmd (unitnum, cmd, sizeof (cmd), 0, 0); - return v >= 0 ? 1 : 0; + uae_u8 cmd [6] = { 0,0,0,0,0,0 }; /* TEST UNIT READY */ + int v; + if (dev_info[unitnum].handle == INVALID_HANDLE_VALUE) + return 0; + v = execscsicmd (unitnum, cmd, sizeof (cmd), 0, 0); + return v >= 0 ? 1 : 0; } static int mediacheck_full (int unitnum, struct device_info *di) { - uae_u8 cmd1[10] = { 0x25,0,0,0,0,0,0,0,0,0 }; /* READ CAPACITY */ - uae_u8 *p; - int outlen; - - 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; - outlen = 32; - 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->sectorspertrack = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]) + 1; - 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 */ + uae_u8 cmd1[10] = { 0x25,0,0,0,0,0,0,0,0,0 }; /* READ CAPACITY */ + uae_u8 *p; + int outlen; + + 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; outlen = 32; - p = execscsicmd_in (unitnum, cmd2, sizeof cmd2, &outlen); - if (p && outlen >= 4) { - di->write_protected = (p[3] & 0x80) ? 1 : 0; + 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->sectorspertrack = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]) + 1; + 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; + } } - } -// write_log (L"mediacheck_full(%d,%d,%d,%d,%d)\n", -// di->bytespersector, di->sectorspertrack, di->trackspercylinder, di->cylinders, di->write_protected); - return 1; + // write_log (L"mediacheck_full(%d,%d,%d,%d,%d)\n", + // di->bytespersector, di->sectorspertrack, di->trackspercylinder, di->cylinders, di->write_protected); + return 1; } int open_scsi_device (int unitnum) { - HANDLE h; - TCHAR *dev; - struct dev_info_spti *di; - - di = &dev_info[unitnum]; - if (unitnum >= total_devices) - return 0; - if (!di) - return 0; - if (di->bus >= 0) { - dev = xmalloc (100); - _stprintf (dev, L"\\\\.\\Scsi%d:", di->bus); - } else { - dev = my_strdup (di->drvpath); - } - if (!di->scsibuf) - di->scsibuf = VirtualAlloc (NULL, DEVICE_SCSI_BUFSIZE, MEM_COMMIT, PAGE_READWRITE); - h = CreateFile(dev,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); - di->handle = h; - if (h == INVALID_HANDLE_VALUE) { - write_log (L"SPTI: failed to open unit %d err=%d ('%s')\n", unitnum, GetLastError (), dev); - } else { - uae_u8 inqdata[INQUIRY_SIZE + 1] = { 0 }; - checkcapabilities (unitnum); - if (!inquiry (unitnum, di, inqdata)) { - write_log (L"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); - xfree (dev); - return 0; + HANDLE h; + TCHAR *dev; + struct dev_info_spti *di; + + di = &dev_info[unitnum]; + if (unitnum >= total_devices) + return 0; + if (!di) + return 0; + if (di->bus >= 0) { + dev = xmalloc (100); + _stprintf (dev, L"\\\\.\\Scsi%d:", di->bus); + } else { + dev = my_strdup (di->drvpath); } - inqdata[INQUIRY_SIZE] = 0; - di->name = my_strdup_ansi (inqdata + 8); - if (di->type == INQ_ROMD) { - dev_info[unitnum].mediainserted = mediacheck (unitnum); - write_log (L"SPTI: unit %d opened [%s], %s, '%s'\n", unitnum, - di->isatapi ? L"ATAPI" : L"SCSI", - di->mediainserted ? L"media inserted" : L"drive empty", - di->name); + if (!di->scsibuf) + di->scsibuf = VirtualAlloc (NULL, DEVICE_SCSI_BUFSIZE, MEM_COMMIT, PAGE_READWRITE); + h = CreateFile(dev,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); + di->handle = h; + if (h == INVALID_HANDLE_VALUE) { + write_log (L"SPTI: failed to open unit %d err=%d ('%s')\n", unitnum, GetLastError (), dev); } else { - write_log (L"SPTI: unit %d, type %d, '%s'\n", - unitnum, di->type, di->name); + uae_u8 inqdata[INQUIRY_SIZE + 1] = { 0 }; + checkcapabilities (unitnum); + if (!inquiry (unitnum, di, inqdata)) { + write_log (L"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); + xfree (dev); + return 0; + } + inqdata[INQUIRY_SIZE] = 0; + di->name = my_strdup_ansi (inqdata + 8); + if (di->type == INQ_ROMD) { + dev_info[unitnum].mediainserted = mediacheck (unitnum); + write_log (L"SPTI: unit %d opened [%s], %s, '%s'\n", unitnum, + di->isatapi ? L"ATAPI" : L"SCSI", + di->mediainserted ? L"media inserted" : L"drive empty", + di->name); + } else { + write_log (L"SPTI: unit %d, type %d, '%s'\n", + unitnum, di->type, di->name); + } + di->inquirydata = xmalloc (INQUIRY_SIZE); + memcpy (di->inquirydata, inqdata, INQUIRY_SIZE); + xfree (dev); + return 1; } - di->inquirydata = xmalloc (INQUIRY_SIZE); - memcpy (di->inquirydata, inqdata, INQUIRY_SIZE); xfree (dev); - return 1; - } - xfree (dev); - return 0; + return 0; } static int adddrive (TCHAR *drvpath, int bus, int pathid, int targetid, int lunid, int scanmode) { - struct dev_info_spti *di; - int cnt = total_devices, i; - int freeit = 1; - - if (cnt >= MAX_TOTAL_DEVICES) - return 0; - for (i = 0; i < total_devices; i++) { - di = &dev_info[i]; - if (!_tcscmp (drvpath, di->drvpath)) - return 0; - } - write_log (L"SPTI: unit %d '%s' added\n", total_devices, drvpath); - di = &dev_info[total_devices]; - di->drvpath = my_strdup (drvpath); - di->type = 0; - di->bus = bus; - di->path = pathid; - di->target = targetid; - di->lun = lunid; - di->scanmode = scanmode; - total_devices++; - if (open_scsi_device (cnt)) { - for (i = 0; i < cnt; i++) { - if (!memcmp (di->inquirydata, dev_info[i].inquirydata, INQUIRY_SIZE) && di->scanmode != dev_info[i].scanmode) { - write_log (L"duplicate device, skipped..\n"); - break; - } + struct dev_info_spti *di; + int cnt = total_devices, i; + int freeit = 1; + + if (cnt >= MAX_TOTAL_DEVICES) + return 0; + for (i = 0; i < total_devices; i++) { + di = &dev_info[i]; + if (!_tcscmp (drvpath, di->drvpath)) + return 0; } - if (i == cnt) { - freeit = 0; - close_scsi_device (cnt); + write_log (L"SPTI: unit %d '%s' added\n", total_devices, drvpath); + di = &dev_info[total_devices]; + di->drvpath = my_strdup (drvpath); + di->type = 0; + di->bus = bus; + di->path = pathid; + di->target = targetid; + di->lun = lunid; + di->scanmode = scanmode; + total_devices++; + if (open_scsi_device (cnt)) { + for (i = 0; i < cnt; i++) { + if (!memcmp (di->inquirydata, dev_info[i].inquirydata, INQUIRY_SIZE) && di->scanmode != dev_info[i].scanmode) { + write_log (L"duplicate device, skipped..\n"); + break; + } + } + if (i == cnt) { + freeit = 0; + close_scsi_device (cnt); + } } - } - if (freeit) { - free_scsi_device (cnt); - total_devices--; - } - return 1; + if (freeit) { + free_scsi_device (cnt); + total_devices--; + } + return 1; } 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; - dispti = &dev_info[unitnum]; - _tcscpy (di->label, 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 = dispti->type; - di->id = unitnum + 1; - if (log_scsi) { - write_log (L"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; + struct dev_info_spti *dispti; + if (unitnum >= MAX_TOTAL_DEVICES || dev_info[unitnum].handle == INVALID_HANDLE_VALUE) + return 0; + dispti = &dev_info[unitnum]; + _tcscpy (di->label, 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 = dispti->type; + di->id = unitnum + 1; + if (log_scsi) { + write_log (L"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; } void win32_spti_media_change (TCHAR driveletter, int insert) { - int i, now; - - for (i = 0; i < total_devices; i++) { - if (dev_info[i].type == INQ_ROMD) { - now = mediacheck (i); - if (now != dev_info[i].mediainserted) { - write_log (L"SPTI: media change %c %d\n", driveletter, insert); - dev_info[i].mediainserted = now; - scsi_do_disk_change (i + 1, insert); - } + int i, now; + + for (i = 0; i < total_devices; i++) { + if (dev_info[i].type == INQ_ROMD) { + now = mediacheck (i); + if (now != dev_info[i].mediainserted) { + write_log (L"SPTI: media change %c %d\n", driveletter, insert); + dev_info[i].mediainserted = now; + scsi_do_disk_change (i + 1, insert); + } + } } - } } static int check_isatapi (int unitnum) { - return dev_info[unitnum].isatapi; + return dev_info[unitnum].isatapi; } static struct device_scsi_info *scsi_info (int unitnum, struct device_scsi_info *dsi) { - dsi->buffer = dev_info[unitnum].scsibuf; - dsi->bufsize = DEVICE_SCSI_BUFSIZE; - return dsi; + dsi->buffer = dev_info[unitnum].scsibuf; + dsi->bufsize = DEVICE_SCSI_BUFSIZE; + return dsi; } struct device_functions devicefunc_win32_spti = { - open_scsi_bus, close_scsi_bus, open_scsi_device, close_scsi_device, info_device, - execscsicmd_out, execscsicmd_in, execscsicmd_direct, - 0, 0, 0, 0, 0, 0, 0, 0, check_isatapi, scsi_info, 0 + open_scsi_bus, close_scsi_bus, open_scsi_device, close_scsi_device, info_device, + execscsicmd_out, execscsicmd_in, execscsicmd_direct, + 0, 0, 0, 0, 0, 0, 0, 0, check_isatapi, scsi_info, 0 }; static int getCDROMProperty (int idx, HDEVINFO DevInfo, const GUID *guid) { - SP_DEVICE_INTERFACE_DATA interfaceData; - PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = NULL; - DWORD interfaceDetailDataSize, reqSize; - DWORD status, errorCode; - - interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA); - status = SetupDiEnumDeviceInterfaces ( - DevInfo, // Interface Device Info handle - 0, // Device Info data - guid, // Interface registered by driver - idx, // Member - &interfaceData // Device Interface Data - ); - if (status == FALSE) - return FALSE; - - status = SetupDiGetDeviceInterfaceDetail ( - DevInfo, // Interface Device info handle - &interfaceData, // Interface data for the event class - NULL, // Checking for buffer size - 0, // Checking for buffer size - &reqSize, // Buffer size required to get the detail data - NULL // Checking for buffer size - ); - - if (status == FALSE) { - errorCode = GetLastError(); - if (errorCode != ERROR_INSUFFICIENT_BUFFER) - return FALSE; - } - - interfaceDetailDataSize = reqSize; - interfaceDetailData = malloc (interfaceDetailDataSize); - if (interfaceDetailData == NULL) - return FALSE; - interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA); - - status = SetupDiGetDeviceInterfaceDetail ( + SP_DEVICE_INTERFACE_DATA interfaceData; + PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = NULL; + DWORD interfaceDetailDataSize, reqSize; + DWORD status, errorCode; + + interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA); + status = SetupDiEnumDeviceInterfaces ( + DevInfo, // Interface Device Info handle + 0, // Device Info data + guid, // Interface registered by driver + idx, // Member + &interfaceData // Device Interface Data + ); + if (status == FALSE) + return FALSE; + + status = SetupDiGetDeviceInterfaceDetail ( + DevInfo, // Interface Device info handle + &interfaceData, // Interface data for the event class + NULL, // Checking for buffer size + 0, // Checking for buffer size + &reqSize, // Buffer size required to get the detail data + NULL // Checking for buffer size + ); + + if (status == FALSE) { + errorCode = GetLastError(); + if (errorCode != ERROR_INSUFFICIENT_BUFFER) + return FALSE; + } + + interfaceDetailDataSize = reqSize; + interfaceDetailData = malloc (interfaceDetailDataSize); + if (interfaceDetailData == NULL) + return FALSE; + interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA); + + status = SetupDiGetDeviceInterfaceDetail ( DevInfo, // Interface Device info handle &interfaceData, // Interface data for the event class interfaceDetailData, // Interface detail data @@ -578,151 +578,151 @@ static int getCDROMProperty (int idx, HDEVINFO DevInfo, const GUID *guid) &reqSize, // Buffer size required to get the detail data NULL); // Interface device info - if (status == FALSE) - return FALSE; + if (status == FALSE) + return FALSE; - adddrive (interfaceDetailData->DevicePath, -1, -1, -1, -1, 1); + adddrive (interfaceDetailData->DevicePath, -1, -1, -1, -1, 1); - free (interfaceDetailData); + free (interfaceDetailData); - return TRUE; + return TRUE; } #define SCSI_INFO_BUFFER_SIZE 0x5000 static void scanscsi (void) { - PSCSI_BUS_DATA BusData; - PSCSI_INQUIRY_DATA InquiryData; - PSCSI_ADAPTER_BUS_INFO AdapterInfo; - HANDLE h; - BOOL status; - BOOL Claimed; - ULONG returnedLength; - SHORT Bus, Luns; - DWORD bytesTransferred; - int idx; - TCHAR DeviceName[256]; - - AdapterInfo = xmalloc (SCSI_INFO_BUFFER_SIZE) ; - if (AdapterInfo == NULL) - return; - - idx = 0; - for (;;) { - _stprintf (DeviceName, L"\\\\.\\Scsi%d:", idx++); - h = CreateFile (DeviceName, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, // no SECURITY_ATTRIBUTES structure - OPEN_EXISTING, // No special create flags - 0, // No special attributes - NULL); - if (h == INVALID_HANDLE_VALUE) - return; - - if(!DeviceIoControl (h, - IOCTL_SCSI_RESCAN_BUS, - NULL, - 0, - NULL, - 0, - &bytesTransferred, - NULL)) { - write_log (L"Rescan SCSI port %d failed [Error %d]\n", idx - 1, GetLastError()); - CloseHandle (h); - continue; - } + PSCSI_BUS_DATA BusData; + PSCSI_INQUIRY_DATA InquiryData; + PSCSI_ADAPTER_BUS_INFO AdapterInfo; + HANDLE h; + BOOL status; + BOOL Claimed; + ULONG returnedLength; + SHORT Bus, Luns; + DWORD bytesTransferred; + int idx; + TCHAR DeviceName[256]; + + AdapterInfo = xmalloc (SCSI_INFO_BUFFER_SIZE) ; + if (AdapterInfo == NULL) + return; + + idx = 0; + for (;;) { + _stprintf (DeviceName, L"\\\\.\\Scsi%d:", idx++); + h = CreateFile (DeviceName, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, // no SECURITY_ATTRIBUTES structure + OPEN_EXISTING, // No special create flags + 0, // No special attributes + NULL); + if (h == INVALID_HANDLE_VALUE) + return; + + if(!DeviceIoControl (h, + IOCTL_SCSI_RESCAN_BUS, + NULL, + 0, + NULL, + 0, + &bytesTransferred, + NULL)) { + write_log (L"Rescan SCSI port %d failed [Error %d]\n", idx - 1, GetLastError()); + CloseHandle (h); + continue; + } - // Get the SCSI inquiry data for all devices for the given SCSI bus - status = DeviceIoControl ( - h, - IOCTL_SCSI_GET_INQUIRY_DATA, - NULL, - 0, - AdapterInfo, - SCSI_INFO_BUFFER_SIZE, - &returnedLength, - NULL); + // Get the SCSI inquiry data for all devices for the given SCSI bus + status = DeviceIoControl ( + h, + IOCTL_SCSI_GET_INQUIRY_DATA, + NULL, + 0, + AdapterInfo, + SCSI_INFO_BUFFER_SIZE, + &returnedLength, + NULL); + + if (!status) { + write_log (L"Error in IOCTL_SCSI_GET_INQUIRY_DATA\n" ); + CloseHandle (h); + continue; + } - if (!status) { - write_log (L"Error in IOCTL_SCSI_GET_INQUIRY_DATA\n" ); - CloseHandle (h); - continue; + for (Bus = 0; Bus < AdapterInfo->NumberOfBuses; Bus++) { + int luncheck = 0; + BusData = &AdapterInfo->BusData[Bus]; + InquiryData = (PSCSI_INQUIRY_DATA) ((PUCHAR)AdapterInfo + BusData->InquiryDataOffset); + for (Luns = 0; Luns < BusData->NumberOfLogicalUnits; Luns++) { + TCHAR label[100]; + int type = InquiryData->InquiryData[0] & 0x1f; + Claimed = InquiryData->DeviceClaimed; + write_log (L"SCSI=%d Initiator=%d Path=%d Target=%d LUN=%d Claimed=%s Type=%d\n", + idx - 1, + BusData->InitiatorBusId, InquiryData->PathId, InquiryData->TargetId, + InquiryData->Lun, Claimed ? L"Yes" : L"No ", type); + if (Claimed == 0 && !luncheck) { + luncheck = 1; + _stprintf (label, L"SCSI(%d):%d:%d:%d:%d", idx - 1, BusData->InitiatorBusId, + InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun); + adddrive (label, idx - 1, InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun, 3); + } + InquiryData = (PSCSI_INQUIRY_DATA) ((PUCHAR)AdapterInfo + InquiryData->NextInquiryDataOffset); + } // for Luns + } // for Bus + CloseHandle(h); } - - for (Bus = 0; Bus < AdapterInfo->NumberOfBuses; Bus++) { - int luncheck = 0; - BusData = &AdapterInfo->BusData[Bus]; - InquiryData = (PSCSI_INQUIRY_DATA) ((PUCHAR)AdapterInfo + BusData->InquiryDataOffset); - for (Luns = 0; Luns < BusData->NumberOfLogicalUnits; Luns++) { - TCHAR label[100]; - int type = InquiryData->InquiryData[0] & 0x1f; - Claimed = InquiryData->DeviceClaimed; - write_log (L"SCSI=%d Initiator=%d Path=%d Target=%d LUN=%d Claimed=%s Type=%d\n", - idx - 1, - BusData->InitiatorBusId, InquiryData->PathId, InquiryData->TargetId, - InquiryData->Lun, Claimed ? L"Yes" : L"No ", type); - if (Claimed == 0 && !luncheck) { - luncheck = 1; - _stprintf (label, L"SCSI(%d):%d:%d:%d:%d", idx - 1, BusData->InitiatorBusId, - InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun); - adddrive (label, idx - 1, InquiryData->PathId, InquiryData->TargetId, InquiryData->Lun, 3); - } - InquiryData = (PSCSI_INQUIRY_DATA) ((PUCHAR)AdapterInfo + InquiryData->NextInquiryDataOffset); - } // for Luns - } // for Bus - CloseHandle(h); - } } static const GUID *guids[] = { - &GUID_DEVINTERFACE_CDROM, - &GUID_DEVCLASS_IMAGE, - &GUID_DEVCLASS_TAPEDRIVE, - NULL }; -static const TCHAR *scsinames[] = { L"Tape", L"Scanner", L"Changer", NULL }; + &GUID_DEVINTERFACE_CDROM, + &GUID_DEVCLASS_IMAGE, + &GUID_DEVCLASS_TAPEDRIVE, + NULL }; + static const TCHAR *scsinames[] = { L"Tape", L"Scanner", L"Changer", NULL }; + + static int rescan (void) + { + int idx, idx2; + + for (idx2 = 0; guids[idx2]; idx2++) { + HDEVINFO hDevInfo = SetupDiGetClassDevs( + guids[idx2], + NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); + if (hDevInfo != INVALID_HANDLE_VALUE) { + for (idx = 0; ; idx++) { + if (!getCDROMProperty (idx, hDevInfo, guids[idx2])) + break; + } + SetupDiDestroyDeviceInfoList (hDevInfo); + } + } -static int rescan (void) -{ - int idx, idx2; - - for (idx2 = 0; guids[idx2]; idx2++) { - HDEVINFO hDevInfo = SetupDiGetClassDevs( - guids[idx2], - NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); - if (hDevInfo != INVALID_HANDLE_VALUE) { - for (idx = 0; ; idx++) { - if (!getCDROMProperty (idx, hDevInfo, guids[idx2])) - break; - } - SetupDiDestroyDeviceInfoList (hDevInfo); - } - } - - for (idx2 = 0; scsinames[idx2]; idx2++) { - int max = 10; - for (idx = 0; idx < max; idx++) { - TCHAR tmp[100]; - HANDLE h; - _stprintf (tmp, L"\\\\.\\%s%d", scsinames[idx2], idx); - h = CreateFile (tmp, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, 0, NULL); - if (h != INVALID_HANDLE_VALUE) { - adddrive (tmp, -1, -1, -1, -1, 2); - CloseHandle (h); - if (idx == max - 1) - max++; - } + for (idx2 = 0; scsinames[idx2]; idx2++) { + int max = 10; + for (idx = 0; idx < max; idx++) { + TCHAR tmp[100]; + HANDLE h; + _stprintf (tmp, L"\\\\.\\%s%d", scsinames[idx2], idx); + h = CreateFile (tmp, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (h != INVALID_HANDLE_VALUE) { + adddrive (tmp, -1, -1, -1, -1, 2); + CloseHandle (h); + if (idx == max - 1) + max++; + } + } + } + if (currprefs.win32_uaescsimode == UAESCSI_SPTISCAN) { + write_log (L"SCSI adapter enumeration..\n"); + scanscsi (); + write_log (L"SCSI adapter enumeration ends\n"); + } + return 1; } - } - if (currprefs.win32_uaescsimode == UAESCSI_SPTISCAN) { - write_log (L"SCSI adapter enumeration..\n"); - scanscsi (); - write_log (L"SCSI adapter enumeration ends\n"); - } - return 1; -} #endif diff --git a/od-win32/bsdsock.c b/od-win32/bsdsock.c index d620d495..1252917f 100644 --- a/od-win32/bsdsock.c +++ b/od-win32/bsdsock.c @@ -1,14 +1,14 @@ /* - * UAE - The Un*x Amiga Emulator - * - * bsdsocket.library emulation - Win32 OS-dependent part - * - * Copyright 1997,98 Mathias Ortmann - * Copyright 1999,2000 Brian King - * - * GNU Public License - * - */ +* UAE - The Un*x Amiga Emulator +* +* bsdsocket.library emulation - Win32 OS-dependent part +* +* Copyright 1997,98 Mathias Ortmann +* Copyright 1999,2000 Brian King +* +* GNU Public License +* +*/ #include #include "sysconfig.h" @@ -41,11 +41,11 @@ static int hWndSelector = 0; /* Set this to zero to get hSockWnd */ struct threadargs { - struct socketbase *sb; - uae_u32 args1; - uae_u32 args2; - int args3; - long args4; + struct socketbase *sb; + uae_u32 args1; + uae_u32 args2; + int args3; + long args4; uae_char buf[MAXGETHOSTSTRUCT]; }; @@ -149,17 +149,17 @@ static int mySockStartup(void) if (!bsd) { bsd = calloc (sizeof (struct bsdsockdata), 1); for (i = 0; i < MAX_GET_THREADS; i++) - threadindextable[i] = i; + threadindextable[i] = i; } if (WSAStartup (MAKEWORD (SOCKVER_MAJOR, SOCKVER_MINOR), &bsd->wsbData)) { - lasterror = WSAGetLastError(); - if(lasterror == WSAVERNOTSUPPORTED) { + lasterror = WSAGetLastError(); + if(lasterror == WSAVERNOTSUPPORTED) { TCHAR szMessage[MAX_DPATH]; WIN32GUI_LoadUIString(IDS_WSOCK2NEEDED, szMessage, MAX_DPATH); - gui_message(szMessage); - } else + gui_message(szMessage); + } else write_log (L"BSDSOCK: ERROR - Unable to initialize Windows socket layer! Error code: %d\n", lasterror); - return 0; + return 0; } ss = au (bsd->wsbData.szDescription); @@ -181,10 +181,10 @@ static int mySockStartup(void) int init_socket_layer (void) { - int result = 0; + int result = 0; - deinit_socket_layer (); - if (currprefs.socket_emu) { + deinit_socket_layer (); + if (currprefs.socket_emu) { if((result = mySockStartup())) { if(bsd->hSockThread == NULL) { WNDCLASS wc; // Set up an invisible window and dummy wndproc @@ -213,9 +213,9 @@ int init_socket_layer (void) NULL, NULL, 0, NULL); bsd->hSockThread = THREAD(sock_thread, NULL); if (!bsd->hSockWnd) { - write_log (L"bsdsocket initialization failed\n"); - deinit_socket_layer(); - return 0; + write_log (L"bsdsocket initialization failed\n"); + deinit_socket_layer(); + return 0; } } } @@ -257,7 +257,7 @@ static void close_selectget_threads(void) void deinit_socket_layer(void) { if (!bsd) - return; + return; if(bsd->hSockThread) { HANDLE t = bsd->hSockThread; DeleteCriticalSection(&bsd->csSigQueueLock); @@ -325,9 +325,9 @@ void host_closesocketquick(SOCKET s) BOOL b = 1; if(s) { - setsockopt(s, SOL_SOCKET, SO_DONTLINGER, (uae_char*)&b, sizeof(b)); - shutdown(s, 1); - closesocket(s); + setsockopt(s, SOL_SOCKET, SO_DONTLINGER, (uae_char*)&b, sizeof(b)); + shutdown(s, 1); + closesocket(s); } } @@ -495,9 +495,9 @@ static void cancelasyncmsg(TrapContext *context, unsigned int wMsg) void sockabort(SB) { - locksigqueue(); + locksigqueue(); - unlocksigqueue(); + unlocksigqueue(); } void setWSAAsyncSelect(SB, uae_u32 sd, SOCKET s, long lEvent ) @@ -537,30 +537,30 @@ void setWSAAsyncSelect(SB, uae_u32 sd, SOCKET s, long lEvent ) // address cleaning static void prephostaddr(SOCKADDR_IN *addr) { - addr->sin_family = AF_INET; + addr->sin_family = AF_INET; } static void prepamigaaddr(struct sockaddr *realpt, int len) { - // little endian address family value to the byte sin_family member - ((uae_u8*)realpt)[1] = *((uae_u8*)realpt); + // little endian address family value to the byte sin_family member + ((uae_u8*)realpt)[1] = *((uae_u8*)realpt); - // set size of address - *((uae_u8*)realpt) = len; + // set size of address + *((uae_u8*)realpt) = len; } int host_dup2socket(SB, int fd1, int fd2) { - SOCKET s1,s2; + SOCKET s1,s2; - BSDTRACE((L"dup2socket(%d,%d) -> ",fd1,fd2)); + BSDTRACE((L"dup2socket(%d,%d) -> ",fd1,fd2)); fd1++; - s1 = getsock(sb, fd1); - if (s1 != INVALID_SOCKET) { + s1 = getsock(sb, fd1); + if (s1 != INVALID_SOCKET) { if (fd2 != -1) { - if ((unsigned int) (fd2) >= (unsigned int) sb->dtablesize) { + if ((unsigned int) (fd2) >= (unsigned int) sb->dtablesize) { BSDTRACE ((L"Bad file descriptor (%d)\n", fd2)); bsdsocklib_seterrno (sb, 9); /* EBADF */ } @@ -568,40 +568,40 @@ int host_dup2socket(SB, int fd1, int fd2) s2 = getsock(sb,fd2); if (s2 != INVALID_SOCKET) { shutdown(s2,1); - closesocket(s2); + closesocket(s2); } setsd(sb,fd2,s1); - BSDTRACE((L"0\n")); + BSDTRACE((L"0\n")); return 0; } else { fd2 = getsd(sb, 1); setsd(sb,fd2,s1); - BSDTRACE((L"%d\n",fd2)); + BSDTRACE((L"%d\n",fd2)); return (fd2 - 1); } } - BSDTRACE((L"-1\n")); - return -1; + BSDTRACE((L"-1\n")); + return -1; } int host_socket(SB, int af, int type, int protocol) { - int sd; - SOCKET s; - unsigned long nonblocking = 1; + int sd; + SOCKET s; + unsigned long nonblocking = 1; - BSDTRACE((L"socket(%s,%s,%d) -> ",af == AF_INET ? "AF_INET" : "AF_other",type == SOCK_STREAM ? "SOCK_STREAM" : type == SOCK_DGRAM ? "SOCK_DGRAM " : "SOCK_RAW",protocol)); + BSDTRACE((L"socket(%s,%s,%d) -> ",af == AF_INET ? "AF_INET" : "AF_other",type == SOCK_STREAM ? "SOCK_STREAM" : type == SOCK_DGRAM ? "SOCK_DGRAM " : "SOCK_RAW",protocol)); - if ((s = socket(af,type,protocol)) == INVALID_SOCKET) { + if ((s = socket(af,type,protocol)) == INVALID_SOCKET) { SETERRNO; BSDTRACE((L"failed (%d)\n",sb->sb_errno)); return -1; - } else + } else sd = getsd(sb,s); sb->ftable[sd-1] = SF_BLOCKING; - ioctlsocket(s,FIONBIO,&nonblocking); - BSDTRACE((L"%d\n",sd)); + ioctlsocket(s,FIONBIO,&nonblocking); + BSDTRACE((L"%d\n",sd)); if (type == SOCK_RAW) { if (protocol==IPPROTO_UDP) { @@ -623,19 +623,19 @@ int host_socket(SB, int af, int type, int protocol) uae_u32 host_bind(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen) { - uae_char buf[MAXADDRLEN]; - uae_u32 success = 0; - SOCKET s; + uae_char buf[MAXADDRLEN]; + uae_u32 success = 0; + SOCKET s; sd++; - BSDTRACE((L"bind(%d,0x%lx,%d) -> ",sd, name, namelen)); - s = getsock(sb, sd); + BSDTRACE((L"bind(%d,0x%lx,%d) -> ",sd, name, namelen)); + s = getsock(sb, sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (namelen <= sizeof buf) { if (!addr_valid (L"host_bind", name, namelen)) return 0; - memcpy(buf, get_real_address (name), namelen); + memcpy(buf, get_real_address (name), namelen); // some Amiga programs set this field to bogus values prephostaddr((SOCKADDR_IN *)buf); @@ -647,45 +647,45 @@ uae_u32 host_bind(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen) BSDTRACE((L"OK\n")); } else write_log (L"BSDSOCK: ERROR - Excessive namelen (%d) in bind()!\n", namelen); - } + } - return success; + return success; } uae_u32 host_listen(SB, uae_u32 sd, uae_u32 backlog) { - SOCKET s; - uae_u32 success = -1; + SOCKET s; + uae_u32 success = -1; sd++; - BSDTRACE((L"listen(%d,%d) -> ", sd, backlog)); - s = getsock(sb, sd); + BSDTRACE((L"listen(%d,%d) -> ", sd, backlog)); + s = getsock(sb, sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if ((success = listen(s,backlog)) != 0) { SETERRNO; BSDTRACE((L"failed (%d)\n",sb->sb_errno)); } else BSDTRACE((L"OK\n")); - } - return success; + } + return success; } void host_accept(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 namelen) { - struct sockaddr *rp_name, *rp_nameuae; - struct sockaddr sockaddr; - int hlen, hlenuae = 0; - SOCKET s, s2; - int success = 0; - unsigned int wMsg; - - sd++; + struct sockaddr *rp_name, *rp_nameuae; + struct sockaddr sockaddr; + int hlen, hlenuae = 0; + SOCKET s, s2; + int success = 0; + unsigned int wMsg; + + sd++; if (name != 0) { if (!addr_valid (L"host_accept1", name, sizeof(struct sockaddr)) || !addr_valid (L"host_accept2", namelen, 4)) return; rp_nameuae = rp_name = (struct sockaddr *)get_real_address (name); - hlenuae = hlen = get_long (namelen); + hlenuae = hlen = get_long (namelen); if (hlenuae < sizeof(sockaddr)) { // Fix for CNET BBS Windows must have 16 Bytes (sizeof(sockaddr)) otherwise Error WSAEFAULT rp_name = &sockaddr; @@ -695,11 +695,11 @@ void host_accept(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 nam rp_name = &sockaddr; hlen = sizeof(sockaddr); } - BSDTRACE((L"accept(%d,%d,%d) -> ",sd,name,hlenuae)); + BSDTRACE((L"accept(%d,%d,%d) -> ",sd,name,hlenuae)); - s = getsock(sb, (int)sd); + s = getsock(sb, (int)sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { BEGINBLOCKING; s2 = accept(s, rp_name, &hlen); @@ -772,50 +772,50 @@ void host_accept(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 nam typedef enum { - connect_req, - recvfrom_req, - sendto_req, - abort_req, - last_req + connect_req, + recvfrom_req, + sendto_req, + abort_req, + last_req } threadsock_e; struct threadsock_packet { - threadsock_e packet_type; - union - { - struct sendto_params + threadsock_e packet_type; + union { - uae_char *buf; - uae_char *realpt; - uae_u32 sd; - uae_u32 msg; - uae_u32 len; - uae_u32 flags; - uae_u32 to; - uae_u32 tolen; - } sendto_s; - struct recvfrom_params - { - uae_char *realpt; - uae_u32 addr; - uae_u32 len; - uae_u32 flags; - struct sockaddr *rp_addr; - int *hlen; - } recvfrom_s; - struct connect_params - { - uae_char *buf; - uae_u32 namelen; - } connect_s; - struct abort_params - { - SOCKET *newsock; - } abort_s; - } params; - SOCKET s; - SB; + struct sendto_params + { + uae_char *buf; + uae_char *realpt; + uae_u32 sd; + uae_u32 msg; + uae_u32 len; + uae_u32 flags; + uae_u32 to; + uae_u32 tolen; + } sendto_s; + struct recvfrom_params + { + uae_char *realpt; + uae_u32 addr; + uae_u32 len; + uae_u32 flags; + struct sockaddr *rp_addr; + int *hlen; + } recvfrom_s; + struct connect_params + { + uae_char *buf; + uae_u32 namelen; + } connect_s; + struct abort_params + { + SOCKET *newsock; + } abort_s; + } params; + SOCKET s; + SB; } sockreq; // sockreg.sb may be gone if thread dies at right time.. fixme.. */ @@ -827,44 +827,44 @@ static BOOL HandleStuff(void) BOOL handled = TRUE; if (bsd->hSockReq) { - // 100ms sleepiness might need some tuning... - //if(WaitForSingleObject( hSockReq, 100 ) == WAIT_OBJECT_0 ) + // 100ms sleepiness might need some tuning... + //if(WaitForSingleObject( hSockReq, 100 ) == WAIT_OBJECT_0 ) { switch(sockreq.packet_type) { - case connect_req: - sockreq.sb->resultval = connect(sockreq.s,(struct sockaddr *)(sockreq.params.connect_s.buf),sockreq.params.connect_s.namelen); + case connect_req: + sockreq.sb->resultval = connect(sockreq.s,(struct sockaddr *)(sockreq.params.connect_s.buf),sockreq.params.connect_s.namelen); break; - case sendto_req: - if(sockreq.params.sendto_s.to) { - sockreq.sb->resultval = sendto(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags,(struct sockaddr *)(sockreq.params.sendto_s.buf),sockreq.params.sendto_s.tolen); - } else { - sockreq.sb->resultval = send(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags); - } + case sendto_req: + if(sockreq.params.sendto_s.to) { + sockreq.sb->resultval = sendto(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags,(struct sockaddr *)(sockreq.params.sendto_s.buf),sockreq.params.sendto_s.tolen); + } else { + sockreq.sb->resultval = send(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags); + } break; - case recvfrom_req: - if(sockreq.params.recvfrom_s.addr) { - sockreq.sb->resultval = recvfrom(sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len, - sockreq.params.recvfrom_s.flags, sockreq.params.recvfrom_s.rp_addr, - sockreq.params.recvfrom_s.hlen); + case recvfrom_req: + if(sockreq.params.recvfrom_s.addr) { + sockreq.sb->resultval = recvfrom(sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len, + sockreq.params.recvfrom_s.flags, sockreq.params.recvfrom_s.rp_addr, + sockreq.params.recvfrom_s.hlen); - } else { - sockreq.sb->resultval = recv(sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len, - sockreq.params.recvfrom_s.flags); - } + } else { + sockreq.sb->resultval = recv(sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len, + sockreq.params.recvfrom_s.flags); + } break; - case abort_req: - *(sockreq.params.abort_s.newsock) = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); - if (*(sockreq.params.abort_s.newsock) != sb->sockAbort) { - shutdown(sb->sockAbort, 1); - closesocket(sb->sockAbort); - } - handled = FALSE; /* Don't bother the SETERRNO section after the switch() */ + case abort_req: + *(sockreq.params.abort_s.newsock) = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); + if (*(sockreq.params.abort_s.newsock) != sb->sockAbort) { + shutdown(sb->sockAbort, 1); + closesocket(sb->sockAbort); + } + handled = FALSE; /* Don't bother the SETERRNO section after the switch() */ break; - case last_req: - default: - write_log (L"BSDSOCK: Invalid sock-thread request!\n"); - handled = FALSE; + case last_req: + default: + write_log (L"BSDSOCK: Invalid sock-thread request!\n"); + handled = FALSE; break; } if(handled) { @@ -875,22 +875,22 @@ static BOOL HandleStuff(void) } SetEvent(bsd->hSockReqHandled); } - } else { + } else { quit = TRUE; - } - return quit; + } + return quit; } static LRESULT CALLBACK SocketWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - if(message >= 0xB000 && message < 0xB000 + MAXPENDINGASYNC * 2) { + if(message >= 0xB000 && message < 0xB000 + MAXPENDINGASYNC * 2) { #if DEBUG_SOCKETS write_log ( "sockmsg(0x%x, 0x%x, 0x%x)\n", message, wParam, lParam ); #endif sockmsg(message, wParam, lParam); return 0; - } - return DefWindowProc(hwnd, message, wParam, lParam); + } + return DefWindowProc(hwnd, message, wParam, lParam); } @@ -902,15 +902,15 @@ static unsigned int sock_thread2(void *blah) MSG msg; if(bsd->hSockWnd) { - // Make sure we're outrunning the wolves - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); + // Make sure we're outrunning the wolves + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); while(bsd->hSockThread && bsd->hSockWnd) { DWORD wait; WaitHandle = bsd->hSockReq; wait = MsgWaitForMultipleObjects (1, &WaitHandle, FALSE, INFINITE, QS_POSTMESSAGE); if (wait == WAIT_ABANDONED_0) - break; + break; if (wait == WAIT_OBJECT_0) { if (!bsd->hSockThread || !bsd->hSockWnd) break; @@ -924,7 +924,7 @@ static unsigned int sock_thread2(void *blah) DispatchMessage(&msg); } } - } + } } write_log (L"BSDSOCK: We have exited our sock_thread()\n"); THREADEND(result); @@ -933,29 +933,29 @@ static unsigned int sock_thread2(void *blah) static unsigned int __stdcall sock_thread(void *p) { - __try { - return sock_thread2 (p); - } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { - } - return 0; + __try { + return sock_thread2 (p); + } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { + } + return 0; } void host_connect(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 namelen) { - SOCKET s; - int success = 0; - unsigned int wMsg; - uae_char buf[MAXADDRLEN]; + SOCKET s; + int success = 0; + unsigned int wMsg; + uae_char buf[MAXADDRLEN]; sd++; - BSDTRACE((L"connect(%d,0x%lx,%d) -> ", sd, name, namelen)); + BSDTRACE((L"connect(%d,0x%lx,%d) -> ", sd, name, namelen)); if (!addr_valid (L"host_connect", name, namelen)) return; - s = getsock(sb,(int)sd); + s = getsock(sb,(int)sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (namelen <= MAXADDRLEN) { if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) { if (sb->mtable[sd-1] == 0) { @@ -1009,28 +1009,28 @@ void host_connect(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 na } } else write_log (L"BSDSOCK: WARNING - Excessive namelen (%d) in connect()!\n", namelen); - } - BSDTRACE((L"%d\n",sb->sb_errno)); + } + BSDTRACE((L"%d\n",sb->sb_errno)); } void host_sendto (TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 to, uae_u32 tolen) { - SOCKET s; - uae_char *realpt; - unsigned int wMsg; - uae_char buf[MAXADDRLEN]; - int iCut; + SOCKET s; + uae_char *realpt; + unsigned int wMsg; + uae_char buf[MAXADDRLEN]; + int iCut; #ifdef TRACING_ENABLED - if (to) + if (to) BSDTRACE((L"sendto(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,to,tolen)); - else + else BSDTRACE((L"send(%d,0x%lx,%d,%d) -> ",sd,msg,len,flags)); #endif sd++; - s = getsock(sb,sd); + s = getsock(sb,sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (!addr_valid (L"host_sendto1", msg, 4)) return; realpt = get_real_address (msg); @@ -1170,33 +1170,33 @@ void host_sendto (TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len sb->resultval = -1; #ifdef TRACING_ENABLED - if (sb->resultval == -1) - BSDTRACE((L"failed (%d)\n",sb->sb_errno)); - else - BSDTRACE((L"%d\n",sb->resultval)); + if (sb->resultval == -1) + BSDTRACE((L"failed (%d)\n",sb->sb_errno)); + else + BSDTRACE((L"%d\n",sb->resultval)); #endif } void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 addr, uae_u32 addrlen) { - SOCKET s; - uae_char *realpt; - struct sockaddr *rp_addr = NULL; - int hlen; - unsigned int wMsg; + SOCKET s; + uae_char *realpt; + struct sockaddr *rp_addr = NULL; + int hlen; + unsigned int wMsg; int waitall, waitallgot; #ifdef TRACING_ENABLED - if (addr) + if (addr) BSDTRACE((L"recvfrom(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,addr,get_long (addrlen))); else BSDTRACE((L"recv(%d,0x%lx,%d,0x%lx) -> ",sd,msg,len,flags)); #endif - sd++; - s = getsock(sb,sd); + sd++; + s = getsock(sb,sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (!addr_valid (L"host_recvfrom1", msg, 4)) return; realpt = get_real_address (msg); @@ -1220,17 +1220,17 @@ void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 le PREPARE_THREAD; - sockreq.packet_type = recvfrom_req; - sockreq.s = s; - sockreq.sb = sb; - sockreq.params.recvfrom_s.addr = addr; - sockreq.params.recvfrom_s.flags = flags; - sockreq.params.recvfrom_s.hlen = &hlen; - sockreq.params.recvfrom_s.len = len; - sockreq.params.recvfrom_s.realpt = realpt; - sockreq.params.recvfrom_s.rp_addr = rp_addr; + sockreq.packet_type = recvfrom_req; + sockreq.s = s; + sockreq.sb = sb; + sockreq.params.recvfrom_s.addr = addr; + sockreq.params.recvfrom_s.flags = flags; + sockreq.params.recvfrom_s.hlen = &hlen; + sockreq.params.recvfrom_s.len = len; + sockreq.params.recvfrom_s.realpt = realpt; + sockreq.params.recvfrom_s.rp_addr = rp_addr; - TRIGGER_THREAD; + TRIGGER_THREAD; if (waitall) { if (sb->resultval > 0) { @@ -1287,13 +1287,13 @@ void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 le prepamigaaddr(rp_addr,hlen); put_long (addrlen,hlen); } - } else + } else sb->resultval = -1; #ifdef TRACING_ENABLED - if (sb->resultval == -1) + if (sb->resultval == -1) BSDTRACE((L"failed (%d)\n",sb->sb_errno)); - else + else BSDTRACE((L"%d\n",sb->resultval)); #endif @@ -1301,13 +1301,13 @@ void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 le uae_u32 host_shutdown(SB, uae_u32 sd, uae_u32 how) { - SOCKET s; + SOCKET s; - BSDTRACE((L"shutdown(%d,%d) -> ",sd,how)); - sd++; - s = getsock(sb,sd); + BSDTRACE((L"shutdown(%d,%d) -> ",sd,how)); + sd++; + s = getsock(sb,sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (shutdown(s,how)) { SETERRNO; BSDTRACE((L"failed (%d)\n",sb->sb_errno)); @@ -1315,21 +1315,21 @@ uae_u32 host_shutdown(SB, uae_u32 sd, uae_u32 how) BSDTRACE((L"OK\n")); return 0; } - } + } - return -1; + return -1; } void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 optval, uae_u32 len) { - SOCKET s; - uae_char buf[MAXADDRLEN]; + SOCKET s; + uae_char buf[MAXADDRLEN]; - BSDTRACE((L"setsockopt(%d,%d,0x%lx,0x%lx,%d) -> ",sd,(short)level,optname,optval,len)); - sd++; - s = getsock(sb,sd); + BSDTRACE((L"setsockopt(%d,%d,0x%lx,0x%lx,%d) -> ",sd,(short)level,optname,optval,len)); + sd++; + s = getsock(sb,sd); - if (s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { if (len > sizeof buf) { write_log (L"BSDSOCK: WARNING - Excessive optlen in setsockopt() (%d)\n", len); len = sizeof buf; @@ -1337,7 +1337,7 @@ void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 opt if (level == IPPROTO_IP && optname == 2) { // IP_HDRINCL emulated by icmp.dll sb->resultval = 0; return; - } + } if (level == SOL_SOCKET && optname == SO_LINGER) { ((LINGER *)buf)->l_onoff = get_long (optval); ((LINGER *)buf)->l_linger = get_long (optval + 4); @@ -1385,7 +1385,7 @@ void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 opt SETERRNO; BSDTRACE((L"failed (%d)\n",sb->sb_errno)); - } + } } uae_u32 host_getsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 optval, uae_u32 optlen) @@ -1412,7 +1412,7 @@ uae_u32 host_getsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 write_log (L"BSDSOCK: ERROR - Unknown optlen (%d) in setsockopt(%d,%d)\n", len, level, optname); } -// put_long (optlen,len); // some programs pass the actual length instead of a pointer to the length, so... + // put_long (optlen,len); // some programs pass the actual length instead of a pointer to the length, so... BSDTRACE((L"OK (%d,%d)\n",len,*(long *)buf)); return 0; } else { @@ -1505,52 +1505,52 @@ uae_u32 host_IoctlSocket(TrapContext *context, SB, uae_u32 sd, uae_u32 request, if (s != INVALID_SOCKET) { switch (request) { - case FIOSETOWN: - sb->ownertask = get_long (arg); - success = 0; + case FIOSETOWN: + sb->ownertask = get_long (arg); + success = 0; break; - case FIOGETOWN: - put_long (arg,sb->ownertask); - success = 0; + case FIOGETOWN: + put_long (arg,sb->ownertask); + success = 0; break; - case FIONBIO: - BSDTRACE((L"[FIONBIO] -> ")); - if (get_long (arg)) { - BSDTRACE((L"nonblocking\n")); - sb->ftable[sd-1] &= ~SF_BLOCKING; - } else { - BSDTRACE((L"blocking\n")); - sb->ftable[sd-1] |= SF_BLOCKING; - } - success = 0; - break; - case FIONREAD: - ioctlsocket(s,request,(u_long *)&data); - BSDTRACE((L"[FIONREAD] -> %d\n",data)); - put_long (arg,data); - success = 0; - break; - case FIOASYNC: - if (get_long (arg)) { - sb->ftable[sd-1] |= REP_ALL; - - BSDTRACE((L"[FIOASYNC] -> enabled\n")); - if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd-> hSockWnd, sb->mtable[sd-1], - FD_ACCEPT | FD_CONNECT | FD_OOB | FD_READ | FD_WRITE | FD_CLOSE); - success = 0; - break; - } + case FIONBIO: + BSDTRACE((L"[FIONBIO] -> ")); + if (get_long (arg)) { + BSDTRACE((L"nonblocking\n")); + sb->ftable[sd-1] &= ~SF_BLOCKING; + } else { + BSDTRACE((L"blocking\n")); + sb->ftable[sd-1] |= SF_BLOCKING; + } + success = 0; + break; + case FIONREAD: + ioctlsocket(s,request,(u_long *)&data); + BSDTRACE((L"[FIONREAD] -> %d\n",data)); + put_long (arg,data); + success = 0; + break; + case FIOASYNC: + if (get_long (arg)) { + sb->ftable[sd-1] |= REP_ALL; + + BSDTRACE((L"[FIOASYNC] -> enabled\n")); + if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) { + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd-> hSockWnd, sb->mtable[sd-1], + FD_ACCEPT | FD_CONNECT | FD_OOB | FD_READ | FD_WRITE | FD_CLOSE); + success = 0; + break; } - else - write_log (L"BSDSOCK: WARNING - FIOASYNC disabling unsupported.\n"); + } + else + write_log (L"BSDSOCK: WARNING - FIOASYNC disabling unsupported.\n"); - success = -1; - break; - default: - write_log (L"BSDSOCK: WARNING - Unknown IoctlSocket request: 0x%08lx\n", request); - bsdsocklib_seterrno(sb, 22); // EINVAL - break; + success = -1; + break; + default: + write_log (L"BSDSOCK: WARNING - Unknown IoctlSocket request: 0x%08lx\n", request); + bsdsocklib_seterrno(sb, 22); // EINVAL + break; } } @@ -1559,14 +1559,14 @@ uae_u32 host_IoctlSocket(TrapContext *context, SB, uae_u32 sd, uae_u32 request, int host_CloseSocket(TrapContext *context, SB, int sd) { - unsigned int wMsg; - SOCKET s; + unsigned int wMsg; + SOCKET s; - BSDTRACE((L"CloseSocket(%d) -> ",sd)); + BSDTRACE((L"CloseSocket(%d) -> ",sd)); sd++; - s = getsock(sb,sd); - if (s != INVALID_SOCKET) { + s = getsock(sb,sd); + if (s != INVALID_SOCKET) { if (sb->mtable[sd-1]) { bsd->asyncsb[(sb->mtable[sd-1]-0xb000)/2] = NULL; @@ -1608,11 +1608,11 @@ int host_CloseSocket(TrapContext *context, SB, int sd) } ENDBLOCKING; - } + } - BSDTRACE((L"failed (%d)\n",sb->sb_errno)); + BSDTRACE((L"failed (%d)\n",sb->sb_errno)); - return -1; + return -1; } // For the sake of efficiency, we do not malloc() the fd_sets here. @@ -1703,48 +1703,48 @@ static void fd_zero(uae_u32 fdset, uae_u32 nfds) // This seems to be the only way of implementing a cancelable WinSock2 select() call... sigh. static unsigned int thread_WaitSelect2(void *indexp) { - int index = *((int*)indexp); - unsigned int result = 0, resultval; - long nfds; - uae_u32 readfds, writefds, exceptfds; - uae_u32 timeout; - struct fd_set readsocks, writesocks, exceptsocks; - struct timeval tv; - volatile struct threadargsw *args; + int index = *((int*)indexp); + unsigned int result = 0, resultval; + long nfds; + uae_u32 readfds, writefds, exceptfds; + uae_u32 timeout; + struct fd_set readsocks, writesocks, exceptsocks; + struct timeval tv; + volatile struct threadargsw *args; - SB; + SB; while (bsd->hEvents[index]) { - if (WaitForSingleObject(bsd->hEvents[index], INFINITE) == WAIT_ABANDONED) + if (WaitForSingleObject(bsd->hEvents[index], INFINITE) == WAIT_ABANDONED) break; if (bsd->hEvents[index] == NULL) break; - if ((args = bsd->threadargsw[index]) != NULL) { - sb = args->sb; - nfds = args->nfds; - readfds = args->readfds; - writefds = args->writefds; - exceptfds = args->exceptfds; - timeout = args->timeout; - - // construct descriptor tables - makesocktable(sb, readfds, &readsocks, nfds, sb->sockAbort); - if (writefds) + if ((args = bsd->threadargsw[index]) != NULL) { + sb = args->sb; + nfds = args->nfds; + readfds = args->readfds; + writefds = args->writefds; + exceptfds = args->exceptfds; + timeout = args->timeout; + + // construct descriptor tables + makesocktable(sb, readfds, &readsocks, nfds, sb->sockAbort); + if (writefds) makesocktable(sb, writefds, &writesocks, nfds, INVALID_SOCKET); - if (exceptfds) + if (exceptfds) makesocktable(sb, exceptfds, &exceptsocks, nfds, INVALID_SOCKET); - if (timeout) { - tv.tv_sec = get_long (timeout); - tv.tv_usec = get_long (timeout+4); - BSDTRACE((L"(timeout: %d.%06d) ",tv.tv_sec,tv.tv_usec)); - } + if (timeout) { + tv.tv_sec = get_long (timeout); + tv.tv_usec = get_long (timeout+4); + BSDTRACE((L"(timeout: %d.%06d) ",tv.tv_sec,tv.tv_usec)); + } - BSDTRACE((L"-> ")); + BSDTRACE((L"-> ")); - resultval = select(nfds+1, &readsocks, writefds ? &writesocks : NULL, - exceptfds ? &exceptsocks : NULL, timeout ? &tv : 0); + resultval = select(nfds+1, &readsocks, writefds ? &writesocks : NULL, + exceptfds ? &exceptsocks : NULL, timeout ? &tv : 0); if (bsd->hEvents[index] == NULL) break; sb->resultval = resultval; @@ -1766,7 +1766,7 @@ static unsigned int thread_WaitSelect2(void *indexp) } } } - } + } if (FD_ISSET(sb->sockAbort,&readsocks)) { if (sb->resultval != SOCKET_ERROR) { sb->resultval--; @@ -1774,42 +1774,42 @@ static unsigned int thread_WaitSelect2(void *indexp) } else { sb->needAbort = 0; } - if (sb->resultval == SOCKET_ERROR) { - SETERRNO; - BSDTRACE((L"failed (%d) - ",sb->sb_errno)); - if (readfds) + if (sb->resultval == SOCKET_ERROR) { + SETERRNO; + BSDTRACE((L"failed (%d) - ",sb->sb_errno)); + if (readfds) fd_zero(readfds,nfds); - if (writefds) + if (writefds) fd_zero(writefds,nfds); - if (exceptfds) + if (exceptfds) fd_zero(exceptfds,nfds); - } else { - if (readfds) + } else { + if (readfds) makesockbitfield(sb,readfds,&readsocks,nfds); - if (writefds) + if (writefds) makesockbitfield(sb,writefds,&writesocks,nfds); - if (exceptfds) + if (exceptfds) makesockbitfield(sb,exceptfds,&exceptsocks,nfds); - } + } - SETSIGNAL; + SETSIGNAL; - bsd->threadargsw[index] = NULL; - SetEvent(sb->hEvent); - } - } + bsd->threadargsw[index] = NULL; + SetEvent(sb->hEvent); + } + } write_log (L"BSDSOCK: thread_WaitSelect2 terminated\n"); - THREADEND(result); - return result; + THREADEND(result); + return result; } static unsigned int __stdcall thread_WaitSelect(void *p) { - __try { - return thread_WaitSelect2 (p); - } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { - } - return 0; + __try { + return thread_WaitSelect2 (p); + } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { + } + return 0; } void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u32 exceptfds, uae_u32 timeout, uae_u32 sigmp) @@ -1876,7 +1876,7 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua } if (i >= MAX_SELECT_THREADS) { - for (i = 0; i < MAX_SELECT_THREADS; i++) { + for (i = 0; i < MAX_SELECT_THREADS; i++) { if (!bsd->hThreads[i]) { bsd->hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); bsd->hThreads[i] = THREAD(thread_WaitSelect, &threadindextable[i]); @@ -1892,7 +1892,7 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua SetThreadPriority(bsd->hThreads[i], THREAD_PRIORITY_ABOVE_NORMAL); break; } - } + } } if (i >= MAX_SELECT_THREADS) @@ -1913,12 +1913,12 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua m68k_dreg (regs, 0) = (((uae_u32)1) << sb->signal) | sb->eintrsigs | wssigs; sigs = CallLib (context, get_long (4), -0x13e); // Wait() -/* + /* if ((1<signal) & sigs) { // 2.3.2002/SR Fix for AmiFTP -> Thread is ready, no need to Abort - sb->needAbort = 0; + sb->needAbort = 0; } -*/ + */ if (sb->needAbort) { if ((newsock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET) write_log (L"BSDSOCK: ERROR - Cannot create socket: %d\n", WSAGetLastError()); @@ -1937,20 +1937,20 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua sb->sockAbort = newsock; if(sigmp) { - put_long (sigmp,sigs & wssigs); - - if (sigs & sb->eintrsigs) { - BSDTRACE((L"[interrupted]\n")); - sb->resultval = -1; - bsdsocklib_seterrno(sb,4); // EINTR - } else if (sigs & wssigs) { - BSDTRACE((L"[interrupted by signals 0x%08lx]\n",sigs & wssigs)); + put_long (sigmp,sigs & wssigs); + + if (sigs & sb->eintrsigs) { + BSDTRACE((L"[interrupted]\n")); + sb->resultval = -1; + bsdsocklib_seterrno(sb,4); // EINTR + } else if (sigs & wssigs) { + BSDTRACE((L"[interrupted by signals 0x%08lx]\n",sigs & wssigs)); if (readfds) fd_zero(readfds,nfds); if (writefds) fd_zero(writefds,nfds); if (exceptfds) fd_zero(exceptfds,nfds); - bsdsocklib_seterrno(sb,0); - sb->resultval = 0; - } + bsdsocklib_seterrno(sb,0); + sb->resultval = 0; + } if (sb->resultval >= 0) { BSDTRACE((L"%d\n",sb->resultval)); } else { @@ -2138,27 +2138,27 @@ static unsigned int thread_get2 (void *indexp) } } - BSDTRACE((L"-> ")); + BSDTRACE((L"-> ")); if (bsd->threadGetargs_inuse[index] != -1) SETSIGNAL; - bsd->threadGetargs_inuse[index] = 0; + bsd->threadGetargs_inuse[index] = 0; } - } + } write_log (L"BSDSOCK: thread_get2 terminated\n"); THREADEND(result); - return result; + return result; } static unsigned int __stdcall thread_get(void *p) { - __try { - return thread_get2 (p); - } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { - } - return 0; + __try { + return thread_get2 (p); + } __except(WIN32_ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { + } + return 0; } static volatile struct threadargs *run_get_thread(TrapContext *context, SB, struct threadargs *args) @@ -2174,7 +2174,7 @@ static volatile struct threadargs *run_get_thread(TrapContext *context, SB, stru } if (i >= MAX_GET_THREADS) { - for (i = 0; i < MAX_GET_THREADS; i++) { + for (i = 0; i < MAX_GET_THREADS; i++) { if (bsd->hGetThreads[i] == NULL) { bsd->hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); bsd->hGetThreads[i] = THREAD(thread_get, &threadindextable[i]); @@ -2188,7 +2188,7 @@ static volatile struct threadargs *run_get_thread(TrapContext *context, SB, stru } break; } - } + } } if (i >= MAX_GET_THREADS) { @@ -2228,9 +2228,9 @@ void host_gethostbynameaddr (TrapContext *context, SB, uae_u32 name, uae_u32 nam volatile uae_char *buf; unsigned int wMsg = 0; -// TCHAR on = 1; -// InternetSetOption(0,INTERNET_OPTION_SETTINGS_CHANGED,&on,strlen(&on)); -// Do not use: Causes locks with some machines + // TCHAR on = 1; + // InternetSetOption(0,INTERNET_OPTION_SETTINGS_CHANGED,&on,strlen(&on)); + // Do not use: Causes locks with some machines memset(&args, 0, sizeof (args)); argsp = &args; diff --git a/od-win32/build68k_msvc/build68k_msvc.vcxproj b/od-win32/build68k_msvc/build68k_msvc.vcxproj index ade2421f..2eb2fb87 100644 --- a/od-win32/build68k_msvc/build68k_msvc.vcxproj +++ b/od-win32/build68k_msvc/build68k_msvc.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -19,62 +20,71 @@ build68k - {AF3DBBDE-E006-4DC3-9A26-CB0D7D82AE3C} + {AF3DBBDE-E006-4DC3-9A26-CB0D7D82AE3C} - + Application false - Unicode + MultiByte - + Application false - Unicode + MultiByte - + Application false - MultiByte + Unicode - + Application false - MultiByte + Unicode - - + + + + + + + + + + + - <_ProjectFileVersion>10.0.20506.1 - - + <_ProjectFileVersion>10.0.21006.1 + .\Release\ .\Release\ - build68k - .exe false - - + .\Debug\ .\Debug\ - build68k - .exe true - - + $(Configuration)\ $(Configuration)\ - build68k - .exe false - - + $(Configuration)\ $(Configuration)\ - build68k - .exe false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + @@ -106,6 +116,7 @@ /MACHINE:I386 %(AdditionalOptions) + build68k.exe true .\Release/build68k.pdb Console @@ -148,6 +159,7 @@ /MACHINE:I386 %(AdditionalOptions) + build68k.exe true true .\Debug/build68k.pdb @@ -191,6 +203,7 @@ /MACHINE:I386 %(AdditionalOptions) + build68k.exe true .\Release/build68k.pdb Console @@ -233,6 +246,7 @@ /MACHINE:I386 %(AdditionalOptions) + build68k.exe true .\Release/build68k.pdb Console diff --git a/od-win32/build68k_msvc/build68k_msvc.vcxproj.filters b/od-win32/build68k_msvc/build68k_msvc.vcxproj.filters index 08ccd055..1542feb6 100644 --- a/od-win32/build68k_msvc/build68k_msvc.vcxproj.filters +++ b/od-win32/build68k_msvc/build68k_msvc.vcxproj.filters @@ -2,7 +2,7 @@ - {95d84b91-1707-44ec-a2c7-4c54318c8beb} + {f5d9c253-f595-45f1-ad29-be4ff9a46bc1} cpp;c;cxx;rc;def;r;odl;idl;hpj;bat diff --git a/od-win32/caps/caps_win32.c b/od-win32/caps/caps_win32.c index 008dcf38..e03ea37f 100644 --- a/od-win32/caps/caps_win32.c +++ b/od-win32/caps/caps_win32.c @@ -41,176 +41,176 @@ static CAPSGETVERSIONINFO pCAPSGetVersionInfo; int caps_init (void) { - static int init, noticed; - int i; - HMODULE h; - struct CapsVersionInfo cvi; - TCHAR *dllname = L"CAPSImg.dll"; - - if (init) - return 1; - h = WIN32_LoadLibrary (dllname); - if (!h) { - TCHAR tmp[MAX_DPATH]; - if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, tmp))) { - _tcscat (tmp, L"\\Software Preservation Society\\"); - _tcscat (tmp, dllname); - h = LoadLibrary (tmp); - if (!h) { + static int init, noticed; + int i; + HMODULE h; + struct CapsVersionInfo cvi; + TCHAR *dllname = L"CAPSImg.dll"; + + if (init) + return 1; + h = WIN32_LoadLibrary (dllname); + if (!h) { + TCHAR tmp[MAX_DPATH]; + if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, tmp))) { + _tcscat (tmp, L"\\Software Preservation Society\\"); + _tcscat (tmp, dllname); + h = LoadLibrary (tmp); + if (!h) { + if (noticed) + return 0; + notify_user (NUMSG_NOCAPS); + noticed = 1; + return 0; + } + } + } + if (GetProcAddress (h, "CAPSLockImageMemory") == 0 || GetProcAddress (h, "CAPSGetVersionInfo") == 0) { if (noticed) - return 0; - notify_user (NUMSG_NOCAPS); + return 0; + notify_user (NUMSG_OLDCAPS); noticed = 1; return 0; - } } - } - if (GetProcAddress (h, "CAPSLockImageMemory") == 0 || GetProcAddress (h, "CAPSGetVersionInfo") == 0) { - if (noticed) - return 0; - notify_user (NUMSG_OLDCAPS); - noticed = 1; - return 0; - } - pCAPSInit = (CAPSINIT)GetProcAddress (h, "CAPSInit"); - pCAPSAddImage = (CAPSADDIMAGE)GetProcAddress (h, "CAPSAddImage"); - pCAPSLockImageMemory = (CAPSLOCKIMAGEMEMORY)GetProcAddress (h, "CAPSLockImageMemory"); - pCAPSUnlockImage = (CAPSUNLOCKIMAGE)GetProcAddress (h, "CAPSUnlockImage"); - pCAPSLoadImage = (CAPSLOADIMAGE)GetProcAddress (h, "CAPSLoadImage"); - pCAPSGetImageInfo = (CAPSGETIMAGEINFO)GetProcAddress (h, "CAPSGetImageInfo"); - pCAPSLockTrack = (CAPSLOCKTRACK)GetProcAddress (h, "CAPSLockTrack"); - pCAPSUnlockTrack = (CAPSUNLOCKTRACK)GetProcAddress (h, "CAPSUnlockTrack"); - pCAPSUnlockAllTracks = (CAPSUNLOCKALLTRACKS)GetProcAddress (h, "CAPSUnlockAllTracks"); - pCAPSGetVersionInfo = (CAPSGETVERSIONINFO)GetProcAddress (h, "CAPSGetVersionInfo"); - init = 1; - cvi.type = LIB_TYPE; - pCAPSGetVersionInfo (&cvi, 0); - write_log (L"CAPS: library version %d.%d\n", cvi.release, cvi.revision); - for (i = 0; i < 4; i++) - caps_cont[i] = pCAPSAddImage (); - return 1; + pCAPSInit = (CAPSINIT)GetProcAddress (h, "CAPSInit"); + pCAPSAddImage = (CAPSADDIMAGE)GetProcAddress (h, "CAPSAddImage"); + pCAPSLockImageMemory = (CAPSLOCKIMAGEMEMORY)GetProcAddress (h, "CAPSLockImageMemory"); + pCAPSUnlockImage = (CAPSUNLOCKIMAGE)GetProcAddress (h, "CAPSUnlockImage"); + pCAPSLoadImage = (CAPSLOADIMAGE)GetProcAddress (h, "CAPSLoadImage"); + pCAPSGetImageInfo = (CAPSGETIMAGEINFO)GetProcAddress (h, "CAPSGetImageInfo"); + pCAPSLockTrack = (CAPSLOCKTRACK)GetProcAddress (h, "CAPSLockTrack"); + pCAPSUnlockTrack = (CAPSUNLOCKTRACK)GetProcAddress (h, "CAPSUnlockTrack"); + pCAPSUnlockAllTracks = (CAPSUNLOCKALLTRACKS)GetProcAddress (h, "CAPSUnlockAllTracks"); + pCAPSGetVersionInfo = (CAPSGETVERSIONINFO)GetProcAddress (h, "CAPSGetVersionInfo"); + init = 1; + cvi.type = LIB_TYPE; + pCAPSGetVersionInfo (&cvi, 0); + write_log (L"CAPS: library version %d.%d\n", cvi.release, cvi.revision); + for (i = 0; i < 4; i++) + caps_cont[i] = pCAPSAddImage (); + return 1; } void caps_unloadimage (int drv) { - if (!caps_locked[drv]) - return; - pCAPSUnlockAllTracks (caps_cont[drv]); - pCAPSUnlockImage (caps_cont[drv]); - caps_locked[drv] = 0; + if (!caps_locked[drv]) + return; + pCAPSUnlockAllTracks (caps_cont[drv]); + pCAPSUnlockImage (caps_cont[drv]); + caps_locked[drv] = 0; } int caps_loadimage (struct zfile *zf, int drv, int *num_tracks) { - struct CapsImageInfo ci; - int len, ret; - uae_u8 *buf; - TCHAR s1[100]; - struct CapsDateTimeExt *cdt; - - if (!caps_init ()) - return 0; - caps_unloadimage (drv); - zfile_fseek (zf, 0, SEEK_END); - len = zfile_ftell (zf); - zfile_fseek (zf, 0, SEEK_SET); - buf = xmalloc (len); - if (!buf) - return 0; - if (zfile_fread (buf, len, 1, zf) == 0) - return 0; - ret = pCAPSLockImageMemory (caps_cont[drv], buf, len, 0); - xfree (buf); - if (ret != imgeOk) - return 0; - caps_locked[drv] = 1; - pCAPSGetImageInfo(&ci, caps_cont[drv]); - *num_tracks = (ci.maxcylinder - ci.mincylinder + 1) * (ci.maxhead - ci.minhead + 1); - pCAPSLoadImage(caps_cont[drv], caps_flags); - cdt = &ci.crdt; - _stprintf (s1, L"%d.%d.%d %d:%d:%d", cdt->day, cdt->month, cdt->year, cdt->hour, cdt->min, cdt->sec); - write_log (L"caps: type:%d date:%s rel:%d rev:%d\n", - ci.type, s1, ci.release, ci.revision); - return 1; + struct CapsImageInfo ci; + int len, ret; + uae_u8 *buf; + TCHAR s1[100]; + struct CapsDateTimeExt *cdt; + + if (!caps_init ()) + return 0; + caps_unloadimage (drv); + zfile_fseek (zf, 0, SEEK_END); + len = zfile_ftell (zf); + zfile_fseek (zf, 0, SEEK_SET); + buf = xmalloc (len); + if (!buf) + return 0; + if (zfile_fread (buf, len, 1, zf) == 0) + return 0; + ret = pCAPSLockImageMemory (caps_cont[drv], buf, len, 0); + xfree (buf); + if (ret != imgeOk) + return 0; + caps_locked[drv] = 1; + pCAPSGetImageInfo(&ci, caps_cont[drv]); + *num_tracks = (ci.maxcylinder - ci.mincylinder + 1) * (ci.maxhead - ci.minhead + 1); + pCAPSLoadImage(caps_cont[drv], caps_flags); + cdt = &ci.crdt; + _stprintf (s1, L"%d.%d.%d %d:%d:%d", cdt->day, cdt->month, cdt->year, cdt->hour, cdt->min, cdt->sec); + write_log (L"caps: type:%d date:%s rel:%d rev:%d\n", + ci.type, s1, ci.release, ci.revision); + return 1; } #if 0 static void outdisk (void) { - struct CapsTrackInfo ci; - int tr; - FILE *f; - static int done; - - if (done) - return; - done = 1; - f = fopen("c:\\out3.dat", "wb"); - if (!f) - return; - for (tr = 0; tr < 160; tr++) { - pCAPSLockTrack(&ci, caps_cont[0], tr / 2, tr & 1, caps_flags); - fwrite (ci.trackdata[0], ci.tracksize[0], 1, f); - fwrite ("XXXX", 4, 1, f); - } - fclose (f); + struct CapsTrackInfo ci; + int tr; + FILE *f; + static int done; + + if (done) + return; + done = 1; + f = fopen("c:\\out3.dat", "wb"); + if (!f) + return; + for (tr = 0; tr < 160; tr++) { + pCAPSLockTrack(&ci, caps_cont[0], tr / 2, tr & 1, caps_flags); + fwrite (ci.trackdata[0], ci.tracksize[0], 1, f); + fwrite ("XXXX", 4, 1, f); + } + fclose (f); } #endif int caps_loadrevolution (uae_u16 *mfmbuf, int drv, int track, int *tracklength) { - int len, i; - uae_u16 *mfm; - struct CapsTrackInfoT1 ci; - - ci.type = LIB_TYPE; - pCAPSLockTrack ((PCAPSTRACKINFO)&ci, caps_cont[drv], track / 2, track & 1, caps_flags); - len = ci.tracklen; - *tracklength = len * 8; - mfm = mfmbuf; - for (i = 0; i < (len + 1) / 2; i++) { - uae_u8 *data = ci.trackbuf + i * 2; - *mfm++ = 256 * *data + *(data + 1); - } - return 1; + int len, i; + uae_u16 *mfm; + struct CapsTrackInfoT1 ci; + + ci.type = LIB_TYPE; + pCAPSLockTrack ((PCAPSTRACKINFO)&ci, caps_cont[drv], track / 2, track & 1, caps_flags); + len = ci.tracklen; + *tracklength = len * 8; + mfm = mfmbuf; + for (i = 0; i < (len + 1) / 2; i++) { + uae_u8 *data = ci.trackbuf + i * 2; + *mfm++ = 256 * *data + *(data + 1); + } + return 1; } int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *multirev, int *gapoffset) { - int i, len, type; - uae_u16 *mfm; - struct CapsTrackInfoT1 ci; - - ci.type = LIB_TYPE; - if (tracktiming) - *tracktiming = 0; - pCAPSLockTrack ((PCAPSTRACKINFO)&ci, caps_cont[drv], track / 2, track & 1, caps_flags); - mfm = mfmbuf; - *multirev = (ci.type & CTIT_FLAG_FLAKEY) ? 1 : 0; - type = ci.type & CTIT_MASK_TYPE; - len = ci.tracklen; - *tracklength = len * 8; - *gapoffset = ci.overlap >= 0 ? ci.overlap * 8 : -1; - for (i = 0; i < (len + 1) / 2; i++) { - uae_u8 *data = ci.trackbuf + i * 2; - *mfm++ = 256 * *data + *(data + 1); - } + int i, len, type; + uae_u16 *mfm; + struct CapsTrackInfoT1 ci; + + ci.type = LIB_TYPE; + if (tracktiming) + *tracktiming = 0; + pCAPSLockTrack ((PCAPSTRACKINFO)&ci, caps_cont[drv], track / 2, track & 1, caps_flags); + mfm = mfmbuf; + *multirev = (ci.type & CTIT_FLAG_FLAKEY) ? 1 : 0; + type = ci.type & CTIT_MASK_TYPE; + len = ci.tracklen; + *tracklength = len * 8; + *gapoffset = ci.overlap >= 0 ? ci.overlap * 8 : -1; + for (i = 0; i < (len + 1) / 2; i++) { + uae_u8 *data = ci.trackbuf + i * 2; + *mfm++ = 256 * *data + *(data + 1); + } #if 0 - { - FILE *f=fopen("c:\\1.txt","wb"); - fwrite (ci.trackbuf, len, 1, f); - fclose (f); - } + { + FILE *f=fopen("c:\\1.txt","wb"); + fwrite (ci.trackbuf, len, 1, f); + fclose (f); + } #endif - if (ci.timelen > 0 && tracktiming) { - for (i = 0; i < ci.timelen; i++) - tracktiming[i] = (uae_u16)ci.timebuf[i]; - } + if (ci.timelen > 0 && tracktiming) { + for (i = 0; i < ci.timelen; i++) + tracktiming[i] = (uae_u16)ci.timebuf[i]; + } #if 0 - write_log (L"caps: drive:%d track:%d len:%d multi:%d timing:%d type:%d overlap:%d\n", - drv, track, len, *multirev, ci.timelen, type, ci.overlap); + write_log (L"caps: drive:%d track:%d len:%d multi:%d timing:%d type:%d overlap:%d\n", + drv, track, len, *multirev, ci.timelen, type, ci.overlap); #endif - return 1; + return 1; } #endif diff --git a/od-win32/clipboard_win32.c b/od-win32/clipboard_win32.c index 21130b81..add57689 100644 --- a/od-win32/clipboard_win32.c +++ b/od-win32/clipboard_win32.c @@ -30,877 +30,877 @@ static int clipboard_delayed_size; static void debugwrite (const TCHAR *name, uae_u8 *p, int size) { - FILE *f; - int cnt; - - if (!p || !size) - return; - cnt = 0; - for (;;) { - TCHAR tmp[MAX_DPATH]; - _stprintf (tmp, L"%s.%03d.dat", name, cnt); - f = _tfopen (tmp, L"rb"); - if (f) { - fclose (f); - cnt++; - continue; - } - f = _tfopen (tmp, L"wb"); - if (f) { - fwrite (p, size, 1, f); - fclose (f); + FILE *f; + int cnt; + + if (!p || !size) + return; + cnt = 0; + for (;;) { + TCHAR tmp[MAX_DPATH]; + _stprintf (tmp, L"%s.%03d.dat", name, cnt); + f = _tfopen (tmp, L"rb"); + if (f) { + fclose (f); + cnt++; + continue; + } + f = _tfopen (tmp, L"wb"); + if (f) { + fwrite (p, size, 1, f); + fclose (f); + } + return; } - return; - } } static void to_amiga_start (void) { - if (!initialized) - return; - if (!clipboard_data) - return; - if (clipboard_debug) { - debugwrite (L"clipboard_p2a", to_amiga, to_amiga_size); - } - //write_log (L"clipboard: to_amiga %08x\n", clipboard_data); - put_long (clipboard_data, to_amiga_size); - uae_Signal (get_long (clipboard_data + 8), 1 << 13); + if (!initialized) + return; + if (!clipboard_data) + return; + if (clipboard_debug) { + debugwrite (L"clipboard_p2a", to_amiga, to_amiga_size); + } + //write_log (L"clipboard: to_amiga %08x\n", clipboard_data); + put_long (clipboard_data, to_amiga_size); + uae_Signal (get_long (clipboard_data + 8), 1 << 13); } static uae_char *pctoamiga (const uae_char *txt) { - int len; - uae_char *txt2; - int i, j; - - len = strlen (txt) + 1; - txt2 = xmalloc (len); - j = 0; - for (i = 0; i < len; i++) { - uae_char c = txt[i]; - if (c == 13) - continue; - txt2[j++] = c; - } - return txt2; + int len; + uae_char *txt2; + int i, j; + + len = strlen (txt) + 1; + txt2 = xmalloc (len); + j = 0; + for (i = 0; i < len; i++) { + uae_char c = txt[i]; + if (c == 13) + continue; + txt2[j++] = c; + } + return txt2; } static int parsecsi (const uae_char *txt, int off, int len) { - while (off < len) { - if (txt[off] >= 0x40) - break; - off++; - } - return off; + while (off < len) { + if (txt[off] >= 0x40) + break; + off++; + } + return off; } static TCHAR *amigatopc (const uae_u8 *txt) { - int i, j, cnt; - int len, pc; - char *txt2; - TCHAR *s; - - pc = 0; - cnt = 0; - len = strlen (txt) + 1; - for (i = 0; i < len; i++) { - uae_char c = txt[i]; - if (c == 13) - pc = 1; - if (c == 10) - cnt++; - } - if (pc) - return my_strdup_ansi (txt); - txt2 = xcalloc (len + cnt, 1); - j = 0; - for (i = 0; i < len; i++) { - uae_char c = txt[i]; - if (c == 0 && i + 1 < len) - continue; - if (c == 10) - txt2[j++] = 13; - if (c == 0x9b) { - i = parsecsi (txt, i + 1, len); - continue; - } else if (c == 0x1b && i + 1 < len && txt[i + 1] == '[') { - i = parsecsi (txt, i + 2, len); - continue; + int i, j, cnt; + int len, pc; + char *txt2; + TCHAR *s; + + pc = 0; + cnt = 0; + len = strlen (txt) + 1; + for (i = 0; i < len; i++) { + uae_char c = txt[i]; + if (c == 13) + pc = 1; + if (c == 10) + cnt++; + } + if (pc) + return my_strdup_ansi (txt); + txt2 = xcalloc (len + cnt, 1); + j = 0; + for (i = 0; i < len; i++) { + uae_char c = txt[i]; + if (c == 0 && i + 1 < len) + continue; + if (c == 10) + txt2[j++] = 13; + if (c == 0x9b) { + i = parsecsi (txt, i + 1, len); + continue; + } else if (c == 0x1b && i + 1 < len && txt[i + 1] == '[') { + i = parsecsi (txt, i + 2, len); + continue; + } + txt2[j++] = c; } - txt2[j++] = c; - } - s = my_strdup_ansi (txt2); - xfree (txt2); - return s; + s = my_strdup_ansi (txt2); + xfree (txt2); + return s; } static void to_iff_text (TCHAR *pctxt) { - uae_u8 b[] = { 'F','O','R','M',0,0,0,0,'F','T','X','T','C','H','R','S',0,0,0,0 }; - uae_u32 size; - int txtlen; - uae_char *txt; - char *s; - - s = ua (pctxt); - txt = pctoamiga (s); - txtlen = strlen (s); - xfree (to_amiga); - size = txtlen + sizeof b + (txtlen & 1) - 8; - b[4] = size >> 24; - b[5] = size >> 16; - b[6] = size >> 8; - b[7] = size >> 0; - size = txtlen; - b[16] = size >> 24; - b[17] = size >> 16; - b[18] = size >> 8; - b[19] = size >> 0; - to_amiga_size = sizeof b + txtlen + (txtlen & 1); - to_amiga = xcalloc (to_amiga_size, 1); - memcpy (to_amiga, b, sizeof b); - memcpy (to_amiga + sizeof b, txt, txtlen); - to_amiga_start (); - xfree (txt); - xfree (s); + uae_u8 b[] = { 'F','O','R','M',0,0,0,0,'F','T','X','T','C','H','R','S',0,0,0,0 }; + uae_u32 size; + int txtlen; + uae_char *txt; + char *s; + + s = ua (pctxt); + txt = pctoamiga (s); + txtlen = strlen (s); + xfree (to_amiga); + size = txtlen + sizeof b + (txtlen & 1) - 8; + b[4] = size >> 24; + b[5] = size >> 16; + b[6] = size >> 8; + b[7] = size >> 0; + size = txtlen; + b[16] = size >> 24; + b[17] = size >> 16; + b[18] = size >> 8; + b[19] = size >> 0; + to_amiga_size = sizeof b + txtlen + (txtlen & 1); + to_amiga = xcalloc (to_amiga_size, 1); + memcpy (to_amiga, b, sizeof b); + memcpy (to_amiga + sizeof b, txt, txtlen); + to_amiga_start (); + xfree (txt); + xfree (s); } static int clipboard_put_text (const TCHAR *txt); static void from_iff_text (uaecptr ftxt, uae_u32 len) { - uae_u8 *addr = NULL, *eaddr; - char *txt = NULL; - int txtsize = 0; + uae_u8 *addr = NULL, *eaddr; + char *txt = NULL; + int txtsize = 0; #if 0 - { - FILE *f = fopen("c:\\d\\clipboard_a2p.005.dat", "rb"); - if (f) { - addr = xmalloc (10000); - len = fread (addr, 1, 10000, f); - fclose (f); + { + FILE *f = fopen("c:\\d\\clipboard_a2p.005.dat", "rb"); + if (f) { + addr = xmalloc (10000); + len = fread (addr, 1, 10000, f); + fclose (f); + } } - } #else - addr = get_real_address (ftxt); + addr = get_real_address (ftxt); #endif - eaddr = addr + len; - if (memcmp ("FTXT", addr + 8, 4)) - return; - addr += 12; - while (addr < eaddr) { - uae_u32 csize = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); - if (addr + 8 + csize > eaddr) - break; - if (!memcmp (addr, "CHRS", 4) && csize) { - int prevsize = txtsize; - txtsize += csize; - txt = realloc (txt, txtsize + 1); - memcpy (txt + prevsize, addr + 8, csize); - txt[txtsize] = 0; + eaddr = addr + len; + if (memcmp ("FTXT", addr + 8, 4)) + return; + addr += 12; + while (addr < eaddr) { + uae_u32 csize = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); + if (addr + 8 + csize > eaddr) + break; + if (!memcmp (addr, "CHRS", 4) && csize) { + int prevsize = txtsize; + txtsize += csize; + txt = realloc (txt, txtsize + 1); + memcpy (txt + prevsize, addr + 8, csize); + txt[txtsize] = 0; + } + addr += 8 + csize + (csize & 1); + if (csize >= 1 && addr[-2] == 0x0d && addr[-1] == 0x0a && addr[0] == 0) + addr++; + else if (csize >= 1 && addr[-1] == 0x0d && addr[0] == 0x0a) + addr++; } - addr += 8 + csize + (csize & 1); - if (csize >= 1 && addr[-2] == 0x0d && addr[-1] == 0x0a && addr[0] == 0) - addr++; - else if (csize >= 1 && addr[-1] == 0x0d && addr[0] == 0x0a) - addr++; - } - if (txt == NULL) { - clipboard_put_text (L""); - } else { - TCHAR *pctxt = amigatopc (txt); - clipboard_put_text (pctxt); - xfree (pctxt); - } - xfree (txt); + if (txt == NULL) { + clipboard_put_text (L""); + } else { + TCHAR *pctxt = amigatopc (txt); + clipboard_put_text (pctxt); + xfree (pctxt); + } + xfree (txt); } - + static void to_iff_ilbm (HBITMAP hbmp) { - BITMAP bmp; - int bmpw, w, h, bpp, iffbpp, tsize, size, x, y, i; - int iffsize, bodysize; - uae_u32 colors[256]; - int cnt; - uae_u8 *iff, *p; - uae_u8 iffilbm[] = { - 'F','O','R','M',0,0,0,0,'I','L','B','M', - 'B','M','H','D',0,0,0,20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 'C','A','M','G',0,0,0, 4, 0,0,0,0, - }; - - if (!GetObject(hbmp, sizeof bmp, &bmp)) - return; - w = bmp.bmWidth; - h = bmp.bmHeight; - bpp = bmp.bmBitsPixel; - if (bpp < 8) - return; - bmpw = (w * bpp / 8 + 3) & ~3; - size = bmpw * h; - bmp.bmBits = xmalloc (size); - if (!GetBitmapBits (hbmp, size, bmp.bmBits)) { - xfree (bmp.bmBits); - return; - } - - write_log (L"BMP2IFF: W=%d H=%d bpp=%d\n", w, h, bpp); - - iffbpp = bpp > 8 ? 24 : bpp; - cnt = 0; - for (y = 0; y < h && cnt < 256; y++) { - uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); - for (x = 0; x < w && cnt < 256; x++) { - uae_u32 v = s[x]; - for (i = 0; i < cnt; i++) { - if (colors[i] == v) - break; - } - if (i == 256) - break; - if (i == cnt) - colors[cnt++] = v; - } - } - if (cnt < 256) { - i = cnt; - iffbpp = 0; - while (i > 0) { - i >>= 1; - iffbpp++; + BITMAP bmp; + int bmpw, w, h, bpp, iffbpp, tsize, size, x, y, i; + int iffsize, bodysize; + uae_u32 colors[256]; + int cnt; + uae_u8 *iff, *p; + uae_u8 iffilbm[] = { + 'F','O','R','M',0,0,0,0,'I','L','B','M', + 'B','M','H','D',0,0,0,20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 'C','A','M','G',0,0,0, 4, 0,0,0,0, + }; + + if (!GetObject(hbmp, sizeof bmp, &bmp)) + return; + w = bmp.bmWidth; + h = bmp.bmHeight; + bpp = bmp.bmBitsPixel; + if (bpp < 8) + return; + bmpw = (w * bpp / 8 + 3) & ~3; + size = bmpw * h; + bmp.bmBits = xmalloc (size); + if (!GetBitmapBits (hbmp, size, bmp.bmBits)) { + xfree (bmp.bmBits); + return; } - write_log (L"BMP2IFF: Colors=%d BPP=%d\n", cnt, iffbpp); - } - - bodysize = (((w + 15) & ~15) / 8) * h * iffbpp; - - iffsize = sizeof (iffilbm) + (8 + 256 * 3 + 1) + (4 + 4) + bodysize; - iff = xcalloc (iffsize, 1); - memcpy (iff, iffilbm, sizeof iffilbm); - p = iff + 5 * 4; - // BMHD - p[0] = w >> 8; - p[1] = w; - p[2] = h >> 8; - p[3] = h; - p[8] = iffbpp; - p[14] = 1; - p[15] = 1; - p[16] = w >> 8; - p[17] = w; - p[18] = h >> 8; - p[19] = h; - p = iff + sizeof iffilbm - 4; - // CAMG - if (w > 400) - p[2] |= 0x80; // HIRES - if (h > 300) - p[3] |= 0x04; // LACE - p += 4; - if (iffbpp <= 8) { - int cols = 1 << iffbpp; - int cnt = 0; - memcpy (p, "CMAP", 4); - p[4] = 0; - p[5] = 0; - p[6] = (cols * 3) >> 8; - p[7] = (cols * 3); - p += 8; - for (i = 0; i < cols; i++) { - *p++ = colors[i] >> 16; - *p++ = colors[i] >> 8; - *p++ = colors[i] >> 0; - cnt += 3; + + write_log (L"BMP2IFF: W=%d H=%d bpp=%d\n", w, h, bpp); + + iffbpp = bpp > 8 ? 24 : bpp; + cnt = 0; + for (y = 0; y < h && cnt < 256; y++) { + uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); + for (x = 0; x < w && cnt < 256; x++) { + uae_u32 v = s[x]; + for (i = 0; i < cnt; i++) { + if (colors[i] == v) + break; + } + if (i == 256) + break; + if (i == cnt) + colors[cnt++] = v; + } } - if (cnt & 1) - *p++ = 0; - } - memcpy (p, "BODY", 4); - p[4] = bodysize >> 24; - p[5] = bodysize >> 16; - p[6] = bodysize >> 8; - p[7] = bodysize >> 0; - p += 8; - - if (bpp > 8 && iffbpp <= 8) { - for (y = 0; y < h && i < 256; y++) { - uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); - int b; - for (b = 0; b < iffbpp; b++) { - int mask2 = 1 << b; - for (x = 0; x < w; x++) { - uae_u32 v = s[x]; - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - for (i = 0; i < (1 << iffbpp); i++) { - if (colors[i] == v) - break; - } - if (i & mask2) - p[off] |= mask; + if (cnt < 256) { + i = cnt; + iffbpp = 0; + while (i > 0) { + i >>= 1; + iffbpp++; } - p += ((w + 15) & ~15) / 8; - } + write_log (L"BMP2IFF: Colors=%d BPP=%d\n", cnt, iffbpp); } - } else if (bpp <= 8) { - for (y = 0; y < h; y++) { - uae_u8 *s = (uae_u8*)(((uae_u8*)bmp.bmBits) + y * bmpw); - int b; - for (b = 0; b < 8; b++) { - int mask2 = 1 << b; - for (x = 0; x < w; x++) { - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - uae_u8 v = s[x]; - if (v & mask2) - p[off] |= mask; + + bodysize = (((w + 15) & ~15) / 8) * h * iffbpp; + + iffsize = sizeof (iffilbm) + (8 + 256 * 3 + 1) + (4 + 4) + bodysize; + iff = xcalloc (iffsize, 1); + memcpy (iff, iffilbm, sizeof iffilbm); + p = iff + 5 * 4; + // BMHD + p[0] = w >> 8; + p[1] = w; + p[2] = h >> 8; + p[3] = h; + p[8] = iffbpp; + p[14] = 1; + p[15] = 1; + p[16] = w >> 8; + p[17] = w; + p[18] = h >> 8; + p[19] = h; + p = iff + sizeof iffilbm - 4; + // CAMG + if (w > 400) + p[2] |= 0x80; // HIRES + if (h > 300) + p[3] |= 0x04; // LACE + p += 4; + if (iffbpp <= 8) { + int cols = 1 << iffbpp; + int cnt = 0; + memcpy (p, "CMAP", 4); + p[4] = 0; + p[5] = 0; + p[6] = (cols * 3) >> 8; + p[7] = (cols * 3); + p += 8; + for (i = 0; i < cols; i++) { + *p++ = colors[i] >> 16; + *p++ = colors[i] >> 8; + *p++ = colors[i] >> 0; + cnt += 3; } - p += ((w + 15) & ~15) / 8; - } + if (cnt & 1) + *p++ = 0; } - } else { - for (y = 0; y < h; y++) { - uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); - int b, bb; - for (bb = 0; bb < 3; bb++) { - for (b = 0; b < 8; b++) { - int mask2 = 1 << (((2 - bb) * 8) + b); - for (x = 0; x < w; x++) { - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - uae_u32 v = s[x]; - if (v & mask2) - p[off] |= mask; - } - p += ((w + 15) & ~15) / 8; + memcpy (p, "BODY", 4); + p[4] = bodysize >> 24; + p[5] = bodysize >> 16; + p[6] = bodysize >> 8; + p[7] = bodysize >> 0; + p += 8; + + if (bpp > 8 && iffbpp <= 8) { + for (y = 0; y < h && i < 256; y++) { + uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); + int b; + for (b = 0; b < iffbpp; b++) { + int mask2 = 1 << b; + for (x = 0; x < w; x++) { + uae_u32 v = s[x]; + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + for (i = 0; i < (1 << iffbpp); i++) { + if (colors[i] == v) + break; + } + if (i & mask2) + p[off] |= mask; + } + p += ((w + 15) & ~15) / 8; + } + } + } else if (bpp <= 8) { + for (y = 0; y < h; y++) { + uae_u8 *s = (uae_u8*)(((uae_u8*)bmp.bmBits) + y * bmpw); + int b; + for (b = 0; b < 8; b++) { + int mask2 = 1 << b; + for (x = 0; x < w; x++) { + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + uae_u8 v = s[x]; + if (v & mask2) + p[off] |= mask; + } + p += ((w + 15) & ~15) / 8; + } + } + } else { + for (y = 0; y < h; y++) { + uae_u32 *s = (uae_u32*)(((uae_u8*)bmp.bmBits) + y * bmpw); + int b, bb; + for (bb = 0; bb < 3; bb++) { + for (b = 0; b < 8; b++) { + int mask2 = 1 << (((2 - bb) * 8) + b); + for (x = 0; x < w; x++) { + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + uae_u32 v = s[x]; + if (v & mask2) + p[off] |= mask; + } + p += ((w + 15) & ~15) / 8; + } + } } - } } - } - tsize = p - iff - 8; - p = iff + 4; - p[0] = tsize >> 24; - p[1] = tsize >> 16; - p[2] = tsize >> 8; - p[3] = tsize >> 0; + tsize = p - iff - 8; + p = iff + 4; + p[0] = tsize >> 24; + p[1] = tsize >> 16; + p[2] = tsize >> 8; + p[3] = tsize >> 0; - to_amiga_size = 8 + tsize + (tsize & 1); - to_amiga = iff; + to_amiga_size = 8 + tsize + (tsize & 1); + to_amiga = iff; - to_amiga_start (); + to_amiga_start (); - xfree (bmp.bmBits); + xfree (bmp.bmBits); } static uae_u8 *iff_decomp (uae_u8 *addr, int w, int h, int planes) { - int y, i, w2; - uae_u8 *dst; - - w2 = (w + 15) & ~15; - dst = xmalloc (w2 * h * planes); - for (y = 0; y < h * planes; y++) { - uae_u8 *p = dst + w2 * y; - uae_u8 *end = p + w2; - while (p < end) { - uae_s8 c = *addr++; - if (c >= 0 && c <= 127) { - uae_u8 cnt = c + 1; - for (i = 0; i < cnt && p < end; i++) - *p++= *addr++; - } else if (c <= -1 && c >= -127) { - uae_u8 cnt = -c + 1; - uae_u8 v = *addr++; - for (i = 0; i < cnt && p < end; i++) - *p++= v; - } + int y, i, w2; + uae_u8 *dst; + + w2 = (w + 15) & ~15; + dst = xmalloc (w2 * h * planes); + for (y = 0; y < h * planes; y++) { + uae_u8 *p = dst + w2 * y; + uae_u8 *end = p + w2; + while (p < end) { + uae_s8 c = *addr++; + if (c >= 0 && c <= 127) { + uae_u8 cnt = c + 1; + for (i = 0; i < cnt && p < end; i++) + *p++= *addr++; + } else if (c <= -1 && c >= -127) { + uae_u8 cnt = -c + 1; + uae_u8 v = *addr++; + for (i = 0; i < cnt && p < end; i++) + *p++= v; + } + } } - } - return dst; + return dst; } static int clipboard_put_bmp (HBITMAP hbmp); static void from_iff_ilbm (uaecptr ilbm, uae_u32 len) { - HBITMAP hbm = NULL; - BITMAPINFO *bmih; - uae_u32 size, bmsize, camg; - uae_u8 *addr, *eaddr, *bmptr; - int i; - int w, bmpw, iffw, h, planes, compr, masking; - int bmhd, body; - RGBQUAD rgbx[256]; - - bmih = NULL; - bmhd = 0, body = 0; - bmsize = 0; - bmptr = NULL; - planes = 0; compr = 0; - addr = get_real_address (ilbm); - eaddr = addr + len; - size = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); - if (memcmp ("ILBM", addr + 8, 4)) - return; - camg = 0; - for (i = 0; i < 256; i++) { - rgbx[i].rgbRed = i; - rgbx[i].rgbGreen = i; - rgbx[i].rgbBlue = i; - rgbx[i].rgbReserved = 0; - } - - addr += 12; - for (;;) { - uae_u8 chunk[4], csize; - uae_u8 *paddr, *ceaddr; - - paddr = addr; - memcpy (chunk, addr, 4); - csize = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); - addr += 8; - ceaddr = addr + csize; - if (!memcmp (chunk, "BMHD" ,4)) { - bmhd = 1; - w = (addr[0] << 8) | addr[1]; - h = (addr[2] << 8) | addr[3]; - planes = addr[8]; - masking = addr[9]; - compr = addr[10]; - - } else if (!memcmp (chunk, "CAMG" ,4)) { - camg = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | (addr[3] << 0); - if ((camg & 0xFFFF0000) && !(camg & 0x1000)) - camg = 0; - } else if (!memcmp (chunk, "CMAP" ,4)) { - if (planes <= 8) { - int zero4 = 1; - for (i = 0; i < (1 << planes) && addr < ceaddr; i++, addr += 3) { - rgbx[i].rgbRed = addr[0]; - rgbx[i].rgbGreen = addr[1]; - rgbx[i].rgbBlue = addr[2]; - if ((addr[0] & 0x0f) || (addr[1] & 0x0f) || (addr[2] & 0x0f)) - zero4 = 0; - } - if (zero4) { - for (i = 0; i < (1 << planes); i++) { - rgbx[i].rgbRed |= rgbx[i].rgbRed >> 4; - rgbx[i].rgbGreen |= rgbx[i].rgbGreen >> 4; - rgbx[i].rgbBlue |= rgbx[i].rgbBlue >> 4; - } - } - } - } else if (!memcmp (chunk, "BODY" ,4) && bmhd) { - int x, y; - int ham, ehb, bmpdepth; - uae_u8 *caddr = NULL, *dptr; - body = 1; - - write_log (L"W=%d H=%d planes=%d mask=%d comp=%d CAMG=%08x\n", w, h, planes, masking, compr, camg); - - ham = 0; ehb = 0; - if ((camg & 0x0800) && planes > 4) - ham = planes >= 7 ? 8 : 6; - if (!(camg & (0x0800 | 0x0400 | 0x8000 | 0x0040)) && (camg & 0x0080) && planes == 6) - ehb = 1; - - if (planes <= 8 && !ham) - bmpdepth = 8; - else - bmpdepth = 32; - iffw = (w + 15) & ~15; - bmpw = (w * (bmpdepth / 8) + 3) & ~3; - - bmsize = sizeof (BITMAPINFO); - if (bmpdepth <= 8) - bmsize += (1 << planes) * sizeof (RGBQUAD); - bmih = xcalloc (bmsize, 1); - bmih->bmiHeader.biSize = sizeof (bmih->bmiHeader); - bmih->bmiHeader.biWidth = w; - bmih->bmiHeader.biHeight = -h; - bmih->bmiHeader.biPlanes = 1; - bmih->bmiHeader.biBitCount = bmpdepth; - bmih->bmiHeader.biCompression = BI_RGB; - if (bmpdepth <= 8) { - RGBQUAD *rgb = bmih->bmiColors; - bmih->bmiHeader.biClrImportant = 0; - bmih->bmiHeader.biClrUsed = 1 << (planes + ehb); - for (i = 0; i < (1 << planes); i++) { - rgb->rgbRed = rgbx[i].rgbRed; - rgb->rgbGreen = rgbx[i].rgbGreen; - rgb->rgbBlue = rgbx[i].rgbBlue; - rgb++; - } - if (ehb) { - for (i = 0; i < (1 << planes); i++) { - rgb->rgbRed = rgbx[i].rgbRed >> 1; - rgb->rgbGreen = rgbx[i].rgbGreen >> 1; - rgb->rgbBlue = rgbx[i].rgbBlue >> 1; - rgb++; - } - } - } - bmptr = xcalloc (bmpw * h, 1); - - if (compr) - addr = caddr = iff_decomp (addr, w, h, planes + (masking == 1 ? 1 : 0)); - dptr = bmptr; + HBITMAP hbm = NULL; + BITMAPINFO *bmih; + uae_u32 size, bmsize, camg; + uae_u8 *addr, *eaddr, *bmptr; + int i; + int w, bmpw, iffw, h, planes, compr, masking; + int bmhd, body; + RGBQUAD rgbx[256]; + + bmih = NULL; + bmhd = 0, body = 0; + bmsize = 0; + bmptr = NULL; + planes = 0; compr = 0; + addr = get_real_address (ilbm); + eaddr = addr + len; + size = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); + if (memcmp ("ILBM", addr + 8, 4)) + return; + camg = 0; + for (i = 0; i < 256; i++) { + rgbx[i].rgbRed = i; + rgbx[i].rgbGreen = i; + rgbx[i].rgbBlue = i; + rgbx[i].rgbReserved = 0; + } - if (planes <= 8 && !ham) { - // paletted - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - int b; - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - uae_u8 c = 0; - for (b = 0; b < planes; b++) - c |= (addr[b * iffw / 8 + off] & mask) ? (1 << b) : 0; - dptr[x] = c; - } - dptr += bmpw; - addr += planes * iffw / 8; - if (masking == 1) - addr += iffw / 8; - } - } else if (ham) { - // HAM6/8 -> 32 - for (y = 0; y < h; y++) { - DWORD ham_lastcolor = 0; - for (x = 0; x < w; x++) { - int b; - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - uae_u8 c = 0; - for (b = 0; b < planes; b++) - c |= (addr[b * iffw / 8 + off] & mask) ? (1 << b) : 0; - if (ham > 6) { - DWORD c2 = c & 0x3f; - switch (c >> 6) - { - case 0: ham_lastcolor = *((DWORD*)(&rgbx[c])); break; - case 1: ham_lastcolor &= 0x00FFFF03; ham_lastcolor |= c2 << 2; break; - case 2: ham_lastcolor &= 0x0003FFFF; ham_lastcolor |= c2 << 18; break; - case 3: ham_lastcolor &= 0x00FF03FF; ham_lastcolor |= c2 << 10; break; - } + addr += 12; + for (;;) { + uae_u8 chunk[4], csize; + uae_u8 *paddr, *ceaddr; + + paddr = addr; + memcpy (chunk, addr, 4); + csize = (addr[4] << 24) | (addr[5] << 16) | (addr[6] << 8) | (addr[7] << 0); + addr += 8; + ceaddr = addr + csize; + if (!memcmp (chunk, "BMHD" ,4)) { + bmhd = 1; + w = (addr[0] << 8) | addr[1]; + h = (addr[2] << 8) | addr[3]; + planes = addr[8]; + masking = addr[9]; + compr = addr[10]; + + } else if (!memcmp (chunk, "CAMG" ,4)) { + camg = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | (addr[3] << 0); + if ((camg & 0xFFFF0000) && !(camg & 0x1000)) + camg = 0; + } else if (!memcmp (chunk, "CMAP" ,4)) { + if (planes <= 8) { + int zero4 = 1; + for (i = 0; i < (1 << planes) && addr < ceaddr; i++, addr += 3) { + rgbx[i].rgbRed = addr[0]; + rgbx[i].rgbGreen = addr[1]; + rgbx[i].rgbBlue = addr[2]; + if ((addr[0] & 0x0f) || (addr[1] & 0x0f) || (addr[2] & 0x0f)) + zero4 = 0; + } + if (zero4) { + for (i = 0; i < (1 << planes); i++) { + rgbx[i].rgbRed |= rgbx[i].rgbRed >> 4; + rgbx[i].rgbGreen |= rgbx[i].rgbGreen >> 4; + rgbx[i].rgbBlue |= rgbx[i].rgbBlue >> 4; + } + } + } + } else if (!memcmp (chunk, "BODY" ,4) && bmhd) { + int x, y; + int ham, ehb, bmpdepth; + uae_u8 *caddr = NULL, *dptr; + body = 1; + + write_log (L"W=%d H=%d planes=%d mask=%d comp=%d CAMG=%08x\n", w, h, planes, masking, compr, camg); + + ham = 0; ehb = 0; + if ((camg & 0x0800) && planes > 4) + ham = planes >= 7 ? 8 : 6; + if (!(camg & (0x0800 | 0x0400 | 0x8000 | 0x0040)) && (camg & 0x0080) && planes == 6) + ehb = 1; + + if (planes <= 8 && !ham) + bmpdepth = 8; + else + bmpdepth = 32; + iffw = (w + 15) & ~15; + bmpw = (w * (bmpdepth / 8) + 3) & ~3; + + bmsize = sizeof (BITMAPINFO); + if (bmpdepth <= 8) + bmsize += (1 << planes) * sizeof (RGBQUAD); + bmih = xcalloc (bmsize, 1); + bmih->bmiHeader.biSize = sizeof (bmih->bmiHeader); + bmih->bmiHeader.biWidth = w; + bmih->bmiHeader.biHeight = -h; + bmih->bmiHeader.biPlanes = 1; + bmih->bmiHeader.biBitCount = bmpdepth; + bmih->bmiHeader.biCompression = BI_RGB; + if (bmpdepth <= 8) { + RGBQUAD *rgb = bmih->bmiColors; + bmih->bmiHeader.biClrImportant = 0; + bmih->bmiHeader.biClrUsed = 1 << (planes + ehb); + for (i = 0; i < (1 << planes); i++) { + rgb->rgbRed = rgbx[i].rgbRed; + rgb->rgbGreen = rgbx[i].rgbGreen; + rgb->rgbBlue = rgbx[i].rgbBlue; + rgb++; + } + if (ehb) { + for (i = 0; i < (1 << planes); i++) { + rgb->rgbRed = rgbx[i].rgbRed >> 1; + rgb->rgbGreen = rgbx[i].rgbGreen >> 1; + rgb->rgbBlue = rgbx[i].rgbBlue >> 1; + rgb++; + } + } + } + bmptr = xcalloc (bmpw * h, 1); + + if (compr) + addr = caddr = iff_decomp (addr, w, h, planes + (masking == 1 ? 1 : 0)); + dptr = bmptr; + + if (planes <= 8 && !ham) { + // paletted + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + int b; + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + uae_u8 c = 0; + for (b = 0; b < planes; b++) + c |= (addr[b * iffw / 8 + off] & mask) ? (1 << b) : 0; + dptr[x] = c; + } + dptr += bmpw; + addr += planes * iffw / 8; + if (masking == 1) + addr += iffw / 8; + } + } else if (ham) { + // HAM6/8 -> 32 + for (y = 0; y < h; y++) { + DWORD ham_lastcolor = 0; + for (x = 0; x < w; x++) { + int b; + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + uae_u8 c = 0; + for (b = 0; b < planes; b++) + c |= (addr[b * iffw / 8 + off] & mask) ? (1 << b) : 0; + if (ham > 6) { + DWORD c2 = c & 0x3f; + switch (c >> 6) + { + case 0: ham_lastcolor = *((DWORD*)(&rgbx[c])); break; + case 1: ham_lastcolor &= 0x00FFFF03; ham_lastcolor |= c2 << 2; break; + case 2: ham_lastcolor &= 0x0003FFFF; ham_lastcolor |= c2 << 18; break; + case 3: ham_lastcolor &= 0x00FF03FF; ham_lastcolor |= c2 << 10; break; + } + } else { + uae_u32 c2 = c & 0x0f; + switch (c >> 4) + { + case 0: ham_lastcolor = *((DWORD*)(&rgbx[c])); break; + case 1: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= c2 << 4; break; + case 2: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= c2 << 20; break; + case 3: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= c2 << 12; break; + } + } + *((DWORD*)(&dptr[x * 4])) = ham_lastcolor; + } + dptr += bmpw; + addr += planes * iffw / 8; + if (masking == 1) + addr += iffw / 8; + } } else { - uae_u32 c2 = c & 0x0f; - switch (c >> 4) - { - case 0: ham_lastcolor = *((DWORD*)(&rgbx[c])); break; - case 1: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= c2 << 4; break; - case 2: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= c2 << 20; break; - case 3: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= c2 << 12; break; - } + // 24bit RGB + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + uae_u8 c; + int b; + int off = x / 8; + int mask = 1 << (7 - (x & 7)); + c = 0; + for (b = 0; b < planes / 3; b++) + c |= (addr[((0 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; + dptr[x * 4 + 2] = c; + c = 0; + for (b = 0; b < planes / 3; b++) + c |= (addr[((1 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; + dptr[x * 4 + 1] = c; + c = 0; + for (b = 0; b < planes / 3; b++) + c |= (addr[((2 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; + dptr[x * 4 + 0] = c; + } + dptr += bmpw; + addr += planes * iffw / 8; + if (masking == 1) + addr += iffw / 8; + } } - *((DWORD*)(&dptr[x * 4])) = ham_lastcolor; - } - dptr += bmpw; - addr += planes * iffw / 8; - if (masking == 1) - addr += iffw / 8; - } - } else { - // 24bit RGB - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - uae_u8 c; - int b; - int off = x / 8; - int mask = 1 << (7 - (x & 7)); - c = 0; - for (b = 0; b < planes / 3; b++) - c |= (addr[((0 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; - dptr[x * 4 + 2] = c; - c = 0; - for (b = 0; b < planes / 3; b++) - c |= (addr[((1 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; - dptr[x * 4 + 1] = c; - c = 0; - for (b = 0; b < planes / 3; b++) - c |= (addr[((2 * planes / 3) + b) * iffw / 8 + off] & mask) ? (1 << b) : 0; - dptr[x * 4 + 0] = c; - } - dptr += bmpw; - addr += planes * iffw / 8; - if (masking == 1) - addr += iffw / 8; + if (caddr) + xfree (caddr); } - } - if (caddr) - xfree (caddr); + addr = paddr + csize + (csize & 1) + 8; + if (addr >= eaddr) + break; } - addr = paddr + csize + (csize & 1) + 8; - if (addr >= eaddr) - break; - } - if (body) { - hbm = CreateDIBitmap (hdc, &bmih->bmiHeader, CBM_INIT, bmptr, bmih, DIB_RGB_COLORS); - if (hbm) - clipboard_put_bmp (hbm); - } - xfree (bmih); - xfree (bmptr); + if (body) { + hbm = CreateDIBitmap (hdc, &bmih->bmiHeader, CBM_INIT, bmptr, bmih, DIB_RGB_COLORS); + if (hbm) + clipboard_put_bmp (hbm); + } + xfree (bmih); + xfree (bmptr); } static void from_iff (uaecptr data, uae_u32 len) { - uae_u8 *addr; - - if (len < 18) - return; - if (!valid_address (data, len)) - return; - addr = get_real_address (data); - if (clipboard_debug) - debugwrite (L"clipboard_a2p", addr, len); - if (memcmp ("FORM", addr, 4)) - return; - if (!memcmp ("FTXT", addr + 8, 4)) - from_iff_text (data, len); - if (!memcmp ("ILBM", addr + 8, 4)) - from_iff_ilbm (data, len); + uae_u8 *addr; + + if (len < 18) + return; + if (!valid_address (data, len)) + return; + addr = get_real_address (data); + if (clipboard_debug) + debugwrite (L"clipboard_a2p", addr, len); + if (memcmp ("FORM", addr, 4)) + return; + if (!memcmp ("FTXT", addr + 8, 4)) + from_iff_text (data, len); + if (!memcmp ("ILBM", addr + 8, 4)) + from_iff_ilbm (data, len); } static void clipboard_read (HWND hwnd) { - HGLOBAL hglb; - UINT f; - int text = FALSE, bmp = FALSE; - - clipboard_change = 0; - //write_log (L"clipboard: read windows clipboard\n"); - if (!OpenClipboard (hwnd)) - return; - f = 0; - while (f = EnumClipboardFormats (f)) { - if (f == CF_UNICODETEXT) - text = TRUE; - if (f == CF_BITMAP) - bmp = TRUE; - } - if (text) { - hglb = GetClipboardData (CF_UNICODETEXT); - if (hglb != NULL) { - TCHAR *lptstr = GlobalLock (hglb); - if (lptstr != NULL) { - //write_log (L"clipboard: CF_UNICODETEXT '%s'\n", lptstr); - to_iff_text (lptstr); - GlobalUnlock (hglb); - } + HGLOBAL hglb; + UINT f; + int text = FALSE, bmp = FALSE; + + clipboard_change = 0; + //write_log (L"clipboard: read windows clipboard\n"); + if (!OpenClipboard (hwnd)) + return; + f = 0; + while (f = EnumClipboardFormats (f)) { + if (f == CF_UNICODETEXT) + text = TRUE; + if (f == CF_BITMAP) + bmp = TRUE; } - } else if (bmp) { - HBITMAP hbmp = GetClipboardData (CF_BITMAP); - if (hbmp != NULL) { - //write_log (L"clipboard: CF_BITMAP\n"); - to_iff_ilbm (hbmp); + if (text) { + hglb = GetClipboardData (CF_UNICODETEXT); + if (hglb != NULL) { + TCHAR *lptstr = GlobalLock (hglb); + if (lptstr != NULL) { + //write_log (L"clipboard: CF_UNICODETEXT '%s'\n", lptstr); + to_iff_text (lptstr); + GlobalUnlock (hglb); + } + } + } else if (bmp) { + HBITMAP hbmp = GetClipboardData (CF_BITMAP); + if (hbmp != NULL) { + //write_log (L"clipboard: CF_BITMAP\n"); + to_iff_ilbm (hbmp); + } } - } - CloseClipboard (); + CloseClipboard (); } static void clipboard_free_delayed (void) { - if (clipboard_delayed_data == 0) - return; - if (clipboard_delayed_size < 0) - xfree (clipboard_delayed_data); - else - DeleteObject (clipboard_delayed_data); - clipboard_delayed_data = 0; - clipboard_delayed_size = 0; + if (clipboard_delayed_data == 0) + return; + if (clipboard_delayed_size < 0) + xfree (clipboard_delayed_data); + else + DeleteObject (clipboard_delayed_data); + clipboard_delayed_data = 0; + clipboard_delayed_size = 0; } void clipboard_changed (HWND hwnd) { - //write_log (L"clipboard: windows clipboard changed message\n"); - if (!clipboard_data || !initialized) - return; - if (clipopen) - return; - if (!clipactive) { - clipboard_change = 1; - return; - } - clipboard_read (hwnd); + //write_log (L"clipboard: windows clipboard changed message\n"); + if (!clipboard_data || !initialized) + return; + if (clipopen) + return; + if (!clipactive) { + clipboard_change = 1; + return; + } + clipboard_read (hwnd); } static int clipboard_put_bmp_real (HBITMAP hbmp) { - int ret = FALSE; + int ret = FALSE; - if (!OpenClipboard (chwnd)) + if (!OpenClipboard (chwnd)) + return ret; + clipopen++; + EmptyClipboard (); + SetClipboardData (CF_BITMAP, hbmp); + ret = TRUE; + CloseClipboard (); + clipopen--; + //write_log (L"clipboard: BMP written to windows clipboard\n"); return ret; - clipopen++; - EmptyClipboard (); - SetClipboardData (CF_BITMAP, hbmp); - ret = TRUE; - CloseClipboard (); - clipopen--; - //write_log (L"clipboard: BMP written to windows clipboard\n"); - return ret; } static int clipboard_put_text_real (const TCHAR *txt) { - HGLOBAL hglb; - int ret = FALSE; - - if (!OpenClipboard (chwnd)) + HGLOBAL hglb; + int ret = FALSE; + + if (!OpenClipboard (chwnd)) + return ret; + clipopen++; + EmptyClipboard (); + hglb = GlobalAlloc (GMEM_MOVEABLE, (_tcslen (txt) + 1) * sizeof (TCHAR)); + if (hglb) { + TCHAR *lptstr = GlobalLock (hglb); + _tcscpy (lptstr, txt); + GlobalUnlock (hglb); + SetClipboardData (CF_UNICODETEXT, hglb); + ret = TRUE; + } + CloseClipboard (); + clipopen--; + //write_log (L"clipboard: text written to windows clipboard\n"); return ret; - clipopen++; - EmptyClipboard (); - hglb = GlobalAlloc (GMEM_MOVEABLE, (_tcslen (txt) + 1) * sizeof (TCHAR)); - if (hglb) { - TCHAR *lptstr = GlobalLock (hglb); - _tcscpy (lptstr, txt); - GlobalUnlock (hglb); - SetClipboardData (CF_UNICODETEXT, hglb); - ret = TRUE; - } - CloseClipboard (); - clipopen--; - //write_log (L"clipboard: text written to windows clipboard\n"); - return ret; } static int clipboard_put_text (const TCHAR *txt) { - if (!clipactive) - return clipboard_put_text_real (txt); - clipboard_free_delayed (); - clipboard_delayed_data = my_strdup (txt); - clipboard_delayed_size = -1; - return 1; + if (!clipactive) + return clipboard_put_text_real (txt); + clipboard_free_delayed (); + clipboard_delayed_data = my_strdup (txt); + clipboard_delayed_size = -1; + return 1; } static int clipboard_put_bmp (HBITMAP hbmp) { - if (!clipactive) - return clipboard_put_bmp_real (hbmp); - clipboard_delayed_data = (void*)hbmp; - clipboard_delayed_size = 1; - return 1; + if (!clipactive) + return clipboard_put_bmp_real (hbmp); + clipboard_delayed_data = (void*)hbmp; + clipboard_delayed_size = 1; + return 1; } void amiga_clipboard_die (void) { - signaling = 0; - write_log (L"clipboard not initialized\n"); + signaling = 0; + write_log (L"clipboard not initialized\n"); } void amiga_clipboard_init (void) { - signaling = 0; - write_log (L"clipboard initialized\n"); - initialized = 1; - clipboard_read (chwnd); + signaling = 0; + write_log (L"clipboard initialized\n"); + initialized = 1; + clipboard_read (chwnd); } void amiga_clipboard_task_start (uaecptr data) { - clipboard_data = data; - signaling = 1; - write_log (L"clipboard task init: %08x\n", clipboard_data); + clipboard_data = data; + signaling = 1; + write_log (L"clipboard task init: %08x\n", clipboard_data); } uae_u32 amiga_clipboard_proc_start (void) { - write_log (L"clipboard process init: %08x\n", clipboard_data); - signaling = 1; - return clipboard_data; + write_log (L"clipboard process init: %08x\n", clipboard_data); + signaling = 1; + return clipboard_data; } void amiga_clipboard_got_data (uaecptr data, uae_u32 size, uae_u32 actual) { - uae_u8 *addr; - if (!initialized) { - write_log (L"clipboard: got_data() before initialized!?\n"); - return; - } - addr = get_real_address (data); - //write_log (L"clipboard: <-amiga, %08x, %08x %d %d\n", clipboard_data, data, size, actual); - from_iff (data, actual); + uae_u8 *addr; + if (!initialized) { + write_log (L"clipboard: got_data() before initialized!?\n"); + return; + } + addr = get_real_address (data); + //write_log (L"clipboard: <-amiga, %08x, %08x %d %d\n", clipboard_data, data, size, actual); + from_iff (data, actual); } void amiga_clipboard_want_data (void) { - uae_u32 addr, size; - - addr = get_long (clipboard_data + 4); - size = get_long (clipboard_data); - if (!initialized) { - write_log (L"clipboard: want_data() before initialized!? (%08x %08x %d)\n", clipboard_data, addr, size); - return; - } - if (addr && size) { - uae_u8 *raddr = get_real_address (addr); - memcpy (raddr, to_amiga, size); - } - xfree (to_amiga); - //write_log (L"clipboard: ->amiga, %08x, %08x %d bytes\n", clipboard_data, addr, size); - to_amiga = NULL; - to_amiga_size = 0; + uae_u32 addr, size; + + addr = get_long (clipboard_data + 4); + size = get_long (clipboard_data); + if (!initialized) { + write_log (L"clipboard: want_data() before initialized!? (%08x %08x %d)\n", clipboard_data, addr, size); + return; + } + if (addr && size) { + uae_u8 *raddr = get_real_address (addr); + memcpy (raddr, to_amiga, size); + } + xfree (to_amiga); + //write_log (L"clipboard: ->amiga, %08x, %08x %d bytes\n", clipboard_data, addr, size); + to_amiga = NULL; + to_amiga_size = 0; } void clipboard_active (HWND hwnd, int active) { - clipactive = active; - if (!initialized) - return; - if (clipactive && clipboard_change) { - clipboard_read (hwnd); - } - if (!clipactive && clipboard_delayed_data) { - if (clipboard_delayed_size < 0) { - clipboard_put_text_real (clipboard_delayed_data); - xfree (clipboard_delayed_data); - } else { - clipboard_put_bmp_real ((HBITMAP)clipboard_delayed_data); + clipactive = active; + if (!initialized) + return; + if (clipactive && clipboard_change) { + clipboard_read (hwnd); + } + if (!clipactive && clipboard_delayed_data) { + if (clipboard_delayed_size < 0) { + clipboard_put_text_real (clipboard_delayed_data); + xfree (clipboard_delayed_data); + } else { + clipboard_put_bmp_real ((HBITMAP)clipboard_delayed_data); + } + clipboard_delayed_data = NULL; + clipboard_delayed_size = 0; } - clipboard_delayed_data = NULL; - clipboard_delayed_size = 0; - } } void clipboard_vsync (void) { - uaecptr task; - - if (!signaling || !clipboard_data) - return; - vdelay--; - if (vdelay > 0) - return; - task = get_long (clipboard_data + 8); - if (task && native2amiga_isfree ()) { - uae_Signal (task, 1 << 13); -// write_log (L"clipboard: signal %08x\n", clipboard_data); - } - vdelay = 50; + uaecptr task; + + if (!signaling || !clipboard_data) + return; + vdelay--; + if (vdelay > 0) + return; + task = get_long (clipboard_data + 8); + if (task && native2amiga_isfree ()) { + uae_Signal (task, 1 << 13); + // write_log (L"clipboard: signal %08x\n", clipboard_data); + } + vdelay = 50; } void clipboard_reset (void) { - write_log (L"clipboard: reset (%08x)\n", clipboard_data); - vdelay = 100; - clipboard_free_delayed (); - clipboard_data = 0; - signaling = 0; - initialized = 0; - xfree (to_amiga); - to_amiga = NULL; - to_amiga_size = 0; - ReleaseDC (chwnd, hdc); + write_log (L"clipboard: reset (%08x)\n", clipboard_data); + vdelay = 100; + clipboard_free_delayed (); + clipboard_data = 0; + signaling = 0; + initialized = 0; + xfree (to_amiga); + to_amiga = NULL; + to_amiga_size = 0; + ReleaseDC (chwnd, hdc); } void clipboard_init (HWND hwnd) { - chwnd = hwnd; - hdc = GetDC (chwnd); + chwnd = hwnd; + hdc = GetDC (chwnd); } diff --git a/od-win32/debug_win32.c b/od-win32/debug_win32.c index f787e0e0..036370f5 100644 --- a/od-win32/debug_win32.c +++ b/od-win32/debug_win32.c @@ -1,10 +1,10 @@ - /* - * WinUAE GUI debugger - * - * Copyright 2008 Karsten Bock - * Copyright 2007 Toni Wilen - * - */ +/* +* WinUAE GUI debugger +* +* Copyright 2008 Karsten Bock +* Copyright 2007 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -59,7 +59,7 @@ static WORD* dlgtmpl; static int reopen; struct histnode { - TCHAR *command; + TCHAR *command; struct histnode *prev; struct histnode *next; }; @@ -68,13 +68,13 @@ static struct histnode *firsthist, *lasthist, *currhist; static int histcount; struct debuggerpage { - HWND ctrl[MAXPAGECONTROLS]; - uae_u32 memaddr; - uae_u32 dasmaddr; - TCHAR addrinput[9]; - int selection; - int init; - int autoset; + HWND ctrl[MAXPAGECONTROLS]; + uae_u32 memaddr; + uae_u32 dasmaddr; + TCHAR addrinput[9]; + int selection; + int init; + int autoset; }; static struct debuggerpage dbgpage[MAXPAGES]; static int currpage, pages; @@ -92,691 +92,691 @@ static const TCHAR *markinstr[] = { L"JMP", L"BT L", L"RTS", L"RTD", L"RTE", L"R static const TCHAR *ucbranch[] = { L"BSR", L"JMP", L"JSR", 0 }; static const TCHAR *cbranch[] = { L"B", L"DB", L"FB", L"FDB", 0 }; static const TCHAR *ccode[] = { L"T ", L"F ", L"HI", L"LS", L"CC", L"CS", L"NE", L"EQ", - L"VC", L"VS", L"PL", L"MI", L"GE", L"LT", L"GT", L"LE", 0 }; + L"VC", L"VS", L"PL", L"MI", L"GE", L"LT", L"GT", L"LE", 0 }; static void OutputCurrHistNode(HWND hWnd) { - int txtlen; - TCHAR *buf; - - if (currhist->command) { - txtlen = GetWindowTextLength(hWnd); - buf = xmalloc((txtlen + 1) * sizeof (TCHAR)); - GetWindowText(hWnd, buf, txtlen + 1); - if (_tcscmp(buf, currhist->command)) { - SetWindowText(hWnd, currhist->command); - txtlen = _tcslen(currhist->command); - SendMessage(hWnd, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); - SendMessage(hWnd, EM_SETSEL, -1, -1); - } - } + int txtlen; + TCHAR *buf; + + if (currhist->command) { + txtlen = GetWindowTextLength(hWnd); + buf = xmalloc((txtlen + 1) * sizeof (TCHAR)); + GetWindowText(hWnd, buf, txtlen + 1); + if (_tcscmp(buf, currhist->command)) { + SetWindowText(hWnd, currhist->command); + txtlen = _tcslen(currhist->command); + SendMessage(hWnd, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); + SendMessage(hWnd, EM_SETSEL, -1, -1); + } + } } static void SetPrevHistNode(HWND hWnd) { - if (currhist) { - if (currhist->prev) - currhist = currhist->prev; - OutputCurrHistNode(hWnd); - - } - else if (lasthist) { - currhist = lasthist; - OutputCurrHistNode(hWnd); - } + if (currhist) { + if (currhist->prev) + currhist = currhist->prev; + OutputCurrHistNode(hWnd); + + } + else if (lasthist) { + currhist = lasthist; + OutputCurrHistNode(hWnd); + } } static void SetNextHistNode(HWND hWnd) { - if (currhist) { - if (currhist->next) - currhist = currhist->next; - OutputCurrHistNode(hWnd); - } + if (currhist) { + if (currhist->next) + currhist = currhist->next; + OutputCurrHistNode(hWnd); + } } static void DeleteFromHistory(int count) { - int i; - struct histnode *tmp; - - for (i = 0; i < count && histcount; i++) { - tmp = firsthist; - firsthist = firsthist->next; - if (currhist == tmp) - currhist = NULL; - if (lasthist == tmp) - lasthist = NULL; - if (firsthist) - firsthist->prev = NULL; - free(tmp->command); - free(tmp); - histcount--; - } + int i; + struct histnode *tmp; + + for (i = 0; i < count && histcount; i++) { + tmp = firsthist; + firsthist = firsthist->next; + if (currhist == tmp) + currhist = NULL; + if (lasthist == tmp) + lasthist = NULL; + if (firsthist) + firsthist->prev = NULL; + free(tmp->command); + free(tmp); + histcount--; + } } static void AddToHistory(const TCHAR *command) { - struct histnode *tmp; - - currhist = NULL; - if (histcount > 0 && !_tcscmp(command, lasthist->command)) - return; - else if (histcount == MAXINPUTHIST) - DeleteFromHistory(1); - tmp = lasthist; - lasthist = malloc(sizeof(struct histnode)); - if (histcount == 0) - firsthist = lasthist; - lasthist->command = my_strdup(command); - lasthist->next = NULL; - lasthist->prev = tmp; - if (tmp) - tmp->next = lasthist; - histcount++; + struct histnode *tmp; + + currhist = NULL; + if (histcount > 0 && !_tcscmp(command, lasthist->command)) + return; + else if (histcount == MAXINPUTHIST) + DeleteFromHistory(1); + tmp = lasthist; + lasthist = malloc(sizeof(struct histnode)); + if (histcount == 0) + firsthist = lasthist; + lasthist->command = my_strdup(command); + lasthist->next = NULL; + lasthist->prev = tmp; + if (tmp) + tmp->next = lasthist; + histcount++; } int GetInput (TCHAR *out, int maxlen) { - HWND hInput; - int chars; + HWND hInput; + int chars; - if (!hDbgWnd) - return 0; - hInput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); - chars = GetWindowText(hInput, out, maxlen); - if (chars == 0) - return 0; - WriteOutput(linebreak + 1, 2); - WriteOutput(out, _tcslen(out)); - WriteOutput(linebreak + 1, 2); - AddToHistory(out); - SetWindowText(hInput, L""); - return chars; + if (!hDbgWnd) + return 0; + hInput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); + chars = GetWindowText(hInput, out, maxlen); + if (chars == 0) + return 0; + WriteOutput(linebreak + 1, 2); + WriteOutput(out, _tcslen(out)); + WriteOutput(linebreak + 1, 2); + AddToHistory(out); + SetWindowText(hInput, L""); + return chars; } static int CheckLineLimit(HWND hWnd, const TCHAR *out) { - TCHAR *tmp, *p; - int lines_have, lines_new = 0, lastchr, txtlen, visible; - - tmp = (TCHAR *)out; - lines_have = SendMessage(hWnd, EM_GETLINECOUNT, 0, 0); - while (_tcslen(tmp) > 0 && (p = _tcschr(tmp, '\n')) > 0) { + TCHAR *tmp, *p; + int lines_have, lines_new = 0, lastchr, txtlen, visible; + + tmp = (TCHAR *)out; + lines_have = SendMessage(hWnd, EM_GETLINECOUNT, 0, 0); + while (_tcslen(tmp) > 0 && (p = _tcschr(tmp, '\n')) > 0) { + lines_new++; + tmp = p + 1; + } lines_new++; - tmp = p + 1; - } - lines_new++; - if (lines_new > MAXLINES) - return 0; - if (lines_have + lines_new > MAXLINES) { - visible = IsWindowVisible(hWnd); - if (visible) - SendMessage(hWnd, WM_SETREDRAW, FALSE, 0); - lastchr = SendMessage(hWnd, EM_LINEINDEX, lines_have + lines_new - MAXLINES, 0); - SendMessage(hWnd, EM_SETSEL, 0, lastchr); - SendMessage(hWnd, EM_REPLACESEL, FALSE, (LPARAM)""); - txtlen = GetWindowTextLength(hWnd); - SendMessage(hWnd, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); - SendMessage(hWnd, EM_SETSEL, -1, -1); - if (visible) - SendMessage(hWnd, WM_SETREDRAW, TRUE, 0); - } - return 1; + if (lines_new > MAXLINES) + return 0; + if (lines_have + lines_new > MAXLINES) { + visible = IsWindowVisible(hWnd); + if (visible) + SendMessage(hWnd, WM_SETREDRAW, FALSE, 0); + lastchr = SendMessage(hWnd, EM_LINEINDEX, lines_have + lines_new - MAXLINES, 0); + SendMessage(hWnd, EM_SETSEL, 0, lastchr); + SendMessage(hWnd, EM_REPLACESEL, FALSE, (LPARAM)""); + txtlen = GetWindowTextLength(hWnd); + SendMessage(hWnd, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); + SendMessage(hWnd, EM_SETSEL, -1, -1); + if (visible) + SendMessage(hWnd, WM_SETREDRAW, TRUE, 0); + } + return 1; } void WriteOutput(const TCHAR *out, int len) { - int txtlen, pos = 0, count, index, leave = 0; - TCHAR *buf = 0, *p, *tmp; - - if (!hOutput || !_tcscmp(out, L">") || len == 0) - return; - if (!CheckLineLimit(hOutput, out)) - return; - tmp = (TCHAR *)out; - for(;;) { - p = _tcschr(tmp, '\n'); - if (p) { - pos = p - tmp + 1; - if (pos > (MAX_LINEWIDTH + 1)) - pos = MAX_LINEWIDTH + 1; - buf = xcalloc(pos + 2, sizeof (TCHAR)); - _tcsncpy(buf, tmp, pos - 1); - _tcscat(buf, linebreak); - } else if (_tcslen(tmp) == 0) { - leave = 1; - } else { - count = SendMessage(hOutput, EM_GETLINECOUNT, 0, 0); - index = SendMessage(hOutput, EM_LINEINDEX, count - 1, 0); - txtlen = SendMessage(hOutput, EM_LINELENGTH, index, 0); - if (_tcslen(tmp) + txtlen > MAX_LINEWIDTH) { - buf = xcalloc(MAX_LINEWIDTH + 3 - txtlen, sizeof (TCHAR)); - _tcsncpy(buf, tmp, MAX_LINEWIDTH - txtlen); - _tcscat(buf, linebreak); - } - leave = 1; - } - txtlen = GetWindowTextLength(hOutput); - SendMessage(hOutput, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); - SendMessage(hOutput, EM_REPLACESEL, FALSE, (LPARAM)(buf ? buf : tmp)); - if (buf) { - xfree(buf); - buf = 0; - tmp += pos; - } - if (leave) - return; - } + int txtlen, pos = 0, count, index, leave = 0; + TCHAR *buf = 0, *p, *tmp; + + if (!hOutput || !_tcscmp(out, L">") || len == 0) + return; + if (!CheckLineLimit(hOutput, out)) + return; + tmp = (TCHAR *)out; + for(;;) { + p = _tcschr(tmp, '\n'); + if (p) { + pos = p - tmp + 1; + if (pos > (MAX_LINEWIDTH + 1)) + pos = MAX_LINEWIDTH + 1; + buf = xcalloc(pos + 2, sizeof (TCHAR)); + _tcsncpy(buf, tmp, pos - 1); + _tcscat(buf, linebreak); + } else if (_tcslen(tmp) == 0) { + leave = 1; + } else { + count = SendMessage(hOutput, EM_GETLINECOUNT, 0, 0); + index = SendMessage(hOutput, EM_LINEINDEX, count - 1, 0); + txtlen = SendMessage(hOutput, EM_LINELENGTH, index, 0); + if (_tcslen(tmp) + txtlen > MAX_LINEWIDTH) { + buf = xcalloc(MAX_LINEWIDTH + 3 - txtlen, sizeof (TCHAR)); + _tcsncpy(buf, tmp, MAX_LINEWIDTH - txtlen); + _tcscat(buf, linebreak); + } + leave = 1; + } + txtlen = GetWindowTextLength(hOutput); + SendMessage(hOutput, EM_SETSEL, (WPARAM)txtlen, (LPARAM)txtlen); + SendMessage(hOutput, EM_REPLACESEL, FALSE, (LPARAM)(buf ? buf : tmp)); + if (buf) { + xfree(buf); + buf = 0; + tmp += pos; + } + if (leave) + return; + } } static HWND ulbs_hwnd; static int ulbs_pos; static void UpdateListboxString(HWND hWnd, int pos, TCHAR *out, int mark) { - int count; - TCHAR text[MAX_LINEWIDTH + 1], *p; - COLORREF cr; - - if (!IsWindowEnabled(hWnd)) { - p = _tcschr(out, ':'); + int count; + TCHAR text[MAX_LINEWIDTH + 1], *p; + COLORREF cr; + + if (!IsWindowEnabled(hWnd)) { + p = _tcschr(out, ':'); + if (p) + *(p + 1) = '\0'; + } + if (_tcslen(out) > MAX_LINEWIDTH) + out[MAX_LINEWIDTH] = '\0'; + p = _tcschr(out, '\n'); if (p) - *(p + 1) = '\0'; - } - if (_tcslen(out) > MAX_LINEWIDTH) - out[MAX_LINEWIDTH] = '\0'; - p = _tcschr(out, '\n'); - if (p) - *p = '\0'; - cr = GetSysColor(COLOR_WINDOWTEXT); - count = SendMessage(hWnd, (UINT) LB_GETCOUNT, 0, 0); - if (pos < count) { - memset(text, 0, MAX_LINEWIDTH + 1); - SendMessage(hWnd, LB_GETTEXT, pos, (LPARAM)((LPTSTR)text)); - if (_tcscmp(out, text) != 0 && mark) - cr = GetSysColor(COLOR_HIGHLIGHT); - SendMessage(hWnd, LB_DELETESTRING, pos, 0); - } - SendMessage(hWnd, LB_INSERTSTRING, pos, (LPARAM)out); - SendMessage(hWnd, LB_SETITEMDATA, pos, cr); + *p = '\0'; + cr = GetSysColor(COLOR_WINDOWTEXT); + count = SendMessage(hWnd, (UINT) LB_GETCOUNT, 0, 0); + if (pos < count) { + memset(text, 0, MAX_LINEWIDTH + 1); + SendMessage(hWnd, LB_GETTEXT, pos, (LPARAM)((LPTSTR)text)); + if (_tcscmp(out, text) != 0 && mark) + cr = GetSysColor(COLOR_HIGHLIGHT); + SendMessage(hWnd, LB_DELETESTRING, pos, 0); + } + SendMessage(hWnd, LB_INSERTSTRING, pos, (LPARAM)out); + SendMessage(hWnd, LB_SETITEMDATA, pos, cr); } static void ULBSINIT(HWND hwnd) { - ulbs_hwnd = hwnd; - ulbs_pos = 0; + ulbs_hwnd = hwnd; + ulbs_pos = 0; } static void ULBS(const TCHAR *format, ...) { - TCHAR buffer[MAX_LINEWIDTH + 1]; - va_list parms; - va_start(parms, format); - _vsntprintf(buffer, MAX_LINEWIDTH, format, parms); - UpdateListboxString(ulbs_hwnd, ulbs_pos++, buffer, FALSE); + TCHAR buffer[MAX_LINEWIDTH + 1]; + va_list parms; + va_start(parms, format); + _vsntprintf(buffer, MAX_LINEWIDTH, format, parms); + UpdateListboxString(ulbs_hwnd, ulbs_pos++, buffer, FALSE); } static void ULBST(const TCHAR *format, ...) { - TCHAR buffer[MAX_LINEWIDTH + 1]; - va_list parms; - va_start(parms, format); - _vsntprintf(buffer, MAX_LINEWIDTH, format, parms); - UpdateListboxString(ulbs_hwnd, ulbs_pos++, buffer, TRUE); + TCHAR buffer[MAX_LINEWIDTH + 1]; + va_list parms; + va_start(parms, format); + _vsntprintf(buffer, MAX_LINEWIDTH, format, parms); + UpdateListboxString(ulbs_hwnd, ulbs_pos++, buffer, TRUE); } static int GetLBOutputLines(HWND hWnd) { - int lines = 0, clientsize, itemsize; - RECT rc; - - GetClientRect(hWnd, &rc); - clientsize = rc.bottom - rc.top; - itemsize = SendMessage(hWnd, LB_GETITEMHEIGHT, 0, 0); - while (clientsize > itemsize) { - lines ++; - clientsize -= itemsize; - } - return lines; + int lines = 0, clientsize, itemsize; + RECT rc; + + GetClientRect(hWnd, &rc); + clientsize = rc.bottom - rc.top; + itemsize = SendMessage(hWnd, LB_GETITEMHEIGHT, 0, 0); + while (clientsize > itemsize) { + lines ++; + clientsize -= itemsize; + } + return lines; } static void ShowMiscCPU(HWND hwnd) { - int line = 0; - TCHAR out[MAX_LINEWIDTH + 1]; - int i; - - for (i = 0; m2cregs[i].regno>= 0; i++) { - if (!movec_illg(m2cregs[i].regno)) { - _stprintf(out, L"%-4s %08X", m2cregs[i].regname, val_move2c(m2cregs[i].regno)); - UpdateListboxString(hwnd, line++, out, TRUE); + int line = 0; + TCHAR out[MAX_LINEWIDTH + 1]; + int i; + + for (i = 0; m2cregs[i].regno>= 0; i++) { + if (!movec_illg(m2cregs[i].regno)) { + _stprintf(out, L"%-4s %08X", m2cregs[i].regname, val_move2c(m2cregs[i].regno)); + UpdateListboxString(hwnd, line++, out, TRUE); + } } - } } static int dcustom[] = { - 0x02, 0x9a, 0x9c, 0x8080, 0x8084, 0x8e, 0x90, 0x92, 0x94, - 0x100, 0x102, 0x104, 0x106, 0x10c, 0 + 0x02, 0x9a, 0x9c, 0x8080, 0x8084, 0x8e, 0x90, 0x92, 0x94, + 0x100, 0x102, 0x104, 0x106, 0x10c, 0 }; static uae_u32 gw(uae_u8 *p, int off) { - return (p[off] << 8) | p[off + 1]; + return (p[off] << 8) | p[off + 1]; } static void ShowCustomSmall(HWND hwnd) { - int len, i, j, cnt; - uae_u8 *p1, *p2, *p3, *p4; - TCHAR out[MAX_LINEWIDTH + 1]; - - p1 = p2 = save_custom (&len, 0, 1); - p1 += 4; // skip chipset type - for (i = 0; i < 4; i++) { - p4 = p1 + 0xa0 + i * 16; - p3 = save_audio (i, &len, 0); - p4[0] = p3[12]; - p4[1] = p3[13]; - p4[2] = p3[14]; - p4[3] = p3[15]; - p4[4] = p3[4]; - p4[5] = p3[5]; - p4[6] = p3[8]; - p4[7] = p3[9]; - p4[8] = 0; - p4[9] = p3[1]; - p4[10] = p3[10]; - p4[11] = p3[11]; - free (p3); - } - ULBSINIT(hwnd); - cnt = 0; - _stprintf(out, L"CPU %d", currprefs.cpu_model); - if (currprefs.fpu_model) - _stprintf (out + _tcslen(out), L"/%d", currprefs.fpu_model); - _stprintf(out + _tcslen(out), L" %s", (currprefs.chipset_mask & CSMASK_AGA) ? L"AGA" : ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? L"ECS" : L"OCS")); - ULBST(out); - ULBST(L"VPOS %04X (%d)", vpos, vpos); - ULBST(L"HPOS %04X (%d)", current_hpos(), current_hpos()); - for (i = 0; dcustom[i]; i++) { - for (j = 0; custd[j].name; j++) { - if (custd[j].adr == (dcustom[i] & 0x1fe) + 0xdff000) { - if (dcustom[i] & 0x8000) - ULBST(L"%-8s %08X", custd[j].name, (gw(p1, dcustom[i] & 0x1fe) << 16) | gw(p1, (dcustom[i] & 0x1fe) + 2)); - else - ULBST(L"%-8s %04X", custd[j].name, gw(p1, dcustom[i] & 0x1fe)); - break; - } + int len, i, j, cnt; + uae_u8 *p1, *p2, *p3, *p4; + TCHAR out[MAX_LINEWIDTH + 1]; + + p1 = p2 = save_custom (&len, 0, 1); + p1 += 4; // skip chipset type + for (i = 0; i < 4; i++) { + p4 = p1 + 0xa0 + i * 16; + p3 = save_audio (i, &len, 0); + p4[0] = p3[12]; + p4[1] = p3[13]; + p4[2] = p3[14]; + p4[3] = p3[15]; + p4[4] = p3[4]; + p4[5] = p3[5]; + p4[6] = p3[8]; + p4[7] = p3[9]; + p4[8] = 0; + p4[9] = p3[1]; + p4[10] = p3[10]; + p4[11] = p3[11]; + free (p3); + } + ULBSINIT(hwnd); + cnt = 0; + _stprintf(out, L"CPU %d", currprefs.cpu_model); + if (currprefs.fpu_model) + _stprintf (out + _tcslen(out), L"/%d", currprefs.fpu_model); + _stprintf(out + _tcslen(out), L" %s", (currprefs.chipset_mask & CSMASK_AGA) ? L"AGA" : ((currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? L"ECS" : L"OCS")); + ULBST(out); + ULBST(L"VPOS %04X (%d)", vpos, vpos); + ULBST(L"HPOS %04X (%d)", current_hpos(), current_hpos()); + for (i = 0; dcustom[i]; i++) { + for (j = 0; custd[j].name; j++) { + if (custd[j].adr == (dcustom[i] & 0x1fe) + 0xdff000) { + if (dcustom[i] & 0x8000) + ULBST(L"%-8s %08X", custd[j].name, (gw(p1, dcustom[i] & 0x1fe) << 16) | gw(p1, (dcustom[i] & 0x1fe) + 2)); + else + ULBST(L"%-8s %04X", custd[j].name, gw(p1, dcustom[i] & 0x1fe)); + break; + } + } } - } - free (p2); + free (p2); } static void ShowMisc(void) { - int line = 0; - HWND hMisc; - int len, i; - uae_u8 *p, *p2; - - hMisc = GetDlgItem(hDbgWnd, IDC_DBG_MISC); - ULBSINIT(hMisc); - for (i = 0; i < 2; i++) { - p = p2 = save_cia (i, &len, NULL); - ULBS(L""); - ULBS(L"CIA %c:", i == 1 ? 'B' : 'A'); + int line = 0; + HWND hMisc; + int len, i; + uae_u8 *p, *p2; + + hMisc = GetDlgItem(hDbgWnd, IDC_DBG_MISC); + ULBSINIT(hMisc); + for (i = 0; i < 2; i++) { + p = p2 = save_cia (i, &len, NULL); + ULBS(L""); + ULBS(L"CIA %c:", i == 1 ? 'B' : 'A'); + ULBS(L""); + ULBS(L"PRA %02X PRB %02X", p[0], p[1]); + ULBS(L"DRA %02X DRB %02X", p[2], p[3]); + ULBS(L"CRA %02X CRB %02X ICR %02X IM %02X", + p[14], p[15], p[13], p[16]); + ULBS(L"TA %04X (%04X) TB %04X (%04X)", + (p[5] << 8) | p[4], (p[18] << 8) | p[17], + (p[7] << 8) | p[6], (p[20] << 8) | p[19]); + ULBS(L"TOD %06X (%06X) ALARM %06X %c%c", + (p[10] << 16) | (p[ 9] << 8) | p[ 8], + (p[23] << 16) | (p[22] << 8) | p[21], + (p[26] << 16) | (p[25] << 8) | p[24], + (p[27] & 1) ? 'L' : ' ', (p[27] & 2) ? ' ' : 'S'); + free(p2); + } + for (i = 0; i < 4; i++) { + p = p2 = save_disk (i, &len, NULL); + ULBS(L""); + ULBS(L"Drive DF%d: (%s)", i, (p[4] & 2) ? "disabled" : "enabled"); + ULBS(L"ID %08X Motor %s Cylinder %2d MFMPOS %d", + (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3], + (p[4] & 1) ? L"On" : L"Off", + p[5], (p[8] << 24) | (p[9] << 16) | (p[10] << 8) | p[11]); + if (p[16]) + ULBS(L"'%s'", p + 16); + else + ULBS(L"Drive is empty"); + free(p2); + } + p = p2 = save_floppy (&len, NULL); ULBS(L""); - ULBS(L"PRA %02X PRB %02X", p[0], p[1]); - ULBS(L"DRA %02X DRB %02X", p[2], p[3]); - ULBS(L"CRA %02X CRB %02X ICR %02X IM %02X", - p[14], p[15], p[13], p[16]); - ULBS(L"TA %04X (%04X) TB %04X (%04X)", - (p[5] << 8) | p[4], (p[18] << 8) | p[17], - (p[7] << 8) | p[6], (p[20] << 8) | p[19]); - ULBS(L"TOD %06X (%06X) ALARM %06X %c%c", - (p[10] << 16) | (p[ 9] << 8) | p[ 8], - (p[23] << 16) | (p[22] << 8) | p[21], - (p[26] << 16) | (p[25] << 8) | p[24], - (p[27] & 1) ? 'L' : ' ', (p[27] & 2) ? ' ' : 'S'); - free(p2); - } - for (i = 0; i < 4; i++) { - p = p2 = save_disk (i, &len, NULL); + ULBS(L"Disk controller:"); ULBS(L""); - ULBS(L"Drive DF%d: (%s)", i, (p[4] & 2) ? "disabled" : "enabled"); - ULBS(L"ID %08X Motor %s Cylinder %2d MFMPOS %d", - (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3], - (p[4] & 1) ? L"On" : L"Off", - p[5], (p[8] << 24) | (p[9] << 16) | (p[10] << 8) | p[11]); - if (p[16]) - ULBS(L"'%s'", p + 16); - else - ULBS(L"Drive is empty"); - free(p2); - } - p = p2 = save_floppy (&len, NULL); - ULBS(L""); - ULBS(L"Disk controller:"); - ULBS(L""); - ULBS(L"Shift register: Data=%04X Shift=%d. DMA=%d,%d", (p[0] << 8) | p[1], p[2], p[3], p[5]); - free (p2); + ULBS(L"Shift register: Data=%04X Shift=%d. DMA=%d,%d", (p[0] << 8) | p[1], p[2], p[3], p[5]); + free (p2); } static void ShowCustom(void) { - int len, i, j, end; - uae_u8 *p1, *p2, *p3, *p4; - - ULBSINIT(GetDlgItem(hDbgWnd, IDC_DBG_CUSTOM)); - p1 = p2 = save_custom (&len, 0, 1); - p1 += 4; // skip chipset type - for (i = 0; i < 4; i++) { - p4 = p1 + 0xa0 + i * 16; - p3 = save_audio (i, &len, 0); - p4[0] = p3[12]; - p4[1] = p3[13]; - p4[2] = p3[14]; - p4[3] = p3[15]; - p4[4] = p3[4]; - p4[5] = p3[5]; - p4[6] = p3[8]; - p4[7] = p3[9]; - p4[8] = 0; - p4[9] = p3[1]; - p4[10] = p3[10]; - p4[11] = p3[11]; - free (p3); - } - end = 0; - while (custd[end].name) + int len, i, j, end; + uae_u8 *p1, *p2, *p3, *p4; + + ULBSINIT(GetDlgItem(hDbgWnd, IDC_DBG_CUSTOM)); + p1 = p2 = save_custom (&len, 0, 1); + p1 += 4; // skip chipset type + for (i = 0; i < 4; i++) { + p4 = p1 + 0xa0 + i * 16; + p3 = save_audio (i, &len, 0); + p4[0] = p3[12]; + p4[1] = p3[13]; + p4[2] = p3[14]; + p4[3] = p3[15]; + p4[4] = p3[4]; + p4[5] = p3[5]; + p4[6] = p3[8]; + p4[7] = p3[9]; + p4[8] = 0; + p4[9] = p3[1]; + p4[10] = p3[10]; + p4[11] = p3[11]; + free (p3); + } + end = 0; + while (custd[end].name) + end++; end++; - end++; - end /= 2; - for (i = 0; i < end; i++) { - uae_u16 v1, v2; - int addr1, addr2; - j = end + i; - addr1 = custd[i].adr & 0x1ff; - addr2 = custd[j].adr & 0x1ff; - v1 = (p1[addr1 + 0] << 8) | p1[addr1 + 1]; - v2 = (p1[addr2 + 0] << 8) | p1[addr2 + 1]; - ULBS(L"%03.3X %-15s %04X %03X %-15s %04X", - addr1, custd[i].name, v1, - addr2, custd[j].name, v2); - } - free (p2); + end /= 2; + for (i = 0; i < end; i++) { + uae_u16 v1, v2; + int addr1, addr2; + j = end + i; + addr1 = custd[i].adr & 0x1ff; + addr2 = custd[j].adr & 0x1ff; + v1 = (p1[addr1 + 0] << 8) | p1[addr1 + 1]; + v2 = (p1[addr2 + 0] << 8) | p1[addr2 + 1]; + ULBS(L"%03.3X %-15s %04X %03X %-15s %04X", + addr1, custd[i].name, v1, + addr2, custd[j].name, v2); + } + free (p2); } static void ShowBreakpoints(void) { - HWND hBrkpts; - int i, lines_old, got; - TCHAR outbp[MAX_LINEWIDTH + 1], outw[50]; - - hBrkpts = GetDlgItem(hDbgWnd, IDC_DBG_BRKPTS); - ULBSINIT(hBrkpts); - lines_old = SendMessage(hBrkpts, LB_GETCOUNT, 0, 0); - ULBS(L""); - ULBS(L"Breakpoints:"); - ULBS(L""); - got = 0; - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - if (!bpnodes[i].enabled) - continue; + HWND hBrkpts; + int i, lines_old, got; + TCHAR outbp[MAX_LINEWIDTH + 1], outw[50]; + + hBrkpts = GetDlgItem(hDbgWnd, IDC_DBG_BRKPTS); + ULBSINIT(hBrkpts); + lines_old = SendMessage(hBrkpts, LB_GETCOUNT, 0, 0); + ULBS(L""); + ULBS(L"Breakpoints:"); + ULBS(L""); + got = 0; + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + if (!bpnodes[i].enabled) + continue; m68k_disasm_2(outbp, sizeof(outbp), bpnodes[i].addr, NULL, 1, NULL, NULL, 0); - ULBS(outbp); - got = 1; - } - if (!got) - ULBS(L"none"); - ULBS(L""); - ULBS(L"Memwatch breakpoints:"); - ULBS(L""); - got = 0; - for (i = 0; i < MEMWATCH_TOTAL; i++) { - if (mwnodes[i].size == 0) - continue; - memwatch_dump2(outw, sizeof(outw), i); - ULBS(outw); - got = 1; - } - if (!got) - ULBS(L"none"); - for (i = ulbs_pos; i < lines_old; i++) - SendMessage(hBrkpts, LB_DELETESTRING, ulbs_pos, 0); + ULBS(outbp); + got = 1; + } + if (!got) + ULBS(L"none"); + ULBS(L""); + ULBS(L"Memwatch breakpoints:"); + ULBS(L""); + got = 0; + for (i = 0; i < MEMWATCH_TOTAL; i++) { + if (mwnodes[i].size == 0) + continue; + memwatch_dump2(outw, sizeof(outw), i); + ULBS(outw); + got = 1; + } + if (!got) + ULBS(L"none"); + for (i = ulbs_pos; i < lines_old; i++) + SendMessage(hBrkpts, LB_DELETESTRING, ulbs_pos, 0); } static void ShowMem(int offset) { - uae_u32 addr; - int i, lines_old, lines_new; - TCHAR out[MAX_LINEWIDTH + 1]; - HWND hMemory; + uae_u32 addr; + int i, lines_old, lines_new; + TCHAR out[MAX_LINEWIDTH + 1]; + HWND hMemory; - dbgpage[currpage].memaddr += offset; - addr = dbgpage[currpage].memaddr; + dbgpage[currpage].memaddr += offset; + addr = dbgpage[currpage].memaddr; if (currpage == 0) hMemory = GetDlgItem(hDbgWnd, IDC_DBG_MEM2); else - hMemory = GetDlgItem(hDbgWnd, IDC_DBG_MEM); - lines_old = SendMessage(hMemory, LB_GETCOUNT, 0, 0); - lines_new = GetLBOutputLines(hMemory); - for (i = 0; i < lines_new; i++) { - addr = dumpmem2(addr, out, sizeof(out)); - UpdateListboxString(hMemory, i, out, FALSE); - } - for (i = lines_new; i < lines_old; i++) { - SendMessage(hMemory, LB_DELETESTRING, lines_new, 0); - } - SendMessage(hMemory, LB_SETTOPINDEX, 0, 0); + hMemory = GetDlgItem(hDbgWnd, IDC_DBG_MEM); + lines_old = SendMessage(hMemory, LB_GETCOUNT, 0, 0); + lines_new = GetLBOutputLines(hMemory); + for (i = 0; i < lines_new; i++) { + addr = dumpmem2(addr, out, sizeof(out)); + UpdateListboxString(hMemory, i, out, FALSE); + } + for (i = lines_new; i < lines_old; i++) { + SendMessage(hMemory, LB_DELETESTRING, lines_new, 0); + } + SendMessage(hMemory, LB_SETTOPINDEX, 0, 0); } static int GetPrevAddr(uae_u32 addr, uae_u32 *prevaddr) { - uae_u32 dasmaddr, next; - - *prevaddr = addr; - dasmaddr = addr - 20; - while (dasmaddr < addr) { - next = dasmaddr + 2; - m68k_disasm_2(NULL, 0, dasmaddr, &next, 1, NULL, NULL, 0); - if (next == addr) { - *prevaddr = dasmaddr; - return 1; - } - dasmaddr = next; - } - return 0; + uae_u32 dasmaddr, next; + + *prevaddr = addr; + dasmaddr = addr - 20; + while (dasmaddr < addr) { + next = dasmaddr + 2; + m68k_disasm_2(NULL, 0, dasmaddr, &next, 1, NULL, NULL, 0); + if (next == addr) { + *prevaddr = dasmaddr; + return 1; + } + dasmaddr = next; + } + return 0; } static void ShowDasm(int direction) { - uae_u32 addr = 0, prev; - int i, lines_old, lines_new; - TCHAR out[MAX_LINEWIDTH + 1]; - HWND hDasm; + uae_u32 addr = 0, prev; + int i, lines_old, lines_new; + TCHAR out[MAX_LINEWIDTH + 1]; + HWND hDasm; if (currpage == 0) hDasm = GetDlgItem(hDbgWnd, IDC_DBG_DASM2); else hDasm = GetDlgItem(hDbgWnd, IDC_DBG_DASM); - if (!dbgpage[currpage].init) { - addr = m68k_getpc (); - dbgpage[currpage].init = 1; - } + if (!dbgpage[currpage].init) { + addr = m68k_getpc (); + dbgpage[currpage].init = 1; + } else if (dbgpage[currpage].autoset == 1 && direction == 0) { - addr = m68k_getpc (); - } - else - addr = dbgpage[currpage].dasmaddr; - if (direction > 0) { - m68k_disasm_2(NULL, 0, addr, &addr, 1, NULL, NULL, 0); - if (!addr || addr < dbgpage[currpage].dasmaddr) - addr = dbgpage[currpage].dasmaddr; - } - else if (direction < 0 && addr > 0) { - if (GetPrevAddr(addr, &prev)) - addr = prev; - else - addr -= 2; - } - dbgpage[currpage].dasmaddr = addr; - lines_old = SendMessage(hDasm, LB_GETCOUNT, 0, 0); - lines_new = GetLBOutputLines(hDasm); - for (i = 0; i < lines_new; i++) { - m68k_disasm_2(out, sizeof(out), addr, &addr, 1, NULL, NULL, 0); - if (addr > dbgpage[currpage].dasmaddr) - UpdateListboxString(hDasm, i, out, FALSE); + addr = m68k_getpc (); + } else - UpdateListboxString(hDasm, i, L"", FALSE); - } - for (i = lines_new; i < lines_old; i++) { - SendMessage(hDasm, LB_DELETESTRING, lines_new, 0); - } - SendMessage(hDasm, LB_SETTOPINDEX, 0, 0); + addr = dbgpage[currpage].dasmaddr; + if (direction > 0) { + m68k_disasm_2(NULL, 0, addr, &addr, 1, NULL, NULL, 0); + if (!addr || addr < dbgpage[currpage].dasmaddr) + addr = dbgpage[currpage].dasmaddr; + } + else if (direction < 0 && addr > 0) { + if (GetPrevAddr(addr, &prev)) + addr = prev; + else + addr -= 2; + } + dbgpage[currpage].dasmaddr = addr; + lines_old = SendMessage(hDasm, LB_GETCOUNT, 0, 0); + lines_new = GetLBOutputLines(hDasm); + for (i = 0; i < lines_new; i++) { + m68k_disasm_2(out, sizeof(out), addr, &addr, 1, NULL, NULL, 0); + if (addr > dbgpage[currpage].dasmaddr) + UpdateListboxString(hDasm, i, out, FALSE); + else + UpdateListboxString(hDasm, i, L"", FALSE); + } + for (i = lines_new; i < lines_old; i++) { + SendMessage(hDasm, LB_DELETESTRING, lines_new, 0); + } + SendMessage(hDasm, LB_SETTOPINDEX, 0, 0); } static void SetMemToPC(void) { - int i, id; - - dbgpage[currpage].dasmaddr = m68k_getpc (); - _stprintf(dbgpage[currpage].addrinput, L"%08lX", dbgpage[currpage].dasmaddr); - for (i = 0; i < MAXPAGECONTROLS; i++) { - id = GetDlgCtrlID(dbgpage[currpage].ctrl[i]); - if (id == IDC_DBG_MEMINPUT) - SetWindowText(dbgpage[currpage].ctrl[i], dbgpage[currpage].addrinput); - } - ShowDasm(0); -} + int i, id; -static void ShowPage(int index, int force) -{ - int i, id; - HWND hwnd; - - if (index >= pages || ((index == currpage) && !force)) - return; - if (currpage >= 0) { - pstatuscolor[currpage] = (currpage < 2 && index > 1) ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT; - if (index < 2) - pstatuscolor[index == 0 ? 1 : 0] = COLOR_GRAYTEXT; + dbgpage[currpage].dasmaddr = m68k_getpc (); + _stprintf(dbgpage[currpage].addrinput, L"%08lX", dbgpage[currpage].dasmaddr); for (i = 0; i < MAXPAGECONTROLS; i++) { - if (dbgpage[currpage].ctrl[i]) { id = GetDlgCtrlID(dbgpage[currpage].ctrl[i]); if (id == IDC_DBG_MEMINPUT) - GetWindowText(dbgpage[currpage].ctrl[i], dbgpage[currpage].addrinput, 9); - if (index != currpage) - ShowWindow(dbgpage[currpage].ctrl[i], SW_HIDE); - } + SetWindowText(dbgpage[currpage].ctrl[i], dbgpage[currpage].addrinput); } - } - pagetype = 0; + ShowDasm(0); +} + +static void ShowPage(int index, int force) +{ + int i, id; + HWND hwnd; + + if (index >= pages || ((index == currpage) && !force)) + return; + if (currpage >= 0) { + pstatuscolor[currpage] = (currpage < 2 && index > 1) ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT; + if (index < 2) + pstatuscolor[index == 0 ? 1 : 0] = COLOR_GRAYTEXT; + for (i = 0; i < MAXPAGECONTROLS; i++) { + if (dbgpage[currpage].ctrl[i]) { + id = GetDlgCtrlID(dbgpage[currpage].ctrl[i]); + if (id == IDC_DBG_MEMINPUT) + GetWindowText(dbgpage[currpage].ctrl[i], dbgpage[currpage].addrinput, 9); + if (index != currpage) + ShowWindow(dbgpage[currpage].ctrl[i], SW_HIDE); + } + } + } + pagetype = 0; currpage = index; - for (i = 0; i < MAXPAGECONTROLS; i++) { - if (dbgpage[index].ctrl[i]) { - id = GetDlgCtrlID(dbgpage[index].ctrl[i]); - if (id == IDC_DBG_OUTPUT1 || id == IDC_DBG_OUTPUT2) { - hOutput = dbgpage[index].ctrl[i]; - } else if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) { - ShowMem(0); - pagetype = id; - } else if (id == IDC_DBG_DASM) { - ShowDasm(0); - pagetype = id; - } else if (id == IDC_DBG_DASM2) { - ShowDasm(0); - } - else if (id == IDC_DBG_MEMINPUT) { - SetWindowText(dbgpage[index].ctrl[i], dbgpage[index].addrinput); - } else if (id == IDC_DBG_BRKPTS) { - ShowBreakpoints(); - } else if (id == IDC_DBG_MISC) { - ShowMisc(); - } else if (id == IDC_DBG_CUSTOM) { - ShowCustom(); - } else if (id == IDC_DBG_AUTOSET) { - SendMessage(dbgpage[index].ctrl[i], BM_SETCHECK, (WPARAM)dbgpage[index].autoset ? BST_CHECKED : BST_UNCHECKED, (LPARAM)0); - } - ShowWindow(dbgpage[index].ctrl[i], SW_SHOW); - } - } - pstatuscolor[currpage] = COLOR_HIGHLIGHT; - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); - RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE); + for (i = 0; i < MAXPAGECONTROLS; i++) { + if (dbgpage[index].ctrl[i]) { + id = GetDlgCtrlID(dbgpage[index].ctrl[i]); + if (id == IDC_DBG_OUTPUT1 || id == IDC_DBG_OUTPUT2) { + hOutput = dbgpage[index].ctrl[i]; + } else if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) { + ShowMem(0); + pagetype = id; + } else if (id == IDC_DBG_DASM) { + ShowDasm(0); + pagetype = id; + } else if (id == IDC_DBG_DASM2) { + ShowDasm(0); + } + else if (id == IDC_DBG_MEMINPUT) { + SetWindowText(dbgpage[index].ctrl[i], dbgpage[index].addrinput); + } else if (id == IDC_DBG_BRKPTS) { + ShowBreakpoints(); + } else if (id == IDC_DBG_MISC) { + ShowMisc(); + } else if (id == IDC_DBG_CUSTOM) { + ShowCustom(); + } else if (id == IDC_DBG_AUTOSET) { + SendMessage(dbgpage[index].ctrl[i], BM_SETCHECK, (WPARAM)dbgpage[index].autoset ? BST_CHECKED : BST_UNCHECKED, (LPARAM)0); + } + ShowWindow(dbgpage[index].ctrl[i], SW_SHOW); + } + } + pstatuscolor[currpage] = COLOR_HIGHLIGHT; + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); + RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE); } static void AddPage(int *iddata) { - int i; - - if (pages >= MAXPAGES) - return; - memset(&dbgpage[pages], 0, sizeof(struct debuggerpage)); - for (i = 0; iddata[i] > 0; i++) { - dbgpage[pages].ctrl[i] = GetDlgItem(hDbgWnd, iddata[i]); - ShowWindow(dbgpage[pages].ctrl[i], SW_HIDE); - } + int i; + + if (pages >= MAXPAGES) + return; + memset(&dbgpage[pages], 0, sizeof(struct debuggerpage)); + for (i = 0; iddata[i] > 0; i++) { + dbgpage[pages].ctrl[i] = GetDlgItem(hDbgWnd, iddata[i]); + ShowWindow(dbgpage[pages].ctrl[i], SW_HIDE); + } if (pages == 0) dbgpage[pages].autoset = 1; else dbgpage[pages].autoset = 0; - pages++; + pages++; } static int GetTextSize(HWND hWnd, TCHAR *text, int width) { - HDC hdc; - TEXTMETRIC tm; - HFONT hfont, hfontold; - hdc = GetDC(hWnd); - hfont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); - hfontold = (HFONT)SelectObject(hdc, hfont); - GetTextMetrics(hdc, &tm); - SelectObject(hdc, hfontold); - ReleaseDC(hWnd, hdc); - if (!width) - return tm.tmHeight + tm.tmExternalLeading; - else if (text) - return tm.tmMaxCharWidth * _tcslen(text); - return 0; + HDC hdc; + TEXTMETRIC tm; + HFONT hfont, hfontold; + hdc = GetDC(hWnd); + hfont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); + hfontold = (HFONT)SelectObject(hdc, hfont); + GetTextMetrics(hdc, &tm); + SelectObject(hdc, hfontold); + ReleaseDC(hWnd, hdc); + if (!width) + return tm.tmHeight + tm.tmExternalLeading; + else if (text) + return tm.tmMaxCharWidth * _tcslen(text); + return 0; } static void InitPages(void) { - int i, parts[MAXPAGES], width, pwidth = 0; - HWND hwnd; - - int dpage[][MAXPAGECONTROLS + 1] = { - { IDC_DBG_OUTPUT1, IDC_DBG_DASM2, IDC_DBG_MEM2, -1 }, - { IDC_DBG_OUTPUT2, -1 }, - { IDC_DBG_MEM, IDC_DBG_MEMINPUT, -1 }, - { IDC_DBG_MEM, IDC_DBG_MEMINPUT, -1 }, - { IDC_DBG_DASM, IDC_DBG_MEMINPUT, IDC_DBG_MEMTOPC, IDC_DBG_AUTOSET, -1 }, - { IDC_DBG_DASM, IDC_DBG_MEMINPUT, IDC_DBG_MEMTOPC, IDC_DBG_AUTOSET, -1 }, - { IDC_DBG_BRKPTS, -1 }, - { IDC_DBG_MISC, -1 }, - { IDC_DBG_CUSTOM, -1 } - }; - - pages = 0; - for (i = 0; i < (sizeof(dpage) / sizeof(dpage[0])); i++) - AddPage(dpage[i]); - memset(parts, 0, MAXPAGES * sizeof(int)); - width = GetTextSize(hDbgWnd, L"12345678", TRUE); // longest pagename + 2 - for (i = 0; i < pages; i++) { - pwidth += width; - parts[i] = pwidth; - } - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); - SendMessage(hwnd, SB_SETPARTS, (WPARAM)pages, (LPARAM)parts); - for (i = 0; i < pages; i++) { - SendMessage(hwnd, SB_SETTEXT, i | SBT_OWNERDRAW, 0); - pstatuscolor[i] = COLOR_GRAYTEXT; - } + int i, parts[MAXPAGES], width, pwidth = 0; + HWND hwnd; + + int dpage[][MAXPAGECONTROLS + 1] = { + { IDC_DBG_OUTPUT1, IDC_DBG_DASM2, IDC_DBG_MEM2, -1 }, + { IDC_DBG_OUTPUT2, -1 }, + { IDC_DBG_MEM, IDC_DBG_MEMINPUT, -1 }, + { IDC_DBG_MEM, IDC_DBG_MEMINPUT, -1 }, + { IDC_DBG_DASM, IDC_DBG_MEMINPUT, IDC_DBG_MEMTOPC, IDC_DBG_AUTOSET, -1 }, + { IDC_DBG_DASM, IDC_DBG_MEMINPUT, IDC_DBG_MEMTOPC, IDC_DBG_AUTOSET, -1 }, + { IDC_DBG_BRKPTS, -1 }, + { IDC_DBG_MISC, -1 }, + { IDC_DBG_CUSTOM, -1 } + }; + + pages = 0; + for (i = 0; i < (sizeof(dpage) / sizeof(dpage[0])); i++) + AddPage(dpage[i]); + memset(parts, 0, MAXPAGES * sizeof(int)); + width = GetTextSize(hDbgWnd, L"12345678", TRUE); // longest pagename + 2 + for (i = 0; i < pages; i++) { + pwidth += width; + parts[i] = pwidth; + } + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); + SendMessage(hwnd, SB_SETPARTS, (WPARAM)pages, (LPARAM)parts); + for (i = 0; i < pages; i++) { + SendMessage(hwnd, SB_SETTEXT, i | SBT_OWNERDRAW, 0); + pstatuscolor[i] = COLOR_GRAYTEXT; + } } static LRESULT CALLBACK InputProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - WNDPROC oldproc; + WNDPROC oldproc; - switch (message) { + switch (message) { case WM_CHAR: if (!debugger_active) return 0; @@ -784,70 +784,70 @@ static LRESULT CALLBACK InputProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM case WM_KEYUP: if (!debugger_active) return 0; - switch (wParam) { + switch (wParam) { case VK_RETURN: - inputfinished = 1; - break; + inputfinished = 1; + break; case VK_UP: - SetPrevHistNode(hWnd); - return 0; + SetPrevHistNode(hWnd); + return 0; case VK_DOWN: - SetNextHistNode(hWnd); - return 0; - } - break; - } - oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); - return CallWindowProc(oldproc, hWnd, message, wParam, lParam); + SetNextHistNode(hWnd); + return 0; + } + break; + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HANDLE hdata; - LPWSTR lptstr; - TCHAR allowed[] = L"1234567890abcdefABCDEF"; - int ok = 1; - TCHAR addrstr[12]; - uae_u32 addr; - WNDPROC oldproc; - - switch (message) { + HANDLE hdata; + LPWSTR lptstr; + TCHAR allowed[] = L"1234567890abcdefABCDEF"; + int ok = 1; + TCHAR addrstr[12]; + uae_u32 addr; + WNDPROC oldproc; + + switch (message) { case WM_CHAR: switch (wParam) { - case VK_BACK: - case VK_CANCEL: //ctrl+c - case VK_FINAL: //ctrl+x - case 0x16: //ctrl+v - break; - default: - if (!debugger_active || !_tcschr(allowed, wParam)) - return 0; - break; + case VK_BACK: + case VK_CANCEL: //ctrl+c + case VK_FINAL: //ctrl+x + case 0x16: //ctrl+v + break; + default: + if (!debugger_active || !_tcschr(allowed, wParam)) + return 0; + break; } - break; + break; case WM_PASTE: - if (!OpenClipboard(NULL)) - return TRUE; - hdata = GetClipboardData(CF_UNICODETEXT); - if (hdata) { - lptstr = GlobalLock(hdata); - if (lptstr) { - if (_tcsspn(lptstr, allowed) != _tcslen(lptstr)) - ok = 0; - GlobalUnlock(hdata); + if (!OpenClipboard(NULL)) + return TRUE; + hdata = GetClipboardData(CF_UNICODETEXT); + if (hdata) { + lptstr = GlobalLock(hdata); + if (lptstr) { + if (_tcsspn(lptstr, allowed) != _tcslen(lptstr)) + ok = 0; + GlobalUnlock(hdata); + } } - } - CloseClipboard(); - if (!ok) - return 0; - break; + CloseClipboard(); + if (!ok) + return 0; + break; case WM_KEYUP: if (!debugger_active) return 0; - switch (wParam) { + switch (wParam) { case VK_RETURN: - _stprintf(addrstr, L"0x"); - GetWindowText(hWnd, addrstr + 2, 9); + _stprintf(addrstr, L"0x"); + GetWindowText(hWnd, addrstr + 2, 9); if (addrstr[2] != 0) { addr = _tcstoul(addrstr, NULL, 0); if (pagetype == IDC_DBG_MEM || pagetype == IDC_DBG_MEM2) { @@ -861,46 +861,46 @@ static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LP ShowDasm(0); } } - return 0; - } - break; - } - oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); - return CallWindowProc(oldproc, hWnd, message, wParam, lParam); + return 0; + } + break; + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } static INT_PTR CALLBACK AddrInputDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch(msg) + { case WM_DESTROY: - PostQuitMessage (0); - return TRUE; + PostQuitMessage (0); + return TRUE; case WM_CLOSE: - EndDialog(hDlg, 0); - return TRUE; + 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; - } + { + 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: + switch (LOWORD(wParam)) { + case IDOK: { TCHAR addrstr[11] = { '0', 'x', '\0' }; @@ -921,12 +921,12 @@ static INT_PTR CALLBACK AddrInputDialogProc(HWND hDlg, UINT msg, WPARAM wParam, EndDialog(hDlg, 1); return TRUE; } - case IDCANCEL: - EndDialog(hDlg, 0); - return TRUE; - } + case IDCANCEL: + EndDialog(hDlg, 0); + return TRUE; + } break; - } + } return FALSE; } @@ -965,7 +965,7 @@ static void CopyListboxText(HWND hwnd, BOOL all) lptstr[len + 1] = '\n'; lptstr += (len + 2); } - GlobalUnlock(hdata); + GlobalUnlock(hdata); SetClipboardData(CF_UNICODETEXT, hdata); } CloseClipboard(); @@ -993,8 +993,8 @@ static void DeleteBreakpoints(HWND hwnd) static void ignore_ws (TCHAR **c) { - while (**c && _istspace(**c)) - (*c)++; + while (**c && _istspace(**c)) + (*c)++; } static void ListboxEndEdit(HWND hwnd, BOOL acceptinput) @@ -1097,76 +1097,76 @@ static void ListboxEndEdit(HWND hwnd, BOOL acceptinput) static LRESULT CALLBACK ListboxEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HANDLE hdata; - LPWSTR lptstr; - TCHAR allowed[] = L"1234567890abcdefABCDEF "; - int ok = 1, id; - WNDPROC oldproc; + HANDLE hdata; + LPWSTR lptstr; + TCHAR allowed[] = L"1234567890abcdefABCDEF "; + int ok = 1, id; + WNDPROC oldproc; HWND hparent = GetParent(hWnd); id = GetDlgCtrlID(hparent); if (id == IDC_DBG_DREG || id == IDC_DBG_AREG) allowed[_tcslen(allowed) - 1] = '\0'; // no space else if (id == IDC_DBG_FPREG) _stprintf(allowed, L"1234567890deDE.+-"); - switch (message) { + switch (message) { case WM_GETDLGCODE: return DLGC_WANTALLKEYS; case WM_MOUSELEAVE: - { - HWND hwcapt = GetCapture(); - if (!hwcapt) - SetCapture(hWnd); - break; - } + { + 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; - } + { + 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); + 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 (!_tcschr(allowed, wParam)) return 0; - default: - if (!_tcschr(allowed, wParam)) - return 0; - break; + break; } - break; + break; case WM_PASTE: - if (!OpenClipboard(NULL)) - return TRUE; - hdata = GetClipboardData(CF_UNICODETEXT); - if (hdata) { - lptstr = GlobalLock(hdata); - if (lptstr) { - if (_tcsspn(lptstr, allowed) != _tcslen(lptstr)) - ok = 0; - GlobalUnlock(hdata); + if (!OpenClipboard(NULL)) + return TRUE; + hdata = GetClipboardData(CF_UNICODETEXT); + if (hdata) { + lptstr = GlobalLock(hdata); + if (lptstr) { + if (_tcsspn(lptstr, allowed) != _tcslen(lptstr)) + ok = 0; + GlobalUnlock(hdata); + } } - } - CloseClipboard(); - if (!ok) - return 0; - break; + 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); + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } static void ListboxEdit(HWND hwnd, int x, int y) @@ -1281,40 +1281,40 @@ static void ToggleCCRFlag(HWND hwnd, int x, int y) memset(txt, 0, MAX_LINEWIDTH + 1); SendMessage(hwnd, LB_GETTEXT, (WPARAM)index, (LPARAM)(LPTSTR)txt); switch (txt[0]) { - case 'X': - SET_XFLG(GET_XFLG() ? 0 : 1); - break; - case 'N': - SET_NFLG(GET_NFLG() ? 0 : 1); - break; - case 'Z': - SET_ZFLG(GET_ZFLG() ? 0 : 1); - break; - case 'V': - SET_VFLG(GET_VFLG() ? 0 : 1); - break; - case 'C': - SET_CFLG(GET_CFLG() ? 0 : 1); - break; + case 'X': + SET_XFLG(GET_XFLG() ? 0 : 1); + break; + case 'N': + SET_NFLG(GET_NFLG() ? 0 : 1); + break; + case 'Z': + SET_ZFLG(GET_ZFLG() ? 0 : 1); + break; + case 'V': + SET_VFLG(GET_VFLG() ? 0 : 1); + break; + case 'C': + SET_CFLG(GET_CFLG() ? 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; + 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) @@ -1330,28 +1330,28 @@ static void ToggleFPSRFlag(HWND hwnd, int x, int y) static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - WNDPROC oldproc; - HWND hinput, hsbar; - RECT rc, r; - int i, itemheight, count, height, bottom, width, id, top; - PAINTSTRUCT ps; - DRAWITEMSTRUCT dis; - HFONT oldfont, font; - HDC hdc, compdc; - HBITMAP compbmp, oldbmp; - - switch (message) { + WNDPROC oldproc; + HWND hinput, hsbar; + RECT rc, r; + int i, itemheight, count, height, bottom, width, id, top; + PAINTSTRUCT ps; + DRAWITEMSTRUCT dis; + HFONT oldfont, font; + HDC hdc, compdc; + HBITMAP compbmp, oldbmp; + + switch (message) { case WM_CHAR: if (debugger_active) { - hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); - SetFocus(hinput); + hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); + SetFocus(hinput); SendMessage(hinput, WM_CHAR, wParam, lParam); } - return 0; + return 0; case WM_ERASEBKGND: - return 1; + return 1; case WM_SETFOCUS: - return 0; + return 0; case WM_LBUTTONDBLCLK: if (debugger_active) { int id = GetDlgCtrlID(hWnd); @@ -1364,132 +1364,132 @@ static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPAR } return 0; case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - GetClientRect(hWnd, &rc); - height = rc.bottom - rc.top; - width = rc.right - rc.left; - bottom = rc.bottom; - itemheight = SendMessage(hWnd, LB_GETITEMHEIGHT, 0, 0); - rc.bottom = itemheight; - count = SendMessage(hWnd, LB_GETCOUNT, 0, 0); - compdc = CreateCompatibleDC(hdc); - compbmp = CreateCompatibleBitmap(hdc, width, height); - oldbmp = SelectObject(compdc, compbmp); - font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); - oldfont = SelectObject(compdc, font); - id = GetDlgCtrlID(hWnd); - dis.CtlType = ODT_LISTBOX; - dis.CtlID = id; - dis.itemAction = 0; - dis.itemState = 0; - dis.hwndItem = hWnd; - dis.hDC = compdc; - top = SendMessage(hWnd, LB_GETTOPINDEX, 0, 0); - for (i = top; i < count && rc.top < height; i++) { - dis.itemID = i; - dis.rcItem = rc; - dis.itemData = SendMessage(hWnd, LB_GETITEMDATA, i, 0); - SendMessage(hDbgWnd, WM_DRAWITEM, id, (LPARAM)&dis); - rc.top += itemheight; - rc.bottom += itemheight; - } - rc.bottom = bottom; - if (!IsWindowEnabled(hWnd)) - FillRect(compdc, &rc, GetSysColorBrush(COLOR_3DFACE)); - else - FillRect(compdc, &rc, GetSysColorBrush(COLOR_WINDOW)); - GetWindowRect(hWnd, &rc); - hsbar = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); - GetWindowRect(hsbar, &r); - if (rc.top < r.top) { // not below status bar - if (rc.bottom > r.top) // partly visible - height -= rc.bottom - r.top; - BitBlt(hdc, 0, 0, width, height, compdc, 0, 0, SRCCOPY); - } - SelectObject(compdc, oldfont); - SelectObject(compdc, oldbmp); - DeleteObject(compbmp); - DeleteDC(compdc); - EndPaint(hWnd, &ps); - return 0; + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rc); + height = rc.bottom - rc.top; + width = rc.right - rc.left; + bottom = rc.bottom; + itemheight = SendMessage(hWnd, LB_GETITEMHEIGHT, 0, 0); + rc.bottom = itemheight; + count = SendMessage(hWnd, LB_GETCOUNT, 0, 0); + compdc = CreateCompatibleDC(hdc); + compbmp = CreateCompatibleBitmap(hdc, width, height); + oldbmp = SelectObject(compdc, compbmp); + font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); + oldfont = SelectObject(compdc, font); + id = GetDlgCtrlID(hWnd); + dis.CtlType = ODT_LISTBOX; + dis.CtlID = id; + dis.itemAction = 0; + dis.itemState = 0; + dis.hwndItem = hWnd; + dis.hDC = compdc; + top = SendMessage(hWnd, LB_GETTOPINDEX, 0, 0); + for (i = top; i < count && rc.top < height; i++) { + dis.itemID = i; + dis.rcItem = rc; + dis.itemData = SendMessage(hWnd, LB_GETITEMDATA, i, 0); + SendMessage(hDbgWnd, WM_DRAWITEM, id, (LPARAM)&dis); + rc.top += itemheight; + rc.bottom += itemheight; + } + rc.bottom = bottom; + if (!IsWindowEnabled(hWnd)) + FillRect(compdc, &rc, GetSysColorBrush(COLOR_3DFACE)); + else + FillRect(compdc, &rc, GetSysColorBrush(COLOR_WINDOW)); + GetWindowRect(hWnd, &rc); + hsbar = GetDlgItem(hDbgWnd, IDC_DBG_STATUS); + GetWindowRect(hsbar, &r); + if (rc.top < r.top) { // not below status bar + if (rc.bottom > r.top) // partly visible + height -= rc.bottom - r.top; + BitBlt(hdc, 0, 0, width, height, compdc, 0, 0, SRCCOPY); + } + SelectObject(compdc, oldfont); + SelectObject(compdc, oldbmp); + DeleteObject(compbmp); + DeleteDC(compdc); + EndPaint(hWnd, &ps); + return 0; case WM_COMMAND: switch(LOWORD(wParam)) { - case ID_DBG_SETTOA0: - case ID_DBG_SETTOA1: - case ID_DBG_SETTOA2: - case ID_DBG_SETTOA3: - case ID_DBG_SETTOA4: - case ID_DBG_SETTOA5: - case ID_DBG_SETTOA6: - case ID_DBG_SETTOA7: - dbgpage[currpage].memaddr = m68k_areg(regs, LOWORD(wParam) - ID_DBG_SETTOA0); - ShowMem(0); - return 0; - case ID_DBG_SETTOPC: - dbgpage[currpage].dasmaddr = m68k_getpc(); - ShowDasm(0); - return 0; - case ID_DBG_ENTERADDR: - dbgpage[currpage].selection = GetDlgCtrlID(hWnd); - CustomDialogBox(IDD_DBGMEMINPUT, hWnd, (DLGPROC)AddrInputDialogProc); - return 0; - case ID_DBG_COPYLBLINE: - CopyListboxText(hWnd, FALSE); - return 0; - case ID_DBG_COPYLB: - CopyListboxText(hWnd, TRUE); - return 0; - case ID_DBG_TOGGLEBP: - ToggleBreakpoint(hWnd); - return 0; - case ID_DBG_DELETEBPS: - DeleteBreakpoints(hWnd); - return 0; + case ID_DBG_SETTOA0: + case ID_DBG_SETTOA1: + case ID_DBG_SETTOA2: + case ID_DBG_SETTOA3: + case ID_DBG_SETTOA4: + case ID_DBG_SETTOA5: + case ID_DBG_SETTOA6: + case ID_DBG_SETTOA7: + dbgpage[currpage].memaddr = m68k_areg(regs, LOWORD(wParam) - ID_DBG_SETTOA0); + ShowMem(0); + return 0; + case ID_DBG_SETTOPC: + dbgpage[currpage].dasmaddr = m68k_getpc(); + ShowDasm(0); + return 0; + case ID_DBG_ENTERADDR: + dbgpage[currpage].selection = GetDlgCtrlID(hWnd); + CustomDialogBox(IDD_DBGMEMINPUT, hWnd, (DLGPROC)AddrInputDialogProc); + return 0; + case ID_DBG_COPYLBLINE: + CopyListboxText(hWnd, FALSE); + return 0; + case ID_DBG_COPYLB: + CopyListboxText(hWnd, TRUE); + return 0; + case ID_DBG_TOGGLEBP: + ToggleBreakpoint(hWnd); + return 0; + case ID_DBG_DELETEBPS: + DeleteBreakpoints(hWnd); + return 0; } break; - } - oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); - return CallWindowProc(oldproc, hWnd, message, wParam, lParam); + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - WNDPROC oldproc; - HWND hinput; + WNDPROC oldproc; + HWND hinput; - switch (message) { + switch (message) { case WM_CHAR: - if (wParam != VK_CANCEL) { // not for Ctrl-C for copying + if (wParam != VK_CANCEL) { // not for Ctrl-C for copying if (debugger_active) { hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); SetFocus(hinput); SendMessage(hinput, WM_CHAR, wParam, lParam); } - return 0; - } - break; - } - oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); - return CallWindowProc(oldproc, hWnd, message, wParam, lParam); + return 0; + } + break; + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } static void moveupdown(int dir) { - if (pagetype == IDC_DBG_MEM || pagetype == IDC_DBG_MEM2) { - if (dir > 1 || dir < -1) - dir *= 4; - ShowMem(dir * 16); - } else if (pagetype == IDC_DBG_DASM) { - if (dir > 1 || dir < -1) - dir *= 4; - while(dir) { - ShowDasm(dir > 0 ? 1 : -1); - if (dir > 0) - dir--; - if (dir < 0) - dir++; - } - } + if (pagetype == IDC_DBG_MEM || pagetype == IDC_DBG_MEM2) { + if (dir > 1 || dir < -1) + dir *= 4; + ShowMem(dir * 16); + } else if (pagetype == IDC_DBG_DASM) { + if (dir > 1 || dir < -1) + dir *= 4; + while(dir) { + ShowDasm(dir > 0 ? 1 : -1); + if (dir > 0) + dir--; + if (dir < 0) + dir++; + } + } } static int width_adjust, height_adjust; @@ -1497,49 +1497,49 @@ static RECT dlgRect; static void adjustitem(HWND hwnd, int x, int y, int w, int h) { - WINDOWINFO pwi; - RECT *r; - pwi.cbSize = sizeof pwi; - GetWindowInfo(hwnd, &pwi); - r = &pwi.rcWindow; - r->bottom -= r->top; - r->right -= r->left; - r->left -= dlgRect.left; - r->top -= dlgRect.top; - r->left += x; - r->top += y; - r->right += w; - r->bottom += h; - MoveWindow(hwnd, r->left, r->top, r->right, r->bottom, TRUE); + WINDOWINFO pwi; + RECT *r; + pwi.cbSize = sizeof pwi; + GetWindowInfo(hwnd, &pwi); + r = &pwi.rcWindow; + r->bottom -= r->top; + r->right -= r->left; + r->left -= dlgRect.left; + r->top -= dlgRect.top; + r->left += x; + r->top += y; + r->right += w; + r->bottom += h; + MoveWindow(hwnd, r->left, r->top, r->right, r->bottom, TRUE); } static int randidx; static BOOL CALLBACK childenumproc (HWND hwnd, LPARAM lParam) { - int id1y[] = { IDC_DBG_OUTPUT2, IDC_DBG_MEM, IDC_DBG_DASM, IDC_DBG_BRKPTS, IDC_DBG_MISC, IDC_DBG_CUSTOM, -1 }; - int id2y[] = { IDC_DBG_INPUT, IDC_DBG_HELP, IDC_DBG_STATUS, -1 }; + int id1y[] = { IDC_DBG_OUTPUT2, IDC_DBG_MEM, IDC_DBG_DASM, IDC_DBG_BRKPTS, IDC_DBG_MISC, IDC_DBG_CUSTOM, -1 }; + int id2y[] = { IDC_DBG_INPUT, IDC_DBG_HELP, IDC_DBG_STATUS, -1 }; int id3y[] = { IDC_DBG_DASM2, IDC_DBG_MEM2, IDC_DBG_OUTPUT1, -1 }; int id1x[] = { IDC_DBG_OUTPUT1, IDC_DBG_OUTPUT2, IDC_DBG_MEM, IDC_DBG_MEM2, IDC_DBG_DASM, IDC_DBG_DASM2, - IDC_DBG_AMEM, IDC_DBG_PREFETCH, IDC_DBG_INPUT, IDC_DBG_STATUS, IDC_DBG_BRKPTS, IDC_DBG_MISC, IDC_DBG_CUSTOM, -1 }; - int id2x[] = { IDC_DBG_HELP, IDC_DBG_CCR, IDC_DBG_SP_VBR, IDC_DBG_MMISC, - IDC_DBG_FPREG, IDC_DBG_FPSR, IDC_DBG_MCUSTOM, IDC_DBG_MISCCPU, -1 }; - - int dlgid, j, count, adjust, remainder, starty; - dlgid = GetDlgCtrlID(hwnd); - - j = 0; - while (id1y[j] >= 0) { - if (id1y[j] == dlgid) - adjustitem(hwnd, 0, 0, 0, height_adjust); - j++; - } - j = 0; - while (id2y[j] >= 0) { - if (id2y[j] == dlgid) - adjustitem(hwnd, 0, height_adjust, 0, 0); - j++; - } + IDC_DBG_AMEM, IDC_DBG_PREFETCH, IDC_DBG_INPUT, IDC_DBG_STATUS, IDC_DBG_BRKPTS, IDC_DBG_MISC, IDC_DBG_CUSTOM, -1 }; + int id2x[] = { IDC_DBG_HELP, IDC_DBG_CCR, IDC_DBG_SP_VBR, IDC_DBG_MMISC, + IDC_DBG_FPREG, IDC_DBG_FPSR, IDC_DBG_MCUSTOM, IDC_DBG_MISCCPU, -1 }; + + int dlgid, j, count, adjust, remainder, starty; + dlgid = GetDlgCtrlID(hwnd); + + j = 0; + while (id1y[j] >= 0) { + if (id1y[j] == dlgid) + adjustitem(hwnd, 0, 0, 0, height_adjust); + j++; + } + j = 0; + while (id2y[j] >= 0) { + if (id2y[j] == dlgid) + adjustitem(hwnd, 0, height_adjust, 0, 0); + j++; + } j = 0; count = sizeof(id3y) / sizeof(int) - 1; adjust = height_adjust / count; @@ -1560,101 +1560,101 @@ static BOOL CALLBACK childenumproc (HWND hwnd, LPARAM lParam) } j++; } - j = 0; - while (id1x[j] >= 0) { - if (id1x[j] == dlgid) - adjustitem(hwnd, 0, 0, width_adjust,0); - j++; - } - j = 0; - while (id2x[j] >= 0) { - if (id2x[j] == dlgid) - adjustitem(hwnd, width_adjust,0, 0, 0); - j++; - } - return TRUE; + j = 0; + while (id1x[j] >= 0) { + if (id1x[j] == dlgid) + adjustitem(hwnd, 0, 0, width_adjust,0); + j++; + } + j = 0; + while (id2x[j] >= 0) { + if (id2x[j] == dlgid) + adjustitem(hwnd, width_adjust,0, 0, 0); + j++; + } + return TRUE; } static void AdjustDialog(HWND hDlg) { - RECT r, r2; + 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; + 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; GetWindowInfo(hDlg, &pwi); AdjustWindowRectEx(&r2, pwi.dwStyle, FALSE, pwi.dwExStyle); - dlgRect.left -= r2.left; - dlgRect.top -= r2.top; + dlgRect.left -= r2.left; + dlgRect.top -= r2.top; randidx = -1; - EnumChildWindows (hDlg, childenumproc, 0); - dlgRect = r; - RedrawWindow(hDlg, 0, 0, RDW_INVALIDATE); + EnumChildWindows (hDlg, childenumproc, 0); + dlgRect = r; + RedrawWindow(hDlg, 0, 0, RDW_INVALIDATE); } static BOOL CALLBACK InitChildWindows(HWND hWnd, LPARAM lParam) { - int i, id, enable = TRUE, items = 0; - WNDPROC newproc = NULL, oldproc; - TCHAR classname[CLASSNAMELENGTH]; - WINDOWINFO pwi; - RECT *r; - - id = GetDlgCtrlID(hWnd); - switch (id) { + int i, id, enable = TRUE, items = 0; + WNDPROC newproc = NULL, oldproc; + TCHAR classname[CLASSNAMELENGTH]; + WINDOWINFO pwi; + RECT *r; + + id = GetDlgCtrlID(hWnd); + switch (id) { case IDC_DBG_INPUT: - newproc = InputProc; - SendMessage(hWnd, EM_LIMITTEXT, MAX_LINEWIDTH, 0); - break; + newproc = InputProc; + SendMessage(hWnd, EM_LIMITTEXT, MAX_LINEWIDTH, 0); + break; case IDC_DBG_MEMINPUT: - newproc = MemInputProc; - SendMessage(hWnd, EM_LIMITTEXT, 8, 0); - break; + newproc = MemInputProc; + SendMessage(hWnd, EM_LIMITTEXT, 8, 0); + break; case IDC_DBG_PREFETCH: - newproc = ListboxProc; - enable = currprefs.cpu_compatible ? TRUE : FALSE; - break; + newproc = ListboxProc; + enable = currprefs.cpu_compatible ? TRUE : FALSE; + break; case IDC_DBG_FPREG: case IDC_DBG_FPSR: - newproc = ListboxProc; - enable = currprefs.cpu_model < 68020 ? FALSE : TRUE; - break; + newproc = ListboxProc; + enable = currprefs.cpu_model < 68020 ? FALSE : TRUE; + break; case IDC_DBG_MISCCPU: - if (currprefs.cpu_model == 68000) { - items = 4; - enable = FALSE; - } - else { - for (i = 0; m2cregs[i].regno>= 0; i++) { - if (!movec_illg(m2cregs[i].regno)) - items++; + if (currprefs.cpu_model == 68000) { + items = 4; + enable = FALSE; + } + else { + for (i = 0; m2cregs[i].regno>= 0; i++) { + if (!movec_illg(m2cregs[i].regno)) + items++; + } } - } - pwi.cbSize = sizeof pwi; - GetWindowInfo(hWnd, &pwi); - r = &pwi.rcClient; - r->bottom = r->top + items * GetTextSize(hWnd, NULL, FALSE); - AdjustWindowRectEx(r, pwi.dwStyle, FALSE, pwi.dwExStyle); - SetWindowPos(hWnd, 0, 0, 0, r->right - r->left, r->bottom - r->top, SWP_NOMOVE | SWP_NOZORDER); - newproc = ListboxProc; - break; + pwi.cbSize = sizeof pwi; + GetWindowInfo(hWnd, &pwi); + r = &pwi.rcClient; + r->bottom = r->top + items * GetTextSize(hWnd, NULL, FALSE); + AdjustWindowRectEx(r, pwi.dwStyle, FALSE, pwi.dwExStyle); + SetWindowPos(hWnd, 0, 0, 0, r->right - r->left, r->bottom - r->top, SWP_NOMOVE | SWP_NOZORDER); + newproc = ListboxProc; + break; default: - if (GetClassName(hWnd, classname, CLASSNAMELENGTH)) { - if (!_tcscmp(classname, L"ListBox")) - newproc = ListboxProc; - else if (!_tcscmp(classname, L"Edit")) - newproc = EditProc; - } - break; - } - if (newproc) { - oldproc = (WNDPROC)SetWindowLongPtr(hWnd, GWL_WNDPROC, (LONG_PTR)newproc); - SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)oldproc); - } - EnableWindow(hWnd, enable); - return TRUE; + if (GetClassName(hWnd, classname, CLASSNAMELENGTH)) { + if (!_tcscmp(classname, L"ListBox")) + newproc = ListboxProc; + else if (!_tcscmp(classname, L"Edit")) + newproc = EditProc; + } + break; + } + if (newproc) { + oldproc = (WNDPROC)SetWindowLongPtr(hWnd, GWL_WNDPROC, (LONG_PTR)newproc); + SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)oldproc); + } + EnableWindow(hWnd, enable); + return TRUE; } static void step(BOOL over) @@ -1669,7 +1669,7 @@ static void step(BOOL over) static void ShowContextMenu(HWND hwnd, int x, int y) { - POINT pt = { x, y }; + POINT pt = { x, y }; HMENU hmenu, hsubmenu; int id = GetDlgCtrlID(hwnd); if (x == -1 || y == -1) { @@ -1710,143 +1710,143 @@ static void SelectListboxLine(HWND hwnd, int x, int y) static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - HWND hwnd; + HWND hwnd; static BOOL sizing = FALSE; - switch (message) { + switch (message) { case WM_INITDIALOG: - { - int newpos = 0; - LONG x, y, w, h; - RECT rw; - HFONT hfont; - LOGFONT lf; - GetWindowRect(hDlg, &rw); - dbgwnd_minx = rw.right - rw.left; - dbgwnd_miny = rw.bottom - rw.top; - GetClientRect(hDlg, &dlgRect); - newpos = 1; - if (!regqueryint (NULL, L"DebuggerPosX", &x)) - newpos = 0; - if (!regqueryint (NULL, L"DebuggerPosY", &y)) - newpos = 0; - if (!regqueryint (NULL, L"DebuggerPosW", &w)) - newpos = 0; - if (!regqueryint (NULL, L"DebuggerPosH", &h)) - newpos = 0; - if (newpos) { - RECT rc; - rc.left = x; - rc.top = y; - rc.right = x + w; - rc.bottom = y + h; - if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) != NULL) - SetWindowPos(hDlg, 0, x, y, w, h, SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_DEFERERASE); - } - SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPICON))); - EnumChildWindows(hDlg, InitChildWindows, 0); - currpage = -1; - firsthist = lasthist = currhist = NULL; - histcount = 0; - inputfinished = 0; - AdjustDialog(hDlg); - hfont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); - GetObject(hfont, sizeof(LOGFONT), &lf); - lf.lfEscapement = lf.lfOrientation = 1800; - udfont = CreateFontIndirect(&lf); - return TRUE; - } + { + int newpos = 0; + LONG x, y, w, h; + RECT rw; + HFONT hfont; + LOGFONT lf; + GetWindowRect(hDlg, &rw); + dbgwnd_minx = rw.right - rw.left; + dbgwnd_miny = rw.bottom - rw.top; + GetClientRect(hDlg, &dlgRect); + newpos = 1; + if (!regqueryint (NULL, L"DebuggerPosX", &x)) + newpos = 0; + if (!regqueryint (NULL, L"DebuggerPosY", &y)) + newpos = 0; + if (!regqueryint (NULL, L"DebuggerPosW", &w)) + newpos = 0; + if (!regqueryint (NULL, L"DebuggerPosH", &h)) + newpos = 0; + if (newpos) { + RECT rc; + rc.left = x; + rc.top = y; + rc.right = x + w; + rc.bottom = y + h; + if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) != NULL) + SetWindowPos(hDlg, 0, x, y, w, h, SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_DEFERERASE); + } + SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPICON))); + EnumChildWindows(hDlg, InitChildWindows, 0); + currpage = -1; + firsthist = lasthist = currhist = NULL; + histcount = 0; + inputfinished = 0; + AdjustDialog(hDlg); + hfont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); + GetObject(hfont, sizeof(LOGFONT), &lf); + lf.lfEscapement = lf.lfOrientation = 1800; + udfont = CreateFontIndirect(&lf); + return TRUE; + } case WM_CLOSE: - DestroyWindow(hDlg); - uae_quit(); - return TRUE; + DestroyWindow(hDlg); + uae_quit(); + return TRUE; case WM_DESTROY: - { - 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; + { + 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, L"DebuggerPosX", r->left); + regsetint (NULL, L"DebuggerPosY", r->top); + regsetint (NULL, L"DebuggerPosW", r->right); + regsetint (NULL, L"DebuggerPosH", r->bottom); + regsetint (NULL, L"DebuggerMaximized", (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) ? 1 : 0); + } + hDbgWnd = 0; + PostQuitMessage(0); + DeleteFromHistory(histcount); + DeleteObject(udfont); + consoleopen = 0; + return TRUE; } - if (GetWindowPlacement (hDlg, &wp)) { - r = &wp.rcNormalPosition; - r->right -= r->left; - r->bottom -= r->top; - r->left += xoffset; - r->top += yoffset; - regsetint (NULL, L"DebuggerPosX", r->left); - regsetint (NULL, L"DebuggerPosY", r->top); - regsetint (NULL, L"DebuggerPosW", r->right); - regsetint (NULL, L"DebuggerPosH", r->bottom); - regsetint (NULL, L"DebuggerMaximized", (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) ? 1 : 0); - } - hDbgWnd = 0; - PostQuitMessage(0); - DeleteFromHistory(histcount); - DeleteObject(udfont); - consoleopen = 0; - return TRUE; - } case WM_GETMINMAXINFO: - { - MINMAXINFO *mmi = (MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x = dbgwnd_minx; - mmi->ptMinTrackSize.y = dbgwnd_miny; - return TRUE; - } + { + MINMAXINFO *mmi = (MINMAXINFO*)lParam; + mmi->ptMinTrackSize.x = dbgwnd_minx; + mmi->ptMinTrackSize.y = dbgwnd_miny; + return TRUE; + } case WM_ENTERSIZEMOVE: sizing = TRUE; return FALSE; case WM_EXITSIZEMOVE: - { - AdjustDialog(hDlg); - ShowPage(currpage, TRUE); - sizing = FALSE; - return TRUE; - } - case WM_SIZE: - { - if (!sizing && (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED)) { + { AdjustDialog(hDlg); 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; } - return TRUE; - } case WM_CTLCOLORSTATIC: - { - int id = GetDlgCtrlID((HWND)lParam); - if (id == IDC_DBG_OUTPUT1 || id == IDC_DBG_OUTPUT2) { - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (LRESULT)GetSysColorBrush(COLOR_WINDOW); + { + int id = GetDlgCtrlID((HWND)lParam); + if (id == IDC_DBG_OUTPUT1 || id == IDC_DBG_OUTPUT2) { + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (LRESULT)GetSysColorBrush(COLOR_WINDOW); + } + return FALSE; } - return FALSE; - } case WM_CTLCOLORLISTBOX: - hwnd = (HWND)lParam; - if (!IsWindowEnabled(hwnd)) { - SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE)); - return (LRESULT)GetSysColorBrush(COLOR_3DFACE); - } - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (LRESULT)GetSysColorBrush(COLOR_WINDOW); + hwnd = (HWND)lParam; + if (!IsWindowEnabled(hwnd)) { + SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE)); + return (LRESULT)GetSysColorBrush(COLOR_3DFACE); + } + 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)) { + switch (LOWORD(wParam)) { case IDC_DBG_HELP: - { - HWND hinput; - WriteOutput(linebreak + 1, 2); - debug_help(); - hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); - SetFocus(hinput); - return TRUE; - } + { + HWND hinput; + WriteOutput(linebreak + 1, 2); + debug_help(); + hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); + SetFocus(hinput); + return TRUE; + } case ID_DBG_PAGE1: case ID_DBG_PAGE2: case ID_DBG_PAGE3: @@ -1856,9 +1856,9 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP case ID_DBG_PAGE7: case ID_DBG_PAGE8: case ID_DBG_PAGE9: - // IDs have to be consecutive and in order of page order for this to work - ShowPage(LOWORD(wParam) - ID_DBG_PAGE1, FALSE); - return TRUE; + // IDs have to be consecutive and in order of page order for this to work + ShowPage(LOWORD(wParam) - ID_DBG_PAGE1, FALSE); + return TRUE; case ID_DBG_STEP_OVER: step(TRUE); return TRUE; @@ -1866,333 +1866,333 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP step(FALSE); return TRUE; case IDC_DBG_MEMUP: - moveupdown(-1); - return TRUE; + moveupdown(-1); + return TRUE; case IDC_DBG_MEMDOWN: - moveupdown(1); - return TRUE; + moveupdown(1); + return TRUE; case IDC_DBG_MEMUPFAST: - moveupdown(-2); - return TRUE; + moveupdown(-2); + return TRUE; case IDC_DBG_MEMDOWNFAST: - moveupdown(2); - return TRUE; + moveupdown(2); + return TRUE; case IDC_DBG_MEMTOPC: - { - HWND hmeminput; - SetMemToPC(); - hmeminput = GetDlgItem(hDbgWnd, IDC_DBG_MEMINPUT); - SetFocus(hmeminput); - return TRUE; - } + { + HWND hmeminput; + SetMemToPC(); + hmeminput = GetDlgItem(hDbgWnd, IDC_DBG_MEMINPUT); + SetFocus(hmeminput); + return TRUE; + } case IDC_DBG_AUTOSET: - { - if (pagetype == IDC_DBG_DASM) { - HWND hctrl; - dbgpage[currpage].autoset = 1 - dbgpage[currpage].autoset; - hctrl = GetDlgItem(hDbgWnd, IDC_DBG_AUTOSET); - SendMessage(hctrl, BM_SETCHECK, dbgpage[currpage].autoset ? BST_CHECKED : BST_UNCHECKED, 0); - hctrl = GetDlgItem(hDbgWnd, IDC_DBG_MEMINPUT); - SetFocus(hctrl); + { + if (pagetype == IDC_DBG_DASM) { + HWND hctrl; + dbgpage[currpage].autoset = 1 - dbgpage[currpage].autoset; + hctrl = GetDlgItem(hDbgWnd, IDC_DBG_AUTOSET); + SendMessage(hctrl, BM_SETCHECK, dbgpage[currpage].autoset ? BST_CHECKED : BST_UNCHECKED, 0); + hctrl = GetDlgItem(hDbgWnd, IDC_DBG_MEMINPUT); + SetFocus(hctrl); + } + return TRUE; } - return TRUE; } - } - break; + break; case WM_CONTEXTMENU: - { - int id = GetDlgCtrlID((HWND)wParam); - if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2 || id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { - if (!hedit){ - SelectListboxLine((HWND)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - ShowContextMenu((HWND)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + { + int id = GetDlgCtrlID((HWND)wParam); + if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2 || id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { + 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; } - return TRUE; + break; } - break; - } case WM_MEASUREITEM: - ((MEASUREITEMSTRUCT*)(lParam))->itemHeight = GetTextSize(hDlg, NULL, FALSE); - return TRUE; - case WM_DRAWITEM: - { - DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; - HDC hdc = pdis->hDC; - RECT rc = pdis->rcItem; - TCHAR text[MAX_LINEWIDTH + 1]; - uae_u32 addr; - SetBkMode(hdc, TRANSPARENT); - if (wParam == IDC_DBG_STATUS) { - SetTextColor(hdc, GetSysColor(pstatuscolor[pdis->itemID])); - DrawText(hdc, pname[pdis->itemID], _tcslen(pname[pdis->itemID]), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + ((MEASUREITEMSTRUCT*)(lParam))->itemHeight = GetTextSize(hDlg, NULL, FALSE); return TRUE; - } - else { - if (pdis->itemID < 0) { - return TRUE; - } - memset(text, 0, MAX_LINEWIDTH + 1); - SendMessage(pdis->hwndItem, LB_GETTEXT, pdis->itemID, (LPARAM)(LPSTR)text); - if (!IsWindowEnabled(pdis->hwndItem)) { - FillRect(hdc, &rc, GetSysColorBrush(COLOR_3DFACE)); - SetBkColor(hdc, GetSysColor(COLOR_3DFACE)); - } - else { - FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW)); - SetBkColor(hdc, GetSysColor(COLOR_WINDOW)); - } - SetTextColor(hdc, pdis->itemData); - if (wParam == IDC_DBG_DASM || wParam == IDC_DBG_DASM2) { - TCHAR addrstr[11] = { '0', 'x', '\0'}, *btemp; - int i, j, size = rc.bottom - rc.top; - _tcsncpy(addrstr + 2, text, 8); - addrstr[10] = 0; - addr = _tcstoul(addrstr, NULL, 0); - for (i = 0; i < BREAKPOINT_TOTAL; i++) { - if (addr == bpnodes[i].addr && bpnodes[i].enabled) { - int offset = 0; - if (size >= 9) - offset = 3; - SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT)); - Ellipse(hdc, rc.left + offset, rc.top + offset, rc.left + size - offset, rc.bottom - offset); - } + case WM_DRAWITEM: + { + DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; + HDC hdc = pdis->hDC; + RECT rc = pdis->rcItem; + TCHAR text[MAX_LINEWIDTH + 1]; + uae_u32 addr; + SetBkMode(hdc, TRANSPARENT); + if (wParam == IDC_DBG_STATUS) { + SetTextColor(hdc, GetSysColor(pstatuscolor[pdis->itemID])); + DrawText(hdc, pname[pdis->itemID], _tcslen(pname[pdis->itemID]), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + return TRUE; } - rc.left += size; - i = 0; - btemp = NULL; - addrstr[2] = '\0'; - while (ucbranch[i]) { - if (!_tcsncmp(text + 34, ucbranch[i], _tcslen(ucbranch[i]))) { - btemp = _tcschr(text + 34, '='); - if (btemp) - _tcsncpy(addrstr + 2, btemp + 4, 8); - else { - int pos = 34 + _tcslen(ucbranch[i]) + 3; - if (text[pos] == '$') //absolute addressing - _tcsncpy(addrstr + 2, text + pos + 1, 8); - else if (text[pos] == '(' && _istdigit(text[pos + 2])) { //address register indirect - int reg = _tstoi(text + pos + 2); - uae_u32 loc = m68k_areg (regs, reg); - _stprintf(addrstr + 2, L"%08lx", loc); + else { + if (pdis->itemID < 0) { + return TRUE; + } + memset(text, 0, MAX_LINEWIDTH + 1); + SendMessage(pdis->hwndItem, LB_GETTEXT, pdis->itemID, (LPARAM)(LPSTR)text); + if (!IsWindowEnabled(pdis->hwndItem)) { + FillRect(hdc, &rc, GetSysColorBrush(COLOR_3DFACE)); + SetBkColor(hdc, GetSysColor(COLOR_3DFACE)); + } + else { + FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW)); + SetBkColor(hdc, GetSysColor(COLOR_WINDOW)); + } + SetTextColor(hdc, pdis->itemData); + if (wParam == IDC_DBG_DASM || wParam == IDC_DBG_DASM2) { + TCHAR addrstr[11] = { '0', 'x', '\0'}, *btemp; + int i, j, size = rc.bottom - rc.top; + _tcsncpy(addrstr + 2, text, 8); + addrstr[10] = 0; + addr = _tcstoul(addrstr, NULL, 0); + for (i = 0; i < BREAKPOINT_TOTAL; i++) { + if (addr == bpnodes[i].addr && bpnodes[i].enabled) { + int offset = 0; + if (size >= 9) + offset = 3; + SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT)); + Ellipse(hdc, rc.left + offset, rc.top + offset, rc.left + size - offset, rc.bottom - offset); } } - break; - } - i++; - } - i = 0; - while (addrstr[2] == '\0' && cbranch[i]) { - if (!_tcsncmp(text + 34, cbranch[i], _tcslen(cbranch[i]))) { - j = 0; - while (ccode[j]) { - if (!_tcsncmp(text + 34 + _tcslen(cbranch[i]), ccode[j], _tcslen(ccode[j]))) { + rc.left += size; + i = 0; + btemp = NULL; + addrstr[2] = '\0'; + while (ucbranch[i]) { + if (!_tcsncmp(text + 34, ucbranch[i], _tcslen(ucbranch[i]))) { btemp = _tcschr(text + 34, '='); if (btemp) _tcsncpy(addrstr + 2, btemp + 4, 8); + else { + int pos = 34 + _tcslen(ucbranch[i]) + 3; + if (text[pos] == '$') //absolute addressing + _tcsncpy(addrstr + 2, text + pos + 1, 8); + else if (text[pos] == '(' && _istdigit(text[pos + 2])) { //address register indirect + int reg = _tstoi(text + pos + 2); + uae_u32 loc = m68k_areg (regs, reg); + _stprintf(addrstr + 2, L"%08lx", loc); + } + } + break; + } + i++; + } + i = 0; + while (addrstr[2] == '\0' && cbranch[i]) { + if (!_tcsncmp(text + 34, cbranch[i], _tcslen(cbranch[i]))) { + j = 0; + while (ccode[j]) { + if (!_tcsncmp(text + 34 + _tcslen(cbranch[i]), ccode[j], _tcslen(ccode[j]))) { + btemp = _tcschr(text + 34, '='); + if (btemp) + _tcsncpy(addrstr + 2, btemp + 4, 8); + break; + } + j++; + } + } + i++; + } + if (addrstr[2] != '\0') { + uae_u32 branchaddr = _tcstoul(addrstr, NULL, 0); + if (branchaddr < addr) + TextOut(hdc, rc.left, rc.top, L"^", 1); + else if (branchaddr > addr) { + HFONT hfontold = (HFONT)SelectObject(hdc, udfont); + int width = GetTextSize(hDlg, L"^", TRUE); + TextOut(hdc, rc.left + width, rc.bottom, L"^", 1); + SelectObject(hdc, hfontold); + } + else + TextOut(hdc, rc.left, rc.top, L"=", 1); + } + rc.left += size; + if (addr == m68k_getpc()) { + FillRect(hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT)); + SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT)); + SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); + } + TextOut(hdc, rc.left, rc.top, text, _tcslen(text)); + i = 0; + while (markinstr[i]) { + if (!_tcsncmp(text + 34, markinstr[i], _tcslen(markinstr[i]))) { + MoveToEx(hdc, rc.left, rc.bottom - 1, NULL); + LineTo(hdc, rc.right, rc.bottom - 1); break; } - j++; + i++; } + if ((pdis->itemState) & (ODS_SELECTED)) + DrawFocusRect(hdc, &rc); } - i++; - } - if (addrstr[2] != '\0') { - uae_u32 branchaddr = _tcstoul(addrstr, NULL, 0); - if (branchaddr < addr) - TextOut(hdc, rc.left, rc.top, L"^", 1); - else if (branchaddr > addr) { - HFONT hfontold = (HFONT)SelectObject(hdc, udfont); - int width = GetTextSize(hDlg, L"^", TRUE); - TextOut(hdc, rc.left + width, rc.bottom, L"^", 1); - SelectObject(hdc, hfontold); + else if (wParam == IDC_DBG_MEM || wParam == IDC_DBG_MEM2) { + TextOut(hdc, rc.left, rc.top, text, _tcslen(text)); + if ((pdis->itemState) & (ODS_SELECTED)) + DrawFocusRect(hdc, &rc); } else - TextOut(hdc, rc.left, rc.top, L"=", 1); - } - rc.left += size; - if (addr == m68k_getpc()) { - FillRect(hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT)); - SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT)); - SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - } - TextOut(hdc, rc.left, rc.top, text, _tcslen(text)); - i = 0; - while (markinstr[i]) { - if (!_tcsncmp(text + 34, markinstr[i], _tcslen(markinstr[i]))) { - MoveToEx(hdc, rc.left, rc.bottom - 1, NULL); - LineTo(hdc, rc.right, rc.bottom - 1); - break; - } - i++; + TextOut(hdc, rc.left, rc.top, text, _tcslen(text)); + return TRUE; } - 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, _tcslen(text)); - if ((pdis->itemState) & (ODS_SELECTED)) - DrawFocusRect(hdc, &rc); + break; } - else - TextOut(hdc, rc.left, rc.top, text, _tcslen(text)); - return TRUE; - } - break; } - } - return FALSE; + return FALSE; } int open_debug_window(void) { - struct newresource *nr; + struct newresource *nr; int maximized; - if (hDbgWnd) - return 0; + if (hDbgWnd) + return 0; debuggerinitializing = TRUE; - reopen = 0; - dbgaccel = LoadAccelerators(hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDR_DBGACCEL)); - nr = getresource(IDD_DEBUGGER); - if (nr) { - hDbgWnd = CreateDialogIndirect (nr->inst, nr->resource, NULL, DebuggerProc); - freescaleresource(nr); - } + reopen = 0; + dbgaccel = LoadAccelerators(hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDR_DBGACCEL)); + nr = getresource(IDD_DEBUGGER); + if (nr) { + hDbgWnd = CreateDialogIndirect (nr->inst, nr->resource, NULL, DebuggerProc); + freescaleresource(nr); + } debuggerinitializing = FALSE; - if (!hDbgWnd) - return 0; - InitPages(); - ShowPage(0, TRUE); + if (!hDbgWnd) + return 0; + InitPages(); + ShowPage(0, TRUE); if (!regqueryint (NULL, L"DebuggerMaximized", &maximized)) maximized = 0; ShowWindow(hDbgWnd, maximized ? SW_SHOWMAXIMIZED : SW_SHOW); - UpdateWindow(hDbgWnd); - SetForegroundWindow (hDbgWnd); - update_debug_info(); - return 1; + UpdateWindow(hDbgWnd); + SetForegroundWindow (hDbgWnd); + update_debug_info(); + return 1; } void close_debug_window(void) { - DestroyWindow(hDbgWnd); - } + DestroyWindow(hDbgWnd); +} int console_get_gui (TCHAR *out, int maxlen) { - MSG msg; - int ret; - - while ((ret = GetMessage(&msg, NULL, 0, 0)) != 0) { - if (!debugger_active || ret == -1) { - return -1; - } else if (!TranslateAccelerator(hDbgWnd, dbgaccel, &msg)) { - if (!IsWindow(hDbgWnd) || !IsDialogMessage(hDbgWnd, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + MSG msg; + int ret; + + while ((ret = GetMessage(&msg, NULL, 0, 0)) != 0) { + if (!debugger_active || ret == -1) { + return -1; + } else if (!TranslateAccelerator(hDbgWnd, dbgaccel, &msg)) { + if (!IsWindow(hDbgWnd) || !IsDialogMessage(hDbgWnd, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } - } - if (inputfinished) { - if (dbgpage[currpage].autoset == 2) - dbgpage[currpage].autoset = 1; - inputfinished = 0; - if (useinternalcmd) { - useinternalcmd = FALSE; - console_out(L"\n"); - console_out(internalcmd); - console_out(L"\n"); - _tcsncpy(out, internalcmd, maxlen); - return _tcslen(out); + if (inputfinished) { + if (dbgpage[currpage].autoset == 2) + dbgpage[currpage].autoset = 1; + inputfinished = 0; + if (useinternalcmd) { + useinternalcmd = FALSE; + console_out(L"\n"); + console_out(internalcmd); + console_out(L"\n"); + _tcsncpy(out, internalcmd, maxlen); + return _tcslen(out); + } + else + return GetInput(out, maxlen); } - else - return GetInput(out, maxlen); } - } - return 0; + return 0; } void update_debug_info(void) { - int i; - TCHAR out[MAX_LINEWIDTH + 1]; - HWND hwnd; - struct instr *dp; - struct mnemolookup *lookup1, *lookup2; - uae_u32 fpsr; - TCHAR *fpsrflag[] = { L"N: ", L"Z: ", L"I: ", L"NAN: " }; - - if (!hDbgWnd) - return; - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_DREG); - for (i = 0; i < 8; i++) { - _stprintf(out, L"D%d: %08lX", i, m68k_dreg (regs, i)); - UpdateListboxString(hwnd, i, out, TRUE); - } - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_AREG); - for (i = 0; i < 8; i++) { + int i; + TCHAR out[MAX_LINEWIDTH + 1]; + HWND hwnd; + struct instr *dp; + struct mnemolookup *lookup1, *lookup2; + uae_u32 fpsr; + TCHAR *fpsrflag[] = { L"N: ", L"Z: ", L"I: ", L"NAN: " }; + + if (!hDbgWnd) + return; + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_DREG); + for (i = 0; i < 8; i++) { + _stprintf(out, L"D%d: %08lX", i, m68k_dreg (regs, i)); + UpdateListboxString(hwnd, i, out, TRUE); + } + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_AREG); - _stprintf(out, L"A%d: %08lX", i, m68k_areg (regs, i)); - UpdateListboxString(hwnd, i, out, TRUE); - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_AMEM); - dumpmem2(m68k_areg (regs, i), out, sizeof(out)); - UpdateListboxString(hwnd, i, out + 9, TRUE); - } - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_CCR); - UpdateListboxString(hwnd, 0, GET_XFLG() ? L"X: 1" : L"X: 0", TRUE); - UpdateListboxString(hwnd, 1, GET_NFLG() ? L"N: 1" : L"N: 0", TRUE); - UpdateListboxString(hwnd, 2, GET_ZFLG() ? L"Z: 1" : L"Z: 0", TRUE); - UpdateListboxString(hwnd, 3, GET_VFLG() ? L"V: 1" : L"V: 0", TRUE); - UpdateListboxString(hwnd, 4, GET_CFLG() ? L"C: 1" : L"C: 0", TRUE); - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_SP_VBR); - _stprintf(out, L"USP: %08lX", regs.usp); - UpdateListboxString(hwnd, 0, out, TRUE); - _stprintf(out, L"ISP: %08lX", regs.isp); - UpdateListboxString(hwnd, 1, out, TRUE); - - ShowMiscCPU(GetDlgItem(hDbgWnd, IDC_DBG_MISCCPU)); - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_MMISC); - _stprintf(out, L"T: %d%d", regs.t1, regs.t0); - UpdateListboxString(hwnd, 0, out, TRUE); - _stprintf(out, L"S: %d", regs.s); - UpdateListboxString(hwnd, 1, out, TRUE); - _stprintf(out, L"M: %d", regs.m); - UpdateListboxString(hwnd, 2, out, TRUE); - _stprintf(out, L"IMASK: %d", regs.intmask); - UpdateListboxString(hwnd, 3, out, TRUE); - _stprintf(out, L"STP: %d", regs.stopped); - UpdateListboxString(hwnd, 4, out, TRUE); - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_PC); - _stprintf(out, L"PC: %08lX", m68k_getpc ()); - UpdateListboxString(hwnd, 0, out, TRUE); - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_PREFETCH); - dp = table68k + regs.irc; - for (lookup1 = lookuptab; lookup1->mnemo != dp->mnemo; lookup1++); - dp = table68k + regs.ir; - for (lookup2 = lookuptab; lookup2->mnemo != dp->mnemo; lookup2++); - _stprintf(out, L"Prefetch: %04X (%s) %04X (%s)", regs.irc, lookup1->name, regs.ir, lookup2->name); - UpdateListboxString(hwnd, 0, out, TRUE); - - ShowCustomSmall(GetDlgItem(hDbgWnd, IDC_DBG_MCUSTOM)); - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_FPREG); - for (i = 0; i < 8; i++) { - _stprintf(out, L"FP%d: %g", i, regs.fp[i]); - UpdateListboxString(hwnd, i, out, TRUE); - } - - hwnd = GetDlgItem(hDbgWnd, IDC_DBG_FPSR); - fpsr = get_fpsr(); - for (i = 0; i < 4; i++) { - _stprintf(out, L"%s%d", fpsrflag[i], (fpsr & (0x8000000 >> i)) != 0 ? 1 : 0); - UpdateListboxString(hwnd, i, out, TRUE); - } - ShowPage(currpage, TRUE); + for (i = 0; i < 8; i++) { + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_AREG); + _stprintf(out, L"A%d: %08lX", i, m68k_areg (regs, i)); + UpdateListboxString(hwnd, i, out, TRUE); + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_AMEM); + dumpmem2(m68k_areg (regs, i), out, sizeof(out)); + UpdateListboxString(hwnd, i, out + 9, TRUE); + } + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_CCR); + UpdateListboxString(hwnd, 0, GET_XFLG() ? L"X: 1" : L"X: 0", TRUE); + UpdateListboxString(hwnd, 1, GET_NFLG() ? L"N: 1" : L"N: 0", TRUE); + UpdateListboxString(hwnd, 2, GET_ZFLG() ? L"Z: 1" : L"Z: 0", TRUE); + UpdateListboxString(hwnd, 3, GET_VFLG() ? L"V: 1" : L"V: 0", TRUE); + UpdateListboxString(hwnd, 4, GET_CFLG() ? L"C: 1" : L"C: 0", TRUE); + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_SP_VBR); + _stprintf(out, L"USP: %08lX", regs.usp); + UpdateListboxString(hwnd, 0, out, TRUE); + _stprintf(out, L"ISP: %08lX", regs.isp); + UpdateListboxString(hwnd, 1, out, TRUE); + + ShowMiscCPU(GetDlgItem(hDbgWnd, IDC_DBG_MISCCPU)); + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_MMISC); + _stprintf(out, L"T: %d%d", regs.t1, regs.t0); + UpdateListboxString(hwnd, 0, out, TRUE); + _stprintf(out, L"S: %d", regs.s); + UpdateListboxString(hwnd, 1, out, TRUE); + _stprintf(out, L"M: %d", regs.m); + UpdateListboxString(hwnd, 2, out, TRUE); + _stprintf(out, L"IMASK: %d", regs.intmask); + UpdateListboxString(hwnd, 3, out, TRUE); + _stprintf(out, L"STP: %d", regs.stopped); + UpdateListboxString(hwnd, 4, out, TRUE); + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_PC); + _stprintf(out, L"PC: %08lX", m68k_getpc ()); + UpdateListboxString(hwnd, 0, out, TRUE); + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_PREFETCH); + dp = table68k + regs.irc; + for (lookup1 = lookuptab; lookup1->mnemo != dp->mnemo; lookup1++); + dp = table68k + regs.ir; + for (lookup2 = lookuptab; lookup2->mnemo != dp->mnemo; lookup2++); + _stprintf(out, L"Prefetch: %04X (%s) %04X (%s)", regs.irc, lookup1->name, regs.ir, lookup2->name); + UpdateListboxString(hwnd, 0, out, TRUE); + + ShowCustomSmall(GetDlgItem(hDbgWnd, IDC_DBG_MCUSTOM)); + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_FPREG); + for (i = 0; i < 8; i++) { + _stprintf(out, L"FP%d: %g", i, regs.fp[i]); + UpdateListboxString(hwnd, i, out, TRUE); + } + + hwnd = GetDlgItem(hDbgWnd, IDC_DBG_FPSR); + fpsr = get_fpsr(); + for (i = 0; i < 4; i++) { + _stprintf(out, L"%s%d", fpsrflag[i], (fpsr & (0x8000000 >> i)) != 0 ? 1 : 0); + UpdateListboxString(hwnd, i, out, TRUE); + } + ShowPage(currpage, TRUE); } void update_disassembly(uae_u32 addr) diff --git a/od-win32/dinput.c b/od-win32/dinput.c index 38530acd..27f9d819 100644 --- a/od-win32/dinput.c +++ b/od-win32/dinput.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 DirectInput/Windows XP RAWINPUT interface - * - * Copyright 2002 - 2004 Toni Wilen - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 DirectInput/Windows XP RAWINPUT interface +* +* Copyright 2002 - 2004 Toni Wilen +*/ #define _WIN32_WINNT 0x501 /* enable RAWINPUT support */ @@ -59,35 +59,35 @@ #define DIDC_CAT 4 struct didata { - int type; - int acquired; - int priority; - int superdevice; - GUID iguid; - GUID pguid; - TCHAR *name; - TCHAR *sortname; - TCHAR *configname; - - int connection; - LPDIRECTINPUTDEVICE8 lpdi; - HANDLE rawinput; - int wininput; - int catweasel; - int coop; - - int axles; - int buttons, buttons_real; - int axismappings[MAX_MAPPINGS]; - TCHAR *axisname[MAX_MAPPINGS]; - int axissort[MAX_MAPPINGS]; - int axistype[MAX_MAPPINGS]; - int buttonmappings[MAX_MAPPINGS]; - TCHAR *buttonname[MAX_MAPPINGS]; - int buttonsort[MAX_MAPPINGS]; - - int axisparent[MAX_MAPPINGS]; - int axisparentdir[MAX_MAPPINGS]; + int type; + int acquired; + int priority; + int superdevice; + GUID iguid; + GUID pguid; + TCHAR *name; + TCHAR *sortname; + TCHAR *configname; + + int connection; + LPDIRECTINPUTDEVICE8 lpdi; + HANDLE rawinput; + int wininput; + int catweasel; + int coop; + + int axles; + int buttons, buttons_real; + int axismappings[MAX_MAPPINGS]; + TCHAR *axisname[MAX_MAPPINGS]; + int axissort[MAX_MAPPINGS]; + int axistype[MAX_MAPPINGS]; + int buttonmappings[MAX_MAPPINGS]; + TCHAR *buttonname[MAX_MAPPINGS]; + int buttonsort[MAX_MAPPINGS]; + + int axisparent[MAX_MAPPINGS]; + int axisparentdir[MAX_MAPPINGS]; }; #define DI_BUFFER 30 @@ -110,154 +110,154 @@ int dinput_enum_all; int dinput_winmouse (void) { - if (winmouse) - return winmousenumber; - return -1; + if (winmouse) + return winmousenumber; + return -1; } int dinput_wheelbuttonstart (void) { - return winmousewheelbuttonstart; + return winmousewheelbuttonstart; } int dinput_winmousemode (void) { - if (winmouse) - return winmousemode; - return 0; + if (winmouse) + return winmousemode; + return 0; } static isrealbutton (struct didata *did, int num) { - if (num >= did->buttons) - return 0; - if (did->axisparent[num] >= 0) - return 0; - return 1; + if (num >= did->buttons) + return 0; + if (did->axisparent[num] >= 0) + return 0; + return 1; } static void fixbuttons (struct didata *did) { - if (did->buttons > 0) - return; - write_log (L"'%s' has no buttons, adding single default button\n", did->name); - did->buttonmappings[0] = DIJOFS_BUTTON (0); - did->buttonsort[0] = 0; - did->buttonname[0] = my_strdup (L"Button"); - did->buttons++; + if (did->buttons > 0) + return; + write_log (L"'%s' has no buttons, adding single default button\n", did->name); + did->buttonmappings[0] = DIJOFS_BUTTON (0); + did->buttonsort[0] = 0; + did->buttonname[0] = my_strdup (L"Button"); + did->buttons++; } static void addplusminus (struct didata *did, int i) { - TCHAR tmp[256]; - int j; + TCHAR tmp[256]; + int j; - if (did->buttons + 1 >= MAX_MAPPINGS) - return; - for (j = 0; j < 2; j++) { - _stprintf (tmp, L"%s [%c]", did->axisname[i], j ? '+' : '-'); - did->buttonname[did->buttons] = my_strdup (tmp); - did->buttonmappings[did->buttons] = did->axismappings[i]; - did->buttonsort[did->buttons] = 1000 + (did->axismappings[i] + did->axistype[i]) * 2 + j; - did->axisparent[did->buttons] = i; - did->axisparentdir[did->buttons] = j; - did->buttons++; - } + if (did->buttons + 1 >= MAX_MAPPINGS) + return; + for (j = 0; j < 2; j++) { + _stprintf (tmp, L"%s [%c]", did->axisname[i], j ? '+' : '-'); + did->buttonname[did->buttons] = my_strdup (tmp); + did->buttonmappings[did->buttons] = did->axismappings[i]; + did->buttonsort[did->buttons] = 1000 + (did->axismappings[i] + did->axistype[i]) * 2 + j; + did->axisparent[did->buttons] = i; + did->axisparentdir[did->buttons] = j; + did->buttons++; + } } static void fixthings (struct didata *did) { - int i; + int i; - for (i = 0; i < did->axles; i++) - addplusminus (did, i); + for (i = 0; i < did->axles; i++) + addplusminus (did, i); } static void fixthings_mouse (struct didata *did) { - int i; + int i; - for (i = 0; i < did->axles; i++) { - if (did->axissort[i] == -97) - addplusminus (did, i); - } + for (i = 0; i < did->axles; i++) { + if (did->axissort[i] == -97) + addplusminus (did, i); + } } typedef BOOL (CALLBACK* REGISTERRAWINPUTDEVICES) - (PCRAWINPUTDEVICE, UINT, UINT); + (PCRAWINPUTDEVICE, UINT, UINT); static REGISTERRAWINPUTDEVICES pRegisterRawInputDevices; typedef UINT (CALLBACK* GETRAWINPUTDATA) - (HRAWINPUT, UINT, LPVOID, PUINT, UINT); + (HRAWINPUT, UINT, LPVOID, PUINT, UINT); static GETRAWINPUTDATA pGetRawInputData; typedef UINT (CALLBACK* GETRAWINPUTDEVICELIST) - (PRAWINPUTDEVICEKUST, PUINT, UINT); + (PRAWINPUTDEVICEKUST, PUINT, UINT); static GETRAWINPUTDEVICELIST pGetRawInputDeviceList; typedef UINT (CALLBACK* GETRAWINPUTDEVICEINFO) - (HANDLE, UINT, LPVOID, PUINT); + (HANDLE, UINT, LPVOID, PUINT); static GETRAWINPUTDEVICEINFO pGetRawInputDeviceInfo; typedef UINT (CALLBACK* GETRAWINPUTBUFFER) - (PRAWINPUT, PUINT, UINT); + (PRAWINPUT, PUINT, UINT); static GETRAWINPUTBUFFER pGetRawInputBuffer; typedef LRESULT (CALLBACK* DEFRAWINPUTPROC) - (PRAWINPUT*, INT, UINT); + (PRAWINPUT*, INT, UINT); static DEFRAWINPUTPROC pDefRawInputProc; static int rawinput_available, rawinput_registered_mouse, rawinput_registered_kb; static int register_rawinput (void) { - int num, rm, rkb; - RAWINPUTDEVICE rid[2]; + int num, rm, rkb; + RAWINPUTDEVICE rid[2]; - if (!rawinput_available) - return 0; + if (!rawinput_available) + return 0; - rm = rawmouse ? 1 : 0; - if (supermouse) - rm = 0; - rkb = rawkb ? 1 : 0; - if (!rawkeyboard) - rkb = 0; - if (rawinput_registered_mouse == rm && rawinput_registered_kb == rkb) - return 1; + rm = rawmouse ? 1 : 0; + if (supermouse) + rm = 0; + rkb = rawkb ? 1 : 0; + if (!rawkeyboard) + rkb = 0; + if (rawinput_registered_mouse == rm && rawinput_registered_kb == rkb) + return 1; - memset (rid, 0, sizeof (rid)); - num = 0; - if (rawinput_registered_mouse != rm) { - /* mouse */ - rid[num].usUsagePage = 1; - rid[num].usUsage = 2; - if (!rawmouse) - rid[num].dwFlags = RIDEV_REMOVE; - num++; - } - if (rawinput_registered_kb != rkb) { - /* keyboard */ - rid[num].usUsagePage = 1; - rid[num].usUsage = 6; - if (!rawkb) - rid[num].dwFlags = RIDEV_REMOVE; - num++; - } - if (num == 0) + memset (rid, 0, sizeof (rid)); + num = 0; + if (rawinput_registered_mouse != rm) { + /* mouse */ + rid[num].usUsagePage = 1; + rid[num].usUsage = 2; + if (!rawmouse) + rid[num].dwFlags = RIDEV_REMOVE; + num++; + } + if (rawinput_registered_kb != rkb) { + /* keyboard */ + rid[num].usUsagePage = 1; + rid[num].usUsage = 6; + if (!rawkb) + rid[num].dwFlags = RIDEV_REMOVE; + num++; + } + if (num == 0) + return 1; + if (pRegisterRawInputDevices (rid, num, sizeof (RAWINPUTDEVICE)) == FALSE) { + write_log (L"RAWINPUT registration failed %d (%d,%d->%d,%d->%d)\n", + GetLastError (), num, + rawinput_registered_mouse, rm, + rawinput_registered_kb, rkb); + return 0; + } + rawinput_registered_mouse = rm; + rawinput_registered_kb = rkb; return 1; - if (pRegisterRawInputDevices (rid, num, sizeof (RAWINPUTDEVICE)) == FALSE) { - write_log (L"RAWINPUT registration failed %d (%d,%d->%d,%d->%d)\n", - GetLastError (), num, - rawinput_registered_mouse, rm, - rawinput_registered_kb, rkb); - return 0; - } - rawinput_registered_mouse = rm; - rawinput_registered_kb = rkb; - return 1; } static void cleardid (struct didata *did) { - int i; - memset (did, 0, sizeof (*did)); - for (i = 0; i < MAX_MAPPINGS; i++) { - did->axismappings[i] = -1; - did->buttonmappings[i] = -1; - did->axisparent[i] = -1; - } + int i; + memset (did, 0, sizeof (*did)); + for (i = 0; i < MAX_MAPPINGS; i++) { + did->axismappings[i] = -1; + did->buttonmappings[i] = -1; + did->axisparent[i] = -1; + } } @@ -267,99 +267,99 @@ static int keyboard_german; static int keyhack (int scancode, int pressed, int num) { - static byte backslashstate,apostrophstate; + static byte backslashstate,apostrophstate; #ifdef RETROPLATFORM - if (rp_checkesc (scancode, di_keycodes[num], pressed, num)) - return -1; + if (rp_checkesc (scancode, di_keycodes[num], pressed, num)) + return -1; #endif - //check ALT-F4 - if (pressed && !di_keycodes[num][DIK_F4] && scancode == DIK_F4) { - if (di_keycodes[num][DIK_LALT] && !currprefs.win32_ctrl_F11_is_quit) { + //check ALT-F4 + if (pressed && !di_keycodes[num][DIK_F4] && scancode == DIK_F4) { + if (di_keycodes[num][DIK_LALT] && !currprefs.win32_ctrl_F11_is_quit) { #ifdef RETROPLATFORM - if (rp_close ()) - return -1; + if (rp_close ()) + return -1; #endif - uae_quit (); - return -1; + uae_quit (); + return -1; + } } - } #ifdef SINGLEFILE - if (pressed && scancode == DIK_ESCAPE) { - uae_quit (); - return -1; - } + if (pressed && scancode == DIK_ESCAPE) { + uae_quit (); + return -1; + } #endif - // release mouse if TAB and ALT is pressed - if (pressed && di_keycodes[num][DIK_LALT] && scancode == DIK_TAB) { - disablecapture (); - return -1; - } + // release mouse if TAB and ALT is pressed + if (pressed && di_keycodes[num][DIK_LALT] && scancode == DIK_TAB) { + disablecapture (); + return -1; + } - if (!keyboard_german || currprefs.input_selected_setting > 0) - return scancode; + if (!keyboard_german || currprefs.input_selected_setting > 0) + return scancode; - //This code look so ugly because there is no Directinput - //key for # (called numbersign on win standard message) - //available - //so here need to change qulifier state and restore it when key - //is release - if (scancode == DIK_BACKSLASH) // The # key - { - if (di_keycodes[num][DIK_LSHIFT] || di_keycodes[num][DIK_RSHIFT] || apostrophstate) + //This code look so ugly because there is no Directinput + //key for # (called numbersign on win standard message) + //available + //so here need to change qulifier state and restore it when key + //is release + if (scancode == DIK_BACKSLASH) // The # key { - if (pressed) - { apostrophstate=1; - inputdevice_translatekeycode (num, DIK_RSHIFT, 0); - inputdevice_translatekeycode (num, DIK_LSHIFT, 0); - return 13; // the german ' key - } - else - { - //best is add a real keystatecheck here but it still work so - apostrophstate = 0; - inputdevice_translatekeycode (num, DIK_LALT,0); - inputdevice_translatekeycode (num, DIK_LSHIFT,0); - inputdevice_translatekeycode (num, 4, 0); // release also the # key - return 13; - } - - } - if (pressed) - { - inputdevice_translatekeycode (num, DIK_LALT, 1); - inputdevice_translatekeycode (num, DIK_LSHIFT,1); - return 4; // the german # key - } - else - { - inputdevice_translatekeycode (num, DIK_LALT, 0); - inputdevice_translatekeycode (num, DIK_LSHIFT, 0); - // Here is the same not nice but do the job - return 4; // the german # key + if (di_keycodes[num][DIK_LSHIFT] || di_keycodes[num][DIK_RSHIFT] || apostrophstate) + { + if (pressed) + { apostrophstate=1; + inputdevice_translatekeycode (num, DIK_RSHIFT, 0); + inputdevice_translatekeycode (num, DIK_LSHIFT, 0); + return 13; // the german ' key + } + else + { + //best is add a real keystatecheck here but it still work so + apostrophstate = 0; + inputdevice_translatekeycode (num, DIK_LALT,0); + inputdevice_translatekeycode (num, DIK_LSHIFT,0); + inputdevice_translatekeycode (num, 4, 0); // release also the # key + return 13; + } + } + if (pressed) + { + inputdevice_translatekeycode (num, DIK_LALT, 1); + inputdevice_translatekeycode (num, DIK_LSHIFT,1); + return 4; // the german # key + } + else + { + inputdevice_translatekeycode (num, DIK_LALT, 0); + inputdevice_translatekeycode (num, DIK_LSHIFT, 0); + // Here is the same not nice but do the job + return 4; // the german # key + + } } - } - if ((di_keycodes[num][DIK_RALT]) || (backslashstate)) { - switch (scancode) - { - case 12: - if (pressed) - { - backslashstate=1; - inputdevice_translatekeycode (num, DIK_RALT, 0); - return DIK_BACKSLASH; - } - else - { - backslashstate=0; - return DIK_BACKSLASH; - } - } - } - return scancode; + if ((di_keycodes[num][DIK_RALT]) || (backslashstate)) { + switch (scancode) + { + case 12: + if (pressed) + { + backslashstate=1; + inputdevice_translatekeycode (num, DIK_RALT, 0); + return DIK_BACKSLASH; + } + else + { + backslashstate=0; + return DIK_BACKSLASH; + } + } + } + return scancode; } static int tablet; @@ -373,236 +373,236 @@ static int tablet_ax, tablet_ay, tablet_az, tablet_flags; static void tablet_send (void) { - static int eraser; + static int eraser; - if ((tablet_flags & TPS_INVERT) && tablet_pressure > 0) { - tablet_buttons |= 2; - eraser = 1; - } else if (eraser) { - tablet_buttons &= ~2; - eraser = 0; - } - if (tablet_x < 0) - return; - inputdevice_tablet (tablet_x, tablet_y, tablet_z, tablet_pressure, tablet_buttons, tablet_proximity, - tablet_ax, tablet_ay, tablet_az); + if ((tablet_flags & TPS_INVERT) && tablet_pressure > 0) { + tablet_buttons |= 2; + eraser = 1; + } else if (eraser) { + tablet_buttons &= ~2; + eraser = 0; + } + if (tablet_x < 0) + return; + inputdevice_tablet (tablet_x, tablet_y, tablet_z, tablet_pressure, tablet_buttons, tablet_proximity, + tablet_ax, tablet_ay, tablet_az); } void send_tablet_proximity (int inproxi) { - if (tablet_proximity == inproxi) - return; - tablet_proximity = inproxi; - if (!tablet_proximity) { - tablet_flags &= ~TPS_INVERT; - } - tablet_send (); + if (tablet_proximity == inproxi) + return; + tablet_proximity = inproxi; + if (!tablet_proximity) { + tablet_flags &= ~TPS_INVERT; + } + tablet_send (); } void send_tablet (int x, int y, int z, int pres, uae_u32 buttons, int flags, int ax, int ay, int az, int rx, int ry, int rz, RECT *r) { - //write_log (L"%d %d %d (%d,%d,%d), %08X %d\n", x, y, pres, ax, ay, az, buttons, proxi); - if (axmax > 0) - ax = ax * 255 / axmax; - else - ax = 0; - if (aymax > 0) - ay = ay * 255 / aymax; - else - ay = 0; - if (azmax > 0) - az = az * 255 / azmax; - else - az = 0; - pres = pres * 255 / maxpres; - - tablet_x = x; - tablet_y = ymax - y; - tablet_z = z; - tablet_pressure = pres; - tablet_buttons = buttons; - tablet_ax = abs (ax); - tablet_ay = abs (ay); - tablet_az = abs (az); - tablet_flags = flags; - - tablet_send (); + //write_log (L"%d %d %d (%d,%d,%d), %08X %d\n", x, y, pres, ax, ay, az, buttons, proxi); + if (axmax > 0) + ax = ax * 255 / axmax; + else + ax = 0; + if (aymax > 0) + ay = ay * 255 / aymax; + else + ay = 0; + if (azmax > 0) + az = az * 255 / azmax; + else + az = 0; + pres = pres * 255 / maxpres; + + tablet_x = x; + tablet_y = ymax - y; + tablet_z = z; + tablet_pressure = pres; + tablet_buttons = buttons; + tablet_ax = abs (ax); + tablet_ay = abs (ay); + tablet_az = abs (az); + tablet_flags = flags; + + tablet_send (); } static int gettabletres (AXIS *a) { - FIX32 r = a->axResolution; - switch (a->axUnits) - { - case TU_INCHES: - return r >> 16; - case TU_CENTIMETERS: - return (int)(((r / 65536.0) / 2.54) + 0.5); - default: - return -1; - } + FIX32 r = a->axResolution; + switch (a->axUnits) + { + case TU_INCHES: + return r >> 16; + case TU_CENTIMETERS: + return (int)(((r / 65536.0) / 2.54) + 0.5); + default: + return -1; + } } void *open_tablet (HWND hwnd) { - LOGCONTEXT lc; - AXIS tx = { 0 }, ty = { 0 }, tz = { 0 }; - AXIS pres = { 0 }; - int xm, ym, zm; - - if (!tablet) - return 0; - xmax = -1; - ymax = -1; - zmax = -1; - WTInfo (WTI_DEFCONTEXT, 0, &lc); - WTInfo (WTI_DEVICES, DVC_X, &tx); - WTInfo (WTI_DEVICES, DVC_Y, &ty); - WTInfo (WTI_DEVICES, DVC_NPRESSURE, &pres); - WTInfo (WTI_DEVICES, DVC_XMARGIN, &xm); - WTInfo (WTI_DEVICES, DVC_YMARGIN, &ym); - WTInfo (WTI_DEVICES, DVC_ZMARGIN, &zm); - xmax = tx.axMax; - ymax = ty.axMax; - if (WTInfo (WTI_DEVICES, DVC_Z, &tz)) - zmax = tz.axMax; - lc.lcOptions |= CXO_MESSAGES; - lc.lcPktData = PACKETDATA; - lc.lcPktMode = PACKETMODE; - lc.lcMoveMask = PACKETDATA; - lc.lcBtnUpMask = lc.lcBtnDnMask; - lc.lcInExtX = tx.axMax; - lc.lcInExtY = ty.axMax; - if (zmax > 0) - lc.lcInExtZ = tz.axMax; - write_log (L"Tablet '%s' parameters\n", tabletname); - write_log (L"Xmax=%d,Ymax=%d,Zmax=%d\n", xmax, ymax, zmax); - write_log (L"Xres=%.1f:%d,Yres=%.1f:%d,Zres=%.1f:%d\n", - tx.axResolution / 65536.0, tx.axUnits, ty.axResolution / 65536.0, ty.axUnits, tz.axResolution / 65536.0, tz.axUnits); - write_log (L"Xrotmax=%d,Yrotmax=%d,Zrotmax=%d\n", axmax, aymax, azmax); - write_log (L"PressureMin=%d,PressureMax=%d\n", pres.axMin, pres.axMax); - maxpres = pres.axMax; - xres = gettabletres (&tx); - yres = gettabletres (&ty); - tablet_proximity = -1; - tablet_x = -1; - inputdevice_tablet_info (xmax, ymax, zmax, axmax, aymax, azmax, xres, yres); - return WTOpen (hwnd, &lc, TRUE); + LOGCONTEXT lc; + AXIS tx = { 0 }, ty = { 0 }, tz = { 0 }; + AXIS pres = { 0 }; + int xm, ym, zm; + + if (!tablet) + return 0; + xmax = -1; + ymax = -1; + zmax = -1; + WTInfo (WTI_DEFCONTEXT, 0, &lc); + WTInfo (WTI_DEVICES, DVC_X, &tx); + WTInfo (WTI_DEVICES, DVC_Y, &ty); + WTInfo (WTI_DEVICES, DVC_NPRESSURE, &pres); + WTInfo (WTI_DEVICES, DVC_XMARGIN, &xm); + WTInfo (WTI_DEVICES, DVC_YMARGIN, &ym); + WTInfo (WTI_DEVICES, DVC_ZMARGIN, &zm); + xmax = tx.axMax; + ymax = ty.axMax; + if (WTInfo (WTI_DEVICES, DVC_Z, &tz)) + zmax = tz.axMax; + lc.lcOptions |= CXO_MESSAGES; + lc.lcPktData = PACKETDATA; + lc.lcPktMode = PACKETMODE; + lc.lcMoveMask = PACKETDATA; + lc.lcBtnUpMask = lc.lcBtnDnMask; + lc.lcInExtX = tx.axMax; + lc.lcInExtY = ty.axMax; + if (zmax > 0) + lc.lcInExtZ = tz.axMax; + write_log (L"Tablet '%s' parameters\n", tabletname); + write_log (L"Xmax=%d,Ymax=%d,Zmax=%d\n", xmax, ymax, zmax); + write_log (L"Xres=%.1f:%d,Yres=%.1f:%d,Zres=%.1f:%d\n", + tx.axResolution / 65536.0, tx.axUnits, ty.axResolution / 65536.0, ty.axUnits, tz.axResolution / 65536.0, tz.axUnits); + write_log (L"Xrotmax=%d,Yrotmax=%d,Zrotmax=%d\n", axmax, aymax, azmax); + write_log (L"PressureMin=%d,PressureMax=%d\n", pres.axMin, pres.axMax); + maxpres = pres.axMax; + xres = gettabletres (&tx); + yres = gettabletres (&ty); + tablet_proximity = -1; + tablet_x = -1; + inputdevice_tablet_info (xmax, ymax, zmax, axmax, aymax, azmax, xres, yres); + return WTOpen (hwnd, &lc, TRUE); } int close_tablet (void *ctx) { - if (ctx != NULL) - WTClose (ctx); - ctx = NULL; - if (!tablet) - return 0; - return 1; + if (ctx != NULL) + WTClose (ctx); + ctx = NULL; + if (!tablet) + return 0; + return 1; } int is_tablet (void) { - return tablet ? 1 : 0; + return tablet ? 1 : 0; } static int initialize_tablet (void) { - HANDLE h; - TCHAR name[MAX_DPATH]; - struct tagAXIS ori[3]; - int tilt = 0; + HANDLE h; + TCHAR name[MAX_DPATH]; + struct tagAXIS ori[3]; + int tilt = 0; - h = LoadLibrary (L"wintab32.dll"); - if (h == NULL) { - write_log (L"Tablet: no wintab32.dll\n"); - return 0; - } - FreeLibrary (h); - if (!WTInfo (0, 0, NULL)) { - write_log (L"Tablet: WTInfo() returned failure\n"); - return 0; - } - name[0] = 0; - WTInfo (WTI_DEVICES, DVC_NAME, name); - axmax = aymax = azmax = -1; - tilt = WTInfo (WTI_DEVICES, DVC_ORIENTATION, &ori); - if (tilt) { - if (ori[0].axMax > 0) - axmax = ori[0].axMax; - if (ori[1].axMax > 0) - aymax = ori[1].axMax; - if (ori[2].axMax > 0) - azmax = ori[2].axMax; - } - write_log (L"Tablet '%s' detected\n", name); - tabletname = my_strdup (name); - tablet = TRUE; - return 1; + h = LoadLibrary (L"wintab32.dll"); + if (h == NULL) { + write_log (L"Tablet: no wintab32.dll\n"); + return 0; + } + FreeLibrary (h); + if (!WTInfo (0, 0, NULL)) { + write_log (L"Tablet: WTInfo() returned failure\n"); + return 0; + } + name[0] = 0; + WTInfo (WTI_DEVICES, DVC_NAME, name); + axmax = aymax = azmax = -1; + tilt = WTInfo (WTI_DEVICES, DVC_ORIENTATION, &ori); + if (tilt) { + if (ori[0].axMax > 0) + axmax = ori[0].axMax; + if (ori[1].axMax > 0) + aymax = ori[1].axMax; + if (ori[2].axMax > 0) + azmax = ori[2].axMax; + } + write_log (L"Tablet '%s' detected\n", name); + tabletname = my_strdup (name); + tablet = TRUE; + return 1; } static int initialize_catweasel (void) { - int j, i; - TCHAR tmp[MAX_DPATH]; - struct didata *did; - - if (catweasel_ismouse ()) { - for (i = 0; i < 2 && num_mouse < MAX_INPUT_DEVICES; i++) { - did = di_mouse; - did += num_mouse; - cleardid(did); - did->connection = DIDC_CAT; - did->catweasel = i; - _stprintf (tmp, L"Catweasel mouse"); - did->name = my_strdup (tmp); - did->sortname = my_strdup (tmp); - _stprintf (tmp, L"CWMOUSE%d", i); - did->configname = my_strdup (tmp); - did->buttons = did->buttons_real = 3; - did->axles = 2; - did->axissort[0] = 0; - did->axisname[0] = my_strdup (L"X-Axis"); - did->axissort[1] = 1; - did->axisname[1] = my_strdup (L"Y-Axis"); - for (j = 0; j < did->buttons; j++) { - did->buttonsort[j] = j; - _stprintf (tmp, L"Button %d", j + 1); - did->buttonname[j] = my_strdup (tmp); - } - did->priority = -1; - num_mouse++; - } - } - if (catweasel_isjoystick ()) { - for (i = 0; i < 2 && num_joystick < MAX_INPUT_DEVICES; i++) { - did = di_joystick; - did += num_joystick; - cleardid(did); - did->connection = DIDC_CAT; - did->catweasel = i; - _stprintf (tmp, L"Catweasel joystick"); - did->name = my_strdup (tmp); - did->sortname = my_strdup (tmp); - _stprintf (tmp, L"CWJOY%d", i); - did->configname = my_strdup (tmp); - did->buttons = did->buttons_real =(catweasel_isjoystick() & 0x80) ? 3 : 1; - did->axles = 2; - did->axissort[0] = 0; - did->axisname[0] = my_strdup (L"X-Axis"); - did->axissort[1] = 1; - did->axisname[1] = my_strdup (L"Y-Axis"); - for (j = 0; j < did->buttons; j++) { - did->buttonsort[j] = j; - _stprintf (tmp, L"Button %d", j + 1); - did->buttonname[j] = my_strdup (tmp); - } - did->priority = -1; - fixbuttons (did); - fixthings (did); - num_joystick++; - } - } - return 1; + int j, i; + TCHAR tmp[MAX_DPATH]; + struct didata *did; + + if (catweasel_ismouse ()) { + for (i = 0; i < 2 && num_mouse < MAX_INPUT_DEVICES; i++) { + did = di_mouse; + did += num_mouse; + cleardid(did); + did->connection = DIDC_CAT; + did->catweasel = i; + _stprintf (tmp, L"Catweasel mouse"); + did->name = my_strdup (tmp); + did->sortname = my_strdup (tmp); + _stprintf (tmp, L"CWMOUSE%d", i); + did->configname = my_strdup (tmp); + did->buttons = did->buttons_real = 3; + did->axles = 2; + did->axissort[0] = 0; + did->axisname[0] = my_strdup (L"X-Axis"); + did->axissort[1] = 1; + did->axisname[1] = my_strdup (L"Y-Axis"); + for (j = 0; j < did->buttons; j++) { + did->buttonsort[j] = j; + _stprintf (tmp, L"Button %d", j + 1); + did->buttonname[j] = my_strdup (tmp); + } + did->priority = -1; + num_mouse++; + } + } + if (catweasel_isjoystick ()) { + for (i = 0; i < 2 && num_joystick < MAX_INPUT_DEVICES; i++) { + did = di_joystick; + did += num_joystick; + cleardid(did); + did->connection = DIDC_CAT; + did->catweasel = i; + _stprintf (tmp, L"Catweasel joystick"); + did->name = my_strdup (tmp); + did->sortname = my_strdup (tmp); + _stprintf (tmp, L"CWJOY%d", i); + did->configname = my_strdup (tmp); + did->buttons = did->buttons_real =(catweasel_isjoystick() & 0x80) ? 3 : 1; + did->axles = 2; + did->axissort[0] = 0; + did->axisname[0] = my_strdup (L"X-Axis"); + did->axissort[1] = 1; + did->axisname[1] = my_strdup (L"Y-Axis"); + for (j = 0; j < did->buttons; j++) { + did->buttonsort[j] = j; + _stprintf (tmp, L"Button %d", j + 1); + did->buttonname[j] = my_strdup (tmp); + } + did->priority = -1; + fixbuttons (did); + fixthings (did); + num_joystick++; + } + } + return 1; } @@ -611,812 +611,812 @@ static int initialize_catweasel (void) static int rdpdevice(TCHAR *buf) { - if (!_tcsncmp (RDP_DEVICE1, buf, _tcslen (RDP_DEVICE1))) - return 1; - if (!_tcsncmp (RDP_DEVICE2, buf, _tcslen (RDP_DEVICE2))) - return 1; - return 0; + if (!_tcsncmp (RDP_DEVICE1, buf, _tcslen (RDP_DEVICE1))) + return 1; + if (!_tcsncmp (RDP_DEVICE2, buf, _tcslen (RDP_DEVICE2))) + return 1; + return 0; } static void rawinputfixname (const TCHAR *name, const TCHAR *friendlyname) { - int i, ii, j; - TCHAR tmp[MAX_DPATH]; - - _stprintf (tmp, L"\\\\?\\%s", name); - for (i = 4; i < _tcslen (tmp); i++) { - if (tmp[i] == '\\') - tmp[i] = '#'; - tmp[i] = _totupper (tmp[i]); - } - for (ii = 0; ii < 2; ii++) { - for (i = 0; i < (ii == 0 ? num_mouse : num_keyboard); i++) { - struct didata *did = ii == 0 ? &di_mouse[i] : &di_keyboard[i]; - TCHAR tmp2[MAX_DPATH]; - if (!did->rawinput) - continue; - for (j = 0; j < _tcslen (did->configname); j++) - tmp2[j] = _totupper (did->configname[j]); - tmp2[j] = 0; - if (_tcslen (tmp2) >= _tcslen (tmp) && !_tcsncmp (tmp2, tmp, _tcslen (tmp))) { - xfree (did->name); - xfree (did->sortname); - did->name = my_strdup (friendlyname); - did->sortname = my_strdup (friendlyname); - write_log (L"'%s' ('%s')\n", did->name, did->configname); - } - } - } + int i, ii, j; + TCHAR tmp[MAX_DPATH]; + + _stprintf (tmp, L"\\\\?\\%s", name); + for (i = 4; i < _tcslen (tmp); i++) { + if (tmp[i] == '\\') + tmp[i] = '#'; + tmp[i] = _totupper (tmp[i]); + } + for (ii = 0; ii < 2; ii++) { + for (i = 0; i < (ii == 0 ? num_mouse : num_keyboard); i++) { + struct didata *did = ii == 0 ? &di_mouse[i] : &di_keyboard[i]; + TCHAR tmp2[MAX_DPATH]; + if (!did->rawinput) + continue; + for (j = 0; j < _tcslen (did->configname); j++) + tmp2[j] = _totupper (did->configname[j]); + tmp2[j] = 0; + if (_tcslen (tmp2) >= _tcslen (tmp) && !_tcsncmp (tmp2, tmp, _tcslen (tmp))) { + xfree (did->name); + xfree (did->sortname); + did->name = my_strdup (friendlyname); + did->sortname = my_strdup (friendlyname); + write_log (L"'%s' ('%s')\n", did->name, did->configname); + } + } + } } static void rawinputfriendlynames (void) { - HDEVINFO di; - int i, ii; - - for (ii = 0; ii < 2; ii++) { - di = SetupDiGetClassDevs (ii == 0 ? &GUID_DEVCLASS_MOUSE : &GUID_DEVCLASS_KEYBOARD, NULL, NULL, DIGCF_PRESENT); - if (di != INVALID_HANDLE_VALUE) { - SP_DEVINFO_DATA dd; - dd.cbSize = sizeof dd; - for (i = 0; SetupDiEnumDeviceInfo (di, i, &dd); i++) { - TCHAR buf[MAX_DPATH]; - DWORD size = 0; - if (SetupDiGetDeviceInstanceId (di, &dd, buf, sizeof buf , &size)) { - TCHAR fname[MAX_DPATH]; - DWORD dt; - fname[0] = 0; - size = 0; - if (!SetupDiGetDeviceRegistryProperty (di, &dd, - SPDRP_FRIENDLYNAME, &dt, (PBYTE)fname, sizeof fname, &size)) { - size = 0; - SetupDiGetDeviceRegistryProperty (di, &dd, - SPDRP_DEVICEDESC, &dt, (PBYTE)fname, sizeof fname, &size); - } - if (size > 0 && fname[0]) - rawinputfixname (buf, fname); - } - } - SetupDiDestroyDeviceInfoList (di); - } - } + HDEVINFO di; + int i, ii; + + for (ii = 0; ii < 2; ii++) { + di = SetupDiGetClassDevs (ii == 0 ? &GUID_DEVCLASS_MOUSE : &GUID_DEVCLASS_KEYBOARD, NULL, NULL, DIGCF_PRESENT); + if (di != INVALID_HANDLE_VALUE) { + SP_DEVINFO_DATA dd; + dd.cbSize = sizeof dd; + for (i = 0; SetupDiEnumDeviceInfo (di, i, &dd); i++) { + TCHAR buf[MAX_DPATH]; + DWORD size = 0; + if (SetupDiGetDeviceInstanceId (di, &dd, buf, sizeof buf , &size)) { + TCHAR fname[MAX_DPATH]; + DWORD dt; + fname[0] = 0; + size = 0; + if (!SetupDiGetDeviceRegistryProperty (di, &dd, + SPDRP_FRIENDLYNAME, &dt, (PBYTE)fname, sizeof fname, &size)) { + size = 0; + SetupDiGetDeviceRegistryProperty (di, &dd, + SPDRP_DEVICEDESC, &dt, (PBYTE)fname, sizeof fname, &size); + } + if (size > 0 && fname[0]) + rawinputfixname (buf, fname); + } + } + SetupDiDestroyDeviceInfoList (di); + } + } } static TCHAR *rawkeyboardlabels[256] = { - L"ESCAPE", - L"1",L"2",L"3",L"4",L"5",L"6",L"7",L"8",L"9",L"0", - L"MINUS",L"EQUALS",L"BACK",L"TAB", - L"Q",L"W",L"E",L"R",L"T",L"Y",L"U",L"I",L"O",L"P", - L"LBRACKET",L"RBRACKET",L"RETURN",L"LCONTROL", - L"A",L"S",L"D",L"F",L"G",L"H",L"J",L"K",L"L", - L"SEMICOLON",L"APOSTROPHE",L"GRAVE",L"LSHIFT",L"BACKSLASH", - L"Z",L"X",L"C",L"V",L"B",L"N",L"M", - L"COMMA",L"PERIOD",L"SLASH",L"RSHIFT",L"MULTIPLY",L"LMENU",L"SPACE",L"CAPITAL", - L"F1",L"F2",L"F3",L"F4",L"F5",L"F6",L"F7",L"F8",L"F9",L"F10", - L"NULOCK",L"SCROLL",L"NUMPAD7",L"NUMPAD8",L"NUMPAD9",L"SUBTRACT", - L"NUMPAD4",L"NUMPAD5",L"NUMPAD6",L"ADD",L"NUMPAD1",L"NUMPAD2",L"NUMPAD3",L"NUMPAD0", - L"DECIMAL",NULL,NULL,L"OEM_102",L"F11",L"F12", - L"F13",L"F14",L"F15",L"F16",NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL, - L"NUMPADEQUALS",NULL,NULL, - L"PREVTRACK",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - L"NEXTTRACK",NULL,NULL,L"NUMPADENTER",L"RCONTROL",NULL,NULL, - L"MUTE",L"CALCULATOR",L"PLAYPAUSE",NULL,L"MEDIASTOP", - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - L"VOLUMEDOWN",NULL,L"VOLUMEUP",NULL,L"WEBHOME",L"NUMPADCOMMA",NULL, - L"DIVIDE",NULL,L"SYSRQ",L"RMENU", - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - L"PAUSE",NULL,L"HOME",L"UP",L"PRIOR",NULL,L"LEFT",NULL,L"RIGHT",NULL,L"END", - L"DOWN",L"NEXT",L"INSERT",L"DELETE", - NULL,NULL,NULL,NULL,NULL,NULL,NULL, - L"LWIN",L"RWIN",L"APPS",L"POWER",L"SLEEP", - NULL,NULL,NULL, - L"WAKE",NULL,L"WEBSEARCH",L"WEBFAVORITES",L"WEBREFRESH",L"WEBSTOP", - L"WEBFORWARD",L"WEBBACK",L"MYCOMPUTER",L"MAIL",L"MEDIASELECT", - L"" + L"ESCAPE", + L"1",L"2",L"3",L"4",L"5",L"6",L"7",L"8",L"9",L"0", + L"MINUS",L"EQUALS",L"BACK",L"TAB", + L"Q",L"W",L"E",L"R",L"T",L"Y",L"U",L"I",L"O",L"P", + L"LBRACKET",L"RBRACKET",L"RETURN",L"LCONTROL", + L"A",L"S",L"D",L"F",L"G",L"H",L"J",L"K",L"L", + L"SEMICOLON",L"APOSTROPHE",L"GRAVE",L"LSHIFT",L"BACKSLASH", + L"Z",L"X",L"C",L"V",L"B",L"N",L"M", + L"COMMA",L"PERIOD",L"SLASH",L"RSHIFT",L"MULTIPLY",L"LMENU",L"SPACE",L"CAPITAL", + L"F1",L"F2",L"F3",L"F4",L"F5",L"F6",L"F7",L"F8",L"F9",L"F10", + L"NULOCK",L"SCROLL",L"NUMPAD7",L"NUMPAD8",L"NUMPAD9",L"SUBTRACT", + L"NUMPAD4",L"NUMPAD5",L"NUMPAD6",L"ADD",L"NUMPAD1",L"NUMPAD2",L"NUMPAD3",L"NUMPAD0", + L"DECIMAL",NULL,NULL,L"OEM_102",L"F11",L"F12", + L"F13",L"F14",L"F15",L"F16",NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL, + L"NUMPADEQUALS",NULL,NULL, + L"PREVTRACK",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + L"NEXTTRACK",NULL,NULL,L"NUMPADENTER",L"RCONTROL",NULL,NULL, + L"MUTE",L"CALCULATOR",L"PLAYPAUSE",NULL,L"MEDIASTOP", + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + L"VOLUMEDOWN",NULL,L"VOLUMEUP",NULL,L"WEBHOME",L"NUMPADCOMMA",NULL, + L"DIVIDE",NULL,L"SYSRQ",L"RMENU", + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + L"PAUSE",NULL,L"HOME",L"UP",L"PRIOR",NULL,L"LEFT",NULL,L"RIGHT",NULL,L"END", + L"DOWN",L"NEXT",L"INSERT",L"DELETE", + NULL,NULL,NULL,NULL,NULL,NULL,NULL, + L"LWIN",L"RWIN",L"APPS",L"POWER",L"SLEEP", + NULL,NULL,NULL, + L"WAKE",NULL,L"WEBSEARCH",L"WEBFAVORITES",L"WEBREFRESH",L"WEBSTOP", + L"WEBFORWARD",L"WEBBACK",L"MYCOMPUTER",L"MAIL",L"MEDIASELECT", + L"" }; static int initialize_rawinput (void) { - RAWINPUTDEVICELIST *ridl = 0; - int num = 500, gotnum, i, bufsize, vtmp; - int rnum_mouse, rnum_kb, rnum_raw; - TCHAR *buf = NULL; - int rmouse = 0, rkb = 0; - TCHAR tmp[100]; - - if (no_rawinput) - goto error; - pRegisterRawInputDevices = (REGISTERRAWINPUTDEVICES)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "RegisterRawInputDevices"); - pGetRawInputData = (GETRAWINPUTDATA)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "GetRawInputData"); - pGetRawInputDeviceList = (GETRAWINPUTDEVICELIST)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "GetRawInputDeviceList"); - pGetRawInputDeviceInfo = (GETRAWINPUTDEVICEINFO)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "GetRawInputDeviceInfoW"); - pGetRawInputBuffer = (GETRAWINPUTBUFFER)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "GetRawInputBuffer"); - pDefRawInputProc = (DEFRAWINPUTPROC)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "DefRawInputProc"); - - if (!pRegisterRawInputDevices || !pGetRawInputData || !pGetRawInputDeviceList || - !pGetRawInputDeviceInfo || !pGetRawInputBuffer || !pDefRawInputProc) - goto error; - - bufsize = 10000 * sizeof (TCHAR); - buf = xmalloc (bufsize); - - register_rawinput (); - if (pGetRawInputDeviceList (NULL, &num, sizeof (RAWINPUTDEVICELIST)) != 0) { - write_log (L"RAWINPUT error %08X\n", GetLastError()); - goto error2; - } - write_log (L"RAWINPUT: found %d devices\n", num); - if (num <= 0) - goto error2; - ridl = xcalloc (sizeof (RAWINPUTDEVICELIST), num); - gotnum = pGetRawInputDeviceList (ridl, &num, sizeof (RAWINPUTDEVICELIST)); - if (gotnum <= 0) { - write_log (L"RAWINPUT didn't find any devices\n"); - goto error2; - } - rnum_raw = rnum_mouse = rnum_kb = 0; - for (i = 0; i < gotnum; i++) { - int type = ridl[i].dwType; - HANDLE h = ridl[i].hDevice; - - if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, NULL, &vtmp) == 1) - continue; - if (vtmp >= bufsize) - continue; - if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, buf, &vtmp) == -1) - continue; - if (rdpdevice (buf)) - continue; - if (type == RIM_TYPEMOUSE) - rnum_mouse++; - if (type == RIM_TYPEKEYBOARD) - rnum_kb++; - } - - for (i = 0; i < gotnum; i++) { - HANDLE h = ridl[i].hDevice; - int type = ridl[i].dwType; - - if (type == RIM_TYPEKEYBOARD && !rawkeyboard) - continue; - - if (type == RIM_TYPEKEYBOARD || type == RIM_TYPEMOUSE) { - struct didata *did = type == RIM_TYPEMOUSE ? di_mouse : di_keyboard; - PRID_DEVICE_INFO rdi; - int v, j; - - if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, NULL, &vtmp) == -1) - continue; - if (vtmp >= bufsize) - continue; - if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, buf, &vtmp) == -1) - continue; - - if (did == di_mouse) { - if (rdpdevice (buf)) - continue; - if (num_mouse >= MAX_INPUT_DEVICES - 1) /* leave space for Windows mouse */ - continue; - did += num_mouse; - num_mouse++; - rmouse++; - v = rmouse; - } else if (did == di_keyboard) { + RAWINPUTDEVICELIST *ridl = 0; + int num = 500, gotnum, i, bufsize, vtmp; + int rnum_mouse, rnum_kb, rnum_raw; + TCHAR *buf = NULL; + int rmouse = 0, rkb = 0; + TCHAR tmp[100]; + + if (no_rawinput) + goto error; + pRegisterRawInputDevices = (REGISTERRAWINPUTDEVICES)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "RegisterRawInputDevices"); + pGetRawInputData = (GETRAWINPUTDATA)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "GetRawInputData"); + pGetRawInputDeviceList = (GETRAWINPUTDEVICELIST)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "GetRawInputDeviceList"); + pGetRawInputDeviceInfo = (GETRAWINPUTDEVICEINFO)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "GetRawInputDeviceInfoW"); + pGetRawInputBuffer = (GETRAWINPUTBUFFER)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "GetRawInputBuffer"); + pDefRawInputProc = (DEFRAWINPUTPROC)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "DefRawInputProc"); + + if (!pRegisterRawInputDevices || !pGetRawInputData || !pGetRawInputDeviceList || + !pGetRawInputDeviceInfo || !pGetRawInputBuffer || !pDefRawInputProc) + goto error; + + bufsize = 10000 * sizeof (TCHAR); + buf = xmalloc (bufsize); + + register_rawinput (); + if (pGetRawInputDeviceList (NULL, &num, sizeof (RAWINPUTDEVICELIST)) != 0) { + write_log (L"RAWINPUT error %08X\n", GetLastError()); + goto error2; + } + write_log (L"RAWINPUT: found %d devices\n", num); + if (num <= 0) + goto error2; + ridl = xcalloc (sizeof (RAWINPUTDEVICELIST), num); + gotnum = pGetRawInputDeviceList (ridl, &num, sizeof (RAWINPUTDEVICELIST)); + if (gotnum <= 0) { + write_log (L"RAWINPUT didn't find any devices\n"); + goto error2; + } + rnum_raw = rnum_mouse = rnum_kb = 0; + for (i = 0; i < gotnum; i++) { + int type = ridl[i].dwType; + HANDLE h = ridl[i].hDevice; + + if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, NULL, &vtmp) == 1) + continue; + if (vtmp >= bufsize) + continue; + if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, buf, &vtmp) == -1) + continue; if (rdpdevice (buf)) - continue; - if (rnum_kb < 2) - continue; - if (num_keyboard >= MAX_INPUT_DEVICES - 1) - continue; - did += num_keyboard; - num_keyboard++; - rkb++; - v = rkb; - } - - rnum_raw++; - cleardid (did); - _stprintf (tmp, L"%s", type == RIM_TYPEMOUSE ? L"RAW Mouse" : L"RAW Keyboard"); - did->name = my_strdup (tmp); - did->rawinput = h; - did->connection = DIDC_RAW; - - write_log (L"%p %s: ", h, type == RIM_TYPEMOUSE ? L"mouse" : L"keyboard"); - did->sortname = my_strdup (buf); - write_log (L"'%s'\n", buf); - did->configname = my_strdup (buf); - rdi = (PRID_DEVICE_INFO)buf; - memset (rdi, 0, sizeof (RID_DEVICE_INFO)); - rdi->cbSize = sizeof (RID_DEVICE_INFO); - if (pGetRawInputDeviceInfo (h, RIDI_DEVICEINFO, NULL, &vtmp) == -1) - continue; - if (vtmp >= bufsize) - continue; - if (pGetRawInputDeviceInfo (h, RIDI_DEVICEINFO, buf, &vtmp) == -1) - continue; - - if (type == RIM_TYPEMOUSE) { - PRID_DEVICE_INFO_MOUSE rdim = &rdi->mouse; - write_log (L"id=%d buttons=%d hw=%d rate=%d\n", - rdim->dwId, rdim->dwNumberOfButtons, rdim->fHasHorizontalWheel, rdim->dwSampleRate); - if (rdim->dwNumberOfButtons >= MAX_MAPPINGS) { - write_log (L"bogus number of buttons, ignored\n"); - continue; - } - did->buttons_real = did->buttons = rdim->dwNumberOfButtons; - for (j = 0; j < did->buttons; j++) { - did->buttonsort[j] = j; - _stprintf (tmp, L"Button %d", j + 1); - did->buttonname[j] = my_strdup (tmp); - } - did->axles = 3; - did->axissort[0] = 0; - did->axisname[0] = my_strdup (L"X-Axis"); - did->axissort[1] = 1; - did->axisname[1] = my_strdup (L"Y-Axis"); - did->axissort[2] = 2; - did->axisname[2] = my_strdup (L"Wheel"); - addplusminus (did, 2); - if (rdim->fHasHorizontalWheel) { - did->axissort[3] = 3; - did->axisname[3] = my_strdup (L"HWheel"); - did->axles++; - addplusminus (did, 3); - } - did->priority = -1; - } else { - int j; - PRID_DEVICE_INFO_KEYBOARD rdik = &rdi->keyboard; - write_log (L"type=%d sub=%d mode=%d fkeys=%d indicators=%d tkeys=%d", - rdik->dwType, rdik->dwSubType, rdik->dwKeyboardMode, - rdik->dwNumberOfFunctionKeys, rdik->dwNumberOfIndicators, rdik->dwNumberOfKeysTotal); - j = 0; - for (i = 0; i < 254; i++) { - TCHAR tmp[100]; - tmp[0] = 0; - if (rawkeyboardlabels[j] != NULL) { - if (rawkeyboardlabels[j][0]) { - _tcscpy (tmp, rawkeyboardlabels[j]); - j++; + continue; + if (type == RIM_TYPEMOUSE) + rnum_mouse++; + if (type == RIM_TYPEKEYBOARD) + rnum_kb++; + } + + for (i = 0; i < gotnum; i++) { + HANDLE h = ridl[i].hDevice; + int type = ridl[i].dwType; + + if (type == RIM_TYPEKEYBOARD && !rawkeyboard) + continue; + + if (type == RIM_TYPEKEYBOARD || type == RIM_TYPEMOUSE) { + struct didata *did = type == RIM_TYPEMOUSE ? di_mouse : di_keyboard; + PRID_DEVICE_INFO rdi; + int v, j; + + if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, NULL, &vtmp) == -1) + continue; + if (vtmp >= bufsize) + continue; + if (pGetRawInputDeviceInfo (h, RIDI_DEVICENAME, buf, &vtmp) == -1) + continue; + + if (did == di_mouse) { + if (rdpdevice (buf)) + continue; + if (num_mouse >= MAX_INPUT_DEVICES - 1) /* leave space for Windows mouse */ + continue; + did += num_mouse; + num_mouse++; + rmouse++; + v = rmouse; + } else if (did == di_keyboard) { + if (rdpdevice (buf)) + continue; + if (rnum_kb < 2) + continue; + if (num_keyboard >= MAX_INPUT_DEVICES - 1) + continue; + did += num_keyboard; + num_keyboard++; + rkb++; + v = rkb; + } + + rnum_raw++; + cleardid (did); + _stprintf (tmp, L"%s", type == RIM_TYPEMOUSE ? L"RAW Mouse" : L"RAW Keyboard"); + did->name = my_strdup (tmp); + did->rawinput = h; + did->connection = DIDC_RAW; + + write_log (L"%p %s: ", h, type == RIM_TYPEMOUSE ? L"mouse" : L"keyboard"); + did->sortname = my_strdup (buf); + write_log (L"'%s'\n", buf); + did->configname = my_strdup (buf); + rdi = (PRID_DEVICE_INFO)buf; + memset (rdi, 0, sizeof (RID_DEVICE_INFO)); + rdi->cbSize = sizeof (RID_DEVICE_INFO); + if (pGetRawInputDeviceInfo (h, RIDI_DEVICEINFO, NULL, &vtmp) == -1) + continue; + if (vtmp >= bufsize) + continue; + if (pGetRawInputDeviceInfo (h, RIDI_DEVICEINFO, buf, &vtmp) == -1) + continue; + + if (type == RIM_TYPEMOUSE) { + PRID_DEVICE_INFO_MOUSE rdim = &rdi->mouse; + write_log (L"id=%d buttons=%d hw=%d rate=%d\n", + rdim->dwId, rdim->dwNumberOfButtons, rdim->fHasHorizontalWheel, rdim->dwSampleRate); + if (rdim->dwNumberOfButtons >= MAX_MAPPINGS) { + write_log (L"bogus number of buttons, ignored\n"); + continue; + } + did->buttons_real = did->buttons = rdim->dwNumberOfButtons; + for (j = 0; j < did->buttons; j++) { + did->buttonsort[j] = j; + _stprintf (tmp, L"Button %d", j + 1); + did->buttonname[j] = my_strdup (tmp); + } + did->axles = 3; + did->axissort[0] = 0; + did->axisname[0] = my_strdup (L"X-Axis"); + did->axissort[1] = 1; + did->axisname[1] = my_strdup (L"Y-Axis"); + did->axissort[2] = 2; + did->axisname[2] = my_strdup (L"Wheel"); + addplusminus (did, 2); + if (rdim->fHasHorizontalWheel) { + did->axissort[3] = 3; + did->axisname[3] = my_strdup (L"HWheel"); + did->axles++; + addplusminus (did, 3); + } + did->priority = -1; + } else { + int j; + PRID_DEVICE_INFO_KEYBOARD rdik = &rdi->keyboard; + write_log (L"type=%d sub=%d mode=%d fkeys=%d indicators=%d tkeys=%d", + rdik->dwType, rdik->dwSubType, rdik->dwKeyboardMode, + rdik->dwNumberOfFunctionKeys, rdik->dwNumberOfIndicators, rdik->dwNumberOfKeysTotal); + j = 0; + for (i = 0; i < 254; i++) { + TCHAR tmp[100]; + tmp[0] = 0; + if (rawkeyboardlabels[j] != NULL) { + if (rawkeyboardlabels[j][0]) { + _tcscpy (tmp, rawkeyboardlabels[j]); + j++; + } + } else { + j++; + } + if (!tmp[0]) + _stprintf (tmp, L"Key %02X", i + 1); + did->buttonname[i] = my_strdup (tmp); + did->buttonmappings[i] = i + 1; + did->buttonsort[i] = i + 1; + did->buttons++; + } } - } else { - j++; - } - if (!tmp[0]) - _stprintf (tmp, L"Key %02X", i + 1); - did->buttonname[i] = my_strdup (tmp); - did->buttonmappings[i] = i + 1; - did->buttonsort[i] = i + 1; - did->buttons++; } - } } - } - rawinputfriendlynames (); + rawinputfriendlynames (); - xfree (ridl); - xfree (buf); - if (rnum_raw > 0) - rawinput_available = 1; - return 1; + xfree (ridl); + xfree (buf); + if (rnum_raw > 0) + rawinput_available = 1; + return 1; error: - write_log (L"RAWINPUT not available or failed to initialize\n"); + write_log (L"RAWINPUT not available or failed to initialize\n"); error2: - xfree (ridl); - xfree (buf); - return 0; + xfree (ridl); + xfree (buf); + return 0; } static void initialize_windowsmouse (void) { - struct didata *did = di_mouse; - TCHAR tmp[100], *name; - int i, j; - - did += num_mouse; - for (i = 0; i < 1; i++) { - if (num_mouse >= MAX_INPUT_DEVICES) - return; - num_mouse++; - name = (i == 0) ? L"Windows mouse" : L"Mousehack mouse"; - did->connection = DIDC_WIN; - did->name = my_strdup (i ? L"Mousehack mouse (Required for tablets)" : L"Windows mouse"); - did->sortname = my_strdup (i ? L"Windowsmouse2" : L"Windowsmouse1"); - did->configname = my_strdup (i ? L"WINMOUSE2" : L"WINMOUSE1"); - did->buttons = GetSystemMetrics (SM_CMOUSEBUTTONS); - if (did->buttons < 3) - did->buttons = 3; - if (did->buttons > 5) - did->buttons = 5; /* no non-direcinput support for >5 buttons */ - did->buttons_real = did->buttons; - for (j = 0; j < did->buttons; j++) { - did->buttonsort[j] = j; - _stprintf (tmp, L"Button %d", j + 1); - did->buttonname[j] = my_strdup (tmp); - } - winmousewheelbuttonstart = did->buttons; - did->axles = os_vista ? 4 : 3; - did->axissort[0] = 0; - did->axisname[0] = my_strdup (L"X-Axis"); - did->axissort[1] = 1; - did->axisname[1] = my_strdup (L"Y-Axis"); - if (did->axles > 2) { - did->axissort[2] = 2; - did->axisname[2] = my_strdup (L"Wheel"); - addplusminus (did, 2); - } - if (did->axles > 3) { - did->axissort[3] = 3; - did->axisname[3] = my_strdup (L"HWheel"); - addplusminus (did, 3); - } - did->priority = 2; - did->wininput = i + 1; - did++; - } + struct didata *did = di_mouse; + TCHAR tmp[100], *name; + int i, j; + + did += num_mouse; + for (i = 0; i < 1; i++) { + if (num_mouse >= MAX_INPUT_DEVICES) + return; + num_mouse++; + name = (i == 0) ? L"Windows mouse" : L"Mousehack mouse"; + did->connection = DIDC_WIN; + did->name = my_strdup (i ? L"Mousehack mouse (Required for tablets)" : L"Windows mouse"); + did->sortname = my_strdup (i ? L"Windowsmouse2" : L"Windowsmouse1"); + did->configname = my_strdup (i ? L"WINMOUSE2" : L"WINMOUSE1"); + did->buttons = GetSystemMetrics (SM_CMOUSEBUTTONS); + if (did->buttons < 3) + did->buttons = 3; + if (did->buttons > 5) + did->buttons = 5; /* no non-direcinput support for >5 buttons */ + did->buttons_real = did->buttons; + for (j = 0; j < did->buttons; j++) { + did->buttonsort[j] = j; + _stprintf (tmp, L"Button %d", j + 1); + did->buttonname[j] = my_strdup (tmp); + } + winmousewheelbuttonstart = did->buttons; + did->axles = os_vista ? 4 : 3; + did->axissort[0] = 0; + did->axisname[0] = my_strdup (L"X-Axis"); + did->axissort[1] = 1; + did->axisname[1] = my_strdup (L"Y-Axis"); + if (did->axles > 2) { + did->axissort[2] = 2; + did->axisname[2] = my_strdup (L"Wheel"); + addplusminus (did, 2); + } + if (did->axles > 3) { + did->axissort[3] = 3; + did->axisname[3] = my_strdup (L"HWheel"); + addplusminus (did, 3); + } + did->priority = 2; + did->wininput = i + 1; + did++; + } } static uae_u8 rawkeystate[256]; static void handle_rawinput_2 (RAWINPUT *raw) { - int i, num; - struct didata *did; + int i, num; + struct didata *did; - if (raw->header.dwType == RIM_TYPEMOUSE) { - PRAWMOUSE rm = &raw->data.mouse; + if (raw->header.dwType == RIM_TYPEMOUSE) { + PRAWMOUSE rm = &raw->data.mouse; - for (num = 0; num < num_mouse; num++) { - did = &di_mouse[num]; - if (did->rawinput == raw->header.hDevice) - break; - } + for (num = 0; num < num_mouse; num++) { + did = &di_mouse[num]; + if (did->rawinput == raw->header.hDevice) + break; + } #ifdef DI_DEBUG_RAWINPUT - write_log (L"HANDLE=%08x %04x %04x %04x %08x %3d %3d %08x M=%d\n", - raw->header.hDevice, - rm->usFlags, - rm->usButtonFlags, - rm->usButtonData, - rm->ulRawButtons, - rm->lLastX, - rm->lLastY, - rm->ulExtraInformation, num < num_mouse ? num + 1 : -1); + write_log (L"HANDLE=%08x %04x %04x %04x %08x %3d %3d %08x M=%d\n", + raw->header.hDevice, + rm->usFlags, + rm->usButtonFlags, + rm->usButtonData, + rm->ulRawButtons, + rm->lLastX, + rm->lLastY, + rm->ulExtraInformation, num < num_mouse ? num + 1 : -1); #endif - if (num == num_mouse) - return; - - if (isfocus () > 0) { - for (i = 0; i < (5 > did->buttons ? did->buttons : 5); i++) { - if (rm->usButtonFlags & (3 << (i * 2))) - setmousebuttonstate (num, i, (rm->usButtonFlags & (1 << (i * 2))) ? 1 : 0); - } - if (did->buttons > 5) { - for (i = 5; i < did->buttons; i++) - setmousebuttonstate (num, i, (rm->ulRawButtons & (1 << i)) ? 1 : 0); - } - if (rm->usButtonFlags & RI_MOUSE_WHEEL) { - int val = (short)rm->usButtonData; - int bnum = did->buttons_real; - setmousestate (num, 2, val, 0); - if (val < 0) - setmousebuttonstate (num, bnum + 0, -1); - else if (val > 0) - setmousebuttonstate (num, bnum + 1, -1); - } - setmousestate (num, 0, rm->lLastX, (rm->usFlags & MOUSE_MOVE_ABSOLUTE) ? 1 : 0); - setmousestate (num, 1, rm->lLastY, (rm->usFlags & MOUSE_MOVE_ABSOLUTE) ? 1 : 0); - } - if (isfocus ()) { - if (did->buttons >= 3 && (rm->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)) { - if (currprefs.win32_middle_mouse) { - if (isfullscreen () > 0) - minimizewindow (); - if (mouseactive) - setmouseactive(0); + if (num == num_mouse) + return; + + if (isfocus () > 0) { + for (i = 0; i < (5 > did->buttons ? did->buttons : 5); i++) { + if (rm->usButtonFlags & (3 << (i * 2))) + setmousebuttonstate (num, i, (rm->usButtonFlags & (1 << (i * 2))) ? 1 : 0); + } + if (did->buttons > 5) { + for (i = 5; i < did->buttons; i++) + setmousebuttonstate (num, i, (rm->ulRawButtons & (1 << i)) ? 1 : 0); + } + if (rm->usButtonFlags & RI_MOUSE_WHEEL) { + int val = (short)rm->usButtonData; + int bnum = did->buttons_real; + setmousestate (num, 2, val, 0); + if (val < 0) + setmousebuttonstate (num, bnum + 0, -1); + else if (val > 0) + setmousebuttonstate (num, bnum + 1, -1); + } + setmousestate (num, 0, rm->lLastX, (rm->usFlags & MOUSE_MOVE_ABSOLUTE) ? 1 : 0); + setmousestate (num, 1, rm->lLastY, (rm->usFlags & MOUSE_MOVE_ABSOLUTE) ? 1 : 0); + } + if (isfocus ()) { + if (did->buttons >= 3 && (rm->usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)) { + if (currprefs.win32_middle_mouse) { + if (isfullscreen () > 0) + minimizewindow (); + if (mouseactive) + setmouseactive(0); + } + } } - } - } - } else if (raw->header.dwType == RIM_TYPEKEYBOARD) { - int istest = inputdevice_istest (); - PRAWKEYBOARD rk = &raw->data.keyboard; - uae_u8 scancode = (rk->MakeCode & 0x7f) | ((rk->Flags & RI_KEY_E0) ? 0x80 : 0x00); - int pressed = (rk->Flags & RI_KEY_BREAK) ? 0 : 1; + } else if (raw->header.dwType == RIM_TYPEKEYBOARD) { + int istest = inputdevice_istest (); + PRAWKEYBOARD rk = &raw->data.keyboard; + uae_u8 scancode = (rk->MakeCode & 0x7f) | ((rk->Flags & RI_KEY_E0) ? 0x80 : 0x00); + int pressed = (rk->Flags & RI_KEY_BREAK) ? 0 : 1; #ifdef DI_DEBUG_RAWINPUT - write_log (L"HANDLE=%x CODE=%x Flags=%x VK=%x MSG=%x EXTRA=%x\n", - raw->header.hDevice, - raw->data.keyboard.MakeCode, - raw->data.keyboard.Flags, - raw->data.keyboard.VKey, - raw->data.keyboard.Message, - raw->data.keyboard.ExtraInformation); + write_log (L"HANDLE=%x CODE=%x Flags=%x VK=%x MSG=%x EXTRA=%x\n", + raw->header.hDevice, + raw->data.keyboard.MakeCode, + raw->data.keyboard.Flags, + raw->data.keyboard.VKey, + raw->data.keyboard.Message, + raw->data.keyboard.ExtraInformation); #endif - if (rk->MakeCode == KEYBOARD_OVERRUN_MAKE_CODE) - return; - if (scancode == 0xaa) - return; + if (rk->MakeCode == KEYBOARD_OVERRUN_MAKE_CODE) + return; + if (scancode == 0xaa) + return; #if 0 - for (num = 0; num < num_keyboard; num++) { - did = &di_keyboard[num]; - if ((did->acquired || rawkeyboard > 0) && did->rawinput == raw->header.hDevice) - break; - } - if (num == num_keyboard) { - if (scancode == DIK_F12 && pressed) { - inputdevice_add_inputcode (AKS_ENTERGUI, 1); - return; - } - return; - } + for (num = 0; num < num_keyboard; num++) { + did = &di_keyboard[num]; + if ((did->acquired || rawkeyboard > 0) && did->rawinput == raw->header.hDevice) + break; + } + if (num == num_keyboard) { + if (scancode == DIK_F12 && pressed) { + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + return; + } + return; + } #endif - num = 0; - if (rawkeystate[scancode] == pressed) - return; - rawkeystate[scancode] = pressed; - if (istest) { - inputdevice_do_keyboard (scancode, pressed); - } else { - scancode = keyhack (scancode, pressed, num); - if (scancode < 0 || isfocus () == 0) - return; - di_keycodes[num][scancode] = pressed; - if (stopoutput == 0) - my_kbd_handler (num, scancode, pressed); + num = 0; + if (rawkeystate[scancode] == pressed) + return; + rawkeystate[scancode] = pressed; + if (istest) { + inputdevice_do_keyboard (scancode, pressed); + } else { + scancode = keyhack (scancode, pressed, num); + if (scancode < 0 || isfocus () == 0) + return; + di_keycodes[num][scancode] = pressed; + if (stopoutput == 0) + my_kbd_handler (num, scancode, pressed); + } } - } } #if 0 static void read_rawinput (void) { - RAWINPUT raw; - int size, ret; + RAWINPUT raw; + int size, ret; - for(;;) { - size = sizeof (RAWINPUT); - ret = pGetRawInputBuffer (&raw, &size, sizeof (RAWINPUTHEADER)); - if (ret <= 0) - return; - handle_rawinput_2 (&raw); - } + for(;;) { + size = sizeof (RAWINPUT); + ret = pGetRawInputBuffer (&raw, &size, sizeof (RAWINPUTHEADER)); + if (ret <= 0) + return; + handle_rawinput_2 (&raw); + } } #endif void handle_rawinput (LPARAM lParam) { - UINT dwSize; - BYTE lpb[1000]; - RAWINPUT *raw; + UINT dwSize; + BYTE lpb[1000]; + RAWINPUT *raw; - if (!rawinput_available) - return; - pGetRawInputData ((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof (RAWINPUTHEADER)); - if (dwSize <= sizeof (lpb)) { - if (pGetRawInputData ((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof (RAWINPUTHEADER)) == dwSize) { - raw = (RAWINPUT*)lpb; - handle_rawinput_2 (raw); - pDefRawInputProc (&raw, 1, sizeof (RAWINPUTHEADER)); + if (!rawinput_available) + return; + pGetRawInputData ((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof (RAWINPUTHEADER)); + if (dwSize <= sizeof (lpb)) { + if (pGetRawInputData ((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof (RAWINPUTHEADER)) == dwSize) { + raw = (RAWINPUT*)lpb; + handle_rawinput_2 (raw); + pDefRawInputProc (&raw, 1, sizeof (RAWINPUTHEADER)); + } } - } } static void unacquire (LPDIRECTINPUTDEVICE8 lpdi, TCHAR *txt) { - HRESULT hr; - if (lpdi) { - hr = IDirectInputDevice8_Unacquire (lpdi); - if (FAILED (hr) && hr != DI_NOEFFECT) - write_log (L"unacquire %s failed, %s\n", txt, DXError (hr)); - } + HRESULT hr; + if (lpdi) { + hr = IDirectInputDevice8_Unacquire (lpdi); + if (FAILED (hr) && hr != DI_NOEFFECT) + write_log (L"unacquire %s failed, %s\n", txt, DXError (hr)); + } } static int acquire (LPDIRECTINPUTDEVICE8 lpdi, TCHAR *txt) { - HRESULT hr = DI_OK; - if (lpdi) { - hr = IDirectInputDevice8_Acquire (lpdi); - if (FAILED (hr) && hr != 0x80070005) { - write_log (L"acquire %s failed, %s\n", txt, DXError (hr)); + HRESULT hr = DI_OK; + if (lpdi) { + hr = IDirectInputDevice8_Acquire (lpdi); + if (FAILED (hr) && hr != 0x80070005) { + write_log (L"acquire %s failed, %s\n", txt, DXError (hr)); + } } - } - return SUCCEEDED (hr) ? 1 : 0; + return SUCCEEDED (hr) ? 1 : 0; } static int setcoop (struct didata *did, DWORD mode, TCHAR *txt) { - HRESULT hr = DI_OK; - if (did->lpdi) { - did->coop = 0; - if (!did->coop && hMainWnd) { - hr = IDirectInputDevice8_SetCooperativeLevel (did->lpdi, hMainWnd, mode); - if (FAILED (hr) && hr != E_NOTIMPL) { - write_log (L"setcooperativelevel %s failed, %s\n", txt, DXError (hr)); - } else { - did->coop = 1; - //write_log (L"cooperativelevel %s set\n", txt); - } + HRESULT hr = DI_OK; + if (did->lpdi) { + did->coop = 0; + if (!did->coop && hMainWnd) { + hr = IDirectInputDevice8_SetCooperativeLevel (did->lpdi, hMainWnd, mode); + if (FAILED (hr) && hr != E_NOTIMPL) { + write_log (L"setcooperativelevel %s failed, %s\n", txt, DXError (hr)); + } else { + did->coop = 1; + //write_log (L"cooperativelevel %s set\n", txt); + } + } } - } - return SUCCEEDED (hr) ? 1 : 0; + return SUCCEEDED (hr) ? 1 : 0; } static void sortdd (struct didata *dd, int num, int type) { - int i, j; - struct didata ddtmp; - - for (i = 0; i < num; i++) { - dd[i].type = type; - for (j = i + 1; j < num; j++) { - dd[j].type = type; - if (dd[i].priority < dd[j].priority || (dd[i].priority == dd[j].priority && _tcscmp (dd[i].sortname, dd[j].sortname) > 0)) { - memcpy (&ddtmp, &dd[i], sizeof (ddtmp)); - memcpy (&dd[i], &dd[j], sizeof (ddtmp)); - memcpy (&dd[j], &ddtmp, sizeof (ddtmp)); - } - } - } - - /* rename duplicate names */ - for (i = 0; i < num; i++) { - for (j = i + 1; j < num; j++) { - if (!_tcscmp (dd[i].name, dd[j].name)) { - int cnt = 1; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - _tcscpy (tmp2, dd[i].name); - for (j = i; j < num; j++) { - if (!_tcscmp (tmp2, dd[j].name)) { - _stprintf (tmp, L"%s [%d]", dd[j].name, cnt++); - xfree (dd[j].name); - dd[j].name = my_strdup (tmp); - } + int i, j; + struct didata ddtmp; + + for (i = 0; i < num; i++) { + dd[i].type = type; + for (j = i + 1; j < num; j++) { + dd[j].type = type; + if (dd[i].priority < dd[j].priority || (dd[i].priority == dd[j].priority && _tcscmp (dd[i].sortname, dd[j].sortname) > 0)) { + memcpy (&ddtmp, &dd[i], sizeof (ddtmp)); + memcpy (&dd[i], &dd[j], sizeof (ddtmp)); + memcpy (&dd[j], &ddtmp, sizeof (ddtmp)); + } + } + } + + /* rename duplicate names */ + for (i = 0; i < num; i++) { + for (j = i + 1; j < num; j++) { + if (!_tcscmp (dd[i].name, dd[j].name)) { + int cnt = 1; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; + _tcscpy (tmp2, dd[i].name); + for (j = i; j < num; j++) { + if (!_tcscmp (tmp2, dd[j].name)) { + _stprintf (tmp, L"%s [%d]", dd[j].name, cnt++); + xfree (dd[j].name); + dd[j].name = my_strdup (tmp); + } + } + break; + } } - break; - } } - } } static void sortobjects (struct didata *did, int *mappings, int *sort, TCHAR **names, int *types, int num) { - int i, j, tmpi; - TCHAR *tmpc; - - for (i = 0; i < num; i++) { - for (j = i + 1; j < num; j++) { - if (sort[i] > sort[j]) { - tmpi = mappings[i]; mappings[i] = mappings[j]; mappings[j] = tmpi; - tmpi = sort[i]; sort[i] = sort[j]; sort[j] = tmpi; - if (types) { - tmpi = types[i]; types[i] = types[j]; types[j] = tmpi; + int i, j, tmpi; + TCHAR *tmpc; + + for (i = 0; i < num; i++) { + for (j = i + 1; j < num; j++) { + if (sort[i] > sort[j]) { + tmpi = mappings[i]; mappings[i] = mappings[j]; mappings[j] = tmpi; + tmpi = sort[i]; sort[i] = sort[j]; sort[j] = tmpi; + if (types) { + tmpi = types[i]; types[i] = types[j]; types[j] = tmpi; + } + tmpc = names[i]; names[i] = names[j]; names[j] = tmpc; + } } - tmpc = names[i]; names[i] = names[j]; names[j] = tmpc; - } } - } #ifdef DI_DEBUG - if (num > 0) { - write_log (L"%s (PGUID=%s):\n", did->name, outGUID (&did->pguid)); - for (i = 0; i < num; i++) - write_log (L"%02X %03d '%s' (%d,%d)\n", mappings[i], mappings[i], names[i], sort[i], types ? types[i] : -1); - } + if (num > 0) { + write_log (L"%s (PGUID=%s):\n", did->name, outGUID (&did->pguid)); + for (i = 0; i < num; i++) + write_log (L"%02X %03d '%s' (%d,%d)\n", mappings[i], mappings[i], names[i], sort[i], types ? types[i] : -1); + } #endif } static int isg (const GUID *g, const GUID *g2, int *dwofs, int v) { - if (!memcmp (g, g2, sizeof (GUID))) { - *dwofs = v; - return 1; - } - return 0; + if (!memcmp (g, g2, sizeof (GUID))) { + *dwofs = v; + return 1; + } + return 0; } static int makesort_joy (const GUID *g, int *dwofs) { - if (isg (g, &GUID_XAxis, dwofs, DIJOFS_X)) return -99; - if (isg (g, &GUID_YAxis, dwofs, DIJOFS_Y)) return -98; - if (isg (g, &GUID_ZAxis, dwofs, DIJOFS_Z)) return -97; - if (isg (g, &GUID_RxAxis, dwofs, DIJOFS_RX)) return -89; - if (isg (g, &GUID_RyAxis, dwofs, DIJOFS_RY)) return -88; - if (isg (g, &GUID_RzAxis, dwofs, DIJOFS_RZ)) return -87; - if (isg (g, &GUID_Slider, dwofs, DIJOFS_SLIDER(0))) return -79; - if (isg (g, &GUID_Slider, dwofs, DIJOFS_SLIDER(1))) return -78; - if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(0))) return -69; - if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(1))) return -68; - if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(2))) return -67; - if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(3))) return -66; - return *dwofs; + if (isg (g, &GUID_XAxis, dwofs, DIJOFS_X)) return -99; + if (isg (g, &GUID_YAxis, dwofs, DIJOFS_Y)) return -98; + if (isg (g, &GUID_ZAxis, dwofs, DIJOFS_Z)) return -97; + if (isg (g, &GUID_RxAxis, dwofs, DIJOFS_RX)) return -89; + if (isg (g, &GUID_RyAxis, dwofs, DIJOFS_RY)) return -88; + if (isg (g, &GUID_RzAxis, dwofs, DIJOFS_RZ)) return -87; + if (isg (g, &GUID_Slider, dwofs, DIJOFS_SLIDER(0))) return -79; + if (isg (g, &GUID_Slider, dwofs, DIJOFS_SLIDER(1))) return -78; + if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(0))) return -69; + if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(1))) return -68; + if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(2))) return -67; + if (isg (g, &GUID_POV, dwofs, DIJOFS_POV(3))) return -66; + return *dwofs; } static int makesort_mouse (const GUID *g, int *dwofs) { - if (isg (g, &GUID_XAxis, dwofs, DIMOFS_X)) return -99; - if (isg (g, &GUID_YAxis, dwofs, DIMOFS_Y)) return -98; - if (isg (g, &GUID_ZAxis, dwofs, DIMOFS_Z)) return -97; - return *dwofs; + if (isg (g, &GUID_XAxis, dwofs, DIMOFS_X)) return -99; + if (isg (g, &GUID_YAxis, dwofs, DIMOFS_Y)) return -98; + if (isg (g, &GUID_ZAxis, dwofs, DIMOFS_Z)) return -97; + return *dwofs; } static BOOL CALLBACK EnumObjectsCallback (const DIDEVICEOBJECTINSTANCE* pdidoi, VOID *pContext) { - struct didata *did = pContext; - int i; - TCHAR tmp[100]; + struct didata *did = pContext; + int i; + TCHAR tmp[100]; #if 0 - if (pdidoi->dwOfs != DIDFT_GETINSTANCE (pdidoi->dwType)) - write_log (L"%x-%s: %x <> %x\n", pdidoi->dwType & 0xff, pdidoi->tszName, - pdidoi->dwOfs, DIDFT_GETINSTANCE (pdidoi->dwType)); + if (pdidoi->dwOfs != DIDFT_GETINSTANCE (pdidoi->dwType)) + write_log (L"%x-%s: %x <> %x\n", pdidoi->dwType & 0xff, pdidoi->tszName, + pdidoi->dwOfs, DIDFT_GETINSTANCE (pdidoi->dwType)); #endif - if (pdidoi->dwType & DIDFT_AXIS) { - int sort = 0; - if (did->axles >= MAX_MAPPINGS) - return DIENUM_CONTINUE; - did->axismappings[did->axles] = DIDFT_GETINSTANCE (pdidoi->dwType); - did->axisname[did->axles] = my_strdup (pdidoi->tszName); - if (did->type == DID_JOYSTICK) - sort = makesort_joy (&pdidoi->guidType, &did->axismappings[did->axles]); - else if (did->type == DID_MOUSE) - sort = makesort_mouse (&pdidoi->guidType, &did->axismappings[did->axles]); - if (sort < 0) { - for (i = 0; i < did->axles; i++) { - if (did->axissort[i] == sort) { - write_log (L"ignored duplicate '%s'\n", pdidoi->tszName); - return DIENUM_CONTINUE; + if (pdidoi->dwType & DIDFT_AXIS) { + int sort = 0; + if (did->axles >= MAX_MAPPINGS) + return DIENUM_CONTINUE; + did->axismappings[did->axles] = DIDFT_GETINSTANCE (pdidoi->dwType); + did->axisname[did->axles] = my_strdup (pdidoi->tszName); + if (did->type == DID_JOYSTICK) + sort = makesort_joy (&pdidoi->guidType, &did->axismappings[did->axles]); + else if (did->type == DID_MOUSE) + sort = makesort_mouse (&pdidoi->guidType, &did->axismappings[did->axles]); + if (sort < 0) { + for (i = 0; i < did->axles; i++) { + if (did->axissort[i] == sort) { + write_log (L"ignored duplicate '%s'\n", pdidoi->tszName); + return DIENUM_CONTINUE; + } + } } - } - } - did->axissort[did->axles] = sort; - did->axles++; - } - if (pdidoi->dwType & DIDFT_POV) { - int numpov = 0; - if (did->axles + 1 >= MAX_MAPPINGS) - return DIENUM_CONTINUE; - for (i = 0; i < did->axles; i++) { - if (did->axistype[i]) { - numpov++; - i++; - } - } - if (did->type == DID_JOYSTICK) - did->axissort[did->axles] = makesort_joy (&pdidoi->guidType, &did->axismappings[did->axles]); - else if (did->type == DID_MOUSE) - did->axissort[did->axles] = makesort_mouse (&pdidoi->guidType, &did->axismappings[did->axles]); - for (i = 0; i < 2; i++) { - did->axismappings[did->axles + i] = DIJOFS_POV(numpov); - _stprintf (tmp, L"%s (%d)", pdidoi->tszName, i + 1); - did->axisname[did->axles + i] = my_strdup (tmp); - did->axissort[did->axles + i] = did->axissort[did->axles]; - did->axistype[did->axles + i] = i + 1; - } - did->axles += 2; - } - - if (pdidoi->dwType & DIDFT_BUTTON) { - if (did->buttons >= MAX_MAPPINGS) - return DIENUM_CONTINUE; - did->buttonname[did->buttons] = my_strdup (pdidoi->tszName); - if (did->type == DID_JOYSTICK) { - //did->buttonmappings[did->buttons] = DIJOFS_BUTTON(DIDFT_GETINSTANCE (pdidoi->dwType)); - did->buttonmappings[did->buttons] = DIJOFS_BUTTON(did->buttons); - did->buttonsort[did->buttons] = makesort_joy (&pdidoi->guidType, &did->buttonmappings[did->buttons]); - } else if (did->type == DID_MOUSE) { - //did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + DIDFT_GETINSTANCE (pdidoi->dwType); - did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + did->buttons; - did->buttonsort[did->buttons] = makesort_mouse (&pdidoi->guidType, &did->buttonmappings[did->buttons]); - } else { - //did->buttonmappings[did->buttons] = pdidoi->dwOfs; - did->buttonmappings[did->buttons] = DIDFT_GETINSTANCE (pdidoi->dwType); + did->axissort[did->axles] = sort; + did->axles++; + } + if (pdidoi->dwType & DIDFT_POV) { + int numpov = 0; + if (did->axles + 1 >= MAX_MAPPINGS) + return DIENUM_CONTINUE; + for (i = 0; i < did->axles; i++) { + if (did->axistype[i]) { + numpov++; + i++; + } + } + if (did->type == DID_JOYSTICK) + did->axissort[did->axles] = makesort_joy (&pdidoi->guidType, &did->axismappings[did->axles]); + else if (did->type == DID_MOUSE) + did->axissort[did->axles] = makesort_mouse (&pdidoi->guidType, &did->axismappings[did->axles]); + for (i = 0; i < 2; i++) { + did->axismappings[did->axles + i] = DIJOFS_POV(numpov); + _stprintf (tmp, L"%s (%d)", pdidoi->tszName, i + 1); + did->axisname[did->axles + i] = my_strdup (tmp); + did->axissort[did->axles + i] = did->axissort[did->axles]; + did->axistype[did->axles + i] = i + 1; + } + did->axles += 2; + } + + if (pdidoi->dwType & DIDFT_BUTTON) { + if (did->buttons >= MAX_MAPPINGS) + return DIENUM_CONTINUE; + did->buttonname[did->buttons] = my_strdup (pdidoi->tszName); + if (did->type == DID_JOYSTICK) { + //did->buttonmappings[did->buttons] = DIJOFS_BUTTON(DIDFT_GETINSTANCE (pdidoi->dwType)); + did->buttonmappings[did->buttons] = DIJOFS_BUTTON(did->buttons); + did->buttonsort[did->buttons] = makesort_joy (&pdidoi->guidType, &did->buttonmappings[did->buttons]); + } else if (did->type == DID_MOUSE) { + //did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + DIDFT_GETINSTANCE (pdidoi->dwType); + did->buttonmappings[did->buttons] = FIELD_OFFSET(DIMOUSESTATE2, rgbButtons) + did->buttons; + did->buttonsort[did->buttons] = makesort_mouse (&pdidoi->guidType, &did->buttonmappings[did->buttons]); + } else { + //did->buttonmappings[did->buttons] = pdidoi->dwOfs; + did->buttonmappings[did->buttons] = DIDFT_GETINSTANCE (pdidoi->dwType); + } + did->buttons++; } - did->buttons++; - } - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } static void trimws (TCHAR *s) { - /* Delete trailing whitespace. */ - int len = _tcslen (s); - while (len > 0 && _tcscspn (s + len - 1, L"\t \r\n") == 0) - s[--len] = '\0'; + /* Delete trailing whitespace. */ + int len = _tcslen (s); + while (len > 0 && _tcscspn (s + len - 1, L"\t \r\n") == 0) + s[--len] = '\0'; } static BOOL CALLBACK di_enumcallback (LPCDIDEVICEINSTANCE lpddi, LPVOID *dd) { - struct didata *did; - int len, type; - TCHAR *typetxt; - TCHAR tmp[100]; - - type = lpddi->dwDevType & 0xff; - if (type == DI8DEVTYPE_MOUSE || type == DI8DEVTYPE_SCREENPOINTER) { - did = di_mouse; - typetxt = L"Mouse"; - } else if (type == DI8DEVTYPE_GAMEPAD || type == DI8DEVTYPE_JOYSTICK || - type == DI8DEVTYPE_FLIGHT || type == DI8DEVTYPE_DRIVING || type == DI8DEVTYPE_1STPERSON) { - did = di_joystick; - typetxt = L"Game controller"; - } else if (type == DI8DEVTYPE_KEYBOARD) { - did = di_keyboard; - typetxt = L"Keyboard"; - } else { - did = NULL; - typetxt = L"Unknown"; - } + struct didata *did; + int len, type; + TCHAR *typetxt; + TCHAR tmp[100]; + + type = lpddi->dwDevType & 0xff; + if (type == DI8DEVTYPE_MOUSE || type == DI8DEVTYPE_SCREENPOINTER) { + did = di_mouse; + typetxt = L"Mouse"; + } else if (type == DI8DEVTYPE_GAMEPAD || type == DI8DEVTYPE_JOYSTICK || + type == DI8DEVTYPE_FLIGHT || type == DI8DEVTYPE_DRIVING || type == DI8DEVTYPE_1STPERSON) { + did = di_joystick; + typetxt = L"Game controller"; + } else if (type == DI8DEVTYPE_KEYBOARD) { + did = di_keyboard; + typetxt = L"Keyboard"; + } else { + did = NULL; + typetxt = L"Unknown"; + } #ifdef DI_DEBUG - write_log (L"I=%s ", outGUID (&lpddi->guidInstance)); - write_log (L"P=%s\n", outGUID (&lpddi->guidProduct)); - write_log (L"'%s' '%s' %08X [%s]\n", lpddi->tszProductName, lpddi->tszInstanceName, lpddi->dwDevType, typetxt); + write_log (L"I=%s ", outGUID (&lpddi->guidInstance)); + write_log (L"P=%s\n", outGUID (&lpddi->guidProduct)); + write_log (L"'%s' '%s' %08X [%s]\n", lpddi->tszProductName, lpddi->tszInstanceName, lpddi->dwDevType, typetxt); #endif - if (did == di_mouse) { - if (num_mouse >= MAX_INPUT_DEVICES) - return DIENUM_CONTINUE; - did += num_mouse; - num_mouse++; - } else if (did == di_joystick) { - if (num_joystick >= MAX_INPUT_DEVICES) - return DIENUM_CONTINUE; - did += num_joystick; - num_joystick++; - } else if (did == di_keyboard) { - if (num_keyboard >= MAX_INPUT_DEVICES) - return DIENUM_CONTINUE; - did += num_keyboard; - num_keyboard++; - } else - return DIENUM_CONTINUE; + if (did == di_mouse) { + if (num_mouse >= MAX_INPUT_DEVICES) + return DIENUM_CONTINUE; + did += num_mouse; + num_mouse++; + } else if (did == di_joystick) { + if (num_joystick >= MAX_INPUT_DEVICES) + return DIENUM_CONTINUE; + did += num_joystick; + num_joystick++; + } else if (did == di_keyboard) { + if (num_keyboard >= MAX_INPUT_DEVICES) + return DIENUM_CONTINUE; + did += num_keyboard; + num_keyboard++; + } else + return DIENUM_CONTINUE; - cleardid (did); - if (lpddi->tszInstanceName) { - len = _tcslen (lpddi->tszInstanceName) + 5 + 1; - did->name = malloc (len * sizeof (TCHAR)); - _tcscpy (did->name, lpddi->tszInstanceName); - } else { - did->name = malloc (100); - _stprintf (did->name, L"[no name]"); - } - trimws (did->name); - _stprintf (tmp, L"%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X %08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", - lpddi->guidProduct.Data1, lpddi->guidProduct.Data2, lpddi->guidProduct.Data3, - lpddi->guidProduct.Data4[0], lpddi->guidProduct.Data4[1], lpddi->guidProduct.Data4[2], lpddi->guidProduct.Data4[3], - lpddi->guidProduct.Data4[4], lpddi->guidProduct.Data4[5], lpddi->guidProduct.Data4[6], lpddi->guidProduct.Data4[7], - lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, - lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], - lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]); - did->configname = my_strdup (tmp); - trimws (did->configname); - did->iguid = lpddi->guidInstance; - did->pguid = lpddi->guidProduct; - did->sortname = my_strdup (did->name); - did->connection = DIDC_DX; - - if (!memcmp (&did->iguid, &GUID_SysKeyboard, sizeof (GUID)) || !memcmp (&did->iguid, &GUID_SysMouse, sizeof (GUID))) { - did->priority = 2; - did->superdevice = 1; - _tcscat (did->name, L" *"); - } - return DIENUM_CONTINUE; + cleardid (did); + if (lpddi->tszInstanceName) { + len = _tcslen (lpddi->tszInstanceName) + 5 + 1; + did->name = malloc (len * sizeof (TCHAR)); + _tcscpy (did->name, lpddi->tszInstanceName); + } else { + did->name = malloc (100); + _stprintf (did->name, L"[no name]"); + } + trimws (did->name); + _stprintf (tmp, L"%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X %08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", + lpddi->guidProduct.Data1, lpddi->guidProduct.Data2, lpddi->guidProduct.Data3, + lpddi->guidProduct.Data4[0], lpddi->guidProduct.Data4[1], lpddi->guidProduct.Data4[2], lpddi->guidProduct.Data4[3], + lpddi->guidProduct.Data4[4], lpddi->guidProduct.Data4[5], lpddi->guidProduct.Data4[6], lpddi->guidProduct.Data4[7], + lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, + lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], + lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]); + did->configname = my_strdup (tmp); + trimws (did->configname); + did->iguid = lpddi->guidInstance; + did->pguid = lpddi->guidProduct; + did->sortname = my_strdup (did->name); + did->connection = DIDC_DX; + + if (!memcmp (&did->iguid, &GUID_SysKeyboard, sizeof (GUID)) || !memcmp (&did->iguid, &GUID_SysMouse, sizeof (GUID))) { + did->priority = 2; + did->superdevice = 1; + _tcscat (did->name, L" *"); + } + return DIENUM_CONTINUE; } extern HINSTANCE hInst; @@ -1425,1217 +1425,1217 @@ static LPDIRECTINPUT8 g_lpdi; static void di_dev_free (struct didata *did) { - if (did->lpdi) - IDirectInputDevice8_Release (did->lpdi); - xfree (did->name); - xfree (did->sortname); - xfree (did->configname); - memset (did, 0, sizeof (struct didata)); + if (did->lpdi) + IDirectInputDevice8_Release (did->lpdi); + xfree (did->name); + xfree (did->sortname); + xfree (did->configname); + memset (did, 0, sizeof (struct didata)); } static int di_do_init (void) { - HRESULT hr; - int i; + HRESULT hr; + int i; - num_mouse = num_joystick = num_keyboard = 0; + num_mouse = num_joystick = num_keyboard = 0; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - di_dev_free (&di_joystick[i]); - di_dev_free (&di_mouse[i]); - di_dev_free (&di_keyboard[i]); - } - hr = DirectInput8Create (hInst, DIRECTINPUT_VERSION, &IID_IDirectInput8, (LPVOID *)&g_lpdi, NULL); - if (FAILED(hr)) { - write_log (L"DirectInput8Create failed, %s\n", DXError (hr)); - gui_message (L"Failed to initialize DirectInput!"); - return 0; - } - if (dinput_enum_all) { - write_log (L"DirectInput enumeration..\n"); - IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_ALL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); - } else { - if (rawkeyboard <= 0) { - write_log (L"DirectInput enumeration.. Keyboards..\n"); - IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_KEYBOARD, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); - } - write_log (L"DirectInput enumeration.. Pointing devices..\n"); - IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_POINTER, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); - write_log (L"DirectInput enumeration.. Game controllers..\n"); - IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_GAMECTRL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); - } - write_log (L"RawInput enumeration..\n"); - initialize_rawinput (); - write_log (L"Windowsmouse initialization..\n"); - initialize_windowsmouse (); - write_log (L"Catweasel joymouse initialization..\n"); - initialize_catweasel (); - write_log (L"wintab tablet initialization..\n"); - initialize_tablet (); - write_log (L"end\n"); - - sortdd (di_joystick, num_joystick, DID_JOYSTICK); - sortdd (di_mouse, num_mouse, DID_MOUSE); - sortdd (di_keyboard, num_keyboard, DID_KEYBOARD); - - return 1; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + di_dev_free (&di_joystick[i]); + di_dev_free (&di_mouse[i]); + di_dev_free (&di_keyboard[i]); + } + hr = DirectInput8Create (hInst, DIRECTINPUT_VERSION, &IID_IDirectInput8, (LPVOID *)&g_lpdi, NULL); + if (FAILED(hr)) { + write_log (L"DirectInput8Create failed, %s\n", DXError (hr)); + gui_message (L"Failed to initialize DirectInput!"); + return 0; + } + if (dinput_enum_all) { + write_log (L"DirectInput enumeration..\n"); + IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_ALL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); + } else { + if (rawkeyboard <= 0) { + write_log (L"DirectInput enumeration.. Keyboards..\n"); + IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_KEYBOARD, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); + } + write_log (L"DirectInput enumeration.. Pointing devices..\n"); + IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_POINTER, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); + write_log (L"DirectInput enumeration.. Game controllers..\n"); + IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_GAMECTRL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); + } + write_log (L"RawInput enumeration..\n"); + initialize_rawinput (); + write_log (L"Windowsmouse initialization..\n"); + initialize_windowsmouse (); + write_log (L"Catweasel joymouse initialization..\n"); + initialize_catweasel (); + write_log (L"wintab tablet initialization..\n"); + initialize_tablet (); + write_log (L"end\n"); + + sortdd (di_joystick, num_joystick, DID_JOYSTICK); + sortdd (di_mouse, num_mouse, DID_MOUSE); + sortdd (di_keyboard, num_keyboard, DID_KEYBOARD); + + return 1; } static int di_init (void) { - if (dd_inited++ > 0) + if (dd_inited++ > 0) + return 1; + if (!di_do_init ()) + return 0; return 1; - if (!di_do_init ()) - return 0; - return 1; } static void di_free (void) { - int i; - if (dd_inited == 0) - return; - dd_inited--; - if (dd_inited > 0) - return; - if (g_lpdi) - IDirectInput8_Release (g_lpdi); - g_lpdi = 0; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - di_dev_free (&di_joystick[i]); - di_dev_free (&di_mouse[i]); - di_dev_free (&di_keyboard[i]); - } + int i; + if (dd_inited == 0) + return; + dd_inited--; + if (dd_inited > 0) + return; + if (g_lpdi) + IDirectInput8_Release (g_lpdi); + g_lpdi = 0; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + di_dev_free (&di_joystick[i]); + di_dev_free (&di_mouse[i]); + di_dev_free (&di_keyboard[i]); + } } static int get_mouse_num (void) { - return num_mouse; + return num_mouse; } static TCHAR *get_mouse_friendlyname (int mouse) { - return di_mouse[mouse].name; + return di_mouse[mouse].name; } static TCHAR *get_mouse_uniquename (int mouse) { - return di_mouse[mouse].configname; + return di_mouse[mouse].configname; } static int get_mouse_widget_num (int mouse) { - return di_mouse[mouse].axles + di_mouse[mouse].buttons; + return di_mouse[mouse].axles + di_mouse[mouse].buttons; } static int get_mouse_widget_first (int mouse, int type) { - switch (type) - { + switch (type) + { case IDEV_WIDGET_BUTTON: - return di_mouse[mouse].axles; + return di_mouse[mouse].axles; case IDEV_WIDGET_AXIS: - return 0; - } - return -1; + return 0; + } + return -1; } static int get_mouse_widget_type (int mouse, int num, TCHAR *name, uae_u32 *code) { - struct didata *did = &di_mouse[mouse]; - - int axles = did->axles; - int buttons = did->buttons; - if (num >= axles && num < axles + buttons) { - if (name) - _tcscpy (name, did->buttonname[num - did->axles]); - return IDEV_WIDGET_BUTTON; - } else if (num < axles) { - if (name) - _tcscpy (name, did->axisname[num]); - return IDEV_WIDGET_AXIS; - } - return IDEV_WIDGET_NONE; + struct didata *did = &di_mouse[mouse]; + + int axles = did->axles; + int buttons = did->buttons; + if (num >= axles && num < axles + buttons) { + if (name) + _tcscpy (name, did->buttonname[num - did->axles]); + return IDEV_WIDGET_BUTTON; + } else if (num < axles) { + if (name) + _tcscpy (name, did->axisname[num]); + return IDEV_WIDGET_AXIS; + } + return IDEV_WIDGET_NONE; } static int init_mouse (void) { - int i; - LPDIRECTINPUTDEVICE8 lpdi; - HRESULT hr; - struct didata *did; - - if (mouse_inited) + int i; + LPDIRECTINPUTDEVICE8 lpdi; + HRESULT hr; + struct didata *did; + + if (mouse_inited) + return 1; + di_init (); + mouse_inited = 1; + for (i = 0; i < num_mouse; i++) { + did = &di_mouse[i]; + if (did->connection == DIDC_DX) { + hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); + if (SUCCEEDED (hr)) { + hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIMouse2); + IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, (void*)did, DIDFT_ALL); + fixbuttons (did); + fixthings_mouse (did); + sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); + sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); + did->lpdi = lpdi; + } else { + write_log (L"mouse %d CreateDevice failed, %s\n", i, DXError (hr)); + } + } + } return 1; - di_init (); - mouse_inited = 1; - for (i = 0; i < num_mouse; i++) { - did = &di_mouse[i]; - if (did->connection == DIDC_DX) { - hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); - if (SUCCEEDED (hr)) { - hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIMouse2); - IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, (void*)did, DIDFT_ALL); - fixbuttons (did); - fixthings_mouse (did); - sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); - sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); - did->lpdi = lpdi; - } else { - write_log (L"mouse %d CreateDevice failed, %s\n", i, DXError (hr)); - } - } - } - return 1; } static void close_mouse (void) { - int i; + int i; - if (!mouse_inited) - return; - mouse_inited = 0; - for (i = 0; i < num_mouse; i++) - di_dev_free (&di_mouse[i]); - supermouse = normalmouse = rawmouse = winmouse = 0; - di_free (); + if (!mouse_inited) + return; + mouse_inited = 0; + for (i = 0; i < num_mouse; i++) + di_dev_free (&di_mouse[i]); + supermouse = normalmouse = rawmouse = winmouse = 0; + di_free (); } static int acquire_mouse (int num, int flags) { - LPDIRECTINPUTDEVICE8 lpdi = di_mouse[num].lpdi; - struct didata *did = &di_mouse[num]; - DIPROPDWORD dipdw; - HRESULT hr; - - unacquire (lpdi, L"mouse"); - if (did->connection == DIDC_DX && lpdi) { - setcoop (&di_mouse[num], flags ? (DISCL_FOREGROUND | DISCL_EXCLUSIVE) : (DISCL_BACKGROUND | DISCL_NONEXCLUSIVE), L"mouse"); - dipdw.diph.dwSize = sizeof (DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DI_BUFFER; - hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); - if (FAILED (hr)) - write_log (L"mouse setpropertry failed, %s\n", DXError (hr)); - di_mouse[num].acquired = acquire (lpdi, L"mouse") ? 1 : -1; - } else { - di_mouse[num].acquired = 1; - } - if (di_mouse[num].acquired > 0) { - if (di_mouse[num].rawinput) - rawmouse++; - else if (di_mouse[num].superdevice) - supermouse++; - else if (di_mouse[num].wininput) { - winmouse++; - winmousenumber = num; - winmousemode = di_mouse[num].wininput == 2; - } else - normalmouse++; - } - register_rawinput (); - return di_mouse[num].acquired > 0 ? 1 : 0; + LPDIRECTINPUTDEVICE8 lpdi = di_mouse[num].lpdi; + struct didata *did = &di_mouse[num]; + DIPROPDWORD dipdw; + HRESULT hr; + + unacquire (lpdi, L"mouse"); + if (did->connection == DIDC_DX && lpdi) { + setcoop (&di_mouse[num], flags ? (DISCL_FOREGROUND | DISCL_EXCLUSIVE) : (DISCL_BACKGROUND | DISCL_NONEXCLUSIVE), L"mouse"); + dipdw.diph.dwSize = sizeof (DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = DI_BUFFER; + hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); + if (FAILED (hr)) + write_log (L"mouse setpropertry failed, %s\n", DXError (hr)); + di_mouse[num].acquired = acquire (lpdi, L"mouse") ? 1 : -1; + } else { + di_mouse[num].acquired = 1; + } + if (di_mouse[num].acquired > 0) { + if (di_mouse[num].rawinput) + rawmouse++; + else if (di_mouse[num].superdevice) + supermouse++; + else if (di_mouse[num].wininput) { + winmouse++; + winmousenumber = num; + winmousemode = di_mouse[num].wininput == 2; + } else + normalmouse++; + } + register_rawinput (); + return di_mouse[num].acquired > 0 ? 1 : 0; } static void unacquire_mouse (int num) { - unacquire (di_mouse[num].lpdi, L"mouse"); - if (di_mouse[num].acquired > 0) { - if (di_mouse[num].rawinput) - rawmouse--; - else if (di_mouse[num].superdevice) - supermouse--; - else if (di_mouse[num].wininput) - winmouse--; - else - normalmouse--; - di_mouse[num].acquired = 0; - } + unacquire (di_mouse[num].lpdi, L"mouse"); + if (di_mouse[num].acquired > 0) { + if (di_mouse[num].rawinput) + rawmouse--; + else if (di_mouse[num].superdevice) + supermouse--; + else if (di_mouse[num].wininput) + winmouse--; + else + normalmouse--; + di_mouse[num].acquired = 0; + } } static void read_mouse (void) { - DIDEVICEOBJECTDATA didod[DI_BUFFER]; - DWORD elements; - HRESULT hr; - int i, j, k; - int fs = isfullscreen () > 0 ? 1 : 0; - int istest = inputdevice_istest (); - - if (IGNOREEVERYTHING) - return; - - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - struct didata *did = &di_mouse[i]; - LPDIRECTINPUTDEVICE8 lpdi = did->lpdi; - if (!did->acquired) - continue; - if (did->connection == DIDC_CAT) { - if (getmousestate (i)) { - int cx, cy, cbuttons; - if (catweasel_read_mouse (did->catweasel, &cx, &cy, &cbuttons)) { - if (cx) - setmousestate (i, 0, cx, 0); - if (cy) - setmousestate (i, 1, cy, 0); - setmousebuttonstate (i, 0, cbuttons & 8); - setmousebuttonstate (i, 1, cbuttons & 4); - setmousebuttonstate (i, 2, cbuttons & 2); + DIDEVICEOBJECTDATA didod[DI_BUFFER]; + DWORD elements; + HRESULT hr; + int i, j, k; + int fs = isfullscreen () > 0 ? 1 : 0; + int istest = inputdevice_istest (); + + if (IGNOREEVERYTHING) + return; + + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + struct didata *did = &di_mouse[i]; + LPDIRECTINPUTDEVICE8 lpdi = did->lpdi; + if (!did->acquired) + continue; + if (did->connection == DIDC_CAT) { + if (getmousestate (i)) { + int cx, cy, cbuttons; + if (catweasel_read_mouse (did->catweasel, &cx, &cy, &cbuttons)) { + if (cx) + setmousestate (i, 0, cx, 0); + if (cy) + setmousestate (i, 1, cy, 0); + setmousebuttonstate (i, 0, cbuttons & 8); + setmousebuttonstate (i, 1, cbuttons & 4); + setmousebuttonstate (i, 2, cbuttons & 2); + } + } + continue; } - } - continue; - } - if (!lpdi || did->connection != DIDC_DX) - continue; - elements = DI_BUFFER; - hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof (DIDEVICEOBJECTDATA), didod, &elements, 0); - if (SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) { - if (supermouse && !did->superdevice) - continue; - for (j = 0; j < elements; j++) { - int dimofs = didod[j].dwOfs; - int data = didod[j].dwData; - int state = (data & 0x80) ? 1 : 0; + if (!lpdi || did->connection != DIDC_DX) + continue; + elements = DI_BUFFER; + hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof (DIDEVICEOBJECTDATA), didod, &elements, 0); + if (SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) { + if (supermouse && !did->superdevice) + continue; + for (j = 0; j < elements; j++) { + int dimofs = didod[j].dwOfs; + int data = didod[j].dwData; + int state = (data & 0x80) ? 1 : 0; #ifdef DI_DEBUG2 - write_log (L"MOUSE: %d OFF=%d DATA=%d STATE=%d\n", i, dimofs, data, state); + write_log (L"MOUSE: %d OFF=%d DATA=%d STATE=%d\n", i, dimofs, data, state); #endif - if (istest || isfocus () > 0) { - for (k = 0; k < did->axles; k++) { - if (did->axismappings[k] == dimofs) - setmousestate (i, k, data, 0); - } - for (k = 0; k < did->buttons; k++) { - if (did->buttonmappings[k] == dimofs) { - if (did->axisparent[k] >= 0) { - int dir = did->axisparentdir[k]; - int bstate = 0; - if (dir) - bstate = data > 0 ? 1 : 0; - else - bstate = data < 0 ? 1 : 0; - if (bstate) - setmousebuttonstate (i, k, -1); - } else { + if (istest || isfocus () > 0) { + for (k = 0; k < did->axles; k++) { + if (did->axismappings[k] == dimofs) + setmousestate (i, k, data, 0); + } + for (k = 0; k < did->buttons; k++) { + if (did->buttonmappings[k] == dimofs) { + if (did->axisparent[k] >= 0) { + int dir = did->axisparentdir[k]; + int bstate = 0; + if (dir) + bstate = data > 0 ? 1 : 0; + else + bstate = data < 0 ? 1 : 0; + if (bstate) + setmousebuttonstate (i, k, -1); + } else { #ifdef SINGLEFILE - if (k == 0) - uae_quit (); + if (k == 0) + uae_quit (); #endif - if ((currprefs.win32_middle_mouse && k != 2) || !(currprefs.win32_middle_mouse)) - setmousebuttonstate (i, k, state); - } + if ((currprefs.win32_middle_mouse && k != 2) || !(currprefs.win32_middle_mouse)) + setmousebuttonstate (i, k, state); + } + } + } + } + if (!istest && isfocus () && currprefs.win32_middle_mouse && dimofs == DIMOFS_BUTTON2 && state) { + if (isfullscreen () > 0) + minimizewindow (); + if (mouseactive) + setmouseactive (0); + } } - } - } - if (!istest && isfocus () && currprefs.win32_middle_mouse && dimofs == DIMOFS_BUTTON2 && state) { - if (isfullscreen () > 0) - minimizewindow (); - if (mouseactive) - setmouseactive (0); + } else if (hr == DIERR_INPUTLOST) { + acquire (lpdi, L"mouse"); + } else if (did->acquired && hr == DIERR_NOTACQUIRED) { + acquire (lpdi, L"mouse"); } - } - } else if (hr == DIERR_INPUTLOST) { - acquire (lpdi, L"mouse"); - } else if (did->acquired && hr == DIERR_NOTACQUIRED) { - acquire (lpdi, L"mouse"); + IDirectInputDevice8_Poll (lpdi); } - IDirectInputDevice8_Poll (lpdi); - } } static int get_mouse_flags (int num) { - if (di_mouse[num].rawinput) - return 0; - if (di_mouse[num].catweasel) - return 0; - if (di_mouse[num].wininput == 1 && !rawinput_available) - return 0; - return 1; + if (di_mouse[num].rawinput) + return 0; + if (di_mouse[num].catweasel) + return 0; + if (di_mouse[num].wininput == 1 && !rawinput_available) + return 0; + return 1; } struct inputdevice_functions inputdevicefunc_mouse = { - init_mouse, close_mouse, acquire_mouse, unacquire_mouse, read_mouse, - get_mouse_num, get_mouse_friendlyname, get_mouse_uniquename, - get_mouse_widget_num, get_mouse_widget_type, - get_mouse_widget_first, - get_mouse_flags + init_mouse, close_mouse, acquire_mouse, unacquire_mouse, read_mouse, + get_mouse_num, get_mouse_friendlyname, get_mouse_uniquename, + get_mouse_widget_num, get_mouse_widget_type, + get_mouse_widget_first, + get_mouse_flags }; static int get_kb_num (void) { - return num_keyboard; + return num_keyboard; } static TCHAR *get_kb_friendlyname (int kb) { - return di_keyboard[kb].name; + return di_keyboard[kb].name; } static TCHAR *get_kb_uniquename (int kb) { - return di_keyboard[kb].configname; + return di_keyboard[kb].configname; } static int get_kb_widget_num (int kb) { - return di_keyboard[kb].buttons; + return di_keyboard[kb].buttons; } static int get_kb_widget_first (int kb, int type) { - return 0; + return 0; } static int get_kb_widget_type (int kb, int num, TCHAR *name, uae_u32 *code) { - if (name) - _stprintf (name, L"[%02X] %s", di_keyboard[kb].buttonmappings[num], di_keyboard[kb].buttonname[num]); - if (code) - *code = di_keyboard[kb].buttonmappings[num]; - return IDEV_WIDGET_KEY; + if (name) + _stprintf (name, L"[%02X] %s", di_keyboard[kb].buttonmappings[num], di_keyboard[kb].buttonname[num]); + if (code) + *code = di_keyboard[kb].buttonmappings[num]; + return IDEV_WIDGET_KEY; } static BYTE ledkeystate[256]; static uae_u32 get_leds (void) { - uae_u32 led = 0; + uae_u32 led = 0; - GetKeyboardState (ledkeystate); - if (ledkeystate[VK_NUMLOCK] & 1) - led |= KBLED_NUMLOCK; - if (ledkeystate[VK_CAPITAL] & 1) - led |= KBLED_CAPSLOCK; - if (ledkeystate[VK_SCROLL] & 1) - led |= KBLED_SCROLLLOCK; + GetKeyboardState (ledkeystate); + if (ledkeystate[VK_NUMLOCK] & 1) + led |= KBLED_NUMLOCK; + if (ledkeystate[VK_CAPITAL] & 1) + led |= KBLED_CAPSLOCK; + if (ledkeystate[VK_SCROLL] & 1) + led |= KBLED_SCROLLLOCK; - if (currprefs.win32_kbledmode) { - oldusbleds = led; - } else if (!currprefs.win32_kbledmode && kbhandle != INVALID_HANDLE_VALUE) { + if (currprefs.win32_kbledmode) { + oldusbleds = led; + } else if (!currprefs.win32_kbledmode && kbhandle != INVALID_HANDLE_VALUE) { #ifdef WINDDK - KEYBOARD_INDICATOR_PARAMETERS InputBuffer; - KEYBOARD_INDICATOR_PARAMETERS OutputBuffer; - ULONG DataLength = sizeof(KEYBOARD_INDICATOR_PARAMETERS); - ULONG ReturnedLength; - - memset (&InputBuffer, 0, sizeof (InputBuffer)); - memset (&OutputBuffer, 0, sizeof (OutputBuffer)); - if (!DeviceIoControl (kbhandle, IOCTL_KEYBOARD_QUERY_INDICATORS, - &InputBuffer, DataLength, &OutputBuffer, DataLength, &ReturnedLength, NULL)) - return 0; - led = 0; - if (OutputBuffer.LedFlags & KEYBOARD_NUM_LOCK_ON) - led |= KBLED_NUMLOCK; - if (OutputBuffer.LedFlags & KEYBOARD_CAPS_LOCK_ON) - led |= KBLED_CAPSLOCK; - if (OutputBuffer.LedFlags & KEYBOARD_SCROLL_LOCK_ON) led - |= KBLED_SCROLLLOCK; + KEYBOARD_INDICATOR_PARAMETERS InputBuffer; + KEYBOARD_INDICATOR_PARAMETERS OutputBuffer; + ULONG DataLength = sizeof(KEYBOARD_INDICATOR_PARAMETERS); + ULONG ReturnedLength; + + memset (&InputBuffer, 0, sizeof (InputBuffer)); + memset (&OutputBuffer, 0, sizeof (OutputBuffer)); + if (!DeviceIoControl (kbhandle, IOCTL_KEYBOARD_QUERY_INDICATORS, + &InputBuffer, DataLength, &OutputBuffer, DataLength, &ReturnedLength, NULL)) + return 0; + led = 0; + if (OutputBuffer.LedFlags & KEYBOARD_NUM_LOCK_ON) + led |= KBLED_NUMLOCK; + if (OutputBuffer.LedFlags & KEYBOARD_CAPS_LOCK_ON) + led |= KBLED_CAPSLOCK; + if (OutputBuffer.LedFlags & KEYBOARD_SCROLL_LOCK_ON) led + |= KBLED_SCROLLLOCK; #endif - } - return led; + } + return led; } static void kbevt (uae_u8 vk, uae_u8 sc) { - if (0) { - INPUT inp[2] = { 0 }; - int i; + if (0) { + INPUT inp[2] = { 0 }; + int i; - for (i = 0; i < 2; i++) { - inp[i].type = INPUT_KEYBOARD; - inp[i].ki.wVk = vk; + for (i = 0; i < 2; i++) { + inp[i].type = INPUT_KEYBOARD; + inp[i].ki.wVk = vk; + } + inp[1].ki.dwFlags |= KEYEVENTF_KEYUP; + SendInput (1, inp, sizeof (INPUT)); + SendInput (1, inp + 1, sizeof (INPUT)); + } else { + keybd_event (vk, 0, 0, 0); + keybd_event (vk, 0, KEYEVENTF_KEYUP, 0); } - inp[1].ki.dwFlags |= KEYEVENTF_KEYUP; - SendInput (1, inp, sizeof (INPUT)); - SendInput (1, inp + 1, sizeof (INPUT)); - } else { - keybd_event (vk, 0, 0, 0); - keybd_event (vk, 0, KEYEVENTF_KEYUP, 0); - } } static void set_leds (uae_u32 led) { - if (currprefs.win32_kbledmode) { - if ((oldusbleds & KBLED_NUMLOCK) != (led & KBLED_NUMLOCK)) - kbevt (VK_NUMLOCK, 0x45); - if ((oldusbleds & KBLED_CAPSLOCK) != (led & KBLED_CAPSLOCK)) - kbevt (VK_CAPITAL, 0x3a); - if ((oldusbleds & KBLED_SCROLLLOCK) != (led & KBLED_SCROLLLOCK)) - kbevt (VK_SCROLL, 0x46); - oldusbleds = led; - } else if (kbhandle != INVALID_HANDLE_VALUE) { + if (currprefs.win32_kbledmode) { + if ((oldusbleds & KBLED_NUMLOCK) != (led & KBLED_NUMLOCK)) + kbevt (VK_NUMLOCK, 0x45); + if ((oldusbleds & KBLED_CAPSLOCK) != (led & KBLED_CAPSLOCK)) + kbevt (VK_CAPITAL, 0x3a); + if ((oldusbleds & KBLED_SCROLLLOCK) != (led & KBLED_SCROLLLOCK)) + kbevt (VK_SCROLL, 0x46); + oldusbleds = led; + } else if (kbhandle != INVALID_HANDLE_VALUE) { #ifdef WINDDK - KEYBOARD_INDICATOR_PARAMETERS InputBuffer; - ULONG DataLength = sizeof(KEYBOARD_INDICATOR_PARAMETERS); - ULONG ReturnedLength; - - memset (&InputBuffer, 0, sizeof (InputBuffer)); - if (led & KBLED_NUMLOCK) - InputBuffer.LedFlags |= KEYBOARD_NUM_LOCK_ON; - if (led & KBLED_CAPSLOCK) - InputBuffer.LedFlags |= KEYBOARD_CAPS_LOCK_ON; - if (led & KBLED_SCROLLLOCK) - InputBuffer.LedFlags |= KEYBOARD_SCROLL_LOCK_ON; - if (!DeviceIoControl (kbhandle, IOCTL_KEYBOARD_SET_INDICATORS, - &InputBuffer, DataLength, NULL, 0, &ReturnedLength, NULL)) - write_log (L"kbleds: DeviceIoControl() failed %d\n", GetLastError()); + KEYBOARD_INDICATOR_PARAMETERS InputBuffer; + ULONG DataLength = sizeof(KEYBOARD_INDICATOR_PARAMETERS); + ULONG ReturnedLength; + + memset (&InputBuffer, 0, sizeof (InputBuffer)); + if (led & KBLED_NUMLOCK) + InputBuffer.LedFlags |= KEYBOARD_NUM_LOCK_ON; + if (led & KBLED_CAPSLOCK) + InputBuffer.LedFlags |= KEYBOARD_CAPS_LOCK_ON; + if (led & KBLED_SCROLLLOCK) + InputBuffer.LedFlags |= KEYBOARD_SCROLL_LOCK_ON; + if (!DeviceIoControl (kbhandle, IOCTL_KEYBOARD_SET_INDICATORS, + &InputBuffer, DataLength, NULL, 0, &ReturnedLength, NULL)) + write_log (L"kbleds: DeviceIoControl() failed %d\n", GetLastError()); #endif - } + } } static void update_leds (void) { - if (!currprefs.keyboard_leds_in_use) - return; - if (newleds != oldusedleds) { - oldusedleds = newleds; - set_leds (newleds); - } + if (!currprefs.keyboard_leds_in_use) + return; + if (newleds != oldusedleds) { + oldusedleds = newleds; + set_leds (newleds); + } } void indicator_leds (int num, int state) { - int i; + int i; - if (!currprefs.keyboard_leds_in_use) - return; - for (i = 0; i < 3; i++) { - if (currprefs.keyboard_leds[i] == num + 1) { - newleds &= ~(1 << i); - if (state) - newleds |= (1 << i); + if (!currprefs.keyboard_leds_in_use) + return; + for (i = 0; i < 3; i++) { + if (currprefs.keyboard_leds[i] == num + 1) { + newleds &= ~(1 << i); + if (state) + newleds |= (1 << i); + } } - } } static int init_kb (void) { - int i; - LPDIRECTINPUTDEVICE8 lpdi; - DIPROPDWORD dipdw; - HRESULT hr; - - if (keyboard_inited) - return 1; - di_init (); - oldusedleds = -1; - keyboard_inited = 1; - for (i = 0; i < num_keyboard; i++) { - struct didata *did = &di_keyboard[i]; - if (did->connection == DIDC_DX) { - hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); - if (SUCCEEDED (hr)) { - hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIKeyboard); - if (FAILED (hr)) - write_log (L"keyboard setdataformat failed, %s\n", DXError (hr)); - memset (&dipdw, 0, sizeof (dipdw)); - dipdw.diph.dwSize = sizeof (DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DI_KBBUFFER; - hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); - if (FAILED (hr)) - write_log (L"keyboard setpropertry failed, %s\n", DXError (hr)); - IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, did, DIDFT_ALL); - sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); - sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); - did->lpdi = lpdi; - } else - write_log (L"keyboard CreateDevice failed, %s\n", DXError (hr)); + int i; + LPDIRECTINPUTDEVICE8 lpdi; + DIPROPDWORD dipdw; + HRESULT hr; + + if (keyboard_inited) + return 1; + di_init (); + oldusedleds = -1; + keyboard_inited = 1; + for (i = 0; i < num_keyboard; i++) { + struct didata *did = &di_keyboard[i]; + if (did->connection == DIDC_DX) { + hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); + if (SUCCEEDED (hr)) { + hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIKeyboard); + if (FAILED (hr)) + write_log (L"keyboard setdataformat failed, %s\n", DXError (hr)); + memset (&dipdw, 0, sizeof (dipdw)); + dipdw.diph.dwSize = sizeof (DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = DI_KBBUFFER; + hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); + if (FAILED (hr)) + write_log (L"keyboard setpropertry failed, %s\n", DXError (hr)); + IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, did, DIDFT_ALL); + sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); + sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); + did->lpdi = lpdi; + } else + write_log (L"keyboard CreateDevice failed, %s\n", DXError (hr)); + } } - } - keyboard_german = 0; - if ((LOWORD(GetKeyboardLayout (0)) & 0x3ff) == 7) - keyboard_german = 1; - return 1; + keyboard_german = 0; + if ((LOWORD(GetKeyboardLayout (0)) & 0x3ff) == 7) + keyboard_german = 1; + return 1; } static void close_kb (void) { - int i; + int i; - if (keyboard_inited == 0) - return; - keyboard_inited = 0; + if (keyboard_inited == 0) + return; + keyboard_inited = 0; - for (i = 0; i < num_keyboard; i++) - di_dev_free (&di_keyboard[i]); - superkb = normalkb = rawkb = 0; - di_free (); + for (i = 0; i < num_keyboard; i++) + di_dev_free (&di_keyboard[i]); + superkb = normalkb = rawkb = 0; + di_free (); } static uae_u32 kb_do_refresh; int ispressed (int key) { - int i; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (di_keycodes[i][key]) - return 1; - } - return 0; + int i; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + if (di_keycodes[i][key]) + return 1; + } + return 0; } void release_keys (void) { - int i, j; + int i, j; - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - for (i = 0; i < MAX_KEYCODES; i++) { - if (di_keycodes[j][i]) { - my_kbd_handler (j, i, 0); - di_keycodes[j][i] = 0; - } + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + for (i = 0; i < MAX_KEYCODES; i++) { + if (di_keycodes[j][i]) { + my_kbd_handler (j, i, 0); + di_keycodes[j][i] = 0; + } + } } - } } static int acquire_kb (int num, int flags) { - LPDIRECTINPUTDEVICE8 lpdi = di_keyboard[num].lpdi; + LPDIRECTINPUTDEVICE8 lpdi = di_keyboard[num].lpdi; - unacquire (lpdi, L"keyboard"); - if (currprefs.keyboard_leds_in_use) { + unacquire (lpdi, L"keyboard"); + if (currprefs.keyboard_leds_in_use) { #ifdef WINDDK - if (!currprefs.win32_kbledmode) { - if (DefineDosDevice (DDD_RAW_TARGET_PATH, L"Kbd", L"\\Device\\KeyboardClass0")) { - kbhandle = CreateFile (L"\\\\.\\Kbd", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (kbhandle == INVALID_HANDLE_VALUE) { - write_log (L"kbled: CreateFile failed, error %d\n", GetLastError()); - currprefs.win32_kbledmode = 1; + if (!currprefs.win32_kbledmode) { + if (DefineDosDevice (DDD_RAW_TARGET_PATH, L"Kbd", L"\\Device\\KeyboardClass0")) { + kbhandle = CreateFile (L"\\\\.\\Kbd", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + if (kbhandle == INVALID_HANDLE_VALUE) { + write_log (L"kbled: CreateFile failed, error %d\n", GetLastError()); + currprefs.win32_kbledmode = 1; + } + } else { + currprefs.win32_kbledmode = 1; + write_log (L"kbled: DefineDosDevice failed, error %d\n", GetLastError()); + } } - } else { - currprefs.win32_kbledmode = 1; - write_log (L"kbled: DefineDosDevice failed, error %d\n", GetLastError()); - } - } #else - currprefs.kbledmode = 1; + currprefs.kbledmode = 1; #endif - oldleds = get_leds (); - if (oldusedleds < 0) - oldusedleds = newleds = oldleds; - set_leds (oldusedleds); - } - - setcoop (&di_keyboard[num], DISCL_NOWINKEY | DISCL_FOREGROUND | DISCL_EXCLUSIVE, L"keyboard"); - kb_do_refresh = ~0; - di_keyboard[num].acquired = -1; - if (acquire (lpdi, L"keyboard")) { - if (di_keyboard[num].rawinput) - rawkb++; - else if (di_keyboard[num].superdevice) - superkb++; - else - normalkb++; - di_keyboard[num].acquired = 1; - } - register_rawinput (); - return di_keyboard[num].acquired > 0 ? 1 : 0; + oldleds = get_leds (); + if (oldusedleds < 0) + oldusedleds = newleds = oldleds; + set_leds (oldusedleds); + } + + setcoop (&di_keyboard[num], DISCL_NOWINKEY | DISCL_FOREGROUND | DISCL_EXCLUSIVE, L"keyboard"); + kb_do_refresh = ~0; + di_keyboard[num].acquired = -1; + if (acquire (lpdi, L"keyboard")) { + if (di_keyboard[num].rawinput) + rawkb++; + else if (di_keyboard[num].superdevice) + superkb++; + else + normalkb++; + di_keyboard[num].acquired = 1; + } + register_rawinput (); + return di_keyboard[num].acquired > 0 ? 1 : 0; } static void unacquire_kb (int num) { - LPDIRECTINPUTDEVICE8 lpdi = di_keyboard[num].lpdi; - - unacquire (lpdi, L"keyboard"); - if (di_keyboard[num].acquired > 0) { - if (di_keyboard[num].rawinput) - rawkb--; - else if (di_keyboard[num].superdevice) - superkb--; - else - normalkb--; - di_keyboard[num].acquired = 0; - } - release_keys (); - - if (currprefs.keyboard_leds_in_use) { - if (oldusedleds >= 0) { - set_leds (oldleds); - oldusedleds = oldleds; + LPDIRECTINPUTDEVICE8 lpdi = di_keyboard[num].lpdi; + + unacquire (lpdi, L"keyboard"); + if (di_keyboard[num].acquired > 0) { + if (di_keyboard[num].rawinput) + rawkb--; + else if (di_keyboard[num].superdevice) + superkb--; + else + normalkb--; + di_keyboard[num].acquired = 0; } + release_keys (); + + if (currprefs.keyboard_leds_in_use) { + if (oldusedleds >= 0) { + set_leds (oldleds); + oldusedleds = oldleds; + } #ifdef WINDDK - if (kbhandle != INVALID_HANDLE_VALUE) { - CloseHandle (kbhandle); - DefineDosDevice (DDD_REMOVE_DEFINITION, L"Kbd", NULL); - kbhandle = INVALID_HANDLE_VALUE; - } + if (kbhandle != INVALID_HANDLE_VALUE) { + CloseHandle (kbhandle); + DefineDosDevice (DDD_REMOVE_DEFINITION, L"Kbd", NULL); + kbhandle = INVALID_HANDLE_VALUE; + } #endif - } + } } static int refresh_kb (LPDIRECTINPUTDEVICE8 lpdi, int num) { - HRESULT hr; - int i; - uae_u8 kc[256]; - - hr = IDirectInputDevice8_GetDeviceState (lpdi, sizeof (kc), kc); - if (SUCCEEDED (hr)) { - for (i = 0; i < sizeof (kc); i++) { - if (i == 0x80) /* USB KB led causes this, better ignore it */ - continue; - if (kc[i] & 0x80) - kc[i] = 1; - else - kc[i] = 0; - if (kc[i] != di_keycodes[num][i]) { - write_log (L"%d: %02X -> %d\n", num, i, kc[i]); - di_keycodes[num][i] = kc[i]; - my_kbd_handler (num, i, kc[i]); - } - } - } else if (hr == DIERR_INPUTLOST) { - acquire_kb (num, 0); + HRESULT hr; + int i; + uae_u8 kc[256]; + + hr = IDirectInputDevice8_GetDeviceState (lpdi, sizeof (kc), kc); + if (SUCCEEDED (hr)) { + for (i = 0; i < sizeof (kc); i++) { + if (i == 0x80) /* USB KB led causes this, better ignore it */ + continue; + if (kc[i] & 0x80) + kc[i] = 1; + else + kc[i] = 0; + if (kc[i] != di_keycodes[num][i]) { + write_log (L"%d: %02X -> %d\n", num, i, kc[i]); + di_keycodes[num][i] = kc[i]; + my_kbd_handler (num, i, kc[i]); + } + } + } else if (hr == DIERR_INPUTLOST) { + acquire_kb (num, 0); + IDirectInputDevice8_Poll (lpdi); + return 0; + } IDirectInputDevice8_Poll (lpdi); - return 0; - } - IDirectInputDevice8_Poll (lpdi); - return 1; + return 1; } static void read_kb (void) { - DIDEVICEOBJECTDATA didod[DI_KBBUFFER]; - DWORD elements; - HRESULT hr; - LPDIRECTINPUTDEVICE8 lpdi; - int i, j; - int istest = inputdevice_istest (); - - if (IGNOREEVERYTHING) - return; - - update_leds (); - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - struct didata *did = &di_keyboard[i]; - if (!did->acquired) - continue; - if (isfocus () == 0) { - if (did->acquired > 0) - unacquire_kb (i); - continue; - } - lpdi = did->lpdi; - if (!lpdi) - continue; - if (kb_do_refresh & (1 << i)) { - if (!refresh_kb (lpdi, i)) - continue; - kb_do_refresh &= ~(1 << i); - } - elements = DI_KBBUFFER; - hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof(DIDEVICEOBJECTDATA), didod, &elements, 0); - if ((SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) && isfocus ()) { - if (did->superdevice && (normalkb || rawkb)) - continue; - for (j = 0; j < elements; j++) { - int scancode = didod[j].dwOfs; - int pressed = (didod[j].dwData & 0x80) ? 1 : 0; - //write_log (L"%d: %02X %d\n", j, scancode, pressed); - if (!istest) - scancode = keyhack (scancode, pressed, i); - if (scancode < 0) - continue; - di_keycodes[i][scancode] = pressed; - if (istest) { - inputdevice_do_keyboard (scancode, pressed); - } else { - if (stopoutput == 0) - my_kbd_handler (i, scancode, pressed); + DIDEVICEOBJECTDATA didod[DI_KBBUFFER]; + DWORD elements; + HRESULT hr; + LPDIRECTINPUTDEVICE8 lpdi; + int i, j; + int istest = inputdevice_istest (); + + if (IGNOREEVERYTHING) + return; + + update_leds (); + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + struct didata *did = &di_keyboard[i]; + if (!did->acquired) + continue; + if (isfocus () == 0) { + if (did->acquired > 0) + unacquire_kb (i); + continue; } - } - } else if (hr == DIERR_INPUTLOST) { - acquire_kb (i, 0); - kb_do_refresh |= 1 << i; - } else if (did->acquired && hr == DIERR_NOTACQUIRED) { - acquire_kb (i, 0); + lpdi = did->lpdi; + if (!lpdi) + continue; + if (kb_do_refresh & (1 << i)) { + if (!refresh_kb (lpdi, i)) + continue; + kb_do_refresh &= ~(1 << i); + } + elements = DI_KBBUFFER; + hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof(DIDEVICEOBJECTDATA), didod, &elements, 0); + if ((SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) && isfocus ()) { + if (did->superdevice && (normalkb || rawkb)) + continue; + for (j = 0; j < elements; j++) { + int scancode = didod[j].dwOfs; + int pressed = (didod[j].dwData & 0x80) ? 1 : 0; + //write_log (L"%d: %02X %d\n", j, scancode, pressed); + if (!istest) + scancode = keyhack (scancode, pressed, i); + if (scancode < 0) + continue; + di_keycodes[i][scancode] = pressed; + if (istest) { + inputdevice_do_keyboard (scancode, pressed); + } else { + if (stopoutput == 0) + my_kbd_handler (i, scancode, pressed); + } + } + } else if (hr == DIERR_INPUTLOST) { + acquire_kb (i, 0); + kb_do_refresh |= 1 << i; + } else if (did->acquired && hr == DIERR_NOTACQUIRED) { + acquire_kb (i, 0); + } + IDirectInputDevice8_Poll (lpdi); } - IDirectInputDevice8_Poll (lpdi); - } #ifdef CATWEASEL - if (isfocus ()) { - uae_u8 kc; - if (stopoutput == 0 && catweasel_read_keyboard (&kc)) - inputdevice_do_keyboard (kc & 0x7f, kc & 0x80); - } + if (isfocus ()) { + uae_u8 kc; + if (stopoutput == 0 && catweasel_read_keyboard (&kc)) + inputdevice_do_keyboard (kc & 0x7f, kc & 0x80); + } #endif } void wait_keyrelease (void) { - stopoutput++; + stopoutput++; #if 0 - int i, j, maxcount = 10, found; - while (maxcount-- > 0) { - read_kb (); - found = 0; - for (j = 0; j < MAX_INPUT_DEVICES; j++) { - for (i = 0; i < MAX_KEYCODES; i++) { - if (di_keycodes[j][i]) - found = 1; - } - } - if (!found) - break; - sleep_millis (10); - } + int i, j, maxcount = 10, found; + while (maxcount-- > 0) { + read_kb (); + found = 0; + for (j = 0; j < MAX_INPUT_DEVICES; j++) { + for (i = 0; i < MAX_KEYCODES; i++) { + if (di_keycodes[j][i]) + found = 1; + } + } + if (!found) + break; + sleep_millis (10); + } #endif - release_keys (); + release_keys (); #if 0 - for (;;) { - int ok = 0, nok = 0; - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - struct didata *did = &di_mouse[i]; - DIMOUSESTATE dis; - LPDIRECTINPUTDEVICE8 lpdi = did->lpdi; - HRESULT hr; - int j; - - if (!lpdi) - continue; - nok++; - hr = IDirectInputDevice8_GetDeviceState (lpdi, sizeof (dis), &dis); - if (SUCCEEDED (hr)) { - for (j = 0; j < 4; j++) { - if (dis.rgbButtons[j] & 0x80) break; + for (;;) { + int ok = 0, nok = 0; + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + struct didata *did = &di_mouse[i]; + DIMOUSESTATE dis; + LPDIRECTINPUTDEVICE8 lpdi = did->lpdi; + HRESULT hr; + int j; + + if (!lpdi) + continue; + nok++; + hr = IDirectInputDevice8_GetDeviceState (lpdi, sizeof (dis), &dis); + if (SUCCEEDED (hr)) { + for (j = 0; j < 4; j++) { + if (dis.rgbButtons[j] & 0x80) break; + } + if (j == 4) ok++; + } else { + ok++; + } } - if (j == 4) ok++; - } else { - ok++; - } - } - if (ok == nok) break; - sleep_millis (10); - } + if (ok == nok) break; + sleep_millis (10); + } #endif - stopoutput--; + stopoutput--; } static int get_kb_flags (int kb) { - return 0; + return 0; } struct inputdevice_functions inputdevicefunc_keyboard = { - init_kb, close_kb, acquire_kb, unacquire_kb, read_kb, - get_kb_num, get_kb_friendlyname, get_kb_uniquename, - get_kb_widget_num, get_kb_widget_type, - get_kb_widget_first, - get_kb_flags + init_kb, close_kb, acquire_kb, unacquire_kb, read_kb, + get_kb_num, get_kb_friendlyname, get_kb_uniquename, + get_kb_widget_num, get_kb_widget_type, + get_kb_widget_first, + get_kb_flags }; static int get_joystick_num (void) { - return num_joystick; + return num_joystick; } static int get_joystick_widget_num (int joy) { - return di_joystick[joy].axles + di_joystick[joy].buttons; + return di_joystick[joy].axles + di_joystick[joy].buttons; } static int get_joystick_widget_type (int joy, int num, TCHAR *name, uae_u32 *code) { - struct didata *did = &di_joystick[joy]; - if (num >= did->axles && num < did->axles + did->buttons) { - if (name) - _tcscpy (name, did->buttonname[num - did->axles]); - return IDEV_WIDGET_BUTTON; - } else if (num < di_joystick[joy].axles) { - if (name) - _tcscpy (name, did->axisname[num]); - return IDEV_WIDGET_AXIS; - } - return IDEV_WIDGET_NONE; + struct didata *did = &di_joystick[joy]; + if (num >= did->axles && num < did->axles + did->buttons) { + if (name) + _tcscpy (name, did->buttonname[num - did->axles]); + return IDEV_WIDGET_BUTTON; + } else if (num < di_joystick[joy].axles) { + if (name) + _tcscpy (name, did->axisname[num]); + return IDEV_WIDGET_AXIS; + } + return IDEV_WIDGET_NONE; } static int get_joystick_widget_first (int joy, int type) { - switch (type) - { + switch (type) + { case IDEV_WIDGET_BUTTON: - return di_joystick[joy].axles; + return di_joystick[joy].axles; case IDEV_WIDGET_AXIS: - return 0; - } - return -1; + return 0; + } + return -1; } static TCHAR *get_joystick_friendlyname (int joy) { - return di_joystick[joy].name; + return di_joystick[joy].name; } static TCHAR *get_joystick_uniquename (int joy) { - return di_joystick[joy].configname; + return di_joystick[joy].configname; } static void read_joystick (void) { - DIDEVICEOBJECTDATA didod[DI_BUFFER]; - LPDIRECTINPUTDEVICE8 lpdi; - DWORD elements; - HRESULT hr; - int i, j, k; - - if (IGNOREEVERYTHING) - return; - - for (i = 0; i < MAX_INPUT_DEVICES; i++) { - struct didata *did = &di_joystick[i]; - if (!did->acquired) - continue; - if (did->connection == DIDC_CAT) { - if (getjoystickstate (i) && isfocus ()) { - /* only read CW state if it is really needed */ - uae_u8 cdir, cbuttons; - if (catweasel_read_joystick (&cdir, &cbuttons)) { - cdir >>= did->catweasel * 4; - cbuttons >>= did->catweasel * 4; - setjoystickstate (i, 0, !(cdir & 1) ? 1 : !(cdir & 2) ? -1 : 0, 0); - setjoystickstate (i, 1, !(cdir & 4) ? 1 : !(cdir & 8) ? -1 : 0, 0); - setjoybuttonstate (i, 0, cbuttons & 8); - setjoybuttonstate (i, 1, cbuttons & 4); - setjoybuttonstate (i, 2, cbuttons & 2); - } - } - continue; - } - lpdi = did->lpdi; - if (!lpdi || did->connection != DIDC_DX) - continue; - elements = DI_BUFFER; - hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof (DIDEVICEOBJECTDATA), didod, &elements, 0); - if ((SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) && isfocus ()) { - for (j = 0; j < elements; j++) { - int dimofs = didod[j].dwOfs; - int data = didod[j].dwData; - int data2 = data; - int state = (data & 0x80) ? 1 : 0; - data -= 32768; - - for (k = 0; k < did->buttons; k++) { - - if (did->axisparent[k] >= 0 && did->buttonmappings[k] == dimofs) { - - int bstate = -1; - int axis = did->axisparent[k]; - int dir = did->axisparentdir[k]; - - if (did->axistype[axis] == 1) { - if (!dir) - bstate = (data2 >= 20250 && data2 <= 33750) ? 1 : 0; - else - bstate = (data2 >= 2250 && data2 <= 15750) ? 1 : 0; - } else if (did->axistype[axis] == 2) { - if (!dir) - bstate = ((data2 >= 29250 && data2 <= 33750) || (data2 >= 0 && data2 <= 6750)) ? 1 : 0; - else - bstate = (data2 >= 11250 && data2 <= 24750) ? 1 : 0; - } else if (did->axistype[axis] == 0) { - if (dir) - bstate = data > 20000 ? 1 : 0; - else - bstate = data < -20000 ? 1 : 0; + DIDEVICEOBJECTDATA didod[DI_BUFFER]; + LPDIRECTINPUTDEVICE8 lpdi; + DWORD elements; + HRESULT hr; + int i, j, k; + + if (IGNOREEVERYTHING) + return; + + for (i = 0; i < MAX_INPUT_DEVICES; i++) { + struct didata *did = &di_joystick[i]; + if (!did->acquired) + continue; + if (did->connection == DIDC_CAT) { + if (getjoystickstate (i) && isfocus ()) { + /* only read CW state if it is really needed */ + uae_u8 cdir, cbuttons; + if (catweasel_read_joystick (&cdir, &cbuttons)) { + cdir >>= did->catweasel * 4; + cbuttons >>= did->catweasel * 4; + setjoystickstate (i, 0, !(cdir & 1) ? 1 : !(cdir & 2) ? -1 : 0, 0); + setjoystickstate (i, 1, !(cdir & 4) ? 1 : !(cdir & 8) ? -1 : 0, 0); + setjoybuttonstate (i, 0, cbuttons & 8); + setjoybuttonstate (i, 1, cbuttons & 4); + setjoybuttonstate (i, 2, cbuttons & 2); + } } - if (bstate >= 0) - setjoybuttonstate (i, k, bstate); + continue; + } + lpdi = did->lpdi; + if (!lpdi || did->connection != DIDC_DX) + continue; + elements = DI_BUFFER; + hr = IDirectInputDevice8_GetDeviceData (lpdi, sizeof (DIDEVICEOBJECTDATA), didod, &elements, 0); + if ((SUCCEEDED (hr) || hr == DI_BUFFEROVERFLOW) && isfocus ()) { + for (j = 0; j < elements; j++) { + int dimofs = didod[j].dwOfs; + int data = didod[j].dwData; + int data2 = data; + int state = (data & 0x80) ? 1 : 0; + data -= 32768; + + for (k = 0; k < did->buttons; k++) { + + if (did->axisparent[k] >= 0 && did->buttonmappings[k] == dimofs) { + + int bstate = -1; + int axis = did->axisparent[k]; + int dir = did->axisparentdir[k]; + + if (did->axistype[axis] == 1) { + if (!dir) + bstate = (data2 >= 20250 && data2 <= 33750) ? 1 : 0; + else + bstate = (data2 >= 2250 && data2 <= 15750) ? 1 : 0; + } else if (did->axistype[axis] == 2) { + if (!dir) + bstate = ((data2 >= 29250 && data2 <= 33750) || (data2 >= 0 && data2 <= 6750)) ? 1 : 0; + else + bstate = (data2 >= 11250 && data2 <= 24750) ? 1 : 0; + } else if (did->axistype[axis] == 0) { + if (dir) + bstate = data > 20000 ? 1 : 0; + else + bstate = data < -20000 ? 1 : 0; + } + if (bstate >= 0) + setjoybuttonstate (i, k, bstate); #ifdef DI_DEBUG2 - write_log (L"AB:NUM=%d OFF=%d AXIS=%d DIR=%d NAME=%s VAL=%d STATE=%d\n", - k, dimofs, axis, dir, did->buttonname[k], data, state); + write_log (L"AB:NUM=%d OFF=%d AXIS=%d DIR=%d NAME=%s VAL=%d STATE=%d\n", + k, dimofs, axis, dir, did->buttonname[k], data, state); #endif - } else if (did->axisparent[k] < 0 && did->buttonmappings[k] == dimofs) { + } else if (did->axisparent[k] < 0 && did->buttonmappings[k] == dimofs) { #ifdef DI_DEBUG2 - write_log (L"B:NUM=%d OFF=%d NAME=%s VAL=%d STATE=%d\n", - k, dimofs, did->buttonname[k], data, state); + write_log (L"B:NUM=%d OFF=%d NAME=%s VAL=%d STATE=%d\n", + k, dimofs, did->buttonname[k], data, state); #endif - setjoybuttonstate (i, k, state); - } - } - - for (k = 0; k < did->axles; k++) { - if (did->axismappings[k] == dimofs) { - if (did->axistype[k] == 1) { - setjoystickstate (i, k, (data2 >= 20250 && data2 <= 33750) ? -1 : (data2 >= 2250 && data2 <= 15750) ? 1 : 0, 1); - } else if (did->axistype[k] == 2) { - setjoystickstate (i, k, ((data2 >= 29250 && data2 <= 33750) || (data2 >= 0 && data2 <= 6750)) ? -1 : (data2 >= 11250 && data2 <= 24750) ? 1 : 0, 1); + setjoybuttonstate (i, k, state); + } + } + + for (k = 0; k < did->axles; k++) { + if (did->axismappings[k] == dimofs) { + if (did->axistype[k] == 1) { + setjoystickstate (i, k, (data2 >= 20250 && data2 <= 33750) ? -1 : (data2 >= 2250 && data2 <= 15750) ? 1 : 0, 1); + } else if (did->axistype[k] == 2) { + setjoystickstate (i, k, ((data2 >= 29250 && data2 <= 33750) || (data2 >= 0 && data2 <= 6750)) ? -1 : (data2 >= 11250 && data2 <= 24750) ? 1 : 0, 1); #ifdef DI_DEBUG2 - write_log (L"P:NUM=%d OFF=%d NAME=%s VAL=%d\n", k, dimofs, did->axisname[k], data2); + write_log (L"P:NUM=%d OFF=%d NAME=%s VAL=%d\n", k, dimofs, did->axisname[k], data2); #endif - } else if (did->axistype[k] == 0) { + } else if (did->axistype[k] == 0) { #ifdef DI_DEBUG2 - if (data < -20000 || data > 20000) - write_log (L"A:NUM=%d OFF=%d NAME=%s VAL=%d\n", k, dimofs, did->axisname[k], data); + if (data < -20000 || data > 20000) + write_log (L"A:NUM=%d OFF=%d NAME=%s VAL=%d\n", k, dimofs, did->axisname[k], data); #endif - setjoystickstate (i, k, data, 32768); - } - } - } + setjoystickstate (i, k, data, 32768); + } + } + } - } + } - } else if (hr == DIERR_INPUTLOST) { - acquire (lpdi, L"joystick"); - } else if (did->acquired && hr == DIERR_NOTACQUIRED) { - acquire (lpdi, L"joystick"); + } else if (hr == DIERR_INPUTLOST) { + acquire (lpdi, L"joystick"); + } else if (did->acquired && hr == DIERR_NOTACQUIRED) { + acquire (lpdi, L"joystick"); + } + IDirectInputDevice8_Poll (lpdi); } - IDirectInputDevice8_Poll (lpdi); - } } static int init_joystick (void) { - int i; - LPDIRECTINPUTDEVICE8 lpdi; - HRESULT hr; - struct didata *did; - - if (joystick_inited) - return 1; - di_init (); - joystick_inited = 1; - for (i = 0; i < num_joystick; i++) { - did = &di_joystick[i]; - if (did->connection == DIDC_DX) { - hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); - if (SUCCEEDED (hr)) { - hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIJoystick); - if (SUCCEEDED (hr)) { - did->lpdi = lpdi; - IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, (void*)did, DIDFT_ALL); - fixbuttons (did); - fixthings (did); - sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); - sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); + int i; + LPDIRECTINPUTDEVICE8 lpdi; + HRESULT hr; + struct didata *did; + + if (joystick_inited) + return 1; + di_init (); + joystick_inited = 1; + for (i = 0; i < num_joystick; i++) { + did = &di_joystick[i]; + if (did->connection == DIDC_DX) { + hr = IDirectInput8_CreateDevice (g_lpdi, &did->iguid, &lpdi, NULL); + if (SUCCEEDED (hr)) { + hr = IDirectInputDevice8_SetDataFormat (lpdi, &c_dfDIJoystick); + if (SUCCEEDED (hr)) { + did->lpdi = lpdi; + IDirectInputDevice8_EnumObjects (lpdi, EnumObjectsCallback, (void*)did, DIDFT_ALL); + fixbuttons (did); + fixthings (did); + sortobjects (did, did->axismappings, did->axissort, did->axisname, did->axistype, did->axles); + sortobjects (did, did->buttonmappings, did->buttonsort, did->buttonname, 0, did->buttons); + } + } else { + write_log (L"joystick createdevice failed, %s\n", DXError (hr)); + } } - } else { - write_log (L"joystick createdevice failed, %s\n", DXError (hr)); - } } - } - return 1; + return 1; } static void close_joystick (void) { - int i; + int i; - if (!joystick_inited) - return; - joystick_inited = 0; - for (i = 0; i < num_joystick; i++) - di_dev_free (&di_joystick[i]); - di_free (); + if (!joystick_inited) + return; + joystick_inited = 0; + for (i = 0; i < num_joystick; i++) + di_dev_free (&di_joystick[i]); + di_free (); } void dinput_window (void) { - int i; - for (i = 0; i < num_joystick; i++) - di_joystick[i].coop = 0; - for (i = 0; i < num_mouse; i++) - di_mouse[i].coop = 0; - for (i = 0; i < num_keyboard; i++) - di_keyboard[i].coop = 0; + int i; + for (i = 0; i < num_joystick; i++) + di_joystick[i].coop = 0; + for (i = 0; i < num_mouse; i++) + di_mouse[i].coop = 0; + for (i = 0; i < num_keyboard; i++) + di_keyboard[i].coop = 0; } static int acquire_joystick (int num, int flags) { - LPDIRECTINPUTDEVICE8 lpdi = di_joystick[num].lpdi; - DIPROPDWORD dipdw; - HRESULT hr; - - unacquire (lpdi, L"joystick"); - if (di_joystick[num].connection == DIDC_DX && lpdi) { - setcoop (&di_joystick[num], flags ? (DISCL_FOREGROUND | DISCL_EXCLUSIVE) : (DISCL_BACKGROUND | DISCL_NONEXCLUSIVE), L"joystick"); - memset (&dipdw, 0, sizeof (dipdw)); - dipdw.diph.dwSize = sizeof (DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DI_BUFFER; - hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); - if (FAILED (hr)) - write_log (L"joystick setproperty failed, %s\n", DXError (hr)); - di_joystick[num].acquired = acquire (lpdi, L"joystick") ? 1 : -1; - } else { - di_joystick[num].acquired = 1; - } - return di_joystick[num].acquired > 0 ? 1 : 0; + LPDIRECTINPUTDEVICE8 lpdi = di_joystick[num].lpdi; + DIPROPDWORD dipdw; + HRESULT hr; + + unacquire (lpdi, L"joystick"); + if (di_joystick[num].connection == DIDC_DX && lpdi) { + setcoop (&di_joystick[num], flags ? (DISCL_FOREGROUND | DISCL_EXCLUSIVE) : (DISCL_BACKGROUND | DISCL_NONEXCLUSIVE), L"joystick"); + memset (&dipdw, 0, sizeof (dipdw)); + dipdw.diph.dwSize = sizeof (DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = DI_BUFFER; + hr = IDirectInputDevice8_SetProperty (lpdi, DIPROP_BUFFERSIZE, &dipdw.diph); + if (FAILED (hr)) + write_log (L"joystick setproperty failed, %s\n", DXError (hr)); + di_joystick[num].acquired = acquire (lpdi, L"joystick") ? 1 : -1; + } else { + di_joystick[num].acquired = 1; + } + return di_joystick[num].acquired > 0 ? 1 : 0; } static void unacquire_joystick (int num) { - unacquire (di_joystick[num].lpdi, L"joystick"); - di_joystick[num].acquired = 0; + unacquire (di_joystick[num].lpdi, L"joystick"); + di_joystick[num].acquired = 0; } static int get_joystick_flags (int num) { - return 0; + return 0; } struct inputdevice_functions inputdevicefunc_joystick = { - init_joystick, close_joystick, acquire_joystick, unacquire_joystick, - read_joystick, get_joystick_num, get_joystick_friendlyname, get_joystick_uniquename, - get_joystick_widget_num, get_joystick_widget_type, - get_joystick_widget_first, - get_joystick_flags + init_joystick, close_joystick, acquire_joystick, unacquire_joystick, + read_joystick, get_joystick_num, get_joystick_friendlyname, get_joystick_uniquename, + get_joystick_widget_num, get_joystick_widget_type, + get_joystick_widget_first, + get_joystick_flags }; int dinput_wmkey (uae_u32 key) { - if (normalkb || superkb || rawkb) + if (normalkb || superkb || rawkb) + return 0; + if (((key >> 16) & 0xff) == 0x58) + return 1; return 0; - if (((key >> 16) & 0xff) == 0x58) - return 1; - return 0; } int input_get_default_mouse (struct uae_input_device *uid, int i, int port) { - struct didata *did; + struct didata *did; - if (i >= num_mouse) + if (i >= num_mouse) + return 0; + did = &di_mouse[i]; + if (did->wininput) + port = 0; + uid[i].eventid[ID_AXIS_OFFSET + 0][0] = port ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; + uid[i].eventid[ID_AXIS_OFFSET + 1][0] = port ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; + uid[i].eventid[ID_AXIS_OFFSET + 2][0] = port ? 0 : INPUTEVENT_MOUSE1_WHEEL; + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; + uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; + uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + if (port == 0) { /* map back and forward to ALT+LCUR and ALT+RCUR */ + if (isrealbutton (did, 3)) { + uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = INPUTEVENT_KEY_ALT_LEFT; + uid[i].eventid[ID_BUTTON_OFFSET + 3][1] = INPUTEVENT_KEY_CURSOR_LEFT; + if (isrealbutton (did, 4)) { + uid[i].eventid[ID_BUTTON_OFFSET + 4][0] = INPUTEVENT_KEY_ALT_LEFT; + uid[i].eventid[ID_BUTTON_OFFSET + 4][1] = INPUTEVENT_KEY_CURSOR_RIGHT; + } + } + } + if (i == 0) + return 1; return 0; - did = &di_mouse[i]; - if (did->wininput) - port = 0; - uid[i].eventid[ID_AXIS_OFFSET + 0][0] = port ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; - uid[i].eventid[ID_AXIS_OFFSET + 1][0] = port ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; - uid[i].eventid[ID_AXIS_OFFSET + 2][0] = port ? 0 : INPUTEVENT_MOUSE1_WHEEL; - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; - uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; - uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - if (port == 0) { /* map back and forward to ALT+LCUR and ALT+RCUR */ - if (isrealbutton (did, 3)) { - uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = INPUTEVENT_KEY_ALT_LEFT; - uid[i].eventid[ID_BUTTON_OFFSET + 3][1] = INPUTEVENT_KEY_CURSOR_LEFT; - if (isrealbutton (did, 4)) { - uid[i].eventid[ID_BUTTON_OFFSET + 4][0] = INPUTEVENT_KEY_ALT_LEFT; - uid[i].eventid[ID_BUTTON_OFFSET + 4][1] = INPUTEVENT_KEY_CURSOR_RIGHT; - } - } - } - if (i == 0) - return 1; - return 0; } int input_get_default_lightpen (struct uae_input_device *uid, int i, int port) { - struct didata *did; + struct didata *did; - if (i >= num_mouse) + if (i >= num_mouse) + return 0; + did = &di_mouse[i]; + if (did->wininput) + port = 0; + uid[i].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_LIGHTPEN_HORIZ; + uid[i].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_LIGHTPEN_VERT; + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + if (i == 0) + return 1; return 0; - did = &di_mouse[i]; - if (did->wininput) - port = 0; - uid[i].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_LIGHTPEN_HORIZ; - uid[i].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_LIGHTPEN_VERT; - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - if (i == 0) - return 1; - return 0; } int input_get_default_joystick (struct uae_input_device *uid, int i, int port, int cd32) { - int j; - struct didata *did; - int h, v; + int j; + struct didata *did; + int h, v; + + if (i >= num_joystick) + return 0; + did = &di_joystick[i]; + if (port >= 2) { + h = port == 3 ? INPUTEVENT_PAR_JOY2_HORIZ : INPUTEVENT_PAR_JOY1_HORIZ; + v = port == 3 ? INPUTEVENT_PAR_JOY2_VERT : INPUTEVENT_PAR_JOY1_VERT; + } else { + h = port ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ;; + v = port ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; + } + uid[i].eventid[ID_AXIS_OFFSET + 0][0] = h; + uid[i].eventid[ID_AXIS_OFFSET + 1][0] = v; - if (i >= num_joystick) + if (port >= 2) { + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port == 3 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON; + } else { + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; + if (isrealbutton (did, 1)) + uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; + if (isrealbutton (did, 2)) + uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + } + + for (j = 2; j < MAX_MAPPINGS - 1; j++) { + int am = did->axismappings[j]; + if (am == DIJOFS_POV(0) || am == DIJOFS_POV(1) || am == DIJOFS_POV(2) || am == DIJOFS_POV(3)) { + uid[i].eventid[ID_AXIS_OFFSET + j + 0][0] = h; + uid[i].eventid[ID_AXIS_OFFSET + j + 1][0] = v; + j++; + } + } + if (cd32) { + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED; + if (isrealbutton (did, 1)) + uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE; + if (isrealbutton (did, 2)) + uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN; + if (isrealbutton (did, 3)) + uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = port ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW; + if (isrealbutton (did, 4)) + uid[i].eventid[ID_BUTTON_OFFSET + 4][0] = port ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD; + if (isrealbutton (did, 5)) + uid[i].eventid[ID_BUTTON_OFFSET + 5][0] = port ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW; + if (isrealbutton (did, 6)) + uid[i].eventid[ID_BUTTON_OFFSET + 6][0] = port ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY; + } + if (i == 0) + return 1; return 0; - did = &di_joystick[i]; - if (port >= 2) { - h = port == 3 ? INPUTEVENT_PAR_JOY2_HORIZ : INPUTEVENT_PAR_JOY1_HORIZ; - v = port == 3 ? INPUTEVENT_PAR_JOY2_VERT : INPUTEVENT_PAR_JOY1_VERT; - } else { - h = port ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ;; - v = port ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; - } - uid[i].eventid[ID_AXIS_OFFSET + 0][0] = h; - uid[i].eventid[ID_AXIS_OFFSET + 1][0] = v; - - if (port >= 2) { - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port == 3 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON; - } else { - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; - if (isrealbutton (did, 1)) - uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; - if (isrealbutton (did, 2)) - uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; - } - - for (j = 2; j < MAX_MAPPINGS - 1; j++) { - int am = did->axismappings[j]; - if (am == DIJOFS_POV(0) || am == DIJOFS_POV(1) || am == DIJOFS_POV(2) || am == DIJOFS_POV(3)) { - uid[i].eventid[ID_AXIS_OFFSET + j + 0][0] = h; - uid[i].eventid[ID_AXIS_OFFSET + j + 1][0] = v; - j++; - } - } - if (cd32) { - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED; - if (isrealbutton (did, 1)) - uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE; - if (isrealbutton (did, 2)) - uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN; - if (isrealbutton (did, 3)) - uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = port ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW; - if (isrealbutton (did, 4)) - uid[i].eventid[ID_BUTTON_OFFSET + 4][0] = port ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD; - if (isrealbutton (did, 5)) - uid[i].eventid[ID_BUTTON_OFFSET + 5][0] = port ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW; - if (isrealbutton (did, 6)) - uid[i].eventid[ID_BUTTON_OFFSET + 6][0] = port ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY; - } - if (i == 0) - return 1; - return 0; } int input_get_default_joystick_analog (struct uae_input_device *uid, int i, int port) { - int j; - struct didata *did; + int j; + struct didata *did; - if (i >= num_joystick) + if (i >= num_joystick) + return 0; + did = &di_joystick[i]; + uid[i].eventid[ID_AXIS_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_HORIZ_POT : INPUTEVENT_JOY1_HORIZ_POT; + uid[i].eventid[ID_AXIS_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_VERT_POT : INPUTEVENT_JOY1_VERT_POT; + uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_LEFT : INPUTEVENT_JOY1_LEFT; + if (isrealbutton (did, 1)) + uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_RIGHT : INPUTEVENT_JOY1_RIGHT; + if (isrealbutton (did, 2)) + uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP; + if (isrealbutton (did, 3)) + uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = port ? INPUTEVENT_JOY2_DOWN : INPUTEVENT_JOY1_DOWN; + for (j = 2; j < MAX_MAPPINGS - 1; j++) { + int am = did->axismappings[j]; + if (am == DIJOFS_POV(0) || am == DIJOFS_POV(1) || am == DIJOFS_POV(2) || am == DIJOFS_POV(3)) { + uid[i].eventid[ID_AXIS_OFFSET + j + 0][0] = port ? INPUTEVENT_JOY2_HORIZ_POT : INPUTEVENT_JOY1_HORIZ_POT; + uid[i].eventid[ID_AXIS_OFFSET + j + 1][0] = port ? INPUTEVENT_JOY2_VERT_POT : INPUTEVENT_JOY1_VERT_POT; + j++; + } + } + if (i == 0) + return 1; return 0; - did = &di_joystick[i]; - uid[i].eventid[ID_AXIS_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_HORIZ_POT : INPUTEVENT_JOY1_HORIZ_POT; - uid[i].eventid[ID_AXIS_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_VERT_POT : INPUTEVENT_JOY1_VERT_POT; - uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_LEFT : INPUTEVENT_JOY1_LEFT; - if (isrealbutton (did, 1)) - uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_RIGHT : INPUTEVENT_JOY1_RIGHT; - if (isrealbutton (did, 2)) - uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP; - if (isrealbutton (did, 3)) - uid[i].eventid[ID_BUTTON_OFFSET + 3][0] = port ? INPUTEVENT_JOY2_DOWN : INPUTEVENT_JOY1_DOWN; - for (j = 2; j < MAX_MAPPINGS - 1; j++) { - int am = did->axismappings[j]; - if (am == DIJOFS_POV(0) || am == DIJOFS_POV(1) || am == DIJOFS_POV(2) || am == DIJOFS_POV(3)) { - uid[i].eventid[ID_AXIS_OFFSET + j + 0][0] = port ? INPUTEVENT_JOY2_HORIZ_POT : INPUTEVENT_JOY1_HORIZ_POT; - uid[i].eventid[ID_AXIS_OFFSET + j + 1][0] = port ? INPUTEVENT_JOY2_VERT_POT : INPUTEVENT_JOY1_VERT_POT; - j++; - } - } - if (i == 0) - return 1; - return 0; } diff --git a/od-win32/direct3d.c b/od-win32/direct3d.c index 342c661d..613468cc 100644 --- a/od-win32/direct3d.c +++ b/od-win32/direct3d.c @@ -27,11 +27,11 @@ static int psEnabled, psActive, psPreProcess; static int tformat; static int d3d_enabled, d3d_ex; -static LPDIRECT3D9 d3d; -static LPDIRECT3D9EX d3dex; +static IDirect3D9 *d3d; +static IDirect3D9Ex *d3dex; static D3DPRESENT_PARAMETERS dpp; -static LPDIRECT3DDEVICE9 d3ddev; -static LPDIRECT3DDEVICE9EX d3ddevex; +static IDirect3DDevice9 *d3ddev; +static IDirect3DDevice9Ex *d3ddevex; static D3DSURFACE_DESC dsdbb; static LPDIRECT3DTEXTURE9 texture, sltexture, ledtexture; static LPDIRECT3DTEXTURE9 lpWorkTexture1, lpWorkTexture2; @@ -58,67 +58,67 @@ static int resetcount; #define D3DFVF_TLVERTEX D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1 struct TLVERTEX { - D3DXVECTOR3 position; // vertex position - D3DCOLOR diffuse; - D3DXVECTOR2 texcoord; // texture coords + D3DXVECTOR3 position; // vertex position + D3DCOLOR diffuse; + D3DXVECTOR2 texcoord; // texture coords }; static TCHAR *D3D_ErrorText (HRESULT error) { - return L""; + return L""; } static TCHAR *D3D_ErrorString (HRESULT dival) { - static TCHAR dierr[200]; - _stprintf (dierr, L"%08X S=%d F=%04X C=%04X (%d) (%s)", - dival, (dival & 0x80000000) ? 1 : 0, - HRESULT_FACILITY(dival), - HRESULT_CODE(dival), - HRESULT_CODE(dival), - D3D_ErrorText (dival)); - return dierr; + static TCHAR dierr[200]; + _stprintf (dierr, L"%08X S=%d F=%04X C=%04X (%d) (%s)", + dival, (dival & 0x80000000) ? 1 : 0, + HRESULT_FACILITY(dival), + HRESULT_CODE(dival), + HRESULT_CODE(dival), + D3D_ErrorText (dival)); + return dierr; } static D3DXMATRIX* MatrixOrthoOffCenterLH (D3DXMATRIX *pOut, float l, float r, float b, float t, float zn, float zf) { - pOut->_11=2.0f/r; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; - pOut->_21=0.0f; pOut->_22=2.0f/t; pOut->_23=0.0f; pOut->_24=0.0f; - pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=1.0f; pOut->_34=0.0f; - pOut->_41=-1.0f; pOut->_42=-1.0f; pOut->_43=0.0f; pOut->_44=1.0f; - return pOut; + pOut->_11=2.0f/r; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; + pOut->_21=0.0f; pOut->_22=2.0f/t; pOut->_23=0.0f; pOut->_24=0.0f; + pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=1.0f; pOut->_34=0.0f; + pOut->_41=-1.0f; pOut->_42=-1.0f; pOut->_43=0.0f; pOut->_44=1.0f; + return pOut; } static D3DXMATRIX* MatrixScaling (D3DXMATRIX *pOut, float sx, float sy, float sz) { - pOut->_11=sx; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; - pOut->_21=0.0f; pOut->_22=sy; pOut->_23=0.0f; pOut->_24=0.0f; - pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=sz; pOut->_34=0.0f; - pOut->_41=0.0f; pOut->_42=0.0f; pOut->_43=0.0f; pOut->_44=1.0f; - return pOut; + pOut->_11=sx; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; + pOut->_21=0.0f; pOut->_22=sy; pOut->_23=0.0f; pOut->_24=0.0f; + pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=sz; pOut->_34=0.0f; + pOut->_41=0.0f; pOut->_42=0.0f; pOut->_43=0.0f; pOut->_44=1.0f; + return pOut; } static D3DXMATRIX* MatrixTranslation (D3DXMATRIX *pOut, float tx, float ty, float tz) { - pOut->_11=1.0f; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; - pOut->_21=0.0f; pOut->_22=1.0f; pOut->_23=0.0f; pOut->_24=0.0f; - pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=1.0f; pOut->_34=0.0f; - pOut->_41=tx; pOut->_42=ty; pOut->_43=tz; pOut->_44=1.0f; - return pOut; + pOut->_11=1.0f; pOut->_12=0.0f; pOut->_13=0.0f; pOut->_14=0.0f; + pOut->_21=0.0f; pOut->_22=1.0f; pOut->_23=0.0f; pOut->_24=0.0f; + pOut->_31=0.0f; pOut->_32=0.0f; pOut->_33=1.0f; pOut->_34=0.0f; + pOut->_41=tx; pOut->_42=ty; pOut->_43=tz; pOut->_44=1.0f; + return pOut; } static TCHAR *D3DX_ErrorString (HRESULT hr, LPD3DXBUFFER Errors) { - static TCHAR buffer[1000]; - TCHAR *s = NULL; - - if (Errors) - s = Errors->lpVtbl->GetBufferPointer (Errors); - _tcscpy (buffer, D3D_ErrorString (hr)); - if (s) { - _tcscat (buffer, L" "); - _tcscat (buffer, s); - } - return buffer; + static TCHAR buffer[1000]; + TCHAR *s = NULL; + + if (Errors) + s = Errors->lpVtbl->GetBufferPointer (Errors); + _tcscpy (buffer, D3D_ErrorString (hr)); + if (s) { + _tcscat (buffer, L" "); + _tcscat (buffer, s); + } + return buffer; } static LPD3DXEFFECT pEffect; @@ -147,165 +147,165 @@ enum psEffect_Pass { psEffect_PreProcess1, psEffect_PreProcess2, psEffect_Combin static int psEffect_ParseParameters (LPD3DXEFFECTCOMPILER EffectCompiler) { - HRESULT hr = S_OK; - // Look at parameters for semantics and annotations that we know how to interpret - D3DXPARAMETER_DESC ParamDesc; - D3DXPARAMETER_DESC AnnotDesc; - D3DXHANDLE hParam; - D3DXHANDLE hAnnot; - LPDIRECT3DBASETEXTURE9 pTex = NULL; - UINT iParam, iAnnot; - - if(pEffect == NULL) - return 0; - - for(iParam = 0; iParam < EffectDesc.Parameters; iParam++) { - LPCSTR pstrName = NULL; - LPCSTR pstrFunction = NULL; - LPCSTR pstrTarget = NULL; - LPCSTR pstrTextureType = NULL; - INT Width = D3DX_DEFAULT; - INT Height= D3DX_DEFAULT; - INT Depth = D3DX_DEFAULT; - - hParam = pEffect->lpVtbl->GetParameter (pEffect, NULL, iParam); - pEffect->lpVtbl->GetParameterDesc (pEffect, hParam, &ParamDesc); - - if(ParamDesc.Semantic != NULL) { - if(ParamDesc.Class == D3DXPC_MATRIX_ROWS || ParamDesc.Class == D3DXPC_MATRIX_COLUMNS) { - if(strcmpi(ParamDesc.Semantic, "world") == 0) - m_MatWorldEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "view") == 0) - m_MatViewEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "projection") == 0) - m_MatProjEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "worldview") == 0) - m_MatWorldViewEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "viewprojection") == 0) - m_MatViewProjEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "worldviewprojection") == 0) - m_MatWorldViewProjEffectHandle = hParam; - } else if(ParamDesc.Class == D3DXPC_VECTOR && ParamDesc.Type == D3DXPT_FLOAT) { - if(strcmpi(ParamDesc.Semantic, "sourcedims") == 0) - m_SourceDimsEffectHandle = hParam; - else if(strcmpi(ParamDesc.Semantic, "texelsize") == 0) - m_TexelSizeEffectHandle = hParam; - } else if(ParamDesc.Class == D3DXPC_SCALAR && ParamDesc.Type == D3DXPT_FLOAT) { - if(strcmpi(ParamDesc.Semantic, "SCALING") == 0) - pEffect->lpVtbl->GetFloat(pEffect, hParam, &m_scale); - } else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_TEXTURE) { - if(strcmpi(ParamDesc.Semantic, "SOURCETEXTURE") == 0) - m_SourceTextureEffectHandle = hParam; - if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE") == 0) - m_WorkingTexture1EffectHandle = hParam; - if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE1") == 0) - m_WorkingTexture2EffectHandle = hParam; - if(strcmpi(ParamDesc.Semantic, "HQ2XLOOKUPTEXTURE") == 0) - m_Hq2xLookupTextureHandle = hParam; - } else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_STRING) { - LPCSTR pstrTechnique = NULL; - - if(strcmpi(ParamDesc.Semantic, "COMBINETECHNIQUE") == 0) { - pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); - m_CombineTechniqueEffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); - } - else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE") == 0) { - pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); - m_PreprocessTechnique1EffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); + HRESULT hr = S_OK; + // Look at parameters for semantics and annotations that we know how to interpret + D3DXPARAMETER_DESC ParamDesc; + D3DXPARAMETER_DESC AnnotDesc; + D3DXHANDLE hParam; + D3DXHANDLE hAnnot; + LPDIRECT3DBASETEXTURE9 pTex = NULL; + UINT iParam, iAnnot; + + if(pEffect == NULL) + return 0; + + for(iParam = 0; iParam < EffectDesc.Parameters; iParam++) { + LPCSTR pstrName = NULL; + LPCSTR pstrFunction = NULL; + LPCSTR pstrTarget = NULL; + LPCSTR pstrTextureType = NULL; + INT Width = D3DX_DEFAULT; + INT Height= D3DX_DEFAULT; + INT Depth = D3DX_DEFAULT; + + hParam = pEffect->lpVtbl->GetParameter (pEffect, NULL, iParam); + pEffect->lpVtbl->GetParameterDesc (pEffect, hParam, &ParamDesc); + + if(ParamDesc.Semantic != NULL) { + if(ParamDesc.Class == D3DXPC_MATRIX_ROWS || ParamDesc.Class == D3DXPC_MATRIX_COLUMNS) { + if(strcmpi(ParamDesc.Semantic, "world") == 0) + m_MatWorldEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "view") == 0) + m_MatViewEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "projection") == 0) + m_MatProjEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "worldview") == 0) + m_MatWorldViewEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "viewprojection") == 0) + m_MatViewProjEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "worldviewprojection") == 0) + m_MatWorldViewProjEffectHandle = hParam; + } else if(ParamDesc.Class == D3DXPC_VECTOR && ParamDesc.Type == D3DXPT_FLOAT) { + if(strcmpi(ParamDesc.Semantic, "sourcedims") == 0) + m_SourceDimsEffectHandle = hParam; + else if(strcmpi(ParamDesc.Semantic, "texelsize") == 0) + m_TexelSizeEffectHandle = hParam; + } else if(ParamDesc.Class == D3DXPC_SCALAR && ParamDesc.Type == D3DXPT_FLOAT) { + if(strcmpi(ParamDesc.Semantic, "SCALING") == 0) + pEffect->lpVtbl->GetFloat(pEffect, hParam, &m_scale); + } else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_TEXTURE) { + if(strcmpi(ParamDesc.Semantic, "SOURCETEXTURE") == 0) + m_SourceTextureEffectHandle = hParam; + if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE") == 0) + m_WorkingTexture1EffectHandle = hParam; + if(strcmpi(ParamDesc.Semantic, "WORKINGTEXTURE1") == 0) + m_WorkingTexture2EffectHandle = hParam; + if(strcmpi(ParamDesc.Semantic, "HQ2XLOOKUPTEXTURE") == 0) + m_Hq2xLookupTextureHandle = hParam; + } else if(ParamDesc.Class == D3DXPC_OBJECT && ParamDesc.Type == D3DXPT_STRING) { + LPCSTR pstrTechnique = NULL; + + if(strcmpi(ParamDesc.Semantic, "COMBINETECHNIQUE") == 0) { + pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); + m_CombineTechniqueEffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); + } + else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE") == 0) { + pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); + m_PreprocessTechnique1EffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); + } + else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE1") == 0) { + pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); + m_PreprocessTechnique2EffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); + } + else if(strcmpi(ParamDesc.Semantic, "NAME") == 0) + pEffect->lpVtbl->GetString(pEffect, hParam, &m_strName); + } } - else if(strcmpi(ParamDesc.Semantic, "PREPROCESSTECHNIQUE1") == 0) { - pEffect->lpVtbl->GetString(pEffect, hParam, &pstrTechnique); - m_PreprocessTechnique2EffectHandle = pEffect->lpVtbl->GetTechniqueByName(pEffect, pstrTechnique); + + for(iAnnot = 0; iAnnot < ParamDesc.Annotations; iAnnot++) { + hAnnot = pEffect->lpVtbl->GetAnnotation (pEffect, hParam, iAnnot); + pEffect->lpVtbl->GetParameterDesc(pEffect, hAnnot, &AnnotDesc); + if(strcmpi(AnnotDesc.Name, "name") == 0) + pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrName); + else if(strcmpi(AnnotDesc.Name, "function") == 0) + pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrFunction); + else if(strcmpi(AnnotDesc.Name, "target") == 0) + pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrTarget); + else if(strcmpi(AnnotDesc.Name, "width") == 0) + pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Width); + else if(strcmpi(AnnotDesc.Name, "height") == 0) + pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Height); + else if(strcmpi(AnnotDesc.Name, "depth") == 0) + pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Depth); + else if(strcmpi(AnnotDesc.Name, "type") == 0) + pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrTextureType); } - else if(strcmpi(ParamDesc.Semantic, "NAME") == 0) - pEffect->lpVtbl->GetString(pEffect, hParam, &m_strName); - } - } - - for(iAnnot = 0; iAnnot < ParamDesc.Annotations; iAnnot++) { - hAnnot = pEffect->lpVtbl->GetAnnotation (pEffect, hParam, iAnnot); - pEffect->lpVtbl->GetParameterDesc(pEffect, hAnnot, &AnnotDesc); - if(strcmpi(AnnotDesc.Name, "name") == 0) - pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrName); - else if(strcmpi(AnnotDesc.Name, "function") == 0) - pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrFunction); - else if(strcmpi(AnnotDesc.Name, "target") == 0) - pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrTarget); - else if(strcmpi(AnnotDesc.Name, "width") == 0) - pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Width); - else if(strcmpi(AnnotDesc.Name, "height") == 0) - pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Height); - else if(strcmpi(AnnotDesc.Name, "depth") == 0) - pEffect->lpVtbl->GetInt(pEffect, hAnnot, &Depth); - else if(strcmpi(AnnotDesc.Name, "type") == 0) - pEffect->lpVtbl->GetString(pEffect, hAnnot, &pstrTextureType); - } - - if(pstrFunction != NULL) { - LPD3DXBUFFER pTextureShader = NULL; - LPD3DXBUFFER lpErrors = 0; - - if(pstrTarget == NULL || strcmp(pstrTarget,"tx_1_1")) - pstrTarget = "tx_1_0"; - - if(SUCCEEDED(hr = EffectCompiler->lpVtbl->CompileShader(EffectCompiler, + + if(pstrFunction != NULL) { + LPD3DXBUFFER pTextureShader = NULL; + LPD3DXBUFFER lpErrors = 0; + + if(pstrTarget == NULL || strcmp(pstrTarget,"tx_1_1")) + pstrTarget = "tx_1_0"; + + if(SUCCEEDED(hr = EffectCompiler->lpVtbl->CompileShader(EffectCompiler, pstrFunction, pstrTarget, 0, &pTextureShader, &lpErrors, NULL))) { - LPD3DXTEXTURESHADER ppTextureShader; - if (lpErrors) - lpErrors->lpVtbl->Release (lpErrors); - - if(Width == D3DX_DEFAULT) - Width = 64; - if(Height == D3DX_DEFAULT) - Height = 64; - if(Depth == D3DX_DEFAULT) - Depth = 64; - - D3DXCreateTextureShader((DWORD *)pTextureShader->lpVtbl->GetBufferPointer(pTextureShader), &ppTextureShader); - - if(pstrTextureType != NULL) { - if(strcmpi(pstrTextureType, "volume") == 0) { - LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL; - if(SUCCEEDED(hr = D3DXCreateVolumeTexture(d3ddev, - Width, Height, Depth, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pVolumeTex))) { - if(SUCCEEDED(hr = D3DXFillVolumeTextureTX(pVolumeTex, ppTextureShader))) { - pTex = pVolumeTex; - } - } - } else if(strcmpi(pstrTextureType, "cube") == 0) { - LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL; - if(SUCCEEDED(hr = D3DXCreateCubeTexture(d3ddev, - Width, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pCubeTex))) { - if(SUCCEEDED(hr = D3DXFillCubeTextureTX(pCubeTex, ppTextureShader))) { - pTex = pCubeTex; - } - } - } - } else { - LPDIRECT3DTEXTURE9 p2DTex = NULL; - if(SUCCEEDED(hr = D3DXCreateTexture(d3ddev, Width, Height, - D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &p2DTex))) { - if(SUCCEEDED(hr = D3DXFillTextureTX(p2DTex, ppTextureShader))) { - pTex = p2DTex; - } - } + LPD3DXTEXTURESHADER ppTextureShader; + if (lpErrors) + lpErrors->lpVtbl->Release (lpErrors); + + if(Width == D3DX_DEFAULT) + Width = 64; + if(Height == D3DX_DEFAULT) + Height = 64; + if(Depth == D3DX_DEFAULT) + Depth = 64; + + D3DXCreateTextureShader((DWORD *)pTextureShader->lpVtbl->GetBufferPointer(pTextureShader), &ppTextureShader); + + if(pstrTextureType != NULL) { + if(strcmpi(pstrTextureType, "volume") == 0) { + LPDIRECT3DVOLUMETEXTURE9 pVolumeTex = NULL; + if(SUCCEEDED(hr = D3DXCreateVolumeTexture(d3ddev, + Width, Height, Depth, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pVolumeTex))) { + if(SUCCEEDED(hr = D3DXFillVolumeTextureTX(pVolumeTex, ppTextureShader))) { + pTex = pVolumeTex; + } + } + } else if(strcmpi(pstrTextureType, "cube") == 0) { + LPDIRECT3DCUBETEXTURE9 pCubeTex = NULL; + if(SUCCEEDED(hr = D3DXCreateCubeTexture(d3ddev, + Width, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pCubeTex))) { + if(SUCCEEDED(hr = D3DXFillCubeTextureTX(pCubeTex, ppTextureShader))) { + pTex = pCubeTex; + } + } + } + } else { + LPDIRECT3DTEXTURE9 p2DTex = NULL; + if(SUCCEEDED(hr = D3DXCreateTexture(d3ddev, Width, Height, + D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &p2DTex))) { + if(SUCCEEDED(hr = D3DXFillTextureTX(p2DTex, ppTextureShader))) { + pTex = p2DTex; + } + } + } + pEffect->lpVtbl->SetTexture(pEffect, pEffect->lpVtbl->GetParameter(pEffect, NULL, iParam), pTex); + if (pTex) + pTex->lpVtbl->Release (pTex); + if (pTextureShader) + pTextureShader->lpVtbl->Release (pTextureShader); + if (ppTextureShader) + ppTextureShader->lpVtbl->Release (ppTextureShader); + } else { + write_log (L"D3D: Could not compile texture shader: %s\n", D3DX_ErrorString (hr, lpErrors)); + if (lpErrors) + lpErrors->lpVtbl->Release (lpErrors); + return 0; + } } - pEffect->lpVtbl->SetTexture(pEffect, pEffect->lpVtbl->GetParameter(pEffect, NULL, iParam), pTex); - if (pTex) - pTex->lpVtbl->Release (pTex); - if (pTextureShader) - pTextureShader->lpVtbl->Release (pTextureShader); - if (ppTextureShader) - ppTextureShader->lpVtbl->Release (ppTextureShader); - } else { - write_log (L"D3D: Could not compile texture shader: %s\n", D3DX_ErrorString (hr, lpErrors)); - if (lpErrors) - lpErrors->lpVtbl->Release (lpErrors); - return 0; - } - } - } - return 1; + } + return 1; } static int psEffect_hasPreProcess (void) { return m_PreprocessTechnique1EffectHandle != 0; } @@ -315,1287 +315,1287 @@ static int d3d_yesno = 0; int D3D_goodenough (void) { - static int d3d_good; - LPDIRECT3D9 d3dx; - D3DCAPS9 d3dCaps; + static int d3d_good; + LPDIRECT3D9 d3dx; + D3DCAPS9 d3dCaps; - if (d3d_yesno > 0 || d3d_good > 0) - return 1; - if (d3d_good < 0) - return 0; - d3d_good = -1; - d3dx = Direct3DCreate9 (D3D_SDK_VERSION); - if (d3dx != NULL) { - if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3dx, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) { - if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) - d3d_good = 1; - } - IDirect3D9_Release (d3dx); - } - return d3d_good > 0 ? 1 : 0; + if (d3d_yesno > 0 || d3d_good > 0) + return 1; + if (d3d_good < 0) + return 0; + d3d_good = -1; + d3dx = Direct3DCreate9 (D3D_SDK_VERSION); + if (d3dx != NULL) { + if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3dx, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) { + if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) + d3d_good = 1; + } + IDirect3D9_Release (d3dx); + } + return d3d_good > 0 ? 1 : 0; } int D3D_canshaders (void) { - HANDLE h; - LPDIRECT3D9 d3dx; - D3DCAPS9 d3dCaps; + HANDLE h; + LPDIRECT3D9 d3dx; + D3DCAPS9 d3dCaps; - if (d3d_yesno < 0) - return 0; - if (d3d_yesno > 0) - return 1; - d3d_yesno = -1; - h = LoadLibrary (L"d3dx9_42.dll"); - if (h != NULL) { - FreeLibrary (h); - d3dx = Direct3DCreate9 (D3D_SDK_VERSION); - if (d3dx != NULL) { - if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3dx, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) { - if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) { - write_log (L"D3D: Pixel shader 2.0+ support detected, shader filters enabled.\n"); - d3d_yesno = 1; + if (d3d_yesno < 0) + return 0; + if (d3d_yesno > 0) + return 1; + d3d_yesno = -1; + h = LoadLibrary (L"d3dx9_42.dll"); + if (h != NULL) { + FreeLibrary (h); + d3dx = Direct3DCreate9 (D3D_SDK_VERSION); + if (d3dx != NULL) { + if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3dx, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) { + if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) { + write_log (L"D3D: Pixel shader 2.0+ support detected, shader filters enabled.\n"); + d3d_yesno = 1; + } + } + IDirect3D9_Release (d3dx); } - } - IDirect3D9_Release (d3dx); } - } - return d3d_yesno > 0 ? 1 : 0; + return d3d_yesno > 0 ? 1 : 0; } static int psEffect_LoadEffect (const TCHAR *shaderfile) { - int ret = 0; - LPD3DXEFFECTCOMPILER EffectCompiler = NULL; - LPD3DXBUFFER Errors = NULL; - LPD3DXBUFFER BufferEffect = NULL; - HRESULT hr; - TCHAR tmp[MAX_DPATH]; - static int first; - - if (!D3D_canshaders ()) { - if (!first) - gui_message (L"Installed DirectX is too old\nD3D shaders disabled."); - first = 1; - return 0; - } - _stprintf (tmp, L"%s%sfiltershaders\\direct3d\\%s", start_path_exe, WIN32_PLUGINDIR, shaderfile); - hr = D3DXCreateEffectCompilerFromFile (tmp, NULL, NULL, 0, &EffectCompiler, &Errors); - if (FAILED (hr)) { - write_log (L"D3D: D3DXCreateEffectCompilerFromFile failed: %s\n", D3DX_ErrorString (hr, Errors)); - goto end; - } - hr = EffectCompiler->lpVtbl->CompileEffect (EffectCompiler, 0, &BufferEffect, &Errors); - if (FAILED (hr)) { - write_log (L"D3D: CompileEffect failed: %s\n", D3DX_ErrorString (hr, Errors)); - goto end; - } - hr = D3DXCreateEffect (d3ddev, - BufferEffect->lpVtbl->GetBufferPointer (BufferEffect), - BufferEffect->lpVtbl->GetBufferSize (BufferEffect), - NULL, NULL, - 0, - NULL, &pEffect, &Errors); - if (FAILED (hr)) { - write_log (L"D3D: D3DXCreateEffect failed: %s\n", D3DX_ErrorString (hr, Errors)); - goto end; - } - pEffect->lpVtbl->GetDesc (pEffect, &EffectDesc); - if (!psEffect_ParseParameters (EffectCompiler)) - goto end; - ret = 1; + int ret = 0; + LPD3DXEFFECTCOMPILER EffectCompiler = NULL; + LPD3DXBUFFER Errors = NULL; + LPD3DXBUFFER BufferEffect = NULL; + HRESULT hr; + TCHAR tmp[MAX_DPATH]; + static int first; + + if (!D3D_canshaders ()) { + if (!first) + gui_message (L"Installed DirectX is too old\nD3D shaders disabled."); + first = 1; + return 0; + } + _stprintf (tmp, L"%s%sfiltershaders\\direct3d\\%s", start_path_exe, WIN32_PLUGINDIR, shaderfile); + hr = D3DXCreateEffectCompilerFromFile (tmp, NULL, NULL, 0, &EffectCompiler, &Errors); + if (FAILED (hr)) { + write_log (L"D3D: D3DXCreateEffectCompilerFromFile failed: %s\n", D3DX_ErrorString (hr, Errors)); + goto end; + } + hr = EffectCompiler->lpVtbl->CompileEffect (EffectCompiler, 0, &BufferEffect, &Errors); + if (FAILED (hr)) { + write_log (L"D3D: CompileEffect failed: %s\n", D3DX_ErrorString (hr, Errors)); + goto end; + } + hr = D3DXCreateEffect (d3ddev, + BufferEffect->lpVtbl->GetBufferPointer (BufferEffect), + BufferEffect->lpVtbl->GetBufferSize (BufferEffect), + NULL, NULL, + 0, + NULL, &pEffect, &Errors); + if (FAILED (hr)) { + write_log (L"D3D: D3DXCreateEffect failed: %s\n", D3DX_ErrorString (hr, Errors)); + goto end; + } + pEffect->lpVtbl->GetDesc (pEffect, &EffectDesc); + if (!psEffect_ParseParameters (EffectCompiler)) + goto end; + ret = 1; end: - if (Errors) - Errors->lpVtbl->Release (Errors); - if (BufferEffect) - BufferEffect->lpVtbl->Release (BufferEffect); - if (EffectCompiler) - EffectCompiler->lpVtbl->Release (EffectCompiler); - - psActive = FALSE; - psPreProcess = FALSE; - if (ret) { - psActive = TRUE; - if (psEffect_hasPreProcess ()) - psPreProcess = TRUE; - write_log (L"D3D: pixelshader filter '%s' enabled, preproc=%d\n", tmp, psPreProcess); - } else { - write_log (L"D3D: pixelshader filter '%s' failed to initialize\n", tmp); - } - return ret; + if (Errors) + Errors->lpVtbl->Release (Errors); + if (BufferEffect) + BufferEffect->lpVtbl->Release (BufferEffect); + if (EffectCompiler) + EffectCompiler->lpVtbl->Release (EffectCompiler); + + psActive = FALSE; + psPreProcess = FALSE; + if (ret) { + psActive = TRUE; + if (psEffect_hasPreProcess ()) + psPreProcess = TRUE; + write_log (L"D3D: pixelshader filter '%s' enabled, preproc=%d\n", tmp, psPreProcess); + } else { + write_log (L"D3D: pixelshader filter '%s' failed to initialize\n", tmp); + } + return ret; } static int psEffect_SetMatrices (D3DXMATRIX *matProj, D3DXMATRIX *matView, D3DXMATRIX *matWorld) { - HRESULT hr; + HRESULT hr; - if (m_MatWorldEffectHandle) { - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldEffectHandle, matWorld); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matWorld %s\n", D3D_ErrorString (hr)); - return 0; + if (m_MatWorldEffectHandle) { + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldEffectHandle, matWorld); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matWorld %s\n", D3D_ErrorString (hr)); + return 0; + } } - } - if (m_MatViewEffectHandle) { - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatViewEffectHandle, matView); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matView %s\n", D3D_ErrorString (hr)); - return 0; + if (m_MatViewEffectHandle) { + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatViewEffectHandle, matView); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matView %s\n", D3D_ErrorString (hr)); + return 0; + } } - } - if (m_MatProjEffectHandle) { - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatProjEffectHandle, matProj); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matProj %s\n", D3D_ErrorString (hr)); - return 0; - } - } - if (m_MatWorldViewEffectHandle) { - D3DXMATRIX matWorldView; - D3DXMatrixMultiply (&matWorldView, matWorld, matView); - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldViewEffectHandle, &matWorldView); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matWorldView %s\n", D3D_ErrorString (hr)); - return 0; - } - } - if (m_MatViewProjEffectHandle) { - D3DXMATRIX matViewProj; - D3DXMatrixMultiply (&matViewProj, matView, matProj); - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatViewProjEffectHandle, &matViewProj); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matViewProj %s\n", D3D_ErrorString (hr)); - return 0; - } - } - if (m_MatWorldViewProjEffectHandle) { - D3DXMATRIX tmp, matWorldViewProj; - D3DXMatrixMultiply (&tmp, matWorld, matView); - D3DXMatrixMultiply (&matWorldViewProj, &tmp, matProj); - hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldViewProjEffectHandle, &matWorldViewProj); - if (FAILED (hr)) { - write_log (L"D3D:Create:SetMatrix:matWorldViewProj %s\n", D3D_ErrorString (hr)); - return 0; + if (m_MatProjEffectHandle) { + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatProjEffectHandle, matProj); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matProj %s\n", D3D_ErrorString (hr)); + return 0; + } } - } - return 1; + if (m_MatWorldViewEffectHandle) { + D3DXMATRIX matWorldView; + D3DXMatrixMultiply (&matWorldView, matWorld, matView); + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldViewEffectHandle, &matWorldView); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matWorldView %s\n", D3D_ErrorString (hr)); + return 0; + } + } + if (m_MatViewProjEffectHandle) { + D3DXMATRIX matViewProj; + D3DXMatrixMultiply (&matViewProj, matView, matProj); + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatViewProjEffectHandle, &matViewProj); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matViewProj %s\n", D3D_ErrorString (hr)); + return 0; + } + } + if (m_MatWorldViewProjEffectHandle) { + D3DXMATRIX tmp, matWorldViewProj; + D3DXMatrixMultiply (&tmp, matWorld, matView); + D3DXMatrixMultiply (&matWorldViewProj, &tmp, matProj); + hr = pEffect->lpVtbl->SetMatrix (pEffect, m_MatWorldViewProjEffectHandle, &matWorldViewProj); + if (FAILED (hr)) { + write_log (L"D3D:Create:SetMatrix:matWorldViewProj %s\n", D3D_ErrorString (hr)); + return 0; + } + } + return 1; } static int psEffect_SetTextures (LPDIRECT3DTEXTURE9 lpSource, LPDIRECT3DTEXTURE9 lpWorking1, - LPDIRECT3DTEXTURE9 lpWorking2, LPDIRECT3DVOLUMETEXTURE9 lpHq2xLookupTexture) + LPDIRECT3DTEXTURE9 lpWorking2, LPDIRECT3DVOLUMETEXTURE9 lpHq2xLookupTexture) { - HRESULT hr; - D3DXVECTOR4 fDims, fTexelSize; + HRESULT hr; + D3DXVECTOR4 fDims, fTexelSize; - if (!m_SourceTextureEffectHandle) { - write_log (L"D3D: Texture with SOURCETEXTURE semantic not found\n"); - return 0; - } - hr = pEffect->lpVtbl->SetTexture (pEffect, m_SourceTextureEffectHandle, (LPDIRECT3DBASETEXTURE9)lpSource); - if (FAILED (hr)) { - write_log (L"D3D:SetTextures:lpSource %s\n", D3D_ErrorString (hr)); - return 0; - } - if(m_WorkingTexture1EffectHandle) { - hr = pEffect->lpVtbl->SetTexture (pEffect, m_WorkingTexture1EffectHandle, (LPDIRECT3DBASETEXTURE9)lpWorking1); - if (FAILED (hr)) { - write_log (L"D3D:SetTextures:lpWorking1 %s\n", D3D_ErrorString (hr)); - return 0; + if (!m_SourceTextureEffectHandle) { + write_log (L"D3D: Texture with SOURCETEXTURE semantic not found\n"); + return 0; } - } - if(m_WorkingTexture2EffectHandle) { - hr = pEffect->lpVtbl->SetTexture (pEffect, m_WorkingTexture2EffectHandle, (LPDIRECT3DBASETEXTURE9)lpWorking2); + hr = pEffect->lpVtbl->SetTexture (pEffect, m_SourceTextureEffectHandle, (LPDIRECT3DBASETEXTURE9)lpSource); if (FAILED (hr)) { - write_log (L"D3D:SetTextures:lpWorking2 %s\n", D3D_ErrorString (hr)); - return 0; + write_log (L"D3D:SetTextures:lpSource %s\n", D3D_ErrorString (hr)); + return 0; } - } - if(m_Hq2xLookupTextureHandle) { - hr = pEffect->lpVtbl->SetTexture (pEffect, m_Hq2xLookupTextureHandle, (LPDIRECT3DBASETEXTURE9)lpHq2xLookupTexture); - if (FAILED (hr)) { - write_log (L"D3D:SetTextures:lpHq2xLookupTexture %s\n", D3D_ErrorString (hr)); - return 0; - } - } - fDims.x = 256; fDims.y = 256; fDims.z = 1; fDims.w = 1; - fTexelSize.x = 1; fTexelSize.y = 1; fTexelSize.z = 1; fTexelSize.w = 1; - if (lpSource) { - D3DSURFACE_DESC Desc; - lpSource->lpVtbl->GetLevelDesc (lpSource, 0, &Desc); - fDims.x = (FLOAT) Desc.Width; - fDims.y = (FLOAT) Desc.Height; - } - fTexelSize.x = 1 / fDims.x; - fTexelSize.y = 1 / fDims.y; - if (m_SourceDimsEffectHandle) { - hr = pEffect->lpVtbl->SetVector (pEffect, m_SourceDimsEffectHandle, &fDims); - if (FAILED (hr)) { - write_log (L"D3D:SetTextures:SetVector:Source %s\n", D3D_ErrorString (hr)); - return 0; + if(m_WorkingTexture1EffectHandle) { + hr = pEffect->lpVtbl->SetTexture (pEffect, m_WorkingTexture1EffectHandle, (LPDIRECT3DBASETEXTURE9)lpWorking1); + if (FAILED (hr)) { + write_log (L"D3D:SetTextures:lpWorking1 %s\n", D3D_ErrorString (hr)); + return 0; + } } - } - if (m_TexelSizeEffectHandle) { - hr = pEffect->lpVtbl->SetVector (pEffect, m_TexelSizeEffectHandle, &fTexelSize); - if (FAILED (hr)) { - write_log (L"D3D:SetTextures:SetVector:Texel %s\n", D3D_ErrorString (hr)); - return 0; + if(m_WorkingTexture2EffectHandle) { + hr = pEffect->lpVtbl->SetTexture (pEffect, m_WorkingTexture2EffectHandle, (LPDIRECT3DBASETEXTURE9)lpWorking2); + if (FAILED (hr)) { + write_log (L"D3D:SetTextures:lpWorking2 %s\n", D3D_ErrorString (hr)); + return 0; + } + } + if(m_Hq2xLookupTextureHandle) { + hr = pEffect->lpVtbl->SetTexture (pEffect, m_Hq2xLookupTextureHandle, (LPDIRECT3DBASETEXTURE9)lpHq2xLookupTexture); + if (FAILED (hr)) { + write_log (L"D3D:SetTextures:lpHq2xLookupTexture %s\n", D3D_ErrorString (hr)); + return 0; + } + } + fDims.x = 256; fDims.y = 256; fDims.z = 1; fDims.w = 1; + fTexelSize.x = 1; fTexelSize.y = 1; fTexelSize.z = 1; fTexelSize.w = 1; + if (lpSource) { + D3DSURFACE_DESC Desc; + lpSource->lpVtbl->GetLevelDesc (lpSource, 0, &Desc); + fDims.x = (FLOAT) Desc.Width; + fDims.y = (FLOAT) Desc.Height; + } + fTexelSize.x = 1 / fDims.x; + fTexelSize.y = 1 / fDims.y; + if (m_SourceDimsEffectHandle) { + hr = pEffect->lpVtbl->SetVector (pEffect, m_SourceDimsEffectHandle, &fDims); + if (FAILED (hr)) { + write_log (L"D3D:SetTextures:SetVector:Source %s\n", D3D_ErrorString (hr)); + return 0; + } + } + if (m_TexelSizeEffectHandle) { + hr = pEffect->lpVtbl->SetVector (pEffect, m_TexelSizeEffectHandle, &fTexelSize); + if (FAILED (hr)) { + write_log (L"D3D:SetTextures:SetVector:Texel %s\n", D3D_ErrorString (hr)); + return 0; + } } - } - return 1; + return 1; } static int psEffect_Begin (enum psEffect_Pass pass, UINT *pPasses) { - HRESULT hr; - switch (pass) { + HRESULT hr; + switch (pass) { case psEffect_PreProcess1: - hr = pEffect->lpVtbl->SetTechnique (pEffect, m_PreprocessTechnique1EffectHandle); - break; + hr = pEffect->lpVtbl->SetTechnique (pEffect, m_PreprocessTechnique1EffectHandle); + break; case psEffect_PreProcess2: - hr = pEffect->lpVtbl->SetTechnique (pEffect, m_PreprocessTechnique2EffectHandle); - break; + hr = pEffect->lpVtbl->SetTechnique (pEffect, m_PreprocessTechnique2EffectHandle); + break; case psEffect_Combine: - hr = pEffect->lpVtbl->SetTechnique (pEffect, m_CombineTechniqueEffectHandle); - break; - } - if(FAILED(hr)) { - write_log (L"D3D: SetTechnique: %s\n", D3D_ErrorString (hr)); - return 0; - } - hr = pEffect->lpVtbl->Begin (pEffect, pPasses, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE); - if(FAILED(hr)) { - write_log (L"D3D: Begin: %s\n", D3D_ErrorString (hr)); - return 0; - } - return 1; + hr = pEffect->lpVtbl->SetTechnique (pEffect, m_CombineTechniqueEffectHandle); + break; + } + if(FAILED(hr)) { + write_log (L"D3D: SetTechnique: %s\n", D3D_ErrorString (hr)); + return 0; + } + hr = pEffect->lpVtbl->Begin (pEffect, pPasses, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE); + if(FAILED(hr)) { + write_log (L"D3D: Begin: %s\n", D3D_ErrorString (hr)); + return 0; + } + return 1; } static int psEffect_BeginPass (UINT Pass) { - HRESULT hr; + HRESULT hr; - hr = pEffect->lpVtbl->BeginPass (pEffect, Pass); - if (FAILED (hr)) { - write_log (L"D3D: BeginPass: %s\n", D3D_ErrorString (hr)); - return 0; - } - return 1; + hr = pEffect->lpVtbl->BeginPass (pEffect, Pass); + if (FAILED (hr)) { + write_log (L"D3D: BeginPass: %s\n", D3D_ErrorString (hr)); + return 0; + } + return 1; } static int psEffect_EndPass (void) { - HRESULT hr; + HRESULT hr; - hr = pEffect->lpVtbl->EndPass (pEffect); - if (FAILED (hr)) { - write_log (L"D3D: EndPass: %s\n", D3D_ErrorString (hr)); - return 0; - } - return 1; + hr = pEffect->lpVtbl->EndPass (pEffect); + if (FAILED (hr)) { + write_log (L"D3D: EndPass: %s\n", D3D_ErrorString (hr)); + return 0; + } + return 1; } static int psEffect_End (void) { - HRESULT hr; + HRESULT hr; - hr = pEffect->lpVtbl->End (pEffect); - if (FAILED (hr)) { - write_log (L"D3D: End: %s\n", D3D_ErrorString (hr)); - return 0; - } - return 1; + hr = pEffect->lpVtbl->End (pEffect); + if (FAILED (hr)) { + write_log (L"D3D: End: %s\n", D3D_ErrorString (hr)); + return 0; + } + return 1; } static LPDIRECT3DTEXTURE9 createtext (int *ww, int *hh, D3DFORMAT format) { - LPDIRECT3DTEXTURE9 t; - HRESULT hr; - int w, h; - - w = *ww; - h = *hh; - if (tex_pow2) { - if (w < 256) - w = 256; - else if (w < 512) - w = 512; - else if (w < 1024) - w = 1024; - else if (w < 2048) - w = 2048; - else if (w < 4096) - w = 4096; - else - w = 8192; - if (h < 256) - h = 256; - else if (h < 512) - h = 512; - else if (h < 1024) - h = 1024; - else if (h < 2048) - h = 2048; - else if (h < 4096) - h = 4096; - else - h = 8192; - } - if (tex_square) { - if (w > h) - h = w; - else - w = h; - } + LPDIRECT3DTEXTURE9 t; + HRESULT hr; + int w, h; + + w = *ww; + h = *hh; + if (tex_pow2) { + if (w < 256) + w = 256; + else if (w < 512) + w = 512; + else if (w < 1024) + w = 1024; + else if (w < 2048) + w = 2048; + else if (w < 4096) + w = 4096; + else + w = 8192; + if (h < 256) + h = 256; + else if (h < 512) + h = 512; + else if (h < 1024) + h = 1024; + else if (h < 2048) + h = 2048; + else if (h < 4096) + h = 4096; + else + h = 8192; + } + if (tex_square) { + if (w > h) + h = w; + else + w = h; + } - if (tex_dynamic) { - hr = IDirect3DDevice9_CreateTexture (d3ddev, w, h, 1, D3DUSAGE_DYNAMIC, format, - D3DPOOL_DEFAULT, &t, NULL); - if (FAILED (hr)) - write_log (L"IDirect3DDevice9_CreateTexture() D3DUSAGE_DYNAMIC failed: %s (%d*%d %08x)\n", - D3D_ErrorString (hr), w, h, format); - } - if (!tex_dynamic || (tex_dynamic && FAILED (hr))) { - hr = IDirect3DDevice9_CreateTexture (d3ddev, w, h, 1, 0, format, - D3DPOOL_MANAGED, &t, NULL); - } - if (FAILED (hr)) { - write_log (L"IDirect3DDevice9_CreateTexture() failed: %s (%d*%d %08x)\n", - D3D_ErrorString (hr), w, h, format); - return 0; - } + if (tex_dynamic) { + hr = IDirect3DDevice9_CreateTexture (d3ddev, w, h, 1, D3DUSAGE_DYNAMIC, format, + D3DPOOL_DEFAULT, &t, NULL); + if (FAILED (hr)) + write_log (L"IDirect3DDevice9_CreateTexture() D3DUSAGE_DYNAMIC failed: %s (%d*%d %08x)\n", + D3D_ErrorString (hr), w, h, format); + } + if (!tex_dynamic || (tex_dynamic && FAILED (hr))) { + hr = IDirect3DDevice9_CreateTexture (d3ddev, w, h, 1, 0, format, + D3DPOOL_MANAGED, &t, NULL); + } + if (FAILED (hr)) { + write_log (L"IDirect3DDevice9_CreateTexture() failed: %s (%d*%d %08x)\n", + D3D_ErrorString (hr), w, h, format); + return 0; + } - *ww = w; - *hh = h; - return t; + *ww = w; + *hh = h; + return t; } static int createtexture (int w, int h) { - HRESULT hr; - UINT ww = w; - UINT hh = h; + HRESULT hr; + UINT ww = w; + UINT hh = h; - texture = createtext (&ww, &hh, tformat); - if (!texture) - return 0; - twidth = ww; - theight = hh; - write_log (L"D3D: %d*%d texture allocated, bits per pixel %d\n", ww, hh, t_depth); - if (psActive) { - D3DLOCKED_BOX lockedBox; - if (FAILED (hr = IDirect3DDevice9_CreateTexture (d3ddev, ww, hh, 1, - D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpWorkTexture1, NULL))) { - write_log (L"D3D:Failed to create working texture1: %s\n", D3D_ErrorString (hr)); - return 0; - } - if (FAILED (hr = IDirect3DDevice9_CreateTexture (d3ddev, ww, hh, 1, - D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpWorkTexture2, NULL))) { - write_log (L"D3D:Failed to create working texture2: %s\n", D3D_ErrorString (hr)); + texture = createtext (&ww, &hh, tformat); + if (!texture) return 0; - } - if (FAILED (hr = IDirect3DDevice9_CreateVolumeTexture (d3ddev, 256, 16, 256, 1, 0, - D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &lpHq2xLookupTexture, NULL))) { - write_log (L"D3D:Failed to create volume texture: %s\n", D3D_ErrorString (hr)); - return 0; - } - if (FAILED (hr = IDirect3DVolumeTexture9_LockBox (lpHq2xLookupTexture, 0, &lockedBox, NULL, 0))) { - write_log (L"D3D: Failed to lock box of volume texture: %s\n", D3D_ErrorString (hr)); - return 0; - } - //BuildHq2xLookupTexture(tin_w, tin_w, window_w, window_h, (unsigned char*)lockedBox.pBits); - BuildHq2xLookupTexture(window_w, window_h, tin_w, tin_w, (unsigned char*)lockedBox.pBits); - IDirect3DVolumeTexture9_UnlockBox (lpHq2xLookupTexture, 0); + twidth = ww; + theight = hh; + write_log (L"D3D: %d*%d texture allocated, bits per pixel %d\n", ww, hh, t_depth); + if (psActive) { + D3DLOCKED_BOX lockedBox; + if (FAILED (hr = IDirect3DDevice9_CreateTexture (d3ddev, ww, hh, 1, + D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpWorkTexture1, NULL))) { + write_log (L"D3D:Failed to create working texture1: %s\n", D3D_ErrorString (hr)); + return 0; + } + if (FAILED (hr = IDirect3DDevice9_CreateTexture (d3ddev, ww, hh, 1, + D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &lpWorkTexture2, NULL))) { + write_log (L"D3D:Failed to create working texture2: %s\n", D3D_ErrorString (hr)); + return 0; + } + if (FAILED (hr = IDirect3DDevice9_CreateVolumeTexture (d3ddev, 256, 16, 256, 1, 0, + D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &lpHq2xLookupTexture, NULL))) { + write_log (L"D3D:Failed to create volume texture: %s\n", D3D_ErrorString (hr)); + return 0; + } + if (FAILED (hr = IDirect3DVolumeTexture9_LockBox (lpHq2xLookupTexture, 0, &lockedBox, NULL, 0))) { + write_log (L"D3D: Failed to lock box of volume texture: %s\n", D3D_ErrorString (hr)); + return 0; + } + //BuildHq2xLookupTexture(tin_w, tin_w, window_w, window_h, (unsigned char*)lockedBox.pBits); + BuildHq2xLookupTexture(window_w, window_h, tin_w, tin_w, (unsigned char*)lockedBox.pBits); + IDirect3DVolumeTexture9_UnlockBox (lpHq2xLookupTexture, 0); - } - return 1; + } + return 1; } static void updateleds (void) { - D3DLOCKED_RECT locked; - HRESULT hr; - static rc[256], gc[256], bc[256], a[256]; - static int done; - int i, y; - - if (!done) { - for (i = 0; i < 256; i++) { - rc[i] = i << 16; - gc[i] = i << 8; - bc[i] = i << 0; - a[i] = i << 24; - } - done = 1; - } - hr = IDirect3DTexture9_LockRect (ledtexture, 0, &locked, NULL, D3DLOCK_DISCARD); - if (FAILED (hr)) { - write_log (L"SL IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); - return; - } - for (y = 0; y < TD_TOTAL_HEIGHT; y++) { - uae_u8 *buf = (uae_u8*)locked.pBits + y * locked.Pitch; - draw_status_line_single (buf, 32 / 8, y, ledwidth, rc, gc, bc, a); - } - IDirect3DTexture9_UnlockRect (ledtexture, 0); + D3DLOCKED_RECT locked; + HRESULT hr; + static rc[256], gc[256], bc[256], a[256]; + static int done; + int i, y; + + if (!done) { + for (i = 0; i < 256; i++) { + rc[i] = i << 16; + gc[i] = i << 8; + bc[i] = i << 0; + a[i] = i << 24; + } + done = 1; + } + hr = IDirect3DTexture9_LockRect (ledtexture, 0, &locked, NULL, D3DLOCK_DISCARD); + if (FAILED (hr)) { + write_log (L"SL IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); + return; + } + for (y = 0; y < TD_TOTAL_HEIGHT; y++) { + uae_u8 *buf = (uae_u8*)locked.pBits + y * locked.Pitch; + draw_status_line_single (buf, 32 / 8, y, ledwidth, rc, gc, bc, a); + } + IDirect3DTexture9_UnlockRect (ledtexture, 0); } static int createledtexture (void) { - ledwidth = window_w; - ledheight = TD_TOTAL_HEIGHT; - ledtexture = createtext (&ledwidth, &ledheight, D3DFMT_A8R8G8B8); - if (!ledtexture) - return 0; - return 1; + ledwidth = window_w; + ledheight = TD_TOTAL_HEIGHT; + ledtexture = createtext (&ledwidth, &ledheight, D3DFMT_A8R8G8B8); + if (!ledtexture) + return 0; + return 1; } static int createsltexture (void) { - UINT ww = required_sl_texture_w; - UINT hh = required_sl_texture_h; + UINT ww = required_sl_texture_w; + UINT hh = required_sl_texture_h; - sltexture = createtext (&ww, &hh, t_depth < 32 ? D3DFMT_A4R4G4B4 : D3DFMT_A8R8G8B8); - if (!sltexture) - return 0; - required_sl_texture_w = ww; - required_sl_texture_h = hh; - write_log (L"D3D: SL %d*%d texture allocated\n", ww, hh); - return 1; + sltexture = createtext (&ww, &hh, t_depth < 32 ? D3DFMT_A4R4G4B4 : D3DFMT_A8R8G8B8); + if (!sltexture) + return 0; + required_sl_texture_w = ww; + required_sl_texture_h = hh; + write_log (L"D3D: SL %d*%d texture allocated\n", ww, hh); + return 1; } static void setupscenescaled (void) { - HRESULT hr; - int v; - - // Set up the texture - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - switch (currprefs.gfx_filter_filtermode & 1) - { + HRESULT hr; + int v; + + // Set up the texture + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + hr = IDirect3DDevice9_SetTextureStageState (d3ddev, 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + switch (currprefs.gfx_filter_filtermode & 1) + { case 0: - v = D3DTEXF_POINT; - break; + v = D3DTEXF_POINT; + break; case 1: default: - v = D3DTEXF_LINEAR; - break; - } - hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MINFILTER, v); - hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MAGFILTER, v); - hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_ALPHABLENDENABLE, FALSE); + v = D3DTEXF_LINEAR; + break; + } + hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MINFILTER, v); + hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MAGFILTER, v); + hr = IDirect3DDevice9_SetSamplerState (d3ddev, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); + hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_ALPHABLENDENABLE, FALSE); } static void setupscenecoordssl (void) { - float w, h; + float w, h; - w = window_w; - h = window_h; + w = window_w; + h = window_h; - MatrixOrthoOffCenterLH (&m_matProj, 0.0f, (float)w, 0.0f, (float)h, 0.0f, 1.0f); - MatrixTranslation (&m_matView, - (float)w / 2 - 0.5, - (float)h / 2 + 0.5, - 0.0f); - MatrixScaling (&m_matWorld, w, h, 1.0f); + MatrixOrthoOffCenterLH (&m_matProj, 0.0f, (float)w, 0.0f, (float)h, 0.0f, 1.0f); + MatrixTranslation (&m_matView, + (float)w / 2 - 0.5, + (float)h / 2 + 0.5, + 0.0f); + MatrixScaling (&m_matWorld, w, h, 1.0f); } static void setupscenecoords (void) { - RECT sr, dr, zr; - float w, h; - float dw, dh; - static RECT sro, dro, zro; - -// write_log (L"%dx%d %dx%d %dx%d\n", twidth, theight, tin_w, tin_h, window_w, window_h); - - getfilterrect2 (&dr, &sr, &zr, window_w, window_h, tin_w, tin_h, 1, tin_w, tin_h); -// write_log (L"(%d %d %d %d) - (%d %d %d %d) (%d %d)\n", -// dr.left, dr.top, dr.right, dr.bottom, sr.left, sr.top, sr.right, sr.bottom, zr.left, zr.top); - - dw = dr.right - dr.left; - dh = dr.bottom - dr.top; - w = sr.right - sr.left; - h = sr.bottom - sr.top; -// write_log (L"%.1fx%.1f %.1fx%.1f\n", dw, dh, w, h); - - MatrixOrthoOffCenterLH (&m_matProj, 0, w, 0, h, 0.0f, 1.0f); - - MatrixTranslation (&m_matView, - -0.5f + dw * tin_w / window_w / 2 - zr.left - sr.left, // - (tin_w - 2 * zr.left - w), - +0.5f + dh * tin_h / window_h / 2 - zr.top - (tin_h - 2 * zr.top - h) + sr.top, // <- ??? - 0); - - MatrixScaling (&m_matWorld, - dw * tin_w / window_w, - dh * tin_h / window_h, - 1.0f); - - if (memcmp (&sr, &sro, sizeof (RECT)) || memcmp (&dr, &dro, sizeof (RECT)) || memcmp (&zr, &zro, sizeof (RECT))) { - needclear = 1; - sro = sr; - dro = dr; - zro = zr; - } + RECT sr, dr, zr; + float w, h; + float dw, dh; + static RECT sro, dro, zro; + + // write_log (L"%dx%d %dx%d %dx%d\n", twidth, theight, tin_w, tin_h, window_w, window_h); + + getfilterrect2 (&dr, &sr, &zr, window_w, window_h, tin_w, tin_h, 1, tin_w, tin_h); + // write_log (L"(%d %d %d %d) - (%d %d %d %d) (%d %d)\n", + // dr.left, dr.top, dr.right, dr.bottom, sr.left, sr.top, sr.right, sr.bottom, zr.left, zr.top); + + dw = dr.right - dr.left; + dh = dr.bottom - dr.top; + w = sr.right - sr.left; + h = sr.bottom - sr.top; + // write_log (L"%.1fx%.1f %.1fx%.1f\n", dw, dh, w, h); + + MatrixOrthoOffCenterLH (&m_matProj, 0, w, 0, h, 0.0f, 1.0f); + + MatrixTranslation (&m_matView, + -0.5f + dw * tin_w / window_w / 2 - zr.left - sr.left, // - (tin_w - 2 * zr.left - w), + +0.5f + dh * tin_h / window_h / 2 - zr.top - (tin_h - 2 * zr.top - h) + sr.top, // <- ??? + 0); + + MatrixScaling (&m_matWorld, + dw * tin_w / window_w, + dh * tin_h / window_h, + 1.0f); + + if (memcmp (&sr, &sro, sizeof (RECT)) || memcmp (&dr, &dro, sizeof (RECT)) || memcmp (&zr, &zro, sizeof (RECT))) { + needclear = 1; + sro = sr; + dro = dr; + zro = zr; + } } static void createvertex (void) { - HRESULT hr; - struct TLVERTEX *vertices; - float sizex, sizey; - - sizex = 1.0; - if (twidth > tin_w) - sizex = (float)tin_w / twidth; - sizey = 1.0; - if (theight > tin_h) - sizey = (float)tin_h / theight; - - hr = IDirect3DVertexBuffer9_Lock (vertexBuffer, 0, 0, (void**)&vertices, 0); - //Setup vertices - vertices[0].position.x = -0.5f; vertices[0].position.y = -0.5f; - vertices[0].diffuse = 0xFFFFFFFF; - vertices[0].texcoord.x = 0.0f; vertices[0].texcoord.y = sizey; - vertices[1].position.x = -0.5f; vertices[1].position.y = 0.5f; - vertices[1].diffuse = 0xFFFFFFFF; - vertices[1].texcoord.x = 0.0f; vertices[1].texcoord.y = 0.0f; - vertices[2].position.x = 0.5f; vertices[2].position.y = -0.5f; - vertices[2].diffuse = 0xFFFFFFFF; - vertices[2].texcoord.x = sizex; vertices[2].texcoord.y = sizey; - vertices[3].position.x = 0.5f; vertices[3].position.y = 0.5f; - vertices[3].diffuse = 0xFFFFFFFF; - vertices[3].texcoord.x = sizex; vertices[3].texcoord.y = 0.0f; - // Additional vertices required for some PS effects - if (psPreProcess) { - vertices[4].position.x = 0.0f; vertices[4].position.y = 0.0f; - vertices[4].diffuse = 0xFFFFFF00; - vertices[4].texcoord.x = 0.0f; vertices[4].texcoord.y = 1.0f; - vertices[5].position.x = 0.0f; vertices[5].position.y = 1.0f; - vertices[5].diffuse = 0xFFFFFF00; - vertices[5].texcoord.x = 0.0f; vertices[5].texcoord.y = 0.0f; - vertices[6].position.x = 1.0f; vertices[6].position.y = 0.0f; - vertices[6].diffuse = 0xFFFFFF00; - vertices[6].texcoord.x = 1.0f; vertices[6].texcoord.y = 1.0f; - vertices[7].position.x = 1.0f; vertices[7].position.y = 1.0f; - vertices[7].diffuse = 0xFFFFFF00; - vertices[7].texcoord.x = 1.0f; vertices[7].texcoord.y = 0.0f; - } - hr = IDirect3DVertexBuffer9_Unlock (vertexBuffer); + HRESULT hr; + struct TLVERTEX *vertices; + float sizex, sizey; + + sizex = 1.0; + if (twidth > tin_w) + sizex = (float)tin_w / twidth; + sizey = 1.0; + if (theight > tin_h) + sizey = (float)tin_h / theight; + + hr = IDirect3DVertexBuffer9_Lock (vertexBuffer, 0, 0, (void**)&vertices, 0); + //Setup vertices + vertices[0].position.x = -0.5f; vertices[0].position.y = -0.5f; + vertices[0].diffuse = 0xFFFFFFFF; + vertices[0].texcoord.x = 0.0f; vertices[0].texcoord.y = sizey; + vertices[1].position.x = -0.5f; vertices[1].position.y = 0.5f; + vertices[1].diffuse = 0xFFFFFFFF; + vertices[1].texcoord.x = 0.0f; vertices[1].texcoord.y = 0.0f; + vertices[2].position.x = 0.5f; vertices[2].position.y = -0.5f; + vertices[2].diffuse = 0xFFFFFFFF; + vertices[2].texcoord.x = sizex; vertices[2].texcoord.y = sizey; + vertices[3].position.x = 0.5f; vertices[3].position.y = 0.5f; + vertices[3].diffuse = 0xFFFFFFFF; + vertices[3].texcoord.x = sizex; vertices[3].texcoord.y = 0.0f; + // Additional vertices required for some PS effects + if (psPreProcess) { + vertices[4].position.x = 0.0f; vertices[4].position.y = 0.0f; + vertices[4].diffuse = 0xFFFFFF00; + vertices[4].texcoord.x = 0.0f; vertices[4].texcoord.y = 1.0f; + vertices[5].position.x = 0.0f; vertices[5].position.y = 1.0f; + vertices[5].diffuse = 0xFFFFFF00; + vertices[5].texcoord.x = 0.0f; vertices[5].texcoord.y = 0.0f; + vertices[6].position.x = 1.0f; vertices[6].position.y = 0.0f; + vertices[6].diffuse = 0xFFFFFF00; + vertices[6].texcoord.x = 1.0f; vertices[6].texcoord.y = 1.0f; + vertices[7].position.x = 1.0f; vertices[7].position.y = 1.0f; + vertices[7].diffuse = 0xFFFFFF00; + vertices[7].texcoord.x = 1.0f; vertices[7].texcoord.y = 0.0f; + } + hr = IDirect3DVertexBuffer9_Unlock (vertexBuffer); } static void settransformsl (void) { - HRESULT hr; + HRESULT hr; - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_PROJECTION, &m_matProj); - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_VIEW, &m_matView); - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_WORLD, &m_matWorld); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_PROJECTION, &m_matProj); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_VIEW, &m_matView); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_WORLD, &m_matWorld); } static void settransform (void) { - HRESULT hr; - - if (!psActive) { - // Disable Shaders - hr = IDirect3DDevice9_SetVertexShader (d3ddev, 0); - hr = IDirect3DDevice9_SetPixelShader (d3ddev, 0); - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_PROJECTION, &m_matProj); - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_VIEW, &m_matView); - hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_WORLD, &m_matWorld); - } else { - if (psPreProcess) { - // Projection is (0,0,0) -> (1,1,1) - MatrixOrthoOffCenterLH (&m_matPreProj, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); - // Align texels with pixels - MatrixTranslation (&m_matPreView, -0.5f / twidth, 0.5f / theight, 0.0f); - // Identity for world - D3DXMatrixIdentity (&m_matPreWorld); + HRESULT hr; + + if (!psActive) { + // Disable Shaders + hr = IDirect3DDevice9_SetVertexShader (d3ddev, 0); + hr = IDirect3DDevice9_SetPixelShader (d3ddev, 0); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_PROJECTION, &m_matProj); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_VIEW, &m_matView); + hr = IDirect3DDevice9_SetTransform (d3ddev, D3DTS_WORLD, &m_matWorld); } else { - psEffect_SetMatrices (&m_matProj, &m_matView, &m_matWorld); + if (psPreProcess) { + // Projection is (0,0,0) -> (1,1,1) + MatrixOrthoOffCenterLH (&m_matPreProj, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); + // Align texels with pixels + MatrixTranslation (&m_matPreView, -0.5f / twidth, 0.5f / theight, 0.0f); + // Identity for world + D3DXMatrixIdentity (&m_matPreWorld); + } else { + psEffect_SetMatrices (&m_matProj, &m_matView, &m_matWorld); + } } - } } static void createscanlines (int force) { - HRESULT hr; - D3DLOCKED_RECT locked; - static int osl1, osl2, osl3; - int sl4, sl42; - int l1, l2; - int x, y, yy; - uae_u8 *sld, *p; - int bpp; - - if (!sltexture) - return; - if (osl1 == currprefs.gfx_filter_scanlines && osl3 == currprefs.gfx_filter_scanlinelevel && osl2 == currprefs.gfx_filter_scanlineratio && !force) - return; - bpp = t_depth < 32 ? 2 : 4; - osl1 = currprefs.gfx_filter_scanlines; - osl3 = currprefs.gfx_filter_scanlinelevel; - osl2 = currprefs.gfx_filter_scanlineratio; - sl4 = currprefs.gfx_filter_scanlines * 16 / 100; - sl42 = currprefs.gfx_filter_scanlinelevel * 16 / 100; - if (sl4 > 15) - sl4 = 15; - if (sl42 > 15) - sl42 = 15; - l1 = currprefs.gfx_filter_scanlineratio & 15; - l2 = currprefs.gfx_filter_scanlineratio >> 4; - - hr = IDirect3DTexture9_LockRect (sltexture, 0, &locked, NULL, D3DLOCK_DISCARD); - if (FAILED (hr)) { - write_log (L"SL IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); - return; - } - sld = (uae_u8*)locked.pBits; - for (y = 0; y < required_sl_texture_h; y++) - memset (sld + y * locked.Pitch, 0, required_sl_texture_w * bpp); - for (y = 1; y < required_sl_texture_h; y += l1 + l2) { - for (yy = 0; yy < l2 && y + yy < required_sl_texture_h; yy++) { - for (x = 0; x < required_sl_texture_w; x++) { - uae_u8 sll = sl42; - p = &sld[(y + yy) * locked.Pitch + (x * bpp)]; - if (bpp < 4) { - /* 16-bit, A4R4G4B4 */ - p[1] = (sl4 << 4) | (sll << 0); - p[0] = (sll << 4) | (sll << 0); - } else { - /* 32-bit, A8R8G8B8 */ - uae_u8 sll4 = sl42 | (sl42 << 4); - uae_u8 sll2 = sll | (sll << 4); - p[0] = sll4; - p[1] = sll2; - p[2] = sll2; - p[3] = sll2; + HRESULT hr; + D3DLOCKED_RECT locked; + static int osl1, osl2, osl3; + int sl4, sl42; + int l1, l2; + int x, y, yy; + uae_u8 *sld, *p; + int bpp; + + if (!sltexture) + return; + if (osl1 == currprefs.gfx_filter_scanlines && osl3 == currprefs.gfx_filter_scanlinelevel && osl2 == currprefs.gfx_filter_scanlineratio && !force) + return; + bpp = t_depth < 32 ? 2 : 4; + osl1 = currprefs.gfx_filter_scanlines; + osl3 = currprefs.gfx_filter_scanlinelevel; + osl2 = currprefs.gfx_filter_scanlineratio; + sl4 = currprefs.gfx_filter_scanlines * 16 / 100; + sl42 = currprefs.gfx_filter_scanlinelevel * 16 / 100; + if (sl4 > 15) + sl4 = 15; + if (sl42 > 15) + sl42 = 15; + l1 = (currprefs.gfx_filter_scanlineratio >> 0) & 15; + l2 = (currprefs.gfx_filter_scanlineratio >> 4) & 15; + + hr = IDirect3DTexture9_LockRect (sltexture, 0, &locked, NULL, D3DLOCK_DISCARD); + if (FAILED (hr)) { + write_log (L"SL IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); + return; + } + sld = (uae_u8*)locked.pBits; + for (y = 0; y < required_sl_texture_h; y++) + memset (sld + y * locked.Pitch, 0, required_sl_texture_w * bpp); + for (y = 1; y < required_sl_texture_h; y += l1 + l2) { + for (yy = 0; yy < l2 && y + yy < required_sl_texture_h; yy++) { + for (x = 0; x < required_sl_texture_w; x++) { + uae_u8 sll = sl42; + p = &sld[(y + yy) * locked.Pitch + (x * bpp)]; + if (bpp < 4) { + /* 16-bit, A4R4G4B4 */ + p[1] = (sl4 << 4) | (sll << 0); + p[0] = (sll << 4) | (sll << 0); + } else { + /* 32-bit, A8R8G8B8 */ + uae_u8 sll4 = sl42 | (sl42 << 4); + uae_u8 sll2 = sll | (sll << 4); + p[0] = sll4; + p[1] = sll2; + p[2] = sll2; + p[3] = sll2; + } + } } - } } - } - IDirect3DTexture9_UnlockRect (sltexture, 0); + IDirect3DTexture9_UnlockRect (sltexture, 0); } static void invalidatedeviceobjects (void) { - if (texture) { - IDirect3DTexture9_Release (texture); - texture = NULL; - } - if (sprite) { - sprite->lpVtbl->Release (sprite); - sprite = NULL; - } - if (ledtexture) { - IDirect3DTexture9_Release (ledtexture); - ledtexture = NULL; - } - if (sltexture) { - IDirect3DTexture9_Release (sltexture); - sltexture = NULL; - } - if (lpWorkTexture1) { - IDirect3DTexture9_Release (lpWorkTexture1); - lpWorkTexture1 = NULL; - } - if (lpWorkTexture2) { - IDirect3DTexture9_Release (lpWorkTexture2); - lpWorkTexture2 = NULL; - } - if (lpHq2xLookupTexture) { - IDirect3DVolumeTexture9_Release (lpHq2xLookupTexture); - lpHq2xLookupTexture = NULL; - } - if (pEffect) { - pEffect->lpVtbl->Release (pEffect); - pEffect = NULL; - } - if (d3ddev) - IDirect3DDevice9_SetStreamSource (d3ddev, 0, NULL, 0, 0); - if (vertexBuffer) { - IDirect3DVertexBuffer9_Release (vertexBuffer); - vertexBuffer = NULL; - } - m_MatWorldEffectHandle = NULL; - m_MatViewEffectHandle = NULL; - m_MatProjEffectHandle = NULL; - m_MatWorldViewEffectHandle = NULL; - m_MatViewProjEffectHandle = NULL; - m_MatWorldViewProjEffectHandle = NULL; - m_SourceDimsEffectHandle = NULL; - m_TexelSizeEffectHandle = NULL; - m_SourceTextureEffectHandle = NULL; - m_WorkingTexture1EffectHandle = NULL; - m_WorkingTexture2EffectHandle = NULL; - m_Hq2xLookupTextureHandle = NULL; - m_PreprocessTechnique1EffectHandle = NULL; - m_PreprocessTechnique2EffectHandle = NULL; - m_CombineTechniqueEffectHandle = NULL; + if (texture) { + IDirect3DTexture9_Release (texture); + texture = NULL; + } + if (sprite) { + sprite->lpVtbl->Release (sprite); + sprite = NULL; + } + if (ledtexture) { + IDirect3DTexture9_Release (ledtexture); + ledtexture = NULL; + } + if (sltexture) { + IDirect3DTexture9_Release (sltexture); + sltexture = NULL; + } + if (lpWorkTexture1) { + IDirect3DTexture9_Release (lpWorkTexture1); + lpWorkTexture1 = NULL; + } + if (lpWorkTexture2) { + IDirect3DTexture9_Release (lpWorkTexture2); + lpWorkTexture2 = NULL; + } + if (lpHq2xLookupTexture) { + IDirect3DVolumeTexture9_Release (lpHq2xLookupTexture); + lpHq2xLookupTexture = NULL; + } + if (pEffect) { + pEffect->lpVtbl->Release (pEffect); + pEffect = NULL; + } + if (d3ddev) + IDirect3DDevice9_SetStreamSource (d3ddev, 0, NULL, 0, 0); + if (vertexBuffer) { + IDirect3DVertexBuffer9_Release (vertexBuffer); + vertexBuffer = NULL; + } + m_MatWorldEffectHandle = NULL; + m_MatViewEffectHandle = NULL; + m_MatProjEffectHandle = NULL; + m_MatWorldViewEffectHandle = NULL; + m_MatViewProjEffectHandle = NULL; + m_MatWorldViewProjEffectHandle = NULL; + m_SourceDimsEffectHandle = NULL; + m_TexelSizeEffectHandle = NULL; + m_SourceTextureEffectHandle = NULL; + m_WorkingTexture1EffectHandle = NULL; + m_WorkingTexture2EffectHandle = NULL; + m_Hq2xLookupTextureHandle = NULL; + m_PreprocessTechnique1EffectHandle = NULL; + m_PreprocessTechnique2EffectHandle = NULL; + m_CombineTechniqueEffectHandle = NULL; } static int restoredeviceobjects (void) { - int vbsize; - HRESULT hr; - - invalidatedeviceobjects (); - if (currprefs.gfx_filtershader[0]) { - if (!psEnabled || !psEffect_LoadEffect (currprefs.gfx_filtershader)) - currprefs.gfx_filtershader[0] = changed_prefs.gfx_filtershader[0] = 0; - } - if (!createtexture (tin_w, tin_h)) - return 0; - if (currprefs.gfx_filter_scanlines > 0) - createsltexture (); - createledtexture (); - - vbsize = sizeof (struct TLVERTEX) * 4; - if (psPreProcess) - vbsize = sizeof (struct TLVERTEX) * 8; - hr = IDirect3DDevice9_SetFVF (d3ddev, D3DFVF_TLVERTEX); - if (FAILED (IDirect3DDevice9_CreateVertexBuffer (d3ddev, vbsize, D3DUSAGE_WRITEONLY, - D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL))) { - write_log (L"D3D: failed to create vertex buffer: %s\n", D3D_ErrorString (hr)); - return 0; - } - createvertex (); - hr = IDirect3DDevice9_SetStreamSource (d3ddev, 0, vertexBuffer, 0, sizeof (struct TLVERTEX)); - - // Turn off culling - hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_CULLMODE, D3DCULL_NONE); - // turn off lighting - hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_LIGHTING, FALSE); - // turn of zbuffer - hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_ZENABLE, FALSE); - - setupscenescaled (); - setupscenecoords (); - settransform (); - - return 1; + int vbsize; + HRESULT hr; + + invalidatedeviceobjects (); + if (currprefs.gfx_filtershader[0]) { + if (!psEnabled || !psEffect_LoadEffect (currprefs.gfx_filtershader)) + currprefs.gfx_filtershader[0] = changed_prefs.gfx_filtershader[0] = 0; + } + if (!createtexture (tin_w, tin_h)) + return 0; + if (currprefs.gfx_filter_scanlines > 0) + createsltexture (); + createledtexture (); + + vbsize = sizeof (struct TLVERTEX) * 4; + if (psPreProcess) + vbsize = sizeof (struct TLVERTEX) * 8; + hr = IDirect3DDevice9_SetFVF (d3ddev, D3DFVF_TLVERTEX); + if (FAILED (IDirect3DDevice9_CreateVertexBuffer (d3ddev, vbsize, D3DUSAGE_WRITEONLY, + D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL))) { + write_log (L"D3D: failed to create vertex buffer: %s\n", D3D_ErrorString (hr)); + return 0; + } + createvertex (); + hr = IDirect3DDevice9_SetStreamSource (d3ddev, 0, vertexBuffer, 0, sizeof (struct TLVERTEX)); + + // Turn off culling + hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_CULLMODE, D3DCULL_NONE); + // turn off lighting + hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_LIGHTING, FALSE); + // turn of zbuffer + hr = IDirect3DDevice9_SetRenderState (d3ddev, D3DRS_ZENABLE, FALSE); + + setupscenescaled (); + setupscenecoords (); + settransform (); + + return 1; } void D3D_free (void) { - D3D_clear (); - invalidatedeviceobjects (); - if (d3ddev) { - IDirect3DDevice9_Release (d3ddev); - d3ddev = NULL; - } - if (d3d) { - IDirect3D9_Release (d3d); - d3d = NULL; - } - d3d_enabled = 0; - psPreProcess = 0; - psActive = 0; - resetcount = 0; - changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen & ~STATUSLINE_TARGET; + D3D_clear (); + invalidatedeviceobjects (); + if (d3ddev) { + IDirect3DDevice9_Release (d3ddev); + d3ddev = NULL; + } + if (d3d) { + IDirect3D9_Release (d3d); + d3d = NULL; + } + d3d_enabled = 0; + psPreProcess = 0; + psActive = 0; + resetcount = 0; + changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen & ~STATUSLINE_TARGET; } const TCHAR *D3D_init (HWND ahwnd, int w_w, int w_h, int t_w, int t_h, int depth) { - HRESULT ret, hr; - static TCHAR errmsg[100] = { 0 }; - D3DDISPLAYMODE mode; - D3DDISPLAYMODEEX modeex; - D3DCAPS9 d3dCaps; - int adapter; - DWORD flags; - HINSTANCE d3dDLL, d3dx; - - D3D_free (); - D3D_canshaders (); - d3d_enabled = 0; - if (currprefs.gfx_filter != UAE_FILTER_DIRECT3D) { - _tcscpy (errmsg, L"D3D: not enabled"); - return errmsg; - } - d3dx = LoadLibrary (L"d3dx9_42.dll"); - if (d3dx == NULL) { - _tcscpy (errmsg, L"Direct3D: August 2009 or newer DirectX Runtime required.\n\nhttp://go.microsoft.com/fwlink/?linkid=56513"); - if (isfullscreen () <= 0) - ShellExecute(NULL, L"open", L"http://go.microsoft.com/fwlink/?linkid=56513", NULL, NULL, SW_SHOWNORMAL); - return errmsg; - } - FreeLibrary (d3dx); - - d3d_ex = FALSE; - d3dDLL = LoadLibrary (L"D3D9.DLL"); - if (d3dDLL == NULL) { - _tcscpy (errmsg, L"Direct3D: DirectX 9 or newer required"); - return errmsg; - } else { - typedef HRESULT (WINAPI *LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**); - LPDIRECT3DCREATE9EX d3dexp = (LPDIRECT3DCREATE9EX)GetProcAddress (d3dDLL, "Direct3DCreate9Ex"); - if (d3dexp) - d3d_ex = TRUE; - } - FreeLibrary (d3dDLL); - hr = -1; - if (d3d_ex && D3DEX) { - hr = Direct3DCreate9Ex (D3D_SDK_VERSION, &d3dex); - if (FAILED (hr)) - write_log (L"Direct3D: failed to create D3DEx object: %s\n", D3D_ErrorString (hr)); - d3d = (IDirect3D9*)d3dex; - } - if (FAILED (hr)) { - d3dex = NULL; - d3d = Direct3DCreate9 (D3D_SDK_VERSION); - if (d3d == NULL) { - D3D_free (); - _tcscpy (errmsg, L"Direct3D: failed to create D3D object"); - return errmsg; - } - } - - adapter = currprefs.gfx_display - 1; - if (adapter < 0) - adapter = 0; - if (adapter >= IDirect3D9_GetAdapterCount (d3d)) - adapter = 0; - - modeex.Size = sizeof modeex; - if (d3dex && D3DEX) { - LUID luid; - hr = IDirect3D9Ex_GetAdapterLUID (d3dex, adapter, &luid); - hr = IDirect3D9Ex_GetAdapterDisplayModeEx (d3dex, adapter, &modeex, NULL); - } - if (FAILED (hr = IDirect3D9_GetAdapterDisplayMode (d3d, adapter, &mode))) - write_log (L"D3D: IDirect3D9_GetAdapterDisplayMode failed %s\n", D3D_ErrorString (hr)); - if (FAILED (hr = IDirect3D9_GetDeviceCaps (d3d, adapter, D3DDEVTYPE_HAL, &d3dCaps))) - write_log (L"D3D: IDirect3D9_GetDeviceCaps failed %s\n", D3D_ErrorString (hr)); - - memset (&dpp, 0, sizeof (dpp)); - dpp.Windowed = isfullscreen() <= 0; - dpp.BackBufferFormat = mode.Format; - dpp.BackBufferCount = 1; - dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; - dpp.BackBufferWidth = w_w; - dpp.BackBufferHeight = w_h; - dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - - modeex.Width = w_w; - modeex.Height = w_h; - modeex.RefreshRate = 0; - modeex.ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE; - modeex.Format = mode.Format; - - vsync2 = 0; - if (isfullscreen() > 0) { - dpp.FullScreen_RefreshRateInHz = currprefs.gfx_refreshrate > 0 ? currprefs.gfx_refreshrate : 0; - modeex.RefreshRate = dpp.FullScreen_RefreshRateInHz; - if (currprefs.gfx_avsync > 0) { - dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - if (getvsyncrate (dpp.FullScreen_RefreshRateInHz) != dpp.FullScreen_RefreshRateInHz) { - if (d3dCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) - dpp.PresentationInterval = D3DPRESENT_INTERVAL_TWO; - else - vsync2 = 1; - } - } - } - - d3dhwnd = ahwnd; - - // Check if hardware vertex processing is available - if(d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) - flags = D3DCREATE_HARDWARE_VERTEXPROCESSING; - else - flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; - flags |= D3DCREATE_NOWINDOWCHANGES | D3DCREATE_FPU_PRESERVE; - - if (d3d_ex && D3DEX) { - ret = IDirect3D9Ex_CreateDeviceEx (d3dex, adapter, D3DDEVTYPE_HAL, d3dhwnd, flags, &dpp, &modeex, &d3ddevex); - d3ddev = (LPDIRECT3DDEVICE9)d3ddevex; - } else { - ret = IDirect3D9_CreateDevice (d3d, adapter, D3DDEVTYPE_HAL, d3dhwnd, flags, &dpp, &d3ddev); - } - if (FAILED (ret)) { - _stprintf (errmsg, L"%s failed, %s\n", d3d_ex && D3DEX ? L"CreateDeviceEx" : L"CreateDevice", D3D_ErrorString (ret)); + HRESULT ret, hr; + static TCHAR errmsg[100] = { 0 }; + D3DDISPLAYMODE mode; + D3DDISPLAYMODEEX modeex; + D3DCAPS9 d3dCaps; + int adapter; + DWORD flags; + HINSTANCE d3dDLL, d3dx; + D3D_free (); - return errmsg; - } - - if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) - tex_square = TRUE; - if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_POW2) { - if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) { - tex_pow2 = FALSE; - } else { - tex_pow2 = TRUE; - } - } else { - tex_pow2 = FALSE; - } - if(d3dCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) - tex_dynamic = TRUE; - - if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) { - if((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && tex_dynamic && !tex_pow2 && !tex_square) { - psEnabled = TRUE; + D3D_canshaders (); + d3d_enabled = 0; + if (currprefs.gfx_filter != UAE_FILTER_DIRECT3D) { + _tcscpy (errmsg, L"D3D: not enabled"); + return errmsg; + } + d3dx = LoadLibrary (L"d3dx9_42.dll"); + if (d3dx == NULL) { + _tcscpy (errmsg, L"Direct3D: August 2009 or newer DirectX Runtime required.\n\nhttp://go.microsoft.com/fwlink/?linkid=56513"); + if (isfullscreen () <= 0) + ShellExecute(NULL, L"open", L"http://go.microsoft.com/fwlink/?linkid=56513", NULL, NULL, SW_SHOWNORMAL); + return errmsg; + } + FreeLibrary (d3dx); + + d3d_ex = FALSE; + d3dDLL = LoadLibrary (L"D3D9.DLL"); + if (d3dDLL == NULL) { + _tcscpy (errmsg, L"Direct3D: DirectX 9 or newer required"); + return errmsg; } else { - psEnabled = FALSE; - } - }else { - psEnabled = FALSE; - } - - max_texture_w = d3dCaps.MaxTextureWidth; - max_texture_h = d3dCaps.MaxTextureHeight; - - write_log (L"D3D: PS=%d.%d VS=%d.%d Square=%d, Pow2=%d, Dyn=%d, %d*%d\n", - (d3dCaps.PixelShaderVersion >> 8) & 0xff, d3dCaps.PixelShaderVersion & 0xff, - (d3dCaps.VertexShaderVersion >> 8) & 0xff, d3dCaps.VertexShaderVersion & 0xff, - tex_square, tex_pow2, tex_dynamic, - max_texture_w, max_texture_h); - - if (max_texture_w < t_w || max_texture_h < t_h) { - _stprintf (errmsg, L"Direct3D: %d * %d or bigger texture support required\nYour card's maximum texture size is only %d * %d", - t_w, t_h, max_texture_w, max_texture_h); - return errmsg; - } - - required_sl_texture_w = w_w; - required_sl_texture_h = w_h; - if (currprefs.gfx_filter_scanlines > 0 && (max_texture_w < w_w || max_texture_h < w_h)) { - gui_message (L"Direct3D: %d * %d or bigger texture support required for scanlines (max is only %d * %d)\n" - L"Scanlines disabled.", - required_sl_texture_w, required_sl_texture_h, max_texture_w, max_texture_h); - changed_prefs.gfx_filter_scanlines = currprefs.gfx_filter_scanlines = 0; - } - - t_depth = depth; - switch (depth) - { - case 32: - if (currprefs.gfx_filter_scanlines) - tformat = D3DFMT_A8R8G8B8; + typedef HRESULT (WINAPI *LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**); + LPDIRECT3DCREATE9EX d3dexp = (LPDIRECT3DCREATE9EX)GetProcAddress (d3dDLL, "Direct3DCreate9Ex"); + if (d3dexp) + d3d_ex = TRUE; + } + FreeLibrary (d3dDLL); + hr = -1; + if (d3d_ex && D3DEX) { + hr = Direct3DCreate9Ex (D3D_SDK_VERSION, &d3dex); + if (FAILED (hr)) + write_log (L"Direct3D: failed to create D3DEx object: %s\n", D3D_ErrorString (hr)); + d3d = (IDirect3D9*)d3dex; + } + if (FAILED (hr)) { + d3dex = NULL; + d3d = Direct3DCreate9 (D3D_SDK_VERSION); + if (d3d == NULL) { + D3D_free (); + _tcscpy (errmsg, L"Direct3D: failed to create D3D object"); + return errmsg; + } + } + + adapter = currprefs.gfx_display - 1; + if (adapter < 0) + adapter = 0; + if (adapter >= IDirect3D9_GetAdapterCount (d3d)) + adapter = 0; + + modeex.Size = sizeof modeex; + if (d3dex && D3DEX) { + LUID luid; + hr = IDirect3D9Ex_GetAdapterLUID (d3dex, adapter, &luid); + hr = IDirect3D9Ex_GetAdapterDisplayModeEx (d3dex, adapter, &modeex, NULL); + } + if (FAILED (hr = IDirect3D9_GetAdapterDisplayMode (d3d, adapter, &mode))) + write_log (L"D3D: IDirect3D9_GetAdapterDisplayMode failed %s\n", D3D_ErrorString (hr)); + if (FAILED (hr = IDirect3D9_GetDeviceCaps (d3d, adapter, D3DDEVTYPE_HAL, &d3dCaps))) + write_log (L"D3D: IDirect3D9_GetDeviceCaps failed %s\n", D3D_ErrorString (hr)); + + memset (&dpp, 0, sizeof (dpp)); + dpp.Windowed = isfullscreen() <= 0; + dpp.BackBufferFormat = mode.Format; + dpp.BackBufferCount = 1; + dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; + dpp.BackBufferWidth = w_w; + dpp.BackBufferHeight = w_h; + dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + + modeex.Width = w_w; + modeex.Height = w_h; + modeex.RefreshRate = 0; + modeex.ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE; + modeex.Format = mode.Format; + + vsync2 = 0; + if (isfullscreen() > 0) { + dpp.FullScreen_RefreshRateInHz = currprefs.gfx_refreshrate > 0 ? currprefs.gfx_refreshrate : 0; + modeex.RefreshRate = dpp.FullScreen_RefreshRateInHz; + if (currprefs.gfx_avsync > 0) { + dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + if (getvsyncrate (dpp.FullScreen_RefreshRateInHz) != dpp.FullScreen_RefreshRateInHz) { + if (d3dCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) + dpp.PresentationInterval = D3DPRESENT_INTERVAL_TWO; + else + vsync2 = 1; + } + } + } + + d3dhwnd = ahwnd; + + // Check if hardware vertex processing is available + if(d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) + flags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else - tformat = D3DFMT_X8R8G8B8; - break; + flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; + flags |= D3DCREATE_NOWINDOWCHANGES | D3DCREATE_FPU_PRESERVE; + + if (d3d_ex && D3DEX) { + ret = IDirect3D9Ex_CreateDeviceEx (d3dex, adapter, D3DDEVTYPE_HAL, d3dhwnd, flags, &dpp, &modeex, &d3ddevex); + d3ddev = (LPDIRECT3DDEVICE9)d3ddevex; + } else { + ret = IDirect3D9_CreateDevice (d3d, adapter, D3DDEVTYPE_HAL, d3dhwnd, flags, &dpp, &d3ddev); + } + if (FAILED (ret)) { + _stprintf (errmsg, L"%s failed, %s\n", d3d_ex && D3DEX ? L"CreateDeviceEx" : L"CreateDevice", D3D_ErrorString (ret)); + D3D_free (); + return errmsg; + } + + if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) + tex_square = TRUE; + if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_POW2) { + if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) { + tex_pow2 = FALSE; + } else { + tex_pow2 = TRUE; + } + } else { + tex_pow2 = FALSE; + } + if(d3dCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) + tex_dynamic = TRUE; + + if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(2,0)) { + if((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && tex_dynamic && !tex_pow2 && !tex_square) { + psEnabled = TRUE; + } else { + psEnabled = FALSE; + } + }else { + psEnabled = FALSE; + } + + max_texture_w = d3dCaps.MaxTextureWidth; + max_texture_h = d3dCaps.MaxTextureHeight; + + write_log (L"D3D: PS=%d.%d VS=%d.%d Square=%d, Pow2=%d, Dyn=%d, %d*%d\n", + (d3dCaps.PixelShaderVersion >> 8) & 0xff, d3dCaps.PixelShaderVersion & 0xff, + (d3dCaps.VertexShaderVersion >> 8) & 0xff, d3dCaps.VertexShaderVersion & 0xff, + tex_square, tex_pow2, tex_dynamic, + max_texture_w, max_texture_h); + + if (max_texture_w < t_w || max_texture_h < t_h) { + _stprintf (errmsg, L"Direct3D: %d * %d or bigger texture support required\nYour card's maximum texture size is only %d * %d", + t_w, t_h, max_texture_w, max_texture_h); + return errmsg; + } + + required_sl_texture_w = w_w; + required_sl_texture_h = w_h; + if (currprefs.gfx_filter_scanlines > 0 && (max_texture_w < w_w || max_texture_h < w_h)) { + gui_message (L"Direct3D: %d * %d or bigger texture support required for scanlines (max is only %d * %d)\n" + L"Scanlines disabled.", + required_sl_texture_w, required_sl_texture_h, max_texture_w, max_texture_h); + changed_prefs.gfx_filter_scanlines = currprefs.gfx_filter_scanlines = 0; + } + + t_depth = depth; + switch (depth) + { + case 32: + if (currprefs.gfx_filter_scanlines) + tformat = D3DFMT_A8R8G8B8; + else + tformat = D3DFMT_X8R8G8B8; + break; case 15: case 16: - if (currprefs.gfx_filter_scanlines) - tformat = D3DFMT_A1R5G5B5; - else - tformat = D3DFMT_X1R5G5B5; - break; - } - window_w = w_w; - window_h = w_h; - tin_w = t_w; - tin_h = t_h; - if (!restoredeviceobjects ()) { - D3D_free (); - _stprintf (errmsg, L"Direct3D: texture creation failed"); - return errmsg; - } + if (currprefs.gfx_filter_scanlines) + tformat = D3DFMT_A1R5G5B5; + else + tformat = D3DFMT_X1R5G5B5; + break; + } + window_w = w_w; + window_h = w_h; + tin_w = t_w; + tin_h = t_h; + if (!restoredeviceobjects ()) { + D3D_free (); + _stprintf (errmsg, L"Direct3D: texture creation failed"); + return errmsg; + } - changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen | STATUSLINE_TARGET; + changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen | STATUSLINE_TARGET; - hr = D3DXCreateSprite (d3ddev, &sprite); - if (FAILED (hr)) { - write_log (L"LED D3DXSprite filaed: %s\n", D3D_ErrorString (hr)); - } + hr = D3DXCreateSprite (d3ddev, &sprite); + if (FAILED (hr)) { + write_log (L"LED D3DXSprite filaed: %s\n", D3D_ErrorString (hr)); + } - createscanlines (1); - d3d_enabled = 1; - return 0; + createscanlines (1); + d3d_enabled = 1; + return 0; } int D3D_needreset (void) { - HRESULT hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); - if (hr == D3DERR_DEVICENOTRESET) { - hr = IDirect3DDevice9_Reset (d3ddev, &dpp); - if (FAILED (hr)) { - write_log (L"D3D: Reset failed %s\n", D3D_ErrorString (hr)); - resetcount++; - if (resetcount > 2) - changed_prefs.gfx_filter = 0; + HRESULT hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); + if (hr == D3DERR_DEVICENOTRESET) { + hr = IDirect3DDevice9_Reset (d3ddev, &dpp); + if (FAILED (hr)) { + write_log (L"D3D: Reset failed %s\n", D3D_ErrorString (hr)); + resetcount++; + if (resetcount > 2) + changed_prefs.gfx_filter = 0; + } + return 1; } - return 1; - } - return 0; + return 0; } void D3D_clear (void) { - int i; - HRESULT hr; - - if (!d3ddev) - return; - hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); - if (FAILED (hr)) - return; - for (i = 0; i < 2; i++) { - IDirect3DDevice9_Clear (d3ddev, 0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0L); - IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); - } + int i; + HRESULT hr; + + if (!d3ddev) + return; + hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); + if (FAILED (hr)) + return; + for (i = 0; i < 2; i++) { + IDirect3DDevice9_Clear (d3ddev, 0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0L); + IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); + } } static void D3D_render22 (int clear) { - HRESULT hr; + HRESULT hr; - if (!d3d_enabled) - return; - if (FAILED (IDirect3DDevice9_TestCooperativeLevel (d3ddev))) - return; - - if (clear) { - setupscenescaled (); - } - setupscenecoords (); - settransform (); - if (clear || needclear) { - int i; - for (i = 0; i < 2; i++) { - hr = IDirect3DDevice9_Clear (d3ddev, 0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0L ); - if (FAILED (hr)) - write_log (L"IDirect3DDevice9_Clear() failed: %s\n", D3D_ErrorString (hr)); - IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); - } - needclear = 0; - } - hr = IDirect3DDevice9_BeginScene (d3ddev); - if (psActive) { - UINT uPasses, uPass; - LPDIRECT3DSURFACE9 lpRenderTarget; - LPDIRECT3DSURFACE9 lpNewRenderTarget; - LPDIRECT3DTEXTURE9 lpWorkTexture; - - if (!psEffect_SetTextures (texture, lpWorkTexture1, lpWorkTexture2, lpHq2xLookupTexture)) - return; - if (psPreProcess) { - if (!psEffect_SetMatrices (&m_matPreProj, &m_matPreView, &m_matPreWorld)) - return; - IDirect3DDevice9_GetRenderTarget (d3ddev, 0, &lpRenderTarget); - lpWorkTexture = lpWorkTexture1; - pass2: - IDirect3DTexture9_GetSurfaceLevel (lpWorkTexture, 0, &lpNewRenderTarget); - if (FAILED (hr = IDirect3DDevice9_SetRenderTarget (d3ddev, 0, lpNewRenderTarget))) { - write_log (L"D3D: IDirect3DDevice9_SetRenderTarget: %s\n", D3D_ErrorString (hr)); + if (!d3d_enabled) return; - } - if (lpRenderTarget) - IDirect3DSurface9_Release (lpRenderTarget); - uPasses = 0; - if (!psEffect_Begin ((lpWorkTexture == lpWorkTexture1) ? - psEffect_PreProcess1 : psEffect_PreProcess2, &uPasses)) - return; - for (uPass = 0; uPass < uPasses; uPass++) { - if (!psEffect_BeginPass (uPass)) - return; - IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 4, 2); - psEffect_EndPass (); - } - if (!psEffect_End ()) - return; - if (psEffect_hasPreProcess2 () && lpWorkTexture == lpWorkTexture1) { - lpWorkTexture = lpWorkTexture2; - goto pass2; - } - IDirect3DDevice9_SetRenderTarget (d3ddev, 0, lpRenderTarget); - if (lpRenderTarget) - IDirect3DTexture9_Release (lpRenderTarget); - if (!psEffect_SetMatrices (&m_matProj, &m_matView, &m_matWorld)) + if (FAILED (IDirect3DDevice9_TestCooperativeLevel (d3ddev))) return; + + if (clear) { + setupscenescaled (); } - uPasses = 0; - if (!psEffect_Begin (psEffect_Combine, &uPasses)) - return; - for (uPass = 0; uPass < uPasses; uPass++) { - if (!psEffect_BeginPass (uPass)) - return; - IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 0, 2); - psEffect_EndPass (); + setupscenecoords (); + settransform (); + if (clear || needclear) { + int i; + for (i = 0; i < 2; i++) { + hr = IDirect3DDevice9_Clear (d3ddev, 0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0L ); + if (FAILED (hr)) + write_log (L"IDirect3DDevice9_Clear() failed: %s\n", D3D_ErrorString (hr)); + IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); + } + needclear = 0; } - if (!psEffect_End ()) - return; - - } else { + hr = IDirect3DDevice9_BeginScene (d3ddev); + if (psActive) { + UINT uPasses, uPass; + LPDIRECT3DSURFACE9 lpRenderTarget; + LPDIRECT3DSURFACE9 lpNewRenderTarget; + LPDIRECT3DTEXTURE9 lpWorkTexture; + + if (!psEffect_SetTextures (texture, lpWorkTexture1, lpWorkTexture2, lpHq2xLookupTexture)) + return; + if (psPreProcess) { + if (!psEffect_SetMatrices (&m_matPreProj, &m_matPreView, &m_matPreWorld)) + return; + IDirect3DDevice9_GetRenderTarget (d3ddev, 0, &lpRenderTarget); + lpWorkTexture = lpWorkTexture1; +pass2: + IDirect3DTexture9_GetSurfaceLevel (lpWorkTexture, 0, &lpNewRenderTarget); + if (FAILED (hr = IDirect3DDevice9_SetRenderTarget (d3ddev, 0, lpNewRenderTarget))) { + write_log (L"D3D: IDirect3DDevice9_SetRenderTarget: %s\n", D3D_ErrorString (hr)); + return; + } + if (lpRenderTarget) + IDirect3DSurface9_Release (lpRenderTarget); + uPasses = 0; + if (!psEffect_Begin ((lpWorkTexture == lpWorkTexture1) ? +psEffect_PreProcess1 : psEffect_PreProcess2, &uPasses)) + return; + for (uPass = 0; uPass < uPasses; uPass++) { + if (!psEffect_BeginPass (uPass)) + return; + IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 4, 2); + psEffect_EndPass (); + } + if (!psEffect_End ()) + return; + if (psEffect_hasPreProcess2 () && lpWorkTexture == lpWorkTexture1) { + lpWorkTexture = lpWorkTexture2; + goto pass2; + } + IDirect3DDevice9_SetRenderTarget (d3ddev, 0, lpRenderTarget); + if (lpRenderTarget) + IDirect3DTexture9_Release (lpRenderTarget); + if (!psEffect_SetMatrices (&m_matProj, &m_matView, &m_matWorld)) + return; + } + uPasses = 0; + if (!psEffect_Begin (psEffect_Combine, &uPasses)) + return; + for (uPass = 0; uPass < uPasses; uPass++) { + if (!psEffect_BeginPass (uPass)) + return; + IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 0, 2); + psEffect_EndPass (); + } + if (!psEffect_End ()) + return; - hr = IDirect3DDevice9_SetTexture (d3ddev, 0, (IDirect3DBaseTexture9*)texture); - hr = IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 0, 2); + } else { - } + hr = IDirect3DDevice9_SetTexture (d3ddev, 0, (IDirect3DBaseTexture9*)texture); + hr = IDirect3DDevice9_DrawPrimitive (d3ddev, D3DPT_TRIANGLESTRIP, 0, 2); - if (sprite && (sltexture || ledtexture)) { - D3DXVECTOR3 v; - sprite->lpVtbl->Begin (sprite, D3DXSPRITE_ALPHABLEND); - if (sltexture) { - v.x = v.y = v.z = 0; - sprite->lpVtbl->Draw (sprite, sltexture, NULL, NULL, &v, 0xffffffff); } - if (ledtexture) { - v.x = 0; - v.y = window_h - TD_TOTAL_HEIGHT; - v.z = 0; - sprite->lpVtbl->Draw (sprite, ledtexture, NULL, NULL, &v, 0xffffffff); + + if (sprite && (sltexture || ledtexture)) { + D3DXVECTOR3 v; + sprite->lpVtbl->Begin (sprite, D3DXSPRITE_ALPHABLEND); + if (sltexture) { + v.x = v.y = v.z = 0; + sprite->lpVtbl->Draw (sprite, sltexture, NULL, NULL, &v, 0xffffffff); + } + if (ledtexture) { + v.x = 0; + v.y = window_h - TD_TOTAL_HEIGHT; + v.z = 0; + sprite->lpVtbl->Draw (sprite, ledtexture, NULL, NULL, &v, 0xffffffff); + } + sprite->lpVtbl->End (sprite); } - sprite->lpVtbl->End (sprite); - } - hr = IDirect3DDevice9_EndScene (d3ddev); - hr = IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); + hr = IDirect3DDevice9_EndScene (d3ddev); + hr = IDirect3DDevice9_Present (d3ddev, NULL, NULL, NULL, NULL); } static void D3D_render2 (int clear) { - int fpuv; + int fpuv; - fpux_save (&fpuv); - D3D_render22 (clear); - fpux_restore (&fpuv); + fpux_save (&fpuv); + D3D_render22 (clear); + fpux_restore (&fpuv); } void D3D_render (void) { - D3D_render2 (1); + D3D_render2 (1); } void D3D_unlocktexture (void) { - HRESULT hr; - RECT r; + HRESULT hr; + RECT r; - if (currprefs.leds_on_screen & STATUSLINE_CHIPSET) - updateleds (); + if (currprefs.leds_on_screen & STATUSLINE_CHIPSET) + updateleds (); - hr = IDirect3DTexture9_UnlockRect (texture, 0); - r.left = 0; r.right = window_w; - r.top = 0; r.bottom = window_h; - hr = IDirect3DTexture9_AddDirtyRect (texture, &r); + hr = IDirect3DTexture9_UnlockRect (texture, 0); + r.left = 0; r.right = window_w; + r.top = 0; r.bottom = window_h; + hr = IDirect3DTexture9_AddDirtyRect (texture, &r); - D3D_render2 (0); - if (vsync2 && !currprefs.turbo_emulation) D3D_render2 (0); + if (vsync2 && !currprefs.turbo_emulation) + D3D_render2 (0); } int D3D_locktexture (void) { - D3DLOCKED_RECT locked; - HRESULT hr; + D3DLOCKED_RECT locked; + HRESULT hr; - hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); - if (FAILED (hr)) { - if (hr == D3DERR_DEVICELOST) { - if (!dpp.Windowed && IsWindow (d3dhwnd) && !IsIconic (d3dhwnd)) { - write_log (L"D3D: minimize\n"); - ShowWindow (d3dhwnd, SW_MINIMIZE); - } + hr = IDirect3DDevice9_TestCooperativeLevel (d3ddev); + if (FAILED (hr)) { + if (hr == D3DERR_DEVICELOST) { + if (!dpp.Windowed && IsWindow (d3dhwnd) && !IsIconic (d3dhwnd)) { + write_log (L"D3D: minimize\n"); + ShowWindow (d3dhwnd, SW_MINIMIZE); + } + } + return 0; } - return 0; - } - - locked.pBits = NULL; - locked.Pitch = 0; - hr = IDirect3DTexture9_LockRect (texture, 0, &locked, NULL, D3DLOCK_NO_DIRTY_UPDATE); - if (FAILED (hr)) { - if (hr != D3DERR_DRIVERINTERNALERROR) { - write_log (L"IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); - D3D_unlocktexture (); - return 0; - } - } - if (locked.pBits == NULL || locked.Pitch == 0) { - write_log (L"IDirect3DTexture9_LockRect return NULL texture\n"); - D3D_unlocktexture (); - return 0; - } - gfxvidinfo.bufmem = locked.pBits; - gfxvidinfo.rowbytes = locked.Pitch; - init_row_map (); - return 1; + + locked.pBits = NULL; + locked.Pitch = 0; + hr = IDirect3DTexture9_LockRect (texture, 0, &locked, NULL, D3DLOCK_NO_DIRTY_UPDATE); + if (FAILED (hr)) { + if (hr != D3DERR_DRIVERINTERNALERROR) { + write_log (L"IDirect3DTexture9_LockRect failed: %s\n", D3D_ErrorString (hr)); + D3D_unlocktexture (); + return 0; + } + } + if (locked.pBits == NULL || locked.Pitch == 0) { + write_log (L"IDirect3DTexture9_LockRect return NULL texture\n"); + D3D_unlocktexture (); + return 0; + } + gfxvidinfo.bufmem = locked.pBits; + gfxvidinfo.rowbytes = locked.Pitch; + init_row_map (); + return 1; } void D3D_refresh (void) { - if (!d3d_enabled) - return; - createscanlines (1); - D3D_render2 (1); + if (!d3d_enabled) + return; + createscanlines (1); + D3D_render2 (1); } void D3D_getpixelformat (int depth,int *rb, int *gb, int *bb, int *rs, int *gs, int *bs, int *ab, int *as, int *a) { - switch (depth) - { - case 32: - *rb = 8; - *gb = 8; - *bb = 8; - *ab = 8; - *rs = 16; - *gs = 8; - *bs = 0; - *as = 24; - *a = 255; - break; - case 15: - case 16: - *rb = 5; - *gb = 5; - *bb = 5; - *ab = 1; - *rs = 10; - *gs = 5; - *bs = 0; - *as = 15; - *a = 1; - break; - } + switch (depth) + { + case 32: + *rb = 8; + *gb = 8; + *bb = 8; + *ab = 8; + *rs = 16; + *gs = 8; + *bs = 0; + *as = 24; + *a = 255; + break; + case 15: + case 16: + *rb = 5; + *gb = 5; + *bb = 5; + *ab = 1; + *rs = 10; + *gs = 5; + *bs = 0; + *as = 15; + *a = 1; + break; + } } void D3D_guimode (int guion) { - HRESULT hr; - if (!d3d_enabled) - return; - hr = IDirect3DDevice9_SetDialogBoxMode (d3ddev, guion); - if (FAILED (hr)) - write_log (L"D3D: SetDialogBoxMode %s\n", D3D_ErrorString (hr)); - guimode = guion; + HRESULT hr; + if (!d3d_enabled) + return; + hr = IDirect3DDevice9_SetDialogBoxMode (d3ddev, guion); + if (FAILED (hr)) + write_log (L"D3D: SetDialogBoxMode %s\n", D3D_ErrorString (hr)); + guimode = guion; } HDC D3D_getDC (HDC hdc) { - static LPDIRECT3DSURFACE9 bb; - HRESULT hr; + static LPDIRECT3DSURFACE9 bb; + HRESULT hr; - if (!d3d_enabled) - return 0; - if (!hdc) { - hr = IDirect3DDevice9_GetBackBuffer (d3ddev, 0, 0, D3DBACKBUFFER_TYPE_MONO, &bb); - if (FAILED (hr)) { - write_log (L"IDirect3DDevice9_GetBackBuffer() failed: %s\n", D3D_ErrorString (hr)); - return 0; + if (!d3d_enabled) + return 0; + if (!hdc) { + hr = IDirect3DDevice9_GetBackBuffer (d3ddev, 0, 0, D3DBACKBUFFER_TYPE_MONO, &bb); + if (FAILED (hr)) { + write_log (L"IDirect3DDevice9_GetBackBuffer() failed: %s\n", D3D_ErrorString (hr)); + return 0; + } + hr = IDirect3DSurface9_GetDC (bb, &hdc); + if (SUCCEEDED (hr)) + return hdc; + write_log (L"IDirect3DSurface9_GetDC() failed: %s\n", D3D_ErrorString (hr)); + return 0; } - hr = IDirect3DSurface9_GetDC (bb, &hdc); - if (SUCCEEDED (hr)) - return hdc; - write_log (L"IDirect3DSurface9_GetDC() failed: %s\n", D3D_ErrorString (hr)); + IDirect3DSurface9_ReleaseDC (bb, hdc); + IDirect3DSurface9_Release (bb); return 0; - } - IDirect3DSurface9_ReleaseDC (bb, hdc); - IDirect3DSurface9_Release (bb); - return 0; } int D3D_isenabled (void) { - return d3d_enabled; + return d3d_enabled; } #endif diff --git a/od-win32/driveclick_win32.c b/od-win32/driveclick_win32.c index d78b09a2..1b8105f5 100644 --- a/od-win32/driveclick_win32.c +++ b/od-win32/driveclick_win32.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * PC drive Drive Click Emulation Support - * - * Copyright 2006 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* PC drive Drive Click Emulation Support +* +* Copyright 2006 Toni Wilen +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -28,149 +28,149 @@ static int motors[2]; static int CmdMotor (HANDLE h_, BYTE motor_) { - DWORD dwRet; - if (h == INVALID_HANDLE_VALUE) - return 0; - return !!DeviceIoControl(h_, motor_ ? IOCTL_FD_MOTOR_ON : IOCTL_FD_MOTOR_OFF, - NULL, 0, NULL, 0, &dwRet, NULL); + DWORD dwRet; + if (h == INVALID_HANDLE_VALUE) + return 0; + return !!DeviceIoControl(h_, motor_ ? IOCTL_FD_MOTOR_ON : IOCTL_FD_MOTOR_OFF, + NULL, 0, NULL, 0, &dwRet, NULL); } static int CmdSeek (HANDLE h_, BYTE cyl_) { - DWORD dwRet; - FD_SEEK_PARAMS sp = { cyl_, 0 }; - if (h == INVALID_HANDLE_VALUE) - return 0; - return !!DeviceIoControl(h_, IOCTL_FDCMD_SEEK, &sp, sizeof(sp), NULL, 0, &dwRet, NULL); + DWORD dwRet; + FD_SEEK_PARAMS sp = { cyl_, 0 }; + if (h == INVALID_HANDLE_VALUE) + return 0; + return !!DeviceIoControl(h_, IOCTL_FDCMD_SEEK, &sp, sizeof(sp), NULL, 0, &dwRet, NULL); } static int CmdSpecify (HANDLE h_, BYTE srt_, BYTE hut_, BYTE hlt_, BYTE nd_) { - DWORD dwRet; - FD_SPECIFY_PARAMS sp = { (srt_ << 4) | (hut_ & 0x0f), (hlt_ << 1) | (nd_ & 1) }; - if (h == INVALID_HANDLE_VALUE) - return 0; - return !!DeviceIoControl(h_, IOCTL_FDCMD_SPECIFY, &sp, sizeof(sp), NULL, 0, &dwRet, NULL); + DWORD dwRet; + FD_SPECIFY_PARAMS sp = { (srt_ << 4) | (hut_ & 0x0f), (hlt_ << 1) | (nd_ & 1) }; + if (h == INVALID_HANDLE_VALUE) + return 0; + return !!DeviceIoControl(h_, IOCTL_FDCMD_SPECIFY, &sp, sizeof(sp), NULL, 0, &dwRet, NULL); } static int SetDataRate (HANDLE h_, BYTE bDataRate_) { - DWORD dwRet; - if (h == INVALID_HANDLE_VALUE) - return 0; - return !!DeviceIoControl(h_, IOCTL_FD_SET_DATA_RATE, &bDataRate_, sizeof(bDataRate_), NULL, 0, &dwRet, NULL); + DWORD dwRet; + if (h == INVALID_HANDLE_VALUE) + return 0; + return !!DeviceIoControl(h_, IOCTL_FD_SET_DATA_RATE, &bDataRate_, sizeof(bDataRate_), NULL, 0, &dwRet, NULL); } static int SetMotorDelay (HANDLE h_, BYTE delay_) { - DWORD dwRet; - if (h == INVALID_HANDLE_VALUE) - return 0; - return !!DeviceIoControl(h_, IOCTL_FD_SET_MOTOR_TIMEOUT, &delay_, sizeof(delay_), NULL, 0, &dwRet, NULL); + DWORD dwRet; + if (h == INVALID_HANDLE_VALUE) + return 0; + return !!DeviceIoControl(h_, IOCTL_FD_SET_MOTOR_TIMEOUT, &delay_, sizeof(delay_), NULL, 0, &dwRet, NULL); } void driveclick_fdrawcmd_seek(int drive, int cyl) { - write_comm_pipe_int (dc_pipe, (drive << 8) | cyl, 1); + write_comm_pipe_int (dc_pipe, (drive << 8) | cyl, 1); } void driveclick_fdrawcmd_motor (int drive, int running) { - write_comm_pipe_int (dc_pipe, 0x8000 | (drive << 8) | (running ? 1 : 0), 1); + write_comm_pipe_int (dc_pipe, 0x8000 | (drive << 8) | (running ? 1 : 0), 1); } void driveclick_fdrawcmd_vsync(void) { - int i; - for (i = 0; i < 2; i++) { - if (motors[i] > 0) { - motors[i]--; - if (motors[i] == 0) - CmdMotor(h[i], 0); + int i; + for (i = 0; i < 2; i++) { + if (motors[i] > 0) { + motors[i]--; + if (motors[i] == 0) + CmdMotor(h[i], 0); + } } - } } static void *driveclick_thread (void *v) { - for (;;) { - int drive, cyl; - int v = read_comm_pipe_int_blocking (dc_pipe); - if (v < 0) - break; - drive = (v >> 8) & 3; - if (v & 0x8000) { - int motor = v & 1; - motors[drive] = motor ? -1 : 0; - CmdMotor(h[drive], motor); - } else { - cyl = v & 255; - if (motors[drive] == 0) - motors[drive] = 100; - CmdSeek(h[drive], cyl); + for (;;) { + int drive, cyl; + int v = read_comm_pipe_int_blocking (dc_pipe); + if (v < 0) + break; + drive = (v >> 8) & 3; + if (v & 0x8000) { + int motor = v & 1; + motors[drive] = motor ? -1 : 0; + CmdMotor(h[drive], motor); + } else { + cyl = v & 255; + if (motors[drive] == 0) + motors[drive] = 100; + CmdSeek(h[drive], cyl); + } } - } - return NULL; + return NULL; } static int driveclick_fdrawcmd_init(int drive) { - static int thread_ok; - - if (h[drive] == INVALID_HANDLE_VALUE) - return 0; - motors[drive] = 0; - SetDataRate(h[drive], 3); - CmdSpecify(h[drive], 0xd, 0xf, 0x1, 0); - SetMotorDelay(h[drive], 0); - CmdMotor(h[drive], 0); - if (thread_ok) + static int thread_ok; + + if (h[drive] == INVALID_HANDLE_VALUE) + return 0; + motors[drive] = 0; + SetDataRate(h[drive], 3); + CmdSpecify(h[drive], 0xd, 0xf, 0x1, 0); + SetMotorDelay(h[drive], 0); + CmdMotor(h[drive], 0); + if (thread_ok) + return 1; + thread_ok = 1; + init_comm_pipe (dc_pipe, DC_PIPE_SIZE, 3); + uae_start_thread (L"fdrawcmd_win32", driveclick_thread, NULL, NULL); return 1; - thread_ok = 1; - init_comm_pipe (dc_pipe, DC_PIPE_SIZE, 3); - uae_start_thread (L"fdrawcmd_win32", driveclick_thread, NULL, NULL); - return 1; } void driveclick_fdrawcmd_close(int drive) { - if (h[drive] != INVALID_HANDLE_VALUE) - CloseHandle(h[drive]); - h[drive] = INVALID_HANDLE_VALUE; - motors[drive] = 0; + if (h[drive] != INVALID_HANDLE_VALUE) + CloseHandle(h[drive]); + h[drive] = INVALID_HANDLE_VALUE; + motors[drive] = 0; } static int driveclick_fdrawcmd_open_2(int drive) { - TCHAR s[32]; - - driveclick_fdrawcmd_close(drive); - _stprintf (s, L"\\\\.\\fdraw%d", drive); - h[drive] = CreateFile(s, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (h[drive] == INVALID_HANDLE_VALUE) - return 0; - return 1; + TCHAR s[32]; + + driveclick_fdrawcmd_close(drive); + _stprintf (s, L"\\\\.\\fdraw%d", drive); + h[drive] = CreateFile(s, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + if (h[drive] == INVALID_HANDLE_VALUE) + return 0; + return 1; } int driveclick_fdrawcmd_open(int drive) { - if (!driveclick_fdrawcmd_open_2(drive)) - return 0; - driveclick_fdrawcmd_init(drive); - return 1; + if (!driveclick_fdrawcmd_open_2(drive)) + return 0; + driveclick_fdrawcmd_init(drive); + return 1; } void driveclick_fdrawcmd_detect(void) { - static int detected; - if (detected) - return; - detected = 1; - if (driveclick_fdrawcmd_open_2(0)) - driveclick_pcdrivemask |= 1; - driveclick_fdrawcmd_close(0); - if (driveclick_fdrawcmd_open_2(1)) - driveclick_pcdrivemask |= 2; - driveclick_fdrawcmd_close(1); + static int detected; + if (detected) + return; + detected = 1; + if (driveclick_fdrawcmd_open_2(0)) + driveclick_pcdrivemask |= 1; + driveclick_fdrawcmd_close(0); + if (driveclick_fdrawcmd_open_2(1)) + driveclick_pcdrivemask |= 2; + driveclick_fdrawcmd_close(1); } #endif diff --git a/od-win32/dxwrap.c b/od-win32/dxwrap.c index bb4f9176..28eb2334 100644 --- a/od-win32/dxwrap.c +++ b/od-win32/dxwrap.c @@ -20,1226 +20,1226 @@ int ddsoftwarecolorkey = 0; HRESULT DirectDraw_GetDisplayMode (void) { - HRESULT ddrval; + HRESULT ddrval; - dxdata.native.dwSize = sizeof (DDSURFACEDESC2); - ddrval = IDirectDraw7_GetDisplayMode (dxdata.maindd, &dxdata.native); - if (FAILED (ddrval)) - write_log (L"IDirectDraw7_GetDisplayMode: %s\n", DXError (ddrval)); - return ddrval; + dxdata.native.dwSize = sizeof (DDSURFACEDESC2); + ddrval = IDirectDraw7_GetDisplayMode (dxdata.maindd, &dxdata.native); + if (FAILED (ddrval)) + write_log (L"IDirectDraw7_GetDisplayMode: %s\n", DXError (ddrval)); + return ddrval; } #define releaser(x, y) if (x) { y (x); x = NULL; } static LPDIRECTDRAWSURFACE7 getlocksurface (void) { - if (dxdata.backbuffers > 0 && currprefs.gfx_afullscreen > 0 && !WIN32GFX_IsPicassoScreen ()) - return dxdata.flipping[0]; - return dxdata.secondary; + if (dxdata.backbuffers > 0 && currprefs.gfx_afullscreen > 0 && !WIN32GFX_IsPicassoScreen ()) + return dxdata.flipping[0]; + return dxdata.secondary; } static void freemainsurface (void) { - if (dxdata.dclip) { - DirectDraw_SetClipper (NULL); - releaser (dxdata.dclip, IDirectDrawClipper_Release); - } - releaser (dxdata.palette, IDirectDrawPalette_Release); - releaser (dxdata.flipping[1], IDirectDrawSurface7_Release); - releaser (dxdata.flipping[0], IDirectDrawSurface7_Release); - releaser (dxdata.primary, IDirectDrawSurface7_Release); - releaser (dxdata.secondary, IDirectDrawSurface7_Release); - releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); - releaser (dxdata.cursorsurface2, IDirectDrawSurface7_Release); - releaser (dxdata.statussurface, IDirectDrawSurface7_Release); - dxdata.backbuffers = 0; + if (dxdata.dclip) { + DirectDraw_SetClipper (NULL); + releaser (dxdata.dclip, IDirectDrawClipper_Release); + } + releaser (dxdata.palette, IDirectDrawPalette_Release); + releaser (dxdata.flipping[1], IDirectDrawSurface7_Release); + releaser (dxdata.flipping[0], IDirectDrawSurface7_Release); + releaser (dxdata.primary, IDirectDrawSurface7_Release); + releaser (dxdata.secondary, IDirectDrawSurface7_Release); + releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); + releaser (dxdata.cursorsurface2, IDirectDrawSurface7_Release); + releaser (dxdata.statussurface, IDirectDrawSurface7_Release); + dxdata.backbuffers = 0; } static HRESULT restoresurface_2 (LPDIRECTDRAWSURFACE7 surf) { - HRESULT ddrval; - - if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) - surf = dxdata.primary; - ddrval = IDirectDrawSurface7_IsLost (surf); - if (SUCCEEDED (ddrval)) + HRESULT ddrval; + + if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) + surf = dxdata.primary; + ddrval = IDirectDrawSurface7_IsLost (surf); + if (SUCCEEDED (ddrval)) + return ddrval; + ddrval = IDirectDrawSurface7_Restore (surf); + if (SUCCEEDED (ddrval)) { + if (surf == dxdata.primary && dxdata.palette) + IDirectDrawSurface7_SetPalette (dxdata.primary, dxdata.palette); + } return ddrval; - ddrval = IDirectDrawSurface7_Restore (surf); - if (SUCCEEDED (ddrval)) { - if (surf == dxdata.primary && dxdata.palette) - IDirectDrawSurface7_SetPalette (dxdata.primary, dxdata.palette); - } - return ddrval; } HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surf) { - HRESULT ddrval; - - if (surf == NULL) - return E_FAIL; - if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) - surf = dxdata.primary; - ddrval = IDirectDrawSurface7_IsLost (surf); - if (SUCCEEDED (ddrval)) + HRESULT ddrval; + + if (surf == NULL) + return E_FAIL; + if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) + surf = dxdata.primary; + ddrval = IDirectDrawSurface7_IsLost (surf); + if (SUCCEEDED (ddrval)) + return ddrval; + ddrval = IDirectDrawSurface7_Restore (surf); + if (FAILED (ddrval)) { + write_log (L"IDirectDrawSurface7_Restore: %s\n", DXError (ddrval)); + } else { + if (surf == dxdata.primary && dxdata.palette) + IDirectDrawSurface7_SetPalette (dxdata.primary, dxdata.palette); + } return ddrval; - ddrval = IDirectDrawSurface7_Restore (surf); - if (FAILED (ddrval)) { - write_log (L"IDirectDrawSurface7_Restore: %s\n", DXError (ddrval)); - } else { - if (surf == dxdata.primary && dxdata.palette) - IDirectDrawSurface7_SetPalette (dxdata.primary, dxdata.palette); - } - return ddrval; } static HRESULT restoresurfacex (LPDIRECTDRAWSURFACE7 surf1, LPDIRECTDRAWSURFACE7 surf2) { - HRESULT r1, r2; + HRESULT r1, r2; - r1 = restoresurface (surf1); - r2 = restoresurface (surf2); - if (SUCCEEDED (r1) && SUCCEEDED (r2)) + r1 = restoresurface (surf1); + r2 = restoresurface (surf2); + if (SUCCEEDED (r1) && SUCCEEDED (r2)) + return r1; + if (SUCCEEDED (r1)) + return r2; return r1; - if (SUCCEEDED (r1)) - return r2; - return r1; } static void clearsurf (LPDIRECTDRAWSURFACE7 surf, DWORD color) { - HRESULT ddrval; - DDBLTFX ddbltfx; - - if (surf == NULL) - return; - memset(&ddbltfx, 0, sizeof (ddbltfx)); - ddbltfx.dwFillColor = color; - ddbltfx.dwSize = sizeof (ddbltfx); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (surf, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (surf); - if (FAILED (ddrval)) + HRESULT ddrval; + DDBLTFX ddbltfx; + + if (surf == NULL) + return; + memset(&ddbltfx, 0, sizeof (ddbltfx)); + ddbltfx.dwFillColor = color; + ddbltfx.dwSize = sizeof (ddbltfx); + while (FAILED (ddrval = IDirectDrawSurface7_Blt (surf, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (surf); + if (FAILED (ddrval)) + break; + } break; } - break; - } } void clearsurface (LPDIRECTDRAWSURFACE7 surf) { - if (surf == NULL) - surf = getlocksurface (); - clearsurf (surf, 0); + if (surf == NULL) + surf = getlocksurface (); + clearsurf (surf, 0); } int locksurface (LPDIRECTDRAWSURFACE7 surf, LPDDSURFACEDESC2 desc) { - static int cnt = 50; - HRESULT ddrval; - desc->dwSize = sizeof (*desc); - while (FAILED (ddrval = IDirectDrawSurface7_Lock (surf, NULL, desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface_2 (surf); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - if (cnt > 0) { - cnt--; - write_log (L"locksurface %d: %s\n", cnt, DXError (ddrval)); - } - return 0; + static int cnt = 50; + HRESULT ddrval; + desc->dwSize = sizeof (*desc); + while (FAILED (ddrval = IDirectDrawSurface7_Lock (surf, NULL, desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface_2 (surf); + if (FAILED (ddrval)) + return 0; + } else if (ddrval != DDERR_SURFACEBUSY) { + if (cnt > 0) { + cnt--; + write_log (L"locksurface %d: %s\n", cnt, DXError (ddrval)); + } + return 0; + } } - } - return 1; + return 1; } void unlocksurface (LPDIRECTDRAWSURFACE7 surf) { - HRESULT ddrval; + HRESULT ddrval; - ddrval = IDirectDrawSurface7_Unlock (surf, NULL); - if (FAILED (ddrval)) - write_log (L"IDirectDrawSurface7_Unlock: %s\n", DXError (ddrval)); + ddrval = IDirectDrawSurface7_Unlock (surf, NULL); + if (FAILED (ddrval)) + write_log (L"IDirectDrawSurface7_Unlock: %s\n", DXError (ddrval)); } static void setsurfacecap (DDSURFACEDESC2 *desc, int w, int h, int mode) { - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY; - if (mode >= DDFORCED_DEFAULT) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - if (mode == DDFORCED_VIDMEM) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; - if (w > dxcaps.maxwidth || h > dxcaps.maxheight || mode == DDFORCED_SYSMEM) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - desc->dwWidth = w; - desc->dwHeight = h; + desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY; + if (mode >= DDFORCED_DEFAULT) + desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + if (mode == DDFORCED_VIDMEM) + desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; + if (w > dxcaps.maxwidth || h > dxcaps.maxheight || mode == DDFORCED_SYSMEM) + desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + desc->dwWidth = w; + desc->dwHeight = h; } STATIC_INLINE uae_u16 rgb32torgb16pc (uae_u32 rgb) { - return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (0 + 3)) & 0x1f) << 0); + return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (0 + 3)) & 0x1f) << 0); } static TCHAR *alloctexts[] = { L"NonLocalVRAM", L"DefaultRAM", L"VRAM", L"RAM" }; static LPDIRECTDRAWSURFACE7 allocsurface_3 (int width, int height, uae_u8 *ptr, int pitch, int ck, int forcemode) { - HRESULT ddrval; - DDSURFACEDESC2 desc; - LPDIRECTDRAWSURFACE7 surf = NULL; - - memset (&desc, 0, sizeof desc); - desc.dwSize = sizeof (desc); - desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; - setsurfacecap (&desc, width, height, forcemode); - memcpy (&desc.ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); - - if (ck) { - DWORD mask = 0xff00fe; - if (desc.ddpfPixelFormat.dwRGBBitCount == 16) - mask = rgb32torgb16pc (mask); - else if (desc.ddpfPixelFormat.dwRGBBitCount == 8) - mask = 16; - dxdata.colorkey = mask; - if (dxcaps.cancolorkey) { - desc.dwFlags |= DDSD_CKSRCBLT; - desc.ddckCKSrcBlt.dwColorSpaceLowValue = mask; - desc.ddckCKSrcBlt.dwColorSpaceHighValue = mask; + HRESULT ddrval; + DDSURFACEDESC2 desc; + LPDIRECTDRAWSURFACE7 surf = NULL; + + memset (&desc, 0, sizeof desc); + desc.dwSize = sizeof (desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; + setsurfacecap (&desc, width, height, forcemode); + memcpy (&desc.ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); + + if (ck) { + DWORD mask = 0xff00fe; + if (desc.ddpfPixelFormat.dwRGBBitCount == 16) + mask = rgb32torgb16pc (mask); + else if (desc.ddpfPixelFormat.dwRGBBitCount == 8) + mask = 16; + dxdata.colorkey = mask; + if (dxcaps.cancolorkey) { + desc.dwFlags |= DDSD_CKSRCBLT; + desc.ddckCKSrcBlt.dwColorSpaceLowValue = mask; + desc.ddckCKSrcBlt.dwColorSpaceHighValue = mask; + } + } + + if (ptr) { + desc.dwFlags |= DDSD_LPSURFACE | DDSD_PITCH; + desc.lPitch = pitch; + desc.lpSurface = ptr; } - } - - if (ptr) { - desc.dwFlags |= DDSD_LPSURFACE | DDSD_PITCH; - desc.lPitch = pitch; - desc.lpSurface = ptr; - } - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &surf, NULL); - if (FAILED (ddrval)) { - write_log (L"IDirectDraw7_CreateSurface (%dx%d,%s): %s\n", width, height, alloctexts[forcemode], DXError (ddrval)); - } else { - write_log (L"Created %dx%dx%d (%p) surface in %s (%d)%s\n", width, height, desc.ddpfPixelFormat.dwRGBBitCount, surf, - alloctexts[forcemode], forcemode, ck ? (dxcaps.cancolorkey ? L" hardware colorkey" : L" software colorkey") : L""); - } - return surf; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &surf, NULL); + if (FAILED (ddrval)) { + write_log (L"IDirectDraw7_CreateSurface (%dx%d,%s): %s\n", width, height, alloctexts[forcemode], DXError (ddrval)); + } else { + write_log (L"Created %dx%dx%d (%p) surface in %s (%d)%s\n", width, height, desc.ddpfPixelFormat.dwRGBBitCount, surf, + alloctexts[forcemode], forcemode, ck ? (dxcaps.cancolorkey ? L" hardware colorkey" : L" software colorkey") : L""); + } + return surf; } static LPDIRECTDRAWSURFACE7 allocsurface_2 (int width, int height, int ck) { - LPDIRECTDRAWSURFACE7 s; - int mode = ddforceram; - static int failednonlocal; - - if (failednonlocal && mode == DDFORCED_NONLOCAL) - mode = DDFORCED_DEFAULT; - for (;;) { - s = allocsurface_3 (width, height, NULL, 0, ck, mode); - if (s) { - clearsurf (s, 0); - return s; + LPDIRECTDRAWSURFACE7 s; + int mode = ddforceram; + static int failednonlocal; + + if (failednonlocal && mode == DDFORCED_NONLOCAL) + mode = DDFORCED_DEFAULT; + for (;;) { + s = allocsurface_3 (width, height, NULL, 0, ck, mode); + if (s) { + clearsurf (s, 0); + return s; + } + if (mode == DDFORCED_NONLOCAL) + failednonlocal = 1; + mode++; + if (mode >= 4) + mode = 0; + if (mode == ddforceram) + return NULL; } - if (mode == DDFORCED_NONLOCAL) - failednonlocal = 1; - mode++; - if (mode >= 4) - mode = 0; - if (mode == ddforceram) - return NULL; - } } LPDIRECTDRAWSURFACE7 allocsurface (int width, int height) { - return allocsurface_2 (width, height, FALSE); + return allocsurface_2 (width, height, FALSE); } LPDIRECTDRAWSURFACE7 allocsystemsurface (int width, int height) { - return allocsurface_3 (width, height, NULL, 0, FALSE, DDFORCED_SYSMEM); + return allocsurface_3 (width, height, NULL, 0, FALSE, DDFORCED_SYSMEM); } LPDIRECTDRAWSURFACE7 createsurface (uae_u8 *ptr, int pitch, int width, int height) { - return allocsurface_3 (width, height, ptr, pitch, FALSE, DDFORCED_SYSMEM); + return allocsurface_3 (width, height, ptr, pitch, FALSE, DDFORCED_SYSMEM); } void freesurface (LPDIRECTDRAWSURFACE7 surf) { - if (surf) - IDirectDrawSurface7_Release (surf); + if (surf) + IDirectDrawSurface7_Release (surf); } void DirectDraw_FreeMainSurface (void) { - freemainsurface (); + freemainsurface (); } #if 0 static int testck2 (LPDIRECTDRAWSURFACE7 tmp, RECT *r) { - DDSURFACEDESC2 desc; - if (locksurface (tmp, &desc)) { - uae_u8 *p = (uae_u8*)desc.lpSurface + r->top * desc.lPitch + r->left * desc.ddpfPixelFormat.dwRGBBitCount / 8; - DWORD v1 = ((uae_u32*)p)[0]; - DWORD v2 = ((uae_u32*)p)[1]; - unlocksurface (tmp); - // no more black = failure - if (v1 != 0 || v2 != 0) - return 0; - } - return 1; + DDSURFACEDESC2 desc; + if (locksurface (tmp, &desc)) { + uae_u8 *p = (uae_u8*)desc.lpSurface + r->top * desc.lPitch + r->left * desc.ddpfPixelFormat.dwRGBBitCount / 8; + DWORD v1 = ((uae_u32*)p)[0]; + DWORD v2 = ((uae_u32*)p)[1]; + unlocksurface (tmp); + // no more black = failure + if (v1 != 0 || v2 != 0) + return 0; + } + return 1; } int dx_testck (void) { - int failed = 0; - LPDIRECTDRAWSURFACE7 cksurf; - LPDIRECTDRAWSURFACE7 tmp; - RECT r1; - int x; - - cksurf = dxdata.cursorsurface1; - tmp = dxdata.secondary; - if (!dxcaps.cancolorkey || !cksurf || !tmp) - return 1; - r1.left = 0; - r1.top = 0; - r1.right = dxcaps.cursorwidth; - r1.bottom = dxcaps.cursorheight; - failed = 0; - // test by blitting surface filled with color key color to destination filled with black - clearsurf (cksurf, dxdata.colorkey); - clearsurf (tmp, 0); - for (x = 0; x < 16; x++) { - DirectDraw_BlitRectCK (tmp, &r1, cksurf, NULL); - if (!testck2 (tmp, &r1)) // non-black = failed - failed = 1; - r1.left++; - r1.right++; - if (x & 1) { - r1.top++; - r1.bottom++; + int failed = 0; + LPDIRECTDRAWSURFACE7 cksurf; + LPDIRECTDRAWSURFACE7 tmp; + RECT r1; + int x; + + cksurf = dxdata.cursorsurface1; + tmp = dxdata.secondary; + if (!dxcaps.cancolorkey || !cksurf || !tmp) + return 1; + r1.left = 0; + r1.top = 0; + r1.right = dxcaps.cursorwidth; + r1.bottom = dxcaps.cursorheight; + failed = 0; + // test by blitting surface filled with color key color to destination filled with black + clearsurf (cksurf, dxdata.colorkey); + clearsurf (tmp, 0); + for (x = 0; x < 16; x++) { + DirectDraw_BlitRectCK (tmp, &r1, cksurf, NULL); + if (!testck2 (tmp, &r1)) // non-black = failed + failed = 1; + r1.left++; + r1.right++; + if (x & 1) { + r1.top++; + r1.bottom++; + } } - } - clearsurface (cksurf); - clearsurface (tmp); - if (failed) { - write_log (L"Color key test failure, display driver bug, falling back to software emulation.\n"); - dxcaps.cancolorkey = 0; - releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); - dxdata.cursorsurface1 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, TRUE); - return 0; - } - return 1; + clearsurface (cksurf); + clearsurface (tmp); + if (failed) { + write_log (L"Color key test failure, display driver bug, falling back to software emulation.\n"); + dxcaps.cancolorkey = 0; + releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); + dxdata.cursorsurface1 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, TRUE); + return 0; + } + return 1; } #endif static void createcursorsurface (void) { - releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); - releaser (dxdata.cursorsurface2, IDirectDrawSurface7_Release); - releaser (dxdata.statussurface, IDirectDrawSurface7_Release); - dxdata.cursorsurface1 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, TRUE); - dxdata.cursorsurface2 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, FALSE); - dxdata.statussurface = allocsurface_2 (dxdata.statuswidth, dxdata.statusheight, FALSE); - if (dxdata.cursorsurface1) - clearsurf (dxdata.cursorsurface1, 0); - if (dxdata.cursorsurface2) - clearsurf (dxdata.cursorsurface2, 0); - if (dxdata.statussurface) - clearsurf (dxdata.statussurface, 0); + releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); + releaser (dxdata.cursorsurface2, IDirectDrawSurface7_Release); + releaser (dxdata.statussurface, IDirectDrawSurface7_Release); + dxdata.cursorsurface1 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, TRUE); + dxdata.cursorsurface2 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, FALSE); + dxdata.statussurface = allocsurface_2 (dxdata.statuswidth, dxdata.statusheight, FALSE); + if (dxdata.cursorsurface1) + clearsurf (dxdata.cursorsurface1, 0); + if (dxdata.cursorsurface2) + clearsurf (dxdata.cursorsurface2, 0); + if (dxdata.statussurface) + clearsurf (dxdata.statussurface, 0); } HRESULT DirectDraw_CreateMainSurface (int width, int height) { - HRESULT ddrval; - DDSURFACEDESC2 desc = { 0 }; - LPDIRECTDRAWSURFACE7 surf; - - width = (width + 7) & ~7; - desc.dwSize = sizeof (desc); - desc.dwFlags = DDSD_CAPS; - desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - if (dxdata.fsmodeset) { - int ok = 0; - DWORD oldcaps = desc.ddsCaps.dwCaps; - DWORD oldflags = desc.dwFlags; - desc.dwFlags |= DDSD_BACKBUFFERCOUNT; - desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; - desc.dwBackBufferCount = currprefs.gfx_backbuffers; - if (desc.dwBackBufferCount > 0) { - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); - 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)) { - if (desc.dwBackBufferCount > 1) { - memset (&ddscaps, 0, sizeof (ddscaps)); - ddscaps.dwCaps = DDSCAPS_FLIP; - ddrval = IDirectDrawSurface7_GetAttachedSurface (dxdata.flipping[0], &ddscaps, &dxdata.flipping[1]); - } + HRESULT ddrval; + DDSURFACEDESC2 desc = { 0 }; + LPDIRECTDRAWSURFACE7 surf; + + width = (width + 7) & ~7; + desc.dwSize = sizeof (desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + if (dxdata.fsmodeset) { + int ok = 0; + DWORD oldcaps = desc.ddsCaps.dwCaps; + DWORD oldflags = desc.dwFlags; + desc.dwFlags |= DDSD_BACKBUFFERCOUNT; + desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; + desc.dwBackBufferCount = currprefs.gfx_backbuffers; + if (desc.dwBackBufferCount > 0) { + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + 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)) { + if (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 (L"IDirectDrawSurface7_GetAttachedSurface: %s\n", DXError (ddrval)); + ok = 1; + } + } + if (!ok) { + desc.dwBackBufferCount = 0; + desc.ddsCaps.dwCaps = oldcaps; + desc.dwFlags = oldflags; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + } + } else { + if (useoverlay && DirectDraw_GetCurrentDepth () == 32) { + DDPIXELFORMAT of; + DWORD dwDDSColor; + memset (&of, 0, sizeof (of)); + of.dwRGBBitCount = 16; + of.dwRBitMask = 0xF800; + of.dwGBitMask = 0x07E0; + of.dwBBitMask = 0x001F; + desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_PRIMARYSURFACE; + desc.ddpfPixelFormat = of; + dxdata.overlayfx.dwSize = sizeof (DDOVERLAYFX); + dxdata.overlayflags = DDOVER_SHOW | DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE; + dwDDSColor = 0xff00ff; + dxdata.overlayfx.dckDestColorkey.dwColorSpaceLowValue = dwDDSColor; + dxdata.overlayfx.dckDestColorkey.dwColorSpaceHighValue = dwDDSColor; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + dxdata.isoverlay = 1; + } else { + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); } - if (FAILED (ddrval)) - write_log (L"IDirectDrawSurface7_GetAttachedSurface: %s\n", DXError (ddrval)); - ok = 1; - } } - if (!ok) { - desc.dwBackBufferCount = 0; - desc.ddsCaps.dwCaps = oldcaps; - desc.dwFlags = oldflags; - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + if (FAILED (ddrval)) { + write_log (L"IDirectDraw7_CreateSurface: %s\n", DXError (ddrval)); + return ddrval; } - } else { - if (useoverlay && DirectDraw_GetCurrentDepth () == 32) { - DDPIXELFORMAT of; - DWORD dwDDSColor; - memset (&of, 0, sizeof (of)); - of.dwRGBBitCount = 16; - of.dwRBitMask = 0xF800; - of.dwGBitMask = 0x07E0; - of.dwBBitMask = 0x001F; - desc.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_PRIMARYSURFACE; - desc.ddpfPixelFormat = of; - dxdata.overlayfx.dwSize = sizeof (DDOVERLAYFX); - dxdata.overlayflags = DDOVER_SHOW | DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE; - dwDDSColor = 0xff00ff; - dxdata.overlayfx.dckDestColorkey.dwColorSpaceLowValue = dwDDSColor; - dxdata.overlayfx.dckDestColorkey.dwColorSpaceHighValue = dwDDSColor; - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); - dxdata.isoverlay = 1; - } else { - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + dxdata.native.dwSize = sizeof (DDSURFACEDESC2); + ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); + if (FAILED (ddrval)) + write_log (L"IDirectDrawSurface7_GetSurfaceDesc: %s\n", DXError (ddrval)); + if (dxdata.fsmodeset) { + clearsurf (dxdata.primary, 0); + dxdata.fsmodeset = 1; } - } - if (FAILED (ddrval)) { - write_log (L"IDirectDraw7_CreateSurface: %s\n", DXError (ddrval)); - return ddrval; - } - dxdata.native.dwSize = sizeof (DDSURFACEDESC2); - ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); - if (FAILED (ddrval)) - write_log (L"IDirectDrawSurface7_GetSurfaceDesc: %s\n", DXError (ddrval)); - if (dxdata.fsmodeset) { - clearsurf (dxdata.primary, 0); - dxdata.fsmodeset = 1; - } - dxdata.backbuffers = desc.dwBackBufferCount; - clearsurf (dxdata.flipping[0], 0); - clearsurf (dxdata.flipping[1], 0); - surf = allocsurface (width, height); - if (surf) { - dxdata.secondary = surf; - dxdata.swidth = width; - dxdata.sheight = height; - dxdata.pitch = 0; - if (locksurface (surf, &desc)) { - dxdata.pitch = desc.lPitch; - unlocksurface (surf); + dxdata.backbuffers = desc.dwBackBufferCount; + clearsurf (dxdata.flipping[0], 0); + clearsurf (dxdata.flipping[1], 0); + surf = allocsurface (width, height); + if (surf) { + dxdata.secondary = surf; + dxdata.swidth = width; + dxdata.sheight = height; + dxdata.pitch = 0; + if (locksurface (surf, &desc)) { + dxdata.pitch = desc.lPitch; + unlocksurface (surf); + } else { + write_log (L"Couldn't get surface pitch!\n"); + } + createcursorsurface (); } else { - write_log (L"Couldn't get surface pitch!\n"); + ddrval = DD_FALSE; } - createcursorsurface (); - } else { - ddrval = DD_FALSE; - } - write_log (L"DDRAW: primary surface %p, secondary %p (%dx%dx%d) bb=%d\n", - dxdata.primary, surf, width, height, dxdata.native.ddpfPixelFormat.dwRGBBitCount, dxdata.backbuffers); - return ddrval; + write_log (L"DDRAW: primary surface %p, secondary %p (%dx%dx%d) bb=%d\n", + dxdata.primary, surf, width, height, dxdata.native.ddpfPixelFormat.dwRGBBitCount, dxdata.backbuffers); + return ddrval; } HRESULT DirectDraw_SetDisplayMode (int width, int height, int bits, int freq) { - HRESULT ddrval; + HRESULT ddrval; - 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 (L"IDirectDraw7_SetDisplayMode: %s\n", DXError (ddrval)); - IDirectDraw7_RestoreDisplayMode (dxdata.maindd); - dxdata.fsmodeset = 0; - } else { - dxdata.fsmodeset = -1; - dxdata.width = width; - dxdata.height = height; - dxdata.depth = bits; - dxdata.freq = freq; - } - return ddrval; + 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 (L"IDirectDraw7_SetDisplayMode: %s\n", DXError (ddrval)); + IDirectDraw7_RestoreDisplayMode (dxdata.maindd); + dxdata.fsmodeset = 0; + } else { + dxdata.fsmodeset = -1; + dxdata.width = width; + dxdata.height = height; + dxdata.depth = bits; + dxdata.freq = freq; + } + return ddrval; } HRESULT DirectDraw_SetCooperativeLevel (HWND window, int fullscreen, int doset) { - HRESULT ddrval; - - if (doset) { - dxdata.hwnd = window; - ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, window, fullscreen ? - DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); - if (FAILED (ddrval)) - write_log (L"IDirectDraw7_SetCooperativeLevel: SET %s\n", DXError (ddrval)); - } else { - ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, dxdata.hwnd, DDSCL_NORMAL); - if (FAILED (ddrval)) - write_log (L"IDirectDraw7_SetCooperativeLevel: RESET %s\n", DXError (ddrval)); - } - return ddrval; + HRESULT ddrval; + + if (doset) { + dxdata.hwnd = window; + ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, window, fullscreen ? + DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); + if (FAILED (ddrval)) + write_log (L"IDirectDraw7_SetCooperativeLevel: SET %s\n", DXError (ddrval)); + } else { + ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, dxdata.hwnd, DDSCL_NORMAL); + if (FAILED (ddrval)) + write_log (L"IDirectDraw7_SetCooperativeLevel: RESET %s\n", DXError (ddrval)); + } + return ddrval; } HRESULT DirectDraw_CreateClipper (void) { - HRESULT ddrval; + HRESULT ddrval; - ddrval = IDirectDraw7_CreateClipper (dxdata.maindd, 0, &dxdata.dclip, NULL); - if (FAILED (ddrval)) - write_log (L"IDirectDraw7_CreateClipper: %s\n", DXError (ddrval)); - return ddrval; + ddrval = IDirectDraw7_CreateClipper (dxdata.maindd, 0, &dxdata.dclip, NULL); + if (FAILED (ddrval)) + write_log (L"IDirectDraw7_CreateClipper: %s\n", DXError (ddrval)); + return ddrval; } HRESULT DirectDraw_SetClipper (HWND hWnd) { - HRESULT ddrval; + HRESULT ddrval; - if (dxdata.primary == NULL) - return DD_FALSE; - ddrval = IDirectDrawSurface7_SetClipper (dxdata.primary, hWnd ? dxdata.dclip : NULL); - if (FAILED (ddrval)) - write_log (L"IDirectDrawSurface7_SetClipper: %s\n", DXError (ddrval)); - if(hWnd && SUCCEEDED (ddrval)) { - ddrval = IDirectDrawClipper_SetHWnd (dxdata.dclip, 0, hWnd); + if (dxdata.primary == NULL) + return DD_FALSE; + ddrval = IDirectDrawSurface7_SetClipper (dxdata.primary, hWnd ? dxdata.dclip : NULL); if (FAILED (ddrval)) - write_log (L"IDirectDrawClipper_SetHWnd: %s\n", DXError (ddrval)); - } - return ddrval; + write_log (L"IDirectDrawSurface7_SetClipper: %s\n", DXError (ddrval)); + if(hWnd && SUCCEEDED (ddrval)) { + ddrval = IDirectDrawClipper_SetHWnd (dxdata.dclip, 0, hWnd); + if (FAILED (ddrval)) + write_log (L"IDirectDrawClipper_SetHWnd: %s\n", DXError (ddrval)); + } + return ddrval; } TCHAR *outGUID (const GUID *guid) { - static TCHAR gb[64]; - if (guid == NULL) - return L"NULL"; - _stprintf (gb, L"%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; + static TCHAR gb[64]; + if (guid == NULL) + return L"NULL"; + _stprintf (gb, L"%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; } const TCHAR *DXError (HRESULT ddrval) { - static TCHAR dderr[1000]; - _stprintf (dderr, L"%08X S=%d F=%04X C=%04X (%d) (%s)", - ddrval, (ddrval & 0x80000000) ? 1 : 0, - HRESULT_FACILITY(ddrval), - HRESULT_CODE(ddrval), - HRESULT_CODE(ddrval), - DXGetErrorDescription (ddrval)); - return dderr; + static TCHAR dderr[1000]; + _stprintf (dderr, L"%08X S=%d F=%04X C=%04X (%d) (%s)", + ddrval, (ddrval & 0x80000000) ? 1 : 0, + HRESULT_FACILITY(ddrval), + HRESULT_CODE(ddrval), + HRESULT_CODE(ddrval), + DXGetErrorDescription (ddrval)); + return dderr; } RGBFTYPE DirectDraw_GetSurfacePixelFormat (LPDDSURFACEDESC2 surface) { - int surface_is = 0; - DDPIXELFORMAT *pfp = NULL; - DWORD r, g, b; - DWORD surf_flags; + int surface_is = 0; + DDPIXELFORMAT *pfp = NULL; + DWORD r, g, b; + DWORD surf_flags; - if (surface == NULL) - surface = &dxdata.native; - surf_flags = surface->dwFlags; - pfp = &surface->ddpfPixelFormat; + if (surface == NULL) + surface = &dxdata.native; + surf_flags = surface->dwFlags; + pfp = &surface->ddpfPixelFormat; - if ((surf_flags & DDSD_PIXELFORMAT) == 0x0) - return RGBFB_NONE; + if ((surf_flags & DDSD_PIXELFORMAT) == 0x0) + return RGBFB_NONE; - if ((pfp->dwFlags & DDPF_RGB) == 0) - 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; + 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; - 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; - 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 (L"Unknown %d bit format %d %d %d\n", pfp->dwRGBBitCount, r, g, b); - break; - } - return RGBFB_NONE; + default: + write_log (L"Unknown %d bit format %d %d %d\n", pfp->dwRGBBitCount, r, g, b); + break; + } + return RGBFB_NONE; } HRESULT DirectDraw_EnumDisplayModes (DWORD flags, LPDDENUMMODESCALLBACK2 callback, void *context) { - HRESULT result; - result = IDirectDraw7_EnumDisplayModes (dxdata.maindd, flags, NULL, context, callback); - return result; + HRESULT result; + result = IDirectDraw7_EnumDisplayModes (dxdata.maindd, flags, NULL, context, callback); + return result; } HRESULT DirectDraw_EnumDisplays (LPDDENUMCALLBACKEXA callback) { - HRESULT result; - result = DirectDrawEnumerateExA (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); - return result; + HRESULT result; + result = DirectDrawEnumerateExA (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); + return result; } DWORD DirectDraw_CurrentWidth (void) { - return dxdata.native.dwWidth; + return dxdata.native.dwWidth; } DWORD DirectDraw_CurrentHeight (void) { - return dxdata.native.dwHeight; + return dxdata.native.dwHeight; } DWORD DirectDraw_GetCurrentDepth (void) { - return dxdata.native.ddpfPixelFormat.dwRGBBitCount; + return dxdata.native.ddpfPixelFormat.dwRGBBitCount; } int DirectDraw_SurfaceLock (void) { - int ok; - LPDIRECTDRAWSURFACE7 surf; - - surf = getlocksurface (); - if (surf == NULL) - return 0; - if (FAILED (IDirectDrawSurface7_IsLost (surf))) - return 0; - if (dxdata.lockcnt > 0) - return 1; - ok = locksurface (getlocksurface (), &dxdata.locksurface); - if (ok) - dxdata.lockcnt++; - return ok; + int ok; + LPDIRECTDRAWSURFACE7 surf; + + surf = getlocksurface (); + if (surf == NULL) + return 0; + if (FAILED (IDirectDrawSurface7_IsLost (surf))) + 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) - write_log (L"DirectDraw_SurfaceUnlock negative lock count %d!\n", dxdata.lockcnt); - if (dxdata.lockcnt == 0) - return; - dxdata.lockcnt--; - unlocksurface (getlocksurface ()); + if (dxdata.lockcnt < 0) + write_log (L"DirectDraw_SurfaceUnlock negative lock count %d!\n", dxdata.lockcnt); + if (dxdata.lockcnt == 0) + return; + dxdata.lockcnt--; + unlocksurface (getlocksurface ()); } void *DirectDraw_GetSurfacePointer (void) { - return dxdata.locksurface.lpSurface; + return dxdata.locksurface.lpSurface; } DWORD DirectDraw_GetSurfacePitch (void) { - return dxdata.locksurface.lPitch; + return dxdata.locksurface.lPitch; } int DirectDraw_IsLocked (void) { - return dxdata.lockcnt; + return dxdata.lockcnt; } DWORD DirectDraw_GetPixelFormatBitMask (DirectDraw_Mask_e mask) { - DWORD result = 0; - switch(mask) - { + DWORD result = 0; + switch(mask) + { case red_mask: - result = dxdata.native.ddpfPixelFormat.dwRBitMask; - break; + result = dxdata.native.ddpfPixelFormat.dwRBitMask; + break; case green_mask: - result = dxdata.native.ddpfPixelFormat.dwGBitMask; - break; + result = dxdata.native.ddpfPixelFormat.dwGBitMask; + break; case blue_mask: - result = dxdata.native.ddpfPixelFormat.dwBBitMask; - break; - } - return result; + result = dxdata.native.ddpfPixelFormat.dwBBitMask; + break; + } + return result; } DWORD DirectDraw_GetPixelFormat (void) { - return DirectDraw_GetSurfacePixelFormat (&dxdata.native); + return DirectDraw_GetSurfacePixelFormat (&dxdata.native); } DWORD DirectDraw_GetBytesPerPixel (void) { - return (dxdata.native.ddpfPixelFormat.dwRGBBitCount + 7) >> 3; + return (dxdata.native.ddpfPixelFormat.dwRGBBitCount + 7) >> 3; } HRESULT DirectDraw_GetDC (HDC *hdc) { - if (getlocksurface () == NULL) - return E_FAIL; - return IDirectDrawSurface7_GetDC (getlocksurface (), hdc); + if (getlocksurface () == NULL) + return E_FAIL; + return IDirectDrawSurface7_GetDC (getlocksurface (), hdc); } HRESULT DirectDraw_ReleaseDC (HDC hdc) { - if (getlocksurface () == NULL) - return E_FAIL; - return IDirectDrawSurface7_ReleaseDC (getlocksurface (), hdc); + if (getlocksurface () == NULL) + return E_FAIL; + return IDirectDrawSurface7_ReleaseDC (getlocksurface (), hdc); } int DirectDraw_GetVerticalBlankStatus (void) { - BOOL status; - if (FAILED (IDirectDraw7_GetVerticalBlankStatus (dxdata.maindd, &status))) - return -1; - return status; + BOOL 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; + memcpy (&desc->ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); + desc->dwFlags |= DDSD_PIXELFORMAT; } DWORD DirectDraw_CurrentRefreshRate (void) { - DirectDraw_GetDisplayMode (); - return dxdata.native.dwRefreshRate; + DirectDraw_GetDisplayMode (); + return dxdata.native.dwRefreshRate; } HRESULT DirectDraw_FlipToGDISurface (void) { - if (!dxdata.ddinit || !dxdata.fsmodeset) - return DD_OK; - return IDirectDraw7_FlipToGDISurface (dxdata.maindd); + if (!dxdata.ddinit || !dxdata.fsmodeset) + return DD_OK; + return IDirectDraw7_FlipToGDISurface (dxdata.maindd); } int DirectDraw_BlitToPrimaryScale (RECT *dstrect, RECT *srcrect) { - LPDIRECTDRAWSURFACE7 dst; - int result = 0; - HRESULT ddrval; - RECT dstrect2; - int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; - - dst = dxdata.primary; - if (dstrect == NULL) { - dstrect = &dstrect2; - SetRect (dstrect, x, y, x + w, y + h); - } - centerdstrect (dstrect); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, dstrect, dxdata.secondary, srcrect, DDBLT_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, dxdata.secondary); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (L"DirectDraw_BlitToPrimary: %s\n", DXError (ddrval)); - if (srcrect) - write_log (L"SRC=%dx%d %dx%d\n", srcrect->left, srcrect->top, srcrect->right, srcrect->bottom); - if (srcrect) - write_log (L"DST=%dx%d %dx%d\n", dstrect->left, dstrect->top, dstrect->right, dstrect->bottom); - break; + LPDIRECTDRAWSURFACE7 dst; + int result = 0; + HRESULT ddrval; + RECT dstrect2; + int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; + + dst = dxdata.primary; + if (dstrect == NULL) { + dstrect = &dstrect2; + SetRect (dstrect, x, y, x + w, y + h); } - } - if (SUCCEEDED(ddrval)) - result = 1; - return result; + centerdstrect (dstrect); + while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, dstrect, dxdata.secondary, srcrect, DDBLT_WAIT, NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurfacex (dst, dxdata.secondary); + if (FAILED (ddrval)) + return 0; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log (L"DirectDraw_BlitToPrimary: %s\n", DXError (ddrval)); + if (srcrect) + write_log (L"SRC=%dx%d %dx%d\n", srcrect->left, srcrect->top, srcrect->right, srcrect->bottom); + if (srcrect) + write_log (L"DST=%dx%d %dx%d\n", dstrect->left, dstrect->top, dstrect->right, dstrect->bottom); + break; + } + } + if (SUCCEEDED(ddrval)) + result = 1; + return result; } static int DirectDraw_BlitToPrimary2 (RECT *rect, int dooffset) { - LPDIRECTDRAWSURFACE7 dst; - int result = 0; - HRESULT ddrval; - RECT srcrect, dstrect; - int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; - - dst = dxdata.primary; - if (dst == NULL) - return DD_FALSE; - 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); - if (rect || dooffset) - centerdstrect (&dstrect); - while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, &dstrect, dxdata.secondary, &srcrect, DDBLT_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, dxdata.secondary); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (L"DirectDraw_BlitToPrimary: %s\n", DXError (ddrval)); - break; + LPDIRECTDRAWSURFACE7 dst; + int result = 0; + HRESULT ddrval; + RECT srcrect, dstrect; + int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; + + dst = dxdata.primary; + if (dst == NULL) + return DD_FALSE; + if (rect) { + x = rect->left; + y = rect->top; + w = rect->right - rect->left; + h = rect->bottom - rect->top; } - } - if (SUCCEEDED(ddrval)) - result = 1; - return result; + 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); + if (rect || dooffset) + centerdstrect (&dstrect); + while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, &dstrect, dxdata.secondary, &srcrect, DDBLT_WAIT, NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurfacex (dst, dxdata.secondary); + if (FAILED (ddrval)) + return 0; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log (L"DirectDraw_BlitToPrimary: %s\n", DXError (ddrval)); + break; + } + } + if (SUCCEEDED(ddrval)) + result = 1; + return result; } int DirectDraw_BlitToPrimary (RECT *rect) { - return DirectDraw_BlitToPrimary2 (rect, FALSE); + return DirectDraw_BlitToPrimary2 (rect, FALSE); } static int DirectDraw_Blt_EmuCK (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *srcrect) { - DDSURFACEDESC2 dstd, srcd; - int x, y, w, h, bpp; - int sx, sy, dx, dy; - int ok; - DWORD ck; - - ok = 0; - ck = dxdata.colorkey; - sx = sy = dx = dy = 0; - if (srcrect) { - sx = srcrect->left; - sy = srcrect->top; - } - if (dstrect) { - dx = dstrect->left; - dy = dstrect->top; - } - if (locksurface (dst, &dstd)) { - if (locksurface (src, &srcd)) { - bpp = srcd.ddpfPixelFormat.dwRGBBitCount / 8; - h = srcd.dwHeight; - w = srcd.dwWidth; - if (srcrect) - w = srcrect->right - srcrect->left; - if (srcrect) - h = srcrect->bottom - srcrect->top; - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - uae_u8 *sp = (uae_u8*)srcd.lpSurface + srcd.lPitch * (y + sy) + (x + sx) * bpp; - uae_u8 *dp = (uae_u8*)dstd.lpSurface + dstd.lPitch * (y + dy) + (x + dx) * bpp; - if (bpp == 1) { - if (*sp != ck) - *dp = *sp; - } else if (bpp == 2) { - if (((uae_u16*)sp)[0] != ck) - ((uae_u16*)dp)[0] = ((uae_u16*)sp)[0]; - } else if (bpp == 4) { - if (((uae_u32*)sp)[0] != ck) - ((uae_u32*)dp)[0] = ((uae_u32*)sp)[0]; - } + DDSURFACEDESC2 dstd, srcd; + int x, y, w, h, bpp; + int sx, sy, dx, dy; + int ok; + DWORD ck; + + ok = 0; + ck = dxdata.colorkey; + sx = sy = dx = dy = 0; + if (srcrect) { + sx = srcrect->left; + sy = srcrect->top; + } + if (dstrect) { + dx = dstrect->left; + dy = dstrect->top; + } + if (locksurface (dst, &dstd)) { + if (locksurface (src, &srcd)) { + bpp = srcd.ddpfPixelFormat.dwRGBBitCount / 8; + h = srcd.dwHeight; + w = srcd.dwWidth; + if (srcrect) + w = srcrect->right - srcrect->left; + if (srcrect) + h = srcrect->bottom - srcrect->top; + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + uae_u8 *sp = (uae_u8*)srcd.lpSurface + srcd.lPitch * (y + sy) + (x + sx) * bpp; + uae_u8 *dp = (uae_u8*)dstd.lpSurface + dstd.lPitch * (y + dy) + (x + dx) * bpp; + if (bpp == 1) { + if (*sp != ck) + *dp = *sp; + } else if (bpp == 2) { + if (((uae_u16*)sp)[0] != ck) + ((uae_u16*)dp)[0] = ((uae_u16*)sp)[0]; + } else if (bpp == 4) { + if (((uae_u32*)sp)[0] != ck) + ((uae_u32*)dp)[0] = ((uae_u32*)sp)[0]; + } + } + } + ok = 1; + unlocksurface (src); } - } - ok = 1; - unlocksurface (src); + unlocksurface (dst); } - unlocksurface (dst); - } - return ok; + return ok; } static int DirectDraw_Blt (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *srcrect, int ck) { - HRESULT ddrval; - - if (dst == NULL) - dst = getlocksurface (); - if (src == NULL) - src = getlocksurface (); - if (dst == src) - return 1; - if (ck && dxcaps.cancolorkey == 0) - return DirectDraw_Blt_EmuCK (dst, dstrect, src, srcrect); - while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, dstrect, src, srcrect, DDBLT_WAIT | (ck ? DDBLT_KEYSRC : 0), NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, src); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (L"DirectDraw_Blit: %s\n", DXError (ddrval)); - return 0; + HRESULT ddrval; + + if (dst == NULL) + dst = getlocksurface (); + if (src == NULL) + src = getlocksurface (); + if (dst == src) + return 1; + if (ck && dxcaps.cancolorkey == 0) + return DirectDraw_Blt_EmuCK (dst, dstrect, src, srcrect); + while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, dstrect, src, srcrect, DDBLT_WAIT | (ck ? DDBLT_KEYSRC : 0), NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurfacex (dst, src); + if (FAILED (ddrval)) + return 0; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log (L"DirectDraw_Blit: %s\n", DXError (ddrval)); + return 0; + } } - } - return 1; + return 1; } int DirectDraw_Blit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src) { - return DirectDraw_Blt (dst, NULL, src, NULL, FALSE); + return DirectDraw_Blt (dst, NULL, src, NULL, FALSE); } int DirectDraw_BlitRect (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect) { - return DirectDraw_Blt (dst, dstrect, src, scrrect, FALSE); + return DirectDraw_Blt (dst, dstrect, src, scrrect, FALSE); } int DirectDraw_BlitRectCK (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect) { - return DirectDraw_Blt (dst, dstrect, src, scrrect, TRUE); + return DirectDraw_Blt (dst, dstrect, src, scrrect, TRUE); } void DirectDraw_FillSurface (LPDIRECTDRAWSURFACE7 dst, RECT *rect, uae_u32 color) { - HRESULT ddrval; - DDBLTFX ddbltfx; - - if (!dst) - return; - memset (&ddbltfx, 0, sizeof (ddbltfx)); - ddbltfx.dwFillColor = color; - ddbltfx.dwSize = sizeof (ddbltfx); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, rect, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (dst); - if (FAILED (ddrval)) - break; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (L"DirectDraw_Fill: %s\n", DXError (ddrval)); - break; + HRESULT ddrval; + DDBLTFX ddbltfx; + + if (!dst) + return; + memset (&ddbltfx, 0, sizeof (ddbltfx)); + ddbltfx.dwFillColor = color; + ddbltfx.dwSize = sizeof (ddbltfx); + while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, rect, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (dst); + if (FAILED (ddrval)) + break; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log (L"DirectDraw_Fill: %s\n", DXError (ddrval)); + break; + } } - } } void DirectDraw_Fill (RECT *rect, uae_u32 color) { - DirectDraw_FillSurface (getlocksurface (), rect, color); + DirectDraw_FillSurface (getlocksurface (), rect, color); } void DirectDraw_FillPrimary (void) { - DirectDraw_FillSurface (dxdata.primary, NULL, 0); + DirectDraw_FillSurface (dxdata.primary, NULL, 0); } extern int vblank_skip; static void flip (void) { - int result = 0; - HRESULT ddrval = DD_OK; - DWORD flags = DDFLIP_WAIT; - - if (currprefs.turbo_emulation) - flags |= DDFLIP_NOVSYNC; - if (dxdata.backbuffers == 2) { - DirectDraw_Blit (dxdata.flipping[1], dxdata.flipping[0]); - if (currprefs.gfx_avsync) { - if (vblank_skip >= 0 || currprefs.turbo_emulation) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else { - if (flipinterval_supported) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); + int result = 0; + HRESULT ddrval = DD_OK; + DWORD flags = DDFLIP_WAIT; + + if (currprefs.turbo_emulation) + flags |= DDFLIP_NOVSYNC; + if (dxdata.backbuffers == 2) { + DirectDraw_Blit (dxdata.flipping[1], dxdata.flipping[0]); + if (currprefs.gfx_avsync) { + if (vblank_skip >= 0 || currprefs.turbo_emulation) { + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + } else { + if (flipinterval_supported) { + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); + } else { + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + DirectDraw_Blit (dxdata.flipping[1], dxdata.primary); + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + } + } } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_Blit (dxdata.flipping[1], dxdata.primary); - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags| DDFLIP_NOVSYNC); } - } - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags| DDFLIP_NOVSYNC); - } - } else if(dxdata.backbuffers == 1) { - if (currprefs.gfx_avsync) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_NOVSYNC); + } else if(dxdata.backbuffers == 1) { + if (currprefs.gfx_avsync) { + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + } else { + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_NOVSYNC); + } + DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); } - DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); - } - if (ddrval == DDERR_SURFACELOST) { - static int recurse; - restoresurface (dxdata.primary); - if (!recurse) { - recurse++; - flip (); - recurse--; + if (ddrval == DDERR_SURFACELOST) { + static int recurse; + restoresurface (dxdata.primary); + if (!recurse) { + recurse++; + flip (); + recurse--; + } + } else if (FAILED (ddrval)) { + write_log (L"IDirectDrawSurface7_Flip: %s\n", DXError (ddrval)); } - } else if (FAILED (ddrval)) { - write_log (L"IDirectDrawSurface7_Flip: %s\n", DXError (ddrval)); - } } int DirectDraw_Flip (int doflip) { - if (dxdata.primary == NULL) - return 0; - if (getlocksurface () != dxdata.secondary) { - if (doflip) { - flip (); - return 1; + if (dxdata.primary == NULL) + return 0; + if (getlocksurface () != dxdata.secondary) { + if (doflip) { + flip (); + return 1; + } else { + DirectDraw_Blit (dxdata.primary, getlocksurface ()); + } } else { - DirectDraw_Blit (dxdata.primary, getlocksurface ()); + DirectDraw_BlitToPrimary2 (NULL, TRUE); } - } else { - DirectDraw_BlitToPrimary2 (NULL, TRUE); - } - return 1; + return 1; } HRESULT DirectDraw_SetPaletteEntries (int start, int count, PALETTEENTRY *palette) { - HRESULT ddrval = DDERR_NOPALETTEATTACHED; - if (dxdata.palette) - ddrval = IDirectDrawPalette_SetEntries(dxdata.palette, 0, start, count, palette); - return ddrval; + HRESULT ddrval = DDERR_NOPALETTEATTACHED; + if (dxdata.palette) + ddrval = IDirectDrawPalette_SetEntries(dxdata.palette, 0, start, count, palette); + return ddrval; } HRESULT DirectDraw_SetPalette (int remove) { - HRESULT ddrval; - if (dxdata.fsmodeset <= 0 || (!dxdata.palette && !remove)) - return DD_FALSE; - ddrval = IDirectDrawSurface7_SetPalette (dxdata.primary, remove ? NULL : dxdata.palette); - if (FAILED (ddrval)) - write_log (L"IDirectDrawSurface7_SetPalette: %s\n", DXError (ddrval)); - return ddrval; + HRESULT ddrval; + if (dxdata.fsmodeset <= 0 || (!dxdata.palette && !remove)) + return DD_FALSE; + ddrval = IDirectDrawSurface7_SetPalette (dxdata.primary, remove ? NULL : dxdata.palette); + if (FAILED (ddrval)) + write_log (L"IDirectDrawSurface7_SetPalette: %s\n", DXError (ddrval)); + return ddrval; } HRESULT DirectDraw_CreatePalette (LPPALETTEENTRY pal) { - HRESULT ddrval; - ddrval = IDirectDraw_CreatePalette (dxdata.maindd, DDPCAPS_8BIT | DDPCAPS_ALLOW256, pal, &dxdata.palette, NULL); - if (FAILED (ddrval)) - write_log (L"IDirectDraw_CreatePalette: %s\n", DXError (ddrval)); - return ddrval; + HRESULT ddrval; + ddrval = IDirectDraw_CreatePalette (dxdata.maindd, DDPCAPS_8BIT | DDPCAPS_ALLOW256, pal, &dxdata.palette, NULL); + if (FAILED (ddrval)) + write_log (L"IDirectDraw_CreatePalette: %s\n", DXError (ddrval)); + return ddrval; } void DirectDraw_Release (void) { - if (!dxdata.ddinit) - return; - dxdata.isoverlay = 0; - dxdata.islost = 0; - 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, IDirectDraw7_Release); - memset (&dxdata, 0, sizeof (dxdata)); + if (!dxdata.ddinit) + return; + dxdata.isoverlay = 0; + dxdata.islost = 0; + 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, IDirectDraw7_Release); + memset (&dxdata, 0, sizeof (dxdata)); } struct dxcap { - int num; - TCHAR *name; - DWORD mask; + int num; + TCHAR *name; + DWORD mask; }; static struct dxcap dxcapsinfo[] = { - { 1, L"DDCAPS_BLT", DDCAPS_BLT }, - { 1, L"DDCAPS_BLTQUEUE", DDCAPS_BLTQUEUE }, - { 1, L"DDCAPS_BLTFOURCC", DDCAPS_BLTFOURCC }, - { 1, L"DDCAPS_BLTCOLORFILL", DDCAPS_BLTSTRETCH }, - { 1, L"DDCAPS_BLTSTRETCH", DDCAPS_BLTSTRETCH }, - { 1, L"DDCAPS_CANBLTSYSMEM", DDCAPS_CANBLTSYSMEM }, - { 1, L"DDCAPS_CANCLIP", DDCAPS_CANCLIP }, - { 1, L"DDCAPS_CANCLIPSTRETCHED", DDCAPS_CANCLIPSTRETCHED }, - { 1, L"DDCAPS_COLORKEY", DDCAPS_COLORKEY }, - { 1, L"DDCAPS_COLORKEYHWASSIST", DDCAPS_COLORKEYHWASSIST }, - { 1, L"DDCAPS_GDI", DDCAPS_GDI }, - { 1, L"DDCAPS_NOHARDWARE", DDCAPS_NOHARDWARE }, - { 1, L"DDCAPS_OVERLAY", DDCAPS_OVERLAY }, - { 1, L"DDCAPS_VBI", DDCAPS_VBI }, - { 1, L"DDCAPS_3D", DDCAPS_3D }, - { 1, L"DDCAPS_BANKSWITCHED", DDCAPS_BANKSWITCHED }, - { 1, L"DDCAPS_PALETTE", DDCAPS_PALETTE }, - { 1, L"DDCAPS_PALETTEVSYNC", DDCAPS_PALETTEVSYNC }, - { 1, L"DDCAPS_READSCANLINE", DDCAPS_READSCANLINE }, - { 2, L"DDCAPS2_CERTIFIED", DDCAPS2_CERTIFIED }, - { 2, L"DDCAPS2_CANRENDERWINDOWED", DDCAPS2_CANRENDERWINDOWED }, - { 2, L"DDCAPS2_NOPAGELOCKREQUIRED", DDCAPS2_NOPAGELOCKREQUIRED }, - { 2, L"DDCAPS2_FLIPNOVSYNC", DDCAPS2_FLIPNOVSYNC }, - { 2, L"DDCAPS2_FLIPINTERVAL", DDCAPS2_FLIPINTERVAL }, - { 2, L"DDCAPS2_NO2DDURING3DSCENE", DDCAPS2_NO2DDURING3DSCENE }, - { 2, L"DDCAPS2_NONLOCALVIDMEM", DDCAPS2_NONLOCALVIDMEM }, - { 2, L"DDCAPS2_NONLOCALVIDMEMCAPS", DDCAPS2_NONLOCALVIDMEMCAPS }, - { 2, L"DDCAPS2_WIDESURFACES", DDCAPS2_WIDESURFACES }, - { 3, L"DDCKEYCAPS_DESTBLT", DDCKEYCAPS_DESTBLT }, - { 3, L"DDCKEYCAPS_DESTBLTCLRSPACE", DDCKEYCAPS_DESTBLTCLRSPACE }, - { 3, L"DDCKEYCAPS_SRCBLT", DDCKEYCAPS_SRCBLT }, - { 3, L"DDCKEYCAPS_SRCBLTCLRSPACE", DDCKEYCAPS_SRCBLTCLRSPACE }, - { 0, NULL } + { 1, L"DDCAPS_BLT", DDCAPS_BLT }, + { 1, L"DDCAPS_BLTQUEUE", DDCAPS_BLTQUEUE }, + { 1, L"DDCAPS_BLTFOURCC", DDCAPS_BLTFOURCC }, + { 1, L"DDCAPS_BLTCOLORFILL", DDCAPS_BLTSTRETCH }, + { 1, L"DDCAPS_BLTSTRETCH", DDCAPS_BLTSTRETCH }, + { 1, L"DDCAPS_CANBLTSYSMEM", DDCAPS_CANBLTSYSMEM }, + { 1, L"DDCAPS_CANCLIP", DDCAPS_CANCLIP }, + { 1, L"DDCAPS_CANCLIPSTRETCHED", DDCAPS_CANCLIPSTRETCHED }, + { 1, L"DDCAPS_COLORKEY", DDCAPS_COLORKEY }, + { 1, L"DDCAPS_COLORKEYHWASSIST", DDCAPS_COLORKEYHWASSIST }, + { 1, L"DDCAPS_GDI", DDCAPS_GDI }, + { 1, L"DDCAPS_NOHARDWARE", DDCAPS_NOHARDWARE }, + { 1, L"DDCAPS_OVERLAY", DDCAPS_OVERLAY }, + { 1, L"DDCAPS_VBI", DDCAPS_VBI }, + { 1, L"DDCAPS_3D", DDCAPS_3D }, + { 1, L"DDCAPS_BANKSWITCHED", DDCAPS_BANKSWITCHED }, + { 1, L"DDCAPS_PALETTE", DDCAPS_PALETTE }, + { 1, L"DDCAPS_PALETTEVSYNC", DDCAPS_PALETTEVSYNC }, + { 1, L"DDCAPS_READSCANLINE", DDCAPS_READSCANLINE }, + { 2, L"DDCAPS2_CERTIFIED", DDCAPS2_CERTIFIED }, + { 2, L"DDCAPS2_CANRENDERWINDOWED", DDCAPS2_CANRENDERWINDOWED }, + { 2, L"DDCAPS2_NOPAGELOCKREQUIRED", DDCAPS2_NOPAGELOCKREQUIRED }, + { 2, L"DDCAPS2_FLIPNOVSYNC", DDCAPS2_FLIPNOVSYNC }, + { 2, L"DDCAPS2_FLIPINTERVAL", DDCAPS2_FLIPINTERVAL }, + { 2, L"DDCAPS2_NO2DDURING3DSCENE", DDCAPS2_NO2DDURING3DSCENE }, + { 2, L"DDCAPS2_NONLOCALVIDMEM", DDCAPS2_NONLOCALVIDMEM }, + { 2, L"DDCAPS2_NONLOCALVIDMEMCAPS", DDCAPS2_NONLOCALVIDMEMCAPS }, + { 2, L"DDCAPS2_WIDESURFACES", DDCAPS2_WIDESURFACES }, + { 3, L"DDCKEYCAPS_DESTBLT", DDCKEYCAPS_DESTBLT }, + { 3, L"DDCKEYCAPS_DESTBLTCLRSPACE", DDCKEYCAPS_DESTBLTCLRSPACE }, + { 3, L"DDCKEYCAPS_SRCBLT", DDCKEYCAPS_SRCBLT }, + { 3, L"DDCKEYCAPS_SRCBLTCLRSPACE", DDCKEYCAPS_SRCBLTCLRSPACE }, + { 0, NULL } }; static void showcaps (DDCAPS_DX7 *dc) { - int i, out; - write_log (L"%08x %08x %08x %08x %08x %08x\n", - dc->dwCaps, dc->dwCaps2, dc->dwCKeyCaps, dc->dwFXCaps, dc->dwFXAlphaCaps, dc->dwPalCaps, dc->ddsCaps); - out = 0; - for (i = 0; dxcapsinfo[i].name; i++) { - DWORD caps = 0; - switch (dxcapsinfo[i].num) - { - case 1: - caps = dc->dwCaps; - break; - case 2: - caps = dc->dwCaps2; - break; - case 3: - caps = dc->dwCKeyCaps; - break; - } - if (caps & dxcapsinfo[i].mask) { - if (out > 0) - write_log (L","); - write_log (L"%s", dxcapsinfo[i].name); - out++; + int i, out; + write_log (L"%08x %08x %08x %08x %08x %08x\n", + dc->dwCaps, dc->dwCaps2, dc->dwCKeyCaps, dc->dwFXCaps, dc->dwFXAlphaCaps, dc->dwPalCaps, dc->ddsCaps); + out = 0; + for (i = 0; dxcapsinfo[i].name; i++) { + DWORD caps = 0; + switch (dxcapsinfo[i].num) + { + case 1: + caps = dc->dwCaps; + break; + case 2: + caps = dc->dwCaps2; + break; + case 3: + caps = dc->dwCKeyCaps; + break; + } + if (caps & dxcapsinfo[i].mask) { + if (out > 0) + write_log (L","); + write_log (L"%s", dxcapsinfo[i].name); + out++; + } } - } - if (out > 0) - write_log (L"\n"); - if ((dc->dwCaps & DDCAPS_COLORKEY) && (dc->dwCKeyCaps & DDCKEYCAPS_SRCBLT)) - dxcaps.cancolorkey = TRUE; - if (dc->dwCaps2 & DDCAPS2_NONLOCALVIDMEM) - dxcaps.cannonlocalvidmem = TRUE; - if (ddsoftwarecolorkey) - dxcaps.cancolorkey = FALSE; + if (out > 0) + write_log (L"\n"); + if ((dc->dwCaps & DDCAPS_COLORKEY) && (dc->dwCKeyCaps & DDCKEYCAPS_SRCBLT)) + dxcaps.cancolorkey = TRUE; + if (dc->dwCaps2 & DDCAPS2_NONLOCALVIDMEM) + dxcaps.cannonlocalvidmem = TRUE; + if (ddsoftwarecolorkey) + dxcaps.cancolorkey = FALSE; } static void getcaps (void) { - HRESULT hr; - DDCAPS_DX7 dc, hc; - - memset (&dc, 0, sizeof dc); - memset (&hc, 0, sizeof hc); - dc.dwSize = sizeof dc; - hc.dwSize = sizeof hc; - hr = IDirectDraw7_GetCaps (dxdata.maindd, &dc, &hc); - if (FAILED (hr)) { - write_log (L"IDirectDraw7_GetCaps() failed %s\n", DXError (hr)); - return; - } - write_log (L"DriverCaps: "); - showcaps (&dc); - write_log (L"HELCaps : "); - showcaps (&hc); + HRESULT hr; + DDCAPS_DX7 dc, hc; + + memset (&dc, 0, sizeof dc); + memset (&hc, 0, sizeof hc); + dc.dwSize = sizeof dc; + hc.dwSize = sizeof hc; + hr = IDirectDraw7_GetCaps (dxdata.maindd, &dc, &hc); + if (FAILED (hr)) { + write_log (L"IDirectDraw7_GetCaps() failed %s\n", DXError (hr)); + return; + } + write_log (L"DriverCaps: "); + showcaps (&dc); + write_log (L"HELCaps : "); + showcaps (&hc); } int DirectDraw_Start (GUID *guid) { - static int d3ddone; - static int first; - HRESULT ddrval; - LPDIRECT3D9 d3d; - D3DCAPS9 d3dCaps; - HINSTANCE d3dDLL; - - dxdata.islost = 0; - if (dxdata.ddinit) { - if (guid == NULL && dxdata.ddzeroguid) - return -1; - if (guid && !memcmp (guid, &dxdata.ddguid, sizeof (GUID))) - return -1; - DirectDraw_Release (); - } + static int d3ddone; + static int first; + HRESULT ddrval; + LPDIRECT3D9 d3d; + D3DCAPS9 d3dCaps; + HINSTANCE d3dDLL; + + dxdata.islost = 0; + if (dxdata.ddinit) { + if (guid == NULL && dxdata.ddzeroguid) + return -1; + if (guid && !memcmp (guid, &dxdata.ddguid, sizeof (GUID))) + return -1; + DirectDraw_Release (); + } #if 0 - LPDIRECTDRAW dd; - ddrval = DirectDrawCreate (guid, &dd, NULL); - if (FAILED (ddrval)) { - write_log (L"DirectDrawCreate() failed, %s\n", DXError (ddrval)); - if (guid != NULL) - return 0; - goto oops; - } - ddrval = IDirectDraw_QueryInterface (dd, &IID_IDirectDraw7, &dxdata.maindd); - IDirectDraw_Release (dd); - if (FAILED (ddrval)) { - write_log (L"IDirectDraw_QueryInterface() failed, %s\n", DXError (ddrval)); - goto oops; - } + LPDIRECTDRAW dd; + ddrval = DirectDrawCreate (guid, &dd, NULL); + if (FAILED (ddrval)) { + write_log (L"DirectDrawCreate() failed, %s\n", DXError (ddrval)); + if (guid != NULL) + return 0; + goto oops; + } + ddrval = IDirectDraw_QueryInterface (dd, &IID_IDirectDraw7, &dxdata.maindd); + IDirectDraw_Release (dd); + if (FAILED (ddrval)) { + write_log (L"IDirectDraw_QueryInterface() failed, %s\n", DXError (ddrval)); + goto oops; + } #else - ddrval = DirectDrawCreateEx (guid, &dxdata.maindd, &IID_IDirectDraw7, NULL); - if (FAILED (ddrval)) { - write_log (L"DirectDrawCreateEx() failed, %s\n", DXError (ddrval)); - if (guid != NULL) - return 0; - goto oops; - } + ddrval = DirectDrawCreateEx (guid, &dxdata.maindd, &IID_IDirectDraw7, NULL); + if (FAILED (ddrval)) { + write_log (L"DirectDrawCreateEx() failed, %s\n", DXError (ddrval)); + if (guid != NULL) + return 0; + goto oops; + } #endif - dxdata.statuswidth = 800; - dxdata.statusheight = TD_TOTAL_HEIGHT; - dxcaps.cursorwidth = 48; - dxcaps.cursorheight = 48; - if (!d3ddone) { - d3dDLL = LoadLibrary (L"D3D9.DLL"); - if (d3dDLL) { - d3d = Direct3DCreate9 (D3D9b_SDK_VERSION); - if (d3d) { - if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3d, 0, D3DDEVTYPE_HAL, &d3dCaps))) { - dxcaps.maxwidth = d3dCaps.MaxTextureWidth; - dxcaps.maxheight = d3dCaps.MaxTextureHeight; - write_log (L"Max hardware surface size: %dx%d\n", dxcaps.maxwidth, dxcaps.maxheight); + dxdata.statuswidth = 800; + dxdata.statusheight = TD_TOTAL_HEIGHT; + dxcaps.cursorwidth = 48; + dxcaps.cursorheight = 48; + if (!d3ddone) { + d3dDLL = LoadLibrary (L"D3D9.DLL"); + if (d3dDLL) { + d3d = Direct3DCreate9 (D3D9b_SDK_VERSION); + if (d3d) { + if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3d, 0, D3DDEVTYPE_HAL, &d3dCaps))) { + dxcaps.maxwidth = d3dCaps.MaxTextureWidth; + dxcaps.maxheight = d3dCaps.MaxTextureHeight; + write_log (L"Max hardware surface size: %dx%d\n", dxcaps.maxwidth, dxcaps.maxheight); + } + IDirect3D9_Release (d3d); + } + FreeLibrary (d3dDLL); } - IDirect3D9_Release (d3d); - } - FreeLibrary (d3dDLL); + d3ddone = 1; } - d3ddone = 1; - } - if (dxcaps.maxwidth < 2048) - dxcaps.maxwidth = 2048; - if (dxcaps.maxheight < 2048) - dxcaps.maxheight = 2048; - - if (!first) { - first = 1; - getcaps (); - } - - if (SUCCEEDED (DirectDraw_GetDisplayMode ())) { - dxdata.ddinit = 1; - dxdata.ddzeroguid = 1; - if (guid) { - dxdata.ddzeroguid = 0; - memcpy (&dxdata.ddguid, guid, sizeof (GUID)); + if (dxcaps.maxwidth < 2048) + dxcaps.maxwidth = 2048; + if (dxcaps.maxheight < 2048) + dxcaps.maxheight = 2048; + + if (!first) { + first = 1; + getcaps (); } - return 1; - } - oops: - write_log (L"DirectDraw_Start: %s\n", DXError (ddrval)); - DirectDraw_Release (); - return 0; + + if (SUCCEEDED (DirectDraw_GetDisplayMode ())) { + dxdata.ddinit = 1; + dxdata.ddzeroguid = 1; + if (guid) { + dxdata.ddzeroguid = 0; + memcpy (&dxdata.ddguid, guid, sizeof (GUID)); + } + return 1; + } +oops: + write_log (L"DirectDraw_Start: %s\n", DXError (ddrval)); + DirectDraw_Release (); + return 0; } int dx_islost (void) { - return dxdata.islost; + return dxdata.islost; } void dx_check (void) { - dxdata.islost = 0; - if (dxdata.fsmodeset <= 0 || dxdata.primary == NULL) - return; - if (IDirectDrawSurface7_IsLost (dxdata.primary) != DDERR_SURFACELOST) - return; - if (IDirectDrawSurface7_Restore (dxdata.primary) != DDERR_WRONGMODE) - return; - dxdata.islost = 1; + dxdata.islost = 0; + if (dxdata.fsmodeset <= 0 || dxdata.primary == NULL) + return; + if (IDirectDrawSurface7_IsLost (dxdata.primary) != DDERR_SURFACELOST) + return; + if (IDirectDrawSurface7_Restore (dxdata.primary) != DDERR_WRONGMODE) + return; + dxdata.islost = 1; } diff --git a/od-win32/fsdb_mywin32.c b/od-win32/fsdb_mywin32.c index e000fc58..e5993cec 100644 --- a/od-win32/fsdb_mywin32.c +++ b/od-win32/fsdb_mywin32.c @@ -9,392 +9,392 @@ int my_setcurrentdir (const TCHAR *curdir, TCHAR *oldcur) { - int ret = 0; - if (oldcur) - ret = GetCurrentDirectory (MAX_DPATH, oldcur); - if (curdir) - ret = SetCurrentDirectory (curdir); - return ret; + int ret = 0; + if (oldcur) + ret = GetCurrentDirectory (MAX_DPATH, oldcur); + if (curdir) + ret = SetCurrentDirectory (curdir); + return ret; } int my_mkdir (const TCHAR *name) { - return CreateDirectory (name, NULL) == 0 ? -1 : 0; + return CreateDirectory (name, NULL) == 0 ? -1 : 0; } static int recycle (const TCHAR *name) { - if (currprefs.win32_norecyclebin) { - DWORD dirattr = GetFileAttributes (name); - if (dirattr != INVALID_FILE_ATTRIBUTES && (dirattr & FILE_ATTRIBUTE_DIRECTORY)) - return RemoveDirectory (name) ? 0 : -1; - return DeleteFile(name) ? 0 : -1; - } else { - SHFILEOPSTRUCT fos; - /* name must be terminated by \0\0 */ - TCHAR *p = xcalloc ((_tcslen (name) + 2) * sizeof (TCHAR), 1); - int v; - - _tcscpy (p, name); - memset (&fos, 0, sizeof (fos)); - fos.wFunc = FO_DELETE; - fos.pFrom = p; - fos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NORECURSION | FOF_SILENT; - v = SHFileOperation (&fos); - xfree (p); - switch (v) - { - case 0xb7: //DE_ERROR_MAX - case 0x7c: //DE_INVALIDFILES - case 0x402: // "unknown error" - v = ERROR_FILE_NOT_FOUND; - break; - case 0x75: //DE_OPCANCELLED: - case 0x10000: //ERRORONDEST: - case 0x78: //DE_ACCESSDENIEDSRC: - case 0x74: //DE_ROOTDIR: - v = ERROR_ACCESS_DENIED; - break; + if (currprefs.win32_norecyclebin) { + DWORD dirattr = GetFileAttributes (name); + if (dirattr != INVALID_FILE_ATTRIBUTES && (dirattr & FILE_ATTRIBUTE_DIRECTORY)) + return RemoveDirectory (name) ? 0 : -1; + return DeleteFile(name) ? 0 : -1; + } else { + SHFILEOPSTRUCT fos; + /* name must be terminated by \0\0 */ + TCHAR *p = xcalloc ((_tcslen (name) + 2) * sizeof (TCHAR), 1); + int v; + + _tcscpy (p, name); + memset (&fos, 0, sizeof (fos)); + fos.wFunc = FO_DELETE; + fos.pFrom = p; + fos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NORECURSION | FOF_SILENT; + v = SHFileOperation (&fos); + xfree (p); + switch (v) + { + case 0xb7: //DE_ERROR_MAX + case 0x7c: //DE_INVALIDFILES + case 0x402: // "unknown error" + v = ERROR_FILE_NOT_FOUND; + break; + case 0x75: //DE_OPCANCELLED: + case 0x10000: //ERRORONDEST: + case 0x78: //DE_ACCESSDENIEDSRC: + case 0x74: //DE_ROOTDIR: + v = ERROR_ACCESS_DENIED; + break; + } + SetLastError (v); + return v ? -1 : 0; } - SetLastError (v); - return v ? -1 : 0; - } } int my_rmdir (const TCHAR *name) { - void *od; - int cnt; - TCHAR tname[MAX_DPATH]; - - /* SHFileOperation() ignores FOF_NORECURSION when deleting directories.. */ - od = my_opendir (name); - if (!od) { - SetLastError (ERROR_FILE_NOT_FOUND); - return -1; - } - cnt = 0; - while (my_readdir (od, tname)) { - if (!_tcscmp (tname, L".") || !_tcscmp (tname, L"..")) - continue; - cnt++; - break; - } - my_closedir (od); - if (cnt > 0) { - SetLastError (ERROR_CURRENT_DIRECTORY); - return -1; - } - - return recycle (name); + void *od; + int cnt; + TCHAR tname[MAX_DPATH]; + + /* SHFileOperation() ignores FOF_NORECURSION when deleting directories.. */ + od = my_opendir (name); + if (!od) { + SetLastError (ERROR_FILE_NOT_FOUND); + return -1; + } + cnt = 0; + while (my_readdir (od, tname)) { + if (!_tcscmp (tname, L".") || !_tcscmp (tname, L"..")) + continue; + cnt++; + break; + } + my_closedir (od); + if (cnt > 0) { + SetLastError (ERROR_CURRENT_DIRECTORY); + return -1; + } + + return recycle (name); } /* "move to Recycle Bin" (if enabled) -version of DeleteFile() */ int my_unlink (const TCHAR *name) { - return recycle (name); + return recycle (name); } int my_rename (const TCHAR *oldname, const TCHAR *newname) { - return MoveFile (oldname, newname) == 0 ? -1 : 0; + return MoveFile (oldname, newname) == 0 ? -1 : 0; } struct my_opendirs { - HANDLE *h; - WIN32_FIND_DATA fd; - int first; + HANDLE *h; + WIN32_FIND_DATA fd; + int first; }; void *my_opendir (const TCHAR *name) { - struct my_opendirs *mod; - TCHAR tmp[MAX_DPATH]; - - _tcscpy (tmp, name); - _tcscat (tmp, L"\\*.*"); - mod = xmalloc (sizeof (struct my_opendirs)); - if (!mod) - return NULL; - mod->h = FindFirstFile(tmp, &mod->fd); - if (mod->h == INVALID_HANDLE_VALUE) { - xfree (mod); - return NULL; - } - mod->first = 1; - return mod; + struct my_opendirs *mod; + TCHAR tmp[MAX_DPATH]; + + _tcscpy (tmp, name); + _tcscat (tmp, L"\\*.*"); + mod = xmalloc (sizeof (struct my_opendirs)); + if (!mod) + return NULL; + mod->h = FindFirstFile(tmp, &mod->fd); + if (mod->h == INVALID_HANDLE_VALUE) { + xfree (mod); + return NULL; + } + mod->first = 1; + return mod; } void my_closedir (void *d) { - struct my_opendirs *mod = d; - if (d) - FindClose (mod->h); - xfree (mod); + struct my_opendirs *mod = d; + if (d) + FindClose (mod->h); + xfree (mod); } int my_readdir (void *d, TCHAR *name) { - struct my_opendirs *mod = d; - if (mod->first) { + struct my_opendirs *mod = d; + if (mod->first) { + _tcscpy (name, mod->fd.cFileName); + mod->first = 0; + return 1; + } + if (!FindNextFile (mod->h, &mod->fd)) + return 0; _tcscpy (name, mod->fd.cFileName); - mod->first = 0; return 1; - } - if (!FindNextFile (mod->h, &mod->fd)) - return 0; - _tcscpy (name, mod->fd.cFileName); - return 1; } struct my_opens { - HANDLE *h; + HANDLE *h; }; void my_close (void *d) { - struct my_opens *mos = d; - CloseHandle (mos->h); - xfree (mos); + struct my_opens *mos = d; + CloseHandle (mos->h); + xfree (mos); } uae_s64 int my_lseek (void *d, uae_s64 int offset, int whence) { - struct my_opens *mos = d; - LARGE_INTEGER li; - - li.QuadPart = offset; - li.LowPart = SetFilePointer (mos->h, li.LowPart, &li.HighPart, - whence == SEEK_SET ? FILE_BEGIN : (whence == SEEK_END ? FILE_END : FILE_CURRENT)); - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR) - li.QuadPart = -1; - return li.QuadPart; + struct my_opens *mos = d; + LARGE_INTEGER li; + + li.QuadPart = offset; + li.LowPart = SetFilePointer (mos->h, li.LowPart, &li.HighPart, + whence == SEEK_SET ? FILE_BEGIN : (whence == SEEK_END ? FILE_END : FILE_CURRENT)); + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR) + li.QuadPart = -1; + return li.QuadPart; } unsigned int my_read (void *d, void *b, unsigned int size) { - struct my_opens *mos = d; - DWORD read = 0; - ReadFile (mos->h, b, size, &read, NULL); - return read; + struct my_opens *mos = d; + DWORD read = 0; + ReadFile (mos->h, b, size, &read, NULL); + return read; } unsigned int my_write (void *d, void *b, unsigned int size) { - struct my_opens *mos = d; - DWORD written = 0; - WriteFile (mos->h, b, size, &written, NULL); - return written; + struct my_opens *mos = d; + DWORD written = 0; + WriteFile (mos->h, b, size, &written, NULL); + return written; } static DWORD GetFileAttributesSafe(const TCHAR *name) { - DWORD attr, last; + DWORD attr, last; - last = SetErrorMode (SEM_FAILCRITICALERRORS); - attr = GetFileAttributes (name); - SetErrorMode (last); - return attr; + last = SetErrorMode (SEM_FAILCRITICALERRORS); + attr = GetFileAttributes (name); + SetErrorMode (last); + return attr; } int my_existsfile (const TCHAR *name) { - DWORD attr = GetFileAttributesSafe (name); - if (attr == INVALID_FILE_ATTRIBUTES) + DWORD attr = GetFileAttributesSafe (name); + if (attr == INVALID_FILE_ATTRIBUTES) + return 0; + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) + return 1; return 0; - if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) - return 1; - return 0; } int my_existsdir (const TCHAR *name) { - DWORD attr = GetFileAttributesSafe (name); - if (attr == INVALID_FILE_ATTRIBUTES) + DWORD attr = GetFileAttributesSafe (name); + if (attr == INVALID_FILE_ATTRIBUTES) + return 0; + if (attr & FILE_ATTRIBUTE_DIRECTORY) + return 1; return 0; - if (attr & FILE_ATTRIBUTE_DIRECTORY) - return 1; - return 0; } void *my_open (const TCHAR *name, int flags) { - struct my_opens *mos; - HANDLE h; - DWORD DesiredAccess = GENERIC_READ; - DWORD ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; - DWORD CreationDisposition = OPEN_EXISTING; - DWORD FlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; - DWORD attr; - - mos = xmalloc (sizeof (struct my_opens)); - if (!mos) - return NULL; - attr = GetFileAttributesSafe (name); - if (flags & O_TRUNC) - CreationDisposition = CREATE_ALWAYS; - else if (flags & O_CREAT) - CreationDisposition = OPEN_ALWAYS; - if (flags & O_WRONLY) - DesiredAccess = GENERIC_WRITE; - if (flags & O_RDONLY) { - DesiredAccess = GENERIC_READ; - CreationDisposition = OPEN_EXISTING; - } - if (flags & O_RDWR) - DesiredAccess = GENERIC_READ | GENERIC_WRITE; - if (CreationDisposition == CREATE_ALWAYS && attr != INVALID_FILE_ATTRIBUTES && - (attr & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) - SetFileAttributes (name, FILE_ATTRIBUTE_NORMAL); - h = CreateFile (name, DesiredAccess, ShareMode, NULL, CreationDisposition, FlagsAndAttributes, NULL); - if (h == INVALID_HANDLE_VALUE) { - DWORD err = GetLastError(); - if (err == ERROR_ACCESS_DENIED && (DesiredAccess & GENERIC_WRITE)) { - DesiredAccess &= ~GENERIC_WRITE; - h = CreateFile (name, DesiredAccess, ShareMode, NULL, CreationDisposition, FlagsAndAttributes, NULL); - if (h == INVALID_HANDLE_VALUE) - err = GetLastError(); + struct my_opens *mos; + HANDLE h; + DWORD DesiredAccess = GENERIC_READ; + DWORD ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + DWORD CreationDisposition = OPEN_EXISTING; + DWORD FlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; + DWORD attr; + + mos = xmalloc (sizeof (struct my_opens)); + if (!mos) + return NULL; + attr = GetFileAttributesSafe (name); + if (flags & O_TRUNC) + CreationDisposition = CREATE_ALWAYS; + else if (flags & O_CREAT) + CreationDisposition = OPEN_ALWAYS; + if (flags & O_WRONLY) + DesiredAccess = GENERIC_WRITE; + if (flags & O_RDONLY) { + DesiredAccess = GENERIC_READ; + CreationDisposition = OPEN_EXISTING; } + if (flags & O_RDWR) + DesiredAccess = GENERIC_READ | GENERIC_WRITE; + if (CreationDisposition == CREATE_ALWAYS && attr != INVALID_FILE_ATTRIBUTES && + (attr & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) + SetFileAttributes (name, FILE_ATTRIBUTE_NORMAL); + h = CreateFile (name, DesiredAccess, ShareMode, NULL, CreationDisposition, FlagsAndAttributes, NULL); if (h == INVALID_HANDLE_VALUE) { - write_log (L"failed to open '%s' %x %x err=%d\n", name, DesiredAccess, CreationDisposition, err); - xfree (mos); - mos = NULL; - goto err; + DWORD err = GetLastError(); + if (err == ERROR_ACCESS_DENIED && (DesiredAccess & GENERIC_WRITE)) { + DesiredAccess &= ~GENERIC_WRITE; + h = CreateFile (name, DesiredAccess, ShareMode, NULL, CreationDisposition, FlagsAndAttributes, NULL); + if (h == INVALID_HANDLE_VALUE) + err = GetLastError(); + } + if (h == INVALID_HANDLE_VALUE) { + write_log (L"failed to open '%s' %x %x err=%d\n", name, DesiredAccess, CreationDisposition, err); + xfree (mos); + mos = NULL; + goto err; + } } - } - mos->h = h; + mos->h = h; err: - //write_log (L"open '%s' = %x\n", name, mos ? mos->h : 0); - return mos; + //write_log (L"open '%s' = %x\n", name, mos ? mos->h : 0); + return mos; } int my_truncate (const TCHAR *name, uae_u64 len) { - HANDLE hFile; - BOOL bResult = FALSE; - int result = -1; + HANDLE hFile; + BOOL bResult = FALSE; + int result = -1; - if ((hFile = CreateFile (name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) ) != INVALID_HANDLE_VALUE ) - { - LARGE_INTEGER li; - li.QuadPart = len; - li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_BEGIN); - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR) { - write_log (L"truncate: SetFilePointer() failure for %s to posn %d\n", name, len); + if ((hFile = CreateFile (name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) ) != INVALID_HANDLE_VALUE ) + { + LARGE_INTEGER li; + li.QuadPart = len; + li.LowPart = SetFilePointer (hFile, li.LowPart, &li.HighPart, FILE_BEGIN); + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR) { + write_log (L"truncate: SetFilePointer() failure for %s to posn %d\n", name, len); + } else { + if (SetEndOfFile (hFile) == TRUE) + result = 0; + } + CloseHandle (hFile); } else { - if (SetEndOfFile (hFile) == TRUE) - result = 0; + write_log (L"truncate: CreateFile() failed to open %s\n", name); } - CloseHandle (hFile); - } else { - write_log (L"truncate: CreateFile() failed to open %s\n", name); - } - return result; + return result; } int dos_errno (void) { - DWORD e = GetLastError (); - - //write_log (L"ec=%d\n", e); - switch (e) { - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_OUTOFMEMORY: - return ERROR_NO_FREE_STORE; - - case ERROR_FILE_EXISTS: - case ERROR_ALREADY_EXISTS: - return ERROR_OBJECT_EXISTS; - - case ERROR_WRITE_PROTECT: - case ERROR_ACCESS_DENIED: - return ERROR_WRITE_PROTECTED; - - case ERROR_FILE_NOT_FOUND: - case ERROR_INVALID_DRIVE: - case ERROR_INVALID_NAME: - case ERROR_PATH_NOT_FOUND: - case ERROR_NOT_READY: - case ERROR_BAD_UNIT: - return ERROR_OBJECT_NOT_AROUND; - - case ERROR_HANDLE_DISK_FULL: - case ERROR_DISK_FULL: - return ERROR_DISK_IS_FULL; - - case ERROR_SHARING_VIOLATION: - case ERROR_BUSY: - case ERROR_INVALID_HANDLE: - return ERROR_OBJECT_IN_USE; - - case ERROR_CURRENT_DIRECTORY: - return ERROR_DIRECTORY_NOT_EMPTY; - - case ERROR_NEGATIVE_SEEK: - case ERROR_SEEK_ON_DEVICE: - return ERROR_SEEK_ERROR; - - default: - { - gui_message (L"Unimplemented error %d\nContact author!", e); + DWORD e = GetLastError (); + + //write_log (L"ec=%d\n", e); + switch (e) { + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: + return ERROR_NO_FREE_STORE; + + case ERROR_FILE_EXISTS: + case ERROR_ALREADY_EXISTS: + return ERROR_OBJECT_EXISTS; + + case ERROR_WRITE_PROTECT: + case ERROR_ACCESS_DENIED: + return ERROR_WRITE_PROTECTED; + + case ERROR_FILE_NOT_FOUND: + case ERROR_INVALID_DRIVE: + case ERROR_INVALID_NAME: + case ERROR_PATH_NOT_FOUND: + case ERROR_NOT_READY: + case ERROR_BAD_UNIT: + return ERROR_OBJECT_NOT_AROUND; + + case ERROR_HANDLE_DISK_FULL: + case ERROR_DISK_FULL: + return ERROR_DISK_IS_FULL; + + case ERROR_SHARING_VIOLATION: + case ERROR_BUSY: + case ERROR_INVALID_HANDLE: + return ERROR_OBJECT_IN_USE; + + case ERROR_CURRENT_DIRECTORY: + return ERROR_DIRECTORY_NOT_EMPTY; + + case ERROR_NEGATIVE_SEEK: + case ERROR_SEEK_ON_DEVICE: + return ERROR_SEEK_ERROR; + + default: + { + gui_message (L"Unimplemented error %d\nContact author!", e); + } + return ERROR_NOT_IMPLEMENTED; } - return ERROR_NOT_IMPLEMENTED; - } } typedef BOOL (CALLBACK* GETVOLUMEPATHNAME) - (LPCTSTR lpszFileName, LPTSTR lpszVolumePathName, DWORD cchBufferLength); + (LPCTSTR lpszFileName, LPTSTR lpszVolumePathName, DWORD cchBufferLength); int my_getvolumeinfo (const TCHAR *root) { - DWORD v, err; - int ret = 0; - GETVOLUMEPATHNAME pGetVolumePathName; - TCHAR volume[MAX_DPATH]; - - v = GetFileAttributesSafe (root); - err = GetLastError (); - if (v == INVALID_FILE_ATTRIBUTES) - return -1; - if (!(v & FILE_ATTRIBUTE_DIRECTORY)) - return -1; -/* - if (v & FILE_ATTRIBUTE_READONLY) + DWORD v, err; + int ret = 0; + GETVOLUMEPATHNAME pGetVolumePathName; + TCHAR volume[MAX_DPATH]; + + v = GetFileAttributesSafe (root); + err = GetLastError (); + if (v == INVALID_FILE_ATTRIBUTES) + return -1; + if (!(v & FILE_ATTRIBUTE_DIRECTORY)) + return -1; + /* + if (v & FILE_ATTRIBUTE_READONLY) ret |= MYVOLUMEINFO_READONLY; -*/ - pGetVolumePathName = (GETVOLUMEPATHNAME)GetProcAddress( - GetModuleHandle (L"kernel32.dll"), "GetVolumePathNameW"); - if (pGetVolumePathName && pGetVolumePathName (root, volume, sizeof (volume))) { - TCHAR fsname[MAX_DPATH]; - DWORD comlen; - DWORD flags; - if (GetVolumeInformation (volume, NULL, 0, NULL, &comlen, &flags, fsname, sizeof (fsname))) { - write_log (L"Volume %s FS=%s maxlen=%d flags=%08X\n", volume, fsname, comlen, flags); - if (flags & FILE_NAMED_STREAMS) - ret |= MYVOLUMEINFO_STREAMS; + */ + pGetVolumePathName = (GETVOLUMEPATHNAME)GetProcAddress( + GetModuleHandle (L"kernel32.dll"), "GetVolumePathNameW"); + if (pGetVolumePathName && pGetVolumePathName (root, volume, sizeof (volume))) { + TCHAR fsname[MAX_DPATH]; + DWORD comlen; + DWORD flags; + if (GetVolumeInformation (volume, NULL, 0, NULL, &comlen, &flags, fsname, sizeof (fsname))) { + write_log (L"Volume %s FS=%s maxlen=%d flags=%08X\n", volume, fsname, comlen, flags); + if (flags & FILE_NAMED_STREAMS) + ret |= MYVOLUMEINFO_STREAMS; + } } - } - return ret; + return ret; } FILE *my_opentext (const TCHAR *name) { - FILE *f; - uae_u8 tmp[4]; - int v; - - f = _tfopen (name, L"rb"); - if (!f) - return NULL; - v = fread (tmp, 1, 4, f); - fclose (f); - if (v == 4) { - if (tmp[0] == 0xef && tmp[1] == 0xbb && tmp[2] == 0xbf) - return _tfopen (name, L"r, ccs=UTF-8"); - if (tmp[0] == 0xff && tmp[1] == 0xfe) - return _tfopen (name, L"r, ccs=UTF-16LE"); - } - return _tfopen (name, L"r"); + FILE *f; + uae_u8 tmp[4]; + int v; + + f = _tfopen (name, L"rb"); + if (!f) + return NULL; + v = fread (tmp, 1, 4, f); + fclose (f); + if (v == 4) { + if (tmp[0] == 0xef && tmp[1] == 0xbb && tmp[2] == 0xbf) + return _tfopen (name, L"r, ccs=UTF-8"); + if (tmp[0] == 0xff && tmp[1] == 0xfe) + return _tfopen (name, L"r, ccs=UTF-16LE"); + } + return _tfopen (name, L"r"); } diff --git a/od-win32/fsdb_win32.c b/od-win32/fsdb_win32.c index e4ae2f4b..0e4795cf 100644 --- a/od-win32/fsdb_win32.c +++ b/od-win32/fsdb_win32.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Library of functions to make emulated filesystem as independent as - * possible of the host filesystem's capabilities. - * This is the Win32 version. - * - * Copyright 1997 Mathias Ortmann - * Copyright 1999 Bernd Schmidt - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Library of functions to make emulated filesystem as independent as +* possible of the host filesystem's capabilities. +* This is the Win32 version. +* +* Copyright 1997 Mathias Ortmann +* Copyright 1999 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -37,534 +37,534 @@ static TCHAR evilchars[NUM_EVILCHARS] = { '\\', '*', '?', '\"', '<', '>', '|' }; #define UAEFSDB2_LEN 1632 /* The on-disk format is as follows: - * Offset 0, 1 byte, valid - * Offset 1, 4 bytes, mode - * Offset 5, 257 bytes, aname - * Offset 262, 257 bytes, nname - * Offset 519, 81 bytes, comment - * Offset 600, 4 bytes, Windows-side mode - * - * 1.6.0+ Unicode data - * - * Offset 604, 257 * 2 bytes, aname - * Offset 1118, 257 * 2 bytes, nname - * 1632 - */ +* Offset 0, 1 byte, valid +* Offset 1, 4 bytes, mode +* Offset 5, 257 bytes, aname +* Offset 262, 257 bytes, nname +* Offset 519, 81 bytes, comment +* Offset 600, 4 bytes, Windows-side mode +* +* 1.6.0+ Unicode data +* +* Offset 604, 257 * 2 bytes, aname +* Offset 1118, 257 * 2 bytes, nname +* 1632 +*/ static TCHAR *make_uaefsdbpath (const TCHAR *dir, const TCHAR *name) { - int len; - TCHAR *p; - - len = _tcslen (dir) + 1 + 1; - if (name) - len += 1 + _tcslen (name); - len += 1 + _tcslen (FSDB_FILE); - p = xmalloc (len * sizeof (TCHAR)); - if (!p) - return NULL; - if (name) - _stprintf (p, L"%s\\%s:%s", dir, name, FSDB_FILE); - else - _stprintf (p, L"%s:%s", dir, FSDB_FILE); - return p; + int len; + TCHAR *p; + + len = _tcslen (dir) + 1 + 1; + if (name) + len += 1 + _tcslen (name); + len += 1 + _tcslen (FSDB_FILE); + p = xmalloc (len * sizeof (TCHAR)); + if (!p) + return NULL; + if (name) + _stprintf (p, L"%s\\%s:%s", dir, name, FSDB_FILE); + else + _stprintf (p, L"%s:%s", dir, FSDB_FILE); + return p; } static int read_uaefsdb (const TCHAR *dir, const TCHAR *name, uae_u8 *fsdb) { - TCHAR *p; - HANDLE h; - DWORD read; - - read = 0; - p = make_uaefsdbpath (dir, name); - h = CreateFile (p, GENERIC_READ, 0, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (fsdb_debug) - write_log (L"read_uaefsdb '%s' = %x\n", p, h); - xfree (p); - if (h != INVALID_HANDLE_VALUE) { + TCHAR *p; + HANDLE h; + DWORD read; + + read = 0; + p = make_uaefsdbpath (dir, name); + h = CreateFile (p, GENERIC_READ, 0, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (fsdb_debug) + write_log (L"read_uaefsdb '%s' = %x\n", p, h); + xfree (p); + if (h != INVALID_HANDLE_VALUE) { + memset (fsdb, 0, UAEFSDB2_LEN); + ReadFile (h, fsdb, UAEFSDB2_LEN, &read, NULL); + CloseHandle (h); + if (read == UAEFSDB_LEN || read == UAEFSDB2_LEN) { + if (fsdb_debug) { + TCHAR *an, *nn, *co; + write_log (L"->ok\n"); + an = aucp (fsdb + 5, currprefs.win32_fscodepage); + nn = aucp (fsdb + 262, currprefs.win32_fscodepage); + co = aucp (fsdb + 519, currprefs.win32_fscodepage); + write_log (L"v=%02x flags=%08x an='%s' nn='%s' c='%s'\n", + fsdb[0], ((uae_u32*)(fsdb+1))[0], an, nn, co); + xfree (co); + xfree (nn); + xfree (an); + } + return 1; + } + } + if (fsdb_debug) + write_log (L"->fail %d, %d\n", read, GetLastError ()); memset (fsdb, 0, UAEFSDB2_LEN); - ReadFile (h, fsdb, UAEFSDB2_LEN, &read, NULL); - CloseHandle (h); - if (read == UAEFSDB_LEN || read == UAEFSDB2_LEN) { - if (fsdb_debug) { + return 0; +} + +static int delete_uaefsdb (const TCHAR *dir) +{ + TCHAR *p; + int ret; + + p = make_uaefsdbpath (dir, NULL); + ret = DeleteFile (p); + if (fsdb_debug) + write_log (L"delete_uaefsdb '%s' = %d\n", p, ret); + xfree (p); + return ret; +} + +static int write_uaefsdb (const TCHAR *dir, uae_u8 *fsdb) +{ + TCHAR *p; + HANDLE h; + DWORD written = 0, dirflag, dirattr; + DWORD attr = INVALID_FILE_ATTRIBUTES; + FILETIME t1, t2, t3; + int time_valid = FALSE; + int ret = 0; + + p = make_uaefsdbpath (dir, NULL); + dirattr = GetFileAttributes (dir); + dirflag = FILE_ATTRIBUTE_NORMAL; + if (dirattr != INVALID_FILE_ATTRIBUTES && (dirattr & FILE_ATTRIBUTE_DIRECTORY)) + dirflag = FILE_FLAG_BACKUP_SEMANTICS; /* argh... */ + h = CreateFile (dir, GENERIC_READ, 0, + NULL, OPEN_EXISTING, dirflag, NULL); + if (h != INVALID_HANDLE_VALUE) { + if (GetFileTime (h, &t1, &t2, &t3)) + time_valid = TRUE; + CloseHandle (h); + } + h = CreateFile (p, GENERIC_WRITE, 0, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (fsdb_debug) { TCHAR *an, *nn, *co; - write_log (L"->ok\n"); an = aucp (fsdb + 5, currprefs.win32_fscodepage); nn = aucp (fsdb + 262, currprefs.win32_fscodepage); co = aucp (fsdb + 519, currprefs.win32_fscodepage); + write_log (L"write_uaefsdb '%s' = %x\n", p, h); write_log (L"v=%02x flags=%08x an='%s' nn='%s' c='%s'\n", - fsdb[0], ((uae_u32*)(fsdb+1))[0], an, nn, co); + fsdb[0], ((uae_u32*)(fsdb+1))[0], an, nn, co); xfree (co); xfree (nn); xfree (an); - } - return 1; } - } - if (fsdb_debug) - write_log (L"->fail %d, %d\n", read, GetLastError ()); - memset (fsdb, 0, UAEFSDB2_LEN); - return 0; -} - -static int delete_uaefsdb (const TCHAR *dir) -{ - TCHAR *p; - int ret; - - p = make_uaefsdbpath (dir, NULL); - ret = DeleteFile (p); - if (fsdb_debug) - write_log (L"delete_uaefsdb '%s' = %d\n", p, ret); - xfree (p); - return ret; -} - -static int write_uaefsdb (const TCHAR *dir, uae_u8 *fsdb) -{ - TCHAR *p; - HANDLE h; - DWORD written = 0, dirflag, dirattr; - DWORD attr = INVALID_FILE_ATTRIBUTES; - FILETIME t1, t2, t3; - int time_valid = FALSE; - int ret = 0; - - p = make_uaefsdbpath (dir, NULL); - dirattr = GetFileAttributes (dir); - dirflag = FILE_ATTRIBUTE_NORMAL; - if (dirattr != INVALID_FILE_ATTRIBUTES && (dirattr & FILE_ATTRIBUTE_DIRECTORY)) - dirflag = FILE_FLAG_BACKUP_SEMANTICS; /* argh... */ - h = CreateFile (dir, GENERIC_READ, 0, - NULL, OPEN_EXISTING, dirflag, NULL); - if (h != INVALID_HANDLE_VALUE) { - if (GetFileTime (h, &t1, &t2, &t3)) - time_valid = TRUE; - CloseHandle (h); - } - h = CreateFile (p, GENERIC_WRITE, 0, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (fsdb_debug) { - TCHAR *an, *nn, *co; - an = aucp (fsdb + 5, currprefs.win32_fscodepage); - nn = aucp (fsdb + 262, currprefs.win32_fscodepage); - co = aucp (fsdb + 519, currprefs.win32_fscodepage); - write_log (L"write_uaefsdb '%s' = %x\n", p, h); - write_log (L"v=%02x flags=%08x an='%s' nn='%s' c='%s'\n", - fsdb[0], ((uae_u32*)(fsdb+1))[0], an, nn, co); - xfree (co); - xfree (nn); - xfree (an); - } - if (h == INVALID_HANDLE_VALUE && GetLastError () == ERROR_ACCESS_DENIED) { - attr = GetFileAttributes (p); - if (attr != INVALID_FILE_ATTRIBUTES) { - if (attr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)) { - SetFileAttributes (p, attr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)); - h = CreateFile (p, GENERIC_WRITE, 0, - NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (fsdb_debug) - write_log (L"write_uaefsdb (2) '%s' = %x\n", p, h); - } + if (h == INVALID_HANDLE_VALUE && GetLastError () == ERROR_ACCESS_DENIED) { + attr = GetFileAttributes (p); + if (attr != INVALID_FILE_ATTRIBUTES) { + if (attr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)) { + SetFileAttributes (p, attr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)); + h = CreateFile (p, GENERIC_WRITE, 0, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (fsdb_debug) + write_log (L"write_uaefsdb (2) '%s' = %x\n", p, h); + } + } } - } - if (h != INVALID_HANDLE_VALUE) { - WriteFile (h, fsdb, UAEFSDB2_LEN, &written, NULL); - CloseHandle (h); - if (written == UAEFSDB2_LEN) { - if (fsdb_debug) - write_log (L"->ok\n"); - ret = 1; - goto end; + if (h != INVALID_HANDLE_VALUE) { + WriteFile (h, fsdb, UAEFSDB2_LEN, &written, NULL); + CloseHandle (h); + if (written == UAEFSDB2_LEN) { + if (fsdb_debug) + write_log (L"->ok\n"); + ret = 1; + goto end; + } } - } - if (fsdb_debug) - write_log (L"->fail %d, %d\n", written, GetLastError ()); + if (fsdb_debug) + write_log (L"->fail %d, %d\n", written, GetLastError ()); - DeleteFile (p); + DeleteFile (p); end: - if (attr != INVALID_FILE_ATTRIBUTES) - SetFileAttributes (p, attr); - if (time_valid) { - h = CreateFile (dir, GENERIC_WRITE, 0, - NULL, OPEN_EXISTING, dirflag, NULL); - if (h != INVALID_HANDLE_VALUE) { - SetFileTime (h, &t1, &t2, &t3); - CloseHandle (h); + if (attr != INVALID_FILE_ATTRIBUTES) + SetFileAttributes (p, attr); + if (time_valid) { + h = CreateFile (dir, GENERIC_WRITE, 0, + NULL, OPEN_EXISTING, dirflag, NULL); + if (h != INVALID_HANDLE_VALUE) { + SetFileTime (h, &t1, &t2, &t3); + CloseHandle (h); + } } - } - xfree (p); - return ret; + xfree (p); + return ret; } static void create_uaefsdb (a_inode *aino, uae_u8 *buf, int winmode) { - TCHAR *nn; - char *s; - buf[0] = 1; - do_put_mem_long ((uae_u32 *)(buf + 1), aino->amigaos_mode); - s = uacp (aino->aname, currprefs.win32_fscodepage); - strncpy (buf + 5, s, 256); - buf[5 + 256] = '\0'; - xfree (s); - nn = nname_begin (aino->nname); - s = uacp (nn, currprefs.win32_fscodepage); - strncpy (buf + 5 + 257, s, 256); - buf[5 + 257 + 256] = '\0'; - xfree (s); - s = uacp (aino->comment ? aino->comment : L"", currprefs.win32_fscodepage); - strncpy (buf + 5 + 2 * 257, s, 80); - buf[5 + 2 * 257 + 80] = '\0'; - xfree (s); - do_put_mem_long ((uae_u32 *)(buf + 5 + 2 * 257 + 81), winmode); - _tcsncpy ((TCHAR*)(buf + 604), aino->aname, 256); - _tcsncpy ((TCHAR*)(buf + 1118), nn, 256); - aino->has_dbentry = 0; + TCHAR *nn; + char *s; + buf[0] = 1; + do_put_mem_long ((uae_u32 *)(buf + 1), aino->amigaos_mode); + s = uacp (aino->aname, currprefs.win32_fscodepage); + strncpy (buf + 5, s, 256); + buf[5 + 256] = '\0'; + xfree (s); + nn = nname_begin (aino->nname); + s = uacp (nn, currprefs.win32_fscodepage); + strncpy (buf + 5 + 257, s, 256); + buf[5 + 257 + 256] = '\0'; + xfree (s); + s = uacp (aino->comment ? aino->comment : L"", currprefs.win32_fscodepage); + strncpy (buf + 5 + 2 * 257, s, 80); + buf[5 + 2 * 257 + 80] = '\0'; + xfree (s); + do_put_mem_long ((uae_u32 *)(buf + 5 + 2 * 257 + 81), winmode); + _tcsncpy ((TCHAR*)(buf + 604), aino->aname, 256); + _tcsncpy ((TCHAR*)(buf + 1118), nn, 256); + aino->has_dbentry = 0; } static a_inode *aino_from_buf (a_inode *base, uae_u8 *buf, int *winmode) { - uae_u32 mode; - a_inode *aino = xcalloc (sizeof (a_inode), 1); - uae_u8 *buf2; - TCHAR *s; - - buf2 = buf + 604; - mode = do_get_mem_long ((uae_u32 *)(buf + 1)); - buf += 5; - if (buf2[0]) { - aino->aname = my_strdup ((TCHAR*)buf2); - } else { - aino->aname = aucp (buf, currprefs.win32_fscodepage); - } - buf += 257; - buf2 += 257 * 2; - if (buf2[0]) { - aino->nname = build_nname (base->nname, (TCHAR*)buf2); - } else { - s = aucp (buf, currprefs.win32_fscodepage); - aino->nname = build_nname (base->nname, s); - xfree (s); - } - buf += 257; - aino->comment = *buf != '\0' ? my_strdup_ansi (buf) : 0; - buf += 81; - aino->amigaos_mode = mode; - *winmode = do_get_mem_long ((uae_u32 *)buf); - aino->dir = ((*winmode) & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; - *winmode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; - aino->has_dbentry = 0; - aino->dirty = 0; - aino->db_offset = 0; - if((mode = GetFileAttributes (aino->nname)) == INVALID_FILE_ATTRIBUTES) { - write_log (L"xGetFileAttributes('%s') failed! error=%d, aino=%p\n", - aino->nname, GetLastError (), aino); + uae_u32 mode; + a_inode *aino = xcalloc (sizeof (a_inode), 1); + uae_u8 *buf2; + TCHAR *s; + + buf2 = buf + 604; + mode = do_get_mem_long ((uae_u32 *)(buf + 1)); + buf += 5; + if (buf2[0]) { + aino->aname = my_strdup ((TCHAR*)buf2); + } else { + aino->aname = aucp (buf, currprefs.win32_fscodepage); + } + buf += 257; + buf2 += 257 * 2; + if (buf2[0]) { + aino->nname = build_nname (base->nname, (TCHAR*)buf2); + } else { + s = aucp (buf, currprefs.win32_fscodepage); + aino->nname = build_nname (base->nname, s); + xfree (s); + } + buf += 257; + aino->comment = *buf != '\0' ? my_strdup_ansi (buf) : 0; + buf += 81; + aino->amigaos_mode = mode; + *winmode = do_get_mem_long ((uae_u32 *)buf); + aino->dir = ((*winmode) & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; + *winmode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; + aino->has_dbentry = 0; + aino->dirty = 0; + aino->db_offset = 0; + if((mode = GetFileAttributes (aino->nname)) == INVALID_FILE_ATTRIBUTES) { + write_log (L"xGetFileAttributes('%s') failed! error=%d, aino=%p\n", + aino->nname, GetLastError (), aino); + return aino; + } + aino->dir = (mode & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; return aino; - } - aino->dir = (mode & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; - return aino; } /* Return nonzero for any name we can't create on the native filesystem. */ int fsdb_name_invalid (const TCHAR *n) { - int i; - TCHAR a = n[0]; - TCHAR b = (a == '\0' ? a : n[1]); - TCHAR c = (b == '\0' ? b : n[2]); - TCHAR d = (c == '\0' ? c : n[3]); - int l = _tcslen (n), ll; - - if (a >= 'a' && a <= 'z') - a -= 32; - if (b >= 'a' && b <= 'z') - b -= 32; - if (c >= 'a' && c <= 'z') - c -= 32; - - /* reserved dos devices */ - ll = 0; - if (a == 'A' && b == 'U' && c == 'X') ll = 3; /* AUX */ - if (a == 'C' && b == 'O' && c == 'N') ll = 3; /* CON */ - if (a == 'P' && b == 'R' && c == 'N') ll = 3; /* PRN */ - if (a == 'N' && b == 'U' && c == 'L') ll = 3; /* NUL */ - if (a == 'L' && b == 'P' && c == 'T' && (d >= '0' && d <= '9')) ll = 4; /* LPT# */ - if (a == 'C' && b == 'O' && c == 'M' && (d >= '0' && d <= '9')) ll = 4; /* COM# */ - /* AUX.anything, CON.anything etc.. are also illegal names */ - if (ll && (l == ll || (l > ll && n[ll] == '.'))) - return 1; - - /* spaces and periods at the end are a no-no */ - i = l - 1; - if (n[i] == '.' || n[i] == ' ') - return 1; - - /* these characters are *never* allowed */ - for (i = 0; i < NUM_EVILCHARS; i++) { - if (_tcschr (n, evilchars[i]) != 0) - return 1; - } + int i; + TCHAR a = n[0]; + TCHAR b = (a == '\0' ? a : n[1]); + TCHAR c = (b == '\0' ? b : n[2]); + TCHAR d = (c == '\0' ? c : n[3]); + int l = _tcslen (n), ll; + + if (a >= 'a' && a <= 'z') + a -= 32; + if (b >= 'a' && b <= 'z') + b -= 32; + if (c >= 'a' && c <= 'z') + c -= 32; + + /* reserved dos devices */ + ll = 0; + if (a == 'A' && b == 'U' && c == 'X') ll = 3; /* AUX */ + if (a == 'C' && b == 'O' && c == 'N') ll = 3; /* CON */ + if (a == 'P' && b == 'R' && c == 'N') ll = 3; /* PRN */ + if (a == 'N' && b == 'U' && c == 'L') ll = 3; /* NUL */ + if (a == 'L' && b == 'P' && c == 'T' && (d >= '0' && d <= '9')) ll = 4; /* LPT# */ + if (a == 'C' && b == 'O' && c == 'M' && (d >= '0' && d <= '9')) ll = 4; /* COM# */ + /* AUX.anything, CON.anything etc.. are also illegal names */ + if (ll && (l == ll || (l > ll && n[ll] == '.'))) + return 1; + + /* spaces and periods at the end are a no-no */ + i = l - 1; + if (n[i] == '.' || n[i] == ' ') + return 1; + + /* these characters are *never* allowed */ + for (i = 0; i < NUM_EVILCHARS; i++) { + if (_tcschr (n, evilchars[i]) != 0) + return 1; + } - /* the reserved fsdb filename */ - if (_tcscmp (n, FSDB_FILE) == 0) - return 1; - return 0; /* the filename passed all checks, now it should be ok */ + /* the reserved fsdb filename */ + if (_tcscmp (n, FSDB_FILE) == 0) + return 1; + return 0; /* the filename passed all checks, now it should be ok */ } uae_u32 filesys_parse_mask(uae_u32 mask) { - return mask ^ 0xf; + return mask ^ 0xf; } int fsdb_exists (TCHAR *nname) { - if (GetFileAttributes(nname) == INVALID_FILE_ATTRIBUTES) - return 0; - return 1; + if (GetFileAttributes(nname) == INVALID_FILE_ATTRIBUTES) + return 0; + return 1; } /* For an a_inode we have newly created based on a filename we found on the - * native fs, fill in information about this file/directory. */ +* native fs, fill in information about this file/directory. */ int fsdb_fill_file_attrs (a_inode *base, a_inode *aino) { - int mode, winmode, oldamode; - uae_u8 fsdb[UAEFSDB2_LEN]; - int reset = 0; + int mode, winmode, oldamode; + uae_u8 fsdb[UAEFSDB2_LEN]; + int reset = 0; + + if((mode = GetFileAttributes(aino->nname)) == INVALID_FILE_ATTRIBUTES) { + write_log (L"GetFileAttributes('%s') failed! error=%d, aino=%p dir=%d\n", + aino->nname, GetLastError(), aino, aino->dir); + return 0; + } + aino->dir = (mode & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; + mode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; + + if ((base->volflags & MYVOLUMEINFO_STREAMS) && read_uaefsdb (aino->nname, NULL, fsdb)) { + aino->amigaos_mode = do_get_mem_long ((uae_u32 *)(fsdb + 1)); + xfree (aino->comment); + aino->comment = NULL; + if (fsdb[5 + 2 * 257]) + aino->comment = my_strdup_ansi (fsdb + 5 + 2 * 257); + xfree (aino_from_buf (base, fsdb, &winmode)); + if (winmode == mode) /* no Windows-side editing? */ + return 1; + write_log (L"FS: '%s' protection flags edited from Windows-side\n", aino->nname); + reset = 1; + /* edited from Windows-side -> use Windows side flags instead */ + } - if((mode = GetFileAttributes(aino->nname)) == INVALID_FILE_ATTRIBUTES) { - write_log (L"GetFileAttributes('%s') failed! error=%d, aino=%p dir=%d\n", - aino->nname, GetLastError(), aino, aino->dir); - return 0; - } - aino->dir = (mode & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; - mode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; - - if ((base->volflags & MYVOLUMEINFO_STREAMS) && read_uaefsdb (aino->nname, NULL, fsdb)) { - aino->amigaos_mode = do_get_mem_long ((uae_u32 *)(fsdb + 1)); - xfree (aino->comment); - aino->comment = NULL; - if (fsdb[5 + 2 * 257]) - aino->comment = my_strdup_ansi (fsdb + 5 + 2 * 257); - xfree (aino_from_buf (base, fsdb, &winmode)); - if (winmode == mode) /* no Windows-side editing? */ - return 1; - write_log (L"FS: '%s' protection flags edited from Windows-side\n", aino->nname); - reset = 1; - /* edited from Windows-side -> use Windows side flags instead */ - } - - oldamode = aino->amigaos_mode; - aino->amigaos_mode = A_FIBF_EXECUTE | A_FIBF_READ; - if (!(FILE_ATTRIBUTE_ARCHIVE & mode)) - aino->amigaos_mode |= A_FIBF_ARCHIVE; - if (!(FILE_ATTRIBUTE_READONLY & mode)) - aino->amigaos_mode |= A_FIBF_WRITE | A_FIBF_DELETE; - if (FILE_ATTRIBUTE_SYSTEM & mode) - aino->amigaos_mode |= A_FIBF_PURE; - if (FILE_ATTRIBUTE_HIDDEN & mode) - aino->amigaos_mode |= A_FIBF_HIDDEN; - aino->amigaos_mode = filesys_parse_mask(aino->amigaos_mode); - aino->amigaos_mode |= oldamode & A_FIBF_SCRIPT; - if (reset && (base->volflags & MYVOLUMEINFO_STREAMS)) { - create_uaefsdb (aino, fsdb, mode); - write_uaefsdb (aino->nname, fsdb); - } - return 1; + oldamode = aino->amigaos_mode; + aino->amigaos_mode = A_FIBF_EXECUTE | A_FIBF_READ; + if (!(FILE_ATTRIBUTE_ARCHIVE & mode)) + aino->amigaos_mode |= A_FIBF_ARCHIVE; + if (!(FILE_ATTRIBUTE_READONLY & mode)) + aino->amigaos_mode |= A_FIBF_WRITE | A_FIBF_DELETE; + if (FILE_ATTRIBUTE_SYSTEM & mode) + aino->amigaos_mode |= A_FIBF_PURE; + if (FILE_ATTRIBUTE_HIDDEN & mode) + aino->amigaos_mode |= A_FIBF_HIDDEN; + aino->amigaos_mode = filesys_parse_mask(aino->amigaos_mode); + aino->amigaos_mode |= oldamode & A_FIBF_SCRIPT; + if (reset && (base->volflags & MYVOLUMEINFO_STREAMS)) { + create_uaefsdb (aino, fsdb, mode); + write_uaefsdb (aino->nname, fsdb); + } + return 1; } static int needs_fsdb (a_inode *aino) { - const TCHAR *nn_begin; + const TCHAR *nn_begin; - if (aino->deleted) - return 0; + if (aino->deleted) + return 0; - if (!fsdb_mode_representable_p (aino, aino->amigaos_mode) || aino->comment != 0) - return 1; + if (!fsdb_mode_representable_p (aino, aino->amigaos_mode) || aino->comment != 0) + return 1; - nn_begin = nname_begin (aino->nname); - return _tcscmp (nn_begin, aino->aname) != 0; + nn_begin = nname_begin (aino->nname); + return _tcscmp (nn_begin, aino->aname) != 0; } int fsdb_set_file_attrs (a_inode *aino) { - uae_u32 tmpmask; - uae_u8 fsdb[UAEFSDB2_LEN]; - uae_u32 mode; - - tmpmask = filesys_parse_mask (aino->amigaos_mode); - - mode = GetFileAttributes (aino->nname); - if (mode == INVALID_FILE_ATTRIBUTES) - return ERROR_OBJECT_NOT_AROUND; - mode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; - - mode = 0; - if ((tmpmask & (A_FIBF_WRITE | A_FIBF_DELETE)) == 0) - mode |= FILE_ATTRIBUTE_READONLY; - if (!(tmpmask & A_FIBF_ARCHIVE)) - mode |= FILE_ATTRIBUTE_ARCHIVE; - if (tmpmask & A_FIBF_PURE) - mode |= FILE_ATTRIBUTE_SYSTEM; - if (tmpmask & A_FIBF_HIDDEN) - mode |= FILE_ATTRIBUTE_HIDDEN; - SetFileAttributes (aino->nname, mode); - - aino->dirty = 1; - if (aino->volflags & MYVOLUMEINFO_STREAMS) { - if (needs_fsdb (aino)) { - create_uaefsdb (aino, fsdb, mode); - write_uaefsdb (aino->nname, fsdb); - } else { - delete_uaefsdb (aino->nname); + uae_u32 tmpmask; + uae_u8 fsdb[UAEFSDB2_LEN]; + uae_u32 mode; + + tmpmask = filesys_parse_mask (aino->amigaos_mode); + + mode = GetFileAttributes (aino->nname); + if (mode == INVALID_FILE_ATTRIBUTES) + return ERROR_OBJECT_NOT_AROUND; + mode &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; + + mode = 0; + if ((tmpmask & (A_FIBF_WRITE | A_FIBF_DELETE)) == 0) + mode |= FILE_ATTRIBUTE_READONLY; + if (!(tmpmask & A_FIBF_ARCHIVE)) + mode |= FILE_ATTRIBUTE_ARCHIVE; + if (tmpmask & A_FIBF_PURE) + mode |= FILE_ATTRIBUTE_SYSTEM; + if (tmpmask & A_FIBF_HIDDEN) + mode |= FILE_ATTRIBUTE_HIDDEN; + SetFileAttributes (aino->nname, mode); + + aino->dirty = 1; + if (aino->volflags & MYVOLUMEINFO_STREAMS) { + if (needs_fsdb (aino)) { + create_uaefsdb (aino, fsdb, mode); + write_uaefsdb (aino->nname, fsdb); + } else { + delete_uaefsdb (aino->nname); + } } - } - return 0; + return 0; } /* return supported combination */ int fsdb_mode_supported (const a_inode *aino) { - int mask = aino->amigaos_mode; - if (0 && aino->dir) + int mask = aino->amigaos_mode; + if (0 && aino->dir) + return 0; + if (fsdb_mode_representable_p (aino, mask)) + return mask; + mask &= ~(A_FIBF_SCRIPT | A_FIBF_READ | A_FIBF_EXECUTE); + if (fsdb_mode_representable_p (aino, mask)) + return mask; + mask &= ~A_FIBF_WRITE; + if (fsdb_mode_representable_p (aino, mask)) + return mask; + mask &= ~A_FIBF_DELETE; + if (fsdb_mode_representable_p (aino, mask)) + return mask; return 0; - if (fsdb_mode_representable_p (aino, mask)) - return mask; - mask &= ~(A_FIBF_SCRIPT | A_FIBF_READ | A_FIBF_EXECUTE); - if (fsdb_mode_representable_p (aino, mask)) - return mask; - mask &= ~A_FIBF_WRITE; - if (fsdb_mode_representable_p (aino, mask)) - return mask; - mask &= ~A_FIBF_DELETE; - if (fsdb_mode_representable_p (aino, mask)) - return mask; - return 0; } /* Return nonzero if we can represent the amigaos_mode of AINO within the - * native FS. Return zero if that is not possible. */ +* native FS. Return zero if that is not possible. */ int fsdb_mode_representable_p (const a_inode *aino, int amigaos_mode) { - int mask = amigaos_mode ^ 15; - - if (0 && aino->dir) - return amigaos_mode == 0; - - if (mask & A_FIBF_SCRIPT) /* script */ - return 0; - if ((mask & 15) == 15) /* xxxxRWED == OK */ - return 1; - if (!(mask & A_FIBF_EXECUTE)) /* not executable */ - return 0; - if (!(mask & A_FIBF_READ)) /* not readable */ + int mask = amigaos_mode ^ 15; + + if (0 && aino->dir) + return amigaos_mode == 0; + + if (mask & A_FIBF_SCRIPT) /* script */ + return 0; + if ((mask & 15) == 15) /* xxxxRWED == OK */ + return 1; + if (!(mask & A_FIBF_EXECUTE)) /* not executable */ + return 0; + if (!(mask & A_FIBF_READ)) /* not readable */ + return 0; + if ((mask & 15) == (A_FIBF_READ | A_FIBF_EXECUTE)) /* ----RxEx == ReadOnly */ + return 1; return 0; - if ((mask & 15) == (A_FIBF_READ | A_FIBF_EXECUTE)) /* ----RxEx == ReadOnly */ - return 1; - return 0; } TCHAR *fsdb_create_unique_nname (a_inode *base, const TCHAR *suggestion) { - TCHAR *c; - TCHAR tmp[256] = UAEFSDB_BEGINS; - int i; - - _tcsncat (tmp, suggestion, 240); - - /* replace the evil ones... */ - for (i = 0; i < NUM_EVILCHARS; i++) - while ((c = _tcschr (tmp, evilchars[i])) != 0) - *c = '_'; - - while ((c = _tcschr (tmp, '.')) != 0) - *c = '_'; - while ((c = _tcschr (tmp, ' ')) != 0) - *c = '_'; - - for (;;) { - TCHAR *p = build_nname (base->nname, tmp); - if (!fsdb_exists (p)) { - write_log (L"unique name: %s\n", p); - return p; - } - xfree (p); - /* tmpnam isn't reentrant and I don't really want to hack configure - * right now to see whether tmpnam_r is available... */ - for (i = 0; i < 8; i++) { - tmp[i+8] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[rand () % 63]; + TCHAR *c; + TCHAR tmp[256] = UAEFSDB_BEGINS; + int i; + + _tcsncat (tmp, suggestion, 240); + + /* replace the evil ones... */ + for (i = 0; i < NUM_EVILCHARS; i++) + while ((c = _tcschr (tmp, evilchars[i])) != 0) + *c = '_'; + + while ((c = _tcschr (tmp, '.')) != 0) + *c = '_'; + while ((c = _tcschr (tmp, ' ')) != 0) + *c = '_'; + + for (;;) { + TCHAR *p = build_nname (base->nname, tmp); + if (!fsdb_exists (p)) { + write_log (L"unique name: %s\n", p); + return p; + } + xfree (p); + /* tmpnam isn't reentrant and I don't really want to hack configure + * right now to see whether tmpnam_r is available... */ + for (i = 0; i < 8; i++) { + tmp[i+8] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[rand () % 63]; + } } - } } TCHAR *fsdb_search_dir (const TCHAR *dirname, TCHAR *rel) { - WIN32_FIND_DATA fd; - HANDLE h; - TCHAR *tmp, *p = 0; - - tmp = build_nname (dirname, rel); - h = FindFirstFile (tmp, &fd); - if (h != INVALID_HANDLE_VALUE) { - if (_tcscmp (fd.cFileName, rel) == 0) - p = rel; - else - p = my_strdup (fd.cFileName); - FindClose (h); - } - xfree (tmp); - return p; + WIN32_FIND_DATA fd; + HANDLE h; + TCHAR *tmp, *p = 0; + + tmp = build_nname (dirname, rel); + h = FindFirstFile (tmp, &fd); + if (h != INVALID_HANDLE_VALUE) { + if (_tcscmp (fd.cFileName, rel) == 0) + p = rel; + else + p = my_strdup (fd.cFileName); + FindClose (h); + } + xfree (tmp); + return p; } static a_inode *custom_fsdb_lookup_aino (a_inode *base, const TCHAR *aname, int offset, int dontcreate) { - uae_u8 fsdb[UAEFSDB2_LEN]; - TCHAR *tmp1; - HANDLE h; - WIN32_FIND_DATA fd; - static a_inode dummy; - - tmp1 = build_nname (base->nname, UAEFSDB_BEGINSX); - if (!tmp1) + uae_u8 fsdb[UAEFSDB2_LEN]; + TCHAR *tmp1; + HANDLE h; + WIN32_FIND_DATA fd; + static a_inode dummy; + + tmp1 = build_nname (base->nname, UAEFSDB_BEGINSX); + if (!tmp1) + return NULL; + h = FindFirstFile (tmp1, &fd); + if (h != INVALID_HANDLE_VALUE) { + do { + if (read_uaefsdb (base->nname, fd.cFileName, fsdb)) { + TCHAR *s = au (fsdb + offset); + if (same_aname (s, aname)) { + int winmode; + FindClose (h); + xfree (tmp1); + xfree (s); + if (dontcreate) + return &dummy; + return aino_from_buf (base, fsdb, &winmode); + } + xfree (s); + } + } while (FindNextFile (h, &fd)); + FindClose (h); + } + xfree (tmp1); return NULL; - h = FindFirstFile (tmp1, &fd); - if (h != INVALID_HANDLE_VALUE) { - do { - if (read_uaefsdb (base->nname, fd.cFileName, fsdb)) { - TCHAR *s = au (fsdb + offset); - if (same_aname (s, aname)) { - int winmode; - FindClose (h); - xfree (tmp1); - xfree (s); - if (dontcreate) - return &dummy; - return aino_from_buf (base, fsdb, &winmode); - } - xfree (s); - } - } while (FindNextFile (h, &fd)); - FindClose (h); - } - xfree (tmp1); - return NULL; } a_inode *custom_fsdb_lookup_aino_aname (a_inode *base, const TCHAR *aname) { - return custom_fsdb_lookup_aino (base, aname, 5, 0); + return custom_fsdb_lookup_aino (base, aname, 5, 0); } a_inode *custom_fsdb_lookup_aino_nname (a_inode *base, const TCHAR *nname) { - return custom_fsdb_lookup_aino (base, nname, 5 + 257, 0); + return custom_fsdb_lookup_aino (base, nname, 5 + 257, 0); } int custom_fsdb_used_as_nname (a_inode *base, const TCHAR *nname) { - if (custom_fsdb_lookup_aino (base, nname, 5 + 257, 1)) - return 1; - return 0; + if (custom_fsdb_lookup_aino (base, nname, 5 + 257, 1)) + return 1; + return 0; } diff --git a/od-win32/genblitter_msvc/genblitter_msvc.vcxproj b/od-win32/genblitter_msvc/genblitter_msvc.vcxproj index 647ca2e3..4451aee4 100644 --- a/od-win32/genblitter_msvc/genblitter_msvc.vcxproj +++ b/od-win32/genblitter_msvc/genblitter_msvc.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -19,62 +20,71 @@ genblitter - {765B0AF0-B8D3-4998-89AF-D6F939E1CD18} + {765B0AF0-B8D3-4998-89AF-D6F939E1CD18} - + Application false - Unicode + MultiByte - + Application false - Unicode + MultiByte - + Application false - MultiByte + Unicode - + Application false - MultiByte + Unicode - - + + + + + + + + + + + - <_ProjectFileVersion>10.0.20506.1 - - + <_ProjectFileVersion>10.0.21006.1 + .\Release\ .\Release\ - genblitter - .exe false - - + .\Debug\ .\Debug\ - genblitter - .exe true - - + $(Configuration)\ $(Configuration)\ - genblitter - .exe false - - + $(Configuration)\ $(Configuration)\ - genblitter - .exe false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + @@ -110,6 +120,7 @@ del ..\..\blittable.c /MACHINE:I386 %(AdditionalOptions) + genblitter.exe true .\Release/genblitter.pdb Console @@ -160,6 +171,7 @@ del ..\..\blittable.c /MACHINE:I386 %(AdditionalOptions) + genblitter.exe true true .\Debug/genblitter.pdb @@ -211,6 +223,7 @@ del ..\..\blittable.c /MACHINE:I386 %(AdditionalOptions) + genblitter.exe true .\Release/genblitter.pdb Console @@ -261,6 +274,7 @@ del ..\..\blittable.c /MACHINE:I386 %(AdditionalOptions) + genblitter.exe true .\Release/genblitter.pdb Console diff --git a/od-win32/genblitter_msvc/genblitter_msvc.vcxproj.filters b/od-win32/genblitter_msvc/genblitter_msvc.vcxproj.filters index 8789c571..29f0050e 100644 --- a/od-win32/genblitter_msvc/genblitter_msvc.vcxproj.filters +++ b/od-win32/genblitter_msvc/genblitter_msvc.vcxproj.filters @@ -2,7 +2,7 @@ - {4ac60c7e-24cc-4a5e-96b9-0495bbc92ee6} + {ec0cc585-13bf-4a0e-a027-9fe8f6ef15a4} cpp;c;cxx;rc;def;r;odl;idl;hpj;bat diff --git a/od-win32/gencomp_msvc/gencomp_msvc.vcxproj b/od-win32/gencomp_msvc/gencomp_msvc.vcxproj index a5dc8139..1b7c8c80 100644 --- a/od-win32/gencomp_msvc/gencomp_msvc.vcxproj +++ b/od-win32/gencomp_msvc/gencomp_msvc.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -19,63 +20,72 @@ gencomp - {54197DFF-9CAA-4A9F-B9C2-2881EA04EACB} + {54197DFF-9CAA-4A9F-B9C2-2881EA04EACB} - + Application false Unicode - + Application false - false - Unicode + MultiByte - + Application false - MultiByte + Unicode - + Application false + false Unicode - - + + + + + + + + + + + - <_ProjectFileVersion>10.0.20506.1 - - + <_ProjectFileVersion>10.0.21006.1 + .\Release\ .\Release\ - gencomp - .exe false - - + .\Debug\ .\Debug\ - gencomp - .exe true - - + $(Configuration)\ $(Configuration)\ - gencomp - .exe false - - + $(Configuration)\ $(Configuration)\ - gencomp - .exe false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + @@ -103,6 +113,7 @@ /MACHINE:I386 %(AdditionalOptions) + gencomp.exe true .\Release/gencomp.pdb Console @@ -145,6 +156,7 @@ od-win32\gencomp_msvc\gencomp.exe /MACHINE:I386 %(AdditionalOptions) + gencomp.exe true true .\Debug/gencomp.pdb @@ -186,6 +198,7 @@ od-win32\gencomp_msvc\gencomp.exe /MACHINE:I386 %(AdditionalOptions) + gencomp.exe true .\Release/gencomp.pdb Console @@ -226,6 +239,7 @@ od-win32\gencomp_msvc\gencomp.exe /MACHINE:I386 %(AdditionalOptions) + gencomp.exe true .\Release/gencomp.pdb Console diff --git a/od-win32/gencomp_msvc/gencomp_msvc.vcxproj.filters b/od-win32/gencomp_msvc/gencomp_msvc.vcxproj.filters index 01ff7454..0e4dc681 100644 --- a/od-win32/gencomp_msvc/gencomp_msvc.vcxproj.filters +++ b/od-win32/gencomp_msvc/gencomp_msvc.vcxproj.filters @@ -2,7 +2,7 @@ - {d5d3910b-2ecf-47a9-9de5-e584e3872e8f} + {9735a950-7202-4e6b-a989-fc2b5974ef43} cpp;c;cxx;rc;def;r;odl;idl;hpj;bat diff --git a/od-win32/gencpu_msvc/gencpu_msvc.vcxproj b/od-win32/gencpu_msvc/gencpu_msvc.vcxproj index 48b8fe7b..d0b1e2fd 100644 --- a/od-win32/gencpu_msvc/gencpu_msvc.vcxproj +++ b/od-win32/gencpu_msvc/gencpu_msvc.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -19,25 +20,25 @@ gencpu - {DEF7ACF7-050E-4069-BB99-5B5D93F60521} + {DEF7ACF7-050E-4069-BB99-5B5D93F60521} - + Application false Unicode - + Application false - Unicode + MultiByte - + Application false - MultiByte + Unicode - + Application false Unicode @@ -45,37 +46,46 @@ - - + + + + + + + + + + + - <_ProjectFileVersion>10.0.20506.1 - - + <_ProjectFileVersion>10.0.21006.1 + .\Debug\ .\Debug\ - gencpu - .exe true - - + .\Release\ .\Release\ - gencpu - .exe false false - - + $(Configuration)\ $(Configuration)\ - gencpu - .exe false - - + $(Configuration)\ $(Configuration)\ - gencpu - .exe false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + @@ -85,7 +95,7 @@ %(AdditionalOptions) Disabled ..\..\include;..\..;..\;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;__STDC__;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug @@ -110,6 +120,7 @@ /MACHINE:I386 %(AdditionalOptions) + gencpu.exe true true .\Debug/gencpu.pdb @@ -158,6 +169,7 @@ del ..\..\cpuemu.c /MACHINE:I386 %(AdditionalOptions) + gencpu.exe true .\Release/gencpu.pdb Console @@ -205,6 +217,7 @@ del ..\..\cpuemu.c /MACHINE:I386 %(AdditionalOptions) + gencpu.exe true .\Release/gencpu.pdb Console @@ -250,6 +263,7 @@ od-win32\gencpu_msvc\gencpu.exe /MACHINE:I386 %(AdditionalOptions) + gencpu.exe true .\Release/gencpu.pdb Console diff --git a/od-win32/gencpu_msvc/gencpu_msvc.vcxproj.filters b/od-win32/gencpu_msvc/gencpu_msvc.vcxproj.filters index 0f0dfbe2..16538dff 100644 --- a/od-win32/gencpu_msvc/gencpu_msvc.vcxproj.filters +++ b/od-win32/gencpu_msvc/gencpu_msvc.vcxproj.filters @@ -2,7 +2,7 @@ - {716280c1-4e3f-408c-966e-614a25731317} + {99e68131-2a40-4811-8a24-ee35d73a5526} cpp;c;cxx;rc;def;r;odl;idl;hpj;bat diff --git a/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcxproj b/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcxproj index d5f31ab8..f414ed14 100644 --- a/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcxproj +++ b/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -15,49 +16,58 @@ genlinetoscr - {E9F73E11-A463-45C6-A733-2BED75852BA1} + {E9F73E11-A463-45C6-A733-2BED75852BA1} genlinetoscr_msvc Win32Proj - + Application Unicode + true Application Unicode true - + Application Unicode - true - - + + + + + + + + - <_ProjectFileVersion>10.0.20506.1 + <_ProjectFileVersion>10.0.21006.1 $(SolutionDir)$(Configuration)\ $(Configuration)\ true - - + $(SolutionDir)$(Configuration)\ $(Configuration)\ - genlinetoscr - .exe false - - + $(SolutionDir)$(Configuration)\ $(Configuration)\ - genlinetoscr - .exe false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + @@ -98,6 +108,7 @@ del ..\..\linetoscr.c + genlinetoscr.exe true Console true @@ -130,6 +141,7 @@ del ..\..\linetoscr.c + genlinetoscr.exe true Console true diff --git a/od-win32/hardfile_win32.c b/od-win32/hardfile_win32.c index 7f172299..c5f69cb4 100644 --- a/od-win32/hardfile_win32.c +++ b/od-win32/hardfile_win32.c @@ -32,19 +32,19 @@ static int usefloppydrives = 0; struct uae_driveinfo { - TCHAR vendor_id[128]; - TCHAR product_id[128]; - TCHAR product_rev[128]; - TCHAR product_serial[128]; - TCHAR device_name[2048]; - TCHAR device_path[2048]; - uae_u64 size; - uae_u64 offset; - int bytespersector; - int removablemedia; - int nomedia; - int dangerous; - int readonly; + TCHAR vendor_id[128]; + TCHAR product_id[128]; + TCHAR product_rev[128]; + TCHAR product_serial[128]; + TCHAR device_name[2048]; + TCHAR device_path[2048]; + uae_u64 size; + uae_u64 offset; + int bytespersector; + int removablemedia; + int nomedia; + int dangerous; + int readonly; }; #define HDF_HANDLE_WIN32 1 @@ -54,242 +54,242 @@ struct uae_driveinfo { #define CACHE_FLUSH_TIME 5 /* safety check: only accept drives that: - * - contain RDSK in block 0 - * - block 0 is zeroed - */ +* - contain RDSK in block 0 +* - block 0 is zeroed +*/ int harddrive_dangerous, do_rdbdump; static struct uae_driveinfo uae_drives[MAX_FILESYSTEM_UNITS]; static int isnomediaerr (DWORD err) { - if (err == ERROR_NOT_READY || - err == ERROR_MEDIA_CHANGED || - err == ERROR_NO_MEDIA_IN_DRIVE || - err == ERROR_DEV_NOT_EXIST || - err == ERROR_BAD_NET_NAME || - err == ERROR_WRONG_DISK) - return 1; - return 0; + if (err == ERROR_NOT_READY || + err == ERROR_MEDIA_CHANGED || + err == ERROR_NO_MEDIA_IN_DRIVE || + err == ERROR_DEV_NOT_EXIST || + err == ERROR_BAD_NET_NAME || + err == ERROR_WRONG_DISK) + return 1; + return 0; } static void rdbdump (HANDLE *h, uae_u64 offset, uae_u8 *buf, int blocksize) { - static int cnt = 1; - int i, blocks; - TCHAR name[100]; - FILE *f; - - blocks = (buf[132] << 24) | (buf[133] << 16) | (buf[134] << 8) | (buf[135] << 0); - if (blocks < 0 || blocks > 100000) - return; - _stprintf (name, L"rdb_dump_%d.rdb", cnt); - f = _tfopen (name, L"wb"); - if (!f) - return; - for (i = 0; i <= blocks; i++) { - DWORD outlen, high; - high = (DWORD)(offset >> 32); - if (SetFilePointer (h, (DWORD)offset, &high, FILE_BEGIN) == INVALID_FILE_SIZE) - break; - ReadFile (h, buf, blocksize, &outlen, NULL); - fwrite (buf, 1, blocksize, f); - offset += blocksize; - } - fclose (f); - cnt++; + static int cnt = 1; + int i, blocks; + TCHAR name[100]; + FILE *f; + + blocks = (buf[132] << 24) | (buf[133] << 16) | (buf[134] << 8) | (buf[135] << 0); + if (blocks < 0 || blocks > 100000) + return; + _stprintf (name, L"rdb_dump_%d.rdb", cnt); + f = _tfopen (name, L"wb"); + if (!f) + return; + for (i = 0; i <= blocks; i++) { + DWORD outlen, high; + high = (DWORD)(offset >> 32); + if (SetFilePointer (h, (DWORD)offset, &high, FILE_BEGIN) == INVALID_FILE_SIZE) + break; + ReadFile (h, buf, blocksize, &outlen, NULL); + fwrite (buf, 1, blocksize, f); + offset += blocksize; + } + fclose (f); + cnt++; } static int getsignfromhandle (HANDLE h, DWORD *sign, DWORD *pstyle) { - int ok; - DWORD written, outsize; - DRIVE_LAYOUT_INFORMATION_EX *dli; - - ok = 0; - outsize = sizeof (DRIVE_LAYOUT_INFORMATION_EX) + sizeof (PARTITION_INFORMATION_EX) * 32; - dli = xmalloc (outsize); - if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, dli, outsize, &written, NULL)) { - *sign = dli->Mbr.Signature; - *pstyle = dli->PartitionStyle; - ok = 1; - } else if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, dli, outsize, &written, NULL)) { - DRIVE_LAYOUT_INFORMATION *dli2 = (DRIVE_LAYOUT_INFORMATION*)dli; - *sign = dli2->Signature; - *pstyle = PARTITION_STYLE_MBR; - ok = 1; - } - xfree (dli); - return ok; + int ok; + DWORD written, outsize; + DRIVE_LAYOUT_INFORMATION_EX *dli; + + ok = 0; + outsize = sizeof (DRIVE_LAYOUT_INFORMATION_EX) + sizeof (PARTITION_INFORMATION_EX) * 32; + dli = xmalloc (outsize); + if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, dli, outsize, &written, NULL)) { + *sign = dli->Mbr.Signature; + *pstyle = dli->PartitionStyle; + ok = 1; + } else if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, dli, outsize, &written, NULL)) { + DRIVE_LAYOUT_INFORMATION *dli2 = (DRIVE_LAYOUT_INFORMATION*)dli; + *sign = dli2->Signature; + *pstyle = PARTITION_STYLE_MBR; + ok = 1; + } + xfree (dli); + return ok; } static int ismounted (HANDLE hd) { - HANDLE h; - TCHAR volname[MAX_DPATH]; - int mounted; - DWORD sign, pstyle; - - if (!getsignfromhandle (hd, &sign, &pstyle)) - return 0; - if (pstyle == PARTITION_STYLE_GPT) - return 1; - if (pstyle == PARTITION_STYLE_RAW) - return 0; - mounted = 0; - h = FindFirstVolume (volname, sizeof volname / sizeof (TCHAR)); - while (h && !mounted) { - HANDLE d; - if (volname[_tcslen (volname) - 1] == '\\') - volname[_tcslen (volname) - 1] = 0; - d = CreateFile (volname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (d != INVALID_HANDLE_VALUE) { - DWORD isntfs, outsize, written; - isntfs = 0; - if (DeviceIoControl (d, FSCTL_IS_VOLUME_MOUNTED, NULL, 0, NULL, 0, &written, NULL)) { - VOLUME_DISK_EXTENTS *vde; - NTFS_VOLUME_DATA_BUFFER ntfs; - if (DeviceIoControl (d, FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0, &ntfs, sizeof ntfs, &written, NULL)) { - isntfs = 1; - } - outsize = sizeof (VOLUME_DISK_EXTENTS) + sizeof (DISK_EXTENT) * 32; - vde = xmalloc (outsize); - if (DeviceIoControl (d, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, vde, outsize, &written, NULL)) { - int i; - for (i = 0; i < vde->NumberOfDiskExtents; i++) { - TCHAR pdrv[MAX_DPATH]; - HANDLE ph; - _stprintf (pdrv, L"\\\\.\\PhysicalDrive%d", vde->Extents[i].DiskNumber); - ph = CreateFile (pdrv, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (ph != INVALID_HANDLE_VALUE) { - DWORD sign2; - if (getsignfromhandle (ph, &sign2, &pstyle)) { - if (sign == sign2 && pstyle == PARTITION_STYLE_MBR) - mounted = isntfs ? -1 : 1; - } - CloseHandle (ph); + HANDLE h; + TCHAR volname[MAX_DPATH]; + int mounted; + DWORD sign, pstyle; + + if (!getsignfromhandle (hd, &sign, &pstyle)) + return 0; + if (pstyle == PARTITION_STYLE_GPT) + return 1; + if (pstyle == PARTITION_STYLE_RAW) + return 0; + mounted = 0; + h = FindFirstVolume (volname, sizeof volname / sizeof (TCHAR)); + while (h && !mounted) { + HANDLE d; + if (volname[_tcslen (volname) - 1] == '\\') + volname[_tcslen (volname) - 1] = 0; + d = CreateFile (volname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (d != INVALID_HANDLE_VALUE) { + DWORD isntfs, outsize, written; + isntfs = 0; + if (DeviceIoControl (d, FSCTL_IS_VOLUME_MOUNTED, NULL, 0, NULL, 0, &written, NULL)) { + VOLUME_DISK_EXTENTS *vde; + NTFS_VOLUME_DATA_BUFFER ntfs; + if (DeviceIoControl (d, FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0, &ntfs, sizeof ntfs, &written, NULL)) { + isntfs = 1; + } + outsize = sizeof (VOLUME_DISK_EXTENTS) + sizeof (DISK_EXTENT) * 32; + vde = xmalloc (outsize); + if (DeviceIoControl (d, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, vde, outsize, &written, NULL)) { + int i; + for (i = 0; i < vde->NumberOfDiskExtents; i++) { + TCHAR pdrv[MAX_DPATH]; + HANDLE ph; + _stprintf (pdrv, L"\\\\.\\PhysicalDrive%d", vde->Extents[i].DiskNumber); + ph = CreateFile (pdrv, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (ph != INVALID_HANDLE_VALUE) { + DWORD sign2; + if (getsignfromhandle (ph, &sign2, &pstyle)) { + if (sign == sign2 && pstyle == PARTITION_STYLE_MBR) + mounted = isntfs ? -1 : 1; + } + CloseHandle (ph); + } + } + } } - } + CloseHandle (d); + } else { + write_log (L"'%s': %d\n", volname, GetLastError ()); } - } - CloseHandle (d); - } else { - write_log (L"'%s': %d\n", volname, GetLastError ()); + if (!FindNextVolume (h, volname, sizeof volname / sizeof (TCHAR))) + break; } - if (!FindNextVolume (h, volname, sizeof volname / sizeof (TCHAR))) - break; - } - FindVolumeClose (h); - return mounted; + FindVolumeClose (h); + return mounted; } #define CA "Commodore\0Amiga\0" static int safetycheck (HANDLE *h, const TCHAR *name, uae_u64 offset, uae_u8 *buf, int blocksize) { - int i, j, blocks = 63, empty = 1; - DWORD outlen, high; - - for (j = 0; j < blocks; j++) { - high = (DWORD)(offset >> 32); - if (SetFilePointer (h, (DWORD)offset, &high, FILE_BEGIN) == INVALID_FILE_SIZE) { - write_log (L"hd ignored, SetFilePointer failed, error %d\n", GetLastError ()); - return 1; - } - memset (buf, 0xaa, blocksize); - ReadFile (h, buf, blocksize, &outlen, NULL); - if (outlen != blocksize) { - write_log (L"hd ignored, read error %d!\n", GetLastError ()); - return 2; - } - if (j == 0 && offset > 0) - return -5; - if (j == 0 && buf[0] == 0x39 && buf[1] == 0x10 && buf[2] == 0xd3 && buf[3] == 0x12) { - // ADIDE "CPRM" hidden block.. - if (do_rdbdump) - rdbdump (h, offset, buf, blocksize); - write_log (L"hd accepted (adide rdb detected at block %d)\n", j); - return -3; - } - if (!memcmp (buf, "RDSK", 4) || !memcmp (buf, "DRKS", 4)) { - if (do_rdbdump) - rdbdump (h, offset, buf, blocksize); - write_log (L"hd accepted (rdb detected at block %d)\n", j); - return -1; - } - - if (!memcmp (buf + 2, "CIS@", 4) && !memcmp (buf + 16, CA, strlen (CA))) { - write_log (L"hd accepted (PCMCIA RAM)\n"); - return -2; - } - if (j == 0) { - for (i = 0; i < blocksize; i++) { - if (buf[i]) - empty = 0; - } - } - offset += blocksize; - } - if (!empty) { - int mounted; - if (regexiststree (NULL, L"DangerousDrives")) { - UAEREG *fkey = regcreatetree (NULL, L"DangerousDrives"); - int match = 0; - if (fkey) { - int idx = 0; - DWORD size, size2; - TCHAR tmp2[MAX_DPATH], tmp[MAX_DPATH]; - for (;;) { - size = sizeof (tmp) / sizeof (TCHAR); - size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - if (!_tcscmp (tmp, name)) - match = 1; - idx++; + int i, j, blocks = 63, empty = 1; + DWORD outlen, high; + + for (j = 0; j < blocks; j++) { + high = (DWORD)(offset >> 32); + if (SetFilePointer (h, (DWORD)offset, &high, FILE_BEGIN) == INVALID_FILE_SIZE) { + write_log (L"hd ignored, SetFilePointer failed, error %d\n", GetLastError ()); + return 1; } - regclosetree (fkey); - } - if (match) { - write_log (L"hd accepted, enabled in registry!\n"); - return -7; - } - } - mounted = ismounted (h); - if (!mounted) { - write_log (L"hd accepted, not empty and not mounted in Windows\n"); - return -8; - } - if (mounted < 0) { - write_log (L"hd ignored, NTFS partitions\n"); - return 0; - } - if (harddrive_dangerous == 0x1234dead) - return -6; - write_log (L"hd ignored, not empty and no RDB detected or Windows mounted\n"); - return 0; - } - write_log (L"hd accepted (empty)\n"); - return -9; + memset (buf, 0xaa, blocksize); + ReadFile (h, buf, blocksize, &outlen, NULL); + if (outlen != blocksize) { + write_log (L"hd ignored, read error %d!\n", GetLastError ()); + return 2; + } + if (j == 0 && offset > 0) + return -5; + if (j == 0 && buf[0] == 0x39 && buf[1] == 0x10 && buf[2] == 0xd3 && buf[3] == 0x12) { + // ADIDE "CPRM" hidden block.. + if (do_rdbdump) + rdbdump (h, offset, buf, blocksize); + write_log (L"hd accepted (adide rdb detected at block %d)\n", j); + return -3; + } + if (!memcmp (buf, "RDSK", 4) || !memcmp (buf, "DRKS", 4)) { + if (do_rdbdump) + rdbdump (h, offset, buf, blocksize); + write_log (L"hd accepted (rdb detected at block %d)\n", j); + return -1; + } + + if (!memcmp (buf + 2, "CIS@", 4) && !memcmp (buf + 16, CA, strlen (CA))) { + write_log (L"hd accepted (PCMCIA RAM)\n"); + return -2; + } + if (j == 0) { + for (i = 0; i < blocksize; i++) { + if (buf[i]) + empty = 0; + } + } + offset += blocksize; + } + if (!empty) { + int mounted; + if (regexiststree (NULL, L"DangerousDrives")) { + UAEREG *fkey = regcreatetree (NULL, L"DangerousDrives"); + int match = 0; + if (fkey) { + int idx = 0; + DWORD size, size2; + TCHAR tmp2[MAX_DPATH], tmp[MAX_DPATH]; + for (;;) { + size = sizeof (tmp) / sizeof (TCHAR); + size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + if (!_tcscmp (tmp, name)) + match = 1; + idx++; + } + regclosetree (fkey); + } + if (match) { + write_log (L"hd accepted, enabled in registry!\n"); + return -7; + } + } + mounted = ismounted (h); + if (!mounted) { + write_log (L"hd accepted, not empty and not mounted in Windows\n"); + return -8; + } + if (mounted < 0) { + write_log (L"hd ignored, NTFS partitions\n"); + return 0; + } + if (harddrive_dangerous == 0x1234dead) + return -6; + write_log (L"hd ignored, not empty and no RDB detected or Windows mounted\n"); + return 0; + } + write_log (L"hd accepted (empty)\n"); + return -9; } static void trim (TCHAR *s) { - while(_tcslen(s) > 0 && s[_tcslen(s) - 1] == ' ') - s[_tcslen(s) - 1] = 0; + while(_tcslen(s) > 0 && s[_tcslen(s) - 1] == ' ') + s[_tcslen(s) - 1] = 0; } int isharddrive (const TCHAR *name) { - int i; + int i; - for (i = 0; i < hdf_getnumharddrives (); i++) { - if (!_tcscmp (uae_drives[i].device_name, name)) - return i; - } - return -1; + for (i = 0; i < hdf_getnumharddrives (); i++) { + if (!_tcscmp (uae_drives[i].device_name, name)) + return i; + } + return -1; } static TCHAR *hdz[] = { L"hdz", L"zip", L"rar", L"7z", NULL }; @@ -297,325 +297,325 @@ static TCHAR *hdz[] = { L"hdz", L"zip", L"rar", L"7z", NULL }; #if 0 static void getserial (HANDLE h) { - DWORD outsize, written; - DISK_GEOMETRY_EX *out; - VOLUME_DISK_EXTENTS *vde; - - DWORD serial, mcl, fsflags; - if (GetVolumeInformationByHandleW (h, NULL, 0, &serial, &mcl, &fsflags, NULL, 0)) { - } - - outsize = sizeof (DISK_GEOMETRY_EX) + 10 * (sizeof (DISK_DETECTION_INFO) + sizeof (DISK_PARTITION_INFO)); - out = xmalloc (outsize); - if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, out, outsize, &written, NULL)) { - DISK_DETECTION_INFO *ddi = DiskGeometryGetDetect (out); - DISK_PARTITION_INFO *dpi = DiskGeometryGetPartition (out); - write_log (L""); - } - xfree (out); - - - outsize = sizeof (VOLUME_DISK_EXTENTS) + sizeof (DISK_EXTENT) * 10; - vde = xmalloc (outsize); - if (DeviceIoControl (h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, vde, outsize, &written, NULL)) { - if (vde->NumberOfDiskExtents > 0) - write_log(L"%d\n", vde->Extents[0].DiskNumber); - } - xfree (vde); + DWORD outsize, written; + DISK_GEOMETRY_EX *out; + VOLUME_DISK_EXTENTS *vde; + + DWORD serial, mcl, fsflags; + if (GetVolumeInformationByHandleW (h, NULL, 0, &serial, &mcl, &fsflags, NULL, 0)) { + } + + outsize = sizeof (DISK_GEOMETRY_EX) + 10 * (sizeof (DISK_DETECTION_INFO) + sizeof (DISK_PARTITION_INFO)); + out = xmalloc (outsize); + if (DeviceIoControl (h, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, out, outsize, &written, NULL)) { + DISK_DETECTION_INFO *ddi = DiskGeometryGetDetect (out); + DISK_PARTITION_INFO *dpi = DiskGeometryGetPartition (out); + write_log (L""); + } + xfree (out); + + + outsize = sizeof (VOLUME_DISK_EXTENTS) + sizeof (DISK_EXTENT) * 10; + vde = xmalloc (outsize); + if (DeviceIoControl (h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, vde, outsize, &written, NULL)) { + if (vde->NumberOfDiskExtents > 0) + write_log(L"%d\n", vde->Extents[0].DiskNumber); + } + xfree (vde); } #endif int hdf_open_target (struct hardfiledata *hfd, const TCHAR *pname) { - HANDLE h = INVALID_HANDLE_VALUE; - DWORD flags; - int i; - struct uae_driveinfo *udi; - TCHAR *name = my_strdup (pname); - - hfd->flags = 0; - hfd->drive_empty = 0; - hdf_close (hfd); - hfd->cache = VirtualAlloc (NULL, CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); - hfd->cache_valid = 0; - hfd->virtual_size = 0; - hfd->virtual_rdb = NULL; - if (!hfd->cache) { - write_log (L"VirtualAlloc(%d) failed, error %d\n", CACHE_SIZE, GetLastError ()); - goto end; - } - hfd_log (L"hfd open: '%s'\n", name); - if (_tcslen (name) > 4 && !_tcsncmp (name, L"HD_", 3)) { - hdf_init_target (); - i = isharddrive (name); - if (i >= 0) { - DWORD r; - udi = &uae_drives[i]; - hfd->flags = HFD_FLAGS_REALDRIVE; - if (udi->nomedia) - hfd->drive_empty = -1; - if (udi->readonly) - hfd->readonly = 1; - flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; - h = CreateFile (udi->device_path, - GENERIC_READ | (hfd->readonly ? 0 : GENERIC_WRITE), - FILE_SHARE_READ | (hfd->readonly ? 0 : FILE_SHARE_WRITE), - NULL, OPEN_EXISTING, flags, NULL); - hfd->handle = h; - if (h == INVALID_HANDLE_VALUE) + HANDLE h = INVALID_HANDLE_VALUE; + DWORD flags; + int i; + struct uae_driveinfo *udi; + TCHAR *name = my_strdup (pname); + + hfd->flags = 0; + hfd->drive_empty = 0; + hdf_close (hfd); + hfd->cache = VirtualAlloc (NULL, CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); + hfd->cache_valid = 0; + hfd->virtual_size = 0; + hfd->virtual_rdb = NULL; + if (!hfd->cache) { + write_log (L"VirtualAlloc(%d) failed, error %d\n", CACHE_SIZE, GetLastError ()); goto end; - if (!DeviceIoControl(h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &r, NULL)) - write_log (L"WARNING: '%s' FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", name, GetLastError ()); - _tcsncpy (hfd->vendor_id, udi->vendor_id, 8); - _tcsncpy (hfd->product_id, udi->product_id, 16); - _tcsncpy (hfd->product_rev, udi->product_rev, 4); - hfd->offset = udi->offset; - hfd->physsize = hfd->virtsize = udi->size; - hfd->blocksize = udi->bytespersector; - if (hfd->offset == 0 && !hfd->drive_empty) { - int sf = safetycheck (hfd->handle, udi->device_path, 0, hfd->cache, hfd->blocksize); - if (sf > 0) - goto end; - if (sf == 0 && !hfd->readonly && harddrive_dangerous != 0x1234dead) { - write_log (L"'%s' forced read-only, safetycheck enabled\n", udi->device_path); - hfd->dangerous = 1; - // clear GENERIC_WRITE - CloseHandle (h); - h = CreateFile (udi->device_path, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, flags, NULL); - hfd->handle = h; - if (h == INVALID_HANDLE_VALUE) - goto end; - if (!DeviceIoControl(h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &r, NULL)) - write_log (L"WARNING: '%s' FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", name, GetLastError ()); - } + } + hfd_log (L"hfd open: '%s'\n", name); + if (_tcslen (name) > 4 && !_tcsncmp (name, L"HD_", 3)) { + hdf_init_target (); + i = isharddrive (name); + if (i >= 0) { + DWORD r; + udi = &uae_drives[i]; + hfd->flags = HFD_FLAGS_REALDRIVE; + if (udi->nomedia) + hfd->drive_empty = -1; + if (udi->readonly) + hfd->readonly = 1; + flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; + h = CreateFile (udi->device_path, + GENERIC_READ | (hfd->readonly ? 0 : GENERIC_WRITE), + FILE_SHARE_READ | (hfd->readonly ? 0 : FILE_SHARE_WRITE), + NULL, OPEN_EXISTING, flags, NULL); + hfd->handle = h; + if (h == INVALID_HANDLE_VALUE) + goto end; + if (!DeviceIoControl(h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &r, NULL)) + write_log (L"WARNING: '%s' FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", name, GetLastError ()); + _tcsncpy (hfd->vendor_id, udi->vendor_id, 8); + _tcsncpy (hfd->product_id, udi->product_id, 16); + _tcsncpy (hfd->product_rev, udi->product_rev, 4); + hfd->offset = udi->offset; + hfd->physsize = hfd->virtsize = udi->size; + hfd->blocksize = udi->bytespersector; + if (hfd->offset == 0 && !hfd->drive_empty) { + int sf = safetycheck (hfd->handle, udi->device_path, 0, hfd->cache, hfd->blocksize); + if (sf > 0) + goto end; + if (sf == 0 && !hfd->readonly && harddrive_dangerous != 0x1234dead) { + write_log (L"'%s' forced read-only, safetycheck enabled\n", udi->device_path); + hfd->dangerous = 1; + // clear GENERIC_WRITE + CloseHandle (h); + h = CreateFile (udi->device_path, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, flags, NULL); + hfd->handle = h; + if (h == INVALID_HANDLE_VALUE) + goto end; + if (!DeviceIoControl(h, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, NULL, 0, &r, NULL)) + write_log (L"WARNING: '%s' FSCTL_ALLOW_EXTENDED_DASD_IO returned %d\n", name, GetLastError ()); + } #if 0 - if (sf == 0 && hfd->warned >= 0) { - if (harddrive_dangerous != 0x1234dead) { - if (!hfd->warned) - gui_message_id (IDS_HARDDRIVESAFETYWARNING1); - hfd->warned = 1; - goto end; - } - if (!hfd->warned) { - gui_message_id (IDS_HARDDRIVESAFETYWARNING2); - hfd->warned = 1; - } - } - } else { - hfd->warned = -1; + if (sf == 0 && hfd->warned >= 0) { + if (harddrive_dangerous != 0x1234dead) { + if (!hfd->warned) + gui_message_id (IDS_HARDDRIVESAFETYWARNING1); + hfd->warned = 1; + goto end; + } + if (!hfd->warned) { + gui_message_id (IDS_HARDDRIVESAFETYWARNING2); + hfd->warned = 1; + } + } + } else { + hfd->warned = -1; #endif - } - hfd->handle_valid = HDF_HANDLE_WIN32; - hfd->emptyname = my_strdup (name); + } + hfd->handle_valid = HDF_HANDLE_WIN32; + hfd->emptyname = my_strdup (name); + } else { + hfd->flags = HFD_FLAGS_REALDRIVE; + hfd->drive_empty = -1; + hfd->emptyname = my_strdup (name); + } } else { - hfd->flags = HFD_FLAGS_REALDRIVE; - hfd->drive_empty = -1; - hfd->emptyname = my_strdup (name); - } - } else { - int zmode = 0; - TCHAR *ext = _tcsrchr (name, '.'); - if (ext != NULL) { - ext++; - for (i = 0; hdz[i]; i++) { - if (!_tcsicmp (ext, hdz[i])) - zmode = 1; - } - } - h = CreateFile (name, GENERIC_READ | (hfd->readonly ? 0 : GENERIC_WRITE), hfd->readonly ? FILE_SHARE_READ : 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + int zmode = 0; + TCHAR *ext = _tcsrchr (name, '.'); + if (ext != NULL) { + ext++; + for (i = 0; hdz[i]; i++) { + if (!_tcsicmp (ext, hdz[i])) + zmode = 1; + } + } + h = CreateFile (name, GENERIC_READ | (hfd->readonly ? 0 : GENERIC_WRITE), hfd->readonly ? FILE_SHARE_READ : 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + hfd->handle = h; + i = _tcslen (name) - 1; + while (i >= 0) { + if ((i > 0 && (name[i - 1] == '/' || name[i - 1] == '\\')) || i == 0) { + _tcscpy (hfd->vendor_id, L"UAE"); + _tcsncpy (hfd->product_id, name + i, 15); + _tcscpy (hfd->product_rev, L"0.3"); + break; + } + i--; + } + if (h != INVALID_HANDLE_VALUE) { + DWORD ret, low, high; + high = 0; + ret = SetFilePointer (h, 0, &high, FILE_END); + if (ret == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) + goto end; + low = GetFileSize (h, &high); + if (low == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) + goto end; + low &= ~(hfd->blocksize - 1); + hfd->physsize = hfd->virtsize = ((uae_u64)high << 32) | low; + hfd->handle_valid = HDF_HANDLE_WIN32; + if (hfd->physsize < 64 * 1024 * 1024 && zmode) { + write_log (L"HDF '%s' re-opened in zfile-mode\n", name); + CloseHandle (h); + hfd->handle = h = zfile_fopen(name, hfd->readonly ? L"rb" : L"r+b", ZFD_NORMAL); + if (!h) + goto end; + zfile_fseek (h, 0, SEEK_END); + hfd->physsize = hfd->virtsize = zfile_ftell (h); + zfile_fseek (h, 0, SEEK_SET); + hfd->handle_valid = HDF_HANDLE_ZFILE; + } + } else { + write_log (L"HDF '%s' failed to open. error = %d\n", name, GetLastError ()); + } + } hfd->handle = h; - i = _tcslen (name) - 1; - while (i >= 0) { - if ((i > 0 && (name[i - 1] == '/' || name[i - 1] == '\\')) || i == 0) { - _tcscpy (hfd->vendor_id, L"UAE"); - _tcsncpy (hfd->product_id, name + i, 15); - _tcscpy (hfd->product_rev, L"0.3"); - break; - } - i--; - } - if (h != INVALID_HANDLE_VALUE) { - DWORD ret, low, high; - high = 0; - ret = SetFilePointer (h, 0, &high, FILE_END); - if (ret == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) - goto end; - low = GetFileSize (h, &high); - if (low == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) - goto end; - low &= ~(hfd->blocksize - 1); - hfd->physsize = hfd->virtsize = ((uae_u64)high << 32) | low; - hfd->handle_valid = HDF_HANDLE_WIN32; - if (hfd->physsize < 64 * 1024 * 1024 && zmode) { - write_log (L"HDF '%s' re-opened in zfile-mode\n", name); - CloseHandle (h); - hfd->handle = h = zfile_fopen(name, hfd->readonly ? L"rb" : L"r+b", ZFD_NORMAL); - if (!h) - goto end; - zfile_fseek (h, 0, SEEK_END); - hfd->physsize = hfd->virtsize = zfile_ftell (h); - zfile_fseek (h, 0, SEEK_SET); - hfd->handle_valid = HDF_HANDLE_ZFILE; - } - } else { - write_log (L"HDF '%s' failed to open. error = %d\n", name, GetLastError ()); + if (hfd->handle_valid || hfd->drive_empty) { + hfd_log (L"HDF '%s' opened, size=%dK mode=%d empty=%d\n", + name, hfd->physsize / 1024, hfd->handle_valid, hfd->drive_empty); + return 1; } - } - hfd->handle = h; - if (hfd->handle_valid || hfd->drive_empty) { - hfd_log (L"HDF '%s' opened, size=%dK mode=%d empty=%d\n", - name, hfd->physsize / 1024, hfd->handle_valid, hfd->drive_empty); - return 1; - } end: - hdf_close (hfd); - xfree (name); - return 0; + hdf_close (hfd); + xfree (name); + return 0; } void hdf_close_target (struct hardfiledata *hfd) { - if (hfd->handle_valid) { - if (hfd->handle && hfd->handle != INVALID_HANDLE_VALUE) { - if (hfd->handle_valid == HDF_HANDLE_WIN32) - CloseHandle (hfd->handle); - else if(hfd->handle_valid == HDF_HANDLE_ZFILE) - zfile_fclose (hfd->handle); - } - } - xfree (hfd->emptyname); - hfd->emptyname = NULL; - hfd->handle = 0; - hfd->handle_valid = 0; - if (hfd->cache) - VirtualFree (hfd->cache, 0, MEM_RELEASE); - xfree(hfd->virtual_rdb); - hfd->virtual_rdb = 0; - hfd->virtual_size = 0; - hfd->cache = 0; - hfd->cache_valid = 0; - hfd->drive_empty = 0; - hfd->dangerous = 0; + if (hfd->handle_valid) { + if (hfd->handle && hfd->handle != INVALID_HANDLE_VALUE) { + if (hfd->handle_valid == HDF_HANDLE_WIN32) + CloseHandle (hfd->handle); + else if(hfd->handle_valid == HDF_HANDLE_ZFILE) + zfile_fclose (hfd->handle); + } + } + xfree (hfd->emptyname); + hfd->emptyname = NULL; + hfd->handle = 0; + hfd->handle_valid = 0; + if (hfd->cache) + VirtualFree (hfd->cache, 0, MEM_RELEASE); + xfree(hfd->virtual_rdb); + hfd->virtual_rdb = 0; + hfd->virtual_size = 0; + hfd->cache = 0; + hfd->cache_valid = 0; + hfd->drive_empty = 0; + hfd->dangerous = 0; } int hdf_dup_target (struct hardfiledata *dhfd, const struct hardfiledata *shfd) { - if (!shfd->handle_valid) - return 0; - if (shfd->handle_valid == HDF_HANDLE_WIN32) { - HANDLE duphandle; - if (!DuplicateHandle (GetCurrentProcess (), shfd->handle, GetCurrentProcess () , &duphandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) - return 0; - dhfd->handle = duphandle; - dhfd->handle_valid = HDF_HANDLE_WIN32; - } else if (shfd->handle_valid == HDF_HANDLE_ZFILE) { - struct zfile *zf; - zf = zfile_dup (shfd->handle); - if (!zf) - return 0; - dhfd->handle = zf; - dhfd->handle_valid = HDF_HANDLE_ZFILE; - } - dhfd->cache = VirtualAlloc (NULL, CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); - dhfd->cache_valid = 0; - if (!dhfd->cache) { - hdf_close (dhfd); - return 0; - } - return 1; + if (!shfd->handle_valid) + return 0; + if (shfd->handle_valid == HDF_HANDLE_WIN32) { + HANDLE duphandle; + if (!DuplicateHandle (GetCurrentProcess (), shfd->handle, GetCurrentProcess () , &duphandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) + return 0; + dhfd->handle = duphandle; + dhfd->handle_valid = HDF_HANDLE_WIN32; + } else if (shfd->handle_valid == HDF_HANDLE_ZFILE) { + struct zfile *zf; + zf = zfile_dup (shfd->handle); + if (!zf) + return 0; + dhfd->handle = zf; + dhfd->handle_valid = HDF_HANDLE_ZFILE; + } + dhfd->cache = VirtualAlloc (NULL, CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); + dhfd->cache_valid = 0; + if (!dhfd->cache) { + hdf_close (dhfd); + return 0; + } + return 1; } static int hdf_seek (struct hardfiledata *hfd, uae_u64 offset) { - DWORD high, ret; - - if (hfd->handle_valid == 0) { - gui_message (L"hd: hdf handle is not valid. bug."); - abort(); - } - if (offset >= hfd->physsize - hfd->virtual_size) { - gui_message (L"hd: tried to seek out of bounds! (%I64X >= %I64X)\n", offset, hfd->physsize); - abort (); - } - offset += hfd->offset; - if (offset & (hfd->blocksize - 1)) { - gui_message (L"hd: poscheck failed, offset=%I64X not aligned to blocksize=%d! (%I64X & %04X = %04X)\n", - offset, hfd->blocksize, offset, hfd->blocksize, offset & (hfd->blocksize - 1)); - abort (); - } - if (hfd->handle_valid == HDF_HANDLE_WIN32) { - high = (DWORD)(offset >> 32); - ret = SetFilePointer (hfd->handle, (DWORD)offset, &high, FILE_BEGIN); - if (ret == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) - return -1; - } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - zfile_fseek (hfd->handle, (long)offset, SEEK_SET); - } - return 0; + DWORD high, ret; + + if (hfd->handle_valid == 0) { + gui_message (L"hd: hdf handle is not valid. bug."); + abort(); + } + if (offset >= hfd->physsize - hfd->virtual_size) { + gui_message (L"hd: tried to seek out of bounds! (%I64X >= %I64X)\n", offset, hfd->physsize); + abort (); + } + offset += hfd->offset; + if (offset & (hfd->blocksize - 1)) { + gui_message (L"hd: poscheck failed, offset=%I64X not aligned to blocksize=%d! (%I64X & %04X = %04X)\n", + offset, hfd->blocksize, offset, hfd->blocksize, offset & (hfd->blocksize - 1)); + abort (); + } + if (hfd->handle_valid == HDF_HANDLE_WIN32) { + high = (DWORD)(offset >> 32); + ret = SetFilePointer (hfd->handle, (DWORD)offset, &high, FILE_BEGIN); + if (ret == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) + return -1; + } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { + zfile_fseek (hfd->handle, (long)offset, SEEK_SET); + } + return 0; } static void poscheck (struct hardfiledata *hfd, int len) { - DWORD high, ret, err; - uae_u64 pos; - - if (hfd->handle_valid == HDF_HANDLE_WIN32) { - high = 0; - ret = SetFilePointer (hfd->handle, 0, &high, FILE_CURRENT); - err = GetLastError (); - if (ret == INVALID_FILE_SIZE && err != NO_ERROR) { - gui_message (L"hd: poscheck failed. seek failure, error %d", err); - abort (); - } - pos = ((uae_u64)high) << 32 | ret; - } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - pos = zfile_ftell (hfd->handle); - } - if (len < 0) { - gui_message (L"hd: poscheck failed, negative length! (%d)", len); - abort (); - } - if (pos < hfd->offset) { - gui_message (L"hd: poscheck failed, offset out of bounds! (%I64d < %I64d)", pos, hfd->offset); - abort (); - } - if (pos >= hfd->offset + hfd->physsize - hfd->virtual_size || pos >= hfd->offset + hfd->physsize + len - hfd->virtual_size) { - gui_message (L"hd: poscheck failed, offset out of bounds! (%I64d >= %I64d, LEN=%d)", pos, hfd->offset + hfd->physsize, len); - abort (); - } - if (pos & (hfd->blocksize - 1)) { - gui_message (L"hd: poscheck failed, offset not aligned to blocksize! (%I64X & %04X = %04X\n", pos, hfd->blocksize, pos & hfd->blocksize); - abort (); - } + DWORD high, ret, err; + uae_u64 pos; + + if (hfd->handle_valid == HDF_HANDLE_WIN32) { + high = 0; + ret = SetFilePointer (hfd->handle, 0, &high, FILE_CURRENT); + err = GetLastError (); + if (ret == INVALID_FILE_SIZE && err != NO_ERROR) { + gui_message (L"hd: poscheck failed. seek failure, error %d", err); + abort (); + } + pos = ((uae_u64)high) << 32 | ret; + } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { + pos = zfile_ftell (hfd->handle); + } + if (len < 0) { + gui_message (L"hd: poscheck failed, negative length! (%d)", len); + abort (); + } + if (pos < hfd->offset) { + gui_message (L"hd: poscheck failed, offset out of bounds! (%I64d < %I64d)", pos, hfd->offset); + abort (); + } + if (pos >= hfd->offset + hfd->physsize - hfd->virtual_size || pos >= hfd->offset + hfd->physsize + len - hfd->virtual_size) { + gui_message (L"hd: poscheck failed, offset out of bounds! (%I64d >= %I64d, LEN=%d)", pos, hfd->offset + hfd->physsize, len); + abort (); + } + if (pos & (hfd->blocksize - 1)) { + gui_message (L"hd: poscheck failed, offset not aligned to blocksize! (%I64X & %04X = %04X\n", pos, hfd->blocksize, pos & hfd->blocksize); + abort (); + } } static int isincache (struct hardfiledata *hfd, uae_u64 offset, int len) { - if (!hfd->cache_valid) + if (!hfd->cache_valid) + return -1; + if (offset >= hfd->cache_offset && offset + len <= hfd->cache_offset + CACHE_SIZE) + return (int)(offset - hfd->cache_offset); return -1; - if (offset >= hfd->cache_offset && offset + len <= hfd->cache_offset + CACHE_SIZE) - return (int)(offset - hfd->cache_offset); - return -1; } #if 0 void hfd_flush_cache (struct hardfiledata *hfd, int now) { - DWORD outlen = 0; - if (!hfd->cache_needs_flush || !hfd->cache_valid) - return; - if (now || time (NULL) > hfd->cache_needs_flush + CACHE_FLUSH_TIME) { - hdf_log ("flushed %d %d %d\n", now, time(NULL), hfd->cache_needs_flush); - hdf_seek (hfd, hfd->cache_offset); - poscheck (hfd, CACHE_SIZE); - WriteFile (hfd->handle, hfd->cache, CACHE_SIZE, &outlen, NULL); - hfd->cache_needs_flush = 0; - } + DWORD outlen = 0; + if (!hfd->cache_needs_flush || !hfd->cache_valid) + return; + if (now || time (NULL) > hfd->cache_needs_flush + CACHE_FLUSH_TIME) { + hdf_log ("flushed %d %d %d\n", now, time(NULL), hfd->cache_needs_flush); + hdf_seek (hfd, hfd->cache_offset); + poscheck (hfd, CACHE_SIZE); + WriteFile (hfd->handle, hfd->cache, CACHE_SIZE, &outlen, NULL); + hfd->cache_needs_flush = 0; + } } #endif @@ -623,230 +623,235 @@ void hfd_flush_cache (struct hardfiledata *hfd, int now) static int hdf_rw (struct hardfiledata *hfd, void *bufferp, uae_u64 offset, int len, int dowrite) { - DWORD outlen = 0, outlen2; - uae_u8 *buffer = bufferp; - int soff, size, mask, bs; - - bs = hfd->blocksize; - mask = hfd->blocksize - 1; - hfd->cache_valid = 0; - if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - if (dowrite) - outlen = zfile_fwrite (buffer, len, 1, hfd->handle); - else - outlen = zfile_fread (buffer, len, 1, hfd->handle); - } else { - soff = offset & mask; - if (soff > 0) { /* offset not aligned to blocksize */ - size = bs - soff; - if (size > len) - size = len; - hdf_seek (hfd, offset & ~mask); - poscheck (hfd, len); - if (dowrite) - WriteFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); - else - ReadFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); - if (outlen2 != hfd->blocksize) - goto end; - outlen += size; - memcpy (buffer, hfd->cache + soff, size); - buffer += size; - offset += size; - len -= size; - } - while (len >= bs) { /* aligned access */ - hdf_seek (hfd, offset); - poscheck (hfd, len); - size = len & ~mask; - if (size > CACHE_SIZE) - size = CACHE_SIZE; - if (dowrite) { - WriteFile (hfd->handle, hfd->cache, size, &outlen2, NULL); - } else { - int coff = isincache(hfd, offset, size); - if (coff >= 0) { - memcpy (buffer, hfd->cache + coff, size); - outlen2 = size; - } else { - ReadFile (hfd->handle, hfd->cache, size, &outlen2, NULL); - if (outlen2 == size) - memcpy (buffer, hfd->cache, size); + DWORD outlen = 0, outlen2; + uae_u8 *buffer = bufferp; + int soff, size, mask, bs; + + bs = hfd->blocksize; + mask = hfd->blocksize - 1; + hfd->cache_valid = 0; + if (hfd->handle_valid == HDF_HANDLE_ZFILE) { + if (dowrite) + outlen = zfile_fwrite (buffer, len, 1, hfd->handle); + else + outlen = zfile_fread (buffer, len, 1, hfd->handle); + } else { + soff = offset & mask; + if (soff > 0) { /* offset not aligned to blocksize */ + size = bs - soff; + if (size > len) + size = len; + hdf_seek (hfd, offset & ~mask); + poscheck (hfd, len); + if (dowrite) + WriteFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); + else + ReadFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); + if (outlen2 != hfd->blocksize) + goto end; + outlen += size; + memcpy (buffer, hfd->cache + soff, size); + buffer += size; + offset += size; + len -= size; + } + while (len >= bs) { /* aligned access */ + hdf_seek (hfd, offset); + poscheck (hfd, len); + size = len & ~mask; + if (size > CACHE_SIZE) + size = CACHE_SIZE; + if (dowrite) { + WriteFile (hfd->handle, hfd->cache, size, &outlen2, NULL); + } else { + int coff = isincache(hfd, offset, size); + if (coff >= 0) { + memcpy (buffer, hfd->cache + coff, size); + outlen2 = size; + } else { + ReadFile (hfd->handle, hfd->cache, size, &outlen2, NULL); + if (outlen2 == size) + memcpy (buffer, hfd->cache, size); + } + } + if (outlen2 != size) + goto end; + outlen += outlen2; + buffer += size; + offset += size; + len -= size; + } + if (len > 0) { /* len > 0 && len < bs */ + hdf_seek (hfd, offset); + poscheck (hfd, len); + if (dowrite) + WriteFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); + else + ReadFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); + if (outlen2 != bs) + goto end; + outlen += len; + memcpy (buffer, hfd->cache, len); } - } - if (outlen2 != size) - goto end; - outlen += outlen2; - buffer += size; - offset += size; - len -= size; - } - if (len > 0) { /* len > 0 && len < bs */ - hdf_seek (hfd, offset); - poscheck (hfd, len); - if (dowrite) - WriteFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); - else - ReadFile (hfd->handle, hfd->cache, bs, &outlen2, NULL); - if (outlen2 != bs) - goto end; - outlen += len; - memcpy (buffer, hfd->cache, len); } - } end: - return outlen; + return outlen; } int hdf_read (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - return hdf_rw (hfd, buffer, offset, len, 0); + return hdf_rw (hfd, buffer, offset, len, 0); } int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - return hdf_rw (hfd, buffer, offset, len, 1); + return hdf_rw (hfd, buffer, offset, len, 1); } #else static int hdf_read_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - DWORD outlen = 0; - int coffset; - - if (offset == 0) + DWORD outlen = 0; + int coffset; + + if (offset == 0) + hfd->cache_valid = 0; + coffset = isincache (hfd, offset, len); + if (coffset >= 0) { + memcpy (buffer, hfd->cache + coffset, len); + return len; + } + hfd->cache_offset = offset; + if (offset + CACHE_SIZE > hfd->offset + (hfd->physsize - hfd->virtual_size)) + hfd->cache_offset = hfd->offset + (hfd->physsize - hfd->virtual_size) - CACHE_SIZE; + hdf_seek (hfd, hfd->cache_offset); + poscheck (hfd, CACHE_SIZE); + if (hfd->handle_valid == HDF_HANDLE_WIN32) + ReadFile (hfd->handle, hfd->cache, CACHE_SIZE, &outlen, NULL); + else if (hfd->handle_valid == HDF_HANDLE_ZFILE) + outlen = zfile_fread (hfd->cache, 1, CACHE_SIZE, hfd->handle); + hfd->cache_valid = 0; + if (outlen != CACHE_SIZE) + return 0; + hfd->cache_valid = 1; + coffset = isincache (hfd, offset, len); + if (coffset >= 0) { + memcpy (buffer, hfd->cache + coffset, len); + return len; + } + write_log (L"hdf_read: cache bug! offset=%I64d len=%d\n", offset, len); hfd->cache_valid = 0; - coffset = isincache (hfd, offset, len); - if (coffset >= 0) { - memcpy (buffer, hfd->cache + coffset, len); - return len; - } - hfd->cache_offset = offset; - if (offset + CACHE_SIZE > hfd->offset + (hfd->physsize - hfd->virtual_size)) - hfd->cache_offset = hfd->offset + (hfd->physsize - hfd->virtual_size) - CACHE_SIZE; - hdf_seek (hfd, hfd->cache_offset); - poscheck (hfd, CACHE_SIZE); - if (hfd->handle_valid == HDF_HANDLE_WIN32) - ReadFile (hfd->handle, hfd->cache, CACHE_SIZE, &outlen, NULL); - else if (hfd->handle_valid == HDF_HANDLE_ZFILE) - outlen = zfile_fread (hfd->cache, 1, CACHE_SIZE, hfd->handle); - hfd->cache_valid = 0; - if (outlen != CACHE_SIZE) return 0; - hfd->cache_valid = 1; - coffset = isincache (hfd, offset, len); - if (coffset >= 0) { - memcpy (buffer, hfd->cache + coffset, len); - return len; - } - write_log (L"hdf_read: cache bug! offset=%I64d len=%d\n", offset, len); - hfd->cache_valid = 0; - return 0; } int hdf_read_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - int got = 0; - uae_u8 *p = buffer; - - if (hfd->drive_empty) - return 0; - if (offset < hfd->virtual_size) { - uae_u64 len2 = offset + len <= hfd->virtual_size ? len : hfd->virtual_size - offset; - if (!hfd->virtual_rdb) - return 0; - memcpy (buffer, hfd->virtual_rdb + offset, len2); - return len2; - } - offset -= hfd->virtual_size; - while (len > 0) { - int ret, maxlen; - if (hfd->physsize < CACHE_SIZE) { - hfd->cache_valid = 0; - hdf_seek (hfd, offset); - poscheck (hfd, len); - if (hfd->handle_valid == HDF_HANDLE_WIN32) { - ReadFile (hfd->handle, hfd->cache, len, &ret, NULL); - memcpy (buffer, hfd->cache, ret); - } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - ret = zfile_fread (buffer, 1, len, hfd->handle); - } - maxlen = len; - } else { - maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; - ret = hdf_read_2 (hfd, p, offset, maxlen); - } - got += ret; - if (ret != maxlen) - return got; - offset += maxlen; - p += maxlen; - len -= maxlen; - } - return got; + int got = 0; + uae_u8 *p = buffer; + + if (hfd->drive_empty) + return 0; + if (offset < hfd->virtual_size) { + uae_u64 len2 = offset + len <= hfd->virtual_size ? len : hfd->virtual_size - offset; + if (!hfd->virtual_rdb) + return 0; + memcpy (buffer, hfd->virtual_rdb + offset, len2); + return len2; + } + offset -= hfd->virtual_size; + while (len > 0) { + int ret, maxlen; + if (hfd->physsize < CACHE_SIZE) { + hfd->cache_valid = 0; + hdf_seek (hfd, offset); + poscheck (hfd, len); + if (hfd->handle_valid == HDF_HANDLE_WIN32) { + ReadFile (hfd->handle, hfd->cache, len, &ret, NULL); + memcpy (buffer, hfd->cache, ret); + } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { + ret = zfile_fread (buffer, 1, len, hfd->handle); + } + maxlen = len; + } else { + maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; + ret = hdf_read_2 (hfd, p, offset, maxlen); + } + got += ret; + if (ret != maxlen) + return got; + offset += maxlen; + p += maxlen; + len -= maxlen; + } + return got; } static int hdf_write_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - DWORD outlen = 0; + DWORD outlen = 0; - if (hfd->readonly) - return 0; - if (hfd->dangerous) - return 0; - hfd->cache_valid = 0; - hdf_seek (hfd, offset); - poscheck (hfd, len); - memcpy (hfd->cache, buffer, len); - if (hfd->handle_valid == HDF_HANDLE_WIN32) - WriteFile (hfd->handle, hfd->cache, len, &outlen, NULL); - else if (hfd->handle_valid == HDF_HANDLE_ZFILE) - outlen = zfile_fwrite (hfd->cache, 1, len, hfd->handle); - return outlen; + if (hfd->readonly) + return 0; + if (hfd->dangerous) + return 0; + hfd->cache_valid = 0; + hdf_seek (hfd, offset); + poscheck (hfd, len); + memcpy (hfd->cache, buffer, len); + if (hfd->handle_valid == HDF_HANDLE_WIN32) + WriteFile (hfd->handle, hfd->cache, len, &outlen, NULL); + else if (hfd->handle_valid == HDF_HANDLE_ZFILE) + outlen = zfile_fwrite (hfd->cache, 1, len, hfd->handle); + return outlen; } int hdf_write_target (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) { - int got = 0; - uae_u8 *p = buffer; - - if (hfd->drive_empty) - return 0; - if (offset < hfd->virtual_size) - return len; - offset -= hfd->virtual_size; - while (len > 0) { - int maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; - int ret = hdf_write_2(hfd, p, offset, maxlen); - if (ret < 0) - return ret; - got += ret; - if (ret != maxlen) - return got; - offset += maxlen; - p += maxlen; - len -= maxlen; - } - return got; + int got = 0; + uae_u8 *p = buffer; + + if (hfd->drive_empty) + return 0; + if (offset < hfd->virtual_size) + return len; + offset -= hfd->virtual_size; + while (len > 0) { + int maxlen = len > CACHE_SIZE ? CACHE_SIZE : len; + int ret = hdf_write_2(hfd, p, offset, maxlen); + if (ret < 0) + return ret; + got += ret; + if (ret != maxlen) + return got; + offset += maxlen; + p += maxlen; + len -= maxlen; + } + return got; } int hdf_resize_target (struct hardfiledata *hfd, uae_u64 newsize) { - LONG highword = 0; - DWORD ret; - - if (newsize >= 0x80000000) { - highword = (DWORD)(newsize >> 32); - ret = SetFilePointer (hfd->handle, (DWORD)newsize, &highword, FILE_BEGIN); - } else { - ret = SetFilePointer (hfd->handle, (DWORD)newsize, NULL, FILE_BEGIN); - } - if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + LONG highword = 0; + DWORD ret, err; + + if (newsize >= 0x80000000) { + highword = (DWORD)(newsize >> 32); + ret = SetFilePointer (hfd->handle, (DWORD)newsize, &highword, FILE_BEGIN); + } else { + ret = SetFilePointer (hfd->handle, (DWORD)newsize, NULL, FILE_BEGIN); + } + err = GetLastError (); + if (ret == INVALID_SET_FILE_POINTER && err != NO_ERROR) { + write_log (L"hdf_resize_target: SetFilePointer() %d\n", err); + return 0; + } + if (SetEndOfFile (hfd->handle)) { + hfd->physsize = newsize; + return 1; + } + err = GetLastError (); + write_log (L"hdf_resize_target: SetEndOfFile() %d\n", err); return 0; - if (SetEndOfFile (hfd->handle)) { - hfd->physsize = newsize; - return 1; - } - return 0; } #endif @@ -855,117 +860,117 @@ int hdf_resize_target (struct hardfiledata *hfd, uae_u64 newsize) static void generatestorageproperty (struct uae_driveinfo *udi, int ignoreduplicates) { - _tcscpy (udi->vendor_id, L"UAE"); - _tcscpy (udi->product_id, L"DISK"); - _tcscpy (udi->product_rev, L"1.1"); - _stprintf (udi->device_name, L"%s", udi->device_path); - udi->removablemedia = 1; + _tcscpy (udi->vendor_id, L"UAE"); + _tcscpy (udi->product_id, L"DISK"); + _tcscpy (udi->product_rev, L"1.1"); + _stprintf (udi->device_name, L"%s", udi->device_path); + udi->removablemedia = 1; } static int getstorageproperty (PUCHAR outBuf, int returnedLength, struct uae_driveinfo *udi, int ignoreduplicates) { - PSTORAGE_DEVICE_DESCRIPTOR devDesc; - TCHAR orgname[1024]; - PUCHAR p; - int i, j; - int size; - - devDesc = (PSTORAGE_DEVICE_DESCRIPTOR) outBuf; - size = devDesc->Version; - p = (PUCHAR) outBuf; - if (offsetof(STORAGE_DEVICE_DESCRIPTOR, CommandQueueing) > size) { - write_log (L"too short STORAGE_DEVICE_DESCRIPTOR only %d bytes\n", size); - return 1; - } - if (devDesc->DeviceType != INQ_DASD && devDesc->DeviceType != INQ_ROMD && devDesc->DeviceType != INQ_OPTD) { - write_log (L"not a direct access device, ignored (type=%d)\n", devDesc->DeviceType); - return 1; - } - if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, VendorIdOffset) && devDesc->VendorIdOffset && p[devDesc->VendorIdOffset]) { - j = 0; - for (i = devDesc->VendorIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) - udi->vendor_id[j++] = p[i]; - } - if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, ProductIdOffset) && devDesc->ProductIdOffset && p[devDesc->ProductIdOffset]) { - j = 0; - for (i = devDesc->ProductIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) - udi->product_id[j++] = p[i]; - } - if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, ProductRevisionOffset) && devDesc->ProductRevisionOffset && p[devDesc->ProductRevisionOffset]) { - j = 0; - for (i = devDesc->ProductRevisionOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) - udi->product_rev[j++] = p[i]; - } - if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, SerialNumberOffset) && devDesc->SerialNumberOffset && p[devDesc->SerialNumberOffset]) { - j = 0; - for (i = devDesc->SerialNumberOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) - udi->product_serial[j++] = p[i]; - } - if (udi->vendor_id[0]) - _tcscat (udi->device_name, udi->vendor_id); - if (udi->product_id[0]) { - if (udi->device_name[0]) - _tcscat (udi->device_name, L" "); - _tcscat (udi->device_name, udi->product_id); - } - if (udi->product_rev[0]) { - if (udi->device_name[0]) - _tcscat (udi->device_name, L" "); - _tcscat (udi->device_name, udi->product_rev); - } - if (udi->product_serial[0]) { - if (udi->device_name[0]) - _tcscat (udi->device_name, L" "); - _tcscat (udi->device_name, udi->product_serial); - } - if (!udi->device_name[0]) { - write_log (L"empty device id?!?, replacing with device path\n"); - _tcscpy (udi->device_name, udi->device_path); - } - udi->removablemedia = devDesc->RemovableMedia; - write_log (L"device id string: '%s'\n", udi->device_name); - if (ignoreduplicates) { - _stprintf (orgname, L"HD_%s", udi->device_name); - if (isharddrive (orgname) >= 0) { - write_log (L"duplicate device, ignored\n"); - return 1; - } - if (!udi->removablemedia) { - write_log (L"drive letter not removable, ignored\n"); - return 1; - } - } - return 0; + PSTORAGE_DEVICE_DESCRIPTOR devDesc; + TCHAR orgname[1024]; + PUCHAR p; + int i, j; + int size; + + devDesc = (PSTORAGE_DEVICE_DESCRIPTOR) outBuf; + size = devDesc->Version; + p = (PUCHAR) outBuf; + if (offsetof(STORAGE_DEVICE_DESCRIPTOR, CommandQueueing) > size) { + write_log (L"too short STORAGE_DEVICE_DESCRIPTOR only %d bytes\n", size); + return 1; + } + if (devDesc->DeviceType != INQ_DASD && devDesc->DeviceType != INQ_ROMD && devDesc->DeviceType != INQ_OPTD) { + write_log (L"not a direct access device, ignored (type=%d)\n", devDesc->DeviceType); + return 1; + } + if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, VendorIdOffset) && devDesc->VendorIdOffset && p[devDesc->VendorIdOffset]) { + j = 0; + for (i = devDesc->VendorIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) + udi->vendor_id[j++] = p[i]; + } + if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, ProductIdOffset) && devDesc->ProductIdOffset && p[devDesc->ProductIdOffset]) { + j = 0; + for (i = devDesc->ProductIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) + udi->product_id[j++] = p[i]; + } + if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, ProductRevisionOffset) && devDesc->ProductRevisionOffset && p[devDesc->ProductRevisionOffset]) { + j = 0; + for (i = devDesc->ProductRevisionOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) + udi->product_rev[j++] = p[i]; + } + if (size > offsetof(STORAGE_DEVICE_DESCRIPTOR, SerialNumberOffset) && devDesc->SerialNumberOffset && p[devDesc->SerialNumberOffset]) { + j = 0; + for (i = devDesc->SerialNumberOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++) + udi->product_serial[j++] = p[i]; + } + if (udi->vendor_id[0]) + _tcscat (udi->device_name, udi->vendor_id); + if (udi->product_id[0]) { + if (udi->device_name[0]) + _tcscat (udi->device_name, L" "); + _tcscat (udi->device_name, udi->product_id); + } + if (udi->product_rev[0]) { + if (udi->device_name[0]) + _tcscat (udi->device_name, L" "); + _tcscat (udi->device_name, udi->product_rev); + } + if (udi->product_serial[0]) { + if (udi->device_name[0]) + _tcscat (udi->device_name, L" "); + _tcscat (udi->device_name, udi->product_serial); + } + if (!udi->device_name[0]) { + write_log (L"empty device id?!?, replacing with device path\n"); + _tcscpy (udi->device_name, udi->device_path); + } + udi->removablemedia = devDesc->RemovableMedia; + write_log (L"device id string: '%s'\n", udi->device_name); + if (ignoreduplicates) { + _stprintf (orgname, L"HD_%s", udi->device_name); + if (isharddrive (orgname) >= 0) { + write_log (L"duplicate device, ignored\n"); + return 1; + } + if (!udi->removablemedia) { + write_log (L"drive letter not removable, ignored\n"); + return 1; + } + } + return 0; } static BOOL GetDevicePropertyFromName(const TCHAR *DevicePath, DWORD Index, DWORD *index2, uae_u8 *buffer, int ignoreduplicates) { - int i, nosp, geom_ok; - int ret = -1; - STORAGE_PROPERTY_QUERY query; - DRIVE_LAYOUT_INFORMATION *dli; - struct uae_driveinfo *udi; - TCHAR orgname[1024]; - HANDLE hDevice = INVALID_HANDLE_VALUE; - UCHAR outBuf[20000]; - DISK_GEOMETRY dg; - GET_LENGTH_INFORMATION gli; - PSTORAGE_ADAPTER_DESCRIPTOR adpDesc; - int gli_ok; - BOOL status; - ULONG length = 0, - returned = 0, - returnedLength; - - // - // Now we have the device path. Open the device interface - // to send Pass Through command - - udi = &uae_drives[*index2]; - memset (udi, 0, sizeof (struct uae_driveinfo)); - _tcscpy (udi->device_path, DevicePath); - write_log (L"opening device '%s'\n", udi->device_path); - hDevice = CreateFile( + int i, nosp, geom_ok; + int ret = -1; + STORAGE_PROPERTY_QUERY query; + DRIVE_LAYOUT_INFORMATION *dli; + struct uae_driveinfo *udi; + TCHAR orgname[1024]; + HANDLE hDevice = INVALID_HANDLE_VALUE; + UCHAR outBuf[20000]; + DISK_GEOMETRY dg; + GET_LENGTH_INFORMATION gli; + PSTORAGE_ADAPTER_DESCRIPTOR adpDesc; + int gli_ok; + BOOL status; + ULONG length = 0, + returned = 0, + returnedLength; + + // + // Now we have the device path. Open the device interface + // to send Pass Through command + + udi = &uae_drives[*index2]; + memset (udi, 0, sizeof (struct uae_driveinfo)); + _tcscpy (udi->device_path, DevicePath); + write_log (L"opening device '%s'\n", udi->device_path); + hDevice = CreateFile( udi->device_path, // device interface name GENERIC_READ, // dwDesiredAccess FILE_SHARE_READ | FILE_SHARE_WRITE, // dwShareMode @@ -975,237 +980,237 @@ static BOOL GetDevicePropertyFromName(const TCHAR *DevicePath, DWORD Index, DWOR NULL // hTemplateFile ); - // - // We have the handle to talk to the device. - // So we can release the interfaceDetailData buffer - // - - - if (hDevice == INVALID_HANDLE_VALUE) { - write_log (L"CreateFile failed with error: %d\n", GetLastError()); - ret = 1; - goto end; - } - - query.PropertyId = StorageAdapterProperty; - query.QueryType = PropertyStandardQuery; - - status = DeviceIoControl( - hDevice, - IOCTL_STORAGE_QUERY_PROPERTY, - &query, - sizeof(STORAGE_PROPERTY_QUERY), - &outBuf, - sizeof (outBuf), - &returnedLength, - NULL - ); - if (!status) { - write_log (L"IOCTL_STORAGE_QUERY_PROPERTY failed with error code %d.\n", GetLastError()); - } else { - adpDesc = (PSTORAGE_ADAPTER_DESCRIPTOR) outBuf; - } - - memset (outBuf, 0, sizeof outBuf); - query.PropertyId = StorageDeviceProperty; - query.QueryType = PropertyStandardQuery; - status = DeviceIoControl( - hDevice, - IOCTL_STORAGE_QUERY_PROPERTY, - &query, - sizeof(STORAGE_PROPERTY_QUERY), - &outBuf, - sizeof outBuf, - &returnedLength, - NULL); - if (!status) { - DWORD err = GetLastError (); - write_log (L"IOCTL_STORAGE_QUERY_PROPERTY failed with error code %d.\n", err); - if (err != ERROR_INVALID_FUNCTION) { - ret = 1; - goto end; - } - nosp = 1; - generatestorageproperty (udi, ignoreduplicates); - } else { - int r; - nosp = 0; - r = getstorageproperty (outBuf, returnedLength, udi, ignoreduplicates); - if (r) { - ret = r; - goto end; - } - } - _tcscpy (orgname, udi->device_name); - udi->bytespersector = 512; - geom_ok = 1; - if (!DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, (void*)&dg, sizeof (dg), &returnedLength, NULL)) { - DWORD err = GetLastError(); - if (isnomediaerr (err)) { - udi->nomedia = 1; - goto amipartfound; - } - write_log (L"IOCTL_DISK_GET_DRIVE_GEOMETRY failed with error code %d.\n", err); - dg.BytesPerSector = 512; - geom_ok = 0; - } - udi->readonly = 0; - if (!DeviceIoControl (hDevice, IOCTL_DISK_IS_WRITABLE, NULL, 0, NULL, 0, &returnedLength, NULL)) { - DWORD err = GetLastError (); - if (err == ERROR_WRITE_PROTECT) - udi->readonly = 1; - } - - gli_ok = 1; - if (!DeviceIoControl (hDevice, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, (void*)&gli, sizeof (gli), &returnedLength, NULL)) { - gli_ok = 0; - write_log (L"IOCTL_DISK_GET_LENGTH_INFO failed with error code %d.\n", GetLastError()); - if (!nosp) - write_log (L"IOCTL_DISK_GET_LENGTH_INFO not supported, detected disk size may not be correct.\n"); - } - if (geom_ok == 0 && gli_ok == 0) { - write_log (L"Can't detect size of device\n"); - ret = 1; - goto end; - } - - udi->offset = 0; - if (geom_ok) { - udi->bytespersector = dg.BytesPerSector; - if (dg.BytesPerSector < 512) { - write_log (L"unsupported blocksize < 512 (%d)\n", dg.BytesPerSector); - ret = 1; - goto end; - } - if (dg.BytesPerSector > 2048) { - write_log (L"unsupported blocksize > 2048 (%d)\n", dg.BytesPerSector); - ret = 1; - goto end; - } - write_log (L"BPS=%d Cyls=%I64d TPC=%d SPT=%d MediaType=%d\n", - dg.BytesPerSector, dg.Cylinders.QuadPart, dg.TracksPerCylinder, dg.SectorsPerTrack, dg.MediaType); - udi->size = (uae_u64)dg.BytesPerSector * (uae_u64)dg.Cylinders.QuadPart * - (uae_u64)dg.TracksPerCylinder * (uae_u64)dg.SectorsPerTrack; - } - if (gli_ok) - udi->size = gli.Length.QuadPart; - write_log (L"device size %I64d (0x%I64x) bytes\n", udi->size, udi->size); - trim (orgname); - - memset (outBuf, 0, sizeof (outBuf)); - status = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, - &outBuf, sizeof (outBuf), &returnedLength, NULL); - if (!status) { - DWORD err = GetLastError(); - write_log (L"IOCTL_DISK_GET_DRIVE_LAYOUT failed with error code %d.\n", err); - if (err != ERROR_INVALID_FUNCTION) { - ret = 1; - goto end; - } - goto amipartfound; - } - dli = (DRIVE_LAYOUT_INFORMATION*)outBuf; - if (dli->PartitionCount) { - struct uae_driveinfo *udi2 = udi; - int nonzeropart = 0; - int gotpart = 0; - int safepart = 0; - write_log (L"%d MBR partitions found\n", dli->PartitionCount); - for (i = 0; i < dli->PartitionCount && (*index2) < MAX_FILESYSTEM_UNITS; i++) { - PARTITION_INFORMATION *pi = &dli->PartitionEntry[i]; - if (pi->PartitionType == PARTITION_ENTRY_UNUSED) - continue; - write_log (L"%d: num: %d type: %02X offset: %I64d size: %I64d, ", i, - pi->PartitionNumber, pi->PartitionType, pi->StartingOffset.QuadPart, pi->PartitionLength.QuadPart); - if (pi->RecognizedPartition == 0) { - write_log (L"unrecognized\n"); - continue; - } - nonzeropart++; - if (pi->PartitionType != 0x76 && pi->PartitionType != 0x30) { - write_log (L"type not 0x76 or 0x30\n"); - continue; - } - memmove (udi, udi2, sizeof (*udi)); - udi->device_name[0] = 0; - udi->offset = pi->StartingOffset.QuadPart; - udi->size = pi->PartitionLength.QuadPart; - write_log (L"used\n"); - _stprintf (udi->device_name, L"HD_P#%d_%s", pi->PartitionNumber, orgname); - udi->dangerous = -5; - udi++; - (*index2)++; - safepart = 1; - gotpart = 1; - } - if (!nonzeropart) { - write_log (L"empty MBR partition table detected, checking for RDB\n"); - } else if (!gotpart) { - write_log (L"non-empty MBR partition table detected, doing RDB check anyway\n"); - } else if (safepart) { - goto amipartfound; /* ugly but bleh.. */ - } - } else { - write_log (L"no MBR partition table detected, checking for RDB\n"); - } - if (udi->offset == 0) { - udi->dangerous = safetycheck (hDevice, udi->device_path, 0, buffer, dg.BytesPerSector); - if (udi->dangerous > 0) - goto end; - } + // + // We have the handle to talk to the device. + // So we can release the interfaceDetailData buffer + // + + + if (hDevice == INVALID_HANDLE_VALUE) { + write_log (L"CreateFile failed with error: %d\n", GetLastError()); + ret = 1; + goto end; + } + + query.PropertyId = StorageAdapterProperty; + query.QueryType = PropertyStandardQuery; + + status = DeviceIoControl( + hDevice, + IOCTL_STORAGE_QUERY_PROPERTY, + &query, + sizeof(STORAGE_PROPERTY_QUERY), + &outBuf, + sizeof (outBuf), + &returnedLength, + NULL + ); + if (!status) { + write_log (L"IOCTL_STORAGE_QUERY_PROPERTY failed with error code %d.\n", GetLastError()); + } else { + adpDesc = (PSTORAGE_ADAPTER_DESCRIPTOR) outBuf; + } + + memset (outBuf, 0, sizeof outBuf); + query.PropertyId = StorageDeviceProperty; + query.QueryType = PropertyStandardQuery; + status = DeviceIoControl( + hDevice, + IOCTL_STORAGE_QUERY_PROPERTY, + &query, + sizeof(STORAGE_PROPERTY_QUERY), + &outBuf, + sizeof outBuf, + &returnedLength, + NULL); + if (!status) { + DWORD err = GetLastError (); + write_log (L"IOCTL_STORAGE_QUERY_PROPERTY failed with error code %d.\n", err); + if (err != ERROR_INVALID_FUNCTION) { + ret = 1; + goto end; + } + nosp = 1; + generatestorageproperty (udi, ignoreduplicates); + } else { + int r; + nosp = 0; + r = getstorageproperty (outBuf, returnedLength, udi, ignoreduplicates); + if (r) { + ret = r; + goto end; + } + } + _tcscpy (orgname, udi->device_name); + udi->bytespersector = 512; + geom_ok = 1; + if (!DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, (void*)&dg, sizeof (dg), &returnedLength, NULL)) { + DWORD err = GetLastError(); + if (isnomediaerr (err)) { + udi->nomedia = 1; + goto amipartfound; + } + write_log (L"IOCTL_DISK_GET_DRIVE_GEOMETRY failed with error code %d.\n", err); + dg.BytesPerSector = 512; + geom_ok = 0; + } + udi->readonly = 0; + if (!DeviceIoControl (hDevice, IOCTL_DISK_IS_WRITABLE, NULL, 0, NULL, 0, &returnedLength, NULL)) { + DWORD err = GetLastError (); + if (err == ERROR_WRITE_PROTECT) + udi->readonly = 1; + } + + gli_ok = 1; + if (!DeviceIoControl (hDevice, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, (void*)&gli, sizeof (gli), &returnedLength, NULL)) { + gli_ok = 0; + write_log (L"IOCTL_DISK_GET_LENGTH_INFO failed with error code %d.\n", GetLastError()); + if (!nosp) + write_log (L"IOCTL_DISK_GET_LENGTH_INFO not supported, detected disk size may not be correct.\n"); + } + if (geom_ok == 0 && gli_ok == 0) { + write_log (L"Can't detect size of device\n"); + ret = 1; + goto end; + } + + udi->offset = 0; + if (geom_ok) { + udi->bytespersector = dg.BytesPerSector; + if (dg.BytesPerSector < 512) { + write_log (L"unsupported blocksize < 512 (%d)\n", dg.BytesPerSector); + ret = 1; + goto end; + } + if (dg.BytesPerSector > 2048) { + write_log (L"unsupported blocksize > 2048 (%d)\n", dg.BytesPerSector); + ret = 1; + goto end; + } + write_log (L"BPS=%d Cyls=%I64d TPC=%d SPT=%d MediaType=%d\n", + dg.BytesPerSector, dg.Cylinders.QuadPart, dg.TracksPerCylinder, dg.SectorsPerTrack, dg.MediaType); + udi->size = (uae_u64)dg.BytesPerSector * (uae_u64)dg.Cylinders.QuadPart * + (uae_u64)dg.TracksPerCylinder * (uae_u64)dg.SectorsPerTrack; + } + if (gli_ok) + udi->size = gli.Length.QuadPart; + write_log (L"device size %I64d (0x%I64x) bytes\n", udi->size, udi->size); + trim (orgname); + + memset (outBuf, 0, sizeof (outBuf)); + status = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, + &outBuf, sizeof (outBuf), &returnedLength, NULL); + if (!status) { + DWORD err = GetLastError(); + write_log (L"IOCTL_DISK_GET_DRIVE_LAYOUT failed with error code %d.\n", err); + if (err != ERROR_INVALID_FUNCTION) { + ret = 1; + goto end; + } + goto amipartfound; + } + dli = (DRIVE_LAYOUT_INFORMATION*)outBuf; + if (dli->PartitionCount) { + struct uae_driveinfo *udi2 = udi; + int nonzeropart = 0; + int gotpart = 0; + int safepart = 0; + write_log (L"%d MBR partitions found\n", dli->PartitionCount); + for (i = 0; i < dli->PartitionCount && (*index2) < MAX_FILESYSTEM_UNITS; i++) { + PARTITION_INFORMATION *pi = &dli->PartitionEntry[i]; + if (pi->PartitionType == PARTITION_ENTRY_UNUSED) + continue; + write_log (L"%d: num: %d type: %02X offset: %I64d size: %I64d, ", i, + pi->PartitionNumber, pi->PartitionType, pi->StartingOffset.QuadPart, pi->PartitionLength.QuadPart); + if (pi->RecognizedPartition == 0) { + write_log (L"unrecognized\n"); + continue; + } + nonzeropart++; + if (pi->PartitionType != 0x76 && pi->PartitionType != 0x30) { + write_log (L"type not 0x76 or 0x30\n"); + continue; + } + memmove (udi, udi2, sizeof (*udi)); + udi->device_name[0] = 0; + udi->offset = pi->StartingOffset.QuadPart; + udi->size = pi->PartitionLength.QuadPart; + write_log (L"used\n"); + _stprintf (udi->device_name, L"HD_P#%d_%s", pi->PartitionNumber, orgname); + udi->dangerous = -5; + udi++; + (*index2)++; + safepart = 1; + gotpart = 1; + } + if (!nonzeropart) { + write_log (L"empty MBR partition table detected, checking for RDB\n"); + } else if (!gotpart) { + write_log (L"non-empty MBR partition table detected, doing RDB check anyway\n"); + } else if (safepart) { + goto amipartfound; /* ugly but bleh.. */ + } + } else { + write_log (L"no MBR partition table detected, checking for RDB\n"); + } + if (udi->offset == 0) { + udi->dangerous = safetycheck (hDevice, udi->device_path, 0, buffer, dg.BytesPerSector); + if (udi->dangerous > 0) + goto end; + } amipartfound: - _stprintf (udi->device_name, L"HD_%s", orgname); - { - int cnt = 1; - int off = _tcslen (udi->device_name); - while (isharddrive (udi->device_name) >= 0) { - udi->device_name[off] = '_'; - udi->device_name[off + 1] = cnt + '0'; - udi->device_name[off + 2] = 0; - cnt++; - } - } - (*index2)++; + _stprintf (udi->device_name, L"HD_%s", orgname); + { + int cnt = 1; + int off = _tcslen (udi->device_name); + while (isharddrive (udi->device_name) >= 0) { + udi->device_name[off] = '_'; + udi->device_name[off + 1] = cnt + '0'; + udi->device_name[off + 2] = 0; + cnt++; + } + } + (*index2)++; end: - if (hDevice != INVALID_HANDLE_VALUE) - CloseHandle (hDevice); - return ret; + if (hDevice != INVALID_HANDLE_VALUE) + CloseHandle (hDevice); + return ret; } /* see MS KB article Q264203 more more information */ static BOOL GetDeviceProperty(HDEVINFO IntDevInfo, DWORD Index, DWORD *index2, uae_u8 *buffer) -/*++ + /*++ -Routine Description: + Routine Description: - This routine enumerates the disk devices using the Device interface - GUID DiskClassGuid. Gets the Adapter & Device property from the port - driver. Then sends IOCTL through SPTI to get the device Inquiry data. + This routine enumerates the disk devices using the Device interface + GUID DiskClassGuid. Gets the Adapter & Device property from the port + driver. Then sends IOCTL through SPTI to get the device Inquiry data. -Arguments: + Arguments: - IntDevInfo - Handles to the interface device information list + IntDevInfo - Handles to the interface device information list - Index - Device member + Index - Device member -Return Value: + Return Value: - TRUE / FALSE. This decides whether to continue or not + TRUE / FALSE. This decides whether to continue or not ---*/ + --*/ { - SP_DEVICE_INTERFACE_DATA interfaceData; - PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = NULL; - BOOL status; - DWORD interfaceDetailDataSize = 0, - reqSize, - errorCode; - int ret = -1; + SP_DEVICE_INTERFACE_DATA interfaceData; + PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData = NULL; + BOOL status; + DWORD interfaceDetailDataSize = 0, + reqSize, + errorCode; + int ret = -1; - interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA); + interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA); - status = SetupDiEnumDeviceInterfaces ( + status = SetupDiEnumDeviceInterfaces ( IntDevInfo, // Interface Device Info handle 0, // Device Info data &GUID_DEVINTERFACE_DISK, // Interface registered by driver @@ -1213,20 +1218,20 @@ Return Value: &interfaceData // Device Interface Data ); - if (status == FALSE) { - errorCode = GetLastError(); - if (errorCode != ERROR_NO_MORE_ITEMS) { - write_log (L"SetupDiEnumDeviceInterfaces failed with error: %d\n", errorCode); + if (status == FALSE) { + errorCode = GetLastError(); + if (errorCode != ERROR_NO_MORE_ITEMS) { + write_log (L"SetupDiEnumDeviceInterfaces failed with error: %d\n", errorCode); + } + ret = 0; + goto end; } - ret = 0; - goto end; - } - // - // Find out required buffer size, so pass NULL - // + // + // Find out required buffer size, so pass NULL + // - status = SetupDiGetDeviceInterfaceDetail ( + status = SetupDiGetDeviceInterfaceDetail ( IntDevInfo, // Interface Device info handle &interfaceData, // Interface data for the event class NULL, // Checking for buffer size @@ -1235,55 +1240,55 @@ Return Value: NULL // Checking for buffer size ); - // - // This call returns ERROR_INSUFFICIENT_BUFFER with reqSize - // set to the required buffer size. Ignore the above error and - // pass a bigger buffer to get the detail data - // - - if (status == FALSE) { - errorCode = GetLastError(); - if (errorCode != ERROR_INSUFFICIENT_BUFFER) { - write_log (L"SetupDiGetDeviceInterfaceDetail failed with error: %d\n", errorCode); - ret = 0; - goto end; - } - } - - // - // Allocate memory to get the interface detail data - // This contains the devicepath we need to open the device - // - - interfaceDetailDataSize = reqSize; - interfaceDetailData = malloc (interfaceDetailDataSize); - if (interfaceDetailData == NULL) { - write_log (L"Unable to allocate memory to get the interface detail data.\n"); - ret = 0; - goto end; - } - interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA); - - status = SetupDiGetDeviceInterfaceDetail ( - IntDevInfo, // Interface Device info handle - &interfaceData, // Interface data for the event class - interfaceDetailData, // Interface detail data - interfaceDetailDataSize, // Interface detail data size - &reqSize, // Buffer size required to get the detail data - NULL); // Interface device info - - if (status == FALSE) { - write_log (L"Error in SetupDiGetDeviceInterfaceDetail failed with error: %d\n", GetLastError()); - ret = 0; - goto end; - } - - ret = GetDevicePropertyFromName (interfaceDetailData->DevicePath, Index, index2, buffer, 0); + // + // This call returns ERROR_INSUFFICIENT_BUFFER with reqSize + // set to the required buffer size. Ignore the above error and + // pass a bigger buffer to get the detail data + // + + if (status == FALSE) { + errorCode = GetLastError(); + if (errorCode != ERROR_INSUFFICIENT_BUFFER) { + write_log (L"SetupDiGetDeviceInterfaceDetail failed with error: %d\n", errorCode); + ret = 0; + goto end; + } + } + + // + // Allocate memory to get the interface detail data + // This contains the devicepath we need to open the device + // + + interfaceDetailDataSize = reqSize; + interfaceDetailData = malloc (interfaceDetailDataSize); + if (interfaceDetailData == NULL) { + write_log (L"Unable to allocate memory to get the interface detail data.\n"); + ret = 0; + goto end; + } + interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA); + + status = SetupDiGetDeviceInterfaceDetail ( + IntDevInfo, // Interface Device info handle + &interfaceData, // Interface data for the event class + interfaceDetailData, // Interface detail data + interfaceDetailDataSize, // Interface detail data size + &reqSize, // Buffer size required to get the detail data + NULL); // Interface device info + + if (status == FALSE) { + write_log (L"Error in SetupDiGetDeviceInterfaceDetail failed with error: %d\n", GetLastError()); + ret = 0; + goto end; + } + + ret = GetDevicePropertyFromName (interfaceDetailData->DevicePath, Index, index2, buffer, 0); end: - free (interfaceDetailData); + free (interfaceDetailData); - return ret; + return ret; } #endif @@ -1296,291 +1301,291 @@ static int num_drives; static int hdf_init2 (int force) { #ifdef WINDDK - HDEVINFO hIntDevInfo; + HDEVINFO hIntDevInfo; #endif - DWORD index = 0, index2 = 0, drive; - uae_u8 *buffer; - UINT errormode; - DWORD dwDriveMask; - static int done; - - if (done && !force) - return num_drives; - done = 1; - num_drives = 0; -#ifdef WINDDK - buffer = VirtualAlloc (NULL, 65536, MEM_COMMIT, PAGE_READWRITE); - if (buffer) { - errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); - memset (uae_drives, 0, sizeof (uae_drives)); + DWORD index = 0, index2 = 0, drive; + uae_u8 *buffer; + UINT errormode; + DWORD dwDriveMask; + static int done; + + if (done && !force) + return num_drives; + done = 1; num_drives = 0; - hIntDevInfo = SetupDiGetClassDevs (&GUID_DEVINTERFACE_DISK, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); - if (hIntDevInfo != INVALID_HANDLE_VALUE) { - while (index < MAX_FILESYSTEM_UNITS) { - memset (uae_drives + index2, 0, sizeof (struct uae_driveinfo)); - if (!GetDeviceProperty (hIntDevInfo, index, &index2, buffer)) - break; - index++; - num_drives = index2; - } - SetupDiDestroyDeviceInfoList (hIntDevInfo); - } - dwDriveMask = GetLogicalDrives (); - for(drive = 'A'; drive <= 'Z'; drive++) { - if((dwDriveMask & 1) && (drive >= 'C' || usefloppydrives)) { - TCHAR tmp1[20], tmp2[20]; - DWORD drivetype; - _stprintf (tmp1, L"%c:\\", drive); - drivetype = GetDriveType (tmp1); - if (drivetype != DRIVE_REMOTE) { - _stprintf (tmp2, L"\\\\.\\%c:", drive); - GetDevicePropertyFromName (tmp2, index, &index2, buffer, 1); - num_drives = index2; +#ifdef WINDDK + buffer = VirtualAlloc (NULL, 65536, MEM_COMMIT, PAGE_READWRITE); + if (buffer) { + errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + memset (uae_drives, 0, sizeof (uae_drives)); + num_drives = 0; + hIntDevInfo = SetupDiGetClassDevs (&GUID_DEVINTERFACE_DISK, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); + if (hIntDevInfo != INVALID_HANDLE_VALUE) { + while (index < MAX_FILESYSTEM_UNITS) { + memset (uae_drives + index2, 0, sizeof (struct uae_driveinfo)); + if (!GetDeviceProperty (hIntDevInfo, index, &index2, buffer)) + break; + index++; + num_drives = index2; + } + SetupDiDestroyDeviceInfoList (hIntDevInfo); } - } - dwDriveMask >>= 1; - } - SetErrorMode (errormode); + dwDriveMask = GetLogicalDrives (); + for(drive = 'A'; drive <= 'Z'; drive++) { + if((dwDriveMask & 1) && (drive >= 'C' || usefloppydrives)) { + TCHAR tmp1[20], tmp2[20]; + DWORD drivetype; + _stprintf (tmp1, L"%c:\\", drive); + drivetype = GetDriveType (tmp1); + if (drivetype != DRIVE_REMOTE) { + _stprintf (tmp2, L"\\\\.\\%c:", drive); + GetDevicePropertyFromName (tmp2, index, &index2, buffer, 1); + num_drives = index2; + } + } + dwDriveMask >>= 1; + } + SetErrorMode (errormode); #if 0 - hIntDevInfo = SetupDiGetClassDevs (&GUID_DEVCLASS_MTD, NULL, NULL, DIGCF_PRESENT); - if (hIntDevInfo != INVALID_HANDLE_VALUE) { - while (index < MAX_FILESYSTEM_UNITS) { - memset (uae_drives + index2, 0, sizeof (struct uae_driveinfo)); - index++; - num_drives = index2; - } - SetupDiDestroyDeviceInfoList(hIntDevInfo); - } + hIntDevInfo = SetupDiGetClassDevs (&GUID_DEVCLASS_MTD, NULL, NULL, DIGCF_PRESENT); + if (hIntDevInfo != INVALID_HANDLE_VALUE) { + while (index < MAX_FILESYSTEM_UNITS) { + memset (uae_drives + index2, 0, sizeof (struct uae_driveinfo)); + index++; + num_drives = index2; + } + SetupDiDestroyDeviceInfoList(hIntDevInfo); + } #endif - VirtualFree (buffer, 0, MEM_RELEASE); - } - num_drives = index2; - write_log (L"Drive scan result: %d drives detected\n", num_drives); + VirtualFree (buffer, 0, MEM_RELEASE); + } + num_drives = index2; + write_log (L"Drive scan result: %d drives detected\n", num_drives); #endif - return num_drives; + return num_drives; } int hdf_init_target (void) { - return hdf_init2 (0); + return hdf_init2 (0); } int hdf_getnumharddrives (void) { - return num_drives; + return num_drives; } TCHAR *hdf_getnameharddrive (int index, int flags, int *sectorsize, int *dangerousdrive) { - static TCHAR name[512]; - TCHAR tmp[32]; - uae_u64 size = uae_drives[index].size; - int nomedia = uae_drives[index].nomedia; - TCHAR *dang = L"?"; - TCHAR *rw = L"RW"; - - if (dangerousdrive) - *dangerousdrive = 0; - switch (uae_drives[index].dangerous) - { + static TCHAR name[512]; + TCHAR tmp[32]; + uae_u64 size = uae_drives[index].size; + int nomedia = uae_drives[index].nomedia; + TCHAR *dang = L"?"; + TCHAR *rw = L"RW"; + + if (dangerousdrive) + *dangerousdrive = 0; + switch (uae_drives[index].dangerous) + { case -5: - dang = L"[PART]"; - break; + dang = L"[PART]"; + break; case -6: - dang = L"[MBR]"; - break; + dang = L"[MBR]"; + break; case -7: - dang = L"[!]"; - break; + dang = L"[!]"; + break; case -8: - dang = L"[UNK]"; - break; + dang = L"[UNK]"; + break; case -9: - dang = L"[EMPTY]"; - break; + dang = L"[EMPTY]"; + break; case -3: - dang = L"(CPRM)"; - break; + dang = L"(CPRM)"; + break; case -2: - dang = L"(SRAM)"; - break; + dang = L"(SRAM)"; + break; case -1: - dang = L"(RDB)"; - break; + dang = L"(RDB)"; + break; case 0: - dang = L"[OS]"; - if (dangerousdrive) - *dangerousdrive |= 1; - break; - } - if (nomedia) { - dang = L"[NO MEDIA]"; - if (dangerousdrive) - *dangerousdrive &= ~1; - } - if (uae_drives[index].readonly) { - rw = L"RO"; - if (dangerousdrive && !nomedia) - *dangerousdrive |= 2; - } - - if (sectorsize) - *sectorsize = uae_drives[index].bytespersector; - if (flags & 1) { + dang = L"[OS]"; + if (dangerousdrive) + *dangerousdrive |= 1; + break; + } if (nomedia) { - _tcscpy (tmp, L"N/A"); - } else { - if (size >= 1024 * 1024 * 1024) - _stprintf (tmp, L"%.1fG", ((double)(uae_u32)(size / (1024 * 1024))) / 1024.0); - else if (size < 10 * 1024 * 1024) - _stprintf (tmp, L"%dK", size / 1024); - else - _stprintf (tmp, L"%.1fM", ((double)(uae_u32)(size / (1024))) / 1024.0); - } - _stprintf (name, L"%10s [%s,%s] %s", dang, tmp, rw, uae_drives[index].device_name + 3); - return name; - } - if (flags & 2) - return uae_drives[index].device_path; - return uae_drives[index].device_name; + dang = L"[NO MEDIA]"; + if (dangerousdrive) + *dangerousdrive &= ~1; + } + if (uae_drives[index].readonly) { + rw = L"RO"; + if (dangerousdrive && !nomedia) + *dangerousdrive |= 2; + } + + if (sectorsize) + *sectorsize = uae_drives[index].bytespersector; + if (flags & 1) { + if (nomedia) { + _tcscpy (tmp, L"N/A"); + } else { + if (size >= 1024 * 1024 * 1024) + _stprintf (tmp, L"%.1fG", ((double)(uae_u32)(size / (1024 * 1024))) / 1024.0); + else if (size < 10 * 1024 * 1024) + _stprintf (tmp, L"%dK", size / 1024); + else + _stprintf (tmp, L"%.1fM", ((double)(uae_u32)(size / (1024))) / 1024.0); + } + _stprintf (name, L"%10s [%s,%s] %s", dang, tmp, rw, uae_drives[index].device_name + 3); + return name; + } + if (flags & 2) + return uae_drives[index].device_path; + return uae_drives[index].device_name; } static int hmc (struct hardfiledata *hfd) { - uae_u8 *buf = xmalloc (hfd->blocksize); - DWORD ret, got, err, status; - int first = 1; - - while (hfd->handle_valid) { - DWORD errormode; - write_log (L"testing if %s has media inserted\n", hfd->emptyname); - status = 0; - errormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); - SetFilePointer (hfd->handle, 0, NULL, FILE_BEGIN); - ret = ReadFile (hfd->handle, buf, hfd->blocksize, &got, NULL); - err = GetLastError (); - SetErrorMode(errormode); - if (ret) { - if (got == hfd->blocksize) { - write_log (L"read ok (%d)\n", got); - } else { - write_log (L"read ok but no data (%d)\n", hfd->blocksize); - ret = 0; - err = 0; - } - } else { - write_log (L"=%d\n", err); - } - if (!ret && (err == ERROR_DEV_NOT_EXIST || err == ERROR_WRONG_DISK)) { - if (!first) + uae_u8 *buf = xmalloc (hfd->blocksize); + DWORD ret, got, err, status; + int first = 1; + + while (hfd->handle_valid) { + DWORD errormode; + write_log (L"testing if %s has media inserted\n", hfd->emptyname); + status = 0; + errormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + SetFilePointer (hfd->handle, 0, NULL, FILE_BEGIN); + ret = ReadFile (hfd->handle, buf, hfd->blocksize, &got, NULL); + err = GetLastError (); + SetErrorMode(errormode); + if (ret) { + if (got == hfd->blocksize) { + write_log (L"read ok (%d)\n", got); + } else { + write_log (L"read ok but no data (%d)\n", hfd->blocksize); + ret = 0; + err = 0; + } + } else { + write_log (L"=%d\n", err); + } + if (!ret && (err == ERROR_DEV_NOT_EXIST || err == ERROR_WRONG_DISK)) { + if (!first) + break; + first = 0; + hdf_open (hfd, hfd->emptyname); + if (!hfd->handle_valid) { + /* whole device has disappeared */ + status = -1; + goto end; + } + continue; + } break; - first = 0; - hdf_open (hfd, hfd->emptyname); - if (!hfd->handle_valid) { - /* whole device has disappeared */ + } + if (ret && hfd->drive_empty) + status = 1; + if (!ret && !hfd->drive_empty && isnomediaerr (err)) status = -1; - goto end; - } - continue; - } - break; - } - if (ret && hfd->drive_empty) - status = 1; - if (!ret && !hfd->drive_empty && isnomediaerr (err)) - status = -1; end: - xfree (buf); - write_log (L"hmc returned %d\n", status); - return status; + xfree (buf); + write_log (L"hmc returned %d\n", status); + return status; } int hardfile_remount (int nr); static void hmc_check (struct hardfiledata *hfd, struct uaedev_config_info *uci, int *rescanned, int *reopen, - int *gotinsert, const TCHAR *drvname, int inserted) + int *gotinsert, const TCHAR *drvname, int inserted) { - int ret; - - if (!hfd || !hfd->emptyname) - return; - if (*rescanned == 0) { - hdf_init2 (1); - *rescanned = 1; - } - if (hfd->emptyname && _tcslen (hfd->emptyname) >= 6 && drvname && _tcslen (drvname) == 3 && drvname[1] == ':' && drvname[2] == '\\' && !inserted) { /* drive letter check */ - TCHAR tmp[10], *p; - _stprintf (tmp, L"\\\\.\\%c:", drvname[0]); - p = hfd->emptyname + _tcslen (hfd->emptyname) - 6; - write_log( L"workaround-remove test: '%s' and '%s'\n", p, drvname); - if (!_tcscmp (tmp, p)) { - TCHAR *en = my_strdup (hfd->emptyname); - write_log (L"workaround-remove done\n"); - hdf_close (hfd); - hfd->emptyname = en; - hfd->drive_empty = 1; - hardfile_do_disk_change (uci, 0); - return; - } - } - - if (hfd->drive_empty < 0 || !hfd->handle_valid) { - int empty = hfd->drive_empty; - int r; - //write_log (L"trying to open '%s' de=%d hv=%d\n", hfd->emptyname, hfd->drive_empty, hfd->handle_valid); - r = hdf_open (hfd, hfd->emptyname); - //write_log (L"=%d\n", r); - if (!r) - return; - *reopen = 1; - if (hfd->drive_empty < 0) - return; - hfd->drive_empty = empty ? 1 : 0; - } - ret = hmc (hfd); - if (!ret) - return; - if (ret > 0) { - if (*reopen == 0) { - hdf_open (hfd, hfd->emptyname); - if (!hfd->handle_valid) - return; - } - *gotinsert = 1; - //hardfile_remount (uci); - } - hardfile_do_disk_change (uci, ret < 0 ? 0 : 1); + int ret; + + if (!hfd || !hfd->emptyname) + return; + if (*rescanned == 0) { + hdf_init2 (1); + *rescanned = 1; + } + if (hfd->emptyname && _tcslen (hfd->emptyname) >= 6 && drvname && _tcslen (drvname) == 3 && drvname[1] == ':' && drvname[2] == '\\' && !inserted) { /* drive letter check */ + TCHAR tmp[10], *p; + _stprintf (tmp, L"\\\\.\\%c:", drvname[0]); + p = hfd->emptyname + _tcslen (hfd->emptyname) - 6; + write_log( L"workaround-remove test: '%s' and '%s'\n", p, drvname); + if (!_tcscmp (tmp, p)) { + TCHAR *en = my_strdup (hfd->emptyname); + write_log (L"workaround-remove done\n"); + hdf_close (hfd); + hfd->emptyname = en; + hfd->drive_empty = 1; + hardfile_do_disk_change (uci, 0); + return; + } + } + + if (hfd->drive_empty < 0 || !hfd->handle_valid) { + int empty = hfd->drive_empty; + int r; + //write_log (L"trying to open '%s' de=%d hv=%d\n", hfd->emptyname, hfd->drive_empty, hfd->handle_valid); + r = hdf_open (hfd, hfd->emptyname); + //write_log (L"=%d\n", r); + if (!r) + return; + *reopen = 1; + if (hfd->drive_empty < 0) + return; + hfd->drive_empty = empty ? 1 : 0; + } + ret = hmc (hfd); + if (!ret) + return; + if (ret > 0) { + if (*reopen == 0) { + hdf_open (hfd, hfd->emptyname); + if (!hfd->handle_valid) + return; + } + *gotinsert = 1; + //hardfile_remount (uci); + } + hardfile_do_disk_change (uci, ret < 0 ? 0 : 1); } int win32_hardfile_media_change (const TCHAR *drvname, int inserted) { - int gotinsert = 0, rescanned = 0; - int i, j; - - for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { - struct hardfiledata *hfd = get_hardfile_data (i); - int reopen = 0; - if (!hfd || !(hfd->flags & HFD_FLAGS_REALDRIVE)) - continue; - for (j = 0; j < currprefs.mountitems; j++) { - if (currprefs.mountconfig[j].configoffset == i) { - hmc_check (hfd, &currprefs.mountconfig[j], &rescanned, &reopen, &gotinsert, drvname, inserted); - break; - } + int gotinsert = 0, rescanned = 0; + int i, j; + + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { + struct hardfiledata *hfd = get_hardfile_data (i); + int reopen = 0; + if (!hfd || !(hfd->flags & HFD_FLAGS_REALDRIVE)) + continue; + for (j = 0; j < currprefs.mountitems; j++) { + if (currprefs.mountconfig[j].configoffset == i) { + hmc_check (hfd, &currprefs.mountconfig[j], &rescanned, &reopen, &gotinsert, drvname, inserted); + break; + } + } } - } - for (i = 0; i < currprefs.mountitems; i++) { - extern struct hd_hardfiledata *pcmcia_sram; - int reopen = 0; - struct uaedev_config_info *uci = &currprefs.mountconfig[i]; - if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { - hmc_check (&pcmcia_sram->hfd, uci, &rescanned, &reopen, &gotinsert, drvname, inserted); + for (i = 0; i < currprefs.mountitems; i++) { + extern struct hd_hardfiledata *pcmcia_sram; + int reopen = 0; + struct uaedev_config_info *uci = &currprefs.mountconfig[i]; + if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { + hmc_check (&pcmcia_sram->hfd, uci, &rescanned, &reopen, &gotinsert, drvname, inserted); + } } - } - //write_log (L"win32_hardfile_media_change returned %d\n", gotinsert); - return gotinsert; + //write_log (L"win32_hardfile_media_change returned %d\n", gotinsert); + return gotinsert; } static int progressdialogreturn; @@ -1588,30 +1593,30 @@ static int progressdialogactive; static INT_PTR CALLBACK ProgressDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch(msg) + { case WM_DESTROY: - PostQuitMessage (0); - progressdialogactive = 0; - return TRUE; + PostQuitMessage (0); + progressdialogactive = 0; + return TRUE; case WM_CLOSE: - DestroyWindow(hDlg); - if (progressdialogreturn < 0) - progressdialogreturn = 0; - return TRUE; + DestroyWindow(hDlg); + if (progressdialogreturn < 0) + progressdialogreturn = 0; + return TRUE; case WM_INITDIALOG: - return TRUE; + return TRUE; case WM_COMMAND: - switch (LOWORD(wParam)) - { + switch (LOWORD(wParam)) + { case IDCANCEL: - progressdialogreturn = 0; - DestroyWindow (hDlg); - return TRUE; - } - break; - } - return FALSE; + progressdialogreturn = 0; + DestroyWindow (hDlg); + return TRUE; + } + break; + } + return FALSE; } extern HMODULE hUIDLL; @@ -1620,137 +1625,137 @@ extern HINSTANCE hInst; #define COPY_CACHE_SIZE 1024*1024 int harddrive_to_hdf (HWND hDlg, struct uae_prefs *p, int idx) { - HANDLE h = INVALID_HANDLE_VALUE, hdst = INVALID_HANDLE_VALUE; - void *cache = NULL; - DWORD ret, got, gotdst, get; - uae_u64 size, sizecnt, written; - LARGE_INTEGER li; - TCHAR path[MAX_DPATH], tmp[MAX_DPATH], tmp2[MAX_DPATH]; - DWORD retcode = 0; - HWND hwnd, hwndprogress, hwndprogresstxt; - MSG msg; - int pct, cnt; - - cache = VirtualAlloc (NULL, COPY_CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); - if (!cache) - goto err; - h = CreateFile (uae_drives[idx].device_path, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_NO_BUFFERING, NULL); - if (h == INVALID_HANDLE_VALUE) - goto err; - size = uae_drives[idx].size; - path[0] = 0; - DiskSelection (hDlg, IDC_PATH_NAME, 3, p, 0); - GetDlgItemText (hDlg, IDC_PATH_NAME, path, MAX_DPATH); - if (*path == 0) - goto err; - hdst = CreateFile (path, GENERIC_WRITE, 0, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_NO_BUFFERING, NULL); - if (hdst == INVALID_HANDLE_VALUE) - goto err; - li.QuadPart = size; - ret = SetFilePointer (hdst, li.LowPart, &li.HighPart, FILE_BEGIN); - if (ret == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) - goto err; - if (!SetEndOfFile (hdst)) - goto err; - li.QuadPart = 0; - SetFilePointer (hdst, 0, &li.HighPart, FILE_BEGIN); - li.QuadPart = 0; - SetFilePointer (h, 0, &li.HighPart, FILE_BEGIN); - progressdialogreturn = -1; - progressdialogactive = 1; - hwnd = CreateDialog (hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_PROGRESSBAR), hDlg, ProgressDialogProc); - if (hwnd == NULL) - goto err; - hwndprogress = GetDlgItem (hwnd, IDC_PROGRESSBAR); - hwndprogresstxt = GetDlgItem (hwnd, IDC_PROGRESSBAR_TEXT); - ShowWindow (hwnd, SW_SHOW); - pct = 0; - cnt = 1000; - sizecnt = 0; - written = 0; - for (;;) { - if (progressdialogreturn >= 0) - break; - if (cnt > 0) { - SendMessage (hwndprogress, PBM_SETPOS, (WPARAM)pct, 0); - _stprintf (tmp, L"%dM / %dM (%d%%)", (int)(written >> 20), (int)(size >> 20), pct); - SendMessage (hwndprogresstxt, WM_SETTEXT, 0, (LPARAM)tmp); - while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - cnt = 0; - } - got = gotdst = 0; - li.QuadPart = sizecnt; - if (SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - DWORD err = GetLastError (); - if (err != NO_ERROR) { - progressdialogreturn = 3; - break; - } - } - get = COPY_CACHE_SIZE; - if (sizecnt + get > size) - get = size - sizecnt; - if (!ReadFile (h, cache, get, &got, NULL)) { - progressdialogreturn = 4; - break; - } - if (get != got) { - progressdialogreturn = 5; - break; - } - if (got > 0) { - if (written + got > size) - got = size - written; - if (!WriteFile (hdst, cache, got, &gotdst, NULL)) { - progressdialogreturn = 5; - break; - } - written += gotdst; - if (written == size) - break; - } - if (got != COPY_CACHE_SIZE) { - progressdialogreturn = 1; - break; + HANDLE h = INVALID_HANDLE_VALUE, hdst = INVALID_HANDLE_VALUE; + void *cache = NULL; + DWORD ret, got, gotdst, get; + uae_u64 size, sizecnt, written; + LARGE_INTEGER li; + TCHAR path[MAX_DPATH], tmp[MAX_DPATH], tmp2[MAX_DPATH]; + DWORD retcode = 0; + HWND hwnd, hwndprogress, hwndprogresstxt; + MSG msg; + int pct, cnt; + + cache = VirtualAlloc (NULL, COPY_CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE); + if (!cache) + goto err; + h = CreateFile (uae_drives[idx].device_path, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_NO_BUFFERING, NULL); + if (h == INVALID_HANDLE_VALUE) + goto err; + size = uae_drives[idx].size; + path[0] = 0; + DiskSelection (hDlg, IDC_PATH_NAME, 3, p, 0); + GetDlgItemText (hDlg, IDC_PATH_NAME, path, MAX_DPATH); + if (*path == 0) + goto err; + hdst = CreateFile (path, GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_NO_BUFFERING, NULL); + if (hdst == INVALID_HANDLE_VALUE) + goto err; + li.QuadPart = size; + ret = SetFilePointer (hdst, li.LowPart, &li.HighPart, FILE_BEGIN); + if (ret == INVALID_FILE_SIZE && GetLastError () != NO_ERROR) + goto err; + if (!SetEndOfFile (hdst)) + goto err; + li.QuadPart = 0; + SetFilePointer (hdst, 0, &li.HighPart, FILE_BEGIN); + li.QuadPart = 0; + SetFilePointer (h, 0, &li.HighPart, FILE_BEGIN); + progressdialogreturn = -1; + progressdialogactive = 1; + hwnd = CreateDialog (hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDD_PROGRESSBAR), hDlg, ProgressDialogProc); + if (hwnd == NULL) + goto err; + hwndprogress = GetDlgItem (hwnd, IDC_PROGRESSBAR); + hwndprogresstxt = GetDlgItem (hwnd, IDC_PROGRESSBAR_TEXT); + ShowWindow (hwnd, SW_SHOW); + pct = 0; + cnt = 1000; + sizecnt = 0; + written = 0; + for (;;) { + if (progressdialogreturn >= 0) + break; + if (cnt > 0) { + SendMessage (hwndprogress, PBM_SETPOS, (WPARAM)pct, 0); + _stprintf (tmp, L"%dM / %dM (%d%%)", (int)(written >> 20), (int)(size >> 20), pct); + SendMessage (hwndprogresstxt, WM_SETTEXT, 0, (LPARAM)tmp); + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + cnt = 0; + } + got = gotdst = 0; + li.QuadPart = sizecnt; + if (SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { + DWORD err = GetLastError (); + if (err != NO_ERROR) { + progressdialogreturn = 3; + break; + } + } + get = COPY_CACHE_SIZE; + if (sizecnt + get > size) + get = size - sizecnt; + if (!ReadFile (h, cache, get, &got, NULL)) { + progressdialogreturn = 4; + break; + } + if (get != got) { + progressdialogreturn = 5; + break; + } + if (got > 0) { + if (written + got > size) + got = size - written; + if (!WriteFile (hdst, cache, got, &gotdst, NULL)) { + progressdialogreturn = 5; + break; + } + written += gotdst; + if (written == size) + break; + } + if (got != COPY_CACHE_SIZE) { + progressdialogreturn = 1; + break; + } + if (got != gotdst) { + progressdialogreturn = 2; + break; + } + cnt++; + sizecnt += got; + pct = (int)(sizecnt * 100 / size); } - if (got != gotdst) { - progressdialogreturn = 2; - break; + if (progressdialogactive) { + DestroyWindow (hwnd); + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage (&msg); + DispatchMessage (&msg); + } } - cnt++; - sizecnt += got; - pct = (int)(sizecnt * 100 / size); - } - if (progressdialogactive) { - DestroyWindow (hwnd); - while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - } - if (progressdialogreturn >= 0) - goto err; - retcode = 1; - WIN32GUI_LoadUIString (IDS_HDCLONE_OK, tmp, MAX_DPATH); - gui_message (tmp); - goto ok; + if (progressdialogreturn >= 0) + goto err; + retcode = 1; + WIN32GUI_LoadUIString (IDS_HDCLONE_OK, tmp, MAX_DPATH); + gui_message (tmp); + goto ok; err: - WIN32GUI_LoadUIString (IDS_HDCLONE_FAIL, tmp, MAX_DPATH); - _stprintf (tmp2, tmp, progressdialogreturn, GetLastError()); - gui_message (tmp2); + WIN32GUI_LoadUIString (IDS_HDCLONE_FAIL, tmp, MAX_DPATH); + _stprintf (tmp2, tmp, progressdialogreturn, GetLastError()); + gui_message (tmp2); ok: - if (h != INVALID_HANDLE_VALUE) - CloseHandle (h); - if (cache) - VirtualFree (cache, 0, MEM_RELEASE); - if (hdst != INVALID_HANDLE_VALUE) - CloseHandle (hdst); - return retcode; + if (h != INVALID_HANDLE_VALUE) + CloseHandle (h); + if (cache) + VirtualFree (cache, 0, MEM_RELEASE); + if (hdst != INVALID_HANDLE_VALUE) + CloseHandle (hdst); + return retcode; } diff --git a/od-win32/ioport.c b/od-win32/ioport.c index 1e444787..6dc1cd05 100644 --- a/od-win32/ioport.c +++ b/od-win32/ioport.c @@ -46,104 +46,104 @@ static int initialized; int ioport_init (void) { - if (initialized) - return initialized > 0 ? 1 : 0; + if (initialized) + return initialized > 0 ? 1 : 0; #ifndef IOPORT_EMU - ioh = WIN32_LoadLibrary (L"tvicport.dll"); - if (ioh) { - for (;;) { - pOpenTVicPort = (OPENTVICPORT)GetProcAddress (ioh, "OpenTVicPort"); - pCloseTVicPort = (CLOSETVICPORT)GetProcAddress (ioh, "CloseTVicPort"); - pIsDriverOpened = (ISDRIVEROPENED)GetProcAddress (ioh, "IsDriverOpened"); - pReadPort = (READPORT)GetProcAddress (ioh, "ReadPort"); - pWritePort = (WRITEPORT)GetProcAddress (ioh, "WritePort"); - if (!pOpenTVicPort || !pCloseTVicPort || !pIsDriverOpened || !pReadPort || !pWritePort) { - write_log (L"IO: incompatible tvicport.dll\n"); - break; - } - if (!pOpenTVicPort()) { - write_log (L"IO: tvicport.dll failed to initialize\n"); - break; - } - if (!pIsDriverOpened()) { - write_log (L"IO: tvicport.dll failed to initialize!\n"); - pCloseTVicPort(); - break; - } - initialized = 1; - write_log (L"IO: tvicport.dll initialized\n"); - return 1; + ioh = WIN32_LoadLibrary (L"tvicport.dll"); + if (ioh) { + for (;;) { + pOpenTVicPort = (OPENTVICPORT)GetProcAddress (ioh, "OpenTVicPort"); + pCloseTVicPort = (CLOSETVICPORT)GetProcAddress (ioh, "CloseTVicPort"); + pIsDriverOpened = (ISDRIVEROPENED)GetProcAddress (ioh, "IsDriverOpened"); + pReadPort = (READPORT)GetProcAddress (ioh, "ReadPort"); + pWritePort = (WRITEPORT)GetProcAddress (ioh, "WritePort"); + if (!pOpenTVicPort || !pCloseTVicPort || !pIsDriverOpened || !pReadPort || !pWritePort) { + write_log (L"IO: incompatible tvicport.dll\n"); + break; + } + if (!pOpenTVicPort()) { + write_log (L"IO: tvicport.dll failed to initialize\n"); + break; + } + if (!pIsDriverOpened()) { + write_log (L"IO: tvicport.dll failed to initialize!\n"); + pCloseTVicPort(); + break; + } + initialized = 1; + write_log (L"IO: tvicport.dll initialized\n"); + return 1; + } } - } - FreeLibrary(ioh); - ioh = WIN32_LoadLibrary (L"winio.dll"); - if (ioh) { - for (;;) { - pInitializeWinIo = (INITIALIZEWINIO)GetProcAddress (ioh, "InitializeWinIo"); - pShutdownWinIo = (SHUTDOWNWINIO)GetProcAddress (ioh, "ShutdownWinIo"); - pGetPortVal = (GETPORTVAL)GetProcAddress (ioh, "GetPortVal"); - pSetPortVal = (SETPORTVAL)GetProcAddress (ioh, "SetPortVal"); - if (!pInitializeWinIo || !pShutdownWinIo || !pGetPortVal || !pSetPortVal) { - write_log (L"IO: incompatible winio.dll\n"); - break; - } - __try { - initialized = pInitializeWinIo() ? 2 : 0; - } __except (EXCEPTION_EXECUTE_HANDLER) { - write_log (L"IO: winio.dll initialization failed\n"); - } - if (!initialized) - break; - write_log (L"IO: winio.dll initialized\n"); - return 1; + FreeLibrary(ioh); + ioh = WIN32_LoadLibrary (L"winio.dll"); + if (ioh) { + for (;;) { + pInitializeWinIo = (INITIALIZEWINIO)GetProcAddress (ioh, "InitializeWinIo"); + pShutdownWinIo = (SHUTDOWNWINIO)GetProcAddress (ioh, "ShutdownWinIo"); + pGetPortVal = (GETPORTVAL)GetProcAddress (ioh, "GetPortVal"); + pSetPortVal = (SETPORTVAL)GetProcAddress (ioh, "SetPortVal"); + if (!pInitializeWinIo || !pShutdownWinIo || !pGetPortVal || !pSetPortVal) { + write_log (L"IO: incompatible winio.dll\n"); + break; + } + __try { + initialized = pInitializeWinIo() ? 2 : 0; + } __except (EXCEPTION_EXECUTE_HANDLER) { + write_log (L"IO: winio.dll initialization failed\n"); + } + if (!initialized) + break; + write_log (L"IO: winio.dll initialized\n"); + return 1; + } } - } - FreeLibrary(ioh); - initialized = -1; - write_log (L"IO: tvicport.dll or winio.dll failed to initialize\n"); - return 0; + FreeLibrary(ioh); + initialized = -1; + write_log (L"IO: tvicport.dll or winio.dll failed to initialize\n"); + return 0; #else - initialized = 1; - return 1; + initialized = 1; + return 1; #endif } void ioport_free (void) { #ifndef IOPORT_EMU - if (initialized == 1) - pCloseTVicPort(); - if (initialized == 2) - pShutdownWinIo(); - if (initialized) - FreeLibrary (ioh); + if (initialized == 1) + pCloseTVicPort(); + if (initialized == 2) + pShutdownWinIo(); + if (initialized) + FreeLibrary (ioh); #endif - initialized = 0; + initialized = 0; } uae_u8 ioport_read (int port) { - DWORD v = 0; + DWORD v = 0; #ifndef IOPORT_EMU - if (initialized == 1) - v = pReadPort (port); - else if (initialized == 2) - pGetPortVal (port, &v, 1); + if (initialized == 1) + v = pReadPort (port); + else if (initialized == 2) + pGetPortVal (port, &v, 1); #endif - io_log ("ioport_read %04X returned %02X\n", port, v); - return (uae_u8)v; + io_log ("ioport_read %04X returned %02X\n", port, v); + return (uae_u8)v; } void ioport_write (int port, uae_u8 v) { #ifndef IOPORT_EMU - if (initialized == 1) - pWritePort (port, v); - else if (initialized == 2) - pSetPortVal (port, v, 1); + if (initialized == 1) + pWritePort (port, v); + else if (initialized == 2) + pSetPortVal (port, v, 1); #endif - io_log ("ioport_write %04X %02X\n", port, v); + io_log ("ioport_write %04X %02X\n", port, v); } @@ -174,200 +174,200 @@ static HANDLE pport; void paraport_free (void) { - if (para) { - if (pport) - pp_closeport (pport); - pport = 0; - FreeLibrary (para); - para = 0; - } + if (para) { + if (pport) + pp_closeport (pport); + pport = 0; + FreeLibrary (para); + para = 0; + } } int paraport_init (void) { - int mask = 0, i; - HANDLE pp; + int mask = 0, i; + HANDLE pp; - paraport_free (); - para = WIN32_LoadLibrary(L"ParaPort.dll"); - if (!para) { - write_log (L"PARAPORT: no ParaPort.dll, direct parallel port emulation disabled\n"); - return 0; - } - pp_closeport = (closePort)GetProcAddress (para, "closePort"); - pp_executecycle = (executeCycle)GetProcAddress (para, "executeCycle"); - pp_getportinfo = (getPortInfo)GetProcAddress (para, "getPortInfo"); - pp_openport = (openPort)GetProcAddress (para, "openPort"); - if (!pp_openport || !pp_closeport || !pp_executecycle) { - write_log (L"PARAPORT: GetProcAddress() failed\n"); paraport_free (); - } - write_log (L"PARAPORT:"); - for (i = 0; i < 4 ; i++) { - char tmp[10]; - sprintf (tmp, "LPT%d", i + 1); - pp = pp_openport (tmp); - if (pp != INVALID_HANDLE_VALUE) { - mask |= 1 << i; - pp_closeport (pp); + para = WIN32_LoadLibrary(L"ParaPort.dll"); + if (!para) { + write_log (L"PARAPORT: no ParaPort.dll, direct parallel port emulation disabled\n"); + return 0; + } + pp_closeport = (closePort)GetProcAddress (para, "closePort"); + pp_executecycle = (executeCycle)GetProcAddress (para, "executeCycle"); + pp_getportinfo = (getPortInfo)GetProcAddress (para, "getPortInfo"); + pp_openport = (openPort)GetProcAddress (para, "openPort"); + if (!pp_openport || !pp_closeport || !pp_executecycle) { + write_log (L"PARAPORT: GetProcAddress() failed\n"); + paraport_free (); } - pp = 0; - } - if (!mask) - write_log (L"no parallel ports detected"); - write_log (L"\n"); - return mask; + write_log (L"PARAPORT:"); + for (i = 0; i < 4 ; i++) { + char tmp[10]; + sprintf (tmp, "LPT%d", i + 1); + pp = pp_openport (tmp); + if (pp != INVALID_HANDLE_VALUE) { + mask |= 1 << i; + pp_closeport (pp); + } + pp = 0; + } + if (!mask) + write_log (L"no parallel ports detected"); + write_log (L"\n"); + return mask; } int paraport_open (TCHAR *port) { - static TCHAR oldport[10]; - PARAPORT_CYCLE c[1]; - char *port2; - - if (!para) - return 0; - if (pport && !_tcscmp (port, oldport)) + static TCHAR oldport[10]; + PARAPORT_CYCLE c[1]; + char *port2; + + if (!para) + return 0; + if (pport && !_tcscmp (port, oldport)) + return 1; + port2 = ua (port); + pport = pp_openport (port2); + xfree (port2); + if (!pport) { + write_log (L"PARAPORT: couldn't open '%s'\n", port); + paraport_free (); + return 0; + } + _tcscpy (oldport, port); + write_log (L"PARAPORT: port '%s' opened\n", port); + memset (c, 0, sizeof (PARAPORT_CYCLE)); + c[0].MaskControl = PARAPORT_MASK_CONTROL | PARAPORT_MASK_CONTROL_DIRECTION; + c[0].Control = PARAPORT_MASK_CONTROL_INIT | PARAPORT_MASK_CONTROL_DIRECTION; + if (!pp_executecycle (pport, c, 1)) { + write_log (L"PARAPORT: init executeCycle failed\n"); + } return 1; - port2 = ua (port); - pport = pp_openport (port2); - xfree (port2); - if (!pport) { - write_log (L"PARAPORT: couldn't open '%s'\n", port); - paraport_free (); - return 0; - } - _tcscpy (oldport, port); - write_log (L"PARAPORT: port '%s' opened\n", port); - memset (c, 0, sizeof (PARAPORT_CYCLE)); - c[0].MaskControl = PARAPORT_MASK_CONTROL | PARAPORT_MASK_CONTROL_DIRECTION; - c[0].Control = PARAPORT_MASK_CONTROL_INIT | PARAPORT_MASK_CONTROL_DIRECTION; - if (!pp_executecycle (pport, c, 1)) { - write_log (L"PARAPORT: init executeCycle failed\n"); - } - return 1; } int parallel_direct_write_status (uae_u8 v, uae_u8 dir) { - PARAPORT_CYCLE c[1]; - int ok = 1; - - if (!pport) - return 0; - memset (c, 0, sizeof (PARAPORT_CYCLE)); - c[0].MaskControl = PARAPORT_MASK_CONTROL_SELECTIN; - if ((dir & 1)) { - write_log (L"PARAPORT: BUSY can't be output\n"); - ok = 0; - } - if ((dir & 2)) { - write_log (L"PARAPORT: POUT can't be output\n"); - ok = 0; - } - if ((dir & 4) && !(v & 4)) - c[0].Control |= PARAPORT_MASK_CONTROL_SELECTIN; - if (!pp_executecycle (pport, c, 1)) { - write_log (L"PARAPORT: write executeCycle failed, CTL=%02X DIR=%02X\n", v & 7, dir & 7); - return 0; - } - para_log (L"PARAPORT: write CTL=%02X DIR=%02X\n", v & 7, dir & 7); - return ok; + PARAPORT_CYCLE c[1]; + int ok = 1; + + if (!pport) + return 0; + memset (c, 0, sizeof (PARAPORT_CYCLE)); + c[0].MaskControl = PARAPORT_MASK_CONTROL_SELECTIN; + if ((dir & 1)) { + write_log (L"PARAPORT: BUSY can't be output\n"); + ok = 0; + } + if ((dir & 2)) { + write_log (L"PARAPORT: POUT can't be output\n"); + ok = 0; + } + if ((dir & 4) && !(v & 4)) + c[0].Control |= PARAPORT_MASK_CONTROL_SELECTIN; + if (!pp_executecycle (pport, c, 1)) { + write_log (L"PARAPORT: write executeCycle failed, CTL=%02X DIR=%02X\n", v & 7, dir & 7); + return 0; + } + para_log (L"PARAPORT: write CTL=%02X DIR=%02X\n", v & 7, dir & 7); + return ok; } int parallel_direct_read_status (uae_u8 *vp) { - PARAPORT_CYCLE c[1]; - int ok = 1; - uae_u8 v = 0; - static int oldack; - - if (!pport) - return 0; - memset (c + 0, 0, sizeof (PARAPORT_CYCLE)); - c[0].MaskStatus = PARAPORT_MASK_STATUS; - if (!pp_executecycle (pport, c, 1)) { - write_log (L"PARAPORT: CTL read executeCycle failed\n"); - return 0; - } - if (c[0].Status & PARAPORT_MASK_STATUS_SELECT) - v |= 4; - if (c[0].Status & PARAPORT_MASK_STATUS_PAPEREND) - v |= 2; - if (!(c[0].Status & PARAPORT_MASK_STATUS_BUSY)) - v |= 1; - if (c[0].Status & PARAPORT_MASK_STATUS_ACKNOWLEDGE) { - v |= 8; - if (!oldack) - cia_parallelack (); - oldack = 1; - } else { - oldack = 0; - } - para_log (L"PARAPORT: read CTL=%02X\n", v); - v &= 7; - *vp &= ~7; - *vp |= v; - return ok; + PARAPORT_CYCLE c[1]; + int ok = 1; + uae_u8 v = 0; + static int oldack; + + if (!pport) + return 0; + memset (c + 0, 0, sizeof (PARAPORT_CYCLE)); + c[0].MaskStatus = PARAPORT_MASK_STATUS; + if (!pp_executecycle (pport, c, 1)) { + write_log (L"PARAPORT: CTL read executeCycle failed\n"); + return 0; + } + if (c[0].Status & PARAPORT_MASK_STATUS_SELECT) + v |= 4; + if (c[0].Status & PARAPORT_MASK_STATUS_PAPEREND) + v |= 2; + if (!(c[0].Status & PARAPORT_MASK_STATUS_BUSY)) + v |= 1; + if (c[0].Status & PARAPORT_MASK_STATUS_ACKNOWLEDGE) { + v |= 8; + if (!oldack) + cia_parallelack (); + oldack = 1; + } else { + oldack = 0; + } + para_log (L"PARAPORT: read CTL=%02X\n", v); + v &= 7; + *vp &= ~7; + *vp |= v; + return ok; } int parallel_direct_write_data (uae_u8 v, uae_u8 dir) { - PARAPORT_CYCLE c[3]; - int ok = 1; - - if (!pport) - return 0; - if (dir != 0xff) { - write_log (L"PARAPORT: unsupported mixed i/o attempted, DATA=%02X DIR=%02X, ignored\n", v, dir); - return 0; - } - memset (c, 0, 3 * sizeof (PARAPORT_CYCLE)); + PARAPORT_CYCLE c[3]; + int ok = 1; + + if (!pport) + return 0; + if (dir != 0xff) { + write_log (L"PARAPORT: unsupported mixed i/o attempted, DATA=%02X DIR=%02X, ignored\n", v, dir); + return 0; + } + memset (c, 0, 3 * sizeof (PARAPORT_CYCLE)); - c[0].Data = v; - c[0].MaskData = 0xff; - c[0].MaskControl = PARAPORT_MASK_CONTROL_STROBE; + c[0].Data = v; + c[0].MaskData = 0xff; + c[0].MaskControl = PARAPORT_MASK_CONTROL_STROBE; - c[1].MaskControl = PARAPORT_MASK_CONTROL_STROBE; - c[1].Control = PARAPORT_MASK_CONTROL_STROBE; + c[1].MaskControl = PARAPORT_MASK_CONTROL_STROBE; + c[1].Control = PARAPORT_MASK_CONTROL_STROBE; - c[2].MaskControl = PARAPORT_MASK_CONTROL_STROBE; + c[2].MaskControl = PARAPORT_MASK_CONTROL_STROBE; - if (!pp_executecycle (pport, c, 3)) { - write_log (L"PARAPORT: write executeCycle failed, data=%02X\n", v); - return 0; - } - para_log (L"PARAPORT: write DATA=%02X\n", v); - return 1; + if (!pp_executecycle (pport, c, 3)) { + write_log (L"PARAPORT: write executeCycle failed, data=%02X\n", v); + return 0; + } + para_log (L"PARAPORT: write DATA=%02X\n", v); + return 1; } int parallel_direct_read_data (uae_u8 *v) { - static uae_u8 olda, oldb; - PARAPORT_CYCLE c[3]; - int ok = 1; + static uae_u8 olda, oldb; + PARAPORT_CYCLE c[3]; + int ok = 1; - if (!pport) - return 0; - memset (c, 0, 3 * sizeof (PARAPORT_CYCLE)); + if (!pport) + return 0; + memset (c, 0, 3 * sizeof (PARAPORT_CYCLE)); - c[0].MaskData = 0xff; - c[0].MaskControl = PARAPORT_MASK_CONTROL_DIRECTION | PARAPORT_MASK_CONTROL_STROBE; - c[0].Control = PARAPORT_MASK_CONTROL_DIRECTION; + c[0].MaskData = 0xff; + c[0].MaskControl = PARAPORT_MASK_CONTROL_DIRECTION | PARAPORT_MASK_CONTROL_STROBE; + c[0].Control = PARAPORT_MASK_CONTROL_DIRECTION; - c[1].MaskControl = PARAPORT_MASK_CONTROL_STROBE; - c[1].Control = PARAPORT_MASK_CONTROL_STROBE; + c[1].MaskControl = PARAPORT_MASK_CONTROL_STROBE; + c[1].Control = PARAPORT_MASK_CONTROL_STROBE; - c[2].MaskControl = PARAPORT_MASK_CONTROL_STROBE; + c[2].MaskControl = PARAPORT_MASK_CONTROL_STROBE; - if (!pp_executecycle (pport, c, 3)) { - write_log (L"PARAPORT: DATA read executeCycle failed\n"); - return 0; - } - *v = c[0].Data; - para_log (L"PARAPORT: read DATA=%02X\n", v); - return ok; + if (!pp_executecycle (pport, c, 3)) { + write_log (L"PARAPORT: DATA read executeCycle failed\n"); + return 0; + } + *v = c[0].Data; + para_log (L"PARAPORT: read DATA=%02X\n", v); + return ok; } #endif diff --git a/od-win32/keyboard_win32.c b/od-win32/keyboard_win32.c index 06bfa325..5544888f 100644 --- a/od-win32/keyboard_win32.c +++ b/od-win32/keyboard_win32.c @@ -1,13 +1,13 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Additional Win32 helper functions not calling any system routines - * - * (c) 1997 Mathias Ortmann - * (c) 1999-2001 Brian King - * (c) 2000-2001 Bernd Roesch - * (c) 2002 Toni Wilen - */ +* UAE - The Un*x Amiga Emulator +* +* Additional Win32 helper functions not calling any system routines +* +* (c) 1997 Mathias Ortmann +* (c) 1999-2001 Brian King +* (c) 2000-2001 Bernd Roesch +* (c) 2002 Toni Wilen +*/ #include "sysconfig.h" @@ -45,215 +45,215 @@ static struct uae_input_device_kbr_default keytrans[] = { - { DIK_ESCAPE, INPUTEVENT_KEY_ESC }, - - { DIK_F1, INPUTEVENT_KEY_F1 }, - { DIK_F2, INPUTEVENT_KEY_F2 }, - { DIK_F3, INPUTEVENT_KEY_F3 }, - { DIK_F4, INPUTEVENT_KEY_F4 }, - { DIK_F5, INPUTEVENT_KEY_F5 }, - - { DIK_F6, INPUTEVENT_KEY_F6 }, - { DIK_F7, INPUTEVENT_KEY_F7 }, - { DIK_F8, INPUTEVENT_KEY_F8 }, - { DIK_F9, INPUTEVENT_KEY_F9 }, - { DIK_F10, INPUTEVENT_KEY_F10 }, - - { DIK_1, INPUTEVENT_KEY_1 }, - { DIK_2, INPUTEVENT_KEY_2 }, - { DIK_3, INPUTEVENT_KEY_3 }, - { DIK_4, INPUTEVENT_KEY_4 }, - { DIK_5, INPUTEVENT_KEY_5 }, - { DIK_6, INPUTEVENT_KEY_6 }, - { DIK_7, INPUTEVENT_KEY_7 }, - { DIK_8, INPUTEVENT_KEY_8 }, - { DIK_9, INPUTEVENT_KEY_9 }, - { DIK_0, INPUTEVENT_KEY_0 }, - - { DIK_TAB, INPUTEVENT_KEY_TAB }, - - { DIK_A, INPUTEVENT_KEY_A }, - { DIK_B, INPUTEVENT_KEY_B }, - { DIK_C, INPUTEVENT_KEY_C }, - { DIK_D, INPUTEVENT_KEY_D }, - { DIK_E, INPUTEVENT_KEY_E }, - { DIK_F, INPUTEVENT_KEY_F }, - { DIK_G, INPUTEVENT_KEY_G }, - { DIK_H, INPUTEVENT_KEY_H }, - { DIK_I, INPUTEVENT_KEY_I }, - { DIK_J, INPUTEVENT_KEY_J }, - { DIK_K, INPUTEVENT_KEY_K }, - { DIK_L, INPUTEVENT_KEY_L }, - { DIK_M, INPUTEVENT_KEY_M }, - { DIK_N, INPUTEVENT_KEY_N }, - { DIK_O, INPUTEVENT_KEY_O }, - { DIK_P, INPUTEVENT_KEY_P }, - { DIK_Q, INPUTEVENT_KEY_Q }, - { DIK_R, INPUTEVENT_KEY_R }, - { DIK_S, INPUTEVENT_KEY_S }, - { DIK_T, INPUTEVENT_KEY_T }, - { DIK_U, INPUTEVENT_KEY_U }, - { DIK_W, INPUTEVENT_KEY_W }, - { DIK_V, INPUTEVENT_KEY_V }, - { DIK_X, INPUTEVENT_KEY_X }, - { DIK_Y, INPUTEVENT_KEY_Y }, - { DIK_Z, INPUTEVENT_KEY_Z }, - - { DIK_CAPITAL, INPUTEVENT_KEY_CAPS_LOCK }, - - { DIK_NUMPAD1, INPUTEVENT_KEY_NP_1 }, - { DIK_NUMPAD2, INPUTEVENT_KEY_NP_2 }, - { DIK_NUMPAD3, INPUTEVENT_KEY_NP_3 }, - { DIK_NUMPAD4, INPUTEVENT_KEY_NP_4 }, - { DIK_NUMPAD5, INPUTEVENT_KEY_NP_5 }, - { DIK_NUMPAD6, INPUTEVENT_KEY_NP_6 }, - { DIK_NUMPAD7, INPUTEVENT_KEY_NP_7 }, - { DIK_NUMPAD8, INPUTEVENT_KEY_NP_8 }, - { DIK_NUMPAD9, INPUTEVENT_KEY_NP_9 }, - { DIK_NUMPAD0, INPUTEVENT_KEY_NP_0 }, - { DIK_DECIMAL, INPUTEVENT_KEY_NP_PERIOD }, - { DIK_ADD, INPUTEVENT_KEY_NP_ADD }, - { DIK_SUBTRACT, INPUTEVENT_KEY_NP_SUB }, - { DIK_MULTIPLY, INPUTEVENT_KEY_NP_MUL }, - { DIK_DIVIDE, INPUTEVENT_KEY_NP_DIV }, - { DIK_NUMPADENTER, INPUTEVENT_KEY_ENTER }, - - { DIK_MINUS, INPUTEVENT_KEY_SUB }, - { DIK_EQUALS, INPUTEVENT_KEY_EQUALS }, - { DIK_BACK, INPUTEVENT_KEY_BACKSPACE }, - { DIK_RETURN, INPUTEVENT_KEY_RETURN }, - { DIK_SPACE, INPUTEVENT_KEY_SPACE }, - - { DIK_LSHIFT, INPUTEVENT_KEY_SHIFT_LEFT }, - { DIK_LCONTROL, INPUTEVENT_KEY_CTRL }, - { DIK_LWIN, INPUTEVENT_KEY_AMIGA_LEFT }, - { DIK_LMENU, INPUTEVENT_KEY_ALT_LEFT }, - { DIK_RMENU, INPUTEVENT_KEY_ALT_RIGHT }, - { DIK_RWIN, INPUTEVENT_KEY_AMIGA_RIGHT }, - { DIK_APPS, INPUTEVENT_KEY_AMIGA_RIGHT }, - { DIK_RCONTROL, INPUTEVENT_KEY_CTRL_RIGHT }, - { DIK_RSHIFT, INPUTEVENT_KEY_SHIFT_RIGHT }, - - { DIK_UP, INPUTEVENT_KEY_CURSOR_UP }, - { DIK_DOWN, INPUTEVENT_KEY_CURSOR_DOWN }, - { DIK_LEFT, INPUTEVENT_KEY_CURSOR_LEFT }, - { DIK_RIGHT, INPUTEVENT_KEY_CURSOR_RIGHT }, - - { DIK_INSERT, INPUTEVENT_KEY_AMIGA_LEFT }, - { DIK_DELETE, INPUTEVENT_KEY_DEL }, - { DIK_HOME, INPUTEVENT_KEY_AMIGA_RIGHT }, - { DIK_NEXT, INPUTEVENT_KEY_HELP }, - - { DIK_LBRACKET, INPUTEVENT_KEY_LEFTBRACKET }, - { DIK_RBRACKET, INPUTEVENT_KEY_RIGHTBRACKET }, - { DIK_SEMICOLON, INPUTEVENT_KEY_SEMICOLON }, - { DIK_APOSTROPHE, INPUTEVENT_KEY_SINGLEQUOTE }, - { DIK_GRAVE, INPUTEVENT_KEY_BACKQUOTE }, - { DIK_BACKSLASH, INPUTEVENT_KEY_BACKSLASH }, - { DIK_COMMA, INPUTEVENT_KEY_COMMA }, - { DIK_PERIOD, INPUTEVENT_KEY_PERIOD }, - { DIK_SLASH, INPUTEVENT_KEY_DIV }, - { DIK_OEM_102, INPUTEVENT_KEY_30 }, - - { DIK_VOLUMEDOWN, INPUTEVENT_SPC_MASTER_VOLUME_DOWN }, - { DIK_VOLUMEUP, INPUTEVENT_SPC_MASTER_VOLUME_UP }, - { DIK_MUTE, INPUTEVENT_SPC_MASTER_VOLUME_MUTE }, - - { DIK_HOME, INPUTEVENT_KEY_70 }, - { DIK_END, INPUTEVENT_KEY_71 }, -// { DIK_SYSRQ, INPUTEVENT_KEY_6E }, -// { DIK_F12, INPUTEVENT_KEY_6F }, - { DIK_INSERT, INPUTEVENT_KEY_47 }, -// { DIK_PRIOR, INPUTEVENT_KEY_48 }, - { DIK_PRIOR, INPUTEVENT_SPC_FREEZEBUTTON }, - { DIK_NEXT, INPUTEVENT_KEY_49 }, - { DIK_F11, INPUTEVENT_KEY_4B }, - - { DIK_MEDIASTOP, INPUTEVENT_KEY_CDTV_STOP }, - { DIK_PLAYPAUSE, INPUTEVENT_KEY_CDTV_PLAYPAUSE }, - { DIK_PREVTRACK, INPUTEVENT_KEY_CDTV_PREV }, - { DIK_NEXTTRACK, INPUTEVENT_KEY_CDTV_NEXT }, - - { -1, 0 } + { DIK_ESCAPE, INPUTEVENT_KEY_ESC }, + + { DIK_F1, INPUTEVENT_KEY_F1 }, + { DIK_F2, INPUTEVENT_KEY_F2 }, + { DIK_F3, INPUTEVENT_KEY_F3 }, + { DIK_F4, INPUTEVENT_KEY_F4 }, + { DIK_F5, INPUTEVENT_KEY_F5 }, + + { DIK_F6, INPUTEVENT_KEY_F6 }, + { DIK_F7, INPUTEVENT_KEY_F7 }, + { DIK_F8, INPUTEVENT_KEY_F8 }, + { DIK_F9, INPUTEVENT_KEY_F9 }, + { DIK_F10, INPUTEVENT_KEY_F10 }, + + { DIK_1, INPUTEVENT_KEY_1 }, + { DIK_2, INPUTEVENT_KEY_2 }, + { DIK_3, INPUTEVENT_KEY_3 }, + { DIK_4, INPUTEVENT_KEY_4 }, + { DIK_5, INPUTEVENT_KEY_5 }, + { DIK_6, INPUTEVENT_KEY_6 }, + { DIK_7, INPUTEVENT_KEY_7 }, + { DIK_8, INPUTEVENT_KEY_8 }, + { DIK_9, INPUTEVENT_KEY_9 }, + { DIK_0, INPUTEVENT_KEY_0 }, + + { DIK_TAB, INPUTEVENT_KEY_TAB }, + + { DIK_A, INPUTEVENT_KEY_A }, + { DIK_B, INPUTEVENT_KEY_B }, + { DIK_C, INPUTEVENT_KEY_C }, + { DIK_D, INPUTEVENT_KEY_D }, + { DIK_E, INPUTEVENT_KEY_E }, + { DIK_F, INPUTEVENT_KEY_F }, + { DIK_G, INPUTEVENT_KEY_G }, + { DIK_H, INPUTEVENT_KEY_H }, + { DIK_I, INPUTEVENT_KEY_I }, + { DIK_J, INPUTEVENT_KEY_J }, + { DIK_K, INPUTEVENT_KEY_K }, + { DIK_L, INPUTEVENT_KEY_L }, + { DIK_M, INPUTEVENT_KEY_M }, + { DIK_N, INPUTEVENT_KEY_N }, + { DIK_O, INPUTEVENT_KEY_O }, + { DIK_P, INPUTEVENT_KEY_P }, + { DIK_Q, INPUTEVENT_KEY_Q }, + { DIK_R, INPUTEVENT_KEY_R }, + { DIK_S, INPUTEVENT_KEY_S }, + { DIK_T, INPUTEVENT_KEY_T }, + { DIK_U, INPUTEVENT_KEY_U }, + { DIK_W, INPUTEVENT_KEY_W }, + { DIK_V, INPUTEVENT_KEY_V }, + { DIK_X, INPUTEVENT_KEY_X }, + { DIK_Y, INPUTEVENT_KEY_Y }, + { DIK_Z, INPUTEVENT_KEY_Z }, + + { DIK_CAPITAL, INPUTEVENT_KEY_CAPS_LOCK }, + + { DIK_NUMPAD1, INPUTEVENT_KEY_NP_1 }, + { DIK_NUMPAD2, INPUTEVENT_KEY_NP_2 }, + { DIK_NUMPAD3, INPUTEVENT_KEY_NP_3 }, + { DIK_NUMPAD4, INPUTEVENT_KEY_NP_4 }, + { DIK_NUMPAD5, INPUTEVENT_KEY_NP_5 }, + { DIK_NUMPAD6, INPUTEVENT_KEY_NP_6 }, + { DIK_NUMPAD7, INPUTEVENT_KEY_NP_7 }, + { DIK_NUMPAD8, INPUTEVENT_KEY_NP_8 }, + { DIK_NUMPAD9, INPUTEVENT_KEY_NP_9 }, + { DIK_NUMPAD0, INPUTEVENT_KEY_NP_0 }, + { DIK_DECIMAL, INPUTEVENT_KEY_NP_PERIOD }, + { DIK_ADD, INPUTEVENT_KEY_NP_ADD }, + { DIK_SUBTRACT, INPUTEVENT_KEY_NP_SUB }, + { DIK_MULTIPLY, INPUTEVENT_KEY_NP_MUL }, + { DIK_DIVIDE, INPUTEVENT_KEY_NP_DIV }, + { DIK_NUMPADENTER, INPUTEVENT_KEY_ENTER }, + + { DIK_MINUS, INPUTEVENT_KEY_SUB }, + { DIK_EQUALS, INPUTEVENT_KEY_EQUALS }, + { DIK_BACK, INPUTEVENT_KEY_BACKSPACE }, + { DIK_RETURN, INPUTEVENT_KEY_RETURN }, + { DIK_SPACE, INPUTEVENT_KEY_SPACE }, + + { DIK_LSHIFT, INPUTEVENT_KEY_SHIFT_LEFT }, + { DIK_LCONTROL, INPUTEVENT_KEY_CTRL }, + { DIK_LWIN, INPUTEVENT_KEY_AMIGA_LEFT }, + { DIK_LMENU, INPUTEVENT_KEY_ALT_LEFT }, + { DIK_RMENU, INPUTEVENT_KEY_ALT_RIGHT }, + { DIK_RWIN, INPUTEVENT_KEY_AMIGA_RIGHT }, + { DIK_APPS, INPUTEVENT_KEY_AMIGA_RIGHT }, + { DIK_RCONTROL, INPUTEVENT_KEY_CTRL_RIGHT }, + { DIK_RSHIFT, INPUTEVENT_KEY_SHIFT_RIGHT }, + + { DIK_UP, INPUTEVENT_KEY_CURSOR_UP }, + { DIK_DOWN, INPUTEVENT_KEY_CURSOR_DOWN }, + { DIK_LEFT, INPUTEVENT_KEY_CURSOR_LEFT }, + { DIK_RIGHT, INPUTEVENT_KEY_CURSOR_RIGHT }, + + { DIK_INSERT, INPUTEVENT_KEY_AMIGA_LEFT }, + { DIK_DELETE, INPUTEVENT_KEY_DEL }, + { DIK_HOME, INPUTEVENT_KEY_AMIGA_RIGHT }, + { DIK_NEXT, INPUTEVENT_KEY_HELP }, + + { DIK_LBRACKET, INPUTEVENT_KEY_LEFTBRACKET }, + { DIK_RBRACKET, INPUTEVENT_KEY_RIGHTBRACKET }, + { DIK_SEMICOLON, INPUTEVENT_KEY_SEMICOLON }, + { DIK_APOSTROPHE, INPUTEVENT_KEY_SINGLEQUOTE }, + { DIK_GRAVE, INPUTEVENT_KEY_BACKQUOTE }, + { DIK_BACKSLASH, INPUTEVENT_KEY_BACKSLASH }, + { DIK_COMMA, INPUTEVENT_KEY_COMMA }, + { DIK_PERIOD, INPUTEVENT_KEY_PERIOD }, + { DIK_SLASH, INPUTEVENT_KEY_DIV }, + { DIK_OEM_102, INPUTEVENT_KEY_30 }, + + { DIK_VOLUMEDOWN, INPUTEVENT_SPC_MASTER_VOLUME_DOWN }, + { DIK_VOLUMEUP, INPUTEVENT_SPC_MASTER_VOLUME_UP }, + { DIK_MUTE, INPUTEVENT_SPC_MASTER_VOLUME_MUTE }, + + { DIK_HOME, INPUTEVENT_KEY_70 }, + { DIK_END, INPUTEVENT_KEY_71 }, + // { DIK_SYSRQ, INPUTEVENT_KEY_6E }, + // { DIK_F12, INPUTEVENT_KEY_6F }, + { DIK_INSERT, INPUTEVENT_KEY_47 }, + // { DIK_PRIOR, INPUTEVENT_KEY_48 }, + { DIK_PRIOR, INPUTEVENT_SPC_FREEZEBUTTON }, + { DIK_NEXT, INPUTEVENT_KEY_49 }, + { DIK_F11, INPUTEVENT_KEY_4B }, + + { DIK_MEDIASTOP, INPUTEVENT_KEY_CDTV_STOP }, + { DIK_PLAYPAUSE, INPUTEVENT_KEY_CDTV_PLAYPAUSE }, + { DIK_PREVTRACK, INPUTEVENT_KEY_CDTV_PREV }, + { DIK_NEXTTRACK, INPUTEVENT_KEY_CDTV_NEXT }, + + { -1, 0 } }; extern int ispressed (int key); static int specialkeycode (void) { - return currprefs.win32_specialkey; + return currprefs.win32_specialkey; } static int specialpressed (void) { - return ispressed (specialkeycode ()); + return ispressed (specialkeycode ()); } static int shiftpressed (void) { - return ispressed (DIK_LSHIFT) || ispressed (DIK_RSHIFT); + return ispressed (DIK_LSHIFT) || ispressed (DIK_RSHIFT); } static int altpressed (void) { - return ispressed (DIK_LMENU) || ispressed (DIK_RMENU); + return ispressed (DIK_LMENU) || ispressed (DIK_RMENU); } static int ctrlpressed (void) { - return ispressed (DIK_LCONTROL) || ispressed (DIK_RCONTROL); + return ispressed (DIK_LCONTROL) || ispressed (DIK_RCONTROL); } static int capslockstate; int getcapslockstate (void) { - return capslockstate; + return capslockstate; } void setcapslockstate (int state) { - capslockstate = state; + capslockstate = state; } int getcapslock (void) { - int newstate; + int newstate; - newstate = GetKeyState (VK_CAPITAL) & 1; // this returns bogus state if caps change when in exclusive mode.. - if (newstate != capslockstate) - inputdevice_translatekeycode (0, DIK_CAPITAL, newstate); - capslockstate = newstate; - return capslockstate; + newstate = GetKeyState (VK_CAPITAL) & 1; // this returns bogus state if caps change when in exclusive mode.. + if (newstate != capslockstate) + inputdevice_translatekeycode (0, DIK_CAPITAL, newstate); + capslockstate = newstate; + return capslockstate; } #ifdef ARCADIA static int handlearcadia (int scancode, int state) { - int e = 0; - if (!arcadia_bios) - return 0; - switch (scancode) - { + int e = 0; + if (!arcadia_bios) + return 0; + switch (scancode) + { case DIK_F2: - e = INPUTEVENT_SPC_ARCADIA_DIAGNOSTICS; - break; + e = INPUTEVENT_SPC_ARCADIA_DIAGNOSTICS; + break; case DIK_1: - e = INPUTEVENT_SPC_ARCADIA_PLAYER1; - break; + e = INPUTEVENT_SPC_ARCADIA_PLAYER1; + break; case DIK_2: - e = INPUTEVENT_SPC_ARCADIA_PLAYER2; - break; + e = INPUTEVENT_SPC_ARCADIA_PLAYER2; + break; case DIK_5: - e = INPUTEVENT_SPC_ARCADIA_COIN1; - break; + e = INPUTEVENT_SPC_ARCADIA_COIN1; + break; case DIK_6: - e = INPUTEVENT_SPC_ARCADIA_COIN2; - break; - } - if (!e) - return 0; - handle_input_event (e, state, 1, 0); - return 1; + e = INPUTEVENT_SPC_ARCADIA_COIN2; + break; + } + if (!e) + return 0; + handle_input_event (e, state, 1, 0); + return 1; } #endif @@ -262,38 +262,38 @@ static int handlearcadia (int scancode, int state) static int handlecdtv (int scancode, int state) { - int e = 0; - switch (scancode) - { + int e = 0; + switch (scancode) + { case DIK_UP: - if (specialpressed ()) - e = INPUTEVENT_KEY_CDTV_PLAYPAUSE; - break; + if (specialpressed ()) + e = INPUTEVENT_KEY_CDTV_PLAYPAUSE; + break; case DIK_DOWN: - if (specialpressed ()) - e = INPUTEVENT_KEY_CDTV_STOP; - break; + if (specialpressed ()) + e = INPUTEVENT_KEY_CDTV_STOP; + break; case DIK_LEFT: - if (specialpressed ()) { - if (shiftpressed ()) - e = INPUTEVENT_KEY_CDTV_REW; - else - e = INPUTEVENT_KEY_CDTV_PREV; - } - break; + if (specialpressed ()) { + if (shiftpressed ()) + e = INPUTEVENT_KEY_CDTV_REW; + else + e = INPUTEVENT_KEY_CDTV_PREV; + } + break; case DIK_RIGHT: - if (specialpressed ()) { - if (shiftpressed ()) - e = INPUTEVENT_KEY_CDTV_FF; - else - e = INPUTEVENT_KEY_CDTV_NEXT; + if (specialpressed ()) { + if (shiftpressed ()) + e = INPUTEVENT_KEY_CDTV_FF; + else + e = INPUTEVENT_KEY_CDTV_NEXT; + } + break; } - break; - } - if (!e) - return 0; - handle_input_event (e, state, 1, 0); - return 1; + if (!e) + return 0; + handle_input_event (e, state, 1, 0); + return 1; } #endif @@ -301,239 +301,239 @@ static int handlecdtv (int scancode, int state) static int handlecd32 (int scancode, int state) { - int e = 0; - if (!currprefs.cs_cd32cd) - return 0; - switch (scancode) - { + int e = 0; + if (!currprefs.cs_cd32cd) + return 0; + switch (scancode) + { case DIK_NUMPAD7: - e = INPUTEVENT_JOY2_CD32_GREEN; - break; + e = INPUTEVENT_JOY2_CD32_GREEN; + break; case DIK_NUMPAD9: - e = INPUTEVENT_JOY2_CD32_YELLOW; - break; + e = INPUTEVENT_JOY2_CD32_YELLOW; + break; case DIK_NUMPAD1: - e = INPUTEVENT_JOY2_CD32_RED; - break; + e = INPUTEVENT_JOY2_CD32_RED; + break; case DIK_NUMPAD3: - e = INPUTEVENT_JOY2_CD32_BLUE; - break; + e = INPUTEVENT_JOY2_CD32_BLUE; + break; case DIK_DIVIDE: - e = INPUTEVENT_JOY2_CD32_RWD; - break; + e = INPUTEVENT_JOY2_CD32_RWD; + break; case DIK_MULTIPLY: - e = INPUTEVENT_JOY2_CD32_PLAY; - break; + e = INPUTEVENT_JOY2_CD32_PLAY; + break; case DIK_SUBTRACT: - e = INPUTEVENT_JOY2_CD32_FFW; - break; - } - if (!e) - return 0; - handle_input_event (e, state, 1, 0); - return 1; + e = INPUTEVENT_JOY2_CD32_FFW; + break; + } + if (!e) + return 0; + handle_input_event (e, state, 1, 0); + return 1; } #endif void clearallkeys (void) { - inputdevice_updateconfig (&currprefs); + inputdevice_updateconfig (&currprefs); } static int np[] = { DIK_NUMPAD0, 0, DIK_NUMPADPERIOD, 0, DIK_NUMPAD1, 1, DIK_NUMPAD2, 2, - DIK_NUMPAD3, 3, DIK_NUMPAD4, 4, DIK_NUMPAD5, 5, DIK_NUMPAD6, 6, DIK_NUMPAD7, 7, - DIK_NUMPAD8, 8, DIK_NUMPAD9, 9, -1 }; + DIK_NUMPAD3, 3, DIK_NUMPAD4, 4, DIK_NUMPAD5, 5, DIK_NUMPAD6, 6, DIK_NUMPAD7, 7, + DIK_NUMPAD8, 8, DIK_NUMPAD9, 9, -1 }; void my_kbd_handler (int keyboard, int scancode, int newstate) { - int code = 0; - static int swapperdrive = 0; - - if (scancode == specialkeycode ()) - return; - - //write_log ( "keyboard = %d scancode = 0x%02x state = %d\n", keyboard, scancode, newstate ); - if (newstate) { - - if (scancode == DIK_F12 || scancode == currprefs.win32_guikey) { - if (ctrlpressed ()) { - code = AKS_TOGGLEFULLSCREEN; - } else if (shiftpressed () || specialpressed ()) { - if (isfullscreen() <= 0) { - disablecapture (); - code = AKS_ENTERDEBUGGER; + int code = 0; + static int swapperdrive = 0; + + if (scancode == specialkeycode ()) + return; + + //write_log ( "keyboard = %d scancode = 0x%02x state = %d\n", keyboard, scancode, newstate ); + if (newstate) { + + if (scancode == DIK_F12 || scancode == currprefs.win32_guikey) { + if (ctrlpressed ()) { + code = AKS_TOGGLEFULLSCREEN; + } else if (shiftpressed () || specialpressed ()) { + if (isfullscreen() <= 0) { + disablecapture (); + code = AKS_ENTERDEBUGGER; + } + } else { + code = AKS_ENTERGUI; + } } - } else { - code = AKS_ENTERGUI; - } - } - switch (scancode) - { - case DIK_F11: - if (currprefs.win32_ctrl_F11_is_quit) { - if (ctrlpressed ()) - code = AKS_QUIT; - } - break; - case DIK_F1: - case DIK_F2: - case DIK_F3: - case DIK_F4: - if (specialpressed ()) { - if (ctrlpressed ()) { - } else { - if (shiftpressed ()) - code = AKS_EFLOPPY0 + (scancode - DIK_F1); - else - code = AKS_FLOPPY0 + (scancode - DIK_F1); - } - } - break; - case DIK_F5: - if (specialpressed ()) { - if (shiftpressed ()) - code = AKS_STATESAVEDIALOG; - else - code = AKS_STATERESTOREDIALOG; - } - break; - case DIK_1: - case DIK_2: - case DIK_3: - case DIK_4: - case DIK_5: - case DIK_6: - case DIK_7: - case DIK_8: - case DIK_9: - case DIK_0: - if (specialpressed ()) { - int num = scancode - DIK_1; - if (shiftpressed ()) - num += 10; - if (ctrlpressed ()) { - swapperdrive = num; - if (swapperdrive > 3) - swapperdrive = 0; - } else { - int i; - for (i = 0; i < 4; i++) { - if (!_tcscmp (currprefs.df[i], currprefs.dfxlist[num])) - changed_prefs.df[i][0] = 0; - } - _tcscpy (changed_prefs.df[swapperdrive], currprefs.dfxlist[num]); - } - } - break; - case DIK_NUMPAD0: - case DIK_NUMPAD1: - case DIK_NUMPAD2: - case DIK_NUMPAD3: - case DIK_NUMPAD4: - case DIK_NUMPAD5: - case DIK_NUMPAD6: - case DIK_NUMPAD7: - case DIK_NUMPAD8: - case DIK_NUMPAD9: - case DIK_NUMPADPERIOD: - if (specialpressed ()) { - int i = 0, v = -1; - while (np[i] >= 0) { - v = np[i + 1]; - if (np[i] == scancode) + switch (scancode) + { + case DIK_F11: + if (currprefs.win32_ctrl_F11_is_quit) { + if (ctrlpressed ()) + code = AKS_QUIT; + } + break; + case DIK_F1: + case DIK_F2: + case DIK_F3: + case DIK_F4: + if (specialpressed ()) { + if (ctrlpressed ()) { + } else { + if (shiftpressed ()) + code = AKS_EFLOPPY0 + (scancode - DIK_F1); + else + code = AKS_FLOPPY0 + (scancode - DIK_F1); + } + } + break; + case DIK_F5: + if (specialpressed ()) { + if (shiftpressed ()) + code = AKS_STATESAVEDIALOG; + else + code = AKS_STATERESTOREDIALOG; + } + break; + case DIK_1: + case DIK_2: + case DIK_3: + case DIK_4: + case DIK_5: + case DIK_6: + case DIK_7: + case DIK_8: + case DIK_9: + case DIK_0: + if (specialpressed ()) { + int num = scancode - DIK_1; + if (shiftpressed ()) + num += 10; + if (ctrlpressed ()) { + swapperdrive = num; + if (swapperdrive > 3) + swapperdrive = 0; + } else { + int i; + for (i = 0; i < 4; i++) { + if (!_tcscmp (currprefs.df[i], currprefs.dfxlist[num])) + changed_prefs.df[i][0] = 0; + } + _tcscpy (changed_prefs.df[swapperdrive], currprefs.dfxlist[num]); + } + } + break; + case DIK_NUMPAD0: + case DIK_NUMPAD1: + case DIK_NUMPAD2: + case DIK_NUMPAD3: + case DIK_NUMPAD4: + case DIK_NUMPAD5: + case DIK_NUMPAD6: + case DIK_NUMPAD7: + case DIK_NUMPAD8: + case DIK_NUMPAD9: + case DIK_NUMPADPERIOD: + if (specialpressed ()) { + int i = 0, v = -1; + while (np[i] >= 0) { + v = np[i + 1]; + if (np[i] == scancode) + break; + i += 2; + } + if (v >= 0) + code = AKS_STATESAVEQUICK + v * 2 + ((shiftpressed () || ctrlpressed()) ? 0 : 1); + } + break; + case DIK_SYSRQ: + screenshot (specialpressed () ? 1 : 0, 1); + break; + case DIK_PAUSE: + if (specialpressed ()) { + if (shiftpressed ()) + code = AKS_IRQ7; + else + code = AKS_WARP; + } else { + code = AKS_PAUSE; + } + break; + case DIK_SCROLL: + code = AKS_INHIBITSCREEN; + break; + case DIK_NUMPADMINUS: + if (specialpressed ()) { + if (shiftpressed ()) + code = AKS_DECREASEREFRESHRATE; + else if (ctrlpressed ()) + code = AKS_MVOLDOWN; + else + code = AKS_VOLDOWN; + } + break; + case DIK_NUMPADPLUS: + if (specialpressed ()) { + if (shiftpressed ()) + code = AKS_INCREASEREFRESHRATE; + else if (ctrlpressed ()) + code = AKS_MVOLUP; + else + code = AKS_VOLUP; + } + break; + case DIK_NUMPADSTAR: + if (specialpressed ()) { + if (ctrlpressed ()) + code = AKS_MVOLMUTE; + else + code = AKS_VOLMUTE; + } + break; + case DIK_NUMPADSLASH: + if (specialpressed ()) + code = AKS_STATEREWIND; break; - i += 2; } - if (v >= 0) - code = AKS_STATESAVEQUICK + v * 2 + ((shiftpressed () || ctrlpressed()) ? 0 : 1); - } - break; - case DIK_SYSRQ: - screenshot (specialpressed () ? 1 : 0, 1); - break; - case DIK_PAUSE: - if (specialpressed ()) { - if (shiftpressed ()) - code = AKS_IRQ7; - else - code = AKS_WARP; - } else { - code = AKS_PAUSE; - } - break; - case DIK_SCROLL: - code = AKS_INHIBITSCREEN; - break; - case DIK_NUMPADMINUS: - if (specialpressed ()) { - if (shiftpressed ()) - code = AKS_DECREASEREFRESHRATE; - else if (ctrlpressed ()) - code = AKS_MVOLDOWN; - else - code = AKS_VOLDOWN; - } - break; - case DIK_NUMPADPLUS: - if (specialpressed ()) { - if (shiftpressed ()) - code = AKS_INCREASEREFRESHRATE; - else if (ctrlpressed ()) - code = AKS_MVOLUP; - else - code = AKS_VOLUP; - } - break; - case DIK_NUMPADSTAR: - if (specialpressed ()) { - if (ctrlpressed ()) - code = AKS_MVOLMUTE; - else - code = AKS_VOLMUTE; - } - break; - case DIK_NUMPADSLASH: - if (specialpressed ()) - code = AKS_STATEREWIND; - break; } - } - if (code) { - inputdevice_add_inputcode (code, 1); - return; - } + if (code) { + inputdevice_add_inputcode (code, 1); + return; + } - if (!specialpressed () && scancode == DIK_CAPITAL) { - if (!newstate) - return; - capslockstate = capslockstate ? 0 : 1; - newstate = capslockstate; - } + if (!specialpressed () && scancode == DIK_CAPITAL) { + if (!newstate) + return; + capslockstate = capslockstate ? 0 : 1; + newstate = capslockstate; + } - if (currprefs.input_selected_setting == 0) { + if (currprefs.input_selected_setting == 0) { #ifdef CD32 - if (handlecd32 (scancode, newstate)) - return; + if (handlecd32 (scancode, newstate)) + return; #endif #ifdef CDTV - if (handlecdtv (scancode, newstate)) - return; + if (handlecdtv (scancode, newstate)) + return; #endif #ifdef ARCADIA - if (handlearcadia (scancode, newstate)) - return; + if (handlearcadia (scancode, newstate)) + return; #endif - } - if (specialpressed ()) - return; + } + if (specialpressed ()) + return; - inputdevice_translatekeycode (keyboard, scancode, newstate); + inputdevice_translatekeycode (keyboard, scancode, newstate); } void keyboard_settrans (void) { - inputdevice_setkeytranslation (keytrans); + inputdevice_setkeytranslation (keytrans); } diff --git a/od-win32/lcd.c b/od-win32/lcd.c index fc4221fc..b4e20016 100644 --- a/od-win32/lcd.c +++ b/od-win32/lcd.c @@ -24,186 +24,186 @@ static int old_pri; void lcd_close (void) { - lgLcdDeInit (); - xfree (lbh); - lbh = NULL; - bitmap = NULL; - inited = 0; + lgLcdDeInit (); + xfree (lbh); + lbh = NULL; + bitmap = NULL; + inited = 0; } static int lcd_init (void) { - DWORD ret; - lgLcdOpenContext octx; - HBITMAP bmp; - BITMAP binfo; - HDC dc; - int x, y; - - old_pri = 0; - ret = lgLcdInit (); - if (ret != ERROR_SUCCESS) { - if (ret == RPC_S_SERVER_UNAVAILABLE || ret == ERROR_OLD_WIN_VERSION) { - write_log (L"LCD: Logitech LCD system not detected\n"); - return 0; + DWORD ret; + lgLcdOpenContext octx; + HBITMAP bmp; + BITMAP binfo; + HDC dc; + int x, y; + + old_pri = 0; + ret = lgLcdInit (); + if (ret != ERROR_SUCCESS) { + if (ret == RPC_S_SERVER_UNAVAILABLE || ret == ERROR_OLD_WIN_VERSION) { + write_log (L"LCD: Logitech LCD system not detected\n"); + return 0; + } + write_log (L"LCD: lgLcdInit() returned %d\n", ret); + return 0; } - write_log (L"LCD: lgLcdInit() returned %d\n", ret); - return 0; - } - memset (&cctx, 0, sizeof (cctx)); - cctx.appFriendlyName = L"WinUAE"; - cctx.isPersistent = TRUE; - cctx.isAutostartable = FALSE; - ret = lgLcdConnect (&cctx); - if (ret != ERROR_SUCCESS) { - write_log (L"LCD: lgLcdConnect() returned %d\n", ret); - lcd_close (); - return 0; - } - ret = lgLcdEnumerateEx (cctx.connection, 0, &desc); - if (ret != ERROR_SUCCESS) { - write_log (L"LCD: lgLcdEnumerateEx() returned %d\n", ret); - lcd_close (); - return 0; - } - lbh = xcalloc (1, sizeof (lgLcdBitmapHeader) + desc.Width * (desc.Height + 20)); - lbh->Format = LGLCD_BMP_FORMAT_160x43x1; - bitmap = (uae_u8*)lbh + sizeof (lgLcdBitmapHeader); - origbitmap = xcalloc (1, desc.Width * desc.Height); - memset (&octx, 0, sizeof (octx)); - octx.connection = cctx.connection; - octx.index = 0; - ret = lgLcdOpen (&octx); - if (ret != ERROR_SUCCESS) { - write_log (L"LCD: lgLcdOpen() returned %d\n", ret); - lcd_close (); - return 0; - } - device = octx.device; - - bmp = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LCD160X43)); - dc = CreateCompatibleDC (NULL); - SelectObject (dc, bmp); - GetObject (bmp, sizeof (binfo), &binfo); - for (y = 0; y < binfo.bmHeight; y++) { - for (x = 0; x < binfo.bmWidth; x++) { - bitmap[y * binfo.bmWidth + x] = GetPixel (dc, x, y) == 0 ? 0xff : 0; + memset (&cctx, 0, sizeof (cctx)); + cctx.appFriendlyName = L"WinUAE"; + cctx.isPersistent = TRUE; + cctx.isAutostartable = FALSE; + ret = lgLcdConnect (&cctx); + if (ret != ERROR_SUCCESS) { + write_log (L"LCD: lgLcdConnect() returned %d\n", ret); + lcd_close (); + return 0; } - } - numbers = bitmap + desc.Width * desc.Height; - memcpy (origbitmap, bitmap, desc.Width * desc.Height); - DeleteDC (dc); + ret = lgLcdEnumerateEx (cctx.connection, 0, &desc); + if (ret != ERROR_SUCCESS) { + write_log (L"LCD: lgLcdEnumerateEx() returned %d\n", ret); + lcd_close (); + return 0; + } + lbh = xcalloc (1, sizeof (lgLcdBitmapHeader) + desc.Width * (desc.Height + 20)); + lbh->Format = LGLCD_BMP_FORMAT_160x43x1; + bitmap = (uae_u8*)lbh + sizeof (lgLcdBitmapHeader); + origbitmap = xcalloc (1, desc.Width * desc.Height); + memset (&octx, 0, sizeof (octx)); + octx.connection = cctx.connection; + octx.index = 0; + ret = lgLcdOpen (&octx); + if (ret != ERROR_SUCCESS) { + write_log (L"LCD: lgLcdOpen() returned %d\n", ret); + lcd_close (); + return 0; + } + device = octx.device; + + bmp = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LCD160X43)); + dc = CreateCompatibleDC (NULL); + SelectObject (dc, bmp); + GetObject (bmp, sizeof (binfo), &binfo); + for (y = 0; y < binfo.bmHeight; y++) { + for (x = 0; x < binfo.bmWidth; x++) { + bitmap[y * binfo.bmWidth + x] = GetPixel (dc, x, y) == 0 ? 0xff : 0; + } + } + numbers = bitmap + desc.Width * desc.Height; + memcpy (origbitmap, bitmap, desc.Width * desc.Height); + DeleteDC (dc); - write_log (L"LCD: '%s' enabled\n", desc.deviceDisplayName); - return 1; + write_log (L"LCD: '%s' enabled\n", desc.deviceDisplayName); + return 1; } static void dorect (int *crd, int inv) { - int yy, xx; - int x = crd[0], y = crd[1], w = crd[2], h = crd[3]; - for (yy = y; yy < y + h; yy++) { - for (xx = x; xx < x + w; xx++) { - uae_u8 b = origbitmap[yy * desc.Width + xx]; - if (inv) - b = b == 0 ? 0xff : 0; - bitmap[yy * desc.Width + xx] = b; + int yy, xx; + int x = crd[0], y = crd[1], w = crd[2], h = crd[3]; + for (yy = y; yy < y + h; yy++) { + for (xx = x; xx < x + w; xx++) { + uae_u8 b = origbitmap[yy * desc.Width + xx]; + if (inv) + b = b == 0 ? 0xff : 0; + bitmap[yy * desc.Width + xx] = b; + } } - } } static void putnumber (int x, int y, int n, int inv) { - int xx, yy; - uae_u8 *dst, *src; - if (n == 0) - n = 9; - else - n--; - if (n < 0) - n = 10; - for (yy = 0; yy < numbers_height; yy++) { - for (xx = 0; xx < numbers_width; xx++) { - dst = bitmap + (yy + y) * desc.Width + (xx + x); - src = numbers + n * numbers_width + yy * desc.Width + xx; - *dst = 0; - if (*src == 0) - *dst = 0xff; - if (inv) - *dst ^= 0xff; + int xx, yy; + uae_u8 *dst, *src; + if (n == 0) + n = 9; + else + n--; + if (n < 0) + n = 10; + for (yy = 0; yy < numbers_height; yy++) { + for (xx = 0; xx < numbers_width; xx++) { + dst = bitmap + (yy + y) * desc.Width + (xx + x); + src = numbers + n * numbers_width + yy * desc.Width + xx; + *dst = 0; + if (*src == 0) + *dst = 0xff; + if (inv) + *dst ^= 0xff; + } } - } } static void putnumbers (int x, int y, int num, int inv) { - putnumber (x, y, num < 0 ? num : ((num / 10) > 0 ? num / 10 : -1), inv); - putnumber (x + numbers_width, y, num < 0 ? num : num % 10, inv); + putnumber (x, y, num < 0 ? num : ((num / 10) > 0 ? num / 10 : -1), inv); + putnumber (x + numbers_width, y, num < 0 ? num : num % 10, inv); } static int coords[] = { - 53, 2, 13, 10, // CD - 36, 2, 13, 10, // HD - 2, 2, 30, 10 // POWER + 53, 2, 13, 10, // CD + 36, 2, 13, 10, // HD + 2, 2, 30, 10 // POWER }; void lcd_priority (int priority) { - if (!inited) - return; - if (old_pri == priority) - return; - if (lgLcdSetAsLCDForegroundApp (device, priority ? LGLCD_LCD_FOREGROUND_APP_YES : LGLCD_LCD_FOREGROUND_APP_NO) == ERROR_SUCCESS) - old_pri = priority; + if (!inited) + return; + if (old_pri == priority) + return; + if (lgLcdSetAsLCDForegroundApp (device, priority ? LGLCD_LCD_FOREGROUND_APP_YES : LGLCD_LCD_FOREGROUND_APP_NO) == ERROR_SUCCESS) + old_pri = priority; } void lcd_update (int led, int on) { - int track, x, y; - - if (!inited) - return; - - if (led < 0) { - lgLcdUpdateBitmap (device, lbh, LGLCD_PRIORITY_IDLE_NO_SHOW); - return; - } - - if (led >= 1 && led <= 4) { - x = 23 + (led - 1) * 40; - y = 17; - track = gui_data.drive_track[led - 1]; - if (gui_data.drive_disabled[led - 1]) { - track = -1; - on = 0; + int track, x, y; + + if (!inited) + return; + + if (led < 0) { + lgLcdUpdateBitmap (device, lbh, LGLCD_PRIORITY_IDLE_NO_SHOW); + return; + } + + if (led >= 1 && led <= 4) { + x = 23 + (led - 1) * 40; + y = 17; + track = gui_data.drive_track[led - 1]; + if (gui_data.drive_disabled[led - 1]) { + track = -1; + on = 0; + } + putnumbers (x, y, track, on); + } else if (led == 0) { + dorect (&coords[4 * 2], on); + } else if (led == 5) { + dorect (&coords[4 * 1], on); + } else if (led == 6) { + dorect (&coords[4 * 0], on); + } else if (led == 7) { + y = 2; + x = 125; + putnumbers (x, y, gui_data.fps <= 999 ? (gui_data.fps + 5) / 10 : 99, 0); + } else if (led == 8) { + y = 2; + x = 98; + putnumbers (x, y, gui_data.idle <= 999 ? gui_data.idle / 10 : 99, 0); } - putnumbers (x, y, track, on); - } else if (led == 0) { - dorect (&coords[4 * 2], on); - } else if (led == 5) { - dorect (&coords[4 * 1], on); - } else if (led == 6) { - dorect (&coords[4 * 0], on); - } else if (led == 7) { - y = 2; - x = 125; - putnumbers (x, y, gui_data.fps <= 999 ? (gui_data.fps + 5) / 10 : 99, 0); - } else if (led == 8) { - y = 2; - x = 98; - putnumbers (x, y, gui_data.idle <= 999 ? gui_data.idle / 10 : 99, 0); - } - lgLcdUpdateBitmap (device, lbh, LGLCD_ASYNC_UPDATE (LGLCD_PRIORITY_NORMAL + 1)); + lgLcdUpdateBitmap (device, lbh, LGLCD_ASYNC_UPDATE (LGLCD_PRIORITY_NORMAL + 1)); } int lcd_open (void) { - if (!inited) { - if (!lcd_init ()) - return 0; - inited = 1; - } - return 1; + if (!inited) { + if (!lcd_init ()) + return 0; + inited = 1; + } + return 1; } #endif diff --git a/od-win32/midi.c b/od-win32/midi.c index 8a978a01..9001261c 100644 --- a/od-win32/midi.c +++ b/od-win32/midi.c @@ -1,20 +1,20 @@ /* - * MODULE: midi.c - * - * DESCRIPTION: MIDI-handling code for MIDI-I/O. Parses the MIDI-output stream and - * sends system-exclusive MIDI-messages out using midiOutLongMsg(), while using - * midiOutShortMsg() for normal MIDI-messages. MIDI-input is passed byte-for-byte - * up to the Amiga's serial-port. - * - * AUTHOR: Brian_King@CodePoet.com - * - * COPYRIGHT: Copyright 1999, 2000 under GNU Public License - * - * HISTORY: - * 1999.09.05 1.0 Brian King - creation - * 2000.01.30 1.1 Brian King - addition of midi-input - * 2002.05.xx 1.2 Bernd Roesch - sysex in/MTC/Song Position pointer add - */ +* MODULE: midi.c +* +* DESCRIPTION: MIDI-handling code for MIDI-I/O. Parses the MIDI-output stream and +* sends system-exclusive MIDI-messages out using midiOutLongMsg(), while using +* midiOutShortMsg() for normal MIDI-messages. MIDI-input is passed byte-for-byte +* up to the Amiga's serial-port. +* +* AUTHOR: Brian_King@CodePoet.com +* +* COPYRIGHT: Copyright 1999, 2000 under GNU Public License +* +* HISTORY: +* 1999.09.05 1.0 Brian King - creation +* 2000.01.30 1.1 Brian King - addition of midi-input +* 2002.05.xx 1.2 Bernd Roesch - sysex in/MTC/Song Position pointer add +*/ #include "sysconfig.h" #include @@ -45,9 +45,9 @@ #define TRACE(x) #endif #define MIDI_INBUFFERS 800 //use 13 MB Buffer with this settings - //on my system it work ok with 10 but who - //know when windows rest for a while - //with sysex size of 40 win can 8 sec sleep +//on my system it work ok with 10 but who +//know when windows rest for a while +//with sysex size of 40 win can 8 sec sleep #define INBUFFLEN 16000 //if this is not enough a warning come static int overflow,only_one_time; BOOL midi_ready = FALSE; @@ -75,632 +75,632 @@ static int out_allocated = 0; static volatile exitin = 0; static CRITICAL_SECTION cs_proc; /* - * FUNCTION: getmidiouterr - * - * PURPOSE: Wrapper for midiOutGetErrorText() - * - * PARAMETERS: - * err Midi-out error number - * - * RETURNS: - * MidiOutErrorMsg char-ptr - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: getmidiouterr +* +* PURPOSE: Wrapper for midiOutGetErrorText() +* +* PARAMETERS: +* err Midi-out error number +* +* RETURNS: +* MidiOutErrorMsg char-ptr +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static TCHAR *getmidiouterr(TCHAR *txt, int err) { - midiOutGetErrorText(err, txt, MAX_DPATH); - return txt; + midiOutGetErrorText(err, txt, MAX_DPATH); + return txt; } /* - * FUNCTION: MidiOut_Alloc - * - * PURPOSE: Allocate the double-buffering needed for processing midi-out messages - * - * PARAMETERS: none - * - * RETURNS: - * allocated - the number of buffers allocated - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: MidiOut_Alloc +* +* PURPOSE: Allocate the double-buffering needed for processing midi-out messages +* +* PARAMETERS: none +* +* RETURNS: +* allocated - the number of buffers allocated +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static int MidiOut_Alloc(void) { - int i; - - if(!out_allocated) { - for(i = 0; i < MIDI_BUFFERS; i++) { - if(!outbuffer[i]) { - outbuffer[i] = (char*)xmalloc(BUFFLEN); - if(outbuffer[i]) { - outbufferlength[i] = BUFFLEN; - out_allocated++; - } else { - outbufferlength[i] = 0; + int i; + + if(!out_allocated) { + for(i = 0; i < MIDI_BUFFERS; i++) { + if(!outbuffer[i]) { + outbuffer[i] = (char*)xmalloc(BUFFLEN); + if(outbuffer[i]) { + outbufferlength[i] = BUFFLEN; + out_allocated++; + } else { + outbufferlength[i] = 0; + } + } } - } + outbufferselect = 0; + } else { + write_log (L"MIDI: ERROR - MidiOutAlloc() called twice?\n"); } - outbufferselect = 0; - } else { - write_log (L"MIDI: ERROR - MidiOutAlloc() called twice?\n"); - } - return out_allocated; + return out_allocated; } /* - * FUNCTION: MidiOut_Free - * - * PURPOSE: Free the double-buffering needed for processing midi-out messages - * - * PARAMETERS: none - * - * RETURNS: none - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: MidiOut_Free +* +* PURPOSE: Free the double-buffering needed for processing midi-out messages +* +* PARAMETERS: none +* +* RETURNS: none +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static void MidiOut_Free(void) { - int i; + int i; - for(i = 0; i < out_allocated; i++) { - if(outbuffer[i]) { - free(outbuffer[i]); - outbufferlength[i] = 0; - outbuffer[i] = NULL; + for(i = 0; i < out_allocated; i++) { + if(outbuffer[i]) { + free(outbuffer[i]); + outbufferlength[i] = 0; + outbuffer[i] = NULL; + } } - } - outbufferselect = 0; - out_allocated = 0; + outbufferselect = 0; + out_allocated = 0; } /* - * FUNCTION: MidiOut_PrepareHeader - * - * PURPOSE: Wrapper for midiOutPrepareHeader - * - * PARAMETERS: - * midihdr - MIDIHDR-ptr which we will prepare - * data - byte-ptr to data which MIDIHDR will contain - * length - length of data - * - * RETURNS: - * result - 1 for success, 0 otherwise - * - * NOTES: none - * - * HISTORY: - * 1999.08.02 1.0 Brian King - Creation - * - */ +* FUNCTION: MidiOut_PrepareHeader +* +* PURPOSE: Wrapper for midiOutPrepareHeader +* +* PARAMETERS: +* midihdr - MIDIHDR-ptr which we will prepare +* data - byte-ptr to data which MIDIHDR will contain +* length - length of data +* +* RETURNS: +* result - 1 for success, 0 otherwise +* +* NOTES: none +* +* HISTORY: +* 1999.08.02 1.0 Brian King - Creation +* +*/ static int MidiOut_PrepareHeader(LPMIDIHDR out, LPSTR data, DWORD length) { - int result = 1; - TCHAR err[MAX_DPATH]; - - out->lpData = data; - out->dwBufferLength = length; - out->dwBytesRecorded = length; - out->dwUser = 0; - out->dwFlags = 0; - - if((result = midiOutPrepareHeader(outHandle, out, sizeof( MIDIHDR)))) { - write_log (L"MIDI: error %s / %d\n", getmidiouterr (err, result), result); - result = 0; - } - return result; + int result = 1; + TCHAR err[MAX_DPATH]; + + out->lpData = data; + out->dwBufferLength = length; + out->dwBytesRecorded = length; + out->dwUser = 0; + out->dwFlags = 0; + + if((result = midiOutPrepareHeader(outHandle, out, sizeof( MIDIHDR)))) { + write_log (L"MIDI: error %s / %d\n", getmidiouterr (err, result), result); + result = 0; + } + return result; } /* MIDI INPUT */ /* - * FUNCTION: getmidiinerr - * - * PURPOSE: Wrapper for midiInGetErrorText() - * - * PARAMETERS: - * err Midi-in error number - * - * RETURNS: - * MidiInErrorMsg char-ptr - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: getmidiinerr +* +* PURPOSE: Wrapper for midiInGetErrorText() +* +* PARAMETERS: +* err Midi-in error number +* +* RETURNS: +* MidiInErrorMsg char-ptr +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static TCHAR *getmidiinerr(TCHAR *txt, int err) { - midiInGetErrorText(err, txt, MAX_DPATH); - return txt; + midiInGetErrorText(err, txt, MAX_DPATH); + return txt; } /* - * FUNCTION: MidiIn_Alloc - * - * PURPOSE: Allocate the double-buffering needed for processing midi-out messages - * - * PARAMETERS: none - * - * RETURNS: - * allocated - the number of buffers allocated - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: MidiIn_Alloc +* +* PURPOSE: Allocate the double-buffering needed for processing midi-out messages +* +* PARAMETERS: none +* +* RETURNS: +* allocated - the number of buffers allocated +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static int MidiIn_Alloc(void) { - int i; - - if(!in_allocated) { - for(i = 0; i < MIDI_INBUFFERS; i++) { - if(!inbuffer[i]) { - inbuffer[i] = (char*)xmalloc(INBUFFLEN); - if(inbuffer[i]) { - inbufferlength[i] = INBUFFLEN; - in_allocated++; - } else { - inbufferlength[i] = 0; + int i; + + if(!in_allocated) { + for(i = 0; i < MIDI_INBUFFERS; i++) { + if(!inbuffer[i]) { + inbuffer[i] = (char*)xmalloc(INBUFFLEN); + if(inbuffer[i]) { + inbufferlength[i] = INBUFFLEN; + in_allocated++; + } else { + inbufferlength[i] = 0; + } + } } - } + } else { + write_log (L"MIDI: ERROR - MidiInAlloc() called twice?\n"); } - } else { - write_log (L"MIDI: ERROR - MidiInAlloc() called twice?\n"); - } - return in_allocated; + return in_allocated; } /* - * FUNCTION: MidiIn_Free - * - * PURPOSE: Free the double-buffering needed for processing midi-in messages - * - * PARAMETERS: none - * - * RETURNS: none - * - * NOTES: none - * - * HISTORY: - * 1999.09.06 1.0 Brian King - Creation - * - */ +* FUNCTION: MidiIn_Free +* +* PURPOSE: Free the double-buffering needed for processing midi-in messages +* +* PARAMETERS: none +* +* RETURNS: none +* +* NOTES: none +* +* HISTORY: +* 1999.09.06 1.0 Brian King - Creation +* +*/ static void MidiIn_Free( void ) { - int i; - - for( i = 0; i < in_allocated; i++ ) { - if(inbuffer[i]) { - //in_allocated--; - free(inbuffer[i]); - inbufferlength[i] = 0; - inbuffer[i] = NULL; + int i; + + for( i = 0; i < in_allocated; i++ ) { + if(inbuffer[i]) { + //in_allocated--; + free(inbuffer[i]); + inbufferlength[i] = 0; + inbuffer[i] = NULL; + } } - } - in_allocated = 0; - only_one_time = 0; + in_allocated = 0; + only_one_time = 0; } static uae_u8 plen[128] = { - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 1,1,2,1,0,0,0,0,0,0,0,0,0,0,0,0 + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 1,1,2,1,0,0,0,0,0,0,0,0,0,0,0,0 }; #define DBGOUT_MIDI_BYTE(x) TRACE(( "MIDI: 0x%02x\n", (x) )) /* - * FUNCTION: Midi_Parse - * - * PURPOSE: Parse the MIDI data-stream based on the direction. - * - * PARAMETERS: - * direction - Either midi_input or midi_output - * data - byte of MIDI data - * - * RETURNS: none - * - * NOTES: Written with much assistance from Todor Fay of Blue Ribbon - * (Bars'n'Pipes) fame. - * - * HISTORY: - * 1999.08.02 1.0 Brian King - Creation - * - */ +* FUNCTION: Midi_Parse +* +* PURPOSE: Parse the MIDI data-stream based on the direction. +* +* PARAMETERS: +* direction - Either midi_input or midi_output +* data - byte of MIDI data +* +* RETURNS: none +* +* NOTES: Written with much assistance from Todor Fay of Blue Ribbon +* (Bars'n'Pipes) fame. +* +* HISTORY: +* 1999.08.02 1.0 Brian King - Creation +* +*/ int Midi_Parse(midi_direction_e direction, BYTE *dataptr) { - int result = 0; - static unsigned short bufferindex; - static uae_u8 *bufferpoint = 0; - - if(direction == midi_output) { - BYTE data = *dataptr; - DBGOUT_MIDI_BYTE(data); - if(data >= 0x80) { - if(data >= MIDI_CLOCK) { - switch(data) - { - case MIDI_CLOCK: - TRACE(( "MIDI: MIDI_CLOCK\n" )); - break; - case MIDI_START: - TRACE(( "MIDI: MIDI_START\n" )); - break; - case MIDI_CONTINUE: - TRACE(( "MIDI: MIDI_CONTINUE\n" )); - break; - case MIDI_STOP: - TRACE(( "MIDI: MIDI_STOP\n" )); - break; - default: - break; - } - } else if(out_status.sysex) { - if(out_allocated) { - bufferpoint[bufferindex++] = (char)MIDI_EOX; - if(bufferindex >= BUFFLEN) - bufferindex = BUFFLEN - 1; - out_status.status = MIDI_SYSX; - // Flush this buffer using midiOutLongMsg - MidiOut_PrepareHeader(&midiout[outbufferselect], bufferpoint, bufferindex); - midiOutLongMsg(outHandle, &midiout[outbufferselect], sizeof(MIDIHDR)); - outbufferselect = !outbufferselect; - bufferpoint = outbuffer[outbufferselect]; - midiOutUnprepareHeader(outHandle, &midiout[outbufferselect], sizeof(MIDIHDR)); + int result = 0; + static unsigned short bufferindex; + static uae_u8 *bufferpoint = 0; + + if(direction == midi_output) { + BYTE data = *dataptr; + DBGOUT_MIDI_BYTE(data); + if(data >= 0x80) { + if(data >= MIDI_CLOCK) { + switch(data) + { + case MIDI_CLOCK: + TRACE(( "MIDI: MIDI_CLOCK\n" )); + break; + case MIDI_START: + TRACE(( "MIDI: MIDI_START\n" )); + break; + case MIDI_CONTINUE: + TRACE(( "MIDI: MIDI_CONTINUE\n" )); + break; + case MIDI_STOP: + TRACE(( "MIDI: MIDI_STOP\n" )); + break; + default: + break; + } + } else if(out_status.sysex) { + if(out_allocated) { + bufferpoint[bufferindex++] = (char)MIDI_EOX; + if(bufferindex >= BUFFLEN) + bufferindex = BUFFLEN - 1; + out_status.status = MIDI_SYSX; + // Flush this buffer using midiOutLongMsg + MidiOut_PrepareHeader(&midiout[outbufferselect], bufferpoint, bufferindex); + midiOutLongMsg(outHandle, &midiout[outbufferselect], sizeof(MIDIHDR)); + outbufferselect = !outbufferselect; + bufferpoint = outbuffer[outbufferselect]; + midiOutUnprepareHeader(outHandle, &midiout[outbufferselect], sizeof(MIDIHDR)); + } + out_status.sysex = 0; // turn off MIDI_SYSX mode + out_status.unknown = 1; // now in an unknown state + if(data == MIDI_EOX) + return 0; + } + out_status.status = data; + out_status.length = plen[data & 0x7F]; + out_status.posn = 0; + out_status.unknown = 0; + if(data == MIDI_SYSX) { + out_status.sysex = 1; // turn on MIDI_SYSX mode + if(out_allocated) { + bufferindex = 0; + bufferpoint = outbuffer[outbufferselect]; + bufferpoint[bufferindex++] = (char)MIDI_SYSX; + } + return 0; + } + } else if(out_status.sysex) { + if(out_allocated) { + bufferpoint[bufferindex++] = data; + if(bufferindex >= BUFFLEN) + bufferindex = BUFFLEN - 1; + } + return 0; + } else if(out_status.unknown) { + return 0; + } else if(++out_status.posn == 1) { + out_status.byte1 = data; + } else { + out_status.byte2 = data; } - out_status.sysex = 0; // turn off MIDI_SYSX mode - out_status.unknown = 1; // now in an unknown state - if(data == MIDI_EOX) - return 0; - } - out_status.status = data; - out_status.length = plen[data & 0x7F]; - out_status.posn = 0; - out_status.unknown = 0; - if(data == MIDI_SYSX) { - out_status.sysex = 1; // turn on MIDI_SYSX mode - if(out_allocated) { - bufferindex = 0; - bufferpoint = outbuffer[outbufferselect]; - bufferpoint[bufferindex++] = (char)MIDI_SYSX; + if(out_status.posn >= out_status.length) { + DWORD shortMsg; + out_status.posn = 0; + // flush the packet using midiOutShortMessage + shortMsg = MAKELONG(MAKEWORD(out_status.status, out_status.byte1), MAKEWORD(out_status.byte2, 0)); + midiOutShortMsg(outHandle, shortMsg); } - return 0; - } - } else if(out_status.sysex) { - if(out_allocated) { - bufferpoint[bufferindex++] = data; - if(bufferindex >= BUFFLEN) - bufferindex = BUFFLEN - 1; - } - return 0; - } else if(out_status.unknown) { - return 0; - } else if(++out_status.posn == 1) { - out_status.byte1 = data; - } else { - out_status.byte2 = data; - } - if(out_status.posn >= out_status.length) { - DWORD shortMsg; - out_status.posn = 0; - // flush the packet using midiOutShortMessage - shortMsg = MAKELONG(MAKEWORD(out_status.status, out_status.byte1), MAKEWORD(out_status.byte2, 0)); - midiOutShortMsg(outHandle, shortMsg); - } - } else { // handle input-data + } else { // handle input-data - } - return result; + } + return result; } /* - * FUNCTION: MidiIn support and Callback function - * - * PURPOSE: Translate Midi in messages to raw serial data +* FUNCTION: MidiIn support and Callback function +* +* PURPOSE: Translate Midi in messages to raw serial data - * NOTES: Sysex in not supported +* NOTES: Sysex in not supported - */ +*/ static uae_u8 midibuf[BUFFLEN]; static long midi_inptr = 0, midi_inlast = 0; static void add1byte(DWORD_PTR w) //put 1 Byte to Midibuffer { - if(midi_inlast >= BUFFLEN - 10) { - TRACE(("add1byte buffer full %d %d (%02X)\n", midi_inlast, midi_inptr, w)); - return; - } - midibuf[midi_inlast++] = (uae_u8)w; + if(midi_inlast >= BUFFLEN - 10) { + TRACE(("add1byte buffer full %d %d (%02X)\n", midi_inlast, midi_inptr, w)); + return; + } + midibuf[midi_inlast++] = (uae_u8)w; } static void add2byte(DWORD_PTR w) //put 2 Byte to Midibuffer { - if(midi_inlast >= BUFFLEN - 10) { - TRACE(("add2byte buffer full %d %d (%04X)\n", midi_inlast, midi_inptr, w)); - return; - } - midibuf[midi_inlast++] = (uae_u8)w; - w = w >> 8; - midibuf[midi_inlast++] = (uae_u8)w; + if(midi_inlast >= BUFFLEN - 10) { + TRACE(("add2byte buffer full %d %d (%04X)\n", midi_inlast, midi_inptr, w)); + return; + } + midibuf[midi_inlast++] = (uae_u8)w; + w = w >> 8; + midibuf[midi_inlast++] = (uae_u8)w; } static void add3byte(DWORD_PTR w) //put 3 Byte to Midibuffer { - if(midi_inlast >= BUFFLEN - 10) { - TRACE(("add3byte buffer full %d %d (%08X)\n", midi_inlast, midi_inptr, w)); - return; - } - midibuf[midi_inlast++] = (uae_u8)w; - w = w >> 8; - midibuf[midi_inlast++] = (uae_u8)w; - w = w >> 8; - midibuf[midi_inlast++] = (uae_u8)w; + if(midi_inlast >= BUFFLEN - 10) { + TRACE(("add3byte buffer full %d %d (%08X)\n", midi_inlast, midi_inptr, w)); + return; + } + midibuf[midi_inlast++] = (uae_u8)w; + w = w >> 8; + midibuf[midi_inlast++] = (uae_u8)w; + w = w >> 8; + midibuf[midi_inlast++] = (uae_u8)w; } int ismidibyte(void) { - if (midi_inptr < midi_inlast) - return 1; - return 0; + if (midi_inptr < midi_inlast) + return 1; + return 0; } LONG getmidibyte(void) //return midibyte or -1 if none { - int i; - LONG rv; - - EnterCriticalSection (&cs_proc); - if (overflow == 1) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString(IDS_MIDIOVERFLOW, szMessage, MAX_DPATH); - gui_message(szMessage); - overflow = 0; - } - TRACE(("getmidibyte(%02X)\n", midibuf[midi_inptr])); - if (midibuf[midi_inptr] >= 0xf0) { // only check for free buffers if status sysex - for (i = 0;i < MIDI_INBUFFERS;i++) { - if (midiin[i].dwFlags == (MHDR_DONE|MHDR_PREPARED)) { - // add a buffer if one is free - LeaveCriticalSection(&cs_proc); - midiInAddBuffer(inHandle, &midiin[i], sizeof(MIDIHDR)); - EnterCriticalSection(&cs_proc); - } + int i; + LONG rv; + + EnterCriticalSection (&cs_proc); + if (overflow == 1) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString(IDS_MIDIOVERFLOW, szMessage, MAX_DPATH); + gui_message(szMessage); + overflow = 0; + } + TRACE(("getmidibyte(%02X)\n", midibuf[midi_inptr])); + if (midibuf[midi_inptr] >= 0xf0) { // only check for free buffers if status sysex + for (i = 0;i < MIDI_INBUFFERS;i++) { + if (midiin[i].dwFlags == (MHDR_DONE|MHDR_PREPARED)) { + // add a buffer if one is free + LeaveCriticalSection(&cs_proc); + midiInAddBuffer(inHandle, &midiin[i], sizeof(MIDIHDR)); + EnterCriticalSection(&cs_proc); + } + } } - } - rv = -1; - if (midi_inptr < midi_inlast) - rv = midibuf[midi_inptr++]; - if (midi_inptr >= midi_inlast) - midi_inptr = midi_inlast = 0; - LeaveCriticalSection(&cs_proc); - return rv; + rv = -1; + if (midi_inptr < midi_inlast) + rv = midibuf[midi_inptr++]; + if (midi_inptr >= midi_inlast) + midi_inptr = midi_inlast = 0; + LeaveCriticalSection(&cs_proc); + return rv; } static void CALLBACK MidiInProc(HMIDIIN hMidiIn,UINT wMsg,DWORD_PTR dwInstance,DWORD_PTR dwParam1,DWORD_PTR dwParam2) { - EnterCriticalSection (&cs_proc); - if(wMsg == MIM_ERROR) { - TRACE(("MIDI Data Lost\n")); - } - if(wMsg == MIM_LONGDATA) { - LPMIDIHDR midiin = (LPMIDIHDR)dwParam1; - static long synum; - TRACE(("MIM_LONGDATA bytes=%d ts=%u\n", midiin->dwBytesRecorded, dwParam2)); - if (exitin == 1) - goto end; //for safeness midi want close - if ((midi_inlast + midiin->dwBytesRecorded) >= (BUFFLEN-6)) { - overflow = 1; - TRACE(("MIDI overflow1\n")); - //for safeness if buffer too full (should not occur) - goto end; + EnterCriticalSection (&cs_proc); + if(wMsg == MIM_ERROR) { + TRACE(("MIDI Data Lost\n")); } - if (midiin->dwBufferLength == midiin->dwBytesRecorded) { - //for safeness if buffer too full (should not occur) - overflow = 1; - TRACE(("MIDI overflow2\n")); - goto end; + if(wMsg == MIM_LONGDATA) { + LPMIDIHDR midiin = (LPMIDIHDR)dwParam1; + static long synum; + TRACE(("MIM_LONGDATA bytes=%d ts=%u\n", midiin->dwBytesRecorded, dwParam2)); + if (exitin == 1) + goto end; //for safeness midi want close + if ((midi_inlast + midiin->dwBytesRecorded) >= (BUFFLEN-6)) { + overflow = 1; + TRACE(("MIDI overflow1\n")); + //for safeness if buffer too full (should not occur) + goto end; + } + if (midiin->dwBufferLength == midiin->dwBytesRecorded) { + //for safeness if buffer too full (should not occur) + overflow = 1; + TRACE(("MIDI overflow2\n")); + goto end; + } + memcpy(&midibuf[midi_inlast], midiin->lpData, midiin->dwBytesRecorded); + midi_inlast = midi_inlast + midiin->dwBytesRecorded; } - memcpy(&midibuf[midi_inlast], midiin->lpData, midiin->dwBytesRecorded); - midi_inlast = midi_inlast + midiin->dwBytesRecorded; - } - - if(wMsg == MM_MIM_DATA || wMsg == MM_MIM_MOREDATA) { - BYTE state = (BYTE)dwParam1; - TRACE(("%s %08X\n", wMsg == MM_MIM_DATA ? "MM_MIM_DATA" : "MM_MIM_MOREDATA", dwParam1)); - if(state == 254) - goto end; - if(state < 0xf0) - state = state & 0xf0; - switch (state) - { - case 0x80: //Note OFF - add3byte(dwParam1); - break; - case 0x90: // Note On - add3byte(dwParam1); - break; - case 0xa0: // Poly Press - add3byte(dwParam1); - break; - case 0xb0: //CTRL Change - add3byte(dwParam1); - break; - case 0xc0: //ProgramChange - add2byte(dwParam1); - break; - case 0xd0: //ChanPress - add2byte(dwParam1); - break; - case 0xe0: //PitchBend - add3byte(dwParam1); - break; - //System Common Messages - case 0xf1: //QuarterFrame-message ... MIDI_Time_Code - add2byte(dwParam1); - break; - case 0xf2: //Song Position - add3byte(dwParam1); - break; - case 0xf3: //Song Select - add2byte(dwParam1); - break; - case 0xf6: //Tune Request - add3byte(dwParam1); - break; - //System Real Time Messages - case 0xf8: //MIDI-Clock - add1byte((char)dwParam1); - break; - case 0xfa: //Start - add1byte((char)dwParam1); - break; - case 0xfb: //Continue - add1byte((char)dwParam1); - break; - case 0xfc: //Stop - add1byte((char)dwParam1); - break; - case 0xfe: //Active Sense (selden used) - add1byte((char)dwParam1); - break; - case 0xff: //Reset (selden used) - add2byte(dwParam1); - break; + + if(wMsg == MM_MIM_DATA || wMsg == MM_MIM_MOREDATA) { + BYTE state = (BYTE)dwParam1; + TRACE(("%s %08X\n", wMsg == MM_MIM_DATA ? "MM_MIM_DATA" : "MM_MIM_MOREDATA", dwParam1)); + if(state == 254) + goto end; + if(state < 0xf0) + state = state & 0xf0; + switch (state) + { + case 0x80: //Note OFF + add3byte(dwParam1); + break; + case 0x90: // Note On + add3byte(dwParam1); + break; + case 0xa0: // Poly Press + add3byte(dwParam1); + break; + case 0xb0: //CTRL Change + add3byte(dwParam1); + break; + case 0xc0: //ProgramChange + add2byte(dwParam1); + break; + case 0xd0: //ChanPress + add2byte(dwParam1); + break; + case 0xe0: //PitchBend + add3byte(dwParam1); + break; + //System Common Messages + case 0xf1: //QuarterFrame-message ... MIDI_Time_Code + add2byte(dwParam1); + break; + case 0xf2: //Song Position + add3byte(dwParam1); + break; + case 0xf3: //Song Select + add2byte(dwParam1); + break; + case 0xf6: //Tune Request + add3byte(dwParam1); + break; + //System Real Time Messages + case 0xf8: //MIDI-Clock + add1byte((char)dwParam1); + break; + case 0xfa: //Start + add1byte((char)dwParam1); + break; + case 0xfb: //Continue + add1byte((char)dwParam1); + break; + case 0xfc: //Stop + add1byte((char)dwParam1); + break; + case 0xfe: //Active Sense (selden used) + add1byte((char)dwParam1); + break; + case 0xff: //Reset (selden used) + add2byte(dwParam1); + break; + } } - } end: - LeaveCriticalSection(&cs_proc); - } + LeaveCriticalSection(&cs_proc); +} /* - * FUNCTION: Midi_Open - * - * PURPOSE: Open the desired MIDI handles (output, and possibly input) - * - * PARAMETERS: none - * - * RETURNS: - * result - 1 for success, 0 for failure - * - * NOTES: none - * - * HISTORY: - * 1999.08.02 1.0 Brian King - Creation - * - */ +* FUNCTION: Midi_Open +* +* PURPOSE: Open the desired MIDI handles (output, and possibly input) +* +* PARAMETERS: none +* +* RETURNS: +* result - 1 for success, 0 for failure +* +* NOTES: none +* +* HISTORY: +* 1999.08.02 1.0 Brian King - Creation +* +*/ int Midi_Open(void) { - unsigned long result = 0, i; - TCHAR err[MAX_DPATH]; - - if((result = midiOutOpen(&outHandle, currprefs.win32_midioutdev, 0, 0,CALLBACK_NULL))) { - write_log (L"MIDI OUT: error %s / %d while opening port %d\n", getmidiouterr(err, result), result, currprefs.win32_midioutdev); - result = 0; - } else { - InitializeCriticalSection(&cs_proc); - // We don't need input for output... - if((currprefs.win32_midiindev >= 0) && - (result = midiInOpen( &inHandle, currprefs.win32_midiindev, (DWORD_PTR)MidiInProc, 0, CALLBACK_FUNCTION|MIDI_IO_STATUS))) { - write_log (L"MIDI IN: error %s / %d while opening port %d\n", getmidiinerr(err, result), result, currprefs.win32_midiindev); + unsigned long result = 0, i; + TCHAR err[MAX_DPATH]; + + if((result = midiOutOpen(&outHandle, currprefs.win32_midioutdev, 0, 0,CALLBACK_NULL))) { + write_log (L"MIDI OUT: error %s / %d while opening port %d\n", getmidiouterr(err, result), result, currprefs.win32_midioutdev); + result = 0; } else { - midi_in_ready = TRUE; - result=midiInStart(inHandle); - } + InitializeCriticalSection(&cs_proc); + // We don't need input for output... + if((currprefs.win32_midiindev >= 0) && + (result = midiInOpen( &inHandle, currprefs.win32_midiindev, (DWORD_PTR)MidiInProc, 0, CALLBACK_FUNCTION|MIDI_IO_STATUS))) { + write_log (L"MIDI IN: error %s / %d while opening port %d\n", getmidiinerr(err, result), result, currprefs.win32_midiindev); + } else { + midi_in_ready = TRUE; + result=midiInStart(inHandle); + } - if(MidiOut_Alloc()) { - if(midi_in_ready) { - if(!MidiIn_Alloc()) { - midiInClose(inHandle); - midi_in_ready = FALSE; + if(MidiOut_Alloc()) { + if(midi_in_ready) { + if(!MidiIn_Alloc()) { + midiInClose(inHandle); + midi_in_ready = FALSE; + } else { + for (i = 0;i < MIDI_INBUFFERS; i++) { + midiin[i].lpData = inbuffer[i]; + midiin[i].dwBufferLength = INBUFFLEN - 1; + midiin[i].dwBytesRecorded = INBUFFLEN - 1; + midiin[i].dwUser = 0; + midiin[i].dwFlags = 0; + result=midiInPrepareHeader(inHandle, &midiin[i], sizeof(MIDIHDR)); + result=midiInAddBuffer(inHandle, &midiin[i], sizeof(MIDIHDR)); + } + } + } + midi_ready = TRUE; + result = 1; + serdev = 1; } else { - for (i = 0;i < MIDI_INBUFFERS; i++) { - midiin[i].lpData = inbuffer[i]; - midiin[i].dwBufferLength = INBUFFLEN - 1; - midiin[i].dwBytesRecorded = INBUFFLEN - 1; - midiin[i].dwUser = 0; - midiin[i].dwFlags = 0; - result=midiInPrepareHeader(inHandle, &midiin[i], sizeof(MIDIHDR)); - result=midiInAddBuffer(inHandle, &midiin[i], sizeof(MIDIHDR)); - } + midiOutClose(outHandle); + if(midi_in_ready) { + midiInClose(inHandle); + midi_in_ready = FALSE; + } + result = 0; + DeleteCriticalSection(&cs_proc); } - } - midi_ready = TRUE; - result = 1; - serdev = 1; - } else { - midiOutClose(outHandle); - if(midi_in_ready) { - midiInClose(inHandle); - midi_in_ready = FALSE; - } - result = 0; - DeleteCriticalSection(&cs_proc); } - } - return result; + return result; } /* - * FUNCTION: Midi_Close - * - * PURPOSE: Close all opened MIDI handles - * - * PARAMETERS: none - * - * RETURNS: none - * - * NOTES: none - * - * HISTORY: - * 1999.08.02 1.0 Brian King - Creation - * - */ +* FUNCTION: Midi_Close +* +* PURPOSE: Close all opened MIDI handles +* +* PARAMETERS: none +* +* RETURNS: none +* +* NOTES: none +* +* HISTORY: +* 1999.08.02 1.0 Brian King - Creation +* +*/ void Midi_Close(void) { - int i; - if(midi_ready) { - midiOutReset(outHandle); - for(i = 0; i < MIDI_BUFFERS; i++) { - while(MIDIERR_STILLPLAYING == midiOutUnprepareHeader(outHandle, &midiout[i], sizeof(MIDIHDR))) { - Sleep(10); - } - } - MidiOut_Free(); - midiOutClose(outHandle); - - if(midi_in_ready) { - exitin = 1; //for safeness sure no callback come now - midiInReset(inHandle); - for (i = 0; i < MIDI_INBUFFERS; i++) { - midiInUnprepareHeader(inHandle, &midiin[i], sizeof(MIDIHDR)); - } - MidiIn_Free(); - midiInClose(inHandle); - midi_in_ready = FALSE; - exitin = 0; + int i; + if(midi_ready) { + midiOutReset(outHandle); + for(i = 0; i < MIDI_BUFFERS; i++) { + while(MIDIERR_STILLPLAYING == midiOutUnprepareHeader(outHandle, &midiout[i], sizeof(MIDIHDR))) { + Sleep(10); + } + } + MidiOut_Free(); + midiOutClose(outHandle); + + if(midi_in_ready) { + exitin = 1; //for safeness sure no callback come now + midiInReset(inHandle); + for (i = 0; i < MIDI_INBUFFERS; i++) { + midiInUnprepareHeader(inHandle, &midiin[i], sizeof(MIDIHDR)); + } + MidiIn_Free(); + midiInClose(inHandle); + midi_in_ready = FALSE; + exitin = 0; + } + midi_ready = FALSE; + write_log (L"MIDI: closed.\n"); + DeleteCriticalSection(&cs_proc); } - midi_ready = FALSE; - write_log (L"MIDI: closed.\n"); - DeleteCriticalSection(&cs_proc); - } } diff --git a/od-win32/mman.c b/od-win32/mman.c index 7d609c82..c2dac551 100644 --- a/od-win32/mman.c +++ b/od-win32/mman.c @@ -27,662 +27,662 @@ int maxmem; static void *virtualallocwithlock (LPVOID addr, SIZE_T size, DWORD allocationtype, DWORD protect) { - void *p = VirtualAlloc (addr, size, allocationtype, protect); - return p; + void *p = VirtualAlloc (addr, size, allocationtype, protect); + return p; } static void virtualfreewithlock (LPVOID addr, SIZE_T size, DWORD freetype) { - VirtualFree(addr, size, freetype); + VirtualFree(addr, size, freetype); } void cache_free (void *cache) { - virtualfreewithlock (cache, 0, MEM_RELEASE); + virtualfreewithlock (cache, 0, MEM_RELEASE); } void *cache_alloc (int size) { - return virtualallocwithlock (NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + return virtualallocwithlock (NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); } #if 0 static void setworkingset(void) { - typedef BOOL (CALLBACK* SETPROCESSWORKINGSETSIZE)(HANDLE,SIZE_T,SIZE_T); - SETPROCESSWORKINGSETSIZE pSetProcessWorkingSetSize; - pSetProcessWorkingSetSize = (SETPROCESSWORKINGSETSIZE)GetProcAddress(GetModuleHandle("kernal32.dll", "GetProcessWorkingSetSize"); - if (!pSetProcessWorkingSetSize) - return; - pSetProcessWorkingSetSize(GetCurrentProcess (), -); + typedef BOOL (CALLBACK* SETPROCESSWORKINGSETSIZE)(HANDLE,SIZE_T,SIZE_T); + SETPROCESSWORKINGSETSIZE pSetProcessWorkingSetSize; + pSetProcessWorkingSetSize = (SETPROCESSWORKINGSETSIZE)GetProcAddress(GetModuleHandle("kernal32.dll", "GetProcessWorkingSetSize"); + if (!pSetProcessWorkingSetSize) + return; + pSetProcessWorkingSetSize(GetCurrentProcess (), + ); #endif -static uae_u32 lowmem (void) -{ - uae_u32 change = 0; - if (currprefs.z3fastmem_size + currprefs.z3fastmem2_size >= 8 * 1024 * 1024) { - if (currprefs.z3fastmem2_size) { - if (currprefs.z3fastmem2_size <= 128 * 1024 * 1024) { - change = currprefs.z3fastmem2_size; - currprefs.z3fastmem2_size = 0; - } else { - change = currprefs.z3fastmem2_size / 2; - currprefs.z3fastmem2_size >>= 1; - changed_prefs.z3fastmem2_size = currprefs.z3fastmem2_size; - } - } else { - change = currprefs.z3fastmem_size - currprefs.z3fastmem_size / 4; - currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size = currprefs.z3fastmem_size / 4; - currprefs.z3fastmem_size >>= 1; - changed_prefs.z3fastmem_size = currprefs.z3fastmem_size; - } - } else if (currprefs.gfxmem_size >= 1 * 1024 * 1024) { - change = currprefs.gfxmem_size - currprefs.gfxmem_size / 2; - currprefs.gfxmem_size >>= 1; - changed_prefs.gfxmem_size = currprefs.gfxmem_size; - } - if (currprefs.z3fastmem2_size < 128 * 1024 * 1024) - currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size = 0; - return change; -} - -typedef UINT (CALLBACK* GETWRITEWATCH) - (DWORD,PVOID,SIZE_T,PVOID*,PULONG_PTR,PULONG); + static uae_u32 lowmem (void) + { + uae_u32 change = 0; + if (currprefs.z3fastmem_size + currprefs.z3fastmem2_size >= 8 * 1024 * 1024) { + if (currprefs.z3fastmem2_size) { + if (currprefs.z3fastmem2_size <= 128 * 1024 * 1024) { + change = currprefs.z3fastmem2_size; + currprefs.z3fastmem2_size = 0; + } else { + change = currprefs.z3fastmem2_size / 2; + currprefs.z3fastmem2_size >>= 1; + changed_prefs.z3fastmem2_size = currprefs.z3fastmem2_size; + } + } else { + change = currprefs.z3fastmem_size - currprefs.z3fastmem_size / 4; + currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size = currprefs.z3fastmem_size / 4; + currprefs.z3fastmem_size >>= 1; + changed_prefs.z3fastmem_size = currprefs.z3fastmem_size; + } + } else if (currprefs.gfxmem_size >= 1 * 1024 * 1024) { + change = currprefs.gfxmem_size - currprefs.gfxmem_size / 2; + currprefs.gfxmem_size >>= 1; + changed_prefs.gfxmem_size = currprefs.gfxmem_size; + } + if (currprefs.z3fastmem2_size < 128 * 1024 * 1024) + currprefs.z3fastmem2_size = changed_prefs.z3fastmem2_size = 0; + return change; + } + + typedef UINT (CALLBACK* GETWRITEWATCH) + (DWORD,PVOID,SIZE_T,PVOID*,PULONG_PTR,PULONG); #define TEST_SIZE (2 * 4096) -static int testwritewatch (void) -{ - GETWRITEWATCH pGetWriteWatch; - void *mem; - void *pages[16]; - ULONG_PTR gwwcnt; - ULONG ps; - int ret = 0; - - ps = si.dwPageSize; - - pGetWriteWatch = (GETWRITEWATCH)GetProcAddress (GetModuleHandle (L"kernel32.dll"), "GetWriteWatch"); - if (pGetWriteWatch == NULL) { - write_log (L"GetWriteWatch(): missing!?\n"); - return 0; - } - mem = VirtualAlloc (NULL, TEST_SIZE, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_EXECUTE_READWRITE); - if (mem == NULL) { - write_log (L"GetWriteWatch(): MEM_WRITE_WATCH not supported!? err=%d\n", GetLastError()); - return 0; - } - if (VirtualAlloc (mem, TEST_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE) == NULL) { - write_log (L"GetWriteWatch(): test memory area MEM_COMMIT failed!? err=%d\n", GetLastError()); - goto end; - } - ResetWriteWatch (mem, TEST_SIZE); - ((uae_u8*)mem)[1] = 0; - gwwcnt = TEST_SIZE / ps; - if (GetWriteWatch (WRITE_WATCH_FLAG_RESET, mem, TEST_SIZE, pages, &gwwcnt, &ps)) { - write_log (L"GetWriteWatch(): failed!? err=%d\n", GetLastError ()); - goto end; - } - if (ps != si.dwPageSize) { - write_log (L"GetWriteWatch(): pagesize %d != %d!?\n", si.dwPageSize, ps); - goto end; - } - if (gwwcnt != 1) { - write_log (L"GetWriteWatch(): modified pages returned %d != 1!?\n", gwwcnt); - goto end; - } - if (pages[0] != mem) { - write_log (L"GetWriteWatch(): modified page was wrong!?\n"); - goto end; - } - write_log (L"GetWriteWatch() test ok\n"); - ret = 1; - memwatchok = 1; + static int testwritewatch (void) + { + GETWRITEWATCH pGetWriteWatch; + void *mem; + void *pages[16]; + ULONG_PTR gwwcnt; + ULONG ps; + int ret = 0; + + ps = si.dwPageSize; + + pGetWriteWatch = (GETWRITEWATCH)GetProcAddress (GetModuleHandle (L"kernel32.dll"), "GetWriteWatch"); + if (pGetWriteWatch == NULL) { + write_log (L"GetWriteWatch(): missing!?\n"); + return 0; + } + mem = VirtualAlloc (NULL, TEST_SIZE, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_EXECUTE_READWRITE); + if (mem == NULL) { + write_log (L"GetWriteWatch(): MEM_WRITE_WATCH not supported!? err=%d\n", GetLastError()); + return 0; + } + if (VirtualAlloc (mem, TEST_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE) == NULL) { + write_log (L"GetWriteWatch(): test memory area MEM_COMMIT failed!? err=%d\n", GetLastError()); + goto end; + } + ResetWriteWatch (mem, TEST_SIZE); + ((uae_u8*)mem)[1] = 0; + gwwcnt = TEST_SIZE / ps; + if (GetWriteWatch (WRITE_WATCH_FLAG_RESET, mem, TEST_SIZE, pages, &gwwcnt, &ps)) { + write_log (L"GetWriteWatch(): failed!? err=%d\n", GetLastError ()); + goto end; + } + if (ps != si.dwPageSize) { + write_log (L"GetWriteWatch(): pagesize %d != %d!?\n", si.dwPageSize, ps); + goto end; + } + if (gwwcnt != 1) { + write_log (L"GetWriteWatch(): modified pages returned %d != 1!?\n", gwwcnt); + goto end; + } + if (pages[0] != mem) { + write_log (L"GetWriteWatch(): modified page was wrong!?\n"); + goto end; + } + write_log (L"GetWriteWatch() test ok\n"); + ret = 1; + memwatchok = 1; end: - if (mem) { - VirtualFree (mem, TEST_SIZE, MEM_DECOMMIT); - VirtualFree (mem, 0, MEM_RELEASE); - } - return ret; -} - -static uae_u8 *memwatchtable; - -int mman_GetWriteWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID *lpAddresses, PULONG_PTR lpdwCount, PULONG lpdwGranularity) -{ - int i, j, off; - - if (memwatchok) - return GetWriteWatch (0, lpBaseAddress, dwRegionSize, lpAddresses, lpdwCount, lpdwGranularity); - j = 0; - off = ((uae_u8*)lpBaseAddress - (natmem_offset + p96ram_start)) / si.dwPageSize; - for (i = 0; i < dwRegionSize / si.dwPageSize; i++) { - if (j >= *lpdwCount) - break; - if (memwatchtable[off + i]) - lpAddresses[j++] = (uae_u8*)lpBaseAddress + i * si.dwPageSize; - } - *lpdwCount = j; - *lpdwGranularity = si.dwPageSize; - return 0; -} -void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize) -{ - if (memwatchok) { - if (ResetWriteWatch (lpBaseAddress, dwRegionSize)) - write_log (L"ResetWriteWatch() failed, %d\n", GetLastError ()); - } else { - DWORD op; - memset (memwatchtable, 0, p96mem_size / si.dwPageSize); - if (!VirtualProtect (lpBaseAddress, dwRegionSize, PAGE_READWRITE | PAGE_GUARD, &op)) - write_log (L"VirtualProtect() failed, err=%d\n", GetLastError ()); - } -} - -int mman_guard_exception (LPEXCEPTION_POINTERS p) -{ - PEXCEPTION_RECORD record = p->ExceptionRecord; - PCONTEXT context = p->ContextRecord; - ULONG_PTR addr = record->ExceptionInformation[1]; - int rw = record->ExceptionInformation[0]; - ULONG_PTR p96addr = (ULONG_PTR)p96mem_offset; - - if (memwatchok) - return EXCEPTION_CONTINUE_SEARCH; - if (addr < p96addr || addr >= p96addr + p96mem_size) - return EXCEPTION_CONTINUE_EXECUTION; - addr -= p96addr; - addr /= si.dwPageSize; - memwatchtable[addr] = 1; - return EXCEPTION_CONTINUE_EXECUTION; -} - -static uae_u64 size64; -typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(LPMEMORYSTATUSEX); - -void preinit_shm (void) -{ - int i; - uae_u64 total64; - uae_u64 totalphys64; - MEMORYSTATUS memstats; - GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx; - MEMORYSTATUSEX memstatsex; - uae_u32 max_allowed_mman; - - GetSystemInfo (&si); - max_allowed_mman = 1536; - if (os_64bit) - max_allowed_mman = 2048; - - memstats.dwLength = sizeof(memstats); - GlobalMemoryStatus(&memstats); - totalphys64 = memstats.dwTotalPhys; - total64 = (uae_u64)memstats.dwAvailPageFile + (uae_u64)memstats.dwTotalPhys; - pGlobalMemoryStatusEx = (GLOBALMEMORYSTATUSEX)GetProcAddress (GetModuleHandle (L"kernel32.dll"), "GlobalMemoryStatusEx"); - if (pGlobalMemoryStatusEx) { - memstatsex.dwLength = sizeof (MEMORYSTATUSEX); - if (pGlobalMemoryStatusEx(&memstatsex)) { - totalphys64 = memstatsex.ullTotalPhys; - total64 = memstatsex.ullAvailPageFile + memstatsex.ullTotalPhys; + if (mem) { + VirtualFree (mem, TEST_SIZE, MEM_DECOMMIT); + VirtualFree (mem, 0, MEM_RELEASE); + } + return ret; } - } - size64 = total64; - if (maxmem < 0) - size64 = MAXZ3MEM; - else if (maxmem > 0) - size64 = maxmem * 1024 * 1024; - if (os_64bit) { - if (size64 > MAXZ3MEM) - size64 = MAXZ3MEM; - } else { - if (size64 > MAXZ3MEM) - size64 = MAXZ3MEM; - } - if (size64 < 8 * 1024 * 1024) - size64 = 8 * 1024 * 1024; - if (max_allowed_mman * 1024 * 1024 > size64) - max_allowed_mman = size64 / (1024 * 1024); - max_z3fastmem = max_allowed_mman * 1024 * 1024; - if (max_z3fastmem < 512 * 1024 * 1024) - max_z3fastmem = 512 * 1024 * 1024; - - shm_start = 0; - for (i = 0; i < MAX_SHMID; i++) { - shmids[i].attached = 0; - shmids[i].key = -1; - shmids[i].size = 0; - shmids[i].addr = NULL; - shmids[i].name[0] = 0; - } - - write_log (L"Max Z3FastRAM %dM. Total physical RAM %uM\n", max_z3fastmem >> 20, totalphys64 >> 20); - testwritewatch (); - canbang = 1; -} -static void resetmem (void) -{ - int i; - - if (!shm_start) - return; - for (i = 0; i < MAX_SHMID; i++) { - struct shmid_ds *s = &shmids[i]; - int size = s->size; - uae_u8 *shmaddr; - uae_u8 *result; - - if (!s->attached) - continue; - if (!s->natmembase) - continue; - shmaddr = natmem_offset + ((uae_u8*)s->attached - (uae_u8*)s->natmembase); - result = virtualallocwithlock (shmaddr, size, MEM_COMMIT, s->mode); - if (result != shmaddr) - write_log (L"NATMEM: realloc(%p,%d,%d) failed, err=%x\n", shmaddr, size, s->mode, GetLastError ()); - else - write_log (L"NATMEM: rellocated(%p,%d,%s)\n", shmaddr, size, s->name); - } -} - -int init_shm (void) -{ - uae_u32 size, totalsize, z3size, natmemsize, rtgbarrier, rtgextra; - int rounds = 0; + static uae_u8 *memwatchtable; -restart: - for (;;) { - int lowround = 0; - LPVOID blah = NULL; - if (rounds > 0) - write_log (L"NATMEM: retrying %d..\n", rounds); - rounds++; - if (natmem_offset) - VirtualFree(natmem_offset, 0, MEM_RELEASE); - natmem_offset = NULL; - natmem_offset_end = NULL; - canbang = 0; - - z3size = 0; - size = 0x1000000; - rtgextra = 0; - rtgbarrier = si.dwPageSize; - if (currprefs.cpu_model >= 68020) - size = 0x10000000; - if (currprefs.z3fastmem_size || currprefs.z3fastmem2_size) { - z3size = currprefs.z3fastmem_size + currprefs.z3fastmem2_size + (currprefs.z3fastmem_start - 0x10000000); - if (currprefs.gfxmem_size) - rtgbarrier = 16 * 1024 * 1024; - } else { - rtgbarrier = 0; - } - totalsize = size + z3size + currprefs.gfxmem_size; - while (totalsize > size64) { - int change = lowmem (); - if (!change) + int mman_GetWriteWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID *lpAddresses, PULONG_PTR lpdwCount, PULONG lpdwGranularity) + { + int i, j, off; + + if (memwatchok) + return GetWriteWatch (0, lpBaseAddress, dwRegionSize, lpAddresses, lpdwCount, lpdwGranularity); + j = 0; + off = ((uae_u8*)lpBaseAddress - (natmem_offset + p96ram_start)) / si.dwPageSize; + for (i = 0; i < dwRegionSize / si.dwPageSize; i++) { + if (j >= *lpdwCount) + break; + if (memwatchtable[off + i]) + lpAddresses[j++] = (uae_u8*)lpBaseAddress + i * si.dwPageSize; + } + *lpdwCount = j; + *lpdwGranularity = si.dwPageSize; return 0; - write_log (L"NATMEM: %d, %dM > %dM = %dM\n", ++lowround, totalsize >> 20, size64 >> 20, (totalsize - change) >> 20); - totalsize -= change; - } - if ((rounds > 1 && totalsize < 0x10000000) || rounds > 20) { - write_log (L"NATMEM: No special area could be allocated (3)!\n"); - return 0; - } - natmemsize = size + z3size; - - xfree (memwatchtable); - memwatchtable = 0; - if (currprefs.gfxmem_size) { - if (!memwatchok) { - write_log (L"GetWriteWatch() not supported, using guard pages, RTG performance will be slower.\n"); - memwatchtable = xcalloc (currprefs.gfxmem_size / si.dwPageSize + 1, 1); - } - } - if (currprefs.gfxmem_size) { - rtgextra = si.dwPageSize; - } else { - rtgbarrier = 0; - rtgextra = 0; - } - blah = VirtualAlloc (NULL, natmemsize + rtgbarrier + currprefs.gfxmem_size + rtgextra + 16 * si.dwPageSize, MEM_RESERVE, PAGE_READWRITE); - if (blah) { - natmem_offset = blah; - break; - } - write_log (L"NATMEM: %dM area failed to allocate, err=%d (Z3=%dM,RTG=%dM)\n", - natmemsize >> 20, GetLastError (), (currprefs.z3fastmem_size + currprefs.z3fastmem2_size) >> 20, currprefs.gfxmem_size >> 20); - if (!lowmem ()) { - write_log (L"NATMEM: No special area could be allocated (2)!\n"); - return 0; - } - } - p96mem_size = currprefs.gfxmem_size; - if (p96mem_size) { - VirtualFree (natmem_offset, 0, MEM_RELEASE); - if (!VirtualAlloc (natmem_offset, natmemsize + rtgbarrier, MEM_RESERVE, PAGE_READWRITE)) { - write_log (L"VirtualAlloc() part 2 error %d. RTG disabled.\n", GetLastError ()); - currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; - rtgbarrier = si.dwPageSize; - rtgextra = 0; - goto restart; } - p96mem_offset = VirtualAlloc (natmem_offset + natmemsize + rtgbarrier, p96mem_size + rtgextra, - MEM_RESERVE | (memwatchok == 1 ? MEM_WRITE_WATCH : 0), PAGE_READWRITE); - if (!p96mem_offset) { - currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; - write_log (L"NATMEM: failed to allocate special Picasso96 GFX RAM, err=%d\n", GetLastError ()); - } - } - - if (!natmem_offset) { - write_log (L"NATMEM: No special area could be allocated! (1) err=%d\n", GetLastError ()); - } else { - write_log (L"NATMEM: Our special area: 0x%p-0x%p (%08x %dM)\n", - natmem_offset, (uae_u8*)natmem_offset + natmemsize, - natmemsize, natmemsize >> 20); - if (currprefs.gfxmem_size) - write_log (L"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); - canbang = 1; - natmem_offset_end = p96mem_offset + currprefs.gfxmem_size; - } - - resetmem (); - - return canbang; -} - + void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize) + { + if (memwatchok) { + if (ResetWriteWatch (lpBaseAddress, dwRegionSize)) + write_log (L"ResetWriteWatch() failed, %d\n", GetLastError ()); + } else { + DWORD op; + memset (memwatchtable, 0, p96mem_size / si.dwPageSize); + if (!VirtualProtect (lpBaseAddress, dwRegionSize, PAGE_READWRITE | PAGE_GUARD, &op)) + write_log (L"VirtualProtect() failed, err=%d\n", GetLastError ()); + } + } + + int mman_guard_exception (LPEXCEPTION_POINTERS p) + { + PEXCEPTION_RECORD record = p->ExceptionRecord; + PCONTEXT context = p->ContextRecord; + ULONG_PTR addr = record->ExceptionInformation[1]; + int rw = record->ExceptionInformation[0]; + ULONG_PTR p96addr = (ULONG_PTR)p96mem_offset; + + if (memwatchok) + return EXCEPTION_CONTINUE_SEARCH; + if (addr < p96addr || addr >= p96addr + p96mem_size) + return EXCEPTION_CONTINUE_EXECUTION; + addr -= p96addr; + addr /= si.dwPageSize; + memwatchtable[addr] = 1; + return EXCEPTION_CONTINUE_EXECUTION; + } + + static uae_u64 size64; + typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(LPMEMORYSTATUSEX); + + void preinit_shm (void) + { + int i; + uae_u64 total64; + uae_u64 totalphys64; + MEMORYSTATUS memstats; + GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx; + MEMORYSTATUSEX memstatsex; + uae_u32 max_allowed_mman; + + GetSystemInfo (&si); + max_allowed_mman = 1536; + if (os_64bit) + max_allowed_mman = 2048; + + memstats.dwLength = sizeof(memstats); + GlobalMemoryStatus(&memstats); + totalphys64 = memstats.dwTotalPhys; + total64 = (uae_u64)memstats.dwAvailPageFile + (uae_u64)memstats.dwTotalPhys; + pGlobalMemoryStatusEx = (GLOBALMEMORYSTATUSEX)GetProcAddress (GetModuleHandle (L"kernel32.dll"), "GlobalMemoryStatusEx"); + if (pGlobalMemoryStatusEx) { + memstatsex.dwLength = sizeof (MEMORYSTATUSEX); + if (pGlobalMemoryStatusEx(&memstatsex)) { + totalphys64 = memstatsex.ullTotalPhys; + total64 = memstatsex.ullAvailPageFile + memstatsex.ullTotalPhys; + } + } + size64 = total64; + if (maxmem < 0) + size64 = MAXZ3MEM; + else if (maxmem > 0) + size64 = maxmem * 1024 * 1024; + if (os_64bit) { + if (size64 > MAXZ3MEM) + size64 = MAXZ3MEM; + } else { + if (size64 > MAXZ3MEM) + size64 = MAXZ3MEM; + } + if (size64 < 8 * 1024 * 1024) + size64 = 8 * 1024 * 1024; + if (max_allowed_mman * 1024 * 1024 > size64) + max_allowed_mman = size64 / (1024 * 1024); + max_z3fastmem = max_allowed_mman * 1024 * 1024; + if (max_z3fastmem < 512 * 1024 * 1024) + max_z3fastmem = 512 * 1024 * 1024; + + shm_start = 0; + for (i = 0; i < MAX_SHMID; i++) { + shmids[i].attached = 0; + shmids[i].key = -1; + shmids[i].size = 0; + shmids[i].addr = NULL; + shmids[i].name[0] = 0; + } + + write_log (L"Max Z3FastRAM %dM. Total physical RAM %uM\n", max_z3fastmem >> 20, totalphys64 >> 20); + testwritewatch (); + canbang = 1; + } + + static void resetmem (void) + { + int i; + + if (!shm_start) + return; + for (i = 0; i < MAX_SHMID; i++) { + struct shmid_ds *s = &shmids[i]; + int size = s->size; + uae_u8 *shmaddr; + uae_u8 *result; + + if (!s->attached) + continue; + if (!s->natmembase) + continue; + shmaddr = natmem_offset + ((uae_u8*)s->attached - (uae_u8*)s->natmembase); + result = virtualallocwithlock (shmaddr, size, MEM_COMMIT, s->mode); + if (result != shmaddr) + write_log (L"NATMEM: realloc(%p,%d,%d) failed, err=%x\n", shmaddr, size, s->mode, GetLastError ()); + else + write_log (L"NATMEM: rellocated(%p,%d,%s)\n", shmaddr, size, s->name); + } + } + + int init_shm (void) + { + uae_u32 size, totalsize, z3size, natmemsize, rtgbarrier, rtgextra; + int rounds = 0; -void mapped_free (uae_u8 *mem) -{ - shmpiece *x = shm_start; - - if (mem == filesysory) { - while(x) { - if (mem == x->native_address) { - int shmid = x->id; - shmids[shmid].key = -1; - shmids[shmid].name[0] = '\0'; - shmids[shmid].size = 0; - shmids[shmid].attached = 0; - shmids[shmid].mode = 0; - shmids[shmid].natmembase = 0; - } - x = x->next; - } - return; - } - - while(x) { - if(mem == x->native_address) - shmdt (x->native_address); - x = x->next; - } - x = shm_start; - while(x) { - struct shmid_ds blah; - if (mem == x->native_address) { - if (shmctl (x->id, IPC_STAT, &blah) == 0) - shmctl (x->id, IPC_RMID, &blah); +restart: + for (;;) { + int lowround = 0; + LPVOID blah = NULL; + if (rounds > 0) + write_log (L"NATMEM: retrying %d..\n", rounds); + rounds++; + if (natmem_offset) + VirtualFree(natmem_offset, 0, MEM_RELEASE); + natmem_offset = NULL; + natmem_offset_end = NULL; + canbang = 0; + + z3size = 0; + size = 0x1000000; + rtgextra = 0; + rtgbarrier = si.dwPageSize; + if (currprefs.cpu_model >= 68020) + size = 0x10000000; + if (currprefs.z3fastmem_size || currprefs.z3fastmem2_size) { + z3size = currprefs.z3fastmem_size + currprefs.z3fastmem2_size + (currprefs.z3fastmem_start - 0x10000000); + if (currprefs.gfxmem_size) + rtgbarrier = 16 * 1024 * 1024; + } else { + rtgbarrier = 0; + } + totalsize = size + z3size + currprefs.gfxmem_size; + while (totalsize > size64) { + int change = lowmem (); + if (!change) + return 0; + write_log (L"NATMEM: %d, %dM > %dM = %dM\n", ++lowround, totalsize >> 20, size64 >> 20, (totalsize - change) >> 20); + totalsize -= change; + } + if ((rounds > 1 && totalsize < 0x10000000) || rounds > 20) { + write_log (L"NATMEM: No special area could be allocated (3)!\n"); + return 0; + } + natmemsize = size + z3size; + + xfree (memwatchtable); + memwatchtable = 0; + if (currprefs.gfxmem_size) { + if (!memwatchok) { + write_log (L"GetWriteWatch() not supported, using guard pages, RTG performance will be slower.\n"); + memwatchtable = xcalloc (currprefs.gfxmem_size / si.dwPageSize + 1, 1); + } + } + if (currprefs.gfxmem_size) { + rtgextra = si.dwPageSize; + } else { + rtgbarrier = 0; + rtgextra = 0; + } + blah = VirtualAlloc (NULL, natmemsize + rtgbarrier + currprefs.gfxmem_size + rtgextra + 16 * si.dwPageSize, MEM_RESERVE, PAGE_READWRITE); + if (blah) { + natmem_offset = blah; + break; + } + write_log (L"NATMEM: %dM area failed to allocate, err=%d (Z3=%dM,RTG=%dM)\n", + natmemsize >> 20, GetLastError (), (currprefs.z3fastmem_size + currprefs.z3fastmem2_size) >> 20, currprefs.gfxmem_size >> 20); + if (!lowmem ()) { + write_log (L"NATMEM: No special area could be allocated (2)!\n"); + return 0; + } + } + p96mem_size = currprefs.gfxmem_size; + if (p96mem_size) { + VirtualFree (natmem_offset, 0, MEM_RELEASE); + if (!VirtualAlloc (natmem_offset, natmemsize + rtgbarrier, MEM_RESERVE, PAGE_READWRITE)) { + write_log (L"VirtualAlloc() part 2 error %d. RTG disabled.\n", GetLastError ()); + currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; + rtgbarrier = si.dwPageSize; + rtgextra = 0; + goto restart; + } + p96mem_offset = VirtualAlloc (natmem_offset + natmemsize + rtgbarrier, p96mem_size + rtgextra, + MEM_RESERVE | (memwatchok == 1 ? MEM_WRITE_WATCH : 0), PAGE_READWRITE); + if (!p96mem_offset) { + currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; + write_log (L"NATMEM: failed to allocate special Picasso96 GFX RAM, err=%d\n", GetLastError ()); + } + } + + if (!natmem_offset) { + write_log (L"NATMEM: No special area could be allocated! (1) err=%d\n", GetLastError ()); + } else { + write_log (L"NATMEM: Our special area: 0x%p-0x%p (%08x %dM)\n", + natmem_offset, (uae_u8*)natmem_offset + natmemsize, + natmemsize, natmemsize >> 20); + if (currprefs.gfxmem_size) + write_log (L"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); + canbang = 1; + natmem_offset_end = p96mem_offset + currprefs.gfxmem_size; + } + + resetmem (); + + return canbang; + } + + + void mapped_free (uae_u8 *mem) + { + shmpiece *x = shm_start; + + if (mem == filesysory) { + while(x) { + if (mem == x->native_address) { + int shmid = x->id; + shmids[shmid].key = -1; + shmids[shmid].name[0] = '\0'; + shmids[shmid].size = 0; + shmids[shmid].attached = 0; + shmids[shmid].mode = 0; + shmids[shmid].natmembase = 0; + } + x = x->next; + } + return; + } + + while(x) { + if(mem == x->native_address) + shmdt (x->native_address); + x = x->next; + } + x = shm_start; + while(x) { + struct shmid_ds blah; + if (mem == x->native_address) { + if (shmctl (x->id, IPC_STAT, &blah) == 0) + shmctl (x->id, IPC_RMID, &blah); + } + x = x->next; + } + } + + static key_t get_next_shmkey (void) + { + key_t result = -1; + int i; + for (i = 0; i < MAX_SHMID; i++) { + if (shmids[i].key == -1) { + shmids[i].key = i; + result = i; + break; + } + } + return result; + } + + STATIC_INLINE key_t find_shmkey (key_t key) + { + int result = -1; + if(shmids[key].key == key) { + result = key; + } + return result; } - x = x->next; - } -} -static key_t get_next_shmkey (void) -{ - key_t result = -1; - int i; - for (i = 0; i < MAX_SHMID; i++) { - if (shmids[i].key == -1) { - shmids[i].key = i; - result = i; - break; + int mprotect (void *addr, size_t len, int prot) + { + int result = 0; + return result; } - } - return result; -} -STATIC_INLINE key_t find_shmkey (key_t key) -{ - int result = -1; - if(shmids[key].key == key) { - result = key; - } - return result; -} - -int mprotect (void *addr, size_t len, int prot) -{ - int result = 0; - return result; -} - -void *shmat (int shmid, void *shmaddr, int shmflg) -{ - void *result = (void *)-1; - BOOL got = FALSE; - int p96special = FALSE; - DWORD protect = PAGE_READWRITE; + void *shmat (int shmid, void *shmaddr, int shmflg) + { + void *result = (void *)-1; + BOOL got = FALSE; + int p96special = FALSE; + DWORD protect = PAGE_READWRITE; #ifdef NATMEM_OFFSET - unsigned int size = shmids[shmid].size; - - if (shmids[shmid].attached) - return shmids[shmid].attached; - - if ((uae_u8*)shmaddr < natmem_offset) { - if(!_tcscmp (shmids[shmid].name, L"chip")) { - shmaddr=natmem_offset; - got = TRUE; - if (currprefs.fastmem_size == 0 || currprefs.chipmem_size < 2 * 1024 * 1024) - size += BARRIER; - } - if(!_tcscmp (shmids[shmid].name, L"kick")) { - shmaddr=natmem_offset + 0xf80000; - got = TRUE; - size += BARRIER; - } - if(!_tcscmp (shmids[shmid].name, L"rom_a8")) { - shmaddr=natmem_offset + 0xa80000; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"rom_e0")) { - shmaddr=natmem_offset + 0xe00000; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"rom_f0")) { - shmaddr=natmem_offset + 0xf00000; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"rtarea")) { - shmaddr=natmem_offset + rtarea_base; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"fast")) { - shmaddr=natmem_offset + 0x200000; - got = TRUE; - size += BARRIER; - } - if(!_tcscmp (shmids[shmid].name, L"ramsey_low")) { - shmaddr=natmem_offset + a3000lmem_start; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"ramsey_high")) { - shmaddr=natmem_offset + a3000hmem_start; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"z3")) { - shmaddr=natmem_offset + currprefs.z3fastmem_start; - if (!currprefs.z3fastmem2_size) - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"z3_2")) { - shmaddr=natmem_offset + currprefs.z3fastmem_start + currprefs.z3fastmem_size; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"gfx")) { - got = TRUE; - p96special = TRUE; - p96ram_start = p96mem_offset - natmem_offset; - shmaddr = natmem_offset + p96ram_start; - size += BARRIER; - if (!memwatchok) - protect |= PAGE_GUARD; - } - if(!_tcscmp (shmids[shmid].name, L"bogo")) { - shmaddr=natmem_offset+0x00C00000; - got = TRUE; - if (currprefs.bogomem_size <= 0x100000) - size += BARRIER; - } - if(!_tcscmp (shmids[shmid].name, L"filesys")) { - static uae_u8 *filesysptr; - if (filesysptr == NULL) - filesysptr = xcalloc (size, 1); - result = filesysptr; - shmids[shmid].attached = result; - return result; - } - if(!_tcscmp (shmids[shmid].name, L"custmem1")) { - shmaddr=natmem_offset + currprefs.custom_memory_addrs[0]; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"custmem2")) { - shmaddr=natmem_offset + currprefs.custom_memory_addrs[1]; - got = TRUE; - } - - if(!_tcscmp (shmids[shmid].name, L"hrtmem")) { - shmaddr=natmem_offset + 0x00a10000; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"arhrtmon")) { - shmaddr=natmem_offset + 0x00800000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"xpower_e2")) { - shmaddr=natmem_offset + 0x00e20000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"xpower_f2")) { - shmaddr=natmem_offset + 0x00f20000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"nordic_f0")) { - shmaddr=natmem_offset + 0x00f00000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"nordic_f4")) { - shmaddr=natmem_offset + 0x00f40000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"nordic_f6")) { - shmaddr=natmem_offset + 0x00f60000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp(shmids[shmid].name, L"superiv_b0")) { - shmaddr=natmem_offset + 0x00b00000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"superiv_d0")) { - shmaddr=natmem_offset + 0x00d00000; - size += BARRIER; - got = TRUE; - } - if(!_tcscmp (shmids[shmid].name, L"superiv_e0")) { - shmaddr=natmem_offset + 0x00e00000; - size += BARRIER; - got = TRUE; - } -} + unsigned int size = shmids[shmid].size; + + if (shmids[shmid].attached) + return shmids[shmid].attached; + + if ((uae_u8*)shmaddr < natmem_offset) { + if(!_tcscmp (shmids[shmid].name, L"chip")) { + shmaddr=natmem_offset; + got = TRUE; + if (currprefs.fastmem_size == 0 || currprefs.chipmem_size < 2 * 1024 * 1024) + size += BARRIER; + } + if(!_tcscmp (shmids[shmid].name, L"kick")) { + shmaddr=natmem_offset + 0xf80000; + got = TRUE; + size += BARRIER; + } + if(!_tcscmp (shmids[shmid].name, L"rom_a8")) { + shmaddr=natmem_offset + 0xa80000; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"rom_e0")) { + shmaddr=natmem_offset + 0xe00000; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"rom_f0")) { + shmaddr=natmem_offset + 0xf00000; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"rtarea")) { + shmaddr=natmem_offset + rtarea_base; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"fast")) { + shmaddr=natmem_offset + 0x200000; + got = TRUE; + size += BARRIER; + } + if(!_tcscmp (shmids[shmid].name, L"ramsey_low")) { + shmaddr=natmem_offset + a3000lmem_start; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"ramsey_high")) { + shmaddr=natmem_offset + a3000hmem_start; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"z3")) { + shmaddr=natmem_offset + currprefs.z3fastmem_start; + if (!currprefs.z3fastmem2_size) + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"z3_2")) { + shmaddr=natmem_offset + currprefs.z3fastmem_start + currprefs.z3fastmem_size; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"gfx")) { + got = TRUE; + p96special = TRUE; + p96ram_start = p96mem_offset - natmem_offset; + shmaddr = natmem_offset + p96ram_start; + size += BARRIER; + if (!memwatchok) + protect |= PAGE_GUARD; + } + if(!_tcscmp (shmids[shmid].name, L"bogo")) { + shmaddr=natmem_offset+0x00C00000; + got = TRUE; + if (currprefs.bogomem_size <= 0x100000) + size += BARRIER; + } + if(!_tcscmp (shmids[shmid].name, L"filesys")) { + static uae_u8 *filesysptr; + if (filesysptr == NULL) + filesysptr = xcalloc (size, 1); + result = filesysptr; + shmids[shmid].attached = result; + return result; + } + if(!_tcscmp (shmids[shmid].name, L"custmem1")) { + shmaddr=natmem_offset + currprefs.custom_memory_addrs[0]; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"custmem2")) { + shmaddr=natmem_offset + currprefs.custom_memory_addrs[1]; + got = TRUE; + } + + if(!_tcscmp (shmids[shmid].name, L"hrtmem")) { + shmaddr=natmem_offset + 0x00a10000; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"arhrtmon")) { + shmaddr=natmem_offset + 0x00800000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"xpower_e2")) { + shmaddr=natmem_offset + 0x00e20000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"xpower_f2")) { + shmaddr=natmem_offset + 0x00f20000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"nordic_f0")) { + shmaddr=natmem_offset + 0x00f00000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"nordic_f4")) { + shmaddr=natmem_offset + 0x00f40000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"nordic_f6")) { + shmaddr=natmem_offset + 0x00f60000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp(shmids[shmid].name, L"superiv_b0")) { + shmaddr=natmem_offset + 0x00b00000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"superiv_d0")) { + shmaddr=natmem_offset + 0x00d00000; + size += BARRIER; + got = TRUE; + } + if(!_tcscmp (shmids[shmid].name, L"superiv_e0")) { + shmaddr=natmem_offset + 0x00e00000; + size += BARRIER; + got = TRUE; + } + } #endif - if (shmids[shmid].key == shmid && shmids[shmid].size) { - shmids[shmid].mode = protect; - shmids[shmid].natmembase = natmem_offset; - if (shmaddr) - virtualfreewithlock (shmaddr, size, MEM_DECOMMIT); - result = virtualallocwithlock (shmaddr, size, MEM_COMMIT, protect); - if (result == NULL) { - result = (void*)-1; - write_log (L"VirtualAlloc %08X - %08X %x (%dk) failed %d\n", - (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, - size, size >> 10, GetLastError ()); - } else { - shmids[shmid].attached = result; - write_log (L"VirtualAlloc %08X - %08X %x (%dk) ok%s\n", - (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, - size, size >> 10, p96special ? L" P96" : L""); + if (shmids[shmid].key == shmid && shmids[shmid].size) { + shmids[shmid].mode = protect; + shmids[shmid].natmembase = natmem_offset; + if (shmaddr) + virtualfreewithlock (shmaddr, size, MEM_DECOMMIT); + result = virtualallocwithlock (shmaddr, size, MEM_COMMIT, protect); + if (result == NULL) { + result = (void*)-1; + write_log (L"VirtualAlloc %08X - %08X %x (%dk) failed %d\n", + (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, + size, size >> 10, GetLastError ()); + } else { + shmids[shmid].attached = result; + write_log (L"VirtualAlloc %08X - %08X %x (%dk) ok%s\n", + (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, + size, size >> 10, p96special ? L" P96" : L""); + } + } + return result; + } + + int shmdt (const void *shmaddr) + { + return 0; } - } - return result; -} -int shmdt (const void *shmaddr) -{ - return 0; -} + int shmget (key_t key, size_t size, int shmflg, const TCHAR *name) + { + int result = -1; -int shmget (key_t key, size_t size, int shmflg, const TCHAR *name) -{ - int result = -1; - - if((key == IPC_PRIVATE) || ((shmflg & IPC_CREAT) && (find_shmkey (key) == -1))) { - write_log (L"shmget of size %d (%dk) for %s\n", size, size >> 10, name); - if ((result = get_next_shmkey ()) != -1) { - shmids[result].size = size; - _tcscpy (shmids[result].name, name); - } else { - result = -1; + if((key == IPC_PRIVATE) || ((shmflg & IPC_CREAT) && (find_shmkey (key) == -1))) { + write_log (L"shmget of size %d (%dk) for %s\n", size, size >> 10, name); + if ((result = get_next_shmkey ()) != -1) { + shmids[result].size = size; + _tcscpy (shmids[result].name, name); + } else { + result = -1; + } + } + return result; } - } - return result; -} -int shmctl (int shmid, int cmd, struct shmid_ds *buf) -{ - int result = -1; - - if ((find_shmkey (shmid) != -1) && buf) { - switch (cmd) + int shmctl (int shmid, int cmd, struct shmid_ds *buf) { - case IPC_STAT: - *buf = shmids[shmid]; - result = 0; - break; - case IPC_RMID: - VirtualFree (shmids[shmid].attached, shmids[shmid].size, MEM_DECOMMIT); - shmids[shmid].key = -1; - shmids[shmid].name[0] = '\0'; - shmids[shmid].size = 0; - shmids[shmid].attached = 0; - shmids[shmid].mode = 0; - result = 0; - break; + int result = -1; + + if ((find_shmkey (shmid) != -1) && buf) { + switch (cmd) + { + case IPC_STAT: + *buf = shmids[shmid]; + result = 0; + break; + case IPC_RMID: + VirtualFree (shmids[shmid].attached, shmids[shmid].size, MEM_DECOMMIT); + shmids[shmid].key = -1; + shmids[shmid].name[0] = '\0'; + shmids[shmid].size = 0; + shmids[shmid].attached = 0; + shmids[shmid].mode = 0; + result = 0; + break; + } + } + return result; } - } - return result; -} #endif -int isinf (double x) -{ - const int nClass = _fpclass (x); - int result; - if (nClass == _FPCLASS_NINF || nClass == _FPCLASS_PINF) - result = 1; - else - result = 0; - return result; -} + int isinf (double x) + { + const int nClass = _fpclass (x); + int result; + if (nClass == _FPCLASS_NINF || nClass == _FPCLASS_PINF) + result = 1; + else + result = 0; + return result; + } diff --git a/od-win32/parser.c b/od-win32/parser.c index cd47f6b5..ce41dacc 100644 --- a/od-win32/parser.c +++ b/od-win32/parser.c @@ -1,11 +1,11 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Not a parser, but parallel and serial emulation for Win32 - * - * Copyright 1997 Mathias Ortmann - * Copyright 1998-1999 Brian King - added MIDI output support - */ +* UAE - The Un*x Amiga Emulator +* +* Not a parser, but parallel and serial emulation for Win32 +* +* Copyright 1997 Mathias Ortmann +* Copyright 1998-1999 Brian King - added MIDI output support +*/ #include "sysconfig.h" #include @@ -85,9 +85,9 @@ static GSAPI_NEW_INSTANCE ptr_gsapi_new_instance; typedef void (CALLBACK* GSAPI_DELETE_INSTANCE)(gs_main_instance *instance); static GSAPI_DELETE_INSTANCE ptr_gsapi_delete_instance; typedef int (CALLBACK* GSAPI_SET_STDIO)(gs_main_instance *instance, - int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len), - int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len), - int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len)); + int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len), + int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len), + int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len)); static GSAPI_SET_STDIO ptr_gsapi_set_stdio; typedef int (CALLBACK* GSAPI_INIT_WITH_ARGS)(gs_main_instance *instance, int argc, char **argv); static GSAPI_INIT_WITH_ARGS ptr_gsapi_init_with_args; @@ -107,704 +107,704 @@ static int psbuffers; static LONG WINAPI ExceptionFilter (struct _EXCEPTION_POINTERS * pExceptionPointers, DWORD ec) { - return EXCEPTION_EXECUTE_HANDLER; + return EXCEPTION_EXECUTE_HANDLER; } static void freepsbuffers (void) { - int i; - for (i = 0; i < psbuffers; i++) - free (psbuffer[i]); - free (psbuffer); - psbuffer = NULL; - psbuffers = 0; + int i; + for (i = 0; i < psbuffers; i++) + free (psbuffer[i]); + free (psbuffer); + psbuffer = NULL; + psbuffers = 0; } static int openprinter_ps (void) { - TCHAR *gsargv[] = { - L"-dNOPAUSE", L"-dBATCH", L"-dNOPAGEPROMPT", L"-dNOPROMPT", L"-dQUIET", L"-dNoCancel", - L"-sDEVICE=mswinpr2", NULL - }; - int gsargc, gsargc2, i; - TCHAR *tmpparms[100]; - TCHAR tmp[MAX_DPATH]; - char *gsparms[100]; - - if (ptr_gsapi_new_instance (&gsinstance, NULL) < 0) - return 0; - cmdlineparser (currprefs.ghostscript_parameters, tmpparms, 100 - 10); - - gsargc2 = 0; - gsparms[gsargc2++] = ua (L"WinUAE"); - for (gsargc = 0; gsargv[gsargc]; gsargc++) { - gsparms[gsargc2++] = ua (gsargv[gsargc]); - } - for (i = 0; tmpparms[i]; i++) - gsparms[gsargc2++] = ua (tmpparms[i]); - if (currprefs.prtname[0]) { - _stprintf (tmp, L"-sOutputFile=%%printer%%%s", currprefs.prtname); - gsparms[gsargc2++] = ua (tmp); - } - if (postscript_print_debugging) { - for (i = 0; i < gsargc2; i++) { - TCHAR *parm = au (gsparms[i]); - write_log (L"GSPARM%d: '%s'\n", i, parm); - xfree (parm); + TCHAR *gsargv[] = { + L"-dNOPAUSE", L"-dBATCH", L"-dNOPAGEPROMPT", L"-dNOPROMPT", L"-dQUIET", L"-dNoCancel", + L"-sDEVICE=mswinpr2", NULL + }; + int gsargc, gsargc2, i; + TCHAR *tmpparms[100]; + TCHAR tmp[MAX_DPATH]; + char *gsparms[100]; + + if (ptr_gsapi_new_instance (&gsinstance, NULL) < 0) + return 0; + cmdlineparser (currprefs.ghostscript_parameters, tmpparms, 100 - 10); + + gsargc2 = 0; + gsparms[gsargc2++] = ua (L"WinUAE"); + for (gsargc = 0; gsargv[gsargc]; gsargc++) { + gsparms[gsargc2++] = ua (gsargv[gsargc]); } - } - __try { - int rc = ptr_gsapi_init_with_args (gsinstance, gsargc2, gsparms); - for (i = 0; i < gsargc2; i++) { - xfree (gsparms[i]); + for (i = 0; tmpparms[i]; i++) + gsparms[gsargc2++] = ua (tmpparms[i]); + if (currprefs.prtname[0]) { + _stprintf (tmp, L"-sOutputFile=%%printer%%%s", currprefs.prtname); + gsparms[gsargc2++] = ua (tmp); } - if (rc != 0) { - write_log (L"GS failed, returncode %d\n", rc); - return 0; + if (postscript_print_debugging) { + for (i = 0; i < gsargc2; i++) { + TCHAR *parm = au (gsparms[i]); + write_log (L"GSPARM%d: '%s'\n", i, parm); + xfree (parm); + } } - ptr_gsapi_run_string_begin (gsinstance, 0, &gs_exitcode); - } __except (ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { - write_log (L"GS crashed\n"); - return 0; - } - psmode = 1; - return 1; + __try { + int rc = ptr_gsapi_init_with_args (gsinstance, gsargc2, gsparms); + for (i = 0; i < gsargc2; i++) { + xfree (gsparms[i]); + } + if (rc != 0) { + write_log (L"GS failed, returncode %d\n", rc); + return 0; + } + ptr_gsapi_run_string_begin (gsinstance, 0, &gs_exitcode); + } __except (ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { + write_log (L"GS crashed\n"); + return 0; + } + psmode = 1; + return 1; } static void *prt_thread (void *p) { - uae_u8 **buffers = p; - int err, cnt, ok; - - ok = 1; - prt_running++; - prt_started = 1; - SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_BELOW_NORMAL); - if (load_ghostscript ()) { - if (openprinter_ps ()) { - write_log (L"PostScript printing emulation started..\n"); - cnt = 0; - while (buffers[cnt]) { - uae_u8 *p = buffers[cnt]; - err = ptr_gsapi_run_string_continue (gsinstance, p + 2, (p[0] << 8) | p[1], 0, &gs_exitcode); - if (err != e_NeedInput && err <= e_Fatal) { - ptr_gsapi_exit (gsinstance); - write_log (L"PostScript parsing failed.\n"); - ok = 0; - break; + uae_u8 **buffers = p; + int err, cnt, ok; + + ok = 1; + prt_running++; + prt_started = 1; + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_BELOW_NORMAL); + if (load_ghostscript ()) { + if (openprinter_ps ()) { + write_log (L"PostScript printing emulation started..\n"); + cnt = 0; + while (buffers[cnt]) { + uae_u8 *p = buffers[cnt]; + err = ptr_gsapi_run_string_continue (gsinstance, p + 2, (p[0] << 8) | p[1], 0, &gs_exitcode); + if (err != e_NeedInput && err <= e_Fatal) { + ptr_gsapi_exit (gsinstance); + write_log (L"PostScript parsing failed.\n"); + ok = 0; + break; + } + cnt++; + } + cnt = 0; + while (buffers[cnt]) { + xfree (buffers[cnt]); + cnt++; + } + xfree (buffers); + if (ok) { + write_log (L"PostScript printing emulation finished..\n"); + ptr_gsapi_run_string_end (gsinstance, 0, &gs_exitcode); + } + } else { + write_log (L"gsdll32.dll failed to initialize\n"); } - cnt++; - } - cnt = 0; - while (buffers[cnt]) { - xfree (buffers[cnt]); - cnt++; - } - xfree (buffers); - if (ok) { - write_log (L"PostScript printing emulation finished..\n"); - ptr_gsapi_run_string_end (gsinstance, 0, &gs_exitcode); - } } else { - write_log (L"gsdll32.dll failed to initialize\n"); + write_log (L"gsdll32.dll failed to load\n"); } - } else { - write_log (L"gsdll32.dll failed to load\n"); - } - unload_ghostscript (); - prt_running--; - return 0; + unload_ghostscript (); + prt_running--; + return 0; } static int doflushprinter (void) { - if (prtopen == 0 && prtbufbytes < MIN_PRTBYTES) { - if (prtbufbytes > 0) - write_log (L"PRINTER: %d bytes received, less than %d bytes, not printing.\n", prtbufbytes, MIN_PRTBYTES); - prtbufbytes = 0; - return 0; - } - return 1; + if (prtopen == 0 && prtbufbytes < MIN_PRTBYTES) { + if (prtbufbytes > 0) + write_log (L"PRINTER: %d bytes received, less than %d bytes, not printing.\n", prtbufbytes, MIN_PRTBYTES); + prtbufbytes = 0; + return 0; + } + return 1; } static void openprinter (void); static void flushprtbuf (void) { - DWORD written = 0; + DWORD written = 0; - if (!prtbufbytes) - return; + if (!prtbufbytes) + return; - if (postscript_print_debugging && prtdump) - zfile_fwrite (prtbuf, prtbufbytes, 1, prtdump); + if (postscript_print_debugging && prtdump) + zfile_fwrite (prtbuf, prtbufbytes, 1, prtdump); - if (currprefs.parallel_postscript_emulation) { + if (currprefs.parallel_postscript_emulation) { - if (psmode) { - uae_u8 *p; - psbuffer = realloc (psbuffer, (psbuffers + 2) * sizeof (uae_u8*)); - p = malloc (prtbufbytes + 2); - p[0] = prtbufbytes >> 8; - p[1] = prtbufbytes; - memcpy (p + 2, prtbuf, prtbufbytes); - psbuffer[psbuffers++] = p; - psbuffer[psbuffers] = NULL; - } - prtbufbytes = 0; - return; - - } else if (prtbufbytes > 0) { - int pbyt = prtbufbytes; - - if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { - int i; - if (!prtopen) { - if (epson_init (currprefs.parallel_matrix_emulation)) - prtopen = 1; - } - for (i = 0; i < prtbufbytes; i++) - epson_printchar (prtbuf[i]); - } else { - if (hPrt == INVALID_HANDLE_VALUE) { - if (!doflushprinter ()) - return; - openprinter (); - } - if (hPrt != INVALID_HANDLE_VALUE) { - if (WritePrinter (hPrt, prtbuf, pbyt, &written)) { - if (written != pbyt) - write_log (L"PRINTER: Only wrote %d of %d bytes!\n", written, pbyt); + if (psmode) { + uae_u8 *p; + psbuffer = realloc (psbuffer, (psbuffers + 2) * sizeof (uae_u8*)); + p = malloc (prtbufbytes + 2); + p[0] = prtbufbytes >> 8; + p[1] = prtbufbytes; + memcpy (p + 2, prtbuf, prtbufbytes); + psbuffer[psbuffers++] = p; + psbuffer[psbuffers] = NULL; + } + prtbufbytes = 0; + return; + + } else if (prtbufbytes > 0) { + int pbyt = prtbufbytes; + + if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { + int i; + if (!prtopen) { + if (epson_init (currprefs.parallel_matrix_emulation)) + prtopen = 1; + } + for (i = 0; i < prtbufbytes; i++) + epson_printchar (prtbuf[i]); } else { - write_log (L"PRINTER: Couldn't write data!\n"); + if (hPrt == INVALID_HANDLE_VALUE) { + if (!doflushprinter ()) + return; + openprinter (); + } + if (hPrt != INVALID_HANDLE_VALUE) { + if (WritePrinter (hPrt, prtbuf, pbyt, &written)) { + if (written != pbyt) + write_log (L"PRINTER: Only wrote %d of %d bytes!\n", written, pbyt); + } else { + write_log (L"PRINTER: Couldn't write data!\n"); + } + } } - } - } - } - prtbufbytes = 0; + } + prtbufbytes = 0; } void finishjob (void) { - flushprtbuf (); + flushprtbuf (); } static void DoSomeWeirdPrintingStuff (uae_char val) { - static uae_char prev[5]; - - memmove (prev, prev + 1, 3); - prev[3] = val; - prev[4] = 0; - if (currprefs.parallel_postscript_detection) { - if (psmode && val == 4) { - flushprtbuf (); - *prtbuf = val; - prtbufbytes = 1; - flushprtbuf (); - write_log (L"PostScript end detected..\n"); - - if (postscript_print_debugging) { - zfile_fclose (prtdump); - prtdump = NULL; - } - - if (currprefs.parallel_postscript_emulation) { - prt_started = 0; - if (uae_start_thread (L"postscript", prt_thread, psbuffer, NULL)) { - while (!prt_started) - Sleep (5); - psbuffers = 0; - psbuffer = NULL; + static uae_char prev[5]; + + memmove (prev, prev + 1, 3); + prev[3] = val; + prev[4] = 0; + if (currprefs.parallel_postscript_detection) { + if (psmode && val == 4) { + flushprtbuf (); + *prtbuf = val; + prtbufbytes = 1; + flushprtbuf (); + write_log (L"PostScript end detected..\n"); + + if (postscript_print_debugging) { + zfile_fclose (prtdump); + prtdump = NULL; + } + + if (currprefs.parallel_postscript_emulation) { + prt_started = 0; + if (uae_start_thread (L"postscript", prt_thread, psbuffer, NULL)) { + while (!prt_started) + Sleep (5); + psbuffers = 0; + psbuffer = NULL; + } + } else { + closeprinter (); + } + freepsbuffers (); + return; + + } else if (!psmode && !stricmp (prev, "%!PS")) { + + if (postscript_print_debugging) + prtdump = zfile_fopen (L"psdump.dat", L"wb", 0); + + psmode = 1; + psbuffer = malloc (sizeof (uae_u8*)); + psbuffer[0] = 0; + psbuffers = 0; + strcpy (prtbuf, "%!PS"); + prtbufbytes = strlen (prtbuf); + flushprtbuf (); + write_log (L"PostScript start detected..\n"); + return; } - } else { - closeprinter (); - } - freepsbuffers (); - return; - - } else if (!psmode && !stricmp (prev, "%!PS")) { - - if (postscript_print_debugging) - prtdump = zfile_fopen (L"psdump.dat", L"wb", 0); - - psmode = 1; - psbuffer = malloc (sizeof (uae_u8*)); - psbuffer[0] = 0; - psbuffers = 0; - strcpy (prtbuf, "%!PS"); - prtbufbytes = strlen (prtbuf); - flushprtbuf (); - write_log (L"PostScript start detected..\n"); - return; } - } - if (prtbufbytes < PRTBUFSIZE) { - prtbuf[prtbufbytes++] = val; - } else { - flushprtbuf (); - *prtbuf = val; - prtbufbytes = 1; - } + if (prtbufbytes < PRTBUFSIZE) { + prtbuf[prtbufbytes++] = val; + } else { + flushprtbuf (); + *prtbuf = val; + prtbufbytes = 1; + } } int isprinter (void) { - if (!currprefs.prtname[0]) - return 0; - if (!_tcsncmp (currprefs.prtname, L"LPT", 3)) { - paraport_open (currprefs.prtname); - return -1; - } - return 1; + if (!currprefs.prtname[0]) + return 0; + if (!_tcsncmp (currprefs.prtname, L"LPT", 3)) { + paraport_open (currprefs.prtname); + return -1; + } + return 1; } int isprinteropen (void) { - if (prtopen || prtbufbytes > 0) - return 1; - return 0; + if (prtopen || prtbufbytes > 0) + return 1; + return 0; } int load_ghostscript (void) { - struct gsapi_revision_s r; - TCHAR path[MAX_DPATH]; - TCHAR *s; + struct gsapi_revision_s r; + TCHAR path[MAX_DPATH]; + TCHAR *s; - if (gsdll) - return 1; - _tcscpy (path, L"gsdll32.dll"); - gsdll = WIN32_LoadLibrary (path); - if (!gsdll) { - if (GetEnvironmentVariable (L"GS_DLL", path, sizeof (path) / sizeof (TCHAR))) - gsdll = LoadLibrary (path); - } - if (!gsdll) { - HKEY key; - DWORD ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\AFPL Ghostscript", 0, KEY_READ, &key); - if (ret != ERROR_SUCCESS) - ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\GPL Ghostscript", 0, KEY_READ, &key); - if (ret == ERROR_SUCCESS) { - int idx = 0, cnt = 20; - TCHAR tmp1[MAX_DPATH]; - while (cnt-- > 0) { - DWORD size1 = sizeof (tmp1) / sizeof (TCHAR); - FILETIME ft; - if (RegEnumKeyEx (key, idx, tmp1, &size1, NULL, NULL, NULL, &ft) == ERROR_SUCCESS) { - HKEY key2; - if (RegOpenKeyEx (key, tmp1, 0, KEY_READ, &key2) == ERROR_SUCCESS) { - DWORD type = REG_SZ; - DWORD size = sizeof (path) / sizeof (TCHAR); - if (RegQueryValueEx (key2, L"GS_DLL", 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS) { - gsdll = LoadLibrary (path); + if (gsdll) + return 1; + _tcscpy (path, L"gsdll32.dll"); + gsdll = WIN32_LoadLibrary (path); + if (!gsdll) { + if (GetEnvironmentVariable (L"GS_DLL", path, sizeof (path) / sizeof (TCHAR))) + gsdll = LoadLibrary (path); + } + if (!gsdll) { + HKEY key; + DWORD ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\AFPL Ghostscript", 0, KEY_READ, &key); + if (ret != ERROR_SUCCESS) + ret = RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\GPL Ghostscript", 0, KEY_READ, &key); + if (ret == ERROR_SUCCESS) { + int idx = 0, cnt = 20; + TCHAR tmp1[MAX_DPATH]; + while (cnt-- > 0) { + DWORD size1 = sizeof (tmp1) / sizeof (TCHAR); + FILETIME ft; + if (RegEnumKeyEx (key, idx, tmp1, &size1, NULL, NULL, NULL, &ft) == ERROR_SUCCESS) { + HKEY key2; + if (RegOpenKeyEx (key, tmp1, 0, KEY_READ, &key2) == ERROR_SUCCESS) { + DWORD type = REG_SZ; + DWORD size = sizeof (path) / sizeof (TCHAR); + if (RegQueryValueEx (key2, L"GS_DLL", 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS) { + gsdll = LoadLibrary (path); + } + RegCloseKey (key2); + if (gsdll) + break; + } + } + idx++; } - RegCloseKey (key2); - if (gsdll) - break; - } + RegCloseKey (key); } - idx++; - } - RegCloseKey (key); } - } - if (!gsdll) - return 0; - ptr_gsapi_revision = (GSAPI_REVISION)GetProcAddress (gsdll, "gsapi_revision"); - if (!ptr_gsapi_revision) { - unload_ghostscript (); - write_log (L"incompatible %s! (1)\n", path); - return -1; - } - if (ptr_gsapi_revision(&r, sizeof(r))) { - unload_ghostscript (); - write_log (L"incompatible %s! (2)\n", path); - return -2; - } - ptr_gsapi_new_instance = (GSAPI_NEW_INSTANCE)GetProcAddress (gsdll, "gsapi_new_instance"); - ptr_gsapi_delete_instance = (GSAPI_DELETE_INSTANCE)GetProcAddress (gsdll, "gsapi_delete_instance"); - ptr_gsapi_set_stdio = (GSAPI_SET_STDIO)GetProcAddress (gsdll, "gsapi_set_stdio"); - ptr_gsapi_exit = (GSAPI_EXIT)GetProcAddress (gsdll, "gsapi_exit"); - ptr_gsapi_run_string_begin = (GSAPI_RUN_STRING_BEGIN)GetProcAddress (gsdll, "gsapi_run_string_begin"); - ptr_gsapi_run_string_continue = (GSAPI_RUN_STRING_CONTINUE)GetProcAddress (gsdll, "gsapi_run_string_continue"); - ptr_gsapi_run_string_end = (GSAPI_RUN_STRING_END)GetProcAddress (gsdll, "gsapi_run_string_end"); - ptr_gsapi_init_with_args = (GSAPI_INIT_WITH_ARGS)GetProcAddress (gsdll, "gsapi_init_with_args"); - if (!ptr_gsapi_new_instance || !ptr_gsapi_delete_instance || !ptr_gsapi_exit || - !ptr_gsapi_run_string_begin || !ptr_gsapi_run_string_continue || !ptr_gsapi_run_string_end || - !ptr_gsapi_init_with_args) { - unload_ghostscript (); - write_log (L"incompatible %s! (3)\n", path); - return -3; - } - s = au (r.product); - write_log (L"%s: %s rev %d initialized\n", path, s, r.revision); - xfree (s); - return 1; + if (!gsdll) + return 0; + ptr_gsapi_revision = (GSAPI_REVISION)GetProcAddress (gsdll, "gsapi_revision"); + if (!ptr_gsapi_revision) { + unload_ghostscript (); + write_log (L"incompatible %s! (1)\n", path); + return -1; + } + if (ptr_gsapi_revision(&r, sizeof(r))) { + unload_ghostscript (); + write_log (L"incompatible %s! (2)\n", path); + return -2; + } + ptr_gsapi_new_instance = (GSAPI_NEW_INSTANCE)GetProcAddress (gsdll, "gsapi_new_instance"); + ptr_gsapi_delete_instance = (GSAPI_DELETE_INSTANCE)GetProcAddress (gsdll, "gsapi_delete_instance"); + ptr_gsapi_set_stdio = (GSAPI_SET_STDIO)GetProcAddress (gsdll, "gsapi_set_stdio"); + ptr_gsapi_exit = (GSAPI_EXIT)GetProcAddress (gsdll, "gsapi_exit"); + ptr_gsapi_run_string_begin = (GSAPI_RUN_STRING_BEGIN)GetProcAddress (gsdll, "gsapi_run_string_begin"); + ptr_gsapi_run_string_continue = (GSAPI_RUN_STRING_CONTINUE)GetProcAddress (gsdll, "gsapi_run_string_continue"); + ptr_gsapi_run_string_end = (GSAPI_RUN_STRING_END)GetProcAddress (gsdll, "gsapi_run_string_end"); + ptr_gsapi_init_with_args = (GSAPI_INIT_WITH_ARGS)GetProcAddress (gsdll, "gsapi_init_with_args"); + if (!ptr_gsapi_new_instance || !ptr_gsapi_delete_instance || !ptr_gsapi_exit || + !ptr_gsapi_run_string_begin || !ptr_gsapi_run_string_continue || !ptr_gsapi_run_string_end || + !ptr_gsapi_init_with_args) { + unload_ghostscript (); + write_log (L"incompatible %s! (3)\n", path); + return -3; + } + s = au (r.product); + write_log (L"%s: %s rev %d initialized\n", path, s, r.revision); + xfree (s); + return 1; } void unload_ghostscript (void) { - if (gsinstance) { - ptr_gsapi_exit (gsinstance); - ptr_gsapi_delete_instance (gsinstance); - } - gsinstance = NULL; - if (gsdll) - FreeLibrary (gsdll); - gsdll = NULL; - psmode = 0; + if (gsinstance) { + ptr_gsapi_exit (gsinstance); + ptr_gsapi_delete_instance (gsinstance); + } + gsinstance = NULL; + if (gsdll) + FreeLibrary (gsdll); + gsdll = NULL; + psmode = 0; } static void openprinter (void) { - DOC_INFO_1 DocInfo; - static int first; - - closeprinter (); - if (!currprefs.prtname[0]) - return; - - if (currprefs.parallel_postscript_emulation) { - prtopen = 1; - return; - } else if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { - epson_init (currprefs.parallel_matrix_emulation); - } else if (hPrt == INVALID_HANDLE_VALUE) { - flushprtbuf (); - if (OpenPrinter (currprefs.prtname, &hPrt, NULL)) { - // Fill in the structure with info about this "document." - DocInfo.pDocName = L"WinUAE Document"; - DocInfo.pOutputFile = NULL; - DocInfo.pDatatype = currprefs.parallel_matrix_emulation ? L"TEXT" : L"RAW"; - // Inform the spooler the document is beginning. - if ((dwJob = StartDocPrinter (hPrt, 1, (LPSTR)&DocInfo)) == 0) { - ClosePrinter (hPrt ); - hPrt = INVALID_HANDLE_VALUE; - } else if (StartPagePrinter (hPrt)) { + DOC_INFO_1 DocInfo; + static int first; + + closeprinter (); + if (!currprefs.prtname[0]) + return; + + if (currprefs.parallel_postscript_emulation) { prtopen = 1; - } - } else { - hPrt = INVALID_HANDLE_VALUE; // Stupid bug in Win32, where OpenPrinter fails, but hPrt ends up being zero + return; + } else if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { + epson_init (currprefs.parallel_matrix_emulation); + } else if (hPrt == INVALID_HANDLE_VALUE) { + flushprtbuf (); + if (OpenPrinter (currprefs.prtname, &hPrt, NULL)) { + // Fill in the structure with info about this "document." + DocInfo.pDocName = L"WinUAE Document"; + DocInfo.pOutputFile = NULL; + DocInfo.pDatatype = currprefs.parallel_matrix_emulation ? L"TEXT" : L"RAW"; + // Inform the spooler the document is beginning. + if ((dwJob = StartDocPrinter (hPrt, 1, (LPSTR)&DocInfo)) == 0) { + ClosePrinter (hPrt ); + hPrt = INVALID_HANDLE_VALUE; + } else if (StartPagePrinter (hPrt)) { + prtopen = 1; + } + } else { + hPrt = INVALID_HANDLE_VALUE; // Stupid bug in Win32, where OpenPrinter fails, but hPrt ends up being zero + } + } + if (hPrt != INVALID_HANDLE_VALUE) { + write_log (L"PRINTER: Opening printer \"%s\" with handle 0x%x.\n", currprefs.prtname, hPrt); + } else if (*currprefs.prtname) { + write_log (L"PRINTER: ERROR - Couldn't open printer \"%s\" for output.\n", currprefs.prtname); } - } - if (hPrt != INVALID_HANDLE_VALUE) { - write_log (L"PRINTER: Opening printer \"%s\" with handle 0x%x.\n", currprefs.prtname, hPrt); - } else if (*currprefs.prtname) { - write_log (L"PRINTER: ERROR - Couldn't open printer \"%s\" for output.\n", currprefs.prtname); - } } void flushprinter (void) { - if (!doflushprinter ()) - return; - flushprtbuf (); - closeprinter (); + if (!doflushprinter ()) + return; + flushprtbuf (); + closeprinter (); } void closeprinter (void) { #ifdef PRINT_DUMP - zfile_fclose (prtdump); + zfile_fclose (prtdump); #endif - parflush = 0; - psmode = 0; - if (hPrt != INVALID_HANDLE_VALUE) { - EndPagePrinter (hPrt); - EndDocPrinter (hPrt); - ClosePrinter (hPrt); - hPrt = INVALID_HANDLE_VALUE; - write_log (L"PRINTER: Closing printer.\n"); - } - if (currprefs.parallel_postscript_emulation) - prtopen = 1; - else - prtopen = 0; - if (prt_running) { - write_log (L"waiting for printing to finish...\n"); - while (prt_running) - Sleep (10); - } - freepsbuffers (); - epson_close (); - prtbufbytes = 0; + parflush = 0; + psmode = 0; + if (hPrt != INVALID_HANDLE_VALUE) { + EndPagePrinter (hPrt); + EndDocPrinter (hPrt); + ClosePrinter (hPrt); + hPrt = INVALID_HANDLE_VALUE; + write_log (L"PRINTER: Closing printer.\n"); + } + if (currprefs.parallel_postscript_emulation) + prtopen = 1; + else + prtopen = 0; + if (prt_running) { + write_log (L"waiting for printing to finish...\n"); + while (prt_running) + Sleep (10); + } + freepsbuffers (); + epson_close (); + prtbufbytes = 0; } void doprinter (uae_u8 val) { - parflush = 0; - DoSomeWeirdPrintingStuff (val); + parflush = 0; + DoSomeWeirdPrintingStuff (val); } struct uaeserialdatawin32 { - HANDLE hCom; - HANDLE evtr, evtw, evtt, evtwce; - OVERLAPPED olr, olw, olwce; - int writeactive; - void *readdata, *writedata; - volatile int threadactive; - uae_sem_t change_sem, sync_sem; - void *user; + HANDLE hCom; + HANDLE evtr, evtw, evtt, evtwce; + OVERLAPPED olr, olw, olwce; + int writeactive; + void *readdata, *writedata; + volatile int threadactive; + uae_sem_t change_sem, sync_sem; + void *user; }; int uaeser_getdatalenght (void) { - return sizeof (struct uaeserialdatawin32); + return sizeof (struct uaeserialdatawin32); } static void uaeser_initdata (struct uaeserialdatawin32 *sd, void *user) { - memset (sd, 0, sizeof (struct uaeserialdatawin32)); - sd->hCom = INVALID_HANDLE_VALUE; - sd->evtr = sd->evtw = sd->evtt = sd->evtwce = 0; - sd->user = user; + memset (sd, 0, sizeof (struct uaeserialdatawin32)); + sd->hCom = INVALID_HANDLE_VALUE; + sd->evtr = sd->evtw = sd->evtt = sd->evtwce = 0; + sd->user = user; } int uaeser_query (struct uaeserialdatawin32 *sd, uae_u16 *status, uae_u32 *pending) { - DWORD err, modem; - COMSTAT ComStat; - uae_u16 s = 0; - - if (!ClearCommError (sd->hCom, &err, &ComStat)) - return 0; - *pending = ComStat.cbInQue; - if (status) { - s |= (err & CE_BREAK) ? (1 << 10) : 0; - s |= (err & CE_RXOVER) ? (1 << 8) : 0; - if (GetCommModemStatus (sd->hCom, &modem)) { - s |= (modem & MS_CTS_ON) ? 0 : (1 << 4); - s |= (modem & MS_DSR_ON) ? 0 : (1 << 7); - s |= (modem & MS_RING_ON) ? (1 << 2) : 0; + DWORD err, modem; + COMSTAT ComStat; + uae_u16 s = 0; + + if (!ClearCommError (sd->hCom, &err, &ComStat)) + return 0; + *pending = ComStat.cbInQue; + if (status) { + s |= (err & CE_BREAK) ? (1 << 10) : 0; + s |= (err & CE_RXOVER) ? (1 << 8) : 0; + if (GetCommModemStatus (sd->hCom, &modem)) { + s |= (modem & MS_CTS_ON) ? 0 : (1 << 4); + s |= (modem & MS_DSR_ON) ? 0 : (1 << 7); + s |= (modem & MS_RING_ON) ? (1 << 2) : 0; + } + *status = s; } - *status = s; - } - return 1; + return 1; } int uaeser_break (struct uaeserialdatawin32 *sd, int brklen) { - if (!SetCommBreak (sd->hCom)) - return 0; - Sleep (brklen / 1000); - ClearCommBreak (sd->hCom); - return 1; + if (!SetCommBreak (sd->hCom)) + return 0; + Sleep (brklen / 1000); + ClearCommBreak (sd->hCom); + return 1; } int uaeser_setparams (struct uaeserialdatawin32 *sd, int baud, int rbuffer, int bits, int sbits, int rtscts, int parity, uae_u32 xonxoff) { - DCB dcb; - - memset (&dcb, 0, sizeof (dcb)); - dcb.DCBlength = sizeof (DCB); - if (!GetCommState (sd->hCom, &dcb)) - return 5; - - dcb.fBinary = TRUE; - dcb.BaudRate = baud; - dcb.ByteSize = bits; - dcb.Parity = parity == 0 ? NOPARITY : (parity == 1 ? ODDPARITY : EVENPARITY); - dcb.fParity = FALSE; - dcb.StopBits = sbits == 1 ? ONESTOPBIT : TWOSTOPBITS; - - dcb.fDsrSensitivity = FALSE; - dcb.fOutxDsrFlow = FALSE; - dcb.fDtrControl = DTR_CONTROL_DISABLE; - - if (rtscts) { - dcb.fOutxCtsFlow = TRUE; - dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; - } else { - dcb.fRtsControl = RTS_CONTROL_DISABLE; - dcb.fOutxCtsFlow = FALSE; - } - - dcb.fTXContinueOnXoff = FALSE; - if (xonxoff & 1) { - dcb.fOutX = TRUE; - dcb.fInX = TRUE; - dcb.XonChar = (xonxoff >> 8) & 0xff; - dcb.XoffChar = (xonxoff >> 16) & 0xff; - } else { - dcb.fOutX = FALSE; - dcb.fInX = FALSE; - } + DCB dcb; + + memset (&dcb, 0, sizeof (dcb)); + dcb.DCBlength = sizeof (DCB); + if (!GetCommState (sd->hCom, &dcb)) + return 5; + + dcb.fBinary = TRUE; + dcb.BaudRate = baud; + dcb.ByteSize = bits; + dcb.Parity = parity == 0 ? NOPARITY : (parity == 1 ? ODDPARITY : EVENPARITY); + dcb.fParity = FALSE; + dcb.StopBits = sbits == 1 ? ONESTOPBIT : TWOSTOPBITS; + + dcb.fDsrSensitivity = FALSE; + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + + if (rtscts) { + dcb.fOutxCtsFlow = TRUE; + dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + } else { + dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fOutxCtsFlow = FALSE; + } + + dcb.fTXContinueOnXoff = FALSE; + if (xonxoff & 1) { + dcb.fOutX = TRUE; + dcb.fInX = TRUE; + dcb.XonChar = (xonxoff >> 8) & 0xff; + dcb.XoffChar = (xonxoff >> 16) & 0xff; + } else { + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + } - dcb.fErrorChar = FALSE; - dcb.fNull = FALSE; - dcb.fAbortOnError = FALSE; + dcb.fErrorChar = FALSE; + dcb.fNull = FALSE; + dcb.fAbortOnError = FALSE; - //dcb.XoffLim = 512; - //dcb.XonLim = 2048; + //dcb.XoffLim = 512; + //dcb.XonLim = 2048; - if (!SetCommState (sd->hCom, &dcb)) { - write_log (L"uaeserial: SetCommState() failed %d\n", GetLastError()); - return 5; - } - SetupComm (sd->hCom, rbuffer, rbuffer); - return 0; + if (!SetCommState (sd->hCom, &dcb)) { + write_log (L"uaeserial: SetCommState() failed %d\n", GetLastError()); + return 5; + } + SetupComm (sd->hCom, rbuffer, rbuffer); + return 0; } static void startwce(struct uaeserialdatawin32 *sd, DWORD *evtmask) { - SetEvent(sd->evtwce); - WaitCommEvent(sd->hCom, evtmask, &sd->olwce); + SetEvent(sd->evtwce); + WaitCommEvent(sd->hCom, evtmask, &sd->olwce); } static void *uaeser_trap_thread (void *arg) { - struct uaeserialdatawin32 *sd = arg; - HANDLE handles[4]; - int cnt, actual; - DWORD evtmask; - - uae_set_thread_priority (NULL, 1); - sd->threadactive = 1; - uae_sem_post (&sd->sync_sem); - startwce(sd, &evtmask); - while (sd->threadactive == 1) { - int sigmask = 0; - uae_sem_wait (&sd->change_sem); - if (WaitForSingleObject(sd->evtwce, 0) == WAIT_OBJECT_0) { - if (evtmask & EV_RXCHAR) - sigmask |= 1; - if ((evtmask & EV_TXEMPTY) && !sd->writeactive) - sigmask |= 2; - startwce(sd, &evtmask); - } - cnt = 0; - handles[cnt++] = sd->evtt; - handles[cnt++] = sd->evtwce; - if (sd->writeactive) { - if (GetOverlappedResult (sd->hCom, &sd->olw, &actual, FALSE)) { - sd->writeactive = 0; - sigmask |= 2; - } else { - handles[cnt++] = sd->evtw; - } + struct uaeserialdatawin32 *sd = arg; + HANDLE handles[4]; + int cnt, actual; + DWORD evtmask; + + uae_set_thread_priority (NULL, 1); + sd->threadactive = 1; + uae_sem_post (&sd->sync_sem); + startwce(sd, &evtmask); + while (sd->threadactive == 1) { + int sigmask = 0; + uae_sem_wait (&sd->change_sem); + if (WaitForSingleObject(sd->evtwce, 0) == WAIT_OBJECT_0) { + if (evtmask & EV_RXCHAR) + sigmask |= 1; + if ((evtmask & EV_TXEMPTY) && !sd->writeactive) + sigmask |= 2; + startwce(sd, &evtmask); + } + cnt = 0; + handles[cnt++] = sd->evtt; + handles[cnt++] = sd->evtwce; + if (sd->writeactive) { + if (GetOverlappedResult (sd->hCom, &sd->olw, &actual, FALSE)) { + sd->writeactive = 0; + sigmask |= 2; + } else { + handles[cnt++] = sd->evtw; + } + } + if (!sd->writeactive) + sigmask |= 2; + uaeser_signal (sd->user, sigmask | 1); + uae_sem_post (&sd->change_sem); + WaitForMultipleObjects(cnt, handles, FALSE, INFINITE); } - if (!sd->writeactive) - sigmask |= 2; - uaeser_signal (sd->user, sigmask | 1); - uae_sem_post (&sd->change_sem); - WaitForMultipleObjects(cnt, handles, FALSE, INFINITE); - } - sd->threadactive = 0; - uae_sem_post (&sd->sync_sem); - return 0; + sd->threadactive = 0; + uae_sem_post (&sd->sync_sem); + return 0; } void uaeser_trigger (struct uaeserialdatawin32 *sd) { - SetEvent (sd->evtt); + SetEvent (sd->evtt); } int uaeser_write (struct uaeserialdatawin32 *sd, uae_u8 *data, uae_u32 len) { - int ret = 1; - if (!WriteFile (sd->hCom, data, len, NULL, &sd->olw)) { - sd->writeactive = 1; - if (GetLastError() != ERROR_IO_PENDING) { - ret = 0; - sd->writeactive = 0; + int ret = 1; + if (!WriteFile (sd->hCom, data, len, NULL, &sd->olw)) { + sd->writeactive = 1; + if (GetLastError() != ERROR_IO_PENDING) { + ret = 0; + sd->writeactive = 0; + } } - } - SetEvent (sd->evtt); - return ret; + SetEvent (sd->evtt); + return ret; } int uaeser_read (struct uaeserialdatawin32 *sd, uae_u8 *data, uae_u32 len) { - int ret = 1; - DWORD err; - COMSTAT ComStat; - - if (!ClearCommError (sd->hCom, &err, &ComStat)) - return 0; - if (len > ComStat.cbInQue) - return 0; - if (!ReadFile (sd->hCom, data, len, NULL, &sd->olr)) { - if (GetLastError() == ERROR_IO_PENDING) - WaitForSingleObject(sd->evtr, INFINITE); - else - ret = 0; - } - SetEvent (sd->evtt); - return ret; + int ret = 1; + DWORD err; + COMSTAT ComStat; + + if (!ClearCommError (sd->hCom, &err, &ComStat)) + return 0; + if (len > ComStat.cbInQue) + return 0; + if (!ReadFile (sd->hCom, data, len, NULL, &sd->olr)) { + if (GetLastError() == ERROR_IO_PENDING) + WaitForSingleObject(sd->evtr, INFINITE); + else + ret = 0; + } + SetEvent (sd->evtt); + return ret; } void uaeser_clearbuffers (struct uaeserialdatawin32 *sd) { - PurgeComm (sd->hCom, PURGE_TXCLEAR | PURGE_RXCLEAR); + PurgeComm (sd->hCom, PURGE_TXCLEAR | PURGE_RXCLEAR); } int uaeser_open (struct uaeserialdatawin32 *sd, void *user, int unit) { - TCHAR buf[256]; - COMMTIMEOUTS CommTimeOuts; - - sd->user = user; - _stprintf (buf, L"\\\\.\\COM%d", unit); - sd->evtr = CreateEvent (NULL, TRUE, FALSE, NULL); - sd->evtw = CreateEvent (NULL, TRUE, FALSE, NULL); - sd->evtt = CreateEvent (NULL, FALSE, FALSE, NULL); - sd->evtwce = CreateEvent (NULL, TRUE, FALSE, NULL); - if (!sd->evtt || !sd->evtw || !sd->evtt || !sd->evtwce) - goto end; - sd->olr.hEvent = sd->evtr; - sd->olw.hEvent = sd->evtw; - sd->olwce.hEvent = sd->evtwce; - sd->hCom = CreateFile (buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); - if (sd->hCom == INVALID_HANDLE_VALUE) { - _stprintf (buf, L"\\.\\\\COM%d", unit); + TCHAR buf[256]; + COMMTIMEOUTS CommTimeOuts; + + sd->user = user; + _stprintf (buf, L"\\\\.\\COM%d", unit); + sd->evtr = CreateEvent (NULL, TRUE, FALSE, NULL); + sd->evtw = CreateEvent (NULL, TRUE, FALSE, NULL); + sd->evtt = CreateEvent (NULL, FALSE, FALSE, NULL); + sd->evtwce = CreateEvent (NULL, TRUE, FALSE, NULL); + if (!sd->evtt || !sd->evtw || !sd->evtt || !sd->evtwce) + goto end; + sd->olr.hEvent = sd->evtr; + sd->olw.hEvent = sd->evtw; + sd->olwce.hEvent = sd->evtwce; sd->hCom = CreateFile (buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); if (sd->hCom == INVALID_HANDLE_VALUE) { - write_log (L"UAESER: '%s' failed to open, err=%d\n", buf, GetLastError()); - goto end; + _stprintf (buf, L"\\.\\\\COM%d", unit); + sd->hCom = CreateFile (buf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); + if (sd->hCom == INVALID_HANDLE_VALUE) { + write_log (L"UAESER: '%s' failed to open, err=%d\n", buf, GetLastError()); + goto end; + } } - } - uae_sem_init (&sd->sync_sem, 0, 0); - uae_sem_init (&sd->change_sem, 0, 1); - uae_start_thread (L"uaeserial_win32", uaeser_trap_thread, sd, NULL); - uae_sem_wait (&sd->sync_sem); - - CommTimeOuts.ReadIntervalTimeout = 0; - CommTimeOuts.ReadTotalTimeoutMultiplier = 0; - CommTimeOuts.ReadTotalTimeoutConstant = 0; - CommTimeOuts.WriteTotalTimeoutMultiplier = 0; - CommTimeOuts.WriteTotalTimeoutConstant = 0; - SetCommTimeouts (sd->hCom, &CommTimeOuts); - SetCommMask (sd->hCom, EV_RXCHAR | EV_TXEMPTY | EV_BREAK); - - return 1; + uae_sem_init (&sd->sync_sem, 0, 0); + uae_sem_init (&sd->change_sem, 0, 1); + uae_start_thread (L"uaeserial_win32", uaeser_trap_thread, sd, NULL); + uae_sem_wait (&sd->sync_sem); + + CommTimeOuts.ReadIntervalTimeout = 0; + CommTimeOuts.ReadTotalTimeoutMultiplier = 0; + CommTimeOuts.ReadTotalTimeoutConstant = 0; + CommTimeOuts.WriteTotalTimeoutMultiplier = 0; + CommTimeOuts.WriteTotalTimeoutConstant = 0; + SetCommTimeouts (sd->hCom, &CommTimeOuts); + SetCommMask (sd->hCom, EV_RXCHAR | EV_TXEMPTY | EV_BREAK); + + return 1; end: - uaeser_close (sd); - return 0; + uaeser_close (sd); + return 0; } void uaeser_close (struct uaeserialdatawin32 *sd) { - if (sd->threadactive) { - sd->threadactive = -1; - SetEvent (sd->evtt); - while (sd->threadactive) - Sleep(10); - CloseHandle (sd->evtt); - } - if (sd->hCom != INVALID_HANDLE_VALUE) - CloseHandle(sd->hCom); - if (sd->evtr) - CloseHandle(sd->evtr); - if (sd->evtw) - CloseHandle(sd->evtw); - if (sd->evtwce) - CloseHandle(sd->evtwce); - uaeser_initdata (sd, sd->user); + if (sd->threadactive) { + sd->threadactive = -1; + SetEvent (sd->evtt); + while (sd->threadactive) + Sleep(10); + CloseHandle (sd->evtt); + } + if (sd->hCom != INVALID_HANDLE_VALUE) + CloseHandle(sd->hCom); + if (sd->evtr) + CloseHandle(sd->evtr); + if (sd->evtw) + CloseHandle(sd->evtw); + if (sd->evtwce) + CloseHandle(sd->evtwce); + uaeser_initdata (sd, sd->user); } static HANDLE hCom = INVALID_HANDLE_VALUE; @@ -822,500 +822,500 @@ static writepending; int openser (TCHAR *sername) { - COMMTIMEOUTS CommTimeOuts; + COMMTIMEOUTS CommTimeOuts; - if (!(readevent = CreateEvent (NULL, TRUE, FALSE, NULL))) { - write_log (L"SERIAL: Failed to create r event!\n"); - return 0; - } - readol.hEvent = readevent; + if (!(readevent = CreateEvent (NULL, TRUE, FALSE, NULL))) { + write_log (L"SERIAL: Failed to create r event!\n"); + return 0; + } + readol.hEvent = readevent; - if (!(writeevent = CreateEvent (NULL, TRUE, FALSE, NULL))) { - write_log (L"SERIAL: Failed to create w event!\n"); - return 0; - } - SetEvent (writeevent); - writeol.hEvent = writeevent; - - uartbreak = 0; - - hCom = CreateFile (sername, GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, - NULL); - if (hCom == INVALID_HANDLE_VALUE) { - write_log (L"SERIAL: failed to open '%s' err=%d\n", sername, GetLastError()); - closeser (); - return 0; - } - - SetCommMask (hCom, EV_RXFLAG); - SetupComm (hCom, 65536, 128); - PurgeComm (hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR); - CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF; - CommTimeOuts.ReadTotalTimeoutMultiplier = 0; - CommTimeOuts.ReadTotalTimeoutConstant = 0; - CommTimeOuts.WriteTotalTimeoutMultiplier = 0; - CommTimeOuts.WriteTotalTimeoutConstant = 0; - SetCommTimeouts (hCom, &CommTimeOuts); - - dcb.DCBlength = sizeof (DCB); - GetCommState (hCom, &dcb); - - dcb.fBinary = TRUE; - dcb.BaudRate = 9600; - dcb.ByteSize = 8; - dcb.Parity = NOPARITY; - dcb.fParity = FALSE; - dcb.StopBits = ONESTOPBIT; - - dcb.fDsrSensitivity = FALSE; - dcb.fOutxDsrFlow = FALSE; - dcb.fDtrControl = DTR_CONTROL_DISABLE; - - if (currprefs.serial_hwctsrts) { - dcb.fOutxCtsFlow = TRUE; - dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; - } else { - dcb.fRtsControl = RTS_CONTROL_DISABLE; - dcb.fOutxCtsFlow = FALSE; - } - - dcb.fTXContinueOnXoff = FALSE; - dcb.fOutX = FALSE; - dcb.fInX = FALSE; - - dcb.fErrorChar = FALSE; - dcb.fNull = FALSE; - dcb.fAbortOnError = FALSE; - - //dcb.XoffLim = 512; - //dcb.XonLim = 2048; - - if (SetCommState (hCom, &dcb)) { - write_log (L"SERIAL: Using %s CTS/RTS=%d\n", sername, currprefs.serial_hwctsrts); - return 1; - } + if (!(writeevent = CreateEvent (NULL, TRUE, FALSE, NULL))) { + write_log (L"SERIAL: Failed to create w event!\n"); + return 0; + } + SetEvent (writeevent); + writeol.hEvent = writeevent; + + uartbreak = 0; + + hCom = CreateFile (sername, GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, + NULL); + if (hCom == INVALID_HANDLE_VALUE) { + write_log (L"SERIAL: failed to open '%s' err=%d\n", sername, GetLastError()); + closeser (); + return 0; + } + + SetCommMask (hCom, EV_RXFLAG); + SetupComm (hCom, 65536, 128); + PurgeComm (hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR); + CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF; + CommTimeOuts.ReadTotalTimeoutMultiplier = 0; + CommTimeOuts.ReadTotalTimeoutConstant = 0; + CommTimeOuts.WriteTotalTimeoutMultiplier = 0; + CommTimeOuts.WriteTotalTimeoutConstant = 0; + SetCommTimeouts (hCom, &CommTimeOuts); + + dcb.DCBlength = sizeof (DCB); + GetCommState (hCom, &dcb); + + dcb.fBinary = TRUE; + dcb.BaudRate = 9600; + dcb.ByteSize = 8; + dcb.Parity = NOPARITY; + dcb.fParity = FALSE; + dcb.StopBits = ONESTOPBIT; + + dcb.fDsrSensitivity = FALSE; + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + + if (currprefs.serial_hwctsrts) { + dcb.fOutxCtsFlow = TRUE; + dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + } else { + dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fOutxCtsFlow = FALSE; + } + + dcb.fTXContinueOnXoff = FALSE; + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + + dcb.fErrorChar = FALSE; + dcb.fNull = FALSE; + dcb.fAbortOnError = FALSE; + + //dcb.XoffLim = 512; + //dcb.XonLim = 2048; + + if (SetCommState (hCom, &dcb)) { + write_log (L"SERIAL: Using %s CTS/RTS=%d\n", sername, currprefs.serial_hwctsrts); + return 1; + } - write_log (L"SERIAL: serial driver didn't accept new parameters\n"); - closeser(); - return 0; + write_log (L"SERIAL: serial driver didn't accept new parameters\n"); + closeser(); + return 0; } void closeser (void) { - if (hCom != INVALID_HANDLE_VALUE) { - CloseHandle (hCom); - hCom = INVALID_HANDLE_VALUE; - } - if (midi_ready) { - extern uae_u16 serper; - Midi_Close (); - //need for camd Midi Stuff(it close midi and reopen it but serial.c think the baudrate - //is the same and do not open midi), so setting serper to different value helps - serper = 0x30; - } - if(writeevent) - CloseHandle(writeevent); - writeevent = 0; - if(readevent) - CloseHandle(readevent); - readevent = 0; - uartbreak = 0; + if (hCom != INVALID_HANDLE_VALUE) { + CloseHandle (hCom); + hCom = INVALID_HANDLE_VALUE; + } + if (midi_ready) { + extern uae_u16 serper; + Midi_Close (); + //need for camd Midi Stuff(it close midi and reopen it but serial.c think the baudrate + //is the same and do not open midi), so setting serper to different value helps + serper = 0x30; + } + if(writeevent) + CloseHandle(writeevent); + writeevent = 0; + if(readevent) + CloseHandle(readevent); + readevent = 0; + uartbreak = 0; } static void outser (void) { - DWORD actual; - if (WaitForSingleObject (writeevent, 0) == WAIT_OBJECT_0 && datainoutput > 0) { - memcpy (outputbufferout, outputbuffer, datainoutput); - WriteFile (hCom, outputbufferout, datainoutput, &actual, &writeol); - datainoutput = 0; - } + DWORD actual; + if (WaitForSingleObject (writeevent, 0) == WAIT_OBJECT_0 && datainoutput > 0) { + memcpy (outputbufferout, outputbuffer, datainoutput); + WriteFile (hCom, outputbufferout, datainoutput, &actual, &writeol); + datainoutput = 0; + } } void writeser (int c) { - if (midi_ready) { - BYTE outchar = (BYTE)c; - Midi_Parse (midi_output, &outchar); - } else { - if (!currprefs.use_serial) - return; - if (datainoutput + 1 < sizeof (outputbuffer)) { - outputbuffer[datainoutput++] = c; + if (midi_ready) { + BYTE outchar = (BYTE)c; + Midi_Parse (midi_output, &outchar); } else { - write_log (L"serial output buffer overflow, data will be lost\n"); - datainoutput = 0; + if (!currprefs.use_serial) + return; + if (datainoutput + 1 < sizeof (outputbuffer)) { + outputbuffer[datainoutput++] = c; + } else { + write_log (L"serial output buffer overflow, data will be lost\n"); + datainoutput = 0; + } + outser (); } - outser (); - } } int checkserwrite (void) { - if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) - return 1; - if (midi_ready) { + if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) + return 1; + if (midi_ready) { + return 1; + } else { + outser (); + if (datainoutput >= sizeof (outputbuffer) - 1) + return 0; + } return 1; - } else { - outser (); - if (datainoutput >= sizeof (outputbuffer) - 1) - return 0; - } - return 1; } int readseravail (void) { - COMSTAT ComStat; - DWORD dwErrorFlags; - if (midi_ready) { - if (ismidibyte ()) - return 1; - } else { - if (!currprefs.use_serial) - return 0; - if (dataininput > dataininputcnt) - return 1; - if (hCom != INVALID_HANDLE_VALUE) { - ClearCommError (hCom, &dwErrorFlags, &ComStat); - if (ComStat.cbInQue > 0) - return 1; + COMSTAT ComStat; + DWORD dwErrorFlags; + if (midi_ready) { + if (ismidibyte ()) + return 1; + } else { + if (!currprefs.use_serial) + return 0; + if (dataininput > dataininputcnt) + return 1; + if (hCom != INVALID_HANDLE_VALUE) { + ClearCommError (hCom, &dwErrorFlags, &ComStat); + if (ComStat.cbInQue > 0) + return 1; + } } - } - return 0; + return 0; } int readser (int *buffer) { - COMSTAT ComStat; - DWORD dwErrorFlags; - DWORD actual; + COMSTAT ComStat; + DWORD dwErrorFlags; + DWORD actual; - if (midi_ready) { - *buffer = getmidibyte (); - if (*buffer < 0) - return 0; - return 1; - } else { - if (!currprefs.use_serial) - return 0; - if (dataininput > dataininputcnt) { - *buffer = inputbuffer[dataininputcnt++]; - return 1; - } - dataininput = 0; - dataininputcnt = 0; - if (hCom != INVALID_HANDLE_VALUE) { - /* only try to read number of bytes in queue */ - ClearCommError (hCom, &dwErrorFlags, &ComStat); - if (ComStat.cbInQue) { - int len = ComStat.cbInQue; - if (len > sizeof (inputbuffer)) - len = sizeof (inputbuffer); - if (!ReadFile (hCom, inputbuffer, len, &actual, &readol)) { - if (GetLastError() == ERROR_IO_PENDING) - WaitForSingleObject (&readol, INFINITE); - else + if (midi_ready) { + *buffer = getmidibyte (); + if (*buffer < 0) + return 0; + return 1; + } else { + if (!currprefs.use_serial) return 0; + if (dataininput > dataininputcnt) { + *buffer = inputbuffer[dataininputcnt++]; + return 1; } - dataininput = actual; + dataininput = 0; dataininputcnt = 0; - if (actual == 0) - return 0; - return readser (buffer); - } + if (hCom != INVALID_HANDLE_VALUE) { + /* only try to read number of bytes in queue */ + ClearCommError (hCom, &dwErrorFlags, &ComStat); + if (ComStat.cbInQue) { + int len = ComStat.cbInQue; + if (len > sizeof (inputbuffer)) + len = sizeof (inputbuffer); + if (!ReadFile (hCom, inputbuffer, len, &actual, &readol)) { + if (GetLastError() == ERROR_IO_PENDING) + WaitForSingleObject (&readol, INFINITE); + else + return 0; + } + dataininput = actual; + dataininputcnt = 0; + if (actual == 0) + return 0; + return readser (buffer); + } + } } - } - return 0; + return 0; } void serialuartbreak (int v) { - if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) - return; + if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) + return; - if (v) - EscapeCommFunction (hCom, SETBREAK); - else - EscapeCommFunction (hCom, CLRBREAK); + if (v) + EscapeCommFunction (hCom, SETBREAK); + else + EscapeCommFunction (hCom, CLRBREAK); } void getserstat (int *pstatus) { - DWORD stat; - int status = 0; - - *pstatus = 0; - if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) - return; - - GetCommModemStatus (hCom, &stat); - if (stat & MS_CTS_ON) - status |= TIOCM_CTS; - if (stat & MS_RLSD_ON) - status |= TIOCM_CAR; - if (stat & MS_DSR_ON) - status |= TIOCM_DSR; - if (stat & MS_RING_ON) - status |= TIOCM_RI; - *pstatus = status; + DWORD stat; + int status = 0; + + *pstatus = 0; + if (hCom == INVALID_HANDLE_VALUE || !currprefs.use_serial) + return; + + GetCommModemStatus (hCom, &stat); + if (stat & MS_CTS_ON) + status |= TIOCM_CTS; + if (stat & MS_RLSD_ON) + status |= TIOCM_CAR; + if (stat & MS_DSR_ON) + status |= TIOCM_DSR; + if (stat & MS_RING_ON) + status |= TIOCM_RI; + *pstatus = status; } void setserstat (int mask, int onoff) { - if (!currprefs.use_serial || hCom == INVALID_HANDLE_VALUE) - return; - - if (mask & TIOCM_DTR) - EscapeCommFunction (hCom, onoff ? SETDTR : CLRDTR); - if (!currprefs.serial_hwctsrts) { - if (mask & TIOCM_RTS) - EscapeCommFunction (hCom, onoff ? SETRTS : CLRRTS); - } + if (!currprefs.use_serial || hCom == INVALID_HANDLE_VALUE) + return; + + if (mask & TIOCM_DTR) + EscapeCommFunction (hCom, onoff ? SETDTR : CLRDTR); + if (!currprefs.serial_hwctsrts) { + if (mask & TIOCM_RTS) + EscapeCommFunction (hCom, onoff ? SETRTS : CLRRTS); + } } int setbaud (long baud) { - if(baud == 31400 && currprefs.win32_midioutdev >= -1) { - /* MIDI baud-rate */ - if (!midi_ready) { - if (Midi_Open()) - write_log (L"Midi enabled\n"); - } - return 1; - } else { - if (midi_ready) { - Midi_Close(); - } - if (!currprefs.use_serial) - return 1; - if (hCom != INVALID_HANDLE_VALUE) { - if (GetCommState (hCom, &dcb)) { - dcb.BaudRate = baud; - if (!SetCommState (hCom, &dcb)) { - write_log (L"SERIAL: Error setting baud rate %d!\n", baud); - return 0; + if(baud == 31400 && currprefs.win32_midioutdev >= -1) { + /* MIDI baud-rate */ + if (!midi_ready) { + if (Midi_Open()) + write_log (L"Midi enabled\n"); + } + return 1; + } else { + if (midi_ready) { + Midi_Close(); + } + if (!currprefs.use_serial) + return 1; + if (hCom != INVALID_HANDLE_VALUE) { + if (GetCommState (hCom, &dcb)) { + dcb.BaudRate = baud; + if (!SetCommState (hCom, &dcb)) { + write_log (L"SERIAL: Error setting baud rate %d!\n", baud); + return 0; + } + } else { + write_log (L"SERIAL: setbaud internal error!\n"); + } } - } else { - write_log (L"SERIAL: setbaud internal error!\n"); - } } - } - return 1; + return 1; } void initparallel (void) { - if (uae_boot_rom) { - uaecptr a = here (); //this install the ahisound - org (rtarea_base + 0xFFC0); - calltrap (deftrapres (ahi_demux, 0, L"ahi_winuae")); - dw (RTS); - org (a); - init_ahi_v2 (); - } + if (uae_boot_rom) { + uaecptr a = here (); //this install the ahisound + org (rtarea_base + 0xFFC0); + calltrap (deftrapres (ahi_demux, 0, L"ahi_winuae")); + dw (RTS); + org (a); + init_ahi_v2 (); + } } int flashscreen; void doflashscreen (void) { - flashscreen = 10; - init_colors (); - picasso_refresh (); - reset_drawing (); - flush_screen (0, 0); + flashscreen = 10; + init_colors (); + picasso_refresh (); + reset_drawing (); + flush_screen (0, 0); } void hsyncstuff (void) -//only generate Interrupts when -//writebuffer is complete flushed -//check state of lwin rwin + //only generate Interrupts when + //writebuffer is complete flushed + //check state of lwin rwin { - static int keycheck = 0; + static int keycheck = 0; #ifdef AHI - { //begin ahi_sound - static int count; - if (ahi_on) { - count++; - //15625/count freebuffer check - if(count > ahi_pollrate) { - ahi_updatesound (1); - count = 0; - } - } - } //end ahi_sound + { //begin ahi_sound + static int count; + if (ahi_on) { + count++; + //15625/count freebuffer check + if(count > ahi_pollrate) { + ahi_updatesound (1); + count = 0; + } + } + } //end ahi_sound #endif #ifdef PARALLEL_PORT - keycheck++; - if(keycheck >= 1000) - { - if (prtopen) - flushprtbuf (); + keycheck++; + if(keycheck >= 1000) { - if (flashscreen > 0) { - flashscreen--; - if (flashscreen == 0) { - init_colors (); - reset_drawing (); - picasso_refresh (); - flush_screen (0, 0); + if (prtopen) + flushprtbuf (); + { + if (flashscreen > 0) { + flashscreen--; + if (flashscreen == 0) { + init_colors (); + reset_drawing (); + picasso_refresh (); + flush_screen (0, 0); + } + } } - } + keycheck = 0; } - keycheck = 0; - } - if (currprefs.parallel_autoflush_time && !currprefs.parallel_postscript_detection) { - parflush++; - if (parflush / ((currprefs.ntscmode ? MAXVPOS_NTSC : MAXVPOS_PAL) * MAXHPOS_PAL / maxhpos) >= currprefs.parallel_autoflush_time * 50) { - flushprinter (); - parflush = 0; + if (currprefs.parallel_autoflush_time && !currprefs.parallel_postscript_detection) { + parflush++; + if (parflush / ((currprefs.ntscmode ? MAXVPOS_NTSC : MAXVPOS_PAL) * MAXHPOS_PAL / maxhpos) >= currprefs.parallel_autoflush_time * 50) { + flushprinter (); + parflush = 0; + } } - } #endif } static int enumserialports_2 (int cnt) { - // Create a device information set that will be the container for - // the device interfaces. - HDEVINFO hDevInfo = INVALID_HANDLE_VALUE; - SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL; - BOOL bOk = TRUE; - SP_DEVICE_INTERFACE_DATA ifcData; - DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256; - DWORD ii; - - hDevInfo = SetupDiGetClassDevs (&GUID_CLASS_COMPORT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - if(hDevInfo == INVALID_HANDLE_VALUE) - return 0; - // Enumerate the serial ports - pDetData = xmalloc (dwDetDataSize); - // This is required, according to the documentation. Yes, - // it's weird. - ifcData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA); - pDetData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA); - for (ii = 0; bOk; ii++) { - bOk = SetupDiEnumDeviceInterfaces (hDevInfo, NULL, &GUID_CLASS_COMPORT, ii, &ifcData); - if (bOk) { - // Got a device. Get the details. - SP_DEVINFO_DATA devdata = { sizeof (SP_DEVINFO_DATA)}; - bOk = SetupDiGetDeviceInterfaceDetail (hDevInfo, - &ifcData, pDetData, dwDetDataSize, NULL, &devdata); - if (bOk) { - // Got a path to the device. Try to get some more info. - TCHAR fname[256]; - TCHAR desc[256]; - BOOL bSuccess = SetupDiGetDeviceRegistryProperty ( - hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL, - (PBYTE)fname, sizeof (fname), NULL); - bSuccess = bSuccess && SetupDiGetDeviceRegistryProperty ( - hDevInfo, &devdata, SPDRP_DEVICEDESC, NULL, - (PBYTE)desc, sizeof (desc), NULL); - if (bSuccess && cnt < MAX_SERIAL_PORTS) { - TCHAR *p; - comports[cnt].dev = my_strdup (pDetData->DevicePath); - comports[cnt].name = my_strdup (fname); - p = _tcsstr (fname, L"(COM"); - if (p && (p[5] == ')' || p[6] == ')')) { - comports[cnt].cfgname = xmalloc (100); - if (isdigit(p[5])) - _stprintf (comports[cnt].cfgname, L"COM%c%c", p[4], p[5]); - else - _stprintf (comports[cnt].cfgname, L"COM%c", p[4]); - } else { - comports[cnt].cfgname = my_strdup (pDetData->DevicePath); - } - write_log (L"SERPORT: '%s' = '%s' = '%s'\n", comports[cnt].name, comports[cnt].cfgname, comports[cnt].dev); - cnt++; + // Create a device information set that will be the container for + // the device interfaces. + HDEVINFO hDevInfo = INVALID_HANDLE_VALUE; + SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL; + BOOL bOk = TRUE; + SP_DEVICE_INTERFACE_DATA ifcData; + DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256; + DWORD ii; + + hDevInfo = SetupDiGetClassDevs (&GUID_CLASS_COMPORT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + if(hDevInfo == INVALID_HANDLE_VALUE) + return 0; + // Enumerate the serial ports + pDetData = xmalloc (dwDetDataSize); + // This is required, according to the documentation. Yes, + // it's weird. + ifcData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA); + pDetData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA); + for (ii = 0; bOk; ii++) { + bOk = SetupDiEnumDeviceInterfaces (hDevInfo, NULL, &GUID_CLASS_COMPORT, ii, &ifcData); + if (bOk) { + // Got a device. Get the details. + SP_DEVINFO_DATA devdata = { sizeof (SP_DEVINFO_DATA)}; + bOk = SetupDiGetDeviceInterfaceDetail (hDevInfo, + &ifcData, pDetData, dwDetDataSize, NULL, &devdata); + if (bOk) { + // Got a path to the device. Try to get some more info. + TCHAR fname[256]; + TCHAR desc[256]; + BOOL bSuccess = SetupDiGetDeviceRegistryProperty ( + hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL, + (PBYTE)fname, sizeof (fname), NULL); + bSuccess = bSuccess && SetupDiGetDeviceRegistryProperty ( + hDevInfo, &devdata, SPDRP_DEVICEDESC, NULL, + (PBYTE)desc, sizeof (desc), NULL); + if (bSuccess && cnt < MAX_SERIAL_PORTS) { + TCHAR *p; + comports[cnt].dev = my_strdup (pDetData->DevicePath); + comports[cnt].name = my_strdup (fname); + p = _tcsstr (fname, L"(COM"); + if (p && (p[5] == ')' || p[6] == ')')) { + comports[cnt].cfgname = xmalloc (100); + if (isdigit(p[5])) + _stprintf (comports[cnt].cfgname, L"COM%c%c", p[4], p[5]); + else + _stprintf (comports[cnt].cfgname, L"COM%c", p[4]); + } else { + comports[cnt].cfgname = my_strdup (pDetData->DevicePath); + } + write_log (L"SERPORT: '%s' = '%s' = '%s'\n", comports[cnt].name, comports[cnt].cfgname, comports[cnt].dev); + cnt++; + } + } else { + write_log (L"SetupDiGetDeviceInterfaceDetail failed, err=%d", GetLastError ()); + goto end; + } + } else { + DWORD err = GetLastError(); + if (err != ERROR_NO_MORE_ITEMS) { + write_log (L"SetupDiEnumDeviceInterfaces failed, err=%d", err); + goto end; + } } - } else { - write_log (L"SetupDiGetDeviceInterfaceDetail failed, err=%d", GetLastError ()); - goto end; - } - } else { - DWORD err = GetLastError(); - if (err != ERROR_NO_MORE_ITEMS) { - write_log (L"SetupDiEnumDeviceInterfaces failed, err=%d", err); - goto end; - } } - } end: - xfree(pDetData); - if (hDevInfo != INVALID_HANDLE_VALUE) - SetupDiDestroyDeviceInfoList (hDevInfo); - return cnt; + xfree(pDetData); + if (hDevInfo != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList (hDevInfo); + return cnt; } int enumserialports (void) { - int cnt, i, j; - TCHAR name[256]; - DWORD size = sizeof (COMMCONFIG); - TCHAR devname[1000]; - - write_log (L"Serial port enumeration..\n"); - - comports[0].dev = my_strdup (L"ENET:H"); - comports[0].cfgname = my_strdup (comports[0].dev); - comports[0].name = my_strdup (L"NET (host)"); - comports[1].dev = my_strdup (L"ENET:L"); - comports[1].cfgname = my_strdup (comports[1].dev); - comports[1].name = my_strdup (L"NET (client)"); - - cnt = enumserialports_2 (2); - for (i = 0; i < 10; i++) { - _stprintf(name, L"COM%d", i); - if (!QueryDosDevice (name, devname, sizeof devname)) - continue; - for(j = 0; j < cnt; j++) { - if (!_tcscmp(comports[j].cfgname, name)) - break; - } - if (j == cnt) { - if (cnt >= MAX_SERIAL_PORTS) - break; - comports[j].dev = xmalloc (100); - _stprintf (comports[cnt].dev, L"\\.\\\\%s", name); - comports[j].cfgname = my_strdup (name); - comports[j].name = my_strdup (name); - write_log (L"SERPORT: %d:'%s' = '%s' (%s)\n", cnt, comports[j].name, comports[j].dev, devname); - cnt++; + int cnt, i, j; + TCHAR name[256]; + DWORD size = sizeof (COMMCONFIG); + TCHAR devname[1000]; + + write_log (L"Serial port enumeration..\n"); + + comports[0].dev = my_strdup (L"ENET:H"); + comports[0].cfgname = my_strdup (comports[0].dev); + comports[0].name = my_strdup (L"NET (host)"); + comports[1].dev = my_strdup (L"ENET:L"); + comports[1].cfgname = my_strdup (comports[1].dev); + comports[1].name = my_strdup (L"NET (client)"); + + cnt = enumserialports_2 (2); + for (i = 0; i < 10; i++) { + _stprintf(name, L"COM%d", i); + if (!QueryDosDevice (name, devname, sizeof devname)) + continue; + for(j = 0; j < cnt; j++) { + if (!_tcscmp(comports[j].cfgname, name)) + break; + } + if (j == cnt) { + if (cnt >= MAX_SERIAL_PORTS) + break; + comports[j].dev = xmalloc (100); + _stprintf (comports[cnt].dev, L"\\.\\\\%s", name); + comports[j].cfgname = my_strdup (name); + comports[j].name = my_strdup (name); + write_log (L"SERPORT: %d:'%s' = '%s' (%s)\n", cnt, comports[j].name, comports[j].dev, devname); + cnt++; + } } - } - write_log (L"Serial port enumeration end\n"); - return cnt; + write_log (L"Serial port enumeration end\n"); + return cnt; } void sernametodev (TCHAR *sername) { - int i; + int i; - for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { - if (!_tcscmp(sername, comports[i].cfgname)) { - _tcscpy (sername, comports[i].dev); - return; + for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { + if (!_tcscmp(sername, comports[i].cfgname)) { + _tcscpy (sername, comports[i].dev); + return; + } } - } - sername[0] = 0; + sername[0] = 0; } void serdevtoname (TCHAR *sername) { - int i; - for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { - if (!_tcscmp(sername, comports[i].dev)) { - _tcscpy (sername, comports[i].cfgname); - return; + int i; + for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { + if (!_tcscmp(sername, comports[i].dev)) { + _tcscpy (sername, comports[i].cfgname); + return; + } } - } - sername[0] = 0; + sername[0] = 0; } diff --git a/od-win32/picasso96_win.c b/od-win32/picasso96_win.c index 3caafbcf..08ff887e 100644 --- a/od-win32/picasso96_win.c +++ b/od-win32/picasso96_win.c @@ -144,29 +144,29 @@ static uae_sem_t sem; static int thread_alive; static uaecptr uaegfx_resname, - uaegfx_resid, - uaegfx_init, - uaegfx_base, - uaegfx_rom; + uaegfx_resid, + uaegfx_init, + uaegfx_base, + uaegfx_rom; 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_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" @@ -176,33 +176,33 @@ typedef enum { #define UAE_RTG_LIBRARY_REVISION 3994 static void checkrtglibrary(void) { - uae_u32 v; - static int checked = FALSE; - - if (checked) - return; - v = get_long (4); // execbase - v += 378; // liblist - while ((v = get_long (v))) { - uae_u32 v2 = get_long (v + 10); // name - uae_u8 *p; - addrbank *b = &get_mem_bank(v2); - if (!b || !b->check (v2, 12)) - continue; - p = b->xlateaddr(v2); - if (!memcmp(p, "rtg.library\0", 12)) { - uae_u16 ver = get_word (v + 20); - uae_u16 rev = get_word (v + 22); - if (ver * 10000 + rev < UAE_RTG_LIBRARY_VERSION * 10000 + UAE_RTG_LIBRARY_REVISION) { - TCHAR msg[2000]; - WIN32GUI_LoadUIString(IDS_OLDRTGLIBRARY, msg, sizeof(msg)); - gui_message(msg, ver, rev, UAE_RTG_LIBRARY_VERSION, UAE_RTG_LIBRARY_REVISION); - } else { - write_log (L"P96: rtg.library %d.%d detected\n", ver, rev); - } - checked = TRUE; + uae_u32 v; + static int checked = FALSE; + + if (checked) + return; + v = get_long (4); // execbase + v += 378; // liblist + while ((v = get_long (v))) { + uae_u32 v2 = get_long (v + 10); // name + uae_u8 *p; + addrbank *b = &get_mem_bank(v2); + if (!b || !b->check (v2, 12)) + continue; + p = b->xlateaddr(v2); + if (!memcmp(p, "rtg.library\0", 12)) { + uae_u16 ver = get_word (v + 20); + uae_u16 rev = get_word (v + 22); + if (ver * 10000 + rev < UAE_RTG_LIBRARY_VERSION * 10000 + UAE_RTG_LIBRARY_REVISION) { + TCHAR msg[2000]; + WIN32GUI_LoadUIString(IDS_OLDRTGLIBRARY, msg, sizeof(msg)); + gui_message(msg, ver, rev, UAE_RTG_LIBRARY_VERSION, UAE_RTG_LIBRARY_REVISION); + } else { + write_log (L"P96: rtg.library %d.%d detected\n", ver, rev); + } + checked = TRUE; + } } - } } static uae_u32 p2ctab[256][2]; @@ -213,16 +213,16 @@ static uaecptr oldscr = 0; static void endianswap (uae_u32 *vp, int bpp) { - uae_u32 v = *vp; - switch (bpp) - { + uae_u32 v = *vp; + switch (bpp) + { case 2: - *vp = (((v >> 8) & 0x00ff) | (v << 8)) & 0xffff; - break; + *vp = (((v >> 8) & 0x00ff) | (v << 8)) & 0xffff; + break; case 4: - *vp = ((v >> 24) & 0x000000ff) | ((v >> 8) & 0x0000ff00) | ((v << 8) & 0x00ff0000) | ((v << 24) & 0xff000000); - break; - } + *vp = ((v >> 24) & 0x000000ff) | ((v >> 8) & 0x0000ff00) | ((v << 8) & 0x00ff0000) | ((v << 24) & 0xff000000); + break; + } } #if P96TRACING_ENABLED @@ -231,130 +231,130 @@ static void endianswap (uae_u32 *vp, int bpp) */ static void DumpModeInfoStructure (uaecptr amigamodeinfoptr) { - write_log (L"ModeInfo Structure Dump:\n"); - write_log (L" Node.ln_Succ = 0x%x\n", get_long (amigamodeinfoptr)); - write_log (L" Node.ln_Pred = 0x%x\n", get_long (amigamodeinfoptr + 4)); - write_log (L" Node.ln_Type = 0x%x\n", get_byte (amigamodeinfoptr + 8)); - write_log (L" Node.ln_Pri = %d\n", get_byte (amigamodeinfoptr + 9)); - /*write_log (L" Node.ln_Name = %s\n", uaememptr->Node.ln_Name); */ - write_log (L" OpenCount = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_OpenCount)); - write_log (L" Active = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Active)); - write_log (L" Width = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Width)); - write_log (L" Height = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Height)); - write_log (L" Depth = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Depth)); - write_log (L" Flags = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Flags)); - write_log (L" HorTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorTotal)); - write_log (L" HorBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorBlankSize)); - write_log (L" HorSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncStart)); - write_log (L" HorSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSize)); - write_log (L" HorSyncSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSkew)); - write_log (L" HorEnableSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorEnableSkew)); - write_log (L" VerTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerTotal)); - write_log (L" VerBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerBlankSize)); - write_log (L" VerSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncStart)); - write_log (L" VerSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncSize)); - write_log (L" Clock = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_first_union)); - write_log (L" ClockDivide = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_second_union)); - write_log (L" PixelClock = %d\n", get_long (amigamodeinfoptr + PSSO_ModeInfo_PixelClock)); + write_log (L"ModeInfo Structure Dump:\n"); + write_log (L" Node.ln_Succ = 0x%x\n", get_long (amigamodeinfoptr)); + write_log (L" Node.ln_Pred = 0x%x\n", get_long (amigamodeinfoptr + 4)); + write_log (L" Node.ln_Type = 0x%x\n", get_byte (amigamodeinfoptr + 8)); + write_log (L" Node.ln_Pri = %d\n", get_byte (amigamodeinfoptr + 9)); + /*write_log (L" Node.ln_Name = %s\n", uaememptr->Node.ln_Name); */ + write_log (L" OpenCount = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_OpenCount)); + write_log (L" Active = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Active)); + write_log (L" Width = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Width)); + write_log (L" Height = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Height)); + write_log (L" Depth = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Depth)); + write_log (L" Flags = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Flags)); + write_log (L" HorTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorTotal)); + write_log (L" HorBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorBlankSize)); + write_log (L" HorSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncStart)); + write_log (L" HorSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSize)); + write_log (L" HorSyncSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSkew)); + write_log (L" HorEnableSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorEnableSkew)); + write_log (L" VerTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerTotal)); + write_log (L" VerBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerBlankSize)); + write_log (L" VerSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncStart)); + write_log (L" VerSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncSize)); + write_log (L" Clock = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_first_union)); + write_log (L" ClockDivide = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_second_union)); + write_log (L" PixelClock = %d\n", get_long (amigamodeinfoptr + PSSO_ModeInfo_PixelClock)); } static void DumpLibResolutionStructure (uaecptr amigalibresptr) { - int i; - uaecptr amigamodeinfoptr; - struct LibResolution *uaememptr = (struct LibResolution *)get_mem_bank(amigalibresptr).xlateaddr(amigalibresptr); - - write_log (L"LibResolution Structure Dump:\n"); - - if (get_long (amigalibresptr + PSSO_LibResolution_DisplayID) == 0xFFFFFFFF) { - write_log (L" Finished With LibResolutions...\n"); - } else { - write_log (L" Name = %s\n", uaememptr->P96ID); - write_log (L" DisplayID = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_DisplayID)); - write_log (L" Width = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Width)); - write_log (L" Height = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Height)); - write_log (L" Flags = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Flags)); - for (i = 0; i < MAXMODES; i++) { - amigamodeinfoptr = get_long (amigalibresptr + PSSO_LibResolution_Modes + i*4); - write_log (L" ModeInfo[%d] = 0x%x\n", i, amigamodeinfoptr); - if (amigamodeinfoptr) - DumpModeInfoStructure (amigamodeinfoptr); + int i; + uaecptr amigamodeinfoptr; + struct LibResolution *uaememptr = (struct LibResolution *)get_mem_bank(amigalibresptr).xlateaddr(amigalibresptr); + + write_log (L"LibResolution Structure Dump:\n"); + + if (get_long (amigalibresptr + PSSO_LibResolution_DisplayID) == 0xFFFFFFFF) { + write_log (L" Finished With LibResolutions...\n"); + } else { + write_log (L" Name = %s\n", uaememptr->P96ID); + write_log (L" DisplayID = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_DisplayID)); + write_log (L" Width = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Width)); + write_log (L" Height = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Height)); + write_log (L" Flags = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Flags)); + for (i = 0; i < MAXMODES; i++) { + amigamodeinfoptr = get_long (amigalibresptr + PSSO_LibResolution_Modes + i*4); + write_log (L" ModeInfo[%d] = 0x%x\n", i, amigamodeinfoptr); + if (amigamodeinfoptr) + DumpModeInfoStructure (amigamodeinfoptr); + } + write_log (L" BoardInfo = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_BoardInfo)); } - write_log (L" BoardInfo = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_BoardInfo)); - } } static TCHAR binary_byte[9] = { 0,0,0,0,0,0,0,0,0 }; static TCHAR *BuildBinaryString (uae_u8 value) { - int i; - for (i = 0; i < 8; i++) { - binary_byte[i] = (value & (1 << (7 - i))) ? '#' : '.'; - } - return binary_byte; + int i; + for (i = 0; i < 8; i++) { + binary_byte[i] = (value & (1 << (7 - i))) ? '#' : '.'; + } + return binary_byte; } static void DumpPattern (struct Pattern *patt) { - uae_u8 *mem; - int row, col; - for (row = 0; row < (1 << patt->Size); row++) { - mem = patt->Memory + row * 2; - for (col = 0; col < 2; col++) { - write_log (L"%s ", BuildBinaryString (*mem++)); + uae_u8 *mem; + int row, col; + for (row = 0; row < (1 << patt->Size); row++) { + mem = patt->Memory + row * 2; + for (col = 0; col < 2; col++) { + write_log (L"%s ", BuildBinaryString (*mem++)); + } + write_log (L"\n"); } - write_log (L"\n"); - } } static void DumpTemplate (struct Template *tmp, unsigned long w, unsigned long h) { - uae_u8 *mem = tmp->Memory; - unsigned int row, col, width; - width = (w + 7) >> 3; - write_log (L"xoffset = %d, bpr = %d\n", tmp->XOffset, tmp->BytesPerRow); - for (row = 0; row < h; row++) { - mem = tmp->Memory + row * tmp->BytesPerRow; - for (col = 0; col < width; col++) { - write_log (L"%s ", BuildBinaryString (*mem++)); + uae_u8 *mem = tmp->Memory; + unsigned int row, col, width; + width = (w + 7) >> 3; + write_log (L"xoffset = %d, bpr = %d\n", tmp->XOffset, tmp->BytesPerRow); + for (row = 0; row < h; row++) { + mem = tmp->Memory + row * tmp->BytesPerRow; + for (col = 0; col < width; col++) { + write_log (L"%s ", BuildBinaryString (*mem++)); + } + write_log (L"\n"); } - write_log (L"\n"); - } } static void DumpLine(struct Line *line) { - if (line) { - write_log (L"Line->X = %d\n", line->X); - write_log (L"Line->Y = %d\n", line->Y); - write_log (L"Line->Length = %d\n", line->Length); - write_log (L"Line->dX = %d\n", line->dX); - write_log (L"Line->dY = %d\n", line->dY); - write_log (L"Line->sDelta = %d\n", line->sDelta); - write_log (L"Line->lDelta = %d\n", line->lDelta); - write_log (L"Line->twoSDminusLD = %d\n", line->twoSDminusLD); - write_log (L"Line->LinePtrn = %d\n", line->LinePtrn); - write_log (L"Line->PatternShift = %d\n", line->PatternShift); - write_log (L"Line->FgPen = 0x%x\n", line->FgPen); - write_log (L"Line->BgPen = 0x%x\n", line->BgPen); - write_log (L"Line->Horizontal = %d\n", line->Horizontal); - write_log (L"Line->DrawMode = %d\n", line->DrawMode); - write_log (L"Line->Xorigin = %d\n", line->Xorigin); - write_log (L"Line->Yorigin = %d\n", line->Yorigin); - } + if (line) { + write_log (L"Line->X = %d\n", line->X); + write_log (L"Line->Y = %d\n", line->Y); + write_log (L"Line->Length = %d\n", line->Length); + write_log (L"Line->dX = %d\n", line->dX); + write_log (L"Line->dY = %d\n", line->dY); + write_log (L"Line->sDelta = %d\n", line->sDelta); + write_log (L"Line->lDelta = %d\n", line->lDelta); + write_log (L"Line->twoSDminusLD = %d\n", line->twoSDminusLD); + write_log (L"Line->LinePtrn = %d\n", line->LinePtrn); + write_log (L"Line->PatternShift = %d\n", line->PatternShift); + write_log (L"Line->FgPen = 0x%x\n", line->FgPen); + write_log (L"Line->BgPen = 0x%x\n", line->BgPen); + write_log (L"Line->Horizontal = %d\n", line->Horizontal); + write_log (L"Line->DrawMode = %d\n", line->DrawMode); + write_log (L"Line->Xorigin = %d\n", line->Xorigin); + write_log (L"Line->Yorigin = %d\n", line->Yorigin); + } } static void ShowSupportedResolutions (void) { - int i = 0; - - write_log (L"-----------------\n"); - while (newmodes[i].depth >= 0) { - write_log (L"%s\n", newmodes[i].name); - i++; - } - write_log (L"-----------------\n"); + int i = 0; + + write_log (L"-----------------\n"); + while (newmodes[i].depth >= 0) { + write_log (L"%s\n", newmodes[i].name); + i++; + } + write_log (L"-----------------\n"); } #endif @@ -365,20 +365,20 @@ extern uae_u8 *natmem_offset; static uae_u8 GetBytesPerPixel (uae_u32 RGBfmt) { - switch (RGBfmt) - { + switch (RGBfmt) + { case RGBFB_CLUT: - return 1; + return 1; case RGBFB_A8R8G8B8: case RGBFB_A8B8G8R8: case RGBFB_R8G8B8A8: case RGBFB_B8G8R8A8: - return 4; + return 4; case RGBFB_B8G8R8: case RGBFB_R8G8B8: - return 3; + return 3; case RGBFB_R5G5B5: case RGBFB_R5G6B5: @@ -386,9 +386,9 @@ static uae_u8 GetBytesPerPixel (uae_u32 RGBfmt) case RGBFB_R5G5B5PC: case RGBFB_B5G6R5PC: case RGBFB_B5G5R5PC: - return 2; - } - return 0; + return 2; + } + return 0; } /* @@ -397,194 +397,194 @@ static uae_u8 GetBytesPerPixel (uae_u32 RGBfmt) static int CopyRenderInfoStructureA2U (uaecptr amigamemptr, struct RenderInfo *ri) { - uaecptr memp = get_long (amigamemptr + PSSO_RenderInfo_Memory); + uaecptr memp = get_long (amigamemptr + PSSO_RenderInfo_Memory); - if (valid_address (memp, PSSO_RenderInfo_sizeof)) { - ri->Memory = get_real_address (memp); - ri->BytesPerRow = get_word (amigamemptr + PSSO_RenderInfo_BytesPerRow); - ri->RGBFormat = get_long (amigamemptr + PSSO_RenderInfo_RGBFormat); - return 1; - } - write_log (L"ERROR - Invalid RenderInfo memory area...\n"); - return 0; + if (valid_address (memp, PSSO_RenderInfo_sizeof)) { + ri->Memory = get_real_address (memp); + ri->BytesPerRow = get_word (amigamemptr + PSSO_RenderInfo_BytesPerRow); + ri->RGBFormat = get_long (amigamemptr + PSSO_RenderInfo_RGBFormat); + return 1; + } + write_log (L"ERROR - Invalid RenderInfo memory area...\n"); + return 0; } static int CopyPatternStructureA2U (uaecptr amigamemptr, struct Pattern *pattern) { - uaecptr memp = get_long (amigamemptr + PSSO_Pattern_Memory); - if (valid_address (memp, PSSO_Pattern_sizeof)) { - pattern->Memory = get_real_address (memp); - pattern->XOffset = get_word (amigamemptr + PSSO_Pattern_XOffset); - pattern->YOffset = get_word (amigamemptr + PSSO_Pattern_YOffset); - pattern->FgPen = get_long (amigamemptr + PSSO_Pattern_FgPen); - pattern->BgPen = get_long (amigamemptr + PSSO_Pattern_BgPen); - pattern->Size = get_byte (amigamemptr + PSSO_Pattern_Size); - pattern->DrawMode = get_byte (amigamemptr + PSSO_Pattern_DrawMode); - return 1; - } - write_log (L"ERROR - Invalid Pattern memory area...\n"); - return 0; + uaecptr memp = get_long (amigamemptr + PSSO_Pattern_Memory); + if (valid_address (memp, PSSO_Pattern_sizeof)) { + pattern->Memory = get_real_address (memp); + pattern->XOffset = get_word (amigamemptr + PSSO_Pattern_XOffset); + pattern->YOffset = get_word (amigamemptr + PSSO_Pattern_YOffset); + pattern->FgPen = get_long (amigamemptr + PSSO_Pattern_FgPen); + pattern->BgPen = get_long (amigamemptr + PSSO_Pattern_BgPen); + pattern->Size = get_byte (amigamemptr + PSSO_Pattern_Size); + pattern->DrawMode = get_byte (amigamemptr + PSSO_Pattern_DrawMode); + return 1; + } + write_log (L"ERROR - Invalid Pattern memory area...\n"); + return 0; } static void CopyColorIndexMappingA2U (uaecptr amigamemptr, struct ColorIndexMapping *cim, int Bpp) { - int i; - cim->ColorMask = get_long (amigamemptr); - for (i = 0; i < 256; i++, amigamemptr += 4) { - uae_u32 v = get_long (amigamemptr + 4); - endianswap (&v, Bpp); - cim->Colors[i] = v; - } + int i; + cim->ColorMask = get_long (amigamemptr); + for (i = 0; i < 256; i++, amigamemptr += 4) { + uae_u32 v = get_long (amigamemptr + 4); + endianswap (&v, Bpp); + cim->Colors[i] = v; + } } static int CopyBitMapStructureA2U (uaecptr amigamemptr, struct BitMap *bm) { - int i; - - bm->BytesPerRow = get_word (amigamemptr + PSSO_BitMap_BytesPerRow); - bm->Rows = get_word (amigamemptr + PSSO_BitMap_Rows); - bm->Flags = get_byte (amigamemptr + PSSO_BitMap_Flags); - bm->Depth = get_byte (amigamemptr + PSSO_BitMap_Depth); - - /* ARGH - why is THIS happening? */ - if(bm->Depth > 8) - bm->Depth = 8; - - for (i = 0; i < bm->Depth; i++) { - uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i * 4); - switch (plane) { - case 0: - bm->Planes[i] = &all_zeros_bitmap; - break; - case 0xFFFFFFFF: - bm->Planes[i] = &all_ones_bitmap; - break; - default: - if (valid_address (plane, bm->BytesPerRow * bm->Rows)) - bm->Planes[i] = get_real_address (plane); - else - return 0; - break; + int i; + + bm->BytesPerRow = get_word (amigamemptr + PSSO_BitMap_BytesPerRow); + bm->Rows = get_word (amigamemptr + PSSO_BitMap_Rows); + bm->Flags = get_byte (amigamemptr + PSSO_BitMap_Flags); + bm->Depth = get_byte (amigamemptr + PSSO_BitMap_Depth); + + /* ARGH - why is THIS happening? */ + if(bm->Depth > 8) + bm->Depth = 8; + + for (i = 0; i < bm->Depth; i++) { + uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i * 4); + switch (plane) { + case 0: + bm->Planes[i] = &all_zeros_bitmap; + break; + case 0xFFFFFFFF: + bm->Planes[i] = &all_ones_bitmap; + break; + default: + if (valid_address (plane, bm->BytesPerRow * bm->Rows)) + bm->Planes[i] = get_real_address (plane); + else + return 0; + break; + } } - } - return 1; + return 1; } static int CopyTemplateStructureA2U (uaecptr amigamemptr, struct Template *tmpl) { - uaecptr memp = get_long (amigamemptr + PSSO_Template_Memory); - - if (valid_address (memp, sizeof(struct Template))) { - tmpl->Memory = get_real_address (memp); - tmpl->BytesPerRow = get_word (amigamemptr + PSSO_Template_BytesPerRow); - tmpl->XOffset = get_byte (amigamemptr + PSSO_Template_XOffset); - tmpl->DrawMode = get_byte (amigamemptr + PSSO_Template_DrawMode); - tmpl->FgPen = get_long (amigamemptr + PSSO_Template_FgPen); - tmpl->BgPen = get_long (amigamemptr + PSSO_Template_BgPen); - return 1; - } - write_log (L"ERROR - Invalid Template memory area...\n"); - return 0; + uaecptr memp = get_long (amigamemptr + PSSO_Template_Memory); + + if (valid_address (memp, sizeof(struct Template))) { + tmpl->Memory = get_real_address (memp); + tmpl->BytesPerRow = get_word (amigamemptr + PSSO_Template_BytesPerRow); + tmpl->XOffset = get_byte (amigamemptr + PSSO_Template_XOffset); + tmpl->DrawMode = get_byte (amigamemptr + PSSO_Template_DrawMode); + tmpl->FgPen = get_long (amigamemptr + PSSO_Template_FgPen); + tmpl->BgPen = get_long (amigamemptr + PSSO_Template_BgPen); + return 1; + } + write_log (L"ERROR - Invalid Template memory area...\n"); + return 0; } static int CopyLineStructureA2U(uaecptr amigamemptr, struct Line *line) { - if (valid_address(amigamemptr, sizeof(struct Line))) { - line->X = get_word (amigamemptr + PSSO_Line_X); - line->Y = get_word (amigamemptr + PSSO_Line_Y); - line->Length = get_word (amigamemptr + PSSO_Line_Length); - line->dX = get_word (amigamemptr + PSSO_Line_dX); - line->dY = get_word (amigamemptr + PSSO_Line_dY); - line->lDelta = get_word (amigamemptr + PSSO_Line_lDelta); - line->sDelta = get_word (amigamemptr + PSSO_Line_sDelta); - line->twoSDminusLD = get_word (amigamemptr + PSSO_Line_twoSDminusLD); - line->LinePtrn = get_word (amigamemptr + PSSO_Line_LinePtrn); - line->PatternShift = get_word (amigamemptr + PSSO_Line_PatternShift); - line->FgPen = get_long (amigamemptr + PSSO_Line_FgPen); - line->BgPen = get_long (amigamemptr + PSSO_Line_BgPen); - line->Horizontal = get_word (amigamemptr + PSSO_Line_Horizontal); - line->DrawMode = get_byte (amigamemptr + PSSO_Line_DrawMode); - line->Xorigin = get_word (amigamemptr + PSSO_Line_Xorigin); - line->Yorigin = get_word (amigamemptr + PSSO_Line_Yorigin); - return 1; - } - write_log (L"ERROR - Invalid Line structure...\n"); - return 0; + if (valid_address(amigamemptr, sizeof(struct Line))) { + line->X = get_word (amigamemptr + PSSO_Line_X); + line->Y = get_word (amigamemptr + PSSO_Line_Y); + line->Length = get_word (amigamemptr + PSSO_Line_Length); + line->dX = get_word (amigamemptr + PSSO_Line_dX); + line->dY = get_word (amigamemptr + PSSO_Line_dY); + line->lDelta = get_word (amigamemptr + PSSO_Line_lDelta); + line->sDelta = get_word (amigamemptr + PSSO_Line_sDelta); + line->twoSDminusLD = get_word (amigamemptr + PSSO_Line_twoSDminusLD); + line->LinePtrn = get_word (amigamemptr + PSSO_Line_LinePtrn); + line->PatternShift = get_word (amigamemptr + PSSO_Line_PatternShift); + line->FgPen = get_long (amigamemptr + PSSO_Line_FgPen); + line->BgPen = get_long (amigamemptr + PSSO_Line_BgPen); + line->Horizontal = get_word (amigamemptr + PSSO_Line_Horizontal); + line->DrawMode = get_byte (amigamemptr + PSSO_Line_DrawMode); + line->Xorigin = get_word (amigamemptr + PSSO_Line_Xorigin); + line->Yorigin = get_word (amigamemptr + PSSO_Line_Yorigin); + return 1; + } + write_log (L"ERROR - Invalid Line structure...\n"); + return 0; } /* list is Amiga address of list, in correct endian format for UAE * node is Amiga address of node, in correct endian format for UAE */ static void AmigaListAddTail (uaecptr l, uaecptr n) { - put_long (n + 0, l + 4); // n->ln_Succ = (struct Node *)&l->lh_Tail; - put_long (n + 4, get_long (l + 8)); // n->ln_Pred = l->lh_TailPred; - put_long (get_long (l + 8) + 0, n); // l->lh_TailPred->ln_Succ = n; - put_long (l + 8, n); // l->lh_TailPred = n; + put_long (n + 0, l + 4); // n->ln_Succ = (struct Node *)&l->lh_Tail; + put_long (n + 4, get_long (l + 8)); // n->ln_Pred = l->lh_TailPred; + put_long (get_long (l + 8) + 0, n); // l->lh_TailPred->ln_Succ = n; + put_long (l + 8, n); // l->lh_TailPred = n; } static int renderinfo_is_current_screen (struct RenderInfo *ri) { - if (! picasso_on) - return 0; - if (ri->Memory != gfxmemory + (picasso96_state.Address - gfxmem_start)) - return 0; - return 1; + if (! picasso_on) + return 0; + if (ri->Memory != gfxmemory + (picasso96_state.Address - gfxmem_start)) + return 0; + return 1; } /* * Fill a rectangle in the screen. */ static void do_fillrect_frame_buffer (struct RenderInfo *ri, int X, int Y, - int Width, int Height, uae_u32 Pen, int Bpp) + int Width, int Height, uae_u32 Pen, int Bpp) { - int cols; - uae_u8 *dst; - int lines; - int bpr = ri->BytesPerRow; - - dst = ri->Memory + X * Bpp + Y * ri->BytesPerRow; - endianswap (&Pen, Bpp); - switch (Bpp) - { + int cols; + uae_u8 *dst; + int lines; + int bpr = ri->BytesPerRow; + + dst = ri->Memory + X * Bpp + Y * ri->BytesPerRow; + endianswap (&Pen, Bpp); + switch (Bpp) + { case 1: - for (lines = 0; lines < Height; lines++, dst += bpr) { - memset (dst, Pen, Width); - } - break; + for (lines = 0; lines < Height; lines++, dst += bpr) { + memset (dst, Pen, Width); + } + break; case 2: - Pen |= Pen << 16; - for (lines = 0; lines < Height; lines++, dst += bpr) { - uae_u32 *p = (uae_u32*)dst; - for (cols = 0; cols < Width / 2; cols++) - *p++ = Pen; - if (Width & 1) - ((uae_u16*)p)[0] = Pen; - } - break; + Pen |= Pen << 16; + for (lines = 0; lines < Height; lines++, dst += bpr) { + uae_u32 *p = (uae_u32*)dst; + for (cols = 0; cols < Width / 2; cols++) + *p++ = Pen; + if (Width & 1) + ((uae_u16*)p)[0] = Pen; + } + break; case 3: - for (lines = 0; lines < Height; lines++, dst += bpr) { - uae_u8 *p = (uae_u8*)dst; - for (cols = 0; cols < Width; cols++) { - *p++ = Pen >> 0; - *p++ = Pen >> 8; - *p++ = Pen >> 16; + for (lines = 0; lines < Height; lines++, dst += bpr) { + uae_u8 *p = (uae_u8*)dst; + for (cols = 0; cols < Width; cols++) { + *p++ = Pen >> 0; + *p++ = Pen >> 8; + *p++ = Pen >> 16; + } } - } - break; + break; case 4: - for (lines = 0; lines < Height; lines++, dst += bpr) { - uae_u32 *p = (uae_u32*)dst; - for (cols = 0; cols < Width; cols++) - *p++ = Pen; - } - break; - } + for (lines = 0; lines < Height; lines++, dst += bpr) { + uae_u32 *p = (uae_u32*)dst; + for (cols = 0; cols < Width; cols++) + *p++ = Pen; + } + break; + } } static void disablemouse (void) { - cursorok = FALSE; - cursordeactivate = 0; + cursorok = FALSE; + cursordeactivate = 0; } static int remcursor_x, remcursor_y, remcursor_w, remcursor_h; @@ -592,153 +592,153 @@ static int newcursor_x, newcursor_y; static int oldcursor_x, oldcursor_y; static void mouseupdate (void) { - int fx1, fy1, fx2, fy2; - int x = newcursor_x; - int y = newcursor_y; - int forced = 0; - - if (cursordeactivate > 0) { - cursordeactivate--; - if (cursordeactivate == 0) { - disablemouse (); - cursorvisible = 0; - oldcursor_x = -10000; + int fx1, fy1, fx2, fy2; + int x = newcursor_x; + int y = newcursor_y; + int forced = 0; + + if (cursordeactivate > 0) { + cursordeactivate--; + if (cursordeactivate == 0) { + disablemouse (); + cursorvisible = 0; + oldcursor_x = -10000; + } + x = oldcursor_x; + y = oldcursor_y; + forced = 1; } - x = oldcursor_x; - y = oldcursor_y; - forced = 1; - } - if (oldcursor_x == x && oldcursor_y == y && !forced) - return; - oldcursor_x = x; - oldcursor_y = y; - - if (x <= -cursorwidth) - x = -cursorwidth; - if (y <= -cursorheight) - y = -cursorheight; - if (x >= picasso96_state.Width) - x = picasso96_state.Width; - if (y >= picasso96_state.Height) - y = picasso96_state.Height; - - fx1 = remcursor_x; - fy1 = remcursor_y; - fx2 = fx1 + remcursor_w; - fy2 = fy1 + remcursor_h; - - remcursor_x = x; - remcursor_y = y; - remcursor_w = cursorwidth; - remcursor_h = cursorheight; - - if (fx2 == fx1 || fy1 == fy2) - return; - - if (x < fx1) - fx1 = x; - if (y < fy1) - fy1 = y; - if (x + cursorwidth > fx2) - fx2 = x + cursorwidth; - if (y + cursorheight > fy2) - fy2 = y + cursorheight; - - if (fx1 < 0) - fx1 = 0; - if (fy1 < 0) - fy1 = 0; - if (fx1 >= picasso96_state.Width) - fx1 = picasso96_state.Width - 1; - if (fy1 >= picasso96_state.Height) - fy1 = picasso96_state.Height - 1; - fx2 -= fx1; - fy2 -= fy1; - if (fx1 + fx2 >= picasso96_state.Width) - fx2 = picasso96_state.Width - fx1; - if (fy1 + fy2 >= picasso96_state.Height) - fy2 = picasso96_state.Height - fy1; - DX_Invalidate (fx1, fy1, fx2, fy2); - gfx_unlock_picasso (); + if (oldcursor_x == x && oldcursor_y == y && !forced) + return; + oldcursor_x = x; + oldcursor_y = y; + + if (x <= -cursorwidth) + x = -cursorwidth; + if (y <= -cursorheight) + y = -cursorheight; + if (x >= picasso96_state.Width) + x = picasso96_state.Width; + if (y >= picasso96_state.Height) + y = picasso96_state.Height; + + fx1 = remcursor_x; + fy1 = remcursor_y; + fx2 = fx1 + remcursor_w; + fy2 = fy1 + remcursor_h; + + remcursor_x = x; + remcursor_y = y; + remcursor_w = cursorwidth; + remcursor_h = cursorheight; + + if (fx2 == fx1 || fy1 == fy2) + return; + + if (x < fx1) + fx1 = x; + if (y < fy1) + fy1 = y; + if (x + cursorwidth > fx2) + fx2 = x + cursorwidth; + if (y + cursorheight > fy2) + fy2 = y + cursorheight; + + if (fx1 < 0) + fx1 = 0; + if (fy1 < 0) + fy1 = 0; + if (fx1 >= picasso96_state.Width) + fx1 = picasso96_state.Width - 1; + if (fy1 >= picasso96_state.Height) + fy1 = picasso96_state.Height - 1; + fx2 -= fx1; + fy2 -= fy1; + if (fx1 + fx2 >= picasso96_state.Width) + fx2 = picasso96_state.Width - fx1; + if (fy1 + fy2 >= picasso96_state.Height) + fy2 = picasso96_state.Height - fy1; + DX_Invalidate (fx1, fy1, fx2, fy2); + gfx_unlock_picasso (); } static int framecnt; int p96skipmode = -1; static int doskip (void) { - if (framecnt >= currprefs.gfx_framerate) - framecnt = 0; - return framecnt > 0; + if (framecnt >= currprefs.gfx_framerate) + framecnt = 0; + return framecnt > 0; } static void picasso_trigger_vblank (void) { - if (!boardinfo || !uaegfx_base || !interrupt_enabled || currprefs.win32_rtgvblankrate < -1) { - return; - } - put_long (uaegfx_base + CARD_IRQPTR, boardinfo + PSSO_BoardInfo_SoftInterrupt); - put_byte (uaegfx_base + CARD_IRQFLAG, 1); - if (currprefs.win32_rtgvblankrate != 0) - INTREQ (0x8000 | 0x0008); + if (!boardinfo || !uaegfx_base || !interrupt_enabled || currprefs.win32_rtgvblankrate < -1) { + return; + } + put_long (uaegfx_base + CARD_IRQPTR, boardinfo + PSSO_BoardInfo_SoftInterrupt); + put_byte (uaegfx_base + CARD_IRQFLAG, 1); + if (currprefs.win32_rtgvblankrate != 0) + INTREQ (0x8000 | 0x0008); } static int isvsync (void) { - return currprefs.gfx_pfullscreen && currprefs.gfx_pvsync; + return currprefs.gfx_pfullscreen && currprefs.gfx_pvsync; } static void flushpixels_do (void) { - if (multithreaded) - uae_sem_post (&sem); - else - flushpixels (); + if (multithreaded) + uae_sem_post (&sem); + else + flushpixels (); } void picasso_handle_vsync (void) { - static int vsynccnt; - int thisisvsync = 1; - + static int vsynccnt; + int thisisvsync = 1; + #ifdef RETROPLATFORM - rp_vsync (); + rp_vsync (); #endif - clipboard_vsync (); - if (!picasso_on) - createwindowscursor (0, 0, 0, 0, 0, 1); + clipboard_vsync (); + if (!picasso_on) + createwindowscursor (0, 0, 0, 0, 0, 1); - if (currprefs.chipset_refreshrate >= 100) { - vsynccnt++; - if (vsynccnt < 2) - thisisvsync = 0; - vsynccnt = 0; - } + if (currprefs.chipset_refreshrate >= 100) { + vsynccnt++; + if (vsynccnt < 2) + thisisvsync = 0; + vsynccnt = 0; + } - if (thisisvsync && currprefs.win32_rtgvblankrate == 0 && !isvsync ()) - picasso_trigger_vblank (); + if (thisisvsync && currprefs.win32_rtgvblankrate == 0 && !isvsync ()) + picasso_trigger_vblank (); - if (!picasso_on) - return; - if (dx_islost ()) - return; + if (!picasso_on) + return; + if (dx_islost ()) + return; - framecnt++; - if (!multithreaded) - mouseupdate (); + framecnt++; + if (!multithreaded) + mouseupdate (); - if (thisisvsync) { - if (multithreaded) { - uae_sem_post (&sem); - } else { - if (doskip () && p96skipmode == 0) { - ; - } else { - flushpixels_do (); - } - gfx_unlock_picasso (); + if (thisisvsync) { + if (multithreaded) { + uae_sem_post (&sem); + } else { + if (doskip () && p96skipmode == 0) { + ; + } else { + flushpixels_do (); + } + gfx_unlock_picasso (); + } } - } } static int set_panning_called = 0; @@ -746,159 +746,159 @@ static int set_panning_called = 0; typedef enum { - /* DEST = RGBFB_B8G8R8A8,32 */ - RGBFB_A8R8G8B8_32 = 1, - RGBFB_A8B8G8R8_32, - RGBFB_R8G8B8A8_32, - RGBFB_B8G8R8A8_32, - RGBFB_R8G8B8_32, - RGBFB_B8G8R8_32, - RGBFB_R5G6B5PC_32, - RGBFB_R5G5B5PC_32, - RGBFB_R5G6B5_32, - RGBFB_R5G5B5_32, - RGBFB_B5G6R5PC_32, - RGBFB_B5G5R5PC_32, - RGBFB_CLUT_RGBFB_32, - - /* DEST = RGBFB_R5G6B5PC,16 */ - RGBFB_A8R8G8B8_16, - RGBFB_A8B8G8R8_16, - RGBFB_R8G8B8A8_16, - RGBFB_B8G8R8A8_16, - RGBFB_R8G8B8_16, - RGBFB_B8G8R8_16, - RGBFB_R5G6B5PC_16, - RGBFB_R5G5B5PC_16, - RGBFB_R5G6B5_16, - RGBFB_R5G5B5_16, - RGBFB_B5G6R5PC_16, - RGBFB_B5G5R5PC_16, - RGBFB_CLUT_RGBFB_16, - - /* DEST = RGBFB_CLUT,8 */ - RGBFB_CLUT_8 + /* DEST = RGBFB_B8G8R8A8,32 */ + RGBFB_A8R8G8B8_32 = 1, + RGBFB_A8B8G8R8_32, + RGBFB_R8G8B8A8_32, + RGBFB_B8G8R8A8_32, + RGBFB_R8G8B8_32, + RGBFB_B8G8R8_32, + RGBFB_R5G6B5PC_32, + RGBFB_R5G5B5PC_32, + RGBFB_R5G6B5_32, + RGBFB_R5G5B5_32, + RGBFB_B5G6R5PC_32, + RGBFB_B5G5R5PC_32, + RGBFB_CLUT_RGBFB_32, + + /* DEST = RGBFB_R5G6B5PC,16 */ + RGBFB_A8R8G8B8_16, + RGBFB_A8B8G8R8_16, + RGBFB_R8G8B8A8_16, + RGBFB_B8G8R8A8_16, + RGBFB_R8G8B8_16, + RGBFB_B8G8R8_16, + RGBFB_R5G6B5PC_16, + RGBFB_R5G5B5PC_16, + RGBFB_R5G6B5_16, + RGBFB_R5G5B5_16, + RGBFB_B5G6R5PC_16, + RGBFB_B5G5R5PC_16, + RGBFB_CLUT_RGBFB_16, + + /* DEST = RGBFB_CLUT,8 */ + RGBFB_CLUT_8 }; static uae_u32 setspriteimage (uaecptr bi); static void recursor (void) { - restoresurface (dxdata.cursorsurface1); - restoresurface (dxdata.cursorsurface2); - clearsurface (dxdata.cursorsurface1); - clearsurface (dxdata.cursorsurface2); - reloadcursor = 1; - cursorok = FALSE; - setspriteimage (boardinfo); + restoresurface (dxdata.cursorsurface1); + restoresurface (dxdata.cursorsurface2); + clearsurface (dxdata.cursorsurface1); + clearsurface (dxdata.cursorsurface2); + reloadcursor = 1; + cursorok = FALSE; + setspriteimage (boardinfo); } static void setconvert (void) { - static int ohost_mode, orgbformat; - int d = picasso_vidinfo.pixbytes; - int v; + static int ohost_mode, orgbformat; + int d = picasso_vidinfo.pixbytes; + int v; - v = 0; - switch (picasso96_state.RGBFormat) - { + v = 0; + switch (picasso96_state.RGBFormat) + { case RGBFB_CLUT: - if (d == 1) - v = RGBFB_CLUT_8; - else if (d == 2) - v = RGBFB_CLUT_RGBFB_16; - else if (d == 4) - v = RGBFB_CLUT_RGBFB_32; - break; + if (d == 1) + v = RGBFB_CLUT_8; + else if (d == 2) + v = RGBFB_CLUT_RGBFB_16; + else if (d == 4) + v = RGBFB_CLUT_RGBFB_32; + break; case RGBFB_B5G6R5PC: - if (d == 2) - v = RGBFB_B5G6R5PC_16; - else if (d == 4) - v = RGBFB_B5G6R5PC_32; - break; + if (d == 2) + v = RGBFB_B5G6R5PC_16; + else if (d == 4) + v = RGBFB_B5G6R5PC_32; + break; case RGBFB_R5G6B5PC: - if (d == 2) - v = RGBFB_R5G6B5PC_16; - else if (d == 4) - v = RGBFB_R5G6B5PC_32; - break; + if (d == 2) + v = RGBFB_R5G6B5PC_16; + else if (d == 4) + v = RGBFB_R5G6B5PC_32; + break; case RGBFB_R5G5B5PC: - if (d == 4) - v = RGBFB_R5G5B5PC_32; - else if (d == 2) - v = RGBFB_R5G5B5PC_16; - break; + if (d == 4) + v = RGBFB_R5G5B5PC_32; + else if (d == 2) + v = RGBFB_R5G5B5PC_16; + break; case RGBFB_R5G6B5: - if (d == 4) - v = RGBFB_R5G6B5_32; - else - v = RGBFB_R5G6B5_16; - break; + if (d == 4) + v = RGBFB_R5G6B5_32; + else + v = RGBFB_R5G6B5_16; + break; case RGBFB_R5G5B5: - if (d == 4) - v = RGBFB_R5G5B5_32; - else - v = RGBFB_R5G5B5_16; - break; + if (d == 4) + v = RGBFB_R5G5B5_32; + else + v = RGBFB_R5G5B5_16; + break; case RGBFB_B5G5R5PC: - if (d == 4) - v = RGBFB_B5G5R5PC_32; - else - v = RGBFB_B5G5R5PC_16; - break; + if (d == 4) + v = RGBFB_B5G5R5PC_32; + else + v = RGBFB_B5G5R5PC_16; + break; case RGBFB_A8R8G8B8: - if (d == 2) - v = RGBFB_A8R8G8B8_16; - else if (d == 4) - v = RGBFB_A8R8G8B8_32; - break; + if (d == 2) + v = RGBFB_A8R8G8B8_16; + else if (d == 4) + v = RGBFB_A8R8G8B8_32; + break; case RGBFB_R8G8B8: - if (d == 2) - v = RGBFB_R8G8B8_16; - else if (d == 4) - v = RGBFB_R8G8B8_32; - break; + if (d == 2) + v = RGBFB_R8G8B8_16; + else if (d == 4) + v = RGBFB_R8G8B8_32; + break; case RGBFB_B8G8R8: - if (d == 2) - v = RGBFB_B8G8R8_16; - else if (d == 4) - v = RGBFB_B8G8R8_32; - break; + if (d == 2) + v = RGBFB_B8G8R8_16; + else if (d == 4) + v = RGBFB_B8G8R8_32; + break; case RGBFB_A8B8G8R8: - if (d == 2) - v = RGBFB_A8B8G8R8_16; - else if (d == 4) - v = RGBFB_A8B8G8R8_32; - break; + if (d == 2) + v = RGBFB_A8B8G8R8_16; + else if (d == 4) + v = RGBFB_A8B8G8R8_32; + break; case RGBFB_B8G8R8A8: - if (d == 2) - v = RGBFB_B8G8R8A8_16; - else if (d == 4) - v = RGBFB_B8G8R8A8_32; - break; + if (d == 2) + v = RGBFB_B8G8R8A8_16; + else if (d == 4) + v = RGBFB_B8G8R8A8_32; + break; case RGBFB_R8G8B8A8: - if (d == 2) - v = RGBFB_R8G8B8A8_16; - else if (d == 4) - v = RGBFB_R8G8B8A8_32; - break; - } - picasso_convert = v; - host_mode = DirectDraw_GetSurfacePixelFormat (NULL); - gfx_set_picasso_colors (picasso96_state.RGBFormat); - if (d == 4) - alloc_colors_rgb (8, 8, 8, 16, 8, 0, 0, 0, 0, 0, p96rc, p96gc, p96bc); - else - alloc_colors_rgb (5, 6, 5, 11, 5, 0, 0, 0, 0, 0, p96rc, p96gc, p96bc); - if (host_mode != ohost_mode || picasso96_state.RGBFormat != orgbformat) { - write_log (L"RTG conversion: Depth=%d HostRGBF=%d P96RGBF=%d Mode=%d\n", d, host_mode, picasso96_state.RGBFormat, v); - ohost_mode = host_mode; - orgbformat = picasso96_state.RGBFormat; - } - recursor (); - full_refresh = 1; + if (d == 2) + v = RGBFB_R8G8B8A8_16; + else if (d == 4) + v = RGBFB_R8G8B8A8_32; + break; + } + picasso_convert = v; + host_mode = DirectDraw_GetSurfacePixelFormat (NULL); + gfx_set_picasso_colors (picasso96_state.RGBFormat); + if (d == 4) + alloc_colors_rgb (8, 8, 8, 16, 8, 0, 0, 0, 0, 0, p96rc, p96gc, p96bc); + else + alloc_colors_rgb (5, 6, 5, 11, 5, 0, 0, 0, 0, 0, p96rc, p96gc, p96bc); + if (host_mode != ohost_mode || picasso96_state.RGBFormat != orgbformat) { + write_log (L"RTG conversion: Depth=%d HostRGBF=%d P96RGBF=%d Mode=%d\n", d, host_mode, picasso96_state.RGBFormat, v); + ohost_mode = host_mode; + orgbformat = picasso96_state.RGBFormat; + } + recursor (); + full_refresh = 1; } /* Clear our screen, since we've got a new Picasso screen-mode, and refresh with the proper contents @@ -910,61 +910,61 @@ static void setconvert (void) extern uae_u16 new_beamcon0; void picasso_refresh (void) { - struct RenderInfo ri; - static int beamcon0_before, p96refresh_was; - - if (! picasso_on) - return; - { //for higher P96 mousedraw rate - /* HACK */ - extern uae_u16 vtotal; - if (p96hack_vpos2) { - vtotal = p96hack_vpos2; - beamcon0_before = new_beamcon0; - new_beamcon0 |= 0x80; - p96refresh_active = 1; - p96refresh_was = 1; - } else { - if (p96refresh_was) { - new_beamcon0 = beamcon0_before; - p96refresh_was = 0; - } - new_beamcon0 |= 0x20; - } + struct RenderInfo ri; + static int beamcon0_before, p96refresh_was; + + if (! picasso_on) + return; + { //for higher P96 mousedraw rate + /* HACK */ + extern uae_u16 vtotal; + if (p96hack_vpos2) { + vtotal = p96hack_vpos2; + beamcon0_before = new_beamcon0; + new_beamcon0 |= 0x80; + p96refresh_active = 1; + p96refresh_was = 1; + } else { + if (p96refresh_was) { + new_beamcon0 = beamcon0_before; + p96refresh_was = 0; + } + new_beamcon0 |= 0x20; + } /* HACK until ntsc timing is fixed.. */ - } //end for higher P96 mousedraw rate - full_refresh = 1; - setconvert (); - - /* Make sure that the first time we show a Picasso video mode, we don't blit any crap. - * We can do this by checking if we have an Address yet. - */ - if (picasso96_state.Address) { - unsigned int width, height; - - /* blit the stuff from our static frame-buffer to the gfx-card */ - ri.Memory = gfxmemory + (picasso96_state.Address - gfxmem_start); - ri.BytesPerRow = picasso96_state.BytesPerRow; - ri.RGBFormat = picasso96_state.RGBFormat; - - if (set_panning_called) { - width = (picasso96_state.VirtualWidth < picasso96_state.Width) ? - picasso96_state.VirtualWidth : picasso96_state.Width; - height = (picasso96_state.VirtualHeight < picasso96_state.Height) ? - picasso96_state.VirtualHeight : picasso96_state.Height; - // 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); - } + } //end for higher P96 mousedraw rate + full_refresh = 1; + setconvert (); + + /* Make sure that the first time we show a Picasso video mode, we don't blit any crap. + * We can do this by checking if we have an Address yet. + */ + if (picasso96_state.Address) { + unsigned int width, height; + + /* blit the stuff from our static frame-buffer to the gfx-card */ + ri.Memory = gfxmemory + (picasso96_state.Address - gfxmem_start); + ri.BytesPerRow = picasso96_state.BytesPerRow; + ri.RGBFormat = picasso96_state.RGBFormat; + + if (set_panning_called) { + width = (picasso96_state.VirtualWidth < picasso96_state.Width) ? + picasso96_state.VirtualWidth : picasso96_state.Width; + height = (picasso96_state.VirtualHeight < picasso96_state.Height) ? + picasso96_state.VirtualHeight : picasso96_state.Height; + // 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); + } + } else { + width = picasso96_state.Width; + height = picasso96_state.Height; + } + flushpixels_do (); } else { - width = picasso96_state.Width; - height = picasso96_state.Height; + write_log (L"ERROR - picasso_refresh() can't refresh!\n"); } - flushpixels_do (); - } else { - write_log (L"ERROR - picasso_refresh() can't refresh!\n"); - } } #define BLT_SIZE 4 @@ -1177,133 +1177,133 @@ void picasso_refresh (void) * Functions to perform an action on the frame-buffer */ static int do_blitrect_frame_buffer (struct RenderInfo *ri, struct - RenderInfo *dstri, unsigned long srcx, unsigned long srcy, - unsigned long dstx, unsigned long dsty, unsigned long width, unsigned - long height, uae_u8 mask, BLIT_OPCODE opcode) + RenderInfo *dstri, unsigned long srcx, unsigned long srcy, + unsigned long dstx, unsigned long dsty, unsigned long width, unsigned + long height, uae_u8 mask, BLIT_OPCODE opcode) { - uae_u8 *src, *dst; - uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat); - unsigned long total_width = width * Bpp; - - src = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow; - dst = dstri->Memory + dstx * Bpp + dsty * dstri->BytesPerRow; - if (mask != 0xFF && Bpp > 1) { - write_log (L"WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp); - } - - P96TRACE ((L"(%dx%d)=(%dx%d)=(%dx%d)=%d\n", srcx, srcy, dstx, dsty, width, height, opcode)); - if (mask == 0xFF || Bpp > 1) { - - if(opcode == BLIT_SRC) { - /* handle normal case efficiently */ - if (ri->Memory == dstri->Memory && dsty == srcy) { - unsigned long i; - for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow) - memmove (dst, src, total_width); - } else if (dsty < srcy) { - unsigned long i; - for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow) - memcpy (dst, src, total_width); - } else { - unsigned long i; - src += (height - 1) * ri->BytesPerRow; - dst += (height - 1) * dstri->BytesPerRow; - for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow) - memcpy (dst, src, total_width); - } - return 1; - - } else if (Bpp == 4) { - - /* 32-bit optimized */ - switch (opcode) - { - case BLIT_FALSE: BLIT_FALSE_32 (PARMS); break; - case BLIT_NOR: BLIT_NOR_32 (PARMS); break; - case BLIT_ONLYDST: BLIT_ONLYDST_32 (PARMS); break; - case BLIT_NOTSRC: BLIT_NOTSRC_32 (PARMS); break; - case BLIT_ONLYSRC: BLIT_ONLYSRC_32 (PARMS); break; - case BLIT_NOTDST: BLIT_NOTDST_32 (PARMS); break; - case BLIT_EOR: BLIT_EOR_32 (PARMS); break; - case BLIT_NAND: BLIT_NAND_32 (PARMS); break; - case BLIT_AND: BLIT_AND_32 (PARMS); break; - case BLIT_NEOR: BLIT_NEOR_32 (PARMS); break; - case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_32 (PARMS); break; - case BLIT_NOTONLYDST: BLIT_NOTONLYDST_32 (PARMS); break; - case BLIT_OR: BLIT_OR_32 (PARMS); break; - case BLIT_TRUE: BLIT_TRUE_32 (PARMS); break; - case 30: BLIT_30_32 (PARMS); break; - } - } else if (Bpp == 3) { - - /* 24-bit (not very) optimized */ - switch (opcode) - { - case BLIT_FALSE: BLIT_FALSE_24 (PARMS); break; - case BLIT_NOR: BLIT_NOR_24 (PARMS); break; - case BLIT_ONLYDST: BLIT_ONLYDST_24 (PARMS); break; - case BLIT_NOTSRC: BLIT_NOTSRC_24 (PARMS); break; - case BLIT_ONLYSRC: BLIT_ONLYSRC_24 (PARMS); break; - case BLIT_NOTDST: BLIT_NOTDST_24 (PARMS); break; - case BLIT_EOR: BLIT_EOR_24 (PARMS); break; - case BLIT_NAND: BLIT_NAND_24 (PARMS); break; - case BLIT_AND: BLIT_AND_24 (PARMS); break; - case BLIT_NEOR: BLIT_NEOR_24 (PARMS); break; - case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_24 (PARMS); break; - case BLIT_NOTONLYDST: BLIT_NOTONLYDST_24 (PARMS); break; - case BLIT_OR: BLIT_OR_24 (PARMS); break; - case BLIT_TRUE: BLIT_TRUE_24 (PARMS); break; - case 30: BLIT_30_24 (PARMS); break; - } - - } else if (Bpp == 2) { - - /* 16-bit optimized */ - switch (opcode) - { - case BLIT_FALSE: BLIT_FALSE_16 (PARMS); break; - case BLIT_NOR: BLIT_NOR_16 (PARMS); break; - case BLIT_ONLYDST: BLIT_ONLYDST_16 (PARMS); break; - case BLIT_NOTSRC: BLIT_NOTSRC_16 (PARMS); break; - case BLIT_ONLYSRC: BLIT_ONLYSRC_16 (PARMS); break; - case BLIT_NOTDST: BLIT_NOTDST_16 (PARMS); break; - case BLIT_EOR: BLIT_EOR_16 (PARMS); break; - case BLIT_NAND: BLIT_NAND_16 (PARMS); break; - case BLIT_AND: BLIT_AND_16 (PARMS); break; - case BLIT_NEOR: BLIT_NEOR_16 (PARMS); break; - case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_16 (PARMS); break; - case BLIT_NOTONLYDST: BLIT_NOTONLYDST_16 (PARMS); break; - case BLIT_OR: BLIT_OR_16 (PARMS); break; - case BLIT_TRUE: BLIT_TRUE_16 (PARMS); break; - case 30: BLIT_30_16 (PARMS); break; - } - - } else if (Bpp == 1) { - - /* 8-bit optimized */ - switch (opcode) - { - case BLIT_FALSE: BLIT_FALSE_8 (PARMS); break; - case BLIT_NOR: BLIT_NOR_8 (PARMS); break; - case BLIT_ONLYDST: BLIT_ONLYDST_8 (PARMS); break; - case BLIT_NOTSRC: BLIT_NOTSRC_8 (PARMS); break; - case BLIT_ONLYSRC: BLIT_ONLYSRC_8 (PARMS); break; - case BLIT_NOTDST: BLIT_NOTDST_8 (PARMS); break; - case BLIT_EOR: BLIT_EOR_8 (PARMS); break; - case BLIT_NAND: BLIT_NAND_8 (PARMS); break; - case BLIT_AND: BLIT_AND_8 (PARMS); break; - case BLIT_NEOR: BLIT_NEOR_8 (PARMS); break; - case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_8 (PARMS); break; - case BLIT_NOTONLYDST: BLIT_NOTONLYDST_8 (PARMS); break; - case BLIT_OR: BLIT_OR_8 (PARMS); break; - case BLIT_TRUE: BLIT_TRUE_8 (PARMS); break; - case 30: BLIT_30_8 (PARMS); break; - } + uae_u8 *src, *dst; + uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat); + unsigned long total_width = width * Bpp; + + src = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow; + dst = dstri->Memory + dstx * Bpp + dsty * dstri->BytesPerRow; + if (mask != 0xFF && Bpp > 1) { + write_log (L"WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp); + } + P96TRACE ((L"(%dx%d)=(%dx%d)=(%dx%d)=%d\n", srcx, srcy, dstx, dsty, width, height, opcode)); + if (mask == 0xFF || Bpp > 1) { + + if(opcode == BLIT_SRC) { + /* handle normal case efficiently */ + if (ri->Memory == dstri->Memory && dsty == srcy) { + unsigned long i; + for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow) + memmove (dst, src, total_width); + } else if (dsty < srcy) { + unsigned long i; + for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow) + memcpy (dst, src, total_width); + } else { + unsigned long i; + src += (height - 1) * ri->BytesPerRow; + dst += (height - 1) * dstri->BytesPerRow; + for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow) + memcpy (dst, src, total_width); + } + return 1; + + } else if (Bpp == 4) { + + /* 32-bit optimized */ + switch (opcode) + { + case BLIT_FALSE: BLIT_FALSE_32 (PARMS); break; + case BLIT_NOR: BLIT_NOR_32 (PARMS); break; + case BLIT_ONLYDST: BLIT_ONLYDST_32 (PARMS); break; + case BLIT_NOTSRC: BLIT_NOTSRC_32 (PARMS); break; + case BLIT_ONLYSRC: BLIT_ONLYSRC_32 (PARMS); break; + case BLIT_NOTDST: BLIT_NOTDST_32 (PARMS); break; + case BLIT_EOR: BLIT_EOR_32 (PARMS); break; + case BLIT_NAND: BLIT_NAND_32 (PARMS); break; + case BLIT_AND: BLIT_AND_32 (PARMS); break; + case BLIT_NEOR: BLIT_NEOR_32 (PARMS); break; + case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_32 (PARMS); break; + case BLIT_NOTONLYDST: BLIT_NOTONLYDST_32 (PARMS); break; + case BLIT_OR: BLIT_OR_32 (PARMS); break; + case BLIT_TRUE: BLIT_TRUE_32 (PARMS); break; + case 30: BLIT_30_32 (PARMS); break; + } + } else if (Bpp == 3) { + + /* 24-bit (not very) optimized */ + switch (opcode) + { + case BLIT_FALSE: BLIT_FALSE_24 (PARMS); break; + case BLIT_NOR: BLIT_NOR_24 (PARMS); break; + case BLIT_ONLYDST: BLIT_ONLYDST_24 (PARMS); break; + case BLIT_NOTSRC: BLIT_NOTSRC_24 (PARMS); break; + case BLIT_ONLYSRC: BLIT_ONLYSRC_24 (PARMS); break; + case BLIT_NOTDST: BLIT_NOTDST_24 (PARMS); break; + case BLIT_EOR: BLIT_EOR_24 (PARMS); break; + case BLIT_NAND: BLIT_NAND_24 (PARMS); break; + case BLIT_AND: BLIT_AND_24 (PARMS); break; + case BLIT_NEOR: BLIT_NEOR_24 (PARMS); break; + case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_24 (PARMS); break; + case BLIT_NOTONLYDST: BLIT_NOTONLYDST_24 (PARMS); break; + case BLIT_OR: BLIT_OR_24 (PARMS); break; + case BLIT_TRUE: BLIT_TRUE_24 (PARMS); break; + case 30: BLIT_30_24 (PARMS); break; + } + + } else if (Bpp == 2) { + + /* 16-bit optimized */ + switch (opcode) + { + case BLIT_FALSE: BLIT_FALSE_16 (PARMS); break; + case BLIT_NOR: BLIT_NOR_16 (PARMS); break; + case BLIT_ONLYDST: BLIT_ONLYDST_16 (PARMS); break; + case BLIT_NOTSRC: BLIT_NOTSRC_16 (PARMS); break; + case BLIT_ONLYSRC: BLIT_ONLYSRC_16 (PARMS); break; + case BLIT_NOTDST: BLIT_NOTDST_16 (PARMS); break; + case BLIT_EOR: BLIT_EOR_16 (PARMS); break; + case BLIT_NAND: BLIT_NAND_16 (PARMS); break; + case BLIT_AND: BLIT_AND_16 (PARMS); break; + case BLIT_NEOR: BLIT_NEOR_16 (PARMS); break; + case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_16 (PARMS); break; + case BLIT_NOTONLYDST: BLIT_NOTONLYDST_16 (PARMS); break; + case BLIT_OR: BLIT_OR_16 (PARMS); break; + case BLIT_TRUE: BLIT_TRUE_16 (PARMS); break; + case 30: BLIT_30_16 (PARMS); break; + } + + } else if (Bpp == 1) { + + /* 8-bit optimized */ + switch (opcode) + { + case BLIT_FALSE: BLIT_FALSE_8 (PARMS); break; + case BLIT_NOR: BLIT_NOR_8 (PARMS); break; + case BLIT_ONLYDST: BLIT_ONLYDST_8 (PARMS); break; + case BLIT_NOTSRC: BLIT_NOTSRC_8 (PARMS); break; + case BLIT_ONLYSRC: BLIT_ONLYSRC_8 (PARMS); break; + case BLIT_NOTDST: BLIT_NOTDST_8 (PARMS); break; + case BLIT_EOR: BLIT_EOR_8 (PARMS); break; + case BLIT_NAND: BLIT_NAND_8 (PARMS); break; + case BLIT_AND: BLIT_AND_8 (PARMS); break; + case BLIT_NEOR: BLIT_NEOR_8 (PARMS); break; + case BLIT_NOTONLYSRC: BLIT_NOTONLYSRC_8 (PARMS); break; + case BLIT_NOTONLYDST: BLIT_NOTONLYDST_8 (PARMS); break; + case BLIT_OR: BLIT_OR_8 (PARMS); break; + case BLIT_TRUE: BLIT_TRUE_8 (PARMS); break; + case 30: BLIT_30_8 (PARMS); break; + } + + } + return 1; } - return 1; - } - return 0; + return 0; } /* @@ -1315,13 +1315,13 @@ d7: RGBFTYPE RGBFormat */ static uae_u32 REGPARAM2 picasso_SetSpritePosition (TrapContext *ctx) { - uaecptr bi = m68k_areg (regs, 0); - boardinfo = bi; - newcursor_x = (uae_s16)get_word (bi + PSSO_BoardInfo_MouseX) - picasso96_state.XOffset; - newcursor_y = (uae_s16)get_word (bi + PSSO_BoardInfo_MouseY) - picasso96_state.YOffset; - if (!hwsprite) - return 0; - return 1; + uaecptr bi = m68k_areg (regs, 0); + boardinfo = bi; + newcursor_x = (uae_s16)get_word (bi + PSSO_BoardInfo_MouseX) - picasso96_state.XOffset; + newcursor_y = (uae_s16)get_word (bi + PSSO_BoardInfo_MouseY) - picasso96_state.YOffset; + if (!hwsprite) + return 0; + return 1; } @@ -1339,20 +1339,20 @@ This function changes one of the possible three colors of the hardware sprite. */ static uae_u32 REGPARAM2 picasso_SetSpriteColor (TrapContext *ctx) { - uaecptr bi = m68k_areg (regs, 0); - uae_u8 idx = m68k_dreg (regs, 0); - uae_u8 red = m68k_dreg (regs, 1); - uae_u8 green = m68k_dreg (regs, 2); - uae_u8 blue = m68k_dreg (regs, 3); - boardinfo = bi; - idx++; - if (!hwsprite) - return 0; - if (idx >= 4) - return 0; - cursorrgb[idx] = (red << 16) | (green << 8) | (blue << 0); - P96TRACE_SPR ((L"SetSpriteColor(%08x,%d:%02X%02X%02X). %x\n", bi, idx, red, green, blue, bi + PSSO_BoardInfo_MousePens)); - return 1; + uaecptr bi = m68k_areg (regs, 0); + uae_u8 idx = m68k_dreg (regs, 0); + uae_u8 red = m68k_dreg (regs, 1); + uae_u8 green = m68k_dreg (regs, 2); + uae_u8 blue = m68k_dreg (regs, 3); + boardinfo = bi; + idx++; + if (!hwsprite) + return 0; + if (idx >= 4) + return 0; + cursorrgb[idx] = (red << 16) | (green << 8) | (blue << 0); + P96TRACE_SPR ((L"SetSpriteColor(%08x,%d:%02X%02X%02X). %x\n", bi, idx, red, green, blue, bi + PSSO_BoardInfo_MousePens)); + return 1; } @@ -1360,155 +1360,155 @@ static RECT cursor_r1, cursor_r2; static int mouseput; void picasso_putcursor (int sx, int sy, int sw, int sh) { - int xdiff, ydiff, xdiff2, ydiff2; - LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; - - if (!cursorvisible || !hwsprite || !cursorok || wincursor_shown) - return; - - if (remcursor_x + remcursor_w < sx) - return; - if (remcursor_y + remcursor_h < sy) - return; - if (remcursor_x > sx + sw) - return; - if (remcursor_y > sy + sh) - return; - if (remcursor_w == 0 || remcursor_h == 0) - return; - - cursor_r1.left = remcursor_x; - cursor_r1.top = remcursor_y; - cursor_r1.right = cursor_r1.left + remcursor_w; - cursor_r1.bottom = cursor_r1.top + remcursor_h; - - xdiff = ydiff = 0; - xdiff2 = ydiff2 = 0; - if (cursor_r1.right > picasso96_state.Width) - xdiff = picasso96_state.Width - cursor_r1.right; - if (cursor_r1.bottom > picasso96_state.Height) - ydiff = picasso96_state.Height - cursor_r1.bottom; - if (xdiff <= -cursorwidth) - return; - if (ydiff <= -cursorheight) - return; - - if (cursor_r1.left < 0) { - xdiff2 = cursor_r1.left; - cursor_r1.left = 0; - } - if (cursor_r1.top < 0) { - ydiff2 = cursor_r1.top; - cursor_r1.top = 0; - } - - cursor_r1.right += xdiff; - cursor_r1.bottom += ydiff; - - cursor_r2.left = 0; - cursor_r2.top = 0; - cursor_r2.right = cursorwidth + xdiff + xdiff2; - cursor_r2.bottom = cursorheight + ydiff + ydiff2; - - if (!DirectDraw_BlitRect (dxdata.cursorsurface2, &cursor_r2, dstsurf, &cursor_r1)) { - recursor (); - return; - } + int xdiff, ydiff, xdiff2, ydiff2; + LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; - cursor_r2.left = -xdiff2; - cursor_r2.top = -ydiff2; - cursor_r2.right = cursor_r2.left + cursorwidth + xdiff + xdiff2; - cursor_r2.bottom = cursor_r2.top + cursorheight + ydiff + ydiff2; + if (!cursorvisible || !hwsprite || !cursorok || wincursor_shown) + return; - if (!DirectDraw_BlitRectCK (dstsurf, &cursor_r1, dxdata.cursorsurface1, &cursor_r2)) { - recursor (); - return; - } + if (remcursor_x + remcursor_w < sx) + return; + if (remcursor_y + remcursor_h < sy) + return; + if (remcursor_x > sx + sw) + return; + if (remcursor_y > sy + sh) + return; + if (remcursor_w == 0 || remcursor_h == 0) + return; + + cursor_r1.left = remcursor_x; + cursor_r1.top = remcursor_y; + cursor_r1.right = cursor_r1.left + remcursor_w; + cursor_r1.bottom = cursor_r1.top + remcursor_h; + + xdiff = ydiff = 0; + xdiff2 = ydiff2 = 0; + if (cursor_r1.right > picasso96_state.Width) + xdiff = picasso96_state.Width - cursor_r1.right; + if (cursor_r1.bottom > picasso96_state.Height) + ydiff = picasso96_state.Height - cursor_r1.bottom; + if (xdiff <= -cursorwidth) + return; + if (ydiff <= -cursorheight) + return; + + if (cursor_r1.left < 0) { + xdiff2 = cursor_r1.left; + cursor_r1.left = 0; + } + if (cursor_r1.top < 0) { + ydiff2 = cursor_r1.top; + cursor_r1.top = 0; + } + + cursor_r1.right += xdiff; + cursor_r1.bottom += ydiff; + + cursor_r2.left = 0; + cursor_r2.top = 0; + cursor_r2.right = cursorwidth + xdiff + xdiff2; + cursor_r2.bottom = cursorheight + ydiff + ydiff2; + + if (!DirectDraw_BlitRect (dxdata.cursorsurface2, &cursor_r2, dstsurf, &cursor_r1)) { + recursor (); + return; + } - cursor_r2.left = 0; - cursor_r2.top = 0; - cursor_r2.right = cursorwidth + xdiff + xdiff2; - cursor_r2.bottom = cursorheight + ydiff + ydiff2; + cursor_r2.left = -xdiff2; + cursor_r2.top = -ydiff2; + cursor_r2.right = cursor_r2.left + cursorwidth + xdiff + xdiff2; + cursor_r2.bottom = cursor_r2.top + cursorheight + ydiff + ydiff2; - mouseput = 1; + if (!DirectDraw_BlitRectCK (dstsurf, &cursor_r1, dxdata.cursorsurface1, &cursor_r2)) { + recursor (); + return; + } + + cursor_r2.left = 0; + cursor_r2.top = 0; + cursor_r2.right = cursorwidth + xdiff + xdiff2; + cursor_r2.bottom = cursorheight + ydiff + ydiff2; + + mouseput = 1; } void picasso_clearcursor (void) { - DWORD ddrval; - LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; - - if (!cursorok || wincursor_shown) - return; - if (!mouseput) - return; - mouseput = 0; - - ddrval = IDirectDrawSurface7_Blt (dstsurf, &cursor_r1, dxdata.cursorsurface2, &cursor_r2, DDBLT_WAIT, NULL); - if (FAILED(ddrval)) { - if (ddrval != DDERR_SURFACELOST) - write_log (L"Cursor surface clearblit failed: %s\n", DXError (ddrval)); - } + DWORD ddrval; + LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; + + if (!cursorok || wincursor_shown) + return; + if (!mouseput) + return; + mouseput = 0; + + ddrval = IDirectDrawSurface7_Blt (dstsurf, &cursor_r1, dxdata.cursorsurface2, &cursor_r2, DDBLT_WAIT, NULL); + if (FAILED(ddrval)) { + if (ddrval != DDERR_SURFACELOST) + write_log (L"Cursor surface clearblit failed: %s\n", DXError (ddrval)); + } } STATIC_INLINE uae_u16 rgb32torgb16pc (uae_u32 rgb) { - return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (0 + 3)) & 0x1f) << 0); + return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (0 + 3)) & 0x1f) << 0); } static void updatesprcolors (void) { - int i; - for (i = 1; i < 4; i++) { - uae_u32 v = cursorrgb[i]; - switch (picasso_vidinfo.pixbytes) - { - case 1: - /* use custom chip sprite palette */ - cursorrgbn[i] = i + 16; - break; - case 2: - cursorrgbn[i] = rgb32torgb16pc (v); - break; - case 4: - cursorrgbn[i] = v; - break; + int i; + for (i = 1; i < 4; i++) { + uae_u32 v = cursorrgb[i]; + switch (picasso_vidinfo.pixbytes) + { + case 1: + /* use custom chip sprite palette */ + cursorrgbn[i] = i + 16; + break; + case 2: + cursorrgbn[i] = rgb32torgb16pc (v); + break; + case 4: + cursorrgbn[i] = v; + break; + } } - } } static void putmousepixel (uae_u8 *d, int bpp, int idx) { - uae_u32 val; - - if (idx == 0) - val = dxdata.colorkey; - else - val = cursorrgbn[idx]; - - switch (bpp) - { + uae_u32 val; + + if (idx == 0) + val = dxdata.colorkey; + else + val = cursorrgbn[idx]; + + switch (bpp) + { case 1: - ((uae_u8*)d)[0] = (uae_u8)val; - break; + ((uae_u8*)d)[0] = (uae_u8)val; + break; case 2: - ((uae_u16*)d)[0] = (uae_u16)val; - break; + ((uae_u16*)d)[0] = (uae_u16)val; + break; case 4: - ((uae_u32*)d)[0] = (uae_u32)val; - break; - } + ((uae_u32*)d)[0] = (uae_u32)val; + break; + } } static void putwinmousepixel (HDC andDC, HDC xorDC, int x, int y, int c, uae_u32 *ct) { - if (c == 0) { - SetPixel (andDC, x, y, RGB (255, 255, 255)); - SetPixel (xorDC, x, y, RGB (0, 0, 0)); - } else { - uae_u32 val = ct[c]; - SetPixel (andDC, x, y, RGB (0, 0, 0)); - SetPixel (xorDC, x, y, RGB ((val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff)); - } + if (c == 0) { + SetPixel (andDC, x, y, RGB (255, 255, 255)); + SetPixel (xorDC, x, y, RGB (0, 0, 0)); + } else { + uae_u32 val = ct[c]; + SetPixel (andDC, x, y, RGB (0, 0, 0)); + SetPixel (xorDC, x, y, RGB ((val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff)); + } } static int wincursorcnt; @@ -1522,324 +1522,324 @@ extern uae_u32 sprite_0_colors[4]; int createwindowscursor (uaecptr src, int w, int h, int hiressprite, int doubledsprite, int chipset) { - HBITMAP andBM, xorBM; - HBITMAP andoBM, xoroBM; - HDC andDC, xorDC, DC, mainDC; - ICONINFO ic; - int x, y, yy, w2, h2; - int ret, isdata, datasize; - HCURSOR oldwincursor = wincursor; - uae_u8 *realsrc; - uae_u32 *ct; - - ret = 0; - wincursor_shown = 0; - - if (isfullscreen () > 0 || currprefs.input_tablet == 0 || currprefs.input_magic_mouse == 0) - goto exit; - if (currprefs.input_magic_mouse_cursor != MAGICMOUSE_HOST_ONLY) - goto exit; - - if (chipset) { - if (!sprite_0 || !mousehack_alive ()) { - if (wincursor) - SetCursor (normalcursor); - goto exit; - } - w2 = w = sprite_0_width; - h2 = h = sprite_0_height; - hiressprite = sprite_0_width / 16; - doubledsprite = sprite_0_doubled; - if (doubledsprite) { - h2 *= 2; - w2 *= 2; + HBITMAP andBM, xorBM; + HBITMAP andoBM, xoroBM; + HDC andDC, xorDC, DC, mainDC; + ICONINFO ic; + int x, y, yy, w2, h2; + int ret, isdata, datasize; + HCURSOR oldwincursor = wincursor; + uae_u8 *realsrc; + uae_u32 *ct; + + ret = 0; + wincursor_shown = 0; + + if (isfullscreen () > 0 || currprefs.input_tablet == 0 || currprefs.input_magic_mouse == 0) + goto exit; + if (currprefs.input_magic_mouse_cursor != MAGICMOUSE_HOST_ONLY) + goto exit; + + if (chipset) { + if (!sprite_0 || !mousehack_alive ()) { + if (wincursor) + SetCursor (normalcursor); + goto exit; + } + w2 = w = sprite_0_width; + h2 = h = sprite_0_height; + hiressprite = sprite_0_width / 16; + doubledsprite = sprite_0_doubled; + if (doubledsprite) { + h2 *= 2; + w2 *= 2; + } + src = sprite_0; + ct = sprite_0_colors; + } else { + h2 = h; + w2 = w; + ct = cursorrgbn; } - src = sprite_0; - ct = sprite_0_colors; - } else { - h2 = h; - w2 = w; - ct = cursorrgbn; - } - datasize = h * ((w + 15) / 16) * 4; - realsrc = get_real_address (src); - - if (w > 64 || h > 64) - goto exit; - - if (wincursor && tmp_sprite_data) { - if (w == tmp_sprite_w && h == tmp_sprite_h && - !memcmp (tmp_sprite_data, realsrc, datasize) && !memcmp (tmp_sprite_colors, ct, sizeof (uae_u32)*4) - && hiressprite == tmp_sprite_hires && doubledsprite == tmp_sprite_doubled - ) { - if (GetCursor () == wincursor) { - wincursor_shown = 1; - return 1; - } + datasize = h * ((w + 15) / 16) * 4; + realsrc = get_real_address (src); + + if (w > 64 || h > 64) + goto exit; + + if (wincursor && tmp_sprite_data) { + if (w == tmp_sprite_w && h == tmp_sprite_h && + !memcmp (tmp_sprite_data, realsrc, datasize) && !memcmp (tmp_sprite_colors, ct, sizeof (uae_u32)*4) + && hiressprite == tmp_sprite_hires && doubledsprite == tmp_sprite_doubled + ) { + if (GetCursor () == wincursor) { + wincursor_shown = 1; + return 1; + } + } } - } - write_log (L"wincursor: %dx%d hires=%d doubled=%d\n", w2, h2, hiressprite, doubledsprite); - - xfree (tmp_sprite_data); - tmp_sprite_data = NULL; - tmp_sprite_w = tmp_sprite_h = 0; - - DC = mainDC = andDC = xorDC = NULL; - andBM = xorBM = NULL; - DC = GetDC (NULL); - if (!DC) - goto end; - mainDC = CreateCompatibleDC (DC); - andDC = CreateCompatibleDC (DC); - xorDC = CreateCompatibleDC (DC); - if (!mainDC || !andDC || !xorDC) - goto end; - andBM = CreateCompatibleBitmap (DC, w2, h2); - xorBM = CreateCompatibleBitmap (DC, w2, h2); - if (!andBM || !xorBM) - goto end; - andoBM = SelectObject (andDC, andBM); - xoroBM = SelectObject (xorDC, xorBM); - - isdata = 0; - for (y = 0, yy = 0; y < h2; yy++) { - int dbl; - uaecptr img = src + yy * 4 * hiressprite; - for (dbl = 0; dbl < (doubledsprite ? 2 : 1); dbl++) { - x = 0; - while (x < w2) { - uae_u32 d1 = get_long (img); - uae_u32 d2 = get_long (img + 2 * hiressprite); - int bits; - int maxbits = w2 - x; - - if (maxbits > 16 * hiressprite) - maxbits = 16 * hiressprite; - for (bits = 0; bits < maxbits && x < w2; bits++) { - uae_u8 c = ((d2 & 0x80000000) ? 2 : 0) + ((d1 & 0x80000000) ? 1 : 0); - d1 <<= 1; - d2 <<= 1; - putwinmousepixel (andDC, xorDC, x, y, c, ct); - if (c > 0) - isdata = 1; - x++; - if (doubledsprite && x < w2) { - putwinmousepixel (andDC, xorDC, x, y, c, ct); - x++; - } + write_log (L"wincursor: %dx%d hires=%d doubled=%d\n", w2, h2, hiressprite, doubledsprite); + + xfree (tmp_sprite_data); + tmp_sprite_data = NULL; + tmp_sprite_w = tmp_sprite_h = 0; + + DC = mainDC = andDC = xorDC = NULL; + andBM = xorBM = NULL; + DC = GetDC (NULL); + if (!DC) + goto end; + mainDC = CreateCompatibleDC (DC); + andDC = CreateCompatibleDC (DC); + xorDC = CreateCompatibleDC (DC); + if (!mainDC || !andDC || !xorDC) + goto end; + andBM = CreateCompatibleBitmap (DC, w2, h2); + xorBM = CreateCompatibleBitmap (DC, w2, h2); + if (!andBM || !xorBM) + goto end; + andoBM = SelectObject (andDC, andBM); + xoroBM = SelectObject (xorDC, xorBM); + + isdata = 0; + for (y = 0, yy = 0; y < h2; yy++) { + int dbl; + uaecptr img = src + yy * 4 * hiressprite; + for (dbl = 0; dbl < (doubledsprite ? 2 : 1); dbl++) { + x = 0; + while (x < w2) { + uae_u32 d1 = get_long (img); + uae_u32 d2 = get_long (img + 2 * hiressprite); + int bits; + int maxbits = w2 - x; + + if (maxbits > 16 * hiressprite) + maxbits = 16 * hiressprite; + for (bits = 0; bits < maxbits && x < w2; bits++) { + uae_u8 c = ((d2 & 0x80000000) ? 2 : 0) + ((d1 & 0x80000000) ? 1 : 0); + d1 <<= 1; + d2 <<= 1; + putwinmousepixel (andDC, xorDC, x, y, c, ct); + if (c > 0) + isdata = 1; + x++; + if (doubledsprite && x < w2) { + putwinmousepixel (andDC, xorDC, x, y, c, ct); + x++; + } + } + } + if (y <= h2) + y++; } - } - if (y <= h2) - y++; } - } - ret = 1; + ret = 1; - SelectObject (andDC, andoBM); - SelectObject (xorDC, xoroBM); + SelectObject (andDC, andoBM); + SelectObject (xorDC, xoroBM); end: - DeleteDC (xorDC); - DeleteDC (andDC); - DeleteDC (mainDC); - ReleaseDC (NULL, DC); - - if (!isdata) { - wincursor = LoadCursor (NULL, IDC_ARROW); - } else if (ret) { - memset (&ic, 0, sizeof ic); - ic.hbmColor = xorBM; - ic.hbmMask = andBM; - wincursor = CreateIconIndirect (&ic); - tmp_sprite_w = w; - tmp_sprite_h = h; - tmp_sprite_data = xmalloc (datasize); - tmp_sprite_hires = hiressprite; - tmp_sprite_doubled = doubledsprite; - memcpy (tmp_sprite_data, realsrc, datasize); - memcpy (tmp_sprite_colors, ct, sizeof (uae_u32) * 4); - } - - DeleteObject (andBM); - DeleteObject (xorBM); - - if (wincursor) { - SetCursor (wincursor); - wincursor_shown = 1; - } - - if (!ret) - write_log (L"RTG Windows color cursor creation failed\n"); + DeleteDC (xorDC); + DeleteDC (andDC); + DeleteDC (mainDC); + ReleaseDC (NULL, DC); + + if (!isdata) { + wincursor = LoadCursor (NULL, IDC_ARROW); + } else if (ret) { + memset (&ic, 0, sizeof ic); + ic.hbmColor = xorBM; + ic.hbmMask = andBM; + wincursor = CreateIconIndirect (&ic); + tmp_sprite_w = w; + tmp_sprite_h = h; + tmp_sprite_data = xmalloc (datasize); + tmp_sprite_hires = hiressprite; + tmp_sprite_doubled = doubledsprite; + memcpy (tmp_sprite_data, realsrc, datasize); + memcpy (tmp_sprite_colors, ct, sizeof (uae_u32) * 4); + } + + DeleteObject (andBM); + DeleteObject (xorBM); + + if (wincursor) { + SetCursor (wincursor); + wincursor_shown = 1; + } + + if (!ret) + write_log (L"RTG Windows color cursor creation failed\n"); exit: - if (currprefs.input_tablet && currprefs.input_magic_mouse && currprefs.input_magic_mouse_cursor == MAGICMOUSE_NATIVE_ONLY) { - if (GetCursor () != NULL) - SetCursor (NULL); - } else { - if (wincursor == oldwincursor) - SetCursor (normalcursor); - } - if (oldwincursor) - DestroyIcon (oldwincursor); - oldwincursor = NULL; - - return ret; + if (currprefs.input_tablet && currprefs.input_magic_mouse && currprefs.input_magic_mouse_cursor == MAGICMOUSE_NATIVE_ONLY) { + if (GetCursor () != NULL) + SetCursor (NULL); + } else { + if (wincursor == oldwincursor) + SetCursor (normalcursor); + } + if (oldwincursor) + DestroyIcon (oldwincursor); + oldwincursor = NULL; + + return ret; } int picasso_setwincursor (void) { - if (wincursor) { - SetCursor (wincursor); - return 1; - } else if (!picasso_on) { - if (createwindowscursor (0, 0, 0, 0, 0, 1)) - return 1; - } - return 0; + if (wincursor) { + SetCursor (wincursor); + return 1; + } else if (!picasso_on) { + if (createwindowscursor (0, 0, 0, 0, 0, 1)) + return 1; + } + return 0; } static uae_u32 setspriteimage (uaecptr bi) { - DDSURFACEDESC2 desc; - uae_u32 flags; - int x, y, yy, bits, bpp; - DWORD ddrval; - uae_u8 *dptr; - uae_u8 *tmpbuf; - DWORD pitch; - int hiressprite, doubledsprite; - int ret = 0; - int w, h; - - cursordeactivate = 0; - if (!hwsprite || !dxdata.cursorsurface1) - return 0; - oldcursor_x = -10000; - w = get_byte (bi + PSSO_BoardInfo_MouseWidth); - h = get_byte (bi + PSSO_BoardInfo_MouseHeight); - tmpbuf = NULL; - flags = get_long (bi + PSSO_BoardInfo_Flags); - hiressprite = 1; - doubledsprite = 0; - if (flags & BIF_HIRESSPRITE) - hiressprite = 2; - if (flags & BIF_BIGSPRITE) - doubledsprite = 1; - updatesprcolors (); - - P96TRACE_SPR ((L"SetSpriteImage(%08x,%08x,w=%d,h=%d,%d/%d,%08x)\n", - bi, get_long (bi + PSSO_BoardInfo_MouseImage), w, h, - hiressprite - 1, doubledsprite, bi + PSSO_BoardInfo_MouseImage)); - - if (w > dxcaps.cursorwidth) - w = dxcaps.cursorwidth; - if (h > dxcaps.cursorheight) - h = dxcaps.cursorheight; - - bpp = picasso_vidinfo.pixbytes; - if (!w || !h || get_long (bi + PSSO_BoardInfo_MouseImage) == 0) { - cursordeactivate = 1; - ret = 1; - goto end; - } - - createwindowscursor (get_long (bi + PSSO_BoardInfo_MouseImage) + 4 * hiressprite, - w, h, hiressprite, doubledsprite, 0); - - tmpbuf = xmalloc (w * h * bpp); - for (y = 0, yy = 0; y < h; y++, yy++) { - uae_u8 *p = tmpbuf + w * bpp * y; - uae_u8 *pprev = p; - uaecptr img = get_long (bi + PSSO_BoardInfo_MouseImage) + 4 * hiressprite + yy * 4 * hiressprite; - x = 0; - while (x < w) { - uae_u32 d1 = get_long (img); - uae_u32 d2 = get_long (img + 2 * hiressprite); - int maxbits = w - x; - if (maxbits > 16 * hiressprite) - maxbits = 16 * hiressprite; - for (bits = 0; bits < maxbits && x < w; bits++) { - uae_u8 c = ((d2 & 0x80000000) ? 2 : 0) + ((d1 & 0x80000000) ? 1 : 0); - d1 <<= 1; - d2 <<= 1; - putmousepixel (p, bpp, c); - p += bpp; - x++; - if (doubledsprite && x < w) { - putmousepixel (p, bpp, c); - p += bpp; - x++; + DDSURFACEDESC2 desc; + uae_u32 flags; + int x, y, yy, bits, bpp; + DWORD ddrval; + uae_u8 *dptr; + uae_u8 *tmpbuf; + DWORD pitch; + int hiressprite, doubledsprite; + int ret = 0; + int w, h; + + cursordeactivate = 0; + if (!hwsprite || !dxdata.cursorsurface1) + return 0; + oldcursor_x = -10000; + w = get_byte (bi + PSSO_BoardInfo_MouseWidth); + h = get_byte (bi + PSSO_BoardInfo_MouseHeight); + tmpbuf = NULL; + flags = get_long (bi + PSSO_BoardInfo_Flags); + hiressprite = 1; + doubledsprite = 0; + if (flags & BIF_HIRESSPRITE) + hiressprite = 2; + if (flags & BIF_BIGSPRITE) + doubledsprite = 1; + updatesprcolors (); + + P96TRACE_SPR ((L"SetSpriteImage(%08x,%08x,w=%d,h=%d,%d/%d,%08x)\n", + bi, get_long (bi + PSSO_BoardInfo_MouseImage), w, h, + hiressprite - 1, doubledsprite, bi + PSSO_BoardInfo_MouseImage)); + + if (w > dxcaps.cursorwidth) + w = dxcaps.cursorwidth; + if (h > dxcaps.cursorheight) + h = dxcaps.cursorheight; + + bpp = picasso_vidinfo.pixbytes; + if (!w || !h || get_long (bi + PSSO_BoardInfo_MouseImage) == 0) { + cursordeactivate = 1; + ret = 1; + goto end; + } + + createwindowscursor (get_long (bi + PSSO_BoardInfo_MouseImage) + 4 * hiressprite, + w, h, hiressprite, doubledsprite, 0); + + tmpbuf = xmalloc (w * h * bpp); + for (y = 0, yy = 0; y < h; y++, yy++) { + uae_u8 *p = tmpbuf + w * bpp * y; + uae_u8 *pprev = p; + uaecptr img = get_long (bi + PSSO_BoardInfo_MouseImage) + 4 * hiressprite + yy * 4 * hiressprite; + x = 0; + while (x < w) { + uae_u32 d1 = get_long (img); + uae_u32 d2 = get_long (img + 2 * hiressprite); + int maxbits = w - x; + if (maxbits > 16 * hiressprite) + maxbits = 16 * hiressprite; + for (bits = 0; bits < maxbits && x < w; bits++) { + uae_u8 c = ((d2 & 0x80000000) ? 2 : 0) + ((d1 & 0x80000000) ? 1 : 0); + d1 <<= 1; + d2 <<= 1; + putmousepixel (p, bpp, c); + p += bpp; + x++; + if (doubledsprite && x < w) { + putmousepixel (p, bpp, c); + p += bpp; + x++; + } + } + } + if (doubledsprite && y < h) { + y++; + memcpy (p, pprev, w * bpp); } - } } - if (doubledsprite && y < h) { - y++; - memcpy (p, pprev, w * bpp); + + if (cursorok) { + for (;;) { + if (!reloadcursor && w == cursorwidth && h == cursorheight) { + int different = 0; + desc.dwSize = sizeof (desc); + while (FAILED ((ddrval = IDirectDrawSurface7_Lock (dxdata.cursorsurface1, NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = IDirectDrawSurface7_Restore (dxdata.cursorsurface1); + if (FAILED (ddrval)) + break; + } + } + if (FAILED (ddrval)) + break; + dptr = (uae_u8*)desc.lpSurface; + pitch = desc.lPitch; + for (y = 0; y < h; y++) { + uae_u8 *p1 = tmpbuf + w * bpp * y; + uae_u8 *p2 = dptr + pitch * y; + if (memcmp (p1, p2, w * bpp)) + different = 1; + } + IDirectDrawSurface_Unlock (dxdata.cursorsurface1, NULL); + if (!different) { + P96TRACE_SPR ((L"sprite was same as previously\n")); + ret = 1; + goto end; + } + } + break; + } + cursorok = FALSE; } - } - if (cursorok) { - for (;;) { - if (!reloadcursor && w == cursorwidth && h == cursorheight) { - int different = 0; - desc.dwSize = sizeof (desc); - while (FAILED ((ddrval = IDirectDrawSurface7_Lock (dxdata.cursorsurface1, NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))) { - if (ddrval == DDERR_SURFACELOST) { + cursorwidth = w; + cursorheight = h; + + desc.dwSize = sizeof (desc); + while (FAILED((ddrval = IDirectDrawSurface7_Lock (dxdata.cursorsurface1, NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))) { + if (ddrval == DDERR_SURFACELOST) { ddrval = IDirectDrawSurface7_Restore (dxdata.cursorsurface1); - if (FAILED (ddrval)) - break; - } - } - if (FAILED (ddrval)) - break; - dptr = (uae_u8*)desc.lpSurface; - pitch = desc.lPitch; - for (y = 0; y < h; y++) { - uae_u8 *p1 = tmpbuf + w * bpp * y; - uae_u8 *p2 = dptr + pitch * y; - if (memcmp (p1, p2, w * bpp)) - different = 1; - } - IDirectDrawSurface_Unlock (dxdata.cursorsurface1, NULL); - if (!different) { - P96TRACE_SPR ((L"sprite was same as previously\n")); - ret = 1; - goto end; + if (FAILED(ddrval)) { + write_log (L"sprite surface failed to restore: %s\n", DXError (ddrval)); + goto end; + } } - } - break; } - cursorok = FALSE; - } - - cursorwidth = w; - cursorheight = h; - - desc.dwSize = sizeof (desc); - while (FAILED((ddrval = IDirectDrawSurface7_Lock (dxdata.cursorsurface1, NULL, &desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = IDirectDrawSurface7_Restore (dxdata.cursorsurface1); - if (FAILED(ddrval)) { - write_log (L"sprite surface failed to restore: %s\n", DXError (ddrval)); - goto end; - } + dptr = (uae_u8*)desc.lpSurface; + pitch = desc.lPitch; + for (y = 0; y < h; y++) { + uae_u8 *p1 = tmpbuf + w * bpp * y; + uae_u8 *p2 = dptr + pitch * y; + memcpy (p2, p1, w * bpp); } - } - dptr = (uae_u8*)desc.lpSurface; - pitch = desc.lPitch; - for (y = 0; y < h; y++) { - uae_u8 *p1 = tmpbuf + w * bpp * y; - uae_u8 *p2 = dptr + pitch * y; - memcpy (p2, p1, w * bpp); - } - IDirectDrawSurface_Unlock (dxdata.cursorsurface1, NULL); - ret = 1; - reloadcursor = 0; - cursorok = TRUE; - P96TRACE_SPR ((L"hardware sprite created\n")); + IDirectDrawSurface_Unlock (dxdata.cursorsurface1, NULL); + ret = 1; + reloadcursor = 0; + cursorok = TRUE; + P96TRACE_SPR ((L"hardware sprite created\n")); end: - xfree (tmpbuf); - return ret; + xfree (tmpbuf); + return ret; } /* @@ -1869,9 +1869,9 @@ compensate for this when accounting for hotspot offsets and sprite dimensions. */ static uae_u32 REGPARAM2 picasso_SetSpriteImage (TrapContext *ctx) { - uaecptr bi = m68k_areg (regs, 0); - boardinfo = bi; - return setspriteimage (bi); + uaecptr bi = m68k_areg (regs, 0); + boardinfo = bi; + return setspriteimage (bi); } /* @@ -1885,19 +1885,19 @@ This function activates or deactivates the hardware sprite. */ static uae_u32 REGPARAM2 picasso_SetSprite (TrapContext *ctx) { - uae_u32 result = 0; - uae_u32 activate = m68k_dreg (regs, 0); - if (!hwsprite) - return 0; - if (activate) { - picasso_SetSpriteImage (ctx); - cursorvisible = 1; - } else { - cursordeactivate = 2; - } - result = 1; - P96TRACE_SPR ((L"SetSprite: %d\n", activate)); - return result; + uae_u32 result = 0; + uae_u32 activate = m68k_dreg (regs, 0); + if (!hwsprite) + return 0; + if (activate) { + picasso_SetSpriteImage (ctx); + cursorvisible = 1; + } else { + cursordeactivate = 2; + } + result = 1; + P96TRACE_SPR ((L"SetSprite: %d\n", activate)); + return result; } /* @@ -1917,150 +1917,150 @@ static uae_u32 REGPARAM2 picasso_SetSprite (TrapContext *ctx) */ static uae_u32 REGPARAM2 picasso_FindCard (TrapContext *ctx) { - uaecptr AmigaBoardInfo = m68k_areg (regs, 0); - /* NOTES: See BoardInfo struct definition in Picasso96 dev info */ + uaecptr AmigaBoardInfo = m68k_areg (regs, 0); + /* NOTES: See BoardInfo struct definition in Picasso96 dev info */ #ifdef UAEGFX_INTERNAL - if (!uaegfx_base) - return 0; - put_long (uaegfx_base + CARD_BOARDINFO, AmigaBoardInfo); - boardinfo = AmigaBoardInfo; + if (!uaegfx_base) + return 0; + put_long (uaegfx_base + CARD_BOARDINFO, AmigaBoardInfo); + boardinfo = AmigaBoardInfo; #endif - if (allocated_gfxmem && !picasso96_state.CardFound) { - /* Fill in MemoryBase, MemorySize */ - put_long (AmigaBoardInfo + PSSO_BoardInfo_MemoryBase, gfxmem_start); - put_long (AmigaBoardInfo + PSSO_BoardInfo_MemorySize, allocated_gfxmem); - picasso96_state.CardFound = 1; /* mark our "card" as being found */ - return -1; - } else - return 0; + if (allocated_gfxmem && !picasso96_state.CardFound) { + /* Fill in MemoryBase, MemorySize */ + put_long (AmigaBoardInfo + PSSO_BoardInfo_MemoryBase, gfxmem_start); + put_long (AmigaBoardInfo + PSSO_BoardInfo_MemorySize, allocated_gfxmem); + picasso96_state.CardFound = 1; /* mark our "card" as being found */ + return -1; + } else + return 0; } static void FillBoardInfo (uaecptr amigamemptr, struct LibResolution *res, int width, int height, int depth) { - int i; + int i; - switch (depth) - { + switch (depth) + { case 8: - res->Modes[CHUNKY] = amigamemptr; - break; + res->Modes[CHUNKY] = amigamemptr; + break; case 15: case 16: - res->Modes[HICOLOR] = amigamemptr; - break; + res->Modes[HICOLOR] = amigamemptr; + break; case 24: - res->Modes[TRUECOLOR] = amigamemptr; - break; + res->Modes[TRUECOLOR] = amigamemptr; + break; default: - res->Modes[TRUEALPHA] = amigamemptr; - break; - } - for (i = 0; i < PSSO_ModeInfo_sizeof; i++) - put_byte (amigamemptr + i, 0); - - put_word (amigamemptr + PSSO_ModeInfo_Width, width); - put_word (amigamemptr + PSSO_ModeInfo_Height, height); - put_byte (amigamemptr + PSSO_ModeInfo_Depth, depth); - put_byte (amigamemptr + PSSO_ModeInfo_Flags, 0); - put_word (amigamemptr + PSSO_ModeInfo_HorTotal, width); - put_word (amigamemptr + PSSO_ModeInfo_HorBlankSize, 0); - put_word (amigamemptr + PSSO_ModeInfo_HorSyncStart, 0); - put_word (amigamemptr + PSSO_ModeInfo_HorSyncSize, 0); - put_byte (amigamemptr + PSSO_ModeInfo_HorSyncSkew, 0); - put_byte (amigamemptr + PSSO_ModeInfo_HorEnableSkew, 0); - - put_word (amigamemptr + PSSO_ModeInfo_VerTotal, height); - put_word (amigamemptr + PSSO_ModeInfo_VerBlankSize, 0); - put_word (amigamemptr + PSSO_ModeInfo_VerSyncStart, 0); - put_word (amigamemptr + PSSO_ModeInfo_VerSyncSize, 0); - - put_byte (amigamemptr + PSSO_ModeInfo_first_union, 98); - put_byte (amigamemptr + PSSO_ModeInfo_second_union, 14); - - put_long (amigamemptr + PSSO_ModeInfo_PixelClock, - width * height * (currprefs.gfx_refreshrate ? abs (currprefs.gfx_refreshrate) : default_freq)); + res->Modes[TRUEALPHA] = amigamemptr; + break; + } + for (i = 0; i < PSSO_ModeInfo_sizeof; i++) + put_byte (amigamemptr + i, 0); + + put_word (amigamemptr + PSSO_ModeInfo_Width, width); + put_word (amigamemptr + PSSO_ModeInfo_Height, height); + put_byte (amigamemptr + PSSO_ModeInfo_Depth, depth); + put_byte (amigamemptr + PSSO_ModeInfo_Flags, 0); + put_word (amigamemptr + PSSO_ModeInfo_HorTotal, width); + put_word (amigamemptr + PSSO_ModeInfo_HorBlankSize, 0); + put_word (amigamemptr + PSSO_ModeInfo_HorSyncStart, 0); + put_word (amigamemptr + PSSO_ModeInfo_HorSyncSize, 0); + put_byte (amigamemptr + PSSO_ModeInfo_HorSyncSkew, 0); + put_byte (amigamemptr + PSSO_ModeInfo_HorEnableSkew, 0); + + put_word (amigamemptr + PSSO_ModeInfo_VerTotal, height); + put_word (amigamemptr + PSSO_ModeInfo_VerBlankSize, 0); + put_word (amigamemptr + PSSO_ModeInfo_VerSyncStart, 0); + put_word (amigamemptr + PSSO_ModeInfo_VerSyncSize, 0); + + put_byte (amigamemptr + PSSO_ModeInfo_first_union, 98); + put_byte (amigamemptr + PSSO_ModeInfo_second_union, 14); + + put_long (amigamemptr + PSSO_ModeInfo_PixelClock, + width * height * (currprefs.gfx_refreshrate ? abs (currprefs.gfx_refreshrate) : default_freq)); } struct modeids { - int width, height; - int id; + int width, height; + int id; }; static struct modeids mi[] = { -/* "original" modes */ - - 320, 200, 0, - 320, 240, 1, - 640, 400, 2, - 640, 480, 3, - 800, 600, 4, - 1024, 768, 5, - 1152, 864, 6, - 1280,1024, 7, - 1600,1280, 8, - 320, 256, 9, - 640, 512,10, - -/* new modes */ - - 704, 480, 129, - 704, 576, 130, - 720, 480, 131, - 720, 576, 132, - 768, 483, 133, - 768, 576, 134, - 800, 480, 135, - 848, 480, 136, - 854, 480, 137, - 948, 576, 138, - 1024, 576, 139, - 1152, 768, 140, - 1152, 864, 141, - 1280, 720, 142, - 1280, 768, 143, - 1280, 800, 144, - 1280, 854, 145, - 1280, 960, 146, - 1366, 768, 147, - 1440, 900, 148, - 1440, 960, 149, - 1600,1200, 150, - 1680,1050, 151, - 1920,1080, 152, - 1920,1200, 153, - 2048,1152, 154, - 2048,1536, 155, - 2560,1600, 156, - 2560,2048, 157, - 400, 300, 158, - 512, 384, 159, - 640, 432, 160, - 1360, 768, 161, - 1360,1024, 162, - 1400,1050, 163, - 1792,1344, 164, - 1800,1440, 165, - 1856,1392, 166, - 1920,1440, 167, - 480, 360, 168, - 640, 350, 169, - 1600, 900, 170, - 960, 600, 171, - 1088, 612, 172, - -1,-1,0 + /* "original" modes */ + + 320, 200, 0, + 320, 240, 1, + 640, 400, 2, + 640, 480, 3, + 800, 600, 4, + 1024, 768, 5, + 1152, 864, 6, + 1280,1024, 7, + 1600,1280, 8, + 320, 256, 9, + 640, 512,10, + + /* new modes */ + + 704, 480, 129, + 704, 576, 130, + 720, 480, 131, + 720, 576, 132, + 768, 483, 133, + 768, 576, 134, + 800, 480, 135, + 848, 480, 136, + 854, 480, 137, + 948, 576, 138, + 1024, 576, 139, + 1152, 768, 140, + 1152, 864, 141, + 1280, 720, 142, + 1280, 768, 143, + 1280, 800, 144, + 1280, 854, 145, + 1280, 960, 146, + 1366, 768, 147, + 1440, 900, 148, + 1440, 960, 149, + 1600,1200, 150, + 1680,1050, 151, + 1920,1080, 152, + 1920,1200, 153, + 2048,1152, 154, + 2048,1536, 155, + 2560,1600, 156, + 2560,2048, 157, + 400, 300, 158, + 512, 384, 159, + 640, 432, 160, + 1360, 768, 161, + 1360,1024, 162, + 1400,1050, 163, + 1792,1344, 164, + 1800,1440, 165, + 1856,1392, 166, + 1920,1440, 167, + 480, 360, 168, + 640, 350, 169, + 1600, 900, 170, + 960, 600, 171, + 1088, 612, 172, + -1,-1,0 }; static int AssignModeID (int w, int h, int *unkcnt) { - int i; - - for (i = 0; mi[i].width > 0; i++) { - if (w == mi[i].width && h == mi[i].height) - return 0x50001000 | (mi[i].id * 0x10000); - } - (*unkcnt)++; - write_log (L"P96: Non-unique mode %dx%d\n", w, h); - return 0x51001000 - (*unkcnt) * 0x10000; + int i; + + for (i = 0; mi[i].width > 0; i++) { + if (w == mi[i].width && h == mi[i].height) + return 0x50001000 | (mi[i].id * 0x10000); + } + (*unkcnt)++; + write_log (L"P96: Non-unique mode %dx%d\n", w, h); + return 0x51001000 - (*unkcnt) * 0x10000; } static uaecptr picasso96_amem, picasso96_amemend; @@ -2068,57 +2068,57 @@ static uaecptr picasso96_amem, picasso96_amemend; static void CopyLibResolutionStructureU2A (struct LibResolution *libres, uaecptr amigamemptr) { - int i; - - for (i = 0; i < PSSO_LibResolution_sizeof; i++) - put_byte (amigamemptr + i, 0); - for (i = 0; i < strlen (libres->P96ID); i++) - put_byte (amigamemptr + PSSO_LibResolution_P96ID + i, libres->P96ID[i]); - put_long (amigamemptr + PSSO_LibResolution_DisplayID, libres->DisplayID); - put_word (amigamemptr + PSSO_LibResolution_Width, libres->Width); - put_word (amigamemptr + PSSO_LibResolution_Height, libres->Height); - put_word (amigamemptr + PSSO_LibResolution_Flags, libres->Flags); - for (i = 0; i < MAXMODES; i++) - put_long (amigamemptr + PSSO_LibResolution_Modes + i * 4, libres->Modes[i]); - put_long (amigamemptr + 10, amigamemptr + PSSO_LibResolution_P96ID); - put_long (amigamemptr + PSSO_LibResolution_BoardInfo, libres->BoardInfo); + int i; + + for (i = 0; i < PSSO_LibResolution_sizeof; i++) + put_byte (amigamemptr + i, 0); + for (i = 0; i < strlen (libres->P96ID); i++) + put_byte (amigamemptr + PSSO_LibResolution_P96ID + i, libres->P96ID[i]); + put_long (amigamemptr + PSSO_LibResolution_DisplayID, libres->DisplayID); + put_word (amigamemptr + PSSO_LibResolution_Width, libres->Width); + put_word (amigamemptr + PSSO_LibResolution_Height, libres->Height); + put_word (amigamemptr + PSSO_LibResolution_Flags, libres->Flags); + for (i = 0; i < MAXMODES; i++) + put_long (amigamemptr + PSSO_LibResolution_Modes + i * 4, libres->Modes[i]); + put_long (amigamemptr + 10, amigamemptr + PSSO_LibResolution_P96ID); + put_long (amigamemptr + PSSO_LibResolution_BoardInfo, libres->BoardInfo); } static void init_alloc (void) { - SYSTEM_INFO si; - - picasso96_amem = picasso96_amemend = 0; - if (uaegfx_base) { - int size = get_long (uaegfx_base + CARD_RESLISTSIZE); - picasso96_amem = get_long (uaegfx_base + CARD_RESLIST); - picasso96_amemend = picasso96_amem + size; - write_log (L"P96 RESINFO: %08X-%08X (%d,%d)\n", picasso96_amem, picasso96_amemend, size / PSSO_ModeInfo_sizeof, size); - } - xfree (gwwbuf); - GetSystemInfo (&si); - gwwpagesize = si.dwPageSize; - gwwbufsize = allocated_gfxmem / gwwpagesize + 1; - gwwpagemask = gwwpagesize - 1; - gwwbuf = xmalloc (gwwbufsize * sizeof (void*)); + SYSTEM_INFO si; + + picasso96_amem = picasso96_amemend = 0; + if (uaegfx_base) { + int size = get_long (uaegfx_base + CARD_RESLISTSIZE); + picasso96_amem = get_long (uaegfx_base + CARD_RESLIST); + picasso96_amemend = picasso96_amem + size; + write_log (L"P96 RESINFO: %08X-%08X (%d,%d)\n", picasso96_amem, picasso96_amemend, size / PSSO_ModeInfo_sizeof, size); + } + xfree (gwwbuf); + GetSystemInfo (&si); + gwwpagesize = si.dwPageSize; + gwwbufsize = allocated_gfxmem / gwwpagesize + 1; + gwwpagemask = gwwpagesize - 1; + gwwbuf = xmalloc (gwwbufsize * sizeof (void*)); } static int p96depth (int depth) { - uae_u32 f = currprefs.picasso96_modeflags; - int ok = 0; - - if (depth == 8 && (f & RGBFF_CLUT)) - ok = 1; - if (depth == 15 && (f & (RGBFF_R5G5B5PC | RGBFF_R5G5B5 | RGBFF_B5G5R5PC))) - ok = 2; - if (depth == 16 && (f & (RGBFF_R5G6B5PC | RGBFF_R5G6B5 | RGBFF_B5G6R5PC))) - ok = 2; - if (depth == 24 && (f & (RGBFF_R8G8B8 | RGBFF_B8G8R8))) - ok = 3; - if (depth == 32 && (f & (RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8))) - ok = 4; - return ok; + uae_u32 f = currprefs.picasso96_modeflags; + int ok = 0; + + if (depth == 8 && (f & RGBFF_CLUT)) + ok = 1; + if (depth == 15 && (f & (RGBFF_R5G5B5PC | RGBFF_R5G5B5 | RGBFF_B5G5R5PC))) + ok = 2; + if (depth == 16 && (f & (RGBFF_R5G6B5PC | RGBFF_R5G6B5 | RGBFF_B5G6R5PC))) + ok = 2; + if (depth == 24 && (f & (RGBFF_R8G8B8 | RGBFF_B8G8R8))) + ok = 3; + if (depth == 32 && (f & (RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8))) + ok = 4; + return ok; } static int missmodes[] = { 320, 200, 320, 240, 320, 256, 640, 400, 640, 480, 640, 512, 800, 600, 1024, 768, 1280, 1024, -1 }; @@ -2128,143 +2128,143 @@ static uaecptr uaegfx_card_install (TrapContext *ctx, uae_u32 size); #endif void picasso96_alloc (TrapContext *ctx) { - int i, j, size, cnt; - int misscnt, depths; - struct MultiDisplay *md = getdisplay (&currprefs); - struct PicassoResolution *DisplayModes = md->DisplayModes; - - uaegfx_resname = ds (L"uaegfx.card"); - xfree (newmodes); - newmodes = NULL; - picasso96_amem = picasso96_amemend = 0; - if (allocated_gfxmem == 0) - return; - misscnt = 0; - cnt = 0; - newmodes = xmalloc (sizeof (struct PicassoResolution) * MAX_PICASSO_MODES); - size = 0; - - depths = 0; - if (p96depth (8)) - depths++; - if (p96depth (15)) - depths++; - if (p96depth (16)) - depths++; - if (p96depth (24)) - depths++; - if (p96depth (32)) - depths++; - - i = 0; - while (DisplayModes[i].depth >= 0) { - if (DisplayModes[i].nondx == 0) { - for (j = 0; missmodes[j * 2] >= 0; j++) { - if (DisplayModes[i].res.width == missmodes[j * 2 + 0] && DisplayModes[i].res.height == missmodes[j * 2 + 1]) { - missmodes[j * 2 + 0] = 0; - missmodes[j * 2 + 1] = 0; + int i, j, size, cnt; + int misscnt, depths; + struct MultiDisplay *md = getdisplay (&currprefs); + struct PicassoResolution *DisplayModes = md->DisplayModes; + + uaegfx_resname = ds (L"uaegfx.card"); + xfree (newmodes); + newmodes = NULL; + picasso96_amem = picasso96_amemend = 0; + if (allocated_gfxmem == 0) + return; + misscnt = 0; + cnt = 0; + newmodes = xmalloc (sizeof (struct PicassoResolution) * MAX_PICASSO_MODES); + size = 0; + + depths = 0; + if (p96depth (8)) + depths++; + if (p96depth (15)) + depths++; + if (p96depth (16)) + depths++; + if (p96depth (24)) + depths++; + if (p96depth (32)) + depths++; + + i = 0; + while (DisplayModes[i].depth >= 0) { + if (DisplayModes[i].nondx == 0) { + for (j = 0; missmodes[j * 2] >= 0; j++) { + if (DisplayModes[i].res.width == missmodes[j * 2 + 0] && DisplayModes[i].res.height == missmodes[j * 2 + 1]) { + missmodes[j * 2 + 0] = 0; + missmodes[j * 2 + 1] = 0; + } + } } - } - } - i++; - } - - i = 0; - while (DisplayModes[i].depth >= 0) { - if (DisplayModes[i].nondx) { - i++; - continue; + i++; } - j = i; - size += PSSO_LibResolution_sizeof; - while (missmodes[misscnt * 2] == 0) - misscnt++; - if (missmodes[misscnt * 2] >= 0) { - int w = DisplayModes[i].res.width; - int h = DisplayModes[i].res.height; - if (w > missmodes[misscnt * 2 + 0] || (w == missmodes[misscnt * 2 + 0] && h > missmodes[misscnt * 2 + 1])) { - struct PicassoResolution *pr = &newmodes[cnt]; - memcpy (pr, &DisplayModes[i], sizeof (struct PicassoResolution)); - pr->res.width = missmodes[misscnt * 2 + 0]; - pr->res.height = missmodes[misscnt * 2 + 1]; - _stprintf (pr->name, L"%dx%d FAKE", pr->res.width, pr->res.height); - size += PSSO_ModeInfo_sizeof * depths; + + i = 0; + while (DisplayModes[i].depth >= 0) { + if (DisplayModes[i].nondx) { + i++; + continue; + } + j = i; + size += PSSO_LibResolution_sizeof; + while (missmodes[misscnt * 2] == 0) + misscnt++; + if (missmodes[misscnt * 2] >= 0) { + int w = DisplayModes[i].res.width; + int h = DisplayModes[i].res.height; + if (w > missmodes[misscnt * 2 + 0] || (w == missmodes[misscnt * 2 + 0] && h > missmodes[misscnt * 2 + 1])) { + struct PicassoResolution *pr = &newmodes[cnt]; + memcpy (pr, &DisplayModes[i], sizeof (struct PicassoResolution)); + pr->res.width = missmodes[misscnt * 2 + 0]; + pr->res.height = missmodes[misscnt * 2 + 1]; + _stprintf (pr->name, L"%dx%d FAKE", pr->res.width, pr->res.height); + size += PSSO_ModeInfo_sizeof * depths; + cnt++; + misscnt++; + continue; + } + } + memcpy (&newmodes[cnt], &DisplayModes[i], sizeof (struct PicassoResolution)); + size += PSSO_ModeInfo_sizeof * depths; + i++; cnt++; - misscnt++; - continue; - } + while (DisplayModes[i].depth >= 0 + && DisplayModes[i].res.width == DisplayModes[j].res.width + && DisplayModes[i].res.height == DisplayModes[j].res.height) + i++; } - memcpy (&newmodes[cnt], &DisplayModes[i], sizeof (struct PicassoResolution)); - size += PSSO_ModeInfo_sizeof * depths; - i++; - cnt++; - while (DisplayModes[i].depth >= 0 - && DisplayModes[i].res.width == DisplayModes[j].res.width - && DisplayModes[i].res.height == DisplayModes[j].res.height) - i++; - } #if MULTIDISPLAY - for (i = 0; Displays[i].name; i++) { - size += PSSO_LibResolution_sizeof; - size += PSSO_ModeInfo_sizeof * depths; - } + for (i = 0; Displays[i].name; i++) { + size += PSSO_LibResolution_sizeof; + size += PSSO_ModeInfo_sizeof * depths; + } #endif - newmodes[cnt].depth = -1; - - for (i = 0; i < cnt; i++) { - int depth; - for (depth = 8; depth <= 32; depth++) { - if (!p96depth (depth)) - continue; - switch (depth) { - case 1: - if (newmodes[i].res.width > chunky.width) - chunky.width = newmodes[i].res.width; - if (newmodes[i].res.height > chunky.height) - chunky.height = newmodes[i].res.height; - break; - case 2: - if (newmodes[i].res.width > hicolour.width) - hicolour.width = newmodes[i].res.width; - if (newmodes[i].res.height > hicolour.height) - hicolour.height = newmodes[i].res.height; - break; - case 3: - if (newmodes[i].res.width > truecolour.width) - truecolour.width = newmodes[i].res.width; - if (newmodes[i].res.height > truecolour.height) - truecolour.height = newmodes[i].res.height; - break; - case 4: - if (newmodes[i].res.width > alphacolour.width) - alphacolour.width = newmodes[i].res.width; - if (newmodes[i].res.height > alphacolour.height) - alphacolour.height = newmodes[i].res.height; - break; - } + newmodes[cnt].depth = -1; + + for (i = 0; i < cnt; i++) { + int depth; + for (depth = 8; depth <= 32; depth++) { + if (!p96depth (depth)) + continue; + switch (depth) { + case 1: + if (newmodes[i].res.width > chunky.width) + chunky.width = newmodes[i].res.width; + if (newmodes[i].res.height > chunky.height) + chunky.height = newmodes[i].res.height; + break; + case 2: + if (newmodes[i].res.width > hicolour.width) + hicolour.width = newmodes[i].res.width; + if (newmodes[i].res.height > hicolour.height) + hicolour.height = newmodes[i].res.height; + break; + case 3: + if (newmodes[i].res.width > truecolour.width) + truecolour.width = newmodes[i].res.width; + if (newmodes[i].res.height > truecolour.height) + truecolour.height = newmodes[i].res.height; + break; + case 4: + if (newmodes[i].res.width > alphacolour.width) + alphacolour.width = newmodes[i].res.width; + if (newmodes[i].res.height > alphacolour.height) + alphacolour.height = newmodes[i].res.height; + break; + } + } } - } #if 0 - ShowSupportedResolutions (); + ShowSupportedResolutions (); #endif #ifdef UAEGFX_INTERNAL - uaegfx_card_install (ctx, size); - init_alloc (); + uaegfx_card_install (ctx, size); + init_alloc (); #else - m68k_dreg (regs, 0) = size; - m68k_dreg (regs, 1) = 65536 + 1; - if ((picasso96_amem = CallLib (ctx, get_long (4), -0xC6))) { /* AllocMem */ - uaecptr rt; - picasso96_amemend = picasso96_amem + size; - write_log("P96 RESINFO: %08X-%08X (%d,%d)\n", picasso96_amem, picasso96_amemend, cnt, size); - /* put magic rtarea pointer to end of display ram */ - put_long (p96ram_start + allocated_gfxmem - 12, 'UAE_'); - rt = need_uae_boot_rom (); - if (rt) - rt += 0xff60; - put_long (p96ram_start + allocated_gfxmem - 8, rt); - put_long (p96ram_start + allocated_gfxmem - 4, '_UAE'); - } + m68k_dreg (regs, 0) = size; + m68k_dreg (regs, 1) = 65536 + 1; + if ((picasso96_amem = CallLib (ctx, get_long (4), -0xC6))) { /* AllocMem */ + uaecptr rt; + picasso96_amemend = picasso96_amem + size; + write_log("P96 RESINFO: %08X-%08X (%d,%d)\n", picasso96_amem, picasso96_amemend, cnt, size); + /* put magic rtarea pointer to end of display ram */ + put_long (p96ram_start + allocated_gfxmem - 12, 'UAE_'); + rt = need_uae_boot_rom (); + if (rt) + rt += 0xff60; + put_long (p96ram_start + allocated_gfxmem - 8, rt); + put_long (p96ram_start + allocated_gfxmem - 4, '_UAE'); + } #endif } @@ -2272,173 +2272,173 @@ void picasso96_alloc (TrapContext *ctx) #ifndef UAEGFX_INTERNAL static void uaegfxversion (uaecptr bi) { - uaecptr addr = get_long (bi + 16); /* gbi_BoardName */ - int max = 1000; - int ok = 0; + uaecptr addr = get_long (bi + 16); /* gbi_BoardName */ + int max = 1000; + int ok = 0; - uaegfxcard_old = 1; + uaegfxcard_old = 1; - addr &= ~1; - for (;;) { - if (!valid_address (addr, 24) || bi == 0) { - max = 0; - break; + addr &= ~1; + for (;;) { + if (!valid_address (addr, 24) || bi == 0) { + max = 0; + break; + } + addr -= 2; + if (get_word (addr) == 0x4afc) + break; + max--; + if (max < 0) + break; } - addr -= 2; - if (get_word (addr) == 0x4afc) - break; - max--; - if (max < 0) - break; - } - if (max > 0) { - uaecptr romtagp; - romtagp = get_long (addr + 2); - if (romtagp == addr) { - uaecptr ver = get_long (addr + 18); - if (valid_address (ver, 8)) { - TCHAR *vers = my_strdup (get_real_address (ver)); - int version = get_byte (addr + 11); - while (strlen (vers) > 0 && (vers[strlen (vers) - 1] == 10 || vers[strlen (vers) - 1] == 13)) - vers[strlen (vers) - 1] = 0; - - write_log (L"P96: v%d %08X %s\n", version, addr, vers); - if (version == 1) { - static int warned; - if (!warned) - gui_message("Buggy libs:picasso96/uaegfx.card detected.\nPlease replace it with official version.\n"); - warned = 1; + if (max > 0) { + uaecptr romtagp; + romtagp = get_long (addr + 2); + if (romtagp == addr) { + uaecptr ver = get_long (addr + 18); + if (valid_address (ver, 8)) { + TCHAR *vers = my_strdup (get_real_address (ver)); + int version = get_byte (addr + 11); + while (strlen (vers) > 0 && (vers[strlen (vers) - 1] == 10 || vers[strlen (vers) - 1] == 13)) + vers[strlen (vers) - 1] = 0; + + write_log (L"P96: v%d %08X %s\n", version, addr, vers); + if (version == 1) { + static int warned; + if (!warned) + gui_message("Buggy libs:picasso96/uaegfx.card detected.\nPlease replace it with official version.\n"); + warned = 1; + } + if (version >= 2) + uaegfxcard_old = 0; + xfree (vers); + ok = 1; + } } - if (version >= 2) - uaegfxcard_old = 0; - xfree (vers); - ok = 1; - } } - } - if (!ok) - write_log (L"P96: uaegfx.card not detected!?\n"); + if (!ok) + write_log (L"P96: uaegfx.card not detected!?\n"); } #endif static uaecptr inituaegfxfuncs (uaecptr start, uaecptr ABI); static void inituaegfx (uaecptr ABI) { - uae_u32 flags; - - cursorvisible = 0; - cursorok = 0; - cursordeactivate = 0; - reloadcursor = 0; - - write_log (L"RTG mode mask: %x\n", currprefs.picasso96_modeflags); - put_word (ABI + PSSO_BoardInfo_BitsPerCannon, 8); - put_word (ABI + PSSO_BoardInfo_RGBFormats, currprefs.picasso96_modeflags); - put_long (ABI + PSSO_BoardInfo_BoardType, picasso96_BT); - put_long (ABI + PSSO_BoardInfo_GraphicsControllerType, picasso96_GCT); - put_long (ABI + PSSO_BoardInfo_PaletteChipType, picasso96_PCT); - put_long (ABI + PSSO_BoardInfo_BoardName, uaegfx_resname); - put_long (ABI + PSSO_BoardInfo_BoardType, 1); - - /* only 1 clock */ - put_long (ABI + PSSO_BoardInfo_PixelClockCount + PLANAR * 4, 1); - put_long (ABI + PSSO_BoardInfo_PixelClockCount + CHUNKY * 4, 1); - put_long (ABI + PSSO_BoardInfo_PixelClockCount + HICOLOR * 4, 1); - put_long (ABI + PSSO_BoardInfo_PixelClockCount + TRUECOLOR * 4, 1); - put_long (ABI + PSSO_BoardInfo_PixelClockCount + TRUEALPHA * 4, 1); - - /* we have 16 bits for horizontal and vertical timings - hack */ - put_word (ABI + PSSO_BoardInfo_MaxHorValue + PLANAR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxHorValue + CHUNKY * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxHorValue + HICOLOR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxHorValue + TRUECOLOR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxHorValue + TRUEALPHA * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxVerValue + PLANAR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxVerValue + CHUNKY * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxVerValue + HICOLOR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxVerValue + TRUECOLOR * 2, 0xffff); - put_word (ABI + PSSO_BoardInfo_MaxVerValue + TRUEALPHA * 2, 0xffff); - - flags = get_long (ABI + PSSO_BoardInfo_Flags); - flags &= 0xffff0000; - flags |= BIF_BLITTER | BIF_NOMEMORYMODEMIX; + uae_u32 flags; + + cursorvisible = 0; + cursorok = 0; + cursordeactivate = 0; + reloadcursor = 0; + + write_log (L"RTG mode mask: %x\n", currprefs.picasso96_modeflags); + put_word (ABI + PSSO_BoardInfo_BitsPerCannon, 8); + put_word (ABI + PSSO_BoardInfo_RGBFormats, currprefs.picasso96_modeflags); + put_long (ABI + PSSO_BoardInfo_BoardType, picasso96_BT); + put_long (ABI + PSSO_BoardInfo_GraphicsControllerType, picasso96_GCT); + put_long (ABI + PSSO_BoardInfo_PaletteChipType, picasso96_PCT); + put_long (ABI + PSSO_BoardInfo_BoardName, uaegfx_resname); + put_long (ABI + PSSO_BoardInfo_BoardType, 1); + + /* only 1 clock */ + put_long (ABI + PSSO_BoardInfo_PixelClockCount + PLANAR * 4, 1); + put_long (ABI + PSSO_BoardInfo_PixelClockCount + CHUNKY * 4, 1); + put_long (ABI + PSSO_BoardInfo_PixelClockCount + HICOLOR * 4, 1); + put_long (ABI + PSSO_BoardInfo_PixelClockCount + TRUECOLOR * 4, 1); + put_long (ABI + PSSO_BoardInfo_PixelClockCount + TRUEALPHA * 4, 1); + + /* we have 16 bits for horizontal and vertical timings - hack */ + put_word (ABI + PSSO_BoardInfo_MaxHorValue + PLANAR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxHorValue + CHUNKY * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxHorValue + HICOLOR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxHorValue + TRUECOLOR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxHorValue + TRUEALPHA * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxVerValue + PLANAR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxVerValue + CHUNKY * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxVerValue + HICOLOR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxVerValue + TRUECOLOR * 2, 0xffff); + put_word (ABI + PSSO_BoardInfo_MaxVerValue + TRUEALPHA * 2, 0xffff); + + flags = get_long (ABI + PSSO_BoardInfo_Flags); + flags &= 0xffff0000; + flags |= BIF_BLITTER | BIF_NOMEMORYMODEMIX; #ifndef UAEGFX_INTERNAL - if (flags & BIF_HARDWARESPRITE) { - hwsprite = 1; - put_word (ABI + PSSO_BoardInfo_SoftSpriteFlags, 0); - write_log (L"P96: uaegfx.card: hardware sprite support enabled\n"); - } else { - hwsprite = 0; - write_log (L"P96: uaegfx.card: no hardware sprite support\n"); - put_word (ABI + PSSO_BoardInfo_SoftSpriteFlags, currprefs.picasso96_modeflags); - } - if (uaegfxcard_old && (flags & BIF_HARDWARESPRITE)) { - flags &= ~BIF_HARDWARESPRITE; - write_log (L"P96: uaegfx.card: old version (<2.0), forced hardware sprite disabled\n"); - } - if (!(flags & BIF_BLITTER)) - write_log (L"P96: no blitter support, bogus uaegfx.card!?\n"); + if (flags & BIF_HARDWARESPRITE) { + hwsprite = 1; + put_word (ABI + PSSO_BoardInfo_SoftSpriteFlags, 0); + write_log (L"P96: uaegfx.card: hardware sprite support enabled\n"); + } else { + hwsprite = 0; + write_log (L"P96: uaegfx.card: no hardware sprite support\n"); + put_word (ABI + PSSO_BoardInfo_SoftSpriteFlags, currprefs.picasso96_modeflags); + } + if (uaegfxcard_old && (flags & BIF_HARDWARESPRITE)) { + flags &= ~BIF_HARDWARESPRITE; + write_log (L"P96: uaegfx.card: old version (<2.0), forced hardware sprite disabled\n"); + } + if (!(flags & BIF_BLITTER)) + write_log (L"P96: no blitter support, bogus uaegfx.card!?\n"); #else - hwsprite = 1; - flags |= BIF_HARDWARESPRITE; + hwsprite = 1; + flags |= BIF_HARDWARESPRITE; #endif - if (flags & BIF_NOBLITTER) - write_log (L"P96: Blitter disabled in devs:monitors/uaegfx!\n"); - - if (currprefs.win32_rtgvblankrate >= -1) - flags |= BIF_VBLANKINTERRUPT; - if (!(flags & BIF_INDISPLAYCHAIN)) { - write_log (L"P96: BIF_INDISPLAYCHAIN force-enabled!\n"); - flags |= BIF_INDISPLAYCHAIN; - } - - put_long (ABI + PSSO_BoardInfo_Flags, flags); - - put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 0, planar.width); - put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 2, chunky.width); - put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 4, hicolour.width); - put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 6, truecolour.width); - put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 8, alphacolour.width); - put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 0, planar.height); - put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 2, chunky.height); - put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 4, hicolour.height); - put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 6, truecolour.height); - put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 8, alphacolour.height); + if (flags & BIF_NOBLITTER) + write_log (L"P96: Blitter disabled in devs:monitors/uaegfx!\n"); + + if (currprefs.win32_rtgvblankrate >= -1) + flags |= BIF_VBLANKINTERRUPT; + if (!(flags & BIF_INDISPLAYCHAIN)) { + write_log (L"P96: BIF_INDISPLAYCHAIN force-enabled!\n"); + flags |= BIF_INDISPLAYCHAIN; + } + + put_long (ABI + PSSO_BoardInfo_Flags, flags); + + put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 0, planar.width); + put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 2, chunky.width); + put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 4, hicolour.width); + put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 6, truecolour.width); + put_word (ABI + PSSO_BoardInfo_MaxHorResolution + 8, alphacolour.width); + put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 0, planar.height); + put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 2, chunky.height); + put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 4, hicolour.height); + put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 6, truecolour.height); + put_word (ABI + PSSO_BoardInfo_MaxVerResolution + 8, alphacolour.height); #ifdef UAEGFX_INTERNAL - inituaegfxfuncs (uaegfx_rom, ABI); + inituaegfxfuncs (uaegfx_rom, ABI); #endif } static void addmode (uaecptr AmigaBoardInfo, uaecptr *amem, struct LibResolution *res, int w, int h, const TCHAR *name, int display, int *unkcnt) { - int depth; - - if (display > 0) { - res->DisplayID = 0x51000000 + display * 0x100000; - } else { - res->DisplayID = AssignModeID (w, h, unkcnt); - } - res->BoardInfo = AmigaBoardInfo; - res->Width = w; - res->Height = h; - res->Flags = P96F_PUBLIC; - memcpy (res->P96ID, "P96-0:", 6); - if (name) { - char *n2 = ua (name); - strcpy (res->Name, n2); - xfree (n2); - } else { - sprintf (res->Name, "UAE:%4dx%4d", w, h); - } - - for (depth = 8; depth <= 32; depth++) { - if (!p96depth (depth)) - continue; - if(allocated_gfxmem >= w * h * (depth + 7) / 8) { - FillBoardInfo (*amem, res, w, h, depth); - *amem += PSSO_ModeInfo_sizeof; + int depth; + + if (display > 0) { + res->DisplayID = 0x51000000 + display * 0x100000; + } else { + res->DisplayID = AssignModeID (w, h, unkcnt); + } + res->BoardInfo = AmigaBoardInfo; + res->Width = w; + res->Height = h; + res->Flags = P96F_PUBLIC; + memcpy (res->P96ID, "P96-0:", 6); + if (name) { + char *n2 = ua (name); + strcpy (res->Name, n2); + xfree (n2); + } else { + sprintf (res->Name, "UAE:%4dx%4d", w, h); + } + + for (depth = 8; depth <= 32; depth++) { + if (!p96depth (depth)) + continue; + if(allocated_gfxmem >= w * h * (depth + 7) / 8) { + FillBoardInfo (*amem, res, w, h, depth); + *amem += PSSO_ModeInfo_sizeof; + } } - } } /**************************************** @@ -2449,72 +2449,72 @@ static void addmode (uaecptr AmigaBoardInfo, uaecptr *amem, struct LibResolution */ static uae_u32 REGPARAM2 picasso_InitCard (TrapContext *ctx) { - int LibResolutionStructureCount = 0; - int i, j, unkcnt; - uaecptr amem; - uaecptr AmigaBoardInfo = m68k_areg (regs, 0); + int LibResolutionStructureCount = 0; + int i, j, unkcnt; + uaecptr amem; + uaecptr AmigaBoardInfo = m68k_areg (regs, 0); #ifndef UAEGFX_INTERNAL - uaegfxversion (AmigaBoardInfo); + uaegfxversion (AmigaBoardInfo); #endif - if (!picasso96_amem) { - write_log (L"P96: InitCard() but no resolution memory!\n"); - return 0; - } - amem = picasso96_amem; - - inituaegfx (AmigaBoardInfo); - - i = 0; - unkcnt = 0; - while (newmodes[i].depth >= 0) { - struct LibResolution res = { 0 }; - TCHAR *s; - j = i; - addmode (AmigaBoardInfo, &amem, &res, newmodes[i].res.width, newmodes[i].res.height, NULL, 0, &unkcnt); - s = au (res.Name); - write_log (L"%08X %4dx%4d %s\n", res.DisplayID, res.Width, res.Height, s); - xfree (s); - while (newmodes[i].depth >= 0 - && newmodes[i].res.width == newmodes[j].res.width - && newmodes[i].res.height == newmodes[j].res.height) - i++; - - LibResolutionStructureCount++; - CopyLibResolutionStructureU2A (&res, amem); + if (!picasso96_amem) { + write_log (L"P96: InitCard() but no resolution memory!\n"); + return 0; + } + amem = picasso96_amem; + + inituaegfx (AmigaBoardInfo); + + i = 0; + unkcnt = 0; + while (newmodes[i].depth >= 0) { + struct LibResolution res = { 0 }; + TCHAR *s; + j = i; + addmode (AmigaBoardInfo, &amem, &res, newmodes[i].res.width, newmodes[i].res.height, NULL, 0, &unkcnt); + s = au (res.Name); + write_log (L"%08X %4dx%4d %s\n", res.DisplayID, res.Width, res.Height, s); + xfree (s); + while (newmodes[i].depth >= 0 + && newmodes[i].res.width == newmodes[j].res.width + && newmodes[i].res.height == newmodes[j].res.height) + i++; + + LibResolutionStructureCount++; + CopyLibResolutionStructureU2A (&res, amem); #if P96TRACING_ENABLED && P96TRACING_LEVEL > 1 - DumpLibResolutionStructure(amem); + DumpLibResolutionStructure(amem); #endif - AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amem); - amem += PSSO_LibResolution_sizeof; - } + AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amem); + amem += PSSO_LibResolution_sizeof; + } #if MULTIDISPLAY - for (i = 0; Displays[i].name; i++) { - struct LibResolution res = { 0 }; - struct MultiDisplay *md = &Displays[i]; - int w = md->rect.right - md->rect.left; - int h = md->rect.bottom - md->rect.top; - TCHAR tmp[100]; - if (md->primary) - strcpy (tmp, "UAE:Primary"); - else - _stprintf (tmp, "UAE:Display#%d", i); - addmode (AmigaBoardInfo, &amem, &res, w, h, tmp, i + 1, &unkcnt); - write_log (L"%08X %4dx%4d %s\n", res.DisplayID, res.Width + 16, res.Height, res.Name); - LibResolutionStructureCount++; - CopyLibResolutionStructureU2A (&res, amem); + for (i = 0; Displays[i].name; i++) { + struct LibResolution res = { 0 }; + struct MultiDisplay *md = &Displays[i]; + int w = md->rect.right - md->rect.left; + int h = md->rect.bottom - md->rect.top; + TCHAR tmp[100]; + if (md->primary) + strcpy (tmp, "UAE:Primary"); + else + _stprintf (tmp, "UAE:Display#%d", i); + addmode (AmigaBoardInfo, &amem, &res, w, h, tmp, i + 1, &unkcnt); + write_log (L"%08X %4dx%4d %s\n", res.DisplayID, res.Width + 16, res.Height, res.Name); + LibResolutionStructureCount++; + CopyLibResolutionStructureU2A (&res, amem); #if P96TRACING_ENABLED && P96TRACING_LEVEL > 1 - DumpLibResolutionStructure(amem); + DumpLibResolutionStructure(amem); #endif - AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amem); - amem += PSSO_LibResolution_sizeof; - } + AmigaListAddTail (AmigaBoardInfo + PSSO_BoardInfo_ResolutionsList, amem); + amem += PSSO_LibResolution_sizeof; + } #endif - if (amem > picasso96_amemend) - write_log (L"P96: display resolution list corruption %08x<>%08x (%d)\n", amem, picasso96_amemend, i); + if (amem > picasso96_amemend) + write_log (L"P96: display resolution list corruption %08x<>%08x (%d)\n", amem, picasso96_amemend, i); - return -1; + return -1; } /* @@ -2531,32 +2531,32 @@ static uae_u32 REGPARAM2 picasso_InitCard (TrapContext *ctx) */ static uae_u32 REGPARAM2 picasso_SetSwitch (TrapContext *ctx) { - uae_u16 flag = m68k_dreg (regs, 0) & 0xFFFF; - TCHAR 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; - p96text[0] = 0; - if (flag) - _stprintf (p96text, L"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 (L"SetSwitch() - %s\n", flag ? p96text : L"amiga"); - /* Put old switch-state in D0 */ - return !flag; + uae_u16 flag = m68k_dreg (regs, 0) & 0xFFFF; + TCHAR 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; + p96text[0] = 0; + if (flag) + _stprintf (p96text, L"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 (L"SetSwitch() - %s\n", flag ? p96text : L"amiga"); + /* Put old switch-state in D0 */ + return !flag; } static void init_picasso_screen(void); void picasso_enablescreen (int on) { - if (!init_picasso_screen_called) - init_picasso_screen(); + if (!init_picasso_screen_called) + init_picasso_screen(); - picasso_refresh (); - checkrtglibrary(); + picasso_refresh (); + checkrtglibrary(); } /* @@ -2573,36 +2573,36 @@ void picasso_enablescreen (int on) */ static int updateclut (uaecptr clut, int start, int count) { - int i, changed = 0; - clut += start * 3; - for (i = start; i < start + count; i++) { - int r = get_byte (clut); - int g = get_byte (clut + 1); - int b = get_byte (clut + 2); - - changed |= (picasso96_state.CLUT[i].Red != r - || picasso96_state.CLUT[i].Green != g - || picasso96_state.CLUT[i].Blue != b); - - picasso96_state.CLUT[i].Red = r; - picasso96_state.CLUT[i].Green = g; - picasso96_state.CLUT[i].Blue = b; - clut += 3; - } - return changed; + int i, changed = 0; + clut += start * 3; + for (i = start; i < start + count; i++) { + int r = get_byte (clut); + int g = get_byte (clut + 1); + int b = get_byte (clut + 2); + + changed |= (picasso96_state.CLUT[i].Red != r + || picasso96_state.CLUT[i].Green != g + || picasso96_state.CLUT[i].Blue != b); + + picasso96_state.CLUT[i].Red = r; + picasso96_state.CLUT[i].Green = g; + picasso96_state.CLUT[i].Blue = b; + clut += 3; + } + return changed; } static uae_u32 REGPARAM2 picasso_SetColorArray (TrapContext *ctx) { - /* Fill in some static UAE related structure about this new CLUT setting - * We need this for CLUT-based displays, and for mapping CLUT to hi/true colour */ - uae_u16 start = m68k_dreg (regs, 0); - uae_u16 count = m68k_dreg (regs, 1); - uaecptr boardinfo = m68k_areg (regs, 0); - uaecptr clut = boardinfo + PSSO_BoardInfo_CLUT; - if (updateclut (clut, start, count)) - full_refresh = 1; - P96TRACE((L"SetColorArray(%d,%d)\n", start, count)); - return 1; + /* Fill in some static UAE related structure about this new CLUT setting + * We need this for CLUT-based displays, and for mapping CLUT to hi/true colour */ + uae_u16 start = m68k_dreg (regs, 0); + uae_u16 count = m68k_dreg (regs, 1); + uaecptr boardinfo = m68k_areg (regs, 0); + uaecptr clut = boardinfo + PSSO_BoardInfo_CLUT; + if (updateclut (clut, start, count)) + full_refresh = 1; + P96TRACE((L"SetColorArray(%d,%d)\n", start, count)); + return 1; } /* @@ -2615,33 +2615,33 @@ static uae_u32 REGPARAM2 picasso_SetColorArray (TrapContext *ctx) */ static uae_u32 REGPARAM2 picasso_SetDAC (TrapContext *ctx) { -/* Fill in some static UAE related structure about this new DAC setting - * Lets us keep track of what pixel format the Amiga is thinking about in our frame-buffer */ + /* Fill in some static UAE related structure about this new DAC setting + * Lets us keep track of what pixel format the Amiga is thinking about in our frame-buffer */ - P96TRACE((L"SetDAC()\n")); - return 1; + P96TRACE((L"SetDAC()\n")); + return 1; } static void init_picasso_screen (void) { - reloadcursor = 1; - if(set_panning_called) { - picasso96_state.Extent = picasso96_state.Address + picasso96_state.BytesPerRow * picasso96_state.VirtualHeight; - } - if (set_gc_called) { - gfx_set_picasso_modeinfo (picasso96_state.Width, picasso96_state.Height, - picasso96_state.GC_Depth, picasso96_state.RGBFormat); - set_gc_called = 0; - } - if((picasso_vidinfo.width == picasso96_state.Width) && - (picasso_vidinfo.height == picasso96_state.Height) && - (picasso_vidinfo.depth == (picasso96_state.GC_Depth >> 3)) && - (picasso_vidinfo.selected_rgbformat == picasso96_state.RGBFormat)) - { - picasso_refresh (); - } - init_picasso_screen_called = 1; - mman_ResetWatch (p96ram_start + natmem_offset, allocated_gfxmem); + reloadcursor = 1; + if(set_panning_called) { + picasso96_state.Extent = picasso96_state.Address + picasso96_state.BytesPerRow * picasso96_state.VirtualHeight; + } + if (set_gc_called) { + gfx_set_picasso_modeinfo (picasso96_state.Width, picasso96_state.Height, + picasso96_state.GC_Depth, picasso96_state.RGBFormat); + set_gc_called = 0; + } + if((picasso_vidinfo.width == picasso96_state.Width) && + (picasso_vidinfo.height == picasso96_state.Height) && + (picasso_vidinfo.depth == (picasso96_state.GC_Depth >> 3)) && + (picasso_vidinfo.selected_rgbformat == picasso96_state.RGBFormat)) + { + picasso_refresh (); + } + init_picasso_screen_called = 1; + mman_ResetWatch (p96ram_start + natmem_offset, allocated_gfxmem); } @@ -2658,29 +2658,29 @@ static void init_picasso_screen (void) */ static uae_u32 REGPARAM2 picasso_SetGC (TrapContext *ctx) { - /* Fill in some static UAE related structure about this new ModeInfo setting */ - uaecptr AmigaBoardInfo = m68k_areg (regs, 0); - uae_u32 border = m68k_dreg (regs, 0); - uaecptr modeinfo = m68k_areg (regs, 1); + /* Fill in some static UAE related structure about this new ModeInfo setting */ + uaecptr AmigaBoardInfo = m68k_areg (regs, 0); + uae_u32 border = m68k_dreg (regs, 0); + uaecptr modeinfo = m68k_areg (regs, 1); - put_long (AmigaBoardInfo + PSSO_BoardInfo_ModeInfo, modeinfo); - put_word (AmigaBoardInfo + PSSO_BoardInfo_Border, border); + put_long (AmigaBoardInfo + PSSO_BoardInfo_ModeInfo, modeinfo); + put_word (AmigaBoardInfo + PSSO_BoardInfo_Border, border); - picasso96_state.Width = get_word (modeinfo + PSSO_ModeInfo_Width); - picasso96_state.VirtualWidth = picasso96_state.Width; /* in case SetPanning doesn't get called */ + picasso96_state.Width = get_word (modeinfo + PSSO_ModeInfo_Width); + picasso96_state.VirtualWidth = picasso96_state.Width; /* in case SetPanning doesn't get called */ - picasso96_state.Height = get_word (modeinfo + PSSO_ModeInfo_Height); - picasso96_state.VirtualHeight = picasso96_state.Height; /* in case SetPanning doesn't get called */ + picasso96_state.Height = get_word (modeinfo + PSSO_ModeInfo_Height); + picasso96_state.VirtualHeight = picasso96_state.Height; /* in case SetPanning doesn't get called */ - picasso96_state.GC_Depth = get_byte (modeinfo + PSSO_ModeInfo_Depth); - picasso96_state.GC_Flags = get_byte (modeinfo + PSSO_ModeInfo_Flags); + picasso96_state.GC_Depth = get_byte (modeinfo + PSSO_ModeInfo_Depth); + picasso96_state.GC_Flags = get_byte (modeinfo + PSSO_ModeInfo_Flags); - P96TRACE((L"SetGC(%d,%d,%d,%d)\n", picasso96_state.Width, picasso96_state.Height, picasso96_state.GC_Depth, border)); - set_gc_called = 1; - picasso96_state.HostAddress = NULL; - init_picasso_screen (); - init_hz_p96 (); - return 1; + P96TRACE((L"SetGC(%d,%d,%d,%d)\n", picasso96_state.Width, picasso96_state.Height, picasso96_state.GC_Depth, border)); + set_gc_called = 1; + picasso96_state.HostAddress = NULL; + init_picasso_screen (); + init_hz_p96 (); + return 1; } /* @@ -2700,101 +2700,101 @@ static uae_u32 REGPARAM2 picasso_SetGC (TrapContext *ctx) * these values you will have to calculate the LinearStartingAddress * fields of the CRTC registers. - * NOTE: SetPanning() can be used to know when a Picasso96 screen is - * being opened. Better to do the appropriate clearing of the - * background here than in SetSwitch() derived functions, - * because SetSwitch() is not called for subsequent Picasso screens. +* NOTE: SetPanning() can be used to know when a Picasso96 screen is +* being opened. Better to do the appropriate clearing of the +* background here than in SetSwitch() derived functions, +* because SetSwitch() is not called for subsequent Picasso screens. */ static void picasso_SetPanningInit (void) { - picasso96_state.XYOffset = picasso96_state.Address + (picasso96_state.XOffset * picasso96_state.BytesPerPixel) - + (picasso96_state.YOffset * picasso96_state.BytesPerRow); - if(picasso96_state.VirtualWidth > picasso96_state.Width || picasso96_state.VirtualHeight > picasso96_state.Height) - picasso96_state.BigAssBitmap = 1; - else - picasso96_state.BigAssBitmap = 0; + picasso96_state.XYOffset = picasso96_state.Address + (picasso96_state.XOffset * picasso96_state.BytesPerPixel) + + (picasso96_state.YOffset * picasso96_state.BytesPerRow); + if(picasso96_state.VirtualWidth > picasso96_state.Width || picasso96_state.VirtualHeight > picasso96_state.Height) + picasso96_state.BigAssBitmap = 1; + else + picasso96_state.BigAssBitmap = 0; } static uae_u32 REGPARAM2 picasso_SetPanning (TrapContext *ctx) { - uae_u16 Width = m68k_dreg (regs, 0); - uaecptr start_of_screen = m68k_areg (regs, 1); - uaecptr bi = m68k_areg (regs, 0); - uaecptr bmeptr = get_long (bi + PSSO_BoardInfo_BitMapExtra); /* Get our BoardInfo ptr's BitMapExtra ptr */ - uae_u16 bme_width, bme_height; - int changed = 0; - RGBFTYPE rgbf; - - if (oldscr == 0) { - oldscr = start_of_screen; - changed = 1; - } - if (oldscr != start_of_screen) { - oldscr = start_of_screen; - changed = 1; - } - - if (changed) { + uae_u16 Width = m68k_dreg (regs, 0); + uaecptr start_of_screen = m68k_areg (regs, 1); + uaecptr bi = m68k_areg (regs, 0); + uaecptr bmeptr = get_long (bi + PSSO_BoardInfo_BitMapExtra); /* Get our BoardInfo ptr's BitMapExtra ptr */ + uae_u16 bme_width, bme_height; + int changed = 0; + RGBFTYPE rgbf; + + if (oldscr == 0) { + oldscr = start_of_screen; + changed = 1; + } + if (oldscr != start_of_screen) { + oldscr = start_of_screen; + changed = 1; + } + + if (changed) { #if P96DX > 0 - freesurface (p96surface); - p96surface = NULL; - if (picasso96_state.BytesPerPixel == picasso_vidinfo.pixbytes) - p96surface = createsurface (get_real_address (picasso96_state.Address), - picasso96_state.Width * picasso96_state.BytesPerPixel, picasso96_state.Width, picasso96_state.Height); - write_log (L"P96Surface: %08X %p\n", picasso96_state.Address, p96surface); + freesurface (p96surface); + p96surface = NULL; + if (picasso96_state.BytesPerPixel == picasso_vidinfo.pixbytes) + p96surface = createsurface (get_real_address (picasso96_state.Address), + picasso96_state.Width * picasso96_state.BytesPerPixel, picasso96_state.Width, picasso96_state.Height); + write_log (L"P96Surface: %08X %p\n", picasso96_state.Address, p96surface); #endif - } - - bme_width = get_word (bmeptr + PSSO_BitMapExtra_Width); - bme_height = get_word (bmeptr + PSSO_BitMapExtra_Height); - rgbf = picasso96_state.RGBFormat; - - picasso96_state.Address = start_of_screen; /* Amiga-side address */ - picasso96_state.XOffset = (uae_s16)(m68k_dreg (regs, 1) & 0xFFFF); - picasso96_state.YOffset = (uae_s16)(m68k_dreg (regs, 2) & 0xFFFF); - put_word (bi + PSSO_BoardInfo_XOffset, picasso96_state.XOffset); - put_word (bi + PSSO_BoardInfo_YOffset, picasso96_state.YOffset); - picasso96_state.VirtualWidth = bme_width; - picasso96_state.VirtualHeight = bme_height; - picasso96_state.RGBFormat = m68k_dreg (regs, 7); - picasso96_state.BytesPerPixel = GetBytesPerPixel (picasso96_state.RGBFormat); - picasso96_state.BytesPerRow = picasso96_state.VirtualWidth * picasso96_state.BytesPerPixel; - picasso_SetPanningInit(); - - if (rgbf != picasso96_state.RGBFormat) - gfx_set_picasso_colors (picasso96_state.RGBFormat); + } + + bme_width = get_word (bmeptr + PSSO_BitMapExtra_Width); + bme_height = get_word (bmeptr + PSSO_BitMapExtra_Height); + rgbf = picasso96_state.RGBFormat; + + picasso96_state.Address = start_of_screen; /* Amiga-side address */ + picasso96_state.XOffset = (uae_s16)(m68k_dreg (regs, 1) & 0xFFFF); + picasso96_state.YOffset = (uae_s16)(m68k_dreg (regs, 2) & 0xFFFF); + put_word (bi + PSSO_BoardInfo_XOffset, picasso96_state.XOffset); + put_word (bi + PSSO_BoardInfo_YOffset, picasso96_state.YOffset); + picasso96_state.VirtualWidth = bme_width; + picasso96_state.VirtualHeight = bme_height; + picasso96_state.RGBFormat = m68k_dreg (regs, 7); + picasso96_state.BytesPerPixel = GetBytesPerPixel (picasso96_state.RGBFormat); + picasso96_state.BytesPerRow = picasso96_state.VirtualWidth * picasso96_state.BytesPerPixel; + picasso_SetPanningInit(); + + if (rgbf != picasso96_state.RGBFormat) + gfx_set_picasso_colors (picasso96_state.RGBFormat); - full_refresh = 1; - set_panning_called = 1; - P96TRACE((L"SetPanning(%d, %d, %d) Start 0x%x, BPR %d Bpp %d RGBF %d\n", - Width, picasso96_state.XOffset, picasso96_state.YOffset, - start_of_screen, picasso96_state.BytesPerRow, picasso96_state.BytesPerPixel, picasso96_state.RGBFormat)); - init_picasso_screen (); - set_panning_called = 0; + full_refresh = 1; + set_panning_called = 1; + P96TRACE((L"SetPanning(%d, %d, %d) Start 0x%x, BPR %d Bpp %d RGBF %d\n", + Width, picasso96_state.XOffset, picasso96_state.YOffset, + start_of_screen, picasso96_state.BytesPerRow, picasso96_state.BytesPerPixel, picasso96_state.RGBFormat)); + init_picasso_screen (); + set_panning_called = 0; - return 1; + return 1; } static void do_xor8 (uae_u8 *p, int w, uae_u32 v) { - while (ALIGN_POINTER_TO32 (p) != 3 && w) { - *p ^= v; - p++; - w--; - } - while (w >= 2 * 4) { - *((uae_u32*)p) ^= v; - p += 4; - *((uae_u32*)p) ^= v; - p += 4; - w -= 2 * 4; - } - while (w) { - *p ^= v; - p++; - w--; - } + while (ALIGN_POINTER_TO32 (p) != 3 && w) { + *p ^= v; + p++; + w--; + } + while (w >= 2 * 4) { + *((uae_u32*)p) ^= v; + p += 4; + *((uae_u32*)p) ^= v; + p += 4; + w -= 2 * 4; + } + while (w) { + *p ^= v; + p++; + w--; + } } /* @@ -2815,38 +2815,38 @@ static void do_xor8 (uae_u8 *p, int w, uae_u32 v) */ static uae_u32 REGPARAM2 picasso_InvertRect (TrapContext *ctx) { - uaecptr renderinfo = m68k_areg (regs, 1); - unsigned long X = (uae_u16)m68k_dreg (regs, 0); - unsigned long Y = (uae_u16)m68k_dreg (regs, 1); - unsigned long Width = (uae_u16)m68k_dreg (regs, 2); - unsigned long Height = (uae_u16)m68k_dreg (regs, 3); - uae_u8 mask = (uae_u8)m68k_dreg (regs, 4); - int Bpp = GetBytesPerPixel (m68k_dreg (regs, 7)); - uae_u32 xorval; - unsigned int lines; - struct RenderInfo ri; - uae_u8 *uae_mem, *rectstart; - unsigned long width_in_bytes; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; - if (CopyRenderInfoStructureA2U (renderinfo, &ri)) { - P96TRACE((L"InvertRect %dbpp 0x%lx\n", Bpp, (long)mask)); + uaecptr renderinfo = m68k_areg (regs, 1); + unsigned long X = (uae_u16)m68k_dreg (regs, 0); + unsigned long Y = (uae_u16)m68k_dreg (regs, 1); + unsigned long Width = (uae_u16)m68k_dreg (regs, 2); + unsigned long Height = (uae_u16)m68k_dreg (regs, 3); + uae_u8 mask = (uae_u8)m68k_dreg (regs, 4); + int Bpp = GetBytesPerPixel (m68k_dreg (regs, 7)); + uae_u32 xorval; + unsigned int lines; + struct RenderInfo ri; + uae_u8 *uae_mem, *rectstart; + unsigned long width_in_bytes; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; + if (CopyRenderInfoStructureA2U (renderinfo, &ri)) { + P96TRACE((L"InvertRect %dbpp 0x%lx\n", Bpp, (long)mask)); - if (mask != 0xFF && Bpp > 1) - mask = 0xFF; + if (mask != 0xFF && Bpp > 1) + mask = 0xFF; - xorval = 0x01010101 * (mask & 0xFF); - width_in_bytes = Bpp * Width; - rectstart = uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; + xorval = 0x01010101 * (mask & 0xFF); + width_in_bytes = Bpp * Width; + rectstart = uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; - for (lines = 0; lines < Height; lines++, uae_mem += ri.BytesPerRow) - do_xor8 (uae_mem, width_in_bytes, xorval); - result = 1; - } + for (lines = 0; lines < Height; lines++, uae_mem += ri.BytesPerRow) + do_xor8 (uae_mem, width_in_bytes, xorval); + result = 1; + } - return result; /* 1 if supported, 0 otherwise */ + return result; /* 1 if supported, 0 otherwise */ } /*********************************************************** @@ -2864,62 +2864,62 @@ FillRect: ***********************************************************/ static uae_u32 REGPARAM2 picasso_FillRect (TrapContext *ctx) { - uaecptr renderinfo = m68k_areg (regs, 1); - uae_u32 X = (uae_u16)m68k_dreg (regs, 0); - uae_u32 Y = (uae_u16)m68k_dreg (regs, 1); - uae_u32 Width = (uae_u16)m68k_dreg (regs, 2); - uae_u32 Height = (uae_u16)m68k_dreg (regs, 3); - uae_u32 Pen = m68k_dreg (regs, 4); - uae_u8 Mask = (uae_u8)m68k_dreg (regs, 5); - RGBFTYPE RGBFormat = m68k_dreg (regs, 7); - uae_u8 *oldstart; - int Bpp; - struct RenderInfo ri; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; - if (CopyRenderInfoStructureA2U (renderinfo, &ri) && Y != 0xFFFF) { - Bpp = GetBytesPerPixel (RGBFormat); + uaecptr renderinfo = m68k_areg (regs, 1); + uae_u32 X = (uae_u16)m68k_dreg (regs, 0); + uae_u32 Y = (uae_u16)m68k_dreg (regs, 1); + uae_u32 Width = (uae_u16)m68k_dreg (regs, 2); + uae_u32 Height = (uae_u16)m68k_dreg (regs, 3); + uae_u32 Pen = m68k_dreg (regs, 4); + uae_u8 Mask = (uae_u8)m68k_dreg (regs, 5); + RGBFTYPE RGBFormat = m68k_dreg (regs, 7); + uae_u8 *oldstart; + int Bpp; + struct RenderInfo ri; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; + if (CopyRenderInfoStructureA2U (renderinfo, &ri) && Y != 0xFFFF) { + Bpp = GetBytesPerPixel (RGBFormat); - P96TRACE((L"FillRect(%d, %d, %d, %d) Pen 0x%x BPP %d BPR %d Mask 0x%x\n", - X, Y, Width, Height, Pen, Bpp, ri.BytesPerRow, Mask)); + P96TRACE((L"FillRect(%d, %d, %d, %d) Pen 0x%x BPP %d BPR %d Mask 0x%x\n", + X, Y, Width, Height, Pen, Bpp, ri.BytesPerRow, Mask)); - if(Bpp > 1) - Mask = 0xFF; + if(Bpp > 1) + Mask = 0xFF; - if (Mask == 0xFF) { + if (Mask == 0xFF) { - /* Do the fill-rect in the frame-buffer */ - do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp); - result = 1; + /* Do the fill-rect in the frame-buffer */ + do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp); + result = 1; - } else { + } else { - /* We get here only if Mask != 0xFF */ - if (Bpp != 1) { - write_log (L"WARNING - FillRect() has unhandled mask 0x%x with Bpp %d. Using fall-back routine.\n", Mask, Bpp); - } else { - Pen &= Mask; - Mask = ~Mask; - oldstart = ri.Memory + Y * ri.BytesPerRow + X * Bpp; - { - uae_u8 *start = oldstart; - uae_u8 *end = start + Height * ri.BytesPerRow; - for (; start != end; start += ri.BytesPerRow) { - uae_u8 *p = start; - unsigned long cols; - for (cols = 0; cols < Width; cols++) { - uae_u32 tmpval = do_get_mem_byte (p + cols) & Mask; - do_put_mem_byte (p + cols, (uae_u8)(Pen | tmpval)); + /* We get here only if Mask != 0xFF */ + if (Bpp != 1) { + write_log (L"WARNING - FillRect() has unhandled mask 0x%x with Bpp %d. Using fall-back routine.\n", Mask, Bpp); + } else { + Pen &= Mask; + Mask = ~Mask; + oldstart = ri.Memory + Y * ri.BytesPerRow + X * Bpp; + { + uae_u8 *start = oldstart; + uae_u8 *end = start + Height * ri.BytesPerRow; + for (; start != end; start += ri.BytesPerRow) { + uae_u8 *p = start; + unsigned long cols; + for (cols = 0; cols < Width; cols++) { + uae_u32 tmpval = do_get_mem_byte (p + cols) & Mask; + do_put_mem_byte (p + cols, (uae_u8)(Pen | tmpval)); + } + } + } + result = 1; } - } } - result = 1; - } } - } - return result; + return result; } /* @@ -2946,80 +2946,80 @@ static uae_u32 REGPARAM2 picasso_FillRect (TrapContext *ctx) */ struct blitdata { - struct RenderInfo ri_struct; - struct RenderInfo dstri_struct; - struct RenderInfo *ri; /* Self-referencing pointers */ - struct RenderInfo *dstri; - unsigned long srcx; - unsigned long srcy; - unsigned long dstx; - unsigned long dsty; - unsigned long width; - unsigned long height; - uae_u8 mask; - BLIT_OPCODE opcode; + struct RenderInfo ri_struct; + struct RenderInfo dstri_struct; + struct RenderInfo *ri; /* Self-referencing pointers */ + struct RenderInfo *dstri; + unsigned long srcx; + unsigned long srcy; + unsigned long dstx; + unsigned long dsty; + unsigned long width; + unsigned long height; + uae_u8 mask; + BLIT_OPCODE opcode; } blitrectdata; STATIC_INLINE int BlitRectHelper (void) { - struct RenderInfo *ri = blitrectdata.ri; - struct RenderInfo *dstri = blitrectdata.dstri; - unsigned long srcx = blitrectdata.srcx; - unsigned long srcy = blitrectdata.srcy; - unsigned long dstx = blitrectdata.dstx; - unsigned long dsty = blitrectdata.dsty; - unsigned long width = blitrectdata.width; - unsigned long height = blitrectdata.height; - uae_u8 mask = blitrectdata.mask; - BLIT_OPCODE opcode = blitrectdata.opcode; - - uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat); - - if (opcode == BLIT_DST) { - write_log ( L"WARNING: BlitRect() being called with opcode of BLIT_DST\n" ); - return 1; - } - - /* - * If we have no destination RenderInfo, then we're dealing with a single-buffer action, called - * from picasso_BlitRect(). The code in do_blitrect_frame_buffer() deals with the frame-buffer, - * while the do_blit() code deals with the visible screen. - * - * If we have a destination RenderInfo, then we've been called from picasso_BlitRectNoMaskComplete() - * and we need to put the results on the screen from the frame-buffer. - */ - if (dstri == NULL || dstri->Memory == ri->Memory) { - if (mask != 0xFF && Bpp > 1) - mask = 0xFF; - dstri = ri; - } - /* Do our virtual frame-buffer memory first */ - return do_blitrect_frame_buffer (ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode); + struct RenderInfo *ri = blitrectdata.ri; + struct RenderInfo *dstri = blitrectdata.dstri; + unsigned long srcx = blitrectdata.srcx; + unsigned long srcy = blitrectdata.srcy; + unsigned long dstx = blitrectdata.dstx; + unsigned long dsty = blitrectdata.dsty; + unsigned long width = blitrectdata.width; + unsigned long height = blitrectdata.height; + uae_u8 mask = blitrectdata.mask; + BLIT_OPCODE opcode = blitrectdata.opcode; + + uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat); + + if (opcode == BLIT_DST) { + write_log ( L"WARNING: BlitRect() being called with opcode of BLIT_DST\n" ); + return 1; + } + + /* + * If we have no destination RenderInfo, then we're dealing with a single-buffer action, called + * from picasso_BlitRect(). The code in do_blitrect_frame_buffer() deals with the frame-buffer, + * while the do_blit() code deals with the visible screen. + * + * If we have a destination RenderInfo, then we've been called from picasso_BlitRectNoMaskComplete() + * and we need to put the results on the screen from the frame-buffer. + */ + if (dstri == NULL || dstri->Memory == ri->Memory) { + if (mask != 0xFF && Bpp > 1) + mask = 0xFF; + dstri = ri; + } + /* Do our virtual frame-buffer memory first */ + return do_blitrect_frame_buffer (ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode); } STATIC_INLINE int BlitRect (uaecptr ri, uaecptr dstri, - unsigned long srcx, unsigned long srcy, unsigned long dstx, unsigned long dsty, - unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode) + unsigned long srcx, unsigned long srcy, unsigned long dstx, unsigned long dsty, + unsigned long width, unsigned long height, uae_u8 mask, BLIT_OPCODE opcode) { - /* Set up the params */ - CopyRenderInfoStructureA2U(ri, &blitrectdata.ri_struct); - blitrectdata.ri = &blitrectdata.ri_struct; - if(dstri) { - CopyRenderInfoStructureA2U(dstri, &blitrectdata.dstri_struct); - blitrectdata.dstri = &blitrectdata.dstri_struct; - } else { - blitrectdata.dstri = NULL; - } - blitrectdata.srcx = srcx; - blitrectdata.srcy = srcy; - blitrectdata.dstx = dstx; - blitrectdata.dsty = dsty; - blitrectdata.width = width; - blitrectdata.height = height; - blitrectdata.mask = mask; - blitrectdata.opcode = opcode; - - return BlitRectHelper (); + /* Set up the params */ + CopyRenderInfoStructureA2U(ri, &blitrectdata.ri_struct); + blitrectdata.ri = &blitrectdata.ri_struct; + if(dstri) { + CopyRenderInfoStructureA2U(dstri, &blitrectdata.dstri_struct); + blitrectdata.dstri = &blitrectdata.dstri_struct; + } else { + blitrectdata.dstri = NULL; + } + blitrectdata.srcx = srcx; + blitrectdata.srcy = srcy; + blitrectdata.dstx = dstx; + blitrectdata.dsty = dsty; + blitrectdata.width = width; + blitrectdata.height = height; + blitrectdata.mask = mask; + blitrectdata.opcode = opcode; + + return BlitRectHelper (); } /*********************************************************** @@ -3038,21 +3038,21 @@ BlitRect: ***********************************************************/ static uae_u32 REGPARAM2 picasso_BlitRect (TrapContext *ctx) { - uaecptr renderinfo = m68k_areg (regs, 1); - unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); - unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); - unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); - unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); - unsigned long width = (uae_u16)m68k_dreg (regs, 4); - unsigned long height = (uae_u16)m68k_dreg (regs, 5); - uae_u8 Mask = (uae_u8)m68k_dreg (regs, 6); - uae_u32 result = 0; - - if (NOBLITTER_BLIT) - return 0; - P96TRACE((L"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); - return result; + uaecptr renderinfo = m68k_areg (regs, 1); + unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); + unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); + unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); + unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); + unsigned long width = (uae_u16)m68k_dreg (regs, 4); + unsigned long height = (uae_u16)m68k_dreg (regs, 5); + uae_u8 Mask = (uae_u8)m68k_dreg (regs, 6); + uae_u32 result = 0; + + if (NOBLITTER_BLIT) + return 0; + P96TRACE((L"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); + return result; } /*********************************************************** @@ -3075,49 +3075,49 @@ BlitRectNoMaskComplete: ***********************************************************/ static uae_u32 REGPARAM2 picasso_BlitRectNoMaskComplete (TrapContext *ctx) { - uaecptr srcri = m68k_areg (regs, 1); - uaecptr dstri = m68k_areg (regs, 2); - unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); - unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); - unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); - unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); - unsigned long width = (uae_u16)m68k_dreg (regs, 4); - unsigned long height = (uae_u16)m68k_dreg (regs, 5); - uae_u8 OpCode = m68k_dreg (regs, 6); - uae_u32 RGBFmt = m68k_dreg (regs, 7); - uae_u32 result = 0; - - if (NOBLITTER_BLIT) - return 0; + uaecptr srcri = m68k_areg (regs, 1); + uaecptr dstri = m68k_areg (regs, 2); + unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); + unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); + unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); + unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); + unsigned long width = (uae_u16)m68k_dreg (regs, 4); + unsigned long height = (uae_u16)m68k_dreg (regs, 5); + uae_u8 OpCode = m68k_dreg (regs, 6); + uae_u32 RGBFmt = m68k_dreg (regs, 7); + uae_u32 result = 0; + + if (NOBLITTER_BLIT) + return 0; - P96TRACE((L"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)); - result = BlitRect (srcri, dstri, srcx, srcy, dstx, dsty, width, height, 0xFF, OpCode); - return result; + P96TRACE((L"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)); + result = BlitRect (srcri, dstri, srcx, srcy, dstx, dsty, width, height, 0xFF, OpCode); + return result; } /* NOTE: fgpen MUST be in host byte order */ STATIC_INLINE void PixelWrite (uae_u8 *mem, int bits, uae_u32 fgpen, int Bpp, uae_u32 mask) { - switch (Bpp) - { + switch (Bpp) + { case 1: - if (mask != 0xFF) - fgpen = (fgpen & mask) | (mem[bits] & ~mask); - mem[bits] = (uae_u8)fgpen; - break; + if (mask != 0xFF) + fgpen = (fgpen & mask) | (mem[bits] & ~mask); + mem[bits] = (uae_u8)fgpen; + break; case 2: - ((uae_u16 *)mem)[bits] = (uae_u16)fgpen; - break; + ((uae_u16 *)mem)[bits] = (uae_u16)fgpen; + break; case 3: - mem[bits * 3 + 0] = fgpen >> 0; - mem[bits * 3 + 1] = fgpen >> 8; - mem[bits * 3 + 2] = fgpen >> 16; - break; + mem[bits * 3 + 0] = fgpen >> 0; + mem[bits * 3 + 1] = fgpen >> 8; + mem[bits * 3 + 2] = fgpen >> 16; + break; case 4: - ((uae_u32 *)mem)[bits] = fgpen; - break; - } + ((uae_u32 *)mem)[bits] = fgpen; + break; + } } /* @@ -3144,145 +3144,145 @@ STATIC_INLINE void PixelWrite (uae_u8 *mem, int bits, uae_u32 fgpen, int Bpp, ua */ static uae_u32 REGPARAM2 picasso_BlitPattern (TrapContext *ctx) { - uaecptr rinf = m68k_areg (regs, 1); - uaecptr pinf = m68k_areg (regs, 2); - unsigned long X = (uae_u16)m68k_dreg (regs, 0); - unsigned long Y = (uae_u16)m68k_dreg (regs, 1); - unsigned long W = (uae_u16)m68k_dreg (regs, 2); - unsigned long H = (uae_u16)m68k_dreg (regs, 3); - uae_u8 Mask = (uae_u8)m68k_dreg (regs, 4); - uae_u32 RGBFmt = m68k_dreg (regs, 7); - uae_u8 Bpp = GetBytesPerPixel (RGBFmt); - int inversion = 0; - struct RenderInfo ri; - struct Pattern pattern; - unsigned long rows; - uae_u8 *uae_mem; - int xshift; - unsigned long ysize_mask; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; + uaecptr rinf = m68k_areg (regs, 1); + uaecptr pinf = m68k_areg (regs, 2); + unsigned long X = (uae_u16)m68k_dreg (regs, 0); + unsigned long Y = (uae_u16)m68k_dreg (regs, 1); + unsigned long W = (uae_u16)m68k_dreg (regs, 2); + unsigned long H = (uae_u16)m68k_dreg (regs, 3); + uae_u8 Mask = (uae_u8)m68k_dreg (regs, 4); + uae_u32 RGBFmt = m68k_dreg (regs, 7); + uae_u8 Bpp = GetBytesPerPixel (RGBFmt); + int inversion = 0; + struct RenderInfo ri; + struct Pattern pattern; + unsigned long rows; + uae_u8 *uae_mem; + int xshift; + unsigned long ysize_mask; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; - if(CopyRenderInfoStructureA2U (rinf, &ri) && CopyPatternStructureA2U (pinf, &pattern)) { - Bpp = GetBytesPerPixel(ri.RGBFormat); - uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset with address */ + if(CopyRenderInfoStructureA2U (rinf, &ri) && CopyPatternStructureA2U (pinf, &pattern)) { + Bpp = GetBytesPerPixel(ri.RGBFormat); + uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset with address */ - if (pattern.DrawMode & INVERS) - inversion = 1; + if (pattern.DrawMode & INVERS) + inversion = 1; - pattern.DrawMode &= 0x03; - if (Mask != 0xFF) { - if(Bpp > 1) - Mask = 0xFF; - result = 1; - } else { - result = 1; - } + pattern.DrawMode &= 0x03; + if (Mask != 0xFF) { + if(Bpp > 1) + Mask = 0xFF; + result = 1; + } else { + result = 1; + } - if(result) { - uae_u32 fgpen, bgpen; - P96TRACE((L"BlitPattern() xy(%d,%d), wh(%d,%d) draw 0x%x, off(%d,%d), ph %d\n", - X, Y, W, H, pattern.DrawMode, pattern.XOffset, pattern.YOffset, 1 << pattern.Size)); + if(result) { + uae_u32 fgpen, bgpen; + P96TRACE((L"BlitPattern() xy(%d,%d), wh(%d,%d) draw 0x%x, off(%d,%d), ph %d\n", + X, Y, W, H, pattern.DrawMode, pattern.XOffset, pattern.YOffset, 1 << pattern.Size)); #if P96TRACING_ENABLED - DumpPattern(&pattern); + DumpPattern(&pattern); #endif - ysize_mask = (1 << pattern.Size) - 1; - xshift = pattern.XOffset & 15; - - fgpen = pattern.FgPen; - endianswap (&fgpen, Bpp); - bgpen = pattern.BgPen; - endianswap (&bgpen, Bpp); - - for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow) { - unsigned long prow = (rows + pattern.YOffset) & ysize_mask; - unsigned int d = do_get_mem_word (((uae_u16 *)pattern.Memory) + prow); - uae_u8 *uae_mem2 = uae_mem; - unsigned long cols; + ysize_mask = (1 << pattern.Size) - 1; + xshift = pattern.XOffset & 15; - if (xshift != 0) - d = (d << xshift) | (d >> (16 - xshift)); + fgpen = pattern.FgPen; + endianswap (&fgpen, Bpp); + bgpen = pattern.BgPen; + endianswap (&bgpen, Bpp); - for (cols = 0; cols < W; cols += 16, uae_mem2 += Bpp * 16) { - long bits; - long max = W - cols; - unsigned int data = d; + for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow) { + unsigned long prow = (rows + pattern.YOffset) & ysize_mask; + unsigned int d = do_get_mem_word (((uae_u16 *)pattern.Memory) + prow); + uae_u8 *uae_mem2 = uae_mem; + unsigned long cols; - if (max > 16) - max = 16; + if (xshift != 0) + d = (d << xshift) | (d >> (16 - xshift)); - switch (pattern.DrawMode) - { - case JAM1: - { - for (bits = 0; bits < max; bits++) { - int bit_set = data & 0x8000; - data <<= 1; - if (inversion) - bit_set = !bit_set; - if (bit_set) - PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask); - } - break; - } - case JAM2: - { - for (bits = 0; bits < max; bits++) { - int bit_set = data & 0x8000; - data <<= 1; - if (inversion) - bit_set = !bit_set; - PixelWrite (uae_mem2, bits, bit_set ? fgpen : bgpen, Bpp, Mask); - } - break; - } - case COMP: - { - for (bits = 0; bits < max; bits++) { - int bit_set = data & 0x8000; - data <<= 1; - if (bit_set) { - switch (Bpp) - { - case 1: - { - uae_mem2[bits] ^= 0xff & Mask; - } - break; - case 2: - { - uae_u16 *addr = (uae_u16 *)uae_mem2; - addr[bits] ^= 0xffff; - } - break; - case 3: - { - uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); - do_put_mem_long (addr, do_get_mem_long (addr) ^ 0x00ffffff); - } - break; - case 4: + for (cols = 0; cols < W; cols += 16, uae_mem2 += Bpp * 16) { + long bits; + long max = W - cols; + unsigned int data = d; + + if (max > 16) + max = 16; + + switch (pattern.DrawMode) { - uae_u32 *addr = (uae_u32 *)uae_mem2; - addr[bits] ^= 0xffffffff; + case JAM1: + { + for (bits = 0; bits < max; bits++) { + int bit_set = data & 0x8000; + data <<= 1; + if (inversion) + bit_set = !bit_set; + if (bit_set) + PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask); + } + break; + } + case JAM2: + { + for (bits = 0; bits < max; bits++) { + int bit_set = data & 0x8000; + data <<= 1; + if (inversion) + bit_set = !bit_set; + PixelWrite (uae_mem2, bits, bit_set ? fgpen : bgpen, Bpp, Mask); + } + break; + } + case COMP: + { + for (bits = 0; bits < max; bits++) { + int bit_set = data & 0x8000; + data <<= 1; + if (bit_set) { + switch (Bpp) + { + case 1: + { + uae_mem2[bits] ^= 0xff & Mask; + } + break; + case 2: + { + uae_u16 *addr = (uae_u16 *)uae_mem2; + addr[bits] ^= 0xffff; + } + break; + case 3: + { + uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); + do_put_mem_long (addr, do_get_mem_long (addr) ^ 0x00ffffff); + } + break; + case 4: + { + uae_u32 *addr = (uae_u32 *)uae_mem2; + addr[bits] ^= 0xffffffff; + } + break; + } + } + } + break; + } } - break; - } } - } - break; } - } + result = 1; } - } - result = 1; } - } - return result; + return result; } /************************************************* @@ -3306,155 +3306,155 @@ BlitTemplate: ***********************************************************************************/ static uae_u32 REGPARAM2 picasso_BlitTemplate (TrapContext *ctx) { - uae_u8 inversion = 0; - uaecptr rinf = m68k_areg (regs, 1); - uaecptr tmpl = m68k_areg (regs, 2); - unsigned long X = (uae_u16)m68k_dreg (regs, 0); - unsigned long Y = (uae_u16)m68k_dreg (regs, 1); - unsigned long W = (uae_u16)m68k_dreg (regs, 2); - unsigned long H = (uae_u16)m68k_dreg (regs, 3); - uae_u16 Mask = (uae_u16)m68k_dreg (regs, 4); - struct Template tmp; - struct RenderInfo ri; - unsigned long rows; - int bitoffset; - uae_u8 *uae_mem, Bpp; - uae_u8 *tmpl_base; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; + uae_u8 inversion = 0; + uaecptr rinf = m68k_areg (regs, 1); + uaecptr tmpl = m68k_areg (regs, 2); + unsigned long X = (uae_u16)m68k_dreg (regs, 0); + unsigned long Y = (uae_u16)m68k_dreg (regs, 1); + unsigned long W = (uae_u16)m68k_dreg (regs, 2); + unsigned long H = (uae_u16)m68k_dreg (regs, 3); + uae_u16 Mask = (uae_u16)m68k_dreg (regs, 4); + struct Template tmp; + struct RenderInfo ri; + unsigned long rows; + int bitoffset; + uae_u8 *uae_mem, Bpp; + uae_u8 *tmpl_base; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; - if (CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp)) { - Bpp = GetBytesPerPixel (ri.RGBFormat); - uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset into address */ + if (CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp)) { + Bpp = GetBytesPerPixel (ri.RGBFormat); + uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset into address */ - if (tmp.DrawMode & INVERS) - inversion = 1; + if (tmp.DrawMode & INVERS) + inversion = 1; - tmp.DrawMode &= 0x03; + tmp.DrawMode &= 0x03; - if (Mask != 0xFF) { - if(Bpp > 1) - Mask = 0xFF; - if(tmp.DrawMode == COMP) { - write_log (L"WARNING - BlitTemplate() has unhandled mask 0x%x with COMP DrawMode. Using fall-back routine.\n", Mask); - return 0; - } else { - result = 1; - } - } else { - result = 1; - } + if (Mask != 0xFF) { + if(Bpp > 1) + Mask = 0xFF; + if(tmp.DrawMode == COMP) { + write_log (L"WARNING - BlitTemplate() has unhandled mask 0x%x with COMP DrawMode. Using fall-back routine.\n", Mask); + return 0; + } else { + result = 1; + } + } else { + result = 1; + } - if(result) { - uae_u32 fgpen, bgpen; + if(result) { + uae_u32 fgpen, bgpen; - P96TRACE((L"BlitTemplate() xy(%d,%d), wh(%d,%d) draw 0x%x fg 0x%x bg 0x%x \n", - X, Y, W, H, tmp.DrawMode, tmp.FgPen, tmp.BgPen)); + P96TRACE((L"BlitTemplate() xy(%d,%d), wh(%d,%d) draw 0x%x fg 0x%x bg 0x%x \n", + X, Y, W, H, tmp.DrawMode, tmp.FgPen, tmp.BgPen)); - bitoffset = tmp.XOffset % 8; + bitoffset = tmp.XOffset % 8; #if P96TRACING_ENABLED && P96TRACING_LEVEL > 0 - DumpTemplate(&tmp, W, H); + DumpTemplate(&tmp, W, H); #endif - tmpl_base = tmp.Memory + tmp.XOffset / 8; + tmpl_base = tmp.Memory + tmp.XOffset / 8; - fgpen = tmp.FgPen; - endianswap (&fgpen, Bpp); - bgpen = tmp.BgPen; - endianswap (&bgpen, Bpp); + fgpen = tmp.FgPen; + endianswap (&fgpen, Bpp); + bgpen = tmp.BgPen; + endianswap (&bgpen, Bpp); - for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow, tmpl_base += tmp.BytesPerRow) { - unsigned long cols; - uae_u8 *tmpl_mem = tmpl_base; - uae_u8 *uae_mem2 = uae_mem; - unsigned int data = *tmpl_mem; + for (rows = 0; rows < H; rows++, uae_mem += ri.BytesPerRow, tmpl_base += tmp.BytesPerRow) { + unsigned long cols; + uae_u8 *tmpl_mem = tmpl_base; + uae_u8 *uae_mem2 = uae_mem; + unsigned int data = *tmpl_mem; - for (cols = 0; cols < W; cols += 8, uae_mem2 += Bpp * 8) { - unsigned int byte; - long bits; - long max = W - cols; + for (cols = 0; cols < W; cols += 8, uae_mem2 += Bpp * 8) { + unsigned int byte; + long bits; + long max = W - cols; - if (max > 8) - max = 8; + if (max > 8) + max = 8; - data <<= 8; - data |= *++tmpl_mem; + data <<= 8; + data |= *++tmpl_mem; - byte = data >> (8 - bitoffset); + byte = data >> (8 - bitoffset); - switch (tmp.DrawMode) - { - case JAM1: - { - for (bits = 0; bits < max; bits++) { - int bit_set = (byte & 0x80); - byte <<= 1; - if (inversion) - bit_set = !bit_set; - if (bit_set) - PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask); - } - break; - } - case JAM2: - { - for (bits = 0; bits < max; bits++) { - int bit_set = (byte & 0x80); - byte <<= 1; - if (inversion) - bit_set = !bit_set; - PixelWrite (uae_mem2, bits, bit_set ? fgpen : bgpen, Bpp, Mask); - } - break; - } - case COMP: - { - for (bits = 0; bits < max; bits++) { - int bit_set = (byte & 0x80); - byte <<= 1; - if (bit_set) { - switch (Bpp) - { - case 1: - { - uae_u8 *addr = uae_mem2; - addr[bits] ^= 0xff; - } - break; - case 2: - { - uae_u16 *addr = (uae_u16 *)uae_mem2; - addr[bits] ^= 0xffff; - } - break; - case 3: - { - uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); - do_put_mem_long (addr, do_get_mem_long (addr) ^ 0x00FFFFFF); - } - break; - case 4: + switch (tmp.DrawMode) { - uae_u32 *addr = (uae_u32 *)uae_mem2; - addr[bits] ^= 0xffffffff; + case JAM1: + { + for (bits = 0; bits < max; bits++) { + int bit_set = (byte & 0x80); + byte <<= 1; + if (inversion) + bit_set = !bit_set; + if (bit_set) + PixelWrite (uae_mem2, bits, fgpen, Bpp, Mask); + } + break; + } + case JAM2: + { + for (bits = 0; bits < max; bits++) { + int bit_set = (byte & 0x80); + byte <<= 1; + if (inversion) + bit_set = !bit_set; + PixelWrite (uae_mem2, bits, bit_set ? fgpen : bgpen, Bpp, Mask); + } + break; + } + case COMP: + { + for (bits = 0; bits < max; bits++) { + int bit_set = (byte & 0x80); + byte <<= 1; + if (bit_set) { + switch (Bpp) + { + case 1: + { + uae_u8 *addr = uae_mem2; + addr[bits] ^= 0xff; + } + break; + case 2: + { + uae_u16 *addr = (uae_u16 *)uae_mem2; + addr[bits] ^= 0xffff; + } + break; + case 3: + { + uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); + do_put_mem_long (addr, do_get_mem_long (addr) ^ 0x00FFFFFF); + } + break; + case 4: + { + uae_u32 *addr = (uae_u32 *)uae_mem2; + addr[bits] ^= 0xffffffff; + } + break; + } + } + } + break; + } } - break; - } } - } - break; } - } + result = 1; } - } - result = 1; } - } - return 1; + return 1; } /* @@ -3467,10 +3467,10 @@ static uae_u32 REGPARAM2 picasso_BlitTemplate (TrapContext *ctx) */ static uae_u32 REGPARAM2 picasso_CalculateBytesPerRow (TrapContext *ctx) { - uae_u16 width = m68k_dreg (regs, 0); - uae_u32 type = m68k_dreg (regs, 7); - width = GetBytesPerPixel (type) * width; - return width; + uae_u16 width = m68k_dreg (regs, 0); + uae_u32 type = m68k_dreg (regs, 7); + width = GetBytesPerPixel (type) * width; + return width; } /* @@ -3483,120 +3483,120 @@ static uae_u32 REGPARAM2 picasso_CalculateBytesPerRow (TrapContext *ctx) */ static uae_u32 REGPARAM2 picasso_SetDisplay (TrapContext *ctx) { - uae_u32 state = m68k_dreg (regs, 0); - P96TRACE ((L"SetDisplay(%d)\n", state)); - return !state; + uae_u32 state = m68k_dreg (regs, 0); + P96TRACE ((L"SetDisplay(%d)\n", state)); + return !state; } void picasso_handle_hsync (void) { - static int p96hsync; - - if (currprefs.gfxmem_size == 0) - return; - if (currprefs.win32_rtgvblankrate == 0 && !isvsync ()) - return; - if (WIN32GFX_IsPicassoScreen () && isvsync ()) { - int vbs = DirectDraw_GetVerticalBlankStatus (); - if (vbs == 0) { - if (p96hsync > 0) - p96hsync = -1; - return; - } else { - if (p96hsync >= 0) + static int p96hsync; + + if (currprefs.gfxmem_size == 0) return; - p96hsync = 0; + if (currprefs.win32_rtgvblankrate == 0 && !isvsync ()) + return; + if (WIN32GFX_IsPicassoScreen () && isvsync ()) { + int vbs = DirectDraw_GetVerticalBlankStatus (); + if (vbs == 0) { + if (p96hsync > 0) + p96hsync = -1; + return; + } else { + if (p96hsync >= 0) + return; + p96hsync = 0; + } + } else { + p96hsync--; + } + if (p96hsync <= 0) { + picasso_trigger_vblank (); + p96hsync = p96syncrate; } - } else { - p96hsync--; - } - if (p96hsync <= 0) { - picasso_trigger_vblank (); - p96hsync = p96syncrate; - } } void init_hz_p96 (void) { - if (currprefs.win32_rtgvblankrate < 0 || isvsync ()) - p96vblank = DirectDraw_CurrentRefreshRate (); - else if (currprefs.win32_rtgvblankrate == 0) - p96vblank = vblank_hz; - else - p96vblank = currprefs.win32_rtgvblankrate; - if (p96vblank <= 0) - p96vblank = 60; - if (p96vblank >= 300) - p96vblank = 300; - p96syncrate = maxvpos * vblank_hz / p96vblank; - write_log (L"P96FREQ: %d*%d = %d / %d = %d\n", maxvpos, vblank_hz, maxvpos * vblank_hz, p96vblank, p96syncrate); + if (currprefs.win32_rtgvblankrate < 0 || isvsync ()) + p96vblank = DirectDraw_CurrentRefreshRate (); + else if (currprefs.win32_rtgvblankrate == 0) + p96vblank = vblank_hz; + else + p96vblank = currprefs.win32_rtgvblankrate; + if (p96vblank <= 0) + p96vblank = 60; + if (p96vblank >= 300) + p96vblank = 300; + p96syncrate = maxvpos * vblank_hz / p96vblank; + write_log (L"P96FREQ: %d*%d = %d / %d = %d\n", maxvpos, vblank_hz, maxvpos * vblank_hz, p96vblank, p96syncrate); } /* NOTE: Watch for those planeptrs of 0x00000000 and 0xFFFFFFFF for all zero / all one bitmaps !!!! */ static void PlanarToChunky (struct RenderInfo *ri, struct BitMap *bm, - unsigned long srcx, unsigned long srcy, - unsigned long dstx, unsigned long dsty, - unsigned long width, unsigned long height, - uae_u8 mask) + unsigned long srcx, unsigned long srcy, + unsigned long dstx, unsigned long dsty, + unsigned long width, unsigned long height, + uae_u8 mask) { - int j; - - uae_u8 *PLANAR[8], *image = ri->Memory + dstx * GetBytesPerPixel (ri->RGBFormat) + dsty * ri->BytesPerRow; - int Depth = bm->Depth; - unsigned long rows, bitoffset = srcx & 7; - long eol_offset; - - /* Set up our bm->Planes[] pointers to the right horizontal offset */ - for (j = 0; j < Depth; j++) { - uae_u8 *p = bm->Planes[j]; - if (p != &all_zeros_bitmap && p != &all_ones_bitmap) - p += srcx / 8 + srcy * bm->BytesPerRow; - PLANAR[j] = p; - if ((mask & (1 << j)) == 0) - PLANAR[j] = &all_zeros_bitmap; - } - eol_offset = (long)bm->BytesPerRow - (long)((width + 7) >> 3); - for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) { - unsigned long cols; - - for (cols = 0; cols < width; cols += 8) { - int k; - uae_u32 a = 0, b = 0; - unsigned int msk = 0xFF; - long tmp = cols + 8 - width; - if (tmp > 0) { - msk <<= tmp; - b = do_get_mem_long ((uae_u32 *)(image + cols + 4)); - if (tmp < 4) - b &= 0xFFFFFFFF >> (32 - tmp * 8); - else if (tmp > 4) { - a = do_get_mem_long ((uae_u32 *)(image + cols)); - a &= 0xFFFFFFFF >> (64 - tmp * 8); + int j; + + uae_u8 *PLANAR[8], *image = ri->Memory + dstx * GetBytesPerPixel (ri->RGBFormat) + dsty * ri->BytesPerRow; + int Depth = bm->Depth; + unsigned long rows, bitoffset = srcx & 7; + long eol_offset; + + /* Set up our bm->Planes[] pointers to the right horizontal offset */ + for (j = 0; j < Depth; j++) { + uae_u8 *p = bm->Planes[j]; + if (p != &all_zeros_bitmap && p != &all_ones_bitmap) + p += srcx / 8 + srcy * bm->BytesPerRow; + PLANAR[j] = p; + if ((mask & (1 << j)) == 0) + PLANAR[j] = &all_zeros_bitmap; + } + eol_offset = (long)bm->BytesPerRow - (long)((width + 7) >> 3); + for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) { + unsigned long cols; + + for (cols = 0; cols < width; cols += 8) { + int k; + uae_u32 a = 0, b = 0; + unsigned int msk = 0xFF; + long tmp = cols + 8 - width; + if (tmp > 0) { + msk <<= tmp; + b = do_get_mem_long ((uae_u32 *)(image + cols + 4)); + if (tmp < 4) + b &= 0xFFFFFFFF >> (32 - tmp * 8); + else if (tmp > 4) { + a = do_get_mem_long ((uae_u32 *)(image + cols)); + a &= 0xFFFFFFFF >> (64 - tmp * 8); + } + } + for (k = 0; k < Depth; k++) { + unsigned int data; + if (PLANAR[k] == &all_zeros_bitmap) + data = 0; + else if (PLANAR[k] == &all_ones_bitmap) + data = 0xFF; + else { + data = (uae_u8)(do_get_mem_word ((uae_u16 *)PLANAR[k]) >> (8 - bitoffset)); + PLANAR[k]++; + } + data &= msk; + a |= p2ctab[data][0] << k; + b |= p2ctab[data][1] << k; + } + do_put_mem_long ((uae_u32 *)(image + cols), a); + do_put_mem_long ((uae_u32 *)(image + cols + 4), b); } - } - for (k = 0; k < Depth; k++) { - unsigned int data; - if (PLANAR[k] == &all_zeros_bitmap) - data = 0; - else if (PLANAR[k] == &all_ones_bitmap) - data = 0xFF; - else { - data = (uae_u8)(do_get_mem_word ((uae_u16 *)PLANAR[k]) >> (8 - bitoffset)); - PLANAR[k]++; + for (j = 0; j < Depth; j++) { + if (PLANAR[j] != &all_zeros_bitmap && PLANAR[j] != &all_ones_bitmap) { + PLANAR[j] += eol_offset; + } } - data &= msk; - a |= p2ctab[data][0] << k; - b |= p2ctab[data][1] << k; - } - do_put_mem_long ((uae_u32 *)(image + cols), a); - do_put_mem_long ((uae_u32 *)(image + cols + 4), b); - } - for (j = 0; j < Depth; j++) { - if (PLANAR[j] != &all_zeros_bitmap && PLANAR[j] != &all_ones_bitmap) { - PLANAR[j] += eol_offset; - } } - } } /* @@ -3619,114 +3619,114 @@ static void PlanarToChunky (struct RenderInfo *ri, struct BitMap *bm, */ static uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (TrapContext *ctx) { - uaecptr bm = m68k_areg (regs, 1); - uaecptr ri = m68k_areg (regs, 2); - unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); - unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); - unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); - unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); - unsigned long width = (uae_u16)m68k_dreg (regs, 4); - unsigned long height = (uae_u16)m68k_dreg (regs, 5); - uae_u8 minterm = m68k_dreg (regs, 6) & 0xFF; - uae_u8 mask = m68k_dreg (regs, 7) & 0xFF; - struct RenderInfo local_ri; - struct BitMap local_bm; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; - if (minterm != 0x0C) { - write_log (L"ERROR - BlitPlanar2Chunky() has minterm 0x%x, which I don't handle. Using fall-back routine.\n", - minterm); - } else if (CopyRenderInfoStructureA2U (ri, &local_ri) && CopyBitMapStructureA2U (bm, &local_bm)) { - P96TRACE((L"BlitPlanar2Chunky(%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)); - P96TRACE((L"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); - result = 1; - } - return result; + uaecptr bm = m68k_areg (regs, 1); + uaecptr ri = m68k_areg (regs, 2); + unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); + unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); + unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); + unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); + unsigned long width = (uae_u16)m68k_dreg (regs, 4); + unsigned long height = (uae_u16)m68k_dreg (regs, 5); + uae_u8 minterm = m68k_dreg (regs, 6) & 0xFF; + uae_u8 mask = m68k_dreg (regs, 7) & 0xFF; + struct RenderInfo local_ri; + struct BitMap local_bm; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; + if (minterm != 0x0C) { + write_log (L"ERROR - BlitPlanar2Chunky() has minterm 0x%x, which I don't handle. Using fall-back routine.\n", + minterm); + } else if (CopyRenderInfoStructureA2U (ri, &local_ri) && CopyBitMapStructureA2U (bm, &local_bm)) { + P96TRACE((L"BlitPlanar2Chunky(%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)); + P96TRACE((L"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); + result = 1; + } + return result; } /* NOTE: Watch for those planeptrs of 0x00000000 and 0xFFFFFFFF for all zero / all one bitmaps !!!! */ static void PlanarToDirect (struct RenderInfo *ri, struct BitMap *bm, - unsigned long srcx, unsigned long srcy, - unsigned long dstx, unsigned long dsty, - unsigned long width, unsigned long height, uae_u8 mask, - struct ColorIndexMapping *cim) + unsigned long srcx, unsigned long srcy, + unsigned long dstx, unsigned long dsty, + unsigned long width, unsigned long height, uae_u8 mask, +struct ColorIndexMapping *cim) { - int j; - int bpp = GetBytesPerPixel (ri->RGBFormat); - uae_u8 *PLANAR[8]; - uae_u8 *image = ri->Memory + dstx * bpp + dsty * ri->BytesPerRow; - int Depth = bm->Depth; - unsigned long rows; - long eol_offset; - - if(!bpp) - return; - - /* Set up our bm->Planes[] pointers to the right horizontal offset */ - for (j = 0; j < Depth; j++) { - uae_u8 *p = bm->Planes[j]; - if (p != &all_zeros_bitmap && p != &all_ones_bitmap) - p += srcx / 8 + srcy * bm->BytesPerRow; - PLANAR[j] = p; - if ((mask & (1 << j)) == 0) - PLANAR[j] = &all_zeros_bitmap; - } - - eol_offset = (long)bm->BytesPerRow - (long)((width + (srcx & 7)) >> 3); - for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) { - unsigned long cols; - uae_u8 *image2 = image; - unsigned int bitoffs = 7 - (srcx & 7); - int i; + int j; + int bpp = GetBytesPerPixel (ri->RGBFormat); + uae_u8 *PLANAR[8]; + uae_u8 *image = ri->Memory + dstx * bpp + dsty * ri->BytesPerRow; + int Depth = bm->Depth; + unsigned long rows; + long eol_offset; + + if(!bpp) + return; - for (cols = 0; cols < width; cols ++) { - int v = 0, k; - for (k = 0; k < Depth; k++) { - if (PLANAR[k] == &all_ones_bitmap) - v |= 1 << k; - else if (PLANAR[k] != &all_zeros_bitmap) { - v |= ((*PLANAR[k] >> bitoffs) & 1) << k; - } - } - switch (bpp) - { - case 2: - ((uae_u16 *)image2)[0] = (uae_u16)(cim->Colors[v]); - image2 += 2; - break; - case 3: - image2[0] = cim->Colors[v] >> 0; - image2[1] = cim->Colors[v] >> 8; - image2[2] = cim->Colors[v] >> 16; - image2 += 3; - break; - case 4: - ((uae_u32 *)image2)[0] = cim->Colors[v]; - image2 += 4; - break; - } - bitoffs--; - bitoffs &= 7; - if (bitoffs == 7) { - int k; - for (k = 0; k < Depth; k++) { - if (PLANAR[k] != &all_zeros_bitmap && PLANAR[k] != &all_ones_bitmap) { - PLANAR[k]++; - } - } - } + /* Set up our bm->Planes[] pointers to the right horizontal offset */ + for (j = 0; j < Depth; j++) { + uae_u8 *p = bm->Planes[j]; + if (p != &all_zeros_bitmap && p != &all_ones_bitmap) + p += srcx / 8 + srcy * bm->BytesPerRow; + PLANAR[j] = p; + if ((mask & (1 << j)) == 0) + PLANAR[j] = &all_zeros_bitmap; } - for (i = 0; i < Depth; i++) { - if (PLANAR[i] != &all_zeros_bitmap && PLANAR[i] != &all_ones_bitmap) { - PLANAR[i] += eol_offset; - } + eol_offset = (long)bm->BytesPerRow - (long)((width + (srcx & 7)) >> 3); + for (rows = 0; rows < height; rows++, image += ri->BytesPerRow) { + unsigned long cols; + uae_u8 *image2 = image; + unsigned int bitoffs = 7 - (srcx & 7); + int i; + + for (cols = 0; cols < width; cols ++) { + int v = 0, k; + for (k = 0; k < Depth; k++) { + if (PLANAR[k] == &all_ones_bitmap) + v |= 1 << k; + else if (PLANAR[k] != &all_zeros_bitmap) { + v |= ((*PLANAR[k] >> bitoffs) & 1) << k; + } + } + switch (bpp) + { + case 2: + ((uae_u16 *)image2)[0] = (uae_u16)(cim->Colors[v]); + image2 += 2; + break; + case 3: + image2[0] = cim->Colors[v] >> 0; + image2[1] = cim->Colors[v] >> 8; + image2[2] = cim->Colors[v] >> 16; + image2 += 3; + break; + case 4: + ((uae_u32 *)image2)[0] = cim->Colors[v]; + image2 += 4; + break; + } + bitoffs--; + bitoffs &= 7; + if (bitoffs == 7) { + int k; + for (k = 0; k < Depth; k++) { + if (PLANAR[k] != &all_zeros_bitmap && PLANAR[k] != &all_ones_bitmap) { + PLANAR[k]++; + } + } + } + } + + for (i = 0; i < Depth; i++) { + if (PLANAR[i] != &all_zeros_bitmap && PLANAR[i] != &all_ones_bitmap) { + PLANAR[i] += eol_offset; + } + } } - } } /* @@ -3758,551 +3758,551 @@ static void PlanarToDirect (struct RenderInfo *ri, struct BitMap *bm, */ static uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (TrapContext *ctx) { - uaecptr bm = m68k_areg (regs, 1); - uaecptr ri = m68k_areg (regs, 2); - uaecptr cim = m68k_areg (regs, 3); - unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); - unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); - unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); - unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); - unsigned long width = (uae_u16)m68k_dreg (regs, 4); - unsigned long height = (uae_u16)m68k_dreg (regs, 5); - uae_u8 minterm = m68k_dreg (regs, 6); - uae_u8 Mask = m68k_dreg (regs, 7); - struct RenderInfo local_ri; - struct BitMap local_bm; - struct ColorIndexMapping local_cim; - uae_u32 result = 0; - - if (NOBLITTER) - return 0; - if (minterm != 0x0C) { - write_log (L"WARNING - BlitPlanar2Direct() has unhandled op-code 0x%x. Using fall-back routine.\n", minterm); - return 0; - } - if (CopyRenderInfoStructureA2U (ri, &local_ri) && CopyBitMapStructureA2U (bm, &local_bm)) { - Mask = 0xFF; - CopyColorIndexMappingA2U (cim, &local_cim, GetBytesPerPixel (local_ri.RGBFormat)); - P96TRACE((L"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); - result = 1; - } - return result; + uaecptr bm = m68k_areg (regs, 1); + uaecptr ri = m68k_areg (regs, 2); + uaecptr cim = m68k_areg (regs, 3); + unsigned long srcx = (uae_u16)m68k_dreg (regs, 0); + unsigned long srcy = (uae_u16)m68k_dreg (regs, 1); + unsigned long dstx = (uae_u16)m68k_dreg (regs, 2); + unsigned long dsty = (uae_u16)m68k_dreg (regs, 3); + unsigned long width = (uae_u16)m68k_dreg (regs, 4); + unsigned long height = (uae_u16)m68k_dreg (regs, 5); + uae_u8 minterm = m68k_dreg (regs, 6); + uae_u8 Mask = m68k_dreg (regs, 7); + struct RenderInfo local_ri; + struct BitMap local_bm; + struct ColorIndexMapping local_cim; + uae_u32 result = 0; + + if (NOBLITTER) + return 0; + if (minterm != 0x0C) { + write_log (L"WARNING - BlitPlanar2Direct() has unhandled op-code 0x%x. Using fall-back routine.\n", minterm); + return 0; + } + if (CopyRenderInfoStructureA2U (ri, &local_ri) && CopyBitMapStructureA2U (bm, &local_bm)) { + Mask = 0xFF; + CopyColorIndexMappingA2U (cim, &local_cim, GetBytesPerPixel (local_ri.RGBFormat)); + P96TRACE((L"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); + result = 1; + } + return result; } #include "statusline.h" static void statusline (uae_u8 *dst) { - int y, yy; - int dst_height, pitch; - - dst_height = picasso96_state.Height; - if (dst_height > picasso_vidinfo.height) - dst_height = picasso_vidinfo.height; - pitch = picasso_vidinfo.rowbytes; - yy = 0; - for (y = dst_height - TD_TOTAL_HEIGHT; y < dst_height; y++) { - uae_u8 *buf = dst + y * pitch; - draw_status_line_single (buf, picasso_vidinfo.pixbytes, yy, picasso96_state.Width, p96rc, p96gc, p96bc, NULL); - yy++; - } + int y, yy; + int dst_height, pitch; + + dst_height = picasso96_state.Height; + if (dst_height > picasso_vidinfo.height) + dst_height = picasso_vidinfo.height; + pitch = picasso_vidinfo.rowbytes; + yy = 0; + for (y = dst_height - TD_TOTAL_HEIGHT; y < dst_height; y++) { + uae_u8 *buf = dst + y * pitch; + draw_status_line_single (buf, picasso_vidinfo.pixbytes, yy, picasso96_state.Width, p96rc, p96gc, p96bc, NULL); + yy++; + } } STATIC_INLINE void copyrow (uae_u8 *src, uae_u8 *dst, int x, int y, int width) { - uae_u8 *src2 = src + y * picasso96_state.BytesPerRow; - uae_u8 *dst2 = dst + y * picasso_vidinfo.rowbytes; - int endx = x + width, endx4; - int dstpix = picasso_vidinfo.pixbytes; - int srcpix = picasso96_state.BytesPerPixel; - - if (picasso96_state.RGBFormat == host_mode) { - memcpy (dst2 + x * dstpix, src2 + x * srcpix, width * dstpix); - return; - } - - endx4 = endx & ~3; - - switch (picasso_convert) - { - /* Picasso96mode == Nativemode */ + uae_u8 *src2 = src + y * picasso96_state.BytesPerRow; + uae_u8 *dst2 = dst + y * picasso_vidinfo.rowbytes; + int endx = x + width, endx4; + int dstpix = picasso_vidinfo.pixbytes; + int srcpix = picasso96_state.BytesPerPixel; + + if (picasso96_state.RGBFormat == host_mode) { + memcpy (dst2 + x * dstpix, src2 + x * srcpix, width * dstpix); + return; + } + + endx4 = endx & ~3; + + switch (picasso_convert) + { + /* Picasso96mode == Nativemode */ case RGBFB_B8G8R8A8_32: case RGBFB_R5G6B5PC_16: case RGBFB_CLUT_8: - memcpy (dst2 + x * dstpix, src2 + x * srcpix, width * dstpix); - break; + memcpy (dst2 + x * dstpix, src2 + x * srcpix, width * dstpix); + break; - /* 24bit->32bit */ + /* 24bit->32bit */ case RGBFB_R8G8B8_32: - while (x < endx) { - ((uae_u32*)dst2)[x] = (src2[x * 3 + 0] << 16) | (src2[x * 3 + 1] << 8) | (src2[x * 3 + 2] << 0); - x++; - } - break; + while (x < endx) { + ((uae_u32*)dst2)[x] = (src2[x * 3 + 0] << 16) | (src2[x * 3 + 1] << 8) | (src2[x * 3 + 2] << 0); + x++; + } + break; case RGBFB_B8G8R8_32: - while (x < endx) { - ((uae_u32*)dst2)[x] = ((uae_u32*)(src2 + x * 3))[0] & 0x00ffffff; - x++; - } - break; + while (x < endx) { + ((uae_u32*)dst2)[x] = ((uae_u32*)(src2 + x * 3))[0] & 0x00ffffff; + x++; + } + break; - /* 32bit->32bit */ + /* 32bit->32bit */ case RGBFB_R8G8B8A8_32: - while (x < endx) { - ((uae_u32*)dst2)[x] = (src2[x * 4 + 0] << 16) | (src2[x * 4 + 1] << 8) | (src2[x * 4 + 2] << 0); - x++; - } - break; + while (x < endx) { + ((uae_u32*)dst2)[x] = (src2[x * 4 + 0] << 16) | (src2[x * 4 + 1] << 8) | (src2[x * 4 + 2] << 0); + x++; + } + break; case RGBFB_A8R8G8B8_32: - while (x < endx) { - ((uae_u32*)dst2)[x] = (src2[x * 4 + 1] << 16) | (src2[x * 4 + 2] << 8) | (src2[x * 4 + 3] << 0); - x++; - } - break; + while (x < endx) { + ((uae_u32*)dst2)[x] = (src2[x * 4 + 1] << 16) | (src2[x * 4 + 2] << 8) | (src2[x * 4 + 3] << 0); + x++; + } + break; case RGBFB_A8B8G8R8_32: - while (x < endx) { - ((uae_u32*)dst2)[x] = ((uae_u32*)src2)[x] >> 8; - x++; - } - break; + while (x < endx) { + ((uae_u32*)dst2)[x] = ((uae_u32*)src2)[x] >> 8; + x++; + } + break; - /* 15/16bit->32bit */ + /* 15/16bit->32bit */ case RGBFB_R5G6B5PC_32: case RGBFB_R5G5B5PC_32: case RGBFB_R5G6B5_32: case RGBFB_R5G5B5_32: case RGBFB_B5G6R5PC_32: case RGBFB_B5G5R5PC_32: - { - while ((x & 3) && x < endx) { - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - while (x < endx4) { - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - while (x < endx) { - ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - } - break; + { + while ((x & 3) && x < endx) { + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + while (x < endx4) { + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + while (x < endx) { + ((uae_u32*)dst2)[x] = p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + } + break; - /* 16/15bit->16bit */ + /* 16/15bit->16bit */ case RGBFB_R5G5B5PC_16: case RGBFB_R5G6B5_16: case RGBFB_R5G5B5_16: case RGBFB_B5G5R5PC_16: case RGBFB_B5G6R5PC_16: - { - while ((x & 3) && x < endx) { - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - while (x < endx4) { - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - while (x < endx) { - ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; - x++; - } - } - break; + { + while ((x & 3) && x < endx) { + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + while (x < endx4) { + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + while (x < endx) { + ((uae_u16*)dst2)[x] = (uae_u16)p96_rgbx16[((uae_u16*)src2)[x]]; + x++; + } + } + break; - /* 24bit->16bit */ + /* 24bit->16bit */ case RGBFB_R8G8B8_16: - while (x < endx) { - uae_u8 r, g, b; - r = src2[x * 3 + 0]; - g = src2[x * 3 + 1]; - b = src2[x * 3 + 2]; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5) | (((b >> 3) & 0x1f) << 0)]; - x++; - } - break; + while (x < endx) { + uae_u8 r, g, b; + r = src2[x * 3 + 0]; + g = src2[x * 3 + 1]; + b = src2[x * 3 + 2]; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5) | (((b >> 3) & 0x1f) << 0)]; + x++; + } + break; case RGBFB_B8G8R8_16: - while (x < endx) { - uae_u32 v; - v = ((uae_u32*)(&src2[x * 3]))[0] >> 8; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (8 + 3)) & 0x1f) << 11) | (((v >> (0 + 2)) & 0x3f) << 5) | (((v >> (16 + 3)) & 0x1f) << 0)]; - x++; - } - break; - - /* 32bit->16bit */ + while (x < endx) { + uae_u32 v; + v = ((uae_u32*)(&src2[x * 3]))[0] >> 8; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (8 + 3)) & 0x1f) << 11) | (((v >> (0 + 2)) & 0x3f) << 5) | (((v >> (16 + 3)) & 0x1f) << 0)]; + x++; + } + break; + + /* 32bit->16bit */ case RGBFB_R8G8B8A8_16: - while (x < endx) { - uae_u32 v; - v = ((uae_u32*)src2)[x]; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (0 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (16 + 3)) & 0x1f) << 0)]; - x++; - } - break; + while (x < endx) { + uae_u32 v; + v = ((uae_u32*)src2)[x]; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (0 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (16 + 3)) & 0x1f) << 0)]; + x++; + } + break; case RGBFB_A8R8G8B8_16: - while (x < endx) { - uae_u32 v; - v = ((uae_u32*)src2)[x]; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (8 + 3)) & 0x1f) << 11) | (((v >> (16 + 2)) & 0x3f) << 5) | (((v >> (24 + 3)) & 0x1f) << 0)]; - x++; - } - break; + while (x < endx) { + uae_u32 v; + v = ((uae_u32*)src2)[x]; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (8 + 3)) & 0x1f) << 11) | (((v >> (16 + 2)) & 0x3f) << 5) | (((v >> (24 + 3)) & 0x1f) << 0)]; + x++; + } + break; case RGBFB_A8B8G8R8_16: - while (x < endx) { - uae_u32 v; - v = ((uae_u32*)src2)[x]; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (24 + 3)) & 0x1f) << 11) | (((v >> (16 + 2)) & 0x3f) << 5) | (((v >> (8 + 3)) & 0x1f) << 0)]; - x++; - } - break; + while (x < endx) { + uae_u32 v; + v = ((uae_u32*)src2)[x]; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (24 + 3)) & 0x1f) << 11) | (((v >> (16 + 2)) & 0x3f) << 5) | (((v >> (8 + 3)) & 0x1f) << 0)]; + x++; + } + break; case RGBFB_B8G8R8A8_16: - while (x < endx) { - uae_u32 v; - v = ((uae_u32*)src2)[x]; - ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (16 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (0 + 3)) & 0x1f) << 0)]; - x++; - } - break; - - /* 8bit->32bit */ + while (x < endx) { + uae_u32 v; + v = ((uae_u32*)src2)[x]; + ((uae_u16*)dst2)[x] = p96_rgbx16[(((v >> (16 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (0 + 3)) & 0x1f) << 0)]; + x++; + } + break; + + /* 8bit->32bit */ case RGBFB_CLUT_RGBFB_32: - { - while ((x & 3) && x < endx) { - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } - while (x < endx4) { - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } - while (x < endx) { - ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } - } - break; + { + while ((x & 3) && x < endx) { + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + while (x < endx4) { + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + while (x < endx) { + ((uae_u32*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + } + break; - /* 8bit->16bit */ + /* 8bit->16bit */ case RGBFB_CLUT_RGBFB_16: - { - while ((x & 3) && x < endx) { - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } - while (x < endx4) { - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } - while (x < endx) { - ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; - x++; - } + { + while ((x & 3) && x < endx) { + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + while (x < endx4) { + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + while (x < endx) { + ((uae_u16*)dst2)[x] = picasso_vidinfo.clut[src2[x]]; + x++; + } + } + break; } - break; - } } static void copyallinvert (uae_u8 *src, uae_u8 *dst) { - int x, y, w; - - w = picasso96_state.Width * picasso_vidinfo.pixbytes; - if (picasso96_state.RGBFormat == host_mode) { - for (y = 0; y < picasso96_state.Height; y++) { - for (x = 0; x < w; x++) - dst[x] = src[x] ^ 0xff; - dst += picasso_vidinfo.rowbytes; - src += picasso96_state.BytesPerRow; - } - } else { - for (y = 0; y < picasso96_state.Height; y++) { - for (x = 0; x < w; x++) - src[x] ^= 0xff; - copyrow (src, dst, 0, y, picasso96_state.Width); - for (x = 0; x < w; x++) - src[x] ^= 0xff; + int x, y, w; + + w = picasso96_state.Width * picasso_vidinfo.pixbytes; + if (picasso96_state.RGBFormat == host_mode) { + for (y = 0; y < picasso96_state.Height; y++) { + for (x = 0; x < w; x++) + dst[x] = src[x] ^ 0xff; + dst += picasso_vidinfo.rowbytes; + src += picasso96_state.BytesPerRow; + } + } else { + for (y = 0; y < picasso96_state.Height; y++) { + for (x = 0; x < w; x++) + src[x] ^= 0xff; + copyrow (src, dst, 0, y, picasso96_state.Width); + for (x = 0; x < w; x++) + src[x] ^= 0xff; + } } - } } static void copyall (uae_u8 *src, uae_u8 *dst) { - int y; - uae_u8 *dstb; - - dstb = dst; - if (picasso96_state.RGBFormat == host_mode) { - int w = picasso96_state.Width * picasso_vidinfo.pixbytes; - for (y = 0; y < picasso96_state.Height; y++) { - memcpy (dst, src, w); - dst += picasso_vidinfo.rowbytes; - src += picasso96_state.BytesPerRow; + int y; + uae_u8 *dstb; + + dstb = dst; + if (picasso96_state.RGBFormat == host_mode) { + int w = picasso96_state.Width * picasso_vidinfo.pixbytes; + for (y = 0; y < picasso96_state.Height; y++) { + memcpy (dst, src, w); + dst += picasso_vidinfo.rowbytes; + src += picasso96_state.BytesPerRow; + } + } else { + for (y = 0; y < picasso96_state.Height; y++) + copyrow (src, dst, 0, y, picasso96_state.Width); } - } else { - for (y = 0; y < picasso96_state.Height; y++) - copyrow (src, dst, 0, y, picasso96_state.Width); - } } static void flushpixels (void) { - int i; - uae_u8 *src = p96ram_start + natmem_offset; - int off = picasso96_state.XYOffset - gfxmem_start; - uae_u8 *src_start = src + (off & ~gwwpagemask); - uae_u8 *src_end = src + ((off + picasso96_state.BytesPerRow * picasso96_state.Height + gwwpagesize - 1) & ~gwwpagemask); - int maxy = -1; - int miny = picasso96_state.Height - 1; - int lock = 0; - uae_u8 *dst = NULL; - ULONG_PTR gwwcnt; + int i; + uae_u8 *src = p96ram_start + natmem_offset; + int off = picasso96_state.XYOffset - gfxmem_start; + uae_u8 *src_start = src + (off & ~gwwpagemask); + uae_u8 *src_end = src + ((off + picasso96_state.BytesPerRow * picasso96_state.Height + gwwpagesize - 1) & ~gwwpagemask); + int maxy = -1; + int miny = picasso96_state.Height - 1; + int lock = 0; + uae_u8 *dst = NULL; + ULONG_PTR gwwcnt; #if 0 - write_log (L"%dx%d %dx%d %dx%d\n", picasso96_state.Width, picasso96_state.Width, - picasso96_state.VirtualWidth, picasso96_state.VirtualHeight, - picasso_vidinfo.width, picasso_vidinfo.height); + write_log (L"%dx%d %dx%d %dx%d\n", picasso96_state.Width, picasso96_state.Width, + picasso96_state.VirtualWidth, picasso96_state.VirtualHeight, + picasso_vidinfo.width, picasso_vidinfo.height); #endif - if (!picasso_vidinfo.extra_mem || !gwwbuf || src_start >= src_end) - return; + if (!picasso_vidinfo.extra_mem || !gwwbuf || src_start >= src_end) + return; - if (flashscreen) { - full_refresh = 1; - } - if (full_refresh) - full_refresh = -1; - - for (;;) { - int dofull; - - gwwcnt = 0; - - if (doskip () && p96skipmode == 1) - break; - - if (full_refresh < 0) { - gwwcnt = (src_end - src_start) / gwwpagesize + 1; - full_refresh = 1; - if (picasso_palette ()) { - reloadcursor = 1; - setspriteimage (boardinfo); - } - for (i = 0; i < gwwcnt; i++) - gwwbuf[i] = src_start + i * gwwpagesize; - } else { - ULONG ps; - gwwcnt = gwwbufsize; - if (mman_GetWriteWatch (src_start, src_end - src_start, gwwbuf, &gwwcnt, &ps)) - break; + if (flashscreen) { + full_refresh = 1; } + if (full_refresh) + full_refresh = -1; - if (gwwcnt == 0) - break; + for (;;) { + int dofull; - dofull = gwwcnt >= ((src_end - src_start) / gwwpagesize) * 80 / 100; + gwwcnt = 0; -#if P96DX > 0 - if (p96surface && dofull && picasso_vidinfo.pixbytes == picasso96_state.BytesPerPixel) { - flushpixels_surface (gwwbuf, gwwcnt, src_start, src_end); - return; - } -#endif + if (doskip () && p96skipmode == 1) + break; - if (dst == NULL) { - if (DirectDraw_IsLocked () == FALSE) { - if (!lock) - dst = gfx_lock_picasso (); - lock = 1; - } else { - dst = picasso96_state.HostAddress; - } - } - if (dst == NULL) - break; - dst += picasso_vidinfo.offset; - - if (doskip () && p96skipmode == 2) - break; - - if (dofull) { - if (flashscreen != 0) - copyallinvert (src + off, dst); - else - copyall (src + off, dst); - miny = 0; - maxy = picasso96_state.Height; - break; - } + if (full_refresh < 0) { + gwwcnt = (src_end - src_start) / gwwpagesize + 1; + full_refresh = 1; + if (picasso_palette ()) { + reloadcursor = 1; + setspriteimage (boardinfo); + } + for (i = 0; i < gwwcnt; i++) + gwwbuf[i] = src_start + i * gwwpagesize; + } else { + ULONG ps; + gwwcnt = gwwbufsize; + if (mman_GetWriteWatch (src_start, src_end - src_start, gwwbuf, &gwwcnt, &ps)) + break; + } - for (i = 0; i < gwwcnt; i++) { - uae_u8 *p = gwwbuf[i]; + if (gwwcnt == 0) + break; - if (p >= src_start && p < src_end) { - int y, x, realoffset; + dofull = gwwcnt >= ((src_end - src_start) / gwwpagesize) * 80 / 100; - if (p >= src + off) { - realoffset = p - (src + off); - } else { - realoffset = 0; +#if P96DX > 0 + if (p96surface && dofull && picasso_vidinfo.pixbytes == picasso96_state.BytesPerPixel) { + flushpixels_surface (gwwbuf, gwwcnt, src_start, src_end); + return; } +#endif - y = realoffset / picasso96_state.BytesPerRow; - if (y < picasso96_state.Height) { - int w = gwwpagesize / picasso96_state.BytesPerPixel; - x = (realoffset % picasso96_state.BytesPerRow) / picasso96_state.BytesPerPixel; - if (x < picasso96_state.Width) - copyrow (src + off, dst, x, y, picasso96_state.Width - x); - w = (gwwpagesize - (picasso96_state.BytesPerRow - x * picasso96_state.BytesPerPixel)) / picasso96_state.BytesPerPixel; - if (y < miny) - miny = y; - y++; - while (y < picasso96_state.Height && w > 0) { - int maxw = w > picasso96_state.Width ? picasso96_state.Width : w; - copyrow (src + off, dst, 0, y, maxw); - w -= maxw; - y++; - } - if (y > maxy) - maxy = y; + if (dst == NULL) { + if (DirectDraw_IsLocked () == FALSE) { + if (!lock) + dst = gfx_lock_picasso (); + lock = 1; + } else { + dst = picasso96_state.HostAddress; + } + } + if (dst == NULL) + break; + dst += picasso_vidinfo.offset; + + if (doskip () && p96skipmode == 2) + break; + + if (dofull) { + if (flashscreen != 0) + copyallinvert (src + off, dst); + else + copyall (src + off, dst); + miny = 0; + maxy = picasso96_state.Height; + break; } - } + for (i = 0; i < gwwcnt; i++) { + uae_u8 *p = gwwbuf[i]; + if (p >= src_start && p < src_end) { + int y, x, realoffset; + + if (p >= src + off) { + realoffset = p - (src + off); + } else { + realoffset = 0; + } + + y = realoffset / picasso96_state.BytesPerRow; + if (y < picasso96_state.Height) { + int w = gwwpagesize / picasso96_state.BytesPerPixel; + x = (realoffset % picasso96_state.BytesPerRow) / picasso96_state.BytesPerPixel; + if (x < picasso96_state.Width) + copyrow (src + off, dst, x, y, picasso96_state.Width - x); + w = (gwwpagesize - (picasso96_state.BytesPerRow - x * picasso96_state.BytesPerPixel)) / picasso96_state.BytesPerPixel; + if (y < miny) + miny = y; + y++; + while (y < picasso96_state.Height && w > 0) { + int maxw = w > picasso96_state.Width ? picasso96_state.Width : w; + copyrow (src + off, dst, 0, y, maxw); + w -= maxw; + y++; + } + if (y > maxy) + maxy = y; + } + + } + + } + break; } - break; - } - - if (currprefs.leds_on_screen & STATUSLINE_RTG) { - if (dst == NULL) { - if (DirectDraw_IsLocked () == FALSE) { - if (!lock) - dst = gfx_lock_picasso (); - lock = 1; - } else { - dst = picasso96_state.HostAddress; - } - } - if (dst) { - statusline (dst); - maxy = picasso_vidinfo.height; - if (miny > picasso_vidinfo.height - TD_TOTAL_HEIGHT) - miny = picasso_vidinfo.height - TD_TOTAL_HEIGHT; + + if (currprefs.leds_on_screen & STATUSLINE_RTG) { + if (dst == NULL) { + if (DirectDraw_IsLocked () == FALSE) { + if (!lock) + dst = gfx_lock_picasso (); + lock = 1; + } else { + dst = picasso96_state.HostAddress; + } + } + if (dst) { + statusline (dst); + maxy = picasso_vidinfo.height; + if (miny > picasso_vidinfo.height - TD_TOTAL_HEIGHT) + miny = picasso_vidinfo.height - TD_TOTAL_HEIGHT; + } } - } - if (maxy >= 0) { - if (doskip () && p96skipmode == 4) { - ; - } else { - DX_Invalidate (0, miny, picasso96_state.Width, maxy - miny); + if (maxy >= 0) { + if (doskip () && p96skipmode == 4) { + ; + } else { + DX_Invalidate (0, miny, picasso96_state.Width, maxy - miny); + } } - } - if (lock) - gfx_unlock_picasso (); - if (dst && gwwcnt) { - if (doskip () && p96skipmode == 3) { - ; - } else { - mman_ResetWatch (src_start, src_end - src_start); + if (lock) + gfx_unlock_picasso (); + if (dst && gwwcnt) { + if (doskip () && p96skipmode == 3) { + ; + } else { + mman_ResetWatch (src_start, src_end - src_start); + } + full_refresh = 0; } - full_refresh = 0; - } } static uae_u32 REGPARAM2 gfxmem_lgetx (uaecptr addr) { - uae_u32 *m; + uae_u32 *m; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u32 *)(gfxmemory + addr); - return do_get_mem_long (m); + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + m = (uae_u32 *)(gfxmemory + addr); + return do_get_mem_long (m); } static uae_u32 REGPARAM2 gfxmem_wgetx (uaecptr addr) { - uae_u16 *m; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u16 *)(gfxmemory + addr); - return do_get_mem_word (m); + uae_u16 *m; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + m = (uae_u16 *)(gfxmemory + addr); + return do_get_mem_word (m); } static uae_u32 REGPARAM2 gfxmem_bgetx (uaecptr addr) { - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - return gfxmemory[addr]; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + return gfxmemory[addr]; } static void REGPARAM2 gfxmem_lputx (uaecptr addr, uae_u32 l) { - uae_u32 *m; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u32 *)(gfxmemory + addr); - do_put_mem_long (m, l); + uae_u32 *m; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + m = (uae_u32 *)(gfxmemory + addr); + do_put_mem_long (m, l); } static void REGPARAM2 gfxmem_wputx (uaecptr addr, uae_u32 w) { - uae_u16 *m; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u16 *)(gfxmemory + addr); - do_put_mem_word (m, (uae_u16)w); + uae_u16 *m; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + m = (uae_u16 *)(gfxmemory + addr); + do_put_mem_word (m, (uae_u16)w); } static void REGPARAM2 gfxmem_bputx (uaecptr addr, uae_u32 b) { - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - gfxmemory[addr] = b; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + gfxmemory[addr] = b; } static int REGPARAM2 gfxmem_check (uaecptr addr, uae_u32 size) { - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - return (addr + size) < allocated_gfxmem; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + return (addr + size) < allocated_gfxmem; } static uae_u8 *REGPARAM2 gfxmem_xlate (uaecptr addr) { - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - return gfxmemory + addr; + addr -= gfxmem_start & gfxmem_mask; + addr &= gfxmem_mask; + return gfxmemory + addr; } addrbank gfxmem_bankx = { - gfxmem_lgetx, gfxmem_wgetx, gfxmem_bgetx, - gfxmem_lputx, gfxmem_wputx, gfxmem_bputx, - gfxmem_xlate, gfxmem_check, NULL, L"RTG RAM", - dummy_lgeti, dummy_wgeti, ABFLAG_RAM + gfxmem_lgetx, gfxmem_wgetx, gfxmem_bgetx, + gfxmem_lputx, gfxmem_wputx, gfxmem_bputx, + gfxmem_xlate, gfxmem_check, NULL, L"RTG RAM", + dummy_lgeti, dummy_wgeti, ABFLAG_RAM }; /* Call this function first, near the beginning of code flow @@ -4310,240 +4310,240 @@ addrbank gfxmem_bankx = { * Also put it in reset_drawing() for safe-keeping. */ void InitPicasso96 (void) { - int i; + int i; -//fastscreen - oldscr = 0; -//fastscreen - memset (&picasso96_state, 0, sizeof (struct picasso96_state_struct)); - - for (i = 0; i < 256; i++) { - p2ctab[i][0] = (((i & 128) ? 0x01000000 : 0) - | ((i & 64) ? 0x010000 : 0) - | ((i & 32) ? 0x0100 : 0) - | ((i & 16) ? 0x01 : 0)); - p2ctab[i][1] = (((i & 8) ? 0x01000000 : 0) - | ((i & 4) ? 0x010000 : 0) - | ((i & 2) ? 0x0100 : 0) - | ((i & 1) ? 0x01 : 0)); - } + //fastscreen + oldscr = 0; + //fastscreen + memset (&picasso96_state, 0, sizeof (struct picasso96_state_struct)); + + for (i = 0; i < 256; i++) { + p2ctab[i][0] = (((i & 128) ? 0x01000000 : 0) + | ((i & 64) ? 0x010000 : 0) + | ((i & 32) ? 0x0100 : 0) + | ((i & 16) ? 0x01 : 0)); + p2ctab[i][1] = (((i & 8) ? 0x01000000 : 0) + | ((i & 4) ? 0x010000 : 0) + | ((i & 2) ? 0x0100 : 0) + | ((i & 1) ? 0x01 : 0)); + } } #endif static uae_u32 REGPARAM2 picasso_SetInterrupt (TrapContext *ctx) { - uaecptr bi = m68k_areg (regs, 0); - uae_u32 onoff = m68k_dreg (regs, 0); - interrupt_enabled = onoff; - //write_log (L"Picasso_SetInterrupt(%08x,%d)\n", bi, onoff); - return onoff; + uaecptr bi = m68k_areg (regs, 0); + uae_u32 onoff = m68k_dreg (regs, 0); + interrupt_enabled = onoff; + //write_log (L"Picasso_SetInterrupt(%08x,%d)\n", bi, onoff); + return onoff; } #ifdef UAEGFX_INTERNAL #define PUTABI(func) \ - if (ABI) \ + if (ABI) \ put_long (ABI + func, here ()); #define RTGCALL(func,funcdef,call) \ - PUTABI (func); \ - dl (0x48e78000); \ - calltrap (deftrap (call)); \ - dw (0x4a80); \ - dl (0x4cdf0001);\ - dw (0x6604); \ - dw (0x2f28); \ - dw (funcdef); \ - dw (RTS); + PUTABI (func); \ + dl (0x48e78000); \ + calltrap (deftrap (call)); \ + dw (0x4a80); \ + dl (0x4cdf0001);\ + dw (0x6604); \ + dw (0x2f28); \ + dw (funcdef); \ + dw (RTS); #define RTGCALL2(func,call) \ - PUTABI (func); \ - calltrap (deftrap (call)); \ - dw (RTS); + PUTABI (func); \ + calltrap (deftrap (call)); \ + dw (RTS); #define RTGCALLDEFAULT(func,funcdef) \ - PUTABI (func); \ - dw (0x2f28); \ - dw (funcdef); \ - dw (RTS); + PUTABI (func); \ + dw (0x2f28); \ + dw (funcdef); \ + dw (RTS); #define RTGNONE(func) \ - if (ABI) \ + if (ABI) \ put_long (ABI + func, start); static uaecptr inituaegfxfuncs (uaecptr start, uaecptr ABI) { - uaecptr old = here (); - uaecptr ptr; + uaecptr old = here (); + uaecptr ptr; - org (start); + org (start); - dw (RTS); - /* ResolvePixelClock + dw (RTS); + /* ResolvePixelClock move.l D0,gmi_PixelClock(a1) ; pass the pixelclock through moveq #0,D0 ; index is 0 move.b #98,gmi_Numerator(a1) ; whatever move.b #14,gmi_Denominator(a1) ; whatever rts - */ - PUTABI (PSSO_BoardInfo_ResolvePixelClock); - dl (0x2340002c); - dw (0x7000); - dl (0x137c0062); dw (0x002a); - dl (0x137c000e); dw (0x002b); - dw (RTS); - - /* GetPixelClock + */ + PUTABI (PSSO_BoardInfo_ResolvePixelClock); + dl (0x2340002c); + dw (0x7000); + dl (0x137c0062); dw (0x002a); + dl (0x137c000e); dw (0x002b); + dw (RTS); + + /* GetPixelClock move.l #CLOCK,D0 ; fill in D0 with our one true pixel clock rts - */ - PUTABI (PSSO_BoardInfo_GetPixelClock); - dw (0x203c); - dl (100227260); - dw (RTS); + */ + PUTABI (PSSO_BoardInfo_GetPixelClock); + dw (0x203c); + dl (100227260); + dw (RTS); - /* CalculateMemory + /* CalculateMemory ; this is simple, because we're not supporting planar modes in UAE move.l a1,d0 rts - */ - PUTABI (PSSO_BoardInfo_CalculateMemory); - dw (0x2009); - dw (RTS); + */ + PUTABI (PSSO_BoardInfo_CalculateMemory); + dw (0x2009); + dw (RTS); - /* GetCompatibleFormats + /* GetCompatibleFormats ; all formats can coexist without any problems, since we don't support planar stuff in UAE move.l #RGBMASK_8BIT | RGBMASK_15BIT | RGBMASK_16BIT | RGBMASK_24BIT | RGBMASK_32BIT,d0 rts - */ - PUTABI (PSSO_BoardInfo_GetCompatibleFormats); - dw (0x203c); - dl (RGBMASK_8BIT | RGBMASK_15BIT | RGBMASK_16BIT | RGBMASK_24BIT | RGBMASK_32BIT); - dw (RTS); - - /* CalculateBytesPerRow (optimized) */ - PUTABI (PSSO_BoardInfo_CalculateBytesPerRow); - dl (0x0c400140); // cmp.w #320,d0 - dw (0x6504); // bcs.s .l1 - calltrap (deftrap (picasso_CalculateBytesPerRow)); - dw (RTS); - dw (0x0c87); dl (0x00000010); // l1: cmp.l #$10,d7 - dw (0x640a); // bcc.s .l2 - dw (0x7200); // moveq #0,d1 - dl (0x123b7010); // move.b table(pc,d7.w),d1 - dw (0x6b04); // bmi.s l3 - dw (0xe368); // lsl.w d1,d0 - dw (RTS); // .l2 - dw (0x3200); // .l3 move.w d0,d1 - dw (0xd041); // add.w d1,d0 - dw (0xd041); // add.w d1,d0 - dw (RTS); - dl (0x0000ffff); // table - dl (0x01010202); - dl (0x02020101); - dl (0x01010100); - - RTGNONE(PSSO_BoardInfo_SetClock); - RTGNONE(PSSO_BoardInfo_SetMemoryMode); - RTGNONE(PSSO_BoardInfo_SetWriteMask); - RTGNONE(PSSO_BoardInfo_SetClearMask); - RTGNONE(PSSO_BoardInfo_SetReadPlane); + */ + PUTABI (PSSO_BoardInfo_GetCompatibleFormats); + dw (0x203c); + dl (RGBMASK_8BIT | RGBMASK_15BIT | RGBMASK_16BIT | RGBMASK_24BIT | RGBMASK_32BIT); + dw (RTS); + + /* CalculateBytesPerRow (optimized) */ + PUTABI (PSSO_BoardInfo_CalculateBytesPerRow); + dl (0x0c400140); // cmp.w #320,d0 + dw (0x6504); // bcs.s .l1 + calltrap (deftrap (picasso_CalculateBytesPerRow)); + dw (RTS); + dw (0x0c87); dl (0x00000010); // l1: cmp.l #$10,d7 + dw (0x640a); // bcc.s .l2 + dw (0x7200); // moveq #0,d1 + dl (0x123b7010); // move.b table(pc,d7.w),d1 + dw (0x6b04); // bmi.s l3 + dw (0xe368); // lsl.w d1,d0 + dw (RTS); // .l2 + dw (0x3200); // .l3 move.w d0,d1 + dw (0xd041); // add.w d1,d0 + dw (0xd041); // add.w d1,d0 + dw (RTS); + dl (0x0000ffff); // table + dl (0x01010202); + dl (0x02020101); + dl (0x01010100); + + RTGNONE(PSSO_BoardInfo_SetClock); + RTGNONE(PSSO_BoardInfo_SetMemoryMode); + RTGNONE(PSSO_BoardInfo_SetWriteMask); + RTGNONE(PSSO_BoardInfo_SetClearMask); + RTGNONE(PSSO_BoardInfo_SetReadPlane); #if 1 - RTGNONE(PSSO_BoardInfo_WaitVerticalSync); + RTGNONE(PSSO_BoardInfo_WaitVerticalSync); #else - PUTABI (PSSO_BoardInfo_WaitVerticalSync); - dl (0x48e7203e); // movem.l d2/a5/a6,-(sp) - dl (0x2c68003c); - dw (0x93c9); - dl (0x4eaefeda); - dw (0x2440); - dw (0x70ff); - dl (0x4eaefeb6); - dw (0x7400); - dw (0x1400); - dw (0x6b40); - dw (0x49f9); - dl (uaegfx_base + CARD_VSYNCLIST); - dw (0x47f9); - dl (uaegfx_base + CARD_VSYNCLIST + CARD_VSYNCMAX * 8); - dl (0x4eaeff88); - dw (0xb9cb); - dw (0x6606); - dl (0x4eaeff82); - dw (0x601c); - dw (0x4a94); - dw (0x6704); - dw (0x508c); - dw (0x60ee); - dw (0x288a); - dl (0x29420004); - dl (0x4eaeff82); - dw (0x7000); - dw (0x05c0); - dl (0x4eaefec2); - dw (0x4294); - dw (0x7000); - dw (0x1002); - dw (0x6b04); - dl (0x4eaefeb0); - dl (0x4cdf7c04); - dw (RTS); + PUTABI (PSSO_BoardInfo_WaitVerticalSync); + dl (0x48e7203e); // movem.l d2/a5/a6,-(sp) + dl (0x2c68003c); + dw (0x93c9); + dl (0x4eaefeda); + dw (0x2440); + dw (0x70ff); + dl (0x4eaefeb6); + dw (0x7400); + dw (0x1400); + dw (0x6b40); + dw (0x49f9); + dl (uaegfx_base + CARD_VSYNCLIST); + dw (0x47f9); + dl (uaegfx_base + CARD_VSYNCLIST + CARD_VSYNCMAX * 8); + dl (0x4eaeff88); + dw (0xb9cb); + dw (0x6606); + dl (0x4eaeff82); + dw (0x601c); + dw (0x4a94); + dw (0x6704); + dw (0x508c); + dw (0x60ee); + dw (0x288a); + dl (0x29420004); + dl (0x4eaeff82); + dw (0x7000); + dw (0x05c0); + dl (0x4eaefec2); + dw (0x4294); + dw (0x7000); + dw (0x1002); + dw (0x6b04); + dl (0x4eaefeb0); + dl (0x4cdf7c04); + dw (RTS); #endif - RTGNONE(PSSO_BoardInfo_WaitBlitter); + RTGNONE(PSSO_BoardInfo_WaitBlitter); #if 0 - RTGCALL2(PSSO_BoardInfo_, picasso_); - RTGCALL(PSSO_BoardInfo_, PSSO_BoardInfo_Default, picasso_); - RTGCALLDEFAULT(PSSO_BoardInfo_, PSSO_BoardInfo_Default); + RTGCALL2(PSSO_BoardInfo_, picasso_); + RTGCALL(PSSO_BoardInfo_, PSSO_BoardInfo_Default, picasso_); + RTGCALLDEFAULT(PSSO_BoardInfo_, PSSO_BoardInfo_Default); #endif - RTGCALL(PSSO_BoardInfo_BlitPlanar2Direct, PSSO_BoardInfo_BlitPlanar2DirectDefault, picasso_BlitPlanar2Direct); - RTGCALL(PSSO_BoardInfo_FillRect, PSSO_BoardInfo_FillRectDefault, picasso_FillRect); - RTGCALL(PSSO_BoardInfo_BlitRect, PSSO_BoardInfo_BlitRectDefault, picasso_BlitRect); - RTGCALL(PSSO_BoardInfo_BlitPlanar2Chunky, PSSO_BoardInfo_BlitPlanar2ChunkyDefault, picasso_BlitPlanar2Chunky); - RTGCALL(PSSO_BoardInfo_BlitTemplate, PSSO_BoardInfo_BlitTemplateDefault, picasso_BlitTemplate); - RTGCALL(PSSO_BoardInfo_InvertRect, PSSO_BoardInfo_InvertRectDefault, picasso_InvertRect); - RTGCALL(PSSO_BoardInfo_BlitRectNoMaskComplete, PSSO_BoardInfo_BlitRectNoMaskCompleteDefault, picasso_BlitRectNoMaskComplete); - RTGCALL(PSSO_BoardInfo_BlitPattern, PSSO_BoardInfo_BlitPatternDefault, picasso_BlitPattern); - - RTGCALL2(PSSO_BoardInfo_SetSwitch, picasso_SetSwitch); - RTGCALL2(PSSO_BoardInfo_SetColorArray, picasso_SetColorArray); - RTGCALL2(PSSO_BoardInfo_SetDAC, picasso_SetDAC); - RTGCALL2(PSSO_BoardInfo_SetGC, picasso_SetGC); - RTGCALL2(PSSO_BoardInfo_SetPanning, picasso_SetPanning); - RTGCALL2(PSSO_BoardInfo_SetDisplay, picasso_SetDisplay); - - RTGCALL2(PSSO_BoardInfo_SetSprite, picasso_SetSprite); - RTGCALL2(PSSO_BoardInfo_SetSpritePosition, picasso_SetSpritePosition); - RTGCALL2(PSSO_BoardInfo_SetSpriteImage, picasso_SetSpriteImage); - RTGCALL2(PSSO_BoardInfo_SetSpriteColor, picasso_SetSpriteColor); - - RTGCALLDEFAULT(PSSO_BoardInfo_ScrollPlanar, PSSO_BoardInfo_ScrollPlanarDefault); - RTGCALLDEFAULT(PSSO_BoardInfo_UpdatePlanar, PSSO_BoardInfo_UpdatePlanarDefault); - RTGCALLDEFAULT(PSSO_BoardInfo_DrawLine, PSSO_BoardInfo_DrawLineDefault); - - RTGCALL2(PSSO_BoardInfo_SetInterrupt, picasso_SetInterrupt); - - write_log (L"uaegfx.card magic code: %08X-%08X ABI=%08X\n", start, here (), ABI); - - ptr = here (); - org (old); - return ptr; + RTGCALL(PSSO_BoardInfo_BlitPlanar2Direct, PSSO_BoardInfo_BlitPlanar2DirectDefault, picasso_BlitPlanar2Direct); + RTGCALL(PSSO_BoardInfo_FillRect, PSSO_BoardInfo_FillRectDefault, picasso_FillRect); + RTGCALL(PSSO_BoardInfo_BlitRect, PSSO_BoardInfo_BlitRectDefault, picasso_BlitRect); + RTGCALL(PSSO_BoardInfo_BlitPlanar2Chunky, PSSO_BoardInfo_BlitPlanar2ChunkyDefault, picasso_BlitPlanar2Chunky); + RTGCALL(PSSO_BoardInfo_BlitTemplate, PSSO_BoardInfo_BlitTemplateDefault, picasso_BlitTemplate); + RTGCALL(PSSO_BoardInfo_InvertRect, PSSO_BoardInfo_InvertRectDefault, picasso_InvertRect); + RTGCALL(PSSO_BoardInfo_BlitRectNoMaskComplete, PSSO_BoardInfo_BlitRectNoMaskCompleteDefault, picasso_BlitRectNoMaskComplete); + RTGCALL(PSSO_BoardInfo_BlitPattern, PSSO_BoardInfo_BlitPatternDefault, picasso_BlitPattern); + + RTGCALL2(PSSO_BoardInfo_SetSwitch, picasso_SetSwitch); + RTGCALL2(PSSO_BoardInfo_SetColorArray, picasso_SetColorArray); + RTGCALL2(PSSO_BoardInfo_SetDAC, picasso_SetDAC); + RTGCALL2(PSSO_BoardInfo_SetGC, picasso_SetGC); + RTGCALL2(PSSO_BoardInfo_SetPanning, picasso_SetPanning); + RTGCALL2(PSSO_BoardInfo_SetDisplay, picasso_SetDisplay); + + RTGCALL2(PSSO_BoardInfo_SetSprite, picasso_SetSprite); + RTGCALL2(PSSO_BoardInfo_SetSpritePosition, picasso_SetSpritePosition); + RTGCALL2(PSSO_BoardInfo_SetSpriteImage, picasso_SetSpriteImage); + RTGCALL2(PSSO_BoardInfo_SetSpriteColor, picasso_SetSpriteColor); + + RTGCALLDEFAULT(PSSO_BoardInfo_ScrollPlanar, PSSO_BoardInfo_ScrollPlanarDefault); + RTGCALLDEFAULT(PSSO_BoardInfo_UpdatePlanar, PSSO_BoardInfo_UpdatePlanarDefault); + RTGCALLDEFAULT(PSSO_BoardInfo_DrawLine, PSSO_BoardInfo_DrawLineDefault); + + RTGCALL2(PSSO_BoardInfo_SetInterrupt, picasso_SetInterrupt); + + write_log (L"uaegfx.card magic code: %08X-%08X ABI=%08X\n", start, here (), ABI); + + ptr = here (); + org (old); + return ptr; } void picasso_reset (void) { - uaegfx_base = 0; - interrupt_enabled = 0; + uaegfx_base = 0; + interrupt_enabled = 0; } void uaegfx_install_code (void) { - uaecptr start = here (); - uaegfx_rom = start; - org (inituaegfxfuncs (start, 0)); + uaecptr start = here (); + uaegfx_rom = start; + org (inituaegfxfuncs (start, 0)); } #define UAEGFX_VERSION 3 @@ -4551,267 +4551,267 @@ void uaegfx_install_code (void) static uae_u32 REGPARAM2 gfx_open (TrapContext *context) { - put_word (uaegfx_base + 32, get_word (uaegfx_base + 32) + 1); - return uaegfx_base; + put_word (uaegfx_base + 32, get_word (uaegfx_base + 32) + 1); + return uaegfx_base; } static uae_u32 REGPARAM2 gfx_close (TrapContext *context) { - put_word (uaegfx_base + 32, get_word (uaegfx_base + 32) - 1); - return 0; + put_word (uaegfx_base + 32, get_word (uaegfx_base + 32) - 1); + return 0; } static uae_u32 REGPARAM2 gfx_expunge (TrapContext *context) { - return 0; + return 0; } static uaecptr uaegfx_vblankname, uaegfx_portsname; static void initvblankirq (TrapContext *ctx, uaecptr base) { - uaecptr p1 = base + CARD_VBLANKIRQ; - uaecptr p2 = base + CARD_PORTSIRQ; - uaecptr c = base + CARD_IRQCODE; - - put_word (p1 + 8, 0x0205); - put_long (p1 + 10, uaegfx_vblankname); - put_long (p1 + 14, base + CARD_IRQFLAG); - put_long (p1 + 18, c); - - put_word (p2 + 8, 0x0205); - put_long (p2 + 10, uaegfx_portsname); - put_long (p2 + 14, base + CARD_IRQFLAG); - put_long (p2 + 18, c); - - put_word (c, 0x4a11); c += 2; // tst.b (a1) - put_word (c, 0x670e); c += 2; // beq.s label - put_word (c, 0x4211); c += 2; // clr.b (a1) - put_long (c, 0x22690004); c += 4; // move.l 4(a1),a1 - put_long (c, 0x2c780004); c += 4; // move.l 4.w,a6 - put_long (c, 0x4eaeff4c); c += 4; // jsr Cause(a6) - put_word (c, 0x7000); c += 2; // label: moveq #0,d0 - put_word (c, RTS); // rts - - m68k_areg (regs, 1) = p1; - m68k_dreg (regs, 0) = 5; /* VERTB */ - CallLib (ctx, get_long (4), -168); /* AddIntServer */ - m68k_areg (regs, 1) = p2; - m68k_dreg (regs, 0) = 3; /* PORTS */ - CallLib (ctx, get_long (4), -168); /* AddIntServer */ + uaecptr p1 = base + CARD_VBLANKIRQ; + uaecptr p2 = base + CARD_PORTSIRQ; + uaecptr c = base + CARD_IRQCODE; + + put_word (p1 + 8, 0x0205); + put_long (p1 + 10, uaegfx_vblankname); + put_long (p1 + 14, base + CARD_IRQFLAG); + put_long (p1 + 18, c); + + put_word (p2 + 8, 0x0205); + put_long (p2 + 10, uaegfx_portsname); + put_long (p2 + 14, base + CARD_IRQFLAG); + put_long (p2 + 18, c); + + put_word (c, 0x4a11); c += 2; // tst.b (a1) + put_word (c, 0x670e); c += 2; // beq.s label + put_word (c, 0x4211); c += 2; // clr.b (a1) + put_long (c, 0x22690004); c += 4; // move.l 4(a1),a1 + put_long (c, 0x2c780004); c += 4; // move.l 4.w,a6 + put_long (c, 0x4eaeff4c); c += 4; // jsr Cause(a6) + put_word (c, 0x7000); c += 2; // label: moveq #0,d0 + put_word (c, RTS); // rts + + m68k_areg (regs, 1) = p1; + m68k_dreg (regs, 0) = 5; /* VERTB */ + CallLib (ctx, get_long (4), -168); /* AddIntServer */ + m68k_areg (regs, 1) = p2; + m68k_dreg (regs, 0) = 3; /* PORTS */ + CallLib (ctx, get_long (4), -168); /* AddIntServer */ } static void *picasso_copy (void *data) { - thread_alive = 1; - while (thread_alive) { - uae_sem_wait (&sem); - if (!thread_alive) - break; - if (!picasso_on) - continue; - if (dx_islost ()) - continue; - mouseupdate (); - flushpixels (); - } - thread_alive = -1; - return NULL; + thread_alive = 1; + while (thread_alive) { + uae_sem_wait (&sem); + if (!thread_alive) + break; + if (!picasso_on) + continue; + if (dx_islost ()) + continue; + mouseupdate (); + flushpixels (); + } + thread_alive = -1; + return NULL; } static uaecptr uaegfx_card_install (TrapContext *ctx, uae_u32 extrasize) { - uae_u32 functable, datatable, a2; - uaecptr openfunc, closefunc, expungefunc; - uaecptr findcardfunc, initcardfunc; - uaecptr exec = get_long (4); - - uaegfx_resid = ds (L"UAE Graphics Card 3.3"); - uaegfx_vblankname = ds (L"UAE Graphics Card VBLANK"); - uaegfx_portsname = ds (L"UAE Graphics Card PORTS"); - - /* Open */ - openfunc = here (); - calltrap (deftrap (gfx_open)); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap (gfx_close)); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap (gfx_expunge)); dw (RTS); - - /* FindCard */ - findcardfunc = here (); - calltrap (deftrap (picasso_FindCard)); dw (RTS); - - /* InitCard */ - initcardfunc = here (); - calltrap (deftrap (picasso_InitCard)); dw (RTS); - - functable = here (); - dl (openfunc); - dl (closefunc); - dl (expungefunc); - dl (EXPANSION_nullfunc); - dl (findcardfunc); - dl (initcardfunc); - dl (0xFFFFFFFF); /* end of table */ - - datatable = makedatatable (uaegfx_resid, uaegfx_resname, 0x09, -50, UAEGFX_VERSION, UAEGFX_REVISION); - - a2 = m68k_areg (regs, 2); - m68k_areg (regs, 0) = functable; - m68k_areg (regs, 1) = datatable; - m68k_areg (regs, 2) = 0; - m68k_dreg (regs, 0) = CARD_SIZEOF + extrasize; - m68k_dreg (regs, 1) = 0; - uaegfx_base = CallLib (ctx, exec, -0x54); /* MakeLibrary */ - m68k_areg (regs, 2) = a2; - if (!uaegfx_base) - return 0; - m68k_areg (regs, 1) = uaegfx_base; - CallLib (ctx, exec, -0x18c); /* AddLibrary */ - m68k_areg (regs, 1) = EXPANSION_explibname; - m68k_dreg (regs, 0) = 0; - put_long (uaegfx_base + CARD_EXPANSIONBASE, CallLib (ctx, exec, -0x228)); /* OpenLibrary */ - put_long (uaegfx_base + CARD_EXECBASE, exec); - put_long (uaegfx_base + CARD_NAME, uaegfx_resname); - put_long (uaegfx_base + CARD_RESLIST, uaegfx_base + CARD_SIZEOF); - put_long (uaegfx_base + CARD_RESLISTSIZE, extrasize); - - if (currprefs.win32_rtgvblankrate >= -1) - initvblankirq (ctx, uaegfx_base); - - if (multithreaded && thread_alive == 0) { - uae_sem_init (&sem, FALSE, FALSE); - uae_start_thread (L"rtg_copy", picasso_copy, NULL, NULL); - } - - write_log (L"uaegfx.card %d.%d init @%08X\n", UAEGFX_VERSION, UAEGFX_REVISION, uaegfx_base); - return uaegfx_base; + uae_u32 functable, datatable, a2; + uaecptr openfunc, closefunc, expungefunc; + uaecptr findcardfunc, initcardfunc; + uaecptr exec = get_long (4); + + uaegfx_resid = ds (L"UAE Graphics Card 3.3"); + uaegfx_vblankname = ds (L"UAE Graphics Card VBLANK"); + uaegfx_portsname = ds (L"UAE Graphics Card PORTS"); + + /* Open */ + openfunc = here (); + calltrap (deftrap (gfx_open)); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap (gfx_close)); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap (gfx_expunge)); dw (RTS); + + /* FindCard */ + findcardfunc = here (); + calltrap (deftrap (picasso_FindCard)); dw (RTS); + + /* InitCard */ + initcardfunc = here (); + calltrap (deftrap (picasso_InitCard)); dw (RTS); + + functable = here (); + dl (openfunc); + dl (closefunc); + dl (expungefunc); + dl (EXPANSION_nullfunc); + dl (findcardfunc); + dl (initcardfunc); + dl (0xFFFFFFFF); /* end of table */ + + datatable = makedatatable (uaegfx_resid, uaegfx_resname, 0x09, -50, UAEGFX_VERSION, UAEGFX_REVISION); + + a2 = m68k_areg (regs, 2); + m68k_areg (regs, 0) = functable; + m68k_areg (regs, 1) = datatable; + m68k_areg (regs, 2) = 0; + m68k_dreg (regs, 0) = CARD_SIZEOF + extrasize; + m68k_dreg (regs, 1) = 0; + uaegfx_base = CallLib (ctx, exec, -0x54); /* MakeLibrary */ + m68k_areg (regs, 2) = a2; + if (!uaegfx_base) + return 0; + m68k_areg (regs, 1) = uaegfx_base; + CallLib (ctx, exec, -0x18c); /* AddLibrary */ + m68k_areg (regs, 1) = EXPANSION_explibname; + m68k_dreg (regs, 0) = 0; + put_long (uaegfx_base + CARD_EXPANSIONBASE, CallLib (ctx, exec, -0x228)); /* OpenLibrary */ + put_long (uaegfx_base + CARD_EXECBASE, exec); + put_long (uaegfx_base + CARD_NAME, uaegfx_resname); + put_long (uaegfx_base + CARD_RESLIST, uaegfx_base + CARD_SIZEOF); + put_long (uaegfx_base + CARD_RESLISTSIZE, extrasize); + + if (currprefs.win32_rtgvblankrate >= -1) + initvblankirq (ctx, uaegfx_base); + + if (multithreaded && thread_alive == 0) { + uae_sem_init (&sem, FALSE, FALSE); + uae_start_thread (L"rtg_copy", picasso_copy, NULL, NULL); + } + + write_log (L"uaegfx.card %d.%d init @%08X\n", UAEGFX_VERSION, UAEGFX_REVISION, uaegfx_base); + return uaegfx_base; } #endif #ifndef UAEGFX_INTERNAL uae_u32 picasso_demux (uae_u32 arg, TrapContext *context) { - switch (arg) - { - case 16: return picasso_FindCard (context); - case 17: return picasso_FillRect (context); - case 18: return picasso_SetSwitch (context); - case 19: return picasso_SetColorArray (context); - case 20: return picasso_SetDAC (context); - case 21: return picasso_SetGC (context); - case 22: return picasso_SetPanning (context); - case 23: return picasso_CalculateBytesPerRow (context); - case 24: return picasso_BlitPlanar2Chunky (context); - case 25: return picasso_BlitRect (context); - case 26: return picasso_SetDisplay (context); - case 27: return picasso_BlitTemplate (context); - case 28: return picasso_BlitRectNoMaskComplete (context); - case 29: return picasso_InitCard (context); - case 30: return picasso_BlitPattern (context); - case 31: return picasso_InvertRect (context); - case 32: return picasso_BlitPlanar2Direct (context); - /* case 34: return picasso_WaitVerticalSync (); handled in asm-code */ - case 35: return allocated_gfxmem ? 1 : 0; - case 36: return picasso_SetSprite (context); - case 37: return picasso_SetSpritePosition (context); - case 38: return picasso_SetSpriteImage (context); - case 39: return picasso_SetSpriteColor (context); - } - return 0; + switch (arg) + { + case 16: return picasso_FindCard (context); + case 17: return picasso_FillRect (context); + case 18: return picasso_SetSwitch (context); + case 19: return picasso_SetColorArray (context); + case 20: return picasso_SetDAC (context); + case 21: return picasso_SetGC (context); + case 22: return picasso_SetPanning (context); + case 23: return picasso_CalculateBytesPerRow (context); + case 24: return picasso_BlitPlanar2Chunky (context); + case 25: return picasso_BlitRect (context); + case 26: return picasso_SetDisplay (context); + case 27: return picasso_BlitTemplate (context); + case 28: return picasso_BlitRectNoMaskComplete (context); + case 29: return picasso_InitCard (context); + case 30: return picasso_BlitPattern (context); + case 31: return picasso_InvertRect (context); + case 32: return picasso_BlitPlanar2Direct (context); + /* case 34: return picasso_WaitVerticalSync (); handled in asm-code */ + case 35: return allocated_gfxmem ? 1 : 0; + case 36: return picasso_SetSprite (context); + case 37: return picasso_SetSpritePosition (context); + case 38: return picasso_SetSpriteImage (context); + case 39: return picasso_SetSpriteColor (context); + } + return 0; } #endif void restore_p96_finish (void) { - init_alloc (); - if (uaegfx_rom && boardinfo) - inituaegfxfuncs (uaegfx_rom, boardinfo); - if (set_gc_called) { - init_picasso_screen (); - init_hz_p96 (); - } + init_alloc (); + if (uaegfx_rom && boardinfo) + inituaegfxfuncs (uaegfx_rom, boardinfo); + if (set_gc_called) { + init_picasso_screen (); + init_hz_p96 (); + } } uae_u8 *restore_p96 (uae_u8 *src) { - uae_u32 flags; - int i; + uae_u32 flags; + int i; - if (restore_u32 () != 2) + if (restore_u32 () != 2) + return src; + InitPicasso96 (); + flags = restore_u32 (); + picasso_requested_on = !!(flags & 1); + hwsprite = !!(flags & 8); + cursorvisible = !!(flags & 16); + picasso96_state.SwitchState = picasso_requested_on; + picasso_on = 0; + init_picasso_screen_called = 0; + set_gc_called = !!(flags & 2); + set_panning_called = !!(flags & 4); + interrupt_enabled = !!(flags & 32); + changed_prefs.gfxmem_size = restore_u32 (); + picasso96_state.Address = restore_u32 (); + picasso96_state.RGBFormat = restore_u32 (); + picasso96_state.Width = restore_u16 (); + picasso96_state.Height = restore_u16 (); + picasso96_state.VirtualWidth = restore_u16 (); + picasso96_state.VirtualHeight = restore_u16 (); + picasso96_state.XOffset = restore_u16 (); + picasso96_state.YOffset = restore_u16 (); + picasso96_state.GC_Depth = restore_u8 (); + picasso96_state.GC_Flags = restore_u8 (); + picasso96_state.BytesPerRow = restore_u16 (); + picasso96_state.BytesPerPixel = restore_u8 (); + uaegfx_base = restore_u32 (); + uaegfx_rom = restore_u32 (); + boardinfo = restore_u32 (); + for (i = 0; i < 4; i++) + cursorrgb[i] = restore_u32 (); + picasso96_state.HostAddress = NULL; + picasso_SetPanningInit(); + picasso96_state.Extent = picasso96_state.Address + picasso96_state.BytesPerRow * picasso96_state.VirtualHeight; return src; - InitPicasso96 (); - flags = restore_u32 (); - picasso_requested_on = !!(flags & 1); - hwsprite = !!(flags & 8); - cursorvisible = !!(flags & 16); - picasso96_state.SwitchState = picasso_requested_on; - picasso_on = 0; - init_picasso_screen_called = 0; - set_gc_called = !!(flags & 2); - set_panning_called = !!(flags & 4); - interrupt_enabled = !!(flags & 32); - changed_prefs.gfxmem_size = restore_u32 (); - picasso96_state.Address = restore_u32 (); - picasso96_state.RGBFormat = restore_u32 (); - picasso96_state.Width = restore_u16 (); - picasso96_state.Height = restore_u16 (); - picasso96_state.VirtualWidth = restore_u16 (); - picasso96_state.VirtualHeight = restore_u16 (); - picasso96_state.XOffset = restore_u16 (); - picasso96_state.YOffset = restore_u16 (); - picasso96_state.GC_Depth = restore_u8 (); - picasso96_state.GC_Flags = restore_u8 (); - picasso96_state.BytesPerRow = restore_u16 (); - picasso96_state.BytesPerPixel = restore_u8 (); - uaegfx_base = restore_u32 (); - uaegfx_rom = restore_u32 (); - boardinfo = restore_u32 (); - for (i = 0; i < 4; i++) - cursorrgb[i] = restore_u32 (); - picasso96_state.HostAddress = NULL; - picasso_SetPanningInit(); - picasso96_state.Extent = picasso96_state.Address + picasso96_state.BytesPerRow * picasso96_state.VirtualHeight; - return src; } uae_u8 *save_p96 (int *len, uae_u8 *dstptr) { - uae_u8 *dstbak, *dst; - int i; + uae_u8 *dstbak, *dst; + int i; - if (currprefs.gfxmem_size == 0) - return NULL; - if (dstptr) - dstbak = dst = dstptr; - else - dstbak = dst = malloc (1000); - save_u32 (2); - save_u32 ((picasso_on ? 1 : 0) | (set_gc_called ? 2 : 0) | (set_panning_called ? 4 : 0) | - (hwsprite ? 8 : 0) | (cursorvisible ? 16 : 0) | (interrupt_enabled ? 32 : 0)); - save_u32 (currprefs.gfxmem_size); - save_u32 (picasso96_state.Address); - save_u32 (picasso96_state.RGBFormat); - save_u16 (picasso96_state.Width); - save_u16 (picasso96_state.Height); - save_u16 (picasso96_state.VirtualWidth); - save_u16 (picasso96_state.VirtualHeight); - save_u16 (picasso96_state.XOffset); - save_u16 (picasso96_state.YOffset); - save_u8 (picasso96_state.GC_Depth); - save_u8 (picasso96_state.GC_Flags); - save_u16 (picasso96_state.BytesPerRow); - save_u8 (picasso96_state.BytesPerPixel); - save_u32 (uaegfx_base); - save_u32 (uaegfx_rom); - save_u32 (boardinfo); - for (i = 0; i < 4; i++) - save_u32 (cursorrgb[i]); - *len = dst - dstbak; - return dstbak; + if (currprefs.gfxmem_size == 0) + return NULL; + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (1000); + save_u32 (2); + save_u32 ((picasso_on ? 1 : 0) | (set_gc_called ? 2 : 0) | (set_panning_called ? 4 : 0) | + (hwsprite ? 8 : 0) | (cursorvisible ? 16 : 0) | (interrupt_enabled ? 32 : 0)); + save_u32 (currprefs.gfxmem_size); + save_u32 (picasso96_state.Address); + save_u32 (picasso96_state.RGBFormat); + save_u16 (picasso96_state.Width); + save_u16 (picasso96_state.Height); + save_u16 (picasso96_state.VirtualWidth); + save_u16 (picasso96_state.VirtualHeight); + save_u16 (picasso96_state.XOffset); + save_u16 (picasso96_state.YOffset); + save_u8 (picasso96_state.GC_Depth); + save_u8 (picasso96_state.GC_Flags); + save_u16 (picasso96_state.BytesPerRow); + save_u8 (picasso96_state.BytesPerPixel); + save_u32 (uaegfx_base); + save_u32 (uaegfx_rom); + save_u32 (boardinfo); + for (i = 0; i < 4; i++) + save_u32 (cursorrgb[i]); + *len = dst - dstbak; + return dstbak; } diff --git a/od-win32/posixemu.c b/od-win32/posixemu.c index 5528aeeb..7502232a 100644 --- a/od-win32/posixemu.c +++ b/od-win32/posixemu.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 interface - * - * Copyright 1997 Mathias Ortmann - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 interface +* +* Copyright 1997 Mathias Ortmann +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -34,23 +34,23 @@ void gettimeofday (struct timeval *tv, void *blah) { #if 1 - struct timeb time; + struct timeb time; - ftime (&time); + ftime (&time); - tv->tv_sec = time.time; - tv->tv_usec = time.millitm * 1000; + tv->tv_sec = time.time; + tv->tv_usec = time.millitm * 1000; #else - SYSTEMTIME st; - FILETIME ft; - uae_u64 v, sec; - GetSystemTime (&st); - SystemTimeToFileTime (&st, &ft); - v = (ft.dwHighDateTime << 32) | ft.dwLowDateTime; - v /= 10; - sec = v / 1000000; - tv->tv_usec = (unsigned long)(v - (sec * 1000000)); - tv->tv_sec = (unsigned long)(sec - 11644463600); + SYSTEMTIME st; + FILETIME ft; + uae_u64 v, sec; + GetSystemTime (&st); + SystemTimeToFileTime (&st, &ft); + v = (ft.dwHighDateTime << 32) | ft.dwLowDateTime; + v /= 10; + sec = v / 1000000; + tv->tv_usec = (unsigned long)(v - (sec * 1000000)); + tv->tv_sec = (unsigned long)(sec - 11644463600); #endif } @@ -60,266 +60,266 @@ void gettimeofday (struct timeval *tv, void *blah) static void get_time (time_t t, long *days, long *mins, long *ticks) { - /* time_t is secs since 1-1-1970 */ - /* days since 1-1-1978 */ - /* mins since midnight */ - /* ticks past minute @ 50Hz */ - - t -= diff; - *days = t / secs_per_day; - t -= *days * secs_per_day; - *mins = t / 60; - t -= *mins * 60; - *ticks = t * 50; + /* time_t is secs since 1-1-1970 */ + /* days since 1-1-1978 */ + /* mins since midnight */ + /* ticks past minute @ 50Hz */ + + t -= diff; + *days = t / secs_per_day; + t -= *days * secs_per_day; + *mins = t / 60; + t -= *mins * 60; + *ticks = t * 50; } static DWORD getattr (const TCHAR *name, LPFILETIME lpft, uae_u64 *size) { - HANDLE hFind; - WIN32_FIND_DATA fd; + HANDLE hFind; + WIN32_FIND_DATA fd; - if ((hFind = FindFirstFile (name, &fd)) == INVALID_HANDLE_VALUE) { - fd.dwFileAttributes = GetFileAttributes (name); - return fd.dwFileAttributes; - } - FindClose (hFind); + if ((hFind = FindFirstFile (name, &fd)) == INVALID_HANDLE_VALUE) { + fd.dwFileAttributes = GetFileAttributes (name); + return fd.dwFileAttributes; + } + FindClose (hFind); - if (lpft) - *lpft = fd.ftLastWriteTime; - if (size) - *size = (((uae_u64)fd.nFileSizeHigh) << 32) | fd.nFileSizeLow; + if (lpft) + *lpft = fd.ftLastWriteTime; + if (size) + *size = (((uae_u64)fd.nFileSizeHigh) << 32) | fd.nFileSizeLow; - return fd.dwFileAttributes; + return fd.dwFileAttributes; } int posixemu_stat (const TCHAR *name, struct _stat64 *statbuf) { - DWORD attr; - FILETIME ft, lft; + DWORD attr; + FILETIME ft, lft; - if ((attr = getattr (name, &ft, &statbuf->st_size)) == (DWORD)~0) { - return -1; - } else { - statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ : FILEFLAG_READ | FILEFLAG_WRITE; - if (attr & FILE_ATTRIBUTE_ARCHIVE) - statbuf->st_mode |= FILEFLAG_ARCHIVE; - if (attr & FILE_ATTRIBUTE_DIRECTORY) - statbuf->st_mode |= FILEFLAG_DIR; - FileTimeToLocalFileTime (&ft,&lft); - statbuf->st_mtime = (long)((*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000); - } - return 0; + if ((attr = getattr (name, &ft, &statbuf->st_size)) == (DWORD)~0) { + return -1; + } else { + statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ : FILEFLAG_READ | FILEFLAG_WRITE; + if (attr & FILE_ATTRIBUTE_ARCHIVE) + statbuf->st_mode |= FILEFLAG_ARCHIVE; + if (attr & FILE_ATTRIBUTE_DIRECTORY) + statbuf->st_mode |= FILEFLAG_DIR; + FileTimeToLocalFileTime (&ft,&lft); + statbuf->st_mtime = (long)((*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000); + } + return 0; } int posixemu_chmod (const TCHAR *name, int mode) { - DWORD attr = FILE_ATTRIBUTE_NORMAL; - if (!(mode & FILEFLAG_WRITE)) - attr |= FILE_ATTRIBUTE_READONLY; - if (mode & FILEFLAG_ARCHIVE) - attr |= FILE_ATTRIBUTE_ARCHIVE; - if (SetFileAttributes (name,attr)) - return 1; - return -1; + DWORD attr = FILE_ATTRIBUTE_NORMAL; + if (!(mode & FILEFLAG_WRITE)) + attr |= FILE_ATTRIBUTE_READONLY; + if (mode & FILEFLAG_ARCHIVE) + attr |= FILE_ATTRIBUTE_ARCHIVE; + if (SetFileAttributes (name,attr)) + return 1; + return -1; } static void tmToSystemTime (struct tm *tmtime, LPSYSTEMTIME systime) { - if (tmtime == NULL) { - GetSystemTime (systime); - } else { - systime->wDay = tmtime->tm_mday; - systime->wDayOfWeek = tmtime->tm_wday; - systime->wMonth = tmtime->tm_mon + 1; - systime->wYear = tmtime->tm_year + 1900; - systime->wHour = tmtime->tm_hour; - systime->wMinute = tmtime->tm_min; - systime->wSecond = tmtime->tm_sec; - systime->wMilliseconds = 0; - } + if (tmtime == NULL) { + GetSystemTime (systime); + } else { + systime->wDay = tmtime->tm_mday; + systime->wDayOfWeek = tmtime->tm_wday; + systime->wMonth = tmtime->tm_mon + 1; + systime->wYear = tmtime->tm_year + 1900; + systime->wHour = tmtime->tm_hour; + systime->wMinute = tmtime->tm_min; + systime->wSecond = tmtime->tm_sec; + systime->wMilliseconds = 0; + } } static int setfiletime (const TCHAR *name, unsigned int days, int minute, int tick, int tolocal) { - FILETIME LocalFileTime, FileTime; - HANDLE hFile; - - if ((hFile = CreateFile (name, GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)) == INVALID_HANDLE_VALUE) - return 0; - - for (;;) { - ULARGE_INTEGER lft; - - lft.QuadPart = (((uae_u64)(377*365+91+days)*(uae_u64)1440+(uae_u64)minute)*(uae_u64)(60*50)+(uae_u64)tick)*(uae_u64)200000; - LocalFileTime.dwHighDateTime = lft.HighPart; - LocalFileTime.dwLowDateTime = lft.LowPart; - if (tolocal) { - if (!LocalFileTimeToFileTime (&LocalFileTime, &FileTime)) - FileTime = LocalFileTime; - } else { - FileTime = LocalFileTime; + FILETIME LocalFileTime, FileTime; + HANDLE hFile; + + if ((hFile = CreateFile (name, GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)) == INVALID_HANDLE_VALUE) + return 0; + + for (;;) { + ULARGE_INTEGER lft; + + lft.QuadPart = (((uae_u64)(377*365+91+days)*(uae_u64)1440+(uae_u64)minute)*(uae_u64)(60*50)+(uae_u64)tick)*(uae_u64)200000; + LocalFileTime.dwHighDateTime = lft.HighPart; + LocalFileTime.dwLowDateTime = lft.LowPart; + if (tolocal) { + if (!LocalFileTimeToFileTime (&LocalFileTime, &FileTime)) + FileTime = LocalFileTime; + } else { + FileTime = LocalFileTime; + } + if (!SetFileTime (hFile, &FileTime, &FileTime, &FileTime)) { + if (days > 47846) { // > 2108-12-31 (fat limit) + days = 47846; + continue; + } + if (days < 730) { // < 1980-01-01 (fat limit) + days = 730; + continue; + } + } + break; } - if (!SetFileTime (hFile, &FileTime, &FileTime, &FileTime)) { - if (days > 47846) { // > 2108-12-31 (fat limit) - days = 47846; - continue; - } - if (days < 730) { // < 1980-01-01 (fat limit) - days = 730; - continue; - } - } - break; - } - CloseHandle (hFile); + CloseHandle (hFile); - return 1; + return 1; } int posixemu_utime (const TCHAR *name, struct utimbuf *ttime) { - int result = -1, tolocal; - long days, mins, ticks; - time_t actime; - - if (!ttime) { - actime = time (NULL); - tolocal = 0; - } else { - tolocal = 1; - actime = ttime->actime; - } - get_time (actime, &days, &mins, &ticks); - - if (setfiletime (name, days, mins, ticks, tolocal)) - result = 0; - - return result; + int result = -1, tolocal; + long days, mins, ticks; + time_t actime; + + if (!ttime) { + actime = time (NULL); + tolocal = 0; + } else { + tolocal = 1; + actime = ttime->actime; + } + get_time (actime, &days, &mins, &ticks); + + if (setfiletime (name, days, mins, ticks, tolocal)) + result = 0; + + return result; } void uae_sem_init (uae_sem_t * event, int manual_reset, int initial_state) { - if(*event) { - if (initial_state) - SetEvent (*event); - else - ResetEvent (*event); - } else { - *event = CreateEvent (NULL, manual_reset, initial_state, NULL); - } + if(*event) { + if (initial_state) + SetEvent (*event); + else + ResetEvent (*event); + } else { + *event = CreateEvent (NULL, manual_reset, initial_state, NULL); + } } void uae_sem_wait (uae_sem_t * event) { - WaitForSingleObject (*event, INFINITE); + WaitForSingleObject (*event, INFINITE); } void uae_sem_post (uae_sem_t * event) { - SetEvent (*event); + SetEvent (*event); } int uae_sem_trywait (uae_sem_t * event) { - return WaitForSingleObject (*event, 0) == WAIT_OBJECT_0 ? 0 : -1; + return WaitForSingleObject (*event, 0) == WAIT_OBJECT_0 ? 0 : -1; } void uae_sem_destroy (uae_sem_t * event) { - if (*event) { - CloseHandle (*event); - *event = NULL; - } + if (*event) { + CloseHandle (*event); + *event = NULL; + } } typedef unsigned (__stdcall *BEGINTHREADEX_FUNCPTR)(void *); struct thparms { - void *(*f)(void*); - void *arg; + void *(*f)(void*); + void *arg; }; static unsigned __stdcall thread_init (void *f) { - struct thparms *thp = f; - void *(*fp)(void*) = thp->f; - void *arg = thp->arg; + struct thparms *thp = f; + void *(*fp)(void*) = thp->f; + void *arg = thp->arg; - xfree (f); + xfree (f); #ifndef _CONSOLE - __try { - fp (arg); + __try { + fp (arg); #endif #ifndef _CONSOLE - } __except (WIN32_ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { - } + } __except (WIN32_ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { + } #endif - return 0; + return 0; } void uae_end_thread (uae_thread_id *tid) { - if (tid) { - CloseHandle (*tid); - *tid = NULL; - } + if (tid) { + CloseHandle (*tid); + *tid = NULL; + } } int uae_start_thread (TCHAR *name, void *(*f)(void *), void *arg, uae_thread_id *tid) { - HANDLE hThread; - int result = 1; - unsigned foo; - struct thparms *thp; - - thp = xmalloc (sizeof (struct thparms)); - thp->f = f; - thp->arg = arg; - hThread = (HANDLE)_beginthreadex (NULL, 0, thread_init, thp, 0, &foo); - if (hThread) { - if (name) - write_log (L"Thread '%s' started (%d)\n", name, hThread); - } else { - result = 0; - write_log (L"Thread '%s' failed to start!?\n", name ? name : L""); - } - if (tid) - *tid = hThread; - else - CloseHandle (hThread); - return result; + HANDLE hThread; + int result = 1; + unsigned foo; + struct thparms *thp; + + thp = xmalloc (sizeof (struct thparms)); + thp->f = f; + thp->arg = arg; + hThread = (HANDLE)_beginthreadex (NULL, 0, thread_init, thp, 0, &foo); + if (hThread) { + if (name) + write_log (L"Thread '%s' started (%d)\n", name, hThread); + } else { + result = 0; + write_log (L"Thread '%s' failed to start!?\n", name ? name : L""); + } + if (tid) + *tid = hThread; + else + CloseHandle (hThread); + return result; } int uae_start_thread_fast (void *(*f)(void *), void *arg, uae_thread_id *tid) { - int v = uae_start_thread (NULL, f, arg, tid); - if (*tid) - SetThreadPriority (*tid, THREAD_PRIORITY_HIGHEST); - return v; + int v = uae_start_thread (NULL, f, arg, tid); + if (*tid) + SetThreadPriority (*tid, THREAD_PRIORITY_HIGHEST); + return v; } DWORD_PTR cpu_affinity = 1, cpu_paffinity = 1; void uae_set_thread_priority (uae_thread_id *tid, int pri) { - int pri2; - HANDLE th; - - if (tid) - th = *tid; - else - th = GetCurrentThread (); - pri2 = GetThreadPriority (th); - if (pri2 == THREAD_PRIORITY_ERROR_RETURN) - pri2 = 0; - pri2 += pri; - if (pri2 > 1) - pri2 = 1; - if (pri2 < -1) - pri2 = -1; - SetThreadPriority (th, pri2); + int pri2; + HANDLE th; + + if (tid) + th = *tid; + else + th = GetCurrentThread (); + pri2 = GetThreadPriority (th); + if (pri2 == THREAD_PRIORITY_ERROR_RETURN) + pri2 = 0; + pri2 += pri; + if (pri2 > 1) + pri2 = 1; + if (pri2 < -1) + pri2 = -1; + SetThreadPriority (th, pri2); } diff --git a/od-win32/registry.c b/od-win32/registry.c index dafec491..a291666f 100644 --- a/od-win32/registry.c +++ b/od-win32/registry.c @@ -14,443 +14,443 @@ static TCHAR *inipath; static HKEY gr (UAEREG *root) { - if (!root) - return hWinUAEKey; - return root->fkey; + if (!root) + return hWinUAEKey; + return root->fkey; } static TCHAR *gs (UAEREG *root) { - if (!root) - return L"WinUAE"; - return root->inipath; + if (!root) + return L"WinUAE"; + return root->inipath; } static TCHAR *gsn (UAEREG *root, const TCHAR *name) { - TCHAR *r, *s; - if (!root) - return my_strdup (name); - r = gs (root); - s = xmalloc ((_tcslen (r) + 1 + _tcslen (name) + 1) * sizeof (TCHAR)); - _stprintf (s, L"%s/%s", r, name); - return s; + TCHAR *r, *s; + if (!root) + return my_strdup (name); + r = gs (root); + s = xmalloc ((_tcslen (r) + 1 + _tcslen (name) + 1) * sizeof (TCHAR)); + _stprintf (s, L"%s/%s", r, name); + return s; } int regsetstr (UAEREG *root, const TCHAR *name, const TCHAR *str) { - if (inimode) { - DWORD ret; - ret = WritePrivateProfileString (gs (root), name, str, inipath); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegSetValueEx (rk, name, 0, REG_SZ, (CONST BYTE *)str, (_tcslen (str) + 1) * sizeof (TCHAR)) == ERROR_SUCCESS; - } + if (inimode) { + DWORD ret; + ret = WritePrivateProfileString (gs (root), name, str, inipath); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegSetValueEx (rk, name, 0, REG_SZ, (CONST BYTE *)str, (_tcslen (str) + 1) * sizeof (TCHAR)) == ERROR_SUCCESS; + } } int regsetint (UAEREG *root, const TCHAR *name, int val) { - if (inimode) { - DWORD ret; - TCHAR tmp[100]; - _stprintf (tmp, L"%d", val); - ret = WritePrivateProfileString (gs (root), name, tmp, inipath); - return ret; - } else { - DWORD v = val; - HKEY rk = gr (root); - if (!rk) - return 0; - return RegSetValueEx(rk, name, 0, REG_DWORD, (CONST BYTE*)&v, sizeof (DWORD)) == ERROR_SUCCESS; - } + if (inimode) { + DWORD ret; + TCHAR tmp[100]; + _stprintf (tmp, L"%d", val); + ret = WritePrivateProfileString (gs (root), name, tmp, inipath); + return ret; + } else { + DWORD v = val; + HKEY rk = gr (root); + if (!rk) + return 0; + return RegSetValueEx(rk, name, 0, REG_DWORD, (CONST BYTE*)&v, sizeof (DWORD)) == ERROR_SUCCESS; + } } int regqueryint (UAEREG *root, const TCHAR *name, int *val) { - if (inimode) { - int ret = 0; - TCHAR tmp[100]; - GetPrivateProfileString (gs (root), name, PUPPA, tmp, sizeof (tmp) / sizeof (TCHAR), inipath); - if (_tcscmp (tmp, PUPPA)) { - *val = _tstol (tmp); - ret = 1; + if (inimode) { + int ret = 0; + TCHAR tmp[100]; + GetPrivateProfileString (gs (root), name, PUPPA, tmp, sizeof (tmp) / sizeof (TCHAR), inipath); + if (_tcscmp (tmp, PUPPA)) { + *val = _tstol (tmp); + ret = 1; + } + return ret; + } else { + DWORD dwType = REG_DWORD; + DWORD size = sizeof (int); + HKEY rk = gr (root); + if (!rk) + return 0; + return RegQueryValueEx (rk, name, 0, &dwType, (LPBYTE)val, &size) == ERROR_SUCCESS; } - return ret; - } else { - DWORD dwType = REG_DWORD; - DWORD size = sizeof (int); - HKEY rk = gr (root); - if (!rk) - return 0; - return RegQueryValueEx (rk, name, 0, &dwType, (LPBYTE)val, &size) == ERROR_SUCCESS; - } } int regquerystr (UAEREG *root, const TCHAR *name, TCHAR *str, int *size) { - if (inimode) { - int ret = 0; - TCHAR *tmp = xmalloc (((*size) + 1) * sizeof (TCHAR)); - GetPrivateProfileString (gs (root), name, PUPPA, tmp, *size, inipath); - if (_tcscmp (tmp, PUPPA)) { - _tcscpy (str, tmp); - ret = 1; + if (inimode) { + int ret = 0; + TCHAR *tmp = xmalloc (((*size) + 1) * sizeof (TCHAR)); + GetPrivateProfileString (gs (root), name, PUPPA, tmp, *size, inipath); + if (_tcscmp (tmp, PUPPA)) { + _tcscpy (str, tmp); + ret = 1; + } + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegQueryValueEx (rk, name, 0, NULL, (LPBYTE)str, size) == ERROR_SUCCESS; } - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegQueryValueEx (rk, name, 0, NULL, (LPBYTE)str, size) == ERROR_SUCCESS; - } } int regenumstr (UAEREG *root, int idx, TCHAR *name, int *nsize, TCHAR *str, int *size) { - name[0] = 0; - str[0] = 0; - if (inimode) { - int ret = 0; - int tmpsize = 65536; - TCHAR *tmp = xmalloc (tmpsize * sizeof (TCHAR)); - if (GetPrivateProfileSection (gs (root), tmp, tmpsize, inipath) > 0) { - int i; - TCHAR *p = tmp, *p2; - for (i = 0; i < idx; i++) { - if (p[0] == 0) - break; - p += _tcslen (p) + 1; - } - if (p[0]) { - p2 = _tcschr (p, '='); - *p2++ = 0; - _tcscpy_s (name, *nsize, p); - _tcscpy_s (str, *size, p2); - ret = 1; - } + name[0] = 0; + str[0] = 0; + if (inimode) { + int ret = 0; + int tmpsize = 65536; + TCHAR *tmp = xmalloc (tmpsize * sizeof (TCHAR)); + if (GetPrivateProfileSection (gs (root), tmp, tmpsize, inipath) > 0) { + int i; + TCHAR *p = tmp, *p2; + for (i = 0; i < idx; i++) { + if (p[0] == 0) + break; + p += _tcslen (p) + 1; + } + if (p[0]) { + p2 = _tcschr (p, '='); + *p2++ = 0; + _tcscpy_s (name, *nsize, p); + _tcscpy_s (str, *size, p2); + ret = 1; + } + } + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegEnumValue (rk, idx, name, nsize, NULL, NULL, (LPBYTE)str, size) == ERROR_SUCCESS; } - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegEnumValue (rk, idx, name, nsize, NULL, NULL, (LPBYTE)str, size) == ERROR_SUCCESS; - } } int regquerydatasize (UAEREG *root, const TCHAR *name, int *size) { - if (inimode) { - int ret = 0; - int csize = 65536; - TCHAR *tmp = xmalloc (csize * sizeof (TCHAR)); - if (regquerystr (root, name, tmp, &csize)) { - *size = _tcslen (tmp) / 2; - ret = 1; + if (inimode) { + int ret = 0; + int csize = 65536; + TCHAR *tmp = xmalloc (csize * sizeof (TCHAR)); + if (regquerystr (root, name, tmp, &csize)) { + *size = _tcslen (tmp) / 2; + ret = 1; + } + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegQueryValueEx(rk, name, 0, NULL, NULL, size) == ERROR_SUCCESS; } - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegQueryValueEx(rk, name, 0, NULL, NULL, size) == ERROR_SUCCESS; - } } int regsetdata (UAEREG *root, const TCHAR *name, void *str, int size) { - if (inimode) { - uae_u8 *in = str; - DWORD ret; - int i; - TCHAR *tmp = xmalloc ((size * 2 + 1) * sizeof (TCHAR)); - for (i = 0; i < size; i++) - _stprintf (tmp + i * 2, L"%02X", in[i]); - ret = WritePrivateProfileString (gs (root), name, tmp, inipath); - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegSetValueEx(rk, name, 0, REG_BINARY, (BYTE*)str, size) == ERROR_SUCCESS; - } + if (inimode) { + uae_u8 *in = str; + DWORD ret; + int i; + TCHAR *tmp = xmalloc ((size * 2 + 1) * sizeof (TCHAR)); + for (i = 0; i < size; i++) + _stprintf (tmp + i * 2, L"%02X", in[i]); + ret = WritePrivateProfileString (gs (root), name, tmp, inipath); + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegSetValueEx(rk, name, 0, REG_BINARY, (BYTE*)str, size) == ERROR_SUCCESS; + } } int regquerydata (UAEREG *root, const TCHAR *name, void *str, int *size) { - if (inimode) { - int csize = (*size) * 2 + 1; - int i, j; - int ret = 0; - TCHAR *tmp = xmalloc (csize * sizeof (TCHAR)); - uae_u8 *out = str; + if (inimode) { + int csize = (*size) * 2 + 1; + int i, j; + int ret = 0; + TCHAR *tmp = xmalloc (csize * sizeof (TCHAR)); + uae_u8 *out = str; - if (!regquerystr (root, name, tmp, &csize)) - goto err; - j = 0; - for (i = 0; i < _tcslen (tmp); i += 2) { - TCHAR c1 = toupper(tmp[i + 0]); - TCHAR c2 = toupper(tmp[i + 1]); - if (c1 >= 'A') - c1 -= 'A' - 10; - else if (c1 >= '0') - c1 -= '0'; - if (c1 > 15) - goto err; - if (c2 >= 'A') - c2 -= 'A' - 10; - else if (c2 >= '0') - c2 -= '0'; - if (c2 > 15) - goto err; - out[j++] = c1 * 16 + c2; + if (!regquerystr (root, name, tmp, &csize)) + goto err; + j = 0; + for (i = 0; i < _tcslen (tmp); i += 2) { + TCHAR c1 = toupper(tmp[i + 0]); + TCHAR c2 = toupper(tmp[i + 1]); + if (c1 >= 'A') + c1 -= 'A' - 10; + else if (c1 >= '0') + c1 -= '0'; + if (c1 > 15) + goto err; + if (c2 >= 'A') + c2 -= 'A' - 10; + else if (c2 >= '0') + c2 -= '0'; + if (c2 > 15) + goto err; + out[j++] = c1 * 16 + c2; + } + ret = 1; +err: + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegQueryValueEx(rk, name, 0, NULL, str, size) == ERROR_SUCCESS; } - ret = 1; - err: - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegQueryValueEx(rk, name, 0, NULL, str, size) == ERROR_SUCCESS; - } } int regdelete (UAEREG *root, const TCHAR *name) { - if (inimode) { - WritePrivateProfileString (gs (root), name, NULL, inipath); - return 1; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegDeleteValue (rk, name) == ERROR_SUCCESS; - } + if (inimode) { + WritePrivateProfileString (gs (root), name, NULL, inipath); + return 1; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegDeleteValue (rk, name) == ERROR_SUCCESS; + } } int regexists (UAEREG *root, const TCHAR *name) { - if (inimode) { - int ret = 1; - TCHAR *tmp = xmalloc ((_tcslen (PUPPA) + 1) * sizeof (TCHAR)); - int size = _tcslen (PUPPA) + 1; - GetPrivateProfileString (gs (root), name, PUPPA, tmp, size, inipath); - if (!_tcscmp (tmp, PUPPA)) - ret = 0; - xfree (tmp); - return ret; - } else { - HKEY rk = gr (root); - if (!rk) - return 0; - return RegQueryValueEx(rk, name, 0, NULL, NULL, NULL) == ERROR_SUCCESS; - } + if (inimode) { + int ret = 1; + TCHAR *tmp = xmalloc ((_tcslen (PUPPA) + 1) * sizeof (TCHAR)); + int size = _tcslen (PUPPA) + 1; + GetPrivateProfileString (gs (root), name, PUPPA, tmp, size, inipath); + if (!_tcscmp (tmp, PUPPA)) + ret = 0; + xfree (tmp); + return ret; + } else { + HKEY rk = gr (root); + if (!rk) + return 0; + return RegQueryValueEx(rk, name, 0, NULL, NULL, NULL) == ERROR_SUCCESS; + } } void regdeletetree (UAEREG *root, const TCHAR *name) { - if (inimode) { - TCHAR *s = gsn (root, name); - if (!s) - return; - WritePrivateProfileSection (s, L"", inipath); - xfree (s); - } else { - HKEY rk = gr (root); - if (!rk) - return; - SHDeleteKey (rk, name); - } + if (inimode) { + TCHAR *s = gsn (root, name); + if (!s) + return; + WritePrivateProfileSection (s, L"", inipath); + xfree (s); + } else { + HKEY rk = gr (root); + if (!rk) + return; + SHDeleteKey (rk, name); + } } int regexiststree (UAEREG *root, const TCHAR *name) { - if (inimode) { - int ret = 0; - int tmpsize = 65536; - TCHAR *p, *tmp; - TCHAR *s = gsn (root, name); - if (!s) - return 0; - tmp = xmalloc (tmpsize); - tmp[0] = 0; - GetPrivateProfileSectionNames (tmp, tmpsize, inipath); - p = tmp; - while (p[0]) { - if (!_tcscmp (p, name)) { - ret = 1; - break; - } - p += _tcslen (p) + 1; + if (inimode) { + int ret = 0; + int tmpsize = 65536; + TCHAR *p, *tmp; + TCHAR *s = gsn (root, name); + if (!s) + return 0; + tmp = xmalloc (tmpsize); + tmp[0] = 0; + GetPrivateProfileSectionNames (tmp, tmpsize, inipath); + p = tmp; + while (p[0]) { + if (!_tcscmp (p, name)) { + ret = 1; + break; + } + p += _tcslen (p) + 1; + } + xfree (tmp); + xfree (s); + return ret; + } else { + int ret = 0; + HKEY k = NULL; + HKEY rk = gr (root); + if (!rk) + return 0; + if (RegOpenKeyEx (rk , name, 0, KEY_READ, &k) == ERROR_SUCCESS) + ret = 1; + if (k) + RegCloseKey (k); + return ret; } - xfree (tmp); - xfree (s); - return ret; - } else { - int ret = 0; - HKEY k = NULL; - HKEY rk = gr (root); - if (!rk) - return 0; - if (RegOpenKeyEx (rk , name, 0, KEY_READ, &k) == ERROR_SUCCESS) - ret = 1; - if (k) - RegCloseKey (k); - return ret; - } } UAEREG *regcreatetree (UAEREG *root, const TCHAR *name) { - UAEREG *fkey; - HKEY rkey; + UAEREG *fkey; + HKEY rkey; - if (inimode) { - TCHAR *ininame; - if (!root) { - if (!name) - ininame = my_strdup (gs (NULL)); - else - ininame = my_strdup (name); + if (inimode) { + TCHAR *ininame; + if (!root) { + if (!name) + ininame = my_strdup (gs (NULL)); + else + ininame = my_strdup (name); + } else { + ininame = xmalloc ((_tcslen (root->inipath) + 1 + _tcslen (name) + 1) * sizeof (TCHAR)); + _stprintf (ininame, L"%s/%s", root->inipath, name); + } + fkey = xcalloc (sizeof (UAEREG), 1); + fkey->inipath = ininame; } else { - ininame = xmalloc ((_tcslen (root->inipath) + 1 + _tcslen (name) + 1) * sizeof (TCHAR)); - _stprintf (ininame, L"%s/%s", root->inipath, name); - } - fkey = xcalloc (sizeof (UAEREG), 1); - fkey->inipath = ininame; - } else { - DWORD err; - HKEY rk = gr (root); - if (!rk) { - rk = HKEY_CURRENT_USER; - name = L"Software\\Arabuusimiehet\\WinUAE"; - } else if (!name) { - name = L""; + DWORD err; + HKEY rk = gr (root); + if (!rk) { + rk = HKEY_CURRENT_USER; + name = L"Software\\Arabuusimiehet\\WinUAE"; + } else if (!name) { + name = L""; + } + err = RegCreateKeyEx (rk, name, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_READ | KEY_WRITE, NULL, &rkey, NULL); + if (err != ERROR_SUCCESS) + return 0; + fkey = xcalloc (sizeof (UAEREG), 1); + fkey->fkey = rkey; } - err = RegCreateKeyEx (rk, name, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_READ | KEY_WRITE, NULL, &rkey, NULL); - if (err != ERROR_SUCCESS) - return 0; - fkey = xcalloc (sizeof (UAEREG), 1); - fkey->fkey = rkey; - } - return fkey; + return fkey; } void regclosetree (UAEREG *key) { - if (!key) - return; - if (key->fkey) - RegCloseKey (key->fkey); - xfree (key->inipath); - xfree (key); + if (!key) + return; + if (key->fkey) + RegCloseKey (key->fkey); + xfree (key->inipath); + xfree (key); } static uae_u8 crcok[20] = { 0xaf,0xb7,0x36,0x15,0x05,0xca,0xe6,0x9d,0x23,0x17,0x4d,0x50,0x2b,0x5c,0xc3,0x64,0x38,0xb8,0x4e,0xfc }; int reginitializeinit (const TCHAR *ppath) { - UAEREG *r = NULL; - TCHAR tmp1[1000]; - uae_u8 crc[20]; - int s, v1, v2, v3; - TCHAR path[MAX_DPATH], fpath[MAX_PATH]; - FILE *f; + UAEREG *r = NULL; + TCHAR tmp1[1000]; + uae_u8 crc[20]; + int s, v1, v2, v3; + TCHAR path[MAX_DPATH], fpath[MAX_PATH]; + FILE *f; - if (!ppath) { - int ok = 0; - TCHAR *posn; - _tcscpy (path, _wpgmptr); - if (_tcslen (path) > 4 && !_tcsicmp (path + _tcslen (path) - 4, L".exe")) { - _tcscpy (path + _tcslen (path) - 3, L"ini"); - if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) - ok = 1; - } - if (!ok) { - _tcscpy (path, _wpgmptr); - if((posn = _tcsrchr (path, '\\'))) - posn[1] = 0; - _tcscat (path, L"winuae.ini"); + if (!ppath) { + int ok = 0; + TCHAR *posn; + _tcscpy (path, _wpgmptr); + if (_tcslen (path) > 4 && !_tcsicmp (path + _tcslen (path) - 4, L".exe")) { + _tcscpy (path + _tcslen (path) - 3, L"ini"); + if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) + ok = 1; + } + if (!ok) { + _tcscpy (path, _wpgmptr); + if((posn = _tcsrchr (path, '\\'))) + posn[1] = 0; + _tcscat (path, L"winuae.ini"); + } + if (GetFileAttributes (path) == INVALID_FILE_ATTRIBUTES) + return 0; + } else { + _tcscpy (path, ppath); } - if (GetFileAttributes (path) == INVALID_FILE_ATTRIBUTES) - return 0; - } else { - _tcscpy (path, ppath); - } - fpath[0] = 0; - GetFullPathName (path, sizeof fpath / sizeof (TCHAR), fpath, NULL); - if (_tcslen (fpath) < 5 || _tcsicmp (fpath + _tcslen (fpath) - 4, L".ini")) - return 0; + fpath[0] = 0; + GetFullPathName (path, sizeof fpath / sizeof (TCHAR), fpath, NULL); + if (_tcslen (fpath) < 5 || _tcsicmp (fpath + _tcslen (fpath) - 4, L".ini")) + return 0; - inimode = 1; - inipath = my_strdup (fpath); - if (!regexists (NULL, L"Version")) - goto fail; - r = regcreatetree (NULL, L"Warning"); - if (!r) - goto fail; - memset (tmp1, 0, sizeof tmp1); - s = 200; - if (!regquerystr (r, L"info1", tmp1, &s)) - goto fail; - if (!regquerystr (r, L"info2", tmp1 + 200, &s)) - goto fail; - get_sha1 (tmp1, sizeof tmp1, crc); - if (memcmp (crc, crcok, sizeof crcok)) - goto fail; - v1 = v2 = -1; - regsetint (r, L"check", 1); - regqueryint (r, L"check", &v1); - regsetint (r, L"check", 3); - regqueryint (r, L"check", &v2); - regdelete (r, L"check"); - if (regqueryint (r, L"check", &v3)) - goto fail; - if (v1 != 1 || v2 != 3) - goto fail; - regclosetree (r); - return 1; + inimode = 1; + inipath = my_strdup (fpath); + if (!regexists (NULL, L"Version")) + goto fail; + r = regcreatetree (NULL, L"Warning"); + if (!r) + goto fail; + memset (tmp1, 0, sizeof tmp1); + s = 200; + if (!regquerystr (r, L"info1", tmp1, &s)) + goto fail; + if (!regquerystr (r, L"info2", tmp1 + 200, &s)) + goto fail; + get_sha1 (tmp1, sizeof tmp1, crc); + if (memcmp (crc, crcok, sizeof crcok)) + goto fail; + v1 = v2 = -1; + regsetint (r, L"check", 1); + regqueryint (r, L"check", &v1); + regsetint (r, L"check", 3); + regqueryint (r, L"check", &v2); + regdelete (r, L"check"); + if (regqueryint (r, L"check", &v3)) + goto fail; + if (v1 != 1 || v2 != 3) + goto fail; + regclosetree (r); + return 1; fail: - regclosetree (r); - if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) - DeleteFile (path); - if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) - goto end; - f = _tfopen (path, L"wb"); - if (f) { - uae_u8 bom[3] = { 0xef, 0xbb, 0xbf }; - fwrite (bom, sizeof (bom), 1, f); - fclose (f); - } - r = regcreatetree (NULL, L"Warning"); - if (!r) - goto end; - regsetstr (r, L"info1", L"This is unsupported file. Compatibility between versions is not guaranteed."); - regsetstr (r, L"info2", L"Incompatible ini-files may be re-created from scratch!"); - regclosetree (r); - return 1; + regclosetree (r); + if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) + DeleteFile (path); + if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES) + goto end; + f = _tfopen (path, L"wb"); + if (f) { + uae_u8 bom[3] = { 0xef, 0xbb, 0xbf }; + fwrite (bom, sizeof (bom), 1, f); + fclose (f); + } + r = regcreatetree (NULL, L"Warning"); + if (!r) + goto end; + regsetstr (r, L"info1", L"This is unsupported file. Compatibility between versions is not guaranteed."); + regsetstr (r, L"info2", L"Incompatible ini-files may be re-created from scratch!"); + regclosetree (r); + return 1; end: - inimode = 0; - xfree (inipath); - return 0; + inimode = 0; + xfree (inipath); + return 0; } void regstatus (void) { - if (inimode) - write_log (L"WARNING: Unsupported '%s' enabled\n", inipath); + if (inimode) + write_log (L"WARNING: Unsupported '%s' enabled\n", inipath); } int getregmode (void) { - return inimode; + return inimode; } diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index e2e66e8a..013e317c 100644 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -15,10 +15,8 @@ // English (Neutral) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL #pragma code_page(1252) -#endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // @@ -58,7 +56,7 @@ IDI_FILE ICON "file.ico" // Accelerator // -IDR_DBGACCEL ACCELERATORS +IDR_DBGACCEL ACCELERATORS BEGIN VK_F1, ID_DBG_PAGE1, VIRTKEY, NOINVERT VK_F2, ID_DBG_PAGE2, VIRTKEY, NOINVERT @@ -183,7 +181,7 @@ IDD_CPU DIALOGEX 0, 0, 300, 241 STYLE DS_LOCALEDIT | DS_SETFONT | DS_3DLOOK | DS_CONTROL | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN - GROUPBOX "CPU",IDC_STATIC,5,1,81,145,BS_LEFT + GROUPBOX "CPU",IDC_STATIC,5,1,81,144,BS_LEFT CONTROL "68000",IDC_CPU0,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,13,15,63,10 CONTROL "68010",IDC_CPU1,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,13,28,65,10 CONTROL "68020",IDC_CPU2,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,13,41,63,10 @@ -1045,7 +1043,7 @@ IDC_MYHAND CURSOR "H_arrow.cur" // Menu // -IDM_SYSTRAY MENU +IDM_SYSTRAY MENU BEGIN POPUP "Menu" BEGIN @@ -1064,7 +1062,7 @@ BEGIN END END -IDM_DBGCONTEXTMENU MENU +IDM_DBGCONTEXTMENU MENU BEGIN POPUP "Inactive" BEGIN @@ -1140,8 +1138,12 @@ IDB_LCD160X43 BITMAP "lcd.bmp" // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO +GUIDELINES DESIGNINFO BEGIN + IDD_CPU, DIALOG + BEGIN + END + IDD_FILTER, DIALOG BEGIN BOTTOMMARGIN, 237 @@ -1155,7 +1157,7 @@ END // String Table // -STRINGTABLE +STRINGTABLE BEGIN IDS_KICKSTART "ROM" IDS_DISK "Disk swapper" @@ -1174,7 +1176,7 @@ BEGIN IDS_FILTER "Filter" END -STRINGTABLE +STRINGTABLE BEGIN IDS_MISC2 "Pri. & Extensions" IDS_PATHS "Paths" @@ -1185,7 +1187,7 @@ BEGIN IDS_EXPANSION "Expansions" END -STRINGTABLE +STRINGTABLE BEGIN IDS_EXTTEXT "Floppy disk image files" IDS_EXTACTUAL "ADF" @@ -1201,7 +1203,7 @@ BEGIN IDS_EIGHTH "eighth " END -STRINGTABLE +STRINGTABLE BEGIN IDS_NINTH "ninth " IDS_TENTH "tenth " @@ -1221,7 +1223,7 @@ BEGIN IDS_VOLUME "Volume" END -STRINGTABLE +STRINGTABLE BEGIN IDS_SELECTFILESYSROOT "Please select the root directory of the file system..." IDS_DEFAULTMIDIOUT "Default MIDI-Out Device" @@ -1240,7 +1242,7 @@ BEGIN IDS_MIDIOVERFLOW "Sysexbuffer overflow. Should not happen. Please report this to\nberndroesch1@compuserve.de" END -STRINGTABLE +STRINGTABLE BEGIN IDS_PATH "Path" IDS_RW "R/W" @@ -1256,7 +1258,7 @@ BEGIN IDS_INVALIDCOMPORT "The serial port you have in this configuration is not valid on this machine.\n" END -STRINGTABLE +STRINGTABLE BEGIN IDS_HFDSIZE "Size" IDS_DEVICE "Device" @@ -1275,7 +1277,7 @@ BEGIN IDS_DEFAULT_WINUAE "WinUAE default (old)" END -STRINGTABLE +STRINGTABLE BEGIN IDS_SOUND_STEREO2 "Cloned Stereo (4 Channels)" IDS_INPUT_CUSTOMEVENT "" @@ -1288,7 +1290,7 @@ BEGIN IDS_NETDISCONNECTED "Cable disconnected" END -STRINGTABLE +STRINGTABLE BEGIN IDS_UNSUPPORTEDPIXELFORMAT "Error: unsupported pixel format. Please use a different screen mode.\n" @@ -1307,7 +1309,7 @@ BEGIN IDS_ERRORTITLE "WinUAE message" END -STRINGTABLE +STRINGTABLE BEGIN IDS_INP "WinUAE Input Recording" IDS_RESTOREINP "Playback a WinUAE input recording" @@ -1325,7 +1327,7 @@ BEGIN IDS_SOUND_FILTER_EMULATED "Emulated (A500)" END -STRINGTABLE +STRINGTABLE BEGIN IDS_SOUND_FILTER_EMULATED_E "Emulated (A1200)" IDS_INPUT_COMPATIBILITY "Compatibility mode" @@ -1347,7 +1349,7 @@ BEGIN "the desktop is running in an unknown color mode." END -STRINGTABLE +STRINGTABLE BEGIN IDS_UNSUPPORTEDSCREENMODE_2 "the desktop is running in 8-bit color depth, which WinUAE can't use in windowed mode." @@ -1370,7 +1372,7 @@ BEGIN IDS_TREEVIEW_ABOUT "About" END -STRINGTABLE +STRINGTABLE BEGIN IDS_NOHARDDRIVES "No hard disks detected that were either empty or RDB-partitioned." IDS_DEFAULT_HOST "Default Configuration" @@ -1390,7 +1392,7 @@ BEGIN IDS_FLOPPYTYPE35DDESCOM "3.5"" ESCOM" END -STRINGTABLE +STRINGTABLE BEGIN IDS_NUMSG_NEEDEXT2 "The software uses a non-standard floppy disk format. You may need to use a custom floppy disk image file instead of a standard one. This message will not appear again." IDS_NUMSG_NOROMKEY "Could not find system ROM key file." @@ -1398,7 +1400,7 @@ BEGIN IDS_NUMSG_KSROMREADERROR "Error while reading system ROM." END -STRINGTABLE +STRINGTABLE BEGIN IDS_NUMSG_NOEXTROM "No extended ROM found." IDS_NUMSG_MODRIP_NOTFOUND "No music modules or packed data found." @@ -1418,7 +1420,7 @@ BEGIN IDS_ROMSCANEND "Scan of ROMs finished" END -STRINGTABLE +STRINGTABLE BEGIN IDS_ROM_AVAILABLE "available" IDS_ROM_UNAVAILABLE "unavailable" @@ -1435,7 +1437,7 @@ BEGIN IDS_SB_CUSTOMEVENT "Enter custom event string.." END -STRINGTABLE +STRINGTABLE BEGIN IDS_QS_MODELS "A500\nA500+\nA600\nA1000\nA1200\nA3000\nA4000\nCD32\nCDTV\nArcadia Multi Select system\nExpanded WinUAE example configuration" IDS_QS_MODEL_A500 "1.3 ROM, OCS, 512 KB Chip + 512 KB Slow RAM (most common)\nThis configuration is capable of running most games and demos produced for first-generation hardware. Only few exceptions need a different configuration (e.g. the oldest games tend to be incompatible with this configuration).\n1.3 ROM, ECS Agnus, 512 KB Chip RAM + 512 KB Slow RAM\nLater hardware revision of the A500. Nearly 100% compatible with the previous configuration.\n1.3 ROM, ECS Agnus, 1 MB Chip RAM\nFew newer games and demos require this configuration.\n1.3 ROM, OCS Agnus, 512 KB Chip RAM\nVery old (e.g. pre-1988) games and demos may require this configuration.\n1.2 ROM, OCS Agnus, 512 KB Chip RAM\nAs available for the A1000, and installed on the first A500 and A2000 series. Some very old programs only work correctly with this configuration. Note: This system ROM version can only boot from floppy disk (no hard disk boot support).\n1.2 ROM, OCS Agnus, 512 KB Chip RAM + 512 KB Slow RAM\nThis configuration adds expansion memory to the first A500 produced. Try this if your game does not work with newer configurations, but works with the previous one. It could add some features to the game, including faster loading times. Note: This system ROM version can only boot from floppy disk (no hard disk boot support)." @@ -1447,7 +1449,7 @@ BEGIN IDS_QS_MODEL_CDTV "CDTV\nThe CDTV was the first model with a built-in CD-ROM drive. Looking like a black CD player, it featured a configuration equivalent to that of an A500 with 1 MB RAM and an ECS chipset.\nFloppy drive and 64KB SRAM card expanded CDTV\n" END -STRINGTABLE +STRINGTABLE BEGIN IDS_QS_MODEL_UAE "High-end expanded configuration" IDS_QS_MODEL_ARCADIA "Arcadia\nArcadia Multi Select system is arcade platform developed by Arcadia and Mastertronic. It is based on an A500 mainboard with ROM cage attached to expansion port. Arcadia ROM files go to ""Cartridge ROM File"" in ROM-panel." @@ -1456,7 +1458,7 @@ BEGIN IDS_QS_MODEL_A4000T "A4000T (test)\nA4000T" END -STRINGTABLE +STRINGTABLE BEGIN IDS_FLOPPYTYPE35DDPC "3.5"" DD (PC)" IDS_FLOPPYTYPE35HDPC "3.5"" HD (PC)" @@ -1476,7 +1478,7 @@ BEGIN IDS_PRINTER_ASCII "ASCII-Only" END -STRINGTABLE +STRINGTABLE BEGIN IDS_PRINTER_EPSON9 "Epson Matrix Printer Emulation, 9pin" IDS_PRINTER_POSTSCRIPT_DETECTION "PostScript (Passthrough)" @@ -1497,10 +1499,8 @@ END // Finnish resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FIN) -#ifdef _WIN32 LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT #pragma code_page(1252) -#endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/od-win32/rp.c b/od-win32/rp.c index 2e3bab9a..15ad220b 100644 --- a/od-win32/rp.c +++ b/od-win32/rp.c @@ -51,30 +51,30 @@ static int currentpausemode; static int cando (void) { - if (!initialized) - return 0; - return 1; + if (!initialized) + return 0; + return 1; } static int isrecursive (void) { - return recursive_device; + return recursive_device; } static void outhex (const uae_u8 *s) { - for (;;) { - write_log (L"%02X%02X ", s[0], s[1]); - if (s[0] == 0 && s[1] == 0) - break; - s += 2; - } - write_log (L"\n"); + for (;;) { + write_log (L"%02X%02X ", s[0], s[1]); + if (s[0] == 0 && s[1] == 0) + break; + s += 2; + } + write_log (L"\n"); } static const TCHAR *getmsg (int msg) { - switch (msg) - { + switch (msg) + { case RPIPCGM_REGISTER: return L"RPIPCGM_REGISTER"; case RPIPCGM_FEATURES: return L"RPIPCGM_FEATURES"; case RPIPCGM_CLOSED: return L"RPIPCGM_CLOSED"; @@ -111,909 +111,909 @@ static const TCHAR *getmsg (int msg) case RPIPCHM_LOADSTATE: return L"RPIPCHM_LOADSTATE"; default: return L"UNKNOWN"; - } + } } static void trimws (TCHAR *s) { - /* Delete trailing whitespace. */ - int len = _tcslen (s); - while (len > 0 && _tcscspn (s + len - 1, L"\t \r\n") == 0) - s[--len] = '\0'; + /* Delete trailing whitespace. */ + int len = _tcslen (s); + while (len > 0 && _tcscspn (s + len - 1, L"\t \r\n") == 0) + s[--len] = '\0'; } static int port_insert2 (int num, const TCHAR *name) { - TCHAR tmp2[1000]; - int i, type; - - type = 1; - _tcscpy (tmp2, name); - for (i = 1; i <= MAX_JPORTS; i++) { - TCHAR tmp1[1000]; - _stprintf (tmp1, L"Mouse%d", i); - if (!_tcscmp (name, tmp1)) { - _stprintf (tmp2, L"mouse%d", i - 1); - type = 0; - break; - } - _stprintf (tmp1, L"Joystick%d", i); - if (!_tcscmp (name, tmp1)) { - if (i - 1 == JSEM_XARCADE1LAYOUT) - _stprintf (tmp2, L"kbd%d", JSEM_XARCADE1LAYOUT); - else if (i - 1 == JSEM_XARCADE2LAYOUT) - _stprintf (tmp2, L"kbd%d", JSEM_XARCADE2LAYOUT); - else - _stprintf (tmp2, L"joy%d", i - 1); - type = 0; - break; - } - _stprintf (tmp1, L"KeyboardLayout%d", i); - if (!_tcscmp (name, tmp1)) { - _stprintf (tmp2, L"kbd%d", i); - type = 0; - break; + TCHAR tmp2[1000]; + int i, type; + + type = 1; + _tcscpy (tmp2, name); + for (i = 1; i <= MAX_JPORTS; i++) { + TCHAR tmp1[1000]; + _stprintf (tmp1, L"Mouse%d", i); + if (!_tcscmp (name, tmp1)) { + _stprintf (tmp2, L"mouse%d", i - 1); + type = 0; + break; + } + _stprintf (tmp1, L"Joystick%d", i); + if (!_tcscmp (name, tmp1)) { + if (i - 1 == JSEM_XARCADE1LAYOUT) + _stprintf (tmp2, L"kbd%d", JSEM_XARCADE1LAYOUT); + else if (i - 1 == JSEM_XARCADE2LAYOUT) + _stprintf (tmp2, L"kbd%d", JSEM_XARCADE2LAYOUT); + else + _stprintf (tmp2, L"joy%d", i - 1); + type = 0; + break; + } + _stprintf (tmp1, L"KeyboardLayout%d", i); + if (!_tcscmp (name, tmp1)) { + _stprintf (tmp2, L"kbd%d", i); + type = 0; + break; + } } - } - trimws (tmp2); - return inputdevice_joyport_config (&changed_prefs, tmp2, num, 0, type); + trimws (tmp2); + return inputdevice_joyport_config (&changed_prefs, tmp2, num, 0, type); } static int port_insert (int num, const TCHAR *name) { - TCHAR tmp1[1000]; - - if (num < 0 || num >= MAX_JPORTS) - return FALSE; - if (_tcslen (name) == 0) { - inputdevice_joyport_config (&changed_prefs, L"none", num, 0, 0); - return TRUE; - } - if (_tcslen (name) >= sizeof (tmp1) / sizeof (TCHAR) - 1) - return FALSE; + TCHAR tmp1[1000]; - _tcscpy (tmp1, name); - for (;;) { - TCHAR *p = _tcsrchr (tmp1, '\\'); - if (p) { - int v = port_insert2 (num, p + 1); - if (v) + if (num < 0 || num >= MAX_JPORTS) + return FALSE; + if (_tcslen (name) == 0) { + inputdevice_joyport_config (&changed_prefs, L"none", num, 0, 0); return TRUE; - *p = 0; - continue; } - return port_insert2 (num, tmp1); - } + if (_tcslen (name) >= sizeof (tmp1) / sizeof (TCHAR) - 1) + return FALSE; + + _tcscpy (tmp1, name); + for (;;) { + TCHAR *p = _tcsrchr (tmp1, '\\'); + if (p) { + int v = port_insert2 (num, p + 1); + if (v) + return TRUE; + *p = 0; + continue; + } + return port_insert2 (num, tmp1); + } } static BOOL RPPostMessagex(UINT uMessage, WPARAM wParam, LPARAM lParam, const RPGUESTINFO *pInfo) { - BOOL v = FALSE; - static int cnt; - int ncnt; - int dolog = log_rp; - - if (!pInfo) { - write_log (L"RPPOST: pInfo == NULL!\n"); - return FALSE; - } - if (uMessage == RPIPCGM_DEVICESEEK || uMessage == RPIPCGM_DEVICEACTIVITY) - dolog = 0; - recursive++; - cnt++; - ncnt = cnt; - if (dolog) - write_log (L"RPPOST_%d->\n", ncnt); - v = RPPostMessage (uMessage, wParam, lParam, pInfo); - recursive--; - if (dolog) { - write_log (L"RPPOST_%d(%s [%d], %08x, %08x)\n", ncnt, - getmsg (uMessage), uMessage - WM_APP, wParam, lParam); - if (v == FALSE) - write_log (L"ERROR %d\n", GetLastError ()); - } - return v; + BOOL v = FALSE; + static int cnt; + int ncnt; + int dolog = log_rp; + + if (!pInfo) { + write_log (L"RPPOST: pInfo == NULL!\n"); + return FALSE; + } + if (uMessage == RPIPCGM_DEVICESEEK || uMessage == RPIPCGM_DEVICEACTIVITY) + dolog = 0; + recursive++; + cnt++; + ncnt = cnt; + if (dolog) + write_log (L"RPPOST_%d->\n", ncnt); + v = RPPostMessage (uMessage, wParam, lParam, pInfo); + recursive--; + if (dolog) { + write_log (L"RPPOST_%d(%s [%d], %08x, %08x)\n", ncnt, + getmsg (uMessage), uMessage - WM_APP, wParam, lParam); + if (v == FALSE) + write_log (L"ERROR %d\n", GetLastError ()); + } + return v; } static BOOL RPSendMessagex (UINT uMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, const RPGUESTINFO *pInfo, LRESULT *plResult) + LPCVOID pData, DWORD dwDataSize, const RPGUESTINFO *pInfo, LRESULT *plResult) { - BOOL v = FALSE; - static int cnt; - int ncnt; - int dolog = log_rp; - - if (!pInfo) { - write_log (L"RPSEND: pInfo == NULL!\n"); - return FALSE; - } - if (!pInfo->hHostMessageWindow) { - write_log (L"RPSEND: pInfo->hHostMessageWindow == NULL!\n"); - return FALSE; - } - if (uMessage == RPIPCGM_DEVICESEEK) - dolog = 0; - recursive++; - cnt++; - ncnt = cnt; - if (dolog) - write_log (L"RPSEND_%d->\n", ncnt); - v = RPSendMessage (uMessage, wParam, lParam, pData, dwDataSize, pInfo, plResult); - recursive--; - if (dolog) { - write_log (L"RPSEND_%d(%s [%d], %08x, %08x, %08x, %d)\n", ncnt, - getmsg (uMessage), uMessage - WM_APP, wParam, lParam, pData, dwDataSize); - if (v == FALSE) - write_log (L"ERROR %d\n", GetLastError ()); - } - return v; + BOOL v = FALSE; + static int cnt; + int ncnt; + int dolog = log_rp; + + if (!pInfo) { + write_log (L"RPSEND: pInfo == NULL!\n"); + return FALSE; + } + if (!pInfo->hHostMessageWindow) { + write_log (L"RPSEND: pInfo->hHostMessageWindow == NULL!\n"); + return FALSE; + } + if (uMessage == RPIPCGM_DEVICESEEK) + dolog = 0; + recursive++; + cnt++; + ncnt = cnt; + if (dolog) + write_log (L"RPSEND_%d->\n", ncnt); + v = RPSendMessage (uMessage, wParam, lParam, pData, dwDataSize, pInfo, plResult); + recursive--; + if (dolog) { + write_log (L"RPSEND_%d(%s [%d], %08x, %08x, %08x, %d)\n", ncnt, + getmsg (uMessage), uMessage - WM_APP, wParam, lParam, pData, dwDataSize); + if (v == FALSE) + write_log (L"ERROR %d\n", GetLastError ()); + } + return v; } static int winok (void) { - if (!initialized) - return 0; - if (!hwndset) - return 0; - return 1; + if (!initialized) + return 0; + if (!hwndset) + return 0; + return 1; } static void fixup_size (struct uae_prefs *prefs) { - if (prefs->gfx_xcenter_size > 0) { - int hres = prefs->gfx_resolution; - if (prefs->gfx_filter) { - if (prefs->gfx_filter_horiz_zoom_mult) - hres += (1000 / prefs->gfx_filter_horiz_zoom_mult) - 1; - hres += uaefilters[prefs->gfx_filter].intmul - 1; + if (prefs->gfx_xcenter_size > 0) { + int hres = prefs->gfx_resolution; + if (prefs->gfx_filter) { + if (prefs->gfx_filter_horiz_zoom_mult) + hres += (1000 / prefs->gfx_filter_horiz_zoom_mult) - 1; + hres += uaefilters[prefs->gfx_filter].intmul - 1; + } + if (hres > RES_MAX) + hres = RES_MAX; + prefs->gfx_size_win.width = prefs->gfx_xcenter_size >> (RES_MAX - hres); } - if (hres > RES_MAX) - hres = RES_MAX; - prefs->gfx_size_win.width = prefs->gfx_xcenter_size >> (RES_MAX - hres); - } - if (prefs->gfx_ycenter_size > 0) { - int vres = prefs->gfx_linedbl ? 1 : 0; - if (prefs->gfx_filter) { - if (prefs->gfx_filter_vert_zoom_mult) - vres += (1000 / prefs->gfx_filter_vert_zoom_mult) - 1; - vres += uaefilters[prefs->gfx_filter].intmul - 1; + if (prefs->gfx_ycenter_size > 0) { + int vres = prefs->gfx_linedbl ? 1 : 0; + if (prefs->gfx_filter) { + if (prefs->gfx_filter_vert_zoom_mult) + vres += (1000 / prefs->gfx_filter_vert_zoom_mult) - 1; + vres += uaefilters[prefs->gfx_filter].intmul - 1; + } + if (vres > RES_MAX) + vres = RES_MAX; + prefs->gfx_size_win.height = (prefs->gfx_ycenter_size * 2) >> (RES_MAX - vres); } - if (vres > RES_MAX) - vres = RES_MAX; - prefs->gfx_size_win.height = (prefs->gfx_ycenter_size * 2) >> (RES_MAX - vres); - } } #define LORES_WIDTH 360 #define LORES_HEIGHT 284 static void get_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) { - int hres; - int m; - int full = 0; - int vres = 0; - int totalhdbl, totalvdbl; - - hres = p->gfx_resolution; - if (p->gfx_filter && p->gfx_filter_horiz_zoom_mult) - hres += (1000 / p->gfx_filter_horiz_zoom_mult) - 1; - if (hres > RES_MAX) - hres = RES_MAX; - vres = hres; - m = RP_SCREENMODE_1X; - - if (WIN32GFX_IsPicassoScreen ()) { - - full = p->gfx_pfullscreen; - sm->lClipTop = 0; - sm->lClipLeft = 0; - sm->lClipHeight = picasso96_state.Height; - sm->lClipWidth = picasso96_state.Width; - - } else { - - full = p->gfx_afullscreen; - - if (hres == RES_HIRES) - m = RP_SCREENMODE_2X; - if (hres == RES_SUPERHIRES) - m = RP_SCREENMODE_4X; - - totalhdbl = hres; - if (hres > max_horiz_dbl) - hres = max_horiz_dbl; - totalvdbl = vres; - if (vres > max_vert_dbl) - vres = max_vert_dbl; + int hres; + int m; + int full = 0; + int vres = 0; + int totalhdbl, totalvdbl; + + hres = p->gfx_resolution; + if (p->gfx_filter && p->gfx_filter_horiz_zoom_mult) + hres += (1000 / p->gfx_filter_horiz_zoom_mult) - 1; + if (hres > RES_MAX) + hres = RES_MAX; + vres = hres; + m = RP_SCREENMODE_1X; + + if (WIN32GFX_IsPicassoScreen ()) { + + full = p->gfx_pfullscreen; + sm->lClipTop = 0; + sm->lClipLeft = 0; + sm->lClipHeight = picasso96_state.Height; + sm->lClipWidth = picasso96_state.Width; - if (log_rp) - write_log (L"GET_RPSM: hres=%d (%d) vres=%d (%d) full=%d xcpos=%d ycpos=%d w=%d h=%d\n", - totalhdbl, hres, totalvdbl, vres, full, - p->gfx_xcenter_pos, p->gfx_ycenter_pos, - p->gfx_size_win.width, p->gfx_size_win.height); - sm->lClipLeft = p->gfx_xcenter_pos <= 0 ? -1 : p->gfx_xcenter_pos; - sm->lClipTop = p->gfx_ycenter_pos <= 0 ? -1 : p->gfx_ycenter_pos; - if (full) { - sm->lClipWidth = LORES_WIDTH << RES_MAX; - sm->lClipHeight = LORES_HEIGHT << 1; } else { - sm->lClipWidth = p->gfx_size_win.width << (RES_MAX - totalhdbl); - if (totalvdbl == 2) - sm->lClipHeight = p->gfx_size_win.height >> 1; - else - sm->lClipHeight = p->gfx_size_win.height << (1 - totalvdbl); + + full = p->gfx_afullscreen; + + if (hres == RES_HIRES) + m = RP_SCREENMODE_2X; + if (hres == RES_SUPERHIRES) + m = RP_SCREENMODE_4X; + + totalhdbl = hres; + if (hres > max_horiz_dbl) + hres = max_horiz_dbl; + totalvdbl = vres; + if (vres > max_vert_dbl) + vres = max_vert_dbl; + + if (log_rp) + write_log (L"GET_RPSM: hres=%d (%d) vres=%d (%d) full=%d xcpos=%d ycpos=%d w=%d h=%d\n", + totalhdbl, hres, totalvdbl, vres, full, + p->gfx_xcenter_pos, p->gfx_ycenter_pos, + p->gfx_size_win.width, p->gfx_size_win.height); + sm->lClipLeft = p->gfx_xcenter_pos <= 0 ? -1 : p->gfx_xcenter_pos; + sm->lClipTop = p->gfx_ycenter_pos <= 0 ? -1 : p->gfx_ycenter_pos; + if (full) { + sm->lClipWidth = LORES_WIDTH << RES_MAX; + sm->lClipHeight = LORES_HEIGHT << 1; + } else { + sm->lClipWidth = p->gfx_size_win.width << (RES_MAX - totalhdbl); + if (totalvdbl == 2) + sm->lClipHeight = p->gfx_size_win.height >> 1; + else + sm->lClipHeight = p->gfx_size_win.height << (1 - totalvdbl); + } + if (full && p->gfx_filter && p->gfx_filter_horiz_zoom_mult == 0) + m = RP_SCREENMODE_XX; } - if (full && p->gfx_filter && p->gfx_filter_horiz_zoom_mult == 0) - m = RP_SCREENMODE_XX; - } - if (full) { - m &= ~0x0000ff00; - m |= p->gfx_display << 8; - } - if (full > 1) - m |= RP_SCREENMODE_FULLWINDOW; - if (p->gfx_filter_scanlines || p->gfx_linedbl == 2) - m |= RP_SCREENMODE_SCANLINES; - sm->dwScreenMode = m; - - if (log_rp) - write_log (L"GET_RPSM: %08X %dx%d %dx%d hres=%d (%d) vres=%d (%d) disp=%d fs=%d\n", - sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, - totalhdbl, hres, totalvdbl, vres, p->gfx_display, full); + if (full) { + m &= ~0x0000ff00; + m |= p->gfx_display << 8; + } + if (full > 1) + m |= RP_SCREENMODE_FULLWINDOW; + if (p->gfx_filter_scanlines || p->gfx_linedbl == 2) + m |= RP_SCREENMODE_SCANLINES; + sm->dwScreenMode = m; + + if (log_rp) + write_log (L"GET_RPSM: %08X %dx%d %dx%d hres=%d (%d) vres=%d (%d) disp=%d fs=%d\n", + sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, + totalhdbl, hres, totalvdbl, vres, p->gfx_display, full); } static void set_screenmode (struct RPScreenMode *sm, struct uae_prefs *p) { - int smm = RP_SCREENMODE_MODE (sm->dwScreenMode); - int display = RP_SCREENMODE_DISPLAY (sm->dwScreenMode); - int fs = 0; - int hdbl = 1, vdbl = 1; - int hres, vres; - struct MultiDisplay *disp; - - minimized = 0; - if (display) { - p->gfx_display = display; - if (sm->dwScreenMode & RP_SCREENMODE_FULLWINDOW) - fs = 2; - else - fs = 1; - } - disp = getdisplay (p); - - if (log_rp) - write_log (L"SET_RPSM: %08X %dx%d %dx%d hres=%d vres=%d disp=%d fs=%d\n", - sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, - hdbl, vdbl, display, fs); - - if (!WIN32GFX_IsPicassoScreen ()) { - - hdbl = smm; - if (smm == RP_SCREENMODE_3X) - hdbl = RES_HIRES; - if (smm == RP_SCREENMODE_4X) - hdbl = RES_SUPERHIRES; - if (smm > RP_SCREENMODE_4X || smm == RP_SCREENMODE_XX) { - hdbl = max_horiz_dbl; - vdbl = max_vert_dbl; + int smm = RP_SCREENMODE_MODE (sm->dwScreenMode); + int display = RP_SCREENMODE_DISPLAY (sm->dwScreenMode); + int fs = 0; + int hdbl = 1, vdbl = 1; + int hres, vres; + struct MultiDisplay *disp; + + minimized = 0; + if (display) { + p->gfx_display = display; + if (sm->dwScreenMode & RP_SCREENMODE_FULLWINDOW) + fs = 2; + else + fs = 1; } + disp = getdisplay (p); - if (hdbl == RES_LORES) { - vdbl = 0; - } else { - vdbl = 1; - if (hdbl == RES_SUPERHIRES) - vdbl = 2; - } - - hres = hdbl; - if (hres > max_horiz_dbl) - hres = max_horiz_dbl; - p->gfx_resolution = hres; - vres = vdbl; - if (vres > max_vert_dbl) - vres = max_vert_dbl; - p->gfx_linedbl = vres ? 1 : 0; - - if (sm->lClipWidth <= 0) - p->gfx_size_win.width = LORES_WIDTH << hdbl; - else - p->gfx_size_win.width = sm->lClipWidth >> (RES_MAX - hdbl); + if (log_rp) + write_log (L"SET_RPSM: %08X %dx%d %dx%d hres=%d vres=%d disp=%d fs=%d\n", + sm->dwScreenMode, sm->lClipLeft, sm->lClipTop, sm->lClipWidth, sm->lClipHeight, + hdbl, vdbl, display, fs); + + if (!WIN32GFX_IsPicassoScreen ()) { + + hdbl = smm; + if (smm == RP_SCREENMODE_3X) + hdbl = RES_HIRES; + if (smm == RP_SCREENMODE_4X) + hdbl = RES_SUPERHIRES; + if (smm > RP_SCREENMODE_4X || smm == RP_SCREENMODE_XX) { + hdbl = max_horiz_dbl; + vdbl = max_vert_dbl; + } - if (sm->lClipHeight <= 0) { - p->gfx_size_win.height = LORES_HEIGHT << vdbl; - } else { - if (vdbl == 2) - p->gfx_size_win.height = sm->lClipHeight * 2; - else - p->gfx_size_win.height = sm->lClipHeight >> (1 - vdbl); - } + if (hdbl == RES_LORES) { + vdbl = 0; + } else { + vdbl = 1; + if (hdbl == RES_SUPERHIRES) + vdbl = 2; + } - if (fs == 1) { - p->gfx_size_fs.width = p->gfx_size_win.width; - p->gfx_size_fs.height = p->gfx_size_win.height; - } else if (fs == 2) { - p->gfx_size_fs.width = disp->rect.right - disp->rect.left; - p->gfx_size_fs.height = disp->rect.bottom - disp->rect.top; - } + hres = hdbl; + if (hres > max_horiz_dbl) + hres = max_horiz_dbl; + p->gfx_resolution = hres; + vres = vdbl; + if (vres > max_vert_dbl) + vres = max_vert_dbl; + p->gfx_linedbl = vres ? 1 : 0; + + if (sm->lClipWidth <= 0) + p->gfx_size_win.width = LORES_WIDTH << hdbl; + else + p->gfx_size_win.width = sm->lClipWidth >> (RES_MAX - hdbl); + + if (sm->lClipHeight <= 0) { + p->gfx_size_win.height = LORES_HEIGHT << vdbl; + } else { + if (vdbl == 2) + p->gfx_size_win.height = sm->lClipHeight * 2; + else + p->gfx_size_win.height = sm->lClipHeight >> (1 - vdbl); + } - p->gfx_filter = rp_filter_default; - p->gfx_filter_horiz_zoom_mult = 1000; - p->gfx_filter_vert_zoom_mult = 1000; - if (log_rp) - write_log (L"WW=%d WH=%d FW=%d FH=%d\n", - p->gfx_size_win.width, p->gfx_size_win.height, - p->gfx_size_fs.width, p->gfx_size_fs.height); - if (fs) { - if (smm == RP_SCREENMODE_XX) { - p->gfx_filter = rp_filter; - p->gfx_filter_horiz_zoom_mult = 0; - p->gfx_filter_vert_zoom_mult = 0; - } else { - int mult; - int prevmult = 1; - int xmult = uaefilters[p->gfx_filter].intmul; - int ymult = uaefilters[p->gfx_filter].intmul ; - for (mult = 2; mult <= 4; mult+=2) { - int w = p->gfx_size_win.width; - int h = p->gfx_size_win.height; - if (p->gfx_size_fs.width * xmult < w * mult || p->gfx_size_fs.height * ymult < h * mult) { - mult = prevmult; - break; - } - prevmult = mult; + if (fs == 1) { + p->gfx_size_fs.width = p->gfx_size_win.width; + p->gfx_size_fs.height = p->gfx_size_win.height; + } else if (fs == 2) { + p->gfx_size_fs.width = disp->rect.right - disp->rect.left; + p->gfx_size_fs.height = disp->rect.bottom - disp->rect.top; } - if (mult > 1 || fs == 2) { - p->gfx_filter = rp_filter; - p->gfx_filter_horiz_zoom_mult = 1000 / mult; - p->gfx_filter_vert_zoom_mult = 1000 / mult; + + p->gfx_filter = rp_filter_default; + p->gfx_filter_horiz_zoom_mult = 1000; + p->gfx_filter_vert_zoom_mult = 1000; + if (log_rp) + write_log (L"WW=%d WH=%d FW=%d FH=%d\n", + p->gfx_size_win.width, p->gfx_size_win.height, + p->gfx_size_fs.width, p->gfx_size_fs.height); + if (fs) { + if (smm == RP_SCREENMODE_XX) { + p->gfx_filter = rp_filter; + p->gfx_filter_horiz_zoom_mult = 0; + p->gfx_filter_vert_zoom_mult = 0; + } else { + int mult; + int prevmult = 1; + int xmult = uaefilters[p->gfx_filter].intmul; + int ymult = uaefilters[p->gfx_filter].intmul ; + for (mult = 2; mult <= 4; mult+=2) { + int w = p->gfx_size_win.width; + int h = p->gfx_size_win.height; + if (p->gfx_size_fs.width * xmult < w * mult || p->gfx_size_fs.height * ymult < h * mult) { + mult = prevmult; + break; + } + prevmult = mult; + } + if (mult > 1 || fs == 2) { + p->gfx_filter = rp_filter; + p->gfx_filter_horiz_zoom_mult = 1000 / mult; + p->gfx_filter_vert_zoom_mult = 1000 / mult; + } + } + } else { + if (hdbl != hres || vdbl != vres) { + p->gfx_filter = rp_filter; + p->gfx_filter_horiz_zoom_mult = 1000 >> (hdbl - hres); + p->gfx_filter_vert_zoom_mult = 1000 >> (vdbl - vres); + } } - } - } else { - if (hdbl != hres || vdbl != vres) { - p->gfx_filter = rp_filter; - p->gfx_filter_horiz_zoom_mult = 1000 >> (hdbl - hres); - p->gfx_filter_vert_zoom_mult = 1000 >> (vdbl - vres); - } - } - } - p->gfx_pfullscreen = fs; - p->gfx_afullscreen = fs; - p->gfx_xcenter_pos = sm->lClipLeft; - p->gfx_ycenter_pos = sm->lClipTop; - p->gfx_xcenter_size = sm->lClipWidth; - p->gfx_ycenter_size = sm->lClipHeight; - - if (sm->dwScreenMode & RP_SCREENMODE_SCANLINES) { - if (p->gfx_linedbl > 0) { - p->gfx_linedbl = 2; - p->gfx_filter_scanlines = 0; } - } + p->gfx_pfullscreen = fs; + p->gfx_afullscreen = fs; + p->gfx_xcenter_pos = sm->lClipLeft; + p->gfx_ycenter_pos = sm->lClipTop; + p->gfx_xcenter_size = sm->lClipWidth; + p->gfx_ycenter_size = sm->lClipHeight; + + if (sm->dwScreenMode & RP_SCREENMODE_SCANLINES) { + if (p->gfx_linedbl > 0) { + p->gfx_linedbl = 2; + p->gfx_filter_scanlines = 0; + } + } - updatewinfsmode (p); - hwndset = 0; + updatewinfsmode (p); + hwndset = 0; } static LRESULT CALLBACK RPHostMsgFunction2 (UINT uMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) + LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) { - if (log_rp) - write_log (L"RPFUNC(%s [%d], %08x, %08x, %08x, %d, %08x)\n", - getmsg (uMessage), uMessage - WM_APP, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); + if (log_rp) + write_log (L"RPFUNC(%s [%d], %08x, %08x, %08x, %d, %08x)\n", + getmsg (uMessage), uMessage - WM_APP, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); - switch (uMessage) - { + switch (uMessage) + { default: - write_log (L"RP: Unknown or unsupported command %x\n", uMessage); - break; + write_log (L"RP: Unknown or unsupported command %x\n", uMessage); + break; case RPIPCHM_PING: - return TRUE; + return TRUE; case RPIPCHM_CLOSE: - uae_quit (); - return TRUE; + uae_quit (); + return TRUE; case RPIPCHM_RESET: - uae_reset (wParam == RP_RESET_SOFT ? 0 : -1); - return TRUE; + uae_reset (wParam == RP_RESET_SOFT ? 0 : -1); + return TRUE; case RPIPCHM_TURBO: - { - if (wParam & RP_TURBO_CPU) - warpmode ((lParam & RP_TURBO_CPU) ? 1 : 0); - if (wParam & RP_TURBO_FLOPPY) - changed_prefs.floppy_speed = (lParam & RP_TURBO_FLOPPY) ? 0 : 100; - } - return TRUE; + { + if (wParam & RP_TURBO_CPU) + warpmode ((lParam & RP_TURBO_CPU) ? 1 : 0); + if (wParam & RP_TURBO_FLOPPY) + changed_prefs.floppy_speed = (lParam & RP_TURBO_FLOPPY) ? 0 : 100; + } + return TRUE; case RPIPCHM_PAUSE: - currentpausemode = pause_emulation; - if (wParam ? 1 : 0 != pause_emulation ? 1 : 0) { - pausemode (wParam ? 1 : 0); - if (wParam) { - currentpausemode = -1; - return 2; + currentpausemode = pause_emulation; + if (wParam ? 1 : 0 != pause_emulation ? 1 : 0) { + pausemode (wParam ? 1 : 0); + if (wParam) { + currentpausemode = -1; + return 2; + } } - } - return 1; + return 1; case RPIPCHM_VOLUME: - currprefs.sound_volume = changed_prefs.sound_volume = 100 - wParam; - set_volume (currprefs.sound_volume, 0); - return TRUE; + currprefs.sound_volume = changed_prefs.sound_volume = 100 - wParam; + set_volume (currprefs.sound_volume, 0); + return TRUE; case RPIPCHM_ESCAPEKEY: - rp_rpescapekey = wParam; - rp_rpescapeholdtime = lParam; - return TRUE; + rp_rpescapekey = wParam; + rp_rpescapeholdtime = lParam; + return TRUE; case RPIPCHM_MOUSECAPTURE: - { - if (wParam & RP_MOUSECAPTURE_CAPTURED) - setmouseactive (1); - else - setmouseactive (0); - } - return TRUE; + { + if (wParam & RP_MOUSECAPTURE_CAPTURED) + setmouseactive (1); + else + setmouseactive (0); + } + return TRUE; case RPIPCHM_DEVICECONTENT: - { - struct RPDeviceContent *dc = (struct RPDeviceContent*)pData; - TCHAR *n = dc->szContent; - int num = dc->btDeviceNumber; - int ok = FALSE; - switch (dc->btDeviceCategory) - { - case RP_DEVICE_FLOPPY: - disk_insert (num, n); - ok = TRUE; - break; - case RP_DEVICE_INPUTPORT: - ok = port_insert (num, n); - break; - - } - xfree (n); - return ok; - } + { + struct RPDeviceContent *dc = (struct RPDeviceContent*)pData; + TCHAR *n = dc->szContent; + int num = dc->btDeviceNumber; + int ok = FALSE; + switch (dc->btDeviceCategory) + { + case RP_DEVICE_FLOPPY: + disk_insert (num, n); + ok = TRUE; + break; + case RP_DEVICE_INPUTPORT: + ok = port_insert (num, n); + break; + + } + xfree (n); + return ok; + } case RPIPCHM_SCREENMODE: - { - struct RPScreenMode *sm = (struct RPScreenMode*)pData; - set_screenmode (sm, &changed_prefs); - return (LRESULT)INVALID_HANDLE_VALUE; - } + { + struct RPScreenMode *sm = (struct RPScreenMode*)pData; + set_screenmode (sm, &changed_prefs); + return (LRESULT)INVALID_HANDLE_VALUE; + } case RPIPCHM_EVENT: - { - TCHAR out[256]; - TCHAR *s = (WCHAR*)pData; - int idx = -1; - for (;;) { - int ret; - out[0] = 0; - ret = cfgfile_modify (idx++, s, _tcslen (s), out, sizeof out / sizeof (TCHAR)); - if (ret >= 0) - break; - } - return TRUE; - } + { + TCHAR out[256]; + TCHAR *s = (WCHAR*)pData; + int idx = -1; + for (;;) { + int ret; + out[0] = 0; + ret = cfgfile_modify (idx++, s, _tcslen (s), out, sizeof out / sizeof (TCHAR)); + if (ret >= 0) + break; + } + return TRUE; + } case RPIPCHM_SCREENCAPTURE: - { - extern int screenshotf (const TCHAR *spath, int mode, int doprepare); - extern int screenshotmode; - int ok; - int ossm = screenshotmode; - TCHAR *s = (TCHAR*)pData; - screenshotmode = 0; - ok = screenshotf (s, 1, 1); - screenshotmode = ossm; - return ok ? TRUE : FALSE; - } + { + extern int screenshotf (const TCHAR *spath, int mode, int doprepare); + extern int screenshotmode; + int ok; + int ossm = screenshotmode; + TCHAR *s = (TCHAR*)pData; + screenshotmode = 0; + ok = screenshotf (s, 1, 1); + screenshotmode = ossm; + return ok ? TRUE : FALSE; + } case RPIPCHM_SAVESTATE: - { - TCHAR *s = (TCHAR*)pData; - DWORD ret = FALSE; - if (s == NULL) { - savestate_initsave (NULL, 0, TRUE); - return 1; - } - if (vpos == 0) { - savestate_initsave (L"", 1, TRUE); - save_state (s, L"AF2008"); - ret = 1; - } else { - //savestate_initsave (s, 1, TRUE); - //ret = -1; - } - return ret; - } + { + TCHAR *s = (TCHAR*)pData; + DWORD ret = FALSE; + if (s == NULL) { + savestate_initsave (NULL, 0, TRUE); + return 1; + } + if (vpos == 0) { + savestate_initsave (L"", 1, TRUE); + save_state (s, L"AF2008"); + ret = 1; + } else { + //savestate_initsave (s, 1, TRUE); + //ret = -1; + } + return ret; + } case RPIPCHM_LOADSTATE: - { - TCHAR *s = (WCHAR*)pData; - DWORD ret = FALSE; - DWORD attr = GetFileAttributes (s); - if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)) { - savestate_state = STATE_DORESTORE; - _tcscpy (savestate_fname, s); - ret = -1; - } - return ret; + { + TCHAR *s = (WCHAR*)pData; + DWORD ret = FALSE; + DWORD attr = GetFileAttributes (s); + if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)) { + savestate_state = STATE_DORESTORE; + _tcscpy (savestate_fname, s); + ret = -1; + } + return ret; + } } - } - return FALSE; + return FALSE; } static LRESULT CALLBACK RPHostMsgFunction (UINT uMessage, WPARAM wParam, LPARAM lParam, - LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) + LPCVOID pData, DWORD dwDataSize, LPARAM lMsgFunctionParam) { - LRESULT lr; - recursive_device++; - lr = RPHostMsgFunction2 (uMessage, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); - recursive_device--; - return lr; + LRESULT lr; + recursive_device++; + lr = RPHostMsgFunction2 (uMessage, wParam, lParam, pData, dwDataSize, lMsgFunctionParam); + recursive_device--; + return lr; } HRESULT rp_init (void) { - HRESULT hr; - - hr = RPInitializeGuest (&guestinfo, hInst, rp_param, RPHostMsgFunction, 0); - if (SUCCEEDED (hr)) { - initialized = TRUE; - write_log (L"rp_init('%s') succeeded\n", rp_param); - } else { - write_log (L"rp_init('%s') failed, error code %08x\n", rp_param, hr); - } - xfree (rp_param); - rp_param = NULL; - mousecapture = 0; - return hr; + HRESULT hr; + + hr = RPInitializeGuest (&guestinfo, hInst, rp_param, RPHostMsgFunction, 0); + if (SUCCEEDED (hr)) { + initialized = TRUE; + write_log (L"rp_init('%s') succeeded\n", rp_param); + } else { + write_log (L"rp_init('%s') failed, error code %08x\n", rp_param, hr); + } + xfree (rp_param); + rp_param = NULL; + mousecapture = 0; + return hr; } void rp_free (void) { - if (!cando ()) - return; - if (hwndset) - rp_set_hwnd (NULL); - initialized = 0; - RPPostMessagex (RPIPCGM_CLOSED, 0, 0, &guestinfo); - RPUninitializeGuest (&guestinfo); + if (!cando ()) + return; + if (hwndset) + rp_set_hwnd (NULL); + initialized = 0; + RPPostMessagex (RPIPCGM_CLOSED, 0, 0, &guestinfo); + RPUninitializeGuest (&guestinfo); } int rp_close (void) { - if (!cando ()) - return 0; - RPSendMessagex (RPIPCGM_CLOSE, 0, 0, NULL, 0, &guestinfo, NULL); - return 1; + if (!cando ()) + return 0; + RPSendMessagex (RPIPCGM_CLOSE, 0, 0, NULL, 0, &guestinfo, NULL); + return 1; } HWND rp_getparent (void) { - LRESULT lr; - if (!initialized) - return NULL; - RPSendMessagex (RPIPCGM_PARENT, 0, 0, NULL, 0, &guestinfo, &lr); - return (HWND)lr; + LRESULT lr; + if (!initialized) + return NULL; + RPSendMessagex (RPIPCGM_PARENT, 0, 0, NULL, 0, &guestinfo, &lr); + return (HWND)lr; } static void sendfeatures (void) { - DWORD feat; - - feat = RP_FEATURE_POWERLED | RP_FEATURE_SCREEN1X | RP_FEATURE_FULLSCREEN; - feat |= RP_FEATURE_PAUSE | RP_FEATURE_TURBO | RP_FEATURE_VOLUME | RP_FEATURE_SCREENCAPTURE; - feat |= RP_FEATURE_STATE | RP_FEATURE_SCANLINES; - if (!WIN32GFX_IsPicassoScreen ()) - feat |= RP_FEATURE_SCREEN2X | RP_FEATURE_SCREEN4X; - RPSendMessagex (RPIPCGM_FEATURES, feat, 0, NULL, 0, &guestinfo, NULL); + DWORD feat; + + feat = RP_FEATURE_POWERLED | RP_FEATURE_SCREEN1X | RP_FEATURE_FULLSCREEN; + feat |= RP_FEATURE_PAUSE | RP_FEATURE_TURBO | RP_FEATURE_VOLUME | RP_FEATURE_SCREENCAPTURE; + feat |= RP_FEATURE_STATE | RP_FEATURE_SCANLINES; + if (!WIN32GFX_IsPicassoScreen ()) + feat |= RP_FEATURE_SCREEN2X | RP_FEATURE_SCREEN4X; + RPSendMessagex (RPIPCGM_FEATURES, feat, 0, NULL, 0, &guestinfo, NULL); } void rp_fixup_options (struct uae_prefs *p) { - int i; - struct RPScreenMode sm; - - if (!initialized) - return; - - write_log (L"rp_fixup_options(escapekey=%d,escapeholdtime=%d,screenmode=%d,inputmode=%d)\n", - rp_rpescapekey, rp_rpescapeholdtime, rp_screenmode, rp_inputmode); - write_log (L"w=%dx%d fs=%dx%d\n", - p->gfx_size_win.width, p->gfx_size_win.height, - p->gfx_size_fs.width, p->gfx_size_fs.height); - - max_horiz_dbl = currprefs.gfx_max_horizontal; - max_vert_dbl = currprefs.gfx_max_vertical; - - changed_prefs.win32_borderless = currprefs.win32_borderless = 1; - rp_filter_default = rp_filter = currprefs.gfx_filter; - if (rp_filter == 0) - rp_filter = UAE_FILTER_NULL; - - fixup_size (p); - get_screenmode (&sm, p); - sm.dwScreenMode = rp_screenmode; - set_screenmode (&sm, &currprefs); - set_screenmode (&sm, &changed_prefs); - - sendfeatures (); - - /* floppy drives */ - floppy_mask = 0; - for (i = 0; i < 4; i++) { - if (p->dfxtype[i] >= 0) - floppy_mask |= 1 << i; - } - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_FLOPPY, floppy_mask, NULL, 0, &guestinfo, NULL); - - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_INPUTPORT, (1 << MAX_JPORTS) - 1, NULL, 0, &guestinfo, NULL); - rp_input_change (0); - rp_input_change (1); - rp_input_change (2); - rp_input_change (3); - - hd_mask = 0; - cd_mask = 0; - for (i = 0; i < currprefs.mountitems; i++) { - struct uaedev_config_info *uci = &currprefs.mountconfig[i]; - int num = -1; - if (uci->controller == HD_CONTROLLER_UAE) { - num = i; - } else if (uci->controller <= HD_CONTROLLER_IDE3 ) { - num = uci->controller - HD_CONTROLLER_IDE0; - } else if (uci->controller <= HD_CONTROLLER_SCSI6) { - num = uci->controller - HD_CONTROLLER_SCSI0; + int i; + struct RPScreenMode sm; + + if (!initialized) + return; + + write_log (L"rp_fixup_options(escapekey=%d,escapeholdtime=%d,screenmode=%d,inputmode=%d)\n", + rp_rpescapekey, rp_rpescapeholdtime, rp_screenmode, rp_inputmode); + write_log (L"w=%dx%d fs=%dx%d\n", + p->gfx_size_win.width, p->gfx_size_win.height, + p->gfx_size_fs.width, p->gfx_size_fs.height); + + max_horiz_dbl = currprefs.gfx_max_horizontal; + max_vert_dbl = currprefs.gfx_max_vertical; + + changed_prefs.win32_borderless = currprefs.win32_borderless = 1; + rp_filter_default = rp_filter = currprefs.gfx_filter; + if (rp_filter == 0) + rp_filter = UAE_FILTER_NULL; + + fixup_size (p); + get_screenmode (&sm, p); + sm.dwScreenMode = rp_screenmode; + set_screenmode (&sm, &currprefs); + set_screenmode (&sm, &changed_prefs); + + sendfeatures (); + + /* floppy drives */ + floppy_mask = 0; + for (i = 0; i < 4; i++) { + if (p->dfxtype[i] >= 0) + floppy_mask |= 1 << i; } - if (num >= 0) { - hd_mask |= 1 << num; - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_HD, hd_mask, NULL, 0, &guestinfo, NULL); - rp_harddrive_image_change (num, uci->rootdir); + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_FLOPPY, floppy_mask, NULL, 0, &guestinfo, NULL); + + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_INPUTPORT, (1 << MAX_JPORTS) - 1, NULL, 0, &guestinfo, NULL); + rp_input_change (0); + rp_input_change (1); + rp_input_change (2); + rp_input_change (3); + + hd_mask = 0; + cd_mask = 0; + for (i = 0; i < currprefs.mountitems; i++) { + struct uaedev_config_info *uci = &currprefs.mountconfig[i]; + int num = -1; + if (uci->controller == HD_CONTROLLER_UAE) { + num = i; + } else if (uci->controller <= HD_CONTROLLER_IDE3 ) { + num = uci->controller - HD_CONTROLLER_IDE0; + } else if (uci->controller <= HD_CONTROLLER_SCSI6) { + num = uci->controller - HD_CONTROLLER_SCSI0; + } + if (num >= 0) { + hd_mask |= 1 << num; + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_HD, hd_mask, NULL, 0, &guestinfo, NULL); + rp_harddrive_image_change (num, uci->rootdir); + } } - } - rp_update_volume (&currprefs); - rp_turbo (currprefs.turbo_emulation); - for (i = 0; i <= 4; i++) - rp_update_leds (i, 0, 0); + rp_update_volume (&currprefs); + rp_turbo (currprefs.turbo_emulation); + for (i = 0; i <= 4; i++) + rp_update_leds (i, 0, 0); } static void rp_device_change (int dev, int num, const TCHAR *name) { - struct RPDeviceContent *dc; - int dc_size; - TCHAR np[MAX_DPATH]; - - if (!cando ()) - return; - if (recursive_device) - return; - np[0] = 0; - if (name != NULL) - _tcscpy (np, name); - dc_size = sizeof (struct RPDeviceContent) + (_tcslen (np) + 1) * sizeof (TCHAR); - dc = xcalloc (dc_size, 1); - dc->btDeviceCategory = dev; - dc->btDeviceNumber = num; - _tcscpy (dc->szContent, np); - RPSendMessagex (RPIPCGM_DEVICECONTENT, 0, 0, dc, dc_size, &guestinfo, NULL); - xfree (dc); + struct RPDeviceContent *dc; + int dc_size; + TCHAR np[MAX_DPATH]; + + if (!cando ()) + return; + if (recursive_device) + return; + np[0] = 0; + if (name != NULL) + _tcscpy (np, name); + dc_size = sizeof (struct RPDeviceContent) + (_tcslen (np) + 1) * sizeof (TCHAR); + dc = xcalloc (dc_size, 1); + dc->btDeviceCategory = dev; + dc->btDeviceNumber = num; + _tcscpy (dc->szContent, np); + RPSendMessagex (RPIPCGM_DEVICECONTENT, 0, 0, dc, dc_size, &guestinfo, NULL); + xfree (dc); } void rp_input_change (int num) { - int j = jsem_isjoy (num, &currprefs); - int m = jsem_ismouse (num, &currprefs); - int k = jsem_iskbdjoy (num, &currprefs); - TCHAR name[MAX_DPATH]; - TCHAR *name2 = NULL, *name3 = NULL; - - if (JSEM_ISXARCADE1 (num, &currprefs)) { - j = 2; - m = k = -1; - } else if (JSEM_ISXARCADE2 (num, &currprefs)) { - j = 3; - m = k = -1; - } else if (j >= 1) { - j = 1; - } - if (j >= 0) { - name2 = inputdevice_get_device_name (IDTYPE_JOYSTICK, j); - name3 = inputdevice_get_device_unique_name (IDTYPE_JOYSTICK, j); - _stprintf (name, L"Joystick%d", j + 1); - } else if (m >= 0) { - name2 = inputdevice_get_device_name (IDTYPE_MOUSE, m); - name3 = inputdevice_get_device_unique_name (IDTYPE_MOUSE, m); - _stprintf (name, L"Mouse%d", m + 1); - } else if (k >= 0) { - _stprintf (name, L"KeyboardLayout%d", k + 1); - } - if (name3) { - _tcscat (name, L"\\"); - _tcscat (name, name3); - if (name2) { - _tcscat (name, L"\\"); - _tcscat (name, name2); + int j = jsem_isjoy (num, &currprefs); + int m = jsem_ismouse (num, &currprefs); + int k = jsem_iskbdjoy (num, &currprefs); + TCHAR name[MAX_DPATH]; + TCHAR *name2 = NULL, *name3 = NULL; + + if (JSEM_ISXARCADE1 (num, &currprefs)) { + j = 2; + m = k = -1; + } else if (JSEM_ISXARCADE2 (num, &currprefs)) { + j = 3; + m = k = -1; + } else if (j >= 1) { + j = 1; } - } - rp_device_change (RP_DEVICE_INPUTPORT, num, name); + if (j >= 0) { + name2 = inputdevice_get_device_name (IDTYPE_JOYSTICK, j); + name3 = inputdevice_get_device_unique_name (IDTYPE_JOYSTICK, j); + _stprintf (name, L"Joystick%d", j + 1); + } else if (m >= 0) { + name2 = inputdevice_get_device_name (IDTYPE_MOUSE, m); + name3 = inputdevice_get_device_unique_name (IDTYPE_MOUSE, m); + _stprintf (name, L"Mouse%d", m + 1); + } else if (k >= 0) { + _stprintf (name, L"KeyboardLayout%d", k + 1); + } + if (name3) { + _tcscat (name, L"\\"); + _tcscat (name, name3); + if (name2) { + _tcscat (name, L"\\"); + _tcscat (name, name2); + } + } + rp_device_change (RP_DEVICE_INPUTPORT, num, name); } void rp_disk_image_change (int num, const TCHAR *name) { - rp_device_change (RP_DEVICE_FLOPPY, num, name); + rp_device_change (RP_DEVICE_FLOPPY, num, name); } void rp_harddrive_image_change (int num, const TCHAR *name) { - rp_device_change (RP_DEVICE_HD, num, name); + rp_device_change (RP_DEVICE_HD, num, name); } void rp_floppydrive_change (int num, int removed) { - if (!cando ()) - return; - if (removed) - floppy_mask &= ~(1 << num); - else - floppy_mask |= 1 << num; - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_FLOPPY, floppy_mask, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + if (removed) + floppy_mask &= ~(1 << num); + else + floppy_mask |= 1 << num; + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_FLOPPY, floppy_mask, NULL, 0, &guestinfo, NULL); } void rp_hd_change (int num, int removed) { - if (!cando ()) - return; - if (removed) - hd_mask &= ~(1 << num); - else - hd_mask |= 1 << num; - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_HD, hd_mask, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + if (removed) + hd_mask &= ~(1 << num); + else + hd_mask |= 1 << num; + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_HD, hd_mask, NULL, 0, &guestinfo, NULL); } void rp_cd_change (int num, int removed) { - if (!cando ()) - return; - if (removed) - cd_mask &= ~(1 << num); - else - cd_mask |= 1 << num; - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_CD, cd_mask, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + if (removed) + cd_mask &= ~(1 << num); + else + cd_mask |= 1 << num; + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_CD, cd_mask, NULL, 0, &guestinfo, NULL); } void rp_floppy_track (int floppy, int track) { - if (!cando ()) - return; - RPPostMessagex (RPIPCGM_DEVICESEEK, MAKEWORD (RP_DEVICE_FLOPPY, floppy), track, &guestinfo); + if (!cando ()) + return; + RPPostMessagex (RPIPCGM_DEVICESEEK, MAKEWORD (RP_DEVICE_FLOPPY, floppy), track, &guestinfo); } void rp_update_leds (int led, int onoff, int write) { - if (!cando ()) - return; - if (led < 0 || led > 4) - return; - switch (led) - { + if (!cando ()) + return; + if (led < 0 || led > 4) + return; + switch (led) + { case 0: - RPSendMessage (RPIPCGM_POWERLED, onoff >= 250 ? 100 : onoff * 10 / 26, 0, NULL, 0, &guestinfo, NULL); - break; + RPSendMessage (RPIPCGM_POWERLED, onoff >= 250 ? 100 : onoff * 10 / 26, 0, NULL, 0, &guestinfo, NULL); + break; case 1: case 2: case 3: case 4: - RPPostMessagex (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_FLOPPY, led - 1), - MAKELONG (onoff ? -1 : 0, write ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ) , &guestinfo); - break; - } + RPPostMessagex (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_FLOPPY, led - 1), + MAKELONG (onoff ? -1 : 0, write ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ) , &guestinfo); + break; + } } void rp_hd_activity (int num, int onoff, int write) { - if (!cando ()) - return; - if (num < 0) - return; - if (onoff) - RPPostMessagex (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_HD, num), - MAKELONG (200, write ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ), &guestinfo); + if (!cando ()) + return; + if (num < 0) + return; + if (onoff) + RPPostMessagex (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_HD, num), + MAKELONG (200, write ? RP_DEVICEACTIVITY_WRITE : RP_DEVICEACTIVITY_READ), &guestinfo); } void rp_cd_activity (int num, int onoff) { - if (!cando ()) - return; - if (num < 0) - return; - if ((cd_mask & (1 << num)) != ((onoff ? 1 : 0) << num)) { - cd_mask ^= 1 << num; - RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_CD, cd_mask, NULL, 0, &guestinfo, NULL); - } - if (onoff) { - RPPostMessage (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_CD, num), - MAKELONG (200, RP_DEVICEACTIVITY_READ), &guestinfo); - } + if (!cando ()) + return; + if (num < 0) + return; + if ((cd_mask & (1 << num)) != ((onoff ? 1 : 0) << num)) { + cd_mask ^= 1 << num; + RPSendMessagex (RPIPCGM_DEVICES, RP_DEVICE_CD, cd_mask, NULL, 0, &guestinfo, NULL); + } + if (onoff) { + RPPostMessage (RPIPCGM_DEVICEACTIVITY, MAKEWORD (RP_DEVICE_CD, num), + MAKELONG (200, RP_DEVICEACTIVITY_READ), &guestinfo); + } } void rp_update_volume (struct uae_prefs *p) { - if (!cando ()) - return; - RPSendMessagex (RPIPCGM_VOLUME, (WPARAM)(100 - p->sound_volume), 0, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + RPSendMessagex (RPIPCGM_VOLUME, (WPARAM)(100 - p->sound_volume), 0, NULL, 0, &guestinfo, NULL); } void rp_pause (int paused) { - if (!cando ()) - return; - if (isrecursive ()) - return; - if (currentpausemode != paused) - RPSendMessagex (RPIPCGM_PAUSE, (WPARAM)paused, 0, NULL, 0, &guestinfo, NULL); - currentpausemode = paused; + if (!cando ()) + return; + if (isrecursive ()) + return; + if (currentpausemode != paused) + RPSendMessagex (RPIPCGM_PAUSE, (WPARAM)paused, 0, NULL, 0, &guestinfo, NULL); + currentpausemode = paused; } static void rp_mouse (void) { - int flags = 0; - - if (!cando ()) - return; - if (mousemagic) - flags |= RP_MOUSECAPTURE_MAGICMOUSE; - if (mousecapture) - flags |= RP_MOUSECAPTURE_CAPTURED; - RPSendMessagex (RPIPCGM_MOUSECAPTURE, flags, 0, NULL, 0, &guestinfo, NULL); + int flags = 0; + + if (!cando ()) + return; + if (mousemagic) + flags |= RP_MOUSECAPTURE_MAGICMOUSE; + if (mousecapture) + flags |= RP_MOUSECAPTURE_CAPTURED; + RPSendMessagex (RPIPCGM_MOUSECAPTURE, flags, 0, NULL, 0, &guestinfo, NULL); } void rp_mouse_capture (int captured) { - mousecapture = captured; - rp_mouse (); + mousecapture = captured; + rp_mouse (); } void rp_mouse_magic (int magic) { - mousemagic = magic; - rp_mouse (); + mousemagic = magic; + rp_mouse (); } void rp_activate (int active, LPARAM lParam) { - if (!cando ()) - return; - RPSendMessagex (active ? RPIPCGM_ACTIVATED : RPIPCGM_DEACTIVATED, 0, lParam, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + RPSendMessagex (active ? RPIPCGM_ACTIVATED : RPIPCGM_DEACTIVATED, 0, lParam, NULL, 0, &guestinfo, NULL); } void rp_turbo (int active) { - if (!cando ()) - return; - if (recursive_device) - return; - RPSendMessagex (RPIPCGM_TURBO, RP_TURBO_CPU, active ? RP_TURBO_CPU : 0, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + if (recursive_device) + return; + RPSendMessagex (RPIPCGM_TURBO, RP_TURBO_CPU, active ? RP_TURBO_CPU : 0, NULL, 0, &guestinfo, NULL); } void rp_set_hwnd (HWND hWnd) { - struct RPScreenMode sm = { 0 }; - - if (!initialized) - return; - get_screenmode (&sm, &currprefs); - sm.hGuestWindow = hWnd; - if (hWnd != NULL) - hwndset = 1; - RPSendMessagex (RPIPCGM_SCREENMODE, 0, 0, &sm, sizeof sm, &guestinfo, NULL); + struct RPScreenMode sm = { 0 }; + + if (!initialized) + return; + get_screenmode (&sm, &currprefs); + sm.hGuestWindow = hWnd; + if (hWnd != NULL) + hwndset = 1; + RPSendMessagex (RPIPCGM_SCREENMODE, 0, 0, &sm, sizeof sm, &guestinfo, NULL); } void rp_set_enabledisable (int enabled) { - if (!cando ()) - return; - RPSendMessagex (enabled ? RPIPCGM_ENABLED : RPIPCGM_DISABLED, 0, 0, NULL, 0, &guestinfo, NULL); + if (!cando ()) + return; + RPSendMessagex (enabled ? RPIPCGM_ENABLED : RPIPCGM_DISABLED, 0, 0, NULL, 0, &guestinfo, NULL); } void rp_rtg_switch (void) { - if (!cando ()) - return; - sendfeatures (); + if (!cando ()) + return; + sendfeatures (); } static uae_u64 esctime; @@ -1021,66 +1021,66 @@ static int ignorerelease; static uae_u64 gett (void) { - SYSTEMTIME st; - FILETIME ft; - ULARGE_INTEGER li; - - GetSystemTime (&st); - if (!SystemTimeToFileTime (&st, &ft)) - return 0; - li.LowPart = ft.dwLowDateTime; - li.HighPart = ft.dwHighDateTime; - return li.QuadPart / 10000; + SYSTEMTIME st; + FILETIME ft; + ULARGE_INTEGER li; + + GetSystemTime (&st); + if (!SystemTimeToFileTime (&st, &ft)) + return 0; + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + return li.QuadPart / 10000; } void rp_vsync (void) { - uae_u64 t; - - if (!initialized) - return; - if (magicmouse_alive () != mousemagic) - rp_mouse_magic (magicmouse_alive ()); - if (!esctime) - return; - t = gett (); - if (t >= esctime) { - RPSendMessagex (RPIPCGM_ESCAPED, 0, 0, NULL, 0, &guestinfo, NULL); - ignorerelease = 1; - esctime = 0; - } + uae_u64 t; + + if (!initialized) + return; + if (magicmouse_alive () != mousemagic) + rp_mouse_magic (magicmouse_alive ()); + if (!esctime) + return; + t = gett (); + if (t >= esctime) { + RPSendMessagex (RPIPCGM_ESCAPED, 0, 0, NULL, 0, &guestinfo, NULL); + ignorerelease = 1; + esctime = 0; + } } int rp_checkesc (int scancode, uae_u8 *codes, int pressed, int num) { - uae_u64 t; - - if (!initialized) - goto end; - if (scancode != rp_rpescapekey) - goto end; - if (ignorerelease && !pressed) { + uae_u64 t; + + if (!initialized) + goto end; + if (scancode != rp_rpescapekey) + goto end; + if (ignorerelease && !pressed) { + ignorerelease = 0; + goto end; + } + t = gett(); + if (!t) + goto end; + if (pressed) { + esctime = t + rp_rpescapeholdtime; + return 1; + } + my_kbd_handler (num, scancode, 1); + my_kbd_handler (num, scancode, 0); ignorerelease = 0; - goto end; - } - t = gett(); - if (!t) - goto end; - if (pressed) { - esctime = t + rp_rpescapeholdtime; + esctime = 0; return 1; - } - my_kbd_handler (num, scancode, 1); - my_kbd_handler (num, scancode, 0); - ignorerelease = 0; - esctime = 0; - return 1; end: - esctime = 0; - return 0; + esctime = 0; + return 0; } int rp_isactive (void) { - return initialized; + return initialized; } diff --git a/od-win32/scaler.c b/od-win32/scaler.c index baf1e88d..51be377d 100644 --- a/od-win32/scaler.c +++ b/od-win32/scaler.c @@ -1,17 +1,17 @@ /* This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ /* Scaler (except Scale2x) code borrowed from ScummVM project */ @@ -72,10 +72,10 @@ static _inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D) const int x = x1+x2; const int y = y1+y2; static const int rmap[3][3] = { - {0, 0, -1}, - {0, 0, -1}, - {1, 1, 0} - }; + {0, 0, -1}, + {0, 0, -1}, + {1, 1, 0} + }; return rmap[y][x]; } @@ -112,10 +112,10 @@ void Super2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 d uint32 colorS1, colorS2; uint32 product1a, product1b, product2a, product2b; -//--------------------------------------- B1 B2 -// 4 5 6 S2 -// 1 2 3 S1 -// A1 A2 + //--------------------------------------- B1 B2 + // 4 5 6 S2 + // 1 2 3 S1 + // A1 A2 colorB0 = *(bP - nextlineSrc - 1); colorB1 = *(bP - nextlineSrc); @@ -137,7 +137,7 @@ void Super2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 d colorA2 = *(bP + 2 * nextlineSrc + 1); colorA3 = *(bP + 2 * nextlineSrc + 2); -//-------------------------------------- + //-------------------------------------- if (color2 == color6 && color5 != color3) { product2b = product1b = color2; } else if (color5 == color3 && color2 != color6) { @@ -219,10 +219,10 @@ void Super2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 d uint32 colorS1, colorS2; uint32 product1a, product1b, product2a, product2b; -//--------------------------------------- B1 B2 -// 4 5 6 S2 -// 1 2 3 S1 -// A1 A2 + //--------------------------------------- B1 B2 + // 4 5 6 S2 + // 1 2 3 S1 + // A1 A2 colorB0 = *(bP - nextlineSrc - 1); colorB1 = *(bP - nextlineSrc); @@ -244,7 +244,7 @@ void Super2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 d colorA2 = *(bP + 2 * nextlineSrc + 1); colorA3 = *(bP + 2 * nextlineSrc + 2); -//-------------------------------------- + //-------------------------------------- if (color2 == color6 && color5 != color3) { product2b = product1b = color2; } else if (color5 == color3 && color2 != color6) { @@ -559,11 +559,11 @@ void _2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi colorE, colorF, colorG, colorH, colorI, colorJ, colorK, colorL, colorM, colorN, colorO, colorP; uint32 product, product1, product2; -//--------------------------------------- -// Map of the pixels: I|E F|J -// G|A B|K -// H|C D|L -// M|N O|P + //--------------------------------------- + // Map of the pixels: I|E F|J + // G|A B|K + // H|C D|L + // M|N O|P colorI = *(bP - nextlineSrc - 1); colorE = *(bP - nextlineSrc); colorF = *(bP - nextlineSrc + 1); @@ -587,14 +587,14 @@ void _2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi if ((colorA == colorD) && (colorB != colorC)) { if (((colorA == colorE) && (colorB == colorL)) || ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))) { - product = colorA; + product = colorA; } else { product = INTERPOLATE(colorA, colorB); } if (((colorA == colorG) && (colorC == colorO)) || ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))) { - product1 = colorA; + product1 = colorA; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -602,14 +602,14 @@ void _2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi } else if ((colorB == colorC) && (colorA != colorD)) { if (((colorB == colorF) && (colorA == colorH)) || ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))) { - product = colorB; + product = colorB; } else { product = INTERPOLATE(colorA, colorB); } if (((colorC == colorH) && (colorA == colorF)) || ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))) { - product1 = colorC; + product1 = colorC; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -642,21 +642,21 @@ void _2xSaI_16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); if ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ)) { - product = colorA; + && (colorB != colorE) && (colorB == colorJ)) { + product = colorA; } else if ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI)) { - product = colorB; + && (colorA != colorF) && (colorA == colorI)) { + product = colorB; } else { product = INTERPOLATE(colorA, colorB); } if ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM)) { - product1 = colorA; + && (colorG != colorC) && (colorC == colorM)) { + product1 = colorA; } else if ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI)) { - product1 = colorC; + && (colorA != colorH) && (colorA == colorI)) { + product1 = colorC; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -693,11 +693,11 @@ void _2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi colorE, colorF, colorG, colorH, colorI, colorJ, colorK, colorL, colorM, colorN, colorO, colorP; uint32 product, product1, product2; -//--------------------------------------- -// Map of the pixels: I|E F|J -// G|A B|K -// H|C D|L -// M|N O|P + //--------------------------------------- + // Map of the pixels: I|E F|J + // G|A B|K + // H|C D|L + // M|N O|P colorI = *(bP - nextlineSrc - 1); colorE = *(bP - nextlineSrc); colorF = *(bP - nextlineSrc + 1); @@ -721,14 +721,14 @@ void _2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi if ((colorA == colorD) && (colorB != colorC)) { if (((colorA == colorE) && (colorB == colorL)) || ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))) { - product = colorA; + product = colorA; } else { product = INTERPOLATE(colorA, colorB); } if (((colorA == colorG) && (colorC == colorO)) || ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))) { - product1 = colorA; + product1 = colorA; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -736,14 +736,14 @@ void _2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi } else if ((colorB == colorC) && (colorA != colorD)) { if (((colorB == colorF) && (colorA == colorH)) || ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))) { - product = colorB; + product = colorB; } else { product = INTERPOLATE(colorA, colorB); } if (((colorC == colorH) && (colorA == colorF)) || ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))) { - product1 = colorC; + product1 = colorC; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -776,21 +776,21 @@ void _2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); if ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ)) { - product = colorA; + && (colorB != colorE) && (colorB == colorJ)) { + product = colorA; } else if ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI)) { - product = colorB; + && (colorA != colorF) && (colorA == colorI)) { + product = colorB; } else { product = INTERPOLATE(colorA, colorB); } if ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM)) { - product1 = colorA; + && (colorG != colorC) && (colorC == colorM)) { + product1 = colorA; } else if ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI)) { - product1 = colorC; + && (colorA != colorH) && (colorA == colorI)) { + product1 = colorC; } else { product1 = INTERPOLATE(colorA, colorC); } @@ -811,38 +811,38 @@ void _2xSaI_32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPi } /* - * This file is part of the Advance project. - * - * Copyright (C) 1999-2002 Andrea Mazzoleni - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ +* This file is part of the Advance project. +* +* Copyright (C) 1999-2002 Andrea Mazzoleni +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ /* - * This file contains a C and MMX implentation of the Scale2x effect. - * - * You can found an high level description of the effect at : - * - * http://scale2x.sourceforge.net/scale2x.html - * - * Alternatively at the previous license terms, you are allowed to use this - * code in your program with these conditions: - * - the program is not used in commercial activities. - * - the whole source code of the program is released with the binary. - * - derivative works of the program are allowed. - */ +* This file contains a C and MMX implentation of the Scale2x effect. +* +* You can found an high level description of the effect at : +* +* http://scale2x.sourceforge.net/scale2x.html +* +* Alternatively at the previous license terms, you are allowed to use this +* code in your program with these conditions: +* - the program is not used in commercial activities. +* - the whole source code of the program is released with the binary. +* - derivative works of the program are allowed. +*/ #define MMX extern int cpu_mmx; @@ -851,1007 +851,1007 @@ extern int cpu_mmx; #define ASM_JUMP_ALIGN ".p2align 4\n" static void internal_scale2x_16_def(u16 *dst0, u16* dst1, const u16* src0, const u16* src1, const u16* src2, unsigned count) { - /* first pixel */ - dst0[0] = src1[0]; - dst1[0] = src1[0]; - if (src1[1] == src0[0] && src2[0] != src0[0]) - dst0[1] =src0[0]; - else - dst0[1] =src1[0]; - if (src1[1] == src2[0] && src0[0] != src2[0]) - dst1[1] =src2[0]; - else - dst1[1] =src1[0]; - ++src0; - ++src1; - ++src2; - dst0 += 2; - dst1 += 2; - - /* central pixels */ - count -= 2; - while (count) { - if (src1[-1] == src0[0] && src2[0] != src0[0] && src1[1] != src0[0]) - dst0[0] = src0[0]; - else - dst0[0] = src1[0]; - if (src1[1] == src0[0] && src2[0] != src0[0] && src1[-1] != src0[0]) - dst0[1] =src0[0]; - else - dst0[1] =src1[0]; - - if (src1[-1] == src2[0] && src0[0] != src2[0] && src1[1] != src2[0]) - dst1[0] =src2[0]; - else - dst1[0] =src1[0]; - if (src1[1] == src2[0] && src0[0] != src2[0] && src1[-1] != src2[0]) - dst1[1] =src2[0]; - else - dst1[1] =src1[0]; - - ++src0; - ++src1; - ++src2; - dst0 += 2; - dst1 += 2; - --count; - } - - /* last pixel */ - if (src1[-1] == src0[0] && src2[0] != src0[0]) - dst0[0] =src0[0]; - else - dst0[0] =src1[0]; - if (src1[-1] == src2[0] && src0[0] != src2[0]) - dst1[0] =src2[0]; - else - dst1[0] =src1[0]; - dst0[1] =src1[0]; - dst1[1] =src1[0]; + /* first pixel */ + dst0[0] = src1[0]; + dst1[0] = src1[0]; + if (src1[1] == src0[0] && src2[0] != src0[0]) + dst0[1] =src0[0]; + else + dst0[1] =src1[0]; + if (src1[1] == src2[0] && src0[0] != src2[0]) + dst1[1] =src2[0]; + else + dst1[1] =src1[0]; + ++src0; + ++src1; + ++src2; + dst0 += 2; + dst1 += 2; + + /* central pixels */ + count -= 2; + while (count) { + if (src1[-1] == src0[0] && src2[0] != src0[0] && src1[1] != src0[0]) + dst0[0] = src0[0]; + else + dst0[0] = src1[0]; + if (src1[1] == src0[0] && src2[0] != src0[0] && src1[-1] != src0[0]) + dst0[1] =src0[0]; + else + dst0[1] =src1[0]; + + if (src1[-1] == src2[0] && src0[0] != src2[0] && src1[1] != src2[0]) + dst1[0] =src2[0]; + else + dst1[0] =src1[0]; + if (src1[1] == src2[0] && src0[0] != src2[0] && src1[-1] != src2[0]) + dst1[1] =src2[0]; + else + dst1[1] =src1[0]; + + ++src0; + ++src1; + ++src2; + dst0 += 2; + dst1 += 2; + --count; + } + + /* last pixel */ + if (src1[-1] == src0[0] && src2[0] != src0[0]) + dst0[0] =src0[0]; + else + dst0[0] =src1[0]; + if (src1[-1] == src2[0] && src0[0] != src2[0]) + dst1[0] =src2[0]; + else + dst1[0] =src1[0]; + dst0[1] =src1[0]; + dst1[1] =src1[0]; } static void internal_scale2x_32_def(u32* dst0, - u32* dst1, - const u32* src0, - const u32* src1, - const u32* src2, - unsigned count) { - /* first pixel */ - dst0[0] = src1[0]; - dst1[0] = src1[0]; - if (src1[1] == src0[0] && src2[0] != src0[0]) - dst0[1] = src0[0]; - else - dst0[1] = src1[0]; - if (src1[1] == src2[0] && src0[0] != src2[0]) - dst1[1] = src2[0]; - else - dst1[1] = src1[0]; - ++src0; - ++src1; - ++src2; - dst0 += 2; - dst1 += 2; - - /* central pixels */ - count -= 2; - while (count) { - if (src1[-1] == src0[0] && src2[0] != src0[0] && src1[1] != src0[0]) - dst0[0] = src0[0]; - else - dst0[0] = src1[0]; - if (src1[1] == src0[0] && src2[0] != src0[0] && src1[-1] != src0[0]) - dst0[1] = src0[0]; - else - dst0[1] = src1[0]; - - if (src1[-1] == src2[0] && src0[0] != src2[0] && src1[1] != src2[0]) - dst1[0] = src2[0]; - else - dst1[0] = src1[0]; - if (src1[1] == src2[0] && src0[0] != src2[0] && src1[-1] != src2[0]) - dst1[1] = src2[0]; - else - dst1[1] = src1[0]; - - ++src0; - ++src1; - ++src2; - dst0 += 2; - dst1 += 2; - --count; - } - - /* last pixel */ - if (src1[-1] == src0[0] && src2[0] != src0[0]) - dst0[0] = src0[0]; - else - dst0[0] = src1[0]; - if (src1[-1] == src2[0] && src0[0] != src2[0]) - dst1[0] = src2[0]; - else - dst1[0] = src1[0]; - dst0[1] = src1[0]; - dst1[1] = src1[0]; + u32* dst1, + const u32* src0, + const u32* src1, + const u32* src2, + unsigned count) { + /* first pixel */ + dst0[0] = src1[0]; + dst1[0] = src1[0]; + if (src1[1] == src0[0] && src2[0] != src0[0]) + dst0[1] = src0[0]; + else + dst0[1] = src1[0]; + if (src1[1] == src2[0] && src0[0] != src2[0]) + dst1[1] = src2[0]; + else + dst1[1] = src1[0]; + ++src0; + ++src1; + ++src2; + dst0 += 2; + dst1 += 2; + + /* central pixels */ + count -= 2; + while (count) { + if (src1[-1] == src0[0] && src2[0] != src0[0] && src1[1] != src0[0]) + dst0[0] = src0[0]; + else + dst0[0] = src1[0]; + if (src1[1] == src0[0] && src2[0] != src0[0] && src1[-1] != src0[0]) + dst0[1] = src0[0]; + else + dst0[1] = src1[0]; + + if (src1[-1] == src2[0] && src0[0] != src2[0] && src1[1] != src2[0]) + dst1[0] = src2[0]; + else + dst1[0] = src1[0]; + if (src1[1] == src2[0] && src0[0] != src2[0] && src1[-1] != src2[0]) + dst1[1] = src2[0]; + else + dst1[1] = src1[0]; + + ++src0; + ++src1; + ++src2; + dst0 += 2; + dst1 += 2; + --count; + } + + /* last pixel */ + if (src1[-1] == src0[0] && src2[0] != src0[0]) + dst0[0] = src0[0]; + else + dst0[0] = src1[0]; + if (src1[-1] == src2[0] && src0[0] != src2[0]) + dst1[0] = src2[0]; + else + dst1[0] = src1[0]; + dst0[1] = src1[0]; + dst1[1] = src1[0]; } #if defined(MMX) && (defined(X86_ASSEMBLY) || defined(X86_MSVC_ASSEMBLY)) static void internal_scale2x_16_mmx_single(u16* dst, const u16* src0, const u16* src1, const u16* src2, unsigned count) { - /* always do the first and last run */ - count -= 2*4; + /* always do the first and last run */ + count -= 2*4; #ifdef __GNUC__ - __asm__ __volatile__( - /* first run */ - /* set the current, current_pre, current_next registers */ - "pxor %%mm0,%%mm0\n" /* use a fake black out of screen */ - "movq 0(%1),%%mm7\n" - "movq 8(%1),%%mm1\n" - "psrlq $48,%%mm0\n" - "psllq $48,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $16,%%mm2\n" - "psrlq $16,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqw %%mm6,%%mm2\n" - "pcmpeqw %%mm6,%%mm4\n" - "pcmpeqw (%2),%%mm3\n" - "pcmpeqw (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqw %%mm1,%%mm2\n" - "pcmpeqw %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpcklwd %%mm4,%%mm2\n" - "punpckhwd %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - - /* next */ - "addl $8,%0\n" - "addl $8,%1\n" - "addl $8,%2\n" - "addl $16,%3\n" - - /* central runs */ - "shrl $2,%4\n" - "jz 1f\n" - ASM_JUMP_ALIGN - "0:\n" - - /* set the current, current_pre, current_next registers */ - "movq -8(%1),%%mm0\n" - "movq (%1),%%mm7\n" - "movq 8(%1),%%mm1\n" - "psrlq $48,%%mm0\n" - "psllq $48,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $16,%%mm2\n" - "psrlq $16,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqw %%mm6,%%mm2\n" - "pcmpeqw %%mm6,%%mm4\n" - "pcmpeqw (%2),%%mm3\n" - "pcmpeqw (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqw %%mm1,%%mm2\n" - "pcmpeqw %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpcklwd %%mm4,%%mm2\n" - "punpckhwd %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - - /* next */ - "addl $8,%0\n" - "addl $8,%1\n" - "addl $8,%2\n" - "addl $16,%3\n" - - "decl %4\n" - "jnz 0b\n" - "1:\n" - - /* final run */ - /* set the current, current_pre, current_next registers */ - "movq -8(%1),%%mm0\n" - "movq (%1),%%mm7\n" - "pxor %%mm1,%%mm1\n" /* use a fake black out of screen */ - "psrlq $48,%%mm0\n" - "psllq $48,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $16,%%mm2\n" - "psrlq $16,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqw %%mm6,%%mm2\n" - "pcmpeqw %%mm6,%%mm4\n" - "pcmpeqw (%2),%%mm3\n" - "pcmpeqw (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqw %%mm1,%%mm2\n" - "pcmpeqw %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpcklwd %%mm4,%%mm2\n" - "punpckhwd %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - "emms\n" - - : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count) - : - : "cc" - ); + __asm__ __volatile__( + /* first run */ + /* set the current, current_pre, current_next registers */ + "pxor %%mm0,%%mm0\n" /* use a fake black out of screen */ + "movq 0(%1),%%mm7\n" + "movq 8(%1),%%mm1\n" + "psrlq $48,%%mm0\n" + "psllq $48,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $16,%%mm2\n" + "psrlq $16,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqw %%mm6,%%mm2\n" + "pcmpeqw %%mm6,%%mm4\n" + "pcmpeqw (%2),%%mm3\n" + "pcmpeqw (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqw %%mm1,%%mm2\n" + "pcmpeqw %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpcklwd %%mm4,%%mm2\n" + "punpckhwd %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + + /* next */ + "addl $8,%0\n" + "addl $8,%1\n" + "addl $8,%2\n" + "addl $16,%3\n" + + /* central runs */ + "shrl $2,%4\n" + "jz 1f\n" + ASM_JUMP_ALIGN + "0:\n" + + /* set the current, current_pre, current_next registers */ + "movq -8(%1),%%mm0\n" + "movq (%1),%%mm7\n" + "movq 8(%1),%%mm1\n" + "psrlq $48,%%mm0\n" + "psllq $48,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $16,%%mm2\n" + "psrlq $16,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqw %%mm6,%%mm2\n" + "pcmpeqw %%mm6,%%mm4\n" + "pcmpeqw (%2),%%mm3\n" + "pcmpeqw (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqw %%mm1,%%mm2\n" + "pcmpeqw %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpcklwd %%mm4,%%mm2\n" + "punpckhwd %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + + /* next */ + "addl $8,%0\n" + "addl $8,%1\n" + "addl $8,%2\n" + "addl $16,%3\n" + + "decl %4\n" + "jnz 0b\n" + "1:\n" + + /* final run */ + /* set the current, current_pre, current_next registers */ + "movq -8(%1),%%mm0\n" + "movq (%1),%%mm7\n" + "pxor %%mm1,%%mm1\n" /* use a fake black out of screen */ + "psrlq $48,%%mm0\n" + "psllq $48,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $16,%%mm2\n" + "psrlq $16,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqw %%mm6,%%mm2\n" + "pcmpeqw %%mm6,%%mm4\n" + "pcmpeqw (%2),%%mm3\n" + "pcmpeqw (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqw %%mm1,%%mm2\n" + "pcmpeqw %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpcklwd %%mm4,%%mm2\n" + "punpckhwd %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + "emms\n" + + : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count) + : + : "cc" + ); #else - __asm { - mov eax, src0; - mov ebx, src1; - mov ecx, src2; - mov edx, dst; - mov esi, count; - - /* first run */ - /* set the current, current_pre, current_next registers */ - pxor mm0,mm0; /* use a fake black out of screen */ - movq mm7, qword ptr [ebx]; - movq mm1, qword ptr [ebx + 8]; - psrlq mm0, 48; - psllq mm1, 48; - movq mm2, mm7; - movq mm3, mm7; - psllq mm2, 16; - psrlq mm3, 16; - por mm0, mm2; - por mm1, mm3; - - /* current_upper */ - movq mm6, qword ptr [eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2, mm0; - movq mm4, mm1; - movq mm3, mm0; - movq mm5, mm1; - pcmpeqw mm2, mm6; - pcmpeqw mm4, mm6; - pcmpeqw mm3, qword ptr [ecx]; - pcmpeqw mm5, qword ptr [ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqw mm2,mm1; - pcmpeqw mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpcklwd mm2,mm4; - punpckhwd mm3,mm4; - movq qword ptr [edx], mm2; - movq qword ptr [edx + 8], mm3; - - /* next */ - add eax, 8; - add ebx, 8; - add ecx, 8; - add edx, 16; - - /* central runs */ - shr esi, 2; - jz label1; - align 4; - label0: - - /* set the current, current_pre, current_next registers */ - movq mm0, qword ptr [ebx-8]; - movq mm7, qword ptr [ebx]; - movq mm1, qword ptr [ebx+8]; - psrlq mm0,48; - psllq mm1,48; - movq mm2,mm7; - movq mm3,mm7; - psllq mm2,16; - psrlq mm3,16; - por mm0,mm2; - por mm1,mm3; - - /* current_upper */ - movq mm6, qword ptr [eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2,mm0; - movq mm4,mm1; - movq mm3,mm0; - movq mm5,mm1; - pcmpeqw mm2,mm6; - pcmpeqw mm4,mm6; - pcmpeqw mm3, qword ptr [ecx]; - pcmpeqw mm5, qword ptr [ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqw mm2,mm1; - pcmpeqw mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpcklwd mm2,mm4; - punpckhwd mm3,mm4; - movq qword ptr [edx], mm2; - movq qword ptr [edx+8], mm3; - - /* next */ - add eax,8; - add ebx,8; - add ecx,8; - add edx,16; - - dec esi; - jnz label0; - label1: - - /* final run */ - /* set the current, current_pre, current_next registers */ - movq mm0, qword ptr [ebx-8]; - movq mm7, qword ptr [ebx]; - pxor mm1,mm1; /* use a fake black out of screen */ - psrlq mm0,48; - psllq mm1,48; - movq mm2,mm7; - movq mm3,mm7; - psllq mm2,16; - psrlq mm3,16; - por mm0,mm2; - por mm1,mm3; - - /* current_upper */ - movq mm6, qword ptr [eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2,mm0; - movq mm4,mm1; - movq mm3,mm0; - movq mm5,mm1; - pcmpeqw mm2,mm6; - pcmpeqw mm4,mm6; - pcmpeqw mm3, qword ptr [ecx]; - pcmpeqw mm5, qword ptr [ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqw mm2,mm1; - pcmpeqw mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpcklwd mm2,mm4; - punpckhwd mm3,mm4; - movq qword ptr [edx], mm2; - movq qword ptr [edx+8], mm3; - - mov src0, eax; - mov src1, ebx; - mov src2, ecx; - mov dst, edx; - mov count, esi; - - emms; - } + __asm { + mov eax, src0; + mov ebx, src1; + mov ecx, src2; + mov edx, dst; + mov esi, count; + + /* first run */ + /* set the current, current_pre, current_next registers */ + pxor mm0,mm0; /* use a fake black out of screen */ + movq mm7, qword ptr [ebx]; + movq mm1, qword ptr [ebx + 8]; + psrlq mm0, 48; + psllq mm1, 48; + movq mm2, mm7; + movq mm3, mm7; + psllq mm2, 16; + psrlq mm3, 16; + por mm0, mm2; + por mm1, mm3; + + /* current_upper */ + movq mm6, qword ptr [eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2, mm0; + movq mm4, mm1; + movq mm3, mm0; + movq mm5, mm1; + pcmpeqw mm2, mm6; + pcmpeqw mm4, mm6; + pcmpeqw mm3, qword ptr [ecx]; + pcmpeqw mm5, qword ptr [ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqw mm2,mm1; + pcmpeqw mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpcklwd mm2,mm4; + punpckhwd mm3,mm4; + movq qword ptr [edx], mm2; + movq qword ptr [edx + 8], mm3; + + /* next */ + add eax, 8; + add ebx, 8; + add ecx, 8; + add edx, 16; + + /* central runs */ + shr esi, 2; + jz label1; + align 4; +label0: + + /* set the current, current_pre, current_next registers */ + movq mm0, qword ptr [ebx-8]; + movq mm7, qword ptr [ebx]; + movq mm1, qword ptr [ebx+8]; + psrlq mm0,48; + psllq mm1,48; + movq mm2,mm7; + movq mm3,mm7; + psllq mm2,16; + psrlq mm3,16; + por mm0,mm2; + por mm1,mm3; + + /* current_upper */ + movq mm6, qword ptr [eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2,mm0; + movq mm4,mm1; + movq mm3,mm0; + movq mm5,mm1; + pcmpeqw mm2,mm6; + pcmpeqw mm4,mm6; + pcmpeqw mm3, qword ptr [ecx]; + pcmpeqw mm5, qword ptr [ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqw mm2,mm1; + pcmpeqw mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpcklwd mm2,mm4; + punpckhwd mm3,mm4; + movq qword ptr [edx], mm2; + movq qword ptr [edx+8], mm3; + + /* next */ + add eax,8; + add ebx,8; + add ecx,8; + add edx,16; + + dec esi; + jnz label0; +label1: + + /* final run */ + /* set the current, current_pre, current_next registers */ + movq mm0, qword ptr [ebx-8]; + movq mm7, qword ptr [ebx]; + pxor mm1,mm1; /* use a fake black out of screen */ + psrlq mm0,48; + psllq mm1,48; + movq mm2,mm7; + movq mm3,mm7; + psllq mm2,16; + psrlq mm3,16; + por mm0,mm2; + por mm1,mm3; + + /* current_upper */ + movq mm6, qword ptr [eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2,mm0; + movq mm4,mm1; + movq mm3,mm0; + movq mm5,mm1; + pcmpeqw mm2,mm6; + pcmpeqw mm4,mm6; + pcmpeqw mm3, qword ptr [ecx]; + pcmpeqw mm5, qword ptr [ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqw mm2,mm1; + pcmpeqw mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpcklwd mm2,mm4; + punpckhwd mm3,mm4; + movq qword ptr [edx], mm2; + movq qword ptr [edx+8], mm3; + + mov src0, eax; + mov src1, ebx; + mov src2, ecx; + mov dst, edx; + mov count, esi; + + emms; + } #endif } static void internal_scale2x_32_mmx_single(u32* dst, const u32* src0, const u32* src1, const u32* src2, unsigned count) { - /* always do the first and last run */ - count -= 2*2; + /* always do the first and last run */ + count -= 2*2; #ifdef __GNUC__ - __asm__ __volatile__( - /* first run */ - /* set the current, current_pre, current_next registers */ - "pxor %%mm0,%%mm0\n" /* use a fake black out of screen */ - "movq 0(%1),%%mm7\n" - "movq 8(%1),%%mm1\n" - "psrlq $32,%%mm0\n" - "psllq $32,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $32,%%mm2\n" - "psrlq $32,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqd %%mm6,%%mm2\n" - "pcmpeqd %%mm6,%%mm4\n" - "pcmpeqd (%2),%%mm3\n" - "pcmpeqd (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqd %%mm1,%%mm2\n" - "pcmpeqd %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpckldq %%mm4,%%mm2\n" - "punpckhdq %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - - /* next */ - "addl $8,%0\n" - "addl $8,%1\n" - "addl $8,%2\n" - "addl $16,%3\n" - - /* central runs */ - "shrl $1,%4\n" - "jz 1f\n" - ASM_JUMP_ALIGN - "0:\n" - - /* set the current, current_pre, current_next registers */ - "movq -8(%1),%%mm0\n" - "movq (%1),%%mm7\n" - "movq 8(%1),%%mm1\n" - "psrlq $32,%%mm0\n" - "psllq $32,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $32,%%mm2\n" - "psrlq $32,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqd %%mm6,%%mm2\n" - "pcmpeqd %%mm6,%%mm4\n" - "pcmpeqd (%2),%%mm3\n" - "pcmpeqd (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqd %%mm1,%%mm2\n" - "pcmpeqd %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpckldq %%mm4,%%mm2\n" - "punpckhdq %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - - /* next */ - "addl $8,%0\n" - "addl $8,%1\n" - "addl $8,%2\n" - "addl $16,%3\n" - - "decl %4\n" - "jnz 0b\n" - "1:\n" - - /* final run */ - /* set the current, current_pre, current_next registers */ - "movq -8(%1),%%mm0\n" - "movq (%1),%%mm7\n" - "pxor %%mm1,%%mm1\n" /* use a fake black out of screen */ - "psrlq $32,%%mm0\n" - "psllq $32,%%mm1\n" - "movq %%mm7,%%mm2\n" - "movq %%mm7,%%mm3\n" - "psllq $32,%%mm2\n" - "psrlq $32,%%mm3\n" - "por %%mm2,%%mm0\n" - "por %%mm3,%%mm1\n" - - /* current_upper */ - "movq (%0),%%mm6\n" - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "movq %%mm0,%%mm3\n" - "movq %%mm1,%%mm5\n" - "pcmpeqd %%mm6,%%mm2\n" - "pcmpeqd %%mm6,%%mm4\n" - "pcmpeqd (%2),%%mm3\n" - "pcmpeqd (%2),%%mm5\n" - "pandn %%mm2,%%mm3\n" - "pandn %%mm4,%%mm5\n" - "movq %%mm0,%%mm2\n" - "movq %%mm1,%%mm4\n" - "pcmpeqd %%mm1,%%mm2\n" - "pcmpeqd %%mm0,%%mm4\n" - "pandn %%mm3,%%mm2\n" - "pandn %%mm5,%%mm4\n" - "movq %%mm2,%%mm3\n" - "movq %%mm4,%%mm5\n" - "pand %%mm6,%%mm2\n" - "pand %%mm6,%%mm4\n" - "pandn %%mm7,%%mm3\n" - "pandn %%mm7,%%mm5\n" - "por %%mm3,%%mm2\n" - "por %%mm5,%%mm4\n" - - /* set *dst0 */ - "movq %%mm2,%%mm3\n" - "punpckldq %%mm4,%%mm2\n" - "punpckhdq %%mm4,%%mm3\n" - "movq %%mm2,(%3)\n" - "movq %%mm3,8(%3)\n" - "emms\n" - - : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count) - : - : "cc" - ); + __asm__ __volatile__( + /* first run */ + /* set the current, current_pre, current_next registers */ + "pxor %%mm0,%%mm0\n" /* use a fake black out of screen */ + "movq 0(%1),%%mm7\n" + "movq 8(%1),%%mm1\n" + "psrlq $32,%%mm0\n" + "psllq $32,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $32,%%mm2\n" + "psrlq $32,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqd %%mm6,%%mm2\n" + "pcmpeqd %%mm6,%%mm4\n" + "pcmpeqd (%2),%%mm3\n" + "pcmpeqd (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqd %%mm1,%%mm2\n" + "pcmpeqd %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpckldq %%mm4,%%mm2\n" + "punpckhdq %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + + /* next */ + "addl $8,%0\n" + "addl $8,%1\n" + "addl $8,%2\n" + "addl $16,%3\n" + + /* central runs */ + "shrl $1,%4\n" + "jz 1f\n" + ASM_JUMP_ALIGN + "0:\n" + + /* set the current, current_pre, current_next registers */ + "movq -8(%1),%%mm0\n" + "movq (%1),%%mm7\n" + "movq 8(%1),%%mm1\n" + "psrlq $32,%%mm0\n" + "psllq $32,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $32,%%mm2\n" + "psrlq $32,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqd %%mm6,%%mm2\n" + "pcmpeqd %%mm6,%%mm4\n" + "pcmpeqd (%2),%%mm3\n" + "pcmpeqd (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqd %%mm1,%%mm2\n" + "pcmpeqd %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpckldq %%mm4,%%mm2\n" + "punpckhdq %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + + /* next */ + "addl $8,%0\n" + "addl $8,%1\n" + "addl $8,%2\n" + "addl $16,%3\n" + + "decl %4\n" + "jnz 0b\n" + "1:\n" + + /* final run */ + /* set the current, current_pre, current_next registers */ + "movq -8(%1),%%mm0\n" + "movq (%1),%%mm7\n" + "pxor %%mm1,%%mm1\n" /* use a fake black out of screen */ + "psrlq $32,%%mm0\n" + "psllq $32,%%mm1\n" + "movq %%mm7,%%mm2\n" + "movq %%mm7,%%mm3\n" + "psllq $32,%%mm2\n" + "psrlq $32,%%mm3\n" + "por %%mm2,%%mm0\n" + "por %%mm3,%%mm1\n" + + /* current_upper */ + "movq (%0),%%mm6\n" + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "movq %%mm0,%%mm3\n" + "movq %%mm1,%%mm5\n" + "pcmpeqd %%mm6,%%mm2\n" + "pcmpeqd %%mm6,%%mm4\n" + "pcmpeqd (%2),%%mm3\n" + "pcmpeqd (%2),%%mm5\n" + "pandn %%mm2,%%mm3\n" + "pandn %%mm4,%%mm5\n" + "movq %%mm0,%%mm2\n" + "movq %%mm1,%%mm4\n" + "pcmpeqd %%mm1,%%mm2\n" + "pcmpeqd %%mm0,%%mm4\n" + "pandn %%mm3,%%mm2\n" + "pandn %%mm5,%%mm4\n" + "movq %%mm2,%%mm3\n" + "movq %%mm4,%%mm5\n" + "pand %%mm6,%%mm2\n" + "pand %%mm6,%%mm4\n" + "pandn %%mm7,%%mm3\n" + "pandn %%mm7,%%mm5\n" + "por %%mm3,%%mm2\n" + "por %%mm5,%%mm4\n" + + /* set *dst0 */ + "movq %%mm2,%%mm3\n" + "punpckldq %%mm4,%%mm2\n" + "punpckhdq %%mm4,%%mm3\n" + "movq %%mm2,(%3)\n" + "movq %%mm3,8(%3)\n" + "emms\n" + + : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (dst), "+r" (count) + : + : "cc" + ); #else - __asm { - mov eax, src0; - mov ebx, src1; - mov ecx, src2; - mov edx, dst; - mov esi, count; - - /* first run */ - /* set the current, current_pre, current_next registers */ - pxor mm0,mm0; - movq mm7,qword ptr [ebx]; - movq mm1,qword ptr [ebx + 8]; - psrlq mm0,32; - psllq mm1,32; - movq mm2,mm7; - movq mm3,mm7; - psllq mm2,32; - psrlq mm3,32; - por mm0,mm2; - por mm1,mm3; - - /* current_upper */ - movq mm6,qword ptr [eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2,mm0; - movq mm4,mm1; - movq mm3,mm0; - movq mm5,mm1; - pcmpeqd mm2,mm6; - pcmpeqd mm4,mm6; - pcmpeqd mm3,qword ptr [ecx]; - pcmpeqd mm5,qword ptr [ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqd mm2,mm1; - pcmpeqd mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpckldq mm2,mm4; - punpckhdq mm3,mm4; - movq qword ptr [edx],mm2; - movq qword ptr [edx+8],mm3; - - /* next */ - add eax,8; - add ebx,8; - add ecx,8; - add edx,16; - - /* central runs */ - shr esi,1; - jz label1; + __asm { + mov eax, src0; + mov ebx, src1; + mov ecx, src2; + mov edx, dst; + mov esi, count; + + /* first run */ + /* set the current, current_pre, current_next registers */ + pxor mm0,mm0; + movq mm7,qword ptr [ebx]; + movq mm1,qword ptr [ebx + 8]; + psrlq mm0,32; + psllq mm1,32; + movq mm2,mm7; + movq mm3,mm7; + psllq mm2,32; + psrlq mm3,32; + por mm0,mm2; + por mm1,mm3; + + /* current_upper */ + movq mm6,qword ptr [eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2,mm0; + movq mm4,mm1; + movq mm3,mm0; + movq mm5,mm1; + pcmpeqd mm2,mm6; + pcmpeqd mm4,mm6; + pcmpeqd mm3,qword ptr [ecx]; + pcmpeqd mm5,qword ptr [ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqd mm2,mm1; + pcmpeqd mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpckldq mm2,mm4; + punpckhdq mm3,mm4; + movq qword ptr [edx],mm2; + movq qword ptr [edx+8],mm3; + + /* next */ + add eax,8; + add ebx,8; + add ecx,8; + add edx,16; + + /* central runs */ + shr esi,1; + jz label1; label0: - /* set the current, current_pre, current_next registers */ - movq mm0,qword ptr [ebx-8]; - movq mm7,qword ptr [ebx]; - movq mm1,qword ptr [ebx+8]; - psrlq mm0,32; - psllq mm1,32; - movq mm2,mm7; - movq mm3,mm7; - psllq mm2,32; - psrlq mm3,32; - por mm0,mm2; - por mm1,mm3; - - /* current_upper */ - movq mm6,qword ptr[eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2,mm0; - movq mm4,mm1; - movq mm3,mm0; - movq mm5,mm1; - pcmpeqd mm2,mm6; - pcmpeqd mm4,mm6; - pcmpeqd mm3,qword ptr[ecx]; - pcmpeqd mm5,qword ptr[ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqd mm2,mm1; - pcmpeqd mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpckldq mm2,mm4; - punpckhdq mm3,mm4; - movq qword ptr [edx],mm2; - movq qword ptr [edx+8],mm3; - - /* next */ - add eax,8; - add ebx,8; - add ecx,8; - add edx,16; - - dec esi; - jnz label0; + /* set the current, current_pre, current_next registers */ + movq mm0,qword ptr [ebx-8]; + movq mm7,qword ptr [ebx]; + movq mm1,qword ptr [ebx+8]; + psrlq mm0,32; + psllq mm1,32; + movq mm2,mm7; + movq mm3,mm7; + psllq mm2,32; + psrlq mm3,32; + por mm0,mm2; + por mm1,mm3; + + /* current_upper */ + movq mm6,qword ptr[eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2,mm0; + movq mm4,mm1; + movq mm3,mm0; + movq mm5,mm1; + pcmpeqd mm2,mm6; + pcmpeqd mm4,mm6; + pcmpeqd mm3,qword ptr[ecx]; + pcmpeqd mm5,qword ptr[ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqd mm2,mm1; + pcmpeqd mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpckldq mm2,mm4; + punpckhdq mm3,mm4; + movq qword ptr [edx],mm2; + movq qword ptr [edx+8],mm3; + + /* next */ + add eax,8; + add ebx,8; + add ecx,8; + add edx,16; + + dec esi; + jnz label0; label1: - /* final run */ - /* set the current, current_pre, current_next registers */ - movq mm0,qword ptr [ebx-8]; - movq mm7,qword ptr [ebx]; - pxor mm1,mm1; - psrlq mm0,32; - psllq mm1,32; - movq mm2,mm7; - movq mm3,mm7; - psllq mm2,32; - psrlq mm3,32; - por mm0,mm2; - por mm1,mm3; - - /* current_upper */ - movq mm6,qword ptr [eax]; - - /* compute the upper-left pixel for dst0 on %%mm2 */ - /* compute the upper-right pixel for dst0 on %%mm4 */ - movq mm2,mm0; - movq mm4,mm1; - movq mm3,mm0; - movq mm5,mm1; - pcmpeqd mm2,mm6; - pcmpeqd mm4,mm6; - pcmpeqd mm3,qword ptr [ecx]; - pcmpeqd mm5,qword ptr [ecx]; - pandn mm3,mm2; - pandn mm5,mm4; - movq mm2,mm0; - movq mm4,mm1; - pcmpeqd mm2,mm1; - pcmpeqd mm4,mm0; - pandn mm2,mm3; - pandn mm4,mm5; - movq mm3,mm2; - movq mm5,mm4; - pand mm2,mm6; - pand mm4,mm6; - pandn mm3,mm7; - pandn mm5,mm7; - por mm2,mm3; - por mm4,mm5; - - /* set *dst0 */ - movq mm3,mm2; - punpckldq mm2,mm4; - punpckhdq mm3,mm4; - movq qword ptr [edx],mm2; - movq qword ptr [edx+8],mm3; - - mov src0, eax; - mov src1, ebx; - mov src2, ecx; - mov dst, edx; - mov count, esi; - - emms; - } + /* final run */ + /* set the current, current_pre, current_next registers */ + movq mm0,qword ptr [ebx-8]; + movq mm7,qword ptr [ebx]; + pxor mm1,mm1; + psrlq mm0,32; + psllq mm1,32; + movq mm2,mm7; + movq mm3,mm7; + psllq mm2,32; + psrlq mm3,32; + por mm0,mm2; + por mm1,mm3; + + /* current_upper */ + movq mm6,qword ptr [eax]; + + /* compute the upper-left pixel for dst0 on %%mm2 */ + /* compute the upper-right pixel for dst0 on %%mm4 */ + movq mm2,mm0; + movq mm4,mm1; + movq mm3,mm0; + movq mm5,mm1; + pcmpeqd mm2,mm6; + pcmpeqd mm4,mm6; + pcmpeqd mm3,qword ptr [ecx]; + pcmpeqd mm5,qword ptr [ecx]; + pandn mm3,mm2; + pandn mm5,mm4; + movq mm2,mm0; + movq mm4,mm1; + pcmpeqd mm2,mm1; + pcmpeqd mm4,mm0; + pandn mm2,mm3; + pandn mm4,mm5; + movq mm3,mm2; + movq mm5,mm4; + pand mm2,mm6; + pand mm4,mm6; + pandn mm3,mm7; + pandn mm5,mm7; + por mm2,mm3; + por mm4,mm5; + + /* set *dst0 */ + movq mm3,mm2; + punpckldq mm2,mm4; + punpckhdq mm3,mm4; + movq qword ptr [edx],mm2; + movq qword ptr [edx+8],mm3; + + mov src0, eax; + mov src1, ebx; + mov src2, ecx; + mov dst, edx; + mov count, esi; + + emms; + } #endif } static void internal_scale2x_16_mmx(u16* dst0, u16* dst1, const u16* src0, const u16* src1, const u16* src2, unsigned count) { - // assert( count >= 2*4 ); - internal_scale2x_16_mmx_single(dst0, src0, src1, src2, count); - internal_scale2x_16_mmx_single(dst1, src2, src1, src0, count); + // assert( count >= 2*4 ); + internal_scale2x_16_mmx_single(dst0, src0, src1, src2, count); + internal_scale2x_16_mmx_single(dst1, src2, src1, src0, count); } static void internal_scale2x_32_mmx(u32* dst0, u32* dst1, const u32* src0, const u32* src1, const u32* src2, unsigned count) { - // assert( count >= 2*2 ); - internal_scale2x_32_mmx_single(dst0, src0, src1, src2, count); - internal_scale2x_32_mmx_single(dst1, src2, src1, src0, count); + // assert( count >= 2*2 ); + internal_scale2x_32_mmx_single(dst0, src0, src1, src2, count); + internal_scale2x_32_mmx_single(dst1, src2, src1, src0, count); } #endif void AdMame2x(u8 *srcPtr, u32 srcPitch, /* u8 deltaPtr, */ - u8 *dstPtr, u32 dstPitch, int width, int height) + u8 *dstPtr, u32 dstPitch, int width, int height) { - u16 *dst0 = (u16 *)dstPtr; - u16 *dst1 = dst0 + (dstPitch/2); + u16 *dst0 = (u16 *)dstPtr; + u16 *dst1 = dst0 + (dstPitch/2); - u16 *src0 = (u16 *)srcPtr; - u16 *src1 = src0 + (srcPitch/2); - u16 *src2 = src1 + (srcPitch/2); + u16 *src0 = (u16 *)srcPtr; + u16 *src1 = src0 + (srcPitch/2); + u16 *src2 = src1 + (srcPitch/2); #if defined(MMX) && (defined(X86_ASSEMBLY) || defined(X86_MSVC_ASSEMBLY)) - if(cpu_mmx) { - internal_scale2x_16_mmx(dst0, dst1, src0, src0, src1, width); - - { - int count = height; - - count -= 2; - while(count) { - dst0 += dstPitch; - dst1 += dstPitch; - internal_scale2x_16_mmx(dst0, dst1, src0, src1, src2, width); - src0 = src1; - src1 = src2; - src2 += srcPitch/2; - --count; - } - } - dst0 += dstPitch; - dst1 += dstPitch; - internal_scale2x_16_mmx(dst0, dst1, src0, src1, src1, width); - } else { + if(cpu_mmx) { + internal_scale2x_16_mmx(dst0, dst1, src0, src0, src1, width); + + { + int count = height; + + count -= 2; + while(count) { + dst0 += dstPitch; + dst1 += dstPitch; + internal_scale2x_16_mmx(dst0, dst1, src0, src1, src2, width); + src0 = src1; + src1 = src2; + src2 += srcPitch/2; + --count; + } + } + dst0 += dstPitch; + dst1 += dstPitch; + internal_scale2x_16_mmx(dst0, dst1, src0, src1, src1, width); + } else { #endif - internal_scale2x_16_def(dst0, dst1, src0, src0, src1, width); - - { - int count = height; - - count -= 2; - while(count) { - dst0 += dstPitch; - dst1 += dstPitch; - internal_scale2x_16_def(dst0, dst1, src0, src1, src2, width); - src0 = src1; - src1 = src2; - src2 += srcPitch/2; - --count; - } - } - dst0 += dstPitch; - dst1 += dstPitch; - internal_scale2x_16_def(dst0, dst1, src0, src1, src1, width); + internal_scale2x_16_def(dst0, dst1, src0, src0, src1, width); + + { + int count = height; + + count -= 2; + while(count) { + dst0 += dstPitch; + dst1 += dstPitch; + internal_scale2x_16_def(dst0, dst1, src0, src1, src2, width); + src0 = src1; + src1 = src2; + src2 += srcPitch/2; + --count; + } + } + dst0 += dstPitch; + dst1 += dstPitch; + internal_scale2x_16_def(dst0, dst1, src0, src1, src1, width); #if defined(MMX) && (defined(X86_ASSEMBLY) || defined(X86_MSVC_ASSEMBLY)) - } + } #endif } void AdMame2x32(u8 *srcPtr, u32 srcPitch, /* u8 deltaPtr, */ - u8 *dstPtr, u32 dstPitch, int width, int height) + u8 *dstPtr, u32 dstPitch, int width, int height) { - u32 *dst0 = (u32 *)dstPtr; - u32 *dst1 = dst0 + (dstPitch/4); + u32 *dst0 = (u32 *)dstPtr; + u32 *dst1 = dst0 + (dstPitch/4); - u32 *src0 = (u32 *)srcPtr; - u32 *src1 = src0 + (srcPitch/4); - u32 *src2 = src1 + (srcPitch/4); + u32 *src0 = (u32 *)srcPtr; + u32 *src1 = src0 + (srcPitch/4); + u32 *src2 = src1 + (srcPitch/4); #if defined(MMX) && (defined(X86_ASSEMBLY) || defined(X86_MSVC_ASSEMBLY)) - if(cpu_mmx) { - internal_scale2x_32_mmx(dst0, dst1, src0, src0, src1, width); - - { - int count = height; - - count -= 2; - while(count) { - dst0 += dstPitch/2; - dst1 += dstPitch/2; - internal_scale2x_32_mmx(dst0, dst1, src0, src1, src2, width); - src0 = src1; - src1 = src2; - src2 += srcPitch/4; - --count; - } - } - dst0 += dstPitch/2; - dst1 += dstPitch/2; - internal_scale2x_32_mmx(dst0, dst1, src0, src1, src1, width); - } else { + if(cpu_mmx) { + internal_scale2x_32_mmx(dst0, dst1, src0, src0, src1, width); + + { + int count = height; + + count -= 2; + while(count) { + dst0 += dstPitch/2; + dst1 += dstPitch/2; + internal_scale2x_32_mmx(dst0, dst1, src0, src1, src2, width); + src0 = src1; + src1 = src2; + src2 += srcPitch/4; + --count; + } + } + dst0 += dstPitch/2; + dst1 += dstPitch/2; + internal_scale2x_32_mmx(dst0, dst1, src0, src1, src1, width); + } else { #endif - internal_scale2x_32_def(dst0, dst1, src0, src0, src1, width); - { - int count = height; - - count -= 2; - while(count) { - dst0 += dstPitch/2; - dst1 += dstPitch/2; - internal_scale2x_32_def(dst0, dst1, src0, src1, src2, width); - src0 = src1; - src1 = src2; - src2 += srcPitch/4; - --count; - } - } - dst0 += dstPitch/2; - dst1 += dstPitch/2; - internal_scale2x_32_def(dst0, dst1, src0, src1, src1, width); + internal_scale2x_32_def(dst0, dst1, src0, src0, src1, width); + { + int count = height; + + count -= 2; + while(count) { + dst0 += dstPitch/2; + dst1 += dstPitch/2; + internal_scale2x_32_def(dst0, dst1, src0, src1, src2, width); + src0 = src1; + src1 = src2; + src2 += srcPitch/4; + --count; + } + } + dst0 += dstPitch/2; + dst1 += dstPitch/2; + internal_scale2x_32_def(dst0, dst1, src0, src1, src1, width); #if defined(MMX) && (defined(X86_ASSEMBLY) || defined(X86_MSVC_ASSEMBLY)) - } + } #endif } @@ -1861,28 +1861,28 @@ void AdMame2x32(u8 *srcPtr, u32 srcPitch, /* u8 deltaPtr, */ void hq_init (int rb, int gb, int bb, int rs, int gs, int bs) { - int i, j, k, r, g, b, Y, u, v; - int rmask, gmask, bmask; - - rmask = ((1 << rb) - 1) << rs; - gmask = ((1 << gb) - 1) << gs; - bmask = ((1 << bb) - 1) << bs; - - for (i=0; i<65536; i++) - LUT16to32[i] = ((i & 0xF800) << 8) + ((i & 0x07E0) << 5) + ((i & 0x001F) << 3); - - for (i=0; i<32; i++) { - for (j=0; j<64; j++) { - for (k=0; k<32; k++) { - r = i << 3; - g = j << 2; - b = k << 3; - Y = (r + g + b) >> 2; - u = 128 + ((r - b) >> 2); - v = 128 + ((-r + 2*g -b)>>3); - RGBtoYUV[ (i << 11) + (j << 5) + k ] = (Y<<16) + (u<<8) + v; - } + int i, j, k, r, g, b, Y, u, v; + int rmask, gmask, bmask; + + rmask = ((1 << rb) - 1) << rs; + gmask = ((1 << gb) - 1) << gs; + bmask = ((1 << bb) - 1) << bs; + + for (i=0; i<65536; i++) + LUT16to32[i] = ((i & 0xF800) << 8) + ((i & 0x07E0) << 5) + ((i & 0x001F) << 3); + + for (i=0; i<32; i++) { + for (j=0; j<64; j++) { + for (k=0; k<32; k++) { + r = i << 3; + g = j << 2; + b = k << 3; + Y = (r + g + b) >> 2; + u = 128 + ((r - b) >> 2); + v = 128 + ((-r + 2*g -b)>>3); + RGBtoYUV[ (i << 11) + (j << 5) + k ] = (Y<<16) + (u<<8) + v; + } + } } - } } diff --git a/od-win32/scaler_more.c b/od-win32/scaler_more.c index 2e479da5..cc18d71e 100644 --- a/od-win32/scaler_more.c +++ b/od-win32/scaler_more.c @@ -23,24 +23,24 @@ uae_s32 tcrrgb[65536]; void PAL_init(void) { - int i; - for (i = 0; i < 4096; i++) - randomtable[i] = rand() | (rand() << 15); - predc = &redc[1 * 256]; - pgrec = &grec[1 * 256]; - pbluc = &bluc[1 * 256]; - - if (currprefs.gfx_resolution == 0) { - xx1 = 1; - xx2 = 2; - xx3 = 3; - } else { - xx1 = 2; - xx2 = 5; - xx3 = 7; - } - pal_noise_mask = (1 << (currprefs.gfx_filter_noise * 7 / 100)) - 1; - scanlinelevel = 128 - currprefs.gfx_filter_scanlines * 128 / 100; + int i; + for (i = 0; i < 4096; i++) + randomtable[i] = rand() | (rand() << 15); + predc = &redc[1 * 256]; + pgrec = &grec[1 * 256]; + pbluc = &bluc[1 * 256]; + + if (currprefs.gfx_resolution == 0) { + xx1 = 1; + xx2 = 2; + xx3 = 3; + } else { + xx1 = 2; + xx2 = 5; + xx3 = 7; + } + pal_noise_mask = (1 << (currprefs.gfx_filter_noise * 7 / 100)) - 1; + scanlinelevel = 128 - currprefs.gfx_filter_scanlines * 128 / 100; } #if 0 @@ -48,337 +48,337 @@ void PAL_init(void) #define sat 256 STATIC_INLINE int zyh(uae_u32 v) { - return ((v >> 24) & 0xff) * mm; + return ((v >> 24) & 0xff) * mm; } STATIC_INLINE int zyl(uae_u32 v) { - return ((v >> 16) & 0xff) * mm; + return ((v >> 16) & 0xff) * mm; } STATIC_INLINE int zcb(uae_u32 v) { - return ((int)((uae_s8)(v >> 8))) * sat; + return ((int)((uae_s8)(v >> 8))) * sat; } STATIC_INLINE int zcr(uae_u32 v) { - return ((int)((uae_s8)(v >> 0))) * sat; + return ((int)((uae_s8)(v >> 0))) * sat; } #endif STATIC_INLINE int zyhRGB(uae_u32 v) { - return tyhrgb[v]; + return tyhrgb[v]; } STATIC_INLINE int zylRGB(uae_u32 v) { - return tylrgb[v]; + return tylrgb[v]; } STATIC_INLINE int zcbRGB(uae_u32 v) { - return tcbrgb[v]; + return tcbrgb[v]; } STATIC_INLINE int zcrRGB(uae_u32 v) { - return tcrrgb[v]; + return tcrrgb[v]; } #if 0 void PAL_1x1_32(uae_u32 *src, int pitchs, uae_u32 *trg, int pitcht, int width, int height) { - const uae_u32 *tmpsrc; - uae_u32 *tmptrg; - uae_s32 *lineptr0; - uae_s32 *lineptr1; - uae_s32 *line; - uae_s32 *linepre; - unsigned int x, y, wstart, wfast, wend, wint; - int l, u, v; - int red, grn, blu; - int xt = 0; - int yt = 0; - int xs = 0; - int ys = 0; - - pitchs /= sizeof (*trg); - pitcht /= sizeof (*trg); - - src = src + pitchs * ys + xs - 2; - trg = trg + pitcht * yt + xt; - if (width < 8) { - wstart = width; - wfast = 0; - wend = 0; - } else { - /* alignment: 8 pixels*/ - wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); - wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ - wend = (width - wstart) & 0x07; /* do not forget the rest*/ - } - wint = width + 5; - lineptr0 = line_yuv_0; - lineptr1 = line_yuv_1; - - tmpsrc = src - pitchs; - line = lineptr0; - for (x = 0; x < wint; x++) { - uae_u32 cl0, cl1, cl2, cl3; - - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = 0; - line[1] = zcb(cl0) + zcb(cl1) + zcb(cl2) + zcb(cl3); - line[2] = zcr(cl0) + zcr(cl1) + zcr(cl2) + zcr(cl3); - tmpsrc++; - line += 3; - } - - for (y = 0; y < height; y++) { - int scn = (y & 1) ? scanlinelevel : 128; - randomshift = rand() & 15; - randomoffset = rand() & 2047; - - tmpsrc = src; - tmptrg = trg; - - line = lineptr0; - lineptr0 = lineptr1; - lineptr1 = line; + const uae_u32 *tmpsrc; + uae_u32 *tmptrg; + uae_s32 *lineptr0; + uae_s32 *lineptr1; + uae_s32 *line; + uae_s32 *linepre; + unsigned int x, y, wstart, wfast, wend, wint; + int l, u, v; + int red, grn, blu; + int xt = 0; + int yt = 0; + int xs = 0; + int ys = 0; + + pitchs /= sizeof (*trg); + pitcht /= sizeof (*trg); + + src = src + pitchs * ys + xs - 2; + trg = trg + pitcht * yt + xt; + if (width < 8) { + wstart = width; + wfast = 0; + wend = 0; + } else { + /* alignment: 8 pixels*/ + wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); + wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ + wend = (width - wstart) & 0x07; /* do not forget the rest*/ + } + wint = width + 5; + lineptr0 = line_yuv_0; + lineptr1 = line_yuv_1; - tmpsrc = src; + tmpsrc = src - pitchs; line = lineptr0; for (x = 0; x < wint; x++) { - int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; - uae_u32 cl0, cl1, cl2, cl3; - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = (zyl(cl1) + zyh(cl2) * (scn - r) / 128 + zyl(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ - line[1] = zcb(cl0) + zcb(cl1) + zcb(cl2) + zcb(cl3); - line[2] = zcr(cl0) + zcr(cl1) + zcr(cl2) + zcr(cl3); - tmpsrc++; - line += 3; + uae_u32 cl0, cl1, cl2, cl3; + + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = 0; + line[1] = zcb(cl0) + zcb(cl1) + zcb(cl2) + zcb(cl3); + line[2] = zcr(cl0) + zcr(cl1) + zcr(cl2) + zcr(cl3); + tmpsrc++; + line += 3; } - line = lineptr0; - linepre = lineptr1; - for (x = 0; x < (wfast << 3) + wend + wstart; x++) { - - l = line[0]; - u = (line[1] + linepre[1]) / 8; - v = (line[2] + linepre[2]) / 8; - line += 3; - linepre += 3; - - red = (v + l) / 256; - blu = (u + l) / 256; - grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); - *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + for (y = 0; y < height; y++) { + int scn = (y & 1) ? scanlinelevel : 128; + randomshift = rand() & 15; + randomoffset = rand() & 2047; + + tmpsrc = src; + tmptrg = trg; + + line = lineptr0; + lineptr0 = lineptr1; + lineptr1 = line; + + tmpsrc = src; + line = lineptr0; + for (x = 0; x < wint; x++) { + int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; + uae_u32 cl0, cl1, cl2, cl3; + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = (zyl(cl1) + zyh(cl2) * (scn - r) / 128 + zyl(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ + line[1] = zcb(cl0) + zcb(cl1) + zcb(cl2) + zcb(cl3); + line[2] = zcr(cl0) + zcr(cl1) + zcr(cl2) + zcr(cl3); + tmpsrc++; + line += 3; + } + + line = lineptr0; + linepre = lineptr1; + for (x = 0; x < (wfast << 3) + wend + wstart; x++) { + + l = line[0]; + u = (line[1] + linepre[1]) / 8; + v = (line[2] + linepre[2]) / 8; + line += 3; + linepre += 3; + + red = (v + l) / 256; + blu = (u + l) / 256; + grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); + *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + } + + src += pitchs; + trg += pitcht; } - - src += pitchs; - trg += pitcht; - } } #endif void PAL_1x1_32(uae_u32 *src, int pitchs, uae_u32 *trg, int pitcht, int width, int height) { - const uae_u32 *tmpsrc; - uae_u32 *tmptrg; - uae_s32 *lineptr0; - uae_s32 *lineptr1; - uae_s32 *line; - uae_s32 *linepre; - unsigned int x, y, wstart, wfast, wend, wint; - int l, u, v; - int red, grn, blu; - int xt = 0; - int yt = 0; - int xs = 0; - int ys = 0; - - pitchs /= sizeof (*trg); - pitcht /= sizeof (*trg); - - src = src + pitchs * ys + xs - 2; - trg = trg + pitcht * yt + xt; - if (width < 8) { - wstart = width; - wfast = 0; - wend = 0; - } else { - /* alignment: 8 pixels*/ - wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); - wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ - wend = (width - wstart) & 0x07; /* do not forget the rest*/ - } - wint = width + 5; - lineptr0 = line_yuv_0; - lineptr1 = line_yuv_1; - - tmpsrc = src - pitchs; - line = lineptr0; - for (x = 0; x < wint; x++) { - uae_u32 cl0, cl1, cl2, cl3; - - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = 0; - line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); - line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); - tmpsrc++; - line += 3; - } - - for (y = 0; y < height; y++) { - int scn = (y & 1) ? scanlinelevel : 128; - randomshift = rand() & 15; - randomoffset = rand() & 2047; - - tmpsrc = src; - tmptrg = trg; - - line = lineptr0; - lineptr0 = lineptr1; - lineptr1 = line; + const uae_u32 *tmpsrc; + uae_u32 *tmptrg; + uae_s32 *lineptr0; + uae_s32 *lineptr1; + uae_s32 *line; + uae_s32 *linepre; + unsigned int x, y, wstart, wfast, wend, wint; + int l, u, v; + int red, grn, blu; + int xt = 0; + int yt = 0; + int xs = 0; + int ys = 0; + + pitchs /= sizeof (*trg); + pitcht /= sizeof (*trg); + + src = src + pitchs * ys + xs - 2; + trg = trg + pitcht * yt + xt; + if (width < 8) { + wstart = width; + wfast = 0; + wend = 0; + } else { + /* alignment: 8 pixels*/ + wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); + wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ + wend = (width - wstart) & 0x07; /* do not forget the rest*/ + } + wint = width + 5; + lineptr0 = line_yuv_0; + lineptr1 = line_yuv_1; - tmpsrc = src; + tmpsrc = src - pitchs; line = lineptr0; for (x = 0; x < wint; x++) { - int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; - uae_u32 cl0, cl1, cl2, cl3; - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = (zylRGB(cl1) + zyhRGB(cl2) * (scn - r) / 128 + zylRGB(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ - line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); - line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); - tmpsrc++; - line += 3; + uae_u32 cl0, cl1, cl2, cl3; + + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = 0; + line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); + line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); + tmpsrc++; + line += 3; } - line = lineptr0; - linepre = lineptr1; - for (x = 0; x < (wfast << 3) + wend + wstart; x++) { - - l = line[0]; - u = (line[1] + linepre[1]) / 8; - v = (line[2] + linepre[2]) / 8; - line += 3; - linepre += 3; - - red = (v + l) / 256; - blu = (u + l) / 256; - grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); - *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + for (y = 0; y < height; y++) { + int scn = (y & 1) ? scanlinelevel : 128; + randomshift = rand() & 15; + randomoffset = rand() & 2047; + + tmpsrc = src; + tmptrg = trg; + + line = lineptr0; + lineptr0 = lineptr1; + lineptr1 = line; + + tmpsrc = src; + line = lineptr0; + for (x = 0; x < wint; x++) { + int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; + uae_u32 cl0, cl1, cl2, cl3; + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = (zylRGB(cl1) + zyhRGB(cl2) * (scn - r) / 128 + zylRGB(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ + line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); + line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); + tmpsrc++; + line += 3; + } + + line = lineptr0; + linepre = lineptr1; + for (x = 0; x < (wfast << 3) + wend + wstart; x++) { + + l = line[0]; + u = (line[1] + linepre[1]) / 8; + v = (line[2] + linepre[2]) / 8; + line += 3; + linepre += 3; + + red = (v + l) / 256; + blu = (u + l) / 256; + grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); + *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + } + + src += pitchs; + trg += pitcht; } - - src += pitchs; - trg += pitcht; - } } void PAL_1x1_16(uae_u16 *src, int pitchs, uae_u16 *trg, int pitcht, int width, int height) { - const uae_u16 *tmpsrc; - uae_u16 *tmptrg; - uae_s32 *lineptr0; - uae_s32 *lineptr1; - uae_s32 *line; - uae_s32 *linepre; - unsigned int x, y, wstart, wfast, wend, wint; - int l, u, v; - int red, grn, blu; - int xt = 0; - int yt = 0; - int xs = 0; - int ys = 0; - - pitchs /= sizeof (*trg); - pitcht /= sizeof (*trg); - - src = src + pitchs * ys + xs - 2; - trg = trg + pitcht * yt + xt; - if (width < 8) { - wstart = width; - wfast = 0; - wend = 0; - } else { - /* alignment: 8 pixels*/ - wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); - wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ - wend = (width - wstart) & 0x07; /* do not forget the rest*/ - } - wint = width + 5; - lineptr0 = line_yuv_0; - lineptr1 = line_yuv_1; - - tmpsrc = src - pitchs; - line = lineptr0; - for (x = 0; x < wint; x++) { - uae_u32 cl0, cl1, cl2, cl3; - - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = 0; - line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); - line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); - tmpsrc++; - line += 3; - } - - for (y = 0; y < height; y++) { - int scn = (y & 1) ? scanlinelevel : 128; - randomshift = rand() & 15; - randomoffset = rand() & 2047; - - tmpsrc = src; - tmptrg = trg; - - line = lineptr0; - lineptr0 = lineptr1; - lineptr1 = line; + const uae_u16 *tmpsrc; + uae_u16 *tmptrg; + uae_s32 *lineptr0; + uae_s32 *lineptr1; + uae_s32 *line; + uae_s32 *linepre; + unsigned int x, y, wstart, wfast, wend, wint; + int l, u, v; + int red, grn, blu; + int xt = 0; + int yt = 0; + int xs = 0; + int ys = 0; + + pitchs /= sizeof (*trg); + pitcht /= sizeof (*trg); + + src = src + pitchs * ys + xs - 2; + trg = trg + pitcht * yt + xt; + if (width < 8) { + wstart = width; + wfast = 0; + wend = 0; + } else { + /* alignment: 8 pixels*/ + wstart = (unsigned int)(8 - ((unsigned long)trg & 7)); + wfast = (width - wstart) >> 3; /* fast loop for 8 pixel segments*/ + wend = (width - wstart) & 0x07; /* do not forget the rest*/ + } + wint = width + 5; + lineptr0 = line_yuv_0; + lineptr1 = line_yuv_1; - tmpsrc = src; + tmpsrc = src - pitchs; line = lineptr0; for (x = 0; x < wint; x++) { - int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; - uae_u32 cl0, cl1, cl2, cl3; - cl0 = tmpsrc[0]; - cl1 = tmpsrc[xx1]; - cl2 = tmpsrc[xx2]; - cl3 = tmpsrc[xx3]; - line[0] = (zylRGB(cl1) + zyhRGB(cl2) * (scn - r) / 128 + zylRGB(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ - line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); - line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); - tmpsrc++; - line += 3; + uae_u32 cl0, cl1, cl2, cl3; + + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = 0; + line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); + line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); + tmpsrc++; + line += 3; } - line = lineptr0; - linepre = lineptr1; - for (x = 0; x < (wfast << 3) + wend + wstart; x++) { - - l = line[0]; - u = (line[1] + linepre[1]) / 8; - v = (line[2] + linepre[2]) / 8; - line += 3; - linepre += 3; - - red = (v + l) / 256; - blu = (u + l) / 256; - grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); - *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + for (y = 0; y < height; y++) { + int scn = (y & 1) ? scanlinelevel : 128; + randomshift = rand() & 15; + randomoffset = rand() & 2047; + + tmpsrc = src; + tmptrg = trg; + + line = lineptr0; + lineptr0 = lineptr1; + lineptr1 = line; + + tmpsrc = src; + line = lineptr0; + for (x = 0; x < wint; x++) { + int r = (randomtable[randomoffset++] >> randomshift) & pal_noise_mask; + uae_u32 cl0, cl1, cl2, cl3; + cl0 = tmpsrc[0]; + cl1 = tmpsrc[xx1]; + cl2 = tmpsrc[xx2]; + cl3 = tmpsrc[xx3]; + line[0] = (zylRGB(cl1) + zyhRGB(cl2) * (scn - r) / 128 + zylRGB(cl3)) / 256; /* 1/4 + 1/2 + 1/4 */ + line[1] = zcbRGB(cl0) + zcbRGB(cl1) + zcbRGB(cl2) + zcbRGB(cl3); + line[2] = zcrRGB(cl0) + zcrRGB(cl1) + zcrRGB(cl2) + zcrRGB(cl3); + tmpsrc++; + line += 3; + } + + line = lineptr0; + linepre = lineptr1; + for (x = 0; x < (wfast << 3) + wend + wstart; x++) { + + l = line[0]; + u = (line[1] + linepre[1]) / 8; + v = (line[2] + linepre[2]) / 8; + line += 3; + linepre += 3; + + red = (v + l) / 256; + blu = (u + l) / 256; + grn = (l * 256 - 50 * u - 130 * v) / (256 * 256); + *tmptrg++ = predc[red] | pgrec[grn] | pbluc[blu]; + } + + src += pitchs; + trg += pitcht; } - - src += pitchs; - trg += pitcht; - } } diff --git a/od-win32/screenshot.c b/od-win32/screenshot.c index 13715a9c..38703ee1 100644 --- a/od-win32/screenshot.c +++ b/od-win32/screenshot.c @@ -22,46 +22,46 @@ int screenshotmode = PNG_SCREENSHOTS; static void namesplit (TCHAR *s) { - int l; - - l = _tcslen (s) - 1; - while (l >= 0) { - if (s[l] == '.') - s[l] = 0; - if (s[l] == '\\' || s[l] == '/' || s[l] == ':' || s[l] == '?') { - l++; - break; + int l; + + l = _tcslen (s) - 1; + while (l >= 0) { + if (s[l] == '.') + s[l] = 0; + if (s[l] == '\\' || s[l] == '/' || s[l] == ':' || s[l] == '?') { + l++; + break; + } + l--; } - l--; - } - if (l > 0) - memmove (s, s + l, (_tcslen (s + l) + 1) * sizeof (TCHAR)); + if (l > 0) + memmove (s, s + l, (_tcslen (s + l) + 1) * sizeof (TCHAR)); } static int toclipboard (BITMAPINFO *bi, void *bmp) { - int v = 0; - uae_u8 *dib = 0; - HANDLE hg; - - if (!OpenClipboard (hMainWnd)) - return v; - EmptyClipboard (); - hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bi->bmiHeader.biSize + bi->bmiHeader.biSizeImage); - if (hg) { - dib = GlobalLock (hg); - if (dib) { - memcpy (dib, &bi->bmiHeader, bi->bmiHeader.biSize); - memcpy (dib + bi->bmiHeader.biSize, bmp, bi->bmiHeader.biSizeImage); + int v = 0; + uae_u8 *dib = 0; + HANDLE hg; + + if (!OpenClipboard (hMainWnd)) + return v; + EmptyClipboard (); + hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bi->bmiHeader.biSize + bi->bmiHeader.biSizeImage); + if (hg) { + dib = GlobalLock (hg); + if (dib) { + memcpy (dib, &bi->bmiHeader, bi->bmiHeader.biSize); + memcpy (dib + bi->bmiHeader.biSize, bmp, bi->bmiHeader.biSizeImage); + } + GlobalUnlock (hg); + if (SetClipboardData (CF_DIB, hg)) + v = 1; } - GlobalUnlock (hg); - if (SetClipboardData (CF_DIB, hg)) - v = 1; - } - CloseClipboard (); - if (!v) - GlobalFree (hg); - return v; + CloseClipboard (); + if (!v) + GlobalFree (hg); + return v; } static HDC surface_dc, offscreen_dc; @@ -72,150 +72,150 @@ static int screenshot_prepared; void screenshot_free (void) { - if (surface_dc) - releasehdc (surface_dc); - surface_dc = NULL; - if(offscreen_dc) - DeleteDC(offscreen_dc); - offscreen_dc = NULL; - if(offscreen_bitmap) - DeleteObject(offscreen_bitmap); - offscreen_bitmap = NULL; - if(lpvBits) - free(lpvBits); - lpvBits = NULL; - screenshot_prepared = FALSE; + if (surface_dc) + releasehdc (surface_dc); + surface_dc = NULL; + if(offscreen_dc) + DeleteDC(offscreen_dc); + offscreen_dc = NULL; + if(offscreen_bitmap) + DeleteObject(offscreen_bitmap); + offscreen_bitmap = NULL; + if(lpvBits) + free(lpvBits); + lpvBits = NULL; + screenshot_prepared = FALSE; } int screenshot_prepare (void) { - unsigned int width, height; - HGDIOBJ hgdiobj; - - screenshot_free (); - - width = WIN32GFX_GetWidth (); - height = WIN32GFX_GetHeight (); - - surface_dc = gethdc (); - if (surface_dc == NULL) - goto oops; - - // need a HBITMAP to convert it to a DIB - if ((offscreen_bitmap = CreateCompatibleBitmap (surface_dc, width, height)) == NULL) - goto oops; // error - - // The bitmap is empty, so let's copy the contents of the surface to it. - // For that we need to select it into a device context. - if ((offscreen_dc = CreateCompatibleDC (surface_dc)) == NULL) - goto oops; // error - - // select offscreen_bitmap into offscreen_dc - hgdiobj = SelectObject (offscreen_dc, offscreen_bitmap); - - // now we can copy the contents of the surface to the offscreen bitmap - BitBlt (offscreen_dc, 0, 0, width, height, surface_dc, 0, 0, SRCCOPY); - - // de-select offscreen_bitmap - SelectObject (offscreen_dc, hgdiobj); - - ZeroMemory (&bi, sizeof(bi)); - bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); - bi.bmiHeader.biWidth = width; - bi.bmiHeader.biHeight = height; - bi.bmiHeader.biPlanes = 1; - bi.bmiHeader.biBitCount = 24; - bi.bmiHeader.biCompression = BI_RGB; - bi.bmiHeader.biSizeImage = (((bi.bmiHeader.biWidth * bi.bmiHeader.biBitCount + 31) & ~31) / 8) * bi.bmiHeader.biHeight; - bi.bmiHeader.biXPelsPerMeter = 0; - bi.bmiHeader.biYPelsPerMeter = 0; - bi.bmiHeader.biClrUsed = 0; - bi.bmiHeader.biClrImportant = 0; - - // Reserve memory for bitmap bits - if (!(lpvBits = xmalloc (bi.bmiHeader.biSizeImage))) - goto oops; // out of memory - - // Have GetDIBits convert offscreen_bitmap to a DIB (device-independent bitmap): - if (!GetDIBits (offscreen_dc, offscreen_bitmap, 0, bi.bmiHeader.biHeight, lpvBits, &bi, DIB_RGB_COLORS)) - goto oops; // GetDIBits FAILED - - releasehdc (surface_dc); - surface_dc = NULL; - screenshot_prepared = TRUE; - return 1; + unsigned int width, height; + HGDIOBJ hgdiobj; + + screenshot_free (); + + width = WIN32GFX_GetWidth (); + height = WIN32GFX_GetHeight (); + + surface_dc = gethdc (); + if (surface_dc == NULL) + goto oops; + + // need a HBITMAP to convert it to a DIB + if ((offscreen_bitmap = CreateCompatibleBitmap (surface_dc, width, height)) == NULL) + goto oops; // error + + // The bitmap is empty, so let's copy the contents of the surface to it. + // For that we need to select it into a device context. + if ((offscreen_dc = CreateCompatibleDC (surface_dc)) == NULL) + goto oops; // error + + // select offscreen_bitmap into offscreen_dc + hgdiobj = SelectObject (offscreen_dc, offscreen_bitmap); + + // now we can copy the contents of the surface to the offscreen bitmap + BitBlt (offscreen_dc, 0, 0, width, height, surface_dc, 0, 0, SRCCOPY); + + // de-select offscreen_bitmap + SelectObject (offscreen_dc, hgdiobj); + + ZeroMemory (&bi, sizeof(bi)); + bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); + bi.bmiHeader.biWidth = width; + bi.bmiHeader.biHeight = height; + bi.bmiHeader.biPlanes = 1; + bi.bmiHeader.biBitCount = 24; + bi.bmiHeader.biCompression = BI_RGB; + bi.bmiHeader.biSizeImage = (((bi.bmiHeader.biWidth * bi.bmiHeader.biBitCount + 31) & ~31) / 8) * bi.bmiHeader.biHeight; + bi.bmiHeader.biXPelsPerMeter = 0; + bi.bmiHeader.biYPelsPerMeter = 0; + bi.bmiHeader.biClrUsed = 0; + bi.bmiHeader.biClrImportant = 0; + + // Reserve memory for bitmap bits + if (!(lpvBits = xmalloc (bi.bmiHeader.biSizeImage))) + goto oops; // out of memory + + // Have GetDIBits convert offscreen_bitmap to a DIB (device-independent bitmap): + if (!GetDIBits (offscreen_dc, offscreen_bitmap, 0, bi.bmiHeader.biHeight, lpvBits, &bi, DIB_RGB_COLORS)) + goto oops; // GetDIBits FAILED + + releasehdc (surface_dc); + surface_dc = NULL; + screenshot_prepared = TRUE; + return 1; oops: - screenshot_free(); - return 0; + screenshot_free(); + return 0; } #if PNG_SCREENSHOTS > 0 static void _cdecl pngtest_blah (png_structp png_ptr, png_const_charp message) { - TCHAR *name = L"unknown"; - if (png_ptr != NULL && png_ptr->error_ptr != NULL) - name = png_ptr->error_ptr; - write_log (L"%s: libpng warning: %s\n", name, message); + TCHAR *name = L"unknown"; + if (png_ptr != NULL && png_ptr->error_ptr != NULL) + name = png_ptr->error_ptr; + write_log (L"%s: libpng warning: %s\n", name, message); } static int savepng (FILE *fp) { - png_structp png_ptr; - png_infop info_ptr; - png_bytep *row_pointers; - int h = bi.bmiHeader.biHeight; - int w = bi.bmiHeader.biWidth; - int i; - - png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, pngtest_blah, pngtest_blah, pngtest_blah); - if (!png_ptr) - return 0; - info_ptr = png_create_info_struct (png_ptr); - if (!info_ptr) { - png_destroy_write_struct (&png_ptr, NULL); - return 0; - } - if (setjmp(png_jmpbuf (png_ptr))) { - png_destroy_write_struct (&png_ptr, &info_ptr); - return 0; - } - - png_init_io (png_ptr, fp); - png_set_filter (png_ptr, 0, PNG_FILTER_NONE); - png_set_IHDR (png_ptr, info_ptr, - w, h, 8, PNG_COLOR_TYPE_RGB, - PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - row_pointers = xmalloc (h * sizeof (png_bytep*)); - for (i = 0; i < h; i++) { - int j = h - i - 1; - row_pointers[i] = (uae_u8*)lpvBits + j * (((w * 24 + 31) & ~31) / 8); - } - png_set_rows (png_ptr, info_ptr, row_pointers); - png_write_png (png_ptr,info_ptr, PNG_TRANSFORM_BGR, NULL); - png_destroy_write_struct (&png_ptr, &info_ptr); - return 1; + png_structp png_ptr; + png_infop info_ptr; + png_bytep *row_pointers; + int h = bi.bmiHeader.biHeight; + int w = bi.bmiHeader.biWidth; + int i; + + png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, pngtest_blah, pngtest_blah, pngtest_blah); + if (!png_ptr) + return 0; + info_ptr = png_create_info_struct (png_ptr); + if (!info_ptr) { + png_destroy_write_struct (&png_ptr, NULL); + return 0; + } + if (setjmp(png_jmpbuf (png_ptr))) { + png_destroy_write_struct (&png_ptr, &info_ptr); + return 0; + } + + png_init_io (png_ptr, fp); + png_set_filter (png_ptr, 0, PNG_FILTER_NONE); + png_set_IHDR (png_ptr, info_ptr, + w, h, 8, PNG_COLOR_TYPE_RGB, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + row_pointers = xmalloc (h * sizeof (png_bytep*)); + for (i = 0; i < h; i++) { + int j = h - i - 1; + row_pointers[i] = (uae_u8*)lpvBits + j * (((w * 24 + 31) & ~31) / 8); + } + png_set_rows (png_ptr, info_ptr, row_pointers); + png_write_png (png_ptr,info_ptr, PNG_TRANSFORM_BGR, NULL); + png_destroy_write_struct (&png_ptr, &info_ptr); + return 1; } #endif static int savebmp(FILE *fp) { - BITMAPFILEHEADER bfh; - // write the file header, bitmap information and pixel data - bfh.bfType = 19778; - bfh.bfSize = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER) + bi.bmiHeader.biSizeImage; - bfh.bfReserved1 = 0; - bfh.bfReserved2 = 0; - bfh.bfOffBits = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER); - if (fwrite (&bfh, 1, sizeof (BITMAPFILEHEADER), fp) < sizeof (BITMAPFILEHEADER)) - return 0; // failed to write bitmap file header - if (fwrite (&bi, 1, sizeof (BITMAPINFOHEADER), fp) < sizeof (BITMAPINFOHEADER)) - return 0; // failed to write bitmap infomation header - if (fwrite (lpvBits, 1, bi.bmiHeader.biSizeImage, fp) < bi.bmiHeader.biSizeImage) - return 0; // failed to write the bitmap - return 1; + BITMAPFILEHEADER bfh; + // write the file header, bitmap information and pixel data + bfh.bfType = 19778; + bfh.bfSize = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER) + bi.bmiHeader.biSizeImage; + bfh.bfReserved1 = 0; + bfh.bfReserved2 = 0; + bfh.bfOffBits = sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER); + if (fwrite (&bfh, 1, sizeof (BITMAPFILEHEADER), fp) < sizeof (BITMAPFILEHEADER)) + return 0; // failed to write bitmap file header + if (fwrite (&bi, 1, sizeof (BITMAPINFOHEADER), fp) < sizeof (BITMAPINFOHEADER)) + return 0; // failed to write bitmap infomation header + if (fwrite (lpvBits, 1, bi.bmiHeader.biSizeImage, fp) < bi.bmiHeader.biSizeImage) + return 0; // failed to write the bitmap + return 1; } /* @@ -223,95 +223,95 @@ Captures the Amiga display (DirectDraw, D3D or OpenGL) surface and saves it to f */ int screenshotf (const TCHAR *spath, int mode, int doprepare) { - static int recursive; - FILE *fp = NULL; - int allok = 0; + static int recursive; + FILE *fp = NULL; + int allok = 0; - HBITMAP offscreen_bitmap = NULL; // bitmap that is converted to a DIB - HDC offscreen_dc = NULL; // offscreen DC that we can select offscreen bitmap into + HBITMAP offscreen_bitmap = NULL; // bitmap that is converted to a DIB + HDC offscreen_dc = NULL; // offscreen DC that we can select offscreen bitmap into - if(recursive) - return 0; + if(recursive) + return 0; + + recursive++; - recursive++; - - if (!screenshot_prepared || doprepare) { - if (!screenshot_prepare ()) - goto oops; - } - - if (mode == 0) { - toclipboard (&bi, lpvBits); - } else { - TCHAR filename[MAX_DPATH]; - TCHAR path[MAX_DPATH]; - TCHAR name[MAX_DPATH]; - TCHAR underline[] = L"_"; - int number = 0; - - if (spath) { - fp = _tfopen (spath, L"wb"); - if (fp) { + if (!screenshot_prepared || doprepare) { + if (!screenshot_prepare ()) + goto oops; + } + + if (mode == 0) { + toclipboard (&bi, lpvBits); + } else { + TCHAR filename[MAX_DPATH]; + TCHAR path[MAX_DPATH]; + TCHAR name[MAX_DPATH]; + TCHAR underline[] = L"_"; + int number = 0; + + if (spath) { + fp = _tfopen (spath, L"wb"); + if (fp) { #if PNG_SCREENSHOTS > 0 - if (screenshotmode) - allok = savepng (fp); - else + if (screenshotmode) + allok = savepng (fp); + else #endif - allok = savebmp (fp); - fclose (fp); - fp = NULL; - goto oops; - } - } - fetch_path (L"ScreenshotPath", path, sizeof (path) / sizeof (TCHAR)); - CreateDirectory (path, NULL); - name[0] = 0; - if (currprefs.dfxtype[0] >= 0) - _tcscpy (name, currprefs.df[0]); - if (!name[0]) - underline[0] = 0; - namesplit (name); - - while(++number < 1000) // limit 999 iterations / screenshots - { - _stprintf (filename, L"%s%s%s%03d.%s", path, name, underline, number, screenshotmode ? L"png" : L"bmp"); - if ((fp = _tfopen (filename, L"rb")) == NULL) // does file not exist? - { - int ok = 0; - if ((fp = _tfopen (filename, L"wb")) == NULL) - goto oops; // error + allok = savebmp (fp); + fclose (fp); + fp = NULL; + goto oops; + } + } + fetch_path (L"ScreenshotPath", path, sizeof (path) / sizeof (TCHAR)); + CreateDirectory (path, NULL); + name[0] = 0; + if (currprefs.dfxtype[0] >= 0) + _tcscpy (name, currprefs.df[0]); + if (!name[0]) + underline[0] = 0; + namesplit (name); + + while(++number < 1000) // limit 999 iterations / screenshots + { + _stprintf (filename, L"%s%s%s%03d.%s", path, name, underline, number, screenshotmode ? L"png" : L"bmp"); + if ((fp = _tfopen (filename, L"rb")) == NULL) // does file not exist? + { + int ok = 0; + if ((fp = _tfopen (filename, L"wb")) == NULL) + goto oops; // error #if PNG_SCREENSHOTS > 0 - if (screenshotmode) - ok = savepng (fp); - else + if (screenshotmode) + ok = savepng (fp); + else #endif - ok = savebmp (fp); - fclose(fp); - fp = NULL; - if (!ok) - goto oops; - write_log (L"Screenshot saved as \"%s\"\n", filename); - allok = 1; - break; - } - fclose (fp); - fp = NULL; + ok = savebmp (fp); + fclose(fp); + fp = NULL; + if (!ok) + goto oops; + write_log (L"Screenshot saved as \"%s\"\n", filename); + allok = 1; + break; + } + fclose (fp); + fp = NULL; + } } - } oops: - if(fp) - fclose (fp); + if(fp) + fclose (fp); - if (doprepare) - screenshot_free(); + if (doprepare) + screenshot_free(); - recursive--; + recursive--; - return allok; + return allok; } void screenshot (int mode, int doprepare) { - screenshotf (NULL, mode, doprepare); + screenshotf (NULL, mode, doprepare); } diff --git a/od-win32/serial_win32.c b/od-win32/serial_win32.c index 818c1830..f2d9820e 100644 --- a/od-win32/serial_win32.c +++ b/od-win32/serial_win32.c @@ -1,12 +1,12 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Serial Line Emulation - * - * (c) 1996, 1997 Stefan Reinauer - * (c) 1997 Christian Schmitt - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Serial Line Emulation +* +* (c) 1996, 1997 Stefan Reinauer +* (c) 1997 Christian Schmitt +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -43,254 +43,254 @@ void serial_close(void); uae_u16 serper, serdat, serdatr; static int allowed_baudrates[] = - { 0, 110, 300, 600, 1200, 2400, 4800, 9600, 14400, - 19200, 31400, 38400, 57600, 115200, 128000, 256000, -1 }; +{ 0, 110, 300, 600, 1200, 2400, 4800, 9600, 14400, +19200, 31400, 38400, 57600, 115200, 128000, 256000, -1 }; void SERPER (uae_u16 w) { - int baud = 0, i, per; - static int warned; + int baud = 0, i, per; + static int warned; - if (serper == w) /* don't set baudrate if it's already ok */ - return; + if (serper == w) /* don't set baudrate if it's already ok */ + return; + + ninebit = 0; + serper = w; + if (w & 0x8000) + ninebit = 1; + w &= 0x7fff; + + if (w < 13) + w = 13; + + per = w; + if (per == 0) + per = 1; + per = 3546895 / (per + 1); + if (per <= 0) + per = 1; + i = 0; + while (allowed_baudrates[i] >= 0 && per > allowed_baudrates[i] * 100 / 97) + i++; + baud = allowed_baudrates[i]; + + serial_period_hsyncs = (((serper & 0x7fff) + 1) * 10) / maxhpos; + if (serial_period_hsyncs <= 0) + serial_period_hsyncs = 1; + serial_period_hsync_counter = 0; + + write_log (L"SERIAL: period=%d, baud=%d, hsyncs=%d, bits=%d, PC=%x\n", w, baud, serial_period_hsyncs, ninebit ? 9 : 8, M68K_GETPC); - ninebit = 0; - serper = w; - if (w & 0x8000) - ninebit = 1; - w &= 0x7fff; - - if (w < 13) - w = 13; - - per = w; - if (per == 0) - per = 1; - per = 3546895 / (per + 1); - if (per <= 0) - per = 1; - i = 0; - while (allowed_baudrates[i] >= 0 && per > allowed_baudrates[i] * 100 / 97) - i++; - baud = allowed_baudrates[i]; - - serial_period_hsyncs = (((serper & 0x7fff) + 1) * 10) / maxhpos; - if (serial_period_hsyncs <= 0) - serial_period_hsyncs = 1; - serial_period_hsync_counter = 0; - - write_log (L"SERIAL: period=%d, baud=%d, hsyncs=%d, bits=%d, PC=%x\n", w, baud, serial_period_hsyncs, ninebit ? 9 : 8, M68K_GETPC); - - if (ninebit) - baud *= 2; - if (currprefs.serial_direct) { - if (baud != 31400 && baud < 115200) - baud = 115200; - serial_period_hsyncs = 1; - } + if (ninebit) + baud *= 2; + if (currprefs.serial_direct) { + if (baud != 31400 && baud < 115200) + baud = 115200; + serial_period_hsyncs = 1; + } #ifdef SERIAL_PORT - setbaud (baud); + setbaud (baud); #endif } static uae_char dochar (int v) { - v &= 0xff; - if (v >= 32 && v < 127) return (char)v; - return '.'; + v &= 0xff; + if (v >= 32 && v < 127) return (char)v; + return '.'; } static void checkreceive (int mode) { #ifdef SERIAL_PORT - static uae_u32 lastchartime; - static int ninebitdata; - struct timeval tv; - int recdata; + static uae_u32 lastchartime; + static int ninebitdata; + struct timeval tv; + int recdata; - if (!readseravail()) - return; + if (!readseravail()) + return; - if (data_in_serdatr) { - /* probably not needed but there may be programs that expect OVRUNs.. */ - gettimeofday (&tv, NULL); - if (tv.tv_sec > lastchartime) { - ovrun = 1; - INTREQ (0x8000 | 0x0800); - while (readser (&recdata)); - write_log (L"SERIAL: overrun\n"); + if (data_in_serdatr) { + /* probably not needed but there may be programs that expect OVRUNs.. */ + gettimeofday (&tv, NULL); + if (tv.tv_sec > lastchartime) { + ovrun = 1; + INTREQ (0x8000 | 0x0800); + while (readser (&recdata)); + write_log (L"SERIAL: overrun\n"); + } + return; } - return; - } - if (ninebit) { - for (;;) { - if (!readser (&recdata)) - return; - if (ninebitdata) { - serdatr = (ninebitdata & 1) << 8; - serdatr |= recdata; - serdatr |= 0x200; - ninebitdata = 0; - break; - } else { - ninebitdata = recdata; - if ((ninebitdata & ~1) != 0xa8) { - write_log (L"SERIAL: 9-bit serial emulation sync lost, %02X != %02X\n", ninebitdata & ~1, 0xa8); - ninebitdata = 0; - return; + if (ninebit) { + for (;;) { + if (!readser (&recdata)) + return; + if (ninebitdata) { + serdatr = (ninebitdata & 1) << 8; + serdatr |= recdata; + serdatr |= 0x200; + ninebitdata = 0; + break; + } else { + ninebitdata = recdata; + if ((ninebitdata & ~1) != 0xa8) { + write_log (L"SERIAL: 9-bit serial emulation sync lost, %02X != %02X\n", ninebitdata & ~1, 0xa8); + ninebitdata = 0; + return; + } + continue; + } } - continue; - } + } else { + if (!readser (&recdata)) + return; + serdatr = recdata; + serdatr |= 0x100; } - } else { - if (!readser (&recdata)) - return; - serdatr = recdata; - serdatr |= 0x100; - } - gettimeofday (&tv, NULL); - lastchartime = tv.tv_sec + 5; - data_in_serdatr = 1; - serial_check_irq (); + gettimeofday (&tv, NULL); + lastchartime = tv.tv_sec + 5; + data_in_serdatr = 1; + serial_check_irq (); #if SERIALDEBUG > 2 - write_log (L"SERIAL: received %02X (%c)\n", serdatr & 0xff, doTCHAR (serdatr)); + write_log (L"SERIAL: received %02X (%c)\n", serdatr & 0xff, doTCHAR (serdatr)); #endif #endif } static void checksend (int mode) { - int bufstate = 0; + int bufstate = 0; #ifdef SERIAL_PORT - bufstate = checkserwrite (); + bufstate = checkserwrite (); #endif - if (!data_in_serdat && !data_in_sershift) - return; + if (!data_in_serdat && !data_in_sershift) + return; - if (data_in_sershift && mode == 0 && bufstate) - data_in_sershift = 0; + if (data_in_sershift && mode == 0 && bufstate) + data_in_sershift = 0; - if (data_in_serdat && !data_in_sershift) { - data_in_sershift = 1; - serdatshift = serdat; + if (data_in_serdat && !data_in_sershift) { + data_in_sershift = 1; + serdatshift = serdat; #ifdef SERIAL_PORT - if (ninebit) - writeser (((serdatshift >> 8) & 1) | 0xa8); - writeser (serdatshift); + if (ninebit) + writeser (((serdatshift >> 8) & 1) | 0xa8); + writeser (serdatshift); #endif - data_in_serdat = 0; - INTREQ (0x8000 | 0x0001); + data_in_serdat = 0; + INTREQ (0x8000 | 0x0001); #if SERIALDEBUG > 2 - write_log (L"SERIAL: send %04X (%c)\n", serdatshift, doTCHAR (serdatshift)); + write_log (L"SERIAL: send %04X (%c)\n", serdatshift, doTCHAR (serdatshift)); #endif - } + } } void serial_hsynchandler (void) { #ifdef AHI - extern void hsyncstuff(void); - hsyncstuff(); + extern void hsyncstuff(void); + hsyncstuff(); #endif - if (serial_period_hsyncs == 0) - return; - serial_period_hsync_counter++; - if (serial_period_hsyncs == 1 || (serial_period_hsync_counter % (serial_period_hsyncs - 1)) == 0) - checkreceive (0); - if ((serial_period_hsync_counter % serial_period_hsyncs) == 0) - checksend (0); + if (serial_period_hsyncs == 0) + return; + serial_period_hsync_counter++; + if (serial_period_hsyncs == 1 || (serial_period_hsync_counter % (serial_period_hsyncs - 1)) == 0) + checkreceive (0); + if ((serial_period_hsync_counter % serial_period_hsyncs) == 0) + checksend (0); } void SERDAT (uae_u16 w) { - serdat = w; + serdat = w; - if (!(w & 0x3ff)) { + if (!(w & 0x3ff)) { #if SERIALDEBUG > 1 - write_log (L"SERIAL: zero serial word written?! PC=%x\n", M68K_GETPC); + write_log (L"SERIAL: zero serial word written?! PC=%x\n", M68K_GETPC); #endif - return; - } + return; + } #if SERIALDEBUG > 1 - if (data_in_serdat) { - write_log (L"SERIAL: program wrote to SERDAT but old byte wasn't fetched yet\n"); - } + if (data_in_serdat) { + write_log (L"SERIAL: program wrote to SERDAT but old byte wasn't fetched yet\n"); + } #endif - if (seriallog) - console_out_f (L"%c", dochar (w)); + if (seriallog) + console_out_f (L"%c", dochar (w)); - if (serper == 372) { - extern int enforcermode; - if (enforcermode & 2) { - console_out_f (L"%c", dochar (w)); - if (w == 266) - console_out(L"\n"); + if (serper == 372) { + extern int enforcermode; + if (enforcermode & 2) { + console_out_f (L"%c", dochar (w)); + if (w == 266) + console_out(L"\n"); + } } - } - data_in_serdat = 1; - if (!data_in_sershift) - checksend (1); + data_in_serdat = 1; + if (!data_in_sershift) + checksend (1); #if SERIALDEBUG > 2 - write_log (L"SERIAL: wrote 0x%04x (%c) PC=%x\n", w, doTCHAR (w), M68K_GETPC); + write_log (L"SERIAL: wrote 0x%04x (%c) PC=%x\n", w, doTCHAR (w), M68K_GETPC); #endif - return; + return; } uae_u16 SERDATR (void) { - serdatr &= 0x03ff; - if (!data_in_serdat) - serdatr |= 0x2000; - if (!data_in_sershift) - serdatr |= 0x1000; - if (data_in_serdatr) - serdatr |= 0x4000; - if (ovrun) - serdatr |= 0x8000; + serdatr &= 0x03ff; + if (!data_in_serdat) + serdatr |= 0x2000; + if (!data_in_sershift) + serdatr |= 0x1000; + if (data_in_serdatr) + serdatr |= 0x4000; + if (ovrun) + serdatr |= 0x8000; #if SERIALDEBUG > 2 - write_log ( "SERIAL: read 0x%04x (%c) %x\n", serdatr, doTCHAR (serdatr), M68K_GETPC); + write_log ( "SERIAL: read 0x%04x (%c) %x\n", serdatr, doTCHAR (serdatr), M68K_GETPC); #endif - ovrun = 0; - data_in_serdatr = 0; - return serdatr; + ovrun = 0; + data_in_serdatr = 0; + return serdatr; } void serial_check_irq (void) { - if (data_in_serdatr) - INTREQ_0 (0x8000 | 0x0800); + if (data_in_serdatr) + INTREQ_0 (0x8000 | 0x0800); } void serial_dtr_on (void) { #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: DTR on\n" ); + write_log ( "SERIAL: DTR on\n" ); #endif - dtr = 1; - if (currprefs.serial_demand) - serial_open (); + dtr = 1; + if (currprefs.serial_demand) + serial_open (); #ifdef SERIAL_PORT - setserstat(TIOCM_DTR, dtr); + setserstat(TIOCM_DTR, dtr); #endif } void serial_dtr_off (void) { #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: DTR off\n" ); + write_log ( "SERIAL: DTR off\n" ); #endif - dtr = 0; + dtr = 0; #ifdef SERIAL_PORT - if (currprefs.serial_demand) - serial_close (); - setserstat(TIOCM_DTR, dtr); + if (currprefs.serial_demand) + serial_close (); + setserstat(TIOCM_DTR, dtr); #endif } @@ -303,165 +303,165 @@ static uae_u8 oldserbits; static void serial_status_debug (TCHAR *s) { #if SERIALHSDEBUG > 1 - write_log (L"%s: DTR=%d RTS=%d CD=%d CTS=%d DSR=%d\n", s, - (oldserbits & 0x80) ? 0 : 1, (oldserbits & 0x40) ? 0 : 1, - (oldserbits & 0x20) ? 0 : 1, (oldserbits & 0x10) ? 0 : 1, (oldserbits & 0x08) ? 0 : 1); + write_log (L"%s: DTR=%d RTS=%d CD=%d CTS=%d DSR=%d\n", s, + (oldserbits & 0x80) ? 0 : 1, (oldserbits & 0x40) ? 0 : 1, + (oldserbits & 0x20) ? 0 : 1, (oldserbits & 0x10) ? 0 : 1, (oldserbits & 0x08) ? 0 : 1); #endif } uae_u8 serial_readstatus (uae_u8 dir) { - int status = 0; - uae_u8 serbits = oldserbits; + int status = 0; + uae_u8 serbits = oldserbits; #ifdef SERIAL_PORT - getserstat (&status); + getserstat (&status); #endif - if (!(status & TIOCM_CAR)) { - if (!(serbits & 0x20)) { - serbits |= 0x20; + if (!(status & TIOCM_CAR)) { + if (!(serbits & 0x20)) { + serbits |= 0x20; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: CD off\n" ); + write_log ( "SERIAL: CD off\n" ); #endif - } - } else { - if (serbits & 0x20) { - serbits &= ~0x20; + } + } else { + if (serbits & 0x20) { + serbits &= ~0x20; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: CD on\n" ); + write_log ( "SERIAL: CD on\n" ); #endif + } } - } - if (!(status & TIOCM_DSR)) { - if (!(serbits & 0x08)) { - serbits |= 0x08; + if (!(status & TIOCM_DSR)) { + if (!(serbits & 0x08)) { + serbits |= 0x08; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: DSR off\n" ); + write_log ( "SERIAL: DSR off\n" ); #endif - } - } else { - if (serbits & 0x08) { - serbits &= ~0x08; + } + } else { + if (serbits & 0x08) { + serbits &= ~0x08; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: DSR on\n" ); + write_log ( "SERIAL: DSR on\n" ); #endif + } } - } - if (!(status & TIOCM_CTS)) { - if (!(serbits & 0x10)) { - serbits |= 0x10; + if (!(status & TIOCM_CTS)) { + if (!(serbits & 0x10)) { + serbits |= 0x10; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: CTS off\n" ); + write_log ( "SERIAL: CTS off\n" ); #endif - } - } else { - if (serbits & 0x10) { - serbits &= ~0x10; + } + } else { + if (serbits & 0x10) { + serbits &= ~0x10; #if SERIALHSDEBUG > 0 - write_log ( "SERIAL: CTS on\n" ); + write_log ( "SERIAL: CTS on\n" ); #endif + } } - } - serbits &= 0x08 | 0x10 | 0x20; - oldserbits &= ~(0x08 | 0x10 | 0x20); - oldserbits |= serbits; + serbits &= 0x08 | 0x10 | 0x20; + oldserbits &= ~(0x08 | 0x10 | 0x20); + oldserbits |= serbits; - serial_status_debug (L"read"); + serial_status_debug (L"read"); - return oldserbits; + return oldserbits; } uae_u8 serial_writestatus (uae_u8 newstate, uae_u8 dir) { - static int logcnt = 10; + static int logcnt = 10; #ifdef SERIAL_PORT - if (((oldserbits ^ newstate) & 0x80) && (dir & 0x80)) { - if (newstate & 0x80) - serial_dtr_off(); - else - serial_dtr_on(); - } - - if (!currprefs.serial_hwctsrts && (dir & 0x40)) { - if ((oldserbits ^ newstate) & 0x40) { - if (newstate & 0x40) { - setserstat (TIOCM_RTS, 0); + if (((oldserbits ^ newstate) & 0x80) && (dir & 0x80)) { + if (newstate & 0x80) + serial_dtr_off(); + else + serial_dtr_on(); + } + + if (!currprefs.serial_hwctsrts && (dir & 0x40)) { + if ((oldserbits ^ newstate) & 0x40) { + if (newstate & 0x40) { + setserstat (TIOCM_RTS, 0); #if SERIALHSDEBUG > 0 - write_log (L"SERIAL: RTS cleared\n"); + write_log (L"SERIAL: RTS cleared\n"); #endif - } else { - setserstat (TIOCM_RTS, 1); + } else { + setserstat (TIOCM_RTS, 1); #if SERIALHSDEBUG > 0 - write_log (L"SERIAL: RTS set\n"); + write_log (L"SERIAL: RTS set\n"); #endif - } + } + } } - } - #if 0 /* CIA io-pins can be read even when set to output.. */ - if ((newstate & 0x20) != (oldserbits & 0x20) && (dir & 0x20)) - write_log (L"SERIAL: warning, program tries to use CD as an output!\n"); - if ((newstate & 0x10) != (oldserbits & 0x10) && (dir & 0x10)) - write_log (L"SERIAL: warning, program tries to use CTS as an output!\n"); - if ((newstate & 0x08) != (oldserbits & 0x08) && (dir & 0x08)) - write_log (L"SERIAL: warning, program tries to use DSR as an output!\n"); +#if 0 /* CIA io-pins can be read even when set to output.. */ + if ((newstate & 0x20) != (oldserbits & 0x20) && (dir & 0x20)) + write_log (L"SERIAL: warning, program tries to use CD as an output!\n"); + if ((newstate & 0x10) != (oldserbits & 0x10) && (dir & 0x10)) + write_log (L"SERIAL: warning, program tries to use CTS as an output!\n"); + if ((newstate & 0x08) != (oldserbits & 0x08) && (dir & 0x08)) + write_log (L"SERIAL: warning, program tries to use DSR as an output!\n"); #endif - if (logcnt > 0) { - if (((newstate ^ oldserbits) & 0x40) && !(dir & 0x40)) { - write_log (L"SERIAL: warning, program tries to use RTS as an input! PC=%x\n", M68K_GETPC); - logcnt--; - } - if (((newstate ^ oldserbits) & 0x80) && !(dir & 0x80)) { - write_log (L"SERIAL: warning, program tries to use DTR as an input! PC=%x\n", M68K_GETPC); - logcnt--; + if (logcnt > 0) { + if (((newstate ^ oldserbits) & 0x40) && !(dir & 0x40)) { + write_log (L"SERIAL: warning, program tries to use RTS as an input! PC=%x\n", M68K_GETPC); + logcnt--; + } + if (((newstate ^ oldserbits) & 0x80) && !(dir & 0x80)) { + write_log (L"SERIAL: warning, program tries to use DTR as an input! PC=%x\n", M68K_GETPC); + logcnt--; + } } - } #endif - oldserbits &= ~(0x80 | 0x40); - newstate &= 0x80 | 0x40; - oldserbits |= newstate; - serial_status_debug (L"write"); + oldserbits &= ~(0x80 | 0x40); + newstate &= 0x80 | 0x40; + oldserbits |= newstate; + serial_status_debug (L"write"); - return oldserbits; + return oldserbits; } void serial_open (void) { #ifdef SERIAL_PORT - if (serdev) - return; - serper = 0; - if(!openser (currprefs.sername)) { - write_log (L"SERIAL: Could not open device %s\n", currprefs.sername); - return; - } - serdev = 1; + if (serdev) + return; + serper = 0; + if(!openser (currprefs.sername)) { + write_log (L"SERIAL: Could not open device %s\n", currprefs.sername); + return; + } + serdev = 1; #endif } void serial_close (void) { #ifdef SERIAL_PORT - closeser (); - serdev = 0; + closeser (); + serdev = 0; #endif } void serial_init (void) { #ifdef SERIAL_PORT - if (!currprefs.use_serial) - return; + if (!currprefs.use_serial) + return; - if (!currprefs.serial_demand) - serial_open (); + if (!currprefs.serial_demand) + serial_open (); #endif } @@ -469,15 +469,15 @@ void serial_init (void) void serial_exit (void) { #ifdef SERIAL_PORT - serial_close (); /* serial_close can always be called because it */ + serial_close (); /* serial_close can always be called because it */ #endif - dtr = 0; /* just closes *opened* filehandles which is ok */ - oldserbits = 0; /* when exiting. */ + dtr = 0; /* just closes *opened* filehandles which is ok */ + oldserbits = 0; /* when exiting. */ } void serial_uartbreak (int v) { #ifdef SERIAL_PORT - serialuartbreak (v); + serialuartbreak (v); #endif } diff --git a/od-win32/sounddep/sound.c b/od-win32/sounddep/sound.c index 4b56e9f3..f25d7a37 100644 --- a/od-win32/sounddep/sound.c +++ b/od-win32/sounddep/sound.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Win32 sound interface (DirectSound) - * - * Copyright 1997 Mathias Ortmann - * Copyright 1997-2001 Brian King - * Copyright 2000-2002 Bernd Roesch - * Copyright 2002-2003 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Win32 sound interface (DirectSound) +* +* Copyright 1997 Mathias Ortmann +* Copyright 1997-2001 Brian King +* Copyright 2000-2002 Bernd Roesch +* Copyright 2002-2003 Toni Wilen +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -47,63 +47,63 @@ struct sound_dp { - // directsound - - LPDIRECTSOUND8 lpDS; - LPDIRECTSOUNDBUFFER8 lpDSBsecondary; - DWORD writepos; - int dsoundbuf; - int safedist; - int snd_writeoffset; - int snd_maxoffset; - int snd_totalmaxoffset_uf; - int snd_totalmaxoffset_of; - int max_sndbufsize; - int snd_configsize; - -// openal - - #define AL_BUFFERS 2 - ALCdevice *al_dev; - ALCcontext *al_ctx; - ALuint al_Buffers[AL_BUFFERS]; - ALuint al_Source; - int al_toggle; - DWORD al_format; - uae_u8 *al_bigbuffer; - int al_bufsize, al_offset; - - -// portaudio - - volatile int patoggle; - volatile int pacounter; - uae_u8 *pasoundbuffer[2]; - int pasndbufsize; - int paframesperbuffer; - PaStream *pastream; - HANDLE paevent; - int opacounter; - int pablocking; - -// wasapi - - IMMDevice *pDevice; - IAudioClient *pAudioClient; - IAudioRenderClient *pRenderClient; - IMMDeviceEnumerator *pEnumerator; + // directsound + + LPDIRECTSOUND8 lpDS; + LPDIRECTSOUNDBUFFER8 lpDSBsecondary; + DWORD writepos; + int dsoundbuf; + int safedist; + int snd_writeoffset; + int snd_maxoffset; + int snd_totalmaxoffset_uf; + int snd_totalmaxoffset_of; + int max_sndbufsize; + int snd_configsize; + + // openal + +#define AL_BUFFERS 2 + ALCdevice *al_dev; + ALCcontext *al_ctx; + ALuint al_Buffers[AL_BUFFERS]; + ALuint al_Source; + int al_toggle; + DWORD al_format; + uae_u8 *al_bigbuffer; + int al_bufsize, al_offset; + + + // portaudio + + volatile int patoggle; + volatile int pacounter; + uae_u8 *pasoundbuffer[2]; + int pasndbufsize; + int paframesperbuffer; + PaStream *pastream; + HANDLE paevent; + int opacounter; + int pablocking; + + // wasapi + + IMMDevice *pDevice; + IAudioClient *pAudioClient; + IAudioRenderClient *pRenderClient; + IMMDeviceEnumerator *pEnumerator; #if 0 - IAudioClock *pAudioClock; - UINT64 wasapiclock; + IAudioClock *pAudioClock; + UINT64 wasapiclock; #endif - REFERENCE_TIME hnsRequestedDuration; - int bufferFrameCount; - UINT64 wasapiframes; - int wasapiexclusive; - int framecounter; - int sndbuf; - int wasapigoodsize; - int sndbufframes; + REFERENCE_TIME hnsRequestedDuration; + int bufferFrameCount; + UINT64 wasapiframes; + int wasapiexclusive; + int framecounter; + int sndbuf; + int wasapigoodsize; + int sndbufframes; }; #define ADJUST_SIZE 30 @@ -137,187 +137,196 @@ static struct sound_data *sdp = &sdpaula; int setup_sound (void) { - sound_available = 1; - return 1; + sound_available = 1; + return 1; } static int isvsync (void) { - return currprefs.gfx_avsync && currprefs.gfx_afullscreen; + return currprefs.gfx_avsync && currprefs.gfx_afullscreen; } float scaled_sample_evtime_orig; -void update_sound (int freq, int longframe) +void update_sound (int freq, int longframe, int linetoggle) { - static int lastfreq; - float lines = 0; + static int lastfreq; + float lines = 0; + float hpos; - if (freq < 0) - freq = lastfreq; - lastfreq = freq; + if (freq < 0) + freq = lastfreq; + lastfreq = freq; - if (longframe < 0) - lines += 0.5; - else if (longframe > 0) - lines += 1.0; + if (!have_sound) + return; + + if (linetoggle) { + hpos = maxhpos_short + 0.5; + lines += 0.5; + } else { + if (longframe < 0) + lines += 0.5; + else if (longframe > 0) + lines += 1.0; + hpos = maxhpos_short; + } + lines += maxvpos; - if (have_sound) { - scaled_sample_evtime_orig = maxhpos * (lines + maxvpos) * freq * CYCLE_UNIT / (float)sdp->obtainedfreq; + scaled_sample_evtime_orig = hpos * lines * freq * CYCLE_UNIT / (float)sdp->obtainedfreq; scaled_sample_evtime = scaled_sample_evtime_orig; - } } static void clearbuffer_ds (struct sound_data *sd) { - void *buffer; - DWORD size; - struct sound_dp *s = sd->data; + void *buffer; + DWORD size; + struct sound_dp *s = sd->data; - HRESULT hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, 0, s->dsoundbuf, &buffer, &size, NULL, NULL, 0); - if (hr == DSERR_BUFFERLOST) { - IDirectSoundBuffer_Restore (s->lpDSBsecondary); - hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, 0, s->dsoundbuf, &buffer, &size, NULL, NULL, 0); - } - if (FAILED (hr)) { - write_log (L"DSSOUND: failed to Lock sound buffer (clear): %s\n", DXError (hr)); - return; - } - memset (buffer, 0, size); - IDirectSoundBuffer_Unlock (s->lpDSBsecondary, buffer, size, NULL, 0); + HRESULT hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, 0, s->dsoundbuf, &buffer, &size, NULL, NULL, 0); + if (hr == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (s->lpDSBsecondary); + hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, 0, s->dsoundbuf, &buffer, &size, NULL, NULL, 0); + } + if (FAILED (hr)) { + write_log (L"DSSOUND: failed to Lock sound buffer (clear): %s\n", DXError (hr)); + return; + } + memset (buffer, 0, size); + IDirectSoundBuffer_Unlock (s->lpDSBsecondary, buffer, size, NULL, 0); } static void clearbuffer (struct sound_data *sd) { - if (sd->devicetype == SOUND_DEVICE_DS) - clearbuffer_ds (sd); + if (sd->devicetype == SOUND_DEVICE_DS) + clearbuffer_ds (sd); } static void pause_audio_wasapi (struct sound_data *sd) { - struct sound_dp *s = sd->data; - HRESULT hr; + struct sound_dp *s = sd->data; + HRESULT hr; - hr = s->pAudioClient->lpVtbl->Stop (s->pAudioClient); - if (FAILED (hr)) - write_log (L"WASAPI: Stop() %08X\n", hr); + hr = s->pAudioClient->lpVtbl->Stop (s->pAudioClient); + if (FAILED (hr)) + write_log (L"WASAPI: Stop() %08X\n", hr); } static void resume_audio_wasapi (struct sound_data *sd) { - struct sound_dp *s = sd->data; - HRESULT hr; - BYTE *pData; - int framecnt; - - hr = s->pAudioClient->lpVtbl->Reset (s->pAudioClient); - if (FAILED (hr)) - write_log (L"WASAPI: Reset() %08X\n", hr); - framecnt = s->wasapigoodsize; - hr = s->pRenderClient->lpVtbl->GetBuffer (s->pRenderClient, framecnt, &pData); - if (FAILED (hr)) - return; - hr = s->pRenderClient->lpVtbl->ReleaseBuffer (s->pRenderClient, framecnt, AUDCLNT_BUFFERFLAGS_SILENT); - hr = s->pAudioClient->lpVtbl->Start (s->pAudioClient); - if (FAILED (hr)) - write_log (L"WASAPI: Start() %08X\n", hr); - s->wasapiframes = 0; - s->framecounter = 0; - s->sndbuf = 0; + struct sound_dp *s = sd->data; + HRESULT hr; + BYTE *pData; + int framecnt; + + hr = s->pAudioClient->lpVtbl->Reset (s->pAudioClient); + if (FAILED (hr)) + write_log (L"WASAPI: Reset() %08X\n", hr); + framecnt = s->wasapigoodsize; + hr = s->pRenderClient->lpVtbl->GetBuffer (s->pRenderClient, framecnt, &pData); + if (FAILED (hr)) + return; + hr = s->pRenderClient->lpVtbl->ReleaseBuffer (s->pRenderClient, framecnt, AUDCLNT_BUFFERFLAGS_SILENT); + hr = s->pAudioClient->lpVtbl->Start (s->pAudioClient); + if (FAILED (hr)) + write_log (L"WASAPI: Start() %08X\n", hr); + s->wasapiframes = 0; + s->framecounter = 0; + s->sndbuf = 0; } static void pause_audio_ds (struct sound_data *sd) { - struct sound_dp *s = sd->data; - HRESULT hr; + struct sound_dp *s = sd->data; + HRESULT hr; - sd->waiting_for_buffer = 0; - hr = IDirectSoundBuffer_Stop (s->lpDSBsecondary); - if (FAILED (hr)) - write_log (L"DSSOUND: DirectSoundBuffer_Stop failed, %s\n", DXError (hr)); - hr = IDirectSoundBuffer_SetCurrentPosition (s->lpDSBsecondary, 0); - if (FAILED (hr)) - write_log (L"DSSOUND: DirectSoundBuffer_SetCurretPosition failed, %s\n", DXError (hr)); - clearbuffer (sd); + sd->waiting_for_buffer = 0; + hr = IDirectSoundBuffer_Stop (s->lpDSBsecondary); + if (FAILED (hr)) + write_log (L"DSSOUND: DirectSoundBuffer_Stop failed, %s\n", DXError (hr)); + hr = IDirectSoundBuffer_SetCurrentPosition (s->lpDSBsecondary, 0); + if (FAILED (hr)) + write_log (L"DSSOUND: DirectSoundBuffer_SetCurretPosition failed, %s\n", DXError (hr)); + clearbuffer (sd); } static void resume_audio_ds (struct sound_data *sd) { - sd->paused = 0; - clearbuffer (sd); - sd->waiting_for_buffer = 1; + sd->paused = 0; + clearbuffer (sd); + sd->waiting_for_buffer = 1; } static void pause_audio_pa (struct sound_data *sd) { - struct sound_dp *s = sd->data; - PaError err = Pa_StopStream (s->pastream); - if (err != paNoError) - write_log (L"PASOUND: Pa_StopStream() error %d (%s)\n", err, Pa_GetErrorText (err)); + struct sound_dp *s = sd->data; + PaError err = Pa_StopStream (s->pastream); + if (err != paNoError) + write_log (L"PASOUND: Pa_StopStream() error %d (%s)\n", err, Pa_GetErrorText (err)); } static void resume_audio_pa (struct sound_data *sd) { - struct sound_dp *s = sd->data; - PaError err = Pa_StartStream (s->pastream); - if (err != paNoError) - write_log (L"PASOUND: Pa_StartStream() error %d (%s)\n", err, Pa_GetErrorText (err)); - sd->paused = 0; + struct sound_dp *s = sd->data; + PaError err = Pa_StartStream (s->pastream); + if (err != paNoError) + write_log (L"PASOUND: Pa_StartStream() error %d (%s)\n", err, Pa_GetErrorText (err)); + sd->paused = 0; } static void pause_audio_al (struct sound_data *sd) { - struct sound_dp *s = sd->data; - sd->waiting_for_buffer = 0; - alSourcePause (s->al_Source); + struct sound_dp *s = sd->data; + sd->waiting_for_buffer = 0; + alSourcePause (s->al_Source); } static void resume_audio_al (struct sound_data *sd) { - struct sound_dp *s = sd->data; - sd->waiting_for_buffer = 1; - s->al_offset = 0; + struct sound_dp *s = sd->data; + sd->waiting_for_buffer = 1; + s->al_offset = 0; } static int restore_ds (struct sound_data *sd, DWORD hr) { - struct sound_dp *s = sd->data; - if (hr != DSERR_BUFFERLOST) - return 0; - if (sound_debug) - write_log (L"DSSOUND: sound buffer lost\n"); - hr = IDirectSoundBuffer_Restore (s->lpDSBsecondary); - if (FAILED (hr)) { - write_log (L"DSSOUND: restore failed %s\n", DXError (hr)); + struct sound_dp *s = sd->data; + if (hr != DSERR_BUFFERLOST) + return 0; + if (sound_debug) + write_log (L"DSSOUND: sound buffer lost\n"); + hr = IDirectSoundBuffer_Restore (s->lpDSBsecondary); + if (FAILED (hr)) { + write_log (L"DSSOUND: restore failed %s\n", DXError (hr)); + return 1; + } + pause_audio_ds (sd); + resume_audio_ds (sd); return 1; - } - pause_audio_ds (sd); - resume_audio_ds (sd); - return 1; } static LARGE_INTEGER qpfc, qpf; static void storeqpf (void) { - QueryPerformanceCounter (&qpfc); + QueryPerformanceCounter (&qpfc); } static double getqpf (void) { - LARGE_INTEGER qpfc2; - QueryPerformanceCounter (&qpfc2); - return (qpfc2.QuadPart - qpfc.QuadPart) / (qpf.QuadPart / 1000.0); + LARGE_INTEGER qpfc2; + QueryPerformanceCounter (&qpfc2); + return (qpfc2.QuadPart - qpfc.QuadPart) / (qpf.QuadPart / 1000.0); } static void close_audio_ds (struct sound_data *sd) { - struct sound_dp *s = sd->data; - if (s->lpDSBsecondary) - IDirectSound_Release (s->lpDSBsecondary); - s->lpDSBsecondary = 0; + struct sound_dp *s = sd->data; + if (s->lpDSBsecondary) + IDirectSound_Release (s->lpDSBsecondary); + s->lpDSBsecondary = 0; #ifdef USE_PRIMARY_BUFFER - if (s->lpDSBprimary) - IDirectSound_Release (s->lpDSBprimary); - s->lpDSBprimary = 0; + if (s->lpDSBprimary) + IDirectSound_Release (s->lpDSBprimary); + s->lpDSBprimary = 0; #endif - if (s->lpDS) { - IDirectSound_Release (s->lpDS); - write_log (L"DSSOUND: DirectSound driver freed\n"); - } - s->lpDS = 0; + if (s->lpDS) { + IDirectSound_Release (s->lpDS); + write_log (L"DSSOUND: DirectSound driver freed\n"); + } + s->lpDS = 0; } extern HWND hMainWnd; @@ -325,363 +334,363 @@ extern void setvolume_ahi (LONG); void set_volume_sound_device (struct sound_data *sd, int volume, int mute) { - struct sound_dp *s = sd->data; - if (sd->devicetype == SOUND_DEVICE_AL) { - float vol = 0.0; - if (volume < 100 && !mute) - vol = (100 - volume) / 100.0; - alSourcef (s->al_Source, AL_GAIN, vol); - } else if (sd->devicetype == SOUND_DEVICE_DS) { - HRESULT hr; - LONG vol = DSBVOLUME_MIN; - if (volume < 100 && !mute) - vol = (LONG)((DSBVOLUME_MIN / 2) + (-DSBVOLUME_MIN / 2) * log (1 + (2.718281828 - 1) * (1 - volume / 100.0))); - hr = IDirectSoundBuffer_SetVolume (s->lpDSBsecondary, vol); - if (FAILED (hr)) - write_log (L"DSSOUND: SetVolume(%d) failed: %s\n", vol, DXError (hr)); - } + struct sound_dp *s = sd->data; + if (sd->devicetype == SOUND_DEVICE_AL) { + float vol = 0.0; + if (volume < 100 && !mute) + vol = (100 - volume) / 100.0; + alSourcef (s->al_Source, AL_GAIN, vol); + } else if (sd->devicetype == SOUND_DEVICE_DS) { + HRESULT hr; + LONG vol = DSBVOLUME_MIN; + if (volume < 100 && !mute) + vol = (LONG)((DSBVOLUME_MIN / 2) + (-DSBVOLUME_MIN / 2) * log (1 + (2.718281828 - 1) * (1 - volume / 100.0))); + hr = IDirectSoundBuffer_SetVolume (s->lpDSBsecondary, vol); + if (FAILED (hr)) + write_log (L"DSSOUND: SetVolume(%d) failed: %s\n", vol, DXError (hr)); + } } void set_volume (int volume, int mute) { - set_volume_sound_device (sdp, volume, mute); - setvolume_ahi (volume); + set_volume_sound_device (sdp, volume, mute); + setvolume_ahi (volume); } static void recalc_offsets (struct sound_data *sd) { - struct sound_dp *s = sd->data; - s->snd_writeoffset = s->max_sndbufsize * 5 / 8; - s->snd_maxoffset = s->max_sndbufsize; - s->snd_totalmaxoffset_of = s->max_sndbufsize + (s->dsoundbuf - s->max_sndbufsize) * 3 / 9; - s->snd_totalmaxoffset_uf = s->max_sndbufsize + (s->dsoundbuf - s->max_sndbufsize) * 7 / 9; + struct sound_dp *s = sd->data; + s->snd_writeoffset = s->max_sndbufsize * 5 / 8; + s->snd_maxoffset = s->max_sndbufsize; + s->snd_totalmaxoffset_of = s->max_sndbufsize + (s->dsoundbuf - s->max_sndbufsize) * 3 / 9; + s->snd_totalmaxoffset_uf = s->max_sndbufsize + (s->dsoundbuf - s->max_sndbufsize) * 7 / 9; } const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010, - {0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}; +{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}; #define KSAUDIO_SPEAKER_QUAD_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \ - SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT) + SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT) #define MAX_SUPPORTEDMODES 16 static struct dsaudiomodes supportedmodes[MAX_SUPPORTEDMODES]; static DWORD fillsupportedmodes (struct sound_data *sd, int freq, struct dsaudiomodes *dsam) { - static DWORD speakerconfig; - DSBUFFERDESC sound_buffer; - WAVEFORMATEXTENSIBLE wavfmt; - LPDIRECTSOUNDBUFFER pdsb; - HRESULT hr; - int ch, round, mode, skip; - DWORD rn[4]; - struct sound_dp *s = sd->data; - LPDIRECTSOUND8 lpDS = s->lpDS; - static done; - - if (done) - return speakerconfig; + static DWORD speakerconfig; + DSBUFFERDESC sound_buffer; + WAVEFORMATEXTENSIBLE wavfmt; + LPDIRECTSOUNDBUFFER pdsb; + HRESULT hr; + int ch, round, mode, skip; + DWORD rn[4]; + struct sound_dp *s = sd->data; + LPDIRECTSOUND8 lpDS = s->lpDS; + static done; + + if (done) + return speakerconfig; + + mode = 2; + dsam[0].ch = 1; + dsam[0].ksmode = 0; + dsam[1].ch = 2; + dsam[1].ksmode = 0; + if (FAILED (IDirectSound8_GetSpeakerConfig (lpDS, &speakerconfig))) + speakerconfig = DSSPEAKER_STEREO; - mode = 2; - dsam[0].ch = 1; - dsam[0].ksmode = 0; - dsam[1].ch = 2; - dsam[1].ksmode = 0; - if (FAILED (IDirectSound8_GetSpeakerConfig (lpDS, &speakerconfig))) - speakerconfig = DSSPEAKER_STEREO; - - memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); - wavfmt.Format.nSamplesPerSec = freq; - wavfmt.Format.wBitsPerSample = 16; - wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; - wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); - wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - wavfmt.Samples.wValidBitsPerSample = 16; - for (ch = 4; ch <= 6; ch+= 2) { - wavfmt.Format.nChannels = ch; - wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; - wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; - if (ch == 6) { - rn[0] = KSAUDIO_SPEAKER_5POINT1; - rn[1] = KSAUDIO_SPEAKER_5POINT1_SURROUND; - rn[2] = 0; - } else { - rn[0] = KSAUDIO_SPEAKER_QUAD; - rn[1] = KSAUDIO_SPEAKER_QUAD_SURROUND; - rn[2] = KSAUDIO_SPEAKER_SURROUND; - rn[3] = 0; - } - skip = sound_mode_skip; - for (round = 0; rn[round]; round++) { - if (skip > 0 && rn[round + 1] != 0) { - skip--; - continue; - } - wavfmt.dwChannelMask = rn[round]; - memset (&sound_buffer, 0, sizeof (sound_buffer)); - sound_buffer.dwSize = sizeof (sound_buffer); - sound_buffer.dwBufferBytes = s->dsoundbuf; - sound_buffer.lpwfxFormat = &wavfmt.Format; - sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; - sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME; - sound_buffer.guid3DAlgorithm = GUID_NULL; - pdsb = NULL; - hr = IDirectSound_CreateSoundBuffer (lpDS, &sound_buffer, &pdsb, NULL); - if (SUCCEEDED (hr)) { - IDirectSound_Release (pdsb); - dsam[mode].ksmode = rn[round]; - dsam[mode].ch = ch; - mode++; - if (mode >= MAX_SUPPORTEDMODES - 1) - break; - } - } - } - dsam[mode].ch = 0; - dsam[mode].ksmode = 0; - done = 1; - return speakerconfig; + memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); + wavfmt.Format.nSamplesPerSec = freq; + wavfmt.Format.wBitsPerSample = 16; + wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); + wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + wavfmt.Samples.wValidBitsPerSample = 16; + for (ch = 4; ch <= 6; ch+= 2) { + wavfmt.Format.nChannels = ch; + wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; + wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; + if (ch == 6) { + rn[0] = KSAUDIO_SPEAKER_5POINT1; + rn[1] = KSAUDIO_SPEAKER_5POINT1_SURROUND; + rn[2] = 0; + } else { + rn[0] = KSAUDIO_SPEAKER_QUAD; + rn[1] = KSAUDIO_SPEAKER_QUAD_SURROUND; + rn[2] = KSAUDIO_SPEAKER_SURROUND; + rn[3] = 0; + } + skip = sound_mode_skip; + for (round = 0; rn[round]; round++) { + if (skip > 0 && rn[round + 1] != 0) { + skip--; + continue; + } + wavfmt.dwChannelMask = rn[round]; + memset (&sound_buffer, 0, sizeof (sound_buffer)); + sound_buffer.dwSize = sizeof (sound_buffer); + sound_buffer.dwBufferBytes = s->dsoundbuf; + sound_buffer.lpwfxFormat = &wavfmt.Format; + sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; + sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME; + sound_buffer.guid3DAlgorithm = GUID_NULL; + pdsb = NULL; + hr = IDirectSound_CreateSoundBuffer (lpDS, &sound_buffer, &pdsb, NULL); + if (SUCCEEDED (hr)) { + IDirectSound_Release (pdsb); + dsam[mode].ksmode = rn[round]; + dsam[mode].ch = ch; + mode++; + if (mode >= MAX_SUPPORTEDMODES - 1) + break; + } + } + } + dsam[mode].ch = 0; + dsam[mode].ksmode = 0; + done = 1; + return speakerconfig; } static void finish_sound_buffer_pa (struct sound_data *sd, uae_u16 *sndbuffer) { - struct sound_dp *s = sd->data; - if (s->pablocking) { - if (s->paframesperbuffer != sd->sndbufsize / (sd->channels * 2)) { - write_log (L"sound buffer size mistmatch %d <> %d\n", s->paframesperbuffer, sd->sndbufsize / (sd->channels * 2)); + struct sound_dp *s = sd->data; + if (s->pablocking) { + if (s->paframesperbuffer != sd->sndbufsize / (sd->channels * 2)) { + write_log (L"sound buffer size mistmatch %d <> %d\n", s->paframesperbuffer, sd->sndbufsize / (sd->channels * 2)); + } else { + Pa_WriteStream (s->pastream, sndbuffer, s->paframesperbuffer); + } } else { - Pa_WriteStream (s->pastream, sndbuffer, s->paframesperbuffer); + while (s->opacounter == s->pacounter && s->pastream && !sd->paused) + WaitForSingleObject (s->paevent, 10); + s->opacounter = s->pacounter; + memcpy (s->pasoundbuffer[s->patoggle], sndbuffer, sd->sndbufsize); } - } else { - while (s->opacounter == s->pacounter && s->pastream && !sd->paused) - WaitForSingleObject (s->paevent, 10); - s->opacounter = s->pacounter; - memcpy (s->pasoundbuffer[s->patoggle], sndbuffer, sd->sndbufsize); - } } static int _cdecl portAudioCallback (const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData) + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData) { - struct sound_data *sd = userData; - struct sound_dp *s = sd->data; + struct sound_data *sd = userData; + struct sound_dp *s = sd->data; - if (framesPerBuffer != sd->sndbufsize / (sd->channels * 2)) { - write_log (L"sound buffer size mistmatch %d <> %d\n", framesPerBuffer, sd->sndbufsize / (sd->channels * 2)); - } else { - memcpy (outputBuffer, s->pasoundbuffer[s->patoggle], sd->sndbufsize); - } - s->patoggle ^= 1; - s->pacounter++; - SetEvent (s->paevent); - return paContinue; + if (framesPerBuffer != sd->sndbufsize / (sd->channels * 2)) { + write_log (L"sound buffer size mistmatch %d <> %d\n", framesPerBuffer, sd->sndbufsize / (sd->channels * 2)); + } else { + memcpy (outputBuffer, s->pasoundbuffer[s->patoggle], sd->sndbufsize); + } + s->patoggle ^= 1; + s->pacounter++; + SetEvent (s->paevent); + return paContinue; } static void close_audio_pa (struct sound_data *sd) { - struct sound_dp *s = sd->data; - int i; - - if (s->pastream) - Pa_CloseStream (s->pastream); - s->pastream = NULL; - for (i = 0; i < 2; i++) { - xfree (s->pasoundbuffer[i]); - s->pasoundbuffer[i] = NULL; - } - if (s->paevent) { - SetEvent (s->paevent); - CloseHandle (s->paevent); - } - s->paevent = NULL; + struct sound_dp *s = sd->data; + int i; + + if (s->pastream) + Pa_CloseStream (s->pastream); + s->pastream = NULL; + for (i = 0; i < 2; i++) { + xfree (s->pasoundbuffer[i]); + s->pasoundbuffer[i] = NULL; + } + if (s->paevent) { + SetEvent (s->paevent); + CloseHandle (s->paevent); + } + s->paevent = NULL; } static int open_audio_pa (struct sound_data *sd, int index) { - struct sound_dp *s = sd->data; - int i; - int freq = sd->freq; - int ch = sd->channels; - int size; - int dev = sound_devices[index].panum; - const PaDeviceInfo *di; - PaStreamParameters p; - PaError err; - TCHAR *name; - TCHAR *errtxt; - int defaultrate = 0; - - size = sd->sndbufsize; - s->paframesperbuffer = size; - sd->devicetype = SOUND_DEVICE_PA; - memset (&p, 0, sizeof p); - di = Pa_GetDeviceInfo (dev); - for (;;) { - int err2; - p.channelCount = ch; - p.device = dev; - p.hostApiSpecificStreamInfo = NULL; - p.sampleFormat = paInt16; - p.suggestedLatency = di->defaultLowOutputLatency; - p.hostApiSpecificStreamInfo = NULL; - - err = Pa_IsFormatSupported (NULL, &p, freq); - if (err == paFormatIsSupported) - break; - err2 = err; - errtxt = au (Pa_GetErrorText (err)); - write_log (L"PASOUND: sound format not supported, ch=%d, rate=%d. %s\n", freq, ch, errtxt); - xfree (errtxt); - if (err == paInvalidChannelCount) { - if (ch > 2) { - ch = sd->channels = 2; - continue; - } - goto end; - } - if (freq < 44000 && err == paInvalidSampleRate) { - freq = 44000; - sd->freq = freq; - continue; - } - if (freq < 48000 && err == paInvalidSampleRate) { - freq = 48000; - sd->freq = freq; - continue; - } - if (freq != di->defaultSampleRate && err == paInvalidSampleRate && !defaultrate) { - freq = di->defaultSampleRate; - sd->freq = freq; - defaultrate = 1; - continue; - } - goto end; - } - sd->sndbufsize = size * ch * 2; -// s->pablocking = 1; -// err = Pa_OpenStream (&s->pastream, NULL, &p, freq, s->paframesperbuffer, paNoFlag, NULL, NULL); -// if (err != paNoError) { + struct sound_dp *s = sd->data; + int i; + int freq = sd->freq; + int ch = sd->channels; + int size; + int dev = sound_devices[index].panum; + const PaDeviceInfo *di; + PaStreamParameters p; + PaError err; + TCHAR *name; + TCHAR *errtxt; + int defaultrate = 0; + + size = sd->sndbufsize; + s->paframesperbuffer = size; + sd->devicetype = SOUND_DEVICE_PA; + memset (&p, 0, sizeof p); + di = Pa_GetDeviceInfo (dev); + for (;;) { + int err2; + p.channelCount = ch; + p.device = dev; + p.hostApiSpecificStreamInfo = NULL; + p.sampleFormat = paInt16; + p.suggestedLatency = di->defaultLowOutputLatency; + p.hostApiSpecificStreamInfo = NULL; + + err = Pa_IsFormatSupported (NULL, &p, freq); + if (err == paFormatIsSupported) + break; + err2 = err; + errtxt = au (Pa_GetErrorText (err)); + write_log (L"PASOUND: sound format not supported, ch=%d, rate=%d. %s\n", freq, ch, errtxt); + xfree (errtxt); + if (err == paInvalidChannelCount) { + if (ch > 2) { + ch = sd->channels = 2; + continue; + } + goto end; + } + if (freq < 44000 && err == paInvalidSampleRate) { + freq = 44000; + sd->freq = freq; + continue; + } + if (freq < 48000 && err == paInvalidSampleRate) { + freq = 48000; + sd->freq = freq; + continue; + } + if (freq != di->defaultSampleRate && err == paInvalidSampleRate && !defaultrate) { + freq = di->defaultSampleRate; + sd->freq = freq; + defaultrate = 1; + continue; + } + goto end; + } + sd->sndbufsize = size * ch * 2; + // s->pablocking = 1; + // err = Pa_OpenStream (&s->pastream, NULL, &p, freq, s->paframesperbuffer, paNoFlag, NULL, NULL); + // if (err != paNoError) { s->pablocking = 0; err = Pa_OpenStream (&s->pastream, NULL, &p, freq, s->paframesperbuffer, paNoFlag, portAudioCallback, sd); if (err != paNoError) { - errtxt = au (Pa_GetErrorText (err)); - write_log (L"PASOUND: Pa_OpenStream() error %d (%s)\n", err, errtxt); - xfree (errtxt); - goto end; - } -// } - s->paevent = CreateEvent (NULL, FALSE, FALSE, NULL); - for (i = 0; i < 2; i++) - s->pasoundbuffer[i] = xcalloc (sd->sndbufsize, 1); - name = au (di->name); - write_log (L"PASOUND: CH=%d,FREQ=%d (%s) '%s' buffer %d\n", - ch, freq, sound_devices[index].name, name, sd->sndbufsize); - xfree (name); - return 1; + errtxt = au (Pa_GetErrorText (err)); + write_log (L"PASOUND: Pa_OpenStream() error %d (%s)\n", err, errtxt); + xfree (errtxt); + goto end; + } + // } + s->paevent = CreateEvent (NULL, FALSE, FALSE, NULL); + for (i = 0; i < 2; i++) + s->pasoundbuffer[i] = xcalloc (sd->sndbufsize, 1); + name = au (di->name); + write_log (L"PASOUND: CH=%d,FREQ=%d (%s) '%s' buffer %d\n", + ch, freq, sound_devices[index].name, name, sd->sndbufsize); + xfree (name); + return 1; end: - s->pastream = NULL; - close_audio_pa (sd); - return 0; + s->pastream = NULL; + close_audio_pa (sd); + return 0; } static void close_audio_al (struct sound_data *sd) { - struct sound_dp *s = sd->data; - int i; - - alDeleteSources (1, &s->al_Source); - s->al_Source = 0; - alDeleteBuffers (AL_BUFFERS, s->al_Buffers); - alcMakeContextCurrent (NULL); - if (s->al_ctx) - alcDestroyContext (s->al_ctx); - s->al_ctx = NULL; - if (s->al_dev) - alcCloseDevice (s->al_dev); - s->al_dev = NULL; - for (i = 0; i < AL_BUFFERS; i++) { - s->al_Buffers[i] = 0; - } - xfree (s->al_bigbuffer); - s->al_bigbuffer = NULL; + struct sound_dp *s = sd->data; + int i; + + alDeleteSources (1, &s->al_Source); + s->al_Source = 0; + alDeleteBuffers (AL_BUFFERS, s->al_Buffers); + alcMakeContextCurrent (NULL); + if (s->al_ctx) + alcDestroyContext (s->al_ctx); + s->al_ctx = NULL; + if (s->al_dev) + alcCloseDevice (s->al_dev); + s->al_dev = NULL; + for (i = 0; i < AL_BUFFERS; i++) { + s->al_Buffers[i] = 0; + } + xfree (s->al_bigbuffer); + s->al_bigbuffer = NULL; } static int open_audio_al (struct sound_data *sd, int index) { - struct sound_dp *s = sd->data; - int freq = sd->freq; - int ch = sd->channels; - char *name; - int size; - - size = sd->sndbufsize; - sd->devicetype = SOUND_DEVICE_AL; - size *= ch * 2; - sd->sndbufsize = size / 8; - if (sd->sndbufsize > SND_MAX_BUFFER) - sd->sndbufsize = SND_MAX_BUFFER; - s->al_bufsize = size; - s->al_bigbuffer = xcalloc (s->al_bufsize, 1); - name = ua (sound_devices[index].alname); - s->al_dev = alcOpenDevice (name); - xfree (name); - if (!s->al_dev) - goto error; - s->al_ctx = alcCreateContext (s->al_dev, NULL); - if (!s->al_ctx) - goto error; - alcMakeContextCurrent (s->al_ctx); - alGenBuffers (AL_BUFFERS, s->al_Buffers); - alGenSources (1, &s->al_Source); - s->al_toggle = 0; - s->al_format = 0; - switch (ch) - { + struct sound_dp *s = sd->data; + int freq = sd->freq; + int ch = sd->channels; + char *name; + int size; + + size = sd->sndbufsize; + sd->devicetype = SOUND_DEVICE_AL; + size *= ch * 2; + sd->sndbufsize = size / 8; + if (sd->sndbufsize > SND_MAX_BUFFER) + sd->sndbufsize = SND_MAX_BUFFER; + s->al_bufsize = size; + s->al_bigbuffer = xcalloc (s->al_bufsize, 1); + name = ua (sound_devices[index].alname); + s->al_dev = alcOpenDevice (name); + xfree (name); + if (!s->al_dev) + goto error; + s->al_ctx = alcCreateContext (s->al_dev, NULL); + if (!s->al_ctx) + goto error; + alcMakeContextCurrent (s->al_ctx); + alGenBuffers (AL_BUFFERS, s->al_Buffers); + alGenSources (1, &s->al_Source); + s->al_toggle = 0; + s->al_format = 0; + switch (ch) + { case 1: - s->al_format = AL_FORMAT_MONO16; - break; + s->al_format = AL_FORMAT_MONO16; + break; case 2: - s->al_format = AL_FORMAT_STEREO16; - break; + s->al_format = AL_FORMAT_STEREO16; + break; case 4: - s->al_format = alGetEnumValue ("AL_FORMAT_QUAD16"); - break; + s->al_format = alGetEnumValue ("AL_FORMAT_QUAD16"); + break; case 6: - s->al_format = alGetEnumValue ("AL_FORMAT_51CHN16"); - break; - } - if (s->al_format == 0) - goto error; + s->al_format = alGetEnumValue ("AL_FORMAT_51CHN16"); + break; + } + if (s->al_format == 0) + goto error; - write_log (L"ALSOUND: %08X,CH=%d,FREQ=%d '%s' buffer %d (%d)\n", - s->al_format, ch, freq, sound_devices[index].alname, - sd->sndbufsize, s->al_bufsize); - return 1; + write_log (L"ALSOUND: %08X,CH=%d,FREQ=%d '%s' buffer %d (%d)\n", + s->al_format, ch, freq, sound_devices[index].alname, + sd->sndbufsize, s->al_bufsize); + return 1; error: - close_audio_al (sd); - return 0; + close_audio_al (sd); + return 0; } static void close_audio_wasapi (struct sound_data *sd) { - struct sound_dp *s = sd->data; + struct sound_dp *s = sd->data; - if (s->pRenderClient) - s->pRenderClient->lpVtbl->Release (s->pRenderClient); + if (s->pRenderClient) + s->pRenderClient->lpVtbl->Release (s->pRenderClient); #if 0 - if (s->pAudioClock) - s->pAudioClock->lpVtbl->Release (s->pAudioClock); + if (s->pAudioClock) + s->pAudioClock->lpVtbl->Release (s->pAudioClock); #endif - if (s->pAudioClient) - s->pAudioClient->lpVtbl->Release (s->pAudioClient); - if (s->pDevice) - s->pDevice->lpVtbl->Release (s->pDevice); - if (s->pEnumerator) - s->pEnumerator->lpVtbl->Release (s->pEnumerator); + if (s->pAudioClient) + s->pAudioClient->lpVtbl->Release (s->pAudioClient); + if (s->pDevice) + s->pDevice->lpVtbl->Release (s->pDevice); + if (s->pEnumerator) + s->pEnumerator->lpVtbl->Release (s->pEnumerator); } const static GUID XIID_IAudioClient = {0x1CB9AD4C,0xDBFA,0x4c32,{0xB1,0x78,0xC2,0xF5,0x68,0xA7,0x03,0xB2}}; @@ -692,579 +701,579 @@ const static GUID XIID_IAudioClock = {0xCD63314F,0x3FBA,0x4a1b,{0x81,0x2C,0xEF,0 static int open_audio_wasapi (struct sound_data *sd, int index, int exclusive) { - HRESULT hr; - struct sound_dp *s = sd->data; - WAVEFORMATEX *pwfx, *pwfx_saved; - WAVEFORMATEXTENSIBLE wavfmt; - int final; - LPWSTR name = NULL; - int rn[4], rncnt; - AUDCLNT_SHAREMODE sharemode; - int size, v; - - sd->devicetype = SOUND_DEVICE_WASAPI; - s->wasapiexclusive = exclusive; - - if (s->wasapiexclusive) - sharemode = AUDCLNT_SHAREMODE_EXCLUSIVE; - else - sharemode = AUDCLNT_SHAREMODE_SHARED; - - hr = CoCreateInstance (&XCLSID_MMDeviceEnumerator, NULL, - CLSCTX_ALL, &XIID_IMMDeviceEnumerator, - (void**)&s->pEnumerator); - if (FAILED (hr)) { - write_log (L"WASAPI: %d\n", hr); - goto error; - } - - if (sound_devices[index].alname == NULL) - hr = s->pEnumerator->lpVtbl->GetDefaultAudioEndpoint (s->pEnumerator, eRender, eMultimedia, &s->pDevice); - else - hr = s->pEnumerator->lpVtbl->GetDevice (s->pEnumerator, sound_devices[index].alname, &s->pDevice); - if (FAILED (hr)) { - write_log (L"WASAPI: GetDevice(%s) %08X\n", sound_devices[index].alname ? sound_devices[index].alname : L"NULL", hr); - goto error; - } - - hr = s->pDevice->lpVtbl->GetId (s->pDevice, &name); - if (FAILED (hr)) { - write_log (L"WASAPI: GetId() %08X\n", hr); - goto error; - } - - hr = s->pDevice->lpVtbl->Activate (s->pDevice, &XIID_IAudioClient, CLSCTX_ALL, NULL, (void**)&s->pAudioClient); - if (FAILED (hr)) { - write_log (L"WASAPI: Activate() %d\n", hr); - goto error; - } - - hr = s->pAudioClient->lpVtbl->GetMixFormat (s->pAudioClient, &pwfx); - if (FAILED (hr)) { - write_log (L"WASAPI: GetMixFormat() %08X\n", hr); - goto error; - } - - hr = s->pAudioClient->lpVtbl->GetDevicePeriod (s->pAudioClient, NULL, &s->hnsRequestedDuration); - if (FAILED (hr)) { - write_log (L"WASAPI: GetDevicePeriod() %08X\n", hr); - goto error; - } - - final = 0; - rncnt = 0; - pwfx_saved = NULL; - for (;;) { - - if (sd->channels == 6) { - rn[0] = KSAUDIO_SPEAKER_5POINT1; - rn[1] = KSAUDIO_SPEAKER_5POINT1_SURROUND; - rn[2] = 0; - } else if (sd->channels == 4) { - rn[0] = KSAUDIO_SPEAKER_QUAD; - rn[1] = KSAUDIO_SPEAKER_QUAD_SURROUND; - rn[2] = KSAUDIO_SPEAKER_SURROUND; - rn[3] = 0; - } else if (sd->channels == 2) { - rn[0] = KSAUDIO_SPEAKER_STEREO; - rn[1] = 0; - } else { - rn[0] = KSAUDIO_SPEAKER_MONO; - rn[1] = 0; + HRESULT hr; + struct sound_dp *s = sd->data; + WAVEFORMATEX *pwfx, *pwfx_saved; + WAVEFORMATEXTENSIBLE wavfmt; + int final; + LPWSTR name = NULL; + int rn[4], rncnt; + AUDCLNT_SHAREMODE sharemode; + int size, v; + + sd->devicetype = SOUND_DEVICE_WASAPI; + s->wasapiexclusive = exclusive; + + if (s->wasapiexclusive) + sharemode = AUDCLNT_SHAREMODE_EXCLUSIVE; + else + sharemode = AUDCLNT_SHAREMODE_SHARED; + + hr = CoCreateInstance (&XCLSID_MMDeviceEnumerator, NULL, + CLSCTX_ALL, &XIID_IMMDeviceEnumerator, + (void**)&s->pEnumerator); + if (FAILED (hr)) { + write_log (L"WASAPI: %d\n", hr); + goto error; } - memset (&wavfmt, 0, sizeof wavfmt); - wavfmt.Format.nChannels = sd->channels; - wavfmt.Format.nSamplesPerSec = sd->freq; - wavfmt.Format.wBitsPerSample = 16; - wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; - wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); - wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - wavfmt.Samples.wValidBitsPerSample = 16; - wavfmt.dwChannelMask = rn[rncnt]; - wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; - wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; - CoTaskMemFree (pwfx); - pwfx = NULL; - hr = s->pAudioClient->lpVtbl->IsFormatSupported (s->pAudioClient, sharemode, &wavfmt.Format, &pwfx); - if (SUCCEEDED (hr) && hr != S_FALSE) - break; - write_log (L"WASAPI: IsFormatSupported(%d,%08X,%d) (%d,%d) %08X\n", - sd->channels, rn[rncnt], sd->freq, - pwfx ? pwfx->nChannels : -1, pwfx ? pwfx->nSamplesPerSec : -1, - hr); - if (final && SUCCEEDED (hr)) { - if (pwfx_saved) { + if (sound_devices[index].alname == NULL) + hr = s->pEnumerator->lpVtbl->GetDefaultAudioEndpoint (s->pEnumerator, eRender, eMultimedia, &s->pDevice); + else + hr = s->pEnumerator->lpVtbl->GetDevice (s->pEnumerator, sound_devices[index].alname, &s->pDevice); + if (FAILED (hr)) { + write_log (L"WASAPI: GetDevice(%s) %08X\n", sound_devices[index].alname ? sound_devices[index].alname : L"NULL", hr); + goto error; + } + + hr = s->pDevice->lpVtbl->GetId (s->pDevice, &name); + if (FAILED (hr)) { + write_log (L"WASAPI: GetId() %08X\n", hr); + goto error; + } + + hr = s->pDevice->lpVtbl->Activate (s->pDevice, &XIID_IAudioClient, CLSCTX_ALL, NULL, (void**)&s->pAudioClient); + if (FAILED (hr)) { + write_log (L"WASAPI: Activate() %d\n", hr); + goto error; + } + + hr = s->pAudioClient->lpVtbl->GetMixFormat (s->pAudioClient, &pwfx); + if (FAILED (hr)) { + write_log (L"WASAPI: GetMixFormat() %08X\n", hr); + goto error; + } + + hr = s->pAudioClient->lpVtbl->GetDevicePeriod (s->pAudioClient, NULL, &s->hnsRequestedDuration); + if (FAILED (hr)) { + write_log (L"WASAPI: GetDevicePeriod() %08X\n", hr); + goto error; + } + + final = 0; + rncnt = 0; + pwfx_saved = NULL; + for (;;) { + + if (sd->channels == 6) { + rn[0] = KSAUDIO_SPEAKER_5POINT1; + rn[1] = KSAUDIO_SPEAKER_5POINT1_SURROUND; + rn[2] = 0; + } else if (sd->channels == 4) { + rn[0] = KSAUDIO_SPEAKER_QUAD; + rn[1] = KSAUDIO_SPEAKER_QUAD_SURROUND; + rn[2] = KSAUDIO_SPEAKER_SURROUND; + rn[3] = 0; + } else if (sd->channels == 2) { + rn[0] = KSAUDIO_SPEAKER_STEREO; + rn[1] = 0; + } else { + rn[0] = KSAUDIO_SPEAKER_MONO; + rn[1] = 0; + } + + memset (&wavfmt, 0, sizeof wavfmt); + wavfmt.Format.nChannels = sd->channels; + wavfmt.Format.nSamplesPerSec = sd->freq; + wavfmt.Format.wBitsPerSample = 16; + wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); + wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + wavfmt.Samples.wValidBitsPerSample = 16; + wavfmt.dwChannelMask = rn[rncnt]; + wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; + wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; + CoTaskMemFree (pwfx); + pwfx = NULL; + hr = s->pAudioClient->lpVtbl->IsFormatSupported (s->pAudioClient, sharemode, &wavfmt.Format, &pwfx); + if (SUCCEEDED (hr) && hr != S_FALSE) + break; + write_log (L"WASAPI: IsFormatSupported(%d,%08X,%d) (%d,%d) %08X\n", + sd->channels, rn[rncnt], sd->freq, + pwfx ? pwfx->nChannels : -1, pwfx ? pwfx->nSamplesPerSec : -1, + hr); + if (final && SUCCEEDED (hr)) { + if (pwfx_saved) { + sd->channels = pwfx_saved->nChannels; + sd->freq = pwfx_saved->nSamplesPerSec; + CoTaskMemFree (pwfx); + pwfx = pwfx_saved; + pwfx_saved = NULL; + } + break; + } + if (hr != AUDCLNT_E_UNSUPPORTED_FORMAT && hr != S_FALSE) + goto error; + if (hr == S_FALSE && pwfx_saved == NULL) { + pwfx_saved = pwfx; + pwfx = NULL; + } + rncnt++; + if (rn[rncnt]) + continue; + if (final) + goto error; + rncnt = 0; + if (sd->freq < 44100) { + sd->freq = 44100; + continue; + } + if (sd->freq < 48000) { + sd->freq = 48000; + continue; + } + if (sd->channels != 2) { + sd->channels = 2; + continue; + } + final = 1; + if (pwfx_saved == NULL) + goto error; sd->channels = pwfx_saved->nChannels; sd->freq = pwfx_saved->nSamplesPerSec; - CoTaskMemFree (pwfx); - pwfx = pwfx_saved; - pwfx_saved = NULL; - } - break; - } - if (hr != AUDCLNT_E_UNSUPPORTED_FORMAT && hr != S_FALSE) - goto error; - if (hr == S_FALSE && pwfx_saved == NULL) { - pwfx_saved = pwfx; - pwfx = NULL; - } - rncnt++; - if (rn[rncnt]) - continue; - if (final) - goto error; - rncnt = 0; - if (sd->freq < 44100) { - sd->freq = 44100; - continue; - } - if (sd->freq < 48000) { - sd->freq = 48000; - continue; - } - if (sd->channels != 2) { - sd->channels = 2; - continue; - } - final = 1; - if (pwfx_saved == NULL) - goto error; - sd->channels = pwfx_saved->nChannels; - sd->freq = pwfx_saved->nSamplesPerSec; - } - - size = sd->sndbufsize * sd->channels * 16 / 8; - s->snd_configsize = size; - sd->sndbufsize = size / 32; - size /= (sd->channels * 16 / 8); - - s->bufferFrameCount = (UINT32)( // frames = - 1.0 * s->hnsRequestedDuration * // hns * - wavfmt.Format.nSamplesPerSec / // (frames / s) / - 1000 / // (ms / s) / - 10000 // (hns / s) / - + 0.5); // rounding - - if (s->bufferFrameCount < size) { - s->bufferFrameCount = size; - s->hnsRequestedDuration = // hns = - (REFERENCE_TIME)( - 10000.0 * // (hns / ms) * - 1000 * // (ms / s) * - s->bufferFrameCount / // frames / - wavfmt.Format.nSamplesPerSec // (frames / s) - + 0.5 // rounding - ); - } - - hr = s->pAudioClient->lpVtbl->Initialize (s->pAudioClient, - sharemode, AUDCLNT_STREAMFLAGS_NOPERSIST, - s->hnsRequestedDuration, s->wasapiexclusive ? s->hnsRequestedDuration : 0, pwfx ? pwfx : &wavfmt.Format, NULL); - if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { + } + + size = sd->sndbufsize * sd->channels * 16 / 8; + s->snd_configsize = size; + sd->sndbufsize = size / 32; + size /= (sd->channels * 16 / 8); + + s->bufferFrameCount = (UINT32)( // frames = + 1.0 * s->hnsRequestedDuration * // hns * + wavfmt.Format.nSamplesPerSec / // (frames / s) / + 1000 / // (ms / s) / + 10000 // (hns / s) / + + 0.5); // rounding + + if (s->bufferFrameCount < size) { + s->bufferFrameCount = size; + s->hnsRequestedDuration = // hns = + (REFERENCE_TIME)( + 10000.0 * // (hns / ms) * + 1000 * // (ms / s) * + s->bufferFrameCount / // frames / + wavfmt.Format.nSamplesPerSec // (frames / s) + + 0.5 // rounding + ); + } + + hr = s->pAudioClient->lpVtbl->Initialize (s->pAudioClient, + sharemode, AUDCLNT_STREAMFLAGS_NOPERSIST, + s->hnsRequestedDuration, s->wasapiexclusive ? s->hnsRequestedDuration : 0, pwfx ? pwfx : &wavfmt.Format, NULL); + if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { + hr = s->pAudioClient->lpVtbl->GetBufferSize (s->pAudioClient, &s->bufferFrameCount); + if (FAILED (hr)) { + write_log (L"WASAPI: GetBufferSize() %08X\n", hr); + goto error; + } + s->pAudioClient->lpVtbl->Release (s->pAudioClient); + s->hnsRequestedDuration = // hns = + (REFERENCE_TIME)( + 10000.0 * // (hns / ms) * + 1000 * // (ms / s) * + s->bufferFrameCount / // frames / + wavfmt.Format.nSamplesPerSec // (frames / s) + + 0.5 // rounding + ); + s->hnsRequestedDuration *= sd->sndbufsize / 512; + hr = s->pDevice->lpVtbl->Activate (s->pDevice, &XIID_IAudioClient, CLSCTX_ALL, NULL, (void**)&s->pAudioClient); + if (FAILED (hr)) { + write_log (L"WASAPI: Activate() %08X\n", hr); + goto error; + } + hr = s->pAudioClient->lpVtbl->Initialize (s->pAudioClient, + sharemode, AUDCLNT_STREAMFLAGS_NOPERSIST, + s->hnsRequestedDuration, s->wasapiexclusive ? s->hnsRequestedDuration : 0, pwfx ? pwfx : &wavfmt.Format, NULL); + } + if (FAILED (hr)) { + write_log (L"WASAPI: Initialize() %08X\n", hr); + goto error; + } + hr = s->pAudioClient->lpVtbl->GetBufferSize (s->pAudioClient, &s->bufferFrameCount); if (FAILED (hr)) { - write_log (L"WASAPI: GetBufferSize() %08X\n", hr); - goto error; + write_log (L"WASAPI: GetBufferSize() %08X\n", hr); + goto error; } - s->pAudioClient->lpVtbl->Release (s->pAudioClient); + s->hnsRequestedDuration = // hns = - (REFERENCE_TIME)( - 10000.0 * // (hns / ms) * - 1000 * // (ms / s) * - s->bufferFrameCount / // frames / - wavfmt.Format.nSamplesPerSec // (frames / s) - + 0.5 // rounding - ); - s->hnsRequestedDuration *= sd->sndbufsize / 512; - hr = s->pDevice->lpVtbl->Activate (s->pDevice, &XIID_IAudioClient, CLSCTX_ALL, NULL, (void**)&s->pAudioClient); + (REFERENCE_TIME)( + 10000.0 * // (hns / ms) * + 1000 * // (ms / s) * + s->bufferFrameCount / // frames / + wavfmt.Format.nSamplesPerSec // (frames / s) + + 0.5 // rounding + ); + + hr = s->pAudioClient->lpVtbl->GetService (s->pAudioClient, &XIID_IAudioRenderClient, (void**)&s->pRenderClient); if (FAILED (hr)) { - write_log (L"WASAPI: Activate() %08X\n", hr); - goto error; + write_log (L"WASAPI: GetService(IID_IAudioRenderClient) %08X\n", hr); + goto error; } - hr = s->pAudioClient->lpVtbl->Initialize (s->pAudioClient, - sharemode, AUDCLNT_STREAMFLAGS_NOPERSIST, - s->hnsRequestedDuration, s->wasapiexclusive ? s->hnsRequestedDuration : 0, pwfx ? pwfx : &wavfmt.Format, NULL); - } - if (FAILED (hr)) { - write_log (L"WASAPI: Initialize() %08X\n", hr); - goto error; - } - - hr = s->pAudioClient->lpVtbl->GetBufferSize (s->pAudioClient, &s->bufferFrameCount); - if (FAILED (hr)) { - write_log (L"WASAPI: GetBufferSize() %08X\n", hr); - goto error; - } - - s->hnsRequestedDuration = // hns = - (REFERENCE_TIME)( - 10000.0 * // (hns / ms) * - 1000 * // (ms / s) * - s->bufferFrameCount / // frames / - wavfmt.Format.nSamplesPerSec // (frames / s) - + 0.5 // rounding - ); - - hr = s->pAudioClient->lpVtbl->GetService (s->pAudioClient, &XIID_IAudioRenderClient, (void**)&s->pRenderClient); - if (FAILED (hr)) { - write_log (L"WASAPI: GetService(IID_IAudioRenderClient) %08X\n", hr); - goto error; - } #if 0 - hr = s->pAudioClient->lpVtbl->GetService (s->pAudioClient, &XIID_IAudioClock, (void**)&s->pAudioClock); - if (FAILED (hr)) { - write_log (L"WASAPI: GetService(IID_IAudioClock) %08X\n", hr); - } else { - hr = s->pAudioClock->lpVtbl->GetFrequency (s->pAudioClock, &s->wasapiclock); + hr = s->pAudioClient->lpVtbl->GetService (s->pAudioClient, &XIID_IAudioClock, (void**)&s->pAudioClock); if (FAILED (hr)) { - write_log (L"WASAPI: GetFrequency() %08X\n", hr); + write_log (L"WASAPI: GetService(IID_IAudioClock) %08X\n", hr); + } else { + hr = s->pAudioClock->lpVtbl->GetFrequency (s->pAudioClock, &s->wasapiclock); + if (FAILED (hr)) { + write_log (L"WASAPI: GetFrequency() %08X\n", hr); + } } - } #endif - v = s->bufferFrameCount * sd->channels * 16 / 8; - v /= 2; - if (sd->sndbufsize > v) - sd->sndbufsize = v; - s->wasapigoodsize =s->bufferFrameCount / 2; - s->sndbufframes = sd->sndbufsize / (sd->channels * 16 / 8); + v = s->bufferFrameCount * sd->channels * 16 / 8; + v /= 2; + if (sd->sndbufsize > v) + sd->sndbufsize = v; + s->wasapigoodsize =s->bufferFrameCount / 2; + s->sndbufframes = sd->sndbufsize / (sd->channels * 16 / 8); - write_log(L"WASAPI: '%s'\nWASAPI: EX=%d CH=%d FREQ=%d BUF=%d (%d)\n", - name, s->wasapiexclusive, sd->channels, sd->freq, sd->sndbufsize, s->bufferFrameCount); + write_log(L"WASAPI: '%s'\nWASAPI: EX=%d CH=%d FREQ=%d BUF=%d (%d)\n", + name, s->wasapiexclusive, sd->channels, sd->freq, sd->sndbufsize, s->bufferFrameCount); - CoTaskMemFree (pwfx); - CoTaskMemFree (pwfx_saved); - CoTaskMemFree (name); + CoTaskMemFree (pwfx); + CoTaskMemFree (pwfx_saved); + CoTaskMemFree (name); - return 1; + return 1; error: - CoTaskMemFree (pwfx); - CoTaskMemFree (pwfx_saved); - CoTaskMemFree (name); - close_audio_wasapi (sd); - return 0; + CoTaskMemFree (pwfx); + CoTaskMemFree (pwfx_saved); + CoTaskMemFree (name); + close_audio_wasapi (sd); + return 0; } static int open_audio_ds (struct sound_data *sd, int index) { - struct sound_dp *s = sd->data; - HRESULT hr; - DSBUFFERDESC sound_buffer; - DSCAPS DSCaps; - WAVEFORMATEXTENSIBLE wavfmt; - LPDIRECTSOUNDBUFFER pdsb; - int freq = sd->freq; - int ch = sd->channels; - int round, i; - DWORD speakerconfig; - int size; - - sd->devicetype = SOUND_DEVICE_DS; - size = sd->sndbufsize * ch * 2; - s->snd_configsize = size; - sd->sndbufsize = size / 32; - if (sd->sndbufsize > SND_MAX_BUFFER) - sd->sndbufsize = SND_MAX_BUFFER; - - s->max_sndbufsize = size * 4; - if (s->max_sndbufsize > SND_MAX_BUFFER2) - s->max_sndbufsize = SND_MAX_BUFFER2; - s->dsoundbuf = s->max_sndbufsize * 2; - - if (s->dsoundbuf < DSBSIZE_MIN) - s->dsoundbuf = DSBSIZE_MIN; - if (s->dsoundbuf > DSBSIZE_MAX) - s->dsoundbuf = DSBSIZE_MAX; - - if (s->max_sndbufsize * 2 > s->dsoundbuf) - s->max_sndbufsize = s->dsoundbuf / 2; - sd->samplesize = sd->channels * 2; - - recalc_offsets (sd); - - hr = DirectSoundCreate8 (&sound_devices[index].guid, &s->lpDS, NULL); - if (FAILED (hr)) { - write_log (L"DSSOUND: DirectSoundCreate8() failure: %s\n", DXError (hr)); - return 0; - } - - hr = IDirectSound_SetCooperativeLevel (s->lpDS, hMainWnd, DSSCL_PRIORITY); - if (FAILED (hr)) { - write_log (L"DSSOUND: Can't set cooperativelevel: %s\n", DXError (hr)); - goto error; - } - - memset (&DSCaps, 0, sizeof (DSCaps)); - DSCaps.dwSize = sizeof (DSCaps); - hr = IDirectSound_GetCaps (s->lpDS, &DSCaps); - if (FAILED(hr)) { - write_log (L"DSSOUND: Error getting DirectSound capabilities: %s\n", DXError (hr)); - goto error; - } - if (DSCaps.dwFlags & DSCAPS_EMULDRIVER) { - write_log (L"DSSOUND: Emulated DirectSound driver detected, don't complain if sound quality is crap :)\n"); - } - if (DSCaps.dwFlags & DSCAPS_CONTINUOUSRATE) { - int minfreq = DSCaps.dwMinSecondarySampleRate; - int maxfreq = DSCaps.dwMaxSecondarySampleRate; - if (minfreq > freq && freq < 22050) { - freq = minfreq; - sd->freq = freq; - write_log (L"DSSOUND: minimum supported frequency: %d\n", minfreq); - } - if (maxfreq < freq && freq > 44100) { - freq = maxfreq; - sd->freq = freq; - write_log (L"DSSOUND: maximum supported frequency: %d\n", maxfreq); - } - } - - speakerconfig = fillsupportedmodes (sd, freq, supportedmodes); - write_log (L"DSSOUND: %08X ", speakerconfig); - for (i = 0; supportedmodes[i].ch; i++) - write_log (L"%d:%08X ", supportedmodes[i].ch, supportedmodes[i].ksmode); - write_log (L"\n"); - - for (round = 0; supportedmodes[round].ch; round++) { - DWORD ksmode = 0; - - pdsb = NULL; - memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); - wavfmt.Format.nChannels = ch; - wavfmt.Format.nSamplesPerSec = freq; - wavfmt.Format.wBitsPerSample = 16; - if (supportedmodes[round].ch != ch) - continue; + struct sound_dp *s = sd->data; + HRESULT hr; + DSBUFFERDESC sound_buffer; + DSCAPS DSCaps; + WAVEFORMATEXTENSIBLE wavfmt; + LPDIRECTSOUNDBUFFER pdsb; + int freq = sd->freq; + int ch = sd->channels; + int round, i; + DWORD speakerconfig; + int size; + + sd->devicetype = SOUND_DEVICE_DS; + size = sd->sndbufsize * ch * 2; + s->snd_configsize = size; + sd->sndbufsize = size / 32; + if (sd->sndbufsize > SND_MAX_BUFFER) + sd->sndbufsize = SND_MAX_BUFFER; + + s->max_sndbufsize = size * 4; + if (s->max_sndbufsize > SND_MAX_BUFFER2) + s->max_sndbufsize = SND_MAX_BUFFER2; + s->dsoundbuf = s->max_sndbufsize * 2; + + if (s->dsoundbuf < DSBSIZE_MIN) + s->dsoundbuf = DSBSIZE_MIN; + if (s->dsoundbuf > DSBSIZE_MAX) + s->dsoundbuf = DSBSIZE_MAX; + + if (s->max_sndbufsize * 2 > s->dsoundbuf) + s->max_sndbufsize = s->dsoundbuf / 2; + sd->samplesize = sd->channels * 2; - if (ch <= 2) { - wavfmt.Format.wFormatTag = WAVE_FORMAT_PCM; - } else { - wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; - ksmode = supportedmodes[round].ksmode; - wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); - wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - wavfmt.Samples.wValidBitsPerSample = 16; - wavfmt.dwChannelMask = ksmode; - } - wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; - wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; - - write_log (L"DSSOUND: %08X,CH=%d,FREQ=%d '%s' buffer %d (%d), dist %d\n", - ksmode, ch, freq, sound_devices[index].name, - s->max_sndbufsize / sd->samplesize, s->max_sndbufsize, s->snd_configsize / sd->samplesize); - - memset (&sound_buffer, 0, sizeof (sound_buffer)); - sound_buffer.dwSize = sizeof (sound_buffer); - sound_buffer.dwBufferBytes = s->dsoundbuf; - sound_buffer.lpwfxFormat = &wavfmt.Format; - sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; - sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME | (ch >= 4 ? DSBCAPS_LOCHARDWARE : DSBCAPS_LOCSOFTWARE); - sound_buffer.guid3DAlgorithm = GUID_NULL; - - hr = IDirectSound_CreateSoundBuffer (s->lpDS, &sound_buffer, &pdsb, NULL); - if (SUCCEEDED (hr)) - break; - if (sound_buffer.dwFlags & DSBCAPS_LOCHARDWARE) { - HRESULT hr2 = hr; - sound_buffer.dwFlags &= ~DSBCAPS_LOCHARDWARE; - sound_buffer.dwFlags |= DSBCAPS_LOCSOFTWARE; - hr = IDirectSound_CreateSoundBuffer (s->lpDS, &sound_buffer, &pdsb, NULL); - if (SUCCEEDED(hr)) { - //write_log (L"DSSOUND: Couldn't use hardware buffer (switched to software): %s\n", DXError (hr2)); - break; - } + recalc_offsets (sd); + + hr = DirectSoundCreate8 (&sound_devices[index].guid, &s->lpDS, NULL); + if (FAILED (hr)) { + write_log (L"DSSOUND: DirectSoundCreate8() failure: %s\n", DXError (hr)); + return 0; } - write_log (L"DSSOUND: Secondary CreateSoundBuffer() failure: %s\n", DXError (hr)); - } - if (pdsb == NULL) - goto error; - hr = IDirectSound_QueryInterface (pdsb, &IID_IDirectSoundBuffer8, (LPVOID*)&s->lpDSBsecondary); - if (FAILED (hr)) { - write_log (L"DSSOUND: Secondary QueryInterface() failure: %s\n", DXError (hr)); - goto error; - } - IDirectSound_Release (pdsb); - clearbuffer (sd); + hr = IDirectSound_SetCooperativeLevel (s->lpDS, hMainWnd, DSSCL_PRIORITY); + if (FAILED (hr)) { + write_log (L"DSSOUND: Can't set cooperativelevel: %s\n", DXError (hr)); + goto error; + } - return 1; + memset (&DSCaps, 0, sizeof (DSCaps)); + DSCaps.dwSize = sizeof (DSCaps); + hr = IDirectSound_GetCaps (s->lpDS, &DSCaps); + if (FAILED(hr)) { + write_log (L"DSSOUND: Error getting DirectSound capabilities: %s\n", DXError (hr)); + goto error; + } + if (DSCaps.dwFlags & DSCAPS_EMULDRIVER) { + write_log (L"DSSOUND: Emulated DirectSound driver detected, don't complain if sound quality is crap :)\n"); + } + if (DSCaps.dwFlags & DSCAPS_CONTINUOUSRATE) { + int minfreq = DSCaps.dwMinSecondarySampleRate; + int maxfreq = DSCaps.dwMaxSecondarySampleRate; + if (minfreq > freq && freq < 22050) { + freq = minfreq; + sd->freq = freq; + write_log (L"DSSOUND: minimum supported frequency: %d\n", minfreq); + } + if (maxfreq < freq && freq > 44100) { + freq = maxfreq; + sd->freq = freq; + write_log (L"DSSOUND: maximum supported frequency: %d\n", maxfreq); + } + } + + speakerconfig = fillsupportedmodes (sd, freq, supportedmodes); + write_log (L"DSSOUND: %08X ", speakerconfig); + for (i = 0; supportedmodes[i].ch; i++) + write_log (L"%d:%08X ", supportedmodes[i].ch, supportedmodes[i].ksmode); + write_log (L"\n"); + + for (round = 0; supportedmodes[round].ch; round++) { + DWORD ksmode = 0; + + pdsb = NULL; + memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); + wavfmt.Format.nChannels = ch; + wavfmt.Format.nSamplesPerSec = freq; + wavfmt.Format.wBitsPerSample = 16; + if (supportedmodes[round].ch != ch) + continue; + + if (ch <= 2) { + wavfmt.Format.wFormatTag = WAVE_FORMAT_PCM; + } else { + wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + ksmode = supportedmodes[round].ksmode; + wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); + wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + wavfmt.Samples.wValidBitsPerSample = 16; + wavfmt.dwChannelMask = ksmode; + } + wavfmt.Format.nBlockAlign = wavfmt.Format.wBitsPerSample / 8 * wavfmt.Format.nChannels; + wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; + + write_log (L"DSSOUND: %08X,CH=%d,FREQ=%d '%s' buffer %d (%d), dist %d\n", + ksmode, ch, freq, sound_devices[index].name, + s->max_sndbufsize / sd->samplesize, s->max_sndbufsize, s->snd_configsize / sd->samplesize); + + memset (&sound_buffer, 0, sizeof (sound_buffer)); + sound_buffer.dwSize = sizeof (sound_buffer); + sound_buffer.dwBufferBytes = s->dsoundbuf; + sound_buffer.lpwfxFormat = &wavfmt.Format; + sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; + sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME | (ch >= 4 ? DSBCAPS_LOCHARDWARE : DSBCAPS_LOCSOFTWARE); + sound_buffer.guid3DAlgorithm = GUID_NULL; + + hr = IDirectSound_CreateSoundBuffer (s->lpDS, &sound_buffer, &pdsb, NULL); + if (SUCCEEDED (hr)) + break; + if (sound_buffer.dwFlags & DSBCAPS_LOCHARDWARE) { + HRESULT hr2 = hr; + sound_buffer.dwFlags &= ~DSBCAPS_LOCHARDWARE; + sound_buffer.dwFlags |= DSBCAPS_LOCSOFTWARE; + hr = IDirectSound_CreateSoundBuffer (s->lpDS, &sound_buffer, &pdsb, NULL); + if (SUCCEEDED(hr)) { + //write_log (L"DSSOUND: Couldn't use hardware buffer (switched to software): %s\n", DXError (hr2)); + break; + } + } + write_log (L"DSSOUND: Secondary CreateSoundBuffer() failure: %s\n", DXError (hr)); + } + + if (pdsb == NULL) + goto error; + hr = IDirectSound_QueryInterface (pdsb, &IID_IDirectSoundBuffer8, (LPVOID*)&s->lpDSBsecondary); + if (FAILED (hr)) { + write_log (L"DSSOUND: Secondary QueryInterface() failure: %s\n", DXError (hr)); + goto error; + } + IDirectSound_Release (pdsb); + clearbuffer (sd); + + return 1; error: - close_audio_ds (sd); - return 0; + close_audio_ds (sd); + return 0; } int open_sound_device (struct sound_data *sd, int index, int exclusive, int bufsize, int freq, int channels) { - int ret = 0; - struct sound_dp *sdp = xcalloc (sizeof (struct sound_dp), 1); - sd->data = sdp; - sd->sndbufsize = bufsize; - sd->freq = freq; - sd->channels = channels; - sd->paused = 1; - if (sound_devices[index].type == SOUND_DEVICE_AL) - ret = open_audio_al (sd, index); - else if (sound_devices[index].type == SOUND_DEVICE_DS) - ret = open_audio_ds (sd, index); - else if (sound_devices[index].type == SOUND_DEVICE_PA) - ret = open_audio_pa (sd, index); - else if (sound_devices[index].type == SOUND_DEVICE_WASAPI) - ret = open_audio_wasapi (sd, index, exclusive); - sd->samplesize = sd->channels * 2; - return ret; + int ret = 0; + struct sound_dp *sdp = xcalloc (sizeof (struct sound_dp), 1); + sd->data = sdp; + sd->sndbufsize = bufsize; + sd->freq = freq; + sd->channels = channels; + sd->paused = 1; + if (sound_devices[index].type == SOUND_DEVICE_AL) + ret = open_audio_al (sd, index); + else if (sound_devices[index].type == SOUND_DEVICE_DS) + ret = open_audio_ds (sd, index); + else if (sound_devices[index].type == SOUND_DEVICE_PA) + ret = open_audio_pa (sd, index); + else if (sound_devices[index].type == SOUND_DEVICE_WASAPI) + ret = open_audio_wasapi (sd, index, exclusive); + sd->samplesize = sd->channels * 2; + return ret; } void close_sound_device (struct sound_data *sd) { - pause_sound_device (sd); - if (sd->devicetype == SOUND_DEVICE_AL) - close_audio_al (sd); - else if (sd->devicetype == SOUND_DEVICE_DS) - close_audio_ds (sd); - else if (sd->devicetype == SOUND_DEVICE_PA) - close_audio_pa (sd); - else if (sd->devicetype == SOUND_DEVICE_WASAPI) - close_audio_wasapi (sd); - xfree (sd->data); - sd->data = NULL; + pause_sound_device (sd); + if (sd->devicetype == SOUND_DEVICE_AL) + close_audio_al (sd); + else if (sd->devicetype == SOUND_DEVICE_DS) + close_audio_ds (sd); + else if (sd->devicetype == SOUND_DEVICE_PA) + close_audio_pa (sd); + else if (sd->devicetype == SOUND_DEVICE_WASAPI) + close_audio_wasapi (sd); + xfree (sd->data); + sd->data = NULL; } void pause_sound_device (struct sound_data *sd) { - sd->paused = 1; - if (sd->devicetype == SOUND_DEVICE_AL) - pause_audio_al (sd); - else if (sd->devicetype == SOUND_DEVICE_DS) - pause_audio_ds (sd); - else if (sd->devicetype == SOUND_DEVICE_PA) - pause_audio_pa (sd); - else if (sd->devicetype == SOUND_DEVICE_WASAPI) - pause_audio_wasapi (sd); + sd->paused = 1; + if (sd->devicetype == SOUND_DEVICE_AL) + pause_audio_al (sd); + else if (sd->devicetype == SOUND_DEVICE_DS) + pause_audio_ds (sd); + else if (sd->devicetype == SOUND_DEVICE_PA) + pause_audio_pa (sd); + else if (sd->devicetype == SOUND_DEVICE_WASAPI) + pause_audio_wasapi (sd); } void resume_sound_device (struct sound_data *sd) { - if (sd->devicetype == SOUND_DEVICE_AL) - resume_audio_al (sd); - else if (sd->devicetype == SOUND_DEVICE_DS) - resume_audio_ds (sd); - else if (sd->devicetype == SOUND_DEVICE_PA) - resume_audio_pa (sd); - else if (sd->devicetype == SOUND_DEVICE_WASAPI) - resume_audio_wasapi (sd); - sd->paused = 0; + if (sd->devicetype == SOUND_DEVICE_AL) + resume_audio_al (sd); + else if (sd->devicetype == SOUND_DEVICE_DS) + resume_audio_ds (sd); + else if (sd->devicetype == SOUND_DEVICE_PA) + resume_audio_pa (sd); + else if (sd->devicetype == SOUND_DEVICE_WASAPI) + resume_audio_wasapi (sd); + sd->paused = 0; } static int open_sound (void) { - int ret = 0, num, ch; - int size = currprefs.sound_maxbsiz; - - if (!currprefs.produce_sound) - return 0; - /* Always interpret buffer size as number of samples, not as actual - buffer size. Of course, since 8192 is the default, we'll have to - scale that to a sane value (assuming that otherwise 16 bits and - stereo would have been enabled and we'd have done the shift by - two anyway). */ - size >>= 2; - if (size & (size - 1)) - size = DEFAULT_SOUND_MAXB; - if (size < 512) - size = 512; - - num = enumerate_sound_devices (); - if (currprefs.win32_soundcard >= num) - currprefs.win32_soundcard = changed_prefs.win32_soundcard = 0; - ch = get_audio_nativechannels (currprefs.sound_stereo); - ret = open_sound_device (sdp, currprefs.win32_soundcard, currprefs.win32_soundexclusive, size, currprefs.sound_freq, ch); - if (!ret) - return 0; - currprefs.sound_freq = changed_prefs.sound_freq = sdp->freq; - if (ch != sdp->channels) - currprefs.sound_stereo = changed_prefs.sound_stereo = get_audio_stereomode (sdp->channels); - - set_volume (currprefs.sound_volume, sdp->mute); - if (get_audio_amigachannels (currprefs.sound_stereo) == 4) - sample_handler = sample16ss_handler; - else - sample_handler = get_audio_ismono (currprefs.sound_stereo) ? sample16_handler : sample16s_handler; + int ret = 0, num, ch; + int size = currprefs.sound_maxbsiz; + + if (!currprefs.produce_sound) + return 0; + /* Always interpret buffer size as number of samples, not as actual + buffer size. Of course, since 8192 is the default, we'll have to + scale that to a sane value (assuming that otherwise 16 bits and + stereo would have been enabled and we'd have done the shift by + two anyway). */ + size >>= 2; + if (size & (size - 1)) + size = DEFAULT_SOUND_MAXB; + if (size < 512) + size = 512; + + num = enumerate_sound_devices (); + if (currprefs.win32_soundcard >= num) + currprefs.win32_soundcard = changed_prefs.win32_soundcard = 0; + ch = get_audio_nativechannels (currprefs.sound_stereo); + ret = open_sound_device (sdp, currprefs.win32_soundcard, currprefs.win32_soundexclusive, size, currprefs.sound_freq, ch); + if (!ret) + return 0; + currprefs.sound_freq = changed_prefs.sound_freq = sdp->freq; + if (ch != sdp->channels) + currprefs.sound_stereo = changed_prefs.sound_stereo = get_audio_stereomode (sdp->channels); + + set_volume (currprefs.sound_volume, sdp->mute); + if (get_audio_amigachannels (currprefs.sound_stereo) == 4) + sample_handler = sample16ss_handler; + else + sample_handler = get_audio_ismono (currprefs.sound_stereo) ? sample16_handler : sample16s_handler; - sdp->obtainedfreq = currprefs.sound_freq; + sdp->obtainedfreq = currprefs.sound_freq; - have_sound = 1; - sound_available = 1; - update_sound (fake_vblank_hz, 1); - paula_sndbufsize = sdp->sndbufsize; - paula_sndbufpt = paula_sndbuffer; - driveclick_init (); + have_sound = 1; + sound_available = 1; + update_sound (fake_vblank_hz, 1, currprefs.ntscmode); + paula_sndbufsize = sdp->sndbufsize; + paula_sndbufpt = paula_sndbuffer; + driveclick_init (); - return 1; + return 1; } void close_sound (void) { - gui_data.sndbuf = 0; - gui_data.sndbuf_status = 3; - if (! have_sound) - return; - close_sound_device (sdp); - have_sound = 0; + gui_data.sndbuf = 0; + gui_data.sndbuf_status = 3; + if (! have_sound) + return; + close_sound_device (sdp); + have_sound = 0; } int init_sound (void) { - gui_data.sndbuf_status = 3; - gui_data.sndbuf = 0; - if (!sound_available) - return 0; - if (currprefs.produce_sound <= 1) - return 0; - if (have_sound) + gui_data.sndbuf_status = 3; + gui_data.sndbuf = 0; + if (!sound_available) + return 0; + if (currprefs.produce_sound <= 1) + return 0; + if (have_sound) + return 1; + if (!open_sound ()) + return 0; + sdp->paused = 1; + driveclick_reset (); + resume_sound (); return 1; - if (!open_sound ()) - return 0; - sdp->paused = 1; - driveclick_reset (); - resume_sound (); - return 1; } void pause_sound (void) { - if (sdp->paused) - return; - if (!have_sound) - return; - pause_sound_device (sdp); + if (sdp->paused) + return; + if (!have_sound) + return; + pause_sound_device (sdp); } void resume_sound (void) { - if (!sdp->paused) - return; - if (!have_sound) - return; - resume_sound_device (sdp); + if (!sdp->paused) + return; + if (!have_sound) + return; + resume_sound_device (sdp); } void reset_sound (void) { - if (!have_sound) - return; - clearbuffer (sdp); + if (!have_sound) + return; + clearbuffer (sdp); } static void disable_sound (void) { - close_sound (); - currprefs.produce_sound = changed_prefs.produce_sound = 1; + close_sound (); + currprefs.produce_sound = changed_prefs.produce_sound = 1; } static void reopen_sound (void) { - close_sound (); - open_sound (); + close_sound (); + open_sound (); } @@ -1281,24 +1290,24 @@ static int avioutput_audio; void sound_setadjust (double v) { - float mult; + float mult; - if (v >= -5 && v <= 5) - v = 0; + if (v >= -5 && v <= 5) + v = 0; - mult = (1000.0 + v); - if (avioutput_audio) - mult = 1000.0; - if (isvsync () || (avioutput_audio && !compiled_code)) { - vsynctime = vsynctime_orig; - scaled_sample_evtime = scaled_sample_evtime_orig * mult / 1000.0; - } else if (compiled_code || currprefs.m68k_speed != 0) { - vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); - scaled_sample_evtime = scaled_sample_evtime_orig; - } else { - vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); - scaled_sample_evtime = scaled_sample_evtime_orig; - } + mult = (1000.0 + v); + if (avioutput_audio) + mult = 1000.0; + if (isvsync () || (avioutput_audio && !compiled_code)) { + vsynctime = vsynctime_orig; + scaled_sample_evtime = scaled_sample_evtime_orig * mult / 1000.0; + } else if (compiled_code || currprefs.m68k_speed != 0) { + vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); + scaled_sample_evtime = scaled_sample_evtime_orig; + } else { + vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); + scaled_sample_evtime = scaled_sample_evtime_orig; + } } #define SND_STATUSCNT 10 @@ -1307,1067 +1316,1067 @@ void sound_setadjust (double v) static void restart_sound_buffer2 (struct sound_data *sd) { - struct sound_dp *s = sd->data; - DWORD playpos, safed; - HRESULT hr; - - if (sd->devicetype != SOUND_DEVICE_DS) - return; - if (sdp->waiting_for_buffer != -1) - return; - hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safed); - if (FAILED (hr)) { - write_log (L"DSSOUND: DirectSoundBuffer_GetCurrentPosition failed, %s\n", DXError (hr)); - return; - } - s->writepos = safed + s->snd_writeoffset; - if (s->writepos < 0) - s->writepos += s->dsoundbuf; - cf (s->writepos); + struct sound_dp *s = sd->data; + DWORD playpos, safed; + HRESULT hr; + + if (sd->devicetype != SOUND_DEVICE_DS) + return; + if (sdp->waiting_for_buffer != -1) + return; + hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safed); + if (FAILED (hr)) { + write_log (L"DSSOUND: DirectSoundBuffer_GetCurrentPosition failed, %s\n", DXError (hr)); + return; + } + s->writepos = safed + s->snd_writeoffset; + if (s->writepos < 0) + s->writepos += s->dsoundbuf; + cf (s->writepos); } void restart_sound_buffer (void) { - restart_sound_buffer2 (sdp); + restart_sound_buffer2 (sdp); } static int alcheck (struct sound_data *sd, int v) { - struct sound_dp *s = sd->data; - int err = alGetError (); - if (err != AL_NO_ERROR) { - int v1, v2, v3; - alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v1); - alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v2); - alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v3); - write_log (L"OpenAL %d: error %d. PROC=%d QUEUE=%d STATE=%d\n", v, err, v1, v2, v3); - write_log (L" %d %08x %08x %08x %d %d\n", - s->al_toggle, s->al_Buffers[s->al_toggle], s->al_format, s->al_bigbuffer, s->al_bufsize, sd->freq); - return 1; - } - return 0; + struct sound_dp *s = sd->data; + int err = alGetError (); + if (err != AL_NO_ERROR) { + int v1, v2, v3; + alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v1); + alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v2); + alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v3); + write_log (L"OpenAL %d: error %d. PROC=%d QUEUE=%d STATE=%d\n", v, err, v1, v2, v3); + write_log (L" %d %08x %08x %08x %d %d\n", + s->al_toggle, s->al_Buffers[s->al_toggle], s->al_format, s->al_bigbuffer, s->al_bufsize, sd->freq); + return 1; + } + return 0; } static void finish_sound_buffer_al (struct sound_data *sd, uae_u16 *sndbuffer) { - struct sound_dp *s = sd->data; - static int tfprev; - static int statuscnt; - int v, v2; - double m, skipmode; + struct sound_dp *s = sd->data; + static int tfprev; + static int statuscnt; + int v, v2; + double m, skipmode; - if (!sd->waiting_for_buffer) - return; - if (savestate_state) - return; + if (!sd->waiting_for_buffer) + return; + if (savestate_state) + return; - if (sd == sdp) { - if (statuscnt > 0) { - statuscnt--; - if (statuscnt == 0) - gui_data.sndbuf_status = 0; - } - if (gui_data.sndbuf_status == 3) - gui_data.sndbuf_status = 0; - } - alGetError (); - - memcpy (s->al_bigbuffer + s->al_offset, sndbuffer, sd->sndbufsize); - s->al_offset += sd->sndbufsize; - if (s->al_offset >= s->al_bufsize) { - ALuint tmp; - alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v); - while (v == 0 && sd->waiting_for_buffer < 0) { - sleep_millis (1); - alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); - if (v != AL_PLAYING) - break; - alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v); + if (sd == sdp) { + if (statuscnt > 0) { + statuscnt--; + if (statuscnt == 0) + gui_data.sndbuf_status = 0; + } + if (gui_data.sndbuf_status == 3) + gui_data.sndbuf_status = 0; } - - alSourceUnqueueBuffers (s->al_Source, 1, &tmp); alGetError (); -// write_log (L" %d %08x %08x %08x %d %d\n", -// al_toggle, al_Buffers[al_toggle], al_format, al_bigbuffer, al_bufsize, currprefs.sound_freq); - - alBufferData (s->al_Buffers[s->al_toggle], s->al_format, s->al_bigbuffer, s->al_bufsize, sd->freq); - alcheck (sd, 4); - alSourceQueueBuffers (s->al_Source, 1, &s->al_Buffers[s->al_toggle]); - alcheck (sd, 2); - s->al_toggle++; - if (s->al_toggle >= AL_BUFFERS) - s->al_toggle = 0; + memcpy (s->al_bigbuffer + s->al_offset, sndbuffer, sd->sndbufsize); + s->al_offset += sd->sndbufsize; + if (s->al_offset >= s->al_bufsize) { + ALuint tmp; + alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v); + while (v == 0 && sd->waiting_for_buffer < 0) { + sleep_millis (1); + alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); + if (v != AL_PLAYING) + break; + alGetSourcei (s->al_Source, AL_BUFFERS_PROCESSED, &v); + } - alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v2); - alcheck (sd, 5); - alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); - alcheck (sd, 3); - if (v != AL_PLAYING && v2 >= AL_BUFFERS) { - if (sd->waiting_for_buffer > 0) { - write_log (L"AL SOUND PLAY!\n"); - alSourcePlay (s->al_Source); - sd->waiting_for_buffer = -1; - tfprev = timeframes + 10; - tfprev = (tfprev / 10) * 10; - } else { - gui_data.sndbuf_status = 2; - statuscnt = SND_STATUSCNT; - write_log (L"AL underflow\n"); - clearbuffer (sd); - sd->waiting_for_buffer = 1; - } + alSourceUnqueueBuffers (s->al_Source, 1, &tmp); + alGetError (); + + // write_log (L" %d %08x %08x %08x %d %d\n", + // al_toggle, al_Buffers[al_toggle], al_format, al_bigbuffer, al_bufsize, currprefs.sound_freq); + + alBufferData (s->al_Buffers[s->al_toggle], s->al_format, s->al_bigbuffer, s->al_bufsize, sd->freq); + alcheck (sd, 4); + alSourceQueueBuffers (s->al_Source, 1, &s->al_Buffers[s->al_toggle]); + alcheck (sd, 2); + s->al_toggle++; + if (s->al_toggle >= AL_BUFFERS) + s->al_toggle = 0; + + alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v2); + alcheck (sd, 5); + alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); + alcheck (sd, 3); + if (v != AL_PLAYING && v2 >= AL_BUFFERS) { + if (sd->waiting_for_buffer > 0) { + write_log (L"AL SOUND PLAY!\n"); + alSourcePlay (s->al_Source); + sd->waiting_for_buffer = -1; + tfprev = timeframes + 10; + tfprev = (tfprev / 10) * 10; + } else { + gui_data.sndbuf_status = 2; + statuscnt = SND_STATUSCNT; + write_log (L"AL underflow\n"); + clearbuffer (sd); + sd->waiting_for_buffer = 1; + } + } + s->al_offset = 0; } - s->al_offset = 0; - } - alcheck (sd, 1); + alcheck (sd, 1); - alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); - alcheck (sd, 6); + alGetSourcei (s->al_Source, AL_SOURCE_STATE, &v); + alcheck (sd, 6); - if (v == AL_PLAYING && sd == sdp) { - alGetSourcei (s->al_Source, AL_BYTE_OFFSET, &v); - alcheck (sd, 7); - v -= s->al_offset; - gui_data.sndbuf = 100 * v / sd->sndbufsize; - m = gui_data.sndbuf / 100.0; + if (v == AL_PLAYING && sd == sdp) { + alGetSourcei (s->al_Source, AL_BYTE_OFFSET, &v); + alcheck (sd, 7); + v -= s->al_offset; + gui_data.sndbuf = 100 * v / sd->sndbufsize; + m = gui_data.sndbuf / 100.0; - if (isvsync ()) { + if (isvsync ()) { - skipmode = pow (m < 0 ? -m : m, EXP) / 8; - if (m < 0) - skipmode = -skipmode; - if (skipmode < -ADJUST_VSSIZE) - skipmode = -ADJUST_VSSIZE; - if (skipmode > ADJUST_VSSIZE) - skipmode = ADJUST_VSSIZE; + skipmode = pow (m < 0 ? -m : m, EXP) / 8; + if (m < 0) + skipmode = -skipmode; + if (skipmode < -ADJUST_VSSIZE) + skipmode = -ADJUST_VSSIZE; + if (skipmode > ADJUST_VSSIZE) + skipmode = ADJUST_VSSIZE; - } else { + } else { - skipmode = pow (m < 0 ? -m : m, EXP) / 2; - if (m < 0) - skipmode = -skipmode; - if (skipmode < -ADJUST_SIZE) - skipmode = -ADJUST_SIZE; - if (skipmode > ADJUST_SIZE) - skipmode = ADJUST_SIZE; + skipmode = pow (m < 0 ? -m : m, EXP) / 2; + if (m < 0) + skipmode = -skipmode; + if (skipmode < -ADJUST_SIZE) + skipmode = -ADJUST_SIZE; + if (skipmode > ADJUST_SIZE) + skipmode = ADJUST_SIZE; + } + if (tfprev != timeframes) { + if ((0 || sound_debug) && !(tfprev % 10)) + write_log (L"s=%+02.1f\n", skipmode); + tfprev = timeframes; + sound_setadjust (skipmode); + } } - if (tfprev != timeframes) { - if ((0 || sound_debug) && !(tfprev % 10)) - write_log (L"s=%+02.1f\n", skipmode); - tfprev = timeframes; - sound_setadjust (skipmode); - } - } - alcheck (sd, 0); + alcheck (sd, 0); } int blocking_sound_device (struct sound_data *sd) { - struct sound_dp *s = sd->data; - - if (sd->devicetype == SOUND_DEVICE_DS) { + struct sound_dp *s = sd->data; - HRESULT hr; - DWORD playpos, safepos; - int diff; - - hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safepos); - if (FAILED (hr)) { - restore_ds (sd, hr); - write_log (L"DSSOUND: GetCurrentPosition failed: %s\n", DXError (hr)); - return -1; - } - if (s->writepos >= safepos) - diff = s->writepos - safepos; - else - diff = s->dsoundbuf - safepos + s->writepos; - if (diff > s->snd_maxoffset) - return 1; - return 0; - - } else if (sd->devicetype == SOUND_DEVICE_AL) { - - int v = 0; - alGetError (); - alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v); - if (alGetError () != AL_NO_ERROR) - return -1; - if (v < AL_BUFFERS) - return 0; - return 1; + if (sd->devicetype == SOUND_DEVICE_DS) { - } else if (sd->devicetype == SOUND_DEVICE_WASAPI) { + HRESULT hr; + DWORD playpos, safepos; + int diff; -// if (WaitForSingleObject (s->wasapihandle, 0) == WAIT_TIMEOUT) -// return 0; - return 1; + hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safepos); + if (FAILED (hr)) { + restore_ds (sd, hr); + write_log (L"DSSOUND: GetCurrentPosition failed: %s\n", DXError (hr)); + return -1; + } + if (s->writepos >= safepos) + diff = s->writepos - safepos; + else + diff = s->dsoundbuf - safepos + s->writepos; + if (diff > s->snd_maxoffset) + return 1; + return 0; + + } else if (sd->devicetype == SOUND_DEVICE_AL) { + + int v = 0; + alGetError (); + alGetSourcei (s->al_Source, AL_BUFFERS_QUEUED, &v); + if (alGetError () != AL_NO_ERROR) + return -1; + if (v < AL_BUFFERS) + return 0; + return 1; + + } else if (sd->devicetype == SOUND_DEVICE_WASAPI) { + + // if (WaitForSingleObject (s->wasapihandle, 0) == WAIT_TIMEOUT) + // return 0; + return 1; - } - return -1; + } + return -1; } int get_offset_sound_device (struct sound_data *sd) { - struct sound_dp *s = sd->data; - - if (sd->devicetype == SOUND_DEVICE_DS) { - HRESULT hr; - DWORD playpos, safedist, status; - - hr = IDirectSoundBuffer_GetStatus (s->lpDSBsecondary, &status); - hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safedist); - if (FAILED (hr)) - return -1; - playpos -= s->writepos; - if (playpos < 0) - playpos += s->dsoundbuf; - return playpos; - } else if (sd->devicetype == SOUND_DEVICE_AL) { - int v; - alGetError (); - alGetSourcei (s->al_Source, AL_BYTE_OFFSET, &v); - if (alGetError () == AL_NO_ERROR) - return v; - } - return -1; + struct sound_dp *s = sd->data; + + if (sd->devicetype == SOUND_DEVICE_DS) { + HRESULT hr; + DWORD playpos, safedist, status; + + hr = IDirectSoundBuffer_GetStatus (s->lpDSBsecondary, &status); + hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safedist); + if (FAILED (hr)) + return -1; + playpos -= s->writepos; + if (playpos < 0) + playpos += s->dsoundbuf; + return playpos; + } else if (sd->devicetype == SOUND_DEVICE_AL) { + int v; + alGetError (); + alGetSourcei (s->al_Source, AL_BYTE_OFFSET, &v); + if (alGetError () == AL_NO_ERROR) + return v; + } + return -1; } static double sync_sound (double m) { - double skipmode; - if (isvsync ()) { - - skipmode = pow (m < 0 ? -m : m, EXP) / 10; - if (m < 0) - skipmode = -skipmode; - if (skipmode < -ADJUST_VSSIZE) - skipmode = -ADJUST_VSSIZE; - if (skipmode > ADJUST_VSSIZE) - skipmode = ADJUST_VSSIZE; - - } else if (1) { + double skipmode; + if (isvsync ()) { - skipmode = pow (m < 0 ? -m : m, EXP) / 2; - if (m < 0) - skipmode = -skipmode; - if (skipmode < -ADJUST_SIZE) - skipmode = -ADJUST_SIZE; - if (skipmode > ADJUST_SIZE) - skipmode = ADJUST_SIZE; - } + skipmode = pow (m < 0 ? -m : m, EXP) / 10; + if (m < 0) + skipmode = -skipmode; + if (skipmode < -ADJUST_VSSIZE) + skipmode = -ADJUST_VSSIZE; + if (skipmode > ADJUST_VSSIZE) + skipmode = ADJUST_VSSIZE; + + } else if (1) { + + skipmode = pow (m < 0 ? -m : m, EXP) / 2; + if (m < 0) + skipmode = -skipmode; + if (skipmode < -ADJUST_SIZE) + skipmode = -ADJUST_SIZE; + if (skipmode > ADJUST_SIZE) + skipmode = ADJUST_SIZE; + } - return skipmode; + return skipmode; } static void finish_sound_buffer_wasapi (struct sound_data *sd, uae_u16 *sndbuffer) { - struct sound_dp *s = sd->data; - HRESULT hr; - BYTE *pData; - DWORD v; - double skipmode; - int numFramesPadding, avail; - int stuck = 2000; - int oldpadding = 0; - - if (sd->paused) - return; - - s->framecounter++; - if (s->framecounter > 50) { - s->sndbuf = s->sndbuf / s->framecounter; - s->framecounter = 2; - } - - for (;;) { - hr = s->pAudioClient->lpVtbl->GetCurrentPadding (s->pAudioClient, &numFramesPadding); - if (FAILED (hr)) { - write_log (L"WASAPI: GetCurrentPadding() %08X\n", hr); - return; - } - avail = s->bufferFrameCount - numFramesPadding; - if (avail >= s->sndbufframes) - break; - gui_data.sndbuf_status = 1; - statuscnt = SND_STATUSCNT; - sleep_millis (1); - if (oldpadding == numFramesPadding) { - if (stuck-- < 0) { - write_log (L"WASAPI: sound stuck %d %d %d !?\n", s->bufferFrameCount, numFramesPadding, s->sndbufframes); - reopen_sound (); + struct sound_dp *s = sd->data; + HRESULT hr; + BYTE *pData; + DWORD v; + double skipmode; + int numFramesPadding, avail; + int stuck = 2000; + int oldpadding = 0; + + if (sd->paused) return; - } + + s->framecounter++; + if (s->framecounter > 50) { + s->sndbuf = s->sndbuf / s->framecounter; + s->framecounter = 2; + } + + for (;;) { + hr = s->pAudioClient->lpVtbl->GetCurrentPadding (s->pAudioClient, &numFramesPadding); + if (FAILED (hr)) { + write_log (L"WASAPI: GetCurrentPadding() %08X\n", hr); + return; + } + avail = s->bufferFrameCount - numFramesPadding; + if (avail >= s->sndbufframes) + break; + gui_data.sndbuf_status = 1; + statuscnt = SND_STATUSCNT; + sleep_millis (1); + if (oldpadding == numFramesPadding) { + if (stuck-- < 0) { + write_log (L"WASAPI: sound stuck %d %d %d !?\n", s->bufferFrameCount, numFramesPadding, s->sndbufframes); + reopen_sound (); + return; + } + } + oldpadding = numFramesPadding; + } + s->sndbuf += (s->wasapigoodsize - avail) * 1000 / s->wasapigoodsize; + gui_data.sndbuf = s->sndbuf / s->framecounter; + if (s->framecounter == 2) { + skipmode = sync_sound (gui_data.sndbuf / 70.0); + sound_setadjust (skipmode); + } + hr = s->pRenderClient->lpVtbl->GetBuffer (s->pRenderClient, s->sndbufframes, &pData); + if (SUCCEEDED (hr)) { + memcpy (pData, sndbuffer, sd->sndbufsize); + s->pRenderClient->lpVtbl->ReleaseBuffer (s->pRenderClient, s->sndbufframes, 0); } - oldpadding = numFramesPadding; - } - s->sndbuf += (s->wasapigoodsize - avail) * 1000 / s->wasapigoodsize; - gui_data.sndbuf = s->sndbuf / s->framecounter; - if (s->framecounter == 2) { - skipmode = sync_sound (gui_data.sndbuf / 70.0); - sound_setadjust (skipmode); - } - hr = s->pRenderClient->lpVtbl->GetBuffer (s->pRenderClient, s->sndbufframes, &pData); - if (SUCCEEDED (hr)) { - memcpy (pData, sndbuffer, sd->sndbufsize); - s->pRenderClient->lpVtbl->ReleaseBuffer (s->pRenderClient, s->sndbufframes, 0); - } } static void finish_sound_buffer_ds (struct sound_data *sd, uae_u16 *sndbuffer) { - struct sound_dp *s = sd->data; - static int tfprev; - DWORD playpos, safepos, status; - HRESULT hr; - void *b1, *b2; - DWORD s1, s2; - int diff; - int counter; + struct sound_dp *s = sd->data; + static int tfprev; + DWORD playpos, safepos, status; + HRESULT hr; + void *b1, *b2; + DWORD s1, s2; + int diff; + int counter; - if (!sd->waiting_for_buffer) - return; + if (!sd->waiting_for_buffer) + return; - if (sd->waiting_for_buffer == 1) { - hr = IDirectSoundBuffer_Play (s->lpDSBsecondary, 0, 0, DSBPLAY_LOOPING); - if (FAILED (hr)) { - write_log (L"DSSOUND: Play failed: %s\n", DXError (hr)); - restore_ds (sd, DSERR_BUFFERLOST); - sd->waiting_for_buffer = 0; - return; + if (sd->waiting_for_buffer == 1) { + hr = IDirectSoundBuffer_Play (s->lpDSBsecondary, 0, 0, DSBPLAY_LOOPING); + if (FAILED (hr)) { + write_log (L"DSSOUND: Play failed: %s\n", DXError (hr)); + restore_ds (sd, DSERR_BUFFERLOST); + sd->waiting_for_buffer = 0; + return; + } + hr = IDirectSoundBuffer_SetCurrentPosition (s->lpDSBsecondary, 0); + if (FAILED (hr)) { + write_log (L"DSSOUND: 1st SetCurrentPosition failed: %s\n", DXError (hr)); + restore_ds (sd, DSERR_BUFFERLOST); + sd->waiting_for_buffer = 0; + return; + } + /* there are crappy drivers that return PLAYCURSOR = WRITECURSOR = 0 without this.. */ + counter = 5000; + for (;;) { + hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &s->safedist); + if (playpos > 0) + break; + sleep_millis (1); + counter--; + if (counter < 0) { + write_log (L"DSSOUND: stuck?!?!\n"); + disable_sound (); + break; + } + } + write_log (L"DSSOUND: %d = (%d - %d)\n", (s->safedist - playpos) / sd->samplesize, s->safedist / sd->samplesize, playpos / sd->samplesize); + recalc_offsets (sd); + s->safedist -= playpos; + if (s->safedist < 64) + s->safedist = 64; + cf (s->safedist); +#if 0 + snd_totalmaxoffset_uf += s->safedist; + cf (snd_totalmaxoffset_uf); + snd_totalmaxoffset_of += s->safedist; + cf (snd_totalmaxoffset_of); + snd_maxoffset += s->safedist; + cf (snd_maxoffset); + snd_writeoffset += s->safedist; + cf (snd_writeoffset); +#endif + sd->waiting_for_buffer = -1; + restart_sound_buffer2 (sd); + write_log (L"DSSOUND: bs=%d w=%d max=%d tof=%d tuf=%d\n", + sd->sndbufsize / sd->samplesize, s->snd_writeoffset / sd->samplesize, + s->snd_maxoffset / sd->samplesize, s->snd_totalmaxoffset_of / sd->samplesize, + s->snd_totalmaxoffset_uf / sd->samplesize); + tfprev = timeframes + 10; + tfprev = (tfprev / 10) * 10; } - hr = IDirectSoundBuffer_SetCurrentPosition (s->lpDSBsecondary, 0); + + counter = 5000; + hr = IDirectSoundBuffer_GetStatus (s->lpDSBsecondary, &status); if (FAILED (hr)) { - write_log (L"DSSOUND: 1st SetCurrentPosition failed: %s\n", DXError (hr)); - restore_ds (sd, DSERR_BUFFERLOST); - sd->waiting_for_buffer = 0; - return; + write_log (L"DSSOUND: GetStatus() failed: %s\n", DXError (hr)); + restore_ds (sd, DSERR_BUFFERLOST); + return; } - /* there are crappy drivers that return PLAYCURSOR = WRITECURSOR = 0 without this.. */ - counter = 5000; - for (;;) { - hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &s->safedist); - if (playpos > 0) - break; - sleep_millis (1); - counter--; - if (counter < 0) { - write_log (L"DSSOUND: stuck?!?!\n"); - disable_sound (); - break; - } + if (status & DSBSTATUS_BUFFERLOST) { + write_log (L"DSSOUND: buffer lost\n"); + restore_ds (sd, DSERR_BUFFERLOST); + return; } - write_log (L"DSSOUND: %d = (%d - %d)\n", (s->safedist - playpos) / sd->samplesize, s->safedist / sd->samplesize, playpos / sd->samplesize); - recalc_offsets (sd); - s->safedist -= playpos; - if (s->safedist < 64) - s->safedist = 64; - cf (s->safedist); -#if 0 - snd_totalmaxoffset_uf += s->safedist; - cf (snd_totalmaxoffset_uf); - snd_totalmaxoffset_of += s->safedist; - cf (snd_totalmaxoffset_of); - snd_maxoffset += s->safedist; - cf (snd_maxoffset); - snd_writeoffset += s->safedist; - cf (snd_writeoffset); -#endif - sd->waiting_for_buffer = -1; - restart_sound_buffer2 (sd); - write_log (L"DSSOUND: bs=%d w=%d max=%d tof=%d tuf=%d\n", - sd->sndbufsize / sd->samplesize, s->snd_writeoffset / sd->samplesize, - s->snd_maxoffset / sd->samplesize, s->snd_totalmaxoffset_of / sd->samplesize, - s->snd_totalmaxoffset_uf / sd->samplesize); - tfprev = timeframes + 10; - tfprev = (tfprev / 10) * 10; - } - - counter = 5000; - hr = IDirectSoundBuffer_GetStatus (s->lpDSBsecondary, &status); - if (FAILED (hr)) { - write_log (L"DSSOUND: GetStatus() failed: %s\n", DXError (hr)); - restore_ds (sd, DSERR_BUFFERLOST); - return; - } - if (status & DSBSTATUS_BUFFERLOST) { - write_log (L"DSSOUND: buffer lost\n"); - restore_ds (sd, DSERR_BUFFERLOST); - return; - } - if ((status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) != (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) { - write_log (L"DSSOUND: status = %08X\n", status); - restore_ds (sd, DSERR_BUFFERLOST); - return; - } - for (;;) { - hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safepos); - if (FAILED (hr)) { - restore_ds (sd, hr); - write_log (L"DSSOUND: GetCurrentPosition failed: %s\n", DXError (hr)); - return; + if ((status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) != (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) { + write_log (L"DSSOUND: status = %08X\n", status); + restore_ds (sd, DSERR_BUFFERLOST); + return; } - if (s->writepos >= safepos) - diff = s->writepos - safepos; - else - diff = s->dsoundbuf - safepos + s->writepos; + for (;;) { + hr = IDirectSoundBuffer_GetCurrentPosition (s->lpDSBsecondary, &playpos, &safepos); + if (FAILED (hr)) { + restore_ds (sd, hr); + write_log (L"DSSOUND: GetCurrentPosition failed: %s\n", DXError (hr)); + return; + } + if (s->writepos >= safepos) + diff = s->writepos - safepos; + else + diff = s->dsoundbuf - safepos + s->writepos; - if (diff < sd->sndbufsize || diff > s->snd_totalmaxoffset_uf) { + if (diff < sd->sndbufsize || diff > s->snd_totalmaxoffset_uf) { #if 0 - hr = IDirectSoundBuffer_Lock (lpDSBsecondary, s->writepos, sndbufsize, &b1, &s1, &b2, &s2, 0); - if (SUCCEEDED(hr)) { - memset (b1, 0, s1); - if (b2) - memset (b2, 0, s2); - IDirectSoundBuffer_Unlock (lpDSBsecondary, b1, s1, b2, s2); - } + hr = IDirectSoundBuffer_Lock (lpDSBsecondary, s->writepos, sndbufsize, &b1, &s1, &b2, &s2, 0); + if (SUCCEEDED(hr)) { + memset (b1, 0, s1); + if (b2) + memset (b2, 0, s2); + IDirectSoundBuffer_Unlock (lpDSBsecondary, b1, s1, b2, s2); + } #endif - gui_data.sndbuf_status = -1; - statuscnt = SND_STATUSCNT; - if (diff > s->snd_totalmaxoffset_uf) - s->writepos += s->dsoundbuf - diff; - s->writepos += sd->sndbufsize; - cf (s->writepos); - diff = s->safedist; - break; - } - - if (diff > s->snd_totalmaxoffset_of) { - gui_data.sndbuf_status = 2; - statuscnt = SND_STATUSCNT; - restart_sound_buffer2 (sd); - diff = s->snd_writeoffset; - write_log (L"DSSOUND: underflow (%d %d)\n", diff / sd->samplesize, s->snd_totalmaxoffset_of / sd->samplesize); - break; - } - - if (diff > s->snd_maxoffset) { - gui_data.sndbuf_status = 1; - statuscnt = SND_STATUSCNT; - sleep_millis (1); - counter--; - if (counter < 0) { - write_log (L"DSSOUND: sound system got stuck!?\n"); - restore_ds (sd, DSERR_BUFFERLOST); - reopen_sound (); + gui_data.sndbuf_status = -1; + statuscnt = SND_STATUSCNT; + if (diff > s->snd_totalmaxoffset_uf) + s->writepos += s->dsoundbuf - diff; + s->writepos += sd->sndbufsize; + cf (s->writepos); + diff = s->safedist; + break; + } + + if (diff > s->snd_totalmaxoffset_of) { + gui_data.sndbuf_status = 2; + statuscnt = SND_STATUSCNT; + restart_sound_buffer2 (sd); + diff = s->snd_writeoffset; + write_log (L"DSSOUND: underflow (%d %d)\n", diff / sd->samplesize, s->snd_totalmaxoffset_of / sd->samplesize); + break; + } + + if (diff > s->snd_maxoffset) { + gui_data.sndbuf_status = 1; + statuscnt = SND_STATUSCNT; + sleep_millis (1); + counter--; + if (counter < 0) { + write_log (L"DSSOUND: sound system got stuck!?\n"); + restore_ds (sd, DSERR_BUFFERLOST); + reopen_sound (); + return; + } + continue; + } + break; + } + + hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, s->writepos, sd->sndbufsize, &b1, &s1, &b2, &s2, 0); + if (restore_ds (sd, hr)) return; - } - continue; - } - break; - } - - hr = IDirectSoundBuffer_Lock (s->lpDSBsecondary, s->writepos, sd->sndbufsize, &b1, &s1, &b2, &s2, 0); - if (restore_ds (sd, hr)) - return; - if (FAILED (hr)) { - write_log (L"DSSOUND: lock failed: %s (%d %d)\n", DXError (hr), s->writepos / sd->samplesize, sd->sndbufsize / sd->samplesize); - return; - } - memcpy (b1, sndbuffer, s1); - if (b2) - memcpy (b2, (uae_u8*)sndbuffer + s1, s2); - IDirectSoundBuffer_Unlock (s->lpDSBsecondary, b1, s1, b2, s2); - - if (sd == sdp) { - double vdiff, m, skipmode; - - vdiff = diff - s->snd_writeoffset; - m = 100.0 * vdiff / s->max_sndbufsize; - skipmode = sync_sound (m); - - if (tfprev != timeframes) { - gui_data.sndbuf = vdiff * 1000 / (s->snd_maxoffset - s->snd_writeoffset); - if ((0 || sound_debug) && !(tfprev % 10)) - write_log (L"b=%4d,%5d,%5d,%5d d=%5d vd=%5.0f s=%+02.1f\n", - sd->sndbufsize / sd->samplesize, s->snd_configsize / sd->samplesize, s->max_sndbufsize / sd->samplesize, - s->dsoundbuf / sd->samplesize, diff / sd->samplesize, vdiff, skipmode); - tfprev = timeframes; - sound_setadjust (skipmode); - } - } - - s->writepos += sd->sndbufsize; - cf (s->writepos); + if (FAILED (hr)) { + write_log (L"DSSOUND: lock failed: %s (%d %d)\n", DXError (hr), s->writepos / sd->samplesize, sd->sndbufsize / sd->samplesize); + return; + } + memcpy (b1, sndbuffer, s1); + if (b2) + memcpy (b2, (uae_u8*)sndbuffer + s1, s2); + IDirectSoundBuffer_Unlock (s->lpDSBsecondary, b1, s1, b2, s2); + + if (sd == sdp) { + double vdiff, m, skipmode; + + vdiff = diff - s->snd_writeoffset; + m = 100.0 * vdiff / s->max_sndbufsize; + skipmode = sync_sound (m); + + if (tfprev != timeframes) { + gui_data.sndbuf = vdiff * 1000 / (s->snd_maxoffset - s->snd_writeoffset); + if ((0 || sound_debug) && !(tfprev % 10)) + write_log (L"b=%4d,%5d,%5d,%5d d=%5d vd=%5.0f s=%+02.1f\n", + sd->sndbufsize / sd->samplesize, s->snd_configsize / sd->samplesize, s->max_sndbufsize / sd->samplesize, + s->dsoundbuf / sd->samplesize, diff / sd->samplesize, vdiff, skipmode); + tfprev = timeframes; + sound_setadjust (skipmode); + } + } + + s->writepos += sd->sndbufsize; + cf (s->writepos); } static void channelswap (uae_s16 *sndbuffer, int len) { - int i; - for (i = 0; i < len; i += 2) { - uae_s16 t; - t = sndbuffer[i]; - sndbuffer[i] = sndbuffer[i + 1]; - sndbuffer[i + 1] = t; - } + int i; + for (i = 0; i < len; i += 2) { + uae_s16 t; + t = sndbuffer[i]; + sndbuffer[i] = sndbuffer[i + 1]; + sndbuffer[i + 1] = t; + } } static void channelswap6 (uae_s16 *sndbuffer, int len) { - int i; - for (i = 0; i < len; i += 6) { - uae_s16 t; - t = sndbuffer[i + 0]; - sndbuffer[i + 0] = sndbuffer[i + 1]; - sndbuffer[i + 1] = t; - t = sndbuffer[i + 4]; - sndbuffer[i + 4] = sndbuffer[i + 5]; - sndbuffer[i + 5] = t; - } + int i; + for (i = 0; i < len; i += 6) { + uae_s16 t; + t = sndbuffer[i + 0]; + sndbuffer[i + 0] = sndbuffer[i + 1]; + sndbuffer[i + 1] = t; + t = sndbuffer[i + 4]; + sndbuffer[i + 4] = sndbuffer[i + 5]; + sndbuffer[i + 5] = t; + } } void send_sound (struct sound_data *sd, uae_u16 *sndbuffer) { - if (savestate_state) - return; - if (sd->devicetype == SOUND_DEVICE_AL) - finish_sound_buffer_al (sd, sndbuffer); - else if (sd->devicetype == SOUND_DEVICE_DS) - finish_sound_buffer_ds (sd, sndbuffer); - else if (sd->devicetype == SOUND_DEVICE_PA) - finish_sound_buffer_pa (sd, sndbuffer); - else if (sd->devicetype == SOUND_DEVICE_WASAPI) - finish_sound_buffer_wasapi (sd, sndbuffer); + if (savestate_state) + return; + if (sd->devicetype == SOUND_DEVICE_AL) + finish_sound_buffer_al (sd, sndbuffer); + else if (sd->devicetype == SOUND_DEVICE_DS) + finish_sound_buffer_ds (sd, sndbuffer); + else if (sd->devicetype == SOUND_DEVICE_PA) + finish_sound_buffer_pa (sd, sndbuffer); + else if (sd->devicetype == SOUND_DEVICE_WASAPI) + finish_sound_buffer_wasapi (sd, sndbuffer); } void finish_sound_buffer (void) { - if (currprefs.turbo_emulation) - return; - if (currprefs.sound_stereo_swap_paula) { - if (get_audio_nativechannels (currprefs.sound_stereo) == 2 || get_audio_nativechannels (currprefs.sound_stereo) == 4) - channelswap ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); - else if (get_audio_nativechannels (currprefs.sound_stereo) == 6) - channelswap6 ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); - } + if (currprefs.turbo_emulation) + return; + if (currprefs.sound_stereo_swap_paula) { + if (get_audio_nativechannels (currprefs.sound_stereo) == 2 || get_audio_nativechannels (currprefs.sound_stereo) == 4) + channelswap ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); + else if (get_audio_nativechannels (currprefs.sound_stereo) == 6) + channelswap6 ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); + } #ifdef DRIVESOUND - driveclick_mix ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); + driveclick_mix ((uae_s16*)paula_sndbuffer, sdp->sndbufsize / 2); #endif #ifdef AVIOUTPUT - if (avioutput_audio) - AVIOutput_WriteAudio ((uae_u8*)paula_sndbuffer, sdp->sndbufsize); - if (avioutput_enabled && (!avioutput_framelimiter || avioutput_nosoundoutput)) - return; + if (avioutput_audio) + AVIOutput_WriteAudio ((uae_u8*)paula_sndbuffer, sdp->sndbufsize); + if (avioutput_enabled && (!avioutput_framelimiter || avioutput_nosoundoutput)) + return; #endif - if (!have_sound) - return; - if (statuscnt > 0) { - statuscnt--; - if (statuscnt == 0) - gui_data.sndbuf_status = 0; - } - if (gui_data.sndbuf_status == 3) - gui_data.sndbuf_status = 0; - send_sound (sdp, paula_sndbuffer); + if (!have_sound) + return; + if (statuscnt > 0) { + statuscnt--; + if (statuscnt == 0) + gui_data.sndbuf_status = 0; + } + if (gui_data.sndbuf_status == 3) + gui_data.sndbuf_status = 0; + send_sound (sdp, paula_sndbuffer); } static BOOL CALLBACK DSEnumProc (LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { - struct sound_device *sd = lpContext; - int i; - - for (i = 0; i < MAX_SOUND_DEVICES; i++) { - if (sd[i].name == NULL) - break; - } - if (i >= MAX_SOUND_DEVICES) + struct sound_device *sd = lpContext; + int i; + + for (i = 0; i < MAX_SOUND_DEVICES; i++) { + if (sd[i].name == NULL) + break; + } + if (i >= MAX_SOUND_DEVICES) + return TRUE; + if (lpGUID != NULL) + memcpy (&sd[i].guid, lpGUID, sizeof (GUID)); + sd[i].name = my_strdup (lpszDesc); + sd[i].type = SOUND_DEVICE_DS; + sd[i].cfgname = my_strdup (sd[i].name); return TRUE; - if (lpGUID != NULL) - memcpy (&sd[i].guid, lpGUID, sizeof (GUID)); - sd[i].name = my_strdup (lpszDesc); - sd[i].type = SOUND_DEVICE_DS; - sd[i].cfgname = my_strdup (sd[i].name); - return TRUE; } static void wasapi_enum (struct sound_device *sd) { - HRESULT hr; - IMMDeviceEnumerator *enumerator; - IMMDeviceCollection *col; - int i, cnt; - - write_log (L"Enumerating WASAPI devices...\n"); - for (cnt = 0; cnt < MAX_SOUND_DEVICES; cnt++) { - if (sd->name == NULL) - break; - sd++; - } - if (cnt >= MAX_SOUND_DEVICES) - return; - - hr = CoCreateInstance (&XCLSID_MMDeviceEnumerator, NULL, - CLSCTX_ALL, &XIID_IMMDeviceEnumerator, - (void**)&enumerator); - if (SUCCEEDED (hr)) { - hr = enumerator->lpVtbl->EnumAudioEndpoints (enumerator, eRender, DEVICE_STATE_ACTIVE, &col); + HRESULT hr; + IMMDeviceEnumerator *enumerator; + IMMDeviceCollection *col; + int i, cnt; + + write_log (L"Enumerating WASAPI devices...\n"); + for (cnt = 0; cnt < MAX_SOUND_DEVICES; cnt++) { + if (sd->name == NULL) + break; + sd++; + } + if (cnt >= MAX_SOUND_DEVICES) + return; + + hr = CoCreateInstance (&XCLSID_MMDeviceEnumerator, NULL, + CLSCTX_ALL, &XIID_IMMDeviceEnumerator, + (void**)&enumerator); if (SUCCEEDED (hr)) { - UINT num; - hr = col->lpVtbl->GetCount (col, &num); - if (SUCCEEDED (hr)) { - for (i = 0; i < num && cnt < MAX_SOUND_DEVICES; i++) { - IMMDevice *dev; - LPWSTR devid = NULL; - LPWSTR devname = NULL; - hr = col->lpVtbl->Item (col, i, &dev); - if (SUCCEEDED (hr)) { - IPropertyStore *prop; - dev->lpVtbl->GetId (dev, &devid); - hr = dev->lpVtbl->OpenPropertyStore (dev, STGM_READ, &prop); + hr = enumerator->lpVtbl->EnumAudioEndpoints (enumerator, eRender, DEVICE_STATE_ACTIVE, &col); + if (SUCCEEDED (hr)) { + UINT num; + hr = col->lpVtbl->GetCount (col, &num); if (SUCCEEDED (hr)) { - PROPVARIANT pv; - PropVariantInit (&pv); - hr = prop->lpVtbl->GetValue (prop, &PKEY_Device_FriendlyName, &pv); - if (SUCCEEDED (hr)) { - devname = my_strdup (pv.pwszVal); - } - PropVariantClear (&pv); - prop->lpVtbl->Release (prop); - } - dev->lpVtbl->Release (dev); - } - if (devid && devname) { - TCHAR tmp[MAX_DPATH]; - if (i == 0) { - sd->cfgname = my_strdup (L"WASAPI:Default Audio Device"); - sd->type = SOUND_DEVICE_WASAPI; - sd->name = my_strdup (L"Default Audio Device"); - sd->alname = NULL; - sd++; - cnt++; + for (i = 0; i < num && cnt < MAX_SOUND_DEVICES; i++) { + IMMDevice *dev; + LPWSTR devid = NULL; + LPWSTR devname = NULL; + hr = col->lpVtbl->Item (col, i, &dev); + if (SUCCEEDED (hr)) { + IPropertyStore *prop; + dev->lpVtbl->GetId (dev, &devid); + hr = dev->lpVtbl->OpenPropertyStore (dev, STGM_READ, &prop); + if (SUCCEEDED (hr)) { + PROPVARIANT pv; + PropVariantInit (&pv); + hr = prop->lpVtbl->GetValue (prop, &PKEY_Device_FriendlyName, &pv); + if (SUCCEEDED (hr)) { + devname = my_strdup (pv.pwszVal); + } + PropVariantClear (&pv); + prop->lpVtbl->Release (prop); + } + dev->lpVtbl->Release (dev); + } + if (devid && devname) { + TCHAR tmp[MAX_DPATH]; + if (i == 0) { + sd->cfgname = my_strdup (L"WASAPI:Default Audio Device"); + sd->type = SOUND_DEVICE_WASAPI; + sd->name = my_strdup (L"Default Audio Device"); + sd->alname = NULL; + sd++; + cnt++; + } + if (cnt < MAX_SOUND_DEVICES) { + _stprintf (tmp, L"WASAPI:%s", devname); + sd->cfgname = my_strdup (tmp); + sd->type = SOUND_DEVICE_WASAPI; + sd->name = my_strdup (devname); + sd->alname = my_strdup (devid); + sd++; + cnt++; + } + } + xfree (devname); + CoTaskMemFree (devid); + } } - if (cnt < MAX_SOUND_DEVICES) { - _stprintf (tmp, L"WASAPI:%s", devname); - sd->cfgname = my_strdup (tmp); - sd->type = SOUND_DEVICE_WASAPI; - sd->name = my_strdup (devname); - sd->alname = my_strdup (devid); - sd++; - cnt++; - } - } - xfree (devname); - CoTaskMemFree (devid); + col->lpVtbl->Release (col); } - } - col->lpVtbl->Release (col); + enumerator->lpVtbl->Release (enumerator); } - enumerator->lpVtbl->Release (enumerator); - } } static void OpenALEnumerate (struct sound_device *sds, const char *pDeviceNames, const char *ppDefaultDevice, int skipdetect) { - struct sound_device *sd; - while (pDeviceNames && *pDeviceNames) { - ALCdevice *pDevice; - const char *devname; - int i, ok; - for (i = 0; i < MAX_SOUND_DEVICES; i++) { - sd = &sds[i]; - if (sd->name == NULL) - break; - } - if (i >= MAX_SOUND_DEVICES) - return; - devname = pDeviceNames; - if (ppDefaultDevice) - devname = ppDefaultDevice; - ok = 0; - if (!skipdetect) { - pDevice = alcOpenDevice (devname); - if (pDevice) { - ALCcontext *context = alcCreateContext (pDevice, NULL); - if (context) { - ALint iMajorVersion = 0, iMinorVersion = 0; - alcMakeContextCurrent (context); - alcGetIntegerv (pDevice, ALC_MAJOR_VERSION, sizeof (ALint), &iMajorVersion); - alcGetIntegerv (pDevice, ALC_MINOR_VERSION, sizeof (ALint), &iMinorVersion); - if (iMajorVersion > 1 || (iMajorVersion == 1 && iMinorVersion > 0)) { + struct sound_device *sd; + while (pDeviceNames && *pDeviceNames) { + ALCdevice *pDevice; + const char *devname; + int i, ok; + for (i = 0; i < MAX_SOUND_DEVICES; i++) { + sd = &sds[i]; + if (sd->name == NULL) + break; + } + if (i >= MAX_SOUND_DEVICES) + return; + devname = pDeviceNames; + if (ppDefaultDevice) + devname = ppDefaultDevice; + ok = 0; + if (!skipdetect) { + pDevice = alcOpenDevice (devname); + if (pDevice) { + ALCcontext *context = alcCreateContext (pDevice, NULL); + if (context) { + ALint iMajorVersion = 0, iMinorVersion = 0; + alcMakeContextCurrent (context); + alcGetIntegerv (pDevice, ALC_MAJOR_VERSION, sizeof (ALint), &iMajorVersion); + alcGetIntegerv (pDevice, ALC_MINOR_VERSION, sizeof (ALint), &iMinorVersion); + if (iMajorVersion > 1 || (iMajorVersion == 1 && iMinorVersion > 0)) { + ok = 1; + } + alcMakeContextCurrent (NULL); + alcDestroyContext (context); + } + alcCloseDevice (pDevice); + } + } else { ok = 1; - } - alcMakeContextCurrent (NULL); - alcDestroyContext (context); } - alcCloseDevice (pDevice); - } - } else { - ok = 1; - } - if (ok) { - TCHAR tmp[MAX_DPATH]; - sd->type = SOUND_DEVICE_AL; - if (ppDefaultDevice) { - TCHAR *tdevname = au (devname); - _stprintf (tmp, L"Default [%s]", tdevname); - xfree (tdevname); - sd->alname = my_strdup_ansi (ppDefaultDevice); - sd->name = my_strdup (tmp); - } else { - sd->alname = my_strdup_ansi (pDeviceNames); - sd->name = my_strdup_ansi (pDeviceNames); - } - _stprintf (tmp, L"OPENAL:%s", sd->alname); - sd->cfgname = my_strdup (tmp); - } - if (ppDefaultDevice) - ppDefaultDevice = NULL; - else - pDeviceNames += strlen (pDeviceNames) + 1; - } + if (ok) { + TCHAR tmp[MAX_DPATH]; + sd->type = SOUND_DEVICE_AL; + if (ppDefaultDevice) { + TCHAR *tdevname = au (devname); + _stprintf (tmp, L"Default [%s]", tdevname); + xfree (tdevname); + sd->alname = my_strdup_ansi (ppDefaultDevice); + sd->name = my_strdup (tmp); + } else { + sd->alname = my_strdup_ansi (pDeviceNames); + sd->name = my_strdup_ansi (pDeviceNames); + } + _stprintf (tmp, L"OPENAL:%s", sd->alname); + sd->cfgname = my_strdup (tmp); + } + if (ppDefaultDevice) + ppDefaultDevice = NULL; + else + pDeviceNames += strlen (pDeviceNames) + 1; + } } static int isdllversion (const TCHAR *name, int version, int revision, int subver, int subrev) { - DWORD dwVersionHandle, dwFileVersionInfoSize; - LPVOID lpFileVersionData = NULL; - int ok = 0; - - dwFileVersionInfoSize = GetFileVersionInfoSize (name, &dwVersionHandle); - if (dwFileVersionInfoSize) { - if (lpFileVersionData = xcalloc (1, dwFileVersionInfoSize)) { - if (GetFileVersionInfo (name, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { - VS_FIXEDFILEINFO *vsFileInfo = NULL; - UINT uLen; - if (VerQueryValue (lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { - if (vsFileInfo) { - uae_u64 v1 = ((uae_u64)vsFileInfo->dwProductVersionMS << 32) | vsFileInfo->dwProductVersionLS; - uae_u64 v2 = ((uae_u64)version << 48) | ((uae_u64)revision << 32) | (subver << 16) | (subrev << 0); - write_log (L"%s %d.%d.%d.%d\n", name, - HIWORD (vsFileInfo->dwProductVersionMS), LOWORD (vsFileInfo->dwProductVersionMS), - HIWORD (vsFileInfo->dwProductVersionLS), LOWORD (vsFileInfo->dwProductVersionLS)); - if (v1 >= v2) - ok = 1; - } + DWORD dwVersionHandle, dwFileVersionInfoSize; + LPVOID lpFileVersionData = NULL; + int ok = 0; + + dwFileVersionInfoSize = GetFileVersionInfoSize (name, &dwVersionHandle); + if (dwFileVersionInfoSize) { + if (lpFileVersionData = xcalloc (1, dwFileVersionInfoSize)) { + if (GetFileVersionInfo (name, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { + VS_FIXEDFILEINFO *vsFileInfo = NULL; + UINT uLen; + if (VerQueryValue (lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { + if (vsFileInfo) { + uae_u64 v1 = ((uae_u64)vsFileInfo->dwProductVersionMS << 32) | vsFileInfo->dwProductVersionLS; + uae_u64 v2 = ((uae_u64)version << 48) | ((uae_u64)revision << 32) | (subver << 16) | (subrev << 0); + write_log (L"%s %d.%d.%d.%d\n", name, + HIWORD (vsFileInfo->dwProductVersionMS), LOWORD (vsFileInfo->dwProductVersionMS), + HIWORD (vsFileInfo->dwProductVersionLS), LOWORD (vsFileInfo->dwProductVersionLS)); + if (v1 >= v2) + ok = 1; + } + } + } + xfree (lpFileVersionData); } - } - xfree (lpFileVersionData); } - } - return ok; + return ok; } #define PORTAUDIO 1 #if PORTAUDIO static void PortAudioEnumerate (struct sound_device *sds) { - struct sound_device *sd; - int num; - int i, j; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH], *s1, *s2; - - num = Pa_GetDeviceCount (); - if (num < 0) { - TCHAR *errtxt = au (Pa_GetErrorText (num)); - write_log (L"PA: Pa_GetDeviceCount() failed: %08x (%s)\n", num, errtxt); - xfree (errtxt); - return; - } - for (j = 0; j < num; j++) { - const PaDeviceInfo *di; - const PaHostApiInfo *hai; - di = Pa_GetDeviceInfo (j); - if (di->maxOutputChannels == 0) - continue; - hai = Pa_GetHostApiInfo (di->hostApi); - if (!hai) - continue; - if (hai->type == paDirectSound || hai->type == paMME) - continue; - for (i = 0; i < MAX_SOUND_DEVICES; i++) { - sd = &sds[i]; - if (sd->name == NULL) - break; + struct sound_device *sd; + int num; + int i, j; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH], *s1, *s2; + + num = Pa_GetDeviceCount (); + if (num < 0) { + TCHAR *errtxt = au (Pa_GetErrorText (num)); + write_log (L"PA: Pa_GetDeviceCount() failed: %08x (%s)\n", num, errtxt); + xfree (errtxt); + return; + } + for (j = 0; j < num; j++) { + const PaDeviceInfo *di; + const PaHostApiInfo *hai; + di = Pa_GetDeviceInfo (j); + if (di->maxOutputChannels == 0) + continue; + hai = Pa_GetHostApiInfo (di->hostApi); + if (!hai) + continue; + if (hai->type == paDirectSound || hai->type == paMME) + continue; + for (i = 0; i < MAX_SOUND_DEVICES; i++) { + sd = &sds[i]; + if (sd->name == NULL) + break; + } + if (i >= MAX_SOUND_DEVICES) + return; + s1 = au (hai->name); + s2 = au (di->name); + _stprintf (tmp, L"[%s] %s", s1, s2); + xfree (s2); + xfree (s1); + sd->type = SOUND_DEVICE_PA; + sd->name = my_strdup (tmp); + _stprintf (tmp2, L"PORTAUDIO:%s", tmp); + sd->cfgname = my_strdup (tmp2); + sd->panum = j; } - if (i >= MAX_SOUND_DEVICES) - return; - s1 = au (hai->name); - s2 = au (di->name); - _stprintf (tmp, L"[%s] %s", s1, s2); - xfree (s2); - xfree (s1); - sd->type = SOUND_DEVICE_PA; - sd->name = my_strdup (tmp); - _stprintf (tmp2, L"PORTAUDIO:%s", tmp); - sd->cfgname = my_strdup (tmp2); - sd->panum = j; - } } #endif static LONG WINAPI ExceptionFilter (struct _EXCEPTION_POINTERS * pExceptionPointers, DWORD ec) { - return EXCEPTION_EXECUTE_HANDLER; + return EXCEPTION_EXECUTE_HANDLER; } int force_directsound; int enumerate_sound_devices (void) { - if (!num_sound_devices) { - HMODULE l = NULL; - write_log (L"Enumerating DirectSound devices..\n"); - if (os_vista && (sounddrivermask & SOUNDDRIVER_WASAPI)) - wasapi_enum (sound_devices); - if ((1 || force_directsound || !os_vista) && (sounddrivermask & SOUNDDRIVER_DS)) { - DirectSoundEnumerate ((LPDSENUMCALLBACK)DSEnumProc, sound_devices); - //DirectSoundCaptureEnumerate ((LPDSENUMCALLBACK)DSEnumProc, record_devices); - } - if (sounddrivermask & SOUNDDRIVER_OPENAL) { - __try { - if (isdllversion (L"openal32.dll", 6, 14, 357, 22)) { - write_log (L"Enumerating OpenAL devices..\n"); - if (alcIsExtensionPresent (NULL, "ALC_ENUMERATION_EXT")) { - const char* ppDefaultDevice = alcGetString (NULL, ALC_DEFAULT_DEVICE_SPECIFIER); - const char* pDeviceNames = alcGetString (NULL, ALC_DEVICE_SPECIFIER); - if (alcIsExtensionPresent (NULL, "ALC_ENUMERATE_ALL_EXT")) - pDeviceNames = alcGetString (NULL, ALC_ALL_DEVICES_SPECIFIER); - OpenALEnumerate (sound_devices, pDeviceNames, ppDefaultDevice, FALSE); - #if 0 - ppDefaultDevice = alcGetString (NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); - pDeviceNames = alcGetString (NULL, ALC_CAPTURE_DEVICE_SPECIFIER); - OpenALEnumerate (record_devices, pDeviceNames, ppDefaultDevice, TRUE); - #endif - } + if (!num_sound_devices) { + HMODULE l = NULL; + write_log (L"Enumerating DirectSound devices..\n"); + if (os_vista && (sounddrivermask & SOUNDDRIVER_WASAPI)) + wasapi_enum (sound_devices); + if ((1 || force_directsound || !os_vista) && (sounddrivermask & SOUNDDRIVER_DS)) { + DirectSoundEnumerate ((LPDSENUMCALLBACK)DSEnumProc, sound_devices); + //DirectSoundCaptureEnumerate ((LPDSENUMCALLBACK)DSEnumProc, record_devices); + } + if (sounddrivermask & SOUNDDRIVER_OPENAL) { + __try { + if (isdllversion (L"openal32.dll", 6, 14, 357, 22)) { + write_log (L"Enumerating OpenAL devices..\n"); + if (alcIsExtensionPresent (NULL, "ALC_ENUMERATION_EXT")) { + const char* ppDefaultDevice = alcGetString (NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + const char* pDeviceNames = alcGetString (NULL, ALC_DEVICE_SPECIFIER); + if (alcIsExtensionPresent (NULL, "ALC_ENUMERATE_ALL_EXT")) + pDeviceNames = alcGetString (NULL, ALC_ALL_DEVICES_SPECIFIER); + OpenALEnumerate (sound_devices, pDeviceNames, ppDefaultDevice, FALSE); +#if 0 + ppDefaultDevice = alcGetString (NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); + pDeviceNames = alcGetString (NULL, ALC_CAPTURE_DEVICE_SPECIFIER); + OpenALEnumerate (record_devices, pDeviceNames, ppDefaultDevice, TRUE); +#endif + } + } + } __except(ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { + write_log (L"OpenAL enumeration crashed!\n"); + flush_log (); + } } - } __except(ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { - write_log (L"OpenAL enumeration crashed!\n"); - flush_log (); - } - } #if PORTAUDIO - if (sounddrivermask & SOUNDDRIVER_PORTAUDIO) { - __try { - HMODULE hm = WIN32_LoadLibrary (L"portaudio_x86.dll"); - if (hm) { - TCHAR *s; - PaError err; - write_log (L"Enumerating PortAudio devices..\n"); - s = au (Pa_GetVersionText ()); - write_log (L"%s (%d)\n", s, Pa_GetVersion ()); - xfree (s); - if (Pa_GetVersion () >= 1899) { - err = Pa_Initialize (); - if (err == paNoError) { - PortAudioEnumerate (sound_devices); - } else { - s = au (Pa_GetErrorText (err)); - write_log (L"Portaudio initialization failed: %d (%s)\n", - err, s); - xfree (s); - FreeLibrary (hm); + if (sounddrivermask & SOUNDDRIVER_PORTAUDIO) { + __try { + HMODULE hm = WIN32_LoadLibrary (L"portaudio_x86.dll"); + if (hm) { + TCHAR *s; + PaError err; + write_log (L"Enumerating PortAudio devices..\n"); + s = au (Pa_GetVersionText ()); + write_log (L"%s (%d)\n", s, Pa_GetVersion ()); + xfree (s); + if (Pa_GetVersion () >= 1899) { + err = Pa_Initialize (); + if (err == paNoError) { + PortAudioEnumerate (sound_devices); + } else { + s = au (Pa_GetErrorText (err)); + write_log (L"Portaudio initialization failed: %d (%s)\n", + err, s); + xfree (s); + FreeLibrary (hm); + } + } else { + write_log (L"Too old PortAudio library\n"); + flush_log (); + FreeLibrary (hm); + } + } + } __except(ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { + write_log (L"Portaudio enumeration crashed!\n"); } - } else { - write_log (L"Too old PortAudio library\n"); - flush_log (); - FreeLibrary (hm); - } } - } __except(ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { - write_log (L"Portaudio enumeration crashed!\n"); - } - } #endif - write_log (L"Enumeration end\n"); - for (num_sound_devices = 0; num_sound_devices < MAX_SOUND_DEVICES; num_sound_devices++) { - if (sound_devices[num_sound_devices].name == NULL) - break; - } - for (num_record_devices = 0; num_record_devices < MAX_SOUND_DEVICES; num_record_devices++) { - if (record_devices[num_record_devices].name == NULL) - break; + write_log (L"Enumeration end\n"); + for (num_sound_devices = 0; num_sound_devices < MAX_SOUND_DEVICES; num_sound_devices++) { + if (sound_devices[num_sound_devices].name == NULL) + break; + } + for (num_record_devices = 0; num_record_devices < MAX_SOUND_DEVICES; num_record_devices++) { + if (record_devices[num_record_devices].name == NULL) + break; + } } - } - return num_sound_devices; + return num_sound_devices; } #include #include /* - Based on - http://blogs.msdn.com/larryosterman/archive/2007/03/06/how-do-i-change-the-master-volume-in-windows-vista.aspx +Based on +http://blogs.msdn.com/larryosterman/archive/2007/03/06/how-do-i-change-the-master-volume-in-windows-vista.aspx */ const static GUID XIID_MMDeviceEnumerator = {0xBCDE0395,0xE52F,0x467C, - {0x8E,0x3D,0xC4,0x57,0x92,0x91,0x69,0x2E}}; +{0x8E,0x3D,0xC4,0x57,0x92,0x91,0x69,0x2E}}; const static GUID XIID_IAudioEndpointVolume = {0x5CDF2C82, 0x841E,0x4546, - {0x97,0x22,0x0C,0xF7,0x40,0x78,0x22,0x9A}}; +{0x97,0x22,0x0C,0xF7,0x40,0x78,0x22,0x9A}}; static int setget_master_volume_vista (int setvolume, int *volume, int *mute) { - IMMDeviceEnumerator *deviceEnumerator = NULL; - IMMDevice *defaultDevice = NULL; - IAudioEndpointVolume *endpointVolume = NULL; - HRESULT hr; - int ok = 0; + IMMDeviceEnumerator *deviceEnumerator = NULL; + IMMDevice *defaultDevice = NULL; + IAudioEndpointVolume *endpointVolume = NULL; + HRESULT hr; + int ok = 0; - hr = CoInitialize (NULL); - if (FAILED (hr)) - return 0; - hr = CoCreateInstance (&XIID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &XIID_IMMDeviceEnumerator, (LPVOID *)&deviceEnumerator); - if (FAILED (hr)) - return 0; - hr = deviceEnumerator->lpVtbl->GetDefaultAudioEndpoint (deviceEnumerator, eRender, eConsole, &defaultDevice); - if (SUCCEEDED (hr)) { - hr = defaultDevice->lpVtbl->Activate (defaultDevice, &XIID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume); + hr = CoInitialize (NULL); + if (FAILED (hr)) + return 0; + hr = CoCreateInstance (&XIID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &XIID_IMMDeviceEnumerator, (LPVOID *)&deviceEnumerator); + if (FAILED (hr)) + return 0; + hr = deviceEnumerator->lpVtbl->GetDefaultAudioEndpoint (deviceEnumerator, eRender, eConsole, &defaultDevice); if (SUCCEEDED (hr)) { - if (setvolume) { - if (SUCCEEDED (endpointVolume->lpVtbl->SetMasterVolumeLevelScalar (endpointVolume, (float)(*volume) / (float)65535.0, NULL))) - ok++; - if (SUCCEEDED (endpointVolume->lpVtbl->SetMute (endpointVolume, *mute, NULL))) - ok++; - } else { - float vol; - if (SUCCEEDED (endpointVolume->lpVtbl->GetMasterVolumeLevelScalar (endpointVolume, &vol))) { - ok++; - *volume = vol * 65535.0; - } - if (SUCCEEDED (endpointVolume->lpVtbl->GetMute (endpointVolume, mute))) { - ok++; + hr = defaultDevice->lpVtbl->Activate (defaultDevice, &XIID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume); + if (SUCCEEDED (hr)) { + if (setvolume) { + if (SUCCEEDED (endpointVolume->lpVtbl->SetMasterVolumeLevelScalar (endpointVolume, (float)(*volume) / (float)65535.0, NULL))) + ok++; + if (SUCCEEDED (endpointVolume->lpVtbl->SetMute (endpointVolume, *mute, NULL))) + ok++; + } else { + float vol; + if (SUCCEEDED (endpointVolume->lpVtbl->GetMasterVolumeLevelScalar (endpointVolume, &vol))) { + ok++; + *volume = vol * 65535.0; + } + if (SUCCEEDED (endpointVolume->lpVtbl->GetMute (endpointVolume, mute))) { + ok++; + } + } + endpointVolume->lpVtbl->Release (endpointVolume); } - } - endpointVolume->lpVtbl->Release (endpointVolume); + defaultDevice->lpVtbl->Release (defaultDevice); } - defaultDevice->lpVtbl->Release (defaultDevice); - } - deviceEnumerator->lpVtbl->Release (deviceEnumerator); - CoUninitialize (); - return ok == 2; + deviceEnumerator->lpVtbl->Release (deviceEnumerator); + CoUninitialize (); + return ok == 2; } static void mcierr (TCHAR *str, DWORD err) { - TCHAR es[1000]; - if (err == MMSYSERR_NOERROR) - return; - if (mciGetErrorString (err, es, sizeof es / sizeof (TCHAR))) - write_log (L"MCIErr: %s: %d = '%s'\n", str, err, es); - else - write_log (L"%s, errcode=%d\n", str, err); + TCHAR es[1000]; + if (err == MMSYSERR_NOERROR) + return; + if (mciGetErrorString (err, es, sizeof es / sizeof (TCHAR))) + write_log (L"MCIErr: %s: %d = '%s'\n", str, err, es); + else + write_log (L"%s, errcode=%d\n", str, err); } /* from http://www.codeproject.com/audio/mixerSetControlDetails.asp */ static int setget_master_volume_xp (int setvolume, int *volume, int *mute) { - MMRESULT result; - HMIXER hMixer; - MIXERLINE ml = {0}; - MIXERLINECONTROLS mlc = {0}; - MIXERCONTROL mc = {0}; - MIXERCONTROLDETAILS mcd = {0}; - MIXERCONTROLDETAILS_UNSIGNED mcdu = {0}; - MIXERCONTROLDETAILS_BOOLEAN mcb = {0}; - int ok = 0; - - result = mixerOpen (&hMixer, 0, 0, 0, MIXER_OBJECTF_MIXER); - if (result == MMSYSERR_NOERROR) { - ml.cbStruct = sizeof (MIXERLINE); - ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; - result = mixerGetLineInfo ((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); - if (result == MIXERR_INVALLINE) { - ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_DIGITAL; - result = mixerGetLineInfo ((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); - } + MMRESULT result; + HMIXER hMixer; + MIXERLINE ml = {0}; + MIXERLINECONTROLS mlc = {0}; + MIXERCONTROL mc = {0}; + MIXERCONTROLDETAILS mcd = {0}; + MIXERCONTROLDETAILS_UNSIGNED mcdu = {0}; + MIXERCONTROLDETAILS_BOOLEAN mcb = {0}; + int ok = 0; + + result = mixerOpen (&hMixer, 0, 0, 0, MIXER_OBJECTF_MIXER); if (result == MMSYSERR_NOERROR) { - mlc.cbStruct = sizeof (MIXERLINECONTROLS); - mlc.dwLineID = ml.dwLineID; - mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; - mlc.cControls = 1; - mlc.pamxctrl = &mc; - mlc.cbmxctrl = sizeof(MIXERCONTROL); - result = mixerGetLineControls ((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); - if (result == MMSYSERR_NOERROR) { - mcd.cbStruct = sizeof (MIXERCONTROLDETAILS); - mcd.hwndOwner = 0; - mcd.dwControlID = mc.dwControlID; - mcd.paDetails = &mcdu; - mcd.cbDetails = sizeof (MIXERCONTROLDETAILS_UNSIGNED); - mcd.cChannels = 1; - mcdu.dwValue = 0; - if (setvolume) { - mcdu.dwValue = *volume; - result = mixerSetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); - } else { - result = mixerGetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_GETCONTROLDETAILSF_VALUE); - *volume = mcdu.dwValue; + ml.cbStruct = sizeof (MIXERLINE); + ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; + result = mixerGetLineInfo ((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); + if (result == MIXERR_INVALLINE) { + ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_DIGITAL; + result = mixerGetLineInfo ((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); } - mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE; - result = mixerGetLineControls ((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); if (result == MMSYSERR_NOERROR) { - mcd.paDetails = &mcb; - mcd.dwControlID = mc.dwControlID; - mcb.fValue = 0; - mcd.cbDetails = sizeof (MIXERCONTROLDETAILS_BOOLEAN); - if (setvolume) { - mcb.fValue = *mute; - result = mixerSetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); - } else { - result = mixerGetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_GETCONTROLDETAILSF_VALUE); - *mute = mcb.fValue; - } - if (result == MMSYSERR_NOERROR) - ok = 1; + mlc.cbStruct = sizeof (MIXERLINECONTROLS); + mlc.dwLineID = ml.dwLineID; + mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; + mlc.cControls = 1; + mlc.pamxctrl = &mc; + mlc.cbmxctrl = sizeof(MIXERCONTROL); + result = mixerGetLineControls ((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); + if (result == MMSYSERR_NOERROR) { + mcd.cbStruct = sizeof (MIXERCONTROLDETAILS); + mcd.hwndOwner = 0; + mcd.dwControlID = mc.dwControlID; + mcd.paDetails = &mcdu; + mcd.cbDetails = sizeof (MIXERCONTROLDETAILS_UNSIGNED); + mcd.cChannels = 1; + mcdu.dwValue = 0; + if (setvolume) { + mcdu.dwValue = *volume; + result = mixerSetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); + } else { + result = mixerGetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_GETCONTROLDETAILSF_VALUE); + *volume = mcdu.dwValue; + } + mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE; + result = mixerGetLineControls ((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); + if (result == MMSYSERR_NOERROR) { + mcd.paDetails = &mcb; + mcd.dwControlID = mc.dwControlID; + mcb.fValue = 0; + mcd.cbDetails = sizeof (MIXERCONTROLDETAILS_BOOLEAN); + if (setvolume) { + mcb.fValue = *mute; + result = mixerSetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); + } else { + result = mixerGetControlDetails ((HMIXEROBJ) hMixer, &mcd, MIXER_GETCONTROLDETAILSF_VALUE); + *mute = mcb.fValue; + } + if (result == MMSYSERR_NOERROR) + ok = 1; + } else + mcierr (L"mixerGetLineControls Mute", result); + } else + mcierr (L"mixerGetLineControls Volume", result); } else - mcierr (L"mixerGetLineControls Mute", result); - } else - mcierr (L"mixerGetLineControls Volume", result); + mcierr (L"mixerGetLineInfo", result); + mixerClose (hMixer); } else - mcierr (L"mixerGetLineInfo", result); - mixerClose (hMixer); - } else - mcierr (L"mixerOpen", result); - return ok; + mcierr (L"mixerOpen", result); + return ok; } static int set_master_volume (int volume, int mute) { - if (os_vista) - return setget_master_volume_vista (1, &volume, &mute); - else - return setget_master_volume_xp (1, &volume, &mute); + if (os_vista) + return setget_master_volume_vista (1, &volume, &mute); + else + return setget_master_volume_xp (1, &volume, &mute); } static int get_master_volume (int *volume, int *mute) { - *volume = 0; - *mute = 0; - if (os_vista) - return setget_master_volume_vista (0, volume, mute); - else - return setget_master_volume_xp (0, volume, mute); + *volume = 0; + *mute = 0; + if (os_vista) + return setget_master_volume_vista (0, volume, mute); + else + return setget_master_volume_xp (0, volume, mute); } void sound_mute (int newmute) { - if (newmute < 0) - sdp->mute = sdp->mute ? 0 : 1; - else - sdp->mute = newmute; - set_volume (currprefs.sound_volume, sdp->mute); + if (newmute < 0) + sdp->mute = sdp->mute ? 0 : 1; + else + sdp->mute = newmute; + set_volume (currprefs.sound_volume, sdp->mute); } void sound_volume (int dir) { - currprefs.sound_volume -= dir * 10; - if (currprefs.sound_volume < 0) - currprefs.sound_volume = 0; - if (currprefs.sound_volume > 100) - currprefs.sound_volume = 100; - changed_prefs.sound_volume = currprefs.sound_volume; - set_volume (currprefs.sound_volume, sdp->mute); + currprefs.sound_volume -= dir * 10; + if (currprefs.sound_volume < 0) + currprefs.sound_volume = 0; + if (currprefs.sound_volume > 100) + currprefs.sound_volume = 100; + changed_prefs.sound_volume = currprefs.sound_volume; + set_volume (currprefs.sound_volume, sdp->mute); } void master_sound_volume (int dir) { - int vol, mute, r; - - r = get_master_volume (&vol, &mute); - if (!r) - return; - if (dir == 0) - mute = mute ? 0 : 1; - vol += dir * (65536 / 10); - if (vol < 0) - vol = 0; - if (vol > 65535) - vol = 65535; - set_master_volume (vol, mute); + int vol, mute, r; + + r = get_master_volume (&vol, &mute); + if (!r) + return; + if (dir == 0) + mute = mute ? 0 : 1; + vol += dir * (65536 / 10); + if (vol < 0) + vol = 0; + if (vol > 65535) + vol = 65535; + set_master_volume (vol, mute); } diff --git a/od-win32/uaeunp/uaeunp.vcxproj b/od-win32/uaeunp/uaeunp.vcxproj index 1275f44b..ae274a13 100644 --- a/od-win32/uaeunp/uaeunp.vcxproj +++ b/od-win32/uaeunp/uaeunp.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -10,37 +11,44 @@ - {6181E50C-5F32-42DC-BEF6-827AA8A5429D} + {6181E50C-5F32-42DC-BEF6-827AA8A5429D} uaeunp Win32Proj - + Application Unicode + true - + Application Unicode - true - - + + + + + - <_ProjectFileVersion>10.0.20506.1 + <_ProjectFileVersion>10.0.21006.1 d:\amiga\ $(Configuration)\ true d:\amiga\ $(Configuration)\ false - $(IncludePath) - $(LibraryPath) + AllRules.ruleset + + + AllRules.ruleset + + @@ -59,6 +67,7 @@ zlibstat.lib;%(AdditionalDependencies) true Console + false MachineX86 @@ -74,7 +83,7 @@ Level3 ProgramDatabase - CompileAsCpp + CompileAsC zlibstat.lib;%(AdditionalDependencies) @@ -86,19 +95,13 @@ - - - - - - - - - - - - - + + + + + + + @@ -110,6 +113,19 @@ + + + + + + + + + + + + + @@ -121,16 +137,9 @@ + - - - - - - - - diff --git a/od-win32/uaeunp/uaeunp.vcxproj.filters b/od-win32/uaeunp/uaeunp.vcxproj.filters index 3309a319..0ec46436 100644 --- a/od-win32/uaeunp/uaeunp.vcxproj.filters +++ b/od-win32/uaeunp/uaeunp.vcxproj.filters @@ -14,31 +14,31 @@ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - {ca0293dc-074a-4abd-a3e4-d5e0073cf020} + {74332802-0dea-481d-8688-6ea8ca3894c9} - {0672cade-bb56-4711-b392-347640e8262d} + {1d6748ee-1e71-4481-b70b-48abbd6579e1} - {a1cca94f-8e58-4e1b-8db2-e1edc73cd5bb} + {9a350565-10e0-4d98-af19-c89cf863c69d} - {8d6365e3-4612-4fb8-8bd4-ffa4704bbb3b} + {7b5944b8-15c4-46bf-b99c-24b604e0a523} - {e221241b-fb65-47f9-a202-bfcb00e61e63} + {3b89358e-ed9f-42d8-a330-90ad0878add0} - {fcf52458-bcf3-411a-b732-dbd936599ae1} + {43f24f87-b713-4df6-aeac-884f63457258} - {50925ec6-0d6f-4b8f-b0bb-3719bf0cee8e} + {0f91f71a-54cd-4ee8-b2d2-71e72654b6f7} - {b7bcc77a-4dbe-4a62-b593-5ce995fb31d9} + {c14490cb-e12c-4dea-9399-f34fd8d6cf23} - {1cf030c6-ec59-44fc-b272-6d40bb977515} + {9656c755-8b1f-4d77-b6ce-ef9f7c8405e2} diff --git a/od-win32/unicode.c b/od-win32/unicode.c index 480b67dd..2dbcbcb0 100644 --- a/od-win32/unicode.c +++ b/od-win32/unicode.c @@ -7,134 +7,134 @@ static void err (const char *func, const WCHAR *w, const char *c, UINT cp) { #if 0 - FILE *f; - uae_u8 zero[2] = { 0 }; - DWORD err = GetLastError (); - - f = fopen ("output.dat", "a"); - fwrite (func, strlen (func) + 1, 1, f); - if (w) - fwrite (w, wcslen (w) + 1, 2, f); - else - fwrite (zero, 1, 2, f); - if (c) - fwrite (c, strlen (c) + 1, 1, f); - else - fwrite (zero, 1, 1, f); - fwrite (&err, 4, 1, f); - fclose (f); - write_log (L"CP=%d,ERR=%d\n", cp, err); + FILE *f; + uae_u8 zero[2] = { 0 }; + DWORD err = GetLastError (); + + f = fopen ("output.dat", "a"); + fwrite (func, strlen (func) + 1, 1, f); + if (w) + fwrite (w, wcslen (w) + 1, 2, f); + else + fwrite (zero, 1, 2, f); + if (c) + fwrite (c, strlen (c) + 1, 1, f); + else + fwrite (zero, 1, 1, f); + fwrite (&err, 4, 1, f); + fclose (f); + write_log (L"CP=%d,ERR=%d\n", cp, err); #endif } char *uutf8 (const WCHAR *s) { - char *d; - int len; - - if (s == NULL) - return NULL; - len = WideCharToMultiByte (CP_UTF8, 0, s, -1, NULL, 0, 0, FALSE); - if (!len) { - err (__FUNCTION__, s, NULL, CP_UTF8); - return strdup (""); - } - d = xmalloc (len + 1); - WideCharToMultiByte (CP_UTF8, 0, s, -1, d, len, 0, FALSE); - return d; + char *d; + int len; + + if (s == NULL) + return NULL; + len = WideCharToMultiByte (CP_UTF8, 0, s, -1, NULL, 0, 0, FALSE); + if (!len) { + err (__FUNCTION__, s, NULL, CP_UTF8); + return strdup (""); + } + d = xmalloc (len + 1); + WideCharToMultiByte (CP_UTF8, 0, s, -1, d, len, 0, FALSE); + return d; } WCHAR *utf8u (const char *s) { - WCHAR *d; - int len; - - if (s == NULL) - return NULL; - len = MultiByteToWideChar (CP_UTF8, 0, s, -1, NULL, 0); - if (!len) { - err (__FUNCTION__, NULL, s, CP_UTF8); - return xcalloc (2, 1); - } - d = xmalloc ((len + 1) * sizeof (WCHAR)); - MultiByteToWideChar (CP_UTF8, 0, s, -1, d, len); - return d; + WCHAR *d; + int len; + + if (s == NULL) + return NULL; + len = MultiByteToWideChar (CP_UTF8, 0, s, -1, NULL, 0); + if (!len) { + err (__FUNCTION__, NULL, s, CP_UTF8); + return xcalloc (2, 1); + } + d = xmalloc ((len + 1) * sizeof (WCHAR)); + MultiByteToWideChar (CP_UTF8, 0, s, -1, d, len); + return d; } static char *ua_2 (const WCHAR *s, UINT cp) { - char *d; - int len; - - if (s == NULL) - return NULL; - len = WideCharToMultiByte (cp, 0, s, -1, NULL, 0, 0, FALSE); - if (!len) { - err (__FUNCTION__, s, NULL, cp); - return strdup (""); - } - d = xmalloc (len + 1); - WideCharToMultiByte (cp, 0, s, -1, d, len, 0, FALSE); - return d; + char *d; + int len; + + if (s == NULL) + return NULL; + len = WideCharToMultiByte (cp, 0, s, -1, NULL, 0, 0, FALSE); + if (!len) { + err (__FUNCTION__, s, NULL, cp); + return strdup (""); + } + d = xmalloc (len + 1); + WideCharToMultiByte (cp, 0, s, -1, d, len, 0, FALSE); + return d; } char *ua (const WCHAR *s) { - return ua_2 (s, CP_ACP); + return ua_2 (s, CP_ACP); } char *uacp (const WCHAR *s, UINT cp) { - return ua_2 (s, cp); + return ua_2 (s, cp); } static WCHAR *au_2 (const char *s, UINT cp) { - WCHAR *d; - int len; - - if (s == NULL) - return NULL; - len = MultiByteToWideChar (cp, 0, s, -1, NULL, 0); - if (!len) { - err (__FUNCTION__, NULL, s, cp); - return xcalloc (2, 1); - } - d = xmalloc ((len + 1) * sizeof (WCHAR)); - MultiByteToWideChar (cp, 0, s, -1, d, len); - return d; + WCHAR *d; + int len; + + if (s == NULL) + return NULL; + len = MultiByteToWideChar (cp, 0, s, -1, NULL, 0); + if (!len) { + err (__FUNCTION__, NULL, s, cp); + return xcalloc (2, 1); + } + d = xmalloc ((len + 1) * sizeof (WCHAR)); + MultiByteToWideChar (cp, 0, s, -1, d, len); + return d; } WCHAR *au (const char *s) { - return au_2 (s, CP_ACP); + return au_2 (s, CP_ACP); } WCHAR *aucp (const char *s, UINT cp) { - return au_2 (s, cp); + return au_2 (s, cp); } WCHAR *au_copy (TCHAR *dst, int maxlen, const char *src) { - MultiByteToWideChar (CP_ACP, 0, src, -1, dst, maxlen); - return dst; + MultiByteToWideChar (CP_ACP, 0, src, -1, dst, maxlen); + return dst; } WCHAR *aucp_copy (TCHAR *dst, int maxlen, const char *src, UINT cp) { - MultiByteToWideChar (cp, 0, src, -1, dst, maxlen); - return dst; + MultiByteToWideChar (cp, 0, src, -1, dst, maxlen); + return dst; } char *ua_copy (char *dst, int maxlen, const TCHAR *src) { - WideCharToMultiByte (CP_ACP, 0, src, -1, dst, maxlen, 0, FALSE); - return dst; + WideCharToMultiByte (CP_ACP, 0, src, -1, dst, maxlen, 0, FALSE); + return dst; } char *uacp_copy (char *dst, int maxlen, const TCHAR *src, UINT cp) { - WideCharToMultiByte (cp, 0, src, -1, dst, maxlen, 0, FALSE); - return dst; + WideCharToMultiByte (cp, 0, src, -1, dst, maxlen, 0, FALSE); + return dst; } TCHAR *my_strdup_ansi (const char *src) { - return au (src); + return au (src); } diff --git a/od-win32/win32.c b/od-win32/win32.c index 0f533c9c..2cb62bf2 100644 --- a/od-win32/win32.c +++ b/od-win32/win32.c @@ -1,11 +1,11 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 interface - * - * Copyright 1997-1998 Mathias Ortmann - * Copyright 1997-1999 Brian King - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 interface +* +* Copyright 1997-1998 Mathias Ortmann +* Copyright 1997-1999 Brian King +*/ //#define MEMDEBUG @@ -168,281 +168,287 @@ static TCHAR *inipath = NULL; static int timeend (void) { - if (!timeon) - return 1; - timeon = 0; - if (timeEndPeriod (mm_timerres) == TIMERR_NOERROR) - return 1; - write_log (L"TimeEndPeriod() failed\n"); - return 0; + if (!timeon) + return 1; + timeon = 0; + if (timeEndPeriod (mm_timerres) == TIMERR_NOERROR) + return 1; + write_log (L"TimeEndPeriod() failed\n"); + return 0; } static int timebegin (void) { - if (timeon) { - timeend (); - return timebegin (); - } - timeon = 0; - if (timeBeginPeriod (mm_timerres) == TIMERR_NOERROR) { - timeon = 1; - return 1; - } - write_log (L"TimeBeginPeriod() failed\n"); - return 0; + if (timeon) { + timeend (); + return timebegin (); + } + timeon = 0; + if (timeBeginPeriod (mm_timerres) == TIMERR_NOERROR) { + timeon = 1; + return 1; + } + write_log (L"TimeBeginPeriod() failed\n"); + return 0; } static int init_mmtimer (void) { - TIMECAPS tc; - int i; + TIMECAPS tc; + int i; - mm_timerres = 0; - if (timeGetDevCaps (&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) - return 0; - mm_timerres = min (max (tc.wPeriodMin, 1), tc.wPeriodMax); - sleep_resolution = 1000 / mm_timerres; - for (i = 0; i < MAX_TIMEHANDLES; i++) - timehandle[i] = CreateEvent (NULL, TRUE, FALSE, NULL); - InitializeCriticalSection (&cs_time); - timehandlecounter = 0; - return 1; + mm_timerres = 0; + if (timeGetDevCaps (&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) + return 0; + mm_timerres = min (max (tc.wPeriodMin, 1), tc.wPeriodMax); + sleep_resolution = 1000 / mm_timerres; + for (i = 0; i < MAX_TIMEHANDLES; i++) + timehandle[i] = CreateEvent (NULL, TRUE, FALSE, NULL); + InitializeCriticalSection (&cs_time); + timehandlecounter = 0; + return 1; } void sleep_millis (int ms) { - UINT TimerEvent; - int start; - int cnt; - - start = read_processor_time (); - EnterCriticalSection (&cs_time); - cnt = timehandlecounter++; - if (timehandlecounter >= MAX_TIMEHANDLES) - timehandlecounter = 0; - LeaveCriticalSection (&cs_time); - TimerEvent = timeSetEvent (ms, 0, timehandle[cnt], 0, TIME_ONESHOT | TIME_CALLBACK_EVENT_SET); - WaitForSingleObject (timehandle[cnt], ms); - ResetEvent (timehandle[cnt]); - timeKillEvent (TimerEvent); - idletime += read_processor_time () - start; + UINT TimerEvent; + int start; + int cnt; + + start = read_processor_time (); + EnterCriticalSection (&cs_time); + cnt = timehandlecounter++; + if (timehandlecounter >= MAX_TIMEHANDLES) + timehandlecounter = 0; + LeaveCriticalSection (&cs_time); + TimerEvent = timeSetEvent (ms, 0, timehandle[cnt], 0, TIME_ONESHOT | TIME_CALLBACK_EVENT_SET); + WaitForSingleObject (timehandle[cnt], ms); + ResetEvent (timehandle[cnt]); + timeKillEvent (TimerEvent); + idletime += read_processor_time () - start; } frame_time_t read_processor_time_qpf (void) { - LARGE_INTEGER counter; - QueryPerformanceCounter (&counter); - if (qpcdivisor == 0) - return (frame_time_t)(counter.LowPart); - return (frame_time_t)(counter.QuadPart >> qpcdivisor); + LARGE_INTEGER counter; + QueryPerformanceCounter (&counter); + if (qpcdivisor == 0) + return (frame_time_t)(counter.LowPart); + return (frame_time_t)(counter.QuadPart >> qpcdivisor); } frame_time_t read_processor_time_rdtsc (void) { - frame_time_t foo = 0; + frame_time_t foo = 0; #if defined(X86_MSVC_ASSEMBLY) - frame_time_t bar; - __asm - { - rdtsc - mov foo, eax - mov bar, edx - } - /* very high speed CPU's RDTSC might overflow without this.. */ - foo >>= 6; - foo |= bar << 26; + frame_time_t bar; + __asm + { + rdtsc + mov foo, eax + mov bar, edx + } + /* very high speed CPU's RDTSC might overflow without this.. */ + foo >>= 6; + foo |= bar << 26; #endif - return foo; + return foo; } frame_time_t read_processor_time (void) { #if 0 - static int cnt; + static int cnt; - cnt++; - if (cnt > 1000000) { - write_log(L"**************\n"); - cnt = 0; - } + cnt++; + if (cnt > 1000000) { + write_log(L"**************\n"); + cnt = 0; + } #endif - if (userdtsc) - return read_processor_time_rdtsc (); - else - return read_processor_time_qpf (); + if (userdtsc) + return read_processor_time_rdtsc (); + else + return read_processor_time_qpf (); } #include static volatile int dummythread_die; static void _cdecl dummythread (void *dummy) { - SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_LOWEST); - while (!dummythread_die); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_LOWEST); + while (!dummythread_die); } static uae_u64 win32_read_processor_time (void) { #if defined(X86_MSVC_ASSEMBLY) - uae_u32 foo, bar; - __asm - { - cpuid - rdtsc - mov foo, eax - mov bar, edx - } - return (((uae_u64)bar) << 32) | foo; + uae_u32 foo, bar; + __asm + { + cpuid + rdtsc + mov foo, eax + mov bar, edx + } + return (((uae_u64)bar) << 32) | foo; #else - return 0; + return 0; #endif } static void figure_processor_speed_rdtsc (void) { - static int freqset; - uae_u64 clockrate; - int oldpri; - HANDLE th; - - if (freqset) - return; - th = GetCurrentThread (); - freqset = 1; - oldpri = GetThreadPriority (th); - SetThreadPriority (th, THREAD_PRIORITY_HIGHEST); - dummythread_die = -1; - CloseHandle((HANDLE)_beginthread (&dummythread, 0, 0)); - sleep_millis (500); - clockrate = win32_read_processor_time (); - sleep_millis (500); - clockrate = (win32_read_processor_time () - clockrate) * 2; - dummythread_die = 0; - SetThreadPriority (th, oldpri); - write_log (L"CLOCKFREQ: RDTSC %.2fMHz\n", clockrate / 1000000.0); - syncbase = clockrate >> 6; + static int freqset; + uae_u64 clockrate; + int oldpri; + HANDLE th; + + if (freqset) + return; + th = GetCurrentThread (); + freqset = 1; + oldpri = GetThreadPriority (th); + SetThreadPriority (th, THREAD_PRIORITY_HIGHEST); + dummythread_die = -1; + CloseHandle((HANDLE)_beginthread (&dummythread, 0, 0)); + sleep_millis (500); + clockrate = win32_read_processor_time (); + sleep_millis (500); + clockrate = (win32_read_processor_time () - clockrate) * 2; + dummythread_die = 0; + SetThreadPriority (th, oldpri); + write_log (L"CLOCKFREQ: RDTSC %.2fMHz\n", clockrate / 1000000.0); + syncbase = clockrate >> 6; } static void figure_processor_speed_qpf (void) { - LARGE_INTEGER freq; - static LARGE_INTEGER freq2; - uae_u64 qpfrate; - - if (!QueryPerformanceFrequency (&freq)) - return; - if (freq.QuadPart == freq2.QuadPart) - return; - freq2.QuadPart = freq.QuadPart; - qpfrate = freq.QuadPart; - /* limit to 10MHz */ - qpcdivisor = 0; - while (qpfrate > 10000000) { - qpfrate >>= 1; - qpcdivisor++; - } - write_log (L"CLOCKFREQ: QPF %.2fMHz (%.2fMHz, DIV=%d)\n", freq.QuadPart / 1000000.0, - qpfrate / 1000000.0, 1 << qpcdivisor); - syncbase = (unsigned long)qpfrate; + LARGE_INTEGER freq; + static LARGE_INTEGER freq2; + uae_u64 qpfrate; + + if (!QueryPerformanceFrequency (&freq)) + return; + if (freq.QuadPart == freq2.QuadPart) + return; + freq2.QuadPart = freq.QuadPart; + qpfrate = freq.QuadPart; + /* limit to 10MHz */ + qpcdivisor = 0; + while (qpfrate > 10000000) { + qpfrate >>= 1; + qpcdivisor++; + } + write_log (L"CLOCKFREQ: QPF %.2fMHz (%.2fMHz, DIV=%d)\n", freq.QuadPart / 1000000.0, + qpfrate / 1000000.0, 1 << qpcdivisor); + syncbase = (unsigned long)qpfrate; } static void figure_processor_speed (void) { - if (SystemInfo.dwNumberOfProcessors > 1) - userdtsc = 0; - if (userdtsc) - figure_processor_speed_rdtsc (); - if (!userdtsc) - figure_processor_speed_qpf (); + if (SystemInfo.dwNumberOfProcessors > 1) + userdtsc = 0; + if (userdtsc) + figure_processor_speed_rdtsc (); + if (!userdtsc) + figure_processor_speed_qpf (); } static void setcursor (int oldx, int oldy) { - int x = (amigawin_rect.right - amigawin_rect.left) / 2; - int y = (amigawin_rect.bottom - amigawin_rect.top) / 2; - mouseposx = oldx - x; - mouseposy = oldy - y; - - if (currprefs.input_magic_mouse && currprefs.input_tablet > 0 && mousehack_alive () && isfullscreen () <= 0) { - mouseposx = mouseposy = 0; - return; - } + int x = (amigawin_rect.right - amigawin_rect.left) / 2; + int y = (amigawin_rect.bottom - amigawin_rect.top) / 2; + mouseposx = oldx - x; + mouseposy = oldy - y; + + if (currprefs.input_magic_mouse && currprefs.input_tablet > 0 && mousehack_alive () && isfullscreen () <= 0) { + mouseposx = mouseposy = 0; + return; + } #if 0 - write_log (L"%d %d %d %d %d - %d %d %d %d %d\n", - x, amigawin_rect.left, amigawin_rect.right, mouseposx, oldx, - y, amigawin_rect.top, amigawin_rect.bottom, mouseposy, oldy); + write_log (L"%d %d %d %d %d - %d %d %d %d %d\n", + x, amigawin_rect.left, amigawin_rect.right, mouseposx, oldx, + y, amigawin_rect.top, amigawin_rect.bottom, mouseposy, oldy); #endif - if (oldx >= 30000 || oldy >= 30000 || oldx <= -30000 || oldy <= -30000) { + if (oldx >= 30000 || oldy >= 30000 || oldx <= -30000 || oldy <= -30000) { + mouseposx = mouseposy = 0; + oldx = oldy = 0; + } else { + if (abs (mouseposx) < 50 && abs (mouseposy) < 50) + return; + } mouseposx = mouseposy = 0; - oldx = oldy = 0; - } else { - if (abs (mouseposx) < 50 && abs (mouseposy) < 50) - return; - } - mouseposx = mouseposy = 0; - if (oldx < 0 || oldy < 0 || oldx > amigawin_rect.right - amigawin_rect.left || oldy > amigawin_rect.bottom - amigawin_rect.top) { - write_log (L"Mouse out of range: %dx%d (%dx%d %dx%d)\n", oldx, oldy, - amigawin_rect.left, amigawin_rect.top, amigawin_rect.right, amigawin_rect.bottom); - return; - } - SetCursorPos (amigawin_rect.left + x, amigawin_rect.top + y); + if (oldx < 0 || oldy < 0 || oldx > amigawin_rect.right - amigawin_rect.left || oldy > amigawin_rect.bottom - amigawin_rect.top) { + write_log (L"Mouse out of range: %dx%d (%dx%d %dx%d)\n", oldx, oldy, + amigawin_rect.left, amigawin_rect.top, amigawin_rect.right, amigawin_rect.bottom); + return; + } + SetCursorPos (amigawin_rect.left + x, amigawin_rect.top + y); } static int pausemouseactive; void resumesoundpaused (void) { - resume_sound (); + resume_sound (); #ifdef AHI - ahi_open_sound (); - ahi2_pause_sound (0); + ahi_open_sound (); + ahi2_pause_sound (0); #endif } void setsoundpaused (void) { - pause_sound (); + pause_sound (); #ifdef AHI - ahi_close_sound (); - ahi2_pause_sound (1); + ahi_close_sound (); + ahi2_pause_sound (1); #endif } -void resumepaused (void) +void resumepaused (int priority) { - resumesoundpaused (); + //write_log (L"resume %d (%d)\n", priority, pause_emulation); + if (pause_emulation > priority) + return; + resumesoundpaused (); #ifdef CD32 - akiko_exitgui (); + akiko_exitgui (); #endif #ifdef CDTV - cdtv_exitgui (); + cdtv_exitgui (); #endif - if (pausemouseactive) - setmouseactive (-1); - pausemouseactive = 0; - pause_emulation = FALSE; + if (pausemouseactive) + setmouseactive (-1); + pausemouseactive = 0; + pause_emulation = 0; #ifdef RETROPLATFORM - rp_pause (pause_emulation); + rp_pause (pause_emulation); #endif } -void setpaused (void) +void setpaused (int priority) { - pause_emulation = TRUE; - setsoundpaused (); + //write_log (L"pause %d (%d)\n", priority, pause_emulation); + if (pause_emulation > priority) + return; + pause_emulation = priority; + setsoundpaused (); #ifdef CD32 - akiko_entergui (); + akiko_entergui (); #endif #ifdef CDTV - cdtv_entergui (); + cdtv_entergui (); #endif - pausemouseactive = 1; - if (isfullscreen () <= 0) { - pausemouseactive = mouseactive; - setmouseactive (0); - } + pausemouseactive = 1; + if (isfullscreen () <= 0) { + pausemouseactive = mouseactive; + setmouseactive (0); + } #ifdef RETROPLATFORM - rp_pause (pause_emulation); + rp_pause (pause_emulation); #endif } static void checkpause (void) { - if (currprefs.win32_inactive_pause) { - setpaused (); - setpriority (&priorities[currprefs.win32_inactive_priority]); - } + if (currprefs.win32_inactive_pause) { + setpaused (1); + setpriority (&priorities[currprefs.win32_inactive_priority]); + } } static int showcursor; @@ -451,36 +457,36 @@ extern TCHAR config_filename[MAX_DPATH]; static void setmaintitle (HWND hwnd) { - TCHAR txt[1000], txt2[500]; + TCHAR txt[1000], txt2[500]; #ifdef RETROPLATFORM - if (rp_isactive ()) - return; + if (rp_isactive ()) + return; #endif - txt[0] = 0; - if (config_filename[0]) { - _tcscat (txt, L"["); - _tcscat (txt, config_filename); - _tcscat (txt, L"] - "); - } - _tcscat (txt, L"WinUAE"); - txt2[0] = 0; - if (mouseactive > 0) { - WIN32GUI_LoadUIString (currprefs.win32_middle_mouse ? IDS_WINUAETITLE_MMB : IDS_WINUAETITLE_NORMAL, - txt2, sizeof (txt2) / sizeof (TCHAR)); - } - if (_tcslen (WINUAEBETA) > 0) { - _tcscat (txt, BetaStr); - if (_tcslen (WINUAEEXTRA) > 0) { - _tcscat (txt, L" "); - _tcscat (txt, WINUAEEXTRA); - } - } - if (txt2[0]) { - _tcscat (txt, L" - "); - _tcscat (txt, txt2); - } - SetWindowText (hwnd, txt); + txt[0] = 0; + if (config_filename[0]) { + _tcscat (txt, L"["); + _tcscat (txt, config_filename); + _tcscat (txt, L"] - "); + } + _tcscat (txt, L"WinUAE"); + txt2[0] = 0; + if (mouseactive > 0) { + WIN32GUI_LoadUIString (currprefs.win32_middle_mouse ? IDS_WINUAETITLE_MMB : IDS_WINUAETITLE_NORMAL, + txt2, sizeof (txt2) / sizeof (TCHAR)); + } + if (_tcslen (WINUAEBETA) > 0) { + _tcscat (txt, BetaStr); + if (_tcslen (WINUAEEXTRA) > 0) { + _tcscat (txt, L" "); + _tcscat (txt, WINUAEEXTRA); + } + } + if (txt2[0]) { + _tcscat (txt, L" - "); + _tcscat (txt, txt2); + } + SetWindowText (hwnd, txt); } @@ -490,1107 +496,1111 @@ static int avioutput_video = 0; void setpriority (struct threadpriorities *pri) { - int err; - DWORD opri = GetPriorityClass (GetCurrentProcess ()); - - if (opri != IDLE_PRIORITY_CLASS && opri != NORMAL_PRIORITY_CLASS && opri != BELOW_NORMAL_PRIORITY_CLASS && opri != ABOVE_NORMAL_PRIORITY_CLASS) - return; - err = SetPriorityClass (GetCurrentProcess (), pri->classvalue); - if (!err) - write_log (L"priority set failed, %08X\n", GetLastError ()); + int err; + DWORD opri = GetPriorityClass (GetCurrentProcess ()); + + if (opri != IDLE_PRIORITY_CLASS && opri != NORMAL_PRIORITY_CLASS && opri != BELOW_NORMAL_PRIORITY_CLASS && opri != ABOVE_NORMAL_PRIORITY_CLASS) + return; + err = SetPriorityClass (GetCurrentProcess (), pri->classvalue); + if (!err) + write_log (L"priority set failed, %08X\n", GetLastError ()); } static void setcursorshape (void) { - if (currprefs.input_tablet && currprefs.input_magic_mouse && currprefs.input_magic_mouse_cursor == MAGICMOUSE_NATIVE_ONLY) { - if (GetCursor () != NULL) - SetCursor (NULL); - } else if (!picasso_setwincursor ()) { - if (GetCursor () != normalcursor) - SetCursor (normalcursor); - } + if (currprefs.input_tablet && currprefs.input_magic_mouse && currprefs.input_magic_mouse_cursor == MAGICMOUSE_NATIVE_ONLY) { + if (GetCursor () != NULL) + SetCursor (NULL); + } else if (!picasso_setwincursor ()) { + if (GetCursor () != normalcursor) + SetCursor (normalcursor); + } } static void releasecapture (void) { - if (!showcursor) - return; - ClipCursor (NULL); - ReleaseCapture (); - ShowCursor (TRUE); - showcursor = 0; + if (!showcursor) + return; + ClipCursor (NULL); + ReleaseCapture (); + ShowCursor (TRUE); + showcursor = 0; } void setmouseactive (int active) { - //write_log (L"setmouseactive %d->%d\n", mouseactive, active); - if (active == 0) + //write_log (L"setmouseactive %d->%d\n", mouseactive, active); + if (active == 0) + releasecapture (); + if (mouseactive == active && active >= 0) + return; + + if (active == 1 && !currprefs.input_magic_mouse) { + HANDLE c = GetCursor (); + if (c != normalcursor) + return; + } + if (active) { + if (IsWindowVisible (hAmigaWnd) == FALSE) + return; + } + + if (active < 0) + active = 1; + + mouseactive = active; + + mouseposx = mouseposy = 0; + //write_log (L"setmouseactive(%d)\n", active); releasecapture (); - if (mouseactive == active && active >= 0) - return; - - if (active == 1 && !currprefs.input_magic_mouse) { - HANDLE c = GetCursor (); - if (c != normalcursor) - return; - } - if (active) { - if (IsWindowVisible (hAmigaWnd) == FALSE) - return; - } - - if (active < 0) - active = 1; - - mouseactive = active; - - mouseposx = mouseposy = 0; - //write_log (L"setmouseactive(%d)\n", active); - releasecapture (); - recapture = 0; - - if (isfullscreen () <= 0 && currprefs.input_magic_mouse && currprefs.input_tablet > 0) { - if (mousehack_alive ()) - return; - SetCursor (normalcursor); - } - - if (mouseactive > 0) - focus = 1; - if (focus) { - int donotfocus = 0; - HWND fw = GetForegroundWindow (); - HWND w1 = hAmigaWnd; - HWND w2 = hMainWnd; - HWND w3 = NULL; + recapture = 0; + + if (isfullscreen () <= 0 && currprefs.input_magic_mouse && currprefs.input_tablet > 0) { + if (mousehack_alive ()) + return; + SetCursor (normalcursor); + } + + if (mouseactive > 0) + focus = 1; + if (focus) { + int donotfocus = 0; + HWND fw = GetForegroundWindow (); + HWND w1 = hAmigaWnd; + HWND w2 = hMainWnd; + HWND w3 = NULL; #ifdef RETROPLATFORM - if (rp_isactive ()) - w3 = rp_getparent (); + if (rp_isactive ()) + w3 = rp_getparent (); #endif - if (isfullscreen () > 0 || (!(fw == w1 || fw == w2))) { - if (SetForegroundWindow (w2) == FALSE) { - if (SetForegroundWindow (w1) == FALSE) { - if (w3 == NULL || SetForegroundWindow (w3) == FALSE) { - donotfocus = 1; - write_log (L"wanted focus but SetForegroundWindow() failed\n"); - } + if (isfullscreen () > 0 || (!(fw == w1 || fw == w2))) { + if (SetForegroundWindow (w2) == FALSE) { + if (SetForegroundWindow (w1) == FALSE) { + if (w3 == NULL || SetForegroundWindow (w3) == FALSE) { + donotfocus = 1; + write_log (L"wanted focus but SetForegroundWindow() failed\n"); + } + } + } } - } - } #ifdef RETROPLATFORM - if (rp_isactive () && isfullscreen () == 0) - donotfocus = 0; + if (rp_isactive () && isfullscreen () == 0) + donotfocus = 0; #endif - if (isfullscreen () > 0) - donotfocus = 0; - if (donotfocus) { - focus = 0; - mouseactive = 0; + if (isfullscreen () > 0) + donotfocus = 0; + if (donotfocus) { + focus = 0; + mouseactive = 0; + } } - } - if (mouseactive) { - if (focus) { - if (!showcursor) { - ShowCursor (FALSE); - SetCapture (hAmigaWnd); - ClipCursor (&amigawin_rect); - } - showcursor = 1; - setcursor (-30000, -30000); + if (mouseactive) { + if (focus) { + if (!showcursor) { + ShowCursor (FALSE); + SetCapture (hAmigaWnd); + ClipCursor (&amigawin_rect); + } + showcursor = 1; + setcursor (-30000, -30000); + } + inputdevice_acquire (TRUE); + setpriority (&priorities[currprefs.win32_active_priority]); + } else { + inputdevice_acquire (FALSE); } - inputdevice_acquire (TRUE); - setpriority (&priorities[currprefs.win32_active_priority]); - } else { - inputdevice_acquire (FALSE); - } - if (!active) - checkpause (); - setmaintitle (hMainWnd); + if (!active) + checkpause (); + setmaintitle (hMainWnd); #ifdef RETROPLATFORM - rp_mouse_capture (active); - rp_mouse_magic (magicmouse_alive ()); + rp_mouse_capture (active); + rp_mouse_magic (magicmouse_alive ()); #endif } static void winuae_active (HWND hWnd, int minimized) { - struct threadpriorities *pri; - - write_log (L"winuae_active(%d)\n", minimized); - /* without this returning from hibernate-mode causes wrong timing - */ - timeend (); - sleep_millis (2); - timebegin (); - - focus = 1; - pri = &priorities[currprefs.win32_inactive_priority]; - if (!minimized) - pri = &priorities[currprefs.win32_active_priority]; - setpriority (pri); - - if (!avioutput_video) { - clear_inhibit_frame (IHF_WINDOWHIDDEN); - } - if (sound_closed) { - if (sound_closed < 0) - resumesoundpaused (); - else - resumepaused (); - sound_closed = 0; - } - if (WIN32GFX_IsPicassoScreen ()) - WIN32GFX_EnablePicasso (); - getcapslock (); - inputdevice_acquire (FALSE); - wait_keyrelease (); - inputdevice_acquire (TRUE); - if (isfullscreen() > 0 && !gui_active) - setmouseactive (1); - manual_palette_refresh_needed = 1; + struct threadpriorities *pri; + + write_log (L"winuae_active(%d)\n", minimized); + /* without this returning from hibernate-mode causes wrong timing + */ + timeend (); + sleep_millis (2); + timebegin (); + + focus = 1; + pri = &priorities[currprefs.win32_inactive_priority]; + if (!minimized) + pri = &priorities[currprefs.win32_active_priority]; + setpriority (pri); + + if (!avioutput_video) { + clear_inhibit_frame (IHF_WINDOWHIDDEN); + } + if (sound_closed) { + if (sound_closed < 0) { + resumesoundpaused (); + } else { + if (currprefs.win32_iconified_pause) + resumepaused (1); + if (currprefs.win32_inactive_pause) + resumepaused (2); + } + sound_closed = 0; + } + if (WIN32GFX_IsPicassoScreen ()) + WIN32GFX_EnablePicasso (); + getcapslock (); + inputdevice_acquire (FALSE); + wait_keyrelease (); + inputdevice_acquire (TRUE); + if (isfullscreen() > 0 && !gui_active) + setmouseactive (1); + manual_palette_refresh_needed = 1; #ifdef LOGITECHLCD - if (!minimized) - lcd_priority (1); + if (!minimized) + lcd_priority (1); #endif - clipboard_active (hAmigaWnd, 1); - SetThreadExecutionState (ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + clipboard_active (hAmigaWnd, 1); + SetThreadExecutionState (ES_CONTINUOUS | ES_DISPLAY_REQUIRED); #if 0 - if (os_vista && AVTask == NULL) { - DWORD taskIndex = 0; - AVTask = AvSetMmThreadCharacteristics (TEXT("Games"), &taskIndex); - } + if (os_vista && AVTask == NULL) { + DWORD taskIndex = 0; + AVTask = AvSetMmThreadCharacteristics (TEXT("Games"), &taskIndex); + } #endif } static void winuae_inactive (HWND hWnd, int minimized) { - struct threadpriorities *pri; - int wasfocus = focus; + struct threadpriorities *pri; + int wasfocus = focus; - write_log (L"winuae_inactive(%d)\n", minimized); + write_log (L"winuae_inactive(%d)\n", minimized); #if 0 - if (AVTask) - AvRevertMmThreadCharacteristics (AVTask); - AVTask = NULL; + if (AVTask) + AvRevertMmThreadCharacteristics (AVTask); + AVTask = NULL; #endif - if (!currprefs.win32_powersavedisabled) - SetThreadExecutionState (ES_CONTINUOUS); - if (minimized) - exit_gui (0); - focus = 0; - wait_keyrelease (); - setmouseactive (0); - clipboard_active (hAmigaWnd, 0); - inputdevice_unacquire (); - pri = &priorities[currprefs.win32_inactive_priority]; - if (!quit_program) { - if (minimized) { - pri = &priorities[currprefs.win32_iconified_priority]; - if (currprefs.win32_iconified_pause) { - setpaused (); - sound_closed = 1; - } else if (currprefs.win32_iconified_nosound) { - setsoundpaused (); - sound_closed = -1; - } - if (!avioutput_video) { - set_inhibit_frame (IHF_WINDOWHIDDEN); - } - } else { - if (currprefs.win32_inactive_pause) { - setpaused (); - sound_closed = 1; - } else if (currprefs.win32_inactive_nosound) { - setsoundpaused (); - sound_closed = -1; - } - } - } - setpriority (pri); + if (!currprefs.win32_powersavedisabled) + SetThreadExecutionState (ES_CONTINUOUS); + if (minimized) + exit_gui (0); + focus = 0; + wait_keyrelease (); + setmouseactive (0); + clipboard_active (hAmigaWnd, 0); + inputdevice_unacquire (); + pri = &priorities[currprefs.win32_inactive_priority]; + if (!quit_program) { + if (minimized) { + pri = &priorities[currprefs.win32_iconified_priority]; + if (currprefs.win32_iconified_pause) { + setpaused (1); + sound_closed = 1; + } else if (currprefs.win32_iconified_nosound) { + setsoundpaused (); + sound_closed = -1; + } + if (!avioutput_video) { + set_inhibit_frame (IHF_WINDOWHIDDEN); + } + } else { + if (currprefs.win32_inactive_pause) { + setpaused (2); + sound_closed = 1; + } else if (currprefs.win32_inactive_nosound) { + setsoundpaused (); + sound_closed = -1; + } + } + } + setpriority (pri); #ifdef FILESYS - filesys_flush_cache (); + filesys_flush_cache (); #endif #ifdef LOGITECHLCD - lcd_priority (0); + lcd_priority (0); #endif } void minimizewindow (void) { - ShowWindow (hMainWnd, SW_MINIMIZE); + ShowWindow (hMainWnd, SW_MINIMIZE); } void disablecapture (void) { - setmouseactive (0); + setmouseactive (0); } void setmouseactivexy (int x, int y, int dir) { - int diff = 8; - - if (isfullscreen () > 0) - return; - x += amigawin_rect.left; - y += amigawin_rect.top; - if (dir & 1) - x = amigawin_rect.left - diff; - if (dir & 2) - x = amigawin_rect.right + diff; - if (dir & 4) - y = amigawin_rect.top - diff; - if (dir & 8) - y = amigawin_rect.bottom + diff; - if (!dir) { - x += (amigawin_rect.right - amigawin_rect.left) / 2; - y += (amigawin_rect.bottom - amigawin_rect.top) / 2; - } - if (mouseactive) { - disablecapture (); - SetCursorPos (x, y); - if (dir) - recapture = 1; - } + int diff = 8; + + if (isfullscreen () > 0) + return; + x += amigawin_rect.left; + y += amigawin_rect.top; + if (dir & 1) + x = amigawin_rect.left - diff; + if (dir & 2) + x = amigawin_rect.right + diff; + if (dir & 4) + y = amigawin_rect.top - diff; + if (dir & 8) + y = amigawin_rect.bottom + diff; + if (!dir) { + x += (amigawin_rect.right - amigawin_rect.left) / 2; + y += (amigawin_rect.bottom - amigawin_rect.top) / 2; + } + if (mouseactive) { + disablecapture (); + SetCursorPos (x, y); + if (dir) + recapture = 1; + } } int isfocus (void) { - if (isfullscreen () > 0) - return 1; - if (focus && mouseactive) - return 1; - if (focus) - return -1; - return 0; + if (isfullscreen () > 0) + return 1; + if (focus && mouseactive) + return 1; + if (focus) + return -1; + return 0; } static void handleXbutton (WPARAM wParam, int updown) { - int b = GET_XBUTTON_WPARAM (wParam); - int num = (b & XBUTTON1) ? 3 : (b & XBUTTON2) ? 4 : -1; - if (num >= 0) - setmousebuttonstate (dinput_winmouse (), num, updown); + int b = GET_XBUTTON_WPARAM (wParam); + int num = (b & XBUTTON1) ? 3 : (b & XBUTTON2) ? 4 : -1; + if (num >= 0) + setmousebuttonstate (dinput_winmouse (), num, updown); } #define MSGDEBUG 1 static LRESULT CALLBACK AmigaWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hDC; - int mx, my; - int istablet = (GetMessageExtraInfo () & 0xFFFFFF00) == 0xFF515700; - static int mm, minimized, recursive, ignoremousemove; + HDC hDC; + int mx, my; + int istablet = (GetMessageExtraInfo () & 0xFFFFFF00) == 0xFF515700; + static int mm, minimized, recursive, ignoremousemove; #if MSGDEBUG > 1 - write_log (L"AWP: %x %d\n", hWnd, message); + write_log (L"AWP: %x %d\n", hWnd, message); #endif - if (ignore_messages_all) - return DefWindowProc (hWnd, message, wParam, lParam); + if (ignore_messages_all) + return DefWindowProc (hWnd, message, wParam, lParam); - switch (message) - { + switch (message) + { - case WM_SETFOCUS: - winuae_active (hWnd, minimized); - minimized = 0; - dx_check (); - return 0; - case WM_ACTIVATE: - if (LOWORD (wParam) == WA_INACTIVE) { - minimized = HIWORD (wParam) ? 1 : 0; - winuae_inactive (hWnd, minimized); - } - dx_check (); - return 0; - case WM_ACTIVATEAPP: + case WM_SETFOCUS: + winuae_active (hWnd, minimized); + minimized = 0; + dx_check (); + return 0; + case WM_ACTIVATE: + if (LOWORD (wParam) == WA_INACTIVE) { + minimized = HIWORD (wParam) ? 1 : 0; + winuae_inactive (hWnd, minimized); + } + dx_check (); + return 0; + case WM_ACTIVATEAPP: #ifdef RETROPLATFORM - rp_activate (wParam, lParam); + rp_activate (wParam, lParam); #endif - dx_check (); - return 0; + dx_check (); + return 0; - case WM_PALETTECHANGED: - if ((HWND)wParam != hWnd) - manual_palette_refresh_needed = 1; - return 0; - - case WM_KEYDOWN: - if (dinput_wmkey ((uae_u32)lParam)) - inputdevice_add_inputcode (AKS_ENTERGUI, 1); - return 0; - - case WM_LBUTTONUP: - if (dinput_winmouse () >= 0 && isfocus ()) - setmousebuttonstate (dinput_winmouse (), 0, 0); - return 0; - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - if (!mouseactive && !gui_active && (!mousehack_alive () || currprefs.input_tablet != TABLET_MOUSEHACK || isfullscreen () > 0)) { - setmouseactive ((message == WM_LBUTTONDBLCLK || isfullscreen() > 0) ? 2 : 1); - } else if (dinput_winmouse () >= 0 && isfocus ()) { - setmousebuttonstate (dinput_winmouse (), 0, 1); - } - return 0; - case WM_RBUTTONUP: - if (dinput_winmouse () >= 0 && isfocus ()) - setmousebuttonstate (dinput_winmouse (), 1, 0); - return 0; - case WM_RBUTTONDOWN: - case WM_RBUTTONDBLCLK: - if (dinput_winmouse () >= 0 && isfocus ()) - setmousebuttonstate (dinput_winmouse (), 1, 1); - return 0; - case WM_MBUTTONUP: - if (!currprefs.win32_middle_mouse) { - if (dinput_winmouse () >= 0 && isfocus ()) - setmousebuttonstate (dinput_winmouse (), 2, 0); - } - return 0; - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: - if (currprefs.win32_middle_mouse) { + case WM_PALETTECHANGED: + if ((HWND)wParam != hWnd) + manual_palette_refresh_needed = 1; + return 0; + + case WM_KEYDOWN: + if (dinput_wmkey ((uae_u32)lParam)) + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + return 0; + + case WM_LBUTTONUP: + if (dinput_winmouse () >= 0 && isfocus ()) + setmousebuttonstate (dinput_winmouse (), 0, 0); + return 0; + case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: + if (!mouseactive && !gui_active && (!mousehack_alive () || currprefs.input_tablet != TABLET_MOUSEHACK || isfullscreen () > 0)) { + setmouseactive ((message == WM_LBUTTONDBLCLK || isfullscreen() > 0) ? 2 : 1); + } else if (dinput_winmouse () >= 0 && isfocus ()) { + setmousebuttonstate (dinput_winmouse (), 0, 1); + } + return 0; + case WM_RBUTTONUP: + if (dinput_winmouse () >= 0 && isfocus ()) + setmousebuttonstate (dinput_winmouse (), 1, 0); + return 0; + case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: + if (dinput_winmouse () >= 0 && isfocus ()) + setmousebuttonstate (dinput_winmouse (), 1, 1); + return 0; + case WM_MBUTTONUP: + if (!currprefs.win32_middle_mouse) { + if (dinput_winmouse () >= 0 && isfocus ()) + setmousebuttonstate (dinput_winmouse (), 2, 0); + } + return 0; + case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: + if (currprefs.win32_middle_mouse) { #ifndef _DEBUG - if (isfullscreen () > 0) - minimizewindow (); + if (isfullscreen () > 0) + minimizewindow (); #endif - if (mouseactive) - setmouseactive (0); - } else { - if (dinput_winmouse () >= 0 && isfocus ()) - setmousebuttonstate (dinput_winmouse (), 2, 1); - } - return 0; - case WM_XBUTTONUP: - if (dinput_winmouse () >= 0 && isfocus ()) { - handleXbutton (wParam, 0); - return TRUE; - } - return 0; - case WM_XBUTTONDOWN: - case WM_XBUTTONDBLCLK: - if (dinput_winmouse () >= 0 && isfocus ()) { - handleXbutton (wParam, 1); - return TRUE; - } - return 0; - case WM_MOUSEWHEEL: - if (dinput_winmouse () >= 0 && isfocus ()) { - int val = ((short)HIWORD (wParam)); - setmousestate (dinput_winmouse (), 2, val, 0); - if (val < 0) - setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 0, -1); - else if (val > 0) - setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 1, -1); - return TRUE; - } - return 0; - case WM_MOUSEHWHEEL: - if (dinput_winmouse () >= 0 && isfocus ()) { - int val = ((short)HIWORD (wParam)); - setmousestate (dinput_winmouse (), 3, val, 0); - if (val < 0) - setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 2, -1); - else if (val > 0) - setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 3, -1); - return TRUE; - } - return 0; - - case WM_PAINT: - { - static int recursive = 0; - if (recursive == 0) { - PAINTSTRUCT ps; - recursive++; - notice_screen_contents_lost (); - hDC = BeginPaint (hWnd, &ps); - /* Check to see if this WM_PAINT is coming while we've got the GUI visible */ - if (manual_painting_needed) - updatedisplayarea (); - EndPaint (hWnd, &ps); - if (manual_palette_refresh_needed) { - WIN32GFX_SetPalette (); + if (mouseactive) + setmouseactive (0); + } else { + if (dinput_winmouse () >= 0 && isfocus ()) + setmousebuttonstate (dinput_winmouse (), 2, 1); + } + return 0; + case WM_XBUTTONUP: + if (dinput_winmouse () >= 0 && isfocus ()) { + handleXbutton (wParam, 0); + return TRUE; + } + return 0; + case WM_XBUTTONDOWN: + case WM_XBUTTONDBLCLK: + if (dinput_winmouse () >= 0 && isfocus ()) { + handleXbutton (wParam, 1); + return TRUE; + } + return 0; + case WM_MOUSEWHEEL: + if (dinput_winmouse () >= 0 && isfocus ()) { + int val = ((short)HIWORD (wParam)); + setmousestate (dinput_winmouse (), 2, val, 0); + if (val < 0) + setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 0, -1); + else if (val > 0) + setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 1, -1); + return TRUE; + } + return 0; + case WM_MOUSEHWHEEL: + if (dinput_winmouse () >= 0 && isfocus ()) { + int val = ((short)HIWORD (wParam)); + setmousestate (dinput_winmouse (), 3, val, 0); + if (val < 0) + setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 2, -1); + else if (val > 0) + setmousebuttonstate (dinput_winmouse (), dinput_wheelbuttonstart () + 3, -1); + return TRUE; + } + return 0; + + case WM_PAINT: + { + static int recursive = 0; + if (recursive == 0) { + PAINTSTRUCT ps; + recursive++; + notice_screen_contents_lost (); + hDC = BeginPaint (hWnd, &ps); + /* Check to see if this WM_PAINT is coming while we've got the GUI visible */ + if (manual_painting_needed) + updatedisplayarea (); + EndPaint (hWnd, &ps); + if (manual_palette_refresh_needed) { + WIN32GFX_SetPalette (); #ifdef PICASSO96 - DX_SetPalette (0, 256); + DX_SetPalette (0, 256); #endif - } - manual_palette_refresh_needed = 0; - recursive--; - } - } - return 0; + } + manual_palette_refresh_needed = 0; + recursive--; + } + } + return 0; - case WM_DROPFILES: - dragdrop (hWnd, (HDROP)wParam, &changed_prefs, -1); - return 0; + case WM_DROPFILES: + dragdrop (hWnd, (HDROP)wParam, &changed_prefs, -1); + return 0; - case WM_TIMER: + case WM_TIMER: #ifdef PARALLEL_PORT - finishjob (); + finishjob (); #endif - return 0; + return 0; - case WM_CREATE: + case WM_CREATE: #ifdef RETROPLATFORM - rp_set_hwnd (hWnd); + rp_set_hwnd (hWnd); #endif - DragAcceptFiles (hWnd, TRUE); - tablet = open_tablet (hWnd); - normalcursor = LoadCursor (NULL, IDC_ARROW); - hwndNextViewer = SetClipboardViewer (hWnd); - clipboard_init (hWnd); - return 0; - - case WM_DESTROY: - ChangeClipboardChain (hWnd, hwndNextViewer); - close_tablet (tablet); - inputdevice_unacquire (); - dinput_window (); - return 0; + DragAcceptFiles (hWnd, TRUE); + tablet = open_tablet (hWnd); + normalcursor = LoadCursor (NULL, IDC_ARROW); + hwndNextViewer = SetClipboardViewer (hWnd); + clipboard_init (hWnd); + return 0; - case WM_CLOSE: - uae_quit (); - return 0; + case WM_DESTROY: + ChangeClipboardChain (hWnd, hwndNextViewer); + close_tablet (tablet); + inputdevice_unacquire (); + dinput_window (); + return 0; - case WM_SIZE: - if (hStatusWnd) - SendMessage (hStatusWnd, WM_SIZE, wParam, lParam); - break; + case WM_CLOSE: + uae_quit (); + return 0; - case WM_WINDOWPOSCHANGED: - { - WINDOWPOS *wp = (WINDOWPOS*)lParam; - if (isfullscreen () <= 0) { - if (!IsIconic (hWnd) && hWnd == hAmigaWnd) { - GetWindowRect (hWnd, &amigawin_rect); - if (isfullscreen () == 0) { - changed_prefs.gfx_size_win.x = amigawin_rect.left; - changed_prefs.gfx_size_win.y = amigawin_rect.top; + case WM_SIZE: + if (hStatusWnd) + SendMessage (hStatusWnd, WM_SIZE, wParam, lParam); + break; + + case WM_WINDOWPOSCHANGED: + { + WINDOWPOS *wp = (WINDOWPOS*)lParam; + if (isfullscreen () <= 0) { + if (!IsIconic (hWnd) && hWnd == hAmigaWnd) { + GetWindowRect (hWnd, &amigawin_rect); + if (isfullscreen () == 0) { + changed_prefs.gfx_size_win.x = amigawin_rect.left; + changed_prefs.gfx_size_win.y = amigawin_rect.top; + } + } + notice_screen_contents_lost (); + } } - } - notice_screen_contents_lost (); - } - } - break; + break; - case WM_SETCURSOR: - { - if ((HWND)wParam == hAmigaWnd && currprefs.input_tablet > 0 && currprefs.input_magic_mouse && isfullscreen () <= 0) { - if (mousehack_alive ()) { - setcursorshape (); - return 1; - } - } - break; - } - - case WM_MOUSEMOVE: - { - int wm = dinput_winmouse (); - - mx = (signed short) LOWORD (lParam); - my = (signed short) HIWORD (lParam); - mx -= mouseposx; - my -= mouseposy; - - //write_log (L"%d %d %d %d %d %d %d\n", wm, mouseactive, focus, mx, my, mouseposx, mouseposy); - if (recapture && isfullscreen () <= 0) { - setmouseactive (1); - return 0; - } - if (wm < 0 && (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK)) { - /* absolute */ - setmousestate (0, 0, mx, 1); - setmousestate (0, 1, my, 1); - return 0; - } - if (wm >= 0) { - if (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK) { - /* absolute */ - setmousestate (dinput_winmouse (), 0, mx, 1); - setmousestate (dinput_winmouse (), 1, my, 1); - return 0; - } - if (!focus || !mouseactive) - return DefWindowProc (hWnd, message, wParam, lParam); - if (dinput_winmousemode () == 0) { - /* relative */ - int mxx = (amigawin_rect.right - amigawin_rect.left) / 2; - int myy = (amigawin_rect.bottom - amigawin_rect.top) / 2; - mx = mx - mxx; - my = my - myy; - //write_log (L"%d:%dx%d\n", dinput_winmouse(), mx, my); - setmousestate (dinput_winmouse (), 0, mx, 0); - setmousestate (dinput_winmouse (), 1, my, 0); - } - } else if (isfocus () < 0 && (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK)) { - setmousestate (0, 0, mx, 1); - setmousestate (0, 1, my, 1); - } - if (showcursor || mouseactive) - setcursor (LOWORD (lParam), HIWORD (lParam)); - return 0; - } - break; - - case WM_MOVING: - { - LRESULT lr = DefWindowProc (hWnd, message, wParam, lParam); - WIN32GFX_WindowMove (); - return lr; - } - case WM_MOVE: - WIN32GFX_WindowMove (); - return FALSE; - - case WM_ENABLE: - rp_set_enabledisable (wParam ? 1 : 0); - return FALSE; + case WM_SETCURSOR: + { + if ((HWND)wParam == hAmigaWnd && currprefs.input_tablet > 0 && currprefs.input_magic_mouse && isfullscreen () <= 0) { + if (mousehack_alive ()) { + setcursorshape (); + return 1; + } + } + break; + } + + case WM_MOUSEMOVE: + { + int wm = dinput_winmouse (); + + mx = (signed short) LOWORD (lParam); + my = (signed short) HIWORD (lParam); + mx -= mouseposx; + my -= mouseposy; + + //write_log (L"%d %d %d %d %d %d %d\n", wm, mouseactive, focus, mx, my, mouseposx, mouseposy); + if (recapture && isfullscreen () <= 0) { + setmouseactive (1); + return 0; + } + if (wm < 0 && (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK)) { + /* absolute */ + setmousestate (0, 0, mx, 1); + setmousestate (0, 1, my, 1); + return 0; + } + if (wm >= 0) { + if (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK) { + /* absolute */ + setmousestate (dinput_winmouse (), 0, mx, 1); + setmousestate (dinput_winmouse (), 1, my, 1); + return 0; + } + if (!focus || !mouseactive) + return DefWindowProc (hWnd, message, wParam, lParam); + if (dinput_winmousemode () == 0) { + /* relative */ + int mxx = (amigawin_rect.right - amigawin_rect.left) / 2; + int myy = (amigawin_rect.bottom - amigawin_rect.top) / 2; + mx = mx - mxx; + my = my - myy; + //write_log (L"%d:%dx%d\n", dinput_winmouse(), mx, my); + setmousestate (dinput_winmouse (), 0, mx, 0); + setmousestate (dinput_winmouse (), 1, my, 0); + } + } else if (isfocus () < 0 && (istablet || currprefs.input_tablet >= TABLET_MOUSEHACK)) { + setmousestate (0, 0, mx, 1); + setmousestate (0, 1, my, 1); + } + if (showcursor || mouseactive) + setcursor (LOWORD (lParam), HIWORD (lParam)); + return 0; + } + break; + + case WM_MOVING: + { + LRESULT lr = DefWindowProc (hWnd, message, wParam, lParam); + WIN32GFX_WindowMove (); + return lr; + } + case WM_MOVE: + WIN32GFX_WindowMove (); + return FALSE; + + case WM_ENABLE: + rp_set_enabledisable (wParam ? 1 : 0); + return FALSE; #ifdef FILESYS - case WM_USER + 2: - { - typedef struct { - DWORD dwItem1; // dwItem1 contains the previous PIDL or name of the folder. - DWORD dwItem2; // dwItem2 contains the new PIDL or name of the folder. - } SHNOTIFYSTRUCT; - TCHAR path[MAX_PATH]; - - if (lParam == SHCNE_MEDIAINSERTED || lParam == SHCNE_MEDIAREMOVED) { - SHNOTIFYSTRUCT *shns = (SHNOTIFYSTRUCT*)wParam; - if (SHGetPathFromIDList ((struct _ITEMIDLIST *)(shns->dwItem1), path)) { - int inserted = lParam == SHCNE_MEDIAINSERTED ? 1 : 0; - UINT errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); - write_log (L"Shell Notification %d '%s'\n", inserted, path); - if (!win32_hardfile_media_change (path, inserted)) { - if ((inserted && CheckRM (path)) || !inserted) { - if (inserted) { - DWORD type = GetDriveType(path); - if (type == DRIVE_CDROM) - inserted = -1; + case WM_USER + 2: + { + typedef struct { + DWORD dwItem1; // dwItem1 contains the previous PIDL or name of the folder. + DWORD dwItem2; // dwItem2 contains the new PIDL or name of the folder. + } SHNOTIFYSTRUCT; + TCHAR path[MAX_PATH]; + + if (lParam == SHCNE_MEDIAINSERTED || lParam == SHCNE_MEDIAREMOVED) { + SHNOTIFYSTRUCT *shns = (SHNOTIFYSTRUCT*)wParam; + if (SHGetPathFromIDList ((struct _ITEMIDLIST *)(shns->dwItem1), path)) { + int inserted = lParam == SHCNE_MEDIAINSERTED ? 1 : 0; + UINT errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + write_log (L"Shell Notification %d '%s'\n", inserted, path); + if (!win32_hardfile_media_change (path, inserted)) { + if ((inserted && CheckRM (path)) || !inserted) { + if (inserted) { + DWORD type = GetDriveType(path); + if (type == DRIVE_CDROM) + inserted = -1; + } + filesys_media_change (path, inserted, NULL); + } + } + SetErrorMode (errormode); + } } - filesys_media_change (path, inserted, NULL); - } } - SetErrorMode (errormode); - } - } - } - return TRUE; - case WM_DEVICECHANGE: - { - extern void win32_spti_media_change (TCHAR driveletter, int insert); - extern void win32_ioctl_media_change (TCHAR driveletter, int insert); - extern void win32_aspi_media_change (TCHAR driveletter, int insert); - DEV_BROADCAST_HDR *pBHdr = (DEV_BROADCAST_HDR *)lParam; - static int waitfornext; - - if (wParam == DBT_DEVNODES_CHANGED && lParam == 0) { - if (waitfornext) - inputdevice_devicechange (&changed_prefs); - waitfornext = 0; - } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { - DEV_BROADCAST_DEVICEINTERFACE *dbd = (DEV_BROADCAST_DEVICEINTERFACE*)lParam; - if (wParam == DBT_DEVICEREMOVECOMPLETE) - inputdevice_devicechange (&changed_prefs); - else if (wParam == DBT_DEVICEARRIVAL) - waitfornext = 1; - } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { - DEV_BROADCAST_VOLUME *pBVol = (DEV_BROADCAST_VOLUME *)lParam; - if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { - if (pBVol->dbcv_unitmask) { - int inserted, i; - TCHAR drive; - UINT errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); - for (i = 0; i <= 'Z'-'A'; i++) { - if (pBVol->dbcv_unitmask & (1 << i)) { - TCHAR drvname[10]; - int type; - - drive = 'A' + i; - _stprintf (drvname, L"%c:\\", drive); - type = GetDriveType (drvname); - if (wParam == DBT_DEVICEARRIVAL) - inserted = 1; - else - inserted = 0; - if (pBVol->dbcv_flags & DBTF_MEDIA) { - #ifdef WINDDK - win32_spti_media_change (drive, inserted); - win32_ioctl_media_change (drive, inserted); - #endif - win32_aspi_media_change (drive, inserted); - } - if (type == DRIVE_REMOVABLE || type == DRIVE_CDROM || !inserted) { - write_log (L"WM_DEVICECHANGE '%s' type=%d inserted=%d\n", drvname, type, inserted); - if (!win32_hardfile_media_change (drvname, inserted)) { - if ((inserted && CheckRM (drvname)) || !inserted) { - if (type == DRIVE_CDROM && inserted) - inserted = -1; - filesys_media_change (drvname, inserted, NULL); - } + return TRUE; + case WM_DEVICECHANGE: + { + extern void win32_spti_media_change (TCHAR driveletter, int insert); + extern void win32_ioctl_media_change (TCHAR driveletter, int insert); + extern void win32_aspi_media_change (TCHAR driveletter, int insert); + DEV_BROADCAST_HDR *pBHdr = (DEV_BROADCAST_HDR *)lParam; + static int waitfornext; + + if (wParam == DBT_DEVNODES_CHANGED && lParam == 0) { + if (waitfornext) + inputdevice_devicechange (&changed_prefs); + waitfornext = 0; + } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { + DEV_BROADCAST_DEVICEINTERFACE *dbd = (DEV_BROADCAST_DEVICEINTERFACE*)lParam; + if (wParam == DBT_DEVICEREMOVECOMPLETE) + inputdevice_devicechange (&changed_prefs); + else if (wParam == DBT_DEVICEARRIVAL) + waitfornext = 1; + } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { + DEV_BROADCAST_VOLUME *pBVol = (DEV_BROADCAST_VOLUME *)lParam; + if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { + if (pBVol->dbcv_unitmask) { + int inserted, i; + TCHAR drive; + UINT errormode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + for (i = 0; i <= 'Z'-'A'; i++) { + if (pBVol->dbcv_unitmask & (1 << i)) { + TCHAR drvname[10]; + int type; + + drive = 'A' + i; + _stprintf (drvname, L"%c:\\", drive); + type = GetDriveType (drvname); + if (wParam == DBT_DEVICEARRIVAL) + inserted = 1; + else + inserted = 0; + if (pBVol->dbcv_flags & DBTF_MEDIA) { +#ifdef WINDDK + win32_spti_media_change (drive, inserted); + win32_ioctl_media_change (drive, inserted); +#endif + win32_aspi_media_change (drive, inserted); + } + if (type == DRIVE_REMOVABLE || type == DRIVE_CDROM || !inserted) { + write_log (L"WM_DEVICECHANGE '%s' type=%d inserted=%d\n", drvname, type, inserted); + if (!win32_hardfile_media_change (drvname, inserted)) { + if ((inserted && CheckRM (drvname)) || !inserted) { + if (type == DRIVE_CDROM && inserted) + inserted = -1; + filesys_media_change (drvname, inserted, NULL); + } + } + } + } + } + SetErrorMode (errormode); + } } - } } - } - SetErrorMode (errormode); } - } - } - } #endif - return TRUE; + return TRUE; - case WM_SYSCOMMAND: - switch (wParam & 0xfff0) // Check System Calls - { - case SC_SCREENSAVE: // Screensaver Trying To Start? - case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? + case WM_SYSCOMMAND: + switch (wParam & 0xfff0) // Check System Calls + { + case SC_SCREENSAVE: // Screensaver Trying To Start? + case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? - // SetThreadExecutionState (ES_CONTINUOUS | ES_DISPLAY_REQUIRED); handles this now + // SetThreadExecutionState (ES_CONTINUOUS | ES_DISPLAY_REQUIRED); handles this now #if 0 - if (!manual_painting_needed && focus && currprefs.win32_powersavedisabled) - return 0; // Prevent From Happening + if (!manual_painting_needed && focus && currprefs.win32_powersavedisabled) + return 0; // Prevent From Happening #endif - break; + break; + + default: + { + LRESULT lr; - default: - { - LRESULT lr; - #ifdef RETROPLATFORM - if ((wParam & 0xfff0) == SC_CLOSE) { - if (rp_close ()) - return 0; - } + if ((wParam & 0xfff0) == SC_CLOSE) { + if (rp_close ()) + return 0; + } #endif - lr = DefWindowProc (hWnd, message, wParam, lParam); - switch (wParam & 0xfff0) + lr = DefWindowProc (hWnd, message, wParam, lParam); + switch (wParam & 0xfff0) + { + case SC_MINIMIZE: + break; + case SC_RESTORE: + break; + case SC_CLOSE: + PostQuitMessage (0); + break; + } + return lr; + } + } + break; + + case WM_SYSKEYDOWN: + if(currprefs.win32_ctrl_F11_is_quit && wParam == VK_F4) + return 0; + break; + + case WM_INPUT: + handle_rawinput (lParam); + DefWindowProc (hWnd, message, wParam, lParam); + return 0; + + case WM_NOTIFY: { - case SC_MINIMIZE: - break; - case SC_RESTORE: - break; - case SC_CLOSE: - PostQuitMessage (0); - break; + LPNMHDR nm = (LPNMHDR)lParam; + if (nm->hwndFrom == hStatusWnd) { + switch (nm->code) + { + /* status bar clicks */ + case NM_CLICK: + case NM_RCLICK: + { + LPNMMOUSE lpnm = (LPNMMOUSE) lParam; + int num = (int)lpnm->dwItemSpec; + if (num >= 7 && num <= 10) { // DF0-DF3 + num -= 7; + if (nm->code == NM_RCLICK) { + disk_eject (num); + } else if (changed_prefs.dfxtype[num] >= 0) { + DiskSelection (hWnd, IDC_DF0 + num, 0, &changed_prefs, 0); + disk_insert (num, changed_prefs.df[num]); + } + } else if (num == 4) { + if (nm->code == NM_CLICK) // POWER + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + else + uae_reset (0); + } else if (num == 3) { + if (pause_emulation) { + resumepaused (9); + setmouseactive (1); + } + } + return TRUE; + } + } + } } - return lr; - } - } - break; - - case WM_SYSKEYDOWN: - if(currprefs.win32_ctrl_F11_is_quit && wParam == VK_F4) - return 0; - break; - - case WM_INPUT: - handle_rawinput (lParam); - DefWindowProc (hWnd, message, wParam, lParam); - return 0; - - case WM_NOTIFY: - { - LPNMHDR nm = (LPNMHDR)lParam; - if (nm->hwndFrom == hStatusWnd) { - switch (nm->code) - { - /* status bar clicks */ - case NM_CLICK: - case NM_RCLICK: + break; + + case WM_CHANGECBCHAIN: + if ((HWND) wParam == hwndNextViewer) + hwndNextViewer = (HWND) lParam; + else if (hwndNextViewer != NULL) + SendMessage (hwndNextViewer, message, wParam, lParam); + return 0; + case WM_DRAWCLIPBOARD: + clipboard_changed (hWnd); + SendMessage (hwndNextViewer, message, wParam, lParam); + return 0; + + case WM_WTSSESSION_CHANGE: { - LPNMMOUSE lpnm = (LPNMMOUSE) lParam; - int num = (int)lpnm->dwItemSpec; - if (num >= 7 && num <= 10) { // DF0-DF3 - num -= 7; - if (nm->code == NM_RCLICK) { - disk_eject (num); - } else if (changed_prefs.dfxtype[num] >= 0) { - DiskSelection (hWnd, IDC_DF0 + num, 0, &changed_prefs, 0); - disk_insert (num, changed_prefs.df[num]); + static int wasactive; + switch (wParam) + { + case WTS_CONSOLE_CONNECT: + case WTS_SESSION_UNLOCK: + if (wasactive) + winuae_active (hWnd, 0); + wasactive = 0; + break; + case WTS_CONSOLE_DISCONNECT: + case WTS_SESSION_LOCK: + wasactive = mouseactive; + winuae_inactive (hWnd, 0); + break; } - } else if (num == 4) { - if (nm->code == NM_CLICK) // POWER - inputdevice_add_inputcode (AKS_ENTERGUI, 1); - else - uae_reset (0); - } else if (num == 3) { - if (pause_emulation) { - resumepaused (); - setmouseactive (1); + } + + + case WT_PROXIMITY: + { + send_tablet_proximity (LOWORD (lParam) ? 1 : 0); + return 0; + } + case WT_PACKET: + { + PACKET pkt; + if (inputdevice_is_tablet () <= 0) { + close_tablet (tablet); + tablet = NULL; + return 0; + } + if (WTPacket ((HCTX)lParam, wParam, &pkt)) { + int x, y, z, pres, proxi; + DWORD buttons; + ORIENTATION ori; + ROTATION rot; + + x = pkt.pkX; + y = pkt.pkY; + z = pkt.pkZ; + pres = pkt.pkNormalPressure; + ori = pkt.pkOrientation; + rot = pkt.pkRotation; + buttons = pkt.pkButtons; + proxi = pkt.pkStatus; + send_tablet (x, y, z, pres, buttons, proxi, ori.orAzimuth, ori.orAltitude, ori.orTwist, rot.roPitch, rot.roRoll, rot.roYaw, &amigawin_rect); + } - } - return TRUE; + return 0; } - } - } - } - break; - - case WM_CHANGECBCHAIN: - if ((HWND) wParam == hwndNextViewer) - hwndNextViewer = (HWND) lParam; - else if (hwndNextViewer != NULL) - SendMessage (hwndNextViewer, message, wParam, lParam); - return 0; - case WM_DRAWCLIPBOARD: - clipboard_changed (hWnd); - SendMessage (hwndNextViewer, message, wParam, lParam); - return 0; - - case WM_WTSSESSION_CHANGE: - { - static int wasactive; - switch (wParam) - { - case WTS_CONSOLE_CONNECT: - case WTS_SESSION_UNLOCK: - if (wasactive) - winuae_active (hWnd, 0); - wasactive = 0; - break; - case WTS_CONSOLE_DISCONNECT: - case WTS_SESSION_LOCK: - wasactive = mouseactive; - winuae_inactive (hWnd, 0); - break; - } - } - - - case WT_PROXIMITY: - { - send_tablet_proximity (LOWORD (lParam) ? 1 : 0); - return 0; - } - case WT_PACKET: - { - PACKET pkt; - if (inputdevice_is_tablet () <= 0) { - close_tablet (tablet); - tablet = NULL; - return 0; - } - if (WTPacket ((HCTX)lParam, wParam, &pkt)) { - int x, y, z, pres, proxi; - DWORD buttons; - ORIENTATION ori; - ROTATION rot; - - x = pkt.pkX; - y = pkt.pkY; - z = pkt.pkZ; - pres = pkt.pkNormalPressure; - ori = pkt.pkOrientation; - rot = pkt.pkRotation; - buttons = pkt.pkButtons; - proxi = pkt.pkStatus; - send_tablet (x, y, z, pres, buttons, proxi, ori.orAzimuth, ori.orAltitude, ori.orTwist, rot.roPitch, rot.roRoll, rot.roYaw, &amigawin_rect); + default: + break; } - return 0; - } - - default: - break; - } - return DefWindowProc (hWnd, message, wParam, lParam); + return DefWindowProc (hWnd, message, wParam, lParam); } static int canstretch (void) { - if (isfullscreen () != 0) - return 0; - if (currprefs.gfx_filter_autoscale == 2) + if (isfullscreen () != 0) + return 0; + if (currprefs.gfx_filter_autoscale == 2) + return 0; + if (!WIN32GFX_IsPicassoScreen ()) + return 1; + if (currprefs.win32_rtgallowscaling || currprefs.win32_rtgscaleaspectratio) + return 1; return 0; - if (!WIN32GFX_IsPicassoScreen ()) - return 1; - if (currprefs.win32_rtgallowscaling || currprefs.win32_rtgscaleaspectratio) - return 1; - return 0; } static LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - PAINTSTRUCT ps; - RECT rc; - HDC hDC; + PAINTSTRUCT ps; + RECT rc; + HDC hDC; #if MSGDEBUG > 1 - write_log (L"MWP: %x %d\n", hWnd, message); + write_log (L"MWP: %x %d\n", hWnd, message); #endif - switch (message) - { - case WM_KILLFOCUS: - case WM_SETFOCUS: - case WM_MOUSEMOVE: - case WM_MOUSEWHEEL: - case WM_MOUSEHWHEEL: - case WM_ACTIVATEAPP: - case WM_DROPFILES: - case WM_ACTIVATE: - case WM_SETCURSOR: - case WM_SYSCOMMAND: - case WM_KEYUP: - case WM_SYSKEYUP: - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_LBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_RBUTTONDBLCLK: - case WM_MOVING: - case WM_MOVE: - case WM_SIZING: - case WM_SIZE: - case WM_DESTROY: - case WM_CLOSE: - case WM_HELP: - case WM_DEVICECHANGE: - case WM_INPUT: - case WM_USER + 1: - case WM_USER + 2: - case WM_COMMAND: - case WM_NOTIFY: - case WM_ENABLE: - case WT_PACKET: - case WM_WTSSESSION_CHANGE: - return AmigaWindowProc (hWnd, message, wParam, lParam); - - case WM_DISPLAYCHANGE: - if (isfullscreen() <= 0 && !currprefs.gfx_filter && (wParam + 7) / 8 != DirectDraw_GetBytesPerPixel ()) - WIN32GFX_DisplayChangeRequested(); - break; - - case WM_GETMINMAXINFO: - { - LPMINMAXINFO lpmmi; - lpmmi = (LPMINMAXINFO)lParam; - lpmmi->ptMinTrackSize.x = 160 + window_extra_width; - lpmmi->ptMinTrackSize.y = 128 + window_extra_height; - lpmmi->ptMaxTrackSize.x = 3072 + window_extra_width; - lpmmi->ptMaxTrackSize.y = 2048 + window_extra_height; - } - return 0; - - case WM_ENTERSIZEMOVE: - in_sizemove++; - break; - - case WM_EXITSIZEMOVE: - in_sizemove--; - /* fall through */ - - case WM_WINDOWPOSCHANGED: - WIN32GFX_WindowMove (); - if (hAmigaWnd && isfullscreen () <= 0) { - DWORD aw, ah; - int iconic = IsIconic (hWnd); - if (!iconic) - GetWindowRect (hAmigaWnd, &amigawin_rect); - aw = amigawin_rect.right - amigawin_rect.left; - ah = amigawin_rect.bottom - amigawin_rect.top; - if (in_sizemove > 0) + switch (message) + { + case WM_KILLFOCUS: + case WM_SETFOCUS: + case WM_MOUSEMOVE: + case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: + case WM_ACTIVATEAPP: + case WM_DROPFILES: + case WM_ACTIVATE: + case WM_SETCURSOR: + case WM_SYSCOMMAND: + case WM_KEYUP: + case WM_SYSKEYUP: + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_LBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_RBUTTONDBLCLK: + case WM_MOVING: + case WM_MOVE: + case WM_SIZING: + case WM_SIZE: + case WM_DESTROY: + case WM_CLOSE: + case WM_HELP: + case WM_DEVICECHANGE: + case WM_INPUT: + case WM_USER + 1: + case WM_USER + 2: + case WM_COMMAND: + case WM_NOTIFY: + case WM_ENABLE: + case WT_PACKET: + case WM_WTSSESSION_CHANGE: + return AmigaWindowProc (hWnd, message, wParam, lParam); + + case WM_DISPLAYCHANGE: + if (isfullscreen() <= 0 && !currprefs.gfx_filter && (wParam + 7) / 8 != DirectDraw_GetBytesPerPixel ()) + WIN32GFX_DisplayChangeRequested(); break; - if (isfullscreen() == 0 && hAmigaWnd && !iconic) { - static int store_xy; - RECT rc2; - if (GetWindowRect (hMainWnd, &rc2)) { - DWORD left = rc2.left - win_x_diff; - DWORD top = rc2.top - win_y_diff; - DWORD width = rc2.right - rc2.left; - DWORD height = rc2.bottom - rc2.top; - if (amigawin_rect.left & 3) { - MoveWindow (hMainWnd, rc2.left + 4 - amigawin_rect.left % 4, rc2.top, - rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE); - - } - if (store_xy++) { - regsetint (NULL, L"MainPosX", left); - regsetint (NULL, L"MainPosY", top); - } - changed_prefs.gfx_size_win.x = left; - changed_prefs.gfx_size_win.y = top; - if (canstretch ()) { - changed_prefs.gfx_size_win.width = width - window_extra_width; - changed_prefs.gfx_size_win.height = height - window_extra_height; - } + case WM_GETMINMAXINFO: + { + LPMINMAXINFO lpmmi; + lpmmi = (LPMINMAXINFO)lParam; + lpmmi->ptMinTrackSize.x = 160 + window_extra_width; + lpmmi->ptMinTrackSize.y = 128 + window_extra_height; + lpmmi->ptMaxTrackSize.x = 3072 + window_extra_width; + lpmmi->ptMaxTrackSize.y = 2048 + window_extra_height; } return 0; - } - } - break; - - case WM_WINDOWPOSCHANGING: - { - WINDOWPOS *wp = (WINDOWPOS*)lParam; - if (!canstretch ()) - wp->flags |= SWP_NOSIZE; - break; - } - - case WM_PAINT: - hDC = BeginPaint (hWnd, &ps); - GetClientRect (hWnd, &rc); - DrawEdge (hDC, &rc, EDGE_SUNKEN, BF_RECT); - EndPaint (hWnd, &ps); - return 0; - case WM_NCLBUTTONDBLCLK: - if (wParam == HTCAPTION) { - WIN32GFX_ToggleFullScreen (); - return 0; - } - break; + case WM_ENTERSIZEMOVE: + in_sizemove++; + break; + + case WM_EXITSIZEMOVE: + in_sizemove--; + /* fall through */ + + case WM_WINDOWPOSCHANGED: + WIN32GFX_WindowMove (); + if (hAmigaWnd && isfullscreen () <= 0) { + DWORD aw, ah; + int iconic = IsIconic (hWnd); + if (!iconic) + GetWindowRect (hAmigaWnd, &amigawin_rect); + aw = amigawin_rect.right - amigawin_rect.left; + ah = amigawin_rect.bottom - amigawin_rect.top; + if (in_sizemove > 0) + break; + + if (isfullscreen() == 0 && hAmigaWnd && !iconic) { + static int store_xy; + RECT rc2; + if (GetWindowRect (hMainWnd, &rc2)) { + DWORD left = rc2.left - win_x_diff; + DWORD top = rc2.top - win_y_diff; + DWORD width = rc2.right - rc2.left; + DWORD height = rc2.bottom - rc2.top; + if (amigawin_rect.left & 3) { + MoveWindow (hMainWnd, rc2.left + 4 - amigawin_rect.left % 4, rc2.top, + rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE); + + } + if (store_xy++) { + regsetint (NULL, L"MainPosX", left); + regsetint (NULL, L"MainPosY", top); + } + changed_prefs.gfx_size_win.x = left; + changed_prefs.gfx_size_win.y = top; + if (canstretch ()) { + changed_prefs.gfx_size_win.width = width - window_extra_width; + changed_prefs.gfx_size_win.height = height - window_extra_height; + } + } + return 0; + } + } + break; + + case WM_WINDOWPOSCHANGING: + { + WINDOWPOS *wp = (WINDOWPOS*)lParam; + if (!canstretch ()) + wp->flags |= SWP_NOSIZE; + break; + } + + case WM_PAINT: + hDC = BeginPaint (hWnd, &ps); + GetClientRect (hWnd, &rc); + DrawEdge (hDC, &rc, EDGE_SUNKEN, BF_RECT); + EndPaint (hWnd, &ps); + return 0; + + case WM_NCLBUTTONDBLCLK: + if (wParam == HTCAPTION) { + WIN32GFX_ToggleFullScreen (); + return 0; + } + break; - default: - break; + default: + break; - } + } - return DefWindowProc (hWnd, message, wParam, lParam); + return DefWindowProc (hWnd, message, wParam, lParam); } static LRESULT CALLBACK HiddenWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) - { + switch (message) + { case WM_USER + 1: /* Systray icon */ - switch (lParam) - { + switch (lParam) + { case WM_LBUTTONDOWN: - SetForegroundWindow (hGUIWnd ? hGUIWnd : hMainWnd); - break; + SetForegroundWindow (hGUIWnd ? hGUIWnd : hMainWnd); + break; case WM_LBUTTONDBLCLK: - if (!gui_active) - inputdevice_add_inputcode (AKS_ENTERGUI, 1); - break; + if (!gui_active) + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + break; case WM_RBUTTONDOWN: - if (!gui_active) - systraymenu (hWnd); - else - SetForegroundWindow (hGUIWnd ? hGUIWnd : hMainWnd); + if (!gui_active) + systraymenu (hWnd); + else + SetForegroundWindow (hGUIWnd ? hGUIWnd : hMainWnd); + break; + } break; - } - break; case WM_COMMAND: - switch (wParam & 0xffff) - { + switch (wParam & 0xffff) + { case ID_ST_CONFIGURATION: - inputdevice_add_inputcode (AKS_ENTERGUI, 1); - break; + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + break; case ID_ST_HELP: - if (pHtmlHelp) - pHtmlHelp (NULL, help_file, 0, NULL); - break; + if (pHtmlHelp) + pHtmlHelp (NULL, help_file, 0, NULL); + break; case ID_ST_QUIT: - uae_quit (); - break; + uae_quit (); + break; case ID_ST_RESET: - uae_reset (0); - break; + uae_reset (0); + break; case ID_ST_EJECTALL: - disk_eject (0); - disk_eject (1); - disk_eject (2); - disk_eject (3); - break; + disk_eject (0); + disk_eject (1); + disk_eject (2); + disk_eject (3); + break; case ID_ST_DF0: - DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF0, 0, &changed_prefs, 0); - disk_insert (0, changed_prefs.df[0]); - break; + DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF0, 0, &changed_prefs, 0); + disk_insert (0, changed_prefs.df[0]); + break; case ID_ST_DF1: - DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF1, 0, &changed_prefs, 0); - disk_insert (1, changed_prefs.df[0]); - break; + DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF1, 0, &changed_prefs, 0); + disk_insert (1, changed_prefs.df[0]); + break; case ID_ST_DF2: - DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF2, 0, &changed_prefs, 0); - disk_insert (2, changed_prefs.df[0]); - break; + DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF2, 0, &changed_prefs, 0); + disk_insert (2, changed_prefs.df[0]); + break; case ID_ST_DF3: - DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF3, 0, &changed_prefs, 0); - disk_insert (3, changed_prefs.df[0]); + DiskSelection (isfullscreen() > 0 ? NULL : hWnd, IDC_DF3, 0, &changed_prefs, 0); + disk_insert (3, changed_prefs.df[0]); + break; + } break; - } - break; - } - if (TaskbarRestart != 0 && TaskbarRestartHWND == hWnd && message == TaskbarRestart) { - //write_log (L"notif: taskbarrestart\n"); - systray (TaskbarRestartHWND, FALSE); - } - return DefWindowProc (hWnd, message, wParam, lParam); + } + if (TaskbarRestart != 0 && TaskbarRestartHWND == hWnd && message == TaskbarRestart) { + //write_log (L"notif: taskbarrestart\n"); + systray (TaskbarRestartHWND, FALSE); + } + return DefWindowProc (hWnd, message, wParam, lParam); } int handle_msgpump (void) { - int got = 0; - MSG msg; - - while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { - got = 1; - TranslateMessage (&msg); - DispatchMessage (&msg); - } - return got; + int got = 0; + MSG msg; + + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + got = 1; + TranslateMessage (&msg); + DispatchMessage (&msg); + } + return got; } void handle_events (void) { - MSG msg; - int was_paused = 0; - static int cnt; - - while (pause_emulation) { - if (pause_emulation && was_paused == 0) { - setpaused (); - was_paused = 1; - manual_painting_needed++; - gui_fps (0, 0); - } - while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - sleep_millis (20); - inputdevicefunc_keyboard.read (); - inputdevicefunc_mouse.read (); - inputdevicefunc_joystick.read (); - inputdevice_handle_inputcode (); - check_prefs_changed_gfx (); + MSG msg; + int was_paused = 0; + static int cnt; + + while (pause_emulation) { + if (pause_emulation && was_paused == 0) { + setpaused (pause_emulation); + was_paused = pause_emulation; + manual_painting_needed++; + gui_fps (0, 0); + } + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + sleep_millis (20); + inputdevicefunc_keyboard.read (); + inputdevicefunc_mouse.read (); + inputdevicefunc_joystick.read (); + inputdevice_handle_inputcode (); + check_prefs_changed_gfx (); #ifdef RETROPLATFORM - rp_vsync (); + rp_vsync (); #endif - cnt = 0; + cnt = 0; + while (checkIPC (globalipc, &currprefs)); + if (quit_program) + break; + } + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage (&msg); + DispatchMessage (&msg); + } while (checkIPC (globalipc, &currprefs)); - if (quit_program) - break; - } - while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - while (checkIPC (globalipc, &currprefs)); - if (was_paused) { - resumepaused (); - sound_closed = 0; - manual_painting_needed--; - } - cnt--; - if (cnt <= 0) { - figure_processor_speed (); - flush_log (); - cnt = 50 * 5; - } + if (was_paused) { + resumepaused (was_paused); + sound_closed = 0; + manual_painting_needed--; + } + cnt--; + if (cnt <= 0) { + figure_processor_speed (); + flush_log (); + cnt = 50 * 5; + } } /* We're not a console-app anymore! */ @@ -1603,71 +1613,71 @@ void remove_brkhandler (void) static void WIN32_UnregisterClasses (void) { - systray (hHiddenWnd, TRUE); - DestroyWindow (hHiddenWnd); + systray (hHiddenWnd, TRUE); + DestroyWindow (hHiddenWnd); } static int WIN32_RegisterClasses (void) { - WNDCLASS wc; - HDC hDC; - COLORREF black = RGB(0, 0, 0); - - g_dwBackgroundColor = RGB(10, 0, 10); - hDC = GetDC (NULL); - if (GetDeviceCaps (hDC, NUMCOLORS) != -1) - g_dwBackgroundColor = RGB (255, 0, 255); - ReleaseDC (NULL, hDC); - - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_OWNDC; - wc.lpfnWndProc = AmigaWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = DLGWINDOWEXTRA; - wc.hInstance = 0; - wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); - wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); - wc.lpszMenuName = 0; - wc.lpszClassName = L"AmigaPowah"; - wc.hbrBackground = CreateSolidBrush (g_dwBackgroundColor); - if (!RegisterClass (&wc)) - return 0; + WNDCLASS wc; + HDC hDC; + COLORREF black = RGB(0, 0, 0); + + g_dwBackgroundColor = RGB(10, 0, 10); + hDC = GetDC (NULL); + if (GetDeviceCaps (hDC, NUMCOLORS) != -1) + g_dwBackgroundColor = RGB (255, 0, 255); + ReleaseDC (NULL, hDC); + + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_OWNDC; + wc.lpfnWndProc = AmigaWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = DLGWINDOWEXTRA; + wc.hInstance = 0; + wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); + wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); + wc.lpszMenuName = 0; + wc.lpszClassName = L"AmigaPowah"; + wc.hbrBackground = CreateSolidBrush (g_dwBackgroundColor); + if (!RegisterClass (&wc)) + return 0; - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = MainWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = DLGWINDOWEXTRA; - wc.hInstance = 0; - wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); - wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); - wc.hbrBackground = CreateSolidBrush (black); - wc.lpszMenuName = 0; - wc.lpszClassName = L"PCsuxRox"; - if (!RegisterClass (&wc)) - return 0; + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = MainWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = DLGWINDOWEXTRA; + wc.hInstance = 0; + wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); + wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = CreateSolidBrush (black); + wc.lpszMenuName = 0; + wc.lpszClassName = L"PCsuxRox"; + if (!RegisterClass (&wc)) + return 0; - wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW; - wc.lpfnWndProc = HiddenWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = DLGWINDOWEXTRA; - wc.hInstance = 0; - wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); - wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); - wc.hbrBackground = CreateSolidBrush (g_dwBackgroundColor); - wc.lpszMenuName = 0; - wc.lpszClassName = L"Useless"; - if (!RegisterClass (&wc)) - return 0; + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW; + wc.lpfnWndProc = HiddenWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = DLGWINDOWEXTRA; + wc.hInstance = 0; + wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_APPICON)); + wc.hCursor = NULL; //LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = CreateSolidBrush (g_dwBackgroundColor); + wc.lpszMenuName = 0; + wc.lpszClassName = L"Useless"; + if (!RegisterClass (&wc)) + return 0; - hHiddenWnd = CreateWindowEx (0, - L"Useless", L"You don't see me", - WS_POPUP, - 0, 0, - 1, 1, - NULL, NULL, 0, NULL); - if (!hHiddenWnd) - return 0; + hHiddenWnd = CreateWindowEx (0, + L"Useless", L"You don't see me", + WS_POPUP, + 0, 0, + 1, 1, + NULL, NULL, 0, NULL); + if (!hHiddenWnd) + return 0; - return 1; + return 1; } #ifdef __GNUC__ @@ -1679,115 +1689,115 @@ static HINSTANCE hRichEdit = NULL, hHtmlHelp = NULL; int WIN32_CleanupLibraries (void) { - if (hRichEdit) - FreeLibrary (hRichEdit); + if (hRichEdit) + FreeLibrary (hRichEdit); - if (hHtmlHelp) - FreeLibrary (hHtmlHelp); + if (hHtmlHelp) + FreeLibrary (hHtmlHelp); - if (hUIDLL) - FreeLibrary (hUIDLL); - CoUninitialize (); - return 1; + if (hUIDLL) + FreeLibrary (hUIDLL); + CoUninitialize (); + return 1; } /* HtmlHelp Initialization - optional component */ int WIN32_InitHtmlHelp (void) { - TCHAR *chm = L"WinUAE.chm"; - int result = 0; - _stprintf(help_file, L"%s%s", start_path_data, chm); - if (!zfile_exists (help_file)) - _stprintf(help_file, L"%s%s", start_path_exe, chm); - if (zfile_exists (help_file)) { - if (hHtmlHelp = LoadLibrary (L"HHCTRL.OCX")) { - pHtmlHelp = (HWND(WINAPI *)(HWND, LPCWSTR, UINT, LPDWORD))GetProcAddress (hHtmlHelp, "HtmlHelpW"); - result = 1; - } - } - return result; + TCHAR *chm = L"WinUAE.chm"; + int result = 0; + _stprintf(help_file, L"%s%s", start_path_data, chm); + if (!zfile_exists (help_file)) + _stprintf(help_file, L"%s%s", start_path_exe, chm); + if (zfile_exists (help_file)) { + if (hHtmlHelp = LoadLibrary (L"HHCTRL.OCX")) { + pHtmlHelp = (HWND(WINAPI *)(HWND, LPCWSTR, UINT, LPDWORD))GetProcAddress (hHtmlHelp, "HtmlHelpW"); + result = 1; + } + } + return result; } struct winuae_lang langs[] = { - { LANG_AFRIKAANS, L"Afrikaans" }, - { LANG_ARABIC, L"Arabic" }, - { LANG_ARMENIAN, L"Armenian" }, - { LANG_ASSAMESE, L"Assamese" }, - { LANG_AZERI, L"Azeri" }, - { LANG_BASQUE, L"Basque" }, - { LANG_BELARUSIAN, L"Belarusian" }, - { LANG_BENGALI, L"Bengali" }, - { LANG_BULGARIAN, L"Bulgarian" }, - { LANG_CATALAN, L"Catalan" }, - { LANG_CHINESE, L"Chinese" }, - { LANG_CROATIAN, L"Croatian" }, - { LANG_CZECH, L"Czech" }, - { LANG_DANISH, L"Danish" }, - { LANG_DUTCH, L"Dutch" }, - { LANG_ESTONIAN, L"Estoanian" }, - { LANG_FAEROESE, L"Faeroese" }, - { LANG_FARSI, L"Farsi" }, - { LANG_FINNISH, L"Finnish" }, - { LANG_FRENCH, L"French" }, - { LANG_GEORGIAN, L"Georgian" }, - { LANG_GERMAN, L"German" }, - { LANG_GREEK, L"Greek" }, - { LANG_GUJARATI, L"Gujarati" }, - { LANG_HEBREW, L"Hebrew" }, - { LANG_HINDI, L"Hindi" }, - { LANG_HUNGARIAN, L"Hungarian" }, - { LANG_ICELANDIC, L"Icelandic" }, - { LANG_INDONESIAN, L"Indonesian" }, - { LANG_ITALIAN, L"Italian" }, - { LANG_JAPANESE, L"Japanese" }, - { LANG_KANNADA, L"Kannada" }, - { LANG_KASHMIRI, L"Kashmiri" }, - { LANG_KAZAK, L"Kazak" }, - { LANG_KONKANI, L"Konkani" }, - { LANG_KOREAN, L"Korean" }, - { LANG_LATVIAN, L"Latvian" }, - { LANG_LITHUANIAN, L"Lithuanian" }, - { LANG_MACEDONIAN, L"Macedonian" }, - { LANG_MALAY, L"Malay" }, - { LANG_MALAYALAM, L"Malayalam" }, - { LANG_MANIPURI, L"Manipuri" }, - { LANG_MARATHI, L"Marathi" }, - { LANG_NEPALI, L"Nepali" }, - { LANG_NORWEGIAN, L"Norwegian" }, - { LANG_ORIYA, L"Oriya" }, - { LANG_POLISH, L"Polish" }, - { LANG_PORTUGUESE, L"Portuguese" }, - { LANG_PUNJABI, L"Punjabi" }, - { LANG_ROMANIAN, L"Romanian" }, - { LANG_RUSSIAN, L"Russian" }, - { LANG_SANSKRIT, L"Sanskrit" }, - { LANG_SINDHI, L"Sindhi" }, - { LANG_SLOVAK, L"Slovak" }, - { LANG_SLOVENIAN, L"Slovenian" }, - { LANG_SPANISH, L"Spanish" }, - { LANG_SWAHILI, L"Swahili" }, - { LANG_SWEDISH, L"Swedish" }, - { LANG_TAMIL, L"Tamil" }, - { LANG_TATAR, L"Tatar" }, - { LANG_TELUGU, L"Telugu" }, - { LANG_THAI, L"Thai" }, - { LANG_TURKISH, L"Turkish" }, - { LANG_UKRAINIAN, L"Ukrainian" }, - { LANG_UZBEK, L"Uzbek" }, - { LANG_VIETNAMESE, L"Vietnamese" }, - { LANG_ENGLISH, L"default" }, - { 0x400, L"guidll.dll"}, - { 0, NULL } + { LANG_AFRIKAANS, L"Afrikaans" }, + { LANG_ARABIC, L"Arabic" }, + { LANG_ARMENIAN, L"Armenian" }, + { LANG_ASSAMESE, L"Assamese" }, + { LANG_AZERI, L"Azeri" }, + { LANG_BASQUE, L"Basque" }, + { LANG_BELARUSIAN, L"Belarusian" }, + { LANG_BENGALI, L"Bengali" }, + { LANG_BULGARIAN, L"Bulgarian" }, + { LANG_CATALAN, L"Catalan" }, + { LANG_CHINESE, L"Chinese" }, + { LANG_CROATIAN, L"Croatian" }, + { LANG_CZECH, L"Czech" }, + { LANG_DANISH, L"Danish" }, + { LANG_DUTCH, L"Dutch" }, + { LANG_ESTONIAN, L"Estoanian" }, + { LANG_FAEROESE, L"Faeroese" }, + { LANG_FARSI, L"Farsi" }, + { LANG_FINNISH, L"Finnish" }, + { LANG_FRENCH, L"French" }, + { LANG_GEORGIAN, L"Georgian" }, + { LANG_GERMAN, L"German" }, + { LANG_GREEK, L"Greek" }, + { LANG_GUJARATI, L"Gujarati" }, + { LANG_HEBREW, L"Hebrew" }, + { LANG_HINDI, L"Hindi" }, + { LANG_HUNGARIAN, L"Hungarian" }, + { LANG_ICELANDIC, L"Icelandic" }, + { LANG_INDONESIAN, L"Indonesian" }, + { LANG_ITALIAN, L"Italian" }, + { LANG_JAPANESE, L"Japanese" }, + { LANG_KANNADA, L"Kannada" }, + { LANG_KASHMIRI, L"Kashmiri" }, + { LANG_KAZAK, L"Kazak" }, + { LANG_KONKANI, L"Konkani" }, + { LANG_KOREAN, L"Korean" }, + { LANG_LATVIAN, L"Latvian" }, + { LANG_LITHUANIAN, L"Lithuanian" }, + { LANG_MACEDONIAN, L"Macedonian" }, + { LANG_MALAY, L"Malay" }, + { LANG_MALAYALAM, L"Malayalam" }, + { LANG_MANIPURI, L"Manipuri" }, + { LANG_MARATHI, L"Marathi" }, + { LANG_NEPALI, L"Nepali" }, + { LANG_NORWEGIAN, L"Norwegian" }, + { LANG_ORIYA, L"Oriya" }, + { LANG_POLISH, L"Polish" }, + { LANG_PORTUGUESE, L"Portuguese" }, + { LANG_PUNJABI, L"Punjabi" }, + { LANG_ROMANIAN, L"Romanian" }, + { LANG_RUSSIAN, L"Russian" }, + { LANG_SANSKRIT, L"Sanskrit" }, + { LANG_SINDHI, L"Sindhi" }, + { LANG_SLOVAK, L"Slovak" }, + { LANG_SLOVENIAN, L"Slovenian" }, + { LANG_SPANISH, L"Spanish" }, + { LANG_SWAHILI, L"Swahili" }, + { LANG_SWEDISH, L"Swedish" }, + { LANG_TAMIL, L"Tamil" }, + { LANG_TATAR, L"Tatar" }, + { LANG_TELUGU, L"Telugu" }, + { LANG_THAI, L"Thai" }, + { LANG_TURKISH, L"Turkish" }, + { LANG_UKRAINIAN, L"Ukrainian" }, + { LANG_UZBEK, L"Uzbek" }, + { LANG_VIETNAMESE, L"Vietnamese" }, + { LANG_ENGLISH, L"default" }, + { 0x400, L"guidll.dll"}, + { 0, NULL } }; static TCHAR *getlanguagename(DWORD id) { - int i; - for (i = 0; langs[i].name; i++) { - if (langs[i].id == id) - return langs[i].name; - } - return NULL; + int i; + for (i = 0; langs[i].name; i++) { + if (langs[i].id == id) + return langs[i].name; + } + return NULL; } typedef LANGID (CALLBACK* PGETUSERDEFAULTUILANGUAGE)(void); @@ -1795,105 +1805,105 @@ static PGETUSERDEFAULTUILANGUAGE pGetUserDefaultUILanguage; HMODULE language_load (WORD language) { - HMODULE result = NULL; + HMODULE result = NULL; #if WINUAEPUBLICBETA == 0 - TCHAR dllbuf[MAX_DPATH]; - TCHAR *dllname; - - if (language <= 0) { - /* new user-specific Windows ME/2K/XP method to get UI language */ - pGetUserDefaultUILanguage = (PGETUSERDEFAULTUILANGUAGE)GetProcAddress ( - GetModuleHandle (L"kernel32.dll"), "GetUserDefaultUILanguage"); - language = GetUserDefaultLangID (); - if (pGetUserDefaultUILanguage) - language = pGetUserDefaultUILanguage (); - language &= 0x3ff; // low 9-bits form the primary-language ID - } - if (language == LANG_GERMAN) - hrtmon_lang = 2; - if (language == LANG_FRENCH) - hrtmon_lang = 3; - dllname = getlanguagename (language); - if (dllname) { - DWORD dwVersionHandle, dwFileVersionInfoSize; - LPVOID lpFileVersionData = NULL; - BOOL success = FALSE; - int fail = 1; - - if (language == 0x400) - _tcscpy (dllbuf, L"guidll.dll"); - else - _stprintf (dllbuf, L"WinUAE_%s.dll", dllname); - result = WIN32_LoadLibrary (dllbuf); - if (result) { - dwFileVersionInfoSize = GetFileVersionInfoSize (dllbuf, &dwVersionHandle); - if (dwFileVersionInfoSize) { - if (lpFileVersionData = xcalloc (1, dwFileVersionInfoSize)) { - if (GetFileVersionInfo (dllbuf, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { - VS_FIXEDFILEINFO *vsFileInfo = NULL; - UINT uLen; - fail = 0; - if (VerQueryValue (lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { - if (vsFileInfo && - HIWORD(vsFileInfo->dwProductVersionMS) == UAEMAJOR - && LOWORD(vsFileInfo->dwProductVersionMS) == UAEMINOR - && (HIWORD(vsFileInfo->dwProductVersionLS) == UAESUBREV)) { - success = TRUE; - write_log (L"Translation DLL '%s' loaded and enabled\n", dllbuf); - } else { - write_log (L"Translation DLL '%s' version mismatch (%d.%d.%d)\n", dllbuf, - HIWORD(vsFileInfo->dwProductVersionMS), - LOWORD(vsFileInfo->dwProductVersionMS), - HIWORD(vsFileInfo->dwProductVersionLS)); - } + TCHAR dllbuf[MAX_DPATH]; + TCHAR *dllname; + + if (language <= 0) { + /* new user-specific Windows ME/2K/XP method to get UI language */ + pGetUserDefaultUILanguage = (PGETUSERDEFAULTUILANGUAGE)GetProcAddress ( + GetModuleHandle (L"kernel32.dll"), "GetUserDefaultUILanguage"); + language = GetUserDefaultLangID (); + if (pGetUserDefaultUILanguage) + language = pGetUserDefaultUILanguage (); + language &= 0x3ff; // low 9-bits form the primary-language ID + } + if (language == LANG_GERMAN) + hrtmon_lang = 2; + if (language == LANG_FRENCH) + hrtmon_lang = 3; + dllname = getlanguagename (language); + if (dllname) { + DWORD dwVersionHandle, dwFileVersionInfoSize; + LPVOID lpFileVersionData = NULL; + BOOL success = FALSE; + int fail = 1; + + if (language == 0x400) + _tcscpy (dllbuf, L"guidll.dll"); + else + _stprintf (dllbuf, L"WinUAE_%s.dll", dllname); + result = WIN32_LoadLibrary (dllbuf); + if (result) { + dwFileVersionInfoSize = GetFileVersionInfoSize (dllbuf, &dwVersionHandle); + if (dwFileVersionInfoSize) { + if (lpFileVersionData = xcalloc (1, dwFileVersionInfoSize)) { + if (GetFileVersionInfo (dllbuf, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData)) { + VS_FIXEDFILEINFO *vsFileInfo = NULL; + UINT uLen; + fail = 0; + if (VerQueryValue (lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen)) { + if (vsFileInfo && + HIWORD(vsFileInfo->dwProductVersionMS) == UAEMAJOR + && LOWORD(vsFileInfo->dwProductVersionMS) == UAEMINOR + && (HIWORD(vsFileInfo->dwProductVersionLS) == UAESUBREV)) { + success = TRUE; + write_log (L"Translation DLL '%s' loaded and enabled\n", dllbuf); + } else { + write_log (L"Translation DLL '%s' version mismatch (%d.%d.%d)\n", dllbuf, + HIWORD(vsFileInfo->dwProductVersionMS), + LOWORD(vsFileInfo->dwProductVersionMS), + HIWORD(vsFileInfo->dwProductVersionLS)); + } + } + } + xfree (lpFileVersionData); + } } - } - xfree (lpFileVersionData); } - } - } - if (fail) { - DWORD err = GetLastError (); - if (err != ERROR_MOD_NOT_FOUND && err != ERROR_DLL_NOT_FOUND) - write_log (L"Translation DLL '%s' failed to load, error %d\n", dllbuf, GetLastError ()); - } - if (result && !success) { - FreeLibrary (result); - result = NULL; + if (fail) { + DWORD err = GetLastError (); + if (err != ERROR_MOD_NOT_FOUND && err != ERROR_DLL_NOT_FOUND) + write_log (L"Translation DLL '%s' failed to load, error %d\n", dllbuf, GetLastError ()); + } + if (result && !success) { + FreeLibrary (result); + result = NULL; + } } - } #endif - return result; + return result; } struct threadpriorities priorities[] = { - { NULL, THREAD_PRIORITY_ABOVE_NORMAL, ABOVE_NORMAL_PRIORITY_CLASS, IDS_PRI_ABOVENORMAL }, - { NULL, THREAD_PRIORITY_NORMAL, NORMAL_PRIORITY_CLASS, IDS_PRI_NORMAL }, - { NULL, THREAD_PRIORITY_BELOW_NORMAL, BELOW_NORMAL_PRIORITY_CLASS, IDS_PRI_BELOWNORMAL }, - { NULL, THREAD_PRIORITY_LOWEST, IDLE_PRIORITY_CLASS, IDS_PRI_LOW }, - { 0, 0, 0, 0 } + { NULL, THREAD_PRIORITY_ABOVE_NORMAL, ABOVE_NORMAL_PRIORITY_CLASS, IDS_PRI_ABOVENORMAL }, + { NULL, THREAD_PRIORITY_NORMAL, NORMAL_PRIORITY_CLASS, IDS_PRI_NORMAL }, + { NULL, THREAD_PRIORITY_BELOW_NORMAL, BELOW_NORMAL_PRIORITY_CLASS, IDS_PRI_BELOWNORMAL }, + { NULL, THREAD_PRIORITY_LOWEST, IDLE_PRIORITY_CLASS, IDS_PRI_LOW }, + { 0, 0, 0, 0 } }; static void pritransla (void) { - int i; + int i; - for (i = 0; priorities[i].id; i++) { - TCHAR tmp[MAX_DPATH]; - WIN32GUI_LoadUIString (priorities[i].id, tmp, sizeof (tmp) / sizeof (TCHAR)); - priorities[i].name = my_strdup (tmp); - } + for (i = 0; priorities[i].id; i++) { + TCHAR tmp[MAX_DPATH]; + WIN32GUI_LoadUIString (priorities[i].id, tmp, sizeof (tmp) / sizeof (TCHAR)); + priorities[i].name = my_strdup (tmp); + } } static void WIN32_InitLang (void) { - int lid; - WORD langid = -1; + int lid; + WORD langid = -1; - if (regqueryint (NULL, L"Language", &lid)) - langid = (WORD)lid; - hUIDLL = language_load (langid); - pritransla (); + if (regqueryint (NULL, L"Language", &lid)) + langid = (WORD)lid; + hUIDLL = language_load (langid); + pritransla (); } typedef HRESULT (CALLBACK* SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD)(PCWSTR); @@ -1901,37 +1911,37 @@ typedef HRESULT (CALLBACK* SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD)(PCWSTR); /* try to load COMDLG32 and DDRAW, initialize csDraw */ static int WIN32_InitLibraries (void) { - LARGE_INTEGER freq; - SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD pSetCurrentProcessExplicitAppUserModelID; + LARGE_INTEGER freq; + SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD pSetCurrentProcessExplicitAppUserModelID; - CoInitializeEx (NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); - /* Determine our processor speed and capabilities */ - if (!init_mmtimer ()) { - pre_gui_message (L"MMTimer initialization failed, exiting.."); - return 0; - } - if (!QueryPerformanceCounter (&freq)) { - pre_gui_message (L"No QueryPerformanceFrequency() supported, exiting..\n"); - return 0; - } - rpt_available = 1; - figure_processor_speed (); - if (!timebegin ()) { - pre_gui_message (L"MMTimer second initialization failed, exiting.."); - return 0; - } - pSetCurrentProcessExplicitAppUserModelID = (SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID"); - if (pSetCurrentProcessExplicitAppUserModelID) - pSetCurrentProcessExplicitAppUserModelID (WINUAEAPPNAME); - - hRichEdit = LoadLibrary (L"RICHED32.DLL"); - return 1; + CoInitializeEx (NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + /* Determine our processor speed and capabilities */ + if (!init_mmtimer ()) { + pre_gui_message (L"MMTimer initialization failed, exiting.."); + return 0; + } + if (!QueryPerformanceCounter (&freq)) { + pre_gui_message (L"No QueryPerformanceFrequency() supported, exiting..\n"); + return 0; + } + rpt_available = 1; + figure_processor_speed (); + if (!timebegin ()) { + pre_gui_message (L"MMTimer second initialization failed, exiting.."); + return 0; + } + pSetCurrentProcessExplicitAppUserModelID = (SETCURRENTPROCESSEXPLICITAPPUSERMODEIDD)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID"); + if (pSetCurrentProcessExplicitAppUserModelID) + pSetCurrentProcessExplicitAppUserModelID (WINUAEAPPNAME); + + hRichEdit = LoadLibrary (L"RICHED32.DLL"); + return 1; } int debuggable (void) { - return 0; + return 0; } void toggle_mousegrab (void) @@ -1942,18 +1952,18 @@ void toggle_mousegrab (void) void logging_open (int bootlog, int append) { - TCHAR debugfilename[MAX_DPATH]; + TCHAR debugfilename[MAX_DPATH]; - debugfilename[0] = 0; + debugfilename[0] = 0; #ifndef SINGLEFILE - if (currprefs.win32_logfile) - _stprintf (debugfilename, L"%s%s", start_path_data, LOG_NORMAL); - if (bootlog) - _stprintf (debugfilename, L"%s%s", start_path_data, LOG_BOOT); - if (debugfilename[0]) { - if (!debugfile) - debugfile = log_open (debugfilename, append, bootlog); - } + if (currprefs.win32_logfile) + _stprintf (debugfilename, L"%s%s", start_path_data, LOG_NORMAL); + if (bootlog) + _stprintf (debugfilename, L"%s%s", start_path_data, LOG_BOOT); + if (debugfilename[0]) { + if (!debugfile) + debugfile = log_open (debugfilename, append, bootlog); + } #endif } @@ -1961,143 +1971,143 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); void logging_init (void) { - LPFN_ISWOW64PROCESS fnIsWow64Process; - int wow64 = 0; - static int started; - static int first; - - if (first > 1) { - write_log (L"** RESTART **\n"); - return; - } - if (first == 1) { - write_log (L"Log (%s): '%s%s'\n", currprefs.win32_logfile ? L"enabled" : L"disabled", - start_path_data, LOG_NORMAL); - if (debugfile) - log_close (debugfile); - debugfile = 0; - } - logging_open (first ? 0 : 1, 0); - logging_started = 1; - first++; - fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process"); - if (fnIsWow64Process) - fnIsWow64Process (GetCurrentProcess (), &wow64); - write_log (L"%s (%d.%d %s%s[%d])", VersionStr, - osVersion.dwMajorVersion, osVersion.dwMinorVersion, osVersion.szCSDVersion, - _tcslen (osVersion.szCSDVersion) > 0 ? L" " : L"", os_winnt_admin); - write_log (L" %d-bit %X.%X %d", wow64 ? 64 : 32, - SystemInfo.wProcessorLevel, SystemInfo.wProcessorRevision, - SystemInfo.dwNumberOfProcessors); - write_log (L"\n(c) 1995-2001 Bernd Schmidt - Core UAE concept and implementation." - L"\n(c) 1998-2009 Toni Wilen - Win32 port, core code updates." - L"\n(c) 1996-2001 Brian King - Win32 port, Picasso96 RTG, and GUI." - L"\n(c) 1996-1999 Mathias Ortmann - Win32 port and bsdsocket support." - L"\n(c) 2000-2001 Bernd Meyer - JIT engine." - L"\n(c) 2000-2005 Bernd Roesch - MIDI input, many fixes." - L"\nPress F12 to show the Settings Dialog (GUI), Alt-F4 to quit." - L"\nEnd+F1 changes floppy 0, End+F2 changes floppy 1, etc." - L"\n"); - write_log (L"EXE: '%s', DATA: '%s'\n", start_path_exe, start_path_data); - regstatus (); + LPFN_ISWOW64PROCESS fnIsWow64Process; + int wow64 = 0; + static int started; + static int first; + + if (first > 1) { + write_log (L"** RESTART **\n"); + return; + } + if (first == 1) { + write_log (L"Log (%s): '%s%s'\n", currprefs.win32_logfile ? L"enabled" : L"disabled", + start_path_data, LOG_NORMAL); + if (debugfile) + log_close (debugfile); + debugfile = 0; + } + logging_open (first ? 0 : 1, 0); + logging_started = 1; + first++; + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process"); + if (fnIsWow64Process) + fnIsWow64Process (GetCurrentProcess (), &wow64); + write_log (L"%s (%d.%d %s%s[%d])", VersionStr, + osVersion.dwMajorVersion, osVersion.dwMinorVersion, osVersion.szCSDVersion, + _tcslen (osVersion.szCSDVersion) > 0 ? L" " : L"", os_winnt_admin); + write_log (L" %d-bit %X.%X %d", wow64 ? 64 : 32, + SystemInfo.wProcessorLevel, SystemInfo.wProcessorRevision, + SystemInfo.dwNumberOfProcessors); + write_log (L"\n(c) 1995-2001 Bernd Schmidt - Core UAE concept and implementation." + L"\n(c) 1998-2009 Toni Wilen - Win32 port, core code updates." + L"\n(c) 1996-2001 Brian King - Win32 port, Picasso96 RTG, and GUI." + L"\n(c) 1996-1999 Mathias Ortmann - Win32 port and bsdsocket support." + L"\n(c) 2000-2001 Bernd Meyer - JIT engine." + L"\n(c) 2000-2005 Bernd Roesch - MIDI input, many fixes." + L"\nPress F12 to show the Settings Dialog (GUI), Alt-F4 to quit." + L"\nEnd+F1 changes floppy 0, End+F2 changes floppy 1, etc." + L"\n"); + write_log (L"EXE: '%s', DATA: '%s'\n", start_path_exe, start_path_data); + regstatus (); } void logging_cleanup (void) { - if (debugfile) - fclose (debugfile); - debugfile = 0; + if (debugfile) + fclose (debugfile); + debugfile = 0; } uae_u8 *save_log (int bootlog, int *len) { - FILE *f; - uae_u8 *dst = NULL; - int size; - - if (!logging_started) - return NULL; - f = _tfopen (bootlog ? LOG_BOOT : LOG_NORMAL, L"rb"); - if (!f) - return NULL; - fseek (f, 0, SEEK_END); - size = ftell (f); - fseek (f, 0, SEEK_SET); - if (size > 30000) - size = 30000; - if (size > 0) { - dst = xcalloc (1, size + 1); - if (dst) - fread (dst, 1, size, f); - fclose (f); - *len = size + 1; - } - return dst; + FILE *f; + uae_u8 *dst = NULL; + int size; + + if (!logging_started) + return NULL; + f = _tfopen (bootlog ? LOG_BOOT : LOG_NORMAL, L"rb"); + if (!f) + return NULL; + fseek (f, 0, SEEK_END); + size = ftell (f); + fseek (f, 0, SEEK_SET); + if (size > 30000) + size = 30000; + if (size > 0) { + dst = xcalloc (1, size + 1); + if (dst) + fread (dst, 1, size, f); + fclose (f); + *len = size + 1; + } + return dst; } static void strip_slashes (TCHAR *p) { - while (_tcslen (p) > 0 && (p[_tcslen (p) - 1] == '\\' || p[_tcslen (p) - 1] == '/')) - p[_tcslen (p) - 1] = 0; + while (_tcslen (p) > 0 && (p[_tcslen (p) - 1] == '\\' || p[_tcslen (p) - 1] == '/')) + p[_tcslen (p) - 1] = 0; } static void fixtrailing(TCHAR *p) { - if (_tcslen(p) == 0) - return; - if (p[_tcslen(p) - 1] == '/' || p[_tcslen(p) - 1] == '\\') - return; - _tcscat(p, L"\\"); + if (_tcslen(p) == 0) + return; + if (p[_tcslen(p) - 1] == '/' || p[_tcslen(p) - 1] == '\\') + return; + _tcscat(p, L"\\"); } typedef DWORD (STDAPICALLTYPE *PFN_GetKey)(LPVOID lpvBuffer, DWORD dwSize); uae_u8 *target_load_keyfile (struct uae_prefs *p, TCHAR *path, int *sizep, TCHAR *name) { - uae_u8 *keybuf = NULL; - HMODULE h; - PFN_GetKey pfnGetKey; - int size; - TCHAR *libname = L"amigaforever.dll"; - - h = WIN32_LoadLibrary (libname); - if (!h) { - TCHAR path[MAX_DPATH]; - _stprintf (path, L"%s..\\Player\\%s", start_path_exe, libname); - h = WIN32_LoadLibrary2 (path); + uae_u8 *keybuf = NULL; + HMODULE h; + PFN_GetKey pfnGetKey; + int size; + TCHAR *libname = L"amigaforever.dll"; + + h = WIN32_LoadLibrary (libname); if (!h) { - TCHAR *afr = _wgetenv (L"AMIGAFOREVERROOT"); - if (afr) { - TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, afr); - fixtrailing (tmp); - _stprintf (path, L"%sPlayer\\%s", tmp, libname); + TCHAR path[MAX_DPATH]; + _stprintf (path, L"%s..\\Player\\%s", start_path_exe, libname); h = WIN32_LoadLibrary2 (path); - } + if (!h) { + TCHAR *afr = _wgetenv (L"AMIGAFOREVERROOT"); + if (afr) { + TCHAR tmp[MAX_DPATH]; + _tcscpy (tmp, afr); + fixtrailing (tmp); + _stprintf (path, L"%sPlayer\\%s", tmp, libname); + h = WIN32_LoadLibrary2 (path); + } + } } - } - if (!h) - return NULL; - GetModuleFileName (h, name, MAX_DPATH); - //write_log (L"keydll: %s'\n", name); - pfnGetKey = (PFN_GetKey)GetProcAddress (h, "GetKey"); - //write_log (L"addr: %08x\n", pfnGetKey); - if (pfnGetKey) { - size = pfnGetKey (NULL, 0); - *sizep = size; - //write_log (L"size: %d\n", size); - if (size > 0) { - int gotsize; - keybuf = xmalloc (size); - gotsize = pfnGetKey (keybuf, size); - //write_log (L"gotsize: %d\n", gotsize); - if (gotsize != size) { - xfree (keybuf); - keybuf = NULL; - } - } - } - FreeLibrary (h); - //write_log (L"keybuf=%08x\n", keybuf); - return keybuf; + if (!h) + return NULL; + GetModuleFileName (h, name, MAX_DPATH); + //write_log (L"keydll: %s'\n", name); + pfnGetKey = (PFN_GetKey)GetProcAddress (h, "GetKey"); + //write_log (L"addr: %08x\n", pfnGetKey); + if (pfnGetKey) { + size = pfnGetKey (NULL, 0); + *sizep = size; + //write_log (L"size: %d\n", size); + if (size > 0) { + int gotsize; + keybuf = xmalloc (size); + gotsize = pfnGetKey (keybuf, size); + //write_log (L"gotsize: %d\n", gotsize); + if (gotsize != size) { + xfree (keybuf); + keybuf = NULL; + } + } + } + FreeLibrary (h); + //write_log (L"keybuf=%08x\n", keybuf); + return keybuf; } @@ -2105,24 +2115,24 @@ extern TCHAR *get_aspi_path(int); static get_aspi (int old) { - if ((old == UAESCSI_SPTI || old == UAESCSI_SPTISCAN) && os_winnt_admin) - return old; - if (old == UAESCSI_NEROASPI && get_aspi_path (1)) - return old; - if (old == UAESCSI_FROGASPI && get_aspi_path (2)) - return old; - if (old == UAESCSI_ADAPTECASPI && get_aspi_path (0)) - return old; - if (os_winnt_admin) - return UAESCSI_SPTI; - else if (get_aspi_path (1)) - return UAESCSI_NEROASPI; - else if (get_aspi_path (2)) - return UAESCSI_FROGASPI; - else if (get_aspi_path (0)) - return UAESCSI_ADAPTECASPI; - else - return UAESCSI_SPTI; + if ((old == UAESCSI_SPTI || old == UAESCSI_SPTISCAN) && os_winnt_admin) + return old; + if (old == UAESCSI_NEROASPI && get_aspi_path (1)) + return old; + if (old == UAESCSI_FROGASPI && get_aspi_path (2)) + return old; + if (old == UAESCSI_ADAPTECASPI && get_aspi_path (0)) + return old; + if (os_winnt_admin) + return UAESCSI_SPTI; + else if (get_aspi_path (1)) + return UAESCSI_NEROASPI; + else if (get_aspi_path (2)) + return UAESCSI_FROGASPI; + else if (get_aspi_path (0)) + return UAESCSI_ADAPTECASPI; + else + return UAESCSI_SPTI; } @@ -2165,1354 +2175,1354 @@ static get_aspi (int old) static void __cdecl wparse_cmdline ( - _TSCHAR *cmdstart, - _TSCHAR **argv, - _TSCHAR *args, - int *numargs, - int *numchars - ) + _TSCHAR *cmdstart, + _TSCHAR **argv, + _TSCHAR *args, + int *numargs, + int *numchars + ) { - _TSCHAR *p; - _TUCHAR c; - int inquote; /* 1 = inside quotes */ - int copychar; /* 1 = copy char to *args */ - unsigned numslash; /* num of backslashes seen */ + _TSCHAR *p; + _TUCHAR c; + int inquote; /* 1 = inside quotes */ + int copychar; /* 1 = copy char to *args */ + unsigned numslash; /* num of backslashes seen */ - *numchars = 0; - *numargs = 1; /* the program name at least */ + *numchars = 0; + *numargs = 1; /* the program name at least */ - /* first scan the program name, copy it, and count the bytes */ - p = cmdstart; - if (argv) - *argv++ = args; + /* first scan the program name, copy it, and count the bytes */ + p = cmdstart; + if (argv) + *argv++ = args; #ifdef WILDCARD - /* To handle later wild card expansion, we prefix each entry by - it's first character before quote handling. This is done - so _[w]cwild() knows whether to expand an entry or not. */ - if (args) - *args++ = *p; - ++*numchars; + /* To handle later wild card expansion, we prefix each entry by + it's first character before quote handling. This is done + so _[w]cwild() knows whether to expand an entry or not. */ + if (args) + *args++ = *p; + ++*numchars; #endif /* WILDCARD */ - /* A quoted program name is handled here. The handling is much - simpler than for other arguments. Basically, whatever lies - between the leading double-quote and next one, or a terminal null - character is simply accepted. Fancier handling is not required - because the program name must be a legal NTFS/HPFS file name. - Note that the double-quote characters are not copied, nor do they - contribute to numchars. */ - inquote = FALSE; - do { - if (*p == DQUOTECHAR ) - { - inquote = !inquote; - c = (_TUCHAR) *p++; - continue; - } - ++*numchars; - if (args) - *args++ = *p; - - c = (_TUCHAR) *p++; + /* A quoted program name is handled here. The handling is much + simpler than for other arguments. Basically, whatever lies + between the leading double-quote and next one, or a terminal null + character is simply accepted. Fancier handling is not required + because the program name must be a legal NTFS/HPFS file name. + Note that the double-quote characters are not copied, nor do they + contribute to numchars. */ + inquote = FALSE; + do { + if (*p == DQUOTECHAR ) + { + inquote = !inquote; + c = (_TUCHAR) *p++; + continue; + } + ++*numchars; + if (args) + *args++ = *p; + + c = (_TUCHAR) *p++; #ifdef _MBCS - if (_ismbblead(c)) { - ++*numchars; - if (args) - *args++ = *p; /* copy 2nd byte too */ - p++; /* skip over trail byte */ - } + if (_ismbblead(c)) { + ++*numchars; + if (args) + *args++ = *p; /* copy 2nd byte too */ + p++; /* skip over trail byte */ + } #endif /* _MBCS */ - } while ( (c != NULCHAR && (inquote || (c !=SPACECHAR && c != TABCHAR))) ); + } while ( (c != NULCHAR && (inquote || (c !=SPACECHAR && c != TABCHAR))) ); - if ( c == NULCHAR ) { - p--; - } else { - if (args) - *(args-1) = NULCHAR; - } + if ( c == NULCHAR ) { + p--; + } else { + if (args) + *(args-1) = NULCHAR; + } - inquote = 0; + inquote = 0; - /* loop on each argument */ - for(;;) { + /* loop on each argument */ + for(;;) { - if ( *p ) { - while (*p == SPACECHAR || *p == TABCHAR) - ++p; - } + if ( *p ) { + while (*p == SPACECHAR || *p == TABCHAR) + ++p; + } - if (*p == NULCHAR) - break; /* end of args */ + if (*p == NULCHAR) + break; /* end of args */ - /* scan an argument */ - if (argv) - *argv++ = args; /* store ptr to arg */ - ++*numargs; + /* scan an argument */ + if (argv) + *argv++ = args; /* store ptr to arg */ + ++*numargs; #ifdef WILDCARD - /* To handle later wild card expansion, we prefix each entry by - it's first character before quote handling. This is done - so _[w]cwild() knows whether to expand an entry or not. */ - if (args) - *args++ = *p; - ++*numchars; + /* To handle later wild card expansion, we prefix each entry by + it's first character before quote handling. This is done + so _[w]cwild() knows whether to expand an entry or not. */ + if (args) + *args++ = *p; + ++*numchars; #endif /* WILDCARD */ - /* loop through scanning one argument */ - for (;;) { - copychar = 1; - /* Rules: 2N backslashes + " ==> N backslashes and begin/end quote - 2N+1 backslashes + " ==> N backslashes + literal " - N backslashes ==> N backslashes */ - numslash = 0; - while (*p == SLASHCHAR) { - /* count number of backslashes for use below */ - ++p; - ++numslash; - } - if (*p == DQUOTECHAR) { - /* if 2N backslashes before, start/end quote, otherwise - copy literally */ - if (numslash % 2 == 0) { - if (inquote && p[1] == DQUOTECHAR) { - p++; /* Double quote inside quoted string */ - } else { /* skip first quote char and copy second */ - copychar = 0; /* don't copy quote */ - inquote = !inquote; - } - } - numslash /= 2; /* divide numslash by two */ - } - - /* copy slashes */ - while (numslash--) { - if (args) - *args++ = SLASHCHAR; - ++*numchars; - } - - /* if at end of arg, break loop */ - if (*p == NULCHAR || (!inquote && (*p == SPACECHAR || *p == TABCHAR))) - break; - - /* copy character into argument */ + /* loop through scanning one argument */ + for (;;) { + copychar = 1; + /* Rules: 2N backslashes + " ==> N backslashes and begin/end quote + 2N+1 backslashes + " ==> N backslashes + literal " + N backslashes ==> N backslashes */ + numslash = 0; + while (*p == SLASHCHAR) { + /* count number of backslashes for use below */ + ++p; + ++numslash; + } + if (*p == DQUOTECHAR) { + /* if 2N backslashes before, start/end quote, otherwise + copy literally */ + if (numslash % 2 == 0) { + if (inquote && p[1] == DQUOTECHAR) { + p++; /* Double quote inside quoted string */ + } else { /* skip first quote char and copy second */ + copychar = 0; /* don't copy quote */ + inquote = !inquote; + } + } + numslash /= 2; /* divide numslash by two */ + } + + /* copy slashes */ + while (numslash--) { + if (args) + *args++ = SLASHCHAR; + ++*numchars; + } + + /* if at end of arg, break loop */ + if (*p == NULCHAR || (!inquote && (*p == SPACECHAR || *p == TABCHAR))) + break; + + /* copy character into argument */ #ifdef _MBCS - if (copychar) { - if (args) { - if (_ismbblead(*p)) { - *args++ = *p++; - ++*numchars; - } - *args++ = *p; - } else { - if (_ismbblead(*p)) { - ++p; - ++*numchars; - } - } - ++*numchars; - } - ++p; + if (copychar) { + if (args) { + if (_ismbblead(*p)) { + *args++ = *p++; + ++*numchars; + } + *args++ = *p; + } else { + if (_ismbblead(*p)) { + ++p; + ++*numchars; + } + } + ++*numchars; + } + ++p; #else /* _MBCS */ - if (copychar) { - if (args) - *args++ = *p; - ++*numchars; - } - ++p; + if (copychar) { + if (args) + *args++ = *p; + ++*numchars; + } + ++p; #endif /* _MBCS */ - } + } - /* null-terminate the argument */ + /* null-terminate the argument */ - if (args) - *args++ = NULCHAR; /* terminate string */ - ++*numchars; - } + if (args) + *args++ = NULCHAR; /* terminate string */ + ++*numchars; + } - /* We put one last argument in -- a null ptr */ - if (argv) - *argv++ = NULL; - ++*numargs; + /* We put one last argument in -- a null ptr */ + if (argv) + *argv++ = NULL; + ++*numargs; } #define MAX_ARGUMENTS 128 static TCHAR **parseargstring (TCHAR *s) { - TCHAR **p; - int numa, numc; - - if (_tcslen (s) == 0) - return NULL; - wparse_cmdline (s, NULL, NULL, &numa, &numc); - numa++; - p = xcalloc (numa * sizeof (TCHAR*) + numc * sizeof (TCHAR), 1); - wparse_cmdline (s, (wchar_t **)p, (wchar_t *)(((char *)p) + numa * sizeof(wchar_t *)), &numa, &numc); - if (numa > MAX_ARGUMENTS) - p[MAX_ARGUMENTS] = NULL; - return p; + TCHAR **p; + int numa, numc; + + if (_tcslen (s) == 0) + return NULL; + wparse_cmdline (s, NULL, NULL, &numa, &numc); + numa++; + p = xcalloc (numa * sizeof (TCHAR*) + numc * sizeof (TCHAR), 1); + wparse_cmdline (s, (wchar_t **)p, (wchar_t *)(((char *)p) + numa * sizeof(wchar_t *)), &numa, &numc); + if (numa > MAX_ARGUMENTS) + p[MAX_ARGUMENTS] = NULL; + return p; } static void shellexecute (TCHAR *command) { - STARTUPINFO si = { 0 }; - PROCESS_INFORMATION pi = { 0 }; - TCHAR **arg; - int i, j, k, stop; - - if (_tcslen (command) == 0) - return; - i = j = 0; - stop = 0; - arg = parseargstring (command); - while (!stop) { - TCHAR *cmd, *exec; - int len = 1; - j = i; - while (arg[i] && _tcscmp (arg[i], L";")) { - len += _tcslen (arg[i]) + 3; - i++; - } - exec = NULL; - cmd = xcalloc (len, sizeof (TCHAR)); - for (k = j; k < i; k++) { - int quote = 0; - if (_tcslen (cmd) > 0) - _tcscat (cmd, L" "); - if (_tcschr (arg[k], ' ')) - quote = 1; - if (quote) - _tcscat (cmd, L"\""); - _tcscat (cmd, arg[k]); - if (quote) - _tcscat (cmd, L"\""); - if (!exec && !_tcsicmp (cmd, L"cmd.exe")) { - int size; - size = GetEnvironmentVariable (L"ComSpec", NULL, 0); - if (size > 0) { - exec = xcalloc (size + 1, sizeof (TCHAR)); - GetEnvironmentVariable (L"ComSpec", exec, size); + STARTUPINFO si = { 0 }; + PROCESS_INFORMATION pi = { 0 }; + TCHAR **arg; + int i, j, k, stop; + + if (_tcslen (command) == 0) + return; + i = j = 0; + stop = 0; + arg = parseargstring (command); + while (!stop) { + TCHAR *cmd, *exec; + int len = 1; + j = i; + while (arg[i] && _tcscmp (arg[i], L";")) { + len += _tcslen (arg[i]) + 3; + i++; } - cmd[0] = 0; - } - } - if (arg[i++] == 0) - stop = 1; - si.cb = sizeof si; - //si.wShowWindow = SW_HIDE; - //si.dwFlags = STARTF_USESHOWWINDOW; - if (CreateProcess (exec, - cmd, - NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { - WaitForSingleObject (pi.hProcess, INFINITE); - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - } else { - write_log (L"CreateProcess('%s' '%s') failed, %d\n", - exec, cmd, GetLastError ()); + exec = NULL; + cmd = xcalloc (len, sizeof (TCHAR)); + for (k = j; k < i; k++) { + int quote = 0; + if (_tcslen (cmd) > 0) + _tcscat (cmd, L" "); + if (_tcschr (arg[k], ' ')) + quote = 1; + if (quote) + _tcscat (cmd, L"\""); + _tcscat (cmd, arg[k]); + if (quote) + _tcscat (cmd, L"\""); + if (!exec && !_tcsicmp (cmd, L"cmd.exe")) { + int size; + size = GetEnvironmentVariable (L"ComSpec", NULL, 0); + if (size > 0) { + exec = xcalloc (size + 1, sizeof (TCHAR)); + GetEnvironmentVariable (L"ComSpec", exec, size); + } + cmd[0] = 0; + } + } + if (arg[i++] == 0) + stop = 1; + si.cb = sizeof si; + //si.wShowWindow = SW_HIDE; + //si.dwFlags = STARTF_USESHOWWINDOW; + if (CreateProcess (exec, + cmd, + NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { + WaitForSingleObject (pi.hProcess, INFINITE); + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + } else { + write_log (L"CreateProcess('%s' '%s') failed, %d\n", + exec, cmd, GetLastError ()); + } + xfree (exec); + xfree (cmd); } - xfree (exec); - xfree (cmd); - } - xfree (arg); + xfree (arg); } void target_run (void) { - shellexecute (currprefs.win32_commandpathstart); + shellexecute (currprefs.win32_commandpathstart); } void target_quit (void) { - shellexecute (currprefs.win32_commandpathend); + shellexecute (currprefs.win32_commandpathend); } void target_fixup_options (struct uae_prefs *p) { #ifdef RETROPLATFORM - rp_fixup_options (p); + rp_fixup_options (p); #endif } void target_default_options (struct uae_prefs *p, int type) { - if (type == 2 || type == 0) { - p->win32_middle_mouse = 1; - p->win32_logfile = 0; - p->win32_iconified_nosound = 1; - p->win32_iconified_pause = 1; - p->win32_inactive_nosound = 0; - p->win32_inactive_pause = 0; - p->win32_ctrl_F11_is_quit = 0; - p->win32_soundcard = 0; - p->win32_soundexclusive = 0; - p->win32_active_priority = 1; - p->win32_inactive_priority = 2; - p->win32_iconified_priority = 3; - p->win32_notaskbarbutton = 0; - p->win32_alwaysontop = 0; - p->win32_specialkey = 0xcf; // DIK_END - p->win32_guikey = -1; - p->win32_automount_removable = 0; - p->win32_automount_drives = 0; - p->win32_automount_removabledrives = 0; - p->win32_automount_cddrives = 0; - p->win32_automount_netdrives = 0; - p->win32_kbledmode = 0; - p->win32_uaescsimode = get_aspi (p->win32_uaescsimode); - p->win32_borderless = 0; - p->win32_powersavedisabled = 1; - p->sana2 = 0; - p->win32_rtgmatchdepth = 1; - p->win32_rtgscaleifsmall = 1; - p->win32_rtgallowscaling = 0; - p->win32_rtgscaleaspectratio = -1; - p->win32_rtgvblankrate = 0; - p->win32_fscodepage = 0; - p->win32_commandpathstart[0] = 0; - p->win32_commandpathend[0] = 0; - } - if (type == 1 || type == 0) { - p->win32_uaescsimode = get_aspi (p->win32_uaescsimode); - p->win32_midioutdev = -2; - p->win32_midiindev = 0; - p->win32_automount_removable = 0; - p->win32_automount_drives = 0; - p->win32_automount_removabledrives = 0; - p->win32_automount_cddrives = 0; - p->win32_automount_netdrives = 0; - p->picasso96_modeflags = RGBFF_CLUT | RGBFF_R5G6B5PC | RGBFF_B8G8R8A8; - } + if (type == 2 || type == 0) { + p->win32_middle_mouse = 1; + p->win32_logfile = 0; + p->win32_iconified_nosound = 1; + p->win32_iconified_pause = 1; + p->win32_inactive_nosound = 0; + p->win32_inactive_pause = 0; + p->win32_ctrl_F11_is_quit = 0; + p->win32_soundcard = 0; + p->win32_soundexclusive = 0; + p->win32_active_priority = 1; + p->win32_inactive_priority = 2; + p->win32_iconified_priority = 3; + p->win32_notaskbarbutton = 0; + p->win32_alwaysontop = 0; + p->win32_specialkey = 0xcf; // DIK_END + p->win32_guikey = -1; + p->win32_automount_removable = 0; + p->win32_automount_drives = 0; + p->win32_automount_removabledrives = 0; + p->win32_automount_cddrives = 0; + p->win32_automount_netdrives = 0; + p->win32_kbledmode = 0; + p->win32_uaescsimode = get_aspi (p->win32_uaescsimode); + p->win32_borderless = 0; + p->win32_powersavedisabled = 1; + p->sana2 = 0; + p->win32_rtgmatchdepth = 1; + p->win32_rtgscaleifsmall = 1; + p->win32_rtgallowscaling = 0; + p->win32_rtgscaleaspectratio = -1; + p->win32_rtgvblankrate = 0; + p->win32_fscodepage = 0; + p->win32_commandpathstart[0] = 0; + p->win32_commandpathend[0] = 0; + } + if (type == 1 || type == 0) { + p->win32_uaescsimode = get_aspi (p->win32_uaescsimode); + p->win32_midioutdev = -2; + p->win32_midiindev = 0; + p->win32_automount_removable = 0; + p->win32_automount_drives = 0; + p->win32_automount_removabledrives = 0; + p->win32_automount_cddrives = 0; + p->win32_automount_netdrives = 0; + p->picasso96_modeflags = RGBFF_CLUT | RGBFF_R5G6B5PC | RGBFF_B8G8R8A8; + } } static const TCHAR *scsimode[] = { L"none", L"SPTI", L"SPTI+SCSISCAN", L"AdaptecASPI", L"NeroASPI", L"FrogASPI", 0 }; void target_save_options (struct zfile *f, struct uae_prefs *p) { - cfgfile_target_dwrite_bool (f, L"middle_mouse", p->win32_middle_mouse); - cfgfile_target_dwrite_bool (f, L"logfile", p->win32_logfile); - cfgfile_target_dwrite_bool (f, L"map_drives", p->win32_automount_drives); - cfgfile_target_dwrite_bool (f, L"map_drives_auto", p->win32_automount_removable); - cfgfile_target_dwrite_bool (f, L"map_cd_drives", p->win32_automount_cddrives); - cfgfile_target_dwrite_bool (f, L"map_net_drives", p->win32_automount_netdrives); - cfgfile_target_dwrite_bool (f, L"map_removable_drives", p->win32_automount_removabledrives); - serdevtoname (p->sername); - cfgfile_target_dwrite_str (f, L"serial_port", p->sername[0] ? p->sername : L"none"); - sernametodev (p->sername); - cfgfile_target_dwrite_str (f, L"parallel_port", p->prtname[0] ? p->prtname : L"none"); - - cfgfile_target_dwrite (f, L"active_priority", L"%d", priorities[p->win32_active_priority].value); - cfgfile_target_dwrite (f, L"inactive_priority", L"%d", priorities[p->win32_inactive_priority].value); - cfgfile_target_dwrite_bool (f, L"inactive_nosound", p->win32_inactive_nosound); - cfgfile_target_dwrite_bool (f, L"inactive_pause", p->win32_inactive_pause); - cfgfile_target_dwrite (f, L"iconified_priority", L"%d", priorities[p->win32_iconified_priority].value); - cfgfile_target_dwrite_bool (f, L"iconified_nosound", p->win32_iconified_nosound); - cfgfile_target_dwrite_bool (f, L"iconified_pause", p->win32_iconified_pause); - - cfgfile_target_dwrite_bool (f, L"ctrl_f11_is_quit", p->win32_ctrl_F11_is_quit); - cfgfile_target_dwrite (f, L"midiout_device", L"%d", p->win32_midioutdev); - cfgfile_target_dwrite (f, L"midiin_device", L"%d", p->win32_midiindev); - cfgfile_target_dwrite_bool (f, L"rtg_match_depth", p->win32_rtgmatchdepth); - cfgfile_target_dwrite_bool (f, L"rtg_scale_small", p->win32_rtgscaleifsmall); - cfgfile_target_dwrite_bool (f, L"rtg_scale_allow", p->win32_rtgallowscaling); - cfgfile_target_dwrite (f, L"rtg_scale_aspect_ratio", L"%d:%d", - p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio >> 8) : -1, - p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio & 0xff) : -1); - if (p->win32_rtgvblankrate <= 0) - cfgfile_target_dwrite_str (f, L"rtg_vblank", p->win32_rtgvblankrate == -1 ? L"real" : (p->win32_rtgvblankrate == -2 ? L"disabled" : L"chipset")); - else - cfgfile_target_dwrite (f, L"rtg_vblank", L"%d", p->win32_rtgvblankrate); - cfgfile_target_dwrite_bool (f, L"borderless", p->win32_borderless); - cfgfile_target_dwrite_str (f, L"uaescsimode", scsimode[p->win32_uaescsimode]); - cfgfile_target_dwrite (f, L"soundcard", L"%d", p->win32_soundcard); - if (sound_devices[p->win32_soundcard].cfgname) - cfgfile_target_dwrite_str (f, L"soundcardname", sound_devices[p->win32_soundcard].cfgname); - cfgfile_target_dwrite_bool (f, L"soundcard_exclusive", p->win32_soundexclusive); - cfgfile_target_dwrite (f, L"cpu_idle", L"%d", p->cpu_idle); - cfgfile_target_dwrite_bool (f, L"notaskbarbutton", p->win32_notaskbarbutton); - cfgfile_target_dwrite_bool (f, L"always_on_top", p->win32_alwaysontop); - cfgfile_target_dwrite_bool (f, L"no_recyclebin", p->win32_norecyclebin); - cfgfile_target_dwrite (f, L"specialkey", L"0x%x", p->win32_specialkey); - if (p->win32_guikey >= 0) - cfgfile_target_dwrite (f, L"guikey", L"0x%x", p->win32_guikey); - cfgfile_target_dwrite (f, L"kbledmode", L"%d", p->win32_kbledmode); - cfgfile_target_dwrite_bool (f, L"powersavedisabled", p->win32_powersavedisabled); - cfgfile_target_dwrite (f, L"filesystem_codepage", L"%d", p->win32_fscodepage); - cfgfile_target_dwrite_str (f, L"exec_before", p->win32_commandpathstart); - cfgfile_target_dwrite_str (f, L"exec_after", p->win32_commandpathend); + cfgfile_target_dwrite_bool (f, L"middle_mouse", p->win32_middle_mouse); + cfgfile_target_dwrite_bool (f, L"logfile", p->win32_logfile); + cfgfile_target_dwrite_bool (f, L"map_drives", p->win32_automount_drives); + cfgfile_target_dwrite_bool (f, L"map_drives_auto", p->win32_automount_removable); + cfgfile_target_dwrite_bool (f, L"map_cd_drives", p->win32_automount_cddrives); + cfgfile_target_dwrite_bool (f, L"map_net_drives", p->win32_automount_netdrives); + cfgfile_target_dwrite_bool (f, L"map_removable_drives", p->win32_automount_removabledrives); + serdevtoname (p->sername); + cfgfile_target_dwrite_str (f, L"serial_port", p->sername[0] ? p->sername : L"none"); + sernametodev (p->sername); + cfgfile_target_dwrite_str (f, L"parallel_port", p->prtname[0] ? p->prtname : L"none"); + + cfgfile_target_dwrite (f, L"active_priority", L"%d", priorities[p->win32_active_priority].value); + cfgfile_target_dwrite (f, L"inactive_priority", L"%d", priorities[p->win32_inactive_priority].value); + cfgfile_target_dwrite_bool (f, L"inactive_nosound", p->win32_inactive_nosound); + cfgfile_target_dwrite_bool (f, L"inactive_pause", p->win32_inactive_pause); + cfgfile_target_dwrite (f, L"iconified_priority", L"%d", priorities[p->win32_iconified_priority].value); + cfgfile_target_dwrite_bool (f, L"iconified_nosound", p->win32_iconified_nosound); + cfgfile_target_dwrite_bool (f, L"iconified_pause", p->win32_iconified_pause); + + cfgfile_target_dwrite_bool (f, L"ctrl_f11_is_quit", p->win32_ctrl_F11_is_quit); + cfgfile_target_dwrite (f, L"midiout_device", L"%d", p->win32_midioutdev); + cfgfile_target_dwrite (f, L"midiin_device", L"%d", p->win32_midiindev); + cfgfile_target_dwrite_bool (f, L"rtg_match_depth", p->win32_rtgmatchdepth); + cfgfile_target_dwrite_bool (f, L"rtg_scale_small", p->win32_rtgscaleifsmall); + cfgfile_target_dwrite_bool (f, L"rtg_scale_allow", p->win32_rtgallowscaling); + cfgfile_target_dwrite (f, L"rtg_scale_aspect_ratio", L"%d:%d", + p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio >> 8) : -1, + p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio & 0xff) : -1); + if (p->win32_rtgvblankrate <= 0) + cfgfile_target_dwrite_str (f, L"rtg_vblank", p->win32_rtgvblankrate == -1 ? L"real" : (p->win32_rtgvblankrate == -2 ? L"disabled" : L"chipset")); + else + cfgfile_target_dwrite (f, L"rtg_vblank", L"%d", p->win32_rtgvblankrate); + cfgfile_target_dwrite_bool (f, L"borderless", p->win32_borderless); + cfgfile_target_dwrite_str (f, L"uaescsimode", scsimode[p->win32_uaescsimode]); + cfgfile_target_dwrite (f, L"soundcard", L"%d", p->win32_soundcard); + if (sound_devices[p->win32_soundcard].cfgname) + cfgfile_target_dwrite_str (f, L"soundcardname", sound_devices[p->win32_soundcard].cfgname); + cfgfile_target_dwrite_bool (f, L"soundcard_exclusive", p->win32_soundexclusive); + cfgfile_target_dwrite (f, L"cpu_idle", L"%d", p->cpu_idle); + cfgfile_target_dwrite_bool (f, L"notaskbarbutton", p->win32_notaskbarbutton); + cfgfile_target_dwrite_bool (f, L"always_on_top", p->win32_alwaysontop); + cfgfile_target_dwrite_bool (f, L"no_recyclebin", p->win32_norecyclebin); + cfgfile_target_dwrite (f, L"specialkey", L"0x%x", p->win32_specialkey); + if (p->win32_guikey >= 0) + cfgfile_target_dwrite (f, L"guikey", L"0x%x", p->win32_guikey); + cfgfile_target_dwrite (f, L"kbledmode", L"%d", p->win32_kbledmode); + cfgfile_target_dwrite_bool (f, L"powersavedisabled", p->win32_powersavedisabled); + cfgfile_target_dwrite (f, L"filesystem_codepage", L"%d", p->win32_fscodepage); + cfgfile_target_dwrite_str (f, L"exec_before", p->win32_commandpathstart); + cfgfile_target_dwrite_str (f, L"exec_after", p->win32_commandpathend); } static int fetchpri (int pri, int defpri) { - int i = 0; - while (priorities[i].name) { - if (priorities[i].value == pri) - return i; - i++; - } - return defpri; + int i = 0; + while (priorities[i].name) { + if (priorities[i].value == pri) + return i; + i++; + } + return defpri; } static const TCHAR *obsolete[] = { - L"killwinkeys", L"sound_force_primary", L"iconified_highpriority", - L"sound_sync", L"sound_tweak", L"directx6", L"sound_style", - L"file_path", L"iconified_nospeed", L"activepriority", L"magic_mouse", - 0 + L"killwinkeys", L"sound_force_primary", L"iconified_highpriority", + L"sound_sync", L"sound_tweak", L"directx6", L"sound_style", + L"file_path", L"iconified_nospeed", L"activepriority", L"magic_mouse", + 0 }; int target_parse_option (struct uae_prefs *p, TCHAR *option, TCHAR *value) { - TCHAR tmpbuf[CONFIG_BLEN]; - int i, v; - int result = (cfgfile_yesno (option, value, L"middle_mouse", &p->win32_middle_mouse) - || cfgfile_yesno (option, value, L"map_drives", &p->win32_automount_drives) - || cfgfile_yesno (option, value, L"map_drives_auto", &p->win32_automount_removable) - || cfgfile_yesno (option, value, L"map_cd_drives", &p->win32_automount_cddrives) - || cfgfile_yesno (option, value, L"map_net_drives", &p->win32_automount_netdrives) - || cfgfile_yesno (option, value, L"map_removable_drives", &p->win32_automount_removabledrives) - || cfgfile_yesno (option, value, L"logfile", &p->win32_logfile) - || cfgfile_yesno (option, value, L"networking", &p->socket_emu) - || cfgfile_yesno (option, value, L"borderless", &p->win32_borderless) - || cfgfile_yesno (option, value, L"inactive_pause", &p->win32_inactive_pause) - || cfgfile_yesno (option, value, L"inactive_nosound", &p->win32_inactive_nosound) - || cfgfile_yesno (option, value, L"iconified_pause", &p->win32_iconified_pause) - || cfgfile_yesno (option, value, L"iconified_nosound", &p->win32_iconified_nosound) - || cfgfile_yesno (option, value, L"ctrl_f11_is_quit", &p->win32_ctrl_F11_is_quit) - || cfgfile_yesno (option, value, L"no_recyclebin", &p->win32_norecyclebin) - || cfgfile_intval (option, value, L"midi_device", &p->win32_midioutdev, 1) - || cfgfile_intval (option, value, L"midiout_device", &p->win32_midioutdev, 1) - || cfgfile_intval (option, value, L"midiin_device", &p->win32_midiindev, 1) - || cfgfile_intval (option, value, L"soundcard", &p->win32_soundcard, 1) - || cfgfile_yesno (option, value, L"soundcard_exclusive", &p->win32_soundexclusive) - || cfgfile_yesno (option, value, L"notaskbarbutton", &p->win32_notaskbarbutton) - || cfgfile_yesno (option, value, L"always_on_top", &p->win32_alwaysontop) - || cfgfile_yesno (option, value, L"powersavedisabled", &p->win32_powersavedisabled) - || cfgfile_string (option, value, L"exec_before", p->win32_commandpathstart, sizeof p->win32_commandpathstart / sizeof (TCHAR)) - || cfgfile_string (option, value, L"exec_after", p->win32_commandpathend, sizeof p->win32_commandpathend / sizeof (TCHAR)) - || cfgfile_intval (option, value, L"specialkey", &p->win32_specialkey, 1) - || cfgfile_intval (option, value, L"guikey", &p->win32_guikey, 1) - || cfgfile_intval (option, value, L"kbledmode", &p->win32_kbledmode, 1) - || cfgfile_intval (option, value, L"filesystem_codepage", &p->win32_fscodepage, 1) - || cfgfile_intval (option, value, L"cpu_idle", &p->cpu_idle, 1)); - - if (cfgfile_yesno (option, value, L"rtg_match_depth", &p->win32_rtgmatchdepth)) - return 1; - if (cfgfile_yesno (option, value, L"rtg_scale_small", &p->win32_rtgscaleifsmall)) - return 1; - if (cfgfile_yesno (option, value, L"rtg_scale_allow", &p->win32_rtgallowscaling)) - return 1; + TCHAR tmpbuf[CONFIG_BLEN]; + int i, v; + int result = (cfgfile_yesno (option, value, L"middle_mouse", &p->win32_middle_mouse) + || cfgfile_yesno (option, value, L"map_drives", &p->win32_automount_drives) + || cfgfile_yesno (option, value, L"map_drives_auto", &p->win32_automount_removable) + || cfgfile_yesno (option, value, L"map_cd_drives", &p->win32_automount_cddrives) + || cfgfile_yesno (option, value, L"map_net_drives", &p->win32_automount_netdrives) + || cfgfile_yesno (option, value, L"map_removable_drives", &p->win32_automount_removabledrives) + || cfgfile_yesno (option, value, L"logfile", &p->win32_logfile) + || cfgfile_yesno (option, value, L"networking", &p->socket_emu) + || cfgfile_yesno (option, value, L"borderless", &p->win32_borderless) + || cfgfile_yesno (option, value, L"inactive_pause", &p->win32_inactive_pause) + || cfgfile_yesno (option, value, L"inactive_nosound", &p->win32_inactive_nosound) + || cfgfile_yesno (option, value, L"iconified_pause", &p->win32_iconified_pause) + || cfgfile_yesno (option, value, L"iconified_nosound", &p->win32_iconified_nosound) + || cfgfile_yesno (option, value, L"ctrl_f11_is_quit", &p->win32_ctrl_F11_is_quit) + || cfgfile_yesno (option, value, L"no_recyclebin", &p->win32_norecyclebin) + || cfgfile_intval (option, value, L"midi_device", &p->win32_midioutdev, 1) + || cfgfile_intval (option, value, L"midiout_device", &p->win32_midioutdev, 1) + || cfgfile_intval (option, value, L"midiin_device", &p->win32_midiindev, 1) + || cfgfile_intval (option, value, L"soundcard", &p->win32_soundcard, 1) + || cfgfile_yesno (option, value, L"soundcard_exclusive", &p->win32_soundexclusive) + || cfgfile_yesno (option, value, L"notaskbarbutton", &p->win32_notaskbarbutton) + || cfgfile_yesno (option, value, L"always_on_top", &p->win32_alwaysontop) + || cfgfile_yesno (option, value, L"powersavedisabled", &p->win32_powersavedisabled) + || cfgfile_string (option, value, L"exec_before", p->win32_commandpathstart, sizeof p->win32_commandpathstart / sizeof (TCHAR)) + || cfgfile_string (option, value, L"exec_after", p->win32_commandpathend, sizeof p->win32_commandpathend / sizeof (TCHAR)) + || cfgfile_intval (option, value, L"specialkey", &p->win32_specialkey, 1) + || cfgfile_intval (option, value, L"guikey", &p->win32_guikey, 1) + || cfgfile_intval (option, value, L"kbledmode", &p->win32_kbledmode, 1) + || cfgfile_intval (option, value, L"filesystem_codepage", &p->win32_fscodepage, 1) + || cfgfile_intval (option, value, L"cpu_idle", &p->cpu_idle, 1)); + + if (cfgfile_yesno (option, value, L"rtg_match_depth", &p->win32_rtgmatchdepth)) + return 1; + if (cfgfile_yesno (option, value, L"rtg_scale_small", &p->win32_rtgscaleifsmall)) + return 1; + if (cfgfile_yesno (option, value, L"rtg_scale_allow", &p->win32_rtgallowscaling)) + return 1; - if (cfgfile_string (option, value, L"soundcardname", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - int i, num; - - num = p->win32_soundcard; - p->win32_soundcard = -1; - for (i = 0; sound_devices[i].cfgname; i++) { - if (i < num) - continue; - if (!_tcscmp (sound_devices[i].cfgname, tmpbuf)) { - p->win32_soundcard = i; - break; - } - } - if (p->win32_soundcard < 0) { - for (i = 0; sound_devices[i].cfgname; i++) { - if (!_tcscmp (sound_devices[i].cfgname, tmpbuf)) { - p->win32_soundcard = i; - break; + if (cfgfile_string (option, value, L"soundcardname", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + int i, num; + + num = p->win32_soundcard; + p->win32_soundcard = -1; + for (i = 0; sound_devices[i].cfgname; i++) { + if (i < num) + continue; + if (!_tcscmp (sound_devices[i].cfgname, tmpbuf)) { + p->win32_soundcard = i; + break; + } + } + if (p->win32_soundcard < 0) { + for (i = 0; sound_devices[i].cfgname; i++) { + if (!_tcscmp (sound_devices[i].cfgname, tmpbuf)) { + p->win32_soundcard = i; + break; + } + } } - } + if (p->win32_soundcard < 0) + p->win32_soundcard = num; + return 1; } - if (p->win32_soundcard < 0) - p->win32_soundcard = num; - return 1; - } - if (cfgfile_yesno (option, value, L"aspi", &v)) { - p->win32_uaescsimode = 0; - if (v) - p->win32_uaescsimode = get_aspi (0); - if (p->win32_uaescsimode < UAESCSI_ASPI_FIRST) - p->win32_uaescsimode = UAESCSI_ADAPTECASPI; - return 1; - } - - if (cfgfile_string (option, value, L"rtg_vblank", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - if (!_tcscmp (tmpbuf, L"real")) { - p->win32_rtgvblankrate = -1; - return 1; - } - if (!_tcscmp (tmpbuf, L"disabled")) { - p->win32_rtgvblankrate = -2; - return 1; + if (cfgfile_yesno (option, value, L"aspi", &v)) { + p->win32_uaescsimode = 0; + if (v) + p->win32_uaescsimode = get_aspi (0); + if (p->win32_uaescsimode < UAESCSI_ASPI_FIRST) + p->win32_uaescsimode = UAESCSI_ADAPTECASPI; + return 1; } - if (!_tcscmp (tmpbuf, L"chipset")) { - p->win32_rtgvblankrate = 0; - return 1; + + if (cfgfile_string (option, value, L"rtg_vblank", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + if (!_tcscmp (tmpbuf, L"real")) { + p->win32_rtgvblankrate = -1; + return 1; + } + if (!_tcscmp (tmpbuf, L"disabled")) { + p->win32_rtgvblankrate = -2; + return 1; + } + if (!_tcscmp (tmpbuf, L"chipset")) { + p->win32_rtgvblankrate = 0; + return 1; + } + p->win32_rtgvblankrate = _tstol (tmpbuf); + return 1; } - p->win32_rtgvblankrate = _tstol (tmpbuf); - return 1; - } - - if (cfgfile_string (option, value, L"rtg_scale_aspect_ratio", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { - int v1, v2; - TCHAR *s; - - p->gfx_filter_aspect = -1; - v1 = _tstol (tmpbuf); - s = _tcschr (tmpbuf, ':'); - if (s) { - v2 = _tstol (s + 1); - if (v1 < 0 || v2 < 0) + + if (cfgfile_string (option, value, L"rtg_scale_aspect_ratio", tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { + int v1, v2; + TCHAR *s; + p->gfx_filter_aspect = -1; - else if (v1 == 0 || v2 == 0) - p->gfx_filter_aspect = 0; - else - p->gfx_filter_aspect = (v1 << 8) | v2; + v1 = _tstol (tmpbuf); + s = _tcschr (tmpbuf, ':'); + if (s) { + v2 = _tstol (s + 1); + if (v1 < 0 || v2 < 0) + p->gfx_filter_aspect = -1; + else if (v1 == 0 || v2 == 0) + p->gfx_filter_aspect = 0; + else + p->gfx_filter_aspect = (v1 << 8) | v2; + } + return 1; } - return 1; - } - if (cfgfile_strval (option, value, L"uaescsimode", &p->win32_uaescsimode, scsimode, 0)) - return 1; + if (cfgfile_strval (option, value, L"uaescsimode", &p->win32_uaescsimode, scsimode, 0)) + return 1; - if (cfgfile_intval (option, value, L"active_priority", &v, 1)) { - p->win32_active_priority = fetchpri (v, 1); - return 1; - } - if (cfgfile_intval (option, value, L"activepriority", &v, 1)) { - p->win32_active_priority = fetchpri (v, 1); - return 1; - } - if (cfgfile_intval (option, value, L"inactive_priority", &v, 1)) { - p->win32_inactive_priority = fetchpri (v, 1); - return 1; - } - if (cfgfile_intval (option, value, L"iconified_priority", &v, 1)) { - p->win32_iconified_priority = fetchpri (v, 2); - return 1; - } + if (cfgfile_intval (option, value, L"active_priority", &v, 1)) { + p->win32_active_priority = fetchpri (v, 1); + return 1; + } + if (cfgfile_intval (option, value, L"activepriority", &v, 1)) { + p->win32_active_priority = fetchpri (v, 1); + return 1; + } + if (cfgfile_intval (option, value, L"inactive_priority", &v, 1)) { + p->win32_inactive_priority = fetchpri (v, 1); + return 1; + } + if (cfgfile_intval (option, value, L"iconified_priority", &v, 1)) { + p->win32_iconified_priority = fetchpri (v, 2); + return 1; + } - if (cfgfile_string (option, value, L"serial_port", &p->sername[0], 256)) { - sernametodev(p->sername); - if (p->sername[0]) - p->use_serial = 1; - else - p->use_serial = 0; - return 1; - } + if (cfgfile_string (option, value, L"serial_port", &p->sername[0], 256)) { + sernametodev(p->sername); + if (p->sername[0]) + p->use_serial = 1; + else + p->use_serial = 0; + return 1; + } - if (cfgfile_string (option, value, L"parallel_port", &p->prtname[0], 256)) { - if (!_tcscmp(p->prtname, L"none")) - p->prtname[0] = 0; - return 1; - } + if (cfgfile_string (option, value, L"parallel_port", &p->prtname[0], 256)) { + if (!_tcscmp(p->prtname, L"none")) + p->prtname[0] = 0; + return 1; + } - i = 0; - while (obsolete[i]) { - if (!strcasecmp (obsolete[i], option)) { - write_log (L"obsolete config entry '%s'\n", option); - return 1; + i = 0; + while (obsolete[i]) { + if (!strcasecmp (obsolete[i], option)) { + write_log (L"obsolete config entry '%s'\n", option); + return 1; + } + i++; } - i++; - } - return result; + return result; } static void createdir (const TCHAR *path) { - CreateDirectory (path, NULL); + CreateDirectory (path, NULL); } void fetch_saveimagepath (TCHAR *out, int size, int dir) { - assert (size > MAX_DPATH); - fetch_path (L"SaveimagePath", out, size); - if (dir) { - out[_tcslen (out) - 1] = 0; - createdir (out); + assert (size > MAX_DPATH); fetch_path (L"SaveimagePath", out, size); - } + if (dir) { + out[_tcslen (out) - 1] = 0; + createdir (out); + fetch_path (L"SaveimagePath", out, size); + } } void fetch_configurationpath (TCHAR *out, int size) { - fetch_path (L"ConfigurationPath", out, size); + fetch_path (L"ConfigurationPath", out, size); } void fetch_screenshotpath (TCHAR *out, int size) { - fetch_path (L"ScreenshotPath", out, size); + fetch_path (L"ScreenshotPath", out, size); } void fetch_ripperpath (TCHAR *out, int size) { - fetch_path (L"RipperPath", out, size); + fetch_path (L"RipperPath", out, size); } void fetch_datapath (TCHAR *out, int size) { - fetch_path (NULL, out, size); + fetch_path (NULL, out, size); } static int isfilesindir (TCHAR *p) { - WIN32_FIND_DATA fd; - HANDLE h; - TCHAR path[MAX_DPATH]; - int i = 0; - DWORD v; - - v = GetFileAttributes (p); - if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) - return 0; - _tcscpy (path, p); - _tcscat (path, L"\\*.*"); - h = FindFirstFile (path, &fd); - if (h != INVALID_HANDLE_VALUE) { - for (i = 0; i < 3; i++) { - if (!FindNextFile (h, &fd)) - break; + WIN32_FIND_DATA fd; + HANDLE h; + TCHAR path[MAX_DPATH]; + int i = 0; + DWORD v; + + v = GetFileAttributes (p); + if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) + return 0; + _tcscpy (path, p); + _tcscat (path, L"\\*.*"); + h = FindFirstFile (path, &fd); + if (h != INVALID_HANDLE_VALUE) { + for (i = 0; i < 3; i++) { + if (!FindNextFile (h, &fd)) + break; + } + FindClose (h); } - FindClose (h); - } - if (i == 3) - return 1; - return 0; + if (i == 3) + return 1; + return 0; } void fetch_path (TCHAR *name, TCHAR *out, int size) { - int size2 = size; - - _tcscpy (out, start_path_data); - if (!name) - return; - if (!_tcscmp (name, L"FloppyPath")) - _tcscat (out, L"..\\shared\\adf\\"); - if (!_tcscmp (name, L"hdfPath")) - _tcscat (out, L"..\\shared\\hdf\\"); - if (!_tcscmp (name, L"KickstartPath")) - _tcscat (out, L"..\\shared\\rom\\"); - if (!_tcscmp (name, L"ConfigurationPath")) - _tcscat (out, L"Configurations\\"); - if (start_data >= 0) - regquerystr (NULL, name, out, &size); - if (out[0] == '\\' && (_tcslen (out) >= 2 && out[1] != '\\')) { /* relative? */ + int size2 = size; + _tcscpy (out, start_path_data); - if (start_data >= 0) { - size2 -= _tcslen (out); - regquerystr (NULL, name, out, &size2); - } - } - strip_slashes (out); - if (!_tcscmp (name, L"KickstartPath")) { - DWORD v = GetFileAttributes (out); - if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) - _tcscpy (out, start_path_data); - } - fixtrailing (out); + if (!name) + return; + if (!_tcscmp (name, L"FloppyPath")) + _tcscat (out, L"..\\shared\\adf\\"); + if (!_tcscmp (name, L"hdfPath")) + _tcscat (out, L"..\\shared\\hdf\\"); + if (!_tcscmp (name, L"KickstartPath")) + _tcscat (out, L"..\\shared\\rom\\"); + if (!_tcscmp (name, L"ConfigurationPath")) + _tcscat (out, L"Configurations\\"); + if (start_data >= 0) + regquerystr (NULL, name, out, &size); + if (out[0] == '\\' && (_tcslen (out) >= 2 && out[1] != '\\')) { /* relative? */ + _tcscpy (out, start_path_data); + if (start_data >= 0) { + size2 -= _tcslen (out); + regquerystr (NULL, name, out, &size2); + } + } + strip_slashes (out); + if (!_tcscmp (name, L"KickstartPath")) { + DWORD v = GetFileAttributes (out); + if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) + _tcscpy (out, start_path_data); + } + fixtrailing (out); } int get_rom_path(TCHAR *out, int mode) { - TCHAR tmp[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; - tmp[0] = 0; - switch (mode) - { - case 0: + tmp[0] = 0; + switch (mode) { - if (!_tcscmp (start_path_data, start_path_exe)) - _tcscpy (tmp, L".\\"); - else - _tcscpy (tmp, start_path_data); - if (GetFileAttributes (tmp) != INVALID_FILE_ATTRIBUTES) { - TCHAR tmp2[MAX_DPATH]; - _tcscpy (tmp2, tmp); - _tcscat (tmp2, L"rom"); - if (GetFileAttributes (tmp2) != INVALID_FILE_ATTRIBUTES) { - _tcscpy (tmp, tmp2); - } else { - _tcscpy (tmp2, tmp); - _tcscpy (tmp2, L"roms"); - if (GetFileAttributes (tmp2) != INVALID_FILE_ATTRIBUTES) - _tcscpy (tmp, tmp2); + case 0: + { + if (!_tcscmp (start_path_data, start_path_exe)) + _tcscpy (tmp, L".\\"); + else + _tcscpy (tmp, start_path_data); + if (GetFileAttributes (tmp) != INVALID_FILE_ATTRIBUTES) { + TCHAR tmp2[MAX_DPATH]; + _tcscpy (tmp2, tmp); + _tcscat (tmp2, L"rom"); + if (GetFileAttributes (tmp2) != INVALID_FILE_ATTRIBUTES) { + _tcscpy (tmp, tmp2); + } else { + _tcscpy (tmp2, tmp); + _tcscpy (tmp2, L"roms"); + if (GetFileAttributes (tmp2) != INVALID_FILE_ATTRIBUTES) + _tcscpy (tmp, tmp2); + } + } } - } - } - break; + break; case 1: - { - TCHAR tmp2[MAX_DPATH]; - _tcscpy (tmp2, start_path_new1); - _tcscat (tmp2, L"..\\system\\rom"); - if (isfilesindir (tmp2)) - _tcscpy (tmp, tmp2); - } - break; + { + TCHAR tmp2[MAX_DPATH]; + _tcscpy (tmp2, start_path_new1); + _tcscat (tmp2, L"..\\system\\rom"); + if (isfilesindir (tmp2)) + _tcscpy (tmp, tmp2); + } + break; case 2: - { - TCHAR tmp2[MAX_DPATH]; - _tcscpy (tmp2, start_path_new2); - _tcscat (tmp2, L"system\\rom"); - if (isfilesindir (tmp2)) - _tcscpy (tmp, tmp2); - } - break; + { + TCHAR tmp2[MAX_DPATH]; + _tcscpy (tmp2, start_path_new2); + _tcscat (tmp2, L"system\\rom"); + if (isfilesindir (tmp2)) + _tcscpy (tmp, tmp2); + } + break; case 3: - { - TCHAR tmp2[MAX_DPATH]; - _tcscpy (tmp2, start_path_af); - _tcscat (tmp2, L"..\\shared\\rom"); - if (isfilesindir (tmp2)) - _tcscpy (tmp, tmp2); - } - break; + { + TCHAR tmp2[MAX_DPATH]; + _tcscpy (tmp2, start_path_af); + _tcscat (tmp2, L"..\\shared\\rom"); + if (isfilesindir (tmp2)) + _tcscpy (tmp, tmp2); + } + break; default: - return -1; - } - if (isfilesindir (tmp)) { - _tcscpy (out, tmp); - fixtrailing (out); - } - return out[0] ? 1 : 0; + return -1; + } + if (isfilesindir (tmp)) { + _tcscpy (out, tmp); + fixtrailing (out); + } + return out[0] ? 1 : 0; } void set_path (TCHAR *name, TCHAR *path) { - TCHAR tmp[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; - if (!path) { - if (!_tcscmp (start_path_data, start_path_exe)) - _tcscpy (tmp, L".\\"); - else - _tcscpy (tmp, start_path_data); - if (!_tcscmp (name, L"KickstartPath")) - _tcscat (tmp, L"Roms"); - if (!_tcscmp (name, L"ConfigurationPath")) - _tcscat (tmp, L"Configurations"); - if (!_tcscmp (name, L"ScreenshotPath")) - _tcscat (tmp, L"Screenshots"); - if (!_tcscmp (name, L"StatefilePath")) - _tcscat (tmp, L"Savestates"); - if (!_tcscmp (name, L"SaveimagePath")) - _tcscat (tmp, L"SaveImages"); - if (!_tcscmp (name, L"InputPath")) - _tcscat (tmp, L"Inputrecordings"); - } else { - _tcscpy (tmp, path); - } - strip_slashes (tmp); - if (!_tcscmp (name, L"KickstartPath")) { - DWORD v = GetFileAttributes (tmp); - if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) - get_rom_path (tmp, 0); - if ((af_path_2005 & 1) && path_type == PATH_TYPE_NEWAF) { - get_rom_path (tmp, 1); - } else if ((af_path_2005 & 2) && path_type == PATH_TYPE_AMIGAFOREVERDATA) { - get_rom_path (tmp, 2); - } else if (af_path_old && path_type == PATH_TYPE_OLDAF) { - get_rom_path (tmp, 3); - } - } - fixtrailing (tmp); - regsetstr (NULL, name, tmp); + if (!path) { + if (!_tcscmp (start_path_data, start_path_exe)) + _tcscpy (tmp, L".\\"); + else + _tcscpy (tmp, start_path_data); + if (!_tcscmp (name, L"KickstartPath")) + _tcscat (tmp, L"Roms"); + if (!_tcscmp (name, L"ConfigurationPath")) + _tcscat (tmp, L"Configurations"); + if (!_tcscmp (name, L"ScreenshotPath")) + _tcscat (tmp, L"Screenshots"); + if (!_tcscmp (name, L"StatefilePath")) + _tcscat (tmp, L"Savestates"); + if (!_tcscmp (name, L"SaveimagePath")) + _tcscat (tmp, L"SaveImages"); + if (!_tcscmp (name, L"InputPath")) + _tcscat (tmp, L"Inputrecordings"); + } else { + _tcscpy (tmp, path); + } + strip_slashes (tmp); + if (!_tcscmp (name, L"KickstartPath")) { + DWORD v = GetFileAttributes (tmp); + if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY)) + get_rom_path (tmp, 0); + if ((af_path_2005 & 1) && path_type == PATH_TYPE_NEWAF) { + get_rom_path (tmp, 1); + } else if ((af_path_2005 & 2) && path_type == PATH_TYPE_AMIGAFOREVERDATA) { + get_rom_path (tmp, 2); + } else if (af_path_old && path_type == PATH_TYPE_OLDAF) { + get_rom_path (tmp, 3); + } + } + fixtrailing (tmp); + regsetstr (NULL, name, tmp); } static void initpath (TCHAR *name, TCHAR *path) { - if (regexists (NULL, name)) - return; - set_path (name, NULL); + if (regexists (NULL, name)) + return; + set_path (name, NULL); } static void romlist_add2 (TCHAR *path, struct romdata *rd) { - if (getregmode ()) { - int ok = 0; - TCHAR tmp[MAX_DPATH]; - if (path[0] == '/' || path[0] == '\\') - ok = 1; - if (_tcslen (path) > 1 && path[1] == ':') - ok = 1; - if (!ok) { - _tcscpy (tmp, start_path_exe); - _tcscat (tmp, path); - romlist_add (tmp, rd); - return; - } - } - romlist_add (path, rd); + if (getregmode ()) { + int ok = 0; + TCHAR tmp[MAX_DPATH]; + if (path[0] == '/' || path[0] == '\\') + ok = 1; + if (_tcslen (path) > 1 && path[1] == ':') + ok = 1; + if (!ok) { + _tcscpy (tmp, start_path_exe); + _tcscat (tmp, path); + romlist_add (tmp, rd); + return; + } + } + romlist_add (path, rd); } extern int scan_roms (int); void read_rom_list (void) { - TCHAR tmp2[1000]; - int idx, idx2; - UAEREG *fkey; - TCHAR tmp[1000]; - int size, size2, exists; - - romlist_clear (); - exists = regexiststree (NULL, L"DetectedROMs"); - fkey = regcreatetree (NULL, L"DetectedROMs"); - if (fkey == NULL) - return; - if (!exists || forceroms) { - load_keyring (NULL, NULL); - scan_roms (forceroms ? 0 : 1); - } - forceroms = 0; - idx = 0; - for (;;) { - size = sizeof (tmp) / sizeof (TCHAR); - size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - if (_tcslen (tmp) == 7 || _tcslen (tmp) == 13) { - int group = 0; - int subitem = 0; - idx2 = _tstol (tmp + 4); - if (_tcslen (tmp) == 13) { - group = _tstol (tmp + 8); - subitem = _tstol (tmp + 11); - } - if (idx2 >= 0 && _tcslen (tmp2) > 0) { - struct romdata *rd = getromdatabyidgroup (idx2, group, subitem); - if (rd) { - TCHAR *s = _tcschr (tmp2, '\"'); - if (s && _tcslen (s) > 1) { - TCHAR *s2 = my_strdup (s + 1); - s = _tcschr (s2, '\"'); - if (s) - *s = 0; - romlist_add2 (s2, rd); - xfree (s2); - } else { - romlist_add2 (tmp2, rd); - } + TCHAR tmp2[1000]; + int idx, idx2; + UAEREG *fkey; + TCHAR tmp[1000]; + int size, size2, exists; + + romlist_clear (); + exists = regexiststree (NULL, L"DetectedROMs"); + fkey = regcreatetree (NULL, L"DetectedROMs"); + if (fkey == NULL) + return; + if (!exists || forceroms) { + load_keyring (NULL, NULL); + scan_roms (forceroms ? 0 : 1); + } + forceroms = 0; + idx = 0; + for (;;) { + size = sizeof (tmp) / sizeof (TCHAR); + size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + if (_tcslen (tmp) == 7 || _tcslen (tmp) == 13) { + int group = 0; + int subitem = 0; + idx2 = _tstol (tmp + 4); + if (_tcslen (tmp) == 13) { + group = _tstol (tmp + 8); + subitem = _tstol (tmp + 11); + } + if (idx2 >= 0 && _tcslen (tmp2) > 0) { + struct romdata *rd = getromdatabyidgroup (idx2, group, subitem); + if (rd) { + TCHAR *s = _tcschr (tmp2, '\"'); + if (s && _tcslen (s) > 1) { + TCHAR *s2 = my_strdup (s + 1); + s = _tcschr (s2, '\"'); + if (s) + *s = 0; + romlist_add2 (s2, rd); + xfree (s2); + } else { + romlist_add2 (tmp2, rd); + } + } + } } - } + idx++; } - idx++; - } - romlist_add (NULL, NULL); - regclosetree (fkey); + romlist_add (NULL, NULL); + regclosetree (fkey); } static int parseversion (TCHAR **vs) { - TCHAR tmp[10]; - int i; - - i = 0; - while (**vs >= '0' && **vs <= '9') { - if (i >= sizeof (tmp) / sizeof (TCHAR)) - return 0; - tmp[i++] = **vs; - (*vs)++; - } - if (**vs == '.') - (*vs)++; - tmp[i] = 0; - return _tstol (tmp); + TCHAR tmp[10]; + int i; + + i = 0; + while (**vs >= '0' && **vs <= '9') { + if (i >= sizeof (tmp) / sizeof (TCHAR)) + return 0; + tmp[i++] = **vs; + (*vs)++; + } + if (**vs == '.') + (*vs)++; + tmp[i] = 0; + return _tstol (tmp); } static int checkversion (TCHAR *vs) { - if (_tcslen (vs) < 10) - return 0; - if (_tcsncmp (vs, L"WinUAE L", 7)) - return 0; - vs += 7; - if (parseversion (&vs) > UAEMAJOR) - return 0; - if (parseversion (&vs) > UAEMINOR) - return 0; - if (parseversion (&vs) >= UAESUBREV) - return 0; - return 1; + if (_tcslen (vs) < 10) + return 0; + if (_tcsncmp (vs, L"WinUAE L", 7)) + return 0; + vs += 7; + if (parseversion (&vs) > UAEMAJOR) + return 0; + if (parseversion (&vs) > UAEMINOR) + return 0; + if (parseversion (&vs) >= UAESUBREV) + return 0; + return 1; } static int shell_deassociate (const TCHAR *extension) { - HKEY rkey; - const TCHAR *progid = L"WinUAE"; - int def = !_tcscmp (extension, L".uae"); - TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH], progid2[MAX_DPATH]; - UAEREG *fkey; + HKEY rkey; + const TCHAR *progid = L"WinUAE"; + int def = !_tcscmp (extension, L".uae"); + TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH], progid2[MAX_DPATH]; + UAEREG *fkey; - if (extension == NULL || _tcslen (extension) < 1 || extension[0] != '.') - return 0; - _tcscpy (progid2, progid); - _tcscat (progid2, extension); - if (os_winnt_admin > 1) - rkey = HKEY_LOCAL_MACHINE; - else - rkey = HKEY_CURRENT_USER; - - _tcscpy (rpath1, L"Software\\Classes\\"); - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, extension); - if (RegDeleteKey (rkey, rpath2) != ERROR_SUCCESS) - return 0; - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, progid); - if (!def) + if (extension == NULL || _tcslen (extension) < 1 || extension[0] != '.') + return 0; + _tcscpy (progid2, progid); + _tcscat (progid2, extension); + if (os_winnt_admin > 1) + rkey = HKEY_LOCAL_MACHINE; + else + rkey = HKEY_CURRENT_USER; + + _tcscpy (rpath1, L"Software\\Classes\\"); + _tcscpy (rpath2, rpath1); _tcscat (rpath2, extension); - SHDeleteKey (rkey, rpath2); - fkey = regcreatetree (NULL, L"FileAssociations"); - regdelete (fkey, extension); - regclosetree (fkey); - return 1; + if (RegDeleteKey (rkey, rpath2) != ERROR_SUCCESS) + return 0; + _tcscpy (rpath2, rpath1); + _tcscat (rpath2, progid); + if (!def) + _tcscat (rpath2, extension); + SHDeleteKey (rkey, rpath2); + fkey = regcreatetree (NULL, L"FileAssociations"); + regdelete (fkey, extension); + regclosetree (fkey); + return 1; } static int shell_associate_2 (const TCHAR *extension, const TCHAR *shellcommand, const TCHAR *command, const TCHAR *perceivedtype, - const TCHAR *description, const TCHAR *ext2, int icon) + const TCHAR *description, const TCHAR *ext2, int icon) { - TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH], progid2[MAX_DPATH]; - HKEY rkey, key1, key2; - DWORD disposition; - const TCHAR *progid = L"WinUAE"; - int def = !_tcscmp (extension, L".uae"); - const TCHAR *defprogid; - UAEREG *fkey; - - _tcscpy (progid2, progid); - _tcscat (progid2, ext2 ? ext2 : extension); - if (os_winnt_admin > 1) - rkey = HKEY_LOCAL_MACHINE; - else - rkey = HKEY_CURRENT_USER; - defprogid = def ? progid : progid2; - - _tcscpy (rpath1, L"Software\\Classes\\"); - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, extension); - if (RegCreateKeyEx (rkey, rpath2, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { - RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)defprogid, (_tcslen (defprogid) + 1) * sizeof (TCHAR)); - if (perceivedtype) - RegSetValueEx (key1, L"PerceivedType", 0, REG_SZ, (CONST BYTE *)perceivedtype, (_tcslen (perceivedtype) + 1) * sizeof (TCHAR)); - RegCloseKey (key1); - } - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, progid); - if (!def) - _tcscat (rpath2, ext2 ? ext2 : extension); - if (description) { - if (RegCreateKeyEx (rkey, rpath2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { - TCHAR tmp[MAX_DPATH]; - RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)description, (_tcslen (description) + 1) * sizeof (TCHAR)); - RegSetValueEx (key1, L"AppUserModelID", 0, REG_SZ, (CONST BYTE *)WINUAEAPPNAME, (_tcslen (WINUAEAPPNAME) + 1) * sizeof (TCHAR)); - _tcscpy (tmp, rpath2); - _tcscat (tmp, L"\\CurVer"); - if (RegCreateKeyEx (rkey, tmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key2, &disposition) == ERROR_SUCCESS) { - RegSetValueEx (key2, L"", 0, REG_SZ, (CONST BYTE *)defprogid, (_tcslen (defprogid) + 1) * sizeof (TCHAR)); - RegCloseKey (key2); - } - if (icon) { - _tcscpy (tmp, rpath2); - _tcscat (tmp, L"\\DefaultIcon"); - if (RegCreateKeyEx (rkey, tmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key2, &disposition) == ERROR_SUCCESS) { - _stprintf (tmp, L"%s,%d", _wpgmptr, -icon); - RegSetValueEx (key2, L"", 0, REG_SZ, (CONST BYTE *)tmp, (_tcslen (tmp) + 1) * sizeof (TCHAR)); - RegCloseKey (key2); - } - } - RegCloseKey (key1); - } - } - if (command) { - _tcscat (rpath2, L"\\shell\\"); - if (shellcommand) - _tcscat (rpath2, shellcommand); + TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH], progid2[MAX_DPATH]; + HKEY rkey, key1, key2; + DWORD disposition; + const TCHAR *progid = L"WinUAE"; + int def = !_tcscmp (extension, L".uae"); + const TCHAR *defprogid; + UAEREG *fkey; + + _tcscpy (progid2, progid); + _tcscat (progid2, ext2 ? ext2 : extension); + if (os_winnt_admin > 1) + rkey = HKEY_LOCAL_MACHINE; else - _tcscat (rpath2, L"open"); - _tcscat (rpath2, L"\\command"); + rkey = HKEY_CURRENT_USER; + defprogid = def ? progid : progid2; + + _tcscpy (rpath1, L"Software\\Classes\\"); + _tcscpy (rpath2, rpath1); + _tcscat (rpath2, extension); if (RegCreateKeyEx (rkey, rpath2, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { - TCHAR path[MAX_DPATH]; - _stprintf (path, L"\"%sWinUAE.exe\" %s", start_path_exe, command); - RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)path, (_tcslen (path) + 1) * sizeof (TCHAR)); - RegCloseKey (key1); - } - } - fkey = regcreatetree (NULL, L"FileAssociations"); - regsetstr (fkey, extension, L""); - regclosetree (fkey); - return 1; + KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { + RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)defprogid, (_tcslen (defprogid) + 1) * sizeof (TCHAR)); + if (perceivedtype) + RegSetValueEx (key1, L"PerceivedType", 0, REG_SZ, (CONST BYTE *)perceivedtype, (_tcslen (perceivedtype) + 1) * sizeof (TCHAR)); + RegCloseKey (key1); + } + _tcscpy (rpath2, rpath1); + _tcscat (rpath2, progid); + if (!def) + _tcscat (rpath2, ext2 ? ext2 : extension); + if (description) { + if (RegCreateKeyEx (rkey, rpath2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { + TCHAR tmp[MAX_DPATH]; + RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)description, (_tcslen (description) + 1) * sizeof (TCHAR)); + RegSetValueEx (key1, L"AppUserModelID", 0, REG_SZ, (CONST BYTE *)WINUAEAPPNAME, (_tcslen (WINUAEAPPNAME) + 1) * sizeof (TCHAR)); + _tcscpy (tmp, rpath2); + _tcscat (tmp, L"\\CurVer"); + if (RegCreateKeyEx (rkey, tmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key2, &disposition) == ERROR_SUCCESS) { + RegSetValueEx (key2, L"", 0, REG_SZ, (CONST BYTE *)defprogid, (_tcslen (defprogid) + 1) * sizeof (TCHAR)); + RegCloseKey (key2); + } + if (icon) { + _tcscpy (tmp, rpath2); + _tcscat (tmp, L"\\DefaultIcon"); + if (RegCreateKeyEx (rkey, tmp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key2, &disposition) == ERROR_SUCCESS) { + _stprintf (tmp, L"%s,%d", _wpgmptr, -icon); + RegSetValueEx (key2, L"", 0, REG_SZ, (CONST BYTE *)tmp, (_tcslen (tmp) + 1) * sizeof (TCHAR)); + RegCloseKey (key2); + } + } + RegCloseKey (key1); + } + } + if (command) { + _tcscat (rpath2, L"\\shell\\"); + if (shellcommand) + _tcscat (rpath2, shellcommand); + else + _tcscat (rpath2, L"open"); + _tcscat (rpath2, L"\\command"); + if (RegCreateKeyEx (rkey, rpath2, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_WRITE | KEY_READ, NULL, &key1, &disposition) == ERROR_SUCCESS) { + TCHAR path[MAX_DPATH]; + _stprintf (path, L"\"%sWinUAE.exe\" %s", start_path_exe, command); + RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)path, (_tcslen (path) + 1) * sizeof (TCHAR)); + RegCloseKey (key1); + } + } + fkey = regcreatetree (NULL, L"FileAssociations"); + regsetstr (fkey, extension, L""); + regclosetree (fkey); + return 1; } static int shell_associate (const TCHAR *extension, const TCHAR *command, const TCHAR *perceivedtype, const TCHAR *description, const TCHAR *ext2, int icon) { - int v = shell_associate_2 (extension, NULL, command, perceivedtype, description, ext2, icon); - if (!_tcscmp (extension, L".uae")) - shell_associate_2 (extension, L"edit", L"-f \"%1\" -s use_gui=yes", L"text", description, NULL, 0); - return v; + int v = shell_associate_2 (extension, NULL, command, perceivedtype, description, ext2, icon); + if (!_tcscmp (extension, L".uae")) + shell_associate_2 (extension, L"edit", L"-f \"%1\" -s use_gui=yes", L"text", description, NULL, 0); + return v; } static int shell_associate_is (const TCHAR *extension) { - TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH]; - TCHAR progid2[MAX_DPATH], tmp[MAX_DPATH]; - DWORD size; - HKEY rkey, key1; - const TCHAR *progid = L"WinUAE"; - int def = !_tcscmp (extension, L".uae"); - - _tcscpy (progid2, progid); - _tcscat (progid2, extension); - if (os_winnt_admin > 1) - rkey = HKEY_LOCAL_MACHINE; - else - rkey = HKEY_CURRENT_USER; - - _tcscpy (rpath1, L"Software\\Classes\\"); - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, extension); - size = sizeof tmp / sizeof (TCHAR); - if (RegOpenKeyEx (rkey, rpath2, 0, KEY_READ, &key1) == ERROR_SUCCESS) { - if (RegQueryValueEx (key1, NULL, NULL, NULL, (LPBYTE)tmp, &size) == ERROR_SUCCESS) { - if (_tcscmp (tmp, def ? progid : progid2)) { + TCHAR rpath1[MAX_DPATH], rpath2[MAX_DPATH]; + TCHAR progid2[MAX_DPATH], tmp[MAX_DPATH]; + DWORD size; + HKEY rkey, key1; + const TCHAR *progid = L"WinUAE"; + int def = !_tcscmp (extension, L".uae"); + + _tcscpy (progid2, progid); + _tcscat (progid2, extension); + if (os_winnt_admin > 1) + rkey = HKEY_LOCAL_MACHINE; + else + rkey = HKEY_CURRENT_USER; + + _tcscpy (rpath1, L"Software\\Classes\\"); + _tcscpy (rpath2, rpath1); + _tcscat (rpath2, extension); + size = sizeof tmp / sizeof (TCHAR); + if (RegOpenKeyEx (rkey, rpath2, 0, KEY_READ, &key1) == ERROR_SUCCESS) { + if (RegQueryValueEx (key1, NULL, NULL, NULL, (LPBYTE)tmp, &size) == ERROR_SUCCESS) { + if (_tcscmp (tmp, def ? progid : progid2)) { + RegCloseKey (key1); + return 0; + } + } RegCloseKey (key1); - return 0; - } } - RegCloseKey (key1); - } - _tcscpy (rpath2, rpath1); - _tcscat (rpath2, progid); - if (!def) - _tcscat (rpath2, extension); - if (RegOpenKeyEx (rkey, rpath2, 0, KEY_READ, &key1) == ERROR_SUCCESS) { - RegCloseKey (key1); - return 1; - } - return 0; + _tcscpy (rpath2, rpath1); + _tcscat (rpath2, progid); + if (!def) + _tcscat (rpath2, extension); + if (RegOpenKeyEx (rkey, rpath2, 0, KEY_READ, &key1) == ERROR_SUCCESS) { + RegCloseKey (key1); + return 1; + } + return 0; } struct assext exts[] = { - { L".uae", L"-f \"%1\"", L"WinUAE configuration file", IDI_CONFIGFILE }, - { L".adf", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, - { L".adz", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, - { L".dms", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, - { L".fdi", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, - { L".ipf", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, - { L".uss", L"-s statefile=\"%1\" -s use_gui=no", L"WinUAE statefile", IDI_APPICON }, - { NULL } + { L".uae", L"-f \"%1\"", L"WinUAE configuration file", IDI_CONFIGFILE }, + { L".adf", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, + { L".adz", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, + { L".dms", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, + { L".fdi", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, + { L".ipf", L"-0 \"%1\" -s use_gui=no", L"WinUAE floppy disk image", IDI_DISKIMAGE }, + { L".uss", L"-s statefile=\"%1\" -s use_gui=no", L"WinUAE statefile", IDI_APPICON }, + { NULL } }; static void associate_init_extensions (void) { - int i; - - for (i = 0; exts[i].ext; i++) { - exts[i].enabled = 0; - if (shell_associate_is (exts[i].ext)) - exts[i].enabled = 1; - } - if (rp_param) - return; - // associate .uae by default when running for the first time - if (!regexiststree (NULL, L"FileAssociations")) { - UAEREG *fkey; - if (exts[0].enabled == 0) { - shell_associate (exts[0].ext, exts[0].cmd, NULL, exts[0].desc, NULL, exts[0].icon); - exts[0].enabled = shell_associate_is (exts[0].ext); + int i; + + for (i = 0; exts[i].ext; i++) { + exts[i].enabled = 0; + if (shell_associate_is (exts[i].ext)) + exts[i].enabled = 1; } - fkey = regcreatetree (NULL, L"FileAssociations"); - regsetstr (fkey, exts[0].ext, L""); - regclosetree (fkey); - } - if (os_winnt_admin > 1) { - DWORD disposition; - TCHAR rpath[MAX_DPATH]; - HKEY rkey = HKEY_LOCAL_MACHINE; - HKEY key1; - int setit = 1; - - _tcscpy (rpath, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\winuae.exe"); - if (RegOpenKeyEx (rkey, rpath, 0, KEY_READ, &key1) == ERROR_SUCCESS) { - TCHAR tmp[MAX_DPATH]; - DWORD size = sizeof tmp / sizeof (TCHAR); - if (RegQueryValueEx (key1, NULL, NULL, NULL, (LPBYTE)tmp, &size) == ERROR_SUCCESS) { - if (!_tcscmp (tmp, _wpgmptr)) - setit = 0; - } - RegCloseKey (key1); - } - if (setit) { - if (RegCreateKeyEx (rkey, rpath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &key1, &disposition) == ERROR_SUCCESS) { - RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)_wpgmptr, (_tcslen (_wpgmptr) + 1) * sizeof (TCHAR)); - RegCloseKey (key1); - SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0); - } + if (rp_param) + return; + // associate .uae by default when running for the first time + if (!regexiststree (NULL, L"FileAssociations")) { + UAEREG *fkey; + if (exts[0].enabled == 0) { + shell_associate (exts[0].ext, exts[0].cmd, NULL, exts[0].desc, NULL, exts[0].icon); + exts[0].enabled = shell_associate_is (exts[0].ext); + } + fkey = regcreatetree (NULL, L"FileAssociations"); + regsetstr (fkey, exts[0].ext, L""); + regclosetree (fkey); + } + if (os_winnt_admin > 1) { + DWORD disposition; + TCHAR rpath[MAX_DPATH]; + HKEY rkey = HKEY_LOCAL_MACHINE; + HKEY key1; + int setit = 1; + + _tcscpy (rpath, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\winuae.exe"); + if (RegOpenKeyEx (rkey, rpath, 0, KEY_READ, &key1) == ERROR_SUCCESS) { + TCHAR tmp[MAX_DPATH]; + DWORD size = sizeof tmp / sizeof (TCHAR); + if (RegQueryValueEx (key1, NULL, NULL, NULL, (LPBYTE)tmp, &size) == ERROR_SUCCESS) { + if (!_tcscmp (tmp, _wpgmptr)) + setit = 0; + } + RegCloseKey (key1); + } + if (setit) { + if (RegCreateKeyEx (rkey, rpath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &key1, &disposition) == ERROR_SUCCESS) { + RegSetValueEx (key1, L"", 0, REG_SZ, (CONST BYTE *)_wpgmptr, (_tcslen (_wpgmptr) + 1) * sizeof (TCHAR)); + RegCloseKey (key1); + SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0); + } + } } - } #if 0 - UAEREG *fkey; - fkey = regcreatetree (NULL, L"FileAssociations"); - if (fkey) { - int ok = 1; - TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, L"Following file associations:\n"); - for (i = 0; exts[i].ext; i++) { - TCHAR tmp2[10]; - int size = sizeof tmp; - int is1 = exts[i].enabled; - int is2 = regquerystr (fkey, exts[i].ext, tmp2, &size); - if (is1 == 0 && is2 != 0) { - _tcscat (tmp, exts[i].ext); - _tcscat (tmp, L"\n"); - ok = 0; - } - } - if (!ok) { - TCHAR szTitle[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); - _tcscat (szTitle, BetaStr); - if (MessageBox (NULL, tmp, szTitle, MB_YESNO | MB_TASKMODAL) == IDOK) { + UAEREG *fkey; + fkey = regcreatetree (NULL, L"FileAssociations"); + if (fkey) { + int ok = 1; + TCHAR tmp[MAX_DPATH]; + _tcscpy (tmp, L"Following file associations:\n"); for (i = 0; exts[i].ext; i++) { - TCHAR tmp2[10]; - int size = sizeof tmp; - int is1 = exts[i].enabled; - int is2 = regquerystr (fkey, exts[i].ext, tmp2, &size); - if (is1 == 0 && is2 != 0) { - regdelete (fkey, exts[i].ext); - shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL); - exts[i].enabled = shell_associate_is (exts[i].ext); - } + TCHAR tmp2[10]; + int size = sizeof tmp; + int is1 = exts[i].enabled; + int is2 = regquerystr (fkey, exts[i].ext, tmp2, &size); + if (is1 == 0 && is2 != 0) { + _tcscat (tmp, exts[i].ext); + _tcscat (tmp, L"\n"); + ok = 0; + } } - } else { - for (i = 0; exts[i].ext; i++) { - if (!exts[i].enabled) - regdelete (fkey, exts[i].ext); + if (!ok) { + TCHAR szTitle[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); + _tcscat (szTitle, BetaStr); + if (MessageBox (NULL, tmp, szTitle, MB_YESNO | MB_TASKMODAL) == IDOK) { + for (i = 0; exts[i].ext; i++) { + TCHAR tmp2[10]; + int size = sizeof tmp; + int is1 = exts[i].enabled; + int is2 = regquerystr (fkey, exts[i].ext, tmp2, &size); + if (is1 == 0 && is2 != 0) { + regdelete (fkey, exts[i].ext); + shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL); + exts[i].enabled = shell_associate_is (exts[i].ext); + } + } + } else { + for (i = 0; exts[i].ext; i++) { + if (!exts[i].enabled) + regdelete (fkey, exts[i].ext); + } + } } - } } - } #endif } void associate_file_extensions (void) { - int i; - int modified = 0; - - if (rp_param) - return; - for (i = 0; exts[i].ext; i++) { - int already = shell_associate_is (exts[i].ext); - if (exts[i].enabled == 0 && already) { - shell_deassociate (exts[i].ext); - exts[i].enabled = shell_associate_is (exts[i].ext); - if (exts[i].enabled) { - modified = 1; - shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL, exts[i].icon); - } - } else if (exts[i].enabled) { - shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL, exts[i].icon); - exts[i].enabled = shell_associate_is (exts[i].ext); - if (exts[i].enabled != already) - modified = 1; - } - } - if (modified) - SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0); + int i; + int modified = 0; + + if (rp_param) + return; + for (i = 0; exts[i].ext; i++) { + int already = shell_associate_is (exts[i].ext); + if (exts[i].enabled == 0 && already) { + shell_deassociate (exts[i].ext); + exts[i].enabled = shell_associate_is (exts[i].ext); + if (exts[i].enabled) { + modified = 1; + shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL, exts[i].icon); + } + } else if (exts[i].enabled) { + shell_associate (exts[i].ext, exts[i].cmd, NULL, exts[i].desc, NULL, exts[i].icon); + exts[i].enabled = shell_associate_is (exts[i].ext); + if (exts[i].enabled != already) + modified = 1; + } + } + if (modified) + SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0); } static void WIN32_HandleRegistryStuff (void) { - RGBFTYPE colortype = RGBFB_NONE; - DWORD dwType = REG_DWORD; - DWORD dwDisplayInfoSize = sizeof (colortype); - DWORD size; - TCHAR path[MAX_DPATH] = L""; - TCHAR version[100]; - - initpath (L"FloppyPath", start_path_data); - initpath (L"KickstartPath", start_path_data); - initpath (L"hdfPath", start_path_data); - initpath (L"ConfigurationPath", start_path_data); - initpath (L"ScreenshotPath", start_path_data); - initpath (L"StatefilePath", start_path_data); - initpath (L"SaveimagePath", start_path_data); - initpath (L"VideoPath", start_path_data); - initpath (L"InputPath", start_path_data); - if (!regexists (NULL, L"MainPosX") || !regexists (NULL, L"GUIPosX")) { - int x = GetSystemMetrics (SM_CXSCREEN); - int y = GetSystemMetrics (SM_CYSCREEN); - x = (x - 800) / 2; - y = (y - 600) / 2; - if (x < 10) - x = 10; - if (y < 10) - y = 10; - /* Create and initialize all our sub-keys to the default values */ - regsetint (NULL, L"MainPosX", x); - regsetint (NULL, L"MainPosY", y); - regsetint (NULL, L"GUIPosX", x); - regsetint (NULL, L"GUIPosY", y); - } - size = sizeof (version) / sizeof (TCHAR); - if (regquerystr (NULL, L"Version", version, &size)) { - if (checkversion (version)) - regsetstr (NULL, L"Version", VersionStr); - } else { - regsetstr (NULL, L"Version", VersionStr); - } - size = sizeof (version) / sizeof (TCHAR); - if (regquerystr (NULL, L"ROMCheckVersion", version, &size)) { - if (checkversion (version)) { - if (regsetstr (NULL, L"ROMCheckVersion", VersionStr)) - forceroms = 1; - } - } else { - if (regsetstr (NULL, L"ROMCheckVersion", VersionStr)) - forceroms = 1; - } - - regqueryint (NULL, L"DirectDraw_Secondary", &ddforceram); - if (regexists (NULL, L"SoundDriverMask")) { - regqueryint (NULL, L"SoundDriverMask", &sounddrivermask); - } else { - sounddrivermask = 15; - regsetint (NULL, L"SoundDriverMask", sounddrivermask); - } - if (regexists (NULL, L"ConfigurationCache")) - regqueryint (NULL, L"ConfigurationCache", &configurationcache); - else - regsetint (NULL, L"ConfigurationCache", configurationcache); - regqueryint (NULL, L"QuickStartMode", &quickstart); - reopen_console (); - fetch_path (L"ConfigurationPath", path, sizeof (path) / sizeof (TCHAR)); - path[_tcslen (path) - 1] = 0; - createdir (path); - _tcscat (path, L"\\Host"); - createdir (path); - fetch_path (L"ConfigurationPath", path, sizeof (path) / sizeof (TCHAR)); - _tcscat (path, L"Hardware"); - createdir (path); - fetch_path (L"StatefilePath", path, sizeof (path) / sizeof (TCHAR)); - createdir (path); - _tcscat (path, L"default.uss"); - _tcscpy (savestate_fname, path); - fetch_path (L"InputPath", path, sizeof (path) / sizeof (TCHAR)); - createdir (path); - regclosetree (read_disk_history ()); - associate_init_extensions (); - read_rom_list (); - load_keyring (NULL, NULL); + RGBFTYPE colortype = RGBFB_NONE; + DWORD dwType = REG_DWORD; + DWORD dwDisplayInfoSize = sizeof (colortype); + DWORD size; + TCHAR path[MAX_DPATH] = L""; + TCHAR version[100]; + + initpath (L"FloppyPath", start_path_data); + initpath (L"KickstartPath", start_path_data); + initpath (L"hdfPath", start_path_data); + initpath (L"ConfigurationPath", start_path_data); + initpath (L"ScreenshotPath", start_path_data); + initpath (L"StatefilePath", start_path_data); + initpath (L"SaveimagePath", start_path_data); + initpath (L"VideoPath", start_path_data); + initpath (L"InputPath", start_path_data); + if (!regexists (NULL, L"MainPosX") || !regexists (NULL, L"GUIPosX")) { + int x = GetSystemMetrics (SM_CXSCREEN); + int y = GetSystemMetrics (SM_CYSCREEN); + x = (x - 800) / 2; + y = (y - 600) / 2; + if (x < 10) + x = 10; + if (y < 10) + y = 10; + /* Create and initialize all our sub-keys to the default values */ + regsetint (NULL, L"MainPosX", x); + regsetint (NULL, L"MainPosY", y); + regsetint (NULL, L"GUIPosX", x); + regsetint (NULL, L"GUIPosY", y); + } + size = sizeof (version) / sizeof (TCHAR); + if (regquerystr (NULL, L"Version", version, &size)) { + if (checkversion (version)) + regsetstr (NULL, L"Version", VersionStr); + } else { + regsetstr (NULL, L"Version", VersionStr); + } + size = sizeof (version) / sizeof (TCHAR); + if (regquerystr (NULL, L"ROMCheckVersion", version, &size)) { + if (checkversion (version)) { + if (regsetstr (NULL, L"ROMCheckVersion", VersionStr)) + forceroms = 1; + } + } else { + if (regsetstr (NULL, L"ROMCheckVersion", VersionStr)) + forceroms = 1; + } + + regqueryint (NULL, L"DirectDraw_Secondary", &ddforceram); + if (regexists (NULL, L"SoundDriverMask")) { + regqueryint (NULL, L"SoundDriverMask", &sounddrivermask); + } else { + sounddrivermask = 15; + regsetint (NULL, L"SoundDriverMask", sounddrivermask); + } + if (regexists (NULL, L"ConfigurationCache")) + regqueryint (NULL, L"ConfigurationCache", &configurationcache); + else + regsetint (NULL, L"ConfigurationCache", configurationcache); + regqueryint (NULL, L"QuickStartMode", &quickstart); + reopen_console (); + fetch_path (L"ConfigurationPath", path, sizeof (path) / sizeof (TCHAR)); + path[_tcslen (path) - 1] = 0; + createdir (path); + _tcscat (path, L"\\Host"); + createdir (path); + fetch_path (L"ConfigurationPath", path, sizeof (path) / sizeof (TCHAR)); + _tcscat (path, L"Hardware"); + createdir (path); + fetch_path (L"StatefilePath", path, sizeof (path) / sizeof (TCHAR)); + createdir (path); + _tcscat (path, L"default.uss"); + _tcscpy (savestate_fname, path); + fetch_path (L"InputPath", path, sizeof (path) / sizeof (TCHAR)); + createdir (path); + regclosetree (read_disk_history ()); + associate_init_extensions (); + read_rom_list (); + load_keyring (NULL, NULL); } #if WINUAEPUBLICBETA > 0 static TCHAR *BETAMESSAGE = { - L"This is unstable beta software. Click cancel if you are not comfortable using software that is incomplete and can have serious programming errors." + L"This is unstable beta software. Click cancel if you are not comfortable using software that is incomplete and can have serious programming errors." }; #endif static int betamessage (void) { #if WINUAEPUBLICBETA > 0 - int showmsg = TRUE; - HANDLE h = INVALID_HANDLE_VALUE; - ULONGLONG regft64; - ULARGE_INTEGER ft64; - ULARGE_INTEGER sft64; - struct tm *t; - __int64 ltime; - DWORD dwType, size, data; - - ft64.QuadPart = 0; - for (;;) { - FILETIME ft, sft; - SYSTEMTIME st; - TCHAR tmp1[MAX_DPATH]; - - if (!hWinUAEKey) - break; - if (GetModuleFileName (NULL, tmp1, sizeof tmp1 / sizeof (TCHAR)) == 0) - break; - h = CreateFile (tmp1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) - break; - if (GetFileTime (h, &ft, NULL, NULL) == 0) - break; - ft64.LowPart = ft.dwLowDateTime; - ft64.HighPart = ft.dwHighDateTime; - dwType = REG_QWORD; - size = sizeof regft64; - if (RegQueryValueEx (hWinUAEKey, L"BetaToken", 0, &dwType, (LPBYTE)®ft64, &size) != ERROR_SUCCESS) - break; - GetSystemTime(&st); - SystemTimeToFileTime(&st, &sft); - sft64.LowPart = sft.dwLowDateTime; - sft64.HighPart = sft.dwHighDateTime; - if (ft64.QuadPart == regft64) - showmsg = FALSE; - /* complain again in 7 days */ - if (sft64.QuadPart > regft64 + (ULONGLONG)1000000000 * 60 * 60 * 24 * 7) - showmsg = TRUE; - break; - } - if (h != INVALID_HANDLE_VALUE) - CloseHandle (h); - if (showmsg) { - int r; - TCHAR title[MAX_DPATH]; - - dwType = REG_DWORD; - size = sizeof data; - if (hWinUAEKey && RegQueryValueEx (hWinUAEKey, L"Beta_Just_Shut_Up", 0, &dwType, (LPBYTE)&data, &size) == ERROR_SUCCESS) { - if (data == 68000) { - write_log (L"I was told to shut up :(\n"); - return 1; - } + int showmsg = TRUE; + HANDLE h = INVALID_HANDLE_VALUE; + ULONGLONG regft64; + ULARGE_INTEGER ft64; + ULARGE_INTEGER sft64; + struct tm *t; + __int64 ltime; + DWORD dwType, size, data; + + ft64.QuadPart = 0; + for (;;) { + FILETIME ft, sft; + SYSTEMTIME st; + TCHAR tmp1[MAX_DPATH]; + + if (!hWinUAEKey) + break; + if (GetModuleFileName (NULL, tmp1, sizeof tmp1 / sizeof (TCHAR)) == 0) + break; + h = CreateFile (tmp1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + break; + if (GetFileTime (h, &ft, NULL, NULL) == 0) + break; + ft64.LowPart = ft.dwLowDateTime; + ft64.HighPart = ft.dwHighDateTime; + dwType = REG_QWORD; + size = sizeof regft64; + if (RegQueryValueEx (hWinUAEKey, L"BetaToken", 0, &dwType, (LPBYTE)®ft64, &size) != ERROR_SUCCESS) + break; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &sft); + sft64.LowPart = sft.dwLowDateTime; + sft64.HighPart = sft.dwHighDateTime; + if (ft64.QuadPart == regft64) + showmsg = FALSE; + /* complain again in 7 days */ + if (sft64.QuadPart > regft64 + (ULONGLONG)1000000000 * 60 * 60 * 24 * 7) + showmsg = TRUE; + break; } + if (h != INVALID_HANDLE_VALUE) + CloseHandle (h); + if (showmsg) { + int r; + TCHAR title[MAX_DPATH]; + + dwType = REG_DWORD; + size = sizeof data; + if (hWinUAEKey && RegQueryValueEx (hWinUAEKey, L"Beta_Just_Shut_Up", 0, &dwType, (LPBYTE)&data, &size) == ERROR_SUCCESS) { + if (data == 68000) { + write_log (L"I was told to shut up :(\n"); + return 1; + } + } - _time64 (<ime); - t = _gmtime64 (<ime); - /* "expire" in 1 month */ - if (MAKEBD(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday) > WINUAEDATE + 100) - pre_gui_message (L"This beta build of WinUAE is obsolete.\nPlease download newer version."); - - _tcscpy (title, L"WinUAE Public Beta Disclaimer"); - _tcscat (title, BetaStr); - r = MessageBox (NULL, BETAMESSAGE, title, MB_OKCANCEL | MB_TASKMODAL | MB_SETFOREGROUND | MB_ICONWARNING | MB_DEFBUTTON2); - if (r == IDABORT || r == IDCANCEL) - return 0; - if (ft64.QuadPart > 0) { - regft64 = ft64.QuadPart; - RegSetValueEx (hWinUAEKey, L"BetaToken", 0, REG_QWORD, (LPBYTE)®ft64, sizeof regft64); + _time64 (<ime); + t = _gmtime64 (<ime); + /* "expire" in 1 month */ + if (MAKEBD(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday) > WINUAEDATE + 100) + pre_gui_message (L"This beta build of WinUAE is obsolete.\nPlease download newer version."); + + _tcscpy (title, L"WinUAE Public Beta Disclaimer"); + _tcscat (title, BetaStr); + r = MessageBox (NULL, BETAMESSAGE, title, MB_OKCANCEL | MB_TASKMODAL | MB_SETFOREGROUND | MB_ICONWARNING | MB_DEFBUTTON2); + if (r == IDABORT || r == IDCANCEL) + return 0; + if (ft64.QuadPart > 0) { + regft64 = ft64.QuadPart; + RegSetValueEx (hWinUAEKey, L"BetaToken", 0, REG_QWORD, (LPBYTE)®ft64, sizeof regft64); + } } - } #endif - return 1; + return 1; } static int dxdetect (void) { #if !defined(WIN64) - /* believe or not but this is MS supported way of detecting DX8+ */ - HMODULE h = LoadLibrary (L"D3D8.DLL"); - TCHAR szWrongDXVersion[MAX_DPATH]; - if (h) { - FreeLibrary (h); - return 1; - } - WIN32GUI_LoadUIString (IDS_WRONGDXVERSION, szWrongDXVersion, MAX_DPATH); - pre_gui_message (szWrongDXVersion); - return 0; + /* believe or not but this is MS supported way of detecting DX8+ */ + HMODULE h = LoadLibrary (L"D3D8.DLL"); + TCHAR szWrongDXVersion[MAX_DPATH]; + if (h) { + FreeLibrary (h); + return 1; + } + WIN32GUI_LoadUIString (IDS_WRONGDXVERSION, szWrongDXVersion, MAX_DPATH); + pre_gui_message (szWrongDXVersion); + return 0; #else - return 1; + return 1; #endif } @@ -3520,59 +3530,59 @@ int os_winnt, os_winnt_admin, os_64bit, os_win7, os_vista, os_winxp; static int isadminpriv (void) { - DWORD i, dwSize = 0, dwResult = 0; - HANDLE hToken; - PTOKEN_GROUPS pGroupInfo; - BYTE sidBuffer[100]; - PSID pSID = (PSID)&sidBuffer; - SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY; - int isadmin = 0; - - // Open a handle to the access token for the calling process. - if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hToken)) { - write_log (L"OpenProcessToken Error %u\n", GetLastError ()); - return FALSE; - } + DWORD i, dwSize = 0, dwResult = 0; + HANDLE hToken; + PTOKEN_GROUPS pGroupInfo; + BYTE sidBuffer[100]; + PSID pSID = (PSID)&sidBuffer; + SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY; + int isadmin = 0; + + // Open a handle to the access token for the calling process. + if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hToken)) { + write_log (L"OpenProcessToken Error %u\n", GetLastError ()); + return FALSE; + } + + // Call GetTokenInformation to get the buffer size. + if(!GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize)) { + dwResult = GetLastError (); + if(dwResult != ERROR_INSUFFICIENT_BUFFER) { + write_log (L"GetTokenInformation Error %u\n", dwResult); + return FALSE; + } + } + + // Allocate the buffer. + pGroupInfo = (PTOKEN_GROUPS)GlobalAlloc (GPTR, dwSize); - // Call GetTokenInformation to get the buffer size. - if(!GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize)) { - dwResult = GetLastError (); - if(dwResult != ERROR_INSUFFICIENT_BUFFER) { - write_log (L"GetTokenInformation Error %u\n", dwResult); - return FALSE; + // Call GetTokenInformation again to get the group information. + if (!GetTokenInformation (hToken, TokenGroups, pGroupInfo, dwSize, &dwSize)) { + write_log (L"GetTokenInformation Error %u\n", GetLastError ()); + return FALSE; } - } - // Allocate the buffer. - pGroupInfo = (PTOKEN_GROUPS)GlobalAlloc (GPTR, dwSize); + // Create a SID for the BUILTIN\Administrators group. + if (!AllocateAndInitializeSid (&SIDAuth, 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + &pSID)) { + write_log (L"AllocateAndInitializeSid Error %u\n", GetLastError ()); + return FALSE; + } - // Call GetTokenInformation again to get the group information. - if (!GetTokenInformation (hToken, TokenGroups, pGroupInfo, dwSize, &dwSize)) { - write_log (L"GetTokenInformation Error %u\n", GetLastError ()); - return FALSE; - } - - // Create a SID for the BUILTIN\Administrators group. - if (!AllocateAndInitializeSid (&SIDAuth, 2, - SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, - 0, 0, 0, 0, 0, 0, - &pSID)) { - write_log (L"AllocateAndInitializeSid Error %u\n", GetLastError ()); - return FALSE; - } - - // Loop through the group SIDs looking for the administrator SID. - for(i = 0; i < pGroupInfo->GroupCount; i++) { - if (EqualSid (pSID, pGroupInfo->Groups[i].Sid)) - isadmin = 1; - } - - if (pSID) - FreeSid (pSID); - if (pGroupInfo) - GlobalFree (pGroupInfo); - return isadmin; + // Loop through the group SIDs looking for the administrator SID. + for(i = 0; i < pGroupInfo->GroupCount; i++) { + if (EqualSid (pSID, pGroupInfo->Groups[i].Sid)) + isadmin = 1; + } + + if (pSID) + FreeSid (pSID); + if (pGroupInfo) + GlobalFree (pGroupInfo); + return isadmin; } typedef void (CALLBACK* PGETNATIVESYSTEMINFO)(LPSYSTEM_INFO); @@ -3580,236 +3590,236 @@ typedef BOOL (CALLBACK* PISUSERANADMIN)(VOID); static int osdetect (void) { - PGETNATIVESYSTEMINFO pGetNativeSystemInfo; - PISUSERANADMIN pIsUserAnAdmin; - - pGetNativeSystemInfo = (PGETNATIVESYSTEMINFO)GetProcAddress ( - GetModuleHandle (L"kernel32.dll"), "GetNativeSystemInfo"); - pIsUserAnAdmin = (PISUSERANADMIN)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "IsUserAnAdmin"); - - GetSystemInfo (&SystemInfo); - if (pGetNativeSystemInfo) - pGetNativeSystemInfo (&SystemInfo); - osVersion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (GetVersionEx (&osVersion)) { - if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && - (osVersion.dwMajorVersion <= 4)) - { - /* WinUAE not supported on this version of Windows... */ - TCHAR szWrongOSVersion[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_WRONGOSVERSION, szWrongOSVersion, MAX_DPATH); - pre_gui_message (szWrongOSVersion); - return FALSE; - } - if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) - os_winnt = 1; - if (osVersion.dwMajorVersion > 5 || (osVersion.dwMajorVersion == 5 && osVersion.dwMinorVersion >= 1)) - os_winxp = 1; - if (osVersion.dwMajorVersion >= 6) - os_vista = 1; - if (osVersion.dwMajorVersion >= 7 || (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion >= 1)) - os_win7 = 1; - if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) - os_64bit = 1; - } - if (!os_winnt) - return 0; - os_winnt_admin = isadminpriv (); - if (os_winnt_admin) { - if (pIsUserAnAdmin) { - if (pIsUserAnAdmin ()) - os_winnt_admin++; - } else { - os_winnt_admin++; + PGETNATIVESYSTEMINFO pGetNativeSystemInfo; + PISUSERANADMIN pIsUserAnAdmin; + + pGetNativeSystemInfo = (PGETNATIVESYSTEMINFO)GetProcAddress ( + GetModuleHandle (L"kernel32.dll"), "GetNativeSystemInfo"); + pIsUserAnAdmin = (PISUSERANADMIN)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "IsUserAnAdmin"); + + GetSystemInfo (&SystemInfo); + if (pGetNativeSystemInfo) + pGetNativeSystemInfo (&SystemInfo); + osVersion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (GetVersionEx (&osVersion)) { + if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && + (osVersion.dwMajorVersion <= 4)) + { + /* WinUAE not supported on this version of Windows... */ + TCHAR szWrongOSVersion[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_WRONGOSVERSION, szWrongOSVersion, MAX_DPATH); + pre_gui_message (szWrongOSVersion); + return FALSE; + } + if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) + os_winnt = 1; + if (osVersion.dwMajorVersion > 5 || (osVersion.dwMajorVersion == 5 && osVersion.dwMinorVersion >= 1)) + os_winxp = 1; + if (osVersion.dwMajorVersion >= 6) + os_vista = 1; + if (osVersion.dwMajorVersion >= 7 || (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion >= 1)) + os_win7 = 1; + if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) + os_64bit = 1; + } + if (!os_winnt) + return 0; + os_winnt_admin = isadminpriv (); + if (os_winnt_admin) { + if (pIsUserAnAdmin) { + if (pIsUserAnAdmin ()) + os_winnt_admin++; + } else { + os_winnt_admin++; + } } - } - return 1; + return 1; } void create_afnewdir (int remove) { - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, tmp))) { - fixtrailing (tmp); - _tcscpy (tmp2, tmp); - _tcscat (tmp2, L"Amiga Files"); - _tcscpy (tmp, tmp2); - _tcscat (tmp, L"\\WinUAE"); - if (remove) { - if (GetFileAttributes (tmp) != INVALID_FILE_ATTRIBUTES) { - RemoveDirectory (tmp); - RemoveDirectory (tmp2); - } - } else { - CreateDirectory (tmp2, NULL); - CreateDirectory (tmp, NULL); + if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, tmp))) { + fixtrailing (tmp); + _tcscpy (tmp2, tmp); + _tcscat (tmp2, L"Amiga Files"); + _tcscpy (tmp, tmp2); + _tcscat (tmp, L"\\WinUAE"); + if (remove) { + if (GetFileAttributes (tmp) != INVALID_FILE_ATTRIBUTES) { + RemoveDirectory (tmp); + RemoveDirectory (tmp2); + } + } else { + CreateDirectory (tmp2, NULL); + CreateDirectory (tmp, NULL); + } } - } } static void getstartpaths (void) { - TCHAR *posn, *p; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH], prevpath[MAX_DPATH]; - DWORD v; - UAEREG *key; - TCHAR xstart_path_uae[MAX_DPATH], xstart_path_old[MAX_DPATH]; - TCHAR xstart_path_new1[MAX_DPATH], xstart_path_new2[MAX_DPATH]; - - path_type = -1; - prevpath[0] = 0; - xstart_path_uae[0] = xstart_path_old[0] = xstart_path_new1[0] = xstart_path_new2[0] = 0; - key = regcreatetree (NULL, NULL); - if (key) { - DWORD size = sizeof (prevpath) / sizeof (TCHAR); - if (!regquerystr (key, L"PathMode", prevpath, &size)) - prevpath[0] = 0; - regclosetree (key); - } - if (!_tcscmp (prevpath, L"WinUAE")) - path_type = PATH_TYPE_WINUAE; - if (!_tcscmp (prevpath, L"WinUAE_2")) - path_type = PATH_TYPE_NEWWINUAE; - if (!_tcscmp (prevpath, L"AF")) - path_type = PATH_TYPE_OLDAF; - if (!_tcscmp (prevpath, L"AF2005")) - path_type = PATH_TYPE_NEWAF; - if (!_tcscmp (prevpath, L"AMIGAFOREVERDATA")) - path_type = PATH_TYPE_AMIGAFOREVERDATA; - - _tcscpy (start_path_exe, _wpgmptr); - if((posn = _tcsrchr (start_path_exe, '\\'))) - posn[1] = 0; - - _tcscpy (tmp, start_path_exe); - _tcscat (tmp, L"roms"); - if (isfilesindir (tmp)) { - _tcscpy (xstart_path_uae, start_path_exe); - } - _tcscpy (tmp, start_path_exe); - _tcscat (tmp, L"configurations"); - if (isfilesindir (tmp)) { - _tcscpy (xstart_path_uae, start_path_exe); - } - - _tcscpy (tmp, start_path_exe); - _tcscat (tmp, L"..\\system\\rom\\rom.key"); - v = GetFileAttributes (tmp); - if (v != INVALID_FILE_ATTRIBUTES) { - af_path_old = 1; - _tcscpy (xstart_path_old, start_path_exe); - _tcscat (xstart_path_old, L"..\\system\\"); - _tcscpy (start_path_af, xstart_path_old); - } else { + TCHAR *posn, *p; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH], prevpath[MAX_DPATH]; + DWORD v; + UAEREG *key; + TCHAR xstart_path_uae[MAX_DPATH], xstart_path_old[MAX_DPATH]; + TCHAR xstart_path_new1[MAX_DPATH], xstart_path_new2[MAX_DPATH]; + + path_type = -1; + prevpath[0] = 0; + xstart_path_uae[0] = xstart_path_old[0] = xstart_path_new1[0] = xstart_path_new2[0] = 0; + key = regcreatetree (NULL, NULL); + if (key) { + DWORD size = sizeof (prevpath) / sizeof (TCHAR); + if (!regquerystr (key, L"PathMode", prevpath, &size)) + prevpath[0] = 0; + regclosetree (key); + } + if (!_tcscmp (prevpath, L"WinUAE")) + path_type = PATH_TYPE_WINUAE; + if (!_tcscmp (prevpath, L"WinUAE_2")) + path_type = PATH_TYPE_NEWWINUAE; + if (!_tcscmp (prevpath, L"AF")) + path_type = PATH_TYPE_OLDAF; + if (!_tcscmp (prevpath, L"AF2005")) + path_type = PATH_TYPE_NEWAF; + if (!_tcscmp (prevpath, L"AMIGAFOREVERDATA")) + path_type = PATH_TYPE_AMIGAFOREVERDATA; + + _tcscpy (start_path_exe, _wpgmptr); + if((posn = _tcsrchr (start_path_exe, '\\'))) + posn[1] = 0; + + _tcscpy (tmp, start_path_exe); + _tcscat (tmp, L"roms"); + if (isfilesindir (tmp)) { + _tcscpy (xstart_path_uae, start_path_exe); + } + _tcscpy (tmp, start_path_exe); + _tcscat (tmp, L"configurations"); + if (isfilesindir (tmp)) { + _tcscpy (xstart_path_uae, start_path_exe); + } + _tcscpy (tmp, start_path_exe); - _tcscat (tmp, L"..\\shared\\rom\\rom.key"); + _tcscat (tmp, L"..\\system\\rom\\rom.key"); v = GetFileAttributes (tmp); if (v != INVALID_FILE_ATTRIBUTES) { - af_path_old = 1; - _tcscpy (xstart_path_old, start_path_exe); - _tcscat (xstart_path_old, L"..\\shared\\"); - _tcscpy (start_path_af, xstart_path_old); + af_path_old = 1; + _tcscpy (xstart_path_old, start_path_exe); + _tcscat (xstart_path_old, L"..\\system\\"); + _tcscpy (start_path_af, xstart_path_old); + } else { + _tcscpy (tmp, start_path_exe); + _tcscat (tmp, L"..\\shared\\rom\\rom.key"); + v = GetFileAttributes (tmp); + if (v != INVALID_FILE_ATTRIBUTES) { + af_path_old = 1; + _tcscpy (xstart_path_old, start_path_exe); + _tcscat (xstart_path_old, L"..\\shared\\"); + _tcscpy (start_path_af, xstart_path_old); + } } - } - p = _wgetenv (L"AMIGAFOREVERDATA"); - if (p) { - _tcscpy (tmp, p); - fixtrailing (tmp); - _tcscpy (start_path_new2, p); - fixtrailing (start_path_af); - v = GetFileAttributes (tmp); - if (v != INVALID_FILE_ATTRIBUTES && (v & FILE_ATTRIBUTE_DIRECTORY)) { - _tcscpy (xstart_path_new2, start_path_af); - _tcscpy (xstart_path_new2, L"WinUAE\\"); - af_path_2005 |= 2; + p = _wgetenv (L"AMIGAFOREVERDATA"); + if (p) { + _tcscpy (tmp, p); + fixtrailing (tmp); + _tcscpy (start_path_new2, p); + fixtrailing (start_path_af); + v = GetFileAttributes (tmp); + if (v != INVALID_FILE_ATTRIBUTES && (v & FILE_ATTRIBUTE_DIRECTORY)) { + _tcscpy (xstart_path_new2, start_path_af); + _tcscpy (xstart_path_new2, L"WinUAE\\"); + af_path_2005 |= 2; + } } - } - { - if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, tmp))) { - fixtrailing (tmp); - _tcscpy (tmp2, tmp); - _tcscat (tmp2, L"Amiga Files\\"); - _tcscpy (tmp, tmp2); - _tcscat (tmp, L"WinUAE"); - v = GetFileAttributes (tmp); - if (v == INVALID_FILE_ATTRIBUTES || (v & FILE_ATTRIBUTE_DIRECTORY)) { - TCHAR *p; - _tcscpy (xstart_path_new1, tmp2); - _tcscat (xstart_path_new1, L"WinUAE\\"); - _tcscpy (xstart_path_uae, start_path_exe); - _tcscpy (start_path_new1, xstart_path_new1); - p = tmp2 + _tcslen (tmp2); - _tcscpy (p, L"System"); - if (isfilesindir (tmp2)) { - af_path_2005 |= 1; - } else { - _tcscpy (p, L"Shared"); - if (isfilesindir (tmp2)) { - af_path_2005 |= 1; - } + { + if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, tmp))) { + fixtrailing (tmp); + _tcscpy (tmp2, tmp); + _tcscat (tmp2, L"Amiga Files\\"); + _tcscpy (tmp, tmp2); + _tcscat (tmp, L"WinUAE"); + v = GetFileAttributes (tmp); + if (v == INVALID_FILE_ATTRIBUTES || (v & FILE_ATTRIBUTE_DIRECTORY)) { + TCHAR *p; + _tcscpy (xstart_path_new1, tmp2); + _tcscat (xstart_path_new1, L"WinUAE\\"); + _tcscpy (xstart_path_uae, start_path_exe); + _tcscpy (start_path_new1, xstart_path_new1); + p = tmp2 + _tcslen (tmp2); + _tcscpy (p, L"System"); + if (isfilesindir (tmp2)) { + af_path_2005 |= 1; + } else { + _tcscpy (p, L"Shared"); + if (isfilesindir (tmp2)) { + af_path_2005 |= 1; + } + } + } } - } - } - } - - if (start_data == 0) { - start_data = 1; - if (path_type == 0 && xstart_path_uae[0]) { - _tcscpy (start_path_data, xstart_path_uae); - } else if (path_type == PATH_TYPE_OLDAF && af_path_old && xstart_path_old[0]) { - _tcscpy (start_path_data, xstart_path_old); - } else if (path_type == PATH_TYPE_NEWWINUAE && xstart_path_new1[0]) { - _tcscpy (start_path_data, xstart_path_new1); - create_afnewdir(0); - } else if (path_type == PATH_TYPE_NEWAF && (af_path_2005 & 1) && xstart_path_new1[0]) { - _tcscpy (start_path_data, xstart_path_new1); - create_afnewdir(0); - } else if (path_type == PATH_TYPE_AMIGAFOREVERDATA && (af_path_2005 & 2) && xstart_path_new2[0]) { - _tcscpy (start_path_data, xstart_path_new2); - } else if (path_type < 0) { - path_type = 0; - _tcscpy (start_path_data, xstart_path_uae); - if (af_path_old) { - path_type = PATH_TYPE_OLDAF; - _tcscpy (start_path_data, xstart_path_old); - } - if (af_path_2005 & 1) { - path_type = PATH_TYPE_NEWAF; - create_afnewdir (1); - _tcscpy (start_path_data, xstart_path_new1); - } - if (af_path_2005 & 2) { - _tcscpy (tmp, xstart_path_new2); - _tcscat (tmp, L"system\\rom"); - if (isfilesindir (tmp)) { - path_type = PATH_TYPE_AMIGAFOREVERDATA; - } else { - _tcscpy (tmp, xstart_path_new2); - _tcscat (tmp, L"shared\\rom"); - if (isfilesindir (tmp)) { - path_type = PATH_TYPE_AMIGAFOREVERDATA; - } else { - path_type = PATH_TYPE_NEWWINUAE; - } + } + + if (start_data == 0) { + start_data = 1; + if (path_type == 0 && xstart_path_uae[0]) { + _tcscpy (start_path_data, xstart_path_uae); + } else if (path_type == PATH_TYPE_OLDAF && af_path_old && xstart_path_old[0]) { + _tcscpy (start_path_data, xstart_path_old); + } else if (path_type == PATH_TYPE_NEWWINUAE && xstart_path_new1[0]) { + _tcscpy (start_path_data, xstart_path_new1); + create_afnewdir(0); + } else if (path_type == PATH_TYPE_NEWAF && (af_path_2005 & 1) && xstart_path_new1[0]) { + _tcscpy (start_path_data, xstart_path_new1); + create_afnewdir(0); + } else if (path_type == PATH_TYPE_AMIGAFOREVERDATA && (af_path_2005 & 2) && xstart_path_new2[0]) { + _tcscpy (start_path_data, xstart_path_new2); + } else if (path_type < 0) { + path_type = 0; + _tcscpy (start_path_data, xstart_path_uae); + if (af_path_old) { + path_type = PATH_TYPE_OLDAF; + _tcscpy (start_path_data, xstart_path_old); + } + if (af_path_2005 & 1) { + path_type = PATH_TYPE_NEWAF; + create_afnewdir (1); + _tcscpy (start_path_data, xstart_path_new1); + } + if (af_path_2005 & 2) { + _tcscpy (tmp, xstart_path_new2); + _tcscat (tmp, L"system\\rom"); + if (isfilesindir (tmp)) { + path_type = PATH_TYPE_AMIGAFOREVERDATA; + } else { + _tcscpy (tmp, xstart_path_new2); + _tcscat (tmp, L"shared\\rom"); + if (isfilesindir (tmp)) { + path_type = PATH_TYPE_AMIGAFOREVERDATA; + } else { + path_type = PATH_TYPE_NEWWINUAE; + } + } + _tcscpy (start_path_data, xstart_path_new2); + } } - _tcscpy (start_path_data, xstart_path_new2); - } - } - } - - v = GetFileAttributes (start_path_data); - if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY) || start_data == 0 || start_data == -2) { - _tcscpy (start_path_data, start_path_exe); - } - fixtrailing (start_path_data); - GetFullPathName (start_path_data, sizeof tmp / sizeof (TCHAR), tmp, NULL); - _tcscpy (start_path_data, tmp); - SetCurrentDirectory (start_path_data); + } + + v = GetFileAttributes (start_path_data); + if (v == INVALID_FILE_ATTRIBUTES || !(v & FILE_ATTRIBUTE_DIRECTORY) || start_data == 0 || start_data == -2) { + _tcscpy (start_path_data, start_path_exe); + } + fixtrailing (start_path_data); + GetFullPathName (start_path_data, sizeof tmp / sizeof (TCHAR), tmp, NULL); + _tcscpy (start_path_data, tmp); + SetCurrentDirectory (start_path_data); } extern void test (void); @@ -3821,565 +3831,565 @@ static DWORD_PTR original_affinity = -1; static int getval (const TCHAR *s) { - int base = 10; - int v; - TCHAR *endptr; - - if (s[0] == '0' && _totupper(s[1]) == 'X') - s += 2, base = 16; - v = _tcstol (s, &endptr, base); - if (*endptr != '\0' || *s == '\0') - return 0; - return v; + int base = 10; + int v; + TCHAR *endptr; + + if (s[0] == '0' && _totupper(s[1]) == 'X') + s += 2, base = 16; + v = _tcstol (s, &endptr, base); + if (*endptr != '\0' || *s == '\0') + return 0; + return v; } static void makeverstr (TCHAR *s) { - if (_tcslen (WINUAEBETA) > 0) { - _stprintf (BetaStr, L" (%sBeta %s, %d.%02d.%02d)", WINUAEPUBLICBETA > 0 ? L"Public " : L"", WINUAEBETA, - GETBDY(WINUAEDATE), GETBDM(WINUAEDATE), GETBDD(WINUAEDATE)); - _stprintf (s, L"WinUAE %d.%d.%d%s%s", - UAEMAJOR, UAEMINOR, UAESUBREV, WINUAEREV, BetaStr); - } else { - _stprintf (s, L"WinUAE %d.%d.%d%s (%d.%02d.%02d)", - UAEMAJOR, UAEMINOR, UAESUBREV, WINUAEREV, GETBDY(WINUAEDATE), GETBDM(WINUAEDATE), GETBDD(WINUAEDATE)); - } - if (_tcslen (WINUAEEXTRA) > 0) { - _tcscat (s, L" "); - _tcscat (s, WINUAEEXTRA); - } + if (_tcslen (WINUAEBETA) > 0) { + _stprintf (BetaStr, L" (%sBeta %s, %d.%02d.%02d)", WINUAEPUBLICBETA > 0 ? L"Public " : L"", WINUAEBETA, + GETBDY(WINUAEDATE), GETBDM(WINUAEDATE), GETBDD(WINUAEDATE)); + _stprintf (s, L"WinUAE %d.%d.%d%s%s", + UAEMAJOR, UAEMINOR, UAESUBREV, WINUAEREV, BetaStr); + } else { + _stprintf (s, L"WinUAE %d.%d.%d%s (%d.%02d.%02d)", + UAEMAJOR, UAEMINOR, UAESUBREV, WINUAEREV, GETBDY(WINUAEDATE), GETBDM(WINUAEDATE), GETBDD(WINUAEDATE)); + } + if (_tcslen (WINUAEEXTRA) > 0) { + _tcscat (s, L" "); + _tcscat (s, WINUAEEXTRA); + } } static int parseargs (const TCHAR *arg, const TCHAR *np, const TCHAR *np2) { - if (!_tcscmp (arg, L"-convert") && np && np2) { - zfile_convertimage (np, np2); - return -1; - } - if (!_tcscmp (arg, L"-console")) { - return 1; - } - if (!_tcscmp (arg, L"-log")) { - console_logging = 1; - return 1; - } + if (!_tcscmp (arg, L"-convert") && np && np2) { + zfile_convertimage (np, np2); + return -1; + } + if (!_tcscmp (arg, L"-console")) { + return 1; + } + if (!_tcscmp (arg, L"-log")) { + console_logging = 1; + return 1; + } #ifdef FILESYS - if (!_tcscmp (arg, L"-rdbdump")) { - do_rdbdump = 1; - return 1; - } - if (!_tcscmp (arg, L"-disableharddrivesafetycheck")) { - harddrive_dangerous = 0x1234dead; - return 1; - } - if (!_tcscmp (arg, L"-noaspifiltering")) { - aspi_allow_all = 1; - return 1; - } + if (!_tcscmp (arg, L"-rdbdump")) { + do_rdbdump = 1; + return 1; + } + if (!_tcscmp (arg, L"-disableharddrivesafetycheck")) { + harddrive_dangerous = 0x1234dead; + return 1; + } + if (!_tcscmp (arg, L"-noaspifiltering")) { + aspi_allow_all = 1; + return 1; + } #endif - if (!_tcscmp (arg, L"-norawinput")) { - no_rawinput = 1; - return 1; - } - if (!_tcscmp (arg, L"-rawkeyboard")) { - rawkeyboard = 1; - return 1; - } - if (!_tcscmp (arg, L"-directsound")) { - force_directsound = 1; - return 1; - } - if (!_tcscmp (arg, L"-scsilog")) { - log_scsi = 1; - return 1; - } - if (!_tcscmp (arg, L"-netlog")) { - log_net = 1; - return 1; - } - if (!_tcscmp (arg, L"-seriallog")) { - log_uaeserial = 1; - return 1; - } - if (!_tcscmp (arg, L"-clipboarddebug")) { - clipboard_debug = 1; - return 1; - } - if (!_tcscmp (arg, L"-rplog")) { - log_rp = 1; - return 1; - } - if (!_tcscmp (arg, L"-nomultidisplay")) { - multi_display = 0; - return 1; - } - if (!_tcscmp (arg, L"-legacypaths")) { - start_data = -2; - return 1; - } - if (!_tcscmp (arg, L"-screenshotbmp")) { - screenshotmode = 0; - return 1; - } - if (!_tcscmp (arg, L"-psprintdebug")) { - postscript_print_debugging = 1; - return 1; - } - if (!_tcscmp (arg, L"-sounddebug")) { - sound_debug = 1; - return 1; - } - if (!_tcscmp (arg, L"-directcatweasel")) { - force_direct_catweasel = 1; - if (np) { - force_direct_catweasel = getval (np); - return 2; + if (!_tcscmp (arg, L"-norawinput")) { + no_rawinput = 1; + return 1; + } + if (!_tcscmp (arg, L"-rawkeyboard")) { + rawkeyboard = 1; + return 1; + } + if (!_tcscmp (arg, L"-directsound")) { + force_directsound = 1; + return 1; + } + if (!_tcscmp (arg, L"-scsilog")) { + log_scsi = 1; + return 1; + } + if (!_tcscmp (arg, L"-netlog")) { + log_net = 1; + return 1; + } + if (!_tcscmp (arg, L"-seriallog")) { + log_uaeserial = 1; + return 1; + } + if (!_tcscmp (arg, L"-clipboarddebug")) { + clipboard_debug = 1; + return 1; + } + if (!_tcscmp (arg, L"-rplog")) { + log_rp = 1; + return 1; + } + if (!_tcscmp (arg, L"-nomultidisplay")) { + multi_display = 0; + return 1; + } + if (!_tcscmp (arg, L"-legacypaths")) { + start_data = -2; + return 1; + } + if (!_tcscmp (arg, L"-screenshotbmp")) { + screenshotmode = 0; + return 1; + } + if (!_tcscmp (arg, L"-psprintdebug")) { + postscript_print_debugging = 1; + return 1; + } + if (!_tcscmp (arg, L"-sounddebug")) { + sound_debug = 1; + return 1; + } + if (!_tcscmp (arg, L"-directcatweasel")) { + force_direct_catweasel = 1; + if (np) { + force_direct_catweasel = getval (np); + return 2; + } + return 1; + } + if (!_tcscmp (arg, L"-forcerdtsc")) { + userdtsc = 1; + return 1; + } + if (!_tcscmp (arg, L"-ddsoftwarecolorkey")) { + extern int ddsoftwarecolorkey; + ddsoftwarecolorkey = 1; + return 1; + } + if (!_tcscmp (arg, L"-logflush")) { + extern int always_flush_log; + always_flush_log = 1; + return 1; + } + if (!_tcscmp (arg, L"-ahidebug")) { + extern int ahi_debug; + ahi_debug = 2; + return 1; + } + if (!_tcscmp (arg, L"-ahidebug2")) { + extern int ahi_debug; + ahi_debug = 3; + return 1; + } + if (!_tcscmp (arg, L"-quittogui")) { + quit_to_gui = 1; + return 1; } - return 1; - } - if (!_tcscmp (arg, L"-forcerdtsc")) { - userdtsc = 1; - return 1; - } - if (!_tcscmp (arg, L"-ddsoftwarecolorkey")) { - extern int ddsoftwarecolorkey; - ddsoftwarecolorkey = 1; - return 1; - } - if (!_tcscmp (arg, L"-logflush")) { - extern int always_flush_log; - always_flush_log = 1; - return 1; - } - if (!_tcscmp (arg, L"-ahidebug")) { - extern int ahi_debug; - ahi_debug = 2; - return 1; - } - if (!_tcscmp (arg, L"-ahidebug2")) { - extern int ahi_debug; - ahi_debug = 3; - return 1; - } - if (!_tcscmp (arg, L"-quittogui")) { - quit_to_gui = 1; - return 1; - } - if (!np) - return 0; + if (!np) + return 0; - if (!_tcscmp (arg, L"-ddforcemode")) { - extern int ddforceram; - ddforceram = getval (np); - if (ddforceram < 0 || ddforceram > 3) - ddforceram = 0; - return 2; - } - if (!_tcscmp (arg, L"-affinity")) { - cpu_affinity = getval (np); - if (cpu_affinity == 0) - cpu_affinity = original_affinity; - SetThreadAffinityMask (GetCurrentThread (), cpu_affinity); - return 2; - } - if (!_tcscmp (arg, L"-paffinity")) { - cpu_paffinity = getval (np); - if (cpu_paffinity == 0) - cpu_paffinity = original_affinity; - SetProcessAffinityMask (GetCurrentProcess (), cpu_paffinity); - return 2; - } - if (!_tcscmp (arg, L"-datapath")) { - _tcscpy(start_path_data, np); - start_data = -1; - return 2; - } - if (!_tcscmp (arg, L"-maxmem")) { - maxmem = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-soundmodeskip")) { - sound_mode_skip = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-ini")) { - inipath = my_strdup (np); - return 2; - } - if (!_tcscmp (arg, L"-p96skipmode")) { - extern int p96skipmode; - p96skipmode = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-minidumpmode")) { - minidumpmode = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-jitevent")) { - pissoff_value = getval (np); - return 2; - } + if (!_tcscmp (arg, L"-ddforcemode")) { + extern int ddforceram; + ddforceram = getval (np); + if (ddforceram < 0 || ddforceram > 3) + ddforceram = 0; + return 2; + } + if (!_tcscmp (arg, L"-affinity")) { + cpu_affinity = getval (np); + if (cpu_affinity == 0) + cpu_affinity = original_affinity; + SetThreadAffinityMask (GetCurrentThread (), cpu_affinity); + return 2; + } + if (!_tcscmp (arg, L"-paffinity")) { + cpu_paffinity = getval (np); + if (cpu_paffinity == 0) + cpu_paffinity = original_affinity; + SetProcessAffinityMask (GetCurrentProcess (), cpu_paffinity); + return 2; + } + if (!_tcscmp (arg, L"-datapath")) { + _tcscpy(start_path_data, np); + start_data = -1; + return 2; + } + if (!_tcscmp (arg, L"-maxmem")) { + maxmem = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-soundmodeskip")) { + sound_mode_skip = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-ini")) { + inipath = my_strdup (np); + return 2; + } + if (!_tcscmp (arg, L"-p96skipmode")) { + extern int p96skipmode; + p96skipmode = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-minidumpmode")) { + minidumpmode = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-jitevent")) { + pissoff_value = getval (np); + return 2; + } #ifdef RETROPLATFORM - if (!_tcscmp (arg, L"-rphost")) { - rp_param = my_strdup (np); - return 2; - } - if (!_tcscmp (arg, L"-rpescapekey")) { - rp_rpescapekey = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-rpescapeholdtime")) { - rp_rpescapeholdtime = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-rpscreenmode")) { - rp_screenmode = getval (np); - return 2; - } - if (!_tcscmp (arg, L"-rpinputmode")) { - rp_inputmode = getval (np); - return 2; - } + if (!_tcscmp (arg, L"-rphost")) { + rp_param = my_strdup (np); + return 2; + } + if (!_tcscmp (arg, L"-rpescapekey")) { + rp_rpescapekey = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-rpescapeholdtime")) { + rp_rpescapeholdtime = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-rpscreenmode")) { + rp_screenmode = getval (np); + return 2; + } + if (!_tcscmp (arg, L"-rpinputmode")) { + rp_inputmode = getval (np); + return 2; + } #endif - return 0; + return 0; } static TCHAR **parseargstrings (TCHAR *s, TCHAR **xargv) { - int cnt, i, xargc; - TCHAR **args; - - args = parseargstring (s); - for (cnt = 0; args[cnt]; cnt++); - for (xargc = 0; xargv[xargc]; xargc++); - for (i = 0; i < cnt; i++) { - TCHAR *arg = args[i]; - TCHAR *next = i + 1 < cnt ? args[i + 1] : NULL; - TCHAR *next2 = i + 2 < cnt ? args[i + 2] : NULL; - int v = parseargs (arg, next, next2); - if (!v) { - xargv[xargc++] = my_strdup (arg); - } else if (v == 2) { - i++; - } else if (v < 0) { - doquit = 1; - return NULL; + int cnt, i, xargc; + TCHAR **args; + + args = parseargstring (s); + for (cnt = 0; args[cnt]; cnt++); + for (xargc = 0; xargv[xargc]; xargc++); + for (i = 0; i < cnt; i++) { + TCHAR *arg = args[i]; + TCHAR *next = i + 1 < cnt ? args[i + 1] : NULL; + TCHAR *next2 = i + 2 < cnt ? args[i + 2] : NULL; + int v = parseargs (arg, next, next2); + if (!v) { + xargv[xargc++] = my_strdup (arg); + } else if (v == 2) { + i++; + } else if (v < 0) { + doquit = 1; + return NULL; + } } - } - return args; + return args; } static int process_arg (TCHAR *cmdline, TCHAR **xargv, TCHAR ***xargv3) { - int i, xargc; - TCHAR **argv; - TCHAR tmp[MAX_DPATH]; - int fd, ok, added; - - *xargv3 = NULL; - argv = parseargstring (cmdline); - if (argv == NULL) - return 0; - added = 0; - xargc = 0; - xargv[xargc++] = my_strdup (_wpgmptr); - fd = 0; - for (i = 0; argv[i]; i++) { - TCHAR *f = argv[i]; - ok = 0; - if (f[0] != '-' && f[0] != '/') { - int type = -1; - struct zfile *z = zfile_fopen (f, L"rb", ZFD_NORMAL); - if (z) { - type = zfile_gettype (z); - zfile_fclose (z); - } - tmp[0] = 0; - switch (type) - { - case ZFILE_CONFIGURATION: - _stprintf (tmp, L"-config=%s", f); - break; - case ZFILE_STATEFILE: - _stprintf (tmp, L"-statefile=%s", f); - break; - case ZFILE_DISKIMAGE: - if (fd < 4) - _stprintf (tmp, L"-cfgparam=floppy%d=%s", fd++, f); - break; - } - if (tmp[0]) { - xfree (argv[i]); - argv[i] = my_strdup (tmp); - ok = 1; - added = 1; - } - } - if (!ok) - break; - } - if (added) { - for (i = 0; argv[i]; i++); - argv[i++] = my_strdup (L"-s"); - argv[i++] = my_strdup (L"use_gui=no"); - argv[i] = NULL; - } - for (i = 0; argv[i]; i++) { - TCHAR *arg = argv[i]; - TCHAR *next = argv[i + 1]; - TCHAR *next2 = next != NULL ? argv[i + 2] : NULL; - int v = parseargs (arg, next, next2); - if (!v) { - xargv[xargc++] = my_strdup (arg); - } else if (v == 2) { - i++; - } else if (v < 0) { - doquit = 1; - return 0; + int i, xargc; + TCHAR **argv; + TCHAR tmp[MAX_DPATH]; + int fd, ok, added; + + *xargv3 = NULL; + argv = parseargstring (cmdline); + if (argv == NULL) + return 0; + added = 0; + xargc = 0; + xargv[xargc++] = my_strdup (_wpgmptr); + fd = 0; + for (i = 0; argv[i]; i++) { + TCHAR *f = argv[i]; + ok = 0; + if (f[0] != '-' && f[0] != '/') { + int type = -1; + struct zfile *z = zfile_fopen (f, L"rb", ZFD_NORMAL); + if (z) { + type = zfile_gettype (z); + zfile_fclose (z); + } + tmp[0] = 0; + switch (type) + { + case ZFILE_CONFIGURATION: + _stprintf (tmp, L"-config=%s", f); + break; + case ZFILE_STATEFILE: + _stprintf (tmp, L"-statefile=%s", f); + break; + case ZFILE_DISKIMAGE: + if (fd < 4) + _stprintf (tmp, L"-cfgparam=floppy%d=%s", fd++, f); + break; + } + if (tmp[0]) { + xfree (argv[i]); + argv[i] = my_strdup (tmp); + ok = 1; + added = 1; + } + } + if (!ok) + break; + } + if (added) { + for (i = 0; argv[i]; i++); + argv[i++] = my_strdup (L"-s"); + argv[i++] = my_strdup (L"use_gui=no"); + argv[i] = NULL; + } + for (i = 0; argv[i]; i++) { + TCHAR *arg = argv[i]; + TCHAR *next = argv[i + 1]; + TCHAR *next2 = next != NULL ? argv[i + 2] : NULL; + int v = parseargs (arg, next, next2); + if (!v) { + xargv[xargc++] = my_strdup (arg); + } else if (v == 2) { + i++; + } else if (v < 0) { + doquit = 1; + return 0; + } } - } #if 0 - argv = 0; - argv[0] = 0; + argv = 0; + argv[0] = 0; #endif - *xargv3 = argv; - return xargc; + *xargv3 = argv; + return xargc; } static TCHAR **WIN32_InitRegistry (TCHAR **argv) { - DWORD disposition; - TCHAR tmp[MAX_DPATH]; - DWORD size = sizeof tmp / sizeof (TCHAR); - - reginitializeinit (inipath); - hWinUAEKey = NULL; - if (getregmode () == 0 || WINUAEPUBLICBETA > 0) { - /* Create/Open the hWinUAEKey which points our config-info */ - RegCreateKeyEx (HKEY_CURRENT_USER, L"Software\\Arabuusimiehet\\WinUAE", 0, L"", REG_OPTION_NON_VOLATILE, - KEY_WRITE | KEY_READ, NULL, &hWinUAEKey, &disposition); - if (hWinUAEKey == NULL) { - FILE *f; - TCHAR path[MAX_DPATH]; - TCHAR *posn; - - _tcscpy (path, _wpgmptr); - if((posn = _tcsrchr (path, '\\'))) - posn[1] = 0; - _tcscat (path, L"winuae.ini"); - f = _tfopen (path, L"r"); - if (!f) - f = _tfopen (path, L"w"); - if (f) { - fclose (f); - reginitializeinit (path); - } + DWORD disposition; + TCHAR tmp[MAX_DPATH]; + DWORD size = sizeof tmp / sizeof (TCHAR); + + reginitializeinit (inipath); + hWinUAEKey = NULL; + if (getregmode () == 0 || WINUAEPUBLICBETA > 0) { + /* Create/Open the hWinUAEKey which points our config-info */ + RegCreateKeyEx (HKEY_CURRENT_USER, L"Software\\Arabuusimiehet\\WinUAE", 0, L"", REG_OPTION_NON_VOLATILE, + KEY_WRITE | KEY_READ, NULL, &hWinUAEKey, &disposition); + if (hWinUAEKey == NULL) { + FILE *f; + TCHAR path[MAX_DPATH]; + TCHAR *posn; + + _tcscpy (path, _wpgmptr); + if((posn = _tcsrchr (path, '\\'))) + posn[1] = 0; + _tcscat (path, L"winuae.ini"); + f = _tfopen (path, L"r"); + if (!f) + f = _tfopen (path, L"w"); + if (f) { + fclose (f); + reginitializeinit (path); + } + } } - } - if (regquerystr (NULL, L"Commandline", tmp, &size)) - return parseargstrings (tmp, argv); - return NULL; + if (regquerystr (NULL, L"Commandline", tmp, &size)) + return parseargstrings (tmp, argv); + return NULL; } static int PASCAL WinMain2 (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { - HANDLE hMutex; - TCHAR **argv = NULL, **argv2 = NULL, **argv3; - int argc, i; + HANDLE hMutex; + TCHAR **argv = NULL, **argv2 = NULL, **argv3; + int argc, i; #if 0 #ifdef _DEBUG - { - int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - //tmp &= 0xffff; - tmp |= _CRTDBG_CHECK_ALWAYS_DF; - tmp |= _CRTDBG_CHECK_CRT_DF; + { + int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmp &= 0xffff; + tmp |= _CRTDBG_CHECK_ALWAYS_DF; + tmp |= _CRTDBG_CHECK_CRT_DF; #ifdef MEMDEBUG - tmp |=_CRTDBG_CHECK_EVERY_16_DF; - tmp |= _CRTDBG_DELAY_FREE_MEM_DF; + tmp |=_CRTDBG_CHECK_EVERY_16_DF; + tmp |= _CRTDBG_DELAY_FREE_MEM_DF; #endif - _CrtSetDbgFlag(tmp); - } + _CrtSetDbgFlag(tmp); + } #endif #endif - if (!osdetect ()) - return 0; - if (!dxdetect ()) - return 0; + if (!osdetect ()) + return 0; + if (!dxdetect ()) + return 0; - hInst = hInstance; - hMutex = CreateMutex (NULL, FALSE, L"WinUAE Instantiated"); // To tell the installer we're running + hInst = hInstance; + hMutex = CreateMutex (NULL, FALSE, L"WinUAE Instantiated"); // To tell the installer we're running - argv = xcalloc (sizeof (TCHAR*), MAX_ARGUMENTS); - argv3 = NULL; - argc = process_arg (lpCmdLine, argv, &argv3); - if (doquit) - return 0; + argv = xcalloc (sizeof (TCHAR*), MAX_ARGUMENTS); + argv3 = NULL; + argc = process_arg (lpCmdLine, argv, &argv3); + if (doquit) + return 0; - argv2 = WIN32_InitRegistry (argv); - getstartpaths (); - makeverstr (VersionStr); - - logging_init (); - if (_tcslen (lpCmdLine) > 0) - write_log (L"'%s'\n", lpCmdLine); - if (argv3 && argv3[0]) { - write_log (L"params:\n"); - for (i = 0; argv3[i]; i++) - write_log (L"%d: '%s'\n", i + 1, argv3[i]); - } - if (argv2) { - write_log (L"extra params:\n"); - for (i = 0; argv2[i]; i++) - write_log (L"%d: '%s'\n", i + 1, argv2[i]); - } - if (WIN32_RegisterClasses () && WIN32_InitLibraries () && DirectDraw_Start (NULL)) { - DEVMODE devmode; - DWORD i; - - WIN32_HandleRegistryStuff (); - DirectDraw_Release (); - write_log (L"Enumerating display devices.. \n"); - enumeratedisplays (multi_display); - write_log (L"Sorting devices and modes..\n"); - sortdisplays (); - write_log (L"Display buffer mode = %d\n", ddforceram); - enumerate_sound_devices (); - for (i = 0; sound_devices[i].name; i++) { - int type = sound_devices[i].type; - write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), sound_devices[i].name); - } - write_log (L"Enumerating recording devices:\n"); - for (i = 0; record_devices[i].name; i++) { - int type = record_devices[i].type; - write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), record_devices[i].name); - } - write_log (L"done\n"); - memset (&devmode, 0, sizeof (devmode)); - devmode.dmSize = sizeof (DEVMODE); - if (EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &devmode)) { - default_freq = devmode.dmDisplayFrequency; - if (default_freq >= 70) - default_freq = 70; - else - default_freq = 60; - } - WIN32_InitLang (); - WIN32_InitHtmlHelp (); - DirectDraw_Release (); - if (betamessage ()) { - keyboard_settrans (); + argv2 = WIN32_InitRegistry (argv); + getstartpaths (); + makeverstr (VersionStr); + + logging_init (); + if (_tcslen (lpCmdLine) > 0) + write_log (L"'%s'\n", lpCmdLine); + if (argv3 && argv3[0]) { + write_log (L"params:\n"); + for (i = 0; argv3[i]; i++) + write_log (L"%d: '%s'\n", i + 1, argv3[i]); + } + if (argv2) { + write_log (L"extra params:\n"); + for (i = 0; argv2[i]; i++) + write_log (L"%d: '%s'\n", i + 1, argv2[i]); + } + if (WIN32_RegisterClasses () && WIN32_InitLibraries () && DirectDraw_Start (NULL)) { + DEVMODE devmode; + DWORD i; + + WIN32_HandleRegistryStuff (); + DirectDraw_Release (); + write_log (L"Enumerating display devices.. \n"); + enumeratedisplays (multi_display); + write_log (L"Sorting devices and modes..\n"); + sortdisplays (); + write_log (L"Display buffer mode = %d\n", ddforceram); + enumerate_sound_devices (); + for (i = 0; sound_devices[i].name; i++) { + int type = sound_devices[i].type; + write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), sound_devices[i].name); + } + write_log (L"Enumerating recording devices:\n"); + for (i = 0; record_devices[i].name; i++) { + int type = record_devices[i].type; + write_log (L"%d:%s: %s\n", i, type == SOUND_DEVICE_DS ? L"DS" : (type == SOUND_DEVICE_AL ? L"AL" : L"PA"), record_devices[i].name); + } + write_log (L"done\n"); + memset (&devmode, 0, sizeof (devmode)); + devmode.dmSize = sizeof (DEVMODE); + if (EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &devmode)) { + default_freq = devmode.dmDisplayFrequency; + if (default_freq >= 70) + default_freq = 70; + else + default_freq = 60; + } + WIN32_InitLang (); + WIN32_InitHtmlHelp (); + DirectDraw_Release (); + if (betamessage ()) { + keyboard_settrans (); #ifdef CATWEASEL - catweasel_init (); + catweasel_init (); #endif #ifdef PARALLEL_PORT - paraport_mask = paraport_init (); + paraport_mask = paraport_init (); #endif - globalipc = createIPC (L"WinUAE", 0); - serialipc = createIPC (COMPIPENAME, 1); - enumserialports (); - real_main (argc, argv); + globalipc = createIPC (L"WinUAE", 0); + serialipc = createIPC (COMPIPENAME, 1); + enumserialports (); + real_main (argc, argv); + } } - } - closeIPC (globalipc); - closeIPC (serialipc); - write_disk_history (); - timeend (); + closeIPC (globalipc); + closeIPC (serialipc); + write_disk_history (); + timeend (); #ifdef AVIOUTPUT - AVIOutput_Release (); + AVIOutput_Release (); #endif #ifdef AHI - ahi_close_sound (); + ahi_close_sound (); #endif #ifdef PARALLEL_PORT - paraport_free (); - closeprinter (); + paraport_free (); + closeprinter (); #endif - create_afnewdir (1); - close_console (); - _fcloseall (); + create_afnewdir (1); + close_console (); + _fcloseall (); #ifdef RETROPLATFORM - rp_free (); + rp_free (); #endif - if (hWinUAEKey) - RegCloseKey (hWinUAEKey); - CloseHandle (hMutex); - WIN32_CleanupLibraries (); - WIN32_UnregisterClasses (); + if (hWinUAEKey) + RegCloseKey (hWinUAEKey); + CloseHandle (hMutex); + WIN32_CleanupLibraries (); + WIN32_UnregisterClasses (); #ifdef _DEBUG - // show memory leaks - //_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + // show memory leaks + //_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif - for (i = 0; i < argc; i++) - xfree (argv[i]); - xfree (argv); - if (argv2) { - for (i = 0; argv2[i]; i++) - xfree (argv2[i]); - xfree (argv2); - } - return FALSE; + for (i = 0; i < argc; i++) + xfree (argv[i]); + xfree (argv); + if (argv2) { + for (i = 0; argv2[i]; i++) + xfree (argv2[i]); + xfree (argv2); + } + return FALSE; } #if 0 int execute_command (TCHAR *cmd) { - STARTUPINFO si; - PROCESS_INFORMATION pi; - - memset (&si, 0, sizeof (si)); - si.cb = sizeof (si); - si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; - si.wShowWindow = SW_HIDE; - if(CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { - WaitForSingleObject(pi.hProcess, INFINITE); - return 1; - } - return 0; + STARTUPINFO si; + PROCESS_INFORMATION pi; + + memset (&si, 0, sizeof (si)); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + if(CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { + WaitForSingleObject(pi.hProcess, INFINITE); + return 1; + } + return 0; } #endif #include "driveclick.h" static int drvsampleres[] = { - IDR_DRIVE_CLICK_A500_1, DS_CLICK, - IDR_DRIVE_SPIN_A500_1, DS_SPIN, - IDR_DRIVE_SPINND_A500_1, DS_SPINND, - IDR_DRIVE_STARTUP_A500_1, DS_START, - IDR_DRIVE_SNATCH_A500_1, DS_SNATCH, - -1 + IDR_DRIVE_CLICK_A500_1, DS_CLICK, + IDR_DRIVE_SPIN_A500_1, DS_SPIN, + IDR_DRIVE_SPINND_A500_1, DS_SPINND, + IDR_DRIVE_STARTUP_A500_1, DS_START, + IDR_DRIVE_SNATCH_A500_1, DS_SNATCH, + -1 }; int driveclick_loadresource (struct drvsample *sp, int drivetype) { - int i, ok; - - ok = 1; - for (i = 0; drvsampleres[i] >= 0; i += 2) { - struct drvsample *s = sp + drvsampleres[i + 1]; - HRSRC res = FindResource (NULL, MAKEINTRESOURCE (drvsampleres[i + 0]), L"WAVE"); - if (res != 0) { - HANDLE h = LoadResource (NULL, res); - int len = SizeofResource (NULL, res); - uae_u8 *p = LockResource (h); - s->p = decodewav (p, &len); - s->len = len; - } else { - ok = 0; + int i, ok; + + ok = 1; + for (i = 0; drvsampleres[i] >= 0; i += 2) { + struct drvsample *s = sp + drvsampleres[i + 1]; + HRSRC res = FindResource (NULL, MAKEINTRESOURCE (drvsampleres[i + 0]), L"WAVE"); + if (res != 0) { + HANDLE h = LoadResource (NULL, res); + int len = SizeofResource (NULL, res); + uae_u8 *p = LockResource (h); + s->p = decodewav (p, &len); + s->len = len; + } else { + ok = 0; + } } - } - return ok; + return ok; } #if defined(WIN64) static LONG WINAPI WIN32_ExceptionFilter( struct _EXCEPTION_POINTERS * pExceptionPointers, DWORD ec) { - write_log (L"EVALEXCEPTION!\n"); - return EXCEPTION_EXECUTE_HANDLER; + write_log (L"EVALEXCEPTION!\n"); + return EXCEPTION_EXECUTE_HANDLER; } #else @@ -4387,461 +4397,461 @@ static LONG WINAPI WIN32_ExceptionFilter( struct _EXCEPTION_POINTERS * pExceptio #include #endif typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, - CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, - CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, - CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); + CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, + CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, + CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); /* Gah, don't look at this crap, please.. */ static void efix (DWORD *regp, void *p, void *ps, int *got) { - DWORD reg = *regp; - if (p >= (void*)reg && p < (void*)(reg + 32)) { - *regp = (DWORD)ps; - *got = 1; - } + DWORD reg = *regp; + if (p >= (void*)reg && p < (void*)(reg + 32)) { + *regp = (DWORD)ps; + *got = 1; + } } static void savedump (MINIDUMPWRITEDUMP dump, HANDLE f, struct _EXCEPTION_POINTERS *pExceptionPointers) { - MINIDUMP_EXCEPTION_INFORMATION exinfo; - MINIDUMP_USER_STREAM_INFORMATION musi, *musip; - MINIDUMP_USER_STREAM mus[2], *musp; - uae_char *log; - int loglen; - - musip = NULL; - log = save_log (TRUE, &loglen); - if (log) { - musi.UserStreamArray = mus; - musi.UserStreamCount = 1; - musp = &mus[0]; - musp->Type = LastReservedStream + 1; - musp->Buffer = log; - musp->BufferSize = loglen; - musip = &musi; - log = save_log (FALSE, &loglen); + MINIDUMP_EXCEPTION_INFORMATION exinfo; + MINIDUMP_USER_STREAM_INFORMATION musi, *musip; + MINIDUMP_USER_STREAM mus[2], *musp; + uae_char *log; + int loglen; + + musip = NULL; + log = save_log (TRUE, &loglen); if (log) { - musi.UserStreamCount++; - musp = &mus[1]; - musp->Type = LastReservedStream + 2; - musp->Buffer = log; - musp->BufferSize = loglen; - } - } - exinfo.ThreadId = GetCurrentThreadId (); - exinfo.ExceptionPointers = pExceptionPointers; - exinfo.ClientPointers = 0; - dump (GetCurrentProcess (), GetCurrentProcessId (), f, minidumpmode, &exinfo, musip, NULL); + musi.UserStreamArray = mus; + musi.UserStreamCount = 1; + musp = &mus[0]; + musp->Type = LastReservedStream + 1; + musp->Buffer = log; + musp->BufferSize = loglen; + musip = &musi; + log = save_log (FALSE, &loglen); + if (log) { + musi.UserStreamCount++; + musp = &mus[1]; + musp->Type = LastReservedStream + 2; + musp->Buffer = log; + musp->BufferSize = loglen; + } + } + exinfo.ThreadId = GetCurrentThreadId (); + exinfo.ExceptionPointers = pExceptionPointers; + exinfo.ClientPointers = 0; + dump (GetCurrentProcess (), GetCurrentProcessId (), f, minidumpmode, &exinfo, musip, NULL); } LONG WINAPI WIN32_ExceptionFilter (struct _EXCEPTION_POINTERS *pExceptionPointers, DWORD ec) { - static uae_u8 *prevpc; - LONG lRet = EXCEPTION_CONTINUE_SEARCH; - PEXCEPTION_RECORD er = pExceptionPointers->ExceptionRecord; - PCONTEXT ctx = pExceptionPointers->ContextRecord; + static uae_u8 *prevpc; + LONG lRet = EXCEPTION_CONTINUE_SEARCH; + PEXCEPTION_RECORD er = pExceptionPointers->ExceptionRecord; + PCONTEXT ctx = pExceptionPointers->ContextRecord; - /* Check possible access violation in 68010+/compatible mode disabled if PC points to non-existing memory */ + /* Check possible access violation in 68010+/compatible mode disabled if PC points to non-existing memory */ #if 1 - if (ec == EXCEPTION_ACCESS_VIOLATION && !er->ExceptionFlags && - er->NumberParameters >= 2 && !er->ExceptionInformation[0] && regs.pc_p) { - void *p = (void*)er->ExceptionInformation[1]; - write_log (L"ExceptionFilter Trap: %p %p %p\n", p, regs.pc_p, prevpc); - if ((p >= (void*)regs.pc_p && p < (void*)(regs.pc_p + 32)) - || (p >= (void*)prevpc && p < (void*)(prevpc + 32))) { - int got = 0; - uaecptr opc = m68k_getpc (); - void *ps = get_real_address (0); - m68k_dumpstate (0, 0); - efix (&ctx->Eax, p, ps, &got); - efix (&ctx->Ebx, p, ps, &got); - efix (&ctx->Ecx, p, ps, &got); - efix (&ctx->Edx, p, ps, &got); - efix (&ctx->Esi, p, ps, &got); - efix (&ctx->Edi, p, ps, &got); - write_log (L"Access violation! (68KPC=%08X HOSTADDR=%p)\n", M68K_GETPC, p); - if (got == 0) { - write_log (L"failed to find and fix the problem (%p). crashing..\n", p); - } else { - void *ppc = regs.pc_p; - m68k_setpc (0); - if (ppc != regs.pc_p) { - prevpc = (uae_u8*)ppc; - } - exception2 (opc, (uaecptr)p); - lRet = EXCEPTION_CONTINUE_EXECUTION; - } - } - } + if (ec == EXCEPTION_ACCESS_VIOLATION && !er->ExceptionFlags && + er->NumberParameters >= 2 && !er->ExceptionInformation[0] && regs.pc_p) { + void *p = (void*)er->ExceptionInformation[1]; + write_log (L"ExceptionFilter Trap: %p %p %p\n", p, regs.pc_p, prevpc); + if ((p >= (void*)regs.pc_p && p < (void*)(regs.pc_p + 32)) + || (p >= (void*)prevpc && p < (void*)(prevpc + 32))) { + int got = 0; + uaecptr opc = m68k_getpc (); + void *ps = get_real_address (0); + m68k_dumpstate (0, 0); + efix (&ctx->Eax, p, ps, &got); + efix (&ctx->Ebx, p, ps, &got); + efix (&ctx->Ecx, p, ps, &got); + efix (&ctx->Edx, p, ps, &got); + efix (&ctx->Esi, p, ps, &got); + efix (&ctx->Edi, p, ps, &got); + write_log (L"Access violation! (68KPC=%08X HOSTADDR=%p)\n", M68K_GETPC, p); + if (got == 0) { + write_log (L"failed to find and fix the problem (%p). crashing..\n", p); + } else { + void *ppc = regs.pc_p; + m68k_setpc (0); + if (ppc != regs.pc_p) { + prevpc = (uae_u8*)ppc; + } + exception2 (opc, (uaecptr)p); + lRet = EXCEPTION_CONTINUE_EXECUTION; + } + } + } #endif #ifndef _DEBUG - if (lRet == EXCEPTION_CONTINUE_SEARCH) { - TCHAR path[MAX_DPATH]; - TCHAR path2[MAX_DPATH]; - TCHAR msg[1024]; - TCHAR *p; - HMODULE dll = NULL; - struct tm when; - __time64_t now; - - if (os_winnt && GetModuleFileName (NULL, path, MAX_DPATH)) { - TCHAR beta[100]; - TCHAR *slash = _tcsrchr (path, '\\'); - _time64 (&now); - when = *_localtime64 (&now); - _tcscpy (path2, path); - if (slash) { - _tcscpy (slash + 1, L"DBGHELP.DLL"); - dll = WIN32_LoadLibrary (path); - } - slash = _tcsrchr (path2, '\\'); - if (slash) - p = slash + 1; - else - p = path2; - beta[0] = 0; - if (WINUAEPUBLICBETA > 0) - _stprintf (beta, L"b%s", WINUAEBETA); - _stprintf (p, L"winuae_%d%d%d%s_%d%02d%02d_%02d%02d%02d.dmp", - UAEMAJOR, UAEMINOR, UAESUBREV, beta, - when.tm_year + 1900, when.tm_mon + 1, when.tm_mday, when.tm_hour, when.tm_min, when.tm_sec); - if (dll == NULL) - dll = WIN32_LoadLibrary (L"DBGHELP.DLL"); - if (dll) { - MINIDUMPWRITEDUMP dump = (MINIDUMPWRITEDUMP)GetProcAddress (dll, "MiniDumpWriteDump"); - if (dump) { - HANDLE f = CreateFile (path2, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (f != INVALID_HANDLE_VALUE) { - flush_log (); - savedump (dump, f, pExceptionPointers); - CloseHandle (f); - if (isfullscreen () <= 0) { - _stprintf (msg, L"Crash detected. MiniDump saved as:\n%s\n", path2); - MessageBox (NULL, msg, L"Crash", MB_OK | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND); + if (lRet == EXCEPTION_CONTINUE_SEARCH) { + TCHAR path[MAX_DPATH]; + TCHAR path2[MAX_DPATH]; + TCHAR msg[1024]; + TCHAR *p; + HMODULE dll = NULL; + struct tm when; + __time64_t now; + + if (os_winnt && GetModuleFileName (NULL, path, MAX_DPATH)) { + TCHAR beta[100]; + TCHAR *slash = _tcsrchr (path, '\\'); + _time64 (&now); + when = *_localtime64 (&now); + _tcscpy (path2, path); + if (slash) { + _tcscpy (slash + 1, L"DBGHELP.DLL"); + dll = WIN32_LoadLibrary (path); + } + slash = _tcsrchr (path2, '\\'); + if (slash) + p = slash + 1; + else + p = path2; + beta[0] = 0; + if (WINUAEPUBLICBETA > 0) + _stprintf (beta, L"b%s", WINUAEBETA); + _stprintf (p, L"winuae_%d%d%d%s_%d%02d%02d_%02d%02d%02d.dmp", + UAEMAJOR, UAEMINOR, UAESUBREV, beta, + when.tm_year + 1900, when.tm_mon + 1, when.tm_mday, when.tm_hour, when.tm_min, when.tm_sec); + if (dll == NULL) + dll = WIN32_LoadLibrary (L"DBGHELP.DLL"); + if (dll) { + MINIDUMPWRITEDUMP dump = (MINIDUMPWRITEDUMP)GetProcAddress (dll, "MiniDumpWriteDump"); + if (dump) { + HANDLE f = CreateFile (path2, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (f != INVALID_HANDLE_VALUE) { + flush_log (); + savedump (dump, f, pExceptionPointers); + CloseHandle (f); + if (isfullscreen () <= 0) { + _stprintf (msg, L"Crash detected. MiniDump saved as:\n%s\n", path2); + MessageBox (NULL, msg, L"Crash", MB_OK | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND); + } + } + } } - } } - } } - } #endif #if 0 HMODULE hFaultRepDll = LoadLibrary (L"FaultRep.dll") ; if (hFaultRepDll) { - pfn_REPORTFAULT pfn = (pfn_REPORTFAULT)GetProcAddress (hFaultRepDll, L"ReportFault"); - if (pfn) { - EFaultRepRetVal rc = pfn (pExceptionPointers, 0); - lRet = EXCEPTION_EXECUTE_HANDLER; - } - FreeLibrary (hFaultRepDll ); + pfn_REPORTFAULT pfn = (pfn_REPORTFAULT)GetProcAddress (hFaultRepDll, L"ReportFault"); + if (pfn) { + EFaultRepRetVal rc = pfn (pExceptionPointers, 0); + lRet = EXCEPTION_EXECUTE_HANDLER; + } + FreeLibrary (hFaultRepDll ); } #endif - return lRet ; + return lRet ; } #endif const static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, - { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } }; +{ 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } }; typedef ULONG (CALLBACK *SHCHANGENOTIFYREGISTER) - (HWND hwnd, - int fSources, - LONG fEvents, - UINT wMsg, - int cEntries, - const SHChangeNotifyEntry *pshcne); + (HWND hwnd, + int fSources, + LONG fEvents, + UINT wMsg, + int cEntries, + const SHChangeNotifyEntry *pshcne); typedef BOOL (CALLBACK *SHCHANGENOTIFYDEREGISTER)(ULONG ulID); void addnotifications (HWND hwnd, int remove, int isgui) { - static ULONG ret; - static HDEVNOTIFY hdn; - static int wtson; - LPITEMIDLIST ppidl; - SHCHANGENOTIFYREGISTER pSHChangeNotifyRegister; - SHCHANGENOTIFYDEREGISTER pSHChangeNotifyDeregister; - - pSHChangeNotifyRegister = (SHCHANGENOTIFYREGISTER)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "SHChangeNotifyRegister"); - pSHChangeNotifyDeregister = (SHCHANGENOTIFYDEREGISTER)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "SHChangeNotifyDeregister"); - - if (remove) { - if (ret > 0 && pSHChangeNotifyDeregister) - pSHChangeNotifyDeregister (ret); - ret = 0; - if (hdn) - UnregisterDeviceNotification (hdn); - hdn = 0; - if (os_winxp && wtson && !isgui) - WTSUnRegisterSessionNotification (hwnd); - wtson = 0; - } else { - DEV_BROADCAST_DEVICEINTERFACE NotificationFilter = { 0 }; - if(pSHChangeNotifyRegister && SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &ppidl) == NOERROR) { - SHChangeNotifyEntry shCNE; - shCNE.pidl = ppidl; - shCNE.fRecursive = TRUE; - ret = pSHChangeNotifyRegister (hwnd, SHCNE_DISKEVENTS, SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED, - WM_USER + 2, 1, &shCNE); - } - NotificationFilter.dbcc_size = - sizeof(DEV_BROADCAST_DEVICEINTERFACE); - NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; - NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_HID; - hdn = RegisterDeviceNotification (hwnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE); - if (os_winxp && !isgui) - wtson = WTSRegisterSessionNotification (hwnd, NOTIFY_FOR_THIS_SESSION); - } + static ULONG ret; + static HDEVNOTIFY hdn; + static int wtson; + LPITEMIDLIST ppidl; + SHCHANGENOTIFYREGISTER pSHChangeNotifyRegister; + SHCHANGENOTIFYDEREGISTER pSHChangeNotifyDeregister; + + pSHChangeNotifyRegister = (SHCHANGENOTIFYREGISTER)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "SHChangeNotifyRegister"); + pSHChangeNotifyDeregister = (SHCHANGENOTIFYDEREGISTER)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "SHChangeNotifyDeregister"); + + if (remove) { + if (ret > 0 && pSHChangeNotifyDeregister) + pSHChangeNotifyDeregister (ret); + ret = 0; + if (hdn) + UnregisterDeviceNotification (hdn); + hdn = 0; + if (os_winxp && wtson && !isgui) + WTSUnRegisterSessionNotification (hwnd); + wtson = 0; + } else { + DEV_BROADCAST_DEVICEINTERFACE NotificationFilter = { 0 }; + if(pSHChangeNotifyRegister && SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &ppidl) == NOERROR) { + SHChangeNotifyEntry shCNE; + shCNE.pidl = ppidl; + shCNE.fRecursive = TRUE; + ret = pSHChangeNotifyRegister (hwnd, SHCNE_DISKEVENTS, SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED, + WM_USER + 2, 1, &shCNE); + } + NotificationFilter.dbcc_size = + sizeof(DEV_BROADCAST_DEVICEINTERFACE); + NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; + NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_HID; + hdn = RegisterDeviceNotification (hwnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE); + if (os_winxp && !isgui) + wtson = WTSRegisterSessionNotification (hwnd, NOTIFY_FOR_THIS_SESSION); + } } void systray (HWND hwnd, int remove) { - NOTIFYICONDATA nid; - BOOL v; + NOTIFYICONDATA nid; + BOOL v; #ifdef RETROPLATFORM - if (rp_isactive ()) - return; + if (rp_isactive ()) + return; #endif - //write_log (L"notif: systray(%x,%d)\n", hwnd, remove); - if (!remove) { - TaskbarRestart = RegisterWindowMessage (L"TaskbarCreated"); - TaskbarRestartHWND = hwnd; - //write_log (L"notif: taskbarrestart = %d\n", TaskbarRestart); - } else { - TaskbarRestart = 0; - hwnd = TaskbarRestartHWND; - } - if (!hwnd) - return; - memset (&nid, 0, sizeof (nid)); - nid.cbSize = sizeof (nid); - nid.hWnd = hwnd; - nid.hIcon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE (IDI_APPICON)); - nid.uFlags = NIF_ICON | NIF_MESSAGE; - nid.uCallbackMessage = WM_USER + 1; - v = Shell_NotifyIcon (remove ? NIM_DELETE : NIM_ADD, &nid); - //write_log (L"notif: Shell_NotifyIcon returned %d\n", v); - if (v) { - if (remove) - TaskbarRestartHWND = NULL; - } else { - DWORD err = GetLastError (); - write_log (L"Notify error code = %x (%d)\n", err, err); - } + //write_log (L"notif: systray(%x,%d)\n", hwnd, remove); + if (!remove) { + TaskbarRestart = RegisterWindowMessage (L"TaskbarCreated"); + TaskbarRestartHWND = hwnd; + //write_log (L"notif: taskbarrestart = %d\n", TaskbarRestart); + } else { + TaskbarRestart = 0; + hwnd = TaskbarRestartHWND; + } + if (!hwnd) + return; + memset (&nid, 0, sizeof (nid)); + nid.cbSize = sizeof (nid); + nid.hWnd = hwnd; + nid.hIcon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE (IDI_APPICON)); + nid.uFlags = NIF_ICON | NIF_MESSAGE; + nid.uCallbackMessage = WM_USER + 1; + v = Shell_NotifyIcon (remove ? NIM_DELETE : NIM_ADD, &nid); + //write_log (L"notif: Shell_NotifyIcon returned %d\n", v); + if (v) { + if (remove) + TaskbarRestartHWND = NULL; + } else { + DWORD err = GetLastError (); + write_log (L"Notify error code = %x (%d)\n", err, err); + } } static void systraymenu (HWND hwnd) { - POINT pt; - HMENU menu, menu2, drvmenu; - int drvs[] = { ID_ST_DF0, ID_ST_DF1, ID_ST_DF2, ID_ST_DF3, -1 }; - int i; - TCHAR text[100]; - - WIN32GUI_LoadUIString (IDS_STMENUNOFLOPPY, text, sizeof (text) / sizeof (TCHAR)); - GetCursorPos (&pt); - menu = LoadMenu (hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDM_SYSTRAY)); - if (!menu) - return; - menu2 = GetSubMenu (menu, 0); - drvmenu = GetSubMenu (menu2, 1); - EnableMenuItem (menu2, ID_ST_HELP, pHtmlHelp ? MF_ENABLED : MF_GRAYED); - i = 0; - while (drvs[i] >= 0) { - TCHAR s[MAX_DPATH]; - if (currprefs.df[i][0]) - _stprintf (s, L"DF%d: [%s]", i, currprefs.df[i]); - else - _stprintf (s, L"DF%d: [%s]", i, text); - ModifyMenu (drvmenu, drvs[i], MF_BYCOMMAND | MF_STRING, drvs[i], s); - EnableMenuItem (menu2, drvs[i], currprefs.dfxtype[i] < 0 ? MF_GRAYED : MF_ENABLED); - i++; - } - if (isfullscreen () <= 0) - SetForegroundWindow (hwnd); - TrackPopupMenu (menu2, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, - pt.x, pt.y, 0, hwnd, NULL); - PostMessage (hwnd, WM_NULL, 0, 0); - DestroyMenu (menu); + POINT pt; + HMENU menu, menu2, drvmenu; + int drvs[] = { ID_ST_DF0, ID_ST_DF1, ID_ST_DF2, ID_ST_DF3, -1 }; + int i; + TCHAR text[100]; + + WIN32GUI_LoadUIString (IDS_STMENUNOFLOPPY, text, sizeof (text) / sizeof (TCHAR)); + GetCursorPos (&pt); + menu = LoadMenu (hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE (IDM_SYSTRAY)); + if (!menu) + return; + menu2 = GetSubMenu (menu, 0); + drvmenu = GetSubMenu (menu2, 1); + EnableMenuItem (menu2, ID_ST_HELP, pHtmlHelp ? MF_ENABLED : MF_GRAYED); + i = 0; + while (drvs[i] >= 0) { + TCHAR s[MAX_DPATH]; + if (currprefs.df[i][0]) + _stprintf (s, L"DF%d: [%s]", i, currprefs.df[i]); + else + _stprintf (s, L"DF%d: [%s]", i, text); + ModifyMenu (drvmenu, drvs[i], MF_BYCOMMAND | MF_STRING, drvs[i], s); + EnableMenuItem (menu2, drvs[i], currprefs.dfxtype[i] < 0 ? MF_GRAYED : MF_ENABLED); + i++; + } + if (isfullscreen () <= 0) + SetForegroundWindow (hwnd); + TrackPopupMenu (menu2, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, + pt.x, pt.y, 0, hwnd, NULL); + PostMessage (hwnd, WM_NULL, 0, 0); + DestroyMenu (menu); } static void LLError(HMODULE m, const TCHAR *s) { - DWORD err; - - if (m) { -// write_log (L"'%s' opened\n", s); - return; - } - err = GetLastError (); - if (err == ERROR_MOD_NOT_FOUND || err == ERROR_DLL_NOT_FOUND) - return; - write_log (L"%s failed to open %d\n", s, err); + DWORD err; + + if (m) { + // write_log (L"'%s' opened\n", s); + return; + } + err = GetLastError (); + if (err == ERROR_MOD_NOT_FOUND || err == ERROR_DLL_NOT_FOUND) + return; + write_log (L"%s failed to open %d\n", s, err); } HMODULE WIN32_LoadLibrary_2 (const TCHAR *name, int expand) { - HMODULE m = NULL; - TCHAR *newname; - DWORD err = -1; + HMODULE m = NULL; + TCHAR *newname; + DWORD err = -1; #ifdef CPU_64_BIT - TCHAR *p; + TCHAR *p; #endif - int round; - - newname = xmalloc ((_tcslen (name) + 1 + 10) * sizeof (TCHAR)); - if (!newname) - return NULL; - for (round = 0; round < 4; round++) { - TCHAR *s; - _tcscpy (newname, name); + int round; + + newname = xmalloc ((_tcslen (name) + 1 + 10) * sizeof (TCHAR)); + if (!newname) + return NULL; + for (round = 0; round < 4; round++) { + TCHAR *s; + _tcscpy (newname, name); #ifdef CPU_64_BIT - switch(round) - { - case 0: - p = strstr (newname,"32"); - if (p) { - p[0] = '6'; - p[1] = '4'; - } - break; - case 1: - p = strchr (newname,'.'); - _tcscpy(p,"_64"); - _tcscat(p, strchr (name,'.')); - break; - case 2: - p = strchr (newname,'.'); - _tcscpy (p,"64"); - _tcscat (p, strchr (name,'.')); - break; - } + switch(round) + { + case 0: + p = strstr (newname,"32"); + if (p) { + p[0] = '6'; + p[1] = '4'; + } + break; + case 1: + p = strchr (newname,'.'); + _tcscpy(p,"_64"); + _tcscat(p, strchr (name,'.')); + break; + case 2: + p = strchr (newname,'.'); + _tcscpy (p,"64"); + _tcscat (p, strchr (name,'.')); + break; + } #endif - s = xmalloc ((_tcslen (start_path_exe) + _tcslen (WIN32_PLUGINDIR) + _tcslen (newname) + 1) * sizeof (TCHAR)); - if (s) { - _stprintf (s, L"%s%s%s", start_path_exe, WIN32_PLUGINDIR, newname); - m = LoadLibrary (s); - LLError(m, s); - if (m) { - xfree (s); - goto end; - } - _stprintf (s, L"%s%s", start_path_exe, newname); - m = LoadLibrary (s); - LLError(m ,s); - if (m) { - xfree (s); - goto end; - } - xfree (s); - } - m = LoadLibrary (newname); - LLError (m, newname); - if (m) - goto end; + s = xmalloc ((_tcslen (start_path_exe) + _tcslen (WIN32_PLUGINDIR) + _tcslen (newname) + 1) * sizeof (TCHAR)); + if (s) { + _stprintf (s, L"%s%s%s", start_path_exe, WIN32_PLUGINDIR, newname); + m = LoadLibrary (s); + LLError(m, s); + if (m) { + xfree (s); + goto end; + } + _stprintf (s, L"%s%s", start_path_exe, newname); + m = LoadLibrary (s); + LLError(m ,s); + if (m) { + xfree (s); + goto end; + } + xfree (s); + } + m = LoadLibrary (newname); + LLError (m, newname); + if (m) + goto end; #ifndef CPU_64_BIT - break; + break; #endif - } + } end: - xfree (newname); - return m; + xfree (newname); + return m; } HMODULE WIN32_LoadLibrary (const TCHAR *name) { - return WIN32_LoadLibrary_2 (name, TRUE); + return WIN32_LoadLibrary_2 (name, TRUE); } HMODULE WIN32_LoadLibrary2 (const TCHAR *name) { - HMODULE m = LoadLibrary (name); - LLError (m, name); - return m; + HMODULE m = LoadLibrary (name); + LLError (m, name); + return m; } int get_guid_target (uae_u8 *out) { - GUID guid; + GUID guid; - if (CoCreateGuid (&guid) != S_OK) - return 0; - out[0] = guid.Data1 >> 24; - out[1] = guid.Data1 >> 16; - out[2] = guid.Data1 >> 8; - out[3] = guid.Data1 >> 0; - out[4] = guid.Data2 >> 8; - out[5] = guid.Data2 >> 0; - out[6] = guid.Data3 >> 8; - out[7] = guid.Data3 >> 0; - memcpy (out + 8, guid.Data4, 8); - return 1; + if (CoCreateGuid (&guid) != S_OK) + return 0; + out[0] = guid.Data1 >> 24; + out[1] = guid.Data1 >> 16; + out[2] = guid.Data1 >> 8; + out[3] = guid.Data1 >> 0; + out[4] = guid.Data2 >> 8; + out[5] = guid.Data2 >> 0; + out[6] = guid.Data3 >> 8; + out[7] = guid.Data3 >> 0; + memcpy (out + 8, guid.Data4, 8); + return 1; } typedef HRESULT (CALLBACK* SHCREATEITEMFROMPARSINGNAME) - (PCWSTR,IBindCtx*,REFIID,void**); // Vista+ only + (PCWSTR,IBindCtx*,REFIID,void**); // Vista+ only void target_addtorecent (const TCHAR *name, int t) { - TCHAR tmp[MAX_DPATH]; - - tmp[0] = 0; - GetFullPathName (name, sizeof tmp / sizeof (TCHAR), tmp, NULL); - if (os_win7) { - SHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName; - SHARDAPPIDINFO shard; - pSHCreateItemFromParsingName = (SHCREATEITEMFROMPARSINGNAME)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "SHCreateItemFromParsingName"); - if (!pSHCreateItemFromParsingName) - return; - shard.pszAppID = WINUAEAPPNAME; - if (SUCCEEDED (pSHCreateItemFromParsingName (tmp, NULL, &IID_IShellItem, &shard.psi))) { - SHAddToRecentDocs (SHARD_APPIDINFO, &shard); - IShellItem_Release (shard.psi); - } - } else { - SHAddToRecentDocs (SHARD_PATH, tmp); - } + TCHAR tmp[MAX_DPATH]; + + tmp[0] = 0; + GetFullPathName (name, sizeof tmp / sizeof (TCHAR), tmp, NULL); + if (os_win7) { + SHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName; + SHARDAPPIDINFO shard; + pSHCreateItemFromParsingName = (SHCREATEITEMFROMPARSINGNAME)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "SHCreateItemFromParsingName"); + if (!pSHCreateItemFromParsingName) + return; + shard.pszAppID = WINUAEAPPNAME; + if (SUCCEEDED (pSHCreateItemFromParsingName (tmp, NULL, &IID_IShellItem, &shard.psi))) { + SHAddToRecentDocs (SHARD_APPIDINFO, &shard); + IShellItem_Release (shard.psi); + } + } else { + SHAddToRecentDocs (SHARD_PATH, tmp); + } } void target_reset (void) { - clipboard_reset (); + clipboard_reset (); } uae_u32 emulib_target_getcpurate (uae_u32 v, uae_u32 *low) { - *low = 0; - if (v == 1) { - LARGE_INTEGER pf; - pf.QuadPart = 0; - QueryPerformanceFrequency (&pf); - *low = pf.LowPart; - return pf.HighPart; - } else if (v == 2) { - LARGE_INTEGER pf; - pf.QuadPart = 0; - QueryPerformanceCounter (&pf); - *low = pf.LowPart; - return pf.HighPart; - } - return 0; + *low = 0; + if (v == 1) { + LARGE_INTEGER pf; + pf.QuadPart = 0; + QueryPerformanceFrequency (&pf); + *low = pf.LowPart; + return pf.HighPart; + } else if (v == 2) { + LARGE_INTEGER pf; + pf.QuadPart = 0; + QueryPerformanceCounter (&pf); + *low = pf.LowPart; + return pf.HighPart; + } + return 0; } void fpux_save (int *v) { - *v = _controlfp (fpucontrol, _MCW_IC | _MCW_RC | _MCW_PC); + *v = _controlfp (fpucontrol, _MCW_IC | _MCW_RC | _MCW_PC); } void fpux_restore (int *v) { - if (v) - _controlfp (*v, _MCW_IC | _MCW_RC | _MCW_PC); - else - _controlfp (fpucontrol, _MCW_IC | _MCW_RC | _MCW_PC); + if (v) + _controlfp (*v, _MCW_IC | _MCW_RC | _MCW_PC); + else + _controlfp (fpucontrol, _MCW_IC | _MCW_RC | _MCW_PC); } typedef BOOL (CALLBACK* SETPROCESSDPIAWARE)(void); @@ -4849,41 +4859,41 @@ typedef BOOL (CALLBACK* CHANGEWINDOWMESSAGEFILTER)(UINT, DWORD); int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { - SETPROCESSDPIAWARE pSetProcessDPIAware; - DWORD_PTR sys_aff; - HANDLE thread; + SETPROCESSDPIAWARE pSetProcessDPIAware; + DWORD_PTR sys_aff; + HANDLE thread; - /* Make sure we do an InitCommonControls() to get some advanced controls */ - InitCommonControls (); + /* Make sure we do an InitCommonControls() to get some advanced controls */ + InitCommonControls (); - original_affinity = 1; - GetProcessAffinityMask (GetCurrentProcess (), &original_affinity, &sys_aff); + original_affinity = 1; + GetProcessAffinityMask (GetCurrentProcess (), &original_affinity, &sys_aff); - thread = GetCurrentThread (); - fpucontrol = _controlfp (0, 0) & (_MCW_IC | _MCW_RC | _MCW_PC); - //original_affinity = SetThreadAffinityMask(thread, 1); + thread = GetCurrentThread (); + fpucontrol = _controlfp (0, 0) & (_MCW_IC | _MCW_RC | _MCW_PC); + //original_affinity = SetThreadAffinityMask(thread, 1); #if 0 #define MSGFLT_ADD 1 - CHANGEWINDOWMESSAGEFILTER pChangeWindowMessageFilter; - pChangeWindowMessageFilter = (CHANGEWINDOWMESSAGEFILTER)GetProcAddress( - GetModuleHandle(L"user32.dll"), L"ChangeWindowMessageFilter"); - if (pChangeWindowMessageFilter) - pChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); + CHANGEWINDOWMESSAGEFILTER pChangeWindowMessageFilter; + pChangeWindowMessageFilter = (CHANGEWINDOWMESSAGEFILTER)GetProcAddress( + GetModuleHandle(L"user32.dll"), L"ChangeWindowMessageFilter"); + if (pChangeWindowMessageFilter) + pChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); #endif - pSetProcessDPIAware = (SETPROCESSDPIAWARE)GetProcAddress ( - GetModuleHandle (L"user32.dll"), "SetProcessDPIAware"); - if (pSetProcessDPIAware) - pSetProcessDPIAware (); - log_open (NULL, 0, 0); - - __try { - WinMain2 (hInstance, hPrevInstance, lpCmdLine, nCmdShow); - } __except(WIN32_ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { - } - //SetThreadAffinityMask(thread, original_affinity); - return FALSE; + pSetProcessDPIAware = (SETPROCESSDPIAWARE)GetProcAddress ( + GetModuleHandle (L"user32.dll"), "SetProcessDPIAware"); + if (pSetProcessDPIAware) + pSetProcessDPIAware (); + log_open (NULL, 0, 0); + + __try { + WinMain2 (hInstance, hPrevInstance, lpCmdLine, nCmdShow); + } __except(WIN32_ExceptionFilter (GetExceptionInformation (), GetExceptionCode ())) { + } + //SetThreadAffinityMask(thread, original_affinity); + return FALSE; } diff --git a/od-win32/win32.h b/od-win32/win32.h index b63aa07b..ca7d7aad 100644 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -17,8 +17,8 @@ #define WINUAEPUBLICBETA 1 -#define WINUAEBETA L"18" -#define WINUAEDATE MAKEBD(2009, 10, 16) +#define WINUAEBETA L"19" +#define WINUAEDATE MAKEBD(2009, 10, 31) #define WINUAEEXTRA L"" #define WINUAEREV L"" @@ -60,8 +60,8 @@ extern void setmouseactive (int active); extern void minimizewindow (void); extern uae_u32 OSDEP_minimize_uae (void); -extern void resumepaused (void); -extern void setpaused (void); +extern void resumepaused (int priority); +extern void setpaused (int priority); void finishjob (void); void updatedisplayarea (void); diff --git a/od-win32/win32_scale2x.c b/od-win32/win32_scale2x.c index 8268eb35..d3e53d2b 100644 --- a/od-win32/win32_scale2x.c +++ b/od-win32/win32_scale2x.c @@ -19,27 +19,27 @@ struct uae_filter uaefilters[] = { - { UAE_FILTER_NULL, 0, 1, L"Null filter", L"null", 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, + { UAE_FILTER_NULL, 0, 1, L"Null filter", L"null", 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, - { UAE_FILTER_DIRECT3D, 0, 1, L"Direct3D", L"direct3d", 1, 0, 0, 0, 0 }, + { UAE_FILTER_DIRECT3D, 0, 1, L"Direct3D", L"direct3d", 1, 0, 0, 0, 0 }, #ifdef OPENGL - { UAE_FILTER_OPENGL, 0, 1, L"OpenGL (unsupported)", L"opengl", 1, 0, 0, 0, 0 }, + { UAE_FILTER_OPENGL, 0, 1, L"OpenGL (unsupported)", L"opengl", 1, 0, 0, 0, 0 }, #endif - { UAE_FILTER_SCALE2X, 0, 2, L"Scale2X", L"scale2x", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, + { UAE_FILTER_SCALE2X, 0, 2, L"Scale2X", L"scale2x", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, - { UAE_FILTER_HQ, 0, 2, L"hq2x/3x/4x", L"hqx", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32 }, + { UAE_FILTER_HQ, 0, 2, L"hq2x/3x/4x", L"hqx", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32 }, - { UAE_FILTER_SUPEREAGLE, 0, 2, L"SuperEagle", L"supereagle", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, + { UAE_FILTER_SUPEREAGLE, 0, 2, L"SuperEagle", L"supereagle", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, - { UAE_FILTER_SUPER2XSAI, 0, 2, L"Super2xSaI", L"super2xsai", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, + { UAE_FILTER_SUPER2XSAI, 0, 2, L"Super2xSaI", L"super2xsai", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, - { UAE_FILTER_2XSAI, 0, 2, L"2xSaI", L"2xsai", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, + { UAE_FILTER_2XSAI, 0, 2, L"2xSaI", L"2xsai", 0, 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_16_32, 0, 0 }, - { UAE_FILTER_PAL, 1, 1, L"PAL", L"pal", 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, + { UAE_FILTER_PAL, 1, 1, L"PAL", L"pal", 0, UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32, 0, 0, 0 }, - { 0 } + { 0 } }; static int filteroffsetx, filteroffsety, filterxmult = 1000, filterymult = 1000; @@ -54,632 +54,632 @@ static int deskw, deskh; void getfilteroffset (int *dx, int *dy, int *mx, int *my) { - *dx = filteroffsetx; - *dy = filteroffsety; - *mx = filterxmult; - *my = filterymult; + *dx = filteroffsetx; + *dy = filteroffsety; + *mx = filterxmult; + *my = filterymult; } static void getinit (void) { - if (isfullscreen ()) { - struct MultiDisplay *md = getdisplay (&currprefs); - - deskw = md->rect.right - md->rect.left; - deskh = md->rect.bottom - md->rect.top; - } else { - deskw = dst_width; - deskh = dst_height; - } + if (isfullscreen ()) { + struct MultiDisplay *md = getdisplay (&currprefs); + + deskw = md->rect.right - md->rect.left; + deskh = md->rect.bottom - md->rect.top; + } else { + deskw = dst_width; + deskh = dst_height; + } } static int vblscale (int v) { - static int o; - int n; - - n = (beamcon0 & 0x80) + maxvpos; - if (n != o) - cleartemp = 1; - o = n; - if (beamcon0 & 0x80) + static int o; + int n; + + n = (beamcon0 & 0x80) + maxvpos; + if (n != o) + cleartemp = 1; + o = n; + if (beamcon0 & 0x80) + return v; + if (currprefs.ntscmode) + v = v * maxvpos / MAXVPOS_NTSC; + else + v = v * maxvpos / MAXVPOS_PAL; return v; - if (currprefs.ntscmode) - v = v * maxvpos / MAXVPOS_NTSC; - else - v = v * maxvpos / MAXVPOS_PAL; - return v; } static int vblscale2 (int v) { - static int o; - int n; - - n = (beamcon0 & 0x80) + maxvpos; - if (n != o) - cleartemp = 1; - o = n; - if (beamcon0 & 0x80) + static int o; + int n; + + n = (beamcon0 & 0x80) + maxvpos; + if (n != o) + cleartemp = 1; + o = n; + if (beamcon0 & 0x80) + return v; + v = v * maxvpos / MAXVPOS_PAL; return v; - v = v * maxvpos / MAXVPOS_PAL; - return v; } static int ispal (void) { - if (beamcon0 & 0x80) - return currprefs.ntscmode == 0; - return maxvpos >= MAXVPOS_NTSC + (MAXVPOS_PAL - MAXVPOS_NTSC) / 2; + if (beamcon0 & 0x80) + return currprefs.ntscmode == 0; + return maxvpos >= MAXVPOS_NTSC + (MAXVPOS_PAL - MAXVPOS_NTSC) / 2; } uae_u8 *getfilterrect1 (RECT *sr, RECT *dr, int dst_depth, int aw, int ah, int scale, int temp_width, int temp_height, uae_u8 *dptr, int pitch) { - int aws, ahs; - - aws = aw * scale; - ahs = ah * scale; - - SetRect (sr, 0, 0, 0, 0); - dr->left = sr->left + (temp_width - aws) /2; - dr->top = sr->top + (temp_height - ahs) / 2; - dptr += dr->left * (dst_depth / 8); - dptr += dr->top * pitch; - return dptr; + int aws, ahs; + + aws = aw * scale; + ahs = ah * scale; + + SetRect (sr, 0, 0, 0, 0); + dr->left = sr->left + (temp_width - aws) /2; + dr->top = sr->top + (temp_height - ahs) / 2; + dptr += dr->left * (dst_depth / 8); + dptr += dr->top * pitch; + return dptr; } static void sizeoffset (RECT *dr, RECT *zr, int w, int h) { - dr->right -= w; - dr->bottom -= h; - OffsetRect (zr, w / 2, h / 2); + dr->right -= w; + dr->bottom -= h; + OffsetRect (zr, w / 2, h / 2); } void getfilterrect2 (RECT *sr, RECT *dr, RECT *zr, int dst_width, int dst_height, int aw, int ah, int scale, int temp_width, int temp_height) { - float srcratio, dstratio; - int aws, ahs, ahs2; - int xs, ys; - float xmult, ymult; - int v; - int extraw, extrah; - int fpuv; - - fpux_save (&fpuv); - - getinit (); - ahs2 = vblscale (ah) * scale; - aws = aw * scale; - ahs = ah * scale; - - extraw = -aws * currprefs.gfx_filter_horiz_zoom / 2000; - extrah = -ahs * currprefs.gfx_filter_vert_zoom / 2000; - - SetRect (sr, 0, 0, dst_width, dst_height); - SetRect (zr, 0, 0, 0, 0); - dr->left = (temp_width - aws) /2; - dr->top = (temp_height - ahs) / 2; - dr->left -= (dst_width - aws) / 2; - dr->top -= (dst_height - ahs) / 2; - dr->right = dr->left + dst_width; - dr->bottom = dr->top + dst_height; - - filteroffsetx = 0; - filteroffsety = 0; - - xmult = currprefs.gfx_filter_horiz_zoom_mult; - ymult = currprefs.gfx_filter_vert_zoom_mult; - - srcratio = 4.0 / 3.0; - if (currprefs.gfx_filter_aspect > 0) { - dstratio = (currprefs.gfx_filter_aspect >> 8) * 1.0 / (currprefs.gfx_filter_aspect & 0xff); - } else if (currprefs.gfx_filter_aspect < 0) { - if (isfullscreen () && deskw > 0 && deskh > 0) - dstratio = 1.0 * deskw / deskh; - else - dstratio = 1.0 * dst_width / dst_height; - } else { - dstratio = srcratio; - } - - if (currprefs.gfx_filter_autoscale) { - int cw, ch, cx, cy, cv; - static int oxmult, oymult; - - filterxmult = 1000 / scale; - filterymult = 1000 / scale; - - cv = get_custom_limits (&cw, &ch, &cx, &cy); - if (cv) { - int diff; - - if (currprefs.gfx_filter_autoscale == 2 && isfullscreen () == 0) { - int ww; - static int lastresize = 0; - static int lastdelay = 1; - static int ocw, och, ocx, ocy, lcw, lch, lcx, lcy; - int useold = 0; - - lastresize--; - if (lastresize > 0) { - if (cw != lcw || ch != lch || cx != lcx || cy != lcy) - lastresize = 50; - useold = 1; - } else if (lastdelay == 0) { - lastdelay = 2; - useold = 1; - } else if (lastdelay > 0) { - lastdelay--; - useold = 1; - if (lastdelay == 0) { - lastdelay = -1; - useold = 0; - } - } - - lcw = cw; - lch = ch; - lcx = cx; - lcy = cy; - if (useold) { - cw = ocw; - ch = och; - cx = ocx; - cy = ocy; - } else { - ocw = cw; - och = ch; - ocx = cx; - ocy = cy; - lastresize = 50; - lastdelay = 0; - } + float srcratio, dstratio; + int aws, ahs, ahs2; + int xs, ys; + float xmult, ymult; + int v; + int extraw, extrah; + int fpuv; + + fpux_save (&fpuv); + + getinit (); + ahs2 = vblscale (ah) * scale; + aws = aw * scale; + ahs = ah * scale; + + extraw = -aws * currprefs.gfx_filter_horiz_zoom / 2000; + extrah = -ahs * currprefs.gfx_filter_vert_zoom / 2000; + + SetRect (sr, 0, 0, dst_width, dst_height); + SetRect (zr, 0, 0, 0, 0); + dr->left = (temp_width - aws) /2; + dr->top = (temp_height - ahs) / 2; + dr->left -= (dst_width - aws) / 2; + dr->top -= (dst_height - ahs) / 2; + dr->right = dr->left + dst_width; + dr->bottom = dr->top + dst_height; + + filteroffsetx = 0; + filteroffsety = 0; + + xmult = currprefs.gfx_filter_horiz_zoom_mult; + ymult = currprefs.gfx_filter_vert_zoom_mult; + + srcratio = 4.0 / 3.0; + if (currprefs.gfx_filter_aspect > 0) { + dstratio = (currprefs.gfx_filter_aspect >> 8) * 1.0 / (currprefs.gfx_filter_aspect & 0xff); + } else if (currprefs.gfx_filter_aspect < 0) { + if (isfullscreen () && deskw > 0 && deskh > 0) + dstratio = 1.0 * deskw / deskh; + else + dstratio = 1.0 * dst_width / dst_height; + } else { + dstratio = srcratio; + } - SetRect (sr, 0, 0, cw * scale, ch * scale); - dr->left = (temp_width - aws) /2; - dr->top = (temp_height - ahs) / 2; - dr->right = dr->left + cw * scale; - dr->bottom = dr->top + ch * scale; - OffsetRect (zr, cx * scale, cy * scale); - ww = dr->right - dr->left; - changed_prefs.gfx_size_win.width = ww; - changed_prefs.gfx_size_win.height = dr->bottom - dr->top; - fixup_prefs_dimensions (&changed_prefs); - OffsetRect (zr, -(changed_prefs.gfx_size_win.width - ww + 1) / 2, 0); - filteroffsetx = -zr->left / scale; - filteroffsety = -zr->top / scale; - goto end; - } - - dr->left = (temp_width - aws) /2; - dr->top = (temp_height - ahs) / 2; - dr->right = dr->left + dst_width * scale; - dr->bottom = dr->top + dst_height * scale; - - OffsetRect (zr, cx * scale, cy * scale); - - sizeoffset (dr, zr, extraw, extrah); - - dr->right -= (dst_width - cw) * scale; - dr->bottom -= (dst_height - ch) * scale; - - filteroffsetx = -zr->left / scale; - filteroffsety = -zr->top / scale; - - if (currprefs.gfx_filter_keep_aspect || currprefs.gfx_filter_aspect != 0) { - int diffx = dr->right - dr->left; - int diffy = dr->bottom - dr->top; - float xmult = 1.0; - float ymult = 1.0; - - if (currprefs.gfx_filter_keep_aspect) { - dstratio = dstratio * (aws * 1.0 / ahs2) / (cw * 1.0 / ch); - if (currprefs.ntscmode) { - dstratio = dstratio * 1.21; - if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) - dstratio = dstratio * 0.93; - else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) - dstratio = dstratio * 0.98; - } else { - if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) - dstratio = dstratio * 0.95; - else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) - dstratio = dstratio * 0.95; - } + if (currprefs.gfx_filter_autoscale) { + int cw, ch, cx, cy, cv; + static int oxmult, oymult; + + filterxmult = 1000 / scale; + filterymult = 1000 / scale; + + cv = get_custom_limits (&cw, &ch, &cx, &cy); + if (cv) { + int diff; + + if (currprefs.gfx_filter_autoscale == 2 && isfullscreen () == 0) { + int ww; + static int lastresize = 0; + static int lastdelay = 1; + static int ocw, och, ocx, ocy, lcw, lch, lcx, lcy; + int useold = 0; + + lastresize--; + if (lastresize > 0) { + if (cw != lcw || ch != lch || cx != lcx || cy != lcy) + lastresize = 50; + useold = 1; + } else if (lastdelay == 0) { + lastdelay = 2; + useold = 1; + } else if (lastdelay > 0) { + lastdelay--; + useold = 1; + if (lastdelay == 0) { + lastdelay = -1; + useold = 0; + } + } + + lcw = cw; + lch = ch; + lcx = cx; + lcy = cy; + if (useold) { + cw = ocw; + ch = och; + cx = ocx; + cy = ocy; + } else { + ocw = cw; + och = ch; + ocx = cx; + ocy = cy; + lastresize = 50; + lastdelay = 0; + } + + SetRect (sr, 0, 0, cw * scale, ch * scale); + dr->left = (temp_width - aws) /2; + dr->top = (temp_height - ahs) / 2; + dr->right = dr->left + cw * scale; + dr->bottom = dr->top + ch * scale; + OffsetRect (zr, cx * scale, cy * scale); + ww = dr->right - dr->left; + changed_prefs.gfx_size_win.width = ww; + changed_prefs.gfx_size_win.height = dr->bottom - dr->top; + fixup_prefs_dimensions (&changed_prefs); + OffsetRect (zr, -(changed_prefs.gfx_size_win.width - ww + 1) / 2, 0); + filteroffsetx = -zr->left / scale; + filteroffsety = -zr->top / scale; + goto end; + } + + dr->left = (temp_width - aws) /2; + dr->top = (temp_height - ahs) / 2; + dr->right = dr->left + dst_width * scale; + dr->bottom = dr->top + dst_height * scale; + + OffsetRect (zr, cx * scale, cy * scale); + + sizeoffset (dr, zr, extraw, extrah); + + dr->right -= (dst_width - cw) * scale; + dr->bottom -= (dst_height - ch) * scale; + + filteroffsetx = -zr->left / scale; + filteroffsety = -zr->top / scale; + + if (currprefs.gfx_filter_keep_aspect || currprefs.gfx_filter_aspect != 0) { + int diffx = dr->right - dr->left; + int diffy = dr->bottom - dr->top; + float xmult = 1.0; + float ymult = 1.0; + + if (currprefs.gfx_filter_keep_aspect) { + dstratio = dstratio * (aws * 1.0 / ahs2) / (cw * 1.0 / ch); + if (currprefs.ntscmode) { + dstratio = dstratio * 1.21; + if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) + dstratio = dstratio * 0.93; + else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) + dstratio = dstratio * 0.98; + } else { + if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) + dstratio = dstratio * 0.95; + else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) + dstratio = dstratio * 0.95; + } + } + + if (srcratio > dstratio) { + ymult = ymult * srcratio / dstratio; + } else { + xmult = xmult * dstratio / srcratio; + } + + diff = diffx - diffx * xmult; + sizeoffset (dr, zr, diff, 0); + filteroffsetx += diff / 2; + + diff = diffy - diffy * ymult; + sizeoffset (dr, zr, 0, diff); + filteroffsety += diff / 2; + } + + diff = dr->right - dr->left; + filterxmult = diff * 1000 / (dst_width * scale); + diff = dr->bottom - dr->top; + filterymult = diff * 1000 / (dst_height * scale); + goto end; } + } - if (srcratio > dstratio) { - ymult = ymult * srcratio / dstratio; - } else { - xmult = xmult * dstratio / srcratio; - } + if (!currprefs.gfx_filter_horiz_zoom_mult && !currprefs.gfx_filter_vert_zoom_mult) { - diff = diffx - diffx * xmult; - sizeoffset (dr, zr, diff, 0); - filteroffsetx += diff / 2; + sizeoffset (dr, zr, extraw, extrah); - diff = diffy - diffy * ymult; - sizeoffset (dr, zr, 0, diff); - filteroffsety += diff / 2; - } + if (currprefs.gfx_filter_keep_aspect) { + float xm, ym, m; - diff = dr->right - dr->left; - filterxmult = diff * 1000 / (dst_width * scale); - diff = dr->bottom - dr->top; - filterymult = diff * 1000 / (dst_height * scale); - goto end; - } - } - - if (!currprefs.gfx_filter_horiz_zoom_mult && !currprefs.gfx_filter_vert_zoom_mult) { + xm = 1.0 * aws / dst_width; + ym = 1.0 * ahs / dst_height; + if (xm < ym) + xm = ym; + else + ym = xm; + xmult = ymult = xm * 1000.0; - sizeoffset (dr, zr, extraw, extrah); + m = (aws * 1.0 / dst_width) / (ahs * 1.0 / dst_height); + dstratio = dstratio * m; + } - if (currprefs.gfx_filter_keep_aspect) { - float xm, ym, m; + } - xm = 1.0 * aws / dst_width; - ym = 1.0 * ahs / dst_height; - if (xm < ym) - xm = ym; - else - ym = xm; - xmult = ymult = xm * 1000.0; + if (currprefs.ntscmode) { + if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) + dstratio = dstratio * 0.93; + else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) + dstratio = dstratio * 0.98; + } else { + if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) + dstratio = dstratio * 0.95; + else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) + dstratio = dstratio * 0.95; + } - m = (aws * 1.0 / dst_width) / (ahs * 1.0 / dst_height); - dstratio = dstratio * m; + if (srcratio > dstratio) { + ymult = ymult * srcratio / dstratio; + } else { + xmult = xmult * dstratio / srcratio; } - } - - if (currprefs.ntscmode) { - if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) - dstratio = dstratio * 0.93; - else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) - dstratio = dstratio * 0.98; - } else { - if (currprefs.gfx_filter_keep_aspect == 2 && ispal ()) - dstratio = dstratio * 0.95; - else if (currprefs.gfx_filter_keep_aspect == 1 && !ispal ()) - dstratio = dstratio * 0.95; - } - - if (srcratio > dstratio) { - ymult = ymult * srcratio / dstratio; - } else { - xmult = xmult * dstratio / srcratio; - } - - if (xmult <= 0.01) - xmult = aws * 1000 / dst_width; - else - xmult = xmult + xmult * currprefs.gfx_filter_horiz_zoom / 2000; - if (ymult <= 0.01) - ymult = ahs * 1000 / dst_height; - else - ymult = ymult + ymult * currprefs.gfx_filter_vert_zoom / 2000; - - if (!currprefs.gfx_filter_horiz_zoom_mult && !currprefs.gfx_filter_vert_zoom_mult) { - if (currprefs.ntscmode) { - int v = vblscale2 (ahs); - ymult /= 1.21; - OffsetRect (dr, 0, (v - ahs2) / 2); + if (xmult <= 0.01) + xmult = aws * 1000 / dst_width; + else + xmult = xmult + xmult * currprefs.gfx_filter_horiz_zoom / 2000; + if (ymult <= 0.01) + ymult = ahs * 1000 / dst_height; + else + ymult = ymult + ymult * currprefs.gfx_filter_vert_zoom / 2000; + + if (!currprefs.gfx_filter_horiz_zoom_mult && !currprefs.gfx_filter_vert_zoom_mult) { + if (currprefs.ntscmode) { + int v = vblscale2 (ahs); + ymult /= 1.21; + OffsetRect (dr, 0, (v - ahs2) / 2); + } } - } - ymult = vblscale (ymult); - OffsetRect (dr, 0, (ahs2 - ahs) / 2); + ymult = vblscale (ymult); + OffsetRect (dr, 0, (ahs2 - ahs) / 2); - v = currprefs.gfx_filter ? currprefs.gfx_filter_horiz_offset : 0; - OffsetRect (zr, (int)(-v * aws / 1000.0), 0); - v = currprefs.gfx_filter ? currprefs.gfx_filter_vert_offset : 0; - OffsetRect (zr, 0, (int)(-v * ahs / 1000.0)); + v = currprefs.gfx_filter ? currprefs.gfx_filter_horiz_offset : 0; + OffsetRect (zr, (int)(-v * aws / 1000.0), 0); + v = currprefs.gfx_filter ? currprefs.gfx_filter_vert_offset : 0; + OffsetRect (zr, 0, (int)(-v * ahs / 1000.0)); - xs = dst_width - dst_width * xmult / 1000; - ys = dst_height - dst_height * ymult / 1000; - sizeoffset (dr, zr, xs, ys); + xs = dst_width - dst_width * xmult / 1000; + ys = dst_height - dst_height * ymult / 1000; + sizeoffset (dr, zr, xs, ys); - filterxmult = xmult; - filterymult = ymult; - filteroffsetx += (dst_width - aw * 1000 / filterxmult) / 2; - filteroffsety += (dst_height - ah * 1000 / filterymult) / 2; + filterxmult = xmult; + filterymult = ymult; + filteroffsetx += (dst_width - aw * 1000 / filterxmult) / 2; + filteroffsety += (dst_height - ah * 1000 / filterymult) / 2; end: - fpux_restore (&fpuv); + fpux_restore (&fpuv); } static void statusline (void) { - DDSURFACEDESC2 desc; - RECT sr, dr; - int y; - int lx, ly, sx; - - if (!(currprefs.leds_on_screen & STATUSLINE_CHIPSET) || !tempsurf) - return; - lx = dst_width; - ly = dst_height; - sx = lx; - if (sx > dst_width) - sx = dst_width; - SetRect (&sr, 0, 0, sx, TD_TOTAL_HEIGHT); - SetRect (&dr, lx - sx, ly - TD_TOTAL_HEIGHT, lx, ly); - DirectDraw_BlitRect (tempsurf, &sr, NULL, &dr); - if (locksurface (tempsurf, &desc)) { - for (y = 0; y < TD_TOTAL_HEIGHT; y++) { - uae_u8 *buf = (uae_u8*)desc.lpSurface + y * desc.lPitch; - draw_status_line_single (buf, dst_depth / 8, y, sx, rc, gc, bc, NULL); + DDSURFACEDESC2 desc; + RECT sr, dr; + int y; + int lx, ly, sx; + + if (!(currprefs.leds_on_screen & STATUSLINE_CHIPSET) || !tempsurf) + return; + lx = dst_width; + ly = dst_height; + sx = lx; + if (sx > dst_width) + sx = dst_width; + SetRect (&sr, 0, 0, sx, TD_TOTAL_HEIGHT); + SetRect (&dr, lx - sx, ly - TD_TOTAL_HEIGHT, lx, ly); + DirectDraw_BlitRect (tempsurf, &sr, NULL, &dr); + if (locksurface (tempsurf, &desc)) { + for (y = 0; y < TD_TOTAL_HEIGHT; y++) { + uae_u8 *buf = (uae_u8*)desc.lpSurface + y * desc.lPitch; + draw_status_line_single (buf, dst_depth / 8, y, sx, rc, gc, bc, NULL); + } + unlocksurface (tempsurf); + DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); } - unlocksurface (tempsurf); - DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); - } } void S2X_configure (int rb, int gb, int bb, int rs, int gs, int bs) { - Init_2xSaI (rb, gb, bb, rs, gs, bs); - hq_init (rb, gb, bb, rs, gs, bs); - PAL_init (); - bufmem_ptr = 0; + Init_2xSaI (rb, gb, bb, rs, gs, bs); + hq_init (rb, gb, bb, rs, gs, bs); + PAL_init (); + bufmem_ptr = 0; } void S2X_free (void) { - changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen & ~STATUSLINE_TARGET; - - freesurface (tempsurf); - tempsurf = 0; - xfree (tempsurf2); - tempsurf2 = 0; - xfree (tempsurf3); - tempsurf3 = 0; - filteroffsetx = 0; - filteroffsety = 0; - filterxmult = 1000; - filterymult = 1000; + changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen & ~STATUSLINE_TARGET; + + freesurface (tempsurf); + tempsurf = 0; + xfree (tempsurf2); + tempsurf2 = 0; + xfree (tempsurf3); + tempsurf3 = 0; + filteroffsetx = 0; + filteroffsety = 0; + filterxmult = 1000; + filterymult = 1000; } void S2X_init (int dw, int dh, int aw, int ah, int mult, int ad, int dd) { - int flags = 0; - int res_shift; - - S2X_free (); - changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen | STATUSLINE_TARGET; - - if (dd == 32) - alloc_colors_rgb (8, 8, 8, 16, 8, 0, 0, 0, 0, 0, rc, gc, bc); - else - alloc_colors_rgb (5, 6, 5, 11, 5, 0, 0, 0, 0, 0, rc, gc, bc); - - - if (!currprefs.gfx_filter || !usedfilter) { - usedfilter = &uaefilters[0]; - mult = 1; - } else if (mult) { - flags = usedfilter->x[mult]; - if ((ad == 16 && !(flags & UAE_FILTER_MODE_16)) || (ad == 32 && !(flags & UAE_FILTER_MODE_32))) { - usedfilter = &uaefilters[0]; - mult = 1; - changed_prefs.gfx_filter = usedfilter->type; + int flags = 0; + int res_shift; + + S2X_free (); + changed_prefs.leds_on_screen = currprefs.leds_on_screen = currprefs.leds_on_screen | STATUSLINE_TARGET; + + if (dd == 32) + alloc_colors_rgb (8, 8, 8, 16, 8, 0, 0, 0, 0, 0, rc, gc, bc); + else + alloc_colors_rgb (5, 6, 5, 11, 5, 0, 0, 0, 0, 0, rc, gc, bc); + + + if (!currprefs.gfx_filter || !usedfilter) { + usedfilter = &uaefilters[0]; + mult = 1; + } else if (mult) { + flags = usedfilter->x[mult]; + if ((ad == 16 && !(flags & UAE_FILTER_MODE_16)) || (ad == 32 && !(flags & UAE_FILTER_MODE_32))) { + usedfilter = &uaefilters[0]; + mult = 1; + changed_prefs.gfx_filter = usedfilter->type; + } } - } - - res_shift = RES_MAX - currprefs.gfx_resolution; - if (currprefs.gfx_xcenter_size > 0 && (currprefs.gfx_xcenter_size >> res_shift) < aw) - aw = currprefs.gfx_xcenter_size >> res_shift; - res_shift = currprefs.gfx_linedbl ? 0 : 1; - if (currprefs.gfx_ycenter_size > 0 && (currprefs.gfx_ycenter_size >> res_shift) < ah) - ah = currprefs.gfx_ycenter_size >> res_shift; - - dst_width = dw; - dst_height = dh; - dst_depth = dd; - amiga_width = aw; - amiga_height = ah; - amiga_depth = ad; - scale = mult; - - temp_width = dst_width * 3; - if (temp_width > dxcaps.maxwidth) - temp_width = dxcaps.maxwidth; - temp_height = dst_height * 3; - if (temp_height > dxcaps.maxheight) - temp_height = dxcaps.maxheight; - if (temp_width < dst_width) - temp_width = dst_width; - if (temp_height < dst_height) - temp_height = dst_height; - - if (usedfilter->type == UAE_FILTER_HQ) { - int w = amiga_width > dst_width ? amiga_width : dst_width; - int h = amiga_height > dst_height ? amiga_height : dst_height; - tempsurf2 = xmalloc (w * h * (amiga_depth / 8) * ((scale + 1) / 2)); - tempsurf3 = xmalloc (w * h *(dst_depth / 8) * 4 * scale); - tempsurf = allocsystemsurface (temp_width, temp_height); - } else { - tempsurf = allocsurface (temp_width, temp_height); - } - if (!tempsurf) - write_log (L"DDRAW: failed to create temp surface (%dx%d)\n", temp_width, temp_height); + + res_shift = RES_MAX - currprefs.gfx_resolution; + if (currprefs.gfx_xcenter_size > 0 && (currprefs.gfx_xcenter_size >> res_shift) < aw) + aw = currprefs.gfx_xcenter_size >> res_shift; + res_shift = currprefs.gfx_linedbl ? 0 : 1; + if (currprefs.gfx_ycenter_size > 0 && (currprefs.gfx_ycenter_size >> res_shift) < ah) + ah = currprefs.gfx_ycenter_size >> res_shift; + + dst_width = dw; + dst_height = dh; + dst_depth = dd; + amiga_width = aw; + amiga_height = ah; + amiga_depth = ad; + scale = mult; + + temp_width = dst_width * 3; + if (temp_width > dxcaps.maxwidth) + temp_width = dxcaps.maxwidth; + temp_height = dst_height * 3; + if (temp_height > dxcaps.maxheight) + temp_height = dxcaps.maxheight; + if (temp_width < dst_width) + temp_width = dst_width; + if (temp_height < dst_height) + temp_height = dst_height; + + if (usedfilter->type == UAE_FILTER_HQ) { + int w = amiga_width > dst_width ? amiga_width : dst_width; + int h = amiga_height > dst_height ? amiga_height : dst_height; + tempsurf2 = xmalloc (w * h * (amiga_depth / 8) * ((scale + 1) / 2)); + tempsurf3 = xmalloc (w * h *(dst_depth / 8) * 4 * scale); + tempsurf = allocsystemsurface (temp_width, temp_height); + } else { + tempsurf = allocsurface (temp_width, temp_height); + } + if (!tempsurf) + write_log (L"DDRAW: failed to create temp surface (%dx%d)\n", temp_width, temp_height); } void S2X_render (void) { - int aw, ah, aws, ahs; - uae_u8 *dptr, *enddptr, *sptr, *endsptr; - int ok = 0; - RECT sr, dr, zr; - DDSURFACEDESC2 desc; - DWORD pitch; - - aw = amiga_width; - ah = amiga_height; - aws = aw * scale; - ahs = ah * scale; - - if (ah < 16) - return; - if (aw < 16) - return; - if (tempsurf == NULL) - return; - - sptr = gfxvidinfo.bufmem; - endsptr = gfxvidinfo.bufmemend; - bufmem_ptr = sptr; - - if (cleartemp) { - clearsurface (tempsurf); - cleartemp = 0; - } - if (!locksurface (tempsurf, &desc)) - return; - pitch = desc.lPitch; - dptr = (uae_u8*)desc.lpSurface; - enddptr = dptr + pitch * temp_height; - dptr = getfilterrect1 (&sr, &dr, dst_depth, aw, ah, scale, temp_width, temp_height, dptr, pitch); - - if (!dptr) /* weird things can happen */ - goto end; - if (dptr < (uae_u8*)desc.lpSurface) - goto endfail; - - if (usedfilter->type == UAE_FILTER_SCALE2X ) { /* 16+32/2X */ - - if (amiga_depth == 16 && dst_depth == 16) { - AdMame2x (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } else if (amiga_depth == 32 && dst_depth == 32) { - AdMame2x32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; + int aw, ah, aws, ahs; + uae_u8 *dptr, *enddptr, *sptr, *endsptr; + int ok = 0; + RECT sr, dr, zr; + DDSURFACEDESC2 desc; + DWORD pitch; + + aw = amiga_width; + ah = amiga_height; + aws = aw * scale; + ahs = ah * scale; + + if (ah < 16) + return; + if (aw < 16) + return; + if (tempsurf == NULL) + return; + + sptr = gfxvidinfo.bufmem; + endsptr = gfxvidinfo.bufmemend; + bufmem_ptr = sptr; + + if (cleartemp) { + clearsurface (tempsurf); + cleartemp = 0; } + if (!locksurface (tempsurf, &desc)) + return; + pitch = desc.lPitch; + dptr = (uae_u8*)desc.lpSurface; + enddptr = dptr + pitch * temp_height; + dptr = getfilterrect1 (&sr, &dr, dst_depth, aw, ah, scale, temp_width, temp_height, dptr, pitch); + + if (!dptr) /* weird things can happen */ + goto end; + if (dptr < (uae_u8*)desc.lpSurface) + goto endfail; - } else if (usedfilter->type == UAE_FILTER_HQ) { /* 32/2X+3X+4X */ - - if (tempsurf2 && scale >= 2 && scale <= 4) { - /* Aaaaaaaarghhhghgh.. */ - uae_u8 *sptr2 = tempsurf3; - uae_u8 *dptr2 = tempsurf2; - int i; - for (i = 0; i < ah; i++) { - int w = aw * (amiga_depth / 8); - memcpy (dptr2, sptr, w); - dptr2 += w; - sptr += gfxvidinfo.rowbytes; - } - if (amiga_depth == 16 && dst_depth == 32) { - if (scale == 2) - hq2x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); - else if (scale == 3) - hq3x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); - else if (scale == 4) - hq4x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); - ok = 1; - } else if (amiga_depth == 16 && dst_depth == 16) { - if (scale == 2) - hq2x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); - else if (scale == 3) - hq3x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); - else if (scale == 4) - hq4x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); - ok = 1; - } - for (i = 0; i < ah * scale; i++) { - int w = aw * scale * (dst_depth / 8); - if (dptr + w > enddptr) - break; - memcpy (dptr, sptr2, w); - sptr2 += w; - dptr += pitch; - } - } + if (usedfilter->type == UAE_FILTER_SCALE2X ) { /* 16+32/2X */ - } else if (usedfilter->type == UAE_FILTER_SUPEREAGLE) { /* 16/32/2X */ + if (amiga_depth == 16 && dst_depth == 16) { + AdMame2x (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } else if (amiga_depth == 32 && dst_depth == 32) { + AdMame2x32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } - if (scale == 2 && amiga_depth == 16) { - if (dst_depth == 16) { - SuperEagle_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } else if (dst_depth == 32) { - SuperEagle_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } - } + } else if (usedfilter->type == UAE_FILTER_HQ) { /* 32/2X+3X+4X */ + + if (tempsurf2 && scale >= 2 && scale <= 4) { + /* Aaaaaaaarghhhghgh.. */ + uae_u8 *sptr2 = tempsurf3; + uae_u8 *dptr2 = tempsurf2; + int i; + for (i = 0; i < ah; i++) { + int w = aw * (amiga_depth / 8); + memcpy (dptr2, sptr, w); + dptr2 += w; + sptr += gfxvidinfo.rowbytes; + } + if (amiga_depth == 16 && dst_depth == 32) { + if (scale == 2) + hq2x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); + else if (scale == 3) + hq3x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); + else if (scale == 4) + hq4x_32 (tempsurf2, tempsurf3, aw, ah, aws * 4); + ok = 1; + } else if (amiga_depth == 16 && dst_depth == 16) { + if (scale == 2) + hq2x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); + else if (scale == 3) + hq3x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); + else if (scale == 4) + hq4x_16 (tempsurf2, tempsurf3, aw, ah, aws * 2); + ok = 1; + } + for (i = 0; i < ah * scale; i++) { + int w = aw * scale * (dst_depth / 8); + if (dptr + w > enddptr) + break; + memcpy (dptr, sptr2, w); + sptr2 += w; + dptr += pitch; + } + } - } else if (usedfilter->type == UAE_FILTER_SUPER2XSAI) { /* 16/32/2X */ + } else if (usedfilter->type == UAE_FILTER_SUPEREAGLE) { /* 16/32/2X */ - if (scale == 2 && amiga_depth == 16) { - if (dst_depth == 16) { - Super2xSaI_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } else if (dst_depth == 32) { - Super2xSaI_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } - } + if (scale == 2 && amiga_depth == 16) { + if (dst_depth == 16) { + SuperEagle_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } else if (dst_depth == 32) { + SuperEagle_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } + } - } else if (usedfilter->type == UAE_FILTER_2XSAI) { /* 16/32/2X */ + } else if (usedfilter->type == UAE_FILTER_SUPER2XSAI) { /* 16/32/2X */ - if (scale == 2 && amiga_depth == 16) { - if (dst_depth == 16) { - _2xSaI_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } else if (dst_depth == 32) { - _2xSaI_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); - ok = 1; - } - } + if (scale == 2 && amiga_depth == 16) { + if (dst_depth == 16) { + Super2xSaI_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } else if (dst_depth == 32) { + Super2xSaI_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } + } - } else if (usedfilter->type == UAE_FILTER_PAL) { /* 16/32/1X */ + } else if (usedfilter->type == UAE_FILTER_2XSAI) { /* 16/32/2X */ - if (amiga_depth == 32 && dst_depth == 32) { - PAL_1x1_32 ((uae_u32*)sptr, gfxvidinfo.rowbytes, (uae_u32*)dptr, pitch, aw, ah); - ok = 1; - } else if (amiga_depth == 16 && dst_depth == 16) { - PAL_1x1_16 ((uae_u16*)sptr, gfxvidinfo.rowbytes, (uae_u16*)dptr, pitch, aw, ah); - ok = 1; - } + if (scale == 2 && amiga_depth == 16) { + if (dst_depth == 16) { + _2xSaI_16 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } else if (dst_depth == 32) { + _2xSaI_32 (sptr, gfxvidinfo.rowbytes, dptr, pitch, aw, ah); + ok = 1; + } + } - } else { /* null */ + } else if (usedfilter->type == UAE_FILTER_PAL) { /* 16/32/1X */ - if (amiga_depth == dst_depth) { - int y; - for (y = 0; y < ah; y++) { - memcpy (dptr, sptr, aw * dst_depth / 8); - sptr += gfxvidinfo.rowbytes; - dptr += pitch; - } - } - ok = 1; + if (amiga_depth == 32 && dst_depth == 32) { + PAL_1x1_32 ((uae_u32*)sptr, gfxvidinfo.rowbytes, (uae_u32*)dptr, pitch, aw, ah); + ok = 1; + } else if (amiga_depth == 16 && dst_depth == 16) { + PAL_1x1_16 ((uae_u16*)sptr, gfxvidinfo.rowbytes, (uae_u16*)dptr, pitch, aw, ah); + ok = 1; + } - } + } else { /* null */ + + if (amiga_depth == dst_depth) { + int y; + for (y = 0; y < ah; y++) { + memcpy (dptr, sptr, aw * dst_depth / 8); + sptr += gfxvidinfo.rowbytes; + dptr += pitch; + } + } + ok = 1; + + } endfail: - if (ok == 0 && currprefs.gfx_filter) { - usedfilter = &uaefilters[0]; - changed_prefs.gfx_filter = usedfilter->type; - } + if (ok == 0 && currprefs.gfx_filter) { + usedfilter = &uaefilters[0]; + changed_prefs.gfx_filter = usedfilter->type; + } end: - unlocksurface (tempsurf); - - getfilterrect2 (&dr, &sr, &zr, dst_width, dst_height, aw, ah, scale, temp_width, temp_height); - //write_log (L"(%d %d %d %d) - (%d %d %d %d) (%d %d)\n", dr.left, dr.top, dr.right, dr.bottom, sr.left, sr.top, sr.right, sr.bottom, zr.left, zr.top); - OffsetRect (&sr, zr.left, zr.top); - if (sr.left >= 0 && sr.top >= 0 && sr.right < temp_width && sr.bottom < temp_height) { - if (sr.left < sr.right && sr.top < sr.bottom) - DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); - } - statusline (); + unlocksurface (tempsurf); + + getfilterrect2 (&dr, &sr, &zr, dst_width, dst_height, aw, ah, scale, temp_width, temp_height); + //write_log (L"(%d %d %d %d) - (%d %d %d %d) (%d %d)\n", dr.left, dr.top, dr.right, dr.bottom, sr.left, sr.top, sr.right, sr.bottom, zr.left, zr.top); + OffsetRect (&sr, zr.left, zr.top); + if (sr.left >= 0 && sr.top >= 0 && sr.right < temp_width && sr.bottom < temp_height) { + if (sr.left < sr.right && sr.top < sr.bottom) + DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); + } + statusline (); } void S2X_refresh (void) { - clearsurface (NULL); - S2X_render (); + clearsurface (NULL); + S2X_render (); } #endif diff --git a/od-win32/win32_uaenet.c b/od-win32/win32_uaenet.c index 6af600cf..e59d9f88 100644 --- a/od-win32/win32_uaenet.c +++ b/od-win32/win32_uaenet.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 uaenet emulation - * - * Copyright 2007 Toni Wilen - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 uaenet emulation +* +* Copyright 2007 Toni Wilen +*/ #include "sysconfig.h" @@ -31,401 +31,401 @@ static int enumerated; struct uaenetdatawin32 { - HANDLE evttw; - void *readdata, *writedata; - - uae_sem_t change_sem; - - volatile int threadactiver; - uae_thread_id tidr; - uae_sem_t sync_semr; - volatile int threadactivew; - uae_thread_id tidw; - uae_sem_t sync_semw; - - void *user; - struct netdriverdata *tc; - uae_u8 *readbuffer; - uae_u8 *writebuffer; - int mtu; - - char errbuf[PCAP_ERRBUF_SIZE]; - pcap_t *fp; - uaenet_gotfunc *gotfunc; - uaenet_getfunc *getfunc; + HANDLE evttw; + void *readdata, *writedata; + + uae_sem_t change_sem; + + volatile int threadactiver; + uae_thread_id tidr; + uae_sem_t sync_semr; + volatile int threadactivew; + uae_thread_id tidw; + uae_sem_t sync_semw; + + void *user; + struct netdriverdata *tc; + uae_u8 *readbuffer; + uae_u8 *writebuffer; + int mtu; + + char errbuf[PCAP_ERRBUF_SIZE]; + pcap_t *fp; + uaenet_gotfunc *gotfunc; + uaenet_getfunc *getfunc; }; int uaenet_getdatalenght (void) { - return sizeof (struct uaenetdatawin32); + return sizeof (struct uaenetdatawin32); } static void uaeser_initdata (struct uaenetdatawin32 *sd, void *user) { - memset (sd, 0, sizeof (struct uaenetdatawin32)); - sd->evttw = 0; - sd->user = user; - sd->fp = NULL; + memset (sd, 0, sizeof (struct uaenetdatawin32)); + sd->evttw = 0; + sd->user = user; + sd->fp = NULL; } #if 0 static void *uaenet_trap_thread (void *arg) { - struct uaenetdatawin32 *sd = arg; - HANDLE handles[4]; - int cnt, towrite; - int readactive, writeactive; - DWORD actual; - - uae_set_thread_priority (NULL, 2); - sd->threadactive = 1; - uae_sem_post (&sd->sync_sem); - readactive = 0; - writeactive = 0; - while (sd->threadactive == 1) { - int donotwait = 0; - - uae_sem_wait (&sd->change_sem); - - if (readactive) { - if (GetOverlappedResult (sd->hCom, &sd->olr, &actual, FALSE)) { - readactive = 0; - uaenet_gotdata (sd->user, sd->readbuffer, actual); - donotwait = 1; - } - } - if (writeactive) { - if (GetOverlappedResult (sd->hCom, &sd->olw, &actual, FALSE)) { - writeactive = 0; - donotwait = 1; - } - } - - if (!readactive) { - if (!ReadFile (sd->hCom, sd->readbuffer, sd->mtu, &actual, &sd->olr)) { - DWORD err = GetLastError(); - if (err == ERROR_IO_PENDING) - readactive = 1; - } else { - uaenet_gotdata (sd->user, sd->readbuffer, actual); - donotwait = 1; - } - } - - towrite = 0; - if (!writeactive && uaenet_getdata (sd->user, sd->writebuffer, &towrite)) { - donotwait = 1; - if (!WriteFile (sd->hCom, sd->writebuffer, towrite, &actual, &sd->olw)) { - DWORD err = GetLastError(); - if (err == ERROR_IO_PENDING) - writeactive = 1; - } - } + struct uaenetdatawin32 *sd = arg; + HANDLE handles[4]; + int cnt, towrite; + int readactive, writeactive; + DWORD actual; + + uae_set_thread_priority (NULL, 2); + sd->threadactive = 1; + uae_sem_post (&sd->sync_sem); + readactive = 0; + writeactive = 0; + while (sd->threadactive == 1) { + int donotwait = 0; + + uae_sem_wait (&sd->change_sem); + + if (readactive) { + if (GetOverlappedResult (sd->hCom, &sd->olr, &actual, FALSE)) { + readactive = 0; + uaenet_gotdata (sd->user, sd->readbuffer, actual); + donotwait = 1; + } + } + if (writeactive) { + if (GetOverlappedResult (sd->hCom, &sd->olw, &actual, FALSE)) { + writeactive = 0; + donotwait = 1; + } + } + + if (!readactive) { + if (!ReadFile (sd->hCom, sd->readbuffer, sd->mtu, &actual, &sd->olr)) { + DWORD err = GetLastError(); + if (err == ERROR_IO_PENDING) + readactive = 1; + } else { + uaenet_gotdata (sd->user, sd->readbuffer, actual); + donotwait = 1; + } + } + + towrite = 0; + if (!writeactive && uaenet_getdata (sd->user, sd->writebuffer, &towrite)) { + donotwait = 1; + if (!WriteFile (sd->hCom, sd->writebuffer, towrite, &actual, &sd->olw)) { + DWORD err = GetLastError(); + if (err == ERROR_IO_PENDING) + writeactive = 1; + } + } + + uae_sem_post (&sd->change_sem); + + if (!donotwait) { + cnt = 0; + handles[cnt++] = sd->evtt; + if (readactive) + handles[cnt++] = sd->olr.hEvent; + if (writeactive) + handles[cnt++] = sd->olw.hEvent; + WaitForMultipleObjects(cnt, handles, FALSE, INFINITE); + } - uae_sem_post (&sd->change_sem); - if (!donotwait) { - cnt = 0; - handles[cnt++] = sd->evtt; - if (readactive) - handles[cnt++] = sd->olr.hEvent; - if (writeactive) - handles[cnt++] = sd->olw.hEvent; - WaitForMultipleObjects(cnt, handles, FALSE, INFINITE); } - - - } - sd->threadactive = 0; - uae_sem_post (&sd->sync_sem); - return 0; + sd->threadactive = 0; + uae_sem_post (&sd->sync_sem); + return 0; } #endif static void *uaenet_trap_threadr (void *arg) { - struct uaenetdatawin32 *sd = arg; - struct pcap_pkthdr *header; - const u_char *pkt_data; - - uae_set_thread_priority (NULL, 1); - sd->threadactiver = 1; - uae_sem_post (&sd->sync_semr); - while (sd->threadactiver == 1) { - int r; - r = pcap_next_ex (sd->fp, &header, &pkt_data); - if (r == 1) { - uae_sem_wait (&sd->change_sem); - sd->gotfunc (sd->user, pkt_data, header->len); - uae_sem_post (&sd->change_sem); - } - if (r < 0) { - write_log (L"pcap_next_ex failed, err=%d\n", r); - break; + struct uaenetdatawin32 *sd = arg; + struct pcap_pkthdr *header; + const u_char *pkt_data; + + uae_set_thread_priority (NULL, 1); + sd->threadactiver = 1; + uae_sem_post (&sd->sync_semr); + while (sd->threadactiver == 1) { + int r; + r = pcap_next_ex (sd->fp, &header, &pkt_data); + if (r == 1) { + uae_sem_wait (&sd->change_sem); + sd->gotfunc (sd->user, pkt_data, header->len); + uae_sem_post (&sd->change_sem); + } + if (r < 0) { + write_log (L"pcap_next_ex failed, err=%d\n", r); + break; + } } - } - sd->threadactiver = 0; - uae_sem_post (&sd->sync_semr); - return 0; + sd->threadactiver = 0; + uae_sem_post (&sd->sync_semr); + return 0; } static void *uaenet_trap_threadw (void *arg) { - struct uaenetdatawin32 *sd = arg; - - uae_set_thread_priority (NULL, 1); - sd->threadactivew = 1; - uae_sem_post (&sd->sync_semw); - while (sd->threadactivew == 1) { - int donotwait = 0; - int towrite = sd->mtu; - uae_sem_wait (&sd->change_sem); - if (sd->getfunc (sd->user, sd->writebuffer, &towrite)) { - pcap_sendpacket (sd->fp, sd->writebuffer, towrite); - donotwait = 1; + struct uaenetdatawin32 *sd = arg; + + uae_set_thread_priority (NULL, 1); + sd->threadactivew = 1; + uae_sem_post (&sd->sync_semw); + while (sd->threadactivew == 1) { + int donotwait = 0; + int towrite = sd->mtu; + uae_sem_wait (&sd->change_sem); + if (sd->getfunc (sd->user, sd->writebuffer, &towrite)) { + pcap_sendpacket (sd->fp, sd->writebuffer, towrite); + donotwait = 1; + } + uae_sem_post (&sd->change_sem); + if (!donotwait) + WaitForSingleObject (sd->evttw, INFINITE); } - uae_sem_post (&sd->change_sem); - if (!donotwait) - WaitForSingleObject (sd->evttw, INFINITE); - } - sd->threadactivew = 0; - uae_sem_post (&sd->sync_semw); - return 0; + sd->threadactivew = 0; + uae_sem_post (&sd->sync_semw); + return 0; } void uaenet_trigger (struct uaenetdatawin32 *sd) { - if (!sd) - return; - SetEvent (sd->evttw); + if (!sd) + return; + SetEvent (sd->evttw); } int uaenet_open (struct uaenetdatawin32 *sd, struct netdriverdata *tc, void *user, uaenet_gotfunc *gotfunc, uaenet_getfunc *getfunc, int promiscuous) { - char *s; - - s = ua (tc->name); - sd->fp = pcap_open (s, 65536, (promiscuous ? PCAP_OPENFLAG_PROMISCUOUS : 0) | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 100, NULL, sd->errbuf); - xfree (s); - if (sd->fp == NULL) { - TCHAR *ss = au (sd->errbuf); - write_log (L"'%s' failed to open: %s\n", tc->name, ss); - xfree (ss); - return 0; - } - sd->tc = tc; - sd->user = user; - sd->evttw = CreateEvent (NULL, FALSE, FALSE, NULL); - - if (!sd->evttw) - goto end; - sd->mtu = tc->mtu; - sd->readbuffer = xmalloc (sd->mtu); - sd->writebuffer = xmalloc (sd->mtu); - sd->gotfunc = gotfunc; - sd->getfunc = getfunc; - - uae_sem_init (&sd->change_sem, 0, 1); - uae_sem_init (&sd->sync_semr, 0, 0); - uae_start_thread (L"uaenet_win32r", uaenet_trap_threadr, sd, &sd->tidr); - uae_sem_wait (&sd->sync_semr); - uae_sem_init (&sd->sync_semw, 0, 0); - uae_start_thread (L"uaenet_win32w", uaenet_trap_threadw, sd, &sd->tidw); - uae_sem_wait (&sd->sync_semw); - write_log (L"uaenet_win32 initialized\n"); - return 1; + char *s; + + s = ua (tc->name); + sd->fp = pcap_open (s, 65536, (promiscuous ? PCAP_OPENFLAG_PROMISCUOUS : 0) | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 100, NULL, sd->errbuf); + xfree (s); + if (sd->fp == NULL) { + TCHAR *ss = au (sd->errbuf); + write_log (L"'%s' failed to open: %s\n", tc->name, ss); + xfree (ss); + return 0; + } + sd->tc = tc; + sd->user = user; + sd->evttw = CreateEvent (NULL, FALSE, FALSE, NULL); + + if (!sd->evttw) + goto end; + sd->mtu = tc->mtu; + sd->readbuffer = xmalloc (sd->mtu); + sd->writebuffer = xmalloc (sd->mtu); + sd->gotfunc = gotfunc; + sd->getfunc = getfunc; + + uae_sem_init (&sd->change_sem, 0, 1); + uae_sem_init (&sd->sync_semr, 0, 0); + uae_start_thread (L"uaenet_win32r", uaenet_trap_threadr, sd, &sd->tidr); + uae_sem_wait (&sd->sync_semr); + uae_sem_init (&sd->sync_semw, 0, 0); + uae_start_thread (L"uaenet_win32w", uaenet_trap_threadw, sd, &sd->tidw); + uae_sem_wait (&sd->sync_semw); + write_log (L"uaenet_win32 initialized\n"); + return 1; end: - uaenet_close (sd); - return 0; + uaenet_close (sd); + return 0; } void uaenet_close (struct uaenetdatawin32 *sd) { - if (!sd) - return; - if (sd->threadactiver) { - sd->threadactiver = -1; - } - if (sd->threadactivew) { - sd->threadactivew = -1; - SetEvent (sd->evttw); - } - if (sd->threadactiver) { - while (sd->threadactiver) - Sleep(10); - write_log (L"uaenet_win32 thread %d killed\n", sd->tidr); - uae_end_thread (&sd->tidr); - } - if (sd->threadactivew) { - while (sd->threadactivew) - Sleep(10); - CloseHandle (sd->evttw); - write_log (L"uaenet_win32 thread %d killed\n", sd->tidw); - uae_end_thread (&sd->tidw); - } - xfree (sd->readbuffer); - xfree (sd->writebuffer); - if (sd->fp) - pcap_close (sd->fp); - uaeser_initdata (sd, sd->user); - write_log (L"uaenet_win32 closed\n"); + if (!sd) + return; + if (sd->threadactiver) { + sd->threadactiver = -1; + } + if (sd->threadactivew) { + sd->threadactivew = -1; + SetEvent (sd->evttw); + } + if (sd->threadactiver) { + while (sd->threadactiver) + Sleep(10); + write_log (L"uaenet_win32 thread %d killed\n", sd->tidr); + uae_end_thread (&sd->tidr); + } + if (sd->threadactivew) { + while (sd->threadactivew) + Sleep(10); + CloseHandle (sd->evttw); + write_log (L"uaenet_win32 thread %d killed\n", sd->tidw); + uae_end_thread (&sd->tidw); + } + xfree (sd->readbuffer); + xfree (sd->writebuffer); + if (sd->fp) + pcap_close (sd->fp); + uaeser_initdata (sd, sd->user); + write_log (L"uaenet_win32 closed\n"); } void uaenet_enumerate_free (struct netdriverdata *tcp) { - int i; - - if (!tcp) - return; - for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { - xfree (tcp[i].name); - xfree (tcp[i].desc); - tcp[i].name = NULL; - tcp[i].desc = NULL; - tcp[i].active = 0; - } + int i; + + if (!tcp) + return; + for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { + xfree (tcp[i].name); + xfree (tcp[i].desc); + tcp[i].name = NULL; + tcp[i].desc = NULL; + tcp[i].active = 0; + } } static struct netdriverdata *enumit (const TCHAR *name) { - int cnt; - for (cnt = 0; cnt < MAX_TOTAL_NET_DEVICES; cnt++) { - TCHAR mac[20]; - struct netdriverdata *tc = tds + cnt; - _stprintf (mac, L"%02X:%02X:%02X:%02X:%02X:%02X", - tc->mac[0], tc->mac[1], tc->mac[2], tc->mac[3], tc->mac[4], tc->mac[5]); - if (tc->active && name && (!_tcsicmp (name, tc->name) || !_tcsicmp (name, mac))) - return tc; - } - return NULL; + int cnt; + for (cnt = 0; cnt < MAX_TOTAL_NET_DEVICES; cnt++) { + TCHAR mac[20]; + struct netdriverdata *tc = tds + cnt; + _stprintf (mac, L"%02X:%02X:%02X:%02X:%02X:%02X", + tc->mac[0], tc->mac[1], tc->mac[2], tc->mac[3], tc->mac[4], tc->mac[5]); + if (tc->active && name && (!_tcsicmp (name, tc->name) || !_tcsicmp (name, mac))) + return tc; + } + return NULL; } struct netdriverdata *uaenet_enumerate (struct netdriverdata **out, const TCHAR *name) { - static int done; - char errbuf[PCAP_ERRBUF_SIZE]; - pcap_if_t *alldevs, *d; - int cnt; - HMODULE hm; - LPADAPTER lpAdapter = 0; - PPACKET_OID_DATA OidData; - struct netdriverdata *tc, *tcp; - pcap_t *fp; - int val; - TCHAR *ss; - - if (enumerated) { - if (out) - *out = tds; - return enumit (name); - } - tcp = tds; - hm = LoadLibrary (L"wpcap.dll"); - if (hm == NULL) { - write_log (L"uaenet: winpcap not installed (wpcap.dll)\n"); - return NULL; - } - FreeLibrary (hm); - hm = LoadLibrary (L"packet.dll"); - if (hm == NULL) { - write_log (L"uaenet: winpcap not installed (packet.dll)\n"); - return NULL; - } - FreeLibrary (hm); - ss = au (pcap_lib_version ()); - if (!done) - write_log (L"uaenet: %s\n", ss); - xfree (ss); - - if (pcap_findalldevs_ex (PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) { - ss = au (errbuf); - write_log (L"uaenet: failed to get interfaces: %s\n", ss); - xfree (ss); - return NULL; - } - - if (!done) - write_log (L"uaenet: detecting interfaces\n"); - for(cnt = 0, d = alldevs; d != NULL; d = d->next) { - char *n2; - TCHAR *ss2; - tc = tcp + cnt; - if (cnt >= MAX_TOTAL_NET_DEVICES) { - write_log (L"buffer overflow\n"); - break; + static int done; + char errbuf[PCAP_ERRBUF_SIZE]; + pcap_if_t *alldevs, *d; + int cnt; + HMODULE hm; + LPADAPTER lpAdapter = 0; + PPACKET_OID_DATA OidData; + struct netdriverdata *tc, *tcp; + pcap_t *fp; + int val; + TCHAR *ss; + + if (enumerated) { + if (out) + *out = tds; + return enumit (name); } - ss = au (d->name); - ss2 = d->description ? au (d->description) : L"(no description)"; - write_log (L"%s\n- %s\n", ss, ss2); - xfree (ss2); - xfree (ss); - n2 = d->name; - if (strlen (n2) <= strlen (PCAP_SRC_IF_STRING)) { - write_log (L"- corrupt name\n"); - continue; + tcp = tds; + hm = LoadLibrary (L"wpcap.dll"); + if (hm == NULL) { + write_log (L"uaenet: winpcap not installed (wpcap.dll)\n"); + return NULL; } - fp = pcap_open (d->name, 65536, 0, 0, NULL, errbuf); - if (!fp) { - ss = au (errbuf); - write_log (L"- pcap_open() failed: %s\n", ss); - xfree (ss); - continue; - } - val = pcap_datalink (fp); - pcap_close (fp); - if (val != DLT_EN10MB) { - if (!done) - write_log (L"- not an ethernet adapter (%d)\n", val); - continue; + FreeLibrary (hm); + hm = LoadLibrary (L"packet.dll"); + if (hm == NULL) { + write_log (L"uaenet: winpcap not installed (packet.dll)\n"); + return NULL; } + FreeLibrary (hm); + ss = au (pcap_lib_version ()); + if (!done) + write_log (L"uaenet: %s\n", ss); + xfree (ss); - lpAdapter = PacketOpenAdapter (n2 + strlen (PCAP_SRC_IF_STRING)); - if (lpAdapter == NULL) { - if (!done) - write_log (L"- PacketOpenAdapter() failed\n"); - continue; + if (pcap_findalldevs_ex (PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) { + ss = au (errbuf); + write_log (L"uaenet: failed to get interfaces: %s\n", ss); + xfree (ss); + return NULL; } - OidData = calloc (6 + sizeof(PACKET_OID_DATA), 1); - if (OidData) { - OidData->Length = 6; - OidData->Oid = OID_802_3_CURRENT_ADDRESS; - if (PacketRequest (lpAdapter, FALSE, OidData)) { - memcpy (tc->mac, OidData->Data, 6); - if (!done) - write_log (L"- MAC %02X:%02X:%02X:%02X:%02X:%02X (%d)\n", - tc->mac[0], tc->mac[1], tc->mac[2], - tc->mac[3], tc->mac[4], tc->mac[5], cnt++); - tc->active = 1; - tc->mtu = 1500; - tc->name = au (d->name); - tc->desc = au (d->description); - } else { - write_log (L" - failed to get MAC\n"); - } - free (OidData); + + if (!done) + write_log (L"uaenet: detecting interfaces\n"); + for(cnt = 0, d = alldevs; d != NULL; d = d->next) { + char *n2; + TCHAR *ss2; + tc = tcp + cnt; + if (cnt >= MAX_TOTAL_NET_DEVICES) { + write_log (L"buffer overflow\n"); + break; + } + ss = au (d->name); + ss2 = d->description ? au (d->description) : L"(no description)"; + write_log (L"%s\n- %s\n", ss, ss2); + xfree (ss2); + xfree (ss); + n2 = d->name; + if (strlen (n2) <= strlen (PCAP_SRC_IF_STRING)) { + write_log (L"- corrupt name\n"); + continue; + } + fp = pcap_open (d->name, 65536, 0, 0, NULL, errbuf); + if (!fp) { + ss = au (errbuf); + write_log (L"- pcap_open() failed: %s\n", ss); + xfree (ss); + continue; + } + val = pcap_datalink (fp); + pcap_close (fp); + if (val != DLT_EN10MB) { + if (!done) + write_log (L"- not an ethernet adapter (%d)\n", val); + continue; + } + + lpAdapter = PacketOpenAdapter (n2 + strlen (PCAP_SRC_IF_STRING)); + if (lpAdapter == NULL) { + if (!done) + write_log (L"- PacketOpenAdapter() failed\n"); + continue; + } + OidData = calloc (6 + sizeof(PACKET_OID_DATA), 1); + if (OidData) { + OidData->Length = 6; + OidData->Oid = OID_802_3_CURRENT_ADDRESS; + if (PacketRequest (lpAdapter, FALSE, OidData)) { + memcpy (tc->mac, OidData->Data, 6); + if (!done) + write_log (L"- MAC %02X:%02X:%02X:%02X:%02X:%02X (%d)\n", + tc->mac[0], tc->mac[1], tc->mac[2], + tc->mac[3], tc->mac[4], tc->mac[5], cnt++); + tc->active = 1; + tc->mtu = 1500; + tc->name = au (d->name); + tc->desc = au (d->description); + } else { + write_log (L" - failed to get MAC\n"); + } + free (OidData); + } + PacketCloseAdapter (lpAdapter); } - PacketCloseAdapter (lpAdapter); - } - if (!done) - write_log (L"uaenet: end of detection\n"); - done = 1; - pcap_freealldevs (alldevs); - enumerated = 1; - if (out) - *out = tds; - return enumit (name); + if (!done) + write_log (L"uaenet: end of detection\n"); + done = 1; + pcap_freealldevs (alldevs); + enumerated = 1; + if (out) + *out = tds; + return enumit (name); } void uaenet_close_driver (struct netdriverdata *tc) { - int i; + int i; - if (!tc) - return; - for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { - tc[i].active = 0; - } + if (!tc) + return; + for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { + tc[i].active = 0; + } } diff --git a/od-win32/win32gfx.c b/od-win32/win32gfx.c index a453eee7..ba50802f 100644 --- a/od-win32/win32gfx.c +++ b/od-win32/win32gfx.c @@ -1,11 +1,11 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Win32 Drawing and DirectX interface - * - * Copyright 1997-1998 Mathias Ortmann - * Copyright 1997-2000 Brian King - */ +* UAE - The Un*x Amiga Emulator +* +* Win32 Drawing and DirectX interface +* +* Copyright 1997-1998 Mathias Ortmann +* Copyright 1997-2000 Brian King +*/ #include "sysconfig.h" @@ -81,15 +81,15 @@ struct uae_filter *usedfilter; static int scalepicasso; struct winuae_currentmode { - unsigned int flags; - int native_width, native_height, native_depth, pitch; - int current_width, current_height, current_depth; - int amiga_width, amiga_height; - int frequency; - int initdone; - int fullfill; - int vsync; - LPPALETTEENTRY pal; + unsigned int flags; + int native_width, native_height, native_depth, pitch; + int current_width, current_height, current_depth; + int amiga_width, amiga_height; + int frequency; + int initdone; + int fullfill; + int vsync; + LPPALETTEENTRY pal; }; struct MultiDisplay Displays[MAX_DISPLAYS]; @@ -109,67 +109,67 @@ int screen_is_picasso = 0; int WIN32GFX_IsPicassoScreen (void) { - return screen_is_picasso; + return screen_is_picasso; } void WIN32GFX_DisablePicasso (void) { - picasso_requested_on = 0; - picasso_on = 0; + picasso_requested_on = 0; + picasso_on = 0; } void WIN32GFX_EnablePicasso (void) { - picasso_requested_on = 1; + picasso_requested_on = 1; } void WIN32GFX_DisplayChangeRequested (void) { - display_change_requested = 1; + display_change_requested = 1; } int isscreen (void) { - return hMainWnd ? 1 : 0; + return hMainWnd ? 1 : 0; } static void clearscreen (void) { - DirectDraw_FillPrimary (); + DirectDraw_FillPrimary (); } static int isfullscreen_2 (struct uae_prefs *p) { - if (screen_is_picasso) - return p->gfx_pfullscreen == 1 ? 1 : (p->gfx_pfullscreen == 2 ? -1 : 0); - else - return p->gfx_afullscreen == 1 ? 1 : (p->gfx_afullscreen == 2 ? -1 : 0); + if (screen_is_picasso) + return p->gfx_pfullscreen == 1 ? 1 : (p->gfx_pfullscreen == 2 ? -1 : 0); + else + return p->gfx_afullscreen == 1 ? 1 : (p->gfx_afullscreen == 2 ? -1 : 0); } int isfullscreen (void) { - return isfullscreen_2 (&currprefs); + return isfullscreen_2 (&currprefs); } int is3dmode (void) { - return currentmode->flags & (DM_D3D | DM_OPENGL); + return currentmode->flags & (DM_D3D | DM_OPENGL); } int WIN32GFX_GetDepth (int real) { - if (!currentmode->native_depth) - return currentmode->current_depth; - return real ? currentmode->native_depth : currentmode->current_depth; + if (!currentmode->native_depth) + return currentmode->current_depth; + return real ? currentmode->native_depth : currentmode->current_depth; } int WIN32GFX_GetWidth (void) { - return currentmode->current_width; + return currentmode->current_width; } int WIN32GFX_GetHeight (void) { - return currentmode->current_height; + return currentmode->current_height; } static BOOL doInit (void); @@ -183,604 +183,604 @@ static uae_u8 scrlinebuf[4096 * 4]; /* this is too large, but let's rather play struct MultiDisplay *getdisplay (struct uae_prefs *p) { - int i; - int display = p->gfx_display; - - i = 0; - while (Displays[i].name) { - struct MultiDisplay *md = &Displays[i]; - if (p->gfx_display_name[0] && !_tcscmp (md->name, p->gfx_display_name)) - return md; - if (p->gfx_display_name[0] && !_tcscmp (md->name2, p->gfx_display_name)) - return md; - i++; - } - if (i == 0) { - gui_message (L"no display adapters! Exiting"); - exit (0); - } - if (display >= i) - display = 0; - return &Displays[display]; + int i; + int display = p->gfx_display; + + i = 0; + while (Displays[i].name) { + struct MultiDisplay *md = &Displays[i]; + if (p->gfx_display_name[0] && !_tcscmp (md->name, p->gfx_display_name)) + return md; + if (p->gfx_display_name[0] && !_tcscmp (md->name2, p->gfx_display_name)) + return md; + i++; + } + if (i == 0) { + gui_message (L"no display adapters! Exiting"); + exit (0); + } + if (display >= i) + display = 0; + return &Displays[display]; } void desktop_coords (int *dw, int *dh, int *ax, int *ay, int *aw, int *ah) { - struct MultiDisplay *md = getdisplay (&currprefs); + struct MultiDisplay *md = getdisplay (&currprefs); - *dw = md->rect.right - md->rect.left; - *dh = md->rect.bottom - md->rect.top; - *ax = amigawin_rect.left; - *ay = amigawin_rect.top; - *aw = amigawin_rect.right - *ax; - *ah = amigawin_rect.bottom - *ay; + *dw = md->rect.right - md->rect.left; + *dh = md->rect.bottom - md->rect.top; + *ax = amigawin_rect.left; + *ay = amigawin_rect.top; + *aw = amigawin_rect.right - *ax; + *ah = amigawin_rect.bottom - *ay; } void centerdstrect (RECT *dr) { - if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_D3D_FULLSCREEN | DM_W_FULLSCREEN))) - OffsetRect (dr, amigawin_rect.left, amigawin_rect.top); - if (currentmode->flags & DM_W_FULLSCREEN) { - if (scalepicasso && screen_is_picasso) - return; - if (usedfilter && !screen_is_picasso) - return; - if (currentmode->fullfill && (currentmode->current_width > currentmode->native_width || currentmode->current_height > currentmode->native_height)) - return; - OffsetRect (dr, (currentmode->native_width - currentmode->current_width) / 2, - (currentmode->native_height - currentmode->current_height) / 2); - } + if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_D3D_FULLSCREEN | DM_W_FULLSCREEN))) + OffsetRect (dr, amigawin_rect.left, amigawin_rect.top); + if (currentmode->flags & DM_W_FULLSCREEN) { + if (scalepicasso && screen_is_picasso) + return; + if (usedfilter && !screen_is_picasso) + return; + if (currentmode->fullfill && (currentmode->current_width > currentmode->native_width || currentmode->current_height > currentmode->native_height)) + return; + OffsetRect (dr, (currentmode->native_width - currentmode->current_width) / 2, + (currentmode->native_height - currentmode->current_height) / 2); + } } static int picasso_offset_x, picasso_offset_y, picasso_offset_mx, picasso_offset_my; void getgfxoffset (int *dxp, int *dyp, int *mxp, int *myp) { - int dx, dy; - - getfilteroffset (&dx, &dy, mxp, myp); - *dxp = dx; - *dyp = dy; - if (picasso_on) { - dx = picasso_offset_x; - dy = picasso_offset_y; - *mxp = picasso_offset_mx; - *myp = picasso_offset_my; - } - *dxp = dx; - *dyp = dy; - if (currentmode->flags & DM_W_FULLSCREEN) { - if (scalepicasso && screen_is_picasso) - return; - if (usedfilter && !screen_is_picasso) - return; - if (currentmode->fullfill && (currentmode->current_width > currentmode->native_width || currentmode->current_height > currentmode->native_height)) - return; - dx += (currentmode->native_width - currentmode->current_width) / 2; - dy += (currentmode->native_height - currentmode->current_height) / 2; - } - *dxp = dx; - *dyp = dy; + int dx, dy; + + getfilteroffset (&dx, &dy, mxp, myp); + *dxp = dx; + *dyp = dy; + if (picasso_on) { + dx = picasso_offset_x; + dy = picasso_offset_y; + *mxp = picasso_offset_mx; + *myp = picasso_offset_my; + } + *dxp = dx; + *dyp = dy; + if (currentmode->flags & DM_W_FULLSCREEN) { + if (scalepicasso && screen_is_picasso) + return; + if (usedfilter && !screen_is_picasso) + return; + if (currentmode->fullfill && (currentmode->current_width > currentmode->native_width || currentmode->current_height > currentmode->native_height)) + return; + dx += (currentmode->native_width - currentmode->current_width) / 2; + dy += (currentmode->native_height - currentmode->current_height) / 2; + } + *dxp = dx; + *dyp = dy; } void DX_Fill (int dstx, int dsty, int width, int height, uae_u32 color) { - RECT dstrect; - if (width < 0) - width = currentmode->current_width; - if (height < 0) - height = currentmode->current_height; - SetRect (&dstrect, dstx, dsty, dstx + width, dsty + height); - DirectDraw_Fill (&dstrect, color); + RECT dstrect; + if (width < 0) + width = currentmode->current_width; + if (height < 0) + height = currentmode->current_height; + SetRect (&dstrect, dstx, dsty, dstx + width, dsty + height); + DirectDraw_Fill (&dstrect, color); } static int rgbformat_bits (RGBFTYPE t) { - unsigned long f = 1 << t; - return ((f & RGBMASK_8BIT) != 0 ? 8 - : (f & RGBMASK_15BIT) != 0 ? 15 - : (f & RGBMASK_16BIT) != 0 ? 16 - : (f & RGBMASK_24BIT) != 0 ? 24 - : (f & RGBMASK_32BIT) != 0 ? 32 - : 0); + unsigned long f = 1 << t; + return ((f & RGBMASK_8BIT) != 0 ? 8 + : (f & RGBMASK_15BIT) != 0 ? 15 + : (f & RGBMASK_16BIT) != 0 ? 16 + : (f & RGBMASK_24BIT) != 0 ? 24 + : (f & RGBMASK_32BIT) != 0 ? 32 + : 0); } static int set_ddraw_2 (void) { - HRESULT ddrval; - int bits = (currentmode->current_depth + 7) & ~7; - int width = currentmode->native_width; - int height = currentmode->native_height; - int freq = currentmode->frequency; - int dxfullscreen, wfullscreen, dd; + HRESULT ddrval; + int bits = (currentmode->current_depth + 7) & ~7; + int width = currentmode->native_width; + int height = currentmode->native_height; + int freq = currentmode->frequency; + 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; + dxfullscreen = (currentmode->flags & DM_DX_FULLSCREEN) ? TRUE : FALSE; + wfullscreen = (currentmode->flags & DM_W_FULLSCREEN) ? TRUE : FALSE; + dd = (currentmode->flags & DM_DDRAW) ? TRUE : FALSE; - if (WIN32GFX_IsPicassoScreen () && (picasso96_state.Width > width || picasso96_state.Height > height)) { - width = picasso96_state.Width; - height = picasso96_state.Height; - } + if (WIN32GFX_IsPicassoScreen () && (picasso96_state.Width > width || picasso96_state.Height > height)) { + width = picasso96_state.Width; + height = picasso96_state.Height; + } - DirectDraw_FreeMainSurface (); + DirectDraw_FreeMainSurface (); - if (!dd && !dxfullscreen) - return 1; + if (!dd && !dxfullscreen) + return 1; - ddrval = DirectDraw_SetCooperativeLevel (hAmigaWnd, dxfullscreen, TRUE); - if (FAILED (ddrval)) - goto oops; + ddrval = DirectDraw_SetCooperativeLevel (hAmigaWnd, dxfullscreen, TRUE); + if (FAILED (ddrval)) + goto oops; - if (dxfullscreen) { - for (;;) { - int i, j, got = FALSE; - HRESULT olderr; - struct MultiDisplay *md = getdisplay (&currprefs); - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - struct PicassoResolution *pr = &md->DisplayModes[i]; - if (pr->res.width == width && pr->res.height == height) { - for (j = 0; pr->refresh[j] > 0; j++) { - if (pr->refresh[j] == freq) - got = TRUE; - } - break; + if (dxfullscreen) { + for (;;) { + int i, j, got = FALSE; + HRESULT olderr; + struct MultiDisplay *md = getdisplay (&currprefs); + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + struct PicassoResolution *pr = &md->DisplayModes[i]; + if (pr->res.width == width && pr->res.height == height) { + for (j = 0; pr->refresh[j] > 0; j++) { + if (pr->refresh[j] == freq) + got = TRUE; + } + break; + } + } + if (got == FALSE) { + write_log (L"set_ddraw: refresh rate %d not supported\n", freq); + freq = 0; + } + write_log (L"set_ddraw: trying %dx%d, bits=%d, refreshrate=%d\n", width, height, bits, freq); + ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); + if (SUCCEEDED (ddrval)) + break; + olderr = ddrval; + if (freq) { + write_log (L"set_ddraw: failed, trying without forced refresh rate\n"); + DirectDraw_SetCooperativeLevel (hAmigaWnd, dxfullscreen, TRUE); + ddrval = DirectDraw_SetDisplayMode (width, height, bits, 0); + if (SUCCEEDED (ddrval)) + break; + } + if (olderr != DDERR_INVALIDMODE && olderr != 0x80004001 && olderr != DDERR_UNSUPPORTEDMODE) + goto oops; + return -1; } - } - if (got == FALSE) { - write_log (L"set_ddraw: refresh rate %d not supported\n", freq); - freq = 0; - } - write_log (L"set_ddraw: trying %dx%d, bits=%d, refreshrate=%d\n", width, height, bits, freq); - ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); - if (SUCCEEDED (ddrval)) - break; - olderr = ddrval; - if (freq) { - write_log (L"set_ddraw: failed, trying without forced refresh rate\n"); - DirectDraw_SetCooperativeLevel (hAmigaWnd, dxfullscreen, TRUE); - ddrval = DirectDraw_SetDisplayMode (width, height, bits, 0); - if (SUCCEEDED (ddrval)) - break; - } - if (olderr != DDERR_INVALIDMODE && olderr != 0x80004001 && olderr != DDERR_UNSUPPORTEDMODE) - goto oops; - return -1; + GetWindowRect (hAmigaWnd, &amigawin_rect); } - GetWindowRect (hAmigaWnd, &amigawin_rect); - } - if (dd) { - ddrval = DirectDraw_CreateClipper (); - if (FAILED (ddrval)) - goto oops; - ddrval = DirectDraw_CreateMainSurface (width, height); - if (FAILED(ddrval)) { - write_log (L"set_ddraw: couldn't CreateSurface() for primary because %s.\n", DXError (ddrval)); - goto oops; - } - ddrval = DirectDraw_SetClipper (hAmigaWnd); - if (FAILED (ddrval)) - goto oops; - if (DirectDraw_SurfaceLock ()) { - currentmode->pitch = DirectDraw_GetSurfacePitch (); - DirectDraw_SurfaceUnlock (); + if (dd) { + ddrval = DirectDraw_CreateClipper (); + if (FAILED (ddrval)) + goto oops; + ddrval = DirectDraw_CreateMainSurface (width, height); + if (FAILED(ddrval)) { + write_log (L"set_ddraw: couldn't CreateSurface() for primary because %s.\n", DXError (ddrval)); + goto oops; + } + ddrval = DirectDraw_SetClipper (hAmigaWnd); + if (FAILED (ddrval)) + goto oops; + if (DirectDraw_SurfaceLock ()) { + currentmode->pitch = DirectDraw_GetSurfacePitch (); + DirectDraw_SurfaceUnlock (); + } + if (bits <= 8) + DirectDraw_CreatePalette (currentmode->pal); } - if (bits <= 8) - DirectDraw_CreatePalette (currentmode->pal); - } - write_log (L"set_ddraw: %dx%d@%d-bytes\n", width, height, bits); - return 1; + write_log (L"set_ddraw: %dx%d@%d-bytes\n", width, height, bits); + return 1; oops: - return 0; + return 0; } static void addmode (struct MultiDisplay *md, int w, int h, int d, int rate, int nondx) { - int ct; - int i, j; - - ct = 0; - if (d == 8) - ct = RGBMASK_8BIT; - if (d == 15) - ct = RGBMASK_15BIT; - if (d == 16) - ct = RGBMASK_16BIT; - if (d == 24) - ct = RGBMASK_24BIT; - if (d == 32) - ct = RGBMASK_32BIT; - if (ct == 0) - return; - d /= 8; - i = 0; - while (md->DisplayModes[i].depth >= 0) { - if (md->DisplayModes[i].depth == d && md->DisplayModes[i].res.width == w && md->DisplayModes[i].res.height == h) { - for (j = 0; j < MAX_REFRESH_RATES; j++) { - if (md->DisplayModes[i].refresh[j] == 0 || md->DisplayModes[i].refresh[j] == rate) - break; - } - if (j < MAX_REFRESH_RATES) { - md->DisplayModes[i].refresh[j] = rate; - md->DisplayModes[i].refreshtype[j] = nondx; - md->DisplayModes[i].refresh[j + 1] = 0; + int ct; + int i, j; + + ct = 0; + if (d == 8) + ct = RGBMASK_8BIT; + if (d == 15) + ct = RGBMASK_15BIT; + if (d == 16) + ct = RGBMASK_16BIT; + if (d == 24) + ct = RGBMASK_24BIT; + if (d == 32) + ct = RGBMASK_32BIT; + if (ct == 0) + return; + d /= 8; + i = 0; + while (md->DisplayModes[i].depth >= 0) { + if (md->DisplayModes[i].depth == d && md->DisplayModes[i].res.width == w && md->DisplayModes[i].res.height == h) { + for (j = 0; j < MAX_REFRESH_RATES; j++) { + if (md->DisplayModes[i].refresh[j] == 0 || md->DisplayModes[i].refresh[j] == rate) + break; + } + if (j < MAX_REFRESH_RATES) { + md->DisplayModes[i].refresh[j] = rate; + md->DisplayModes[i].refreshtype[j] = nondx; + md->DisplayModes[i].refresh[j + 1] = 0; + return; + } + } + i++; + } + i = 0; + while (md->DisplayModes[i].depth >= 0) + i++; + if (i >= MAX_PICASSO_MODES - 1) return; - } - } - i++; - } - i = 0; - while (md->DisplayModes[i].depth >= 0) - i++; - if (i >= MAX_PICASSO_MODES - 1) - return; - md->DisplayModes[i].nondx = nondx; - md->DisplayModes[i].res.width = w; - md->DisplayModes[i].res.height = h; - md->DisplayModes[i].depth = d; - md->DisplayModes[i].refresh[0] = rate; - md->DisplayModes[i].refreshtype[0] = nondx; - md->DisplayModes[i].refresh[1] = 0; - md->DisplayModes[i].colormodes = ct; - md->DisplayModes[i + 1].depth = -1; - _stprintf (md->DisplayModes[i].name, L"%dx%d, %d-bit", - md->DisplayModes[i].res.width, md->DisplayModes[i].res.height, md->DisplayModes[i].depth * 8); + md->DisplayModes[i].nondx = nondx; + md->DisplayModes[i].res.width = w; + md->DisplayModes[i].res.height = h; + md->DisplayModes[i].depth = d; + md->DisplayModes[i].refresh[0] = rate; + md->DisplayModes[i].refreshtype[0] = nondx; + md->DisplayModes[i].refresh[1] = 0; + md->DisplayModes[i].colormodes = ct; + md->DisplayModes[i + 1].depth = -1; + _stprintf (md->DisplayModes[i].name, L"%dx%d, %d-bit", + md->DisplayModes[i].res.width, md->DisplayModes[i].res.height, md->DisplayModes[i].depth * 8); } static HRESULT CALLBACK modesCallback (LPDDSURFACEDESC2 modeDesc, LPVOID context) { - struct MultiDisplay *md = context; - RGBFTYPE colortype; - int depth, ct; - - colortype = DirectDraw_GetSurfacePixelFormat (modeDesc); - ct = 1 << colortype; - depth = 0; - if (ct & RGBMASK_8BIT) - depth = 8; - else if (ct & RGBMASK_15BIT) - depth = 15; - else if (ct & RGBMASK_16BIT) - depth = 16; - else if (ct & RGBMASK_24BIT) - depth = 24; - else if (ct & RGBMASK_32BIT) - depth = 32; - if (depth == 0) - return DDENUMRET_OK; - if (colortype == RGBFB_NONE) - return DDENUMRET_OK; - if (modeDesc->dwWidth > 2560 || modeDesc->dwHeight > 2048) + struct MultiDisplay *md = context; + RGBFTYPE colortype; + int depth, ct; + + colortype = DirectDraw_GetSurfacePixelFormat (modeDesc); + ct = 1 << colortype; + depth = 0; + if (ct & RGBMASK_8BIT) + depth = 8; + else if (ct & RGBMASK_15BIT) + depth = 15; + else if (ct & RGBMASK_16BIT) + depth = 16; + else if (ct & RGBMASK_24BIT) + depth = 24; + else if (ct & RGBMASK_32BIT) + depth = 32; + if (depth == 0) + return DDENUMRET_OK; + if (colortype == RGBFB_NONE) + return DDENUMRET_OK; + if (modeDesc->dwWidth > 2560 || modeDesc->dwHeight > 2048) + return DDENUMRET_OK; + addmode (md, modeDesc->dwWidth, modeDesc->dwHeight, depth, modeDesc->dwRefreshRate, 0); return DDENUMRET_OK; - addmode (md, modeDesc->dwWidth, modeDesc->dwHeight, depth, modeDesc->dwRefreshRate, 0); - return DDENUMRET_OK; } static int _cdecl resolution_compare (const void *a, const void *b) { - struct PicassoResolution *ma = (struct PicassoResolution *)a; - struct PicassoResolution *mb = (struct PicassoResolution *)b; - if (ma->res.width < mb->res.width) - return -1; - if (ma->res.width > mb->res.width) - return 1; - if (ma->res.height < mb->res.height) - return -1; - if (ma->res.height > mb->res.height) - return 1; - return ma->depth - mb->depth; + struct PicassoResolution *ma = (struct PicassoResolution *)a; + struct PicassoResolution *mb = (struct PicassoResolution *)b; + if (ma->res.width < mb->res.width) + return -1; + if (ma->res.width > mb->res.width) + return 1; + if (ma->res.height < mb->res.height) + return -1; + if (ma->res.height > mb->res.height) + return 1; + return ma->depth - mb->depth; } static void sortmodes (struct MultiDisplay *md) { - int i, idx = -1; - int pw = -1, ph = -1; - - i = 0; - while (md->DisplayModes[i].depth >= 0) - i++; - qsort (md->DisplayModes, i, sizeof (struct PicassoResolution), resolution_compare); - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - int j, k; - for (j = 0; md->DisplayModes[i].refresh[j]; j++) { - for (k = j + 1; md->DisplayModes[i].refresh[k]; k++) { - if (md->DisplayModes[i].refresh[j] > md->DisplayModes[i].refresh[k]) { - int t = md->DisplayModes[i].refresh[j]; - md->DisplayModes[i].refresh[j] = md->DisplayModes[i].refresh[k]; - md->DisplayModes[i].refresh[k] = t; - t = md->DisplayModes[i].refreshtype[j]; - md->DisplayModes[i].refreshtype[j] = md->DisplayModes[i].refreshtype[k]; - md->DisplayModes[i].refreshtype[k] = t; + int i, idx = -1; + int pw = -1, ph = -1; + + i = 0; + while (md->DisplayModes[i].depth >= 0) + i++; + qsort (md->DisplayModes, i, sizeof (struct PicassoResolution), resolution_compare); + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + int j, k; + for (j = 0; md->DisplayModes[i].refresh[j]; j++) { + for (k = j + 1; md->DisplayModes[i].refresh[k]; k++) { + if (md->DisplayModes[i].refresh[j] > md->DisplayModes[i].refresh[k]) { + int t = md->DisplayModes[i].refresh[j]; + md->DisplayModes[i].refresh[j] = md->DisplayModes[i].refresh[k]; + md->DisplayModes[i].refresh[k] = t; + t = md->DisplayModes[i].refreshtype[j]; + md->DisplayModes[i].refreshtype[j] = md->DisplayModes[i].refreshtype[k]; + md->DisplayModes[i].refreshtype[k] = t; + } + } } - } - } - if (md->DisplayModes[i].res.height != ph || md->DisplayModes[i].res.width != pw) { - ph = md->DisplayModes[i].res.height; - pw = md->DisplayModes[i].res.width; - idx++; + if (md->DisplayModes[i].res.height != ph || md->DisplayModes[i].res.width != pw) { + ph = md->DisplayModes[i].res.height; + pw = md->DisplayModes[i].res.width; + idx++; + } + md->DisplayModes[i].residx = idx; } - md->DisplayModes[i].residx = idx; - } } static void modesList (struct MultiDisplay *md) { - int i, j; + int i, j; - i = 0; - while (md->DisplayModes[i].depth >= 0) { - write_log (L"%d: %s%s (", i, md->DisplayModes[i].nondx ? L"!" : L"", md->DisplayModes[i].name); - j = 0; - while (md->DisplayModes[i].refresh[j] > 0) { - if (j > 0) - write_log (L","); - if (md->DisplayModes[i].refreshtype[j]) - write_log (L"!%d", md->DisplayModes[i].refresh[j]); - else - write_log (L"%d", md->DisplayModes[i].refresh[j]); - j++; + i = 0; + while (md->DisplayModes[i].depth >= 0) { + write_log (L"%d: %s%s (", i, md->DisplayModes[i].nondx ? L"!" : L"", md->DisplayModes[i].name); + j = 0; + while (md->DisplayModes[i].refresh[j] > 0) { + if (j > 0) + write_log (L","); + if (md->DisplayModes[i].refreshtype[j]) + write_log (L"!%d", md->DisplayModes[i].refresh[j]); + else + write_log (L"%d", md->DisplayModes[i].refresh[j]); + j++; + } + write_log (L")\n"); + i++; } - write_log (L")\n"); - i++; - } } BOOL CALLBACK displaysCallback (GUID *guid, char *adesc, char *aname, LPVOID ctx, HMONITOR hm) { - struct MultiDisplay *md = Displays; - MONITORINFOEX lpmi; - TCHAR tmp[200]; - TCHAR *desc = au (adesc); - TCHAR *name = au (aname); - int ret = 0; - - while (md->name) { - if (md - Displays >= MAX_DISPLAYS) - goto end; - md++; - } - lpmi.cbSize = sizeof (lpmi); - if (guid == 0) { - POINT pt = { 0, 0 }; - md->primary = 1; - GetMonitorInfo (MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&lpmi); - } else { - memcpy (&md->guid, guid, sizeof (GUID)); - GetMonitorInfo (hm, (LPMONITORINFO)&lpmi); - } - md->rect = lpmi.rcMonitor; - if (md->rect.left == 0 && md->rect.top == 0) - _stprintf (tmp, L"%s (%d*%d)", desc, md->rect.right - md->rect.left, md->rect.bottom - md->rect.top); - else - _stprintf (tmp, L"%s (%d*%d) [%d*%d]", desc, md->rect.right - md->rect.left, md->rect.bottom - md->rect.top, md->rect.left, md->rect.top); - md->name = my_strdup (tmp); - md->name2 = my_strdup (desc); - md->name3 = my_strdup (name); - write_log (L"'%s' '%s' %s\n", desc, name, outGUID(guid)); - ret = 1; + struct MultiDisplay *md = Displays; + MONITORINFOEX lpmi; + TCHAR tmp[200]; + TCHAR *desc = au (adesc); + TCHAR *name = au (aname); + int ret = 0; + + while (md->name) { + if (md - Displays >= MAX_DISPLAYS) + goto end; + md++; + } + lpmi.cbSize = sizeof (lpmi); + if (guid == 0) { + POINT pt = { 0, 0 }; + md->primary = 1; + GetMonitorInfo (MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&lpmi); + } else { + memcpy (&md->guid, guid, sizeof (GUID)); + GetMonitorInfo (hm, (LPMONITORINFO)&lpmi); + } + md->rect = lpmi.rcMonitor; + if (md->rect.left == 0 && md->rect.top == 0) + _stprintf (tmp, L"%s (%d*%d)", desc, md->rect.right - md->rect.left, md->rect.bottom - md->rect.top); + else + _stprintf (tmp, L"%s (%d*%d) [%d*%d]", desc, md->rect.right - md->rect.left, md->rect.bottom - md->rect.top, md->rect.left, md->rect.top); + md->name = my_strdup (tmp); + md->name2 = my_strdup (desc); + md->name3 = my_strdup (name); + write_log (L"'%s' '%s' %s\n", desc, name, outGUID(guid)); + ret = 1; end: - xfree (name); - xfree (desc); - return ret; + xfree (name); + xfree (desc); + return ret; } static BOOL CALLBACK monitorEnumProc (HMONITOR h, HDC hdc, LPRECT rect, LPARAM data) { - MONITORINFOEX lpmi; - int cnt = *((int*)data); - if (!Displays[cnt].name) - return FALSE; - lpmi.cbSize = sizeof (lpmi); - GetMonitorInfo(h, (LPMONITORINFO)&lpmi); - Displays[cnt].rect = *rect; - Displays[cnt].gdi = TRUE; - (*((int*)data))++; - return TRUE; + MONITORINFOEX lpmi; + int cnt = *((int*)data); + if (!Displays[cnt].name) + return FALSE; + lpmi.cbSize = sizeof (lpmi); + GetMonitorInfo(h, (LPMONITORINFO)&lpmi); + Displays[cnt].rect = *rect; + Displays[cnt].gdi = TRUE; + (*((int*)data))++; + return TRUE; } void enumeratedisplays (int multi) { - if (multi) { - int cnt = 1; - DirectDraw_EnumDisplays (displaysCallback); - EnumDisplayMonitors (NULL, NULL, monitorEnumProc, (LPARAM)&cnt); - } else { - write_log (L"Multimonitor detection disabled\n"); - Displays[0].primary = 1; - Displays[0].name = L"Display"; - Displays[0].disabled = 0; - } + if (multi) { + int cnt = 1; + DirectDraw_EnumDisplays (displaysCallback); + EnumDisplayMonitors (NULL, NULL, monitorEnumProc, (LPARAM)&cnt); + } else { + write_log (L"Multimonitor detection disabled\n"); + Displays[0].primary = 1; + Displays[0].name = L"Display"; + Displays[0].disabled = 0; + } } static int makesort (struct MultiDisplay *md) { - int v; + int v; - v = md->rect.top * 65536 + md->rect.left; - if (md->primary) - v = 0x80000001; - if (md->rect.top == 0 && md->rect.left == 0) - v = 0x80000000; - return v; + v = md->rect.top * 65536 + md->rect.left; + if (md->primary) + v = 0x80000001; + if (md->rect.top == 0 && md->rect.left == 0) + v = 0x80000000; + return v; } void sortdisplays (void) { - struct MultiDisplay *md1, *md2, tmp; - int i, idx, idx2; - - md1 = Displays; - while (md1->name) { - int sort1 = makesort (md1); - md2 = md1 + 1; - while (md2->name) { - int sort2 = makesort (md2); - if (sort1 > sort2) { - memcpy (&tmp, md1, sizeof (tmp)); - memcpy (md1, md2, sizeof (tmp)); - memcpy (md2, &tmp, sizeof (tmp)); - } - md2++; - } - md1++; - } - - md1 = Displays; - while (md1->name) { - md1->DisplayModes = xmalloc (sizeof (struct PicassoResolution) * MAX_PICASSO_MODES); - md1->DisplayModes[0].depth = -1; - md1->disabled = 1; - if (DirectDraw_Start (md1->primary ? NULL : &md1->guid)) { - if (SUCCEEDED (DirectDraw_GetDisplayMode ())) { - int w = DirectDraw_CurrentWidth (); - int h = DirectDraw_CurrentHeight (); - int b = DirectDraw_GetCurrentDepth (); - int maxw = 0, maxh = 0; - - DirectDraw_EnumDisplayModes (DDEDM_REFRESHRATES, modesCallback, md1); - idx2 = 0; - while (md1->DisplayModes[idx2].depth >= 0) { - struct PicassoResolution *pr = &md1->DisplayModes[idx2]; - if (pr->res.width > maxw) - maxw = pr->res.width; - if (pr->res.height > maxh) - maxh = pr->res.height; - idx2++; + struct MultiDisplay *md1, *md2, tmp; + int i, idx, idx2; + + md1 = Displays; + while (md1->name) { + int sort1 = makesort (md1); + md2 = md1 + 1; + while (md2->name) { + int sort2 = makesort (md2); + if (sort1 > sort2) { + memcpy (&tmp, md1, sizeof (tmp)); + memcpy (md1, md2, sizeof (tmp)); + memcpy (md2, &tmp, sizeof (tmp)); + } + md2++; } - write_log (L"Desktop: W=%d H=%d B=%d. MaxW=%d MaxH=%d CXVS=%d CYVS=%d\n", w, h, b, maxw, maxh, - GetSystemMetrics (SM_CXVIRTUALSCREEN), GetSystemMetrics (SM_CYVIRTUALSCREEN)); - idx = 0; - for (;;) { - int found; - DEVMODE dm; - dm.dmSize = sizeof dm; - dm.dmDriverExtra = 0; - if (!EnumDisplaySettingsEx (md1->primary ? NULL : md1->name3, idx, &dm, EDS_RAWMODE)) - break; - idx2 = 0; - found = 0; - while (md1->DisplayModes[idx2].depth >= 0 && !found) { - struct PicassoResolution *pr = &md1->DisplayModes[idx2]; - if (pr->res.width == dm.dmPelsWidth && pr->res.height == dm.dmPelsHeight && pr->depth == dm.dmBitsPerPel / 8) { - for (i = 0; pr->refresh[i]; i++) { - if (pr->refresh[i] == dm.dmDisplayFrequency) { - found = 1; - break; + md1++; + } + + md1 = Displays; + while (md1->name) { + md1->DisplayModes = xmalloc (sizeof (struct PicassoResolution) * MAX_PICASSO_MODES); + md1->DisplayModes[0].depth = -1; + md1->disabled = 1; + if (DirectDraw_Start (md1->primary ? NULL : &md1->guid)) { + if (SUCCEEDED (DirectDraw_GetDisplayMode ())) { + int w = DirectDraw_CurrentWidth (); + int h = DirectDraw_CurrentHeight (); + int b = DirectDraw_GetCurrentDepth (); + int maxw = 0, maxh = 0; + + DirectDraw_EnumDisplayModes (DDEDM_REFRESHRATES, modesCallback, md1); + idx2 = 0; + while (md1->DisplayModes[idx2].depth >= 0) { + struct PicassoResolution *pr = &md1->DisplayModes[idx2]; + if (pr->res.width > maxw) + maxw = pr->res.width; + if (pr->res.height > maxh) + maxh = pr->res.height; + idx2++; } - } - } - idx2++; - } - if (!found) { - int freq = 0; + write_log (L"Desktop: W=%d H=%d B=%d. MaxW=%d MaxH=%d CXVS=%d CYVS=%d\n", w, h, b, maxw, maxh, + GetSystemMetrics (SM_CXVIRTUALSCREEN), GetSystemMetrics (SM_CYVIRTUALSCREEN)); + idx = 0; + for (;;) { + int found; + DEVMODE dm; + dm.dmSize = sizeof dm; + dm.dmDriverExtra = 0; + if (!EnumDisplaySettingsEx (md1->primary ? NULL : md1->name3, idx, &dm, EDS_RAWMODE)) + break; + idx2 = 0; + found = 0; + while (md1->DisplayModes[idx2].depth >= 0 && !found) { + struct PicassoResolution *pr = &md1->DisplayModes[idx2]; + if (pr->res.width == dm.dmPelsWidth && pr->res.height == dm.dmPelsHeight && pr->depth == dm.dmBitsPerPel / 8) { + for (i = 0; pr->refresh[i]; i++) { + if (pr->refresh[i] == dm.dmDisplayFrequency) { + found = 1; + break; + } + } + } + idx2++; + } + if (!found) { + int freq = 0; #if 0 - write_log (L"EnumDisplaySettings(%dx%dx%d %dHz %08x)\n", - dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, dm.dmDisplayFrequency, dm.dmFields); + write_log (L"EnumDisplaySettings(%dx%dx%d %dHz %08x)\n", + dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, dm.dmDisplayFrequency, dm.dmFields); #endif - if (dm.dmFields & DM_DISPLAYFREQUENCY) { - freq = dm.dmDisplayFrequency; - if (freq < 10) - freq = 0; - } - if (freq < 75 && dm.dmPelsWidth <= maxw && dm.dmPelsHeight <= maxh) { - if ((dm.dmFields & DM_PELSWIDTH) && (dm.dmFields & DM_PELSHEIGHT) && (dm.dmFields & DM_BITSPERPEL)) - addmode (md1, dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, freq, 1); + if (dm.dmFields & DM_DISPLAYFREQUENCY) { + freq = dm.dmDisplayFrequency; + if (freq < 10) + freq = 0; + } + if (freq < 75 && dm.dmPelsWidth <= maxw && dm.dmPelsHeight <= maxh) { + if ((dm.dmFields & DM_PELSWIDTH) && (dm.dmFields & DM_PELSHEIGHT) && (dm.dmFields & DM_BITSPERPEL)) + addmode (md1, dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, freq, 1); + } + } + idx++; + } + //dhack(); + sortmodes (md1); + modesList (md1); + DirectDraw_Release (); + if (md1->DisplayModes[0].depth >= 0) + md1->disabled = 0; } - } - idx++; } - //dhack(); - sortmodes (md1); - modesList (md1); - DirectDraw_Release (); - if (md1->DisplayModes[0].depth >= 0) - md1->disabled = 0; - } + i = 0; + while (md1->DisplayModes[i].depth > 0) + i++; + write_log (L"'%s', %d display modes (%s)\n", md1->name, i, md1->disabled ? L"disabled" : L"enabled"); + md1++; } - i = 0; - while (md1->DisplayModes[i].depth > 0) - i++; - write_log (L"'%s', %d display modes (%s)\n", md1->name, i, md1->disabled ? L"disabled" : L"enabled"); - md1++; - } - displayGUID = NULL; + displayGUID = NULL; } /* DirectX will fail with "Mode not supported" if we try to switch to a full - * screen mode that doesn't match one of the dimensions we got during enumeration. - * So try to find a best match for the given resolution in our list. */ +* screen mode that doesn't match one of the dimensions we got during enumeration. +* So try to find a best match for the given resolution in our list. */ int WIN32GFX_AdjustScreenmode (struct MultiDisplay *md, uae_u32 *pwidth, uae_u32 *pheight, uae_u32 *ppixbits) { - struct PicassoResolution *best; - uae_u32 selected_mask = (*ppixbits == 8 ? RGBMASK_8BIT - : *ppixbits == 15 ? RGBMASK_15BIT - : *ppixbits == 16 ? RGBMASK_16BIT - : *ppixbits == 24 ? RGBMASK_24BIT - : RGBMASK_32BIT); - int pass, i = 0, index = 0; - - for (pass = 0; pass < 2; pass++) { - struct PicassoResolution *dm; - uae_u32 mask = (pass == 0 + struct PicassoResolution *best; + uae_u32 selected_mask = (*ppixbits == 8 ? RGBMASK_8BIT + : *ppixbits == 15 ? RGBMASK_15BIT + : *ppixbits == 16 ? RGBMASK_16BIT + : *ppixbits == 24 ? RGBMASK_24BIT + : RGBMASK_32BIT); + int pass, i = 0, index = 0; + + for (pass = 0; pass < 2; pass++) { + struct PicassoResolution *dm; + uae_u32 mask = (pass == 0 ? selected_mask : RGBMASK_8BIT | RGBMASK_15BIT | RGBMASK_16BIT | RGBMASK_24BIT | RGBMASK_32BIT); /* %%% - BERND, were you missing 15-bit here??? */ - i = 0; - index = 0; + i = 0; + index = 0; - best = &md->DisplayModes[0]; - dm = &md->DisplayModes[1]; + best = &md->DisplayModes[0]; + dm = &md->DisplayModes[1]; - while (dm->depth >= 0) { + while (dm->depth >= 0) { - /* do we already have supported resolution? */ - if (dm->res.width == *pwidth && dm->res.height == *pheight && dm->depth == (*ppixbits / 8)) - return i; + /* do we already have supported resolution? */ + if (dm->res.width == *pwidth && dm->res.height == *pheight && dm->depth == (*ppixbits / 8)) + return i; - if ((dm->colormodes & mask) != 0) { - if (dm->res.width <= best->res.width && dm->res.height <= best->res.height - && dm->res.width >= *pwidth && dm->res.height >= *pheight) - { - best = dm; - index = i; + if ((dm->colormodes & mask) != 0) { + if (dm->res.width <= best->res.width && dm->res.height <= best->res.height + && dm->res.width >= *pwidth && dm->res.height >= *pheight) + { + best = dm; + index = i; + } + if (dm->res.width >= best->res.width && dm->res.height >= best->res.height + && dm->res.width <= *pwidth && dm->res.height <= *pheight) + { + best = dm; + index = i; + } + } + dm++; + i++; } - if (dm->res.width >= best->res.width && dm->res.height >= best->res.height - && dm->res.width <= *pwidth && dm->res.height <= *pheight) - { - best = dm; - index = i; + if (best->res.width == *pwidth && best->res.height == *pheight) { + selected_mask = mask; /* %%% - BERND, I added this - does it make sense? Otherwise, I'd specify a 16-bit display-mode for my + Workbench (using -H 2, but SHOULD have been -H 1), and end up with an 8-bit mode instead*/ + break; } - } - dm++; - i++; - } - if (best->res.width == *pwidth && best->res.height == *pheight) { - selected_mask = mask; /* %%% - BERND, I added this - does it make sense? Otherwise, I'd specify a 16-bit display-mode for my - Workbench (using -H 2, but SHOULD have been -H 1), and end up with an 8-bit mode instead*/ - break; - } - } - *pwidth = best->res.width; - *pheight = best->res.height; - if (best->colormodes & selected_mask) - return index; - - /* Ordering here is done such that 16-bit is preferred, followed by 15-bit, 8-bit, 32-bit and 24-bit */ - if (best->colormodes & RGBMASK_16BIT) - *ppixbits = 16; - else if (best->colormodes & RGBMASK_15BIT) /* %%% - BERND, this possibility was missing? */ - *ppixbits = 15; - else if (best->colormodes & RGBMASK_8BIT) - *ppixbits = 8; - else if (best->colormodes & RGBMASK_32BIT) - *ppixbits = 32; - else if (best->colormodes & RGBMASK_24BIT) - *ppixbits = 24; - else - index = -1; + } + *pwidth = best->res.width; + *pheight = best->res.height; + if (best->colormodes & selected_mask) + return index; + + /* Ordering here is done such that 16-bit is preferred, followed by 15-bit, 8-bit, 32-bit and 24-bit */ + if (best->colormodes & RGBMASK_16BIT) + *ppixbits = 16; + else if (best->colormodes & RGBMASK_15BIT) /* %%% - BERND, this possibility was missing? */ + *ppixbits = 15; + else if (best->colormodes & RGBMASK_8BIT) + *ppixbits = 8; + else if (best->colormodes & RGBMASK_32BIT) + *ppixbits = 32; + else if (best->colormodes & RGBMASK_24BIT) + *ppixbits = 24; + else + index = -1; - return index; + return index; } void flush_line (int lineno) @@ -795,88 +795,88 @@ void flush_block (int a, int b) void flush_screen (int a, int b) { - if (dx_islost ()) - return; - if (currentmode->flags & DM_OPENGL) { + if (dx_islost ()) + return; + if (currentmode->flags & DM_OPENGL) { #ifdef OPENGL - OGL_render (); + OGL_render (); #endif - } else if (currentmode->flags & DM_D3D) { - return; + } else if (currentmode->flags & DM_D3D) { + return; #ifdef GFXFILTER - } else if (currentmode->flags & DM_SWSCALE) { - S2X_render (); - DirectDraw_Flip (1); + } else if (currentmode->flags & DM_SWSCALE) { + S2X_render (); + DirectDraw_Flip (1); #endif - } else if (currentmode->flags & DM_DDRAW) { - DirectDraw_Flip (1); - } + } else if (currentmode->flags & DM_DDRAW) { + DirectDraw_Flip (1); + } } static uae_u8 *ddraw_dolock (void) { - if (dx_islost ()) - return 0; - if (!DirectDraw_SurfaceLock ()) - return 0; - gfxvidinfo.bufmem = DirectDraw_GetSurfacePointer (); - gfxvidinfo.rowbytes = DirectDraw_GetSurfacePitch (); - init_row_map (); - clear_inhibit_frame (IHF_WINDOWHIDDEN); - return gfxvidinfo.bufmem; + if (dx_islost ()) + return 0; + if (!DirectDraw_SurfaceLock ()) + return 0; + gfxvidinfo.bufmem = DirectDraw_GetSurfacePointer (); + gfxvidinfo.rowbytes = DirectDraw_GetSurfacePitch (); + init_row_map (); + clear_inhibit_frame (IHF_WINDOWHIDDEN); + return gfxvidinfo.bufmem; } int lockscr (void) { - int ret = 0; - if (!isscreen ()) - return ret; - ret = 1; - if (currentmode->flags & DM_D3D) { + int ret = 0; + if (!isscreen ()) + return ret; + ret = 1; + if (currentmode->flags & DM_D3D) { #ifdef D3D - if (D3D_needreset ()) - WIN32GFX_DisplayChangeRequested (); - ret = D3D_locktexture (); + if (D3D_needreset ()) + WIN32GFX_DisplayChangeRequested (); + ret = D3D_locktexture (); #endif - } else if (currentmode->flags & DM_SWSCALE) { - ret = 1; - } else if (currentmode->flags & DM_DDRAW) { - ret = ddraw_dolock () != 0; - } - return ret; + } else if (currentmode->flags & DM_SWSCALE) { + ret = 1; + } else if (currentmode->flags & DM_DDRAW) { + ret = ddraw_dolock () != 0; + } + return ret; } void unlockscr (void) { - if (currentmode->flags & DM_D3D) { + if (currentmode->flags & DM_D3D) { #ifdef D3D - D3D_unlocktexture (); + D3D_unlocktexture (); #endif - } else if (currentmode->flags & DM_SWSCALE) { - return; - } else if (currentmode->flags & DM_DDRAW) { - DirectDraw_SurfaceUnlock (); - } + } else if (currentmode->flags & DM_SWSCALE) { + return; + } else if (currentmode->flags & DM_DDRAW) { + DirectDraw_SurfaceUnlock (); + } } void flush_clear_screen (void) { - if (lockscr ()) { - int y; - for (y = 0; y < gfxvidinfo.height; y++) { - memset (gfxvidinfo.bufmem + y * gfxvidinfo.rowbytes, 0, gfxvidinfo.width * gfxvidinfo.pixbytes); + if (lockscr ()) { + int y; + for (y = 0; y < gfxvidinfo.height; y++) { + memset (gfxvidinfo.bufmem + y * gfxvidinfo.rowbytes, 0, gfxvidinfo.width * gfxvidinfo.pixbytes); + } + unlockscr (); + flush_screen (0, 0); } - unlockscr (); - flush_screen (0, 0); - } } uae_u8 *gfx_lock_picasso (void) { - if (!DirectDraw_SurfaceLock ()) - return 0; - picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch (); - return DirectDraw_GetSurfacePointer (); + if (!DirectDraw_SurfaceLock ()) + return 0; + picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch (); + return DirectDraw_GetSurfacePointer (); } /* For the DX_Invalidate() and gfx_unlock_picasso() functions */ @@ -886,547 +886,547 @@ static int p96_double_buffer_needs_flushing = 0; static void DX_Blit96 (int x, int y, int w, int h) { - RECT dr, sr; + RECT dr, sr; - picasso_offset_x = 0; - picasso_offset_y = 0; - picasso_offset_mx = 1000; - picasso_offset_my = 1000; - if (scalepicasso) { - int srcratio, dstratio; - int srcwidth, srcheight; + picasso_offset_x = 0; + picasso_offset_y = 0; + picasso_offset_mx = 1000; + picasso_offset_my = 1000; + if (scalepicasso) { + int srcratio, dstratio; + int srcwidth, srcheight; - if (scalepicasso < 0) { - srcwidth = picasso96_state.Width; - srcheight = picasso96_state.Height; - } else { - srcwidth = currentmode->native_width; - srcheight = currentmode->native_height; - } - - SetRect (&sr, 0, 0, picasso96_state.Width, picasso96_state.Height); - if (currprefs.win32_rtgscaleaspectratio < 0) { - // automatic - srcratio = picasso96_state.Width * 256 / picasso96_state.Height; - dstratio = srcwidth * 256 / srcheight; - } else if (currprefs.win32_rtgscaleaspectratio == 0) { - // none - srcratio = dstratio = 0; - } else { - // manual - srcratio = (currprefs.win32_rtgscaleaspectratio >> 8) * 256 / (currprefs.win32_rtgscaleaspectratio & 0xff); - dstratio = srcwidth * 256 / srcheight; - } - if (srcratio == dstratio) { - SetRect (&dr, 0, 0, srcwidth, srcheight); - } else if (srcratio > dstratio) { - int yy = srcheight - srcheight * dstratio / srcratio; - SetRect (&dr, 0, yy / 2, srcwidth, srcheight - yy / 2); - picasso_offset_y = yy / 2; + if (scalepicasso < 0) { + srcwidth = picasso96_state.Width; + srcheight = picasso96_state.Height; + } else { + srcwidth = currentmode->native_width; + srcheight = currentmode->native_height; + } + + SetRect (&sr, 0, 0, picasso96_state.Width, picasso96_state.Height); + if (currprefs.win32_rtgscaleaspectratio < 0) { + // automatic + srcratio = picasso96_state.Width * 256 / picasso96_state.Height; + dstratio = srcwidth * 256 / srcheight; + } else if (currprefs.win32_rtgscaleaspectratio == 0) { + // none + srcratio = dstratio = 0; + } else { + // manual + srcratio = (currprefs.win32_rtgscaleaspectratio >> 8) * 256 / (currprefs.win32_rtgscaleaspectratio & 0xff); + dstratio = srcwidth * 256 / srcheight; + } + if (srcratio == dstratio) { + SetRect (&dr, 0, 0, srcwidth, srcheight); + } else if (srcratio > dstratio) { + int yy = srcheight - srcheight * dstratio / srcratio; + SetRect (&dr, 0, yy / 2, srcwidth, srcheight - yy / 2); + picasso_offset_y = yy / 2; + } else { + int xx = srcwidth - srcwidth * srcratio / dstratio; + SetRect (&dr, xx / 2, 0,srcwidth - xx / 2, srcheight); + picasso_offset_x = xx / 2; + } + picasso_offset_mx = picasso96_state.Width * 1000 / (dr.right - dr.left); + picasso_offset_my = picasso96_state.Height * 1000 / (dr.bottom - dr.top); + DirectDraw_BlitToPrimaryScale (&dr, &sr); } else { - int xx = srcwidth - srcwidth * srcratio / dstratio; - SetRect (&dr, xx / 2, 0,srcwidth - xx / 2, srcheight); - picasso_offset_x = xx / 2; + SetRect (&sr, x, y, x + w, y + h); + DirectDraw_BlitToPrimary (&sr); } - picasso_offset_mx = picasso96_state.Width * 1000 / (dr.right - dr.left); - picasso_offset_my = picasso96_state.Height * 1000 / (dr.bottom - dr.top); - DirectDraw_BlitToPrimaryScale (&dr, &sr); - } else { - SetRect (&sr, x, y, x + w, y + h); - DirectDraw_BlitToPrimary (&sr); - } } void gfx_unlock_picasso (void) { - DirectDraw_SurfaceUnlock (); - if (p96_double_buffer_needs_flushing) { - if (scalepicasso) { - p96_double_buffer_firstx = 0; - p96_double_buffer_lastx = picasso96_state.Width; - p96_double_buffer_first = 0; - p96_double_buffer_last = picasso96_state.Height; + DirectDraw_SurfaceUnlock (); + if (p96_double_buffer_needs_flushing) { + if (scalepicasso) { + p96_double_buffer_firstx = 0; + p96_double_buffer_lastx = picasso96_state.Width; + p96_double_buffer_first = 0; + p96_double_buffer_last = picasso96_state.Height; + } + 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_Blit96 (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 (); + p96_double_buffer_needs_flushing = 0; } - 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_Blit96 (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 (); - p96_double_buffer_needs_flushing = 0; - } } static void close_hwnds (void) { - screen_is_initialized = 0; + screen_is_initialized = 0; #ifdef AVIOUTPUT - AVIOutput_Restart (); + AVIOutput_Restart (); #endif - setmouseactive (0); + setmouseactive (0); #ifdef RETROPLATFORM - rp_set_hwnd (NULL); + rp_set_hwnd (NULL); #endif - if (hStatusWnd) { - ShowWindow (hStatusWnd, SW_HIDE); - DestroyWindow (hStatusWnd); - hStatusWnd = 0; - } - if (hAmigaWnd) { - addnotifications (hAmigaWnd, TRUE, FALSE); + if (hStatusWnd) { + ShowWindow (hStatusWnd, SW_HIDE); + DestroyWindow (hStatusWnd); + hStatusWnd = 0; + } + if (hAmigaWnd) { + addnotifications (hAmigaWnd, TRUE, FALSE); #ifdef OPENGL - OGL_free (); + OGL_free (); #endif #ifdef D3D - D3D_free (); + D3D_free (); #endif - ShowWindow (hAmigaWnd, SW_HIDE); - DestroyWindow (hAmigaWnd); - if (hAmigaWnd == hMainWnd) - hMainWnd = 0; - hAmigaWnd = 0; - } - if (hMainWnd) { - ShowWindow (hMainWnd, SW_HIDE); - DestroyWindow (hMainWnd); - hMainWnd = 0; - } + ShowWindow (hAmigaWnd, SW_HIDE); + DestroyWindow (hAmigaWnd); + if (hAmigaWnd == hMainWnd) + hMainWnd = 0; + hAmigaWnd = 0; + } + if (hMainWnd) { + ShowWindow (hMainWnd, SW_HIDE); + DestroyWindow (hMainWnd); + hMainWnd = 0; + } } static void updatemodes (void) { - DWORD flags; + DWORD flags; - currentmode->fullfill = 0; - flags = DM_DDRAW; - if (isfullscreen () > 0) - flags |= DM_DX_FULLSCREEN; - else if (isfullscreen () < 0) - flags |= DM_W_FULLSCREEN; + currentmode->fullfill = 0; + flags = DM_DDRAW; + if (isfullscreen () > 0) + flags |= DM_DX_FULLSCREEN; + else if (isfullscreen () < 0) + flags |= DM_W_FULLSCREEN; #if defined (GFXFILTER) - if (usedfilter) { - if (!usedfilter->x[0]) { - flags |= DM_SWSCALE; - if (currentmode->current_depth < 15) - currentmode->current_depth = 16; - } - if (!screen_is_picasso) { - if (usedfilter->type == UAE_FILTER_DIRECT3D) { - flags |= DM_D3D; - if (flags & DM_DX_FULLSCREEN) { - flags &= ~DM_DX_FULLSCREEN; - flags |= DM_D3D_FULLSCREEN; + if (usedfilter) { + if (!usedfilter->x[0]) { + flags |= DM_SWSCALE; + if (currentmode->current_depth < 15) + currentmode->current_depth = 16; } - flags &= ~DM_DDRAW; - } + if (!screen_is_picasso) { + if (usedfilter->type == UAE_FILTER_DIRECT3D) { + flags |= DM_D3D; + if (flags & DM_DX_FULLSCREEN) { + flags &= ~DM_DX_FULLSCREEN; + flags |= DM_D3D_FULLSCREEN; + } + flags &= ~DM_DDRAW; + } #if defined (OPENGL) - if (usedfilter->type == UAE_FILTER_OPENGL) { - flags |= DM_OPENGL; - flags &= ~DM_DDRAW; - } + if (usedfilter->type == UAE_FILTER_OPENGL) { + flags |= DM_OPENGL; + flags &= ~DM_DDRAW; + } #endif - } - } + } + } #endif - currentmode->flags = flags; - if (flags & DM_SWSCALE) - currentmode->fullfill = 1; - if (useoverlay && currentmode->current_depth > 16) - currentmode->current_depth = 16; - if (flags & DM_W_FULLSCREEN) { - RECT rc = getdisplay (&currprefs)->rect; - currentmode->native_width = rc.right - rc.left; - currentmode->native_height = rc.bottom - rc.top; - currentmode->current_width = currentmode->native_width; - currentmode->current_height = currentmode->native_height; - } else { - currentmode->native_width = currentmode->current_width; - currentmode->native_height = currentmode->current_height; - } + currentmode->flags = flags; + if (flags & DM_SWSCALE) + currentmode->fullfill = 1; + if (useoverlay && currentmode->current_depth > 16) + currentmode->current_depth = 16; + if (flags & DM_W_FULLSCREEN) { + RECT rc = getdisplay (&currprefs)->rect; + currentmode->native_width = rc.right - rc.left; + currentmode->native_height = rc.bottom - rc.top; + currentmode->current_width = currentmode->native_width; + currentmode->current_height = currentmode->native_height; + } else { + currentmode->native_width = currentmode->current_width; + currentmode->native_height = currentmode->current_height; + } } static void update_gfxparams (void) { - updatewinfsmode (&currprefs); + updatewinfsmode (&currprefs); #ifdef PICASSO96 - currentmode->vsync = 0; - if (screen_is_picasso) { - currentmode->current_width = picasso96_state.Width; - currentmode->current_height = picasso96_state.Height; - currentmode->frequency = abs (currprefs.gfx_refreshrate > default_freq ? currprefs.gfx_refreshrate : default_freq); - if (currprefs.gfx_pvsync) - currentmode->vsync = 1; - } else { + currentmode->vsync = 0; + if (screen_is_picasso) { + currentmode->current_width = picasso96_state.Width; + currentmode->current_height = picasso96_state.Height; + currentmode->frequency = abs (currprefs.gfx_refreshrate > default_freq ? currprefs.gfx_refreshrate : default_freq); + if (currprefs.gfx_pvsync) + currentmode->vsync = 1; + } else { #endif - currentmode->current_width = currprefs.gfx_size.width; - currentmode->current_height = currprefs.gfx_size.height; - currentmode->frequency = abs (currprefs.gfx_refreshrate); - if (currprefs.gfx_avsync) - currentmode->vsync = 1; + currentmode->current_width = currprefs.gfx_size.width; + currentmode->current_height = currprefs.gfx_size.height; + currentmode->frequency = abs (currprefs.gfx_refreshrate); + if (currprefs.gfx_avsync) + currentmode->vsync = 1; #ifdef PICASSO96 - } + } #endif - 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 == 24) - pbits = 32; - if (pbits >= 8) - currentmode->current_depth = pbits; - } - if (useoverlay && currentmode->current_depth > 16) - currentmode->current_depth = 16; - currentmode->amiga_width = currentmode->current_width; - currentmode->amiga_height = currentmode->current_height; - - scalepicasso = 0; - if (screen_is_picasso) { - if (isfullscreen () < 0) { - if ((currprefs.win32_rtgscaleifsmall || currprefs.win32_rtgallowscaling) && (picasso96_state.Width != currentmode->native_width || picasso96_state.Height != currentmode->native_height)) - scalepicasso = 1; - if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) - scalepicasso = -1; - } else if (isfullscreen () > 0) { - if (!currprefs.win32_rtgmatchdepth) { // can't scale to different color depth - if (currentmode->native_width > picasso96_state.Width && currentmode->native_height > picasso96_state.Height) { - if (currprefs.win32_rtgscaleifsmall) - scalepicasso = 1; - } - if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) - scalepicasso = -1; - } - } else if (isfullscreen () == 0) { - if ((currprefs.gfx_size.width != picasso96_state.Width || currprefs.gfx_size.height != picasso96_state.Height) && currprefs.win32_rtgallowscaling) - scalepicasso = 1; - if ((currprefs.gfx_size.width > picasso96_state.Width || currprefs.gfx_size.height > picasso96_state.Height) && currprefs.win32_rtgscaleifsmall) - scalepicasso = 1; - if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) - scalepicasso = -1; + 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 == 24) + pbits = 32; + if (pbits >= 8) + currentmode->current_depth = pbits; } + if (useoverlay && currentmode->current_depth > 16) + currentmode->current_depth = 16; + currentmode->amiga_width = currentmode->current_width; + currentmode->amiga_height = currentmode->current_height; - if (scalepicasso > 0 && (currprefs.gfx_size.width != picasso96_state.Width || currprefs.gfx_size.height != picasso96_state.Height)) { - currentmode->current_width = currprefs.gfx_size.width; - currentmode->current_height = currprefs.gfx_size.height; + scalepicasso = 0; + if (screen_is_picasso) { + if (isfullscreen () < 0) { + if ((currprefs.win32_rtgscaleifsmall || currprefs.win32_rtgallowscaling) && (picasso96_state.Width != currentmode->native_width || picasso96_state.Height != currentmode->native_height)) + scalepicasso = 1; + if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) + scalepicasso = -1; + } else if (isfullscreen () > 0) { + if (!currprefs.win32_rtgmatchdepth) { // can't scale to different color depth + if (currentmode->native_width > picasso96_state.Width && currentmode->native_height > picasso96_state.Height) { + if (currprefs.win32_rtgscaleifsmall) + scalepicasso = 1; + } + if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) + scalepicasso = -1; + } + } else if (isfullscreen () == 0) { + if ((currprefs.gfx_size.width != picasso96_state.Width || currprefs.gfx_size.height != picasso96_state.Height) && currprefs.win32_rtgallowscaling) + scalepicasso = 1; + if ((currprefs.gfx_size.width > picasso96_state.Width || currprefs.gfx_size.height > picasso96_state.Height) && currprefs.win32_rtgscaleifsmall) + scalepicasso = 1; + if (!scalepicasso && currprefs.win32_rtgscaleaspectratio) + scalepicasso = -1; + } + + if (scalepicasso > 0 && (currprefs.gfx_size.width != picasso96_state.Width || currprefs.gfx_size.height != picasso96_state.Height)) { + currentmode->current_width = currprefs.gfx_size.width; + currentmode->current_height = currprefs.gfx_size.height; + } } - } } static int open_windows (int full) { - int ret, i; + int ret, i; - inputdevice_unacquire (); - reset_sound (); - in_sizemove = 0; + inputdevice_unacquire (); + reset_sound (); + in_sizemove = 0; - updatewinfsmode (&currprefs); + updatewinfsmode (&currprefs); #ifdef D3D - D3D_free (); + D3D_free (); #endif #ifdef OPENGL - OGL_free (); + OGL_free (); #endif - if (!DirectDraw_Start (displayGUID)) - return 0; - write_log (L"DirectDraw GUID=%s\n", outGUID (displayGUID)); + if (!DirectDraw_Start (displayGUID)) + return 0; + write_log (L"DirectDraw GUID=%s\n", outGUID (displayGUID)); - ret = -2; - do { - if (ret < -1) { - updatemodes (); - update_gfxparams (); - } - ret = doInit (); - } while (ret < 0); + ret = -2; + do { + if (ret < -1) { + updatemodes (); + update_gfxparams (); + } + ret = doInit (); + } while (ret < 0); - if (!ret) { - DirectDraw_Release (); - return ret; - } + if (!ret) { + DirectDraw_Release (); + return ret; + } - setpriority (&priorities[currprefs.win32_active_priority]); - if (!rp_isactive () && full) - setmouseactive (-1); - for (i = 0; i < NUM_LEDS; i++) - gui_led (i, 0); - gui_fps (0, 0); - inputdevice_acquire (TRUE); + setpriority (&priorities[currprefs.win32_active_priority]); + if (!rp_isactive () && full) + setmouseactive (-1); + for (i = 0; i < NUM_LEDS; i++) + gui_led (i, 0); + gui_fps (0, 0); + inputdevice_acquire (TRUE); - return ret; + return ret; } int check_prefs_changed_gfx (void) { - int c = 0; + int c = 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 + 7) & ~7) != ((changed_prefs.gfx_size_win.width + 7) & ~7) ? 16 : 0; - c |= currprefs.gfx_size_win.height != changed_prefs.gfx_size_win.height ? 16 : 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 + 7) & ~7) != ((changed_prefs.gfx_size_win.width + 7) & ~7) ? 16 : 0; + c |= currprefs.gfx_size_win.height != changed_prefs.gfx_size_win.height ? 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; + 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 | 16 : 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; - c |= _tcscmp (currprefs.gfx_filtershader, changed_prefs.gfx_filtershader) ? (2|8|32) : 0; - c |= currprefs.gfx_filter_filtermode != changed_prefs.gfx_filter_filtermode ? (2|8|32) : 0; - c |= currprefs.gfx_filter_horiz_zoom_mult != changed_prefs.gfx_filter_horiz_zoom_mult ? (1|8) : 0; - c |= currprefs.gfx_filter_vert_zoom_mult != changed_prefs.gfx_filter_vert_zoom_mult ? (1|8) : 0; - c |= currprefs.gfx_filter_noise != changed_prefs.gfx_filter_noise ? (1|8) : 0; - c |= currprefs.gfx_filter_blur != changed_prefs.gfx_filter_blur ? (1|8) : 0; - c |= currprefs.gfx_filter_scanlines != changed_prefs.gfx_filter_scanlines ? (1|8) : 0; - c |= currprefs.gfx_filter_scanlinelevel != changed_prefs.gfx_filter_scanlinelevel ? (1|8) : 0; - c |= currprefs.gfx_filter_scanlineratio != changed_prefs.gfx_filter_scanlineratio ? (1|8) : 0; - c |= currprefs.gfx_filter_aspect != changed_prefs.gfx_filter_aspect ? (1|8) : 0; - c |= currprefs.gfx_filter_luminance != changed_prefs.gfx_filter_luminance ? (1|8) : 0; - c |= currprefs.gfx_filter_contrast != changed_prefs.gfx_filter_contrast ? (1|8) : 0; - c |= currprefs.gfx_filter_saturation != changed_prefs.gfx_filter_saturation ? (1|8) : 0; - c |= currprefs.gfx_filter_gamma != changed_prefs.gfx_filter_gamma ? (1|8) : 0; - //c |= currprefs.gfx_filter_ != changed_prefs.gfx_filter_ ? (1|8) : 0; - - c |= currprefs.gfx_resolution != changed_prefs.gfx_resolution ? (2 | 8) : 0; - c |= currprefs.gfx_linedbl != changed_prefs.gfx_linedbl ? (2 | 8) : 0; - c |= currprefs.gfx_lores_mode != changed_prefs.gfx_lores_mode ? (2 | 8) : 0; - c |= currprefs.gfx_scandoubler != changed_prefs.gfx_scandoubler ? (2 | 8) : 0; - c |= currprefs.gfx_display != changed_prefs.gfx_display ? (2|4|8) : 0; - c |= _tcscmp (currprefs.gfx_display_name, changed_prefs.gfx_display_name) ? (2|4|8) : 0; - c |= currprefs.gfx_blackerthanblack != changed_prefs.gfx_blackerthanblack ? (2 | 8) : 0; - - c |= currprefs.win32_alwaysontop != changed_prefs.win32_alwaysontop ? 32 : 0; - c |= currprefs.win32_notaskbarbutton != changed_prefs.win32_notaskbarbutton ? 32 : 0; - c |= currprefs.win32_borderless != changed_prefs.win32_borderless ? 32 : 0; - c |= currprefs.win32_rtgmatchdepth != changed_prefs.win32_rtgmatchdepth ? 2 : 0; - c |= currprefs.win32_rtgscaleifsmall != changed_prefs.win32_rtgscaleifsmall ? (2 | 8 | 64) : 0; - c |= currprefs.win32_rtgallowscaling != changed_prefs.win32_rtgallowscaling ? (2 | 8 | 64) : 0; - c |= currprefs.win32_rtgscaleaspectratio != changed_prefs.win32_rtgscaleaspectratio ? (8 | 64) : 0; - c |= currprefs.win32_rtgvblankrate != changed_prefs.win32_rtgvblankrate ? 8 : 0; - - if (display_change_requested || c) - { - int keepfsmode = - currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && - currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen; - cfgfile_configuration_change (1); - - currprefs.gfx_autoresolution = changed_prefs.gfx_autoresolution; - currprefs.color_mode = changed_prefs.color_mode; - - if (changed_prefs.gfx_afullscreen == 1) { - if (currprefs.gfx_filter == UAE_FILTER_DIRECT3D && changed_prefs.gfx_filter != UAE_FILTER_DIRECT3D) - display_change_requested = 1; + c |= currprefs.color_mode != changed_prefs.color_mode ? 2 | 16 : 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; + c |= _tcscmp (currprefs.gfx_filtershader, changed_prefs.gfx_filtershader) ? (2|8|32) : 0; + c |= currprefs.gfx_filter_filtermode != changed_prefs.gfx_filter_filtermode ? (2|8|32) : 0; + c |= currprefs.gfx_filter_horiz_zoom_mult != changed_prefs.gfx_filter_horiz_zoom_mult ? (1|8) : 0; + c |= currprefs.gfx_filter_vert_zoom_mult != changed_prefs.gfx_filter_vert_zoom_mult ? (1|8) : 0; + c |= currprefs.gfx_filter_noise != changed_prefs.gfx_filter_noise ? (1|8) : 0; + c |= currprefs.gfx_filter_blur != changed_prefs.gfx_filter_blur ? (1|8) : 0; + c |= currprefs.gfx_filter_scanlines != changed_prefs.gfx_filter_scanlines ? (1|8) : 0; + c |= currprefs.gfx_filter_scanlinelevel != changed_prefs.gfx_filter_scanlinelevel ? (1|8) : 0; + c |= currprefs.gfx_filter_scanlineratio != changed_prefs.gfx_filter_scanlineratio ? (1|8) : 0; + c |= currprefs.gfx_filter_aspect != changed_prefs.gfx_filter_aspect ? (1|8) : 0; + c |= currprefs.gfx_filter_luminance != changed_prefs.gfx_filter_luminance ? (1|8) : 0; + c |= currprefs.gfx_filter_contrast != changed_prefs.gfx_filter_contrast ? (1|8) : 0; + c |= currprefs.gfx_filter_saturation != changed_prefs.gfx_filter_saturation ? (1|8) : 0; + c |= currprefs.gfx_filter_gamma != changed_prefs.gfx_filter_gamma ? (1|8) : 0; + //c |= currprefs.gfx_filter_ != changed_prefs.gfx_filter_ ? (1|8) : 0; + + c |= currprefs.gfx_resolution != changed_prefs.gfx_resolution ? (2 | 8) : 0; + c |= currprefs.gfx_linedbl != changed_prefs.gfx_linedbl ? (2 | 8) : 0; + c |= currprefs.gfx_lores_mode != changed_prefs.gfx_lores_mode ? (2 | 8) : 0; + c |= currprefs.gfx_scandoubler != changed_prefs.gfx_scandoubler ? (2 | 8) : 0; + c |= currprefs.gfx_display != changed_prefs.gfx_display ? (2|4|8) : 0; + c |= _tcscmp (currprefs.gfx_display_name, changed_prefs.gfx_display_name) ? (2|4|8) : 0; + c |= currprefs.gfx_blackerthanblack != changed_prefs.gfx_blackerthanblack ? (2 | 8) : 0; + + c |= currprefs.win32_alwaysontop != changed_prefs.win32_alwaysontop ? 32 : 0; + c |= currprefs.win32_notaskbarbutton != changed_prefs.win32_notaskbarbutton ? 32 : 0; + c |= currprefs.win32_borderless != changed_prefs.win32_borderless ? 32 : 0; + c |= currprefs.win32_rtgmatchdepth != changed_prefs.win32_rtgmatchdepth ? 2 : 0; + c |= currprefs.win32_rtgscaleifsmall != changed_prefs.win32_rtgscaleifsmall ? (2 | 8 | 64) : 0; + c |= currprefs.win32_rtgallowscaling != changed_prefs.win32_rtgallowscaling ? (2 | 8 | 64) : 0; + c |= currprefs.win32_rtgscaleaspectratio != changed_prefs.win32_rtgscaleaspectratio ? (8 | 64) : 0; + c |= currprefs.win32_rtgvblankrate != changed_prefs.win32_rtgvblankrate ? 8 : 0; + + if (display_change_requested || c) + { + int keepfsmode = + currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && + currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen; + cfgfile_configuration_change (1); + + currprefs.gfx_autoresolution = changed_prefs.gfx_autoresolution; + currprefs.color_mode = changed_prefs.color_mode; + + if (changed_prefs.gfx_afullscreen == 1) { + if (currprefs.gfx_filter == UAE_FILTER_DIRECT3D && changed_prefs.gfx_filter != UAE_FILTER_DIRECT3D) + display_change_requested = 1; #ifdef OPENGL - if (currprefs.gfx_filter == UAE_FILTER_OPENGL && changed_prefs.gfx_filter != UAE_FILTER_OPENGL) - display_change_requested = 1; - if (changed_prefs.gfx_filter == UAE_FILTER_OPENGL && currprefs.gfx_filter != UAE_FILTER_OPENGL) - display_change_requested = 1; + if (currprefs.gfx_filter == UAE_FILTER_OPENGL && changed_prefs.gfx_filter != UAE_FILTER_OPENGL) + display_change_requested = 1; + if (changed_prefs.gfx_filter == UAE_FILTER_OPENGL && currprefs.gfx_filter != UAE_FILTER_OPENGL) + display_change_requested = 1; #endif - if (changed_prefs.gfx_filter == UAE_FILTER_DIRECT3D && currprefs.gfx_filter != UAE_FILTER_DIRECT3D) - display_change_requested = 1; - } - - if (display_change_requested) { - c = 2; - keepfsmode = 0; - display_change_requested = 0; - } - - currprefs.gfx_filter = changed_prefs.gfx_filter; - _tcscpy (currprefs.gfx_filtershader, changed_prefs.gfx_filtershader); - currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode; - currprefs.gfx_filter_horiz_zoom_mult = changed_prefs.gfx_filter_horiz_zoom_mult; - currprefs.gfx_filter_vert_zoom_mult = changed_prefs.gfx_filter_vert_zoom_mult; - currprefs.gfx_filter_noise = changed_prefs.gfx_filter_noise; - currprefs.gfx_filter_blur = changed_prefs.gfx_filter_blur; - currprefs.gfx_filter_scanlines = changed_prefs.gfx_filter_scanlines; - currprefs.gfx_filter_scanlinelevel = changed_prefs.gfx_filter_scanlinelevel; - currprefs.gfx_filter_scanlineratio = changed_prefs.gfx_filter_scanlineratio; - currprefs.gfx_filter_aspect = changed_prefs.gfx_filter_aspect; - currprefs.gfx_filter_luminance = changed_prefs.gfx_filter_luminance; - currprefs.gfx_filter_contrast = changed_prefs.gfx_filter_contrast; - currprefs.gfx_filter_saturation = changed_prefs.gfx_filter_saturation; - currprefs.gfx_filter_gamma = changed_prefs.gfx_filter_gamma; - currprefs.gfx_filter_autoscale = changed_prefs.gfx_filter_autoscale; - //currprefs.gfx_filter_ = changed_prefs.gfx_filter_; - - currprefs.gfx_lores_mode = changed_prefs.gfx_lores_mode; - currprefs.gfx_scandoubler = changed_prefs.gfx_scandoubler; - currprefs.gfx_resolution = changed_prefs.gfx_resolution; - currprefs.gfx_linedbl = changed_prefs.gfx_linedbl; - currprefs.gfx_display = changed_prefs.gfx_display; - _tcscpy (currprefs.gfx_display_name, changed_prefs.gfx_display_name); - currprefs.gfx_blackerthanblack = changed_prefs.gfx_blackerthanblack; - - currprefs.win32_alwaysontop = changed_prefs.win32_alwaysontop; - currprefs.win32_notaskbarbutton = changed_prefs.win32_notaskbarbutton; - currprefs.win32_borderless = changed_prefs.win32_borderless; - currprefs.win32_rtgmatchdepth = changed_prefs.win32_rtgmatchdepth; - currprefs.win32_rtgscaleifsmall = changed_prefs.win32_rtgscaleifsmall; - currprefs.win32_rtgallowscaling = changed_prefs.win32_rtgallowscaling; - currprefs.win32_rtgscaleaspectratio = changed_prefs.win32_rtgscaleaspectratio; - currprefs.win32_rtgvblankrate = changed_prefs.win32_rtgvblankrate; + if (changed_prefs.gfx_filter == UAE_FILTER_DIRECT3D && currprefs.gfx_filter != UAE_FILTER_DIRECT3D) + display_change_requested = 1; + } - inputdevice_unacquire (); - if (c & 64) { - DirectDraw_Fill (NULL, 0); - DirectDraw_BlitToPrimary (NULL); - } - if ((c & 16) || ((c & 8) && keepfsmode)) { - extern int reopen (int); - if (reopen (c & 2)) - c |= 2; - } - if ((c & 32) || ((c & 2) && !keepfsmode)) { - close_windows (); - graphics_init (); + if (display_change_requested) { + c = 2; + keepfsmode = 0; + display_change_requested = 0; + } + + currprefs.gfx_filter = changed_prefs.gfx_filter; + _tcscpy (currprefs.gfx_filtershader, changed_prefs.gfx_filtershader); + currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode; + currprefs.gfx_filter_horiz_zoom_mult = changed_prefs.gfx_filter_horiz_zoom_mult; + currprefs.gfx_filter_vert_zoom_mult = changed_prefs.gfx_filter_vert_zoom_mult; + currprefs.gfx_filter_noise = changed_prefs.gfx_filter_noise; + currprefs.gfx_filter_blur = changed_prefs.gfx_filter_blur; + currprefs.gfx_filter_scanlines = changed_prefs.gfx_filter_scanlines; + currprefs.gfx_filter_scanlinelevel = changed_prefs.gfx_filter_scanlinelevel; + currprefs.gfx_filter_scanlineratio = changed_prefs.gfx_filter_scanlineratio; + currprefs.gfx_filter_aspect = changed_prefs.gfx_filter_aspect; + currprefs.gfx_filter_luminance = changed_prefs.gfx_filter_luminance; + currprefs.gfx_filter_contrast = changed_prefs.gfx_filter_contrast; + currprefs.gfx_filter_saturation = changed_prefs.gfx_filter_saturation; + currprefs.gfx_filter_gamma = changed_prefs.gfx_filter_gamma; + currprefs.gfx_filter_autoscale = changed_prefs.gfx_filter_autoscale; + //currprefs.gfx_filter_ = changed_prefs.gfx_filter_; + + currprefs.gfx_lores_mode = changed_prefs.gfx_lores_mode; + currprefs.gfx_scandoubler = changed_prefs.gfx_scandoubler; + currprefs.gfx_resolution = changed_prefs.gfx_resolution; + currprefs.gfx_linedbl = changed_prefs.gfx_linedbl; + currprefs.gfx_display = changed_prefs.gfx_display; + _tcscpy (currprefs.gfx_display_name, changed_prefs.gfx_display_name); + currprefs.gfx_blackerthanblack = changed_prefs.gfx_blackerthanblack; + + currprefs.win32_alwaysontop = changed_prefs.win32_alwaysontop; + currprefs.win32_notaskbarbutton = changed_prefs.win32_notaskbarbutton; + currprefs.win32_borderless = changed_prefs.win32_borderless; + currprefs.win32_rtgmatchdepth = changed_prefs.win32_rtgmatchdepth; + currprefs.win32_rtgscaleifsmall = changed_prefs.win32_rtgscaleifsmall; + currprefs.win32_rtgallowscaling = changed_prefs.win32_rtgallowscaling; + currprefs.win32_rtgscaleaspectratio = changed_prefs.win32_rtgscaleaspectratio; + currprefs.win32_rtgvblankrate = changed_prefs.win32_rtgvblankrate; + + inputdevice_unacquire (); + if (c & 64) { + DirectDraw_Fill (NULL, 0); + DirectDraw_BlitToPrimary (NULL); + } + if ((c & 16) || ((c & 8) && keepfsmode)) { + extern int reopen (int); + if (reopen (c & 2)) + c |= 2; + } + if ((c & 32) || ((c & 2) && !keepfsmode)) { + close_windows (); + graphics_init (); + } + init_custom (); + if (c & 4) { + pause_sound (); + resume_sound (); + } + inputdevice_acquire (TRUE); + return 1; } - init_custom (); - if (c & 4) { - pause_sound (); - resume_sound (); + + if (currprefs.chipset_refreshrate != changed_prefs.chipset_refreshrate) { + currprefs.chipset_refreshrate = changed_prefs.chipset_refreshrate; + init_hz (); + return 1; } - inputdevice_acquire (TRUE); - return 1; - } - if (currprefs.chipset_refreshrate != changed_prefs.chipset_refreshrate) { - currprefs.chipset_refreshrate = changed_prefs.chipset_refreshrate; - init_hz (); - return 1; - } - - if (currprefs.gfx_filter_autoscale != changed_prefs.gfx_filter_autoscale || - currprefs.gfx_xcenter_pos != changed_prefs.gfx_xcenter_pos || - currprefs.gfx_ycenter_pos != changed_prefs.gfx_ycenter_pos || - currprefs.gfx_xcenter_size != changed_prefs.gfx_xcenter_size || - currprefs.gfx_ycenter_size != changed_prefs.gfx_ycenter_size || - currprefs.gfx_xcenter != changed_prefs.gfx_xcenter || - currprefs.gfx_ycenter != changed_prefs.gfx_ycenter) - { - currprefs.gfx_xcenter_pos = changed_prefs.gfx_xcenter_pos; - currprefs.gfx_ycenter_pos = changed_prefs.gfx_ycenter_pos; - currprefs.gfx_xcenter_size = changed_prefs.gfx_xcenter_size; - currprefs.gfx_ycenter_size = changed_prefs.gfx_ycenter_size; - currprefs.gfx_xcenter = changed_prefs.gfx_xcenter; - currprefs.gfx_ycenter = changed_prefs.gfx_ycenter; - currprefs.gfx_filter_autoscale = changed_prefs.gfx_filter_autoscale; - - get_custom_limits (NULL, NULL, NULL, NULL); - fixup_prefs_dimensions (&changed_prefs); + if (currprefs.gfx_filter_autoscale != changed_prefs.gfx_filter_autoscale || + currprefs.gfx_xcenter_pos != changed_prefs.gfx_xcenter_pos || + currprefs.gfx_ycenter_pos != changed_prefs.gfx_ycenter_pos || + currprefs.gfx_xcenter_size != changed_prefs.gfx_xcenter_size || + currprefs.gfx_ycenter_size != changed_prefs.gfx_ycenter_size || + currprefs.gfx_xcenter != changed_prefs.gfx_xcenter || + currprefs.gfx_ycenter != changed_prefs.gfx_ycenter) + { + currprefs.gfx_xcenter_pos = changed_prefs.gfx_xcenter_pos; + currprefs.gfx_ycenter_pos = changed_prefs.gfx_ycenter_pos; + currprefs.gfx_xcenter_size = changed_prefs.gfx_xcenter_size; + currprefs.gfx_ycenter_size = changed_prefs.gfx_ycenter_size; + currprefs.gfx_xcenter = changed_prefs.gfx_xcenter; + currprefs.gfx_ycenter = changed_prefs.gfx_ycenter; + currprefs.gfx_filter_autoscale = changed_prefs.gfx_filter_autoscale; + + get_custom_limits (NULL, NULL, NULL, NULL); + fixup_prefs_dimensions (&changed_prefs); - return 1; - } + return 1; + } - if (currprefs.win32_norecyclebin != changed_prefs.win32_norecyclebin) { - currprefs.win32_norecyclebin = changed_prefs.win32_norecyclebin; - } + if (currprefs.win32_norecyclebin != changed_prefs.win32_norecyclebin) { + currprefs.win32_norecyclebin = changed_prefs.win32_norecyclebin; + } - if (currprefs.win32_logfile != changed_prefs.win32_logfile) { - currprefs.win32_logfile = changed_prefs.win32_logfile; - if (currprefs.win32_logfile) - logging_open (0, 1); - else - logging_cleanup (); - } - - if (currprefs.leds_on_screen != changed_prefs.leds_on_screen || - currprefs.keyboard_leds[0] != changed_prefs.keyboard_leds[0] || - currprefs.keyboard_leds[1] != changed_prefs.keyboard_leds[1] || - currprefs.keyboard_leds[2] != changed_prefs.keyboard_leds[2] || - currprefs.win32_middle_mouse != changed_prefs.win32_middle_mouse || - currprefs.win32_active_priority != changed_prefs.win32_active_priority || - currprefs.win32_inactive_priority != changed_prefs.win32_inactive_priority || - currprefs.win32_iconified_priority != changed_prefs.win32_iconified_priority || - currprefs.win32_inactive_nosound != changed_prefs.win32_inactive_nosound || - currprefs.win32_inactive_pause != changed_prefs.win32_inactive_pause || - currprefs.win32_iconified_nosound != changed_prefs.win32_iconified_nosound || - currprefs.win32_iconified_pause != changed_prefs.win32_iconified_pause || - currprefs.win32_ctrl_F11_is_quit != changed_prefs.win32_ctrl_F11_is_quit) - { - currprefs.leds_on_screen = changed_prefs.leds_on_screen; - currprefs.keyboard_leds[0] = changed_prefs.keyboard_leds[0]; - currprefs.keyboard_leds[1] = changed_prefs.keyboard_leds[1]; - currprefs.keyboard_leds[2] = changed_prefs.keyboard_leds[2]; - currprefs.win32_middle_mouse = changed_prefs.win32_middle_mouse; - currprefs.win32_active_priority = changed_prefs.win32_active_priority; - currprefs.win32_inactive_priority = changed_prefs.win32_inactive_priority; - currprefs.win32_iconified_priority = changed_prefs.win32_iconified_priority; - currprefs.win32_inactive_nosound = changed_prefs.win32_inactive_nosound; - currprefs.win32_inactive_pause = changed_prefs.win32_inactive_pause; - currprefs.win32_iconified_nosound = changed_prefs.win32_iconified_nosound; - currprefs.win32_iconified_pause = changed_prefs.win32_iconified_pause; - currprefs.win32_ctrl_F11_is_quit = changed_prefs.win32_ctrl_F11_is_quit; - inputdevice_unacquire (); - currprefs.keyboard_leds_in_use = currprefs.keyboard_leds[0] | currprefs.keyboard_leds[1] | currprefs.keyboard_leds[2]; - pause_sound (); - resume_sound (); - inputdevice_acquire (TRUE); + if (currprefs.win32_logfile != changed_prefs.win32_logfile) { + currprefs.win32_logfile = changed_prefs.win32_logfile; + if (currprefs.win32_logfile) + logging_open (0, 1); + else + logging_cleanup (); + } + + if (currprefs.leds_on_screen != changed_prefs.leds_on_screen || + currprefs.keyboard_leds[0] != changed_prefs.keyboard_leds[0] || + currprefs.keyboard_leds[1] != changed_prefs.keyboard_leds[1] || + currprefs.keyboard_leds[2] != changed_prefs.keyboard_leds[2] || + currprefs.win32_middle_mouse != changed_prefs.win32_middle_mouse || + currprefs.win32_active_priority != changed_prefs.win32_active_priority || + currprefs.win32_inactive_priority != changed_prefs.win32_inactive_priority || + currprefs.win32_iconified_priority != changed_prefs.win32_iconified_priority || + currprefs.win32_inactive_nosound != changed_prefs.win32_inactive_nosound || + currprefs.win32_inactive_pause != changed_prefs.win32_inactive_pause || + currprefs.win32_iconified_nosound != changed_prefs.win32_iconified_nosound || + currprefs.win32_iconified_pause != changed_prefs.win32_iconified_pause || + currprefs.win32_ctrl_F11_is_quit != changed_prefs.win32_ctrl_F11_is_quit) + { + currprefs.leds_on_screen = changed_prefs.leds_on_screen; + currprefs.keyboard_leds[0] = changed_prefs.keyboard_leds[0]; + currprefs.keyboard_leds[1] = changed_prefs.keyboard_leds[1]; + currprefs.keyboard_leds[2] = changed_prefs.keyboard_leds[2]; + currprefs.win32_middle_mouse = changed_prefs.win32_middle_mouse; + currprefs.win32_active_priority = changed_prefs.win32_active_priority; + currprefs.win32_inactive_priority = changed_prefs.win32_inactive_priority; + currprefs.win32_iconified_priority = changed_prefs.win32_iconified_priority; + currprefs.win32_inactive_nosound = changed_prefs.win32_inactive_nosound; + currprefs.win32_inactive_pause = changed_prefs.win32_inactive_pause; + currprefs.win32_iconified_nosound = changed_prefs.win32_iconified_nosound; + currprefs.win32_iconified_pause = changed_prefs.win32_iconified_pause; + currprefs.win32_ctrl_F11_is_quit = changed_prefs.win32_ctrl_F11_is_quit; + inputdevice_unacquire (); + currprefs.keyboard_leds_in_use = currprefs.keyboard_leds[0] | currprefs.keyboard_leds[1] | currprefs.keyboard_leds[2]; + pause_sound (); + resume_sound (); + inputdevice_acquire (TRUE); #ifndef _DEBUG - setpriority (&priorities[currprefs.win32_active_priority]); + setpriority (&priorities[currprefs.win32_active_priority]); #endif - return 1; - } - - if (_tcscmp (currprefs.prtname, changed_prefs.prtname) || - currprefs.parallel_autoflush_time != changed_prefs.parallel_autoflush_time || - currprefs.parallel_matrix_emulation != changed_prefs.parallel_matrix_emulation || - currprefs.parallel_postscript_emulation != changed_prefs.parallel_postscript_emulation || - currprefs.parallel_postscript_detection != changed_prefs.parallel_postscript_detection || - _tcscmp (currprefs.ghostscript_parameters, changed_prefs.ghostscript_parameters)) { - _tcscpy (currprefs.prtname, changed_prefs.prtname); - currprefs.parallel_autoflush_time = changed_prefs.parallel_autoflush_time; - currprefs.parallel_matrix_emulation = changed_prefs.parallel_matrix_emulation; - currprefs.parallel_postscript_emulation = changed_prefs.parallel_postscript_emulation; - currprefs.parallel_postscript_detection = changed_prefs.parallel_postscript_detection; - _tcscpy (currprefs.ghostscript_parameters, changed_prefs.ghostscript_parameters); + return 1; + } + + if (_tcscmp (currprefs.prtname, changed_prefs.prtname) || + currprefs.parallel_autoflush_time != changed_prefs.parallel_autoflush_time || + currprefs.parallel_matrix_emulation != changed_prefs.parallel_matrix_emulation || + currprefs.parallel_postscript_emulation != changed_prefs.parallel_postscript_emulation || + currprefs.parallel_postscript_detection != changed_prefs.parallel_postscript_detection || + _tcscmp (currprefs.ghostscript_parameters, changed_prefs.ghostscript_parameters)) { + _tcscpy (currprefs.prtname, changed_prefs.prtname); + currprefs.parallel_autoflush_time = changed_prefs.parallel_autoflush_time; + currprefs.parallel_matrix_emulation = changed_prefs.parallel_matrix_emulation; + currprefs.parallel_postscript_emulation = changed_prefs.parallel_postscript_emulation; + currprefs.parallel_postscript_detection = changed_prefs.parallel_postscript_detection; + _tcscpy (currprefs.ghostscript_parameters, changed_prefs.ghostscript_parameters); #ifdef PARALLEL_PORT - closeprinter (); + closeprinter (); #endif - } - if (_tcscmp (currprefs.sername, changed_prefs.sername) || - currprefs.serial_hwctsrts != changed_prefs.serial_hwctsrts || - currprefs.serial_direct != changed_prefs.serial_direct || - currprefs.serial_demand != changed_prefs.serial_demand) { - _tcscpy (currprefs.sername, changed_prefs.sername); - currprefs.serial_hwctsrts = changed_prefs.serial_hwctsrts; - currprefs.serial_demand = changed_prefs.serial_demand; - currprefs.serial_direct = changed_prefs.serial_direct; + } + if (_tcscmp (currprefs.sername, changed_prefs.sername) || + currprefs.serial_hwctsrts != changed_prefs.serial_hwctsrts || + currprefs.serial_direct != changed_prefs.serial_direct || + currprefs.serial_demand != changed_prefs.serial_demand) { + _tcscpy (currprefs.sername, changed_prefs.sername); + currprefs.serial_hwctsrts = changed_prefs.serial_hwctsrts; + currprefs.serial_demand = changed_prefs.serial_demand; + currprefs.serial_direct = changed_prefs.serial_direct; #ifdef SERIAL_PORT - serial_exit (); - serial_init (); + serial_exit (); + serial_init (); #endif - } - if (currprefs.win32_midiindev != changed_prefs.win32_midiindev || - currprefs.win32_midioutdev != changed_prefs.win32_midioutdev) - { - currprefs.win32_midiindev = changed_prefs.win32_midiindev; - currprefs.win32_midioutdev = changed_prefs.win32_midioutdev; -#ifdef SERIAL_PORT - if (midi_ready) { - Midi_Close (); - Midi_Open (); } + if (currprefs.win32_midiindev != changed_prefs.win32_midiindev || + currprefs.win32_midioutdev != changed_prefs.win32_midioutdev) + { + currprefs.win32_midiindev = changed_prefs.win32_midiindev; + currprefs.win32_midioutdev = changed_prefs.win32_midioutdev; +#ifdef SERIAL_PORT + if (midi_ready) { + Midi_Close (); + Midi_Open (); + } #endif - } + } - if (currprefs.win32_powersavedisabled != changed_prefs.win32_powersavedisabled) { + if (currprefs.win32_powersavedisabled != changed_prefs.win32_powersavedisabled) { - currprefs.win32_powersavedisabled = changed_prefs.win32_powersavedisabled; - } - return 0; + currprefs.win32_powersavedisabled = changed_prefs.win32_powersavedisabled; + } + return 0; } /* Color management */ @@ -1443,85 +1443,85 @@ static int alpha; static int get_color (int r, int g, int b, xcolnr * cnp) { - if (ncols256 == 256) - return 0; - colors256[ncols256].peRed = r * 0x11; - colors256[ncols256].peGreen = g * 0x11; - colors256[ncols256].peBlue = b * 0x11; - colors256[ncols256].peFlags = 0; - *cnp = ncols256; - ncols256++; - return 1; + if (ncols256 == 256) + return 0; + colors256[ncols256].peRed = r * 0x11; + colors256[ncols256].peGreen = g * 0x11; + colors256[ncols256].peBlue = b * 0x11; + colors256[ncols256].peFlags = 0; + *cnp = ncols256; + ncols256++; + return 1; } void init_colors (void) { - if (ncols256 == 0) { - alloc_colors256 (get_color); - memcpy (xcol8, xcolors, sizeof xcol8); - } - - /* init colors */ - switch(currentmode->current_depth >> 3) - { - case 1: - memcpy (xcolors, xcol8, sizeof xcolors); - DirectDraw_SetPaletteEntries (0, 256, colors256); - break; + if (ncols256 == 0) { + alloc_colors256 (get_color); + memcpy (xcol8, xcolors, sizeof xcol8); + } + + /* init colors */ + switch(currentmode->current_depth >> 3) + { + case 1: + memcpy (xcolors, xcol8, sizeof xcolors); + DirectDraw_SetPaletteEntries (0, 256, colors256); + break; case 2: case 3: case 4: - x_red_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (red_mask)); - x_green_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (green_mask)); - x_blue_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (blue_mask)); - x_red_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (red_mask)); - x_green_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (green_mask)); - x_blue_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (blue_mask)); - x_alpha_bits = 0; - x_alpha_shift = 0; - break; - } - - if (currentmode->flags & DM_OPENGL) { + x_red_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (red_mask)); + x_green_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (green_mask)); + x_blue_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (blue_mask)); + x_red_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (red_mask)); + x_green_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (green_mask)); + x_blue_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (blue_mask)); + x_alpha_bits = 0; + x_alpha_shift = 0; + break; + } + + if (currentmode->flags & DM_OPENGL) { #ifdef OPENGL - OGL_getpixelformat (currentmode->current_depth,&red_bits,&green_bits,&blue_bits,&red_shift,&green_shift,&blue_shift,&alpha_bits,&alpha_shift,&alpha); + OGL_getpixelformat (currentmode->current_depth,&red_bits,&green_bits,&blue_bits,&red_shift,&green_shift,&blue_shift,&alpha_bits,&alpha_shift,&alpha); #endif - } else if (currentmode->flags & DM_D3D) { + } else if (currentmode->flags & DM_D3D) { #ifdef D3D - D3D_getpixelformat (currentmode->current_depth,&red_bits,&green_bits,&blue_bits,&red_shift,&green_shift,&blue_shift,&alpha_bits,&alpha_shift,&alpha); + D3D_getpixelformat (currentmode->current_depth,&red_bits,&green_bits,&blue_bits,&red_shift,&green_shift,&blue_shift,&alpha_bits,&alpha_shift,&alpha); #endif - } else { - red_bits = x_red_bits; - green_bits = x_green_bits; - blue_bits = x_blue_bits; - red_shift = x_red_shift; - green_shift = x_green_shift; - blue_shift = x_blue_shift; - alpha_bits = x_alpha_bits; - alpha_shift = x_alpha_shift; - } - - if (currentmode->current_depth > 8) { - if (!(currentmode->flags & (DM_OPENGL|DM_D3D))) { - if (currentmode->current_depth != currentmode->native_depth) { - if (currentmode->current_depth == 16) { - red_bits = 5; green_bits = 6; blue_bits = 5; - red_shift = 11; green_shift = 5; blue_shift = 0; - } else { - red_bits = green_bits = blue_bits = 8; - red_shift = 16; green_shift = 8; blue_shift = 0; - } - } + } else { + red_bits = x_red_bits; + green_bits = x_green_bits; + blue_bits = x_blue_bits; + red_shift = x_red_shift; + green_shift = x_green_shift; + blue_shift = x_blue_shift; + alpha_bits = x_alpha_bits; + alpha_shift = x_alpha_shift; } - alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift, alpha_bits, alpha_shift, alpha, 0); - notice_new_xcolors (); + + if (currentmode->current_depth > 8) { + if (!(currentmode->flags & (DM_OPENGL|DM_D3D))) { + if (currentmode->current_depth != currentmode->native_depth) { + if (currentmode->current_depth == 16) { + red_bits = 5; green_bits = 6; blue_bits = 5; + red_shift = 11; green_shift = 5; blue_shift = 0; + } else { + red_bits = green_bits = blue_bits = 8; + red_shift = 16; green_shift = 8; blue_shift = 0; + } + } + } + alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift, alpha_bits, alpha_shift, alpha, 0); + notice_new_xcolors (); #ifdef GFXFILTER - S2X_configure (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift); + S2X_configure (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift); #endif #ifdef AVIOUTPUT - AVIOutput_RGBinfo (red_bits, green_bits, blue_bits, red_shift, green_shift, blue_shift); + AVIOutput_RGBinfo (red_bits, green_bits, blue_bits, red_shift, green_shift, blue_shift); #endif - } + } } #ifdef PICASSO96 @@ -1531,455 +1531,455 @@ void DX_SetPalette_vsync (void) int picasso_palette (void) { - int i, changed; - - changed = 0; - for (i = 0; i < 256; i++) { - int r = picasso96_state.CLUT[i].Red; - int g = picasso96_state.CLUT[i].Green; - int b = picasso96_state.CLUT[i].Blue; - uae_u32 v = (doMask256 (r, red_bits, red_shift) - | doMask256 (g, green_bits, green_shift) - | doMask256 (b, blue_bits, blue_shift)); - if (v != picasso_vidinfo.clut[i]) { - picasso_vidinfo.clut[i] = v; - changed = 1; + int i, changed; + + changed = 0; + for (i = 0; i < 256; i++) { + int r = picasso96_state.CLUT[i].Red; + int g = picasso96_state.CLUT[i].Green; + int b = picasso96_state.CLUT[i].Blue; + uae_u32 v = (doMask256 (r, red_bits, red_shift) + | doMask256 (g, green_bits, green_shift) + | doMask256 (b, blue_bits, blue_shift)); + if (v != picasso_vidinfo.clut[i]) { + picasso_vidinfo.clut[i] = v; + changed = 1; + } } - } - if (changed) - DX_SetPalette (0,256); - return changed; + if (changed) + DX_SetPalette (0,256); + return changed; } void DX_SetPalette (int start, int count) { - if (!screen_is_picasso) - return; - if (picasso_vidinfo.pixbytes != 1) - return; - if(currentmode->current_depth > 8) - return; - if (SUCCEEDED (DirectDraw_SetPalette (0))) - DirectDraw_SetPaletteEntries (start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start])); + if (!screen_is_picasso) + return; + if (picasso_vidinfo.pixbytes != 1) + return; + if(currentmode->current_depth > 8) + return; + if (SUCCEEDED (DirectDraw_SetPalette (0))) + DirectDraw_SetPaletteEntries (start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start])); } void DX_Invalidate (int x, int y, int width, int height) { - int last, lastx; - - if (width == 0 || height == 0) - return; - if (y < 0 || height < 0) { - y = 0; - height = picasso_vidinfo.height; - } - if (x < 0 || width < 0) { - x = 0; - width = picasso_vidinfo.width; - } - last = y + height - 1; - lastx = x + width - 1; - p96_double_buffer_first = y; - p96_double_buffer_last = last; - p96_double_buffer_firstx = x; - p96_double_buffer_lastx = lastx; - p96_double_buffer_needs_flushing = 1; + int last, lastx; + + if (width == 0 || height == 0) + return; + if (y < 0 || height < 0) { + y = 0; + height = picasso_vidinfo.height; + } + if (x < 0 || width < 0) { + x = 0; + width = picasso_vidinfo.width; + } + last = y + height - 1; + lastx = x + width - 1; + p96_double_buffer_first = y; + p96_double_buffer_last = last; + p96_double_buffer_firstx = x; + p96_double_buffer_lastx = lastx; + p96_double_buffer_needs_flushing = 1; } #endif static void open_screen (void) { - close_windows (); - open_windows (1); + close_windows (); + open_windows (1); #ifdef PICASSO96 - DX_SetPalette (0, 256); + DX_SetPalette (0, 256); #endif } static int ifs (struct uae_prefs *p) { - if (screen_is_picasso) - return p->gfx_pfullscreen == 1 ? 1 : (p->gfx_pfullscreen == 2 ? -1 : 0); - else - return p->gfx_afullscreen == 1 ? 1 : (p->gfx_afullscreen == 2 ? -1 : 0); + if (screen_is_picasso) + return p->gfx_pfullscreen == 1 ? 1 : (p->gfx_pfullscreen == 2 ? -1 : 0); + else + return p->gfx_afullscreen == 1 ? 1 : (p->gfx_afullscreen == 2 ? -1 : 0); } static int reopen (int full) { - int quick = 0; - - updatewinfsmode (&changed_prefs); - - 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; - - /* fullscreen to fullscreen? */ - if (isfullscreen () > 0 && currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && - currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen && currprefs.gfx_afullscreen == 1) { - quick = 1; - } - /* windowed to windowed */ - if (isfullscreen () <= 0 && currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && - currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen) { - quick = 1; - } - - 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; - - if (!quick) - return 1; - - open_windows (0); + int quick = 0; - if (isfullscreen () <= 0) - DirectDraw_FillPrimary (); + updatewinfsmode (&changed_prefs); + + 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; + + /* fullscreen to fullscreen? */ + if (isfullscreen () > 0 && currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && + currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen && currprefs.gfx_afullscreen == 1) { + quick = 1; + } + /* windowed to windowed */ + if (isfullscreen () <= 0 && currprefs.gfx_afullscreen == changed_prefs.gfx_afullscreen && + currprefs.gfx_pfullscreen == changed_prefs.gfx_pfullscreen) { + quick = 1; + } - return 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; + + if (!quick) + return 1; + + open_windows (0); + + if (isfullscreen () <= 0) + DirectDraw_FillPrimary (); + + return 0; } int vsync_switchmode (int hz, int oldhz) { - static int tempvsync; - int w = currentmode->native_width; - int h = currentmode->native_height; - int d = currentmode->native_depth / 8; - struct MultiDisplay *md = getdisplay (&currprefs); - struct PicassoResolution *found; - int newh, i, cnt; - int dbl = getvsyncrate (currprefs.chipset_refreshrate) != currprefs.chipset_refreshrate ? 2 : 1; - - if (hz < 0) - return tempvsync; - - newh = h * oldhz / hz; - hz = hz * dbl; - - found = NULL; - for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) { - struct PicassoResolution *r = &md->DisplayModes[i]; - if (r->res.width == w && r->res.height == h && r->depth == d) { - int j; - for (j = 0; r->refresh[j] > 0; j++) { - if (r->refresh[j] == oldhz) { - found = r; - break; + static int tempvsync; + int w = currentmode->native_width; + int h = currentmode->native_height; + int d = currentmode->native_depth / 8; + struct MultiDisplay *md = getdisplay (&currprefs); + struct PicassoResolution *found; + int newh, i, cnt; + int dbl = getvsyncrate (currprefs.chipset_refreshrate) != currprefs.chipset_refreshrate ? 2 : 1; + + if (hz < 0) + return tempvsync; + + newh = h * oldhz / hz; + hz = hz * dbl; + + found = NULL; + for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) { + struct PicassoResolution *r = &md->DisplayModes[i]; + if (r->res.width == w && r->res.height == h && r->depth == d) { + int j; + for (j = 0; r->refresh[j] > 0; j++) { + if (r->refresh[j] == oldhz) { + found = r; + break; + } + } } - } } - } - if (found == NULL) { - write_log (L"refresh rate changed to %d but original rate was not found\n", hz); - return 0; - } + if (found == NULL) { + write_log (L"refresh rate changed to %d but original rate was not found\n", hz); + return 0; + } - found = NULL; - for (cnt = 0; cnt <= abs (newh - h) + 1 && !found; cnt++) { - for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) { - struct PicassoResolution *r = &md->DisplayModes[i]; - if (r->res.width == w && (r->res.height == newh + cnt || r->res.height == newh - cnt) && r->depth == d) { - int j; - for (j = 0; r->refresh[j] > 0; j++) { - if (r->refresh[j] == hz) { - found = r; - break; - } + found = NULL; + for (cnt = 0; cnt <= abs (newh - h) + 1 && !found; cnt++) { + for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) { + struct PicassoResolution *r = &md->DisplayModes[i]; + if (r->res.width == w && (r->res.height == newh + cnt || r->res.height == newh - cnt) && r->depth == d) { + int j; + for (j = 0; r->refresh[j] > 0; j++) { + if (r->refresh[j] == hz) { + found = r; + break; + } + } + } } - } - } - } - if (!found) { - tempvsync = currprefs.gfx_avsync; - changed_prefs.gfx_avsync = 0; - write_log (L"refresh rate changed to %d but no matching screenmode found, vsync disabled\n", hz); - } else { - newh = found->res.height; - changed_prefs.gfx_size_fs.height = newh; - changed_prefs.gfx_refreshrate = hz; - write_log (L"refresh rate changed to %d, new screenmode %dx%d\n", hz, w, newh); - } - reopen (1); - return 0; + } + if (!found) { + tempvsync = currprefs.gfx_avsync; + changed_prefs.gfx_avsync = 0; + write_log (L"refresh rate changed to %d but no matching screenmode found, vsync disabled\n", hz); + } else { + newh = found->res.height; + changed_prefs.gfx_size_fs.height = newh; + changed_prefs.gfx_refreshrate = hz; + write_log (L"refresh rate changed to %d, new screenmode %dx%d\n", hz, w, newh); + } + reopen (1); + return 0; } #ifdef PICASSO96 static int modeswitchneeded (struct winuae_currentmode *wc) { - if (isfullscreen () > 0) { - /* fullscreen to fullscreen */ - if (screen_is_picasso) { - if (picasso96_state.BytesPerPixel * 8 != wc->current_depth && currprefs.win32_rtgmatchdepth) + if (isfullscreen () > 0) { + /* fullscreen to fullscreen */ + if (screen_is_picasso) { + if (picasso96_state.BytesPerPixel * 8 != wc->current_depth && currprefs.win32_rtgmatchdepth) + return -1; + if (picasso96_state.Width < wc->current_width && picasso96_state.Height < wc->current_height) { + if (currprefs.win32_rtgscaleifsmall && !currprefs.win32_rtgmatchdepth) + return 0; + } + if (picasso96_state.Width != wc->current_width || + picasso96_state.Height != wc->current_height) + return 1; + if (picasso96_state.Width == wc->current_width && + picasso96_state.Height == wc->current_height) { + if (picasso96_state.BytesPerPixel * 8 == wc->current_depth) + return 0; + if (!currprefs.win32_rtgmatchdepth && wc->current_depth >= 16) + return 0; + } + return 1; + } else { + if (currentmode->current_width != wc->current_width || + currentmode->current_height != wc->current_height || + currentmode->current_depth != wc->current_depth) + return -1; + } + } else if (isfullscreen () == 0) { + /* windowed to windowed */ return -1; - if (picasso96_state.Width < wc->current_width && picasso96_state.Height < wc->current_height) { - if (currprefs.win32_rtgscaleifsmall && !currprefs.win32_rtgmatchdepth) - return 0; - } - if (picasso96_state.Width != wc->current_width || - picasso96_state.Height != wc->current_height) - return 1; - if (picasso96_state.Width == wc->current_width && - picasso96_state.Height == wc->current_height) { - if (picasso96_state.BytesPerPixel * 8 == wc->current_depth) - return 0; - if (!currprefs.win32_rtgmatchdepth && wc->current_depth >= 16) - return 0; - } - return 1; } else { - if (currentmode->current_width != wc->current_width || - currentmode->current_height != wc->current_height || - currentmode->current_depth != wc->current_depth) - return -1; - } - } else if (isfullscreen () == 0) { - /* windowed to windowed */ - return -1; - } else { - /* fullwindow to fullwindow */ - DirectDraw_Fill (NULL, 0); - DirectDraw_BlitToPrimary (NULL); - if (screen_is_picasso) { - if (currprefs.win32_rtgscaleifsmall && (wc->native_width > picasso96_state.Width || wc->native_height > picasso96_state.Height)) - return -1; - if (currprefs.win32_rtgallowscaling && (picasso96_state.Width != wc->native_width || picasso96_state.Height != wc->native_height)) + /* fullwindow to fullwindow */ + DirectDraw_Fill (NULL, 0); + DirectDraw_BlitToPrimary (NULL); + if (screen_is_picasso) { + if (currprefs.win32_rtgscaleifsmall && (wc->native_width > picasso96_state.Width || wc->native_height > picasso96_state.Height)) + return -1; + if (currprefs.win32_rtgallowscaling && (picasso96_state.Width != wc->native_width || picasso96_state.Height != wc->native_height)) + return -1; + } return -1; } - return -1; - } - return 0; + return 0; } void gfx_set_picasso_state (int on) { - struct winuae_currentmode wc; - int mode; + struct winuae_currentmode wc; + int mode; - if (screen_is_picasso == on) - return; - screen_is_picasso = on; - rp_rtg_switch (); - memcpy (&wc, currentmode, sizeof (wc)); + if (screen_is_picasso == on) + return; + screen_is_picasso = on; + rp_rtg_switch (); + memcpy (&wc, currentmode, sizeof (wc)); - updatemodes (); - update_gfxparams (); - clearscreen (); - if (currprefs.gfx_afullscreen != currprefs.gfx_pfullscreen || - (currprefs.gfx_afullscreen == 1 && (currprefs.gfx_filter == UAE_FILTER_DIRECT3D + updatemodes (); + update_gfxparams (); + clearscreen (); + if (currprefs.gfx_afullscreen != currprefs.gfx_pfullscreen || + (currprefs.gfx_afullscreen == 1 && (currprefs.gfx_filter == UAE_FILTER_DIRECT3D #ifdef OPENGL - || currprefs.gfx_filter == UAE_FILTER_OPENGL + || currprefs.gfx_filter == UAE_FILTER_OPENGL #endif - ))) { - mode = 1; - } else { - mode = modeswitchneeded (&wc); - if (!mode) - goto end; - } - if (mode < 0) { - open_windows (0); - } else { - open_screen (); // reopen everything - } + ))) { + mode = 1; + } else { + mode = modeswitchneeded (&wc); + if (!mode) + goto end; + } + if (mode < 0) { + open_windows (0); + } else { + open_screen (); // reopen everything + } end: #ifdef RETROPLATFORM - rp_set_hwnd (hAmigaWnd); + rp_set_hwnd (hAmigaWnd); #endif } void gfx_set_picasso_modeinfo (uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt) { - int need; - if (!screen_is_picasso) - return; - clearscreen (); - gfx_set_picasso_colors (rgbfmt); - updatemodes (); - need = modeswitchneeded (currentmode); - update_gfxparams (); - if (need > 0) { - open_screen (); - } else if (need < 0) { - open_windows (0); - } + int need; + if (!screen_is_picasso) + return; + clearscreen (); + gfx_set_picasso_colors (rgbfmt); + updatemodes (); + need = modeswitchneeded (currentmode); + update_gfxparams (); + if (need > 0) { + open_screen (); + } else if (need < 0) { + open_windows (0); + } #ifdef RETROPLATFORM - rp_set_hwnd (hAmigaWnd); + rp_set_hwnd (hAmigaWnd); #endif } #endif void gfx_set_picasso_colors (RGBFTYPE rgbfmt) { - alloc_colors_picasso (x_red_bits, x_green_bits, x_blue_bits, x_red_shift, x_green_shift, x_blue_shift, rgbfmt); + alloc_colors_picasso (x_red_bits, x_green_bits, x_blue_bits, x_red_shift, x_green_shift, x_blue_shift, rgbfmt); } static void gfxmode_reset (void) { #ifdef GFXFILTER - usedfilter = 0; - if (currprefs.gfx_filter > 0) { - int i = 0; - while (uaefilters[i].name) { - if (uaefilters[i].type == currprefs.gfx_filter) { - usedfilter = &uaefilters[i]; - break; - } - i++; + usedfilter = 0; + if (currprefs.gfx_filter > 0) { + int i = 0; + while (uaefilters[i].name) { + if (uaefilters[i].type == currprefs.gfx_filter) { + usedfilter = &uaefilters[i]; + break; + } + i++; + } } - } #endif } int machdep_init (void) { - picasso_requested_on = 0; - picasso_on = 0; - screen_is_picasso = 0; - memset (currentmode, 0, sizeof (*currentmode)); + picasso_requested_on = 0; + picasso_on = 0; + screen_is_picasso = 0; + memset (currentmode, 0, sizeof (*currentmode)); #ifdef LOGITECHLCD - lcd_open (); + lcd_open (); #endif #ifdef RETROPLATFORM - if (rp_param != NULL) { - if (FAILED (rp_init ())) - return 0; - } + if (rp_param != NULL) { + if (FAILED (rp_init ())) + return 0; + } #endif - systray (hHiddenWnd, FALSE); - return 1; + systray (hHiddenWnd, FALSE); + return 1; } void machdep_free (void) { #ifdef LOGITECHLCD - lcd_close (); + lcd_close (); #endif } int graphics_init (void) { - gfxmode_reset (); - return open_windows (1); + gfxmode_reset (); + return open_windows (1); } int graphics_setup (void) { - if (!DirectDraw_Start (NULL)) - return 0; - DirectDraw_Release (); + if (!DirectDraw_Start (NULL)) + return 0; + DirectDraw_Release (); #ifdef PICASSO96 - InitPicasso96 (); + InitPicasso96 (); #endif - return 1; + return 1; } void graphics_leave (void) { - close_windows (); + close_windows (); } uae_u32 OSDEP_minimize_uae (void) { - return ShowWindow (hAmigaWnd, SW_MINIMIZE); + return ShowWindow (hAmigaWnd, SW_MINIMIZE); } void close_windows (void) { - reset_sound(); + reset_sound(); #if defined (GFXFILTER) - S2X_free (); + S2X_free (); #endif - xfree (gfxvidinfo.realbufmem); - gfxvidinfo.realbufmem = 0; - DirectDraw_Release (); - close_hwnds (); + xfree (gfxvidinfo.realbufmem); + gfxvidinfo.realbufmem = 0; + DirectDraw_Release (); + close_hwnds (); } void WIN32GFX_ToggleFullScreen (void) { - display_change_requested = 1; - if (screen_is_picasso) - currprefs.gfx_pfullscreen ^= 1; - else - currprefs.gfx_afullscreen ^= 1; + display_change_requested = 1; + if (screen_is_picasso) + currprefs.gfx_pfullscreen ^= 1; + else + currprefs.gfx_afullscreen ^= 1; } static void createstatuswindow (void) { - HDC hdc; - RECT rc; - HLOCAL hloc; - LPINT lpParts; - int drive_width, hd_width, cd_width, power_width, fps_width, idle_width, snd_width; - int num_parts = 11; - double scaleX, scaleY; - WINDOWINFO wi; - int extra; - - if (hStatusWnd) { - ShowWindow (hStatusWnd, SW_HIDE); - DestroyWindow (hStatusWnd); - } - hStatusWnd = CreateWindowEx ( - 0, STATUSCLASSNAME, (LPCTSTR) NULL, SBT_TOOLTIPS | WS_CHILD | WS_VISIBLE, - 0, 0, 0, 0, hMainWnd, (HMENU) 1, hInst, NULL); - if (!hStatusWnd) - return; - wi.cbSize = sizeof wi; - GetWindowInfo (hMainWnd, &wi); - extra = wi.rcClient.top - wi.rcWindow.top; - - hdc = GetDC (hStatusWnd); - scaleX = GetDeviceCaps (hdc, LOGPIXELSX) / 96.0; - scaleY = GetDeviceCaps (hdc, LOGPIXELSY) / 96.0; - ReleaseDC (hStatusWnd, hdc); - drive_width = (int)(24 * scaleX); - hd_width = (int)(24 * scaleX); - cd_width = (int)(24 * scaleX); - power_width = (int)(42 * scaleX); - fps_width = (int)(64 * scaleX); - idle_width = (int)(64 * scaleX); - snd_width = (int)(64 * scaleX); - GetClientRect (hMainWnd, &rc); - /* Allocate an array for holding the right edge coordinates. */ - hloc = LocalAlloc (LHND, sizeof (int) * num_parts); - if (hloc) { - lpParts = LocalLock (hloc); - /* Calculate the right edge coordinate for each part, and copy the coords - * to the array. */ - lpParts[0] = rc.right - (drive_width * 4) - power_width - idle_width - fps_width - cd_width - hd_width - snd_width - extra; - lpParts[1] = lpParts[0] + snd_width; - lpParts[2] = lpParts[1] + idle_width; - lpParts[3] = lpParts[2] + fps_width; - lpParts[4] = lpParts[3] + power_width; - lpParts[5] = lpParts[4] + hd_width; - lpParts[6] = lpParts[5] + cd_width; - lpParts[7] = lpParts[6] + drive_width; - lpParts[8] = lpParts[7] + drive_width; - lpParts[9] = lpParts[8] + drive_width; - lpParts[10] = lpParts[9] + drive_width; - window_led_drives = lpParts[6]; - window_led_drives_end = lpParts[10]; - window_led_hd = lpParts[4]; - window_led_hd_end = lpParts[5]; - - /* Create the parts */ - SendMessage (hStatusWnd, SB_SETPARTS, (WPARAM)num_parts, (LPARAM)lpParts); - LocalUnlock (hloc); - LocalFree (hloc); - } + HDC hdc; + RECT rc; + HLOCAL hloc; + LPINT lpParts; + int drive_width, hd_width, cd_width, power_width, fps_width, idle_width, snd_width; + int num_parts = 11; + double scaleX, scaleY; + WINDOWINFO wi; + int extra; + + if (hStatusWnd) { + ShowWindow (hStatusWnd, SW_HIDE); + DestroyWindow (hStatusWnd); + } + hStatusWnd = CreateWindowEx ( + 0, STATUSCLASSNAME, (LPCTSTR) NULL, SBT_TOOLTIPS | WS_CHILD | WS_VISIBLE, + 0, 0, 0, 0, hMainWnd, (HMENU) 1, hInst, NULL); + if (!hStatusWnd) + return; + wi.cbSize = sizeof wi; + GetWindowInfo (hMainWnd, &wi); + extra = wi.rcClient.top - wi.rcWindow.top; + + hdc = GetDC (hStatusWnd); + scaleX = GetDeviceCaps (hdc, LOGPIXELSX) / 96.0; + scaleY = GetDeviceCaps (hdc, LOGPIXELSY) / 96.0; + ReleaseDC (hStatusWnd, hdc); + drive_width = (int)(24 * scaleX); + hd_width = (int)(24 * scaleX); + cd_width = (int)(24 * scaleX); + power_width = (int)(42 * scaleX); + fps_width = (int)(64 * scaleX); + idle_width = (int)(64 * scaleX); + snd_width = (int)(64 * scaleX); + GetClientRect (hMainWnd, &rc); + /* Allocate an array for holding the right edge coordinates. */ + hloc = LocalAlloc (LHND, sizeof (int) * num_parts); + if (hloc) { + lpParts = LocalLock (hloc); + /* Calculate the right edge coordinate for each part, and copy the coords + * to the array. */ + lpParts[0] = rc.right - (drive_width * 4) - power_width - idle_width - fps_width - cd_width - hd_width - snd_width - extra; + lpParts[1] = lpParts[0] + snd_width; + lpParts[2] = lpParts[1] + idle_width; + lpParts[3] = lpParts[2] + fps_width; + lpParts[4] = lpParts[3] + power_width; + lpParts[5] = lpParts[4] + hd_width; + lpParts[6] = lpParts[5] + cd_width; + lpParts[7] = lpParts[6] + drive_width; + lpParts[8] = lpParts[7] + drive_width; + lpParts[9] = lpParts[8] + drive_width; + lpParts[10] = lpParts[9] + drive_width; + window_led_drives = lpParts[6]; + window_led_drives_end = lpParts[10]; + window_led_hd = lpParts[4]; + window_led_hd_end = lpParts[5]; + + /* Create the parts */ + SendMessage (hStatusWnd, SB_SETPARTS, (WPARAM)num_parts, (LPARAM)lpParts); + LocalUnlock (hloc); + LocalFree (hloc); + } } #if 0 @@ -1987,611 +1987,611 @@ static void createstatuswindow (void) static int createnotification (HWND hwnd) { - DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; - HDEVNOTIFY hDevNotify; + DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; + HDEVNOTIFY hDevNotify; - ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); - NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); - NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; + ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); + NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); + NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; - hDevNotify = RegisterDeviceNotification(hMainWnd, - &NotificationFilter, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); + hDevNotify = RegisterDeviceNotification(hMainWnd, + &NotificationFilter, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); - if(!hDevNotify) - { - write_log (L"RegisterDeviceNotification failed: %d\n", GetLastError()); - return FALSE; - } + if(!hDevNotify) + { + write_log (L"RegisterDeviceNotification failed: %d\n", GetLastError()); + return FALSE; + } - return TRUE; + return TRUE; } #endif static int getbestmode (int nextbest) { - int i, startidx, disp; - struct MultiDisplay *md = getdisplay (&currprefs); - int ratio; - - ratio = currentmode->native_width > currentmode->native_height ? 1 : 0; - disp = currprefs.gfx_display; - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - struct PicassoResolution *pr = &md->DisplayModes[i]; - if (pr->res.width == currentmode->native_width && pr->res.height == currentmode->native_height) - break; - } - if (md->DisplayModes[i].depth >= 0) { - if (!nextbest) - return 1; - while (md->DisplayModes[i].res.width == currentmode->native_width && md->DisplayModes[i].res.height == currentmode->native_height) - i++; - } else { - i = 0; - } - // first iterate only modes that have similar aspect ratio - startidx = i; - for (; md->DisplayModes[i].depth >= 0; i++) { - struct PicassoResolution *pr = &md->DisplayModes[i]; - int r = pr->res.width > pr->res.height ? 1 : 0; - if (pr->res.width >= currentmode->native_width && pr->res.height >= currentmode->native_height && r == ratio) { - write_log (L"FS: %dx%d -> %dx%d (%d)\n", currentmode->native_width, currentmode->native_height, - pr->res.width, pr->res.height, ratio); - currentmode->native_width = pr->res.width; - currentmode->native_height = pr->res.height; - currentmode->current_width = currentmode->native_width; - currentmode->current_height = currentmode->native_height; - return 1; - } - } - // still not match? check all modes - i = startidx; - for (; md->DisplayModes[i].depth >= 0; i++) { - struct PicassoResolution *pr = &md->DisplayModes[i]; - int r = pr->res.width > pr->res.height ? 1 : 0; - if (pr->res.width >= currentmode->native_width && pr->res.height >= currentmode->native_height) { - write_log (L"FS: %dx%d -> %dx%d\n", currentmode->native_width, currentmode->native_height, - pr->res.width, pr->res.height); - currentmode->native_width = pr->res.width; - currentmode->native_height = pr->res.height; - currentmode->current_width = currentmode->native_width; - currentmode->current_height = currentmode->native_height; - return 1; - } - } - return 0; + int i, startidx, disp; + struct MultiDisplay *md = getdisplay (&currprefs); + int ratio; + + ratio = currentmode->native_width > currentmode->native_height ? 1 : 0; + disp = currprefs.gfx_display; + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + struct PicassoResolution *pr = &md->DisplayModes[i]; + if (pr->res.width == currentmode->native_width && pr->res.height == currentmode->native_height) + break; + } + if (md->DisplayModes[i].depth >= 0) { + if (!nextbest) + return 1; + while (md->DisplayModes[i].res.width == currentmode->native_width && md->DisplayModes[i].res.height == currentmode->native_height) + i++; + } else { + i = 0; + } + // first iterate only modes that have similar aspect ratio + startidx = i; + for (; md->DisplayModes[i].depth >= 0; i++) { + struct PicassoResolution *pr = &md->DisplayModes[i]; + int r = pr->res.width > pr->res.height ? 1 : 0; + if (pr->res.width >= currentmode->native_width && pr->res.height >= currentmode->native_height && r == ratio) { + write_log (L"FS: %dx%d -> %dx%d (%d)\n", currentmode->native_width, currentmode->native_height, + pr->res.width, pr->res.height, ratio); + currentmode->native_width = pr->res.width; + currentmode->native_height = pr->res.height; + currentmode->current_width = currentmode->native_width; + currentmode->current_height = currentmode->native_height; + return 1; + } + } + // still not match? check all modes + i = startidx; + for (; md->DisplayModes[i].depth >= 0; i++) { + struct PicassoResolution *pr = &md->DisplayModes[i]; + int r = pr->res.width > pr->res.height ? 1 : 0; + if (pr->res.width >= currentmode->native_width && pr->res.height >= currentmode->native_height) { + write_log (L"FS: %dx%d -> %dx%d\n", currentmode->native_width, currentmode->native_height, + pr->res.width, pr->res.height); + currentmode->native_width = pr->res.width; + currentmode->native_height = pr->res.height; + currentmode->current_width = currentmode->native_width; + currentmode->current_height = currentmode->native_height; + return 1; + } + } + return 0; } static int create_windows_2 (void) { - static int firstwindow = 1; - int dxfs = currentmode->flags & (DM_DX_FULLSCREEN); - int d3dfs = currentmode->flags & (DM_D3D_FULLSCREEN); - int fsw = currentmode->flags & (DM_W_FULLSCREEN); - DWORD exstyle = currprefs.win32_notaskbarbutton ? WS_EX_TOOLWINDOW : WS_EX_APPWINDOW; - DWORD flags = 0; - HWND hhWnd = NULL;//currprefs.win32_notaskbarbutton ? hHiddenWnd : NULL; - int borderless = currprefs.win32_borderless; - DWORD style = NORMAL_WINDOW_STYLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; - int cymenu = GetSystemMetrics (SM_CYMENU); - int cyborder = GetSystemMetrics (SM_CYBORDER); - int cxborder = GetSystemMetrics (SM_CXBORDER); - int gap = 3; - int x, y, w, h; - - if (hAmigaWnd) { - RECT r; - int w, h, x, y; - int nw, nh, nx, ny; - GetWindowRect (hAmigaWnd, &r); - x = r.left; - y = r.top; - w = r.right - r.left; - h = r.bottom - r.top; - nx = x; - ny = y; - - if (screen_is_picasso) { - nw = currentmode->current_width; - nh = currentmode->current_height; - } else { - nw = currprefs.gfx_size_win.width; - nh = currprefs.gfx_size_win.height; - } - - if (fsw || dxfs) { - RECT rc = getdisplay (&currprefs)->rect; - nx = rc.left; - ny = rc.top; - nw = rc.right - rc.left; - nh = rc.bottom - rc.top; - } else if (d3dfs) { - RECT rc = getdisplay (&currprefs)->rect; - nw = currentmode->native_width; - nh = currentmode->native_height; - if (rc.left >= 0) - nx = rc.left; - else - nx = rc.left + (rc.right - rc.left - nw); - if (rc.top >= 0) - ny = rc.top; - else - ny = rc.top + (rc.bottom - rc.top - nh); - } - if (w != nw || h != nh || x != nx || y != ny) { - w = nw; - h = nh; - x = nx; - y = ny; - in_sizemove++; - if (hMainWnd && !fsw && !dxfs && !d3dfs && !rp_isactive ()) { - GetWindowRect (hMainWnd, &r); + static int firstwindow = 1; + int dxfs = currentmode->flags & (DM_DX_FULLSCREEN); + int d3dfs = currentmode->flags & (DM_D3D_FULLSCREEN); + int fsw = currentmode->flags & (DM_W_FULLSCREEN); + DWORD exstyle = currprefs.win32_notaskbarbutton ? WS_EX_TOOLWINDOW : WS_EX_APPWINDOW; + DWORD flags = 0; + HWND hhWnd = NULL;//currprefs.win32_notaskbarbutton ? hHiddenWnd : NULL; + int borderless = currprefs.win32_borderless; + DWORD style = NORMAL_WINDOW_STYLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + int cymenu = GetSystemMetrics (SM_CYMENU); + int cyborder = GetSystemMetrics (SM_CYBORDER); + int cxborder = GetSystemMetrics (SM_CXBORDER); + int gap = 3; + int x, y, w, h; + + if (hAmigaWnd) { + RECT r; + int w, h, x, y; + int nw, nh, nx, ny; + GetWindowRect (hAmigaWnd, &r); x = r.left; y = r.top; - SetWindowPos (hMainWnd, HWND_TOP, x, y, w + window_extra_width, h + window_extra_height, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); - x = gap - 1; - y = gap - 2; - } - SetWindowPos (hAmigaWnd, HWND_TOP, x, y, w, h, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); - if (hStatusWnd) - createstatuswindow (); - in_sizemove--; - } else { - w = nw; - h = nh; - x = nx; - y = ny; - } - GetWindowRect (hAmigaWnd, &amigawin_rect); - if (d3dfs || dxfs) - SetCursorPos (x + w / 2, y + h / 2); - write_log (L"window already open\n"); + w = r.right - r.left; + h = r.bottom - r.top; + nx = x; + ny = y; + + if (screen_is_picasso) { + nw = currentmode->current_width; + nh = currentmode->current_height; + } else { + nw = currprefs.gfx_size_win.width; + nh = currprefs.gfx_size_win.height; + } + + if (fsw || dxfs) { + RECT rc = getdisplay (&currprefs)->rect; + nx = rc.left; + ny = rc.top; + nw = rc.right - rc.left; + nh = rc.bottom - rc.top; + } else if (d3dfs) { + RECT rc = getdisplay (&currprefs)->rect; + nw = currentmode->native_width; + nh = currentmode->native_height; + if (rc.left >= 0) + nx = rc.left; + else + nx = rc.left + (rc.right - rc.left - nw); + if (rc.top >= 0) + ny = rc.top; + else + ny = rc.top + (rc.bottom - rc.top - nh); + } + if (w != nw || h != nh || x != nx || y != ny) { + w = nw; + h = nh; + x = nx; + y = ny; + in_sizemove++; + if (hMainWnd && !fsw && !dxfs && !d3dfs && !rp_isactive ()) { + GetWindowRect (hMainWnd, &r); + x = r.left; + y = r.top; + SetWindowPos (hMainWnd, HWND_TOP, x, y, w + window_extra_width, h + window_extra_height, + SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); + x = gap - 1; + y = gap - 2; + } + SetWindowPos (hAmigaWnd, HWND_TOP, x, y, w, h, + SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER); + if (hStatusWnd) + createstatuswindow (); + in_sizemove--; + } else { + w = nw; + h = nh; + x = nx; + y = ny; + } + GetWindowRect (hAmigaWnd, &amigawin_rect); + if (d3dfs || dxfs) + SetCursorPos (x + w / 2, y + h / 2); + write_log (L"window already open\n"); #ifdef RETROPLATFORM - rp_set_hwnd (hAmigaWnd); + rp_set_hwnd (hAmigaWnd); #endif - return 1; - } - - if (fsw && !borderless) - borderless = 1; - window_led_drives = 0; - window_led_drives_end = 0; - hMainWnd = NULL; - x = 2; y = 2; - if (borderless) - cymenu = cyborder = cxborder = 0; - - if (!dxfs && !d3dfs) { - RECT rc; - LONG stored_x = 1, stored_y = cymenu + cyborder; - int oldx, oldy; - int first = 2; - - regqueryint (NULL, L"MainPosX", &stored_x); - regqueryint (NULL, L"MainPosY", &stored_y); - - while (first) { - first--; - if (stored_x < GetSystemMetrics (SM_XVIRTUALSCREEN)) - stored_x = GetSystemMetrics (SM_XVIRTUALSCREEN); - if (stored_y < GetSystemMetrics (SM_YVIRTUALSCREEN) + cymenu + cyborder) - stored_y = GetSystemMetrics (SM_YVIRTUALSCREEN) + cymenu + cyborder; - - if (stored_x > GetSystemMetrics (SM_CXVIRTUALSCREEN)) - rc.left = 1; - else - rc.left = stored_x; - - if (stored_y > GetSystemMetrics (SM_CYVIRTUALSCREEN)) - rc.top = 1; - else - rc.top = stored_y; - - rc.right = rc.left + gap + currentmode->current_width + gap - 2; - rc.bottom = rc.top + gap + currentmode->current_height + gap + cymenu - 1 - 2; - - oldx = rc.left; - oldy = rc.top; - AdjustWindowRect (&rc, borderless ? WS_POPUP : style, FALSE); - win_x_diff = rc.left - oldx; - win_y_diff = rc.top - oldy; - - if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) == NULL) { - write_log (L"window coordinates are not visible on any monitor, reseting..\n"); - stored_x = stored_y = 0; - continue; - } - break; - } - - if (fsw) { - rc = getdisplay (&currprefs)->rect; - flags |= WS_EX_TOPMOST; - style = WS_POPUP; - currentmode->native_width = rc.right - rc.left; - currentmode->native_height = rc.bottom - rc.top; - } - flags |= (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0); - - if (!borderless) { - RECT rc2; - hMainWnd = CreateWindowEx (WS_EX_ACCEPTFILES | exstyle | flags, - L"PCsuxRox", L"WinUAE", - style, - rc.left, rc.top, - rc.right - rc.left + 1, rc.bottom - rc.top + 1, - hhWnd, NULL, hInst, NULL); - if (!hMainWnd) { - write_log (L"main window creation failed\n"); - return 0; - } - GetWindowRect (hMainWnd, &rc2); - window_extra_width = rc2.right - rc2.left - currentmode->current_width; - window_extra_height = rc2.bottom - rc2.top - currentmode->current_height; - if (!(currentmode->flags & DM_W_FULLSCREEN)) - createstatuswindow (); - } else { - x = rc.left; - y = rc.top; + return 1; } - w = currentmode->native_width; - h = currentmode->native_height; - } else { + if (fsw && !borderless) + borderless = 1; + window_led_drives = 0; + window_led_drives_end = 0; + hMainWnd = NULL; + x = 2; y = 2; + if (borderless) + cymenu = cyborder = cxborder = 0; + + if (!dxfs && !d3dfs) { + RECT rc; + LONG stored_x = 1, stored_y = cymenu + cyborder; + int oldx, oldy; + int first = 2; + + regqueryint (NULL, L"MainPosX", &stored_x); + regqueryint (NULL, L"MainPosY", &stored_y); + + while (first) { + first--; + if (stored_x < GetSystemMetrics (SM_XVIRTUALSCREEN)) + stored_x = GetSystemMetrics (SM_XVIRTUALSCREEN); + if (stored_y < GetSystemMetrics (SM_YVIRTUALSCREEN) + cymenu + cyborder) + stored_y = GetSystemMetrics (SM_YVIRTUALSCREEN) + cymenu + cyborder; + + if (stored_x > GetSystemMetrics (SM_CXVIRTUALSCREEN)) + rc.left = 1; + else + rc.left = stored_x; + + if (stored_y > GetSystemMetrics (SM_CYVIRTUALSCREEN)) + rc.top = 1; + else + rc.top = stored_y; + + rc.right = rc.left + gap + currentmode->current_width + gap - 2; + rc.bottom = rc.top + gap + currentmode->current_height + gap + cymenu - 1 - 2; + + oldx = rc.left; + oldy = rc.top; + AdjustWindowRect (&rc, borderless ? WS_POPUP : style, FALSE); + win_x_diff = rc.left - oldx; + win_y_diff = rc.top - oldy; + + if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) == NULL) { + write_log (L"window coordinates are not visible on any monitor, reseting..\n"); + stored_x = stored_y = 0; + continue; + } + break; + } - RECT rc; - getbestmode (0); - w = currentmode->native_width; - h = currentmode->native_height; - rc = getdisplay (&currprefs)->rect; - if (rc.left >= 0) - x = rc.left; - else - x = rc.left + (rc.right - rc.left - w); - if (rc.top >= 0) - y = rc.top; - else - y = rc.top + (rc.bottom - rc.top - h); - } - - if (rp_isactive () && !dxfs && !d3dfs && !fsw) { - HWND parent = rp_getparent (); - hAmigaWnd = CreateWindowEx (dxfs || d3dfs ? WS_EX_ACCEPTFILES | WS_EX_TOPMOST : WS_EX_ACCEPTFILES | WS_EX_TOOLWINDOW | (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0), - L"AmigaPowah", L"WinUAE", - WS_POPUP, - x, y, w, h, - parent, NULL, hInst, NULL); - } else { - hAmigaWnd = CreateWindowEx (dxfs || d3dfs ? - WS_EX_TOPMOST : - WS_EX_ACCEPTFILES | exstyle | (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0), - L"AmigaPowah", L"WinUAE", - (dxfs || d3dfs || currprefs.headless ? WS_POPUP : (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | (hMainWnd ? WS_VISIBLE | WS_CHILD : WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_MINIMIZEBOX))), - x, y, w, h, - borderless ? NULL : (hMainWnd ? hMainWnd : hhWnd), NULL, hInst, NULL); - } - if (!hAmigaWnd) { - write_log (L"creation of amiga window failed\n"); - close_hwnds (); - return 0; - } - if (hMainWnd == NULL) - hMainWnd = hAmigaWnd; - GetWindowRect (hAmigaWnd, &amigawin_rect); - if (dxfs || d3dfs) - SetCursorPos (x + w / 2, y + h / 2); - addnotifications (hAmigaWnd, FALSE, FALSE); - if (hMainWnd != hAmigaWnd) { + if (fsw) { + rc = getdisplay (&currprefs)->rect; + flags |= WS_EX_TOPMOST; + style = WS_POPUP; + currentmode->native_width = rc.right - rc.left; + currentmode->native_height = rc.bottom - rc.top; + } + flags |= (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0); + + if (!borderless) { + RECT rc2; + hMainWnd = CreateWindowEx (WS_EX_ACCEPTFILES | exstyle | flags, + L"PCsuxRox", L"WinUAE", + style, + rc.left, rc.top, + rc.right - rc.left + 1, rc.bottom - rc.top + 1, + hhWnd, NULL, hInst, NULL); + if (!hMainWnd) { + write_log (L"main window creation failed\n"); + return 0; + } + GetWindowRect (hMainWnd, &rc2); + window_extra_width = rc2.right - rc2.left - currentmode->current_width; + window_extra_height = rc2.bottom - rc2.top - currentmode->current_height; + if (!(currentmode->flags & DM_W_FULLSCREEN)) + createstatuswindow (); + } else { + x = rc.left; + y = rc.top; + } + w = currentmode->native_width; + h = currentmode->native_height; + + } else { + + RECT rc; + getbestmode (0); + w = currentmode->native_width; + h = currentmode->native_height; + rc = getdisplay (&currprefs)->rect; + if (rc.left >= 0) + x = rc.left; + else + x = rc.left + (rc.right - rc.left - w); + if (rc.top >= 0) + y = rc.top; + else + y = rc.top + (rc.bottom - rc.top - h); + } + + if (rp_isactive () && !dxfs && !d3dfs && !fsw) { + HWND parent = rp_getparent (); + hAmigaWnd = CreateWindowEx (dxfs || d3dfs ? WS_EX_ACCEPTFILES | WS_EX_TOPMOST : WS_EX_ACCEPTFILES | WS_EX_TOOLWINDOW | (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0), + L"AmigaPowah", L"WinUAE", + WS_POPUP, + x, y, w, h, + parent, NULL, hInst, NULL); + } else { + hAmigaWnd = CreateWindowEx (dxfs || d3dfs ? +WS_EX_TOPMOST : + WS_EX_ACCEPTFILES | exstyle | (currprefs.win32_alwaysontop ? WS_EX_TOPMOST : 0), + L"AmigaPowah", L"WinUAE", + (dxfs || d3dfs || currprefs.headless ? WS_POPUP : (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | (hMainWnd ? WS_VISIBLE | WS_CHILD : WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_MINIMIZEBOX))), + x, y, w, h, + borderless ? NULL : (hMainWnd ? hMainWnd : hhWnd), NULL, hInst, NULL); + } + if (!hAmigaWnd) { + write_log (L"creation of amiga window failed\n"); + close_hwnds (); + return 0; + } + if (hMainWnd == NULL) + hMainWnd = hAmigaWnd; + GetWindowRect (hAmigaWnd, &amigawin_rect); + if (dxfs || d3dfs) + SetCursorPos (x + w / 2, y + h / 2); + addnotifications (hAmigaWnd, FALSE, FALSE); + if (hMainWnd != hAmigaWnd) { + if (!currprefs.headless) + ShowWindow (hMainWnd, firstwindow ? SW_SHOWDEFAULT : SW_SHOWNORMAL); + UpdateWindow (hMainWnd); + } if (!currprefs.headless) - ShowWindow (hMainWnd, firstwindow ? SW_SHOWDEFAULT : SW_SHOWNORMAL); - UpdateWindow (hMainWnd); - } - if (!currprefs.headless) - ShowWindow (hAmigaWnd, firstwindow ? SW_SHOWDEFAULT : SW_SHOWNORMAL); - UpdateWindow (hAmigaWnd); - firstwindow = 0; + ShowWindow (hAmigaWnd, firstwindow ? SW_SHOWDEFAULT : SW_SHOWNORMAL); + UpdateWindow (hAmigaWnd); + firstwindow = 0; - return 1; + return 1; } static int set_ddraw (void) { - int cnt, ret; + int cnt, ret; - if (picasso_on) - currentmode->pal = (LPPALETTEENTRY) & picasso96_state.CLUT; - else - currentmode->pal = colors256; + if (picasso_on) + currentmode->pal = (LPPALETTEENTRY) & picasso96_state.CLUT; + else + currentmode->pal = colors256; - cnt = 3; - for (;;) { - ret = set_ddraw_2 (); - if (cnt-- <= 0) - return 0; - if (ret < 0) { - getbestmode (1); - continue; + cnt = 3; + for (;;) { + ret = set_ddraw_2 (); + if (cnt-- <= 0) + return 0; + if (ret < 0) { + getbestmode (1); + continue; + } + if (ret == 0) + return 0; + break; } - if (ret == 0) - return 0; - break; - } - return 1; + return 1; } static int create_windows (void) { - if (!create_windows_2 ()) - return 0; - return set_ddraw (); + if (!create_windows_2 ()) + return 0; + return set_ddraw (); } static BOOL doInit (void) { - int fs_warning = -1; - TCHAR tmpstr[300]; - RGBFTYPE colortype; - int tmp_depth; - int ret = 0; - int mult = 0; + int fs_warning = -1; + TCHAR tmpstr[300]; + RGBFTYPE colortype; + int tmp_depth; + int ret = 0; + int mult = 0; - colortype = DirectDraw_GetPixelFormat(); - gfxmode_reset (); + colortype = DirectDraw_GetPixelFormat(); + gfxmode_reset (); - for (;;) { - updatemodes (); - currentmode->native_depth = 0; - tmp_depth = currentmode->current_depth; + for (;;) { + updatemodes (); + currentmode->native_depth = 0; + tmp_depth = currentmode->current_depth; + + if (currentmode->flags & DM_W_FULLSCREEN) { + RECT rc = getdisplay (&currprefs)->rect; + currentmode->native_width = rc.right - rc.left; + currentmode->native_height = rc.bottom - rc.top; + } - if (currentmode->flags & DM_W_FULLSCREEN) { - RECT rc = getdisplay (&currprefs)->rect; - currentmode->native_width = rc.right - rc.left; - currentmode->native_height = rc.bottom - rc.top; - } + write_log (L"W=%d H=%d B=%d CT=%d\n", + DirectDraw_CurrentWidth (), DirectDraw_CurrentHeight (), DirectDraw_GetCurrentDepth (), colortype); - write_log (L"W=%d H=%d B=%d CT=%d\n", - DirectDraw_CurrentWidth (), DirectDraw_CurrentHeight (), DirectDraw_GetCurrentDepth (), colortype); + if (currentmode->current_depth < 15 && (currprefs.chipset_mask & CSMASK_AGA) && isfullscreen () > 0 && !WIN32GFX_IsPicassoScreen()) { + static int warned; + if (!warned) { + TCHAR szMessage[MAX_DPATH]; + currentmode->current_depth = 16; + WIN32GUI_LoadUIString(IDS_AGA8BIT, szMessage, MAX_DPATH); + gui_message(szMessage); + } + warned = 1; + } - if (currentmode->current_depth < 15 && (currprefs.chipset_mask & CSMASK_AGA) && isfullscreen () > 0 && !WIN32GFX_IsPicassoScreen()) { - static int warned; - if (!warned) { - TCHAR szMessage[MAX_DPATH]; - currentmode->current_depth = 16; - WIN32GUI_LoadUIString(IDS_AGA8BIT, szMessage, MAX_DPATH); - gui_message(szMessage); - } - warned = 1; - } - - if (isfullscreen() <= 0 && !(currentmode->flags & (DM_OPENGL | DM_D3D))) { - currentmode->current_depth = DirectDraw_GetCurrentDepth (); - updatemodes (); - } - 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_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; - } - if (fs_warning >= 0 && isfullscreen () <= 0) { - TCHAR szMessage[MAX_DPATH], szMessage2[MAX_DPATH]; - WIN32GUI_LoadUIString(IDS_UNSUPPORTEDSCREENMODE, szMessage, MAX_DPATH); - WIN32GUI_LoadUIString(fs_warning, szMessage2, MAX_DPATH); - // Temporarily drop the DirectDraw stuff - DirectDraw_Release (); - _stprintf (tmpstr, szMessage, szMessage2); - gui_message (tmpstr); - DirectDraw_Start (displayGUID); - if (screen_is_picasso) - changed_prefs.gfx_pfullscreen = currprefs.gfx_pfullscreen = 1; - else - changed_prefs.gfx_afullscreen = currprefs.gfx_afullscreen = 1; - updatewinfsmode (&currprefs); - updatewinfsmode (&changed_prefs); - currentmode->current_depth = tmp_depth; - updatemodes (); - ret = -2; - goto oops; - } - if (! create_windows ()) - goto oops; + if (isfullscreen() <= 0 && !(currentmode->flags & (DM_OPENGL | DM_D3D))) { + currentmode->current_depth = DirectDraw_GetCurrentDepth (); + updatemodes (); + } + 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_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; + } + if (fs_warning >= 0 && isfullscreen () <= 0) { + TCHAR szMessage[MAX_DPATH], szMessage2[MAX_DPATH]; + WIN32GUI_LoadUIString(IDS_UNSUPPORTEDSCREENMODE, szMessage, MAX_DPATH); + WIN32GUI_LoadUIString(fs_warning, szMessage2, MAX_DPATH); + // Temporarily drop the DirectDraw stuff + DirectDraw_Release (); + _stprintf (tmpstr, szMessage, szMessage2); + gui_message (tmpstr); + DirectDraw_Start (displayGUID); + if (screen_is_picasso) + changed_prefs.gfx_pfullscreen = currprefs.gfx_pfullscreen = 1; + else + changed_prefs.gfx_afullscreen = currprefs.gfx_afullscreen = 1; + updatewinfsmode (&currprefs); + updatewinfsmode (&changed_prefs); + currentmode->current_depth = tmp_depth; + updatemodes (); + ret = -2; + goto oops; + } + if (! create_windows ()) + goto oops; #ifdef PICASSO96 - if (screen_is_picasso) { - break; - } else { + if (screen_is_picasso) { + break; + } else { #endif - currentmode->native_depth = currentmode->current_depth; + currentmode->native_depth = currentmode->current_depth; #if defined (GFXFILTER) - if (currentmode->flags & (DM_OPENGL | DM_D3D | DM_SWSCALE)) { - currentmode->amiga_width = AMIGA_WIDTH_MAX << currprefs.gfx_resolution; - currentmode->amiga_height = AMIGA_HEIGHT_MAX << (currprefs.gfx_linedbl ? 1 : 0); - if (usedfilter) { - if (usedfilter->x[0]) { - currentmode->current_depth = (currprefs.gfx_filter_filtermode / 2) ? 32 : 16; - } else { - int j, i; - j = 0; - for (i = 1; i <= 4; i++) { - if (usedfilter->x[i]) - j++; - } - i = currprefs.gfx_filter_filtermode; - if (i >= j) - i = 0; - j = 0; - while (i >= 0) { - while (!usedfilter->x[j]) - j++; - if(i-- > 0) - j++; + if (currentmode->flags & (DM_OPENGL | DM_D3D | DM_SWSCALE)) { + currentmode->amiga_width = AMIGA_WIDTH_MAX << currprefs.gfx_resolution; + currentmode->amiga_height = AMIGA_HEIGHT_MAX << (currprefs.gfx_linedbl ? 1 : 0); + if (usedfilter) { + if (usedfilter->x[0]) { + currentmode->current_depth = (currprefs.gfx_filter_filtermode / 2) ? 32 : 16; + } else { + int j, i; + j = 0; + for (i = 1; i <= 4; i++) { + if (usedfilter->x[i]) + j++; + } + i = currprefs.gfx_filter_filtermode; + if (i >= j) + i = 0; + j = 0; + while (i >= 0) { + while (!usedfilter->x[j]) + j++; + if(i-- > 0) + j++; + } + if ((usedfilter->x[j] & (UAE_FILTER_MODE_16 | UAE_FILTER_MODE_32)) == (UAE_FILTER_MODE_16 | UAE_FILTER_MODE_32)) { + currentmode->current_depth = currentmode->native_depth; + } else { + currentmode->current_depth = (usedfilter->x[j] & UAE_FILTER_MODE_16) ? 16 : 32; + } + mult = j; + } + } + currentmode->pitch = currentmode->amiga_width * currentmode->current_depth >> 3; } - if ((usedfilter->x[j] & (UAE_FILTER_MODE_16 | UAE_FILTER_MODE_32)) == (UAE_FILTER_MODE_16 | UAE_FILTER_MODE_32)) { - currentmode->current_depth = currentmode->native_depth; - } else { - currentmode->current_depth = (usedfilter->x[j] & UAE_FILTER_MODE_16) ? 16 : 32; + else +#endif + { + currentmode->amiga_width = currentmode->current_width; + currentmode->amiga_height = currentmode->current_height; } - mult = j; - } + gfxvidinfo.pixbytes = currentmode->current_depth >> 3; + gfxvidinfo.bufmem = 0; + gfxvidinfo.linemem = 0; + gfxvidinfo.emergmem = scrlinebuf; // memcpy from system-memory to video-memory + gfxvidinfo.width = (currentmode->amiga_width + 7) & ~7; + gfxvidinfo.height = currentmode->amiga_height; + gfxvidinfo.maxblocklines = 0; // flush_screen actually does everything + gfxvidinfo.rowbytes = currentmode->pitch; + break; +#ifdef PICASSO96 } - currentmode->pitch = currentmode->amiga_width * currentmode->current_depth >> 3; - } - else #endif - { - currentmode->amiga_width = currentmode->current_width; - currentmode->amiga_height = currentmode->current_height; - } - gfxvidinfo.pixbytes = currentmode->current_depth >> 3; - gfxvidinfo.bufmem = 0; - gfxvidinfo.linemem = 0; - gfxvidinfo.emergmem = scrlinebuf; // memcpy from system-memory to video-memory - gfxvidinfo.width = (currentmode->amiga_width + 7) & ~7; - gfxvidinfo.height = currentmode->amiga_height; - gfxvidinfo.maxblocklines = 0; // flush_screen actually does everything - gfxvidinfo.rowbytes = currentmode->pitch; - break; -#ifdef PICASSO96 } -#endif - } #ifdef PICASSO96 - 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.offset = 0; + 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.offset = 0; #endif - xfree (gfxvidinfo.realbufmem); - gfxvidinfo.realbufmem = NULL; - gfxvidinfo.bufmem = NULL; + xfree (gfxvidinfo.realbufmem); + gfxvidinfo.realbufmem = NULL; + gfxvidinfo.bufmem = NULL; - if ((currentmode->flags & DM_DDRAW) && !(currentmode->flags & (DM_D3D | DM_SWSCALE | DM_OPENGL))) { + if ((currentmode->flags & DM_DDRAW) && !(currentmode->flags & (DM_D3D | DM_SWSCALE | DM_OPENGL))) { - ; + ; - } else if (!(currentmode->flags & DM_SWSCALE)) { + } else if (!(currentmode->flags & DM_SWSCALE)) { - int size = currentmode->amiga_width * currentmode->amiga_height * gfxvidinfo.pixbytes; - gfxvidinfo.realbufmem = xmalloc (size); - gfxvidinfo.bufmem = gfxvidinfo.realbufmem; - gfxvidinfo.rowbytes = currentmode->amiga_width * gfxvidinfo.pixbytes; - gfxvidinfo.bufmemend = gfxvidinfo.bufmem + size; + int size = currentmode->amiga_width * currentmode->amiga_height * gfxvidinfo.pixbytes; + gfxvidinfo.realbufmem = xmalloc (size); + gfxvidinfo.bufmem = gfxvidinfo.realbufmem; + gfxvidinfo.rowbytes = currentmode->amiga_width * gfxvidinfo.pixbytes; + gfxvidinfo.bufmemend = gfxvidinfo.bufmem + size; - } else if (!(currentmode->flags & DM_D3D)) { + } else if (!(currentmode->flags & DM_D3D)) { - int w = currentmode->amiga_width * 2; - int h = currentmode->amiga_height * 2; - int size = (w * 2) * (h * 3) * gfxvidinfo.pixbytes; - gfxvidinfo.realbufmem = xmalloc (size); - memset (gfxvidinfo.realbufmem, 0, size); - gfxvidinfo.bufmem = gfxvidinfo.realbufmem + (w + (w * 2) * h) * gfxvidinfo.pixbytes; - gfxvidinfo.rowbytes = w * 2 * gfxvidinfo.pixbytes; - gfxvidinfo.bufmemend = gfxvidinfo.realbufmem + size - gfxvidinfo.rowbytes; + int w = currentmode->amiga_width * 2; + int h = currentmode->amiga_height * 2; + int size = (w * 2) * (h * 3) * gfxvidinfo.pixbytes; + gfxvidinfo.realbufmem = xmalloc (size); + memset (gfxvidinfo.realbufmem, 0, size); + gfxvidinfo.bufmem = gfxvidinfo.realbufmem + (w + (w * 2) * h) * gfxvidinfo.pixbytes; + gfxvidinfo.rowbytes = w * 2 * gfxvidinfo.pixbytes; + gfxvidinfo.bufmemend = gfxvidinfo.realbufmem + size - gfxvidinfo.rowbytes; - } + } - init_row_map (); - init_colors (); + init_row_map (); + init_colors (); #if defined (GFXFILTER) - S2X_free (); - if ((currentmode->flags & DM_SWSCALE) && !WIN32GFX_IsPicassoScreen ()) { - S2X_init (currentmode->native_width, currentmode->native_height, - currentmode->amiga_width, currentmode->amiga_height, - mult, currentmode->current_depth, currentmode->native_depth); - } + S2X_free (); + if ((currentmode->flags & DM_SWSCALE) && !WIN32GFX_IsPicassoScreen ()) { + S2X_init (currentmode->native_width, currentmode->native_height, + currentmode->amiga_width, currentmode->amiga_height, + mult, currentmode->current_depth, currentmode->native_depth); + } #if defined OPENGL - if (currentmode->flags & DM_OPENGL) { - const TCHAR *err = OGL_init (hAmigaWnd, currentmode->native_width, currentmode->native_height, - currentmode->amiga_width, currentmode->amiga_height, currentmode->current_depth); - if (err) { - OGL_free (); - if (err[0] != '*') { - gui_message (err); - changed_prefs.gfx_filter = currprefs.gfx_filter = 0; - } - currentmode->current_depth = currentmode->native_depth; - gfxmode_reset (); - ret = -1; - goto oops; - } - } + if (currentmode->flags & DM_OPENGL) { + const TCHAR *err = OGL_init (hAmigaWnd, currentmode->native_width, currentmode->native_height, + currentmode->amiga_width, currentmode->amiga_height, currentmode->current_depth); + if (err) { + OGL_free (); + if (err[0] != '*') { + gui_message (err); + changed_prefs.gfx_filter = currprefs.gfx_filter = 0; + } + currentmode->current_depth = currentmode->native_depth; + gfxmode_reset (); + ret = -1; + goto oops; + } + } #endif #ifdef D3D - if (currentmode->flags & DM_D3D) { - const TCHAR *err = D3D_init (hAmigaWnd, currentmode->native_width, currentmode->native_height, - currentmode->amiga_width, currentmode->amiga_height, currentmode->current_depth); - if (err) { - D3D_free (); - gui_message (err); - changed_prefs.gfx_filter = currprefs.gfx_filter = 0; - currentmode->current_depth = currentmode->native_depth; - gfxmode_reset (); - ret = -1; - goto oops; - } - } + if (currentmode->flags & DM_D3D) { + const TCHAR *err = D3D_init (hAmigaWnd, currentmode->native_width, currentmode->native_height, + currentmode->amiga_width, currentmode->amiga_height, currentmode->current_depth); + if (err) { + D3D_free (); + gui_message (err); + changed_prefs.gfx_filter = currprefs.gfx_filter = 0; + currentmode->current_depth = currentmode->native_depth; + gfxmode_reset (); + ret = -1; + goto oops; + } + } #endif #endif - screen_is_initialized = 1; - WIN32GFX_SetPalette (); + screen_is_initialized = 1; + WIN32GFX_SetPalette (); #ifdef PICASSO96 - DX_SetPalette (0, 256); + DX_SetPalette (0, 256); #endif - picasso_refresh (); + picasso_refresh (); - if (isfullscreen () > 0) - setmouseactive (-1); + if (isfullscreen () > 0) + setmouseactive (-1); - return 1; + return 1; oops: - close_hwnds(); - return ret; + close_hwnds(); + return ret; } void WIN32GFX_PaletteChange(void) { - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) - return; - if (currentmode->current_depth > 8) - return; - DirectDraw_SetPalette (1); /* Remove current palette */ - DirectDraw_SetPalette (0); /* Set our real palette */ + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return; + if (currentmode->current_depth > 8) + return; + DirectDraw_SetPalette (1); /* Remove current palette */ + DirectDraw_SetPalette (0); /* Set our real palette */ } int WIN32GFX_ClearPalette(void) { - if (currentmode->current_depth > 8) - return 1; - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + if (currentmode->current_depth > 8) + return 1; + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return 1; + DirectDraw_SetPalette (1); /* Remove palette */ return 1; - DirectDraw_SetPalette (1); /* Remove palette */ - return 1; } int WIN32GFX_SetPalette(void) { - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) - return 1; - if (currentmode->current_depth > 8) + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return 1; + if (currentmode->current_depth > 8) + return 1; + DirectDraw_SetPalette (0); /* Set palette */ return 1; - DirectDraw_SetPalette (0); /* Set palette */ - return 1; } void WIN32GFX_WindowMove (void) { @@ -2599,92 +2599,92 @@ void WIN32GFX_WindowMove (void) void updatedisplayarea (void) { - if (!screen_is_initialized) - return; - if (picasso_on) - return; - if (dx_islost ()) - return; + if (!screen_is_initialized) + return; + if (picasso_on) + return; + if (dx_islost ()) + return; #if defined (GFXFILTER) - if (currentmode->flags & DM_OPENGL) { + if (currentmode->flags & DM_OPENGL) { #if defined (OPENGL) - OGL_refresh (); + OGL_refresh (); #endif - } else if (currentmode->flags & DM_D3D) { + } else if (currentmode->flags & DM_D3D) { #if defined (D3D) - D3D_refresh (); + D3D_refresh (); #endif - } else + } else #endif - if (currentmode->flags & DM_DDRAW) { + if (currentmode->flags & DM_DDRAW) { #if defined (GFXFILTER) - if (currentmode->flags & DM_SWSCALE) - S2X_refresh (); + if (currentmode->flags & DM_SWSCALE) + S2X_refresh (); #endif - DirectDraw_Flip (0); - } + DirectDraw_Flip (0); + } } void updatewinfsmode (struct uae_prefs *p) { - struct MultiDisplay *md; - - fixup_prefs_dimensions (p); - if (isfullscreen_2 (p) != 0) { - p->gfx_size = p->gfx_size_fs; - } else { - p->gfx_size = p->gfx_size_win; - } - displayGUID = NULL; - md = getdisplay (p); - if (md->disabled) { - p->gfx_display = 0; - md = getdisplay (p); - } - if (!md->primary) - displayGUID = &md->guid; - if (isfullscreen () == 0) + struct MultiDisplay *md; + + fixup_prefs_dimensions (p); + if (isfullscreen_2 (p) != 0) { + p->gfx_size = p->gfx_size_fs; + } else { + p->gfx_size = p->gfx_size_win; + } displayGUID = NULL; + md = getdisplay (p); + if (md->disabled) { + p->gfx_display = 0; + md = getdisplay (p); + } + if (!md->primary) + displayGUID = &md->guid; + if (isfullscreen () == 0) + displayGUID = NULL; } void toggle_fullscreen (void) { - if(picasso_on) - changed_prefs.gfx_pfullscreen = !changed_prefs.gfx_pfullscreen; - else - changed_prefs.gfx_afullscreen = !changed_prefs.gfx_afullscreen; - updatewinfsmode (&changed_prefs); + if(picasso_on) + changed_prefs.gfx_pfullscreen = !changed_prefs.gfx_pfullscreen; + else + changed_prefs.gfx_afullscreen = !changed_prefs.gfx_afullscreen; + updatewinfsmode (&changed_prefs); } HDC gethdc (void) { - HDC hdc = 0; + HDC hdc = 0; #ifdef OPENGL - if (OGL_isenabled ()) - return OGL_getDC (0); + if (OGL_isenabled ()) + return OGL_getDC (0); #endif #ifdef D3D - if (D3D_isenabled ()) - return D3D_getDC (0); + if (D3D_isenabled ()) + return D3D_getDC (0); #endif - if(FAILED (DirectDraw_GetDC (&hdc))) - hdc = 0; - return hdc; + if(FAILED (DirectDraw_GetDC (&hdc))) + hdc = 0; + return hdc; } void releasehdc (HDC hdc) { #ifdef OPENGL - if (OGL_isenabled ()) { - OGL_getDC (hdc); - return; - } + if (OGL_isenabled ()) { + OGL_getDC (hdc); + return; + } #endif #ifdef D3D - if (D3D_isenabled ()) { - D3D_getDC (hdc); - return; - } + if (D3D_isenabled ()) { + D3D_getDC (hdc); + return; + } #endif - DirectDraw_ReleaseDC (hdc); + DirectDraw_ReleaseDC (hdc); } diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index c468890e..f9002334 100644 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -1,11 +1,11 @@ /*========================================================================== - * - * Copyright (C) 1996 Brian King - * - * File: win32gui.c - * Content: Win32-specific gui features for UAE port. - * - ***************************************************************************/ +* +* Copyright (C) 1996 Brian King +* +* File: win32gui.c +* Content: Win32-specific gui features for UAE port. +* +***************************************************************************/ #define CONFIGCACHE 1 #define FRONTEND 0 @@ -88,11 +88,11 @@ #define ARCHIVE_STRING L"*.zip;*.7z;*.rar;*.lha;*.lzh;*.lzx" -#define DISK_FORMAT_STRING L"(*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.exe)\0*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.exe;*.ima;*.wrp;*.dsq;" ARCHIVE_STRING L"\0" +#define DISK_FORMAT_STRING L"(*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.exe)\0*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.exe;*.ima;*.wrp;*.dsq;*.st;" ARCHIVE_STRING L"\0" #define ROM_FORMAT_STRING L"(*.rom;*.roz)\0*.rom;*.roz;" ARCHIVE_STRING L"\0" #define USS_FORMAT_STRING_RESTORE L"(*.uss)\0*.uss;*.gz;" ARCHIVE_STRING L"\0" #define USS_FORMAT_STRING_SAVE L"(*.uss)\0*.uss\0" -#define HDF_FORMAT_STRING L"(*.hdf;*.rdf;*.hdz;*.rdz)\0*.hdf;*.rdf;*.hdz;*.rdz\0" +#define HDF_FORMAT_STRING L"(*.hdf;*.vhd;*.rdf;*.hdz;*.rdz)\0*.hdf;*.vhd;*.rdf;*.hdz;*.rdz\0" #define INP_FORMAT_STRING L"(*.inp)\0*.inp\0" #define CONFIG_HOST L"Host" #define CONFIG_HARDWARE L"Hardware" @@ -129,590 +129,590 @@ static TCHAR stored_path[MAX_DPATH]; void WIN32GUI_LoadUIString (DWORD id, TCHAR *string, DWORD dwStringLen) { - if (LoadString (hUIDLL ? hUIDLL : hInst, id, string, dwStringLen) == 0) - LoadString (hInst, id, string, dwStringLen); + if (LoadString (hUIDLL ? hUIDLL : hInst, id, string, dwStringLen) == 0) + LoadString (hInst, id, string, dwStringLen); } static int C_PAGES; #define MAX_C_PAGES 30 static int LOADSAVE_ID = -1, MEMORY_ID = -1, KICKSTART_ID = -1, CPU_ID = -1, - DISPLAY_ID = -1, HW3D_ID = -1, CHIPSET_ID = -1, CHIPSET2_ID = -1, SOUND_ID = -1, FLOPPY_ID = -1, DISK_ID = -1, - HARDDISK_ID = -1, IOPORTS_ID = -1, GAMEPORTS_ID = -1, INPUT_ID = -1, MISC1_ID = -1, MISC2_ID = -1, AVIOUTPUT_ID = -1, - PATHS_ID = -1, QUICKSTART_ID = -1, ABOUT_ID = -1, EXPANSION_ID = -1, FRONTEND_ID = -1; + DISPLAY_ID = -1, HW3D_ID = -1, CHIPSET_ID = -1, CHIPSET2_ID = -1, SOUND_ID = -1, FLOPPY_ID = -1, DISK_ID = -1, + HARDDISK_ID = -1, IOPORTS_ID = -1, GAMEPORTS_ID = -1, INPUT_ID = -1, MISC1_ID = -1, MISC2_ID = -1, AVIOUTPUT_ID = -1, + PATHS_ID = -1, QUICKSTART_ID = -1, ABOUT_ID = -1, EXPANSION_ID = -1, FRONTEND_ID = -1; static HWND pages[MAX_C_PAGES]; #define MAX_IMAGETOOLTIPS 10 static HWND guiDlg, panelDlg, ToolTipHWND; static HACCEL hAccelTable; struct ToolTipHWNDS { - WNDPROC proc; - HWND hwnd; - int imageid; + WNDPROC proc; + HWND hwnd; + int imageid; }; static struct ToolTipHWNDS ToolTipHWNDS2[MAX_IMAGETOOLTIPS + 1]; static void ew (HWND hDlg, DWORD id, int enable) { - HWND w = GetDlgItem (hDlg, id); - if (!w) - return; - if (!enable && w == GetFocus ()) - SendMessage (hDlg, WM_NEXTDLGCTL, 0, FALSE); - EnableWindow (w, !!enable); + HWND w = GetDlgItem (hDlg, id); + if (!w) + return; + if (!enable && w == GetFocus ()) + SendMessage (hDlg, WM_NEXTDLGCTL, 0, FALSE); + EnableWindow (w, !!enable); } static int CALLBACK BrowseForFolderCallback (HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) { - TCHAR szPath[MAX_PATH]; - switch(uMsg) - { - case BFFM_INITIALIZED: - SendMessage (hwnd, BFFM_SETSELECTION, TRUE, pData); - break; + TCHAR szPath[MAX_PATH]; + switch(uMsg) + { + case BFFM_INITIALIZED: + SendMessage (hwnd, BFFM_SETSELECTION, TRUE, pData); + break; case BFFM_SELCHANGED: - if (SHGetPathFromIDList ((LPITEMIDLIST)lp ,szPath)) - SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szPath); - break; - } - return 0; + if (SHGetPathFromIDList ((LPITEMIDLIST)lp ,szPath)) + SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szPath); + break; + } + return 0; } static int DirectorySelection2 (OPENFILENAME *ofn) { - BROWSEINFO bi; - LPITEMIDLIST pidlBrowse; - TCHAR buf[MAX_DPATH], fullpath[MAX_DPATH]; - TCHAR *path = ofn->lpstrFile; - int ret = 0; - - buf[0] = 0; - memset (&bi, 0, sizeof bi); - bi.hwndOwner = ofn->hwndOwner; - bi.pidlRoot = NULL; - bi.pszDisplayName = buf; - bi.lpszTitle = NULL; - bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; - if (path[0] && GetFullPathName (path, sizeof fullpath / sizeof (TCHAR), fullpath, NULL)) { - bi.lpfn = BrowseForFolderCallback; - bi.lParam = (LPARAM)fullpath; - } - // Browse for a folder and return its PIDL. - pidlBrowse = SHBrowseForFolder (&bi); - if (pidlBrowse != NULL) { - if (SHGetPathFromIDList (pidlBrowse, buf)) { - _tcscpy (path, buf); - ret = 1; - } - CoTaskMemFree (pidlBrowse); - } - return ret; + BROWSEINFO bi; + LPITEMIDLIST pidlBrowse; + TCHAR buf[MAX_DPATH], fullpath[MAX_DPATH]; + TCHAR *path = ofn->lpstrFile; + int ret = 0; + + buf[0] = 0; + memset (&bi, 0, sizeof bi); + bi.hwndOwner = ofn->hwndOwner; + bi.pidlRoot = NULL; + bi.pszDisplayName = buf; + bi.lpszTitle = NULL; + bi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; + if (path[0] && GetFullPathName (path, sizeof fullpath / sizeof (TCHAR), fullpath, NULL)) { + bi.lpfn = BrowseForFolderCallback; + bi.lParam = (LPARAM)fullpath; + } + // Browse for a folder and return its PIDL. + pidlBrowse = SHBrowseForFolder (&bi); + if (pidlBrowse != NULL) { + if (SHGetPathFromIDList (pidlBrowse, buf)) { + _tcscpy (path, buf); + ret = 1; + } + CoTaskMemFree (pidlBrowse); + } + return ret; } static TCHAR *getfilepath (TCHAR *s) { - TCHAR *p = _tcsrchr (s, '\\'); - if (p) - return p + 1; - return NULL; + TCHAR *p = _tcsrchr (s, '\\'); + if (p) + return p + 1; + return NULL; } typedef HRESULT (CALLBACK* SHCREATEITEMFROMPARSINGNAME) - (PCWSTR,IBindCtx*,REFIID,void**); // Vista+ only + (PCWSTR,IBindCtx*,REFIID,void**); // Vista+ only // OPENFILENAME->IFileOpenDialog wrapper static BOOL GetFileDialog (OPENFILENAME *opn, const GUID *guid, int mode) { - SHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName; - HRESULT hr; - IFileOpenDialog *pfd; - FILEOPENDIALOGOPTIONS pfos; - IShellItem *shellitem = NULL; - int ret; - COMDLG_FILTERSPEC *fs = NULL; - int filtercnt = 0; - - hr = -1; - ret = 0; - pSHCreateItemFromParsingName = (SHCREATEITEMFROMPARSINGNAME)GetProcAddress ( - GetModuleHandle (L"shell32.dll"), "SHCreateItemFromParsingName"); - if (pSHCreateItemFromParsingName) - hr = CoCreateInstance (mode > 0 ? &CLSID_FileSaveDialog : &CLSID_FileOpenDialog, - NULL, - CLSCTX_INPROC_SERVER, - mode > 0 ? &IID_IFileSaveDialog : &IID_IFileOpenDialog, (LPVOID*)&pfd); - if (FAILED (hr)) { - if (mode > 0) - return GetSaveFileName (opn); - else if (mode == 0) - return GetOpenFileName (opn); - else - return DirectorySelection2 (opn); - } - IFileDialog_GetOptions (pfd, &pfos); - pfos |= FOS_FORCEFILESYSTEM; - if (opn->Flags & OFN_ALLOWMULTISELECT) - pfos |= FOS_ALLOWMULTISELECT; - if (mode < 0) - pfos |= FOS_PICKFOLDERS; - IFileDialog_SetOptions (pfd, pfos); - - if (guid) - IFileDialog_SetClientGuid (pfd, guid); - - if (opn->lpstrFilter) { - const TCHAR *p = opn->lpstrFilter; - int i; - while (*p) { - p += _tcslen (p) + 1; - p += _tcslen (p) + 1; - filtercnt++; + SHCREATEITEMFROMPARSINGNAME pSHCreateItemFromParsingName; + HRESULT hr; + IFileOpenDialog *pfd; + FILEOPENDIALOGOPTIONS pfos; + IShellItem *shellitem = NULL; + int ret; + COMDLG_FILTERSPEC *fs = NULL; + int filtercnt = 0; + + hr = -1; + ret = 0; + pSHCreateItemFromParsingName = (SHCREATEITEMFROMPARSINGNAME)GetProcAddress ( + GetModuleHandle (L"shell32.dll"), "SHCreateItemFromParsingName"); + if (pSHCreateItemFromParsingName) + hr = CoCreateInstance (mode > 0 ? &CLSID_FileSaveDialog : &CLSID_FileOpenDialog, + NULL, + CLSCTX_INPROC_SERVER, + mode > 0 ? &IID_IFileSaveDialog : &IID_IFileOpenDialog, (LPVOID*)&pfd); + if (FAILED (hr)) { + if (mode > 0) + return GetSaveFileName (opn); + else if (mode == 0) + return GetOpenFileName (opn); + else + return DirectorySelection2 (opn); } - if (filtercnt) { - fs = xmalloc (sizeof (COMDLG_FILTERSPEC) * filtercnt); - p = opn->lpstrFilter; - for (i = 0; i < filtercnt; i++) { - fs[i].pszName = p; - p += _tcslen (p) + 1; - fs[i].pszSpec = p; - p += _tcslen (p) + 1; - } - IFileDialog_SetFileTypes (pfd, filtercnt, fs); - } - IFileOpenDialog_SetFileTypeIndex (pfd, opn->nFilterIndex); - } - - if (opn->lpstrTitle) { - IFileDialog_SetTitle (pfd, opn->lpstrTitle); - } - if (opn->lpstrDefExt) { - IFileDialog_SetDefaultExtension (pfd, opn->lpstrDefExt); - } - if (opn->lpstrInitialDir) { - TCHAR tmp[MAX_DPATH]; - const TCHAR *p = opn->lpstrInitialDir; - if (GetFullPathName (p, sizeof tmp / sizeof (TCHAR), tmp, NULL)) - p = tmp; - hr = pSHCreateItemFromParsingName (p, NULL, &IID_IShellItem, &shellitem); - if (SUCCEEDED (hr)) - IFileDialog_SetFolder (pfd, shellitem); - } - - hr = IFileDialog_Show (pfd, opn->hwndOwner); - if (SUCCEEDED (hr)) { - UINT idx; - IShellItemArray *pitema; - opn->lpstrFile[0] = 0; - opn->lpstrFile[1] = 0; - if (opn->lpstrFileTitle) - opn->lpstrFileTitle[0] = 0; - if (mode > 0) { - IShellItem *pitem; - hr = IFileOpenDialog_GetResult (pfd, &pitem); - if (SUCCEEDED (hr)) { - WCHAR *path = NULL; - hr = IShellItem_GetDisplayName (pitem, SIGDN_FILESYSPATH, &path); - if (SUCCEEDED (hr)) { - TCHAR *p = opn->lpstrFile; - _tcscpy (p, path); - p[_tcslen (p) + 1] = 0; - p = getfilepath (opn->lpstrFile); - if (p && opn->lpstrFileTitle) - _tcscpy (opn->lpstrFileTitle, p); - } - IShellItem_Release (pitem); - } - } else { - hr = IFileOpenDialog_GetResults (pfd, &pitema); - if (SUCCEEDED (hr)) { - DWORD cnt; - hr = IShellItemArray_GetCount (pitema, &cnt); - if (SUCCEEDED (hr)) { - int i; - for (i = 0; i < cnt; i++) { + IFileDialog_GetOptions (pfd, &pfos); + pfos |= FOS_FORCEFILESYSTEM; + if (opn->Flags & OFN_ALLOWMULTISELECT) + pfos |= FOS_ALLOWMULTISELECT; + if (mode < 0) + pfos |= FOS_PICKFOLDERS; + IFileDialog_SetOptions (pfd, pfos); + + if (guid) + IFileDialog_SetClientGuid (pfd, guid); + + if (opn->lpstrFilter) { + const TCHAR *p = opn->lpstrFilter; + int i; + while (*p) { + p += _tcslen (p) + 1; + p += _tcslen (p) + 1; + filtercnt++; + } + if (filtercnt) { + fs = xmalloc (sizeof (COMDLG_FILTERSPEC) * filtercnt); + p = opn->lpstrFilter; + for (i = 0; i < filtercnt; i++) { + fs[i].pszName = p; + p += _tcslen (p) + 1; + fs[i].pszSpec = p; + p += _tcslen (p) + 1; + } + IFileDialog_SetFileTypes (pfd, filtercnt, fs); + } + IFileOpenDialog_SetFileTypeIndex (pfd, opn->nFilterIndex); + } + + if (opn->lpstrTitle) { + IFileDialog_SetTitle (pfd, opn->lpstrTitle); + } + if (opn->lpstrDefExt) { + IFileDialog_SetDefaultExtension (pfd, opn->lpstrDefExt); + } + if (opn->lpstrInitialDir) { + TCHAR tmp[MAX_DPATH]; + const TCHAR *p = opn->lpstrInitialDir; + if (GetFullPathName (p, sizeof tmp / sizeof (TCHAR), tmp, NULL)) + p = tmp; + hr = pSHCreateItemFromParsingName (p, NULL, &IID_IShellItem, &shellitem); + if (SUCCEEDED (hr)) + IFileDialog_SetFolder (pfd, shellitem); + } + + hr = IFileDialog_Show (pfd, opn->hwndOwner); + if (SUCCEEDED (hr)) { + UINT idx; + IShellItemArray *pitema; + opn->lpstrFile[0] = 0; + opn->lpstrFile[1] = 0; + if (opn->lpstrFileTitle) + opn->lpstrFileTitle[0] = 0; + if (mode > 0) { IShellItem *pitem; - hr = IShellItemArray_GetItemAt (pitema, i, &pitem); + hr = IFileOpenDialog_GetResult (pfd, &pitem); if (SUCCEEDED (hr)) { - WCHAR *path = NULL; - hr = IShellItem_GetDisplayName (pitem, SIGDN_FILESYSPATH, &path); - if (SUCCEEDED (hr)) { - TCHAR *p = opn->lpstrFile; - while (*p) - p += _tcslen (p) + 1; - if (p - opn->lpstrFile + _tcslen (path) + 2 < opn->nMaxFile) { - _tcscpy (p, path); - p[_tcslen (p) + 1] = 0; + WCHAR *path = NULL; + hr = IShellItem_GetDisplayName (pitem, SIGDN_FILESYSPATH, &path); + if (SUCCEEDED (hr)) { + TCHAR *p = opn->lpstrFile; + _tcscpy (p, path); + p[_tcslen (p) + 1] = 0; + p = getfilepath (opn->lpstrFile); + if (p && opn->lpstrFileTitle) + _tcscpy (opn->lpstrFileTitle, p); } - if (opn->lpstrFileTitle && !opn->lpstrFileTitle[0]) { - p = getfilepath (opn->lpstrFile); - if (p && opn->lpstrFileTitle) - _tcscpy (opn->lpstrFileTitle, p); + IShellItem_Release (pitem); + } + } else { + hr = IFileOpenDialog_GetResults (pfd, &pitema); + if (SUCCEEDED (hr)) { + DWORD cnt; + hr = IShellItemArray_GetCount (pitema, &cnt); + if (SUCCEEDED (hr)) { + int i; + for (i = 0; i < cnt; i++) { + IShellItem *pitem; + hr = IShellItemArray_GetItemAt (pitema, i, &pitem); + if (SUCCEEDED (hr)) { + WCHAR *path = NULL; + hr = IShellItem_GetDisplayName (pitem, SIGDN_FILESYSPATH, &path); + if (SUCCEEDED (hr)) { + TCHAR *p = opn->lpstrFile; + while (*p) + p += _tcslen (p) + 1; + if (p - opn->lpstrFile + _tcslen (path) + 2 < opn->nMaxFile) { + _tcscpy (p, path); + p[_tcslen (p) + 1] = 0; + } + if (opn->lpstrFileTitle && !opn->lpstrFileTitle[0]) { + p = getfilepath (opn->lpstrFile); + if (p && opn->lpstrFileTitle) + _tcscpy (opn->lpstrFileTitle, p); + } + } + CoTaskMemFree (path); + } + } } - } - CoTaskMemFree (path); + IShellItemArray_Release (pitema); } - } } - IShellItemArray_Release (pitema); - } + hr = IFileOpenDialog_GetFileTypeIndex (pfd, &idx); + if (SUCCEEDED (hr)) + opn->nFilterIndex = idx; + ret = 1; } - hr = IFileOpenDialog_GetFileTypeIndex (pfd, &idx); - if (SUCCEEDED (hr)) - opn->nFilterIndex = idx; - ret = 1; - } - IFileDialog_Release (pfd); - if (shellitem) - IShellItem_Release (shellitem); - if (filtercnt) { - xfree (fs); - } - return ret; + IFileDialog_Release (pfd); + if (shellitem) + IShellItem_Release (shellitem); + if (filtercnt) { + xfree (fs); + } + return ret; } static BOOL GetOpenFileName_2 (OPENFILENAME *opn, const GUID *guid) { - return GetFileDialog (opn, guid, 0); + return GetFileDialog (opn, guid, 0); } static BOOL GetSaveFileName_2 (OPENFILENAME *opn, const GUID *guid) { - return GetFileDialog (opn, guid, 1); + return GetFileDialog (opn, guid, 1); } int DirectorySelection (HWND hDlg, const GUID *guid, TCHAR *path) { - OPENFILENAME ofn = { 0 }; - ofn.hwndOwner = hDlg; - ofn.lpstrFile = path; - ofn.lpstrInitialDir = path; - ofn.nMaxFile = MAX_DPATH; - return GetFileDialog (&ofn, NULL, -1); + OPENFILENAME ofn = { 0 }; + ofn.hwndOwner = hDlg; + ofn.lpstrFile = path; + ofn.lpstrInitialDir = path; + ofn.nMaxFile = MAX_DPATH; + return GetFileDialog (&ofn, NULL, -1); } void write_disk_history (void) { - int i, j; - TCHAR tmp[16]; - UAEREG *fkey; - - fkey = regcreatetree (NULL, L"DiskImageMRUList"); - if (fkey == NULL) - return; - j = 1; - for (i = 0; i <= MAX_PREVIOUS_FLOPPIES; i++) { - TCHAR *s = DISK_history_get (i); - if (s == 0 || _tcslen (s) == 0) - continue; - _stprintf (tmp, L"Image%02d", j); - regsetstr (fkey, tmp, s); - j++; - } - while (j <= MAX_PREVIOUS_FLOPPIES) { - TCHAR *s = L""; - _stprintf (tmp, L"Image%02d", j); - regsetstr (fkey, tmp, s); - j++; - } - regclosetree (fkey); + int i, j; + TCHAR tmp[16]; + UAEREG *fkey; + + fkey = regcreatetree (NULL, L"DiskImageMRUList"); + if (fkey == NULL) + return; + j = 1; + for (i = 0; i <= MAX_PREVIOUS_FLOPPIES; i++) { + TCHAR *s = DISK_history_get (i); + if (s == 0 || _tcslen (s) == 0) + continue; + _stprintf (tmp, L"Image%02d", j); + regsetstr (fkey, tmp, s); + j++; + } + while (j <= MAX_PREVIOUS_FLOPPIES) { + TCHAR *s = L""; + _stprintf (tmp, L"Image%02d", j); + regsetstr (fkey, tmp, s); + j++; + } + regclosetree (fkey); } void reset_disk_history (void) { - int i; + int i; - for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) - DISK_history_add (NULL, i, 0); - write_disk_history (); + for (i = 0; i < MAX_PREVIOUS_FLOPPIES; i++) + DISK_history_add (NULL, i, 0); + write_disk_history (); } UAEREG *read_disk_history (void) { - static int regread; - TCHAR tmp2[1000]; - DWORD size2; - int idx, idx2; - UAEREG *fkey; - TCHAR tmp[1000]; - DWORD size; + static int regread; + TCHAR tmp2[1000]; + DWORD size2; + int idx, idx2; + UAEREG *fkey; + TCHAR tmp[1000]; + DWORD size; - fkey = regcreatetree (NULL, L"DiskImageMRUList"); - if (fkey == NULL || regread) - return fkey; + fkey = regcreatetree (NULL, L"DiskImageMRUList"); + if (fkey == NULL || regread) + return fkey; - idx = 0; - for (;;) { - size = sizeof (tmp) / sizeof (TCHAR); - size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - if (_tcslen (tmp) == 7) { - idx2 = _tstol (tmp + 5) - 1; - if (idx2 >= 0) - DISK_history_add (tmp2, idx2, 0); + idx = 0; + for (;;) { + size = sizeof (tmp) / sizeof (TCHAR); + size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + if (_tcslen (tmp) == 7) { + idx2 = _tstol (tmp + 5) - 1; + if (idx2 >= 0) + DISK_history_add (tmp2, idx2, 0); + } + idx++; } - idx++; - } - regread = 1; - return fkey; + regread = 1; + return fkey; } void exit_gui (int ok) { - if (!gui_active) - return; - if (guiDlg == NULL) - return; - SendMessage (guiDlg, WM_COMMAND, ok ? IDOK : IDCANCEL, 0); + if (!gui_active) + return; + if (guiDlg == NULL) + return; + SendMessage (guiDlg, WM_COMMAND, ok ? IDOK : IDCANCEL, 0); } static int getcbn (HWND hDlg, int v, TCHAR *out, int len) { - LRESULT val = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); - out[0] = 0; - if (val == CB_ERR) { - SendDlgItemMessage (hDlg, v, WM_GETTEXT, (WPARAM)len, (LPARAM)out); - return 1; - } else { - val = SendDlgItemMessage (hDlg, v, CB_GETLBTEXT, (WPARAM)val, (LPARAM)out); - return 0; - } + LRESULT val = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); + out[0] = 0; + if (val == CB_ERR) { + SendDlgItemMessage (hDlg, v, WM_GETTEXT, (WPARAM)len, (LPARAM)out); + return 1; + } else { + val = SendDlgItemMessage (hDlg, v, CB_GETLBTEXT, (WPARAM)val, (LPARAM)out); + return 0; + } } #define MAXFAVORITES 30 static void writefavoritepaths (int num, TCHAR **values, TCHAR **paths) { - int i; - UAEREG *fkey; - - fkey = regcreatetree (NULL, L"FavoritePaths"); - if (fkey == NULL) - return; - for (i = 0; i < num; i++) { - TCHAR str[MAX_DPATH]; - TCHAR key[100]; - if (!_tcscmp (values[i], paths[i])) - _tcscpy (str, values[i]); - else - _stprintf (str, L"%s \"%s\"", values[i], paths[i]); - _stprintf (key, L"PATH_ALL_%02d", i + 1); - regsetstr (fkey, key, str); - xfree (values[i]); - xfree (paths[i]); - } - while (i < MAXFAVORITES) { - TCHAR key[100]; - _stprintf (key, L"PATH_ALL_%02d", i + 1); - regdelete (fkey, key); - i++; - } - regclosetree (fkey); + int i; + UAEREG *fkey; + + fkey = regcreatetree (NULL, L"FavoritePaths"); + if (fkey == NULL) + return; + for (i = 0; i < num; i++) { + TCHAR str[MAX_DPATH]; + TCHAR key[100]; + if (!_tcscmp (values[i], paths[i])) + _tcscpy (str, values[i]); + else + _stprintf (str, L"%s \"%s\"", values[i], paths[i]); + _stprintf (key, L"PATH_ALL_%02d", i + 1); + regsetstr (fkey, key, str); + xfree (values[i]); + xfree (paths[i]); + } + while (i < MAXFAVORITES) { + TCHAR key[100]; + _stprintf (key, L"PATH_ALL_%02d", i + 1); + regdelete (fkey, key); + i++; + } + regclosetree (fkey); } static int askinputcustom (HWND hDlg, TCHAR *custom, int maxlen, DWORD titleid); static int addfavoritepath (HWND hDlg, int num, TCHAR **values, TCHAR **paths) { - TCHAR name[MAX_DPATH]; - const GUID favoriteguid = - { 0xed6e5ad9, 0xc0aa, 0x42fb, { 0x83, 0x3, 0x37, 0x41, 0x77, 0xb4, 0x6f, 0x18 } }; - - if (num >= MAXFAVORITES) - return 0; - if (!stored_path[0]) - GetModuleFileName (NULL, stored_path, MAX_DPATH); - while (stored_path[0]) { - DWORD v = GetFileAttributes (stored_path); - TCHAR *s; - if (v == INVALID_FILE_ATTRIBUTES) - break; - if (v & FILE_ATTRIBUTE_DIRECTORY) - break; - s = _tcsrchr (stored_path, '\\'); - if (!s) - s = _tcsrchr (stored_path, '/'); - if (!s) { - stored_path[0] = 0; - break; - } - s[0] = 0; - } - if (!DirectorySelection (hDlg, &favoriteguid, stored_path)) - return 0; - _tcscpy (name, stored_path); - if (askinputcustom (hDlg, name, sizeof name / sizeof (TCHAR), IDS_SB_FAVORITENAME)) { - values[num] = my_strdup (name); - paths[num] = my_strdup (stored_path); - num++; - writefavoritepaths (num, values, paths); - } - return 1; + TCHAR name[MAX_DPATH]; + const GUID favoriteguid = + { 0xed6e5ad9, 0xc0aa, 0x42fb, { 0x83, 0x3, 0x37, 0x41, 0x77, 0xb4, 0x6f, 0x18 } }; + + if (num >= MAXFAVORITES) + return 0; + if (!stored_path[0]) + GetModuleFileName (NULL, stored_path, MAX_DPATH); + while (stored_path[0]) { + DWORD v = GetFileAttributes (stored_path); + TCHAR *s; + if (v == INVALID_FILE_ATTRIBUTES) + break; + if (v & FILE_ATTRIBUTE_DIRECTORY) + break; + s = _tcsrchr (stored_path, '\\'); + if (!s) + s = _tcsrchr (stored_path, '/'); + if (!s) { + stored_path[0] = 0; + break; + } + s[0] = 0; + } + if (!DirectorySelection (hDlg, &favoriteguid, stored_path)) + return 0; + _tcscpy (name, stored_path); + if (askinputcustom (hDlg, name, sizeof name / sizeof (TCHAR), IDS_SB_FAVORITENAME)) { + values[num] = my_strdup (name); + paths[num] = my_strdup (stored_path); + num++; + writefavoritepaths (num, values, paths); + } + return 1; } static void removefavoritepath (int idx, int num, TCHAR **values, TCHAR **paths) { - int i; + int i; - 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); + 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, TCHAR **items) { - int i; - HMENU emenu = CreatePopupMenu (); - TCHAR 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); - - mii.fMask = MIIM_STRING | MIIM_ID; - mii.fType = MFT_STRING; - mii.fState = MFS_ENABLED; - mii.dwTypeData = L"Add New"; - mii.cch = _tcslen (mii.dwTypeData); - mii.wID = 1000; - InsertMenuItem (emenu, -1, TRUE, &mii); - i = 0; - while (items[i]) { + int i; + HMENU emenu = CreatePopupMenu (); + TCHAR 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); + mii.fMask = MIIM_STRING | MIIM_ID; mii.fType = MFT_STRING; mii.fState = MFS_ENABLED; - mii.wID = 1001 + i; - _stprintf (newpath, L"Remove '%s'", items[i]); - mii.dwTypeData = newpath; + mii.dwTypeData = L"Add New"; mii.cch = _tcslen (mii.dwTypeData); + mii.wID = 1000; InsertMenuItem (emenu, -1, TRUE, &mii); - i++; - } + i = 0; + while (items[i]) { + mii.fMask = MIIM_STRING | MIIM_ID; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + mii.wID = 1001 + i; + _stprintf (newpath, L"Remove '%s'", items[i]); + mii.dwTypeData = newpath; + mii.cch = _tcslen (mii.dwTypeData); + InsertMenuItem (emenu, -1, TRUE, &mii); + i++; + } - mii.fMask = MIIM_STRING | MIIM_SUBMENU; - mii.fType = MFT_STRING; - mii.fState = MFS_ENABLED; - mii.dwTypeData = L"Edit"; - mii.cch = _tcslen (mii.dwTypeData); - mii.hSubMenu = emenu; - InsertMenuItem (menu, -1, TRUE, &mii); + mii.fMask = MIIM_STRING | MIIM_SUBMENU; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + mii.dwTypeData = L"Edit"; + mii.cch = _tcslen (mii.dwTypeData); + mii.hSubMenu = emenu; + InsertMenuItem (menu, -1, TRUE, &mii); } static int popupmenu (HWND hwnd, TCHAR **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 = _tcslen (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); - PostMessage (hwnd, WM_NULL, 0, 0); - DestroyMenu (menu); - return item; + 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 = _tcslen (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); + PostMessage (hwnd, WM_NULL, 0, 0); + DestroyMenu (menu); + return item; } static TCHAR *favoritepopup (HWND hwnd) { - UAEREG *fkey; - int idx, idx2; - TCHAR *values[MAXFAVORITES + 1]; - TCHAR *paths[MAXFAVORITES + 1]; - int ret, i, j, num; + UAEREG *fkey; + int idx, idx2; + TCHAR *values[MAXFAVORITES + 1]; + TCHAR *paths[MAXFAVORITES + 1]; + int ret, i, j, num; - for (;;) { - fkey = regcreatetree (NULL, L"FavoritePaths"); - if (fkey == NULL) - return NULL; - idx = 0; - num = 0; for (;;) { - TCHAR *p; - DWORD size, size2; - TCHAR tmp[1000], tmp2[1000]; - size = sizeof (tmp) / sizeof (TCHAR); - size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - p = _tcsrchr (tmp, '_'); - if (p) { - idx2 = _tstol (p + 1); - if (idx2 > 0 && idx2 < MAXFAVORITES) { - TCHAR *p2 = _tcschr (tmp2, '"'); - TCHAR *str, *fname; - idx2--; - if (p2) { - fname = my_strdup (p2 + 1); - p2[0] = 0; - p2 = _tcschr (fname, '"'); - if (p2) - *p2 = 0; - str = my_strdup (tmp2); - } else { - str = my_strdup (tmp2); - fname = my_strdup (tmp2); - } - paths[idx2] = fname; - values[idx2] = str; - } - } - idx++; + fkey = regcreatetree (NULL, L"FavoritePaths"); + if (fkey == NULL) + return NULL; + idx = 0; + num = 0; + for (;;) { + TCHAR *p; + DWORD size, size2; + TCHAR tmp[1000], tmp2[1000]; + size = sizeof (tmp) / sizeof (TCHAR); + size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + p = _tcsrchr (tmp, '_'); + if (p) { + idx2 = _tstol (p + 1); + if (idx2 > 0 && idx2 < MAXFAVORITES) { + TCHAR *p2 = _tcschr (tmp2, '"'); + TCHAR *str, *fname; + idx2--; + if (p2) { + fname = my_strdup (p2 + 1); + p2[0] = 0; + p2 = _tcschr (fname, '"'); + if (p2) + *p2 = 0; + str = my_strdup (tmp2); + } else { + str = my_strdup (tmp2); + fname = 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 (_tcscmp (values[i], values[j]) > 0) { + TCHAR *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 (!addfavoritepath (hwnd, idx, values, paths)) { + ret = 0; + break; + } + } else if (ret > 1000) { + removefavoritepath (ret - 1001, idx, values, paths); + } } - regclosetree (fkey); for (i = 0; i < idx; i++) { - for (j = i + 1; j < idx; j++) { - if (_tcscmp (values[i], values[j]) > 0) { - TCHAR *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); + xfree (values[i]); + if (i != ret - 1) + xfree (paths[i]); + } if (ret == 0) - break; - if (ret <= idx) - break; - if (ret == 1000) { - if (!addfavoritepath (hwnd, idx, values, paths)) { - ret = 0; - break; - } - } else if (ret > 1000) { - removefavoritepath (ret - 1001, idx, values, paths); - } - } - for (i = 0; i < idx; i++) { - xfree (values[i]); - if (i != ret - 1) - xfree (paths[i]); - } - if (ret == 0) - return NULL; - return paths[ret - 1]; + return NULL; + return paths[ret - 1]; } /* base Drag'n'Drop code borrowed from http://www.codeproject.com/listctrl/jianghong.asp */ @@ -721,123 +721,123 @@ static int bDragging = 0; static HIMAGELIST hDragImageList; static int drag_start (HWND hWnd, HWND hListView, LPARAM lParam) { - POINT p, pt; - int bFirst, iPos, iHeight; - HIMAGELIST hOneImageList, hTempImageList; - IMAGEINFO imf; - - // You can set your customized cursor here - p.x = 8; - p.y = 8; - // Ok, now we create a drag-image for all selected items - bFirst = TRUE; - iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); - while (iPos != -1) { - if (bFirst) { - // For the first selected item, - // we simply create a single-line drag image - hDragImageList = ListView_CreateDragImage(hListView, iPos, &p); - ImageList_GetImageInfo(hDragImageList, 0, &imf); - iHeight = imf.rcImage.bottom; - bFirst = FALSE; - } else { - // For the rest selected items, - // we create a single-line drag image, then - // append it to the bottom of the complete drag image - hOneImageList = ListView_CreateDragImage(hListView, iPos, &p); - hTempImageList = ImageList_Merge(hDragImageList, 0, hOneImageList, 0, 0, iHeight); - ImageList_Destroy(hDragImageList); - ImageList_Destroy(hOneImageList); - hDragImageList = hTempImageList; - ImageList_GetImageInfo(hDragImageList, 0, &imf); - iHeight = imf.rcImage.bottom; + POINT p, pt; + int bFirst, iPos, iHeight; + HIMAGELIST hOneImageList, hTempImageList; + IMAGEINFO imf; + + // You can set your customized cursor here + p.x = 8; + p.y = 8; + // Ok, now we create a drag-image for all selected items + bFirst = TRUE; + iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); + while (iPos != -1) { + if (bFirst) { + // For the first selected item, + // we simply create a single-line drag image + hDragImageList = ListView_CreateDragImage(hListView, iPos, &p); + ImageList_GetImageInfo(hDragImageList, 0, &imf); + iHeight = imf.rcImage.bottom; + bFirst = FALSE; + } else { + // For the rest selected items, + // we create a single-line drag image, then + // append it to the bottom of the complete drag image + hOneImageList = ListView_CreateDragImage(hListView, iPos, &p); + hTempImageList = ImageList_Merge(hDragImageList, 0, hOneImageList, 0, 0, iHeight); + ImageList_Destroy(hDragImageList); + ImageList_Destroy(hOneImageList); + hDragImageList = hTempImageList; + ImageList_GetImageInfo(hDragImageList, 0, &imf); + iHeight = imf.rcImage.bottom; + } + iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); } - iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); - } - // Now we can initialize then start the drag action - ImageList_BeginDrag(hDragImageList, 0, 0, 0); + // Now we can initialize then start the drag action + ImageList_BeginDrag(hDragImageList, 0, 0, 0); - pt = ((NM_LISTVIEW*) ((LPNMHDR)lParam))->ptAction; - ClientToScreen(hListView, &pt); + pt = ((NM_LISTVIEW*) ((LPNMHDR)lParam))->ptAction; + ClientToScreen(hListView, &pt); - ImageList_DragEnter(NULL, pt.x, pt.y); + ImageList_DragEnter(NULL, pt.x, pt.y); - bDragging = TRUE; + bDragging = TRUE; - // Don't forget to capture the mouse - SetCapture (hWnd); + // Don't forget to capture the mouse + SetCapture (hWnd); - return 1; + return 1; } static int drag_end (HWND hWnd, HWND hListView, LPARAM lParam, int **draggeditems) { - int iPos, cnt; - LVHITTESTINFO lvhti; - LVITEM lvi; - - *draggeditems = NULL; - if (!bDragging) - return -1; - // End the drag-and-drop process - bDragging = FALSE; - ImageList_DragLeave(hListView); - ImageList_EndDrag(); - ImageList_Destroy(hDragImageList); - ReleaseCapture(); - - // Determine the dropped item - lvhti.pt.x = LOWORD(lParam); - lvhti.pt.y = HIWORD(lParam); - ClientToScreen(hWnd, &lvhti.pt); - ScreenToClient(hListView, &lvhti.pt); - ListView_HitTest(hListView, &lvhti); - - // Out of the ListView? - if (lvhti.iItem == -1) - return -1; - // Not in an item? - if ((lvhti.flags & LVHT_ONITEMLABEL) == 0 && (lvhti.flags & LVHT_ONITEMSTATEICON) == 0) - return -1; - // Dropped item is selected? - lvi.iItem = lvhti.iItem; - lvi.iSubItem = 0; - lvi.mask = LVIF_STATE; - lvi.stateMask = LVIS_SELECTED; - ListView_GetItem(hListView, &lvi); - if (lvi.state & LVIS_SELECTED) - return -1; - // Rearrange the items - iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); - cnt = 0; - while (iPos != -1) { - iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); - cnt++; - } - if (cnt == 0) - return -1; - *draggeditems = xmalloc (sizeof (int) * (cnt + 1)); - iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); - cnt = 0; - while (iPos != -1) { - (*draggeditems)[cnt++] = iPos; - iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); - } - (*draggeditems)[cnt] = -1; - return lvhti.iItem; + int iPos, cnt; + LVHITTESTINFO lvhti; + LVITEM lvi; + + *draggeditems = NULL; + if (!bDragging) + return -1; + // End the drag-and-drop process + bDragging = FALSE; + ImageList_DragLeave(hListView); + ImageList_EndDrag(); + ImageList_Destroy(hDragImageList); + ReleaseCapture(); + + // Determine the dropped item + lvhti.pt.x = LOWORD(lParam); + lvhti.pt.y = HIWORD(lParam); + ClientToScreen(hWnd, &lvhti.pt); + ScreenToClient(hListView, &lvhti.pt); + ListView_HitTest(hListView, &lvhti); + + // Out of the ListView? + if (lvhti.iItem == -1) + return -1; + // Not in an item? + if ((lvhti.flags & LVHT_ONITEMLABEL) == 0 && (lvhti.flags & LVHT_ONITEMSTATEICON) == 0) + return -1; + // Dropped item is selected? + lvi.iItem = lvhti.iItem; + lvi.iSubItem = 0; + lvi.mask = LVIF_STATE; + lvi.stateMask = LVIS_SELECTED; + ListView_GetItem(hListView, &lvi); + if (lvi.state & LVIS_SELECTED) + return -1; + // Rearrange the items + iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); + cnt = 0; + while (iPos != -1) { + iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); + cnt++; + } + if (cnt == 0) + return -1; + *draggeditems = xmalloc (sizeof (int) * (cnt + 1)); + iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED); + cnt = 0; + while (iPos != -1) { + (*draggeditems)[cnt++] = iPos; + iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED); + } + (*draggeditems)[cnt] = -1; + return lvhti.iItem; } static int drag_move (HWND hWnd, LPARAM lParam) { - POINT p; + POINT p; - if (!bDragging) - return 0; - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - ClientToScreen(hWnd, &p); - ImageList_DragMove(p.x, p.y); - return 1; + if (!bDragging) + return 0; + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + ClientToScreen(hWnd, &p); + ImageList_DragMove(p.x, p.y); + return 1; } static HWND cachedlist = NULL; @@ -865,407 +865,407 @@ static HWND cachedlist = NULL; #define MAX_SOUND_MEM 6 struct romscandata { - UAEREG *fkey; - int got; + UAEREG *fkey; + int got; }; static struct romdata *scan_single_rom_2 (struct zfile *f) { - uae_u8 buffer[20] = { 0 }; - uae_u8 *rombuf; - int cl = 0, size; - struct romdata *rd = 0; + uae_u8 buffer[20] = { 0 }; + uae_u8 *rombuf; + int cl = 0, size; + struct romdata *rd = 0; - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f); - zfile_fseek (f, 0, SEEK_SET); - if (size > 524288 * 2) {/* don't skip KICK disks or 1M ROMs */ - write_log (L"'%s': too big %d, ignored\n", zfile_getname(f), size); - return 0; - } - zfile_fread (buffer, 1, 11, f); - if (!memcmp (buffer, "KICK", 4)) { - zfile_fseek (f, 512, SEEK_SET); - if (size > 262144) - size = 262144; - } else if (!memcmp (buffer, "AMIROMTYPE1", 11)) { - cl = 1; - size -= 11; - } else { + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f); zfile_fseek (f, 0, SEEK_SET); - } - rombuf = xcalloc (size, 1); - if (!rombuf) - return 0; - zfile_fread (rombuf, 1, size, f); - if (cl > 0) { - decode_cloanto_rom_do (rombuf, size, size); - cl = 0; - } - if (!cl) { - rd = getromdatabydata (rombuf, size); - if (!rd && (size & 65535) == 0) { - /* check byteswap */ - int i; - for (i = 0; i < size; i+=2) { - uae_u8 b = rombuf[i]; - rombuf[i] = rombuf[i + 1]; - rombuf[i + 1] = b; - } - rd = getromdatabydata (rombuf, size); - } - } - if (!rd) { - write_log (L"!: Name='%s':%d\nCRC32=%08X SHA1=%s\n", - zfile_getname(f), size, get_crc32(rombuf, size), get_sha1_txt(rombuf, size)); - } else { - TCHAR tmp[MAX_DPATH]; - getromname (rd, tmp); - write_log (L"*: %s:%d = %s\nCRC32=%08X SHA1=%s\n", - zfile_getname(f), size, tmp, get_crc32(rombuf, size), get_sha1_txt(rombuf, size)); - } - xfree (rombuf); - return rd; + if (size > 524288 * 2) {/* don't skip KICK disks or 1M ROMs */ + write_log (L"'%s': too big %d, ignored\n", zfile_getname(f), size); + return 0; + } + zfile_fread (buffer, 1, 11, f); + if (!memcmp (buffer, "KICK", 4)) { + zfile_fseek (f, 512, SEEK_SET); + if (size > 262144) + size = 262144; + } else if (!memcmp (buffer, "AMIROMTYPE1", 11)) { + cl = 1; + size -= 11; + } else { + zfile_fseek (f, 0, SEEK_SET); + } + rombuf = xcalloc (size, 1); + if (!rombuf) + return 0; + zfile_fread (rombuf, 1, size, f); + if (cl > 0) { + decode_cloanto_rom_do (rombuf, size, size); + cl = 0; + } + if (!cl) { + rd = getromdatabydata (rombuf, size); + if (!rd && (size & 65535) == 0) { + /* check byteswap */ + int i; + for (i = 0; i < size; i+=2) { + uae_u8 b = rombuf[i]; + rombuf[i] = rombuf[i + 1]; + rombuf[i + 1] = b; + } + rd = getromdatabydata (rombuf, size); + } + } + if (!rd) { + write_log (L"!: Name='%s':%d\nCRC32=%08X SHA1=%s\n", + zfile_getname(f), size, get_crc32(rombuf, size), get_sha1_txt(rombuf, size)); + } else { + TCHAR tmp[MAX_DPATH]; + getromname (rd, tmp); + write_log (L"*: %s:%d = %s\nCRC32=%08X SHA1=%s\n", + zfile_getname(f), size, tmp, get_crc32(rombuf, size), get_sha1_txt(rombuf, size)); + } + xfree (rombuf); + return rd; } static struct romdata *scan_single_rom (TCHAR *path) { - struct zfile *z; - TCHAR tmp[MAX_DPATH]; - struct romdata *rd; + struct zfile *z; + TCHAR tmp[MAX_DPATH]; + struct romdata *rd; - _tcscpy (tmp, path); - rd = scan_arcadia_rom (tmp, 0); - if (rd) - return rd; - rd = getromdatabypath (path); - if (rd && rd->crc32 == 0xffffffff) - return rd; - z = zfile_fopen (path, L"rb", ZFD_NORMAL); - if (!z) - return 0; - return scan_single_rom_2 (z); + _tcscpy (tmp, path); + rd = scan_arcadia_rom (tmp, 0); + if (rd) + return rd; + rd = getromdatabypath (path); + if (rd && rd->crc32 == 0xffffffff) + return rd; + z = zfile_fopen (path, L"rb", ZFD_NORMAL); + if (!z) + return 0; + return scan_single_rom_2 (z); } static void abspathtorelative (TCHAR *name) { - if (!_tcsncmp (start_path_exe, name, _tcslen (start_path_exe))) - memmove (name, name + _tcslen (start_path_exe), (_tcslen (name) - _tcslen (start_path_exe) + 1) * sizeof (TCHAR)); + if (!_tcsncmp (start_path_exe, name, _tcslen (start_path_exe))) + memmove (name, name + _tcslen (start_path_exe), (_tcslen (name) - _tcslen (start_path_exe) + 1) * sizeof (TCHAR)); } static int addrom (UAEREG *fkey, struct romdata *rd, TCHAR *name) { - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; - - _stprintf (tmp1, L"ROM_%03d", rd->id); - if (rd->group) { - TCHAR *p = tmp1 + _tcslen (tmp1); - _stprintf (p, L"_%02d_%02d", rd->group >> 16, rd->group & 65535); - } - if (regexists (fkey, tmp1)) - return 0; - getromname (rd, tmp2); - if (name) { - _tcscat (tmp2, L" / \""); - if (getregmode ()) - abspathtorelative (name); - _tcscat (tmp2, name); - _tcscat (tmp2, L"\""); - } - if (rd->crc32 == 0xffffffff) { - if (rd->configname) - _stprintf (tmp2, L":%s", rd->configname); - else - _stprintf (tmp2, L":ROM_%03d", rd->id); - } - if (!regsetstr (fkey, tmp1, tmp2)) - return 0; - return 1; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; + + _stprintf (tmp1, L"ROM_%03d", rd->id); + if (rd->group) { + TCHAR *p = tmp1 + _tcslen (tmp1); + _stprintf (p, L"_%02d_%02d", rd->group >> 16, rd->group & 65535); + } + if (regexists (fkey, tmp1)) + return 0; + getromname (rd, tmp2); + if (name) { + _tcscat (tmp2, L" / \""); + if (getregmode ()) + abspathtorelative (name); + _tcscat (tmp2, name); + _tcscat (tmp2, L"\""); + } + if (rd->crc32 == 0xffffffff) { + if (rd->configname) + _stprintf (tmp2, L":%s", rd->configname); + else + _stprintf (tmp2, L":ROM_%03d", rd->id); + } + if (!regsetstr (fkey, tmp1, tmp2)) + return 0; + return 1; } static int isromext (TCHAR *path) { - TCHAR *ext; - int i; + TCHAR *ext; + int i; - if (!path) - return 0; - ext = _tcsrchr (path, '.'); - if (!ext) - return 0; - ext++; + if (!path) + return 0; + ext = _tcsrchr (path, '.'); + if (!ext) + return 0; + ext++; - if (!_tcsicmp (ext, L"rom") || !_tcsicmp (ext, L"adf") || !_tcsicmp (ext, L"key") - || !_tcsicmp (ext, L"a500") || !_tcsicmp (ext, L"a1200") || !_tcsicmp (ext, L"a4000")) - return 1; - if (_tcslen (ext) >= 2 && toupper(ext[0]) == 'U' && isdigit (ext[1])) - return 1; - for (i = 0; uae_archive_extensions[i]; i++) { - if (!_tcsicmp (ext, uae_archive_extensions[i])) - return 1; - } - return 0; + if (!_tcsicmp (ext, L"rom") || !_tcsicmp (ext, L"adf") || !_tcsicmp (ext, L"key") + || !_tcsicmp (ext, L"a500") || !_tcsicmp (ext, L"a1200") || !_tcsicmp (ext, L"a4000")) + return 1; + if (_tcslen (ext) >= 2 && toupper(ext[0]) == 'U' && isdigit (ext[1])) + return 1; + for (i = 0; uae_archive_extensions[i]; i++) { + if (!_tcsicmp (ext, uae_archive_extensions[i])) + return 1; + } + return 0; } static int scan_rom_2 (struct zfile *f, struct romscandata *rsd) { - TCHAR *path = zfile_getname(f); - struct romdata *rd; + TCHAR *path = zfile_getname(f); + struct romdata *rd; - if (!isromext(path)) + if (!isromext(path)) + return 0; + rd = scan_single_rom_2 (f); + if (rd) { + addrom (rsd->fkey, rd, path); + rsd->got = 1; + } return 0; - rd = scan_single_rom_2 (f); - if (rd) { - addrom (rsd->fkey, rd, path); - rsd->got = 1; - } - return 0; } static int scan_rom (TCHAR *path, UAEREG *fkey) { - struct romscandata rsd = { fkey, 0 }; - struct romdata *rd; - int cnt = 0; + struct romscandata rsd = { fkey, 0 }; + struct romdata *rd; + int cnt = 0; - if (!isromext (path)) { - //write_log("ROMSCAN: skipping file '%s', unknown extension\n", path); - return 0; - } - for (;;) { - TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, path); - rd = scan_arcadia_rom (tmp, cnt++); - if (rd) { - if (!addrom (fkey, rd, tmp)) - return 1; - continue; + if (!isromext (path)) { + //write_log("ROMSCAN: skipping file '%s', unknown extension\n", path); + return 0; + } + for (;;) { + TCHAR tmp[MAX_DPATH]; + _tcscpy (tmp, path); + rd = scan_arcadia_rom (tmp, cnt++); + if (rd) { + if (!addrom (fkey, rd, tmp)) + return 1; + continue; + } + break; } - break; - } - zfile_zopen (path, scan_rom_2, &rsd); - return rsd.got; + zfile_zopen (path, scan_rom_2, &rsd); + return rsd.got; } static int listrom (int *roms) { - int i; + int i; - i = 0; - while (roms[i] >= 0) { - struct romdata *rd = getromdatabyid (roms[i]); - if (rd && romlist_get (rd)) - return 1; - i++; - } - return 0; + i = 0; + while (roms[i] >= 0) { + struct romdata *rd = getromdatabyid (roms[i]); + if (rd && romlist_get (rd)) + return 1; + i++; + } + return 0; } static void show_rom_list (void) { - TCHAR *p; - TCHAR unavail[MAX_DPATH], avail[MAX_DPATH]; - TCHAR *p1, *p2; - int *rp; - int romtable[] = { - 5, 4, -1, -1, // A500 1.2 - 6, 32, -1, -1, // A500 1.3 - 7, -1, -1, // A500+ - 8, 9, 10, -1, -1, // A600 - 23, 24, -1, -1, // A1000 - 11, 31, 15, -1, -1, // A1200 - 59, 71, 61, -1, -1, // A3000 - 16, 46, 31, 13, 12, -1, -1, // A4000 - 18, -1, 19, -1, -1, // CD32 - 20, 21, 22, -1, 6, 32, -1, -1, // CDTV - 49, 50, 51, -1, 5, 4, -1, -1, // ARCADIA - 46, 16, 17, 31, 13, 12, -1, -1, // highend, any 3.x A4000 - 53, 54, 55, -1, -1, // A590/A2091 - //56, 57, -1, -1, // A4091 - 0, 0, 0 - }; - - WIN32GUI_LoadUIString (IDS_ROM_AVAILABLE, avail, sizeof (avail) / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_ROM_UNAVAILABLE, unavail, sizeof (avail) / sizeof (TCHAR)); - _tcscat (avail, L"\n"); - _tcscat (unavail, L"\n"); - p1 = L"A500 Boot ROM 1.2\0A500 Boot ROM 1.3\0A500+\0A600\0A1000\0A1200\0A3000\0A4000\0\nCD32\0CDTV\0Arcadia Multi Select\0High end WinUAE\0\nA590/A2091 SCSI Boot ROM\0\0"; - - p = malloc (100000); - if (!p) - return; - WIN32GUI_LoadUIString (IDS_ROMSCANEND, p, 100); - _tcscat (p, L"\n\n"); - - rp = romtable; - while(rp[0]) { - int ok = 0; - p2 = p1 + _tcslen (p1) + 1; - _tcscat (p, L" "); - _tcscat (p, p1); _tcscat (p, L": "); - if (listrom (rp)) - ok = 1; - while(*rp++ != -1); - if (*rp != -1) { - if (ok) { - ok = 0; + TCHAR *p; + TCHAR unavail[MAX_DPATH], avail[MAX_DPATH]; + TCHAR *p1, *p2; + int *rp; + int romtable[] = { + 5, 4, -1, -1, // A500 1.2 + 6, 32, -1, -1, // A500 1.3 + 7, -1, -1, // A500+ + 8, 9, 10, -1, -1, // A600 + 23, 24, -1, -1, // A1000 + 11, 31, 15, -1, -1, // A1200 + 59, 71, 61, -1, -1, // A3000 + 16, 46, 31, 13, 12, -1, -1, // A4000 + 18, -1, 19, -1, -1, // CD32 + 20, 21, 22, -1, 6, 32, -1, -1, // CDTV + 49, 50, 51, -1, 5, 4, -1, -1, // ARCADIA + 46, 16, 17, 31, 13, 12, -1, -1, // highend, any 3.x A4000 + 53, 54, 55, -1, -1, // A590/A2091 + //56, 57, -1, -1, // A4091 + 0, 0, 0 + }; + + WIN32GUI_LoadUIString (IDS_ROM_AVAILABLE, avail, sizeof (avail) / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_ROM_UNAVAILABLE, unavail, sizeof (avail) / sizeof (TCHAR)); + _tcscat (avail, L"\n"); + _tcscat (unavail, L"\n"); + p1 = L"A500 Boot ROM 1.2\0A500 Boot ROM 1.3\0A500+\0A600\0A1000\0A1200\0A3000\0A4000\0\nCD32\0CDTV\0Arcadia Multi Select\0High end WinUAE\0\nA590/A2091 SCSI Boot ROM\0\0"; + + p = malloc (100000); + if (!p) + return; + WIN32GUI_LoadUIString (IDS_ROMSCANEND, p, 100); + _tcscat (p, L"\n\n"); + + rp = romtable; + while(rp[0]) { + int ok = 0; + p2 = p1 + _tcslen (p1) + 1; + _tcscat (p, L" "); + _tcscat (p, p1); _tcscat (p, L": "); if (listrom (rp)) - ok = 1; - } - while(*rp++ != -1); + ok = 1; + while(*rp++ != -1); + if (*rp != -1) { + if (ok) { + ok = 0; + if (listrom (rp)) + ok = 1; + } + while(*rp++ != -1); + } + rp++; + if (ok) + _tcscat (p, avail); else _tcscat (p, unavail); + p1 = p2; } - rp++; - if (ok) - _tcscat (p, avail); else _tcscat (p, unavail); - p1 = p2; - } - pre_gui_message (p); - free (p); + pre_gui_message (p); + free (p); } static int scan_roms_2 (UAEREG *fkey, TCHAR *path) { - TCHAR buf[MAX_DPATH]; - WIN32_FIND_DATA find_data; - HANDLE handle; - int ret; + TCHAR buf[MAX_DPATH]; + WIN32_FIND_DATA find_data; + HANDLE handle; + int ret; - if (!path) - return 0; - write_log (L"ROM scan directory '%s'\n", path); - _tcscpy (buf, path); - _tcscat (buf, L"*.*"); - ret = 0; - handle = FindFirstFile (buf, &find_data); - if (handle == INVALID_HANDLE_VALUE) - return 0; - for (;;) { - TCHAR tmppath[MAX_DPATH]; - _tcscpy (tmppath, path); - _tcscat (tmppath, find_data.cFileName); - if (!(find_data.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY |FILE_ATTRIBUTE_SYSTEM)) && find_data.nFileSizeLow < 10000000) { - if (scan_rom (tmppath, fkey)) - ret = 1; - } - if (FindNextFile (handle, &find_data) == 0) { - FindClose (handle); - break; + if (!path) + return 0; + write_log (L"ROM scan directory '%s'\n", path); + _tcscpy (buf, path); + _tcscat (buf, L"*.*"); + ret = 0; + handle = FindFirstFile (buf, &find_data); + if (handle == INVALID_HANDLE_VALUE) + return 0; + for (;;) { + TCHAR tmppath[MAX_DPATH]; + _tcscpy (tmppath, path); + _tcscat (tmppath, find_data.cFileName); + if (!(find_data.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY |FILE_ATTRIBUTE_SYSTEM)) && find_data.nFileSizeLow < 10000000) { + if (scan_rom (tmppath, fkey)) + ret = 1; + } + if (FindNextFile (handle, &find_data) == 0) { + FindClose (handle); + break; + } } - } - return ret; + return ret; } #define MAX_ROM_PATHS 10 static int scan_roms_3(void *fkey, TCHAR **paths, TCHAR *path) { - int i, ret; - TCHAR pathp[MAX_DPATH]; + int i, ret; + TCHAR pathp[MAX_DPATH]; - ret = 0; - GetFullPathName (path, MAX_DPATH, pathp, NULL); - for (i = 0; i < MAX_ROM_PATHS; i++) { - if (paths[i] && !_tcsicmp (paths[i], pathp)) - return ret; - } - ret = scan_roms_2 (fkey, pathp); - for (i = 0; i < MAX_ROM_PATHS; i++) { - if (!paths[i]) { - paths[i] = my_strdup(pathp); - break; + ret = 0; + GetFullPathName (path, MAX_DPATH, pathp, NULL); + for (i = 0; i < MAX_ROM_PATHS; i++) { + if (paths[i] && !_tcsicmp (paths[i], pathp)) + return ret; + } + ret = scan_roms_2 (fkey, pathp); + for (i = 0; i < MAX_ROM_PATHS; i++) { + if (!paths[i]) { + paths[i] = my_strdup(pathp); + break; + } } - } - return ret; + return ret; } extern int get_rom_path(TCHAR *out, int mode); int scan_roms (int show) { - TCHAR path[MAX_DPATH]; - static int recursive; - int id, i, ret, keys, cnt; - UAEREG *fkey, *fkey2; - TCHAR *paths[MAX_ROM_PATHS]; + TCHAR path[MAX_DPATH]; + static int recursive; + int id, i, ret, keys, cnt; + UAEREG *fkey, *fkey2; + TCHAR *paths[MAX_ROM_PATHS]; - if (recursive) - return 0; - recursive++; - - regdeletetree (NULL, L"DetectedROMs"); - fkey = regcreatetree (NULL, L"DetectedROMs"); - if (fkey == NULL) - goto end; - - cnt = 0; - ret = 0; - for (i = 0; i < MAX_ROM_PATHS; i++) - paths[i] = NULL; - for (;;) { - keys = get_keyring (); - fetch_path (L"KickstartPath", path, sizeof path / sizeof (TCHAR)); - cnt += scan_roms_3 (fkey, paths, path); - if (1) { - for(i = 0; i < MAX_ROM_PATHS; i++) { - ret = get_rom_path (path, i); - if (ret < 0) - break; - cnt += scan_roms_3 (fkey, paths, path); - } - if (get_keyring() > keys) { /* more keys detected in previous scan? */ - write_log (L"ROM scan: more keys found, restarting..\n"); - for (i = 0; i < MAX_ROM_PATHS; i++) { - xfree (paths[i]); - paths[i] = NULL; - } - continue; - } - } - break; - } - if (cnt == 0) - scan_roms_3 (fkey, paths, workprefs.path_rom); - - for (i = 0; i < MAX_ROM_PATHS; i++) - xfree (paths[i]); - - fkey2 = regcreatetree (NULL, L"DetectedROMS"); - if (fkey2) { - id = 1; + if (recursive) + return 0; + recursive++; + + regdeletetree (NULL, L"DetectedROMs"); + fkey = regcreatetree (NULL, L"DetectedROMs"); + if (fkey == NULL) + goto end; + + cnt = 0; + ret = 0; + for (i = 0; i < MAX_ROM_PATHS; i++) + paths[i] = NULL; for (;;) { - struct romdata *rd = getromdatabyid (id); - if (!rd) + keys = get_keyring (); + fetch_path (L"KickstartPath", path, sizeof path / sizeof (TCHAR)); + cnt += scan_roms_3 (fkey, paths, path); + if (1) { + for(i = 0; i < MAX_ROM_PATHS; i++) { + ret = get_rom_path (path, i); + if (ret < 0) + break; + cnt += scan_roms_3 (fkey, paths, path); + } + if (get_keyring() > keys) { /* more keys detected in previous scan? */ + write_log (L"ROM scan: more keys found, restarting..\n"); + for (i = 0; i < MAX_ROM_PATHS; i++) { + xfree (paths[i]); + paths[i] = NULL; + } + continue; + } + } break; - if (rd->crc32 == 0xffffffff) - addrom(fkey, rd, NULL); - id++; } - regclosetree (fkey2); - } + if (cnt == 0) + scan_roms_3 (fkey, paths, workprefs.path_rom); + + for (i = 0; i < MAX_ROM_PATHS; i++) + xfree (paths[i]); + + fkey2 = regcreatetree (NULL, L"DetectedROMS"); + if (fkey2) { + id = 1; + for (;;) { + struct romdata *rd = getromdatabyid (id); + if (!rd) + break; + if (rd->crc32 == 0xffffffff) + addrom(fkey, rd, NULL); + id++; + } + regclosetree (fkey2); + } end: - read_rom_list (); - if (show) - show_rom_list (); + read_rom_list (); + if (show) + show_rom_list (); - regclosetree (fkey); - recursive--; - return ret; + regclosetree (fkey); + recursive--; + return ret; } struct ConfigStruct { - TCHAR Name[MAX_DPATH]; - TCHAR Path[MAX_DPATH]; - TCHAR Fullpath[MAX_DPATH]; - TCHAR HostLink[MAX_DPATH]; - TCHAR HardwareLink[MAX_DPATH]; - TCHAR Description[CFG_DESCRIPTION_LENGTH]; - int Type, Directory; - struct ConfigStruct *Parent, *Child; - int host, hardware; - HTREEITEM item; - FILETIME t; + TCHAR Name[MAX_DPATH]; + TCHAR Path[MAX_DPATH]; + TCHAR Fullpath[MAX_DPATH]; + TCHAR HostLink[MAX_DPATH]; + TCHAR HardwareLink[MAX_DPATH]; + TCHAR Description[CFG_DESCRIPTION_LENGTH]; + int Type, Directory; + struct ConfigStruct *Parent, *Child; + int host, hardware; + HTREEITEM item; + FILETIME t; }; static TCHAR *configreg[] = { L"ConfigFile", L"ConfigFileHardware", L"ConfigFileHost" }; @@ -1275,73 +1275,73 @@ static int configstoresize, configstoreallocated, configtype, configtypepanel; static struct ConfigStruct *getconfigstorefrompath (TCHAR *path, TCHAR *out, int type) { - int i; - for (i = 0; i < configstoresize; i++) { - if (((configstore[i]->Type == 0 || configstore[i]->Type == 3) && type == 0) || (configstore[i]->Type == type)) { - TCHAR path2[MAX_DPATH]; - _tcscpy (path2, configstore[i]->Path); - _tcsncat (path2, configstore[i]->Name, MAX_DPATH); - if (!_tcscmp (path, path2)) { - _tcscpy (out, configstore[i]->Fullpath); - _tcsncat (out, configstore[i]->Name, MAX_DPATH); - return configstore[i]; - } + int i; + for (i = 0; i < configstoresize; i++) { + if (((configstore[i]->Type == 0 || configstore[i]->Type == 3) && type == 0) || (configstore[i]->Type == type)) { + TCHAR path2[MAX_DPATH]; + _tcscpy (path2, configstore[i]->Path); + _tcsncat (path2, configstore[i]->Name, MAX_DPATH); + if (!_tcscmp (path, path2)) { + _tcscpy (out, configstore[i]->Fullpath); + _tcsncat (out, configstore[i]->Name, MAX_DPATH); + return configstore[i]; + } + } } - } - return 0; + return 0; } int target_cfgfile_load (struct uae_prefs *p, TCHAR *filename, int type, int isdefault) { - int v, i, type2; - DWORD ct, ct2, size; - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; - TCHAR fname[MAX_DPATH]; + int v, i, type2; + DWORD ct, ct2, size; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; + TCHAR fname[MAX_DPATH]; - _tcscpy (fname, filename); - if (!zfile_exists (fname)) { - fetch_configurationpath (fname, sizeof (fname) / sizeof (TCHAR)); - if (_tcsncmp (fname, filename, _tcslen (fname))) - _tcscat (fname, filename); - else - _tcscpy (fname, filename); - } - - if (!isdefault) - qs_override = 1; - if (type < 0) { - type = 0; - cfgfile_get_description (fname, NULL, NULL, NULL, &type); - } - if (type == 0 || type == 1) { - discard_prefs (p, 0); - } - type2 = type; - if (type == 0) - default_prefs (p, type); - regqueryint (NULL, L"ConfigFile_NoAuto", &ct2); - v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1); - if (!v) - return v; - if (type > 0) + _tcscpy (fname, filename); + if (!zfile_exists (fname)) { + fetch_configurationpath (fname, sizeof (fname) / sizeof (TCHAR)); + if (_tcsncmp (fname, filename, _tcslen (fname))) + _tcscat (fname, filename); + else + _tcscpy (fname, filename); + } + + if (!isdefault) + qs_override = 1; + if (type < 0) { + type = 0; + cfgfile_get_description (fname, NULL, NULL, NULL, &type); + } + if (type == 0 || type == 1) { + discard_prefs (p, 0); + } + type2 = type; + if (type == 0) + default_prefs (p, type); + regqueryint (NULL, L"ConfigFile_NoAuto", &ct2); + v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1); + if (!v) + return v; + if (type > 0) + return v; + for (i = 1; i <= 2; i++) { + if (type != i) { + size = sizeof (ct); + ct = 0; + regqueryint (NULL, configreg2[i], &ct); + if (ct && ((i == 1 && p->config_hardware_path[0] == 0) || (i == 2 && p->config_host_path[0] == 0) || ct2)) { + size = sizeof (tmp1) / sizeof (TCHAR); + regquerystr (NULL, configreg[i], tmp1, &size); + fetch_path (L"ConfigurationPath", tmp2, sizeof (tmp2) / sizeof (TCHAR)); + _tcscat (tmp2, tmp1); + v = i; + cfgfile_load (p, tmp2, &v, 1, 0); + } + } + } + v = 1; return v; - for (i = 1; i <= 2; i++) { - if (type != i) { - size = sizeof (ct); - ct = 0; - regqueryint (NULL, configreg2[i], &ct); - if (ct && ((i == 1 && p->config_hardware_path[0] == 0) || (i == 2 && p->config_host_path[0] == 0) || ct2)) { - size = sizeof (tmp1) / sizeof (TCHAR); - regquerystr (NULL, configreg[i], tmp1, &size); - fetch_path (L"ConfigurationPath", tmp2, sizeof (tmp2) / sizeof (TCHAR)); - _tcscat (tmp2, tmp1); - v = i; - cfgfile_load (p, tmp2, &v, 1, 0); - } - } - } - v = 1; - return v; } static int gui_width = 640, gui_height = 480; @@ -1349,131 +1349,131 @@ static int gui_width = 640, gui_height = 480; static int mm = 0; static void m(void) { - write_log (L"%d:0: %dx%d %dx%d %dx%d\n", mm, currprefs.gfx_size.width, currprefs.gfx_size.height, - workprefs.gfx_size.width, workprefs.gfx_size.height, changed_prefs.gfx_size.width, changed_prefs.gfx_size.height); - write_log (L"%d:1: %dx%d %dx%d %dx%d\n", mm, currprefs.gfx_size_fs.width, currprefs.gfx_size_fs.height, - workprefs.gfx_size_fs.width, workprefs.gfx_size_fs.height, changed_prefs.gfx_size_fs.width, changed_prefs.gfx_size_fs.height); - mm++; + write_log (L"%d:0: %dx%d %dx%d %dx%d\n", mm, currprefs.gfx_size.width, currprefs.gfx_size.height, + workprefs.gfx_size.width, workprefs.gfx_size.height, changed_prefs.gfx_size.width, changed_prefs.gfx_size.height); + write_log (L"%d:1: %dx%d %dx%d %dx%d\n", mm, currprefs.gfx_size_fs.width, currprefs.gfx_size_fs.height, + workprefs.gfx_size_fs.width, workprefs.gfx_size_fs.height, changed_prefs.gfx_size_fs.width, changed_prefs.gfx_size_fs.height); + mm++; } static int GetSettings (int all_options, HWND hwnd); /* if drive is -1, show the full GUI, otherwise file-requester for DF[drive] */ void gui_display (int shortcut) { - static int here; - HRESULT hr; - int w, h; + static int here; + HRESULT hr; + int w, h; - if (here) - return; - here++; - gui_active++; - setpaused (); - screenshot_prepare (); + if (here) + return; + here++; + gui_active++; + setpaused (9); + screenshot_prepare (); #ifdef D3D - D3D_guimode (TRUE); + D3D_guimode (TRUE); #endif - inputdevice_unacquire (); - clearallkeys (); - setmouseactive (0); - - w = h = -1; - if (!WIN32GFX_IsPicassoScreen () && currprefs.gfx_afullscreen && (currprefs.gfx_size.width < gui_width || currprefs.gfx_size.height < gui_height)) { - w = currprefs.gfx_size.width; - h = currprefs.gfx_size.height; - } - if (WIN32GFX_IsPicassoScreen () && currprefs.gfx_pfullscreen && (picasso96_state.Width < gui_width || picasso96_state.Height < gui_height)) { - w = currprefs.gfx_size.width; - h = currprefs.gfx_size.height; - } - scaleresource_setmaxsize (-1, -1); - if (w > 0 && h > 0) - scaleresource_setmaxsize (w, h); - WIN32GFX_ClearPalette (); - manual_painting_needed++; /* So that WM_PAINT will refresh the display */ - - if (isfullscreen () > 0) { - hr = DirectDraw_FlipToGDISurface (); - if (FAILED (hr)) - write_log (L"FlipToGDISurface failed, %s\n", DXError (hr)); - } + inputdevice_unacquire (); + clearallkeys (); + setmouseactive (0); - flush_log (); + w = h = -1; + if (!WIN32GFX_IsPicassoScreen () && currprefs.gfx_afullscreen && (currprefs.gfx_size.width < gui_width || currprefs.gfx_size.height < gui_height)) { + w = currprefs.gfx_size.width; + h = currprefs.gfx_size.height; + } + if (WIN32GFX_IsPicassoScreen () && currprefs.gfx_pfullscreen && (picasso96_state.Width < gui_width || picasso96_state.Height < gui_height)) { + w = currprefs.gfx_size.width; + h = currprefs.gfx_size.height; + } + scaleresource_setmaxsize (-1, -1); + if (w > 0 && h > 0) + scaleresource_setmaxsize (w, h); + WIN32GFX_ClearPalette (); + manual_painting_needed++; /* So that WM_PAINT will refresh the display */ - if (shortcut == -1) { - int ret; - ret = GetSettings (0, hAmigaWnd); - if (!ret) { - savestate_state = 0; - } - } else if (shortcut >= 0 && shortcut < 4) { - DiskSelection (hAmigaWnd, IDC_DF0 + shortcut, 0, &changed_prefs, 0); - } else if (shortcut == 5) { - if (DiskSelection (hAmigaWnd, IDC_DOSAVESTATE, 9, &changed_prefs, 0)) - save_state (savestate_fname, L"Description!"); - } else if (shortcut == 4) { - if (DiskSelection (hAmigaWnd, IDC_DOLOADSTATE, 10, &changed_prefs, 0)) - savestate_state = STATE_DORESTORE; - } - manual_painting_needed--; /* So that WM_PAINT doesn't need to use custom refreshing */ - manual_palette_refresh_needed = 1; - resumepaused (); - inputdevice_copyconfig (&changed_prefs, &currprefs); - inputdevice_config_change_test (); - clearallkeys (); - inputdevice_acquire (TRUE); - setmouseactive (1); + if (isfullscreen () > 0) { + hr = DirectDraw_FlipToGDISurface (); + if (FAILED (hr)) + write_log (L"FlipToGDISurface failed, %s\n", DXError (hr)); + } + + flush_log (); + + if (shortcut == -1) { + int ret; + ret = GetSettings (0, hAmigaWnd); + if (!ret) { + savestate_state = 0; + } + } else if (shortcut >= 0 && shortcut < 4) { + DiskSelection (hAmigaWnd, IDC_DF0 + shortcut, 0, &changed_prefs, 0); + } else if (shortcut == 5) { + if (DiskSelection (hAmigaWnd, IDC_DOSAVESTATE, 9, &changed_prefs, 0)) + save_state (savestate_fname, L"Description!"); + } else if (shortcut == 4) { + if (DiskSelection (hAmigaWnd, IDC_DOLOADSTATE, 10, &changed_prefs, 0)) + savestate_state = STATE_DORESTORE; + } + manual_painting_needed--; /* So that WM_PAINT doesn't need to use custom refreshing */ + manual_palette_refresh_needed = 1; + resumepaused (9); + inputdevice_copyconfig (&changed_prefs, &currprefs); + inputdevice_config_change_test (); + clearallkeys (); + inputdevice_acquire (TRUE); + setmouseactive (1); #ifdef D3D - D3D_guimode (FALSE); + D3D_guimode (FALSE); #endif #ifdef AVIOUTPUT - AVIOutput_Begin (); + AVIOutput_Begin (); #endif - fpscounter_reset (); - WIN32GFX_SetPalette (); + fpscounter_reset (); + WIN32GFX_SetPalette (); #ifdef PICASSO96 - DX_SetPalette (0, 256); + DX_SetPalette (0, 256); #endif - screenshot_free (); - write_disk_history (); - gui_active--; - here--; + screenshot_free (); + write_disk_history (); + gui_active--; + here--; } static void prefs_to_gui (struct uae_prefs *p) { - workprefs = *p; - /* filesys hack */ - workprefs.mountitems = currprefs.mountitems; - memcpy (&workprefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info)); + workprefs = *p; + /* filesys hack */ + workprefs.mountitems = currprefs.mountitems; + memcpy (&workprefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info)); - updatewinfsmode (&workprefs); + updatewinfsmode (&workprefs); #if 0 #ifdef _DEBUG - if (workprefs.gfx_framerate < 5) - workprefs.gfx_framerate = 5; + if (workprefs.gfx_framerate < 5) + workprefs.gfx_framerate = 5; #endif #endif } static void gui_to_prefs (void) { - /* Always copy our prefs to changed_prefs, ... */ - changed_prefs = workprefs; - /* filesys hack */ - currprefs.mountitems = changed_prefs.mountitems; - memcpy (&currprefs.mountconfig, &changed_prefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info)); - fixup_prefs (&changed_prefs); - updatewinfsmode (&changed_prefs); + /* Always copy our prefs to changed_prefs, ... */ + changed_prefs = workprefs; + /* filesys hack */ + currprefs.mountitems = changed_prefs.mountitems; + memcpy (&currprefs.mountconfig, &changed_prefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info)); + fixup_prefs (&changed_prefs); + updatewinfsmode (&changed_prefs); } static const GUID diskselectionguids[] = { - { 0x4fa8fa15, 0xc209, 0x4112, { 0x94, 0x7b, 0xc6, 0x00, 0x8e, 0x1f, 0xa3, 0x29 } }, - { 0x32073f09, 0x752d, 0x4783, { 0x84, 0x6c, 0xaa, 0x66, 0x48, 0x84, 0x14, 0x45 } }, - { 0x8047f7ea, 0x8a42, 0x4695, { 0x94, 0x52, 0xf5, 0x0d, 0xb8, 0x43, 0x00, 0x58 } }, - { 0x2412c4e7, 0xf608, 0x4333, { 0x83, 0xd2, 0xa1, 0x2f, 0xdf, 0x66, 0xac, 0xe5 } }, - { 0xe3741dff, 0x11f2, 0x445f, { 0x94, 0xb0, 0xa3, 0xe7, 0x58, 0xe2, 0xcb, 0xb5 } }, - { 0x2056d641, 0xba13, 0x4312, { 0xaa, 0x75, 0xc5, 0xeb, 0x52, 0xa8, 0x1c, 0xe3 } } + { 0x4fa8fa15, 0xc209, 0x4112, { 0x94, 0x7b, 0xc6, 0x00, 0x8e, 0x1f, 0xa3, 0x29 } }, + { 0x32073f09, 0x752d, 0x4783, { 0x84, 0x6c, 0xaa, 0x66, 0x48, 0x84, 0x14, 0x45 } }, + { 0x8047f7ea, 0x8a42, 0x4695, { 0x94, 0x52, 0xf5, 0x0d, 0xb8, 0x43, 0x00, 0x58 } }, + { 0x2412c4e7, 0xf608, 0x4333, { 0x83, 0xd2, 0xa1, 0x2f, 0xdf, 0x66, 0xac, 0xe5 } }, + { 0xe3741dff, 0x11f2, 0x445f, { 0x94, 0xb0, 0xa3, 0xe7, 0x58, 0xe2, 0xcb, 0xb5 } }, + { 0x2056d641, 0xba13, 0x4312, { 0xaa, 0x75, 0xc5, 0xeb, 0x52, 0xa8, 0x1c, 0xe3 } } }; // Common routine for popping up a file-requester @@ -1491,534 +1491,534 @@ static const GUID diskselectionguids[] = { // flag = 16 for recording input int DiskSelection_2 (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *path_out, int *multi) { - static int statefile_previousfilter; - static int previousfilter[20]; - OPENFILENAME openFileName; - TCHAR full_path[MAX_DPATH] = L""; - TCHAR full_path2[MAX_DPATH]; - TCHAR file_name[MAX_DPATH] = L""; - TCHAR init_path[MAX_DPATH] = L""; - BOOL result = FALSE; - TCHAR *amiga_path = NULL, *initialdir = NULL, *defext = NULL; - TCHAR description[CFG_DESCRIPTION_LENGTH] = L""; - TCHAR *p, *nextp; - int all = 1; - int next; - int nosavepath = 0; - const GUID *guid = NULL; - - TCHAR szTitle[MAX_DPATH] = { 0 }; - TCHAR szFormat[MAX_DPATH]; - TCHAR szFilter[MAX_DPATH] = { 0 }; - - memset (&openFileName, 0, sizeof (OPENFILENAME)); - - if (path_out && path_out[0]) { - _tcscpy (init_path, path_out); - nosavepath = 1; - } else { - _tcsncpy (init_path, start_path_data, MAX_DPATH); - switch (flag) - { - case 0: - case 1: - fetch_path (L"FloppyPath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[0]; - break; - case 2: - case 3: - fetch_path (L"hdfPath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[1]; - break; - case 6: - case 7: - case 11: - fetch_path (L"KickstartPath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[2]; - break; - case 4: - case 5: - case 8: - fetch_path (L"ConfigurationPath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[3]; - break; - case 9: - case 10: - { - int ok = 0; - if (savestate_fname[0]) { - _tcscpy (init_path, savestate_fname); - for (;;) { - TCHAR *p; - if (my_existsdir (init_path)) { - ok = 1; - break; - } - p = _tcsrchr (init_path, '\\'); - if (!p) - p = _tcsrchr (init_path, '/'); - if (!p) - break; - *p = 0; - } - } - if (!ok) - fetch_path (L"StatefilePath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[4]; - } - break; - case 15: - case 16: - fetch_path (L"InputPath", init_path, sizeof (init_path) / sizeof (TCHAR)); - guid = &diskselectionguids[5]; - break; - } - } - - szFilter[0] = 0; - szFilter[1] = 0; - switch (flag) { - case 0: - WIN32GUI_LoadUIString (IDS_SELECTADF, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), DISK_FORMAT_STRING, sizeof (DISK_FORMAT_STRING) + sizeof (TCHAR)); - defext = L"ADF"; - break; - case 1: - WIN32GUI_LoadUIString (IDS_CHOOSEBLANK, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), L"(*.adf)\0*.adf\0", 15 * sizeof (TCHAR)); - defext = L"ADF"; - break; - case 2: - case 3: - WIN32GUI_LoadUIString (IDS_SELECTHDF, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_HDF, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), HDF_FORMAT_STRING, sizeof (HDF_FORMAT_STRING) + sizeof (TCHAR)); - defext = L"HDF"; - break; - case 4: - case 5: - WIN32GUI_LoadUIString (IDS_SELECTUAE, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_UAE, szFormat, MAX_DPATH ); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), L"(*.uae)\0*.uae\0", 15 * sizeof (TCHAR)); - defext = L"UAE"; - break; - case 6: - WIN32GUI_LoadUIString (IDS_SELECTROM, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_ROM, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), ROM_FORMAT_STRING, sizeof (ROM_FORMAT_STRING) + sizeof (TCHAR)); - defext = L"ROM"; - break; - case 7: - WIN32GUI_LoadUIString (IDS_SELECTKEY, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_KEY, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), L"(*.key)\0*.key\0", 15 * sizeof (TCHAR)); - defext = L"KEY"; - break; - case 15: - case 16: - WIN32GUI_LoadUIString (flag == 15 ? IDS_RESTOREINP : IDS_SAVEINP, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_INP, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), INP_FORMAT_STRING, sizeof (INP_FORMAT_STRING) + sizeof (TCHAR)); - defext = L"IMP"; - break; - case 9: - case 10: - WIN32GUI_LoadUIString (flag == 10 ? IDS_RESTOREUSS : IDS_SAVEUSS, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_USS, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - if (flag == 10) { - memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_RESTORE, sizeof (USS_FORMAT_STRING_RESTORE) + sizeof (TCHAR)); - all = 1; + static int statefile_previousfilter; + static int previousfilter[20]; + OPENFILENAME openFileName; + TCHAR full_path[MAX_DPATH] = L""; + TCHAR full_path2[MAX_DPATH]; + TCHAR file_name[MAX_DPATH] = L""; + TCHAR init_path[MAX_DPATH] = L""; + BOOL result = FALSE; + TCHAR *amiga_path = NULL, *initialdir = NULL, *defext = NULL; + TCHAR description[CFG_DESCRIPTION_LENGTH] = L""; + TCHAR *p, *nextp; + int all = 1; + int next; + int nosavepath = 0; + const GUID *guid = NULL; + + TCHAR szTitle[MAX_DPATH] = { 0 }; + TCHAR szFormat[MAX_DPATH]; + TCHAR szFilter[MAX_DPATH] = { 0 }; + + memset (&openFileName, 0, sizeof (OPENFILENAME)); + + if (path_out && path_out[0]) { + _tcscpy (init_path, path_out); + nosavepath = 1; } else { - TCHAR tmp[MAX_DPATH]; - memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_SAVE, sizeof (USS_FORMAT_STRING_SAVE) + sizeof (TCHAR)); - p = szFilter; - while (p[0] != 0 || p[1] !=0 ) p++; - p++; - WIN32GUI_LoadUIString (IDS_STATEFILE_UNCOMPRESSED, tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcscat (p, tmp); - _tcscat (p, L" (*.uss)"); - p += _tcslen (p) + 1; - _tcscpy (p, L"*.uss"); - p += _tcslen (p) + 1; - WIN32GUI_LoadUIString (IDS_STATEFILE_RAMDUMP, tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcscat (p, tmp); - _tcscat (p, L" (*.dat)"); - p += _tcslen (p) + 1; - _tcscpy (p, L"*.dat"); - p += _tcslen (p) + 1; - WIN32GUI_LoadUIString (IDS_STATEFILE_WAVE, tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcscat (p, tmp); - _tcscat (p, L" (*.wav)"); - p += _tcslen (p) + 1; - _tcscpy (p, L"*.wav"); - p += _tcslen (p) + 1; - *p = 0; - all = 0; - } - defext = L"USS"; - break; - case 11: - WIN32GUI_LoadUIString (IDS_SELECTFLASH, szTitle, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_FLASH, szFormat, MAX_DPATH); - _stprintf (szFilter, L"%s ", szFormat); - memcpy (szFilter + _tcslen (szFilter), L"(*.nvr)\0*.nvr\0", 15 * sizeof (TCHAR)); - defext = L"NVR"; - break; - case 8: - default: - WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH); - break; - case 12: - WIN32GUI_LoadUIString (IDS_SELECTFS, szTitle, MAX_DPATH); - initialdir = path_out; - break; - case 13: - WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH); - initialdir = path_out; - break; - case 14: - _tcscpy (szTitle, L"Select supported archive file"); - _stprintf (szFilter, L"%s (%s)", L"Archive", ARCHIVE_STRING); - _tcscpy (szFilter + _tcslen (szFilter) + 1, ARCHIVE_STRING); - initialdir = path_out; - break; - } - if (all) { - p = szFilter; - while (p[0] != 0 || p[1] !=0) p++; - p++; - _tcscpy (p, L"All files (*.*)"); - p += _tcslen (p) + 1; - _tcscpy (p, L"*.*"); - p += _tcslen (p) + 1; - *p = 0; - } - openFileName.lStructSize = sizeof (OPENFILENAME); - openFileName.hwndOwner = hDlg; - openFileName.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | - OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; - openFileName.lpstrFilter = szFilter; - openFileName.lpstrDefExt = defext; - openFileName.nFilterIndex = previousfilter[flag]; - openFileName.lpstrFile = full_path; - openFileName.nMaxFile = MAX_DPATH; - openFileName.lpstrFileTitle = file_name; - openFileName.nMaxFileTitle = MAX_DPATH; - if (initialdir) - openFileName.lpstrInitialDir = initialdir; - else - openFileName.lpstrInitialDir = init_path; - openFileName.lpstrTitle = szTitle; - - if (multi) - openFileName.Flags |= OFN_ALLOWMULTISELECT; - if (flag == 1 || flag == 3 || flag == 5 || flag == 9 || flag == 11 || flag == 16) { - if (!(result = GetSaveFileName_2 (&openFileName, guid))) - write_log (L"GetSaveFileNameX() failed, err=%d.\n", GetLastError ()); - } else { - if (!(result = GetOpenFileName_2 (&openFileName, guid))) - write_log (L"GetOpenFileNameX() failed, err=%d.\n", GetLastError ()); - } - previousfilter[flag] = openFileName.nFilterIndex; - - memcpy (full_path2, full_path, sizeof (full_path) / sizeof (TCHAR)); - memcpy (stored_path, full_path, sizeof (stored_path) / sizeof (TCHAR)); - next = 0; - nextp = full_path2 + openFileName.nFileOffset; - if (path_out) { - if (multi) { - while (nextp[0]) - nextp += _tcslen (nextp) + 1; - memcpy (path_out, full_path2, (nextp - full_path2 + 1) * sizeof (TCHAR)); + _tcsncpy (init_path, start_path_data, MAX_DPATH); + switch (flag) + { + case 0: + case 1: + fetch_path (L"FloppyPath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[0]; + break; + case 2: + case 3: + fetch_path (L"hdfPath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[1]; + break; + case 6: + case 7: + case 11: + fetch_path (L"KickstartPath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[2]; + break; + case 4: + case 5: + case 8: + fetch_path (L"ConfigurationPath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[3]; + break; + case 9: + case 10: + { + int ok = 0; + if (savestate_fname[0]) { + _tcscpy (init_path, savestate_fname); + for (;;) { + TCHAR *p; + if (my_existsdir (init_path)) { + ok = 1; + break; + } + p = _tcsrchr (init_path, '\\'); + if (!p) + p = _tcsrchr (init_path, '/'); + if (!p) + break; + *p = 0; + } + } + if (!ok) + fetch_path (L"StatefilePath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[4]; + } + break; + case 15: + case 16: + fetch_path (L"InputPath", init_path, sizeof (init_path) / sizeof (TCHAR)); + guid = &diskselectionguids[5]; + break; + } + } + + szFilter[0] = 0; + szFilter[1] = 0; + switch (flag) { + case 0: + WIN32GUI_LoadUIString (IDS_SELECTADF, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), DISK_FORMAT_STRING, sizeof (DISK_FORMAT_STRING) + sizeof (TCHAR)); + defext = L"ADF"; + break; + case 1: + WIN32GUI_LoadUIString (IDS_CHOOSEBLANK, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_ADF, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), L"(*.adf)\0*.adf\0", 15 * sizeof (TCHAR)); + defext = L"ADF"; + break; + case 2: + case 3: + WIN32GUI_LoadUIString (IDS_SELECTHDF, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_HDF, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), HDF_FORMAT_STRING, sizeof (HDF_FORMAT_STRING) + sizeof (TCHAR)); + defext = L"HDF"; + break; + case 4: + case 5: + WIN32GUI_LoadUIString (IDS_SELECTUAE, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_UAE, szFormat, MAX_DPATH ); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), L"(*.uae)\0*.uae\0", 15 * sizeof (TCHAR)); + defext = L"UAE"; + break; + case 6: + WIN32GUI_LoadUIString (IDS_SELECTROM, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_ROM, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), ROM_FORMAT_STRING, sizeof (ROM_FORMAT_STRING) + sizeof (TCHAR)); + defext = L"ROM"; + break; + case 7: + WIN32GUI_LoadUIString (IDS_SELECTKEY, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_KEY, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), L"(*.key)\0*.key\0", 15 * sizeof (TCHAR)); + defext = L"KEY"; + break; + case 15: + case 16: + WIN32GUI_LoadUIString (flag == 15 ? IDS_RESTOREINP : IDS_SAVEINP, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_INP, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), INP_FORMAT_STRING, sizeof (INP_FORMAT_STRING) + sizeof (TCHAR)); + defext = L"IMP"; + break; + case 9: + case 10: + WIN32GUI_LoadUIString (flag == 10 ? IDS_RESTOREUSS : IDS_SAVEUSS, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_USS, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + if (flag == 10) { + memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_RESTORE, sizeof (USS_FORMAT_STRING_RESTORE) + sizeof (TCHAR)); + all = 1; + } else { + TCHAR tmp[MAX_DPATH]; + memcpy (szFilter + _tcslen (szFilter), USS_FORMAT_STRING_SAVE, sizeof (USS_FORMAT_STRING_SAVE) + sizeof (TCHAR)); + p = szFilter; + while (p[0] != 0 || p[1] !=0 ) p++; + p++; + WIN32GUI_LoadUIString (IDS_STATEFILE_UNCOMPRESSED, tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcscat (p, tmp); + _tcscat (p, L" (*.uss)"); + p += _tcslen (p) + 1; + _tcscpy (p, L"*.uss"); + p += _tcslen (p) + 1; + WIN32GUI_LoadUIString (IDS_STATEFILE_RAMDUMP, tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcscat (p, tmp); + _tcscat (p, L" (*.dat)"); + p += _tcslen (p) + 1; + _tcscpy (p, L"*.dat"); + p += _tcslen (p) + 1; + WIN32GUI_LoadUIString (IDS_STATEFILE_WAVE, tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcscat (p, tmp); + _tcscat (p, L" (*.wav)"); + p += _tcslen (p) + 1; + _tcscpy (p, L"*.wav"); + p += _tcslen (p) + 1; + *p = 0; + all = 0; + } + defext = L"USS"; + break; + case 11: + WIN32GUI_LoadUIString (IDS_SELECTFLASH, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_FLASH, szFormat, MAX_DPATH); + _stprintf (szFilter, L"%s ", szFormat); + memcpy (szFilter + _tcslen (szFilter), L"(*.nvr)\0*.nvr\0", 15 * sizeof (TCHAR)); + defext = L"NVR"; + break; + case 8: + default: + WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH); + break; + case 12: + WIN32GUI_LoadUIString (IDS_SELECTFS, szTitle, MAX_DPATH); + initialdir = path_out; + break; + case 13: + WIN32GUI_LoadUIString (IDS_SELECTINFO, szTitle, MAX_DPATH); + initialdir = path_out; + break; + case 14: + _tcscpy (szTitle, L"Select supported archive file"); + _stprintf (szFilter, L"%s (%s)", L"Archive", ARCHIVE_STRING); + _tcscpy (szFilter + _tcslen (szFilter) + 1, ARCHIVE_STRING); + initialdir = path_out; + break; + } + if (all) { + p = szFilter; + while (p[0] != 0 || p[1] !=0) p++; + p++; + _tcscpy (p, L"All files (*.*)"); + p += _tcslen (p) + 1; + _tcscpy (p, L"*.*"); + p += _tcslen (p) + 1; + *p = 0; + } + openFileName.lStructSize = sizeof (OPENFILENAME); + openFileName.hwndOwner = hDlg; + openFileName.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | + OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; + openFileName.lpstrFilter = szFilter; + openFileName.lpstrDefExt = defext; + openFileName.nFilterIndex = previousfilter[flag]; + openFileName.lpstrFile = full_path; + openFileName.nMaxFile = MAX_DPATH; + openFileName.lpstrFileTitle = file_name; + openFileName.nMaxFileTitle = MAX_DPATH; + if (initialdir) + openFileName.lpstrInitialDir = initialdir; + else + openFileName.lpstrInitialDir = init_path; + openFileName.lpstrTitle = szTitle; + + if (multi) + openFileName.Flags |= OFN_ALLOWMULTISELECT; + if (flag == 1 || flag == 3 || flag == 5 || flag == 9 || flag == 11 || flag == 16) { + if (!(result = GetSaveFileName_2 (&openFileName, guid))) + write_log (L"GetSaveFileNameX() failed, err=%d.\n", GetLastError ()); } else { - _tcscpy (path_out, full_path2); - } - } - nextp = full_path2 + openFileName.nFileOffset; - if (nextp[_tcslen (nextp) + 1] == 0) - multi = 0; - while (result && next >= 0) - { - next = -1; - if (multi) { - if (nextp[0] == 0) - break; - _stprintf (full_path, L"%s\\%s", full_path2, nextp); - nextp += _tcslen (nextp) + 1; - } - switch (wParam) + if (!(result = GetOpenFileName_2 (&openFileName, guid))) + write_log (L"GetOpenFileNameX() failed, err=%d.\n", GetLastError ()); + } + previousfilter[flag] = openFileName.nFilterIndex; + + memcpy (full_path2, full_path, sizeof (full_path) / sizeof (TCHAR)); + memcpy (stored_path, full_path, sizeof (stored_path) / sizeof (TCHAR)); + next = 0; + nextp = full_path2 + openFileName.nFileOffset; + if (path_out) { + if (multi) { + while (nextp[0]) + nextp += _tcslen (nextp) + 1; + memcpy (path_out, full_path2, (nextp - full_path2 + 1) * sizeof (TCHAR)); + } else { + _tcscpy (path_out, full_path2); + } + } + nextp = full_path2 + openFileName.nFileOffset; + if (nextp[_tcslen (nextp) + 1] == 0) + multi = 0; + while (result && next >= 0) { - case IDC_PATH_NAME: - case IDC_PATH_FILESYS: - if (flag == 8) { - if(_tcsstr(full_path, L"Configurations\\")) { - _tcscpy(full_path, init_path); - _tcscat(full_path, file_name); - } - } - SetDlgItemText (hDlg, wParam, full_path); - break; - case IDC_DF0: - case IDC_DF0QQ: - SetDlgItemText (hDlg, IDC_DF0TEXT, full_path); - _tcscpy(prefs->df[0], full_path); - DISK_history_add (full_path, -1, 0); - next = IDC_DF1; - break; - case IDC_DF1: - case IDC_DF1QQ: - SetDlgItemText (hDlg, IDC_DF1TEXT, full_path); - _tcscpy(prefs->df[1], full_path); - DISK_history_add (full_path, -1, 0); - next = IDC_DF2; - break; - case IDC_DF2: - SetDlgItemText (hDlg, IDC_DF2TEXT, full_path); - _tcscpy(prefs->df[2], full_path); - DISK_history_add (full_path, -1, 0); - next = IDC_DF3; - break; - case IDC_DF3: - SetDlgItemText (hDlg, IDC_DF3TEXT, full_path); - _tcscpy (prefs->df[3], full_path); - DISK_history_add (full_path, -1, 0); - break; - case IDC_DOSAVESTATE: - case IDC_DOLOADSTATE: - savestate_initsave (full_path, openFileName.nFilterIndex, FALSE); - break; - case IDC_CREATE: - { - TCHAR disk_name[32]; - disk_name[0] = 0; disk_name[31] = 0; - GetDlgItemText (hDlg, IDC_CREATE_NAME, disk_name, 30); - disk_creatediskfile (full_path, 0, SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_GETCURSEL, 0, 0L), disk_name); - } - break; - case IDC_CREATE_RAW: - disk_creatediskfile (full_path, 1, SendDlgItemMessage(hDlg, IDC_FLOPPYTYPE, CB_GETCURSEL, 0, 0L), NULL); - break; - case IDC_LOAD: - if (target_cfgfile_load (&workprefs, full_path, 0, 0) == 0) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - } else { - SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description); - SetDlgItemText (hDlg, IDC_EDITNAME, full_path); - SetDlgItemText (hDlg, IDC_CONFIGLINK, workprefs.config_host_path); - } - break; - case IDC_SAVE: - SetDlgItemText (hDlg, IDC_EDITNAME, full_path); - cfgfile_save (&workprefs, full_path, 0); - break; - case IDC_ROMFILE: - _tcscpy (workprefs.romfile, full_path); - break; - case IDC_ROMFILE2: - _tcscpy (workprefs.romextfile, full_path); - break; - case IDC_FLASHFILE: - _tcscpy (workprefs.flashfile, full_path); - break; - case IDC_CARTFILE: - _tcscpy (workprefs.cartfile, full_path); - break; - case IDC_INPREC_PLAY: - inprec_open (full_path, IsDlgButtonChecked (hDlg, IDC_INPREC_PLAYMODE) == BST_CHECKED ? -1 : -2); - break; - case IDC_INPREC_RECORD: - inprec_open (full_path, 1); - break; - } - if (!nosavepath) { - if (flag == 0 || flag == 1) { - amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle); - if (amiga_path && amiga_path != openFileName.lpstrFile) { - *amiga_path = 0; - regsetstr (NULL, L"FloppyPath", openFileName.lpstrFile); - } - } else if (flag == 2 || flag == 3) { - amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle); - if (amiga_path && amiga_path != openFileName.lpstrFile) { - *amiga_path = 0; - regsetstr (NULL, L"hdfPath", openFileName.lpstrFile); - } - } - } - if (!multi) - next = -1; - if (next >= 0) - wParam = next; - } - return result; + next = -1; + if (multi) { + if (nextp[0] == 0) + break; + _stprintf (full_path, L"%s\\%s", full_path2, nextp); + nextp += _tcslen (nextp) + 1; + } + switch (wParam) + { + case IDC_PATH_NAME: + case IDC_PATH_FILESYS: + if (flag == 8) { + if(_tcsstr(full_path, L"Configurations\\")) { + _tcscpy(full_path, init_path); + _tcscat(full_path, file_name); + } + } + SetDlgItemText (hDlg, wParam, full_path); + break; + case IDC_DF0: + case IDC_DF0QQ: + SetDlgItemText (hDlg, IDC_DF0TEXT, full_path); + _tcscpy(prefs->df[0], full_path); + DISK_history_add (full_path, -1, 0); + next = IDC_DF1; + break; + case IDC_DF1: + case IDC_DF1QQ: + SetDlgItemText (hDlg, IDC_DF1TEXT, full_path); + _tcscpy(prefs->df[1], full_path); + DISK_history_add (full_path, -1, 0); + next = IDC_DF2; + break; + case IDC_DF2: + SetDlgItemText (hDlg, IDC_DF2TEXT, full_path); + _tcscpy(prefs->df[2], full_path); + DISK_history_add (full_path, -1, 0); + next = IDC_DF3; + break; + case IDC_DF3: + SetDlgItemText (hDlg, IDC_DF3TEXT, full_path); + _tcscpy (prefs->df[3], full_path); + DISK_history_add (full_path, -1, 0); + break; + case IDC_DOSAVESTATE: + case IDC_DOLOADSTATE: + savestate_initsave (full_path, openFileName.nFilterIndex, FALSE); + break; + case IDC_CREATE: + { + TCHAR disk_name[32]; + disk_name[0] = 0; disk_name[31] = 0; + GetDlgItemText (hDlg, IDC_CREATE_NAME, disk_name, 30); + disk_creatediskfile (full_path, 0, SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_GETCURSEL, 0, 0L), disk_name); + } + break; + case IDC_CREATE_RAW: + disk_creatediskfile (full_path, 1, SendDlgItemMessage(hDlg, IDC_FLOPPYTYPE, CB_GETCURSEL, 0, 0L), NULL); + break; + case IDC_LOAD: + if (target_cfgfile_load (&workprefs, full_path, 0, 0) == 0) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + } else { + SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description); + SetDlgItemText (hDlg, IDC_EDITNAME, full_path); + SetDlgItemText (hDlg, IDC_CONFIGLINK, workprefs.config_host_path); + } + break; + case IDC_SAVE: + SetDlgItemText (hDlg, IDC_EDITNAME, full_path); + cfgfile_save (&workprefs, full_path, 0); + break; + case IDC_ROMFILE: + _tcscpy (workprefs.romfile, full_path); + break; + case IDC_ROMFILE2: + _tcscpy (workprefs.romextfile, full_path); + break; + case IDC_FLASHFILE: + _tcscpy (workprefs.flashfile, full_path); + break; + case IDC_CARTFILE: + _tcscpy (workprefs.cartfile, full_path); + break; + case IDC_INPREC_PLAY: + inprec_open (full_path, IsDlgButtonChecked (hDlg, IDC_INPREC_PLAYMODE) == BST_CHECKED ? -1 : -2); + break; + case IDC_INPREC_RECORD: + inprec_open (full_path, 1); + break; + } + if (!nosavepath) { + if (flag == 0 || flag == 1) { + amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle); + if (amiga_path && amiga_path != openFileName.lpstrFile) { + *amiga_path = 0; + regsetstr (NULL, L"FloppyPath", openFileName.lpstrFile); + } + } else if (flag == 2 || flag == 3) { + amiga_path = _tcsstr (openFileName.lpstrFile, openFileName.lpstrFileTitle); + if (amiga_path && amiga_path != openFileName.lpstrFile) { + *amiga_path = 0; + regsetstr (NULL, L"hdfPath", openFileName.lpstrFile); + } + } + } + if (!multi) + next = -1; + if (next >= 0) + wParam = next; + } + return result; } int DiskSelection (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *path_out) { - return DiskSelection_2 (hDlg, wParam, flag, prefs, path_out, NULL); + return DiskSelection_2 (hDlg, wParam, flag, prefs, path_out, NULL); } int MultiDiskSelection (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs, TCHAR *path_out) { - int multi = 0; - return DiskSelection_2 (hDlg, wParam, flag, prefs, path_out, &multi); + int multi = 0; + return DiskSelection_2 (hDlg, wParam, flag, prefs, path_out, &multi); } static int loopmulti (TCHAR *s, TCHAR *out) { - static int index; + static int index; - if (!out) { - index = _tcslen (s) + 1; - return 1; - } - if (index < 0) - return 0; - if (!s[index]) { - if (s[_tcslen (s) + 1] == 0) { - _tcscpy (out, s); - index = -1; - return 1; + if (!out) { + index = _tcslen (s) + 1; + return 1; } - return 0; - } - _stprintf (out, L"%s\\%s", s, s + index); - index += _tcslen (s + index) + 1; - return 1; + if (index < 0) + return 0; + if (!s[index]) { + if (s[_tcslen (s) + 1] == 0) { + _tcscpy (out, s); + index = -1; + return 1; + } + return 0; + } + _stprintf (out, L"%s\\%s", s, s + index); + index += _tcslen (s + index) + 1; + return 1; } static BOOL CreateHardFile (HWND hDlg, UINT hfsizem, TCHAR *dostype, TCHAR *newpath) { - HANDLE hf; - int i = 0; - BOOL result = FALSE; - LONG highword = 0; - DWORD ret, written; - TCHAR init_path[MAX_DPATH] = L""; - uae_u64 hfsize; - uae_u32 dt; - uae_u8 b; - int sparse, dynamic; - - sparse = 0; - dynamic = 0; - hfsize = (uae_u64)hfsizem * 1024 * 1024; - if (IsDlgButtonChecked (hDlg, IDC_HF_SPARSE) == BST_CHECKED) - sparse = 1; - if (IsDlgButtonChecked (hDlg, IDC_HF_DYNAMIC) == BST_CHECKED) { - dynamic = 1; + HANDLE hf; + int i = 0; + BOOL result = FALSE; + LONG highword = 0; + DWORD ret, written; + TCHAR init_path[MAX_DPATH] = L""; + uae_u64 hfsize; + uae_u32 dt; + uae_u8 b; + int sparse, dynamic; + sparse = 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) { - if (dynamic) { - result = vhd_create (init_path, hfsize); - } else { - SetCursor (LoadCursor (NULL, IDC_WAIT)); - if ((hf = CreateFile (init_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) { - if (sparse) { - DWORD ret; - DeviceIoControl (hf, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &ret, NULL); - } - if (hfsize >= 0x80000000) { - highword = (DWORD)(hfsize >> 32); - ret = SetFilePointer (hf, (DWORD)hfsize, &highword, FILE_BEGIN); + dynamic = 0; + hfsize = (uae_u64)hfsizem * 1024 * 1024; + if (IsDlgButtonChecked (hDlg, IDC_HF_SPARSE) == BST_CHECKED) + sparse = 1; + if (IsDlgButtonChecked (hDlg, IDC_HF_DYNAMIC) == BST_CHECKED) { + dynamic = 1; + sparse = 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) { + if (dynamic) { + result = vhd_create (init_path, hfsize); } else { - ret = SetFilePointer (hf, (DWORD)hfsize, NULL, FILE_BEGIN); + SetCursor (LoadCursor (NULL, IDC_WAIT)); + if ((hf = CreateFile (init_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) { + if (sparse) { + DWORD ret; + DeviceIoControl (hf, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &ret, NULL); + } + if (hfsize >= 0x80000000) { + highword = (DWORD)(hfsize >> 32); + ret = SetFilePointer (hf, (DWORD)hfsize, &highword, FILE_BEGIN); + } else { + ret = SetFilePointer (hf, (DWORD)hfsize, NULL, FILE_BEGIN); + } + if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + write_log (L"SetFilePointer() failure for %s to posn %ud\n", init_path, hfsize); + else + result = SetEndOfFile (hf); + SetFilePointer (hf, 0, NULL, FILE_BEGIN); + b = 0; + WriteFile (hf, &b, 1, &written, NULL); + WriteFile (hf, &b, 1, &written, NULL); + WriteFile (hf, &b, 1, &written, NULL); + WriteFile (hf, &b, 1, &written, NULL); + if (_stscanf (dostype, L"%x", &dt) > 0) { + SetFilePointer (hf, 0, NULL, FILE_BEGIN); + b = dt >> 24; + WriteFile (hf, &b, 1, &written, NULL); + b = dt >> 16; + WriteFile (hf, &b, 1, &written, NULL); + b = dt >> 8; + WriteFile (hf, &b, 1, &written, NULL); + b = dt >> 0; + WriteFile (hf, &b, 1, &written, NULL); + } + CloseHandle (hf); + } else { + write_log (L"CreateFile() failed to create %s\n", init_path); + } + SetCursor (LoadCursor (NULL, IDC_ARROW)); } - if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) - write_log (L"SetFilePointer() failure for %s to posn %ud\n", init_path, hfsize); - else - result = SetEndOfFile (hf); - SetFilePointer (hf, 0, NULL, FILE_BEGIN); - b = 0; - WriteFile (hf, &b, 1, &written, NULL); - WriteFile (hf, &b, 1, &written, NULL); - WriteFile (hf, &b, 1, &written, NULL); - WriteFile (hf, &b, 1, &written, NULL); - if (_stscanf (dostype, L"%x", &dt) > 0) { - SetFilePointer (hf, 0, NULL, FILE_BEGIN); - b = dt >> 24; - WriteFile (hf, &b, 1, &written, NULL); - b = dt >> 16; - WriteFile (hf, &b, 1, &written, NULL); - b = dt >> 8; - WriteFile (hf, &b, 1, &written, NULL); - b = dt >> 0; - WriteFile (hf, &b, 1, &written, NULL); - } - CloseHandle (hf); - } else { - write_log (L"CreateFile() failed to create %s\n", init_path); - } - SetCursor (LoadCursor (NULL, IDC_ARROW)); - } - } - if (!result) { - TCHAR szMessage[MAX_DPATH]; - TCHAR 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; + } + if (!result) { + TCHAR szMessage[MAX_DPATH]; + TCHAR 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; } static const TCHAR *memsize_names[] = { -/* 0 */ szNone, -/* 1 */ L"256 K", -/* 2 */ L"512 K", -/* 3 */ L"1 MB", -/* 4 */ L"2 MB", -/* 5 */ L"4 MB", -/* 6 */ L"8 MB", -/* 7 */ L"16 MB", -/* 8 */ L"32 MB", -/* 9 */ L"64 MB", -/* 10*/ L"128 MB", -/* 11*/ L"256 MB", -/* 12*/ L"512 MB", -/* 13*/ L"1 GB", -/* 14*/ L"1.5MB", -/* 15*/ L"1.8MB", -/* 16*/ L"2 GB", -/* 17*/ L"384 MB", -/* 18*/ L"768 MB", -/* 19*/ L"1.5 GB", + /* 0 */ szNone, + /* 1 */ L"256 K", + /* 2 */ L"512 K", + /* 3 */ L"1 MB", + /* 4 */ L"2 MB", + /* 5 */ L"4 MB", + /* 6 */ L"8 MB", + /* 7 */ L"16 MB", + /* 8 */ L"32 MB", + /* 9 */ L"64 MB", + /* 10*/ L"128 MB", + /* 11*/ L"256 MB", + /* 12*/ L"512 MB", + /* 13*/ L"1 GB", + /* 14*/ L"1.5MB", + /* 15*/ L"1.8MB", + /* 16*/ L"2 GB", + /* 17*/ L"384 MB", + /* 18*/ L"768 MB", + /* 19*/ L"1.5 GB", }; static unsigned long memsizes[] = { -/* 0 */ 0, -/* 1 */ 0x00040000, /* 256K */ -/* 2 */ 0x00080000, /* 512K */ -/* 3 */ 0x00100000, /* 1M */ -/* 4 */ 0x00200000, /* 2M */ -/* 5 */ 0x00400000, /* 4M */ -/* 6 */ 0x00800000, /* 8M */ -/* 7 */ 0x01000000, /* 16M */ -/* 8 */ 0x02000000, /* 32M */ -/* 9 */ 0x04000000, /* 64M */ -/* 10*/ 0x08000000, //128M -/* 11*/ 0x10000000, //256M -/* 12*/ 0x20000000, //512M -/* 13*/ 0x40000000, //1GB -/* 14*/ 0x00180000, //1.5MB -/* 15*/ 0x001C0000, //1.8MB -/* 16*/ 0x80000000, //2GB -/* 17*/ 0x18000000, //384M -/* 18*/ 0x30000000, //768M -/* 19*/ 0x60000000, //1.5GB + /* 0 */ 0, + /* 1 */ 0x00040000, /* 256K */ + /* 2 */ 0x00080000, /* 512K */ + /* 3 */ 0x00100000, /* 1M */ + /* 4 */ 0x00200000, /* 2M */ + /* 5 */ 0x00400000, /* 4M */ + /* 6 */ 0x00800000, /* 8M */ + /* 7 */ 0x01000000, /* 16M */ + /* 8 */ 0x02000000, /* 32M */ + /* 9 */ 0x04000000, /* 64M */ + /* 10*/ 0x08000000, //128M + /* 11*/ 0x10000000, //256M + /* 12*/ 0x20000000, //512M + /* 13*/ 0x40000000, //1GB + /* 14*/ 0x00180000, //1.5MB + /* 15*/ 0x001C0000, //1.8MB + /* 16*/ 0x80000000, //2GB + /* 17*/ 0x18000000, //384M + /* 18*/ 0x30000000, //768M + /* 19*/ 0x60000000, //1.5GB }; static int msi_chip[] = { 1, 2, 3, 14, 4, 5, 6 }; @@ -2029,702 +2029,702 @@ static int msi_gfx[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; static int CalculateHardfileSize (HWND hDlg) { - BOOL Translated = FALSE; - UINT mbytes = 0; + BOOL Translated = FALSE; + UINT mbytes = 0; - mbytes = GetDlgItemInt(hDlg, IDC_HF_SIZE, &Translated, FALSE); - if (mbytes <= 0) - mbytes = 0; - if( !Translated ) - mbytes = 0; - return mbytes; + mbytes = GetDlgItemInt(hDlg, IDC_HF_SIZE, &Translated, FALSE); + if (mbytes <= 0) + mbytes = 0; + if( !Translated ) + mbytes = 0; + return mbytes; } static const TCHAR *nth[] = { - L"", L"second ", L"third ", L"fourth ", L"fifth ", L"sixth ", L"seventh ", L"eighth ", L"ninth ", L"tenth " + L"", L"second ", L"third ", L"fourth ", L"fifth ", L"sixth ", L"seventh ", L"eighth ", L"ninth ", L"tenth " }; static void setguititle (HWND phwnd) { - static TCHAR title[200]; - TCHAR title2[1000]; - TCHAR *name; - static HWND hwnd; - - if (phwnd) - hwnd = phwnd; - if (hwnd && !title[0]) { - GetWindowText (hwnd, title, sizeof (title) / sizeof (TCHAR)); - if (_tcslen (WINUAEBETA) > 0) { - _tcscat (title, BetaStr); - if (_tcslen (WINUAEEXTRA) > 0) { - _tcscat (title, L" "); - _tcscat (title, WINUAEEXTRA); - } - } - } - title2[0] = 0; - name = config_filename; - if (name && _tcslen (name) > 0) { - _tcscat (title2, L"["); - _tcscat (title2, name); - _tcscat (title2, L"] - "); - } - _tcscat (title2, title); - SetWindowText (hwnd, title2); + static TCHAR title[200]; + TCHAR title2[1000]; + TCHAR *name; + static HWND hwnd; + + if (phwnd) + hwnd = phwnd; + if (hwnd && !title[0]) { + GetWindowText (hwnd, title, sizeof (title) / sizeof (TCHAR)); + if (_tcslen (WINUAEBETA) > 0) { + _tcscat (title, BetaStr); + if (_tcslen (WINUAEEXTRA) > 0) { + _tcscat (title, L" "); + _tcscat (title, WINUAEEXTRA); + } + } + } + title2[0] = 0; + name = config_filename; + if (name && _tcslen (name) > 0) { + _tcscat (title2, L"["); + _tcscat (title2, name); + _tcscat (title2, L"] - "); + } + _tcscat (title2, title); + SetWindowText (hwnd, title2); } static void GetConfigPath (TCHAR *path, struct ConfigStruct *parent, int noroot) { - if (parent == NULL) { - path[0] = 0; - if (!noroot) { - fetch_path (L"ConfigurationPath", path, MAX_DPATH); + if (parent == NULL) { + path[0] = 0; + if (!noroot) { + fetch_path (L"ConfigurationPath", path, MAX_DPATH); + } + return; + } + if (parent) { + GetConfigPath (path, parent->Parent, noroot); + _tcsncat (path, parent->Name, MAX_DPATH); + _tcsncat (path, L"\\", MAX_DPATH); } - return; - } - if (parent) { - GetConfigPath (path, parent->Parent, noroot); - _tcsncat (path, parent->Name, MAX_DPATH); - _tcsncat (path, L"\\", MAX_DPATH); - } } void FreeConfigStruct (struct ConfigStruct *config) { - xfree (config); + xfree (config); } struct ConfigStruct *AllocConfigStruct (void) { - struct ConfigStruct *config; + struct ConfigStruct *config; - config = xcalloc (sizeof (struct ConfigStruct), 1); - return config; + config = xcalloc (sizeof (struct ConfigStruct), 1); + return config; } static void FreeConfigStore (void) { - int i; - for (i = 0; i < configstoresize; i++) - FreeConfigStruct (configstore[i]); - xfree (configstore); - configstore = 0; - configstoresize = configstoreallocated = 0; + int i; + for (i = 0; i < configstoresize; i++) + FreeConfigStruct (configstore[i]); + xfree (configstore); + configstore = 0; + configstoresize = configstoreallocated = 0; } static void getconfigcache (TCHAR *dst, const TCHAR *path) { - _tcscpy (dst, path); - _tcsncat (dst, L"configuration.cache", MAX_DPATH); + _tcscpy (dst, path); + _tcsncat (dst, L"configuration.cache", MAX_DPATH); } static TCHAR *fgetsx (TCHAR *dst, FILE *f) { - TCHAR *s2; - dst[0] = 0; - s2 = fgetws (dst, MAX_DPATH, f); - if (!s2) - return NULL; - if (_tcslen (dst) == 0) + TCHAR *s2; + dst[0] = 0; + s2 = fgetws (dst, MAX_DPATH, f); + if (!s2) + return NULL; + if (_tcslen (dst) == 0) + return dst; + if (dst[_tcslen (dst) - 1] == '\n') + dst[_tcslen (dst) - 1] = 0; + if (dst[_tcslen (dst) - 1] == '\r') + dst[_tcslen (dst) - 1] = 0; return dst; - if (dst[_tcslen (dst) - 1] == '\n') - dst[_tcslen (dst) - 1] = 0; - if (dst[_tcslen (dst) - 1] == '\r') - dst[_tcslen (dst) - 1] = 0; - return dst; } static TCHAR configcachever[] = L"WinUAE Configuration.Cache"; static void setconfighosthard (struct ConfigStruct *config) { - if (!config->Directory) - return; - if (!_tcsicmp (config->Name, CONFIG_HOST)) - config->host = 1; - if (!_tcsicmp (config->Name, CONFIG_HARDWARE)) - config->hardware = 1; + if (!config->Directory) + return; + if (!_tcsicmp (config->Name, CONFIG_HOST)) + config->host = 1; + if (!_tcsicmp (config->Name, CONFIG_HARDWARE)) + config->hardware = 1; } static void flushconfigcache (const TCHAR *cachepath) { - FILE *zcache; - zcache = _tfopen (cachepath, L"r"); - if (zcache == NULL) - return; - fclose (zcache); - zcache = _tfopen (cachepath, L"w+, ccs=UTF-8"); - if (zcache) - fclose (zcache); - write_log (L"'%s' flushed\n", cachepath); + FILE *zcache; + zcache = _tfopen (cachepath, L"r"); + if (zcache == NULL) + return; + fclose (zcache); + zcache = _tfopen (cachepath, L"w+, ccs=UTF-8"); + if (zcache) + fclose (zcache); + write_log (L"'%s' flushed\n", cachepath); } static struct ConfigStruct *readconfigcache (const TCHAR *path) { - FILE *zcache; - TCHAR cachepath[MAX_DPATH]; - TCHAR buf[MAX_DPATH]; - TCHAR rootpath[MAX_DPATH]; - TCHAR path2[MAX_DPATH], tmp[MAX_DPATH]; - struct ConfigStruct *cs, *first; - int err; - int filelines, dirlines, headlines, dirmode, lines; - TCHAR dirsep = '\\'; - FILETIME t; - SYSTEMTIME st; - ULARGE_INTEGER t1, stt, dirtt; - HANDLE h; - WIN32_FIND_DATA ffd; + FILE *zcache; + TCHAR cachepath[MAX_DPATH]; + TCHAR buf[MAX_DPATH]; + TCHAR rootpath[MAX_DPATH]; + TCHAR path2[MAX_DPATH], tmp[MAX_DPATH]; + struct ConfigStruct *cs, *first; + int err; + int filelines, dirlines, headlines, dirmode, lines; + TCHAR dirsep = '\\'; + FILETIME t; + SYSTEMTIME st; + ULARGE_INTEGER t1, stt, dirtt; + HANDLE h; + WIN32_FIND_DATA ffd; #if CONFIGCACHE == 0 - return NULL; -#endif - err = 0; - first = NULL; - getconfigcache (cachepath, path); - zcache = my_opentext (cachepath); - if (!zcache) - return NULL; - if (!configurationcache) { - fclose (zcache); - _wunlink (cachepath); return NULL; - } - fgetsx (buf, zcache); - if (feof (zcache)) - goto end; - if (_tcscmp (buf, configcachever)) - goto end; - GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL); - _tcscpy (rootpath, path2); - if (path2[_tcslen (path2) - 1] == '\\' || path2[_tcslen (path2) -1] == '/') - path2[_tcslen (path2) - 1] = 0; - h = FindFirstFile (path2, &ffd); - if (h == INVALID_HANDLE_VALUE) - goto end; - FindClose (h); - memcpy (&dirtt, &ffd.ftLastWriteTime, sizeof (ULARGE_INTEGER)); - - fgetsx (buf, zcache); - headlines = _tstol (buf); - fgetsx (buf, zcache); - headlines--; - dirlines = _tstol (buf); - fgetsx (buf, zcache); - headlines--; - filelines = _tstol (buf); - fgetsx (buf, zcache); - t1.QuadPart = _tstoi64 (buf); - headlines--; - GetSystemTime (&st); - SystemTimeToFileTime (&st, &t); - memcpy (&stt, &t, sizeof (ULARGE_INTEGER)); - - if (headlines < 0 || dirlines < 3 || filelines < 3 || - t1.QuadPart == 0 || t1.QuadPart > stt.QuadPart || dirtt.QuadPart > t1.QuadPart) - goto end; - - while (headlines-- > 0) +#endif + err = 0; + first = NULL; + getconfigcache (cachepath, path); + zcache = my_opentext (cachepath); + if (!zcache) + return NULL; + if (!configurationcache) { + fclose (zcache); + _wunlink (cachepath); + return NULL; + } fgetsx (buf, zcache); - fgetsx (buf, zcache); - if (buf[0] != ';') - goto end; - - while (fgetsx (buf, zcache)) { - TCHAR c; - TCHAR dirpath[MAX_DPATH]; - - dirmode = 0; - if (_tcslen (buf) > 0) { - c = buf[_tcslen (buf) - 1]; - if (c == '/' || c == '\\') { - dirmode = 1; - dirsep = c; - } - } - - _tcscpy (dirpath, buf); - if (dirmode) { - lines = dirlines; - } else { - TCHAR *p; - lines = filelines; - p = _tcsrchr (dirpath, dirsep); - if (p) - p[0] = 0; - else - dirpath[0] = 0; - } - - lines--; - cs = AllocConfigStruct (); - if (configstore == NULL || configstoreallocated == configstoresize) { - configstoreallocated += 100; - configstore = realloc (configstore, sizeof (struct ConfigStruct*) * configstoreallocated); - } - configstore[configstoresize++] = cs; - if (!first) - first = cs; - - cs->Directory = dirmode; - _tcscpy (tmp, path); - _tcscat (tmp, dirpath); - _tcscpy (cs->Fullpath, tmp); - _tcscpy (cs->Path, dirpath); - - fgetsx (tmp, zcache); - lines--; - t1.QuadPart = _tstoi64 (tmp); - if (t1.QuadPart > stt.QuadPart) - goto end; - - fgetsx (cs->Name, zcache); - lines--; - fgetsx (cs->Description, zcache); - lines--; - - _tcscpy (tmp, cs->Path); - if (_tcslen (tmp) > 0) { - TCHAR *p = tmp; - if (tmp[_tcslen (tmp) - 1] == dirsep) { - tmp[_tcslen (tmp) - 1] = 0; - p = _tcsrchr (tmp, dirsep); - if (p) - p[1] = 0; - } else { - tmp[_tcslen (tmp) + 1] = 0; - tmp[_tcslen (tmp)] = dirsep; - } - if (p) { - int i; - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs2 = configstore[i]; - if (cs2 != cs && !_tcscmp (cs2->Path, tmp) && cs2->Directory) { - cs->Parent = cs2; - if (!cs2->Child) - cs2->Child = cs; - cs->host = cs2->host; - cs->hardware = cs2->hardware; - } + if (feof (zcache)) + goto end; + if (_tcscmp (buf, configcachever)) + goto end; + GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL); + _tcscpy (rootpath, path2); + if (path2[_tcslen (path2) - 1] == '\\' || path2[_tcslen (path2) -1] == '/') + path2[_tcslen (path2) - 1] = 0; + h = FindFirstFile (path2, &ffd); + if (h == INVALID_HANDLE_VALUE) + goto end; + FindClose (h); + memcpy (&dirtt, &ffd.ftLastWriteTime, sizeof (ULARGE_INTEGER)); + + fgetsx (buf, zcache); + headlines = _tstol (buf); + fgetsx (buf, zcache); + headlines--; + dirlines = _tstol (buf); + fgetsx (buf, zcache); + headlines--; + filelines = _tstol (buf); + fgetsx (buf, zcache); + t1.QuadPart = _tstoi64 (buf); + headlines--; + GetSystemTime (&st); + SystemTimeToFileTime (&st, &t); + memcpy (&stt, &t, sizeof (ULARGE_INTEGER)); + + if (headlines < 0 || dirlines < 3 || filelines < 3 || + t1.QuadPart == 0 || t1.QuadPart > stt.QuadPart || dirtt.QuadPart > t1.QuadPart) + goto end; + + while (headlines-- > 0) + fgetsx (buf, zcache); + fgetsx (buf, zcache); + if (buf[0] != ';') + goto end; + + while (fgetsx (buf, zcache)) { + TCHAR c; + TCHAR dirpath[MAX_DPATH]; + + dirmode = 0; + if (_tcslen (buf) > 0) { + c = buf[_tcslen (buf) - 1]; + if (c == '/' || c == '\\') { + dirmode = 1; + dirsep = c; + } } - } - } - if (_tcslen (cs->Path) > 0 && !dirmode) { - _tcscat (cs->Path, L"\\"); - _tcscat (cs->Fullpath, L"\\"); - } + _tcscpy (dirpath, buf); + if (dirmode) { + lines = dirlines; + } else { + TCHAR *p; + lines = filelines; + p = _tcsrchr (dirpath, dirsep); + if (p) + p[0] = 0; + else + dirpath[0] = 0; + } - if (!dirmode) { - fgetsx (cs->HardwareLink, zcache); - lines--; - fgetsx (cs->HostLink, zcache); - lines--; - fgetsx (buf, zcache); - lines--; - cs->Type = _tstol (buf); - } + lines--; + cs = AllocConfigStruct (); + if (configstore == NULL || configstoreallocated == configstoresize) { + configstoreallocated += 100; + configstore = realloc (configstore, sizeof (struct ConfigStruct*) * configstoreallocated); + } + configstore[configstoresize++] = cs; + if (!first) + first = cs; + + cs->Directory = dirmode; + _tcscpy (tmp, path); + _tcscat (tmp, dirpath); + _tcscpy (cs->Fullpath, tmp); + _tcscpy (cs->Path, dirpath); + + fgetsx (tmp, zcache); + lines--; + t1.QuadPart = _tstoi64 (tmp); + if (t1.QuadPart > stt.QuadPart) + goto end; + + fgetsx (cs->Name, zcache); + lines--; + fgetsx (cs->Description, zcache); + lines--; + + _tcscpy (tmp, cs->Path); + if (_tcslen (tmp) > 0) { + TCHAR *p = tmp; + if (tmp[_tcslen (tmp) - 1] == dirsep) { + tmp[_tcslen (tmp) - 1] = 0; + p = _tcsrchr (tmp, dirsep); + if (p) + p[1] = 0; + } else { + tmp[_tcslen (tmp) + 1] = 0; + tmp[_tcslen (tmp)] = dirsep; + } + if (p) { + int i; + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs2 = configstore[i]; + if (cs2 != cs && !_tcscmp (cs2->Path, tmp) && cs2->Directory) { + cs->Parent = cs2; + if (!cs2->Child) + cs2->Child = cs; + cs->host = cs2->host; + cs->hardware = cs2->hardware; + } + } + } + } + + if (_tcslen (cs->Path) > 0 && !dirmode) { + _tcscat (cs->Path, L"\\"); + _tcscat (cs->Fullpath, L"\\"); + } - setconfighosthard (cs); + if (!dirmode) { + fgetsx (cs->HardwareLink, zcache); + lines--; + fgetsx (cs->HostLink, zcache); + lines--; + fgetsx (buf, zcache); + lines--; + cs->Type = _tstol (buf); + } + + setconfighosthard (cs); - if (lines < 0) - goto end; - while (lines-- > 0) - fgetsx (tmp, zcache); + if (lines < 0) + goto end; + while (lines-- > 0) + fgetsx (tmp, zcache); - fgetsx (tmp, zcache); - if (tmp[0] != ';') - goto end; + fgetsx (tmp, zcache); + if (tmp[0] != ';') + goto end; - } + } end: - if (!feof (zcache)) - err = 1; - fclose (zcache); - if (err || first == NULL) { - write_log (L"'%s' load failed\n", cachepath); - flushconfigcache (cachepath); - FreeConfigStore (); - return NULL; - } else { - write_log (L"'%s' loaded successfully\n", cachepath); - } - return first; + if (!feof (zcache)) + err = 1; + fclose (zcache); + if (err || first == NULL) { + write_log (L"'%s' load failed\n", cachepath); + flushconfigcache (cachepath); + FreeConfigStore (); + return NULL; + } else { + write_log (L"'%s' loaded successfully\n", cachepath); + } + return first; } static void writeconfigcacheentry (FILE *zcache, const TCHAR *relpath, struct ConfigStruct *cs) { - TCHAR path2[MAX_DPATH]; - TCHAR lf = 10; - TCHAR el[] = L";\n"; - TCHAR *p; - ULARGE_INTEGER li; - - GetFullPathName (cs->Fullpath, sizeof path2 / sizeof (TCHAR), path2, NULL); - if (_tcslen (path2) < _tcslen (relpath)) - return; - if (_tcsncmp (path2, relpath, _tcslen (relpath))) - return; - p = path2 + _tcslen (relpath); - if (!cs->Directory) - _tcscat (p, cs->Name); - fwrite (p, _tcslen (p), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - - memcpy (&li, &cs->t, sizeof (ULARGE_INTEGER)); - _stprintf (path2, L"%I64u", li.QuadPart); - fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - - fwrite (cs->Name, _tcslen (cs->Name), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - fwrite (cs->Description, _tcslen (cs->Description), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - - if (!cs->Directory) { - fwrite (cs->HardwareLink, _tcslen (cs->HardwareLink), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - fwrite (cs->HostLink, _tcslen (cs->HostLink), sizeof (TCHAR), zcache); + TCHAR path2[MAX_DPATH]; + TCHAR lf = 10; + TCHAR el[] = L";\n"; + TCHAR *p; + ULARGE_INTEGER li; + + GetFullPathName (cs->Fullpath, sizeof path2 / sizeof (TCHAR), path2, NULL); + if (_tcslen (path2) < _tcslen (relpath)) + return; + if (_tcsncmp (path2, relpath, _tcslen (relpath))) + return; + p = path2 + _tcslen (relpath); + if (!cs->Directory) + _tcscat (p, cs->Name); + fwrite (p, _tcslen (p), sizeof (TCHAR), zcache); fwrite (&lf, 1, sizeof (TCHAR), zcache); - _stprintf (path2, L"%d", cs->Type); + + memcpy (&li, &cs->t, sizeof (ULARGE_INTEGER)); + _stprintf (path2, L"%I64u", li.QuadPart); fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache); fwrite (&lf, 1, sizeof (TCHAR), zcache); - } - fwrite (el, _tcslen (el), sizeof (TCHAR), zcache); + fwrite (cs->Name, _tcslen (cs->Name), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + fwrite (cs->Description, _tcslen (cs->Description), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + + if (!cs->Directory) { + fwrite (cs->HardwareLink, _tcslen (cs->HardwareLink), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + fwrite (cs->HostLink, _tcslen (cs->HostLink), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + _stprintf (path2, L"%d", cs->Type); + fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + } + + fwrite (el, _tcslen (el), sizeof (TCHAR), zcache); } static void writeconfigcacherec (FILE *zcache, const TCHAR *relpath, struct ConfigStruct *cs) { - int i; - - if (!cs->Directory) - return; - writeconfigcacheentry (zcache, relpath, cs); - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs2 = configstore[i]; - if (cs2->Parent == cs) - writeconfigcacherec (zcache, relpath, cs2); - } + int i; + + if (!cs->Directory) + return; + writeconfigcacheentry (zcache, relpath, cs); + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs2 = configstore[i]; + if (cs2->Parent == cs) + writeconfigcacherec (zcache, relpath, cs2); + } } static void writeconfigcache (const TCHAR *path) { - int i; - TCHAR lf = 10; - FILE *zcache; - TCHAR cachepath[MAX_DPATH]; - TCHAR path2[MAX_DPATH]; - FILETIME t; - SYSTEMTIME st; - - if (!configurationcache) - return; - getconfigcache (cachepath, path); - zcache = _tfopen (cachepath, L"w, ccs=UTF-8"); - if (!zcache) - return; - t.dwHighDateTime = t.dwLowDateTime = 0; - GetSystemTime (&st); - SystemTimeToFileTime (&st, &t); - fwrite (configcachever, _tcslen (configcachever), sizeof (TCHAR), zcache); - fwrite (&lf, 1, sizeof (TCHAR), zcache); - _stprintf (path2, L"3\n4\n7\n%I64u\n;\n", t); - fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache); - GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL); - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs = configstore[i]; - if (cs->Directory && cs->Parent == NULL) - writeconfigcacherec (zcache, path2, cs); - } - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs = configstore[i]; - if (!cs->Directory) - writeconfigcacheentry (zcache, path2, cs); - } - fclose (zcache); - write_log (L"'%s' created\n", cachepath); + int i; + TCHAR lf = 10; + FILE *zcache; + TCHAR cachepath[MAX_DPATH]; + TCHAR path2[MAX_DPATH]; + FILETIME t; + SYSTEMTIME st; + + if (!configurationcache) + return; + getconfigcache (cachepath, path); + zcache = _tfopen (cachepath, L"w, ccs=UTF-8"); + if (!zcache) + return; + t.dwHighDateTime = t.dwLowDateTime = 0; + GetSystemTime (&st); + SystemTimeToFileTime (&st, &t); + fwrite (configcachever, _tcslen (configcachever), sizeof (TCHAR), zcache); + fwrite (&lf, 1, sizeof (TCHAR), zcache); + _stprintf (path2, L"3\n4\n7\n%I64u\n;\n", t); + fwrite (path2, _tcslen (path2), sizeof (TCHAR), zcache); + GetFullPathName (path, sizeof path2 / sizeof (TCHAR), path2, NULL); + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs = configstore[i]; + if (cs->Directory && cs->Parent == NULL) + writeconfigcacherec (zcache, path2, cs); + } + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs = configstore[i]; + if (!cs->Directory) + writeconfigcacheentry (zcache, path2, cs); + } + fclose (zcache); + write_log (L"'%s' created\n", cachepath); } static struct ConfigStruct *GetConfigs (struct ConfigStruct *configparent, int usedirs, int *level, int flushcache) { - DWORD num_bytes = 0; - TCHAR path[MAX_DPATH]; - TCHAR path2[MAX_DPATH]; - TCHAR shortpath[MAX_DPATH]; - WIN32_FIND_DATA find_data; - struct ConfigStruct *config, *first; - HANDLE handle; - - if (*level == 0) - FreeConfigStore (); + DWORD num_bytes = 0; + TCHAR path[MAX_DPATH]; + TCHAR path2[MAX_DPATH]; + TCHAR shortpath[MAX_DPATH]; + WIN32_FIND_DATA find_data; + struct ConfigStruct *config, *first; + HANDLE handle; - first = NULL; - GetConfigPath (path, configparent, FALSE); - GetConfigPath (shortpath, configparent, TRUE); - _tcscpy (path2, path); - _tcsncat (path2, L"*.*", MAX_DPATH); + if (*level == 0) + FreeConfigStore (); - if (*level == 0) { - if (flushcache) { - TCHAR cachepath[MAX_DPATH]; - getconfigcache (cachepath, path); - flushconfigcache (cachepath); + first = NULL; + GetConfigPath (path, configparent, FALSE); + GetConfigPath (shortpath, configparent, TRUE); + _tcscpy (path2, path); + _tcsncat (path2, L"*.*", MAX_DPATH); + + if (*level == 0) { + if (flushcache) { + TCHAR cachepath[MAX_DPATH]; + getconfigcache (cachepath, path); + flushconfigcache (cachepath); + } + first = readconfigcache (path); + if (first) + return first; } - first = readconfigcache (path); - if (first) - return first; - } - handle = FindFirstFile (path2, &find_data ); - if (handle == INVALID_HANDLE_VALUE) { + handle = FindFirstFile (path2, &find_data ); + if (handle == INVALID_HANDLE_VALUE) { #ifndef SINGLEFILE - // Either the directory has no .CFG files, or doesn't exist. - // Create the directory, even if it already exists. No harm, and don't check return codes, because - // we may be doing this on a read-only media like CD-ROM. - if (configparent == NULL) { - GetConfigPath (path, NULL, FALSE); - CreateDirectory (path, NULL); - } -#endif - return NULL; - } - for (;;) { - config = NULL; - if (_tcscmp (find_data.cFileName, L".") && _tcscmp (find_data.cFileName, L"..")) { - int ok = 0; - config = AllocConfigStruct (); - _tcscpy (config->Path, shortpath); - _tcscpy (config->Fullpath, path); - memcpy (&config->t, &find_data.ftLastWriteTime, sizeof (FILETIME)); - if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && usedirs) { - if ((*level) < 2) { - struct ConfigStruct *child; - _tcscpy (config->Name, find_data.cFileName); - _tcscpy (config->Path, shortpath); - _tcscat (config->Path, config->Name); - _tcscat (config->Path, L"\\"); - _tcscpy (config->Fullpath, path); - _tcscat (config->Fullpath, config->Name); - _tcscat (config->Fullpath, L"\\"); - config->Directory = 1; - (*level)++; - config->Parent = configparent; - setconfighosthard (config); - child = GetConfigs (config, usedirs, level, FALSE); - (*level)--; - if (child) - config->Child = child; - ok = 1; - } - } else if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - TCHAR path3[MAX_DPATH]; - if (_tcslen (find_data.cFileName) > 4 && !strcasecmp (find_data.cFileName + _tcslen (find_data.cFileName) - 4, L".uae")) { - _tcscpy (path3, path); - _tcsncat (path3, find_data.cFileName, MAX_DPATH); - if (cfgfile_get_description (path3, config->Description, config->HostLink, config->HardwareLink, &config->Type)) { - _tcscpy (config->Name, find_data.cFileName); - ok = 1; - } + // Either the directory has no .CFG files, or doesn't exist. + // Create the directory, even if it already exists. No harm, and don't check return codes, because + // we may be doing this on a read-only media like CD-ROM. + if (configparent == NULL) { + GetConfigPath (path, NULL, FALSE); + CreateDirectory (path, NULL); } - } - if (!ok) { - FreeConfigStruct (config); +#endif + return NULL; + } + for (;;) { config = NULL; - } + if (_tcscmp (find_data.cFileName, L".") && _tcscmp (find_data.cFileName, L"..")) { + int ok = 0; + config = AllocConfigStruct (); + _tcscpy (config->Path, shortpath); + _tcscpy (config->Fullpath, path); + memcpy (&config->t, &find_data.ftLastWriteTime, sizeof (FILETIME)); + if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && usedirs) { + if ((*level) < 2) { + struct ConfigStruct *child; + _tcscpy (config->Name, find_data.cFileName); + _tcscpy (config->Path, shortpath); + _tcscat (config->Path, config->Name); + _tcscat (config->Path, L"\\"); + _tcscpy (config->Fullpath, path); + _tcscat (config->Fullpath, config->Name); + _tcscat (config->Fullpath, L"\\"); + config->Directory = 1; + (*level)++; + config->Parent = configparent; + setconfighosthard (config); + child = GetConfigs (config, usedirs, level, FALSE); + (*level)--; + if (child) + config->Child = child; + ok = 1; + } + } else if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + TCHAR path3[MAX_DPATH]; + if (_tcslen (find_data.cFileName) > 4 && !strcasecmp (find_data.cFileName + _tcslen (find_data.cFileName) - 4, L".uae")) { + _tcscpy (path3, path); + _tcsncat (path3, find_data.cFileName, MAX_DPATH); + if (cfgfile_get_description (path3, config->Description, config->HostLink, config->HardwareLink, &config->Type)) { + _tcscpy (config->Name, find_data.cFileName); + ok = 1; + } + } + } + if (!ok) { + FreeConfigStruct (config); + config = NULL; + } + } + if (config) { + if (configparent) { + config->host = configparent->host; + config->hardware = configparent->hardware; + } + config->Parent = configparent; + if (configstore == NULL || configstoreallocated == configstoresize) { + configstoreallocated += 100; + configstore = realloc (configstore, sizeof (struct ConfigStruct*) * configstoreallocated); + } + configstore[configstoresize++] = config; + if (first == NULL) + first = config; + } + if (FindNextFile (handle, &find_data) == 0) { + FindClose(handle); + break; + } } - if (config) { - if (configparent) { - config->host = configparent->host; - config->hardware = configparent->hardware; - } - config->Parent = configparent; - if (configstore == NULL || configstoreallocated == configstoresize) { - configstoreallocated += 100; - configstore = realloc (configstore, sizeof (struct ConfigStruct*) * configstoreallocated); - } - configstore[configstoresize++] = config; - if (first == NULL) - first = config; - } - if (FindNextFile (handle, &find_data) == 0) { - FindClose(handle); - break; - } - } - if (*level == 0 && CONFIGCACHE) - writeconfigcache (path); - return first; + if (*level == 0 && CONFIGCACHE) + writeconfigcache (path); + return first; } static struct ConfigStruct *CreateConfigStore (struct ConfigStruct *oldconfig, int flushcache) { - int level, i; - TCHAR path[MAX_DPATH], name[MAX_DPATH]; - struct ConfigStruct *cs; - - if (oldconfig) { - _tcscpy (path, oldconfig->Path); - _tcscpy (name, oldconfig->Name); - } - level = 0; - GetConfigs (NULL, 1, &level, flushcache); - if (oldconfig) { - for (i = 0; i < configstoresize; i++) { - cs = configstore[i]; - if (!cs->Directory && !_tcscmp (path, cs->Path) && !_tcscmp (name, cs->Name)) - return cs; + int level, i; + TCHAR path[MAX_DPATH], name[MAX_DPATH]; + struct ConfigStruct *cs; + + if (oldconfig) { + _tcscpy (path, oldconfig->Path); + _tcscpy (name, oldconfig->Name); + } + level = 0; + GetConfigs (NULL, 1, &level, flushcache); + if (oldconfig) { + for (i = 0; i < configstoresize; i++) { + cs = configstore[i]; + if (!cs->Directory && !_tcscmp (path, cs->Path) && !_tcscmp (name, cs->Name)) + return cs; + } } - } - return 0; + return 0; } static TCHAR *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *config, TCHAR *newpath) { - TCHAR name[MAX_DPATH], desc[MAX_DPATH]; - TCHAR path[MAX_DPATH]; - static TCHAR full_path[MAX_DPATH]; - - full_path[0] = 0; - name[0] = 0; - desc[0] = 0; - GetDlgItemText (hDlg, IDC_EDITNAME, name, MAX_DPATH); - _tcscpy (config_filename, name); - if (flag == CONFIG_SAVE_FULL || flag == CONFIG_SAVE) { - if (_tcslen (name) < 4 || strcasecmp (name + _tcslen (name) - 4, L".uae")) { - _tcscat (name, L".uae"); - SetDlgItemText (hDlg, IDC_EDITNAME, name); - } - if (config) - _tcscpy (config->Name, name); - } - GetDlgItemText (hDlg, IDC_EDITDESCRIPTION, desc, MAX_DPATH); - if (config) { - _tcscpy (path, config->Fullpath); - } else { - fetch_configurationpath (path, sizeof (path) / sizeof (TCHAR)); - } - _tcsncat (path, name, MAX_DPATH); - _tcscpy (full_path, path); - switch (flag) - { + TCHAR name[MAX_DPATH], desc[MAX_DPATH]; + TCHAR path[MAX_DPATH]; + static TCHAR full_path[MAX_DPATH]; + + full_path[0] = 0; + name[0] = 0; + desc[0] = 0; + GetDlgItemText (hDlg, IDC_EDITNAME, name, MAX_DPATH); + _tcscpy (config_filename, name); + if (flag == CONFIG_SAVE_FULL || flag == CONFIG_SAVE) { + if (_tcslen (name) < 4 || strcasecmp (name + _tcslen (name) - 4, L".uae")) { + _tcscat (name, L".uae"); + SetDlgItemText (hDlg, IDC_EDITNAME, name); + } + if (config) + _tcscpy (config->Name, name); + } + GetDlgItemText (hDlg, IDC_EDITDESCRIPTION, desc, MAX_DPATH); + if (config) { + _tcscpy (path, config->Fullpath); + } else { + fetch_configurationpath (path, sizeof (path) / sizeof (TCHAR)); + } + _tcsncat (path, name, MAX_DPATH); + _tcscpy (full_path, path); + switch (flag) + { case CONFIG_SAVE_FULL: - DiskSelection(hDlg, IDC_SAVE, 5, &workprefs, newpath); - break; + DiskSelection(hDlg, IDC_SAVE, 5, &workprefs, newpath); + break; case CONFIG_LOAD_FULL: - DiskSelection(hDlg, IDC_LOAD, 4, &workprefs, newpath); - EnableWindow(GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]); - break; + DiskSelection(hDlg, IDC_LOAD, 4, &workprefs, newpath); + EnableWindow(GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]); + break; case CONFIG_SAVE: - if (_tcslen (name) == 0 || _tcscmp (name, L".uae") == 0) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString(IDS_MUSTENTERNAME, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - } else { - _tcscpy (workprefs.description, desc); - cfgfile_save (&workprefs, path, configtypepanel); - } - break; + if (_tcslen (name) == 0 || _tcscmp (name, L".uae") == 0) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString(IDS_MUSTENTERNAME, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + } else { + _tcscpy (workprefs.description, desc); + cfgfile_save (&workprefs, path, configtypepanel); + } + break; case CONFIG_LOAD: - if (_tcslen (name) == 0) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIG, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - } else { - if (target_cfgfile_load (&workprefs, path, configtypepanel, 0) == 0) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - config_filename[0] = 0; + if (_tcslen (name) == 0) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIG, szMessage, MAX_DPATH); + pre_gui_message (szMessage); } else { - ew (hDlg, IDC_VIEWINFO, workprefs.info[0]); + if (target_cfgfile_load (&workprefs, path, configtypepanel, 0) == 0) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + config_filename[0] = 0; + } else { + ew (hDlg, IDC_VIEWINFO, workprefs.info[0]); + } } - } - break; + break; case CONFIG_DELETE: - if (_tcslen (name) == 0) { - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIGFORDELETE, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - } else { - TCHAR szMessage[MAX_DPATH]; - TCHAR szTitle[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_DELETECONFIGCONFIRMATION, szMessage, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_DELETECONFIGTITLE, szTitle, MAX_DPATH ); - if (MessageBox (hDlg, szMessage, szTitle, - MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND) == IDYES) { - cfgfile_backup (path); - DeleteFile (path); - write_log (L"deleted config '%s'\n", path); - config_filename[0] = 0; - } - } - break; - } - - setguititle (NULL); - return full_path; -} - - + if (_tcslen (name) == 0) { + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIGFORDELETE, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + } else { + TCHAR szMessage[MAX_DPATH]; + TCHAR szTitle[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_DELETECONFIGCONFIRMATION, szMessage, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_DELETECONFIGTITLE, szTitle, MAX_DPATH ); + if (MessageBox (hDlg, szMessage, szTitle, + MB_YESNO | MB_ICONWARNING | MB_APPLMODAL | MB_SETFOREGROUND) == IDYES) { + cfgfile_backup (path); + DeleteFile (path); + write_log (L"deleted config '%s'\n", path); + config_filename[0] = 0; + } + } + break; + } + + setguititle (NULL); + return full_path; +} + + static int disk_in_drive (int entry) { - int i; - for (i = 0; i < 4; i++) { - if (_tcslen (workprefs.dfxlist[entry]) > 0 && !_tcscmp (workprefs.dfxlist[entry], workprefs.df[i])) - return i; - } - return -1; + int i; + for (i = 0; i < 4; i++) { + if (_tcslen (workprefs.dfxlist[entry]) > 0 && !_tcscmp (workprefs.dfxlist[entry], workprefs.df[i])) + return i; + } + return -1; } static int disk_swap (int entry, int mode) { - int drv, i, drvs[4] = { -1, -1, -1, -1 }; + int drv, i, drvs[4] = { -1, -1, -1, -1 }; - for (i = 0; i < MAX_SPARE_DRIVES; i++) { - drv = disk_in_drive (i); - if (drv >= 0) - drvs[drv] = i; - } - if ((drv = disk_in_drive (entry)) >= 0) { - if (mode < 0) { - workprefs.df[drv][0] = 0; - return 1; - } + for (i = 0; i < MAX_SPARE_DRIVES; i++) { + drv = disk_in_drive (i); + if (drv >= 0) + drvs[drv] = i; + } + if ((drv = disk_in_drive (entry)) >= 0) { + if (mode < 0) { + workprefs.df[drv][0] = 0; + return 1; + } - if (_tcscmp (workprefs.df[drv], currprefs.df[drv])) { - _tcscpy (workprefs.df[drv], currprefs.df[drv]); - disk_insert (drv, workprefs.df[drv]); - } else { - workprefs.df[drv][0] = 0; + if (_tcscmp (workprefs.df[drv], currprefs.df[drv])) { + _tcscpy (workprefs.df[drv], currprefs.df[drv]); + disk_insert (drv, workprefs.df[drv]); + } else { + workprefs.df[drv][0] = 0; + } + if (drvs[0] < 0 || drvs[1] < 0 || drvs[2] < 0 || drvs[3] < 0) { + drv++; + while (drv < 4 && drvs[drv] >= 0) + drv++; + if (drv < 4 && workprefs.dfxtype[drv] >= 0) { + _tcscpy (workprefs.df[drv], workprefs.dfxlist[entry]); + disk_insert (drv, workprefs.df[drv]); + } + } + return 1; } - if (drvs[0] < 0 || drvs[1] < 0 || drvs[2] < 0 || drvs[3] < 0) { - drv++; - while (drv < 4 && drvs[drv] >= 0) - drv++; - if (drv < 4 && workprefs.dfxtype[drv] >= 0) { - _tcscpy (workprefs.df[drv], workprefs.dfxlist[entry]); - disk_insert (drv, workprefs.df[drv]); - } + for (i = 0; i < 4; i++) { + if (drvs[i] < 0 && workprefs.dfxtype[i] >= 0) { + _tcscpy (workprefs.df[i], workprefs.dfxlist[entry]); + disk_insert (i, workprefs.df[i]); + return 1; + } } + _tcscpy (workprefs.df[0], workprefs.dfxlist[entry]); + disk_insert (0, workprefs.df[0]); return 1; - } - for (i = 0; i < 4; i++) { - if (drvs[i] < 0 && workprefs.dfxtype[i] >= 0) { - _tcscpy (workprefs.df[i], workprefs.dfxlist[entry]); - disk_insert (i, workprefs.df[i]); - return 1; - } - } - _tcscpy (workprefs.df[0], workprefs.dfxlist[entry]); - disk_insert (0, workprefs.df[0]); - return 1; } static int input_selected_device, input_selected_widget, input_total_devices; @@ -2732,43 +2732,43 @@ static int input_selected_event, input_selected_sub_num; static void set_lventry_input (HWND list, int index) { - int flags, i, sub; - TCHAR name[256]; - TCHAR custom[MAX_DPATH]; - TCHAR af[32], toggle[32]; - - inputdevice_get_mapped_name (input_selected_device, index, &flags, name, custom, input_selected_sub_num); - if (flags & IDEV_MAPPED_AUTOFIRE_SET) - WIN32GUI_LoadUIString (IDS_YES, af, sizeof (af) / sizeof (TCHAR)); - else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE) - WIN32GUI_LoadUIString (IDS_NO, af, sizeof (af) / sizeof (TCHAR)); - else - _tcscpy (af, L"-"); - if (flags & IDEV_MAPPED_TOGGLE) - WIN32GUI_LoadUIString (IDS_YES, toggle, sizeof (toggle) / sizeof (TCHAR)); - else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE) - WIN32GUI_LoadUIString (IDS_NO, toggle, sizeof (toggle) / sizeof (TCHAR)); - else - _tcscpy (toggle, L"-"); - ListView_SetItemText (list, index, 1, custom[0] ? custom : name); - ListView_SetItemText (list, index, 2, af); - ListView_SetItemText (list, index, 3, toggle); - sub = 0; - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { - if (inputdevice_get_mapped_name (input_selected_device, index, &flags, name, custom, i) || custom[0]) - sub++; - } - _stprintf (name, L"%d", sub); - ListView_SetItemText (list, index, 4, name); + int flags, i, sub; + TCHAR name[256]; + TCHAR custom[MAX_DPATH]; + TCHAR af[32], toggle[32]; + + inputdevice_get_mapped_name (input_selected_device, index, &flags, name, custom, input_selected_sub_num); + if (flags & IDEV_MAPPED_AUTOFIRE_SET) + WIN32GUI_LoadUIString (IDS_YES, af, sizeof (af) / sizeof (TCHAR)); + else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE) + WIN32GUI_LoadUIString (IDS_NO, af, sizeof (af) / sizeof (TCHAR)); + else + _tcscpy (af, L"-"); + if (flags & IDEV_MAPPED_TOGGLE) + WIN32GUI_LoadUIString (IDS_YES, toggle, sizeof (toggle) / sizeof (TCHAR)); + else if (flags & IDEV_MAPPED_AUTOFIRE_POSSIBLE) + WIN32GUI_LoadUIString (IDS_NO, toggle, sizeof (toggle) / sizeof (TCHAR)); + else + _tcscpy (toggle, L"-"); + ListView_SetItemText (list, index, 1, custom[0] ? custom : name); + ListView_SetItemText (list, index, 2, af); + ListView_SetItemText (list, index, 3, toggle); + sub = 0; + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { + if (inputdevice_get_mapped_name (input_selected_device, index, &flags, name, custom, i) || custom[0]) + sub++; + } + _stprintf (name, L"%d", sub); + ListView_SetItemText (list, index, 4, name); } static void update_listview_input (HWND hDlg) { - int i; - if (!input_total_devices) - return; - for (i = 0; i < inputdevice_get_widget_num (input_selected_device); i++) - set_lventry_input (GetDlgItem (hDlg, IDC_INPUTLIST), i); + int i; + if (!input_total_devices) + return; + for (i = 0; i < inputdevice_get_widget_num (input_selected_device); i++) + set_lventry_input (GetDlgItem (hDlg, IDC_INPUTLIST), i); } static int clicked_entry = -1; @@ -2790,1263 +2790,1263 @@ static int listview_num_columns; void InitializeListView (HWND hDlg) { - int lv_type; - HWND list; - LV_ITEM lvstruct; - LV_COLUMN lvcolumn; - RECT rect; - TCHAR column_heading[HARDDISK_COLUMNS][MAX_COLUMN_HEADING_WIDTH]; - TCHAR blocksize_str[6] = L""; - TCHAR readwrite_str[10] = L""; - TCHAR size_str[32] = L""; - TCHAR volname_str[MAX_DPATH] = L""; - TCHAR devname_str[MAX_DPATH] = L""; - TCHAR bootpri_str[6] = L""; - int width = 0; - int items = 0, result = 0, i, j, entry = 0, temp = 0; - TCHAR tmp[10], tmp2[MAX_DPATH]; - int listview_column_width[HARDDISK_COLUMNS]; - - if (hDlg == pages[HARDDISK_ID]) { - - listview_num_columns = HARDDISK_COLUMNS; - lv_type = LV_HARDDISK; - _tcscpy (column_heading[0], L"*"); - WIN32GUI_LoadUIString(IDS_DEVICE, column_heading[1], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_VOLUME, column_heading[2], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_PATH, column_heading[3], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_RW, column_heading[4], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_BLOCKSIZE, column_heading[5], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_HFDSIZE, column_heading[6], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_BOOTPRI, column_heading[7], MAX_COLUMN_HEADING_WIDTH); - list = GetDlgItem(hDlg, IDC_VOLUMELIST); - - } else if (hDlg == pages[INPUT_ID]) { - - listview_num_columns = INPUT_COLUMNS; - lv_type = LV_INPUT; - WIN32GUI_LoadUIString(IDS_INPUTHOSTWIDGET, column_heading[0], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_INPUTAMIGAEVENT, column_heading[1], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_INPUTAUTOFIRE, column_heading[2], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_INPUTTOGGLE, column_heading[3], MAX_COLUMN_HEADING_WIDTH); - _tcscpy (column_heading[4], L"#"); - list = GetDlgItem(hDlg, IDC_INPUTLIST); - - } else if (hDlg == pages[MISC2_ID]) { - - listview_num_columns = MISC2_COLUMNS; - lv_type = LV_MISC2; - _tcscpy (column_heading[0], L"Extension"); - _tcscpy (column_heading[1], L""); - list = GetDlgItem (hDlg, IDC_ASSOCIATELIST); - - } else { - - listview_num_columns = DISK_COLUMNS; - lv_type = LV_DISK; - _tcscpy (column_heading[0], L"#"); - WIN32GUI_LoadUIString(IDS_DISK_IMAGENAME, column_heading[1], MAX_COLUMN_HEADING_WIDTH); - WIN32GUI_LoadUIString(IDS_DISK_DRIVENAME, column_heading[2], MAX_COLUMN_HEADING_WIDTH); - list = GetDlgItem (hDlg, IDC_DISK); - - } - - cachedlist = list; - ListView_DeleteAllItems (list); - - for(i = 0; i < listview_num_columns; i++) - listview_column_width[i] = ListView_GetStringWidth (list, column_heading[i]) + 15; - - // If there are no columns, then insert some - lvcolumn.mask = LVCF_WIDTH; - if (ListView_GetColumn (list, 1, &lvcolumn) == FALSE) { - for(i = 0; i < listview_num_columns; i++) { - lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; - lvcolumn.iSubItem = i; - lvcolumn.fmt = LVCFMT_LEFT; - lvcolumn.pszText = column_heading[i]; - lvcolumn.cx = listview_column_width[i]; - ListView_InsertColumn (list, i, &lvcolumn); - } - } - - if (lv_type == LV_MISC2) { - - listview_column_width[0] = 180; - listview_column_width[1] = 10; - for (i = 0; exts[i].ext; i++) { - lvstruct.mask = LVIF_TEXT | LVIF_PARAM; - lvstruct.pszText = exts[i].ext; - lvstruct.lParam = 0; - lvstruct.iItem = i; - lvstruct.iSubItem = 0; - result = ListView_InsertItem (list, &lvstruct); - ListView_SetItemText (list, result, 1, exts[i].enabled ? L"*" : L""); - } - } else if (lv_type == LV_INPUT) { - - for (i = 0; input_total_devices && i < inputdevice_get_widget_num (input_selected_device); i++) { - TCHAR name[100]; - inputdevice_get_widget_type (input_selected_device, i, name); - lvstruct.mask = LVIF_TEXT | LVIF_PARAM; - lvstruct.pszText = name; - lvstruct.lParam = 0; - lvstruct.iItem = i; - lvstruct.iSubItem = 0; - result = ListView_InsertItem (list, &lvstruct); - width = ListView_GetStringWidth (list, lvstruct.pszText) + 15; - if( width > listview_column_width[0]) - listview_column_width[0] = width; - entry++; - } - listview_column_width [1] = 260; - listview_column_width [2] = 65; - listview_column_width [3] = 65; - listview_column_width [4] = 30; - update_listview_input (hDlg); - - } else if (lv_type == LV_DISK) { + int lv_type; + HWND list; + LV_ITEM lvstruct; + LV_COLUMN lvcolumn; + RECT rect; + TCHAR column_heading[HARDDISK_COLUMNS][MAX_COLUMN_HEADING_WIDTH]; + TCHAR blocksize_str[6] = L""; + TCHAR readwrite_str[10] = L""; + TCHAR size_str[32] = L""; + TCHAR volname_str[MAX_DPATH] = L""; + TCHAR devname_str[MAX_DPATH] = L""; + TCHAR bootpri_str[6] = L""; + int width = 0; + int items = 0, result = 0, i, j, entry = 0, temp = 0; + TCHAR tmp[10], tmp2[MAX_DPATH]; + int listview_column_width[HARDDISK_COLUMNS]; + + if (hDlg == pages[HARDDISK_ID]) { + + listview_num_columns = HARDDISK_COLUMNS; + lv_type = LV_HARDDISK; + _tcscpy (column_heading[0], L"*"); + WIN32GUI_LoadUIString(IDS_DEVICE, column_heading[1], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_VOLUME, column_heading[2], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_PATH, column_heading[3], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_RW, column_heading[4], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_BLOCKSIZE, column_heading[5], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_HFDSIZE, column_heading[6], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_BOOTPRI, column_heading[7], MAX_COLUMN_HEADING_WIDTH); + list = GetDlgItem(hDlg, IDC_VOLUMELIST); + + } else if (hDlg == pages[INPUT_ID]) { + + listview_num_columns = INPUT_COLUMNS; + lv_type = LV_INPUT; + WIN32GUI_LoadUIString(IDS_INPUTHOSTWIDGET, column_heading[0], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_INPUTAMIGAEVENT, column_heading[1], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_INPUTAUTOFIRE, column_heading[2], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_INPUTTOGGLE, column_heading[3], MAX_COLUMN_HEADING_WIDTH); + _tcscpy (column_heading[4], L"#"); + list = GetDlgItem(hDlg, IDC_INPUTLIST); + + } else if (hDlg == pages[MISC2_ID]) { + + listview_num_columns = MISC2_COLUMNS; + lv_type = LV_MISC2; + _tcscpy (column_heading[0], L"Extension"); + _tcscpy (column_heading[1], L""); + list = GetDlgItem (hDlg, IDC_ASSOCIATELIST); - for (i = 0; i < MAX_SPARE_DRIVES; i++) { - int drv; - _stprintf (tmp, L"%d", i + 1); - lvstruct.mask = LVIF_TEXT | LVIF_PARAM; - lvstruct.pszText = tmp; - lvstruct.lParam = 0; - lvstruct.iItem = i; - lvstruct.iSubItem = 0; - result = ListView_InsertItem (list, &lvstruct); - _tcscpy (tmp2, workprefs.dfxlist[i]); - j = _tcslen (tmp2) - 1; - if (j < 0) - j = 0; - while (j > 0) { - if ((tmp2[j - 1] == '\\' || tmp2[j - 1] == '/')) { - if (!(j >= 5 && (tmp2[j - 5] == '.' || tmp2[j - 4] == '.'))) - break; - } - j--; - } - ListView_SetItemText (list, result, 1, tmp2 + j); - drv = disk_in_drive (i); - tmp[0] = 0; - if (drv >= 0) - _stprintf (tmp, L"DF%d:", drv); - ListView_SetItemText (list, result, 2, tmp); - width = ListView_GetStringWidth (list, lvstruct.pszText) + 15; - if (width > listview_column_width[0]) - listview_column_width[0] = width; - entry++; - } - listview_column_width[0] = 30; - listview_column_width[1] = 336; - listview_column_width[2] = 50; - - } else if (lv_type == LV_HARDDISK) { -#ifdef FILESYS - for(i = 0; i < workprefs.mountitems; i++) - { - struct uaedev_config_info *uci = &workprefs.mountconfig[i]; - int nosize = 0, type; - struct mountedinfo mi; - TCHAR *rootdir = uci->rootdir; + } else { + + listview_num_columns = DISK_COLUMNS; + lv_type = LV_DISK; + _tcscpy (column_heading[0], L"#"); + WIN32GUI_LoadUIString(IDS_DISK_IMAGENAME, column_heading[1], MAX_COLUMN_HEADING_WIDTH); + WIN32GUI_LoadUIString(IDS_DISK_DRIVENAME, column_heading[2], MAX_COLUMN_HEADING_WIDTH); + list = GetDlgItem (hDlg, IDC_DISK); - type = get_filesys_unitconfig (&workprefs, i, &mi); - if (type < 0) { - type = uci->ishdf ? FILESYS_HARDFILE : FILESYS_VIRTUAL; - nosize = 1; - } - - if (nosize) - _tcscpy (size_str, L"n/a"); - else if (mi.size >= 1024 * 1024 * 1024) - _stprintf (size_str, L"%.1fG", ((double)(uae_u32)(mi.size / (1024 * 1024))) / 1024.0); - else if (mi.size < 10 * 1024 * 1024) - _stprintf (size_str, L"%dK", mi.size / 1024); - else - _stprintf (size_str, L"%.1fM", ((double)(uae_u32)(mi.size / (1024))) / 1024.0); - - if (uci->controller >= HD_CONTROLLER_IDE0 && uci->controller <= HD_CONTROLLER_IDE3) { - _stprintf (blocksize_str, L"%d", uci->blocksize); - _stprintf (devname_str, L"*IDE%d*", uci->controller - HD_CONTROLLER_IDE0); - _tcscpy (volname_str, L"n/a"); - _tcscpy (bootpri_str, L"n/a"); - } else if (uci->controller >= HD_CONTROLLER_SCSI0 && uci->controller <= HD_CONTROLLER_SCSI6) { - _stprintf (blocksize_str, L"%d", uci->blocksize); - _stprintf (devname_str, L"*SCSI%d*", uci->controller - HD_CONTROLLER_SCSI0); - _tcscpy (volname_str, L"n/a"); - _tcscpy (bootpri_str, L"n/a"); - } else if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { - _tcscpy (blocksize_str, L"n/a"); - _tcscpy(devname_str, L"*SCSRAM*"); - _tcscpy (volname_str, L"n/a"); - _tcscpy (bootpri_str, L"n/a"); - } else if (type == FILESYS_HARDFILE) { - _stprintf (blocksize_str, L"%d", uci->blocksize); - _tcscpy (devname_str, uci->devname); - _tcscpy (volname_str, L"n/a"); - _stprintf (bootpri_str, L"%d", uci->bootpri); - } else if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE || uci->controller) { - _stprintf (blocksize_str, L"%d", uci->blocksize); - _tcscpy (devname_str, L"n/a"); - _tcscpy (volname_str, L"n/a"); - _tcscpy (bootpri_str, L"n/a"); - if (!_tcsncmp (rootdir, L"HD_", 3)) - rootdir += 3; - } else { - _tcscpy (blocksize_str, L"n/a"); - _tcscpy (devname_str, uci->devname); - _tcscpy (volname_str, uci->volname); - _tcscpy (size_str, L"n/a"); - _stprintf (bootpri_str, L"%d", uci->bootpri); - } - if (!mi.ismedia) { - _tcscpy (blocksize_str, L"n/a"); - _tcscpy (size_str, L"n/a"); - } - WIN32GUI_LoadUIString (uci->readonly ? IDS_NO : IDS_YES, readwrite_str, sizeof (readwrite_str) / sizeof (TCHAR)); - - lvstruct.mask = LVIF_TEXT | LVIF_PARAM; - lvstruct.pszText = mi.ismedia == 0 ? L"E" : (nosize ? L"X" : (mi.ismounted ? L"*" : L" ")); - if (uci->controller) - lvstruct.pszText = L" "; - lvstruct.lParam = 0; - lvstruct.iItem = i; - lvstruct.iSubItem = 0; - result = ListView_InsertItem (list, &lvstruct); - if (result != -1) { - - listview_column_width[0] = 15; - - ListView_SetItemText(list, result, 1, devname_str); - width = ListView_GetStringWidth(list, devname_str) + 10; - if(width > listview_column_width[1]) - listview_column_width[1] = width; - - ListView_SetItemText(list, result, 2, volname_str); - width = ListView_GetStringWidth(list, volname_str) + 10; - if(width > listview_column_width[2]) - listview_column_width[2] = width; - - listview_column_width [3] = 150; - ListView_SetItemText(list, result, 3, rootdir); - width = ListView_GetStringWidth(list, rootdir) + 10; - if(width > listview_column_width[3]) - listview_column_width[3] = width; - - ListView_SetItemText(list, result, 4, readwrite_str); - width = ListView_GetStringWidth(list, readwrite_str) + 10; - if(width > listview_column_width[4]) - listview_column_width[4] = width; - - ListView_SetItemText(list, result, 5, blocksize_str); - width = ListView_GetStringWidth(list, blocksize_str) + 10; - if(width > listview_column_width[5]) - listview_column_width[5] = width; - - ListView_SetItemText(list, result, 6, size_str); - width = ListView_GetStringWidth(list, size_str) + 10; - if(width > listview_column_width[6]) - listview_column_width[6] = width; - - ListView_SetItemText(list, result, 7, bootpri_str); - width = ListView_GetStringWidth(list, bootpri_str) + 10; - if(width > listview_column_width[7] ) - listview_column_width[7] = width; - } } -#endif - } - if (result != -1) { - if (GetWindowRect (list, &rect)) { - ScreenToClient (hDlg, (LPPOINT)&rect); - ScreenToClient (hDlg, (LPPOINT)&rect.right); - if (listview_num_columns == 2) { - if ((temp = rect.right - rect.left - listview_column_width[0] - 30) > listview_column_width[1]) - listview_column_width[1] = temp; - } - } - // Adjust our column widths so that we can see the contents... + + cachedlist = list; + ListView_DeleteAllItems (list); + for(i = 0; i < listview_num_columns; i++) - ListView_SetColumnWidth (list, i, listview_column_width[i]); - // Turn on full-row-select option - ListView_SetExtendedListViewStyle (list, LVS_EX_FULLROWSELECT); - // Redraw the items in the list... - items = ListView_GetItemCount (list); - ListView_RedrawItems (list, 0, items); - } + listview_column_width[i] = ListView_GetStringWidth (list, column_heading[i]) + 15; + + // If there are no columns, then insert some + lvcolumn.mask = LVCF_WIDTH; + if (ListView_GetColumn (list, 1, &lvcolumn) == FALSE) { + for(i = 0; i < listview_num_columns; i++) { + lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; + lvcolumn.iSubItem = i; + lvcolumn.fmt = LVCFMT_LEFT; + lvcolumn.pszText = column_heading[i]; + lvcolumn.cx = listview_column_width[i]; + ListView_InsertColumn (list, i, &lvcolumn); + } + } + + if (lv_type == LV_MISC2) { + + listview_column_width[0] = 180; + listview_column_width[1] = 10; + for (i = 0; exts[i].ext; i++) { + lvstruct.mask = LVIF_TEXT | LVIF_PARAM; + lvstruct.pszText = exts[i].ext; + lvstruct.lParam = 0; + lvstruct.iItem = i; + lvstruct.iSubItem = 0; + result = ListView_InsertItem (list, &lvstruct); + ListView_SetItemText (list, result, 1, exts[i].enabled ? L"*" : L""); + } + } else if (lv_type == LV_INPUT) { + + for (i = 0; input_total_devices && i < inputdevice_get_widget_num (input_selected_device); i++) { + TCHAR name[100]; + inputdevice_get_widget_type (input_selected_device, i, name); + lvstruct.mask = LVIF_TEXT | LVIF_PARAM; + lvstruct.pszText = name; + lvstruct.lParam = 0; + lvstruct.iItem = i; + lvstruct.iSubItem = 0; + result = ListView_InsertItem (list, &lvstruct); + width = ListView_GetStringWidth (list, lvstruct.pszText) + 15; + if( width > listview_column_width[0]) + listview_column_width[0] = width; + entry++; + } + listview_column_width [1] = 260; + listview_column_width [2] = 65; + listview_column_width [3] = 65; + listview_column_width [4] = 30; + update_listview_input (hDlg); + + } else if (lv_type == LV_DISK) { + + for (i = 0; i < MAX_SPARE_DRIVES; i++) { + int drv; + _stprintf (tmp, L"%d", i + 1); + lvstruct.mask = LVIF_TEXT | LVIF_PARAM; + lvstruct.pszText = tmp; + lvstruct.lParam = 0; + lvstruct.iItem = i; + lvstruct.iSubItem = 0; + result = ListView_InsertItem (list, &lvstruct); + _tcscpy (tmp2, workprefs.dfxlist[i]); + j = _tcslen (tmp2) - 1; + if (j < 0) + j = 0; + while (j > 0) { + if ((tmp2[j - 1] == '\\' || tmp2[j - 1] == '/')) { + if (!(j >= 5 && (tmp2[j - 5] == '.' || tmp2[j - 4] == '.'))) + break; + } + j--; + } + ListView_SetItemText (list, result, 1, tmp2 + j); + drv = disk_in_drive (i); + tmp[0] = 0; + if (drv >= 0) + _stprintf (tmp, L"DF%d:", drv); + ListView_SetItemText (list, result, 2, tmp); + width = ListView_GetStringWidth (list, lvstruct.pszText) + 15; + if (width > listview_column_width[0]) + listview_column_width[0] = width; + entry++; + } + listview_column_width[0] = 30; + listview_column_width[1] = 336; + listview_column_width[2] = 50; + + } else if (lv_type == LV_HARDDISK) { +#ifdef FILESYS + for(i = 0; i < workprefs.mountitems; i++) + { + struct uaedev_config_info *uci = &workprefs.mountconfig[i]; + int nosize = 0, type; + struct mountedinfo mi; + TCHAR *rootdir = uci->rootdir; + + type = get_filesys_unitconfig (&workprefs, i, &mi); + if (type < 0) { + type = uci->ishdf ? FILESYS_HARDFILE : FILESYS_VIRTUAL; + nosize = 1; + } + + if (nosize) + _tcscpy (size_str, L"n/a"); + else if (mi.size >= 1024 * 1024 * 1024) + _stprintf (size_str, L"%.1fG", ((double)(uae_u32)(mi.size / (1024 * 1024))) / 1024.0); + else if (mi.size < 10 * 1024 * 1024) + _stprintf (size_str, L"%dK", mi.size / 1024); + else + _stprintf (size_str, L"%.1fM", ((double)(uae_u32)(mi.size / (1024))) / 1024.0); + + if (uci->controller >= HD_CONTROLLER_IDE0 && uci->controller <= HD_CONTROLLER_IDE3) { + _stprintf (blocksize_str, L"%d", uci->blocksize); + _stprintf (devname_str, L"*IDE%d*", uci->controller - HD_CONTROLLER_IDE0); + _tcscpy (volname_str, L"n/a"); + _tcscpy (bootpri_str, L"n/a"); + } else if (uci->controller >= HD_CONTROLLER_SCSI0 && uci->controller <= HD_CONTROLLER_SCSI6) { + _stprintf (blocksize_str, L"%d", uci->blocksize); + _stprintf (devname_str, L"*SCSI%d*", uci->controller - HD_CONTROLLER_SCSI0); + _tcscpy (volname_str, L"n/a"); + _tcscpy (bootpri_str, L"n/a"); + } else if (uci->controller == HD_CONTROLLER_PCMCIA_SRAM) { + _tcscpy (blocksize_str, L"n/a"); + _tcscpy(devname_str, L"*SCSRAM*"); + _tcscpy (volname_str, L"n/a"); + _tcscpy (bootpri_str, L"n/a"); + } else if (type == FILESYS_HARDFILE) { + _stprintf (blocksize_str, L"%d", uci->blocksize); + _tcscpy (devname_str, uci->devname); + _tcscpy (volname_str, L"n/a"); + _stprintf (bootpri_str, L"%d", uci->bootpri); + } else if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE || uci->controller) { + _stprintf (blocksize_str, L"%d", uci->blocksize); + _tcscpy (devname_str, L"n/a"); + _tcscpy (volname_str, L"n/a"); + _tcscpy (bootpri_str, L"n/a"); + if (!_tcsncmp (rootdir, L"HD_", 3)) + rootdir += 3; + } else { + _tcscpy (blocksize_str, L"n/a"); + _tcscpy (devname_str, uci->devname); + _tcscpy (volname_str, uci->volname); + _tcscpy (size_str, L"n/a"); + _stprintf (bootpri_str, L"%d", uci->bootpri); + } + if (!mi.ismedia) { + _tcscpy (blocksize_str, L"n/a"); + _tcscpy (size_str, L"n/a"); + } + WIN32GUI_LoadUIString (uci->readonly ? IDS_NO : IDS_YES, readwrite_str, sizeof (readwrite_str) / sizeof (TCHAR)); + + lvstruct.mask = LVIF_TEXT | LVIF_PARAM; + lvstruct.pszText = mi.ismedia == 0 ? L"E" : (nosize ? L"X" : (mi.ismounted ? L"*" : L" ")); + if (uci->controller) + lvstruct.pszText = L" "; + lvstruct.lParam = 0; + lvstruct.iItem = i; + lvstruct.iSubItem = 0; + result = ListView_InsertItem (list, &lvstruct); + if (result != -1) { + + listview_column_width[0] = 15; + + ListView_SetItemText(list, result, 1, devname_str); + width = ListView_GetStringWidth(list, devname_str) + 10; + if(width > listview_column_width[1]) + listview_column_width[1] = width; + + ListView_SetItemText(list, result, 2, volname_str); + width = ListView_GetStringWidth(list, volname_str) + 10; + if(width > listview_column_width[2]) + listview_column_width[2] = width; + + listview_column_width [3] = 150; + ListView_SetItemText(list, result, 3, rootdir); + width = ListView_GetStringWidth(list, rootdir) + 10; + if(width > listview_column_width[3]) + listview_column_width[3] = width; + + ListView_SetItemText(list, result, 4, readwrite_str); + width = ListView_GetStringWidth(list, readwrite_str) + 10; + if(width > listview_column_width[4]) + listview_column_width[4] = width; + + ListView_SetItemText(list, result, 5, blocksize_str); + width = ListView_GetStringWidth(list, blocksize_str) + 10; + if(width > listview_column_width[5]) + listview_column_width[5] = width; + + ListView_SetItemText(list, result, 6, size_str); + width = ListView_GetStringWidth(list, size_str) + 10; + if(width > listview_column_width[6]) + listview_column_width[6] = width; + + ListView_SetItemText(list, result, 7, bootpri_str); + width = ListView_GetStringWidth(list, bootpri_str) + 10; + if(width > listview_column_width[7] ) + listview_column_width[7] = width; + } + } +#endif + } + if (result != -1) { + if (GetWindowRect (list, &rect)) { + ScreenToClient (hDlg, (LPPOINT)&rect); + ScreenToClient (hDlg, (LPPOINT)&rect.right); + if (listview_num_columns == 2) { + if ((temp = rect.right - rect.left - listview_column_width[0] - 30) > listview_column_width[1]) + listview_column_width[1] = temp; + } + } + // Adjust our column widths so that we can see the contents... + for(i = 0; i < listview_num_columns; i++) + ListView_SetColumnWidth (list, i, listview_column_width[i]); + // Turn on full-row-select option + ListView_SetExtendedListViewStyle (list, LVS_EX_FULLROWSELECT); + // Redraw the items in the list... + items = ListView_GetItemCount (list); + ListView_RedrawItems (list, 0, items); + } } static int listview_find_selected (HWND list) { - int i, items; - items = ListView_GetItemCount (list); - for (i = 0; i < items; i++) { - if (ListView_GetItemState (list, i, LVIS_SELECTED) == LVIS_SELECTED) - return i; - } - return -1; + int i, items; + items = ListView_GetItemCount (list); + for (i = 0; i < items; i++) { + if (ListView_GetItemState (list, i, LVIS_SELECTED) == LVIS_SELECTED) + return i; + } + return -1; } static int listview_entry_from_click (HWND list, int *column) { - POINT point; - POINTS p; - DWORD pos = GetMessagePos (); - int items, entry; - - p = MAKEPOINTS (pos); - point.x = p.x; - point.y = p.y; - ScreenToClient (list, &point); - entry = ListView_GetTopIndex (list); - items = entry + ListView_GetCountPerPage (list); - if (items > ListView_GetItemCount (list)) - items = ListView_GetItemCount (list); - - while (entry <= items) { - RECT rect; - /* Get the bounding rectangle of an item. If the mouse - * location is within the bounding rectangle of the item, - * you know you have found the item that was being clicked. */ - if (ListView_GetItemRect (list, entry, &rect, LVIR_BOUNDS)) { - if (PtInRect (&rect, point)) { - POINT ppt; - int i, x; - UINT flag = LVIS_SELECTED | LVIS_FOCUSED; - - ListView_GetItemPosition (list, entry, &ppt); - x = ppt.x; - ListView_SetItemState (list, entry, flag, flag); - for (i = 0; i < listview_num_columns && column; i++) { - int cw = ListView_GetColumnWidth (list, i); - if (x < point.x && x + cw > point.x) { - *column = i; - break; - } - x += cw; - } - return entry; - } - } - entry++; - } - return -1; + POINT point; + POINTS p; + DWORD pos = GetMessagePos (); + int items, entry; + + p = MAKEPOINTS (pos); + point.x = p.x; + point.y = p.y; + ScreenToClient (list, &point); + entry = ListView_GetTopIndex (list); + items = entry + ListView_GetCountPerPage (list); + if (items > ListView_GetItemCount (list)) + items = ListView_GetItemCount (list); + + while (entry <= items) { + RECT rect; + /* Get the bounding rectangle of an item. If the mouse + * location is within the bounding rectangle of the item, + * you know you have found the item that was being clicked. */ + if (ListView_GetItemRect (list, entry, &rect, LVIR_BOUNDS)) { + if (PtInRect (&rect, point)) { + POINT ppt; + int i, x; + UINT flag = LVIS_SELECTED | LVIS_FOCUSED; + + ListView_GetItemPosition (list, entry, &ppt); + x = ppt.x; + ListView_SetItemState (list, entry, flag, flag); + for (i = 0; i < listview_num_columns && column; i++) { + int cw = ListView_GetColumnWidth (list, i); + if (x < point.x && x + cw > point.x) { + *column = i; + break; + } + x += cw; + } + return entry; + } + } + entry++; + } + return -1; } static INT_PTR CALLBACK InfoSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; + static int recursive = 0; - switch (msg) - { + switch (msg) + { case WM_INITDIALOG: - recursive++; - SetDlgItemText (hDlg, IDC_PATH_NAME, workprefs.info); - recursive--; - return TRUE; + recursive++; + SetDlgItemText (hDlg, IDC_PATH_NAME, workprefs.info); + recursive--; + return TRUE; case WM_COMMAND: - if (recursive) - break; - recursive++; + if (recursive) + break; + recursive++; - switch(wParam) - { + switch(wParam) + { case IDC_SELECTOR: - DiskSelection (hDlg, IDC_PATH_NAME, 8, &workprefs, 0); - break; + DiskSelection (hDlg, IDC_PATH_NAME, 8, &workprefs, 0); + break; case IDOK: - EndDialog (hDlg, 1); - break; + EndDialog (hDlg, 1); + break; case IDCANCEL: - EndDialog (hDlg, 0); - break; - } + EndDialog (hDlg, 0); + break; + } - GetDlgItemText(hDlg, IDC_PATH_NAME, workprefs.info, sizeof workprefs.info); - recursive--; - break; - } - return FALSE; + GetDlgItemText(hDlg, IDC_PATH_NAME, workprefs.info, sizeof workprefs.info); + recursive--; + break; + } + return FALSE; } static HTREEITEM AddConfigNode (HWND hDlg, struct ConfigStruct *config, TCHAR *name, TCHAR *desc, TCHAR *path, int isdir, int expand, HTREEITEM parent) { - TVINSERTSTRUCT is; - HWND TVhDlg; - TCHAR s[MAX_DPATH] = L""; - TCHAR file_name[MAX_DPATH], file_path[MAX_DPATH]; - - GetDlgItemText (hDlg, IDC_EDITNAME, file_name, MAX_DPATH); - GetDlgItemText (hDlg, IDC_EDITPATH, file_path, MAX_DPATH); - TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); - memset (&is, 0, sizeof (is)); - is.hInsertAfter = isdir < 0 ? TVI_ROOT : TVI_SORT; - is.hParent = parent; - is.itemex.mask = TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; - if (!_tcscmp (file_name, name) && !_tcscmp (file_path, path)) { - is.itemex.state |= TVIS_SELECTED; - is.itemex.stateMask |= TVIS_SELECTED; - } - if (isdir) { - _tcscat (s, L" "); - is.itemex.state |= TVIS_BOLD; - is.itemex.stateMask |= TVIS_BOLD; - } - if (expand) { - is.itemex.state |= TVIS_EXPANDED; - is.itemex.stateMask |= TVIS_EXPANDED; - } - _tcscat (s, name); - if (_tcslen (s) > 4 && !_tcsicmp (s + _tcslen (s) - 4, L".uae")) - s[_tcslen (s) - 4] = 0; - if (desc && _tcslen (desc) > 0) { - _tcscat (s, L" ("); - _tcscat (s, desc); - _tcscat (s, L")"); - } - is.itemex.pszText = s; - is.itemex.iImage = is.itemex.iSelectedImage = isdir > 0 ? 0 : (isdir < 0) ? 2 : 1; - is.itemex.lParam = (LPARAM)config; - return TreeView_InsertItem (TVhDlg, &is); + TVINSERTSTRUCT is; + HWND TVhDlg; + TCHAR s[MAX_DPATH] = L""; + TCHAR file_name[MAX_DPATH], file_path[MAX_DPATH]; + + GetDlgItemText (hDlg, IDC_EDITNAME, file_name, MAX_DPATH); + GetDlgItemText (hDlg, IDC_EDITPATH, file_path, MAX_DPATH); + TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); + memset (&is, 0, sizeof (is)); + is.hInsertAfter = isdir < 0 ? TVI_ROOT : TVI_SORT; + is.hParent = parent; + is.itemex.mask = TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + if (!_tcscmp (file_name, name) && !_tcscmp (file_path, path)) { + is.itemex.state |= TVIS_SELECTED; + is.itemex.stateMask |= TVIS_SELECTED; + } + if (isdir) { + _tcscat (s, L" "); + is.itemex.state |= TVIS_BOLD; + is.itemex.stateMask |= TVIS_BOLD; + } + if (expand) { + is.itemex.state |= TVIS_EXPANDED; + is.itemex.stateMask |= TVIS_EXPANDED; + } + _tcscat (s, name); + if (_tcslen (s) > 4 && !_tcsicmp (s + _tcslen (s) - 4, L".uae")) + s[_tcslen (s) - 4] = 0; + if (desc && _tcslen (desc) > 0) { + _tcscat (s, L" ("); + _tcscat (s, desc); + _tcscat (s, L")"); + } + is.itemex.pszText = s; + is.itemex.iImage = is.itemex.iSelectedImage = isdir > 0 ? 0 : (isdir < 0) ? 2 : 1; + is.itemex.lParam = (LPARAM)config; + return TreeView_InsertItem (TVhDlg, &is); } static int LoadConfigTreeView (HWND hDlg, int idx, HTREEITEM parent) { - struct ConfigStruct *cparent, *config; - int cnt = 0; + struct ConfigStruct *cparent, *config; + int cnt = 0; - if (configstoresize == 0) - return cnt; - if (idx < 0) { - idx = 0; - for (;;) { - config = configstore[idx]; - if (config->Parent == NULL) - break; - idx++; - if (idx >= configstoresize) + if (configstoresize == 0) return cnt; - } - } - cparent = configstore[idx]->Parent; - idx = 0; - while (idx < configstoresize) { - config = configstore[idx]; - if ((configtypepanel == 1 && !config->hardware) || (configtypepanel == 2 && !config->host) || (configtypepanel == 0 && (config->host || config->hardware))) { - idx++; - continue; - } - if (config->Parent == cparent) { - if (config->Directory) { - HTREEITEM par = AddConfigNode (hDlg, config, config->Name, NULL, config->Path, 1, config->hardware || config->host, parent); - int idx2 = 0; + if (idx < 0) { + idx = 0; for (;;) { - if (configstore[idx2] == config->Child) { - config->item = par; - if (LoadConfigTreeView (hDlg, idx2, par) == 0) { - if (!config->hardware && !config->host && !config->Directory) - TreeView_DeleteItem (GetDlgItem(hDlg, IDC_CONFIGTREE), par); - } - break; - } - idx2++; - if (idx2 >= configstoresize) - break; + config = configstore[idx]; + if (config->Parent == NULL) + break; + idx++; + if (idx >= configstoresize) + return cnt; + } + } + cparent = configstore[idx]->Parent; + idx = 0; + while (idx < configstoresize) { + config = configstore[idx]; + if ((configtypepanel == 1 && !config->hardware) || (configtypepanel == 2 && !config->host) || (configtypepanel == 0 && (config->host || config->hardware))) { + idx++; + continue; } - } else if (!config->Directory) { - if (((config->Type == 0 || config->Type == 3) && configtype == 0) || (config->Type == configtype)) { - config->item = AddConfigNode (hDlg, config, config->Name, config->Description, config->Path, 0, 0, parent); - cnt++; + if (config->Parent == cparent) { + if (config->Directory) { + HTREEITEM par = AddConfigNode (hDlg, config, config->Name, NULL, config->Path, 1, config->hardware || config->host, parent); + int idx2 = 0; + for (;;) { + if (configstore[idx2] == config->Child) { + config->item = par; + if (LoadConfigTreeView (hDlg, idx2, par) == 0) { + if (!config->hardware && !config->host && !config->Directory) + TreeView_DeleteItem (GetDlgItem(hDlg, IDC_CONFIGTREE), par); + } + break; + } + idx2++; + if (idx2 >= configstoresize) + break; + } + } else if (!config->Directory) { + if (((config->Type == 0 || config->Type == 3) && configtype == 0) || (config->Type == configtype)) { + config->item = AddConfigNode (hDlg, config, config->Name, config->Description, config->Path, 0, 0, parent); + cnt++; + } + } } - } + idx++; } - idx++; - } - return cnt; + return cnt; } static void InitializeConfig (HWND hDlg, struct ConfigStruct *config) { - int i, j, idx1, idx2; - - if (config == NULL) { - SetDlgItemText (hDlg, IDC_EDITNAME, L""); - SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, L""); - } else { - SetDlgItemText (hDlg, IDC_EDITNAME, config->Name); - SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, config->Description); - } - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)L""); - idx1 = 1; - idx2 = 0; - for (j = 0; j < 2; j++) { - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs = configstore[i]; - if ((j == 0 && cs->Type == CONFIG_TYPE_HOST) || (j == 1 && cs->Type == CONFIG_TYPE_HARDWARE)) { - TCHAR tmp2[MAX_DPATH]; - _tcscpy (tmp2, configstore[i]->Path); - _tcsncat (tmp2, configstore[i]->Name, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)tmp2); - if (config && (!_tcsicmp (tmp2, config->HardwareLink) || !_tcsicmp (tmp2, config->HostLink))) - idx2 = idx1; - idx1++; - } + int i, j, idx1, idx2; + + if (config == NULL) { + SetDlgItemText (hDlg, IDC_EDITNAME, L""); + SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, L""); + } else { + SetDlgItemText (hDlg, IDC_EDITNAME, config->Name); + SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, config->Description); + } + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)L""); + idx1 = 1; + idx2 = 0; + for (j = 0; j < 2; j++) { + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs = configstore[i]; + if ((j == 0 && cs->Type == CONFIG_TYPE_HOST) || (j == 1 && cs->Type == CONFIG_TYPE_HARDWARE)) { + TCHAR tmp2[MAX_DPATH]; + _tcscpy (tmp2, configstore[i]->Path); + _tcsncat (tmp2, configstore[i]->Name, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_ADDSTRING, 0, (LPARAM)tmp2); + if (config && (!_tcsicmp (tmp2, config->HardwareLink) || !_tcsicmp (tmp2, config->HostLink))) + idx2 = idx1; + idx1++; + } + } } - } - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_SETCURSEL, idx2, 0); + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_SETCURSEL, idx2, 0); } static void DeleteConfigTree (HWND hDlg) { - int i; - HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); - for (i = 0; i < configstoresize; i++) - configstore[i]->item = NULL; - TreeView_DeleteAllItems (TVhDlg); + int i; + HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); + for (i = 0; i < configstoresize; i++) + configstore[i]->item = NULL; + TreeView_DeleteAllItems (TVhDlg); } static HTREEITEM InitializeConfigTreeView (HWND hDlg) { - HIMAGELIST himl = ImageList_Create (16, 16, ILC_COLOR8 | ILC_MASK, 3, 0); - HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); - HTREEITEM parent; - TCHAR path[MAX_DPATH]; - - if (himl) { - HICON icon; - icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FOLDER)); - ImageList_AddIcon (himl, icon); - icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FILE)); - ImageList_AddIcon (himl, icon); - icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_ROOT)); - ImageList_AddIcon (himl, icon); - TreeView_SetImageList (TVhDlg, himl, TVSIL_NORMAL); - } - DeleteConfigTree (hDlg); - GetConfigPath (path, NULL, FALSE); - parent = AddConfigNode (hDlg, NULL, path, NULL, NULL, 0, 1, NULL); - LoadConfigTreeView (hDlg, -1, parent); - return parent; + HIMAGELIST himl = ImageList_Create (16, 16, ILC_COLOR8 | ILC_MASK, 3, 0); + HWND TVhDlg = GetDlgItem(hDlg, IDC_CONFIGTREE); + HTREEITEM parent; + TCHAR path[MAX_DPATH]; + + if (himl) { + HICON icon; + icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FOLDER)); + ImageList_AddIcon (himl, icon); + icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_FILE)); + ImageList_AddIcon (himl, icon); + icon = LoadIcon (hInst, (LPCWSTR)MAKEINTRESOURCE(IDI_ROOT)); + ImageList_AddIcon (himl, icon); + TreeView_SetImageList (TVhDlg, himl, TVSIL_NORMAL); + } + DeleteConfigTree (hDlg); + GetConfigPath (path, NULL, FALSE); + parent = AddConfigNode (hDlg, NULL, path, NULL, NULL, 0, 1, NULL); + LoadConfigTreeView (hDlg, -1, parent); + return parent; } static void ConfigToRegistry (struct ConfigStruct *config, int type) { - if (config) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, config->Path); - _tcsncat (path, config->Name, MAX_DPATH); - regsetstr (NULL, configreg[type], path); - } + if (config) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, config->Path); + _tcsncat (path, config->Name, MAX_DPATH); + regsetstr (NULL, configreg[type], path); + } } static void ConfigToRegistry2 (DWORD ct, int type, DWORD noauto) { - if (type > 0) - regsetint (NULL, configreg2[type], ct); - if (noauto == 0 || noauto == 1) - regsetint (NULL, L"ConfigFile_NoAuto", noauto); + if (type > 0) + regsetint (NULL, configreg2[type], ct); + if (noauto == 0 || noauto == 1) + regsetint (NULL, L"ConfigFile_NoAuto", noauto); } static void checkautoload (HWND hDlg, struct ConfigStruct *config) { - int ct = 0; + int ct = 0; - if (configtypepanel > 0) - regqueryint (NULL, configreg2[configtypepanel], &ct); - if (!config || config->Directory) { - ct = 0; - ConfigToRegistry2 (ct, configtypepanel, -1); - } - CheckDlgButton(hDlg, IDC_CONFIGAUTO, ct ? BST_CHECKED : BST_UNCHECKED); - ew (hDlg, IDC_CONFIGAUTO, configtypepanel > 0 && config && !config->Directory ? TRUE : FALSE); - regqueryint (NULL, L"ConfigFile_NoAuto", &ct); - CheckDlgButton(hDlg, IDC_CONFIGNOLINK, ct ? BST_CHECKED : BST_UNCHECKED); + if (configtypepanel > 0) + regqueryint (NULL, configreg2[configtypepanel], &ct); + if (!config || config->Directory) { + ct = 0; + ConfigToRegistry2 (ct, configtypepanel, -1); + } + CheckDlgButton(hDlg, IDC_CONFIGAUTO, ct ? BST_CHECKED : BST_UNCHECKED); + ew (hDlg, IDC_CONFIGAUTO, configtypepanel > 0 && config && !config->Directory ? TRUE : FALSE); + regqueryint (NULL, L"ConfigFile_NoAuto", &ct); + CheckDlgButton(hDlg, IDC_CONFIGNOLINK, ct ? BST_CHECKED : BST_UNCHECKED); } static struct ConfigStruct *fixloadconfig (HWND hDlg, struct ConfigStruct *config) { - int i; + int i; - if (config && configtypepanel == 0 && (config->host || config->hardware)) - return NULL; - if ((!config && configtypepanel) || (config && (configtypepanel == 2 && !config->host) || (configtypepanel == 1 && !config->hardware))) { - for (i = 0; i < configstoresize; i++) { - struct ConfigStruct *cs = configstore[i]; - if (cs->Directory && ((configtypepanel == 1 && cs->hardware) || (configtypepanel == 2 && cs->host))) { - config = cs; - SetDlgItemText (hDlg, IDC_EDITPATH, config->Path); - break; - } + if (config && configtypepanel == 0 && (config->host || config->hardware)) + return NULL; + if ((!config && configtypepanel) || (config && (configtypepanel == 2 && !config->host) || (configtypepanel == 1 && !config->hardware))) { + for (i = 0; i < configstoresize; i++) { + struct ConfigStruct *cs = configstore[i]; + if (cs->Directory && ((configtypepanel == 1 && cs->hardware) || (configtypepanel == 2 && cs->host))) { + config = cs; + SetDlgItemText (hDlg, IDC_EDITPATH, config->Path); + break; + } + } } - } - return config; + return config; } static struct ConfigStruct *initloadsave (HWND hDlg, struct ConfigStruct *config) { - HTREEITEM root; - TCHAR name_buf[MAX_DPATH]; - DWORD dwRFPsize = sizeof (name_buf) / sizeof (TCHAR); - TCHAR path[MAX_DPATH]; - - EnableWindow (GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]); - SetDlgItemText (hDlg, IDC_EDITPATH, L""); - SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description); - root = InitializeConfigTreeView (hDlg); - if (regquerystr (NULL, configreg[configtypepanel], name_buf, &dwRFPsize)) { - struct ConfigStruct *config2 = getconfigstorefrompath (name_buf, path, configtypepanel); - if (config2) - config = config2; - checkautoload (hDlg, config); - } - config = fixloadconfig (hDlg, config); - if (config && config->item) - TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), config->item); - else - TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), root); - EnableWindow (GetDlgItem(hDlg, IDC_CONFIGAUTO), configtypepanel > 0); - EnableWindow (GetDlgItem(hDlg, IDC_CONFIGLINK), configtypepanel == 0); - EnableWindow (GetDlgItem(hDlg, IDC_CONFIGNOLINK), configtypepanel == 0); - return config; + HTREEITEM root; + TCHAR name_buf[MAX_DPATH]; + DWORD dwRFPsize = sizeof (name_buf) / sizeof (TCHAR); + TCHAR path[MAX_DPATH]; + + EnableWindow (GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]); + SetDlgItemText (hDlg, IDC_EDITPATH, L""); + SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description); + root = InitializeConfigTreeView (hDlg); + if (regquerystr (NULL, configreg[configtypepanel], name_buf, &dwRFPsize)) { + struct ConfigStruct *config2 = getconfigstorefrompath (name_buf, path, configtypepanel); + if (config2) + config = config2; + checkautoload (hDlg, config); + } + config = fixloadconfig (hDlg, config); + if (config && config->item) + TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), config->item); + else + TreeView_SelectItem (GetDlgItem(hDlg, IDC_CONFIGTREE), root); + EnableWindow (GetDlgItem(hDlg, IDC_CONFIGAUTO), configtypepanel > 0); + EnableWindow (GetDlgItem(hDlg, IDC_CONFIGLINK), configtypepanel == 0); + EnableWindow (GetDlgItem(hDlg, IDC_CONFIGNOLINK), configtypepanel == 0); + return config; } static void loadsavecommands (HWND hDlg, WPARAM wParam, struct ConfigStruct **configp, TCHAR **pcfgfile, TCHAR *newpath) { - struct ConfigStruct *config = *configp; - switch (LOWORD (wParam)) - { - case IDC_SAVE: - HandleConfiguration (hDlg, CONFIG_SAVE_FULL, config, newpath); - DeleteConfigTree (hDlg); - config = CreateConfigStore (config, TRUE); - config = fixloadconfig (hDlg, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfigTreeView (hDlg); - InitializeConfig (hDlg, config); - break; + struct ConfigStruct *config = *configp; + switch (LOWORD (wParam)) + { + case IDC_SAVE: + HandleConfiguration (hDlg, CONFIG_SAVE_FULL, config, newpath); + DeleteConfigTree (hDlg); + config = CreateConfigStore (config, TRUE); + config = fixloadconfig (hDlg, config); + ConfigToRegistry (config, configtypepanel); + InitializeConfigTreeView (hDlg); + InitializeConfig (hDlg, config); + break; case IDC_QUICKSAVE: - HandleConfiguration (hDlg, CONFIG_SAVE, config, NULL); - DeleteConfigTree (hDlg); - config = CreateConfigStore (config, TRUE); - config = fixloadconfig (hDlg, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfigTreeView (hDlg); - InitializeConfig (hDlg, config); - break; + HandleConfiguration (hDlg, CONFIG_SAVE, config, NULL); + DeleteConfigTree (hDlg); + config = CreateConfigStore (config, TRUE); + 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); - DeleteConfigTree (hDlg); - config = CreateConfigStore (config, TRUE); - config = fixloadconfig (hDlg, config); - InitializeConfigTreeView (hDlg); - break; - case IDC_VIEWINFO: - if (workprefs.info[0]) { - TCHAR name_buf[MAX_DPATH]; - if (_tcsstr (workprefs.info, L"Configurations\\")) - _stprintf (name_buf, L"%s\\%s", start_path_data, workprefs.info); - else - _tcscpy (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; - TCHAR 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) / sizeof (TCHAR), (LPARAM)tmp); - else - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); - _tcscpy (workprefs.config_host_path, tmp); - } - break; - } - *configp = config; + *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); + DeleteConfigTree (hDlg); + config = CreateConfigStore (config, TRUE); + config = fixloadconfig (hDlg, config); + InitializeConfigTreeView (hDlg); + break; + case IDC_VIEWINFO: + if (workprefs.info[0]) { + TCHAR name_buf[MAX_DPATH]; + if (_tcsstr (workprefs.info, L"Configurations\\")) + _stprintf (name_buf, L"%s\\%s", start_path_data, workprefs.info); + else + _tcscpy (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; + TCHAR 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) / sizeof (TCHAR), (LPARAM)tmp); + else + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); + _tcscpy (workprefs.config_host_path, tmp); + } + break; + } + *configp = config; } static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - TCHAR *cfgfile = NULL; - static int recursive; - static struct ConfigStruct *config; + TCHAR *cfgfile = NULL; + static int recursive; + static struct ConfigStruct *config; - switch (msg) - { - case WM_INITDIALOG: - recursive++; - if (!configstore) { - DeleteConfigTree (hDlg); - CreateConfigStore (NULL, FALSE); - config = NULL; - } - pages[LOADSAVE_ID] = hDlg; - currentpage = LOADSAVE_ID; - config = initloadsave (hDlg, config); - recursive--; - return TRUE; - - case WM_USER: - break; - - case WM_CONTEXTMENU: - { - int id = GetDlgCtrlID((HWND)wParam); - if (id == IDC_SAVE || id == IDC_LOAD) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - loadsavecommands (hDlg, id, &config, &cfgfile, s); - xfree (s); - } - } - break; - } + switch (msg) + { + case WM_INITDIALOG: + recursive++; + if (!configstore) { + DeleteConfigTree (hDlg); + CreateConfigStore (NULL, FALSE); + config = NULL; + } + pages[LOADSAVE_ID] = hDlg; + currentpage = LOADSAVE_ID; + config = initloadsave (hDlg, config); + recursive--; + return TRUE; - case WM_COMMAND: - { - recursive++; - loadsavecommands (hDlg, wParam, &config, &cfgfile, NULL); - recursive++; - break; - } - - case WM_NOTIFY: - { - LPNMHDR nm = (LPNMHDR)lParam; - if (nm->hwndFrom == GetDlgItem (hDlg, IDC_CONFIGTREE)) { - switch (nm->code) - { - case NM_DBLCLK: + case WM_USER: + break; + + case WM_CONTEXTMENU: { - HTREEITEM ht = TreeView_GetSelection (GetDlgItem(hDlg, IDC_CONFIGTREE)); - if (ht != NULL) { - TVITEMEX pitem; - memset (&pitem, 0, sizeof (pitem)); - pitem.mask = TVIF_HANDLE | TVIF_PARAM; - pitem.hItem = ht; - 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, NULL); - ConfigToRegistry (config, configtypepanel); - if (!full_property_sheet) - uae_restart (0, cfgfile); - exit_gui (1); - } + int id = GetDlgCtrlID((HWND)wParam); + if (id == IDC_SAVE || id == IDC_LOAD) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + loadsavecommands (hDlg, id, &config, &cfgfile, s); + xfree (s); + } } - } - return TRUE; + break; } - break; - case TVN_SELCHANGING: - return FALSE; - case TVN_SELCHANGED: + + case WM_COMMAND: { - LPNMTREEVIEW tv = (LPNMTREEVIEW)lParam; - struct ConfigStruct *c = (struct ConfigStruct*)tv->itemNew.lParam; - if (c) { - config = c; - if (!config->Directory) { - InitializeConfig (hDlg, config); - } else { - InitializeConfig (hDlg, NULL); - } - SetDlgItemText (hDlg, IDC_EDITPATH, config->Path); - } - if (configtypepanel > 0) { - if (c && !c->Directory) { - ConfigToRegistry (config, configtypepanel); - InitializeConfig (hDlg, config); + recursive++; + loadsavecommands (hDlg, wParam, &config, &cfgfile, NULL); + recursive++; + break; + } + + case WM_NOTIFY: + { + LPNMHDR nm = (LPNMHDR)lParam; + if (nm->hwndFrom == GetDlgItem (hDlg, IDC_CONFIGTREE)) { + switch (nm->code) + { + case NM_DBLCLK: + { + HTREEITEM ht = TreeView_GetSelection (GetDlgItem(hDlg, IDC_CONFIGTREE)); + if (ht != NULL) { + TVITEMEX pitem; + memset (&pitem, 0, sizeof (pitem)); + pitem.mask = TVIF_HANDLE | TVIF_PARAM; + pitem.hItem = ht; + 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, NULL); + ConfigToRegistry (config, configtypepanel); + if (!full_property_sheet) + uae_restart (0, cfgfile); + exit_gui (1); + } + } + } + return TRUE; + } + break; + case TVN_SELCHANGING: + return FALSE; + case TVN_SELCHANGED: + { + LPNMTREEVIEW tv = (LPNMTREEVIEW)lParam; + struct ConfigStruct *c = (struct ConfigStruct*)tv->itemNew.lParam; + if (c) { + config = c; + if (!config->Directory) { + InitializeConfig (hDlg, config); + } else { + InitializeConfig (hDlg, NULL); + } + SetDlgItemText (hDlg, IDC_EDITPATH, config->Path); + } + if (configtypepanel > 0) { + if (c && !c->Directory) { + ConfigToRegistry (config, configtypepanel); + InitializeConfig (hDlg, config); + } + checkautoload (hDlg, c); + } + return TRUE; + } + break; + } } - checkautoload (hDlg, c); - } - return TRUE; + break; } - break; - } } - break; - } - } - return FALSE; + return FALSE; } #define MAX_CONTRIBUTORS_LENGTH 2048 static INT_PTR CALLBACK ContributorsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - CHARFORMAT CharFormat; - TCHAR szContributors1[MAX_CONTRIBUTORS_LENGTH]; - TCHAR szContributors2[MAX_CONTRIBUTORS_LENGTH]; - TCHAR szContributors[MAX_CONTRIBUTORS_LENGTH * 2]; + CHARFORMAT CharFormat; + TCHAR szContributors1[MAX_CONTRIBUTORS_LENGTH]; + TCHAR szContributors2[MAX_CONTRIBUTORS_LENGTH]; + TCHAR szContributors[MAX_CONTRIBUTORS_LENGTH * 2]; - switch (msg) { - case WM_COMMAND: - if (wParam == ID_OK) { - EndDialog (hDlg, 1); - return TRUE; - } - break; - case WM_INITDIALOG: - CharFormat.cbSize = sizeof (CharFormat); + switch (msg) { + case WM_COMMAND: + if (wParam == ID_OK) { + EndDialog (hDlg, 1); + return TRUE; + } + break; + case WM_INITDIALOG: + CharFormat.cbSize = sizeof (CharFormat); - WIN32GUI_LoadUIString(IDS_CONTRIBUTORS1, szContributors1, MAX_CONTRIBUTORS_LENGTH); - WIN32GUI_LoadUIString(IDS_CONTRIBUTORS2, szContributors2, MAX_CONTRIBUTORS_LENGTH); - _stprintf (szContributors, L"%s%s", szContributors1, szContributors2); + WIN32GUI_LoadUIString(IDS_CONTRIBUTORS1, szContributors1, MAX_CONTRIBUTORS_LENGTH); + WIN32GUI_LoadUIString(IDS_CONTRIBUTORS2, szContributors2, MAX_CONTRIBUTORS_LENGTH); + _stprintf (szContributors, L"%s%s", szContributors1, szContributors2); - SetDlgItemText (hDlg, IDC_CONTRIBUTORS, szContributors ); - SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); - CharFormat.dwMask |= CFM_SIZE | CFM_FACE; - CharFormat.yHeight = 8 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ + SetDlgItemText (hDlg, IDC_CONTRIBUTORS, szContributors ); + SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); + CharFormat.dwMask |= CFM_SIZE | CFM_FACE; + CharFormat.yHeight = 8 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ - _tcscpy (CharFormat.szFaceName, os_vista ? L"Segoe UI" : L"Tahoma"); - SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); - return TRUE; - } - return FALSE; + _tcscpy (CharFormat.szFaceName, os_vista ? L"Segoe UI" : L"Tahoma"); + SendDlgItemMessage (hDlg, IDC_CONTRIBUTORS, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); + return TRUE; + } + return FALSE; } static void DisplayContributors (HWND hDlg) { - CustomDialogBox(IDD_CONTRIBUTORS, hDlg, ContributorsProc); + CustomDialogBox(IDD_CONTRIBUTORS, hDlg, ContributorsProc); } typedef struct url_info { - int id; - BOOL state; - TCHAR *display; - TCHAR *url; + int id; + BOOL state; + TCHAR *display; + TCHAR *url; } urlinfo; static urlinfo urls[] = { - {IDC_CLOANTOHOME, FALSE, L"Cloanto's Amiga Forever", L"http://www.amigaforever.com/"}, - {IDC_AMIGAHOME, FALSE, L"Amiga Inc.", L"http://www.amiga.com"}, - {IDC_PICASSOHOME, FALSE, L"Picasso96 Home Page", L"http://www.picasso96.cogito.de/"}, - {IDC_UAEHOME, FALSE, L"UAE Home Page", L"http://uae.coresystems.de/"}, - {IDC_WINUAEHOME, FALSE, L"WinUAE Home Page", L"http://www.winuae.net/"}, - {IDC_AIABHOME, FALSE, L"AIAB", L"http://www.amigainabox.co.uk/"}, - {IDC_THEROOTS, FALSE, L"Back To The Roots", L"http://www.back2roots.org/"}, - {IDC_ABIME, FALSE, L"abime.net", L"http://www.abime.net/"}, - {IDC_CAPS, FALSE, L"SPS", L"http://www.softpres.org/"}, - {IDC_AMIGASYS, FALSE, L"AmigaSYS", L"http://amigasys.extra.hu/"}, - {IDC_AMIKIT, FALSE, L"AmiKit", L"http://amikit.amiga.sk/"}, - { -1, FALSE, NULL, NULL } + {IDC_CLOANTOHOME, FALSE, L"Cloanto's Amiga Forever", L"http://www.amigaforever.com/"}, + {IDC_AMIGAHOME, FALSE, L"Amiga Inc.", L"http://www.amiga.com"}, + {IDC_PICASSOHOME, FALSE, L"Picasso96 Home Page", L"http://www.picasso96.cogito.de/"}, + {IDC_UAEHOME, FALSE, L"UAE Home Page", L"http://uae.coresystems.de/"}, + {IDC_WINUAEHOME, FALSE, L"WinUAE Home Page", L"http://www.winuae.net/"}, + {IDC_AIABHOME, FALSE, L"AIAB", L"http://www.amigainabox.co.uk/"}, + {IDC_THEROOTS, FALSE, L"Back To The Roots", L"http://www.back2roots.org/"}, + {IDC_ABIME, FALSE, L"abime.net", L"http://www.abime.net/"}, + {IDC_CAPS, FALSE, L"SPS", L"http://www.softpres.org/"}, + {IDC_AMIGASYS, FALSE, L"AmigaSYS", L"http://amigasys.extra.hu/"}, + {IDC_AMIKIT, FALSE, L"AmiKit", L"http://amikit.amiga.sk/"}, + { -1, FALSE, NULL, NULL } }; static void SetupRichText(HWND hDlg, urlinfo *url) { - CHARFORMAT CharFormat; - CharFormat.cbSize = sizeof (CharFormat); + CHARFORMAT CharFormat; + CharFormat.cbSize = sizeof (CharFormat); - SetDlgItemText(hDlg, url->id, url->display); - SendDlgItemMessage(hDlg, url->id, EM_GETCHARFORMAT, 0, (LPARAM)&CharFormat); - CharFormat.dwMask |= CFM_UNDERLINE | CFM_SIZE | CFM_FACE | CFM_COLOR; - CharFormat.dwEffects = url->state ? CFE_UNDERLINE : 0; - CharFormat.yHeight = 10 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ + SetDlgItemText(hDlg, url->id, url->display); + SendDlgItemMessage(hDlg, url->id, EM_GETCHARFORMAT, 0, (LPARAM)&CharFormat); + CharFormat.dwMask |= CFM_UNDERLINE | CFM_SIZE | CFM_FACE | CFM_COLOR; + CharFormat.dwEffects = url->state ? CFE_UNDERLINE : 0; + CharFormat.yHeight = 10 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ - CharFormat.crTextColor = GetSysColor(COLOR_ACTIVECAPTION); - _tcscpy (CharFormat.szFaceName, os_vista ? L"Segoe UI" : L"Tahoma"); - SendDlgItemMessage(hDlg, url->id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CharFormat); - SendDlgItemMessage(hDlg, url->id, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_3DFACE)); + CharFormat.crTextColor = GetSysColor(COLOR_ACTIVECAPTION); + _tcscpy (CharFormat.szFaceName, os_vista ? L"Segoe UI" : L"Tahoma"); + SendDlgItemMessage(hDlg, url->id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CharFormat); + SendDlgItemMessage(hDlg, url->id, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_3DFACE)); } static void url_handler(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int last_rectangle = -1; - int i; - BOOL found = FALSE; - HCURSOR m_hCursor = NULL; - POINT point; - point.x = LOWORD (lParam); - point.y = HIWORD (lParam); + static int last_rectangle = -1; + int i; + BOOL found = FALSE; + HCURSOR m_hCursor = NULL; + POINT point; + point.x = LOWORD (lParam); + point.y = HIWORD (lParam); - for (i = 0; urls[i].id >= 0; i++) - { - RECT rect; - GetWindowRect(GetDlgItem(hDlg, urls[i].id), &rect); - ScreenToClient(hDlg, (POINT*)&rect); - ScreenToClient(hDlg, (POINT*)&rect.right); - if(PtInRect(&rect, point)) + for (i = 0; urls[i].id >= 0; i++) { - if(msg == WM_LBUTTONDOWN) - { - ShellExecute (NULL, NULL, urls[i].url , NULL, NULL, SW_SHOWNORMAL); - SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); - } - else - { - if(i != last_rectangle) + RECT rect; + GetWindowRect(GetDlgItem(hDlg, urls[i].id), &rect); + ScreenToClient(hDlg, (POINT*)&rect); + ScreenToClient(hDlg, (POINT*)&rect.right); + if(PtInRect(&rect, point)) { - // try and load the system hand (Win2000+) - m_hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND) ); - if (!m_hCursor) - { - // retry with our fallback hand - m_hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_MYHAND) ); - } - SetCursor(m_hCursor); - urls[i].state = TRUE; - SetupRichText(hDlg, &urls[i]); - - if(last_rectangle != -1) - { - urls[last_rectangle].state = FALSE; - SetupRichText(hDlg, &urls[last_rectangle]); - } - } - } - last_rectangle = i; - found = TRUE; - break; - } - } - - if(!found && last_rectangle >= 0) - { - SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); - urls[last_rectangle].state = FALSE; - SetupRichText(hDlg, &urls[last_rectangle]); - last_rectangle = -1; - } + if(msg == WM_LBUTTONDOWN) + { + ShellExecute (NULL, NULL, urls[i].url , NULL, NULL, SW_SHOWNORMAL); + SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); + } + else + { + if(i != last_rectangle) + { + // try and load the system hand (Win2000+) + m_hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND) ); + if (!m_hCursor) + { + // retry with our fallback hand + m_hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_MYHAND) ); + } + SetCursor(m_hCursor); + urls[i].state = TRUE; + SetupRichText(hDlg, &urls[i]); + + if(last_rectangle != -1) + { + urls[last_rectangle].state = FALSE; + SetupRichText(hDlg, &urls[last_rectangle]); + } + } + } + last_rectangle = i; + found = TRUE; + break; + } + } + + if(!found && last_rectangle >= 0) + { + SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); + urls[last_rectangle].state = FALSE; + SetupRichText(hDlg, &urls[last_rectangle]); + last_rectangle = -1; + } } static void setac (HWND hDlg, int id) { - SHAutoComplete (GetDlgItem (hDlg, id), SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB); + SHAutoComplete (GetDlgItem (hDlg, id), SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB); } static void setautocomplete (HWND hDlg, int id) { - HWND item = FindWindowEx (GetDlgItem (hDlg, id), NULL, L"Edit", NULL); - if (item) - SHAutoComplete (item, SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB); + HWND item = FindWindowEx (GetDlgItem (hDlg, id), NULL, L"Edit", NULL); + if (item) + SHAutoComplete (item, SHACF_FILESYSTEM | SHACF_AUTOAPPEND_FORCE_ON | SHACF_AUTOSUGGEST_FORCE_ON | SHACF_USETAB); } static void setmultiautocomplete (HWND hDlg, int *ids) { - int i; - for (i = 0; ids[i] >= 0; i++) - setautocomplete (hDlg, ids[i]); + int i; + for (i = 0; ids[i] >= 0; i++) + setautocomplete (hDlg, ids[i]); } static void setpath (HWND hDlg, TCHAR *name, DWORD d, TCHAR *def) { - TCHAR tmp[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, def); - fetch_path (name, tmp, sizeof (tmp) / sizeof (TCHAR)); - SetDlgItemText (hDlg, d, tmp); + _tcscpy (tmp, def); + fetch_path (name, tmp, sizeof (tmp) / sizeof (TCHAR)); + SetDlgItemText (hDlg, d, tmp); } static void values_to_pathsdialog (HWND hDlg) { - setpath (hDlg, L"KickstartPath", IDC_PATHS_ROM, L"Roms"); - setpath (hDlg, L"ConfigurationPath", IDC_PATHS_CONFIG, L"Configurations"); - setpath (hDlg, L"ScreenshotPath", IDC_PATHS_SCREENSHOT, L"ScreenShots"); - setpath (hDlg, L"StatefilePath", IDC_PATHS_SAVESTATE, L"Savestates"); - setpath (hDlg, L"SaveimagePath", IDC_PATHS_SAVEIMAGE, L"SaveImages"); - setpath (hDlg, L"VideoPath", IDC_PATHS_AVIOUTPUT, L"Videos"); - setpath (hDlg, L"RipperPath", IDC_PATHS_RIP, L".\\"); + setpath (hDlg, L"KickstartPath", IDC_PATHS_ROM, L"Roms"); + setpath (hDlg, L"ConfigurationPath", IDC_PATHS_CONFIG, L"Configurations"); + setpath (hDlg, L"ScreenshotPath", IDC_PATHS_SCREENSHOT, L"ScreenShots"); + setpath (hDlg, L"StatefilePath", IDC_PATHS_SAVESTATE, L"Savestates"); + setpath (hDlg, L"SaveimagePath", IDC_PATHS_SAVEIMAGE, L"SaveImages"); + setpath (hDlg, L"VideoPath", IDC_PATHS_AVIOUTPUT, L"Videos"); + setpath (hDlg, L"RipperPath", IDC_PATHS_RIP, L".\\"); } static void resetregistry (void) { - regdeletetree (NULL, L"DetectedROMs"); - regdelete (NULL, L"QuickStartMode"); - regdelete (NULL, L"ConfigFile"); - regdelete (NULL, L"ConfigFileHardware"); - regdelete (NULL, L"ConfigFileHost"); - regdelete (NULL, L"ConfigFileHardware_Auto"); - regdelete (NULL, L"ConfigFileHost_Auto"); - regdelete (NULL, L"ConfigurationPath"); - regdelete (NULL, L"SaveimagePath"); - regdelete (NULL, L"ScreenshotPath"); - regdelete (NULL, L"StatefilePath"); - regdelete (NULL, L"VideoPath"); - regdelete (NULL, L"RipperPath"); - regdelete (NULL, L"QuickStartModel"); - regdelete (NULL, L"QuickStartConfiguration"); - regdelete (NULL, L"QuickStartCompatibility"); - regdelete (NULL, L"QuickStartHostConfig"); - regdelete (NULL, L"ConfigurationCache"); - regdelete (NULL, L"DirectDraw_Secondary"); - regdelete (NULL, L"ShownsupportedModes"); + regdeletetree (NULL, L"DetectedROMs"); + regdelete (NULL, L"QuickStartMode"); + regdelete (NULL, L"ConfigFile"); + regdelete (NULL, L"ConfigFileHardware"); + regdelete (NULL, L"ConfigFileHost"); + regdelete (NULL, L"ConfigFileHardware_Auto"); + regdelete (NULL, L"ConfigFileHost_Auto"); + regdelete (NULL, L"ConfigurationPath"); + regdelete (NULL, L"SaveimagePath"); + regdelete (NULL, L"ScreenshotPath"); + regdelete (NULL, L"StatefilePath"); + regdelete (NULL, L"VideoPath"); + regdelete (NULL, L"RipperPath"); + regdelete (NULL, L"QuickStartModel"); + regdelete (NULL, L"QuickStartConfiguration"); + regdelete (NULL, L"QuickStartCompatibility"); + regdelete (NULL, L"QuickStartHostConfig"); + regdelete (NULL, L"ConfigurationCache"); + regdelete (NULL, L"DirectDraw_Secondary"); + regdelete (NULL, L"ShownsupportedModes"); } int path_type; static INT_PTR CALLBACK PathsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - const GUID pathsguid = { 0x5674338c, 0x7a0b, 0x4565, { 0xbf, 0x75, 0x62, 0x8c, 0x80, 0x4a, 0xef, 0xf7 } }; - void create_afnewdir(int); - static int recursive; - static int ptypes[3], numtypes; - int val, selpath = 0; - TCHAR tmp[MAX_DPATH], pathmode[32]; + const GUID pathsguid = { 0x5674338c, 0x7a0b, 0x4565, { 0xbf, 0x75, 0x62, 0x8c, 0x80, 0x4a, 0xef, 0xf7 } }; + void create_afnewdir(int); + static int recursive; + static int ptypes[3], numtypes; + int val, selpath = 0; + TCHAR tmp[MAX_DPATH], pathmode[32]; - switch (msg) - { + switch (msg) + { case WM_INITDIALOG: - recursive++; - pages[PATHS_ID] = hDlg; - setac (hDlg, IDC_PATHS_ROM); - setac (hDlg, IDC_PATHS_CONFIG); - setac (hDlg, IDC_PATHS_SCREENSHOT); - setac (hDlg, IDC_PATHS_SAVESTATE); - setac (hDlg, IDC_PATHS_SAVEIMAGE); - setac (hDlg, IDC_PATHS_AVIOUTPUT); - setac (hDlg, IDC_PATHS_RIP); - CheckDlgButton(hDlg, IDC_PATHS_CONFIGCACHE, configurationcache); - currentpage = PATHS_ID; - ShowWindow (GetDlgItem (hDlg, IDC_RESETREGISTRY), FALSE); - numtypes = 0; - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_RESETCONTENT, 0, 0L); - if (af_path_2005 & 1) { - WIN32GUI_LoadUIString (IDS_DEFAULT_AF2005, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (path_type == PATH_TYPE_NEWAF) - selpath = numtypes; - ptypes[numtypes++] = PATH_TYPE_NEWAF; - } - if (start_path_new1[0]) { - WIN32GUI_LoadUIString (IDS_DEFAULT_NEWWINUAE, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (path_type == PATH_TYPE_NEWWINUAE) - selpath = numtypes; - ptypes[numtypes++] = PATH_TYPE_NEWWINUAE; - } - if (af_path_2005 & 2) { - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)L"AmigaForeverData"); - if (path_type == PATH_TYPE_AMIGAFOREVERDATA) - selpath = numtypes; - ptypes[numtypes++] = PATH_TYPE_AMIGAFOREVERDATA; - } - if (af_path_old) { - WIN32GUI_LoadUIString (IDS_DEFAULT_AF, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (path_type == PATH_TYPE_OLDAF) - selpath = numtypes; - ptypes[numtypes++] = PATH_TYPE_OLDAF; - } - WIN32GUI_LoadUIString (IDS_DEFAULT_WINUAE, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (path_type == 0) - selpath = numtypes; - ptypes[numtypes++] = 0; - SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_SETCURSEL, selpath, 0); - EnableWindow (GetDlgItem (hDlg, IDC_PATHS_DEFAULTTYPE), numtypes > 0 ? TRUE : FALSE); - values_to_pathsdialog (hDlg); - recursive--; - return TRUE; + recursive++; + pages[PATHS_ID] = hDlg; + setac (hDlg, IDC_PATHS_ROM); + setac (hDlg, IDC_PATHS_CONFIG); + setac (hDlg, IDC_PATHS_SCREENSHOT); + setac (hDlg, IDC_PATHS_SAVESTATE); + setac (hDlg, IDC_PATHS_SAVEIMAGE); + setac (hDlg, IDC_PATHS_AVIOUTPUT); + setac (hDlg, IDC_PATHS_RIP); + CheckDlgButton(hDlg, IDC_PATHS_CONFIGCACHE, configurationcache); + currentpage = PATHS_ID; + ShowWindow (GetDlgItem (hDlg, IDC_RESETREGISTRY), FALSE); + numtypes = 0; + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_RESETCONTENT, 0, 0L); + if (af_path_2005 & 1) { + WIN32GUI_LoadUIString (IDS_DEFAULT_AF2005, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (path_type == PATH_TYPE_NEWAF) + selpath = numtypes; + ptypes[numtypes++] = PATH_TYPE_NEWAF; + } + if (start_path_new1[0]) { + WIN32GUI_LoadUIString (IDS_DEFAULT_NEWWINUAE, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (path_type == PATH_TYPE_NEWWINUAE) + selpath = numtypes; + ptypes[numtypes++] = PATH_TYPE_NEWWINUAE; + } + if (af_path_2005 & 2) { + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)L"AmigaForeverData"); + if (path_type == PATH_TYPE_AMIGAFOREVERDATA) + selpath = numtypes; + ptypes[numtypes++] = PATH_TYPE_AMIGAFOREVERDATA; + } + if (af_path_old) { + WIN32GUI_LoadUIString (IDS_DEFAULT_AF, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (path_type == PATH_TYPE_OLDAF) + selpath = numtypes; + ptypes[numtypes++] = PATH_TYPE_OLDAF; + } + WIN32GUI_LoadUIString (IDS_DEFAULT_WINUAE, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (path_type == 0) + selpath = numtypes; + ptypes[numtypes++] = 0; + SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_SETCURSEL, selpath, 0); + EnableWindow (GetDlgItem (hDlg, IDC_PATHS_DEFAULTTYPE), numtypes > 0 ? TRUE : FALSE); + values_to_pathsdialog (hDlg); + recursive--; + return TRUE; case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - switch (LOWORD (wParam)) - { - case IDC_PATHS_ROMS: - fetch_path (L"KickstartPath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - load_keyring (&workprefs, NULL); - set_path (L"KickstartPath", tmp); - if (!scan_roms (1)) - gui_message_id (IDS_ROMSCANNOROMS); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_ROM: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_ROM), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"KickstartPath", tmp); - break; - case IDC_PATHS_CONFIGS: - fetch_path (L"ConfigurationPath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"ConfigurationPath", tmp); - values_to_pathsdialog (hDlg); - FreeConfigStore (); - } - break; - case IDC_PATHS_CONFIG: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_CONFIG), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"ConfigurationPath", tmp); - FreeConfigStore (); - break; - case IDC_PATHS_SCREENSHOTS: - fetch_path (L"ScreenshotPath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"ScreenshotPath", tmp); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_SCREENSHOT: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SCREENSHOT), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"ScreenshotPath", tmp); - break; - case IDC_PATHS_SAVESTATES: - fetch_path (L"StatefilePath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"StatefilePath", tmp); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_SAVESTATE: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVESTATE), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"StatefilePath", tmp); - break; - case IDC_PATHS_SAVEIMAGES: - fetch_path (L"SaveimagePath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"SaveimagePath", tmp); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_SAVEIMAGE: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVEIMAGE), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"SaveimagePath", tmp); - break; - case IDC_PATHS_AVIOUTPUTS: - fetch_path (L"VideoPath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"VideoPath", tmp); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_RIPS: - fetch_path (L"RipperPath", tmp, sizeof (tmp) / sizeof (TCHAR)); - if (DirectorySelection (hDlg, &pathsguid, tmp)) { - set_path (L"RipperPath", tmp); - values_to_pathsdialog (hDlg); - } - break; - case IDC_PATHS_AVIOUTPUT: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_AVIOUTPUT), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"VideoPath", tmp); - break; - case IDC_PATHS_RIP: - GetWindowText (GetDlgItem (hDlg, IDC_PATHS_RIP), tmp, sizeof (tmp) / sizeof (TCHAR)); - set_path (L"RipperPath", tmp); - break; - case IDC_PATHS_DEFAULT: - val = SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_GETCURSEL, 0, 0L); - if (val != CB_ERR && val >= 0 && val < numtypes) { - val = ptypes[val]; - if (val == PATH_TYPE_WINUAE) { - _tcscpy (start_path_data, start_path_exe); - path_type = PATH_TYPE_WINUAE; - _tcscpy (pathmode, L"WinUAE"); - } else if (val == PATH_TYPE_NEWWINUAE && start_path_new1[0]) { - _tcscpy (start_path_data, start_path_new1); - path_type = PATH_TYPE_NEWWINUAE; - create_afnewdir(0); - _tcscpy (pathmode, L"WinUAE_2"); - } else if (val == PATH_TYPE_OLDAF && start_path_af[0]) { - _tcscpy (start_path_data, start_path_af); - _tcscpy (pathmode, L"AF"); - path_type = PATH_TYPE_OLDAF; - } else if (val == PATH_TYPE_NEWAF && start_path_new1[0]) { - _tcscpy (pathmode, L"AF2005"); - path_type = PATH_TYPE_NEWAF; - create_afnewdir(0); - _tcscpy (start_path_data, start_path_new1); - } else if (val == PATH_TYPE_AMIGAFOREVERDATA && start_path_new2[0]) { - _tcscpy (pathmode, L"AMIGAFOREVERDATA"); - path_type = PATH_TYPE_AMIGAFOREVERDATA; - _tcscpy (start_path_data, start_path_new1); - } - SetCurrentDirectory (start_path_data); - regsetstr (NULL, L"PathMode", pathmode); - set_path (L"KickstartPath", NULL); - set_path (L"ConfigurationPath", NULL); - set_path (L"ScreenshotPath", NULL); - set_path (L"StatefilePath", NULL); - set_path (L"SaveimagePath", NULL); - set_path (L"VideoPath", NULL); - set_path (L"RipperPath", NULL); - values_to_pathsdialog (hDlg); - FreeConfigStore (); - } - break; - case IDC_ROM_RESCAN: - scan_roms (1); - break; - case IDC_RESETREGISTRY: - resetregistry (); - break; - case IDC_RESETDISKHISTORY: - reset_disk_history (); - break; - case IDC_PATHS_CONFIGCACHE: - configurationcache = IsDlgButtonChecked (hDlg, IDC_PATHS_CONFIGCACHE) ? 1 : 0; - regsetint (NULL, L"ConfigurationCache", configurationcache); - break; + if (recursive > 0) + break; + recursive++; + switch (LOWORD (wParam)) + { + case IDC_PATHS_ROMS: + fetch_path (L"KickstartPath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + load_keyring (&workprefs, NULL); + set_path (L"KickstartPath", tmp); + if (!scan_roms (1)) + gui_message_id (IDS_ROMSCANNOROMS); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_ROM: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_ROM), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"KickstartPath", tmp); + break; + case IDC_PATHS_CONFIGS: + fetch_path (L"ConfigurationPath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"ConfigurationPath", tmp); + values_to_pathsdialog (hDlg); + FreeConfigStore (); + } + break; + case IDC_PATHS_CONFIG: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_CONFIG), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"ConfigurationPath", tmp); + FreeConfigStore (); + break; + case IDC_PATHS_SCREENSHOTS: + fetch_path (L"ScreenshotPath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"ScreenshotPath", tmp); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_SCREENSHOT: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SCREENSHOT), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"ScreenshotPath", tmp); + break; + case IDC_PATHS_SAVESTATES: + fetch_path (L"StatefilePath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"StatefilePath", tmp); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_SAVESTATE: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVESTATE), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"StatefilePath", tmp); + break; + case IDC_PATHS_SAVEIMAGES: + fetch_path (L"SaveimagePath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"SaveimagePath", tmp); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_SAVEIMAGE: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_SAVEIMAGE), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"SaveimagePath", tmp); + break; + case IDC_PATHS_AVIOUTPUTS: + fetch_path (L"VideoPath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"VideoPath", tmp); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_RIPS: + fetch_path (L"RipperPath", tmp, sizeof (tmp) / sizeof (TCHAR)); + if (DirectorySelection (hDlg, &pathsguid, tmp)) { + set_path (L"RipperPath", tmp); + values_to_pathsdialog (hDlg); + } + break; + case IDC_PATHS_AVIOUTPUT: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_AVIOUTPUT), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"VideoPath", tmp); + break; + case IDC_PATHS_RIP: + GetWindowText (GetDlgItem (hDlg, IDC_PATHS_RIP), tmp, sizeof (tmp) / sizeof (TCHAR)); + set_path (L"RipperPath", tmp); + break; + case IDC_PATHS_DEFAULT: + val = SendDlgItemMessage (hDlg, IDC_PATHS_DEFAULTTYPE, CB_GETCURSEL, 0, 0L); + if (val != CB_ERR && val >= 0 && val < numtypes) { + val = ptypes[val]; + if (val == PATH_TYPE_WINUAE) { + _tcscpy (start_path_data, start_path_exe); + path_type = PATH_TYPE_WINUAE; + _tcscpy (pathmode, L"WinUAE"); + } else if (val == PATH_TYPE_NEWWINUAE && start_path_new1[0]) { + _tcscpy (start_path_data, start_path_new1); + path_type = PATH_TYPE_NEWWINUAE; + create_afnewdir(0); + _tcscpy (pathmode, L"WinUAE_2"); + } else if (val == PATH_TYPE_OLDAF && start_path_af[0]) { + _tcscpy (start_path_data, start_path_af); + _tcscpy (pathmode, L"AF"); + path_type = PATH_TYPE_OLDAF; + } else if (val == PATH_TYPE_NEWAF && start_path_new1[0]) { + _tcscpy (pathmode, L"AF2005"); + path_type = PATH_TYPE_NEWAF; + create_afnewdir(0); + _tcscpy (start_path_data, start_path_new1); + } else if (val == PATH_TYPE_AMIGAFOREVERDATA && start_path_new2[0]) { + _tcscpy (pathmode, L"AMIGAFOREVERDATA"); + path_type = PATH_TYPE_AMIGAFOREVERDATA; + _tcscpy (start_path_data, start_path_new1); + } + SetCurrentDirectory (start_path_data); + regsetstr (NULL, L"PathMode", pathmode); + set_path (L"KickstartPath", NULL); + set_path (L"ConfigurationPath", NULL); + set_path (L"ScreenshotPath", NULL); + set_path (L"StatefilePath", NULL); + set_path (L"SaveimagePath", NULL); + set_path (L"VideoPath", NULL); + set_path (L"RipperPath", NULL); + values_to_pathsdialog (hDlg); + FreeConfigStore (); + } + break; + case IDC_ROM_RESCAN: + scan_roms (1); + break; + case IDC_RESETREGISTRY: + resetregistry (); + break; + case IDC_RESETDISKHISTORY: + reset_disk_history (); + break; + case IDC_PATHS_CONFIGCACHE: + configurationcache = IsDlgButtonChecked (hDlg, IDC_PATHS_CONFIGCACHE) ? 1 : 0; + regsetint (NULL, L"ConfigurationCache", configurationcache); + break; + } + recursive--; } - recursive--; - } - return FALSE; + return FALSE; } struct amigamodels { - int compalevels; - int id; + int compalevels; + int id; }; static struct amigamodels amodels[] = { - { 4, IDS_QS_MODEL_A500 }, // "Amiga 500" - { 4, IDS_QS_MODEL_A500P }, // "Amiga 500+" - { 4, IDS_QS_MODEL_A600 }, // "Amiga 600" - { 4, IDS_QS_MODEL_A1000 }, // "Amiga 1000" - { 3, IDS_QS_MODEL_A1200 }, // "Amiga 1200" - { 1, IDS_QS_MODEL_A3000 }, // "Amiga 3000" - { 1, IDS_QS_MODEL_A4000 }, // "Amiga 4000" - { 0, }, //{ 1, IDS_QS_MODEL_A4000T }, // "Amiga 4000T" - { 3, IDS_QS_MODEL_CD32 }, // "CD32" - { 4, IDS_QS_MODEL_CDTV }, // "CDTV" - { 4, IDS_QS_MODEL_ARCADIA }, // "Arcadia" - { 1, IDS_QS_MODEL_UAE }, // "Expanded UAE example configuration" - { -1 } + { 4, IDS_QS_MODEL_A500 }, // "Amiga 500" + { 4, IDS_QS_MODEL_A500P }, // "Amiga 500+" + { 4, IDS_QS_MODEL_A600 }, // "Amiga 600" + { 4, IDS_QS_MODEL_A1000 }, // "Amiga 1000" + { 3, IDS_QS_MODEL_A1200 }, // "Amiga 1200" + { 1, IDS_QS_MODEL_A3000 }, // "Amiga 3000" + { 1, IDS_QS_MODEL_A4000 }, // "Amiga 4000" + { 0, }, //{ 1, IDS_QS_MODEL_A4000T }, // "Amiga 4000T" + { 3, IDS_QS_MODEL_CD32 }, // "CD32" + { 4, IDS_QS_MODEL_CDTV }, // "CDTV" + { 4, IDS_QS_MODEL_ARCADIA }, // "Arcadia" + { 1, IDS_QS_MODEL_UAE }, // "Expanded UAE example configuration" + { -1 } }; static DWORD quickstart_model = 0, quickstart_conf = 0, quickstart_compa = 1, quickstart_floppy = 1; @@ -4056,221 +4056,221 @@ static void addfloppyhistory (HWND hDlg); static void enable_for_quickstart (HWND hDlg) { - int v = quickstart_ok && quickstart_ok_floppy ? TRUE : FALSE; - ew (guiDlg, IDC_RESETAMIGA, !full_property_sheet ? TRUE : FALSE); - ShowWindow (GetDlgItem (hDlg, IDC_QUICKSTART_SETCONFIG), quickstart ? SW_HIDE : SW_SHOW); + int v = quickstart_ok && quickstart_ok_floppy ? TRUE : FALSE; + ew (guiDlg, IDC_RESETAMIGA, !full_property_sheet ? TRUE : FALSE); + ShowWindow (GetDlgItem (hDlg, IDC_QUICKSTART_SETCONFIG), quickstart ? SW_HIDE : SW_SHOW); } static void load_quickstart (HWND hDlg, int romcheck) { - ew (guiDlg, IDC_RESETAMIGA, FALSE); - workprefs.nr_floppies = quickstart_floppy; - quickstart_ok = built_in_prefs (&workprefs, quickstart_model, quickstart_conf, quickstart_compa, romcheck); - enable_for_quickstart (hDlg); - addfloppytype (hDlg, 0); - addfloppytype (hDlg, 1); - addfloppyhistory (hDlg); - config_filename[0] = 0; - setguititle (NULL); + ew (guiDlg, IDC_RESETAMIGA, FALSE); + workprefs.nr_floppies = quickstart_floppy; + quickstart_ok = built_in_prefs (&workprefs, quickstart_model, quickstart_conf, quickstart_compa, romcheck); + enable_for_quickstart (hDlg); + addfloppytype (hDlg, 0); + addfloppytype (hDlg, 1); + addfloppyhistory (hDlg); + config_filename[0] = 0; + setguititle (NULL); } static void quickstarthost (HWND hDlg, TCHAR *name) { - int type = CONFIG_TYPE_HOST; - TCHAR tmp[MAX_DPATH]; + int type = CONFIG_TYPE_HOST; + TCHAR tmp[MAX_DPATH]; - if (getconfigstorefrompath (name, tmp, CONFIG_TYPE_HOST)) { - if (cfgfile_load (&workprefs, tmp, &type, 1, 0)) - workprefs.start_gui = 1; - } + if (getconfigstorefrompath (name, tmp, CONFIG_TYPE_HOST)) { + if (cfgfile_load (&workprefs, tmp, &type, 1, 0)) + workprefs.start_gui = 1; + } } static void init_quickstartdlg_tooltip (HWND hDlg, TCHAR *tt) { - TOOLINFO ti; + TOOLINFO ti; - ti.cbSize = sizeof (TOOLINFO); - ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; - ti.hwnd = hDlg; - ti.hinst = hInst; - ti.uId = (UINT_PTR)GetDlgItem (hDlg, IDC_QUICKSTART_CONFIGURATION); - ti.lpszText = tt; - SendMessage (ToolTipHWND, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); - if (!tt) - return; - SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + ti.cbSize = sizeof (TOOLINFO); + ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; + ti.hwnd = hDlg; + ti.hinst = hInst; + ti.uId = (UINT_PTR)GetDlgItem (hDlg, IDC_QUICKSTART_CONFIGURATION); + ti.lpszText = tt; + SendMessage (ToolTipHWND, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + if (!tt) + return; + SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } static void init_quickstartdlg (HWND hDlg) { - static int firsttime; - int i, j, idx, idx2, qssize; - TCHAR tmp1[2 * MAX_DPATH], tmp2[MAX_DPATH], hostconf[MAX_DPATH]; - TCHAR *p1, *p2; - - qssize = sizeof (tmp1) / sizeof (TCHAR); - regquerystr (NULL, L"QuickStartHostConfig", hostconf, &qssize); - if (firsttime == 0 && workprefs.start_gui) { - regqueryint (NULL, L"QuickStartModel", &quickstart_model); - regqueryint (NULL, L"QuickStartConfiguration", &quickstart_conf); - regqueryint (NULL, L"QuickStartCompatibility", &quickstart_compa); - regqueryint (NULL, L"QuickStartFloppies", &quickstart_floppy); - if (quickstart) { - workprefs.df[0][0] = 0; - workprefs.df[1][0] = 0; - workprefs.df[2][0] = 0; - workprefs.df[3][0] = 0; - load_quickstart (hDlg, 1); - quickstarthost (hDlg, hostconf); - } - } - firsttime = 1; - - CheckDlgButton (hDlg, IDC_QUICKSTARTMODE, quickstart); - - WIN32GUI_LoadUIString (IDS_QS_MODELS, tmp1, sizeof (tmp1) / sizeof (TCHAR)); - _tcscat (tmp1, L"\n"); - p1 = tmp1; - SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_RESETCONTENT, 0, 0L); - idx = idx2 = 0; - i = 0; - while (amodels[i].compalevels >= 0) { - if (amodels[i].compalevels > 0) { - p2 = _tcschr (p1, '\n'); - if (p2 && _tcslen (p2) > 0) { - *p2++ = 0; - SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_ADDSTRING, 0, (LPARAM)p1); + static int firsttime; + int i, j, idx, idx2, qssize; + TCHAR tmp1[2 * MAX_DPATH], tmp2[MAX_DPATH], hostconf[MAX_DPATH]; + TCHAR *p1, *p2; + + qssize = sizeof (tmp1) / sizeof (TCHAR); + regquerystr (NULL, L"QuickStartHostConfig", hostconf, &qssize); + if (firsttime == 0 && workprefs.start_gui) { + regqueryint (NULL, L"QuickStartModel", &quickstart_model); + regqueryint (NULL, L"QuickStartConfiguration", &quickstart_conf); + regqueryint (NULL, L"QuickStartCompatibility", &quickstart_compa); + regqueryint (NULL, L"QuickStartFloppies", &quickstart_floppy); + if (quickstart) { + workprefs.df[0][0] = 0; + workprefs.df[1][0] = 0; + workprefs.df[2][0] = 0; + workprefs.df[3][0] = 0; + load_quickstart (hDlg, 1); + quickstarthost (hDlg, hostconf); + } + } + firsttime = 1; + + CheckDlgButton (hDlg, IDC_QUICKSTARTMODE, quickstart); + + WIN32GUI_LoadUIString (IDS_QS_MODELS, tmp1, sizeof (tmp1) / sizeof (TCHAR)); + _tcscat (tmp1, L"\n"); + p1 = tmp1; + SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_RESETCONTENT, 0, 0L); + idx = idx2 = 0; + i = 0; + while (amodels[i].compalevels >= 0) { + if (amodels[i].compalevels > 0) { + p2 = _tcschr (p1, '\n'); + if (p2 && _tcslen (p2) > 0) { + *p2++ = 0; + SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_ADDSTRING, 0, (LPARAM)p1); + p1 = p2; + } + if (i == quickstart_model) + idx2 = idx; + idx++; + } + i++; + } + SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_SETCURSEL, idx2, 0); + + WIN32GUI_LoadUIString (amodels[quickstart_model].id, tmp1, sizeof (tmp1) / sizeof (TCHAR)); + _tcscat (tmp1, L"\n"); + p1 = tmp1; + init_quickstartdlg_tooltip (hDlg, 0); + SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_RESETCONTENT, 0, 0L); + i = 0; + for (;;) { + p2 = _tcschr (p1, '\n'); + if (!p2) + break; + *p2++= 0; + SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_ADDSTRING, 0, (LPARAM)p1); + p1 = p2; + p2 = _tcschr (p1, '\n'); + if (!p2) + break; + *p2++= 0; + if (quickstart_conf == i && _tcslen (p1) > 0) + init_quickstartdlg_tooltip (hDlg, p1); p1 = p2; - } - if (i == quickstart_model) - idx2 = idx; - idx++; - } - i++; - } - SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_SETCURSEL, idx2, 0); - - WIN32GUI_LoadUIString (amodels[quickstart_model].id, tmp1, sizeof (tmp1) / sizeof (TCHAR)); - _tcscat (tmp1, L"\n"); - p1 = tmp1; - init_quickstartdlg_tooltip (hDlg, 0); - SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_RESETCONTENT, 0, 0L); - i = 0; - for (;;) { - p2 = _tcschr (p1, '\n'); - if (!p2) - break; - *p2++= 0; - SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_ADDSTRING, 0, (LPARAM)p1); - p1 = p2; - p2 = _tcschr (p1, '\n'); - if (!p2) - break; - *p2++= 0; - if (quickstart_conf == i && _tcslen (p1) > 0) - init_quickstartdlg_tooltip (hDlg, p1); - p1 = p2; - i++; - } - if (quickstart_conf >= i) - quickstart_conf = 0; - SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_SETCURSEL, quickstart_conf, 0); - - if (quickstart_compa >= amodels[quickstart_model].compalevels) - quickstart_compa = 1; - if (quickstart_compa >= amodels[quickstart_model].compalevels) - quickstart_compa = 0; - i = amodels[quickstart_model].compalevels; - ew (hDlg, IDC_QUICKSTART_COMPATIBILITY, i > 1); - SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETRANGE, TRUE, MAKELONG (0, i > 1 ? i - 1 : 1)); - SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage( hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPOS, TRUE, quickstart_compa); - - SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_DEFAULT_HOST, tmp1, sizeof (tmp1) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp1); - idx = 0; - j = 1; - for (i = 0; i < configstoresize; i++) { - if (configstore[i]->Type == CONFIG_TYPE_HOST) { - _tcscpy (tmp2, configstore[i]->Path); - _tcsncat (tmp2, configstore[i]->Name, MAX_DPATH); - if (!_tcscmp (tmp2, hostconf)) - idx = j; - SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp2); - j++; - } - } - SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_SETCURSEL, idx, 0); - regsetint (NULL, L"QuickStartModel", quickstart_model); - regsetint (NULL, L"QuickStartConfiguration", quickstart_conf); - regsetint (NULL, L"QuickStartCompatibility", quickstart_compa); + i++; + } + if (quickstart_conf >= i) + quickstart_conf = 0; + SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_SETCURSEL, quickstart_conf, 0); + + if (quickstart_compa >= amodels[quickstart_model].compalevels) + quickstart_compa = 1; + if (quickstart_compa >= amodels[quickstart_model].compalevels) + quickstart_compa = 0; + i = amodels[quickstart_model].compalevels; + ew (hDlg, IDC_QUICKSTART_COMPATIBILITY, i > 1); + SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETRANGE, TRUE, MAKELONG (0, i > 1 ? i - 1 : 1)); + SendDlgItemMessage (hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage( hDlg, IDC_QUICKSTART_COMPATIBILITY, TBM_SETPOS, TRUE, quickstart_compa); + + SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_DEFAULT_HOST, tmp1, sizeof (tmp1) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp1); + idx = 0; + j = 1; + for (i = 0; i < configstoresize; i++) { + if (configstore[i]->Type == CONFIG_TYPE_HOST) { + _tcscpy (tmp2, configstore[i]->Path); + _tcsncat (tmp2, configstore[i]->Name, MAX_DPATH); + if (!_tcscmp (tmp2, hostconf)) + idx = j; + SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_ADDSTRING, 0, (LPARAM)tmp2); + j++; + } + } + SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_SETCURSEL, idx, 0); + regsetint (NULL, L"QuickStartModel", quickstart_model); + regsetint (NULL, L"QuickStartConfiguration", quickstart_conf); + regsetint (NULL, L"QuickStartCompatibility", quickstart_compa); } static void floppytooltip (HWND hDlg, int num, uae_u32 crc32); static void testimage (HWND hDlg, int num) { - int ret; - int reload = 0; - uae_u32 crc32; - int messageid = -1; - TCHAR tmp[MAX_DPATH]; - - floppytooltip (hDlg, num, 0); - quickstart_ok_floppy = 0; - if (workprefs.dfxtype[0] < 0) { - quickstart_ok_floppy = 1; - return; - } - if (!workprefs.df[num][0]) - return; - ret = DISK_examine_image (&workprefs, num, &crc32); - if (!ret) - return; - floppytooltip (hDlg, num, crc32); - if (num > 0) - return; - if (!full_property_sheet) - return; - switch (ret) - { + int ret; + int reload = 0; + uae_u32 crc32; + int messageid = -1; + TCHAR tmp[MAX_DPATH]; + + floppytooltip (hDlg, num, 0); + quickstart_ok_floppy = 0; + if (workprefs.dfxtype[0] < 0) { + quickstart_ok_floppy = 1; + return; + } + if (!workprefs.df[num][0]) + return; + ret = DISK_examine_image (&workprefs, num, &crc32); + if (!ret) + return; + floppytooltip (hDlg, num, crc32); + if (num > 0) + return; + if (!full_property_sheet) + return; + switch (ret) + { case 10: - quickstart_ok_floppy = 1; - break; + quickstart_ok_floppy = 1; + break; case 11: - quickstart_ok_floppy = 1; - if (quickstart_model != 1 && quickstart_model != 2 && quickstart_model != 4) { - quickstart_model = 4; - messageid = IDS_IMGCHK_KS2; - reload = 1; - } - break; + quickstart_ok_floppy = 1; + if (quickstart_model != 1 && quickstart_model != 2 && quickstart_model != 4) { + quickstart_model = 4; + messageid = IDS_IMGCHK_KS2; + reload = 1; + } + break; case 12: - quickstart_ok_floppy = 1; - if (quickstart_model != 4) { - quickstart_model = 4; - messageid = IDS_IMGCHK_KS3; - reload = 1; - } - break; + quickstart_ok_floppy = 1; + if (quickstart_model != 4) { + quickstart_model = 4; + messageid = IDS_IMGCHK_KS3; + reload = 1; + } + break; case 4: - messageid = IDS_IMGCHK_BOOTBLOCKNO; - break; + messageid = IDS_IMGCHK_BOOTBLOCKNO; + break; case 3: - messageid = IDS_IMGCHK_BOOTBLOCKCRCERROR; - break; + messageid = IDS_IMGCHK_BOOTBLOCKCRCERROR; + break; case 2: - messageid = IDS_IMGCHK_DAMAGED; - break; - } - if (messageid > 0) { - WIN32GUI_LoadUIString (messageid, tmp, sizeof (tmp) / sizeof (TCHAR)); - gui_message (tmp); - } - if (reload && quickstart) { - load_quickstart (hDlg, 1); - init_quickstartdlg (hDlg); - } + messageid = IDS_IMGCHK_DAMAGED; + break; + } + if (messageid > 0) { + WIN32GUI_LoadUIString (messageid, tmp, sizeof (tmp) / sizeof (TCHAR)); + gui_message (tmp); + } + if (reload && quickstart) { + load_quickstart (hDlg, 1); + init_quickstartdlg (hDlg); + } } static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); @@ -4278,338 +4278,338 @@ static int diskselectmenu (HWND hDlg, WPARAM wParam); static INT_PTR CALLBACK QuickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive; - int ret = FALSE, i; - TCHAR tmp[MAX_DPATH]; - static TCHAR df0[MAX_DPATH]; - static TCHAR df1[MAX_DPATH]; - static int dfxtype[2] = { -1, -1 }; - static int doinit; - LRESULT val; - - switch(msg) - { - case WM_INITDIALOG: + static int recursive; + int ret = FALSE, i; + TCHAR tmp[MAX_DPATH]; + static TCHAR df0[MAX_DPATH]; + static TCHAR df1[MAX_DPATH]; + static int dfxtype[2] = { -1, -1 }; + static int doinit; + LRESULT val; + + switch(msg) { - int ids[] = { IDC_DF0TEXTQ, IDC_DF1TEXTQ, -1 }; - pages[QUICKSTART_ID] = hDlg; - currentpage = QUICKSTART_ID; - enable_for_quickstart (hDlg); - _tcscpy (df0, workprefs.df[0]); - _tcscpy (df1, workprefs.df[1]); - setmultiautocomplete (hDlg, ids); - doinit = 1; - break; - } + case WM_INITDIALOG: + { + int ids[] = { IDC_DF0TEXTQ, IDC_DF1TEXTQ, -1 }; + pages[QUICKSTART_ID] = hDlg; + currentpage = QUICKSTART_ID; + enable_for_quickstart (hDlg); + _tcscpy (df0, workprefs.df[0]); + _tcscpy (df1, workprefs.df[1]); + setmultiautocomplete (hDlg, ids); + doinit = 1; + break; + } case WM_NULL: - if (recursive > 0) + if (recursive > 0) + break; + recursive++; + if (doinit) { + addfloppytype (hDlg, 0); + addfloppytype (hDlg, 1); + addfloppyhistory (hDlg); + init_quickstartdlg (hDlg); + } + doinit = 0; + recursive--; break; - recursive++; - if (doinit) { - addfloppytype (hDlg, 0); - addfloppytype (hDlg, 1); - addfloppyhistory (hDlg); - init_quickstartdlg (hDlg); - } - doinit = 0; - recursive--; - break; case WM_CONTEXTMENU: - diskselectmenu (hDlg, wParam); - break; + diskselectmenu (hDlg, wParam); + break; case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { - switch (LOWORD (wParam)) - { - case IDC_QUICKSTART_MODEL: - val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_GETCURSEL, 0, 0L); - if (val != CB_ERR) { - i = 0; - while (amodels[i].compalevels >= 0) { - if (amodels[i].compalevels > 0) - val--; - if (val < 0) - break; - i++; - } - if (i != quickstart_model) { - quickstart_model = i; - init_quickstartdlg (hDlg); - if (quickstart) - load_quickstart (hDlg, 1); - if (quickstart && !full_property_sheet) - qs_request_reset = 2; - } - } - break; - case IDC_QUICKSTART_CONFIGURATION: - val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_GETCURSEL, 0, 0L); - if (val != CB_ERR && val != quickstart_conf) { - quickstart_conf = val; - init_quickstartdlg (hDlg); - if (quickstart) - load_quickstart (hDlg, 1); - if (quickstart && !full_property_sheet) - qs_request_reset = 2; + if (recursive > 0) + break; + recursive++; + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + switch (LOWORD (wParam)) + { + case IDC_QUICKSTART_MODEL: + val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_MODEL, CB_GETCURSEL, 0, 0L); + if (val != CB_ERR) { + i = 0; + while (amodels[i].compalevels >= 0) { + if (amodels[i].compalevels > 0) + val--; + if (val < 0) + break; + i++; + } + if (i != quickstart_model) { + quickstart_model = i; + init_quickstartdlg (hDlg); + if (quickstart) + load_quickstart (hDlg, 1); + if (quickstart && !full_property_sheet) + qs_request_reset = 2; + } + } + break; + case IDC_QUICKSTART_CONFIGURATION: + val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_CONFIGURATION, CB_GETCURSEL, 0, 0L); + if (val != CB_ERR && val != quickstart_conf) { + quickstart_conf = val; + init_quickstartdlg (hDlg); + if (quickstart) + load_quickstart (hDlg, 1); + if (quickstart && !full_property_sheet) + qs_request_reset = 2; + } + break; + case IDC_QUICKSTART_HOSTCONFIG: + val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETCURSEL, 0, 0); + if (val != CB_ERR) { + SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); + regsetstr (NULL, L"QuickStartHostConfig", tmp); + quickstarthost (hDlg, tmp); + if (val == 0 && quickstart) + load_quickstart (hDlg, 0); + } + break; + } + } else { + switch (LOWORD (wParam)) + { + case IDC_QUICKSTARTMODE: + quickstart = IsDlgButtonChecked (hDlg, IDC_QUICKSTARTMODE); + regsetint (NULL, L"QuickStartMode", quickstart); + if (quickstart) { + init_quickstartdlg (hDlg); + load_quickstart (hDlg, 0); + } + enable_for_quickstart (hDlg); + break; + } } - break; - case IDC_QUICKSTART_HOSTCONFIG: - val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETCURSEL, 0, 0); - if (val != CB_ERR) { - SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); - regsetstr (NULL, L"QuickStartHostConfig", tmp); - quickstarthost (hDlg, tmp); - if (val == 0 && quickstart) - load_quickstart (hDlg, 0); + switch (LOWORD (wParam)) + { + case IDC_DF0TEXTQ: + case IDC_DF0WPQ: + case IDC_EJECT0Q: + case IDC_DF0QQ: + case IDC_DF1TEXTQ: + case IDC_DF1WPQ: + case IDC_EJECT1Q: + case IDC_DF1QQ: + case IDC_DF0QENABLE: + case IDC_DF1QENABLE: + if (currentpage == QUICKSTART_ID) + ret = FloppyDlgProc (hDlg, msg, wParam, lParam); + break; + case IDC_QUICKSTART_SETCONFIG: + load_quickstart (hDlg, 1); + break; } - break; - } - } else { - switch (LOWORD (wParam)) - { - case IDC_QUICKSTARTMODE: - quickstart = IsDlgButtonChecked (hDlg, IDC_QUICKSTARTMODE); - regsetint (NULL, L"QuickStartMode", quickstart); - if (quickstart) { - init_quickstartdlg (hDlg); - load_quickstart (hDlg, 0); + recursive--; + case WM_HSCROLL: + if (recursive > 0) + break; + recursive++; + if ((HWND)lParam == GetDlgItem (hDlg, IDC_QUICKSTART_COMPATIBILITY)) { + val = SendMessage ((HWND)lParam, TBM_GETPOS, 0, 0); + if (val >= 0 && val != quickstart_compa) { + quickstart_compa = val; + init_quickstartdlg (hDlg); + if (quickstart) + load_quickstart (hDlg, 0); + } } - enable_for_quickstart (hDlg); + recursive--; break; - } - } - switch (LOWORD (wParam)) - { - case IDC_DF0TEXTQ: - case IDC_DF0WPQ: - case IDC_EJECT0Q: - case IDC_DF0QQ: - case IDC_DF1TEXTQ: - case IDC_DF1WPQ: - case IDC_EJECT1Q: - case IDC_DF1QQ: - case IDC_DF0QENABLE: - case IDC_DF1QENABLE: - if (currentpage == QUICKSTART_ID) - ret = FloppyDlgProc (hDlg, msg, wParam, lParam); - break; - case IDC_QUICKSTART_SETCONFIG: - load_quickstart (hDlg, 1); - break; - } - recursive--; - case WM_HSCROLL: - if (recursive > 0) - break; - recursive++; - if ((HWND)lParam == GetDlgItem (hDlg, IDC_QUICKSTART_COMPATIBILITY)) { - val = SendMessage ((HWND)lParam, TBM_GETPOS, 0, 0); - if (val >= 0 && val != quickstart_compa) { - quickstart_compa = val; - init_quickstartdlg (hDlg); - if (quickstart) - load_quickstart (hDlg, 0); - } - } - recursive--; - break; - } - if (recursive == 0 && quickstart) { - recursive++; - if (_tcscmp (workprefs.df[0], df0) || workprefs.dfxtype[0] != dfxtype[0]) { - _tcscpy (df0, workprefs.df[0]); - dfxtype[0] = workprefs.dfxtype[0]; - testimage (hDlg, 0); - enable_for_quickstart (hDlg); } - if (_tcscmp (workprefs.df[1], df1) || workprefs.dfxtype[1] != dfxtype[1]) { - _tcscpy (df1, workprefs.df[1]); - dfxtype[1] = workprefs.dfxtype[1]; - testimage (hDlg, 1); + if (recursive == 0 && quickstart) { + recursive++; + if (_tcscmp (workprefs.df[0], df0) || workprefs.dfxtype[0] != dfxtype[0]) { + _tcscpy (df0, workprefs.df[0]); + dfxtype[0] = workprefs.dfxtype[0]; + testimage (hDlg, 0); + enable_for_quickstart (hDlg); + } + if (_tcscmp (workprefs.df[1], df1) || workprefs.dfxtype[1] != dfxtype[1]) { + _tcscpy (df1, workprefs.df[1]); + dfxtype[1] = workprefs.dfxtype[1]; + testimage (hDlg, 1); + } + recursive--; } - recursive--; - } - return ret; + return ret; } static void init_aboutdlg (HWND hDlg) { - CHARFORMAT CharFormat; - int i; + CHARFORMAT CharFormat; + int i; - CharFormat.cbSize = sizeof (CharFormat); + CharFormat.cbSize = sizeof (CharFormat); - SetDlgItemText (hDlg, IDC_RICHEDIT1, L"WinUAE"); - SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); - CharFormat.dwMask |= CFM_BOLD | CFM_SIZE | CFM_FACE; - CharFormat.dwEffects = CFE_BOLD; - CharFormat.yHeight = 18 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ + SetDlgItemText (hDlg, IDC_RICHEDIT1, L"WinUAE"); + SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); + CharFormat.dwMask |= CFM_BOLD | CFM_SIZE | CFM_FACE; + CharFormat.dwEffects = CFE_BOLD; + CharFormat.yHeight = 18 * 20; /* height in twips, where a twip is 1/20th of a point - for a pt.size of 18 */ - _tcscpy (CharFormat.szFaceName, L"Times New Roman"); - SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); - SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE)); + _tcscpy (CharFormat.szFaceName, L"Times New Roman"); + SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); + SendDlgItemMessage (hDlg, IDC_RICHEDIT1, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE)); - SetDlgItemText (hDlg, IDC_RICHEDIT2, VersionStr ); - SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); - CharFormat.dwMask |= CFM_SIZE | CFM_FACE; - CharFormat.yHeight = 10 * 20; - _tcscpy (CharFormat.szFaceName, L"Times New Roman"); - SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); - SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE)); + SetDlgItemText (hDlg, IDC_RICHEDIT2, VersionStr ); + SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_GETCHARFORMAT, 0, (LPARAM) & CharFormat); + CharFormat.dwMask |= CFM_SIZE | CFM_FACE; + CharFormat.yHeight = 10 * 20; + _tcscpy (CharFormat.szFaceName, L"Times New Roman"); + SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & CharFormat); + SendDlgItemMessage (hDlg, IDC_RICHEDIT2, EM_SETBKGNDCOLOR, 0, GetSysColor (COLOR_3DFACE)); - for(i = 0; urls[i].id >= 0; i++) - SetupRichText(hDlg, &urls[i]); + for(i = 0; urls[i].id >= 0; i++) + SetupRichText(hDlg, &urls[i]); } static INT_PTR CALLBACK AboutDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch( msg ) - { + switch( msg ) + { case WM_INITDIALOG: - pages[ABOUT_ID] = hDlg; - currentpage = ABOUT_ID; - init_aboutdlg (hDlg); - break; + pages[ABOUT_ID] = hDlg; + currentpage = ABOUT_ID; + init_aboutdlg (hDlg); + break; case WM_COMMAND: - if (wParam == IDC_CONTRIBUTORS) - DisplayContributors (hDlg); - break; + if (wParam == IDC_CONTRIBUTORS) + DisplayContributors (hDlg); + break; case WM_SETCURSOR: - return TRUE; - break; + return TRUE; + break; case WM_LBUTTONDOWN: case WM_MOUSEMOVE: - url_handler( hDlg, msg, wParam, lParam ); - break; - } + url_handler( hDlg, msg, wParam, lParam ); + break; + } - return FALSE; + return FALSE; } static void enable_for_displaydlg (HWND hDlg) { - int rtg = ! workprefs.address_space_24; + int rtg = ! workprefs.address_space_24; #ifndef PICASSO96 - rtg = FALSE; + rtg = FALSE; #endif - ew (hDlg, IDC_SCREENMODE_RTG, rtg); - ew (hDlg, IDC_XCENTER, TRUE); - ew (hDlg, IDC_YCENTER, TRUE); - ew (hDlg, IDC_LM_SCANLINES, TRUE); - ew (hDlg, IDC_FRAMERATE2, !workprefs.gfx_avsync); - ew (hDlg, IDC_FRAMERATE, !workprefs.cpu_cycle_exact); - ew (hDlg, IDC_LORES, !workprefs.gfx_autoresolution); - ew (hDlg, IDC_LM_NORMAL, !workprefs.gfx_autoresolution); - ew (hDlg, IDC_LM_DOUBLED, !workprefs.gfx_autoresolution); - ew (hDlg, IDC_LM_SCANLINES, !workprefs.gfx_autoresolution); + ew (hDlg, IDC_SCREENMODE_RTG, rtg); + ew (hDlg, IDC_XCENTER, TRUE); + ew (hDlg, IDC_YCENTER, TRUE); + ew (hDlg, IDC_LM_SCANLINES, TRUE); + ew (hDlg, IDC_FRAMERATE2, !workprefs.gfx_avsync); + ew (hDlg, IDC_FRAMERATE, !workprefs.cpu_cycle_exact); + ew (hDlg, IDC_LORES, !workprefs.gfx_autoresolution); + ew (hDlg, IDC_LM_NORMAL, !workprefs.gfx_autoresolution); + ew (hDlg, IDC_LM_DOUBLED, !workprefs.gfx_autoresolution); + ew (hDlg, IDC_LM_SCANLINES, !workprefs.gfx_autoresolution); } static void enable_for_chipsetdlg (HWND hDlg) { - int enable = workprefs.cpu_cycle_exact ? FALSE : TRUE; + int enable = workprefs.cpu_cycle_exact ? FALSE : TRUE; #if !defined (CPUEMU_12) - ew (hDlg, IDC_CYCLEEXACT, FALSE); + ew (hDlg, IDC_CYCLEEXACT, FALSE); #endif - ew (hDlg, IDC_FASTCOPPER, enable); - ew (hDlg, IDC_GENLOCK, full_property_sheet); - ew (hDlg, IDC_BLITIMM, enable); - if (enable == FALSE) { - workprefs.immediate_blits = 0; - CheckDlgButton (hDlg, IDC_FASTCOPPER, FALSE); - CheckDlgButton (hDlg, IDC_BLITIMM, FALSE); - } - ew (hDlg, IDC_CS_EXT, workprefs.cs_compatible ? TRUE : FALSE); + ew (hDlg, IDC_FASTCOPPER, enable); + ew (hDlg, IDC_GENLOCK, full_property_sheet); + ew (hDlg, IDC_BLITIMM, enable); + if (enable == FALSE) { + workprefs.immediate_blits = 0; + CheckDlgButton (hDlg, IDC_FASTCOPPER, FALSE); + CheckDlgButton (hDlg, IDC_BLITIMM, FALSE); + } + ew (hDlg, IDC_CS_EXT, workprefs.cs_compatible ? TRUE : FALSE); } static DWORD idnth[] = { IDS_SECOND, IDS_THIRD, IDS_FOURTH, IDS_FIFTH, IDS_SIXTH, IDS_SEVENTH, IDS_EIGHTH, IDS_NINTH, IDS_TENTH, -1 }; static void LoadNthString( DWORD value, TCHAR *nth, DWORD dwNthMax ) { - nth[0] = 0; - if (value >= 1 && value <= 9) - WIN32GUI_LoadUIString(idnth[value - 1], nth, dwNthMax); + nth[0] = 0; + if (value >= 1 && value <= 9) + WIN32GUI_LoadUIString(idnth[value - 1], nth, dwNthMax); } static int fakerefreshrates[] = { 50, 60, 100, 120, 0 }; struct storedrefreshrate { - int rate, type; + int rate, type; }; static struct storedrefreshrate storedrefreshrates[MAX_REFRESH_RATES + 1]; static void init_frequency_combo (HWND hDlg, int dmode) { - int i, j, freq; - TCHAR hz[20], hz2[20], txt[100]; - LRESULT index; - struct MultiDisplay *md = getdisplay (&workprefs); - - i = 0; index = 0; - while (dmode >= 0 && (freq = md->DisplayModes[dmode].refresh[i]) > 0 && index < MAX_REFRESH_RATES) { - storedrefreshrates[index].rate = freq; - storedrefreshrates[index++].type = md->DisplayModes[dmode].refreshtype[i]; - i++; - } - i = 0; - while ((freq = fakerefreshrates[i]) > 0 && index < MAX_REFRESH_RATES) { - for (j = 0; j < index; j++) { - if (storedrefreshrates[j].rate == freq) - break; - } - if (j == index) { - storedrefreshrates[index].rate = -freq; - storedrefreshrates[index++].type = 0; - } - i++; - } - storedrefreshrates[index].rate = 0; - for (i = 0; i < index; i++) { - for (j = i + 1; j < index; j++) { - if (abs (storedrefreshrates[i].rate) >= abs (storedrefreshrates[j].rate)) { - struct storedrefreshrate srr; - memcpy (&srr, &storedrefreshrates[i], sizeof (struct storedrefreshrate)); - memcpy (&storedrefreshrates[i], &storedrefreshrates[j], sizeof (struct storedrefreshrate)); - memcpy (&storedrefreshrates[j], &srr, sizeof (struct storedrefreshrate)); - } - } - } - - hz[0] = hz2[0] = 0; - SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_VSYNC_DEFAULT, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)txt); - for (i = 0; i < index; i++) { - freq = storedrefreshrates[i].rate; - if (freq < 0) { - freq = -freq; - _stprintf (hz, L"(%dHz)", freq); - } else { - _stprintf (hz, L"%dHz", freq); - } - if (freq == 50 || freq == 100) - _tcscat (hz, L" PAL"); - if (freq == 60 || freq == 120) - _tcscat (hz, L" NTSC"); - if (storedrefreshrates[i].type) - _tcscat (hz, L" (*)"); - if (abs (workprefs.gfx_refreshrate) == freq) - _tcscpy (hz2, hz); - SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)hz); - } - index = CB_ERR; - if (hz2[0] >= 0) - index = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, 0, (LPARAM)hz2); - if (index == CB_ERR) { + int i, j, freq; + TCHAR hz[20], hz2[20], txt[100]; + LRESULT index; + struct MultiDisplay *md = getdisplay (&workprefs); + + i = 0; index = 0; + while (dmode >= 0 && (freq = md->DisplayModes[dmode].refresh[i]) > 0 && index < MAX_REFRESH_RATES) { + storedrefreshrates[index].rate = freq; + storedrefreshrates[index++].type = md->DisplayModes[dmode].refreshtype[i]; + i++; + } + i = 0; + while ((freq = fakerefreshrates[i]) > 0 && index < MAX_REFRESH_RATES) { + for (j = 0; j < index; j++) { + if (storedrefreshrates[j].rate == freq) + break; + } + if (j == index) { + storedrefreshrates[index].rate = -freq; + storedrefreshrates[index++].type = 0; + } + i++; + } + storedrefreshrates[index].rate = 0; + for (i = 0; i < index; i++) { + for (j = i + 1; j < index; j++) { + if (abs (storedrefreshrates[i].rate) >= abs (storedrefreshrates[j].rate)) { + struct storedrefreshrate srr; + memcpy (&srr, &storedrefreshrates[i], sizeof (struct storedrefreshrate)); + memcpy (&storedrefreshrates[i], &storedrefreshrates[j], sizeof (struct storedrefreshrate)); + memcpy (&storedrefreshrates[j], &srr, sizeof (struct storedrefreshrate)); + } + } + } + + hz[0] = hz2[0] = 0; + SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_RESETCONTENT, 0, 0); WIN32GUI_LoadUIString (IDS_VSYNC_DEFAULT, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, i, (LPARAM)txt); - workprefs.gfx_refreshrate = 0; - } + SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)txt); + for (i = 0; i < index; i++) { + freq = storedrefreshrates[i].rate; + if (freq < 0) { + freq = -freq; + _stprintf (hz, L"(%dHz)", freq); + } else { + _stprintf (hz, L"%dHz", freq); + } + if (freq == 50 || freq == 100) + _tcscat (hz, L" PAL"); + if (freq == 60 || freq == 120) + _tcscat (hz, L" NTSC"); + if (storedrefreshrates[i].type) + _tcscat (hz, L" (*)"); + if (abs (workprefs.gfx_refreshrate) == freq) + _tcscpy (hz2, hz); + SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_ADDSTRING, 0, (LPARAM)hz); + } + index = CB_ERR; + if (hz2[0] >= 0) + index = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, 0, (LPARAM)hz2); + if (index == CB_ERR) { + WIN32GUI_LoadUIString (IDS_VSYNC_DEFAULT, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_REFRESHRATE, CB_SELECTSTRING, i, (LPARAM)txt); + workprefs.gfx_refreshrate = 0; + } } #define MAX_FRAMERATE_LENGTH 40 @@ -4617,1836 +4617,1836 @@ static void init_frequency_combo (HWND hDlg, int dmode) static int display_mode_index (uae_u32 x, uae_u32 y, uae_u32 d) { - int i, j; - struct MultiDisplay *md = getdisplay (&workprefs); + int i, j; + struct MultiDisplay *md = getdisplay (&workprefs); - j = 0; - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - if (md->DisplayModes[i].res.width == x && - md->DisplayModes[i].res.height == y && - md->DisplayModes[i].depth == d) - break; - j++; - } - if(md->DisplayModes[i].depth < 0) - j = -1; - return j; + j = 0; + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + if (md->DisplayModes[i].res.width == x && + md->DisplayModes[i].res.height == y && + md->DisplayModes[i].depth == d) + break; + j++; + } + if(md->DisplayModes[i].depth < 0) + j = -1; + return j; } static int da_mode_selected; static int *getp_da (void) { - int *p = 0; - switch (da_mode_selected) - { + int *p = 0; + switch (da_mode_selected) + { case 0: - p = &workprefs.gfx_luminance; - break; + p = &workprefs.gfx_luminance; + break; case 1: - p = &workprefs.gfx_contrast; - break; + p = &workprefs.gfx_contrast; + break; case 2: - p = &workprefs.gfx_gamma; - break; - } - return p; + p = &workprefs.gfx_gamma; + break; + } + return p; } static void update_da(void) { - currprefs.gfx_gamma = workprefs.gfx_gamma; - currprefs.gfx_luminance = workprefs.gfx_luminance; - currprefs.gfx_contrast = workprefs.gfx_contrast; - init_colors (); - init_custom(); - updatedisplayarea (); - WIN32GFX_WindowMove (); + currprefs.gfx_gamma = workprefs.gfx_gamma; + currprefs.gfx_luminance = workprefs.gfx_luminance; + currprefs.gfx_contrast = workprefs.gfx_contrast; + init_colors (); + init_custom(); + updatedisplayarea (); + WIN32GFX_WindowMove (); } static void handle_da (HWND hDlg) { - int *p; - int v; + int *p; + int v; - p = getp_da (); - if (!p) - return; - v = SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_GETPOS, 0, 0) * 10; - if (v == *p) - return; - *p = v; - update_da(); + p = getp_da (); + if (!p) + return; + v = SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_GETPOS, 0, 0) * 10; + if (v == *p) + return; + *p = v; + update_da(); } void init_da (HWND hDlg) { - int *p; - SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Brightness"); - SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Contrast"); - SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Gamma"); - if (da_mode_selected == CB_ERR) - da_mode_selected = 0; - SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_SETCURSEL, da_mode_selected, 0); - SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG (-99, 99)); - p = getp_da (); - if (p) - SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETPOS, TRUE, (*p) / 10); + int *p; + SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Brightness"); + SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Contrast"); + SendDlgItemMessage(hDlg, IDC_DA_MODE, CB_ADDSTRING, 0, (LPARAM)L"Gamma"); + if (da_mode_selected == CB_ERR) + da_mode_selected = 0; + SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_SETCURSEL, da_mode_selected, 0); + SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG (-99, 99)); + p = getp_da (); + if (p) + SendDlgItemMessage (hDlg, IDC_DA_SLIDER, TBM_SETPOS, TRUE, (*p) / 10); } static int gui_display_depths[3]; static void init_display_mode (HWND hDlg) { - int d, d2, index; - int i, cnt; - struct MultiDisplay *md = getdisplay (&workprefs); - - switch (workprefs.color_mode) - { - case 2: - d = 16; - break; - case 5: - default: - d = 32; - break; - } - - if (workprefs.gfx_afullscreen) { - d2 = d; - if ((index = WIN32GFX_AdjustScreenmode (md, &workprefs.gfx_size_fs.width, &workprefs.gfx_size_fs.height, &d2)) >= 0) { - switch (d2) - { - case 15: - workprefs.color_mode = 1; - d = 2; - break; - case 16: - workprefs.color_mode = 2; - d = 2; - break; - case 32: - default: - workprefs.color_mode = 5; - d = 4; - break; - } - } - } else { - d = d / 8; - } - - index = display_mode_index (workprefs.gfx_size_fs.width, workprefs.gfx_size_fs.height, d); - if (index >= 0) - SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_SETCURSEL, md->DisplayModes[index].residx, 0); - else - index = 0; - SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_RESETCONTENT, 0, 0); - cnt = 0; - gui_display_depths[0] = gui_display_depths[1] = gui_display_depths[2] = -1; - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx == md->DisplayModes[index].residx) { - TCHAR tmp[64]; - _stprintf (tmp, L"%d", md->DisplayModes[i].depth * 8); - SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_ADDSTRING, 0, (LPARAM)tmp); - if (md->DisplayModes[i].depth == d) - SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_SETCURSEL, cnt, 0); - gui_display_depths[cnt] = md->DisplayModes[i].depth; - cnt++; - } - } - init_frequency_combo (hDlg, index); + int d, d2, index; + int i, cnt; + struct MultiDisplay *md = getdisplay (&workprefs); + + switch (workprefs.color_mode) + { + case 2: + d = 16; + break; + case 5: + default: + d = 32; + break; + } + + if (workprefs.gfx_afullscreen) { + d2 = d; + if ((index = WIN32GFX_AdjustScreenmode (md, &workprefs.gfx_size_fs.width, &workprefs.gfx_size_fs.height, &d2)) >= 0) { + switch (d2) + { + case 15: + workprefs.color_mode = 1; + d = 2; + break; + case 16: + workprefs.color_mode = 2; + d = 2; + break; + case 32: + default: + workprefs.color_mode = 5; + d = 4; + break; + } + } + } else { + d = d / 8; + } + + index = display_mode_index (workprefs.gfx_size_fs.width, workprefs.gfx_size_fs.height, d); + if (index >= 0) + SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_SETCURSEL, md->DisplayModes[index].residx, 0); + else + index = 0; + SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_RESETCONTENT, 0, 0); + cnt = 0; + gui_display_depths[0] = gui_display_depths[1] = gui_display_depths[2] = -1; + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx == md->DisplayModes[index].residx) { + TCHAR tmp[64]; + _stprintf (tmp, L"%d", md->DisplayModes[i].depth * 8); + SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_ADDSTRING, 0, (LPARAM)tmp); + if (md->DisplayModes[i].depth == d) + SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_SETCURSEL, cnt, 0); + gui_display_depths[cnt] = md->DisplayModes[i].depth; + cnt++; + } + } + init_frequency_combo (hDlg, index); } static int display_toselect (int fs, int vsync, int p96) { - if (p96) - return fs * 2 + (vsync ? 1 : 0); - if (fs == 2) - return 4; - if (!vsync) + if (p96) + return fs * 2 + (vsync ? 1 : 0); + if (fs == 2) + return 4; + if (!vsync) + return fs; + if (fs == 1 && vsync == 1) + return 2; + if (fs == 1 && vsync == 2) + return 3; return fs; - if (fs == 1 && vsync == 1) - return 2; - if (fs == 1 && vsync == 2) - return 3; - return fs; } static void display_fromselect (int val, int *fs, int *vsync, int p96) { - int ofs = *fs; - if (val == CB_ERR) - return; - *fs = 0; - *vsync = 0; - if (p96) { - *fs = val / 2; - *vsync = val & 1; - if (*fs == 2 && *fs != ofs) { - workprefs.win32_rtgscaleifsmall = 1; - workprefs.win32_rtgmatchdepth = 0; - } - return; - } - switch (val) - { - case 0: + int ofs = *fs; + if (val == CB_ERR) + return; *fs = 0; - break; + *vsync = 0; + if (p96) { + *fs = val / 2; + *vsync = val & 1; + if (*fs == 2 && *fs != ofs) { + workprefs.win32_rtgscaleifsmall = 1; + workprefs.win32_rtgmatchdepth = 0; + } + return; + } + switch (val) + { + case 0: + *fs = 0; + break; case 1: - *fs = 1; - break; + *fs = 1; + break; case 2: - *fs = 1; - *vsync = 1; - break; + *fs = 1; + *vsync = 1; + break; case 3: - *fs = 1; - *vsync = 2; - break; + *fs = 1; + *vsync = 2; + break; case 4: - *fs = 2; - if (workprefs.gfx_filter == 0 && *fs != ofs) { - if (D3D_goodenough ()) { - workprefs.gfx_filter = 2; - workprefs.gfx_filter_filtermode = 2; - } else { - workprefs.gfx_filter = 1; - } - workprefs.gfx_filter_horiz_zoom = 0; - workprefs.gfx_filter_vert_zoom = 0; - workprefs.gfx_filter_horiz_zoom_mult = 0; - workprefs.gfx_filter_vert_zoom_mult = 0; - workprefs.gfx_filter_aspect = -1; - workprefs.gfx_filter_horiz_offset = 0; - workprefs.gfx_filter_vert_offset = 0; - workprefs.gfx_filter_keep_aspect = 0; - } - break; - } + *fs = 2; + if (workprefs.gfx_filter == 0 && *fs != ofs) { + if (D3D_goodenough ()) { + workprefs.gfx_filter = 2; + workprefs.gfx_filter_filtermode = 2; + } else { + workprefs.gfx_filter = 1; + } + workprefs.gfx_filter_horiz_zoom = 0; + workprefs.gfx_filter_vert_zoom = 0; + workprefs.gfx_filter_horiz_zoom_mult = 0; + workprefs.gfx_filter_vert_zoom_mult = 0; + workprefs.gfx_filter_aspect = -1; + workprefs.gfx_filter_horiz_offset = 0; + workprefs.gfx_filter_vert_offset = 0; + workprefs.gfx_filter_keep_aspect = 0; + } + break; + } } static void values_to_displaydlg (HWND hDlg) { - TCHAR buffer[MAX_DPATH], buffer2[MAX_DPATH]; - TCHAR Nth[MAX_NTH_LENGTH]; - TCHAR *blah[1] = { Nth }; - TCHAR *string = NULL; - int v; - - init_display_mode (hDlg); - - SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_size_win.width, FALSE); - SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_size_win.height, FALSE); - - v = workprefs.chipset_refreshrate; - if (v == 0) - v = currprefs.ntscmode ? 60 : 50; - SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPOS, TRUE, v); - _stprintf (buffer, L"%d", v); - SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer); - - v = workprefs.cpu_cycle_exact ? 1 : workprefs.gfx_framerate; - SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPOS, TRUE, v); - WIN32GUI_LoadUIString(IDS_FRAMERATE, buffer, sizeof buffer / sizeof (TCHAR)); - LoadNthString (v - 1, Nth, MAX_NTH_LENGTH); - if (FormatMessage (FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, - buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0) - { - DWORD dwLastError = GetLastError(); - _stprintf (buffer, L"Every %s Frame", nth[v - 1]); - SetDlgItemText(hDlg, IDC_RATETEXT, buffer); - } else { - SetDlgItemText( hDlg, IDC_RATETEXT, string); - LocalFree(string); - } - - CheckRadioButton (hDlg, IDC_LM_NORMAL, IDC_LM_SCANLINES, IDC_LM_NORMAL + workprefs.gfx_linedbl); - - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_RESETCONTENT, 0, 0); - - WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); - - WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); - - WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer2, sizeof buffer2 / sizeof (TCHAR)); - _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); - - WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); - WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC_AUTOSWITCH, buffer2, sizeof buffer2 / sizeof (TCHAR)); - _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); - - - WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); - - SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_SETCURSEL, - display_toselect (workprefs.gfx_afullscreen, workprefs.gfx_avsync, 0), 0); - - - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer2, sizeof buffer2 / sizeof (TCHAR)); - _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); - SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_SETCURSEL, - display_toselect (workprefs.gfx_pfullscreen, workprefs.gfx_pvsync, 1), 0); - - SendDlgItemMessage(hDlg, IDC_LORES, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString(IDS_RES_LORES, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); - WIN32GUI_LoadUIString(IDS_RES_HIRES, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); - WIN32GUI_LoadUIString(IDS_RES_SUPERHIRES, buffer, sizeof buffer / sizeof (TCHAR)); - SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); - SendDlgItemMessage (hDlg, IDC_LORES, CB_SETCURSEL, workprefs.gfx_resolution, 0); - - CheckDlgButton (hDlg, IDC_BLACKER_THAN_BLACK, workprefs.gfx_blackerthanblack); - CheckDlgButton (hDlg, IDC_LORES_SMOOTHED, workprefs.gfx_lores_mode); - CheckDlgButton (hDlg, IDC_FLICKERFIXER, workprefs.gfx_scandoubler); - - CheckDlgButton (hDlg, IDC_XCENTER, workprefs.gfx_xcenter); - CheckDlgButton (hDlg, IDC_YCENTER, workprefs.gfx_ycenter); - - init_da (hDlg); -} + TCHAR buffer[MAX_DPATH], buffer2[MAX_DPATH]; + TCHAR Nth[MAX_NTH_LENGTH]; + TCHAR *blah[1] = { Nth }; + TCHAR *string = NULL; + int v; -static void init_resolution_combo (HWND hDlg) -{ - int i, idx; - TCHAR tmp[64]; - struct MultiDisplay *md = getdisplay (&workprefs); + init_display_mode (hDlg); - idx = -1; - SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_RESETCONTENT, 0, 0); - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx != idx) { - _stprintf (tmp, L"%dx%d", md->DisplayModes[i].res.width, md->DisplayModes[i].res.height); - if (md->DisplayModes[i].nondx) - _tcscat (tmp, L" (*)"); - SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)tmp); - idx = md->DisplayModes[i].residx; - } - } + SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_size_win.width, FALSE); + SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_size_win.height, FALSE); + + v = workprefs.chipset_refreshrate; + if (v == 0) + v = currprefs.ntscmode ? 60 : 50; + SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPOS, TRUE, v); + _stprintf (buffer, L"%d", v); + SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer); + + v = workprefs.cpu_cycle_exact ? 1 : workprefs.gfx_framerate; + SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPOS, TRUE, v); + WIN32GUI_LoadUIString(IDS_FRAMERATE, buffer, sizeof buffer / sizeof (TCHAR)); + LoadNthString (v - 1, Nth, MAX_NTH_LENGTH); + if (FormatMessage (FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, + buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0) + { + DWORD dwLastError = GetLastError(); + _stprintf (buffer, L"Every %s Frame", nth[v - 1]); + SetDlgItemText(hDlg, IDC_RATETEXT, buffer); + } else { + SetDlgItemText( hDlg, IDC_RATETEXT, string); + LocalFree(string); + } + + CheckRadioButton (hDlg, IDC_LM_NORMAL, IDC_LM_SCANLINES, IDC_LM_NORMAL + workprefs.gfx_linedbl); + + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_RESETCONTENT, 0, 0); + + WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); + + WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); + + WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer2, sizeof buffer2 / sizeof (TCHAR)); + _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); + + WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); + WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC_AUTOSWITCH, buffer2, sizeof buffer2 / sizeof (TCHAR)); + _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); + + + WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_ADDSTRING, 0, (LPARAM)buffer); + + SendDlgItemMessage(hDlg, IDC_SCREENMODE_NATIVE, CB_SETCURSEL, + display_toselect (workprefs.gfx_afullscreen, workprefs.gfx_avsync, 0), 0); + + + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString(IDS_SCREEN_WINDOWED, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + WIN32GUI_LoadUIString(IDS_SCREEN_FULLSCREEN, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + WIN32GUI_LoadUIString(IDS_SCREEN_VSYNC, buffer2, sizeof buffer2 / sizeof (TCHAR)); + _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + WIN32GUI_LoadUIString(IDS_SCREEN_FULLWINDOW, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + _stprintf (buffer + _tcslen (buffer), L" + %s", buffer2); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_ADDSTRING, 0, (LPARAM)buffer); + SendDlgItemMessage(hDlg, IDC_SCREENMODE_RTG, CB_SETCURSEL, + display_toselect (workprefs.gfx_pfullscreen, workprefs.gfx_pvsync, 1), 0); + + SendDlgItemMessage(hDlg, IDC_LORES, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString(IDS_RES_LORES, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); + WIN32GUI_LoadUIString(IDS_RES_HIRES, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); + WIN32GUI_LoadUIString(IDS_RES_SUPERHIRES, buffer, sizeof buffer / sizeof (TCHAR)); + SendDlgItemMessage(hDlg, IDC_LORES, CB_ADDSTRING, 0, (LPARAM)buffer); + SendDlgItemMessage (hDlg, IDC_LORES, CB_SETCURSEL, workprefs.gfx_resolution, 0); + + CheckDlgButton (hDlg, IDC_BLACKER_THAN_BLACK, workprefs.gfx_blackerthanblack); + CheckDlgButton (hDlg, IDC_LORES_SMOOTHED, workprefs.gfx_lores_mode); + CheckDlgButton (hDlg, IDC_FLICKERFIXER, workprefs.gfx_scandoubler); + + CheckDlgButton (hDlg, IDC_XCENTER, workprefs.gfx_xcenter); + CheckDlgButton (hDlg, IDC_YCENTER, workprefs.gfx_ycenter); + + init_da (hDlg); +} + +static void init_resolution_combo (HWND hDlg) +{ + int i, idx; + TCHAR tmp[64]; + struct MultiDisplay *md = getdisplay (&workprefs); + + idx = -1; + SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_RESETCONTENT, 0, 0); + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + if (md->DisplayModes[i].depth > 1 && md->DisplayModes[i].residx != idx) { + _stprintf (tmp, L"%dx%d", md->DisplayModes[i].res.width, md->DisplayModes[i].res.height); + if (md->DisplayModes[i].nondx) + _tcscat (tmp, L" (*)"); + SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)tmp); + idx = md->DisplayModes[i].residx; + } + } } static void init_displays_combo (HWND hDlg) { - int i = 0; - SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_RESETCONTENT, 0, 0); - while (Displays[i].name) { - SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_ADDSTRING, 0, (LPARAM)Displays[i].name); - i++; - } - if (workprefs.gfx_display >= i) - workprefs.gfx_display = 0; - SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_SETCURSEL, workprefs.gfx_display, 0); + int i = 0; + SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_RESETCONTENT, 0, 0); + while (Displays[i].name) { + SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_ADDSTRING, 0, (LPARAM)Displays[i].name); + i++; + } + if (workprefs.gfx_display >= i) + workprefs.gfx_display = 0; + SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_SETCURSEL, workprefs.gfx_display, 0); } static void values_from_displaydlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - BOOL success = FALSE; - int i, j; - int gfx_width = workprefs.gfx_size_win.width; - int gfx_height = workprefs.gfx_size_win.height; - LRESULT posn; + BOOL success = FALSE; + int i, j; + int gfx_width = workprefs.gfx_size_win.width; + int gfx_height = workprefs.gfx_size_win.height; + LRESULT posn; - display_fromselect (SendDlgItemMessage (hDlg, IDC_SCREENMODE_NATIVE, CB_GETCURSEL, 0, 0), - &workprefs.gfx_afullscreen, &workprefs.gfx_avsync, 0); - display_fromselect (SendDlgItemMessage (hDlg, IDC_SCREENMODE_RTG, CB_GETCURSEL, 0, 0), - &workprefs.gfx_pfullscreen, &workprefs.gfx_pvsync, 1); + display_fromselect (SendDlgItemMessage (hDlg, IDC_SCREENMODE_NATIVE, CB_GETCURSEL, 0, 0), + &workprefs.gfx_afullscreen, &workprefs.gfx_avsync, 0); + display_fromselect (SendDlgItemMessage (hDlg, IDC_SCREENMODE_RTG, CB_GETCURSEL, 0, 0), + &workprefs.gfx_pfullscreen, &workprefs.gfx_pvsync, 1); - workprefs.gfx_lores_mode = IsDlgButtonChecked (hDlg, IDC_LORES_SMOOTHED); - workprefs.gfx_scandoubler = IsDlgButtonChecked (hDlg, IDC_FLICKERFIXER); - workprefs.gfx_blackerthanblack = IsDlgButtonChecked (hDlg, IDC_BLACKER_THAN_BLACK); - workprefs.gfx_linedbl = (IsDlgButtonChecked(hDlg, IDC_LM_SCANLINES) ? 2 : - IsDlgButtonChecked(hDlg, IDC_LM_DOUBLED) ? 1 : 0); + workprefs.gfx_lores_mode = IsDlgButtonChecked (hDlg, IDC_LORES_SMOOTHED); + workprefs.gfx_scandoubler = IsDlgButtonChecked (hDlg, IDC_FLICKERFIXER); + workprefs.gfx_blackerthanblack = IsDlgButtonChecked (hDlg, IDC_BLACKER_THAN_BLACK); + workprefs.gfx_linedbl = (IsDlgButtonChecked(hDlg, IDC_LM_SCANLINES) ? 2 : + IsDlgButtonChecked(hDlg, IDC_LM_DOUBLED) ? 1 : 0); - workprefs.gfx_framerate = SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_GETPOS, 0, 0); - workprefs.chipset_refreshrate = SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_GETPOS, 0, 0); - - { - TCHAR buffer[MAX_FRAMERATE_LENGTH]; - TCHAR Nth[MAX_NTH_LENGTH]; - TCHAR *blah[1] = { Nth }; - TCHAR *string = NULL; + workprefs.gfx_framerate = SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_GETPOS, 0, 0); + workprefs.chipset_refreshrate = SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_GETPOS, 0, 0); - WIN32GUI_LoadUIString(IDS_FRAMERATE, buffer, MAX_FRAMERATE_LENGTH); - LoadNthString(workprefs.gfx_framerate - 1, Nth, MAX_NTH_LENGTH); - if(FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, - buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0) { - DWORD dwLastError = GetLastError(); - _stprintf (buffer, L"Every %s Frame", nth[workprefs.gfx_framerate - 1]); - SetDlgItemText(hDlg, IDC_RATETEXT, buffer); - } - else + TCHAR buffer[MAX_FRAMERATE_LENGTH]; + TCHAR Nth[MAX_NTH_LENGTH]; + TCHAR *blah[1] = { Nth }; + TCHAR *string = NULL; + + WIN32GUI_LoadUIString(IDS_FRAMERATE, buffer, MAX_FRAMERATE_LENGTH); + LoadNthString(workprefs.gfx_framerate - 1, Nth, MAX_NTH_LENGTH); + if(FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, + buffer, 0, 0, (LPTSTR)&string, MAX_FRAMERATE_LENGTH + MAX_NTH_LENGTH, (va_list *)blah ) == 0) + { + DWORD dwLastError = GetLastError(); + _stprintf (buffer, L"Every %s Frame", nth[workprefs.gfx_framerate - 1]); + SetDlgItemText(hDlg, IDC_RATETEXT, buffer); + } + else + { + SetDlgItemText(hDlg, IDC_RATETEXT, string); + LocalFree(string); + } + _stprintf (buffer, L"%d", workprefs.chipset_refreshrate); + SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer); + workprefs.gfx_size_win.width = GetDlgItemInt(hDlg, IDC_XSIZE, &success, FALSE); + if(!success) + workprefs.gfx_size_win.width = 800; + workprefs.gfx_size_win.height = GetDlgItemInt(hDlg, IDC_YSIZE, &success, FALSE); + if(!success) + workprefs.gfx_size_win.height = 600; + } + if (workprefs.chipset_refreshrate == (currprefs.ntscmode ? 60 : 50)) + workprefs.chipset_refreshrate = 0; + workprefs.gfx_xcenter = (IsDlgButtonChecked (hDlg, IDC_XCENTER) ? 2 : 0 ); /* Smart centering */ + workprefs.gfx_ycenter = (IsDlgButtonChecked (hDlg, IDC_YCENTER) ? 2 : 0 ); /* Smart centering */ + + if (msg == WM_COMMAND && HIWORD (wParam) == CBN_SELCHANGE) { - SetDlgItemText(hDlg, IDC_RATETEXT, string); - LocalFree(string); - } - _stprintf (buffer, L"%d", workprefs.chipset_refreshrate); - SetDlgItemText (hDlg, IDC_RATE2TEXT, buffer); - workprefs.gfx_size_win.width = GetDlgItemInt(hDlg, IDC_XSIZE, &success, FALSE); - if(!success) - workprefs.gfx_size_win.width = 800; - workprefs.gfx_size_win.height = GetDlgItemInt(hDlg, IDC_YSIZE, &success, FALSE); - if(!success) - workprefs.gfx_size_win.height = 600; - } - if (workprefs.chipset_refreshrate == (currprefs.ntscmode ? 60 : 50)) - workprefs.chipset_refreshrate = 0; - workprefs.gfx_xcenter = (IsDlgButtonChecked (hDlg, IDC_XCENTER) ? 2 : 0 ); /* Smart centering */ - workprefs.gfx_ycenter = (IsDlgButtonChecked (hDlg, IDC_YCENTER) ? 2 : 0 ); /* Smart centering */ - - if (msg == WM_COMMAND && HIWORD (wParam) == CBN_SELCHANGE) - { - if (LOWORD (wParam) == IDC_DISPLAYSELECT) { - posn = SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_GETCURSEL, 0, 0); - if (posn != CB_ERR && posn != workprefs.gfx_display) { - if (Displays[posn].disabled) - posn = 0; - workprefs.gfx_display = posn; - init_resolution_combo (hDlg); - init_display_mode (hDlg); - } - return; - } else if (LOWORD (wParam) == IDC_LORES) { - posn = SendDlgItemMessage (hDlg, IDC_LORES, CB_GETCURSEL, 0, 0); - if (posn != CB_ERR) - workprefs.gfx_resolution = posn; - } else if (LOWORD (wParam) == IDC_RESOLUTION || LOWORD(wParam) == IDC_RESOLUTIONDEPTH) { - struct MultiDisplay *md = getdisplay (&workprefs); - LRESULT posn1, posn2; - posn1 = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0); - if (posn1 == CB_ERR) - return; - posn2 = SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_GETCURSEL, 0, 0); - if (posn2 == CB_ERR) - return; - for (i = 0; md->DisplayModes[i].depth >= 0; i++) { - if (md->DisplayModes[i].residx == posn1) - break; - } - if (md->DisplayModes[i].depth < 0) - return; - j = i; - while (md->DisplayModes[i].residx == posn1) { - if (md->DisplayModes[i].depth == gui_display_depths[posn2]) - break; - i++; - } - if (md->DisplayModes[i].residx != posn1) - i = j; - workprefs.gfx_size_fs.width = md->DisplayModes[i].res.width; - workprefs.gfx_size_fs.height = md->DisplayModes[i].res.height; - switch(md->DisplayModes[i].depth) - { - case 2: - workprefs.color_mode = 2; - break; - case 3: - case 4: - workprefs.color_mode = 5; - break; - default: - workprefs.color_mode = 0; - break; - } - /* Set the Int boxes */ - SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_size_win.width, FALSE); - SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_size_win.height, FALSE); - init_frequency_combo (hDlg, i); - } else if (LOWORD (wParam) == IDC_REFRESHRATE) { - LRESULT posn1, posn2; - posn1 = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_GETCURSEL, 0, 0); - if (posn1 == CB_ERR) - return; - posn2 = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0); - if (posn2 == CB_ERR) - return; - if (posn1 == 0) { - workprefs.gfx_refreshrate = 0; - } else { - posn1--; - workprefs.gfx_refreshrate = storedrefreshrates[posn1].rate; - } - values_to_displaydlg (hDlg); - } else if (LOWORD (wParam) == IDC_DA_MODE) { - da_mode_selected = SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0); - init_da (hDlg); - handle_da (hDlg); + if (LOWORD (wParam) == IDC_DISPLAYSELECT) { + posn = SendDlgItemMessage (hDlg, IDC_DISPLAYSELECT, CB_GETCURSEL, 0, 0); + if (posn != CB_ERR && posn != workprefs.gfx_display) { + if (Displays[posn].disabled) + posn = 0; + workprefs.gfx_display = posn; + init_resolution_combo (hDlg); + init_display_mode (hDlg); + } + return; + } else if (LOWORD (wParam) == IDC_LORES) { + posn = SendDlgItemMessage (hDlg, IDC_LORES, CB_GETCURSEL, 0, 0); + if (posn != CB_ERR) + workprefs.gfx_resolution = posn; + } else if (LOWORD (wParam) == IDC_RESOLUTION || LOWORD(wParam) == IDC_RESOLUTIONDEPTH) { + struct MultiDisplay *md = getdisplay (&workprefs); + LRESULT posn1, posn2; + posn1 = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0); + if (posn1 == CB_ERR) + return; + posn2 = SendDlgItemMessage (hDlg, IDC_RESOLUTIONDEPTH, CB_GETCURSEL, 0, 0); + if (posn2 == CB_ERR) + return; + for (i = 0; md->DisplayModes[i].depth >= 0; i++) { + if (md->DisplayModes[i].residx == posn1) + break; + } + if (md->DisplayModes[i].depth < 0) + return; + j = i; + while (md->DisplayModes[i].residx == posn1) { + if (md->DisplayModes[i].depth == gui_display_depths[posn2]) + break; + i++; + } + if (md->DisplayModes[i].residx != posn1) + i = j; + workprefs.gfx_size_fs.width = md->DisplayModes[i].res.width; + workprefs.gfx_size_fs.height = md->DisplayModes[i].res.height; + switch(md->DisplayModes[i].depth) + { + case 2: + workprefs.color_mode = 2; + break; + case 3: + case 4: + workprefs.color_mode = 5; + break; + default: + workprefs.color_mode = 0; + break; + } + /* Set the Int boxes */ + SetDlgItemInt (hDlg, IDC_XSIZE, workprefs.gfx_size_win.width, FALSE); + SetDlgItemInt (hDlg, IDC_YSIZE, workprefs.gfx_size_win.height, FALSE); + init_frequency_combo (hDlg, i); + } else if (LOWORD (wParam) == IDC_REFRESHRATE) { + LRESULT posn1, posn2; + posn1 = SendDlgItemMessage (hDlg, IDC_REFRESHRATE, CB_GETCURSEL, 0, 0); + if (posn1 == CB_ERR) + return; + posn2 = SendDlgItemMessage (hDlg, IDC_RESOLUTION, CB_GETCURSEL, 0, 0); + if (posn2 == CB_ERR) + return; + if (posn1 == 0) { + workprefs.gfx_refreshrate = 0; + } else { + posn1--; + workprefs.gfx_refreshrate = storedrefreshrates[posn1].rate; + } + values_to_displaydlg (hDlg); + } else if (LOWORD (wParam) == IDC_DA_MODE) { + da_mode_selected = SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0); + init_da (hDlg); + handle_da (hDlg); + } } - } - updatewinfsmode (&workprefs); + updatewinfsmode (&workprefs); } static int hw3d_changed; static INT_PTR CALLBACK DisplayDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - - switch (msg) - { - case WM_INITDIALOG: - pages[DISPLAY_ID] = hDlg; - currentpage = DISPLAY_ID; - SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETRANGE, TRUE, MAKELONG (MIN_REFRESH_RATE, MAX_REFRESH_RATE)); - SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETRANGE, TRUE, MAKELONG (1, 99)); - init_displays_combo (hDlg); - init_resolution_combo (hDlg); - init_da (hDlg); + static int recursive = 0; - case WM_USER: - recursive++; - values_to_displaydlg (hDlg); - enable_for_displaydlg (hDlg); - recursive--; - break; + switch (msg) + { + case WM_INITDIALOG: + pages[DISPLAY_ID] = hDlg; + currentpage = DISPLAY_ID; + SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FRAMERATE, TBM_SETRANGE, TRUE, MAKELONG (MIN_REFRESH_RATE, MAX_REFRESH_RATE)); + SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FRAMERATE2, TBM_SETRANGE, TRUE, MAKELONG (1, 99)); + init_displays_combo (hDlg); + init_resolution_combo (hDlg); + init_da (hDlg); - case WM_HSCROLL: - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (LOWORD (wParam) == IDC_DA_RESET) { - int *p; - da_mode_selected = SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0); - p = getp_da(); - if (p) - *p = 0; - init_da(hDlg); - update_da(); - } - handle_da (hDlg); - values_from_displaydlg (hDlg, msg, wParam, lParam); - enable_for_displaydlg (hDlg); - recursive--; - break; + case WM_USER: + recursive++; + values_to_displaydlg (hDlg); + enable_for_displaydlg (hDlg); + recursive--; + break; - } - if (hw3d_changed && recursive == 0) { - recursive++; - enable_for_displaydlg (hDlg); - values_to_displaydlg (hDlg); - hw3d_changed = 0; - recursive--; - } - return FALSE; + case WM_HSCROLL: + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + if (LOWORD (wParam) == IDC_DA_RESET) { + int *p; + da_mode_selected = SendDlgItemMessage (hDlg, IDC_DA_MODE, CB_GETCURSEL, 0, 0); + p = getp_da(); + if (p) + *p = 0; + init_da(hDlg); + update_da(); + } + handle_da (hDlg); + values_from_displaydlg (hDlg, msg, wParam, lParam); + enable_for_displaydlg (hDlg); + recursive--; + break; + + } + if (hw3d_changed && recursive == 0) { + recursive++; + enable_for_displaydlg (hDlg); + values_to_displaydlg (hDlg); + hw3d_changed = 0; + recursive--; + } + return FALSE; } static void values_to_chipsetdlg (HWND hDlg) { - TCHAR Nth[MAX_NTH_LENGTH]; - TCHAR *blah[1] = { Nth }; - TCHAR *string = NULL; - int which_button; - - switch(workprefs.chipset_mask) - { - case 0: - CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 0); - break; - case CSMASK_ECS_AGNUS: - CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 1); - break; - case CSMASK_ECS_DENISE: - CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 2); - break; - case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE: - CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 3); - break; - case CSMASK_AGA: - case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA: - CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 4); - break; - } - CheckDlgButton (hDlg, IDC_NTSC, workprefs.ntscmode); - CheckDlgButton (hDlg, IDC_GENLOCK, workprefs.genlock); - CheckDlgButton (hDlg, IDC_BLITIMM, workprefs.immediate_blits); - CheckRadioButton (hDlg, IDC_COLLISION0, IDC_COLLISION3, IDC_COLLISION0 + workprefs.collision_level); - CheckDlgButton (hDlg, IDC_CYCLEEXACT, workprefs.cpu_cycle_exact); - switch (workprefs.produce_sound) { - case 0: which_button = IDC_CS_SOUND0; break; - case 1: case 2: which_button = IDC_CS_SOUND1; break; - default: which_button = IDC_CS_SOUND2; break; - } - CheckRadioButton (hDlg, IDC_CS_SOUND0, IDC_CS_SOUND2, which_button); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L""); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"Generic"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"CDTV"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"CD32"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A500"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A500+"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A600"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A1000"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A1200"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A2000"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A3000"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A3000T"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A4000"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A4000T"); - SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_SETCURSEL, workprefs.cs_compatible, 0); + TCHAR Nth[MAX_NTH_LENGTH]; + TCHAR *blah[1] = { Nth }; + TCHAR *string = NULL; + int which_button; + + switch(workprefs.chipset_mask) + { + case 0: + CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 0); + break; + case CSMASK_ECS_AGNUS: + CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 1); + break; + case CSMASK_ECS_DENISE: + CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 2); + break; + case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE: + CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 3); + break; + case CSMASK_AGA: + case CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE | CSMASK_AGA: + CheckRadioButton(hDlg, IDC_OCS, IDC_AGA, IDC_OCS + 4); + break; + } + CheckDlgButton (hDlg, IDC_NTSC, workprefs.ntscmode); + CheckDlgButton (hDlg, IDC_GENLOCK, workprefs.genlock); + CheckDlgButton (hDlg, IDC_BLITIMM, workprefs.immediate_blits); + CheckRadioButton (hDlg, IDC_COLLISION0, IDC_COLLISION3, IDC_COLLISION0 + workprefs.collision_level); + CheckDlgButton (hDlg, IDC_CYCLEEXACT, workprefs.cpu_cycle_exact); + switch (workprefs.produce_sound) { + case 0: which_button = IDC_CS_SOUND0; break; + case 1: case 2: which_button = IDC_CS_SOUND1; break; + default: which_button = IDC_CS_SOUND2; break; + } + CheckRadioButton (hDlg, IDC_CS_SOUND0, IDC_CS_SOUND2, which_button); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L""); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"Generic"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"CDTV"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"CD32"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A500"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A500+"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A600"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A1000"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A1200"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A2000"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A3000"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A3000T"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A4000"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_ADDSTRING, 0, (LPARAM)L"A4000T"); + SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_SETCURSEL, workprefs.cs_compatible, 0); } static void values_from_chipsetdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - BOOL success = FALSE; - int n, snd; - - workprefs.genlock = IsDlgButtonChecked (hDlg, IDC_GENLOCK); - workprefs.immediate_blits = IsDlgButtonChecked (hDlg, IDC_BLITIMM); - n = IsDlgButtonChecked (hDlg, IDC_CYCLEEXACT) ? 1 : 0; - if (workprefs.cpu_cycle_exact != n) { - workprefs.cpu_cycle_exact = workprefs.blitter_cycle_exact = n; - if (n) { - if (workprefs.cpu_model == 68000) { - workprefs.cpu_compatible = 1; - workprefs.m68k_speed = 0; - } - workprefs.immediate_blits = 0; - workprefs.gfx_framerate = 1; - } - } - workprefs.collision_level = IsDlgButtonChecked (hDlg, IDC_COLLISION0) ? 0 - : IsDlgButtonChecked (hDlg, IDC_COLLISION1) ? 1 - : IsDlgButtonChecked (hDlg, IDC_COLLISION2) ? 2 : 3; - workprefs.chipset_mask = IsDlgButtonChecked (hDlg, IDC_OCS) ? 0 - : IsDlgButtonChecked (hDlg, IDC_ECS_AGNUS) ? CSMASK_ECS_AGNUS - : IsDlgButtonChecked (hDlg, IDC_ECS_DENISE) ? CSMASK_ECS_DENISE - : IsDlgButtonChecked (hDlg, IDC_ECS) ? CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE - : CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; - n = IsDlgButtonChecked (hDlg, IDC_NTSC) ? 1 : 0; - if (workprefs.ntscmode != n) { - workprefs.ntscmode = n; + BOOL success = FALSE; + int n, snd; + + workprefs.genlock = IsDlgButtonChecked (hDlg, IDC_GENLOCK); + workprefs.immediate_blits = IsDlgButtonChecked (hDlg, IDC_BLITIMM); + n = IsDlgButtonChecked (hDlg, IDC_CYCLEEXACT) ? 1 : 0; + if (workprefs.cpu_cycle_exact != n) { + workprefs.cpu_cycle_exact = workprefs.blitter_cycle_exact = n; + if (n) { + if (workprefs.cpu_model == 68000) { + workprefs.cpu_compatible = 1; + workprefs.m68k_speed = 0; + } + workprefs.immediate_blits = 0; + workprefs.gfx_framerate = 1; + } + } + workprefs.collision_level = IsDlgButtonChecked (hDlg, IDC_COLLISION0) ? 0 + : IsDlgButtonChecked (hDlg, IDC_COLLISION1) ? 1 + : IsDlgButtonChecked (hDlg, IDC_COLLISION2) ? 2 : 3; + workprefs.chipset_mask = IsDlgButtonChecked (hDlg, IDC_OCS) ? 0 + : IsDlgButtonChecked (hDlg, IDC_ECS_AGNUS) ? CSMASK_ECS_AGNUS + : IsDlgButtonChecked (hDlg, IDC_ECS_DENISE) ? CSMASK_ECS_DENISE + : IsDlgButtonChecked (hDlg, IDC_ECS) ? CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE + : CSMASK_AGA | CSMASK_ECS_AGNUS | CSMASK_ECS_DENISE; + n = IsDlgButtonChecked (hDlg, IDC_NTSC) ? 1 : 0; + if (workprefs.ntscmode != n) { + workprefs.ntscmode = n; #ifdef AVIOUTPUT - avioutput_fps = n ? VBLANK_HZ_NTSC : VBLANK_HZ_PAL; + avioutput_fps = n ? VBLANK_HZ_NTSC : VBLANK_HZ_PAL; #endif - } - snd = IsDlgButtonChecked (hDlg, IDC_CS_SOUND0) ? 0 - : IsDlgButtonChecked (hDlg, IDC_CS_SOUND1) ? 2 : 3; - if (snd == 0 || snd == 3) { - workprefs.produce_sound = snd; - } else if (snd == 2) { - if (workprefs.produce_sound == 0) - workprefs.produce_sound = 2; - else if (workprefs.produce_sound >= 2) - workprefs.produce_sound = 2; - } - n = SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_GETCURSEL, 0, 0); - if (n != CB_ERR) { - workprefs.cs_compatible = n; - built_in_chipset_prefs (&workprefs); - } + } + snd = IsDlgButtonChecked (hDlg, IDC_CS_SOUND0) ? 0 + : IsDlgButtonChecked (hDlg, IDC_CS_SOUND1) ? 2 : 3; + if (snd == 0 || snd == 3) { + workprefs.produce_sound = snd; + } else if (snd == 2) { + if (workprefs.produce_sound == 0) + workprefs.produce_sound = 2; + else if (workprefs.produce_sound >= 2) + workprefs.produce_sound = 2; + } + n = SendDlgItemMessage (hDlg, IDC_CS_EXT, CB_GETCURSEL, 0, 0); + if (n != CB_ERR) { + workprefs.cs_compatible = n; + built_in_chipset_prefs (&workprefs); + } } static INT_PTR CALLBACK ChipsetDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; + static int recursive = 0; - switch (msg) { - case WM_INITDIALOG: - pages[CHIPSET_ID] = hDlg; - currentpage = CHIPSET_ID; + switch (msg) { + case WM_INITDIALOG: + pages[CHIPSET_ID] = hDlg; + currentpage = CHIPSET_ID; #ifndef AGA - ew (hDlg, IDC_AGA, FALSE); + ew (hDlg, IDC_AGA, FALSE); #endif - case WM_USER: - recursive++; - values_to_chipsetdlg (hDlg); - enable_for_chipsetdlg (hDlg); - recursive--; - break; + case WM_USER: + recursive++; + values_to_chipsetdlg (hDlg); + enable_for_chipsetdlg (hDlg); + recursive--; + break; - case WM_HSCROLL: - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - values_from_chipsetdlg (hDlg, msg, wParam, lParam); - enable_for_chipsetdlg( hDlg ); - recursive--; - break; - } - return FALSE; + case WM_HSCROLL: + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + values_from_chipsetdlg (hDlg, msg, wParam, lParam); + enable_for_chipsetdlg( hDlg ); + recursive--; + break; + } + return FALSE; } static void values_to_chipsetdlg2 (HWND hDlg) { - TCHAR txt[32]; - uae_u32 rev; + TCHAR txt[32]; + uae_u32 rev; - switch(workprefs.cs_ciaatod) - { + switch(workprefs.cs_ciaatod) + { case 0: - CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD1); - break; + CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD1); + break; case 1: - CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD2); - break; + CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD2); + break; case 2: - CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD3); - break; - } - switch(workprefs.cs_rtc) - { + CheckRadioButton(hDlg, IDC_CS_CIAA_TOD1, IDC_CS_CIAA_TOD3, IDC_CS_CIAA_TOD3); + break; + } + switch(workprefs.cs_rtc) + { case 0: - CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC1); - break; + CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC1); + break; case 1: - CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC2); - break; + CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC2); + break; case 2: - CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC3); - break; - } - CheckDlgButton (hDlg, IDC_CS_COMPATIBLE, workprefs.cs_compatible); - CheckDlgButton (hDlg, IDC_CS_RESETWARNING, workprefs.cs_resetwarning); - CheckDlgButton (hDlg, IDC_CS_NOEHB, workprefs.cs_denisenoehb); - CheckDlgButton (hDlg, IDC_CS_BLITTERBUG, workprefs.cs_agnusbltbusybug); - CheckDlgButton (hDlg, IDC_CS_KSMIRROR_E0, workprefs.cs_ksmirror_e0); - CheckDlgButton (hDlg, IDC_CS_KSMIRROR_A8, workprefs.cs_ksmirror_a8); - CheckDlgButton (hDlg, IDC_CS_CIAOVERLAY, workprefs.cs_ciaoverlay); - CheckDlgButton (hDlg, IDC_CS_DF0IDHW, workprefs.cs_df0idhw); - CheckDlgButton (hDlg, IDC_CS_CD32CD, workprefs.cs_cd32cd); - CheckDlgButton (hDlg, IDC_CS_CD32C2P, workprefs.cs_cd32c2p); - CheckDlgButton (hDlg, IDC_CS_CD32NVRAM, workprefs.cs_cd32nvram); - CheckDlgButton (hDlg, IDC_CS_CDTVCD, workprefs.cs_cdtvcd); - CheckDlgButton (hDlg, IDC_CS_CDTVRAM, workprefs.cs_cdtvram); - CheckDlgButton (hDlg, IDC_CS_CDTVRAMEXP, workprefs.cs_cdtvcard); - CheckDlgButton (hDlg, IDC_CS_A1000RAM, workprefs.cs_a1000ram); - CheckDlgButton (hDlg, IDC_CS_RAMSEY, workprefs.cs_ramseyrev >= 0); - CheckDlgButton (hDlg, IDC_CS_FATGARY, workprefs.cs_fatgaryrev >= 0); - CheckDlgButton (hDlg, IDC_CS_AGNUS, workprefs.cs_agnusrev >= 0); - CheckDlgButton (hDlg, IDC_CS_DENISE, workprefs.cs_deniserev >= 0); - CheckDlgButton (hDlg, IDC_CS_DMAC, workprefs.cs_mbdmac == 1); - CheckDlgButton (hDlg, IDC_CS_DMAC2, workprefs.cs_mbdmac == 2); - CheckDlgButton (hDlg, IDC_CS_A2091, workprefs.cs_a2091 > 0); - CheckDlgButton (hDlg, IDC_CS_A4091, workprefs.cs_a4091 > 0); - CheckDlgButton (hDlg, IDC_CS_CDTVSCSI, workprefs.cs_cdtvscsi > 0); - CheckDlgButton (hDlg, IDC_CS_SCSIMODE, workprefs.scsi == 2); - CheckDlgButton (hDlg, IDC_CS_PCMCIA, workprefs.cs_pcmcia > 0); - CheckDlgButton (hDlg, IDC_CS_SLOWISFAST, workprefs.cs_slowmemisfast > 0); - CheckDlgButton (hDlg, IDC_CS_IDE1, workprefs.cs_ide > 0 && (workprefs.cs_ide & 1)); - CheckDlgButton (hDlg, IDC_CS_IDE2, workprefs.cs_ide > 0 && (workprefs.cs_ide & 2)); - txt[0] = 0; - _stprintf (txt, L"%d", workprefs.cs_rtc_adjust); - SetDlgItemText(hDlg, IDC_CS_RTCADJUST, txt); - txt[0] = 0; - if (workprefs.cs_fatgaryrev >= 0) - _stprintf (txt, L"%02X", workprefs.cs_fatgaryrev); - SetDlgItemText(hDlg, IDC_CS_FATGARYREV, txt); - txt[0] = 0; - if (workprefs.cs_ramseyrev >= 0) - _stprintf (txt, L"%02X", workprefs.cs_ramseyrev); - SetDlgItemText(hDlg, IDC_CS_RAMSEYREV, txt); - txt[0] = 0; - if (workprefs.cs_agnusrev >= 0) { - rev = workprefs.cs_agnusrev; - _stprintf (txt, L"%02X", rev); - } else if (workprefs.cs_compatible) { - rev = 0; - if (workprefs.ntscmode) - rev |= 0x10; - rev |= (workprefs.chipset_mask & CSMASK_AGA) ? 0x23 : 0; - rev |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x20 : 0; - if (workprefs.chipmem_size > 1024 * 1024 && (workprefs.chipset_mask & CSMASK_ECS_AGNUS)) - rev |= 0x21; - _stprintf (txt, L"%02X", rev); - } - SetDlgItemText(hDlg, IDC_CS_AGNUSREV, txt); - txt[0] = 0; - if (workprefs.cs_deniserev >= 0) { - rev = workprefs.cs_deniserev; - _stprintf (txt, L"%01.1X", rev); - } else if (workprefs.cs_compatible) { - rev = 0xf; - if (workprefs.chipset_mask & CSMASK_ECS_DENISE) - rev = 0xc; - if (workprefs.chipset_mask & CSMASK_AGA) - rev = 0x8; - _stprintf (txt, L"%01.1X", rev); - } - SetDlgItemText(hDlg, IDC_CS_DENISEREV, txt); + CheckRadioButton(hDlg, IDC_CS_RTC1, IDC_CS_RTC3, IDC_CS_RTC3); + break; + } + CheckDlgButton (hDlg, IDC_CS_COMPATIBLE, workprefs.cs_compatible); + CheckDlgButton (hDlg, IDC_CS_RESETWARNING, workprefs.cs_resetwarning); + CheckDlgButton (hDlg, IDC_CS_NOEHB, workprefs.cs_denisenoehb); + CheckDlgButton (hDlg, IDC_CS_BLITTERBUG, workprefs.cs_agnusbltbusybug); + CheckDlgButton (hDlg, IDC_CS_KSMIRROR_E0, workprefs.cs_ksmirror_e0); + CheckDlgButton (hDlg, IDC_CS_KSMIRROR_A8, workprefs.cs_ksmirror_a8); + CheckDlgButton (hDlg, IDC_CS_CIAOVERLAY, workprefs.cs_ciaoverlay); + CheckDlgButton (hDlg, IDC_CS_DF0IDHW, workprefs.cs_df0idhw); + CheckDlgButton (hDlg, IDC_CS_CD32CD, workprefs.cs_cd32cd); + CheckDlgButton (hDlg, IDC_CS_CD32C2P, workprefs.cs_cd32c2p); + CheckDlgButton (hDlg, IDC_CS_CD32NVRAM, workprefs.cs_cd32nvram); + CheckDlgButton (hDlg, IDC_CS_CDTVCD, workprefs.cs_cdtvcd); + CheckDlgButton (hDlg, IDC_CS_CDTVRAM, workprefs.cs_cdtvram); + CheckDlgButton (hDlg, IDC_CS_CDTVRAMEXP, workprefs.cs_cdtvcard); + CheckDlgButton (hDlg, IDC_CS_A1000RAM, workprefs.cs_a1000ram); + CheckDlgButton (hDlg, IDC_CS_RAMSEY, workprefs.cs_ramseyrev >= 0); + CheckDlgButton (hDlg, IDC_CS_FATGARY, workprefs.cs_fatgaryrev >= 0); + CheckDlgButton (hDlg, IDC_CS_AGNUS, workprefs.cs_agnusrev >= 0); + CheckDlgButton (hDlg, IDC_CS_DENISE, workprefs.cs_deniserev >= 0); + CheckDlgButton (hDlg, IDC_CS_DMAC, workprefs.cs_mbdmac == 1); + CheckDlgButton (hDlg, IDC_CS_DMAC2, workprefs.cs_mbdmac == 2); + CheckDlgButton (hDlg, IDC_CS_A2091, workprefs.cs_a2091 > 0); + CheckDlgButton (hDlg, IDC_CS_A4091, workprefs.cs_a4091 > 0); + CheckDlgButton (hDlg, IDC_CS_CDTVSCSI, workprefs.cs_cdtvscsi > 0); + CheckDlgButton (hDlg, IDC_CS_SCSIMODE, workprefs.scsi == 2); + CheckDlgButton (hDlg, IDC_CS_PCMCIA, workprefs.cs_pcmcia > 0); + CheckDlgButton (hDlg, IDC_CS_SLOWISFAST, workprefs.cs_slowmemisfast > 0); + CheckDlgButton (hDlg, IDC_CS_IDE1, workprefs.cs_ide > 0 && (workprefs.cs_ide & 1)); + CheckDlgButton (hDlg, IDC_CS_IDE2, workprefs.cs_ide > 0 && (workprefs.cs_ide & 2)); + txt[0] = 0; + _stprintf (txt, L"%d", workprefs.cs_rtc_adjust); + SetDlgItemText(hDlg, IDC_CS_RTCADJUST, txt); + txt[0] = 0; + if (workprefs.cs_fatgaryrev >= 0) + _stprintf (txt, L"%02X", workprefs.cs_fatgaryrev); + SetDlgItemText(hDlg, IDC_CS_FATGARYREV, txt); + txt[0] = 0; + if (workprefs.cs_ramseyrev >= 0) + _stprintf (txt, L"%02X", workprefs.cs_ramseyrev); + SetDlgItemText(hDlg, IDC_CS_RAMSEYREV, txt); + txt[0] = 0; + if (workprefs.cs_agnusrev >= 0) { + rev = workprefs.cs_agnusrev; + _stprintf (txt, L"%02X", rev); + } else if (workprefs.cs_compatible) { + rev = 0; + if (workprefs.ntscmode) + rev |= 0x10; + rev |= (workprefs.chipset_mask & CSMASK_AGA) ? 0x23 : 0; + rev |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x20 : 0; + if (workprefs.chipmem_size > 1024 * 1024 && (workprefs.chipset_mask & CSMASK_ECS_AGNUS)) + rev |= 0x21; + _stprintf (txt, L"%02X", rev); + } + SetDlgItemText(hDlg, IDC_CS_AGNUSREV, txt); + txt[0] = 0; + if (workprefs.cs_deniserev >= 0) { + rev = workprefs.cs_deniserev; + _stprintf (txt, L"%01.1X", rev); + } else if (workprefs.cs_compatible) { + rev = 0xf; + if (workprefs.chipset_mask & CSMASK_ECS_DENISE) + rev = 0xc; + if (workprefs.chipset_mask & CSMASK_AGA) + rev = 0x8; + _stprintf (txt, L"%01.1X", rev); + } + SetDlgItemText(hDlg, IDC_CS_DENISEREV, txt); } static void values_from_chipsetdlg2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - TCHAR txt[32], *p; - int v; - - workprefs.cs_compatible = IsDlgButtonChecked (hDlg, IDC_CS_COMPATIBLE); - workprefs.cs_resetwarning = IsDlgButtonChecked (hDlg, IDC_CS_RESETWARNING); - workprefs.cs_denisenoehb = IsDlgButtonChecked (hDlg, IDC_CS_NOEHB); - workprefs.cs_agnusbltbusybug = IsDlgButtonChecked (hDlg, IDC_CS_BLITTERBUG); - workprefs.cs_ksmirror_e0 = IsDlgButtonChecked (hDlg, IDC_CS_KSMIRROR_E0); - workprefs.cs_ksmirror_a8 = IsDlgButtonChecked (hDlg, IDC_CS_KSMIRROR_A8); - workprefs.cs_ciaoverlay = IsDlgButtonChecked (hDlg, IDC_CS_CIAOVERLAY); - workprefs.cs_df0idhw = IsDlgButtonChecked (hDlg, IDC_CS_DF0IDHW); - workprefs.cs_cd32cd = IsDlgButtonChecked (hDlg, IDC_CS_CD32CD); - workprefs.cs_cd32c2p = IsDlgButtonChecked (hDlg, IDC_CS_CD32C2P); - workprefs.cs_cd32nvram = IsDlgButtonChecked (hDlg, IDC_CS_CD32NVRAM); - workprefs.cs_cdtvcd = IsDlgButtonChecked (hDlg, IDC_CS_CDTVCD); - workprefs.cs_cdtvram = IsDlgButtonChecked (hDlg, IDC_CS_CDTVRAM); - workprefs.cs_cdtvcard = IsDlgButtonChecked (hDlg, IDC_CS_CDTVRAMEXP) ? 64 : 0; - workprefs.cs_a1000ram = IsDlgButtonChecked (hDlg, IDC_CS_A1000RAM); - workprefs.cs_ramseyrev = IsDlgButtonChecked (hDlg, IDC_CS_RAMSEY) ? 0x0f : -1; - workprefs.cs_fatgaryrev = IsDlgButtonChecked (hDlg, IDC_CS_FATGARY) ? 0x00 : -1; - workprefs.cs_mbdmac = IsDlgButtonChecked (hDlg, IDC_CS_DMAC) ? 1 : 0; - if (workprefs.cs_mbdmac == 0) - workprefs.cs_mbdmac = IsDlgButtonChecked (hDlg, IDC_CS_DMAC2) ? 2 : 0; - workprefs.cs_a2091 = IsDlgButtonChecked (hDlg, IDC_CS_A2091) ? 1 : 0; - workprefs.cs_a4091 = IsDlgButtonChecked (hDlg, IDC_CS_A4091) ? 1 : 0; + TCHAR txt[32], *p; + int v; + + workprefs.cs_compatible = IsDlgButtonChecked (hDlg, IDC_CS_COMPATIBLE); + workprefs.cs_resetwarning = IsDlgButtonChecked (hDlg, IDC_CS_RESETWARNING); + workprefs.cs_denisenoehb = IsDlgButtonChecked (hDlg, IDC_CS_NOEHB); + workprefs.cs_agnusbltbusybug = IsDlgButtonChecked (hDlg, IDC_CS_BLITTERBUG); + workprefs.cs_ksmirror_e0 = IsDlgButtonChecked (hDlg, IDC_CS_KSMIRROR_E0); + workprefs.cs_ksmirror_a8 = IsDlgButtonChecked (hDlg, IDC_CS_KSMIRROR_A8); + workprefs.cs_ciaoverlay = IsDlgButtonChecked (hDlg, IDC_CS_CIAOVERLAY); + workprefs.cs_df0idhw = IsDlgButtonChecked (hDlg, IDC_CS_DF0IDHW); + workprefs.cs_cd32cd = IsDlgButtonChecked (hDlg, IDC_CS_CD32CD); + workprefs.cs_cd32c2p = IsDlgButtonChecked (hDlg, IDC_CS_CD32C2P); + workprefs.cs_cd32nvram = IsDlgButtonChecked (hDlg, IDC_CS_CD32NVRAM); + workprefs.cs_cdtvcd = IsDlgButtonChecked (hDlg, IDC_CS_CDTVCD); + workprefs.cs_cdtvram = IsDlgButtonChecked (hDlg, IDC_CS_CDTVRAM); + workprefs.cs_cdtvcard = IsDlgButtonChecked (hDlg, IDC_CS_CDTVRAMEXP) ? 64 : 0; + workprefs.cs_a1000ram = IsDlgButtonChecked (hDlg, IDC_CS_A1000RAM); + workprefs.cs_ramseyrev = IsDlgButtonChecked (hDlg, IDC_CS_RAMSEY) ? 0x0f : -1; + workprefs.cs_fatgaryrev = IsDlgButtonChecked (hDlg, IDC_CS_FATGARY) ? 0x00 : -1; + workprefs.cs_mbdmac = IsDlgButtonChecked (hDlg, IDC_CS_DMAC) ? 1 : 0; + if (workprefs.cs_mbdmac == 0) + workprefs.cs_mbdmac = IsDlgButtonChecked (hDlg, IDC_CS_DMAC2) ? 2 : 0; + workprefs.cs_a2091 = IsDlgButtonChecked (hDlg, IDC_CS_A2091) ? 1 : 0; + workprefs.cs_a4091 = IsDlgButtonChecked (hDlg, IDC_CS_A4091) ? 1 : 0; #if 0 - if (msg == WM_COMMAND && LOWORD(wParam) == IDC_CS_SCSIMODE) - workprefs.scsi = IsDlgButtonChecked (hDlg, IDC_CS_SCSIMODE) ? 2 : 0; + if (msg == WM_COMMAND && LOWORD(wParam) == IDC_CS_SCSIMODE) + workprefs.scsi = IsDlgButtonChecked (hDlg, IDC_CS_SCSIMODE) ? 2 : 0; #endif - workprefs.cs_cdtvscsi = IsDlgButtonChecked (hDlg, IDC_CS_CDTVSCSI) ? 1 : 0; - workprefs.cs_pcmcia = IsDlgButtonChecked (hDlg, IDC_CS_PCMCIA) ? 1 : 0; - workprefs.cs_slowmemisfast = IsDlgButtonChecked (hDlg, IDC_CS_SLOWISFAST) ? 1 : 0; - workprefs.cs_ide = IsDlgButtonChecked (hDlg, IDC_CS_IDE1) ? 1 : (IsDlgButtonChecked (hDlg, IDC_CS_IDE2) ? 2 : 0); - workprefs.cs_ciaatod = IsDlgButtonChecked (hDlg, IDC_CS_CIAA_TOD1) ? 0 - : (IsDlgButtonChecked (hDlg, IDC_CS_CIAA_TOD2) ? 1 : 2); - workprefs.cs_rtc = IsDlgButtonChecked (hDlg, IDC_CS_RTC1) ? 0 - : (IsDlgButtonChecked (hDlg, IDC_CS_RTC2) ? 1 : 2); - - if (workprefs.cs_rtc) { - txt[0] = 0; - SendDlgItemMessage (hDlg, IDC_CS_RTCADJUST, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - workprefs.cs_rtc_adjust = _tstol(txt); - } - if (workprefs.cs_fatgaryrev >= 0) { - txt[0] = 0; - SendDlgItemMessage (hDlg, IDC_CS_FATGARYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - v = _tcstol (txt, &p, 16); - if (v >= 0 && v <= 255) - workprefs.cs_fatgaryrev = v; - } - if (workprefs.cs_ramseyrev >= 0) { - txt[0] = 0; - SendDlgItemMessage (hDlg, IDC_CS_RAMSEYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - v = _tcstol (txt, &p, 16); - if (v >= 0 && v <= 255) - workprefs.cs_ramseyrev = v; - } - if (workprefs.cs_agnusrev >= 0) { - txt[0] = 0; - SendDlgItemMessage (hDlg, IDC_CS_AGNUSREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - v = _tcstol (txt, &p, 16); - if (v >= 0 && v <= 255) - workprefs.cs_agnusrev = v; - } - if (workprefs.cs_deniserev >= 0) { - txt[0] = 0; - SendDlgItemMessage (hDlg, IDC_CS_DENISEREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - v = _tcstol (txt, &p, 16); - if (v >= 0 && v <= 15) - workprefs.cs_deniserev = v; - } + workprefs.cs_cdtvscsi = IsDlgButtonChecked (hDlg, IDC_CS_CDTVSCSI) ? 1 : 0; + workprefs.cs_pcmcia = IsDlgButtonChecked (hDlg, IDC_CS_PCMCIA) ? 1 : 0; + workprefs.cs_slowmemisfast = IsDlgButtonChecked (hDlg, IDC_CS_SLOWISFAST) ? 1 : 0; + workprefs.cs_ide = IsDlgButtonChecked (hDlg, IDC_CS_IDE1) ? 1 : (IsDlgButtonChecked (hDlg, IDC_CS_IDE2) ? 2 : 0); + workprefs.cs_ciaatod = IsDlgButtonChecked (hDlg, IDC_CS_CIAA_TOD1) ? 0 + : (IsDlgButtonChecked (hDlg, IDC_CS_CIAA_TOD2) ? 1 : 2); + workprefs.cs_rtc = IsDlgButtonChecked (hDlg, IDC_CS_RTC1) ? 0 + : (IsDlgButtonChecked (hDlg, IDC_CS_RTC2) ? 1 : 2); + + if (workprefs.cs_rtc) { + txt[0] = 0; + SendDlgItemMessage (hDlg, IDC_CS_RTCADJUST, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + workprefs.cs_rtc_adjust = _tstol(txt); + } + if (workprefs.cs_fatgaryrev >= 0) { + txt[0] = 0; + SendDlgItemMessage (hDlg, IDC_CS_FATGARYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + v = _tcstol (txt, &p, 16); + if (v >= 0 && v <= 255) + workprefs.cs_fatgaryrev = v; + } + if (workprefs.cs_ramseyrev >= 0) { + txt[0] = 0; + SendDlgItemMessage (hDlg, IDC_CS_RAMSEYREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + v = _tcstol (txt, &p, 16); + if (v >= 0 && v <= 255) + workprefs.cs_ramseyrev = v; + } + if (workprefs.cs_agnusrev >= 0) { + txt[0] = 0; + SendDlgItemMessage (hDlg, IDC_CS_AGNUSREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + v = _tcstol (txt, &p, 16); + if (v >= 0 && v <= 255) + workprefs.cs_agnusrev = v; + } + if (workprefs.cs_deniserev >= 0) { + txt[0] = 0; + SendDlgItemMessage (hDlg, IDC_CS_DENISEREV, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + v = _tcstol (txt, &p, 16); + if (v >= 0 && v <= 15) + workprefs.cs_deniserev = v; + } } static void enable_for_chipsetdlg2 (HWND hDlg) { - int e = workprefs.cs_compatible ? FALSE : TRUE; - - ew (hDlg, IDC_CS_FATGARY, e); - ew (hDlg, IDC_CS_RAMSEY, e); - ew (hDlg, IDC_CS_AGNUS, e); - ew (hDlg, IDC_CS_DENISE, e); - ew (hDlg, IDC_CS_FATGARYREV, e); - ew (hDlg, IDC_CS_RAMSEYREV, e); - ew (hDlg, IDC_CS_AGNUSREV, e); - ew (hDlg, IDC_CS_DENISEREV, e); - ew (hDlg, IDC_CS_IDE1, e); - ew (hDlg, IDC_CS_IDE2, e); - ew (hDlg, IDC_CS_DMAC, e); - ew (hDlg, IDC_CS_DMAC2, e); - ew (hDlg, IDC_CS_A2091, e); - ew (hDlg, IDC_CS_A4091, e); - ShowWindow (GetDlgItem(hDlg, IDC_CS_SCSIMODE), SW_HIDE); - ew (hDlg, IDC_CS_SCSIMODE, FALSE); - ew (hDlg, IDC_CS_CDTVSCSI, e); - ew (hDlg, IDC_CS_PCMCIA, e); - ew (hDlg, IDC_CS_SLOWISFAST, e); - ew (hDlg, IDC_CS_CD32CD, e); - ew (hDlg, IDC_CS_CD32NVRAM, e); - ew (hDlg, IDC_CS_CD32C2P, e); - ew (hDlg, IDC_CS_CDTVCD, e); - ew (hDlg, IDC_CS_CDTVRAM, e); - ew (hDlg, IDC_CS_CDTVRAMEXP, e); - ew (hDlg, IDC_CS_RESETWARNING, e); - ew (hDlg, IDC_CS_NOEHB, e); - ew (hDlg, IDC_CS_BLITTERBUG, e); - ew (hDlg, IDC_CS_KSMIRROR_E0, e); - ew (hDlg, IDC_CS_KSMIRROR_A8, e); - ew (hDlg, IDC_CS_CIAOVERLAY, e); - ew (hDlg, IDC_CS_A1000RAM, e); - ew (hDlg, IDC_CS_DF0IDHW, e); - ew (hDlg, IDC_CS_CIAA_TOD1, e); - ew (hDlg, IDC_CS_CIAA_TOD2, e); - ew (hDlg, IDC_CS_CIAA_TOD3, e); - ew (hDlg, IDC_CS_RTC1, e); - ew (hDlg, IDC_CS_RTC2, e); - ew (hDlg, IDC_CS_RTC3, e); - ew (hDlg, IDC_CS_RTCADJUST, e); + int e = workprefs.cs_compatible ? FALSE : TRUE; + + ew (hDlg, IDC_CS_FATGARY, e); + ew (hDlg, IDC_CS_RAMSEY, e); + ew (hDlg, IDC_CS_AGNUS, e); + ew (hDlg, IDC_CS_DENISE, e); + ew (hDlg, IDC_CS_FATGARYREV, e); + ew (hDlg, IDC_CS_RAMSEYREV, e); + ew (hDlg, IDC_CS_AGNUSREV, e); + ew (hDlg, IDC_CS_DENISEREV, e); + ew (hDlg, IDC_CS_IDE1, e); + ew (hDlg, IDC_CS_IDE2, e); + ew (hDlg, IDC_CS_DMAC, e); + ew (hDlg, IDC_CS_DMAC2, e); + ew (hDlg, IDC_CS_A2091, e); + ew (hDlg, IDC_CS_A4091, e); + ShowWindow (GetDlgItem(hDlg, IDC_CS_SCSIMODE), SW_HIDE); + ew (hDlg, IDC_CS_SCSIMODE, FALSE); + ew (hDlg, IDC_CS_CDTVSCSI, e); + ew (hDlg, IDC_CS_PCMCIA, e); + ew (hDlg, IDC_CS_SLOWISFAST, e); + ew (hDlg, IDC_CS_CD32CD, e); + ew (hDlg, IDC_CS_CD32NVRAM, e); + ew (hDlg, IDC_CS_CD32C2P, e); + ew (hDlg, IDC_CS_CDTVCD, e); + ew (hDlg, IDC_CS_CDTVRAM, e); + ew (hDlg, IDC_CS_CDTVRAMEXP, e); + ew (hDlg, IDC_CS_RESETWARNING, e); + ew (hDlg, IDC_CS_NOEHB, e); + ew (hDlg, IDC_CS_BLITTERBUG, e); + ew (hDlg, IDC_CS_KSMIRROR_E0, e); + ew (hDlg, IDC_CS_KSMIRROR_A8, e); + ew (hDlg, IDC_CS_CIAOVERLAY, e); + ew (hDlg, IDC_CS_A1000RAM, e); + ew (hDlg, IDC_CS_DF0IDHW, e); + ew (hDlg, IDC_CS_CIAA_TOD1, e); + ew (hDlg, IDC_CS_CIAA_TOD2, e); + ew (hDlg, IDC_CS_CIAA_TOD3, e); + ew (hDlg, IDC_CS_RTC1, e); + ew (hDlg, IDC_CS_RTC2, e); + ew (hDlg, IDC_CS_RTC3, e); + ew (hDlg, IDC_CS_RTCADJUST, e); } static INT_PTR CALLBACK ChipsetDlgProc2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; + static int recursive = 0; - switch (msg) { - case WM_INITDIALOG: - pages[CHIPSET2_ID] = hDlg; - currentpage = CHIPSET2_ID; - case WM_USER: - recursive++; - values_to_chipsetdlg2 (hDlg); - enable_for_chipsetdlg2 (hDlg); - recursive--; - break; - case WM_HSCROLL: - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - values_from_chipsetdlg2 (hDlg, msg, wParam, lParam); - enable_for_chipsetdlg2 (hDlg); - recursive--; - break; - } - return FALSE; + switch (msg) { + case WM_INITDIALOG: + pages[CHIPSET2_ID] = hDlg; + currentpage = CHIPSET2_ID; + case WM_USER: + recursive++; + values_to_chipsetdlg2 (hDlg); + enable_for_chipsetdlg2 (hDlg); + recursive--; + break; + case WM_HSCROLL: + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + values_from_chipsetdlg2 (hDlg, msg, wParam, lParam); + enable_for_chipsetdlg2 (hDlg); + recursive--; + break; + } + return FALSE; } static void enable_for_memorydlg (HWND hDlg) { - int z3 = ! workprefs.address_space_24; - int fast = workprefs.chipmem_size <= 0x200000; - int rtg = workprefs.gfxmem_size && full_property_sheet; - int rtg2 = workprefs.gfxmem_size; + int z3 = ! workprefs.address_space_24; + int fast = workprefs.chipmem_size <= 0x200000; + int rtg = workprefs.gfxmem_size && full_property_sheet; + int rtg2 = workprefs.gfxmem_size; #ifndef AUTOCONFIG - z3 = FALSE; - fast = FALSE; + z3 = FALSE; + fast = FALSE; #endif - ew (hDlg, IDC_Z3TEXT, z3); - ew (hDlg, IDC_Z3FASTRAM, z3); - ew (hDlg, IDC_Z3FASTMEM, z3); - ew (hDlg, IDC_FASTMEM, fast); - ew (hDlg, IDC_FASTRAM, fast); - ew (hDlg, IDC_FASTTEXT, fast); - ew (hDlg, IDC_GFXCARDTEXT, z3); - ew (hDlg, IDC_P96RAM, z3); - ew (hDlg, IDC_P96MEM, z3); - ew (hDlg, IDC_MBRAM1, z3); - ew (hDlg, IDC_MBMEM1, z3); - ew (hDlg, IDC_MBRAM2, z3); - ew (hDlg, IDC_MBMEM2, z3); - - ew (hDlg, IDC_RTG_8BIT, rtg); - ew (hDlg, IDC_RTG_16BIT, rtg); - ew (hDlg, IDC_RTG_24BIT, rtg); - ew (hDlg, IDC_RTG_32BIT, rtg); - ew (hDlg, IDC_RTG_MATCH_DEPTH, rtg2); - ew (hDlg, IDC_RTG_SCALE, rtg2); - ew (hDlg, IDC_RTG_SCALE_ALLOW, rtg2); - ew (hDlg, IDC_RTG_SCALE_ASPECTRATIO, rtg2); - ew (hDlg, IDC_RTG_VBLANKRATE, rtg2); + ew (hDlg, IDC_Z3TEXT, z3); + ew (hDlg, IDC_Z3FASTRAM, z3); + ew (hDlg, IDC_Z3FASTMEM, z3); + ew (hDlg, IDC_FASTMEM, fast); + ew (hDlg, IDC_FASTRAM, fast); + ew (hDlg, IDC_FASTTEXT, fast); + ew (hDlg, IDC_GFXCARDTEXT, z3); + ew (hDlg, IDC_P96RAM, z3); + ew (hDlg, IDC_P96MEM, z3); + ew (hDlg, IDC_MBRAM1, z3); + ew (hDlg, IDC_MBMEM1, z3); + ew (hDlg, IDC_MBRAM2, z3); + ew (hDlg, IDC_MBMEM2, z3); + + ew (hDlg, IDC_RTG_8BIT, rtg); + ew (hDlg, IDC_RTG_16BIT, rtg); + ew (hDlg, IDC_RTG_24BIT, rtg); + ew (hDlg, IDC_RTG_32BIT, rtg); + ew (hDlg, IDC_RTG_MATCH_DEPTH, rtg2); + ew (hDlg, IDC_RTG_SCALE, rtg2); + ew (hDlg, IDC_RTG_SCALE_ALLOW, rtg2); + ew (hDlg, IDC_RTG_SCALE_ASPECTRATIO, rtg2); + ew (hDlg, IDC_RTG_VBLANKRATE, rtg2); } static int manybits (int v, int mask) { - int i, cnt; + int i, cnt; - cnt = 0; - for (i = 0; i < 32; i++) { - if (((1 << i) & mask) & v) - cnt++; - } - if (cnt > 1) - return 1; - return 0; + cnt = 0; + for (i = 0; i < 32; i++) { + if (((1 << i) & mask) & v) + cnt++; + } + if (cnt > 1) + return 1; + return 0; } static void values_to_memorydlg (HWND hDlg) { - uae_u32 mem_size = 0; + uae_u32 mem_size = 0; uae_u32 v; - switch (workprefs.chipmem_size) { - case 0x00040000: mem_size = 0; break; - case 0x00080000: mem_size = 1; break; - case 0x00100000: mem_size = 2; break; - case 0x00180000: mem_size = 3; break; - case 0x00200000: mem_size = 4; break; - case 0x00400000: mem_size = 5; break; - case 0x00800000: mem_size = 6; break; - } - SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_CHIPRAM, memsize_names[msi_chip[mem_size]]); - - mem_size = 0; - switch (workprefs.fastmem_size) { - case 0x00000000: mem_size = 0; break; - case 0x00100000: mem_size = 1; break; - case 0x00200000: mem_size = 2; break; - case 0x00400000: mem_size = 3; break; - case 0x00800000: mem_size = 4; break; - case 0x01000000: mem_size = 5; break; - } - SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_FASTRAM, memsize_names[msi_fast[mem_size]]); - - mem_size = 0; - switch (workprefs.bogomem_size) { - case 0x00000000: mem_size = 0; break; - case 0x00080000: mem_size = 1; break; - case 0x00100000: mem_size = 2; break; - case 0x00180000: mem_size = 3; break; - case 0x001C0000: mem_size = 4; break; - } - SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_SLOWRAM, memsize_names[msi_bogo[mem_size]]); - - mem_size = 0; - v = workprefs.z3fastmem_size + workprefs.z3fastmem2_size; - if (v < 0x00100000) - mem_size = 0; - else if (v < 0x00200000) - mem_size = 1; - else if (v < 0x00400000) - mem_size = 2; - else if (v < 0x00800000) - mem_size = 3; - else if (v < 0x01000000) - mem_size = 4; - else if (v < 0x02000000) - mem_size = 5; - else if (v < 0x04000000) - mem_size = 6; - else if (v < 0x08000000) - mem_size = 7; - else if (v < 0x10000000) - mem_size = 8; - else if (v < 0x18000000) - mem_size = 9; - else if (v < 0x20000000) - mem_size = 10; - else if (v < 0x30000000) - mem_size = 11; - else if (v < 0x40000000) - mem_size = 12; - else if (v < 0x60000000) - mem_size = 13; - else if (v < 0x80000000) - mem_size = 14; - else - mem_size = 15; - SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_Z3FASTRAM, memsize_names[msi_z3fast[mem_size]]); - - mem_size = 0; - switch (workprefs.gfxmem_size) { - case 0x00000000: mem_size = 0; break; - case 0x00100000: mem_size = 1; break; - case 0x00200000: mem_size = 2; break; - case 0x00400000: mem_size = 3; break; - case 0x00800000: mem_size = 4; break; - case 0x01000000: mem_size = 5; break; - case 0x02000000: mem_size = 6; break; - case 0x04000000: mem_size = 7; break; - case 0x08000000: mem_size = 8; break; - case 0x10000000: mem_size = 9; break; - case 0x20000000: mem_size = 10; break; - case 0x40000000: mem_size = 11; break; - } - SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_P96RAM, memsize_names[msi_gfx[mem_size]]); - SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_SETCURSEL, (workprefs.picasso96_modeflags & RGBFF_CLUT) ? 1 : 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_SETCURSEL, - (manybits (workprefs.picasso96_modeflags, RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC)) ? 1 : - (workprefs.picasso96_modeflags & RGBFF_R5G6B5PC) ? 2 : - (workprefs.picasso96_modeflags & RGBFF_R5G5B5PC) ? 3 : - (workprefs.picasso96_modeflags & RGBFF_R5G6B5) ? 4 : - (workprefs.picasso96_modeflags & RGBFF_R5G5B5) ? 5 : - (workprefs.picasso96_modeflags & RGBFF_B5G6R5PC) ? 6 : - (workprefs.picasso96_modeflags & RGBFF_B5G5R5PC) ? 7 : 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_SETCURSEL, - (manybits (workprefs.picasso96_modeflags, RGBFF_R8G8B8 | RGBFF_B8G8R8)) ? 1 : - (workprefs.picasso96_modeflags & RGBFF_R8G8B8) ? 2 : - (workprefs.picasso96_modeflags & RGBFF_B8G8R8) ? 3 : 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_SETCURSEL, - (manybits (workprefs.picasso96_modeflags, RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8)) ? 1 : - (workprefs.picasso96_modeflags & RGBFF_A8R8G8B8) ? 2 : - (workprefs.picasso96_modeflags & RGBFF_A8B8G8R8) ? 3 : - (workprefs.picasso96_modeflags & RGBFF_R8G8B8A8) ? 4 : - (workprefs.picasso96_modeflags & RGBFF_B8G8R8A8) ? 5 : 0, 0); - if (workprefs.win32_rtgvblankrate <= 0 || - workprefs.win32_rtgvblankrate == 50 || - workprefs.win32_rtgvblankrate == 60 || - workprefs.win32_rtgvblankrate == 70 || - workprefs.win32_rtgvblankrate == 75) { - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_SETCURSEL, - (workprefs.win32_rtgvblankrate == 0) ? 1 : - (workprefs.win32_rtgvblankrate == -1) ? 2 : - (workprefs.win32_rtgvblankrate == -2) ? 0 : - (workprefs.win32_rtgvblankrate == 50) ? 3 : - (workprefs.win32_rtgvblankrate == 60) ? 4 : - (workprefs.win32_rtgvblankrate == 70) ? 5 : - (workprefs.win32_rtgvblankrate == 75) ? 6 : 0, 0); - } else { - TCHAR tmp[10]; - _stprintf (tmp, L"%d", workprefs.win32_rtgvblankrate); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, WM_SETTEXT, 0, (LPARAM)tmp); - } - - - CheckDlgButton (hDlg, IDC_RTG_SCALE, workprefs.win32_rtgscaleifsmall); - CheckDlgButton (hDlg, IDC_RTG_SCALE_ALLOW, workprefs.win32_rtgallowscaling); - CheckDlgButton (hDlg, IDC_RTG_MATCH_DEPTH, workprefs.win32_rtgmatchdepth); - - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_SETCURSEL, - (workprefs.win32_rtgscaleaspectratio == 0) ? 0 : - (workprefs.win32_rtgscaleaspectratio == 4 * 256 + 3) ? 2 : - (workprefs.win32_rtgscaleaspectratio == 5 * 256 + 4) ? 3 : - (workprefs.win32_rtgscaleaspectratio == 15 * 256 + 9) ? 4 : - (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 9) ? 5 : - (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 10) ? 6 : 1, 0); - - mem_size = 0; - switch (workprefs.mbresmem_low_size) { - case 0x00000000: mem_size = 0; break; - case 0x00100000: mem_size = 1; break; - case 0x00200000: mem_size = 2; break; - case 0x00400000: mem_size = 3; break; - case 0x00800000: mem_size = 4; break; - case 0x01000000: mem_size = 5; break; - case 0x02000000: mem_size = 6; break; - case 0x04000000: mem_size = 7; break; - } - SendDlgItemMessage (hDlg, IDC_MBMEM1, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_MBRAM1, memsize_names[msi_gfx[mem_size]]); - - mem_size = 0; - switch (workprefs.mbresmem_high_size) { - case 0x00000000: mem_size = 0; break; - case 0x00100000: mem_size = 1; break; - case 0x00200000: mem_size = 2; break; - case 0x00400000: mem_size = 3; break; - case 0x00800000: mem_size = 4; break; - case 0x01000000: mem_size = 5; break; - case 0x02000000: mem_size = 6; break; - case 0x04000000: mem_size = 7; break; - } - SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETPOS, TRUE, mem_size); - SetDlgItemText (hDlg, IDC_MBRAM2, memsize_names[msi_gfx[mem_size]]); + switch (workprefs.chipmem_size) { + case 0x00040000: mem_size = 0; break; + case 0x00080000: mem_size = 1; break; + case 0x00100000: mem_size = 2; break; + case 0x00180000: mem_size = 3; break; + case 0x00200000: mem_size = 4; break; + case 0x00400000: mem_size = 5; break; + case 0x00800000: mem_size = 6; break; + } + SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_CHIPRAM, memsize_names[msi_chip[mem_size]]); + + mem_size = 0; + switch (workprefs.fastmem_size) { + case 0x00000000: mem_size = 0; break; + case 0x00100000: mem_size = 1; break; + case 0x00200000: mem_size = 2; break; + case 0x00400000: mem_size = 3; break; + case 0x00800000: mem_size = 4; break; + case 0x01000000: mem_size = 5; break; + } + SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_FASTRAM, memsize_names[msi_fast[mem_size]]); + + mem_size = 0; + switch (workprefs.bogomem_size) { + case 0x00000000: mem_size = 0; break; + case 0x00080000: mem_size = 1; break; + case 0x00100000: mem_size = 2; break; + case 0x00180000: mem_size = 3; break; + case 0x001C0000: mem_size = 4; break; + } + SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_SLOWRAM, memsize_names[msi_bogo[mem_size]]); + + mem_size = 0; + v = workprefs.z3fastmem_size + workprefs.z3fastmem2_size; + if (v < 0x00100000) + mem_size = 0; + else if (v < 0x00200000) + mem_size = 1; + else if (v < 0x00400000) + mem_size = 2; + else if (v < 0x00800000) + mem_size = 3; + else if (v < 0x01000000) + mem_size = 4; + else if (v < 0x02000000) + mem_size = 5; + else if (v < 0x04000000) + mem_size = 6; + else if (v < 0x08000000) + mem_size = 7; + else if (v < 0x10000000) + mem_size = 8; + else if (v < 0x18000000) + mem_size = 9; + else if (v < 0x20000000) + mem_size = 10; + else if (v < 0x30000000) + mem_size = 11; + else if (v < 0x40000000) + mem_size = 12; + else if (v < 0x60000000) + mem_size = 13; + else if (v < 0x80000000) + mem_size = 14; + else + mem_size = 15; + SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_Z3FASTRAM, memsize_names[msi_z3fast[mem_size]]); + + mem_size = 0; + switch (workprefs.gfxmem_size) { + case 0x00000000: mem_size = 0; break; + case 0x00100000: mem_size = 1; break; + case 0x00200000: mem_size = 2; break; + case 0x00400000: mem_size = 3; break; + case 0x00800000: mem_size = 4; break; + case 0x01000000: mem_size = 5; break; + case 0x02000000: mem_size = 6; break; + case 0x04000000: mem_size = 7; break; + case 0x08000000: mem_size = 8; break; + case 0x10000000: mem_size = 9; break; + case 0x20000000: mem_size = 10; break; + case 0x40000000: mem_size = 11; break; + } + SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_P96RAM, memsize_names[msi_gfx[mem_size]]); + SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_SETCURSEL, (workprefs.picasso96_modeflags & RGBFF_CLUT) ? 1 : 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_SETCURSEL, + (manybits (workprefs.picasso96_modeflags, RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC)) ? 1 : + (workprefs.picasso96_modeflags & RGBFF_R5G6B5PC) ? 2 : + (workprefs.picasso96_modeflags & RGBFF_R5G5B5PC) ? 3 : + (workprefs.picasso96_modeflags & RGBFF_R5G6B5) ? 4 : + (workprefs.picasso96_modeflags & RGBFF_R5G5B5) ? 5 : + (workprefs.picasso96_modeflags & RGBFF_B5G6R5PC) ? 6 : + (workprefs.picasso96_modeflags & RGBFF_B5G5R5PC) ? 7 : 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_SETCURSEL, + (manybits (workprefs.picasso96_modeflags, RGBFF_R8G8B8 | RGBFF_B8G8R8)) ? 1 : + (workprefs.picasso96_modeflags & RGBFF_R8G8B8) ? 2 : + (workprefs.picasso96_modeflags & RGBFF_B8G8R8) ? 3 : 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_SETCURSEL, + (manybits (workprefs.picasso96_modeflags, RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8)) ? 1 : + (workprefs.picasso96_modeflags & RGBFF_A8R8G8B8) ? 2 : + (workprefs.picasso96_modeflags & RGBFF_A8B8G8R8) ? 3 : + (workprefs.picasso96_modeflags & RGBFF_R8G8B8A8) ? 4 : + (workprefs.picasso96_modeflags & RGBFF_B8G8R8A8) ? 5 : 0, 0); + if (workprefs.win32_rtgvblankrate <= 0 || + workprefs.win32_rtgvblankrate == 50 || + workprefs.win32_rtgvblankrate == 60 || + workprefs.win32_rtgvblankrate == 70 || + workprefs.win32_rtgvblankrate == 75) { + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_SETCURSEL, + (workprefs.win32_rtgvblankrate == 0) ? 1 : + (workprefs.win32_rtgvblankrate == -1) ? 2 : + (workprefs.win32_rtgvblankrate == -2) ? 0 : + (workprefs.win32_rtgvblankrate == 50) ? 3 : + (workprefs.win32_rtgvblankrate == 60) ? 4 : + (workprefs.win32_rtgvblankrate == 70) ? 5 : + (workprefs.win32_rtgvblankrate == 75) ? 6 : 0, 0); + } else { + TCHAR tmp[10]; + _stprintf (tmp, L"%d", workprefs.win32_rtgvblankrate); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, WM_SETTEXT, 0, (LPARAM)tmp); + } + + + CheckDlgButton (hDlg, IDC_RTG_SCALE, workprefs.win32_rtgscaleifsmall); + CheckDlgButton (hDlg, IDC_RTG_SCALE_ALLOW, workprefs.win32_rtgallowscaling); + CheckDlgButton (hDlg, IDC_RTG_MATCH_DEPTH, workprefs.win32_rtgmatchdepth); + + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_SETCURSEL, + (workprefs.win32_rtgscaleaspectratio == 0) ? 0 : + (workprefs.win32_rtgscaleaspectratio == 4 * 256 + 3) ? 2 : + (workprefs.win32_rtgscaleaspectratio == 5 * 256 + 4) ? 3 : + (workprefs.win32_rtgscaleaspectratio == 15 * 256 + 9) ? 4 : + (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 9) ? 5 : + (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 10) ? 6 : 1, 0); + + mem_size = 0; + switch (workprefs.mbresmem_low_size) { + case 0x00000000: mem_size = 0; break; + case 0x00100000: mem_size = 1; break; + case 0x00200000: mem_size = 2; break; + case 0x00400000: mem_size = 3; break; + case 0x00800000: mem_size = 4; break; + case 0x01000000: mem_size = 5; break; + case 0x02000000: mem_size = 6; break; + case 0x04000000: mem_size = 7; break; + } + SendDlgItemMessage (hDlg, IDC_MBMEM1, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_MBRAM1, memsize_names[msi_gfx[mem_size]]); + + mem_size = 0; + switch (workprefs.mbresmem_high_size) { + case 0x00000000: mem_size = 0; break; + case 0x00100000: mem_size = 1; break; + case 0x00200000: mem_size = 2; break; + case 0x00400000: mem_size = 3; break; + case 0x00800000: mem_size = 4; break; + case 0x01000000: mem_size = 5; break; + case 0x02000000: mem_size = 6; break; + case 0x04000000: mem_size = 7; break; + } + SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETPOS, TRUE, mem_size); + SetDlgItemText (hDlg, IDC_MBRAM2, memsize_names[msi_gfx[mem_size]]); } static void fix_values_memorydlg (void) { - if (workprefs.chipmem_size > 0x200000) - workprefs.fastmem_size = 0; + if (workprefs.chipmem_size > 0x200000) + workprefs.fastmem_size = 0; } static void updatez3 (uae_u32 *size1p, uae_u32 *size2p) { - int i; - uae_u32 s1, s2; - - s1 = *size1p; - *size1p = 0; - *size2p = 0; - s2 = 0; - for (i = 32; i >= 0; i--) { - if (s1 & (1 << i)) - break; - } - if (i < 20) - return; - if (s1 == (1 << i)) { - *size1p = s1; - return; - } - s2 = s1 & ((1 << i) - 1); - s1 = 1 << i; - i--; - while (i >= 0) { - if (s2 & (1 << i)) { - s2 = 1 << i; - break; + int i; + uae_u32 s1, s2; + + s1 = *size1p; + *size1p = 0; + *size2p = 0; + s2 = 0; + for (i = 32; i >= 0; i--) { + if (s1 & (1 << i)) + break; } + if (i < 20) + return; + if (s1 == (1 << i)) { + *size1p = s1; + return; + } + s2 = s1 & ((1 << i) - 1); + s1 = 1 << i; i--; - } - if (i < 19) - s2 = 0; - *size1p = s1; - *size2p = s2; + while (i >= 0) { + if (s2 & (1 << i)) { + s2 = 1 << i; + break; + } + i--; + } + if (i < 19) + s2 = 0; + *size1p = s1; + *size2p = s2; } static struct netdriverdata *ndd; static void expansion_net (HWND hDlg) { - int i, cnt; - TCHAR tmp[MAX_DPATH]; - - SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_NETDISCONNECTED, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (!_tcscmp (workprefs.a2065name, L"none")) - SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_SETCURSEL, 0, 0); - cnt = 1; - for (i = 0; ndd && i < MAX_TOTAL_NET_DEVICES; i++) { - if (ndd[i].active) { - TCHAR mac[20]; - _stprintf (mac, L"%02X:%02X:%02X:%02X:%02X:%02X", - ndd[i].mac[0], ndd[i].mac[1], ndd[i].mac[2], ndd[i].mac[3], ndd[i].mac[4], ndd[i].mac[5]); - _stprintf (tmp, L"%s %s", mac, ndd[i].desc); - SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_ADDSTRING, 0, (LPARAM)tmp); - if (!_tcsicmp (workprefs.a2065name, mac) || !_tcsicmp (workprefs.a2065name, ndd[i].name)) - SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_SETCURSEL, cnt, 0); - cnt++; - } - } + int i, cnt; + TCHAR tmp[MAX_DPATH]; + + SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_NETDISCONNECTED, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (!_tcscmp (workprefs.a2065name, L"none")) + SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_SETCURSEL, 0, 0); + cnt = 1; + for (i = 0; ndd && i < MAX_TOTAL_NET_DEVICES; i++) { + if (ndd[i].active) { + TCHAR mac[20]; + _stprintf (mac, L"%02X:%02X:%02X:%02X:%02X:%02X", + ndd[i].mac[0], ndd[i].mac[1], ndd[i].mac[2], ndd[i].mac[3], ndd[i].mac[4], ndd[i].mac[5]); + _stprintf (tmp, L"%s %s", mac, ndd[i].desc); + SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_ADDSTRING, 0, (LPARAM)tmp); + if (!_tcsicmp (workprefs.a2065name, mac) || !_tcsicmp (workprefs.a2065name, ndd[i].name)) + SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_SETCURSEL, cnt, 0); + cnt++; + } + } } static void enable_for_expansiondlg (HWND hDlg) { - int cw, en; + int cw, en; - en = !!full_property_sheet; - cw = catweasel_detect (); - ew (hDlg, IDC_CATWEASEL, cw && en); - ew (hDlg, IDC_SOCKETS, en); - ew (hDlg, IDC_SCSIDEVICE, en); - ew (hDlg, IDC_CATWEASEL, en); - ew (hDlg, IDC_NETDEVICE, en); - ew (hDlg, IDC_SANA2, en); - ew (hDlg, IDC_A2065, en); - ew (hDlg, IDC_NETDEVICE, en && workprefs.a2065name[0]); + en = !!full_property_sheet; + cw = catweasel_detect (); + ew (hDlg, IDC_CATWEASEL, cw && en); + ew (hDlg, IDC_SOCKETS, en); + ew (hDlg, IDC_SCSIDEVICE, en); + ew (hDlg, IDC_CATWEASEL, en); + ew (hDlg, IDC_NETDEVICE, en); + ew (hDlg, IDC_SANA2, en); + ew (hDlg, IDC_A2065, en); + ew (hDlg, IDC_NETDEVICE, en && workprefs.a2065name[0]); } static void values_to_expansiondlg (HWND hDlg) { - int cw; + int cw; - CheckDlgButton (hDlg, IDC_SOCKETS, workprefs.socket_emu); - CheckDlgButton (hDlg, IDC_CATWEASEL, workprefs.catweasel); - CheckDlgButton (hDlg, IDC_SCSIDEVICE, workprefs.scsi == 1); - CheckDlgButton (hDlg, IDC_SANA2, workprefs.sana2); - CheckDlgButton (hDlg, IDC_A2065, workprefs.a2065name[0] ? 1 : 0); - cw = catweasel_detect (); - ew (hDlg, IDC_CATWEASEL, cw); - if (!cw && workprefs.catweasel < 100) - workprefs.catweasel = 0; + CheckDlgButton (hDlg, IDC_SOCKETS, workprefs.socket_emu); + CheckDlgButton (hDlg, IDC_CATWEASEL, workprefs.catweasel); + CheckDlgButton (hDlg, IDC_SCSIDEVICE, workprefs.scsi == 1); + CheckDlgButton (hDlg, IDC_SANA2, workprefs.sana2); + CheckDlgButton (hDlg, IDC_A2065, workprefs.a2065name[0] ? 1 : 0); + cw = catweasel_detect (); + ew (hDlg, IDC_CATWEASEL, cw); + if (!cw && workprefs.catweasel < 100) + workprefs.catweasel = 0; } static INT_PTR CALLBACK ExpansionDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - int v; - TCHAR tmp[100]; - static int recursive = 0; - static int enumerated; + int v; + TCHAR tmp[100]; + static int recursive = 0; + static int enumerated; - switch (msg) - { + switch (msg) + { case WM_INITDIALOG: - pages[EXPANSION_ID] = hDlg; - currentpage = EXPANSION_ID; - - if (!enumerated) { - uaenet_enumerate (&ndd, NULL); - enumerated = 1; - } - expansion_net (hDlg); - WIN32GUI_LoadUIString(IDS_ALL, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)L"(8bit)"); - SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)L"8-bit (*)"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"(15/16bit)"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G6B5PC (*)"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G5B5PC"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G6B5"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G5B5"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"B5G6R5PC"); - SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"B5G5R5PC"); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"(24bit)"); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"R8G8B8"); - SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"B8G8R8"); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"(32bit)"); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"A8R8G8B8"); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"A8B8G8R8"); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"R8G8B8A8"); - SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"B8G8R8A8 (*)"); - SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_P96_MEM, MAX_P96_MEM)); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"4:3"); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"5:4"); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"15:9"); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"16:9"); - SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"16:10"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Disabled"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Chipset"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Real"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"50"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"60"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"70"); - SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"75"); + pages[EXPANSION_ID] = hDlg; + currentpage = EXPANSION_ID; + + if (!enumerated) { + uaenet_enumerate (&ndd, NULL); + enumerated = 1; + } + expansion_net (hDlg); + WIN32GUI_LoadUIString(IDS_ALL, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)L"(8bit)"); + SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_ADDSTRING, 0, (LPARAM)L"8-bit (*)"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"(15/16bit)"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G6B5PC (*)"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G5B5PC"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G6B5"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"R5G5B5"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"B5G6R5PC"); + SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_ADDSTRING, 0, (LPARAM)L"B5G5R5PC"); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"(24bit)"); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"R8G8B8"); + SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_ADDSTRING, 0, (LPARAM)L"B8G8R8"); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"(32bit)"); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"A8R8G8B8"); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"A8B8G8R8"); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"R8G8B8A8"); + SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_ADDSTRING, 0, (LPARAM)L"B8G8R8A8 (*)"); + SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_P96_MEM, MAX_P96_MEM)); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"4:3"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"5:4"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"15:9"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"16:9"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)L"16:10"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Disabled"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Chipset"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"Real"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"50"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"60"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"70"); + SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_ADDSTRING, 0, (LPARAM)L"75"); case WM_USER: - recursive++; - values_to_expansiondlg (hDlg); - enable_for_expansiondlg (hDlg); - values_to_memorydlg (hDlg); - enable_for_memorydlg (hDlg); - recursive--; - break; + recursive++; + values_to_expansiondlg (hDlg); + enable_for_expansiondlg (hDlg); + values_to_memorydlg (hDlg); + enable_for_memorydlg (hDlg); + recursive--; + break; case WM_HSCROLL: - workprefs.gfxmem_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_P96MEM), TBM_GETPOS, 0, 0)]]; - values_to_memorydlg (hDlg); - enable_for_memorydlg (hDlg); - break; + workprefs.gfxmem_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_P96MEM), TBM_GETPOS, 0, 0)]]; + values_to_memorydlg (hDlg); + enable_for_memorydlg (hDlg); + break; case WM_COMMAND: - { - if (recursive > 0) - break; - recursive++; - switch (LOWORD (wParam)) - { - case IDC_RTG_MATCH_DEPTH: - workprefs.win32_rtgmatchdepth = IsDlgButtonChecked (hDlg, IDC_RTG_MATCH_DEPTH); - break; - case IDC_RTG_SCALE: - workprefs.win32_rtgscaleifsmall = IsDlgButtonChecked (hDlg, IDC_RTG_SCALE); - break; - case IDC_RTG_SCALE_ALLOW: - workprefs.win32_rtgallowscaling = IsDlgButtonChecked (hDlg, IDC_RTG_SCALE_ALLOW); - break; - case IDC_SOCKETS: - workprefs.socket_emu = IsDlgButtonChecked (hDlg, IDC_SOCKETS); - break; - case IDC_SCSIDEVICE: - workprefs.scsi = IsDlgButtonChecked (hDlg, IDC_SCSIDEVICE) ? 1 : 0; - enable_for_expansiondlg (hDlg); - break; - case IDC_SANA2: - workprefs.sana2 = IsDlgButtonChecked (hDlg, IDC_SANA2) ? 1 : 0; - break; - case IDC_A2065: - if (IsDlgButtonChecked (hDlg, IDC_A2065)) { - _tcscpy (workprefs.a2065name, L"none"); - expansion_net (hDlg); - enable_for_expansiondlg (hDlg); - } else { - ew (hDlg, IDC_NETDEVICE, FALSE); - workprefs.a2065name[0] = 0; - enable_for_expansiondlg (hDlg); + { + if (recursive > 0) + break; + recursive++; + switch (LOWORD (wParam)) + { + case IDC_RTG_MATCH_DEPTH: + workprefs.win32_rtgmatchdepth = IsDlgButtonChecked (hDlg, IDC_RTG_MATCH_DEPTH); + break; + case IDC_RTG_SCALE: + workprefs.win32_rtgscaleifsmall = IsDlgButtonChecked (hDlg, IDC_RTG_SCALE); + break; + case IDC_RTG_SCALE_ALLOW: + workprefs.win32_rtgallowscaling = IsDlgButtonChecked (hDlg, IDC_RTG_SCALE_ALLOW); + break; + case IDC_SOCKETS: + workprefs.socket_emu = IsDlgButtonChecked (hDlg, IDC_SOCKETS); + break; + case IDC_SCSIDEVICE: + workprefs.scsi = IsDlgButtonChecked (hDlg, IDC_SCSIDEVICE) ? 1 : 0; + enable_for_expansiondlg (hDlg); + break; + case IDC_SANA2: + workprefs.sana2 = IsDlgButtonChecked (hDlg, IDC_SANA2) ? 1 : 0; + break; + case IDC_A2065: + if (IsDlgButtonChecked (hDlg, IDC_A2065)) { + _tcscpy (workprefs.a2065name, L"none"); + expansion_net (hDlg); + enable_for_expansiondlg (hDlg); + } else { + ew (hDlg, IDC_NETDEVICE, FALSE); + workprefs.a2065name[0] = 0; + enable_for_expansiondlg (hDlg); + } + break; + case IDC_CATWEASEL: + workprefs.catweasel = IsDlgButtonChecked (hDlg, IDC_CATWEASEL) ? -1 : 0; + break; + } + if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { + uae_u32 mask = workprefs.picasso96_modeflags; + switch (LOWORD (wParam)) + { + case IDC_RTG_SCALE_ASPECTRATIO: + v = SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + if (v == 0) + workprefs.win32_rtgscaleaspectratio = 0; + if (v == 1) + workprefs.win32_rtgscaleaspectratio = -1; + if (v == 2) + workprefs.win32_rtgscaleaspectratio = 4 * 256 + 3; + if (v == 3) + workprefs.win32_rtgscaleaspectratio = 5 * 256 + 4; + if (v == 4) + workprefs.win32_rtgscaleaspectratio = 15 * 256 + 9; + if (v == 5) + workprefs.win32_rtgscaleaspectratio = 16 * 256 + 9; + if (v == 6) + workprefs.win32_rtgscaleaspectratio = 16 * 256 + 10; + } + break; + case IDC_RTG_8BIT: + v = SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + mask &= ~RGBFF_CLUT; + if (v == 1) + mask |= RGBFF_CLUT; + } + break; + case IDC_RTG_16BIT: + v = SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + mask &= ~(RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC); + if (v == 1) + mask |= RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC; + if (v == 2) + mask |= RGBFF_R5G6B5PC; + if (v == 3) + mask |= RGBFF_R5G5B5PC; + if (v == 4) + mask |= RGBFF_R5G6B5; + if (v == 5) + mask |= RGBFF_R5G5B5; + if (v == 6) + mask |= RGBFF_B5G6R5PC; + if (v == 7) + mask |= RGBFF_B5G5R5PC; + } + break; + case IDC_RTG_24BIT: + v = SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + mask &= ~(RGBFF_R8G8B8 | RGBFF_B8G8R8); + if (v == 1) + mask |= RGBFF_R8G8B8 | RGBFF_B8G8R8; + if (v == 2) + mask |= RGBFF_R8G8B8; + if (v == 3) + mask |= RGBFF_B8G8R8; + } + break; + case IDC_RTG_32BIT: + v = SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + mask &= ~(RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8); + if (v == 1) + mask |= RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8; + if (v == 2) + mask |= RGBFF_A8R8G8B8; + if (v == 3) + mask |= RGBFF_A8B8G8R8; + if (v == 4) + mask |= RGBFF_R8G8B8A8; + if (v == 5) + mask |= RGBFF_B8G8R8A8; + } + break; + case IDC_RTG_VBLANKRATE: + tmp[0] = 0; + v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + if (v == 0) { + workprefs.win32_rtgvblankrate = -2; + } else if (v == 1) { + workprefs.win32_rtgvblankrate = 0; + } else if (v == 2) { + workprefs.win32_rtgvblankrate = -1; + } else { + v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETLBTEXT, (WPARAM)v, (LPARAM)tmp); + } + } else { + v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, WM_GETTEXT, (WPARAM)sizeof tmp / sizeof (TCHAR), (LPARAM)tmp); + } + if (tmp[0]) + workprefs.win32_rtgvblankrate = _tstol (tmp); + break; + case IDC_NETDEVICE: + v = SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + if (v == 0) { + _tcscpy (workprefs.a2065name, L"none"); + } else if (ndd) { + v--; + _tcscpy (workprefs.a2065name, ndd[v].name); + } + } + break; + + } + workprefs.picasso96_modeflags = mask; + values_to_memorydlg (hDlg); + } + recursive--; } break; - case IDC_CATWEASEL: - workprefs.catweasel = IsDlgButtonChecked (hDlg, IDC_CATWEASEL) ? -1 : 0; - break; - } - if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { - uae_u32 mask = workprefs.picasso96_modeflags; - switch (LOWORD (wParam)) - { - case IDC_RTG_SCALE_ASPECTRATIO: - v = SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - if (v == 0) - workprefs.win32_rtgscaleaspectratio = 0; - if (v == 1) - workprefs.win32_rtgscaleaspectratio = -1; - if (v == 2) - workprefs.win32_rtgscaleaspectratio = 4 * 256 + 3; - if (v == 3) - workprefs.win32_rtgscaleaspectratio = 5 * 256 + 4; - if (v == 4) - workprefs.win32_rtgscaleaspectratio = 15 * 256 + 9; - if (v == 5) - workprefs.win32_rtgscaleaspectratio = 16 * 256 + 9; - if (v == 6) - workprefs.win32_rtgscaleaspectratio = 16 * 256 + 10; - } - break; - case IDC_RTG_8BIT: - v = SendDlgItemMessage (hDlg, IDC_RTG_8BIT, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - mask &= ~RGBFF_CLUT; - if (v == 1) - mask |= RGBFF_CLUT; - } - break; - case IDC_RTG_16BIT: - v = SendDlgItemMessage (hDlg, IDC_RTG_16BIT, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - mask &= ~(RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC); - if (v == 1) - mask |= RGBFF_R5G6B5PC | RGBFF_R5G6B5PC | RGBFF_R5G5B5PC | RGBFF_R5G6B5 | RGBFF_R5G5B5 | RGBFF_B5G6R5PC | RGBFF_B5G5R5PC; - if (v == 2) - mask |= RGBFF_R5G6B5PC; - if (v == 3) - mask |= RGBFF_R5G5B5PC; - if (v == 4) - mask |= RGBFF_R5G6B5; - if (v == 5) - mask |= RGBFF_R5G5B5; - if (v == 6) - mask |= RGBFF_B5G6R5PC; - if (v == 7) - mask |= RGBFF_B5G5R5PC; - } - break; - case IDC_RTG_24BIT: - v = SendDlgItemMessage (hDlg, IDC_RTG_24BIT, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - mask &= ~(RGBFF_R8G8B8 | RGBFF_B8G8R8); - if (v == 1) - mask |= RGBFF_R8G8B8 | RGBFF_B8G8R8; - if (v == 2) - mask |= RGBFF_R8G8B8; - if (v == 3) - mask |= RGBFF_B8G8R8; - } - break; - case IDC_RTG_32BIT: - v = SendDlgItemMessage (hDlg, IDC_RTG_32BIT, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - mask &= ~(RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8); - if (v == 1) - mask |= RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8; - if (v == 2) - mask |= RGBFF_A8R8G8B8; - if (v == 3) - mask |= RGBFF_A8B8G8R8; - if (v == 4) - mask |= RGBFF_R8G8B8A8; - if (v == 5) - mask |= RGBFF_B8G8R8A8; - } - break; - case IDC_RTG_VBLANKRATE: - tmp[0] = 0; - v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - if (v == 0) { - workprefs.win32_rtgvblankrate = -2; - } else if (v == 1) { - workprefs.win32_rtgvblankrate = 0; - } else if (v == 2) { - workprefs.win32_rtgvblankrate = -1; - } else { - v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, CB_GETLBTEXT, (WPARAM)v, (LPARAM)tmp); - } - } else { - v = SendDlgItemMessage (hDlg, IDC_RTG_VBLANKRATE, WM_GETTEXT, (WPARAM)sizeof tmp / sizeof (TCHAR), (LPARAM)tmp); - } - if (tmp[0]) - workprefs.win32_rtgvblankrate = _tstol (tmp); - break; - case IDC_NETDEVICE: - v = SendDlgItemMessage (hDlg, IDC_NETDEVICE, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - if (v == 0) { - _tcscpy (workprefs.a2065name, L"none"); - } else if (ndd) { - v--; - _tcscpy (workprefs.a2065name, ndd[v].name); - } - } - break; - - } - workprefs.picasso96_modeflags = mask; - values_to_memorydlg (hDlg); - } - recursive--; } - break; - } - return FALSE; + return FALSE; } static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; + static int recursive = 0; - switch (msg) - { + switch (msg) + { case WM_INITDIALOG: - pages[MEMORY_ID] = hDlg; - currentpage = MEMORY_ID; - SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CHIP_MEM, MAX_CHIP_MEM)); - SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_FAST_MEM, MAX_FAST_MEM)); - SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SLOW_MEM, MAX_SLOW_MEM)); - SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_Z3_MEM, MAX_Z3_MEM)); - SendDlgItemMessage (hDlg, IDC_MBMEM1, TBM_SETRANGE, TRUE, MAKELONG (MIN_MB_MEM, MAX_MB_MEM)); - SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETRANGE, TRUE, MAKELONG (MIN_MB_MEM, MAX_MB_MEM)); + pages[MEMORY_ID] = hDlg; + currentpage = MEMORY_ID; + SendDlgItemMessage (hDlg, IDC_CHIPMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_CHIP_MEM, MAX_CHIP_MEM)); + SendDlgItemMessage (hDlg, IDC_FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_FAST_MEM, MAX_FAST_MEM)); + SendDlgItemMessage (hDlg, IDC_SLOWMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SLOW_MEM, MAX_SLOW_MEM)); + SendDlgItemMessage (hDlg, IDC_Z3FASTMEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_Z3_MEM, MAX_Z3_MEM)); + SendDlgItemMessage (hDlg, IDC_MBMEM1, TBM_SETRANGE, TRUE, MAKELONG (MIN_MB_MEM, MAX_MB_MEM)); + SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETRANGE, TRUE, MAKELONG (MIN_MB_MEM, MAX_MB_MEM)); case WM_USER: - recursive++; - fix_values_memorydlg (); - values_to_memorydlg (hDlg); - enable_for_memorydlg (hDlg); - recursive--; - break; + recursive++; + fix_values_memorydlg (); + values_to_memorydlg (hDlg); + enable_for_memorydlg (hDlg); + recursive--; + break; case WM_HSCROLL: - workprefs.chipmem_size = memsizes[msi_chip[SendMessage (GetDlgItem (hDlg, IDC_CHIPMEM), TBM_GETPOS, 0, 0)]]; - workprefs.bogomem_size = memsizes[msi_bogo[SendMessage (GetDlgItem (hDlg, IDC_SLOWMEM), TBM_GETPOS, 0, 0)]]; - workprefs.fastmem_size = memsizes[msi_fast[SendMessage (GetDlgItem (hDlg, IDC_FASTMEM), TBM_GETPOS, 0, 0)]]; - workprefs.z3fastmem_size = memsizes[msi_z3fast[SendMessage (GetDlgItem (hDlg, IDC_Z3FASTMEM), TBM_GETPOS, 0, 0)]]; - updatez3 (&workprefs.z3fastmem_size, &workprefs.z3fastmem2_size); - workprefs.mbresmem_low_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_MBMEM1), TBM_GETPOS, 0, 0)]]; - workprefs.mbresmem_high_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_MBMEM2), TBM_GETPOS, 0, 0)]]; - fix_values_memorydlg (); - values_to_memorydlg (hDlg); - enable_for_memorydlg (hDlg); - break; + workprefs.chipmem_size = memsizes[msi_chip[SendMessage (GetDlgItem (hDlg, IDC_CHIPMEM), TBM_GETPOS, 0, 0)]]; + workprefs.bogomem_size = memsizes[msi_bogo[SendMessage (GetDlgItem (hDlg, IDC_SLOWMEM), TBM_GETPOS, 0, 0)]]; + workprefs.fastmem_size = memsizes[msi_fast[SendMessage (GetDlgItem (hDlg, IDC_FASTMEM), TBM_GETPOS, 0, 0)]]; + workprefs.z3fastmem_size = memsizes[msi_z3fast[SendMessage (GetDlgItem (hDlg, IDC_Z3FASTMEM), TBM_GETPOS, 0, 0)]]; + updatez3 (&workprefs.z3fastmem_size, &workprefs.z3fastmem2_size); + workprefs.mbresmem_low_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_MBMEM1), TBM_GETPOS, 0, 0)]]; + workprefs.mbresmem_high_size = memsizes[msi_gfx[SendMessage (GetDlgItem (hDlg, IDC_MBMEM2), TBM_GETPOS, 0, 0)]]; + fix_values_memorydlg (); + values_to_memorydlg (hDlg); + enable_for_memorydlg (hDlg); + break; case WM_COMMAND: - { - if (recursive > 0) + { + if (recursive > 0) + break; + recursive++; + switch (LOWORD (wParam)) + { + ; + } + if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { + } + recursive--; + } break; - recursive++; - switch (LOWORD (wParam)) - { - ; - } - if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { - } - recursive--; } - break; - } - return FALSE; + return FALSE; } static void addromfiles (UAEREG *fkey, HWND hDlg, DWORD d, TCHAR *path, int type) { - int idx; - TCHAR tmp[MAX_DPATH]; - TCHAR tmp2[MAX_DPATH]; - TCHAR seltmp[MAX_DPATH]; - struct romdata *rdx; - - rdx = scan_single_rom (path); - SendDlgItemMessage(hDlg, d, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)L""); - idx = 0; - seltmp[0] = 0; - for (;fkey;) { - DWORD size = sizeof (tmp) / sizeof (TCHAR); - DWORD size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - if (_tcslen (tmp) == 7 || _tcslen (tmp) == 13) { - int group = 0; - int subitem = 0; - int idx2 = _tstol (tmp + 4); - if (_tcslen (tmp) == 13) { - group = _tstol (tmp + 8); - subitem = _tstol (tmp + 11); - } - if (idx2 >= 0) { - struct romdata *rd = getromdatabyidgroup (idx2, group, subitem); - if (rd && (rd->type & type)) { - getromname (rd, tmp); - if (SendDlgItemMessage (hDlg, d, CB_FINDSTRING, (WPARAM)-1, (LPARAM)tmp) < 0) - SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)tmp); - if (rd == rdx) - _tcscpy (seltmp, tmp); - } - } - } - idx++; - } - if (seltmp[0]) - SendDlgItemMessage (hDlg, d, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)seltmp); - else - SetDlgItemText(hDlg, d, path); -} + int idx; + TCHAR tmp[MAX_DPATH]; + TCHAR tmp2[MAX_DPATH]; + TCHAR seltmp[MAX_DPATH]; + struct romdata *rdx; -static void getromfile (HWND hDlg, DWORD d, TCHAR *path, int size) -{ - LRESULT val = SendDlgItemMessage (hDlg, d, CB_GETCURSEL, 0, 0L); - if (val == CB_ERR) { - SendDlgItemMessage (hDlg, d, WM_GETTEXT, (WPARAM)size, (LPARAM)path); - } else { - TCHAR tmp1[MAX_DPATH]; - struct romdata *rd; - SendDlgItemMessage (hDlg, d, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp1); - path[0] = 0; - rd = getromdatabyname (tmp1); - if (rd) { - struct romlist *rl = getromlistbyromdata(rd); - if (rd->configname) - _stprintf (path, L":%s", rd->configname); - else if (rl) - _tcsncpy (path, rl->path, size); + rdx = scan_single_rom (path); + SendDlgItemMessage(hDlg, d, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)L""); + idx = 0; + seltmp[0] = 0; + for (;fkey;) { + DWORD size = sizeof (tmp) / sizeof (TCHAR); + DWORD size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + if (_tcslen (tmp) == 7 || _tcslen (tmp) == 13) { + int group = 0; + int subitem = 0; + int idx2 = _tstol (tmp + 4); + if (_tcslen (tmp) == 13) { + group = _tstol (tmp + 8); + subitem = _tstol (tmp + 11); + } + if (idx2 >= 0) { + struct romdata *rd = getromdatabyidgroup (idx2, group, subitem); + if (rd && (rd->type & type)) { + getromname (rd, tmp); + if (SendDlgItemMessage (hDlg, d, CB_FINDSTRING, (WPARAM)-1, (LPARAM)tmp) < 0) + SendDlgItemMessage(hDlg, d, CB_ADDSTRING, 0, (LPARAM)tmp); + if (rd == rdx) + _tcscpy (seltmp, tmp); + } + } + } + idx++; + } + if (seltmp[0]) + SendDlgItemMessage (hDlg, d, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)seltmp); + else + SetDlgItemText(hDlg, d, path); +} + +static void getromfile (HWND hDlg, DWORD d, TCHAR *path, int size) +{ + LRESULT val = SendDlgItemMessage (hDlg, d, CB_GETCURSEL, 0, 0L); + if (val == CB_ERR) { + SendDlgItemMessage (hDlg, d, WM_GETTEXT, (WPARAM)size, (LPARAM)path); + } else { + TCHAR tmp1[MAX_DPATH]; + struct romdata *rd; + SendDlgItemMessage (hDlg, d, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp1); + path[0] = 0; + rd = getromdatabyname (tmp1); + if (rd) { + struct romlist *rl = getromlistbyromdata(rd); + if (rd->configname) + _stprintf (path, L":%s", rd->configname); + else if (rl) + _tcsncpy (path, rl->path, size); + } } - } } static void values_from_kickstartdlg (HWND hDlg) { - getromfile (hDlg, IDC_ROMFILE, workprefs.romfile, sizeof (workprefs.romfile) / sizeof (TCHAR)); - getromfile (hDlg, IDC_ROMFILE2, workprefs.romextfile, sizeof (workprefs.romextfile) / sizeof (TCHAR)); - getromfile (hDlg, IDC_CARTFILE, workprefs.cartfile, sizeof (workprefs.cartfile) / sizeof (TCHAR)); + getromfile (hDlg, IDC_ROMFILE, workprefs.romfile, sizeof (workprefs.romfile) / sizeof (TCHAR)); + getromfile (hDlg, IDC_ROMFILE2, workprefs.romextfile, sizeof (workprefs.romextfile) / sizeof (TCHAR)); + getromfile (hDlg, IDC_CARTFILE, workprefs.cartfile, sizeof (workprefs.cartfile) / sizeof (TCHAR)); } static void values_to_kickstartdlg (HWND hDlg) { - UAEREG *fkey; + UAEREG *fkey; - fkey = regcreatetree (NULL, L"DetectedROMs"); - load_keyring(&workprefs, NULL); - addromfiles (fkey, hDlg, IDC_ROMFILE, workprefs.romfile, - ROMTYPE_KICK | ROMTYPE_KICKCD32); - addromfiles (fkey, hDlg, IDC_ROMFILE2, workprefs.romextfile, - ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS); - addromfiles (fkey, hDlg, IDC_CARTFILE, workprefs.cartfile, - ROMTYPE_AR | ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON | ROMTYPE_CD32CART); - regclosetree (fkey); + fkey = regcreatetree (NULL, L"DetectedROMs"); + load_keyring(&workprefs, NULL); + addromfiles (fkey, hDlg, IDC_ROMFILE, workprefs.romfile, + ROMTYPE_KICK | ROMTYPE_KICKCD32); + addromfiles (fkey, hDlg, IDC_ROMFILE2, workprefs.romextfile, + ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS); + addromfiles (fkey, hDlg, IDC_CARTFILE, workprefs.cartfile, + ROMTYPE_AR | ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON | ROMTYPE_CD32CART); + regclosetree (fkey); - SetDlgItemText(hDlg, IDC_FLASHFILE, workprefs.flashfile); - CheckDlgButton(hDlg, IDC_KICKSHIFTER, workprefs.kickshifter); - CheckDlgButton(hDlg, IDC_MAPROM, workprefs.maprom); - //CheckDlgButton(hDlg, IDC_HRTMON, workprefs.cart_internal == 1); + SetDlgItemText(hDlg, IDC_FLASHFILE, workprefs.flashfile); + CheckDlgButton(hDlg, IDC_KICKSHIFTER, workprefs.kickshifter); + CheckDlgButton(hDlg, IDC_MAPROM, workprefs.maprom); + //CheckDlgButton(hDlg, IDC_HRTMON, workprefs.cart_internal == 1); } static void init_kickstart (HWND hDlg) { #if !defined(AUTOCONFIG) - ew (hDlg, IDC_MAPROM), FALSE); + ew (hDlg, IDC_MAPROM), FALSE); #endif #if !defined (CDTV) && !defined (CD32) - ew (hDlg, IDC_FLASHFILE), FALSE); - ew (hDlg, IDC_ROMFILE2), FALSE); + ew (hDlg, IDC_FLASHFILE), FALSE); + ew (hDlg, IDC_ROMFILE2), FALSE); #endif #if !defined (ACTION_REPLAY) - ew (hDlg, IDC_CARTFILE), FALSE); + ew (hDlg, IDC_CARTFILE), FALSE); #endif #if defined (UAE_MINI) - ew (hDlg, IDC_KICKSHIFTER), FALSE); - ew (hDlg, IDC_ROMCHOOSER2), FALSE); - ew (hDlg, IDC_CARTCHOOSER), FALSE); - ew (hDlg, IDC_FLASHCHOOSER), FALSE); + ew (hDlg, IDC_KICKSHIFTER), FALSE); + ew (hDlg, IDC_ROMCHOOSER2), FALSE); + ew (hDlg, IDC_CARTCHOOSER), FALSE); + ew (hDlg, IDC_FLASHCHOOSER), FALSE); #endif - if (!regexiststree (NULL , L"DetectedROMs")) - scan_roms (1); + if (!regexiststree (NULL , L"DetectedROMs")) + scan_roms (1); } static void kickstartfilebuttons (HWND hDlg, WPARAM wParam, TCHAR *path) { - switch (LOWORD(wParam)) - { + switch (LOWORD(wParam)) + { case IDC_KICKCHOOSER: - DiskSelection(hDlg, IDC_ROMFILE, 6, &workprefs, path); - values_to_kickstartdlg (hDlg); - break; + DiskSelection(hDlg, IDC_ROMFILE, 6, &workprefs, path); + values_to_kickstartdlg (hDlg); + break; case IDC_ROMCHOOSER2: - DiskSelection(hDlg, IDC_ROMFILE2, 6, &workprefs, path); - values_to_kickstartdlg (hDlg); - break; + DiskSelection(hDlg, IDC_ROMFILE2, 6, &workprefs, path); + values_to_kickstartdlg (hDlg); + break; case IDC_FLASHCHOOSER: - DiskSelection(hDlg, IDC_FLASHFILE, 11, &workprefs, path); - values_to_kickstartdlg (hDlg); - break; + DiskSelection(hDlg, IDC_FLASHFILE, 11, &workprefs, path); + values_to_kickstartdlg (hDlg); + break; case IDC_CARTCHOOSER: - DiskSelection(hDlg, IDC_CARTFILE, 6, &workprefs, path); - values_to_kickstartdlg (hDlg); - break; - } + DiskSelection(hDlg, IDC_CARTFILE, 6, &workprefs, path); + values_to_kickstartdlg (hDlg); + break; + } } static INT_PTR CALLBACK KickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive; - TCHAR tmp[MAX_DPATH]; - - switch (msg) - { - case WM_INITDIALOG: - { - int ids[] = { IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, -1 }; - pages[KICKSTART_ID] = hDlg; - currentpage = KICKSTART_ID; - init_kickstart (hDlg); - values_to_kickstartdlg (hDlg); - setmultiautocomplete (hDlg, ids); - setac (hDlg, IDC_FLASHFILE); - return TRUE; - } - - case WM_CONTEXTMENU: - { - int id = GetDlgCtrlID((HWND)wParam); - if (id == IDC_KICKCHOOSER || id == IDC_ROMCHOOSER2 - || id == IDC_FLASHCHOOSER || id == IDC_CARTCHOOSER) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR newfile[MAX_DPATH]; - _tcscpy (newfile, s); - kickstartfilebuttons (hDlg, id, newfile); - xfree (s); - } - } - break; - } + static int recursive; + TCHAR tmp[MAX_DPATH]; - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { - switch (LOWORD (wParam)) - { - case IDC_ROMFILE: - case IDC_ROMFILE2: - case IDC_CARTFILE: - values_from_kickstartdlg (hDlg); - break; - } - } - kickstartfilebuttons (hDlg, wParam, NULL); - switch (LOWORD (wParam)) + switch (msg) { - case IDC_FLASHFILE: - GetWindowText (GetDlgItem (hDlg, IDC_FLASHFILE), tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcscpy (workprefs.flashfile, tmp); - break; - - case IDC_KICKSHIFTER: - workprefs.kickshifter = IsDlgButtonChecked(hDlg, IDC_KICKSHIFTER); - break; - - case IDC_MAPROM: - workprefs.maprom = IsDlgButtonChecked(hDlg, IDC_MAPROM) ? 0x0f000000 : 0; - break; + case WM_INITDIALOG: + { + int ids[] = { IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, -1 }; + pages[KICKSTART_ID] = hDlg; + currentpage = KICKSTART_ID; + init_kickstart (hDlg); + values_to_kickstartdlg (hDlg); + setmultiautocomplete (hDlg, ids); + setac (hDlg, IDC_FLASHFILE); + return TRUE; + } + + case WM_CONTEXTMENU: + { + int id = GetDlgCtrlID((HWND)wParam); + if (id == IDC_KICKCHOOSER || id == IDC_ROMCHOOSER2 + || id == IDC_FLASHCHOOSER || id == IDC_CARTCHOOSER) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR newfile[MAX_DPATH]; + _tcscpy (newfile, s); + kickstartfilebuttons (hDlg, id, newfile); + xfree (s); + } + } + break; + } + + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + switch (LOWORD (wParam)) + { + case IDC_ROMFILE: + case IDC_ROMFILE2: + case IDC_CARTFILE: + values_from_kickstartdlg (hDlg); + break; + } + } + kickstartfilebuttons (hDlg, wParam, NULL); + switch (LOWORD (wParam)) + { + case IDC_FLASHFILE: + GetWindowText (GetDlgItem (hDlg, IDC_FLASHFILE), tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcscpy (workprefs.flashfile, tmp); + break; + + case IDC_KICKSHIFTER: + workprefs.kickshifter = IsDlgButtonChecked(hDlg, IDC_KICKSHIFTER); + break; + + case IDC_MAPROM: + workprefs.maprom = IsDlgButtonChecked(hDlg, IDC_MAPROM) ? 0x0f000000 : 0; + break; #if 0 - case IDC_HRTMON: - workprefs.cart_internal = IsDlgButtonChecked(hDlg, IDC_HRTMON) ? 1 : 0; - ew (hDlg, IDC_CARTFILE, workprefs.cart_internal == 1 ? FALSE : TRUE); - break; + case IDC_HRTMON: + workprefs.cart_internal = IsDlgButtonChecked(hDlg, IDC_HRTMON) ? 1 : 0; + ew (hDlg, IDC_CARTFILE, workprefs.cart_internal == 1 ? FALSE : TRUE); + break; #endif + } + recursive--; + break; } - recursive--; - break; - } - return FALSE; + return FALSE; } static void enable_for_miscdlg (HWND hDlg) { - ew (hDlg, IDC_DD_SURFACETYPE, full_property_sheet); - if (!full_property_sheet) { - ew (hDlg, IDC_JULIAN, TRUE); - ew (hDlg, IDC_CTRLF11, TRUE); - ew (hDlg, IDC_SHOWGUI, FALSE); - ew (hDlg, IDC_NOSPEED, TRUE); - ew (hDlg, IDC_NOSPEEDPAUSE, TRUE); - ew (hDlg, IDC_NOSOUND, TRUE); - ew (hDlg, IDC_DOSAVESTATE, TRUE); - ew (hDlg, IDC_SCSIMODE, FALSE); - ew (hDlg, IDC_CLOCKSYNC, FALSE); - ew (hDlg, IDC_STATE_CAPTURE, FALSE); - ew (hDlg, IDC_STATE_RATE, FALSE); - ew (hDlg, IDC_STATE_BUFFERSIZE, FALSE); - ew (hDlg, IDC_LANGUAGE, FALSE); - } else { + ew (hDlg, IDC_DD_SURFACETYPE, full_property_sheet); + if (!full_property_sheet) { + ew (hDlg, IDC_JULIAN, TRUE); + ew (hDlg, IDC_CTRLF11, TRUE); + ew (hDlg, IDC_SHOWGUI, FALSE); + ew (hDlg, IDC_NOSPEED, TRUE); + ew (hDlg, IDC_NOSPEEDPAUSE, TRUE); + ew (hDlg, IDC_NOSOUND, TRUE); + ew (hDlg, IDC_DOSAVESTATE, TRUE); + ew (hDlg, IDC_SCSIMODE, FALSE); + ew (hDlg, IDC_CLOCKSYNC, FALSE); + ew (hDlg, IDC_STATE_CAPTURE, FALSE); + ew (hDlg, IDC_STATE_RATE, FALSE); + ew (hDlg, IDC_STATE_BUFFERSIZE, FALSE); + ew (hDlg, IDC_LANGUAGE, FALSE); + } else { #if !defined (SCSIEMU) - EnableWindow (GetDlgItem(hDlg, IDC_SCSIMODE), TRUE); + EnableWindow (GetDlgItem(hDlg, IDC_SCSIMODE), TRUE); #endif - ew (hDlg, IDC_DOSAVESTATE, FALSE); - ew (hDlg, IDC_STATE_RATE, workprefs.statecapture ? TRUE : FALSE); - ew (hDlg, IDC_STATE_BUFFERSIZE, workprefs.statecapture ? TRUE : FALSE); - } - ew (hDlg, IDC_ASSOCIATELIST, !rp_isactive ()); - ew (hDlg, IDC_ASSOCIATE_ON, !rp_isactive ()); - ew (hDlg, IDC_ASSOCIATE_OFF, !rp_isactive ()); + ew (hDlg, IDC_DOSAVESTATE, FALSE); + ew (hDlg, IDC_STATE_RATE, workprefs.statecapture ? TRUE : FALSE); + ew (hDlg, IDC_STATE_BUFFERSIZE, workprefs.statecapture ? TRUE : FALSE); + } + ew (hDlg, IDC_ASSOCIATELIST, !rp_isactive ()); + ew (hDlg, IDC_ASSOCIATE_ON, !rp_isactive ()); + ew (hDlg, IDC_ASSOCIATE_OFF, !rp_isactive ()); } static void misc_kbled (HWND hDlg, int v, int nv) { - TCHAR *defname = v == IDC_KBLED1 ? L"(NumLock)" : v == IDC_KBLED2 ? L"(CapsLock)" : L"(ScrollLock)"; - SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)defname); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"POWER"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF0"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF1"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF2"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF3"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"HD"); - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"CD"); - SendDlgItemMessage (hDlg, v, CB_SETCURSEL, nv, 0); + TCHAR *defname = v == IDC_KBLED1 ? L"(NumLock)" : v == IDC_KBLED2 ? L"(CapsLock)" : L"(ScrollLock)"; + SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)defname); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"POWER"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF0"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF1"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF2"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"DF3"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"HD"); + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)L"CD"); + SendDlgItemMessage (hDlg, v, CB_SETCURSEL, nv, 0); } static void misc_getkbled (HWND hDlg, int v, int n) { - LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); - if (nv != CB_ERR) { - workprefs.keyboard_leds[n] = nv; - misc_kbled (hDlg, v, nv); - } - workprefs.keyboard_leds_in_use = workprefs.keyboard_leds[0] | workprefs.keyboard_leds[1] | workprefs.keyboard_leds[2]; + LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); + if (nv != CB_ERR) { + workprefs.keyboard_leds[n] = nv; + misc_kbled (hDlg, v, nv); + } + workprefs.keyboard_leds_in_use = workprefs.keyboard_leds[0] | workprefs.keyboard_leds[1] | workprefs.keyboard_leds[2]; } static void misc_getpri (HWND hDlg, int v, int *n) { - LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); - if (nv != CB_ERR) - *n = nv; + LRESULT nv = SendDlgItemMessage (hDlg, v, CB_GETCURSEL, 0, 0L); + if (nv != CB_ERR) + *n = nv; } static void misc_addpri (HWND hDlg, int v, int pri) { - int i; - - DWORD opri = GetPriorityClass (GetCurrentProcess ()); - ew (hDlg, v, !(opri != IDLE_PRIORITY_CLASS && opri != NORMAL_PRIORITY_CLASS && opri != BELOW_NORMAL_PRIORITY_CLASS && opri != ABOVE_NORMAL_PRIORITY_CLASS)); - SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L); - i = 0; - while (priorities[i].name) { - SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)priorities[i].name); - i++; - } - SendDlgItemMessage (hDlg, v, CB_SETCURSEL, pri, 0); + int i; + + DWORD opri = GetPriorityClass (GetCurrentProcess ()); + ew (hDlg, v, !(opri != IDLE_PRIORITY_CLASS && opri != NORMAL_PRIORITY_CLASS && opri != BELOW_NORMAL_PRIORITY_CLASS && opri != ABOVE_NORMAL_PRIORITY_CLASS)); + SendDlgItemMessage (hDlg, v, CB_RESETCONTENT, 0, 0L); + i = 0; + while (priorities[i].name) { + SendDlgItemMessage (hDlg, v, CB_ADDSTRING, 0, (LPARAM)priorities[i].name); + i++; + } + SendDlgItemMessage (hDlg, v, CB_SETCURSEL, pri, 0); } @@ -6455,359 +6455,359 @@ extern TCHAR *get_aspi_path (int); static void misc_scsi (HWND hDlg) { - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)L"SPTI *"); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)L"SPTI + SCSI SCAN"); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(0)) ? L"AdaptecASPI" : L"(AdaptecASPI)")); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(1)) ? L"NeroASPI" : L"(NeroASPI)")); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(2)) ? L"FrogASPI" : L"(FrogASPI)")); - SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_SETCURSEL, workprefs.win32_uaescsimode - 1, 0); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)L"SPTI *"); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)L"SPTI + SCSI SCAN"); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(0)) ? L"AdaptecASPI" : L"(AdaptecASPI)")); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(1)) ? L"NeroASPI" : L"(NeroASPI)")); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_ADDSTRING, 0, (LPARAM)((get_aspi_path(2)) ? L"FrogASPI" : L"(FrogASPI)")); + SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_SETCURSEL, workprefs.win32_uaescsimode - 1, 0); } static void misc_lang (HWND hDlg) { - int i, idx = 0, cnt = 0, lid; - WORD langid = -1; - - if (regqueryint (NULL, L"Language", &lid)) - langid = (WORD)lid; - SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)L"Autodetect"); - SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)L"English (built-in)"); - if (langid == 0) - idx = 1; - cnt = 2; - for (i = 0; langs[i].name; i++) { - HMODULE hm = language_load (langs[i].id); - if (hm) { - FreeLibrary (hm); - SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)langs[i].name); - if (langs[i].id == langid) - idx = cnt; - cnt++; - } - } - SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_SETCURSEL, idx, 0); + int i, idx = 0, cnt = 0, lid; + WORD langid = -1; + + if (regqueryint (NULL, L"Language", &lid)) + langid = (WORD)lid; + SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)L"Autodetect"); + SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)L"English (built-in)"); + if (langid == 0) + idx = 1; + cnt = 2; + for (i = 0; langs[i].name; i++) { + HMODULE hm = language_load (langs[i].id); + if (hm) { + FreeLibrary (hm); + SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)langs[i].name); + if (langs[i].id == langid) + idx = cnt; + cnt++; + } + } + SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_SETCURSEL, idx, 0); } static void misc_setlang (int v) { - int i; - WORD langid = 0; - v-=2; - if (v >= 0) { - for (i = 0; langs[i].name; i++) { - HMODULE hm = language_load (langs[i].id); - if (hm) { - FreeLibrary(hm); - if (v == 0) { - langid = langs[i].id; - break; - } - v--; - } - } - } - if (v == -2) - langid = -1; - regsetint (NULL, L"Language", langid); - FreeLibrary(hUIDLL); - hUIDLL = NULL; - if (langid >= 0) - hUIDLL = language_load(langid); - restart_requested = 1; - exit_gui(0); + int i; + WORD langid = 0; + v-=2; + if (v >= 0) { + for (i = 0; langs[i].name; i++) { + HMODULE hm = language_load (langs[i].id); + if (hm) { + FreeLibrary(hm); + if (v == 0) { + langid = langs[i].id; + break; + } + v--; + } + } + } + if (v == -2) + langid = -1; + regsetint (NULL, L"Language", langid); + FreeLibrary(hUIDLL); + hUIDLL = NULL; + if (langid >= 0) + hUIDLL = language_load(langid); + restart_requested = 1; + exit_gui(0); } static void values_to_miscdlg (HWND hDlg) { - TCHAR txt[100]; - - if (currentpage == MISC1_ID) { - - CheckDlgButton (hDlg, IDC_ILLEGAL, workprefs.illegal_mem); - CheckDlgButton (hDlg, IDC_SHOWGUI, workprefs.start_gui); - 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_SHOWLEDS, (workprefs.leds_on_screen & STATUSLINE_CHIPSET) ? 1 : 0); - CheckDlgButton (hDlg, IDC_SHOWLEDSRTG, (workprefs.leds_on_screen & STATUSLINE_RTG) ? 1 : 0); - CheckDlgButton (hDlg, IDC_NOTASKBARBUTTON, workprefs.win32_notaskbarbutton); - CheckDlgButton (hDlg, IDC_ALWAYSONTOP, workprefs.win32_alwaysontop); - CheckDlgButton (hDlg, IDC_CLOCKSYNC, workprefs.tod_hack); - CheckDlgButton (hDlg, IDC_POWERSAVE, workprefs.win32_powersavedisabled); - CheckDlgButton (hDlg, IDC_STATE_CAPTURE, workprefs.statecapture); - CheckDlgButton (hDlg, IDC_FASTERRTG, workprefs.picasso96_nocustom); - - misc_kbled (hDlg, IDC_KBLED1, workprefs.keyboard_leds[0]); - misc_kbled (hDlg, IDC_KBLED2, workprefs.keyboard_leds[1]); - misc_kbled (hDlg, IDC_KBLED3, workprefs.keyboard_leds[2]); - CheckDlgButton (hDlg, IDC_KBLED_USB, workprefs.win32_kbledmode); - - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"1"); - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"5"); - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"10"); - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"20"); - SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"30"); - _stprintf (txt, L"%d", workprefs.statecapturerate / 50); - SendDlgItemMessage( hDlg, IDC_STATE_RATE, WM_SETTEXT, 0, (LPARAM)txt); - - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"5"); - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"10"); - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"20"); - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"50"); - SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"100"); - _stprintf (txt, L"%d", workprefs.statecapturebuffersize / (1024 * 1024)); - SendDlgItemMessage( hDlg, IDC_STATE_BUFFERSIZE, WM_SETTEXT, 0, (LPARAM)txt); - - misc_scsi (hDlg); - misc_lang (hDlg); - - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"NonLocalVRAM"); - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"DefaultRAM *"); - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"LocalVRAM"); - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"SystemRAM"); - SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_SETCURSEL, ddforceram, 0); - - } else if (currentpage == MISC2_ID) { - - CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, workprefs.win32_inactive_pause); - CheckDlgButton (hDlg, IDC_INACTIVE_NOSOUND, workprefs.win32_inactive_nosound || workprefs.win32_inactive_pause); - CheckDlgButton (hDlg, IDC_MINIMIZED_PAUSE, workprefs.win32_iconified_pause); - CheckDlgButton (hDlg, IDC_MINIMIZED_NOSOUND, workprefs.win32_iconified_nosound || workprefs.win32_iconified_pause); - misc_addpri (hDlg, IDC_ACTIVE_PRIORITY, workprefs.win32_active_priority); - misc_addpri (hDlg, IDC_INACTIVE_PRIORITY, workprefs.win32_inactive_priority); - misc_addpri (hDlg, IDC_MINIMIZED_PRIORITY, workprefs.win32_iconified_priority); - - } + TCHAR txt[100]; + + if (currentpage == MISC1_ID) { + + CheckDlgButton (hDlg, IDC_ILLEGAL, workprefs.illegal_mem); + CheckDlgButton (hDlg, IDC_SHOWGUI, workprefs.start_gui); + 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_SHOWLEDS, (workprefs.leds_on_screen & STATUSLINE_CHIPSET) ? 1 : 0); + CheckDlgButton (hDlg, IDC_SHOWLEDSRTG, (workprefs.leds_on_screen & STATUSLINE_RTG) ? 1 : 0); + CheckDlgButton (hDlg, IDC_NOTASKBARBUTTON, workprefs.win32_notaskbarbutton); + CheckDlgButton (hDlg, IDC_ALWAYSONTOP, workprefs.win32_alwaysontop); + CheckDlgButton (hDlg, IDC_CLOCKSYNC, workprefs.tod_hack); + CheckDlgButton (hDlg, IDC_POWERSAVE, workprefs.win32_powersavedisabled); + CheckDlgButton (hDlg, IDC_STATE_CAPTURE, workprefs.statecapture); + CheckDlgButton (hDlg, IDC_FASTERRTG, workprefs.picasso96_nocustom); + + misc_kbled (hDlg, IDC_KBLED1, workprefs.keyboard_leds[0]); + misc_kbled (hDlg, IDC_KBLED2, workprefs.keyboard_leds[1]); + misc_kbled (hDlg, IDC_KBLED3, workprefs.keyboard_leds[2]); + CheckDlgButton (hDlg, IDC_KBLED_USB, workprefs.win32_kbledmode); + + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"1"); + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"5"); + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"10"); + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"20"); + SendDlgItemMessage (hDlg, IDC_STATE_RATE, CB_ADDSTRING, 0, (LPARAM)L"30"); + _stprintf (txt, L"%d", workprefs.statecapturerate / 50); + SendDlgItemMessage( hDlg, IDC_STATE_RATE, WM_SETTEXT, 0, (LPARAM)txt); + + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"5"); + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"10"); + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"20"); + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"50"); + SendDlgItemMessage (hDlg, IDC_STATE_BUFFERSIZE, CB_ADDSTRING, 0, (LPARAM)L"100"); + _stprintf (txt, L"%d", workprefs.statecapturebuffersize / (1024 * 1024)); + SendDlgItemMessage( hDlg, IDC_STATE_BUFFERSIZE, WM_SETTEXT, 0, (LPARAM)txt); + + misc_scsi (hDlg); + misc_lang (hDlg); + + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"NonLocalVRAM"); + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"DefaultRAM *"); + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"LocalVRAM"); + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_ADDSTRING, 0, (LPARAM)L"SystemRAM"); + SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_SETCURSEL, ddforceram, 0); + + } else if (currentpage == MISC2_ID) { + + CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, workprefs.win32_inactive_pause); + CheckDlgButton (hDlg, IDC_INACTIVE_NOSOUND, workprefs.win32_inactive_nosound || workprefs.win32_inactive_pause); + CheckDlgButton (hDlg, IDC_MINIMIZED_PAUSE, workprefs.win32_iconified_pause); + CheckDlgButton (hDlg, IDC_MINIMIZED_NOSOUND, workprefs.win32_iconified_nosound || workprefs.win32_iconified_pause); + misc_addpri (hDlg, IDC_ACTIVE_PRIORITY, workprefs.win32_active_priority); + misc_addpri (hDlg, IDC_INACTIVE_PRIORITY, workprefs.win32_inactive_priority); + misc_addpri (hDlg, IDC_MINIMIZED_PRIORITY, workprefs.win32_iconified_priority); + + } } static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - TCHAR txt[100]; - int v, i; - static int recursive; + TCHAR txt[100]; + int v, i; + static int recursive; - if (recursive) - return FALSE; - recursive++; + if (recursive) + return FALSE; + recursive++; - switch (msg) - { + switch (msg) + { - case WM_USER: - values_to_miscdlg (hDlg); - enable_for_miscdlg (hDlg); - recursive--; - return TRUE; + case WM_USER: + values_to_miscdlg (hDlg); + enable_for_miscdlg (hDlg); + recursive--; + return TRUE; - case WM_CONTEXTMENU: - if (GetDlgCtrlID((HWND)wParam) == IDC_DOSAVESTATE) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, s); - xfree (s); - if (DiskSelection(hDlg, wParam, 9, &workprefs, path)) - save_state (savestate_fname, L"Description!"); - } - } else if (GetDlgCtrlID((HWND)wParam) == IDC_DOLOADSTATE) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, s); - xfree (s); - if (DiskSelection(hDlg, wParam, 10, &workprefs, path)) - savestate_state = STATE_DORESTORE; - } - } - break; - - case WM_NOTIFY: - if (((LPNMHDR) lParam)->idFrom == IDC_ASSOCIATELIST) { - int entry, col; - HWND list; - NM_LISTVIEW *nmlistview; - nmlistview = (NM_LISTVIEW *) lParam; - list = nmlistview->hdr.hwndFrom; - if (nmlistview->hdr.code == NM_DBLCLK) { - entry = listview_entry_from_click (list, &col); - exts[entry].enabled = exts[entry].enabled ? 0 : 1; - associate_file_extensions (); - InitializeListView (hDlg); - } - } - break; + case WM_CONTEXTMENU: + if (GetDlgCtrlID((HWND)wParam) == IDC_DOSAVESTATE) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, s); + xfree (s); + if (DiskSelection(hDlg, wParam, 9, &workprefs, path)) + save_state (savestate_fname, L"Description!"); + } + } else if (GetDlgCtrlID((HWND)wParam) == IDC_DOLOADSTATE) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, s); + xfree (s); + if (DiskSelection(hDlg, wParam, 10, &workprefs, path)) + savestate_state = STATE_DORESTORE; + } + } + break; - case WM_COMMAND: - if (currentpage == MISC1_ID) { - if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { - switch (LOWORD (wParam)) - { - case IDC_KBLED1: - misc_getkbled (hDlg, IDC_KBLED1, 0); - break; - case IDC_KBLED2: - misc_getkbled (hDlg, IDC_KBLED2, 1); - break; - case IDC_KBLED3: - misc_getkbled (hDlg, IDC_KBLED3, 2); - break; - case IDC_STATE_RATE: - getcbn (hDlg, IDC_STATE_RATE, txt, sizeof (txt) / sizeof (TCHAR)); - workprefs.statecapturerate = _tstol (txt) * 50; - break; - case IDC_STATE_BUFFERSIZE: - getcbn (hDlg, IDC_STATE_BUFFERSIZE, txt, sizeof (txt) / sizeof (TCHAR)); - break; - case IDC_LANGUAGE: - if (HIWORD (wParam) == CBN_SELENDOK) { - v = SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) - misc_setlang(v); - } - break; - case IDC_DD_SURFACETYPE: - v = SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) { - ddforceram = v; - regsetint (NULL, L"DirectDraw_Secondary", ddforceram); - } - break; - case IDC_SCSIMODE: - v = SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) - workprefs.win32_uaescsimode = v + 1; - break; - } - } - } else if (currentpage == MISC2_ID) { - misc_getpri (hDlg, IDC_ACTIVE_PRIORITY, &workprefs.win32_active_priority); - misc_getpri (hDlg, IDC_INACTIVE_PRIORITY, &workprefs.win32_inactive_priority); - misc_getpri (hDlg, IDC_MINIMIZED_PRIORITY, &workprefs.win32_iconified_priority); - } + case WM_NOTIFY: + if (((LPNMHDR) lParam)->idFrom == IDC_ASSOCIATELIST) { + int entry, col; + HWND list; + NM_LISTVIEW *nmlistview; + nmlistview = (NM_LISTVIEW *) lParam; + list = nmlistview->hdr.hwndFrom; + if (nmlistview->hdr.code == NM_DBLCLK) { + entry = listview_entry_from_click (list, &col); + exts[entry].enabled = exts[entry].enabled ? 0 : 1; + associate_file_extensions (); + InitializeListView (hDlg); + } + } + break; - switch(wParam) - { - case IDC_ASSOCIATE_ON: - for (i = 0; exts[i].ext; i++) - exts[i].enabled = 1; - associate_file_extensions (); - InitializeListView (hDlg); - break; - case IDC_ASSOCIATE_OFF: - for (i = 0; exts[i].ext; i++) - exts[i].enabled = 0; - associate_file_extensions (); - InitializeListView (hDlg); - break; - case IDC_DOSAVESTATE: - if (DiskSelection(hDlg, wParam, 9, &workprefs, 0)) - save_state (savestate_fname, L"Description!"); - break; - case IDC_DOLOADSTATE: - if (DiskSelection(hDlg, wParam, 10, &workprefs, 0)) - savestate_state = STATE_DORESTORE; - break; - case IDC_STATE_CAPTURE: - workprefs.statecapture = IsDlgButtonChecked (hDlg, IDC_STATE_CAPTURE); - enable_for_miscdlg (hDlg); - break; - case IDC_ILLEGAL: - workprefs.illegal_mem = IsDlgButtonChecked (hDlg, IDC_ILLEGAL); - break; - case IDC_JULIAN: - workprefs.win32_middle_mouse = IsDlgButtonChecked(hDlg, IDC_JULIAN); - break; - case IDC_SHOWLEDS: - workprefs.leds_on_screen &= ~STATUSLINE_CHIPSET; - if (IsDlgButtonChecked(hDlg, IDC_SHOWLEDS)) - workprefs.leds_on_screen |= STATUSLINE_CHIPSET; - break; - case IDC_SHOWLEDSRTG: - workprefs.leds_on_screen &= ~STATUSLINE_RTG; - if (IsDlgButtonChecked(hDlg, IDC_SHOWLEDSRTG)) - workprefs.leds_on_screen |= STATUSLINE_RTG; - break; - case IDC_SHOWGUI: - workprefs.start_gui = IsDlgButtonChecked (hDlg, IDC_SHOWGUI); - break; - case IDC_CREATELOGFILE: - workprefs.win32_logfile = IsDlgButtonChecked (hDlg, IDC_CREATELOGFILE); - enable_for_miscdlg(hDlg); - break; - case IDC_POWERSAVE: - workprefs.win32_powersavedisabled = IsDlgButtonChecked (hDlg, IDC_POWERSAVE); - break; - case IDC_INACTIVE_NOSOUND: - if (!IsDlgButtonChecked (hDlg, IDC_INACTIVE_NOSOUND)) - CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, BST_UNCHECKED); - case IDC_INACTIVE_PAUSE: - workprefs.win32_inactive_pause = IsDlgButtonChecked (hDlg, IDC_INACTIVE_PAUSE); - if (workprefs.win32_inactive_pause) - CheckDlgButton (hDlg, IDC_INACTIVE_NOSOUND, BST_CHECKED); - workprefs.win32_inactive_nosound = IsDlgButtonChecked (hDlg, IDC_INACTIVE_NOSOUND); - break; - case IDC_MINIMIZED_NOSOUND: - if (!IsDlgButtonChecked (hDlg, IDC_MINIMIZED_NOSOUND)) - CheckDlgButton (hDlg, IDC_MINIMIZED_PAUSE, BST_UNCHECKED); - case IDC_MINIMIZED_PAUSE: - workprefs.win32_iconified_pause = IsDlgButtonChecked (hDlg, IDC_MINIMIZED_PAUSE); - if (workprefs.win32_iconified_pause) - CheckDlgButton (hDlg, IDC_MINIMIZED_NOSOUND, BST_CHECKED); - workprefs.win32_iconified_nosound = IsDlgButtonChecked (hDlg, IDC_MINIMIZED_NOSOUND); - break; - case IDC_CTRLF11: - workprefs.win32_ctrl_F11_is_quit = IsDlgButtonChecked (hDlg, IDC_CTRLF11); - break; - case IDC_CLOCKSYNC: - workprefs.tod_hack = IsDlgButtonChecked (hDlg, IDC_CLOCKSYNC); - break; - case IDC_NOTASKBARBUTTON: - workprefs.win32_notaskbarbutton = IsDlgButtonChecked (hDlg, IDC_NOTASKBARBUTTON); - break; - case IDC_ALWAYSONTOP: - workprefs.win32_alwaysontop = IsDlgButtonChecked (hDlg, IDC_ALWAYSONTOP); - break; - case IDC_KBLED_USB: - workprefs.win32_kbledmode = IsDlgButtonChecked (hDlg, IDC_KBLED_USB) ? 1 : 0; - break; - case IDC_FASTERRTG: - workprefs.picasso96_nocustom = IsDlgButtonChecked (hDlg, IDC_FASTERRTG); - break; + case WM_COMMAND: + if (currentpage == MISC1_ID) { + if (HIWORD (wParam) == CBN_SELENDOK || HIWORD (wParam) == CBN_KILLFOCUS || HIWORD (wParam) == CBN_EDITCHANGE) { + switch (LOWORD (wParam)) + { + case IDC_KBLED1: + misc_getkbled (hDlg, IDC_KBLED1, 0); + break; + case IDC_KBLED2: + misc_getkbled (hDlg, IDC_KBLED2, 1); + break; + case IDC_KBLED3: + misc_getkbled (hDlg, IDC_KBLED3, 2); + break; + case IDC_STATE_RATE: + getcbn (hDlg, IDC_STATE_RATE, txt, sizeof (txt) / sizeof (TCHAR)); + workprefs.statecapturerate = _tstol (txt) * 50; + break; + case IDC_STATE_BUFFERSIZE: + getcbn (hDlg, IDC_STATE_BUFFERSIZE, txt, sizeof (txt) / sizeof (TCHAR)); + break; + case IDC_LANGUAGE: + if (HIWORD (wParam) == CBN_SELENDOK) { + v = SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) + misc_setlang(v); + } + break; + case IDC_DD_SURFACETYPE: + v = SendDlgItemMessage (hDlg, IDC_DD_SURFACETYPE, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) { + ddforceram = v; + regsetint (NULL, L"DirectDraw_Secondary", ddforceram); + } + break; + case IDC_SCSIMODE: + v = SendDlgItemMessage (hDlg, IDC_SCSIMODE, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) + workprefs.win32_uaescsimode = v + 1; + break; + } + } + } else if (currentpage == MISC2_ID) { + misc_getpri (hDlg, IDC_ACTIVE_PRIORITY, &workprefs.win32_active_priority); + misc_getpri (hDlg, IDC_INACTIVE_PRIORITY, &workprefs.win32_inactive_priority); + misc_getpri (hDlg, IDC_MINIMIZED_PRIORITY, &workprefs.win32_iconified_priority); + } + + switch(wParam) + { + case IDC_ASSOCIATE_ON: + for (i = 0; exts[i].ext; i++) + exts[i].enabled = 1; + associate_file_extensions (); + InitializeListView (hDlg); + break; + case IDC_ASSOCIATE_OFF: + for (i = 0; exts[i].ext; i++) + exts[i].enabled = 0; + associate_file_extensions (); + InitializeListView (hDlg); + break; + case IDC_DOSAVESTATE: + if (DiskSelection(hDlg, wParam, 9, &workprefs, 0)) + save_state (savestate_fname, L"Description!"); + break; + case IDC_DOLOADSTATE: + if (DiskSelection(hDlg, wParam, 10, &workprefs, 0)) + savestate_state = STATE_DORESTORE; + break; + case IDC_STATE_CAPTURE: + workprefs.statecapture = IsDlgButtonChecked (hDlg, IDC_STATE_CAPTURE); + enable_for_miscdlg (hDlg); + break; + case IDC_ILLEGAL: + workprefs.illegal_mem = IsDlgButtonChecked (hDlg, IDC_ILLEGAL); + break; + case IDC_JULIAN: + workprefs.win32_middle_mouse = IsDlgButtonChecked(hDlg, IDC_JULIAN); + break; + case IDC_SHOWLEDS: + workprefs.leds_on_screen &= ~STATUSLINE_CHIPSET; + if (IsDlgButtonChecked(hDlg, IDC_SHOWLEDS)) + workprefs.leds_on_screen |= STATUSLINE_CHIPSET; + break; + case IDC_SHOWLEDSRTG: + workprefs.leds_on_screen &= ~STATUSLINE_RTG; + if (IsDlgButtonChecked(hDlg, IDC_SHOWLEDSRTG)) + workprefs.leds_on_screen |= STATUSLINE_RTG; + break; + case IDC_SHOWGUI: + workprefs.start_gui = IsDlgButtonChecked (hDlg, IDC_SHOWGUI); + break; + case IDC_CREATELOGFILE: + workprefs.win32_logfile = IsDlgButtonChecked (hDlg, IDC_CREATELOGFILE); + enable_for_miscdlg(hDlg); + break; + case IDC_POWERSAVE: + workprefs.win32_powersavedisabled = IsDlgButtonChecked (hDlg, IDC_POWERSAVE); + break; + case IDC_INACTIVE_NOSOUND: + if (!IsDlgButtonChecked (hDlg, IDC_INACTIVE_NOSOUND)) + CheckDlgButton (hDlg, IDC_INACTIVE_PAUSE, BST_UNCHECKED); + case IDC_INACTIVE_PAUSE: + workprefs.win32_inactive_pause = IsDlgButtonChecked (hDlg, IDC_INACTIVE_PAUSE); + if (workprefs.win32_inactive_pause) + CheckDlgButton (hDlg, IDC_INACTIVE_NOSOUND, BST_CHECKED); + workprefs.win32_inactive_nosound = IsDlgButtonChecked (hDlg, IDC_INACTIVE_NOSOUND); + break; + case IDC_MINIMIZED_NOSOUND: + if (!IsDlgButtonChecked (hDlg, IDC_MINIMIZED_NOSOUND)) + CheckDlgButton (hDlg, IDC_MINIMIZED_PAUSE, BST_UNCHECKED); + case IDC_MINIMIZED_PAUSE: + workprefs.win32_iconified_pause = IsDlgButtonChecked (hDlg, IDC_MINIMIZED_PAUSE); + if (workprefs.win32_iconified_pause) + CheckDlgButton (hDlg, IDC_MINIMIZED_NOSOUND, BST_CHECKED); + workprefs.win32_iconified_nosound = IsDlgButtonChecked (hDlg, IDC_MINIMIZED_NOSOUND); + break; + case IDC_CTRLF11: + workprefs.win32_ctrl_F11_is_quit = IsDlgButtonChecked (hDlg, IDC_CTRLF11); + break; + case IDC_CLOCKSYNC: + workprefs.tod_hack = IsDlgButtonChecked (hDlg, IDC_CLOCKSYNC); + break; + case IDC_NOTASKBARBUTTON: + workprefs.win32_notaskbarbutton = IsDlgButtonChecked (hDlg, IDC_NOTASKBARBUTTON); + break; + case IDC_ALWAYSONTOP: + workprefs.win32_alwaysontop = IsDlgButtonChecked (hDlg, IDC_ALWAYSONTOP); + break; + case IDC_KBLED_USB: + workprefs.win32_kbledmode = IsDlgButtonChecked (hDlg, IDC_KBLED_USB) ? 1 : 0; + break; + case IDC_FASTERRTG: + workprefs.picasso96_nocustom = IsDlgButtonChecked (hDlg, IDC_FASTERRTG); + break; + } + recursive--; + return TRUE; } recursive--; - return TRUE; - } - recursive--; - return FALSE; + return FALSE; } static INT_PTR CALLBACK MiscDlgProc1 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - currentpage = MISC1_ID; - if (msg == WM_INITDIALOG) { - pages[MISC1_ID] = hDlg; - values_to_miscdlg (hDlg); - enable_for_miscdlg (hDlg); - return TRUE; - } - return MiscDlgProc (hDlg, msg, wParam, lParam); + currentpage = MISC1_ID; + if (msg == WM_INITDIALOG) { + pages[MISC1_ID] = hDlg; + values_to_miscdlg (hDlg); + enable_for_miscdlg (hDlg); + return TRUE; + } + return MiscDlgProc (hDlg, msg, wParam, lParam); } static INT_PTR CALLBACK MiscDlgProc2 (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - currentpage = MISC2_ID; - if (msg == WM_INITDIALOG) { - pages[MISC2_ID] = hDlg; - InitializeListView (hDlg); - values_to_miscdlg (hDlg); - enable_for_miscdlg (hDlg); - return TRUE; - } - return MiscDlgProc (hDlg, msg, wParam, lParam); + currentpage = MISC2_ID; + if (msg == WM_INITDIALOG) { + pages[MISC2_ID] = hDlg; + InitializeListView (hDlg); + values_to_miscdlg (hDlg); + enable_for_miscdlg (hDlg); + return TRUE; + } + return MiscDlgProc (hDlg, msg, wParam, lParam); } static int cpu_ids[] = { IDC_CPU0, IDC_CPU1, IDC_CPU2, IDC_CPU3, IDC_CPU4, IDC_CPU5 }; @@ -6816,432 +6816,432 @@ static int trust_ids[] = { IDC_TRUST0, IDC_TRUST1, IDC_TRUST1, IDC_TRUST1 }; static void enable_for_cpudlg (HWND hDlg) { - BOOL enable = FALSE; - BOOL cpu_based_enable = FALSE; - BOOL fpu; - - /* These four items only get enabled when adjustable CPU style is enabled */ - ew (hDlg, IDC_SPEED, workprefs.m68k_speed > 0); - ew (hDlg, IDC_COMPATIBLE24, workprefs.cpu_model == 68020); - ew (hDlg, IDC_CS_HOST, !workprefs.cpu_cycle_exact); - ew (hDlg, IDC_CS_68000, !workprefs.cpu_cycle_exact); - ew (hDlg, IDC_CS_ADJUSTABLE, !workprefs.cpu_cycle_exact); - ew (hDlg, IDC_CPUIDLE, workprefs.m68k_speed != 0 ? TRUE : FALSE); + BOOL enable = FALSE; + BOOL cpu_based_enable = FALSE; + BOOL fpu; + + /* These four items only get enabled when adjustable CPU style is enabled */ + ew (hDlg, IDC_SPEED, workprefs.m68k_speed > 0); + ew (hDlg, IDC_COMPATIBLE24, workprefs.cpu_model == 68020); + ew (hDlg, IDC_CS_HOST, !workprefs.cpu_cycle_exact); + ew (hDlg, IDC_CS_68000, !workprefs.cpu_cycle_exact); + ew (hDlg, IDC_CS_ADJUSTABLE, !workprefs.cpu_cycle_exact); + ew (hDlg, IDC_CPUIDLE, workprefs.m68k_speed != 0 ? TRUE : FALSE); #if !defined(CPUEMU_0) || defined(CPUEMU_68000_ONLY) - ew (hDlg, IDC_CPU1, FALSE); - ew (hDlg, IDC_CPU2, FALSE); - ew (hDlg, IDC_CPU3, FALSE); - ew (hDlg, IDC_CPU4, FALSE); - ew (hDlg, IDC_CPU5, FALSE); + ew (hDlg, IDC_CPU1, FALSE); + ew (hDlg, IDC_CPU2, FALSE); + ew (hDlg, IDC_CPU3, FALSE); + ew (hDlg, IDC_CPU4, FALSE); + ew (hDlg, IDC_CPU5, FALSE); #endif - cpu_based_enable = workprefs.cpu_model >= 68020 && - workprefs.address_space_24 == 0; + cpu_based_enable = workprefs.cpu_model >= 68020 && + workprefs.address_space_24 == 0; - enable = cpu_based_enable && workprefs.cachesize; + enable = cpu_based_enable && workprefs.cachesize; #ifndef JIT - enable = FALSE; + enable = FALSE; #endif - ew (hDlg, IDC_TRUST0, enable); - ew (hDlg, IDC_TRUST1, enable); - ew (hDlg, IDC_HARDFLUSH, enable); - ew (hDlg, IDC_CONSTJUMP, enable); - ew (hDlg, IDC_JITFPU, enable); - ew (hDlg, IDC_NOFLAGS, enable); - ew (hDlg, IDC_CS_CACHE_TEXT, enable); - ew (hDlg, IDC_CACHE, enable); - ew (hDlg, IDC_JITENABLE, cpu_based_enable); - ew (hDlg, IDC_COMPATIBLE, !workprefs.cpu_cycle_exact && !workprefs.cachesize); - ew (hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_model > 0); + ew (hDlg, IDC_TRUST0, enable); + ew (hDlg, IDC_TRUST1, enable); + ew (hDlg, IDC_HARDFLUSH, enable); + ew (hDlg, IDC_CONSTJUMP, enable); + ew (hDlg, IDC_JITFPU, enable); + ew (hDlg, IDC_NOFLAGS, enable); + ew (hDlg, IDC_CS_CACHE_TEXT, enable); + ew (hDlg, IDC_CACHE, enable); + ew (hDlg, IDC_JITENABLE, cpu_based_enable); + ew (hDlg, IDC_COMPATIBLE, !workprefs.cpu_cycle_exact && !workprefs.cachesize); + ew (hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_model > 0); #if 0 - ew (hDlg, IDC_CPU_MULTIPLIER, workprefs.cpu_cycle_exact); + ew (hDlg, IDC_CPU_MULTIPLIER, workprefs.cpu_cycle_exact); #endif - ew (hDlg, IDC_CPU_FREQUENCY, workprefs.cpu_cycle_exact); - ew (hDlg, IDC_CPU_FREQUENCY2, workprefs.cpu_cycle_exact && !workprefs.cpu_clock_multiplier); + ew (hDlg, IDC_CPU_FREQUENCY, workprefs.cpu_cycle_exact); + ew (hDlg, IDC_CPU_FREQUENCY2, workprefs.cpu_cycle_exact && !workprefs.cpu_clock_multiplier); - fpu = TRUE; - if (workprefs.cpu_model > 68030 || workprefs.cpu_compatible || workprefs.cpu_cycle_exact) - fpu = FALSE; - ew (hDlg, IDC_FPU1, fpu); - ew (hDlg, IDC_FPU2, fpu); - ew (hDlg, IDC_FPU3, workprefs.cpu_model >= 68040); - ew (hDlg, IDC_MMUENABLE, workprefs.cpu_model == 68040 && workprefs.cachesize == 0); + fpu = TRUE; + if (workprefs.cpu_model > 68030 || workprefs.cpu_compatible || workprefs.cpu_cycle_exact) + fpu = FALSE; + ew (hDlg, IDC_FPU1, fpu); + ew (hDlg, IDC_FPU2, fpu); + ew (hDlg, IDC_FPU3, workprefs.cpu_model >= 68040); + ew (hDlg, IDC_MMUENABLE, workprefs.cpu_model == 68040 && workprefs.cachesize == 0); } static int getcpufreq (int m) { - int f; - - f = workprefs.ntscmode ? 28636360.0 : 28375160.0; - return f * (m >> 8) / 8; + int f; + + f = workprefs.ntscmode ? 28636360.0 : 28375160.0; + return f * (m >> 8) / 8; } static void values_to_cpudlg (HWND hDlg) { - TCHAR cache[8] = L""; - int cpu; - - SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPOS, TRUE, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT ); - SetDlgItemInt( hDlg, IDC_CPUTEXT, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT, FALSE ); - CheckDlgButton (hDlg, IDC_COMPATIBLE, workprefs.cpu_compatible); - CheckDlgButton (hDlg, IDC_COMPATIBLE24, workprefs.address_space_24); - CheckDlgButton (hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_strict); - SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPOS, TRUE, workprefs.cpu_idle == 0 ? 0 : 12 - workprefs.cpu_idle / 15); - cpu = (workprefs.cpu_model - 68000) / 10; - if (cpu >= 5) - cpu--; - CheckRadioButton (hDlg, IDC_CPU0, IDC_CPU5, cpu_ids[cpu]); - CheckRadioButton (hDlg, IDC_FPU0, IDC_FPU3, fpu_ids[workprefs.fpu_model == 0 ? 0 : (workprefs.fpu_model == 68881 ? 1 : (workprefs.fpu_model == 68882 ? 2 : 3))]); - - if (workprefs.m68k_speed == -1) - CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_HOST); - else if (workprefs.m68k_speed == 0) - CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_68000); - else - CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_ADJUSTABLE); - - CheckRadioButton (hDlg, IDC_TRUST0, IDC_TRUST1, trust_ids[workprefs.comptrustbyte]); - - SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPOS, TRUE, workprefs.cachesize / 1024); - _stprintf (cache, L"%d MB", workprefs.cachesize / 1024 ); - SetDlgItemText (hDlg, IDC_CACHETEXT, cache); - - CheckDlgButton (hDlg, IDC_NOFLAGS, workprefs.compnf); - CheckDlgButton (hDlg, IDC_JITFPU, workprefs.compfpu); - CheckDlgButton (hDlg, IDC_HARDFLUSH, workprefs.comp_hardflush); - CheckDlgButton (hDlg, IDC_CONSTJUMP, workprefs.comp_constjump); - CheckDlgButton (hDlg, IDC_JITENABLE, workprefs.cachesize > 0); - CheckDlgButton (hDlg, IDC_MMUENABLE, workprefs.cpu_model == 68040 && workprefs.cachesize == 0 && workprefs.mmu_model == 68040); - - if (workprefs.cpu_cycle_exact) { - if (workprefs.cpu_clock_multiplier) { - TCHAR txt[20]; - double f = getcpufreq (workprefs.cpu_clock_multiplier); - _stprintf (txt, L"%.6f", f / 1000000.0); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt); - } - } else { - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)""); - } + TCHAR cache[8] = L""; + int cpu; + + SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPOS, TRUE, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT ); + SetDlgItemInt( hDlg, IDC_CPUTEXT, workprefs.m68k_speed <= 0 ? 1 : workprefs.m68k_speed / CYCLE_UNIT, FALSE ); + CheckDlgButton (hDlg, IDC_COMPATIBLE, workprefs.cpu_compatible); + CheckDlgButton (hDlg, IDC_COMPATIBLE24, workprefs.address_space_24); + CheckDlgButton (hDlg, IDC_COMPATIBLE_FPU, workprefs.fpu_strict); + SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPOS, TRUE, workprefs.cpu_idle == 0 ? 0 : 12 - workprefs.cpu_idle / 15); + cpu = (workprefs.cpu_model - 68000) / 10; + if (cpu >= 5) + cpu--; + CheckRadioButton (hDlg, IDC_CPU0, IDC_CPU5, cpu_ids[cpu]); + CheckRadioButton (hDlg, IDC_FPU0, IDC_FPU3, fpu_ids[workprefs.fpu_model == 0 ? 0 : (workprefs.fpu_model == 68881 ? 1 : (workprefs.fpu_model == 68882 ? 2 : 3))]); + + if (workprefs.m68k_speed == -1) + CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_HOST); + else if (workprefs.m68k_speed == 0) + CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_68000); + else + CheckRadioButton(hDlg, IDC_CS_HOST, IDC_CS_ADJUSTABLE, IDC_CS_ADJUSTABLE); + + CheckRadioButton (hDlg, IDC_TRUST0, IDC_TRUST1, trust_ids[workprefs.comptrustbyte]); + + SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPOS, TRUE, workprefs.cachesize / 1024); + _stprintf (cache, L"%d MB", workprefs.cachesize / 1024 ); + SetDlgItemText (hDlg, IDC_CACHETEXT, cache); + + CheckDlgButton (hDlg, IDC_NOFLAGS, workprefs.compnf); + CheckDlgButton (hDlg, IDC_JITFPU, workprefs.compfpu); + CheckDlgButton (hDlg, IDC_HARDFLUSH, workprefs.comp_hardflush); + CheckDlgButton (hDlg, IDC_CONSTJUMP, workprefs.comp_constjump); + CheckDlgButton (hDlg, IDC_JITENABLE, workprefs.cachesize > 0); + CheckDlgButton (hDlg, IDC_MMUENABLE, workprefs.cpu_model == 68040 && workprefs.cachesize == 0 && workprefs.mmu_model == 68040); + + if (workprefs.cpu_cycle_exact) { + if (workprefs.cpu_clock_multiplier) { + TCHAR txt[20]; + double f = getcpufreq (workprefs.cpu_clock_multiplier); + _stprintf (txt, L"%.6f", f / 1000000.0); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt); + } + } else { + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)""); + } } static void values_from_cpudlg (HWND hDlg) { - int newcpu, newfpu, newtrust, oldcache, jitena, idx; - static int cachesize_prev, trust_prev; - - workprefs.cpu_compatible = workprefs.cpu_cycle_exact | (IsDlgButtonChecked (hDlg, IDC_COMPATIBLE) ? 1 : 0); - workprefs.fpu_strict = IsDlgButtonChecked (hDlg, IDC_COMPATIBLE_FPU) ? 1 : 0; - workprefs.address_space_24 = IsDlgButtonChecked (hDlg, IDC_COMPATIBLE24) ? 1 : 0; - workprefs.m68k_speed = IsDlgButtonChecked (hDlg, IDC_CS_HOST) ? -1 - : IsDlgButtonChecked (hDlg, IDC_CS_68000) ? 0 - : SendMessage (GetDlgItem (hDlg, IDC_SPEED), TBM_GETPOS, 0, 0) * CYCLE_UNIT; - workprefs.mmu_model = IsDlgButtonChecked (hDlg, IDC_MMUENABLE) ? 68040 : 0; - - newcpu = IsDlgButtonChecked (hDlg, IDC_CPU0) ? 68000 - : IsDlgButtonChecked (hDlg, IDC_CPU1) ? 68010 - : IsDlgButtonChecked (hDlg, IDC_CPU2) ? 68020 - : IsDlgButtonChecked (hDlg, IDC_CPU3) ? 68030 - : IsDlgButtonChecked (hDlg, IDC_CPU4) ? 68040 - : IsDlgButtonChecked (hDlg, IDC_CPU5) ? 68060 : 0; - newfpu = IsDlgButtonChecked (hDlg, IDC_FPU0) ? 0 - : IsDlgButtonChecked (hDlg, IDC_FPU1) ? 1 - : IsDlgButtonChecked (hDlg, IDC_FPU2) ? 2 - : IsDlgButtonChecked (hDlg, IDC_FPU3) ? 3 : 0; - - /* When switching away from 68000, disable 24 bit addressing. */ - workprefs.cpu_model = newcpu; - switch(newcpu) - { + int newcpu, newfpu, newtrust, oldcache, jitena, idx; + static int cachesize_prev, trust_prev; + + workprefs.cpu_compatible = workprefs.cpu_cycle_exact | (IsDlgButtonChecked (hDlg, IDC_COMPATIBLE) ? 1 : 0); + workprefs.fpu_strict = IsDlgButtonChecked (hDlg, IDC_COMPATIBLE_FPU) ? 1 : 0; + workprefs.address_space_24 = IsDlgButtonChecked (hDlg, IDC_COMPATIBLE24) ? 1 : 0; + workprefs.m68k_speed = IsDlgButtonChecked (hDlg, IDC_CS_HOST) ? -1 + : IsDlgButtonChecked (hDlg, IDC_CS_68000) ? 0 + : SendMessage (GetDlgItem (hDlg, IDC_SPEED), TBM_GETPOS, 0, 0) * CYCLE_UNIT; + workprefs.mmu_model = IsDlgButtonChecked (hDlg, IDC_MMUENABLE) ? 68040 : 0; + + newcpu = IsDlgButtonChecked (hDlg, IDC_CPU0) ? 68000 + : IsDlgButtonChecked (hDlg, IDC_CPU1) ? 68010 + : IsDlgButtonChecked (hDlg, IDC_CPU2) ? 68020 + : IsDlgButtonChecked (hDlg, IDC_CPU3) ? 68030 + : IsDlgButtonChecked (hDlg, IDC_CPU4) ? 68040 + : IsDlgButtonChecked (hDlg, IDC_CPU5) ? 68060 : 0; + newfpu = IsDlgButtonChecked (hDlg, IDC_FPU0) ? 0 + : IsDlgButtonChecked (hDlg, IDC_FPU1) ? 1 + : IsDlgButtonChecked (hDlg, IDC_FPU2) ? 2 + : IsDlgButtonChecked (hDlg, IDC_FPU3) ? 3 : 0; + + /* When switching away from 68000, disable 24 bit addressing. */ + workprefs.cpu_model = newcpu; + switch(newcpu) + { case 68000: case 68010: - workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); - if (workprefs.cpu_compatible || workprefs.cpu_cycle_exact) - workprefs.fpu_model = 0; - workprefs.address_space_24 = 1; - if (newcpu == 0 && workprefs.cpu_cycle_exact) - workprefs.m68k_speed = 0; - break; + workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); + if (workprefs.cpu_compatible || workprefs.cpu_cycle_exact) + workprefs.fpu_model = 0; + workprefs.address_space_24 = 1; + if (newcpu == 0 && workprefs.cpu_cycle_exact) + workprefs.m68k_speed = 0; + break; case 68020: - workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); - break; + workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); + break; case 68030: - workprefs.address_space_24 = 0; - workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); - break; + workprefs.address_space_24 = 0; + workprefs.fpu_model = newfpu == 0 ? 0 : (newfpu == 2 ? 68882 : 68881); + break; case 68040: - workprefs.fpu_model = newfpu ? 68040 : 0; - workprefs.address_space_24 = 0; - if (workprefs.fpu_model) - workprefs.fpu_model = 68040; - break; + workprefs.fpu_model = newfpu ? 68040 : 0; + workprefs.address_space_24 = 0; + if (workprefs.fpu_model) + workprefs.fpu_model = 68040; + break; case 68060: - workprefs.fpu_model = newfpu ? 68060 : 0; - workprefs.address_space_24 = 0; - break; - } - - newtrust = IsDlgButtonChecked (hDlg, IDC_TRUST0) ? 0 : 1; - workprefs.comptrustbyte = newtrust; - workprefs.comptrustword = newtrust; - workprefs.comptrustlong = newtrust; - workprefs.comptrustnaddr= newtrust; - - workprefs.compnf = IsDlgButtonChecked (hDlg, IDC_NOFLAGS); - workprefs.compfpu = IsDlgButtonChecked (hDlg, IDC_JITFPU); - workprefs.comp_hardflush = IsDlgButtonChecked (hDlg, IDC_HARDFLUSH); - workprefs.comp_constjump = IsDlgButtonChecked (hDlg, IDC_CONSTJUMP); + workprefs.fpu_model = newfpu ? 68060 : 0; + workprefs.address_space_24 = 0; + break; + } + + newtrust = IsDlgButtonChecked (hDlg, IDC_TRUST0) ? 0 : 1; + workprefs.comptrustbyte = newtrust; + workprefs.comptrustword = newtrust; + workprefs.comptrustlong = newtrust; + workprefs.comptrustnaddr= newtrust; + + workprefs.compnf = IsDlgButtonChecked (hDlg, IDC_NOFLAGS); + workprefs.compfpu = IsDlgButtonChecked (hDlg, IDC_JITFPU); + workprefs.comp_hardflush = IsDlgButtonChecked (hDlg, IDC_HARDFLUSH); + workprefs.comp_constjump = IsDlgButtonChecked (hDlg, IDC_CONSTJUMP); #ifdef JIT - oldcache = workprefs.cachesize; - jitena = IsDlgButtonChecked (hDlg, IDC_JITENABLE) ? 1 : 0; - workprefs.cachesize = SendMessage (GetDlgItem (hDlg, IDC_CACHE), TBM_GETPOS, 0, 0) * 1024; - if (!jitena) { - cachesize_prev = workprefs.cachesize; - trust_prev = workprefs.comptrustbyte; - workprefs.cachesize = 0; - } else if (jitena && !oldcache) { - workprefs.cachesize = 8192; - if (cachesize_prev) { - workprefs.cachesize = cachesize_prev; - workprefs.comptrustbyte = trust_prev; - workprefs.comptrustword = trust_prev; - workprefs.comptrustlong = trust_prev; - workprefs.comptrustnaddr = trust_prev; - } - } - if (oldcache == 0 && candirect && workprefs.cachesize > 0) - canbang = 1; + oldcache = workprefs.cachesize; + jitena = IsDlgButtonChecked (hDlg, IDC_JITENABLE) ? 1 : 0; + workprefs.cachesize = SendMessage (GetDlgItem (hDlg, IDC_CACHE), TBM_GETPOS, 0, 0) * 1024; + if (!jitena) { + cachesize_prev = workprefs.cachesize; + trust_prev = workprefs.comptrustbyte; + workprefs.cachesize = 0; + } else if (jitena && !oldcache) { + workprefs.cachesize = 8192; + if (cachesize_prev) { + workprefs.cachesize = cachesize_prev; + workprefs.comptrustbyte = trust_prev; + workprefs.comptrustword = trust_prev; + workprefs.comptrustlong = trust_prev; + workprefs.comptrustnaddr = trust_prev; + } + } + if (oldcache == 0 && candirect && workprefs.cachesize > 0) + canbang = 1; #endif - workprefs.cpu_idle = SendMessage (GetDlgItem (hDlg, IDC_CPUIDLE), TBM_GETPOS, 0, 0); - if (workprefs.cpu_idle > 0) - workprefs.cpu_idle = (12 - workprefs.cpu_idle) * 15; - - if (workprefs.cachesize > 0) - workprefs.cpu_compatible = 0; - if (pages[KICKSTART_ID]) - SendMessage (pages[KICKSTART_ID], WM_USER, 0, 0); - if (pages[DISPLAY_ID]) - SendMessage (pages[DISPLAY_ID], WM_USER, 0, 0); - if (pages[MEMORY_ID]) - SendMessage (pages[MEMORY_ID], WM_USER, 0, 0); - - idx = SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_GETCURSEL, 0, 0); - if (idx != CB_ERR) { - int m = workprefs.cpu_clock_multiplier; - workprefs.cpu_frequency = 0; - workprefs.cpu_clock_multiplier = 0; - if (idx == 0) - workprefs.cpu_clock_multiplier = 2 << 8; - if (idx == 1) - workprefs.cpu_clock_multiplier = 4 << 8; - if (idx == 2) - workprefs.cpu_clock_multiplier = 8 << 8; - if (idx == 3) { - TCHAR txt[20]; - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - workprefs.cpu_clock_multiplier = 0; - workprefs.cpu_frequency = _tstof (txt) * 1000000.0; - if (workprefs.cpu_frequency < 1 * 1000000) - workprefs.cpu_frequency = 1 * 1000000; - if (workprefs.cpu_frequency >= 99 * 1000000) - workprefs.cpu_frequency = 99 * 1000000; - } - } + workprefs.cpu_idle = SendMessage (GetDlgItem (hDlg, IDC_CPUIDLE), TBM_GETPOS, 0, 0); + if (workprefs.cpu_idle > 0) + workprefs.cpu_idle = (12 - workprefs.cpu_idle) * 15; + + if (workprefs.cachesize > 0) + workprefs.cpu_compatible = 0; + if (pages[KICKSTART_ID]) + SendMessage (pages[KICKSTART_ID], WM_USER, 0, 0); + if (pages[DISPLAY_ID]) + SendMessage (pages[DISPLAY_ID], WM_USER, 0, 0); + if (pages[MEMORY_ID]) + SendMessage (pages[MEMORY_ID], WM_USER, 0, 0); + + idx = SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_GETCURSEL, 0, 0); + if (idx != CB_ERR) { + int m = workprefs.cpu_clock_multiplier; + workprefs.cpu_frequency = 0; + workprefs.cpu_clock_multiplier = 0; + if (idx == 0) + workprefs.cpu_clock_multiplier = 2 << 8; + if (idx == 1) + workprefs.cpu_clock_multiplier = 4 << 8; + if (idx == 2) + workprefs.cpu_clock_multiplier = 8 << 8; + if (idx == 3) { + TCHAR txt[20]; + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + workprefs.cpu_clock_multiplier = 0; + workprefs.cpu_frequency = _tstof (txt) * 1000000.0; + if (workprefs.cpu_frequency < 1 * 1000000) + workprefs.cpu_frequency = 1 * 1000000; + if (workprefs.cpu_frequency >= 99 * 1000000) + workprefs.cpu_frequency = 99 * 1000000; + } + } } static INT_PTR CALLBACK CPUDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - int idx; + static int recursive = 0; + int idx; - switch (msg) { - case WM_INITDIALOG: - recursive++; - pages[CPU_ID] = hDlg; - currentpage = CPU_ID; - SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETRANGE, TRUE, MAKELONG (MIN_M68K_PRIORITY, MAX_M68K_PRIORITY)); - SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETRANGE, TRUE, MAKELONG (MIN_CACHE_SIZE, MAX_CACHE_SIZE)); - SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETRANGE, TRUE, MAKELONG (0, 10)); - SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPAGESIZE, 0, 1); - - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"A500"); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"A1200"); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"2x"); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"Custom"); - - idx = 3; - if (workprefs.cpu_clock_multiplier == 2 << 8 || (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model <= 68010)) { - idx = 0; - workprefs.cpu_clock_multiplier = 2 << 8; - } - if (workprefs.cpu_clock_multiplier == 4 << 8 || (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model >= 68020)) { - idx = 1; - workprefs.cpu_clock_multiplier = 4 << 8; - } - if (workprefs.cpu_clock_multiplier == 8 << 8) { - idx = 2; - } - if (!workprefs.cpu_cycle_exact) { - idx = 3; - workprefs.cpu_clock_multiplier = 0; - workprefs.cpu_frequency = 0; - } - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_SETCURSEL, idx, 0); - if (!workprefs.cpu_clock_multiplier) { - TCHAR txt[20]; - _stprintf (txt, L"%.6f", workprefs.cpu_frequency / 1000000.0); - SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt); - } - recursive--; + switch (msg) { + case WM_INITDIALOG: + recursive++; + pages[CPU_ID] = hDlg; + currentpage = CPU_ID; + SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETRANGE, TRUE, MAKELONG (MIN_M68K_PRIORITY, MAX_M68K_PRIORITY)); + SendDlgItemMessage (hDlg, IDC_SPEED, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETRANGE, TRUE, MAKELONG (MIN_CACHE_SIZE, MAX_CACHE_SIZE)); + SendDlgItemMessage (hDlg, IDC_CACHE, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETRANGE, TRUE, MAKELONG (0, 10)); + SendDlgItemMessage (hDlg, IDC_CPUIDLE, TBM_SETPAGESIZE, 0, 1); + + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"A500"); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"A1200"); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"2x"); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_ADDSTRING, 0, (LPARAM)L"Custom"); + + idx = 3; + if (workprefs.cpu_clock_multiplier == 2 << 8 || (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model <= 68010)) { + idx = 0; + workprefs.cpu_clock_multiplier = 2 << 8; + } + if (workprefs.cpu_clock_multiplier == 4 << 8 || (workprefs.cpu_clock_multiplier == 0 && workprefs.cpu_frequency == 0 && workprefs.cpu_model >= 68020)) { + idx = 1; + workprefs.cpu_clock_multiplier = 4 << 8; + } + if (workprefs.cpu_clock_multiplier == 8 << 8) { + idx = 2; + } + if (!workprefs.cpu_cycle_exact) { + idx = 3; + workprefs.cpu_clock_multiplier = 0; + workprefs.cpu_frequency = 0; + } + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY, CB_SETCURSEL, idx, 0); + if (!workprefs.cpu_clock_multiplier) { + TCHAR txt[20]; + _stprintf (txt, L"%.6f", workprefs.cpu_frequency / 1000000.0); + SendDlgItemMessage (hDlg, IDC_CPU_FREQUENCY2, WM_SETTEXT, 0, (LPARAM)txt); + } + recursive--; - case WM_USER: - recursive++; - values_to_cpudlg (hDlg); - enable_for_cpudlg (hDlg); - recursive--; - return TRUE; + case WM_USER: + recursive++; + values_to_cpudlg (hDlg); + enable_for_cpudlg (hDlg); + recursive--; + return TRUE; - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - values_from_cpudlg (hDlg); - values_to_cpudlg (hDlg); - enable_for_cpudlg (hDlg); - recursive--; - break; + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + values_from_cpudlg (hDlg); + values_to_cpudlg (hDlg); + enable_for_cpudlg (hDlg); + recursive--; + break; - case WM_HSCROLL: - recursive++; - values_from_cpudlg( hDlg ); - values_to_cpudlg( hDlg ); - enable_for_cpudlg( hDlg ); - recursive--; - break; - } - return FALSE; + case WM_HSCROLL: + recursive++; + values_from_cpudlg( hDlg ); + values_to_cpudlg( hDlg ); + enable_for_cpudlg( hDlg ); + recursive--; + break; + } + return FALSE; } static void enable_for_sounddlg (HWND hDlg) { - int numdevs; + int numdevs; - numdevs = enumerate_sound_devices (); - if (numdevs == 0) - ew (hDlg, IDC_SOUNDCARDLIST, FALSE); - else - ew (hDlg, IDC_SOUNDCARDLIST, workprefs.produce_sound); - - ew (hDlg, IDC_FREQUENCY, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDFREQ, workprefs.produce_sound ? TRUE : FALSE); - ew (hDlg, IDC_SOUNDSTEREO, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDINTERPOLATION, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDVOLUME, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDVOLUME2, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDSTEREOSEP, workprefs.sound_stereo > 0 && workprefs.produce_sound); - ew (hDlg, IDC_SOUNDSTEREOMIX, workprefs.sound_stereo > 0 && workprefs.produce_sound); - - ew (hDlg, IDC_SOUNDBUFFERMEM, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDBUFFERRAM, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDADJUST, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDADJUSTNUM, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDBUFFERTEXT, workprefs.produce_sound); - - ew (hDlg, IDC_SOUNDDRIVE, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDDRIVESELECT, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDDRIVEVOLUME, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDDRIVEVOLUME2, workprefs.produce_sound); - ew (hDlg, IDC_AUDIOSYNC, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDFILTER, workprefs.produce_sound); - ew (hDlg, IDC_SOUNDSWAP, workprefs.produce_sound); - - ew (hDlg, IDC_SOUNDCALIBRATE, workprefs.produce_sound && full_property_sheet); + numdevs = enumerate_sound_devices (); + if (numdevs == 0) + ew (hDlg, IDC_SOUNDCARDLIST, FALSE); + else + ew (hDlg, IDC_SOUNDCARDLIST, workprefs.produce_sound); + + ew (hDlg, IDC_FREQUENCY, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDFREQ, workprefs.produce_sound ? TRUE : FALSE); + ew (hDlg, IDC_SOUNDSTEREO, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDINTERPOLATION, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDVOLUME, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDVOLUME2, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDSTEREOSEP, workprefs.sound_stereo > 0 && workprefs.produce_sound); + ew (hDlg, IDC_SOUNDSTEREOMIX, workprefs.sound_stereo > 0 && workprefs.produce_sound); + + ew (hDlg, IDC_SOUNDBUFFERMEM, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDBUFFERRAM, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDADJUST, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDADJUSTNUM, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDBUFFERTEXT, workprefs.produce_sound); + + ew (hDlg, IDC_SOUNDDRIVE, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDDRIVESELECT, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDDRIVEVOLUME, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDDRIVEVOLUME2, workprefs.produce_sound); + ew (hDlg, IDC_AUDIOSYNC, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDFILTER, workprefs.produce_sound); + ew (hDlg, IDC_SOUNDSWAP, workprefs.produce_sound); + + ew (hDlg, IDC_SOUNDCALIBRATE, workprefs.produce_sound && full_property_sheet); } static int exact_log2 (int v) { - int l = 0; - while ((v >>= 1) != 0) - l++; - return l; + int l = 0; + while ((v >>= 1) != 0) + l++; + return l; } static TCHAR *drivesounds; static void sound_loaddrivesamples (void) { - WIN32_FIND_DATA fd; - HANDLE h; - TCHAR *p; - int len = 0; - TCHAR dirname[1024]; - - free (drivesounds); - p = drivesounds = 0; - _stprintf (dirname, L"%s\\%sfloppysounds\\*.wav", start_path_data, WIN32_PLUGINDIR); - h = FindFirstFile (dirname, &fd); - if (h == INVALID_HANDLE_VALUE) { - _stprintf (dirname, L"%s\\uae_data\\*.wav", start_path_data); - h = FindFirstFile (dirname, &fd); - if (h == INVALID_HANDLE_VALUE) - return; - } - for (;;) { - if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - TCHAR *name = fd.cFileName; - if (_tcslen (name) > _tcslen (DS_NAME_CLICK) + 4 && !_tcsncmp (name, DS_NAME_CLICK, _tcslen (DS_NAME_CLICK))) { - if (p - drivesounds < 1000) { - TCHAR *oldp = p; - len += 2000; - drivesounds = p = realloc (drivesounds, len); - if (oldp) { - do { - p = p + _tcslen (p) + 1; - } while (p[0]); - } - } - _tcscpy (p, name + _tcslen (DS_NAME_CLICK)); - p[_tcslen (name + _tcslen (DS_NAME_CLICK)) - 4] = 0; - p += _tcslen (p); - *p++ = 0; - *p = 0; - } + WIN32_FIND_DATA fd; + HANDLE h; + TCHAR *p; + int len = 0; + TCHAR dirname[1024]; + + free (drivesounds); + p = drivesounds = 0; + _stprintf (dirname, L"%s\\%sfloppysounds\\*.wav", start_path_data, WIN32_PLUGINDIR); + h = FindFirstFile (dirname, &fd); + if (h == INVALID_HANDLE_VALUE) { + _stprintf (dirname, L"%s\\uae_data\\*.wav", start_path_data); + h = FindFirstFile (dirname, &fd); + if (h == INVALID_HANDLE_VALUE) + return; + } + for (;;) { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + TCHAR *name = fd.cFileName; + if (_tcslen (name) > _tcslen (DS_NAME_CLICK) + 4 && !_tcsncmp (name, DS_NAME_CLICK, _tcslen (DS_NAME_CLICK))) { + if (p - drivesounds < 1000) { + TCHAR *oldp = p; + len += 2000; + drivesounds = p = realloc (drivesounds, len); + if (oldp) { + do { + p = p + _tcslen (p) + 1; + } while (p[0]); + } + } + _tcscpy (p, name + _tcslen (DS_NAME_CLICK)); + p[_tcslen (name + _tcslen (DS_NAME_CLICK)) - 4] = 0; + p += _tcslen (p); + *p++ = 0; + *p = 0; + } + } + if (!FindNextFile (h, &fd)) + break; } - if (!FindNextFile (h, &fd)) - break; - } - FindClose (h); + FindClose (h); } extern int soundpercent; static void update_soundgui (HWND hDlg) { - int bufsize, canexc; - TCHAR txt[20]; + int bufsize, canexc; + TCHAR txt[20]; - bufsize = exact_log2 (workprefs.sound_maxbsiz / 1024); - _stprintf (txt, L"%d", bufsize); - SetDlgItemText (hDlg, IDC_SOUNDBUFFERMEM, txt); + bufsize = exact_log2 (workprefs.sound_maxbsiz / 1024); + _stprintf (txt, L"%d", bufsize); + SetDlgItemText (hDlg, IDC_SOUNDBUFFERMEM, txt); - SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.sound_volume); - _stprintf (txt, L"%d%%", 100 - workprefs.sound_volume); - SetDlgItemText (hDlg, IDC_SOUNDVOLUME2, txt); + SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.sound_volume); + _stprintf (txt, L"%d%%", 100 - workprefs.sound_volume); + SetDlgItemText (hDlg, IDC_SOUNDVOLUME2, txt); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume); - _stprintf (txt, L"%d%%", 100 - workprefs.dfxclickvolume); - SetDlgItemText (hDlg, IDC_SOUNDDRIVEVOLUME2, txt); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume); + _stprintf (txt, L"%d%%", 100 - workprefs.dfxclickvolume); + SetDlgItemText (hDlg, IDC_SOUNDDRIVEVOLUME2, txt); - canexc = sound_devices[workprefs.win32_soundcard].type == SOUND_DEVICE_WASAPI; - ew (hDlg, IDC_SOUND_EXCLUSIVE, canexc); - if (!canexc) - workprefs.win32_soundexclusive = 0; - CheckDlgButton (hDlg, IDC_SOUND_EXCLUSIVE, workprefs.win32_soundexclusive); + canexc = sound_devices[workprefs.win32_soundcard].type == SOUND_DEVICE_WASAPI; + ew (hDlg, IDC_SOUND_EXCLUSIVE, canexc); + if (!canexc) + workprefs.win32_soundexclusive = 0; + CheckDlgButton (hDlg, IDC_SOUND_EXCLUSIVE, workprefs.win32_soundexclusive); } @@ -7250,365 +7250,365 @@ static int sounddrivers[] = { IDC_SOUND_DS, IDC_SOUND_WASAPI, IDC_SOUND_OPENAL, static void values_to_sounddlg (HWND hDlg) { - int which_button; - int sound_freq = workprefs.sound_freq; - int produce_sound = workprefs.produce_sound; - int stereo = workprefs.sound_stereo; - TCHAR txt[100], txt2[100], *p; - int i, selected; - LRESULT idx; - - if (workprefs.sound_maxbsiz & (workprefs.sound_maxbsiz - 1)) - workprefs.sound_maxbsiz = DEFAULT_SOUND_MAXB; - - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_SOUND_FILTER_OFF, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED_E, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_AGA, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_A500, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); - i = 0; - switch (workprefs.sound_filter) - { - case 0: + int which_button; + int sound_freq = workprefs.sound_freq; + int produce_sound = workprefs.produce_sound; + int stereo = workprefs.sound_stereo; + TCHAR txt[100], txt2[100], *p; + int i, selected; + LRESULT idx; + + if (workprefs.sound_maxbsiz & (workprefs.sound_maxbsiz - 1)) + workprefs.sound_maxbsiz = DEFAULT_SOUND_MAXB; + + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_SOUND_FILTER_OFF, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_FILTER_EMULATED_E, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_AGA, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_FILTER_ON_A500, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_ADDSTRING, 0, (LPARAM)txt); i = 0; - break; + switch (workprefs.sound_filter) + { + case 0: + i = 0; + break; case 1: - i = workprefs.sound_filter_type ? 2 : 1; - break; + i = workprefs.sound_filter_type ? 2 : 1; + break; case 2: - i = workprefs.sound_filter_type ? 4 : 3; - break; - } - SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_SETCURSEL, i, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_SOUND_MONO, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_STEREO, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_STEREO2, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_4CHANNEL, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_CLONED51, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_51, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_SETCURSEL, workprefs.sound_stereo, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)L"-"); - WIN32GUI_LoadUIString (IDS_SOUND_SWAP_PAULA, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_SWAP_AHI, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_SOUND_SWAP_BOTH, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); - SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_SETCURSEL, - workprefs.sound_stereo_swap_paula + workprefs.sound_stereo_swap_ahi * 2, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_RESETCONTENT, 0, 0); - for (i = 10; i >= 0; i--) { - _stprintf (txt, L"%d%%", i * 10); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_ADDSTRING, 0, (LPARAM)txt); - } - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_SETCURSEL, 10 - workprefs.sound_stereo_separation, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)L"-"); - for (i = 0; i < 10; i++) { - _stprintf (txt, L"%d", i + 1); - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)txt); - } - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_SETCURSEL, - workprefs.sound_mixed_stereo_delay > 0 ? workprefs.sound_mixed_stereo_delay : 0, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_DISABLED, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)txt); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Anti"); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Sinc"); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"RH"); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Crux"); - SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_SETCURSEL, workprefs.sound_interpol, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_RESETCONTENT, 0, 0); - i = 0; - selected = -1; - while (soundfreqs[i]) { - _stprintf (txt, L"%d", soundfreqs[i]); - SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_ADDSTRING, 0, (LPARAM)txt); - i++; - } - _stprintf (txt, L"%d", workprefs.sound_freq); - SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_SETTEXT, 0, (LPARAM)txt); - - switch (workprefs.produce_sound) - { - case 0: which_button = IDC_SOUND0; break; - case 1: which_button = IDC_SOUND1; break; - case 2: which_button = IDC_SOUND2; break; - case 3: which_button = IDC_SOUND3; break; - } - CheckRadioButton (hDlg, IDC_SOUND0, IDC_SOUND3, which_button); - - CheckDlgButton (hDlg, IDC_SOUND_AUTO, workprefs.sound_auto); - - workprefs.sound_maxbsiz = 1 << exact_log2 (workprefs.sound_maxbsiz); - if (workprefs.sound_maxbsiz < 2048) - workprefs.sound_maxbsiz = 2048; - SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, exact_log2 (workprefs.sound_maxbsiz / 2048)); - - SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 0); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 0); - - SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_SETCURSEL, workprefs.win32_soundcard, 0); - - idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0); - if (idx < 0) - idx = 0; - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_RESETCONTENT, 0, 0); - for (i = 0; i < 4; i++) { - _stprintf (txt, L"DF%d:", i); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_ADDSTRING, 0, (LPARAM)txt); - } - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_SETCURSEL, idx, 0); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_DRIVESOUND_NONE, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_DRIVESOUND_DEFAULT_A500, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt); - driveclick_fdrawcmd_detect (); - if (driveclick_pcdrivemask) { - for (i = 0; i < 2; i++) { - WIN32GUI_LoadUIString (IDS_DRIVESOUND_PC_FLOPPY, txt, sizeof (txt) / sizeof (TCHAR)); - _stprintf (txt2, txt, 'A' + i); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt2); - } - } - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, 0, 0); - p = drivesounds; - if (p) { - while (p[0]) { - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)p); - p += _tcslen (p) + 1; - } - } - if (workprefs.dfxclick[idx] < 0) { - p = drivesounds; - i = DS_BUILD_IN_SOUNDS + (driveclick_pcdrivemask ? 2 : 0) + 1; - while (p && p[0]) { - if (!_tcsicmp (p, workprefs.dfxclickexternal[idx])) { - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, i, 0); + i = workprefs.sound_filter_type ? 4 : 3; break; - } - i++; - p += _tcslen (p) + 1; } + SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_SETCURSEL, i, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_SOUND_MONO, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_STEREO, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_STEREO2, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_4CHANNEL, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_CLONED51, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_51, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_ADDSTRING, 0, (LPARAM)txt); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_SETCURSEL, workprefs.sound_stereo, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)L"-"); + WIN32GUI_LoadUIString (IDS_SOUND_SWAP_PAULA, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_SWAP_AHI, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_SOUND_SWAP_BOTH, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_ADDSTRING, 0, (LPARAM)txt); + SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_SETCURSEL, + workprefs.sound_stereo_swap_paula + workprefs.sound_stereo_swap_ahi * 2, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_RESETCONTENT, 0, 0); + for (i = 10; i >= 0; i--) { + _stprintf (txt, L"%d%%", i * 10); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_ADDSTRING, 0, (LPARAM)txt); + } + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_SETCURSEL, 10 - workprefs.sound_stereo_separation, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)L"-"); + for (i = 0; i < 10; i++) { + _stprintf (txt, L"%d", i + 1); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)txt); + } + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_SETCURSEL, + workprefs.sound_mixed_stereo_delay > 0 ? workprefs.sound_mixed_stereo_delay : 0, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_DISABLED, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)txt); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Anti"); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Sinc"); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"RH"); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_ADDSTRING, 0, (LPARAM)L"Crux"); + SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_SETCURSEL, workprefs.sound_interpol, 0); + + SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_RESETCONTENT, 0, 0); + i = 0; + selected = -1; + while (soundfreqs[i]) { + _stprintf (txt, L"%d", soundfreqs[i]); + SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_ADDSTRING, 0, (LPARAM)txt); + i++; + } + _stprintf (txt, L"%d", workprefs.sound_freq); + SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_SETTEXT, 0, (LPARAM)txt); - } else { - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, workprefs.dfxclick[idx], 0); - } + switch (workprefs.produce_sound) + { + case 0: which_button = IDC_SOUND0; break; + case 1: which_button = IDC_SOUND1; break; + case 2: which_button = IDC_SOUND2; break; + case 3: which_button = IDC_SOUND3; break; + } + CheckRadioButton (hDlg, IDC_SOUND0, IDC_SOUND3, which_button); - update_soundgui (hDlg); -} + CheckDlgButton (hDlg, IDC_SOUND_AUTO, workprefs.sound_auto); -static void values_from_sounddlg (HWND hDlg) -{ - TCHAR txt[10]; - LRESULT idx; - int soundcard, i; - - idx = SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_GETCURSEL, 0, 0); - if (idx >= 0) { - workprefs.sound_freq = soundfreqs[idx]; - } else { - SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); - workprefs.sound_freq = _tstol (txt); - } - if (workprefs.sound_freq < 8000) - workprefs.sound_freq = 8000; - if (workprefs.sound_freq > 96000) - workprefs.sound_freq = 96000; - - workprefs.produce_sound = (IsDlgButtonChecked (hDlg, IDC_SOUND0) ? 0 - : IsDlgButtonChecked (hDlg, IDC_SOUND1) ? 1 - : IsDlgButtonChecked (hDlg, IDC_SOUND2) ? 2 : 3); - - workprefs.sound_auto = IsDlgButtonChecked (hDlg, IDC_SOUND_AUTO) ? 1 : 0; - - idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_GETCURSEL, 0, 0); - if (idx != CB_ERR) - workprefs.sound_stereo = idx; - workprefs.sound_stereo_separation = 0; - workprefs.sound_mixed_stereo_delay = 0; - if (workprefs.sound_stereo > 0) { - idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_GETCURSEL, 0, 0); - if (idx != CB_ERR) { - if (idx > 0) - workprefs.sound_mixed_stereo_delay = -1; - workprefs.sound_stereo_separation = 10 - idx; - } - idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_GETCURSEL, 0, 0); - if (idx != CB_ERR && idx > 0) - workprefs.sound_mixed_stereo_delay = idx; - } - - workprefs.sound_interpol = SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_GETCURSEL, 0, 0); - workprefs.win32_soundexclusive = IsDlgButtonChecked (hDlg, IDC_SOUND_EXCLUSIVE) ? 1 : 0; - soundcard = SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_GETCURSEL, 0, 0L); - if (soundcard != workprefs.win32_soundcard && soundcard != CB_ERR) { - workprefs.win32_soundcard = soundcard; - update_soundgui (hDlg); - } + workprefs.sound_maxbsiz = 1 << exact_log2 (workprefs.sound_maxbsiz); + if (workprefs.sound_maxbsiz < 2048) + workprefs.sound_maxbsiz = 2048; + SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, exact_log2 (workprefs.sound_maxbsiz / 2048)); - switch (SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_GETCURSEL, 0, 0)) - { - case 0: - workprefs.sound_filter = FILTER_SOUND_OFF; - break; - case 1: - workprefs.sound_filter = FILTER_SOUND_EMUL; - workprefs.sound_filter_type = 0; - break; - case 2: - workprefs.sound_filter = FILTER_SOUND_EMUL; - workprefs.sound_filter_type = 1; - break; - case 3: - workprefs.sound_filter = FILTER_SOUND_ON; - workprefs.sound_filter_type = 0; - break; - case 4: - workprefs.sound_filter = FILTER_SOUND_ON; - workprefs.sound_filter_type = 1; - break; - } - - workprefs.sound_stereo_swap_paula = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 1) ? 1 : 0; - workprefs.sound_stereo_swap_ahi = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 2) ? 1 : 0; - - for (i = 0; sounddrivers[i]; i++) { - int old = sounddrivermask; - sounddrivermask &= ~(1 << i); - if (IsDlgButtonChecked (hDlg, sounddrivers[i])) - sounddrivermask |= 1 << i; - if (old != sounddrivermask) - regsetint (NULL, L"SoundDriverMask", sounddrivermask); - } - - idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0); - if (idx != CB_ERR && idx >= 0) { - LRESULT res = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_GETCURSEL, 0, 0); - if (res != CB_ERR && res >= 0) { - int xtra = driveclick_pcdrivemask ? 2 : 0; - if (res > DS_BUILD_IN_SOUNDS + xtra) { - int j = res - (DS_BUILD_IN_SOUNDS + xtra + 1); - TCHAR *p = drivesounds; - while (j-- > 0) - p += _tcslen (p) + 1; - workprefs.dfxclick[idx] = -1; - _tcscpy (workprefs.dfxclickexternal[idx], p); - } else { - workprefs.dfxclick[idx] = res; - workprefs.dfxclickexternal[idx][0] = 0; - } - } - } -} + SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 0); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 0); -static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static int recursive = 0; - int numdevs; - int card, i; + SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_SETCURSEL, workprefs.win32_soundcard, 0); - switch (msg) { - case WM_INITDIALOG: - { - recursive++; - sound_loaddrivesamples (); - SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SOUND_MEM, MAX_SOUND_MEM)); - SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPAGESIZE, 0, 1); + idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0); + if (idx < 0) + idx = 0; + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_RESETCONTENT, 0, 0); + for (i = 0; i < 4; i++) { + _stprintf (txt, L"DF%d:", i); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_ADDSTRING, 0, (LPARAM)txt); + } + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_SETCURSEL, idx, 0); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_DRIVESOUND_NONE, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_DRIVESOUND_DEFAULT_A500, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt); + driveclick_fdrawcmd_detect (); + if (driveclick_pcdrivemask) { + for (i = 0; i < 2; i++) { + WIN32GUI_LoadUIString (IDS_DRIVESOUND_PC_FLOPPY, txt, sizeof (txt) / sizeof (TCHAR)); + _stprintf (txt2, txt, 'A' + i); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)txt2); + } + } + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, 0, 0); + p = drivesounds; + if (p) { + while (p[0]) { + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_ADDSTRING, 0, (LPARAM)p); + p += _tcslen (p) + 1; + } + } + if (workprefs.dfxclick[idx] < 0) { + p = drivesounds; + i = DS_BUILD_IN_SOUNDS + (driveclick_pcdrivemask ? 2 : 0) + 1; + while (p && p[0]) { + if (!_tcsicmp (p, workprefs.dfxclickexternal[idx])) { + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, i, 0); + break; + } + i++; + p += _tcslen (p) + 1; + } - SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100)); - SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPAGESIZE, 0, 1); + } else { + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_SETCURSEL, workprefs.dfxclick[idx], 0); + } - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100)); - SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPAGESIZE, 0, 1); + update_soundgui (hDlg); +} - SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETRANGE, TRUE, MAKELONG (-100, +30)); - SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETPAGESIZE, 0, 1); +static void values_from_sounddlg (HWND hDlg) +{ + TCHAR txt[10]; + LRESULT idx; + int soundcard, i; - for (i = 0; i < sounddrivers[i]; i++) { - CheckDlgButton (hDlg, sounddrivers[i], (sounddrivermask & (1 << i)) ? TRUE : FALSE); + idx = SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, CB_GETCURSEL, 0, 0); + if (idx >= 0) { + workprefs.sound_freq = soundfreqs[idx]; + } else { + SendDlgItemMessage (hDlg, IDC_SOUNDFREQ, WM_GETTEXT, (WPARAM)sizeof (txt) / sizeof (TCHAR), (LPARAM)txt); + workprefs.sound_freq = _tstol (txt); + } + if (workprefs.sound_freq < 8000) + workprefs.sound_freq = 8000; + if (workprefs.sound_freq > 96000) + workprefs.sound_freq = 96000; + + workprefs.produce_sound = (IsDlgButtonChecked (hDlg, IDC_SOUND0) ? 0 + : IsDlgButtonChecked (hDlg, IDC_SOUND1) ? 1 + : IsDlgButtonChecked (hDlg, IDC_SOUND2) ? 2 : 3); + + workprefs.sound_auto = IsDlgButtonChecked (hDlg, IDC_SOUND_AUTO) ? 1 : 0; + + idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_GETCURSEL, 0, 0); + if (idx != CB_ERR) + workprefs.sound_stereo = idx; + workprefs.sound_stereo_separation = 0; + workprefs.sound_mixed_stereo_delay = 0; + if (workprefs.sound_stereo > 0) { + idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOSEP, CB_GETCURSEL, 0, 0); + if (idx != CB_ERR) { + if (idx > 0) + workprefs.sound_mixed_stereo_delay = -1; + workprefs.sound_stereo_separation = 10 - idx; + } + idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_GETCURSEL, 0, 0); + if (idx != CB_ERR && idx > 0) + workprefs.sound_mixed_stereo_delay = idx; } - SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_RESETCONTENT, 0, 0L); - numdevs = enumerate_sound_devices (); - for (card = 0; card < numdevs; card++) { - TCHAR tmp[MAX_DPATH]; - int type = sound_devices[card].type; - _stprintf (tmp, L"%s: %s", - type == SOUND_DEVICE_DS ? L"DSOUND" : (type == SOUND_DEVICE_AL ? L"OpenAL" : (type == SOUND_DEVICE_PA ? L"PortAudio" : L"WASAPI")), - sound_devices[card].name); - SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_ADDSTRING, 0, (LPARAM)tmp); + workprefs.sound_interpol = SendDlgItemMessage (hDlg, IDC_SOUNDINTERPOLATION, CB_GETCURSEL, 0, 0); + workprefs.win32_soundexclusive = IsDlgButtonChecked (hDlg, IDC_SOUND_EXCLUSIVE) ? 1 : 0; + soundcard = SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_GETCURSEL, 0, 0L); + if (soundcard != workprefs.win32_soundcard && soundcard != CB_ERR) { + workprefs.win32_soundcard = soundcard; + update_soundgui (hDlg); } - if (numdevs == 0) - workprefs.produce_sound = 0; /* No sound card in system, enable_for_sounddlg will accomodate this */ - pages[SOUND_ID] = hDlg; - currentpage = SOUND_ID; - update_soundgui (hDlg); - recursive--; - } - case WM_USER: - recursive++; - values_to_sounddlg (hDlg); - enable_for_sounddlg (hDlg); - recursive--; - return TRUE; + switch (SendDlgItemMessage (hDlg, IDC_SOUNDFILTER, CB_GETCURSEL, 0, 0)) + { + case 0: + workprefs.sound_filter = FILTER_SOUND_OFF; + break; + case 1: + workprefs.sound_filter = FILTER_SOUND_EMUL; + workprefs.sound_filter_type = 0; + break; + case 2: + workprefs.sound_filter = FILTER_SOUND_EMUL; + workprefs.sound_filter_type = 1; + break; + case 3: + workprefs.sound_filter = FILTER_SOUND_ON; + workprefs.sound_filter_type = 0; + break; + case 4: + workprefs.sound_filter = FILTER_SOUND_ON; + workprefs.sound_filter_type = 1; + break; + } - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if(LOWORD (wParam) == IDC_SOUNDDRIVE) { - values_to_sounddlg (hDlg); + workprefs.sound_stereo_swap_paula = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 1) ? 1 : 0; + workprefs.sound_stereo_swap_ahi = (SendDlgItemMessage (hDlg, IDC_SOUNDSWAP, CB_GETCURSEL, 0, 0) & 2) ? 1 : 0; + + for (i = 0; sounddrivers[i]; i++) { + int old = sounddrivermask; + sounddrivermask &= ~(1 << i); + if (IsDlgButtonChecked (hDlg, sounddrivers[i])) + sounddrivermask |= 1 << i; + if (old != sounddrivermask) + regsetint (NULL, L"SoundDriverMask", sounddrivermask); + } + + idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0); + if (idx != CB_ERR && idx >= 0) { + LRESULT res = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVESELECT, CB_GETCURSEL, 0, 0); + if (res != CB_ERR && res >= 0) { + int xtra = driveclick_pcdrivemask ? 2 : 0; + if (res > DS_BUILD_IN_SOUNDS + xtra) { + int j = res - (DS_BUILD_IN_SOUNDS + xtra + 1); + TCHAR *p = drivesounds; + while (j-- > 0) + p += _tcslen (p) + 1; + workprefs.dfxclick[idx] = -1; + _tcscpy (workprefs.dfxclickexternal[idx], p); + } else { + workprefs.dfxclick[idx] = res; + workprefs.dfxclickexternal[idx][0] = 0; + } + } } - values_from_sounddlg (hDlg); - enable_for_sounddlg (hDlg); - recursive--; - break; +} - case WM_HSCROLL: - workprefs.sound_maxbsiz = 2048 << SendMessage (GetDlgItem (hDlg, IDC_SOUNDBUFFERRAM), TBM_GETPOS, 0, 0); - workprefs.sound_volume = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDVOLUME), TBM_GETPOS, 0, 0); - workprefs.dfxclickvolume = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDDRIVEVOLUME), TBM_GETPOS, 0, 0); - update_soundgui (hDlg); - break; - } - return FALSE; +static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static int recursive = 0; + int numdevs; + int card, i; + + switch (msg) { + case WM_INITDIALOG: + { + recursive++; + sound_loaddrivesamples (); + SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETRANGE, TRUE, MAKELONG (MIN_SOUND_MEM, MAX_SOUND_MEM)); + SendDlgItemMessage (hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPAGESIZE, 0, 1); + + SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100)); + SendDlgItemMessage (hDlg, IDC_SOUNDVOLUME, TBM_SETPAGESIZE, 0, 1); + + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETRANGE, TRUE, MAKELONG (0, 100)); + SendDlgItemMessage (hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPAGESIZE, 0, 1); + + SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETRANGE, TRUE, MAKELONG (-100, +30)); + SendDlgItemMessage (hDlg, IDC_SOUNDADJUST, TBM_SETPAGESIZE, 0, 1); + + for (i = 0; i < sounddrivers[i]; i++) { + CheckDlgButton (hDlg, sounddrivers[i], (sounddrivermask & (1 << i)) ? TRUE : FALSE); + } + + SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_RESETCONTENT, 0, 0L); + numdevs = enumerate_sound_devices (); + for (card = 0; card < numdevs; card++) { + TCHAR tmp[MAX_DPATH]; + int type = sound_devices[card].type; + _stprintf (tmp, L"%s: %s", + type == SOUND_DEVICE_DS ? L"DSOUND" : (type == SOUND_DEVICE_AL ? L"OpenAL" : (type == SOUND_DEVICE_PA ? L"PortAudio" : L"WASAPI")), + sound_devices[card].name); + SendDlgItemMessage (hDlg, IDC_SOUNDCARDLIST, CB_ADDSTRING, 0, (LPARAM)tmp); + } + if (numdevs == 0) + workprefs.produce_sound = 0; /* No sound card in system, enable_for_sounddlg will accomodate this */ + + pages[SOUND_ID] = hDlg; + currentpage = SOUND_ID; + update_soundgui (hDlg); + recursive--; + } + case WM_USER: + recursive++; + values_to_sounddlg (hDlg); + enable_for_sounddlg (hDlg); + recursive--; + return TRUE; + + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + if(LOWORD (wParam) == IDC_SOUNDDRIVE) { + values_to_sounddlg (hDlg); + } + values_from_sounddlg (hDlg); + enable_for_sounddlg (hDlg); + recursive--; + break; + + case WM_HSCROLL: + workprefs.sound_maxbsiz = 2048 << SendMessage (GetDlgItem (hDlg, IDC_SOUNDBUFFERRAM), TBM_GETPOS, 0, 0); + workprefs.sound_volume = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDVOLUME), TBM_GETPOS, 0, 0); + workprefs.dfxclickvolume = 100 - SendMessage (GetDlgItem (hDlg, IDC_SOUNDDRIVEVOLUME), TBM_GETPOS, 0, 0); + update_soundgui (hDlg); + break; + } + return FALSE; } #ifdef FILESYS struct fsvdlg_vals { - TCHAR volume[MAX_DPATH]; - TCHAR device[MAX_DPATH]; - TCHAR rootdir[MAX_DPATH]; - int bootpri; - int autoboot; - int donotmount; - int rw; - int rdb; + TCHAR volume[MAX_DPATH]; + TCHAR device[MAX_DPATH]; + TCHAR rootdir[MAX_DPATH]; + int bootpri; + int autoboot; + int donotmount; + int rw; + int rdb; }; static struct fsvdlg_vals empty_fsvdlg = { L"", L"", L"", 0, 1, 1, 1, 0 }; @@ -7616,1696 +7616,1708 @@ static struct fsvdlg_vals current_fsvdlg; struct hfdlg_vals { - TCHAR volumename[MAX_DPATH]; - TCHAR devicename[MAX_DPATH]; - TCHAR filename[MAX_DPATH]; - TCHAR fsfilename[MAX_DPATH]; - int sectors; - int reserved; - int surfaces; - int cylinders; - int blocksize; - int rw; - int rdb; - int bootpri; - int donotmount; - int autoboot; - int controller; + TCHAR volumename[MAX_DPATH]; + TCHAR devicename[MAX_DPATH]; + TCHAR filename[MAX_DPATH]; + TCHAR fsfilename[MAX_DPATH]; + int sectors; + int reserved; + int surfaces; + int cylinders; + int blocksize; + int rw; + int rdb; + int bootpri; + int donotmount; + int autoboot; + int controller; + int original; }; -static struct hfdlg_vals empty_hfdlg = { L"", L"", L"", L"", 32, 2, 1, 0, 512, 1, 0, 0, 0, 1, 0 }; +static struct hfdlg_vals empty_hfdlg = { L"", L"", L"", L"", 32, 2, 1, 0, 512, 1, 0, 0, 0, 1, 0, 1 }; static struct hfdlg_vals current_hfdlg; static int archivehd; static void volumeselectfile (HWND hDlg) { - TCHAR directory_path[MAX_DPATH]; - _tcscpy (directory_path, current_fsvdlg.rootdir); - if (DiskSelection (hDlg, 0, 14, &workprefs, directory_path)) { - TCHAR *s = filesys_createvolname (NULL, directory_path, L"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; - } + TCHAR directory_path[MAX_DPATH]; + _tcscpy (directory_path, current_fsvdlg.rootdir); + if (DiskSelection (hDlg, 0, 14, &workprefs, directory_path)) { + TCHAR *s = filesys_createvolname (NULL, directory_path, L"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) { - const GUID volumeguid = { 0x1df05121, 0xcc08, 0x46ea, { 0x80, 0x3f, 0x98, 0x3c, 0x54, 0x88, 0x53, 0x76 } }; - TCHAR szTitle[MAX_DPATH]; - TCHAR directory_path[MAX_DPATH]; + const GUID volumeguid = { 0x1df05121, 0xcc08, 0x46ea, { 0x80, 0x3f, 0x98, 0x3c, 0x54, 0x88, 0x53, 0x76 } }; + TCHAR szTitle[MAX_DPATH]; + TCHAR directory_path[MAX_DPATH]; - _tcscpy (directory_path, current_fsvdlg.rootdir); - if (!newdir) { - WIN32GUI_LoadUIString (IDS_SELECTFILESYSROOT, szTitle, MAX_DPATH); - if (DirectorySelection (hDlg, &volumeguid, directory_path)) - newdir = 1; - } - if (newdir) { - SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path); - ew (hDlg, IDC_FS_RW, TRUE); - archivehd = 0; - } + _tcscpy (directory_path, current_fsvdlg.rootdir); + if (!newdir) { + WIN32GUI_LoadUIString (IDS_SELECTFILESYSROOT, szTitle, MAX_DPATH); + if (DirectorySelection (hDlg, &volumeguid, 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; + static int recursive = 0; - switch (msg) { + switch (msg) { case WM_INITDIALOG: - { - archivehd = -1; - if (my_existsfile (current_fsvdlg.rootdir)) - archivehd = 1; - else if (my_existsdir (current_fsvdlg.rootdir)) - archivehd = 0; - recursive++; - setac (hDlg, IDC_PATH_NAME); - SetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume); - SetDlgItemText (hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.device); - SetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir); - SetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, current_fsvdlg.bootpri >= -127 ? current_fsvdlg.bootpri : -127, TRUE); - if (archivehd > 0) - current_fsvdlg.rw = 0; - CheckDlgButton (hDlg, IDC_FS_RW, current_fsvdlg.rw); - CheckDlgButton (hDlg, IDC_FS_AUTOBOOT, current_fsvdlg.autoboot); - current_fsvdlg.donotmount = 0; - ew (hDlg, IDC_FS_RW, archivehd <= 0); - recursive--; - } - return TRUE; + { + archivehd = -1; + if (my_existsfile (current_fsvdlg.rootdir)) + archivehd = 1; + else if (my_existsdir (current_fsvdlg.rootdir)) + archivehd = 0; + recursive++; + setac (hDlg, IDC_PATH_NAME); + SetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume); + SetDlgItemText (hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.device); + SetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir); + SetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, current_fsvdlg.bootpri >= -127 ? current_fsvdlg.bootpri : -127, TRUE); + if (archivehd > 0) + current_fsvdlg.rw = 0; + CheckDlgButton (hDlg, IDC_FS_RW, current_fsvdlg.rw); + CheckDlgButton (hDlg, IDC_FS_AUTOBOOT, current_fsvdlg.autoboot); + current_fsvdlg.donotmount = 0; + ew (hDlg, IDC_FS_RW, archivehd <= 0); + recursive--; + } + return TRUE; case WM_CONTEXTMENU: - if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_FILE) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - _tcscpy (current_fsvdlg.rootdir, s); - xfree (s); - volumeselectfile (hDlg); - } - } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_DIR) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - _tcscpy (current_fsvdlg.rootdir, s); - xfree (s); - volumeselectdir (hDlg, 1); + if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_FILE) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + _tcscpy (current_fsvdlg.rootdir, s); + xfree (s); + volumeselectfile (hDlg); + } + } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FS_SELECT_DIR) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + _tcscpy (current_fsvdlg.rootdir, s); + xfree (s); + volumeselectdir (hDlg, 1); + } } - } - break; + break; case WM_COMMAND: - if (recursive) - break; - recursive++; - if (HIWORD (wParam) == BN_CLICKED) { - switch (LOWORD (wParam)) - { - case IDC_FS_SELECT_EJECT: - SetDlgItemText (hDlg, IDC_PATH_NAME, L""); - SetDlgItemText (hDlg, IDC_VOLUME_NAME, L""); - CheckDlgButton (hDlg, IDC_FS_RW, TRUE); - ew (hDlg, IDC_FS_RW, TRUE); - archivehd = -1; - break; - case IDC_FS_SELECT_FILE: - volumeselectfile (hDlg); - break; - case IDC_FS_SELECT_DIR: - volumeselectdir (hDlg, 0); - break; - case IDOK: - EndDialog (hDlg, 1); - break; - case IDCANCEL: - EndDialog (hDlg, 0); - break; + if (recursive) + break; + recursive++; + if (HIWORD (wParam) == BN_CLICKED) { + switch (LOWORD (wParam)) + { + case IDC_FS_SELECT_EJECT: + SetDlgItemText (hDlg, IDC_PATH_NAME, L""); + SetDlgItemText (hDlg, IDC_VOLUME_NAME, L""); + CheckDlgButton (hDlg, IDC_FS_RW, TRUE); + ew (hDlg, IDC_FS_RW, TRUE); + archivehd = -1; + break; + case IDC_FS_SELECT_FILE: + volumeselectfile (hDlg); + break; + case IDC_FS_SELECT_DIR: + volumeselectdir (hDlg, 0); + break; + case IDOK: + EndDialog (hDlg, 1); + break; + case IDCANCEL: + EndDialog (hDlg, 0); + break; + } } - } - GetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir, sizeof current_fsvdlg.rootdir / sizeof (TCHAR)); - GetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume, sizeof current_fsvdlg.volume / sizeof (TCHAR)); - GetDlgItemText (hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.device, sizeof current_fsvdlg.device / sizeof (TCHAR)); - current_fsvdlg.rw = IsDlgButtonChecked (hDlg, IDC_FS_RW); - current_fsvdlg.bootpri = GetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, NULL, TRUE); - current_fsvdlg.autoboot = IsDlgButtonChecked (hDlg, IDC_FS_AUTOBOOT); - recursive--; - break; - } - return FALSE; + GetDlgItemText (hDlg, IDC_PATH_NAME, current_fsvdlg.rootdir, sizeof current_fsvdlg.rootdir / sizeof (TCHAR)); + GetDlgItemText (hDlg, IDC_VOLUME_NAME, current_fsvdlg.volume, sizeof current_fsvdlg.volume / sizeof (TCHAR)); + GetDlgItemText (hDlg, IDC_VOLUME_DEVICE, current_fsvdlg.device, sizeof current_fsvdlg.device / sizeof (TCHAR)); + current_fsvdlg.rw = IsDlgButtonChecked (hDlg, IDC_FS_RW); + current_fsvdlg.bootpri = GetDlgItemInt (hDlg, IDC_VOLUME_BOOTPRI, NULL, TRUE); + current_fsvdlg.autoboot = IsDlgButtonChecked (hDlg, IDC_FS_AUTOBOOT); + recursive--; + break; + } + return FALSE; } -STATIC_INLINE int is_hdf_rdb(void) +STATIC_INLINE int is_hdf_rdb (void) { - return current_hfdlg.sectors == 0 && current_hfdlg.surfaces == 0 && current_hfdlg.reserved == 0; + return current_hfdlg.sectors == 0 && current_hfdlg.surfaces == 0 && current_hfdlg.reserved == 0; } static void sethardfile (HWND hDlg) { - int rdb = is_hdf_rdb(); - SetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename); - SetDlgItemText (hDlg, IDC_PATH_FILESYS, current_hfdlg.fsfilename); - SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.devicename); - SetDlgItemInt (hDlg, IDC_SECTORS, current_hfdlg.sectors, FALSE); - SetDlgItemInt (hDlg, IDC_HEADS, current_hfdlg.surfaces, FALSE); - SetDlgItemInt (hDlg, IDC_RESERVED, current_hfdlg.reserved, FALSE); - SetDlgItemInt (hDlg, IDC_BLOCKSIZE, current_hfdlg.blocksize, FALSE); - SetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, current_hfdlg.bootpri >= -127 ? current_hfdlg.bootpri : -127, TRUE); - CheckDlgButton (hDlg, IDC_HDF_RW, current_hfdlg.rw); - CheckDlgButton (hDlg, IDC_HDF_AUTOBOOT, current_hfdlg.autoboot); - CheckDlgButton (hDlg, IDC_HDF_DONOTMOUNT, current_hfdlg.donotmount); - ew (hDlg, IDC_HDF_RDB, !rdb); - ew (hDlg, IDC_HDF_AUTOBOOT, !rdb); - ew (hDlg, IDC_HDF_DONOTMOUNT, !rdb); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); + int rdb = is_hdf_rdb (); + + SetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename); + SetDlgItemText (hDlg, IDC_PATH_FILESYS, current_hfdlg.fsfilename); + SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.devicename); + SetDlgItemInt (hDlg, IDC_SECTORS, current_hfdlg.sectors, FALSE); + SetDlgItemInt (hDlg, IDC_HEADS, current_hfdlg.surfaces, FALSE); + SetDlgItemInt (hDlg, IDC_RESERVED, current_hfdlg.reserved, FALSE); + SetDlgItemInt (hDlg, IDC_BLOCKSIZE, current_hfdlg.blocksize, FALSE); + SetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, current_hfdlg.bootpri >= -127 ? current_hfdlg.bootpri : -127, TRUE); + CheckDlgButton (hDlg, IDC_HDF_RW, current_hfdlg.rw); + CheckDlgButton (hDlg, IDC_HDF_AUTOBOOT, current_hfdlg.autoboot); + CheckDlgButton (hDlg, IDC_HDF_DONOTMOUNT, current_hfdlg.donotmount); + ew (hDlg, IDC_HDF_RDB, !rdb); + ew (hDlg, IDC_HDF_AUTOBOOT, !rdb); + ew (hDlg, IDC_HDF_DONOTMOUNT, !rdb); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); } static void inithdcontroller (HWND hDlg) { - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"UAE"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE0"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE1"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE2"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE3"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI0"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI1"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI2"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI3"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI4"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI5"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI6"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSRAM"); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, 0, 0); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"UAE"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE0"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE1"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE2"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"IDE3"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI0"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI1"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI2"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI3"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI4"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI5"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSI6"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_ADDSTRING, 0, (LPARAM)L"SCSRAM"); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, 0, 0); } static void inithardfile (HWND hDlg) { - TCHAR tmp[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; - ew (hDlg, IDC_HF_DOSTYPE, FALSE); - ew (hDlg, IDC_HF_CREATE, FALSE); - inithdcontroller (hDlg); - SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_HF_FS_CUSTOM, tmp, sizeof (tmp) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)L"OFS/FFS/RDB"); - SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)L"SFS"); - SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_SETCURSEL, 0, 0); + ew (hDlg, IDC_HF_DOSTYPE, FALSE); + ew (hDlg, IDC_HF_CREATE, FALSE); + inithdcontroller (hDlg); + SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_HF_FS_CUSTOM, tmp, sizeof (tmp) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)L"OFS/FFS/RDB"); + SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)L"SFS"); + SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_SETCURSEL, 0, 0); } static void sethfdostype (HWND hDlg, int idx) { - if (idx == 1) - SetDlgItemText (hDlg, IDC_HF_DOSTYPE, L"0x53465300"); - else - SetDlgItemText (hDlg, IDC_HF_DOSTYPE, L""); + if (idx == 1) + SetDlgItemText (hDlg, IDC_HF_DOSTYPE, L"0x53465300"); + else + SetDlgItemText (hDlg, IDC_HF_DOSTYPE, L""); } static void hardfile_testrdb (HWND hDlg, struct hfdlg_vals *hdf) { - void *f = zfile_fopen (hdf->filename, L"rb", ZFD_NORMAL); - uae_u8 tmp[8]; - int i; - - if (!f) - return; - for (i = 0; i < 16; i++) { - zfile_fseek (f, i * 512, SEEK_SET); - memset (tmp, 0, sizeof tmp); - zfile_fread (tmp, 1, sizeof tmp, f); - if (i == 0 && !memcmp (tmp + 2, "CIS", 3)) { - hdf->controller = HD_CONTROLLER_PCMCIA_SRAM; - break; - } - if (!memcmp (tmp, "RDSK\0\0\0", 7) || !memcmp (tmp, "DRKS\0\0", 6) || (tmp[0] == 0x53 && tmp[1] == 0x10 && tmp[2] == 0x9b && tmp[3] == 0x13 && tmp[4] == 0 && tmp[5] == 0)) { - // RDSK or ADIDE "encoded" RDSK - hdf->sectors = 0; - hdf->surfaces = 0; - hdf->reserved = 0; - hdf->fsfilename[0] = 0; - hdf->bootpri = 0; - hdf->autoboot = 1; - hdf->donotmount = 0; - hdf->devicename[0] = 0; - break; - } - } - zfile_fclose (f); - sethardfile (hDlg); + void *f = zfile_fopen (hdf->filename, L"rb", ZFD_NORMAL); + uae_u8 tmp[8]; + int i; + + if (!f) + return; + for (i = 0; i < 16; i++) { + zfile_fseek (f, i * 512, SEEK_SET); + memset (tmp, 0, sizeof tmp); + zfile_fread (tmp, 1, sizeof tmp, f); + if (i == 0 && !memcmp (tmp + 2, "CIS", 3)) { + hdf->controller = HD_CONTROLLER_PCMCIA_SRAM; + break; + } + if (!memcmp (tmp, "RDSK\0\0\0", 7) || !memcmp (tmp, "DRKS\0\0", 6) || (tmp[0] == 0x53 && tmp[1] == 0x10 && tmp[2] == 0x9b && tmp[3] == 0x13 && tmp[4] == 0 && tmp[5] == 0)) { + // RDSK or ADIDE "encoded" RDSK + hdf->sectors = 0; + hdf->surfaces = 0; + hdf->reserved = 0; + hdf->fsfilename[0] = 0; + hdf->bootpri = 0; + hdf->autoboot = 1; + hdf->donotmount = 0; + hdf->devicename[0] = 0; + break; + } + } + zfile_fclose (f); + sethardfile (hDlg); } static void updatehdfinfo (HWND hDlg, int force) { - static uae_u64 bsize; - static uae_u8 id[512]; - int blocks, cyls, i; - TCHAR tmp[200], tmp2[200]; - TCHAR idtmp[9]; - - if (force) { - struct hardfiledata hfd; - memset (id, 0, sizeof id); - memset (&hfd, 0, sizeof hfd); - hfd.readonly = 1; - hfd.blocksize = 512; - if (hdf_open (&hfd, current_hfdlg.filename)) { - for (i = 0; i < 16; i++) { - hdf_read (&hfd, id, i * 512, 512); - bsize = hfd.virtsize; - if (!memcmp (id, "RDSK", 4)) - break; - } - if (i == 16) - hdf_read (&hfd, id, 0, 512); - hdf_close (&hfd); - } - } - cyls = 0; - if (current_hfdlg.blocksize * current_hfdlg.sectors * current_hfdlg.surfaces) - cyls = bsize / (current_hfdlg.blocksize * current_hfdlg.sectors * current_hfdlg.surfaces); - blocks = cyls * (current_hfdlg.sectors * current_hfdlg.surfaces); - for (i = 0; i < sizeof (idtmp) / sizeof (TCHAR) - 1; i++) { - TCHAR c = id[i]; - if (c < 32 || c > 126) - c = '.'; - idtmp[i] = c; - idtmp[i + 1] = 0; - } - - tmp[0] = 0; - if (bsize) { - _stprintf (tmp2, L" %s [%02X%02X%02X%02X%02X%02X%02X%02X]", idtmp, id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); - if (!cyls || !blocks) { - _stprintf (tmp, L"%dMB", bsize / (1024 * 1024)); - } else { - _stprintf (tmp, L"%u cyls, %u blocks, %.1fMB/%.1fMB", - cyls, blocks, - (double)blocks * 1.0 * current_hfdlg.blocksize / (1024.0 * 1024.0), - (double)bsize / (1024.0 * 1024.0)); - if (cyls > 65535) { - _stprintf (tmp2, L" %4.4s [%02X%02X%02X%02X]", idtmp, id[0], id[1], id[2], id[3]); - _tcscat (tmp, L" [Too many cyls]"); - } + static uae_u64 bsize; + static uae_u8 id[512]; + int blocks, cyls, i; + TCHAR tmp[200], tmp2[200]; + TCHAR idtmp[9]; + + if (force) { + struct hardfiledata hfd; + memset (id, 0, sizeof id); + memset (&hfd, 0, sizeof hfd); + hfd.readonly = 1; + hfd.blocksize = 512; + if (hdf_open (&hfd, current_hfdlg.filename)) { + for (i = 0; i < 16; i++) { + hdf_read (&hfd, id, i * 512, 512); + bsize = hfd.virtsize; + if (!memcmp (id, "RDSK", 4)) + break; + } + if (i == 16) + hdf_read (&hfd, id, 0, 512); + hdf_close (&hfd); + } } - _tcscat (tmp, tmp2); - } - SetDlgItemText (hDlg, IDC_HDFINFO, tmp); + + cyls = 0; + if (current_hfdlg.blocksize * current_hfdlg.sectors * current_hfdlg.surfaces) { + if (bsize >= 512 * 1024 * 1024 && current_hfdlg.original) { + getchsgeometry (bsize, ¤t_hfdlg.cylinders, ¤t_hfdlg.surfaces, ¤t_hfdlg.sectors); + current_hfdlg.original = 0; + } + cyls = bsize / (current_hfdlg.blocksize * current_hfdlg.sectors * current_hfdlg.surfaces); + } + blocks = cyls * (current_hfdlg.sectors * current_hfdlg.surfaces); + for (i = 0; i < sizeof (idtmp) / sizeof (TCHAR) - 1; i++) { + TCHAR c = id[i]; + if (c < 32 || c > 126) + c = '.'; + idtmp[i] = c; + idtmp[i + 1] = 0; + } + + tmp[0] = 0; + if (bsize) { + _stprintf (tmp2, L" %s [%02X%02X%02X%02X%02X%02X%02X%02X]", idtmp, id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); + if (!cyls || !blocks) { + _stprintf (tmp, L"%dMB", bsize / (1024 * 1024)); + } else { + _stprintf (tmp, L"%u cyls, %u blocks, %.1fMB/%.1fMB", + cyls, blocks, + (double)blocks * 1.0 * current_hfdlg.blocksize / (1024.0 * 1024.0), + (double)bsize / (1024.0 * 1024.0)); + if (cyls > 65535) { + _stprintf (tmp2, L" %4.4s [%02X%02X%02X%02X]", idtmp, id[0], id[1], id[2], id[3]); + _tcscat (tmp, L" [Too many cyls]"); + } + } + _tcscat (tmp, tmp2); + } + SetDlgItemText (hDlg, IDC_HDFINFO, tmp); } static void hardfileselecthdf (HWND hDlg, TCHAR *newpath) { - DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs, newpath); - GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename, sizeof current_hfdlg.filename / sizeof (TCHAR)); - inithardfile (hDlg); - hardfile_testrdb (hDlg, ¤t_hfdlg); - updatehdfinfo (hDlg, 1); + DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs, newpath); + GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename, sizeof current_hfdlg.filename / sizeof (TCHAR)); + inithardfile (hDlg); + hardfile_testrdb (hDlg, ¤t_hfdlg); + updatehdfinfo (hDlg, 1); + sethardfile (hDlg); } static void hardfilecreatehdf (HWND hDlg, TCHAR *newpath) { - LRESULT res; - UINT setting = CalculateHardfileSize (hDlg); - TCHAR dostype[16]; - GetDlgItemText (hDlg, IDC_HF_DOSTYPE, dostype, sizeof (dostype) / sizeof (TCHAR)); - res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); - if (res == 0) - dostype[0] = 0; - CreateHardFile (hDlg, setting, dostype, newpath); + LRESULT res; + UINT setting = CalculateHardfileSize (hDlg); + TCHAR dostype[16]; + GetDlgItemText (hDlg, IDC_HF_DOSTYPE, dostype, sizeof (dostype) / sizeof (TCHAR)); + res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); + if (res == 0) + dostype[0] = 0; + CreateHardFile (hDlg, setting, dostype, newpath); + sethardfile (hDlg); } static INT_PTR CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - LRESULT res, posn; - TCHAR tmp[MAX_DPATH]; + static int recursive = 0; + LRESULT res, posn; + TCHAR tmp[MAX_DPATH]; - switch (msg) { - case WM_INITDIALOG: - recursive++; - inithardfile (hDlg); - sethardfile (hDlg); - sethfdostype (hDlg, 0); - updatehdfinfo (hDlg, 1); - setac (hDlg, IDC_PATH_NAME); - recursive--; - return TRUE; + switch (msg) { + case WM_INITDIALOG: + recursive++; + inithardfile (hDlg); + sethardfile (hDlg); + sethfdostype (hDlg, 0); + updatehdfinfo (hDlg, 1); + setac (hDlg, IDC_PATH_NAME); + recursive--; + return TRUE; - case WM_CONTEXTMENU: - if (GetDlgCtrlID ((HWND)wParam) == IDC_SELECTOR) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, s); - xfree (s); - hardfileselecthdf (hDlg, path); - } - } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FILESYS_SELECTOR) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, s); - xfree (s); - DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, path); - } - } else if (GetDlgCtrlID ((HWND)wParam) == IDC_HF_CREATE) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - TCHAR path[MAX_DPATH]; - _tcscpy (path, s); - xfree (s); - hardfilecreatehdf (hDlg, path); - } - } - break; + case WM_CONTEXTMENU: + if (GetDlgCtrlID ((HWND)wParam) == IDC_SELECTOR) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, s); + xfree (s); + hardfileselecthdf (hDlg, path); + } + } else if (GetDlgCtrlID ((HWND)wParam) == IDC_FILESYS_SELECTOR) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, s); + xfree (s); + DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, path); + } + } else if (GetDlgCtrlID ((HWND)wParam) == IDC_HF_CREATE) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + TCHAR path[MAX_DPATH]; + _tcscpy (path, s); + xfree (s); + hardfilecreatehdf (hDlg, path); + } + } + break; - case WM_COMMAND: - if (recursive) - break; - recursive++; + case WM_COMMAND: + if (recursive) + break; + recursive++; - switch (LOWORD (wParam)) { - case IDC_HF_SIZE: - ew (hDlg, IDC_HF_CREATE, CalculateHardfileSize (hDlg) > 0); - break; - case IDC_HF_TYPE: - res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); - sethfdostype (hDlg, (int)res); - ew (hDlg, IDC_HF_DOSTYPE, res >= 2); - break; - case IDC_HF_CREATE: - hardfilecreatehdf (hDlg, NULL); - break; - case IDC_SELECTOR: - hardfileselecthdf (hDlg, NULL); - break; - case IDC_FILESYS_SELECTOR: - DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, 0); - break; - case IDOK: - if (_tcslen (current_hfdlg.filename) == 0) { - TCHAR szMessage[MAX_DPATH]; - TCHAR 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); - break; - } - EndDialog (hDlg, 1); - break; - case IDCANCEL: - EndDialog (hDlg, 0); - break; - case IDC_HDF_RW: - current_hfdlg.rw = IsDlgButtonChecked (hDlg, IDC_HDF_RW); - break; - case IDC_HDF_AUTOBOOT: - current_hfdlg.autoboot = IsDlgButtonChecked (hDlg, IDC_HDF_AUTOBOOT); - break; - case IDC_HDF_DONOTMOUNT: - current_hfdlg.donotmount = IsDlgButtonChecked (hDlg, IDC_HDF_DONOTMOUNT); - break; - case IDC_HDF_RDB: - SetDlgItemInt (hDlg, IDC_SECTORS, 0, FALSE); - SetDlgItemInt (hDlg, IDC_RESERVED, 0, FALSE); - SetDlgItemInt (hDlg, IDC_HEADS, 0, FALSE); - SetDlgItemText (hDlg, IDC_PATH_FILESYS, L""); - SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, L""); - current_hfdlg.sectors = current_hfdlg.reserved = current_hfdlg.surfaces = 0; - current_hfdlg.autoboot = 1; - current_hfdlg.donotmount = 0; - sethardfile (hDlg); - break; - } + switch (LOWORD (wParam)) { + case IDC_HF_SIZE: + ew (hDlg, IDC_HF_CREATE, CalculateHardfileSize (hDlg) > 0); + break; + case IDC_HF_TYPE: + res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); + sethfdostype (hDlg, (int)res); + ew (hDlg, IDC_HF_DOSTYPE, res >= 2); + break; + case IDC_HF_CREATE: + current_hfdlg = empty_hfdlg; + hardfilecreatehdf (hDlg, NULL); + break; + case IDC_SELECTOR: + current_hfdlg = empty_hfdlg; + hardfileselecthdf (hDlg, NULL); + break; + case IDC_FILESYS_SELECTOR: + DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, 0); + break; + case IDOK: + if (_tcslen (current_hfdlg.filename) == 0) { + TCHAR szMessage[MAX_DPATH]; + TCHAR 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); + break; + } + EndDialog (hDlg, 1); + break; + case IDCANCEL: + EndDialog (hDlg, 0); + break; + case IDC_HDF_RW: + current_hfdlg.rw = IsDlgButtonChecked (hDlg, IDC_HDF_RW); + break; + case IDC_HDF_AUTOBOOT: + current_hfdlg.autoboot = IsDlgButtonChecked (hDlg, IDC_HDF_AUTOBOOT); + break; + case IDC_HDF_DONOTMOUNT: + current_hfdlg.donotmount = IsDlgButtonChecked (hDlg, IDC_HDF_DONOTMOUNT); + break; + case IDC_HDF_RDB: + SetDlgItemInt (hDlg, IDC_SECTORS, 0, FALSE); + SetDlgItemInt (hDlg, IDC_RESERVED, 0, FALSE); + SetDlgItemInt (hDlg, IDC_HEADS, 0, FALSE); + SetDlgItemText (hDlg, IDC_PATH_FILESYS, L""); + SetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, L""); + current_hfdlg.sectors = current_hfdlg.reserved = current_hfdlg.surfaces = 0; + current_hfdlg.autoboot = 1; + current_hfdlg.donotmount = 0; + sethardfile (hDlg); + break; + } - current_hfdlg.sectors = GetDlgItemInt (hDlg, IDC_SECTORS, NULL, FALSE); - current_hfdlg.reserved = GetDlgItemInt (hDlg, IDC_RESERVED, NULL, FALSE); - current_hfdlg.surfaces = GetDlgItemInt (hDlg, IDC_HEADS, NULL, FALSE); - current_hfdlg.blocksize = GetDlgItemInt (hDlg, IDC_BLOCKSIZE, NULL, FALSE); - current_hfdlg.bootpri = GetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, NULL, TRUE); - GetDlgItemText (hDlg, IDC_PATH_NAME, tmp, sizeof tmp / sizeof (TCHAR)); - if (_tcscmp (tmp, current_hfdlg.filename)) { - _tcscpy (current_hfdlg.filename, tmp); - updatehdfinfo (hDlg, 1); - } - GetDlgItemText (hDlg, IDC_PATH_FILESYS, current_hfdlg.fsfilename, sizeof current_hfdlg.fsfilename / sizeof (TCHAR)); - GetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.devicename, sizeof current_hfdlg.devicename / sizeof (TCHAR)); - posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_GETCURSEL, 0, 0); - if (posn != CB_ERR) - current_hfdlg.controller = posn; - updatehdfinfo (hDlg, 0); - recursive--; + current_hfdlg.sectors = GetDlgItemInt (hDlg, IDC_SECTORS, NULL, FALSE); + current_hfdlg.reserved = GetDlgItemInt (hDlg, IDC_RESERVED, NULL, FALSE); + current_hfdlg.surfaces = GetDlgItemInt (hDlg, IDC_HEADS, NULL, FALSE); + current_hfdlg.blocksize = GetDlgItemInt (hDlg, IDC_BLOCKSIZE, NULL, FALSE); + current_hfdlg.bootpri = GetDlgItemInt (hDlg, IDC_HARDFILE_BOOTPRI, NULL, TRUE); + GetDlgItemText (hDlg, IDC_PATH_NAME, tmp, sizeof tmp / sizeof (TCHAR)); + if (_tcscmp (tmp, current_hfdlg.filename)) { + _tcscpy (current_hfdlg.filename, tmp); + updatehdfinfo (hDlg, 1); + } + GetDlgItemText (hDlg, IDC_PATH_FILESYS, current_hfdlg.fsfilename, sizeof current_hfdlg.fsfilename / sizeof (TCHAR)); + GetDlgItemText (hDlg, IDC_HARDFILE_DEVICE, current_hfdlg.devicename, sizeof current_hfdlg.devicename / sizeof (TCHAR)); + posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_GETCURSEL, 0, 0); + if (posn != CB_ERR) + current_hfdlg.controller = posn; + updatehdfinfo (hDlg, 0); + recursive--; - break; - } - return FALSE; + break; + } + return FALSE; } extern int harddrive_to_hdf (HWND, struct uae_prefs*, int); static INT_PTR CALLBACK HarddriveSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - int i; - LRESULT posn; - static int oposn; - - switch (msg) { - case WM_INITDIALOG: - { - int index; - oposn = -1; - hdf_init_target (); - recursive++; - inithdcontroller (hDlg); - CheckDlgButton (hDlg, IDC_HDF_RW, current_hfdlg.rw); - SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_RESETCONTENT, 0, 0); - ew (hDlg, IDC_HARDDRIVE_IMAGE, FALSE); - ew (hDlg, IDOK, FALSE); - ew (hDlg, IDC_HDF_RW, FALSE); - ew (hDlg, IDC_HDF_CONTROLLER, FALSE); - index = -1; - for (i = 0; i < hdf_getnumharddrives (); i++) { - SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_ADDSTRING, 0, (LPARAM)hdf_getnameharddrive (i, 1, NULL, NULL)); - if (!_tcscmp (current_hfdlg.filename, hdf_getnameharddrive (i, 0, NULL, NULL))) - index = i; - } - if (index >= 0) { - SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_SETCURSEL, index, 0); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); - } - recursive--; - return TRUE; - } - case WM_COMMAND: - if (recursive) - break; - recursive++; - posn = SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0); - if (oposn != posn && posn != CB_ERR) { - oposn = posn; - if (posn >= 0) { - int dang = 1; - hdf_getnameharddrive (posn, 1, NULL, &dang); - ew (hDlg, IDC_HARDDRIVE_IMAGE, TRUE); - ew (hDlg, IDOK, TRUE); - ew (hDlg, IDC_HDF_RW, !dang); - if (dang) - current_hfdlg.rw = FALSE; - ew (hDlg, IDC_HDF_CONTROLLER, TRUE); - hardfile_testrdb (hDlg, ¤t_hfdlg); - SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); - CheckDlgButton(hDlg, IDC_HDF_RW, current_hfdlg.rw); - } - } - if (HIWORD (wParam) == BN_CLICKED) { - switch (LOWORD (wParam)) { - case IDOK: - EndDialog (hDlg, 1); - break; - case IDCANCEL: - EndDialog (hDlg, 0); - break; - case IDC_HARDDRIVE_IMAGE: + static int recursive = 0; + int i; + LRESULT posn; + static int oposn; + + switch (msg) { + case WM_INITDIALOG: + { + int index; + oposn = -1; + hdf_init_target (); + recursive++; + inithdcontroller (hDlg); + CheckDlgButton (hDlg, IDC_HDF_RW, current_hfdlg.rw); + SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_RESETCONTENT, 0, 0); + ew (hDlg, IDC_HARDDRIVE_IMAGE, FALSE); + ew (hDlg, IDOK, FALSE); + ew (hDlg, IDC_HDF_RW, FALSE); + ew (hDlg, IDC_HDF_CONTROLLER, FALSE); + index = -1; + for (i = 0; i < hdf_getnumharddrives (); i++) { + SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_ADDSTRING, 0, (LPARAM)hdf_getnameharddrive (i, 1, NULL, NULL)); + if (!_tcscmp (current_hfdlg.filename, hdf_getnameharddrive (i, 0, NULL, NULL))) + index = i; + } + if (index >= 0) { + SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_SETCURSEL, index, 0); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); + } + recursive--; + return TRUE; + } + case WM_COMMAND: + if (recursive) + break; + recursive++; + posn = SendDlgItemMessage (hDlg, IDC_HARDDRIVE, CB_GETCURSEL, 0, 0); + if (oposn != posn && posn != CB_ERR) { + oposn = posn; + if (posn >= 0) { + int dang = 1; + hdf_getnameharddrive (posn, 1, NULL, &dang); + ew (hDlg, IDC_HARDDRIVE_IMAGE, TRUE); + ew (hDlg, IDOK, TRUE); + ew (hDlg, IDC_HDF_RW, !dang); + if (dang) + current_hfdlg.rw = FALSE; + ew (hDlg, IDC_HDF_CONTROLLER, TRUE); + hardfile_testrdb (hDlg, ¤t_hfdlg); + SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_SETCURSEL, current_hfdlg.controller, 0); + CheckDlgButton(hDlg, IDC_HDF_RW, current_hfdlg.rw); + } + } + if (HIWORD (wParam) == BN_CLICKED) { + switch (LOWORD (wParam)) { + case IDOK: + EndDialog (hDlg, 1); + break; + case IDCANCEL: + EndDialog (hDlg, 0); + break; + case IDC_HARDDRIVE_IMAGE: + if (posn != CB_ERR) + harddrive_to_hdf (hDlg, &workprefs, posn); + break; + } + } if (posn != CB_ERR) - harddrive_to_hdf (hDlg, &workprefs, posn); + _tcscpy (current_hfdlg.filename, hdf_getnameharddrive ((int)posn, 0, ¤t_hfdlg.blocksize, NULL)); + current_hfdlg.rw = IsDlgButtonChecked (hDlg, IDC_HDF_RW); + posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_GETCURSEL, 0, 0); + if (posn != CB_ERR) + current_hfdlg.controller = posn; + recursive--; break; - } } - if (posn != CB_ERR) - _tcscpy (current_hfdlg.filename, hdf_getnameharddrive ((int)posn, 0, ¤t_hfdlg.blocksize, NULL)); - current_hfdlg.rw = IsDlgButtonChecked (hDlg, IDC_HDF_RW); - posn = SendDlgItemMessage (hDlg, IDC_HDF_CONTROLLER, CB_GETCURSEL, 0, 0); - if (posn != CB_ERR) - current_hfdlg.controller = posn; - recursive--; - break; - } - return FALSE; + return FALSE; } static int tweakbootpri (int bp, int ab, int dnm) { - if (dnm) - return -129; - if (!ab) - return -128; - if (bp < -127) - bp = -127; - return bp; + if (dnm) + return -129; + if (!ab) + return -128; + if (bp < -127) + bp = -127; + return bp; } static void new_filesys (HWND hDlg, int entry) { - struct uaedev_config_info *uci; - int bp = tweakbootpri (current_fsvdlg.bootpri, current_fsvdlg.autoboot, current_fsvdlg.donotmount); + struct uaedev_config_info *uci; + int bp = tweakbootpri (current_fsvdlg.bootpri, current_fsvdlg.autoboot, current_fsvdlg.donotmount); - uci = add_filesys_config (&workprefs, entry, current_fsvdlg.device, current_fsvdlg.volume, - current_fsvdlg.rootdir, ! current_fsvdlg.rw, 0, 0, 0, 0, bp, 0, 0, 0); - if (uci) { - if (uci->rootdir[0]) - filesys_media_change (uci->rootdir, 1, uci); - else - filesys_eject (uci->configoffset); - } + uci = add_filesys_config (&workprefs, entry, current_fsvdlg.device, current_fsvdlg.volume, + current_fsvdlg.rootdir, ! current_fsvdlg.rw, 0, 0, 0, 0, bp, 0, 0, 0); + if (uci) { + if (uci->rootdir[0]) + filesys_media_change (uci->rootdir, 1, uci); + else + filesys_eject (uci->configoffset); + } } static void new_hardfile (HWND hDlg, int entry) { - struct uaedev_config_info *uci; - int bp = tweakbootpri (current_hfdlg.bootpri, current_hfdlg.autoboot, current_hfdlg.donotmount); + struct uaedev_config_info *uci; + int bp = tweakbootpri (current_hfdlg.bootpri, current_hfdlg.autoboot, current_hfdlg.donotmount); - uci = add_filesys_config (&workprefs, entry, current_hfdlg.devicename, 0, - current_hfdlg.filename, ! current_hfdlg.rw, - current_hfdlg.sectors, current_hfdlg.surfaces, - current_hfdlg.reserved, current_hfdlg.blocksize, - bp, current_hfdlg.fsfilename, - current_hfdlg.controller, 0); - if (uci) - hardfile_do_disk_change (uci, 1); + uci = add_filesys_config (&workprefs, entry, current_hfdlg.devicename, 0, + current_hfdlg.filename, ! current_hfdlg.rw, + current_hfdlg.sectors, current_hfdlg.surfaces, + current_hfdlg.reserved, current_hfdlg.blocksize, + bp, current_hfdlg.fsfilename, + current_hfdlg.controller, 0); + if (uci) + hardfile_do_disk_change (uci, 1); } static void new_harddrive (HWND hDlg, int entry) { - struct uaedev_config_info *uci; + struct uaedev_config_info *uci; - uci = add_filesys_config (&workprefs, entry, 0, 0, - current_hfdlg.filename, ! current_hfdlg.rw, 0, 0, - 0, current_hfdlg.blocksize, 0, 0, current_hfdlg.controller, 0); - if (uci) - hardfile_do_disk_change (uci, 1); + uci = add_filesys_config (&workprefs, entry, 0, 0, + current_hfdlg.filename, ! current_hfdlg.rw, 0, 0, + 0, current_hfdlg.blocksize, 0, 0, current_hfdlg.controller, 0); + if (uci) + hardfile_do_disk_change (uci, 1); } static void harddisk_remove (HWND hDlg) { - int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); - if (entry < 0) - return; - kill_filesys_unitconfig (&workprefs, entry); + int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); + if (entry < 0) + return; + kill_filesys_unitconfig (&workprefs, entry); } static void harddisk_move (HWND hDlg, int up) { - int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); - if (entry < 0) - return; - move_filesys_unitconfig (&workprefs, entry, up ? entry - 1 : entry + 1); + int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); + if (entry < 0) + return; + move_filesys_unitconfig (&workprefs, entry, up ? entry - 1 : entry + 1); } static void harddisk_edit (HWND hDlg) { - int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); - int type; - struct uaedev_config_info *uci; - struct mountedinfo mi; - - if (entry < 0 || entry >= workprefs.mountitems) - return; - uci = &workprefs.mountconfig[entry]; - - type = get_filesys_unitconfig (&workprefs, entry, &mi); - if (type < 0) - type = uci->ishdf ? FILESYS_HARDFILE : FILESYS_VIRTUAL; - - if(type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) - { - current_hfdlg.sectors = uci->sectors; - current_hfdlg.surfaces = uci->surfaces; - current_hfdlg.reserved = uci->reserved; - current_hfdlg.cylinders = mi.nrcyls; - current_hfdlg.blocksize = uci->blocksize; - current_hfdlg.controller = uci->controller; - - _tcsncpy (current_hfdlg.filename, uci->rootdir, (sizeof current_hfdlg.filename / sizeof (TCHAR)) - 1); - current_hfdlg.filename[(sizeof current_hfdlg.filename / sizeof (TCHAR)) - 1] = '\0'; - current_hfdlg.fsfilename[0] = 0; - if (uci->filesys) { - _tcsncpy (current_hfdlg.fsfilename, uci->filesys, (sizeof current_hfdlg.fsfilename / sizeof (TCHAR)) - 1); - current_hfdlg.fsfilename[(sizeof current_hfdlg.fsfilename / sizeof (TCHAR)) - 1] = '\0'; - } - current_fsvdlg.device[0] = 0; - if (uci->devname) { - _tcsncpy (current_hfdlg.devicename, uci->devname, (sizeof current_hfdlg.devicename / sizeof (TCHAR)) - 1); - current_hfdlg.devicename[(sizeof current_hfdlg.devicename / sizeof (TCHAR)) - 1] = '\0'; - } - current_hfdlg.rw = !uci->readonly; - current_hfdlg.bootpri = uci->bootpri; - current_hfdlg.autoboot = uci->autoboot; - current_hfdlg.donotmount = uci->donotmount; - if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc)) { - new_hardfile (hDlg, entry); - } - } - else if (type == FILESYS_HARDDRIVE) /* harddisk */ - { - current_hfdlg.controller = uci->controller; - current_hfdlg.rw = !uci->readonly; - _tcsncpy (current_hfdlg.filename, uci->rootdir, (sizeof current_hfdlg.filename) / sizeof (TCHAR) - 1); - current_hfdlg.filename[(sizeof current_hfdlg.filename) / sizeof (TCHAR) - 1] = '\0'; - if (CustomDialogBox (IDD_HARDDRIVE, hDlg, HarddriveSettingsProc)) { - new_harddrive (hDlg, entry); - } - } - else /* Filesystem */ - { - _tcsncpy (current_fsvdlg.rootdir, uci->rootdir, (sizeof current_fsvdlg.rootdir / sizeof (TCHAR)) - 1); - current_fsvdlg.rootdir[sizeof (current_fsvdlg.rootdir) / sizeof (TCHAR) - 1] = '\0'; - _tcsncpy (current_fsvdlg.volume, uci->volname, (sizeof current_fsvdlg.volume / sizeof (TCHAR)) - 1); - current_fsvdlg.volume[sizeof (current_fsvdlg.volume) / sizeof (TCHAR) - 1] = '\0'; - current_fsvdlg.device[0] = 0; - if (uci->devname) { - _tcsncpy (current_fsvdlg.device, uci->devname, (sizeof current_fsvdlg.device) / sizeof (TCHAR) - 1); - current_fsvdlg.device[sizeof (current_fsvdlg.device) / sizeof (TCHAR) - 1] = '\0'; - } - current_fsvdlg.rw = !uci->readonly; - current_fsvdlg.bootpri = uci->bootpri; - current_fsvdlg.autoboot = uci->autoboot; - current_fsvdlg.donotmount = uci->donotmount; - archivehd = -1; - if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) { - new_filesys (hDlg, entry); - } - } + int entry = listview_find_selected (GetDlgItem (hDlg, IDC_VOLUMELIST)); + int type; + struct uaedev_config_info *uci; + struct mountedinfo mi; + + if (entry < 0 || entry >= workprefs.mountitems) + return; + uci = &workprefs.mountconfig[entry]; + + type = get_filesys_unitconfig (&workprefs, entry, &mi); + if (type < 0) + type = uci->ishdf ? FILESYS_HARDFILE : FILESYS_VIRTUAL; + + if(type == FILESYS_HARDFILE || type == FILESYS_HARDFILE_RDB) + { + current_hfdlg.sectors = uci->sectors; + current_hfdlg.surfaces = uci->surfaces; + current_hfdlg.reserved = uci->reserved; + current_hfdlg.cylinders = mi.nrcyls; + current_hfdlg.blocksize = uci->blocksize; + current_hfdlg.controller = uci->controller; + + _tcsncpy (current_hfdlg.filename, uci->rootdir, (sizeof current_hfdlg.filename / sizeof (TCHAR)) - 1); + current_hfdlg.filename[(sizeof current_hfdlg.filename / sizeof (TCHAR)) - 1] = '\0'; + current_hfdlg.fsfilename[0] = 0; + if (uci->filesys) { + _tcsncpy (current_hfdlg.fsfilename, uci->filesys, (sizeof current_hfdlg.fsfilename / sizeof (TCHAR)) - 1); + current_hfdlg.fsfilename[(sizeof current_hfdlg.fsfilename / sizeof (TCHAR)) - 1] = '\0'; + } + current_fsvdlg.device[0] = 0; + if (uci->devname) { + _tcsncpy (current_hfdlg.devicename, uci->devname, (sizeof current_hfdlg.devicename / sizeof (TCHAR)) - 1); + current_hfdlg.devicename[(sizeof current_hfdlg.devicename / sizeof (TCHAR)) - 1] = '\0'; + } + current_hfdlg.rw = !uci->readonly; + current_hfdlg.bootpri = uci->bootpri; + current_hfdlg.autoboot = uci->autoboot; + current_hfdlg.donotmount = uci->donotmount; + if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc)) { + new_hardfile (hDlg, entry); + } + } + else if (type == FILESYS_HARDDRIVE) /* harddisk */ + { + current_hfdlg.controller = uci->controller; + current_hfdlg.rw = !uci->readonly; + _tcsncpy (current_hfdlg.filename, uci->rootdir, (sizeof current_hfdlg.filename) / sizeof (TCHAR) - 1); + current_hfdlg.filename[(sizeof current_hfdlg.filename) / sizeof (TCHAR) - 1] = '\0'; + if (CustomDialogBox (IDD_HARDDRIVE, hDlg, HarddriveSettingsProc)) { + new_harddrive (hDlg, entry); + } + } + else /* Filesystem */ + { + _tcsncpy (current_fsvdlg.rootdir, uci->rootdir, (sizeof current_fsvdlg.rootdir / sizeof (TCHAR)) - 1); + current_fsvdlg.rootdir[sizeof (current_fsvdlg.rootdir) / sizeof (TCHAR) - 1] = '\0'; + _tcsncpy (current_fsvdlg.volume, uci->volname, (sizeof current_fsvdlg.volume / sizeof (TCHAR)) - 1); + current_fsvdlg.volume[sizeof (current_fsvdlg.volume) / sizeof (TCHAR) - 1] = '\0'; + current_fsvdlg.device[0] = 0; + if (uci->devname) { + _tcsncpy (current_fsvdlg.device, uci->devname, (sizeof current_fsvdlg.device) / sizeof (TCHAR) - 1); + current_fsvdlg.device[sizeof (current_fsvdlg.device) / sizeof (TCHAR) - 1] = '\0'; + } + current_fsvdlg.rw = !uci->readonly; + current_fsvdlg.bootpri = uci->bootpri; + current_fsvdlg.autoboot = uci->autoboot; + current_fsvdlg.donotmount = uci->donotmount; + archivehd = -1; + if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) { + new_filesys (hDlg, entry); + } + } } static ACCEL HarddiskAccel[] = { - { FVIRTKEY, VK_UP, 10001 }, { FVIRTKEY, VK_DOWN, 10002 }, - { FVIRTKEY|FSHIFT, VK_UP, IDC_UP }, { FVIRTKEY|FSHIFT, VK_DOWN, IDC_DOWN }, - { FVIRTKEY, VK_RETURN, IDC_EDIT }, { FVIRTKEY, VK_DELETE, IDC_REMOVE }, - { 0, 0, 0 } + { FVIRTKEY, VK_UP, 10001 }, { FVIRTKEY, VK_DOWN, 10002 }, + { FVIRTKEY|FSHIFT, VK_UP, IDC_UP }, { FVIRTKEY|FSHIFT, VK_DOWN, IDC_DOWN }, + { FVIRTKEY, VK_RETURN, IDC_EDIT }, { FVIRTKEY, VK_DELETE, IDC_REMOVE }, + { 0, 0, 0 } }; static void harddiskdlg_button (HWND hDlg, int button) { - switch (button) { - case IDC_NEW_FS: - current_fsvdlg = empty_fsvdlg; - archivehd = 0; - if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) - new_filesys (hDlg, -1); - break; - case IDC_NEW_FSARCH: - archivehd = 1; - current_fsvdlg = empty_fsvdlg; - if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) - new_filesys (hDlg, -1); - break; - - case IDC_NEW_HF: - current_hfdlg = empty_hfdlg; - if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc)) - new_hardfile (hDlg, -1); - break; - - case IDC_NEW_HD: - memset (¤t_hfdlg, 0, sizeof (current_hfdlg)); - if (hdf_init_target () == 0) { - TCHAR tmp[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_NOHARDDRIVES, tmp, sizeof (tmp) / sizeof (TCHAR)); - gui_message (tmp); - } else { - if (CustomDialogBox (IDD_HARDDRIVE, hDlg, HarddriveSettingsProc)) - new_harddrive (hDlg, -1); - } - break; + switch (button) { + case IDC_NEW_FS: + current_fsvdlg = empty_fsvdlg; + archivehd = 0; + if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) + new_filesys (hDlg, -1); + break; + case IDC_NEW_FSARCH: + archivehd = 1; + current_fsvdlg = empty_fsvdlg; + if (CustomDialogBox (IDD_FILESYS, hDlg, VolumeSettingsProc)) + new_filesys (hDlg, -1); + break; - case IDC_EDIT: - harddisk_edit (hDlg); - break; + case IDC_NEW_HF: + current_hfdlg = empty_hfdlg; + if (CustomDialogBox (IDD_HARDFILE, hDlg, HardfileSettingsProc)) + new_hardfile (hDlg, -1); + break; - case IDC_REMOVE: - harddisk_remove (hDlg); - break; + case IDC_NEW_HD: + memset (¤t_hfdlg, 0, sizeof (current_hfdlg)); + if (hdf_init_target () == 0) { + TCHAR tmp[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_NOHARDDRIVES, tmp, sizeof (tmp) / sizeof (TCHAR)); + gui_message (tmp); + } else { + if (CustomDialogBox (IDD_HARDDRIVE, hDlg, HarddriveSettingsProc)) + new_harddrive (hDlg, -1); + } + break; + + case IDC_EDIT: + harddisk_edit (hDlg); + break; + + case IDC_REMOVE: + harddisk_remove (hDlg); + break; - case IDC_UP: - harddisk_move (hDlg, 1); - clicked_entry--; - break; + case IDC_UP: + harddisk_move (hDlg, 1); + clicked_entry--; + break; - case IDC_DOWN: - harddisk_move (hDlg, 0); - clicked_entry++; - break; + case IDC_DOWN: + harddisk_move (hDlg, 0); + clicked_entry++; + break; - case IDC_MAPDRIVES_AUTO: - workprefs.win32_automount_removable = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_AUTO); - break; + case IDC_MAPDRIVES_AUTO: + workprefs.win32_automount_removable = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_AUTO); + break; - case IDC_MAPDRIVES: - workprefs.win32_automount_drives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES); - break; + case IDC_MAPDRIVES: + workprefs.win32_automount_drives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES); + break; - case IDC_MAPDRIVES_REMOVABLE: - workprefs.win32_automount_removabledrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_REMOVABLE); - break; + case IDC_MAPDRIVES_REMOVABLE: + workprefs.win32_automount_removabledrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_REMOVABLE); + break; - case IDC_MAPDRIVES_CD: - workprefs.win32_automount_cddrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_CD); - break; + case IDC_MAPDRIVES_CD: + workprefs.win32_automount_cddrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_CD); + break; - case IDC_MAPDRIVES_NET: - workprefs.win32_automount_netdrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_NET); - break; + case IDC_MAPDRIVES_NET: + workprefs.win32_automount_netdrives = IsDlgButtonChecked (hDlg, IDC_MAPDRIVES_NET); + break; - case IDC_NOUAEFSDB: - workprefs.filesys_no_uaefsdb = IsDlgButtonChecked (hDlg, IDC_NOUAEFSDB); - break; + case IDC_NOUAEFSDB: + workprefs.filesys_no_uaefsdb = IsDlgButtonChecked (hDlg, IDC_NOUAEFSDB); + break; - case IDC_NORECYCLEBIN: - workprefs.win32_norecyclebin = IsDlgButtonChecked (hDlg, IDC_NORECYCLEBIN); - break; + case IDC_NORECYCLEBIN: + workprefs.win32_norecyclebin = IsDlgButtonChecked (hDlg, IDC_NORECYCLEBIN); + break; - } + } } static void harddiskdlg_volume_notify (HWND hDlg, NM_LISTVIEW *nmlistview) { - HWND list = nmlistview->hdr.hwndFrom; - int dblclick = 0; - int entry = 0; - - switch (nmlistview->hdr.code) { - case LVN_BEGINDRAG: - drag_start (hDlg, cachedlist, (LPARAM)nmlistview); - break; - case NM_DBLCLK: - dblclick = 1; - /* fall through */ - case NM_CLICK: - entry = listview_entry_from_click (list, 0); - if (entry >= 0) - { - if(dblclick) - harddisk_edit (hDlg); - InitializeListView (hDlg); - clicked_entry = entry; - // Hilite the current selected item - ListView_SetItemState (cachedlist, clicked_entry, LVIS_SELECTED, LVIS_SELECTED); + HWND list = nmlistview->hdr.hwndFrom; + int dblclick = 0; + int entry = 0; + + switch (nmlistview->hdr.code) { + case LVN_BEGINDRAG: + drag_start (hDlg, cachedlist, (LPARAM)nmlistview); + break; + case NM_DBLCLK: + dblclick = 1; + /* fall through */ + case NM_CLICK: + entry = listview_entry_from_click (list, 0); + if (entry >= 0) + { + if(dblclick) + harddisk_edit (hDlg); + InitializeListView (hDlg); + clicked_entry = entry; + // Hilite the current selected item + ListView_SetItemState (cachedlist, clicked_entry, LVIS_SELECTED, LVIS_SELECTED); + } + break; } - break; - } } static void hilitehd (void) { - int total = ListView_GetItemCount (cachedlist); - if (total <= 0) - return; - if (clicked_entry < 0) - clicked_entry = 0; - if (clicked_entry >= total) - clicked_entry = total; - ListView_SetItemState (cachedlist, clicked_entry, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + int total = ListView_GetItemCount (cachedlist); + if (total <= 0) + return; + if (clicked_entry < 0) + clicked_entry = 0; + if (clicked_entry >= total) + clicked_entry = total; + ListView_SetItemState (cachedlist, clicked_entry, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); } static INT_PTR CALLBACK HarddiskDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) { - case WM_INITDIALOG: - clicked_entry = 0; - pages[HARDDISK_ID] = hDlg; - currentpage = HARDDISK_ID; - EnableWindow (GetDlgItem (hDlg, IDC_NEW_HD), os_winnt_admin > 1 ? TRUE : FALSE); - - case WM_USER: - CheckDlgButton (hDlg, IDC_MAPDRIVES_AUTO, workprefs.win32_automount_removable); - CheckDlgButton (hDlg, IDC_MAPDRIVES, workprefs.win32_automount_drives); - CheckDlgButton (hDlg, IDC_MAPDRIVES_CD, workprefs.win32_automount_cddrives); - CheckDlgButton (hDlg, IDC_MAPDRIVES_NET, workprefs.win32_automount_netdrives); - CheckDlgButton (hDlg, IDC_MAPDRIVES_REMOVABLE, workprefs.win32_automount_removabledrives); - CheckDlgButton (hDlg, IDC_NOUAEFSDB, workprefs.filesys_no_uaefsdb); - CheckDlgButton (hDlg, IDC_NORECYCLEBIN, workprefs.win32_norecyclebin); - InitializeListView (hDlg); - hilitehd (); - break; - - case WM_MOUSEMOVE: - if (drag_move (hDlg, lParam)) - return TRUE; - break; - case WM_LBUTTONUP: - { - int *draggeditems, item; - if ((item = drag_end (hDlg, cachedlist, lParam, &draggeditems)) >= 0) { - move_filesys_unitconfig (&workprefs, draggeditems[0], item); - InitializeListView (hDlg); - clicked_entry = item; - hilitehd (); - } - xfree (draggeditems); - break; - } - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case 10001: - clicked_entry--; - hilitehd (); - break; - case 10002: - clicked_entry++; - hilitehd (); - break; - default: - harddiskdlg_button (hDlg, LOWORD (wParam)); - InitializeListView (hDlg); - hilitehd (); - break; - } - break; - - case WM_NOTIFY: - if (((LPNMHDR) lParam)->idFrom == IDC_VOLUMELIST) - harddiskdlg_volume_notify (hDlg, (NM_LISTVIEW *) lParam); - return TRUE; - default: - return FALSE; - } + switch (msg) { + case WM_INITDIALOG: + clicked_entry = 0; + pages[HARDDISK_ID] = hDlg; + currentpage = HARDDISK_ID; + EnableWindow (GetDlgItem (hDlg, IDC_NEW_HD), os_winnt_admin > 1 ? TRUE : FALSE); + + case WM_USER: + CheckDlgButton (hDlg, IDC_MAPDRIVES_AUTO, workprefs.win32_automount_removable); + CheckDlgButton (hDlg, IDC_MAPDRIVES, workprefs.win32_automount_drives); + CheckDlgButton (hDlg, IDC_MAPDRIVES_CD, workprefs.win32_automount_cddrives); + CheckDlgButton (hDlg, IDC_MAPDRIVES_NET, workprefs.win32_automount_netdrives); + CheckDlgButton (hDlg, IDC_MAPDRIVES_REMOVABLE, workprefs.win32_automount_removabledrives); + CheckDlgButton (hDlg, IDC_NOUAEFSDB, workprefs.filesys_no_uaefsdb); + CheckDlgButton (hDlg, IDC_NORECYCLEBIN, workprefs.win32_norecyclebin); + InitializeListView (hDlg); + hilitehd (); + break; + + case WM_MOUSEMOVE: + if (drag_move (hDlg, lParam)) + return TRUE; + break; + case WM_LBUTTONUP: + { + int *draggeditems, item; + if ((item = drag_end (hDlg, cachedlist, lParam, &draggeditems)) >= 0) { + move_filesys_unitconfig (&workprefs, draggeditems[0], item); + InitializeListView (hDlg); + clicked_entry = item; + hilitehd (); + } + xfree (draggeditems); + break; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case 10001: + clicked_entry--; + hilitehd (); + break; + case 10002: + clicked_entry++; + hilitehd (); + break; + default: + harddiskdlg_button (hDlg, LOWORD (wParam)); + InitializeListView (hDlg); + hilitehd (); + break; + } + break; + + case WM_NOTIFY: + if (((LPNMHDR) lParam)->idFrom == IDC_VOLUMELIST) + harddiskdlg_volume_notify (hDlg, (NM_LISTVIEW *) lParam); + return TRUE; + default: + return FALSE; + } - return FALSE; + return FALSE; } #endif static void out_floppyspeed (HWND hDlg) { - TCHAR txt[30]; - TCHAR tmp1[MAX_DPATH]; - TCHAR tmp2[MAX_DPATH]; + TCHAR txt[30]; + TCHAR tmp1[MAX_DPATH]; + TCHAR tmp2[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_FLOPPY_COMPATIBLE, tmp1, sizeof (tmp1) / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPY_TURBO, tmp2, sizeof (tmp2) / sizeof (TCHAR)); - if (workprefs.floppy_speed) - _stprintf (txt, L"%d%%%s", workprefs.floppy_speed, workprefs.floppy_speed == 100 ? tmp1 : L""); - else - _tcscpy (txt, tmp2); - SetDlgItemText (hDlg, IDC_FLOPPYSPDTEXT, txt); + WIN32GUI_LoadUIString (IDS_FLOPPY_COMPATIBLE, tmp1, sizeof (tmp1) / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPY_TURBO, tmp2, sizeof (tmp2) / sizeof (TCHAR)); + if (workprefs.floppy_speed) + _stprintf (txt, L"%d%%%s", workprefs.floppy_speed, workprefs.floppy_speed == 100 ? tmp1 : L""); + else + _tcscpy (txt, tmp2); + SetDlgItemText (hDlg, IDC_FLOPPYSPDTEXT, txt); } #define BUTTONSPERFLOPPY 7 static int floppybuttons[][BUTTONSPERFLOPPY] = { - { IDC_DF0TEXT,IDC_DF0,IDC_EJECT0,IDC_DF0TYPE,IDC_DF0WP,IDC_SAVEIMAGE0,IDC_DF0ENABLE }, - { IDC_DF1TEXT,IDC_DF1,IDC_EJECT1,IDC_DF1TYPE,IDC_DF1WP,IDC_SAVEIMAGE1,IDC_DF1ENABLE }, - { IDC_DF2TEXT,IDC_DF2,IDC_EJECT2,IDC_DF2TYPE,IDC_DF2WP,IDC_SAVEIMAGE2,IDC_DF2ENABLE }, - { IDC_DF3TEXT,IDC_DF3,IDC_EJECT3,IDC_DF3TYPE,IDC_DF3WP,IDC_SAVEIMAGE3,IDC_DF3ENABLE } + { IDC_DF0TEXT,IDC_DF0,IDC_EJECT0,IDC_DF0TYPE,IDC_DF0WP,IDC_SAVEIMAGE0,IDC_DF0ENABLE }, + { IDC_DF1TEXT,IDC_DF1,IDC_EJECT1,IDC_DF1TYPE,IDC_DF1WP,IDC_SAVEIMAGE1,IDC_DF1ENABLE }, + { IDC_DF2TEXT,IDC_DF2,IDC_EJECT2,IDC_DF2TYPE,IDC_DF2WP,IDC_SAVEIMAGE2,IDC_DF2ENABLE }, + { IDC_DF3TEXT,IDC_DF3,IDC_EJECT3,IDC_DF3TYPE,IDC_DF3WP,IDC_SAVEIMAGE3,IDC_DF3ENABLE } }; static int floppybuttonsq[][BUTTONSPERFLOPPY] = { - { IDC_DF0TEXTQ,IDC_DF0QQ,IDC_EJECT0Q,-1,IDC_DF0WPQ,-1,IDC_DF0QENABLE }, - { IDC_DF1TEXTQ,IDC_DF1QQ,IDC_EJECT1Q,-1,IDC_DF1WPQ,-1,IDC_DF1QENABLE }, - { -1,-1,-1,-1,-1,-1,-1 }, - { -1,-1,-1,-1,-1,-1,-1 } + { IDC_DF0TEXTQ,IDC_DF0QQ,IDC_EJECT0Q,-1,IDC_DF0WPQ,-1,IDC_DF0QENABLE }, + { IDC_DF1TEXTQ,IDC_DF1QQ,IDC_EJECT1Q,-1,IDC_DF1WPQ,-1,IDC_DF1QENABLE }, + { -1,-1,-1,-1,-1,-1,-1 }, + { -1,-1,-1,-1,-1,-1,-1 } }; static void floppytooltip (HWND hDlg, int num, uae_u32 crc32) { - TOOLINFO ti; - int id; - TCHAR tmp[100]; - - if (currentpage == QUICKSTART_ID) - id = floppybuttonsq[num][0]; - else - id = floppybuttons[num][0]; - ti.cbSize = sizeof (TOOLINFO); - ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; - ti.hwnd = hDlg; - ti.hinst = hInst; - ti.uId = (UINT_PTR)GetDlgItem (hDlg, id); - SendMessage (ToolTipHWND, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); - if (crc32 == 0) - return; - _stprintf (tmp, L"CRC=%08X", crc32); - ti.lpszText = tmp; - SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + TOOLINFO ti; + int id; + TCHAR tmp[100]; + + if (currentpage == QUICKSTART_ID) + id = floppybuttonsq[num][0]; + else + id = floppybuttons[num][0]; + ti.cbSize = sizeof (TOOLINFO); + ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; + ti.hwnd = hDlg; + ti.hinst = hInst; + ti.uId = (UINT_PTR)GetDlgItem (hDlg, id); + SendMessage (ToolTipHWND, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + if (crc32 == 0) + return; + _stprintf (tmp, L"CRC=%08X", crc32); + ti.lpszText = tmp; + SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } static void addfloppyhistory_2 (HWND hDlg, UAEREG *fkey, int n, int f_text) { - int i, j; - TCHAR *s; - int nn = workprefs.dfxtype[n] + 1; - - if (f_text < 0) - return; - SendDlgItemMessage (hDlg, f_text, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, f_text, WM_SETTEXT, 0, (LPARAM)workprefs.df[n]); - i = 0; - while (s = DISK_history_get (i)) { - TCHAR tmpname[MAX_DPATH], tmppath[MAX_DPATH], *p, *p2; - if (_tcslen (s) == 0) - break; - i++; - _tcscpy (tmppath, s); - p = tmppath + _tcslen (tmppath) - 1; - for (j = 0; uae_archive_extensions[j]; j++) { - p2 = _tcsstr (tmppath, uae_archive_extensions[j]); - if (p2) { - p = p2; - break; - } - } - while (p > tmppath) { - if (*p == '\\' || *p == '/') - break; - p--; - } - _tcscpy (tmpname, p + 1); - *++p = 0; - if (tmppath[0]) { - _tcscat (tmpname, L" { "); - _tcscat (tmpname, tmppath); - _tcscat (tmpname, L" }"); - } - if (f_text >= 0) - SendDlgItemMessage (hDlg, f_text, CB_ADDSTRING, 0, (LPARAM)tmpname); - if (!_tcscmp (workprefs.df[n], s)) { - if (f_text >= 0) - SendDlgItemMessage (hDlg, f_text, CB_SETCURSEL, i - 1, 0); + int i, j; + TCHAR *s; + int nn = workprefs.dfxtype[n] + 1; + + if (f_text < 0) + return; + SendDlgItemMessage (hDlg, f_text, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, f_text, WM_SETTEXT, 0, (LPARAM)workprefs.df[n]); + i = 0; + while (s = DISK_history_get (i)) { + TCHAR tmpname[MAX_DPATH], tmppath[MAX_DPATH], *p, *p2; + if (_tcslen (s) == 0) + break; + i++; + _tcscpy (tmppath, s); + p = tmppath + _tcslen (tmppath) - 1; + for (j = 0; uae_archive_extensions[j]; j++) { + p2 = _tcsstr (tmppath, uae_archive_extensions[j]); + if (p2) { + p = p2; + break; + } + } + while (p > tmppath) { + if (*p == '\\' || *p == '/') + break; + p--; + } + _tcscpy (tmpname, p + 1); + *++p = 0; + if (tmppath[0]) { + _tcscat (tmpname, L" { "); + _tcscat (tmpname, tmppath); + _tcscat (tmpname, L" }"); + } + if (f_text >= 0) + SendDlgItemMessage (hDlg, f_text, CB_ADDSTRING, 0, (LPARAM)tmpname); + if (!_tcscmp (workprefs.df[n], s)) { + if (f_text >= 0) + SendDlgItemMessage (hDlg, f_text, CB_SETCURSEL, i - 1, 0); + } + if (nn <= 0) + break; } - if (nn <= 0) - break; - } } static void addfloppyhistory (HWND hDlg) { - UAEREG *fkey; - int f_text, max, n; - - if (currentpage == QUICKSTART_ID) - max = 2; - else if (currentpage == FLOPPY_ID) - max = 4; - else if (currentpage == DISK_ID) - max = 1; - else - return; - fkey = read_disk_history (); - for (n = 0; n < max; n++) { + UAEREG *fkey; + int f_text, max, n; + if (currentpage == QUICKSTART_ID) - f_text = floppybuttonsq[n][0]; + max = 2; else if (currentpage == FLOPPY_ID) - f_text = floppybuttons[n][0]; + max = 4; + else if (currentpage == DISK_ID) + max = 1; else - f_text = IDC_DISKTEXT; - addfloppyhistory_2 (hDlg, fkey, n, f_text); - } - regclosetree (fkey); + return; + fkey = read_disk_history (); + for (n = 0; n < max; n++) { + if (currentpage == QUICKSTART_ID) + f_text = floppybuttonsq[n][0]; + else if (currentpage == FLOPPY_ID) + f_text = floppybuttons[n][0]; + else + f_text = IDC_DISKTEXT; + addfloppyhistory_2 (hDlg, fkey, n, f_text); + } + regclosetree (fkey); } static void addfloppytype (HWND hDlg, int n) { - int state, chk; - int nn = workprefs.dfxtype[n] + 1; - - int f_text = floppybuttons[n][0]; - int f_drive = floppybuttons[n][1]; - int f_eject = floppybuttons[n][2]; - int f_type = floppybuttons[n][3]; - int f_wp = floppybuttons[n][4]; - int f_si = floppybuttons[n][5]; - int f_enable = floppybuttons[n][6]; - - if (currentpage == QUICKSTART_ID) { - f_text = floppybuttonsq[n][0]; - f_drive = floppybuttonsq[n][1]; - f_type = -1; - f_eject = floppybuttonsq[n][2]; - f_wp = floppybuttonsq[n][4]; - f_si = -1; - f_enable = floppybuttonsq[n][6]; - } - - if (nn <= 0) - state = FALSE; - else - state = TRUE; - if (f_type >= 0) - SendDlgItemMessage (hDlg, f_type, CB_SETCURSEL, nn, 0); - if (f_si >= 0) - ShowWindow (GetDlgItem(hDlg, f_si), zfile_exists (DISK_get_saveimagepath (workprefs.df[n])) ? SW_SHOW : SW_HIDE); - - if (f_text >= 0) - ew (hDlg, f_text, state); - if (f_eject >= 0) - ew (hDlg, f_eject, TRUE); - if (f_drive >= 0) - ew (hDlg, f_drive, state); - if (f_enable >= 0) { - if (currentpage == QUICKSTART_ID) - ew (hDlg, f_enable, n > 0 && workprefs.nr_floppies > 0); + int state, chk; + int nn = workprefs.dfxtype[n] + 1; + + int f_text = floppybuttons[n][0]; + int f_drive = floppybuttons[n][1]; + int f_eject = floppybuttons[n][2]; + int f_type = floppybuttons[n][3]; + int f_wp = floppybuttons[n][4]; + int f_si = floppybuttons[n][5]; + int f_enable = floppybuttons[n][6]; + + if (currentpage == QUICKSTART_ID) { + f_text = floppybuttonsq[n][0]; + f_drive = floppybuttonsq[n][1]; + f_type = -1; + f_eject = floppybuttonsq[n][2]; + f_wp = floppybuttonsq[n][4]; + f_si = -1; + f_enable = floppybuttonsq[n][6]; + } + + if (nn <= 0) + state = FALSE; else - ew (hDlg, f_enable, TRUE); - CheckDlgButton(hDlg, f_enable, state ? BST_CHECKED : BST_UNCHECKED); - } - chk = disk_getwriteprotect (workprefs.df[n]) && state == TRUE ? BST_CHECKED : 0; - if (f_wp >= 0) - CheckDlgButton(hDlg, f_wp, chk); - chk = state && DISK_validate_filename (workprefs.df[n], 0, NULL, NULL) ? TRUE : FALSE; - if (f_wp >= 0) - ew (hDlg, f_wp, chk); - } + state = TRUE; + if (f_type >= 0) + SendDlgItemMessage (hDlg, f_type, CB_SETCURSEL, nn, 0); + if (f_si >= 0) + ShowWindow (GetDlgItem(hDlg, f_si), zfile_exists (DISK_get_saveimagepath (workprefs.df[n])) ? SW_SHOW : SW_HIDE); + + if (f_text >= 0) + ew (hDlg, f_text, state); + if (f_eject >= 0) + ew (hDlg, f_eject, TRUE); + if (f_drive >= 0) + ew (hDlg, f_drive, state); + if (f_enable >= 0) { + if (currentpage == QUICKSTART_ID) + ew (hDlg, f_enable, n > 0 && workprefs.nr_floppies > 0); + else + ew (hDlg, f_enable, TRUE); + CheckDlgButton(hDlg, f_enable, state ? BST_CHECKED : BST_UNCHECKED); + } + chk = disk_getwriteprotect (workprefs.df[n]) && state == TRUE ? BST_CHECKED : 0; + if (f_wp >= 0) + CheckDlgButton(hDlg, f_wp, chk); + chk = state && DISK_validate_filename (workprefs.df[n], 0, NULL, NULL) ? TRUE : FALSE; + if (f_wp >= 0) + ew (hDlg, f_wp, chk); +} static void getfloppytype (HWND hDlg, int n) { - int f_type = floppybuttons[n][3]; - LRESULT val = SendDlgItemMessage (hDlg, f_type, CB_GETCURSEL, 0, 0L); + int f_type = floppybuttons[n][3]; + LRESULT val = SendDlgItemMessage (hDlg, f_type, CB_GETCURSEL, 0, 0L); - if (val != CB_ERR && workprefs.dfxtype[n] != val - 1) { - workprefs.dfxtype[n] = (int)val - 1; - addfloppytype (hDlg, n); - } + if (val != CB_ERR && workprefs.dfxtype[n] != val - 1) { + workprefs.dfxtype[n] = (int)val - 1; + addfloppytype (hDlg, n); + } } static void getfloppytypeq (HWND hDlg, int n) { - int f_enable = currentpage == QUICKSTART_ID ? floppybuttonsq[n][6] : floppybuttons[n][6]; - int chk; + int f_enable = currentpage == QUICKSTART_ID ? floppybuttonsq[n][6] : floppybuttons[n][6]; + int chk; - if (f_enable <= 0 || (n == 0 && currentpage == QUICKSTART_ID)) - return; - chk = IsDlgButtonChecked (hDlg, f_enable) ? 0 : -1; - if (chk != workprefs.dfxtype[n]) { - workprefs.dfxtype[n] = chk; - addfloppytype (hDlg, n); - } - if (currentpage == QUICKSTART_ID) { - if (chk == 0) - quickstart_floppy = 2; - else - quickstart_floppy = 1; - regsetint (NULL, L"QuickStartFloppies", quickstart_floppy); - } + if (f_enable <= 0 || (n == 0 && currentpage == QUICKSTART_ID)) + return; + chk = IsDlgButtonChecked (hDlg, f_enable) ? 0 : -1; + if (chk != workprefs.dfxtype[n]) { + workprefs.dfxtype[n] = chk; + addfloppytype (hDlg, n); + } + if (currentpage == QUICKSTART_ID) { + if (chk == 0) + quickstart_floppy = 2; + else + quickstart_floppy = 1; + regsetint (NULL, L"QuickStartFloppies", quickstart_floppy); + } } static int getfloppybox (HWND hDlg, int f_text, TCHAR *out, int maxlen) { - LRESULT val; - TCHAR *p1, *p2, *p; - TCHAR *tmp; - int i; - - out[0] = 0; - val = SendDlgItemMessage (hDlg, f_text, CB_GETCURSEL, 0, 0L); - if (val != CB_ERR) - val = SendDlgItemMessage (hDlg, f_text, CB_GETLBTEXT, (WPARAM)val, (LPARAM)out); - else - SendDlgItemMessage (hDlg, f_text, WM_GETTEXT, (WPARAM)maxlen, (LPARAM)out); - - tmp = xmalloc ((maxlen + 1) * sizeof (TCHAR)); - _tcscpy (tmp, out); - p1 = _tcsstr(tmp, L" { "); - p2 = _tcsstr(tmp, L" }"); - if (p1 && p2 && p2 > p1) { - *p1 = 0; - memset (out, 0, maxlen * sizeof (TCHAR)); - memcpy (out, p1 + 3, (p2 - p1 - 3) * sizeof (TCHAR)); - _tcscat (out, tmp); - } - xfree (tmp); - i = 0; - while ((p = DISK_history_get (i))) { - if (!_tcscmp (p, out)) { - DISK_history_add (out, -1, 0); - break; - } - i++; - } - return out[0] ? 1 : 0; + LRESULT val; + TCHAR *p1, *p2, *p; + TCHAR *tmp; + int i; + + out[0] = 0; + val = SendDlgItemMessage (hDlg, f_text, CB_GETCURSEL, 0, 0L); + if (val != CB_ERR) + val = SendDlgItemMessage (hDlg, f_text, CB_GETLBTEXT, (WPARAM)val, (LPARAM)out); + else + SendDlgItemMessage (hDlg, f_text, WM_GETTEXT, (WPARAM)maxlen, (LPARAM)out); + + tmp = xmalloc ((maxlen + 1) * sizeof (TCHAR)); + _tcscpy (tmp, out); + p1 = _tcsstr(tmp, L" { "); + p2 = _tcsstr(tmp, L" }"); + if (p1 && p2 && p2 > p1) { + *p1 = 0; + memset (out, 0, maxlen * sizeof (TCHAR)); + memcpy (out, p1 + 3, (p2 - p1 - 3) * sizeof (TCHAR)); + _tcscat (out, tmp); + } + xfree (tmp); + i = 0; + while ((p = DISK_history_get (i))) { + if (!_tcscmp (p, out)) { + DISK_history_add (out, -1, 0); + break; + } + i++; + } + return out[0] ? 1 : 0; } static void getfloppyname (HWND hDlg, int n) { - int f_text = currentpage == QUICKSTART_ID ? floppybuttonsq[n][0] : floppybuttons[n][0]; - TCHAR tmp[MAX_DPATH]; + int f_text = currentpage == QUICKSTART_ID ? floppybuttonsq[n][0] : floppybuttons[n][0]; + TCHAR tmp[MAX_DPATH]; - if (getfloppybox (hDlg, f_text, tmp, sizeof (tmp) / sizeof (TCHAR))) { - disk_insert (n, tmp); - _tcscpy (workprefs.df[n], tmp); - } + if (getfloppybox (hDlg, f_text, tmp, sizeof (tmp) / sizeof (TCHAR))) { + disk_insert (n, tmp); + _tcscpy (workprefs.df[n], tmp); + } } static void addallfloppies (HWND hDlg) { - int i; + int i; - for (i = 0; i < 4; i++) - addfloppytype (hDlg, i); - addfloppyhistory (hDlg); + for (i = 0; i < 4; i++) + addfloppytype (hDlg, i); + addfloppyhistory (hDlg); } static void floppysetwriteprotect (HWND hDlg, int n, int protect) { - disk_setwriteprotect (n, workprefs.df[n], protect); - addfloppytype (hDlg, n); + disk_setwriteprotect (n, workprefs.df[n], protect); + addfloppytype (hDlg, n); } static void deletesaveimage (HWND hDlg, int num) { - TCHAR *p = DISK_get_saveimagepath (workprefs.df[num]); - if (zfile_exists (p)) { - DeleteFile (p); - DISK_reinsert (num); - addfloppytype (hDlg, num); - } + TCHAR *p = DISK_get_saveimagepath (workprefs.df[num]); + if (zfile_exists (p)) { + DeleteFile (p); + DISK_reinsert (num); + addfloppytype (hDlg, num); + } } static void diskselect (HWND hDlg, WPARAM wParam, struct uae_prefs *p, int drv, TCHAR *defaultpath) { - MultiDiskSelection (hDlg, wParam, 0, &workprefs, defaultpath); - disk_insert (0, p->df[0]); - disk_insert (1, p->df[1]); - disk_insert (2, p->df[2]); - disk_insert (3, p->df[3]); - addfloppytype (hDlg, drv); - addfloppyhistory (hDlg); + MultiDiskSelection (hDlg, wParam, 0, &workprefs, defaultpath); + disk_insert (0, p->df[0]); + disk_insert (1, p->df[1]); + disk_insert (2, p->df[2]); + disk_insert (3, p->df[3]); + addfloppytype (hDlg, drv); + addfloppyhistory (hDlg); } static int diskselectmenu (HWND hDlg, WPARAM wParam) { - int id = GetDlgCtrlID ((HWND)wParam); - int num = -1; - switch (id) - { + int id = GetDlgCtrlID ((HWND)wParam); + int num = -1; + switch (id) + { case IDC_DF0: case IDC_DF0QQ: - num = 0; - break; + num = 0; + break; case IDC_DF1: case IDC_DF1QQ: - num = 1; - break; + num = 1; + break; case IDC_DF2: - num = 2; - break; + num = 2; + break; case IDC_DF3: - num = 3; - break; - } - if (num >= 0) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - int num = id == IDC_DF0QQ ? 0 : 1; - TCHAR tmp[MAX_DPATH]; - _tcscpy (tmp, s); - xfree (s); - diskselect (hDlg, id, &workprefs, num, tmp); + num = 3; + break; } - return 1; - } - return 0; + if (num >= 0) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + int num = id == IDC_DF0QQ ? 0 : 1; + TCHAR tmp[MAX_DPATH]; + _tcscpy (tmp, s); + xfree (s); + diskselect (hDlg, id, &workprefs, num, tmp); + } + return 1; + } + return 0; } static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - int i; - static TCHAR diskname[40] = { L"empty" }; + static int recursive = 0; + int i; + static TCHAR diskname[40] = { L"empty" }; - switch (msg) - { - case WM_INITDIALOG: + switch (msg) { - TCHAR ft35dd[20], ft35hd[20], ft35ddpc[20], ft35hdpc[20], ft525sd[20], ftdis[20], ft35ddescom[20]; - int df0texts[] = { IDC_DF0TEXT, IDC_DF1TEXT, IDC_DF2TEXT, IDC_DF3TEXT, -1 }; - - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DD, ft35dd, sizeof ft35dd / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35HD, ft35hd, sizeof ft35hd / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DDPC, ft35ddpc, sizeof ft35ddpc / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35HDPC, ft35hdpc, sizeof ft35hdpc / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE525SD, ft525sd, sizeof ft525sd / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DDESCOM, ft35ddescom, sizeof ft35ddescom / sizeof (TCHAR)); - WIN32GUI_LoadUIString (IDS_FLOPPYTYPEDISABLED, ftdis, sizeof ftdis / sizeof (TCHAR)); - pages[FLOPPY_ID] = hDlg; - if (workprefs.floppy_speed > 0 && workprefs.floppy_speed < 10) - workprefs.floppy_speed = 100; - currentpage = FLOPPY_ID; - SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETRANGE, TRUE, MAKELONG (0, 4)); - SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35dd); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35hd); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35ddpc); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35hdpc); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft525sd); - SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_SETCURSEL, 0, 0); - for (i = 0; i < 4; i++) { - int f_type = floppybuttons[i][3]; - SendDlgItemMessage (hDlg, f_type, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ftdis); - SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35dd); - SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35hd); - SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft525sd); - SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35ddescom); - } - setmultiautocomplete (hDlg, df0texts); - } + case WM_INITDIALOG: + { + TCHAR ft35dd[20], ft35hd[20], ft35ddpc[20], ft35hdpc[20], ft525sd[20], ftdis[20], ft35ddescom[20]; + int df0texts[] = { IDC_DF0TEXT, IDC_DF1TEXT, IDC_DF2TEXT, IDC_DF3TEXT, -1 }; + + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DD, ft35dd, sizeof ft35dd / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35HD, ft35hd, sizeof ft35hd / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DDPC, ft35ddpc, sizeof ft35ddpc / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35HDPC, ft35hdpc, sizeof ft35hdpc / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE525SD, ft525sd, sizeof ft525sd / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPE35DDESCOM, ft35ddescom, sizeof ft35ddescom / sizeof (TCHAR)); + WIN32GUI_LoadUIString (IDS_FLOPPYTYPEDISABLED, ftdis, sizeof ftdis / sizeof (TCHAR)); + pages[FLOPPY_ID] = hDlg; + if (workprefs.floppy_speed > 0 && workprefs.floppy_speed < 10) + workprefs.floppy_speed = 100; + currentpage = FLOPPY_ID; + SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETRANGE, TRUE, MAKELONG (0, 4)); + SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35dd); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35hd); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35ddpc); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft35hdpc); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_ADDSTRING, 0, (LPARAM)ft525sd); + SendDlgItemMessage (hDlg, IDC_FLOPPYTYPE, CB_SETCURSEL, 0, 0); + for (i = 0; i < 4; i++) { + int f_type = floppybuttons[i][3]; + SendDlgItemMessage (hDlg, f_type, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ftdis); + SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35dd); + SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35hd); + SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft525sd); + SendDlgItemMessage (hDlg, f_type, CB_ADDSTRING, 0, (LPARAM)ft35ddescom); + } + setmultiautocomplete (hDlg, df0texts); + } case WM_USER: - recursive++; - SetDlgItemText (hDlg, IDC_DF0TEXT, workprefs.df[0]); - SetDlgItemText (hDlg, IDC_DF1TEXT, workprefs.df[1]); - SetDlgItemText (hDlg, IDC_DF2TEXT, workprefs.df[2]); - SetDlgItemText (hDlg, IDC_DF3TEXT, workprefs.df[3]); - SetDlgItemText (hDlg, IDC_DF0TEXTQ, workprefs.df[0]); - SetDlgItemText (hDlg, IDC_DF1TEXTQ, workprefs.df[1]); - SetDlgItemText (hDlg, IDC_CREATE_NAME, diskname); - SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETPOS, TRUE, - workprefs.floppy_speed ? exact_log2 ((workprefs.floppy_speed) / 100) + 1 : 0); - out_floppyspeed (hDlg); - addallfloppies (hDlg); - recursive--; - break; + recursive++; + SetDlgItemText (hDlg, IDC_DF0TEXT, workprefs.df[0]); + SetDlgItemText (hDlg, IDC_DF1TEXT, workprefs.df[1]); + SetDlgItemText (hDlg, IDC_DF2TEXT, workprefs.df[2]); + SetDlgItemText (hDlg, IDC_DF3TEXT, workprefs.df[3]); + SetDlgItemText (hDlg, IDC_DF0TEXTQ, workprefs.df[0]); + SetDlgItemText (hDlg, IDC_DF1TEXTQ, workprefs.df[1]); + SetDlgItemText (hDlg, IDC_CREATE_NAME, diskname); + SendDlgItemMessage (hDlg, IDC_FLOPPYSPD, TBM_SETPOS, TRUE, + workprefs.floppy_speed ? exact_log2 ((workprefs.floppy_speed) / 100) + 1 : 0); + out_floppyspeed (hDlg); + addallfloppies (hDlg); + recursive--; + break; case WM_CONTEXTMENU: - diskselectmenu (hDlg, wParam); - break; + diskselectmenu (hDlg, wParam); + break; case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + if (recursive > 0) + break; + recursive++; + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + switch (LOWORD (wParam)) + { + case IDC_DF0TEXT: + case IDC_DF0TEXTQ: + getfloppyname (hDlg, 0); + addfloppytype (hDlg, 0); + addfloppyhistory (hDlg); + break; + case IDC_DF1TEXT: + case IDC_DF1TEXTQ: + getfloppyname (hDlg, 1); + addfloppytype (hDlg, 1); + addfloppyhistory (hDlg); + break; + case IDC_DF2TEXT: + getfloppyname (hDlg, 2); + addfloppytype (hDlg, 2); + addfloppyhistory (hDlg); + break; + case IDC_DF3TEXT: + getfloppyname (hDlg, 3); + addfloppytype (hDlg, 3); + addfloppyhistory (hDlg); + break; + case IDC_DF0TYPE: + getfloppytype (hDlg, 0); + break; + case IDC_DF1TYPE: + getfloppytype (hDlg, 1); + break; + case IDC_DF2TYPE: + getfloppytype (hDlg, 2); + break; + case IDC_DF3TYPE: + getfloppytype (hDlg, 3); + break; + } + } switch (LOWORD (wParam)) { - case IDC_DF0TEXT: - case IDC_DF0TEXTQ: - getfloppyname (hDlg, 0); - addfloppytype (hDlg, 0); - addfloppyhistory (hDlg); - break; - case IDC_DF1TEXT: - case IDC_DF1TEXTQ: - getfloppyname (hDlg, 1); - addfloppytype (hDlg, 1); - addfloppyhistory (hDlg); - break; - case IDC_DF2TEXT: - getfloppyname (hDlg, 2); - addfloppytype (hDlg, 2); - addfloppyhistory (hDlg); - break; - case IDC_DF3TEXT: - getfloppyname (hDlg, 3); - addfloppytype (hDlg, 3); - addfloppyhistory (hDlg); - break; - case IDC_DF0TYPE: - getfloppytype (hDlg, 0); - break; - case IDC_DF1TYPE: - getfloppytype (hDlg, 1); - break; - case IDC_DF2TYPE: - getfloppytype (hDlg, 2); - break; - case IDC_DF3TYPE: - getfloppytype (hDlg, 3); - break; - } - } - switch (LOWORD (wParam)) - { - case IDC_DF0ENABLE: - case IDC_DF0QENABLE: - getfloppytypeq (hDlg, 0); - break; - case IDC_DF1ENABLE: - case IDC_DF1QENABLE: - getfloppytypeq (hDlg, 1); - break; - case IDC_DF2ENABLE: - getfloppytypeq (hDlg, 2); - break; - case IDC_DF3ENABLE: - getfloppytypeq (hDlg, 3); - break; - case IDC_DF0WP: - case IDC_DF0WPQ: - floppysetwriteprotect (hDlg, 0, currentpage == QUICKSTART_ID ? IsDlgButtonChecked (hDlg, IDC_DF0WPQ) : IsDlgButtonChecked (hDlg, IDC_DF0WP)); - break; - case IDC_DF1WP: - case IDC_DF1WPQ: - floppysetwriteprotect (hDlg, 1, currentpage == QUICKSTART_ID ? IsDlgButtonChecked (hDlg, IDC_DF1WPQ) : IsDlgButtonChecked (hDlg, IDC_DF1WP)); - break; - case IDC_DF2WP: - floppysetwriteprotect (hDlg, 2, IsDlgButtonChecked (hDlg, IDC_DF2WP)); - break; - case IDC_DF3WP: - floppysetwriteprotect (hDlg, 3, IsDlgButtonChecked (hDlg, IDC_DF3WP)); - break; - case IDC_DF0: - case IDC_DF0QQ: - diskselect (hDlg, wParam, &workprefs, 0, NULL); - break; - case IDC_DF1: - case IDC_DF1QQ: - diskselect (hDlg, wParam, &workprefs, 1, NULL); - break; - case IDC_DF2: - diskselect (hDlg, wParam, &workprefs, 2, NULL); - break; - case IDC_DF3: - diskselect (hDlg, wParam, &workprefs, 3, NULL); - break; - case IDC_EJECT0: - case IDC_EJECT0Q: - SetDlgItemText (hDlg, IDC_DF0TEXT, L""); - SetDlgItemText (hDlg, IDC_DF0TEXTQ, L""); - workprefs.df[0][0] = 0; - addfloppytype (hDlg, 0); - break; - case IDC_EJECT1: - case IDC_EJECT1Q: - SetDlgItemText (hDlg, IDC_DF1TEXT, L""); - SetDlgItemText (hDlg, IDC_DF1TEXTQ, L""); - workprefs.df[1][0] = 0; - addfloppytype (hDlg, 1); - break; - case IDC_EJECT2: - SetDlgItemText (hDlg, IDC_DF2TEXT, L""); - workprefs.df[2][0] = 0; - addfloppytype (hDlg, 2); - break; - case IDC_EJECT3: - SetDlgItemText (hDlg, IDC_DF3TEXT, L""); - workprefs.df[3][0] = 0; - addfloppytype (hDlg, 3); - break; - case IDC_SAVEIMAGE0: - deletesaveimage (hDlg, 0); - break; - case IDC_SAVEIMAGE1: - deletesaveimage (hDlg, 1); - break; - case IDC_SAVEIMAGE2: - deletesaveimage (hDlg, 2); - break; - case IDC_SAVEIMAGE3: - deletesaveimage (hDlg, 3); - break; - case IDC_CREATE: - DiskSelection (hDlg, wParam, 1, &workprefs, 0); - addfloppyhistory (hDlg); - break; - case IDC_CREATE_RAW: - DiskSelection (hDlg, wParam, 1, &workprefs, 0); - addfloppyhistory (hDlg); - break; - } - recursive--; - break; + case IDC_DF0ENABLE: + case IDC_DF0QENABLE: + getfloppytypeq (hDlg, 0); + break; + case IDC_DF1ENABLE: + case IDC_DF1QENABLE: + getfloppytypeq (hDlg, 1); + break; + case IDC_DF2ENABLE: + getfloppytypeq (hDlg, 2); + break; + case IDC_DF3ENABLE: + getfloppytypeq (hDlg, 3); + break; + case IDC_DF0WP: + case IDC_DF0WPQ: + floppysetwriteprotect (hDlg, 0, currentpage == QUICKSTART_ID ? IsDlgButtonChecked (hDlg, IDC_DF0WPQ) : IsDlgButtonChecked (hDlg, IDC_DF0WP)); + break; + case IDC_DF1WP: + case IDC_DF1WPQ: + floppysetwriteprotect (hDlg, 1, currentpage == QUICKSTART_ID ? IsDlgButtonChecked (hDlg, IDC_DF1WPQ) : IsDlgButtonChecked (hDlg, IDC_DF1WP)); + break; + case IDC_DF2WP: + floppysetwriteprotect (hDlg, 2, IsDlgButtonChecked (hDlg, IDC_DF2WP)); + break; + case IDC_DF3WP: + floppysetwriteprotect (hDlg, 3, IsDlgButtonChecked (hDlg, IDC_DF3WP)); + break; + case IDC_DF0: + case IDC_DF0QQ: + diskselect (hDlg, wParam, &workprefs, 0, NULL); + break; + case IDC_DF1: + case IDC_DF1QQ: + diskselect (hDlg, wParam, &workprefs, 1, NULL); + break; + case IDC_DF2: + diskselect (hDlg, wParam, &workprefs, 2, NULL); + break; + case IDC_DF3: + diskselect (hDlg, wParam, &workprefs, 3, NULL); + break; + case IDC_EJECT0: + case IDC_EJECT0Q: + SetDlgItemText (hDlg, IDC_DF0TEXT, L""); + SetDlgItemText (hDlg, IDC_DF0TEXTQ, L""); + workprefs.df[0][0] = 0; + addfloppytype (hDlg, 0); + break; + case IDC_EJECT1: + case IDC_EJECT1Q: + SetDlgItemText (hDlg, IDC_DF1TEXT, L""); + SetDlgItemText (hDlg, IDC_DF1TEXTQ, L""); + workprefs.df[1][0] = 0; + addfloppytype (hDlg, 1); + break; + case IDC_EJECT2: + SetDlgItemText (hDlg, IDC_DF2TEXT, L""); + workprefs.df[2][0] = 0; + addfloppytype (hDlg, 2); + break; + case IDC_EJECT3: + SetDlgItemText (hDlg, IDC_DF3TEXT, L""); + workprefs.df[3][0] = 0; + addfloppytype (hDlg, 3); + break; + case IDC_SAVEIMAGE0: + deletesaveimage (hDlg, 0); + break; + case IDC_SAVEIMAGE1: + deletesaveimage (hDlg, 1); + break; + case IDC_SAVEIMAGE2: + deletesaveimage (hDlg, 2); + break; + case IDC_SAVEIMAGE3: + deletesaveimage (hDlg, 3); + break; + case IDC_CREATE: + DiskSelection (hDlg, wParam, 1, &workprefs, 0); + addfloppyhistory (hDlg); + break; + case IDC_CREATE_RAW: + DiskSelection (hDlg, wParam, 1, &workprefs, 0); + addfloppyhistory (hDlg); + break; + } + recursive--; + break; case WM_HSCROLL: - workprefs.floppy_speed = (int)SendMessage (GetDlgItem (hDlg, IDC_FLOPPYSPD), TBM_GETPOS, 0, 0); - if (workprefs.floppy_speed > 0) { - workprefs.floppy_speed--; - workprefs.floppy_speed = 1 << workprefs.floppy_speed; - workprefs.floppy_speed *= 100; - } - out_floppyspeed (hDlg); - break; - } + workprefs.floppy_speed = (int)SendMessage (GetDlgItem (hDlg, IDC_FLOPPYSPD), TBM_GETPOS, 0, 0); + if (workprefs.floppy_speed > 0) { + workprefs.floppy_speed--; + workprefs.floppy_speed = 1 << workprefs.floppy_speed; + workprefs.floppy_speed *= 100; + } + out_floppyspeed (hDlg); + break; + } - return FALSE; + return FALSE; } static ACCEL SwapperAccel[] = { - { FALT|FVIRTKEY, '1', 10001 }, { FALT|FVIRTKEY, '2', 10002 }, { FALT|FVIRTKEY, '3', 10003 }, { FALT|FVIRTKEY, '4', 10004 }, { FALT|FVIRTKEY, '5', 10005 }, - { FALT|FVIRTKEY, '6', 10006 }, { FALT|FVIRTKEY, '7', 10007 }, { FALT|FVIRTKEY, '8', 10008 }, { FALT|FVIRTKEY, '9', 10009 }, { FALT|FVIRTKEY, '0', 10010 }, - { FALT|FSHIFT|FVIRTKEY, '1', 10011 }, { FALT|FSHIFT|FVIRTKEY, '2', 10012 }, { FALT|FSHIFT|FVIRTKEY, '3', 10013 }, { FALT|FSHIFT|FVIRTKEY, '4', 10014 }, { FALT|FSHIFT|FVIRTKEY, '5', 10015 }, - { FALT|FSHIFT|FVIRTKEY, '6', 10016 }, { FALT|FSHIFT|FVIRTKEY, '7', 10017 }, { FALT|FSHIFT|FVIRTKEY, '8', 10018 }, { FALT|FSHIFT|FVIRTKEY, '9', 10019 }, { FALT|FSHIFT|FVIRTKEY, '0', 10020 }, - { FVIRTKEY, VK_UP, 10101 }, { FVIRTKEY, VK_DOWN, 10102 }, { FVIRTKEY, VK_RIGHT, 10104 }, - { FVIRTKEY|FSHIFT, VK_UP, IDC_UP }, { FVIRTKEY|FSHIFT, VK_DOWN, IDC_DOWN }, - { FVIRTKEY|FCONTROL, '1', 10201 }, { FVIRTKEY|FCONTROL, '2', 10202 }, { FVIRTKEY|FCONTROL, '3', 10203 }, { FVIRTKEY|FCONTROL, '4', 10204 }, - { FVIRTKEY|FCONTROL|FSHIFT, '1', 10205 }, { FVIRTKEY|FCONTROL|FSHIFT, '2', 10206 }, { FVIRTKEY|FCONTROL|FSHIFT, '3', 10207 }, { FVIRTKEY|FCONTROL|FSHIFT, '4', 10208 }, - { FVIRTKEY, VK_RETURN, 10209 }, { FVIRTKEY, VK_DELETE, IDC_DISKLISTREMOVE }, - { 0, 0, 0 } + { FALT|FVIRTKEY, '1', 10001 }, { FALT|FVIRTKEY, '2', 10002 }, { FALT|FVIRTKEY, '3', 10003 }, { FALT|FVIRTKEY, '4', 10004 }, { FALT|FVIRTKEY, '5', 10005 }, + { FALT|FVIRTKEY, '6', 10006 }, { FALT|FVIRTKEY, '7', 10007 }, { FALT|FVIRTKEY, '8', 10008 }, { FALT|FVIRTKEY, '9', 10009 }, { FALT|FVIRTKEY, '0', 10010 }, + { FALT|FSHIFT|FVIRTKEY, '1', 10011 }, { FALT|FSHIFT|FVIRTKEY, '2', 10012 }, { FALT|FSHIFT|FVIRTKEY, '3', 10013 }, { FALT|FSHIFT|FVIRTKEY, '4', 10014 }, { FALT|FSHIFT|FVIRTKEY, '5', 10015 }, + { FALT|FSHIFT|FVIRTKEY, '6', 10016 }, { FALT|FSHIFT|FVIRTKEY, '7', 10017 }, { FALT|FSHIFT|FVIRTKEY, '8', 10018 }, { FALT|FSHIFT|FVIRTKEY, '9', 10019 }, { FALT|FSHIFT|FVIRTKEY, '0', 10020 }, + { FVIRTKEY, VK_UP, 10101 }, { FVIRTKEY, VK_DOWN, 10102 }, { FVIRTKEY, VK_RIGHT, 10104 }, + { FVIRTKEY|FSHIFT, VK_UP, IDC_UP }, { FVIRTKEY|FSHIFT, VK_DOWN, IDC_DOWN }, + { FVIRTKEY|FCONTROL, '1', 10201 }, { FVIRTKEY|FCONTROL, '2', 10202 }, { FVIRTKEY|FCONTROL, '3', 10203 }, { FVIRTKEY|FCONTROL, '4', 10204 }, + { FVIRTKEY|FCONTROL|FSHIFT, '1', 10205 }, { FVIRTKEY|FCONTROL|FSHIFT, '2', 10206 }, { FVIRTKEY|FCONTROL|FSHIFT, '3', 10207 }, { FVIRTKEY|FCONTROL|FSHIFT, '4', 10208 }, + { FVIRTKEY, VK_RETURN, 10209 }, { FVIRTKEY, VK_DELETE, IDC_DISKLISTREMOVE }, + { 0, 0, 0 } }; static void swapperhili (HWND hDlg, int entry) { - ListView_SetItemState (cachedlist, entry, - LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - SetDlgItemText (hDlg, IDC_DISKTEXT, workprefs.dfxlist[entry]); + ListView_SetItemState (cachedlist, entry, + LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + SetDlgItemText (hDlg, IDC_DISKTEXT, workprefs.dfxlist[entry]); } static void addswapperfile (HWND hDlg, int entry, TCHAR *newpath) { - TCHAR path[MAX_DPATH]; - int lastentry = entry; + TCHAR path[MAX_DPATH]; + int lastentry = entry; - path[0] = 0; - if (newpath) - _tcscpy (path, newpath); - if (MultiDiskSelection (hDlg, -1, 0, &changed_prefs, path)) { - TCHAR dpath[MAX_DPATH]; - loopmulti (path, NULL); - while (loopmulti (path, dpath) && entry < MAX_SPARE_DRIVES) { - _tcscpy (workprefs.dfxlist[entry], dpath); - lastentry = entry; - entry++; + path[0] = 0; + if (newpath) + _tcscpy (path, newpath); + if (MultiDiskSelection (hDlg, -1, 0, &changed_prefs, path)) { + TCHAR dpath[MAX_DPATH]; + loopmulti (path, NULL); + while (loopmulti (path, dpath) && entry < MAX_SPARE_DRIVES) { + _tcscpy (workprefs.dfxlist[entry], dpath); + lastentry = entry; + entry++; + } + InitializeListView (hDlg); + swapperhili (hDlg, lastentry); } - InitializeListView (hDlg); - swapperhili (hDlg, lastentry); - } } static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - static int entry; - TCHAR tmp[MAX_DPATH]; + static int recursive = 0; + static int entry; + TCHAR tmp[MAX_DPATH]; - switch (msg) - { - case WM_INITDIALOG: - pages[DISK_ID] = hDlg; - currentpage = DISK_ID; - InitializeListView (hDlg); - addfloppyhistory (hDlg); - entry = 0; - swapperhili (hDlg, entry); - setautocomplete (hDlg, IDC_DISKTEXT); - break; - case WM_LBUTTONUP: - { - int *draggeditems; - int item = drag_end (hDlg, cachedlist, lParam, &draggeditems); - if (item >= 0) { - int i, item2; - entry = item; - for (i = 0; (item2 = draggeditems[i]) >= 0 && item2 < MAX_SPARE_DRIVES; i++, item++) { - if (item != item2) { - TCHAR tmp[1000]; - _tcscpy (tmp, workprefs.dfxlist[item]); - _tcscpy (workprefs.dfxlist[item], workprefs.dfxlist[item2]); - _tcscpy (workprefs.dfxlist[item2], tmp); - } - } - InitializeListView(hDlg); - swapperhili (hDlg, entry); - return TRUE; - } - xfree (draggeditems); - } - break; - case WM_MOUSEMOVE: - if (drag_move (hDlg, lParam)) - return TRUE; - break; - case WM_CONTEXTMENU: - if (GetDlgCtrlID ((HWND)wParam) == IDC_DISKLISTINSERT && entry >= 0) { - TCHAR *s = favoritepopup (hDlg); - if (s) { - addswapperfile (hDlg, entry, s); - xfree (s); - } - } - break; - case WM_COMMAND: - { - switch (LOWORD (wParam)) + switch (msg) { - case 10001: - case 10002: - case 10003: - case 10004: - case 10005: - case 10006: - case 10007: - case 10008: - case 10009: - case 10010: - case 10011: - case 10012: - case 10013: - case 10014: - case 10015: - case 10016: - case 10017: - case 10018: - case 10019: - case 10020: - entry = LOWORD (wParam) - 10001; - swapperhili (hDlg, entry); - break; - case 10101: - if (entry > 0) { - entry--; - swapperhili (hDlg, entry); - } - break; - case 10102: - if (entry >= 0 && entry < MAX_SPARE_DRIVES - 1) { - entry++; - swapperhili (hDlg, entry); - } - break; - case 10103: - case 10104: - disk_swap (entry, 1); - InitializeListView (hDlg); - swapperhili (hDlg, entry); - break; - case 10201: - case 10202: - case 10203: - case 10204: - { - int drv = LOWORD (wParam) - 10201; - int i; - if (workprefs.dfxtype[drv] >= 0 && entry >= 0) { - for (i = 0; i < 4; i++) { - if (!_tcscmp (workprefs.df[i], workprefs.dfxlist[entry])) - workprefs.df[i][0] = 0; - } - _tcscpy (workprefs.df[drv], workprefs.dfxlist[entry]); - disk_insert (drv, workprefs.df[drv]); - InitializeListView (hDlg); - swapperhili (hDlg, entry); - } - } - break; - case 10205: - case 10206: - case 10207: - case 10208: - { - int drv = LOWORD (wParam) - 10201; - workprefs.df[drv][0] = 0; + case WM_INITDIALOG: + pages[DISK_ID] = hDlg; + currentpage = DISK_ID; InitializeListView (hDlg); + addfloppyhistory (hDlg); + entry = 0; swapperhili (hDlg, entry); - } - break; - case 10209: - { - addswapperfile (hDlg, entry, NULL); - } - break; - - case IDC_DISKLISTINSERT: - if (entry >= 0) { - if (getfloppybox (hDlg, IDC_DISKTEXT, tmp, sizeof (tmp) / sizeof (TCHAR))) { - _tcscpy (workprefs.dfxlist[entry], tmp); - addfloppyhistory (hDlg); - InitializeListView (hDlg); - swapperhili (hDlg, entry); - } else { - addswapperfile (hDlg, entry, NULL); - } - } + setautocomplete (hDlg, IDC_DISKTEXT); break; - - case IDC_DISKLISTREMOVE: - if (entry >= 0) { - workprefs.dfxlist[entry][0] = 0; - InitializeListView (hDlg); - swapperhili (hDlg, entry); + case WM_LBUTTONUP: + { + int *draggeditems; + int item = drag_end (hDlg, cachedlist, lParam, &draggeditems); + if (item >= 0) { + int i, item2; + entry = item; + for (i = 0; (item2 = draggeditems[i]) >= 0 && item2 < MAX_SPARE_DRIVES; i++, item++) { + if (item != item2) { + TCHAR tmp[1000]; + _tcscpy (tmp, workprefs.dfxlist[item]); + _tcscpy (workprefs.dfxlist[item], workprefs.dfxlist[item2]); + _tcscpy (workprefs.dfxlist[item2], tmp); + } + } + InitializeListView(hDlg); + swapperhili (hDlg, entry); + return TRUE; + } + xfree (draggeditems); } break; - case IDC_UP: - if (entry > 0) { - _tcscpy (tmp, workprefs.dfxlist[entry - 1]); - _tcscpy (workprefs.dfxlist[entry - 1], workprefs.dfxlist[entry]); - _tcscpy (workprefs.dfxlist[entry], tmp); - InitializeListView (hDlg); - entry--; - swapperhili (hDlg, entry); - } + case WM_MOUSEMOVE: + if (drag_move (hDlg, lParam)) + return TRUE; break; - case IDC_DOWN: - if (entry >= 0 && entry < MAX_SPARE_DRIVES - 1) { - _tcscpy (tmp, workprefs.dfxlist[entry + 1]); - _tcscpy (workprefs.dfxlist[entry + 1], workprefs.dfxlist[entry]); - _tcscpy (workprefs.dfxlist[entry], tmp); - InitializeListView (hDlg); - entry++; - swapperhili (hDlg, entry); + case WM_CONTEXTMENU: + if (GetDlgCtrlID ((HWND)wParam) == IDC_DISKLISTINSERT && entry >= 0) { + TCHAR *s = favoritepopup (hDlg); + if (s) { + addswapperfile (hDlg, entry, s); + xfree (s); + } } break; - } - break; - } - case WM_NOTIFY: - if (((LPNMHDR) lParam)->idFrom == IDC_DISKLIST) - { - int dblclick = 0, button = 0, col; - HWND list; - NM_LISTVIEW *nmlistview; - nmlistview = (NM_LISTVIEW *) lParam; - cachedlist = list = nmlistview->hdr.hwndFrom; - switch (nmlistview->hdr.code) - { - case LVN_BEGINDRAG: - drag_start (hDlg, cachedlist, lParam); - break; - case NM_RDBLCLK: - case NM_DBLCLK: - dblclick = 1; - /* fall-through here too */ - case NM_RCLICK: - if (nmlistview->hdr.code == NM_RCLICK || nmlistview->hdr.code == NM_RDBLCLK) - button = 2; - case NM_CLICK: - entry = listview_entry_from_click (list, &col); - if (entry >= 0) { - if (col == 2) { - if (button) { - if (!dblclick) { - if (disk_swap (entry, -1)) - InitializeListView (hDlg); - swapperhili (hDlg, entry); - } - } else { - if (!dblclick) { - if (disk_swap (entry, 0)) - InitializeListView (hDlg); + case WM_COMMAND: + { + switch (LOWORD (wParam)) + { + case 10001: + case 10002: + case 10003: + case 10004: + case 10005: + case 10006: + case 10007: + case 10008: + case 10009: + case 10010: + case 10011: + case 10012: + case 10013: + case 10014: + case 10015: + case 10016: + case 10017: + case 10018: + case 10019: + case 10020: + entry = LOWORD (wParam) - 10001; swapperhili (hDlg, entry); - } - } - } else if (col == 1) { - if (dblclick) { - if (!button) { - addswapperfile (hDlg, entry, NULL); - } else { - workprefs.dfxlist[entry][0] = 0; + break; + case 10101: + if (entry > 0) { + entry--; + swapperhili (hDlg, entry); + } + break; + case 10102: + if (entry >= 0 && entry < MAX_SPARE_DRIVES - 1) { + entry++; + swapperhili (hDlg, entry); + } + break; + case 10103: + case 10104: + disk_swap (entry, 1); InitializeListView (hDlg); - } - } - } - SetDlgItemText (hDlg, IDC_DISKTEXT, workprefs.dfxlist[entry]); - } - break; - } - } - } - return FALSE; -} + swapperhili (hDlg, entry); + break; + case 10201: + case 10202: + case 10203: + case 10204: + { + int drv = LOWORD (wParam) - 10201; + int i; + if (workprefs.dfxtype[drv] >= 0 && entry >= 0) { + for (i = 0; i < 4; i++) { + if (!_tcscmp (workprefs.df[i], workprefs.dfxlist[entry])) + workprefs.df[i][0] = 0; + } + _tcscpy (workprefs.df[drv], workprefs.dfxlist[entry]); + disk_insert (drv, workprefs.df[drv]); + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } + } + break; + case 10205: + case 10206: + case 10207: + case 10208: + { + int drv = LOWORD (wParam) - 10201; + workprefs.df[drv][0] = 0; + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } + break; + case 10209: + { + addswapperfile (hDlg, entry, NULL); + } + break; -static PRINTER_INFO_1 *pInfo = NULL; -static DWORD dwEnumeratedPrinters = 0; -#define MAX_PRINTERS 10 -struct serialportinfo comports[MAX_SERIAL_PORTS]; + case IDC_DISKLISTINSERT: + if (entry >= 0) { + if (getfloppybox (hDlg, IDC_DISKTEXT, tmp, sizeof (tmp) / sizeof (TCHAR))) { + _tcscpy (workprefs.dfxlist[entry], tmp); + addfloppyhistory (hDlg); + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } else { + addswapperfile (hDlg, entry, NULL); + } + } + break; + + case IDC_DISKLISTREMOVE: + if (entry >= 0) { + workprefs.dfxlist[entry][0] = 0; + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } + break; + case IDC_UP: + if (entry > 0) { + _tcscpy (tmp, workprefs.dfxlist[entry - 1]); + _tcscpy (workprefs.dfxlist[entry - 1], workprefs.dfxlist[entry]); + _tcscpy (workprefs.dfxlist[entry], tmp); + InitializeListView (hDlg); + entry--; + swapperhili (hDlg, entry); + } + break; + case IDC_DOWN: + if (entry >= 0 && entry < MAX_SPARE_DRIVES - 1) { + _tcscpy (tmp, workprefs.dfxlist[entry + 1]); + _tcscpy (workprefs.dfxlist[entry + 1], workprefs.dfxlist[entry]); + _tcscpy (workprefs.dfxlist[entry], tmp); + InitializeListView (hDlg); + entry++; + swapperhili (hDlg, entry); + } + break; + } + break; + } + case WM_NOTIFY: + if (((LPNMHDR) lParam)->idFrom == IDC_DISKLIST) + { + int dblclick = 0, button = 0, col; + HWND list; + NM_LISTVIEW *nmlistview; + nmlistview = (NM_LISTVIEW *) lParam; + cachedlist = list = nmlistview->hdr.hwndFrom; + switch (nmlistview->hdr.code) + { + case LVN_BEGINDRAG: + drag_start (hDlg, cachedlist, lParam); + break; + case NM_RDBLCLK: + case NM_DBLCLK: + dblclick = 1; + /* fall-through here too */ + case NM_RCLICK: + if (nmlistview->hdr.code == NM_RCLICK || nmlistview->hdr.code == NM_RDBLCLK) + button = 2; + case NM_CLICK: + entry = listview_entry_from_click (list, &col); + if (entry >= 0) { + if (col == 2) { + if (button) { + if (!dblclick) { + if (disk_swap (entry, -1)) + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } + } else { + if (!dblclick) { + if (disk_swap (entry, 0)) + InitializeListView (hDlg); + swapperhili (hDlg, entry); + } + } + } else if (col == 1) { + if (dblclick) { + if (!button) { + addswapperfile (hDlg, entry, NULL); + } else { + workprefs.dfxlist[entry][0] = 0; + InitializeListView (hDlg); + } + } + } + SetDlgItemText (hDlg, IDC_DISKTEXT, workprefs.dfxlist[entry]); + } + break; + } + } + } + return FALSE; +} + +static PRINTER_INFO_1 *pInfo = NULL; +static DWORD dwEnumeratedPrinters = 0; +#define MAX_PRINTERS 10 +struct serialportinfo comports[MAX_SERIAL_PORTS]; static int ghostscript_available; static int joyxprevious[4]; @@ -9313,44 +9325,44 @@ static BOOL bNoMidiIn = FALSE; static void enable_for_gameportsdlg (HWND hDlg) { - int v = full_property_sheet; - ew (hDlg, IDC_PORT_TABLET_FULL, v && is_tablet () && workprefs.input_tablet > 0); - ew (hDlg, IDC_PORT_TABLET_CURSOR, v && workprefs.input_tablet > 0); - ew (hDlg, IDC_PORT_TABLET, v); + int v = full_property_sheet; + ew (hDlg, IDC_PORT_TABLET_FULL, v && is_tablet () && workprefs.input_tablet > 0); + ew (hDlg, IDC_PORT_TABLET_CURSOR, v && workprefs.input_tablet > 0); + ew (hDlg, IDC_PORT_TABLET, v); } static void enable_for_portsdlg (HWND hDlg) { - int v; + int v; - v = workprefs.input_selected_setting > 0 ? FALSE : TRUE; - ew (hDlg, IDC_SWAP, v); + v = workprefs.input_selected_setting > 0 ? FALSE : TRUE; + ew (hDlg, IDC_SWAP, v); #if !defined (SERIAL_PORT) - ew (hDlg, IDC_MIDIOUTLIST, FALSE); - ew (hDlg, IDC_MIDIINLIST, FALSE); - ew (hDlg, IDC_SHARED, FALSE); - ew (hDlg, IDC_SER_CTSRTS, FALSE); - ew (hDlg, IDC_SERIAL_DIRECT, FALSE); - ew (hDlg, IDC_SERIAL, FALSE); - ew (hDlg, IDC_UAESERIAL, FALSE); + ew (hDlg, IDC_MIDIOUTLIST, FALSE); + ew (hDlg, IDC_MIDIINLIST, FALSE); + ew (hDlg, IDC_SHARED, FALSE); + ew (hDlg, IDC_SER_CTSRTS, FALSE); + ew (hDlg, IDC_SERIAL_DIRECT, FALSE); + ew (hDlg, IDC_SERIAL, FALSE); + ew (hDlg, IDC_UAESERIAL, FALSE); #else - v = workprefs.use_serial ? TRUE : FALSE; - ew (hDlg, IDC_SER_SHARED, v); - ew (hDlg, IDC_SER_CTSRTS, v); - ew (hDlg, IDC_SER_DIRECT, v); - ew (hDlg, IDC_UAESERIAL, full_property_sheet); + v = workprefs.use_serial ? TRUE : FALSE; + ew (hDlg, IDC_SER_SHARED, v); + ew (hDlg, IDC_SER_CTSRTS, v); + ew (hDlg, IDC_SER_DIRECT, v); + ew (hDlg, IDC_UAESERIAL, full_property_sheet); #endif #if !defined (PARALLEL_PORT) - ew (hDlg, IDC_PRINTERLIST, FALSE); - ew (hDlg, IDC_FLUSHPRINTER, FALSE); - ew (hDlg, IDC_PSPRINTER, FALSE); - ew (hDlg, IDC_PS_PARAMS, FALSE); - ew (hDlg, IDC_PRINTER_AUTOFLUSH, FALSE); + ew (hDlg, IDC_PRINTERLIST, FALSE); + ew (hDlg, IDC_FLUSHPRINTER, FALSE); + ew (hDlg, IDC_PSPRINTER, FALSE); + ew (hDlg, IDC_PS_PARAMS, FALSE); + ew (hDlg, IDC_PRINTER_AUTOFLUSH, FALSE); #else - ew (hDlg, IDC_FLUSHPRINTER, isprinteropen () ? TRUE : FALSE); - ew (hDlg, IDC_PSPRINTER, full_property_sheet && ghostscript_available ? TRUE : FALSE); - ew (hDlg, IDC_PSPRINTERDETECT, full_property_sheet ? TRUE : FALSE); - ew (hDlg, IDC_PS_PARAMS, full_property_sheet && ghostscript_available); + ew (hDlg, IDC_FLUSHPRINTER, isprinteropen () ? TRUE : FALSE); + ew (hDlg, IDC_PSPRINTER, full_property_sheet && ghostscript_available ? TRUE : FALSE); + ew (hDlg, IDC_PSPRINTERDETECT, full_property_sheet ? TRUE : FALSE); + ew (hDlg, IDC_PS_PARAMS, full_property_sheet && ghostscript_available); #endif } @@ -9359,1069 +9371,1069 @@ static int joysm[] = { IDC_PORT0_JOYSMODE, IDC_PORT1_JOYSMODE, -1, -1 }; static void updatejoyport (HWND hDlg) { - int i, j; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - - SetDlgItemInt (hDlg, IDC_INPUTSPEEDM, workprefs.input_mouse_speed, FALSE); - CheckDlgButton (hDlg, IDC_PORT_MOUSETRICK, workprefs.input_magic_mouse); - SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_SETCURSEL, workprefs.input_magic_mouse_cursor, 0); - CheckDlgButton (hDlg, IDC_PORT_TABLET, workprefs.input_tablet > 0); - CheckDlgButton (hDlg, IDC_PORT_TABLET_FULL, workprefs.input_tablet == TABLET_REAL); - - if (joyxprevious[0] < 0) - joyxprevious[0] = inputdevice_get_device_total (IDTYPE_JOYSTICK) + 1; - if (joyxprevious[1] < 0) - joyxprevious[1] = JSEM_LASTKBD + 1; - - for (i = 0; i < MAX_JPORTS; i++) { - int total = 2; - int idx = joyxprevious[i]; - int id = joys[i]; - int idm = joysm[i]; - int v = workprefs.jports[i].id; - int vm = workprefs.jports[i].mode; - TCHAR *p1, *p2; + int i, j; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - if (idm > 0) - SendDlgItemMessage (hDlg, idm, CB_SETCURSEL, vm, 0); - - SendDlgItemMessage (hDlg, id, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)L""); - WIN32GUI_LoadUIString (IDS_NONE, tmp, sizeof (tmp) / sizeof (TCHAR) - 3); - _stprintf (tmp2, L"<%s>", tmp); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp2); - WIN32GUI_LoadUIString (IDS_KEYJOY, tmp, sizeof (tmp) / sizeof (TCHAR)); - _tcscat (tmp, L"\n"); - p1 = tmp; - for (;;) { - p2 = _tcschr (p1, '\n'); - if (p2 && _tcslen (p2) > 0) { - *p2++ = 0; - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)p1); - total++; - p1 = p2; - } else - break; - } - for (j = 0; j < inputdevice_get_device_total (IDTYPE_JOYSTICK); j++, total++) - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name(IDTYPE_JOYSTICK, j)); - if (i < 2) { - for (j = 0; j < inputdevice_get_device_total (IDTYPE_MOUSE); j++, total++) - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name(IDTYPE_MOUSE, j)); + SetDlgItemInt (hDlg, IDC_INPUTSPEEDM, workprefs.input_mouse_speed, FALSE); + CheckDlgButton (hDlg, IDC_PORT_MOUSETRICK, workprefs.input_magic_mouse); + SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_SETCURSEL, workprefs.input_magic_mouse_cursor, 0); + CheckDlgButton (hDlg, IDC_PORT_TABLET, workprefs.input_tablet > 0); + CheckDlgButton (hDlg, IDC_PORT_TABLET_FULL, workprefs.input_tablet == TABLET_REAL); + + if (joyxprevious[0] < 0) + joyxprevious[0] = inputdevice_get_device_total (IDTYPE_JOYSTICK) + 1; + if (joyxprevious[1] < 0) + joyxprevious[1] = JSEM_LASTKBD + 1; + + for (i = 0; i < MAX_JPORTS; i++) { + int total = 2; + int idx = joyxprevious[i]; + int id = joys[i]; + int idm = joysm[i]; + int v = workprefs.jports[i].id; + int vm = workprefs.jports[i].mode; + TCHAR *p1, *p2; + + if (idm > 0) + SendDlgItemMessage (hDlg, idm, CB_SETCURSEL, vm, 0); + + SendDlgItemMessage (hDlg, id, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)L""); + WIN32GUI_LoadUIString (IDS_NONE, tmp, sizeof (tmp) / sizeof (TCHAR) - 3); + _stprintf (tmp2, L"<%s>", tmp); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp2); + WIN32GUI_LoadUIString (IDS_KEYJOY, tmp, sizeof (tmp) / sizeof (TCHAR)); + _tcscat (tmp, L"\n"); + p1 = tmp; + for (;;) { + p2 = _tcschr (p1, '\n'); + if (p2 && _tcslen (p2) > 0) { + *p2++ = 0; + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)p1); + total++; + p1 = p2; + } else + break; + } + for (j = 0; j < inputdevice_get_device_total (IDTYPE_JOYSTICK); j++, total++) + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name(IDTYPE_JOYSTICK, j)); + if (i < 2) { + for (j = 0; j < inputdevice_get_device_total (IDTYPE_MOUSE); j++, total++) + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name(IDTYPE_MOUSE, j)); + } + idx = inputdevice_getjoyportdevice (v); + if (idx >= 0) + idx += 2; + else + idx = 1; + if (idx >= total) + idx = 0; + SendDlgItemMessage (hDlg, id, CB_SETCURSEL, idx, 0); } - idx = inputdevice_getjoyportdevice (v); - if (idx >= 0) - idx += 2; - else - idx = 1; - if (idx >= total) - idx = 0; - SendDlgItemMessage (hDlg, id, CB_SETCURSEL, idx, 0); - } } static void fixjport (struct jport *port, int v) { - int vv = port->id; - if (vv != v) - return; - if (vv >= JSEM_JOYS && vv < JSEM_MICE) { - vv -= JSEM_JOYS; - vv++; - if (vv >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) - vv = 0; - vv += JSEM_JOYS; - } - if (vv >= JSEM_MICE && vv < JSEM_END) { - vv -= JSEM_MICE; - vv++; - if (vv >= inputdevice_get_device_total (IDTYPE_MOUSE)) - vv = 0; - vv += JSEM_MICE; - } - if (vv >= JSEM_KBDLAYOUT && vv < JSEM_LASTKBD) { - vv -= JSEM_KBDLAYOUT; - vv++; - if (vv >= JSEM_LASTKBD) - vv = 0; - vv += JSEM_KBDLAYOUT; - } - port->id = vv; + int vv = port->id; + if (vv != v) + return; + if (vv >= JSEM_JOYS && vv < JSEM_MICE) { + vv -= JSEM_JOYS; + vv++; + if (vv >= inputdevice_get_device_total (IDTYPE_JOYSTICK)) + vv = 0; + vv += JSEM_JOYS; + } + if (vv >= JSEM_MICE && vv < JSEM_END) { + vv -= JSEM_MICE; + vv++; + if (vv >= inputdevice_get_device_total (IDTYPE_MOUSE)) + vv = 0; + vv += JSEM_MICE; + } + if (vv >= JSEM_KBDLAYOUT && vv < JSEM_LASTKBD) { + vv -= JSEM_KBDLAYOUT; + vv++; + if (vv >= JSEM_LASTKBD) + vv = 0; + vv += JSEM_KBDLAYOUT; + } + port->id = vv; } static void values_from_gameportsdlg (HWND hDlg, int d) { - int i, j, success; - int changed = 0; + int i, j, success; + int changed = 0; + + if (d) { + i = GetDlgItemInt (hDlg, IDC_INPUTSPEEDM, &success, FALSE); + if (success) + currprefs.input_mouse_speed = workprefs.input_mouse_speed = i; + + currprefs.input_magic_mouse = workprefs.input_magic_mouse = IsDlgButtonChecked (hDlg, IDC_PORT_MOUSETRICK) ? -1 : 0; + workprefs.input_magic_mouse_cursor = SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_GETCURSEL, 0, 0L); + workprefs.input_tablet = 0; + if (IsDlgButtonChecked (hDlg, IDC_PORT_TABLET)) { + workprefs.input_tablet = TABLET_MOUSEHACK; + if (IsDlgButtonChecked (hDlg, IDC_PORT_TABLET_FULL)) + workprefs.input_tablet = TABLET_REAL; + } + return; + } - if (d) { - i = GetDlgItemInt (hDlg, IDC_INPUTSPEEDM, &success, FALSE); - if (success) - currprefs.input_mouse_speed = workprefs.input_mouse_speed = i; - - currprefs.input_magic_mouse = workprefs.input_magic_mouse = IsDlgButtonChecked (hDlg, IDC_PORT_MOUSETRICK) ? -1 : 0; - workprefs.input_magic_mouse_cursor = SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_GETCURSEL, 0, 0L); - workprefs.input_tablet = 0; - if (IsDlgButtonChecked (hDlg, IDC_PORT_TABLET)) { - workprefs.input_tablet = TABLET_MOUSEHACK; - if (IsDlgButtonChecked (hDlg, IDC_PORT_TABLET_FULL)) - workprefs.input_tablet = TABLET_REAL; - } - return; - } - - for (i = 0; i < MAX_JPORTS; i++) { - int idx = 0; - int *port = &workprefs.jports[i].id; - int *portm = &workprefs.jports[i].mode; - int prevport = *port; - int id = joys[i]; - int idm = joysm[i]; - LRESULT v = SendDlgItemMessage (hDlg, id, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR && v > 0) { - v -= 2; - if (v < 0) - *port = -1; - else if (v < JSEM_LASTKBD) - *port = JSEM_KBDLAYOUT + (int)v; - else if (v >= JSEM_LASTKBD + inputdevice_get_device_total (IDTYPE_JOYSTICK)) - *port = JSEM_MICE + (int)v - inputdevice_get_device_total (IDTYPE_JOYSTICK) - JSEM_LASTKBD; - else - *port = JSEM_JOYS + (int)v - JSEM_LASTKBD; - } - v = SendDlgItemMessage (hDlg, idm, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR && v > 0) - *portm = v; - if (*port != prevport) - changed = 1; - } - if (changed) { for (i = 0; i < MAX_JPORTS; i++) { - for (j = 0; j < MAX_JPORTS; j++) { - if (j != i) - fixjport (&workprefs.jports[i], workprefs.jports[j].id); - } + int idx = 0; + int *port = &workprefs.jports[i].id; + int *portm = &workprefs.jports[i].mode; + int prevport = *port; + int id = joys[i]; + int idm = joysm[i]; + LRESULT v = SendDlgItemMessage (hDlg, id, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR && v > 0) { + v -= 2; + if (v < 0) + *port = -1; + else if (v < JSEM_LASTKBD) + *port = JSEM_KBDLAYOUT + (int)v; + else if (v >= JSEM_LASTKBD + inputdevice_get_device_total (IDTYPE_JOYSTICK)) + *port = JSEM_MICE + (int)v - inputdevice_get_device_total (IDTYPE_JOYSTICK) - JSEM_LASTKBD; + else + *port = JSEM_JOYS + (int)v - JSEM_LASTKBD; + } + v = SendDlgItemMessage (hDlg, idm, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR && v > 0) + *portm = v; + if (*port != prevport) + changed = 1; + } + if (changed) { + for (i = 0; i < MAX_JPORTS; i++) { + for (j = 0; j < MAX_JPORTS; j++) { + if (j != i) + fixjport (&workprefs.jports[i], workprefs.jports[j].id); + } + } } - } - + } static void values_from_portsdlg (HWND hDlg) { - int v; - TCHAR tmp[256]; - BOOL success; - LRESULT item; - - item = SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_GETCURSEL, 0, 0L); - if(item != CB_ERR) { - int got = 0; - _tcscpy (tmp, workprefs.prtname); - if (item > 0) { - item--; - if (item < dwEnumeratedPrinters) { - _tcscpy (workprefs.prtname, pInfo[item].pName); - got = 1; - } else { - int i; - item -= dwEnumeratedPrinters; - for (i = 0; i < 4; i++) { - if ((paraport_mask & (1 << i)) && item == 0) { - _stprintf (workprefs.prtname, L"LPT%d", i + 1); - got = 1; - break; - } - item--; + int v; + TCHAR tmp[256]; + BOOL success; + LRESULT item; + + item = SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_GETCURSEL, 0, 0L); + if(item != CB_ERR) { + int got = 0; + _tcscpy (tmp, workprefs.prtname); + if (item > 0) { + item--; + if (item < dwEnumeratedPrinters) { + _tcscpy (workprefs.prtname, pInfo[item].pName); + got = 1; + } else { + int i; + item -= dwEnumeratedPrinters; + for (i = 0; i < 4; i++) { + if ((paraport_mask & (1 << i)) && item == 0) { + _stprintf (workprefs.prtname, L"LPT%d", i + 1); + got = 1; + break; + } + item--; + } + } } - } - } - if (!got) - workprefs.prtname[0] = 0; + if (!got) + workprefs.prtname[0] = 0; #ifdef PARALLEL_PORT - if (_tcscmp (workprefs.prtname, tmp)) - closeprinter (); + if (_tcscmp (workprefs.prtname, tmp)) + closeprinter (); #endif - } - - workprefs.win32_midioutdev = SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_GETCURSEL, 0, 0); - workprefs.win32_midioutdev -= 2; - - if( bNoMidiIn) { - workprefs.win32_midiindev = -1; - } else { - workprefs.win32_midiindev = SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_GETCURSEL, 0, 0); - } - ew (hDlg, IDC_MIDIINLIST, workprefs.win32_midioutdev < -1 ? FALSE : TRUE); - - item = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR && item > 0) { - workprefs.use_serial = 1; - _tcscpy (workprefs.sername, comports[item - 1].dev); - } else { - workprefs.use_serial = 0; - workprefs.sername[0] = 0; - } - workprefs.serial_demand = 0; - if (IsDlgButtonChecked (hDlg, IDC_SER_SHARED)) - workprefs.serial_demand = 1; - workprefs.serial_hwctsrts = 0; - if (IsDlgButtonChecked (hDlg, IDC_SER_CTSRTS)) - workprefs.serial_hwctsrts = 1; - workprefs.serial_direct = 0; - if (IsDlgButtonChecked (hDlg, IDC_SER_DIRECT)) - workprefs.serial_direct = 1; - - workprefs.uaeserial = 0; - if (IsDlgButtonChecked (hDlg, IDC_UAESERIAL)) - workprefs.uaeserial = 1; - - GetDlgItemText (hDlg, IDC_PS_PARAMS, workprefs.ghostscript_parameters, sizeof workprefs.ghostscript_parameters / sizeof (TCHAR)); - v = GetDlgItemInt (hDlg, IDC_PRINTERAUTOFLUSH, &success, FALSE); - if (success) - workprefs.parallel_autoflush_time = v; - - item = SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR) - workprefs.dongle = item; + } + + workprefs.win32_midioutdev = SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_GETCURSEL, 0, 0); + workprefs.win32_midioutdev -= 2; + + if( bNoMidiIn) { + workprefs.win32_midiindev = -1; + } else { + workprefs.win32_midiindev = SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_GETCURSEL, 0, 0); + } + ew (hDlg, IDC_MIDIINLIST, workprefs.win32_midioutdev < -1 ? FALSE : TRUE); + + item = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR && item > 0) { + workprefs.use_serial = 1; + _tcscpy (workprefs.sername, comports[item - 1].dev); + } else { + workprefs.use_serial = 0; + workprefs.sername[0] = 0; + } + workprefs.serial_demand = 0; + if (IsDlgButtonChecked (hDlg, IDC_SER_SHARED)) + workprefs.serial_demand = 1; + workprefs.serial_hwctsrts = 0; + if (IsDlgButtonChecked (hDlg, IDC_SER_CTSRTS)) + workprefs.serial_hwctsrts = 1; + workprefs.serial_direct = 0; + if (IsDlgButtonChecked (hDlg, IDC_SER_DIRECT)) + workprefs.serial_direct = 1; + + workprefs.uaeserial = 0; + if (IsDlgButtonChecked (hDlg, IDC_UAESERIAL)) + workprefs.uaeserial = 1; + + GetDlgItemText (hDlg, IDC_PS_PARAMS, workprefs.ghostscript_parameters, sizeof workprefs.ghostscript_parameters / sizeof (TCHAR)); + v = GetDlgItemInt (hDlg, IDC_PRINTERAUTOFLUSH, &success, FALSE); + if (success) + workprefs.parallel_autoflush_time = v; + + item = SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR) + workprefs.dongle = item; } static void values_to_portsdlg (HWND hDlg) { - LRESULT result = 0; - int idx; + LRESULT result = 0; + int idx; - if(workprefs.prtname[0]) { - int i, got = 1; - TCHAR tmp[10]; - result = SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_FINDSTRINGEXACT, -1, (LPARAM)workprefs.prtname); - for (i = 0; i < 4; i++) { - _stprintf (tmp, L"LPT%d", i + 1); - if (!_tcscmp (tmp, workprefs.prtname)) { - got = 0; - if (paraport_mask & (1 << i)) - got = 1; - break; - } - } - if(result < 0 || got == 0) { - // Warn the user that their printer-port selection is not valid on this machine - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_INVALIDPRTPORT, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - // Disable the invalid parallel-port selection - workprefs.prtname[0] = 0; - result = 0; - } - } - SetDlgItemInt (hDlg, IDC_PRINTERAUTOFLUSH, workprefs.parallel_autoflush_time, FALSE); - idx = workprefs.parallel_matrix_emulation; - if (workprefs.parallel_postscript_detection) - idx = 4; - if (workprefs.parallel_postscript_emulation) - idx = 5; - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_SETCURSEL, idx, 0); - - SetDlgItemText (hDlg, IDC_PS_PARAMS, workprefs.ghostscript_parameters); - - SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_SETCURSEL, result, 0); - SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_SETCURSEL, workprefs.win32_midioutdev + 2, 0); - if (!bNoMidiIn && workprefs.win32_midiindev >= 0) - SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_SETCURSEL, workprefs.win32_midiindev, 0); - else - SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_SETCURSEL, 0, 0); - ew (hDlg, IDC_MIDIINLIST, workprefs.win32_midioutdev < -1 ? FALSE : TRUE); - - CheckDlgButton (hDlg, IDC_UAESERIAL, workprefs.uaeserial); - CheckDlgButton (hDlg, IDC_SER_SHARED, workprefs.serial_demand); - CheckDlgButton (hDlg, IDC_SER_CTSRTS, workprefs.serial_hwctsrts); - CheckDlgButton (hDlg, IDC_SER_DIRECT, workprefs.serial_direct); - - if(!workprefs.sername[0]) { - SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0, 0L); - workprefs.use_serial = 0; - } else { - int i; - LRESULT result = -1; - for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { - if (!_tcscmp (comports[i].dev, workprefs.sername)) { - result = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, i + 1, 0L); - break; - } - } - if(result < 0 && workprefs.sername[0]) { - // Warn the user that their COM-port selection is not valid on this machine - TCHAR szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_INVALIDCOMPORT, szMessage, MAX_DPATH); - pre_gui_message (szMessage); - // Select "none" as the COM-port - SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0L, 0L); - // Disable the chosen serial-port selection - workprefs.sername[0] = 0; - workprefs.use_serial = 0; + if(workprefs.prtname[0]) { + int i, got = 1; + TCHAR tmp[10]; + result = SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_FINDSTRINGEXACT, -1, (LPARAM)workprefs.prtname); + for (i = 0; i < 4; i++) { + _stprintf (tmp, L"LPT%d", i + 1); + if (!_tcscmp (tmp, workprefs.prtname)) { + got = 0; + if (paraport_mask & (1 << i)) + got = 1; + break; + } + } + if(result < 0 || got == 0) { + // Warn the user that their printer-port selection is not valid on this machine + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_INVALIDPRTPORT, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + // Disable the invalid parallel-port selection + workprefs.prtname[0] = 0; + result = 0; + } + } + SetDlgItemInt (hDlg, IDC_PRINTERAUTOFLUSH, workprefs.parallel_autoflush_time, FALSE); + idx = workprefs.parallel_matrix_emulation; + if (workprefs.parallel_postscript_detection) + idx = 4; + if (workprefs.parallel_postscript_emulation) + idx = 5; + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_SETCURSEL, idx, 0); + + SetDlgItemText (hDlg, IDC_PS_PARAMS, workprefs.ghostscript_parameters); + + SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_SETCURSEL, result, 0); + SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_SETCURSEL, workprefs.win32_midioutdev + 2, 0); + if (!bNoMidiIn && workprefs.win32_midiindev >= 0) + SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_SETCURSEL, workprefs.win32_midiindev, 0); + else + SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_SETCURSEL, 0, 0); + ew (hDlg, IDC_MIDIINLIST, workprefs.win32_midioutdev < -1 ? FALSE : TRUE); + + CheckDlgButton (hDlg, IDC_UAESERIAL, workprefs.uaeserial); + CheckDlgButton (hDlg, IDC_SER_SHARED, workprefs.serial_demand); + CheckDlgButton (hDlg, IDC_SER_CTSRTS, workprefs.serial_hwctsrts); + CheckDlgButton (hDlg, IDC_SER_DIRECT, workprefs.serial_direct); + + if(!workprefs.sername[0]) { + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0, 0L); + workprefs.use_serial = 0; } else { - workprefs.use_serial = 1; + int i; + LRESULT result = -1; + for (i = 0; i < MAX_SERIAL_PORTS && comports[i].name; i++) { + if (!_tcscmp (comports[i].dev, workprefs.sername)) { + result = SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, i + 1, 0L); + break; + } + } + if(result < 0 && workprefs.sername[0]) { + // Warn the user that their COM-port selection is not valid on this machine + TCHAR szMessage[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_INVALIDCOMPORT, szMessage, MAX_DPATH); + pre_gui_message (szMessage); + // Select "none" as the COM-port + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0L, 0L); + // Disable the chosen serial-port selection + workprefs.sername[0] = 0; + workprefs.use_serial = 0; + } else { + workprefs.use_serial = 1; + } } - } - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_SETCURSEL, workprefs.dongle, 0L); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_SETCURSEL, workprefs.dongle, 0L); } static void init_portsdlg (HWND hDlg) { - static int first; - int port, numdevs; - MIDIOUTCAPS midiOutCaps; - MIDIINCAPS midiInCaps; - TCHAR tmp[MAX_DPATH]; - - if (!first) { - first = 1; - if (load_ghostscript () > 0) { - unload_ghostscript (); - ghostscript_available = 1; - } - } - if (!ghostscript_available) { - workprefs.parallel_postscript_emulation = 0; - } - - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)szNone); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Robocop 3"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Leaderboard"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"B.A.T. II"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Italy'90 Soccer"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Dames Grand Maitre"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Rugby Coach"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Cricket Captain"); - SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Leviathan"); - - SendDlgItemMessage (hDlg, IDC_SERIAL, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)szNone); - for (port = 0; port < MAX_SERIAL_PORTS && comports[port].name; port++) { - SendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)comports[port].name); - } - - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_PRINTER_PASSTHROUGH, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_ASCII, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_EPSON9, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_EPSON48, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_DETECTION, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_EMULATION, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - - SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)szNone); - if(!pInfo) { - int flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS; - DWORD needed = 0; - EnumPrinters (flags, NULL, 1, (LPBYTE)pInfo, 0, &needed, &dwEnumeratedPrinters); - if (needed > 0) { - DWORD size = needed; - pInfo = xcalloc (1, size); - dwEnumeratedPrinters = 0; - EnumPrinters (flags, NULL, 1, (LPBYTE)pInfo, size, &needed, &dwEnumeratedPrinters); - } - if (dwEnumeratedPrinters == 0) { - xfree (pInfo); - pInfo = 0; - } - } - if (pInfo) { - for(port = 0; port < (int)dwEnumeratedPrinters; port++) - SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)pInfo[port].pName); - } else { - ew (hDlg, IDC_PRINTERLIST, FALSE); - } - if (paraport_mask) { - int mask = paraport_mask; - int i = 1; - while (mask) { - if (mask & 1) { - TCHAR tmp[30]; - _stprintf (tmp, L"LPT%d", i); - SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)tmp); - } - i++; - mask >>= 1; - } - } - - SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)szNone); - if ((numdevs = midiOutGetNumDevs ()) == 0) { - ew (hDlg, IDC_MIDIOUTLIST, FALSE); - } else { - TCHAR szMidiOut[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_DEFAULTMIDIOUT, szMidiOut, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)szMidiOut); + static int first; + int port, numdevs; + MIDIOUTCAPS midiOutCaps; + MIDIINCAPS midiInCaps; + TCHAR tmp[MAX_DPATH]; + + if (!first) { + first = 1; + if (load_ghostscript () > 0) { + unload_ghostscript (); + ghostscript_available = 1; + } + } + if (!ghostscript_available) { + workprefs.parallel_postscript_emulation = 0; + } + + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)szNone); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Robocop 3"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Leaderboard"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"B.A.T. II"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Italy'90 Soccer"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Dames Grand Maitre"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Rugby Coach"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Cricket Captain"); + SendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)L"Leviathan"); + + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)szNone); + for (port = 0; port < MAX_SERIAL_PORTS && comports[port].name; port++) { + SendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)comports[port].name); + } + + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_PRINTER_PASSTHROUGH, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_PRINTER_ASCII, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_PRINTER_EPSON9, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_PRINTER_EPSON48, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_DETECTION, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_EMULATION, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + + SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)szNone); + if(!pInfo) { + int flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS; + DWORD needed = 0; + EnumPrinters (flags, NULL, 1, (LPBYTE)pInfo, 0, &needed, &dwEnumeratedPrinters); + if (needed > 0) { + DWORD size = needed; + pInfo = xcalloc (1, size); + dwEnumeratedPrinters = 0; + EnumPrinters (flags, NULL, 1, (LPBYTE)pInfo, size, &needed, &dwEnumeratedPrinters); + } + if (dwEnumeratedPrinters == 0) { + xfree (pInfo); + pInfo = 0; + } + } + if (pInfo) { + for(port = 0; port < (int)dwEnumeratedPrinters; port++) + SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)pInfo[port].pName); + } else { + ew (hDlg, IDC_PRINTERLIST, FALSE); + } + if (paraport_mask) { + int mask = paraport_mask; + int i = 1; + while (mask) { + if (mask & 1) { + TCHAR tmp[30]; + _stprintf (tmp, L"LPT%d", i); + SendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)tmp); + } + i++; + mask >>= 1; + } + } - for(port = 0; port < numdevs; port++) { - if (midiOutGetDevCaps (port, &midiOutCaps, sizeof (midiOutCaps)) == MMSYSERR_NOERROR) - SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)midiOutCaps.szPname); + SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)szNone); + if ((numdevs = midiOutGetNumDevs ()) == 0) { + ew (hDlg, IDC_MIDIOUTLIST, FALSE); + } else { + TCHAR szMidiOut[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_DEFAULTMIDIOUT, szMidiOut, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)szMidiOut); + + for(port = 0; port < numdevs; port++) { + if (midiOutGetDevCaps (port, &midiOutCaps, sizeof (midiOutCaps)) == MMSYSERR_NOERROR) + SendDlgItemMessage (hDlg, IDC_MIDIOUTLIST, CB_ADDSTRING, 0, (LPARAM)midiOutCaps.szPname); + } + ew (hDlg, IDC_MIDIOUTLIST, TRUE); } - ew (hDlg, IDC_MIDIOUTLIST, TRUE); - } - SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_RESETCONTENT, 0, 0L); - if ((numdevs = midiInGetNumDevs ()) == 0) { - ew (hDlg, IDC_MIDIINLIST, FALSE); - bNoMidiIn = TRUE; - } else { - for(port = 0; port < numdevs; port++) { - if (midiInGetDevCaps (port, &midiInCaps, sizeof (midiInCaps)) == MMSYSERR_NOERROR) - SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_ADDSTRING, 0, (LPARAM)midiInCaps.szPname); + SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_RESETCONTENT, 0, 0L); + if ((numdevs = midiInGetNumDevs ()) == 0) { + ew (hDlg, IDC_MIDIINLIST, FALSE); + bNoMidiIn = TRUE; + } else { + for(port = 0; port < numdevs; port++) { + if (midiInGetDevCaps (port, &midiInCaps, sizeof (midiInCaps)) == MMSYSERR_NOERROR) + SendDlgItemMessage (hDlg, IDC_MIDIINLIST, CB_ADDSTRING, 0, (LPARAM)midiInCaps.szPname); + } } - } } /* Handle messages for the Joystick Settings page of our property-sheet */ static INT_PTR CALLBACK GamePortsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - TCHAR tmp[MAX_DPATH]; - static int recursive = 0; - static int first; - int temp, i; + TCHAR tmp[MAX_DPATH]; + static int recursive = 0; + static int first; + int temp, i; - switch (msg) - { - case WM_INITDIALOG: - recursive++; - pages[GAMEPORTS_ID] = hDlg; - currentpage = GAMEPORTS_ID; - - if (!first) { - first = 1; - joyxprevious[0] = -1; - joyxprevious[1] = -1; - joyxprevious[2] = -1; - joyxprevious[3] = -1; - } - - SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_TABLET_BOTH_CURSORS, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_TABLET_NATIVE_CURSOR, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_TABLET_HOST_CURSOR, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); - - for (i = 0; i < 2; i++) { - int id = i == 0 ? IDC_PORT0_JOYSMODE : IDC_PORT1_JOYSMODE; - SendDlgItemMessage (hDlg, id, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_JOYMODE_DEFAULT, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_MOUSE, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICK, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICKANALOG, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_MOUSE_CDTV, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICK_CD32, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_JOYMODE_LIGHTPEN, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); - } + switch (msg) + { + case WM_INITDIALOG: + recursive++; + pages[GAMEPORTS_ID] = hDlg; + currentpage = GAMEPORTS_ID; + + if (!first) { + first = 1; + joyxprevious[0] = -1; + joyxprevious[1] = -1; + joyxprevious[2] = -1; + joyxprevious[3] = -1; + } - inputdevice_updateconfig (&workprefs); - enable_for_gameportsdlg (hDlg); - updatejoyport (hDlg); - recursive--; - break; - case WM_USER: - recursive++; - enable_for_gameportsdlg (hDlg); - updatejoyport (hDlg); - recursive--; - return TRUE; + SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_TABLET_BOTH_CURSORS, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_TABLET_NATIVE_CURSOR, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_TABLET_HOST_CURSOR, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_PORT_TABLET_CURSOR, CB_ADDSTRING, 0, (LPARAM)tmp); + + for (i = 0; i < 2; i++) { + int id = i == 0 ? IDC_PORT0_JOYSMODE : IDC_PORT1_JOYSMODE; + SendDlgItemMessage (hDlg, id, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_JOYMODE_DEFAULT, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_MOUSE, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICK, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICKANALOG, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_MOUSE_CDTV, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_JOYSTICK_CD32, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_JOYMODE_LIGHTPEN, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, id, CB_ADDSTRING, 0, (LPARAM)tmp); + } - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (LOWORD (wParam) == IDC_SWAP) { - struct jport tmp; - memcpy (&tmp, &workprefs.jports[0], sizeof (struct jport)); - memcpy (&workprefs.jports[0], &workprefs.jports[1], sizeof (struct jport)); - memcpy (&workprefs.jports[1], &tmp, sizeof (struct jport)); - temp = joyxprevious[0]; - joyxprevious[0] = joyxprevious[1]; - joyxprevious[1] = temp; - enable_for_gameportsdlg (hDlg); - updatejoyport (hDlg); - inputdevice_updateconfig (&workprefs); - inputdevice_config_change (); - } else if (HIWORD (wParam) == CBN_SELCHANGE) { - switch (LOWORD (wParam)) - { - case IDC_PORT0_JOYS: - case IDC_PORT1_JOYS: - case IDC_PORT2_JOYS: - case IDC_PORT3_JOYS: - case IDC_PORT0_JOYSMODE: - case IDC_PORT1_JOYSMODE: - values_from_gameportsdlg (hDlg, 0); - enable_for_gameportsdlg (hDlg); - updatejoyport (hDlg); - inputdevice_updateconfig (&workprefs); - inputdevice_config_change (); - break; - } - } else { - values_from_gameportsdlg (hDlg, 1); - enable_for_gameportsdlg (hDlg); + inputdevice_updateconfig (&workprefs); + enable_for_gameportsdlg (hDlg); + updatejoyport (hDlg); + recursive--; + break; + case WM_USER: + recursive++; + enable_for_gameportsdlg (hDlg); + updatejoyport (hDlg); + recursive--; + return TRUE; + + case WM_COMMAND: + if (recursive > 0) + break; + recursive++; + if (LOWORD (wParam) == IDC_SWAP) { + struct jport tmp; + memcpy (&tmp, &workprefs.jports[0], sizeof (struct jport)); + memcpy (&workprefs.jports[0], &workprefs.jports[1], sizeof (struct jport)); + memcpy (&workprefs.jports[1], &tmp, sizeof (struct jport)); + temp = joyxprevious[0]; + joyxprevious[0] = joyxprevious[1]; + joyxprevious[1] = temp; + enable_for_gameportsdlg (hDlg); + updatejoyport (hDlg); + inputdevice_updateconfig (&workprefs); + inputdevice_config_change (); + } else if (HIWORD (wParam) == CBN_SELCHANGE) { + switch (LOWORD (wParam)) + { + case IDC_PORT0_JOYS: + case IDC_PORT1_JOYS: + case IDC_PORT2_JOYS: + case IDC_PORT3_JOYS: + case IDC_PORT0_JOYSMODE: + case IDC_PORT1_JOYSMODE: + values_from_gameportsdlg (hDlg, 0); + enable_for_gameportsdlg (hDlg); + updatejoyport (hDlg); + inputdevice_updateconfig (&workprefs); + inputdevice_config_change (); + break; + } + } else { + values_from_gameportsdlg (hDlg, 1); + enable_for_gameportsdlg (hDlg); + } + recursive--; + break; } - recursive--; - break; - } - return FALSE; + return FALSE; } /* Handle messages for the IO Settings page of our property-sheet */ static INT_PTR CALLBACK IOPortsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; + static int recursive = 0; - switch (msg) - { - case WM_INITDIALOG: - recursive++; - pages[IOPORTS_ID] = hDlg; - currentpage = IOPORTS_ID; - init_portsdlg (hDlg); - inputdevice_updateconfig (&workprefs); - enable_for_portsdlg (hDlg); - values_to_portsdlg (hDlg); - recursive--; - break; - case WM_USER: - recursive++; - enable_for_portsdlg (hDlg); - recursive--; - return TRUE; + switch (msg) + { + case WM_INITDIALOG: + recursive++; + pages[IOPORTS_ID] = hDlg; + currentpage = IOPORTS_ID; + init_portsdlg (hDlg); + inputdevice_updateconfig (&workprefs); + enable_for_portsdlg (hDlg); + values_to_portsdlg (hDlg); + recursive--; + break; + case WM_USER: + recursive++; + enable_for_portsdlg (hDlg); + recursive--; + return TRUE; - case WM_COMMAND: - if (recursive > 0) - break; - recursive++; - if (wParam == IDC_FLUSHPRINTER) { - if (isprinter ()) { - closeprinter (); - } - } else if (wParam == IDC_UAESERIAL || wParam == IDC_SER_SHARED || wParam == IDC_SER_DIRECT || wParam == IDC_SER_CTSRTS || wParam == IDC_PRINTERAUTOFLUSH) { - values_from_portsdlg (hDlg); - } else { - if (HIWORD (wParam) == CBN_SELCHANGE) { - switch (LOWORD (wParam)) - { - case IDC_PRINTERLIST: - case IDC_SERIAL: - case IDC_MIDIOUTLIST: - case IDC_MIDIINLIST: - case IDC_DONGLELIST: - values_from_portsdlg (hDlg); - inputdevice_updateconfig (&workprefs); - inputdevice_config_change (); - break; - case IDC_PRINTERTYPELIST: - { - int item = SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_GETCURSEL, 0, 0L); - workprefs.parallel_postscript_detection = workprefs.parallel_postscript_emulation = workprefs.parallel_matrix_emulation = 0; - switch (item) - { - case 1: - workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_TEXT; - break; - case 2: - workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_EPSON9; - break; - case 3: - workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_EPSON48; - break; - case 4: - workprefs.parallel_postscript_detection = 1; - break; - case 5: - workprefs.parallel_postscript_detection = 1; - workprefs.parallel_postscript_emulation = 1; + case WM_COMMAND: + if (recursive > 0) break; + recursive++; + if (wParam == IDC_FLUSHPRINTER) { + if (isprinter ()) { + closeprinter (); + } + } else if (wParam == IDC_UAESERIAL || wParam == IDC_SER_SHARED || wParam == IDC_SER_DIRECT || wParam == IDC_SER_CTSRTS || wParam == IDC_PRINTERAUTOFLUSH) { + values_from_portsdlg (hDlg); + } else { + if (HIWORD (wParam) == CBN_SELCHANGE) { + switch (LOWORD (wParam)) + { + case IDC_PRINTERLIST: + case IDC_SERIAL: + case IDC_MIDIOUTLIST: + case IDC_MIDIINLIST: + case IDC_DONGLELIST: + values_from_portsdlg (hDlg); + inputdevice_updateconfig (&workprefs); + inputdevice_config_change (); + break; + case IDC_PRINTERTYPELIST: + { + int item = SendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_GETCURSEL, 0, 0L); + workprefs.parallel_postscript_detection = workprefs.parallel_postscript_emulation = workprefs.parallel_matrix_emulation = 0; + switch (item) + { + case 1: + workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_TEXT; + break; + case 2: + workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_EPSON9; + break; + case 3: + workprefs.parallel_matrix_emulation = PARALLEL_MATRIX_EPSON48; + break; + case 4: + workprefs.parallel_postscript_detection = 1; + break; + case 5: + workprefs.parallel_postscript_detection = 1; + workprefs.parallel_postscript_emulation = 1; + break; + } + } + } } - } } - } + recursive--; + break; } - recursive--; - break; - } - return FALSE; + return FALSE; } static TCHAR *eventnames[INPUTEVENT_END]; static void values_to_inputdlg (HWND hDlg) { - SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_SETCURSEL, workprefs.input_selected_setting, 0); - SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_SETCURSEL, input_selected_device, 0); - SetDlgItemInt (hDlg, IDC_INPUTDEADZONE, workprefs.input_joystick_deadzone, FALSE); - SetDlgItemInt (hDlg, IDC_INPUTAUTOFIRERATE, workprefs.input_autofire_framecnt, FALSE); - SetDlgItemInt (hDlg, IDC_INPUTSPEEDD, workprefs.input_joymouse_speed, FALSE); - SetDlgItemInt (hDlg, IDC_INPUTSPEEDA, workprefs.input_joymouse_multiplier, FALSE); - CheckDlgButton (hDlg, IDC_INPUTDEVICEDISABLE, (!input_total_devices || inputdevice_get_device_status (input_selected_device)) ? BST_CHECKED : BST_UNCHECKED); + SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_SETCURSEL, workprefs.input_selected_setting, 0); + SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_SETCURSEL, input_selected_device, 0); + SetDlgItemInt (hDlg, IDC_INPUTDEADZONE, workprefs.input_joystick_deadzone, FALSE); + SetDlgItemInt (hDlg, IDC_INPUTAUTOFIRERATE, workprefs.input_autofire_framecnt, FALSE); + SetDlgItemInt (hDlg, IDC_INPUTSPEEDD, workprefs.input_joymouse_speed, FALSE); + SetDlgItemInt (hDlg, IDC_INPUTSPEEDA, workprefs.input_joymouse_multiplier, FALSE); + CheckDlgButton (hDlg, IDC_INPUTDEVICEDISABLE, (!input_total_devices || inputdevice_get_device_status (input_selected_device)) ? BST_CHECKED : BST_UNCHECKED); } static int stringboxdialogactive; static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch(msg) + { case WM_DESTROY: - PostQuitMessage (0); - return TRUE; + PostQuitMessage (0); + return TRUE; case WM_CLOSE: - stringboxdialogactive = 0; - DestroyWindow (hDlg); - return TRUE; + stringboxdialogactive = 0; + DestroyWindow (hDlg); + return TRUE; case WM_INITDIALOG: - return TRUE; + return TRUE; case WM_COMMAND: - switch (LOWORD (wParam)) - { + switch (LOWORD (wParam)) + { case IDOK: - stringboxdialogactive = -1; - DestroyWindow (hDlg); - return TRUE; + stringboxdialogactive = -1; + DestroyWindow (hDlg); + return TRUE; case IDCANCEL: - stringboxdialogactive = 0; - DestroyWindow (hDlg); - return TRUE; - } - break; - } - return FALSE; + stringboxdialogactive = 0; + DestroyWindow (hDlg); + return TRUE; + } + break; + } + return FALSE; } static int askinputcustom (HWND hDlg, TCHAR *custom, int maxlen, DWORD titleid) { - HWND hwnd; - TCHAR txt[MAX_DPATH]; + HWND hwnd; + TCHAR txt[MAX_DPATH]; - stringboxdialogactive = 1; - hwnd = CustomCreateDialog (IDD_STRINGBOX, hDlg, StringBoxDialogProc); - if (hwnd == NULL) - return 0; - if (titleid != 0) { - LoadString (hUIDLL, titleid, txt, MAX_DPATH); - SetWindowText (hwnd, txt); - } - txt[0] = 0; - SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_SETTEXT, 0, (LPARAM)custom); - SetFocus (GetDlgItem (hwnd, IDC_STRINGBOXEDIT)); - while (stringboxdialogactive == 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_STRINGBOXEDIT), WM_GETTEXT, sizeof txt / sizeof (TCHAR), (LPARAM)txt); + stringboxdialogactive = 1; + hwnd = CustomCreateDialog (IDD_STRINGBOX, hDlg, StringBoxDialogProc); + if (hwnd == NULL) + return 0; + if (titleid != 0) { + LoadString (hUIDLL, titleid, txt, MAX_DPATH); + SetWindowText (hwnd, txt); } - if (stringboxdialogactive == -1) { - _tcscpy (custom, txt); - return 1; + txt[0] = 0; + SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_SETTEXT, 0, (LPARAM)custom); + SetFocus (GetDlgItem (hwnd, IDC_STRINGBOXEDIT)); + while (stringboxdialogactive == 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_STRINGBOXEDIT), WM_GETTEXT, sizeof txt / sizeof (TCHAR), (LPARAM)txt); + } + if (stringboxdialogactive == -1) { + _tcscpy (custom, txt); + return 1; + } } - } - return 0; + return 0; } static void init_inputdlg_2(HWND hDlg) { - TCHAR name1[256], name2[256]; - TCHAR custom1[MAX_DPATH], tmp1[MAX_DPATH]; - int cnt, index, af, aftmp; - - if (input_selected_widget < 0 || workprefs.input_selected_setting == 0) { - EnableWindow (GetDlgItem (hDlg, IDC_INPUTAMIGA), FALSE); - } else { - EnableWindow (GetDlgItem (hDlg, IDC_INPUTAMIGA), TRUE); - } - SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)szNone); - WIN32GUI_LoadUIString (IDS_INPUT_CUSTOMEVENT, tmp1, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)tmp1); - index = 0; af = 0; - if (input_selected_widget >= 0) { - inputdevice_get_mapped_name (input_selected_device, input_selected_widget, 0, name1, custom1, input_selected_sub_num); - cnt = 2; - while(inputdevice_iterate (input_selected_device, input_selected_widget, name2, &aftmp)) { - free (eventnames[cnt]); - eventnames[cnt] = my_strdup (name2); - if (name1 && !_tcscmp (name1, name2)) { - index = cnt; - af = aftmp; - } - cnt++; - SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)name2); - } - if (_tcslen (custom1) > 0) - index = 1; - if (index >= 0) { - SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_SETCURSEL, index, 0); - SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); + TCHAR name1[256], name2[256]; + TCHAR custom1[MAX_DPATH], tmp1[MAX_DPATH]; + int cnt, index, af, aftmp; + + if (input_selected_widget < 0 || workprefs.input_selected_setting == 0) { + EnableWindow (GetDlgItem (hDlg, IDC_INPUTAMIGA), FALSE); + } else { + EnableWindow (GetDlgItem (hDlg, IDC_INPUTAMIGA), TRUE); + } + SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)szNone); + WIN32GUI_LoadUIString (IDS_INPUT_CUSTOMEVENT, tmp1, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)tmp1); + index = 0; af = 0; + if (input_selected_widget >= 0) { + inputdevice_get_mapped_name (input_selected_device, input_selected_widget, 0, name1, custom1, input_selected_sub_num); + cnt = 2; + while(inputdevice_iterate (input_selected_device, input_selected_widget, name2, &aftmp)) { + free (eventnames[cnt]); + eventnames[cnt] = my_strdup (name2); + if (name1 && !_tcscmp (name1, name2)) { + index = cnt; + af = aftmp; + } + cnt++; + SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_ADDSTRING, 0, (LPARAM)name2); + } + if (_tcslen (custom1) > 0) + index = 1; + if (index >= 0) { + SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_SETCURSEL, index, 0); + SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); + } } - } } static void init_inputdlg (HWND hDlg) { - int i; - TCHAR buf[100], txt[100]; - - SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_INPUT_COMPATIBILITY, buf, sizeof (buf) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_ADDSTRING, 0, (LPARAM)buf); - WIN32GUI_LoadUIString (IDS_INPUT_CUSTOM, buf, sizeof (buf) / sizeof (TCHAR)); - for (i = 0; i < 4; i++) { - _stprintf (txt, buf, i + 1); - SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_ADDSTRING, 0, (LPARAM)txt); - } - - SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_INPUT_COPY_DEFAULT, buf, sizeof (buf) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_ADDSTRING, 0, (LPARAM)buf); - WIN32GUI_LoadUIString (IDS_INPUT_COPY_CUSTOM, buf, sizeof (buf) / sizeof (TCHAR)); - for (i = 0; i < 4; i++) { - _stprintf (txt, buf, i + 1); - SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_ADDSTRING, 0, (LPARAM)txt); - } - - SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_RESETCONTENT, 0, 0L); - for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { - _stprintf (buf, L"%d", i + 1); - SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_ADDSTRING, 0, (LPARAM)buf); - } - SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); - - SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_RESETCONTENT, 0, 0L); - for (i = 0; i < inputdevice_get_device_total (IDTYPE_JOYSTICK); i++) { - SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_JOYSTICK, i)); - } - for (i = 0; i < inputdevice_get_device_total (IDTYPE_MOUSE); i++) { - SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_MOUSE, i)); - } - for (i = 0; i < inputdevice_get_device_total (IDTYPE_KEYBOARD); i++) { - SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_KEYBOARD, i)); - } - input_total_devices = inputdevice_get_device_total (IDTYPE_JOYSTICK) + - inputdevice_get_device_total (IDTYPE_MOUSE) + - inputdevice_get_device_total (IDTYPE_KEYBOARD); - if (input_selected_device >= input_total_devices) - input_selected_device = 0; - InitializeListView (hDlg); - init_inputdlg_2 (hDlg); - values_to_inputdlg (hDlg); + int i; + TCHAR buf[100], txt[100]; + + SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_INPUT_COMPATIBILITY, buf, sizeof (buf) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_ADDSTRING, 0, (LPARAM)buf); + WIN32GUI_LoadUIString (IDS_INPUT_CUSTOM, buf, sizeof (buf) / sizeof (TCHAR)); + for (i = 0; i < 4; i++) { + _stprintf (txt, buf, i + 1); + SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_ADDSTRING, 0, (LPARAM)txt); + } + + SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_INPUT_COPY_DEFAULT, buf, sizeof (buf) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_ADDSTRING, 0, (LPARAM)buf); + WIN32GUI_LoadUIString (IDS_INPUT_COPY_CUSTOM, buf, sizeof (buf) / sizeof (TCHAR)); + for (i = 0; i < 4; i++) { + _stprintf (txt, buf, i + 1); + SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_ADDSTRING, 0, (LPARAM)txt); + } + + SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_RESETCONTENT, 0, 0L); + for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) { + _stprintf (buf, L"%d", i + 1); + SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_ADDSTRING, 0, (LPARAM)buf); + } + SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); + + SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_RESETCONTENT, 0, 0L); + for (i = 0; i < inputdevice_get_device_total (IDTYPE_JOYSTICK); i++) { + SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_JOYSTICK, i)); + } + for (i = 0; i < inputdevice_get_device_total (IDTYPE_MOUSE); i++) { + SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_MOUSE, i)); + } + for (i = 0; i < inputdevice_get_device_total (IDTYPE_KEYBOARD); i++) { + SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_ADDSTRING, 0, (LPARAM)inputdevice_get_device_name (IDTYPE_KEYBOARD, i)); + } + input_total_devices = inputdevice_get_device_total (IDTYPE_JOYSTICK) + + inputdevice_get_device_total (IDTYPE_MOUSE) + + inputdevice_get_device_total (IDTYPE_KEYBOARD); + if (input_selected_device >= input_total_devices) + input_selected_device = 0; + InitializeListView (hDlg); + init_inputdlg_2 (hDlg); + values_to_inputdlg (hDlg); } static void enable_for_inputdlg (HWND hDlg) { - int v = workprefs.input_selected_setting == 0 ? FALSE : TRUE; - ew (hDlg, IDC_INPUTLIST, TRUE); - ew (hDlg, IDC_INPUTAMIGA, v); - ew (hDlg, IDC_INPUTAMIGACNT, TRUE); - ew (hDlg, IDC_INPUTDEADZONE, TRUE); - ew (hDlg, IDC_INPUTAUTOFIRERATE, v); - ew (hDlg, IDC_INPUTSPEEDA, v); - ew (hDlg, IDC_INPUTSPEEDD, v); - ew (hDlg, IDC_INPUTCOPY, v); - ew (hDlg, IDC_INPUTCOPYFROM, v); - ew (hDlg, IDC_INPUTSWAP, v); - ew (hDlg, IDC_INPUTDEVICEDISABLE, v); + int v = workprefs.input_selected_setting == 0 ? FALSE : TRUE; + ew (hDlg, IDC_INPUTLIST, TRUE); + ew (hDlg, IDC_INPUTAMIGA, v); + ew (hDlg, IDC_INPUTAMIGACNT, TRUE); + ew (hDlg, IDC_INPUTDEADZONE, TRUE); + ew (hDlg, IDC_INPUTAUTOFIRERATE, v); + ew (hDlg, IDC_INPUTSPEEDA, v); + ew (hDlg, IDC_INPUTSPEEDD, v); + ew (hDlg, IDC_INPUTCOPY, v); + ew (hDlg, IDC_INPUTCOPYFROM, v); + ew (hDlg, IDC_INPUTSWAP, v); + ew (hDlg, IDC_INPUTDEVICEDISABLE, v); } static void clearinputlistview (HWND hDlg) { - ListView_DeleteAllItems (GetDlgItem (hDlg, IDC_INPUTLIST)); + ListView_DeleteAllItems (GetDlgItem (hDlg, IDC_INPUTLIST)); } static void doinputcustom (HWND hDlg, int newcustom) { - TCHAR custom1[MAX_DPATH]; - int flags; - custom1[0] = 0; - inputdevice_get_mapped_name (input_selected_device, input_selected_widget, - &flags, 0, custom1, input_selected_sub_num); - if (_tcslen (custom1) > 0 || newcustom) { - if (askinputcustom (hDlg, custom1, sizeof custom1 / sizeof (TCHAR), IDS_SB_CUSTOMEVENT)) { - inputdevice_set_mapping (input_selected_device, input_selected_widget, - 0, custom1, flags, input_selected_sub_num); + TCHAR custom1[MAX_DPATH]; + int flags; + custom1[0] = 0; + inputdevice_get_mapped_name (input_selected_device, input_selected_widget, + &flags, 0, custom1, input_selected_sub_num); + if (_tcslen (custom1) > 0 || newcustom) { + if (askinputcustom (hDlg, custom1, sizeof custom1 / sizeof (TCHAR), IDS_SB_CUSTOMEVENT)) { + inputdevice_set_mapping (input_selected_device, input_selected_widget, + 0, custom1, flags, input_selected_sub_num); + } } - } } static void values_from_inputdlgbottom (HWND hDlg) { - int v; - BOOL success; - - v = GetDlgItemInt (hDlg, IDC_INPUTDEADZONE, &success, FALSE); - if (success) { - currprefs.input_joystick_deadzone = workprefs.input_joystick_deadzone = v; - currprefs.input_joystick_deadzone = workprefs.input_joymouse_deadzone = v; - } - v = GetDlgItemInt (hDlg, IDC_INPUTAUTOFIRERATE, &success, FALSE); - if (success) - currprefs.input_autofire_framecnt = workprefs.input_autofire_framecnt = v; - v = GetDlgItemInt (hDlg, IDC_INPUTSPEEDD, &success, FALSE); - if (success) - currprefs.input_joymouse_speed = workprefs.input_joymouse_speed = v; - v = GetDlgItemInt (hDlg, IDC_INPUTSPEEDA, &success, FALSE); - if (success) - currprefs.input_joymouse_multiplier = workprefs.input_joymouse_multiplier = v; + int v; + BOOL success; + + v = GetDlgItemInt (hDlg, IDC_INPUTDEADZONE, &success, FALSE); + if (success) { + currprefs.input_joystick_deadzone = workprefs.input_joystick_deadzone = v; + currprefs.input_joystick_deadzone = workprefs.input_joymouse_deadzone = v; + } + v = GetDlgItemInt (hDlg, IDC_INPUTAUTOFIRERATE, &success, FALSE); + if (success) + currprefs.input_autofire_framecnt = workprefs.input_autofire_framecnt = v; + v = GetDlgItemInt (hDlg, IDC_INPUTSPEEDD, &success, FALSE); + if (success) + currprefs.input_joymouse_speed = workprefs.input_joymouse_speed = v; + v = GetDlgItemInt (hDlg, IDC_INPUTSPEEDA, &success, FALSE); + if (success) + currprefs.input_joymouse_multiplier = workprefs.input_joymouse_multiplier = v; } static void values_from_inputdlg (HWND hDlg, int inputchange) { - int doselect = 0; - LRESULT item; + int doselect = 0; + LRESULT item; - item = SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR && input_selected_sub_num != item) { - input_selected_sub_num = (int)item; - doselect = 0; - init_inputdlg_2 (hDlg); - update_listview_input (hDlg); - return; - } - - item = SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_GETCURSEL, 0, 0L); - if(item != CB_ERR) { - if (item != workprefs.input_selected_setting) { - workprefs.input_selected_setting = (int)item; - input_selected_widget = -1; - inputdevice_updateconfig (&workprefs); - enable_for_inputdlg (hDlg); - InitializeListView (hDlg); - doselect = 1; - } - } - item = SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_GETCURSEL, 0, 0L); - if(item != CB_ERR) { - if (item != input_selected_device) { - input_selected_device = (int)item; - input_selected_widget = -1; - input_selected_event = -1; - InitializeListView (hDlg); - init_inputdlg_2 (hDlg); - values_to_inputdlg (hDlg); - doselect = 1; - } - } - item = SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_GETCURSEL, 0, 0L); - if(item != CB_ERR) { - if (item == 1) { - if (item != input_selected_event) - doinputcustom (hDlg, 1); - } - input_selected_event = (int)item; - doselect = 1; - } - - if (inputchange && doselect && input_selected_device >= 0 && input_selected_event >= 0) { - int flags; - TCHAR custom[MAX_DPATH]; - custom[0] = 0; - inputdevice_get_mapped_name (input_selected_device, input_selected_widget, - &flags, 0, custom, input_selected_sub_num); - if (input_selected_event != 1) - custom[0] = 0; - inputdevice_set_mapping (input_selected_device, input_selected_widget, - eventnames[input_selected_event], _tcslen (custom) == 0 ? NULL : custom, - flags, input_selected_sub_num); - update_listview_input (hDlg); - inputdevice_updateconfig (&workprefs); - } + item = SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR && input_selected_sub_num != item) { + input_selected_sub_num = (int)item; + doselect = 0; + init_inputdlg_2 (hDlg); + update_listview_input (hDlg); + return; + } + + item = SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_GETCURSEL, 0, 0L); + if(item != CB_ERR) { + if (item != workprefs.input_selected_setting) { + workprefs.input_selected_setting = (int)item; + input_selected_widget = -1; + inputdevice_updateconfig (&workprefs); + enable_for_inputdlg (hDlg); + InitializeListView (hDlg); + doselect = 1; + } + } + item = SendDlgItemMessage (hDlg, IDC_INPUTDEVICE, CB_GETCURSEL, 0, 0L); + if(item != CB_ERR) { + if (item != input_selected_device) { + input_selected_device = (int)item; + input_selected_widget = -1; + input_selected_event = -1; + InitializeListView (hDlg); + init_inputdlg_2 (hDlg); + values_to_inputdlg (hDlg); + doselect = 1; + } + } + item = SendDlgItemMessage (hDlg, IDC_INPUTAMIGA, CB_GETCURSEL, 0, 0L); + if(item != CB_ERR) { + if (item == 1) { + if (item != input_selected_event) + doinputcustom (hDlg, 1); + } + input_selected_event = (int)item; + doselect = 1; + } + + if (inputchange && doselect && input_selected_device >= 0 && input_selected_event >= 0) { + int flags; + TCHAR custom[MAX_DPATH]; + custom[0] = 0; + inputdevice_get_mapped_name (input_selected_device, input_selected_widget, + &flags, 0, custom, input_selected_sub_num); + if (input_selected_event != 1) + custom[0] = 0; + inputdevice_set_mapping (input_selected_device, input_selected_widget, + eventnames[input_selected_event], _tcslen (custom) == 0 ? NULL : custom, + flags, input_selected_sub_num); + update_listview_input (hDlg); + inputdevice_updateconfig (&workprefs); + } } static void input_swap (HWND hDlg) { - inputdevice_swap_ports (&workprefs, input_selected_device); - init_inputdlg (hDlg); + inputdevice_swap_ports (&workprefs, input_selected_device); + init_inputdlg (hDlg); } #if 0 static void input_copy (HWND hDlg) { - TCHAR buf[2000]; - inputdevice_acquire (1); - for (;;) { - focus = 1; - inputdevice_testread (buf); - focus = 0; - Sleep (100); - } - inputdevice_unacquire (); + TCHAR buf[2000]; + inputdevice_acquire (1); + for (;;) { + focus = 1; + inputdevice_testread (buf); + focus = 0; + Sleep (100); + } + inputdevice_unacquire (); } #else static void input_copy (HWND hDlg) { - int dst = workprefs.input_selected_setting; - LRESULT src = SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_GETCURSEL, 0, 0L); - if (src == CB_ERR) - return; - inputdevice_copy_single_config (&workprefs, (int)src, workprefs.input_selected_setting, input_selected_device); - init_inputdlg (hDlg); + int dst = workprefs.input_selected_setting; + LRESULT src = SendDlgItemMessage (hDlg, IDC_INPUTCOPYFROM, CB_GETCURSEL, 0, 0L); + if (src == CB_ERR) + return; + inputdevice_copy_single_config (&workprefs, (int)src, workprefs.input_selected_setting, input_selected_device); + init_inputdlg (hDlg); } #endif static void input_toggleautofire (void) { - int flags, evt; - TCHAR name[256]; - TCHAR custom[MAX_DPATH]; - if (input_selected_device < 0 || input_selected_widget < 0) - return; - evt = inputdevice_get_mapped_name (input_selected_device, input_selected_widget, - &flags, name, custom, input_selected_sub_num); - if (evt <= 0) - return; - inputdevice_set_mapping (input_selected_device, input_selected_widget, - name, custom, flags ^ IDEV_MAPPED_AUTOFIRE_SET, input_selected_sub_num); + int flags, evt; + TCHAR name[256]; + TCHAR custom[MAX_DPATH]; + if (input_selected_device < 0 || input_selected_widget < 0) + return; + evt = inputdevice_get_mapped_name (input_selected_device, input_selected_widget, + &flags, name, custom, input_selected_sub_num); + if (evt <= 0) + return; + inputdevice_set_mapping (input_selected_device, input_selected_widget, + name, custom, flags ^ IDEV_MAPPED_AUTOFIRE_SET, input_selected_sub_num); } static void input_toggletoggle (void) { - int flags, evt; - TCHAR name[256]; - TCHAR custom[MAX_DPATH]; - if (input_selected_device < 0 || input_selected_widget < 0) - return; - evt = inputdevice_get_mapped_name (input_selected_device, input_selected_widget, - &flags, name, custom, input_selected_sub_num); - if (evt <= 0) - return; - inputdevice_set_mapping (input_selected_device, input_selected_widget, - name, custom, flags ^ IDEV_MAPPED_TOGGLE, input_selected_sub_num); + int flags, evt; + TCHAR name[256]; + TCHAR custom[MAX_DPATH]; + if (input_selected_device < 0 || input_selected_widget < 0) + return; + evt = inputdevice_get_mapped_name (input_selected_device, input_selected_widget, + &flags, name, custom, input_selected_sub_num); + if (evt <= 0) + return; + inputdevice_set_mapping (input_selected_device, input_selected_widget, + name, custom, flags ^ IDEV_MAPPED_TOGGLE, input_selected_sub_num); } static INT_PTR CALLBACK InputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - TCHAR name_buf[MAX_DPATH] = L"", desc_buf[128] = L""; - TCHAR *posn = NULL; - HWND list; - int dblclick = 0; - NM_LISTVIEW *nmlistview; - int items = 0, entry = 0; - static int recursive; - - switch (msg) - { - case WM_INITDIALOG: - pages[INPUT_ID] = hDlg; - currentpage = INPUT_ID; - inputdevice_updateconfig (&workprefs); - inputdevice_config_change (); - input_selected_widget = -1; - init_inputdlg (hDlg); + TCHAR name_buf[MAX_DPATH] = L"", desc_buf[128] = L""; + TCHAR *posn = NULL; + HWND list; + int dblclick = 0; + NM_LISTVIEW *nmlistview; + int items = 0, entry = 0; + static int recursive; - case WM_USER: - recursive++; - enable_for_inputdlg (hDlg); - values_to_inputdlg (hDlg); - recursive--; - return TRUE; - case WM_COMMAND: - if (recursive) - break; - recursive++; - switch (wParam) + switch (msg) { - case IDC_INPUTCOPY: - input_copy (hDlg); - break; - case IDC_INPUTSWAP: - input_swap (hDlg); - break; - case IDC_INPUTDEVICEDISABLE: - inputdevice_set_device_status (input_selected_device, IsDlgButtonChecked (hDlg, IDC_INPUTDEVICEDISABLE) ? 1 : 0); - break; - default: - switch (LOWORD (wParam)) - { - case IDC_INPUTDEADZONE: - case IDC_INPUTAUTOFIRERATE: - case IDC_INPUTSPEEDD: - case IDC_INPUTSPEEDA: - values_from_inputdlgbottom (hDlg); - break; - } - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { - switch (LOWORD (wParam)) + case WM_INITDIALOG: + pages[INPUT_ID] = hDlg; + currentpage = INPUT_ID; + inputdevice_updateconfig (&workprefs); + inputdevice_config_change (); + input_selected_widget = -1; + init_inputdlg (hDlg); + + case WM_USER: + recursive++; + enable_for_inputdlg (hDlg); + values_to_inputdlg (hDlg); + recursive--; + return TRUE; + case WM_COMMAND: + if (recursive) + break; + recursive++; + switch (wParam) + { + case IDC_INPUTCOPY: + input_copy (hDlg); + break; + case IDC_INPUTSWAP: + input_swap (hDlg); + break; + case IDC_INPUTDEVICEDISABLE: + inputdevice_set_device_status (input_selected_device, IsDlgButtonChecked (hDlg, IDC_INPUTDEVICEDISABLE) ? 1 : 0); + break; + default: + switch (LOWORD (wParam)) + { + case IDC_INPUTDEADZONE: + case IDC_INPUTAUTOFIRERATE: + case IDC_INPUTSPEEDD: + case IDC_INPUTSPEEDA: + values_from_inputdlgbottom (hDlg); + break; + } + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + switch (LOWORD (wParam)) + { + case IDC_INPUTAMIGA: + values_from_inputdlg (hDlg, 1); + break; + case IDC_INPUTAMIGACNT: + case IDC_INPUTTYPE: + case IDC_INPUTDEVICE: + values_from_inputdlg (hDlg, 0); + break; + } + } + break; + } + enable_for_portsdlg (hDlg); + inputdevice_config_change (); + recursive--; + break; + case WM_NOTIFY: + if (((LPNMHDR) lParam)->idFrom == IDC_INPUTLIST) { - case IDC_INPUTAMIGA: - values_from_inputdlg (hDlg, 1); - break; - case IDC_INPUTAMIGACNT: - case IDC_INPUTTYPE: - case IDC_INPUTDEVICE: - values_from_inputdlg (hDlg, 0); - break; - } - } - break; - } - enable_for_portsdlg (hDlg); - inputdevice_config_change (); - recursive--; - break; - case WM_NOTIFY: - if (((LPNMHDR) lParam)->idFrom == IDC_INPUTLIST) - { - int row; - nmlistview = (NM_LISTVIEW *) lParam; - list = nmlistview->hdr.hwndFrom; - switch (nmlistview->hdr.code) - { - case NM_DBLCLK: - dblclick = 1; - /* fall-through */ - case NM_CLICK: - entry = listview_entry_from_click (list, &row); - if (entry >= 0) { - int oldentry = input_selected_widget; - input_selected_widget = entry; - if (row == 2 && entry == oldentry) - input_toggleautofire (); - if (row == 3 && entry == oldentry) - input_toggletoggle (); - if (row == 4) { - input_selected_sub_num++; - if (input_selected_sub_num >= MAX_INPUT_SUB_EVENT) - input_selected_sub_num = 0; - SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); - } - } else { - input_selected_widget = -1; + int row; + nmlistview = (NM_LISTVIEW *) lParam; + list = nmlistview->hdr.hwndFrom; + switch (nmlistview->hdr.code) + { + case NM_DBLCLK: + dblclick = 1; + /* fall-through */ + case NM_CLICK: + entry = listview_entry_from_click (list, &row); + if (entry >= 0) { + int oldentry = input_selected_widget; + input_selected_widget = entry; + if (row == 2 && entry == oldentry) + input_toggleautofire (); + if (row == 3 && entry == oldentry) + input_toggletoggle (); + if (row == 4) { + input_selected_sub_num++; + if (input_selected_sub_num >= MAX_INPUT_SUB_EVENT) + input_selected_sub_num = 0; + SendDlgItemMessage (hDlg, IDC_INPUTAMIGACNT, CB_SETCURSEL, input_selected_sub_num, 0); + } + } else { + input_selected_widget = -1; + } + if (dblclick) + doinputcustom (hDlg, 0); + update_listview_input (hDlg); + init_inputdlg_2 (hDlg); + } } - if (dblclick) - doinputcustom (hDlg, 0); - update_listview_input (hDlg); - init_inputdlg_2 (hDlg); - } } - } - return FALSE; + return FALSE; } #ifdef GFXFILTER @@ -10432,88 +10444,88 @@ static int filterpreset_selected = -1, filterpreset_builtin = -1; static void enable_for_hw3ddlg (HWND hDlg) { - int v = workprefs.gfx_filter ? TRUE : FALSE; - int vv = FALSE, vv2 = FALSE, vv3 = FALSE, vv4 = FALSE; - int as = workprefs.gfx_filter_autoscale; - struct uae_filter *uf; - int i; - - uf = &uaefilters[0]; - i = 0; - while (uaefilters[i].name) { - if (workprefs.gfx_filter == uaefilters[i].type) { - uf = &uaefilters[i]; - break; - } - i++; - } - if (v && (uf->x[0] || uf->x[1] || uf->x[2] || uf->x[3] || uf->x[4])) - vv = TRUE; - if (v && (uf->x[0] || uf->yuv)) - vv2 = TRUE; - if (v && (uf->x[0] && !uf->yuv)) - vv3 = TRUE; - if (v && uf->x[0]) - vv4 = TRUE; - ew (hDlg, IDC_FILTERHZ, v); - ew (hDlg, IDC_FILTERVZ, v); - ew (hDlg, IDC_FILTERHZMULT, v && !as); - ew (hDlg, IDC_FILTERVZMULT, v && !as); - ew (hDlg, IDC_FILTERHO, v && !as); - ew (hDlg, IDC_FILTERVO, v && !as); - ew (hDlg, IDC_FILTERSLR, vv3); - ew (hDlg, IDC_FILTERXL, vv2); - ew (hDlg, IDC_FILTERXLV, vv2); - ew (hDlg, IDC_FILTERXTRA, vv2); - ew (hDlg, IDC_FILTERDEFAULT, v); - ew (hDlg, IDC_FILTERFILTER, vv); - ew (hDlg, IDC_FILTERKEEPASPECT, v); - ew (hDlg, IDC_FILTERASPECT, v); - ew (hDlg, IDC_FILTERASPECT2, v && workprefs.gfx_filter_keep_aspect); - - ew (hDlg, IDC_FILTERPRESETSAVE, filterpreset_builtin < 0); - ew (hDlg, IDC_FILTERPRESETLOAD, filterpreset_selected > 0); - ew (hDlg, IDC_FILTERPRESETDELETE, filterpreset_selected > 0 && filterpreset_builtin < 0); + int v = workprefs.gfx_filter ? TRUE : FALSE; + int vv = FALSE, vv2 = FALSE, vv3 = FALSE, vv4 = FALSE; + int as = workprefs.gfx_filter_autoscale; + struct uae_filter *uf; + int i; + + uf = &uaefilters[0]; + i = 0; + while (uaefilters[i].name) { + if (workprefs.gfx_filter == uaefilters[i].type) { + uf = &uaefilters[i]; + break; + } + i++; + } + if (v && (uf->x[0] || uf->x[1] || uf->x[2] || uf->x[3] || uf->x[4])) + vv = TRUE; + if (v && (uf->x[0] || uf->yuv)) + vv2 = TRUE; + if (v && (uf->x[0] && !uf->yuv)) + vv3 = TRUE; + if (v && uf->x[0]) + vv4 = TRUE; + ew (hDlg, IDC_FILTERHZ, v); + ew (hDlg, IDC_FILTERVZ, v); + ew (hDlg, IDC_FILTERHZMULT, v && !as); + ew (hDlg, IDC_FILTERVZMULT, v && !as); + ew (hDlg, IDC_FILTERHO, v && !as); + ew (hDlg, IDC_FILTERVO, v && !as); + ew (hDlg, IDC_FILTERSLR, vv3); + ew (hDlg, IDC_FILTERXL, vv2); + ew (hDlg, IDC_FILTERXLV, vv2); + ew (hDlg, IDC_FILTERXTRA, vv2); + ew (hDlg, IDC_FILTERDEFAULT, v); + ew (hDlg, IDC_FILTERFILTER, vv); + ew (hDlg, IDC_FILTERKEEPASPECT, v); + ew (hDlg, IDC_FILTERASPECT, v); + ew (hDlg, IDC_FILTERASPECT2, v && workprefs.gfx_filter_keep_aspect); + + ew (hDlg, IDC_FILTERPRESETSAVE, filterpreset_builtin < 0); + ew (hDlg, IDC_FILTERPRESETLOAD, filterpreset_selected > 0); + ew (hDlg, IDC_FILTERPRESETDELETE, filterpreset_selected > 0 && filterpreset_builtin < 0); } static void makefilter (TCHAR *s, int x, int flags) { - _stprintf (s, L"%dx", x); - if ((flags & (UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32)) == (UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32)) { - _tcscat (s, L" (16bit/32bit)"); - return; - } - if (flags & UAE_FILTER_MODE_16) - _tcscat (s, L" (16bit)"); - if (flags & UAE_FILTER_MODE_32) - _tcscat (s, L" (32bit)"); + _stprintf (s, L"%dx", x); + if ((flags & (UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32)) == (UAE_FILTER_MODE_16_16 | UAE_FILTER_MODE_32_32)) { + _tcscat (s, L" (16bit/32bit)"); + return; + } + if (flags & UAE_FILTER_MODE_16) + _tcscat (s, L" (16bit)"); + if (flags & UAE_FILTER_MODE_32) + _tcscat (s, L" (32bit)"); } static TCHAR *filtermultnames[] = { L"FS", L"1/2x", L"1x", L"2x", L"4x", L"6x", L"8x", NULL }; static int filtermults[] = { 0, 2000, 1000, 500, 250, 167, 125 }; struct filterxtra { - TCHAR *label; - int *varw, *varc; - int min, max, step; + TCHAR *label; + int *varw, *varc; + int min, max, step; }; static struct filterxtra *filter_extra, *filter_selected; static struct filterxtra filter_pal_extra[] = { - L"Brightness", &workprefs.gfx_filter_luminance, &currprefs.gfx_filter_luminance, -1000, 1000, 10, - L"Contrast", &workprefs.gfx_filter_contrast, &currprefs.gfx_filter_contrast, -1000, 1000, 10, - L"Saturation", &workprefs.gfx_filter_saturation, &currprefs.gfx_filter_saturation, -1000, 1000, 10, - L"Gamma", &workprefs.gfx_gamma, &currprefs.gfx_gamma, -1000, 1000, 10, - L"Scanlines", &workprefs.gfx_filter_scanlines, &currprefs.gfx_filter_scanlines, 0, 100, 1, - L"Blurriness", &workprefs.gfx_filter_blur, &currprefs.gfx_filter_blur,0, 2000, 10, - L"Noise", &workprefs.gfx_filter_noise, &currprefs.gfx_filter_noise,0, 100, 10, - NULL + L"Brightness", &workprefs.gfx_filter_luminance, &currprefs.gfx_filter_luminance, -1000, 1000, 10, + L"Contrast", &workprefs.gfx_filter_contrast, &currprefs.gfx_filter_contrast, -1000, 1000, 10, + L"Saturation", &workprefs.gfx_filter_saturation, &currprefs.gfx_filter_saturation, -1000, 1000, 10, + L"Gamma", &workprefs.gfx_gamma, &currprefs.gfx_gamma, -1000, 1000, 10, + L"Scanlines", &workprefs.gfx_filter_scanlines, &currprefs.gfx_filter_scanlines, 0, 100, 1, + L"Blurriness", &workprefs.gfx_filter_blur, &currprefs.gfx_filter_blur,0, 2000, 10, + L"Noise", &workprefs.gfx_filter_noise, &currprefs.gfx_filter_noise,0, 100, 10, + NULL }; static struct filterxtra filter_3d_extra[] = { - L"Scanline transparency", &workprefs.gfx_filter_scanlines, &currprefs.gfx_filter_scanlines, 0, 100, 10, - L"Scanline level", &workprefs.gfx_filter_scanlinelevel, &currprefs.gfx_filter_scanlinelevel, 0, 100, 10, - NULL + L"Scanline transparency", &workprefs.gfx_filter_scanlines, &currprefs.gfx_filter_scanlines, 0, 100, 10, + L"Scanline level", &workprefs.gfx_filter_scanlinelevel, &currprefs.gfx_filter_scanlinelevel, 0, 100, 10, + NULL }; static int dummy_in, dummy_out; static int *filtervars[] = { @@ -10529,7 +10541,7 @@ static int *filtervars[] = { &workprefs.gfx_filter_keep_aspect, &workprefs.gfx_filter_aspect, &workprefs.gfx_filter_autoscale, NULL - }; +}; static int *filtervars2[] = { NULL, &currprefs.gfx_filter_filtermode, &currprefs.gfx_filter_vert_zoom, &currprefs.gfx_filter_horiz_zoom, @@ -10543,281 +10555,281 @@ static int *filtervars2[] = { &currprefs.gfx_filter_keep_aspect, &currprefs.gfx_filter_aspect, &workprefs.gfx_filter_autoscale, NULL - }; +}; struct filterpreset { - TCHAR *name; - int conf[25]; + TCHAR *name; + int conf[25]; }; static struct filterpreset filterpresets[] = { - { L"PAL", 8, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 1, 1, 0, 0, 0, 10, 0, 0, 0, 300, 30, 0, 0, 0 }, - { L"D3D Autoscale", 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1 }, - { L"D3D Full Scaling", 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0 }, - { NULL } + { L"PAL", 8, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 1, 1, 0, 0, 0, 10, 0, 0, 0, 300, 30, 0, 0, 0 }, + { L"D3D Autoscale", 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1 }, + { L"D3D Full Scaling", 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0 }, + { NULL } }; static int getfiltermult(HWND hDlg, DWORD dlg) { - TCHAR tmp[100]; - LRESULT v = SendDlgItemMessage (hDlg, dlg, CB_GETCURSEL, 0, 0L); - float f; - - if (v != CB_ERR) - return filtermults[v]; - SendDlgItemMessage (hDlg, dlg, WM_GETTEXT, (WPARAM)sizeof tmp / sizeof (TCHAR), (LPARAM)tmp); - if (!_tcsicmp (tmp, L"FS")) - return 0; - f = (float)_tstof (tmp); - if (f < 0) - f = 0; - if (f > 9) - f = 9; - return (int)(1000.0 / f); + TCHAR tmp[100]; + LRESULT v = SendDlgItemMessage (hDlg, dlg, CB_GETCURSEL, 0, 0L); + float f; + + if (v != CB_ERR) + return filtermults[v]; + SendDlgItemMessage (hDlg, dlg, WM_GETTEXT, (WPARAM)sizeof tmp / sizeof (TCHAR), (LPARAM)tmp); + if (!_tcsicmp (tmp, L"FS")) + return 0; + f = (float)_tstof (tmp); + if (f < 0) + f = 0; + if (f > 9) + f = 9; + return (int)(1000.0 / f); } static void setfiltermult2 (HWND hDlg, int id, int val) { - int i, got; + int i, got; - got = 0; - SendDlgItemMessage (hDlg, id, CB_SETCURSEL, 0, 0); - for (i = 0; filtermultnames[i]; i++) { - if (filtermults[i] == val) { - SendDlgItemMessage (hDlg, id, CB_SETCURSEL, i, 0); - got = 1; + got = 0; + SendDlgItemMessage (hDlg, id, CB_SETCURSEL, 0, 0); + for (i = 0; filtermultnames[i]; i++) { + if (filtermults[i] == val) { + SendDlgItemMessage (hDlg, id, CB_SETCURSEL, i, 0); + got = 1; + } + } + if (!got) { + TCHAR tmp[100]; + tmp[0] = 0; + if (val > 0) + _stprintf (tmp, L"%.2f", 1000.0 / val); + SetDlgItemText (hDlg, id, tmp); } - } - if (!got) { - TCHAR tmp[100]; - tmp[0] = 0; - if (val > 0) - _stprintf (tmp, L"%.2f", 1000.0 / val); - SetDlgItemText (hDlg, id, tmp); - } } static void setfiltermult (HWND hDlg) { - int i; + int i; - SendDlgItemMessage (hDlg, IDC_FILTERHZMULT, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_FILTERVZMULT, CB_RESETCONTENT, 0, 0L); - for (i = 0; filtermultnames[i]; i++) { - SendDlgItemMessage (hDlg, IDC_FILTERHZMULT, CB_ADDSTRING, 0, (LPARAM)filtermultnames[i]); - SendDlgItemMessage (hDlg, IDC_FILTERVZMULT, CB_ADDSTRING, 0, (LPARAM)filtermultnames[i]); - } - setfiltermult2 (hDlg, IDC_FILTERHZMULT, workprefs.gfx_filter_horiz_zoom_mult); - setfiltermult2 (hDlg, IDC_FILTERVZMULT, workprefs.gfx_filter_vert_zoom_mult); + SendDlgItemMessage (hDlg, IDC_FILTERHZMULT, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_FILTERVZMULT, CB_RESETCONTENT, 0, 0L); + for (i = 0; filtermultnames[i]; i++) { + SendDlgItemMessage (hDlg, IDC_FILTERHZMULT, CB_ADDSTRING, 0, (LPARAM)filtermultnames[i]); + SendDlgItemMessage (hDlg, IDC_FILTERVZMULT, CB_ADDSTRING, 0, (LPARAM)filtermultnames[i]); + } + setfiltermult2 (hDlg, IDC_FILTERHZMULT, workprefs.gfx_filter_horiz_zoom_mult); + setfiltermult2 (hDlg, IDC_FILTERVZMULT, workprefs.gfx_filter_vert_zoom_mult); } static void values_to_hw3ddlg (HWND hDlg) { - TCHAR txt[100], tmp[100]; - int i, j, nofilter, fltnum, modenum; - struct uae_filter *uf; - UAEREG *fkey; - - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_SETCURSEL, - (workprefs.gfx_filter_aspect == 0) ? 0 : - (workprefs.gfx_filter_aspect < 0) ? 1 : - (workprefs.gfx_filter_aspect == 4 * 256 + 3) ? 2 : - (workprefs.gfx_filter_aspect == 5 * 256 + 4) ? 3 : - (workprefs.gfx_filter_aspect == 15 * 256 + 9) ? 4 : - (workprefs.gfx_filter_aspect == 16 * 256 + 9) ? 5 : - (workprefs.gfx_filter_aspect == 16 * 256 + 10) ? 6 : 0, 0); - - CheckDlgButton (hDlg, IDC_FILTERKEEPASPECT, workprefs.gfx_filter_keep_aspect); - - SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_SETCURSEL, - workprefs.gfx_filter_keep_aspect, 0); - - SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_AUTOSCALE_DISABLED, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_AUTOSCALE_SCALING, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); - WIN32GUI_LoadUIString (IDS_AUTOSCALE_RESIZE, txt, sizeof (txt) / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); - SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_SETCURSEL, workprefs.gfx_filter_autoscale, 0); - - SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); - SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); - SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); - SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETPAGESIZE, 0, 1); - SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); - SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETPAGESIZE, 0, 1); - - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_NONE, tmp, MAX_DPATH); - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)tmp); - uf = &uaefilters[0]; - nofilter = 0; fltnum = 0; - i = 0; j = 1; - while (uaefilters[i].name) { - switch (uaefilters[i].type) - { + TCHAR txt[100], tmp[100]; + int i, j, nofilter, fltnum, modenum; + struct uae_filter *uf; + UAEREG *fkey; + + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_SETCURSEL, + (workprefs.gfx_filter_aspect == 0) ? 0 : + (workprefs.gfx_filter_aspect < 0) ? 1 : + (workprefs.gfx_filter_aspect == 4 * 256 + 3) ? 2 : + (workprefs.gfx_filter_aspect == 5 * 256 + 4) ? 3 : + (workprefs.gfx_filter_aspect == 15 * 256 + 9) ? 4 : + (workprefs.gfx_filter_aspect == 16 * 256 + 9) ? 5 : + (workprefs.gfx_filter_aspect == 16 * 256 + 10) ? 6 : 0, 0); + + CheckDlgButton (hDlg, IDC_FILTERKEEPASPECT, workprefs.gfx_filter_keep_aspect); + + SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_SETCURSEL, + workprefs.gfx_filter_keep_aspect, 0); + + SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_AUTOSCALE_DISABLED, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_AUTOSCALE_SCALING, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); + WIN32GUI_LoadUIString (IDS_AUTOSCALE_RESIZE, txt, sizeof (txt) / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_ADDSTRING, 0, (LPARAM)txt); + SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_SETCURSEL, workprefs.gfx_filter_autoscale, 0); + + SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); + SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); + SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); + SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETPAGESIZE, 0, 1); + SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); + SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETPAGESIZE, 0, 1); + + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString (IDS_NONE, tmp, MAX_DPATH); + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)tmp); + uf = &uaefilters[0]; + nofilter = 0; fltnum = 0; + i = 0; j = 1; + while (uaefilters[i].name) { + switch (uaefilters[i].type) + { #if 0 #ifndef D3D - case UAE_FILTER_DIRECT3D: - nofilter = 1; - break; + case UAE_FILTER_DIRECT3D: + nofilter = 1; + break; #endif #ifndef OPENGL - case UAE_FILTER_OPENGL: - nofilter = 1; - break; + case UAE_FILTER_OPENGL: + nofilter = 1; + break; #endif #endif - default: - nofilter = 0; - break; - } - if (nofilter == 0) { - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)uaefilters[i].name); - if (uaefilters[i].type == workprefs.gfx_filter) { - uf = &uaefilters[i]; - fltnum = j; - } - j++; - } - i++; - } - if (D3D_canshaders ()) { - HANDLE h; - WIN32_FIND_DATA wfd; - TCHAR tmp[MAX_DPATH]; - _stprintf (tmp, L"%s%sfiltershaders\\direct3d\\*.fx", start_path_exe, WIN32_PLUGINDIR); - h = FindFirstFile (tmp, &wfd); - while (h != INVALID_HANDLE_VALUE) { - TCHAR tmp2[100]; - _stprintf (tmp2, L"D3D: %s", wfd.cFileName); - tmp2[_tcslen (tmp2) - 3] = 0; - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)tmp2); - if (uf->type == UAE_FILTER_DIRECT3D && !_tcscmp (workprefs.gfx_filtershader, wfd.cFileName)) - fltnum = j; - j++; - if (!FindNextFile (h, &wfd)) { - FindClose (h); - h = INVALID_HANDLE_VALUE; - } - } - } - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_SETCURSEL, fltnum, 0); - - filter_extra = NULL; - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_RESETCONTENT, 0, 0L); - if (uf->x[0]) { - WIN32GUI_LoadUIString (IDS_3D_NO_FILTER, txt, sizeof (txt) / sizeof (TCHAR)); - _stprintf (tmp, txt, 16); - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_3D_BILINEAR, txt, sizeof (txt) / sizeof (TCHAR)); - _stprintf (tmp, txt, 16); - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_3D_NO_FILTER, txt, sizeof (txt) / sizeof (TCHAR)); - _stprintf (tmp, txt, 32); - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_3D_BILINEAR, txt, sizeof (txt) / sizeof (TCHAR)); - _stprintf (tmp, txt, 32); - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); - modenum = 4; - filter_extra = filter_3d_extra; - } else { - modenum = 0; - for (i = 1; i <= 4; i++) { - if (uf->x[i]) { - makefilter (tmp, i, uf->x[i]); + default: + nofilter = 0; + break; + } + if (nofilter == 0) { + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)uaefilters[i].name); + if (uaefilters[i].type == workprefs.gfx_filter) { + uf = &uaefilters[i]; + fltnum = j; + } + j++; + } + i++; + } + if (D3D_canshaders ()) { + HANDLE h; + WIN32_FIND_DATA wfd; + TCHAR tmp[MAX_DPATH]; + _stprintf (tmp, L"%s%sfiltershaders\\direct3d\\*.fx", start_path_exe, WIN32_PLUGINDIR); + h = FindFirstFile (tmp, &wfd); + while (h != INVALID_HANDLE_VALUE) { + TCHAR tmp2[100]; + _stprintf (tmp2, L"D3D: %s", wfd.cFileName); + tmp2[_tcslen (tmp2) - 3] = 0; + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_ADDSTRING, 0, (LPARAM)tmp2); + if (uf->type == UAE_FILTER_DIRECT3D && !_tcscmp (workprefs.gfx_filtershader, wfd.cFileName)) + fltnum = j; + j++; + if (!FindNextFile (h, &wfd)) { + FindClose (h); + h = INVALID_HANDLE_VALUE; + } + } + } + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_SETCURSEL, fltnum, 0); + + filter_extra = NULL; + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_RESETCONTENT, 0, 0L); + if (uf->x[0]) { + WIN32GUI_LoadUIString (IDS_3D_NO_FILTER, txt, sizeof (txt) / sizeof (TCHAR)); + _stprintf (tmp, txt, 16); SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); - modenum++; - } - } - if (uf->yuv) { - filter_extra = filter_pal_extra; - } - } - SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETRANGE, TRUE, MAKELONG ( 0, +1000)); - SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPAGESIZE, 0, 1); - if (filter_extra) { - int idx2 = -1; - int idx = SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_GETCURSEL, 0, 0L); - if (idx == CB_ERR) - idx = -1; - SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_RESETCONTENT, 0, 0L); - for (i = 0; filter_extra[i].label; i++) { - if (filter_selected == &filter_extra[i] && idx < 0) - idx2 = i; - SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_ADDSTRING, 0, (LPARAM)filter_extra[i].label); - } - if (idx2 >= 0) - filter_selected = &filter_extra[idx2]; - else if (idx >= 0) - filter_selected = &filter_extra[idx]; - else - filter_selected = &filter_extra[0]; - SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_SETCURSEL, filter_selected - &filter_extra[0], 0); - SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETRANGE, TRUE, MAKELONG (filter_selected->min, filter_selected->max)); - SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPAGESIZE, 0, filter_selected->step); - if (filter_selected) { - SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPOS, TRUE, *(filter_selected->varw)); - SetDlgItemInt (hDlg, IDC_FILTERXLV, *(filter_selected->varw), TRUE); - } - } - - if (workprefs.gfx_filter_filtermode >= modenum) - workprefs.gfx_filter_filtermode = 0; - SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_SETCURSEL, workprefs.gfx_filter_filtermode, 0); - - setfiltermult (hDlg); - - SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_RESETCONTENT, 0, 0L); - i = j = 0; - while (scanlineratios[i * 2]) { - int sl = scanlineratios[i * 2] * 16 + scanlineratios[i * 2 + 1]; - _stprintf (txt, L"%d:%d", scanlineratios[i * 2], scanlineratios[i * 2 + 1]); - if (workprefs.gfx_filter_scanlineratio == sl) - j = i; - SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_ADDSTRING, 0, (LPARAM)txt); - scanlineindexes[i] = sl; - i++; - } - SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_SETCURSEL, j, 0); - - j = 0; - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_RESETCONTENT, 0, 0L); - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)L""); - for (i = 0; filterpresets[i].name; i++) { - TCHAR tmp[MAX_DPATH]; - _stprintf (tmp, L"* %s", filterpresets[i].name); - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp); - } - fkey = regcreatetree (NULL, L"FilterPresets"); - if (fkey) { - int idx = 0; - TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; - DWORD size, size2; - - for (;;) { - size = sizeof (tmp) / sizeof (TCHAR); - size2 = sizeof (tmp2) / sizeof (TCHAR); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp); - idx++; - } - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_SETCURSEL, filterpreset_selected, 0); - regclosetree (fkey); - } + WIN32GUI_LoadUIString (IDS_3D_BILINEAR, txt, sizeof (txt) / sizeof (TCHAR)); + _stprintf (tmp, txt, 16); + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_3D_NO_FILTER, txt, sizeof (txt) / sizeof (TCHAR)); + _stprintf (tmp, txt, 32); + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_3D_BILINEAR, txt, sizeof (txt) / sizeof (TCHAR)); + _stprintf (tmp, txt, 32); + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); + modenum = 4; + filter_extra = filter_3d_extra; + } else { + modenum = 0; + for (i = 1; i <= 4; i++) { + if (uf->x[i]) { + makefilter (tmp, i, uf->x[i]); + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_ADDSTRING, 0, (LPARAM)tmp); + modenum++; + } + } + if (uf->yuv) { + filter_extra = filter_pal_extra; + } + } + SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETRANGE, TRUE, MAKELONG ( 0, +1000)); + SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPAGESIZE, 0, 1); + if (filter_extra) { + int idx2 = -1; + int idx = SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_GETCURSEL, 0, 0L); + if (idx == CB_ERR) + idx = -1; + SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_RESETCONTENT, 0, 0L); + for (i = 0; filter_extra[i].label; i++) { + if (filter_selected == &filter_extra[i] && idx < 0) + idx2 = i; + SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_ADDSTRING, 0, (LPARAM)filter_extra[i].label); + } + if (idx2 >= 0) + filter_selected = &filter_extra[idx2]; + else if (idx >= 0) + filter_selected = &filter_extra[idx]; + else + filter_selected = &filter_extra[0]; + SendDlgItemMessage (hDlg, IDC_FILTERXTRA, CB_SETCURSEL, filter_selected - &filter_extra[0], 0); + SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETRANGE, TRUE, MAKELONG (filter_selected->min, filter_selected->max)); + SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPAGESIZE, 0, filter_selected->step); + if (filter_selected) { + SendDlgItemMessage (hDlg, IDC_FILTERXL, TBM_SETPOS, TRUE, *(filter_selected->varw)); + SetDlgItemInt (hDlg, IDC_FILTERXLV, *(filter_selected->varw), TRUE); + } + } + + if (workprefs.gfx_filter_filtermode >= modenum) + workprefs.gfx_filter_filtermode = 0; + SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_SETCURSEL, workprefs.gfx_filter_filtermode, 0); + + setfiltermult (hDlg); + + SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_RESETCONTENT, 0, 0L); + i = j = 0; + while (scanlineratios[i * 2]) { + int sl = scanlineratios[i * 2] * 16 + scanlineratios[i * 2 + 1]; + _stprintf (txt, L"%d:%d", scanlineratios[i * 2], scanlineratios[i * 2 + 1]); + if (workprefs.gfx_filter_scanlineratio == sl) + j = i; + SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_ADDSTRING, 0, (LPARAM)txt); + scanlineindexes[i] = sl; + i++; + } + SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_SETCURSEL, j, 0); + + j = 0; + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_RESETCONTENT, 0, 0L); + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)L""); + for (i = 0; filterpresets[i].name; i++) { + TCHAR tmp[MAX_DPATH]; + _stprintf (tmp, L"* %s", filterpresets[i].name); + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp); + } + fkey = regcreatetree (NULL, L"FilterPresets"); + if (fkey) { + int idx = 0; + TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH]; + DWORD size, size2; + + for (;;) { + size = sizeof (tmp) / sizeof (TCHAR); + size2 = sizeof (tmp2) / sizeof (TCHAR); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp); + idx++; + } + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_SETCURSEL, filterpreset_selected, 0); + regclosetree (fkey); + } - SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_zoom); - SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_zoom); - SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_offset); - SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_offset); - SetDlgItemInt (hDlg, IDC_FILTERHZV, workprefs.gfx_filter_horiz_zoom, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERVZV, workprefs.gfx_filter_vert_zoom, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERHOV, workprefs.gfx_filter_horiz_offset, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERVOV, workprefs.gfx_filter_vert_offset, TRUE); + SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_zoom); + SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_zoom); + SendDlgItemMessage (hDlg, IDC_FILTERHO, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_offset); + SendDlgItemMessage (hDlg, IDC_FILTERVO, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_offset); + SetDlgItemInt (hDlg, IDC_FILTERHZV, workprefs.gfx_filter_horiz_zoom, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERVZV, workprefs.gfx_filter_vert_zoom, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERHOV, workprefs.gfx_filter_horiz_offset, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERVOV, workprefs.gfx_filter_vert_offset, TRUE); } static void values_from_hw3ddlg (HWND hDlg) @@ -10826,386 +10838,386 @@ static void values_from_hw3ddlg (HWND hDlg) static void filter_preset (HWND hDlg, WPARAM wParam) { - int ok, load, i, builtin, userfilter; - TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; - DWORD outsize; - UAEREG *fkey; - LRESULT item; - - load = 0; - ok = 0; - for (builtin = 0; filterpresets[builtin].name; builtin++); - fkey = regcreatetree (NULL, L"FilterPresets"); - item = SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_GETCURSEL, 0, 0); - tmp1[0] = 0; - if (item != CB_ERR) { - filterpreset_selected = (int)item; - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_GETLBTEXT, (WPARAM)item, (LPARAM)tmp1); - } else { - filterpreset_selected = -1; - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, WM_GETTEXT, (WPARAM)sizeof tmp1 / sizeof (TCHAR), (LPARAM)tmp1); - } - userfilter = 0; - filterpreset_builtin = -1; - if (filterpreset_selected < 0 || filterpreset_selected == 0) { - userfilter = -1; - } else if (filterpreset_selected > builtin) { - userfilter = filterpreset_selected - builtin; - } else { - filterpreset_builtin = filterpreset_selected - 1; - } - - if (filterpreset_builtin < 0) { - outsize = sizeof (tmp2) / sizeof (TCHAR); - if (tmp1[0] && regquerystr (fkey, tmp1, tmp2, &outsize)) - ok = 1; - } else { - TCHAR *p = tmp2; - for (i = 0; filtervars[i]; i++) { - if (i > 0) { - _tcscat (p, L","); - p++; - } - _stprintf (p, L"%d", filterpresets[filterpreset_builtin].conf[i]); - p += _tcslen (p); - } - ok = 1; - } - - if (wParam == IDC_FILTERPRESETSAVE && userfilter && fkey) { - TCHAR *p = tmp2; - for (i = 0; filtervars[i]; i++) { - if (i > 0) { - _tcscat (p, L","); - p++; - } - _stprintf (p, L"%d", *(filtervars[i])); - p += _tcslen (p); - } - if (ok == 0) { - tmp1[0] = 0; - SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, WM_GETTEXT, (WPARAM)sizeof (tmp1) / sizeof (TCHAR), (LPARAM)tmp1); - if (tmp1[0] == 0) - goto end; + int ok, load, i, builtin, userfilter; + TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; + DWORD outsize; + UAEREG *fkey; + LRESULT item; + + load = 0; + ok = 0; + for (builtin = 0; filterpresets[builtin].name; builtin++); + fkey = regcreatetree (NULL, L"FilterPresets"); + item = SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_GETCURSEL, 0, 0); + tmp1[0] = 0; + if (item != CB_ERR) { + filterpreset_selected = (int)item; + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_GETLBTEXT, (WPARAM)item, (LPARAM)tmp1); + } else { + filterpreset_selected = -1; + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, WM_GETTEXT, (WPARAM)sizeof tmp1 / sizeof (TCHAR), (LPARAM)tmp1); + } + userfilter = 0; + filterpreset_builtin = -1; + if (filterpreset_selected < 0 || filterpreset_selected == 0) { + userfilter = -1; + } else if (filterpreset_selected > builtin) { + userfilter = filterpreset_selected - builtin; + } else { + filterpreset_builtin = filterpreset_selected - 1; + } + + if (filterpreset_builtin < 0) { + outsize = sizeof (tmp2) / sizeof (TCHAR); + if (tmp1[0] && regquerystr (fkey, tmp1, tmp2, &outsize)) + ok = 1; + } else { + TCHAR *p = tmp2; + for (i = 0; filtervars[i]; i++) { + if (i > 0) { + _tcscat (p, L","); + p++; + } + _stprintf (p, L"%d", filterpresets[filterpreset_builtin].conf[i]); + p += _tcslen (p); + } + ok = 1; + } + + if (wParam == IDC_FILTERPRESETSAVE && userfilter && fkey) { + TCHAR *p = tmp2; + for (i = 0; filtervars[i]; i++) { + if (i > 0) { + _tcscat (p, L","); + p++; + } + _stprintf (p, L"%d", *(filtervars[i])); + p += _tcslen (p); + } + if (ok == 0) { + tmp1[0] = 0; + SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, WM_GETTEXT, (WPARAM)sizeof (tmp1) / sizeof (TCHAR), (LPARAM)tmp1); + if (tmp1[0] == 0) + goto end; + } + regsetstr (fkey, tmp1, tmp2); + values_to_hw3ddlg (hDlg); + } + if (ok) { + if (wParam == IDC_FILTERPRESETDELETE && userfilter) { + regdelete (fkey, tmp1); + values_to_hw3ddlg (hDlg); + } else if (wParam == IDC_FILTERPRESETLOAD) { + TCHAR *s = tmp2; + TCHAR *t; + + load = 1; + _tcscat (s, L","); + t = _tcschr (s, ','); + *t++ = 0; + for (i = 0; filtervars[i]; i++) { + *(filtervars[i]) = _tstol(s); + if (filtervars2[i]) + *(filtervars2[i]) = *(filtervars[i]); + s = t; + t = _tcschr (s, ','); + if (!t) + break; + *t++ = 0; + } + } } - regsetstr (fkey, tmp1, tmp2); - values_to_hw3ddlg (hDlg); - } - if (ok) { - if (wParam == IDC_FILTERPRESETDELETE && userfilter) { - regdelete (fkey, tmp1); - values_to_hw3ddlg (hDlg); - } else if (wParam == IDC_FILTERPRESETLOAD) { - TCHAR *s = tmp2; - TCHAR *t; - - load = 1; - _tcscat (s, L","); - t = _tcschr (s, ','); - *t++ = 0; - for (i = 0; filtervars[i]; i++) { - *(filtervars[i]) = _tstol(s); - if (filtervars2[i]) - *(filtervars2[i]) = *(filtervars[i]); - s = t; - t = _tcschr (s, ','); - if (!t) - break; - *t++ = 0; - } - } - } end: - regclosetree (fkey); - enable_for_hw3ddlg (hDlg); - if (load) { - values_to_hw3ddlg (hDlg); - SendMessage (hDlg, WM_HSCROLL, 0, 0); - } + regclosetree (fkey); + enable_for_hw3ddlg (hDlg); + if (load) { + values_to_hw3ddlg (hDlg); + SendMessage (hDlg, WM_HSCROLL, 0, 0); + } } static void filter_handle (HWND hDlg) { - LRESULT item = SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR) { - TCHAR tmp[MAX_DPATH]; - int of = workprefs.gfx_filter; - int off = workprefs.gfx_filter_filtermode; - tmp[0] = 0; - SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_GETLBTEXT, (WPARAM)item, (LPARAM)tmp); - workprefs.gfx_filtershader[0] = 0; - workprefs.gfx_filter = 0; - if (item > 0) { - item--; - if (item > UAE_FILTER_PAL) { - item = UAE_FILTER_DIRECT3D - 1; - _stprintf (workprefs.gfx_filtershader, L"%s.fx", tmp + 5); - } - workprefs.gfx_filter = uaefilters[item].type; - item = SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR) - workprefs.gfx_filter_filtermode = (int)item; - if (of != workprefs.gfx_filter || off != workprefs.gfx_filter_filtermode) { - values_to_hw3ddlg (hDlg); - hw3d_changed = 1; - } + LRESULT item = SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR) { + TCHAR tmp[MAX_DPATH]; + int of = workprefs.gfx_filter; + int off = workprefs.gfx_filter_filtermode; + tmp[0] = 0; + SendDlgItemMessage (hDlg, IDC_FILTERMODE, CB_GETLBTEXT, (WPARAM)item, (LPARAM)tmp); + workprefs.gfx_filtershader[0] = 0; + workprefs.gfx_filter = 0; + if (item > 0) { + item--; + if (item > UAE_FILTER_PAL) { + item = UAE_FILTER_DIRECT3D - 1; + _stprintf (workprefs.gfx_filtershader, L"%s.fx", tmp + 5); + } + workprefs.gfx_filter = uaefilters[item].type; + item = SendDlgItemMessage (hDlg, IDC_FILTERFILTER, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR) + workprefs.gfx_filter_filtermode = (int)item; + if (of != workprefs.gfx_filter || off != workprefs.gfx_filter_filtermode) { + values_to_hw3ddlg (hDlg); + hw3d_changed = 1; + } + } + if (workprefs.gfx_filter == 0) + workprefs.gfx_filter_autoscale = 0; } - if (workprefs.gfx_filter == 0) - workprefs.gfx_filter_autoscale = 0; - } - enable_for_hw3ddlg (hDlg); - updatedisplayarea (); + enable_for_hw3ddlg (hDlg); + updatedisplayarea (); } static INT_PTR CALLBACK hw3dDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive; - LRESULT item; - TCHAR tmp[100]; + static int recursive; + LRESULT item; + TCHAR tmp[100]; - switch (msg) - { + switch (msg) + { case WM_INITDIALOG: - pages[HW3D_ID] = hDlg; - currentpage = HW3D_ID; - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"4:3"); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"5:4"); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"15:9"); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"16:9"); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"16:10"); - - SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_RESETCONTENT, 0, 0); - WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)tmp); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)L"VGA"); - SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)L"TV"); - - enable_for_hw3ddlg (hDlg); + pages[HW3D_ID] = hDlg; + currentpage = HW3D_ID; + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString (IDS_AUTOMATIC, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"4:3"); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"5:4"); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"15:9"); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"16:9"); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_ADDSTRING, 0, (LPARAM)L"16:10"); + + SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_RESETCONTENT, 0, 0); + WIN32GUI_LoadUIString (IDS_DISABLED, tmp, sizeof tmp / sizeof (TCHAR)); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)tmp); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)L"VGA"); + SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_ADDSTRING, 0, (LPARAM)L"TV"); + + enable_for_hw3ddlg (hDlg); case WM_USER: - if(recursive > 0) - break; - recursive++; - enable_for_hw3ddlg (hDlg); - values_to_hw3ddlg (hDlg); - recursive--; - return TRUE; - case WM_COMMAND: - if(recursive > 0) - break; - recursive++; - switch (wParam) - { - case IDC_FILTERDEFAULT: - currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = 0; - currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = 0; - currprefs.gfx_filter_horiz_offset = workprefs.gfx_filter_horiz_offset = 0; - currprefs.gfx_filter_vert_offset = workprefs.gfx_filter_vert_offset = 0; + if(recursive > 0) + break; + recursive++; + enable_for_hw3ddlg (hDlg); values_to_hw3ddlg (hDlg); - updatedisplayarea (); - WIN32GFX_WindowMove (); - break; - case IDC_FILTERPRESETLOAD: - case IDC_FILTERPRESETSAVE: - case IDC_FILTERPRESETDELETE: recursive--; - filter_preset (hDlg, wParam); + return TRUE; + case WM_COMMAND: + if(recursive > 0) + break; recursive++; - break; - case IDC_FILTERKEEPASPECT: + switch (wParam) { - if (IsDlgButtonChecked (hDlg, IDC_FILTERKEEPASPECT)) - currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = 1; - else - currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = 0; - enable_for_hw3ddlg (hDlg); - values_to_hw3ddlg (hDlg); - updatedisplayarea (); - WIN32GFX_WindowMove (); - } - break; - default: - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { - switch (LOWORD (wParam)) - { - case IDC_FILTERAUTOSCALE: - item = SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR) { - workprefs.gfx_filter_autoscale = item; - if (workprefs.gfx_filter_autoscale && workprefs.gfx_filter == 0) { - if (D3D_goodenough ()) { - workprefs.gfx_filter = 2; // D3D - workprefs.gfx_filter_filtermode = 2; - } else { - workprefs.gfx_filter = 1; // NULL - } - } - values_to_hw3ddlg (hDlg); - enable_for_hw3ddlg (hDlg); - } - break; - case IDC_FILTERXTRA: - values_to_hw3ddlg (hDlg); - break; - case IDC_FILTERPRESETS: - filter_preset (hDlg, LOWORD (wParam)); - break; - case IDC_FILTERSLR: - item = SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_GETCURSEL, 0, 0L); - if (item != CB_ERR) { - currprefs.gfx_filter_scanlineratio = workprefs.gfx_filter_scanlineratio = scanlineindexes[item]; - updatedisplayarea (); - } - break; - case IDC_FILTERMODE: - case IDC_FILTERFILTER: - filter_handle (hDlg); + case IDC_FILTERDEFAULT: + currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = 0; + currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = 0; + currprefs.gfx_filter_horiz_offset = workprefs.gfx_filter_horiz_offset = 0; + currprefs.gfx_filter_vert_offset = workprefs.gfx_filter_vert_offset = 0; values_to_hw3ddlg (hDlg); - break; - case IDC_FILTERHZMULT: - currprefs.gfx_filter_horiz_zoom_mult = workprefs.gfx_filter_horiz_zoom_mult = getfiltermult (hDlg, IDC_FILTERHZMULT); updatedisplayarea (); WIN32GFX_WindowMove (); break; - case IDC_FILTERVZMULT: - currprefs.gfx_filter_vert_zoom_mult = workprefs.gfx_filter_vert_zoom_mult = getfiltermult (hDlg, IDC_FILTERVZMULT); - updatedisplayarea (); - WIN32GFX_WindowMove (); + case IDC_FILTERPRESETLOAD: + case IDC_FILTERPRESETSAVE: + case IDC_FILTERPRESETDELETE: + recursive--; + filter_preset (hDlg, wParam); + recursive++; break; - case IDC_FILTERASPECT: - { - int v = SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_GETCURSEL, 0, 0L); - int v2 = 0; - if (v != CB_ERR) { - if (v == 0) - v2 = 0; - if (v == 1) - v2 = -1; - if (v == 2) - v2 = 4 * 256 + 3; - if (v == 3) - v2 = 5 * 256 + 4; - if (v == 4) - v2 = 15 * 256 + 9; - if (v == 5) - v2 = 16 * 256 + 9; - if (v == 6) - v2 = 16 * 256 + 10; - } - currprefs.gfx_filter_aspect = workprefs.gfx_filter_aspect = v2; - updatedisplayarea (); - WIN32GFX_WindowMove (); - } - break; - case IDC_FILTERASPECT2: + case IDC_FILTERKEEPASPECT: { - int v = SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_GETCURSEL, 0, 0L); - if (v != CB_ERR) - currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = v; - updatedisplayarea (); - WIN32GFX_WindowMove (); + if (IsDlgButtonChecked (hDlg, IDC_FILTERKEEPASPECT)) + currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = 1; + else + currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = 0; + enable_for_hw3ddlg (hDlg); + values_to_hw3ddlg (hDlg); + updatedisplayarea (); + WIN32GFX_WindowMove (); } break; + default: + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + switch (LOWORD (wParam)) + { + case IDC_FILTERAUTOSCALE: + item = SendDlgItemMessage (hDlg, IDC_FILTERAUTOSCALE, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR) { + workprefs.gfx_filter_autoscale = item; + if (workprefs.gfx_filter_autoscale && workprefs.gfx_filter == 0) { + if (D3D_goodenough ()) { + workprefs.gfx_filter = 2; // D3D + workprefs.gfx_filter_filtermode = 2; + } else { + workprefs.gfx_filter = 1; // NULL + } + } + values_to_hw3ddlg (hDlg); + enable_for_hw3ddlg (hDlg); + } + break; + case IDC_FILTERXTRA: + values_to_hw3ddlg (hDlg); + break; + case IDC_FILTERPRESETS: + filter_preset (hDlg, LOWORD (wParam)); + break; + case IDC_FILTERSLR: + item = SendDlgItemMessage (hDlg, IDC_FILTERSLR, CB_GETCURSEL, 0, 0L); + if (item != CB_ERR) { + currprefs.gfx_filter_scanlineratio = workprefs.gfx_filter_scanlineratio = scanlineindexes[item]; + updatedisplayarea (); + } + break; + case IDC_FILTERMODE: + case IDC_FILTERFILTER: + filter_handle (hDlg); + values_to_hw3ddlg (hDlg); + break; + case IDC_FILTERHZMULT: + currprefs.gfx_filter_horiz_zoom_mult = workprefs.gfx_filter_horiz_zoom_mult = getfiltermult (hDlg, IDC_FILTERHZMULT); + updatedisplayarea (); + WIN32GFX_WindowMove (); + break; + case IDC_FILTERVZMULT: + currprefs.gfx_filter_vert_zoom_mult = workprefs.gfx_filter_vert_zoom_mult = getfiltermult (hDlg, IDC_FILTERVZMULT); + updatedisplayarea (); + WIN32GFX_WindowMove (); + break; + case IDC_FILTERASPECT: + { + int v = SendDlgItemMessage (hDlg, IDC_FILTERASPECT, CB_GETCURSEL, 0, 0L); + int v2 = 0; + if (v != CB_ERR) { + if (v == 0) + v2 = 0; + if (v == 1) + v2 = -1; + if (v == 2) + v2 = 4 * 256 + 3; + if (v == 3) + v2 = 5 * 256 + 4; + if (v == 4) + v2 = 15 * 256 + 9; + if (v == 5) + v2 = 16 * 256 + 9; + if (v == 6) + v2 = 16 * 256 + 10; + } + currprefs.gfx_filter_aspect = workprefs.gfx_filter_aspect = v2; + updatedisplayarea (); + WIN32GFX_WindowMove (); + } + break; + case IDC_FILTERASPECT2: + { + int v = SendDlgItemMessage (hDlg, IDC_FILTERASPECT2, CB_GETCURSEL, 0, 0L); + if (v != CB_ERR) + currprefs.gfx_filter_keep_aspect = workprefs.gfx_filter_keep_aspect = v; + updatedisplayarea (); + WIN32GFX_WindowMove (); + } + break; - } + } + } + break; } + recursive--; break; - } - recursive--; - break; case WM_HSCROLL: - { - HWND hz = GetDlgItem (hDlg, IDC_FILTERHZ); - HWND vz = GetDlgItem (hDlg, IDC_FILTERVZ); - HWND h = (HWND)lParam; - - if (recursive) - break; - recursive++; - if (h == hz) { - currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = (int)SendMessage (hz, TBM_GETPOS, 0, 0); - if (workprefs.gfx_filter_keep_aspect) { - currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = currprefs.gfx_filter_horiz_zoom; - SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_zoom); - } - } else if (h == vz) { - currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = (int)SendMessage (vz, TBM_GETPOS, 0, 0); - if (workprefs.gfx_filter_keep_aspect) { - currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = currprefs.gfx_filter_vert_zoom; - SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_zoom); - } - } else { - currprefs.gfx_filter_horiz_offset = workprefs.gfx_filter_horiz_offset = (int)SendMessage (GetDlgItem (hDlg, IDC_FILTERHO), TBM_GETPOS, 0, 0); - currprefs.gfx_filter_vert_offset = workprefs.gfx_filter_vert_offset = (int)SendMessage (GetDlgItem (hDlg, IDC_FILTERVO), TBM_GETPOS, 0, 0); - } - if (filter_selected) { - int *pw = filter_selected->varw; - int *pc = filter_selected->varc; - int v = (int)SendMessage (GetDlgItem(hDlg, IDC_FILTERXL), TBM_GETPOS, 0, 0); - if (v < filter_selected->min) - v = filter_selected->min; - if (v > filter_selected->max) - v = filter_selected->max; - *pw = v; - *pc = v; - SetDlgItemInt (hDlg, IDC_FILTERXLV, v, TRUE); - } - SetDlgItemInt (hDlg, IDC_FILTERHZV, workprefs.gfx_filter_horiz_zoom, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERVZV, workprefs.gfx_filter_vert_zoom, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERHOV, workprefs.gfx_filter_horiz_offset, TRUE); - SetDlgItemInt (hDlg, IDC_FILTERVOV, workprefs.gfx_filter_vert_offset, TRUE); - init_colors (); - notice_new_xcolors (); - reset_drawing (); - updatedisplayarea (); - WIN32GFX_WindowMove (); - recursive--; - break; - } - } - return FALSE; + { + HWND hz = GetDlgItem (hDlg, IDC_FILTERHZ); + HWND vz = GetDlgItem (hDlg, IDC_FILTERVZ); + HWND h = (HWND)lParam; + + if (recursive) + break; + recursive++; + if (h == hz) { + currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = (int)SendMessage (hz, TBM_GETPOS, 0, 0); + if (workprefs.gfx_filter_keep_aspect) { + currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = currprefs.gfx_filter_horiz_zoom; + SendDlgItemMessage (hDlg, IDC_FILTERVZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_vert_zoom); + } + } else if (h == vz) { + currprefs.gfx_filter_vert_zoom = workprefs.gfx_filter_vert_zoom = (int)SendMessage (vz, TBM_GETPOS, 0, 0); + if (workprefs.gfx_filter_keep_aspect) { + currprefs.gfx_filter_horiz_zoom = workprefs.gfx_filter_horiz_zoom = currprefs.gfx_filter_vert_zoom; + SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_zoom); + } + } else { + currprefs.gfx_filter_horiz_offset = workprefs.gfx_filter_horiz_offset = (int)SendMessage (GetDlgItem (hDlg, IDC_FILTERHO), TBM_GETPOS, 0, 0); + currprefs.gfx_filter_vert_offset = workprefs.gfx_filter_vert_offset = (int)SendMessage (GetDlgItem (hDlg, IDC_FILTERVO), TBM_GETPOS, 0, 0); + } + if (filter_selected) { + int *pw = filter_selected->varw; + int *pc = filter_selected->varc; + int v = (int)SendMessage (GetDlgItem(hDlg, IDC_FILTERXL), TBM_GETPOS, 0, 0); + if (v < filter_selected->min) + v = filter_selected->min; + if (v > filter_selected->max) + v = filter_selected->max; + *pw = v; + *pc = v; + SetDlgItemInt (hDlg, IDC_FILTERXLV, v, TRUE); + } + SetDlgItemInt (hDlg, IDC_FILTERHZV, workprefs.gfx_filter_horiz_zoom, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERVZV, workprefs.gfx_filter_vert_zoom, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERHOV, workprefs.gfx_filter_horiz_offset, TRUE); + SetDlgItemInt (hDlg, IDC_FILTERVOV, workprefs.gfx_filter_vert_offset, TRUE); + init_colors (); + notice_new_xcolors (); + reset_drawing (); + updatedisplayarea (); + WIN32GFX_WindowMove (); + recursive--; + break; + } + } + return FALSE; } #endif #ifdef AVIOUTPUT static void values_to_avioutputdlg (HWND hDlg) { - TCHAR tmpstr[256]; + TCHAR tmpstr[256]; - updatewinfsmode (&workprefs); - SetDlgItemText (hDlg, IDC_AVIOUTPUT_FILETEXT, avioutput_filename); + updatewinfsmode (&workprefs); + SetDlgItemText (hDlg, IDC_AVIOUTPUT_FILETEXT, avioutput_filename); - _stprintf (tmpstr, L"%d fps", avioutput_fps); - SendMessage (GetDlgItem(hDlg, IDC_AVIOUTPUT_FPS_STATIC), WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpstr); + _stprintf (tmpstr, L"%d fps", avioutput_fps); + SendMessage (GetDlgItem(hDlg, IDC_AVIOUTPUT_FPS_STATIC), WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpstr); - _stprintf (tmpstr, L"Actual: %d x %d", workprefs.gfx_size.width, workprefs.gfx_size.height); - SendMessage (GetDlgItem(hDlg, IDC_AVIOUTPUT_DIMENSIONS_STATIC), WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpstr); + _stprintf (tmpstr, L"Actual: %d x %d", workprefs.gfx_size.width, workprefs.gfx_size.height); + SendMessage (GetDlgItem(hDlg, IDC_AVIOUTPUT_DIMENSIONS_STATIC), WM_SETTEXT, (WPARAM) 0, (LPARAM) tmpstr); - switch(avioutput_fps) - { + switch(avioutput_fps) + { case VBLANK_HZ_PAL: - CheckRadioButton (hDlg, IDC_AVIOUTPUT_PAL, IDC_AVIOUTPUT_NTSC, IDC_AVIOUTPUT_PAL); - break; + CheckRadioButton (hDlg, IDC_AVIOUTPUT_PAL, IDC_AVIOUTPUT_NTSC, IDC_AVIOUTPUT_PAL); + break; case VBLANK_HZ_NTSC: - CheckRadioButton (hDlg, IDC_AVIOUTPUT_PAL, IDC_AVIOUTPUT_NTSC, IDC_AVIOUTPUT_NTSC); - break; + CheckRadioButton (hDlg, IDC_AVIOUTPUT_PAL, IDC_AVIOUTPUT_NTSC, IDC_AVIOUTPUT_NTSC); + break; default: - CheckDlgButton (hDlg, IDC_AVIOUTPUT_PAL, BST_UNCHECKED); - CheckDlgButton (hDlg, IDC_AVIOUTPUT_NTSC, BST_UNCHECKED); - break; - } + CheckDlgButton (hDlg, IDC_AVIOUTPUT_PAL, BST_UNCHECKED); + CheckDlgButton (hDlg, IDC_AVIOUTPUT_NTSC, BST_UNCHECKED); + break; + } - CheckDlgButton (hDlg, IDC_AVIOUTPUT_FRAMELIMITER, avioutput_framelimiter ? FALSE : TRUE); - CheckDlgButton (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_nosoundoutput ? TRUE : FALSE); - CheckDlgButton (hDlg, IDC_AVIOUTPUT_ACTIVATED, avioutput_requested ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton (hDlg, IDC_SAMPLERIPPER_ACTIVATED, sampleripper_enabled ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton (hDlg, IDC_AVIOUTPUT_FRAMELIMITER, avioutput_framelimiter ? FALSE : TRUE); + CheckDlgButton (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_nosoundoutput ? TRUE : FALSE); + CheckDlgButton (hDlg, IDC_AVIOUTPUT_ACTIVATED, avioutput_requested ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton (hDlg, IDC_SAMPLERIPPER_ACTIVATED, sampleripper_enabled ? BST_CHECKED : BST_UNCHECKED); } static void values_from_avioutputdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -11215,277 +11227,277 @@ static void values_from_avioutputdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM updatewinfsmode (&workprefs); tmp = SendMessage (GetDlgItem (hDlg, IDC_AVIOUTPUT_FPS), TBM_GETPOS, 0, 0); if (tmp < 1) - tmp = 1; + tmp = 1; if (tmp != avioutput_fps) { - avioutput_fps = (int)tmp; - AVIOutput_Restart (); + avioutput_fps = (int)tmp; + AVIOutput_Restart (); } } static void enable_for_avioutputdlg(HWND hDlg) { - TCHAR tmp[1000]; + TCHAR tmp[1000]; #if defined (PROWIZARD) - ew (hDlg, IDC_PROWIZARD, TRUE); - if (full_property_sheet) - ew (hDlg, IDC_PROWIZARD, FALSE); + ew (hDlg, IDC_PROWIZARD, TRUE); + if (full_property_sheet) + ew (hDlg, IDC_PROWIZARD, FALSE); #endif - ew (hDlg, IDC_SCREENSHOT, full_property_sheet ? FALSE : TRUE); - ew (hDlg, IDC_SAMPLERIPPER_ACTIVATED, full_property_sheet ? FALSE : TRUE); - - ew (hDlg, IDC_AVIOUTPUT_PAL, TRUE); - ew (hDlg, IDC_AVIOUTPUT_NTSC, TRUE); - ew (hDlg, IDC_AVIOUTPUT_FPS, TRUE); - ew (hDlg, IDC_AVIOUTPUT_FILE, TRUE); - - if(workprefs.produce_sound < 2) { - ew (hDlg, IDC_AVIOUTPUT_AUDIO, FALSE); - ew (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC, FALSE); - avioutput_audio = 0; - } else { - ew (hDlg, IDC_AVIOUTPUT_AUDIO, TRUE); - ew (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC, TRUE); - } - - if (avioutput_audio == AVIAUDIO_WAV) { - _tcscpy (tmp, L"Wave (internal)"); - } else { - avioutput_audio = AVIOutput_GetAudioCodec (tmp, sizeof tmp / sizeof (TCHAR)); - } - if(!avioutput_audio) { - CheckDlgButton (hDlg, IDC_AVIOUTPUT_AUDIO, BST_UNCHECKED); - WIN32GUI_LoadUIString (IDS_AVIOUTPUT_NOCODEC, tmp, sizeof tmp / sizeof (TCHAR)); - } - SetWindowText (GetDlgItem (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC), tmp); - - if (avioutput_audio != AVIAUDIO_WAV) - avioutput_video = AVIOutput_GetVideoCodec (tmp, sizeof tmp / sizeof (TCHAR)); - if(!avioutput_video) { - CheckDlgButton (hDlg, IDC_AVIOUTPUT_VIDEO, BST_UNCHECKED); - WIN32GUI_LoadUIString (IDS_AVIOUTPUT_NOCODEC, tmp, sizeof tmp / sizeof (TCHAR)); - } - SetWindowText (GetDlgItem (hDlg, IDC_AVIOUTPUT_VIDEO_STATIC), tmp); - - ew (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_framelimiter ? TRUE : FALSE); - - if (!avioutput_framelimiter) - avioutput_nosoundoutput = 1; - CheckDlgButton (hDlg, IDC_AVIOUTPUT_FRAMELIMITER, avioutput_framelimiter ? FALSE : TRUE); - CheckDlgButton (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_nosoundoutput ? TRUE : FALSE); - - ew (hDlg, IDC_AVIOUTPUT_ACTIVATED, (!avioutput_audio && !avioutput_video) ? FALSE : TRUE); - - ew (hDlg, IDC_INPREC_RECORD, input_recording >= 0); - CheckDlgButton (hDlg, IDC_INPREC_RECORD, input_recording > 0 ? BST_CHECKED : BST_UNCHECKED); - ew (hDlg, IDC_INPREC_PLAY, input_recording <= 0); - CheckDlgButton (hDlg, IDC_INPREC_PLAY, input_recording < 0 ? BST_CHECKED : BST_UNCHECKED); - ew (hDlg, IDC_INPREC_PLAYMODE, input_recording == 0); + ew (hDlg, IDC_SCREENSHOT, full_property_sheet ? FALSE : TRUE); + ew (hDlg, IDC_SAMPLERIPPER_ACTIVATED, full_property_sheet ? FALSE : TRUE); + + ew (hDlg, IDC_AVIOUTPUT_PAL, TRUE); + ew (hDlg, IDC_AVIOUTPUT_NTSC, TRUE); + ew (hDlg, IDC_AVIOUTPUT_FPS, TRUE); + ew (hDlg, IDC_AVIOUTPUT_FILE, TRUE); + + if(workprefs.produce_sound < 2) { + ew (hDlg, IDC_AVIOUTPUT_AUDIO, FALSE); + ew (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC, FALSE); + avioutput_audio = 0; + } else { + ew (hDlg, IDC_AVIOUTPUT_AUDIO, TRUE); + ew (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC, TRUE); + } + + if (avioutput_audio == AVIAUDIO_WAV) { + _tcscpy (tmp, L"Wave (internal)"); + } else { + avioutput_audio = AVIOutput_GetAudioCodec (tmp, sizeof tmp / sizeof (TCHAR)); + } + if(!avioutput_audio) { + CheckDlgButton (hDlg, IDC_AVIOUTPUT_AUDIO, BST_UNCHECKED); + WIN32GUI_LoadUIString (IDS_AVIOUTPUT_NOCODEC, tmp, sizeof tmp / sizeof (TCHAR)); + } + SetWindowText (GetDlgItem (hDlg, IDC_AVIOUTPUT_AUDIO_STATIC), tmp); + + if (avioutput_audio != AVIAUDIO_WAV) + avioutput_video = AVIOutput_GetVideoCodec (tmp, sizeof tmp / sizeof (TCHAR)); + if(!avioutput_video) { + CheckDlgButton (hDlg, IDC_AVIOUTPUT_VIDEO, BST_UNCHECKED); + WIN32GUI_LoadUIString (IDS_AVIOUTPUT_NOCODEC, tmp, sizeof tmp / sizeof (TCHAR)); + } + SetWindowText (GetDlgItem (hDlg, IDC_AVIOUTPUT_VIDEO_STATIC), tmp); + + ew (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_framelimiter ? TRUE : FALSE); + + if (!avioutput_framelimiter) + avioutput_nosoundoutput = 1; + CheckDlgButton (hDlg, IDC_AVIOUTPUT_FRAMELIMITER, avioutput_framelimiter ? FALSE : TRUE); + CheckDlgButton (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT, avioutput_nosoundoutput ? TRUE : FALSE); + + ew (hDlg, IDC_AVIOUTPUT_ACTIVATED, (!avioutput_audio && !avioutput_video) ? FALSE : TRUE); + + ew (hDlg, IDC_INPREC_RECORD, input_recording >= 0); + CheckDlgButton (hDlg, IDC_INPREC_RECORD, input_recording > 0 ? BST_CHECKED : BST_UNCHECKED); + ew (hDlg, IDC_INPREC_PLAY, input_recording <= 0); + CheckDlgButton (hDlg, IDC_INPREC_PLAY, input_recording < 0 ? BST_CHECKED : BST_UNCHECKED); + ew (hDlg, IDC_INPREC_PLAYMODE, input_recording == 0); } static INT_PTR CALLBACK AVIOutputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - TCHAR tmp[1000]; + static int recursive = 0; + TCHAR tmp[1000]; - switch(msg) - { + switch(msg) + { case WM_INITDIALOG: - pages[AVIOUTPUT_ID] = hDlg; - currentpage = AVIOUTPUT_ID; - AVIOutput_GetSettings (); - enable_for_avioutputdlg (hDlg); - SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETRANGE, TRUE, MAKELONG(1, VBLANK_HZ_NTSC)); - SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, avioutput_fps); - SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); - if (!avioutput_filename[0]) { - fetch_path (L"VideoPath", avioutput_filename, sizeof (avioutput_filename) / sizeof (TCHAR)); - _tcscat (avioutput_filename, L"output.avi"); - } + pages[AVIOUTPUT_ID] = hDlg; + currentpage = AVIOUTPUT_ID; + AVIOutput_GetSettings (); + enable_for_avioutputdlg (hDlg); + SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETRANGE, TRUE, MAKELONG(1, VBLANK_HZ_NTSC)); + SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, avioutput_fps); + SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); + if (!avioutput_filename[0]) { + fetch_path (L"VideoPath", avioutput_filename, sizeof (avioutput_filename) / sizeof (TCHAR)); + _tcscat (avioutput_filename, L"output.avi"); + } case WM_USER: - recursive++; - values_to_avioutputdlg (hDlg); - enable_for_avioutputdlg (hDlg); - recursive--; - return TRUE; + recursive++; + values_to_avioutputdlg (hDlg); + enable_for_avioutputdlg (hDlg); + recursive--; + return TRUE; case WM_HSCROLL: - { - recursive++; - values_from_avioutputdlg (hDlg, msg, wParam, lParam); - values_to_avioutputdlg (hDlg); - enable_for_avioutputdlg (hDlg); - recursive--; - return TRUE; - } + { + recursive++; + values_from_avioutputdlg (hDlg, msg, wParam, lParam); + values_to_avioutputdlg (hDlg); + enable_for_avioutputdlg (hDlg); + recursive--; + return TRUE; + } case WM_COMMAND: - if(recursive > 0) - break; + if(recursive > 0) + break; - recursive++; + recursive++; - switch(wParam) - { + switch(wParam) + { case IDC_AVIOUTPUT_FRAMELIMITER: - avioutput_framelimiter = IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_FRAMELIMITER) ? 0 : 1; - AVIOutput_SetSettings (); - break; + avioutput_framelimiter = IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_FRAMELIMITER) ? 0 : 1; + AVIOutput_SetSettings (); + break; case IDC_AVIOUTPUT_NOSOUNDOUTPUT: - avioutput_nosoundoutput = IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT) ? 1 : 0; - AVIOutput_SetSettings (); - break; + avioutput_nosoundoutput = IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_NOSOUNDOUTPUT) ? 1 : 0; + AVIOutput_SetSettings (); + break; case IDC_INPREC_PLAYMODE: - break; + break; case IDC_INPREC_RECORD: - if (input_recording) - inprec_close (); - else - DiskSelection (hDlg, wParam, 16, &workprefs, NULL); - break; + if (input_recording) + inprec_close (); + else + DiskSelection (hDlg, wParam, 16, &workprefs, NULL); + break; case IDC_INPREC_PLAY: - if (input_recording) - inprec_close (); - else - DiskSelection (hDlg, wParam, 15, &workprefs, NULL); - break; + if (input_recording) + inprec_close (); + else + DiskSelection (hDlg, wParam, 15, &workprefs, NULL); + break; #ifdef PROWIZARD case IDC_PROWIZARD: - moduleripper (); - break; + moduleripper (); + break; #endif case IDC_SAMPLERIPPER_ACTIVATED: - sampleripper_enabled = !sampleripper_enabled; - audio_sampleripper (-1); - break; + sampleripper_enabled = !sampleripper_enabled; + audio_sampleripper (-1); + break; case IDC_AVIOUTPUT_ACTIVATED: - avioutput_requested = !avioutput_requested; - SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); - if (!avioutput_requested) - AVIOutput_End (); - break; + avioutput_requested = !avioutput_requested; + SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); + if (!avioutput_requested) + AVIOutput_End (); + break; case IDC_SCREENSHOT: - screenshot(1, 0); - break; + screenshot(1, 0); + break; case IDC_AVIOUTPUT_PAL: - SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, VBLANK_HZ_PAL); - SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); - break; + SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, VBLANK_HZ_PAL); + SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); + break; case IDC_AVIOUTPUT_NTSC: - SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, VBLANK_HZ_NTSC); - SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); - break; + SendDlgItemMessage (hDlg, IDC_AVIOUTPUT_FPS, TBM_SETPOS, TRUE, VBLANK_HZ_NTSC); + SendMessage (hDlg, WM_HSCROLL, (WPARAM) NULL, (LPARAM) NULL); + break; case IDC_AVIOUTPUT_AUDIO: - { - if (avioutput_enabled) - AVIOutput_End (); - if(IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_AUDIO) == BST_CHECKED) { - avioutput_audio = AVIOutput_ChooseAudioCodec (hDlg, tmp, sizeof tmp / sizeof (TCHAR)); - enable_for_avioutputdlg (hDlg); - } else { - avioutput_audio = 0; - } - break; - } + { + if (avioutput_enabled) + AVIOutput_End (); + if(IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_AUDIO) == BST_CHECKED) { + avioutput_audio = AVIOutput_ChooseAudioCodec (hDlg, tmp, sizeof tmp / sizeof (TCHAR)); + enable_for_avioutputdlg (hDlg); + } else { + avioutput_audio = 0; + } + break; + } case IDC_AVIOUTPUT_VIDEO: - { - if (avioutput_enabled) - AVIOutput_End (); - if(IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_VIDEO) == BST_CHECKED) { - avioutput_video = AVIOutput_ChooseVideoCodec (hDlg, tmp, sizeof tmp / sizeof (TCHAR)); - if (avioutput_audio = AVIAUDIO_WAV) - avioutput_audio = 0; - enable_for_avioutputdlg (hDlg); - } else { - avioutput_video = 0; - } - enable_for_avioutputdlg (hDlg); - break; + { + if (avioutput_enabled) + AVIOutput_End (); + if(IsDlgButtonChecked (hDlg, IDC_AVIOUTPUT_VIDEO) == BST_CHECKED) { + avioutput_video = AVIOutput_ChooseVideoCodec (hDlg, tmp, sizeof tmp / sizeof (TCHAR)); + if (avioutput_audio = AVIAUDIO_WAV) + avioutput_audio = 0; + enable_for_avioutputdlg (hDlg); + } else { + avioutput_video = 0; + } + enable_for_avioutputdlg (hDlg); + break; + } + + case IDC_AVIOUTPUT_FILE: + { + OPENFILENAME ofn; + + ZeroMemory (&ofn, sizeof (OPENFILENAME)); + ofn.lStructSize = sizeof (OPENFILENAME); + ofn.hwndOwner = hDlg; + ofn.hInstance = hInst; + ofn.Flags = OFN_EXTENSIONDIFFERENT | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR; + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 0; + ofn.lpstrFile = avioutput_filename; + ofn.nMaxFile = MAX_DPATH; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.lpfnHook = NULL; + ofn.lpTemplateName = NULL; + ofn.lCustData = 0; + ofn.lpstrFilter = L"Video Clip (*.avi)\0*.avi\0Wave Sound (*.wav)\0"; + + if(!GetSaveFileName (&ofn)) + break; + if (ofn.nFilterIndex == 2) { + avioutput_audio = AVIAUDIO_WAV; + avioutput_video = 0; + if (_tcslen (avioutput_filename) > 4 && !_tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, L".avi")) + _tcscpy (avioutput_filename + _tcslen (avioutput_filename) - 4, L".wav"); + } + break; + } + } - case IDC_AVIOUTPUT_FILE: - { - OPENFILENAME ofn; - - ZeroMemory (&ofn, sizeof (OPENFILENAME)); - ofn.lStructSize = sizeof (OPENFILENAME); - ofn.hwndOwner = hDlg; - ofn.hInstance = hInst; - ofn.Flags = OFN_EXTENSIONDIFFERENT | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 0; - ofn.lpstrFile = avioutput_filename; - ofn.nMaxFile = MAX_DPATH; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.lpfnHook = NULL; - ofn.lpTemplateName = NULL; - ofn.lCustData = 0; - ofn.lpstrFilter = L"Video Clip (*.avi)\0*.avi\0Wave Sound (*.wav)\0"; - - if(!GetSaveFileName (&ofn)) - break; - if (ofn.nFilterIndex == 2) { - avioutput_audio = AVIAUDIO_WAV; - avioutput_video = 0; - if (_tcslen (avioutput_filename) > 4 && !_tcsicmp (avioutput_filename + _tcslen (avioutput_filename) - 4, L".avi")) - _tcscpy (avioutput_filename + _tcslen (avioutput_filename) - 4, L".wav"); - } - break; - } - - } - - values_from_avioutputdlg (hDlg, msg, wParam, lParam); - values_to_avioutputdlg (hDlg); - enable_for_avioutputdlg (hDlg); - - recursive--; - - return TRUE; + values_from_avioutputdlg (hDlg, msg, wParam, lParam); + values_to_avioutputdlg (hDlg); + enable_for_avioutputdlg (hDlg); + + recursive--; + + return TRUE; } return FALSE; } #endif struct GUIPAGE { - DLGPROC dlgproc; - LPCTSTR title; - LPCTSTR icon; - HTREEITEM tv; - int himg; - int idx; - const TCHAR *help; - HACCEL accel; - int fullpanel; - struct newresource *nres; + DLGPROC dlgproc; + LPCTSTR title; + LPCTSTR icon; + HTREEITEM tv; + int himg; + int idx; + const TCHAR *help; + HACCEL accel; + int fullpanel; + struct newresource *nres; }; static int GetPanelRect (HWND hDlg, RECT *r) { - RECT rect; - if (!GetWindowRect (guiDlg, &rect)) - return 0; - if (!GetWindowRect (hDlg, r)) - return 0; - r->top -= rect.top; - r->left -= rect.left; - r->right -= rect.left; - r->bottom -= rect.top; - return 1; + RECT rect; + if (!GetWindowRect (guiDlg, &rect)) + return 0; + if (!GetWindowRect (hDlg, r)) + return 0; + r->top -= rect.top; + r->left -= rect.left; + r->right -= rect.left; + r->bottom -= rect.top; + return 1; } static int ToolTipImageIDs[] = { 1, IDB_XARCADE, -1 }; @@ -11493,196 +11505,196 @@ static int ToolTipImageIDs[] = { 1, IDB_XARCADE, -1 }; static WNDPROC ToolTipWndProcOld; static LRESULT FAR PASCAL ToolTipWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - RECT r1; - POINT p1; - PAINTSTRUCT ps; - HBITMAP bm; - BITMAP binfo; - HDC memdc; - int w, h, i; - - for (i = 0; ToolTipHWNDS2[i].hwnd; i++) { - if (hwnd == ToolTipHWNDS2[i].hwnd) - break; - } - if (!ToolTipHWNDS2[i].hwnd) - return CallWindowProc (ToolTipHWNDS2[i].proc, hwnd, message, wParam, lParam); + RECT r1; + POINT p1; + PAINTSTRUCT ps; + HBITMAP bm; + BITMAP binfo; + HDC memdc; + int w, h, i; - switch (message) - { + for (i = 0; ToolTipHWNDS2[i].hwnd; i++) { + if (hwnd == ToolTipHWNDS2[i].hwnd) + break; + } + if (!ToolTipHWNDS2[i].hwnd) + return CallWindowProc (ToolTipHWNDS2[i].proc, hwnd, message, wParam, lParam); + + switch (message) + { case WM_WINDOWPOSCHANGED: - bm = LoadBitmap (hInst, MAKEINTRESOURCE (ToolTipHWNDS2[i].imageid)); - GetObject (bm, sizeof (binfo), &binfo); - w = binfo.bmWidth; - h = binfo.bmHeight; - GetWindowRect (hwnd, &r1); - GetCursorPos (&p1); - r1.right = r1.left + w; - r1.bottom = r1.top + h; - MoveWindow (hwnd, r1.left, r1.top, r1.right - r1.left, r1.bottom - r1.top, TRUE); - DeleteObject (bm); - return 0; + bm = LoadBitmap (hInst, MAKEINTRESOURCE (ToolTipHWNDS2[i].imageid)); + GetObject (bm, sizeof (binfo), &binfo); + w = binfo.bmWidth; + h = binfo.bmHeight; + GetWindowRect (hwnd, &r1); + GetCursorPos (&p1); + r1.right = r1.left + w; + r1.bottom = r1.top + h; + MoveWindow (hwnd, r1.left, r1.top, r1.right - r1.left, r1.bottom - r1.top, TRUE); + DeleteObject (bm); + return 0; case WM_PAINT: - bm = LoadBitmap (hInst, MAKEINTRESOURCE (ToolTipHWNDS2[i].imageid)); - GetObject (bm, sizeof (binfo), &binfo); - w = binfo.bmWidth; - h = binfo.bmHeight; - GetWindowRect (hwnd, &r1); - GetCursorPos (&p1); - r1.right = r1.left + w; - r1.bottom = r1.top + h; - BeginPaint (hwnd, &ps); - memdc = CreateCompatibleDC (ps.hdc); - SelectObject (memdc, bm); - ShowWindow (hwnd, SW_SHOWNA); - MoveWindow (hwnd, r1.left, r1.top, r1.right - r1.left, r1.bottom - r1.top, TRUE); - SetBkMode (ps.hdc, TRANSPARENT); - BitBlt (ps.hdc, 0, 0, w, h, memdc, 0, 0, SRCCOPY); - DeleteObject (bm); - EndPaint (hwnd, &ps); - DeleteDC (memdc); - return FALSE; + bm = LoadBitmap (hInst, MAKEINTRESOURCE (ToolTipHWNDS2[i].imageid)); + GetObject (bm, sizeof (binfo), &binfo); + w = binfo.bmWidth; + h = binfo.bmHeight; + GetWindowRect (hwnd, &r1); + GetCursorPos (&p1); + r1.right = r1.left + w; + r1.bottom = r1.top + h; + BeginPaint (hwnd, &ps); + memdc = CreateCompatibleDC (ps.hdc); + SelectObject (memdc, bm); + ShowWindow (hwnd, SW_SHOWNA); + MoveWindow (hwnd, r1.left, r1.top, r1.right - r1.left, r1.bottom - r1.top, TRUE); + SetBkMode (ps.hdc, TRANSPARENT); + BitBlt (ps.hdc, 0, 0, w, h, memdc, 0, 0, SRCCOPY); + DeleteObject (bm); + EndPaint (hwnd, &ps); + DeleteDC (memdc); + return FALSE; case WM_PRINT: - PostMessage (hwnd, WM_PAINT, 0, 0); - return TRUE; - } - return CallWindowProc (ToolTipHWNDS2[i].proc, hwnd, message, wParam, lParam); + PostMessage (hwnd, WM_PAINT, 0, 0); + return TRUE; + } + return CallWindowProc (ToolTipHWNDS2[i].proc, hwnd, message, wParam, lParam); } static int ignorewindows[] = { - IDD_FLOPPY, IDC_DF0TEXT, IDC_DF1TEXT, IDC_DF2TEXT, IDC_DF3TEXT, IDC_CREATE_NAME, - -1, - IDD_QUICKSTART, IDC_DF0TEXTQ, IDC_DF1TEXTQ, IDC_QUICKSTART_HOSTCONFIG, - -1, - IDD_AVIOUTPUT, IDC_AVIOUTPUT_FILETEXT, IDC_AVIOUTPUT_VIDEO_STATIC, IDC_AVIOUTPUT_AUDIO_STATIC, - -1, - IDD_DISK, IDC_DISKTEXT, IDC_DISKLIST, - -1, - IDD_DISPLAY, IDC_DISPLAYSELECT, - -1, - IDD_FILTER, IDC_FILTERPRESETS, - -1, - IDD_HARDDISK, IDC_VOLUMELIST, - -1, - IDD_INPUT, IDC_INPUTDEVICE, IDC_INPUTLIST, IDC_INPUTAMIGA, - -1, - IDD_KICKSTART, IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, IDC_FLASHFILE, - -1, - IDD_LOADSAVE, IDC_CONFIGTREE, IDC_EDITNAME, IDC_EDITDESCRIPTION, IDC_CONFIGLINK, IDC_EDITPATH, - -1, - IDD_MISC1, IDC_LANGUAGE, - -1, - IDD_PATHS, IDC_PATHS_ROM, IDC_PATHS_CONFIG, IDC_PATHS_SCREENSHOT, IDC_PATHS_SAVESTATE, IDC_PATHS_AVIOUTPUT, IDC_PATHS_SAVEIMAGE, IDC_PATHS_RIP, - -1, - IDD_IOPORTS, IDC_PRINTERLIST, IDC_PS_PARAMS, IDC_SERIAL, IDC_MIDIOUTLIST, IDC_MIDIINLIST, - -1, - IDD_SOUND, IDC_SOUNDCARDLIST, IDC_SOUNDDRIVESELECT, - -1, - 0 + IDD_FLOPPY, IDC_DF0TEXT, IDC_DF1TEXT, IDC_DF2TEXT, IDC_DF3TEXT, IDC_CREATE_NAME, + -1, + IDD_QUICKSTART, IDC_DF0TEXTQ, IDC_DF1TEXTQ, IDC_QUICKSTART_HOSTCONFIG, + -1, + IDD_AVIOUTPUT, IDC_AVIOUTPUT_FILETEXT, IDC_AVIOUTPUT_VIDEO_STATIC, IDC_AVIOUTPUT_AUDIO_STATIC, + -1, + IDD_DISK, IDC_DISKTEXT, IDC_DISKLIST, + -1, + IDD_DISPLAY, IDC_DISPLAYSELECT, + -1, + IDD_FILTER, IDC_FILTERPRESETS, + -1, + IDD_HARDDISK, IDC_VOLUMELIST, + -1, + IDD_INPUT, IDC_INPUTDEVICE, IDC_INPUTLIST, IDC_INPUTAMIGA, + -1, + IDD_KICKSTART, IDC_ROMFILE, IDC_ROMFILE2, IDC_CARTFILE, IDC_FLASHFILE, + -1, + IDD_LOADSAVE, IDC_CONFIGTREE, IDC_EDITNAME, IDC_EDITDESCRIPTION, IDC_CONFIGLINK, IDC_EDITPATH, + -1, + IDD_MISC1, IDC_LANGUAGE, + -1, + IDD_PATHS, IDC_PATHS_ROM, IDC_PATHS_CONFIG, IDC_PATHS_SCREENSHOT, IDC_PATHS_SAVESTATE, IDC_PATHS_AVIOUTPUT, IDC_PATHS_SAVEIMAGE, IDC_PATHS_RIP, + -1, + IDD_IOPORTS, IDC_PRINTERLIST, IDC_PS_PARAMS, IDC_SERIAL, IDC_MIDIOUTLIST, IDC_MIDIINLIST, + -1, + IDD_SOUND, IDC_SOUNDCARDLIST, IDC_SOUNDDRIVESELECT, + -1, + 0 }; static BOOL CALLBACK childenumproc (HWND hwnd, LPARAM lParam) { - int i; - TOOLINFO ti; - TCHAR tmp[MAX_DPATH]; - TCHAR *p; - LRESULT v; - - if (GetParent (hwnd) != panelDlg) - return 1; - i = 0; - while (ignorewindows[i]) { - if (ignorewindows[i] == (int)lParam) { - int dlgid = GetDlgCtrlID (hwnd); - i++; - while (ignorewindows[i] > 0) { - if (dlgid == ignorewindows[i]) - return 1; - i++; - } - break; - } else { - while (ignorewindows[i++] > 0); - } - } - tmp[0] = 0; - SendMessage (hwnd, WM_GETTEXT, (WPARAM)sizeof (tmp) / sizeof (TCHAR), (LPARAM)tmp); - p = _tcschr (tmp, '['); - if (_tcslen (tmp) > 0 && p && _tcslen (p) > 2 && p[1] == ']') { - int imageid = 0; - *p++ = 0; - *p++ = 0; - if (p[0] == ' ') - *p++; - if (p[0] == '#') - imageid = _tstol (p + 1); - tmp[_tcslen (tmp) - 1] = 0; - ti.cbSize = sizeof (TOOLINFO); - ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; - ti.hwnd = GetParent (hwnd); - ti.hinst = hInst; - ti.uId = (UINT_PTR)hwnd; - ti.lpszText = p; - if (imageid > 0) { - int idx, i; + int i; + TOOLINFO ti; + TCHAR tmp[MAX_DPATH]; + TCHAR *p; + LRESULT v; - idx = 0; - while (ToolTipHWNDS2[idx].hwnd) - idx++; - for (i = 0; ToolTipImageIDs[i] >= 0; i += 2) { - if (ToolTipImageIDs[i] == imageid) - break; - } - if (ToolTipImageIDs[i] >= 0 && idx < MAX_IMAGETOOLTIPS) { - HWND ToolTipHWND2 = CreateWindowEx (WS_EX_TOPMOST, - TOOLTIPS_CLASS, NULL, - WS_POPUP | TTS_NOPREFIX, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - panelDlg, NULL, hInst, NULL); - ToolTipHWNDS2[idx].hwnd = ToolTipHWND2; - ToolTipHWNDS2[idx+1].hwnd = NULL; - ToolTipHWNDS2[idx].proc = (WNDPROC)GetWindowLongPtr (ToolTipHWND2, GWLP_WNDPROC); - ToolTipHWNDS2[idx].imageid = ToolTipImageIDs[i + 1]; - SetWindowLongPtr (ToolTipHWND2, GWLP_WNDPROC, (LONG_PTR)ToolTipWndProc); - SetWindowPos (ToolTipHWND2, HWND_TOPMOST, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - SendMessage (ToolTipHWND2, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)MAKELONG(20000, 0)); - SendMessage (ToolTipHWND2, TTM_SETMAXTIPWIDTH, 0, 400); + if (GetParent (hwnd) != panelDlg) + return 1; + i = 0; + while (ignorewindows[i]) { + if (ignorewindows[i] == (int)lParam) { + int dlgid = GetDlgCtrlID (hwnd); + i++; + while (ignorewindows[i] > 0) { + if (dlgid == ignorewindows[i]) + return 1; + i++; + } + break; + } else { + while (ignorewindows[i++] > 0); + } + } + tmp[0] = 0; + SendMessage (hwnd, WM_GETTEXT, (WPARAM)sizeof (tmp) / sizeof (TCHAR), (LPARAM)tmp); + p = _tcschr (tmp, '['); + if (_tcslen (tmp) > 0 && p && _tcslen (p) > 2 && p[1] == ']') { + int imageid = 0; + *p++ = 0; + *p++ = 0; + if (p[0] == ' ') + *p++; + if (p[0] == '#') + imageid = _tstol (p + 1); + tmp[_tcslen (tmp) - 1] = 0; + ti.cbSize = sizeof (TOOLINFO); + ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; + ti.hwnd = GetParent (hwnd); + ti.hinst = hInst; + ti.uId = (UINT_PTR)hwnd; + ti.lpszText = p; + if (imageid > 0) { + int idx, i; + + idx = 0; + while (ToolTipHWNDS2[idx].hwnd) + idx++; + for (i = 0; ToolTipImageIDs[i] >= 0; i += 2) { + if (ToolTipImageIDs[i] == imageid) + break; + } + if (ToolTipImageIDs[i] >= 0 && idx < MAX_IMAGETOOLTIPS) { + HWND ToolTipHWND2 = CreateWindowEx (WS_EX_TOPMOST, + TOOLTIPS_CLASS, NULL, + WS_POPUP | TTS_NOPREFIX, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + panelDlg, NULL, hInst, NULL); + ToolTipHWNDS2[idx].hwnd = ToolTipHWND2; + ToolTipHWNDS2[idx+1].hwnd = NULL; + ToolTipHWNDS2[idx].proc = (WNDPROC)GetWindowLongPtr (ToolTipHWND2, GWLP_WNDPROC); + ToolTipHWNDS2[idx].imageid = ToolTipImageIDs[i + 1]; + SetWindowLongPtr (ToolTipHWND2, GWLP_WNDPROC, (LONG_PTR)ToolTipWndProc); + SetWindowPos (ToolTipHWND2, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + SendMessage (ToolTipHWND2, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)MAKELONG(20000, 0)); + SendMessage (ToolTipHWND2, TTM_SETMAXTIPWIDTH, 0, 400); + SendMessage (hwnd, WM_SETTEXT, 0, (LPARAM)tmp); + v = SendMessage (ToolTipHWND2, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + } + } else { + v = SendMessage (hwnd, WM_SETTEXT, 0, (LPARAM)tmp); + v = SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + } + return 1; + } + p = _tcschr (tmp, ']'); + if (_tcslen (tmp) > 0 && p && _tcslen (p) > 2 && p[1] == '[') { + RECT r; + *p++ = 0; + *p++ = 0; + if (p[0] == ' ') + *p++; + tmp[_tcslen (tmp) - 1] = 0; SendMessage (hwnd, WM_SETTEXT, 0, (LPARAM)tmp); - v = SendMessage (ToolTipHWND2, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); - } - } else { - v = SendMessage (hwnd, WM_SETTEXT, 0, (LPARAM)tmp); - v = SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + ti.cbSize = sizeof (TOOLINFO); + ti.uFlags = TTF_SUBCLASS; + ti.hwnd = GetParent (hwnd); + ti.hinst = hInst; + ti.uId = (UINT_PTR)hwnd; + ti.lpszText = p; + GetWindowRect (GetParent (hwnd), &r); + GetWindowRect (hwnd, &ti.rect); + ti.rect.top -= r.top; + ti.rect.left -= r.left; + ti.rect.right -= r.left; + ti.rect.bottom -= r.top; + SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } return 1; - } - p = _tcschr (tmp, ']'); - if (_tcslen (tmp) > 0 && p && _tcslen (p) > 2 && p[1] == '[') { - RECT r; - *p++ = 0; - *p++ = 0; - if (p[0] == ' ') - *p++; - tmp[_tcslen (tmp) - 1] = 0; - SendMessage (hwnd, WM_SETTEXT, 0, (LPARAM)tmp); - ti.cbSize = sizeof (TOOLINFO); - ti.uFlags = TTF_SUBCLASS; - ti.hwnd = GetParent (hwnd); - ti.hinst = hInst; - ti.uId = (UINT_PTR)hwnd; - ti.lpszText = p; - GetWindowRect (GetParent (hwnd), &r); - GetWindowRect (hwnd, &ti.rect); - ti.rect.top -= r.top; - ti.rect.left -= r.left; - ti.rect.right -= r.left; - ti.rect.bottom -= r.top; - SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); - } - return 1; } static struct GUIPAGE ppage[MAX_C_PAGES]; @@ -11693,919 +11705,919 @@ static struct GUIPAGE ppage[MAX_C_PAGES]; static HWND updatePanel (HWND hDlg, int id) { - static HWND hwndTT; - RECT r1c, r1w, r2c, r2w, r3c, r3w; - int w, h, pw, ph, x , y, i; - int fullpanel; - struct newresource *tres; - - ew (guiDlg, IDC_RESETAMIGA, full_property_sheet ? FALSE : TRUE); - ew (guiDlg, IDOK, TRUE); - if (panelDlg != NULL) { - ShowWindow (panelDlg, FALSE); - DestroyWindow (panelDlg); - panelDlg = NULL; - } - if (ToolTipHWND != NULL) { - DestroyWindow (ToolTipHWND); - ToolTipHWND = NULL; - } - for (i = 0; ToolTipHWNDS2[i].hwnd; i++) { - DestroyWindow (ToolTipHWNDS2[i].hwnd); - ToolTipHWNDS2[i].hwnd = NULL; - } - hAccelTable = NULL; - if (id < 0) { - if (isfullscreen () <= 0) { - RECT r; - if (GetWindowRect (hDlg, &r)) { - LONG left, top; - left = r.left; - top = r.top; - regsetint (NULL, L"GUIPosX", left); - regsetint (NULL, L"GUIPosY", top); - } - } - ew (hDlg, IDHELP, FALSE); - return NULL; - } - - fullpanel = ppage[id].fullpanel; - GetWindowRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1w); - GetClientRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1c); - GetWindowRect (hDlg, &r2w); - GetClientRect (hDlg, &r2c); - gui_width = r2c.right; - gui_height = r2c.bottom; - tres = scaleresource (ppage[id].nres, hDlg); - panelDlg = CreateDialogIndirectParam (tres->inst, tres->resource, hDlg, ppage[id].dlgproc, id); - freescaleresource(tres); - GetWindowRect (hDlg, &r3w); - GetClientRect (panelDlg, &r3c); - x = r1w.left - r2w.left; - y = r1w.top - r2w.top; - w = r3c.right - r3c.left + 1; - h = r3c.bottom - r3c.top + 1; - pw = r1w.right - r1w.left + 1; - ph = r1w.bottom - r1w.top + 1; - SetWindowPos (panelDlg, HWND_TOP, 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOOWNERZORDER); - GetWindowRect (panelDlg, &r3w); - GetClientRect (panelDlg, &r3c); - x -= r3w.left - r2w.left - 1; - y -= r3w.top - r2w.top - 1; - if (!fullpanel) { - SetWindowPos (panelDlg, HWND_TOP, x + (pw - w) / 2, y + (ph - h) / 2, 0, 0, - SWP_NOSIZE | SWP_NOOWNERZORDER); - } - ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME), SW_HIDE); - ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME_OUTER), !fullpanel ? SW_SHOW : SW_HIDE); - ShowWindow (GetDlgItem (hDlg, IDC_PANELTREE), !fullpanel ? SW_SHOW : SW_HIDE); - ShowWindow (panelDlg, SW_SHOW); - ew (hDlg, IDHELP, pHtmlHelp && ppage[currentpage].help ? TRUE : FALSE); - - ToolTipHWND = CreateWindowEx (WS_EX_TOPMOST, - TOOLTIPS_CLASS, NULL, - WS_POPUP | TTS_NOPREFIX | TTS_BALLOON, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - panelDlg, NULL, hInst, NULL); - SetWindowPos (ToolTipHWND, HWND_TOPMOST, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + static HWND hwndTT; + RECT r1c, r1w, r2c, r2w, r3c, r3w; + int w, h, pw, ph, x , y, i; + int fullpanel; + struct newresource *tres; + + ew (guiDlg, IDC_RESETAMIGA, full_property_sheet ? FALSE : TRUE); + ew (guiDlg, IDOK, TRUE); + if (panelDlg != NULL) { + ShowWindow (panelDlg, FALSE); + DestroyWindow (panelDlg); + panelDlg = NULL; + } + if (ToolTipHWND != NULL) { + DestroyWindow (ToolTipHWND); + ToolTipHWND = NULL; + } + for (i = 0; ToolTipHWNDS2[i].hwnd; i++) { + DestroyWindow (ToolTipHWNDS2[i].hwnd); + ToolTipHWNDS2[i].hwnd = NULL; + } + hAccelTable = NULL; + if (id < 0) { + if (isfullscreen () <= 0) { + RECT r; + if (GetWindowRect (hDlg, &r)) { + LONG left, top; + left = r.left; + top = r.top; + regsetint (NULL, L"GUIPosX", left); + regsetint (NULL, L"GUIPosY", top); + } + } + ew (hDlg, IDHELP, FALSE); + return NULL; + } + + fullpanel = ppage[id].fullpanel; + GetWindowRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1w); + GetClientRect (GetDlgItem (hDlg, IDC_PANEL_FRAME), &r1c); + GetWindowRect (hDlg, &r2w); + GetClientRect (hDlg, &r2c); + gui_width = r2c.right; + gui_height = r2c.bottom; + tres = scaleresource (ppage[id].nres, hDlg); + panelDlg = CreateDialogIndirectParam (tres->inst, tres->resource, hDlg, ppage[id].dlgproc, id); + freescaleresource(tres); + GetWindowRect (hDlg, &r3w); + GetClientRect (panelDlg, &r3c); + x = r1w.left - r2w.left; + y = r1w.top - r2w.top; + w = r3c.right - r3c.left + 1; + h = r3c.bottom - r3c.top + 1; + pw = r1w.right - r1w.left + 1; + ph = r1w.bottom - r1w.top + 1; + SetWindowPos (panelDlg, HWND_TOP, 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOOWNERZORDER); + GetWindowRect (panelDlg, &r3w); + GetClientRect (panelDlg, &r3c); + x -= r3w.left - r2w.left - 1; + y -= r3w.top - r2w.top - 1; + if (!fullpanel) { + SetWindowPos (panelDlg, HWND_TOP, x + (pw - w) / 2, y + (ph - h) / 2, 0, 0, + SWP_NOSIZE | SWP_NOOWNERZORDER); + } + ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME), SW_HIDE); + ShowWindow (GetDlgItem (hDlg, IDC_PANEL_FRAME_OUTER), !fullpanel ? SW_SHOW : SW_HIDE); + ShowWindow (GetDlgItem (hDlg, IDC_PANELTREE), !fullpanel ? SW_SHOW : SW_HIDE); + ShowWindow (panelDlg, SW_SHOW); + ew (hDlg, IDHELP, pHtmlHelp && ppage[currentpage].help ? TRUE : FALSE); + + ToolTipHWND = CreateWindowEx (WS_EX_TOPMOST, + TOOLTIPS_CLASS, NULL, + WS_POPUP | TTS_NOPREFIX | TTS_BALLOON, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + panelDlg, NULL, hInst, NULL); + SetWindowPos (ToolTipHWND, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); #if 0 - SendMessage(ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_INITIAL, (LPARAM)MAKELONG(100, 0)); - SendMessage(ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_RESHOW, (LPARAM)MAKELONG(0, 0)); + SendMessage(ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_INITIAL, (LPARAM)MAKELONG(100, 0)); + SendMessage(ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_RESHOW, (LPARAM)MAKELONG(0, 0)); #endif - SendMessage (ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)MAKELONG(20000, 0)); - SendMessage (ToolTipHWND, TTM_SETMAXTIPWIDTH, 0, 400); + SendMessage (ToolTipHWND, TTM_SETDELAYTIME, (WPARAM)TTDT_AUTOPOP, (LPARAM)MAKELONG(20000, 0)); + SendMessage (ToolTipHWND, TTM_SETMAXTIPWIDTH, 0, 400); - EnumChildWindows (panelDlg, &childenumproc, (LPARAM)ppage[currentpage].nres->tmpl); - SendMessage (panelDlg, WM_NULL, 0, 0); + EnumChildWindows (panelDlg, &childenumproc, (LPARAM)ppage[currentpage].nres->tmpl); + SendMessage (panelDlg, WM_NULL, 0, 0); - hAccelTable = ppage[currentpage].accel; + hAccelTable = ppage[currentpage].accel; - return panelDlg; + return panelDlg; } static HTREEITEM CreateFolderNode (HWND TVhDlg, int nameid, HTREEITEM parent, int nodeid, int sub) { - TVINSERTSTRUCT is; - TCHAR txt[100]; + TVINSERTSTRUCT is; + TCHAR txt[100]; - memset (&is, 0, sizeof (is)); - is.hInsertAfter = TVI_LAST; - is.hParent = parent; - is.itemex.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - WIN32GUI_LoadUIString (nameid, txt, sizeof (txt) / sizeof (TCHAR)); - is.itemex.pszText = txt; - is.itemex.lParam = (LPARAM)(nodeid | (sub << 16)); - is.itemex.iImage = C_PAGES; - is.itemex.iSelectedImage = C_PAGES; - is.itemex.state = TVIS_BOLD | TVIS_EXPANDED; - is.itemex.stateMask = TVIS_BOLD | TVIS_EXPANDED; - return TreeView_InsertItem (TVhDlg, &is); + memset (&is, 0, sizeof (is)); + is.hInsertAfter = TVI_LAST; + is.hParent = parent; + is.itemex.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + WIN32GUI_LoadUIString (nameid, txt, sizeof (txt) / sizeof (TCHAR)); + is.itemex.pszText = txt; + is.itemex.lParam = (LPARAM)(nodeid | (sub << 16)); + is.itemex.iImage = C_PAGES; + is.itemex.iSelectedImage = C_PAGES; + is.itemex.state = TVIS_BOLD | TVIS_EXPANDED; + is.itemex.stateMask = TVIS_BOLD | TVIS_EXPANDED; + return TreeView_InsertItem (TVhDlg, &is); } static void CreateNode (HWND TVhDlg, int page, HTREEITEM parent) { - TVINSERTSTRUCT is; - struct GUIPAGE *p; - - if (page < 0) - return; - p = &ppage[page]; - memset (&is, 0, sizeof (is)); - is.hInsertAfter = TVI_LAST; - is.hParent = parent; - is.itemex.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - is.itemex.pszText = (TCHAR*)p->title; - is.itemex.lParam = (LPARAM)p->idx; - is.itemex.iImage = p->himg; - is.itemex.iSelectedImage = is.itemex.iImage; - p->tv = TreeView_InsertItem (TVhDlg, &is); + TVINSERTSTRUCT is; + struct GUIPAGE *p; + + if (page < 0) + return; + p = &ppage[page]; + memset (&is, 0, sizeof (is)); + is.hInsertAfter = TVI_LAST; + is.hParent = parent; + is.itemex.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + is.itemex.pszText = (TCHAR*)p->title; + is.itemex.lParam = (LPARAM)p->idx; + is.itemex.iImage = p->himg; + is.itemex.iSelectedImage = is.itemex.iImage; + p->tv = TreeView_InsertItem (TVhDlg, &is); } #define CN(page) CreateNode(TVhDlg, page, p); static void createTreeView (HWND hDlg, int currentpage) { - HWND TVhDlg; - int i; - HIMAGELIST himl; - HTREEITEM p, root; + HWND TVhDlg; + int i; + HIMAGELIST himl; + HTREEITEM p, root; + + himl = ImageList_Create (16, 16, ILC_COLOR8 | ILC_MASK, C_PAGES + 1, 0); + if (himl) { + HICON icon; + for (i = 0; i < C_PAGES; i++) { + icon = LoadIcon (hInst, (LPCWSTR)ppage[i].icon); + ppage[i].himg = ImageList_AddIcon (himl, icon); + } + icon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ROOT)); + ImageList_AddIcon (himl, icon); + } + TVhDlg = GetDlgItem (hDlg, IDC_PANELTREE); + TreeView_SetImageList (TVhDlg, himl, TVSIL_NORMAL); - himl = ImageList_Create (16, 16, ILC_COLOR8 | ILC_MASK, C_PAGES + 1, 0); - if (himl) { - HICON icon; - for (i = 0; i < C_PAGES; i++) { - icon = LoadIcon (hInst, (LPCWSTR)ppage[i].icon); - ppage[i].himg = ImageList_AddIcon (himl, icon); - } - icon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ROOT)); - ImageList_AddIcon (himl, icon); - } - TVhDlg = GetDlgItem (hDlg, IDC_PANELTREE); - TreeView_SetImageList (TVhDlg, himl, TVSIL_NORMAL); - - p = root = CreateFolderNode (TVhDlg, IDS_TREEVIEW_SETTINGS, NULL, ABOUT_ID, 0); - CN (ABOUT_ID); - CN (PATHS_ID); - CN (QUICKSTART_ID); - CN (LOADSAVE_ID); + p = root = CreateFolderNode (TVhDlg, IDS_TREEVIEW_SETTINGS, NULL, ABOUT_ID, 0); + CN (ABOUT_ID); + CN (PATHS_ID); + CN (QUICKSTART_ID); + CN (LOADSAVE_ID); #if FRONTEND == 1 - CN (FRONTEND_ID); + CN (FRONTEND_ID); #endif - p = CreateFolderNode (TVhDlg, IDS_TREEVIEW_HARDWARE, root, LOADSAVE_ID, CONFIG_TYPE_HARDWARE); - CN (CPU_ID); - CN (CHIPSET_ID); - CN (CHIPSET2_ID); - CN (KICKSTART_ID); - CN (MEMORY_ID); - CN (FLOPPY_ID); - CN (HARDDISK_ID); - CN (EXPANSION_ID); - - p = CreateFolderNode (TVhDlg, IDS_TREEVIEW_HOST, root, LOADSAVE_ID, CONFIG_TYPE_HOST); - CN (DISPLAY_ID); - CN (SOUND_ID); - CN (GAMEPORTS_ID); - CN (IOPORTS_ID); - CN (INPUT_ID); - CN (AVIOUTPUT_ID); - CN (HW3D_ID); - CN (DISK_ID); - CN (MISC1_ID); - CN (MISC2_ID); - - TreeView_SelectItem (TVhDlg, ppage[currentpage].tv); + p = CreateFolderNode (TVhDlg, IDS_TREEVIEW_HARDWARE, root, LOADSAVE_ID, CONFIG_TYPE_HARDWARE); + CN (CPU_ID); + CN (CHIPSET_ID); + CN (CHIPSET2_ID); + CN (KICKSTART_ID); + CN (MEMORY_ID); + CN (FLOPPY_ID); + CN (HARDDISK_ID); + CN (EXPANSION_ID); + + p = CreateFolderNode (TVhDlg, IDS_TREEVIEW_HOST, root, LOADSAVE_ID, CONFIG_TYPE_HOST); + CN (DISPLAY_ID); + CN (SOUND_ID); + CN (GAMEPORTS_ID); + CN (IOPORTS_ID); + CN (INPUT_ID); + CN (AVIOUTPUT_ID); + CN (HW3D_ID); + CN (DISK_ID); + CN (MISC1_ID); + CN (MISC2_ID); + + TreeView_SelectItem (TVhDlg, ppage[currentpage].tv); } static int dialog_x_offset, dialog_y_offset; static void centerWindow (HWND hDlg) { - RECT rc, rcDlg, rcOwner; - HWND owner = GetParent(hDlg); - LONG x = 0, y = 0; - POINT pt1, pt2; - - if (owner == NULL) - owner = GetDesktopWindow (); - if (isfullscreen () <= 0) { - regqueryint (NULL, L"GUIPosX", &x); - regqueryint (NULL, L"GUIPosY", &y); - } else { - GetWindowRect (owner, &rcOwner); - GetWindowRect (hDlg, &rcDlg); - CopyRect (&rc, &rcOwner); - OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect (&rc, -rc.left, -rc.top); - OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom); - x = rcOwner.left + (rc.right / 2); - y = rcOwner.top + (rc.bottom / 2); - } - SetForegroundWindow (hDlg); - pt1.x = x; - pt1.y = y; - pt2.x = x + 16; - pt2.y = y + GetSystemMetrics (SM_CYMENU) + GetSystemMetrics (SM_CYBORDER); - if (MonitorFromPoint (pt1, MONITOR_DEFAULTTONULL) == NULL || MonitorFromPoint (pt2, MONITOR_DEFAULTTONULL) == NULL) { - if (isfullscreen () > 0) { - x = 0; - y = 0; + RECT rc, rcDlg, rcOwner; + HWND owner = GetParent(hDlg); + LONG x = 0, y = 0; + POINT pt1, pt2; + + if (owner == NULL) + owner = GetDesktopWindow (); + if (isfullscreen () <= 0) { + regqueryint (NULL, L"GUIPosX", &x); + regqueryint (NULL, L"GUIPosY", &y); } else { - x = 16; - y = 16; + GetWindowRect (owner, &rcOwner); + GetWindowRect (hDlg, &rcDlg); + CopyRect (&rc, &rcOwner); + OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect (&rc, -rc.left, -rc.top); + OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom); + x = rcOwner.left + (rc.right / 2); + y = rcOwner.top + (rc.bottom / 2); + } + SetForegroundWindow (hDlg); + pt1.x = x; + pt1.y = y; + pt2.x = x + 16; + pt2.y = y + GetSystemMetrics (SM_CYMENU) + GetSystemMetrics (SM_CYBORDER); + if (MonitorFromPoint (pt1, MONITOR_DEFAULTTONULL) == NULL || MonitorFromPoint (pt2, MONITOR_DEFAULTTONULL) == NULL) { + if (isfullscreen () > 0) { + x = 0; + y = 0; + } else { + x = 16; + y = 16; + } } - } - dialog_x_offset = x; - dialog_y_offset = y; - SetWindowPos (hDlg, HWND_TOP, x, y, 0, 0, SWP_NOSIZE); + dialog_x_offset = x; + dialog_y_offset = y; + SetWindowPos (hDlg, HWND_TOP, x, y, 0, 0, SWP_NOSIZE); } static int do_filesys_insert (const TCHAR *root) { - if (filesys_insert (-1, NULL, root, 0, 0) == 0) - return filesys_media_change (root, 2, NULL); - return 1; + if (filesys_insert (-1, NULL, root, 0, 0) == 0) + return filesys_media_change (root, 2, NULL); + return 1; } int dragdrop (HWND hDlg, HDROP hd, struct uae_prefs *prefs, int currentpage) { - int cnt, i, drv, harddrive, drvdrag, firstdrv, list; - TCHAR file[MAX_DPATH]; - int dfxtext[] = { IDC_DF0TEXT, IDC_DF0TEXTQ, IDC_DF1TEXT, IDC_DF1TEXTQ, IDC_DF2TEXT, -1, IDC_DF3TEXT, -1 }; - POINT pt; - RECT r, r2; - int ret = 0; - DWORD flags; - - DragQueryPoint (hd, &pt); - pt.y += GetSystemMetrics (SM_CYMENU) + GetSystemMetrics (SM_CYBORDER); - cnt = DragQueryFile (hd, 0xffffffff, NULL, 0); - if (!cnt) - return 0; - drv = harddrive = 0; - drvdrag = 0; - if (currentpage < 0) { - GetClientRect (hMainWnd, &r2); - GetClientRect (hStatusWnd, &r); - if (pt.y >= r2.bottom && pt.y < r2.bottom + r.bottom) { - if (pt.x >= window_led_drives && pt.x < window_led_drives_end && window_led_drives > 0) { - drv = pt.x - window_led_drives; - drv /= (window_led_drives_end - window_led_drives) / 4; - drvdrag = 1; - if (drv < 0 || drv > 3) - drv = 0; - } - if (pt.x >= window_led_hd && pt.x < window_led_hd_end && window_led_hd > 0) { - harddrive = 1; - } - } - } else if (currentpage == FLOPPY_ID || currentpage == QUICKSTART_ID) { - for (i = 0; i < 4; i++) { - int id = dfxtext[i * 2 + (currentpage == QUICKSTART_ID ? 1 : 0)]; - if (workprefs.dfxtype[i] >= 0 && id >= 0) { - if (GetPanelRect (GetDlgItem (panelDlg, id), &r)) { - if (PtInRect (&r, pt)) { - drv = i; - break; - } + int cnt, i, drv, harddrive, drvdrag, firstdrv, list; + TCHAR file[MAX_DPATH]; + int dfxtext[] = { IDC_DF0TEXT, IDC_DF0TEXTQ, IDC_DF1TEXT, IDC_DF1TEXTQ, IDC_DF2TEXT, -1, IDC_DF3TEXT, -1 }; + POINT pt; + RECT r, r2; + int ret = 0; + DWORD flags; + + DragQueryPoint (hd, &pt); + pt.y += GetSystemMetrics (SM_CYMENU) + GetSystemMetrics (SM_CYBORDER); + cnt = DragQueryFile (hd, 0xffffffff, NULL, 0); + if (!cnt) + return 0; + drv = harddrive = 0; + drvdrag = 0; + if (currentpage < 0) { + GetClientRect (hMainWnd, &r2); + GetClientRect (hStatusWnd, &r); + if (pt.y >= r2.bottom && pt.y < r2.bottom + r.bottom) { + if (pt.x >= window_led_drives && pt.x < window_led_drives_end && window_led_drives > 0) { + drv = pt.x - window_led_drives; + drv /= (window_led_drives_end - window_led_drives) / 4; + drvdrag = 1; + if (drv < 0 || drv > 3) + drv = 0; + } + if (pt.x >= window_led_hd && pt.x < window_led_hd_end && window_led_hd > 0) { + harddrive = 1; + } + } + } else if (currentpage == FLOPPY_ID || currentpage == QUICKSTART_ID) { + for (i = 0; i < 4; i++) { + int id = dfxtext[i * 2 + (currentpage == QUICKSTART_ID ? 1 : 0)]; + if (workprefs.dfxtype[i] >= 0 && id >= 0) { + if (GetPanelRect (GetDlgItem (panelDlg, id), &r)) { + if (PtInRect (&r, pt)) { + drv = i; + break; + } + } + } } - } } - } - firstdrv = drv; - for (i = 0; i < cnt; i++) { - struct romdata *rd = NULL; - struct zfile *z; - int type = -1, zip = 0; - int mask; - - DragQueryFile (hd, i, file, sizeof (file) / sizeof (TCHAR)); - flags = GetFileAttributes (file); - if (flags & FILE_ATTRIBUTE_DIRECTORY) - type = ZFILE_HDF; - if (harddrive) - mask = ZFD_ALL; - else - mask = ZFD_NORMAL; - if (type < 0) { - if (currentpage < 0) { - z = zfile_fopen (file, L"rb", mask); - if (z) { - int zip = iszip (z); - zfile_fclose (z); - } - } - if (!zip) { - z = zfile_fopen (file, L"rb", mask); - if (z) { - if (currentpage < 0 && iszip (z)) { - zip = 1; - } else { - type = zfile_gettype (z); - if (type == ZFILE_ROM) - rd = getromdatabyzfile (z); - } - zfile_fclose (z); - z = NULL; - } - } - } - - if (drvdrag) { - type = ZFILE_DISKIMAGE; - } else if (zip || harddrive) { - do_filesys_insert (file); - continue; - } - - switch (type) - { - case ZFILE_DISKIMAGE: - if (currentpage == DISK_ID) { - list = 0; - while (list < MAX_SPARE_DRIVES) { - if (!strcasecmp (prefs->dfxlist[list], file)) - break; - list++; - } - if (list == MAX_SPARE_DRIVES) { - list = 0; - while (list < MAX_SPARE_DRIVES) { - if (!prefs->dfxlist[list][0]) { - _tcscpy (prefs->dfxlist[list], file); - break; - } - list++; + firstdrv = drv; + for (i = 0; i < cnt; i++) { + struct romdata *rd = NULL; + struct zfile *z; + int type = -1, zip = 0; + int mask; + + DragQueryFile (hd, i, file, sizeof (file) / sizeof (TCHAR)); + flags = GetFileAttributes (file); + if (flags & FILE_ATTRIBUTE_DIRECTORY) + type = ZFILE_HDF; + if (harddrive) + mask = ZFD_ALL; + else + mask = ZFD_NORMAL; + if (type < 0) { + if (currentpage < 0) { + z = zfile_fopen (file, L"rb", mask); + if (z) { + int zip = iszip (z); + zfile_fclose (z); + } + } + if (!zip) { + z = zfile_fopen (file, L"rb", mask); + if (z) { + if (currentpage < 0 && iszip (z)) { + zip = 1; + } else { + type = zfile_gettype (z); + if (type == ZFILE_ROM) + rd = getromdatabyzfile (z); + } + zfile_fclose (z); + z = NULL; + } } - } - } else if (currentpage == HARDDISK_ID) { - add_filesys_config (&workprefs, -1, NULL, L"", file, 0, - 0, 0, 0, 0, 0, NULL, 0, 0); - } else { - _tcscpy (workprefs.df[drv], file); - disk_insert (drv, workprefs.df[drv]); - drv++; - if (drv >= (currentpage == QUICKSTART_ID ? 2 : 4)) - drv = 0; - if (workprefs.dfxtype[drv] < 0) - drv = 0; - if (drv == firstdrv) - i = cnt; - } - break; - case ZFILE_ROM: - if (rd) { - if (rd->type == ROMTYPE_KICK || rd->type == ROMTYPE_KICKCD32) - _tcscpy (prefs->romfile, file); - if (rd->type == ROMTYPE_EXTCD32 || rd->type == ROMTYPE_EXTCDTV) - _tcscpy (prefs->romextfile, file); - if (rd->type == ROMTYPE_AR) - _tcscpy (prefs->cartfile, file); - } else { - _tcscpy (prefs->romfile, file); } - break; - case ZFILE_HDF: - if (flags & FILE_ATTRIBUTE_DIRECTORY) { - if (!full_property_sheet && currentpage < 0) + + if (drvdrag) { + type = ZFILE_DISKIMAGE; + } else if (zip || harddrive) { do_filesys_insert (file); - else - add_filesys_config (&workprefs, -1, NULL, L"", file, 0, - 0, 0, 0, 0, 0, NULL, 0, 0); - } else { - add_filesys_config (&workprefs, -1, NULL, NULL, file, 0, - 32, 1, 2, 512, 0, NULL, 0, 0); - } - break; - case ZFILE_HDFRDB: - add_filesys_config (&workprefs, -1, NULL, NULL, file, 0, - 0, 0, 0, 512, 0, NULL, 0, 0); - break; - case ZFILE_NVR: - _tcscpy (prefs->flashfile, file); - break; - case ZFILE_CONFIGURATION: - if (target_cfgfile_load (&workprefs, file, 0, 0)) { - if (full_property_sheet) { - inputdevice_updateconfig (&workprefs); - if (!workprefs.start_gui) - ret = 1; - } else { - uae_restart (workprefs.start_gui, file); - ret = 1; - } + continue; } - break; - case ZFILE_STATEFILE: - savestate_state = STATE_DORESTORE; - _tcscpy (savestate_fname, file); - ret = 1; - break; - default: - if (currentpage < 0 && !full_property_sheet) { - do_filesys_insert (file); - } else if (currentpage == HARDDISK_ID) { - add_filesys_config (&workprefs, -1, NULL, L"", file, 0, - 0, 0, 0, 0, 0, NULL, 0, 0); - if (!full_property_sheet) - do_filesys_insert (file); - } else { - rd = scan_arcadia_rom (file, 0); - if (rd) { - if (rd->type == ROMTYPE_ARCADIABIOS) - _tcscpy (prefs->romextfile, file); - else if (rd->type == ROMTYPE_ARCADIAGAME) - _tcscpy (prefs->cartfile, file); - } + + switch (type) + { + case ZFILE_DISKIMAGE: + if (currentpage == DISK_ID) { + list = 0; + while (list < MAX_SPARE_DRIVES) { + if (!strcasecmp (prefs->dfxlist[list], file)) + break; + list++; + } + if (list == MAX_SPARE_DRIVES) { + list = 0; + while (list < MAX_SPARE_DRIVES) { + if (!prefs->dfxlist[list][0]) { + _tcscpy (prefs->dfxlist[list], file); + break; + } + list++; + } + } + } else if (currentpage == HARDDISK_ID) { + add_filesys_config (&workprefs, -1, NULL, L"", file, 0, + 0, 0, 0, 0, 0, NULL, 0, 0); + } else { + _tcscpy (workprefs.df[drv], file); + disk_insert (drv, workprefs.df[drv]); + drv++; + if (drv >= (currentpage == QUICKSTART_ID ? 2 : 4)) + drv = 0; + if (workprefs.dfxtype[drv] < 0) + drv = 0; + if (drv == firstdrv) + i = cnt; + } + break; + case ZFILE_ROM: + if (rd) { + if (rd->type == ROMTYPE_KICK || rd->type == ROMTYPE_KICKCD32) + _tcscpy (prefs->romfile, file); + if (rd->type == ROMTYPE_EXTCD32 || rd->type == ROMTYPE_EXTCDTV) + _tcscpy (prefs->romextfile, file); + if (rd->type == ROMTYPE_AR) + _tcscpy (prefs->cartfile, file); + } else { + _tcscpy (prefs->romfile, file); + } + break; + case ZFILE_HDF: + if (flags & FILE_ATTRIBUTE_DIRECTORY) { + if (!full_property_sheet && currentpage < 0) + do_filesys_insert (file); + else + add_filesys_config (&workprefs, -1, NULL, L"", file, 0, + 0, 0, 0, 0, 0, NULL, 0, 0); + } else { + add_filesys_config (&workprefs, -1, NULL, NULL, file, 0, + 32, 1, 2, 512, 0, NULL, 0, 0); + } + break; + case ZFILE_HDFRDB: + add_filesys_config (&workprefs, -1, NULL, NULL, file, 0, + 0, 0, 0, 512, 0, NULL, 0, 0); + break; + case ZFILE_NVR: + _tcscpy (prefs->flashfile, file); + break; + case ZFILE_CONFIGURATION: + if (target_cfgfile_load (&workprefs, file, 0, 0)) { + if (full_property_sheet) { + inputdevice_updateconfig (&workprefs); + if (!workprefs.start_gui) + ret = 1; + } else { + uae_restart (workprefs.start_gui, file); + ret = 1; + } + } + break; + case ZFILE_STATEFILE: + savestate_state = STATE_DORESTORE; + _tcscpy (savestate_fname, file); + ret = 1; + break; + default: + if (currentpage < 0 && !full_property_sheet) { + do_filesys_insert (file); + } else if (currentpage == HARDDISK_ID) { + add_filesys_config (&workprefs, -1, NULL, L"", file, 0, + 0, 0, 0, 0, 0, NULL, 0, 0); + if (!full_property_sheet) + do_filesys_insert (file); + } else { + rd = scan_arcadia_rom (file, 0); + if (rd) { + if (rd->type == ROMTYPE_ARCADIABIOS) + _tcscpy (prefs->romextfile, file); + else if (rd->type == ROMTYPE_ARCADIAGAME) + _tcscpy (prefs->cartfile, file); + } + } + break; } - break; } - } - DragFinish (hd); - return ret; + DragFinish (hd); + return ret; } static int dialogreturn; static INT_PTR CALLBACK DialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static int recursive = 0; - static int waitfornext; + static int recursive = 0; + static int waitfornext; - switch(msg) - { - case WM_DEVICECHANGE: + switch(msg) { - DEV_BROADCAST_HDR *pBHdr = (DEV_BROADCAST_HDR *)lParam; - int doit = 0; - if (wParam == DBT_DEVNODES_CHANGED && lParam == 0) { - if (waitfornext) - doit = 1; - } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { - DEV_BROADCAST_DEVICEINTERFACE *dbd = (DEV_BROADCAST_DEVICEINTERFACE*)lParam; - write_log (L"%s: %s\n", wParam == DBT_DEVICEREMOVECOMPLETE ? L"Removed" : L"Inserted", - dbd->dbcc_name); - if (wParam == DBT_DEVICEREMOVECOMPLETE) - doit = 1; - else if (wParam == DBT_DEVICEARRIVAL) - waitfornext = 1; /* DirectInput enumeration does not yet show the new device.. */ - } - if (doit) { - inputdevice_devicechange (&workprefs); - updatePanel (hDlg, currentpage); - waitfornext = 0; - } - } - return TRUE; + case WM_DEVICECHANGE: + { + DEV_BROADCAST_HDR *pBHdr = (DEV_BROADCAST_HDR *)lParam; + int doit = 0; + if (wParam == DBT_DEVNODES_CHANGED && lParam == 0) { + if (waitfornext) + doit = 1; + } else if (pBHdr && pBHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { + DEV_BROADCAST_DEVICEINTERFACE *dbd = (DEV_BROADCAST_DEVICEINTERFACE*)lParam; + write_log (L"%s: %s\n", wParam == DBT_DEVICEREMOVECOMPLETE ? L"Removed" : L"Inserted", + dbd->dbcc_name); + if (wParam == DBT_DEVICEREMOVECOMPLETE) + doit = 1; + else if (wParam == DBT_DEVICEARRIVAL) + waitfornext = 1; /* DirectInput enumeration does not yet show the new device.. */ + } + if (doit) { + inputdevice_devicechange (&workprefs); + updatePanel (hDlg, currentpage); + waitfornext = 0; + } + } + return TRUE; case WM_DESTROY: - PostQuitMessage (0); - return TRUE; + PostQuitMessage (0); + return TRUE; case WM_CLOSE: - addnotifications (hDlg, TRUE, TRUE); - DestroyWindow(hDlg); - if (dialogreturn < 0) { - dialogreturn = 0; - if (allow_quit) { - quit_program = 1; - regs.spcflags |= SPCFLAG_BRK; - } - } - return TRUE; + addnotifications (hDlg, TRUE, TRUE); + DestroyWindow(hDlg); + if (dialogreturn < 0) { + dialogreturn = 0; + if (allow_quit) { + quit_program = 1; + regs.spcflags |= SPCFLAG_BRK; + } + } + return TRUE; case WM_INITDIALOG: - waitfornext = 0; - guiDlg = hDlg; - SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE(IDI_APPICON))); - if (full_property_sheet) { - TCHAR tmp[100]; - WIN32GUI_LoadUIString (IDS_STARTEMULATION, tmp, sizeof (tmp) / sizeof (TCHAR)); - SetWindowText (GetDlgItem (guiDlg, IDOK), tmp); - } - ShowWindow (GetDlgItem(guiDlg, IDC_RESTARTEMU), full_property_sheet ? SW_HIDE : SW_SHOW); - centerWindow (hDlg); - createTreeView (hDlg, currentpage); - updatePanel (hDlg, currentpage); - addnotifications (hDlg, FALSE, TRUE); - return TRUE; + waitfornext = 0; + guiDlg = hDlg; + SendMessage (hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE(IDI_APPICON))); + if (full_property_sheet) { + TCHAR tmp[100]; + WIN32GUI_LoadUIString (IDS_STARTEMULATION, tmp, sizeof (tmp) / sizeof (TCHAR)); + SetWindowText (GetDlgItem (guiDlg, IDOK), tmp); + } + ShowWindow (GetDlgItem(guiDlg, IDC_RESTARTEMU), full_property_sheet ? SW_HIDE : SW_SHOW); + centerWindow (hDlg); + createTreeView (hDlg, currentpage); + updatePanel (hDlg, currentpage); + addnotifications (hDlg, FALSE, TRUE); + return TRUE; case WM_DROPFILES: - if (dragdrop (hDlg, (HDROP)wParam, (gui_active || full_property_sheet) ? &workprefs : &changed_prefs, currentpage)) - SendMessage (hDlg, WM_COMMAND, IDOK, 0); - updatePanel (hDlg, currentpage); - return FALSE; - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->code) - { - case TVN_SELCHANGING: + if (dragdrop (hDlg, (HDROP)wParam, (gui_active || full_property_sheet) ? &workprefs : &changed_prefs, currentpage)) + SendMessage (hDlg, WM_COMMAND, IDOK, 0); + updatePanel (hDlg, currentpage); return FALSE; - case TVN_SELCHANGED: + case WM_NOTIFY: { - int cp, cf; - LPNMTREEVIEW tv = (LPNMTREEVIEW)lParam; - cp = (int)(tv->itemNew.lParam & 0xffff); - cf = (int)(tv->itemNew.lParam >> 16); - if (cp != currentpage || cf != configtype) { - currentpage = cp; - configtypepanel = configtype = cf; - updatePanel (hDlg, currentpage); - } - return TRUE; + switch (((LPNMHDR)lParam)->code) + { + case TVN_SELCHANGING: + return FALSE; + case TVN_SELCHANGED: + { + int cp, cf; + LPNMTREEVIEW tv = (LPNMTREEVIEW)lParam; + cp = (int)(tv->itemNew.lParam & 0xffff); + cf = (int)(tv->itemNew.lParam >> 16); + if (cp != currentpage || cf != configtype) { + currentpage = cp; + configtypepanel = configtype = cf; + updatePanel (hDlg, currentpage); + } + return TRUE; + } + break; + } + break; } - break; - } - break; - } case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_RESETAMIGA: - uae_reset (1); - SendMessage (hDlg, WM_COMMAND, IDOK, 0); - return TRUE; - case IDC_QUITEMU: - uae_quit (); - SendMessage (hDlg, WM_COMMAND, IDCANCEL, 0); - return TRUE; - case IDC_RESTARTEMU: - uae_restart (-1, NULL); - exit_gui (1); - return TRUE; - case IDHELP: - if (pHtmlHelp && ppage[currentpage].help) - HtmlHelp (NULL, help_file, HH_DISPLAY_TOPIC, ppage[currentpage].help); - return TRUE; - case IDOK: - updatePanel (hDlg, -1); - dialogreturn = 1; - DestroyWindow (hDlg); - gui_to_prefs (); - guiDlg = NULL; - return TRUE; - case IDCANCEL: - updatePanel (hDlg, -1); - dialogreturn = 0; - DestroyWindow (hDlg); - if (allow_quit) { - quit_program = 1; - regs.spcflags |= SPCFLAG_BRK; - } - guiDlg = NULL; - return TRUE; - } - break; - } - } - return FALSE; + { + switch (LOWORD(wParam)) + { + case IDC_RESETAMIGA: + uae_reset (1); + SendMessage (hDlg, WM_COMMAND, IDOK, 0); + return TRUE; + case IDC_QUITEMU: + uae_quit (); + SendMessage (hDlg, WM_COMMAND, IDCANCEL, 0); + return TRUE; + case IDC_RESTARTEMU: + uae_restart (-1, NULL); + exit_gui (1); + return TRUE; + case IDHELP: + if (pHtmlHelp && ppage[currentpage].help) + HtmlHelp (NULL, help_file, HH_DISPLAY_TOPIC, ppage[currentpage].help); + return TRUE; + case IDOK: + updatePanel (hDlg, -1); + dialogreturn = 1; + DestroyWindow (hDlg); + gui_to_prefs (); + guiDlg = NULL; + return TRUE; + case IDCANCEL: + updatePanel (hDlg, -1); + dialogreturn = 0; + DestroyWindow (hDlg); + if (allow_quit) { + quit_program = 1; + regs.spcflags |= SPCFLAG_BRK; + } + guiDlg = NULL; + return TRUE; + } + break; + } + } + return FALSE; } static ACCEL EmptyAccel[] = { - { FVIRTKEY, VK_UP, 20001 }, { FVIRTKEY, VK_DOWN, 20002 }, - { 0, 0, 0 } + { FVIRTKEY, VK_UP, 20001 }, { FVIRTKEY, VK_DOWN, 20002 }, + { 0, 0, 0 } }; struct newresource *getresource (int tmpl) { - TCHAR rid[10]; - HRSRC hrsrc; - HGLOBAL res; - HINSTANCE inst = hUIDLL ? hUIDLL : hInst; - void *resdata, *newres; - struct newresource *nr; - int size; - - _stprintf (rid, L"#%d", tmpl); - hrsrc = FindResource (inst, rid, RT_DIALOG); - if (!hrsrc) { - inst = hInst; + TCHAR rid[10]; + HRSRC hrsrc; + HGLOBAL res; + HINSTANCE inst = hUIDLL ? hUIDLL : hInst; + void *resdata, *newres; + struct newresource *nr; + int size; + + _stprintf (rid, L"#%d", tmpl); hrsrc = FindResource (inst, rid, RT_DIALOG); - } - if (!hrsrc) - return NULL; - res = LoadResource (inst, hrsrc); - if (!res) - return NULL; - resdata = LockResource (res); - size = SizeofResource (inst, hrsrc); - nr = xcalloc (sizeof (struct newresource), 1); - newres = xmalloc (size); - memcpy (newres, resdata, size); - nr->resource = newres; - nr->size = size; - nr->tmpl = tmpl; - nr->inst = inst; - return nr; + if (!hrsrc) { + inst = hInst; + hrsrc = FindResource (inst, rid, RT_DIALOG); + } + if (!hrsrc) + return NULL; + res = LoadResource (inst, hrsrc); + if (!res) + return NULL; + resdata = LockResource (res); + size = SizeofResource (inst, hrsrc); + nr = xcalloc (sizeof (struct newresource), 1); + newres = xmalloc (size); + memcpy (newres, resdata, size); + nr->resource = newres; + nr->size = size; + nr->tmpl = tmpl; + nr->inst = inst; + return nr; } INT_PTR CustomDialogBox (int templ, HWND hDlg, DLGPROC proc) { - struct newresource *res, *r; - INT_PTR h = -1; + struct newresource *res, *r; + INT_PTR h = -1; - res = getresource (templ); - if (!res) + res = getresource (templ); + if (!res) + return h; + r = scaleresource (res, hDlg); + if (r) { + h = DialogBoxIndirect (r->inst, r->resource, hDlg, proc); + freescaleresource (r); + } + freescaleresource (res); return h; - r = scaleresource (res, hDlg); - if (r) { - h = DialogBoxIndirect (r->inst, r->resource, hDlg, proc); - freescaleresource (r); - } - freescaleresource (res); - return h; } HWND CustomCreateDialog (int templ, HWND hDlg, DLGPROC proc) { - struct newresource *res, *r; - HWND h = NULL; + struct newresource *res, *r; + HWND h = NULL; - res = getresource (templ); - if (!res) + res = getresource (templ); + if (!res) + return h; + r = scaleresource (res, hDlg); + if (r) { + h = CreateDialogIndirect (r->inst, r->resource, hDlg, proc); + freescaleresource (r); + } + freescaleresource (res); return h; - r = scaleresource (res, hDlg); - if (r) { - h = CreateDialogIndirect (r->inst, r->resource, hDlg, proc); - freescaleresource (r); - } - freescaleresource (res); - return h; } static int init_page (int tmpl, int icon, int title, - INT_PTR (CALLBACK FAR *func) (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam), ACCEL *accels, TCHAR *help) -{ - LPTSTR lpstrTitle; - static id = 0; - int i = -1; - struct newresource *res; - - res = getresource (tmpl); - if (!res) - return -1; - ppage[id].nres = res; - ppage[id].icon = MAKEINTRESOURCE (icon); - lpstrTitle = calloc (1, MAX_DPATH); - LoadString (hUIDLL, title, lpstrTitle, MAX_DPATH); - ppage[id].title = lpstrTitle; - ppage[id].dlgproc = func; - ppage[id].help = help; - ppage[id].idx = id; - ppage[id].accel = NULL; - if (!accels) - accels = EmptyAccel; - while (accels[++i].key); - ppage[id].accel = CreateAcceleratorTable (accels, i); - if (tmpl == IDD_FRONTEND) - ppage[id].fullpanel = TRUE; - id++; - return id - 1; + INT_PTR (CALLBACK FAR *func) (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam), ACCEL *accels, TCHAR *help) +{ + LPTSTR lpstrTitle; + static id = 0; + int i = -1; + struct newresource *res; + + res = getresource (tmpl); + if (!res) + return -1; + ppage[id].nres = res; + ppage[id].icon = MAKEINTRESOURCE (icon); + lpstrTitle = calloc (1, MAX_DPATH); + LoadString (hUIDLL, title, lpstrTitle, MAX_DPATH); + ppage[id].title = lpstrTitle; + ppage[id].dlgproc = func; + ppage[id].help = help; + ppage[id].idx = id; + ppage[id].accel = NULL; + if (!accels) + accels = EmptyAccel; + while (accels[++i].key); + ppage[id].accel = CreateAcceleratorTable (accels, i); + if (tmpl == IDD_FRONTEND) + ppage[id].fullpanel = TRUE; + id++; + return id - 1; } static RECT dialog_rect; static void dialogmousemove (HWND hDlg) { - static int newmx, newmy; - RECT rc; - POINT pt; - static POINT pt2; - int dx, dy; - int sw, sh; - int xstart, ystart; - MONITORINFOEX pmi; - - if (full_property_sheet || isfullscreen () <= 0) - return; - pmi.cbSize = sizeof (pmi); - GetMonitorInfo (MonitorFromWindow (hAmigaWnd, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&pmi); - xstart = pmi.rcMonitor.left; - ystart = pmi.rcMonitor.top; - GetCursorPos (&pt); - pt.x -= xstart; - pt.y -= ystart; - if (pt.x == pt2.x && pt.y == pt2.y) - return; - sw = pmi.rcMonitor.right - pmi.rcMonitor.left; - sh = pmi.rcMonitor.bottom - pmi.rcMonitor.top; - dx = dialog_x_offset; - dy = dialog_y_offset; - GetWindowRect (hDlg, &rc); - rc.right -= rc.left; - rc.bottom -= rc.top; - rc.left = 0; - rc.top = 0; - if (rc.right <= sw && rc.bottom <= sh) - return; - pt2.x = pt.x; - pt2.y = pt.y; - - newmx = pt.x; - newmy = pt.y; - - if (newmx >= sw - 1 && rc.right > sw) - dx = sw - rc.right; - if (newmx <= 1) - dx = 0; - if (newmy >= sh - 1 && rc.bottom > sh) - dy = sh - rc.bottom; - if (newmy <= 1) - dy = 0; - - if (dx != dialog_x_offset || dy != dialog_y_offset) { - dialog_x_offset = dx; - dialog_y_offset = dy; - dx += xstart; - dy += ystart; - SetWindowPos (hDlg, 0, dx, dy, 0, 0, - SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE); - } + static int newmx, newmy; + RECT rc; + POINT pt; + static POINT pt2; + int dx, dy; + int sw, sh; + int xstart, ystart; + MONITORINFOEX pmi; + + if (full_property_sheet || isfullscreen () <= 0) + return; + pmi.cbSize = sizeof (pmi); + GetMonitorInfo (MonitorFromWindow (hAmigaWnd, MONITOR_DEFAULTTOPRIMARY), (LPMONITORINFO)&pmi); + xstart = pmi.rcMonitor.left; + ystart = pmi.rcMonitor.top; + GetCursorPos (&pt); + pt.x -= xstart; + pt.y -= ystart; + if (pt.x == pt2.x && pt.y == pt2.y) + return; + sw = pmi.rcMonitor.right - pmi.rcMonitor.left; + sh = pmi.rcMonitor.bottom - pmi.rcMonitor.top; + dx = dialog_x_offset; + dy = dialog_y_offset; + GetWindowRect (hDlg, &rc); + rc.right -= rc.left; + rc.bottom -= rc.top; + rc.left = 0; + rc.top = 0; + if (rc.right <= sw && rc.bottom <= sh) + return; + pt2.x = pt.x; + pt2.y = pt.y; + + newmx = pt.x; + newmy = pt.y; + + if (newmx >= sw - 1 && rc.right > sw) + dx = sw - rc.right; + if (newmx <= 1) + dx = 0; + if (newmy >= sh - 1 && rc.bottom > sh) + dy = sh - rc.bottom; + if (newmy <= 1) + dy = 0; + + if (dx != dialog_x_offset || dy != dialog_y_offset) { + dialog_x_offset = dx; + dialog_y_offset = dy; + dx += xstart; + dy += ystart; + SetWindowPos (hDlg, 0, dx, dy, 0, 0, + SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DEFERERASE); + } } #if 0 static void blah(void) { - char *str1 = "äöå€õãñëÿüïñç"; - TCHAR *str2 = L"äöå€õãñëÿüïñç"; - TCHAR *s1; - char *s2; - MessageBoxA(NULL, str1, "Test1 ANSI", MB_OK); - s1 = au (str1); - MessageBoxW(NULL, s1, L"Test1 UNICODE", MB_OK); + char *str1 = "äöå€õãñëÿüïñç"; + TCHAR *str2 = L"äöå€õãñëÿüïñç"; + TCHAR *s1; + char *s2; + MessageBoxA(NULL, str1, "Test1 ANSI", MB_OK); + s1 = au (str1); + MessageBoxW(NULL, s1, L"Test1 UNICODE", MB_OK); - MessageBoxW(NULL, str2, L"Test2 UNICODE", MB_OK); - s2 = ua (str2); - MessageBoxA(NULL, s2, "Test2 ANSI", MB_OK); + MessageBoxW(NULL, str2, L"Test2 UNICODE", MB_OK); + s2 = ua (str2); + MessageBoxA(NULL, s2, "Test2 ANSI", MB_OK); } #endif static int GetSettings (int all_options, HWND hwnd) { - static int init_called = 0; - int psresult; - HWND dhwnd; - int first = 0; - static struct newresource *panelresource; - struct newresource *tres; - - gui_active++; - - full_property_sheet = all_options; - allow_quit = all_options; - pguiprefs = &currprefs; - default_prefs (&workprefs, 0); - - WIN32GUI_LoadUIString (IDS_NONE, szNone, MAX_DPATH); - prefs_to_gui (&changed_prefs); - - if (!init_called) { - first = 1; - panelresource = getresource (IDD_PANEL); - LOADSAVE_ID = init_page (IDD_LOADSAVE, IDI_FILE, IDS_LOADSAVE, LoadSaveDlgProc, NULL, L"gui/configurations.htm"); - MEMORY_ID = init_page (IDD_MEMORY, IDI_MEMORY, IDS_MEMORY, MemoryDlgProc, NULL, L"gui/ram.htm"); - EXPANSION_ID = init_page (IDD_EXPANSION, IDI_DISPLAY, IDS_EXPANSION, ExpansionDlgProc, NULL, L"gui/expansion.htm"); - KICKSTART_ID = init_page (IDD_KICKSTART, IDI_MEMORY, IDS_KICKSTART, KickstartDlgProc, NULL, L"gui/rom.htm"); - CPU_ID = init_page (IDD_CPU, IDI_CPU, IDS_CPU, CPUDlgProc, NULL, L"gui/cpu.htm"); - DISPLAY_ID = init_page (IDD_DISPLAY, IDI_DISPLAY, IDS_DISPLAY, DisplayDlgProc, NULL, L"gui/display.htm"); + static int init_called = 0; + int psresult; + HWND dhwnd; + int first = 0; + static struct newresource *panelresource; + struct newresource *tres; + + gui_active++; + + full_property_sheet = all_options; + allow_quit = all_options; + pguiprefs = &currprefs; + default_prefs (&workprefs, 0); + + WIN32GUI_LoadUIString (IDS_NONE, szNone, MAX_DPATH); + prefs_to_gui (&changed_prefs); + + if (!init_called) { + first = 1; + panelresource = getresource (IDD_PANEL); + LOADSAVE_ID = init_page (IDD_LOADSAVE, IDI_FILE, IDS_LOADSAVE, LoadSaveDlgProc, NULL, L"gui/configurations.htm"); + MEMORY_ID = init_page (IDD_MEMORY, IDI_MEMORY, IDS_MEMORY, MemoryDlgProc, NULL, L"gui/ram.htm"); + EXPANSION_ID = init_page (IDD_EXPANSION, IDI_DISPLAY, IDS_EXPANSION, ExpansionDlgProc, NULL, L"gui/expansion.htm"); + KICKSTART_ID = init_page (IDD_KICKSTART, IDI_MEMORY, IDS_KICKSTART, KickstartDlgProc, NULL, L"gui/rom.htm"); + CPU_ID = init_page (IDD_CPU, IDI_CPU, IDS_CPU, CPUDlgProc, NULL, L"gui/cpu.htm"); + DISPLAY_ID = init_page (IDD_DISPLAY, IDI_DISPLAY, IDS_DISPLAY, DisplayDlgProc, NULL, L"gui/display.htm"); #if defined (GFXFILTER) - HW3D_ID = init_page (IDD_FILTER, IDI_DISPLAY, IDS_FILTER, hw3dDlgProc, NULL, L"gui/filter.htm"); + HW3D_ID = init_page (IDD_FILTER, IDI_DISPLAY, IDS_FILTER, hw3dDlgProc, NULL, L"gui/filter.htm"); #endif - CHIPSET_ID = init_page (IDD_CHIPSET, IDI_CPU, IDS_CHIPSET, ChipsetDlgProc, NULL, L"gui/chipset.htm"); - CHIPSET2_ID = init_page (IDD_CHIPSET2, IDI_CPU, IDS_CHIPSET2, ChipsetDlgProc2, NULL, L"gui/chipset.htm"); - SOUND_ID = init_page (IDD_SOUND, IDI_SOUND, IDS_SOUND, SoundDlgProc, NULL, L"gui/sound.htm"); - FLOPPY_ID = init_page (IDD_FLOPPY, IDI_FLOPPY, IDS_FLOPPY, FloppyDlgProc, NULL, L"gui/floppies.htm"); - DISK_ID = init_page (IDD_DISK, IDI_FLOPPY, IDS_DISK, SwapperDlgProc, SwapperAccel, L"gui/disk.htm"); + CHIPSET_ID = init_page (IDD_CHIPSET, IDI_CPU, IDS_CHIPSET, ChipsetDlgProc, NULL, L"gui/chipset.htm"); + CHIPSET2_ID = init_page (IDD_CHIPSET2, IDI_CPU, IDS_CHIPSET2, ChipsetDlgProc2, NULL, L"gui/chipset.htm"); + SOUND_ID = init_page (IDD_SOUND, IDI_SOUND, IDS_SOUND, SoundDlgProc, NULL, L"gui/sound.htm"); + FLOPPY_ID = init_page (IDD_FLOPPY, IDI_FLOPPY, IDS_FLOPPY, FloppyDlgProc, NULL, L"gui/floppies.htm"); + DISK_ID = init_page (IDD_DISK, IDI_FLOPPY, IDS_DISK, SwapperDlgProc, SwapperAccel, L"gui/disk.htm"); #ifdef FILESYS - HARDDISK_ID = init_page (IDD_HARDDISK, IDI_HARDDISK, IDS_HARDDISK, HarddiskDlgProc, HarddiskAccel, L"gui/hard-drives.htm"); + HARDDISK_ID = init_page (IDD_HARDDISK, IDI_HARDDISK, IDS_HARDDISK, HarddiskDlgProc, HarddiskAccel, L"gui/hard-drives.htm"); #endif - GAMEPORTS_ID = init_page (IDD_GAMEPORTS, IDI_GAMEPORTS, IDS_GAMEPORTS, GamePortsDlgProc, NULL, L"gui/gameports.htm"); - IOPORTS_ID = init_page (IDD_IOPORTS, IDI_PORTS, IDS_IOPORTS, IOPortsDlgProc, NULL, L"gui/ioports.htm"); - INPUT_ID = init_page (IDD_INPUT, IDI_INPUT, IDS_INPUT, InputDlgProc, NULL, L"gui/input.htm"); - MISC1_ID = init_page (IDD_MISC1, IDI_MISC1, IDS_MISC1, MiscDlgProc1, NULL, L"gui/misc.htm"); - MISC2_ID = init_page (IDD_MISC2, IDI_MISC2, IDS_MISC2, MiscDlgProc2, NULL, L"gui/misc2.htm"); + GAMEPORTS_ID = init_page (IDD_GAMEPORTS, IDI_GAMEPORTS, IDS_GAMEPORTS, GamePortsDlgProc, NULL, L"gui/gameports.htm"); + IOPORTS_ID = init_page (IDD_IOPORTS, IDI_PORTS, IDS_IOPORTS, IOPortsDlgProc, NULL, L"gui/ioports.htm"); + INPUT_ID = init_page (IDD_INPUT, IDI_INPUT, IDS_INPUT, InputDlgProc, NULL, L"gui/input.htm"); + MISC1_ID = init_page (IDD_MISC1, IDI_MISC1, IDS_MISC1, MiscDlgProc1, NULL, L"gui/misc.htm"); + MISC2_ID = init_page (IDD_MISC2, IDI_MISC2, IDS_MISC2, MiscDlgProc2, NULL, L"gui/misc2.htm"); #ifdef AVIOUTPUT - AVIOUTPUT_ID = init_page (IDD_AVIOUTPUT, IDI_AVIOUTPUT, IDS_AVIOUTPUT, AVIOutputDlgProc, NULL, L"gui/output.htm"); + AVIOUTPUT_ID = init_page (IDD_AVIOUTPUT, IDI_AVIOUTPUT, IDS_AVIOUTPUT, AVIOutputDlgProc, NULL, L"gui/output.htm"); #endif - PATHS_ID = init_page (IDD_PATHS, IDI_PATHS, IDS_PATHS, PathsDlgProc, NULL, L"gui/paths.htm"); - QUICKSTART_ID = init_page (IDD_QUICKSTART, IDI_QUICKSTART, IDS_QUICKSTART, QuickstartDlgProc, NULL, L"gui/quickstart.htm"); - ABOUT_ID = init_page (IDD_ABOUT, IDI_ABOUT, IDS_ABOUT, AboutDlgProc, NULL, NULL); - FRONTEND_ID = init_page (IDD_FRONTEND, IDI_QUICKSTART, IDS_FRONTEND, AboutDlgProc, NULL, NULL); - C_PAGES = FRONTEND_ID + 1; - init_called = 1; - if (quickstart && !qs_override) - currentpage = QUICKSTART_ID; - else - currentpage = LOADSAVE_ID; - } - - if (all_options || !configstore) - CreateConfigStore (NULL, FALSE); - - dialogreturn = -1; - hAccelTable = NULL; - DragAcceptFiles (hwnd, TRUE); - if (first) - write_log (L"Entering GUI idle loop\n"); - //blah(); - - scaleresource_setmaxsize (800, 600); - tres = scaleresource (panelresource, hwnd); - dhwnd = CreateDialogIndirect (tres->inst, tres->resource, hwnd, DialogProc); - dialog_rect.top = dialog_rect.left = 0; - dialog_rect.right = tres->width; - dialog_rect.bottom = tres->height; - freescaleresource(tres); - psresult = 0; - if (dhwnd != NULL) { - MSG msg; - DWORD v; - - setguititle (dhwnd); - ShowWindow (dhwnd, SW_SHOW); - MapDialogRect (dhwnd, &dialog_rect); - hGUIWnd = dhwnd; + PATHS_ID = init_page (IDD_PATHS, IDI_PATHS, IDS_PATHS, PathsDlgProc, NULL, L"gui/paths.htm"); + QUICKSTART_ID = init_page (IDD_QUICKSTART, IDI_QUICKSTART, IDS_QUICKSTART, QuickstartDlgProc, NULL, L"gui/quickstart.htm"); + ABOUT_ID = init_page (IDD_ABOUT, IDI_ABOUT, IDS_ABOUT, AboutDlgProc, NULL, NULL); + FRONTEND_ID = init_page (IDD_FRONTEND, IDI_QUICKSTART, IDS_FRONTEND, AboutDlgProc, NULL, NULL); + C_PAGES = FRONTEND_ID + 1; + init_called = 1; + if (quickstart && !qs_override) + currentpage = QUICKSTART_ID; + else + currentpage = LOADSAVE_ID; + } - for (;;) { - HANDLE IPChandle; - IPChandle = geteventhandleIPC (globalipc); - if (globalipc && IPChandle != INVALID_HANDLE_VALUE) { - MsgWaitForMultipleObjects (1, &IPChandle, FALSE, INFINITE, QS_ALLINPUT); - while (checkIPC (globalipc, &workprefs)); - } else { - WaitMessage(); - } - dialogmousemove (dhwnd); - while ((v = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))) { - if (dialogreturn >= 0) - break; - if (v == -1) - continue; - if (!IsWindow (dhwnd)) - continue; - if (hAccelTable && panelDlg) { - if (TranslateAccelerator (panelDlg, hAccelTable, &msg)) - continue; + if (all_options || !configstore) + CreateConfigStore (NULL, FALSE); + + dialogreturn = -1; + hAccelTable = NULL; + DragAcceptFiles (hwnd, TRUE); + if (first) + write_log (L"Entering GUI idle loop\n"); + //blah(); + + scaleresource_setmaxsize (800, 600); + tres = scaleresource (panelresource, hwnd); + dhwnd = CreateDialogIndirect (tres->inst, tres->resource, hwnd, DialogProc); + dialog_rect.top = dialog_rect.left = 0; + dialog_rect.right = tres->width; + dialog_rect.bottom = tres->height; + freescaleresource(tres); + psresult = 0; + if (dhwnd != NULL) { + MSG msg; + DWORD v; + + setguititle (dhwnd); + ShowWindow (dhwnd, SW_SHOW); + MapDialogRect (dhwnd, &dialog_rect); + hGUIWnd = dhwnd; + + for (;;) { + HANDLE IPChandle; + IPChandle = geteventhandleIPC (globalipc); + if (globalipc && IPChandle != INVALID_HANDLE_VALUE) { + MsgWaitForMultipleObjects (1, &IPChandle, FALSE, INFINITE, QS_ALLINPUT); + while (checkIPC (globalipc, &workprefs)); + } else { + WaitMessage(); + } + dialogmousemove (dhwnd); + while ((v = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))) { + if (dialogreturn >= 0) + break; + if (v == -1) + continue; + if (!IsWindow (dhwnd)) + continue; + if (hAccelTable && panelDlg) { + if (TranslateAccelerator (panelDlg, hAccelTable, &msg)) + continue; + } + if (IsDialogMessage (dhwnd, &msg)) + continue; + TranslateMessage (&msg); + DispatchMessage (&msg); + } + if (dialogreturn >= 0) + break; } - if (IsDialogMessage (dhwnd, &msg)) - continue; - TranslateMessage (&msg); - DispatchMessage (&msg); - } - if (dialogreturn >= 0) - break; + psresult = dialogreturn; } - psresult = dialogreturn; - } - hGUIWnd = NULL; - if (quit_program) - psresult = -2; - else if (qs_request_reset && quickstart) - uae_reset (qs_request_reset == 2 ? 1 : 0); + hGUIWnd = NULL; + if (quit_program) + psresult = -2; + else if (qs_request_reset && quickstart) + uae_reset (qs_request_reset == 2 ? 1 : 0); - qs_request_reset = 0; - full_property_sheet = 0; - gui_active--; - return psresult; + qs_request_reset = 0; + full_property_sheet = 0; + gui_active--; + return psresult; } int gui_init (void) { - int ret; - - read_rom_list (); - inputdevice_updateconfig (&workprefs); - for (;;) { - ret = GetSettings (1, currprefs.win32_notaskbarbutton ? hHiddenWnd : NULL); - if (!restart_requested) - break; - restart_requested = 0; - } - if (ret > 0) { + int ret; + + read_rom_list (); + inputdevice_updateconfig (&workprefs); + for (;;) { + ret = GetSettings (1, currprefs.win32_notaskbarbutton ? hHiddenWnd : NULL); + if (!restart_requested) + break; + restart_requested = 0; + } + if (ret > 0) { #ifdef AVIOUTPUT - AVIOutput_Begin (); + AVIOutput_Begin (); #endif - } - return ret; + } + return ret; } int gui_update (void) { - return 1; + return 1; } void gui_exit (void) { - int i; + int i; - for (i = 0; i < C_PAGES; i++) { - if (ppage[i].accel) - DestroyAcceleratorTable (ppage[i].accel); - ppage[i].accel = NULL; - } - FreeConfigStore (); + for (i = 0; i < C_PAGES; i++) { + if (ppage[i].accel) + DestroyAcceleratorTable (ppage[i].accel); + ppage[i].accel = NULL; + } + FreeConfigStore (); #ifdef PARALLEL_PORT - closeprinter (); // Bernd Roesch + closeprinter (); // Bernd Roesch #endif } @@ -12619,149 +12631,149 @@ void check_prefs_changed_gui (void) void gui_disk_image_change (int unitnum, const TCHAR *name) { #ifdef RETROPLATFORM - rp_disk_image_change (unitnum, name); + rp_disk_image_change (unitnum, name); #endif } void gui_hd_led (int unitnum, int led) { - static int resetcounter; - int old; - - old = gui_data.hd; - if (led == 0) { - resetcounter--; - if (resetcounter > 0) - return; - } + static int resetcounter; + int old; + + old = gui_data.hd; + if (led == 0) { + resetcounter--; + if (resetcounter > 0) + return; + } #ifdef RETROPLATFORM - rp_hd_activity (unitnum, led ? 1 : 0, led == 2 ? 1 : 0); + rp_hd_activity (unitnum, led ? 1 : 0, led == 2 ? 1 : 0); #endif - gui_data.hd = led; - resetcounter = 6; - if (old != gui_data.hd) - gui_led (5, gui_data.hd); + gui_data.hd = led; + resetcounter = 6; + if (old != gui_data.hd) + gui_led (5, gui_data.hd); } void gui_cd_led (int unitnum, int led) { - static int resetcounter; - int old; - - old = gui_data.cd; - if (led == 0) { - resetcounter--; - if (resetcounter > 0) - return; - } - if (led < 0) - led = 0; + static int resetcounter; + int old; + + old = gui_data.cd; + if (led == 0) { + resetcounter--; + if (resetcounter > 0) + return; + } + if (led < 0) + led = 0; #ifdef RETROPLATFORM - rp_cd_activity (unitnum, led); + rp_cd_activity (unitnum, led); #endif - gui_data.cd = led; - resetcounter = 6; - if (old != gui_data.cd) - gui_led (6, gui_data.cd); + gui_data.cd = led; + resetcounter = 6; + if (old != gui_data.cd) + gui_led (6, gui_data.cd); } void gui_fps (int fps, int idle) { - gui_data.fps = fps; - gui_data.idle = idle; - gui_led (7, 0); - gui_led (8, 0); - gui_led (9, gui_data.sndbuf_status > 1 || gui_data.sndbuf_status < 0); + gui_data.fps = fps; + gui_data.idle = idle; + gui_led (7, 0); + gui_led (8, 0); + gui_led (9, gui_data.sndbuf_status > 1 || gui_data.sndbuf_status < 0); } void gui_led (int led, int on) { - WORD type; - static TCHAR drive_text[NUM_LEDS * 16]; - static TCHAR dfx[4][300]; - TCHAR *ptr, *tt, *p; - int pos = -1, j; - int writing = 0; + WORD type; + static TCHAR drive_text[NUM_LEDS * 16]; + static TCHAR dfx[4][300]; + TCHAR *ptr, *tt, *p; + int pos = -1, j; + int writing = 0; - indicator_leds (led, on); + indicator_leds (led, on); #ifdef LOGITECHLCD - lcd_update (led, on); + lcd_update (led, on); #endif #ifdef RETROPLATFORM - if (led >= 1 && led <= 4 && !gui_data.drive_disabled[led - 1]) { - rp_floppy_track (led - 1, gui_data.drive_track[led - 1]); - writing = gui_data.drive_writing[led - 1]; - } - rp_update_leds (led, on, writing); + if (led >= 1 && led <= 4 && !gui_data.drive_disabled[led - 1]) { + rp_floppy_track (led - 1, gui_data.drive_track[led - 1]); + writing = gui_data.drive_writing[led - 1]; + } + rp_update_leds (led, on, writing); #endif - if (!hStatusWnd) - return; - tt = NULL; - if (led >= 1 && led <= 4) { - pos = 6 + (led - 1); - ptr = drive_text + pos * 16; - if (gui_data.drive_disabled[led - 1]) - _tcscpy (ptr, L""); - else - _stprintf (ptr , L"%02d .", gui_data.drive_track[led - 1]); - p = gui_data.df[led - 1]; - j = _tcslen (p) - 1; - if (j < 0) - j = 0; - while (j > 0) { - if (p[j - 1] == '\\' || p[j - 1] == '/') - break; - j--; - } - tt = dfx[led - 1]; - tt[0] = 0; - if (_tcslen (p + j) > 0) - _stprintf (tt, L"%s [CRC=%08X]", p + j, gui_data.crc32[led - 1]); - } else if (led == 0) { - pos = 3; - ptr = _tcscpy (drive_text + pos * 16, L"Power"); - } else if (led == 5) { - pos = 4; - ptr = _tcscpy (drive_text + pos * 16, L"HD"); - } else if (led == 6) { - pos = 5; - ptr = _tcscpy (drive_text + pos * 16, L"CD"); - } else if (led == 7) { - double fps = (double)gui_data.fps / 10.0; - extern int p96vblank; - pos = 2; - ptr = drive_text + pos * 16; - if (fps > 999.9) - fps = 999.9; - if (picasso_on) - _stprintf (ptr, L"%d [%.1f]", p96vblank, fps); + if (!hStatusWnd) + return; + tt = NULL; + if (led >= 1 && led <= 4) { + pos = 6 + (led - 1); + ptr = drive_text + pos * 16; + if (gui_data.drive_disabled[led - 1]) + _tcscpy (ptr, L""); + else + _stprintf (ptr , L"%02d .", gui_data.drive_track[led - 1]); + p = gui_data.df[led - 1]; + j = _tcslen (p) - 1; + if (j < 0) + j = 0; + while (j > 0) { + if (p[j - 1] == '\\' || p[j - 1] == '/') + break; + j--; + } + tt = dfx[led - 1]; + tt[0] = 0; + if (_tcslen (p + j) > 0) + _stprintf (tt, L"%s [CRC=%08X]", p + j, gui_data.crc32[led - 1]); + } else if (led == 0) { + pos = 3; + ptr = _tcscpy (drive_text + pos * 16, L"Power"); + } else if (led == 5) { + pos = 4; + ptr = _tcscpy (drive_text + pos * 16, L"HD"); + } else if (led == 6) { + pos = 5; + ptr = _tcscpy (drive_text + pos * 16, L"CD"); + } else if (led == 7) { + double fps = (double)gui_data.fps / 10.0; + extern int p96vblank; + pos = 2; + ptr = drive_text + pos * 16; + if (fps > 999.9) + fps = 999.9; + if (picasso_on) + _stprintf (ptr, L"%d [%.1f]", p96vblank, fps); + else + _stprintf (ptr, L"FPS: %.1f", fps); + if (pause_emulation) + _tcscpy (ptr, L"PAUSED"); + } else if (led == 8) { + pos = 1; + ptr = drive_text + pos * 16; + _stprintf (ptr, L"CPU: %.0f%%", (double)((gui_data.idle) / 10.0)); + } else if (led == 9) { + pos = 0; + ptr = drive_text + pos * 16; + if (gui_data.sndbuf_status < 3) { + _stprintf (ptr, L"SND: %+.0f%%", (double)((gui_data.sndbuf) / 10.0)); + } else { + _tcscpy (ptr, L"SND: -"); + on = 0; + } + } + if (on) + type = SBT_POPOUT; else - _stprintf (ptr, L"FPS: %.1f", fps); - if (pause_emulation) - _tcscpy (ptr, L"PAUSED"); - } else if (led == 8) { - pos = 1; - ptr = drive_text + pos * 16; - _stprintf (ptr, L"CPU: %.0f%%", (double)((gui_data.idle) / 10.0)); - } else if (led == 9) { - pos = 0; - ptr = drive_text + pos * 16; - if (gui_data.sndbuf_status < 3) { - _stprintf (ptr, L"SND: %+.0f%%", (double)((gui_data.sndbuf) / 10.0)); - } else { - _tcscpy (ptr, L"SND: -"); - on = 0; + type = 0; + if (pos >= 0) { + PostMessage (hStatusWnd, SB_SETTEXT, (WPARAM) ((pos + 1) | type), (LPARAM) ptr); + if (tt != NULL) + PostMessage (hStatusWnd, SB_SETTIPTEXT, (WPARAM) (pos + 1), (LPARAM) tt); } - } - if (on) - type = SBT_POPOUT; - else - type = 0; - if (pos >= 0) { - PostMessage (hStatusWnd, SB_SETTEXT, (WPARAM) ((pos + 1) | type), (LPARAM) ptr); - if (tt != NULL) - PostMessage (hStatusWnd, SB_SETTIPTEXT, (WPARAM) (pos + 1), (LPARAM) tt); - } } void gui_filename (int num, const TCHAR *name) @@ -12771,233 +12783,233 @@ void gui_filename (int num, const TCHAR *name) static int fsdialog (HWND *hwnd, DWORD *flags) { - HRESULT hr; + HRESULT hr; - if (gui_active) { - *hwnd = guiDlg; + if (gui_active) { + *hwnd = guiDlg; + *flags |= MB_SETFOREGROUND; + return 0; + } + *hwnd = hAmigaWnd; + if (isfullscreen () <= 0) + return 0; + hr = DirectDraw_FlipToGDISurface (); + if (FAILED (hr)) + write_log (L"FlipToGDISurface failed, %s\n", DXError (hr)); *flags |= MB_SETFOREGROUND; + *flags |= MB_TOPMOST; return 0; - } - *hwnd = hAmigaWnd; - if (isfullscreen () <= 0) - return 0; - hr = DirectDraw_FlipToGDISurface (); - if (FAILED (hr)) - write_log (L"FlipToGDISurface failed, %s\n", DXError (hr)); - *flags |= MB_SETFOREGROUND; - *flags |= MB_TOPMOST; - return 0; -/* - HRESULT hr; - hr = DirectDraw_FlipToGDISurface(); - if (FAILED(hr)) { + /* + HRESULT hr; + hr = DirectDraw_FlipToGDISurface(); + if (FAILED(hr)) { write_log (L"FlipToGDISurface failed, %s\n", DXError (hr)); return 0; - } - *hwnd = NULL; - return 1; -*/ + } + *hwnd = NULL; + return 1; + */ } int gui_message_multibutton (int flags, const TCHAR *format,...) { - TCHAR msg[2048]; - TCHAR szTitle[MAX_DPATH]; - va_list parms; - int flipflop = 0; - int fullscreen = 0; - int focuso = isfocus (); - int mbflags, ret; - HWND hwnd; - - mbflags = MB_ICONWARNING | MB_TASKMODAL; - if (flags == 0) - mbflags |= MB_OK; - else if (flags == 1) - mbflags |= MB_YESNO; - else if (flags == 2) - mbflags |= MB_YESNOCANCEL; - - flipflop = fsdialog (&hwnd, &mbflags); - if (!gui_active) { - pause_sound (); - if (flipflop) - ShowWindow (hAmigaWnd, SW_MINIMIZE); - } - - va_start (parms, format); - _vstprintf (msg, format, parms); - va_end (parms); - write_log (msg); - if (msg[_tcslen (msg) - 1]!='\n') - write_log (L"\n"); - - WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); - - ret = MessageBox (hwnd, msg, szTitle, mbflags); - - if (!gui_active) { - if (flipflop) - ShowWindow (hAmigaWnd, SW_RESTORE); - resume_sound (); - setmouseactive (focuso > 0 ? 1 : 0); - } - if (ret == IDOK) + TCHAR msg[2048]; + TCHAR szTitle[MAX_DPATH]; + va_list parms; + int flipflop = 0; + int fullscreen = 0; + int focuso = isfocus (); + int mbflags, ret; + HWND hwnd; + + mbflags = MB_ICONWARNING | MB_TASKMODAL; + if (flags == 0) + mbflags |= MB_OK; + else if (flags == 1) + mbflags |= MB_YESNO; + else if (flags == 2) + mbflags |= MB_YESNOCANCEL; + + flipflop = fsdialog (&hwnd, &mbflags); + if (!gui_active) { + pause_sound (); + if (flipflop) + ShowWindow (hAmigaWnd, SW_MINIMIZE); + } + + va_start (parms, format); + _vsntprintf (msg, sizeof msg / sizeof (TCHAR), format, parms); + va_end (parms); + write_log (msg); + if (msg[_tcslen (msg) - 1]!='\n') + write_log (L"\n"); + + WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); + + ret = MessageBox (hwnd, msg, szTitle, mbflags); + + if (!gui_active) { + if (flipflop) + ShowWindow (hAmigaWnd, SW_RESTORE); + resume_sound (); + setmouseactive (focuso > 0 ? 1 : 0); + } + if (ret == IDOK) + return 0; + if (ret == IDYES) + return 1; + if (ret == IDNO) + return 2; + if (ret == IDCANCEL) + return -1; return 0; - if (ret == IDYES) - return 1; - if (ret == IDNO) - return 2; - if (ret == IDCANCEL) - return -1; - return 0; } void gui_message (const TCHAR *format,...) { - TCHAR msg[2048]; - TCHAR szTitle[MAX_DPATH]; - va_list parms; - int flipflop = 0; - int fullscreen = 0; - int focuso = isfocus (); - DWORD flags = MB_OK | MB_TASKMODAL; - HWND hwnd; - - va_start (parms, format); - _vstprintf (msg, format, parms); - va_end (parms); - - if (full_property_sheet) { - pre_gui_message (msg); - return; - } + TCHAR msg[2048]; + TCHAR szTitle[MAX_DPATH]; + va_list parms; + int flipflop = 0; + int fullscreen = 0; + int focuso = isfocus (); + DWORD flags = MB_OK | MB_TASKMODAL; + HWND hwnd; + + va_start (parms, format); + _vsntprintf (msg, sizeof msg / sizeof (TCHAR), format, parms); + va_end (parms); + + if (full_property_sheet) { + pre_gui_message (msg); + return; + } - flipflop = fsdialog (&hwnd, &flags); - if (!gui_active) { - pause_sound (); - if (flipflop) - ShowWindow (hAmigaWnd, SW_MINIMIZE); - } + flipflop = fsdialog (&hwnd, &flags); + if (!gui_active) { + pause_sound (); + if (flipflop) + ShowWindow (hAmigaWnd, SW_MINIMIZE); + } - write_log (msg); - if (msg[_tcslen (msg) - 1] != '\n') - write_log (L"\n"); + write_log (msg); + if (msg[_tcslen (msg) - 1] != '\n') + write_log (L"\n"); - WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); - if (!MessageBox (hwnd, msg, szTitle, flags)) - write_log (L"MessageBox(%s) failed, err=%d\n", msg, GetLastError ()); + if (!MessageBox (hwnd, msg, szTitle, flags)) + write_log (L"MessageBox(%s) failed, err=%d\n", msg, GetLastError ()); - if (!gui_active) { - if (flipflop) - ShowWindow (hAmigaWnd, SW_RESTORE); - resume_sound (); - setmouseactive (focuso > 0 ? 1 : 0); - } + if (!gui_active) { + if (flipflop) + ShowWindow (hAmigaWnd, SW_RESTORE); + resume_sound (); + setmouseactive (focuso > 0 ? 1 : 0); + } } void gui_message_id (int id) { - TCHAR msg[MAX_DPATH]; - WIN32GUI_LoadUIString (id, msg, sizeof (msg) / sizeof (TCHAR)); - gui_message (msg); + TCHAR msg[MAX_DPATH]; + WIN32GUI_LoadUIString (id, msg, sizeof (msg) / sizeof (TCHAR)); + gui_message (msg); } void pre_gui_message (const TCHAR *format,...) { - TCHAR msg[2048]; - TCHAR szTitle[MAX_DPATH]; - va_list parms; + TCHAR msg[2048]; + TCHAR szTitle[MAX_DPATH]; + va_list parms; - va_start (parms, format); - _vstprintf (msg, format, parms); - va_end (parms); - write_log (msg); - if (msg[_tcslen (msg) - 1] != '\n') - write_log (L"\n"); + va_start (parms, format); + _vsntprintf (msg, sizeof msg / sizeof (TCHAR), format, parms); + va_end (parms); + write_log (msg); + if (msg[_tcslen (msg) - 1] != '\n') + write_log (L"\n"); - WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); - _tcscat (szTitle, BetaStr); - MessageBox (guiDlg, msg, szTitle, MB_OK | MB_TASKMODAL | MB_SETFOREGROUND); + WIN32GUI_LoadUIString (IDS_ERRORTITLE, szTitle, MAX_DPATH); + _tcscat (szTitle, BetaStr); + MessageBox (guiDlg, msg, szTitle, MB_OK | MB_TASKMODAL | MB_SETFOREGROUND); } static int transla[] = { - NUMSG_NEEDEXT2, IDS_NUMSG_NEEDEXT2, - NUMSG_NOROMKEY,IDS_NUMSG_NOROMKEY, - NUMSG_NOROM,IDS_NUMSG_NOROM, - NUMSG_KSROMCRCERROR,IDS_NUMSG_KSROMCRCERROR, - NUMSG_KSROMREADERROR,IDS_NUMSG_KSROMREADERROR, - NUMSG_NOEXTROM,IDS_NUMSG_NOEXTROM, - NUMSG_MODRIP_NOTFOUND,IDS_NUMSG_MODRIP_NOTFOUND, - NUMSG_MODRIP_FINISHED,IDS_NUMSG_MODRIP_FINISHED, - NUMSG_MODRIP_SAVE,IDS_NUMSG_MODRIP_SAVE, - NUMSG_KS68EC020,IDS_NUMSG_KS68EC020, - NUMSG_KS68020,IDS_NUMSG_KS68020, - NUMSG_KS68030,IDS_NUMSG_KS68030, - NUMSG_ROMNEED,IDS_NUMSG_ROMNEED, - NUMSG_EXPROMNEED,IDS_NUMSG_EXPROMNEED, - NUMSG_NOZLIB,IDS_NUMSG_NOZLIB, - NUMSG_STATEHD,IDS_NUMSG_STATEHD, - NUMSG_OLDCAPS, IDS_NUMSG_OLDCAPS, - NUMSG_NOCAPS, IDS_NUMSG_NOCAPS, - NUMSG_KICKREP, IDS_NUMSG_KICKREP, - NUMSG_KICKREPNO, IDS_NUMSG_KICKREPNO, - -1 + NUMSG_NEEDEXT2, IDS_NUMSG_NEEDEXT2, + NUMSG_NOROMKEY,IDS_NUMSG_NOROMKEY, + NUMSG_NOROM,IDS_NUMSG_NOROM, + NUMSG_KSROMCRCERROR,IDS_NUMSG_KSROMCRCERROR, + NUMSG_KSROMREADERROR,IDS_NUMSG_KSROMREADERROR, + NUMSG_NOEXTROM,IDS_NUMSG_NOEXTROM, + NUMSG_MODRIP_NOTFOUND,IDS_NUMSG_MODRIP_NOTFOUND, + NUMSG_MODRIP_FINISHED,IDS_NUMSG_MODRIP_FINISHED, + NUMSG_MODRIP_SAVE,IDS_NUMSG_MODRIP_SAVE, + NUMSG_KS68EC020,IDS_NUMSG_KS68EC020, + NUMSG_KS68020,IDS_NUMSG_KS68020, + NUMSG_KS68030,IDS_NUMSG_KS68030, + NUMSG_ROMNEED,IDS_NUMSG_ROMNEED, + NUMSG_EXPROMNEED,IDS_NUMSG_EXPROMNEED, + NUMSG_NOZLIB,IDS_NUMSG_NOZLIB, + NUMSG_STATEHD,IDS_NUMSG_STATEHD, + NUMSG_OLDCAPS, IDS_NUMSG_OLDCAPS, + NUMSG_NOCAPS, IDS_NUMSG_NOCAPS, + NUMSG_KICKREP, IDS_NUMSG_KICKREP, + NUMSG_KICKREPNO, IDS_NUMSG_KICKREPNO, + -1 }; static int gettranslation (int msg) { - int i; + int i; - i = 0; - while (transla[i] >= 0) { - if (transla[i] == msg) - return transla[i + 1]; - i += 2; - } - return -1; + i = 0; + while (transla[i] >= 0) { + if (transla[i] == msg) + return transla[i + 1]; + i += 2; + } + return -1; } void notify_user (int msg) { - TCHAR tmp[MAX_DPATH]; - int c = 0; + TCHAR tmp[MAX_DPATH]; + int c = 0; - c = gettranslation (msg); - if (c < 0) - return; - WIN32GUI_LoadUIString (c, tmp, MAX_DPATH); - gui_message (tmp); + c = gettranslation (msg); + if (c < 0) + return; + WIN32GUI_LoadUIString (c, tmp, MAX_DPATH); + gui_message (tmp); } void notify_user_parms (int msg, const TCHAR *parms, ...) { - TCHAR msgtxt[MAX_DPATH]; - TCHAR tmp[MAX_DPATH]; - int c = 0; - va_list parms2; + TCHAR msgtxt[MAX_DPATH]; + TCHAR tmp[MAX_DPATH]; + int c = 0; + va_list parms2; - c = gettranslation (msg); - if (c < 0) - return; - WIN32GUI_LoadUIString (c, tmp, MAX_DPATH); - va_start (parms2, parms); - _vstprintf (msgtxt, tmp, parms2); - gui_message (msgtxt); - va_end (parms2); + c = gettranslation (msg); + if (c < 0) + return; + WIN32GUI_LoadUIString (c, tmp, MAX_DPATH); + va_start (parms2, parms); + _vsntprintf (msgtxt, sizeof msgtxt / sizeof (TCHAR), tmp, parms2); + gui_message (msgtxt); + va_end (parms2); } int translate_message (int msg, TCHAR *out) { - msg = gettranslation (msg); - out[0] = 0; - if (msg < 0) - return 0; - WIN32GUI_LoadUIString (msg, out, MAX_DPATH); - return 1; + msg = gettranslation (msg); + out[0] = 0; + if (msg < 0) + return 0; + WIN32GUI_LoadUIString (msg, out, MAX_DPATH); + return 1; } void gui_lock (void) diff --git a/od-win32/win32gui_extra.c b/od-win32/win32gui_extra.c index ad2cbe72..ca9f0884 100644 --- a/od-win32/win32gui_extra.c +++ b/od-win32/win32gui_extra.c @@ -29,45 +29,45 @@ static int max_w = 800, max_h = 600, mult = 100, pointsize; #include typedef struct { - WORD dlgVer; - WORD signature; - DWORD helpID; - DWORD exStyle; - DWORD style; - WORD cDlgItems; - short x; - short y; - short cx; - short cy; -/* - sz_Or_Ord menu; - sz_Or_Ord windowClass; - WCHAR title[titleLen]; -*/ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; + /* + sz_Or_Ord menu; + sz_Or_Ord windowClass; + WCHAR title[titleLen]; + */ } DLGTEMPLATEEX; typedef struct { - WORD pointsize; - WORD weight; - BYTE italic; - BYTE charset; - WCHAR typeface[0]; + WORD pointsize; + WORD weight; + BYTE italic; + BYTE charset; + WCHAR typeface[0]; } DLGTEMPLATEEX_END; typedef struct { - DWORD helpID; - DWORD exStyle; - DWORD style; - short x; - short y; - short cx; - short cy; - WORD id; - WORD reserved; - WCHAR windowClass[0]; - /* variable data after this */ - /* sz_Or_Ord title; */ - /* WORD extraCount; */ + DWORD helpID; + DWORD exStyle; + DWORD style; + short x; + short y; + short cx; + short cy; + WORD id; + WORD reserved; + WCHAR windowClass[0]; + /* variable data after this */ + /* sz_Or_Ord title; */ + /* WORD extraCount; */ } DLGITEMTEMPLATEEX; #include @@ -81,140 +81,140 @@ static TCHAR font_xp[] = L"Tahoma"; static BYTE *skiptext (BYTE *s) { - if (s[0] == 0xff && s[1] == 0xff) { - s += 4; - return s; - } - while (s[0] != 0 || s[1] != 0) + if (s[0] == 0xff && s[1] == 0xff) { + s += 4; + return s; + } + while (s[0] != 0 || s[1] != 0) + s += 2; s += 2; - s += 2; - return s; + return s; } static BYTE *todword (BYTE *p) { - while ((LONG_PTR)p & 3) - p++; - return p; + while ((LONG_PTR)p & 3) + p++; + return p; } static void modifytemplate (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2, int id, int mult) { - d->cx = d->cx * mult / 100; - d->cy = d->cy * mult / 100; + d->cx = d->cx * mult / 100; + d->cy = d->cy * mult / 100; } static void modifytemplatefont (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2) { - wchar_t *p = NULL; - - if (font_vista_ok) - p = wfont_vista; - else - p = wfont_xp; - if (p && !wcscmp (d2->typeface, wfont_old)) - wcscpy (d2->typeface, p); + wchar_t *p = NULL; + + if (font_vista_ok) + p = wfont_vista; + else + p = wfont_xp; + if (p && !wcscmp (d2->typeface, wfont_old)) + wcscpy (d2->typeface, p); } static void modifyitem (DLGTEMPLATEEX *d, DLGTEMPLATEEX_END *d2, DLGITEMTEMPLATEEX *dt, int id, int mult) { - dt->cy = dt->cy * mult / 100; - dt->cx = dt->cx * mult / 100; - dt->y = dt->y * mult / 100; - dt->x = dt->x * mult / 100; + dt->cy = dt->cy * mult / 100; + dt->cx = dt->cx * mult / 100; + dt->y = dt->y * mult / 100; + dt->x = dt->x * mult / 100; } static INT_PTR CALLBACK DummyProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch(msg) + { case WM_DESTROY: - PostQuitMessage (0); - return TRUE; + PostQuitMessage (0); + return TRUE; case WM_CLOSE: - DestroyWindow(hDlg); - return TRUE; + DestroyWindow(hDlg); + return TRUE; case WM_INITDIALOG: - return TRUE; - } - return FALSE; + return TRUE; + } + return FALSE; } struct newresource *scaleresource (struct newresource *res, HWND parent) { - DLGTEMPLATEEX *d; - DLGTEMPLATEEX_END *d2; - DLGITEMTEMPLATEEX *dt; - BYTE *p, *p2; - int i; - struct newresource *ns; - - d = res->resource; - d2 = res->resource; - - if (d->dlgVer != 1 || d->signature != 0xffff) - return 0; - if (!(d->style & (DS_SETFONT | DS_SHELLFONT))) - return 0; - - ns = xcalloc (sizeof (struct newresource), 1); - ns->inst = res->inst; - ns->size = res->size; - ns->tmpl = res->tmpl; - ns->resource = xmalloc (ns->size); - memcpy (ns->resource, res->resource, ns->size); - - d = ns->resource; - d2 = ns->resource; - p = (BYTE*)d + sizeof (DLGTEMPLATEEX); - p = skiptext (p); - p = skiptext (p); - p = skiptext (p); - d2 = (DLGTEMPLATEEX_END*)p; - p2 = p; - p2 += sizeof (DLGTEMPLATEEX_END); - p2 = skiptext (p2); - p2 = todword (p2); - - modifytemplatefont (d, d2); - - p += sizeof (DLGTEMPLATEEX_END); - p = skiptext (p); - p = todword (p); - - if (p != p2) - memmove (p, p2, ns->size - (p2 - (BYTE*)ns->resource)); - - modifytemplate(d, d2, ns->tmpl, mult); - - for (i = 0; i < d->cDlgItems; i++) { - dt = (DLGITEMTEMPLATEEX*)p; - modifyitem (d, d2, dt, ns->tmpl, mult); - p += sizeof (DLGITEMTEMPLATEEX); - p = skiptext(p); - p = skiptext(p); - p += ((WORD*)p)[0]; - p += sizeof (WORD); + DLGTEMPLATEEX *d; + DLGTEMPLATEEX_END *d2; + DLGITEMTEMPLATEEX *dt; + BYTE *p, *p2; + int i; + struct newresource *ns; + + d = res->resource; + d2 = res->resource; + + if (d->dlgVer != 1 || d->signature != 0xffff) + return 0; + if (!(d->style & (DS_SETFONT | DS_SHELLFONT))) + return 0; + + ns = xcalloc (sizeof (struct newresource), 1); + ns->inst = res->inst; + ns->size = res->size; + ns->tmpl = res->tmpl; + ns->resource = xmalloc (ns->size); + memcpy (ns->resource, res->resource, ns->size); + + d = ns->resource; + d2 = ns->resource; + p = (BYTE*)d + sizeof (DLGTEMPLATEEX); + p = skiptext (p); + p = skiptext (p); + p = skiptext (p); + d2 = (DLGTEMPLATEEX_END*)p; + p2 = p; + p2 += sizeof (DLGTEMPLATEEX_END); + p2 = skiptext (p2); + p2 = todword (p2); + + modifytemplatefont (d, d2); + + p += sizeof (DLGTEMPLATEEX_END); + p = skiptext (p); p = todword (p); - } - ns->width = d->cx; - ns->height = d->cy; - return ns; + if (p != p2) + memmove (p, p2, ns->size - (p2 - (BYTE*)ns->resource)); + + modifytemplate(d, d2, ns->tmpl, mult); + + for (i = 0; i < d->cDlgItems; i++) { + dt = (DLGITEMTEMPLATEEX*)p; + modifyitem (d, d2, dt, ns->tmpl, mult); + p += sizeof (DLGITEMTEMPLATEEX); + p = skiptext(p); + p = skiptext(p); + p += ((WORD*)p)[0]; + p += sizeof (WORD); + p = todword (p); + } + + ns->width = d->cx; + ns->height = d->cy; + return ns; } void freescaleresource (struct newresource *ns) { - xfree (ns->resource); - xfree (ns); + xfree (ns->resource); + xfree (ns); } void scaleresource_setmaxsize (int w, int h) { - if (os_vista) - font_vista_ok = 1; - max_w = w; - max_h = h; - mult = 100; + if (os_vista) + font_vista_ok = 1; + max_w = w; + max_h = h; + mult = 100; } diff --git a/od-win32/winuaechangelog.txt b/od-win32/winuaechangelog.txt index d4d90c99..bbccce01 100644 --- a/od-win32/winuaechangelog.txt +++ b/od-win32/winuaechangelog.txt @@ -1,4 +1,27 @@ +Beta 19: + +- do not "fix" \\'s at start of path (b14) +- sound sync ignored recently emulated NTSC short/long line toggle +- less aggressive sound sync in non-vsync modes (not much point really) +- 68020 CE cycle counting rewritten (may not be better yet but easier + to tweak in future) +- added support for single sided PC/Atari ST-style images +- added .st to disk image dialog extension list, .vhd to hardfile list +- onscreen leds show selected disk side +- onscreen led track number is dimmed when drive is empty +- always mount regular hardfiles, even if dostype is unknown or + filesystem fails to load (unknown dostype = whole drive disappeared + after reboot) +- add or create regular partition hardfile and size >=512M: generate + more compatible default disk geometry (cylinders less than 65536) +- Action Replay statefile support should work again (again and again) +- AVIOutput: handle recording thread errors without freezing, record + as 24-bit (instead of 32) if display is 32-bit +- fixed really stupid and old bug in blitter state restore +- added pause priorities (user pause > inactive > minimized), lower + priority pause states can't unpause higher priority states + Beta 18: - dongle GUI selection added (IO Ports), Leviathan dongle supported @@ -16,7 +39,7 @@ Beta 18: - minimizing: priority was set wrong, closing when minimized: remembered windowed mode size was reset (old bugs) - unpause when clicking on "PAUSED" fps led -- some vsync sound sync experiments again.. +- some (vsync)sound sync experiments again.. Beta 17: diff --git a/od-win32/writelog.c b/od-win32/writelog.c index f01023c0..c7cb135e 100644 --- a/od-win32/writelog.c +++ b/od-win32/writelog.c @@ -36,439 +36,439 @@ int always_flush_log = 0; static HWND myGetConsoleWindow (void) { - return GetConsoleWindow (); + return GetConsoleWindow (); } static void getconsole (void) { - CONSOLE_SCREEN_BUFFER_INFO csbi; - - stdinput = GetStdHandle (STD_INPUT_HANDLE); - stdoutput = GetStdHandle (STD_OUTPUT_HANDLE); - SetConsoleMode (stdinput, ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_OUTPUT); - SetConsoleCP (65001); - SetConsoleOutputCP (65001); - if (GetConsoleScreenBufferInfo (stdoutput, &csbi)) { - if (csbi.dwMaximumWindowSize.Y < 900) { - csbi.dwMaximumWindowSize.Y = 900; - SetConsoleScreenBufferSize (stdoutput, csbi.dwMaximumWindowSize); + CONSOLE_SCREEN_BUFFER_INFO csbi; + + stdinput = GetStdHandle (STD_INPUT_HANDLE); + stdoutput = GetStdHandle (STD_OUTPUT_HANDLE); + SetConsoleMode (stdinput, ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_OUTPUT); + SetConsoleCP (65001); + SetConsoleOutputCP (65001); + if (GetConsoleScreenBufferInfo (stdoutput, &csbi)) { + if (csbi.dwMaximumWindowSize.Y < 900) { + csbi.dwMaximumWindowSize.Y = 900; + SetConsoleScreenBufferSize (stdoutput, csbi.dwMaximumWindowSize); + } } - } } static void open_console_window (void) { - AllocConsole (); - getconsole (); - consoleopen = -1; - reopen_console (); + AllocConsole (); + getconsole (); + consoleopen = -1; + reopen_console (); } static void openconsole (void) { - if (realconsole) { - if (debugger_type == 2) { - open_debug_window (); - consoleopen = 1; - } else { - close_debug_window (); - consoleopen = -1; - } - return; - } - if (debugger_active && (debugger_type < 0 || debugger_type == 2)) { - if (consoleopen > 0 || debuggerinitializing) - return; - if (debugger_type < 0) { - regqueryint (NULL, L"DebuggerType", &debugger_type); - if (debugger_type <= 0) - debugger_type = 2; - openconsole(); - return; + if (realconsole) { + if (debugger_type == 2) { + open_debug_window (); + consoleopen = 1; + } else { + close_debug_window (); + consoleopen = -1; + } + return; } - close_console (); - if (open_debug_window ()) { - consoleopen = 1; - return; + if (debugger_active && (debugger_type < 0 || debugger_type == 2)) { + if (consoleopen > 0 || debuggerinitializing) + return; + if (debugger_type < 0) { + regqueryint (NULL, L"DebuggerType", &debugger_type); + if (debugger_type <= 0) + debugger_type = 2; + openconsole(); + return; + } + close_console (); + if (open_debug_window ()) { + consoleopen = 1; + return; + } + open_console_window (); + } else { + if (consoleopen < 0) + return; + close_console (); + open_console_window (); } - open_console_window (); - } else { - if (consoleopen < 0) - return; - close_console (); - open_console_window (); - } } void debugger_change (int mode) { - if (mode < 0) - debugger_type = debugger_type == 2 ? 1 : 2; - else - debugger_type = mode; - if (debugger_type != 1 && debugger_type != 2) - debugger_type = 2; - regsetint (NULL, L"DebuggerType", debugger_type); - openconsole (); + if (mode < 0) + debugger_type = debugger_type == 2 ? 1 : 2; + else + debugger_type = mode; + if (debugger_type != 1 && debugger_type != 2) + debugger_type = 2; + regsetint (NULL, L"DebuggerType", debugger_type); + openconsole (); } void reopen_console (void) { - HWND hwnd; - - if (realconsole) - return; - if (consoleopen >= 0) - return; - hwnd = myGetConsoleWindow (); - if (hwnd) { - int newpos = 1; - LONG x, y, w, h; - if (!regqueryint (NULL, L"LoggerPosX", &x)) - newpos = 0; - if (!regqueryint (NULL, L"LoggerPosY", &y)) - newpos = 0; - if (!regqueryint (NULL, L"LoggerPosW", &w)) - newpos = 0; - if (!regqueryint (NULL, L"LoggerPosH", &h)) - newpos = 0; - if (newpos) { - RECT rc; - rc.left = x; - rc.top = y; - rc.right = x + w; - rc.bottom = y + h; - if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) != NULL) { - SetForegroundWindow (hwnd); - SetWindowPos (hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE); - - } + HWND hwnd; + + if (realconsole) + return; + if (consoleopen >= 0) + return; + hwnd = myGetConsoleWindow (); + if (hwnd) { + int newpos = 1; + LONG x, y, w, h; + if (!regqueryint (NULL, L"LoggerPosX", &x)) + newpos = 0; + if (!regqueryint (NULL, L"LoggerPosY", &y)) + newpos = 0; + if (!regqueryint (NULL, L"LoggerPosW", &w)) + newpos = 0; + if (!regqueryint (NULL, L"LoggerPosH", &h)) + newpos = 0; + if (newpos) { + RECT rc; + rc.left = x; + rc.top = y; + rc.right = x + w; + rc.bottom = y + h; + if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) != NULL) { + SetForegroundWindow (hwnd); + SetWindowPos (hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE); + + } + } } - } } void close_console (void) { - if (realconsole) - return; - if (consoleopen > 0) { - close_debug_window (); - } else if (consoleopen < 0) { - HWND hwnd = myGetConsoleWindow (); - if (hwnd) { - RECT r; - if (GetWindowRect (hwnd, &r)) { - r.bottom -= r.top; - r.right -= r.left; - regsetint (NULL, L"LoggerPosX", r.left); - regsetint (NULL, L"LoggerPosY", r.top); - regsetint (NULL, L"LoggerPosW", r.right); - regsetint (NULL, L"LoggerPosH", r.bottom); - } + if (realconsole) + return; + if (consoleopen > 0) { + close_debug_window (); + } else if (consoleopen < 0) { + HWND hwnd = myGetConsoleWindow (); + if (hwnd) { + RECT r; + if (GetWindowRect (hwnd, &r)) { + r.bottom -= r.top; + r.right -= r.left; + regsetint (NULL, L"LoggerPosX", r.left); + regsetint (NULL, L"LoggerPosY", r.top); + regsetint (NULL, L"LoggerPosW", r.right); + regsetint (NULL, L"LoggerPosH", r.bottom); + } + } + FreeConsole (); } - FreeConsole (); - } - consoleopen = 0; + consoleopen = 0; } static void writeconsole_2 (const TCHAR *buffer) { - DWORD temp; - - if (!consoleopen) - openconsole (); - - if (consoleopen > 0) { - WriteOutput (buffer, _tcslen (buffer)); - } else if (realconsole) { - fputws (buffer, stdout); - fflush (stdout); - } else if (consoleopen < 0) { - WriteConsole (stdoutput, buffer, _tcslen (buffer), &temp, 0); - } + DWORD temp; + + if (!consoleopen) + openconsole (); + + if (consoleopen > 0) { + WriteOutput (buffer, _tcslen (buffer)); + } else if (realconsole) { + fputws (buffer, stdout); + fflush (stdout); + } else if (consoleopen < 0) { + WriteConsole (stdoutput, buffer, _tcslen (buffer), &temp, 0); + } } static void writeconsole (const TCHAR *buffer) { - if (_tcslen (buffer) > 256) { - TCHAR *p = my_strdup (buffer); - TCHAR *p2 = p; - while (_tcslen (p) > 256) { - TCHAR tmp = p[256]; - p[256] = 0; - writeconsole_2 (p); - p[256] = tmp; - p += 256; + if (_tcslen (buffer) > 256) { + TCHAR *p = my_strdup (buffer); + TCHAR *p2 = p; + while (_tcslen (p) > 256) { + TCHAR tmp = p[256]; + p[256] = 0; + writeconsole_2 (p); + p[256] = tmp; + p += 256; + } + writeconsole_2 (p); + xfree (p2); + } else { + writeconsole_2 (buffer); } - writeconsole_2 (p); - xfree (p2); - } else { - writeconsole_2 (buffer); - } } static void flushconsole (void) { - if (consoleopen > 0) { - fflush (stdout); - } else if (realconsole) { - fflush (stdout); - } else if (consoleopen < 0) { - FlushFileBuffers (stdoutput); - } + if (consoleopen > 0) { + fflush (stdout); + } else if (realconsole) { + fflush (stdout); + } else if (consoleopen < 0) { + FlushFileBuffers (stdoutput); + } } void console_out_f (const TCHAR *format,...) { - va_list parms; - TCHAR buffer[WRITE_LOG_BUF_SIZE]; - - va_start (parms, format); - _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); - va_end (parms); - openconsole (); - writeconsole (buffer); + va_list parms; + TCHAR buffer[WRITE_LOG_BUF_SIZE]; + + va_start (parms, format); + _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); + va_end (parms); + openconsole (); + writeconsole (buffer); } void console_out (const TCHAR *txt) { - openconsole (); - writeconsole (txt); + openconsole (); + writeconsole (txt); } int console_get (TCHAR *out, int maxlen) { - *out = 0; - - if (consoleopen > 0) { - return console_get_gui (out, maxlen); - } else if (realconsole) { - _fgetts (out, maxlen, stdin); - return _tcslen (out); - } else if (consoleopen < 0) { - DWORD len, totallen; - *out = 0; - totallen = 0; - while(maxlen > 0) { - ReadConsole (stdinput, out, 1, &len, 0); - if(*out == 13) - break; - out++; - maxlen--; - totallen++; + + if (consoleopen > 0) { + return console_get_gui (out, maxlen); + } else if (realconsole) { + _fgetts (out, maxlen, stdin); + return _tcslen (out); + } else if (consoleopen < 0) { + DWORD len, totallen; + + *out = 0; + totallen = 0; + while(maxlen > 0) { + ReadConsole (stdinput, out, 1, &len, 0); + if(*out == 13) + break; + out++; + maxlen--; + totallen++; + } + *out = 0; + return totallen; } - *out = 0; - return totallen; - } - return 0; + return 0; } void console_flush (void) { - flushconsole (); + flushconsole (); } static int lfdetected = 1; static TCHAR *writets (void) { - struct tm *t; - struct _timeb tb; - static TCHAR out[100]; - TCHAR *p; - static TCHAR lastts[100]; - TCHAR curts[100]; - - if (bootlogmode) - return NULL; - if (nodatestamps) - return NULL; - _ftime (&tb); - t = localtime (&tb.time); - _tcsftime (curts, sizeof curts / sizeof (TCHAR), L"%Y-%m-%d %H:%M:%S\n", t); - p = out; - *p = 0; - if (_tcsncmp (curts, lastts, _tcslen (curts) - 3)) { // "xx\n" - _tcscat (p, curts); + struct tm *t; + struct _timeb tb; + static TCHAR out[100]; + TCHAR *p; + static TCHAR lastts[100]; + TCHAR curts[100]; + + if (bootlogmode) + return NULL; + if (nodatestamps) + return NULL; + _ftime (&tb); + t = localtime (&tb.time); + _tcsftime (curts, sizeof curts / sizeof (TCHAR), L"%Y-%m-%d %H:%M:%S\n", t); + p = out; + *p = 0; + if (_tcsncmp (curts, lastts, _tcslen (curts) - 3)) { // "xx\n" + _tcscat (p, curts); + p += _tcslen (p); + _tcscpy (lastts, curts); + } + _tcsftime (p, sizeof out / sizeof (TCHAR) - (p - out) , L"%S-", t); p += _tcslen (p); - _tcscpy (lastts, curts); - } - _tcsftime (p, sizeof out / sizeof (TCHAR) - (p - out) , L"%S-", t); - p += _tcslen (p); - _stprintf (p, L"%03d", tb.millitm); - p += _tcslen (p); - if (timeframes || (vpos > 0 && current_hpos () > 0)) - _stprintf (p, L" [%d %03dx%03d]", timeframes, current_hpos (), vpos); - _tcscat (p, L": "); - return out; + _stprintf (p, L"%03d", tb.millitm); + p += _tcslen (p); + if (timeframes || (vpos > 0 && current_hpos () > 0)) + _stprintf (p, L" [%d %03dx%03d]", timeframes, current_hpos (), vpos); + _tcscat (p, L": "); + return out; } void write_dlog (const TCHAR *format, ...) { - int count; - TCHAR buffer[WRITE_LOG_BUF_SIZE]; - TCHAR *ts; - va_list parms; - - if (!SHOW_CONSOLE && !console_logging && !debugfile) - return; - - EnterCriticalSection (&cs); - va_start (parms, format); - count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); - ts = writets (); - if (SHOW_CONSOLE || console_logging) { - if (lfdetected && ts) - writeconsole (ts); - writeconsole (buffer); - } - if (debugfile) { - if (lfdetected && ts) - _ftprintf (debugfile, L"%s", ts); - _ftprintf (debugfile, L"%s", buffer); - } - lfdetected = 0; - if (_tcslen (buffer) > 0 && buffer[_tcslen(buffer) - 1] == '\n') - lfdetected = 1; - va_end (parms); - LeaveCriticalSection (&cs); + int count; + TCHAR buffer[WRITE_LOG_BUF_SIZE]; + TCHAR *ts; + va_list parms; + + if (!SHOW_CONSOLE && !console_logging && !debugfile) + return; + + EnterCriticalSection (&cs); + va_start (parms, format); + count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); + ts = writets (); + if (SHOW_CONSOLE || console_logging) { + if (lfdetected && ts) + writeconsole (ts); + writeconsole (buffer); + } + if (debugfile) { + if (lfdetected && ts) + _ftprintf (debugfile, L"%s", ts); + _ftprintf (debugfile, L"%s", buffer); + } + lfdetected = 0; + if (_tcslen (buffer) > 0 && buffer[_tcslen(buffer) - 1] == '\n') + lfdetected = 1; + va_end (parms); + LeaveCriticalSection (&cs); } void write_log (const TCHAR *format, ...) { - int count; - TCHAR buffer[WRITE_LOG_BUF_SIZE], *ts; - int bufsize = WRITE_LOG_BUF_SIZE; - TCHAR *bufp; - va_list parms; - - if (!cs_init) - return; - EnterCriticalSection (&cs); - va_start (parms, format); - bufp = buffer; - for (;;) { - count = _vsntprintf (bufp, bufsize - 1, format, parms); - if (count < 0) { - bufsize *= 10; - if (bufp != buffer) - xfree (bufp); - bufp = xmalloc (bufsize * sizeof (TCHAR)); - continue; + int count; + TCHAR buffer[WRITE_LOG_BUF_SIZE], *ts; + int bufsize = WRITE_LOG_BUF_SIZE; + TCHAR *bufp; + va_list parms; + + if (!cs_init) + return; + EnterCriticalSection (&cs); + va_start (parms, format); + bufp = buffer; + for (;;) { + count = _vsntprintf (bufp, bufsize - 1, format, parms); + if (count < 0) { + bufsize *= 10; + if (bufp != buffer) + xfree (bufp); + bufp = xmalloc (bufsize * sizeof (TCHAR)); + continue; + } + break; + } + bufp[bufsize - 1] = 0; + if (!_tcsncmp (bufp, L"write ", 6)) + bufsize--; + ts = writets (); + if (bufp[0] == '*') + count++; + if (SHOW_CONSOLE || console_logging) { + if (lfdetected && ts) + writeconsole (ts); + writeconsole (bufp); + } + if (debugfile) { + if (lfdetected && ts) + _ftprintf (debugfile, L"%s", ts); + _ftprintf (debugfile, L"%s", bufp); } - break; - } - bufp[bufsize - 1] = 0; - if (!_tcsncmp (bufp, L"write ", 6)) - bufsize--; - ts = writets (); - if (bufp[0] == '*') - count++; - if (SHOW_CONSOLE || console_logging) { - if (lfdetected && ts) - writeconsole (ts); - writeconsole (bufp); - } - if (debugfile) { - if (lfdetected && ts) - _ftprintf (debugfile, L"%s", ts); - _ftprintf (debugfile, L"%s", bufp); - } - lfdetected = 0; - if (_tcslen (bufp) > 0 && bufp[_tcslen (bufp) - 1] == '\n') - lfdetected = 1; - va_end (parms); - if (bufp != buffer) - xfree (bufp); - if (always_flush_log) - flush_log (); - LeaveCriticalSection (&cs); + lfdetected = 0; + if (_tcslen (bufp) > 0 && bufp[_tcslen (bufp) - 1] == '\n') + lfdetected = 1; + va_end (parms); + if (bufp != buffer) + xfree (bufp); + if (always_flush_log) + flush_log (); + LeaveCriticalSection (&cs); } void flush_log (void) { - if (debugfile) - fflush (debugfile); - flushconsole (); + if (debugfile) + fflush (debugfile); + flushconsole (); } void f_out (void *f, const TCHAR *format, ...) { - int count; - TCHAR buffer[WRITE_LOG_BUF_SIZE]; - va_list parms; - va_start (parms, format); - - if (f == NULL) - return; - count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); - openconsole (); - writeconsole (buffer); - va_end (parms); + int count; + TCHAR buffer[WRITE_LOG_BUF_SIZE]; + va_list parms; + va_start (parms, format); + + if (f == NULL) + return; + count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); + openconsole (); + writeconsole (buffer); + va_end (parms); } TCHAR* buf_out (TCHAR *buffer, int *bufsize, const TCHAR *format, ...) { - int count; - va_list parms; - va_start (parms, format); - - if (buffer == NULL) - return 0; - count = _vsntprintf (buffer, (*bufsize) - 1, format, parms); - va_end (parms); - *bufsize -= _tcslen (buffer); - return buffer + _tcslen (buffer); + int count; + va_list parms; + va_start (parms, format); + + if (buffer == NULL) + return 0; + count = _vsntprintf (buffer, (*bufsize) - 1, format, parms); + va_end (parms); + *bufsize -= _tcslen (buffer); + return buffer + _tcslen (buffer); } void *log_open (const TCHAR *name, int append, int bootlog) { - FILE *f = NULL; - - if (!cs_init) - InitializeCriticalSection (&cs); - cs_init = 1; - - if (name != NULL) { - f = _tfopen (name, append ? L"a, ccs=UTF-8" : L"wt, ccs=UTF-8"); - bootlogmode = bootlog; - } else if (1) { - TCHAR *c = GetCommandLine (); - if (_tcsstr (c, L" -console")) { - if (GetStdHandle (STD_INPUT_HANDLE) && GetStdHandle (STD_OUTPUT_HANDLE)) { - consoleopen = -1; - realconsole = 1; - getconsole (); - _setmode(_fileno (stdout), _O_U16TEXT); - _setmode(_fileno (stdin), _O_U16TEXT); - } + FILE *f = NULL; + + if (!cs_init) + InitializeCriticalSection (&cs); + cs_init = 1; + + if (name != NULL) { + f = _tfopen (name, append ? L"a, ccs=UTF-8" : L"wt, ccs=UTF-8"); + bootlogmode = bootlog; + } else if (1) { + TCHAR *c = GetCommandLine (); + if (_tcsstr (c, L" -console")) { + if (GetStdHandle (STD_INPUT_HANDLE) && GetStdHandle (STD_OUTPUT_HANDLE)) { + consoleopen = -1; + realconsole = 1; + getconsole (); + _setmode(_fileno (stdout), _O_U16TEXT); + _setmode(_fileno (stdin), _O_U16TEXT); + } + } } - } - return f; + return f; } void log_close (void *f) { - fclose (f); + fclose (f); } void jit_abort (const TCHAR *format,...) { - static int happened; - int count; - TCHAR buffer[WRITE_LOG_BUF_SIZE]; - va_list parms; - va_start (parms, format); - - count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); - writeconsole (buffer); - va_end (parms); - if (!happened) - gui_message (L"JIT: Serious error:\n%s", buffer); - happened = 1; - uae_reset (1); + static int happened; + int count; + TCHAR buffer[WRITE_LOG_BUF_SIZE]; + va_list parms; + va_start (parms, format); + + count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); + writeconsole (buffer); + va_end (parms); + if (!happened) + gui_message (L"JIT: Serious error:\n%s", buffer); + happened = 1; + uae_reset (1); } diff --git a/readcpu.c b/readcpu.c index a562ff1f..09aae600 100644 --- a/readcpu.c +++ b/readcpu.c @@ -1,10 +1,10 @@ /* - * UAE - The Un*x Amiga Emulator - * - * Read 68000 CPU specs from file "table68k" - * - * Copyright 1995,1996 Bernd Schmidt - */ +* UAE - The Un*x Amiga Emulator +* +* Read 68000 CPU specs from file "table68k" +* +* Copyright 1995,1996 Bernd Schmidt +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -15,866 +15,866 @@ int nr_cpuop_funcs; struct mnemolookup lookuptab[] = { - { i_ILLG, L"ILLEGAL" }, - { i_OR, L"OR" }, - { i_CHK, L"CHK" }, - { i_CHK2, L"CHK2" }, - { i_AND, L"AND" }, - { i_EOR, L"EOR" }, - { i_ORSR, L"ORSR" }, - { i_ANDSR, L"ANDSR" }, - { i_EORSR, L"EORSR" }, - { i_SUB, L"SUB" }, - { i_SUBA, L"SUBA" }, - { i_SUBX, L"SUBX" }, - { i_SBCD, L"SBCD" }, - { i_ADD, L"ADD" }, - { i_ADDA, L"ADDA" }, - { i_ADDX, L"ADDX" }, - { i_ABCD, L"ABCD" }, - { i_NEG, L"NEG" }, - { i_NEGX, L"NEGX" }, - { i_NBCD, L"NBCD" }, - { i_CLR, L"CLR" }, - { i_NOT, L"NOT" }, - { i_TST, L"TST" }, - { i_BTST, L"BTST" }, - { i_BCHG, L"BCHG" }, - { i_BCLR, L"BCLR" }, - { i_BSET, L"BSET" }, - { i_CMP, L"CMP" }, - { i_CMPM, L"CMPM" }, - { i_CMPA, L"CMPA" }, - { i_MVPRM, L"MVPRM" }, - { i_MVPMR, L"MVPMR" }, - { i_MOVE, L"MOVE" }, - { i_MOVEA, L"MOVEA" }, - { i_MVSR2, L"MVSR2" }, - { i_MV2SR, L"MV2SR" }, - { i_SWAP, L"SWAP" }, - { i_EXG, L"EXG" }, - { i_EXT, L"EXT" }, - { i_MVMEL, L"MVMEL", L"MOVEM" }, - { i_MVMLE, L"MVMLE", L"MOVEM" }, - { i_TRAP, L"TRAP" }, - { i_MVR2USP, L"MVR2USP" }, - { i_MVUSP2R, L"MVUSP2R" }, - { i_NOP, L"NOP" }, - { i_RESET, L"RESET" }, - { i_RTE, L"RTE" }, - { i_RTD, L"RTD" }, - { i_LINK, L"LINK" }, - { i_UNLK, L"UNLK" }, - { i_RTS, L"RTS" }, - { i_STOP, L"STOP" }, - { i_TRAPV, L"TRAPV" }, - { i_RTR, L"RTR" }, - { i_JSR, L"JSR" }, - { i_JMP, L"JMP" }, - { i_BSR, L"BSR" }, - { i_Bcc, L"Bcc" }, - { i_LEA, L"LEA" }, - { i_PEA, L"PEA" }, - { i_DBcc, L"DBcc" }, - { i_Scc, L"Scc" }, - { i_DIVU, L"DIVU" }, - { i_DIVS, L"DIVS" }, - { i_MULU, L"MULU" }, - { i_MULS, L"MULS" }, - { i_ASR, L"ASR" }, - { i_ASL, L"ASL" }, - { i_LSR, L"LSR" }, - { i_LSL, L"LSL" }, - { i_ROL, L"ROL" }, - { i_ROR, L"ROR" }, - { i_ROXL, L"ROXL" }, - { i_ROXR, L"ROXR" }, - { i_ASRW, L"ASRW" }, - { i_ASLW, L"ASLW" }, - { i_LSRW, L"LSRW" }, - { i_LSLW, L"LSLW" }, - { i_ROLW, L"ROLW" }, - { i_RORW, L"RORW" }, - { i_ROXLW, L"ROXLW" }, - { i_ROXRW, L"ROXRW" }, - - { i_MOVE2C, L"MOVE2C", L"MOVEC" }, - { i_MOVEC2, L"MOVEC2", L"MOVEC" }, - { i_CAS, L"CAS" }, - { i_CAS2, L"CAS2" }, - { i_MULL, L"MULL" }, - { i_DIVL, L"DIVL" }, - { i_BFTST, L"BFTST" }, - { i_BFEXTU, L"BFEXTU" }, - { i_BFCHG, L"BFCHG" }, - { i_BFEXTS, L"BFEXTS" }, - { i_BFCLR, L"BFCLR" }, - { i_BFFFO, L"BFFFO" }, - { i_BFSET, L"BFSET" }, - { i_BFINS, L"BFINS" }, - { i_PACK, L"PACK" }, - { i_UNPK, L"UNPK" }, - { i_TAS, L"TAS" }, - { i_BKPT, L"BKPT" }, - { i_CALLM, L"CALLM" }, - { i_RTM, L"RTM" }, - { i_TRAPcc, L"TRAPcc" }, - { i_MOVES, L"MOVES" }, - { i_FPP, L"FPP" }, - { i_FDBcc, L"FDBcc" }, - { i_FScc, L"FScc" }, - { i_FTRAPcc, L"FTRAPcc" }, - { i_FBcc, L"FBcc" }, - { i_FBcc, L"FBcc" }, - { i_FSAVE, L"FSAVE" }, - { i_FRESTORE, L"FRESTORE" }, - - { i_CINVL, L"CINVL" }, - { i_CINVP, L"CINVP" }, - { i_CINVA, L"CINVA" }, - { i_CPUSHL, L"CPUSHL" }, - { i_CPUSHP, L"CPUSHP" }, - { i_CPUSHA, L"CPUSHA" }, - { i_MOVE16, L"MOVE16" }, - - { i_MMUOP030, L"MMUOP030" }, - { i_PFLUSHN, L"PFLUSHN" }, - { i_PFLUSH, L"PFLUSH" }, - { i_PFLUSHAN, L"PFLUSHAN" }, - { i_PFLUSHA, L"PFLUSHA" }, - - { i_PLPAR, L"PLPAR" }, - { i_PLPAW, L"PLPAW" }, - { i_PTESTR, L"PTESTR" }, - { i_PTESTW, L"PTESTW" }, - - { i_LPSTOP, L"LPSTOP" }, - { i_ILLG, L"" }, + { i_ILLG, L"ILLEGAL" }, + { i_OR, L"OR" }, + { i_CHK, L"CHK" }, + { i_CHK2, L"CHK2" }, + { i_AND, L"AND" }, + { i_EOR, L"EOR" }, + { i_ORSR, L"ORSR" }, + { i_ANDSR, L"ANDSR" }, + { i_EORSR, L"EORSR" }, + { i_SUB, L"SUB" }, + { i_SUBA, L"SUBA" }, + { i_SUBX, L"SUBX" }, + { i_SBCD, L"SBCD" }, + { i_ADD, L"ADD" }, + { i_ADDA, L"ADDA" }, + { i_ADDX, L"ADDX" }, + { i_ABCD, L"ABCD" }, + { i_NEG, L"NEG" }, + { i_NEGX, L"NEGX" }, + { i_NBCD, L"NBCD" }, + { i_CLR, L"CLR" }, + { i_NOT, L"NOT" }, + { i_TST, L"TST" }, + { i_BTST, L"BTST" }, + { i_BCHG, L"BCHG" }, + { i_BCLR, L"BCLR" }, + { i_BSET, L"BSET" }, + { i_CMP, L"CMP" }, + { i_CMPM, L"CMPM" }, + { i_CMPA, L"CMPA" }, + { i_MVPRM, L"MVPRM" }, + { i_MVPMR, L"MVPMR" }, + { i_MOVE, L"MOVE" }, + { i_MOVEA, L"MOVEA" }, + { i_MVSR2, L"MVSR2" }, + { i_MV2SR, L"MV2SR" }, + { i_SWAP, L"SWAP" }, + { i_EXG, L"EXG" }, + { i_EXT, L"EXT" }, + { i_MVMEL, L"MVMEL", L"MOVEM" }, + { i_MVMLE, L"MVMLE", L"MOVEM" }, + { i_TRAP, L"TRAP" }, + { i_MVR2USP, L"MVR2USP" }, + { i_MVUSP2R, L"MVUSP2R" }, + { i_NOP, L"NOP" }, + { i_RESET, L"RESET" }, + { i_RTE, L"RTE" }, + { i_RTD, L"RTD" }, + { i_LINK, L"LINK" }, + { i_UNLK, L"UNLK" }, + { i_RTS, L"RTS" }, + { i_STOP, L"STOP" }, + { i_TRAPV, L"TRAPV" }, + { i_RTR, L"RTR" }, + { i_JSR, L"JSR" }, + { i_JMP, L"JMP" }, + { i_BSR, L"BSR" }, + { i_Bcc, L"Bcc" }, + { i_LEA, L"LEA" }, + { i_PEA, L"PEA" }, + { i_DBcc, L"DBcc" }, + { i_Scc, L"Scc" }, + { i_DIVU, L"DIVU" }, + { i_DIVS, L"DIVS" }, + { i_MULU, L"MULU" }, + { i_MULS, L"MULS" }, + { i_ASR, L"ASR" }, + { i_ASL, L"ASL" }, + { i_LSR, L"LSR" }, + { i_LSL, L"LSL" }, + { i_ROL, L"ROL" }, + { i_ROR, L"ROR" }, + { i_ROXL, L"ROXL" }, + { i_ROXR, L"ROXR" }, + { i_ASRW, L"ASRW" }, + { i_ASLW, L"ASLW" }, + { i_LSRW, L"LSRW" }, + { i_LSLW, L"LSLW" }, + { i_ROLW, L"ROLW" }, + { i_RORW, L"RORW" }, + { i_ROXLW, L"ROXLW" }, + { i_ROXRW, L"ROXRW" }, + + { i_MOVE2C, L"MOVE2C", L"MOVEC" }, + { i_MOVEC2, L"MOVEC2", L"MOVEC" }, + { i_CAS, L"CAS" }, + { i_CAS2, L"CAS2" }, + { i_MULL, L"MULL" }, + { i_DIVL, L"DIVL" }, + { i_BFTST, L"BFTST" }, + { i_BFEXTU, L"BFEXTU" }, + { i_BFCHG, L"BFCHG" }, + { i_BFEXTS, L"BFEXTS" }, + { i_BFCLR, L"BFCLR" }, + { i_BFFFO, L"BFFFO" }, + { i_BFSET, L"BFSET" }, + { i_BFINS, L"BFINS" }, + { i_PACK, L"PACK" }, + { i_UNPK, L"UNPK" }, + { i_TAS, L"TAS" }, + { i_BKPT, L"BKPT" }, + { i_CALLM, L"CALLM" }, + { i_RTM, L"RTM" }, + { i_TRAPcc, L"TRAPcc" }, + { i_MOVES, L"MOVES" }, + { i_FPP, L"FPP" }, + { i_FDBcc, L"FDBcc" }, + { i_FScc, L"FScc" }, + { i_FTRAPcc, L"FTRAPcc" }, + { i_FBcc, L"FBcc" }, + { i_FBcc, L"FBcc" }, + { i_FSAVE, L"FSAVE" }, + { i_FRESTORE, L"FRESTORE" }, + + { i_CINVL, L"CINVL" }, + { i_CINVP, L"CINVP" }, + { i_CINVA, L"CINVA" }, + { i_CPUSHL, L"CPUSHL" }, + { i_CPUSHP, L"CPUSHP" }, + { i_CPUSHA, L"CPUSHA" }, + { i_MOVE16, L"MOVE16" }, + + { i_MMUOP030, L"MMUOP030" }, + { i_PFLUSHN, L"PFLUSHN" }, + { i_PFLUSH, L"PFLUSH" }, + { i_PFLUSHAN, L"PFLUSHAN" }, + { i_PFLUSHA, L"PFLUSHA" }, + + { i_PLPAR, L"PLPAR" }, + { i_PLPAW, L"PLPAW" }, + { i_PTESTR, L"PTESTR" }, + { i_PTESTW, L"PTESTW" }, + + { i_LPSTOP, L"LPSTOP" }, + { i_ILLG, L"" }, }; struct instr *table68k; static int specialcase (uae_u16 opcode, int cpu_lev) { - int mode = (opcode >> 3) & 7; - int reg = opcode & 7; - - if (cpu_lev >= 2) + int mode = (opcode >> 3) & 7; + int reg = opcode & 7; + + if (cpu_lev >= 2) + return cpu_lev; + /* TST.W A0, TST.L A0, TST.x (d16,PC) and TST.x (d8,PC,Xn) are 68020+ only */ + if ((opcode & 0xff00) == 0x4a00) { + if (mode == 7 && (reg == 4 || reg == 2 || reg == 3)) + return 2; + if (mode == 1) /* Ax */ + return 2; + } + /* CMPI.W #x,(d16,PC) and CMPI.W #x,(d8,PC,Xn) are 68020+ only */ + if ((opcode & 0xff00) == 0x0c00) { + if (mode == 7 && (reg == 2 || reg == 3)) + return 2; + } return cpu_lev; - /* TST.W A0, TST.L A0, TST.x (d16,PC) and TST.x (d8,PC,Xn) are 68020+ only */ - if ((opcode & 0xff00) == 0x4a00) { - if (mode == 7 && (reg == 4 || reg == 2 || reg == 3)) - return 2; - if (mode == 1) /* Ax */ - return 2; - } - /* CMPI.W #x,(d16,PC) and CMPI.W #x,(d8,PC,Xn) are 68020+ only */ - if ((opcode & 0xff00) == 0x0c00) { - if (mode == 7 && (reg == 2 || reg == 3)) - return 2; - } - return cpu_lev; } static amodes mode_from_str (const TCHAR *str) { - if (_tcsncmp (str, L"Dreg", 4) == 0) return Dreg; - if (_tcsncmp (str, L"Areg", 4) == 0) return Areg; - if (_tcsncmp (str, L"Aind", 4) == 0) return Aind; - if (_tcsncmp (str, L"Apdi", 4) == 0) return Apdi; - if (_tcsncmp (str, L"Aipi", 4) == 0) return Aipi; - if (_tcsncmp (str, L"Ad16", 4) == 0) return Ad16; - if (_tcsncmp (str, L"Ad8r", 4) == 0) return Ad8r; - if (_tcsncmp (str, L"absw", 4) == 0) return absw; - if (_tcsncmp (str, L"absl", 4) == 0) return absl; - if (_tcsncmp (str, L"PC16", 4) == 0) return PC16; - if (_tcsncmp (str, L"PC8r", 4) == 0) return PC8r; - if (_tcsncmp (str, L"Immd", 4) == 0) return imm; - abort (); - return 0; + if (_tcsncmp (str, L"Dreg", 4) == 0) return Dreg; + if (_tcsncmp (str, L"Areg", 4) == 0) return Areg; + if (_tcsncmp (str, L"Aind", 4) == 0) return Aind; + if (_tcsncmp (str, L"Apdi", 4) == 0) return Apdi; + if (_tcsncmp (str, L"Aipi", 4) == 0) return Aipi; + if (_tcsncmp (str, L"Ad16", 4) == 0) return Ad16; + if (_tcsncmp (str, L"Ad8r", 4) == 0) return Ad8r; + if (_tcsncmp (str, L"absw", 4) == 0) return absw; + if (_tcsncmp (str, L"absl", 4) == 0) return absl; + if (_tcsncmp (str, L"PC16", 4) == 0) return PC16; + if (_tcsncmp (str, L"PC8r", 4) == 0) return PC8r; + if (_tcsncmp (str, L"Immd", 4) == 0) return imm; + abort (); + return 0; } STATIC_INLINE amodes mode_from_mr (int mode, int reg) { - switch (mode) { - case 0: return Dreg; - case 1: return Areg; - case 2: return Aind; - case 3: return Aipi; - case 4: return Apdi; - case 5: return Ad16; - case 6: return Ad8r; - case 7: - switch (reg) { - case 0: return absw; - case 1: return absl; - case 2: return PC16; - case 3: return PC8r; - case 4: return imm; - case 5: - case 6: - case 7: return am_illg; + switch (mode) { + case 0: return Dreg; + case 1: return Areg; + case 2: return Aind; + case 3: return Aipi; + case 4: return Apdi; + case 5: return Ad16; + case 6: return Ad8r; + case 7: + switch (reg) { + case 0: return absw; + case 1: return absl; + case 2: return PC16; + case 3: return PC8r; + case 4: return imm; + case 5: + case 6: + case 7: return am_illg; + } } - } - abort (); - return 0; + abort (); + return 0; } static void build_insn (int insn) { - int find = -1; - int variants; - int isjmp = 0; - struct instr_def id; - const TCHAR *opcstr; - int i; - - int flaglive = 0, flagdead = 0; - - id = defs68k[insn]; - - /* Note: We treat anything with unknown flags as a jump. That - is overkill, but "the programmer" was lazy quite often, and - *this* programmer can't be bothered to work out what can and - can't trap. Usually, this will be overwritten with the gencomp - based information, anyway. */ - - for (i = 0; i < 5; i++) { - switch (id.flaginfo[i].flagset){ - case fa_unset: break; - case fa_isjmp: isjmp = 1; break; - case fa_isbranch: isjmp = 1; break; - case fa_zero: flagdead |= 1 << i; break; - case fa_one: flagdead |= 1 << i; break; - case fa_dontcare: flagdead |= 1 << i; break; - case fa_unknown: isjmp = 1; flagdead = -1; goto out1; - case fa_set: flagdead |= 1 << i; break; - } - } - - out1: - for (i = 0; i < 5; i++) { - switch (id.flaginfo[i].flaguse) { - case fu_unused: break; - case fu_isjmp: isjmp = 1; flaglive |= 1 << i; break; - case fu_maybecc: isjmp = 1; flaglive |= 1 << i; break; - case fu_unknown: isjmp = 1; flaglive |= 1 << i; break; - case fu_used: flaglive |= 1 << i; break; - } - } - - opcstr = id.opcstr; - for (variants = 0; variants < (1 << id.n_variable); variants++) { - int bitcnt[lastbit]; - int bitval[lastbit]; - int bitpos[lastbit]; + int find = -1; + int variants; + int isjmp = 0; + struct instr_def id; + const TCHAR *opcstr; int i; - uae_u16 opc = id.bits; - uae_u16 msk, vmsk; - int pos = 0; - int mnp = 0; - int bitno = 0; - TCHAR mnemonic[10]; - - wordsizes sz = sz_long; - int srcgather = 0, dstgather = 0; - int usesrc = 0, usedst = 0; - int srctype = 0; - int srcpos = -1, dstpos = -1; - - amodes srcmode = am_unknown, destmode = am_unknown; - int srcreg = -1, destreg = -1; - - for (i = 0; i < lastbit; i++) - bitcnt[i] = bitval[i] = 0; - - vmsk = 1 << id.n_variable; - - for (i = 0, msk = 0x8000; i < 16; i++, msk >>= 1) { - if (!(msk & id.mask)) { - int currbit = id.bitpos[bitno++]; - int bit_set; - vmsk >>= 1; - bit_set = variants & vmsk ? 1 : 0; - if (bit_set) - opc |= msk; - bitpos[currbit] = 15 - i; - bitcnt[currbit]++; - bitval[currbit] <<= 1; - bitval[currbit] |= bit_set; - } - } - if (bitval[bitj] == 0) bitval[bitj] = 8; - /* first check whether this one does not match after all */ - if (bitval[bitz] == 3 || bitval[bitC] == 1) - continue; - if (bitcnt[bitI] && (bitval[bitI] == 0x00 || bitval[bitI] == 0xff)) - continue; + int flaglive = 0, flagdead = 0; - /* bitI and bitC get copied to biti and bitc */ - if (bitcnt[bitI]) { - bitval[biti] = bitval[bitI]; bitpos[biti] = bitpos[bitI]; - } - if (bitcnt[bitC]) - bitval[bitc] = bitval[bitC]; + id = defs68k[insn]; - pos = 0; - while (opcstr[pos] && !_istspace(opcstr[pos])) { - if (opcstr[pos] == '.') { - pos++; - switch (opcstr[pos]) { - - case 'B': sz = sz_byte; break; - case 'W': sz = sz_word; break; - case 'L': sz = sz_long; break; - case 'z': - switch (bitval[bitz]) { - case 0: sz = sz_byte; break; - case 1: sz = sz_word; break; - case 2: sz = sz_long; break; - default: abort(); - } - break; - default: abort(); - } - } else { - mnemonic[mnp] = opcstr[pos]; - if (mnemonic[mnp] == 'f') { - find = -1; - switch (bitval[bitf]) { - case 0: mnemonic[mnp] = 'R'; break; - case 1: mnemonic[mnp] = 'L'; break; - default: abort(); - } + /* Note: We treat anything with unknown flags as a jump. That + is overkill, but "the programmer" was lazy quite often, and + *this* programmer can't be bothered to work out what can and + can't trap. Usually, this will be overwritten with the gencomp + based information, anyway. */ + + for (i = 0; i < 5; i++) { + switch (id.flaginfo[i].flagset){ + case fa_unset: break; + case fa_isjmp: isjmp = 1; break; + case fa_isbranch: isjmp = 1; break; + case fa_zero: flagdead |= 1 << i; break; + case fa_one: flagdead |= 1 << i; break; + case fa_dontcare: flagdead |= 1 << i; break; + case fa_unknown: isjmp = 1; flagdead = -1; goto out1; + case fa_set: flagdead |= 1 << i; break; } - mnp++; - } - pos++; } - mnemonic[mnp] = 0; - - /* now, we have read the mnemonic and the size */ - while (opcstr[pos] && _istspace(opcstr[pos])) - pos++; - - /* A goto a day keeps the D******a away. */ - if (opcstr[pos] == 0) - goto endofline; - - /* parse the source address */ - usesrc = 1; - switch (opcstr[pos++]) { - case 'D': - srcmode = Dreg; - switch (opcstr[pos++]) { - case 'r': srcreg = bitval[bitr]; srcgather = 1; srcpos = bitpos[bitr]; break; - case 'R': srcreg = bitval[bitR]; srcgather = 1; srcpos = bitpos[bitR]; break; - default: abort(); - } - break; - case 'A': - srcmode = Areg; - switch (opcstr[pos++]) { - case 'r': srcreg = bitval[bitr]; srcgather = 1; srcpos = bitpos[bitr]; break; - case 'R': srcreg = bitval[bitR]; srcgather = 1; srcpos = bitpos[bitR]; break; - default: abort(); - } - switch (opcstr[pos]) { - case 'p': srcmode = Apdi; pos++; break; - case 'P': srcmode = Aipi; pos++; break; - case 'a': srcmode = Aind; pos++; break; - } - break; - case 'L': - srcmode = absl; - break; - case '#': - switch (opcstr[pos++]) { - case 'z': srcmode = imm; break; - case '0': srcmode = imm0; break; - case '1': srcmode = imm1; break; - case '2': srcmode = imm2; break; - case 'i': srcmode = immi; srcreg = (uae_s32)(uae_s8)bitval[biti]; - if (CPU_EMU_SIZE < 4) { - /* Used for branch instructions */ - srctype = 1; - srcgather = 1; - srcpos = bitpos[biti]; - } - break; - case 'j': srcmode = immi; srcreg = bitval[bitj]; - if (CPU_EMU_SIZE < 3) { - /* 1..8 for ADDQ/SUBQ and rotshi insns */ - srcgather = 1; - srctype = 3; - srcpos = bitpos[bitj]; - } - break; - case 'J': srcmode = immi; srcreg = bitval[bitJ]; - if (CPU_EMU_SIZE < 5) { - /* 0..15 */ - srcgather = 1; - srctype = 2; - srcpos = bitpos[bitJ]; - } - break; - case 'k': srcmode = immi; srcreg = bitval[bitk]; - if (CPU_EMU_SIZE < 3) { - srcgather = 1; - srctype = 4; - srcpos = bitpos[bitk]; - } - break; - case 'K': srcmode = immi; srcreg = bitval[bitK]; - if (CPU_EMU_SIZE < 5) { - /* 0..15 */ - srcgather = 1; - srctype = 5; - srcpos = bitpos[bitK]; + +out1: + for (i = 0; i < 5; i++) { + switch (id.flaginfo[i].flaguse) { + case fu_unused: break; + case fu_isjmp: isjmp = 1; flaglive |= 1 << i; break; + case fu_maybecc: isjmp = 1; flaglive |= 1 << i; break; + case fu_unknown: isjmp = 1; flaglive |= 1 << i; break; + case fu_used: flaglive |= 1 << i; break; } - break; - case 'p': srcmode = immi; srcreg = bitval[bitK]; - if (CPU_EMU_SIZE < 5) { - /* 0..3 */ - srcgather = 1; - srctype = 7; - srcpos = bitpos[bitp]; + } + + opcstr = id.opcstr; + for (variants = 0; variants < (1 << id.n_variable); variants++) { + int bitcnt[lastbit]; + int bitval[lastbit]; + int bitpos[lastbit]; + int i; + uae_u16 opc = id.bits; + uae_u16 msk, vmsk; + int pos = 0; + int mnp = 0; + int bitno = 0; + TCHAR mnemonic[10]; + + wordsizes sz = sz_long; + int srcgather = 0, dstgather = 0; + int usesrc = 0, usedst = 0; + int srctype = 0; + int srcpos = -1, dstpos = -1; + + amodes srcmode = am_unknown, destmode = am_unknown; + int srcreg = -1, destreg = -1; + + for (i = 0; i < lastbit; i++) + bitcnt[i] = bitval[i] = 0; + + vmsk = 1 << id.n_variable; + + for (i = 0, msk = 0x8000; i < 16; i++, msk >>= 1) { + if (!(msk & id.mask)) { + int currbit = id.bitpos[bitno++]; + int bit_set; + vmsk >>= 1; + bit_set = variants & vmsk ? 1 : 0; + if (bit_set) + opc |= msk; + bitpos[currbit] = 15 - i; + bitcnt[currbit]++; + bitval[currbit] <<= 1; + bitval[currbit] |= bit_set; + } } - break; - default: abort(); - } - break; - case 'd': - srcreg = bitval[bitD]; - srcmode = mode_from_mr(bitval[bitd],bitval[bitD]); - if (srcmode == am_illg) - continue; - if (CPU_EMU_SIZE < 2 && - (srcmode == Areg || srcmode == Dreg || srcmode == Aind - || srcmode == Ad16 || srcmode == Ad8r || srcmode == Aipi - || srcmode == Apdi)) - { - srcgather = 1; srcpos = bitpos[bitD]; + + if (bitval[bitj] == 0) bitval[bitj] = 8; + /* first check whether this one does not match after all */ + if (bitval[bitz] == 3 || bitval[bitC] == 1) + continue; + if (bitcnt[bitI] && (bitval[bitI] == 0x00 || bitval[bitI] == 0xff)) + continue; + + /* bitI and bitC get copied to biti and bitc */ + if (bitcnt[bitI]) { + bitval[biti] = bitval[bitI]; bitpos[biti] = bitpos[bitI]; } - if (opcstr[pos] == '[') { - pos++; - if (opcstr[pos] == '!') { - /* exclusion */ - do { - pos++; - if (mode_from_str(opcstr+pos) == srcmode) - goto nomatch; - pos += 4; - } while (opcstr[pos] == ','); - pos++; - } else { - if (opcstr[pos+4] == '-') { - /* replacement */ - if (mode_from_str(opcstr+pos) == srcmode) - srcmode = mode_from_str(opcstr+pos+5); - else - goto nomatch; - pos += 10; - } else { - /* normal */ - while(mode_from_str(opcstr+pos) != srcmode) { - pos += 4; - if (opcstr[pos] == ']') - goto nomatch; - pos++; + if (bitcnt[bitC]) + bitval[bitc] = bitval[bitC]; + + pos = 0; + while (opcstr[pos] && !_istspace(opcstr[pos])) { + if (opcstr[pos] == '.') { + pos++; + switch (opcstr[pos]) { + + case 'B': sz = sz_byte; break; + case 'W': sz = sz_word; break; + case 'L': sz = sz_long; break; + case 'z': + switch (bitval[bitz]) { + case 0: sz = sz_byte; break; + case 1: sz = sz_word; break; + case 2: sz = sz_long; break; + default: abort(); + } + break; + default: abort(); + } + } else { + mnemonic[mnp] = opcstr[pos]; + if (mnemonic[mnp] == 'f') { + find = -1; + switch (bitval[bitf]) { + case 0: mnemonic[mnp] = 'R'; break; + case 1: mnemonic[mnp] = 'L'; break; + default: abort(); + } + } + mnp++; } - while(opcstr[pos] != ']') pos++; pos++; - break; - } } - } - /* Some addressing modes are invalid as destination */ - if (srcmode == imm || srcmode == PC16 || srcmode == PC8r) - goto nomatch; - break; - case 's': - srcreg = bitval[bitS]; - srcmode = mode_from_mr(bitval[bits],bitval[bitS]); - - if (srcmode == am_illg) - continue; - if (CPU_EMU_SIZE < 2 && - (srcmode == Areg || srcmode == Dreg || srcmode == Aind - || srcmode == Ad16 || srcmode == Ad8r || srcmode == Aipi - || srcmode == Apdi)) - { - srcgather = 1; srcpos = bitpos[bitS]; - } - if (opcstr[pos] == '[') { - pos++; - if (opcstr[pos] == '!') { - /* exclusion */ - do { + mnemonic[mnp] = 0; + + /* now, we have read the mnemonic and the size */ + while (opcstr[pos] && _istspace(opcstr[pos])) pos++; - if (mode_from_str(opcstr+pos) == srcmode) - goto nomatch; - pos += 4; - } while (opcstr[pos] == ','); - pos++; - } else { - if (opcstr[pos+4] == '-') { - /* replacement */ - if (mode_from_str(opcstr+pos) == srcmode) - srcmode = mode_from_str(opcstr+pos+5); - else - goto nomatch; - pos += 10; - } else { - /* normal */ - while(mode_from_str(opcstr+pos) != srcmode) { - pos += 4; - if (opcstr[pos] == ']') + + /* A goto a day keeps the D******a away. */ + if (opcstr[pos] == 0) + goto endofline; + + /* parse the source address */ + usesrc = 1; + switch (opcstr[pos++]) { + case 'D': + srcmode = Dreg; + switch (opcstr[pos++]) { + case 'r': srcreg = bitval[bitr]; srcgather = 1; srcpos = bitpos[bitr]; break; + case 'R': srcreg = bitval[bitR]; srcgather = 1; srcpos = bitpos[bitR]; break; + default: abort(); + } + break; + case 'A': + srcmode = Areg; + switch (opcstr[pos++]) { + case 'r': srcreg = bitval[bitr]; srcgather = 1; srcpos = bitpos[bitr]; break; + case 'R': srcreg = bitval[bitR]; srcgather = 1; srcpos = bitpos[bitR]; break; + default: abort(); + } + switch (opcstr[pos]) { + case 'p': srcmode = Apdi; pos++; break; + case 'P': srcmode = Aipi; pos++; break; + case 'a': srcmode = Aind; pos++; break; + } + break; + case 'L': + srcmode = absl; + break; + case '#': + switch (opcstr[pos++]) { + case 'z': srcmode = imm; break; + case '0': srcmode = imm0; break; + case '1': srcmode = imm1; break; + case '2': srcmode = imm2; break; + case 'i': srcmode = immi; srcreg = (uae_s32)(uae_s8)bitval[biti]; + if (CPU_EMU_SIZE < 4) { + /* Used for branch instructions */ + srctype = 1; + srcgather = 1; + srcpos = bitpos[biti]; + } + break; + case 'j': srcmode = immi; srcreg = bitval[bitj]; + if (CPU_EMU_SIZE < 3) { + /* 1..8 for ADDQ/SUBQ and rotshi insns */ + srcgather = 1; + srctype = 3; + srcpos = bitpos[bitj]; + } + break; + case 'J': srcmode = immi; srcreg = bitval[bitJ]; + if (CPU_EMU_SIZE < 5) { + /* 0..15 */ + srcgather = 1; + srctype = 2; + srcpos = bitpos[bitJ]; + } + break; + case 'k': srcmode = immi; srcreg = bitval[bitk]; + if (CPU_EMU_SIZE < 3) { + srcgather = 1; + srctype = 4; + srcpos = bitpos[bitk]; + } + break; + case 'K': srcmode = immi; srcreg = bitval[bitK]; + if (CPU_EMU_SIZE < 5) { + /* 0..15 */ + srcgather = 1; + srctype = 5; + srcpos = bitpos[bitK]; + } + break; + case 'p': srcmode = immi; srcreg = bitval[bitK]; + if (CPU_EMU_SIZE < 5) { + /* 0..3 */ + srcgather = 1; + srctype = 7; + srcpos = bitpos[bitp]; + } + break; + default: abort(); + } + break; + case 'd': + srcreg = bitval[bitD]; + srcmode = mode_from_mr(bitval[bitd],bitval[bitD]); + if (srcmode == am_illg) + continue; + if (CPU_EMU_SIZE < 2 && + (srcmode == Areg || srcmode == Dreg || srcmode == Aind + || srcmode == Ad16 || srcmode == Ad8r || srcmode == Aipi + || srcmode == Apdi)) + { + srcgather = 1; srcpos = bitpos[bitD]; + } + if (opcstr[pos] == '[') { + pos++; + if (opcstr[pos] == '!') { + /* exclusion */ + do { + pos++; + if (mode_from_str(opcstr+pos) == srcmode) + goto nomatch; + pos += 4; + } while (opcstr[pos] == ','); + pos++; + } else { + if (opcstr[pos+4] == '-') { + /* replacement */ + if (mode_from_str(opcstr+pos) == srcmode) + srcmode = mode_from_str(opcstr+pos+5); + else + goto nomatch; + pos += 10; + } else { + /* normal */ + while(mode_from_str(opcstr+pos) != srcmode) { + pos += 4; + if (opcstr[pos] == ']') + goto nomatch; + pos++; + } + while(opcstr[pos] != ']') pos++; + pos++; + break; + } + } + } + /* Some addressing modes are invalid as destination */ + if (srcmode == imm || srcmode == PC16 || srcmode == PC8r) goto nomatch; - pos++; + break; + case 's': + srcreg = bitval[bitS]; + srcmode = mode_from_mr(bitval[bits],bitval[bitS]); + + if (srcmode == am_illg) + continue; + if (CPU_EMU_SIZE < 2 && + (srcmode == Areg || srcmode == Dreg || srcmode == Aind + || srcmode == Ad16 || srcmode == Ad8r || srcmode == Aipi + || srcmode == Apdi)) + { + srcgather = 1; srcpos = bitpos[bitS]; } - while(opcstr[pos] != ']') pos++; - pos++; - } + if (opcstr[pos] == '[') { + pos++; + if (opcstr[pos] == '!') { + /* exclusion */ + do { + pos++; + if (mode_from_str(opcstr+pos) == srcmode) + goto nomatch; + pos += 4; + } while (opcstr[pos] == ','); + pos++; + } else { + if (opcstr[pos+4] == '-') { + /* replacement */ + if (mode_from_str(opcstr+pos) == srcmode) + srcmode = mode_from_str(opcstr+pos+5); + else + goto nomatch; + pos += 10; + } else { + /* normal */ + while(mode_from_str(opcstr+pos) != srcmode) { + pos += 4; + if (opcstr[pos] == ']') + goto nomatch; + pos++; + } + while(opcstr[pos] != ']') pos++; + pos++; + } + } + } + break; + default: abort(); } - } - break; - default: abort(); - } - /* safety check - might have changed */ - if (srcmode != Areg && srcmode != Dreg && srcmode != Aind - && srcmode != Ad16 && srcmode != Ad8r && srcmode != Aipi - && srcmode != Apdi && srcmode != immi) - { - srcgather = 0; - } - if (srcmode == Areg && sz == sz_byte) - goto nomatch; - - if (opcstr[pos] != ',') - goto endofline; - pos++; - - /* parse the destination address */ - usedst = 1; - switch (opcstr[pos++]) { - case 'D': - destmode = Dreg; - switch (opcstr[pos++]) { - case 'r': destreg = bitval[bitr]; dstgather = 1; dstpos = bitpos[bitr]; break; - case 'R': destreg = bitval[bitR]; dstgather = 1; dstpos = bitpos[bitR]; break; - default: abort(); - } - if (dstpos < 0 || dstpos >= 32) - abort (); - break; - case 'A': - destmode = Areg; - switch (opcstr[pos++]) { - case 'r': destreg = bitval[bitr]; dstgather = 1; dstpos = bitpos[bitr]; break; - case 'R': destreg = bitval[bitR]; dstgather = 1; dstpos = bitpos[bitR]; break; - case 'x': destreg = 0; dstgather = 0; dstpos = 0; break; - default: abort(); - } - if (dstpos < 0 || dstpos >= 32) - abort (); - switch (opcstr[pos]) { - case 'p': destmode = Apdi; pos++; break; - case 'P': destmode = Aipi; pos++; break; - } - break; - case 'L': - destmode = absl; - break; - case '#': - switch (opcstr[pos++]) { - case 'z': destmode = imm; break; - case '0': destmode = imm0; break; - case '1': destmode = imm1; break; - case '2': destmode = imm2; break; - case 'i': destmode = immi; destreg = (uae_s32)(uae_s8)bitval[biti]; break; - case 'j': destmode = immi; destreg = bitval[bitj]; break; - case 'J': destmode = immi; destreg = bitval[bitJ]; break; - case 'k': destmode = immi; destreg = bitval[bitk]; break; - case 'K': destmode = immi; destreg = bitval[bitK]; break; - default: abort(); - } - break; - case 'd': - destreg = bitval[bitD]; - destmode = mode_from_mr(bitval[bitd],bitval[bitD]); - if (destmode == am_illg) - continue; - if (CPU_EMU_SIZE < 1 && - (destmode == Areg || destmode == Dreg || destmode == Aind - || destmode == Ad16 || destmode == Ad8r || destmode == Aipi - || destmode == Apdi)) + /* safety check - might have changed */ + if (srcmode != Areg && srcmode != Dreg && srcmode != Aind + && srcmode != Ad16 && srcmode != Ad8r && srcmode != Aipi + && srcmode != Apdi && srcmode != immi) { - dstgather = 1; dstpos = bitpos[bitD]; + srcgather = 0; } + if (srcmode == Areg && sz == sz_byte) + goto nomatch; - if (opcstr[pos] == '[') { + if (opcstr[pos] != ',') + goto endofline; pos++; - if (opcstr[pos] == '!') { - /* exclusion */ - do { - pos++; - if (mode_from_str(opcstr+pos) == destmode) - goto nomatch; - pos += 4; - } while (opcstr[pos] == ','); - pos++; - } else { - if (opcstr[pos+4] == '-') { - /* replacement */ - if (mode_from_str(opcstr+pos) == destmode) - destmode = mode_from_str(opcstr+pos+5); - else - goto nomatch; - pos += 10; - } else { - /* normal */ - while(mode_from_str(opcstr+pos) != destmode) { - pos += 4; - if (opcstr[pos] == ']') + + /* parse the destination address */ + usedst = 1; + switch (opcstr[pos++]) { + case 'D': + destmode = Dreg; + switch (opcstr[pos++]) { + case 'r': destreg = bitval[bitr]; dstgather = 1; dstpos = bitpos[bitr]; break; + case 'R': destreg = bitval[bitR]; dstgather = 1; dstpos = bitpos[bitR]; break; + default: abort(); + } + if (dstpos < 0 || dstpos >= 32) + abort (); + break; + case 'A': + destmode = Areg; + switch (opcstr[pos++]) { + case 'r': destreg = bitval[bitr]; dstgather = 1; dstpos = bitpos[bitr]; break; + case 'R': destreg = bitval[bitR]; dstgather = 1; dstpos = bitpos[bitR]; break; + case 'x': destreg = 0; dstgather = 0; dstpos = 0; break; + default: abort(); + } + if (dstpos < 0 || dstpos >= 32) + abort (); + switch (opcstr[pos]) { + case 'p': destmode = Apdi; pos++; break; + case 'P': destmode = Aipi; pos++; break; + } + break; + case 'L': + destmode = absl; + break; + case '#': + switch (opcstr[pos++]) { + case 'z': destmode = imm; break; + case '0': destmode = imm0; break; + case '1': destmode = imm1; break; + case '2': destmode = imm2; break; + case 'i': destmode = immi; destreg = (uae_s32)(uae_s8)bitval[biti]; break; + case 'j': destmode = immi; destreg = bitval[bitj]; break; + case 'J': destmode = immi; destreg = bitval[bitJ]; break; + case 'k': destmode = immi; destreg = bitval[bitk]; break; + case 'K': destmode = immi; destreg = bitval[bitK]; break; + default: abort(); + } + break; + case 'd': + destreg = bitval[bitD]; + destmode = mode_from_mr(bitval[bitd],bitval[bitD]); + if (destmode == am_illg) + continue; + if (CPU_EMU_SIZE < 1 && + (destmode == Areg || destmode == Dreg || destmode == Aind + || destmode == Ad16 || destmode == Ad8r || destmode == Aipi + || destmode == Apdi)) + { + dstgather = 1; dstpos = bitpos[bitD]; + } + + if (opcstr[pos] == '[') { + pos++; + if (opcstr[pos] == '!') { + /* exclusion */ + do { + pos++; + if (mode_from_str(opcstr+pos) == destmode) + goto nomatch; + pos += 4; + } while (opcstr[pos] == ','); + pos++; + } else { + if (opcstr[pos+4] == '-') { + /* replacement */ + if (mode_from_str(opcstr+pos) == destmode) + destmode = mode_from_str(opcstr+pos+5); + else + goto nomatch; + pos += 10; + } else { + /* normal */ + while(mode_from_str(opcstr+pos) != destmode) { + pos += 4; + if (opcstr[pos] == ']') + goto nomatch; + pos++; + } + while(opcstr[pos] != ']') pos++; + pos++; + break; + } + } + } + /* Some addressing modes are invalid as destination */ + if (destmode == imm || destmode == PC16 || destmode == PC8r) goto nomatch; - pos++; + break; + case 's': + destreg = bitval[bitS]; + destmode = mode_from_mr(bitval[bits],bitval[bitS]); + + if (destmode == am_illg) + continue; + if (CPU_EMU_SIZE < 1 && + (destmode == Areg || destmode == Dreg || destmode == Aind + || destmode == Ad16 || destmode == Ad8r || destmode == Aipi + || destmode == Apdi)) + { + dstgather = 1; dstpos = bitpos[bitS]; + } + + if (opcstr[pos] == '[') { + pos++; + if (opcstr[pos] == '!') { + /* exclusion */ + do { + pos++; + if (mode_from_str(opcstr+pos) == destmode) + goto nomatch; + pos += 4; + } while (opcstr[pos] == ','); + pos++; + } else { + if (opcstr[pos+4] == '-') { + /* replacement */ + if (mode_from_str(opcstr+pos) == destmode) + destmode = mode_from_str(opcstr+pos+5); + else + goto nomatch; + pos += 10; + } else { + /* normal */ + while(mode_from_str(opcstr+pos) != destmode) { + pos += 4; + if (opcstr[pos] == ']') + goto nomatch; + pos++; + } + while(opcstr[pos] != ']') pos++; + pos++; + } + } } - while(opcstr[pos] != ']') pos++; - pos++; break; - } + default: abort(); } - } - /* Some addressing modes are invalid as destination */ - if (destmode == imm || destmode == PC16 || destmode == PC8r) - goto nomatch; - break; - case 's': - destreg = bitval[bitS]; - destmode = mode_from_mr(bitval[bits],bitval[bitS]); - - if (destmode == am_illg) - continue; - if (CPU_EMU_SIZE < 1 && - (destmode == Areg || destmode == Dreg || destmode == Aind - || destmode == Ad16 || destmode == Ad8r || destmode == Aipi - || destmode == Apdi)) + /* safety check - might have changed */ + if (destmode != Areg && destmode != Dreg && destmode != Aind + && destmode != Ad16 && destmode != Ad8r && destmode != Aipi + && destmode != Apdi) { - dstgather = 1; dstpos = bitpos[bitS]; + dstgather = 0; } - if (opcstr[pos] == '[') { - pos++; - if (opcstr[pos] == '!') { - /* exclusion */ - do { - pos++; - if (mode_from_str(opcstr+pos) == destmode) - goto nomatch; - pos += 4; - } while (opcstr[pos] == ','); - pos++; - } else { - if (opcstr[pos+4] == '-') { - /* replacement */ - if (mode_from_str(opcstr+pos) == destmode) - destmode = mode_from_str(opcstr+pos+5); - else - goto nomatch; - pos += 10; - } else { - /* normal */ - while(mode_from_str(opcstr+pos) != destmode) { - pos += 4; - if (opcstr[pos] == ']') - goto nomatch; - pos++; - } - while(opcstr[pos] != ']') pos++; - pos++; - } - } - } - break; - default: abort(); - } - /* safety check - might have changed */ - if (destmode != Areg && destmode != Dreg && destmode != Aind - && destmode != Ad16 && destmode != Ad8r && destmode != Aipi - && destmode != Apdi) - { - dstgather = 0; - } - - if (destmode == Areg && sz == sz_byte) - goto nomatch; + if (destmode == Areg && sz == sz_byte) + goto nomatch; #if 0 - if (sz == sz_byte && (destmode == Aipi || destmode == Apdi)) { - dstgather = 0; - } + if (sz == sz_byte && (destmode == Aipi || destmode == Apdi)) { + dstgather = 0; + } #endif - endofline: - /* now, we have a match */ - if (table68k[opc].mnemo != i_ILLG) - ;//write_log (L"Double match: %x: %s\n", opc, opcstr); - if (find == -1) { - for (find = 0;; find++) { - if (_tcscmp (mnemonic, lookuptab[find].name) == 0) { - table68k[opc].mnemo = lookuptab[find].mnemo; - break; +endofline: + /* now, we have a match */ + if (table68k[opc].mnemo != i_ILLG) + ;//write_log (L"Double match: %x: %s\n", opc, opcstr); + if (find == -1) { + for (find = 0;; find++) { + if (_tcscmp (mnemonic, lookuptab[find].name) == 0) { + table68k[opc].mnemo = lookuptab[find].mnemo; + break; + } + if (_tcslen (lookuptab[find].name) == 0) + abort(); + } } - if (_tcslen (lookuptab[find].name) == 0) - abort(); - } - } - else { - table68k[opc].mnemo = lookuptab[find].mnemo; - } - table68k[opc].cc = bitval[bitc]; - if (table68k[opc].mnemo == i_BTST - || table68k[opc].mnemo == i_BSET - || table68k[opc].mnemo == i_BCLR - || table68k[opc].mnemo == i_BCHG) - { - sz = destmode == Dreg ? sz_long : sz_byte; - } - table68k[opc].size = sz; - table68k[opc].sreg = srcreg; - table68k[opc].dreg = destreg; - table68k[opc].smode = srcmode; - table68k[opc].dmode = destmode; - table68k[opc].spos = srcgather ? srcpos : -1; - table68k[opc].dpos = dstgather ? dstpos : -1; - table68k[opc].suse = usesrc; - table68k[opc].duse = usedst; - table68k[opc].stype = srctype; - table68k[opc].plev = id.plevel; - table68k[opc].clev = specialcase(opc, id.cpulevel); + else { + table68k[opc].mnemo = lookuptab[find].mnemo; + } + table68k[opc].cc = bitval[bitc]; + if (table68k[opc].mnemo == i_BTST + || table68k[opc].mnemo == i_BSET + || table68k[opc].mnemo == i_BCLR + || table68k[opc].mnemo == i_BCHG) + { + sz = destmode == Dreg ? sz_long : sz_byte; + } + table68k[opc].size = sz; + table68k[opc].sreg = srcreg; + table68k[opc].dreg = destreg; + table68k[opc].smode = srcmode; + table68k[opc].dmode = destmode; + table68k[opc].spos = srcgather ? srcpos : -1; + table68k[opc].dpos = dstgather ? dstpos : -1; + table68k[opc].suse = usesrc; + table68k[opc].duse = usedst; + table68k[opc].stype = srctype; + table68k[opc].plev = id.plevel; + table68k[opc].clev = specialcase(opc, id.cpulevel); #if 0 - for (i = 0; i < 5; i++) { - table68k[opc].flaginfo[i].flagset = id.flaginfo[i].flagset; - table68k[opc].flaginfo[i].flaguse = id.flaginfo[i].flaguse; - } + for (i = 0; i < 5; i++) { + table68k[opc].flaginfo[i].flagset = id.flaginfo[i].flagset; + table68k[opc].flaginfo[i].flaguse = id.flaginfo[i].flaguse; + } #endif - table68k[opc].flagdead = flagdead; - table68k[opc].flaglive = flaglive; - table68k[opc].isjmp = isjmp; - nomatch: - /* FOO! */; - } + table68k[opc].flagdead = flagdead; + table68k[opc].flaglive = flaglive; + table68k[opc].isjmp = isjmp; +nomatch: + /* FOO! */; + } } void read_table68k (void) { - int i; - - free (table68k); - table68k = (struct instr *)xmalloc (65536 * sizeof (struct instr)); - for (i = 0; i < 65536; i++) { - table68k[i].mnemo = i_ILLG; - table68k[i].handler = -1; - } - for (i = 0; i < n_defs68k; i++) { - build_insn (i); - } + int i; + + free (table68k); + table68k = (struct instr *)xmalloc (65536 * sizeof (struct instr)); + for (i = 0; i < 65536; i++) { + table68k[i].mnemo = i_ILLG; + table68k[i].handler = -1; + } + for (i = 0; i < n_defs68k; i++) { + build_insn (i); + } } static int mismatch; static void handle_merges (long int opcode) { - uae_u16 smsk; - uae_u16 dmsk; - int sbitdst, dstend; - int srcreg, dstreg; - - if (table68k[opcode].spos == -1) { - sbitdst = 1; smsk = 0; - } else { - switch (table68k[opcode].stype) { - case 0: - smsk = 7; sbitdst = 8; break; - case 1: - smsk = 255; sbitdst = 256; break; - case 2: - smsk = 15; sbitdst = 16; break; - case 3: - smsk = 7; sbitdst = 8; break; - case 4: - smsk = 7; sbitdst = 8; break; - case 5: - smsk = 63; sbitdst = 64; break; - case 7: - smsk = 3; sbitdst = 4; break; - default: - smsk = 0; sbitdst = 0; - abort(); - break; + uae_u16 smsk; + uae_u16 dmsk; + int sbitdst, dstend; + int srcreg, dstreg; + + if (table68k[opcode].spos == -1) { + sbitdst = 1; smsk = 0; + } else { + switch (table68k[opcode].stype) { + case 0: + smsk = 7; sbitdst = 8; break; + case 1: + smsk = 255; sbitdst = 256; break; + case 2: + smsk = 15; sbitdst = 16; break; + case 3: + smsk = 7; sbitdst = 8; break; + case 4: + smsk = 7; sbitdst = 8; break; + case 5: + smsk = 63; sbitdst = 64; break; + case 7: + smsk = 3; sbitdst = 4; break; + default: + smsk = 0; sbitdst = 0; + abort(); + break; + } + smsk <<= table68k[opcode].spos; + } + if (table68k[opcode].dpos == -1) { + dstend = 1; dmsk = 0; + } else { + dmsk = 7 << table68k[opcode].dpos; + dstend = 8; } - smsk <<= table68k[opcode].spos; - } - if (table68k[opcode].dpos == -1) { - dstend = 1; dmsk = 0; - } else { - dmsk = 7 << table68k[opcode].dpos; - dstend = 8; - } - for (srcreg=0; srcreg < sbitdst; srcreg++) { - for (dstreg=0; dstreg < dstend; dstreg++) { - uae_u16 code = (uae_u16)opcode; - - code = (code & ~smsk) | (srcreg << table68k[opcode].spos); - code = (code & ~dmsk) | (dstreg << table68k[opcode].dpos); - - /* Check whether this is in fact the same instruction. - * The instructions should never differ, except for the - * Bcc.(BW) case. */ - if (table68k[code].mnemo != table68k[opcode].mnemo - || table68k[code].size != table68k[opcode].size - || table68k[code].suse != table68k[opcode].suse - || table68k[code].duse != table68k[opcode].duse) - { - mismatch++; continue; - } - if (table68k[opcode].suse - && (table68k[opcode].spos != table68k[code].spos - || table68k[opcode].smode != table68k[code].smode - || table68k[opcode].stype != table68k[code].stype)) - { - mismatch++; continue; - } - if (table68k[opcode].duse - && (table68k[opcode].dpos != table68k[code].dpos - || table68k[opcode].dmode != table68k[code].dmode)) - { - mismatch++; continue; - } - - if (code != opcode) - table68k[code].handler = opcode; + for (srcreg=0; srcreg < sbitdst; srcreg++) { + for (dstreg=0; dstreg < dstend; dstreg++) { + uae_u16 code = (uae_u16)opcode; + + code = (code & ~smsk) | (srcreg << table68k[opcode].spos); + code = (code & ~dmsk) | (dstreg << table68k[opcode].dpos); + + /* Check whether this is in fact the same instruction. + * The instructions should never differ, except for the + * Bcc.(BW) case. */ + if (table68k[code].mnemo != table68k[opcode].mnemo + || table68k[code].size != table68k[opcode].size + || table68k[code].suse != table68k[opcode].suse + || table68k[code].duse != table68k[opcode].duse) + { + mismatch++; continue; + } + if (table68k[opcode].suse + && (table68k[opcode].spos != table68k[code].spos + || table68k[opcode].smode != table68k[code].smode + || table68k[opcode].stype != table68k[code].stype)) + { + mismatch++; continue; + } + if (table68k[opcode].duse + && (table68k[opcode].dpos != table68k[code].dpos + || table68k[opcode].dmode != table68k[code].dmode)) + { + mismatch++; continue; + } + + if (code != opcode) + table68k[code].handler = opcode; + } } - } } void do_merges (void) { - long int opcode; - int nr = 0; - mismatch = 0; - for (opcode = 0; opcode < 65536; opcode++) { - if (table68k[opcode].handler != -1 || table68k[opcode].mnemo == i_ILLG) - continue; - nr++; - handle_merges (opcode); - } - nr_cpuop_funcs = nr; + long int opcode; + int nr = 0; + mismatch = 0; + for (opcode = 0; opcode < 65536; opcode++) { + if (table68k[opcode].handler != -1 || table68k[opcode].mnemo == i_ILLG) + continue; + nr++; + handle_merges (opcode); + } + nr_cpuop_funcs = nr; } int get_no_mismatches (void) { - return mismatch; + return mismatch; } diff --git a/sana2.c b/sana2.c index 673a78d5..c43e98cf 100644 --- a/sana2.c +++ b/sana2.c @@ -1,13 +1,13 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * SanaII emulation - * - * partially based on code from 3c589 PCMCIA driver by Neil Cafferke - * - * Copyright 2007 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* SanaII emulation +* +* partially based on code from 3c589 PCMCIA driver by Neil Cafferke +* +* Copyright 2007 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -107,7 +107,7 @@ #define S2EVENT_SOFTWARE (1L<<7) /* software error catch all */ #define KNOWN_EVENTS (S2EVENT_ERROR|S2EVENT_TX|S2EVENT_RX|S2EVENT_ONLINE|\ - S2EVENT_OFFLINE|S2EVENT_BUFF|S2EVENT_HARDWARE|S2EVENT_SOFTWARE) + S2EVENT_OFFLINE|S2EVENT_BUFF|S2EVENT_HARDWARE|S2EVENT_SOFTWARE) #define SANA2OPB_MINE 0 #define SANA2OPF_MINE (1<= MAX_TOTAL_NET_DEVICES || unit < 0) - return 0; - return &devst[unit]; + if (unit >= MAX_TOTAL_NET_DEVICES || unit < 0) + return 0; + return &devst[unit]; } static struct priv_devstruct *getpdevstruct (uaecptr request) { - int i = get_long (request + 24); - if (i < 0 || i >= MAX_OPEN_DEVICES || pdevst[i].inuse == 0) { - write_log (L"%s: corrupt iorequest %08X %d\n", SANA2NAME, request, i); - return 0; - } - return &pdevst[i]; + int i = get_long (request + 24); + if (i < 0 || i >= MAX_OPEN_DEVICES || pdevst[i].inuse == 0) { + write_log (L"%s: corrupt iorequest %08X %d\n", SANA2NAME, request, i); + return 0; + } + return &pdevst[i]; } static void *dev_thread (void *devs); static int start_thread (struct devstruct *dev) { - if (dev->thread_running) - return 1; - init_comm_pipe (&dev->requests, 100, 1); - uae_sem_init (&dev->sync_sem, 0, 0); - uae_start_thread (SANA2NAME, dev_thread, dev, NULL); - uae_sem_wait (&dev->sync_sem); - return dev->thread_running; + if (dev->thread_running) + return 1; + init_comm_pipe (&dev->requests, 100, 1); + uae_sem_init (&dev->sync_sem, 0, 0); + uae_start_thread (SANA2NAME, dev_thread, dev, NULL); + uae_sem_wait (&dev->sync_sem); + return dev->thread_running; } static uae_u32 REGPARAM2 dev_close_2 (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; + uae_u32 request = m68k_areg (regs, 1); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; - if (!pdev) { - write_log (L"%s close with unknown request %08X!?\n", SANA2NAME, request); - return 0; - } - dev = getdevstruct (pdev->unit); - if (!dev) { - write_log (L"%s:%d close with unknown request %08X!?\n", SANA2NAME, pdev->unit, request); - return 0; - } - if (log_net) - write_log (L"%s:%d close, open=%d req=%08X\n", SANA2NAME, pdev->unit, dev->opencnt, request); - put_long (request + 24, 0); - dev->opencnt--; - pdev->inuse = 0; - if (!dev->opencnt) { - dev->exclusive = 0; - if (pdev->tempbuf) { - m68k_areg (regs, 1) = pdev->tempbuf; - m68k_dreg (regs, 0) = pdev->td->mtu + ETH_HEADER_SIZE + 2; - CallLib (context, get_long (4), -0xD2); /* FreeMem */ - pdev->tempbuf = 0; + if (!pdev) { + write_log (L"%s close with unknown request %08X!?\n", SANA2NAME, request); + return 0; + } + dev = getdevstruct (pdev->unit); + if (!dev) { + write_log (L"%s:%d close with unknown request %08X!?\n", SANA2NAME, pdev->unit, request); + return 0; + } + if (log_net) + write_log (L"%s:%d close, open=%d req=%08X\n", SANA2NAME, pdev->unit, dev->opencnt, request); + put_long (request + 24, 0); + dev->opencnt--; + pdev->inuse = 0; + if (!dev->opencnt) { + dev->exclusive = 0; + if (pdev->tempbuf) { + m68k_areg (regs, 1) = pdev->tempbuf; + m68k_dreg (regs, 0) = pdev->td->mtu + ETH_HEADER_SIZE + 2; + CallLib (context, get_long (4), -0xD2); /* FreeMem */ + pdev->tempbuf = 0; + } + uaenet_close (dev->sysdata); + xfree (dev->sysdata); + dev->sysdata = NULL; + write_comm_pipe_u32 (&dev->requests, 0, 1); + write_log (L"%s: opencnt == 0, all instances closed\n", SANA2NAME); } - uaenet_close (dev->sysdata); - xfree (dev->sysdata); - dev->sysdata = NULL; - write_comm_pipe_u32 (&dev->requests, 0, 1); - write_log (L"%s: opencnt == 0, all instances closed\n", SANA2NAME); - } - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); - return 0; + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); + return 0; } static uae_u32 REGPARAM2 dev_close (TrapContext *context) { - return dev_close_2 (context); + return dev_close_2 (context); } static uae_u32 REGPARAM2 diskdev_close (TrapContext *context) { - return dev_close_2 (context); + return dev_close_2 (context); } static int openfail (uaecptr ioreq, int error) { - put_long (ioreq + 20, -1); - put_byte (ioreq + 31, error); - put_long (ioreq + 32, 0); /* io_device */ - if (log_net) - write_log (L"-> failed with error %d\n", error); - return (uae_u32)-1; + put_long (ioreq + 20, -1); + put_byte (ioreq + 31, error); + put_long (ioreq + 32, 0); /* io_device */ + if (log_net) + write_log (L"-> failed with error %d\n", error); + return (uae_u32)-1; } static uae_u32 REGPARAM2 uaenet_int_handler (TrapContext *ctx); static int irq_init; static int initint (TrapContext *ctx) { - uae_u32 tmp1; - uaecptr p; + uae_u32 tmp1; + uaecptr p; - if (irq_init) + if (irq_init) + return 1; + m68k_dreg (regs, 0) = 26; + m68k_dreg (regs, 1) = 65536 + 1; + p = CallLib (ctx, get_long (4), -0xC6); /* AllocMem */ + if (!p) + return 0; + tmp1 = here (); + calltrap (deftrap2 (uaenet_int_handler, TRAPFLAG_EXTRA_STACK, L"uaenet_int_handler")); + put_word (p + 8, 0x020a); + put_long (p + 10, ROM_netdev_resid); + put_long (p + 18, tmp1); + m68k_areg (regs, 1) = p; + m68k_dreg (regs, 0) = 13; /* EXTER */ + dw (0x4a80); /* TST.L D0 */ + dw (0x4e75); /* RTS */ + CallLib (ctx, get_long (4), -168); /* AddIntServer */ + irq_init = 1; return 1; - m68k_dreg (regs, 0) = 26; - m68k_dreg (regs, 1) = 65536 + 1; - p = CallLib (ctx, get_long (4), -0xC6); /* AllocMem */ - if (!p) - return 0; - tmp1 = here (); - calltrap (deftrap2 (uaenet_int_handler, TRAPFLAG_EXTRA_STACK, L"uaenet_int_handler")); - put_word (p + 8, 0x020a); - put_long (p + 10, ROM_netdev_resid); - put_long (p + 18, tmp1); - m68k_areg (regs, 1) = p; - m68k_dreg (regs, 0) = 13; /* EXTER */ - dw (0x4a80); /* TST.L D0 */ - dw (0x4e75); /* RTS */ - CallLib (ctx, get_long (4), -168); /* AddIntServer */ - irq_init = 1; - return 1; } static uae_u32 REGPARAM2 dev_open_2 (TrapContext *context) { - uaecptr ioreq = m68k_areg (regs, 1); - uae_u32 unit = m68k_dreg (regs, 0); - uae_u32 flags = m68k_dreg (regs, 1); - uaecptr buffermgmt; - struct devstruct *dev = getdevstruct (unit); - struct priv_devstruct *pdev = 0; - int i; - uaecptr tagp, tagpnext; - - if (!dev) - return openfail (ioreq, IOERR_OPENFAIL); - if (!initint(context)) - return openfail (ioreq, IOERR_SELFTEST); - if (log_net) - write_log (L"opening %s:%d opencnt=%d ioreq=%08X\n", SANA2NAME, unit, dev->opencnt, ioreq); - if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) - return openfail (ioreq, IOERR_BADLENGTH); - if ((flags & SANA2OPF_PROM) && dev->opencnt > 0) - return openfail (ioreq, IOERR_UNITBUSY); - - for (i = 0; i < MAX_OPEN_DEVICES; i++) { - pdev = &pdevst[i]; - if (pdev->inuse == 0) - break; - } - if (i == MAX_OPEN_DEVICES) - return openfail (ioreq, IOERR_UNITBUSY); - - put_long (ioreq + 24, pdev - pdevst); - pdev->unit = unit; - pdev->flags = flags; - pdev->inuse = 1; - pdev->td = &td[unit]; - pdev->promiscuous = (flags & SANA2OPF_PROM) ? 1 : 0; - - if (pdev->td->active == 0) - return openfail (ioreq, IOERR_OPENFAIL); - - if (dev->opencnt == 0) { - dev->unit = unit; - dev->sysdata = xcalloc (uaenet_getdatalenght(), 1); - if (!uaenet_open (dev->sysdata, pdev->td, dev, uaenet_gotdata, uaenet_getdata, pdev->promiscuous)) { - xfree (dev->sysdata); - dev->sysdata = NULL; - return openfail (ioreq, IOERR_OPENFAIL); + uaecptr ioreq = m68k_areg (regs, 1); + uae_u32 unit = m68k_dreg (regs, 0); + uae_u32 flags = m68k_dreg (regs, 1); + uaecptr buffermgmt; + struct devstruct *dev = getdevstruct (unit); + struct priv_devstruct *pdev = 0; + int i; + uaecptr tagp, tagpnext; + + if (!dev) + return openfail (ioreq, IOERR_OPENFAIL); + if (!initint(context)) + return openfail (ioreq, IOERR_SELFTEST); + if (log_net) + write_log (L"opening %s:%d opencnt=%d ioreq=%08X\n", SANA2NAME, unit, dev->opencnt, ioreq); + if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) + return openfail (ioreq, IOERR_BADLENGTH); + if ((flags & SANA2OPF_PROM) && dev->opencnt > 0) + return openfail (ioreq, IOERR_UNITBUSY); + + for (i = 0; i < MAX_OPEN_DEVICES; i++) { + pdev = &pdevst[i]; + if (pdev->inuse == 0) + break; } - write_log (L"%s: initializing unit %d\n", getdevname (), unit); - dev->td = pdev->td; - dev->adapter = pdev->td->active; - if (dev->adapter) { - dev->online = 1; - dev->configured = 1; + if (i == MAX_OPEN_DEVICES) + return openfail (ioreq, IOERR_UNITBUSY); + + put_long (ioreq + 24, pdev - pdevst); + pdev->unit = unit; + pdev->flags = flags; + pdev->inuse = 1; + pdev->td = &td[unit]; + pdev->promiscuous = (flags & SANA2OPF_PROM) ? 1 : 0; + + if (pdev->td->active == 0) + return openfail (ioreq, IOERR_OPENFAIL); + + if (dev->opencnt == 0) { + dev->unit = unit; + dev->sysdata = xcalloc (uaenet_getdatalenght(), 1); + if (!uaenet_open (dev->sysdata, pdev->td, dev, uaenet_gotdata, uaenet_getdata, pdev->promiscuous)) { + xfree (dev->sysdata); + dev->sysdata = NULL; + return openfail (ioreq, IOERR_OPENFAIL); + } + write_log (L"%s: initializing unit %d\n", getdevname (), unit); + dev->td = pdev->td; + dev->adapter = pdev->td->active; + if (dev->adapter) { + dev->online = 1; + dev->configured = 1; + } + start_thread (dev); } - start_thread (dev); - } - - if (kickstart_version >= 36) { - m68k_areg (regs, 0) = get_long (4) + 350; - m68k_areg (regs, 1) = timerdevname; - CallLib (context, get_long (4), -0x114); /* FindName('timer.device') */ - pdev->timerbase = m68k_dreg (regs, 0); - } - - pdev->copyfrombuff = pdev->copytobuff = pdev->packetfilter = 0; - pdev->tempbuf = 0; - if (get_word (ioreq + 0x12) >= SANA2_IOREQSIZE) { - buffermgmt = get_long (ioreq + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4); - tagpnext = buffermgmt; - while (tagpnext) { - uae_u32 tag = get_long (tagpnext); - uae_u32 val = get_long (tagpnext + 4); - tagp = tagpnext; - tagpnext += 8; - switch (tag) - { - case TAG_DONE: - tagpnext = 0; - break; - case TAG_IGNORE: - break; - case TAG_MORE: - tagpnext = val; - break; - case TAG_SKIP: - tagpnext = tagp + val * 8; - break; - case S2_CopyToBuff: - pdev->copytobuff = val; - break; - case S2_CopyFromBuff: - pdev->copyfrombuff = val; - break; - case S2_PacketFilter: - pdev->packetfilter = val; - break; - } + + if (kickstart_version >= 36) { + m68k_areg (regs, 0) = get_long (4) + 350; + m68k_areg (regs, 1) = timerdevname; + CallLib (context, get_long (4), -0x114); /* FindName('timer.device') */ + pdev->timerbase = m68k_dreg (regs, 0); } - if (log_net) - write_log (L"%s:%d CTB=%08x CFB=%08x PF=%08x\n", - getdevname(), unit, pdev->copytobuff, pdev->copyfrombuff, pdev->packetfilter); - m68k_dreg (regs, 0) = dev->td->mtu + ETH_HEADER_SIZE + 2; - m68k_dreg (regs, 1) = 1; - pdev->tempbuf = CallLib (context, get_long (4), -0xC6); /* AllocMem */ - if (!pdev->tempbuf) { - if (dev->opencnt == 0) { - uaenet_close (dev->sysdata); - xfree (dev->sysdata); - dev->sysdata = NULL; - } - return openfail (ioreq, S2ERR_BAD_ARGUMENT); + + pdev->copyfrombuff = pdev->copytobuff = pdev->packetfilter = 0; + pdev->tempbuf = 0; + if (get_word (ioreq + 0x12) >= SANA2_IOREQSIZE) { + buffermgmt = get_long (ioreq + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4); + tagpnext = buffermgmt; + while (tagpnext) { + uae_u32 tag = get_long (tagpnext); + uae_u32 val = get_long (tagpnext + 4); + tagp = tagpnext; + tagpnext += 8; + switch (tag) + { + case TAG_DONE: + tagpnext = 0; + break; + case TAG_IGNORE: + break; + case TAG_MORE: + tagpnext = val; + break; + case TAG_SKIP: + tagpnext = tagp + val * 8; + break; + case S2_CopyToBuff: + pdev->copytobuff = val; + break; + case S2_CopyFromBuff: + pdev->copyfrombuff = val; + break; + case S2_PacketFilter: + pdev->packetfilter = val; + break; + } + } + if (log_net) + write_log (L"%s:%d CTB=%08x CFB=%08x PF=%08x\n", + getdevname(), unit, pdev->copytobuff, pdev->copyfrombuff, pdev->packetfilter); + m68k_dreg (regs, 0) = dev->td->mtu + ETH_HEADER_SIZE + 2; + m68k_dreg (regs, 1) = 1; + pdev->tempbuf = CallLib (context, get_long (4), -0xC6); /* AllocMem */ + if (!pdev->tempbuf) { + if (dev->opencnt == 0) { + uaenet_close (dev->sysdata); + xfree (dev->sysdata); + dev->sysdata = NULL; + } + return openfail (ioreq, S2ERR_BAD_ARGUMENT); + } + /* buffermanagement */ + put_long (ioreq + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4, pdev->tempbuf); } - /* buffermanagement */ - put_long (ioreq + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4, pdev->tempbuf); - } - dev->exclusive = flags & SANA2OPF_MINE; - dev->opencnt++; - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); - put_byte (ioreq + 31, 0); - put_byte (ioreq + 8, 7); - return 0; + dev->exclusive = flags & SANA2OPF_MINE; + dev->opencnt++; + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); + put_byte (ioreq + 31, 0); + put_byte (ioreq + 8, 7); + return 0; } static uae_u32 REGPARAM2 dev_open (TrapContext *context) { - return dev_open_2 (context); + return dev_open_2 (context); } static uae_u32 REGPARAM2 dev_expunge (TrapContext *context) { - return 0; + return 0; } static uae_u32 REGPARAM2 diskdev_expunge (TrapContext *context) { - return 0; + return 0; } static void freepacket (struct s2packet *s2p) { - xfree (s2p->data); - xfree (s2p); + xfree (s2p->data); + xfree (s2p); } static void add_async_packet (struct devstruct *dev, struct s2packet *s2p, uaecptr request) { - struct asyncreq *ar, *ar2; - - ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); - ar->s2p = s2p; - if (!dev->s2p) { - dev->s2p = ar; - } else { - ar2 = dev->s2p; - while (ar2->next) - ar2 = ar2->next; - ar2->next = ar; - } - ar->request = request; + struct asyncreq *ar, *ar2; + + ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); + ar->s2p = s2p; + if (!dev->s2p) { + dev->s2p = ar; + } else { + ar2 = dev->s2p; + while (ar2->next) + ar2 = ar2->next; + ar2->next = ar; + } + ar->request = request; } static void rem_async_packet (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar, *prevar; - - uae_sem_wait (&async_sem); - ar = dev->s2p; - prevar = NULL; - while (ar) { - if (ar->request == request) { - if (prevar == NULL) - dev->s2p = ar->next; - else - prevar->next = ar->next; - uae_sem_post (&async_sem); - freepacket (ar->s2p); - xfree (ar); - return; + struct asyncreq *ar, *prevar; + + uae_sem_wait (&async_sem); + ar = dev->s2p; + prevar = NULL; + while (ar) { + if (ar->request == request) { + if (prevar == NULL) + dev->s2p = ar->next; + else + prevar->next = ar->next; + uae_sem_post (&async_sem); + freepacket (ar->s2p); + xfree (ar); + return; + } + prevar = ar; + ar = ar->next; } - prevar = ar; - ar = ar->next; - } - uae_sem_post (&async_sem); + uae_sem_post (&async_sem); } static struct asyncreq *get_async_request (struct devstruct *dev, uaecptr request, int ready) { - struct asyncreq *ar; - int ret = 0; - - uae_sem_wait (&async_sem); - ar = dev->ar; - while (ar) { - if (ar->request == request) { - if (ready) - ar->ready = 1; - break; + struct asyncreq *ar; + int ret = 0; + + uae_sem_wait (&async_sem); + ar = dev->ar; + while (ar) { + if (ar->request == request) { + if (ready) + ar->ready = 1; + break; + } + ar = ar->next; } - ar = ar->next; - } - uae_sem_post (&async_sem); - return ar; + uae_sem_post (&async_sem); + return ar; } static int add_async_request (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar, *ar2; - - if (log_net) - write_log (L"%s:%d async request %x added\n", getdevname(), dev->unit, request); - - uae_sem_wait (&async_sem); - ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); - ar->request = request; - if (!dev->ar) { - dev->ar = ar; - } else { - ar2 = dev->ar; - while (ar2->next) - ar2 = ar2->next; - ar2->next = ar; - } - uae_sem_post (&async_sem); - return 1; + struct asyncreq *ar, *ar2; + + if (log_net) + write_log (L"%s:%d async request %x added\n", getdevname(), dev->unit, request); + + uae_sem_wait (&async_sem); + ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); + ar->request = request; + if (!dev->ar) { + dev->ar = ar; + } else { + ar2 = dev->ar; + while (ar2->next) + ar2 = ar2->next; + ar2->next = ar; + } + uae_sem_post (&async_sem); + return 1; } static int release_async_request (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar, *prevar; - - uae_sem_wait (&async_sem); - ar = dev->ar; - prevar = NULL; - while (ar) { - if (ar->request == request) { - if (prevar == NULL) - dev->ar = ar->next; - else - prevar->next = ar->next; - uae_sem_post (&async_sem); - xfree (ar); - if (log_net) - write_log (L"%s:%d async request %x removed\n", getdevname(), dev->unit, request); - return 1; + struct asyncreq *ar, *prevar; + + uae_sem_wait (&async_sem); + ar = dev->ar; + prevar = NULL; + while (ar) { + if (ar->request == request) { + if (prevar == NULL) + dev->ar = ar->next; + else + prevar->next = ar->next; + uae_sem_post (&async_sem); + xfree (ar); + if (log_net) + write_log (L"%s:%d async request %x removed\n", getdevname(), dev->unit, request); + return 1; + } + prevar = ar; + ar = ar->next; } - prevar = ar; - ar = ar->next; - } - uae_sem_post (&async_sem); - write_log (L"%s:%d async request %x not found for removal!\n", getdevname(), dev->unit, request); - return 0; + uae_sem_post (&async_sem); + write_log (L"%s:%d async request %x not found for removal!\n", getdevname(), dev->unit, request); + return 0; } static void do_abort_async (struct devstruct *dev, uaecptr request) { - put_byte (request + 30, get_byte (request + 30) | 0x20); - put_byte (request + 31, IOERR_ABORTED); - put_long (request + 32, S2WERR_GENERIC_ERROR); - write_comm_pipe_u32 (&dev->requests, request, 1); + put_byte (request + 30, get_byte (request + 30) | 0x20); + put_byte (request + 31, IOERR_ABORTED); + put_long (request + 32, S2WERR_GENERIC_ERROR); + write_comm_pipe_u32 (&dev->requests, request, 1); } static void abort_async (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar = get_async_request (dev, request, 1); - if (!ar) { - write_log (L"%s:%d: abort async but no request %x found!\n", getdevname(), dev->unit, request); - return; - } - if (log_net) - write_log (L"%s:%d asyncronous request=%08X aborted\n", getdevname(), dev->unit, request); - do_abort_async (dev, request); + struct asyncreq *ar = get_async_request (dev, request, 1); + if (!ar) { + write_log (L"%s:%d: abort async but no request %x found!\n", getdevname(), dev->unit, request); + return; + } + if (log_net) + write_log (L"%s:%d asyncronous request=%08X aborted\n", getdevname(), dev->unit, request); + do_abort_async (dev, request); } static void signalasync (struct devstruct *dev, struct asyncreq *ar, int actual, int err) { - uaecptr request = ar->request; - int command = get_word (request + 28); - if (log_net) - write_log (L"%s:%d CMD=%d async request %x completed\n", getdevname(), dev->unit, command, request); - put_long (request + 32, actual); - put_byte (request + 31, err); - ar->ready = 1; - write_comm_pipe_u32 (&dev->requests, request, 1); + uaecptr request = ar->request; + int command = get_word (request + 28); + if (log_net) + write_log (L"%s:%d CMD=%d async request %x completed\n", getdevname(), dev->unit, command, request); + put_long (request + 32, actual); + put_byte (request + 31, err); + ar->ready = 1; + write_comm_pipe_u32 (&dev->requests, request, 1); } static uae_u32 copytobuff (TrapContext *ctx, uaecptr from, uaecptr to, uae_u32 len, uaecptr func) { - m68k_areg (regs, 0) = to; - m68k_areg (regs, 1) = from; - m68k_dreg (regs, 0) = len; - return CallFunc (ctx, func); + m68k_areg (regs, 0) = to; + m68k_areg (regs, 1) = from; + m68k_dreg (regs, 0) = len; + return CallFunc (ctx, func); } static uae_u32 copyfrombuff (TrapContext *ctx, uaecptr from, uaecptr to, uae_u32 len, uaecptr func) { - m68k_areg (regs, 0) = to; - m68k_areg (regs, 1) = from; - m68k_dreg (regs, 0) = len; - return CallFunc (ctx, func); + m68k_areg (regs, 0) = to; + m68k_areg (regs, 1) = from; + m68k_dreg (regs, 0) = len; + return CallFunc (ctx, func); } static uae_u32 packetfilter (TrapContext *ctx, uaecptr hook, uaecptr ios2, uaecptr data) { - uae_u32 a2, v; - - a2 = m68k_areg (regs, 2); - m68k_areg (regs, 0) = hook; - m68k_areg (regs, 2) = ios2; - m68k_areg (regs, 1) = data; - v = CallFunc (ctx, get_long (hook + 8)); - m68k_areg (regs, 2) = a2; - return v; + uae_u32 a2, v; + + a2 = m68k_areg (regs, 2); + m68k_areg (regs, 0) = hook; + m68k_areg (regs, 2) = ios2; + m68k_areg (regs, 1) = data; + v = CallFunc (ctx, get_long (hook + 8)); + m68k_areg (regs, 2) = a2; + return v; } static int isbroadcast (const uae_u8 *d) { - if (d[0] == 0xff && d[1] == 0xff && d[2] == 0xff && - d[3] == 0xff && d[4] == 0xff && d[5] == 0xff) - return 1; - return 0; + if (d[0] == 0xff && d[1] == 0xff && d[2] == 0xff && + d[3] == 0xff && d[4] == 0xff && d[5] == 0xff) + return 1; + return 0; } static int ismulticast (const uae_u8 *d) { - if (isbroadcast (d)) + if (isbroadcast (d)) + return 0; + if (d[0] & 1) + return 1; return 0; - if (d[0] & 1) - return 1; - return 0; } static uae_u64 addrto64 (const uae_u8 *d) { - int i; - uae_u64 addr = 0; - for (i = 0; i < ADDR_SIZE; i++) { - addr <<= 8; - addr |= d[i]; - } - return addr; + int i; + uae_u64 addr = 0; + for (i = 0; i < ADDR_SIZE; i++) { + addr <<= 8; + addr |= d[i]; + } + return addr; } static uae_u64 amigaaddrto64 (uaecptr d) { - int i; - uae_u64 addr = 0; - for (i = 0; i < ADDR_SIZE; i++) { - addr <<= 8; - addr |= get_byte (d + i); - } - return addr; + int i; + uae_u64 addr = 0; + for (i = 0; i < ADDR_SIZE; i++) { + addr <<= 8; + addr |= get_byte (d + i); + } + return addr; } static void addmulticastaddresses (struct devstruct *dev, uae_u64 start, uae_u64 end) { - struct mcast *mc, *mc2; - - if (!end) - end = start; - mc = dev->mc; - while (mc) { - if (start == mc->start && end == mc->end) { - mc->cnt++; - return; + struct mcast *mc, *mc2; + + if (!end) + end = start; + mc = dev->mc; + while (mc) { + if (start == mc->start && end == mc->end) { + mc->cnt++; + return; + } + mc = mc->next; + } + mc = xcalloc (sizeof (struct mcast), 1); + mc->start = start; + mc->end = end; + mc->cnt = 1; + if (!dev->mc) { + dev->mc = mc; + } else { + mc2 = dev->mc; + while (mc2->next) + mc2 = mc2->next; + mc2->next = mc; } - mc = mc->next; - } - mc = xcalloc (sizeof (struct mcast), 1); - mc->start = start; - mc->end = end; - mc->cnt = 1; - if (!dev->mc) { - dev->mc = mc; - } else { - mc2 = dev->mc; - while (mc2->next) - mc2 = mc2->next; - mc2->next = mc; - } } static int delmulticastaddresses (struct devstruct *dev, uae_u64 start, uae_u64 end) { - struct mcast *mc, *prevmc; - - if (!end) - end = start; - mc = dev->mc; - prevmc = NULL; - while (mc) { - if (start == mc->start && end == mc->end) { - mc->cnt--; - if (mc->cnt > 0) - return 1; - if (prevmc == NULL) - dev->mc = mc->next; - else - prevmc->next = mc->next; - xfree (mc); - return 1; + struct mcast *mc, *prevmc; + + if (!end) + end = start; + mc = dev->mc; + prevmc = NULL; + while (mc) { + if (start == mc->start && end == mc->end) { + mc->cnt--; + if (mc->cnt > 0) + return 1; + if (prevmc == NULL) + dev->mc = mc->next; + else + prevmc->next = mc->next; + xfree (mc); + return 1; + } + prevmc = mc; + mc = mc->next; } - prevmc = mc; - mc = mc->next; - } - return 0; + return 0; } static struct s2packet *createreadpacket (struct devstruct *dev, const uae_u8 *d, int len) { - struct s2packet *s2p = xcalloc (sizeof (struct s2packet), 1); - s2p->data = xmalloc (dev->td->mtu + ETH_HEADER_SIZE + 2); - memcpy (s2p->data, d, len); - s2p->len = len; - return s2p; + struct s2packet *s2p = xcalloc (sizeof (struct s2packet), 1); + s2p->data = xmalloc (dev->td->mtu + ETH_HEADER_SIZE + 2); + memcpy (s2p->data, d, len); + s2p->len = len; + return s2p; } static int handleread (TrapContext *ctx, struct priv_devstruct *pdev, uaecptr request, uae_u8 *d, int len, int cmd) { - uae_u8 flags = get_byte (request + 30); - uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); - uaecptr srcaddr = request + 32 + 4 + 4; - uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; - uae_u16 type = (d[2 * ADDR_SIZE] << 8) | d[2 * ADDR_SIZE + 1]; - uae_u32 v = 0; - uaecptr data2; - - memcpyha_safe (pdev->tempbuf, d, len); - memcpyha_safe (dstaddr, d, ADDR_SIZE); - memcpyha_safe (srcaddr, d + ADDR_SIZE, ADDR_SIZE); - put_long (request + 32 + 4, type); - if (pdev->tracks[type]) { - pdev->bytesreceived += len; - pdev->packetsreceived++; - } - flags &= ~(SANA2IOF_BCAST | SANA2IOF_MCAST); - if (isbroadcast (d)) - flags |= SANA2IOF_BCAST; - else if (ismulticast (d)) - flags |= SANA2IOF_MCAST; - put_byte (request + 30, flags); - - data2 = pdev->tempbuf; - if (!(flags & SANA2IOF_RAW)) { - len -= ETH_HEADER_SIZE; - data2 += ETH_HEADER_SIZE; - } - put_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2, len); - - if (pdev->packetfilter && cmd == CMD_READ && packetfilter (ctx, pdev->packetfilter, request, data2) == 0) - return 0; - if (!copytobuff (ctx, data2, data, len, pdev->copytobuff)) { - put_long (request + 32, S2WERR_BUFF_ERROR); - put_byte (request + 31, S2ERR_NO_RESOURCES); - } - return 1; + uae_u8 flags = get_byte (request + 30); + uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); + uaecptr srcaddr = request + 32 + 4 + 4; + uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; + uae_u16 type = (d[2 * ADDR_SIZE] << 8) | d[2 * ADDR_SIZE + 1]; + uae_u32 v = 0; + uaecptr data2; + + memcpyha_safe (pdev->tempbuf, d, len); + memcpyha_safe (dstaddr, d, ADDR_SIZE); + memcpyha_safe (srcaddr, d + ADDR_SIZE, ADDR_SIZE); + put_long (request + 32 + 4, type); + if (pdev->tracks[type]) { + pdev->bytesreceived += len; + pdev->packetsreceived++; + } + flags &= ~(SANA2IOF_BCAST | SANA2IOF_MCAST); + if (isbroadcast (d)) + flags |= SANA2IOF_BCAST; + else if (ismulticast (d)) + flags |= SANA2IOF_MCAST; + put_byte (request + 30, flags); + + data2 = pdev->tempbuf; + if (!(flags & SANA2IOF_RAW)) { + len -= ETH_HEADER_SIZE; + data2 += ETH_HEADER_SIZE; + } + put_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2, len); + + if (pdev->packetfilter && cmd == CMD_READ && packetfilter (ctx, pdev->packetfilter, request, data2) == 0) + return 0; + if (!copytobuff (ctx, data2, data, len, pdev->copytobuff)) { + put_long (request + 32, S2WERR_BUFF_ERROR); + put_byte (request + 31, S2ERR_NO_RESOURCES); + } + return 1; } void uaenet_gotdata (struct devstruct *dev, const uae_u8 *d, int len) { - uae_u16 type; - struct mcast *mc; - struct s2packet *s2p; - - if (!dev->online) - return; - /* drop if bogus size */ - if (len < ETH_HEADER_SIZE || len >= dev->td->mtu + ETH_HEADER_SIZE + 2) - return; - /* drop if dst == broadcast and src == me */ - if (isbroadcast (d) && !memcmp (d + 6, dev->td->mac, ADDR_SIZE)) - return; - /* drop if not promiscuous and dst != broadcast and dst != me */ - if (!dev->promiscuous && !isbroadcast (d) && memcmp (d, dev->td->mac, ADDR_SIZE)) - return; - /* drop if multicast with unknown address */ - if (ismulticast (d)) { - uae_u64 mac64 = addrto64 (d); - /* multicast */ - mc = dev->mc; - while (mc) { - if (mac64 >= mc->start && mac64 <= mc->end) - break; - mc = mc->next; + uae_u16 type; + struct mcast *mc; + struct s2packet *s2p; + + if (!dev->online) + return; + /* drop if bogus size */ + if (len < ETH_HEADER_SIZE || len >= dev->td->mtu + ETH_HEADER_SIZE + 2) + return; + /* drop if dst == broadcast and src == me */ + if (isbroadcast (d) && !memcmp (d + 6, dev->td->mac, ADDR_SIZE)) + return; + /* drop if not promiscuous and dst != broadcast and dst != me */ + if (!dev->promiscuous && !isbroadcast (d) && memcmp (d, dev->td->mac, ADDR_SIZE)) + return; + /* drop if multicast with unknown address */ + if (ismulticast (d)) { + uae_u64 mac64 = addrto64 (d); + /* multicast */ + mc = dev->mc; + while (mc) { + if (mac64 >= mc->start && mac64 <= mc->end) + break; + mc = mc->next; + } + if (!mc) + return; } - if (!mc) - return; - } - - type = (d[12] << 8) | d[13]; - s2p = createreadpacket (dev, d, len); - if (log_net) - write_log (L"<-DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X L=%d P=%p\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - type, len, s2p); - uae_sem_wait (&async_sem); - if (!dev->readqueue) { - dev->readqueue = s2p; - } else { - struct s2packet *s2p2 = dev->readqueue; - while (s2p2->next) - s2p2 = s2p2->next; - s2p2->next = s2p; - } - uaenet_int_requested = 1; - uae_sem_post (&async_sem); + + type = (d[12] << 8) | d[13]; + s2p = createreadpacket (dev, d, len); + if (log_net) + write_log (L"<-DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X L=%d P=%p\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + type, len, s2p); + uae_sem_wait (&async_sem); + if (!dev->readqueue) { + dev->readqueue = s2p; + } else { + struct s2packet *s2p2 = dev->readqueue; + while (s2p2->next) + s2p2 = s2p2->next; + s2p2->next = s2p; + } + uaenet_int_requested = 1; + uae_sem_post (&async_sem); } static struct s2packet *createwritepacket (TrapContext *ctx, uaecptr request) { - uae_u8 flags = get_byte (request + 30); - uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); - uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); - uaecptr srcaddr = request + 32 + 4 + 4; - uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; - uae_u16 packettype = get_long (request + 32 + 4); - struct priv_devstruct *pdev = getpdevstruct (request); - struct s2packet *s2p; - - if (!pdev) - return NULL; - if (!copyfrombuff (ctx, data, pdev->tempbuf, datalength, pdev->copyfrombuff)) - return NULL; - s2p = xcalloc (sizeof (struct s2packet), 1); - s2p->data = xmalloc (pdev->td->mtu + ETH_HEADER_SIZE + 2); - if (flags & SANA2IOF_RAW) { - memcpyah_safe (s2p->data, pdev->tempbuf, datalength); - packettype = (s2p->data[2 * ADDR_SIZE + 0] << 8) | (s2p->data[2 * ADDR_SIZE + 1]); - s2p->len = datalength; - } else { - memcpyah_safe (s2p->data + ETH_HEADER_SIZE, pdev->tempbuf, datalength); - memcpy (s2p->data + ADDR_SIZE, pdev->td->mac, ADDR_SIZE); - memcpyah_safe (s2p->data, dstaddr, ADDR_SIZE); - s2p->data[2 * ADDR_SIZE + 0] = packettype >> 8; - s2p->data[2 * ADDR_SIZE + 1] = packettype; - s2p->len = datalength + ETH_HEADER_SIZE; - } - if (pdev->tracks[packettype]) { - pdev->packetssent++; - pdev->bytessent += datalength; - } - return s2p; + uae_u8 flags = get_byte (request + 30); + uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); + uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); + uaecptr srcaddr = request + 32 + 4 + 4; + uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; + uae_u16 packettype = get_long (request + 32 + 4); + struct priv_devstruct *pdev = getpdevstruct (request); + struct s2packet *s2p; + + if (!pdev) + return NULL; + if (!copyfrombuff (ctx, data, pdev->tempbuf, datalength, pdev->copyfrombuff)) + return NULL; + s2p = xcalloc (sizeof (struct s2packet), 1); + s2p->data = xmalloc (pdev->td->mtu + ETH_HEADER_SIZE + 2); + if (flags & SANA2IOF_RAW) { + memcpyah_safe (s2p->data, pdev->tempbuf, datalength); + packettype = (s2p->data[2 * ADDR_SIZE + 0] << 8) | (s2p->data[2 * ADDR_SIZE + 1]); + s2p->len = datalength; + } else { + memcpyah_safe (s2p->data + ETH_HEADER_SIZE, pdev->tempbuf, datalength); + memcpy (s2p->data + ADDR_SIZE, pdev->td->mac, ADDR_SIZE); + memcpyah_safe (s2p->data, dstaddr, ADDR_SIZE); + s2p->data[2 * ADDR_SIZE + 0] = packettype >> 8; + s2p->data[2 * ADDR_SIZE + 1] = packettype; + s2p->len = datalength + ETH_HEADER_SIZE; + } + if (pdev->tracks[packettype]) { + pdev->packetssent++; + pdev->bytessent += datalength; + } + return s2p; } static int uaenet_getdata (struct devstruct *dev, uae_u8 *d, int *len) { - int gotit; - struct asyncreq *ar; - - uae_sem_wait (&async_sem); - ar = dev->ar; - gotit = 0; - while (ar && !gotit) { - if (!ar->ready) { - uaecptr request = ar->request; - int command = get_word (request + 28); - uae_u32 packettype = get_long (request + 32 + 4); - if (command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { - struct priv_devstruct *pdev = getpdevstruct (request); - struct asyncreq *ars2p = dev->s2p; - while (ars2p) { - if (ars2p->request == request) { - *len = ars2p->s2p->len; - memcpy (d, ars2p->s2p->data, *len); - if (log_net) - write_log (L"->DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", - d[0], d[1], d[2], d[3], d[4], d[5], - d[6], d[7], d[8], d[9], d[10], d[11], - packettype, *len); - gotit = 1; - dev->packetssent++; - signalasync (dev, ar, *len, 0); - break; - } - ars2p = ars2p->next; + int gotit; + struct asyncreq *ar; + + uae_sem_wait (&async_sem); + ar = dev->ar; + gotit = 0; + while (ar && !gotit) { + if (!ar->ready) { + uaecptr request = ar->request; + int command = get_word (request + 28); + uae_u32 packettype = get_long (request + 32 + 4); + if (command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { + struct priv_devstruct *pdev = getpdevstruct (request); + struct asyncreq *ars2p = dev->s2p; + while (ars2p) { + if (ars2p->request == request) { + *len = ars2p->s2p->len; + memcpy (d, ars2p->s2p->data, *len); + if (log_net) + write_log (L"->DST:%02X.%02X.%02X.%02X.%02X.%02X SRC:%02X.%02X.%02X.%02X.%02X.%02X E=%04X S=%d\n", + d[0], d[1], d[2], d[3], d[4], d[5], + d[6], d[7], d[8], d[9], d[10], d[11], + packettype, *len); + gotit = 1; + dev->packetssent++; + signalasync (dev, ar, *len, 0); + break; + } + ars2p = ars2p->next; + } + } } - } + ar = ar->next; } - ar = ar->next; - } - uae_sem_post (&async_sem); - return gotit; + uae_sem_post (&async_sem); + return gotit; } void checkevents (struct devstruct *dev, int mask, int sem) { - struct asyncreq *ar; + struct asyncreq *ar; - if (sem) - uae_sem_wait (&async_sem); - ar = dev->ar; - while (ar) { - if (!ar->ready) { - uaecptr request = ar->request; - int command = get_word (request + 28); - uae_u32 cmask = get_long (request + 32); - if (command == S2_ONEVENT && (mask & cmask)) - signalasync (dev, ar, 0, 0); + if (sem) + uae_sem_wait (&async_sem); + ar = dev->ar; + while (ar) { + if (!ar->ready) { + uaecptr request = ar->request; + int command = get_word (request + 28); + uae_u32 cmask = get_long (request + 32); + if (command == S2_ONEVENT && (mask & cmask)) + signalasync (dev, ar, 0, 0); + } + ar = ar->next; } - ar = ar->next; - } - if (sem) - uae_sem_post (&async_sem); + if (sem) + uae_sem_post (&async_sem); } static int checksize (uaecptr request, struct devstruct *dev) { - uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); + uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); - if (datalength > dev->td->mtu) - return 0; - return 1; + if (datalength > dev->td->mtu) + return 0; + return 1; } static void flush (struct priv_devstruct *pdev) { - struct asyncreq *ar; - struct devstruct *dev; - - dev = getdevstruct (pdev->unit); - ar = dev->ar; - while (ar) { - if (!ar->ready && getpdevstruct (ar->request) == pdev) { - ar->ready = 1; - do_abort_async (dev, ar->request); + struct asyncreq *ar; + struct devstruct *dev; + + dev = getdevstruct (pdev->unit); + ar = dev->ar; + while (ar) { + if (!ar->ready && getpdevstruct (ar->request) == pdev) { + ar->ready = 1; + do_abort_async (dev, ar->request); + } + ar = ar->next; } - ar = ar->next; - } } static int dev_do_io_2 (struct devstruct *dev, uaecptr request, int quick) { - uae_u8 flags = get_byte (request + 30); - uae_u32 command = get_word (request + 28); - uae_u32 packettype = get_long (request + 32 + 4); - uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); - uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); - uaecptr srcaddr = request + 32 + 4 + 4; - uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; - uaecptr statdata = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4); - uaecptr buffermgmt = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4); - uae_u32 io_error = 0; - uae_u32 wire_error = 0; - int i; - int async = 0; - struct priv_devstruct *pdev = getpdevstruct (request); - - if (log_net) - write_log (L"S2: C=%02d T=%04X S=%02X%02X%02X%02X%02X%02X D=%02X%02X%02X%02X%02X%02X L=%d D=%08X SD=%08X BM=%08X\n", - command, packettype, - get_byte (srcaddr + 0), get_byte (srcaddr + 1), get_byte (srcaddr + 2), get_byte (srcaddr + 3), get_byte (srcaddr + 4), get_byte (srcaddr + 5), - get_byte (dstaddr + 0), get_byte (dstaddr + 1), get_byte (dstaddr + 2), get_byte (dstaddr + 3), get_byte (dstaddr + 4), get_byte (dstaddr + 5), - datalength, data, statdata, buffermgmt); - - if (command == CMD_READ || command == S2_READORPHAN || command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { - if (!pdev->copyfrombuff || !pdev->copytobuff) { - io_error = S2ERR_BAD_ARGUMENT; - wire_error = S2WERR_BUFF_ERROR; - goto end; + uae_u8 flags = get_byte (request + 30); + uae_u32 command = get_word (request + 28); + uae_u32 packettype = get_long (request + 32 + 4); + uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); + uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2); + uaecptr srcaddr = request + 32 + 4 + 4; + uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; + uaecptr statdata = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4); + uaecptr buffermgmt = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4); + uae_u32 io_error = 0; + uae_u32 wire_error = 0; + int i; + int async = 0; + struct priv_devstruct *pdev = getpdevstruct (request); + + if (log_net) + write_log (L"S2: C=%02d T=%04X S=%02X%02X%02X%02X%02X%02X D=%02X%02X%02X%02X%02X%02X L=%d D=%08X SD=%08X BM=%08X\n", + command, packettype, + get_byte (srcaddr + 0), get_byte (srcaddr + 1), get_byte (srcaddr + 2), get_byte (srcaddr + 3), get_byte (srcaddr + 4), get_byte (srcaddr + 5), + get_byte (dstaddr + 0), get_byte (dstaddr + 1), get_byte (dstaddr + 2), get_byte (dstaddr + 3), get_byte (dstaddr + 4), get_byte (dstaddr + 5), + datalength, data, statdata, buffermgmt); + + if (command == CMD_READ || command == S2_READORPHAN || command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { + if (!pdev->copyfrombuff || !pdev->copytobuff) { + io_error = S2ERR_BAD_ARGUMENT; + wire_error = S2WERR_BUFF_ERROR; + goto end; + } } - } - switch (command) - { + switch (command) + { case CMD_READ: - if (!dev->online) - goto offline; - async = 1; - break; + if (!dev->online) + goto offline; + async = 1; + break; case S2_READORPHAN: - if (!dev->online) - goto offline; - async = 1; - break; + if (!dev->online) + goto offline; + async = 1; + break; case S2_BROADCAST: case CMD_WRITE: - if (!dev->online) - goto offline; - if (!checksize (request, dev)) - goto toobig; - async = 1; - break; + if (!dev->online) + goto offline; + if (!checksize (request, dev)) + goto toobig; + async = 1; + break; case S2_MULTICAST: - if (!dev->online) - goto offline; - if ((get_byte (dstaddr + 0) & 1) == 0) { - io_error = S2ERR_BAD_ADDRESS; - wire_error = S2WERR_BAD_MULTICAST; - goto end; - } - if (!checksize (request, dev)) - goto toobig; - async = 1; - break; + if (!dev->online) + goto offline; + if ((get_byte (dstaddr + 0) & 1) == 0) { + io_error = S2ERR_BAD_ADDRESS; + wire_error = S2WERR_BAD_MULTICAST; + goto end; + } + if (!checksize (request, dev)) + goto toobig; + async = 1; + break; case CMD_FLUSH: - dev->flush_timeout_cnt = 0; - dev->flush_timeout = FLUSH_TIMEOUT; - if (log_net) - write_log (L"CMD_FLUSH started %08x\n", request); - uae_sem_wait (&async_sem); - flush (pdev); - uae_sem_post (&async_sem); - async = 1; - uaenet_vsync_requested++; - break; + dev->flush_timeout_cnt = 0; + dev->flush_timeout = FLUSH_TIMEOUT; + if (log_net) + write_log (L"CMD_FLUSH started %08x\n", request); + uae_sem_wait (&async_sem); + flush (pdev); + uae_sem_post (&async_sem); + async = 1; + uaenet_vsync_requested++; + break; case S2_ADDMULTICASTADDRESS: - addmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0); - break; + addmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0); + break; case S2_DELMULTICASTADDRESS: - if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0)) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_BAD_MULTICAST; - } - break; + if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0)) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_BAD_MULTICAST; + } + break; case S2_ADDMULTICASTADDRESSES: - addmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr)); - break; + addmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr)); + break; case S2_DELMULTICASTADDRESSES: - if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr))) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_BAD_MULTICAST; - } - break; + if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr))) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_BAD_MULTICAST; + } + break; case S2_DEVICEQUERY: - { - int size = get_long (statdata); - if (size > 30) - size = 30; - put_long (statdata + 4, size); - if (size >= 12) - put_long (statdata + 8, 0); - if (size >= 16) - put_long (statdata + 12, 0); - if (size >= 18) - put_word (statdata + 16, ADDR_SIZE * 8); - if (size >= 22) - put_long (statdata + 18, dev->td->mtu); - if (size >= 26) - put_long (statdata + 22, 10000000); - if (size >= 30) - put_long (statdata + 26, S2WireType_Ethernet); - } - break; + { + int size = get_long (statdata); + if (size > 30) + size = 30; + put_long (statdata + 4, size); + if (size >= 12) + put_long (statdata + 8, 0); + if (size >= 16) + put_long (statdata + 12, 0); + if (size >= 18) + put_word (statdata + 16, ADDR_SIZE * 8); + if (size >= 22) + put_long (statdata + 18, dev->td->mtu); + if (size >= 26) + put_long (statdata + 22, 10000000); + if (size >= 30) + put_long (statdata + 26, S2WireType_Ethernet); + } + break; case S2_GETTYPESTATS: - if (pdev->trackcnt) { - put_long (statdata + 0, pdev->packetssent); - put_long (statdata + 4, pdev->packetsreceived); - put_long (statdata + 8, pdev->bytessent); - put_long (statdata + 12, pdev->bytesreceived); - put_long (statdata + 16, pdev->packetsdropped); - } else { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_NOT_TRACKED; - } - break; + if (pdev->trackcnt) { + put_long (statdata + 0, pdev->packetssent); + put_long (statdata + 4, pdev->packetsreceived); + put_long (statdata + 8, pdev->bytessent); + put_long (statdata + 12, pdev->bytesreceived); + put_long (statdata + 16, pdev->packetsdropped); + } else { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_NOT_TRACKED; + } + break; case S2_GETGLOBALSTATS: - put_long (statdata + 0, dev->packetsreceived); - put_long (statdata + 4, dev->packetssent); - put_long (statdata + 8, dev->baddata); - put_long (statdata + 12, dev->overruns); - put_long (statdata + 16, 0); - put_long (statdata + 20, dev->unknowntypesreceived); - put_long (statdata + 24, dev->reconfigurations); - put_long (statdata + 28, dev->online_secs); - put_long (statdata + 32, dev->online_micro); - break; + put_long (statdata + 0, dev->packetsreceived); + put_long (statdata + 4, dev->packetssent); + put_long (statdata + 8, dev->baddata); + put_long (statdata + 12, dev->overruns); + put_long (statdata + 16, 0); + put_long (statdata + 20, dev->unknowntypesreceived); + put_long (statdata + 24, dev->reconfigurations); + put_long (statdata + 28, dev->online_secs); + put_long (statdata + 32, dev->online_micro); + break; case S2_GETSPECIALSTATS: - put_long (statdata + 1, 0); - break; + put_long (statdata + 1, 0); + break; case S2_GETSTATIONADDRESS: - for (i = 0; i < ADDR_SIZE; i++) { - put_byte (srcaddr + i, dev->td->mac[i]); - put_byte (dstaddr + i, dev->td->mac[i]); - } - break; + for (i = 0; i < ADDR_SIZE; i++) { + put_byte (srcaddr + i, dev->td->mac[i]); + put_byte (dstaddr + i, dev->td->mac[i]); + } + break; case S2_CONFIGINTERFACE: - if (dev->configured) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_IS_CONFIGURED; - } else { - dev->configured = TRUE; - } - break; + if (dev->configured) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_IS_CONFIGURED; + } else { + dev->configured = TRUE; + } + break; case S2_ONLINE: - if (!dev->configured) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_NOT_CONFIGURED; - } - if (!dev->adapter) { - io_error = S2ERR_OUTOFSERVICE; - wire_error = S2WERR_RCVREL_HDW_ERR; - } - if (!io_error) { - uaenet_vsync_requested++; - async = 1; - } - break; + if (!dev->configured) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_NOT_CONFIGURED; + } + if (!dev->adapter) { + io_error = S2ERR_OUTOFSERVICE; + wire_error = S2WERR_RCVREL_HDW_ERR; + } + if (!io_error) { + uaenet_vsync_requested++; + async = 1; + } + break; case S2_TRACKTYPE: - if (packettype <= 65535) { - if (pdev->tracks[packettype]) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_ALREADY_TRACKED; + if (packettype <= 65535) { + if (pdev->tracks[packettype]) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_ALREADY_TRACKED; + } else { + pdev->tracks[packettype] = 1; + pdev->trackcnt++; + } } else { - pdev->tracks[packettype] = 1; - pdev->trackcnt++; + io_error = S2ERR_BAD_ARGUMENT; } - } else { - io_error = S2ERR_BAD_ARGUMENT; - } - break; + break; case S2_UNTRACKTYPE: - if (packettype <= 65535) { - if (!pdev->tracks[packettype]) { - io_error = S2ERR_BAD_STATE; - wire_error = S2WERR_NOT_TRACKED; + if (packettype <= 65535) { + if (!pdev->tracks[packettype]) { + io_error = S2ERR_BAD_STATE; + wire_error = S2WERR_NOT_TRACKED; + } else { + pdev->tracks[packettype] = 0; + pdev->trackcnt--; + } } else { - pdev->tracks[packettype] = 0; - pdev->trackcnt--; + io_error = S2ERR_BAD_ARGUMENT; } - } else { - io_error = S2ERR_BAD_ARGUMENT; - } - break; + break; case S2_OFFLINE: - if (dev->online) { - dev->online = 0; - checkevents (dev, S2EVENT_OFFLINE, 1); - } - break; + if (dev->online) { + dev->online = 0; + checkevents (dev, S2EVENT_OFFLINE, 1); + } + break; case S2_ONEVENT: - { - uae_u32 events; - uae_u32 wanted_events = get_long (request + 32); - if (wanted_events & ~KNOWN_EVENTS) { - io_error = S2ERR_NOT_SUPPORTED; - events = S2WERR_BAD_EVENT; - } else { - if (dev->online) - events = S2EVENT_ONLINE; - else - events = S2EVENT_OFFLINE; - events &= wanted_events; - if (events) { - wire_error = events; - } else { - async = 1; + { + uae_u32 events; + uae_u32 wanted_events = get_long (request + 32); + if (wanted_events & ~KNOWN_EVENTS) { + io_error = S2ERR_NOT_SUPPORTED; + events = S2WERR_BAD_EVENT; + } else { + if (dev->online) + events = S2EVENT_ONLINE; + else + events = S2EVENT_OFFLINE; + events &= wanted_events; + if (events) { + wire_error = events; + } else { + async = 1; + } + } } - } - } - break; + break; default: - io_error = IOERR_NOCMD; - break; - - offline: - io_error = S2ERR_OUTOFSERVICE; - wire_error = S2WERR_UNIT_OFFLINE; - break; - toobig: - io_error = S2ERR_MTU_EXCEEDED; - wire_error = S2WERR_GENERIC_ERROR; - break; - - } + io_error = IOERR_NOCMD; + break; + +offline: + io_error = S2ERR_OUTOFSERVICE; + wire_error = S2WERR_UNIT_OFFLINE; + break; +toobig: + io_error = S2ERR_MTU_EXCEEDED; + wire_error = S2WERR_GENERIC_ERROR; + break; + + } end: - if (log_net && (io_error || wire_error)) - write_log (L"-> %d (%d)\n", io_error, wire_error); - put_long (request + 32, wire_error); - put_byte (request + 31, io_error); - return async; + if (log_net && (io_error || wire_error)) + write_log (L"-> %d (%d)\n", io_error, wire_error); + put_long (request + 32, wire_error); + put_byte (request + 31, io_error); + return async; } static int dev_do_io (struct devstruct *dev, uaecptr request, int quick) { - uae_u32 command = get_word (request + 28); - struct priv_devstruct *pdev = getpdevstruct (request); - uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); - - put_byte (request + 31, 0); - if (!pdev) { - write_log (L"%s unknown iorequest %08x\n", getdevname (), request); - return 0; - } - if (command == NSCMD_DEVICEQUERY) { - uae_u32 data = get_long (request + 40); /* io_data */ - put_long (data + 0, 0); - put_long (data + 4, 16); /* size */ - put_word (data + 8, 7); /* NSDEVTYPE_SANA2 */ - put_word (data + 10, 0); - put_long (data + 12, nscmd_cmd); - put_long (request + 32, 16); /* io_actual */ - return 0; - } else if (get_word (request + 0x12) < SANA2_IOREQSIZE) { - put_byte (request + 31, IOERR_BADLENGTH); - return 0; - } - return dev_do_io_2 (dev, request, quick); + uae_u32 command = get_word (request + 28); + struct priv_devstruct *pdev = getpdevstruct (request); + uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4); + + put_byte (request + 31, 0); + if (!pdev) { + write_log (L"%s unknown iorequest %08x\n", getdevname (), request); + return 0; + } + if (command == NSCMD_DEVICEQUERY) { + uae_u32 data = get_long (request + 40); /* io_data */ + put_long (data + 0, 0); + put_long (data + 4, 16); /* size */ + put_word (data + 8, 7); /* NSDEVTYPE_SANA2 */ + put_word (data + 10, 0); + put_long (data + 12, nscmd_cmd); + put_long (request + 32, 16); /* io_actual */ + return 0; + } else if (get_word (request + 0x12) < SANA2_IOREQSIZE) { + put_byte (request + 31, IOERR_BADLENGTH); + return 0; + } + return dev_do_io_2 (dev, request, quick); } static int dev_can_quick (uae_u32 command) { - switch (command) - { + switch (command) + { case NSCMD_DEVICEQUERY: case S2_DEVICEQUERY: case S2_CONFIGINTERFACE: case S2_GETSTATIONADDRESS: case S2_TRACKTYPE: case S2_UNTRACKTYPE: - return 1; - } - return 0; + return 1; + } + return 0; } static int dev_canquick (struct devstruct *dev, uaecptr request) { - uae_u32 command = get_word (request + 28); - return dev_can_quick (command); + uae_u32 command = get_word (request + 28); + return dev_can_quick (command); } static uae_u32 REGPARAM2 dev_beginio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - uae_u8 flags = get_byte (request + 30); - int command = get_word (request + 28); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; - - put_byte (request + 8, NT_MESSAGE); - if (!pdev) { - write_log (L"%s unknown iorequest (1) %08x\n", getdevname (), request); - put_byte (request + 31, 32); - return get_byte (request + 31); - } - dev = getdevstruct (pdev->unit); - if (!dev) { - write_log (L"%s unknown iorequest (2) %08x\n", getdevname (), request); - put_byte (request + 31, 32); - return get_byte (request + 31); - } - put_byte (request + 31, 0); - if ((flags & 1) && dev_canquick (dev, request)) { - if (dev_do_io (dev, request, 1)) - write_log (L"%s: command %d bug with IO_QUICK\n", SANA2NAME, command); - return get_byte (request + 31); - } else { - if (command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { - struct s2packet *s2p; - if (!pdev->copyfrombuff || !pdev->copytobuff) { - put_long (request + 32, S2ERR_BAD_ARGUMENT); - put_byte (request + 31, S2WERR_BUFF_ERROR); - } else { - if (command == S2_BROADCAST) { - uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; - put_byte (dstaddr + 0, 0xff); - put_byte (dstaddr + 1, 0xff); - put_byte (dstaddr + 2, 0xff); - put_byte (dstaddr + 3, 0xff); - put_byte (dstaddr + 4, 0xff); - put_byte (dstaddr + 5, 0xff); - } - s2p = createwritepacket (context, request); - if (s2p) { - uae_sem_wait (&async_sem); - add_async_packet (dev, s2p, request); - uae_sem_post (&async_sem); - } - if (!s2p) { - put_long (request + 32, S2WERR_BUFF_ERROR); - put_byte (request + 31, S2ERR_NO_RESOURCES); + uae_u32 request = m68k_areg (regs, 1); + uae_u8 flags = get_byte (request + 30); + int command = get_word (request + 28); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; + + put_byte (request + 8, NT_MESSAGE); + if (!pdev) { + write_log (L"%s unknown iorequest (1) %08x\n", getdevname (), request); + put_byte (request + 31, 32); + return get_byte (request + 31); + } + dev = getdevstruct (pdev->unit); + if (!dev) { + write_log (L"%s unknown iorequest (2) %08x\n", getdevname (), request); + put_byte (request + 31, 32); + return get_byte (request + 31); + } + put_byte (request + 31, 0); + if ((flags & 1) && dev_canquick (dev, request)) { + if (dev_do_io (dev, request, 1)) + write_log (L"%s: command %d bug with IO_QUICK\n", SANA2NAME, command); + return get_byte (request + 31); + } else { + if (command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) { + struct s2packet *s2p; + if (!pdev->copyfrombuff || !pdev->copytobuff) { + put_long (request + 32, S2ERR_BAD_ARGUMENT); + put_byte (request + 31, S2WERR_BUFF_ERROR); + } else { + if (command == S2_BROADCAST) { + uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES; + put_byte (dstaddr + 0, 0xff); + put_byte (dstaddr + 1, 0xff); + put_byte (dstaddr + 2, 0xff); + put_byte (dstaddr + 3, 0xff); + put_byte (dstaddr + 4, 0xff); + put_byte (dstaddr + 5, 0xff); + } + s2p = createwritepacket (context, request); + if (s2p) { + uae_sem_wait (&async_sem); + add_async_packet (dev, s2p, request); + uae_sem_post (&async_sem); + } + if (!s2p) { + put_long (request + 32, S2WERR_BUFF_ERROR); + put_byte (request + 31, S2ERR_NO_RESOURCES); + } + } } - } + put_byte (request + 30, get_byte (request + 30) & ~1); + write_comm_pipe_u32 (&dev->requests, request, 1); + return 0; } - put_byte (request + 30, get_byte (request + 30) & ~1); - write_comm_pipe_u32 (&dev->requests, request, 1); - return 0; - } } static void *dev_thread (void *devs) { - struct devstruct *dev = (struct devstruct*)devs; - - uae_set_thread_priority (NULL, 1); - dev->thread_running = 1; - uae_sem_post (&dev->sync_sem); - for (;;) { - uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); - uae_sem_wait (&change_sem); - if (!request) { - dev->thread_running = 0; - uae_sem_post (&dev->sync_sem); - uae_sem_post (&change_sem); - write_log (L"%s: dev_thread killed\n", getdevname ()); - return 0; - } else if (get_async_request (dev, request, 1)) { - uae_ReplyMsg (request); - release_async_request (dev, request); - rem_async_packet (dev, request); - } else if (dev_do_io (dev, request, 0) == 0) { - uae_ReplyMsg (request); - rem_async_packet (dev, request); - } else { - add_async_request (dev, request); - uaenet_trigger (dev->sysdata); + struct devstruct *dev = (struct devstruct*)devs; + + uae_set_thread_priority (NULL, 1); + dev->thread_running = 1; + uae_sem_post (&dev->sync_sem); + for (;;) { + uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); + uae_sem_wait (&change_sem); + if (!request) { + dev->thread_running = 0; + uae_sem_post (&dev->sync_sem); + uae_sem_post (&change_sem); + write_log (L"%s: dev_thread killed\n", getdevname ()); + return 0; + } else if (get_async_request (dev, request, 1)) { + uae_ReplyMsg (request); + release_async_request (dev, request); + rem_async_packet (dev, request); + } else if (dev_do_io (dev, request, 0) == 0) { + uae_ReplyMsg (request); + rem_async_packet (dev, request); + } else { + add_async_request (dev, request); + uaenet_trigger (dev->sysdata); + } + uae_sem_post (&change_sem); } - uae_sem_post (&change_sem); - } - return 0; + return 0; } static uae_u32 REGPARAM2 dev_init_2 (TrapContext *context) { - uae_u32 base = m68k_dreg (regs,0); - if (log_net) - write_log (L"%s init\n", SANA2NAME); - return base; + uae_u32 base = m68k_dreg (regs,0); + if (log_net) + write_log (L"%s init\n", SANA2NAME); + return base; } static uae_u32 REGPARAM2 dev_init (TrapContext *context) { - return dev_init_2 (context); + return dev_init_2 (context); } static uae_u32 REGPARAM2 dev_abortio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; - - if (!pdev) { - write_log (L"%s abortio but no request %08x found!\n", getdevname(), request); - put_byte (request + 31, 32); - return get_byte (request + 31); - } - dev = getdevstruct (pdev->unit); - if (!dev) { - write_log (L"%s (%d) abortio but no request %08x found!\n", getdevname(), pdev->unit, request); - put_byte (request + 31, 32); - return get_byte (request + 31); - } - if (log_net) - write_log (L"%s:%d abortio %08x\n", getdevname(), dev->unit, request); - abort_async (dev, request); - return 0; + uae_u32 request = m68k_areg (regs, 1); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; + + if (!pdev) { + write_log (L"%s abortio but no request %08x found!\n", getdevname(), request); + put_byte (request + 31, 32); + return get_byte (request + 31); + } + dev = getdevstruct (pdev->unit); + if (!dev) { + write_log (L"%s (%d) abortio but no request %08x found!\n", getdevname(), pdev->unit, request); + put_byte (request + 31, 32); + return get_byte (request + 31); + } + if (log_net) + write_log (L"%s:%d abortio %08x\n", getdevname(), dev->unit, request); + abort_async (dev, request); + return 0; } static uae_u32 REGPARAM2 uaenet_int_handler (TrapContext *ctx) { - int i, j; - int gotit; - struct asyncreq *ar; - - if (uae_sem_trywait (&async_sem)) { - uaenet_int_requested = 0; - uaenet_int_late = 1; - return 0; - } - for (i = 0; i < MAX_OPEN_DEVICES; i++) - pdevst[i].tmp = 0; - - for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { - struct devstruct *dev = &devst[i]; - struct s2packet *p; - if (dev->online) { - while (dev->readqueue) { - uae_u16 type; - p = dev->readqueue; - type = (p->data[2 * ADDR_SIZE] << 8) | p->data[2 * ADDR_SIZE + 1]; - ar = dev->ar; - gotit = 0; - while (ar) { - if (!ar->ready) { - uaecptr request = ar->request; - int command = get_word (request + 28); - uae_u32 packettype = get_long (request + 32 + 4); - if (command == CMD_READ && (packettype == type || (packettype <= 1500 && type <= 1500))) { - struct priv_devstruct *pdev = getpdevstruct (request); - if (pdev && pdev->tmp == 0) { - if (handleread (ctx, pdev, request, p->data, p->len, command)) { - if (log_net) - write_log (L"-> %p Accepted, CMD_READ, REQ=%08X LEN=%d\n", p, request, p->len); - write_comm_pipe_u32 (&dev->requests, request, 1); - dev->packetsreceived++; - gotit = 1; - pdev->tmp = 1; - } else { - if (log_net) - write_log (L"-> %p PacketFilter() rejected, CMD_READ, REQ=%08X LEN=%d\n", p, request, p->len); - pdev->tmp = -1; + int i, j; + int gotit; + struct asyncreq *ar; + + if (uae_sem_trywait (&async_sem)) { + uaenet_int_requested = 0; + uaenet_int_late = 1; + return 0; + } + for (i = 0; i < MAX_OPEN_DEVICES; i++) + pdevst[i].tmp = 0; + + for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { + struct devstruct *dev = &devst[i]; + struct s2packet *p; + if (dev->online) { + while (dev->readqueue) { + uae_u16 type; + p = dev->readqueue; + type = (p->data[2 * ADDR_SIZE] << 8) | p->data[2 * ADDR_SIZE + 1]; + ar = dev->ar; + gotit = 0; + while (ar) { + if (!ar->ready) { + uaecptr request = ar->request; + int command = get_word (request + 28); + uae_u32 packettype = get_long (request + 32 + 4); + if (command == CMD_READ && (packettype == type || (packettype <= 1500 && type <= 1500))) { + struct priv_devstruct *pdev = getpdevstruct (request); + if (pdev && pdev->tmp == 0) { + if (handleread (ctx, pdev, request, p->data, p->len, command)) { + if (log_net) + write_log (L"-> %p Accepted, CMD_READ, REQ=%08X LEN=%d\n", p, request, p->len); + write_comm_pipe_u32 (&dev->requests, request, 1); + dev->packetsreceived++; + gotit = 1; + pdev->tmp = 1; + } else { + if (log_net) + write_log (L"-> %p PacketFilter() rejected, CMD_READ, REQ=%08X LEN=%d\n", p, request, p->len); + pdev->tmp = -1; + } + } + } + } + ar = ar->next; } - } - } - } - ar = ar->next; - } - ar = dev->ar; - while (ar) { - if (!ar->ready) { - uaecptr request = ar->request; - int command = get_word (request + 28); - if (command == S2_READORPHAN) { - struct priv_devstruct *pdev = getpdevstruct (request); - if (pdev && pdev->tmp <= 0) { - if (log_net) - write_log (L"-> %p Accepted, S2_READORPHAN, REQ=%08X LEN=%d\n", p, request, p->len); - handleread (ctx, pdev, request, p->data, p->len, command); - write_comm_pipe_u32 (&dev->requests, request, 1); - dev->packetsreceived++; - dev->unknowntypesreceived++; - gotit = 1; - pdev->tmp = 1; - } + ar = dev->ar; + while (ar) { + if (!ar->ready) { + uaecptr request = ar->request; + int command = get_word (request + 28); + if (command == S2_READORPHAN) { + struct priv_devstruct *pdev = getpdevstruct (request); + if (pdev && pdev->tmp <= 0) { + if (log_net) + write_log (L"-> %p Accepted, S2_READORPHAN, REQ=%08X LEN=%d\n", p, request, p->len); + handleread (ctx, pdev, request, p->data, p->len, command); + write_comm_pipe_u32 (&dev->requests, request, 1); + dev->packetsreceived++; + dev->unknowntypesreceived++; + gotit = 1; + pdev->tmp = 1; + } + } + } + ar = ar->next; + } + if (!gotit) { + if (log_net) + write_log (L"-> %p packet dropped, LEN=%d\n", p, p->len); + for (j = 0; j < MAX_OPEN_DEVICES; j++) { + if (pdevst[j].unit == dev->unit) { + if (pdevst[j].tracks[type]) + pdevst[j].packetsdropped++; + } + } + } + dev->readqueue = dev->readqueue->next; + freepacket (p); } - } - ar = ar->next; - } - if (!gotit) { - if (log_net) - write_log (L"-> %p packet dropped, LEN=%d\n", p, p->len); - for (j = 0; j < MAX_OPEN_DEVICES; j++) { - if (pdevst[j].unit == dev->unit) { - if (pdevst[j].tracks[type]) - pdevst[j].packetsdropped++; + } else { + while (dev->readqueue) { + p = dev->readqueue; + dev->readqueue = dev->readqueue->next; + freepacket (p); } - } } - dev->readqueue = dev->readqueue->next; - freepacket (p); - } - } else { - while (dev->readqueue) { - p = dev->readqueue; - dev->readqueue = dev->readqueue->next; - freepacket (p); - } - } - ar = dev->ar; - while (ar) { - if (!ar->ready) { - uaecptr request = ar->request; - int command = get_word (request + 28); - if (command == S2_ONLINE) { - struct priv_devstruct *pdev = getpdevstruct (request); - dev->packetsreceived = 0; - dev->packetssent = 0; - dev->baddata = 0; - dev->overruns = 0; - dev->unknowntypesreceived = 0; - dev->reconfigurations = 0; - if (pdev && pdev->timerbase) { - m68k_areg (regs, 0) = pdev->tempbuf; - CallLib (ctx, pdev->timerbase, -0x42); /* GetSysTime() */ - } else { - put_long (pdev->tempbuf + 0, 0); - put_long (pdev->tempbuf + 4, 0); - } - dev->online_secs = get_long (pdev->tempbuf + 0); - dev->online_micro = get_long (pdev->tempbuf + 4); - checkevents (dev, S2EVENT_ONLINE, 0); - dev->online = 1; - write_comm_pipe_u32 (&dev->requests, request, 1); - uaenet_vsync_requested--; - } else if (command == CMD_FLUSH) { - /* do not reply CMD_FLUSH until all other requests are gone */ - if (dev->ar->next == NULL) { - if (log_net) - write_log (L"CMD_FLUSH replied %08x\n", request); - write_comm_pipe_u32 (&dev->requests, request, 1); - uaenet_vsync_requested--; - } else { - struct priv_devstruct *pdev = getpdevstruct (request); - if (pdev) { - dev->flush_timeout--; - if (dev->flush_timeout <= 0) { - dev->flush_timeout = FLUSH_TIMEOUT; - if (dev->flush_timeout_cnt > 1) - write_log (L"WARNING: %s:%d CMD_FLUSH possibly frozen..\n", getdevname(), pdev->unit); - dev->flush_timeout_cnt++; - flush (pdev); - } + ar = dev->ar; + while (ar) { + if (!ar->ready) { + uaecptr request = ar->request; + int command = get_word (request + 28); + if (command == S2_ONLINE) { + struct priv_devstruct *pdev = getpdevstruct (request); + dev->packetsreceived = 0; + dev->packetssent = 0; + dev->baddata = 0; + dev->overruns = 0; + dev->unknowntypesreceived = 0; + dev->reconfigurations = 0; + if (pdev && pdev->timerbase) { + m68k_areg (regs, 0) = pdev->tempbuf; + CallLib (ctx, pdev->timerbase, -0x42); /* GetSysTime() */ + } else { + put_long (pdev->tempbuf + 0, 0); + put_long (pdev->tempbuf + 4, 0); + } + dev->online_secs = get_long (pdev->tempbuf + 0); + dev->online_micro = get_long (pdev->tempbuf + 4); + checkevents (dev, S2EVENT_ONLINE, 0); + dev->online = 1; + write_comm_pipe_u32 (&dev->requests, request, 1); + uaenet_vsync_requested--; + } else if (command == CMD_FLUSH) { + /* do not reply CMD_FLUSH until all other requests are gone */ + if (dev->ar->next == NULL) { + if (log_net) + write_log (L"CMD_FLUSH replied %08x\n", request); + write_comm_pipe_u32 (&dev->requests, request, 1); + uaenet_vsync_requested--; + } else { + struct priv_devstruct *pdev = getpdevstruct (request); + if (pdev) { + dev->flush_timeout--; + if (dev->flush_timeout <= 0) { + dev->flush_timeout = FLUSH_TIMEOUT; + if (dev->flush_timeout_cnt > 1) + write_log (L"WARNING: %s:%d CMD_FLUSH possibly frozen..\n", getdevname(), pdev->unit); + dev->flush_timeout_cnt++; + flush (pdev); + } + } + } + } } - } + ar = ar->next; } - } - ar = ar->next; } - } - if (uaenet_int_late) - uaenet_int_requested = 1; - else - uaenet_int_requested = 0; - uaenet_int_late = 0; - uae_sem_post (&async_sem); - return 0; + if (uaenet_int_late) + uaenet_int_requested = 1; + else + uaenet_int_requested = 0; + uaenet_int_late = 0; + uae_sem_post (&async_sem); + return 0; } static void dev_reset (void) { - int i; - struct devstruct *dev; - int unitnum = 0; - - write_log (L"%s reset\n", getdevname()); - for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { - dev = &devst[i]; - if (dev->opencnt) { - struct asyncreq *ar = dev->ar; - while (ar) { - if (!ar->ready) { - dev->ar->ready = 1; - do_abort_async (dev, ar->request); + int i; + struct devstruct *dev; + int unitnum = 0; + + write_log (L"%s reset\n", getdevname()); + for (i = 0; i < MAX_TOTAL_NET_DEVICES; i++) { + dev = &devst[i]; + if (dev->opencnt) { + struct asyncreq *ar = dev->ar; + while (ar) { + if (!ar->ready) { + dev->ar->ready = 1; + do_abort_async (dev, ar->request); + } + ar = ar->next; + } + write_comm_pipe_u32 (&dev->requests, 0, 1); + uae_sem_wait (&dev->sync_sem); } - ar = ar->next; - } - write_comm_pipe_u32 (&dev->requests, 0, 1); - uae_sem_wait (&dev->sync_sem); + while (dev->mc) + delmulticastaddresses (dev, dev->mc->start, dev->mc->end); + memset (dev, 0, sizeof (struct devstruct)); } - while (dev->mc) - delmulticastaddresses (dev, dev->mc->start, dev->mc->end); - memset (dev, 0, sizeof (struct devstruct)); - } - for (i = 0; i < MAX_OPEN_DEVICES; i++) - memset (&pdevst[i], 0, sizeof (struct priv_devstruct)); - uaenet_vsync_requested = 0; - uaenet_int_requested = 0; - irq_init = 0; + for (i = 0; i < MAX_OPEN_DEVICES; i++) + memset (&pdevst[i], 0, sizeof (struct priv_devstruct)); + uaenet_vsync_requested = 0; + uaenet_int_requested = 0; + irq_init = 0; } uaecptr netdev_startup (uaecptr resaddr) { - if (!currprefs.sana2) + if (!currprefs.sana2) + return resaddr; + if (log_net) + write_log (L"netdev_startup(0x%x)\n", resaddr); + /* Build a struct Resident. This will set up and initialize + * the uaescsi.device */ + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, ROM_netdev_resname); + put_long (resaddr + 0x12, ROM_netdev_resid); + put_long (resaddr + 0x16, ROM_netdev_init); /* calls scsidev_init */ + resaddr += 0x1A; return resaddr; - if (log_net) - write_log (L"netdev_startup(0x%x)\n", resaddr); - /* Build a struct Resident. This will set up and initialize - * the uaescsi.device */ - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, ROM_netdev_resname); - put_long (resaddr + 0x12, ROM_netdev_resid); - put_long (resaddr + 0x16, ROM_netdev_init); /* calls scsidev_init */ - resaddr += 0x1A; - return resaddr; } void netdev_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, openfunc, closefunc, expungefunc; - uae_u32 beginiofunc, abortiofunc; - - if (!currprefs.sana2) - return; - if (log_net) - write_log (L"netdev_install(): 0x%x\n", here ()); - - uaenet_enumerate_free (td); - uaenet_enumerate (&td, NULL); - - ROM_netdev_resname = ds (getdevname()); - ROM_netdev_resid = ds (L"UAE net.device 0.2"); - timerdevname = ds (L"timer.device"); - - /* initcode */ - initcode = here (); - calltrap (deftrap2 (dev_init, TRAPFLAG_EXTRA_STACK, L"uaenet.init")); dw (RTS); - - /* Open */ - openfunc = here (); - calltrap (deftrap2 (dev_open, TRAPFLAG_EXTRA_STACK, L"uaenet.open")); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap2 (dev_close, TRAPFLAG_EXTRA_STACK, L"uaenet.close")); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap2 (dev_expunge, TRAPFLAG_EXTRA_STACK, L"uaenet.expunge")); dw (RTS); - - /* BeginIO */ - beginiofunc = here (); - calltrap (deftrap2 (dev_beginio, TRAPFLAG_EXTRA_STACK, L"uaenet.beginio")); dw (RTS); - - /* AbortIO */ - abortiofunc = here (); - calltrap (deftrap2 (dev_abortio, TRAPFLAG_EXTRA_STACK, L"uaenet.abortio")); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (openfunc); /* Open */ - dl (closefunc); /* Close */ - dl (expungefunc); /* Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - dl (beginiofunc); /* BeginIO */ - dl (abortiofunc); /* AbortIO */ - dl (0xFFFFFFFFul); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0300); /* NT_DEVICE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (ROM_netdev_resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); /* 0.4 */ - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (0x0000); /* end of table already ??? */ - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (ROM_netdev_resid); - dw (0x0000); /* end of table */ - - ROM_netdev_init = here (); - dl (0x00000100); /* size of device base */ - dl (functable); - dl (datatable); - dl (initcode); - - nscmd_cmd = here (); - dw (CMD_READ); - dw (CMD_WRITE); - dw (CMD_FLUSH); - dw (S2_DEVICEQUERY); - dw (S2_GETSTATIONADDRESS); - dw (S2_CONFIGINTERFACE); - dw (S2_ADDMULTICASTADDRESS); - dw (S2_DELMULTICASTADDRESS); - dw (S2_MULTICAST); - dw (S2_BROADCAST); - dw (S2_TRACKTYPE); - dw (S2_UNTRACKTYPE); - dw (S2_GETTYPESTATS); - dw (S2_GETSPECIALSTATS); - dw (S2_GETGLOBALSTATS); - dw (S2_ONEVENT); - dw (S2_READORPHAN); - dw (S2_ONLINE); - dw (S2_OFFLINE); - dw (S2_ADDMULTICASTADDRESSES); - dw (S2_DELMULTICASTADDRESSES); - dw (NSCMD_DEVICEQUERY); - dw (0); + uae_u32 functable, datatable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; + + if (!currprefs.sana2) + return; + if (log_net) + write_log (L"netdev_install(): 0x%x\n", here ()); + + uaenet_enumerate_free (td); + uaenet_enumerate (&td, NULL); + + ROM_netdev_resname = ds (getdevname()); + ROM_netdev_resid = ds (L"UAE net.device 0.2"); + timerdevname = ds (L"timer.device"); + + /* initcode */ + initcode = here (); + calltrap (deftrap2 (dev_init, TRAPFLAG_EXTRA_STACK, L"uaenet.init")); dw (RTS); + + /* Open */ + openfunc = here (); + calltrap (deftrap2 (dev_open, TRAPFLAG_EXTRA_STACK, L"uaenet.open")); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap2 (dev_close, TRAPFLAG_EXTRA_STACK, L"uaenet.close")); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap2 (dev_expunge, TRAPFLAG_EXTRA_STACK, L"uaenet.expunge")); dw (RTS); + + /* BeginIO */ + beginiofunc = here (); + calltrap (deftrap2 (dev_beginio, TRAPFLAG_EXTRA_STACK, L"uaenet.beginio")); dw (RTS); + + /* AbortIO */ + abortiofunc = here (); + calltrap (deftrap2 (dev_abortio, TRAPFLAG_EXTRA_STACK, L"uaenet.abortio")); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (openfunc); /* Open */ + dl (closefunc); /* Close */ + dl (expungefunc); /* Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + dl (beginiofunc); /* BeginIO */ + dl (abortiofunc); /* AbortIO */ + dl (0xFFFFFFFFul); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0300); /* NT_DEVICE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (ROM_netdev_resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); /* 0.4 */ + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (0x0000); /* end of table already ??? */ + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (ROM_netdev_resid); + dw (0x0000); /* end of table */ + + ROM_netdev_init = here (); + dl (0x00000100); /* size of device base */ + dl (functable); + dl (datatable); + dl (initcode); + + nscmd_cmd = here (); + dw (CMD_READ); + dw (CMD_WRITE); + dw (CMD_FLUSH); + dw (S2_DEVICEQUERY); + dw (S2_GETSTATIONADDRESS); + dw (S2_CONFIGINTERFACE); + dw (S2_ADDMULTICASTADDRESS); + dw (S2_DELMULTICASTADDRESS); + dw (S2_MULTICAST); + dw (S2_BROADCAST); + dw (S2_TRACKTYPE); + dw (S2_UNTRACKTYPE); + dw (S2_GETTYPESTATS); + dw (S2_GETSPECIALSTATS); + dw (S2_GETGLOBALSTATS); + dw (S2_ONEVENT); + dw (S2_READORPHAN); + dw (S2_ONLINE); + dw (S2_OFFLINE); + dw (S2_ADDMULTICASTADDRESSES); + dw (S2_DELMULTICASTADDRESSES); + dw (NSCMD_DEVICEQUERY); + dw (0); } void netdev_start_threads (void) { - if (!currprefs.sana2) - return; - if (log_net) - write_log (L"netdev_start_threads()\n"); - uae_sem_init (&change_sem, 0, 1); - uae_sem_init (&async_sem, 0, 1); + if (!currprefs.sana2) + return; + if (log_net) + write_log (L"netdev_start_threads()\n"); + uae_sem_init (&change_sem, 0, 1); + uae_sem_init (&async_sem, 0, 1); } void netdev_reset (void) { - if (!currprefs.sana2) - return; - dev_reset (); + if (!currprefs.sana2) + return; + dev_reset (); } diff --git a/savestate.c b/savestate.c index ae308b26..d15433e0 100644 --- a/savestate.c +++ b/savestate.c @@ -1,48 +1,48 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Save/restore emulator state - * - * (c) 1999-2001 Toni Wilen - * - * see below for ASF-structure - */ - - /* Features: - * - * - full CPU state (68000/68010/68020/68030/68040/68060) - * - FPU (68881/68882/68040/68060) - * - full CIA-A and CIA-B state (with all internal registers) - * - saves all custom registers and audio internal state. - * - Chip, Bogo, Fast, Z3 and Picasso96 RAM supported - * - disk drive type, imagefile, track and motor state - * - Kickstart ROM version, address and size is saved. This data is not used during restore yet. - * - Action Replay state is saved - */ - - /* Notes: - * - * - blitter state is not saved, blitter is forced to finish immediately if it - * was active - * - disk DMA state is completely saved - * - does not ask for statefile name and description. Currently uses DF0's disk - * image name (".adf" is replaced with ".asf") - * - only Amiga state is restored, harddisk support, autoconfig, expansion boards etc.. - * are not saved/restored (and probably never will). - * - use this for saving games that can't be saved to disk - */ - - /* Usage : - * - * save: - * - * set savestate_state = STATE_DOSAVE, savestate_filename = "..." - * - * restore: - * - * set savestate_state = STATE_DORESTORE, savestate_filename = "..." - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* Save/restore emulator state +* +* (c) 1999-2001 Toni Wilen +* +* see below for ASF-structure +*/ + +/* Features: +* +* - full CPU state (68000/68010/68020/68030/68040/68060) +* - FPU (68881/68882/68040/68060) +* - full CIA-A and CIA-B state (with all internal registers) +* - saves all custom registers and audio internal state. +* - Chip, Bogo, Fast, Z3 and Picasso96 RAM supported +* - disk drive type, imagefile, track and motor state +* - Kickstart ROM version, address and size is saved. This data is not used during restore yet. +* - Action Replay state is saved +*/ + +/* Notes: +* +* - blitter state is not saved, blitter is forced to finish immediately if it +* was active +* - disk DMA state is completely saved +* - does not ask for statefile name and description. Currently uses DF0's disk +* image name (".adf" is replaced with ".asf") +* - only Amiga state is restored, harddisk support, autoconfig, expansion boards etc.. +* are not saved/restored (and probably never will). +* - use this for saving games that can't be saved to disk +*/ + +/* Usage : +* +* save: +* +* set savestate_state = STATE_DOSAVE, savestate_filename = "..." +* +* restore: +* +* set savestate_state = STATE_DORESTORE, savestate_filename = "..." +* +*/ #define OPEN_LOG 0 @@ -66,10 +66,10 @@ int savestate_state = 0; #define MAX_STATERECORDS 1024 /* must be power of 2 */ struct staterecord { - uae_u8 *start; - uae_u8 *end; - uae_u8 *next; - uae_u8 *cpu; + uae_u8 *start; + uae_u8 *end; + uae_u8 *next; + uae_u8 *cpu; }; static int replaycounter; static int replaylastreloaded = -1; @@ -85,566 +85,566 @@ static struct staterecord staterecords[MAX_STATERECORDS]; static void state_incompatible_warn (void) { - static int warned; - int dowarn = 0; - int i; + static int warned; + int dowarn = 0; + int i; #ifdef BSDSOCKET - if (currprefs.socket_emu) - dowarn = 1; + if (currprefs.socket_emu) + dowarn = 1; #endif #ifdef UAESERIAL - if (currprefs.uaeserial) - dowarn = 1; + if (currprefs.uaeserial) + dowarn = 1; #endif #ifdef SCSIEMU - if (currprefs.scsi) - dowarn = 1; + if (currprefs.scsi) + dowarn = 1; #endif #ifdef CATWEASEL - if (currprefs.catweasel) - dowarn = 1; + if (currprefs.catweasel) + dowarn = 1; #endif #ifdef FILESYS - for(i = 0; i < currprefs.mountitems; i++) { - struct mountedinfo mi; - int type = get_filesys_unitconfig (&currprefs, i, &mi); - if (mi.ismounted && type != FILESYS_VIRTUAL && type != FILESYS_HARDFILE && type != FILESYS_HARDFILE_RDB) - dowarn = 1; - } + for(i = 0; i < currprefs.mountitems; i++) { + struct mountedinfo mi; + int type = get_filesys_unitconfig (&currprefs, i, &mi); + if (mi.ismounted && type != FILESYS_VIRTUAL && type != FILESYS_HARDFILE && type != FILESYS_HARDFILE_RDB) + dowarn = 1; + } #endif - if (!warned && dowarn) { - warned = 1; - notify_user (NUMSG_STATEHD); - } + if (!warned && dowarn) { + warned = 1; + notify_user (NUMSG_STATEHD); + } } /* functions for reading/writing bytes, shorts and longs in big-endian - * format independent of host machine's endianess */ +* format independent of host machine's endianess */ void save_u32_func (uae_u8 **dstp, uae_u32 v) { - uae_u8 *dst = *dstp; - *dst++ = (uae_u8)(v >> 24); - *dst++ = (uae_u8)(v >> 16); - *dst++ = (uae_u8)(v >> 8); - *dst++ = (uae_u8)(v >> 0); - *dstp = dst; + uae_u8 *dst = *dstp; + *dst++ = (uae_u8)(v >> 24); + *dst++ = (uae_u8)(v >> 16); + *dst++ = (uae_u8)(v >> 8); + *dst++ = (uae_u8)(v >> 0); + *dstp = dst; } void save_u64_func (uae_u8 **dstp, uae_u64 v) { - save_u32_func (dstp, (uae_u32)(v >> 32)); - save_u32_func (dstp, (uae_u32)v); + save_u32_func (dstp, (uae_u32)(v >> 32)); + save_u32_func (dstp, (uae_u32)v); } void save_u16_func (uae_u8 **dstp, uae_u16 v) { - uae_u8 *dst = *dstp; - *dst++ = (uae_u8)(v >> 8); - *dst++ = (uae_u8)(v >> 0); - *dstp = dst; + uae_u8 *dst = *dstp; + *dst++ = (uae_u8)(v >> 8); + *dst++ = (uae_u8)(v >> 0); + *dstp = dst; } void save_u8_func (uae_u8 **dstp, uae_u8 v) { - uae_u8 *dst = *dstp; - *dst++ = v; - *dstp = dst; + uae_u8 *dst = *dstp; + *dst++ = v; + *dstp = dst; } void save_string_func (uae_u8 **dstp, const TCHAR *from) { - uae_u8 *dst = *dstp; - char *s, *s2; - s2 = s = ua (from); - while (s && *s) - *dst++ = *s++; - *dst++ = 0; - *dstp = dst; - xfree (s2); + uae_u8 *dst = *dstp; + char *s, *s2; + s2 = s = ua (from); + while (s && *s) + *dst++ = *s++; + *dst++ = 0; + *dstp = dst; + xfree (s2); } uae_u32 restore_u32_func (uae_u8 **dstp) { - uae_u32 v; - uae_u8 *dst = *dstp; - v = (dst[0] << 24) | (dst[1] << 16) | (dst[2] << 8) | (dst[3]); - *dstp = dst + 4; - return v; + uae_u32 v; + uae_u8 *dst = *dstp; + v = (dst[0] << 24) | (dst[1] << 16) | (dst[2] << 8) | (dst[3]); + *dstp = dst + 4; + return v; } uae_u64 restore_u64_func (uae_u8 **dstp) { - uae_u64 v; + uae_u64 v; - v = restore_u32_func (dstp); - v <<= 32; - v |= restore_u32_func (dstp); - return v; + v = restore_u32_func (dstp); + v <<= 32; + v |= restore_u32_func (dstp); + return v; } uae_u16 restore_u16_func (uae_u8 **dstp) { - uae_u16 v; - uae_u8 *dst = *dstp; - v=(dst[0] << 8) | (dst[1]); - *dstp = dst + 2; - return v; + uae_u16 v; + uae_u8 *dst = *dstp; + v=(dst[0] << 8) | (dst[1]); + *dstp = dst + 2; + return v; } uae_u8 restore_u8_func (uae_u8 **dstp) { - uae_u8 v; - uae_u8 *dst = *dstp; - v = dst[0]; - *dstp = dst + 1; - return v; + uae_u8 v; + uae_u8 *dst = *dstp; + v = dst[0]; + *dstp = dst + 1; + return v; } TCHAR *restore_string_func (uae_u8 **dstp) { - int len; - uae_u8 v; - uae_u8 *dst = *dstp; - char *top, *to; - TCHAR *s; - - len = strlen(dst) + 1; - top = to = (char*)malloc (len); - do { - v = *dst++; - *top++ = v; - } while(v); - *dstp = dst; - s = au (to); - xfree (to); - return s; + int len; + uae_u8 v; + uae_u8 *dst = *dstp; + char *top, *to; + TCHAR *s; + + len = strlen(dst) + 1; + top = to = (char*)malloc (len); + do { + v = *dst++; + *top++ = v; + } while(v); + *dstp = dst; + s = au (to); + xfree (to); + return s; } /* read and write IFF-style hunks */ static void save_chunk (struct zfile *f, uae_u8 *chunk, size_t len, TCHAR *name, int compress) { - uae_u8 tmp[8], *dst; - uae_u8 zero[4]= { 0, 0, 0, 0 }; - uae_u32 flags; - size_t pos; - size_t chunklen, len2; - char *s; - - if (!chunk) - return; + uae_u8 tmp[8], *dst; + uae_u8 zero[4]= { 0, 0, 0, 0 }; + uae_u32 flags; + size_t pos; + size_t chunklen, len2; + char *s; - if (compress < 0) { - zfile_fwrite (chunk, 1, len, f); - return; - } - - /* chunk name */ - s = ua (name); - zfile_fwrite (s, 1, 4, f); - xfree (s); - pos = zfile_ftell (f); - /* chunk size */ - dst = &tmp[0]; - chunklen = len + 4 + 4 + 4; - save_u32 (chunklen); - zfile_fwrite (&tmp[0], 1, 4, f); - /* chunk flags */ - flags = 0; - dst = &tmp[0]; - save_u32 (flags | compress); - zfile_fwrite (&tmp[0], 1, 4, f); - /* chunk data */ - if (compress) { - int tmplen = len; - size_t opos; + if (!chunk) + return; + + if (compress < 0) { + zfile_fwrite (chunk, 1, len, f); + return; + } + + /* chunk name */ + s = ua (name); + zfile_fwrite (s, 1, 4, f); + xfree (s); + pos = zfile_ftell (f); + /* chunk size */ dst = &tmp[0]; - save_u32 (len); - opos = zfile_ftell (f); + chunklen = len + 4 + 4 + 4; + save_u32 (chunklen); zfile_fwrite (&tmp[0], 1, 4, f); - len = zfile_zcompress (f, chunk, len); - if (len > 0) { - zfile_fseek (f, pos, SEEK_SET); - dst = &tmp[0]; - save_u32 (len + 4 + 4 + 4 + 4); - zfile_fwrite (&tmp[0], 1, 4, f); - zfile_fseek (f, 0, SEEK_END); - } else { - len = tmplen; - compress = 0; - zfile_fseek (f, opos, SEEK_SET); - dst = &tmp[0]; - save_u32 (flags); - zfile_fwrite (&tmp[0], 1, 4, f); + /* chunk flags */ + flags = 0; + dst = &tmp[0]; + save_u32 (flags | compress); + zfile_fwrite (&tmp[0], 1, 4, f); + /* chunk data */ + if (compress) { + int tmplen = len; + size_t opos; + dst = &tmp[0]; + save_u32 (len); + opos = zfile_ftell (f); + zfile_fwrite (&tmp[0], 1, 4, f); + len = zfile_zcompress (f, chunk, len); + if (len > 0) { + zfile_fseek (f, pos, SEEK_SET); + dst = &tmp[0]; + save_u32 (len + 4 + 4 + 4 + 4); + zfile_fwrite (&tmp[0], 1, 4, f); + zfile_fseek (f, 0, SEEK_END); + } else { + len = tmplen; + compress = 0; + zfile_fseek (f, opos, SEEK_SET); + dst = &tmp[0]; + save_u32 (flags); + zfile_fwrite (&tmp[0], 1, 4, f); + } } - } - if (!compress) - zfile_fwrite (chunk, 1, len, f); - /* alignment */ - len2 = 4 - (len & 3); - if (len2) - zfile_fwrite (zero, 1, len2, f); - - write_log (L"Chunk '%s' chunk size %d (%d)\n", name, chunklen, len); + if (!compress) + zfile_fwrite (chunk, 1, len, f); + /* alignment */ + len2 = 4 - (len & 3); + if (len2) + zfile_fwrite (zero, 1, len2, f); + + write_log (L"Chunk '%s' chunk size %d (%d)\n", name, chunklen, len); } static uae_u8 *restore_chunk (struct zfile *f, TCHAR *name, size_t *len, size_t *totallen, size_t *filepos) { - uae_u8 tmp[5], dummy[4], *mem, *src; - uae_u32 flags; - int len2; - - *totallen = 0; - /* chunk name */ - zfile_fread (tmp, 1, 4, f); - tmp[4] = 0; - au_copy (name, 5, tmp); - /* chunk size */ - zfile_fread (tmp, 1, 4, f); - src = tmp; - len2 = restore_u32 () - 4 - 4 - 4; - if (len2 < 0) - len2 = 0; - *len = len2; - if (len2 == 0) { - *filepos = zfile_ftell (f); - return 0; - } - - /* chunk flags */ - zfile_fread (tmp, 1, 4, f); - src = tmp; - flags = restore_u32 (); - *totallen = *len; - if (flags & 1) { + uae_u8 tmp[6], dummy[4], *mem, *src; + uae_u32 flags; + int len2; + + *totallen = 0; + /* chunk name */ + zfile_fread (tmp, 1, 4, f); + tmp[4] = 0; + au_copy (name, 5, tmp); + /* chunk size */ + zfile_fread (tmp, 1, 4, f); + src = tmp; + len2 = restore_u32 () - 4 - 4 - 4; + if (len2 < 0) + len2 = 0; + *len = len2; + if (len2 == 0) { + *filepos = zfile_ftell (f); + return 0; + } + + /* chunk flags */ zfile_fread (tmp, 1, 4, f); src = tmp; - *totallen = restore_u32 (); - *filepos = zfile_ftell (f) - 4 - 4 - 4; - len2 -= 4; - } else { - *filepos = zfile_ftell (f) - 4 - 4; - } - /* chunk data. RAM contents will be loaded during the reset phase, - no need to malloc multiple megabytes here. */ - if (_tcscmp (name, L"CRAM") != 0 - && _tcscmp (name, L"BRAM") != 0 - && _tcscmp (name, L"FRAM") != 0 - && _tcscmp (name, L"ZRAM") != 0 - && _tcscmp (name, L"PRAM") != 0 - && _tcscmp (name, L"A3K1") != 0 - && _tcscmp (name, L"A3K2") != 0) - { - /* without zeros at the end old state files may not work */ - mem = (uae_u8*)calloc (1, *totallen + 32); + flags = restore_u32 (); + *totallen = *len; if (flags & 1) { - zfile_zuncompress (mem, *totallen, f, len2); + zfile_fread (tmp, 1, 4, f); + src = tmp; + *totallen = restore_u32 (); + *filepos = zfile_ftell (f) - 4 - 4 - 4; + len2 -= 4; + } else { + *filepos = zfile_ftell (f) - 4 - 4; + } + /* chunk data. RAM contents will be loaded during the reset phase, + no need to malloc multiple megabytes here. */ + if (_tcscmp (name, L"CRAM") != 0 + && _tcscmp (name, L"BRAM") != 0 + && _tcscmp (name, L"FRAM") != 0 + && _tcscmp (name, L"ZRAM") != 0 + && _tcscmp (name, L"PRAM") != 0 + && _tcscmp (name, L"A3K1") != 0 + && _tcscmp (name, L"A3K2") != 0) + { + /* without zeros at the end old state files may not work */ + mem = calloc (1, *totallen + 32); + if (flags & 1) { + zfile_zuncompress (mem, *totallen, f, len2); + } else { + zfile_fread (mem, 1, len2, f); + } } else { - zfile_fread (mem, 1, len2, f); + mem = 0; + zfile_fseek (f, len2, SEEK_CUR); } - } else { - mem = 0; - zfile_fseek (f, len2, SEEK_CUR); - } - - /* alignment */ - len2 = 4 - (len2 & 3); - if (len2) - zfile_fread (dummy, 1, len2, f); - return mem; + + /* alignment */ + len2 = 4 - (len2 & 3); + if (len2) + zfile_fread (dummy, 1, len2, f); + return mem; } void restore_ram (size_t filepos, uae_u8 *memory) { - uae_u8 tmp[8]; - uae_u8 *src = tmp; - int size, fullsize; - uae_u32 flags; - - if (filepos == 0 || memory == NULL) - return; - zfile_fseek (savestate_file, filepos, SEEK_SET); - zfile_fread (tmp, 1, sizeof(tmp), savestate_file); - size = restore_u32 (); - flags = restore_u32 (); - size -= 4 + 4 + 4; - if (flags & 1) { - zfile_fread (tmp, 1, 4, savestate_file); - src = tmp; - fullsize = restore_u32 (); - size -= 4; - zfile_zuncompress (memory, fullsize, savestate_file, size); - } else { - zfile_fread (memory, 1, size, savestate_file); - } + uae_u8 tmp[8]; + uae_u8 *src = tmp; + int size, fullsize; + uae_u32 flags; + + if (filepos == 0 || memory == NULL) + return; + zfile_fseek (savestate_file, filepos, SEEK_SET); + zfile_fread (tmp, 1, sizeof tmp, savestate_file); + size = restore_u32 (); + flags = restore_u32 (); + size -= 4 + 4 + 4; + if (flags & 1) { + zfile_fread (tmp, 1, 4, savestate_file); + src = tmp; + fullsize = restore_u32 (); + size -= 4; + zfile_zuncompress (memory, fullsize, savestate_file, size); + } else { + zfile_fread (memory, 1, size, savestate_file); + } } static uae_u8 *restore_log (uae_u8 *src) { #if OPEN_LOG > 0 - TCHAR *s = utf8u (src); - write_log (L"%s\n", s); - xfree (s); + TCHAR *s = utf8u (src); + write_log (L"%s\n", s); + xfree (s); #endif - src += strlen (src) + 1; - return src; + src += strlen (src) + 1; + return src; } static void restore_header (uae_u8 *src) { - TCHAR *emuname, *emuversion, *description; - - restore_u32 (); - emuname = restore_string (); - emuversion = restore_string (); - description = restore_string (); - write_log (L"Saved with: '%s %s', description: '%s'\n", - emuname, emuversion, description); - xfree (description); - xfree (emuversion); - xfree (emuname); + TCHAR *emuname, *emuversion, *description; + + restore_u32 (); + emuname = restore_string (); + emuversion = restore_string (); + description = restore_string (); + write_log (L"Saved with: '%s %s', description: '%s'\n", + emuname, emuversion, description); + xfree (description); + xfree (emuversion); + xfree (emuname); } /* restore all subsystems */ void restore_state (const TCHAR *filename) { - struct zfile *f; - uae_u8 *chunk,*end; - TCHAR name[5]; - size_t len, totallen; - size_t filepos, filesize; - int z3num; - - chunk = 0; - f = zfile_fopen (filename, L"rb", ZFD_NORMAL); - if (!f) - goto error; - zfile_fseek (f, 0, SEEK_END); - filesize = zfile_ftell (f); - zfile_fseek (f, 0, SEEK_SET); - savestate_init (); - - chunk = restore_chunk (f, name, &len, &totallen, &filepos); - if (!chunk || _tcsncmp (name, L"ASF ", 4)) { - write_log (L"%s is not an AmigaStateFile\n", filename); - goto error; - } - savestate_file = f; - restore_header (chunk); - xfree (chunk); - changed_prefs.bogomem_size = 0; - changed_prefs.chipmem_size = 0; - changed_prefs.fastmem_size = 0; - changed_prefs.z3fastmem_size = 0; - changed_prefs.z3fastmem2_size = 0; - changed_prefs.mbresmem_low_size = 0; - changed_prefs.mbresmem_high_size = 0; - z3num = 0; - savestate_state = STATE_RESTORE; - for (;;) { - name[0] = 0; - chunk = end = restore_chunk (f, name, &len, &totallen, &filepos); - write_log (L"Chunk '%s' size %d (%d)\n", name, len, totallen); - if (!_tcscmp (name, L"END ")) { + struct zfile *f; + uae_u8 *chunk,*end; + TCHAR name[5]; + size_t len, totallen; + size_t filepos, filesize; + int z3num; + + chunk = 0; + f = zfile_fopen (filename, L"rb", ZFD_NORMAL); + if (!f) + goto error; + zfile_fseek (f, 0, SEEK_END); + filesize = zfile_ftell (f); + zfile_fseek (f, 0, SEEK_SET); + savestate_init (); + + chunk = restore_chunk (f, name, &len, &totallen, &filepos); + if (!chunk || _tcsncmp (name, L"ASF ", 4)) { + write_log (L"%s is not an AmigaStateFile\n", filename); + goto error; + } + savestate_file = f; + restore_header (chunk); + xfree (chunk); + changed_prefs.bogomem_size = 0; + changed_prefs.chipmem_size = 0; + changed_prefs.fastmem_size = 0; + changed_prefs.z3fastmem_size = 0; + changed_prefs.z3fastmem2_size = 0; + changed_prefs.mbresmem_low_size = 0; + changed_prefs.mbresmem_high_size = 0; + z3num = 0; + savestate_state = STATE_RESTORE; + for (;;) { + name[0] = 0; + chunk = end = restore_chunk (f, name, &len, &totallen, &filepos); + write_log (L"Chunk '%s' size %d (%d)\n", name, len, totallen); + if (!_tcscmp (name, L"END ")) { #ifdef _DEBUG - if (filesize > filepos + 8) - continue; + if (filesize > filepos + 8) + continue; #endif - break; - } - if (!_tcscmp (name, L"CRAM")) { - restore_cram (totallen, filepos); - continue; - } else if (!_tcscmp (name, L"BRAM")) { - restore_bram (totallen, filepos); - continue; - } else if (!_tcscmp (name, L"A3K1")) { - restore_a3000lram (totallen, filepos); - continue; - } else if (!_tcscmp (name, L"A3K2")) { - restore_a3000hram (totallen, filepos); - continue; + break; + } + if (!_tcscmp (name, L"CRAM")) { + restore_cram (totallen, filepos); + continue; + } else if (!_tcscmp (name, L"BRAM")) { + restore_bram (totallen, filepos); + continue; + } else if (!_tcscmp (name, L"A3K1")) { + restore_a3000lram (totallen, filepos); + continue; + } else if (!_tcscmp (name, L"A3K2")) { + restore_a3000hram (totallen, filepos); + continue; #ifdef AUTOCONFIG - } else if (!_tcscmp (name, L"FRAM")) { - restore_fram (totallen, filepos); - continue; - } else if (!_tcscmp (name, L"ZRAM")) { - restore_zram (totallen, filepos, z3num++); - continue; - } else if (!_tcscmp (name, L"BORO")) { - restore_bootrom (totallen, filepos); - continue; + } else if (!_tcscmp (name, L"FRAM")) { + restore_fram (totallen, filepos); + continue; + } else if (!_tcscmp (name, L"ZRAM")) { + restore_zram (totallen, filepos, z3num++); + continue; + } else if (!_tcscmp (name, L"BORO")) { + restore_bootrom (totallen, filepos); + continue; #endif #ifdef PICASSO96 - } else if (!_tcscmp (name, L"PRAM")) { - restore_pram (totallen, filepos); - continue; + } else if (!_tcscmp (name, L"PRAM")) { + restore_pram (totallen, filepos); + continue; #endif - } else if (!_tcscmp (name, L"CPU ")) - end = restore_cpu (chunk); + } else if (!_tcscmp (name, L"CPU ")) + end = restore_cpu (chunk); #ifdef FPUEMU - else if (!_tcscmp (name, L"FPU ")) - end = restore_fpu (chunk); + else if (!_tcscmp (name, L"FPU ")) + end = restore_fpu (chunk); #endif #ifdef MMUEMU - else if (!_tcscmp (name, L"MMU ")) - end = restore_mmu (chunk); + else if (!_tcscmp (name, L"MMU ")) + end = restore_mmu (chunk); #endif - else if (!_tcscmp (name, L"AGAC")) - end = restore_custom_agacolors (chunk); - else if (!_tcscmp (name, L"SPR0")) - end = restore_custom_sprite (0, chunk); - else if (!_tcscmp (name, L"SPR1")) - end = restore_custom_sprite (1, chunk); - else if (!_tcscmp (name, L"SPR2")) - end = restore_custom_sprite (2, chunk); - else if (!_tcscmp (name, L"SPR3")) - end = restore_custom_sprite (3, chunk); - else if (!_tcscmp (name, L"SPR4")) - end = restore_custom_sprite (4, chunk); - else if (!_tcscmp (name, L"SPR5")) - end = restore_custom_sprite (5, chunk); - else if (!_tcscmp (name, L"SPR6")) - end = restore_custom_sprite (6, chunk); - else if (!_tcscmp (name, L"SPR7")) - end = restore_custom_sprite (7, chunk); - else if (!_tcscmp (name, L"CIAA")) - end = restore_cia (0, chunk); - else if (!_tcscmp (name, L"CIAB")) - end = restore_cia (1, chunk); - else if (!_tcscmp (name, L"CHIP")) - end = restore_custom (chunk); - else if (!_tcscmp (name, L"AUD0")) - end = restore_audio (0, chunk); - else if (!_tcscmp (name, L"AUD1")) - end = restore_audio (1, chunk); - else if (!_tcscmp (name, L"AUD2")) - end = restore_audio (2, chunk); - else if (!_tcscmp (name, L"AUD3")) - end = restore_audio (3, chunk); - else if (!_tcscmp (name, L"BLIT")) - end = restore_blitter (chunk); - else if (!_tcscmp (name, L"DISK")) - end = restore_floppy (chunk); - else if (!_tcscmp (name, L"DSK0")) - end = restore_disk (0, chunk); - else if (!_tcscmp (name, L"DSK1")) - end = restore_disk (1, chunk); - else if (!_tcscmp (name, L"DSK2")) - end = restore_disk (2, chunk); - else if (!_tcscmp (name, L"DSK3")) - end = restore_disk (3, chunk); - else if (!_tcscmp (name, L"KEYB")) - end = restore_keyboard (chunk); + else if (!_tcscmp (name, L"AGAC")) + end = restore_custom_agacolors (chunk); + else if (!_tcscmp (name, L"SPR0")) + end = restore_custom_sprite (0, chunk); + else if (!_tcscmp (name, L"SPR1")) + end = restore_custom_sprite (1, chunk); + else if (!_tcscmp (name, L"SPR2")) + end = restore_custom_sprite (2, chunk); + else if (!_tcscmp (name, L"SPR3")) + end = restore_custom_sprite (3, chunk); + else if (!_tcscmp (name, L"SPR4")) + end = restore_custom_sprite (4, chunk); + else if (!_tcscmp (name, L"SPR5")) + end = restore_custom_sprite (5, chunk); + else if (!_tcscmp (name, L"SPR6")) + end = restore_custom_sprite (6, chunk); + else if (!_tcscmp (name, L"SPR7")) + end = restore_custom_sprite (7, chunk); + else if (!_tcscmp (name, L"CIAA")) + end = restore_cia (0, chunk); + else if (!_tcscmp (name, L"CIAB")) + end = restore_cia (1, chunk); + else if (!_tcscmp (name, L"CHIP")) + end = restore_custom (chunk); + else if (!_tcscmp (name, L"AUD0")) + end = restore_audio (0, chunk); + else if (!_tcscmp (name, L"AUD1")) + end = restore_audio (1, chunk); + else if (!_tcscmp (name, L"AUD2")) + end = restore_audio (2, chunk); + else if (!_tcscmp (name, L"AUD3")) + end = restore_audio (3, chunk); + else if (!_tcscmp (name, L"BLIT")) + end = restore_blitter (chunk); + else if (!_tcscmp (name, L"DISK")) + end = restore_floppy (chunk); + else if (!_tcscmp (name, L"DSK0")) + end = restore_disk (0, chunk); + else if (!_tcscmp (name, L"DSK1")) + end = restore_disk (1, chunk); + else if (!_tcscmp (name, L"DSK2")) + end = restore_disk (2, chunk); + else if (!_tcscmp (name, L"DSK3")) + end = restore_disk (3, chunk); + else if (!_tcscmp (name, L"KEYB")) + end = restore_keyboard (chunk); #ifdef AUTOCONFIG - else if (!_tcscmp (name, L"EXPA")) - end = restore_expansion (chunk); + else if (!_tcscmp (name, L"EXPA")) + end = restore_expansion (chunk); #endif - else if (!_tcscmp (name, L"ROM ")) - end = restore_rom (chunk); + else if (!_tcscmp (name, L"ROM ")) + end = restore_rom (chunk); #ifdef PICASSO96 - else if (!_tcscmp (name, L"P96 ")) - end = restore_p96 (chunk); + else if (!_tcscmp (name, L"P96 ")) + end = restore_p96 (chunk); #endif #ifdef ACTION_REPLAY - else if (!_tcscmp (name, L"ACTR")) - end = restore_action_replay (chunk); - else if (!_tcscmp (name, L"HRTM")) - end = restore_hrtmon (chunk); + else if (!_tcscmp (name, L"ACTR")) + end = restore_action_replay (chunk); + else if (!_tcscmp (name, L"HRTM")) + end = restore_hrtmon (chunk); #endif #ifdef FILESYS - else if (!_tcscmp (name, L"FSYS")) - end = restore_filesys (chunk); - else if (!_tcscmp (name, L"FSYC")) - end = restore_filesys_common (chunk); + else if (!_tcscmp (name, L"FSYS")) + end = restore_filesys (chunk); + else if (!_tcscmp (name, L"FSYC")) + end = restore_filesys_common (chunk); #endif #ifdef CD32 - else if (!_tcscmp (name, L"CD32")) - end = restore_akiko (chunk); + else if (!_tcscmp (name, L"CD32")) + end = restore_akiko (chunk); #endif - else if (!_tcscmp (name, L"GAYL")) - end = restore_gayle (chunk); - else if (!_tcscmp (name, L"IDE ")) - end = restore_ide (chunk); - else if (!_tcscmp (name, L"CONF")) - end = restore_configuration (chunk); - else if (!_tcscmp (name, L"LOG ")) - end = restore_log (chunk); - else { - end = chunk + len; - write_log (L"unknown chunk '%s' size %d bytes\n", name, len); + else if (!_tcscmp (name, L"GAYL")) + end = restore_gayle (chunk); + else if (!_tcscmp (name, L"IDE ")) + end = restore_ide (chunk); + else if (!_tcscmp (name, L"CONF")) + end = restore_configuration (chunk); + else if (!_tcscmp (name, L"LOG ")) + end = restore_log (chunk); + else { + end = chunk + len; + write_log (L"unknown chunk '%s' size %d bytes\n", name, len); + } + if (end == NULL) + write_log (L"Chunk '%s', size %d bytes was not accepted!\n", + name, len); + else if (totallen != end - chunk) + write_log (L"Chunk '%s' total size %d bytes but read %d bytes!\n", + name, totallen, end - chunk); + xfree (chunk); } - if (end == NULL) - write_log (L"Chunk '%s', size %d bytes was not accepted!\n", - name, len); - else if (len != end - chunk) - write_log (L"Chunk '%s' total size %d bytes but read %d bytes!\n", - name, len, end - chunk); - xfree (chunk); - } - restore_disk_finish (); - restore_blitter_finish (); - restore_akiko_finish (); - restore_p96_finish (); - target_addtorecent (filename, 0); - return; - - error: - savestate_state = 0; - savestate_file = 0; - if (chunk) - xfree (chunk); - if (f) - zfile_fclose (f); + restore_disk_finish (); + restore_blitter_finish (); + restore_akiko_finish (); + restore_p96_finish (); + target_addtorecent (filename, 0); + return; + +error: + savestate_state = 0; + savestate_file = 0; + if (chunk) + xfree (chunk); + if (f) + zfile_fclose (f); } void savestate_restore_finish (void) { - if (savestate_state != STATE_RESTORE && savestate_state != STATE_REWIND) - return; - zfile_fclose (savestate_file); - savestate_file = 0; - savestate_state = 0; - restore_cpu_finish (); + if (savestate_state != STATE_RESTORE && savestate_state != STATE_REWIND) + return; + zfile_fclose (savestate_file); + savestate_file = 0; + savestate_state = 0; + restore_cpu_finish (); } /* 1=compressed,2=not compressed,3=ram dump,4=audio dump */ void savestate_initsave (const TCHAR *filename, int mode, int nodialogs) { - if (filename == NULL) { - savestate_fname[0] = 0; - savestate_docompress = 0; - savestate_specialdump = 0; - savestate_nodialogs = 0; - return; - } - _tcscpy (savestate_fname, filename); - savestate_docompress = (mode == 1) ? 1 : 0; - savestate_specialdump = (mode == 3) ? 1 : (mode == 4) ? 2 : 0; - savestate_nodialogs = nodialogs; + if (filename == NULL) { + savestate_fname[0] = 0; + savestate_docompress = 0; + savestate_specialdump = 0; + savestate_nodialogs = 0; + return; + } + _tcscpy (savestate_fname, filename); + savestate_docompress = (mode == 1) ? 1 : 0; + savestate_specialdump = (mode == 3) ? 1 : (mode == 4) ? 2 : 0; + savestate_nodialogs = nodialogs; } static void save_rams (struct zfile *f, int comp) { - uae_u8 *dst; - int len; - - dst = save_cram (&len); - save_chunk (f, dst, len, L"CRAM", comp); - dst = save_bram (&len); - save_chunk (f, dst, len, L"BRAM", comp); - dst = save_a3000lram (&len); - save_chunk (f, dst, len, L"A3K1", comp); - dst = save_a3000hram (&len); - save_chunk (f, dst, len, L"A3K2", comp); + uae_u8 *dst; + int len; + + dst = save_cram (&len); + save_chunk (f, dst, len, L"CRAM", comp); + dst = save_bram (&len); + save_chunk (f, dst, len, L"BRAM", comp); + dst = save_a3000lram (&len); + save_chunk (f, dst, len, L"A3K1", comp); + dst = save_a3000hram (&len); + save_chunk (f, dst, len, L"A3K2", comp); #ifdef AUTOCONFIG - dst = save_fram (&len); - save_chunk (f, dst, len, L"FRAM", comp); - dst = save_zram (&len, 0); - save_chunk (f, dst, len, L"ZRAM", comp); - dst = save_zram (&len, 1); - save_chunk (f, dst, len, L"ZRAM", comp); - dst = save_bootrom (&len); - save_chunk (f, dst, len, L"BORO", comp); + dst = save_fram (&len); + save_chunk (f, dst, len, L"FRAM", comp); + dst = save_zram (&len, 0); + save_chunk (f, dst, len, L"ZRAM", comp); + dst = save_zram (&len, 1); + save_chunk (f, dst, len, L"ZRAM", comp); + dst = save_bootrom (&len); + save_chunk (f, dst, len, L"BORO", comp); #endif #ifdef PICASSO96 - dst = save_pram (&len); - save_chunk (f, dst, len, L"PRAM", comp); + dst = save_pram (&len); + save_chunk (f, dst, len, L"PRAM", comp); #endif } @@ -652,554 +652,554 @@ static void save_rams (struct zfile *f, int comp) int save_state (const TCHAR *filename, const TCHAR *description) { - uae_u8 endhunk[] = { 'E', 'N', 'D', ' ', 0, 0, 0, 8 }; - uae_u8 header[1000]; - TCHAR tmp[100]; - uae_u8 *dst; - struct zfile *f; - int len,i; - TCHAR name[5]; - int comp = savestate_docompress; - - if (!savestate_specialdump && !savestate_nodialogs) { - state_incompatible_warn (); - if (!save_filesys_cando ()) { - gui_message (L"Filesystem active. Try again later"); - return -1; + uae_u8 endhunk[] = { 'E', 'N', 'D', ' ', 0, 0, 0, 8 }; + uae_u8 header[1000]; + TCHAR tmp[100]; + uae_u8 *dst; + struct zfile *f; + int len,i; + TCHAR name[5]; + int comp = savestate_docompress; + + if (!savestate_specialdump && !savestate_nodialogs) { + state_incompatible_warn (); + if (!save_filesys_cando ()) { + gui_message (L"Filesystem active. Try again later"); + return -1; + } } - } - savestate_nodialogs = 0; - custom_prepare_savestate (); - f = zfile_fopen (filename, L"w+b", 0); - if (!f) - return 0; - if (savestate_specialdump) { - size_t pos; - if (savestate_specialdump == 2) - write_wavheader (f, 0, 22050); - pos = zfile_ftell (f); - save_rams (f, -1); - if (savestate_specialdump == 2) { - int len, len2, i; - uae_u8 *tmp; - len = zfile_ftell (f) - pos; - tmp = xmalloc (len); - zfile_fseek(f, pos, SEEK_SET); - len2 = zfile_fread (tmp, 1, len, f); - for (i = 0; i < len2; i++) - tmp[i] += 0x80; - write_wavheader (f, len, 22050); - zfile_fwrite (tmp, len2, 1, f); - xfree (tmp); + savestate_nodialogs = 0; + custom_prepare_savestate (); + f = zfile_fopen (filename, L"w+b", 0); + if (!f) + return 0; + if (savestate_specialdump) { + size_t pos; + if (savestate_specialdump == 2) + write_wavheader (f, 0, 22050); + pos = zfile_ftell (f); + save_rams (f, -1); + if (savestate_specialdump == 2) { + int len, len2, i; + uae_u8 *tmp; + len = zfile_ftell (f) - pos; + tmp = xmalloc (len); + zfile_fseek(f, pos, SEEK_SET); + len2 = zfile_fread (tmp, 1, len, f); + for (i = 0; i < len2; i++) + tmp[i] += 0x80; + write_wavheader (f, len, 22050); + zfile_fwrite (tmp, len2, 1, f); + xfree (tmp); + } + zfile_fclose (f); + return 1; } - zfile_fclose (f); - return 1; - } - dst = header; - save_u32 (0); - save_string (L"UAE"); - _stprintf (tmp, L"%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); - save_string (tmp); - save_string (description); - save_chunk (f, header, dst-header, L"ASF ", 0); + dst = header; + save_u32 (0); + save_string (L"UAE"); + _stprintf (tmp, L"%d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); + save_string (tmp); + save_string (description); + save_chunk (f, header, dst-header, L"ASF ", 0); - dst = save_cpu (&len, 0); - save_chunk (f, dst, len, L"CPU ", 0); - xfree (dst); + dst = save_cpu (&len, 0); + save_chunk (f, dst, len, L"CPU ", 0); + xfree (dst); #ifdef FPUEMU - dst = save_fpu (&len,0 ); - save_chunk (f, dst, len, L"FPU ", 0); - xfree (dst); + dst = save_fpu (&len,0 ); + save_chunk (f, dst, len, L"FPU ", 0); + xfree (dst); #endif #ifdef MMUEMU - dst = save_mmu (&len, 0); - save_chunk (f, dst, len, L"MMU ", 0); - xfree (dst); + dst = save_mmu (&len, 0); + save_chunk (f, dst, len, L"MMU ", 0); + xfree (dst); #endif - _tcscpy(name, L"DSKx"); - for (i = 0; i < 4; i++) { - dst = save_disk (i, &len, 0); - if (dst) { - name[3] = i + '0'; - save_chunk (f, dst, len, name, 0); - xfree (dst); + _tcscpy(name, L"DSKx"); + for (i = 0; i < 4; i++) { + dst = save_disk (i, &len, 0); + if (dst) { + name[3] = i + '0'; + save_chunk (f, dst, len, name, 0); + xfree (dst); + } } - } - dst = save_floppy (&len, 0); - save_chunk (f, dst, len, L"DISK", 0); - xfree (dst); - - dst = save_blitter (&len, 0); - save_chunk (f, dst, len, L"BLIT", 0); - xfree (dst); - - dst = save_custom (&len, 0, 0); - save_chunk (f, dst, len, L"CHIP", 0); - xfree (dst); - - dst = save_custom_agacolors (&len, 0); - save_chunk (f, dst, len, L"AGAC", 0); - xfree (dst); - - _tcscpy (name, L"SPRx"); - for (i = 0; i < 8; i++) { - dst = save_custom_sprite (i, &len, 0); - name[3] = i + '0'; - save_chunk (f, dst, len, name, 0); + dst = save_floppy (&len, 0); + save_chunk (f, dst, len, L"DISK", 0); + xfree (dst); + + dst = save_blitter (&len, 0); + save_chunk (f, dst, len, L"BLIT", 0); + xfree (dst); + + dst = save_custom (&len, 0, 0); + save_chunk (f, dst, len, L"CHIP", 0); xfree (dst); - } - _tcscpy (name, L"AUDx"); - for (i = 0; i < 4; i++) { - dst = save_audio (i, &len, 0); - name[3] = i + '0'; - save_chunk (f, dst, len, name, 0); + dst = save_custom_agacolors (&len, 0); + save_chunk (f, dst, len, L"AGAC", 0); xfree (dst); - } - dst = save_cia (0, &len, 0); - save_chunk (f, dst, len, L"CIAA", 0); - xfree (dst); + _tcscpy (name, L"SPRx"); + for (i = 0; i < 8; i++) { + dst = save_custom_sprite (i, &len, 0); + name[3] = i + '0'; + save_chunk (f, dst, len, name, 0); + xfree (dst); + } - dst = save_cia (1, &len, 0); - save_chunk (f, dst, len, L"CIAB", 0); - xfree (dst); + _tcscpy (name, L"AUDx"); + for (i = 0; i < 4; i++) { + dst = save_audio (i, &len, 0); + name[3] = i + '0'; + save_chunk (f, dst, len, name, 0); + xfree (dst); + } - dst = save_keyboard (&len); - save_chunk (f, dst, len, L"KEYB", 0); - xfree (dst); + dst = save_cia (0, &len, 0); + save_chunk (f, dst, len, L"CIAA", 0); + xfree (dst); + + dst = save_cia (1, &len, 0); + save_chunk (f, dst, len, L"CIAB", 0); + xfree (dst); + + dst = save_keyboard (&len); + save_chunk (f, dst, len, L"KEYB", 0); + xfree (dst); #ifdef AUTOCONFIG - dst = save_expansion (&len, 0); - save_chunk (f, dst, len, L"EXPA", 0); + dst = save_expansion (&len, 0); + save_chunk (f, dst, len, L"EXPA", 0); #endif #ifdef PICASSO96 - dst = save_p96 (&len, 0); - save_chunk (f, dst, len, L"P96 ", 0); + dst = save_p96 (&len, 0); + save_chunk (f, dst, len, L"P96 ", 0); #endif - save_rams (f, comp); + save_rams (f, comp); - dst = save_rom (1, &len, 0); - do { - if (!dst) - break; - save_chunk (f, dst, len, L"ROM ", 0); - xfree (dst); - } while ((dst = save_rom (0, &len, 0))); + dst = save_rom (1, &len, 0); + do { + if (!dst) + break; + save_chunk (f, dst, len, L"ROM ", 0); + xfree (dst); + } while ((dst = save_rom (0, &len, 0))); #ifdef CD32 - dst = save_akiko (&len); - save_chunk (f, dst, len, L"CD32", 0); - xfree (dst); + dst = save_akiko (&len); + save_chunk (f, dst, len, L"CD32", 0); + xfree (dst); #endif #ifdef ACTION_REPLAY - dst = save_action_replay (&len, 0); - save_chunk (f, dst, len, L"ACTR", 1); - dst = save_hrtmon (&len, 0); - save_chunk (f, dst, len, L"HRTM", 1); + dst = save_action_replay (&len, 0); + save_chunk (f, dst, len, L"ACTR", comp); + dst = save_hrtmon (&len, 0); + save_chunk (f, dst, len, L"HRTM", comp); #endif #ifdef FILESYS - dst = save_filesys_common (&len); - if (dst) { - save_chunk (f, dst, len, L"FSYC", 0); - for (i = 0; i < nr_units (); i++) { - dst = save_filesys (i, &len); - if (dst) { - save_chunk (f, dst, len, L"FSYS", 0); - xfree (dst); - } + dst = save_filesys_common (&len); + if (dst) { + save_chunk (f, dst, len, L"FSYC", 0); + for (i = 0; i < nr_units (); i++) { + dst = save_filesys (i, &len); + if (dst) { + save_chunk (f, dst, len, L"FSYS", 0); + xfree (dst); + } + } } - } #endif - dst = save_gayle(&len); - if (dst) { - save_chunk (f, dst, len, L"GAYL", 0); - xfree(dst); - } - for (i = 0; i < 4; i++) { - dst = save_ide (i, &len); + dst = save_gayle (&len); if (dst) { - save_chunk (f, dst, len, L"IDE ", 0); - xfree(dst); + save_chunk (f, dst, len, L"GAYL", 0); + xfree(dst); } - } - - /* add fake END tag, makes it easy to strip CONF and LOG hunks */ - /* move this if you want to use CONF or LOG hunks when restoring state */ - zfile_fwrite (endhunk, 1, 8, f); - - dst = save_configuration (&len); - if (dst) { - save_chunk (f, dst, len, L"CONF", 1); - xfree(dst); - } - dst = save_log (TRUE, &len); - if (dst) { - save_chunk (f, dst, len, L"LOG ", 1); - xfree(dst); - } - - zfile_fwrite (endhunk, 1, 8, f); - - write_log (L"Save of '%s' complete\n", filename); - zfile_fclose (f); - savestate_state = 0; - return 1; + for (i = 0; i < 4; i++) { + dst = save_ide (i, &len); + if (dst) { + save_chunk (f, dst, len, L"IDE ", 0); + xfree (dst); + } + } + + /* add fake END tag, makes it easy to strip CONF and LOG hunks */ + /* move this if you want to use CONF or LOG hunks when restoring state */ + zfile_fwrite (endhunk, 1, 8, f); + + dst = save_configuration (&len); + if (dst) { + save_chunk (f, dst, len, L"CONF", comp); + xfree(dst); + } + dst = save_log (TRUE, &len); + if (dst) { + save_chunk (f, dst, len, L"LOG ", comp); + xfree (dst); + } + + zfile_fwrite (endhunk, 1, 8, f); + + write_log (L"Save of '%s' complete\n", filename); + zfile_fclose (f); + savestate_state = 0; + return 1; } void savestate_quick (int slot, int save) { - int i, len = _tcslen (savestate_fname); - i = len - 1; - while (i >= 0 && savestate_fname[i] != '_') - i--; - if (i < len - 6 || i <= 0) { /* "_?.uss" */ + int i, len = _tcslen (savestate_fname); i = len - 1; - while (i >= 0 && savestate_fname[i] != '.') - i--; - if (i <= 0) { - write_log (L"savestate name skipped '%s'\n", savestate_fname); - return; + while (i >= 0 && savestate_fname[i] != '_') + i--; + if (i < len - 6 || i <= 0) { /* "_?.uss" */ + i = len - 1; + while (i >= 0 && savestate_fname[i] != '.') + i--; + if (i <= 0) { + write_log (L"savestate name skipped '%s'\n", savestate_fname); + return; + } } - } - _tcscpy (savestate_fname + i, L".uss"); - if (slot > 0) - _stprintf (savestate_fname + i, L"_%d.uss", slot); - if (save) { - write_log (L"saving '%s'\n", savestate_fname); - savestate_docompress = 1; - save_state (savestate_fname, L""); - } else { - if (!zfile_exists (savestate_fname)) { - write_log (L"staterestore, file '%s' not found\n", savestate_fname); - return; + _tcscpy (savestate_fname + i, L".uss"); + if (slot > 0) + _stprintf (savestate_fname + i, L"_%d.uss", slot); + if (save) { + write_log (L"saving '%s'\n", savestate_fname); + savestate_docompress = 1; + save_state (savestate_fname, L""); + } else { + if (!zfile_exists (savestate_fname)) { + write_log (L"staterestore, file '%s' not found\n", savestate_fname); + return; + } + savestate_state = STATE_DORESTORE; + write_log (L"staterestore starting '%s'\n", savestate_fname); } - savestate_state = STATE_DORESTORE; - write_log (L"staterestore starting '%s'\n", savestate_fname); - } } static struct staterecord *canrewind (int pos) { - int i; - struct staterecord *st; + int i; + struct staterecord *st; - if (!replaybuffer) + if (!replaybuffer) + return 0; + i = replaycounter; + st = &staterecords[i]; + if (st->start) + return st; return 0; - i = replaycounter; - st = &staterecords[i]; - if (st->start) - return st; - return 0; } int savestate_dorewind (int pos) { - if (canrewind (pos)) { - savestate_state = STATE_DOREWIND; - return 1; - } - return 0; + if (canrewind (pos)) { + savestate_state = STATE_DOREWIND; + return 1; + } + return 0; } void savestate_listrewind (void) { - int i = replaycounter; - int cnt; - uae_u8 *p; - uae_u32 pc; - - cnt = 1; - for (;;) { - struct staterecord *st; - st = &staterecords[i]; - if (!st->start) - break; - p = st->cpu + 17 * 4; - pc = restore_u32_func (&p); - console_out_f (L"%d: PC=%08X %c\n", cnt, pc, regs.pc == pc ? '*' : ' '); - cnt++; - i--; - if (i < 0) - i += MAX_STATERECORDS; - } + int i = replaycounter; + int cnt; + uae_u8 *p; + uae_u32 pc; + + cnt = 1; + for (;;) { + struct staterecord *st; + st = &staterecords[i]; + if (!st->start) + break; + p = st->cpu + 17 * 4; + pc = restore_u32_func (&p); + console_out_f (L"%d: PC=%08X %c\n", cnt, pc, regs.pc == pc ? '*' : ' '); + cnt++; + i--; + if (i < 0) + i += MAX_STATERECORDS; + } } void savestate_rewind (void) { - int len, i, dummy; - uae_u8 *p, *p2; - struct staterecord *st; + int len, i, dummy; + uae_u8 *p, *p2; + struct staterecord *st; - st = canrewind (1); - if (!st) - return; - frameextra = timeframes % currprefs.statecapturerate; - p = st->start; - p2 = st->end; - write_log (L"rewinding from %d\n", replaycounter); - p = restore_cpu (p); + st = canrewind (1); + if (!st) + return; + frameextra = timeframes % currprefs.statecapturerate; + p = st->start; + p2 = st->end; + write_log (L"rewinding from %d\n", replaycounter); + p = restore_cpu (p); #ifdef FPUEMU - if (restore_u32_func (&p)) - p = restore_fpu (p); + if (restore_u32_func (&p)) + p = restore_fpu (p); #endif - for (i = 0; i < 4; i++) { - p = restore_disk (i, p); - } - p = restore_floppy (p); - p = restore_custom (p); - p = restore_blitter (p); - p = restore_custom_agacolors (p); - for (i = 0; i < 8; i++) { - p = restore_custom_sprite (i, p); - } - for (i = 0; i < 4; i++) { - p = restore_audio (i, p); - } - p = restore_cia (0, p); - p = restore_cia (1, p); + for (i = 0; i < 4; i++) { + p = restore_disk (i, p); + } + p = restore_floppy (p); + p = restore_custom (p); + p = restore_blitter (p); + p = restore_custom_agacolors (p); + for (i = 0; i < 8; i++) { + p = restore_custom_sprite (i, p); + } + for (i = 0; i < 4; i++) { + p = restore_audio (i, p); + } + p = restore_cia (0, p); + p = restore_cia (1, p); #ifdef AUTOCONFIG - p = restore_expansion (p); + p = restore_expansion (p); #endif - len = restore_u32_func (&p); - memcpy (chipmemory, p, currprefs.chipmem_size > len ? len : currprefs.chipmem_size); - p += len; - len = restore_u32_func (&p); - memcpy (save_bram (&dummy), p, currprefs.bogomem_size > len ? len : currprefs.bogomem_size); - p += len; + len = restore_u32_func (&p); + memcpy (chipmemory, p, currprefs.chipmem_size > len ? len : currprefs.chipmem_size); + p += len; + len = restore_u32_func (&p); + memcpy (save_bram (&dummy), p, currprefs.bogomem_size > len ? len : currprefs.bogomem_size); + p += len; #ifdef AUTOCONFIG - len = restore_u32_func (&p); - memcpy (save_fram (&dummy), p, currprefs.fastmem_size > len ? len : currprefs.fastmem_size); - p += len; - len = restore_u32_func (&p); - memcpy (save_zram (&dummy, 0), p, currprefs.z3fastmem_size > len ? len : currprefs.z3fastmem_size); - p += len; + len = restore_u32_func (&p); + memcpy (save_fram (&dummy), p, currprefs.fastmem_size > len ? len : currprefs.fastmem_size); + p += len; + len = restore_u32_func (&p); + memcpy (save_zram (&dummy, 0), p, currprefs.z3fastmem_size > len ? len : currprefs.z3fastmem_size); + p += len; #endif #ifdef ACTION_REPLAY - if (restore_u32_func (&p)) - p = restore_action_replay (p); + if (restore_u32_func (&p)) + p = restore_action_replay (p); #endif - p += 4; - if (p != p2) { - gui_message (L"reload failure, address mismatch %p != %p", p, p2); - uae_reset (0); - return; - } - st->start = st->next = 0; - replaycounter--; - if (replaycounter < 0) - replaycounter += MAX_STATERECORDS; + p += 4; + if (p != p2) { + gui_message (L"reload failure, address mismatch %p != %p", p, p2); + uae_reset (0); + return; + } + st->start = st->next = 0; + replaycounter--; + if (replaycounter < 0) + replaycounter += MAX_STATERECORDS; } #define BS 10000 static int bufcheck (uae_u8 **pp, int len) { - uae_u8 *p = *pp; - if (p + len + BS >= replaybuffer + replaybuffersize) { - //write_log (L"capture buffer wrap-around\n"); - return 1; - } - return 0; + uae_u8 *p = *pp; + if (p + len + BS >= replaybuffer + replaybuffersize) { + //write_log (L"capture buffer wrap-around\n"); + return 1; + } + return 0; } void savestate_capture (int force) { - uae_u8 *p, *p2, *p3, *dst; - int i, len, tlen, retrycnt; - struct staterecord *st, *stn; + uae_u8 *p, *p2, *p3, *dst; + int i, len, tlen, retrycnt; + struct staterecord *st, *stn; #ifdef FILESYS - if (nr_units ()) - return; + if (nr_units ()) + return; #endif - if (!replaybuffer) - return; - if (!force && (!currprefs.statecapture || !currprefs.statecapturerate || ((timeframes + frameextra) % currprefs.statecapturerate))) - return; + if (!replaybuffer) + return; + if (!force && (!currprefs.statecapture || !currprefs.statecapturerate || ((timeframes + frameextra) % currprefs.statecapturerate))) + return; - retrycnt = 0; + retrycnt = 0; retry2: - st = &staterecords[replaycounter]; - if (st->next == 0) { - replaycounter = 0; st = &staterecords[replaycounter]; - st->next = replaybuffer; - } - stn = &staterecords[(replaycounter + 1) & (MAX_STATERECORDS - 1)]; - p = p2 = st->next; - tlen = 0; - if (bufcheck (&p, 0)) - goto retry; - stn->cpu = p; - save_cpu (&len, p); - tlen += len; - p += len; -#ifdef FPUEMU - if (bufcheck (&p, 0)) - goto retry; - p3 = p; - save_u32_func (&p, 0); - tlen += 4; - if (save_fpu (&len, p)) { - save_u32_func (&p3, 1); + if (st->next == 0) { + replaycounter = 0; + st = &staterecords[replaycounter]; + st->next = replaybuffer; + } + stn = &staterecords[(replaycounter + 1) & (MAX_STATERECORDS - 1)]; + p = p2 = st->next; + tlen = 0; + if (bufcheck (&p, 0)) + goto retry; + stn->cpu = p; + save_cpu (&len, p); tlen += len; p += len; - } +#ifdef FPUEMU + if (bufcheck (&p, 0)) + goto retry; + p3 = p; + save_u32_func (&p, 0); + tlen += 4; + if (save_fpu (&len, p)) { + save_u32_func (&p3, 1); + tlen += len; + p += len; + } #endif - for (i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { + if (bufcheck (&p, 0)) + goto retry; + save_disk (i, &len, p); + tlen += len; + p += len; + } if (bufcheck (&p, 0)) - goto retry; - save_disk (i, &len, p); + goto retry; + save_floppy (&len, p); tlen += len; p += len; - } - if (bufcheck (&p, 0)) - goto retry; - save_floppy (&len, p); - tlen += len; - p += len; - if (bufcheck (&p, 0)) - goto retry; - save_custom (&len, p, 0); - tlen += len; - p += len; - if (bufcheck (&p, 0)) - goto retry; - save_blitter (&len, p); - tlen += len; - p += len; - if (bufcheck (&p, 0)) - goto retry; - save_custom_agacolors (&len, p); - tlen += len; - p += len; - for (i = 0; i < 8; i++) { if (bufcheck (&p, 0)) - goto retry; - save_custom_sprite (i, &len, p); + goto retry; + save_custom (&len, p, 0); tlen += len; p += len; - } - for (i = 0; i < 4; i++) { if (bufcheck (&p, 0)) - goto retry; - save_audio (i, &len, p); + goto retry; + save_blitter (&len, p); + tlen += len; + p += len; + if (bufcheck (&p, 0)) + goto retry; + save_custom_agacolors (&len, p); + tlen += len; + p += len; + for (i = 0; i < 8; i++) { + if (bufcheck (&p, 0)) + goto retry; + save_custom_sprite (i, &len, p); + tlen += len; + p += len; + } + for (i = 0; i < 4; i++) { + if (bufcheck (&p, 0)) + goto retry; + save_audio (i, &len, p); + tlen += len; + p += len; + } + if (bufcheck (&p, 0)) + goto retry; + save_cia (0, &len, p); + tlen += len; + p += len; + if (bufcheck (&p, 0)) + goto retry; + save_cia (1, &len, p); tlen += len; p += len; - } - if (bufcheck (&p, 0)) - goto retry; - save_cia (0, &len, p); - tlen += len; - p += len; - if (bufcheck (&p, 0)) - goto retry; - save_cia (1, &len, p); - tlen += len; - p += len; #ifdef AUTOCONFIG - if (bufcheck (&p, 0)) - goto retry; - save_expansion (&len, p); - tlen += len; - p += len; + if (bufcheck (&p, 0)) + goto retry; + save_expansion (&len, p); + tlen += len; + p += len; #endif - dst = save_cram (&len); - if (bufcheck (&p, len)) - goto retry; - save_u32_func (&p, len); - memcpy (p, dst, len); - tlen += len + 4; - p += len; - dst = save_bram (&len); - if (bufcheck (&p, len)) - goto retry; - save_u32_func (&p, len); - memcpy (p, dst, len); - tlen += len + 4; - p += len; + dst = save_cram (&len); + if (bufcheck (&p, len)) + goto retry; + save_u32_func (&p, len); + memcpy (p, dst, len); + tlen += len + 4; + p += len; + dst = save_bram (&len); + if (bufcheck (&p, len)) + goto retry; + save_u32_func (&p, len); + memcpy (p, dst, len); + tlen += len + 4; + p += len; #ifdef AUTOCONFIG - dst = save_fram (&len); - if (bufcheck (&p, len)) - goto retry; - save_u32_func (&p, len); - memcpy (p, dst, len); - tlen += len + 4; - p += len; - dst = save_zram (&len, 0); - if (bufcheck (&p, len)) - goto retry; - save_u32_func (&p, len); - memcpy (p, dst, len); - tlen += len + 4; - p += len; + dst = save_fram (&len); + if (bufcheck (&p, len)) + goto retry; + save_u32_func (&p, len); + memcpy (p, dst, len); + tlen += len + 4; + p += len; + dst = save_zram (&len, 0); + if (bufcheck (&p, len)) + goto retry; + save_u32_func (&p, len); + memcpy (p, dst, len); + tlen += len + 4; + p += len; #endif #ifdef ACTION_REPLAY - if (bufcheck (&p, 0)) - goto retry; - p3 = p; - save_u32_func (&p, 0); - tlen += 4; - if (save_action_replay (&len, p)) { - save_u32_func (&p3, 1); - tlen += len; - p += len; - } + if (bufcheck (&p, 0)) + goto retry; + p3 = p; + save_u32_func (&p, 0); + tlen += 4; + if (save_action_replay (&len, p)) { + save_u32_func (&p3, 1); + tlen += len; + p += len; + } #endif - save_u32_func (&p, tlen); - stn->next = p; - stn->start = p2; - stn->end = p; - replaylastreloaded = -1; - replaycounter++; - replaycounter &= (MAX_STATERECORDS - 1); - i = (replaycounter + 1) & (MAX_STATERECORDS - 1); - staterecords[i].next = staterecords[i].start = 0; - i = replaycounter - 1; - while (i != replaycounter) { - if (i < 0) - i += MAX_STATERECORDS; - st = &staterecords[i]; - if (p2 <= st->start && p >= st->end) { - st->start = st->next = 0; - break; + save_u32_func (&p, tlen); + stn->next = p; + stn->start = p2; + stn->end = p; + replaylastreloaded = -1; + replaycounter++; + replaycounter &= (MAX_STATERECORDS - 1); + i = (replaycounter + 1) & (MAX_STATERECORDS - 1); + staterecords[i].next = staterecords[i].start = 0; + i = replaycounter - 1; + while (i != replaycounter) { + if (i < 0) + i += MAX_STATERECORDS; + st = &staterecords[i]; + if (p2 <= st->start && p >= st->end) { + st->start = st->next = 0; + break; + } + i--; } - i--; - } - //write_log (L"state capture %d (%d bytes)\n", replaycounter, p - p2); - return; -retry: - staterecords[replaycounter].next = replaybuffer; - retrycnt++; - if (retrycnt > 1) { - write_log (L"can't save, too small capture buffer\n"); + //write_log (L"state capture %d (%d bytes)\n", replaycounter, p - p2); return; - } - goto retry2; +retry: + staterecords[replaycounter].next = replaybuffer; + retrycnt++; + if (retrycnt > 1) { + write_log (L"can't save, too small capture buffer\n"); + return; + } + goto retry2; } void savestate_free (void) { - xfree (replaybuffer); - replaybuffer = 0; + xfree (replaybuffer); + replaybuffer = 0; } void savestate_init (void) { - savestate_free (); - memset (staterecords, 0, sizeof (staterecords)); - replaycounter = 0; - replaylastreloaded = -1; - frameextra = 0; - if (currprefs.statecapture && currprefs.statecapturebuffersize && currprefs.statecapturerate) { - replaybuffersize = currprefs.statecapturebuffersize; - replaybuffer = xmalloc (replaybuffersize); - } + savestate_free (); + memset (staterecords, 0, sizeof (staterecords)); + replaycounter = 0; + replaylastreloaded = -1; + frameextra = 0; + if (currprefs.statecapture && currprefs.statecapturebuffersize && currprefs.statecapturerate) { + replaybuffersize = currprefs.statecapturebuffersize; + replaybuffer = xmalloc (replaybuffersize); + } } /* @@ -1217,271 +1217,271 @@ version 0.8 HUNK HEADER (beginning of every hunk) - hunk name (4 ascii-characters) - hunk size (including header) - hunk flags +hunk name (4 ascii-characters) +hunk size (including header) +hunk flags - bit 0 = chunk contents are compressed with zlib (maybe RAM chunks only?) +bit 0 = chunk contents are compressed with zlib (maybe RAM chunks only?) HEADER - "ASF " (AmigaStateFile) +"ASF " (AmigaStateFile) - statefile version - emulator name ("uae", "fellow" etc..) - emulator version string (example: "0.8.15") - free user writable comment string +statefile version +emulator name ("uae", "fellow" etc..) +emulator version string (example: "0.8.15") +free user writable comment string CPU - "CPU " +"CPU " - CPU model 4 (68000,68010,68020,68030,68040,68060) - CPU typeflags bit 0=EC-model or not, bit 31 = clock rate included - D0-D7 8*4=32 - A0-A6 7*4=32 - PC 4 - unused 4 - 68000 prefetch (IRC) 2 - 68000 prefetch (IR) 2 - USP 4 - ISP 4 - SR/CCR 2 - flags 4 (bit 0=CPU was HALTed) +CPU model 4 (68000,68010,68020,68030,68040,68060) +CPU typeflags bit 0=EC-model or not, bit 31 = clock rate included +D0-D7 8*4=32 +A0-A6 7*4=32 +PC 4 +unused 4 +68000 prefetch (IRC) 2 +68000 prefetch (IR) 2 +USP 4 +ISP 4 +SR/CCR 2 +flags 4 (bit 0=CPU was HALTed) - CPU specific registers +CPU specific registers - 68000: SR/CCR is last saved register - 68010: save also DFC,SFC and VBR - 68020: all 68010 registers and CAAR,CACR and MSP - etc.. +68000: SR/CCR is last saved register +68010: save also DFC,SFC and VBR +68020: all 68010 registers and CAAR,CACR and MSP +etc.. - 68010+: +68010+: - DFC 4 - SFC 4 - VBR 4 +DFC 4 +SFC 4 +VBR 4 - 68020+: +68020+: - CAAR 4 - CACR 4 - MSP 4 +CAAR 4 +CACR 4 +MSP 4 - 68030+: +68030+: - AC0 4 - AC1 4 - ACUSR 2 - TT0 4 - TT1 4 +AC0 4 +AC1 4 +ACUSR 2 +TT0 4 +TT1 4 - 68040+: +68040+: - ITT0 4 - ITT1 4 - DTT0 4 - DTT1 4 - TCR 4 - URP 4 - SRP 4 +ITT0 4 +ITT1 4 +DTT0 4 +DTT1 4 +TCR 4 +URP 4 +SRP 4 - 68060: +68060: - BUSCR 4 - PCR 4 +BUSCR 4 +PCR 4 - All: +All: - Clock in KHz 4 (only if bit 31 in flags) - 4 (spare, only if bit 31 in flags) +Clock in KHz 4 (only if bit 31 in flags) +4 (spare, only if bit 31 in flags) FPU (only if used) - "FPU " +"FPU " - FPU model 4 (68881/68882/68040/68060) - FPU typeflags 4 (bit 31 = clock rate included) - FP0-FP7 4+4+2 (80 bits) - FPCR 4 - FPSR 4 - FPIAR 4 +FPU model 4 (68881/68882/68040/68060) +FPU typeflags 4 (bit 31 = clock rate included) +FP0-FP7 4+4+2 (80 bits) +FPCR 4 +FPSR 4 +FPIAR 4 - Clock in KHz 4 (only if bit 31 in flags) - 4 (spare, only if bit 31 in flags) +Clock in KHz 4 (only if bit 31 in flags) +4 (spare, only if bit 31 in flags) MMU (when and if MMU is supported in future..) - "MMU " +"MMU " - MMU model 4 (68040) - flags 4 (none defined yet) +MMU model 4 (68040) +flags 4 (none defined yet) CUSTOM CHIPS - "CHIP" +"CHIP" - chipset flags 4 OCS=0,ECSAGNUS=1,ECSDENISE=2,AGA=4 - ECSAGNUS and ECSDENISE can be combined +chipset flags 4 OCS=0,ECSAGNUS=1,ECSDENISE=2,AGA=4 +ECSAGNUS and ECSDENISE can be combined - DFF000-DFF1FF 352 (0x120 - 0x17f and 0x0a0 - 0xdf excluded) +DFF000-DFF1FF 352 (0x120 - 0x17f and 0x0a0 - 0xdf excluded) - sprite registers (0x120 - 0x17f) saved with SPRx chunks - audio registers (0x0a0 - 0xdf) saved with AUDx chunks +sprite registers (0x120 - 0x17f) saved with SPRx chunks +audio registers (0x0a0 - 0xdf) saved with AUDx chunks AGA COLORS - "AGAC" +"AGAC" - AGA color 8 banks * 32 registers * - registers LONG (XRGB) = 1024 +AGA color 8 banks * 32 registers * +registers LONG (XRGB) = 1024 SPRITE - "SPR0" - "SPR7" +"SPR0" - "SPR7" - SPRxPT 4 - SPRxPOS 2 - SPRxCTL 2 - SPRxDATA 2 - SPRxDATB 2 - AGA sprite DATA/DATB 3 * 2 * 2 - sprite "armed" status 1 +SPRxPT 4 +SPRxPOS 2 +SPRxCTL 2 +SPRxDATA 2 +SPRxDATB 2 +AGA sprite DATA/DATB 3 * 2 * 2 +sprite "armed" status 1 - sprites maybe armed in non-DMA mode - use bit 0 only, other bits are reserved +sprites maybe armed in non-DMA mode +use bit 0 only, other bits are reserved AUDIO - "AUD0" "AUD1" "AUD2" "AUD3" - - audio state 1 - machine mode - AUDxVOL 1 - irq? 1 - data_written? 1 - internal AUDxLEN 2 - AUDxLEN 2 - internal AUDxPER 2 - AUDxPER 2 - internal AUDxLC 4 - AUDxLC 4 - evtime? 4 +"AUD0" "AUD1" "AUD2" "AUD3" + +audio state 1 +machine mode +AUDxVOL 1 +irq? 1 +data_written? 1 +internal AUDxLEN 2 +AUDxLEN 2 +internal AUDxPER 2 +AUDxPER 2 +internal AUDxLC 4 +AUDxLC 4 +evtime? 4 BLITTER - "BLIT" +"BLIT" - internal blitter state +internal blitter state - flags 4 - bit 0=blitter active - bit 1=fill carry bit - internal ahold 4 - internal bhold 4 - internal hsize 2 - internal vsize 2 +flags 4 +bit 0=blitter active +bit 1=fill carry bit +internal ahold 4 +internal bhold 4 +internal hsize 2 +internal vsize 2 CIA - "CIAA" and "CIAB" +"CIAA" and "CIAB" - BFE001-BFEF01 16*1 (CIAA) - BFD000-BFDF00 16*1 (CIAB) +BFE001-BFEF01 16*1 (CIAA) +BFD000-BFDF00 16*1 (CIAB) - internal registers +internal registers - IRQ mask (ICR) 1 BYTE - timer latches 2 timers * 2 BYTES (LO/HI) - latched tod 3 BYTES (LO/MED/HI) - alarm 3 BYTES (LO/MED/HI) - flags 1 BYTE - bit 0=tod latched (read) - bit 1=tod stopped (write) - div10 counter 1 BYTE +IRQ mask (ICR) 1 BYTE +timer latches 2 timers * 2 BYTES (LO/HI) +latched tod 3 BYTES (LO/MED/HI) +alarm 3 BYTES (LO/MED/HI) +flags 1 BYTE +bit 0=tod latched (read) +bit 1=tod stopped (write) +div10 counter 1 BYTE FLOPPY DRIVES - "DSK0" "DSK1" "DSK2" "DSK3" +"DSK0" "DSK1" "DSK2" "DSK3" - drive state +drive state - drive ID-word 4 - state 1 (bit 0: motor on, bit 1: drive disabled, bit 2: current id bit) - rw-head track 1 - dskready 1 - id-mode 1 (ID mode bit number 0-31) - floppy information +drive ID-word 4 +state 1 (bit 0: motor on, bit 1: drive disabled, bit 2: current id bit) +rw-head track 1 +dskready 1 +id-mode 1 (ID mode bit number 0-31) +floppy information - bits from 4 - beginning of track - CRC of disk-image 4 (used during restore to check if image - is correct) - disk-image null-terminated - file name +bits from 4 +beginning of track +CRC of disk-image 4 (used during restore to check if image +is correct) +disk-image null-terminated +file name INTERNAL FLOPPY CONTROLLER STATUS - "DISK" +"DISK" - current DMA word 2 - DMA word bit offset 1 - WORDSYNC found 1 (no=0,yes=1) - hpos of next bit 1 - DSKLENGTH status 0=off,1=written once,2=written twice - unused 2 +current DMA word 2 +DMA word bit offset 1 +WORDSYNC found 1 (no=0,yes=1) +hpos of next bit 1 +DSKLENGTH status 0=off,1=written once,2=written twice +unused 2 RAM SPACE - "xRAM" (CRAM = chip, BRAM = bogo, FRAM = fast, ZRAM = Z3, P96 = RTG RAM, A3K1/A3K2 = MB RAM) +"xRAM" (CRAM = chip, BRAM = bogo, FRAM = fast, ZRAM = Z3, P96 = RTG RAM, A3K1/A3K2 = MB RAM) - start address 4 ("bank"=chip/slow/fast etc..) - of RAM "bank" - RAM "bank" size 4 - RAM flags 4 (bit 0 = zlib compressed) - RAM "bank" contents +start address 4 ("bank"=chip/slow/fast etc..) +of RAM "bank" +RAM "bank" size 4 +RAM flags 4 (bit 0 = zlib compressed) +RAM "bank" contents ROM SPACE - "ROM " +"ROM " - ROM start 4 - address - size of ROM 4 - ROM type 4 KICK=0 - ROM flags 4 - ROM version 2 - ROM revision 2 - ROM CRC 4 see below - ROM-image ID-string null terminated, see below - path to rom image - ROM contents (Not mandatory, use hunk size to check if - this hunk contains ROM data or not) +ROM start 4 +address +size of ROM 4 +ROM type 4 KICK=0 +ROM flags 4 +ROM version 2 +ROM revision 2 +ROM CRC 4 see below +ROM-image ID-string null terminated, see below +path to rom image +ROM contents (Not mandatory, use hunk size to check if +this hunk contains ROM data or not) - Kickstart ROM: - ID-string is "Kickstart x.x" - ROM version: version in high word and revision in low word - Kickstart ROM version and revision can be found from ROM start - + 12 (version) and +14 (revision) +Kickstart ROM: +ID-string is "Kickstart x.x" +ROM version: version in high word and revision in low word +Kickstart ROM version and revision can be found from ROM start ++ 12 (version) and +14 (revision) - ROM version and CRC is only meant for emulator to automatically - find correct image from its ROM-directory during state restore. +ROM version and CRC is only meant for emulator to automatically +find correct image from its ROM-directory during state restore. - Usually saving ROM contents is not good idea. +Usually saving ROM contents is not good idea. ACTION REPLAY - "ACTR" +"ACTR" - Model (1,2,3) 4 - path to rom image - RAM space (depends on model) - ROM CRC 4 +Model (1,2,3) 4 +path to rom image +RAM space (depends on model) +ROM CRC 4 END - hunk "END " ends, remember hunk size 8! +hunk "END " ends, remember hunk size 8! EMULATOR SPECIFIC HUNKS diff --git a/scsi.c b/scsi.c index 636e4500..2518ca26 100644 --- a/scsi.c +++ b/scsi.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * SCSI emulation (not uaescsi.device) - * - * Copyright 2007 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* SCSI emulation (not uaescsi.device) +* +* Copyright 2007 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -21,138 +21,138 @@ static int nonecmd[] = { 0x00, 0x35, -1 }; int scsi_data_dir(struct scsi_data *sd) { - int i; - uae_u8 cmd; + int i; + uae_u8 cmd; - cmd = sd->cmd[0]; - for (i = 0; outcmd[i] >= 0; i++) { - if (cmd == outcmd[i]) { - return 1; + cmd = sd->cmd[0]; + for (i = 0; outcmd[i] >= 0; i++) { + if (cmd == outcmd[i]) { + return 1; + } } - } - for (i = 0; incmd[i] >= 0; i++) { - if (cmd == incmd[i]) { - return -1; + for (i = 0; incmd[i] >= 0; i++) { + if (cmd == incmd[i]) { + return -1; + } } - } - for (i = 0; nonecmd[i] >= 0; i++) { - if (cmd == nonecmd[i]) { - return 0; + for (i = 0; nonecmd[i] >= 0; i++) { + if (cmd == nonecmd[i]) { + return 0; + } } - } - write_log (L"SCSI command %02X, no direction specified (IN?)!\n", sd->cmd[0]); - return -2; + write_log (L"SCSI command %02X, no direction specified (IN?)!\n", sd->cmd[0]); + return -2; } void scsi_emulate_cmd(struct scsi_data *sd) { - sd->status = 0; - if (sd->cmd[0] == 0x03) { /* REQUEST SENSE */ - int len = sd->buffer[4]; - memset (sd->buffer, 0, len); - memcpy (sd->buffer, sd->sense, sd->sense_len > len ? len : sd->sense_len); - sd->data_len = len; - } else if (sd->nativescsiunit < 0) { - sd->status = scsi_emulate(&sd->hfd->hfd, sd->hfd, - sd->cmd, sd->len, sd->buffer, &sd->data_len, sd->reply, &sd->reply_len, sd->sense, &sd->sense_len); - if (sd->status == 0) { - if (sd->reply_len > 0) { - memset(sd->buffer, 0, 256); - memcpy(sd->buffer, sd->reply, sd->reply_len); - } - } - } else { - struct amigascsi as; + sd->status = 0; + if (sd->cmd[0] == 0x03) { /* REQUEST SENSE */ + int len = sd->buffer[4]; + memset (sd->buffer, 0, len); + memcpy (sd->buffer, sd->sense, sd->sense_len > len ? len : sd->sense_len); + sd->data_len = len; + } else if (sd->nativescsiunit < 0) { + sd->status = scsi_emulate(&sd->hfd->hfd, sd->hfd, + sd->cmd, sd->len, sd->buffer, &sd->data_len, sd->reply, &sd->reply_len, sd->sense, &sd->sense_len); + if (sd->status == 0) { + if (sd->reply_len > 0) { + memset(sd->buffer, 0, 256); + memcpy(sd->buffer, sd->reply, sd->reply_len); + } + } + } else { + struct amigascsi as; - memset(sd->sense, 0, 256); - memset(&as, 0, sizeof as); - memcpy (&as.cmd, sd->cmd, sd->len); - as.flags = 2 | 1; - if (sd->direction > 0) - as.flags &= ~1; - as.sense_len = 32; - as.cmd_len = sd->len; - as.data = sd->buffer; - as.len = sd->direction < 0 ? DEVICE_SCSI_BUFSIZE : sd->data_len; - sys_command_scsi_direct_native(sd->nativescsiunit, &as); - sd->status = as.status; - sd->data_len = as.len; - if (sd->status) { - sd->direction = 0; - sd->data_len = 0; - memcpy(sd->sense, as.sensedata, as.sense_len); + memset(sd->sense, 0, 256); + memset(&as, 0, sizeof as); + memcpy (&as.cmd, sd->cmd, sd->len); + as.flags = 2 | 1; + if (sd->direction > 0) + as.flags &= ~1; + as.sense_len = 32; + as.cmd_len = sd->len; + as.data = sd->buffer; + as.len = sd->direction < 0 ? DEVICE_SCSI_BUFSIZE : sd->data_len; + sys_command_scsi_direct_native(sd->nativescsiunit, &as); + sd->status = as.status; + sd->data_len = as.len; + if (sd->status) { + sd->direction = 0; + sd->data_len = 0; + memcpy(sd->sense, as.sensedata, as.sense_len); + } } - } - sd->offset = 0; + sd->offset = 0; } struct scsi_data *scsi_alloc(int id, struct hd_hardfiledata *hfd) { - struct scsi_data *sd = (struct scsi_data*)xcalloc(sizeof (struct scsi_data), 1); - sd->hfd = hfd; - sd->id = id; - sd->nativescsiunit = -1; - return sd; + struct scsi_data *sd = (struct scsi_data*)xcalloc(sizeof (struct scsi_data), 1); + sd->hfd = hfd; + sd->id = id; + sd->nativescsiunit = -1; + return sd; } struct scsi_data *scsi_alloc_native(int id, int nativeunit) { - struct scsi_data *sd; - if (!sys_command_open (DF_SCSI, nativeunit)) { - write_log (L"SCSI: native scsi unit %d failed to open\n", nativeunit); - return NULL; - } - sd = (struct scsi_data*)xcalloc(sizeof (struct scsi_data), 1); - sd->id = id; - sd->nativescsiunit = nativeunit; - return sd; + struct scsi_data *sd; + if (!sys_command_open (DF_SCSI, nativeunit)) { + write_log (L"SCSI: native scsi unit %d failed to open\n", nativeunit); + return NULL; + } + sd = (struct scsi_data*)xcalloc(sizeof (struct scsi_data), 1); + sd->id = id; + sd->nativescsiunit = nativeunit; + return sd; } void scsi_reset(void) { - //device_func_init (DEVICE_TYPE_SCSI); + //device_func_init (DEVICE_TYPE_SCSI); } void scsi_free(struct scsi_data *sd) { - if (!sd) - return; - if (sd->nativescsiunit >= 0) { - sys_command_close (DF_SCSI, sd->nativescsiunit); - } - xfree(sd); + if (!sd) + return; + if (sd->nativescsiunit >= 0) { + sys_command_close (DF_SCSI, sd->nativescsiunit); + } + xfree(sd); } void scsi_start_transfer(struct scsi_data *sd, int len) { - sd->len = len; - sd->offset = 0; + sd->len = len; + sd->offset = 0; } int scsi_send_data(struct scsi_data *sd, uae_u8 b) { - if (sd->direction) { - if (sd->offset >= SCSI_DATA_BUFFER_SIZE) { - write_log (L"SCSI data buffer overflow!\n"); - return 0; - } - sd->buffer[sd->offset++] = b; - } else { - if (sd->offset >= 16) { - write_log (L"SCSI command buffer overflow!\n"); - return 0; + if (sd->direction) { + if (sd->offset >= SCSI_DATA_BUFFER_SIZE) { + write_log (L"SCSI data buffer overflow!\n"); + return 0; + } + sd->buffer[sd->offset++] = b; + } else { + if (sd->offset >= 16) { + write_log (L"SCSI command buffer overflow!\n"); + return 0; + } + sd->cmd[sd->offset++] = b; } - sd->cmd[sd->offset++] = b; - } - if (sd->offset == sd->len) - return 1; - return 0; + if (sd->offset == sd->len) + return 1; + return 0; } int scsi_receive_data(struct scsi_data *sd, uae_u8 *b) { - *b = sd->buffer[sd->offset++]; - if (sd->offset == sd->len) - return 1; - return 0; + *b = sd->buffer[sd->offset++]; + if (sd->offset == sd->len) + return 1; + return 0; } diff --git a/scsiemul.c b/scsiemul.c index 8047c67a..a424f96e 100644 --- a/scsiemul.c +++ b/scsiemul.c @@ -1,14 +1,14 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * scsi.device emulation - * - * Copyright 1995 Bernd Schmidt - * Copyright 1999 Patrick Ohly - * Copyright 2001 Brian King - * Copyright 2002 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* scsi.device emulation +* +* Copyright 1995 Bernd Schmidt +* Copyright 1999 Patrick Ohly +* Copyright 2001 Brian King +* Copyright 2002 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -43,33 +43,33 @@ #define ASYNC_REQUEST_CHANGEINT 10 struct devstruct { - int unitnum, aunit; - int opencnt; - int changenum; - int allow_scsi; - int allow_ioctl; - int drivetype; - int iscd; - volatile uaecptr d_request[MAX_ASYNC_REQUESTS]; - volatile int d_request_type[MAX_ASYNC_REQUESTS]; - volatile uae_u32 d_request_data[MAX_ASYNC_REQUESTS]; - struct device_info di; - uaecptr changeint; - - smp_comm_pipe requests; - int thread_running; - uae_sem_t sync_sem; + int unitnum, aunit; + int opencnt; + int changenum; + int allow_scsi; + int allow_ioctl; + int drivetype; + int iscd; + volatile uaecptr d_request[MAX_ASYNC_REQUESTS]; + volatile int d_request_type[MAX_ASYNC_REQUESTS]; + volatile uae_u32 d_request_data[MAX_ASYNC_REQUESTS]; + struct device_info di; + uaecptr changeint; + + smp_comm_pipe requests; + int thread_running; + uae_sem_t sync_sem; }; struct priv_devstruct { - int inuse; - int unit; - int mode; - int scsi; - int ioctl; - int noscsi; - int type; - int flags; /* OpenDevice() */ + int inuse; + int unit; + int mode; + int scsi; + int ioctl; + int noscsi; + int type; + int flags; /* OpenDevice() */ }; static struct devstruct devst[MAX_TOTAL_DEVICES]; @@ -79,566 +79,566 @@ static uae_sem_t change_sem; static struct device_info *devinfo (int mode, int unitnum, struct device_info *di) { - return sys_command_info (mode, unitnum, di); + return sys_command_info (mode, unitnum, di); } static void io_log (const TCHAR *msg, uaecptr request) { - if (log_scsi) - write_log (L"%s: %08X %d %08X %d %d io_actual=%d io_error=%d\n", - msg, request, get_word (request + 28), get_long (request + 40), - get_long (request + 36), get_long (request + 44), - get_long (request + 32), get_byte (request + 31)); + if (log_scsi) + write_log (L"%s: %08X %d %08X %d %d io_actual=%d io_error=%d\n", + msg, request, get_word (request + 28), get_long (request + 40), + get_long (request + 36), get_long (request + 44), + get_long (request + 32), get_byte (request + 31)); } static struct devstruct *getdevstruct (int unit) { - int i; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (unit >= 0 && devst[i].aunit == unit) return &devst[i]; - } - return 0; + int i; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (unit >= 0 && devst[i].aunit == unit) return &devst[i]; + } + return 0; } static struct priv_devstruct *getpdevstruct (uaecptr request) { - int i = get_long (request + 24); - if (i < 0 || i >= MAX_OPEN_DEVICES || pdevst[i].inuse == 0) { - write_log (L"uaescsi.device: corrupt iorequest %08X %d\n", request, i); - return 0; - } - return &pdevst[i]; + int i = get_long (request + 24); + if (i < 0 || i >= MAX_OPEN_DEVICES || pdevst[i].inuse == 0) { + write_log (L"uaescsi.device: corrupt iorequest %08X %d\n", request, i); + return 0; + } + return &pdevst[i]; } static TCHAR *getdevname (int type) { - switch (type) { + switch (type) { case UAEDEV_SCSI_ID: - return UAEDEV_SCSI; + return UAEDEV_SCSI; case UAEDEV_DISK_ID: - return UAEDEV_DISK; + return UAEDEV_DISK; default: - return L"NULL"; - } + return L"NULL"; + } } static void *dev_thread (void *devs); static int start_thread (struct devstruct *dev) { - if (dev->thread_running) - return 1; - init_comm_pipe (&dev->requests, 100, 1); - uae_sem_init (&dev->sync_sem, 0, 0); - uae_start_thread (L"uaescsi", dev_thread, dev, NULL); - uae_sem_wait (&dev->sync_sem); - return dev->thread_running; + if (dev->thread_running) + return 1; + init_comm_pipe (&dev->requests, 100, 1); + uae_sem_init (&dev->sync_sem, 0, 0); + uae_start_thread (L"uaescsi", dev_thread, dev, NULL); + uae_sem_wait (&dev->sync_sem); + return dev->thread_running; } static void dev_close_3 (struct devstruct *dev, struct priv_devstruct *pdev) { - if (!dev->opencnt) return; - dev->opencnt--; - if (!dev->opencnt) { - if (pdev->scsi) - sys_command_close (DF_SCSI, dev->unitnum); - if (pdev->ioctl) - sys_command_close (DF_IOCTL, dev->unitnum); - pdev->inuse = 0; - write_comm_pipe_u32 (&dev->requests, 0, 1); - } + if (!dev->opencnt) return; + dev->opencnt--; + if (!dev->opencnt) { + if (pdev->scsi) + sys_command_close (DF_SCSI, dev->unitnum); + if (pdev->ioctl) + sys_command_close (DF_IOCTL, dev->unitnum); + pdev->inuse = 0; + write_comm_pipe_u32 (&dev->requests, 0, 1); + } } static uae_u32 REGPARAM2 dev_close_2 (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; - - if (!pdev) - return 0; - dev = getdevstruct (pdev->unit); - if (log_scsi) - write_log (L"%s:%d close, req=%08X\n", getdevname (pdev->type), pdev->unit, request); - if (!dev) + uae_u32 request = m68k_areg (regs, 1); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; + + if (!pdev) + return 0; + dev = getdevstruct (pdev->unit); + if (log_scsi) + write_log (L"%s:%d close, req=%08X\n", getdevname (pdev->type), pdev->unit, request); + if (!dev) + return 0; + dev_close_3 (dev, pdev); + put_long (request + 24, 0); + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); return 0; - dev_close_3 (dev, pdev); - put_long (request + 24, 0); - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); - return 0; } static uae_u32 REGPARAM2 dev_close (TrapContext *context) { - return dev_close_2 (context); + return dev_close_2 (context); } static uae_u32 REGPARAM2 diskdev_close (TrapContext *context) { - return dev_close_2 (context); + return dev_close_2 (context); } static int openfail (uaecptr ioreq, int error) { - put_long (ioreq + 20, -1); - put_byte (ioreq + 31, error); - return (uae_u32)-1; + put_long (ioreq + 20, -1); + put_byte (ioreq + 31, error); + return (uae_u32)-1; } static uae_u32 REGPARAM2 dev_open_2 (TrapContext *context, int type) { - uaecptr ioreq = m68k_areg (regs, 1); - uae_u32 unit = m68k_dreg (regs, 0); - uae_u32 flags = m68k_dreg (regs, 1); - struct devstruct *dev = getdevstruct (unit); - struct priv_devstruct *pdev = 0; - int i; - - if (log_scsi) - write_log (L"opening %s:%d ioreq=%08X\n", getdevname (type), unit, ioreq); - if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) - return openfail (ioreq, IOERR_BADLENGTH); - if (!dev) - return openfail (ioreq, 32); /* badunitnum */ - if (!dev->opencnt) { - for (i = 0; i < MAX_OPEN_DEVICES; i++) { - pdev = &pdevst[i]; - if (pdev->inuse == 0) break; - } - if (type == UAEDEV_SCSI_ID && sys_command_open (DF_SCSI, dev->unitnum)) { - pdev->scsi = 1; - pdev->mode = DF_SCSI; - } - if (type == UAEDEV_DISK_ID && sys_command_open (DF_IOCTL, dev->unitnum)) { - pdev->ioctl = 1; - pdev->mode = DF_IOCTL; - } - if (!pdev->scsi && !pdev->ioctl) - return openfail (ioreq, IOERR_OPENFAIL); - pdev->type = type; - pdev->unit = unit; - pdev->flags = flags; - pdev->inuse = 1; - put_long (ioreq + 24, pdev - pdevst); - start_thread (dev); - } else { - for (i = 0; i < MAX_OPEN_DEVICES; i++) { - pdev = &pdevst[i]; - if (pdev->inuse && pdev->unit == unit) break; + uaecptr ioreq = m68k_areg (regs, 1); + uae_u32 unit = m68k_dreg (regs, 0); + uae_u32 flags = m68k_dreg (regs, 1); + struct devstruct *dev = getdevstruct (unit); + struct priv_devstruct *pdev = 0; + int i; + + if (log_scsi) + write_log (L"opening %s:%d ioreq=%08X\n", getdevname (type), unit, ioreq); + if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) + return openfail (ioreq, IOERR_BADLENGTH); + if (!dev) + return openfail (ioreq, 32); /* badunitnum */ + if (!dev->opencnt) { + for (i = 0; i < MAX_OPEN_DEVICES; i++) { + pdev = &pdevst[i]; + if (pdev->inuse == 0) break; + } + if (type == UAEDEV_SCSI_ID && sys_command_open (DF_SCSI, dev->unitnum)) { + pdev->scsi = 1; + pdev->mode = DF_SCSI; + } + if (type == UAEDEV_DISK_ID && sys_command_open (DF_IOCTL, dev->unitnum)) { + pdev->ioctl = 1; + pdev->mode = DF_IOCTL; + } + if (!pdev->scsi && !pdev->ioctl) + return openfail (ioreq, IOERR_OPENFAIL); + pdev->type = type; + pdev->unit = unit; + pdev->flags = flags; + pdev->inuse = 1; + put_long (ioreq + 24, pdev - pdevst); + start_thread (dev); + } else { + for (i = 0; i < MAX_OPEN_DEVICES; i++) { + pdev = &pdevst[i]; + if (pdev->inuse && pdev->unit == unit) break; + } + if (i == MAX_OPEN_DEVICES) + return openfail (ioreq, IOERR_OPENFAIL); + put_long (ioreq + 24, pdev - pdevst); } - if (i == MAX_OPEN_DEVICES) - return openfail (ioreq, IOERR_OPENFAIL); - put_long (ioreq + 24, pdev - pdevst); - } - dev->opencnt++; - - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); - put_byte (ioreq + 31, 0); - put_byte (ioreq + 8, 7); - return 0; + dev->opencnt++; + + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); + put_byte (ioreq + 31, 0); + put_byte (ioreq + 8, 7); + return 0; } static uae_u32 REGPARAM2 dev_open (TrapContext *context) { - return dev_open_2 (context, UAEDEV_SCSI_ID); + return dev_open_2 (context, UAEDEV_SCSI_ID); } static uae_u32 REGPARAM2 diskdev_open (TrapContext *context) { - return dev_open_2 (context, UAEDEV_DISK_ID); + return dev_open_2 (context, UAEDEV_DISK_ID); } static uae_u32 REGPARAM2 dev_expunge (TrapContext *context) { - return 0; + return 0; } static uae_u32 REGPARAM2 diskdev_expunge (TrapContext *context) { - return 0; + return 0; } static int is_async_request (struct devstruct *dev, uaecptr request) { - int i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (dev->d_request[i] == request) return 1; - i++; - } - return 0; + int i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (dev->d_request[i] == request) return 1; + i++; + } + return 0; } void scsi_do_disk_change (int device_id, int insert) { - int i, j; - - uae_sem_wait (&change_sem); - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - struct devstruct *dev = &devst[i]; - if (dev->di.id == device_id) { - if (dev->aunit >= 0) { - struct priv_devstruct *pdev = &pdevst[dev->aunit]; - devinfo (pdev->mode, dev->unitnum, &dev->di); - } - dev->changenum++; - j = 0; - while (j < MAX_ASYNC_REQUESTS) { - if (dev->d_request_type[j] == ASYNC_REQUEST_CHANGEINT) { - uae_Cause (dev->d_request_data[j]); + int i, j; + + uae_sem_wait (&change_sem); + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + struct devstruct *dev = &devst[i]; + if (dev->di.id == device_id) { + if (dev->aunit >= 0) { + struct priv_devstruct *pdev = &pdevst[dev->aunit]; + devinfo (pdev->mode, dev->unitnum, &dev->di); + } + dev->changenum++; + j = 0; + while (j < MAX_ASYNC_REQUESTS) { + if (dev->d_request_type[j] == ASYNC_REQUEST_CHANGEINT) { + uae_Cause (dev->d_request_data[j]); + } + j++; + } + if (dev->changeint) + uae_Cause (dev->changeint); } - j++; - } - if (dev->changeint) - uae_Cause (dev->changeint); } - } - uae_sem_post (&change_sem); + uae_sem_post (&change_sem); } static int add_async_request (struct devstruct *dev, uaecptr request, int type, uae_u32 data) { - int i; - - if (log_scsi) - write_log (L"async request %08x (%d) added\n", request, type); - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (dev->d_request[i] == request) { - dev->d_request_type[i] = type; - dev->d_request_data[i] = data; - return 0; + int i; + + if (log_scsi) + write_log (L"async request %08x (%d) added\n", request, type); + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (dev->d_request[i] == request) { + dev->d_request_type[i] = type; + dev->d_request_data[i] = data; + return 0; + } + i++; } - i++; - } - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (dev->d_request[i] == 0) { - dev->d_request[i] = request; - dev->d_request_type[i] = type; - dev->d_request_data[i] = data; - return 0; + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (dev->d_request[i] == 0) { + dev->d_request[i] = request; + dev->d_request_type[i] = type; + dev->d_request_data[i] = data; + return 0; + } + i++; } - i++; - } - return -1; + return -1; } static int release_async_request (struct devstruct *dev, uaecptr request) { - int i = 0; - - if (log_scsi) - write_log (L"async request %p removed\n", request); - while (i < MAX_ASYNC_REQUESTS) { - if (dev->d_request[i] == request) { - int type = dev->d_request_type[i]; - dev->d_request[i] = 0; - dev->d_request_data[i] = 0; - dev->d_request_type[i] = 0; - return type; + int i = 0; + + if (log_scsi) + write_log (L"async request %p removed\n", request); + while (i < MAX_ASYNC_REQUESTS) { + if (dev->d_request[i] == request) { + int type = dev->d_request_type[i]; + dev->d_request[i] = 0; + dev->d_request_data[i] = 0; + dev->d_request_type[i] = 0; + return type; + } + i++; } - i++; - } - return -1; + return -1; } static void abort_async (struct devstruct *dev, uaecptr request, int errcode, int type) { - int i; - i = 0; - while (i < MAX_ASYNC_REQUESTS) { - if (dev->d_request[i] == request && dev->d_request_type[i] == ASYNC_REQUEST_TEMP) { - /* ASYNC_REQUEST_TEMP = request is processing */ - sleep_millis (10); - i = 0; - continue; + int i; + i = 0; + while (i < MAX_ASYNC_REQUESTS) { + if (dev->d_request[i] == request && dev->d_request_type[i] == ASYNC_REQUEST_TEMP) { + /* ASYNC_REQUEST_TEMP = request is processing */ + sleep_millis (10); + i = 0; + continue; + } + i++; } - i++; - } - i = release_async_request (dev, request); - if (i >= 0 && log_scsi) - write_log (L"asyncronous request=%08X aborted, error=%d\n", request, errcode); + i = release_async_request (dev, request); + if (i >= 0 && log_scsi) + write_log (L"asyncronous request=%08X aborted, error=%d\n", request, errcode); } static int command_read (int mode, struct devstruct *dev, uaecptr data, uae_u64 offset, uae_u32 length, uae_u32 *io_actual) { - int blocksize = dev->di.bytespersector; - uae_u8 *temp; - - length /= blocksize; - offset /= blocksize; - while (length > 0) { - temp = sys_command_read (mode, dev->unitnum, offset); - if (!temp) - return 20; - memcpyha_safe (data, temp, blocksize); - data += blocksize; - offset++; - length--; - } - return 0; + int blocksize = dev->di.bytespersector; + uae_u8 *temp; + + length /= blocksize; + offset /= blocksize; + while (length > 0) { + temp = sys_command_read (mode, dev->unitnum, offset); + if (!temp) + return 20; + memcpyha_safe (data, temp, blocksize); + data += blocksize; + offset++; + length--; + } + return 0; } static int command_write (int mode, struct devstruct *dev, uaecptr data, uae_u64 offset, uae_u32 length, uae_u32 *io_actual) { - uae_u32 blocksize = dev->di.bytespersector; - struct device_scsi_info dsi; - - if (!sys_command_scsi_info(mode, dev->unitnum, &dsi)) - return 20; - length /= blocksize; - offset /= blocksize; - while (length > 0) { - int err; - memcpyah_safe (dsi.buffer, data, blocksize); - err = sys_command_write (mode, dev->unitnum, offset); - if (!err) - return 20; - if (err < 0) - return 28; // write protected - data += blocksize; - offset++; - length--; - } - return 0; + uae_u32 blocksize = dev->di.bytespersector; + struct device_scsi_info dsi; + + if (!sys_command_scsi_info(mode, dev->unitnum, &dsi)) + return 20; + length /= blocksize; + offset /= blocksize; + while (length > 0) { + int err; + memcpyah_safe (dsi.buffer, data, blocksize); + err = sys_command_write (mode, dev->unitnum, offset); + if (!err) + return 20; + if (err < 0) + return 28; // write protected + data += blocksize; + offset++; + length--; + } + return 0; } static int command_cd_read (int mode, struct devstruct *dev, uaecptr data, uae_u64 offset, uae_u32 length, uae_u32 *io_actual) { - uae_u8 *temp; - uae_u32 len, sector, startoffset; - - *io_actual = 0; - if (dev->di.bytespersector == 0) - dev->di.bytespersector = 2048; - startoffset = offset % dev->di.bytespersector; - offset -= startoffset; - sector = offset / dev->di.bytespersector; - while (length > 0) { - temp = sys_command_cd_read (mode, dev->unitnum, sector); - if (!temp) - return 20; - if (startoffset > 0) { - len = dev->di.bytespersector - startoffset; - if (len > length) len = length; - memcpyha_safe (data, temp + startoffset, len); - length -= len; - data += len; - startoffset = 0; - *io_actual += len; - } else if (length >= dev->di.bytespersector) { - len = dev->di.bytespersector; - memcpyha_safe (data, temp, len); - length -= len; - data += len; - *io_actual += len; - } else { - memcpyha_safe (data, temp, length); - *io_actual += length; - length = 0; + uae_u8 *temp; + uae_u32 len, sector, startoffset; + + *io_actual = 0; + if (dev->di.bytespersector == 0) + dev->di.bytespersector = 2048; + startoffset = offset % dev->di.bytespersector; + offset -= startoffset; + sector = offset / dev->di.bytespersector; + while (length > 0) { + temp = sys_command_cd_read (mode, dev->unitnum, sector); + if (!temp) + return 20; + if (startoffset > 0) { + len = dev->di.bytespersector - startoffset; + if (len > length) len = length; + memcpyha_safe (data, temp + startoffset, len); + length -= len; + data += len; + startoffset = 0; + *io_actual += len; + } else if (length >= dev->di.bytespersector) { + len = dev->di.bytespersector; + memcpyha_safe (data, temp, len); + length -= len; + data += len; + *io_actual += len; + } else { + memcpyha_safe (data, temp, length); + *io_actual += length; + length = 0; + } + sector++; } - sector++; - } - return 0; + return 0; } static int dev_do_io (struct devstruct *dev, uaecptr request) { - uae_u32 command; - uae_u32 io_data = get_long (request + 40); // 0x28 - uae_u32 io_length = get_long (request + 36); // 0x24 - uae_u32 io_actual = get_long (request + 32); // 0x20 - uae_u32 io_offset = get_long (request + 44); // 0x2c - uae_u32 io_error = 0; - uae_u64 io_offset64; - int async = 0; - int bmask = dev->di.bytespersector - 1; - struct priv_devstruct *pdev = getpdevstruct (request); - - if (!pdev) - return 0; - command = get_word (request + 28); - - switch (command) - { + uae_u32 command; + uae_u32 io_data = get_long (request + 40); // 0x28 + uae_u32 io_length = get_long (request + 36); // 0x24 + uae_u32 io_actual = get_long (request + 32); // 0x20 + uae_u32 io_offset = get_long (request + 44); // 0x2c + uae_u32 io_error = 0; + uae_u64 io_offset64; + int async = 0; + int bmask = dev->di.bytespersector - 1; + struct priv_devstruct *pdev = getpdevstruct (request); + + if (!pdev) + return 0; + command = get_word (request + 28); + + switch (command) + { case CMD_READ: - //write_log (L"CMD_READ %08x %d %d %08x\n", io_data, io_offset, io_length, bmask); - if (!dev->di.media_inserted) - goto no_media; - if (dev->drivetype == INQ_ROMD) { - io_error = command_cd_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); - } else { - if ((io_offset & bmask) || bmask == 0 || io_data == 0) - goto bad_command; - if ((io_length & bmask) || io_length == 0) - goto bad_len; - io_error = command_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); - } - break; + //write_log (L"CMD_READ %08x %d %d %08x\n", io_data, io_offset, io_length, bmask); + if (!dev->di.media_inserted) + goto no_media; + if (dev->drivetype == INQ_ROMD) { + io_error = command_cd_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); + } else { + if ((io_offset & bmask) || bmask == 0 || io_data == 0) + goto bad_command; + if ((io_length & bmask) || io_length == 0) + goto bad_len; + io_error = command_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); + } + break; case TD_READ64: case NSCMD_TD_READ64: - if (!dev->di.media_inserted) - goto no_media; - io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); - if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) - goto bad_command; - if ((io_length & bmask) || io_length == 0) - goto bad_len; - if (dev->drivetype == INQ_ROMD) - io_error = command_cd_read (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); - else - io_error = command_read (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); - break; + if (!dev->di.media_inserted) + goto no_media; + io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); + if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) + goto bad_command; + if ((io_length & bmask) || io_length == 0) + goto bad_len; + if (dev->drivetype == INQ_ROMD) + io_error = command_cd_read (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); + else + io_error = command_read (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); + break; case CMD_WRITE: - if (!dev->di.media_inserted) - goto no_media; - if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { - io_error = 28; /* writeprotect */ - } else if ((io_offset & bmask) || bmask == 0 || io_data == 0) { - goto bad_command; - } else if ((io_length & bmask) || io_length == 0) { - goto bad_len; - } else { - io_error = command_write (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); - } - break; + if (!dev->di.media_inserted) + goto no_media; + if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { + io_error = 28; /* writeprotect */ + } else if ((io_offset & bmask) || bmask == 0 || io_data == 0) { + goto bad_command; + } else if ((io_length & bmask) || io_length == 0) { + goto bad_len; + } else { + io_error = command_write (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); + } + break; case TD_WRITE64: case NSCMD_TD_WRITE64: - if (!dev->di.media_inserted) - goto no_media; - io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); - if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { - io_error = 28; /* writeprotect */ - } else if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) { - goto bad_command; - } else if ((io_length & bmask) || io_length == 0) { - goto bad_len; - } else { - io_error = command_write (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); - } - break; + if (!dev->di.media_inserted) + goto no_media; + io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); + if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { + io_error = 28; /* writeprotect */ + } else if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) { + goto bad_command; + } else if ((io_length & bmask) || io_length == 0) { + goto bad_len; + } else { + io_error = command_write (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); + } + break; case CMD_FORMAT: - if (!dev->di.media_inserted) - goto no_media; - if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { - io_error = 28; /* writeprotect */ - } else if ((io_offset & bmask) || bmask == 0 || io_data == 0) { - goto bad_command; - } else if ((io_length & bmask) || io_length == 0) { - goto bad_len; - } else { - io_error = command_write (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); - } - break; + if (!dev->di.media_inserted) + goto no_media; + if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { + io_error = 28; /* writeprotect */ + } else if ((io_offset & bmask) || bmask == 0 || io_data == 0) { + goto bad_command; + } else if ((io_length & bmask) || io_length == 0) { + goto bad_len; + } else { + io_error = command_write (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); + } + break; case TD_FORMAT64: case NSCMD_TD_FORMAT64: - if (!dev->di.media_inserted) - goto no_media; - io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); - if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { - io_error = 28; /* writeprotect */ - } else if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) { - goto bad_command; - } else if ((io_length & bmask) || io_length == 0) { - goto bad_len; - } else { - io_error = command_write (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); - } - break; + if (!dev->di.media_inserted) + goto no_media; + io_offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32); + if (dev->di.write_protected || dev->drivetype == INQ_ROMD) { + io_error = 28; /* writeprotect */ + } else if ((io_offset64 & bmask) || bmask == 0 || io_data == 0) { + goto bad_command; + } else if ((io_length & bmask) || io_length == 0) { + goto bad_len; + } else { + io_error = command_write (pdev->mode, dev, io_data, io_offset64, io_length, &io_actual); + } + break; case CMD_UPDATE: case CMD_CLEAR: case CMD_FLUSH: case CMD_MOTOR: case CMD_SEEK: - io_actual = 0; - break; + io_actual = 0; + break; case CMD_REMOVE: - io_actual = dev->changeint; - dev->changeint = io_data; - break; + io_actual = dev->changeint; + dev->changeint = io_data; + break; case CMD_CHANGENUM: - io_actual = dev->changenum; - break; + io_actual = dev->changenum; + break; case CMD_CHANGESTATE: - io_actual = devinfo (pdev->mode, dev->unitnum, &dev->di)->media_inserted ? 0 : 1; - break; + io_actual = devinfo (pdev->mode, dev->unitnum, &dev->di)->media_inserted ? 0 : 1; + break; case CMD_PROTSTATUS: - io_actual = devinfo (pdev->mode, dev->unitnum, &dev->di)->write_protected ? -1 : 0; - break; + io_actual = devinfo (pdev->mode, dev->unitnum, &dev->di)->write_protected ? -1 : 0; + break; case CMD_GETDRIVETYPE: - io_actual = dev->drivetype; - break; + io_actual = dev->drivetype; + break; case CMD_GETNUMTRACKS: - if (!dev->di.media_inserted) - goto no_media; - io_actual = dev->di.cylinders; - break; + if (!dev->di.media_inserted) + goto no_media; + io_actual = dev->di.cylinders; + break; case CMD_GETGEOMETRY: - { - struct device_info *di; - di = devinfo (pdev->mode, dev->unitnum, &dev->di); - if (!di->media_inserted) - goto no_media; - 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 */ - io_actual = 30; - } - break; + { + struct device_info *di; + di = devinfo (pdev->mode, dev->unitnum, &dev->di); + if (!di->media_inserted) + goto no_media; + 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 */ + io_actual = 30; + } + break; case CMD_ADDCHANGEINT: - io_error = add_async_request (dev, request, ASYNC_REQUEST_CHANGEINT, io_data); - if (!io_error) - async = 1; - break; + io_error = add_async_request (dev, request, ASYNC_REQUEST_CHANGEINT, io_data); + if (!io_error) + async = 1; + break; case CMD_REMCHANGEINT: - release_async_request (dev, request); - break; + release_async_request (dev, request); + break; case HD_SCSICMD: - if (dev->allow_scsi && pdev->scsi) { - uae_u32 sdd = get_long (request + 40); - io_error = sys_command_scsi_direct (dev->unitnum, sdd); - if (log_scsi) - write_log (L"scsidev: did io: sdd %p request %p error %d\n", sdd, request, get_byte (request + 31)); - } else { - io_error = IOERR_NOCMD; - } - break; + if (dev->allow_scsi && pdev->scsi) { + uae_u32 sdd = get_long (request + 40); + io_error = sys_command_scsi_direct (dev->unitnum, sdd); + if (log_scsi) + write_log (L"scsidev: did io: sdd %p request %p error %d\n", sdd, request, get_byte (request + 31)); + } else { + io_error = IOERR_NOCMD; + } + break; case NSCMD_DEVICEQUERY: - put_long (io_data + 0, 0); - put_long (io_data + 4, 16); /* size */ - put_word (io_data + 8, NSDEVTYPE_TRACKDISK); - put_word (io_data + 10, 0); - put_long (io_data + 12, nscmd_cmd); - io_actual = 16; - break; + put_long (io_data + 0, 0); + put_long (io_data + 4, 16); /* size */ + put_word (io_data + 8, NSDEVTYPE_TRACKDISK); + put_word (io_data + 10, 0); + put_long (io_data + 12, nscmd_cmd); + io_actual = 16; + break; default: - io_error = IOERR_NOCMD; - break; - bad_len: - io_error = IOERR_BADLENGTH; - break; - bad_command: - io_error = IOERR_BADADDRESS; - break; - no_media: - io_error = TDERR_DiskChanged; - break; - } - put_long (request + 32, io_actual); - put_byte (request + 31, io_error); - io_log (L"dev_io",request); - return async; + io_error = IOERR_NOCMD; + break; +bad_len: + io_error = IOERR_BADLENGTH; + break; +bad_command: + io_error = IOERR_BADADDRESS; + break; +no_media: + io_error = TDERR_DiskChanged; + break; + } + put_long (request + 32, io_actual); + put_byte (request + 31, io_error); + io_log (L"dev_io",request); + return async; } static int dev_can_quick (uae_u32 command) { - switch (command) - { + switch (command) + { case CMD_RESET: case CMD_STOP: case CMD_START: @@ -646,432 +646,432 @@ static int dev_can_quick (uae_u32 command) case CMD_PROTSTATUS: case CMD_GETDRIVETYPE: case CMD_GETNUMTRACKS: - return 1; - } - return 0; + return 1; + } + return 0; } static int dev_canquick (struct devstruct *dev, uaecptr request) { - uae_u32 command = get_word (request + 28); - return dev_can_quick (command); + uae_u32 command = get_word (request + 28); + return dev_can_quick (command); } static uae_u32 REGPARAM2 dev_beginio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - uae_u8 flags = get_byte (request + 30); - int command = get_word (request + 28); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; - - put_byte (request + 8, NT_MESSAGE); - if (!pdev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - dev = getdevstruct (pdev->unit); - if (!dev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - put_byte (request+31, 0); - if ((flags & 1) && dev_canquick (dev, request)) { - if (dev_do_io (dev, request)) - write_log (L"device %s command %d bug with IO_QUICK\n", getdevname (pdev->type), command); - return get_byte (request + 31); - } else { - add_async_request (dev, request, ASYNC_REQUEST_TEMP, 0); - put_byte (request+30, get_byte (request + 30) & ~1); - write_comm_pipe_u32 (&dev->requests, request, 1); - return 0; - } + uae_u32 request = m68k_areg (regs, 1); + uae_u8 flags = get_byte (request + 30); + int command = get_word (request + 28); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; + + put_byte (request + 8, NT_MESSAGE); + if (!pdev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + dev = getdevstruct (pdev->unit); + if (!dev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + put_byte (request+31, 0); + if ((flags & 1) && dev_canquick (dev, request)) { + if (dev_do_io (dev, request)) + write_log (L"device %s command %d bug with IO_QUICK\n", getdevname (pdev->type), command); + return get_byte (request + 31); + } else { + add_async_request (dev, request, ASYNC_REQUEST_TEMP, 0); + put_byte (request+30, get_byte (request + 30) & ~1); + write_comm_pipe_u32 (&dev->requests, request, 1); + return 0; + } } static void *dev_thread (void *devs) { - struct devstruct *dev = (struct devstruct*)devs; - - uae_set_thread_priority (NULL, 1); - dev->thread_running = 1; - uae_sem_post (&dev->sync_sem); - for (;;) { - uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); - uae_sem_wait (&change_sem); - if (!request) { - dev->thread_running = 0; - uae_sem_post (&dev->sync_sem); - uae_sem_post (&change_sem); - return 0; - } else if (dev_do_io (dev, request) == 0) { - put_byte (request + 30, get_byte (request + 30) & ~1); - release_async_request (dev, request); - uae_ReplyMsg (request); - } else { - if (log_scsi) - write_log (L"%s:%d async request %08X\n", getdevname(0), dev->unitnum, request); + struct devstruct *dev = (struct devstruct*)devs; + + uae_set_thread_priority (NULL, 1); + dev->thread_running = 1; + uae_sem_post (&dev->sync_sem); + for (;;) { + uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); + uae_sem_wait (&change_sem); + if (!request) { + dev->thread_running = 0; + uae_sem_post (&dev->sync_sem); + uae_sem_post (&change_sem); + return 0; + } else if (dev_do_io (dev, request) == 0) { + put_byte (request + 30, get_byte (request + 30) & ~1); + release_async_request (dev, request); + uae_ReplyMsg (request); + } else { + if (log_scsi) + write_log (L"%s:%d async request %08X\n", getdevname(0), dev->unitnum, request); + } + uae_sem_post (&change_sem); } - uae_sem_post (&change_sem); - } - return 0; + return 0; } static uae_u32 REGPARAM2 dev_init_2 (TrapContext *context, int type) { - uae_u32 base = m68k_dreg (regs,0); - if (log_scsi) - write_log (L"%s init\n", getdevname (type)); - return base; + uae_u32 base = m68k_dreg (regs,0); + if (log_scsi) + write_log (L"%s init\n", getdevname (type)); + return base; } static uae_u32 REGPARAM2 dev_init (TrapContext *context) { - return dev_init_2 (context, UAEDEV_SCSI_ID); + return dev_init_2 (context, UAEDEV_SCSI_ID); } static uae_u32 REGPARAM2 diskdev_init (TrapContext *context) { - return dev_init_2 (context, UAEDEV_DISK_ID); + return dev_init_2 (context, UAEDEV_DISK_ID); } static uae_u32 REGPARAM2 dev_abortio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct priv_devstruct *pdev = getpdevstruct (request); - struct devstruct *dev; - - if (!pdev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - dev = getdevstruct (pdev->unit); - if (!dev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - put_byte (request + 31, IOERR_ABORTED); - if (log_scsi) - write_log (L"abortio %s unit=%d, request=%08X\n", getdevname (pdev->type), pdev->unit, request); - abort_async (dev, request, IOERR_ABORTED, 0); - return 0; + uae_u32 request = m68k_areg (regs, 1); + struct priv_devstruct *pdev = getpdevstruct (request); + struct devstruct *dev; + + if (!pdev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + dev = getdevstruct (pdev->unit); + if (!dev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + put_byte (request + 31, IOERR_ABORTED); + if (log_scsi) + write_log (L"abortio %s unit=%d, request=%08X\n", getdevname (pdev->type), pdev->unit, request); + abort_async (dev, request, IOERR_ABORTED, 0); + return 0; } #define BTL2UNIT(bus, target, lun) (2 * (bus) + (target) / 8) * 100 + (lun) * 10 + (target % 8) static void dev_reset (void) { - int i, j; - struct devstruct *dev; - struct device_info *discsi, discsi2; - int unitnum = 0; - - device_func_init (DEVICE_TYPE_SCSI); - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - dev = &devst[i]; - if (dev->opencnt > 0) { - for (j = 0; j < MAX_ASYNC_REQUESTS; j++) { - uaecptr request; - if (request = dev->d_request[i]) - abort_async (dev, request, 0, 0); - } - dev->opencnt = 1; - sys_command_close (DF_SCSI, dev->unitnum); - sys_command_close (DF_IOCTL, dev->unitnum); - } - memset (dev, 0, sizeof (struct devstruct)); - dev->unitnum = dev->aunit = -1; - } - for (i = 0; i < MAX_OPEN_DEVICES; i++) - memset (&pdevst[i], 0, sizeof (struct priv_devstruct)); - - i = j = 0; - while (i < MAX_TOTAL_DEVICES) { - dev = &devst[i]; - discsi = 0; - if (sys_command_open (DF_SCSI, j)) { - discsi = sys_command_info (DF_SCSI, j, &discsi2); - sys_command_close (DF_SCSI, j); + int i, j; + struct devstruct *dev; + struct device_info *discsi, discsi2; + int unitnum = 0; + + device_func_init (DEVICE_TYPE_SCSI); + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + dev = &devst[i]; + if (dev->opencnt > 0) { + for (j = 0; j < MAX_ASYNC_REQUESTS; j++) { + uaecptr request; + if (request = dev->d_request[i]) + abort_async (dev, request, 0, 0); + } + dev->opencnt = 1; + sys_command_close (DF_SCSI, dev->unitnum); + sys_command_close (DF_IOCTL, dev->unitnum); + } + memset (dev, 0, sizeof (struct devstruct)); + dev->unitnum = dev->aunit = -1; } - if (discsi) { - dev->unitnum = j; - dev->allow_scsi = 1; - dev->drivetype = discsi->type; - memcpy (&dev->di, discsi, sizeof (struct device_info)); - if (discsi->type == INQ_ROMD) - dev->iscd = 1; + for (i = 0; i < MAX_OPEN_DEVICES; i++) + memset (&pdevst[i], 0, sizeof (struct priv_devstruct)); + + i = j = 0; + while (i < MAX_TOTAL_DEVICES) { + dev = &devst[i]; + discsi = 0; + if (sys_command_open (DF_SCSI, j)) { + discsi = sys_command_info (DF_SCSI, j, &discsi2); + sys_command_close (DF_SCSI, j); + } + if (discsi) { + dev->unitnum = j; + dev->allow_scsi = 1; + dev->drivetype = discsi->type; + memcpy (&dev->di, discsi, sizeof (struct device_info)); + if (discsi->type == INQ_ROMD) + dev->iscd = 1; + } + i++; + j++; } - i++; - j++; - } - unitnum = 0; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - dev = &devst[i]; - if (dev->unitnum >= 0 && dev->iscd) { - dev->aunit = unitnum; - unitnum++; + unitnum = 0; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + dev = &devst[i]; + if (dev->unitnum >= 0 && dev->iscd) { + dev->aunit = unitnum; + unitnum++; + } } - } - if (unitnum == 0) - unitnum = 1; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - dev = &devst[i]; - if (dev->unitnum >= 0) { - if (!dev->iscd) { - dev->aunit = unitnum; - unitnum++; - } - write_log (L"%s:%d = '%s'\n", UAEDEV_SCSI, dev->aunit, dev->di.label); + if (unitnum == 0) + unitnum = 1; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + dev = &devst[i]; + if (dev->unitnum >= 0) { + if (!dev->iscd) { + dev->aunit = unitnum; + unitnum++; + } + write_log (L"%s:%d = '%s'\n", UAEDEV_SCSI, dev->aunit, dev->di.label); + } + dev->di.label[0] = 0; } - dev->di.label[0] = 0; - } } static uaecptr ROM_scsidev_resname = 0, - ROM_scsidev_resid = 0, - ROM_scsidev_init = 0; + ROM_scsidev_resid = 0, + ROM_scsidev_init = 0; static uaecptr ROM_diskdev_resname = 0, - ROM_diskdev_resid = 0, - ROM_diskdev_init = 0; + ROM_diskdev_resid = 0, + ROM_diskdev_init = 0; static uaecptr diskdev_startup (uaecptr resaddr) { - /* Build a struct Resident. This will set up and initialize - * the cd.device */ - if (log_scsi) - write_log (L"diskdev_startup(0x%x)\n", resaddr); - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, ROM_diskdev_resname); - put_long (resaddr + 0x12, ROM_diskdev_resid); - put_long (resaddr + 0x16, ROM_diskdev_init); - resaddr += 0x1A; - return resaddr; + /* Build a struct Resident. This will set up and initialize + * the cd.device */ + if (log_scsi) + write_log (L"diskdev_startup(0x%x)\n", resaddr); + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, ROM_diskdev_resname); + put_long (resaddr + 0x12, ROM_diskdev_resid); + put_long (resaddr + 0x16, ROM_diskdev_init); + resaddr += 0x1A; + return resaddr; } uaecptr scsidev_startup (uaecptr resaddr) { - if (currprefs.scsi != 1) + if (currprefs.scsi != 1) + return resaddr; + if (log_scsi) + write_log (L"scsidev_startup(0x%x)\n", resaddr); + /* Build a struct Resident. This will set up and initialize + * the uaescsi.device */ + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, ROM_scsidev_resname); + put_long (resaddr + 0x12, ROM_scsidev_resid); + put_long (resaddr + 0x16, ROM_scsidev_init); /* calls scsidev_init */ + resaddr += 0x1A; return resaddr; - if (log_scsi) - write_log (L"scsidev_startup(0x%x)\n", resaddr); - /* Build a struct Resident. This will set up and initialize - * the uaescsi.device */ - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, ROM_scsidev_resname); - put_long (resaddr + 0x12, ROM_scsidev_resid); - put_long (resaddr + 0x16, ROM_scsidev_init); /* calls scsidev_init */ - resaddr += 0x1A; - return resaddr; - return diskdev_startup (resaddr); + return diskdev_startup (resaddr); } static void diskdev_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, openfunc, closefunc, expungefunc; - uae_u32 beginiofunc, abortiofunc; - - if (currprefs.scsi != 1) - return; - if (log_scsi) - write_log (L"diskdev_install(): 0x%x\n", here ()); - - ROM_diskdev_resname = ds (UAEDEV_DISK); - ROM_diskdev_resid = ds (L"UAE disk.device 0.1"); - - /* initcode */ - initcode = here (); - calltrap (deftrap (diskdev_init)); dw (RTS); - - /* Open */ - openfunc = here (); - calltrap (deftrap (diskdev_open)); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap (diskdev_close)); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap (diskdev_expunge)); dw (RTS); - - /* BeginIO */ - beginiofunc = here (); - calltrap (deftrap (dev_beginio)); - dw (RTS); - - /* AbortIO */ - abortiofunc = here (); - calltrap (deftrap (dev_abortio)); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (openfunc); /* Open */ - dl (closefunc); /* Close */ - dl (expungefunc); /* Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - dl (beginiofunc); /* BeginIO */ - dl (abortiofunc); /* AbortIO */ - dl (0xFFFFFFFFul); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0300); /* NT_DEVICE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (ROM_diskdev_resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); /* 0.4 */ - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (0x0000); /* end of table already ??? */ - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (ROM_diskdev_resid); - dw (0x0000); /* end of table */ - - ROM_diskdev_init = here (); - dl (0x00000100); /* size of device base */ - dl (functable); - dl (datatable); - dl (initcode); + uae_u32 functable, datatable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; + + if (currprefs.scsi != 1) + return; + if (log_scsi) + write_log (L"diskdev_install(): 0x%x\n", here ()); + + ROM_diskdev_resname = ds (UAEDEV_DISK); + ROM_diskdev_resid = ds (L"UAE disk.device 0.1"); + + /* initcode */ + initcode = here (); + calltrap (deftrap (diskdev_init)); dw (RTS); + + /* Open */ + openfunc = here (); + calltrap (deftrap (diskdev_open)); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap (diskdev_close)); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap (diskdev_expunge)); dw (RTS); + + /* BeginIO */ + beginiofunc = here (); + calltrap (deftrap (dev_beginio)); + dw (RTS); + + /* AbortIO */ + abortiofunc = here (); + calltrap (deftrap (dev_abortio)); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (openfunc); /* Open */ + dl (closefunc); /* Close */ + dl (expungefunc); /* Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + dl (beginiofunc); /* BeginIO */ + dl (abortiofunc); /* AbortIO */ + dl (0xFFFFFFFFul); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0300); /* NT_DEVICE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (ROM_diskdev_resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); /* 0.4 */ + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (0x0000); /* end of table already ??? */ + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (ROM_diskdev_resid); + dw (0x0000); /* end of table */ + + ROM_diskdev_init = here (); + dl (0x00000100); /* size of device base */ + dl (functable); + dl (datatable); + dl (initcode); } void scsidev_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, openfunc, closefunc, expungefunc; - uae_u32 beginiofunc, abortiofunc; - - if (currprefs.scsi != 1) - return; - if (log_scsi) - write_log (L"scsidev_install(): 0x%x\n", here ()); - - ROM_scsidev_resname = ds (UAEDEV_SCSI); - ROM_scsidev_resid = ds (L"UAE scsi.device 0.2"); - - /* initcode */ - initcode = here (); - calltrap (deftrap (dev_init)); dw (RTS); - - /* Open */ - openfunc = here (); - calltrap (deftrap (dev_open)); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap (dev_close)); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap (dev_expunge)); dw (RTS); - - /* BeginIO */ - beginiofunc = here (); - calltrap (deftrap (dev_beginio)); - dw (RTS); - - /* AbortIO */ - abortiofunc = here (); - calltrap (deftrap (dev_abortio)); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (openfunc); /* Open */ - dl (closefunc); /* Close */ - dl (expungefunc); /* Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - dl (beginiofunc); /* BeginIO */ - dl (abortiofunc); /* AbortIO */ - dl (0xFFFFFFFFul); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0300); /* NT_DEVICE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (ROM_scsidev_resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); /* 0.4 */ - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (0x0000); - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (ROM_scsidev_resid); - dw (0x0000); /* end of table */ - - ROM_scsidev_init = here (); - dl (0x00000100); /* size of device base */ - dl (functable); - dl (datatable); - dl (initcode); - - nscmd_cmd = here (); - dw (NSCMD_DEVICEQUERY); - dw (CMD_RESET); - dw (CMD_READ); - dw (CMD_WRITE); - dw (CMD_UPDATE); - dw (CMD_CLEAR); - dw (CMD_START); - dw (CMD_STOP); - dw (CMD_FLUSH); - dw (CMD_MOTOR); - dw (CMD_SEEK); - dw (CMD_FORMAT); - dw (CMD_REMOVE); - dw (CMD_CHANGENUM); - dw (CMD_CHANGESTATE); - dw (CMD_PROTSTATUS); - dw (CMD_GETDRIVETYPE); - dw (CMD_GETGEOMETRY); - dw (CMD_ADDCHANGEINT); - dw (CMD_REMCHANGEINT); - dw (HD_SCSICMD); - dw (NSCMD_TD_READ64); - dw (NSCMD_TD_WRITE64); - dw (NSCMD_TD_SEEK64); - dw (NSCMD_TD_FORMAT64); - dw (0); - - diskdev_install (); + uae_u32 functable, datatable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; + + if (currprefs.scsi != 1) + return; + if (log_scsi) + write_log (L"scsidev_install(): 0x%x\n", here ()); + + ROM_scsidev_resname = ds (UAEDEV_SCSI); + ROM_scsidev_resid = ds (L"UAE scsi.device 0.2"); + + /* initcode */ + initcode = here (); + calltrap (deftrap (dev_init)); dw (RTS); + + /* Open */ + openfunc = here (); + calltrap (deftrap (dev_open)); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap (dev_close)); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap (dev_expunge)); dw (RTS); + + /* BeginIO */ + beginiofunc = here (); + calltrap (deftrap (dev_beginio)); + dw (RTS); + + /* AbortIO */ + abortiofunc = here (); + calltrap (deftrap (dev_abortio)); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (openfunc); /* Open */ + dl (closefunc); /* Close */ + dl (expungefunc); /* Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + dl (beginiofunc); /* BeginIO */ + dl (abortiofunc); /* AbortIO */ + dl (0xFFFFFFFFul); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0300); /* NT_DEVICE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (ROM_scsidev_resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); /* 0.4 */ + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (0x0000); + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (ROM_scsidev_resid); + dw (0x0000); /* end of table */ + + ROM_scsidev_init = here (); + dl (0x00000100); /* size of device base */ + dl (functable); + dl (datatable); + dl (initcode); + + nscmd_cmd = here (); + dw (NSCMD_DEVICEQUERY); + dw (CMD_RESET); + dw (CMD_READ); + dw (CMD_WRITE); + dw (CMD_UPDATE); + dw (CMD_CLEAR); + dw (CMD_START); + dw (CMD_STOP); + dw (CMD_FLUSH); + dw (CMD_MOTOR); + dw (CMD_SEEK); + dw (CMD_FORMAT); + dw (CMD_REMOVE); + dw (CMD_CHANGENUM); + dw (CMD_CHANGESTATE); + dw (CMD_PROTSTATUS); + dw (CMD_GETDRIVETYPE); + dw (CMD_GETGEOMETRY); + dw (CMD_ADDCHANGEINT); + dw (CMD_REMCHANGEINT); + dw (HD_SCSICMD); + dw (NSCMD_TD_READ64); + dw (NSCMD_TD_WRITE64); + dw (NSCMD_TD_SEEK64); + dw (NSCMD_TD_FORMAT64); + dw (0); + + diskdev_install (); } void scsidev_start_threads (void) { - if (currprefs.scsi != 1) /* quite useless.. */ - return; - if (log_scsi) - write_log (L"scsidev_start_threads()\n"); - uae_sem_init (&change_sem, 0, 1); + if (currprefs.scsi != 1) /* quite useless.. */ + return; + if (log_scsi) + write_log (L"scsidev_start_threads()\n"); + uae_sem_init (&change_sem, 0, 1); } void scsidev_reset (void) { - if (currprefs.scsi != 1) - return; - dev_reset (); + if (currprefs.scsi != 1) + return; + dev_reset (); } diff --git a/traps.c b/traps.c index 63981ae9..4b71bce2 100644 --- a/traps.c +++ b/traps.c @@ -1,14 +1,14 @@ - /* - * E-UAE - The portable Amiga Emulator - * - * Support for traps - * - * Copyright Richard Drummond 2005 - * - * Inspired by code from UAE: - * Copyright 1995, 1996 Bernd Schmidt - * Copyright 1996 Ed Hanway - */ +/* +* E-UAE - The portable Amiga Emulator +* +* Support for traps +* +* Copyright Richard Drummond 2005 +* +* Inspired by code from UAE: +* Copyright 1995, 1996 Bernd Schmidt +* Copyright 1996 Ed Hanway +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -22,51 +22,51 @@ #include "traps.h" /* - * Traps are the mechanism via which 68k code can call emulator code - * (and for that emulator code in turn to call 68k code). They are - * thus the basis for much of the cool stuff that E-UAE can do. - * - * Emulator traps take advantage of the illegal 68k opwords 0xA000 to - * 0xAFFF. Normally these would generate an A-line exception. However, - * when encountered in the RTAREA section of memory, these opwords - * instead invoke a corresponding emulator trap, allowing a host - * function to be called. - * - * Two types of emulator trap are available - a simple trap and an - * extended trap. A simple trap may not call 68k code; an extended - * trap can. - * - * Extended traps are rather complex beasts (to implement, not - * necessarily to use). This is because for the trap handler function - * to be able to call 68k code, we must somehow allow the emulator's - * 68k interpreter to resume execution of 68k code in the middle of - * the trap handler function. - * - * In UAE of old this used to be implemented via a stack-swap mechanism. - * While this worked, it was definitely in the realm of black magic and - * horribly non-portable, requiring assembly language glue specific to - * the host ABI and compiler to actually perform the swap. - * - * In this implementation, in essence we do something similar - but the - * new stack is provided by a new thread. No voodoo required, just a - * working thread layer. - * - * The complexity in this approach arises in synchronizing the trap - * threads with the emulator thread. This implementation errs on the side - * of paranoia when it comes to thread synchronization. Once all the - * bugs are knocked out of the bsdsocket emulation, a simpler scheme may - * suffice. - */ +* Traps are the mechanism via which 68k code can call emulator code +* (and for that emulator code in turn to call 68k code). They are +* thus the basis for much of the cool stuff that E-UAE can do. +* +* Emulator traps take advantage of the illegal 68k opwords 0xA000 to +* 0xAFFF. Normally these would generate an A-line exception. However, +* when encountered in the RTAREA section of memory, these opwords +* instead invoke a corresponding emulator trap, allowing a host +* function to be called. +* +* Two types of emulator trap are available - a simple trap and an +* extended trap. A simple trap may not call 68k code; an extended +* trap can. +* +* Extended traps are rather complex beasts (to implement, not +* necessarily to use). This is because for the trap handler function +* to be able to call 68k code, we must somehow allow the emulator's +* 68k interpreter to resume execution of 68k code in the middle of +* the trap handler function. +* +* In UAE of old this used to be implemented via a stack-swap mechanism. +* While this worked, it was definitely in the realm of black magic and +* horribly non-portable, requiring assembly language glue specific to +* the host ABI and compiler to actually perform the swap. +* +* In this implementation, in essence we do something similar - but the +* new stack is provided by a new thread. No voodoo required, just a +* working thread layer. +* +* The complexity in this approach arises in synchronizing the trap +* threads with the emulator thread. This implementation errs on the side +* of paranoia when it comes to thread synchronization. Once all the +* bugs are knocked out of the bsdsocket emulation, a simpler scheme may +* suffice. +*/ /* - * Record of a defined trap (that is, a trap allocated to a host function) - */ +* Record of a defined trap (that is, a trap allocated to a host function) +*/ struct Trap { - TrapHandler handler; /* Handler function to be invoked for this trap. */ - int flags; /* Trap attributes. */ - const TCHAR *name; /* For debugging purposes. */ - uaecptr addr; + TrapHandler handler; /* Handler function to be invoked for this trap. */ + int flags; /* Trap attributes. */ + const TCHAR *name; /* For debugging purposes. */ + uaecptr addr; }; #define MAX_TRAPS 4096 @@ -82,131 +82,131 @@ static void trap_HandleExtendedTrap (TrapHandler, int has_retval); uaecptr find_trap (const TCHAR *name) { - int i; - - for (i = 0; i < trap_count; i++) { - struct Trap *trap = &traps[i]; - if ((trap->flags & TRAPFLAG_UAERES) && trap->name && !_tcscmp (trap->name, name)) - return trap->addr; - } - return 0; + int i; + + for (i = 0; i < trap_count; i++) { + struct Trap *trap = &traps[i]; + if ((trap->flags & TRAPFLAG_UAERES) && trap->name && !_tcscmp (trap->name, name)) + return trap->addr; + } + return 0; } /* - * Define an emulator trap - * - * handler_func = host function that will be invoked to handle this trap - * flags = trap attributes - * name = name for debugging purposes - * - * returns trap number of defined trap - */ +* Define an emulator trap +* +* handler_func = host function that will be invoked to handle this trap +* flags = trap attributes +* name = name for debugging purposes +* +* returns trap number of defined trap +*/ unsigned int define_trap (TrapHandler handler_func, int flags, const TCHAR *name) { - if (trap_count == MAX_TRAPS) { - write_log (L"Ran out of emulator traps\n"); - abort (); - return -1; - } else { - int i; - unsigned int trap_num; - struct Trap *trap; - uaecptr addr = here (); + if (trap_count == MAX_TRAPS) { + write_log (L"Ran out of emulator traps\n"); + abort (); + return -1; + } else { + int i; + unsigned int trap_num; + struct Trap *trap; + uaecptr addr = here (); - for (i = 0; i < trap_count; i++) { - if (addr == traps[i].addr) - return i; - } + for (i = 0; i < trap_count; i++) { + if (addr == traps[i].addr) + return i; + } - trap_num = trap_count++; - trap = &traps[trap_num]; + trap_num = trap_count++; + trap = &traps[trap_num]; - trap->handler = handler_func; - trap->flags = flags; - trap->name = name; - trap->addr = addr; + trap->handler = handler_func; + trap->flags = flags; + trap->name = name; + trap->addr = addr; - return trap_num; - } + return trap_num; + } } /* - * This function is called by the 68k interpreter to handle an emulator trap. - * - * trap_num = number of trap to invoke - * regs = current 68k state - */ +* This function is called by the 68k interpreter to handle an emulator trap. +* +* trap_num = number of trap to invoke +* regs = current 68k state +*/ void REGPARAM2 m68k_handle_trap (unsigned int trap_num) { - struct Trap *trap = &traps[trap_num]; - uae_u32 retval = 0; - - int has_retval = (trap->flags & TRAPFLAG_NO_RETVAL) == 0; - int implicit_rts = (trap->flags & TRAPFLAG_DORET) != 0; - - if (trap->name && trap->name[0] != 0 && trace_traps) - write_log (L"TRAP: %s\n", trap->name); - - if (trap_num < trap_count) { - if (trap->flags & TRAPFLAG_EXTRA_STACK) { - /* Handle an extended trap. - * Note: the return value of this trap is passed back to 68k - * space via a separate, dedicated simple trap which the trap - * handler causes to be invoked when it is done. - */ - trap_HandleExtendedTrap (trap->handler, has_retval); - } else { - /* Handle simple trap */ - retval = (trap->handler) (NULL); - - if (has_retval) - m68k_dreg (regs, 0) = retval; - - if (implicit_rts) { - m68k_do_rts (); - fill_prefetch_slow (); - } - } - } else - write_log (L"Illegal emulator trap\n"); + struct Trap *trap = &traps[trap_num]; + uae_u32 retval = 0; + + int has_retval = (trap->flags & TRAPFLAG_NO_RETVAL) == 0; + int implicit_rts = (trap->flags & TRAPFLAG_DORET) != 0; + + if (trap->name && trap->name[0] != 0 && trace_traps) + write_log (L"TRAP: %s\n", trap->name); + + if (trap_num < trap_count) { + if (trap->flags & TRAPFLAG_EXTRA_STACK) { + /* Handle an extended trap. + * Note: the return value of this trap is passed back to 68k + * space via a separate, dedicated simple trap which the trap + * handler causes to be invoked when it is done. + */ + trap_HandleExtendedTrap (trap->handler, has_retval); + } else { + /* Handle simple trap */ + retval = (trap->handler) (NULL); + + if (has_retval) + m68k_dreg (regs, 0) = retval; + + if (implicit_rts) { + m68k_do_rts (); + fill_prefetch_slow (); + } + } + } else + write_log (L"Illegal emulator trap\n"); } /* - * Implementation of extended traps - */ +* Implementation of extended traps +*/ struct TrapContext { - /* Trap's working copy of 68k state. This is what the trap handler should - * access to get arguments from 68k space. */ - struct regstruct regs; - - /* Trap handler function that gets called on the trap context */ - TrapHandler trap_handler; - /* Should the handler return a value to 68k space in D0? */ - int trap_has_retval; - /* Return value from trap handler */ - uae_u32 trap_retval; - - /* Copy of 68k state at trap entry. */ - struct regstruct saved_regs; - - /* Thread which effects the trap context. */ - uae_thread_id thread; - /* For IPC between the main emulator. */ - uae_sem_t switch_to_emu_sem; - /* context and the trap context. */ - uae_sem_t switch_to_trap_sem; - - /* When calling a 68k function from a trap handler, this is set to the - * address of the function to call. */ - uaecptr call68k_func_addr; - /* And this gets set to the return value of the 68k call. */ - uae_u32 call68k_retval; + /* Trap's working copy of 68k state. This is what the trap handler should + * access to get arguments from 68k space. */ + struct regstruct regs; + + /* Trap handler function that gets called on the trap context */ + TrapHandler trap_handler; + /* Should the handler return a value to 68k space in D0? */ + int trap_has_retval; + /* Return value from trap handler */ + uae_u32 trap_retval; + + /* Copy of 68k state at trap entry. */ + struct regstruct saved_regs; + + /* Thread which effects the trap context. */ + uae_thread_id thread; + /* For IPC between the main emulator. */ + uae_sem_t switch_to_emu_sem; + /* context and the trap context. */ + uae_sem_t switch_to_trap_sem; + + /* When calling a 68k function from a trap handler, this is set to the + * address of the function to call. */ + uaecptr call68k_func_addr; + /* And this gets set to the return value of the 68k call. */ + uae_u32 call68k_retval; }; @@ -221,267 +221,267 @@ static TrapContext *current_context; /* - * Thread body for trap context - */ +* Thread body for trap context +*/ static void *trap_thread (void *arg) { - TrapContext *context = (TrapContext *) arg; + TrapContext *context = (TrapContext *) arg; - /* Wait until main thread is ready to switch to the - * this trap context. */ - uae_sem_wait (&context->switch_to_trap_sem); + /* Wait until main thread is ready to switch to the + * this trap context. */ + uae_sem_wait (&context->switch_to_trap_sem); - /* Execute trap handler function. */ - context->trap_retval = context->trap_handler (context); + /* Execute trap handler function. */ + context->trap_retval = context->trap_handler (context); - /* Trap handler is done - we still need to tidy up - * and make sure the handler's return value is propagated - * to the calling 68k thread. - * - * We do this by causing our exit handler to be executed on the 68k context. - */ + /* Trap handler is done - we still need to tidy up + * and make sure the handler's return value is propagated + * to the calling 68k thread. + * + * We do this by causing our exit handler to be executed on the 68k context. + */ - /* Enter critical section - only one trap at a time, please! */ - uae_sem_wait (&trap_mutex); + /* Enter critical section - only one trap at a time, please! */ + uae_sem_wait (&trap_mutex); - regs = context->saved_regs; - /* Don't allow an interrupt and thus potentially another - * trap to be invoked while we hold the above mutex. - * This is probably just being paranoid. */ - regs.intmask = 7; + regs = context->saved_regs; + /* Don't allow an interrupt and thus potentially another + * trap to be invoked while we hold the above mutex. + * This is probably just being paranoid. */ + regs.intmask = 7; - /* Set PC to address of the exit handler, so that it will be called - * when the 68k context resumes. */ - m68k_setpc (exit_trap_trapaddr); - current_context = context; + /* Set PC to address of the exit handler, so that it will be called + * when the 68k context resumes. */ + m68k_setpc (exit_trap_trapaddr); + current_context = context; - /* Switch back to 68k context */ - uae_sem_post (&context->switch_to_emu_sem); + /* Switch back to 68k context */ + uae_sem_post (&context->switch_to_emu_sem); - /* Good bye, cruel world... */ + /* Good bye, cruel world... */ - /* dummy return value */ - return 0; + /* dummy return value */ + return 0; } /* - * Set up extended trap context and call handler function - */ +* Set up extended trap context and call handler function +*/ static void trap_HandleExtendedTrap (TrapHandler handler_func, int has_retval) { - struct TrapContext *context = calloc (1, sizeof (TrapContext)); + struct TrapContext *context = calloc (1, sizeof (TrapContext)); - if (context) { - uae_sem_init (&context->switch_to_trap_sem, 0, 0); - uae_sem_init (&context->switch_to_emu_sem, 0, 0); + if (context) { + uae_sem_init (&context->switch_to_trap_sem, 0, 0); + uae_sem_init (&context->switch_to_emu_sem, 0, 0); - context->trap_handler = handler_func; - context->trap_has_retval = has_retval; + context->trap_handler = handler_func; + context->trap_has_retval = has_retval; - context->saved_regs = regs; + context->saved_regs = regs; - /* Start thread to handle new trap context. */ - uae_start_thread_fast (trap_thread, (void *)context, &context->thread); + /* Start thread to handle new trap context. */ + uae_start_thread_fast (trap_thread, (void *)context, &context->thread); - /* Switch to trap context to begin execution of - * trap handler function. - */ - uae_sem_post (&context->switch_to_trap_sem); + /* Switch to trap context to begin execution of + * trap handler function. + */ + uae_sem_post (&context->switch_to_trap_sem); - /* Wait for trap context to switch back to us. - * - * It'll do this when the trap handler is done - or when - * the handler wants to call 68k code. */ - uae_sem_wait (&context->switch_to_emu_sem); - } + /* Wait for trap context to switch back to us. + * + * It'll do this when the trap handler is done - or when + * the handler wants to call 68k code. */ + uae_sem_wait (&context->switch_to_emu_sem); + } } /* - * Call m68k function from an extended trap handler - * - * This function is to be called from the trap context. - */ +* Call m68k function from an extended trap handler +* +* This function is to be called from the trap context. +*/ static uae_u32 trap_Call68k (TrapContext *context, uaecptr func_addr) { - /* Enter critical section - only one trap at a time, please! */ - uae_sem_wait (&trap_mutex); - current_context = context; + /* Enter critical section - only one trap at a time, please! */ + uae_sem_wait (&trap_mutex); + current_context = context; - /* Don't allow an interrupt and thus potentially another - * trap to be invoked while we hold the above mutex. - * This is probably just being paranoid. */ - regs.intmask = 7; + /* Don't allow an interrupt and thus potentially another + * trap to be invoked while we hold the above mutex. + * This is probably just being paranoid. */ + regs.intmask = 7; - /* Set up function call address. */ - context->call68k_func_addr = func_addr; + /* Set up function call address. */ + context->call68k_func_addr = func_addr; - /* Set PC to address of 68k call trap, so that it will be - * executed when emulator context resumes. */ - m68k_setpc (m68k_call_trapaddr); - fill_prefetch_slow (); + /* Set PC to address of 68k call trap, so that it will be + * executed when emulator context resumes. */ + m68k_setpc (m68k_call_trapaddr); + fill_prefetch_slow (); - /* Switch to emulator context. */ - uae_sem_post (&context->switch_to_emu_sem); + /* Switch to emulator context. */ + uae_sem_post (&context->switch_to_emu_sem); - /* Wait for 68k call return handler to switch back to us. */ - uae_sem_wait (&context->switch_to_trap_sem); + /* Wait for 68k call return handler to switch back to us. */ + uae_sem_wait (&context->switch_to_trap_sem); - /* End critical section. */ - uae_sem_post (&trap_mutex); + /* End critical section. */ + uae_sem_post (&trap_mutex); - /* Get return value from 68k function called. */ - return context->call68k_retval; + /* Get return value from 68k function called. */ + return context->call68k_retval; } /* - * Handles the emulator's side of a 68k call (from an extended trap) - */ +* Handles the emulator's side of a 68k call (from an extended trap) +*/ static uae_u32 REGPARAM3 m68k_call_handler (TrapContext *dummy_ctx) { - TrapContext *context = current_context; + TrapContext *context = current_context; - uae_u32 sp; + uae_u32 sp; - sp = m68k_areg (regs, 7); + sp = m68k_areg (regs, 7); - /* Push address of trap context on 68k stack. This is - * so the return trap can find this context. */ - sp -= sizeof (void *); - put_pointer (sp, context); + /* Push address of trap context on 68k stack. This is + * so the return trap can find this context. */ + sp -= sizeof (void *); + put_pointer (sp, context); - /* Push addr to return handler trap on 68k stack. - * When the called m68k function does an RTS, the CPU will pull this - * address off the stack and so call the return handler. */ - sp -= 4; - put_long (sp, m68k_return_trapaddr); + /* Push addr to return handler trap on 68k stack. + * When the called m68k function does an RTS, the CPU will pull this + * address off the stack and so call the return handler. */ + sp -= 4; + put_long (sp, m68k_return_trapaddr); - m68k_areg (regs, 7) = sp; + m68k_areg (regs, 7) = sp; - /* Set PC to address of 68k function to call. */ - m68k_setpc (context->call68k_func_addr); - fill_prefetch_slow (); + /* Set PC to address of 68k function to call. */ + m68k_setpc (context->call68k_func_addr); + fill_prefetch_slow (); - /* End critical section: allow other traps run. */ - uae_sem_post (&trap_mutex); + /* End critical section: allow other traps run. */ + uae_sem_post (&trap_mutex); - /* Restore interrupts. */ - regs.intmask = context->saved_regs.intmask; + /* Restore interrupts. */ + regs.intmask = context->saved_regs.intmask; - /* Dummy return value. */ - return 0; + /* Dummy return value. */ + return 0; } /* - * Handles the return from a 68k call at the emulator's side. - */ +* Handles the return from a 68k call at the emulator's side. +*/ static uae_u32 REGPARAM3 m68k_return_handler (TrapContext *dummy_ctx) { - TrapContext *context; - uae_u32 sp; + TrapContext *context; + uae_u32 sp; - /* One trap returning at a time, please! */ - uae_sem_wait (&trap_mutex); + /* One trap returning at a time, please! */ + uae_sem_wait (&trap_mutex); - /* Get trap context from 68k stack. */ - sp = m68k_areg (regs, 7); - context = (TrapContext *)get_pointer (sp); - sp += sizeof (void *); - m68k_areg (regs, 7) = sp; + /* Get trap context from 68k stack. */ + sp = m68k_areg (regs, 7); + context = (TrapContext *)get_pointer (sp); + sp += sizeof (void *); + m68k_areg (regs, 7) = sp; - /* Get return value from the 68k call. */ - context->call68k_retval = m68k_dreg (regs, 0); + /* Get return value from the 68k call. */ + context->call68k_retval = m68k_dreg (regs, 0); - /* Switch back to trap context. */ - uae_sem_post (&context->switch_to_trap_sem); + /* Switch back to trap context. */ + uae_sem_post (&context->switch_to_trap_sem); - /* Wait for trap context to switch back to us. - * - * It'll do this when the trap handler is done - or when - * the handler wants to call another 68k function. */ - uae_sem_wait (&context->switch_to_emu_sem); + /* Wait for trap context to switch back to us. + * + * It'll do this when the trap handler is done - or when + * the handler wants to call another 68k function. */ + uae_sem_wait (&context->switch_to_emu_sem); - /* Dummy return value. */ - return 0; + /* Dummy return value. */ + return 0; } /* - * Handles completion of an extended trap and passes - * return value from trap function to 68k space. - */ +* Handles completion of an extended trap and passes +* return value from trap function to 68k space. +*/ static uae_u32 REGPARAM3 exit_trap_handler (TrapContext *dummy_ctx) { - TrapContext *context = current_context; + TrapContext *context = current_context; - /* Wait for trap context thread to exit. */ - uae_wait_thread (context->thread); + /* Wait for trap context thread to exit. */ + uae_wait_thread (context->thread); - /* Restore 68k state saved at trap entry. */ - regs = context->saved_regs; + /* Restore 68k state saved at trap entry. */ + regs = context->saved_regs; - /* If trap is supposed to return a value, then store - * return value in D0. */ - if (context->trap_has_retval) - m68k_dreg (regs, 0) = context->trap_retval; + /* If trap is supposed to return a value, then store + * return value in D0. */ + if (context->trap_has_retval) + m68k_dreg (regs, 0) = context->trap_retval; - uae_sem_destroy (&context->switch_to_trap_sem); - uae_sem_destroy (&context->switch_to_emu_sem); + uae_sem_destroy (&context->switch_to_trap_sem); + uae_sem_destroy (&context->switch_to_emu_sem); - free (context); + free (context); - /* End critical section */ - uae_sem_post (&trap_mutex); + /* End critical section */ + uae_sem_post (&trap_mutex); - /* Dummy return value. */ - return 0; + /* Dummy return value. */ + return 0; } /* - * Call a 68k library function from extended trap. - */ +* Call a 68k library function from extended trap. +*/ uae_u32 CallLib (TrapContext *context, uaecptr base, uae_s16 offset) { - uae_u32 retval; - uaecptr olda6 = m68k_areg (regs, 6); + uae_u32 retval; + uaecptr olda6 = m68k_areg (regs, 6); - m68k_areg (regs, 6) = base; - retval = trap_Call68k (context, base + offset); - m68k_areg (regs, 6) = olda6; + m68k_areg (regs, 6) = base; + retval = trap_Call68k (context, base + offset); + m68k_areg (regs, 6) = olda6; - return retval; + return retval; } /* - * Call 68k function from extended trap. - */ +* Call 68k function from extended trap. +*/ uae_u32 CallFunc (TrapContext *context, uaecptr func) { - return trap_Call68k (context, func); + return trap_Call68k (context, func); } /* - * Initialize trap mechanism. - */ +* Initialize trap mechanism. +*/ void init_traps (void) { - trap_count = 0; + trap_count = 0; } /* - * Initialize the extended trap mechanism. - */ +* Initialize the extended trap mechanism. +*/ void init_extended_traps (void) { - m68k_call_trapaddr = here (); - calltrap (deftrap2 (m68k_call_handler, TRAPFLAG_NO_RETVAL, L"m68k_call")); + m68k_call_trapaddr = here (); + calltrap (deftrap2 (m68k_call_handler, TRAPFLAG_NO_RETVAL, L"m68k_call")); - m68k_return_trapaddr = here(); - calltrap (deftrap2 (m68k_return_handler, TRAPFLAG_NO_RETVAL, L"m68k_return")); + m68k_return_trapaddr = here(); + calltrap (deftrap2 (m68k_return_handler, TRAPFLAG_NO_RETVAL, L"m68k_return")); - exit_trap_trapaddr = here(); - calltrap (deftrap2 (exit_trap_handler, TRAPFLAG_NO_RETVAL, L"exit_trap")); + exit_trap_trapaddr = here(); + calltrap (deftrap2 (exit_trap_handler, TRAPFLAG_NO_RETVAL, L"exit_trap")); - uae_sem_init (&trap_mutex, 0, 1); + uae_sem_init (&trap_mutex, 0, 1); } diff --git a/uaeexe.c b/uaeexe.c index a3e6606c..d2102be0 100644 --- a/uaeexe.c +++ b/uaeexe.c @@ -1,8 +1,8 @@ /* - * uaeexe.c - UAE remote cli - * - * (c) 1997 by Samuel Devulder - */ +* uaeexe.c - UAE remote cli +* +* (c) 1997 by Samuel Devulder +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -22,112 +22,112 @@ static TCHAR running = 0; static uae_u32 REGPARAM3 uaeexe_server (TrapContext *context) REGPARAM; /* - * Install the server - */ +* Install the server +*/ void uaeexe_install (void) { - uaecptr loop; + uaecptr loop; - loop = here (); - org (UAEEXE_ORG); - calltrap (deftrapres (uaeexe_server, 0, L"uaeexe_server")); - dw (RTS); - org (loop); + loop = here (); + org (UAEEXE_ORG); + calltrap (deftrapres (uaeexe_server, 0, L"uaeexe_server")); + dw (RTS); + org (loop); } /* - * Send command to the remote cli. - * - * To use this, just call uaeexe("command") and the command will be - * executed by the remote cli (provided you've started it in the - * s:user-startup for example). Be sure to add "run" if you want - * to launch the command asynchronously. Please note also that the - * remote cli works better if you've got the fifo-handler installed. - */ +* Send command to the remote cli. +* +* To use this, just call uaeexe("command") and the command will be +* executed by the remote cli (provided you've started it in the +* s:user-startup for example). Be sure to add "run" if you want +* to launch the command asynchronously. Please note also that the +* remote cli works better if you've got the fifo-handler installed. +*/ int uaeexe (const TCHAR *cmd) { - struct uae_xcmd *nw; - - if (!running) - goto NORUN; - - nw = malloc (sizeof *nw); - if (!nw) - goto NOMEM; - nw->cmd = malloc ((_tcslen (cmd) + 1) * sizeof (TCHAR)); - if (!nw->cmd) { - free (nw); - goto NOMEM; - } - - _tcscpy (nw->cmd, cmd); - nw->prev = last; - nw->next = NULL; - - if (!first) - first = nw; - if (last) { - last->next = nw; - last = nw; - } else - last = nw; - - return UAEEXE_OK; - NOMEM: - return UAEEXE_NOMEM; - NORUN: - write_log (L"Remote cli is not running.\n"); - return UAEEXE_NOTRUNNING; + struct uae_xcmd *nw; + + if (!running) + goto NORUN; + + nw = malloc (sizeof *nw); + if (!nw) + goto NOMEM; + nw->cmd = malloc ((_tcslen (cmd) + 1) * sizeof (TCHAR)); + if (!nw->cmd) { + free (nw); + goto NOMEM; + } + + _tcscpy (nw->cmd, cmd); + nw->prev = last; + nw->next = NULL; + + if (!first) + first = nw; + if (last) { + last->next = nw; + last = nw; + } else + last = nw; + + return UAEEXE_OK; +NOMEM: + return UAEEXE_NOMEM; +NORUN: + write_log (L"Remote cli is not running.\n"); + return UAEEXE_NOTRUNNING; } /* - * returns next command to be executed - */ +* returns next command to be executed +*/ static TCHAR *get_cmd (void) { - struct uae_xcmd *cmd; - TCHAR *s; - - if (!first) - return NULL; - s = first->cmd; - cmd = first; - first = first->next; - if (!first) - last = NULL; - free (cmd); - return s; + struct uae_xcmd *cmd; + TCHAR *s; + + if (!first) + return NULL; + s = first->cmd; + cmd = first; + first = first->next; + if (!first) + last = NULL; + free (cmd); + return s; } /* - * helper function - */ +* helper function +*/ #define ARG(x) (get_long (m68k_areg (regs, 7) + 4 * (x + 1))) static uae_u32 REGPARAM2 uaeexe_server (TrapContext *context) { - int len; - TCHAR *cmd; - char *dst, *s; - - if (ARG (0) && !running) { - running = 1; - write_log (L"Remote CLI started.\n"); - } - - cmd = get_cmd (); - if (!cmd) - return 0; - if (!ARG (0)) { - running = 0; - return 0; - } - - dst = (char*)get_real_address (ARG (0)); - len = ARG (1); - s = ua (cmd); - strncpy (dst, s, len); - write_log (L"Sending '%s' to remote cli\n", cmd); - xfree (s); - xfree (cmd); - return ARG (0); + int len; + TCHAR *cmd; + char *dst, *s; + + if (ARG (0) && !running) { + running = 1; + write_log (L"Remote CLI started.\n"); + } + + cmd = get_cmd (); + if (!cmd) + return 0; + if (!ARG (0)) { + running = 0; + return 0; + } + + dst = (char*)get_real_address (ARG (0)); + len = ARG (1); + s = ua (cmd); + strncpy (dst, s, len); + write_log (L"Sending '%s' to remote cli\n", cmd); + xfree (s); + xfree (cmd); + return ARG (0); } diff --git a/uaeipc.c b/uaeipc.c index d1b81f3f..9f6fee20 100644 --- a/uaeipc.c +++ b/uaeipc.c @@ -18,274 +18,274 @@ struct uaeipc { - HANDLE hipc, olevent; - OVERLAPPED ol; - uae_u8 buffer[IPC_BUFFER_SIZE], outbuf[IPC_BUFFER_SIZE]; - int connected, readpending, writepending; - int binary; - TCHAR *outmsg[MAX_OUTMESSAGES]; - int outmessages; - uae_u8 outbin[MAX_OUTMESSAGES][MAX_BINMESSAGE]; - int outbinlen[MAX_OUTMESSAGES]; + HANDLE hipc, olevent; + OVERLAPPED ol; + uae_u8 buffer[IPC_BUFFER_SIZE], outbuf[IPC_BUFFER_SIZE]; + int connected, readpending, writepending; + int binary; + TCHAR *outmsg[MAX_OUTMESSAGES]; + int outmessages; + uae_u8 outbin[MAX_OUTMESSAGES][MAX_BINMESSAGE]; + int outbinlen[MAX_OUTMESSAGES]; }; static void parsemessage(TCHAR *in, struct uae_prefs *p, TCHAR *out, int outsize) { - out[0] = 0; - if (!_tcsncmp (in, L"CFG ", 4) || !_tcsncmp (in, L"EVT ", 4)) { - TCHAR tmpout[256]; - int index = -1; - int cnt = 0; - in += 4; - for (;;) { - int ret; - tmpout[0] = 0; - ret = cfgfile_modify (index, in, _tcslen (in), tmpout, sizeof (tmpout) * sizeof (TCHAR)); - index++; - if (_tcslen (tmpout) > 0) { + out[0] = 0; + if (!_tcsncmp (in, L"CFG ", 4) || !_tcsncmp (in, L"EVT ", 4)) { + TCHAR tmpout[256]; + int index = -1; + int cnt = 0; + in += 4; + for (;;) { + int ret; + tmpout[0] = 0; + ret = cfgfile_modify (index, in, _tcslen (in), tmpout, sizeof (tmpout) * sizeof (TCHAR)); + index++; + if (_tcslen (tmpout) > 0) { + if (_tcslen (out) == 0) + _tcscat (out, L"200 "); + _tcsncat (out, L"\n", outsize); + _tcsncat (out, tmpout, outsize); + } + cnt++; + if (ret >= 0) + break; + } if (_tcslen (out) == 0) - _tcscat (out, L"200 "); - _tcsncat (out, L"\n", outsize); - _tcsncat (out, tmpout, outsize); - } - cnt++; - if (ret >= 0) - break; + _tcscat (out, L"404"); + } else { + _tcscpy (out, L"501"); } - if (_tcslen (out) == 0) - _tcscat (out, L"404"); - } else { - _tcscpy (out, L"501"); - } } static int listenIPC(struct uaeipc *ipc) { - DWORD err; + DWORD err; - memset(&ipc->ol, 0, sizeof (OVERLAPPED)); - ipc->ol.hEvent = ipc->olevent; - if (ConnectNamedPipe(ipc->hipc, &ipc->ol)) { - write_log (L"IPC: ConnectNamedPipe init failed, err=%d\n", GetLastError()); - closeIPC(ipc); - return 0; - } - err = GetLastError(); - if (err == ERROR_PIPE_CONNECTED) { - if (SetEvent(ipc->olevent)) { - write_log (L"IPC: ConnectNamedPipe SetEvent failed, err=%d\n", GetLastError()); - closeIPC(ipc); - return 0; + memset(&ipc->ol, 0, sizeof (OVERLAPPED)); + ipc->ol.hEvent = ipc->olevent; + if (ConnectNamedPipe(ipc->hipc, &ipc->ol)) { + write_log (L"IPC: ConnectNamedPipe init failed, err=%d\n", GetLastError()); + closeIPC(ipc); + return 0; } - } else if (err != ERROR_IO_PENDING) { - write_log (L"IPC: ConnectNamedPipe failed, err=%d\n", err); - closeIPC(ipc); - return 0; - } - return 1; + err = GetLastError(); + if (err == ERROR_PIPE_CONNECTED) { + if (SetEvent(ipc->olevent)) { + write_log (L"IPC: ConnectNamedPipe SetEvent failed, err=%d\n", GetLastError()); + closeIPC(ipc); + return 0; + } + } else if (err != ERROR_IO_PENDING) { + write_log (L"IPC: ConnectNamedPipe failed, err=%d\n", err); + closeIPC(ipc); + return 0; + } + return 1; } static void disconnectIPC(struct uaeipc *ipc) { - ipc->readpending = ipc->writepending = FALSE; - if (ipc->connected) { - if (!DisconnectNamedPipe(ipc->hipc)) - write_log (L"IPC: DisconnectNamedPipe failed, err=%d\n", GetLastError()); - ipc->connected = FALSE; - } + ipc->readpending = ipc->writepending = FALSE; + if (ipc->connected) { + if (!DisconnectNamedPipe(ipc->hipc)) + write_log (L"IPC: DisconnectNamedPipe failed, err=%d\n", GetLastError()); + ipc->connected = FALSE; + } } static void resetIPC(struct uaeipc *ipc) { - disconnectIPC(ipc); - listenIPC(ipc); + disconnectIPC(ipc); + listenIPC(ipc); } void closeIPC(struct uaeipc *ipc) { - if (!ipc) - return; - disconnectIPC(ipc); - if (ipc->hipc == INVALID_HANDLE_VALUE) - return; - CloseHandle(ipc->hipc); - ipc->hipc = INVALID_HANDLE_VALUE; - if (ipc->olevent != INVALID_HANDLE_VALUE) - CloseHandle (ipc->olevent); - ipc->olevent = INVALID_HANDLE_VALUE; - xfree (ipc); + if (!ipc) + return; + disconnectIPC(ipc); + if (ipc->hipc == INVALID_HANDLE_VALUE) + return; + CloseHandle(ipc->hipc); + ipc->hipc = INVALID_HANDLE_VALUE; + if (ipc->olevent != INVALID_HANDLE_VALUE) + CloseHandle (ipc->olevent); + ipc->olevent = INVALID_HANDLE_VALUE; + xfree (ipc); } void *createIPC(const TCHAR *name, int binary) { - TCHAR tmpname[100]; - int cnt = 0; - struct uaeipc *ipc; + TCHAR tmpname[100]; + int cnt = 0; + struct uaeipc *ipc; - ipc = xcalloc (sizeof (struct uaeipc), 1); - ipc->connected = FALSE; - ipc->readpending = FALSE; - ipc->writepending = FALSE; - ipc->olevent = INVALID_HANDLE_VALUE; - ipc->binary = 1; - while (cnt < 10) { - _stprintf (tmpname, L"\\\\.\\pipe\\%s", name); - if (cnt > 0) { - TCHAR *p = tmpname + _tcslen (tmpname); - _stprintf (p, L"_%d", cnt); - } - ipc->hipc = CreateNamedPipe (tmpname, - PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, - PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, - 1, IPC_BUFFER_SIZE, IPC_BUFFER_SIZE, - NMPWAIT_USE_DEFAULT_WAIT, NULL); - if (ipc->hipc == INVALID_HANDLE_VALUE) { - DWORD err = GetLastError (); - if (err == ERROR_ALREADY_EXISTS || err == ERROR_PIPE_BUSY) { - cnt++; - continue; - } - return 0; + ipc = xcalloc (sizeof (struct uaeipc), 1); + ipc->connected = FALSE; + ipc->readpending = FALSE; + ipc->writepending = FALSE; + ipc->olevent = INVALID_HANDLE_VALUE; + ipc->binary = 1; + while (cnt < 10) { + _stprintf (tmpname, L"\\\\.\\pipe\\%s", name); + if (cnt > 0) { + TCHAR *p = tmpname + _tcslen (tmpname); + _stprintf (p, L"_%d", cnt); + } + ipc->hipc = CreateNamedPipe (tmpname, + PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, + 1, IPC_BUFFER_SIZE, IPC_BUFFER_SIZE, + NMPWAIT_USE_DEFAULT_WAIT, NULL); + if (ipc->hipc == INVALID_HANDLE_VALUE) { + DWORD err = GetLastError (); + if (err == ERROR_ALREADY_EXISTS || err == ERROR_PIPE_BUSY) { + cnt++; + continue; + } + return 0; + } + break; } - break; - } - write_log (L"IPC: Named Pipe '%s' open\n", tmpname); - ipc->olevent = CreateEvent(NULL, TRUE, TRUE, NULL); - if (listenIPC(ipc)) - return ipc; - closeIPC(ipc); - return NULL; + write_log (L"IPC: Named Pipe '%s' open\n", tmpname); + ipc->olevent = CreateEvent(NULL, TRUE, TRUE, NULL); + if (listenIPC(ipc)) + return ipc; + closeIPC(ipc); + return NULL; } void *geteventhandleIPC(struct uaeipc *ipc) { - return ipc->olevent; + return ipc->olevent; } int sendIPC(struct uaeipc *ipc, TCHAR *msg) { - if (ipc->hipc == INVALID_HANDLE_VALUE) - return 0; - if (ipc->outmessages >= MAX_OUTMESSAGES) - return 0; - ipc->outmsg[ipc->outmessages++] = my_strdup (msg); - if (!ipc->readpending && !ipc->writepending) - SetEvent (ipc->olevent); - return 1; + if (ipc->hipc == INVALID_HANDLE_VALUE) + return 0; + if (ipc->outmessages >= MAX_OUTMESSAGES) + return 0; + ipc->outmsg[ipc->outmessages++] = my_strdup (msg); + if (!ipc->readpending && !ipc->writepending) + SetEvent (ipc->olevent); + return 1; } int sendBinIPC(struct uaeipc *ipc, uae_u8 *msg, int len) { - if (ipc->hipc == INVALID_HANDLE_VALUE) - return 0; - if (ipc->outmessages >= MAX_OUTMESSAGES) - return 0; - ipc->outbinlen[ipc->outmessages] = len; - memcpy (&ipc->outbin[ipc->outmessages++][0], msg, len); - if (!ipc->readpending && !ipc->writepending) - SetEvent (ipc->olevent); - return 1; + if (ipc->hipc == INVALID_HANDLE_VALUE) + return 0; + if (ipc->outmessages >= MAX_OUTMESSAGES) + return 0; + ipc->outbinlen[ipc->outmessages] = len; + memcpy (&ipc->outbin[ipc->outmessages++][0], msg, len); + if (!ipc->readpending && !ipc->writepending) + SetEvent (ipc->olevent); + return 1; } int checkIPC(struct uaeipc *ipc, struct uae_prefs *p) { - BOOL ok; - DWORD ret, err; + BOOL ok; + DWORD ret, err; - if (ipc->hipc == INVALID_HANDLE_VALUE) - return 0; - if (WaitForSingleObject(ipc->olevent, 0) != WAIT_OBJECT_0) - return 0; - if (!ipc->readpending && !ipc->writepending && ipc->outmessages > 0) { - memset (&ipc->ol, 0, sizeof (OVERLAPPED)); - ipc->ol.hEvent = ipc->olevent; - if (ipc->binary) { - ok = WriteFile (ipc->hipc, &ipc->outbin[ipc->outmessages][0], ipc->outbinlen[ipc->outmessages], &ret, &ipc->ol); - } else { - ok = WriteFile (ipc->hipc, ipc->outmsg[ipc->outmessages], (_tcslen (ipc->outmsg[ipc->outmessages]) + 1) * sizeof (TCHAR), &ret, &ipc->ol); - } - xfree (ipc->outmsg[ipc->outmessages--]); - err = GetLastError (); - if (!ok && err != ERROR_IO_PENDING) { - write_log (L"IPC: WriteFile() err=%d\n", err); - resetIPC (ipc); - return 0; - } - ipc->writepending = TRUE; - return 1; - } - if (ipc->readpending || ipc->writepending) { - ok = GetOverlappedResult (ipc->hipc, &ipc->ol, &ret, FALSE); - if (!ok) { - err = GetLastError (); - if (err == ERROR_IO_INCOMPLETE) + if (ipc->hipc == INVALID_HANDLE_VALUE) return 0; - write_log (L"IPC: GetOverlappedResult error %d\n", err); - resetIPC (ipc); - return 0; - } - if (!ipc->connected) { - write_log (L"IPC: Pipe connected\n"); - ipc->connected = TRUE; - return 0; + if (WaitForSingleObject(ipc->olevent, 0) != WAIT_OBJECT_0) + return 0; + if (!ipc->readpending && !ipc->writepending && ipc->outmessages > 0) { + memset (&ipc->ol, 0, sizeof (OVERLAPPED)); + ipc->ol.hEvent = ipc->olevent; + if (ipc->binary) { + ok = WriteFile (ipc->hipc, &ipc->outbin[ipc->outmessages][0], ipc->outbinlen[ipc->outmessages], &ret, &ipc->ol); + } else { + ok = WriteFile (ipc->hipc, ipc->outmsg[ipc->outmessages], (_tcslen (ipc->outmsg[ipc->outmessages]) + 1) * sizeof (TCHAR), &ret, &ipc->ol); + } + xfree (ipc->outmsg[ipc->outmessages--]); + err = GetLastError (); + if (!ok && err != ERROR_IO_PENDING) { + write_log (L"IPC: WriteFile() err=%d\n", err); + resetIPC (ipc); + return 0; + } + ipc->writepending = TRUE; + return 1; } - if (ipc->writepending) { - ipc->writepending = FALSE; - SetEvent (ipc->ol.hEvent); - memset (&ipc->ol, 0, sizeof (OVERLAPPED)); - ipc->ol.hEvent = ipc->olevent; - return 0; + if (ipc->readpending || ipc->writepending) { + ok = GetOverlappedResult (ipc->hipc, &ipc->ol, &ret, FALSE); + if (!ok) { + err = GetLastError (); + if (err == ERROR_IO_INCOMPLETE) + return 0; + write_log (L"IPC: GetOverlappedResult error %d\n", err); + resetIPC (ipc); + return 0; + } + if (!ipc->connected) { + write_log (L"IPC: Pipe connected\n"); + ipc->connected = TRUE; + return 0; + } + if (ipc->writepending) { + ipc->writepending = FALSE; + SetEvent (ipc->ol.hEvent); + memset (&ipc->ol, 0, sizeof (OVERLAPPED)); + ipc->ol.hEvent = ipc->olevent; + return 0; + } } - } - if (!ipc->readpending) { - ok = ReadFile (ipc->hipc, ipc->buffer, IPC_BUFFER_SIZE, &ret, &ipc->ol); - err = GetLastError (); - if (!ok) { - if (err == ERROR_IO_PENDING) { - ipc->readpending = TRUE; - return 0; - } else if (err == ERROR_BROKEN_PIPE) { - write_log (L"IPC: IPC client disconnected\n"); - } else { - write_log (L"IPC: ReadFile() err=%d\n", err); - } - resetIPC (ipc); - return 0; + if (!ipc->readpending) { + ok = ReadFile (ipc->hipc, ipc->buffer, IPC_BUFFER_SIZE, &ret, &ipc->ol); + err = GetLastError (); + if (!ok) { + if (err == ERROR_IO_PENDING) { + ipc->readpending = TRUE; + return 0; + } else if (err == ERROR_BROKEN_PIPE) { + write_log (L"IPC: IPC client disconnected\n"); + } else { + write_log (L"IPC: ReadFile() err=%d\n", err); + } + resetIPC (ipc); + return 0; + } } - } - ipc->readpending = FALSE; - if (ipc->binary) { + ipc->readpending = FALSE; + if (ipc->binary) { - } else { - write_log (L"IPC: got message '%s'\n", ipc->buffer); - parsemessage ((TCHAR*)ipc->buffer, p, (TCHAR*)ipc->outbuf, sizeof ipc->outbuf); - memset (&ipc->ol, 0, sizeof (OVERLAPPED)); - ipc->ol.hEvent = ipc->olevent; - ok = WriteFile (ipc->hipc, ipc->outbuf, strlen ((char*)ipc->outbuf) + 1, &ret, &ipc->ol); - err = GetLastError (); - if (!ok && err != ERROR_IO_PENDING) { - write_log (L"IPC: WriteFile() err=%d\n", err); - resetIPC (ipc); - return 0; + } else { + write_log (L"IPC: got message '%s'\n", ipc->buffer); + parsemessage ((TCHAR*)ipc->buffer, p, (TCHAR*)ipc->outbuf, sizeof ipc->outbuf); + memset (&ipc->ol, 0, sizeof (OVERLAPPED)); + ipc->ol.hEvent = ipc->olevent; + ok = WriteFile (ipc->hipc, ipc->outbuf, strlen ((char*)ipc->outbuf) + 1, &ret, &ipc->ol); + err = GetLastError (); + if (!ok && err != ERROR_IO_PENDING) { + write_log (L"IPC: WriteFile() err=%d\n", err); + resetIPC (ipc); + return 0; + } + ipc->writepending = TRUE; } - ipc->writepending = TRUE; - } - return 1; + return 1; } int isIPC (const TCHAR *pipename) { - HANDLE *p; + HANDLE *p; - p = CreateFile( - pipename, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); - if (p == INVALID_HANDLE_VALUE) - return 0; - CloseHandle (p); - return 1; + p = CreateFile( + pipename, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + 0, + NULL); + if (p == INVALID_HANDLE_VALUE) + return 0; + CloseHandle (p); + return 1; } diff --git a/uaelib.c b/uaelib.c index 4bb325ff..d1d58055 100644 --- a/uaelib.c +++ b/uaelib.c @@ -1,12 +1,12 @@ /* - * UAE - The U*nix Amiga Emulator - * - * UAE Library v0.1 - * - * (c) 1996 Tauno Taipaleenmaki - * - * Change UAE parameters and other stuff from inside the emulation. - */ +* UAE - The U*nix Amiga Emulator +* +* UAE Library v0.1 +* +* (c) 1996 Tauno Taipaleenmaki +* +* Change UAE parameters and other stuff from inside the emulation. +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -29,272 +29,272 @@ #include "filesys.h" /* - * Returns UAE Version - */ +* Returns UAE Version +*/ static uae_u32 emulib_GetVersion (void) { - return version; + return version; } /* - * Resets your amiga - */ +* Resets your amiga +*/ static uae_u32 emulib_HardReset (void) { - uae_reset(0); - return 0; + uae_reset(0); + return 0; } static uae_u32 emulib_Reset (void) { - uae_reset(0); - return 0; + uae_reset(0); + return 0; } /* - * Enables SOUND - */ +* Enables SOUND +*/ static uae_u32 emulib_EnableSound (uae_u32 val) { - if (!sound_available || currprefs.produce_sound == 2) - return 0; + if (!sound_available || currprefs.produce_sound == 2) + return 0; - currprefs.produce_sound = val; - return 1; + currprefs.produce_sound = val; + return 1; } /* - * Enables FAKE JOYSTICK - */ +* Enables FAKE JOYSTICK +*/ static uae_u32 emulib_EnableJoystick (uae_u32 val) { - currprefs.jports[0].id = val & 255; - currprefs.jports[1].id = (val >> 8) & 255; - return 1; + currprefs.jports[0].id = val & 255; + currprefs.jports[1].id = (val >> 8) & 255; + return 1; } /* - * Sets the framerate - */ +* Sets the framerate +*/ static uae_u32 emulib_SetFrameRate (uae_u32 val) { - if (val == 0) - return 0; - else if (val > 20) - return 0; - else { - currprefs.gfx_framerate = val; - return 1; - } + if (val == 0) + return 0; + else if (val > 20) + return 0; + else { + currprefs.gfx_framerate = val; + return 1; + } } /* - * Changes keyboard language settings - */ +* Changes keyboard language settings +*/ static uae_u32 emulib_ChangeLanguage (uae_u32 which) { - if (which > 6) - return 0; - else { - switch (which) { - case 0: - currprefs.keyboard_lang = KBD_LANG_US; - break; - case 1: - currprefs.keyboard_lang = KBD_LANG_DK; - break; - case 2: - currprefs.keyboard_lang = KBD_LANG_DE; - break; - case 3: - currprefs.keyboard_lang = KBD_LANG_SE; - break; - case 4: - currprefs.keyboard_lang = KBD_LANG_FR; - break; - case 5: - currprefs.keyboard_lang = KBD_LANG_IT; - break; - case 6: - currprefs.keyboard_lang = KBD_LANG_ES; - break; - default: - break; + if (which > 6) + return 0; + else { + switch (which) { + case 0: + currprefs.keyboard_lang = KBD_LANG_US; + break; + case 1: + currprefs.keyboard_lang = KBD_LANG_DK; + break; + case 2: + currprefs.keyboard_lang = KBD_LANG_DE; + break; + case 3: + currprefs.keyboard_lang = KBD_LANG_SE; + break; + case 4: + currprefs.keyboard_lang = KBD_LANG_FR; + break; + case 5: + currprefs.keyboard_lang = KBD_LANG_IT; + break; + case 6: + currprefs.keyboard_lang = KBD_LANG_ES; + break; + default: + break; + } + return 1; } - return 1; - } } /* The following ones don't work as we never realloc the arrays... */ /* - * Changes chip memory size - * (reboots) - */ +* Changes chip memory size +* (reboots) +*/ static uae_u32 REGPARAM2 emulib_ChgCMemSize (uae_u32 memsize) { - if (memsize != 0x80000 && memsize != 0x100000 && - memsize != 0x200000) { - memsize = 0x200000; - write_log (L"Unsupported chipmem size!\n"); - } - m68k_dreg (regs, 0) = 0; - - currprefs.chipmem_size = memsize; - uae_reset(0); - return 1; + if (memsize != 0x80000 && memsize != 0x100000 && + memsize != 0x200000) { + memsize = 0x200000; + write_log (L"Unsupported chipmem size!\n"); + } + m68k_dreg (regs, 0) = 0; + + currprefs.chipmem_size = memsize; + uae_reset(0); + return 1; } /* - * Changes slow memory size - * (reboots) - */ +* Changes slow memory size +* (reboots) +*/ static uae_u32 REGPARAM2 emulib_ChgSMemSize (uae_u32 memsize) { - if (memsize != 0x80000 && memsize != 0x100000 && - memsize != 0x180000 && memsize != 0x1C0000) { - memsize = 0; - write_log (L"Unsupported bogomem size!\n"); - } - - m68k_dreg (regs, 0) = 0; - currprefs.bogomem_size = memsize; - uae_reset (0); - return 1; + if (memsize != 0x80000 && memsize != 0x100000 && + memsize != 0x180000 && memsize != 0x1C0000) { + memsize = 0; + write_log (L"Unsupported bogomem size!\n"); + } + + m68k_dreg (regs, 0) = 0; + currprefs.bogomem_size = memsize; + uae_reset (0); + return 1; } /* - * Changes fast memory size - * (reboots) - */ +* Changes fast memory size +* (reboots) +*/ static uae_u32 REGPARAM2 emulib_ChgFMemSize (uae_u32 memsize) { - if (memsize != 0x100000 && memsize != 0x200000 && - memsize != 0x400000 && memsize != 0x800000) { - memsize = 0; - write_log (L"Unsupported fastmem size!\n"); - } - m68k_dreg (regs, 0) = 0; - currprefs.fastmem_size = memsize; - uae_reset (0); - return 0; + if (memsize != 0x100000 && memsize != 0x200000 && + memsize != 0x400000 && memsize != 0x800000) { + memsize = 0; + write_log (L"Unsupported fastmem size!\n"); + } + m68k_dreg (regs, 0) = 0; + currprefs.fastmem_size = memsize; + uae_reset (0); + return 0; } /* - * Inserts a disk - */ +* Inserts a disk +*/ static uae_u32 emulib_InsertDisk (uaecptr name, uae_u32 drive) { - int i = 0; - char real_name[256]; - TCHAR *s; + int i = 0; + char real_name[256]; + TCHAR *s; - if (drive > 3) - return 0; + if (drive > 3) + return 0; - while ((real_name[i] = get_byte (name + i)) != 0 && i++ != 254) - ; + while ((real_name[i] = get_byte (name + i)) != 0 && i++ != 254) + ; - if (i == 255) - return 0; /* ENAMETOOLONG */ + if (i == 255) + return 0; /* ENAMETOOLONG */ - s = au (real_name); - _tcscpy (changed_prefs.df[drive], s); - xfree (s); + s = au (real_name); + _tcscpy (changed_prefs.df[drive], s); + xfree (s); - return 1; + return 1; } /* - * Exits the emulator - */ +* Exits the emulator +*/ static uae_u32 emulib_ExitEmu (void) { - uae_quit (); - return 1; + uae_quit (); + return 1; } /* - * Gets UAE Configuration - */ +* Gets UAE Configuration +*/ static uae_u32 emulib_GetUaeConfig (uaecptr place) { - int i, j; - - put_long (place, version); - put_long (place + 4, allocated_chipmem); - put_long (place + 8, allocated_bogomem); - put_long (place + 12, allocated_fastmem); - put_long (place + 16, currprefs.gfx_framerate); - put_long (place + 20, currprefs.produce_sound); - put_long (place + 24, currprefs.jports[0].id | (currprefs.jports[1].id << 8)); - put_long (place + 28, currprefs.keyboard_lang); - if (disk_empty (0)) - put_byte (place + 32, 0); - else - put_byte (place + 32, 1); - if (disk_empty (1)) - put_byte (place + 33, 0); - else - put_byte (place + 33, 1); - if (disk_empty(2)) - put_byte (place + 34, 0); - else - put_byte (place + 34, 1); - if (disk_empty(3)) - put_byte (place + 35, 0); - else - put_byte (place + 35, 1); - - for (j = 0; j < 4; j++) { - char *s = ua (currprefs.df[j]); - for (i = 0; i < 256; i++) - put_byte (place + 36 + i + j * 256, s[i]); - xfree (s); - } - return 1; + int i, j; + + put_long (place, version); + put_long (place + 4, allocated_chipmem); + put_long (place + 8, allocated_bogomem); + put_long (place + 12, allocated_fastmem); + put_long (place + 16, currprefs.gfx_framerate); + put_long (place + 20, currprefs.produce_sound); + put_long (place + 24, currprefs.jports[0].id | (currprefs.jports[1].id << 8)); + put_long (place + 28, currprefs.keyboard_lang); + if (disk_empty (0)) + put_byte (place + 32, 0); + else + put_byte (place + 32, 1); + if (disk_empty (1)) + put_byte (place + 33, 0); + else + put_byte (place + 33, 1); + if (disk_empty(2)) + put_byte (place + 34, 0); + else + put_byte (place + 34, 1); + if (disk_empty(3)) + put_byte (place + 35, 0); + else + put_byte (place + 35, 1); + + for (j = 0; j < 4; j++) { + char *s = ua (currprefs.df[j]); + for (i = 0; i < 256; i++) + put_byte (place + 36 + i + j * 256, s[i]); + xfree (s); + } + return 1; } /* - * Sets UAE Configuration - * - * NOT IMPLEMENTED YET - */ +* Sets UAE Configuration +* +* NOT IMPLEMENTED YET +*/ static uae_u32 emulib_SetUaeConfig (uaecptr place) { - return 1; + return 1; } /* - * Gets the name of the disk in the given drive - */ +* Gets the name of the disk in the given drive +*/ static uae_u32 emulib_GetDisk (uae_u32 drive, uaecptr name) { - int i; - if (drive > 3) - return 0; + int i; + if (drive > 3) + return 0; - for (i = 0;i < 256; i++) { - put_byte (name + i, currprefs.df[drive][i]); - } - return 1; + for (i = 0;i < 256; i++) { + put_byte (name + i, currprefs.df[drive][i]); + } + return 1; } /* - * Enter debugging state - */ +* Enter debugging state +*/ static uae_u32 emulib_Debug (void) { #ifdef DEBUGGER - activate_debugger (); - return 1; + activate_debugger (); + return 1; #else - return 0; + return 0; #endif } #define CREATE_NATIVE_FUNC_PTR uae_u32 (* native_func) (uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, \ - uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32) + uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32) #define SET_NATIVE_FUNC(x) native_func = (uae_u32 (*)(uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32))(x) #define CALL_NATIVE_FUNC( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 ) if(native_func) native_func( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 ) /* A0 - Contains a ptr to the native .obj data. This ptr is Amiga-based. */ @@ -302,62 +302,62 @@ static uae_u32 emulib_Debug (void) static uae_u32 REGPARAM2 emulib_ExecuteNativeCode (void) { #if 0 - uaecptr object_AAM = m68k_areg (regs, 0); - uae_u32 d1 = m68k_dreg (regs, 1); - uae_u32 d2 = m68k_dreg (regs, 2); - uae_u32 d3 = m68k_dreg (regs, 3); - uae_u32 d4 = m68k_dreg (regs, 4); - uae_u32 d5 = m68k_dreg (regs, 5); - uae_u32 d6 = m68k_dreg (regs, 6); - uae_u32 d7 = m68k_dreg (regs, 7); - uae_u32 a1 = m68k_areg (regs, 1); - uae_u32 a2 = m68k_areg (regs, 2); - uae_u32 a3 = m68k_areg (regs, 3); - uae_u32 a4 = m68k_areg (regs, 4); - uae_u32 a5 = m68k_areg (regs, 5); - uae_u32 a6 = m68k_areg (regs, 6); - - uae_u8* object_UAM = NULL; - CREATE_NATIVE_FUNC_PTR; - - if (get_mem_bank(object_AAM).check (object_AAM, 1)) - object_UAM = get_mem_bank (object_AAM).xlateaddr (object_AAM); - - if (object_UAM) { - SET_NATIVE_FUNC (FindFunctionInObject (object_UAM)); - CALL_NATIVE_FUNC (d1, d2, d3, d4, d5, d6, d7, a1, a2, a3, a4, a5, a6); - } - return 1; + uaecptr object_AAM = m68k_areg (regs, 0); + uae_u32 d1 = m68k_dreg (regs, 1); + uae_u32 d2 = m68k_dreg (regs, 2); + uae_u32 d3 = m68k_dreg (regs, 3); + uae_u32 d4 = m68k_dreg (regs, 4); + uae_u32 d5 = m68k_dreg (regs, 5); + uae_u32 d6 = m68k_dreg (regs, 6); + uae_u32 d7 = m68k_dreg (regs, 7); + uae_u32 a1 = m68k_areg (regs, 1); + uae_u32 a2 = m68k_areg (regs, 2); + uae_u32 a3 = m68k_areg (regs, 3); + uae_u32 a4 = m68k_areg (regs, 4); + uae_u32 a5 = m68k_areg (regs, 5); + uae_u32 a6 = m68k_areg (regs, 6); + + uae_u8* object_UAM = NULL; + CREATE_NATIVE_FUNC_PTR; + + if (get_mem_bank(object_AAM).check (object_AAM, 1)) + object_UAM = get_mem_bank (object_AAM).xlateaddr (object_AAM); + + if (object_UAM) { + SET_NATIVE_FUNC (FindFunctionInObject (object_UAM)); + CALL_NATIVE_FUNC (d1, d2, d3, d4, d5, d6, d7, a1, a2, a3, a4, a5, a6); + } + return 1; #endif - return 0; + return 0; } static uae_u32 emulib_Minimize (void) { - return 0; // OSDEP_minimize_uae(); + return 0; // OSDEP_minimize_uae(); } static int native_dos_op (uae_u32 mode, uae_u32 p1, uae_u32 p2, uae_u32 p3) { - TCHAR tmp[MAX_DPATH]; - char *s; - int v, i; - - if (mode) - return -1; - /* receive native path from lock - * p1 = dos.library:Lock, p2 = buffer, p3 = max buffer size - */ - v = get_native_path (p1, tmp); - if (v) - return v; - s = ua (tmp); - for (i = 0; i <= strlen (s) && i < p3 - 1; i++) { - put_byte (p2 + i, s[i]); - put_byte (p2 + i + 1, 0); - } - xfree (s); - return 0; + TCHAR tmp[MAX_DPATH]; + char *s; + int v, i; + + if (mode) + return -1; + /* receive native path from lock + * p1 = dos.library:Lock, p2 = buffer, p3 = max buffer size + */ + v = get_native_path (p1, tmp); + if (v) + return v; + s = ua (tmp); + for (i = 0; i <= strlen (s) && i < p3 - 1; i++) { + put_byte (p2 + i, s[i]); + put_byte (p2 + i + 1, 0); + } + xfree (s); + return 0; } #ifndef UAEGFX_INTERNAL extern uae_u32 picasso_demux (uae_u32 arg, TrapContext *context); @@ -373,99 +373,99 @@ static uae_u32 REGPARAM2 uaelib_demux2 (TrapContext *context) #define ARG5 (get_long (m68k_areg (regs, 7) + 24)) #ifndef UAEGFX_INTERNAL - if (ARG0 >= 16 && ARG0 <= 39) - return picasso_demux (ARG0, context); + if (ARG0 >= 16 && ARG0 <= 39) + return picasso_demux (ARG0, context); #endif - switch (ARG0) - { - case 0: return emulib_GetVersion (); - case 1: return emulib_GetUaeConfig (ARG1); - case 2: return emulib_SetUaeConfig (ARG1); - case 3: return emulib_HardReset (); - case 4: return emulib_Reset (); - case 5: return emulib_InsertDisk (ARG1, ARG2); - case 6: return emulib_EnableSound (ARG1); - case 7: return emulib_EnableJoystick (ARG1); - case 8: return emulib_SetFrameRate (ARG1); - case 9: return emulib_ChgCMemSize (ARG1); - case 10: return emulib_ChgSMemSize (ARG1); - case 11: return emulib_ChgFMemSize (ARG1); - case 12: return emulib_ChangeLanguage (ARG1); - /* The next call brings bad luck */ - case 13: return emulib_ExitEmu (); - case 14: return emulib_GetDisk (ARG1, ARG2); - case 15: return emulib_Debug (); - - case 68: return emulib_Minimize (); - case 69: return emulib_ExecuteNativeCode (); - - case 70: return 0; /* RESERVED. Something uses this.. */ - - case 80: return currprefs.maprom ? currprefs.maprom : 0xffffffff; - case 81: return cfgfile_uaelib (ARG1, ARG2, ARG3, ARG4); - case 82: return cfgfile_uaelib_modify (ARG1, ARG2, ARG3, ARG4, ARG5); - case 83: currprefs.mmkeyboard = ARG1 ? 1 : 0; return currprefs.mmkeyboard; + switch (ARG0) + { + case 0: return emulib_GetVersion (); + case 1: return emulib_GetUaeConfig (ARG1); + case 2: return emulib_SetUaeConfig (ARG1); + case 3: return emulib_HardReset (); + case 4: return emulib_Reset (); + case 5: return emulib_InsertDisk (ARG1, ARG2); + case 6: return emulib_EnableSound (ARG1); + case 7: return emulib_EnableJoystick (ARG1); + case 8: return emulib_SetFrameRate (ARG1); + case 9: return emulib_ChgCMemSize (ARG1); + case 10: return emulib_ChgSMemSize (ARG1); + case 11: return emulib_ChgFMemSize (ARG1); + case 12: return emulib_ChangeLanguage (ARG1); + /* The next call brings bad luck */ + case 13: return emulib_ExitEmu (); + case 14: return emulib_GetDisk (ARG1, ARG2); + case 15: return emulib_Debug (); + + case 68: return emulib_Minimize (); + case 69: return emulib_ExecuteNativeCode (); + + case 70: return 0; /* RESERVED. Something uses this.. */ + + case 80: return currprefs.maprom ? currprefs.maprom : 0xffffffff; + case 81: return cfgfile_uaelib (ARG1, ARG2, ARG3, ARG4); + case 82: return cfgfile_uaelib_modify (ARG1, ARG2, ARG3, ARG4, ARG5); + case 83: currprefs.mmkeyboard = ARG1 ? 1 : 0; return currprefs.mmkeyboard; #ifdef DEBUGGER - case 84: return mmu_init (ARG1, ARG2, ARG3); + case 84: return mmu_init (ARG1, ARG2, ARG3); #endif - case 85: return native_dos_op (ARG1, ARG2, ARG3, ARG4); - case 86: - if (valid_address (ARG1, 1)) - write_log (L"DBG: %s\n", get_real_address (ARG1)); - return 1; - case 87: - { - uae_u32 d0, d1; - d0 = emulib_target_getcpurate (ARG1, &d1); - m68k_dreg (regs, 1) = d1; - return d0; - } + case 85: return native_dos_op (ARG1, ARG2, ARG3, ARG4); + case 86: + if (valid_address (ARG1, 1)) + write_log (L"DBG: %s\n", get_real_address (ARG1)); + return 1; + case 87: + { + uae_u32 d0, d1; + d0 = emulib_target_getcpurate (ARG1, &d1); + m68k_dreg (regs, 1) = d1; + return d0; + } - } - return 0; + } + return 0; } extern int uaelib_debug; static uae_u32 REGPARAM2 uaelib_demux (TrapContext *context) { - uae_u32 v; - struct regstruct *r = ®s; - - if (uaelib_debug) - write_log (L"%d: %08x %08x %08x %08x %08x %08x %08x %08x, %08x %08x %08x %08x %08x %08x %08x %08x\n", - ARG0, - r->regs[0],r->regs[1],r->regs[2],r->regs[3],r->regs[4],r->regs[5],r->regs[6],r->regs[7], - r->regs[8],r->regs[9],r->regs[10],r->regs[11],r->regs[12],r->regs[13],r->regs[14],r->regs[15]); + uae_u32 v; + struct regstruct *r = ®s; + + if (uaelib_debug) + write_log (L"%d: %08x %08x %08x %08x %08x %08x %08x %08x, %08x %08x %08x %08x %08x %08x %08x %08x\n", + ARG0, + r->regs[0],r->regs[1],r->regs[2],r->regs[3],r->regs[4],r->regs[5],r->regs[6],r->regs[7], + r->regs[8],r->regs[9],r->regs[10],r->regs[11],r->regs[12],r->regs[13],r->regs[14],r->regs[15]); #ifdef UAEGFX_INTERNAL - if (ARG0 >= 16 && ARG0 <= 39) { - write_log (L"uaelib: obsolete Picasso96 uaelib hook called, call ignored\n"); - return 0; - } + if (ARG0 >= 16 && ARG0 <= 39) { + write_log (L"uaelib: obsolete Picasso96 uaelib hook called, call ignored\n"); + return 0; + } #endif - v = uaelib_demux2 (context); - if (uaelib_debug) - write_log (L"=%08x\n", v); - return v; + v = uaelib_demux2 (context); + if (uaelib_debug) + write_log (L"=%08x\n", v); + return v; } /* - * Installs the UAE LIBRARY - */ +* Installs the UAE LIBRARY +*/ void emulib_install (void) { - uaecptr a; - if (!uae_boot_rom) - return; - a = here (); - currprefs.mmkeyboard = 0; - org (rtarea_base + 0xFF60); + uaecptr a; + if (!uae_boot_rom) + return; + a = here (); + currprefs.mmkeyboard = 0; + org (rtarea_base + 0xFF60); #if 0 - dw (0x4eb9); - dw ((rtarea_base >> 16) | get_word (rtarea_base + 36)); - dw (get_word (rtarea_base + 38) + 12); + dw (0x4eb9); + dw ((rtarea_base >> 16) | get_word (rtarea_base + 36)); + dw (get_word (rtarea_base + 38) + 12); #endif - calltrap (deftrapres (uaelib_demux, 0, L"uaelib_demux")); - dw (RTS); - org (a); + calltrap (deftrapres (uaelib_demux, 0, L"uaelib_demux")); + dw (RTS); + org (a); } diff --git a/uaeresource.c b/uaeresource.c index 24a779f2..9c39fb9a 100644 --- a/uaeresource.c +++ b/uaeresource.c @@ -1,9 +1,9 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * uae.resource - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* uae.resource +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -19,21 +19,21 @@ #if 0 - #define UAERESNAME "uae.resource" +#define UAERESNAME "uae.resource" - #define UAERES_GETFUNC (LIB_BASE - 0*LIB_VECTSIZE) +#define UAERES_GETFUNC (LIB_BASE - 0*LIB_VECTSIZE) - APTR GetFunc (const char *name); +APTR GetFunc (const char *name); - struct uaebase - { +struct uaebase +{ struct Library uae_lib; UWORD uae_version; UWORD uae_revision; UWORD uae_subrevision; UWORD zero; APTR uae_rombase; - }; +}; #endif @@ -41,94 +41,94 @@ static uaecptr res_init, res_name, res_id, base; static uae_u32 REGPARAM2 res_getfunc (TrapContext *ctx) { - uaecptr funcname = m68k_areg (regs, 0); - uae_char tmp[256]; - uae_u32 p; - TCHAR *s; - - if (funcname == 0) - return 0; - strcpyah_safe (tmp, funcname, sizeof tmp); - s = au (tmp); - p = find_trap (s); - xfree (s); - return p; + uaecptr funcname = m68k_areg (regs, 0); + uae_char tmp[256]; + uae_u32 p; + TCHAR *s; + + if (funcname == 0) + return 0; + strcpyah_safe (tmp, funcname, sizeof tmp); + s = au (tmp); + p = find_trap (s); + xfree (s); + return p; } static uae_u32 REGPARAM2 res_initcode (TrapContext *ctx) { - uaecptr rb; - base = m68k_dreg (regs, 0); - rb = base + SIZEOF_LIBRARY; - put_word (rb + 0, UAEMAJOR); - put_word (rb + 2, UAEMINOR); - put_word (rb + 4, UAESUBREV); - put_word (rb + 6, 0); - put_long (rb + 8, rtarea_base); - return base; + uaecptr rb; + base = m68k_dreg (regs, 0); + rb = base + SIZEOF_LIBRARY; + put_word (rb + 0, UAEMAJOR); + put_word (rb + 2, UAEMINOR); + put_word (rb + 4, UAESUBREV); + put_word (rb + 6, 0); + put_long (rb + 8, rtarea_base); + return base; } uaecptr uaeres_startup (uaecptr resaddr) { - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0878); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, res_name); - put_long (resaddr + 0x12, res_id); - put_long (resaddr + 0x16, res_init); - resaddr += 0x1A; - return resaddr; + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0878); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, res_name); + put_long (resaddr + 0x12, res_id); + put_long (resaddr + 0x16, res_init); + resaddr += 0x1A; + return resaddr; } void uaeres_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, getfunc; - TCHAR tmp[100]; - - _stprintf (tmp, L"UAE resource %d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); - res_name = ds (L"uae.resource"); - res_id = ds (tmp); - - /* initcode */ - initcode = here (); - calltrap (deftrap (res_initcode)); dw (RTS); - /* getfunc */ - getfunc = here (); - calltrap (deftrap (res_getfunc)); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (getfunc); /* getfunc */ - dl (0xFFFFFFFF); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0800); /* NT_RESOURCE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (res_name); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (UAEMAJOR); - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (UAEMINOR); - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (res_id); - dw (0x0000); /* end of table */ - - res_init = here (); - dl (SIZEOF_LIBRARY + 16); /* size of device base */ - dl (functable); - dl (datatable); - dl (initcode); + uae_u32 functable, datatable; + uae_u32 initcode, getfunc; + TCHAR tmp[100]; + + _stprintf (tmp, L"UAE resource %d.%d.%d", UAEMAJOR, UAEMINOR, UAESUBREV); + res_name = ds (L"uae.resource"); + res_id = ds (tmp); + + /* initcode */ + initcode = here (); + calltrap (deftrap (res_initcode)); dw (RTS); + /* getfunc */ + getfunc = here (); + calltrap (deftrap (res_getfunc)); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (getfunc); /* getfunc */ + dl (0xFFFFFFFF); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0800); /* NT_RESOURCE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (res_name); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (UAEMAJOR); + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (UAEMINOR); + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (res_id); + dw (0x0000); /* end of table */ + + res_init = here (); + dl (SIZEOF_LIBRARY + 16); /* size of device base */ + dl (functable); + dl (datatable); + dl (initcode); } diff --git a/uaeserial.c b/uaeserial.c index 29137d0c..743ce7f1 100644 --- a/uaeserial.c +++ b/uaeserial.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * uaeserial.device - * - * Copyright 2004/2006 Toni Wilen - * - */ +/* +* UAE - The Un*x Amiga Emulator +* +* uaeserial.device +* +* Copyright 2004/2006 Toni Wilen +* +*/ #include "sysconfig.h" #include "sysdeps.h" @@ -106,24 +106,24 @@ int log_uaeserial = 0; struct asyncreq { - struct asyncreq *next; - uaecptr request; - int ready; + struct asyncreq *next; + uaecptr request; + int ready; }; struct devstruct { - int open; - int unit; - int uniq; - int exclusive; + int open; + int unit; + int uniq; + int exclusive; - struct asyncreq *ar; + struct asyncreq *ar; - smp_comm_pipe requests; - int thread_running; - uae_sem_t sync_sem; + smp_comm_pipe requests; + int thread_running; + uae_sem_t sync_sem; - void *sysdata; + void *sysdata; }; static int uniq; @@ -133,647 +133,647 @@ static uae_sem_t change_sem, async_sem; static TCHAR *getdevname (void) { - return L"uaeserial.device"; + return L"uaeserial.device"; } static void io_log (TCHAR *msg, uaecptr request) { - if (log_uaeserial) - write_log (L"%s: %08X %d %08X %d %d io_actual=%d io_error=%d\n", - msg, request, get_word (request + 28), get_long (request + 40), - get_long (request + 36), get_long (request + 44), - get_long (request + 32), get_byte (request + 31)); + if (log_uaeserial) + write_log (L"%s: %08X %d %08X %d %d io_actual=%d io_error=%d\n", + msg, request, get_word (request + 28), get_long (request + 40), + get_long (request + 36), get_long (request + 44), + get_long (request + 32), get_byte (request + 31)); } static struct devstruct *getdevstruct (int uniq) { - int i; - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (devst[i].uniq == uniq) - return &devst[i]; - } - return 0; + int i; + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (devst[i].uniq == uniq) + return &devst[i]; + } + return 0; } static void *dev_thread (void *devs); static int start_thread (struct devstruct *dev) { - init_comm_pipe (&dev->requests, 100, 1); - uae_sem_init (&dev->sync_sem, 0, 0); - uae_start_thread (L"uaeserial", dev_thread, dev, NULL); - uae_sem_wait (&dev->sync_sem); - return dev->thread_running; + init_comm_pipe (&dev->requests, 100, 1); + uae_sem_init (&dev->sync_sem, 0, 0); + uae_start_thread (L"uaeserial", dev_thread, dev, NULL); + uae_sem_wait (&dev->sync_sem); + return dev->thread_running; } static void dev_close_3 (struct devstruct *dev) { - uaeser_close (dev->sysdata); - dev->open = 0; - xfree (dev->sysdata); - write_comm_pipe_u32 (&dev->requests, 0, 1); + uaeser_close (dev->sysdata); + dev->open = 0; + xfree (dev->sysdata); + write_comm_pipe_u32 (&dev->requests, 0, 1); } static uae_u32 REGPARAM2 dev_close (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct devstruct *dev; - - dev = getdevstruct (get_long (request + 24)); - if (!dev) + uae_u32 request = m68k_areg (regs, 1); + struct devstruct *dev; + + dev = getdevstruct (get_long (request + 24)); + if (!dev) + return 0; + if (log_uaeserial) + write_log (L"%s:%d close, req=%x\n", getdevname(), dev->unit, request); + dev_close_3 (dev); + put_long (request + 24, 0); + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); return 0; - if (log_uaeserial) - write_log (L"%s:%d close, req=%x\n", getdevname(), dev->unit, request); - dev_close_3 (dev); - put_long (request + 24, 0); - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) - 1); - return 0; } static void resetparams (struct devstruct *dev, uaecptr req) { - put_long (req + io_CtlChar, 0x00001311); - put_long (req + io_RBufLen, 1024); - put_long (req + io_ExtFlags, 0); - put_long (req + io_Baud, 9600); - put_long (req + io_BrkTime, 250000); - put_long (req + io_TermArray0, 0); - put_long (req + io_TermArray1, 0); - put_byte (req + io_ReadLen, 8); - put_byte (req + io_WriteLen, 8); - put_byte (req + io_StopBits, 1); - put_byte (req + io_SerFlags, get_byte (req + io_SerFlags) & (SERF_XDISABLED | SERF_SHARED | SERF_7WIRE)); - put_word (req + io_Status, 0); + put_long (req + io_CtlChar, 0x00001311); + put_long (req + io_RBufLen, 1024); + put_long (req + io_ExtFlags, 0); + put_long (req + io_Baud, 9600); + put_long (req + io_BrkTime, 250000); + put_long (req + io_TermArray0, 0); + put_long (req + io_TermArray1, 0); + put_byte (req + io_ReadLen, 8); + put_byte (req + io_WriteLen, 8); + put_byte (req + io_StopBits, 1); + put_byte (req + io_SerFlags, get_byte (req + io_SerFlags) & (SERF_XDISABLED | SERF_SHARED | SERF_7WIRE)); + put_word (req + io_Status, 0); } static int setparams (struct devstruct *dev, uaecptr req) { - int v; - int rbuffer, baud, rbits, wbits, sbits, rtscts, parity, xonxoff; - - rbuffer = get_long (req + io_RBufLen); - v = get_long (req + io_ExtFlags); - if (v) { - write_log (L"UAESER: io_ExtFlags=%08x, not supported\n", v); - return 5; - } - baud = get_long (req + io_Baud); - v = get_byte (req + io_SerFlags); - if (v & SERF_EOFMODE) { - write_log (L"UAESER: SERF_EOFMODE not supported\n"); - return 5; - } - xonxoff = (v & SERF_XDISABLED) ? 0 : 1; - if (xonxoff) { - xonxoff |= (get_long (req + io_CtlChar) << 8) & 0x00ffff00; - } - rtscts = (v & SERF_7WIRE) ? 1 : 0; - parity = 0; - if (v & SERF_PARTY_ON) - parity = (v & SERF_PARTY_ODD) ? 1 : 2; - rbits = get_byte (req + io_ReadLen); - wbits = get_byte (req + io_WriteLen); - sbits = get_byte (req + io_StopBits); - if ((rbits != 7 && rbits != 8) || (wbits != 7 && wbits != 8) || (sbits != 1 && sbits != 2) || rbits != wbits) { - write_log (L"UAESER: Read=%d, Write=%d, Stop=%d, not supported\n", rbits, wbits, sbits); - return 5; - } - write_log (L"%s:%d BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PAR=%d XO=%06X\n", - getdevname(), dev->unit, - baud, rbuffer, rbits, sbits, rtscts, parity, xonxoff); - v = uaeser_setparams (dev->sysdata, baud, rbuffer, - rbits, sbits, rtscts, parity, xonxoff); - if (v) { - write_log (L"->failed\n"); - return v; - } - return 0; + int v; + int rbuffer, baud, rbits, wbits, sbits, rtscts, parity, xonxoff; + + rbuffer = get_long (req + io_RBufLen); + v = get_long (req + io_ExtFlags); + if (v) { + write_log (L"UAESER: io_ExtFlags=%08x, not supported\n", v); + return 5; + } + baud = get_long (req + io_Baud); + v = get_byte (req + io_SerFlags); + if (v & SERF_EOFMODE) { + write_log (L"UAESER: SERF_EOFMODE not supported\n"); + return 5; + } + xonxoff = (v & SERF_XDISABLED) ? 0 : 1; + if (xonxoff) { + xonxoff |= (get_long (req + io_CtlChar) << 8) & 0x00ffff00; + } + rtscts = (v & SERF_7WIRE) ? 1 : 0; + parity = 0; + if (v & SERF_PARTY_ON) + parity = (v & SERF_PARTY_ODD) ? 1 : 2; + rbits = get_byte (req + io_ReadLen); + wbits = get_byte (req + io_WriteLen); + sbits = get_byte (req + io_StopBits); + if ((rbits != 7 && rbits != 8) || (wbits != 7 && wbits != 8) || (sbits != 1 && sbits != 2) || rbits != wbits) { + write_log (L"UAESER: Read=%d, Write=%d, Stop=%d, not supported\n", rbits, wbits, sbits); + return 5; + } + write_log (L"%s:%d BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PAR=%d XO=%06X\n", + getdevname(), dev->unit, + baud, rbuffer, rbits, sbits, rtscts, parity, xonxoff); + v = uaeser_setparams (dev->sysdata, baud, rbuffer, + rbits, sbits, rtscts, parity, xonxoff); + if (v) { + write_log (L"->failed\n"); + return v; + } + return 0; } static int openfail (uaecptr ioreq, int error) { - put_long (ioreq + 20, -1); - put_byte (ioreq + 31, error); - return (uae_u32)-1; + put_long (ioreq + 20, -1); + put_byte (ioreq + 31, error); + return (uae_u32)-1; } static uae_u32 REGPARAM2 dev_open (TrapContext *context) { - uaecptr ioreq = m68k_areg (regs, 1); - uae_u32 unit = m68k_dreg (regs, 0); - uae_u32 flags = m68k_dreg (regs, 1); - struct devstruct *dev; - int i, err; - - if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) - return openfail (ioreq, IOERR_BADLENGTH); - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (devst[i].open && devst[i].unit == unit && devst[i].exclusive) - return openfail (ioreq, IOERR_UNITBUSY); - } - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - if (!devst[i].open) - break; - } - if (i == MAX_TOTAL_DEVICES) - return openfail (ioreq, IOERR_OPENFAIL); - dev = &devst[i]; - dev->sysdata = xcalloc (uaeser_getdatalenght(), 1); - if (!uaeser_open (dev->sysdata, dev, unit)) { - xfree (dev->sysdata); - return openfail (ioreq, IOERR_OPENFAIL); - } - dev->unit = unit; - dev->open = 1; - dev->uniq = ++uniq; - dev->exclusive = (get_word (ioreq + io_SerFlags) & SERF_SHARED) ? 0 : 1; - put_long (ioreq + 24, dev->uniq); - resetparams (dev, ioreq); - err = setparams (dev, ioreq); - if (err) { - uaeser_close (dev->sysdata); - dev->open = 0; - xfree (dev->sysdata); - return openfail (ioreq, err); - } - if (log_uaeserial) - write_log (L"%s:%d open ioreq=%08X\n", getdevname(), unit, ioreq); - start_thread (dev); - - put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); - put_byte (ioreq + 31, 0); - put_byte (ioreq + 8, 7); - return 0; + uaecptr ioreq = m68k_areg (regs, 1); + uae_u32 unit = m68k_dreg (regs, 0); + uae_u32 flags = m68k_dreg (regs, 1); + struct devstruct *dev; + int i, err; + + if (get_word (ioreq + 0x12) < IOSTDREQ_SIZE) + return openfail (ioreq, IOERR_BADLENGTH); + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (devst[i].open && devst[i].unit == unit && devst[i].exclusive) + return openfail (ioreq, IOERR_UNITBUSY); + } + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + if (!devst[i].open) + break; + } + if (i == MAX_TOTAL_DEVICES) + return openfail (ioreq, IOERR_OPENFAIL); + dev = &devst[i]; + dev->sysdata = xcalloc (uaeser_getdatalenght(), 1); + if (!uaeser_open (dev->sysdata, dev, unit)) { + xfree (dev->sysdata); + return openfail (ioreq, IOERR_OPENFAIL); + } + dev->unit = unit; + dev->open = 1; + dev->uniq = ++uniq; + dev->exclusive = (get_word (ioreq + io_SerFlags) & SERF_SHARED) ? 0 : 1; + put_long (ioreq + 24, dev->uniq); + resetparams (dev, ioreq); + err = setparams (dev, ioreq); + if (err) { + uaeser_close (dev->sysdata); + dev->open = 0; + xfree (dev->sysdata); + return openfail (ioreq, err); + } + if (log_uaeserial) + write_log (L"%s:%d open ioreq=%08X\n", getdevname(), unit, ioreq); + start_thread (dev); + + put_word (m68k_areg (regs, 6) + 32, get_word (m68k_areg (regs, 6) + 32) + 1); + put_byte (ioreq + 31, 0); + put_byte (ioreq + 8, 7); + return 0; } static uae_u32 REGPARAM2 dev_expunge (TrapContext *context) { - return 0; + return 0; } static struct asyncreq *get_async_request (struct devstruct *dev, uaecptr request, int ready) { - struct asyncreq *ar; - int ret = 0; - - uae_sem_wait (&async_sem); - ar = dev->ar; - while (ar) { - if (ar->request == request) { - if (ready) - ar->ready = 1; - break; + struct asyncreq *ar; + int ret = 0; + + uae_sem_wait (&async_sem); + ar = dev->ar; + while (ar) { + if (ar->request == request) { + if (ready) + ar->ready = 1; + break; + } + ar = ar->next; } - ar = ar->next; - } - uae_sem_post (&async_sem); - return ar; + uae_sem_post (&async_sem); + return ar; } static int add_async_request (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar, *ar2; - - if (log_uaeserial) - write_log (L"%s:%d async request %x added\n", getdevname(), dev->unit, request); - - uae_sem_wait (&async_sem); - ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); - ar->request = request; - if (!dev->ar) { - dev->ar = ar; - } else { - ar2 = dev->ar; - while (ar2->next) - ar2 = ar2->next; - ar2->next = ar; - } - uae_sem_post (&async_sem); - return 1; + struct asyncreq *ar, *ar2; + + if (log_uaeserial) + write_log (L"%s:%d async request %x added\n", getdevname(), dev->unit, request); + + uae_sem_wait (&async_sem); + ar = (struct asyncreq*)xcalloc (sizeof (struct asyncreq), 1); + ar->request = request; + if (!dev->ar) { + dev->ar = ar; + } else { + ar2 = dev->ar; + while (ar2->next) + ar2 = ar2->next; + ar2->next = ar; + } + uae_sem_post (&async_sem); + return 1; } static int release_async_request (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar, *prevar; - - uae_sem_wait (&async_sem); - ar = dev->ar; - prevar = NULL; - while (ar) { - if (ar->request == request) { - if (prevar == NULL) - dev->ar = ar->next; - else - prevar->next = ar->next; - uae_sem_post (&async_sem); - xfree (ar); - if (log_uaeserial) - write_log (L"%s:%d async request %x removed\n", getdevname(), dev->unit, request); - return 1; + struct asyncreq *ar, *prevar; + + uae_sem_wait (&async_sem); + ar = dev->ar; + prevar = NULL; + while (ar) { + if (ar->request == request) { + if (prevar == NULL) + dev->ar = ar->next; + else + prevar->next = ar->next; + uae_sem_post (&async_sem); + xfree (ar); + if (log_uaeserial) + write_log (L"%s:%d async request %x removed\n", getdevname(), dev->unit, request); + return 1; + } + prevar = ar; + ar = ar->next; } - prevar = ar; - ar = ar->next; - } - uae_sem_post (&async_sem); - write_log (L"%s:%d async request %x not found for removal!\n", getdevname(), dev->unit, request); - return 0; + uae_sem_post (&async_sem); + write_log (L"%s:%d async request %x not found for removal!\n", getdevname(), dev->unit, request); + return 0; } static void abort_async (struct devstruct *dev, uaecptr request) { - struct asyncreq *ar = get_async_request (dev, request, 1); - if (!ar) { - write_log (L"%s:%d: abort async but no request %x found!\n", getdevname(), dev->unit, request); - return; - } - if (log_uaeserial) - write_log (L"%s:%d asyncronous request=%08X aborted\n", getdevname(), dev->unit, request); - put_byte (request + 31, IOERR_ABORTED); - put_byte (request + 30, get_byte (request + 30) | 0x20); - write_comm_pipe_u32 (&dev->requests, request, 1); + struct asyncreq *ar = get_async_request (dev, request, 1); + if (!ar) { + write_log (L"%s:%d: abort async but no request %x found!\n", getdevname(), dev->unit, request); + return; + } + if (log_uaeserial) + write_log (L"%s:%d asyncronous request=%08X aborted\n", getdevname(), dev->unit, request); + put_byte (request + 31, IOERR_ABORTED); + put_byte (request + 30, get_byte (request + 30) | 0x20); + write_comm_pipe_u32 (&dev->requests, request, 1); } static uae_u8 *memmap(uae_u32 addr, uae_u32 len) { - addrbank *bank_data = &get_mem_bank (addr); - if (!bank_data->check (addr, len)) - return NULL; - return bank_data->xlateaddr (addr); + addrbank *bank_data = &get_mem_bank (addr); + if (!bank_data->check (addr, len)) + return NULL; + return bank_data->xlateaddr (addr); } void uaeser_signal (struct devstruct *dev, int sigmask) { - struct asyncreq *ar; - int i = 0; - - uae_sem_wait (&async_sem); - ar = dev->ar; - while (ar) { - if (!ar->ready) { - uaecptr request = ar->request; - uae_u32 io_data = get_long (request + 40); // 0x28 - uae_u32 io_length = get_long (request + 36); // 0x24 - int command = get_word (request + 28); - uae_u32 io_error = 0, io_actual = 0; - uae_u8 *addr; - int io_done = 0; - - switch (command) - { - case SDCMD_BREAK: - if (ar == dev->ar) { - uaeser_break (dev->sysdata, get_long (request + io_BrkTime)); - io_done = 1; - } - break; - case CMD_READ: - if (sigmask & 1) { - addr = memmap(io_data, io_length); - if (addr) { - if (uaeser_read (dev->sysdata, addr, io_length)) { - io_error = 0; - io_actual = io_length; - io_done = 1; + struct asyncreq *ar; + int i = 0; + + uae_sem_wait (&async_sem); + ar = dev->ar; + while (ar) { + if (!ar->ready) { + uaecptr request = ar->request; + uae_u32 io_data = get_long (request + 40); // 0x28 + uae_u32 io_length = get_long (request + 36); // 0x24 + int command = get_word (request + 28); + uae_u32 io_error = 0, io_actual = 0; + uae_u8 *addr; + int io_done = 0; + + switch (command) + { + case SDCMD_BREAK: + if (ar == dev->ar) { + uaeser_break (dev->sysdata, get_long (request + io_BrkTime)); + io_done = 1; + } + break; + case CMD_READ: + if (sigmask & 1) { + addr = memmap(io_data, io_length); + if (addr) { + if (uaeser_read (dev->sysdata, addr, io_length)) { + io_error = 0; + io_actual = io_length; + io_done = 1; + } + } else { + io_error = IOERR_BADADDRESS; + io_done = 1; + } + } + break; + case CMD_WRITE: + if (sigmask & 2) { + io_error = IOERR_BADADDRESS; + addr = memmap(io_data, io_length); + if (addr && uaeser_write (dev->sysdata, addr, io_length)) + io_error = 0; + io_actual = io_length; + io_done = 1; + } + break; + default: + write_log (L"%s:%d incorrect async request %x (cmd=%d) signaled?!", getdevname(), dev->unit, request, command); + break; } - } else { - io_error = IOERR_BADADDRESS; - io_done = 1; - } - } - break; - case CMD_WRITE: - if (sigmask & 2) { - io_error = IOERR_BADADDRESS; - addr = memmap(io_data, io_length); - if (addr && uaeser_write (dev->sysdata, addr, io_length)) - io_error = 0; - io_actual = io_length; - io_done = 1; - } - break; - default: - write_log (L"%s:%d incorrect async request %x (cmd=%d) signaled?!", getdevname(), dev->unit, request, command); - break; - } - - if (io_done) { - if (log_uaeserial) - write_log (L"%s:%d async request %x completed\n", getdevname(), dev->unit, request); - put_long (request + 32, io_actual); - put_byte (request + 31, io_error); - ar->ready = 1; - write_comm_pipe_u32 (&dev->requests, request, 1); - } + if (io_done) { + if (log_uaeserial) + write_log (L"%s:%d async request %x completed\n", getdevname(), dev->unit, request); + put_long (request + 32, io_actual); + put_byte (request + 31, io_error); + ar->ready = 1; + write_comm_pipe_u32 (&dev->requests, request, 1); + } + + } + ar = ar->next; } - ar = ar->next; - } - uae_sem_post (&async_sem); + uae_sem_post (&async_sem); } static void cmd_reset(struct devstruct *dev, uaecptr req) { - while (dev->ar) - abort_async (dev, dev->ar->request); - put_long (req + io_RBufLen, 8192); - put_long (req + io_ExtFlags, 0); - put_long (req + io_Baud, 57600); - put_long (req + io_BrkTime, 250000); - put_long (req + io_TermArray0, 0); - put_long (req + io_TermArray1, 0); - put_long (req + io_ReadLen, 8); - put_long (req + io_WriteLen, 8); - put_long (req + io_StopBits, 1); - put_long (req + io_SerFlags, SERF_XDISABLED); - put_word (req + io_Status, 0); + while (dev->ar) + abort_async (dev, dev->ar->request); + put_long (req + io_RBufLen, 8192); + put_long (req + io_ExtFlags, 0); + put_long (req + io_Baud, 57600); + put_long (req + io_BrkTime, 250000); + put_long (req + io_TermArray0, 0); + put_long (req + io_TermArray1, 0); + put_long (req + io_ReadLen, 8); + put_long (req + io_WriteLen, 8); + put_long (req + io_StopBits, 1); + put_long (req + io_SerFlags, SERF_XDISABLED); + put_word (req + io_Status, 0); } static int dev_do_io (struct devstruct *dev, uaecptr request, int quick) { - uae_u32 command; - uae_u32 io_data = get_long (request + 40); // 0x28 - uae_u32 io_length = get_long (request + 36); // 0x24 - uae_u32 io_actual = get_long (request + 32); // 0x20 - uae_u32 io_offset = get_long (request + 44); // 0x2c - uae_u32 io_error = 0; - uae_u16 io_status; - int async = 0; - - if (!dev) - return 0; - command = get_word (request + 28); - io_log (L"dev_io_START",request); - - switch (command) - { + uae_u32 command; + uae_u32 io_data = get_long (request + 40); // 0x28 + uae_u32 io_length = get_long (request + 36); // 0x24 + uae_u32 io_actual = get_long (request + 32); // 0x20 + uae_u32 io_offset = get_long (request + 44); // 0x2c + uae_u32 io_error = 0; + uae_u16 io_status; + int async = 0; + + if (!dev) + return 0; + command = get_word (request + 28); + io_log (L"dev_io_START",request); + + switch (command) + { case SDCMD_QUERY: - if (uaeser_query (dev->sysdata, &io_status, &io_actual)) - put_byte (request + io_Status, io_status); - else - io_error = IOERR_BADADDRESS; - break; + if (uaeser_query (dev->sysdata, &io_status, &io_actual)) + put_byte (request + io_Status, io_status); + else + io_error = IOERR_BADADDRESS; + break; case SDCMD_SETPARAMS: - io_error = setparams(dev, request); - break; + io_error = setparams(dev, request); + break; case CMD_WRITE: - async = 1; - break; + async = 1; + break; case CMD_READ: - async = 1; - break; + async = 1; + break; case SDCMD_BREAK: - if (get_byte (request + io_SerFlags) & SERF_QUEUEDBRK) { - async = 1; - } else { - uaeser_break (dev->sysdata, get_long (request + io_BrkTime)); - } - break; + if (get_byte (request + io_SerFlags) & SERF_QUEUEDBRK) { + async = 1; + } else { + uaeser_break (dev->sysdata, get_long (request + io_BrkTime)); + } + break; case CMD_CLEAR: - uaeser_clearbuffers(dev->sysdata); - break; + uaeser_clearbuffers(dev->sysdata); + break; case CMD_RESET: - cmd_reset(dev, request); - break; + cmd_reset(dev, request); + break; case CMD_FLUSH: case CMD_START: case CMD_STOP: - break; + break; case NSCMD_DEVICEQUERY: - put_long (io_data + 0, 0); - put_long (io_data + 4, 16); /* size */ - put_word (io_data + 8, NSDEVTYPE_SERIAL); - put_word (io_data + 10, 0); - put_long (io_data + 12, nscmd_cmd); - io_actual = 16; - break; + put_long (io_data + 0, 0); + put_long (io_data + 4, 16); /* size */ + put_word (io_data + 8, NSDEVTYPE_SERIAL); + put_word (io_data + 10, 0); + put_long (io_data + 12, nscmd_cmd); + io_actual = 16; + break; default: - io_error = IOERR_NOCMD; - break; - } - put_long (request + 32, io_actual); - put_byte (request + 31, io_error); - io_log (L"dev_io_END",request); - return async; + io_error = IOERR_NOCMD; + break; + } + put_long (request + 32, io_actual); + put_byte (request + 31, io_error); + io_log (L"dev_io_END",request); + return async; } static int dev_canquick (struct devstruct *dev, uaecptr request) { - return 0; + return 0; } static uae_u32 REGPARAM2 dev_beginio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - uae_u8 flags = get_byte (request + 30); - int command = get_word (request + 28); - struct devstruct *dev = getdevstruct (get_long (request + 24)); - - put_byte (request + 8, NT_MESSAGE); - if (!dev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - put_byte (request + 31, 0); - if ((flags & 1) && dev_canquick (dev, request)) { - if (dev_do_io (dev, request, 1)) - write_log (L"device %s:%d command %d bug with IO_QUICK\n", getdevname(), dev->unit, command); - return get_byte (request + 31); - } else { - put_byte (request + 30, get_byte (request + 30) & ~1); - write_comm_pipe_u32 (&dev->requests, request, 1); - return 0; - } + uae_u32 request = m68k_areg (regs, 1); + uae_u8 flags = get_byte (request + 30); + int command = get_word (request + 28); + struct devstruct *dev = getdevstruct (get_long (request + 24)); + + put_byte (request + 8, NT_MESSAGE); + if (!dev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + put_byte (request + 31, 0); + if ((flags & 1) && dev_canquick (dev, request)) { + if (dev_do_io (dev, request, 1)) + write_log (L"device %s:%d command %d bug with IO_QUICK\n", getdevname(), dev->unit, command); + return get_byte (request + 31); + } else { + put_byte (request + 30, get_byte (request + 30) & ~1); + write_comm_pipe_u32 (&dev->requests, request, 1); + return 0; + } } static void *dev_thread (void *devs) { - struct devstruct *dev = (struct devstruct*)devs; - - uae_set_thread_priority (NULL, 1); - dev->thread_running = 1; - uae_sem_post (&dev->sync_sem); - for (;;) { - uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); - uae_sem_wait (&change_sem); - if (!request) { - dev->thread_running = 0; - uae_sem_post (&dev->sync_sem); - uae_sem_post (&change_sem); - return 0; - } else if (get_async_request (dev, request, 1)) { - uae_ReplyMsg (request); - release_async_request (dev, request); - } else if (dev_do_io (dev, request, 0) == 0) { - uae_ReplyMsg (request); - } else { - add_async_request (dev, request); - uaeser_trigger (dev->sysdata); + struct devstruct *dev = (struct devstruct*)devs; + + uae_set_thread_priority (NULL, 1); + dev->thread_running = 1; + uae_sem_post (&dev->sync_sem); + for (;;) { + uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); + uae_sem_wait (&change_sem); + if (!request) { + dev->thread_running = 0; + uae_sem_post (&dev->sync_sem); + uae_sem_post (&change_sem); + return 0; + } else if (get_async_request (dev, request, 1)) { + uae_ReplyMsg (request); + release_async_request (dev, request); + } else if (dev_do_io (dev, request, 0) == 0) { + uae_ReplyMsg (request); + } else { + add_async_request (dev, request); + uaeser_trigger (dev->sysdata); + } + uae_sem_post (&change_sem); } - uae_sem_post (&change_sem); - } - return 0; + return 0; } static uae_u32 REGPARAM2 dev_init (TrapContext *context) { - uae_u32 base = m68k_dreg (regs, 0); - if (log_uaeserial) - write_log (L"%s init\n", getdevname ()); - return base; + uae_u32 base = m68k_dreg (regs, 0); + if (log_uaeserial) + write_log (L"%s init\n", getdevname ()); + return base; } static uae_u32 REGPARAM2 dev_abortio (TrapContext *context) { - uae_u32 request = m68k_areg (regs, 1); - struct devstruct *dev = getdevstruct (get_long (request + 24)); - - if (!dev) { - put_byte (request + 31, 32); - return get_byte (request + 31); - } - abort_async (dev, request); - return 0; + uae_u32 request = m68k_areg (regs, 1); + struct devstruct *dev = getdevstruct (get_long (request + 24)); + + if (!dev) { + put_byte (request + 31, 32); + return get_byte (request + 31); + } + abort_async (dev, request); + return 0; } static void dev_reset (void) { - int i; - struct devstruct *dev; - - for (i = 0; i < MAX_TOTAL_DEVICES; i++) { - dev = &devst[i]; - if (dev->open) { - while (dev->ar) - abort_async (dev, dev->ar->request); - dev_close_3 (dev); - uae_sem_wait (&dev->sync_sem); + int i; + struct devstruct *dev; + + for (i = 0; i < MAX_TOTAL_DEVICES; i++) { + dev = &devst[i]; + if (dev->open) { + while (dev->ar) + abort_async (dev, dev->ar->request); + dev_close_3 (dev); + uae_sem_wait (&dev->sync_sem); + } + memset (dev, 0, sizeof (struct devstruct)); } - memset (dev, 0, sizeof (struct devstruct)); - } } static uaecptr ROM_uaeserialdev_resname = 0, - ROM_uaeserialdev_resid = 0, - ROM_uaeserialdev_init = 0; + ROM_uaeserialdev_resid = 0, + ROM_uaeserialdev_init = 0; uaecptr uaeserialdev_startup (uaecptr resaddr) { - if (!currprefs.uaeserial) + if (!currprefs.uaeserial) + return resaddr; + if (log_uaeserial) + write_log (L"uaeserialdev_startup(0x%x)\n", resaddr); + /* Build a struct Resident. This will set up and initialize + * the serial.device */ + put_word (resaddr + 0x0, 0x4AFC); + put_long (resaddr + 0x2, resaddr); + put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ + put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ + put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ + put_long (resaddr + 0xE, ROM_uaeserialdev_resname); + put_long (resaddr + 0x12, ROM_uaeserialdev_resid); + put_long (resaddr + 0x16, ROM_uaeserialdev_init); + resaddr += 0x1A; return resaddr; - if (log_uaeserial) - write_log (L"uaeserialdev_startup(0x%x)\n", resaddr); - /* Build a struct Resident. This will set up and initialize - * the serial.device */ - put_word (resaddr + 0x0, 0x4AFC); - put_long (resaddr + 0x2, resaddr); - put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */ - put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */ - put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */ - put_long (resaddr + 0xE, ROM_uaeserialdev_resname); - put_long (resaddr + 0x12, ROM_uaeserialdev_resid); - put_long (resaddr + 0x16, ROM_uaeserialdev_init); - resaddr += 0x1A; - return resaddr; } void uaeserialdev_install (void) { - uae_u32 functable, datatable; - uae_u32 initcode, openfunc, closefunc, expungefunc; - uae_u32 beginiofunc, abortiofunc; - - if (!currprefs.uaeserial) - return; - - ROM_uaeserialdev_resname = ds (L"uaeserial.device"); - ROM_uaeserialdev_resid = ds (L"UAE serial.device 0.1"); - - /* initcode */ - initcode = here (); - calltrap (deftrap (dev_init)); dw (RTS); - - /* Open */ - openfunc = here (); - calltrap (deftrap (dev_open)); dw (RTS); - - /* Close */ - closefunc = here (); - calltrap (deftrap (dev_close)); dw (RTS); - - /* Expunge */ - expungefunc = here (); - calltrap (deftrap (dev_expunge)); dw (RTS); - - /* BeginIO */ - beginiofunc = here (); - calltrap (deftrap (dev_beginio)); dw (RTS); - - /* AbortIO */ - abortiofunc = here (); - calltrap (deftrap (dev_abortio)); dw (RTS); - - /* FuncTable */ - functable = here (); - dl (openfunc); /* Open */ - dl (closefunc); /* Close */ - dl (expungefunc); /* Expunge */ - dl (EXPANSION_nullfunc); /* Null */ - dl (beginiofunc); /* BeginIO */ - dl (abortiofunc); /* AbortIO */ - dl (0xFFFFFFFFul); /* end of table */ - - /* DataTable */ - datatable = here (); - dw (0xE000); /* INITBYTE */ - dw (0x0008); /* LN_TYPE */ - dw (0x0300); /* NT_DEVICE */ - dw (0xC000); /* INITLONG */ - dw (0x000A); /* LN_NAME */ - dl (ROM_uaeserialdev_resname); - dw (0xE000); /* INITBYTE */ - dw (0x000E); /* LIB_FLAGS */ - dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ - dw (0xD000); /* INITWORD */ - dw (0x0014); /* LIB_VERSION */ - dw (0x0004); /* 0.4 */ - dw (0xD000); /* INITWORD */ - dw (0x0016); /* LIB_REVISION */ - dw (0x0000); - dw (0xC000); /* INITLONG */ - dw (0x0018); /* LIB_IDSTRING */ - dl (ROM_uaeserialdev_resid); - dw (0x0000); /* end of table */ - - ROM_uaeserialdev_init = here (); - dl (0x00000100); /* size of device base */ - dl (functable); - dl (datatable); - dl (initcode); - - nscmd_cmd = here (); - dw (NSCMD_DEVICEQUERY); - dw (CMD_RESET); - dw (CMD_READ); - dw (CMD_WRITE); - dw (CMD_CLEAR); - dw (CMD_START); - dw (CMD_STOP); - dw (CMD_FLUSH); - dw (SDCMD_BREAK); - dw (SDCMD_SETPARAMS); - dw (SDCMD_QUERY); - dw (0); + uae_u32 functable, datatable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; + + if (!currprefs.uaeserial) + return; + + ROM_uaeserialdev_resname = ds (L"uaeserial.device"); + ROM_uaeserialdev_resid = ds (L"UAE serial.device 0.1"); + + /* initcode */ + initcode = here (); + calltrap (deftrap (dev_init)); dw (RTS); + + /* Open */ + openfunc = here (); + calltrap (deftrap (dev_open)); dw (RTS); + + /* Close */ + closefunc = here (); + calltrap (deftrap (dev_close)); dw (RTS); + + /* Expunge */ + expungefunc = here (); + calltrap (deftrap (dev_expunge)); dw (RTS); + + /* BeginIO */ + beginiofunc = here (); + calltrap (deftrap (dev_beginio)); dw (RTS); + + /* AbortIO */ + abortiofunc = here (); + calltrap (deftrap (dev_abortio)); dw (RTS); + + /* FuncTable */ + functable = here (); + dl (openfunc); /* Open */ + dl (closefunc); /* Close */ + dl (expungefunc); /* Expunge */ + dl (EXPANSION_nullfunc); /* Null */ + dl (beginiofunc); /* BeginIO */ + dl (abortiofunc); /* AbortIO */ + dl (0xFFFFFFFFul); /* end of table */ + + /* DataTable */ + datatable = here (); + dw (0xE000); /* INITBYTE */ + dw (0x0008); /* LN_TYPE */ + dw (0x0300); /* NT_DEVICE */ + dw (0xC000); /* INITLONG */ + dw (0x000A); /* LN_NAME */ + dl (ROM_uaeserialdev_resname); + dw (0xE000); /* INITBYTE */ + dw (0x000E); /* LIB_FLAGS */ + dw (0x0600); /* LIBF_SUMUSED | LIBF_CHANGED */ + dw (0xD000); /* INITWORD */ + dw (0x0014); /* LIB_VERSION */ + dw (0x0004); /* 0.4 */ + dw (0xD000); /* INITWORD */ + dw (0x0016); /* LIB_REVISION */ + dw (0x0000); + dw (0xC000); /* INITLONG */ + dw (0x0018); /* LIB_IDSTRING */ + dl (ROM_uaeserialdev_resid); + dw (0x0000); /* end of table */ + + ROM_uaeserialdev_init = here (); + dl (0x00000100); /* size of device base */ + dl (functable); + dl (datatable); + dl (initcode); + + nscmd_cmd = here (); + dw (NSCMD_DEVICEQUERY); + dw (CMD_RESET); + dw (CMD_READ); + dw (CMD_WRITE); + dw (CMD_CLEAR); + dw (CMD_START); + dw (CMD_STOP); + dw (CMD_FLUSH); + dw (SDCMD_BREAK); + dw (SDCMD_SETPARAMS); + dw (SDCMD_QUERY); + dw (0); } void uaeserialdev_start_threads (void) { - uae_sem_init (&change_sem, 0, 1); - uae_sem_init (&async_sem, 0, 1); + uae_sem_init (&change_sem, 0, 1); + uae_sem_init (&async_sem, 0, 1); } void uaeserialdev_reset (void) { - if (!currprefs.uaeserial) - return; - dev_reset (); + if (!currprefs.uaeserial) + return; + dev_reset (); } diff --git a/zfile.c b/zfile.c index 2568ae50..5675014c 100644 --- a/zfile.c +++ b/zfile.c @@ -1,11 +1,11 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * routines to handle compressed file automatically - * - * (c) 1996 Samuel Devulder, Tim Gunn - * 2002-2007 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* routines to handle compressed file automatically +* +* (c) 1996 Samuel Devulder, Tim Gunn +* 2002-2007 Toni Wilen +*/ #define ZLIB_WINAPI #define RECURSIVE_ARCHIVES 1 @@ -35,83 +35,83 @@ const TCHAR *uae_archive_extensions[] = { L"zip", L"rar", L"7z", L"lha", L"lzh", static struct zfile *zfile_create (struct zfile *prev) { - struct zfile *z; + struct zfile *z; - z = xmalloc (sizeof *z); - if (!z) - return 0; - memset (z, 0, sizeof *z); - z->next = zlist; - zlist = z; - z->opencnt = 1; - if (prev) { - z->zfdmask = prev->zfdmask; - } - return z; + z = xmalloc (sizeof *z); + if (!z) + return 0; + memset (z, 0, sizeof *z); + z->next = zlist; + zlist = z; + z->opencnt = 1; + if (prev) { + z->zfdmask = prev->zfdmask; + } + return z; } static void zfile_free (struct zfile *f) { - if (f->f) - fclose (f->f); - if (f->deleteafterclose) { - _wunlink (f->name); - write_log (L"deleted temporary file '%s'\n", f->name); - } - xfree (f->name); - xfree (f->data); - xfree (f->mode); - xfree (f->userdata); - xfree (f); + if (f->f) + fclose (f->f); + if (f->deleteafterclose) { + _wunlink (f->name); + write_log (L"deleted temporary file '%s'\n", f->name); + } + xfree (f->name); + xfree (f->data); + xfree (f->mode); + xfree (f->userdata); + xfree (f); } void zfile_exit (void) { - struct zfile *l; - while ((l = zlist)) { - zlist = l->next; - zfile_free (l); - } + struct zfile *l; + while ((l = zlist)) { + zlist = l->next; + zfile_free (l); + } } void zfile_fclose (struct zfile *f) { - struct zfile *pl = NULL; - struct zfile *l = zlist; - struct zfile *nxt; - - if (!f) - return; - if (f->opencnt < 0) { - write_log (L"zfile: tried to free already closed filehandle!\n"); - return; - } - f->opencnt--; - if (f->opencnt > 0) - return; - f->opencnt = -100; - if (f->parent) { - f->parent->opencnt--; - if (f->parent->opencnt <= 0) - zfile_fclose (f->parent); - } - while (l != f) { - if (l == 0) { - write_log (L"zfile: tried to free already freed or nonexisting filehandle!\n"); - return; - } - pl = l; - l = l->next; - } - if (l) - nxt = l->next; - zfile_free (f); - if (l == 0) - return; - if(!pl) - zlist = nxt; - else - pl->next = nxt; + struct zfile *pl = NULL; + struct zfile *l = zlist; + struct zfile *nxt; + + if (!f) + return; + if (f->opencnt < 0) { + write_log (L"zfile: tried to free already closed filehandle!\n"); + return; + } + f->opencnt--; + if (f->opencnt > 0) + return; + f->opencnt = -100; + if (f->parent) { + f->parent->opencnt--; + if (f->parent->opencnt <= 0) + zfile_fclose (f->parent); + } + while (l != f) { + if (l == 0) { + write_log (L"zfile: tried to free already freed or nonexisting filehandle!\n"); + return; + } + pl = l; + l = l->next; + } + if (l) + nxt = l->next; + zfile_free (f); + if (l == 0) + return; + if(!pl) + zlist = nxt; + else + pl->next = nxt; } static uae_u8 exeheader[]={ 0x00,0x00,0x03,0xf3,0x00,0x00,0x00,0x00 }; @@ -119,52 +119,52 @@ static TCHAR *diskimages[] = { L"adf", L"adz", L"ipf", L"fdi", L"dms", L"wrp", L int zfile_gettype (struct zfile *z) { - uae_u8 buf[8]; - TCHAR *ext; - - if (!z || !z->name) - return ZFILE_UNKNOWN; - ext = _tcsrchr (z->name, '.'); - if (ext != NULL) { - int i; - ext++; - for (i = 0; diskimages[i]; i++) { - if (strcasecmp (ext, diskimages[i]) == 0) + uae_u8 buf[8]; + TCHAR *ext; + + if (!z || !z->name) + return ZFILE_UNKNOWN; + ext = _tcsrchr (z->name, '.'); + if (ext != NULL) { + int i; + ext++; + for (i = 0; diskimages[i]; i++) { + if (strcasecmp (ext, diskimages[i]) == 0) + return ZFILE_DISKIMAGE; + } + if (strcasecmp (ext, L"roz") == 0) + return ZFILE_ROM; + if (strcasecmp (ext, L"uss") == 0) + return ZFILE_STATEFILE; + if (strcasecmp (ext, L"rom") == 0) + return ZFILE_ROM; + if (strcasecmp (ext, L"key") == 0) + return ZFILE_KEY; + if (strcasecmp (ext, L"nvr") == 0) + return ZFILE_NVR; + if (strcasecmp (ext, L"uae") == 0) + return ZFILE_CONFIGURATION; + } + memset (buf, 0, sizeof (buf)); + zfile_fread (buf, 8, 1, z); + zfile_fseek (z, -8, SEEK_CUR); + if (!memcmp (buf, exeheader, sizeof (buf))) return ZFILE_DISKIMAGE; + if (!memcmp (buf, "RDSK", 4)) + return ZFILE_HDFRDB; + if (!memcmp (buf, "DOS", 3)) { + if (z->size < 4 * 1024 * 1024) + return ZFILE_DISKIMAGE; + else + return ZFILE_HDF; } - if (strcasecmp (ext, L"roz") == 0) - return ZFILE_ROM; - if (strcasecmp (ext, L"uss") == 0) - return ZFILE_STATEFILE; - if (strcasecmp (ext, L"rom") == 0) - return ZFILE_ROM; - if (strcasecmp (ext, L"key") == 0) - return ZFILE_KEY; - if (strcasecmp (ext, L"nvr") == 0) - return ZFILE_NVR; - if (strcasecmp (ext, L"uae") == 0) - return ZFILE_CONFIGURATION; - } - memset (buf, 0, sizeof (buf)); - zfile_fread (buf, 8, 1, z); - zfile_fseek (z, -8, SEEK_CUR); - if (!memcmp (buf, exeheader, sizeof (buf))) - return ZFILE_DISKIMAGE; - if (!memcmp (buf, "RDSK", 4)) - return ZFILE_HDFRDB; - if (!memcmp (buf, "DOS", 3)) { - if (z->size < 4 * 1024 * 1024) - return ZFILE_DISKIMAGE; - else - return ZFILE_HDF; - } - if (ext != NULL) { - if (strcasecmp (ext, L"hdf") == 0) - return ZFILE_HDF; - if (strcasecmp (ext, L"hdz") == 0) - return ZFILE_HDF; - } - return ZFILE_UNKNOWN; + if (ext != NULL) { + if (strcasecmp (ext, L"hdf") == 0) + return ZFILE_HDF; + if (strcasecmp (ext, L"hdz") == 0) + return ZFILE_HDF; + } + return ZFILE_UNKNOWN; } #define VHD_DYNAMIC 3 @@ -172,885 +172,887 @@ int zfile_gettype (struct zfile *z) STATIC_INLINE uae_u32 gl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); } static uae_u32 vhd_checksum (uae_u8 *p, int offset) { - int i; - uae_u32 sum; + int i; + uae_u32 sum; - sum = 0; - for (i = 0; i < 512; i++) { - if (offset >= 0 && i >= offset && i < offset + 4) - continue; - sum += p[i]; - } - return ~sum; + sum = 0; + for (i = 0; i < 512; i++) { + if (offset >= 0 && i >= offset && i < offset + 4) + continue; + sum += p[i]; + } + return ~sum; } struct zfile_vhd { - int vhd_type; - uae_u64 virtsize; - uae_u32 vhd_bamoffset; - uae_u32 vhd_blocksize; - uae_u8 *vhd_header, *vhd_sectormap; - uae_u64 vhd_footerblock; - uae_u32 vhd_bamsize; - uae_u64 vhd_sectormapblock; - uae_u32 vhd_bitmapsize; + int vhd_type; + uae_u64 virtsize; + uae_u32 vhd_bamoffset; + uae_u32 vhd_blocksize; + uae_u8 *vhd_header, *vhd_sectormap; + uae_u64 vhd_footerblock; + uae_u32 vhd_bamsize; + uae_u64 vhd_sectormapblock; + uae_u32 vhd_bitmapsize; }; static uae_u64 vhd_fread2 (struct zfile *zf, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { - uae_u32 bamoffset; - uae_u32 sectoroffset; - uae_u64 read; - struct zfile *zp = zf->parent; - struct zfile_vhd *zvhd = zf->userdata; - - //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); - read = 0; - if (offset & 511) - return read; - if (len & 511) + uae_u32 bamoffset; + uae_u32 sectoroffset; + uae_u64 read; + struct zfile *zp = zf->parent; + struct zfile_vhd *zvhd = zf->userdata; + + //write_log (L"%08x %08x\n", (uae_u32)offset, (uae_u32)len); + read = 0; + if (offset & 511) + return read; + if (len & 511) + return read; + while (len > 0) { + bamoffset = (offset / zvhd->vhd_blocksize) * 4 + zvhd->vhd_bamoffset; + sectoroffset = gl (zvhd->vhd_header + bamoffset); + if (sectoroffset == 0xffffffff) { + memset (dataptr, 0, 512); + read += 512; + } else { + int bitmapoffsetbits; + int bitmapoffsetbytes; + int sectormapblock; + + bitmapoffsetbits = (offset / 512) % (zvhd->vhd_blocksize / 512); + bitmapoffsetbytes = bitmapoffsetbits / 8; + sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); + if (zvhd->vhd_sectormapblock != sectormapblock) { + // read sector bitmap + //write_log (L"BM %08x\n", sectormapblock); + zfile_fseek (zp, sectormapblock, SEEK_SET); + if (zfile_fread (zvhd->vhd_sectormap, 1, 512, zp) != 512) + return read; + zvhd->vhd_sectormapblock = sectormapblock; + } + // block allocated in bitmap? + if (zvhd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7)))) { + // read data block + int block = sectoroffset * 512 + zvhd->vhd_bitmapsize + bitmapoffsetbits * 512; + //write_log (L"DB %08x\n", block); + zfile_fseek (zp, block, SEEK_SET); + if (zfile_fread (dataptr, 1, 512, zp) != 512) + return read; + } else { + memset (dataptr, 0, 512); + } + read += 512; + } + len -= 512; + dataptr += 512; + offset += 512; + } return read; - while (len > 0) { - bamoffset = (offset / zvhd->vhd_blocksize) * 4 + zvhd->vhd_bamoffset; - sectoroffset = gl (zvhd->vhd_header + bamoffset); - if (sectoroffset == 0xffffffff) { - memset (dataptr, 0, 512); - read += 512; - } else { - int bitmapoffsetbits; - int bitmapoffsetbytes; - int sectormapblock; - - bitmapoffsetbits = (offset / 512) % (zvhd->vhd_blocksize / 512); - bitmapoffsetbytes = bitmapoffsetbits / 8; - sectormapblock = sectoroffset * 512 + (bitmapoffsetbytes & ~511); - if (zvhd->vhd_sectormapblock != sectormapblock) { - // read sector bitmap - //write_log (L"BM %08x\n", sectormapblock); - zfile_fseek (zp, sectormapblock, SEEK_SET); - if (zfile_fread (zvhd->vhd_sectormap, 1, 512, zp) != 512) - return read; - zvhd->vhd_sectormapblock = sectormapblock; - } - // block allocated in bitmap? - if (zvhd->vhd_sectormap[bitmapoffsetbytes & 511] & (1 << (7 - (bitmapoffsetbits & 7)))) { - // read data block - int block = sectoroffset * 512 + zvhd->vhd_bitmapsize + bitmapoffsetbits * 512; - //write_log (L"DB %08x\n", block); - zfile_fseek (zp, block, SEEK_SET); - if (zfile_fread (dataptr, 1, 512, zp) != 512) - return read; - } else { - memset (dataptr, 0, 512); - } - read += 512; - } - len -= 512; - dataptr += 512; - offset += 512; - } - return read; } static uae_u64 vhd_fread (uae_u8 *data, uae_u64 l1, uae_u64 l2, struct zfile *zf) { - uae_u64 size = l1 * l2; - uae_u64 out = 0; - int len = 0; - - if ((zf->seek & 511) || (size & 511)) { - int seek; - uae_u8 tmp[512]; - - if (zf->seek & 511) { - int s; - s = 512 - (zf->seek & 511); - vhd_fread2 (zf, tmp, zf->seek & ~511, 512); - memcpy (data + len, tmp + 512 - s, s); - len += s; - out += s; - zf->seek += s; - } - while (size > 0) { - int s = size > 512 ? 512 : size; - vhd_fread2 (zf, tmp, zf->seek, 512); - memcpy (data + len, tmp, s); - zf->seek += s; - size -= s; - out += s; - } - } else { - out = vhd_fread2 (zf, data, zf->seek, size); - zf->seek += out; - out /= l1; - } - return out; + uae_u64 size = l1 * l2; + uae_u64 out = 0; + int len = 0; + + if ((zf->seek & 511) || (size & 511)) { + int seek; + uae_u8 tmp[512]; + + if (zf->seek & 511) { + int s; + s = 512 - (zf->seek & 511); + vhd_fread2 (zf, tmp, zf->seek & ~511, 512); + memcpy (data + len, tmp + 512 - s, s); + len += s; + out += s; + zf->seek += s; + } + while (size > 0) { + int s = size > 512 ? 512 : size; + vhd_fread2 (zf, tmp, zf->seek, 512); + memcpy (data + len, tmp, s); + zf->seek += s; + size -= s; + out += s; + } + } else { + out = vhd_fread2 (zf, data, zf->seek, size); + zf->seek += out; + out /= l1; + } + return out; } static struct zfile *vhd (struct zfile *z) { - uae_u8 tmp[512], tmp2[512]; - uae_u32 v; - struct zfile_vhd *zvhd; - uae_u64 fsize; - - zvhd = xcalloc (sizeof (struct zfile_vhd), 1); - zfile_fseek (z, 0, SEEK_END); - fsize = zfile_ftell (z); - zfile_fseek (z, 0, SEEK_SET); - if (zfile_fread (tmp, 1, 512, z) != 512) - goto nonvhd; - v = gl (tmp + 8); // features - if ((v & 3) != 2) - goto nonvhd; - v = gl (tmp + 8 + 4); // version - if ((v >> 16) != 1) - goto nonvhd; - zvhd->vhd_type = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4); - if (zvhd->vhd_type != VHD_FIXED && zvhd->vhd_type != VHD_DYNAMIC) - goto nonvhd; - v = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4); - if (v == 0) - goto nonvhd; - if (vhd_checksum (tmp, 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4) != v) - goto nonvhd; - zfile_fseek (z, fsize - sizeof tmp2, SEEK_SET); - if (zfile_fread (tmp2, 1, 512, z) != 512) - goto end; - if (memcmp (tmp, tmp2, sizeof tmp)) - goto nonvhd; - zvhd->vhd_footerblock = fsize - 512; - zvhd->virtsize = (uae_u64)(gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8)) << 32; - zvhd->virtsize |= gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8 + 4); - if (zvhd->vhd_type == VHD_DYNAMIC) { - uae_u32 size; - zvhd->vhd_bamoffset = gl (tmp + 8 + 4 + 4 + 4); - if (zvhd->vhd_bamoffset == 0 || zvhd->vhd_bamoffset >= fsize) - goto end; - zfile_fseek (z, zvhd->vhd_bamoffset, SEEK_SET); + uae_u8 tmp[512], tmp2[512]; + uae_u32 v; + struct zfile_vhd *zvhd; + uae_u64 fsize; + + zvhd = xcalloc (sizeof (struct zfile_vhd), 1); + zfile_fseek (z, 0, SEEK_END); + fsize = zfile_ftell (z); + zfile_fseek (z, 0, SEEK_SET); if (zfile_fread (tmp, 1, 512, z) != 512) - goto end; - v = gl (tmp + 8 + 8 + 8 + 4 + 4 + 4); - if (vhd_checksum (tmp, 8 + 8 + 8 + 4 + 4 + 4) != v) - goto end; - v = gl (tmp + 8 + 8 + 8); + goto nonvhd; + v = gl (tmp + 8); // features + if ((v & 3) != 2) + goto nonvhd; + v = gl (tmp + 8 + 4); // version if ((v >> 16) != 1) - goto end; - zvhd->vhd_blocksize = gl (tmp + 8 + 8 + 8 + 4 + 4); - zvhd->vhd_bamoffset = gl (tmp + 8 + 8 + 4); - zvhd->vhd_bamsize = (((zvhd->virtsize + zvhd->vhd_blocksize - 1) / zvhd->vhd_blocksize) * 4 + 511) & ~511; - size = zvhd->vhd_bamoffset + zvhd->vhd_bamsize; - zvhd->vhd_header = xmalloc (size); - zfile_fseek (z, 0, SEEK_SET); - if (zfile_fread (zvhd->vhd_header, 1, size, z) != size) - goto end; - zvhd->vhd_sectormap = xmalloc (512); - zvhd->vhd_sectormapblock = -1; - zvhd->vhd_bitmapsize = ((zvhd->vhd_blocksize / (8 * 512)) + 511) & ~511; - } - z = zfile_fopen_parent (z, NULL, 0, zvhd->virtsize); - z->useparent = 0; - z->dataseek = 1; - z->userdata = zvhd; - z->zfileread = vhd_fread; - write_log (L"%s is VHD %s image, virtual size=%dK\n", - zfile_getname (z), - zvhd->vhd_type == 2 ? L"fixed" : L"dynamic", - zvhd->virtsize / 1024); - return z; + goto nonvhd; + zvhd->vhd_type = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4); + if (zvhd->vhd_type != VHD_FIXED && zvhd->vhd_type != VHD_DYNAMIC) + goto nonvhd; + v = gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4); + if (v == 0) + goto nonvhd; + if (vhd_checksum (tmp, 8 + 4 + 4 + 8 + 4 + 4 + 4 + 4 + 8 + 8 + 4 + 4) != v) + goto nonvhd; + zfile_fseek (z, fsize - sizeof tmp2, SEEK_SET); + if (zfile_fread (tmp2, 1, 512, z) != 512) + goto end; + if (memcmp (tmp, tmp2, sizeof tmp)) + goto nonvhd; + zvhd->vhd_footerblock = fsize - 512; + zvhd->virtsize = (uae_u64)(gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8)) << 32; + zvhd->virtsize |= gl (tmp + 8 + 4 + 4 + 8 + 4 + 4 +4 + 4 + 8 + 4); + if (zvhd->vhd_type == VHD_DYNAMIC) { + uae_u32 size; + zvhd->vhd_bamoffset = gl (tmp + 8 + 4 + 4 + 4); + if (zvhd->vhd_bamoffset == 0 || zvhd->vhd_bamoffset >= fsize) + goto end; + zfile_fseek (z, zvhd->vhd_bamoffset, SEEK_SET); + if (zfile_fread (tmp, 1, 512, z) != 512) + goto end; + v = gl (tmp + 8 + 8 + 8 + 4 + 4 + 4); + if (vhd_checksum (tmp, 8 + 8 + 8 + 4 + 4 + 4) != v) + goto end; + v = gl (tmp + 8 + 8 + 8); + if ((v >> 16) != 1) + goto end; + zvhd->vhd_blocksize = gl (tmp + 8 + 8 + 8 + 4 + 4); + zvhd->vhd_bamoffset = gl (tmp + 8 + 8 + 4); + zvhd->vhd_bamsize = (((zvhd->virtsize + zvhd->vhd_blocksize - 1) / zvhd->vhd_blocksize) * 4 + 511) & ~511; + size = zvhd->vhd_bamoffset + zvhd->vhd_bamsize; + zvhd->vhd_header = xmalloc (size); + zfile_fseek (z, 0, SEEK_SET); + if (zfile_fread (zvhd->vhd_header, 1, size, z) != size) + goto end; + zvhd->vhd_sectormap = xmalloc (512); + zvhd->vhd_sectormapblock = -1; + zvhd->vhd_bitmapsize = ((zvhd->vhd_blocksize / (8 * 512)) + 511) & ~511; + } + z = zfile_fopen_parent (z, NULL, 0, zvhd->virtsize); + z->useparent = 0; + z->dataseek = 1; + z->userdata = zvhd; + z->zfileread = vhd_fread; + write_log (L"%s is VHD %s image, virtual size=%dK\n", + zfile_getname (z), + zvhd->vhd_type == 2 ? L"fixed" : L"dynamic", + zvhd->virtsize / 1024); + return z; nonvhd: end: - return z; + return z; } struct zfile *zfile_gunzip (struct zfile *z) { - uae_u8 header[2 + 1 + 1 + 4 + 1 + 1]; - z_stream zs; - int i, size, ret, first; - uae_u8 flags; - uae_s64 offset; - TCHAR name[MAX_DPATH]; - uae_u8 buffer[8192]; - struct zfile *z2; - uae_u8 b; - - _tcscpy (name, z->name); - memset (&zs, 0, sizeof (zs)); - memset (header, 0, sizeof (header)); - zfile_fread (header, sizeof (header), 1, z); - flags = header[3]; - if (header[0] != 0x1f && header[1] != 0x8b) - return z; - if (flags & 2) /* multipart not supported */ - return z; - if (flags & 32) /* encryption not supported */ - return z; - if (flags & 4) { /* skip extra field */ + uae_u8 header[2 + 1 + 1 + 4 + 1 + 1]; + z_stream zs; + int i, size, ret, first; + uae_u8 flags; + uae_s64 offset; + TCHAR name[MAX_DPATH]; + uae_u8 buffer[8192]; + struct zfile *z2; + uae_u8 b; + + _tcscpy (name, z->name); + memset (&zs, 0, sizeof (zs)); + memset (header, 0, sizeof (header)); + zfile_fread (header, sizeof (header), 1, z); + flags = header[3]; + if (header[0] != 0x1f && header[1] != 0x8b) + return z; + if (flags & 2) /* multipart not supported */ + return z; + if (flags & 32) /* encryption not supported */ + return z; + if (flags & 4) { /* skip extra field */ + zfile_fread (&b, 1, 1, z); + size = b; + zfile_fread (&b, 1, 1, z); + size |= b << 8; + zfile_fseek (z, size + 2, SEEK_CUR); + } + if (flags & 8) { /* get original file name */ + uae_char aname[MAX_DPATH]; + i = 0; + do { + zfile_fread (aname + i, 1, 1, z); + } while (i < MAX_DPATH - 1 && aname[i++]); + aname[i] = 0; + au_copy (name, MAX_DPATH, aname); + } + if (flags & 16) { /* skip comment */ + i = 0; + do { + b = 0; + zfile_fread (&b, 1, 1, z); + } while (b); + } + offset = zfile_ftell (z); + zfile_fseek (z, -4, SEEK_END); zfile_fread (&b, 1, 1, z); size = b; zfile_fread (&b, 1, 1, z); size |= b << 8; - zfile_fseek (z, size + 2, SEEK_CUR); - } - if (flags & 8) { /* get original file name */ - uae_char aname[MAX_DPATH]; - i = 0; - do { - zfile_fread (aname + i, 1, 1, z); - } while (i < MAX_DPATH - 1 && aname[i++]); - aname[i] = 0; - au_copy (name, MAX_DPATH, aname); - } - if (flags & 16) { /* skip comment */ - i = 0; + zfile_fread (&b, 1, 1, z); + size |= b << 16; + zfile_fread (&b, 1, 1, z); + size |= b << 24; + if (size < 8 || size > 64 * 1024 * 1024) /* safety check */ + return z; + zfile_fseek (z, offset, SEEK_SET); + z2 = zfile_fopen_empty (z, name, size); + if (!z2) + return z; + zs.next_out = z2->data; + zs.avail_out = size; + first = 1; do { - b = 0; - zfile_fread (&b, 1, 1, z); - } while (b); - } - offset = zfile_ftell (z); - zfile_fseek (z, -4, SEEK_END); - zfile_fread (&b, 1, 1, z); - size = b; - zfile_fread (&b, 1, 1, z); - size |= b << 8; - zfile_fread (&b, 1, 1, z); - size |= b << 16; - zfile_fread (&b, 1, 1, z); - size |= b << 24; - if (size < 8 || size > 64 * 1024 * 1024) /* safety check */ - return z; - zfile_fseek (z, offset, SEEK_SET); - z2 = zfile_fopen_empty (z, name, size); - if (!z2) - return z; - zs.next_out = z2->data; - zs.avail_out = size; - first = 1; - do { - zs.next_in = buffer; - zs.avail_in = zfile_fread (buffer, 1, sizeof (buffer), z); - if (first) { - if (inflateInit2_ (&zs, -MAX_WBITS, ZLIB_VERSION, sizeof (z_stream)) != Z_OK) - break; - first = 0; - } - ret = inflate (&zs, 0); - } while (ret == Z_OK); - inflateEnd (&zs); - if (ret != Z_STREAM_END || first != 0) { - zfile_fclose (z2); - return z; - } - zfile_fclose (z); - return z2; + zs.next_in = buffer; + zs.avail_in = zfile_fread (buffer, 1, sizeof (buffer), z); + if (first) { + if (inflateInit2_ (&zs, -MAX_WBITS, ZLIB_VERSION, sizeof (z_stream)) != Z_OK) + break; + first = 0; + } + ret = inflate (&zs, 0); + } while (ret == Z_OK); + inflateEnd (&zs); + if (ret != Z_STREAM_END || first != 0) { + zfile_fclose (z2); + return z; + } + zfile_fclose (z); + return z2; } static struct zfile *extadf (struct zfile *z, int pctype) { - int i, r; - struct zfile *zo; - uae_u16 *mfm; - uae_u16 *amigamfmbuffer; - uae_u8 writebuffer_ok[32], *outbuf; - int tracks, len, offs, pos; - uae_u8 buffer[2 + 2 + 4 + 4]; - int outsize; - TCHAR newname[MAX_DPATH]; - TCHAR *ext; - - //pctype = 1; - - mfm = xcalloc (32000, 1); - amigamfmbuffer = xcalloc (32000, 1); - outbuf = xcalloc (16384, 1); - - zfile_fread (buffer, 1, 8, z); - zfile_fread (buffer, 1, 4, z); - tracks = buffer[2] * 256 + buffer[3]; - offs = 8 + 2 + 2 + tracks * (2 + 2 + 4 + 4); - - _tcscpy (newname, zfile_getname (z)); - ext = _tcsrchr (newname, '.'); - if (ext) { - _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".ext.adf"); - } else { - _tcscat (newname, L".adf"); - } - zo = zfile_fopen_empty (z, newname, 0); - if (!zo) - goto end; - - pos = 12; - outsize = 0; - for (i = 0; i < tracks; i++) { - int type, bitlen; - - zfile_fseek (z, pos, SEEK_SET); - zfile_fread (buffer, 2 + 2 + 4 + 4, 1, z); - pos = zfile_ftell (z); - type = buffer[2] * 256 + buffer[3]; - len = buffer[5] * 65536 + buffer[6] * 256 + buffer[7]; - bitlen = buffer[9] * 65536 + buffer[10] * 256 + buffer[11]; - - zfile_fseek (z, offs, SEEK_SET); - if (type == 1) { - zfile_fread (mfm, len, 1, z); - memset (writebuffer_ok, 0, sizeof writebuffer_ok); - memset (outbuf, 0, 16384); - if (pctype <= 0) { - r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); - if (r < 0 && i == 0) { - zfile_seterror (L"'%s' is not AmigaDOS formatted", zo->name); - goto end; - } - } else { - r = ispctrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); - if (r < 0 && i == 0) { - zfile_seterror (L"'%s' is not PC formatted", zo->name); - goto end; - } - } + int i, r; + struct zfile *zo; + uae_u16 *mfm; + uae_u16 *amigamfmbuffer; + uae_u8 writebuffer_ok[32], *outbuf; + int tracks, len, offs, pos; + uae_u8 buffer[2 + 2 + 4 + 4]; + int outsize; + TCHAR newname[MAX_DPATH]; + TCHAR *ext; + + //pctype = 1; + + mfm = xcalloc (32000, 1); + amigamfmbuffer = xcalloc (32000, 1); + outbuf = xcalloc (16384, 1); + + zfile_fread (buffer, 1, 8, z); + zfile_fread (buffer, 1, 4, z); + tracks = buffer[2] * 256 + buffer[3]; + offs = 8 + 2 + 2 + tracks * (2 + 2 + 4 + 4); + + _tcscpy (newname, zfile_getname (z)); + ext = _tcsrchr (newname, '.'); + if (ext) { + _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".ext.adf"); } else { - outsize = 512 * 11; - zfile_fread (outbuf, outsize, 1, z); + _tcscat (newname, L".adf"); } - zfile_fwrite (outbuf, outsize, 1, zo); + zo = zfile_fopen_empty (z, newname, 0); + if (!zo) + goto end; + + pos = 12; + outsize = 0; + for (i = 0; i < tracks; i++) { + int type, bitlen; + + zfile_fseek (z, pos, SEEK_SET); + zfile_fread (buffer, 2 + 2 + 4 + 4, 1, z); + pos = zfile_ftell (z); + type = buffer[2] * 256 + buffer[3]; + len = buffer[5] * 65536 + buffer[6] * 256 + buffer[7]; + bitlen = buffer[9] * 65536 + buffer[10] * 256 + buffer[11]; + + zfile_fseek (z, offs, SEEK_SET); + if (type == 1) { + zfile_fread (mfm, len, 1, z); + memset (writebuffer_ok, 0, sizeof writebuffer_ok); + memset (outbuf, 0, 16384); + if (pctype <= 0) { + r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); + if (r < 0 && i == 0) { + zfile_seterror (L"'%s' is not AmigaDOS formatted", zo->name); + goto end; + } + } else { + r = ispctrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); + if (r < 0 && i == 0) { + zfile_seterror (L"'%s' is not PC formatted", zo->name); + goto end; + } + } + } else { + outsize = 512 * 11; + zfile_fread (outbuf, outsize, 1, z); + } + zfile_fwrite (outbuf, outsize, 1, zo); - offs += len; + offs += len; - } - zfile_fclose (z); - xfree (mfm); - xfree (amigamfmbuffer); - return zo; + } + zfile_fclose (z); + xfree (mfm); + xfree (amigamfmbuffer); + return zo; end: - zfile_fclose (zo); - xfree (mfm); - xfree (amigamfmbuffer); - return z; + zfile_fclose (zo); + xfree (mfm); + xfree (amigamfmbuffer); + return z; } #include "fdi2raw.h" static struct zfile *fdi (struct zfile *z, int type) { - int i, j, r; - struct zfile *zo; - TCHAR *orgname = zfile_getname (z); - TCHAR *ext = _tcsrchr (orgname, '.'); - TCHAR newname[MAX_DPATH]; - uae_u16 *mfm; - uae_u16 *amigamfmbuffer; - uae_u8 writebuffer_ok[32], *outbuf; - int tracks, len, outsize; - FDI *fdi; - - fdi = fdi2raw_header (z); - if (!fdi) - return z; - mfm = xcalloc (32000, 1); - amigamfmbuffer = xcalloc (32000, 1); - outbuf = xcalloc (16384, 1); - tracks = fdi2raw_get_last_track (fdi); - if (ext) { - _tcscpy (newname, orgname); - _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); - } else { - _tcscat (newname, L".adf"); - } - zo = zfile_fopen_empty (z, newname, 0); - if (!zo) - goto end; - outsize = 0; - for (i = 0; i < tracks; i++) { - uae_u8 *p = (uae_u8*)mfm; - fdi2raw_loadtrack (fdi, mfm, NULL, i, &len, NULL, NULL, 1); - len /= 8; - for (j = 0; j < len / 2; j++) { - uae_u16 v = mfm[j]; - *p++ = v >> 8; - *p++ = v; - } - memset (writebuffer_ok, 0, sizeof writebuffer_ok); - memset (outbuf, 0, 16384); - if (type <= 0) { - r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); - if (r < 0 && i == 0) { - zfile_seterror (L"'%s' is not AmigaDOS formatted", orgname); - goto end; - } - } else if (type == 1) { - r = ispctrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); - if (r < 0 && i == 0) { - zfile_seterror (L"'%s' is not PC formatted", orgname); + int i, j, r; + struct zfile *zo; + TCHAR *orgname = zfile_getname (z); + TCHAR *ext = _tcsrchr (orgname, '.'); + TCHAR newname[MAX_DPATH]; + uae_u16 *mfm; + uae_u16 *amigamfmbuffer; + uae_u8 writebuffer_ok[32], *outbuf; + int tracks, len, outsize; + FDI *fdi; + + fdi = fdi2raw_header (z); + if (!fdi) + return z; + mfm = xcalloc (32000, 1); + amigamfmbuffer = xcalloc (32000, 1); + outbuf = xcalloc (16384, 1); + tracks = fdi2raw_get_last_track (fdi); + if (ext) { + _tcscpy (newname, orgname); + _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); + } else { + _tcscat (newname, L".adf"); + } + zo = zfile_fopen_empty (z, newname, 0); + if (!zo) goto end; - } - } - zfile_fwrite (outbuf, outsize, 1, zo); - } - zfile_fclose (z); - fdi2raw_header_free (fdi); - xfree (mfm); - xfree (amigamfmbuffer); - xfree (outbuf); - return zo; + outsize = 0; + for (i = 0; i < tracks; i++) { + uae_u8 *p = (uae_u8*)mfm; + fdi2raw_loadtrack (fdi, mfm, NULL, i, &len, NULL, NULL, 1); + len /= 8; + for (j = 0; j < len / 2; j++) { + uae_u16 v = mfm[j]; + *p++ = v >> 8; + *p++ = v; + } + memset (writebuffer_ok, 0, sizeof writebuffer_ok); + memset (outbuf, 0, 16384); + if (type <= 0) { + r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); + if (r < 0 && i == 0) { + zfile_seterror (L"'%s' is not AmigaDOS formatted", orgname); + goto end; + } + } else if (type == 1) { + r = ispctrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); + if (r < 0 && i == 0) { + zfile_seterror (L"'%s' is not PC formatted", orgname); + goto end; + } + } + zfile_fwrite (outbuf, outsize, 1, zo); + } + zfile_fclose (z); + fdi2raw_header_free (fdi); + xfree (mfm); + xfree (amigamfmbuffer); + xfree (outbuf); + return zo; end: - if (zo) - zfile_fclose (zo); - fdi2raw_header_free (fdi); - xfree (mfm); - xfree (amigamfmbuffer); - xfree (outbuf); - return z; + if (zo) + zfile_fclose (zo); + fdi2raw_header_free (fdi); + xfree (mfm); + xfree (amigamfmbuffer); + xfree (outbuf); + return z; } #ifdef CAPS #include "caps/caps_win32.h" static struct zfile *ipf (struct zfile *z, int type) { - int i, j, r; - struct zfile *zo; - TCHAR *orgname = zfile_getname (z); - TCHAR *ext = _tcsrchr (orgname, '.'); - TCHAR newname[MAX_DPATH]; - uae_u16 *mfm; - uae_u16 *amigamfmbuffer; - uae_u8 writebuffer_ok[32]; - int tracks, len; - int outsize; - uae_u8 *outbuf; - - if (!caps_loadimage (z, 0, &tracks)) - return z; - mfm = xcalloc (32000, 1); - outbuf = xcalloc (16384, 1); - amigamfmbuffer = xcalloc (32000, 1); - if (ext) { - _tcscpy (newname, orgname); - _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); - } else { - _tcscat (newname, L".adf"); - } - zo = zfile_fopen_empty (z, newname, 0); - if (!zo) - goto end; - outsize = 0; - for (i = 0; i < tracks; i++) { - uae_u8 *p = (uae_u8*)mfm; - caps_loadrevolution (mfm, 0, i, &len); - len /= 8; - for (j = 0; j < len / 2; j++) { - uae_u16 v = mfm[j]; - *p++ = v >> 8; - *p++ = v; - } - memset (writebuffer_ok, 0, sizeof writebuffer_ok); - memset (outbuf, 0, 16384); - r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); - if (r < 0 && i == 0) { - zfile_seterror (L"'%s' is not AmigaDOS formatted", orgname); - goto end; - } - zfile_fwrite (outbuf, 1, outsize, zo); - } - caps_unloadimage (0); - zfile_fclose (z); - xfree (mfm); - xfree (amigamfmbuffer); - xfree (outbuf); - return zo; + int i, j, r; + struct zfile *zo; + TCHAR *orgname = zfile_getname (z); + TCHAR *ext = _tcsrchr (orgname, '.'); + TCHAR newname[MAX_DPATH]; + uae_u16 *mfm; + uae_u16 *amigamfmbuffer; + uae_u8 writebuffer_ok[32]; + int tracks, len; + int outsize; + uae_u8 *outbuf; + + if (!caps_loadimage (z, 0, &tracks)) + return z; + mfm = xcalloc (32000, 1); + outbuf = xcalloc (16384, 1); + amigamfmbuffer = xcalloc (32000, 1); + if (ext) { + _tcscpy (newname, orgname); + _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); + } else { + _tcscat (newname, L".adf"); + } + zo = zfile_fopen_empty (z, newname, 0); + if (!zo) + goto end; + outsize = 0; + for (i = 0; i < tracks; i++) { + uae_u8 *p = (uae_u8*)mfm; + caps_loadrevolution (mfm, 0, i, &len); + len /= 8; + for (j = 0; j < len / 2; j++) { + uae_u16 v = mfm[j]; + *p++ = v >> 8; + *p++ = v; + } + memset (writebuffer_ok, 0, sizeof writebuffer_ok); + memset (outbuf, 0, 16384); + r = isamigatrack (amigamfmbuffer, (uae_u8*)mfm, len, outbuf, writebuffer_ok, i, &outsize); + if (r < 0 && i == 0) { + zfile_seterror (L"'%s' is not AmigaDOS formatted", orgname); + goto end; + } + zfile_fwrite (outbuf, 1, outsize, zo); + } + caps_unloadimage (0); + zfile_fclose (z); + xfree (mfm); + xfree (amigamfmbuffer); + xfree (outbuf); + return zo; end: - if (zo) - zfile_fclose (zo); - caps_unloadimage (0); - xfree (mfm); - xfree (amigamfmbuffer); - xfree (outbuf); - return z; + if (zo) + zfile_fclose (zo); + caps_unloadimage (0); + xfree (mfm); + xfree (amigamfmbuffer); + xfree (outbuf); + return z; } #endif static struct zfile *dsq (struct zfile *z, int lzx) { - struct zfile *zi = NULL; - struct zvolume *zv = NULL; - - if (lzx) { - zv = archive_directory_lzx (z); - if (zv) { - if (zv->root.child) - zi = archive_access_lzx (zv->root.child); - } - } else { - zi = z; - } - if (zi) { - uae_u8 *buf = zfile_getdata (zi, 0, -1); - if (!memcmp (buf, "PKD\x13", 4) || !memcmp (buf, "PKD\x11", 4)) { - TCHAR *fn; - int sectors = buf[18]; - int heads = buf[15]; - int blocks = (buf[6] << 8) | buf[7]; - int blocksize = (buf[10] << 8) | buf[11]; - struct zfile *zo; - int size = blocks * blocksize; - int off = buf[3] == 0x13 ? 52 : 32; - int i; - - if (size < 1760 * 512) - size = 1760 * 512; - - if (zfile_getfilename (zi) && _tcslen (zfile_getfilename (zi))) { - fn = xmalloc ((_tcslen (zfile_getfilename (zi)) + 5) * sizeof (TCHAR)); - _tcscpy (fn, zfile_getfilename (zi)); - _tcscat (fn, L".adf"); - } else { - fn = my_strdup (L"dsq.adf"); - } - zo = zfile_fopen_empty (z, fn, size); - xfree (fn); - for (i = 0; i < blocks / (sectors / heads); i++) { - zfile_fwrite (buf + off, sectors * blocksize / heads, 1, zo); - off += sectors * (blocksize + 16) / heads; - } - zfile_fclose_archive (zv); - zfile_fclose (z); - xfree (buf); - return zo; - } - xfree (buf); - } - if (lzx) - zfile_fclose (zi); - return z; + struct zfile *zi = NULL; + struct zvolume *zv = NULL; + + if (lzx) { + zv = archive_directory_lzx (z); + if (zv) { + if (zv->root.child) + zi = archive_access_lzx (zv->root.child); + } + } else { + zi = z; + } + if (zi) { + uae_u8 *buf = zfile_getdata (zi, 0, -1); + if (!memcmp (buf, "PKD\x13", 4) || !memcmp (buf, "PKD\x11", 4)) { + TCHAR *fn; + int sectors = buf[18]; + int heads = buf[15]; + int blocks = (buf[6] << 8) | buf[7]; + int blocksize = (buf[10] << 8) | buf[11]; + struct zfile *zo; + int size = blocks * blocksize; + int off = buf[3] == 0x13 ? 52 : 32; + int i; + + if (size < 1760 * 512) + size = 1760 * 512; + + if (zfile_getfilename (zi) && _tcslen (zfile_getfilename (zi))) { + fn = xmalloc ((_tcslen (zfile_getfilename (zi)) + 5) * sizeof (TCHAR)); + _tcscpy (fn, zfile_getfilename (zi)); + _tcscat (fn, L".adf"); + } else { + fn = my_strdup (L"dsq.adf"); + } + zo = zfile_fopen_empty (z, fn, size); + xfree (fn); + for (i = 0; i < blocks / (sectors / heads); i++) { + zfile_fwrite (buf + off, sectors * blocksize / heads, 1, zo); + off += sectors * (blocksize + 16) / heads; + } + zfile_fclose_archive (zv); + zfile_fclose (z); + xfree (buf); + return zo; + } + xfree (buf); + } + if (lzx) + zfile_fclose (zi); + return z; } static struct zfile *wrp (struct zfile *z) { - return unwarp (z); + return unwarp (z); } static struct zfile *dms (struct zfile *z) { - int ret; - struct zfile *zo; - TCHAR *orgname = zfile_getname (z); - TCHAR *ext = _tcsrchr (orgname, '.'); - TCHAR newname[MAX_DPATH]; - static int recursive; + int ret; + struct zfile *zo; + TCHAR *orgname = zfile_getname (z); + TCHAR *ext = _tcsrchr (orgname, '.'); + TCHAR newname[MAX_DPATH]; + static int recursive; - if (recursive) - return NULL; - if (ext) { - _tcscpy (newname, orgname); - _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); - } else { - _tcscat (newname, L".adf"); - } - - zo = zfile_fopen_empty (z, newname, 1760 * 512); - if (!zo) - return z; - ret = DMS_Process_File (z, zo, CMD_UNPACK, OPT_VERBOSE, 0, 0, 0); - if (ret == NO_PROBLEM || ret == DMS_FILE_END) { - int off = zfile_ftell (zo); - if (off >= 1760 * 512 / 3 && off <= 1760 * 512 * 3 / 4) { // possible split dms? - if (_tcslen (orgname) > 5) { - TCHAR *s = orgname + _tcslen (orgname) - 5; - if (!_tcsicmp (s, L"a.dms")) { - TCHAR *fn2 = my_strdup (orgname); - struct zfile *z2; - fn2[_tcslen (fn2) - 5]++; - recursive++; - z2 = zfile_fopen (fn2, L"rb", z->zfdmask); - recursive--; - if (z2) { - ret = DMS_Process_File (z2, zo, CMD_UNPACK, OPT_VERBOSE, 0, 0, 1); - zfile_fclose (z2); - } - xfree (fn2); - } - } + if (recursive) + return NULL; + if (ext) { + _tcscpy (newname, orgname); + _tcscpy (newname + _tcslen (newname) - _tcslen (ext), L".adf"); + } else { + _tcscat (newname, L".adf"); + } + + zo = zfile_fopen_empty (z, newname, 1760 * 512); + if (!zo) + return z; + ret = DMS_Process_File (z, zo, CMD_UNPACK, OPT_VERBOSE, 0, 0, 0); + if (ret == NO_PROBLEM || ret == DMS_FILE_END) { + int off = zfile_ftell (zo); + if (off >= 1760 * 512 / 3 && off <= 1760 * 512 * 3 / 4) { // possible split dms? + if (_tcslen (orgname) > 5) { + TCHAR *s = orgname + _tcslen (orgname) - 5; + if (!_tcsicmp (s, L"a.dms")) { + TCHAR *fn2 = my_strdup (orgname); + struct zfile *z2; + fn2[_tcslen (fn2) - 5]++; + recursive++; + z2 = zfile_fopen (fn2, L"rb", z->zfdmask); + recursive--; + if (z2) { + ret = DMS_Process_File (z2, zo, CMD_UNPACK, OPT_VERBOSE, 0, 0, 1); + zfile_fclose (z2); + } + xfree (fn2); + } + } + } + zfile_fclose (z); + zfile_fseek (zo, 0, SEEK_SET); + return zo; } - zfile_fclose (z); - zfile_fseek (zo, 0, SEEK_SET); - return zo; - } - return z; + return z; } const TCHAR *uae_ignoreextensions[] = - { L".gif", L".jpg", L".png", L".xml", L".pdf", L".txt", 0 }; +{ L".gif", L".jpg", L".png", L".xml", L".pdf", L".txt", 0 }; const TCHAR *uae_diskimageextensions[] = - { L".adf", L".adz", L".ipf", L".fdi", L".exe", L".dms", L".wrp", L".dsq", 0 }; +{ L".adf", L".adz", L".ipf", L".fdi", L".exe", L".dms", L".wrp", L".dsq", 0 }; int zfile_is_ignore_ext (const TCHAR *name) { - int i; + int i; - for (i = 0; uae_ignoreextensions[i]; i++) { - if (_tcslen(name) > _tcslen (uae_ignoreextensions[i]) && - !strcasecmp (uae_ignoreextensions[i], name + _tcslen (name) - _tcslen (uae_ignoreextensions[i]))) - return 1; - } - return 0; + for (i = 0; uae_ignoreextensions[i]; i++) { + if (_tcslen(name) > _tcslen (uae_ignoreextensions[i]) && + !strcasecmp (uae_ignoreextensions[i], name + _tcslen (name) - _tcslen (uae_ignoreextensions[i]))) + return 1; + } + return 0; } int zfile_is_diskimage (const TCHAR *name) { - int i; + int i; - i = 0; - while (uae_diskimageextensions[i]) { - if (_tcslen (name) > 3 && !strcasecmp (name + _tcslen (name) - 4, uae_diskimageextensions[i])) - return 1; - i++; - } - return 0; + i = 0; + while (uae_diskimageextensions[i]) { + if (_tcslen (name) > 3 && !strcasecmp (name + _tcslen (name) - 4, uae_diskimageextensions[i])) + return 1; + i++; + } + return 0; } static const TCHAR *plugins_7z[] = { L"7z", L"rar", L"zip", L"lha", L"lzh", L"lzx", L"adf", L"dsq", L"hdf", NULL }; static const uae_char *plugins_7z_x[] = { "7z", "Rar!", "MK", NULL, NULL, NULL, NULL, NULL, NULL, NULL }; static const int plugins_7z_t[] = { - ArchiveFormat7Zip, ArchiveFormatRAR, ArchiveFormatZIP, ArchiveFormatLHA, ArchiveFormatLHA, ArchiveFormatLZX, - ArchiveFormatADF, ArchiveFormatADF, ArchiveFormatADF }; + ArchiveFormat7Zip, ArchiveFormatRAR, ArchiveFormatZIP, ArchiveFormatLHA, ArchiveFormatLHA, ArchiveFormatLZX, + ArchiveFormatADF, ArchiveFormatADF, ArchiveFormatADF +}; static const int plugins_7z_m[] = { - ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, - ZFD_ADF, ZFD_ADF, ZFD_ADF }; + ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, ZFD_ARCHIVE, + ZFD_ADF, ZFD_ADF, ZFD_ADF +}; int iszip (struct zfile *z) { - TCHAR *name = z->name; - TCHAR *ext = _tcsrchr (name, '.'); - uae_u8 header[32]; - int i; - int mask = z->zfdmask; + TCHAR *name = z->name; + TCHAR *ext = _tcsrchr (name, '.'); + uae_u8 header[32]; + int i; + int mask = z->zfdmask; - if (!mask) - return 0; - if (!ext) - return 0; - memset (header, 0, sizeof (header)); - zfile_fseek (z, 0, SEEK_SET); - zfile_fread (header, sizeof (header), 1, z); - zfile_fseek (z, 0, SEEK_SET); - - if (mask & ZFD_ARCHIVE) { - if (!strcasecmp (ext, L".zip")) { - if (header[0] == 'P' && header[1] == 'K') - return ArchiveFormatZIP; - return 0; - } - } - if (mask & ZFD_ARCHIVE) { - if (!strcasecmp (ext, L".7z")) { - if (header[0] == '7' && header[1] == 'z') - return ArchiveFormat7Zip; - return 0; - } - if (!strcasecmp (ext, L".rar")) { - if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') - return ArchiveFormatRAR; - return 0; - } - if (!strcasecmp (ext, L".lha") || !strcasecmp (ext, L".lzh")) { - if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') - return ArchiveFormatLHA; - return 0; - } - if (!strcasecmp (ext, L".lzx")) { - if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') - return ArchiveFormatLZX; - return 0; - } - } - if (mask & ZFD_ADF) { - if (!strcasecmp (ext, L".adf")) { - if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) - return ArchiveFormatADF; - if (isfat (header)) - return ArchiveFormatFAT; - return 0; - } - } - if (mask & ZFD_HD) { - if (!strcasecmp (ext, L".hdf")) { - if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) - return ArchiveFormatADF; - if (header[0] == 'S' && header[1] == 'F' && header[2] == 'S') - return ArchiveFormatADF; - if (header[0] == 'R' && header[1] == 'D' && header[2] == 'S' && header[3] == 'K') - return ArchiveFormatRDB; - if (isfat (header)) - return ArchiveFormatFAT; - return 0; - } - } + if (!mask) + return 0; + if (!ext) + return 0; + memset (header, 0, sizeof (header)); + zfile_fseek (z, 0, SEEK_SET); + zfile_fread (header, sizeof (header), 1, z); + zfile_fseek (z, 0, SEEK_SET); + + if (mask & ZFD_ARCHIVE) { + if (!strcasecmp (ext, L".zip")) { + if (header[0] == 'P' && header[1] == 'K') + return ArchiveFormatZIP; + return 0; + } + } + if (mask & ZFD_ARCHIVE) { + if (!strcasecmp (ext, L".7z")) { + if (header[0] == '7' && header[1] == 'z') + return ArchiveFormat7Zip; + return 0; + } + if (!strcasecmp (ext, L".rar")) { + if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') + return ArchiveFormatRAR; + return 0; + } + if (!strcasecmp (ext, L".lha") || !strcasecmp (ext, L".lzh")) { + if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') + return ArchiveFormatLHA; + return 0; + } + if (!strcasecmp (ext, L".lzx")) { + if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') + return ArchiveFormatLZX; + return 0; + } + } + if (mask & ZFD_ADF) { + if (!strcasecmp (ext, L".adf")) { + if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) + return ArchiveFormatADF; + if (isfat (header)) + return ArchiveFormatFAT; + return 0; + } + } + if (mask & ZFD_HD) { + if (!strcasecmp (ext, L".hdf")) { + if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) + return ArchiveFormatADF; + if (header[0] == 'S' && header[1] == 'F' && header[2] == 'S') + return ArchiveFormatADF; + if (header[0] == 'R' && header[1] == 'D' && header[2] == 'S' && header[3] == 'K') + return ArchiveFormatRDB; + if (isfat (header)) + return ArchiveFormatFAT; + return 0; + } + } #if defined(ARCHIVEACCESS) - for (i = 0; plugins_7z_x[i]; i++) { - if ((plugins_7z_m[i] & mask) && plugins_7z_x[i] && !strcasecmp (ext + 1, plugins_7z[i]) && - !memcmp (header, plugins_7z_x[i], strlen (plugins_7z_x[i]))) - return plugins_7z_t[i]; - } + for (i = 0; plugins_7z_x[i]; i++) { + if ((plugins_7z_m[i] & mask) && plugins_7z_x[i] && !strcasecmp (ext + 1, plugins_7z[i]) && + !memcmp (header, plugins_7z_x[i], strlen (plugins_7z_x[i]))) + return plugins_7z_t[i]; + } #endif - return 0; + return 0; } struct zfile *zuncompress (struct znode *parent, struct zfile *z, int dodefault, int mask, int *retcode) { - TCHAR *name = z->name; - TCHAR *ext = NULL; - uae_u8 header[32]; - int i; - - if (retcode) - *retcode = 0; - if (!mask) - return NULL; - if (name) { - ext = _tcsrchr (name, '.'); - if (ext) - ext++; - } + TCHAR *name = z->name; + TCHAR *ext = NULL; + uae_u8 header[32]; + int i; - if (ext != NULL) { - if (mask & ZFD_ARCHIVE) { - if (strcasecmp (ext, L"7z") == 0) - return archive_access_select (parent, z, ArchiveFormat7Zip, dodefault, retcode); - if (strcasecmp (ext, L"zip") == 0) - return archive_access_select (parent, z, ArchiveFormatZIP, dodefault, retcode); - if (strcasecmp (ext, L"lha") == 0 || strcasecmp (ext, L"lzh") == 0) - return archive_access_select (parent, z, ArchiveFormatLHA, dodefault, retcode); - if (strcasecmp (ext, L"lzx") == 0) - return archive_access_select (parent, z, ArchiveFormatLZX, dodefault, retcode); - if (strcasecmp (ext, L"rar") == 0) - return archive_access_select (parent, z, ArchiveFormatRAR, dodefault, retcode); - } - if (mask & ZFD_UNPACK) { - if (strcasecmp (ext, L"gz") == 0) - return zfile_gunzip (z); - if (strcasecmp (ext, L"adz") == 0) - return zfile_gunzip (z); - if (strcasecmp (ext, L"roz") == 0) - return zfile_gunzip (z); - if (strcasecmp (ext, L"hdz") == 0) - return zfile_gunzip (z); - if (strcasecmp (ext, L"dms") == 0) - return dms (z); - if (strcasecmp (ext, L"wrp") == 0) - return wrp (z); - } - if (mask & ZFD_RAWDISK) { + if (retcode) + *retcode = 0; + if (!mask) + return NULL; + if (name) { + ext = _tcsrchr (name, '.'); + if (ext) + ext++; + } + + if (ext != NULL) { + if (mask & ZFD_ARCHIVE) { + if (strcasecmp (ext, L"7z") == 0) + return archive_access_select (parent, z, ArchiveFormat7Zip, dodefault, retcode); + if (strcasecmp (ext, L"zip") == 0) + return archive_access_select (parent, z, ArchiveFormatZIP, dodefault, retcode); + if (strcasecmp (ext, L"lha") == 0 || strcasecmp (ext, L"lzh") == 0) + return archive_access_select (parent, z, ArchiveFormatLHA, dodefault, retcode); + if (strcasecmp (ext, L"lzx") == 0) + return archive_access_select (parent, z, ArchiveFormatLZX, dodefault, retcode); + if (strcasecmp (ext, L"rar") == 0) + return archive_access_select (parent, z, ArchiveFormatRAR, dodefault, retcode); + } + if (mask & ZFD_UNPACK) { + if (strcasecmp (ext, L"gz") == 0) + return zfile_gunzip (z); + if (strcasecmp (ext, L"adz") == 0) + return zfile_gunzip (z); + if (strcasecmp (ext, L"roz") == 0) + return zfile_gunzip (z); + if (strcasecmp (ext, L"hdz") == 0) + return zfile_gunzip (z); + if (strcasecmp (ext, L"dms") == 0) + return dms (z); + if (strcasecmp (ext, L"wrp") == 0) + return wrp (z); + } + if (mask & ZFD_RAWDISK) { #ifdef CAPS - if (strcasecmp (ext, L"ipf") == 0) { - if (mask & ZFD_RAWDISK_PC) - return ipf (z, 1); - else if (mask & ZFD_RAWDISK_AMIGA) - return ipf (z, 0); - else - return ipf (z, -1); - } + if (strcasecmp (ext, L"ipf") == 0) { + if (mask & ZFD_RAWDISK_PC) + return ipf (z, 1); + else if (mask & ZFD_RAWDISK_AMIGA) + return ipf (z, 0); + else + return ipf (z, -1); + } #endif - if (strcasecmp (ext, L"fdi") == 0) { - if (mask & ZFD_RAWDISK_PC) - return fdi (z, 1); - else if (mask & ZFD_RAWDISK_AMIGA) - return fdi (z, 0); - else - return fdi (z, -1); - } - if (mask & (ZFD_RAWDISK_PC | ZFD_RAWDISK_AMIGA)) - return NULL; - } + if (strcasecmp (ext, L"fdi") == 0) { + if (mask & ZFD_RAWDISK_PC) + return fdi (z, 1); + else if (mask & ZFD_RAWDISK_AMIGA) + return fdi (z, 0); + else + return fdi (z, -1); + } + if (mask & (ZFD_RAWDISK_PC | ZFD_RAWDISK_AMIGA)) + return NULL; + } #if defined(ARCHIVEACCESS) - for (i = 0; plugins_7z_x[i]; i++) { - if ((plugins_7z_t[i] & mask) && strcasecmp (ext, plugins_7z[i]) == 0) - return archive_access_arcacc_select (z, plugins_7z_t[i], retcode); - } + for (i = 0; plugins_7z_x[i]; i++) { + if ((plugins_7z_t[i] & mask) && strcasecmp (ext, plugins_7z[i]) == 0) + return archive_access_arcacc_select (z, plugins_7z_t[i], retcode); + } #endif - } - memset (header, 0, sizeof (header)); - zfile_fseek (z, 0, SEEK_SET); - zfile_fread (header, sizeof (header), 1, z); - zfile_fseek (z, 0, SEEK_SET); - if (!memcmp (header, "conectix", 8)) - return vhd (z); - - if (mask & ZFD_UNPACK) { - if (header[0] == 0x1f && header[1] == 0x8b) - return zfile_gunzip (z); - if (header[0] == 'D' && header[1] == 'M' && header[2] == 'S' && header[3] == '!') - return dms (z); - if (header[0] == 'P' && header[1] == 'K' && header[2] == 'D') - return dsq (z, 0); - } - if (mask & ZFD_RAWDISK) { -#ifdef CAPS - if (header[0] == 'C' && header[1] == 'A' && header[2] == 'P' && header[3] == 'S') { - if (mask & ZFD_RAWDISK_PC) - return ipf (z, 1); - else if (mask & ZFD_RAWDISK_AMIGA) - return ipf (z, 0); - else - return ipf (z, -1); } -#endif - if (!memcmp (header, "Formatte", 8)) { - if (mask & ZFD_RAWDISK_PC) - return fdi (z, 1); - else if (mask & ZFD_RAWDISK_AMIGA) - return fdi (z, 0); - else - return fdi (z, -1); - } - if (!memcmp (header, "UAE-1ADF", 8)) { - if (mask & ZFD_RAWDISK_PC) - return extadf (z, 1); - else if (mask & ZFD_RAWDISK_AMIGA) - return extadf (z, 0); - else - return extadf (z, -1); - } - } - if (mask & ZFD_ARCHIVE) { - if (header[0] == 'P' && header[1] == 'K') - return archive_access_select (parent, z, ArchiveFormatZIP, dodefault, retcode); - if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') - return archive_access_select (parent, z, ArchiveFormatRAR, dodefault, retcode); - if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') - return archive_access_select (parent, z, ArchiveFormatLZX, dodefault, retcode); - if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') - return archive_access_select (parent, z, ArchiveFormatLHA, dodefault, retcode); - } - if (mask & ZFD_ADF) { - if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) - return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); - if (header[0] == 'S' && header[1] == 'F' && header[2] == 'S') - return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); - if (isfat (header)) - return archive_access_select (parent, z, ArchiveFormatFAT, dodefault, retcode); - } + memset (header, 0, sizeof (header)); + zfile_fseek (z, 0, SEEK_SET); + zfile_fread (header, sizeof (header), 1, z); + zfile_fseek (z, 0, SEEK_SET); + if (!memcmp (header, "conectix", 8)) + return vhd (z); - if (ext) { if (mask & ZFD_UNPACK) { - if (strcasecmp (ext, L"dsq") == 0) - return dsq (z, 1); + if (header[0] == 0x1f && header[1] == 0x8b) + return zfile_gunzip (z); + if (header[0] == 'D' && header[1] == 'M' && header[2] == 'S' && header[3] == '!') + return dms (z); + if (header[0] == 'P' && header[1] == 'K' && header[2] == 'D') + return dsq (z, 0); + } + if (mask & ZFD_RAWDISK) { +#ifdef CAPS + if (header[0] == 'C' && header[1] == 'A' && header[2] == 'P' && header[3] == 'S') { + if (mask & ZFD_RAWDISK_PC) + return ipf (z, 1); + else if (mask & ZFD_RAWDISK_AMIGA) + return ipf (z, 0); + else + return ipf (z, -1); + } +#endif + if (!memcmp (header, "Formatte", 8)) { + if (mask & ZFD_RAWDISK_PC) + return fdi (z, 1); + else if (mask & ZFD_RAWDISK_AMIGA) + return fdi (z, 0); + else + return fdi (z, -1); + } + if (!memcmp (header, "UAE-1ADF", 8)) { + if (mask & ZFD_RAWDISK_PC) + return extadf (z, 1); + else if (mask & ZFD_RAWDISK_AMIGA) + return extadf (z, 0); + else + return extadf (z, -1); + } + } + if (mask & ZFD_ARCHIVE) { + if (header[0] == 'P' && header[1] == 'K') + return archive_access_select (parent, z, ArchiveFormatZIP, dodefault, retcode); + if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') + return archive_access_select (parent, z, ArchiveFormatRAR, dodefault, retcode); + if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') + return archive_access_select (parent, z, ArchiveFormatLZX, dodefault, retcode); + if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') + return archive_access_select (parent, z, ArchiveFormatLHA, dodefault, retcode); } if (mask & ZFD_ADF) { - if (strcasecmp (ext, L"adf") == 0 && !memcmp (header, "DOS", 3)) - return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); + if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) + return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); + if (header[0] == 'S' && header[1] == 'F' && header[2] == 'S') + return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); + if (isfat (header)) + return archive_access_select (parent, z, ArchiveFormatFAT, dodefault, retcode); + } + + if (ext) { + if (mask & ZFD_UNPACK) { + if (strcasecmp (ext, L"dsq") == 0) + return dsq (z, 1); + } + if (mask & ZFD_ADF) { + if (strcasecmp (ext, L"adf") == 0 && !memcmp (header, "DOS", 3)) + return archive_access_select (parent, z, ArchiveFormatADF, dodefault, retcode); + } } - } - return NULL; + return NULL; } @@ -1059,129 +1061,129 @@ extern uae_u8 singlefile_data[]; static struct zfile *zfile_opensinglefile(struct zfile *l) { - uae_u8 *p = singlefile_data; - int size, offset; - TCHAR tmp[256], *s; - - _tcscpy (tmp, l->name); - s = tmp + _tcslen (tmp) - 1; - while (*s != 0 && *s != '/' && *s != '\\') - s--; - if (s > tmp) - s++; - write_log (L"loading from singlefile: '%s'\n", tmp); - while (*p++); - offset = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|(p[3] << 0); - p += 4; - for (;;) { - size = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|(p[3] << 0); - if (!size) - break; - if (!strcmpi (tmp, p + 4)) { - l->data = singlefile_data + offset; - l->size = size; - write_log (L"found, size %d\n", size); - return l; - } - offset += size; + uae_u8 *p = singlefile_data; + int size, offset; + TCHAR tmp[256], *s; + + _tcscpy (tmp, l->name); + s = tmp + _tcslen (tmp) - 1; + while (*s != 0 && *s != '/' && *s != '\\') + s--; + if (s > tmp) + s++; + write_log (L"loading from singlefile: '%s'\n", tmp); + while (*p++); + offset = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|(p[3] << 0); p += 4; - p += _tcslen (p) + 1; - } - write_log (L"not found\n"); - return 0; + for (;;) { + size = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|(p[3] << 0); + if (!size) + break; + if (!strcmpi (tmp, p + 4)) { + l->data = singlefile_data + offset; + l->size = size; + write_log (L"found, size %d\n", size); + return l; + } + offset += size; + p += 4; + p += _tcslen (p) + 1; + } + write_log (L"not found\n"); + return 0; } #endif static struct zfile *zfile_fopen_nozip (const TCHAR *name, const TCHAR *mode) { - struct zfile *l; - FILE *f; + struct zfile *l; + FILE *f; - if(*name == '\0') - return NULL; - l = zfile_create (NULL); - l->name = my_strdup (name); - l->mode = my_strdup (mode); - f = _tfopen (name, mode); - if (!f) { - zfile_fclose (l); - return 0; - } - l->f = f; - return l; + if(*name == '\0') + return NULL; + l = zfile_create (NULL); + l->name = my_strdup (name); + l->mode = my_strdup (mode); + f = _tfopen (name, mode); + if (!f) { + zfile_fclose (l); + return 0; + } + l->f = f; + return l; } static struct zfile *openzip (const TCHAR *pname) { - int i, j; - TCHAR v; - TCHAR name[MAX_DPATH]; - TCHAR zippath[MAX_DPATH]; - - zippath[0] = 0; - _tcscpy (name, pname); - i = _tcslen (name) - 2; - while (i > 0) { - if (name[i] == '/' || name[i] == '\\' && i > 4) { - v = name[i]; - name[i] = 0; - for (j = 0; plugins_7z[j]; j++) { - int len = _tcslen (plugins_7z[j]); - if (name[i - len - 1] == '.' && !strcasecmp (name + i - len, plugins_7z[j])) { - struct zfile *f = zfile_fopen_nozip (name, L"rb"); - if (f) { - f->zipname = my_strdup (name + i + 1); - return f; - } - break; + int i, j; + TCHAR v; + TCHAR name[MAX_DPATH]; + TCHAR zippath[MAX_DPATH]; + + zippath[0] = 0; + _tcscpy (name, pname); + i = _tcslen (name) - 2; + while (i > 0) { + if (name[i] == '/' || name[i] == '\\' && i > 4) { + v = name[i]; + name[i] = 0; + for (j = 0; plugins_7z[j]; j++) { + int len = _tcslen (plugins_7z[j]); + if (name[i - len - 1] == '.' && !strcasecmp (name + i - len, plugins_7z[j])) { + struct zfile *f = zfile_fopen_nozip (name, L"rb"); + if (f) { + f->zipname = my_strdup (name + i + 1); + return f; + } + break; + } + } + name[i] = v; } - } - name[i] = v; + i--; } - i--; - } - return 0; + return 0; } static struct zfile *zfile_fopen_2 (const TCHAR *name, const TCHAR *mode, int mask) { - struct zfile *l; - FILE *f; + struct zfile *l; + FILE *f; - if(*name == '\0') - return NULL; + if(*name == '\0') + return NULL; #ifdef SINGLEFILE - if (zfile_opensinglefile (l)) - return l; + if (zfile_opensinglefile (l)) + return l; #endif - l = openzip (name); - if (l) { - if (_tcsicmp (mode, L"rb") && _tcsicmp (mode, L"r")) { - zfile_fclose (l); - return 0; - } - l->zfdmask = mask; - } else { - struct _stat64 st; - l = zfile_create (NULL); - l->mode = my_strdup (mode); - l->name = my_strdup (name); - l->zfdmask = mask; - if (!_tcsicmp (mode, L"r")) { - f = my_opentext (l->name); - l->textmode = 1; + l = openzip (name); + if (l) { + if (_tcsicmp (mode, L"rb") && _tcsicmp (mode, L"r")) { + zfile_fclose (l); + return 0; + } + l->zfdmask = mask; } else { - f = _tfopen (l->name, mode); - } - if (!f) { - zfile_fclose (l); - return 0; + struct _stat64 st; + l = zfile_create (NULL); + l->mode = my_strdup (mode); + l->name = my_strdup (name); + l->zfdmask = mask; + if (!_tcsicmp (mode, L"r")) { + f = my_opentext (l->name); + l->textmode = 1; + } else { + f = _tfopen (l->name, mode); + } + if (!f) { + zfile_fclose (l); + return 0; + } + if (stat (l->name, &st) != -1) + l->size = st.st_size; + l->f = f; } - if (stat (l->name, &st) != -1) - l->size = st.st_size; - l->f = f; - } - return l; + return l; } #ifdef _WIN32 @@ -1191,1400 +1193,1402 @@ static struct zfile *zfile_fopen_2 (const TCHAR *name, const TCHAR *mode, int ma static void manglefilename (TCHAR *out, const TCHAR *in) { - int i; + int i; - out[0] = 0; - if (!strncasecmp (in, AF, _tcslen (AF))) - _tcscpy (out, start_path_data); - if ((in[0] == '/' || in[0] == '\\') || (_tcslen(in) > 3 && in[1] == ':' && in[2] == '\\')) out[0] = 0; - _tcscat (out, in); - for (i = 0; i < _tcslen (out); i++) { - if ((out[i] == '/' || out[i] == '\\') && (out[i + 1] == '/' || out[i + 1] == '\\')) { - memmove (out + i, out + i + 1, (_tcslen (out + i) + 1) * sizeof (TCHAR)); - i--; - continue; + if (!strncasecmp (in, AF, _tcslen (AF))) + _tcscpy (out, start_path_data); + if ((in[0] == '/' || in[0] == '\\') || (_tcslen(in) > 3 && in[1] == ':' && in[2] == '\\')) + out[0] = 0; + _tcscat (out, in); + for (i = 0; i < _tcslen (out); i++) { + // remove \\ or // in the middle of path + if ((out[i] == '/' || out[i] == '\\') && (out[i + 1] == '/' || out[i + 1] == '\\') && i > 0) { + memmove (out + i, out + i + 1, (_tcslen (out + i) + 1) * sizeof (TCHAR)); + i--; + continue; + } } - } } #else static void manglefilename(TCHAR *out, const TCHAR *in) { - _tcscpy (out, in); + _tcscpy (out, in); } #endif int zfile_zopen (const TCHAR *name, zfile_callback zc, void *user) { - struct zfile *l; - int ztype; - TCHAR path[MAX_DPATH]; - - manglefilename (path, name); - l = zfile_fopen_2 (path, L"rb", ZFD_NORMAL); - if (!l) - return 0; - ztype = iszip (l); - if (ztype == 0) - zc (l, user); - else - archive_access_scan (l, zc, user, ztype); - zfile_fclose (l); - return 1; + struct zfile *l; + int ztype; + TCHAR path[MAX_DPATH]; + + manglefilename (path, name); + l = zfile_fopen_2 (path, L"rb", ZFD_NORMAL); + if (!l) + return 0; + ztype = iszip (l); + if (ztype == 0) + zc (l, user); + else + archive_access_scan (l, zc, user, ztype); + zfile_fclose (l); + return 1; } /* - * fopen() for a compressed file - */ +* fopen() for a compressed file +*/ static struct zfile *zfile_fopen_x (const TCHAR *name, const TCHAR *mode, int mask) { - int cnt = 10; - struct zfile *l, *l2; - TCHAR path[MAX_DPATH]; + int cnt = 10; + struct zfile *l, *l2; + TCHAR path[MAX_DPATH]; - if (_tcslen (name) == 0) - return NULL; - manglefilename (path, name); - //write_log (L"zfile_fopen('%s','%s',%08x)\n", path, mode, mask); - l = zfile_fopen_2 (path, mode, mask); - if (!l) - return 0; - if (_tcschr (mode, 'w') || _tcschr (mode, 'a')) - return l; - l2 = NULL; - while (cnt-- > 0) { - int rc; - zfile_fseek (l, 0, SEEK_SET); - l2 = zuncompress (NULL, l, 0, mask, &rc); - if (!l2) { - if (rc < 0) { - zfile_fclose (l); + if (_tcslen (name) == 0) return NULL; - } - zfile_fseek (l, 0, SEEK_SET); - break; + manglefilename (path, name); + //write_log (L"zfile_fopen('%s','%s',%08x)\n", path, mode, mask); + l = zfile_fopen_2 (path, mode, mask); + if (!l) + return 0; + if (_tcschr (mode, 'w') || _tcschr (mode, 'a')) + return l; + l2 = NULL; + while (cnt-- > 0) { + int rc; + zfile_fseek (l, 0, SEEK_SET); + l2 = zuncompress (NULL, l, 0, mask, &rc); + if (!l2) { + if (rc < 0) { + zfile_fclose (l); + return NULL; + } + zfile_fseek (l, 0, SEEK_SET); + break; + } + l = l2; } - l = l2; - } - return l; + return l; } struct zfile *zfile_fopen (const TCHAR *name, const TCHAR *mode, int mask) { - struct zfile *f; - TCHAR tmp[MAX_DPATH]; - TCHAR dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' }; + struct zfile *f; + TCHAR tmp[MAX_DPATH]; + TCHAR dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' }; - f = zfile_fopen_x (name, mode, mask); - if (f) - return f; - if (_tcslen (name) <= 2) - return NULL; - if (name[1] != ':') { - _tcscpy (tmp, start_path_data); - _tcscat (tmp, name); - f = zfile_fopen_x (tmp, mode, mask); + f = zfile_fopen_x (name, mode, mask); if (f) - return f; - } + return f; + if (_tcslen (name) <= 2) + return NULL; + if (name[1] != ':') { + _tcscpy (tmp, start_path_data); + _tcscat (tmp, name); + f = zfile_fopen_x (tmp, mode, mask); + if (f) + return f; + } #if 0 - name += 2; - if (name[0] == '/' || name[0] == '\\') - name++; - for (;;) { - _tcscpy (tmp, start_path_data); - _tcscpy (tmp, name); - f = zfile_fopen_x (tmp, mode, mask); - if (f) - return f; - while (name[0]) { - name++; - if (name[-1] == '/' || name[-1] == '\\') - break; - } - if (name[0] == 0) - break; - } + name += 2; + if (name[0] == '/' || name[0] == '\\') + name++; + for (;;) { + _tcscpy (tmp, start_path_data); + _tcscpy (tmp, name); + f = zfile_fopen_x (tmp, mode, mask); + if (f) + return f; + while (name[0]) { + name++; + if (name[-1] == '/' || name[-1] == '\\') + break; + } + if (name[0] == 0) + break; + } #endif - return NULL; + return NULL; } struct zfile *zfile_dup (struct zfile *zf) { - struct zfile *nzf; - if (!zf) - return NULL; - if (zf->userdata) - return NULL; - if (!zf->data && zf->dataseek) { - nzf = zfile_create (zf); - } else if (zf->data) { - nzf = zfile_create (zf); - nzf->data = xmalloc (zf->size); - memcpy (nzf->data, zf->data, zf->size); - nzf->size = zf->size; - } else if (zf->zipname) { - nzf = openzip (zf->name); + struct zfile *nzf; + if (!zf) + return NULL; + if (zf->userdata) + return NULL; + if (!zf->data && zf->dataseek) { + nzf = zfile_create (zf); + } else if (zf->data) { + nzf = zfile_create (zf); + nzf->data = xmalloc (zf->size); + memcpy (nzf->data, zf->data, zf->size); + nzf->size = zf->size; + } else if (zf->zipname) { + nzf = openzip (zf->name); + return nzf; + } else { + nzf = zfile_create (zf); + nzf->f = _tfopen (zf->name, zf->mode); + } + zfile_fseek (nzf, zf->seek, SEEK_SET); + if (zf->name) + nzf->name = my_strdup (zf->name); + if (nzf->zipname) + nzf->zipname = my_strdup (zf->zipname); + nzf->zfdmask = zf->zfdmask; + nzf->mode = my_strdup (zf->mode); return nzf; - } else { - nzf = zfile_create (zf); - nzf->f = _tfopen (zf->name, zf->mode); - } - zfile_fseek (nzf, zf->seek, SEEK_SET); - if (zf->name) - nzf->name = my_strdup (zf->name); - if (nzf->zipname) - nzf->zipname = my_strdup (zf->zipname); - nzf->zfdmask = zf->zfdmask; - nzf->mode = my_strdup (zf->mode); - return nzf; } int zfile_exists (const TCHAR *name) { - struct zfile *z; + struct zfile *z; - if (my_existsfile (name)) + if (my_existsfile (name)) + return 1; + z = zfile_fopen (name, L"rb", ZFD_NORMAL | ZFD_CHECKONLY); + if (!z) + return 0; + zfile_fclose (z); return 1; - z = zfile_fopen (name, L"rb", ZFD_NORMAL | ZFD_CHECKONLY); - if (!z) - return 0; - zfile_fclose (z); - return 1; } int zfile_iscompressed (struct zfile *z) { - return z->data ? 1 : 0; + return z->data ? 1 : 0; } struct zfile *zfile_fopen_empty (struct zfile *prev, const TCHAR *name, uae_u64 size) { - struct zfile *l; - l = zfile_create (prev); - l->name = name ? my_strdup (name) : L""; - if (size) { - l->data = xcalloc (size, 1); - if (!l->data) { - xfree (l); - return NULL; + struct zfile *l; + l = zfile_create (prev); + l->name = name ? my_strdup (name) : L""; + if (size) { + l->data = xcalloc (size, 1); + if (!l->data) { + xfree (l); + return NULL; + } + l->size = size; + } else { + l->data = xcalloc (1, 1); + l->size = 0; } - l->size = size; - } else { - l->data = xcalloc (1, 1); - l->size = 0; - } - return l; + return l; } struct zfile *zfile_fopen_parent (struct zfile *z, const TCHAR *name, uae_u64 offset, uae_u64 size) { - struct zfile *l; + struct zfile *l; - l = zfile_create (z); - if (name) - l->name = my_strdup (name); - else if (z->name) - l->name = my_strdup (z->name); - l->size = size; - l->offset = offset; - for (;;) { - l->parent = z; - l->useparent = 1; - if (!z->parent) - break; - l->offset += z->offset; - z = z->parent; - } - z->opencnt++; - return l; + l = zfile_create (z); + if (name) + l->name = my_strdup (name); + else if (z->name) + l->name = my_strdup (z->name); + l->size = size; + l->offset = offset; + for (;;) { + l->parent = z; + l->useparent = 1; + if (!z->parent) + break; + l->offset += z->offset; + z = z->parent; + } + z->opencnt++; + return l; } struct zfile *zfile_fopen_data (const TCHAR *name, uae_u64 size, uae_u8 *data) { - struct zfile *l; + struct zfile *l; - l = zfile_create (NULL); - l->name = name ? my_strdup (name) : L""; - l->data = xmalloc (size); - l->size = size; - memcpy (l->data, data, size); - return l; + l = zfile_create (NULL); + l->name = name ? my_strdup (name) : L""; + l->data = xmalloc (size); + l->size = size; + memcpy (l->data, data, size); + return l; } uae_s64 zfile_ftell (struct zfile *z) { - uae_s64 v; - if (z->data || z->dataseek) - return z->seek; - if (z->parent) { - v = _ftelli64 (z->parent->f); - v -= z->offset; - } else { - v = _ftelli64 (z->f); - } - return v; + uae_s64 v; + if (z->data || z->dataseek) + return z->seek; + if (z->parent) { + v = _ftelli64 (z->parent->f); + v -= z->offset; + } else { + v = _ftelli64 (z->f); + } + return v; } uae_s64 zfile_fseek (struct zfile *z, uae_s64 offset, int mode) { - if (z->zfileseek) - return z->zfileseek (z, offset, mode); - if (z->data || z->dataseek) { - int ret = 0; - switch (mode) - { - case SEEK_SET: - z->seek = offset; - break; - case SEEK_CUR: - z->seek += offset; - break; - case SEEK_END: - z->seek = z->size + offset; - break; - } - if (z->seek < 0) { - z->seek = 0; - ret = 1; - } - if (z->seek > z->size) { - z->seek = z->size; - ret = 1; - } - return ret; - } else { - if (z->parent && z->useparent) { - switch (mode) - { + if (z->zfileseek) + return z->zfileseek (z, offset, mode); + if (z->data || z->dataseek) { + int ret = 0; + switch (mode) + { case SEEK_SET: - if (offset >= z->size) { - _fseeki64 (z->parent->f, z->offset + z->size, SEEK_SET); - return 1; - } else if (offset < 0) { - return 1; - } - return _fseeki64 (z->parent->f, offset + z->offset, SEEK_SET); - + z->seek = offset; + break; + case SEEK_CUR: + z->seek += offset; + break; case SEEK_END: - if (offset > 0) - return 1; - if (offset < -z->size) { - _fseeki64 (z->parent->f, z->offset, SEEK_SET); - return 1; + z->seek = z->size + offset; + break; } - return _fseeki64 (z->parent->f, offset + z->size + z->offset, SEEK_SET); - - case SEEK_CUR: - { - uae_s64 v = zfile_ftell (z->parent); - if (v + offset > z->size) { - _fseeki64 (z->parent->f, z->offset + z->size, SEEK_SET); - return 1; - } else if (v + offset < 0) { - _fseeki64 (z->parent->f, z->offset, SEEK_SET); - return 1; - } - return _fseeki64 (z->parent->f, v + offset + z->offset, SEEK_SET); + if (z->seek < 0) { + z->seek = 0; + ret = 1; } - } + if (z->seek > z->size) { + z->seek = z->size; + ret = 1; + } + return ret; } else { - return _fseeki64 (z->f, offset, mode); + if (z->parent && z->useparent) { + switch (mode) + { + case SEEK_SET: + if (offset >= z->size) { + _fseeki64 (z->parent->f, z->offset + z->size, SEEK_SET); + return 1; + } else if (offset < 0) { + return 1; + } + return _fseeki64 (z->parent->f, offset + z->offset, SEEK_SET); + + case SEEK_END: + if (offset > 0) + return 1; + if (offset < -z->size) { + _fseeki64 (z->parent->f, z->offset, SEEK_SET); + return 1; + } + return _fseeki64 (z->parent->f, offset + z->size + z->offset, SEEK_SET); + + case SEEK_CUR: + { + uae_s64 v = zfile_ftell (z->parent); + if (v + offset > z->size) { + _fseeki64 (z->parent->f, z->offset + z->size, SEEK_SET); + return 1; + } else if (v + offset < 0) { + _fseeki64 (z->parent->f, z->offset, SEEK_SET); + return 1; + } + return _fseeki64 (z->parent->f, v + offset + z->offset, SEEK_SET); + } + } + } else { + return _fseeki64 (z->f, offset, mode); + } } - } - return 1; + return 1; } size_t zfile_fread (void *b, size_t l1, size_t l2,struct zfile *z) { - if (z->zfileread) - return z->zfileread (b, l1, l2, z); - if (z->data) { - if (z->seek + l1 * l2 > z->size) { - if (l1) - l2 = (z->size - z->seek) / l1; - else - l2 = 0; - if (l2 < 0) - l2 = 0; - } - memcpy (b, z->data + z->offset + z->seek, l1 * l2); - z->seek += l1 * l2; - return l2; - } - if (z->parent && z->useparent) { - uae_s64 v; - uae_s64 size = z->size; - v = zfile_ftell (z); - if (v + l1 * l2 > size) { - if (l1) - l2 = (size - v) / l1; - else - l2 = 0; - if (l2 < 0) - l2 = 0; + if (z->zfileread) + return z->zfileread (b, l1, l2, z); + if (z->data) { + if (z->seek + l1 * l2 > z->size) { + if (l1) + l2 = (z->size - z->seek) / l1; + else + l2 = 0; + if (l2 < 0) + l2 = 0; + } + memcpy (b, z->data + z->offset + z->seek, l1 * l2); + z->seek += l1 * l2; + return l2; + } + if (z->parent && z->useparent) { + uae_s64 v; + uae_s64 size = z->size; + v = zfile_ftell (z); + if (v + l1 * l2 > size) { + if (l1) + l2 = (size - v) / l1; + else + l2 = 0; + if (l2 < 0) + l2 = 0; + } + z = z->parent; } - z = z->parent; - } - return fread (b, l1, l2, z->f); + return fread (b, l1, l2, z->f); } size_t zfile_fwrite (void *b, size_t l1, size_t l2, struct zfile *z) { - if (z->zfilewrite) - return z->zfilewrite (b, l1, l2, z); - if (z->parent && z->useparent) - return 0; - if (z->data) { - int off = z->seek + l1 * l2; - if (off > z->size) { - z->data = realloc (z->data, off); - z->size = off; + if (z->zfilewrite) + return z->zfilewrite (b, l1, l2, z); + if (z->parent && z->useparent) + return 0; + if (z->data) { + int off = z->seek + l1 * l2; + if (off > z->size) { + z->data = realloc (z->data, off); + z->size = off; + } + memcpy (z->data + z->seek, b, l1 * l2); + z->seek += l1 * l2; + return l2; } - memcpy (z->data + z->seek, b, l1 * l2); - z->seek += l1 * l2; - return l2; - } - return fwrite (b, l1, l2, z->f); + return fwrite (b, l1, l2, z->f); } size_t zfile_fputs (struct zfile *z, TCHAR *s) { - char *s2 = ua (s); - size_t t; - t = zfile_fwrite (s2, strlen (s2), 1, z); - xfree (s2); - return t; + char *s2 = ua (s); + size_t t; + t = zfile_fwrite (s2, strlen (s2), 1, z); + xfree (s2); + return t; } char *zfile_fgetsa (char *s, int size, struct zfile *z) { - if (z->data) { - char *os = s; - int i; - for (i = 0; i < size - 1; i++) { - if (z->seek == z->size) { - if (i == 0) - return NULL; - break; - } - *s = z->data[z->seek++]; - if (*s == '\n') { - s++; - break; - } - s++; + if (z->data) { + char *os = s; + int i; + for (i = 0; i < size - 1; i++) { + if (z->seek == z->size) { + if (i == 0) + return NULL; + break; + } + *s = z->data[z->seek++]; + if (*s == '\n') { + s++; + break; + } + s++; + } + *s = 0; + return os; + } else { + return fgets (s, size, z->f); } - *s = 0; - return os; - } else { - return fgets (s, size, z->f); - } } TCHAR *zfile_fgets (TCHAR *s, int size, struct zfile *z) { - if (z->data) { - char s2[MAX_DPATH]; - char *p = s2; - int i; - for (i = 0; i < size - 1; i++) { - if (z->seek == z->size) { - if (i == 0) - return NULL; - break; - } - *p = z->data[z->seek++]; - if (*p == '\n') { - p++; - break; - } - p++; - } - *p = 0; - if (size > strlen (s2) + 1) - size = strlen (s2) + 1; - au_copy (s, size, s2); - return s + size; - } else { - char s2[MAX_DPATH]; - char *s1; - s1 = fgets (s2, size, z->f); - if (!s1) - return NULL; - if (size > strlen (s2) + 1) - size = strlen (s2) + 1; - au_copy (s, size, s2); - return s + size; - } + if (z->data) { + char s2[MAX_DPATH]; + char *p = s2; + int i; + for (i = 0; i < size - 1; i++) { + if (z->seek == z->size) { + if (i == 0) + return NULL; + break; + } + *p = z->data[z->seek++]; + if (*p == '\n') { + p++; + break; + } + p++; + } + *p = 0; + if (size > strlen (s2) + 1) + size = strlen (s2) + 1; + au_copy (s, size, s2); + return s + size; + } else { + char s2[MAX_DPATH]; + char *s1; + s1 = fgets (s2, size, z->f); + if (!s1) + return NULL; + if (size > strlen (s2) + 1) + size = strlen (s2) + 1; + au_copy (s, size, s2); + return s + size; + } } int zfile_putc (int c, struct zfile *z) { - uae_u8 b = (uae_u8)c; - return zfile_fwrite (&b, 1, 1, z) ? 1 : -1; + uae_u8 b = (uae_u8)c; + return zfile_fwrite (&b, 1, 1, z) ? 1 : -1; } int zfile_getc (struct zfile *z) { - int out = -1; - if (z->data) { - if (z->seek < z->size) { - out = z->data[z->seek++]; + int out = -1; + if (z->data) { + if (z->seek < z->size) { + out = z->data[z->seek++]; + } + } else { + out = fgetc (z->f); } - } else { - out = fgetc (z->f); - } - return out; + return out; } int zfile_ferror (struct zfile *z) { - return 0; + return 0; } uae_u8 *zfile_getdata (struct zfile *z, uae_s64 offset, int len) { - uae_s64 pos; - uae_u8 *b; - if (len < 0) { - zfile_fseek (z, 0, SEEK_END); - len = zfile_ftell (z); - zfile_fseek (z, 0, SEEK_SET); - } - b = xmalloc (len); - if (z->data) { - memcpy (b, z->data + offset, len); - } else { - pos = zfile_ftell (z); - zfile_fseek (z, offset, SEEK_SET); - zfile_fread (b, len, 1, z); - zfile_fseek (z, pos, SEEK_SET); - } - return b; + uae_s64 pos; + uae_u8 *b; + if (len < 0) { + zfile_fseek (z, 0, SEEK_END); + len = zfile_ftell (z); + zfile_fseek (z, 0, SEEK_SET); + } + b = xmalloc (len); + if (z->data) { + memcpy (b, z->data + offset, len); + } else { + pos = zfile_ftell (z); + zfile_fseek (z, offset, SEEK_SET); + zfile_fread (b, len, 1, z); + zfile_fseek (z, pos, SEEK_SET); + } + return b; } int zfile_zuncompress (void *dst, int dstsize, struct zfile *src, int srcsize) { - z_stream zs; - int v; - uae_u8 inbuf[4096]; - int incnt; - - memset (&zs, 0, sizeof(zs)); - if (inflateInit_ (&zs, ZLIB_VERSION, sizeof(z_stream)) != Z_OK) + z_stream zs; + int v; + uae_u8 inbuf[4096]; + int incnt; + + memset (&zs, 0, sizeof(zs)); + if (inflateInit_ (&zs, ZLIB_VERSION, sizeof(z_stream)) != Z_OK) + return 0; + zs.next_out = (Bytef*)dst; + zs.avail_out = dstsize; + incnt = 0; + v = Z_OK; + while (v == Z_OK && zs.avail_out > 0) { + if (zs.avail_in == 0) { + int left = srcsize - incnt; + if (left == 0) + break; + if (left > sizeof (inbuf)) + left = sizeof (inbuf); + zs.next_in = inbuf; + zs.avail_in = zfile_fread (inbuf, 1, left, src); + incnt += left; + } + v = inflate (&zs, 0); + } + inflateEnd (&zs); return 0; - zs.next_out = (Bytef*)dst; - zs.avail_out = dstsize; - incnt = 0; - v = Z_OK; - while (v == Z_OK && zs.avail_out > 0) { - if (zs.avail_in == 0) { - int left = srcsize - incnt; - if (left == 0) - break; - if (left > sizeof (inbuf)) left = sizeof (inbuf); - zs.next_in = inbuf; - zs.avail_in = zfile_fread (inbuf, 1, left, src); - incnt += left; - } - v = inflate (&zs, 0); - } - inflateEnd (&zs); - return 0; } int zfile_zcompress (struct zfile *f, void *src, int size) { - int v; - z_stream zs; - uae_u8 outbuf[4096]; + int v; + z_stream zs; + uae_u8 outbuf[4096]; - memset (&zs, 0, sizeof (zs)); - if (deflateInit_ (&zs, Z_DEFAULT_COMPRESSION, ZLIB_VERSION, sizeof (z_stream)) != Z_OK) - return 0; - zs.next_in = (Bytef*)src; - zs.avail_in = size; - v = Z_OK; - while (v == Z_OK) { - zs.next_out = outbuf; - zs.avail_out = sizeof (outbuf); - v = deflate (&zs, Z_NO_FLUSH | Z_FINISH); - if (sizeof (outbuf) - zs.avail_out > 0) - zfile_fwrite (outbuf, 1, sizeof (outbuf) - zs.avail_out, f); - } - deflateEnd (&zs); - return zs.total_out; + memset (&zs, 0, sizeof (zs)); + if (deflateInit_ (&zs, Z_DEFAULT_COMPRESSION, ZLIB_VERSION, sizeof (z_stream)) != Z_OK) + return 0; + zs.next_in = (Bytef*)src; + zs.avail_in = size; + v = Z_OK; + while (v == Z_OK) { + zs.next_out = outbuf; + zs.avail_out = sizeof (outbuf); + v = deflate (&zs, Z_NO_FLUSH | Z_FINISH); + if (sizeof (outbuf) - zs.avail_out > 0) + zfile_fwrite (outbuf, 1, sizeof (outbuf) - zs.avail_out, f); + } + deflateEnd (&zs); + return zs.total_out; } TCHAR *zfile_getname (struct zfile *f) { - return f ? f->name : NULL; + return f ? f->name : NULL; } TCHAR *zfile_getfilename (struct zfile *f) { - int i; - if (f->name == NULL) - return NULL; - for (i = _tcslen (f->name) - 1; i >= 0; i--) { - if (f->name[i] == '\\' || f->name[i] == '/' || f->name[i] == ':') { - i++; - return &f->name[i]; + int i; + if (f->name == NULL) + return NULL; + for (i = _tcslen (f->name) - 1; i >= 0; i--) { + if (f->name[i] == '\\' || f->name[i] == '/' || f->name[i] == ':') { + i++; + return &f->name[i]; + } } - } - return f->name; + return f->name; } uae_u32 zfile_crc32 (struct zfile *f) { - uae_u8 *p; - int pos, size; - uae_u32 crc; - - if (!f) - return 0; - if (f->data) - return get_crc32 (f->data, f->size); - pos = zfile_ftell (f); - zfile_fseek (f, 0, SEEK_END); - size = zfile_ftell (f); - p = xmalloc (size); - if (!p) - return 0; - memset (p, 0, size); - zfile_fseek (f, 0, SEEK_SET); - zfile_fread (p, 1, size, f); - zfile_fseek (f, pos, SEEK_SET); - crc = get_crc32 (p, size); - xfree (p); - return crc; + uae_u8 *p; + int pos, size; + uae_u32 crc; + + if (!f) + return 0; + if (f->data) + return get_crc32 (f->data, f->size); + pos = zfile_ftell (f); + zfile_fseek (f, 0, SEEK_END); + size = zfile_ftell (f); + p = xmalloc (size); + if (!p) + return 0; + memset (p, 0, size); + zfile_fseek (f, 0, SEEK_SET); + zfile_fread (p, 1, size, f); + zfile_fseek (f, pos, SEEK_SET); + crc = get_crc32 (p, size); + xfree (p); + return crc; } static struct zvolume *zvolume_list; static void recurparent (TCHAR *newpath, struct znode *zn, int recurse) { - TCHAR tmp[2] = { FSDB_DIR_SEPARATOR, 0 }; - if (zn->parent && (&zn->volume->root != zn->parent || zn->volume->parentz == NULL)) { - if (&zn->volume->root == zn->parent && zn->volume->parentz == NULL && !_tcscmp (zn->name, zn->parent->name)) - goto end; - recurparent (newpath, zn->parent, recurse); - } else { - struct zvolume *zv = zn->volume; - if (zv->parentz && recurse) - recurparent (newpath, zv->parentz, recurse); - } + TCHAR tmp[2] = { FSDB_DIR_SEPARATOR, 0 }; + if (zn->parent && (&zn->volume->root != zn->parent || zn->volume->parentz == NULL)) { + if (&zn->volume->root == zn->parent && zn->volume->parentz == NULL && !_tcscmp (zn->name, zn->parent->name)) + goto end; + recurparent (newpath, zn->parent, recurse); + } else { + struct zvolume *zv = zn->volume; + if (zv->parentz && recurse) + recurparent (newpath, zv->parentz, recurse); + } end: - if (newpath[0]) - _tcscat (newpath, tmp); - _tcscat (newpath, zn->name); + if (newpath[0]) + _tcscat (newpath, tmp); + _tcscat (newpath, zn->name); } static struct znode *znode_alloc (struct znode *parent, const TCHAR *name) { - TCHAR fullpath[MAX_DPATH]; - TCHAR tmpname[MAX_DPATH]; - struct znode *zn = xcalloc (sizeof (struct znode), 1); - struct znode *zn2; - TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; - - _tcscpy (tmpname, name); - zn2 = parent->child; - while (zn2) { - if (!_tcscmp (zn2->name, tmpname)) { - TCHAR *ext = _tcsrchr (tmpname, '.'); - if (ext && ext > tmpname + 2 && ext[-2] == '.') { - ext[-1]++; - } else if (ext) { - memmove (ext + 2, ext, (_tcslen (ext) + 1) * sizeof (TCHAR)); - ext[0] = '.'; - ext[1] = '1'; - } else { - int len = _tcslen (tmpname); - tmpname[len] = '.'; - tmpname[len + 1] = '1'; - tmpname[len + 2] = 0; - } - zn2 = parent->child; - continue; - } - zn2 = zn2->sibling; - } - - fullpath[0] = 0; - recurparent (fullpath, parent, FALSE); - _tcscat (fullpath, sep); - _tcscat (fullpath, tmpname); + TCHAR fullpath[MAX_DPATH]; + TCHAR tmpname[MAX_DPATH]; + struct znode *zn = xcalloc (sizeof (struct znode), 1); + struct znode *zn2; + TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; + + _tcscpy (tmpname, name); + zn2 = parent->child; + while (zn2) { + if (!_tcscmp (zn2->name, tmpname)) { + TCHAR *ext = _tcsrchr (tmpname, '.'); + if (ext && ext > tmpname + 2 && ext[-2] == '.') { + ext[-1]++; + } else if (ext) { + memmove (ext + 2, ext, (_tcslen (ext) + 1) * sizeof (TCHAR)); + ext[0] = '.'; + ext[1] = '1'; + } else { + int len = _tcslen (tmpname); + tmpname[len] = '.'; + tmpname[len + 1] = '1'; + tmpname[len + 2] = 0; + } + zn2 = parent->child; + continue; + } + zn2 = zn2->sibling; + } + + fullpath[0] = 0; + recurparent (fullpath, parent, FALSE); + _tcscat (fullpath, sep); + _tcscat (fullpath, tmpname); #ifdef ZFILE_DEBUG - write_log (L"znode_alloc vol='%s' parent='%s' name='%s'\n", parent->volume->root.name, parent->name, name); + write_log (L"znode_alloc vol='%s' parent='%s' name='%s'\n", parent->volume->root.name, parent->name, name); #endif - zn->fullname = my_strdup (fullpath); - zn->name = my_strdup (tmpname); - zn->volume = parent->volume; - zn->volume->last->next = zn; - zn->prev = zn->volume->last; - zn->volume->last = zn; - return zn; + zn->fullname = my_strdup (fullpath); + zn->name = my_strdup (tmpname); + zn->volume = parent->volume; + zn->volume->last->next = zn; + zn->prev = zn->volume->last; + zn->volume->last = zn; + return zn; } static struct znode *znode_alloc_child (struct znode *parent, const TCHAR *name) { - struct znode *zn = znode_alloc (parent, name); + struct znode *zn = znode_alloc (parent, name); - if (!parent->child) { - parent->child = zn; - } else { - struct znode *pn = parent->child; - while (pn->sibling) - pn = pn->sibling; - pn->sibling = zn; - } - zn->parent = parent; - return zn; + if (!parent->child) { + parent->child = zn; + } else { + struct znode *pn = parent->child; + while (pn->sibling) + pn = pn->sibling; + pn->sibling = zn; + } + zn->parent = parent; + return zn; } static struct znode *znode_alloc_sibling (struct znode *sibling, const TCHAR *name) { - struct znode *zn = znode_alloc (sibling->parent, name); + struct znode *zn = znode_alloc (sibling->parent, name); - if (!sibling->sibling) { - sibling->sibling = zn; - } else { - struct znode *pn = sibling->sibling; - while (pn->sibling) - pn = pn->sibling; - pn->sibling = zn; - } - zn->parent = sibling->parent; - return zn; + if (!sibling->sibling) { + sibling->sibling = zn; + } else { + struct znode *pn = sibling->sibling; + while (pn->sibling) + pn = pn->sibling; + pn->sibling = zn; + } + zn->parent = sibling->parent; + return zn; } static void zvolume_addtolist (struct zvolume *zv) { - if (!zv) - return; - if (!zvolume_list) { - zvolume_list = zv; - } else { - struct zvolume *v = zvolume_list; - while (v->next) - v = v->next; - v->next = zv; - } + if (!zv) + return; + if (!zvolume_list) { + zvolume_list = zv; + } else { + struct zvolume *v = zvolume_list; + while (v->next) + v = v->next; + v->next = zv; + } } static struct zvolume *zvolume_alloc_2 (const TCHAR *name, struct zfile *z, unsigned int id, void *handle, const TCHAR *volname) { - struct zvolume *zv = xcalloc (sizeof (struct zvolume), 1); - struct znode *root; - uae_s64 pos; - int i; - - root = &zv->root; - zv->last = root; - zv->archive = z; - zv->handle = handle; - zv->id = id; - zv->blocks = 4; - if (z) - zv->zfdmask = z->zfdmask; - root->volume = zv; - root->type = ZNODE_DIR; - i = 0; - if (name[0] != '/' && name[0] != '\\') { - if (_tcschr (name, ':') == 0) { - for (i = _tcslen (name) - 1; i > 0; i--) { - if (name[i] == FSDB_DIR_SEPARATOR) { - i++; - break; - } - } - } - } - root->name = my_strdup (name + i); - root->fullname = my_strdup (name); + struct zvolume *zv = xcalloc (sizeof (struct zvolume), 1); + struct znode *root; + uae_s64 pos; + int i; + + root = &zv->root; + zv->last = root; + zv->archive = z; + zv->handle = handle; + zv->id = id; + zv->blocks = 4; + if (z) + zv->zfdmask = z->zfdmask; + root->volume = zv; + root->type = ZNODE_DIR; + i = 0; + if (name[0] != '/' && name[0] != '\\') { + if (_tcschr (name, ':') == 0) { + for (i = _tcslen (name) - 1; i > 0; i--) { + if (name[i] == FSDB_DIR_SEPARATOR) { + i++; + break; + } + } + } + } + root->name = my_strdup (name + i); + root->fullname = my_strdup (name); #ifdef ZFILE_DEBUG - write_log (L"created zvolume: '%s' (%s)\n", root->name, root->fullname); + write_log (L"created zvolume: '%s' (%s)\n", root->name, root->fullname); #endif - if (volname) - zv->volumename = my_strdup (volname); - if (z) { - pos = zfile_ftell (z); - zfile_fseek (z, 0, SEEK_END); - zv->archivesize = zfile_ftell (z); - zfile_fseek (z, pos, SEEK_SET); - } - return zv; + if (volname) + zv->volumename = my_strdup (volname); + if (z) { + pos = zfile_ftell (z); + zfile_fseek (z, 0, SEEK_END); + zv->archivesize = zfile_ftell (z); + zfile_fseek (z, pos, SEEK_SET); + } + return zv; } struct zvolume *zvolume_alloc (struct zfile *z, unsigned int id, void *handle, const TCHAR *volumename) { - return zvolume_alloc_2 (zfile_getname (z), z, id, handle, volumename); + return zvolume_alloc_2 (zfile_getname (z), z, id, handle, volumename); } struct zvolume *zvolume_alloc_nofile (const TCHAR *name, unsigned int id, void *handle, const TCHAR *volumename) { - return zvolume_alloc_2 (name, NULL, id, handle, volumename); + return zvolume_alloc_2 (name, NULL, id, handle, volumename); } struct zvolume *zvolume_alloc_empty (struct zvolume *prev, const TCHAR *name) { - struct zvolume *zv = zvolume_alloc_2(name, 0, 0, 0, NULL); - if (!zv) - return NULL; - if (prev) - zv->zfdmask = prev->zfdmask; - return zv; + struct zvolume *zv = zvolume_alloc_2(name, 0, 0, 0, NULL); + if (!zv) + return NULL; + if (prev) + zv->zfdmask = prev->zfdmask; + return zv; } static struct zvolume *get_zvolume (const TCHAR *path) { - struct zvolume *zv = zvolume_list; - while (zv) { - TCHAR *s = zfile_getname (zv->archive); - if (!s) - s = zv->root.name; - if (_tcslen (path) >= _tcslen (s) && !memcmp (path, s, _tcslen (s) * sizeof (TCHAR))) - return zv; - zv = zv->next; - } - return NULL; + struct zvolume *zv = zvolume_list; + while (zv) { + TCHAR *s = zfile_getname (zv->archive); + if (!s) + s = zv->root.name; + if (_tcslen (path) >= _tcslen (s) && !memcmp (path, s, _tcslen (s) * sizeof (TCHAR))) + return zv; + zv = zv->next; + } + return NULL; } static struct zvolume *zfile_fopen_archive_ext (struct znode *parent, struct zfile *zf) { - struct zvolume *zv = NULL; - TCHAR *name = zfile_getname (zf); - TCHAR *ext; - uae_u8 header[7]; + struct zvolume *zv = NULL; + TCHAR *name = zfile_getname (zf); + TCHAR *ext; + uae_u8 header[7]; - if (!name) - return NULL; + if (!name) + return NULL; - memset (header, 0, sizeof (header)); - zfile_fseek (zf, 0, SEEK_SET); - zfile_fread (header, sizeof (header), 1, zf); - zfile_fseek (zf, 0, SEEK_SET); - - ext = _tcsrchr (name, '.'); - if (ext != NULL) { - ext++; - if (strcasecmp (ext, L"lha") == 0 || strcasecmp (ext, L"lzh") == 0) - zv = archive_directory_lha (zf); - if (strcasecmp (ext, L"zip") == 0) - zv = archive_directory_zip (zf); - if (strcasecmp (ext, L"7z") == 0) - zv = archive_directory_7z (zf); - if (strcasecmp (ext, L"lzx") == 0) - zv = archive_directory_lzx (zf); - if (strcasecmp (ext, L"rar") == 0) - zv = archive_directory_rar (zf); - if (strcasecmp (ext, L"adf") == 0 && !memcmp (header, "DOS", 3)) - zv = archive_directory_adf (parent, zf); - if (strcasecmp (ext, L"hdf") == 0) { - if (!memcmp (header, "RDSK", 4)) - zv = archive_directory_rdb (zf); - else - zv = archive_directory_adf (parent, zf); + memset (header, 0, sizeof (header)); + zfile_fseek (zf, 0, SEEK_SET); + zfile_fread (header, sizeof (header), 1, zf); + zfile_fseek (zf, 0, SEEK_SET); + + ext = _tcsrchr (name, '.'); + if (ext != NULL) { + ext++; + if (strcasecmp (ext, L"lha") == 0 || strcasecmp (ext, L"lzh") == 0) + zv = archive_directory_lha (zf); + if (strcasecmp (ext, L"zip") == 0) + zv = archive_directory_zip (zf); + if (strcasecmp (ext, L"7z") == 0) + zv = archive_directory_7z (zf); + if (strcasecmp (ext, L"lzx") == 0) + zv = archive_directory_lzx (zf); + if (strcasecmp (ext, L"rar") == 0) + zv = archive_directory_rar (zf); + if (strcasecmp (ext, L"adf") == 0 && !memcmp (header, "DOS", 3)) + zv = archive_directory_adf (parent, zf); + if (strcasecmp (ext, L"hdf") == 0) { + if (!memcmp (header, "RDSK", 4)) + zv = archive_directory_rdb (zf); + else + zv = archive_directory_adf (parent, zf); + } } - } - return zv; + return zv; } static struct zvolume *zfile_fopen_archive_data (struct znode *parent, struct zfile *zf) { - struct zvolume *zv = NULL; - uae_u8 header[32]; - - memset (header, 0, sizeof (header)); - zfile_fread (header, sizeof (header), 1, zf); - zfile_fseek (zf, 0, SEEK_SET); - if (header[0] == 'P' && header[1] == 'K') - zv = archive_directory_zip (zf); - if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') - zv = archive_directory_rar (zf); - if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') - zv = archive_directory_lzx (zf); - if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') - zv = archive_directory_lha (zf); - if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) - zv = archive_directory_adf (parent, zf); - if (header[0] == 'R' && header[1] == 'D' && header[2] == 'S' && header[3] == 'K') - zv = archive_directory_rdb (zf); - if (isfat (header)) - zv = archive_directory_fat (zf); - return zv; + struct zvolume *zv = NULL; + uae_u8 header[32]; + + memset (header, 0, sizeof (header)); + zfile_fread (header, sizeof (header), 1, zf); + zfile_fseek (zf, 0, SEEK_SET); + if (header[0] == 'P' && header[1] == 'K') + zv = archive_directory_zip (zf); + if (header[0] == 'R' && header[1] == 'a' && header[2] == 'r' && header[3] == '!') + zv = archive_directory_rar (zf); + if (header[0] == 'L' && header[1] == 'Z' && header[2] == 'X') + zv = archive_directory_lzx (zf); + if (header[2] == '-' && header[3] == 'l' && header[4] == 'h' && header[6] == '-') + zv = archive_directory_lha (zf); + if (header[0] == 'D' && header[1] == 'O' && header[2] == 'S' && (header[3] >= 0 && header[3] <= 7)) + zv = archive_directory_adf (parent, zf); + if (header[0] == 'R' && header[1] == 'D' && header[2] == 'S' && header[3] == 'K') + zv = archive_directory_rdb (zf); + if (isfat (header)) + zv = archive_directory_fat (zf); + return zv; } static struct znode *get_znode (struct zvolume *zv, const TCHAR *ppath, int); static void zfile_fopen_archive_recurse2 (struct zvolume *zv, struct znode *zn) { - struct zvolume *zvnew; - struct znode *zndir; - TCHAR tmp[MAX_DPATH]; - - _stprintf (tmp, L"%s.DIR", zn->fullname + _tcslen (zv->root.name) + 1); - zndir = get_znode (zv, tmp, TRUE); - if (!zndir) { - struct zarchive_info zai = { 0 }; - zvnew = zvolume_alloc_empty (zv, tmp); - zvnew->parentz = zn; - zai.name = tmp; - zai.t = zn->mtime; - zai.comment = zv->volumename; - if (zn->flags < 0) - zai.flags = zn->flags; - zndir = zvolume_adddir_abs (zv, &zai); - zndir->type = ZNODE_VDIR; - zndir->vfile = zn; - zndir->vchild = zvnew; - zvnew->parent = zv; - zndir->offset = zn->offset; - zndir->offset2 = zn->offset2; - } + struct zvolume *zvnew; + struct znode *zndir; + TCHAR tmp[MAX_DPATH]; + + _stprintf (tmp, L"%s.DIR", zn->fullname + _tcslen (zv->root.name) + 1); + zndir = get_znode (zv, tmp, TRUE); + if (!zndir) { + struct zarchive_info zai = { 0 }; + zvnew = zvolume_alloc_empty (zv, tmp); + zvnew->parentz = zn; + zai.name = tmp; + zai.t = zn->mtime; + zai.comment = zv->volumename; + if (zn->flags < 0) + zai.flags = zn->flags; + zndir = zvolume_adddir_abs (zv, &zai); + zndir->type = ZNODE_VDIR; + zndir->vfile = zn; + zndir->vchild = zvnew; + zvnew->parent = zv; + zndir->offset = zn->offset; + zndir->offset2 = zn->offset2; + } } static int zfile_fopen_archive_recurse (struct zvolume *zv) { - struct znode *zn; - int i, added; - - added = 0; - zn = zv->root.child; - while (zn) { - struct zfile *z; - TCHAR *ext = _tcsrchr (zn->name, '.'); - if (ext && !zn->vchild && zn->type == ZNODE_FILE) { - for (i = 0; plugins_7z[i]; i++) { - if (!strcasecmp (ext + 1, plugins_7z[i])) { - zfile_fopen_archive_recurse2 (zv, zn); + struct znode *zn; + int i, added; + + added = 0; + zn = zv->root.child; + while (zn) { + struct zfile *z; + TCHAR *ext = _tcsrchr (zn->name, '.'); + if (ext && !zn->vchild && zn->type == ZNODE_FILE) { + for (i = 0; plugins_7z[i]; i++) { + if (!strcasecmp (ext + 1, plugins_7z[i])) { + zfile_fopen_archive_recurse2 (zv, zn); + } + } } - } + z = archive_getzfile (zn, zv->method); + if (z && iszip (z)) + zfile_fopen_archive_recurse2 (zv, zn); + zn = zn->next; } - z = archive_getzfile (zn, zv->method); - if (z && iszip (z)) - zfile_fopen_archive_recurse2 (zv, zn); - zn = zn->next; - } - return 0; + return 0; } static struct zvolume *prepare_recursive_volume (struct zvolume *zv, const TCHAR *path) { - struct zfile *zf = NULL; - struct zvolume *zvnew = NULL; + struct zfile *zf = NULL; + struct zvolume *zvnew = NULL; #ifdef ZFILE_DEBUG - write_log (L"unpacking '%s'\n", path); + write_log (L"unpacking '%s'\n", path); #endif - zf = zfile_open_archive (path, 0); - if (!zf) - goto end; - zvnew = zfile_fopen_archive_ext (zv->parentz, zf); - if (!zvnew) { - struct zfile *zf2 = zuncompress (&zv->root, zf, 0, ZFD_ALL, NULL); - if (zf2) { - zf = zf2; - zvnew = archive_directory_plain (zf); - } - } - if (!zvnew) - goto end; - zvnew->parent = zv->parent; - zfile_fopen_archive_recurse (zvnew); - zfile_fclose_archive (zv); - return zvnew; + zf = zfile_open_archive (path, 0); + if (!zf) + goto end; + zvnew = zfile_fopen_archive_ext (zv->parentz, zf); + if (!zvnew) { + struct zfile *zf2 = zuncompress (&zv->root, zf, 0, ZFD_ALL, NULL); + if (zf2) { + zf = zf2; + zvnew = archive_directory_plain (zf); + } + } + if (!zvnew) + goto end; + zvnew->parent = zv->parent; + zfile_fopen_archive_recurse (zvnew); + zfile_fclose_archive (zv); + return zvnew; end: - write_log (L"unpack '%s' failed\n", path); - zfile_fclose_archive (zvnew); - zfile_fclose (zf); - return NULL; + write_log (L"unpack '%s' failed\n", path); + zfile_fclose_archive (zvnew); + zfile_fclose (zf); + return NULL; } static struct znode *get_znode (struct zvolume *zv, const TCHAR *ppath, int recurse) { - struct znode *zn; - TCHAR path[MAX_DPATH], zpath[MAX_DPATH]; + struct znode *zn; + TCHAR path[MAX_DPATH], zpath[MAX_DPATH]; - if (!zv) - return NULL; - _tcscpy (path, ppath); - zn = &zv->root; - while (zn) { - zpath[0] = 0; - recurparent (zpath, zn, recurse); - if (zn->type == ZNODE_FILE) { - if (!_tcsicmp (zpath, path)) - return zn; - } else { - int len = _tcslen (zpath); - if (_tcslen (path) >= len && (path[len] == 0 || path[len] == FSDB_DIR_SEPARATOR) && !_tcsnicmp (zpath, path, len)) { - if (path[len] == 0) - return zn; - if (zn->vchild) { - /* jump to separate tree, recursive archives */ - struct zvolume *zvdeep = zn->vchild; - if (zvdeep->archive == NULL) { - TCHAR newpath[MAX_DPATH]; - newpath[0] = 0; - recurparent (newpath, zn, recurse); + if (!zv) + return NULL; + _tcscpy (path, ppath); + zn = &zv->root; + while (zn) { + zpath[0] = 0; + recurparent (zpath, zn, recurse); + if (zn->type == ZNODE_FILE) { + if (!_tcsicmp (zpath, path)) + return zn; + } else { + int len = _tcslen (zpath); + if (_tcslen (path) >= len && (path[len] == 0 || path[len] == FSDB_DIR_SEPARATOR) && !_tcsnicmp (zpath, path, len)) { + if (path[len] == 0) + return zn; + if (zn->vchild) { + /* jump to separate tree, recursive archives */ + struct zvolume *zvdeep = zn->vchild; + if (zvdeep->archive == NULL) { + TCHAR newpath[MAX_DPATH]; + newpath[0] = 0; + recurparent (newpath, zn, recurse); #ifdef ZFILE_DEBUG - write_log (L"'%s'\n", newpath); + write_log (L"'%s'\n", newpath); #endif - zvdeep = prepare_recursive_volume (zvdeep, newpath); - if (!zvdeep) { - write_log (L"failed to unpack '%s'\n", newpath); - return NULL; + zvdeep = prepare_recursive_volume (zvdeep, newpath); + if (!zvdeep) { + write_log (L"failed to unpack '%s'\n", newpath); + return NULL; + } + /* replace dummy empty volume with real volume */ + zn->vchild = zvdeep; + zvdeep->parentz = zn; + } + zn = zvdeep->root.child; + } else { + zn = zn->child; + } + continue; } - /* replace dummy empty volume with real volume */ - zn->vchild = zvdeep; - zvdeep->parentz = zn; - } - zn = zvdeep->root.child; - } else { - zn = zn->child; } - continue; - } + zn = zn->sibling; } - zn = zn->sibling; - } - return NULL; + return NULL; } static void addvolumesize (struct zvolume *zv, uae_s64 size) { - unsigned int blocks = (size + 511) / 512; + unsigned int blocks = (size + 511) / 512; - if (blocks == 0) - blocks++; - while (zv) { - zv->blocks += blocks; - zv->size += size; - zv = zv->parent; - } + if (blocks == 0) + blocks++; + while (zv) { + zv->blocks += blocks; + zv->size += size; + zv = zv->parent; + } } struct znode *znode_adddir (struct znode *parent, const TCHAR *name, struct zarchive_info *zai) { - struct znode *zn; - TCHAR path[MAX_DPATH]; - TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; + struct znode *zn; + TCHAR path[MAX_DPATH]; + TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; - path[0] = 0; - recurparent (path, parent, FALSE); - _tcscat (path, sep); - _tcscat (path, name); - zn = get_znode (parent->volume, path, FALSE); - if (zn) + path[0] = 0; + recurparent (path, parent, FALSE); + _tcscat (path, sep); + _tcscat (path, name); + zn = get_znode (parent->volume, path, FALSE); + if (zn) + return zn; + zn = znode_alloc_child (parent, name); + zn->mtime = zai->t; + zn->type = ZNODE_DIR; + if (zai->comment) + zn->comment = my_strdup (zai->comment); + if (zai->flags < 0) + zn->flags = zai->flags; + addvolumesize (parent->volume, 0); return zn; - zn = znode_alloc_child (parent, name); - zn->mtime = zai->t; - zn->type = ZNODE_DIR; - if (zai->comment) - zn->comment = my_strdup (zai->comment); - if (zai->flags < 0) - zn->flags = zai->flags; - addvolumesize (parent->volume, 0); - return zn; } struct znode *zvolume_adddir_abs (struct zvolume *zv, struct zarchive_info *zai) { - struct znode *zn2; - TCHAR *path = my_strdup (zai->name); - TCHAR *p, *p2; - int i; - - if (_tcslen (path) > 0) { - /* remove possible trailing / or \ */ - TCHAR last; - last = path[_tcslen (path) - 1]; - if (last == '/' || last == '\\') - path[_tcslen (path) - 1] = 0; - } - zn2 = &zv->root; - p = p2 = path; - for (i = 0; path[i]; i++) { - if (path[i] == '/' || path[i] == '\\') { - path[i] = 0; - zn2 = znode_adddir (zn2, p, zai); - path[i] = FSDB_DIR_SEPARATOR; - p = p2 = &path[i + 1]; - } - } - return znode_adddir (zn2, p, zai); + struct znode *zn2; + TCHAR *path = my_strdup (zai->name); + TCHAR *p, *p2; + int i; + + if (_tcslen (path) > 0) { + /* remove possible trailing / or \ */ + TCHAR last; + last = path[_tcslen (path) - 1]; + if (last == '/' || last == '\\') + path[_tcslen (path) - 1] = 0; + } + zn2 = &zv->root; + p = p2 = path; + for (i = 0; path[i]; i++) { + if (path[i] == '/' || path[i] == '\\') { + path[i] = 0; + zn2 = znode_adddir (zn2, p, zai); + path[i] = FSDB_DIR_SEPARATOR; + p = p2 = &path[i + 1]; + } + } + return znode_adddir (zn2, p, zai); } struct znode *zvolume_addfile_abs (struct zvolume *zv, struct zarchive_info *zai) { - struct znode *zn, *zn2; - int i; - TCHAR *path = my_strdup (zai->name); - TCHAR *p, *p2; - - zn2 = &zv->root; - p = p2 = path; - for (i = 0; path[i]; i++) { - if (path[i] == '/' || path[i] == '\\') { - path[i] = 0; - zn2 = znode_adddir (zn2, p, zai); - path[i] = FSDB_DIR_SEPARATOR; - p = p2 = &path[i + 1]; - } - } - if (p2) { - zn = znode_alloc_child (zn2, p2); - zn->size = zai->size; - zn->type = ZNODE_FILE; - zn->mtime = zai->t; - if (zai->comment) - zn->comment = my_strdup (zai->comment); - zn->flags = zai->flags; - addvolumesize (zn->volume, zai->size); - } - xfree (path); - return zn; + struct znode *zn, *zn2; + int i; + TCHAR *path = my_strdup (zai->name); + TCHAR *p, *p2; + + zn2 = &zv->root; + p = p2 = path; + for (i = 0; path[i]; i++) { + if (path[i] == '/' || path[i] == '\\') { + path[i] = 0; + zn2 = znode_adddir (zn2, p, zai); + path[i] = FSDB_DIR_SEPARATOR; + p = p2 = &path[i + 1]; + } + } + if (p2) { + zn = znode_alloc_child (zn2, p2); + zn->size = zai->size; + zn->type = ZNODE_FILE; + zn->mtime = zai->t; + if (zai->comment) + zn->comment = my_strdup (zai->comment); + zn->flags = zai->flags; + addvolumesize (zn->volume, zai->size); + } + xfree (path); + return zn; } struct zvolume *zfile_fopen_directory (const TCHAR *dirname) { - struct zvolume *zv = NULL; - void *dir; - TCHAR fname[MAX_DPATH]; + struct zvolume *zv = NULL; + void *dir; + TCHAR fname[MAX_DPATH]; - dir = my_opendir (dirname); - if (!dir) - return NULL; - zv = zvolume_alloc_nofile (dirname, ArchiveFormatDIR, NULL, NULL); - while (my_readdir (dir, fname)) { - TCHAR fullname[MAX_DPATH]; - struct _stat64 statbuf; - struct zarchive_info zai = { 0 }; - if (!_tcscmp (fname, L".") || !_tcscmp (fname, L"..")) - continue; - _tcscpy (fullname, dirname); - _tcscat (fullname, L"\\"); - _tcscat (fullname, fname); - if (stat (fullname, &statbuf) == -1) - continue; - zai.name = fname; - zai.size = statbuf.st_size; - zai.t = statbuf.st_mtime; - if (statbuf.st_mode & FILEFLAG_DIR) { - zvolume_adddir_abs (zv, &zai); - } else { - struct znode *zn; - zn = zvolume_addfile_abs (zv, &zai); - //zfile_fopen_archive_recurse2 (zv, zn); + dir = my_opendir (dirname); + if (!dir) + return NULL; + zv = zvolume_alloc_nofile (dirname, ArchiveFormatDIR, NULL, NULL); + while (my_readdir (dir, fname)) { + TCHAR fullname[MAX_DPATH]; + struct _stat64 statbuf; + struct zarchive_info zai = { 0 }; + if (!_tcscmp (fname, L".") || !_tcscmp (fname, L"..")) + continue; + _tcscpy (fullname, dirname); + _tcscat (fullname, L"\\"); + _tcscat (fullname, fname); + if (stat (fullname, &statbuf) == -1) + continue; + zai.name = fname; + zai.size = statbuf.st_size; + zai.t = statbuf.st_mtime; + if (statbuf.st_mode & FILEFLAG_DIR) { + zvolume_adddir_abs (zv, &zai); + } else { + struct znode *zn; + zn = zvolume_addfile_abs (zv, &zai); + //zfile_fopen_archive_recurse2 (zv, zn); + } } - } - my_closedir (dir); -// zfile_fopen_archive_recurse (zv); - if (zv) - zvolume_addtolist (zv); - return zv; + my_closedir (dir); + // zfile_fopen_archive_recurse (zv); + if (zv) + zvolume_addtolist (zv); + return zv; } struct zvolume *zfile_fopen_archive (const TCHAR *filename) { - struct zvolume *zv = NULL; - struct zfile *zf = zfile_fopen_nozip (filename, L"rb"); + struct zvolume *zv = NULL; + struct zfile *zf = zfile_fopen_nozip (filename, L"rb"); - if (!zf) - return NULL; - zf->zfdmask = ZFD_ALL; - zv = zfile_fopen_archive_ext (NULL, zf); - if (!zv) - zv = zfile_fopen_archive_data (NULL, zf); + if (!zf) + return NULL; + zf->zfdmask = ZFD_ALL; + zv = zfile_fopen_archive_ext (NULL, zf); + if (!zv) + zv = zfile_fopen_archive_data (NULL, zf); #if 0 - if (!zv) { - struct zfile *zf2 = zuncompress (zf, 0, 0); - if (zf2 != zf) { - zf = zf2; - zv = zfile_fopen_archive_ext (zf); - if (!zv) - zv = zfile_fopen_archive_data (zf); - } - } + if (!zv) { + struct zfile *zf2 = zuncompress (zf, 0, 0); + if (zf2 != zf) { + zf = zf2; + zv = zfile_fopen_archive_ext (zf); + if (!zv) + zv = zfile_fopen_archive_data (zf); + } + } #endif - /* pointless but who cares? */ - if (!zv) - zv = archive_directory_plain (zf); + /* pointless but who cares? */ + if (!zv) + zv = archive_directory_plain (zf); #if RECURSIVE_ARCHIVES - if (zv) - zfile_fopen_archive_recurse (zv); + if (zv) + zfile_fopen_archive_recurse (zv); #endif - if (zv) - zvolume_addtolist (zv); - else - zfile_fclose (zf); + if (zv) + zvolume_addtolist (zv); + else + zfile_fclose (zf); - return zv; + return zv; } struct zvolume *zfile_fopen_archive_root (const TCHAR *filename) { - TCHAR path[MAX_DPATH], *p1, *p2, *lastp; - struct zvolume *zv = NULL; - //int last = 0; - int num, i; - - if (my_existsdir (filename)) - return zfile_fopen_directory (filename); - - num = 1; - lastp = NULL; - for (;;) { - _tcscpy (path, filename); - p1 = p2 = path; - for (i = 0; i < num; i++) { - while (*p1 != FSDB_DIR_SEPARATOR && *p1 != 0) - p1++; - if (*p1 == 0 && p1 == lastp) - return NULL; - if (i + 1 < num) - p1++; + TCHAR path[MAX_DPATH], *p1, *p2, *lastp; + struct zvolume *zv = NULL; + //int last = 0; + int num, i; + + if (my_existsdir (filename)) + return zfile_fopen_directory (filename); + + num = 1; + lastp = NULL; + for (;;) { + _tcscpy (path, filename); + p1 = p2 = path; + for (i = 0; i < num; i++) { + while (*p1 != FSDB_DIR_SEPARATOR && *p1 != 0) + p1++; + if (*p1 == 0 && p1 == lastp) + return NULL; + if (i + 1 < num) + p1++; + } + *p1 = 0; + lastp = p1; + if (my_existsfile (p2)) + return zfile_fopen_archive (p2); + num++; } - *p1 = 0; - lastp = p1; - if (my_existsfile (p2)) - return zfile_fopen_archive (p2); - num++; - } #if 0 - while (!last) { - while (*p1 != FSDB_DIR_SEPARATOR && *p1 != 0) - p1++; - if (*p1 == 0) - last = 1; - *p1 = 0; - if (!zv) { - zv = zfile_fopen_archive (p2); - if (!zv) - return NULL; - } else { - struct znode *zn = get_znode (zv, p2); - if (!zn) - return NULL; + while (!last) { + while (*p1 != FSDB_DIR_SEPARATOR && *p1 != 0) + p1++; + if (*p1 == 0) + last = 1; + *p1 = 0; + if (!zv) { + zv = zfile_fopen_archive (p2); + if (!zv) + return NULL; + } else { + struct znode *zn = get_znode (zv, p2); + if (!zn) + return NULL; + } + p2 = p1 + 1; } - p2 = p1 + 1; - } - return zv; + return zv; #endif } void zfile_fclose_archive (struct zvolume *zv) { - struct znode *zn; - struct zvolume *v; - - if (!zv) - return; - zn = &zv->root; - while (zn) { - struct znode *zn2 = zn->next; - if (zn->vchild) - zfile_fclose_archive (zn->vchild); - xfree (zn->comment); - xfree (zn->fullname); - xfree (zn->name); - zfile_fclose (zn->f); - memset (zn, 0, sizeof (struct znode)); - if (zn != &zv->root) - xfree (zn); - zn = zn2; - } - archive_access_close (zv->handle, zv->id); - if (zvolume_list == zv) { - zvolume_list = zvolume_list->next; - } else { - v = zvolume_list; - while (v) { - if (v->next == zv) { - v->next = zv->next; - break; - } - v = v->next; - } - } - xfree (zv); + struct znode *zn; + struct zvolume *v; + + if (!zv) + return; + zn = &zv->root; + while (zn) { + struct znode *zn2 = zn->next; + if (zn->vchild) + zfile_fclose_archive (zn->vchild); + xfree (zn->comment); + xfree (zn->fullname); + xfree (zn->name); + zfile_fclose (zn->f); + memset (zn, 0, sizeof (struct znode)); + if (zn != &zv->root) + xfree (zn); + zn = zn2; + } + archive_access_close (zv->handle, zv->id); + if (zvolume_list == zv) { + zvolume_list = zvolume_list->next; + } else { + v = zvolume_list; + while (v) { + if (v->next == zv) { + v->next = zv->next; + break; + } + v = v->next; + } + } + xfree (zv); } struct zdirectory { - struct znode *first; - struct znode *n; + struct znode *first; + struct znode *n; }; void *zfile_opendir_archive (const TCHAR *path) { - struct zvolume *zv = get_zvolume (path); - struct znode *zn = get_znode (zv, path, TRUE); - struct zdirectory *zd; + struct zvolume *zv = get_zvolume (path); + struct znode *zn = get_znode (zv, path, TRUE); + struct zdirectory *zd; - if (!zn || (!zn->child && !zn->vchild)) - return NULL; - zd = xmalloc (sizeof (struct zdirectory)); - if (zn->child) { - zd->n = zn->child; - } else { - if (zn->vchild->archive == NULL) { - struct zvolume *zvnew = prepare_recursive_volume (zn->vchild, path); - if (zvnew) { - zn->vchild = zvnew; - zvnew->parentz = zn; - } + if (!zn || (!zn->child && !zn->vchild)) + return NULL; + zd = xmalloc (sizeof (struct zdirectory)); + if (zn->child) { + zd->n = zn->child; + } else { + if (zn->vchild->archive == NULL) { + struct zvolume *zvnew = prepare_recursive_volume (zn->vchild, path); + if (zvnew) { + zn->vchild = zvnew; + zvnew->parentz = zn; + } + } + zd->n = zn->vchild->root.next; } - zd->n = zn->vchild->root.next; - } - zd->first = zd->n; - return zd; + zd->first = zd->n; + return zd; } void zfile_closedir_archive (struct zdirectory *zd) { - xfree (zd); + xfree (zd); } int zfile_readdir_archive (struct zdirectory *zd, TCHAR *out) { - if (!zd->n) - return 0; - _tcscpy (out, zd->n->name); - zd->n = zd->n->sibling; - return 1; + if (!zd->n) + return 0; + _tcscpy (out, zd->n->name); + zd->n = zd->n->sibling; + return 1; } void zfile_resetdir_archive (struct zdirectory *zd) { - zd->n = zd->first; + zd->n = zd->first; } int zfile_fill_file_attrs_archive (const TCHAR *path, int *isdir, int *flags, TCHAR **comment) { - struct zvolume *zv = get_zvolume (path); - struct znode *zn = get_znode (zv, path, TRUE); - - *isdir = 0; - *flags = 0; - if (comment) - *comment = 0; - if (!zn) - return 0; - if (zn->type == ZNODE_DIR) - *isdir = 1; - else if (zn->type == ZNODE_VDIR) - *isdir = -1; - *flags = zn->flags; - if (zn->comment && comment) - *comment = my_strdup (zn->comment); - return 1; + struct zvolume *zv = get_zvolume (path); + struct znode *zn = get_znode (zv, path, TRUE); + + *isdir = 0; + *flags = 0; + if (comment) + *comment = 0; + if (!zn) + return 0; + if (zn->type == ZNODE_DIR) + *isdir = 1; + else if (zn->type == ZNODE_VDIR) + *isdir = -1; + *flags = zn->flags; + if (zn->comment && comment) + *comment = my_strdup (zn->comment); + return 1; } int zfile_fs_usage_archive (const TCHAR *path, const TCHAR *disk, struct fs_usage *fsp) { - struct zvolume *zv = get_zvolume (path); + struct zvolume *zv = get_zvolume (path); - if (!zv) - return -1; - fsp->fsu_blocks = zv->blocks; - fsp->fsu_bavail = 0; - return 0; + if (!zv) + return -1; + fsp->fsu_blocks = zv->blocks; + fsp->fsu_bavail = 0; + return 0; } int zfile_stat_archive (const TCHAR *path, struct _stat64 *s) { - struct zvolume *zv = get_zvolume (path); - struct znode *zn = get_znode (zv, path, TRUE); + struct zvolume *zv = get_zvolume (path); + struct znode *zn = get_znode (zv, path, TRUE); - memset (s, 0, sizeof (struct _stat64)); - if (!zn) - return 0; - s->st_mode = zn->type == ZNODE_FILE ? 0 : FILEFLAG_DIR; - s->st_size = zn->size; - s->st_mtime = zn->mtime; - return 1; + memset (s, 0, sizeof (struct _stat64)); + if (!zn) + return 0; + s->st_mode = zn->type == ZNODE_FILE ? 0 : FILEFLAG_DIR; + s->st_size = zn->size; + s->st_mtime = zn->mtime; + return 1; } uae_s64 zfile_lseek_archive (void *d, uae_s64 offset, int whence) { - if (zfile_fseek (d, offset, whence)) - return -1; - return zfile_ftell (d); + if (zfile_fseek (d, offset, whence)) + return -1; + return zfile_ftell (d); } unsigned int zfile_read_archive (void *d, void *b, unsigned int size) { - return zfile_fread (b, 1, size, d); + return zfile_fread (b, 1, size, d); } void zfile_close_archive (void *d) { - /* do nothing, keep file cached */ + /* do nothing, keep file cached */ } void *zfile_open_archive (const TCHAR *path, int flags) { - struct zvolume *zv = get_zvolume (path); - struct znode *zn = get_znode (zv, path, TRUE); - struct zfile *z; + struct zvolume *zv = get_zvolume (path); + struct znode *zn = get_znode (zv, path, TRUE); + struct zfile *z; - if (!zn) - return 0; - if (zn->f) { - zfile_fseek (zn->f, 0, SEEK_SET); + if (!zn) + return 0; + if (zn->f) { + zfile_fseek (zn->f, 0, SEEK_SET); + return zn->f; + } + if (zn->vfile) + zn = zn->vfile; + z = archive_getzfile (zn, zn->volume->id); + if (z) + zfile_fseek (z, 0, SEEK_SET); + zn->f = z; return zn->f; - } - if (zn->vfile) - zn = zn->vfile; - z = archive_getzfile (zn, zn->volume->id); - if (z) - zfile_fseek (z, 0, SEEK_SET); - zn->f = z; - return zn->f; } int zfile_exists_archive (const TCHAR *path, const TCHAR *rel) { - TCHAR tmp[MAX_DPATH]; - struct zvolume *zv; - struct znode *zn; + TCHAR tmp[MAX_DPATH]; + struct zvolume *zv; + struct znode *zn; - _stprintf (tmp, L"%s%c%s", path, FSDB_DIR_SEPARATOR, rel); - zv = get_zvolume (tmp); - zn = get_znode (zv, tmp, TRUE); - return zn ? 1 : 0; + _stprintf (tmp, L"%s%c%s", path, FSDB_DIR_SEPARATOR, rel); + zv = get_zvolume (tmp); + zn = get_znode (zv, tmp, TRUE); + return zn ? 1 : 0; } int zfile_convertimage (const TCHAR *src, const TCHAR *dst) { - struct zfile *s, *d; - struct zvolume *zv; - int ret = 0; + struct zfile *s, *d; + struct zvolume *zv; + int ret = 0; - zv = zfile_open_archive (src, 0); - s = zfile_fopen (src, L"rb", ZFD_NORMAL); - if (s) { - uae_u8 *b; - int size; - zfile_fseek (s, 0, SEEK_END); - size = zfile_ftell (s); - zfile_fseek (s, 0, SEEK_SET); - b = xcalloc (size, 1); - if (b) { - if (zfile_fread (b, size, 1, s) == 1) { - d = zfile_fopen (dst, L"wb", 0); - if (d) { - if (zfile_fwrite (b, size, 1, d) == 1) - ret = 1; - zfile_fclose (d); + zv = zfile_open_archive (src, 0); + s = zfile_fopen (src, L"rb", ZFD_NORMAL); + if (s) { + uae_u8 *b; + int size; + zfile_fseek (s, 0, SEEK_END); + size = zfile_ftell (s); + zfile_fseek (s, 0, SEEK_SET); + b = xcalloc (size, 1); + if (b) { + if (zfile_fread (b, size, 1, s) == 1) { + d = zfile_fopen (dst, L"wb", 0); + if (d) { + if (zfile_fwrite (b, size, 1, d) == 1) + ret = 1; + zfile_fclose (d); + } + } + xfree (b); } - } - xfree (b); + zfile_fclose (s); } - zfile_fclose (s); - } - return ret; + return ret; } #ifdef _CONSOLE @@ -2592,19 +2596,19 @@ static TCHAR *zerror; #define WRITE_LOG_BUF_SIZE 4096 void zfile_seterror (const TCHAR *format, ...) { - int count; - if (!zerror) { - TCHAR buffer[WRITE_LOG_BUF_SIZE]; - va_list parms; - va_start (parms, format); - count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); - zerror = my_strdup (buffer); - va_end (parms); - } + int count; + if (!zerror) { + TCHAR buffer[WRITE_LOG_BUF_SIZE]; + va_list parms; + va_start (parms, format); + count = _vsntprintf (buffer, WRITE_LOG_BUF_SIZE - 1, format, parms); + zerror = my_strdup (buffer); + va_end (parms); + } } TCHAR *zfile_geterror (void) { - return zerror; + return zerror; } #else void zfile_seterror (const TCHAR *format, ...) diff --git a/zfile_archive.c b/zfile_archive.c index 26dede37..bc185809 100644 --- a/zfile_archive.c +++ b/zfile_archive.c @@ -1,10 +1,10 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * transparent archive handling - * - * 2007 Toni Wilen - */ +/* +* UAE - The Un*x Amiga Emulator +* +* transparent archive handling +* +* 2007 Toni Wilen +*/ #define ZLIB_WINAPI @@ -28,320 +28,320 @@ static time_t fromdostime (uae_u32 dd) { - struct tm tm; - time_t t; - - memset (&tm, 0, sizeof tm); - tm.tm_hour = (dd >> 11) & 0x1f; - tm.tm_min = (dd >> 5) & 0x3f; - tm.tm_sec = ((dd >> 0) & 0x1f) * 2; - tm.tm_year = ((dd >> 25) & 0x7f) + 80; - tm.tm_mon = ((dd >> 21) & 0x0f) - 1; - tm.tm_mday = (dd >> 16) & 0x1f; - t = mktime (&tm); - _tzset (); - t -= _timezone; - return t; + struct tm tm; + time_t t; + + memset (&tm, 0, sizeof tm); + tm.tm_hour = (dd >> 11) & 0x1f; + tm.tm_min = (dd >> 5) & 0x3f; + tm.tm_sec = ((dd >> 0) & 0x1f) * 2; + tm.tm_year = ((dd >> 25) & 0x7f) + 80; + tm.tm_mon = ((dd >> 21) & 0x0f) - 1; + tm.tm_mday = (dd >> 16) & 0x1f; + t = mktime (&tm); + _tzset (); + t -= _timezone; + return t; } static struct zvolume *getzvolume (struct znode *parent, struct zfile *zf, unsigned int id) { - struct zvolume *zv = NULL; + struct zvolume *zv = NULL; - switch (id) - { + switch (id) + { case ArchiveFormatZIP: - zv = archive_directory_zip (zf); - break; + zv = archive_directory_zip (zf); + break; case ArchiveFormat7Zip: - zv = archive_directory_7z (zf); - break; + zv = archive_directory_7z (zf); + break; case ArchiveFormatRAR: - zv = archive_directory_rar (zf); - break; + zv = archive_directory_rar (zf); + break; case ArchiveFormatLHA: - zv = archive_directory_lha (zf); - break; + zv = archive_directory_lha (zf); + break; case ArchiveFormatLZX: - zv = archive_directory_lzx (zf); - break; + zv = archive_directory_lzx (zf); + break; case ArchiveFormatPLAIN: - zv = archive_directory_plain (zf); - break; + zv = archive_directory_plain (zf); + break; case ArchiveFormatADF: - zv = archive_directory_adf (parent, zf); - break; + zv = archive_directory_adf (parent, zf); + break; case ArchiveFormatRDB: - zv = archive_directory_rdb (zf); - break; + zv = archive_directory_rdb (zf); + break; case ArchiveFormatFAT: - zv = archive_directory_fat (zf); - break; - } - if (!zv) - zv = archive_directory_arcacc (zf, id); - return zv; + zv = archive_directory_fat (zf); + break; + } + if (!zv) + zv = archive_directory_arcacc (zf, id); + return zv; } struct zfile *archive_getzfile (struct znode *zn, unsigned int id) { - struct zfile *zf = NULL; + struct zfile *zf = NULL; - switch (id) - { + switch (id) + { case ArchiveFormatZIP: - zf = archive_access_zip (zn); - break; + zf = archive_access_zip (zn); + break; case ArchiveFormat7Zip: - zf = archive_access_7z (zn); - break; + zf = archive_access_7z (zn); + break; case ArchiveFormatRAR: - zf = archive_access_rar (zn); - break; + zf = archive_access_rar (zn); + break; case ArchiveFormatLHA: - zf = archive_access_lha (zn); - break; + zf = archive_access_lha (zn); + break; case ArchiveFormatLZX: - zf = archive_access_lzx (zn); - break; + zf = archive_access_lzx (zn); + break; case ArchiveFormatPLAIN: - zf = archive_access_plain (zn); - break; + zf = archive_access_plain (zn); + break; case ArchiveFormatADF: - zf = archive_access_adf (zn); - break; + zf = archive_access_adf (zn); + break; case ArchiveFormatRDB: - zf = archive_access_rdb (zn); - break; + zf = archive_access_rdb (zn); + break; case ArchiveFormatFAT: - zf = archive_access_fat (zn); - break; + zf = archive_access_fat (zn); + break; case ArchiveFormatDIR: - zf = archive_access_dir (zn); - break; - } - return zf; + zf = archive_access_dir (zn); + break; + } + return zf; } struct zfile *archive_access_select (struct znode *parent, struct zfile *zf, unsigned int id, int dodefault, int *retcode) { - struct zvolume *zv; - struct znode *zn; - int zipcnt, first, select; - TCHAR tmphist[MAX_DPATH]; - struct zfile *z = NULL; - int we_have_file; - int canhistory = (zf->zfdmask & ZFD_DISKHISTORY) && !(zf->zfdmask & ZFD_CHECKONLY); - - if (retcode) - *retcode = 0; - zv = getzvolume (parent, zf, id); - if (!zv) - return NULL; - we_have_file = 0; - tmphist[0] = 0; - zipcnt = 1; - first = 1; - zn = &zv->root; - while (zn) { - int isok = 1, diskimg = 0; - - if (zn->type != ZNODE_FILE) - isok = 0; - if (zfile_is_ignore_ext (zn->fullname)) - isok = 0; - if (zfile_is_diskimage (zn->fullname)) - diskimg = 1; - if (isok) { - if (tmphist[0]) { + struct zvolume *zv; + struct znode *zn; + int zipcnt, first, select; + TCHAR tmphist[MAX_DPATH]; + struct zfile *z = NULL; + int we_have_file; + int canhistory = (zf->zfdmask & ZFD_DISKHISTORY) && !(zf->zfdmask & ZFD_CHECKONLY); + + if (retcode) + *retcode = 0; + zv = getzvolume (parent, zf, id); + if (!zv) + return NULL; + we_have_file = 0; + tmphist[0] = 0; + zipcnt = 1; + first = 1; + zn = &zv->root; + while (zn) { + int isok = 1, diskimg = 0; + + if (zn->type != ZNODE_FILE) + isok = 0; + if (zfile_is_ignore_ext (zn->fullname)) + isok = 0; + if (zfile_is_diskimage (zn->fullname)) + diskimg = 1; + if (isok) { + if (tmphist[0]) { #ifndef _CONSOLE - if (diskimg && canhistory) - DISK_history_add (tmphist, -1, 1); + if (diskimg && canhistory) + DISK_history_add (tmphist, -1, 1); #endif - tmphist[0] = 0; - first = 0; - } - if (first) { - if (diskimg) - _tcscpy (tmphist, zn->fullname); - } else { - _tcscpy (tmphist, zn->fullname); + tmphist[0] = 0; + first = 0; + } + if (first) { + if (diskimg) + _tcscpy (tmphist, zn->fullname); + } else { + _tcscpy (tmphist, zn->fullname); #ifndef _CONSOLE - if (diskimg && canhistory) - DISK_history_add (tmphist, -1, 1); + if (diskimg && canhistory) + DISK_history_add (tmphist, -1, 1); #endif - tmphist[0] = 0; - } - select = 0; - if (!zf->zipname) - select = 1; - if (zf->zipname && _tcslen (zn->fullname) >= _tcslen (zf->zipname) && !strcasecmp (zf->zipname, zn->fullname + _tcslen (zn->fullname) - _tcslen (zf->zipname))) - select = -1; - if (zf->zipname && zf->zipname[0] == '#' && _tstol (zf->zipname + 1) == zipcnt) - select = -1; - if (select && !we_have_file) { - z = archive_getzfile (zn, id); - if (z) { - if (select < 0 || zfile_gettype (z)) - we_have_file = 1; - if (!we_have_file) { - zfile_fclose (z); - z = NULL; - } + tmphist[0] = 0; + } + select = 0; + if (!zf->zipname) + select = 1; + if (zf->zipname && _tcslen (zn->fullname) >= _tcslen (zf->zipname) && !strcasecmp (zf->zipname, zn->fullname + _tcslen (zn->fullname) - _tcslen (zf->zipname))) + select = -1; + if (zf->zipname && zf->zipname[0] == '#' && _tstol (zf->zipname + 1) == zipcnt) + select = -1; + if (select && !we_have_file) { + z = archive_getzfile (zn, id); + if (z) { + if (select < 0 || zfile_gettype (z)) + we_have_file = 1; + if (!we_have_file) { + zfile_fclose (z); + z = NULL; + } + } + } } - } + zipcnt++; + zn = zn->next; } - zipcnt++; - zn = zn->next; - } #ifndef _CONSOLE - if (zfile_is_diskimage (zfile_getname (zf)) && first && tmphist[0] && canhistory) - DISK_history_add (zfile_getname (zf), -1, 1); + if (zfile_is_diskimage (zfile_getname (zf)) && first && tmphist[0] && canhistory) + DISK_history_add (zfile_getname (zf), -1, 1); #endif - zfile_fclose_archive (zv); - if (z) { - zfile_fclose (zf); - zf = z; - } else if (!dodefault && zf->zipname && zf->zipname[0]) { - if (retcode) - *retcode = -1; - zf = NULL; - } - return zf; + zfile_fclose_archive (zv); + if (z) { + zfile_fclose (zf); + zf = z; + } else if (!dodefault && zf->zipname && zf->zipname[0]) { + if (retcode) + *retcode = -1; + zf = NULL; + } + return zf; } struct zfile *archive_access_arcacc_select (struct zfile *zf, unsigned int id, int *retcode) { - return zf; + return zf; } void archive_access_scan (struct zfile *zf, zfile_callback zc, void *user, unsigned int id) { - struct zvolume *zv; - struct znode *zn; - - zv = getzvolume (NULL, zf, id); - if (!zv) - return; - zn = &zv->root; - while (zn) { - if (zn->type == ZNODE_FILE) { - struct zfile *zf2 = archive_getzfile (zn, id); - if (zf2) { - int ztype = iszip (zf2); - if (ztype) { - zfile_fclose (zf2); - } else { - int ret = zc (zf2, user); - zfile_fclose (zf2); - if (ret) - break; + struct zvolume *zv; + struct znode *zn; + + zv = getzvolume (NULL, zf, id); + if (!zv) + return; + zn = &zv->root; + while (zn) { + if (zn->type == ZNODE_FILE) { + struct zfile *zf2 = archive_getzfile (zn, id); + if (zf2) { + int ztype = iszip (zf2); + if (ztype) { + zfile_fclose (zf2); + } else { + int ret = zc (zf2, user); + zfile_fclose (zf2); + if (ret) + break; + } + } } - } + zn = zn->next; } - zn = zn->next; - } - zfile_fclose_archive (zv); + zfile_fclose_archive (zv); } /* ZIP */ static void archive_close_zip (void *handle) { - unzClose (handle); + unzClose (handle); } struct zvolume *archive_directory_zip (struct zfile *z) { - unzFile uz; - unz_file_info file_info; - struct zvolume *zv; - int err; + unzFile uz; + unz_file_info file_info; + struct zvolume *zv; + int err; - uz = unzOpen (z); - if (!uz) - return 0; - if (unzGoToFirstFile (uz) != UNZ_OK) - return 0; - zv = zvolume_alloc (z, ArchiveFormatZIP, uz, NULL); - for (;;) { - char filename_inzip2[MAX_DPATH]; - TCHAR c; - struct zarchive_info zai; - time_t t; - unsigned int dd; - TCHAR *filename_inzip; - - err = unzGetCurrentFileInfo (uz, &file_info, filename_inzip2, sizeof (filename_inzip2), NULL, 0, NULL, 0); - if (err != UNZ_OK) - return 0; - filename_inzip = au (filename_inzip2); - dd = file_info.dosDate; - t = fromdostime (dd); - memset(&zai, 0, sizeof zai); - zai.name = filename_inzip; - zai.t = t; - zai.flags = -1; - c = filename_inzip[_tcslen (filename_inzip) - 1]; - if (c != '/' && c != '\\') { - int err = unzOpenCurrentFile (uz); - if (err == UNZ_OK) { - struct znode *zn; - zai.size = file_info.uncompressed_size; - zn = zvolume_addfile_abs (zv, &zai); - } - } else { - filename_inzip[_tcslen (filename_inzip) - 1] = 0; - zvolume_adddir_abs (zv, &zai); + uz = unzOpen (z); + if (!uz) + return 0; + if (unzGoToFirstFile (uz) != UNZ_OK) + return 0; + zv = zvolume_alloc (z, ArchiveFormatZIP, uz, NULL); + for (;;) { + char filename_inzip2[MAX_DPATH]; + TCHAR c; + struct zarchive_info zai; + time_t t; + unsigned int dd; + TCHAR *filename_inzip; + + err = unzGetCurrentFileInfo (uz, &file_info, filename_inzip2, sizeof (filename_inzip2), NULL, 0, NULL, 0); + if (err != UNZ_OK) + return 0; + filename_inzip = au (filename_inzip2); + dd = file_info.dosDate; + t = fromdostime (dd); + memset(&zai, 0, sizeof zai); + zai.name = filename_inzip; + zai.t = t; + zai.flags = -1; + c = filename_inzip[_tcslen (filename_inzip) - 1]; + if (c != '/' && c != '\\') { + int err = unzOpenCurrentFile (uz); + if (err == UNZ_OK) { + struct znode *zn; + zai.size = file_info.uncompressed_size; + zn = zvolume_addfile_abs (zv, &zai); + } + } else { + filename_inzip[_tcslen (filename_inzip) - 1] = 0; + zvolume_adddir_abs (zv, &zai); + } + xfree (filename_inzip); + err = unzGoToNextFile (uz); + if (err != UNZ_OK) + break; } - xfree (filename_inzip); - err = unzGoToNextFile (uz); - if (err != UNZ_OK) - break; - } - zv->method = ArchiveFormatZIP; - return zv; + zv->method = ArchiveFormatZIP; + return zv; } struct zfile *archive_access_zip (struct znode *zn) { - struct zfile *z = NULL; - unzFile uz = zn->volume->handle; - int i, err; - TCHAR tmp[MAX_DPATH]; - char *s; - - _tcscpy (tmp, zn->fullname + _tcslen (zn->volume->root.fullname) + 1); - if (unzGoToFirstFile (uz) != UNZ_OK) - return 0; - for (i = 0; tmp[i]; i++) { - if (tmp[i] == '\\') - tmp[i] = '/'; - } - s = ua (tmp); - if (unzLocateFile (uz, s, 1) != UNZ_OK) { - xfree (s); + struct zfile *z = NULL; + unzFile uz = zn->volume->handle; + int i, err; + TCHAR tmp[MAX_DPATH]; + char *s; + + _tcscpy (tmp, zn->fullname + _tcslen (zn->volume->root.fullname) + 1); + if (unzGoToFirstFile (uz) != UNZ_OK) + return 0; for (i = 0; tmp[i]; i++) { - if (tmp[i] == '/') - tmp[i] = '\\'; + if (tmp[i] == '\\') + tmp[i] = '/'; } s = ua (tmp); if (unzLocateFile (uz, s, 1) != UNZ_OK) { - xfree (s); - return 0; + xfree (s); + for (i = 0; tmp[i]; i++) { + if (tmp[i] == '/') + tmp[i] = '\\'; + } + s = ua (tmp); + if (unzLocateFile (uz, s, 1) != UNZ_OK) { + xfree (s); + return 0; + } } - } - xfree (s); - s = NULL; - if (unzOpenCurrentFile (uz) != UNZ_OK) - return 0; - z = zfile_fopen_empty (uz, zn->fullname, zn->size); - if (z) { - err = unzReadCurrentFile (uz, z->data, zn->size); - } - unzCloseCurrentFile (uz); - return z; + xfree (s); + s = NULL; + if (unzOpenCurrentFile (uz) != UNZ_OK) + return 0; + z = zfile_fopen_empty (uz, zn->fullname, zn->size); + if (z) { + err = unzReadCurrentFile (uz, z->data, zn->size); + } + unzCloseCurrentFile (uz); + return z; } /* 7Z */ @@ -357,64 +357,64 @@ static ISzAlloc allocTempImp; typedef struct { - ISeekInStream s; - struct zfile *zf; + ISeekInStream s; + struct zfile *zf; } CFileInStream; static SRes SzFileReadImp (void *object, void *buffer, size_t *size) { - CFileInStream *s = (CFileInStream *)object; - *size = zfile_fread (buffer, 1, *size, s->zf); - return SZ_OK; + CFileInStream *s = (CFileInStream *)object; + *size = zfile_fread (buffer, 1, *size, s->zf); + return SZ_OK; } static SRes SzFileSeekImp(void *object, Int64 *pos, ESzSeek origin) { - CFileInStream *s = (CFileInStream *)object; - int org = 0; - switch (origin) - { - case SZ_SEEK_SET: org = SEEK_SET; break; - case SZ_SEEK_CUR: org = SEEK_CUR; break; - case SZ_SEEK_END: org = SEEK_END; break; - } - zfile_fseek (s->zf, *pos, org); - *pos = zfile_ftell (s->zf); - return 0; + CFileInStream *s = (CFileInStream *)object; + int org = 0; + switch (origin) + { + case SZ_SEEK_SET: org = SEEK_SET; break; + case SZ_SEEK_CUR: org = SEEK_CUR; break; + case SZ_SEEK_END: org = SEEK_END; break; + } + zfile_fseek (s->zf, *pos, org); + *pos = zfile_ftell (s->zf); + return 0; } static void init_7z (void) { - static int initialized; - - if (initialized) - return; - initialized = 1; - allocImp.Alloc = SzAlloc; - allocImp.Free = SzFree; - allocTempImp.Alloc = SzAllocTemp; - allocTempImp.Free = SzFreeTemp; - CrcGenerateTable (); - _tzset (); + static int initialized; + + if (initialized) + return; + initialized = 1; + allocImp.Alloc = SzAlloc; + allocImp.Free = SzFree; + allocTempImp.Alloc = SzAllocTemp; + allocTempImp.Free = SzFreeTemp; + CrcGenerateTable (); + _tzset (); } struct SevenZContext { - CSzArEx db; - CFileInStream archiveStream; - CLookToRead lookStream; - Byte *outBuffer; - size_t outBufferSize; - UInt32 blockIndex; + CSzArEx db; + CFileInStream archiveStream; + CLookToRead lookStream; + Byte *outBuffer; + size_t outBufferSize; + UInt32 blockIndex; }; static void archive_close_7z (struct SevenZContext *ctx) { - SzArEx_Free (&ctx->db, &allocImp); - allocImp.Free (&allocImp, ctx->outBuffer); - xfree (ctx); + SzArEx_Free (&ctx->db, &allocImp); + allocImp.Free (&allocImp, ctx->outBuffer); + xfree (ctx); } #define EPOCH_DIFF 0x019DB1DED53E8000LL /* 116444736000000000 nsecs */ @@ -422,79 +422,79 @@ static void archive_close_7z (struct SevenZContext *ctx) struct zvolume *archive_directory_7z (struct zfile *z) { - SRes res; - struct zvolume *zv; - int i; - struct SevenZContext *ctx; - - init_7z (); - ctx = xcalloc (sizeof (struct SevenZContext), 1); - ctx->blockIndex = 0xffffffff; - ctx->archiveStream.s.Read = SzFileReadImp; - ctx->archiveStream.s.Seek = SzFileSeekImp; - ctx->archiveStream.zf = z; - LookToRead_CreateVTable (&ctx->lookStream, False); - ctx->lookStream.realStream = &ctx->archiveStream.s; - LookToRead_Init (&ctx->lookStream); - - SzArEx_Init (&ctx->db); - res = SzArEx_Open (&ctx->db, &ctx->lookStream.s, &allocImp, &allocTempImp); - if (res != SZ_OK) { - write_log (L"7Z: SzArchiveOpen %s returned %d\n", zfile_getname (z), res); - xfree (ctx); - return NULL; - } - zv = zvolume_alloc (z, ArchiveFormat7Zip, ctx, NULL); - for (i = 0; i < ctx->db.db.NumFiles; i++) { - CSzFileItem *f = ctx->db.db.Files + i; - TCHAR *name = au (f->Name); - struct zarchive_info zai; - - memset(&zai, 0, sizeof zai); - zai.name = name; - zai.flags = -1; - zai.size = f->Size; - zai.t = 0; - if (f->MTimeDefined) { - uae_u64 t = (((uae_u64)f->MTime.High) << 32) | f->MTime.Low; - if (t >= EPOCH_DIFF) { - zai.t = (t - EPOCH_DIFF) / RATE_DIFF; - zai.t -= _timezone; - if (_daylight) - zai.t += 1 * 60 * 60; - } + SRes res; + struct zvolume *zv; + int i; + struct SevenZContext *ctx; + + init_7z (); + ctx = xcalloc (sizeof (struct SevenZContext), 1); + ctx->blockIndex = 0xffffffff; + ctx->archiveStream.s.Read = SzFileReadImp; + ctx->archiveStream.s.Seek = SzFileSeekImp; + ctx->archiveStream.zf = z; + LookToRead_CreateVTable (&ctx->lookStream, False); + ctx->lookStream.realStream = &ctx->archiveStream.s; + LookToRead_Init (&ctx->lookStream); + + SzArEx_Init (&ctx->db); + res = SzArEx_Open (&ctx->db, &ctx->lookStream.s, &allocImp, &allocTempImp); + if (res != SZ_OK) { + write_log (L"7Z: SzArchiveOpen %s returned %d\n", zfile_getname (z), res); + xfree (ctx); + return NULL; } - if (!f->IsDir) { - struct znode *zn = zvolume_addfile_abs (zv, &zai); - zn->offset = i; + zv = zvolume_alloc (z, ArchiveFormat7Zip, ctx, NULL); + for (i = 0; i < ctx->db.db.NumFiles; i++) { + CSzFileItem *f = ctx->db.db.Files + i; + TCHAR *name = au (f->Name); + struct zarchive_info zai; + + memset(&zai, 0, sizeof zai); + zai.name = name; + zai.flags = -1; + zai.size = f->Size; + zai.t = 0; + if (f->MTimeDefined) { + uae_u64 t = (((uae_u64)f->MTime.High) << 32) | f->MTime.Low; + if (t >= EPOCH_DIFF) { + zai.t = (t - EPOCH_DIFF) / RATE_DIFF; + zai.t -= _timezone; + if (_daylight) + zai.t += 1 * 60 * 60; + } + } + if (!f->IsDir) { + struct znode *zn = zvolume_addfile_abs (zv, &zai); + zn->offset = i; + } + xfree (name); } - xfree (name); - } - zv->method = ArchiveFormat7Zip; - return zv; + zv->method = ArchiveFormat7Zip; + return zv; } struct zfile *archive_access_7z (struct znode *zn) { - SRes res; - struct zvolume *zv = zn->volume; - struct zfile *z = NULL; - size_t offset; - size_t outSizeProcessed; - struct SevenZContext *ctx; - - ctx = zv->handle; - res = SzAr_Extract (&ctx->db, &ctx->lookStream.s, zn->offset, - &ctx->blockIndex, &ctx->outBuffer, &ctx->outBufferSize, - &offset, &outSizeProcessed, - &allocImp, &allocTempImp); - if (res == SZ_OK) { - z = zfile_fopen_empty (NULL, zn->fullname, zn->size); - zfile_fwrite (ctx->outBuffer + offset, zn->size, 1, z); - } else { - write_log (L"7Z: SzExtract %s returned %d\n", zn->fullname, res); - } - return z; + SRes res; + struct zvolume *zv = zn->volume; + struct zfile *z = NULL; + size_t offset; + size_t outSizeProcessed; + struct SevenZContext *ctx; + + ctx = zv->handle; + res = SzAr_Extract (&ctx->db, &ctx->lookStream.s, zn->offset, + &ctx->blockIndex, &ctx->outBuffer, &ctx->outBufferSize, + &offset, &outSizeProcessed, + &allocImp, &allocTempImp); + if (res == SZ_OK) { + z = zfile_fopen_empty (NULL, zn->fullname, zn->size); + zfile_fwrite (ctx->outBuffer + offset, zn->size, 1, z); + } else { + write_log (L"7Z: SzExtract %s returned %d\n", zn->fullname, res); + } + return z; } /* RAR */ @@ -519,147 +519,147 @@ static RARGETDLLVERSION pRARGetDllVersion; static int rar_resetf (struct zfile *z) { - z->f = _tfopen (z->name, L"rb"); - if (!z->f) { - zfile_fclose (z); - return 0; - } - return 1; + z->f = _tfopen (z->name, L"rb"); + if (!z->f) { + zfile_fclose (z); + return 0; + } + return 1; } static int canrar (void) { - static int israr; + static int israr; - if (israr == 0) { - israr = -1; + if (israr == 0) { + israr = -1; #ifdef _WIN32 - { - HMODULE rarlib; - - rarlib = WIN32_LoadLibrary (L"unrar.dll"); - if (rarlib) { - pRAROpenArchiveEx = (RAROPENARCHIVEEX)GetProcAddress (rarlib, "RAROpenArchiveEx"); - pRARReadHeaderEx = (RARREADHEADEREX)GetProcAddress (rarlib, "RARReadHeaderEx"); - pRARProcessFile = (RARPROCESSFILE)GetProcAddress (rarlib, "RARProcessFile"); - pRARCloseArchive = (RARCLOSEARCHIVE)GetProcAddress (rarlib, "RARCloseArchive"); - pRARSetCallback = (RARSETCALLBACK)GetProcAddress (rarlib, "RARSetCallback"); - pRARGetDllVersion = (RARGETDLLVERSION)GetProcAddress (rarlib, "RARGetDllVersion"); - if (pRAROpenArchiveEx && pRARReadHeaderEx && pRARProcessFile && pRARCloseArchive && pRARSetCallback) { - israr = 1; - write_log (L"unrar.dll version %08X detected and used\n", pRARGetDllVersion ? pRARGetDllVersion() : -1); - + { + HMODULE rarlib; + + rarlib = WIN32_LoadLibrary (L"unrar.dll"); + if (rarlib) { + pRAROpenArchiveEx = (RAROPENARCHIVEEX)GetProcAddress (rarlib, "RAROpenArchiveEx"); + pRARReadHeaderEx = (RARREADHEADEREX)GetProcAddress (rarlib, "RARReadHeaderEx"); + pRARProcessFile = (RARPROCESSFILE)GetProcAddress (rarlib, "RARProcessFile"); + pRARCloseArchive = (RARCLOSEARCHIVE)GetProcAddress (rarlib, "RARCloseArchive"); + pRARSetCallback = (RARSETCALLBACK)GetProcAddress (rarlib, "RARSetCallback"); + pRARGetDllVersion = (RARGETDLLVERSION)GetProcAddress (rarlib, "RARGetDllVersion"); + if (pRAROpenArchiveEx && pRARReadHeaderEx && pRARProcessFile && pRARCloseArchive && pRARSetCallback) { + israr = 1; + write_log (L"unrar.dll version %08X detected and used\n", pRARGetDllVersion ? pRARGetDllVersion() : -1); + + } + } } - } - } #endif - } - return israr < 0 ? 0 : 1; + } + return israr < 0 ? 0 : 1; } static int CALLBACK RARCallbackProc (UINT msg,LONG UserData,LONG P1,LONG P2) { - if (msg == UCM_PROCESSDATA) { - zfile_fwrite ((uae_u8*)P1, 1, P2, rarunpackzf); - return 0; - } - return -1; + if (msg == UCM_PROCESSDATA) { + zfile_fwrite ((uae_u8*)P1, 1, P2, rarunpackzf); + return 0; + } + return -1; } struct RARContext { - struct RAROpenArchiveDataEx OpenArchiveData; - struct RARHeaderDataEx HeaderData; - HANDLE hArcData; + struct RAROpenArchiveDataEx OpenArchiveData; + struct RARHeaderDataEx HeaderData; + HANDLE hArcData; }; static void archive_close_rar (struct RARContext *rc) { - xfree (rc); + xfree (rc); } struct zvolume *archive_directory_rar (struct zfile *z) { - struct zvolume *zv; - struct RARContext *rc; - struct zfile *zftmp; - int cnt; - - if (!canrar ()) - return archive_directory_arcacc (z, ArchiveFormatRAR); - if (z->data) - /* wtf? stupid unrar.dll only accept filename as an input.. */ - return archive_directory_arcacc (z, ArchiveFormatRAR); - rc = xcalloc (sizeof (struct RARContext), 1); - zv = zvolume_alloc (z, ArchiveFormatRAR, rc, NULL); - fclose (z->f); /* bleh, unrar.dll fails to open the archive if it is already open.. */ - z->f = NULL; - rc->OpenArchiveData.ArcNameW = z->name; - rc->OpenArchiveData.OpenMode = RAR_OM_LIST; - rc->hArcData = pRAROpenArchiveEx (&rc->OpenArchiveData); - if (rc->OpenArchiveData.OpenResult != 0) { - xfree (rc); - if (!rar_resetf (z)) { - zfile_fclose_archive (zv); - return NULL; + struct zvolume *zv; + struct RARContext *rc; + struct zfile *zftmp; + int cnt; + + if (!canrar ()) + return archive_directory_arcacc (z, ArchiveFormatRAR); + if (z->data) + /* wtf? stupid unrar.dll only accept filename as an input.. */ + return archive_directory_arcacc (z, ArchiveFormatRAR); + rc = xcalloc (sizeof (struct RARContext), 1); + zv = zvolume_alloc (z, ArchiveFormatRAR, rc, NULL); + fclose (z->f); /* bleh, unrar.dll fails to open the archive if it is already open.. */ + z->f = NULL; + rc->OpenArchiveData.ArcNameW = z->name; + rc->OpenArchiveData.OpenMode = RAR_OM_LIST; + rc->hArcData = pRAROpenArchiveEx (&rc->OpenArchiveData); + if (rc->OpenArchiveData.OpenResult != 0) { + xfree (rc); + if (!rar_resetf (z)) { + zfile_fclose_archive (zv); + return NULL; + } + zfile_fclose_archive (zv); + return archive_directory_arcacc (z, ArchiveFormatRAR); } - zfile_fclose_archive (zv); - return archive_directory_arcacc (z, ArchiveFormatRAR); - } - pRARSetCallback (rc->hArcData, RARCallbackProc, 0); - cnt = 0; - while (pRARReadHeaderEx (rc->hArcData, &rc->HeaderData) == 0) { - struct zarchive_info zai; - struct znode *zn; - memset (&zai, 0, sizeof zai); - zai.name = rc->HeaderData.FileNameW; - zai.size = rc->HeaderData.UnpSize; - zai.flags = -1; - zai.t = fromdostime (rc->HeaderData.FileTime); - zn = zvolume_addfile_abs (zv, &zai); - zn->offset = cnt++; - pRARProcessFile (rc->hArcData, RAR_SKIP, NULL, NULL); - } - pRARCloseArchive (rc->hArcData); - zftmp = zfile_fopen_empty (z, z->name, 0); - zv->archive = zftmp; - zv->method = ArchiveFormatRAR; - return zv; + pRARSetCallback (rc->hArcData, RARCallbackProc, 0); + cnt = 0; + while (pRARReadHeaderEx (rc->hArcData, &rc->HeaderData) == 0) { + struct zarchive_info zai; + struct znode *zn; + memset (&zai, 0, sizeof zai); + zai.name = rc->HeaderData.FileNameW; + zai.size = rc->HeaderData.UnpSize; + zai.flags = -1; + zai.t = fromdostime (rc->HeaderData.FileTime); + zn = zvolume_addfile_abs (zv, &zai); + zn->offset = cnt++; + pRARProcessFile (rc->hArcData, RAR_SKIP, NULL, NULL); + } + pRARCloseArchive (rc->hArcData); + zftmp = zfile_fopen_empty (z, z->name, 0); + zv->archive = zftmp; + zv->method = ArchiveFormatRAR; + return zv; } struct zfile *archive_access_rar (struct znode *zn) { - struct RARContext *rc = zn->volume->handle; - int i; - struct zfile *zf = NULL; - - if (zn->volume->method != ArchiveFormatRAR) - return archive_access_arcacc (zn); - rc->OpenArchiveData.OpenMode = RAR_OM_EXTRACT; - rc->hArcData = pRAROpenArchiveEx (&rc->OpenArchiveData); - if (rc->OpenArchiveData.OpenResult != 0) - return NULL; - pRARSetCallback (rc->hArcData, RARCallbackProc, 0); - for (i = 0; i <= zn->offset; i++) { - if (pRARReadHeaderEx (rc->hArcData, &rc->HeaderData)) - return NULL; - if (i < zn->offset) { - if (pRARProcessFile (rc->hArcData, RAR_SKIP, NULL, NULL)) - goto end; + struct RARContext *rc = zn->volume->handle; + int i; + struct zfile *zf = NULL; + + if (zn->volume->method != ArchiveFormatRAR) + return archive_access_arcacc (zn); + rc->OpenArchiveData.OpenMode = RAR_OM_EXTRACT; + rc->hArcData = pRAROpenArchiveEx (&rc->OpenArchiveData); + if (rc->OpenArchiveData.OpenResult != 0) + return NULL; + pRARSetCallback (rc->hArcData, RARCallbackProc, 0); + for (i = 0; i <= zn->offset; i++) { + if (pRARReadHeaderEx (rc->hArcData, &rc->HeaderData)) + return NULL; + if (i < zn->offset) { + if (pRARProcessFile (rc->hArcData, RAR_SKIP, NULL, NULL)) + goto end; + } } - } - zf = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); - if (zf) { - rarunpackzf = zf; - if (pRARProcessFile (rc->hArcData, RAR_TEST, NULL, NULL)) { - zfile_fclose (zf); - zf = NULL; + zf = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); + if (zf) { + rarunpackzf = zf; + if (pRARProcessFile (rc->hArcData, RAR_TEST, NULL, NULL)) { + zfile_fclose (zf); + zf = NULL; + } } - } end: - pRARCloseArchive(rc->hArcData); - return zf; + pRARCloseArchive(rc->hArcData); + return zf; } /* ArchiveAccess */ @@ -669,8 +669,8 @@ end: struct aaFILETIME { - uae_u32 dwLowDateTime; - uae_u32 dwHighDateTime; + uae_u32 dwLowDateTime; + uae_u32 dwHighDateTime; }; typedef void* aaHandle; // This struct contains file information from an archive. The caller may store @@ -705,31 +705,31 @@ static HMODULE arcacc_mod; static void arcacc_free (void) { - if (arcacc_mod) - FreeLibrary (arcacc_mod); - arcacc_mod = NULL; + if (arcacc_mod) + FreeLibrary (arcacc_mod); + arcacc_mod = NULL; } static int arcacc_init (struct zfile *zf) { - if (arcacc_mod) + if (arcacc_mod) + return 1; + arcacc_mod = WIN32_LoadLibrary (L"archiveaccess.dll"); + if (!arcacc_mod) { + write_log (L"failed to open archiveaccess.dll ('%s')\n", zfile_getname (zf)); + return 0; + } + aaOpenArchive = (aapOpenArchive) GetProcAddress (arcacc_mod, "aaOpenArchive"); + aaGetFileCount = (aapGetFileCount) GetProcAddress (arcacc_mod, "aaGetFileCount"); + aaGetFileInfo = (aapGetFileInfo) GetProcAddress (arcacc_mod, "aaGetFileInfo"); + aaExtract = (aapExtract) GetProcAddress (arcacc_mod, "aaExtract"); + aaCloseArchive = (aapCloseArchive) GetProcAddress (arcacc_mod, "aaCloseArchive"); + if (!aaOpenArchive || !aaGetFileCount || !aaGetFileInfo || !aaExtract || !aaCloseArchive) { + write_log (L"Missing functions in archiveaccess.dll. Old version?\n"); + arcacc_free (); + return 0; + } return 1; - arcacc_mod = WIN32_LoadLibrary (L"archiveaccess.dll"); - if (!arcacc_mod) { - write_log (L"failed to open archiveaccess.dll ('%s')\n", zfile_getname (zf)); - return 0; - } - aaOpenArchive = (aapOpenArchive) GetProcAddress (arcacc_mod, "aaOpenArchive"); - aaGetFileCount = (aapGetFileCount) GetProcAddress (arcacc_mod, "aaGetFileCount"); - aaGetFileInfo = (aapGetFileInfo) GetProcAddress (arcacc_mod, "aaGetFileInfo"); - aaExtract = (aapExtract) GetProcAddress (arcacc_mod, "aaExtract"); - aaCloseArchive = (aapCloseArchive) GetProcAddress (arcacc_mod, "aaCloseArchive"); - if (!aaOpenArchive || !aaGetFileCount || !aaGetFileInfo || !aaExtract || !aaCloseArchive) { - write_log (L"Missing functions in archiveaccess.dll. Old version?\n"); - arcacc_free (); - return 0; - } - return 1; } #endif @@ -739,121 +739,121 @@ static int arcacc_stackptr = -1; static int arcacc_push (struct zfile *f) { - if (arcacc_stackptr == ARCACC_STACKSIZE - 1) - return -1; - arcacc_stackptr++; - arcacc_stack[arcacc_stackptr] = f; - return arcacc_stackptr; + if (arcacc_stackptr == ARCACC_STACKSIZE - 1) + return -1; + arcacc_stackptr++; + arcacc_stack[arcacc_stackptr] = f; + return arcacc_stackptr; } static void arcacc_pop (void) { - arcacc_stackptr--; + arcacc_stackptr--; } static HRESULT __stdcall readCallback (int StreamID, uae_u64 offset, uae_u32 count, void *buf, uae_u32 *processedSize) { - struct zfile *f = arcacc_stack[StreamID]; - int ret; - - zfile_fseek (f, (long)offset, SEEK_SET); - ret = zfile_fread (buf, 1, count, f); - if (processedSize) - *processedSize = ret; - return 0; + struct zfile *f = arcacc_stack[StreamID]; + int ret; + + zfile_fseek (f, (long)offset, SEEK_SET); + ret = zfile_fread (buf, 1, count, f); + if (processedSize) + *processedSize = ret; + return 0; } static HRESULT __stdcall writeCallback (int StreamID, uae_u64 offset, uae_u32 count, const void *buf, uae_u32 *processedSize) { - struct zfile *f = arcacc_stack[StreamID]; - int ret; - - ret = zfile_fwrite ((void*)buf, 1, count, f); - if (processedSize) - *processedSize = ret; - if (ret != count) - return -1; - return 0; + struct zfile *f = arcacc_stack[StreamID]; + int ret; + + ret = zfile_fwrite ((void*)buf, 1, count, f); + if (processedSize) + *processedSize = ret; + if (ret != count) + return -1; + return 0; } struct zvolume *archive_directory_arcacc (struct zfile *z, unsigned int id) { - aaHandle ah; - int id_r, status; - int fc, f; - struct zvolume *zv; - int skipsize = 0; - - if (!arcacc_init (z)) - return NULL; - zv = zvolume_alloc (z, id, NULL, NULL); - id_r = arcacc_push (z); - ah = aaOpenArchive (readCallback, id_r, zv->archivesize, id, &status, NULL); - if (!status) { - zv->handle = ah; - fc = aaGetFileCount (ah); - for (f = 0; f < fc; f++) { - struct aaFileInArchiveInfo fi; - TCHAR *name; - struct znode *zn; - struct zarchive_info zai; - - memset (&fi, 0, sizeof (fi)); - aaGetFileInfo (ah, f, &fi); - if (fi.IsDir) - continue; - - name = au (fi.path); - memset (&zai, 0, sizeof zai); - zai.name = name; - zai.flags = -1; - zai.size = (unsigned int)fi.UncompressedFileSize; - zn = zvolume_addfile_abs (zv, &zai); - xfree (name); - zn->offset = f; - zn->method = id; - - if (id == ArchiveFormat7Zip) { - if (fi.CompressedFileSize) - skipsize = 0; - skipsize += (int)fi.UncompressedFileSize; - } + aaHandle ah; + int id_r, status; + int fc, f; + struct zvolume *zv; + int skipsize = 0; + + if (!arcacc_init (z)) + return NULL; + zv = zvolume_alloc (z, id, NULL, NULL); + id_r = arcacc_push (z); + ah = aaOpenArchive (readCallback, id_r, zv->archivesize, id, &status, NULL); + if (!status) { + zv->handle = ah; + fc = aaGetFileCount (ah); + for (f = 0; f < fc; f++) { + struct aaFileInArchiveInfo fi; + TCHAR *name; + struct znode *zn; + struct zarchive_info zai; + + memset (&fi, 0, sizeof (fi)); + aaGetFileInfo (ah, f, &fi); + if (fi.IsDir) + continue; + + name = au (fi.path); + memset (&zai, 0, sizeof zai); + zai.name = name; + zai.flags = -1; + zai.size = (unsigned int)fi.UncompressedFileSize; + zn = zvolume_addfile_abs (zv, &zai); + xfree (name); + zn->offset = f; + zn->method = id; + + if (id == ArchiveFormat7Zip) { + if (fi.CompressedFileSize) + skipsize = 0; + skipsize += (int)fi.UncompressedFileSize; + } + } + aaCloseArchive (ah); } - aaCloseArchive (ah); - } - arcacc_pop (); - zv->method = ArchiveFormatAA; - return zv; + arcacc_pop (); + zv->method = ArchiveFormatAA; + return zv; } struct zfile *archive_access_arcacc (struct znode *zn) { - struct zfile *zf; - struct zfile *z = zn->volume->archive; - int status, id_r, id_w; - aaHandle ah; - int ok = 0; - - id_r = arcacc_push (z); - ah = aaOpenArchive (readCallback, id_r, zn->volume->archivesize, zn->method, &status, NULL); - if (!status) { - int err; - uae_u64 written = 0; - struct aaFileInArchiveInfo fi; - memset (&fi, 0, sizeof (fi)); - aaGetFileInfo (ah, zn->offset, &fi); - zf = zfile_fopen_empty (z, zn->fullname, zn->size); - id_w = arcacc_push (zf); - err = aaExtract(ah, zn->offset, id_w, writeCallback, &written); - if (zf->seek == fi.UncompressedFileSize) - ok = 1; + struct zfile *zf; + struct zfile *z = zn->volume->archive; + int status, id_r, id_w; + aaHandle ah; + int ok = 0; + + id_r = arcacc_push (z); + ah = aaOpenArchive (readCallback, id_r, zn->volume->archivesize, zn->method, &status, NULL); + if (!status) { + int err; + uae_u64 written = 0; + struct aaFileInArchiveInfo fi; + memset (&fi, 0, sizeof (fi)); + aaGetFileInfo (ah, zn->offset, &fi); + zf = zfile_fopen_empty (z, zn->fullname, zn->size); + id_w = arcacc_push (zf); + err = aaExtract(ah, zn->offset, id_w, writeCallback, &written); + if (zf->seek == fi.UncompressedFileSize) + ok = 1; + arcacc_pop(); + } + aaCloseArchive(ah); arcacc_pop(); - } - aaCloseArchive(ah); - arcacc_pop(); - if (ok) - return zf; - zfile_fclose(zf); - return NULL; + if (ok) + return zf; + zfile_fclose(zf); + return NULL; } #endif @@ -861,144 +861,144 @@ struct zfile *archive_access_arcacc (struct znode *zn) static struct znode *addfile (struct zvolume *zv, struct zfile *zf, const TCHAR *path, uae_u8 *data, int size) { - struct zarchive_info zai; - struct znode *zn; - struct zfile *z; - - z = zfile_fopen_empty (zf, path, size); - zfile_fwrite (data, size, 1, z); - memset(&zai, 0, sizeof zai); - zai.name = path; - zai.flags = -1; - zai.size = size; - zn = zvolume_addfile_abs (zv, &zai); - if (zn) - zn->f = z; - else - zfile_fclose (z); - return zn; + struct zarchive_info zai; + struct znode *zn; + struct zfile *z; + + z = zfile_fopen_empty (zf, path, size); + zfile_fwrite (data, size, 1, z); + memset(&zai, 0, sizeof zai); + zai.name = path; + zai.flags = -1; + zai.size = size; + zn = zvolume_addfile_abs (zv, &zai); + if (zn) + zn->f = z; + else + zfile_fclose (z); + return zn; } static uae_u8 exeheader[]={0x00,0x00,0x03,0xf3,0x00,0x00,0x00,0x00}; struct zvolume *archive_directory_plain (struct zfile *z) { - struct zfile *zf, *zf2; - struct zvolume *zv; - struct znode *zn; - struct zarchive_info zai; - uae_u8 id[8]; - int rc; - - memset (&zai, 0, sizeof zai); - zv = zvolume_alloc (z, ArchiveFormatPLAIN, NULL, NULL); - memset(id, 0, sizeof id); - zai.name = zfile_getfilename (z); - zai.flags = -1; - zfile_fseek(z, 0, SEEK_END); - zai.size = zfile_ftell(z); - zfile_fseek(z, 0, SEEK_SET); - zfile_fread(id, sizeof id, 1, z); - zfile_fseek(z, 0, SEEK_SET); - zn = zvolume_addfile_abs (zv, &zai); - if (!memcmp (id, exeheader, sizeof id)) { - uae_u8 *data = xmalloc (1 + _tcslen (zai.name) + 1 + 2); - sprintf (data, "\"%s\"\n", zai.name); - zn = addfile (zv, z, L"s/startup-sequence", data, strlen (data)); - xfree (data); - } - zf = zfile_dup (z); - if (zf) { - zf2 = zuncompress (NULL, zf, 0, ZFD_ALL, &rc); - if (zf2) { - zf = NULL; - zai.name = zfile_getfilename (zf2); - zai.flags = -1; - zfile_fseek (zf2, 0, SEEK_END); - zai.size = zfile_ftell (zf2); - zfile_fseek (zf2, 0, SEEK_SET); - zn = zvolume_addfile_abs (zv, &zai); - if (zn) - zn->offset = 1; - zfile_fclose (zf2); + struct zfile *zf, *zf2; + struct zvolume *zv; + struct znode *zn; + struct zarchive_info zai; + uae_u8 id[8]; + int rc; + + memset (&zai, 0, sizeof zai); + zv = zvolume_alloc (z, ArchiveFormatPLAIN, NULL, NULL); + memset(id, 0, sizeof id); + zai.name = zfile_getfilename (z); + zai.flags = -1; + zfile_fseek(z, 0, SEEK_END); + zai.size = zfile_ftell(z); + zfile_fseek(z, 0, SEEK_SET); + zfile_fread(id, sizeof id, 1, z); + zfile_fseek(z, 0, SEEK_SET); + zn = zvolume_addfile_abs (zv, &zai); + if (!memcmp (id, exeheader, sizeof id)) { + uae_u8 *data = xmalloc (1 + _tcslen (zai.name) + 1 + 2); + sprintf (data, "\"%s\"\n", zai.name); + zn = addfile (zv, z, L"s/startup-sequence", data, strlen (data)); + xfree (data); + } + zf = zfile_dup (z); + if (zf) { + zf2 = zuncompress (NULL, zf, 0, ZFD_ALL, &rc); + if (zf2) { + zf = NULL; + zai.name = zfile_getfilename (zf2); + zai.flags = -1; + zfile_fseek (zf2, 0, SEEK_END); + zai.size = zfile_ftell (zf2); + zfile_fseek (zf2, 0, SEEK_SET); + zn = zvolume_addfile_abs (zv, &zai); + if (zn) + zn->offset = 1; + zfile_fclose (zf2); + } + zfile_fclose (zf); } - zfile_fclose (zf); - } - return zv; + return zv; } struct zfile *archive_access_plain (struct znode *zn) { - struct zfile *z; - - if (zn->offset) { - struct zfile *zf; - z = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); - zf = zfile_fopen (zfile_getname (zn->volume->archive), L"rb", zn->volume->archive->zfdmask & ~ZFD_ADF); - if (zf) { - zfile_fread (z->data, zn->size, 1, zf); - zfile_fclose (zf); - } - } else { - z = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); - if (z) { - zfile_fseek (zn->volume->archive, 0, SEEK_SET); - zfile_fread (z->data, zn->size, 1, zn->volume->archive); + struct zfile *z; + + if (zn->offset) { + struct zfile *zf; + z = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); + zf = zfile_fopen (zfile_getname (zn->volume->archive), L"rb", zn->volume->archive->zfdmask & ~ZFD_ADF); + if (zf) { + zfile_fread (z->data, zn->size, 1, zf); + zfile_fclose (zf); + } + } else { + z = zfile_fopen_empty (zn->volume->archive, zn->fullname, zn->size); + if (z) { + zfile_fseek (zn->volume->archive, 0, SEEK_SET); + zfile_fread (z->data, zn->size, 1, zn->volume->archive); + } } - } - return z; + return z; } struct adfhandle { - int size; - int highblock; - int blocksize; - int rootblock; - struct zfile *z; - uae_u8 block[65536]; - uae_u32 dostype; + int size; + int highblock; + int blocksize; + int rootblock; + struct zfile *z; + uae_u8 block[65536]; + uae_u32 dostype; }; static int dos_checksum (uae_u8 *p, int blocksize) { - uae_u32 cs = 0; - int i; - for (i = 0; i < blocksize; i += 4) - cs += (p[i] << 24) | (p[i + 1] << 16) | (p[i + 2] << 8) | (p[i + 3] << 0); - return cs; + uae_u32 cs = 0; + int i; + for (i = 0; i < blocksize; i += 4) + cs += (p[i] << 24) | (p[i + 1] << 16) | (p[i + 2] << 8) | (p[i + 3] << 0); + return cs; } static int sfs_checksum (uae_u8 *p, int blocksize, int sfs2) { - uae_u32 cs = sfs2 ? 2 : 1; - int i; - for (i = 0; i < blocksize; i += 4) - cs += (p[i] << 24) | (p[i + 1] << 16) | (p[i + 2] << 8) | (p[i + 3] << 0); - return cs; + uae_u32 cs = sfs2 ? 2 : 1; + int i; + for (i = 0; i < blocksize; i += 4) + cs += (p[i] << 24) | (p[i + 1] << 16) | (p[i + 2] << 8) | (p[i + 3] << 0); + return cs; } static TCHAR *getBSTR (uae_u8 *bstr) { - int n = *bstr++; - uae_char buf[257]; - int i; - - for (i = 0; i < n; i++) - buf[i] = *bstr++; - buf[i] = 0; - return au (buf); + int n = *bstr++; + uae_char buf[257]; + int i; + + for (i = 0; i < n; i++) + buf[i] = *bstr++; + buf[i] = 0; + return au (buf); } static uae_u32 gl (struct adfhandle *adf, int off) { - uae_u8 *p = adf->block + off; - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); + uae_u8 *p = adf->block + off; + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); } static uae_u32 glx (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); } static uae_u32 gwx (uae_u8 *p) { - return (p[0] << 8) | (p[1] << 0); + return (p[0] << 8) | (p[1] << 0); } static const int secs_per_day = 24 * 60 * 60; @@ -1006,666 +1006,666 @@ static const int diff = (8 * 365 + 2) * (24 * 60 * 60); static const int diff2 = (-8 * 365 - 2) * (24 * 60 * 60); static time_t put_time (long days, long mins, long ticks) { - time_t t; - - if (days < 0) - days = 0; - if (days > 9900 * 365) - days = 9900 * 365; // in future far enough? - if (mins < 0 || mins >= 24 * 60) - mins = 0; - if (ticks < 0 || ticks >= 60 * 50) - ticks = 0; - - t = ticks / 50; - t += mins * 60; - t += ((uae_u64)days) * secs_per_day; - t += diff; - - return t; + time_t t; + + if (days < 0) + days = 0; + if (days > 9900 * 365) + days = 9900 * 365; // in future far enough? + if (mins < 0 || mins >= 24 * 60) + mins = 0; + if (ticks < 0 || ticks >= 60 * 50) + ticks = 0; + + t = ticks / 50; + t += mins * 60; + t += ((uae_u64)days) * secs_per_day; + t += diff; + + return t; } static int adf_read_block (struct adfhandle *adf, int block) { - memset (adf->block, 0, adf->blocksize); - if (block >= adf->highblock || block < 0) - return 0; - zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); - zfile_fread (adf->block, adf->blocksize, 1, adf->z); - return 1; + memset (adf->block, 0, adf->blocksize); + if (block >= adf->highblock || block < 0) + return 0; + zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); + zfile_fread (adf->block, adf->blocksize, 1, adf->z); + return 1; } static void recurseadf (struct znode *zn, int root, TCHAR *name) { - int i; - struct zvolume *zv = zn->volume; - struct adfhandle *adf = zv->handle; - TCHAR name2[MAX_DPATH]; - int bs = adf->blocksize; + int i; + struct zvolume *zv = zn->volume; + struct adfhandle *adf = zv->handle; + TCHAR name2[MAX_DPATH]; + int bs = adf->blocksize; - for (i = 0; i < bs / 4 - 56; i++) { - int block; - if (!adf_read_block (adf, root)) - return; - block = gl (adf, (i + 6) * 4); - while (block > 0 && block < adf->size / bs) { - struct zarchive_info zai; - TCHAR *fname; - uae_u32 size, secondary; - - if (!adf_read_block (adf, block)) - return; - if (gl (adf, 0) != 2) - break; - if (gl (adf, 1 * 4) != block) - break; - secondary = gl (adf, bs - 1 * 4); - if (secondary != -3 && secondary != 2) - break; - memset (&zai, 0, sizeof zai); - fname = getBSTR (adf->block + bs - 20 * 4); - size = gl (adf, bs - 47 * 4); - name2[0] = 0; - if (name[0]) { - TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; - _tcscpy (name2, name); - _tcscat (name2, sep); - } - _tcscat (name2, fname); - zai.name = name2; - if (size < 0 || size > 0x7fffffff) - size = 0; - zai.size = size; - zai.flags = gl (adf, bs - 48 * 4); - zai.t = put_time (gl (adf, bs - 23 * 4), gl (adf, bs - 22 * 4),gl (adf, bs - 21 * 4)); - if (secondary == -3) { - struct znode *znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = block; - } else { - struct znode *znnew = zvolume_adddir_abs (zv, &zai); - znnew->offset = block; - recurseadf (znnew, block, name2); - if (!adf_read_block (adf, block)) - return; - } - xfree (fname); - block = gl (adf, bs - 4 * 4); + for (i = 0; i < bs / 4 - 56; i++) { + int block; + if (!adf_read_block (adf, root)) + return; + block = gl (adf, (i + 6) * 4); + while (block > 0 && block < adf->size / bs) { + struct zarchive_info zai; + TCHAR *fname; + uae_u32 size, secondary; + + if (!adf_read_block (adf, block)) + return; + if (gl (adf, 0) != 2) + break; + if (gl (adf, 1 * 4) != block) + break; + secondary = gl (adf, bs - 1 * 4); + if (secondary != -3 && secondary != 2) + break; + memset (&zai, 0, sizeof zai); + fname = getBSTR (adf->block + bs - 20 * 4); + size = gl (adf, bs - 47 * 4); + name2[0] = 0; + if (name[0]) { + TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; + _tcscpy (name2, name); + _tcscat (name2, sep); + } + _tcscat (name2, fname); + zai.name = name2; + if (size < 0 || size > 0x7fffffff) + size = 0; + zai.size = size; + zai.flags = gl (adf, bs - 48 * 4); + zai.t = put_time (gl (adf, bs - 23 * 4), gl (adf, bs - 22 * 4),gl (adf, bs - 21 * 4)); + if (secondary == -3) { + struct znode *znnew = zvolume_addfile_abs (zv, &zai); + znnew->offset = block; + } else { + struct znode *znnew = zvolume_adddir_abs (zv, &zai); + znnew->offset = block; + recurseadf (znnew, block, name2); + if (!adf_read_block (adf, block)) + return; + } + xfree (fname); + block = gl (adf, bs - 4 * 4); + } } - } } static void recursesfs (struct znode *zn, int root, TCHAR *name, int sfs2) { - struct zvolume *zv = zn->volume; - struct adfhandle *adf = zv->handle; - TCHAR name2[MAX_DPATH]; - int bs = adf->blocksize; - int block; - uae_u8 *p, *s; - struct zarchive_info zai; - - block = root; - while (block) { - if (!adf_read_block (adf, block)) - return; - p = adf->block + 12 + 3 * 4; - while (glx (p + 4) && p < adf->block + adf->blocksize - 27) { - TCHAR *fname; - int i; - int align; - - memset (&zai, 0, sizeof zai); - zai.flags = glx (p + 8) ^ 0x0f; - s = p + (sfs2 ? 27 : 25); - fname = au (s); - i = 0; - while (*s) { - s++; - i++; - } - s++; - i++; - if (*s) - zai.comment = au (s); - while (*s) { - s++; - i++; - } - s++; - i++; - i += sfs2 ? 27 : 25; - align = i & 1; - - name2[0] = 0; - if (name[0]) { - TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; - _tcscpy (name2, name); - _tcscat (name2, sep); - } - _tcscat (name2, fname); - zai.name = name2; - if (sfs2) - zai.t = glx (p + 22) - diff2; - else - zai.t = glx (p + 20) - diff; - if (p[sfs2 ? 26 : 24] & 0x80) { // dir - struct znode *znnew = zvolume_adddir_abs (zv, &zai); - int newblock = glx (p + 16); - if (newblock) { - znnew->offset = block; - recursesfs (znnew, newblock, name2, sfs2); - } + struct zvolume *zv = zn->volume; + struct adfhandle *adf = zv->handle; + TCHAR name2[MAX_DPATH]; + int bs = adf->blocksize; + int block; + uae_u8 *p, *s; + struct zarchive_info zai; + + block = root; + while (block) { if (!adf_read_block (adf, block)) - return; - } else { - struct znode *znnew; - if (sfs2) { - uae_u64 b1 = p[16]; - uae_u64 b2 = p[17]; - zai.size = (b1 << 40) | (b2 << 32) | glx (p + 18) ; - } else { - zai.size = glx (p + 16); + return; + p = adf->block + 12 + 3 * 4; + while (glx (p + 4) && p < adf->block + adf->blocksize - 27) { + TCHAR *fname; + int i; + int align; + + memset (&zai, 0, sizeof zai); + zai.flags = glx (p + 8) ^ 0x0f; + s = p + (sfs2 ? 27 : 25); + fname = au (s); + i = 0; + while (*s) { + s++; + i++; + } + s++; + i++; + if (*s) + zai.comment = au (s); + while (*s) { + s++; + i++; + } + s++; + i++; + i += sfs2 ? 27 : 25; + align = i & 1; + + name2[0] = 0; + if (name[0]) { + TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; + _tcscpy (name2, name); + _tcscat (name2, sep); + } + _tcscat (name2, fname); + zai.name = name2; + if (sfs2) + zai.t = glx (p + 22) - diff2; + else + zai.t = glx (p + 20) - diff; + if (p[sfs2 ? 26 : 24] & 0x80) { // dir + struct znode *znnew = zvolume_adddir_abs (zv, &zai); + int newblock = glx (p + 16); + if (newblock) { + znnew->offset = block; + recursesfs (znnew, newblock, name2, sfs2); + } + if (!adf_read_block (adf, block)) + return; + } else { + struct znode *znnew; + if (sfs2) { + uae_u64 b1 = p[16]; + uae_u64 b2 = p[17]; + zai.size = (b1 << 40) | (b2 << 32) | glx (p + 18) ; + } else { + zai.size = glx (p + 16); + } + znnew = zvolume_addfile_abs (zv, &zai); + znnew->offset = block; + znnew->offset2 = p - adf->block; + } + xfree (zai.comment); + xfree (fname); + p += i + align; } - znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = block; - znnew->offset2 = p - adf->block; - } - xfree (zai.comment); - xfree (fname); - p += i + align; + block = gl (adf, 12 + 4); } - block = gl (adf, 12 + 4); - } } struct zvolume *archive_directory_adf (struct znode *parent, struct zfile *z) { - struct zvolume *zv; - struct adfhandle *adf; - TCHAR *volname = NULL; - TCHAR name[MAX_DPATH]; - int gotroot = 0; - - adf = xcalloc (sizeof (struct adfhandle), 1); - zfile_fseek (z, 0, SEEK_END); - adf->size = zfile_ftell (z); - zfile_fseek (z, 0, SEEK_SET); - - adf->blocksize = 512; - if (parent && parent->offset2) { - if (parent->offset2 == 1024 || parent->offset2 == 2048 || parent->offset2 == 4096 || parent->offset2 == 8192 || - parent->offset2 == 16384 || parent->offset2 == 32768 || parent->offset2 == 65536) { - adf->blocksize = parent->offset2; - gotroot = 1; - } - } - - adf->highblock = adf->size / adf->blocksize; - adf->z = z; - - if (!adf_read_block (adf, 0)) - goto fail; - adf->dostype = gl (adf, 0); + struct zvolume *zv; + struct adfhandle *adf; + TCHAR *volname = NULL; + TCHAR name[MAX_DPATH]; + int gotroot = 0; + + adf = xcalloc (sizeof (struct adfhandle), 1); + zfile_fseek (z, 0, SEEK_END); + adf->size = zfile_ftell (z); + zfile_fseek (z, 0, SEEK_SET); - if ((adf->dostype & 0xffffff00) == 'DOS\0') { - int bs = adf->blocksize; - int res; - - adf->rootblock = ((adf->size / bs) - 1 + 2) / 2; - if (!gotroot) { - for (res = 2; res >= 1; res--) { - for (bs = 512; bs < 65536; bs <<= 1) { - adf->blocksize = bs; - adf->rootblock = ((adf->size / bs) - 1 + res) / 2; - if (!adf_read_block (adf, adf->rootblock)) - continue; - if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) - continue; - if (dos_checksum (adf->block, bs) != 0) - continue; - gotroot = 1; - break; + adf->blocksize = 512; + if (parent && parent->offset2) { + if (parent->offset2 == 1024 || parent->offset2 == 2048 || parent->offset2 == 4096 || parent->offset2 == 8192 || + parent->offset2 == 16384 || parent->offset2 == 32768 || parent->offset2 == 65536) { + adf->blocksize = parent->offset2; + gotroot = 1; } - if (gotroot) - break; - } - } - if (!gotroot) { - bs = adf->blocksize = 512; - if (adf->size < 2000000 && adf->rootblock != 880) { - adf->rootblock = 880; - if (!adf_read_block (adf, adf->rootblock)) - goto fail; - if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) - goto fail; - if (dos_checksum (adf->block, bs) != 0) - goto fail; - } } - if (!adf_read_block (adf, adf->rootblock)) - goto fail; - if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) - goto fail; - if (dos_checksum (adf->block, adf->blocksize) != 0) - goto fail; - adf->blocksize = bs; - adf->highblock = adf->size / adf->blocksize; - volname = getBSTR (adf->block + adf->blocksize - 20 * 4); - zv = zvolume_alloc (z, ArchiveFormatADF, NULL, NULL); - zv->method = ArchiveFormatADF; - zv->handle = adf; - - name[0] = 0; - recurseadf (&zv->root, adf->rootblock, name); - - } else if ((adf->dostype & 0xffffff00) == 'SFS\0') { - - uae_u16 version, sfs2; + adf->highblock = adf->size / adf->blocksize; + adf->z = z; + + if (!adf_read_block (adf, 0)) + goto fail; + adf->dostype = gl (adf, 0); + + if ((adf->dostype & 0xffffff00) == 'DOS\0') { + int bs = adf->blocksize; + int res; + + adf->rootblock = ((adf->size / bs) - 1 + 2) / 2; + if (!gotroot) { + for (res = 2; res >= 1; res--) { + for (bs = 512; bs < 65536; bs <<= 1) { + adf->blocksize = bs; + adf->rootblock = ((adf->size / bs) - 1 + res) / 2; + if (!adf_read_block (adf, adf->rootblock)) + continue; + if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) + continue; + if (dos_checksum (adf->block, bs) != 0) + continue; + gotroot = 1; + break; + } + if (gotroot) + break; + } + } + if (!gotroot) { + bs = adf->blocksize = 512; + if (adf->size < 2000000 && adf->rootblock != 880) { + adf->rootblock = 880; + if (!adf_read_block (adf, adf->rootblock)) + goto fail; + if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) + goto fail; + if (dos_checksum (adf->block, bs) != 0) + goto fail; + } + } - for (;;) { - for (;;) { - version = gl (adf, 12) >> 16; - sfs2 = version > 3; - if (version > 4) - break; - adf->rootblock = gl (adf, 104); - if (!adf_read_block (adf, adf->rootblock)) - break; - if (gl (adf, 0) != 'OBJC') - break; - if (sfs_checksum (adf->block, adf->blocksize, sfs2)) - break; - adf->rootblock = gl (adf, 40); if (!adf_read_block (adf, adf->rootblock)) - break; - if (gl (adf, 0) != 'OBJC') - break; - if (sfs_checksum (adf->block, adf->blocksize, sfs2)) - break; - gotroot = 1; - break; - } - if (gotroot) - break; - adf->blocksize <<= 1; - if (adf->blocksize == 65536) - break; - } - if (!gotroot) - goto fail; + goto fail; + if (gl (adf, 0) != 2 || gl (adf, bs - 1 * 4) != 1) + goto fail; + if (dos_checksum (adf->block, adf->blocksize) != 0) + goto fail; + adf->blocksize = bs; + adf->highblock = adf->size / adf->blocksize; + volname = getBSTR (adf->block + adf->blocksize - 20 * 4); + zv = zvolume_alloc (z, ArchiveFormatADF, NULL, NULL); + zv->method = ArchiveFormatADF; + zv->handle = adf; + + name[0] = 0; + recurseadf (&zv->root, adf->rootblock, name); + + } else if ((adf->dostype & 0xffffff00) == 'SFS\0') { + + uae_u16 version, sfs2; + + for (;;) { + for (;;) { + version = gl (adf, 12) >> 16; + sfs2 = version > 3; + if (version > 4) + break; + adf->rootblock = gl (adf, 104); + if (!adf_read_block (adf, adf->rootblock)) + break; + if (gl (adf, 0) != 'OBJC') + break; + if (sfs_checksum (adf->block, adf->blocksize, sfs2)) + break; + adf->rootblock = gl (adf, 40); + if (!adf_read_block (adf, adf->rootblock)) + break; + if (gl (adf, 0) != 'OBJC') + break; + if (sfs_checksum (adf->block, adf->blocksize, sfs2)) + break; + gotroot = 1; + break; + } + if (gotroot) + break; + adf->blocksize <<= 1; + if (adf->blocksize == 65536) + break; + } + if (!gotroot) + goto fail; - zv = zvolume_alloc (z, ArchiveFormatADF, NULL, NULL); - zv->method = ArchiveFormatADF; - zv->handle = adf; + zv = zvolume_alloc (z, ArchiveFormatADF, NULL, NULL); + zv->method = ArchiveFormatADF; + zv->handle = adf; - name[0] = 0; - recursesfs (&zv->root, adf->rootblock, name, version > 3); + name[0] = 0; + recursesfs (&zv->root, adf->rootblock, name, version > 3); - } else { - goto fail; - } + } else { + goto fail; + } - xfree (volname); - return zv; + xfree (volname); + return zv; fail: - xfree (adf); - return NULL; + xfree (adf); + return NULL; } struct sfsblock { - int block; - int length; + int block; + int length; }; static int sfsfindblock (struct adfhandle *adf, int btree, int theblock, struct sfsblock **sfsb, int *sfsblockcnt, int *sfsmaxblockcnt, int sfs2) { - int nodecount, isleaf, nodesize; - int i; - uae_u8 *p; + int nodecount, isleaf, nodesize; + int i; + uae_u8 *p; - if (!btree) - return 0; - if (!adf_read_block (adf, btree)) - return 0; - if (memcmp (adf->block, "BNDC", 4)) - return 0; - nodecount = gwx (adf->block + 12); - isleaf = adf->block[14]; - nodesize = adf->block[15]; - p = adf->block + 16; - for (i = 0; i < nodecount; i++) { - if (isleaf) { - uae_u32 key = glx (p); - uae_u32 next = glx (p + 4); - uae_u32 prev = glx (p + 8); - uae_u32 blocks; - if (sfs2) - blocks = glx (p + 12); - else - blocks = gwx (p + 12); - if (key == theblock) { - struct sfsblock *sb; - if (*sfsblockcnt >= *sfsmaxblockcnt) { - *sfsmaxblockcnt += 100; - *sfsb = realloc (*sfsb, (*sfsmaxblockcnt) * sizeof (struct sfsblock)); - } - sb = *sfsb + (*sfsblockcnt); - sb->block = key; - sb->length = blocks; - (*sfsblockcnt)++; - return next; - } - } else { - uae_u32 key = glx (p); - uae_u32 data = glx (p + 4); - int newblock = sfsfindblock (adf, data, theblock, sfsb, sfsblockcnt, sfsmaxblockcnt, sfs2); - if (newblock) - return newblock; - if (!adf_read_block (adf, btree)) + if (!btree) + return 0; + if (!adf_read_block (adf, btree)) return 0; - if (memcmp (adf->block, "BNDC", 4)) + if (memcmp (adf->block, "BNDC", 4)) return 0; + nodecount = gwx (adf->block + 12); + isleaf = adf->block[14]; + nodesize = adf->block[15]; + p = adf->block + 16; + for (i = 0; i < nodecount; i++) { + if (isleaf) { + uae_u32 key = glx (p); + uae_u32 next = glx (p + 4); + uae_u32 prev = glx (p + 8); + uae_u32 blocks; + if (sfs2) + blocks = glx (p + 12); + else + blocks = gwx (p + 12); + if (key == theblock) { + struct sfsblock *sb; + if (*sfsblockcnt >= *sfsmaxblockcnt) { + *sfsmaxblockcnt += 100; + *sfsb = realloc (*sfsb, (*sfsmaxblockcnt) * sizeof (struct sfsblock)); + } + sb = *sfsb + (*sfsblockcnt); + sb->block = key; + sb->length = blocks; + (*sfsblockcnt)++; + return next; + } + } else { + uae_u32 key = glx (p); + uae_u32 data = glx (p + 4); + int newblock = sfsfindblock (adf, data, theblock, sfsb, sfsblockcnt, sfsmaxblockcnt, sfs2); + if (newblock) + return newblock; + if (!adf_read_block (adf, btree)) + return 0; + if (memcmp (adf->block, "BNDC", 4)) + return 0; + } + p += nodesize; } - p += nodesize; - } - return 0; + return 0; } struct zfile *archive_access_adf (struct znode *zn) { - struct zfile *z = NULL; - int root, ffs; - struct adfhandle *adf = zn->volume->handle; - int size, bs; - int i; - uae_u8 *dst; - - size = zn->size; - bs = adf->blocksize; - z = zfile_fopen_empty (zn->volume->archive, zn->fullname, size); - if (!z) - return NULL; + struct zfile *z = NULL; + int root, ffs; + struct adfhandle *adf = zn->volume->handle; + int size, bs; + int i; + uae_u8 *dst; - if ((adf->dostype & 0xffffff00) == 'DOS\0') { + size = zn->size; + bs = adf->blocksize; + z = zfile_fopen_empty (zn->volume->archive, zn->fullname, size); + if (!z) + return NULL; + + if ((adf->dostype & 0xffffff00) == 'DOS\0') { + + ffs = adf->dostype & 1; + root = zn->offset; + dst = z->data; + for (;;) { + adf_read_block (adf, root); + for (i = bs / 4 - 51; i >= 6; i--) { + int bsize = ffs ? bs : bs - 24; + int block = gl (adf, i * 4); + if (size < bsize) + bsize = size; + if (ffs) + zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); + else + zfile_fseek (adf->z, block * adf->blocksize + 24, SEEK_SET); + zfile_fread (dst, bsize, 1, adf->z); + size -= bsize; + dst += bsize; + if (size <= 0) + break; + } + if (size <= 0) + break; + root = gl (adf, bs - 2 * 4); + } + } else if ((adf->dostype & 0xffffff00) == 'SFS\0') { + + struct sfsblock *sfsblocks; + int sfsblockcnt, sfsmaxblockcnt, i; + int bsize; + int block = zn->offset; + int dblock; + int btree, version, sfs2; + uae_u8 *p; + + if (!adf_read_block (adf, 0)) + goto end; + btree = glx (adf->block + 108); + version = gwx (adf->block + 12); + sfs2 = version > 3; - ffs = adf->dostype & 1; - root = zn->offset; - dst = z->data; - for (;;) { - adf_read_block (adf, root); - for (i = bs / 4 - 51; i >= 6; i--) { - int bsize = ffs ? bs : bs - 24; - int block = gl (adf, i * 4); - if (size < bsize) - bsize = size; - if (ffs) - zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); - else - zfile_fseek (adf->z, block * adf->blocksize + 24, SEEK_SET); - zfile_fread (dst, bsize, 1, adf->z); - size -= bsize; - dst += bsize; - if (size <= 0) - break; - } - if (size <= 0) - break; - root = gl (adf, bs - 2 * 4); - } - } else if ((adf->dostype & 0xffffff00) == 'SFS\0') { - - struct sfsblock *sfsblocks; - int sfsblockcnt, sfsmaxblockcnt, i; - int bsize; - int block = zn->offset; - int dblock; - int btree, version, sfs2; - uae_u8 *p; + if (!adf_read_block (adf, block)) + goto end; + p = adf->block + zn->offset2; + dblock = glx (p + 12); + + sfsblockcnt = 0; + sfsmaxblockcnt = 0; + sfsblocks = NULL; + if (size > 0) { + int nextblock = dblock; + while (nextblock) { + nextblock = sfsfindblock (adf, btree, nextblock, &sfsblocks, &sfsblockcnt, &sfsmaxblockcnt, sfs2); + } + } - if (!adf_read_block (adf, 0)) - goto end; - btree = glx (adf->block + 108); - version = gwx (adf->block + 12); - sfs2 = version > 3; - - if (!adf_read_block (adf, block)) - goto end; - p = adf->block + zn->offset2; - dblock = glx (p + 12); - - sfsblockcnt = 0; - sfsmaxblockcnt = 0; - sfsblocks = NULL; - if (size > 0) { - int nextblock = dblock; - while (nextblock) { - nextblock = sfsfindblock (adf, btree, nextblock, &sfsblocks, &sfsblockcnt, &sfsmaxblockcnt, sfs2); - } - } + bsize = 0; + for (i = 0; i < sfsblockcnt; i++) + bsize += sfsblocks[i].length * adf->blocksize; + if (bsize < size) + write_log (L"SFS extracting error, %s size mismatch %d<%d\n", z->name, bsize, size); + + dst = z->data; + block = zn->offset; + for (i = 0; i < sfsblockcnt; i++) { + block = sfsblocks[i].block; + bsize = sfsblocks[i].length * adf->blocksize; + zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); + if (bsize > size) + bsize = size; + zfile_fread (dst, bsize, 1, adf->z); + dst += bsize; + size -= bsize; + } - bsize = 0; - for (i = 0; i < sfsblockcnt; i++) - bsize += sfsblocks[i].length * adf->blocksize; - if (bsize < size) - write_log (L"SFS extracting error, %s size mismatch %d<%d\n", z->name, bsize, size); - - dst = z->data; - block = zn->offset; - for (i = 0; i < sfsblockcnt; i++) { - block = sfsblocks[i].block; - bsize = sfsblocks[i].length * adf->blocksize; - zfile_fseek (adf->z, block * adf->blocksize, SEEK_SET); - if (bsize > size) - bsize = size; - zfile_fread (dst, bsize, 1, adf->z); - dst += bsize; - size -= bsize; + xfree (sfsblocks); } - - xfree (sfsblocks); - } - return z; + return z; end: - zfile_fclose (z); - return NULL; + zfile_fclose (z); + return NULL; } static void archive_close_adf (void *v) { - struct adfhandle *adf = v; - xfree (adf); + struct adfhandle *adf = v; + xfree (adf); } static int rl (uae_u8 *p) { - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); + return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]); } static TCHAR *tochar (uae_u8 *s, int len) { - int i, j; - uae_char tmp[256]; - j = 0; - for (i = 0; i < len; i++) { - uae_char c = *s++; - if (c >= 0 && c <= 9) { - tmp[j++] = '\\'; - tmp[j++] = '0' + c; - } else if (c < ' ' || c > 'z') { - tmp[j++] = '.'; - } else { - tmp[j++] = c; + int i, j; + uae_char tmp[256]; + j = 0; + for (i = 0; i < len; i++) { + uae_char c = *s++; + if (c >= 0 && c <= 9) { + tmp[j++] = '\\'; + tmp[j++] = '0' + c; + } else if (c < ' ' || c > 'z') { + tmp[j++] = '.'; + } else { + tmp[j++] = c; + } + tmp[j] = 0; } - tmp[j] = 0; - } - return au (tmp); + return au (tmp); } struct zvolume *archive_directory_rdb (struct zfile *z) { - uae_u8 buf[512] = { 0 }; - int partnum, bs; - TCHAR *devname; - struct zvolume *zv; - struct zarchive_info zai; - uae_u8 *p; - struct znode *zn; - - zv = zvolume_alloc (z, ArchiveFormatRDB, NULL, NULL); - - zfile_fseek (z, 0, SEEK_SET); - zfile_fread (buf, 1, 512, z); - - partnum = 0; - for (;;) { - int partblock; - TCHAR tmp[MAX_DPATH]; - int surf, spt, spb, lowcyl, highcyl, reserved; - int size, block, blocksize, rootblock; - TCHAR comment[81], *dos; + uae_u8 buf[512] = { 0 }; + int partnum, bs; + TCHAR *devname; + struct zvolume *zv; + struct zarchive_info zai; + uae_u8 *p; + struct znode *zn; - if (partnum == 0) - partblock = rl (buf + 28); - else - partblock = rl (buf + 4 * 4); - partnum++; - if (partblock <= 0) - break; - zfile_fseek (z, partblock * 512, SEEK_SET); + zv = zvolume_alloc (z, ArchiveFormatRDB, NULL, NULL); + + zfile_fseek (z, 0, SEEK_SET); zfile_fread (buf, 1, 512, z); - if (memcmp (buf, "PART", 4)) - break; - - p = buf + 128 - 16; - surf = rl (p + 28); - spb = rl (p + 32); - spt = rl (p + 36); - reserved = rl (p + 40); - lowcyl = rl (p + 52); - highcyl = rl (p + 56); - blocksize = rl (p + 20) * 4 * spb; - block = lowcyl * surf * spt; - - size = (highcyl - lowcyl + 1) * surf * spt; - size *= blocksize; - - dos = tochar (buf + 192, 4); - - if (!memcmp (dos, L"DOS", 3)) - rootblock = ((size / blocksize) - 1 + 2) / 2; - else - rootblock = 0; - devname = getBSTR (buf + 36); - _stprintf (tmp, L"%s.hdf", devname); - memset (&zai, 0, sizeof zai); - _stprintf (comment, L"FS=%s LO=%d HI=%d HEADS=%d SPT=%d RES=%d BLOCK=%d ROOT=%d", - dos, lowcyl, highcyl, surf, spt, reserved, blocksize, rootblock); - zai.comment = comment; - xfree (dos); - zai.name = tmp; - zai.size = size; - zai.flags = -1; + partnum = 0; + for (;;) { + int partblock; + TCHAR tmp[MAX_DPATH]; + int surf, spt, spb, lowcyl, highcyl, reserved; + int size, block, blocksize, rootblock; + TCHAR comment[81], *dos; + + if (partnum == 0) + partblock = rl (buf + 28); + else + partblock = rl (buf + 4 * 4); + partnum++; + if (partblock <= 0) + break; + zfile_fseek (z, partblock * 512, SEEK_SET); + zfile_fread (buf, 1, 512, z); + if (memcmp (buf, "PART", 4)) + break; + + p = buf + 128 - 16; + surf = rl (p + 28); + spb = rl (p + 32); + spt = rl (p + 36); + reserved = rl (p + 40); + lowcyl = rl (p + 52); + highcyl = rl (p + 56); + blocksize = rl (p + 20) * 4 * spb; + block = lowcyl * surf * spt; + + size = (highcyl - lowcyl + 1) * surf * spt; + size *= blocksize; + + dos = tochar (buf + 192, 4); + + if (!memcmp (dos, L"DOS", 3)) + rootblock = ((size / blocksize) - 1 + 2) / 2; + else + rootblock = 0; + + devname = getBSTR (buf + 36); + _stprintf (tmp, L"%s.hdf", devname); + memset (&zai, 0, sizeof zai); + _stprintf (comment, L"FS=%s LO=%d HI=%d HEADS=%d SPT=%d RES=%d BLOCK=%d ROOT=%d", + dos, lowcyl, highcyl, surf, spt, reserved, blocksize, rootblock); + zai.comment = comment; + xfree (dos); + zai.name = tmp; + zai.size = size; + zai.flags = -1; + zn = zvolume_addfile_abs (zv, &zai); + zn->offset = partblock; + zn->offset2 = blocksize; // örp? + } + + zfile_fseek (z, 0, SEEK_SET); + p = buf; + zfile_fread (buf, 1, 512, z); + zai.name = L"rdb_dump.dat"; + bs = rl (p + 16); + zai.size = rl (p + 140) * bs; + zai.comment = NULL; zn = zvolume_addfile_abs (zv, &zai); - zn->offset = partblock; - zn->offset2 = blocksize; // örp? - } - - zfile_fseek (z, 0, SEEK_SET); - p = buf; - zfile_fread (buf, 1, 512, z); - zai.name = L"rdb_dump.dat"; - bs = rl (p + 16); - zai.size = rl (p + 140) * bs; - zai.comment = NULL; - zn = zvolume_addfile_abs (zv, &zai); - zn->offset = 0; - - zv->method = ArchiveFormatRDB; - return zv; + zn->offset = 0; + + zv->method = ArchiveFormatRDB; + return zv; } struct zfile *archive_access_rdb (struct znode *zn) { - struct zfile *z = zn->volume->archive; - struct zfile *zf; - uae_u8 buf[512] = { 0 }; - int surf, spb, spt, lowcyl, highcyl; - int size, block, blocksize; - uae_u8 *p; - - if (zn->offset) { - zfile_fseek (z, zn->offset * 512, SEEK_SET); - zfile_fread (buf, 1, 512, z); - - p = buf + 128 - 16; - surf = rl (p + 28); - spb = rl (p + 32); - spt = rl (p + 36); - lowcyl = rl (p + 52); - highcyl = rl (p + 56); - blocksize = rl (p + 20) * 4; - block = lowcyl * surf * spt; - - size = (highcyl - lowcyl + 1) * surf * spt; - size *= blocksize; - } else { - zfile_fseek (z, 0, SEEK_SET); - zfile_fread (buf, 1, 512, z); - p = buf; - blocksize = rl (p + 16); - block = 0; - size = zn->size; - } + struct zfile *z = zn->volume->archive; + struct zfile *zf; + uae_u8 buf[512] = { 0 }; + int surf, spb, spt, lowcyl, highcyl; + int size, block, blocksize; + uae_u8 *p; + + if (zn->offset) { + zfile_fseek (z, zn->offset * 512, SEEK_SET); + zfile_fread (buf, 1, 512, z); + + p = buf + 128 - 16; + surf = rl (p + 28); + spb = rl (p + 32); + spt = rl (p + 36); + lowcyl = rl (p + 52); + highcyl = rl (p + 56); + blocksize = rl (p + 20) * 4; + block = lowcyl * surf * spt; + + size = (highcyl - lowcyl + 1) * surf * spt; + size *= blocksize; + } else { + zfile_fseek (z, 0, SEEK_SET); + zfile_fread (buf, 1, 512, z); + p = buf; + blocksize = rl (p + 16); + block = 0; + size = zn->size; + } - zf = zfile_fopen_parent (z, zn->fullname, block * blocksize, size); - return zf; + zf = zfile_fopen_parent (z, zn->fullname, block * blocksize, size); + return zf; } int isfat (uae_u8 *p) { - int i, b; + int i, b; - if ((p[0x15] & 0xf0) != 0xf0) - return 0; - if (p[0x0b] != 0x00 || p[0x0c] != 0x02) - return 0; - b = 0; - for (i = 0; i < 8; i++) { - if (p[0x0d] & (1 << i)) - b++; - } - if (b != 1) - return 0; - if (p[0x0f] != 0) - return 0; - if (p[0x0e] > 8 || p[0x0e] == 0) - return 0; - if (p[0x10] == 0 || p[0x10] > 8) - return 0; - b = (p[0x12] << 8) | p[0x11]; - if (b > 8192 || b <= 0) - return 0; - b = p[0x16] | (p[0x17] << 8); - if (b == 0 || b > 8192) - return 0; - return 1; + if ((p[0x15] & 0xf0) != 0xf0) + return 0; + if (p[0x0b] != 0x00 || p[0x0c] != 0x02) + return 0; + b = 0; + for (i = 0; i < 8; i++) { + if (p[0x0d] & (1 << i)) + b++; + } + if (b != 1) + return 0; + if (p[0x0f] != 0) + return 0; + if (p[0x0e] > 8 || p[0x0e] == 0) + return 0; + if (p[0x10] == 0 || p[0x10] > 8) + return 0; + b = (p[0x12] << 8) | p[0x11]; + if (b > 8192 || b <= 0) + return 0; + b = p[0x16] | (p[0x17] << 8); + if (b == 0 || b > 8192) + return 0; + return 1; } /* - * The epoch of FAT timestamp is 1980. - * : bits : value - * date: 0 - 4: day (1 - 31) - * date: 5 - 8: month (1 - 12) - * date: 9 - 15: year (0 - 127) from 1980 - * time: 0 - 4: sec (0 - 29) 2sec counts - * time: 5 - 10: min (0 - 59) - * time: 11 - 15: hour (0 - 23) - */ +* The epoch of FAT timestamp is 1980. +* : bits : value +* date: 0 - 4: day (1 - 31) +* date: 5 - 8: month (1 - 12) +* date: 9 - 15: year (0 - 127) from 1980 +* time: 0 - 4: sec (0 - 29) 2sec counts +* time: 5 - 10: min (0 - 59) +* time: 11 - 15: hour (0 - 23) +*/ #define SECS_PER_MIN 60 #define SECS_PER_HOUR (60 * 60) #define SECS_PER_DAY (SECS_PER_HOUR * 24) @@ -1681,247 +1681,247 @@ int isfat (uae_u8 *p) /* Linear day numbers of the respective 1sts in non-leap years. */ static time_t days_in_year[] = { - /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */ - 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, + /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */ + 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, }; /* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */ static time_t fat_time_fat2unix (uae_u16 time, uae_u16 date, int fat12) { - time_t second, day, leap_day, month, year; - - if (0 && fat12) { - year = date & 0x7f; - month = (date >> 7) & 0x0f; - day = (date >> 11); - } else { - year = date >> 9; - month = max(1, (date >> 5) & 0xf); - day = max(1, date & 0x1f) - 1; - } - - leap_day = (year + 3) / 4; - if (year > YEAR_2100) /* 2100 isn't leap year */ - leap_day--; - if (IS_LEAP_YEAR(year) && month > 2) - leap_day++; - - second = (time & 0x1f) << 1; - second += ((time >> 5) & 0x3f) * SECS_PER_MIN; - second += (time >> 11) * SECS_PER_HOUR; - second += (year * 365 + leap_day - + days_in_year[month] + day - + DAYS_DELTA) * SECS_PER_DAY; - return second; + time_t second, day, leap_day, month, year; + + if (0 && fat12) { + year = date & 0x7f; + month = (date >> 7) & 0x0f; + day = (date >> 11); + } else { + year = date >> 9; + month = max(1, (date >> 5) & 0xf); + day = max(1, date & 0x1f) - 1; + } + + leap_day = (year + 3) / 4; + if (year > YEAR_2100) /* 2100 isn't leap year */ + leap_day--; + if (IS_LEAP_YEAR(year) && month > 2) + leap_day++; + + second = (time & 0x1f) << 1; + second += ((time >> 5) & 0x3f) * SECS_PER_MIN; + second += (time >> 11) * SECS_PER_HOUR; + second += (year * 365 + leap_day + + days_in_year[month] + day + + DAYS_DELTA) * SECS_PER_DAY; + return second; } static int getcluster (struct zfile *z, int cluster, int fatstart, int fatbits) { - uae_u32 fat = 0; - uae_u8 p[4]; - int offset = cluster * fatbits; - zfile_fseek (z, fatstart * 512 + offset / 8, SEEK_SET); - if (fatbits == 12) { - zfile_fread (p, 2, 1, z); - if ((offset & 4)) - fat = ((p[0] & 0xf0) >> 4) | (p[1] << 4); - else - fat = (p[0]) | ((p[1] & 0x0f) << 8); - if (fat >= 0xff0) - return -1; - } else if (fatbits == 16) { - zfile_fread (p, 2, 1, z); - fat = p[0] | (p[1] << 8); - if (fat >= 0xfff0) - return -1; - } else if (fatbits == 32) { - zfile_fread (p, 4, 1, z); - fat = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); - fat &= ~0x0fffffff; - if (fat >= 0x0ffffff0) - return -1; - } - return fat; + uae_u32 fat = 0; + uae_u8 p[4]; + int offset = cluster * fatbits; + zfile_fseek (z, fatstart * 512 + offset / 8, SEEK_SET); + if (fatbits == 12) { + zfile_fread (p, 2, 1, z); + if ((offset & 4)) + fat = ((p[0] & 0xf0) >> 4) | (p[1] << 4); + else + fat = (p[0]) | ((p[1] & 0x0f) << 8); + if (fat >= 0xff0) + return -1; + } else if (fatbits == 16) { + zfile_fread (p, 2, 1, z); + fat = p[0] | (p[1] << 8); + if (fat >= 0xfff0) + return -1; + } else if (fatbits == 32) { + zfile_fread (p, 4, 1, z); + fat = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); + fat &= ~0x0fffffff; + if (fat >= 0x0ffffff0) + return -1; + } + return fat; } static void fatdirectory (struct zfile *z, struct zvolume *zv, TCHAR *name, int startblock, int entries, int sectorspercluster, int fatstart, int dataregion, int fatbits) { - struct zarchive_info zai; - struct znode *znnew; - int i, j; - - for (i = 0; i < entries; i++) { - TCHAR name2[MAX_DPATH], *fname; - uae_s64 size; - uae_u8 fatname[16]; - uae_u8 buf[32]; - int attr, cnt, ext; - int startcluster; - - memset (buf, 0, sizeof buf); - memset (&zai, 0, sizeof zai); - zfile_fseek (z, startblock * 512 + i * 32, SEEK_SET); - zfile_fread (buf, 32, 1, z); - if (buf[0] == 0) - break; - if (buf[0] == 0xe5) - continue; - if (buf[0] == 0x05) - buf[0] = 0xe5; - size = buf[0x1c] | (buf[0x1d] << 8) | (buf[0x1e] << 16) | (buf[0x1f] << 24); - attr = buf[0x0b]; - startcluster = buf[0x1a] | (buf[0x1b] << 8); - if ((attr & (0x4 | 0x2)) == 0x06) // system+hidden - continue; - if (attr & 8) // disk name - continue; - if (attr & 1) // read-only - zai.flags |= 1 << 3; - if (!(attr & 32)) // archive - zai.flags |= 1 << 4; - - cnt = 0; - ext = 0; - for (j = 0; j < 8 && buf[j] != 0x20 && buf[j] != 0; j++) - fatname[cnt++] = buf[j]; - for (j = 0; j < 3 && buf[8 + j] != 0x20 && buf[8 + j] != 0; j++) { - if (ext == 0) - fatname[cnt++] = '.'; - ext = 1; - fatname[cnt++] = buf[8 + j]; - } - fatname[cnt] = 0; - - fname = au (fatname); - name2[0] = 0; - if (name[0]) { - TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; - _tcscpy (name2, name); - _tcscat (name2, sep); - } - _tcscat (name2, fname); - - zai.name = name2; - zai.t = fat_time_fat2unix (buf[0x16] | (buf[0x17] << 8), buf[0x18] | (buf[0x19] << 8), 1); - if (attr & (16 | 8)) { - int nextblock, cluster; - nextblock = dataregion + (startcluster - 2) * sectorspercluster; - cluster = getcluster (z, startcluster, fatstart, fatbits); - if ((cluster < 0 || cluster >= 3) && nextblock != startblock) { - znnew = zvolume_adddir_abs (zv, &zai); - fatdirectory (z, zv, name2, nextblock, sectorspercluster * 512 / 32, sectorspercluster, fatstart, dataregion, fatbits); - while (cluster >= 3) { - nextblock = dataregion + (cluster - 2) * sectorspercluster; - fatdirectory (z, zv, name2, nextblock, sectorspercluster * 512 / 32, sectorspercluster, fatstart, dataregion, fatbits); - cluster = getcluster (z, cluster, fatstart, fatbits); + struct zarchive_info zai; + struct znode *znnew; + int i, j; + + for (i = 0; i < entries; i++) { + TCHAR name2[MAX_DPATH], *fname; + uae_s64 size; + uae_u8 fatname[16]; + uae_u8 buf[32]; + int attr, cnt, ext; + int startcluster; + + memset (buf, 0, sizeof buf); + memset (&zai, 0, sizeof zai); + zfile_fseek (z, startblock * 512 + i * 32, SEEK_SET); + zfile_fread (buf, 32, 1, z); + if (buf[0] == 0) + break; + if (buf[0] == 0xe5) + continue; + if (buf[0] == 0x05) + buf[0] = 0xe5; + size = buf[0x1c] | (buf[0x1d] << 8) | (buf[0x1e] << 16) | (buf[0x1f] << 24); + attr = buf[0x0b]; + startcluster = buf[0x1a] | (buf[0x1b] << 8); + if ((attr & (0x4 | 0x2)) == 0x06) // system+hidden + continue; + if (attr & 8) // disk name + continue; + if (attr & 1) // read-only + zai.flags |= 1 << 3; + if (!(attr & 32)) // archive + zai.flags |= 1 << 4; + + cnt = 0; + ext = 0; + for (j = 0; j < 8 && buf[j] != 0x20 && buf[j] != 0; j++) + fatname[cnt++] = buf[j]; + for (j = 0; j < 3 && buf[8 + j] != 0x20 && buf[8 + j] != 0; j++) { + if (ext == 0) + fatname[cnt++] = '.'; + ext = 1; + fatname[cnt++] = buf[8 + j]; + } + fatname[cnt] = 0; + + fname = au (fatname); + name2[0] = 0; + if (name[0]) { + TCHAR sep[] = { FSDB_DIR_SEPARATOR, 0 }; + _tcscpy (name2, name); + _tcscat (name2, sep); + } + _tcscat (name2, fname); + + zai.name = name2; + zai.t = fat_time_fat2unix (buf[0x16] | (buf[0x17] << 8), buf[0x18] | (buf[0x19] << 8), 1); + if (attr & (16 | 8)) { + int nextblock, cluster; + nextblock = dataregion + (startcluster - 2) * sectorspercluster; + cluster = getcluster (z, startcluster, fatstart, fatbits); + if ((cluster < 0 || cluster >= 3) && nextblock != startblock) { + znnew = zvolume_adddir_abs (zv, &zai); + fatdirectory (z, zv, name2, nextblock, sectorspercluster * 512 / 32, sectorspercluster, fatstart, dataregion, fatbits); + while (cluster >= 3) { + nextblock = dataregion + (cluster - 2) * sectorspercluster; + fatdirectory (z, zv, name2, nextblock, sectorspercluster * 512 / 32, sectorspercluster, fatstart, dataregion, fatbits); + cluster = getcluster (z, cluster, fatstart, fatbits); + } + } + } else { + zai.size = size; + znnew = zvolume_addfile_abs (zv, &zai); + znnew->offset = startcluster; } - } - } else { - zai.size = size; - znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = startcluster; - } - xfree (fname); - } + xfree (fname); + } } struct zvolume *archive_directory_fat (struct zfile *z) { - uae_u8 buf[512] = { 0 }; - int fatbits = 12; - struct zvolume *zv; - int rootdir, reserved, sectorspercluster; - int numfats, sectorsperfat, rootentries; - int dataregion; + uae_u8 buf[512] = { 0 }; + int fatbits = 12; + struct zvolume *zv; + int rootdir, reserved, sectorspercluster; + int numfats, sectorsperfat, rootentries; + int dataregion; - zfile_fseek (z, 0, SEEK_SET); - zfile_fread (buf, 1, 512, z); + zfile_fseek (z, 0, SEEK_SET); + zfile_fread (buf, 1, 512, z); - if (!isfat (buf)) - return NULL; - reserved = buf[0x0e] | (buf[0x0f] << 8); - numfats = buf[0x10]; - sectorsperfat = buf[0x16] | (buf[0x17] << 8); - rootentries = buf[0x11] | (buf[0x12] << 8); - sectorspercluster = buf[0x0d]; - rootdir = reserved + numfats * sectorsperfat; - dataregion = rootdir + rootentries * 32 / 512; - - zv = zvolume_alloc (z, ArchiveFormatFAT, NULL, NULL); - fatdirectory (z, zv, L"", rootdir, rootentries, sectorspercluster, reserved, dataregion, fatbits); - zv->method = ArchiveFormatFAT; - return zv; + if (!isfat (buf)) + return NULL; + reserved = buf[0x0e] | (buf[0x0f] << 8); + numfats = buf[0x10]; + sectorsperfat = buf[0x16] | (buf[0x17] << 8); + rootentries = buf[0x11] | (buf[0x12] << 8); + sectorspercluster = buf[0x0d]; + rootdir = reserved + numfats * sectorsperfat; + dataregion = rootdir + rootentries * 32 / 512; + + zv = zvolume_alloc (z, ArchiveFormatFAT, NULL, NULL); + fatdirectory (z, zv, L"", rootdir, rootentries, sectorspercluster, reserved, dataregion, fatbits); + zv->method = ArchiveFormatFAT; + return zv; } struct zfile *archive_access_fat (struct znode *zn) { - uae_u8 buf[512] = { 0 }; - int fatbits = 12; - int size = zn->size; - struct zfile *sz, *dz; - int rootdir, reserved, sectorspercluster; - int numfats, sectorsperfat, rootentries; - int dataregion; - int offset, cluster; - - sz = zn->volume->archive; - - zfile_fseek (sz, 0, SEEK_SET); - zfile_fread (buf, 1, 512, sz); - - if (!isfat (buf)) - return NULL; - reserved = buf[0x0e] | (buf[0x0f] << 8); - numfats = buf[0x10]; - sectorsperfat = buf[0x16] | (buf[0x17] << 8); - rootentries = buf[0x11] | (buf[0x12] << 8); - sectorspercluster = buf[0x0d]; - rootdir = reserved + numfats * sectorsperfat; - dataregion = rootdir + rootentries * 32 / 512; - - dz = zfile_fopen_empty (sz, zn->fullname, size); - if (!dz) - return NULL; + uae_u8 buf[512] = { 0 }; + int fatbits = 12; + int size = zn->size; + struct zfile *sz, *dz; + int rootdir, reserved, sectorspercluster; + int numfats, sectorsperfat, rootentries; + int dataregion; + int offset, cluster; + + sz = zn->volume->archive; + + zfile_fseek (sz, 0, SEEK_SET); + zfile_fread (buf, 1, 512, sz); + + if (!isfat (buf)) + return NULL; + reserved = buf[0x0e] | (buf[0x0f] << 8); + numfats = buf[0x10]; + sectorsperfat = buf[0x16] | (buf[0x17] << 8); + rootentries = buf[0x11] | (buf[0x12] << 8); + sectorspercluster = buf[0x0d]; + rootdir = reserved + numfats * sectorsperfat; + dataregion = rootdir + rootentries * 32 / 512; + + dz = zfile_fopen_empty (sz, zn->fullname, size); + if (!dz) + return NULL; + + offset = 0; + cluster = zn->offset; + while (size && cluster >= 2) { + int left = size > sectorspercluster * 512 ? sectorspercluster * 512 : size; + int sector = dataregion + (cluster - 2) * sectorspercluster; + zfile_fseek (sz, sector * 512, SEEK_SET); + zfile_fread (dz->data + offset, 1, left, sz); + size -= left; + offset += left; + cluster = getcluster (sz, cluster, reserved, fatbits); + } - offset = 0; - cluster = zn->offset; - while (size && cluster >= 2) { - int left = size > sectorspercluster * 512 ? sectorspercluster * 512 : size; - int sector = dataregion + (cluster - 2) * sectorspercluster; - zfile_fseek (sz, sector * 512, SEEK_SET); - zfile_fread (dz->data + offset, 1, left, sz); - size -= left; - offset += left; - cluster = getcluster (sz, cluster, reserved, fatbits); - } - - return dz; + return dz; } void archive_access_close (void *handle, unsigned int id) { - switch (id) - { + switch (id) + { case ArchiveFormatZIP: - archive_close_zip (handle); - break; + archive_close_zip (handle); + break; case ArchiveFormat7Zip: - archive_close_7z (handle); - break; + archive_close_7z (handle); + break; case ArchiveFormatRAR: - archive_close_rar (handle); - break; + archive_close_rar (handle); + break; case ArchiveFormatLHA: - break; + break; case ArchiveFormatADF: - archive_close_adf (handle); - break; - } + archive_close_adf (handle); + break; + } } struct zfile *archive_access_dir (struct znode *zn) { - return zfile_fopen (zn->fullname, L"rb", 0); + return zfile_fopen (zn->fullname, L"rb", 0); } -- 2.47.3