X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=4847f554b37b05b8f20693a82a56dad53795efdb;hb=3d48f1437fc5e2c556ed900ae25fd4a255d52922;hp=5ab8483b712675702ca614759aa4718e26919211;hpb=312e9ce192d49b4bea2f8a7e3cd2eb91a860564f;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index 5ab8483..4847f55 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -11,19 +11,20 @@ #include "sound/sound.h" #include "sound/ym2612.h" -int PicoVer=0x0080; +int PicoVer=0x0110; 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 //int z80ExtraCycles = 0; -int PicoPad[2]; // Joypads, format is SACB RLDU -int PicoMCD = 0; // mega CD status +int PicoPad[2]; // Joypads, format is SACB RLDU +int PicoMCD = 0; // mega CD status: scd_started, reset_pending // to be called once on emu init int PicoInit(void) @@ -36,9 +37,6 @@ int PicoInit(void) SekInit(); z80_init(); // init even if we aren't going to use it - // Setup memory callbacks: - PicoMemInit(); - PicoInitMCD(); // notaz: sram @@ -51,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 @@ -66,14 +65,21 @@ int PicoReset(int hard) if (Pico.romsize<=0) return 1; + // setup correct memory map + if (PicoMCD & 1) + PicoMemSetupCD(); + 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). + CycloneSetRealTAS(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; @@ -105,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: @@ -118,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 @@ -237,31 +253,6 @@ static __inline void SekRun(int cyc) { int cyc_do; SekCycleAim+=cyc; -#if 0 - if(Pico.m.dma_bytes) { - int burn=0; - if((Pico.video.status&8)||!(Pico.video.reg[1]&0x40)) { // vblank? - if(Pico.m.dma_bytes < 205) { - burn = Pico.m.dma_bytes*(((488<<8)/205))>>8; - Pico.m.dma_bytes = 0; - } else { - burn += 488; - Pico.m.dma_bytes -= 205; - } - } else { - if(Pico.m.dma_bytes < 18) { - burn = Pico.m.dma_bytes*(((488<<8)/18))>>8; - Pico.m.dma_bytes = 0; - } else { - burn += 488; - Pico.m.dma_bytes -= 18; - } - } - SekCycleCnt+=burn; - dprintf("~DmaSlow %i burn=%i do=%i [%i|%i]", Pico.m.dma_bytes, burn, SekCycleAim-SekCycleCnt, - Pico.m.scanline, SekCyclesDone()); - } -#endif //dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt); if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return; //dprintf("cyc_do: %i", cyc_do); @@ -327,20 +318,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); } } @@ -549,10 +542,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 @@ -621,6 +614,8 @@ int PicoFrame(void) { int acc; + Pico.m.frame_count++; + if (PicoMCD & 1) { PicoFrameMCD(); return 0; @@ -644,19 +639,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