From cc5ffc3cbe03715710a2adf6a8829f082fa7a819 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 3 Sep 2013 04:11:50 +0300 Subject: [PATCH] cd: fix breakage in comm detection --- pico/cd/mcd.c | 8 ++++-- pico/cd/memory.c | 24 ++++++++-------- pico/cd/memory_arm.s | 67 ++++++++++++++++++++++++-------------------- 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 8b807d30..0157bb56 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -45,8 +45,6 @@ PICO_INTERNAL void PicoPowerMCD(void) Pico_mcd->m.state_flags = PCD_ST_S68K_RST; Pico_mcd->m.busreq = 2; // busreq on, s68k in reset Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode, m68k access - Pico_mcd->s68k_regs[6] = 0xff; - Pico_mcd->s68k_regs[7] = 0xff; memset(Pico_mcd->bios + 0x70, 0xff, 4); } @@ -265,7 +263,9 @@ static void SekSyncM68k(void); static inline void pcd_run_cpus_normal(int m68k_cycles) { SekCycleAim += m68k_cycles; - if (Pico_mcd->m.m68k_poll_cnt >= 16 && !SekShouldInterrupt()) { + if (SekShouldInterrupt()) + Pico_mcd->m.m68k_poll_cnt = 0; + else if (Pico_mcd->m.m68k_poll_cnt >= 16) { int s68k_left = pcd_sync_s68k(SekCycleAim, 1); if (s68k_left <= 0) { elprintf(EL_CDPOLL, "m68k poll [%02x] x%d @%06x", @@ -287,6 +287,8 @@ static inline void pcd_run_cpus_lockstep(int m68k_cycles) SekSyncM68k(); pcd_sync_s68k(SekCycleAim, 0); } while (CYCLES_GT(target, SekCycleAim)); + + SekCycleAim = target; } #define PICO_CD diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 1064b91c..4b4c18f8 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -72,16 +72,15 @@ static void remap_word_ram(u32 r3); #define POLL_LIMIT 16 #define POLL_CYCLES 124 -u32 m68k_comm_check(u32 a, u32 d) +void m68k_comm_check(u32 a) { pcd_sync_s68k(SekCyclesDone(), 0); if (a != Pico_mcd->m.m68k_poll_a) { Pico_mcd->m.m68k_poll_a = a; Pico_mcd->m.m68k_poll_cnt = 0; - return d; + return; } Pico_mcd->m.m68k_poll_cnt++; - return d; } #ifndef _ASM_CD_MEMORY_C @@ -97,9 +96,10 @@ static u32 m68k_reg_read16(u32 a) | Pico_mcd->m.busreq; goto end; case 2: + m68k_comm_check(a); d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7); elprintf(EL_CDREG3, "m68k_regs r3: %02x @%06x", (u8)d, SekPc); - goto end_comm; + goto end; case 4: d = Pico_mcd->s68k_regs[4]<<8; goto end; @@ -123,17 +123,15 @@ static u32 m68k_reg_read16(u32 a) if (a < 0x30) { // comm flag/cmd/status (0xE-0x2F) + m68k_comm_check(a); d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1]; - goto end_comm; + goto end; } elprintf(EL_UIO, "m68k_regs FIXME invalid read @ %02x", a); end: return d; - -end_comm: - return m68k_comm_check(a, d); } #endif @@ -259,7 +257,7 @@ u32 s68k_poll_detect(u32 a, u32 d) //printf("-- diff: %u, cnt = %i\n", clkdiff, cnt); if (Pico_mcd->m.s68k_poll_cnt > POLL_LIMIT) { SekSetStopS68k(1); - elprintf(EL_CDPOLL, "s68k poll detected @ %06x, a=%02x", + elprintf(EL_CDPOLL, "s68k poll detected @%06x, a=%02x", SekPcS68k, a); } } @@ -820,7 +818,7 @@ static u32 PicoReadS68k8_pr(u32 a) regs_done: d &= 0xff; - elprintf(EL_CDREGS, "s68k_regs r8: [%02x] %02x @ %06x", + elprintf(EL_CDREGS, "s68k_regs r8: [%02x] %02x @%06x", a, d, SekPcS68k); return d; } @@ -854,7 +852,7 @@ static u32 PicoReadS68k16_pr(u32 a) d = gfx_cd_read(a); else d = s68k_reg_read16(a); - elprintf(EL_CDREGS, "s68k_regs r16: [%02x] %04x @ %06x", + elprintf(EL_CDREGS, "s68k_regs r16: [%02x] %04x @%06x", a, d, SekPcS68k); return d; } @@ -882,7 +880,7 @@ static void PicoWriteS68k8_pr(u32 a, u32 d) // regs if ((a & 0xfe00) == 0x8000) { a &= 0x1ff; - elprintf(EL_CDREGS, "s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k); + elprintf(EL_CDREGS, "s68k_regs w8: [%02x] %02x @%06x", a, d, SekPcS68k); if (0x58 <= a && a < 0x68) gfx_cd_write16(a&~1, (d<<8)|d); else s68k_reg_write8(a,d); @@ -907,7 +905,7 @@ static void PicoWriteS68k16_pr(u32 a, u32 d) // regs if ((a & 0xfe00) == 0x8000) { a &= 0x1fe; - elprintf(EL_CDREGS, "s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k); + elprintf(EL_CDREGS, "s68k_regs w16: [%02x] %04x @%06x", a, d, SekPcS68k); if (a >= 0x58 && a < 0x68) gfx_cd_write16(a, d); else { diff --git a/pico/cd/memory_arm.s b/pico/cd/memory_arm.s index 2fc74ca0..380258c9 100644 --- a/pico/cd/memory_arm.s +++ b/pico/cd/memory_arm.s @@ -174,16 +174,14 @@ m_m68k_read8_r02: add r1, r1, #0x110000 ldrb r0, [r1, #2] bx lr -m_m68k_read8_r03: @ FIXME: sync with C - add r2, r1, #0x110000 - ldrb r1, [r2, #3] - add r2, r2, #0x002200 - ldr r2, [r2, #4] - and r1, r1, #0xc7 - tst r2, #2 @ DMNA pending? - bicne r1, r1, #1 - orrne r1, r1, #2 - b m68k_comm_check +m_m68k_read8_r03: + add r1, r1, #0x110000 + push {r1, lr} + bl m68k_comm_check + pop {r1, lr} + ldrb r0, [r1, #3] + and r0, r0, #0xc7 + bx lr m_m68k_read8_r04: add r1, r1, #0x110000 ldrb r0, [r1, #4] @@ -216,11 +214,15 @@ m_m68k_read8_r0d: bx lr m_m68k_read8_hi: cmp r0, #0x30 - movge r0, #0 - bxeq lr add r1, r1, #0x110000 - ldrb r1, [r1, r0] - b m68k_comm_check + movge r0, #0 + bxge lr + add r1, r0 + push {r1, lr} + bl m68k_comm_check + pop {r1, lr} + ldrb r0, [r1] + bx lr @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -269,18 +271,16 @@ m_m68k_read16_r00: and r0, r0, #0x04000000 @ we need irq2 mask state orr r0, r1, r0, lsr #11 bx lr -m_m68k_read16_r02: @ FIXME: out of sync from C - add r3, r1, #0x110000 - ldrb r1, [r3, #2] - ldrb r2, [r3, #3] - add r3, r3, #0x002200 - ldr r3, [r3, #4] +m_m68k_read16_r02: + add r1, r1, #0x110000 + push {r1, lr} + bl m68k_comm_check + pop {r1, lr} + ldrb r2, [r1, #3] + ldrb r0, [r1, #2] and r2, r2, #0xc7 - orr r1, r2, r1, lsl #8 - tst r3, #2 @ DMNA pending? - bicne r1, r1, #1 - orrne r1, r1, #2 - b m68k_comm_check + orr r0, r2, r0, lsl #8 + bx lr m_m68k_read16_r04: add r1, r1, #0x110000 ldrb r0, [r1, #4] @@ -300,14 +300,19 @@ m_m68k_read16_r0c: bx lr m_m68k_read16_hi: cmp r0, #0x30 - addlt r1, r1, #0x110000 - ldrlth r1, [r1, r0] + add r1, r1, #0x110000 movge r0, #0 bxge lr - mov r2, r1, lsr #8 - and r1, r1, #0xff - orr r1, r2, r1, lsl #8 - b m68k_comm_check + + add r1, r0, r1 + push {r1, lr} + bl m68k_comm_check + pop {r0, lr} + ldrh r0, [r0] + mov r1, r0, lsr #8 + and r0, r0, #0xff + orr r0, r1, r0, lsl #8 + bx lr @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -- 2.39.5