X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=Pico%2FPico.c;h=48899a06f21c7d9a70757d16a3ce3010943b8fdc;hb=1820b5a7a18fc8c37dddb2ab88159e513ceb3b16;hp=73321bce7427a0e5560cad215f90dce0da6b90af;hpb=1dceadaee482ad3ca6f5ccbef57ea93893f45e82;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index 73321bc..48899a0 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -16,14 +16,13 @@ int PicoOpt=0; // disable everything by default 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; +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 struct PicoSRAM SRam = {0,}; int z80startCycle, z80stopCycle; // in 68k cycles -//int z80ExtraCycles = 0; int PicoPad[2]; // Joypads, format is SACB RLDU -int PicoMCD = 0; // mega CD status: scd_started, reset_pending +int PicoMCD = 0; // mega CD status: scd_started // to be called once on emu init int PicoInit(void) @@ -199,7 +198,7 @@ PICO_INTERNAL int CheckDMA(void) return burn; } -static __inline void SekRun(int cyc) +static __inline void SekRunM68k(int cyc) { int cyc_do; SekCycleAim+=cyc; @@ -265,6 +264,8 @@ static int CheckIdle(void) return 0; } +void lprintf_al(const char *fmt, ...); + // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) { @@ -422,24 +423,34 @@ static int PicoFrameHints(void) #include "PicoFrameHints.c" #endif -// helper z80 runner +// helper z80 runner. Runs only if z80 is enabled at this point +// (z80WriteBusReq will handle the rest) static void PicoRunZ80Simple(int line_from, int line_to) { - int line_from_r=line_from, line_to_r=line_to, line = line_from; + int line_from_r=line_from, line_to_r=line_to, line=0; int line_sample = Pico.m.pal ? 68 : 93; - if(!(PicoOpt&4) || Pico.m.z80Run == 0) { line_from_r = line_to_r; line_to_r = 0; } + if (!(PicoOpt&4) || Pico.m.z80Run == 0) line_to_r = 0; + else { + extern const unsigned short vcounts[]; + if (z80startCycle) { + line = vcounts[z80startCycle>>8]; + if (line > line_from) + line_from_r = line; + } + z80startCycle = SekCyclesDone(); + } - if(PicoOpt&1) { + 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_to; line++) { + for (line = line_from; line < line_to; line++) { sound_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) + 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); } - } else if(line_to_r-line_from_r > 0) { + } else if (line_to_r-line_from_r > 0) { z80_run(228*(line_to_r-line_from_r)); // samples will be taken by caller } @@ -481,6 +492,7 @@ static int PicoFrameSimple(void) Pico.video.status|=0x200; Pico.m.scanline=-1; + z80startCycle=0; SekCyclesReset(); @@ -496,7 +508,7 @@ static int PicoFrameSimple(void) if (CheckIdle()) break; lines += lines_step; - SekRun(cycles_68k_block); + SekRunM68k(cycles_68k_block); PicoRunZ80Simple(line, lines); line=lines; @@ -506,11 +518,12 @@ static int PicoFrameSimple(void) if(sects) { int c = sects*cycles_68k_block; - lines += sects*lines_step; - PicoRunZ80Simple(line, lines); - // this is for approriate line counter, etc + // this "run" is for approriate line counter, etc SekCycleCnt += c; SekCycleAim += c; + + lines += sects*lines_step; + PicoRunZ80Simple(line, lines); } // here we render sound if ym2612 is disabled @@ -541,7 +554,7 @@ static int PicoFrameSimple(void) // a gap between flags set and vint pv->pending_ints|=0x20; pv->status|=8; // go into vblank - SekRun(68+4); + SekRunM68k(68+4); // ---- V-Blanking period ---- // fix line counts @@ -568,7 +581,7 @@ static int PicoFrameSimple(void) while (sects) { lines += lines_step; - SekRun(cycles_68k_vblock); + SekRunM68k(cycles_68k_vblock); PicoRunZ80Simple(line, lines); line=lines; @@ -625,7 +638,7 @@ void PicoFrameDrawOnly(void) // callback to output message from emu void (*PicoMessage)(const char *msg)=NULL; -#if defined(__DEBUG_PRINT) || defined(__GP2X__) +#if 1 // defined(__DEBUG_PRINT) // tmp debug: dump some stuff #define bit(r, x) ((r>>x)&1) void z80_debug(char *dstr);