X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=3cee0c27238abd0398eae985f295df63474385b1;hb=7336a99a49268970e0df89d15210b98dd7798f1e;hp=750ffc5f9e32c31561518b8ad95ec038ae7341f4;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index 750ffc5..3cee0c2 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,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 @@ -187,11 +200,59 @@ int PicoReset(int hard) return 0; } +static int dma_timings[] = { +83, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy +102, 205, 204, 102, // vblank: 40cell: +8, 16, 15, 8, // active: 32cell: +9, 18, 17, 9 // ... +}; + +static int dma_bsycles[] = { +(488<<8)/83, (488<<8)/167, (488<<8)/166, (488<<8)/83, +(488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102, +(488<<8)/8, (488<<8)/16, (488<<8)/15, (488<<8)/8, +(488<<8)/9, (488<<8)/18, (488<<8)/17, (488<<8)/9 +}; + +//static +int CheckDMA(void) +{ + int burn = 0, bytes_can = 0, dma_op = Pico.video.reg[0x17]>>6; // see gens for 00 and 01 modes + int bytes = Pico.m.dma_bytes; + int dma_op1; + + if(!(dma_op&2)) dma_op = (Pico.video.type==1) ? 0 : 1; // setting dma_timings offset here according to Gens + dma_op1 = dma_op; + if(Pico.video.reg[12] & 1) dma_op |= 4; // 40 cell mode? + if(!(Pico.video.status&8)&&(Pico.video.reg[1]&0x40)) dma_op|=8; // active display? + bytes_can = dma_timings[dma_op]; + + if(bytes <= bytes_can) { + if(dma_op&2) Pico.video.status&=~2; // dma no longer busy + else { + burn = bytes * dma_bsycles[dma_op] >> 8; // have to be approximate because can't afford division.. + //SekCycleCnt-=Pico.m.dma_endcycles; + //Pico.m.dma_endcycles = 0; + } + Pico.m.dma_bytes = 0; + } else { + if(!(dma_op&2)) burn = 488; + Pico.m.dma_bytes -= bytes_can; + } + + //SekCycleCnt+=burn; + dprintf("~Dma %i op=%i can=%i burn=%i [%i|%i]", Pico.m.dma_bytes, dma_op1, bytes_can, burn, Pico.m.scanline, SekCyclesDone()); + //dprintf("~aim: %i, cnt: %i", SekCycleAim, SekCycleCnt); + return burn; +} + static __inline void SekRun(int cyc) { int cyc_do; SekCycleAim+=cyc; - if((cyc_do=SekCycleAim-SekCycleCnt) < 0) return; + //dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt); + if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return; + //dprintf("cyc_do: %i", cyc_do); #if defined(EMU_C68K) && defined(EMU_M68K) // this means we do run-compare Cyclone vs Musashi SekCycleCnt+=CM_compareRun(cyc_do); @@ -254,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); } } @@ -331,14 +394,14 @@ static int PicoFrameHints(void) // V-Interrupt: if (y == lines_vis) { - //dprintf("vint: @ %06x [%i|%i]", SekPc, y, SekCycleCnt); - pv->status|=0x88; // V-Int happened, go into vblank - SekRun(128); SekCycleAim-=128; // there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula) - /*if(Pico.m.z80Run && (PicoOpt&4)) { - z80CycleAim+=cycles_z80/2; - total_z80+=z80_run(z80CycleAim-total_z80); - z80CycleAim-=cycles_z80/2; - }*/ + dprintf("vint: @ %06x [%i|%i], aim=%i cnt=%i", SekPc, y, SekCycleCnt, SekCycleAim, SekCycleCnt); + pv->status|=0x08; // go into vblank + if(!Pico.m.dma_bytes||(Pico.video.reg[0x17]&0x80)) { + // there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula) + SekRun(128); SekCycleAim-=128; // 128; ? + } + dprintf("[%i|%i], aim=%i cnt=%i @ %x", y, SekCycleCnt, SekCycleAim, SekCycleCnt, SekPc); + pv->status|=0x80; // V-Int happened pv->pending_ints|=0x20; if(pv->reg[1]&0x20) SekInterrupt(6); if(Pico.m.z80Run && (PicoOpt&4)) // ? @@ -364,6 +427,7 @@ static int PicoFrameHints(void) getSamples(y); // Run scanline: + if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); SekRun(cycles_68k); if((PicoOpt&4) && Pico.m.z80Run) { Pico.m.z80Run|=2; @@ -475,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 @@ -547,6 +611,8 @@ int PicoFrame(void) { int acc; + Pico.m.frame_count++; + if (PicoMCD & 1) { PicoFrameMCD(); return 0;