X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FPico.c;h=e6a3b296339f54c4dcb721e3dc0c44127d94359a;hb=a4f0cc8647c019f149541df380a2d30e14aeb75c;hp=bd21a569f2c086901cd4a7fab48f7cf0fe8a2c2e;hpb=bf098bc53228f6b5016cb4a6126f4466bfba4e00;p=picodrive.git diff --git a/Pico/Pico.c b/Pico/Pico.c index bd21a56..e6a3b29 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -11,16 +11,17 @@ #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 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 @@ -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). + 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; @@ -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 @@ -133,7 +149,6 @@ int PicoReset(int hard) if (PicoMCD & 1) { PicoResetMCD(hard); - SRam.data = 0; return 0; } @@ -179,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 @@ -237,31 +254,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 +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); } } @@ -437,11 +431,18 @@ static int PicoFrameHints(void) getSamples(y); // Run scanline: - if(Pico.m.dma_bytes) SekCycleCnt+=CheckDMA(); + if (Pico.m.dma_bytes) SekCyclesBurn(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); } } @@ -462,13 +463,13 @@ static void PicoRunZ80Simple(int line_from, int line_to) if(!(PicoOpt&4) || Pico.m.z80Run == 0) { line_from_r = line_to_r; line_to_r = 0; } - if(z80startCycle != 0) { + if(z80startCycle != 0x01000000) { line_from_r = vcounts[z80startCycle>>8]+1; - z80startCycle = 0; + z80startCycle = 0x01000000; } - if(z80stopCycle != 0) { + if(z80stopCycle != 0x01000000) { line_to_r = vcounts[z80stopCycle>>8]+1; - z80stopCycle = 0; + z80stopCycle = 0x01000000; } if(PicoOpt&1) { @@ -493,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 @@ -549,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 @@ -646,47 +653,57 @@ int PicoFrame(void) return 0; } -static int DefaultCram(int cram) +void PicoFrameDrawOnly(void) { - 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; + int y; + PicoFrameStart(); + for (y=0;y<224;y++) PicoLine(y); } -// 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) +#if defined(__DEBUG_PRINT) || defined(__GP2X__) // tmp debug: dump some stuff #define bit(r, x) ((r>>x)&1) void z80_debug(char *dstr); -char *debugString() +char *debugString(void) { #if 1 static char dstr[1024]; - unsigned char *reg=Pico.video.reg, r; - - // dump some info - sprintf(dstr, "mode set 1: %02x\n", (r=reg[0])); - sprintf(dstr, "%sdisplay_disable: %i, M3: %i, palette: %i, ?, hints: %i\n\n", dstr, bit(r,0), bit(r,1), bit(r,2), bit(r,4)); - sprintf(dstr, "%smode set 2: %02x\n", dstr, (r=reg[1])); - sprintf(dstr, "%sSMS/genesis: %i, pal: %i, dma: %i, vints: %i, disp: %i, TMS9918: %i\n\n",dstr, bit(r,2), bit(r,3), bit(r,4), bit(r,5), bit(r,6), bit(r,7)); - sprintf(dstr, "%smode set 3: %02x\n", dstr, (r=reg[0xB])); - sprintf(dstr, "%sLSCR: %i, HSCR: %i, 2cell vscroll: %i, IE2: %i\n\n", dstr, bit(r,0), bit(r,1), bit(r,2), bit(r,3)); - sprintf(dstr, "%smode set 4: %02x\n", dstr, (r=reg[0xC])); - sprintf(dstr, "%sinterlace: %i%i; cells: %i; shadow: %i\n\n", dstr, bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3)); - sprintf(dstr, "%sscroll size: w: %i; h: %i\n\n", dstr, reg[0x10]&3, (reg[0x10]&0x30)>>4); - sprintf(dstr, "%sSRAM: det: %i; eeprom: %i\n", dstr, bit(Pico.m.sram_reg, 4), bit(Pico.m.sram_reg, 2)); - sprintf(dstr, "%sCPU state: PC: %06x cycles: %i\n", dstr, SekPc, SekCyclesDoneT()); + struct PicoVideo *pv=&Pico.video; + unsigned char *reg=pv->reg, r; + char *dstrp; + + dstrp = dstr; + sprintf(dstrp, "mode set 1: %02x\n", (r=reg[0])); dstrp+=strlen(dstrp); + sprintf(dstrp, "display_disable: %i, M3: %i, palette: %i, ?, hints: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,4)); + dstrp+=strlen(dstrp); + sprintf(dstrp, "mode set 2: %02x\n", (r=reg[1])); dstrp+=strlen(dstrp); + sprintf(dstrp, "SMS/gen: %i, pal: %i, dma: %i, vints: %i, disp: %i, TMS: %i\n", bit(r,2), bit(r,3), bit(r,4), + bit(r,5), bit(r,6), bit(r,7)); dstrp+=strlen(dstrp); + sprintf(dstrp, "mode set 3: %02x\n", (r=reg[0xB])); dstrp+=strlen(dstrp); + sprintf(dstrp, "LSCR: %i, HSCR: %i, 2cell vscroll: %i, IE2: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,3)); dstrp+=strlen(dstrp); + sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); dstrp+=strlen(dstrp); + sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3)); + dstrp+=strlen(dstrp); + sprintf(dstrp, "scroll size: w: %i, h: %i SRAM: %i; eeprom: %i\n", reg[0x10]&3, (reg[0x10]&0x30)>>4, + bit(Pico.m.sram_reg, 4), bit(Pico.m.sram_reg, 2)); dstrp+=strlen(dstrp); + sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status); + dstrp+=strlen(dstrp); #ifdef EMU_C68K - for(r=0; r < 8; r++) - sprintf(dstr, "%sd%i=%08x, a%i=%08x\n", dstr, r, PicoCpu.d[r], r, PicoCpu.a[r]); + sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpu.state_flags, SekCyclesDoneT()); + dstrp+=strlen(dstrp); + sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpu.d[0], PicoCpu.a[0], PicoCpu.osp, PicoCpu.irq); dstrp+=strlen(dstrp); + sprintf(dstrp, "d1=%08x, a1=%08x, sr=%04x\n", PicoCpu.d[1], PicoCpu.a[1], CycloneGetSr(&PicoCpu)); dstrp+=strlen(dstrp); + for(r=2; r < 8; r++) { + sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpu.d[r], r, PicoCpu.a[r]); dstrp+=strlen(dstrp); + } #endif - z80_debug(dstr); + sprintf(dstrp, "z80Run: %i, pal: %i, frame#: %i\n", Pico.m.z80Run, Pico.m.pal, Pico.m.frame_count); dstrp+=strlen(dstrp); + z80_debug(dstrp); dstrp+=strlen(dstrp); + if (strlen(dstr) > sizeof(dstr)) + printf("warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr)); #else struct PicoVideo *pvid=&Pico.video;