From: kub Date: Fri, 20 Dec 2024 11:04:54 +0000 (+0100) Subject: mcd, some fixes for msu/md+ X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0ddd2423dae568996c2c801be02dbfe0034890b;p=picodrive.git mcd, some fixes for msu/md+ --- diff --git a/pico/cd/megasd.c b/pico/cd/megasd.c index 6f1ec7ea..ec31acbd 100644 --- a/pico/cd/megasd.c +++ b/pico/cd/megasd.c @@ -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 @@ -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); } @@ -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; @@ -173,13 +169,10 @@ 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; } } @@ -187,11 +180,9 @@ static void msd_init(void) 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; } } @@ -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) @@ -237,16 +230,20 @@ 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; } } @@ -254,6 +251,7 @@ 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; } } diff --git a/pico/cd/megasd.h b/pico/cd/megasd.h index 63846e1e..7c311584 100644 --- a/pico/cd/megasd.h +++ b/pico/cd/megasd.h @@ -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; diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 72a64e4c..d00f5b91 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -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<