cd: better cd change handling, perhaps?

This commit is contained in:
notaz 2013-09-16 04:09:02 +03:00
parent fa8fb75445
commit d0132772f7
7 changed files with 52 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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