From f701172f26ac3fa21b1baf0b4bc1ae6dfb7f813b Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Wed, 2 Jul 2008 19:58:46 +0300 Subject: [PATCH] imported winuaesrc1510b4.zip --- bsdsocket.c | 4 +- custom.c | 34 +- debug.c | 185 ++++----- filesys.c | 16 +- include/debug.h | 2 +- include/inputdevice.h | 3 + include/options.h | 1 + inputdevice.c | 57 ++- newcpu.c | 8 +- od-win32/ahidsound_new.c | 691 ++++++++++++++++++++++++++++------ od-win32/dinput.c | 385 ++++++++++++------- od-win32/dxwrap.c | 2 - od-win32/parser.c | 4 +- od-win32/posixemu.c | 2 +- od-win32/resources/resource | 3 +- od-win32/resources/resource.h | 1 + od-win32/resources/winuae.rc | 33 +- od-win32/rp.c | 4 +- od-win32/win32.c | 31 +- od-win32/win32.h | 4 +- od-win32/win32gfx.c | 25 +- od-win32/win32gui.c | 53 ++- od-win32/winuaechangelog.txt | 12 + uaeresource.c | 13 +- zfile.c | 2 + 25 files changed, 1176 insertions(+), 399 deletions(-) diff --git a/bsdsocket.c b/bsdsocket.c index 188fd365..dcf74601 100755 --- a/bsdsocket.c +++ b/bsdsocket.c @@ -265,7 +265,7 @@ void addtosigqueue (SB, int events) unlocksigqueue (); if (sts) - uae_Signal(ot, sts); + uae_Signal (ot, sts); #endif } @@ -282,7 +282,7 @@ void bsdsock_fake_int_handler(void) for (sb = sbsigqueue; sb; sb = sb->nextsig) { if (sb->dosignal == 1) { - uae_Signal(sb->ownertask, sb->sigstosend); + uae_Signal (sb->ownertask, sb->sigstosend); sb->sigstosend = 0; } sb->dosignal = 0; diff --git a/custom.c b/custom.c index 6400a2b7..6ce16b9d 100755 --- a/custom.c +++ b/custom.c @@ -2555,11 +2555,11 @@ STATIC_INLINE uae_u16 ADKCONR (void) return adkcon; } -STATIC_INLINE int GETVPOS(void) +STATIC_INLINE int GETVPOS (void) { return lightpen_triggered > 0 ? vpos_lpen : (((bplcon0 & 2) && !currprefs.genlock) ? vpos_previous : vpos); } -STATIC_INLINE int GETHPOS(void) +STATIC_INLINE int GETHPOS (void) { return lightpen_triggered > 0 ? hpos_lpen : (((bplcon0 & 2) && !currprefs.genlock) ? hpos_previous : current_hpos ()); } @@ -2589,7 +2589,7 @@ STATIC_INLINE uae_u16 VPOSR (void) write_log ("vposr %x at %x\n", vp, m68k_getpc (®s)); #endif if (currprefs.cpu_model >= 68020) - hsyncdelay(); + hsyncdelay (); return vp; } static void VPOSW (uae_u16 v) @@ -2606,10 +2606,10 @@ static void VPOSW (uae_u16 v) STATIC_INLINE uae_u16 VHPOSR (void) { - uae_u16 vp = GETVPOS(); - uae_u16 hp = GETHPOS(); + uae_u16 vp = GETVPOS (); + uae_u16 hp = GETHPOS (); vp <<= 8; - vp |= hp; + vp |= hp ^ 1; // hack.. if (currprefs.cpu_model >= 68020) hsyncdelay (); return vp; @@ -4404,6 +4404,10 @@ static void vsync_handler (void) #ifdef PICASSO96 picasso_handle_vsync (); #endif + { + void ahi_vsync (void); + ahi_vsync (); + } if (quit_program > 0) { /* prevent possible infinite loop at wait_cycles().. */ @@ -4710,6 +4714,18 @@ static void hsync_handler (void) hsync_counter++; //copper_check (2); +#if 0 + { + static int skip; + if (M68K_GETPC >= 0x0C0D7A2 && M68K_GETPC < 0x00C0D7B2 && vpos == 0xf3) { + if (!skip) + activate_debugger (); + skip = 1; + } + if (vpos != 0xf3) + skip = 0; + } +#endif } static void MISC_handler(void) @@ -4746,7 +4762,7 @@ static void MISC_handler(void) eventtab[ev_misc].active = 1; eventtab[ev_misc].oldcycles = ct; eventtab[ev_misc].evtime = ct + mintime; - events_schedule(); + events_schedule (); } recursive--; } @@ -5960,7 +5976,7 @@ STATIC_INLINE void decide_fetch_ce (int hpos) decide_fetch (hpos); } -STATIC_INLINE void dma_cycle(void) +STATIC_INLINE void dma_cycle (void) { int hpos; static int bnasty; @@ -5988,7 +6004,7 @@ STATIC_INLINE void dma_cycle(void) /* bus was allocated to dma channel, wait for next cycle.. */ } bnasty = 0; - alloc_cycle(hpos, CYCLE_CPU); + alloc_cycle (hpos, CYCLE_CPU); } uae_u32 wait_cpu_cycle_read (uaecptr addr, int mode) diff --git a/debug.c b/debug.c index 279e9b96..b063694b 100755 --- a/debug.c +++ b/debug.c @@ -254,11 +254,11 @@ static uae_u32 readhexx (char **c) char nc; ignore_ws (c); - while (isxdigit(nc = **c)) { + while (isxdigit (nc = **c)) { (*c)++; val *= 16; - nc = toupper(nc); - if (isdigit(nc)) { + nc = toupper (nc); + if (isdigit (nc)) { val += nc - '0'; } else { val += nc - 'A' + 10; @@ -276,7 +276,7 @@ static uae_u32 readintx (char **c) ignore_ws (c); if (**c == '-') negative = 1, (*c)++; - while (isdigit(nc = **c)) { + while (isdigit (nc = **c)) { (*c)++; val *= 10; val += nc - '0'; @@ -290,7 +290,7 @@ static int checkvaltype (char **c, uae_u32 *val) char nc; ignore_ws (c); - nc = toupper(**c); + nc = toupper (**c); if (nc == '!') { (*c)++; *val = readintx (c); @@ -301,7 +301,7 @@ static int checkvaltype (char **c, uae_u32 *val) *val = readhexx (c); return 1; } - if (nc == '0' && toupper((*c)[1]) == 'X') { + if (nc == '0' && toupper ((*c)[1]) == 'X') { (*c)+= 2; *val = readhexx (c); return 1; @@ -908,7 +908,7 @@ static void deepcheatsearch (char **c) int addrcnt, cnt; char v; - v = toupper(**c); + v = toupper (**c); if(!memtmp || v == 'S') { maxdiff = 0x10000; @@ -919,31 +919,31 @@ static void deepcheatsearch (char **c) if (**c) (*c)++; - ignore_ws(c); + ignore_ws (c); if ((**c) == '1' || (**c) == '2') { size = **c - '0'; (*c)++; } - if (more_params(c)) + if (more_params (c)) maxdiff = readint(c); if (!memtmp || v == 'S') { first = 1; - xfree(memtmp); + xfree (memtmp); memsize = 0; addr = 0xffffffff; - while ((addr = nextaddr(addr, &end)) != 0xffffffff) { + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { memsize += end - addr; addr = end - 1; } memsize2 = (memsize + 7) / 8; - memtmp = (uae_u8*)xmalloc (memsize + memsize2); + memtmp = xmalloc (memsize + memsize2); if (!memtmp) return; memset (memtmp + memsize, 0xff, memsize2); p1 = memtmp; addr = 0xffffffff; - while ((addr = nextaddr(addr, &end)) != 0xffffffff) { + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { for (i = addr; i < end; i++) *p1++ = get_byte (i); addr = end - 1; @@ -963,7 +963,7 @@ static void deepcheatsearch (char **c) addrcnt = 0; cnt = 0; addr = 0xffffffff; - while ((addr = nextaddr(addr, NULL)) != 0xffffffff) { + while ((addr = nextaddr (addr, NULL)) != 0xffffffff) { uae_s32 b, b2; int doremove = 0; int addroff = addrcnt >> 3; @@ -1006,7 +1006,7 @@ static void deepcheatsearch (char **c) } else { p1[addrcnt] = b >> 8; p1[addrcnt + 1] = b >> 0; - addr = nextaddr(addr, NULL); + addr = nextaddr (addr, NULL); if (addr == 0xffffffff) break; addrcnt += 2; @@ -1015,7 +1015,7 @@ static void deepcheatsearch (char **c) console_out_f ("%d addresses found\n", cnt); if (cnt <= MAX_CHEAT_VIEW) { - clearcheater(); + clearcheater (); cnt = 0; addrcnt = 0; addr = 0xffffffff; @@ -1023,11 +1023,11 @@ static void deepcheatsearch (char **c) int addroff = addrcnt >> 3; int addrmask = (size == 1 ? 1 : 3) << (addrcnt & 7); if (p2[addroff] & addrmask) - addcheater(addr, size); + addcheater (addr, size); addrcnt += size; cnt++; } - listcheater(1, size); + listcheater (1, size); } else { console_out ("Now continue with 'g' and use 'D' again after you have lost another life\n"); } @@ -1046,22 +1046,22 @@ static void cheatsearch (char **c) memsize = 0; addr = 0xffffffff; - while ((addr = nextaddr(addr, &end)) != 0xffffffff) { + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { memsize += end - addr; addr = end - 1; } - if (toupper(**c) == 'L') { - listcheater(1, size); + if (toupper (**c) == 'L') { + listcheater (1, size); return; } ignore_ws (c); - if (!more_params(c)) { + if (!more_params (c)) { first = 1; console_out ("search reset\n"); xfree (vlist); listsize = memsize; - vlist = (uae_u8*)xcalloc (listsize >> 3, 1); + vlist = xcalloc (listsize >> 3, 1); return; } val = readint (c); @@ -1074,8 +1074,8 @@ static void cheatsearch (char **c) size = 4; } ignore_ws (c); - if (more_params(c)) - size = readint(c); + if (more_params (c)) + size = readint (c); if (size > 4) size = 4; if (size < 1) @@ -1083,16 +1083,16 @@ static void cheatsearch (char **c) if (vlist == NULL) { listsize = memsize; - vlist = (uae_u8*)xcalloc (listsize >> 3, 1); + vlist = xcalloc (listsize >> 3, 1); } count = 0; vcnt = 0; - clearcheater(); + clearcheater (); addr = 0xffffffff; prevmemcnt = memcnt = 0; - while ((addr = nextaddr(addr, &end)) != 0xffffffff) { + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { if (addr + size < end) { for (i = 0; i < size; i++) { int shift = (size - i - 1) * 8; @@ -1158,14 +1158,14 @@ static void illg_init (void) uae_u8 c = 3; uaecptr addr, end; - illgdebug = (uae_u8*)xcalloc (0x01000000, 1); - illghdebug = (uae_u8*)xcalloc(65536, 1); + illgdebug = xcalloc (0x01000000, 1); + illghdebug = xcalloc (65536, 1); if (!illgdebug || !illghdebug) { illg_free(); return; } addr = 0xffffffff; - while ((addr = nextaddr(addr, &end)) != 0xffffffff) { + while ((addr = nextaddr (addr, &end)) != 0xffffffff) { if (end < 0x01000000) { memset (illgdebug + addr, c, end - addr); } else { @@ -1364,7 +1364,7 @@ static int memwatch_func (uaecptr addr, int rwi, int size, uae_u32 *valp) illg_debug_do (addr, rwi, size, val); addr = munge24 (addr); if (smc_table && (rwi >= 2)) - smc_detector(addr, rwi, size, valp); + smc_detector (addr, rwi, size, valp); for (i = 0; i < MEMWATCH_TOTAL; i++) { struct memwatch_node *m = &mwnodes[i]; uaecptr addr2 = m->addr; @@ -1388,16 +1388,22 @@ static int memwatch_func (uaecptr addr, int rwi, int size, uae_u32 *valp) if (!m->frozen && m->val_enabled) { int trigger = 0; - uae_u32 mask = ((1 << (m->size * 8)) - 1); + uae_u32 mask = (1 << (m->size * 8)) - 1; + int scnt = size; for (;;) { - if ((m->val & mask) == (val & mask)) + if (((m->val & mask) & m->valmask) == ((val & mask) & m->valmask)) trigger = 1; if (mask & 0x80000000) break; - if (m->size == 1) + if (m->size == 1) { mask <<= 8; - else if (m->size == 2) + scnt--; + } else if (m->size == 2) { mask <<= 16; + scnt -= 2; + } + if (scnt <= 0) + break; } if (!trigger) continue; @@ -1448,16 +1454,16 @@ 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); + 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); + if (!mmu_hit (addr, 2, 0, &v)) + v = debug_mem_banks[off]->wget (addr); return v; } static uae_u32 REGPARAM2 mmu_bget (uaecptr addr) @@ -1465,33 +1471,33 @@ 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); + 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); + 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); + 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); + 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); + v = debug_mem_banks[off]->lget (addr); memwatch_func (addr, 1, 4, &v); return v; } @@ -1499,16 +1505,16 @@ 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); + 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); + if (!mmu_hit (addr, 2, 4, &v)) + v = debug_mem_banks[off]->wgeti (addr); return v; } @@ -1516,7 +1522,7 @@ static uae_u32 REGPARAM2 debug_wget (uaecptr addr) { int off = debug_mem_off (addr); uae_u32 v; - v = debug_mem_banks[off]->wget(addr); + v = debug_mem_banks[off]->wget (addr); memwatch_func (addr, 1, 2, &v); return v; } @@ -1524,7 +1530,7 @@ static uae_u32 REGPARAM2 debug_bget (uaecptr addr) { int off = debug_mem_off (addr); uae_u32 v; - v = debug_mem_banks[off]->bget(addr); + v = debug_mem_banks[off]->bget (addr); memwatch_func (addr, 1, 1, &v); return v; } @@ -1532,7 +1538,7 @@ static uae_u32 REGPARAM2 debug_lgeti (uaecptr addr) { int off = debug_mem_off (addr); uae_u32 v; - v = debug_mem_banks[off]->lgeti(addr); + v = debug_mem_banks[off]->lgeti (addr); memwatch_func (addr, 4, 4, &v); return v; } @@ -1540,7 +1546,7 @@ static uae_u32 REGPARAM2 debug_wgeti (uaecptr addr) { int off = debug_mem_off (addr); uae_u32 v; - v = debug_mem_banks[off]->wgeti(addr); + v = debug_mem_banks[off]->wgeti (addr); memwatch_func (addr, 4, 2, &v); return v; } @@ -1548,19 +1554,19 @@ 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); + 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); + 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); + debug_mem_banks[off]->bput (addr, v); } static int REGPARAM2 debug_check (uaecptr addr, uae_u32 size) { @@ -1638,10 +1644,10 @@ static void initialize_memwatch (int mode) int i, as; addrbank *a1, *a2; - deinitialize_memwatch(); + deinitialize_memwatch (); as = currprefs.address_space_24 ? 256 : 65536; - debug_mem_banks = (addrbank**)xmalloc (sizeof (addrbank*) * as); - debug_mem_area = (addrbank*)xmalloc (sizeof (addrbank) * as); + debug_mem_banks = xmalloc (sizeof (addrbank*) * as); + debug_mem_area = xmalloc (sizeof (addrbank) * as); for (i = 0; i < as; i++) { a1 = debug_mem_banks[i] = debug_mem_area + i; a2 = mem_banks[i]; @@ -1672,7 +1678,7 @@ void memwatch_dump2 (char *buf, int bufsize, int num) struct memwatch_node *mwn; if (buf) - memset(buf, 0, bufsize); + memset (buf, 0, bufsize); for (i = 0; i < MEMWATCH_TOTAL; i++) { if ((num >= 0 && num == i) || (num < 0)) { mwn = &mwnodes[i]; @@ -1697,12 +1703,12 @@ static void memwatch_dump (int num) char *buf; int multiplier = num < 0 ? MEMWATCH_TOTAL : 1; - buf = (char*)malloc(50 * multiplier); + buf = malloc (50 * multiplier); if (!buf) return; memwatch_dump2 (buf, 50 * multiplier, num); - f_out(stdout, "%s", buf); - free(buf); + f_out (stdout, "%s", buf); + xfree (buf); } static void memwatch (char **c) @@ -1770,6 +1776,7 @@ static void memwatch (char **c) mwn->size = 1; mwn->rwi = 7; mwn->val_enabled = 0; + mwn->valmask = 0xffffffff; mwn->frozen = 0; mwn->modval_written = 0; ignore_ws (c); @@ -1828,8 +1835,8 @@ static void writeintomem (char **c) len = 2; else len = 1; - if (more_params(c)) { - ignore_ws(c); + if (more_params (c)) { + ignore_ws (c); len = readint (c); } if (len == 4) { @@ -1845,11 +1852,11 @@ static void writeintomem (char **c) console_out_f ("Wrote %X (%u) at %08X.%c\n", val, val, addr, cc); } -static uae_u8 *dump_xlate(uae_u32 addr) +static uae_u8 *dump_xlate (uae_u32 addr) { - if (!mem_banks[addr >> 16]->check(addr, 1)) + if (!mem_banks[addr >> 16]->check (addr, 1)) return NULL; - return mem_banks[addr >> 16]->xlateaddr(addr); + return mem_banks[addr >> 16]->xlateaddr (addr); } static void memory_map_dump_2 (int log) @@ -1878,11 +1885,11 @@ static void memory_map_dump_2 (int log) name = ""; k = j; - caddr = dump_xlate(k << 16); + caddr = dump_xlate (k << 16); mirrored = caddr ? 1 : 0; k++; while (k < i && caddr) { - if (dump_xlate(k << 16) == caddr) + if (dump_xlate (k << 16) == caddr) mirrored++; k++; } @@ -1898,17 +1905,17 @@ static void memory_map_dump_2 (int log) tmp[0] = 0; if (a1->flags == ABFLAG_ROM && mirrored) { - char *p = txt + strlen(txt); - uae_u32 crc = get_crc32(a1->xlateaddr(j << 16), (size * 1024) / mirrored); - struct romdata *rd = getromdatabycrc(crc); + char *p = txt + strlen (txt); + uae_u32 crc = get_crc32 (a1->xlateaddr(j << 16), (size * 1024) / mirrored); + struct romdata *rd = getromdatabycrc (crc); sprintf(p, " (%08.8X)", crc); if (rd) { tmp[0] = '='; - getromname(rd, tmp + 1); - strcat(tmp,"\n"); + getromname (rd, tmp + 1); + strcat (tmp,"\n"); } } - strcat(txt,"\n"); + strcat (txt,"\n"); if (log) write_log (txt); else @@ -1930,21 +1937,21 @@ void memory_map_dump (void) memory_map_dump_2 (1); } -STATIC_INLINE uaecptr BPTR2APTR(uaecptr addr) +STATIC_INLINE uaecptr BPTR2APTR (uaecptr addr) { return addr << 2; } -static char* BSTR2CSTR(uae_u8 *bstr) +static char* BSTR2CSTR (uae_u8 *bstr) { - char *cstr = (char*)xmalloc(bstr[0] + 1); + char *cstr = xmalloc (bstr[0] + 1); if (cstr) { - memcpy(cstr, bstr + 1, bstr[0]); + memcpy (cstr, bstr + 1, bstr[0]); cstr[bstr[0]] = 0; } return cstr; } -static void print_task_info(uaecptr node) +static void print_task_info (uaecptr node) { int process = get_byte (node + 8) == 13 ? 1 : 0; console_out_f ("%08X: %08X", node, 0); @@ -2002,7 +2009,7 @@ int instruction_breakpoint (char **c) int i; if (more_params (c)) { - char nc = toupper((*c)[0]); + char nc = toupper ((*c)[0]); if (nc == 'S') { next_char (c); sr_bpvalue = sr_bpmask = 0; @@ -2088,15 +2095,15 @@ int instruction_breakpoint (char **c) static int process_breakpoint(char **c) { processptr = 0; - xfree(processname); + xfree (processname); processname = NULL; if (!more_params (c)) return 0; if (**c == '\"') { - processname = (char*)xmalloc(200); - next_string(c, processname, 200, 0); + processname = xmalloc (200); + next_string (c, processname, 200, 0); } else { - processptr = readhex(c); + processptr = readhex (c); } do_skip = 1; skipaddr_doskip = 1; diff --git a/filesys.c b/filesys.c index b230c759..ed51619a 100755 --- a/filesys.c +++ b/filesys.c @@ -291,9 +291,9 @@ char *filesys_createvolname (const char *volname, const char *rootdir, const cha char *p = NULL; archivehd = -1; - if (my_existsfile(rootdir)) + if (my_existsfile (rootdir)) archivehd = 1; - else if (my_existsdir(rootdir)) + else if (my_existsdir (rootdir)) archivehd = 0; if ((!volname || strlen (volname) == 0) && rootdir && archivehd >= 0) { @@ -331,7 +331,7 @@ char *filesys_createvolname (const char *volname, const char *rootdir, const cha else nvol = my_strdup (""); } - stripsemicolon(nvol); + stripsemicolon (nvol); xfree (p); return nvol; } @@ -936,12 +936,12 @@ static void set_volume_name (Unit *unit) unit->rootnode.mountcount = unit->mountcount; } -static int filesys_isvolume(Unit *unit) +static int filesys_isvolume (Unit *unit) { return get_byte (unit->volume + 44); } -static void clear_exkeys(Unit *unit) +static void clear_exkeys (Unit *unit) { int i; a_inode *a; @@ -1172,7 +1172,7 @@ int filesys_insert (int nr, char *volume, const char *rootdir, int readonly, int return 0; if (u->reinsertdelay) return -1; - if (is_hardfile(nr) != FILESYS_VIRTUAL) + if (is_hardfile (nr) != FILESYS_VIRTUAL) return 0; if (filesys_isvolume (u)) { filesys_delayed_change (u, 50, rootdir, volume, readonly, flags); @@ -1182,7 +1182,7 @@ int filesys_insert (int nr, char *volume, const char *rootdir, int readonly, int clear_exkeys (u); xfree (u->ui.rootdir); ui->rootdir = u->ui.rootdir = my_strdup (rootdir); - flush_cache(u, -1); + flush_cache (u, -1); if (set_filesys_volume (rootdir, &flags, &readonly, &emptydrive, &u->zarchive) < 0) return 0; if (emptydrive) @@ -1199,7 +1199,7 @@ int filesys_insert (int nr, char *volume, const char *rootdir, int readonly, int 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 << 17); + uae_Signal (get_long (u->volume + 176 - 32), 1 << 17); return 100 + nr; } diff --git a/include/debug.h b/include/debug.h index e1272cba..623f8e9e 100755 --- a/include/debug.h +++ b/include/debug.h @@ -47,7 +47,7 @@ struct memwatch_node { uaecptr addr; int size; int rwi; - uae_u32 val; + uae_u32 val, valmask; int val_enabled; uae_u32 modval; int modval_written; diff --git a/include/inputdevice.h b/include/inputdevice.h index 60d48970..df61d2cd 100755 --- a/include/inputdevice.h +++ b/include/inputdevice.h @@ -189,3 +189,6 @@ extern uae_u8 inprec_pu8(void); extern uae_u16 inprec_pu16(void); extern uae_u32 inprec_pu32(void); extern int inprec_pstr(char*); + +extern int inputdevice_testread (char *name); +extern int inputdevice_istest (void); diff --git a/include/options.h b/include/options.h index 2a7c3c6c..50c22010 100755 --- a/include/options.h +++ b/include/options.h @@ -315,6 +315,7 @@ struct uae_prefs { int win32_rtgmatchdepth; int win32_rtgscaleifsmall; int win32_rtgallowscaling; + int win32_rtgscaleaspectratio; int win32_borderless; int win32_ctrl_F11_is_quit; int win32_automount_removable; diff --git a/inputdevice.c b/inputdevice.c index ee7cc2a8..7efcb55c 100755 --- a/inputdevice.c +++ b/inputdevice.c @@ -115,6 +115,7 @@ static struct uae_input_device2 joysticks2[MAX_INPUT_DEVICES]; static struct uae_input_device2 mice2[MAX_INPUT_DEVICES]; static int input_acquired; +static int testmode; static uae_u8 *inprec_buffer, *inprec_p; static struct zfile *inprec_zf; @@ -430,7 +431,7 @@ static void write_config2 (struct zfile *f, int idnum, int i, int offset, char * 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) + if (id->eventid[i + offset][k] > 0 || id->custom[i + offset][k] != NULL) break; } if (k == MAX_INPUT_SUB_EVENT) @@ -538,7 +539,7 @@ static void write_kbr_config (struct zfile *f, int idnum, int devnum, struct uae 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) break; + if (kbr->eventid[i][k] > 0 || kbr->custom[i][k] != NULL) break; } if (k == MAX_INPUT_SUB_EVENT) break; @@ -3078,8 +3079,8 @@ void inputdevice_acquire (int allmode) if (use_keyboards[i]) idev[IDTYPE_KEYBOARD].acquire (i, 0); } - if (!input_acquired) - write_log ("input devices acquired (%s)\n", allmode ? "all" : "selected only"); +// if (!input_acquired) +// write_log ("input devices acquired (%s)\n", allmode ? "all" : "selected only"); input_acquired = 1; } @@ -3087,8 +3088,8 @@ void inputdevice_unacquire (void) { int i; - if (input_acquired) - write_log ("input devices unacquired\n"); +// if (input_acquired) +// write_log ("input devices unacquired\n"); input_acquired = 0; for (i = 0; i < MAX_INPUT_DEVICES; i++) idev[IDTYPE_JOYSTICK].unacquire (i); @@ -3098,6 +3099,30 @@ void inputdevice_unacquire (void) idev[IDTYPE_KEYBOARD].unacquire (i); } +static void testrecord (int type, int num, int wtype, int wnum, int state) +{ + char tmp[2000]; + tmp[0] = 0; + wnum += idev[type].get_widget_first (num, wtype); + idev[type].get_widget_type (num, wnum, tmp, NULL); + write_log ("%s: %s %d\n", idev[type].get_friendlyname (num), tmp, state); +} + +int inputdevice_istest (void) +{ + return testmode; +} + +int inputdevice_testread (char *name) +{ + 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]) @@ -3109,7 +3134,7 @@ static int ignoreoldinput (int joy) return 0; } -void do_fake_joystick(int nr, int *fake) +void do_fake_joystick (int nr, int *fake) { struct uae_input_device *id1; struct uae_input_device2 *id2; @@ -3189,6 +3214,10 @@ void setmousebuttonstateall (int mouse, uae_u32 buttonbits, uae_u32 buttonmask) 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); } @@ -3202,6 +3231,10 @@ void setjoystickstate (int joy, int axis, int state, int max) 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) @@ -3222,6 +3255,8 @@ void setjoystickstate (int joy, int axis, int state, int max) } int getjoystickstate(int joy) { + if (testmode) + return 1; return joysticks[joy].enabled; } @@ -3233,6 +3268,10 @@ void setmousestate (int mouse, int axis, int data, int isabs) static double fract1[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS]; static double fract2[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS]; + if (testmode) { + testrecord (IDTYPE_MOUSE, mouse, IDEV_WIDGET_AXIS, axis, data); + return; + } if (!mice[mouse].enabled) return; d = 0; @@ -3263,8 +3302,10 @@ void setmousestate (int mouse, int axis, int data, int isabs) handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], v, 0, 0); mousehack_helper (); } -int getmousestate(int joy) +int getmousestate (int joy) { + if (testmode) + return 1; return mice[joy].enabled; } diff --git a/newcpu.c b/newcpu.c index ee6991a5..c85f821f 100755 --- a/newcpu.c +++ b/newcpu.c @@ -2698,16 +2698,16 @@ void m68k_disasm_2 (char *buf, int bufsize, uaecptr addr, uaecptr *nextpc, int c m68kpc_offset += 2; } else if (lookup->mnemo == i_MVMEL) { newpc = m68k_getpc (®s) + m68kpc_offset; + m68kpc_offset += 2; newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); strcat (instrname, ","); - movemout (instrname, get_iword_1 (m68kpc_offset), dp->dmode); - m68kpc_offset += 2; + movemout (instrname, get_iword_1 (m68kpc_offset - 2), dp->dmode); } else if (lookup->mnemo == i_MVMLE) { - movemout (instrname, get_iword_1 (m68kpc_offset), dp->dmode); + m68kpc_offset += 2; + movemout (instrname, get_iword_1 (m68kpc_offset - 2), dp->dmode); strcat (instrname, ","); newpc = m68k_getpc (®s) + m68kpc_offset; newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode); - m68kpc_offset += 2; } else { if (dp->suse) { newpc = m68k_getpc (®s) + m68kpc_offset; diff --git a/od-win32/ahidsound_new.c b/od-win32/ahidsound_new.c index 44d27908..a32b6a9c 100755 --- a/od-win32/ahidsound_new.c +++ b/od-win32/ahidsound_new.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "sysdeps.h" #include "options.h" @@ -27,6 +29,8 @@ #include "newcpu.h" #include "autoconf.h" #include "traps.h" +#include "threaddep/thread.h" +#include "native2amiga.h" #include "od-win32/win32.h" #include "sounddep/sound.h" #include "ahidsound_new.h" @@ -39,6 +43,29 @@ #include +static int ahi_debug = 1; + +#define UAE_MAXCHANNELS 24 +#define UAE_MAXSOUNDS 256 + +#define ub_Flags 34 +#define ub_Pad1 (ub_Flags + 1) +#define ub_Pad2 (ub_Pad1 + 1) +#define ub_SysLib (ub_Pad2 + 2) +#define ub_SegList (ub_SysLib + 4) +#define ub_DOSBase (ub_SegList + 4) +#define ub_AHIFunc (ub_DOSBase + 4) + +#define pub_Index 0 +#define pub_Base (pub_Index + 4) +#define pub_audioctrl (pub_Base + 4) +#define pub_FuncTask (pub_audioctrl + 4) +#define pub_WaitMask (pub_FuncTask + 4) +#define pub_WaitSigBit (pub_WaitMask + 4) +#define pub_FuncMode (pub_WaitSigBit +4) +#define pub_TaskMode (pub_FuncMode + 2) +#define pub_ChannelSignal (pub_TaskMode + 2) + #define ahiac_AudioCtrl 0 #define ahiac_Flags ahiac_AudioCtrl + 4 #define ahiac_SoundFunc ahiac_Flags + 4 @@ -320,26 +347,37 @@ struct AHIAudioCtrlDrv #define AHIE_UNKNOWN (5UL) /* Error, but unknown */ #define AHIE_HALFDUPLEX (6UL) /* CMD_WRITE/CMD_READ failure */ -#define MAX_SAMPLES 64 - struct dssample { int num; LPDIRECTSOUNDBUFFER8 dsb; LPDIRECTSOUNDBUFFER8 dsbback; + LPDIRECTSOUNDNOTIFY dsnotify; + HANDLE notifyevent; int ch, chout; int bitspersample; int bitspersampleout; - int freq; - int volume; int bytespersample; int bytespersampleout; + int frequency; + int volume; + int panning; uae_u32 addr; uae_u32 len; uae_u32 type; int streaming; + int ready; // 1 = playing, -1 = set + int channel; +}; + +struct dschannel { + int frequency; + int volume; + int panning; + struct dssample *ds; }; struct DSAHI { + uae_u32 audioctrl; uae_u32 audioid; int mixfreq; int channels; @@ -354,11 +392,20 @@ struct DSAHI { int anticlicksamples; int enabledisable; struct dssample *sample; + struct dschannel *channel; int playing, recording; int cansurround; + evt evttime; + volatile int thread; + HANDLE threadevent; }; 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 uae_u32 xahi_author, xahi_copyright, xahi_version, xahi_output; @@ -396,6 +443,66 @@ static uae_u32 gettag (uae_u32 *tagpp, uae_u32 *datap) } } + +static int sendsignal (struct DSAHI *dsahip) +{ + uae_u32 audioctrl = dsahip->audioctrl; + uae_u32 puaebase = get_long (audioctrl + ahiac_DriverData); + uae_u32 task, signalmask; + uae_s16 taskmode = get_word (puaebase + pub_TaskMode); + task = get_long (puaebase + pub_FuncTask); + signalmask = get_long (puaebase + pub_WaitMask); + + if (!dsahip->playing) + return 0; + if (taskmode <= 0) + return 0; + if (dsahip->enabledisable) + return 0; + uae_Signal (task, signalmask); + return 1; +} + +static void 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]; + + //write_log ("AHI: channel signal %d\n", ch); + put_long (puaebase + pub_ChannelSignal, get_long (puaebase + pub_ChannelSignal) | (1 << ch)); + sendsignal (dsahip); +} + +static void evtfunc (uae_u32 v) +{ + 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) | 1); + if (sendsignal (dsahip)) + event2_newevent2 (dsahip->evttime, v, evtfunc); +} + +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; + write_log ("AHI: playerfunc freq = %.2fHz\n", f); + cycles = maxhpos * maxvpos * vblank_hz; + t = (evt)(cycles / f); + dsahip->evttime = t; + event2_newevent2 (t, dsahip - &dsahi[0], evtfunc); +} + + + static LPDIRECTSOUND8 lpDS; extern GUID sound_device_guid[]; const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010, @@ -403,19 +510,79 @@ const static GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010, #define KSAUDIO_SPEAKER_QUAD_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \ SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT) + +static void ds_freebuffer (struct DSAHI *ahidsp, struct dssample *ds) +{ + if (!ds) + return; + if (ds->dsb) + IDirectSoundBuffer8_Release (ds->dsb); + if (ds->dsbback) + IDirectSoundBuffer8_Release (ds->dsbback); + if (ds->dsnotify) + IDirectSoundNotify_Release (ds->dsnotify); + if (ds->notifyevent) + CloseHandle (ds->notifyevent); + memset (ds, 0, sizeof (struct dssample)); + ds->channel = -1; +} + static void ds_free (struct DSAHI *dsahip) { int i; for (i = 0; i < dsahip->sounds; i++) { struct dssample *ds = &dsahip->sample[i]; - if (ds->dsb) - IDirectSoundBuffer8_Release (ds->dsb); - memset (ds, 0, sizeof (ds)); + ds_freebuffer (dsahip, ds); } if (lpDS) IDirectSound_Release (lpDS); lpDS = NULL; + if (dsahip->thread) { + dsahip->thread = -1; + SetEvent (dsahip->threadevent); + while (dsahip->thread) + Sleep (2); + } +} + +static unsigned __stdcall waitthread (void *f) +{ + struct DSAHI *dsahip = f; + + dsahip->thread = 1; + while (dsahip->thread > 0) { + HANDLE handles[UAE_MAXCHANNELS + 1]; + int channelindex[UAE_MAXCHANNELS + 1]; + DWORD ob; + int maxnum = UAE_MAXCHANNELS + 1; + int num = 0; + int i; + + handles[num++] = dsahip->threadevent; + if (dsahip->playing) { + for (i = 0; i < UAE_MAXSOUNDS && num < maxnum; i++) { + struct dssample *ds = &dsahip->sample[i]; + if (ds->channel >= 0 && ds->notifyevent) { + handles[num] = ds->notifyevent; + channelindex[num] = ds->channel; + num++; + } + } + } + //write_log ("AHI: WFMO %d\n", num); + ob = WaitForMultipleObjects (num, handles, FALSE, INFINITE); + if (ob == WAIT_OBJECT_0) + continue; + if (ob >= WAIT_OBJECT_0 + 1 && ob < WAIT_OBJECT_0 + num) { + int ch; + ob -= WAIT_OBJECT_0; + ch = channelindex[ob]; + setchannelevent (dsahip, &dsahip->channel[ch]); + } + } + dsahip->thread = 0; + return 0; } DWORD fillsupportedmodes (LPDIRECTSOUND8 lpDS, int freq, struct dsaudiomodes *dsam); @@ -423,6 +590,7 @@ static struct dsaudiomodes supportedmodes[16]; static int ds_init (struct DSAHI *dsahip) { + unsigned int ta; int freq = 48000; DSCAPS DSCaps; HRESULT hr; @@ -468,17 +636,52 @@ static int ds_init (struct DSAHI *dsahip) write_log ("AHI: maximum supported frequency: %d\n", maxfreq); } } + if (ahi_debug) + write_log ("AHI: DSOUND initialized\n"); + + dsahip->thread = -1; + dsahip->threadevent = CreateEvent (NULL, FALSE, FALSE, NULL); + _beginthreadex (NULL, 0, waitthread, dsahip, 0, &ta); + return 1; error: + if (ahi_debug) + write_log ("AHI: DSOUND initialization failed\n"); ds_free (dsahip); return 0; } +static void ds_play (struct DSAHI *dsahip, struct dssample *ds) +{ + HRESULT hr; + DWORD status; + + if (ahi_debug) + write_log ("AHI: ds_play(%d)\n", ds->num); + hr = IDirectSoundBuffer8_GetStatus (ds->dsb, &status); + if (FAILED (hr)) { + write_log ("AHI: IDirectSoundBuffer8_GetStatus() failed, %s\n", DXError (hr)); + } else { + if (!(status & DSBSTATUS_PLAYING)) + setchannelevent (dsahip, &dsahip->channel[ds->channel]); + } + hr = IDirectSoundBuffer8_Play (ds->dsb, 0, 0, DSBPLAY_LOOPING); + if (FAILED (hr)) + write_log ("AHI: IDirectSoundBuffer8_Play() failed, %s\n", DXError (hr)); + if (ds->dsbback) { + hr = IDirectSoundBuffer8_Play (ds->dsbback, 0, 0, DSBPLAY_LOOPING); + if (FAILED (hr)) + write_log ("AHI: IDirectSoundBuffer8_PlayBack() failed, %s\n", DXError (hr)); + } + ds->ready = -1; +} + static void ds_setvolume (struct dssample *ds, int volume, int panning) { HRESULT hr; LONG vol, pan; + // weird AHI features: // negative pan = output from surround speakers! // negative volume = invert sample data!! (not yet emulated) vol = (LONG)((DSBVOLUME_MIN / 2) + (-DSBVOLUME_MIN / 2) * log (1 + (2.718281828 - 1) * (abs (volume) / 65536.0))); @@ -508,39 +711,42 @@ static void ds_setvolume (struct dssample *ds, int volume, int panning) write_log ("AHI: SetVolumeBack(%d,%d) failed: %s\n", ds->num, vol, DXError (hr)); } } + ds->volume = volume; + ds->panning = panning; } -static void ds_setfreq (struct dssample *ds, int freq) +static void ds_setfreq (struct DSAHI *dsahip, struct dssample *ds, int frequency) { HRESULT hr; - if (freq == 0) { + if (frequency == 0) { hr = IDirectSoundBuffer8_Stop (ds->dsb); if (ds->dsbback) hr = IDirectSoundBuffer8_Stop (ds->dsbback); } else { - if (ds->freq == 0) { - hr = IDirectSoundBuffer8_Play (ds->dsb, 0, 0, 0); - if (ds->dsbback) - hr = IDirectSoundBuffer8_Play (ds->dsbback, 0, 0, 0); - } - hr = IDirectSoundBuffer8_SetFrequency (ds->dsb, freq); + hr = IDirectSoundBuffer8_SetFrequency (ds->dsb, frequency); if (FAILED (hr)) - write_log ("AHI: SetFrequency(%d,%d) failed: %s\n", ds->num, freq, DXError (hr)); + write_log ("AHI: SetFrequency(%d,%d) failed: %s\n", ds->num, frequency, DXError (hr)); if (ds->dsbback) { - hr = IDirectSoundBuffer8_SetFrequency (ds->dsbback, freq); + hr = IDirectSoundBuffer8_SetFrequency (ds->dsbback, frequency); if (FAILED (hr)) - write_log ("AHI: SetFrequencyBack(%d,%d) failed: %s\n", ds->num, freq, DXError (hr)); + write_log ("AHI: SetFrequencyBack(%d,%d) failed: %s\n", ds->num, frequency, DXError (hr)); } + if (ds->frequency == 0) + ds_play (dsahip, ds); } - ds->freq = freq; + ds->frequency = frequency; } +#define US(x) ((x)) + static void copysampledata (struct dssample *ds, void *srcp, void *dstp, int dstsize, int offset, int srcsize) { int i, j; uae_u8 *src = (uae_u8*)srcp; uae_u8 *dst = (uae_u8*)dstp; + int och = ds->chout; + int ich = ds->ch; src += offset * ds->ch * ds->bytespersample; if (dstsize < srcsize) @@ -549,16 +755,27 @@ static void copysampledata (struct dssample *ds, void *srcp, void *dstp, int dst switch (ds->type) { case AHIST_M8S: + for (i = 0; i < srcsize; i++) { + dst[i * 4 + 0] = US (src[i]); + dst[i * 4 + 1] = US (src[i]); + dst[i * 4 + 2] = US (src[i]); + dst[i * 4 + 3] = US (src[i]); + } + break; case AHIST_S8S: for (i = 0; i < srcsize; i++) { - dst[i * 2 + 0] = src[i]; - dst[i * 2 + 1] = src[i]; + dst[i * 4 + 0] = src[i * 2 + 0]; + dst[i * 4 + 1] = src[i * 2 + 0]; + dst[i * 4 + 2] = src[i * 2 + 1]; + dst[i * 4 + 3] = src[i * 2 + 1]; } break; case AHIST_M16S: for (i = 0; i < srcsize; i++) { - dst[i * 2 + 0] = src[i * 2 + 1]; - dst[i * 2 + 1] = src[i * 2 + 0]; + dst[i * 4 + 0] = src[i * 2 + 1]; + dst[i * 4 + 1] = src[i * 2 + 0]; + dst[i * 4 + 2] = src[i * 2 + 1]; + dst[i * 4 + 3] = src[i * 2 + 0]; } break; case AHIST_S16S: @@ -571,8 +788,10 @@ static void copysampledata (struct dssample *ds, void *srcp, void *dstp, int dst break; case AHIST_M32S: for (i = 0; i < srcsize; i++) { - dst[i * 2 + 0] = src[i * 4 + 3]; - dst[i * 2 + 1] = src[i * 4 + 2]; + dst[i * 4 + 0] = src[i * 4 + 3]; + dst[i * 4 + 1] = src[i * 4 + 2]; + dst[i * 4 + 2] = src[i * 4 + 3]; + dst[i * 4 + 3] = src[i * 4 + 2]; } break; case AHIST_S32S: @@ -584,7 +803,7 @@ static void copysampledata (struct dssample *ds, void *srcp, void *dstp, int dst } break; case AHIST_L7_1: - if (ds->ch == ds->chout) { + if (ds->chout == 8) { for (i = 0; i < srcsize; i++) { for (j = 0; j < 8; j++) { dst[j * 4 + 0] = src[j * 4 + 2]; @@ -611,69 +830,129 @@ static void copysampledata (struct dssample *ds, void *srcp, void *dstp, int dst } } -static void copysample (struct dssample *ds, LPDIRECTSOUNDBUFFER8 dsb, uae_u32 offset, uae_u32 length) +static void clearsample (struct dssample *ds, LPDIRECTSOUNDBUFFER8 dsb, int dstlength) +{ + HRESULT hr; + void *buffer1; + DWORD size1, outlen; + + if (!dsb) + return; + outlen = dstlength * ds->bytespersampleout * ds->chout; + hr = IDirectSoundBuffer8_Lock (dsb, 0, outlen, &buffer1, &size1, NULL, NULL, 0); + if (hr == DSERR_BUFFERLOST) { + IDirectSoundBuffer_Restore (dsb); + hr = IDirectSoundBuffer8_Lock (dsb, 0, outlen, &buffer1, &size1, NULL, NULL, 0); + } + if (FAILED (hr)) + return; + memset (buffer1, 0, size1); + IDirectSoundBuffer8_Unlock (dsb, buffer1, size1, NULL, 0); +} + +static void copysample (struct dssample *ds, LPDIRECTSOUNDBUFFER8 dsb, int dstoffset, int dstlength, uae_u32 srcoffset, uae_u32 srclength) { HRESULT hr; - void *buffer; - DWORD size; + void *buffer1, *buffer2; + DWORD size1, size2, outoffset, outlen; uae_u32 addr; if (!dsb) return; - hr = IDirectSoundBuffer8_Lock (dsb, 0, ds->len, &buffer, &size, NULL, NULL, 0); + outlen = dstlength * ds->bytespersampleout * ds->chout; + outoffset = dstoffset * ds->bytespersampleout * ds->chout; + hr = IDirectSoundBuffer8_Lock (dsb, outoffset, outlen, &buffer1, &size1, &buffer2, &size2, 0); if (hr == DSERR_BUFFERLOST) { IDirectSoundBuffer_Restore (dsb); - hr = IDirectSoundBuffer8_Lock (dsb, 0, ds->len, &buffer, &size, NULL, NULL, 0); + hr = IDirectSoundBuffer8_Lock (dsb, outoffset, outlen, &buffer1, &size1, &buffer2, &size2, 0); } if (FAILED (hr)) return; - memset (buffer, 0, size); if (ds->addr == 0 && ds->len == 0xffffffff) - addr = offset; + addr = srcoffset; else addr = ds->addr; - if (valid_address (addr + offset * ds->ch * ds->bytespersample, length * ds->ch * ds->bytespersample)) - copysampledata (ds, get_real_address (addr), buffer, size, offset, length); - IDirectSoundBuffer8_Unlock (dsb, buffer, size, NULL, 0); + if (valid_address (addr + srcoffset * ds->ch * ds->bytespersample, srclength * ds->ch * ds->bytespersample)) { + uae_u8 *naddr = get_real_address (addr); + int part1 = size1 / (ds->bytespersampleout * ds->chout); + int part2 = size2 / (ds->bytespersampleout * ds->chout); + copysampledata (ds, naddr, buffer1, part1, srcoffset, srclength); + srcoffset += part1; + srclength -= part1; + if (srclength != 0) + copysampledata (ds, naddr, buffer2, part2, srcoffset, srclength); + } + IDirectSoundBuffer8_Unlock (dsb, buffer1, size1, buffer2, size2); } -static void ds_setsound (struct DSAHI *dsahip, struct dssample *ds, int offset, int length) +void ahi_vsync (void) { - HRESULT hr; + struct DSAHI *dsahip = &dsahi[0]; + int i; + if (!dsahip->playing) return; - copysample (ds, ds->dsb, offset, length); - copysample (ds, ds->dsbback, offset, length); + for (i = 0; i < UAE_MAXCHANNELS; i++) { + HRESULT hr; + DWORD playc, writec; + struct dssample *ds = dsahip->channel[i].ds; + + if (ds == NULL) + continue; + if (ds->type != AHIST_DYNAMICSAMPLE) + continue; + hr = IDirectSoundBuffer8_GetCurrentPosition (ds->dsb, &playc, &writec); + if (FAILED (hr)) { + write_log ("AHI: GetCurrentPosition(%d) failed, %s\n", ds->channel, DXError (hr)); + continue; + } + write_log ("AHI: ch=%d writec=%d\n", ds->channel, writec / (ds->bytespersampleout * ds->chout)); + copysample (ds, ds->dsb, + writec / (ds->bytespersampleout * ds->chout), + ds->len - 1000, + writec / (ds->bytespersampleout * ds->chout), + ds->len - 1000); + } +} + +static void ds_stop (struct dssample *ds) +{ + HRESULT hr; + + if (!ds->ready) + return; + if (ahi_debug) + write_log ("AHI: ds_stop(%d)\n", ds->num); + hr = IDirectSoundBuffer8_Stop (ds->dsb); + if (FAILED (hr)) + write_log ("AHI: IDirectSoundBuffer8_Stop() failed, %s\n", DXError (hr)); + if (ds->dsbback) { + hr = IDirectSoundBuffer8_Stop (ds->dsbback); + if (FAILED (hr)) + write_log ("AHI: IDirectSoundBuffer8_StopBack() failed, %s\n", DXError (hr)); + } + ds->ready = 1; +} + +static void ds_setsound (struct DSAHI *dsahip, struct dssample *ds, int offset, int length) +{ + HRESULT hr; + + clearsample (ds, ds->dsb, ds->len); + clearsample (ds, ds->dsbback, ds->len); + copysample (ds, ds->dsb, 0, ds->len, offset, length); + copysample (ds, ds->dsbback, 0, ds->len, offset, length); hr = IDirectSoundBuffer8_SetCurrentPosition (ds->dsb, 0); if (FAILED (hr)) write_log ("AHI: IDirectSoundBuffer8_SetCurrentPosition() failed, %s\n", DXError (hr)); - hr = IDirectSoundBuffer8_Play (ds->dsb, 0, 0, 0); - if (FAILED (hr)) - write_log ("AHI: IDirectSoundBuffer8_Play() failed, %s\n", DXError (hr)); if (ds->dsbback) { hr = IDirectSoundBuffer8_SetCurrentPosition (ds->dsbback, 0); if (FAILED (hr)) write_log ("AHI: IDirectSoundBuffer8_SetCurrentPositionBack() failed, %s\n", DXError (hr)); - hr = IDirectSoundBuffer8_Play (ds->dsbback, 0, 0, 0); - if (FAILED (hr)) - write_log ("AHI: IDirectSoundBuffer8_PlayBack() failed, %s\n", DXError (hr)); } } - -static void ds_freebuffer (struct DSAHI *ahidsp, struct dssample *ds) -{ - if (!ds) - return; - if (ds->dsb) - IDirectSoundBuffer8_Release (ds->dsb); - if (ds->dsbback) - IDirectSoundBuffer8_Release (ds->dsbback); - ds->dsb = NULL; - ds->dsbback = NULL; -} - -static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, uae_u32 addr, uae_u32 len) +static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, uae_u32 len) { HRESULT hr; DSBUFFERDESC dd; @@ -681,8 +960,9 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, LPDIRECTSOUNDBUFFER pdsb; LPDIRECTSOUNDBUFFER8 pdsb8; int round, chround; - int channels[] = { 8, 6, 2, 0 }; + int channels[] = { 2, 4, 6, 8 }; int ch, chout, bps, bpsout; + DSBPOSITIONNOTIFY pn[1]; if (!ds) return 0; @@ -700,6 +980,9 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, break; case AHIST_L7_1: ch = 8; + channels[0] = 6; + channels[1] = 8; + channels[2] = 0; break; default: return 0; @@ -722,7 +1005,10 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, default: return 0; } + if (ahi_debug) + write_log ("AHI: AllocBuffer ch=%d,bps=%d\n", ch, bps); + pdsb = NULL; bpsout = 16; for (chround = 0; channels[chround]; chround++) { chout = channels[chround]; @@ -730,13 +1016,13 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, DWORD ksmode = 0; pdsb = NULL; - memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); - wavfmt.Format.nChannels = ch; - wavfmt.Format.nSamplesPerSec = default_freq; - wavfmt.Format.wBitsPerSample = bps; if (supportedmodes[round].ch != chout) continue; + memset (&wavfmt, 0, sizeof (WAVEFORMATEXTENSIBLE)); + wavfmt.Format.nChannels = chout; + wavfmt.Format.nSamplesPerSec = default_freq; + wavfmt.Format.wBitsPerSample = bpsout; if (chout <= 2) { wavfmt.Format.wFormatTag = WAVE_FORMAT_PCM; } else { @@ -744,16 +1030,17 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, wavfmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; wavfmt.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); wavfmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; - wavfmt.Samples.wValidBitsPerSample = bps; + wavfmt.Samples.wValidBitsPerSample = bpsout; wavfmt.dwChannelMask = supportedmodes[round].ksmode; } - wavfmt.Format.nBlockAlign = bps / 8 * wavfmt.Format.nChannels; + wavfmt.Format.nBlockAlign = bpsout / 8 * wavfmt.Format.nChannels; wavfmt.Format.nAvgBytesPerSec = wavfmt.Format.nBlockAlign * wavfmt.Format.nSamplesPerSec; - dd.dwSize = sizeof (dd); - dd.dwBufferBytes = len * bps / 8 * chout; + memset (&dd, 0, sizeof dd); + dd.dwSize = sizeof dd; + dd.dwBufferBytes = len * bpsout / 8 * chout; dd.lpwfxFormat = &wavfmt.Format; - dd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; + dd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; dd.dwFlags |= DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY; dd.dwFlags |= chout >= 4 ? DSBCAPS_LOCHARDWARE : DSBCAPS_LOCSOFTWARE; dd.guid3DAlgorithm = GUID_NULL; @@ -772,21 +1059,38 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, } } write_log ("AHI: DS sound buffer failed (ch=%d,bps=%d): %s\n", - ch, bps, DXError (hr)); + chout, bpsout, DXError (hr)); } if (pdsb) break; } if (pdsb == NULL) goto error; + hr = IDirectSound_QueryInterface (pdsb, &IID_IDirectSoundBuffer8, (LPVOID*)&pdsb8); if (FAILED (hr)) { - write_log ("AHI: Secondary QueryInterface() failure: %s\n", DXError (hr)); + write_log ("AHI: Secondary QueryInterface(IID_IDirectSoundBuffer8) failure: %s\n", DXError (hr)); goto error; } + IDirectSound_Release (pdsb); ds->dsb = pdsb8; + hr = IDirectSoundBuffer8_QueryInterface (pdsb, &IID_IDirectSoundNotify8, (void**)&ds->dsnotify); + if (FAILED (hr)) { + write_log ("AHI: Secondary QueryInterface(IID_IDirectSoundNotify8) failure: %s\n", DXError (hr)); + goto error; + } + ds->notifyevent = CreateEvent (NULL, FALSE, FALSE, NULL); + pn[0].dwOffset = 0; + pn[0].hEventNotify = ds->notifyevent; + hr = IDirectSoundNotify_SetNotificationPositions (ds->dsnotify, 1, pn); + if (FAILED (hr)) { + write_log ("AHI: Secondary SetNotificationPositions() failure: %s\n", DXError (hr)); + goto error; + } + + if (chout > 2) { // create "surround" sound buffer hr = IDirectSound_CreateSoundBuffer (lpDS, &dd, &pdsb, NULL); @@ -805,10 +1109,8 @@ static int ds_allocbuffer (struct DSAHI *ahidsp, struct dssample *ds, int type, ds->chout = chout; ds->bytespersample = bps / 8; ds->bytespersampleout = bpsout / 8; - ds->freq = default_freq; - ds->addr = addr; - ds->len = len; - ds->type = type; + + SetEvent (ahidsp->threadevent); return 1; @@ -816,23 +1118,42 @@ error: return 0; } +static uae_u32 init (TrapContext *ctx) +{ + xahi_author = ds ("Toni Wilen"); + xahi_copyright = ds ("GPL"); + xahi_version = ds ("uae2 0.1 (xx.xx.2008)\r\n"); + xahi_output = ds ("Default Output"); + return 1; +} static uae_u32 AHIsub_AllocAudio (TrapContext *ctx) { + int i; uae_u32 tags = m68k_areg (&ctx->regs, 1); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); + uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); uae_u32 tag, data; uae_u32 ret = AHISF_KNOWSTEREO | AHISF_KNOWHIFI; struct DSAHI *dsahip = &dsahi[0]; - put_long (audioctrl + ahiac_DriverData, dsahip - dsahi); + if (ahi_debug) + write_log ("AHI: AllocAudio(%08x,%08x)\n", tags, audioctrl); + + put_long (pbase + pub_Index, dsahip - dsahi); + dsahip->audioctrl = audioctrl; if (!ds_init (dsahip)) return AHISF_ERROR; + dsahip->sounds = UAE_MAXSOUNDS; + dsahip->channels = UAE_MAXCHANNELS; + if (dsahip->cansurround) ret |= AHISF_KNOWMULTICHANNEL; while ((tag = gettag (&tags, &data))) { + if (ahi_debug) + write_log ("- TAG %08x=%d: %08x=%u\n", tag, tag & 0x7fff, data, data); switch (tag) { case AHIA_Sounds: @@ -859,21 +1180,25 @@ static uae_u32 AHIsub_AllocAudio (TrapContext *ctx) ds_free (dsahip); return AHISF_ERROR; } - dsahip->sample = xmalloc (sizeof (struct dssample) * dsahip->sounds); - xahi_author = ds ("Toni Wilen"); - xahi_copyright = ds ("GPL"); - xahi_version = ds ("uae2 0.1 (22.06.2008)\r\n"); - xahi_output = ds ("Default Output"); + 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]; + } + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + ds->channel = -1; + ds->num = -1; + } return ret; } -#define GETAHI (&dsahi[get_long(audioctrl + ahiac_DriverData)]) -#define GETSAMPLE (dsahip ? &dsahip->sample[channel] : NULL) - static void AHIsub_Disable (TrapContext *ctx) { uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log ("AHI: Disable(%08x)\n", audioctrl); dsahip->enabledisable++; } @@ -881,29 +1206,35 @@ static void AHIsub_Enable (TrapContext *ctx) { uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log ("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 (&ctx->regs, 2); + uae_u32 pbase = get_long (audioctrl + ahiac_DriverData); struct DSAHI *dsahip = GETAHI; - put_long (audioctrl + ahiac_DriverData, -1); + if (ahi_debug) + write_log ("AHI: FreeAudio(%08x)\n", audioctrl); + put_long (pbase + pub_Index, -1); + if (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 AHIsub_GetAttr (TrapContext *ctx) +static uae_u32 getattr2 (struct DSAHI *dsahip, uae_u32 attribute, uae_u32 argument, uae_u32 def) { - uae_u32 attribute = m68k_dreg (&ctx->regs, 0); - uae_u32 argument = m68k_dreg (&ctx->regs, 1); - uae_u32 def = m68k_dreg (&ctx->regs, 2); - uae_u32 taglist = m68k_areg (&ctx->regs, 1); - uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); - struct DSAHI *dsahip = GETAHI; int i; - + switch (attribute) { case AHIDB_Bits: @@ -935,7 +1266,7 @@ static uae_u32 AHIsub_GetAttr (TrapContext *ctx) case AHIDB_Version: return xahi_version; case AHIDB_Record: - return FALSE; + return TRUE; case AHIDB_Realtime: return TRUE; case AHIDB_Outputs: @@ -955,18 +1286,39 @@ static uae_u32 AHIsub_GetAttr (TrapContext *ctx) case AHIDB_MultiChannel: return dsahip->cansurround; case AHIDB_MaxChannels: - return 32; + return UAE_MAXCHANNELS; + case AHIDB_FullDuplex: + return 1; default: return def; } } +static uae_u32 AHIsub_GetAttr (TrapContext *ctx) +{ + uae_u32 attribute = m68k_dreg (&ctx->regs, 0); + uae_u32 argument = m68k_dreg (&ctx->regs, 1); + uae_u32 def = m68k_dreg (&ctx->regs, 2); + uae_u32 taglist = m68k_areg (&ctx->regs, 1); + uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); + struct DSAHI *dsahip = GETAHI; + uae_u32 v; + + v = getattr2 (dsahip, attribute, argument, def); + if (ahi_debug) + write_log ("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 (&ctx->regs, 0); uae_u32 argument = m68k_dreg (&ctx->regs, 1); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log ("AHI: HardwareControl(%08x,%08x,%08x)\n", attribute, argument, audioctrl); return 0; } @@ -975,10 +1327,27 @@ static uae_u32 AHIsub_Start (TrapContext *ctx) uae_u32 flags = m68k_dreg (&ctx->regs, 0); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + int i; + + if (ahi_debug) + write_log ("AHI: Play(%08x,%08x)\n", + flags, audioctrl); if (flags & AHISF_PLAY) dsahip->playing = 1; if (flags & AHISF_RECORD) dsahip->recording = 1; + if (dsahip->playing) { + setevent (dsahip); + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + if (ds->ready > 0 && ds->channel >= 0) { + struct dschannel *dc = &dsahip->channel[ds->channel]; + ds_setvolume (ds, dc->volume, dc->panning); + ds->frequency = 0; + ds_setfreq (dsahip, ds, dc->frequency); // this also starts playback + } + } + } return 0; } @@ -987,10 +1356,22 @@ static uae_u32 AHIsub_Stop (TrapContext *ctx) uae_u32 flags = m68k_dreg (&ctx->regs, 0); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + int i; + + if (ahi_debug) + write_log ("AHI: Stop(%08x,%08x)\n", + flags, audioctrl); if (flags & AHISF_PLAY) dsahip->playing = 0; if (flags & AHISF_RECORD) dsahip->recording = 0; + if (!dsahip->playing) { + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + if (ds->ready) + ds_stop (ds); + } + } return 0; } @@ -999,48 +1380,106 @@ static uae_u32 AHIsub_Update (TrapContext *ctx) uae_u32 flags = m68k_dreg (&ctx->regs, 0); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + if (ahi_debug) + write_log ("AHI: Update(%08x,%08x)\n", flags, audioctrl); + setevent (dsahip); return 0; } static uae_u32 AHIsub_SetVol (TrapContext *ctx) { - uae_u32 channel = m68k_dreg (&ctx->regs, 0); + int i; + uae_u16 channel = m68k_dreg (&ctx->regs, 0); uae_u32 volume = m68k_dreg (&ctx->regs, 1); uae_u32 pan = m68k_dreg (&ctx->regs, 2); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); uae_u32 flags = m68k_dreg (&ctx->regs, 3); struct DSAHI *dsahip = GETAHI; - struct dssample *ds = GETSAMPLE; - if (ds) - ds_setvolume (ds, volume, pan); + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug) + write_log ("AHI: SetVol(%d,%d,%08x,%08x)\n", + channel, pan, audioctrl, flags); + if (dc) { + dc->volume = volume; + dc->panning = pan; + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + if (ds->channel == channel) + ds_setvolume (ds, volume, pan); + } + } return 0; } static uae_u32 AHIsub_SetFreq (TrapContext *ctx) { - uae_u32 channel = m68k_dreg (&ctx->regs, 0); - uae_u32 freq = m68k_dreg (&ctx->regs, 1); + int i; + uae_u16 channel = m68k_dreg (&ctx->regs, 0); + uae_u32 frequency = m68k_dreg (&ctx->regs, 1); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); uae_u32 flags = m68k_dreg (&ctx->regs, 3); struct DSAHI *dsahip = GETAHI; - struct dssample *ds = GETSAMPLE; - if (ds) - ds_setfreq (ds, freq); + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug) + write_log ("AHI: SetFreq(%d,%d,%08x,%08x)\n", + channel, frequency, audioctrl, flags); + if (dc) { + dc->frequency = frequency; + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds = &dsahip->sample[i]; + if (ds->channel == channel) + ds_setfreq (dsahip, ds, frequency); + } + } return 0; } static uae_u32 AHIsub_SetSound (TrapContext *ctx) { - uae_u32 channel = m68k_dreg (&ctx->regs, 0); - uae_u32 sound = m68k_dreg (&ctx->regs, 1); + int i; + uae_u16 channel = m68k_dreg (&ctx->regs, 0); + uae_u16 sound = m68k_dreg (&ctx->regs, 1); uae_u32 offset = m68k_dreg (&ctx->regs, 2); uae_u32 length = m68k_dreg (&ctx->regs, 3); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); uae_u32 flags = m68k_dreg (&ctx->regs, 4); struct DSAHI *dsahip = GETAHI; struct dssample *ds = GETSAMPLE; - if (ds) + struct dschannel *dc = GETCHANNEL; + + if (ahi_debug) + write_log ("AHI: SetSound(%d,%d,%08x,%d,%08x,%08x)\n", + channel, sound, offset, length, audioctrl, flags); + dc->ds = NULL; + if (sound == 0xffff) { + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds2 = &dsahip->sample[i]; + if (ds2->channel == channel) { + ds_stop (ds2); + ds2->channel = -1; + + } + } + } else if (ds) { + length = abs (length); + if (length == 0) + length = ds->len; + ds->ready = 1; + ds->channel = channel; + dc->ds = ds; + for (i = 0; i < dsahip->sounds; i++) { + struct dssample *ds2 = &dsahip->sample[i]; + if (ds2 != ds && ds2->channel == channel) { + ds_stop (ds2); + ds2->channel = -1; + } + } ds_setsound (dsahip, ds, offset, length); + if (dsahip->playing) + ds_play (dsahip, ds); + } return 0; } @@ -1049,6 +1488,9 @@ static uae_u32 AHIsub_SetEffect (TrapContext *ctx) uae_u32 effect = m68k_areg (&ctx->regs, 0); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; + + if (ahi_debug) + write_log ("AHI: SetEffect(%08x,%08x)\n", effect, audioctrl); return 0; } @@ -1063,10 +1505,21 @@ static uae_u32 AHIsub_LoadSound (TrapContext *ctx) int sampletype = get_long (info + ahisi_Type); uae_u32 addr = get_long (info + ahisi_Address); uae_u32 len = get_long (info + ahisi_Length); - if (sound >= 0 && sound < MAX_SAMPLES && sound < dsahip->sounds) { + struct dssample *ds = GETSAMPLE; + + if (ahi_debug) + write_log ("AHI: LoadSound(%d,%d,%08x,%08x,SMP=%d,ADDR=%08x,LEN=%d)\n", + sound, type, info, audioctrl, sampletype, addr, len); + + if (ds) { + ds->num = sound; if (!dsahip->cansurround && type == AHIST_L7_1) return AHIE_BADSOUNDTYPE; - if (ds_allocbuffer (dsahip, &dsahip->sample[sound], type, addr, len)) + ds->addr = addr; + ds->type = type; + ds->len = len; + ds->frequency = 0; + if (ds_allocbuffer (dsahip, ds, type, len)) ret = AHIE_OK; } return ret; @@ -1077,8 +1530,13 @@ static uae_u32 AHIsub_UnloadSound (TrapContext *ctx) uae_u16 sound = m68k_dreg (&ctx->regs, 0); uae_u32 audioctrl = m68k_areg (&ctx->regs, 2); struct DSAHI *dsahip = GETAHI; - if (sound >= 0 && sound < MAX_SAMPLES) - ds_freebuffer (dsahip, &dsahip->sample[sound]); + struct dssample *ds = GETSAMPLE; + + if (ahi_debug) + write_log ("AHI: UnloadSound(%d,%08x)\n", + sound, audioctrl); + if (ds) + ds_freebuffer (dsahip, ds); return AHIE_OK; } @@ -1086,9 +1544,16 @@ static uae_u32 REGPARAM2 ahi_demux (TrapContext *ctx) { uae_u32 ret = 0; uae_u32 sp = m68k_areg (&ctx->regs, 7); - uae_u32 offset = get_word (sp); + uae_u32 offset = get_long (sp + 4); + + if (ahi_debug) + write_log ("AHI: %d\n", offset); + switch (offset) { + case 0xffffffff: + ret = init (ctx); + break; case 0: ret = AHIsub_AllocAudio (ctx); break; diff --git a/od-win32/dinput.c b/od-win32/dinput.c index 414065f0..c3d54fb7 100755 --- a/od-win32/dinput.c +++ b/od-win32/dinput.c @@ -38,6 +38,8 @@ #include #include #endif +#include +#include #include "win32.h" @@ -98,7 +100,9 @@ static int oldleds, oldusedleds, newleds, oldusbleds; static int normalmouse, supermouse, rawmouse, winmouse, winmousenumber, winmousemode, winmousewheelbuttonstart; static int normalkb, superkb, rawkb; -int no_rawinput, dinput_enum_all; +int no_rawinput; +int rawkeyboard; +int dinput_enum_all; int dinput_winmouse (void) { @@ -194,27 +198,38 @@ static int rawinput_available, rawinput_registered; static void unregister_rawinput (void) { + rawinput_registered = 0; } static int register_rawinput (void) { - RAWINPUTDEVICE rid[1]; + int num; + RAWINPUTDEVICE rid[2]; if (!rawinput_available) return 0; memset (rid, 0, sizeof (rid)); + num = 0; /* mouse */ - rid[0].usUsagePage = 1; - rid[0].usUsage = 2; - rid[0].dwFlags = 0; -#if 0 + if (rawmouse) { + rid[num].usUsagePage = 1; + rid[num].usUsage = 2; + rid[num].dwFlags = RIDEV_INPUTSINK; + rid[num].hwndTarget = hAmigaWnd; + num++; + } /* keyboard */ - rid[1].usUsagePage = 1; - rid[1].usUsage = 6; - rid[1].dwFlags = 0; -#endif - - if (pRegisterRawInputDevices(rid, sizeof (rid) / sizeof (RAWINPUTDEVICE), sizeof (RAWINPUTDEVICE)) == FALSE) { + if (rawkb) { + rid[num].usUsagePage = 1; + rid[num].usUsage = 6; + rid[num].dwFlags = RIDEV_INPUTSINK; + rid[num].hwndTarget = hAmigaWnd; + num++; + } + if (!num) + return 0; + write_log ("%d\n", num); + if (pRegisterRawInputDevices(rid, num, sizeof (RAWINPUTDEVICE)) == FALSE) { write_log ("RAWINPUT registration failed %d\n", GetLastError ()); return 0; } @@ -222,7 +237,7 @@ static int register_rawinput (void) return 1; } -static void cleardid(struct didata *did) +static void cleardid (struct didata *did) { int i; memset (did, 0, sizeof (*did)); @@ -233,6 +248,106 @@ static void cleardid(struct didata *did) } } + +#define MAX_KEYCODES 256 +static uae_u8 di_keycodes[MAX_INPUT_DEVICES][MAX_KEYCODES]; +static int keyboard_german; + +static int keyhack (int scancode,int pressed, int num) +{ + static byte backslashstate,apostrophstate; + +#ifdef RETROPLATFORM + 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 && di_keycodes[num][DIK_LALT] && !currprefs.win32_ctrl_F11_is_quit) { +#ifdef RETROPLATFORM + if (rp_close ()) + return -1; +#endif + uae_quit (); + return -1; + } +#ifdef SINGLEFILE + 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; + } + + 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) + { + 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; +} + static int initialize_catweasel(void) { int j, i; @@ -311,6 +426,70 @@ static int rdpmouse(char *buf) return 0; } +static void rawinputfixname (const char *name, const char *friendlyname) +{ + int i, ii, j; + char tmp[MAX_DPATH]; + + sprintf (tmp, "\\\\?\\%s", name); + for (i = 4; i < strlen (tmp); i++) { + if (tmp[i] == '\\') + tmp[i] = '#'; + tmp[i] = toupper (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]; + char tmp2[MAX_DPATH]; + if (!did->rawinput) + continue; + for (j = 0; j < strlen (did->configname); j++) + tmp2[j] = toupper (did->configname[j]); + tmp2[j] = 0; + if (strlen (tmp2) >= strlen (tmp) && !memcmp (tmp2, tmp, strlen (tmp))) { + xfree (did->name); + xfree (did->sortname); + did->name = my_strdup (friendlyname); + did->sortname = my_strdup (friendlyname); + write_log ("'%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++) { + char buf[MAX_DPATH]; + DWORD size = 0; + if (SetupDiGetDeviceInstanceId (di, &dd, buf, sizeof buf , &size)) { + char 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 int initialize_rawinput (void) { RAWINPUTDEVICELIST *ridl = 0; @@ -379,7 +558,10 @@ static int initialize_rawinput (void) HANDLE h = ridl[i].hDevice; int type = ridl[i].dwType; - if (/* type == RIM_TYPEKEYBOARD || */ type == RIM_TYPEMOUSE) { + 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; @@ -403,7 +585,7 @@ static int initialize_rawinput (void) } else if (did == di_keyboard) { if (rnum_kb < 2) continue; - if (num_keyboard >= MAX_INPUT_DEVICES) + if (num_keyboard >= MAX_INPUT_DEVICES - 1) continue; did += num_keyboard; num_keyboard++; @@ -465,10 +647,13 @@ static int initialize_rawinput (void) write_log ("type=%d sub=%d mode=%d fkeys=%d indicators=%d tkeys=%d", rdik->dwType, rdik->dwSubType, rdik->dwKeyboardMode, rdik->dwNumberOfFunctionKeys, rdik->dwNumberOfIndicators, rdik->dwNumberOfKeysTotal); + } } } + rawinputfriendlynames (); + xfree (ridl); xfree (buf); if (rnum_raw > 0) @@ -555,9 +740,8 @@ static void handle_rawinput_2 (RAWINPUT *raw) rm->lLastY, rm->ulExtraInformation, num < num_mouse ? num + 1 : -1); #endif - if (num == num_mouse) { + if (num == num_mouse) return; - } if (focus) { if (mouseactive || isfullscreen () > 0) { @@ -594,7 +778,12 @@ static void handle_rawinput_2 (RAWINPUT *raw) } } else if (raw->header.dwType == RIM_TYPEKEYBOARD) { -#ifdef DI_DEBUG2 + 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) ? 1 : 0; + + #ifdef DI_DEBUG2 write_log ("HANDLE=%x CODE=%x Flags=%x VK=%x MSG=%x EXTRA=%x\n", raw->header.hDevice, raw->data.keyboard.MakeCode, @@ -603,6 +792,31 @@ static void handle_rawinput_2 (RAWINPUT *raw) raw->data.keyboard.Message, raw->data.keyboard.ExtraInformation); #endif + if (scancode == DIK_F12 && pressed) { + inputdevice_add_inputcode (AKS_ENTERGUI, 1); + return; + } + + for (num = 0; num < num_keyboard; num++) { + did = &di_keyboard[num]; + if (!did->disabled && did->rawinput == raw->header.hDevice) + break; + } + if (num == num_keyboard) + return; + if (scancode == 0xaa) + return; + if (!istest) + scancode = keyhack (scancode, pressed, num); + if (scancode < 0) + return; + di_keycodes[num][scancode] = pressed; + if (istest) { + inputdevice_do_keyboard (scancode, pressed); + } else { + if (stopoutput == 0) + my_kbd_handler (num, scancode, pressed); + } } } @@ -968,11 +1182,11 @@ static int di_do_init (void) IDirectInput8_EnumDevices (g_lpdi, DI8DEVCLASS_GAMECTRL, di_enumcallback, 0, DIEDFL_ATTACHEDONLY); } write_log ("RawInput enumeration..\n"); - initialize_rawinput(); + initialize_rawinput (); write_log ("Windowsmouse initialization..\n"); - initialize_windowsmouse(); + initialize_windowsmouse (); write_log ("Catweasel joymouse initialization..\n"); - initialize_catweasel(); + initialize_catweasel (); write_log ("end\n"); sortdd (di_joystick, num_joystick, DID_JOYSTICK); @@ -1173,6 +1387,7 @@ static void read_mouse (void) HRESULT hr; int i, j, k; int fs = isfullscreen() > 0 ? 1 : 0; + int istest = inputdevice_istest (); if (IGNOREEVERYTHING) return; @@ -1211,8 +1426,8 @@ static void read_mouse (void) #ifdef DI_DEBUG2 write_log ("MOUSE: %d OFF=%d DATA=%d STATE=%d\n", i, dimofs, data, state); #endif - if (focus) { - if (mouseactive || fs) { + if (istest || focus) { + if (istest || mouseactive || fs) { for (k = 0; k < did->axles; k++) { if (did->axismappings[k] == dimofs) setmousestate (i, k, data, 0); @@ -1239,7 +1454,7 @@ static void read_mouse (void) } } } - if (currprefs.win32_middle_mouse && dimofs == DIMOFS_BUTTON2 && state) { + if (!istest && currprefs.win32_middle_mouse && dimofs == DIMOFS_BUTTON2 && state) { if (isfullscreen () > 0) minimizewindow (); if (mouseactive) @@ -1309,8 +1524,6 @@ static int get_kb_widget_type (int kb, int num, char *name, uae_u32 *code) return IDEV_WIDGET_KEY; } -static int keyboard_german; - static BYTE ledkeystate[256]; static uae_u32 get_leds (void) @@ -1481,11 +1694,10 @@ static void close_kb (void) IDirectInputDevice8_Release (di_keyboard[i].lpdi); di_keyboard[i].lpdi = 0; } + superkb = normalkb = rawkb = 0; di_free (); } -#define MAX_KEYCODES 256 -static uae_u8 di_keycodes[MAX_INPUT_DEVICES][MAX_KEYCODES]; static uae_u32 kb_do_refresh; int ispressed (int key) @@ -1540,101 +1752,6 @@ static int refresh_kb (LPDIRECTINPUTDEVICE8 lpdi, int num) } -static int keyhack (int scancode,int pressed, int num) -{ - static byte backslashstate,apostrophstate; - -#ifdef RETROPLATFORM - 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 && di_keycodes[num][DIK_LALT] && !currprefs.win32_ctrl_F11_is_quit) { -#ifdef RETROPLATFORM - if (rp_close ()) - return -1; -#endif - uae_quit (); - return -1; - } -#ifdef SINGLEFILE - 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; - } - - 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) - { - 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; -} - static void read_kb (void) { DIDEVICEOBJECTDATA didod[DI_KBBUFFER]; @@ -1642,6 +1759,7 @@ static void read_kb (void) HRESULT hr; LPDIRECTINPUTDEVICE8 lpdi; int i, j; + int istest = inputdevice_istest (); if (IGNOREEVERYTHING) return; @@ -1667,12 +1785,17 @@ static void read_kb (void) for (j = 0; j < elements; j++) { int scancode = didod[j].dwOfs; int pressed = (didod[j].dwData & 0x80) ? 1 : 0; - scancode = keyhack (scancode, pressed, i); + if (!istest) + scancode = keyhack (scancode, pressed, i); if (scancode < 0) continue; di_keycodes[i][scancode] = pressed; - if (stopoutput == 0) - my_kbd_handler (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 (lpdi, "keyboard"); @@ -1774,12 +1897,16 @@ static int acquire_kb (int num, int flags) kb_do_refresh = ~0; di_keyboard[num].acquired = -1; if (acquire (lpdi, "keyboard")) { - if (di_keyboard[num].superdevice) + if (di_keyboard[num].rawinput) + rawkb++; + else if (di_keyboard[num].superdevice) superkb++; else normalkb++; di_keyboard[num].acquired = 1; } + if (rawkb) + register_rawinput (); return di_keyboard[num].acquired > 0 ? 1 : 0; } @@ -1789,7 +1916,9 @@ static void unacquire_kb (int num) unacquire (lpdi, "keyboard"); if (di_keyboard[num].acquired) { - if (di_keyboard[num].superdevice) + if (di_keyboard[num].rawinput) + rawkb--; + else if (di_keyboard[num].superdevice) superkb--; else normalkb--; diff --git a/od-win32/dxwrap.c b/od-win32/dxwrap.c index 1aa4b564..65d5579e 100755 --- a/od-win32/dxwrap.c +++ b/od-win32/dxwrap.c @@ -924,8 +924,6 @@ int DirectDraw_Start (GUID *guid) // dxdata.statusheight = TD_TOTAL_HEIGHT; dxdata.cursorwidth = 48; dxdata.cursorheight = 48; - dxdata.maxwidth = 16384; - dxdata.maxheight = 16384; if (!d3ddone) { d3dDLL = LoadLibrary ("D3D9.DLL"); if (d3dDLL) { diff --git a/od-win32/parser.c b/od-win32/parser.c index f7631d36..44cac415 100755 --- a/od-win32/parser.c +++ b/od-win32/parser.c @@ -47,6 +47,7 @@ #include "threaddep/thread.h" #include "serial.h" #include "savestate.h" +#include "ahidsound_new.h" #include #include @@ -1063,8 +1064,9 @@ void initparallel (void) uaecptr a = here (); //this install the ahisound org (rtarea_base + 0xFFC0); calltrap (deftrapres (ahi_demux, 0, "ahi_winuae")); - dw (0x4e75);// rts + dw (RTS); org (a); + init_ahi_v2 (); } } diff --git a/od-win32/posixemu.c b/od-win32/posixemu.c index 4aa5516d..28181339 100755 --- a/od-win32/posixemu.c +++ b/od-win32/posixemu.c @@ -226,7 +226,7 @@ struct thparms void *arg; }; -static unsigned __stdcall thread_init(void *f) +static unsigned __stdcall thread_init (void *f) { struct thparms *thp = f; void *(*fp)(void*) = thp->f; diff --git a/od-win32/resources/resource b/od-win32/resources/resource index 86ccddc9..65f83289 100755 --- a/od-win32/resources/resource +++ b/od-win32/resources/resource @@ -940,7 +940,8 @@ #define IDC_RTG_24BIT 1789 #define IDC_RTG_32BIT 1790 #define IDC_DD_SURFACETYPE 1791 -#define IDC_RTG_LEDS 1791 +#define IDC_RTG_SCALE_ALLOW 1791 +#define IDC_RTG_SCALE_ASPECTRATIO 1792 #define ID__FLOPPYDRIVES 40004 #define ID_FLOPPYDRIVES_DF0 40005 #define ID_ST_CONFIGURATION 40010 diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index 4624cf89..65f83289 100755 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -941,6 +941,7 @@ #define IDC_RTG_32BIT 1790 #define IDC_DD_SURFACETYPE 1791 #define IDC_RTG_SCALE_ALLOW 1791 +#define IDC_RTG_SCALE_ASPECTRATIO 1792 #define ID__FLOPPYDRIVES 40004 #define ID_FLOPPYDRIVES_DF0 40005 #define ID_ST_CONFIGURATION 40010 diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index bee92ccd..be90d711 100755 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -139,23 +139,26 @@ BEGIN RTEXT "Memory: [] Graphics card memory. Required for RTG (Picasso96) emulation.",IDC_GFXCARDTEXT,25,98,53,10,SS_NOTIFY | SS_CENTERIMAGE CONTROL "Slider1",IDC_P96MEM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,88,94,60,20 EDITTEXT IDC_P96RAM,152,97,34,12,ES_CENTER | ES_READONLY - GROUPBOX "Advanced Memory Settings",-1,13,171,275,65 - RTEXT "Motherboard RAM (Low area):",-1,39,190,129,10,SS_CENTERIMAGE - CONTROL "",IDC_MBMEM1,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,180,186,59,20 - EDITTEXT IDC_MBRAM1,243,189,34,12,ES_CENTER | ES_READONLY - RTEXT "Motherboard RAM (High area):",-1,39,215,129,10,SS_CENTERIMAGE - CONTROL "",IDC_MBMEM2,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,180,211,59,20 - EDITTEXT IDC_MBRAM2,243,214,34,12,ES_CENTER | ES_READONLY - GROUPBOX "RTG Graphics Card Settings",-1,14,81,275,87 + GROUPBOX "Advanced Memory Settings",-1,13,179,275,57 + RTEXT "Motherboard RAM (Low area):",-1,39,194,129,10,SS_CENTERIMAGE + CONTROL "",IDC_MBMEM1,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,180,190,59,20 + EDITTEXT IDC_MBRAM1,243,193,34,12,ES_CENTER | ES_READONLY + RTEXT "Motherboard RAM (High area):",-1,39,217,129,10,SS_CENTERIMAGE + CONTROL "",IDC_MBMEM2,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,180,213,59,20 + EDITTEXT IDC_MBRAM2,243,216,34,12,ES_CENTER | ES_READONLY + GROUPBOX "RTG Graphics Card Settings",-1,14,81,275,95 CONTROL "Scale if smaller than display size setting",IDC_RTG_SCALE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,134,162,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,128,162,10 CONTROL "Match host and RTG color depth if possible",IDC_RTG_MATCH_DEPTH, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,119,163,10 - COMBOBOX IDC_RTG_8BIT,211,101,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_RTG_16BIT,211,117,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_RTG_24BIT,211,133,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_RTG_32BIT,211,149,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP - CONTROL "Always scale in windowed mode",IDC_RTG_SCALE_ALLOW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,148,162,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,116,163,10 + COMBOBOX IDC_RTG_8BIT,211,107,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_RTG_16BIT,211,123,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_RTG_24BIT,211,139,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_RTG_32BIT,211,155,68,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP + CONTROL "Always scale in windowed mode",IDC_RTG_SCALE_ALLOW, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,140,162,10 + COMBOBOX IDC_RTG_SCALE_ASPECTRATIO,131,155,57,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP + RTEXT "Scale aspect ratio",-1,24,156,99,10,SS_CENTERIMAGE END IDD_CPU DIALOGEX 0, 0, 300, 226 diff --git a/od-win32/rp.c b/od-win32/rp.c index 3119a52a..514513bc 100755 --- a/od-win32/rp.c +++ b/od-win32/rp.c @@ -36,7 +36,7 @@ int rp_rpescapekey = 0x01; int rp_rpescapeholdtime = 600; int rp_screenmode = 0; int rp_inputmode = 0; -int log_rp = 0; +int log_rp = 1; static int max_horiz_dbl = RES_HIRES; static int max_vert_dbl = 1; @@ -222,7 +222,7 @@ static BOOL RPPostMessagex(UINT uMessage, WPARAM wParam, LPARAM lParam, const RP write_log ("RPPOST: pInfo == NULL!\n"); return FALSE; } - if (uMessage == RPIPCGM_DEVICESEEK) + if (uMessage == RPIPCGM_DEVICESEEK || uMessage == RPIPCGM_DEVICEACTIVITY) dolog = 0; recursive++; cnt++; diff --git a/od-win32/win32.c b/od-win32/win32.c index 0eb1c7c6..2de0252d 100755 --- a/od-win32/win32.c +++ b/od-win32/win32.c @@ -74,7 +74,7 @@ #include "rp.h" #endif -extern int harddrive_dangerous, do_rdbdump, aspi_allow_all, no_rawinput; +extern int harddrive_dangerous, do_rdbdump, aspi_allow_all, no_rawinput, rawkeyboard; int log_scsi, log_net, uaelib_debug; int pissoff_value = 25000; @@ -1904,6 +1904,7 @@ void target_default_options (struct uae_prefs *p, int type) p->win32_rtgmatchdepth = 1; p->win32_rtgscaleifsmall = 1; p->win32_rtgallowscaling = 0; + p->win32_rtgscaleaspectratio = -1; } if (type == 1 || type == 0) { p->win32_uaescsimode = get_aspi (p->win32_uaescsimode); @@ -1947,6 +1948,9 @@ void target_save_options (struct zfile *f, struct uae_prefs *p) cfgfile_target_dwrite (f, "rtg_match_depth=%s\n", p->win32_rtgmatchdepth ? "true" : "false" ); cfgfile_target_dwrite (f, "rtg_scale_small=%s\n", p->win32_rtgscaleifsmall ? "true" : "false" ); cfgfile_target_dwrite (f, "rtg_scale_allow=%s\n", p->win32_rtgallowscaling ? "true" : "false" ); + cfgfile_target_dwrite (f, "rtg_scale_aspect_ratio=%d:%d\n", + p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio >> 8) : -1, + p->win32_rtgscaleaspectratio >= 0 ? (p->win32_rtgscaleaspectratio & 0xff) : -1); cfgfile_target_dwrite (f, "borderless=%s\n", p->win32_borderless ? "true" : "false" ); cfgfile_target_dwrite (f, "uaescsimode=%s\n", scsimode[p->win32_uaescsimode]); cfgfile_target_dwrite (f, "soundcard=%d\n", p->win32_soundcard ); @@ -1980,6 +1984,7 @@ static const char *obsolete[] = { int target_parse_option (struct uae_prefs *p, char *option, char *value) { + char tmpbuf[CONFIG_BLEN]; int i, v; int result = (cfgfile_yesno (option, value, "middle_mouse", &p->win32_middle_mouse) || cfgfile_yesno (option, value, "map_drives", &p->win32_automount_drives) @@ -2023,6 +2028,25 @@ int target_parse_option (struct uae_prefs *p, char *option, char *value) return 1; } + if (cfgfile_string (option, value, "rtg_scale_aspect_ratio", tmpbuf, sizeof tmpbuf)) { + int v1, v2; + char *s; + + p->win32_rtgscaleaspectratio = -1; + v1 = atol (tmpbuf); + s = strchr (tmpbuf, ':'); + if (s) { + v2 = atol (s + 1); + if (v1 < 0 || v2 < 0) + p->win32_rtgscaleaspectratio = -1; + else if (v1 == 0 || v2 == 0) + p->win32_rtgscaleaspectratio = 0; + else + p->win32_rtgscaleaspectratio = (v1 << 8) | v2; + } + return 1; + } + if (cfgfile_strval (option, value, "uaescsimode", &p->win32_uaescsimode, scsimode, 0)) return 1; @@ -2963,6 +2987,10 @@ static int process_arg(char **xargv) no_rawinput = 1; continue; } + if (!strcmp (arg, "-rawkeyboard")) { + rawkeyboard = 1; + continue; + } if (!strcmp (arg, "-scsilog")) { log_scsi = 1; continue; @@ -3163,6 +3191,7 @@ static int PASCAL WinMain2 (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR enumeratedisplays (multi_display); write_log ("Sorting devices and modes..\n"); sortdisplays (); + write_log ("Display buffer mode = %d\n", ddforceram); write_log ("done\n"); memset (&devmode, 0, sizeof(devmode)); diff --git a/od-win32/win32.h b/od-win32/win32.h index ecbb38ed..56270753 100755 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -16,8 +16,8 @@ #define GETBDD(x) ((x) % 100) #define WINUAEBETA 1 -#define WINUAEPUBLICBETA 3 -#define WINUAEDATE MAKEBD(2008, 6, 28) +#define WINUAEPUBLICBETA 4 +#define WINUAEDATE MAKEBD(2008, 7, 2) #define WINUAEEXTRA "" #define WINUAEREV "" diff --git a/od-win32/win32gfx.c b/od-win32/win32gfx.c index 4d0b03fe..e05a7173 100755 --- a/od-win32/win32gfx.c +++ b/od-win32/win32gfx.c @@ -710,8 +710,23 @@ static void DX_Blit96 (int x, int y, int w, int h) if (scalepicasso) { int srcratio, dstratio; SetRect (&sr, 0, 0, picasso96_state.Width, picasso96_state.Height); - srcratio = picasso96_state.Width * 256 / picasso96_state.Height; - dstratio = currentmode->native_width * 256 / currentmode->native_height; + if (currprefs.win32_rtgscaleaspectratio < 0) { + // automatic + srcratio = picasso96_state.Width * 256 / picasso96_state.Height; + dstratio = currentmode->native_width * 256 / currentmode->native_height; + } else if (currprefs.win32_rtgscaleaspectratio == 0) { + // none + srcratio = dstratio = 0; + } else { + // manual + if (isfullscreen () == 0) { + dstratio = currentmode->native_width * 256 / currentmode->native_height; + srcratio = (currprefs.win32_rtgscaleaspectratio >> 8) * 256 / (currprefs.win32_rtgscaleaspectratio & 0xff); + } else { + srcratio = picasso96_state.Width * 256 / picasso96_state.Height; + dstratio = (currprefs.win32_rtgscaleaspectratio >> 8) * 256 / (currprefs.win32_rtgscaleaspectratio & 0xff); + } + } if (srcratio == dstratio) { SetRect (&dr, 0, 0, currentmode->native_width, currentmode->native_height); } else if (srcratio > dstratio) { @@ -996,6 +1011,7 @@ int check_prefs_changed_gfx (void) c |= currprefs.win32_rtgmatchdepth != changed_prefs.win32_rtgmatchdepth ? 2 : 0; c |= currprefs.win32_rtgscaleifsmall != changed_prefs.win32_rtgscaleifsmall ? 8 : 0; c |= currprefs.win32_rtgallowscaling != changed_prefs.win32_rtgallowscaling ? 8 : 0; + c |= currprefs.win32_rtgscaleaspectratio != changed_prefs.win32_rtgscaleaspectratio ? 8 : 0; if (display_change_requested || c) { @@ -1047,6 +1063,7 @@ int check_prefs_changed_gfx (void) 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; inputdevice_unacquire (); if ((c & 16) || ((c & 8) && keepfsmode)) { @@ -1775,13 +1792,15 @@ static int create_windows_2 (void) nw = rc.right - rc.left; nh = rc.bottom - rc.top; } + write_log ("%d %d %d %d\n", x, y, w, h); + write_log ("%d %d %d %d\n", nx, ny, nw, nh); if (w != nw || h != nh || x != nx || y != ny) { w = nw; h = nh; x = nx; y = ny; in_sizemove++; - if (hMainWnd && !fsw && !dxfs) { + if (hMainWnd && !fsw && !dxfs && !rp_isactive ()) { GetWindowRect (hMainWnd, &r); x = r.left; y = r.top; diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index 3dd8c59c..3a1100f4 100755 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -5223,6 +5223,7 @@ static void enable_for_memorydlg (HWND hDlg) 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); } static void values_to_memorydlg (HWND hDlg) @@ -5339,7 +5340,14 @@ static void values_to_memorydlg (HWND hDlg) 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); -// CheckDlgButton (hDlg, IDC_RTG_LEDS, (workprefs.leds_on_screen & STATUSLINE_RTG) ? 1 : 0); + //CheckDlgButton (hDlg, IDC_RTG_LEDS, (workprefs.leds_on_screen & STATUSLINE_RTG) ? 1 : 0); + + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_SETCURSEL, + (workprefs.win32_rtgscaleaspectratio == 0) ? 0 : + (workprefs.win32_rtgscaleaspectratio == 4 * 256 + 3) ? 2 : + (workprefs.win32_rtgscaleaspectratio == 15 * 256 + 9) ? 3 : + (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 9) ? 4 : + (workprefs.win32_rtgscaleaspectratio == 16 * 256 + 10) ? 5 : 1, 0); mem_size = 0; switch (workprefs.mbresmem_low_size) { @@ -5448,6 +5456,13 @@ static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA SendDlgItemMessage (hDlg, IDC_P96MEM, TBM_SETRANGE, TRUE, MAKELONG (MIN_P96_MEM, MAX_P96_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)); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"Disabled"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"Automatic"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"4:3"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"15:9"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"16:9"); + SendDlgItemMessage (hDlg, IDC_RTG_SCALE_ASPECTRATIO, CB_ADDSTRING, 0, (LPARAM)"16:10"); case WM_USER: recursive++; @@ -5497,6 +5512,23 @@ static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA 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 = 15 * 256 + 9; + if (v == 4) + workprefs.win32_rtgscaleaspectratio = 16 * 256 + 9; + if (v == 5) + 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) { @@ -9138,10 +9170,9 @@ static void init_inputdlg_2(HWND hDlg) } } -static void init_inputdlg( HWND hDlg ) +static void init_inputdlg (HWND hDlg) { int i; - DWORD size = sizeof(COMMCONFIG); char buf[100], txt[100]; SendDlgItemMessage (hDlg, IDC_INPUTTYPE, CB_RESETCONTENT, 0, 0L); @@ -9314,6 +9345,21 @@ static void input_swap (HWND hDlg) init_inputdlg (hDlg); } +#if 0 +static void input_copy (HWND hDlg) +{ + char 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; @@ -9323,6 +9369,7 @@ static void input_copy (HWND hDlg) inputdevice_copy_single_config (&workprefs, (int)src, workprefs.input_selected_setting, input_selected_device); init_inputdlg (hDlg); } +#endif static void input_toggleautofire (void) { diff --git a/od-win32/winuaechangelog.txt b/od-win32/winuaechangelog.txt index 5d054619..b83923ad 100755 --- a/od-win32/winuaechangelog.txt +++ b/od-win32/winuaechangelog.txt @@ -1,4 +1,16 @@ +Beta 4: + +- input panel custom events in slots 2+ were not saved if previous + slot was empty +- debugger memwatch points were still broken in byte and word modes +- debugger movem was disassembled incorrectly (wrong source/dest + address shown) if addressing mode was not address register relative +- raw mouse friendly names added (was easier said than done..), + defaults to old-style "RAW Mouse" if name can't be found +- directdraw max surface size driver workaround fixed +- game Lancaster ce-mode blank-screen tweak + Beta 3: - corrected directinput keyboard enumeration, possible fix for diff --git a/uaeresource.c b/uaeresource.c index 13269897..397a595e 100755 --- a/uaeresource.c +++ b/uaeresource.c @@ -37,11 +37,11 @@ #endif -static uaecptr res_init, res_name, res_id; +static uaecptr res_init, res_name, res_id, base; -static uae_u32 REGPARAM2 res_getfunc (TrapContext *context) +static uae_u32 REGPARAM2 res_getfunc (TrapContext *ctx) { - uaecptr funcname = m68k_areg (&context->regs, 0); + uaecptr funcname = m68k_areg (&ctx->regs, 0); char tmp[256]; if (funcname == 0) return 0; @@ -49,10 +49,11 @@ static uae_u32 REGPARAM2 res_getfunc (TrapContext *context) return find_trap (tmp); } -static uae_u32 REGPARAM2 res_initcode (TrapContext *context) +static uae_u32 REGPARAM2 res_initcode (TrapContext *ctx) { - uaecptr base = m68k_dreg (&context->regs, 0); - uaecptr rb = base + SIZEOF_LIBRARY; + uaecptr rb; + base = m68k_dreg (&ctx->regs, 0); + rb = base + SIZEOF_LIBRARY; put_word (rb + 0, UAEMAJOR); put_word (rb + 2, UAEMINOR); put_word (rb + 4, UAESUBREV); diff --git a/zfile.c b/zfile.c index 129816de..094d5982 100755 --- a/zfile.c +++ b/zfile.c @@ -129,6 +129,8 @@ int zfile_gettype (struct zfile *z) return ZFILE_DISKIMAGE; if (!memcmp (buf, "RDSK", 4)) return ZFILE_HDFRDB; + if (!memcmp (buf, "DOS", 3)) + return ZFILE_HDF; if (ext != NULL) { if (strcasecmp (ext, "hdf") == 0) return ZFILE_HDF; -- 2.47.3