X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=aec354d26e3f67b6bb2ca034563321ea49e2ab18;hb=b5e5172d049a83251874fb33e65a53c9654dc0bc;hp=48899a06f21c7d9a70757d16a3ce3010943b8fdc;hpb=1820b5a7a18fc8c37dddb2ab88159e513ceb3b16;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index 48899a0..aec354d 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -137,7 +137,7 @@ int PicoReset(int hard) Pico.m.pal=pal; Pico.video.status = 0x3408 | pal; // always set bits | vblank | pal - sound_reset(); // pal must be known here + PsndReset(); // pal must be known here if (PicoMCD & 1) { PicoResetMCD(hard); @@ -202,22 +202,18 @@ static __inline void SekRunM68k(int cyc) { int cyc_do; SekCycleAim+=cyc; - //printf("aim: %i, cnt: %i\n", SekCycleAim, SekCycleCnt); if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return; - //printf("cyc_do: %i\n", cyc_do); -#if defined(EMU_C68K) && defined(EMU_M68K) - // this means we do run-compare Cyclone vs Musashi - SekCycleCnt+=CM_compareRun(cyc_do); +#if defined(EMU_CORE_DEBUG) + // this means we do run-compare + SekCycleCnt+=CM_compareRun(cyc_do, 0); #elif defined(EMU_C68K) - PicoCpu.cycles=cyc_do; - CycloneRun(&PicoCpu); - SekCycleCnt+=cyc_do-PicoCpu.cycles; -#elif defined(EMU_A68K) - m68k_ICount=cyc_do; - M68000_RUN(); - SekCycleCnt+=cyc_do-m68k_ICount; + PicoCpuCM68k.cycles=cyc_do; + CycloneRun(&PicoCpuCM68k); + SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles; #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(cyc_do); +#elif defined(EMU_F68K) + SekCycleCnt+=fm68k_emulate(cyc_do+1); #endif } @@ -225,46 +221,32 @@ static __inline void SekStep(void) { // this is required for timing sensitive stuff to work int realaim=SekCycleAim; SekCycleAim=SekCycleCnt+1; -#if defined(EMU_C68K) && defined(EMU_M68K) - // this means we do run-compare Cyclone vs Musashi - SekCycleCnt+=CM_compareRun(1); +#if defined(EMU_CORE_DEBUG) + SekCycleCnt+=CM_compareRun(1, 0); #elif defined(EMU_C68K) - PicoCpu.cycles=1; - CycloneRun(&PicoCpu); - SekCycleCnt+=1-PicoCpu.cycles; -#elif defined(EMU_A68K) - m68k_ICount=1; - M68000_RUN(); - SekCycleCnt+=1-m68k_ICount; + PicoCpuCM68k.cycles=1; + CycloneRun(&PicoCpuCM68k); + SekCycleCnt+=1-PicoCpuCM68k.cycles; #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(1); +#elif defined(EMU_F68K) + SekCycleCnt+=fm68k_emulate(1); #endif SekCycleAim=realaim; } static int CheckIdle(void) { -#if 1 - unsigned char state[0x88]; - - memset(state,0,sizeof(state)); + int i, state[0x22]; // See if the state is the same after 2 steps: - SekState(state); SekStep(); SekStep(); SekState(state+0x44); - if (memcmp(state,state+0x44,0x44)==0) return 1; -#else - unsigned char state[0x44]; - static unsigned char oldstate[0x44]; + SekState(state); SekStep(); SekStep(); SekState(state+0x11); + for (i = 0x10; i >= 0; i--) + if (state[i] != state[i+0x11]) return 0; - SekState(state); - if(memcmp(state,oldstate,0x40)==0) return 1; - memcpy(oldstate, state, 0x40); -#endif - - return 0; + return 1; } -void lprintf_al(const char *fmt, ...); // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) @@ -273,155 +255,22 @@ static __inline void getSamples(int y) if(y == 224) { if(emustatus & 2) - curr_pos += sound_render(curr_pos, PsndLen-PsndLen/2); - else curr_pos = sound_render(0, PsndLen); + curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2); + else curr_pos = PsndRender(0, PsndLen); if (emustatus&1) emustatus|=2; else emustatus&=~2; if (PicoWriteSound) PicoWriteSound(curr_pos); // clear sound buffer - sound_clear(); + PsndClear(); } else if(emustatus & 3) { emustatus|= 2; emustatus&=~1; - curr_pos = sound_render(0, PsndLen/2); + curr_pos = PsndRender(0, PsndLen/2); } } -#if 1*0 -int vint_delay = 205/*68*/, as_delay = 18/*148*/; - -// Accurate but slower frame which does hints -static int PicoFrameHints(void) -{ - struct PicoVideo *pv=&Pico.video; - int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample; - const int cycles_68k=488,cycles_z80=228; // both PAL and NTSC compile to same values - int skip=PicoSkipFrame || (PicoOpt&0x10); - int hint; // Hint counter - - if(Pico.m.pal) { // - //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488) - //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; - 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; - line_sample = 93; - } - - SekCyclesReset(); - //z80ExtraCycles = 0; - - if(PicoOpt&4) - z80CycleAim = 0; -// z80_resetCycles(); - - pv->status&=~0x88; // clear V-Int, come out of vblank - - hint=pv->reg[10]; // Load H-Int counter - //dprintf("-hint: %i", hint); - - //SekRun(as_delay); - SekRun(148); - - for (y=0;ylwrite_cnt -= 12; - if (pv->lwrite_cnt < 0) pv->lwrite_cnt=0; - if (pv->lwrite_cnt == 0) - Pico.video.status|=0x200; - - // pad delay (for 6 button pads) - if(PicoOpt&0x20) { - if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; - if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; - } - - // H-Interrupts: - if(y <= lines_vis && --hint < 0) // y <= lines_vis: Comix Zone, Golden Axe - { - //dprintf("rhint:old @ %06x", SekPc); - hint=pv->reg[10]; // Reload H-Int counter - pv->pending_ints|=0x10; - if (pv->reg[0]&0x10) { - elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt); - SekInterrupt(4); - } - //dprintf("hint_routine: %x", (*(unsigned short*)(Pico.ram+0x0B84)<<16)|*(unsigned short*)(Pico.ram+0x0B86)); - } - - // V-Interrupt: - if (y == lines_vis) - { - pv->status|=0x08; // go into vblank - //pv->status|=0x80; // V-Int happened - //if(!Pico.m.dma_bytes||(Pico.video.reg[0x17]&0x80)) { - // there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula) - SekRun(68); SekCycleAim-=68; // 128; ? - SekCycleAim-=148; -// SekRun(vint_delay); SekCycleAim-=vint_delay; // 128; ? -// SekCycleAim-=as_delay; - //} - pv->pending_ints|=0x20; - if(pv->reg[1]&0x20) { - elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt); - SekInterrupt(6); - } - if(Pico.m.z80Run && (PicoOpt&4)) // ? - z80_int(); - //dprintf("zint: [%i|%i] zPC=%04x", Pico.m.scanline, SekCyclesDone(), mz80GetRegisterValue(NULL, 0)); - } - - // decide if we draw this line -#if CAN_HANDLE_240_LINES - if(!skip && ((!(pv->reg[1]&8) && y<224) || ((pv->reg[1]&8) && y<240)) ) -#else - if(!skip && y<224) -#endif - PicoLine(y); - - if(PicoOpt&1) - 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); - - // Run scanline: - if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA()); - SekRun(cycles_68k); - if ((PicoOpt&4) && Pico.m.z80Run) { - if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80; - else { - int cnt = SekCyclesDone() - z80startCycle; - cnt = (cnt>>1)-(cnt>>5); - //if (cnt > cycles_z80) printf("FIXME: z80 cycles: %i\n", cnt); - if (cnt > cycles_z80) cnt = cycles_z80; - Pico.m.z80Run |= 2; - z80CycleAim+=cnt; - } - total_z80+=z80_run(z80CycleAim-total_z80); - } - } - - // draw a frame just after vblank in alternative render mode - if(!PicoSkipFrame && (PicoOpt&0x10)) - PicoFrameFull(); - - return 0; -} -#else #include "PicoFrameHints.c" -#endif // helper z80 runner. Runs only if z80 is enabled at this point // (z80WriteBusReq will handle the rest) @@ -444,7 +293,7 @@ static void PicoRunZ80Simple(int line_from, int line_to) if (PicoOpt&1) { // we have ym2612 enabled, so we have to run Z80 in lines, so we could update DAC and timers for (line = line_from; line < line_to; line++) { - sound_timers_and_dac(line); + Psnd_timers_and_dac(line); if ((line == 224 || line == line_sample) && PsndOut) getSamples(line); if (line == 32 && PsndOut) emustatus &= ~1; if (line >= line_from_r && line < line_to_r) @@ -464,7 +313,7 @@ static int PicoFrameSimple(void) int cycles_68k_vblock,cycles_68k_block; // split to 16 run calls for active scan, for vblank split to 2 (ntsc), 3 (pal 240), 4 (pal 224) - if (Pico.m.pal && (pv->reg[1]&8)) { // 240 lines + if (Pico.m.pal && (pv->reg[1]&8)) { if(pv->reg[1]&8) { // 240 lines cycles_68k_block = 7329; // (488*240+148)/16.0, -4 cycles_68k_vblock = 11640; // (72*488-148-68)/3.0, 0 @@ -526,14 +375,6 @@ static int PicoFrameSimple(void) PicoRunZ80Simple(line, lines); } - // here we render sound if ym2612 is disabled - if (!(PicoOpt&1) && PsndOut) { - int len = sound_render(0, PsndLen); - if (PicoWriteSound) PicoWriteSound(len); - // clear sound buffer - sound_clear(); - } - // render screen if (!PicoSkipFrame) { @@ -549,6 +390,17 @@ static int PicoFrameSimple(void) for (y=0;y<224;y++) PicoLine(y); #endif else PicoFrameFull(); +#ifdef DRAW_FINISH_FUNC + DRAW_FINISH_FUNC(); +#endif + } + + // here we render sound if ym2612 is disabled + if (!(PicoOpt&1) && PsndOut) { + int len = PsndRender(0, PsndLen); + if (PicoWriteSound) PicoWriteSound(len); + // clear sound buffer + PsndClear(); } // a gap between flags set and vint @@ -667,14 +519,18 @@ char *debugString(void) sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", SRam.start, SRam.end, Pico.m.sram_reg); dstrp+=strlen(dstrp); sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status); dstrp+=strlen(dstrp); -#ifdef EMU_C68K - sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpu.state_flags, SekCyclesDoneT()); +#if defined(EMU_C68K) + sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpuCM68k.state_flags, SekCyclesDoneT()); dstrp+=strlen(dstrp); - sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpu.d[0], PicoCpu.a[0], PicoCpu.osp, PicoCpu.irq); dstrp+=strlen(dstrp); - sprintf(dstrp, "d1=%08x, a1=%08x, sr=%04x\n", PicoCpu.d[1], PicoCpu.a[1], CycloneGetSr(&PicoCpu)); dstrp+=strlen(dstrp); + sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpuCM68k.d[0], PicoCpuCM68k.a[0], PicoCpuCM68k.osp, PicoCpuCM68k.irq); dstrp+=strlen(dstrp); + sprintf(dstrp, "d1=%08x, a1=%08x, sr=%04x\n", PicoCpuCM68k.d[1], PicoCpuCM68k.a[1], CycloneGetSr(&PicoCpuCM68k)); dstrp+=strlen(dstrp); for(r=2; r < 8; r++) { - sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpu.d[r], r, PicoCpu.a[r]); dstrp+=strlen(dstrp); + sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpuCM68k.d[r], r, PicoCpuCM68k.a[r]); dstrp+=strlen(dstrp); } +#elif defined(EMU_M68K) + sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuMM68k.int_level>>8); dstrp+=strlen(dstrp); +#elif defined(EMU_F68K) + sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuFM68k.interrupts[0]); dstrp+=strlen(dstrp); #endif sprintf(dstrp, "z80Run: %i, pal: %i, frame#: %i\n", Pico.m.z80Run, Pico.m.pal, Pico.m.frame_count); dstrp+=strlen(dstrp); z80_debug(dstrp); dstrp+=strlen(dstrp);