Skip to content

Commit

Permalink
mcd, some fixes for msu/md+
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Dec 20, 2024
1 parent 9ca608b commit a0ddd24
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
56 changes: 27 additions & 29 deletions pico/cd/megasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ static void cdd_play(s32 lba)
Pico_msd.currentlba = lba;

cdd_play_audio(Pico_msd.index, Pico_msd.currentlba);
Pico_msd.state = 3;
Pico_msd.state |= MSD_ST_PLAY;
}

static void cdd_pause(void)
{
Pico_msd.state |= 4;
Pico_msd.state |= MSD_ST_PAUSE;
}

static void cdd_resume(void)
{
Pico_msd.state &= ~4;
Pico_msd.state &= ~MSD_ST_PAUSE;
}

static void cdd_stop(void)
{
Pico_msd.index = -1;
Pico_msd.state &= ~6;
Pico_msd.state &= ~(MSD_ST_PAUSE | MSD_ST_PLAY);
}

// play a track, looping from offset if enabled
Expand Down Expand Up @@ -121,19 +121,15 @@ static void msd_playsectors(s32 startlba, s32 endlba, s32 looplba, int loop)
void msd_update()
{
if (Pico_msd.state && Pico_msd.index >= 0) {
// CD LEDs

if (Pico_msd.state & 2) {
s68k_write8(0xff8000, 0x3);
if (Pico_msd.state & MSD_ST_PLAY) {
Pico_msd.command = 0;
if (!(Pico_msd.state & 4))
if (!(Pico_msd.state & MSD_ST_PAUSE))
Pico_msd.currentlba ++;
if (Pico_msd.currentlba >= Pico_msd.endlba-1) {
if (!Pico_msd.loop || Pico_msd.index < 0) {
Pico_msd.state = 1;
Pico_msd.state &= MSD_ST_INIT;
// audio done
Pico_msd.index = -1;
s68k_write8(0xff8000, 0x2);
} else
cdd_play(Pico_msd.looplba);
}
Expand All @@ -159,7 +155,7 @@ void msd_process(u16 d)
case 0x14: cdd_resume();
Pico_msd.command = 0; break;

case 0x16: Pico_msd.result = !!(Pico_msd.state & 2) << 8;
case 0x16: Pico_msd.result = !!(Pico_msd.state & MSD_ST_PLAY) << 8;
Pico_msd.command = 0; break;

case 0x27: Pico_msd.result = cdd.toc.last << 8;
Expand All @@ -173,25 +169,20 @@ void msd_process(u16 d)
// initialize MEGASD
static void msd_init(void)
{
if (!(Pico_msd.state & 1)) {
Pico_msd.state = 1;
if (!(Pico_msd.state & MSD_ST_INIT)) {
Pico_msd.state = MSD_ST_INIT;
Pico_msd.index = -1;

// CD LEDs
s68k_write8(0xff8000, 0x2);

PicoResetHook = msd_reset;
}
}

void msd_reset(void)
{
if (Pico_msd.state) {
Pico_msd.state = Pico_msd.command = 0;
Pico_msd.state = Pico_msd.command = Pico_msd.result = 0;
cdd_stop();

s68k_write8(0xff8000, 0x0);

PicoResetHook = NULL;
}
}
Expand All @@ -201,27 +192,29 @@ static u32 msd_read16(u32 a)
{
u16 d = 0;

if ((u16)a >= 0x0f800) {
a = (u16)a;
if (a >= 0x0f800) {
d = Pico_msd.data[(a&0x7ff)>>1];
} else if ((u16)a >= 0xf7f0) {
} else if (a >= 0xf7f6) {
switch (a&0xe) {
case 0x6: d = 0x5241; break; // RA
case 0x8: d = 0x5445; break; // TE
case 0xa: d = 0xcd54; break;
case 0xc: d = Pico_msd.result; break;
case 0xe: d = Pico_msd.command; break;
}
} else if (a < Pico.romsize)
d = *(u16 *)(Pico.rom + a);
} else if (Pico.romsize > 0x30000)
d = *(u16 *)(Pico.rom + 0x30000 + a);

return d;
}

static u32 msd_read8(u32 a)
{
u16 d = msd_read16(a);
u16 d = msd_read16(a&~1);

if (!(a&1)) d >>= 8;
return d;
return (u8)d;
}

void msd_write16(u32 a, u32 d)
Expand All @@ -237,23 +230,28 @@ void msd_write16(u32 a, u32 d)
base += 0x800000; // mirror
cpu68k_map_set(m68k_read8_map, base, 0x0bffff, msd_read8, 1);
cpu68k_map_set(m68k_read16_map, base, 0x0bffff, msd_read16, 1);
if (Pico.romsize > base)
memcpy(Pico_msd.data, Pico.rom + 0x3f800, 0x800);
} else if (Pico.romsize > base) {
cpu68k_map_set(m68k_read8_map, base, 0x03ffff, Pico.rom+base, 0);
cpu68k_map_set(m68k_read16_map, base, 0x03ffff, Pico.rom+base, 0);
}
} else if (a == 0xf7fe) {
// command port
msd_process(d);
if (Pico_msd.state & MSD_ST_INIT)
msd_process(d);
} else if (a >= 0xf800) {
// data area
Pico_msd.data[(a&0x7ff) >> 1] = d;
if (Pico_msd.state & MSD_ST_INIT)
Pico_msd.data[(a&0x7ff) >> 1] = d;
}
}

void msd_write8(u32 a, u32 d)
{
if ((u16)a >= 0xf800) {
// data area
((u8 *)Pico_msd.data)[MEM_BE2(a&0x7ff)] = d;
if (Pico_msd.state & MSD_ST_INIT)
((u8 *)Pico_msd.data)[MEM_BE2(a&0x7ff)] = d;
}
}
4 changes: 4 additions & 0 deletions pico/cd/megasd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct megasd {
s32 pad[7];
};

#define MSD_ST_INIT 1
#define MSD_ST_PLAY 2
#define MSD_ST_PAUSE 4

extern struct megasd Pico_msd;


Expand Down
9 changes: 5 additions & 4 deletions pico/cd/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,10 +1237,11 @@ PICO_INTERNAL void PicoMemSetupCD(void)
cpu68k_map_set(m68k_read16_map, BASE, BASE+0x01ffff, Pico_mcd->bios, 0);
if (pcd_base_address != 0) { // cartridge (for MSU/MD+)
// MD+ on MEGASD plus mirror
cpu68k_map_set(m68k_write8_map, 0x040000-(1<<M68K_MEM_SHIFT), 0x03ffff, msd_write8, 1);
cpu68k_map_set(m68k_write16_map, 0x040000-(1<<M68K_MEM_SHIFT), 0x03ffff, msd_write16, 1);
cpu68k_map_set(m68k_write8_map, 0x0c0000-(1<<M68K_MEM_SHIFT), 0x0bffff, msd_write8, 1);
cpu68k_map_set(m68k_write16_map, 0x0c0000-(1<<M68K_MEM_SHIFT), 0x0bffff, msd_write16, 1);
u32 base = 0x040000-(1<<M68K_MEM_SHIFT);
cpu68k_map_set(m68k_write8_map, base, 0x03ffff, msd_write8, 1);
cpu68k_map_set(m68k_write16_map, base, 0x03ffff, msd_write16, 1);
cpu68k_map_set(m68k_write8_map, base+0x080000, 0x0bffff, msd_write8, 1);
cpu68k_map_set(m68k_write16_map, base+0x080000, 0x0bffff, msd_write16, 1);
msd_reset();
} else { // no cartridge
// RAM cart
Expand Down
6 changes: 2 additions & 4 deletions pico/cd/memory_arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ m_m68k_read8_r06:
ldrb r0, [r1, #0x73] @ IRQ vector
bx lr
m_m68k_read8_r07:
PIC_LDR(r1, r2, Pico_mcd)
ldr r1, [r1]
ldrb r0, [r1, #0x72]
bx lr
m_m68k_read8_r08:
Expand Down Expand Up @@ -298,8 +296,6 @@ m_m68k_read16_r04:
mov r0, r0, lsl #8
bx lr
m_m68k_read16_r06:
PIC_LDR(r1, r2, Pico_mcd)
ldr r1, [r1]
ldrh r0, [r1, #0x72] @ IRQ vector
bx lr
m_m68k_read16_r08:
Expand Down Expand Up @@ -352,6 +348,7 @@ PicoWrite8_mcd_io:
beq m68k_reg_write8

PIC_LDR(r2, r3, carthw_ssf2_active)
ldr r2, [r2]
tst r2, r2
bne carthw_ssf2_write8
b PicoWrite8_io
Expand Down Expand Up @@ -383,6 +380,7 @@ PicoWrite16_mcd_io:
beq m_m68k_write16_regs

PIC_LDR(r2, r3, carthw_ssf2_active)
ldr r2, [r2]
tst r2, r2
bne carthw_ssf2_write16
b PicoWrite16_io
Expand Down
2 changes: 1 addition & 1 deletion pico/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ enum media_type_e PicoLoadMedia(const char *filename,
rom_size = 0;
}

// if there is an MSU ROM, it's name is now in rom_fname for loading
// if there is an MSU ROM, its name is now in rom_fname for loading
PicoIn.AHW |= PAHW_MCD;
}
else {
Expand Down
10 changes: 5 additions & 5 deletions pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void cpu68k_map_all_funcs(u32 start_addr, u32 end_addr, u32 (*r8)(u32), u32 (*r1
u32 PicoRead16_floating(u32 a)
{
// faking open bus
u32 d = (Pico.m.rotate += 0x41);
u16 d = (Pico.m.rotate += 0x41);
d ^= (d << 5) ^ (d << 8);
if ((a & 0xff0000) == 0xa10000) return d; // MegaCD pulldowns don't work here curiously
return (PicoIn.AHW & PAHW_MCD) ? 0x00 : d; // pulldown if MegaCD2 attached
Expand Down Expand Up @@ -775,9 +775,9 @@ u32 PicoRead8_io(u32 a)
goto end;
}

d = PicoRead16_floating(a);

if ((a & 0xfc00) == 0x1000) {
d = (u8)PicoRead16_floating(a);

if ((a & 0xff01) == 0x1100) { // z80 busreq (verified)
// bit8 seems to be readable in this range
if (!(a & 1)) {
Expand Down Expand Up @@ -807,10 +807,10 @@ u32 PicoRead16_io(u32 a)
goto end;
}

d = PicoRead16_floating(a);

// bit8 seems to be readable in this range
if ((a & 0xfc00) == 0x1000) {
d = PicoRead16_floating(a);

if ((a & 0xff00) == 0x1100) { // z80 busreq
d &= ~0x0100;
d |= (z80_cycles_from_68k() < Pico.t.z80c_cnt) << 8;
Expand Down

0 comments on commit a0ddd24

Please sign in to comment.