X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=0e9ee6c2bf8a9198bc9f05773494b28020c319fb;hb=259ed0ea6635845527a3da94a67a6260463861e6;hp=ce3e3408f7618f78d6852fef5505ab0ba60fe21f;hpb=3aa1e148a28da9b4e10e824984f7b3a4908b1ace;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index ce3e340..0e9ee6c 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -17,7 +17,9 @@ int PicoSkipFrame=0; // skip rendering frame? int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe int PicoAutoRgnOrder = 0; int emustatus = 0; // rapid_ym2612, multi_ym_updates -void (*PicoWriteSound)(int len) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware +void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware +void (*PicoResetHook)(void) = NULL; +void (*PicoLineHook)(int count) = NULL; struct PicoSRAM SRam = {0,}; int z80startCycle, z80stopCycle; // in 68k cycles @@ -137,7 +139,9 @@ 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 (PicoResetHook) PicoResetHook(); if (PicoMCD & 1) { PicoResetMCD(hard); @@ -202,12 +206,10 @@ 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) PicoCpuCM68k.cycles=cyc_do; CycloneRun(&PicoCpuCM68k); @@ -215,7 +217,7 @@ static __inline void SekRunM68k(int cyc) #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(cyc_do); #elif defined(EMU_F68K) - SekCycleCnt+=m68k_emulate(cyc_do); + SekCycleCnt+=fm68k_emulate(cyc_do+1, 0); #endif } @@ -223,9 +225,8 @@ 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) PicoCpuCM68k.cycles=1; CycloneRun(&PicoCpuCM68k); @@ -233,7 +234,7 @@ static __inline void SekStep(void) #elif defined(EMU_M68K) SekCycleCnt+=m68k_execute(1); #elif defined(EMU_F68K) - SekCycleCnt+=m68k_emulate(1); + SekCycleCnt+=fm68k_emulate(1, 0); #endif SekCycleAim=realaim; } @@ -254,22 +255,29 @@ static int CheckIdle(void) // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) { +#if SIMPLE_WRITE_SOUND + if (y != 224) return; + PsndRender(0, PsndLen); + if (PicoWriteSound) PicoWriteSound(PsndLen); + PsndClear(); +#else static int curr_pos = 0; 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); } +#endif } @@ -296,14 +304,14 @@ 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) - z80_run(228); + z80_run_nr(228); } } else if (line_to_r-line_from_r > 0) { - z80_run(228*(line_to_r-line_from_r)); + z80_run_nr(228*(line_to_r-line_from_r)); // samples will be taken by caller } } @@ -316,7 +324,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 @@ -363,6 +371,7 @@ static int PicoFrameSimple(void) SekRunM68k(cycles_68k_block); PicoRunZ80Simple(line, lines); + if (PicoLineHook) PicoLineHook(lines_step); line=lines; } @@ -376,14 +385,7 @@ static int PicoFrameSimple(void) lines += sects*lines_step; 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(); + if (PicoLineHook) PicoLineHook(sects*lines_step); } // render screen @@ -401,6 +403,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 @@ -436,6 +449,7 @@ static int PicoFrameSimple(void) SekRunM68k(cycles_68k_vblock); PicoRunZ80Simple(line, lines); + if (PicoLineHook) PicoLineHook(lines_step); line=lines; sects--; @@ -446,6 +460,7 @@ static int PicoFrameSimple(void) if (sects) { lines += sects*lines_step; PicoRunZ80Simple(line, lines); + if (PicoLineHook) PicoLineHook(sects*lines_step); } return 0; @@ -487,6 +502,17 @@ void PicoFrameDrawOnly(void) for (y=0;y<224;y++) PicoLine(y); } +int PicoGetStat(pstat_t which) +{ + switch (which) + { + case PS_PAL: return Pico.m.pal; + case PS_40_CELL: return Pico.video.reg[12]&1; + case PS_240_LINES: return Pico.m.pal && (Pico.video.reg[1]&8); + } + return 0; +} + // callback to output message from emu void (*PicoMessage)(const char *msg)=NULL; @@ -573,14 +599,6 @@ char *debugString(void) } #endif -#if 0 - { - FILE *f = fopen("zram", "wb"); - fwrite(Pico.zram, 1, 0x2000, f); - fclose(f); - } -#endif - return dstr; } #endif