X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=5fd1557b70ef49fc87b5d7bb003e6dc3b6fc5413;hb=4ff2d52753e46bce5622a5935f3d3750b5848f8f;hp=bd21a569f2c086901cd4a7fab48f7cf0fe8a2c2e;hpb=bf098bc53228f6b5016cb4a6126f4466bfba4e00;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index bd21a56..5fd1557 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -11,13 +11,14 @@ #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 @@ -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,6 +65,10 @@ int PicoReset(int hard) if (Pico.romsize<=0) return 1; + // setup correct memory map + if (PicoMCD & 1) + PicoMemSetupCD(); + else PicoMemSetup(); PicoMemReset(); SekReset(); SekCycleCntT=0; @@ -105,9 +108,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 +124,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 +250,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 +315,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 +539,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 @@ -646,19 +636,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