X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcd%2Fmcd.c;h=6d23604cdef4e9eda56646f8f59e7fcf456286d8;hb=e42a47e2086e6512519dd86af420363498302f49;hp=8451a1c2fa08c198695ca44e0452e646b797f5d3;hpb=99ade2ee2f76fa8170fb4e1abacc24f39a150c44;p=picodrive.git diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 8451a1c..6d23604 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -11,7 +11,9 @@ extern unsigned char formatted_bram[4*0x10]; -static unsigned int m68k_cycle_mult; +static unsigned int mcd_m68k_cycle_mult; +static unsigned int mcd_m68k_cycle_base; +static unsigned int mcd_s68k_cycle_base; void (*PicoMCDopenTray)(void) = NULL; void (*PicoMCDcloseTray)(void) = NULL; @@ -20,13 +22,10 @@ void (*PicoMCDcloseTray)(void) = NULL; PICO_INTERNAL void PicoInitMCD(void) { SekInitS68k(); - Init_CD_Driver(); - gfx_init(); } PICO_INTERNAL void PicoExitMCD(void) { - End_CD_Driver(); } PICO_INTERNAL void PicoPowerMCD(void) @@ -44,7 +43,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(); + cdc_init(); + gfx_init(); // cold reset state (tested) Pico_mcd->m.state_flags = PCD_ST_S68K_RST; @@ -55,13 +55,18 @@ PICO_INTERNAL void PicoPowerMCD(void) void pcd_soft_reset(void) { - // Reset_CD(); // breaks Fahrenheit CD swap + elprintf(EL_CD, "cd: soft reset"); - LC89510_Reset(); + Pico_mcd->m.s68k_pend_ints = 0; + cdc_reset(); + cdd_reset(); #ifdef _ASM_CD_MEMORY_C //PicoMemResetCDdecode(1); // don't have to call this in 2M mode #endif + memset(&Pico_mcd->s68k_regs[0x38], 0, 9); + Pico_mcd->s68k_regs[0x38+9] = 0x0f; // default checksum + pcd_event_schedule_s68k(PCD_EVENT_CDC, 12500000/75); // TODO: test if register state/timers change @@ -85,7 +90,32 @@ PICO_INTERNAL int PicoResetMCD(void) return 0; } -static __inline void SekRunS68k(unsigned int to) +static void SekRunM68kOnce(void) +{ + int cyc_do; + pevt_log_m68k_o(EVT_RUN_START); + + if ((cyc_do = SekCycleAim - SekCycleCnt) > 0) { + SekCycleCnt += cyc_do; + +#if defined(EMU_C68K) + PicoCpuCM68k.cycles = cyc_do; + CycloneRun(&PicoCpuCM68k); + SekCycleCnt -= PicoCpuCM68k.cycles; +#elif defined(EMU_M68K) + SekCycleCnt += m68k_execute(cyc_do) - cyc_do; +#elif defined(EMU_F68K) + SekCycleCnt += fm68k_emulate(cyc_do, 0) - cyc_do; +#endif + } + + SekCyclesLeft = 0; + + SekTrace(0); + pevt_log_m68k_o(EVT_RUN_END); +} + +static void SekRunS68k(unsigned int to) { int cyc_do; @@ -116,21 +146,34 @@ static void pcd_set_cycle_mult(void) { // ~1.63 for NTSC, ~1.645 for PAL if (Pico.m.pal) - m68k_cycle_mult = ((12500000ull << 16) / (50*312*488)); + mcd_m68k_cycle_mult = ((12500000ull << 16) / (50*313*488)); else - m68k_cycle_mult = ((12500000ull << 16) / (60*262*488)) + 1; + mcd_m68k_cycle_mult = ((12500000ull << 16) / (60*262*488)) + 1; } unsigned int pcd_cycles_m68k_to_s68k(unsigned int c) { - return (long long)c * m68k_cycle_mult >> 16; + return (long long)c * mcd_m68k_cycle_mult >> 16; } /* events */ static void pcd_cdc_event(unsigned int now) { // 75Hz CDC update - Check_CD_Command(); + cdd_update(); + + /* check if a new CDD command has been processed */ + if (!(Pico_mcd->s68k_regs[0x4b] & 0xf0)) + { + /* reset CDD command wait flag */ + Pico_mcd->s68k_regs[0x4b] = 0xf0; + + if (Pico_mcd->s68k_regs[0x33] & PCDS_IEN4) { + elprintf(EL_INTS|EL_CD, "s68k: cdd irq 4"); + SekInterruptS68k(4); + } + } + pcd_event_schedule(now, PCD_EVENT_CDC, 12500000/75); } @@ -148,8 +191,7 @@ static void pcd_int3_timer_event(unsigned int now) static void pcd_dma_event(unsigned int now) { - int ddx = Pico_mcd->s68k_regs[4] & 7; - Update_CDC_TRansfer(ddx); + cdc_dma_update(); } typedef void (event_cb)(unsigned int now); @@ -234,10 +276,13 @@ static void pcd_run_events(unsigned int until) int pcd_sync_s68k(unsigned int m68k_target, int m68k_poll_sync) { #define now SekCycleCntS68k - unsigned int s68k_target = - (unsigned long long)m68k_target * m68k_cycle_mult >> 16; + unsigned int s68k_target; unsigned int target; + target = m68k_target - mcd_m68k_cycle_base; + s68k_target = mcd_s68k_cycle_base + + ((unsigned long long)target * mcd_m68k_cycle_mult >> 16); + elprintf(EL_CD, "s68k sync to %u, %u->%u", m68k_target, now, s68k_target); @@ -285,7 +330,13 @@ void pcd_run_cpus_normal(int m68k_cycles) SekCycleCnt = SekCycleAim - (s68k_left * 40220 >> 16); } - SekSyncM68k(); + while (CYCLES_GT(SekCycleAim, SekCycleCnt)) { + SekRunM68kOnce(); + if (Pico_mcd->m.need_sync) { + Pico_mcd->m.need_sync = 0; + pcd_sync_s68k(SekCycleCnt, 0); + } + } } void pcd_run_cpus_lockstep(int m68k_cycles) @@ -307,12 +358,21 @@ void pcd_run_cpus_lockstep(int m68k_cycles) #include "../pico_cmn.c" +void pcd_prepare_frame(void) +{ + pcd_set_cycle_mult(); + + // need this because we can't have direct mapping between + // master<->slave cycle counters because of overflows + mcd_m68k_cycle_base = SekCycleAim; + mcd_s68k_cycle_base = SekCycleAimS68k; +} + PICO_INTERNAL void PicoFrameMCD(void) { - if (!(PicoOpt&POPT_ALT_RENDERER)) - PicoFrameStart(); + PicoFrameStart(); - pcd_set_cycle_mult(); + pcd_prepare_frame(); PicoFrameHints(); } @@ -341,9 +401,6 @@ void pcd_state_loaded(void) if (Pico_mcd->s68k_regs[0x31]) pcd_event_schedule(SekCycleAimS68k, PCD_EVENT_TIMER3, Pico_mcd->s68k_regs[0x31] * 384); - - if (Pico_mcd->scd.Status_CDC & 0x08) - Update_CDC_TRansfer(Pico_mcd->s68k_regs[4] & 7); } diff = cycles - Pico_mcd->pcm.update_cycles;