mcd, fixes for msu

This commit is contained in:
kub 2023-05-30 22:07:56 +00:00
parent 02f3222feb
commit 411b2c1949
3 changed files with 62 additions and 30 deletions

View file

@ -665,10 +665,29 @@ 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 (PicoIn.opt & POPT_EN_MCD_RAMCART) {
if ((a & 0xf00001) == 0x400001) {
if (Pico.sv.data != NULL)
d = 3; // 64k cart
@ -683,6 +702,7 @@ static u32 PicoReadM68k8_ramc(u32 a)
if ((a & 0xf00001) == 0x700001)
return Pico_mcd->m.bcram_reg;
}
elprintf(EL_UIO, "m68k unmapped r8 [%06x] @%06x", a, SekPc);
return d;
@ -690,14 +710,13 @@ 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 (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;
@ -710,6 +729,7 @@ static void PicoWriteM68k8_ramc(u32 a, u32 d)
Pico_mcd->m.bcram_reg = d;
return;
}
}
elprintf(EL_UIO, "m68k unmapped w8 [%06x] %02x @%06x",
a, d & 0xff, SekPc);
@ -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);

View file

@ -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

View file

@ -384,6 +384,7 @@ enum media_type_e PicoLoadMedia(const char *filename,
media_type = PM_BAD_CD;
goto out;
}
if (Pico.romsize <= 0x20000)
Pico.m.ncart_in = 1;
}