From 411b2c19499ec1d41e15954d1019536e9949360f Mon Sep 17 00:00:00 2001 From: kub Date: Tue, 30 May 2023 22:07:56 +0000 Subject: [PATCH] mcd, fixes for msu --- pico/cd/memory.c | 76 +++++++++++++++++++++++++++++--------------- pico/cd/memory_arm.S | 13 ++++++-- pico/media.c | 3 +- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 87bbc252..4aa1abc4 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -665,24 +665,44 @@ static void PicoWriteM68k16_cell1(u32 a, u32 d) } #endif +// BIOS faking for MSU-MD, checks for "SEGA" at 0x400100 to detect CD drive +static u8 bios_id[4] = "SEGA"; + +static u32 PicoReadM68k8_bios(u32 a) +{ + if ((a & 0xfffffc) == BASE+0x100) // CD detection by MSU + return bios_id[a&3]; + return 0; +} + +static u32 PicoReadM68k16_bios(u32 a) +{ + if ((a & 0xfffffc) == BASE+0x100) // CD detection by MSU + return (bios_id[a&2]<<8) | bios_id[(a&2)+1]; + return 0; +} + // RAM cart (400000 - 7fffff, optional) static u32 PicoReadM68k8_ramc(u32 a) { u32 d = 0; - if ((a & 0xf00001) == 0x400001) { - if (Pico.sv.data != NULL) - d = 3; // 64k cart - return d; - } - if ((a & 0xf00001) == 0x600001) { - if (Pico.sv.data != NULL) - d = Pico.sv.data[((a >> 1) & 0xffff) + 0x2000]; - return d; - } + if (PicoIn.opt & POPT_EN_MCD_RAMCART) { + if ((a & 0xf00001) == 0x400001) { + if (Pico.sv.data != NULL) + d = 3; // 64k cart + return d; + } + + if ((a & 0xf00001) == 0x600001) { + if (Pico.sv.data != NULL) + d = Pico.sv.data[((a >> 1) & 0xffff) + 0x2000]; + return d; + } - if ((a & 0xf00001) == 0x700001) - return Pico_mcd->m.bcram_reg; + if ((a & 0xf00001) == 0x700001) + return Pico_mcd->m.bcram_reg; + } elprintf(EL_UIO, "m68k unmapped r8 [%06x] @%06x", a, SekPc); return d; @@ -690,25 +710,25 @@ static u32 PicoReadM68k8_ramc(u32 a) static u32 PicoReadM68k16_ramc(u32 a) { - elprintf(EL_ANOMALY, "ramcart r16: [%06x] @%06x", a, SekPcS68k); - if ((a & 0xfffffc) == BASE+0x100) // CD detection by MSU - return (~a & 2) ? 0x5345 : 0x4741; // "SEGA" + elprintf(EL_ANOMALY, "ramcart r16: [%06x] @%06x", a, SekPc); return PicoReadM68k8_ramc(a + 1); } static void PicoWriteM68k8_ramc(u32 a, u32 d) { - if ((a & 0xf00001) == 0x600001) { - if (Pico.sv.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { - Pico.sv.data[((a >> 1) & 0xffff) + 0x2000] = d; - Pico.sv.changed = 1; + if (PicoIn.opt & POPT_EN_MCD_RAMCART) { + if ((a & 0xf00001) == 0x600001) { + if (Pico.sv.data != NULL && (Pico_mcd->m.bcram_reg & 1)) { + Pico.sv.data[((a >> 1) & 0xffff) + 0x2000] = d; + Pico.sv.changed = 1; + } + return; } - return; - } - if ((a & 0xf00001) == 0x700001) { - Pico_mcd->m.bcram_reg = d; - return; + if ((a & 0xf00001) == 0x700001) { + Pico_mcd->m.bcram_reg = d; + return; + } } elprintf(EL_UIO, "m68k unmapped w8 [%06x] %02x @%06x", @@ -1210,9 +1230,13 @@ PICO_INTERNAL void PicoMemSetupCD(void) // setup default main68k map PicoMemSetup(); - // main68k map (BIOS mapped by PicoMemSetup()): + // main68k map (BIOS or MSU mapped by PicoMemSetup()): + if (Pico.romsize > 0x20000) { + // MSU cartridge. Fake BIOS detection + cpu68k_map_set(m68k_read8_map, 0x400000, 0x41ffff, PicoReadM68k8_bios, 1); + cpu68k_map_set(m68k_read16_map, 0x400000, 0x41ffff, PicoReadM68k16_bios, 1); // RAM cart - if (PicoIn.opt & POPT_EN_MCD_RAMCART) { + } else { cpu68k_map_set(m68k_read8_map, 0x400000, 0x7fffff, PicoReadM68k8_ramc, 1); cpu68k_map_set(m68k_read16_map, 0x400000, 0x7fffff, PicoReadM68k16_ramc, 1); cpu68k_map_set(m68k_write8_map, 0x400000, 0x7fffff, PicoWriteM68k8_ramc, 1); diff --git a/pico/cd/memory_arm.S b/pico/cd/memory_arm.S index 68bd48b8..810fe747 100644 --- a/pico/cd/memory_arm.S +++ b/pico/cd/memory_arm.S @@ -165,9 +165,13 @@ PicoRead8_mcd_io: PIC_BT(m_m68k_read8_r0d) m_m68k_read8_r00: add r1, r1, #0x110000 - ldr r0, [r1, #0x30] + ldr r0, [r1, #0x30] @ Pico_mcd->s68k_regs + add r1, r1, #0x002200 + ldr r1, [r1, #4] @ Pico_mcd->m.state_flags and r0, r0, #0x04000000 @ we need irq2 mask state mov r0, r0, lsr #19 + and r1, r1, #0x00000100 @ irq2 pending + orr r0, r0, r1, lsr #8 bx lr m_m68k_read8_r01: add r1, r1, #0x110000 @@ -271,9 +275,12 @@ m_m68k_read16_r00: add r1, r1, #0x110000 ldr r0, [r1, #0x30] add r1, r1, #0x002200 - ldrb r1, [r1, #2] @ Pico_mcd->m.busreq + ldrb r2, [r1, #2] @ Pico_mcd->m.busreq + ldr r1, [r1, #4] and r0, r0, #0x04000000 @ we need irq2 mask state - orr r0, r1, r0, lsr #11 + orr r0, r2, r0, lsr #11 + and r1, r1, #0x00000100 @ irq2 pending + orr r0, r1, r0 bx lr m_m68k_read16_r02: add r1, r1, #0x110000 diff --git a/pico/media.c b/pico/media.c index fd33f476..27f0c14c 100644 --- a/pico/media.c +++ b/pico/media.c @@ -384,7 +384,8 @@ enum media_type_e PicoLoadMedia(const char *filename, media_type = PM_BAD_CD; goto out; } - Pico.m.ncart_in = 1; + if (Pico.romsize <= 0x20000) + Pico.m.ncart_in = 1; } if (PicoIn.quirks & PQUIRK_FORCE_6BTN) -- 2.39.5