From ecc8036ee27ec57454c3fe736a71dd9c0cbcf3de Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 8 Sep 2013 16:43:54 +0300 Subject: [PATCH] handle dbra wait loops, update cyclone --- cpu/cyclone | 2 +- cpu/cyclone_config.h | 2 +- cpu/fame/fame.h | 4 ++++ cpu/fame/famec_opcodes.h | 36 ++++++++++++++++++++++++++++++++++++ cpu/musashi/m68kcpu.c | 2 ++ cpu/musashi/m68kcpu.h | 1 + pico/32x/memory.c | 10 ++-------- pico/cd/memory.c | 6 ++++-- pico/pico_int.h | 9 +++++++++ 9 files changed, 60 insertions(+), 12 deletions(-) diff --git a/cpu/cyclone b/cpu/cyclone index 7ddcd35..590d780 160000 --- a/cpu/cyclone +++ b/cpu/cyclone @@ -1 +1 @@ -Subproject commit 7ddcd35c8b2a8248257bd89ef989095639c29c08 +Subproject commit 590d780f20871b29fdc803bd2c74b046fd2d0f28 diff --git a/cpu/cyclone_config.h b/cpu/cyclone_config.h index 7f9690d..13e2c5e 100644 --- a/cpu/cyclone_config.h +++ b/cpu/cyclone_config.h @@ -10,7 +10,7 @@ #define USE_MS_SYNTAX 0 #define CYCLONE_FOR_GENESIS 2 -#define COMPRESS_JUMPTABLE 1 +#define COMPRESS_JUMPTABLE 0 #define MEMHANDLERS_ADDR_MASK 0 #define MEMHANDLERS_NEED_PC 0 diff --git a/cpu/fame/fame.h b/cpu/fame/fame.h index d534924..111af88 100644 --- a/cpu/fame/fame.h +++ b/cpu/fame/fame.h @@ -125,6 +125,7 @@ typedef struct unsigned int Opcode; signed int cycles_needed; + unsigned short *PC; unsigned long BasePC; unsigned int flag_C; @@ -136,6 +137,9 @@ typedef struct unsigned int flag_S; unsigned int flag_I; + unsigned char not_polling; + unsigned char pad[3]; + unsigned long Fetch[M68K_FETCHBANK1]; } M68K_CONTEXT; diff --git a/cpu/fame/famec_opcodes.h b/cpu/fame/famec_opcodes.h index 5e09a92..c690b45 100644 --- a/cpu/fame/famec_opcodes.h +++ b/cpu/fame/famec_opcodes.h @@ -1,4 +1,10 @@ +#ifdef PICODRIVE_HACK +#define NOT_POLLING g_m68kcontext->not_polling = 1; +#else +#define NOT_POLLING +#endif + // ORI OPCODE(0x0000) { @@ -23298,6 +23304,8 @@ OPCODE(0x51C8) u32 adr, res; u32 src, dst; + NOT_POLLING + res = DREGu16((Opcode >> 0) & 7); res--; DREGu16((Opcode >> 0) & 7) = res; @@ -23321,6 +23329,8 @@ OPCODE(0x52C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if ((!flag_NotZ) || (flag_C & 0x100)) { res = DREGu16((Opcode >> 0) & 7); @@ -23352,6 +23362,8 @@ OPCODE(0x53C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_NotZ && (!(flag_C & 0x100))) { res = DREGu16((Opcode >> 0) & 7); @@ -23383,6 +23395,8 @@ OPCODE(0x54C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_C & 0x100) { res = DREGu16((Opcode >> 0) & 7); @@ -23414,6 +23428,8 @@ OPCODE(0x55C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (!(flag_C & 0x100)) { res = DREGu16((Opcode >> 0) & 7); @@ -23445,6 +23461,8 @@ OPCODE(0x56C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (!flag_NotZ) { res = DREGu16((Opcode >> 0) & 7); @@ -23476,6 +23494,8 @@ OPCODE(0x57C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_NotZ) { res = DREGu16((Opcode >> 0) & 7); @@ -23507,6 +23527,8 @@ OPCODE(0x58C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_V & 0x80) { res = DREGu16((Opcode >> 0) & 7); @@ -23538,6 +23560,8 @@ OPCODE(0x59C8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (!(flag_V & 0x80)) { res = DREGu16((Opcode >> 0) & 7); @@ -23569,6 +23593,8 @@ OPCODE(0x5AC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_N & 0x80) { res = DREGu16((Opcode >> 0) & 7); @@ -23600,6 +23626,8 @@ OPCODE(0x5BC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (!(flag_N & 0x80)) { res = DREGu16((Opcode >> 0) & 7); @@ -23631,6 +23659,8 @@ OPCODE(0x5CC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if ((flag_N ^ flag_V) & 0x80) { res = DREGu16((Opcode >> 0) & 7); @@ -23662,6 +23692,8 @@ OPCODE(0x5DC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (!((flag_N ^ flag_V) & 0x80)) { res = DREGu16((Opcode >> 0) & 7); @@ -23693,6 +23725,8 @@ OPCODE(0x5EC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if ((!flag_NotZ) || ((flag_N ^ flag_V) & 0x80)) { res = DREGu16((Opcode >> 0) & 7); @@ -23724,6 +23758,8 @@ OPCODE(0x5FC8) u32 adr, res; u32 src, dst; + NOT_POLLING + if (flag_NotZ && (!((flag_N ^ flag_V) & 0x80))) { res = DREGu16((Opcode >> 0) & 7); diff --git a/cpu/musashi/m68kcpu.c b/cpu/musashi/m68kcpu.c index d766eb5..72bb217 100644 --- a/cpu/musashi/m68kcpu.c +++ b/cpu/musashi/m68kcpu.c @@ -832,6 +832,8 @@ int m68k_execute(int num_cycles) m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */ m68ki_trace_t1(); /* notaz */ + + m68ki_cpu_p->not_polling = 1; } // while(GET_CYCLES() > 0); // notaz /* set previous PC to current PC for the next entry into the loop */ diff --git a/cpu/musashi/m68kcpu.h b/cpu/musashi/m68kcpu.h index 7b050f7..83e92c5 100644 --- a/cpu/musashi/m68kcpu.h +++ b/cpu/musashi/m68kcpu.h @@ -919,6 +919,7 @@ typedef struct // notaz sint cyc_remaining_cycles; + sint not_polling; } m68ki_cpu_core; // notaz diff --git a/pico/32x/memory.c b/pico/32x/memory.c index fd902dd..722698e 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -65,7 +65,7 @@ static int m68k_poll_detect(u32 a, u32 cycles, u32 flags) int ret = 0; if (a - 2 <= m68k_poll.addr && m68k_poll.addr <= a + 2 - && cycles - m68k_poll.cycles <= 64) + && cycles - m68k_poll.cycles <= 64 && !SekNotPolling) { if (m68k_poll.cnt++ > POLL_THRESHOLD) { if (!(Pico32x.emu_flags & flags)) { @@ -79,6 +79,7 @@ static int m68k_poll_detect(u32 a, u32 cycles, u32 flags) else { m68k_poll.cnt = 0; m68k_poll.addr = a; + SekNotPolling = 0; } m68k_poll.cycles = cycles; @@ -186,15 +187,9 @@ static u32 p32x_reg_read16(u32 a) return sh2_comm_faker(a); #else if ((a & 0x30) == 0x20) { - static u32 dr2 = 0; unsigned int cycles = SekCyclesDone(); int comreg = 1 << (a & 0x0f) / 2; - // evil X-Men proto polls in a dbra loop and expects it to expire.. - if (SekDar(2) != dr2) - m68k_poll.cnt = 0; - dr2 = SekDar(2); - if (cycles - msh2.m68krcycles_done > 244 || (Pico32x.comm_dirty_68k & comreg)) p32x_sync_sh2s(cycles); @@ -205,7 +200,6 @@ static u32 p32x_reg_read16(u32 a) SekSetStop(1); SekEndRun(16); } - dr2 = SekDar(2); goto out; } #endif diff --git a/pico/cd/memory.c b/pico/cd/memory.c index b15e9c8..47553f5 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -75,9 +75,10 @@ static void remap_word_ram(u32 r3); void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); - if (a != Pico_mcd->m.m68k_poll_a) { + if (SekNotPolling || a != Pico_mcd->m.m68k_poll_a) { Pico_mcd->m.m68k_poll_a = a; Pico_mcd->m.m68k_poll_cnt = 0; + SekNotPolling = 0; return; } Pico_mcd->m.m68k_poll_cnt++; @@ -246,7 +247,7 @@ u32 s68k_poll_detect(u32 a, u32 d) return d; cycles = SekCyclesDoneS68k(); - if (a == Pico_mcd->m.s68k_poll_a) { + if (!SekNotPolling && a == Pico_mcd->m.s68k_poll_a) { u32 clkdiff = cycles - Pico_mcd->m.s68k_poll_clk; if (clkdiff <= POLL_CYCLES) { cnt = Pico_mcd->m.s68k_poll_cnt + 1; @@ -261,6 +262,7 @@ u32 s68k_poll_detect(u32 a, u32 d) Pico_mcd->m.s68k_poll_a = a; Pico_mcd->m.s68k_poll_clk = cycles; Pico_mcd->m.s68k_poll_cnt = cnt; + SekNotPollingS68k = 0; #endif return d; } diff --git a/pico/pico_int.h b/pico/pico_int.h index 6096e13..3a530ca 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -51,6 +51,9 @@ extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k; #define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1) #define SekShouldInterrupt() (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7)) +#define SekNotPolling PicoCpuCM68k.not_pol +#define SekNotPollingS68k PicoCpuCS68k.not_pol + #define SekInterrupt(i) PicoCpuCM68k.irq=i #define SekIrqLevel PicoCpuCM68k.irq @@ -79,6 +82,9 @@ extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k; #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED) #define SekShouldInterrupt() fm68k_would_interrupt() +#define SekNotPolling PicoCpuFM68k.not_polling +#define SekNotPollingS68k PicoCpuFS68k.not_polling + #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq #define SekIrqLevel PicoCpuFM68k.interrupts[0] @@ -108,6 +114,9 @@ extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k; #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP) #define SekShouldInterrupt() (CPU_INT_LEVEL > FLAG_INT_MASK) +#define SekNotPolling PicoCpuMM68k.not_polling +#define SekNotPollingS68k PicoCpuMS68k.not_polling + #define SekInterrupt(irq) { \ void *oldcontext = m68ki_cpu_p; \ m68k_set_context(&PicoCpuMM68k); \ -- 2.39.2