int PicoAHW = 0; // active addon hardware: scd_active, 32x_active, svp_active, pico_active\r
int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
int PicoAutoRgnOrder = 0;\r
-int z80startCycle, z80stopCycle; // in 68k cycles\r
struct PicoSRAM SRam = {0,};\r
\r
void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware\r
{\r
unsigned char sram_reg=Pico.m.sram_reg; // must be preserved\r
\r
+ Pico.m.frame_count = 0;\r
+\r
// clear all memory of the emulated machine\r
memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);\r
\r
\r
Pico.m.dirtyPal = 1;\r
\r
+ Pico.m.z80_bank68k = 0;\r
+ memset(Pico.zram, 0, sizeof(Pico.zram)); // ??\r
+\r
PicoDetectRegion();\r
- Pico.video.status = 0x3408 | Pico.m.pal; // 'always set' bits | vblank | pal\r
+ Pico.video.status = 0x3428 | Pico.m.pal; // 'always set' bits | vblank | collision | pal\r
\r
PsndReset(); // pal must be known here\r
\r
PicoResetMCD();\r
return 0;\r
}\r
+ else {\r
+ // reinit, so that checksum checks pass\r
+ SekFinishIdleDet();\r
+ if (!(PicoOpt & POPT_DIS_IDLE_DET))\r
+ SekInitIdleDet();\r
+ }\r
\r
// reset sram state; enable sram access by default if it doesn't overlap with ROM\r
Pico.m.sram_reg=sram_reg&0x14;\r
// same for Outrunners (92-121, when active is set to 24)\r
// 96 is VR hack\r
static const int dma_timings[] = {\r
-96, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
-102, 205, 204, 102, // vblank: 40cell:\r
-16, 16, 15, 8, // active: 32cell:\r
-24, 18, 17, 9 // ...\r
+ 96, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
+ 102, 205, 204, 102, // vblank: 40cell:\r
+ 16, 16, 15, 8, // active: 32cell:\r
+ 24, 18, 17, 9 // ...\r
};\r
\r
static const int dma_bsycles[] = {\r
-(488<<8)/96, (488<<8)/167, (488<<8)/166, (488<<8)/83,\r
-(488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102,\r
-(488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,\r
-(488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9\r
+ (488<<8)/96, (488<<8)/167, (488<<8)/166, (488<<8)/83,\r
+ (488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102,\r
+ (488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,\r
+ (488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9\r
};\r
\r
PICO_INTERNAL int CheckDMA(void)\r
{\r
int cyc_do;\r
SekCycleAim+=cyc;\r
- if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
+ if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
#if defined(EMU_CORE_DEBUG)\r
// this means we do run-compare\r
SekCycleCnt+=CM_compareRun(cyc_do, 0);\r
\r
#include "PicoFrameHints.c"\r
\r
-// helper z80 runner. Runs only if z80 is enabled at this point\r
-// (z80WriteBusReq will handle the rest)\r
-static void PicoRunZ80Simple(int line_from, int line_to)\r
+\r
+int z80stopCycle;\r
+int z80_cycle_cnt; /* 'done' z80 cycles before z80_run() */\r
+int z80_cycle_aim;\r
+int z80_scanline;\r
+int z80_scanline_cycles; /* cycles done until z80_scanline */\r
+\r
+/* sync z80 to 68k */\r
+PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done)\r
{\r
- int line_from_r=line_from, line_to_r=line_to, line=0;\r
- int line_sample = Pico.m.pal ? 68 : 93;\r
+ int cnt;\r
+ z80_cycle_aim = cycles_68k_to_z80(m68k_cycles_done);\r
+ cnt = z80_cycle_aim - z80_cycle_cnt;\r
\r
- if (!(PicoOpt&POPT_EN_Z80) || Pico.m.z80Run == 0) line_to_r = 0;\r
- else {\r
- extern const unsigned short vcounts[];\r
- if (z80startCycle) {\r
- line = vcounts[z80startCycle>>8];\r
- if (line > line_from)\r
- line_from_r = line;\r
- }\r
- z80startCycle = SekCyclesDone();\r
- }\r
+ elprintf(EL_BUSREQ, "z80 sync %i (%i|%i -> %i|%i)", cnt, z80_cycle_cnt, z80_cycle_cnt / 228,\r
+ z80_cycle_aim, z80_cycle_aim / 228);\r
\r
- if (PicoOpt&POPT_EN_FM) {\r
- // we have ym2612 enabled, so we have to run Z80 in lines, so we could update DAC and timers\r
- for (line = line_from; line < line_to; line++) {\r
- Psnd_timers_and_dac(line);\r
- if ((line == 224 || line == line_sample) && PsndOut) getSamples(line);\r
- if (line == 32 && PsndOut) emustatus &= ~1;\r
- if (line >= line_from_r && line < line_to_r)\r
- z80_run_nr(228);\r
- }\r
- } else if (line_to_r-line_from_r > 0) {\r
- z80_run_nr(228*(line_to_r-line_from_r));\r
- // samples will be taken by caller\r
- }\r
+ if (cnt > 0)\r
+ z80_cycle_cnt += z80_run(cnt);\r
}\r
\r
+\r
// Simple frame without H-Ints\r
static int PicoFrameSimple(void)\r
{\r
struct PicoVideo *pv=&Pico.video;\r
- int y=0,line=0,lines=0,lines_step=0,sects;\r
+ int y=0,lines_step=0,sects,line_last;\r
int cycles_68k_vblock,cycles_68k_block;\r
\r
// split to 16 run calls for active scan, for vblank split to 2 (ntsc), 3 (pal 240), 4 (pal 224)\r
- if (Pico.m.pal && (pv->reg[1]&8)) {\r
+ if (Pico.m.pal)\r
+ {\r
if(pv->reg[1]&8) { // 240 lines\r
- cycles_68k_block = 7329; // (488*240+148)/16.0, -4\r
- cycles_68k_vblock = 11640; // (72*488-148-68)/3.0, 0\r
+ cycles_68k_block = 7308;\r
+ cycles_68k_vblock = 11694;\r
lines_step = 15;\r
} else {\r
- cycles_68k_block = 6841; // (488*224+148)/16.0, -4\r
- cycles_68k_vblock = 10682; // (88*488-148-68)/4.0, 0\r
+ cycles_68k_block = 6821;\r
+ cycles_68k_vblock = 10719;\r
lines_step = 14;\r
}\r
+ line_last = 312-1;\r
} else {\r
// M68k cycles/frame: 127840.71\r
cycles_68k_block = 6841; // (488*224+148)/16.0, -4\r
cycles_68k_vblock = 9164; // (38*488-148-68)/2.0, 0\r
lines_step = 14;\r
+ line_last = 262-1;\r
}\r
\r
// a hack for VR, to get it running in fast mode\r
Pico.video.status|=0x200;\r
\r
Pico.m.scanline=-1;\r
- z80startCycle=0;\r
+ PsndDacLine = 0;\r
\r
SekCyclesReset();\r
+ z80_resetCycles();\r
\r
// 6 button pad: let's just say it timed out now\r
Pico.m.padTHPhase[0]=Pico.m.padTHPhase[1]=0;\r
pv->status&=~0x88; // clear V-Int, come out of vblank\r
\r
// Run in sections:\r
- for(sects=16; sects; sects--)\r
+ for (sects=16; sects; sects--)\r
{\r
if (CheckIdle()) break;\r
\r
- lines += lines_step;\r
SekRunM68k(cycles_68k_block);\r
-\r
- PicoRunZ80Simple(line, lines);\r
if (PicoLineHook) PicoLineHook(lines_step);\r
- line=lines;\r
}\r
\r
- // run Z80 for remaining sections\r
- if(sects) {\r
- int c = sects*cycles_68k_block;\r
-\r
- // this "run" is for approriate line counter, etc\r
- SekCycleCnt += c;\r
- SekCycleAim += c;\r
+ // do remaining sections without 68k\r
+ if (sects) {\r
+ SekCycleCnt += sects * cycles_68k_block;\r
+ SekCycleAim += sects * cycles_68k_block;\r
\r
- lines += sects*lines_step;\r
- PicoRunZ80Simple(line, lines);\r
if (PicoLineHook) PicoLineHook(sects*lines_step);\r
}\r
\r
if (!(PicoOpt&POPT_ALT_RENDERER))\r
{\r
// Draw the screen\r
+#if 0\r
#if CAN_HANDLE_240_LINES\r
if (pv->reg[1]&8) {\r
for (y=0;y<240;y++) PicoLine(y);\r
}\r
#else\r
for (y=0;y<224;y++) PicoLine(y);\r
+#endif\r
#endif\r
}\r
else PicoFrameFull();\r
#endif\r
}\r
\r
- // here we render sound if ym2612 is disabled\r
- if (!(PicoOpt&POPT_EN_FM) && PsndOut) {\r
- int len = PsndRender(0, PsndLen);\r
- if (PicoWriteSound) PicoWriteSound(len);\r
- // clear sound buffer\r
- PsndClear();\r
- }\r
-\r
// a gap between flags set and vint\r
pv->pending_ints|=0x20;\r
pv->status|=8; // go into vblank\r
SekRunM68k(68+4);\r
\r
+ if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))\r
+ PicoSyncZ80(SekCycleCnt);\r
+\r
+ // render sound\r
+ if (PsndOut)\r
+ {\r
+ int len;\r
+ if (ym2612.dacen && PsndDacLine <= lines_step*16)\r
+ PsndDoDAC(lines_step*16);\r
+ len = PsndRender(0, PsndLen);\r
+ if (PicoWriteSound) PicoWriteSound(len);\r
+ // clear sound buffer\r
+ PsndClear();\r
+ }\r
+\r
// ---- V-Blanking period ----\r
// fix line counts\r
if(Pico.m.pal) {\r
if(pv->reg[1]&8) { // 240 lines\r
- lines = line = 240;\r
sects = 3;\r
lines_step = 24;\r
} else {\r
- lines = line = 224;\r
sects = 4;\r
lines_step = 22;\r
}\r
} else {\r
- lines = line = 224;\r
sects = 2;\r
lines_step = 19;\r
}\r
if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))\r
z80_int();\r
\r
- while (sects)\r
+ while (1)\r
{\r
- lines += lines_step;\r
-\r
SekRunM68k(cycles_68k_vblock);\r
-\r
- PicoRunZ80Simple(line, lines);\r
if (PicoLineHook) PicoLineHook(lines_step);\r
- line=lines;\r
\r
sects--;\r
- if (sects && CheckIdle()) break;\r
+ if (sects == 0) break;\r
+ if (CheckIdle()) break;\r
}\r
\r
- // run Z80 for remaining sections\r
if (sects) {\r
- lines += sects*lines_step;\r
- PicoRunZ80Simple(line, lines);\r
+ SekCycleCnt += sects * cycles_68k_vblock;\r
+ SekCycleAim += sects * cycles_68k_vblock;\r
if (PicoLineHook) PicoLineHook(sects*lines_step);\r
}\r
\r
+ // must sync z80 before return, and extend last DAC sample\r
+ if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))\r
+ PicoSyncZ80(SekCycleCnt);\r
+ if (PsndOut && ym2612.dacen && PsndDacLine <= line_last)\r
+ PsndDoDAC(line_last);\r
+\r
+ timers_cycle();\r
+\r
return 0;\r
}\r
\r
+int idle_hit_counter = 0;\r
+\r
int PicoFrame(void)\r
{\r
int acc;\r
\r
+ if ((Pico.m.frame_count&0x3f) == 0) {\r
+ elprintf(EL_STATUS, "ihits: %i", idle_hit_counter);\r
+ idle_hit_counter = 0;\r
+ }\r
+\r
Pico.m.frame_count++;\r
\r
if (PicoAHW & PAHW_MCD) {\r
for (y=0;y<224;y++) PicoLine(y);\r
}\r
\r
-int PicoGetStat(pstat_t which)\r
+void PicoGetInternal(pint_t which, pint_ret_t *r)\r
{\r
switch (which)\r
{\r
- case PS_PAL: return Pico.m.pal;\r
- case PS_40_CELL: return Pico.video.reg[12]&1;\r
- case PS_240_LINES: return Pico.m.pal && (Pico.video.reg[1]&8);\r
+ case PI_ROM: r->vptr = Pico.rom; break;\r
+ case PI_ISPAL: r->vint = Pico.m.pal; break;\r
+ case PI_IS40_CELL: r->vint = Pico.video.reg[12]&1; break;\r
+ case PI_IS240_LINES: r->vint = Pico.m.pal && (Pico.video.reg[1]&8); break;\r
}\r
- return 0;\r
}\r
\r
// callback to output message from emu\r
void (*PicoMessage)(const char *msg)=NULL;\r
\r
#if 1 // defined(__DEBUG_PRINT)\r
-// tmp debug: dump some stuff\r
#define bit(r, x) ((r>>x)&1)\r
void z80_debug(char *dstr);\r
char *debugString(void)\r