X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2FPico.c;h=678ef97ebc3b5f8c5d58cf982bfa3ebb379c5fa6;hb=0a051f558c6585c94d06dbe670e70bcac4e0aadd;hp=9e87e9ed91a899638a81d8fd228ed9e3e2cc264b;hpb=d1df87866b45a5ab9f1b6c6c8a40da6a3a777f83;p=picodrive.git diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 9e87e9e..678ef97 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -11,7 +11,7 @@ #include "../sound/sound.h" -static int counter75hz = 0; // TODO: move 2 context +extern unsigned char formatted_bram[4*0x10]; int PicoInitMCD(void) @@ -30,15 +30,25 @@ void PicoExitMCD(void) int PicoResetMCD(int hard) { - // clear everything except BIOS - memset(Pico_mcd->prg_ram, 0, sizeof(mcd_state) - sizeof(Pico_mcd->bios)); + memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram)); + memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M)); + memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram)); + if (hard) { + int fmt_size = sizeof(formatted_bram); + memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram)); + memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size); + } + memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs)); + memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm)); + *(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6) - PicoMCD |= 2; // s68k reset pending + Pico_mcd->m.state_flags |= 2; // s68k reset pending Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset - counter75hz = 0; + Pico_mcd->m.counter75hz = 0; LC89510_Reset(); Reset_CD(); + gfx_cd_reset(); return 0; } @@ -48,7 +58,11 @@ static __inline void SekRun(int cyc) int cyc_do; SekCycleAim+=cyc; if((cyc_do=SekCycleAim-SekCycleCnt) < 0) return; -#if defined(EMU_M68K) +#if defined(EMU_C68K) + PicoCpu.cycles=cyc_do; + CycloneRun(&PicoCpu); + SekCycleCnt+=cyc_do-PicoCpu.cycles; +#elif defined(EMU_M68K) m68k_set_context(&PicoM68kCPU); SekCycleCnt+=m68k_execute(cyc_do); #endif @@ -59,12 +73,56 @@ static __inline void SekRunS68k(int cyc) int cyc_do; SekCycleAimS68k+=cyc; if((cyc_do=SekCycleAimS68k-SekCycleCntS68k) < 0) return; -#if defined(EMU_M68K) +#if defined(EMU_C68K) + PicoCpuS68k.cycles=cyc_do; + CycloneRun(&PicoCpuS68k); + SekCycleCntS68k+=cyc_do-PicoCpuS68k.cycles; +#elif defined(EMU_M68K) m68k_set_context(&PicoS68kCPU); SekCycleCntS68k+=m68k_execute(cyc_do); #endif } +#define PS_STEP_M68K 8 +#define PS_STEP_S68K 13 + +static __inline void SekRunPS(int cyc_m68k, int cyc_s68k) +{ + int cyc_do_m68k, cyc_do_s68k, it=0; + int cyc_done_m68k=0, cyc_done_s68k=0; + SekCycleAim+=cyc_m68k; + SekCycleAimS68k+=cyc_s68k; + cyc_do_m68k=SekCycleAim-SekCycleCnt; + cyc_do_s68k=SekCycleAimS68k-SekCycleCntS68k; + while (cyc_done_m68k < cyc_do_m68k || cyc_done_s68k < cyc_do_s68k) { + it++; + if (cyc_done_m68k < cyc_do_m68k && it*PS_STEP_M68K > cyc_done_m68k) { +#if defined(EMU_C68K) + PicoCpu.cycles = PS_STEP_M68K; + CycloneRun(&PicoCpu); + cyc_done_m68k += PS_STEP_M68K - PicoCpu.cycles; +#elif defined(EMU_M68K) + m68k_set_context(&PicoM68kCPU); + cyc_done_m68k += m68k_execute(PS_STEP_M68K); +#endif + } //else dprintf("m68k skipping it #%i", it); + if (cyc_done_s68k < cyc_do_s68k && it*PS_STEP_S68K > cyc_done_s68k) { +#if defined(EMU_C68K) + PicoCpuS68k.cycles = PS_STEP_S68K; + CycloneRun(&PicoCpuS68k); + cyc_done_s68k += PS_STEP_S68K - PicoCpuS68k.cycles; +#elif defined(EMU_M68K) + m68k_set_context(&PicoS68kCPU); + cyc_done_s68k += m68k_execute(PS_STEP_S68K); +#endif + } //else dprintf("s68k skipping it #%i", it); + } + SekCycleCnt += cyc_done_m68k; + SekCycleCntS68k += cyc_done_s68k; + //dprintf("== end SekRunPS, it=%i ==", it); +} + + static __inline void check_cd_dma(void) { int ddx; @@ -82,12 +140,43 @@ static __inline void check_cd_dma(void) Update_CDC_TRansfer(ddx); // now go and do the actual transfer } +static __inline void update_chips(void) +{ + int counter_timer, int3_set; + int counter75hz_lim = Pico.m.pal ? 2080 : 2096; + + // 75Hz CDC update + if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) { + Pico_mcd->m.counter75hz -= counter75hz_lim; + Check_CD_Command(); + } + + // update timers + counter_timer = Pico.m.pal ? 0x21630 : 0x2121c; // 136752 : 135708; + Pico_mcd->m.timer_stopwatch += counter_timer; + if ((int3_set = Pico_mcd->s68k_regs[0x31])) { + Pico_mcd->m.timer_int3 -= counter_timer; + if (Pico_mcd->m.timer_int3 < 0) { + if (Pico_mcd->s68k_regs[0x33] & (1<<3)) { + dprintf("s68k: timer irq 3"); + SekInterruptS68k(3); + Pico_mcd->m.timer_int3 += int3_set << 16; + } + // is this really what happens if irq3 is masked out? + Pico_mcd->m.timer_int3 &= 0xffffff; + } + } + + // update gfx chip + if (Pico_mcd->rot_comp.Reg_58 & 0x8000) + gfx_cd_update(); +} + -// Accurate but slower frame which does hints static int PicoFrameHintsMCD(void) { struct PicoVideo *pv=&Pico.video; - int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample,counter75hz_lim; + int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample; const int cycles_68k=488,cycles_z80=228,cycles_s68k=795; // both PAL and NTSC compile to same values int skip=PicoSkipFrame || (PicoOpt&0x10); int hint; // Hint counter @@ -97,13 +186,11 @@ static int PicoFrameHintsMCD(void) //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228 lines = 312; // Steve Snake says there are 313 lines, but this seems to also work well line_sample = 68; - counter75hz_lim = 2080; if(pv->reg[1]&8) lines_vis = 240; } else { //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228 lines = 262; - counter75hz_lim = 2096; line_sample = 93; } @@ -173,31 +260,22 @@ static int PicoFrameHintsMCD(void) sound_timers_and_dac(y); // get samples from sound chips - if(y == 32 && PsndOut) - emustatus &= ~1; - else if((y == 224 || y == line_sample) && PsndOut) - ;//getSamples(y); + if (y == 224 && PsndOut) { + int len = sound_render(0, PsndLen); + if (PicoWriteSound) PicoWriteSound(len); + // clear sound buffer + sound_clear(); + } // Run scanline: //dprintf("m68k starting exec @ %06x", SekPc); if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); - SekRun(cycles_68k); - if ((Pico_mcd->m.busreq&3) == 1) { // no busreq/no reset -#if 0 - int i; - FILE *f = fopen("prg_ram.bin", "wb"); - for (i = 0; i < 0x80000; i+=2) - { - int tmp = Pico_mcd->prg_ram[i]; - Pico_mcd->prg_ram[i] = Pico_mcd->prg_ram[i+1]; - Pico_mcd->prg_ram[i+1] = tmp; - } - fwrite(Pico_mcd->prg_ram, 1, 0x80000, f); - fclose(f); - exit(1); -#endif - //dprintf("s68k starting exec @ %06x", SekPcS68k); - SekRunS68k(cycles_s68k); + if((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) { + SekRunPS(cycles_68k, cycles_s68k); // "perfect sync" + } else { + SekRun(cycles_68k); + if ((Pico_mcd->m.busreq&3) == 1) // no busreq/no reset + SekRunS68k(cycles_s68k); } if((PicoOpt&4) && Pico.m.z80Run) { @@ -206,13 +284,7 @@ static int PicoFrameHintsMCD(void) total_z80+=z80_run(z80CycleAim-total_z80); } - if ((counter75hz+=10) >= counter75hz_lim) { - counter75hz -= counter75hz_lim; - Check_CD_Command(); - } - - if (Pico_mcd->rot_comp.Reg_58 & 0x8000) - gfx_cd_update(); + update_chips(); } // draw a frame just after vblank in alternative render mode