X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=104aef0015f3a8b263866e9cbf166fd8b1917407;hb=6cadc2da0070781cf2d8fcff84265d3ca1f423b9;hp=f821cf417fc169741fcaad22db482341411bd7b5;hpb=b837b69b3fcff1737431c8be1c78d1cfd64003a6;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index f821cf4..104aef0 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -16,8 +16,9 @@ struct Pico Pico; 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; -void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware +void (*PicoWriteSound)(int len) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware struct PicoSRAM SRam; int z80startCycle = 0, z80stopCycle = 0; // in 68k cycles @@ -48,7 +49,8 @@ int PicoInit(void) // to be called once on emu exit void PicoExit(void) { - PicoExitMCD(); + if (PicoMCD&1) + PicoExitMCD(); z80_exit(); // notaz: sram @@ -69,12 +71,15 @@ int PicoReset(int hard) else PicoMemSetup(); PicoMemReset(); SekReset(); + // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games). + SekSetRealTAS(PicoMCD & 1); SekCycleCntT=0; z80_reset(); // reset VDP state, VRAM and PicoMisc //memset(&Pico.video,0,sizeof(Pico.video)); //memset(&Pico.vram,0,sizeof(Pico.vram)); + memset(Pico.ioports,0,sizeof(Pico.ioports)); // needed for MCD to reset properly memset(&Pico.m,0,sizeof(Pico.m)); Pico.video.pending_ints=0; emustatus = 0; @@ -106,9 +111,12 @@ int PicoReset(int hard) c=region>>(i<<3); c&=0xff; if (c<=' ') continue; - if (c=='J') support|=1; - else if (c=='U') support|=4; - else if (c=='E') support|=8; + if (c=='J') support|=1; + else if (c=='U') support|=4; + else if (c=='E') support|=8; + else if (c=='j') {support|=1; break; } + else if (c=='u') {support|=4; break; } + else if (c=='e') {support|=8; break; } else { // New style code: @@ -119,6 +127,13 @@ int PicoReset(int hard) } } + // auto detection order override + if (PicoAutoRgnOrder) { + if (((PicoAutoRgnOrder>>0)&0xf) & support) support = (PicoAutoRgnOrder>>0)&0xf; + else if (((PicoAutoRgnOrder>>4)&0xf) & support) support = (PicoAutoRgnOrder>>4)&0xf; + else if (((PicoAutoRgnOrder>>8)&0xf) & support) support = (PicoAutoRgnOrder>>8)&0xf; + } + // Try to pick the best hardware value for English/50hz: if (support&8) { hw=0xc0; pal=1; } // Europe else if (support&4) hw=0x80; // USA @@ -134,7 +149,6 @@ int PicoReset(int hard) if (PicoMCD & 1) { PicoResetMCD(hard); - SRam.data = 0; return 0; } @@ -180,6 +194,8 @@ int PicoReset(int hard) // Dino Dini's Soccer malfunctions if SRAM is not filled with 0xff if (strncmp((char *)Pico.rom+0x150, "IDOND NI'I", 10) == 0) memset(SRam.data, 0xff, sram_size); + dprintf("sram: det: %i; eeprom: %i; start: %06x; end: %06x\n", + (Pico.m.sram_reg>>4)&1, (Pico.m.sram_reg>>2)&1, SRam.start, SRam.end); } Pico.m.sram_reg = SRam.reg_back; // restore sram_reg @@ -303,20 +319,22 @@ static int CheckIdle(void) // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) { + static int curr_pos = 0; + if(y == 224) { //dprintf("sta%i: %i [%i]", (emustatus & 2), emustatus, y); if(emustatus & 2) - sound_render(PsndLen/2, PsndLen-PsndLen/2); - else sound_render(0, PsndLen); + curr_pos += sound_render(curr_pos, PsndLen-PsndLen/2); + else curr_pos = sound_render(0, PsndLen); if (emustatus&1) emustatus|=2; else emustatus&=~2; - if (PicoWriteSound) PicoWriteSound(); + if (PicoWriteSound) PicoWriteSound(curr_pos); // clear sound buffer - memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); + sound_clear(); } else if(emustatus & 3) { emustatus|= 2; emustatus&=~1; - sound_render(0, PsndLen/2); + curr_pos = sound_render(0, PsndLen/2); } } @@ -413,11 +431,18 @@ static int PicoFrameHints(void) getSamples(y); // Run scanline: - if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); + if (Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); SekRun(cycles_68k); - if((PicoOpt&4) && Pico.m.z80Run) { - Pico.m.z80Run|=2; - z80CycleAim+=cycles_z80; + 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); } } @@ -469,7 +494,13 @@ static int PicoFrameSimple(void) int y=0,line=0,lines=0,lines_step=0,sects; int cycles_68k_vblock,cycles_68k_block; - if(Pico.m.pal) { + // we don't emulate DMA timing in this mode + if (Pico.m.dma_bytes) { + Pico.m.dma_bytes=0; + Pico.video.status&=~2; + } + + if (Pico.m.pal) { // M68k cycles/frame: 152009.78 if(pv->reg[1]&8) { // 240 lines cycles_68k_block = (int) ((double) OSC_PAL / 7 / 50 / 312 * 15 + 0.4); // 16 sects, 16*15=240, 7308 @@ -525,10 +556,10 @@ static int PicoFrameSimple(void) // here we render sound if ym2612 is disabled if(!(PicoOpt&1) && PsndOut) { - sound_render(0, PsndLen); - if(PicoWriteSound) PicoWriteSound(); + int len = sound_render(0, PsndLen); + if(PicoWriteSound) PicoWriteSound(len); // clear sound buffer - memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); + sound_clear(); } // render screen @@ -622,19 +653,8 @@ int PicoFrame(void) return 0; } -static int DefaultCram(int cram) -{ - int high=0x0841; - // Convert 0000bbbb ggggrrrr - // to rrrr1ggg g10bbbb1 - high|=(cram&0x00f)<<12; // Red - high|=(cram&0x0f0)<< 3; // Green - high|=(cram&0xf00)>> 7; // Blue - return high; -} - -// Function to convert Megadrive Cram into a native colour: -int (*PicoCram)(int cram)=DefaultCram; +// callback to output message from emu +void (*PicoMessage)(const char *msg)=NULL; #if defined(__DEBUG_PRINT) || defined(WIN32) // tmp debug: dump some stuff