From d0132772f773fbb4fbc4354b06a8e8d356ec70da Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 16 Sep 2013 04:09:02 +0300 Subject: [PATCH] cd: better cd change handling, perhaps? --- pico/cd/cd_sys.c | 29 ++++++++++++++++++++++------- pico/cd/mcd.c | 19 ++++++++++++++----- pico/cd/memory.c | 4 ++++ pico/pico.h | 2 +- pico/pico_int.h | 1 + platform/common/menu_pico.c | 9 +++++++++ platform/common/menu_pico.h | 1 + 7 files changed, 52 insertions(+), 13 deletions(-) diff --git a/pico/cd/cd_sys.c b/pico/cd/cd_sys.c index 6b92d56..1c19057 100644 --- a/pico/cd/cd_sys.c +++ b/pico/cd/cd_sys.c @@ -190,7 +190,8 @@ PICO_INTERNAL void Reset_CD(void) Pico_mcd->scd.Cur_Track = 0; Pico_mcd->scd.Cur_LBA = -150; Pico_mcd->scd.Status_CDC &= ~1; - Pico_mcd->scd.Status_CDD = CD_Present ? READY : NOCD; + if (Pico_mcd->scd.Status_CDD != TRAY_OPEN) + Pico_mcd->scd.Status_CDD = CD_Present ? READY : NOCD; Pico_mcd->scd.CDD_Complete = 0; Pico_mcd->scd.File_Add_Delay = 0; } @@ -201,27 +202,41 @@ int Insert_CD(const char *cdimg_name, int type) int ret = 1; CD_Present = 0; - Pico_mcd->scd.Status_CDD = NOCD; if (cdimg_name != NULL && type != CIT_NOT_CD) { ret = Load_CD_Image(cdimg_name, type); if (ret == 0) { CD_Present = 1; - /* for open tray close command will handle Status_CDD */ - if (Pico_mcd->scd.Status_CDD != TRAY_OPEN) + + if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) + { + if (Pico_mcd->bios[0x122 ^ 1] == '2') + Close_Tray_CDD_cC(); + // else bios will issue it + } + else + { Pico_mcd->scd.Status_CDD = READY; + } } } + if (Pico_mcd->scd.Status_CDD != TRAY_OPEN && !CD_Present) + Pico_mcd->scd.Status_CDD = NOCD; + return ret; } -void Stop_CD(void) +int Stop_CD(void) { + int ret = CD_Present; + Unload_ISO(); CD_Present = 0; + + return ret; } @@ -471,8 +486,8 @@ PICO_INTERNAL int Play_CDD_c3(void) if (delay < 0) delay = -delay; delay >>= 12; - // based on genplys GX - if (delay < 13) + if (Pico_mcd->scd.Cur_LBA > 0 && delay < 13) + // based on genplus GX delay = 13; Pico_mcd->scd.Cur_LBA = new_lba; diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 04c6156..b57fa16 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -41,6 +41,8 @@ PICO_INTERNAL void PicoPowerMCD(void) memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm)); memset(&Pico_mcd->m, 0, sizeof(Pico_mcd->m)); + Reset_CD(); + // cold reset state (tested) Pico_mcd->m.state_flags = PCD_ST_S68K_RST; Pico_mcd->m.busreq = 2; // busreq on, s68k in reset @@ -48,16 +50,25 @@ PICO_INTERNAL void PicoPowerMCD(void) memset(Pico_mcd->bios + 0x70, 0xff, 4); } -PICO_INTERNAL int PicoResetMCD(void) +void pcd_soft_reset(void) { - // ?? - Reset_CD(); + // Reset_CD(); // breaks Fahrenheit CD swap + LC89510_Reset(); gfx_cd_reset(); #ifdef _ASM_CD_MEMORY_C //PicoMemResetCDdecode(1); // don't have to call this in 2M mode #endif + pcd_event_schedule_s68k(PCD_EVENT_CDC, 12500000/75); + + // TODO: test if register state/timers change +} + +PICO_INTERNAL int PicoResetMCD(void) +{ + // reset button doesn't affect MCD hardware + // use SRam.data for RAM cart if (PicoOpt & POPT_EN_MCD_RAMCART) { if (SRam.data == NULL) @@ -69,8 +80,6 @@ PICO_INTERNAL int PicoResetMCD(void) } SRam.start = SRam.end = 0; // unused - pcd_event_schedule(0, PCD_EVENT_CDC, 12500000/75); - return 0; } diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 1d844da..af455f2 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -331,6 +331,10 @@ void s68k_reg_write8(u32 a, u32 d) { // Warning: d might have upper bits set switch (a) { + case 1: + if (!(d & 1)) + pcd_soft_reset(); + return; case 2: return; // only m68k can change WP case 3: { diff --git a/pico/pico.h b/pico/pico.h index 9922d56..41ba7fb 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -135,7 +135,7 @@ void PicoCDBufferFlush(void); // cd/cd_sys.c int Insert_CD(const char *cdimg_name, int type); -void Stop_CD(void); // releases all resources taken when CD game was started. +int Stop_CD(void); // unloads CD, returns 1 if there was cd loaded // Cart.c typedef enum diff --git a/pico/pico_int.h b/pico/pico_int.h index 38676cf..08c7a20 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -653,6 +653,7 @@ void pcd_event_schedule_s68k(enum pcd_event event, int after); unsigned int pcd_cycles_m68k_to_s68k(unsigned int c); int pcd_sync_s68k(unsigned int m68k_target, int m68k_poll_sync); void pcd_run_cpus(int m68k_cycles); +void pcd_soft_reset(void); void pcd_state_loaded(void); // pico/pico.c diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 0a5e85a..6033a35 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -1029,6 +1029,13 @@ static int main_menu_handler(int id, int keys) return 1; } break; + case MA_MAIN_CHANGE_CD: + if (PicoAHW & PAHW_MCD) { + if (!Stop_CD()) + menu_loop_tray(); + return 1; + } + break; case MA_MAIN_CREDITS: draw_menu_message(credits, NULL); in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70); @@ -1062,6 +1069,7 @@ static menu_entry e_menu_main[] = mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler), mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler), mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler), + mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler), mee_handler ("Change options", menu_loop_options), mee_handler ("Configure controls", menu_loop_keyconfig), mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler), @@ -1078,6 +1086,7 @@ void menu_loop(void) me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded); me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded); me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded); + me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoAHW & PAHW_MCD); me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL); menu_enter(PicoGameLoaded); diff --git a/platform/common/menu_pico.h b/platform/common/menu_pico.h index 39bd9e3..c5edde3 100644 --- a/platform/common/menu_pico.h +++ b/platform/common/menu_pico.h @@ -11,6 +11,7 @@ typedef enum MA_MAIN_LOAD_STATE, MA_MAIN_RESET_GAME, MA_MAIN_LOAD_ROM, + MA_MAIN_CHANGE_CD, MA_MAIN_CONTROLS, MA_MAIN_CREDITS, MA_MAIN_PATCHES, -- 2.39.2