// pc&=0xfffffe;\r
pc&=~1;\r
if ((pc<<8) == 0)\r
+ {\r
+ printf("%i:%03i: game crash detected @ %06x\n", Pico.m.frame_count, Pico.m.scanline, SekPc);\r
return (int)Pico.rom + Pico.romsize; // common crash condition, can happen if acc timing is off\r
+ }\r
\r
PicoCpu.membase=PicoMemBase(pc&0x00ffffff);\r
PicoCpu.membase-=pc&0xff000000;\r
addr68k+=a&0x7fff;\r
\r
ret = (u8) PicoRead8(addr68k);\r
- //dprintf("z80->68k w8 : %06x, %02x", addr68k, ret);\r
+ elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);\r
goto end;\r
}\r
\r
// should not be needed || dprintf("z80_read RAM");\r
if (a<0x4000) { ret = (u8) Pico.zram[a&0x1fff]; goto end; }\r
\r
+ elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, ret);\r
+\r
end:\r
return ret;\r
}\r
u32 addr68k;\r
addr68k=Pico.m.z80_bank68k<<15;\r
addr68k+=a&0x7fff;\r
+ elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);\r
PicoWrite8(addr68k, data);\r
- //dprintf("z80->68k w8 : %06x, %02x", addr68k, data);\r
return;\r
}\r
\r
// should not be needed, drZ80 knows how to access RAM itself || dprintf("z80_write RAM @ %08x", lr);\r
if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }\r
+\r
+ elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);\r
}\r
\r
PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)\r
if (!d && Pico.m.scanline != -1) {
// needed by buggy Terminator (Sega CD)
int stop_before = SekCyclesDone() - z80stopCycle;
- dprintf("stop before: %i", stop_before);
- if (stop_before > 0 && stop_before <= 32) // Gens uses 16 here
+ //elprintf(EL_BUSREQ, "get_zrun: stop before: %i", stop_before);
+ // note: if we use 20 or more here, Barkley Shut Up and Jam! will purposedly crash itself.
+ // TODO: CD Terminator
+ if (stop_before > 0 && stop_before < 20) // Gens uses 16 here
d = 1; // bus not yet available
}
// |=0x80 for Shadow of the Beast & Super Offroad
+ elprintf(EL_BUSREQ, "get_zrun: %02x [%i] @%06x", d|0x80, SekCyclesDone(), SekPc);
return d|0x80;
}
void z80WriteBusReq(u32 d)
{
d&=1; d^=1;
- if(Pico.m.scanline != -1)
+ if (Pico.m.scanline != -1)
{
if(!d) {
// this is for a nasty situation where Z80 was enabled and disabled in the same 68k timeslice (Golden Axe III)
lineCycles=(488-SekCyclesLeft)&0x1ff;
else lineCycles=z80stopCycle-z80startCycle; // z80 was started at current line
if (lineCycles > 0 && lineCycles <= 488) {
- dprintf("zrun: %i/%i cycles", lineCycles, (lineCycles>>1)-(lineCycles>>5));
+ //dprintf("zrun: %i/%i cycles", lineCycles, (lineCycles>>1)-(lineCycles>>5));
lineCycles=(lineCycles>>1)-(lineCycles>>5);
z80_run(lineCycles);
}
}
} else {
- z80startCycle = SekCyclesDone();
+ if (!Pico.m.z80Run)
+ z80startCycle = SekCyclesDone();
+ else
+ d|=Pico.m.z80Run;
}
}
- dprintf("set_zrun: %02x [%i|%i] @%06x", d, Pico.m.scanline, SekCyclesDone(), /*mz80GetRegisterValue(NULL, 0),*/ SekPc);
+ elprintf(EL_BUSREQ, "set_zrun: %i->%i [%i] @%06x", Pico.m.z80Run, d, SekCyclesDone(), SekPc);
Pico.m.z80Run=(u8)d;
}
// rotate fakes next fetched instruction for Time Killers
if (a==0xa11100) { // z80 busreq
d=(z80ReadBusReq()<<8)|Pico.m.rotate++;
- dprintf("get_zrun: %04x [%i|%i] @%06x", d, Pico.m.scanline, SekCyclesDone(), SekPc);
goto end;
}
if ((a&0x6000)==0x4000) { // 0x4000-0x5fff, Fudge if disabled
if(PicoOpt&1) d=YM2612Read();
else d=Pico.m.rotate++&3;
- dprintf("read ym2612: %04x", d);
+ elprintf(EL_YM2612R, "read ym2612: %02x", d);
goto end;
}
d=0xffff;
return;
}
+#ifndef _CD_MEMORY_C
if (a >= SRam.start && a <= SRam.end) {
if ((a&0x16)==0x10) { // detected, not EEPROM, write not disabled
u8 *pm=(u8 *)(SRam.data-SRam.start+a);
SRAMWrite(a, d); // ??
return;
}
- //OtherWrite8End(a, d>>8, 16);
- //OtherWrite8End(a+1,d&0xff, 16);
+#else
+ OtherWrite8End(a, d>>8, 16);
+ OtherWrite8End(a+1,d&0xff, 16);
+#endif
}
#include "PicoInt.h"\r
#include "sound/ym2612.h"\r
\r
-int PicoVer=0x0110;\r
+int PicoVer=0x0133;\r
struct Pico Pico;\r
int PicoOpt=0; // disable everything by default\r
int PicoSkipFrame=0; // skip rendering frame?\r
\r
PicoInitMCD();\r
\r
- // notaz: sram\r
SRam.data=0;\r
SRam.resize=1;\r
\r
PicoExitMCD();\r
z80_exit();\r
\r
- // notaz: sram\r
if(SRam.data) free(SRam.data); SRam.data=0;\r
}\r
\r
return 0;\r
}\r
\r
-\r
- // notaz: sram\r
if(SRam.resize) {\r
int sram_size = 0;\r
if(SRam.data) free(SRam.data); SRam.data=0;\r
\r
if(*(Pico.rom+0x1B1) == 'R' && *(Pico.rom+0x1B0) == 'A') {\r
if(*(Pico.rom+0x1B2) & 0x40) {\r
- // EEPROM SRAM\r
+ // EEPROM\r
// what kind of EEPROMs are actually used? X24C02? X24C04? (X24C01 has only 128), but we will support up to 8K\r
SRam.start = PicoRead32(0x1B4) & ~1; // zero address is used for clock by some games\r
SRam.end = PicoRead32(0x1B8);\r
// Dino Dini's Soccer malfunctions if SRAM is not filled with 0xff\r
if (strncmp((char *)Pico.rom+0x150, "IDOND NI'I", 10) == 0)\r
memset(SRam.data, 0xff, sram_size);\r
- dprintf("sram: det: %i; eeprom: %i; start: %06x; end: %06x\n",\r
+ elprintf(EL_STATUS, "sram: det: %i; eeprom: %i; start: %06x; end: %06x",\r
(Pico.m.sram_reg>>4)&1, (Pico.m.sram_reg>>2)&1, SRam.start, SRam.end);\r
}\r
\r
return 0;\r
}\r
\r
-static int dma_timings[] = {\r
+// dma2vram settings are just hacks to unglitch Legend of Galahad (needs <= 104 to work)\r
+// same for Outrunners (92-121, when active is set to 24)\r
+static const int dma_timings[] = {\r
83, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
102, 205, 204, 102, // vblank: 40cell:\r
-8, 16, 15, 8, // active: 32cell:\r
-9, 18, 17, 9 // ...\r
+16, 16, 15, 8, // active: 32cell:\r
+24, 18, 17, 9 // ...\r
};\r
\r
-static int dma_bsycles[] = {\r
-(488<<8)/83, (488<<8)/167, (488<<8)/166, (488<<8)/83,\r
+static const int dma_bsycles[] = {\r
+(488<<8)/82, (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)/8, (488<<8)/16, (488<<8)/15, (488<<8)/8,\r
-(488<<8)/9, (488<<8)/18, (488<<8)/17, (488<<8)/9\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
-\r
PICO_INTERNAL int CheckDMA(void)\r
{\r
- int burn = 0, bytes_can = 0, dma_op = Pico.video.reg[0x17]>>6; // see gens for 00 and 01 modes\r
- int bytes = Pico.m.dma_bytes;\r
+ int burn = 0, xfers_can, dma_op = Pico.video.reg[0x17]>>6; // see gens for 00 and 01 modes\r
+ int xfers = Pico.m.dma_xfers;\r
int dma_op1;\r
\r
if(!(dma_op&2)) dma_op = (Pico.video.type==1) ? 0 : 1; // setting dma_timings offset here according to Gens\r
dma_op1 = dma_op;\r
if(Pico.video.reg[12] & 1) dma_op |= 4; // 40 cell mode?\r
if(!(Pico.video.status&8)&&(Pico.video.reg[1]&0x40)) dma_op|=8; // active display?\r
- bytes_can = dma_timings[dma_op];\r
-\r
- if(bytes <= bytes_can) {\r
+ xfers_can = dma_timings[dma_op];\r
+ if(xfers <= xfers_can) {\r
if(dma_op&2) Pico.video.status&=~2; // dma no longer busy\r
else {\r
- burn = bytes * dma_bsycles[dma_op] >> 8; // have to be approximate because can't afford division..\r
- //SekCycleCnt-=Pico.m.dma_endcycles;\r
- //Pico.m.dma_endcycles = 0;\r
+ burn = xfers * dma_bsycles[dma_op] >> 8; // have to be approximate because can't afford division..\r
}\r
- Pico.m.dma_bytes = 0;\r
+ Pico.m.dma_xfers = 0;\r
} else {\r
if(!(dma_op&2)) burn = 488;\r
- Pico.m.dma_bytes -= bytes_can;\r
+ Pico.m.dma_xfers -= xfers_can;\r
}\r
\r
- //SekCycleCnt+=burn;\r
- dprintf("~Dma %i op=%i can=%i burn=%i [%i|%i]", Pico.m.dma_bytes, dma_op1, bytes_can, burn, Pico.m.scanline, SekCyclesDone());\r
+ elprintf(EL_VDPDMA, "~Dma %i op=%i can=%i burn=%i [%i]", Pico.m.dma_xfers, dma_op1, xfers_can, burn, SekCyclesDone());\r
//dprintf("~aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);\r
return burn;\r
}\r
{\r
int cyc_do;\r
SekCycleAim+=cyc;\r
- //dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);\r
+ //printf("aim: %i, cnt: %i\n", SekCycleAim, SekCycleCnt);\r
if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
- //dprintf("cyc_do: %i", cyc_do);\r
+ //printf("cyc_do: %i\n", cyc_do);\r
#if defined(EMU_C68K) && defined(EMU_M68K)\r
// this means we do run-compare Cyclone vs Musashi\r
SekCycleCnt+=CM_compareRun(cyc_do);\r
static int curr_pos = 0;\r
\r
if(y == 224) {\r
- //dprintf("sta%i: %i [%i]", (emustatus & 2), emustatus, y);\r
if(emustatus & 2)\r
curr_pos += sound_render(curr_pos, PsndLen-PsndLen/2);\r
else curr_pos = sound_render(0, PsndLen);\r
}\r
}\r
\r
-//extern UINT32 mz80GetRegisterValue(void *, UINT32);\r
+\r
+#if 1*0\r
+int vint_delay = 205/*68*/, as_delay = 18/*148*/;\r
\r
// Accurate but slower frame which does hints\r
static int PicoFrameHints(void)\r
hint=pv->reg[10]; // Load H-Int counter\r
//dprintf("-hint: %i", hint);\r
\r
+ //SekRun(as_delay);\r
+ SekRun(148);\r
+\r
for (y=0;y<lines;y++)\r
{\r
Pico.m.scanline=(short)y;\r
\r
+ // VDP FIFO\r
+ pv->lwrite_cnt -= 12;\r
+ if (pv->lwrite_cnt < 0) pv->lwrite_cnt=0;\r
+ if (pv->lwrite_cnt == 0)\r
+ Pico.video.status|=0x200;\r
+\r
// pad delay (for 6 button pads)\r
if(PicoOpt&0x20) {\r
if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0;\r
//dprintf("rhint:old @ %06x", SekPc);\r
hint=pv->reg[10]; // Reload H-Int counter\r
pv->pending_ints|=0x10;\r
- if (pv->reg[0]&0x10) SekInterrupt(4);\r
- //dprintf("rhint: %i @ %06x [%i|%i]", hint, SekPc, y, SekCycleCnt);\r
+ if (pv->reg[0]&0x10) {\r
+ elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);\r
+ SekInterrupt(4);\r
+ }\r
//dprintf("hint_routine: %x", (*(unsigned short*)(Pico.ram+0x0B84)<<16)|*(unsigned short*)(Pico.ram+0x0B86));\r
}\r
\r
// V-Interrupt:\r
if (y == lines_vis)\r
{\r
- dprintf("vint: @ %06x [%i|%i], aim=%i cnt=%i", SekPc, y, SekCycleCnt, SekCycleAim, SekCycleCnt);\r
pv->status|=0x08; // go into vblank\r
- if(!Pico.m.dma_bytes||(Pico.video.reg[0x17]&0x80)) {\r
+ //pv->status|=0x80; // V-Int happened\r
+ //if(!Pico.m.dma_bytes||(Pico.video.reg[0x17]&0x80)) {\r
// there must be a gap between H and V ints, also after vblank bit set (Mazin Saga, Bram Stoker's Dracula)\r
- SekRun(128); SekCycleAim-=128; // 128; ?\r
- }\r
- dprintf("[%i|%i], aim=%i cnt=%i @ %x", y, SekCycleCnt, SekCycleAim, SekCycleCnt, SekPc);\r
- pv->status|=0x80; // V-Int happened\r
+ SekRun(68); SekCycleAim-=68; // 128; ?\r
+ SekCycleAim-=148;\r
+// SekRun(vint_delay); SekCycleAim-=vint_delay; // 128; ?\r
+// SekCycleAim-=as_delay;\r
+ //}\r
pv->pending_ints|=0x20;\r
- if(pv->reg[1]&0x20) SekInterrupt(6);\r
+ if(pv->reg[1]&0x20) {\r
+ elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);\r
+ SekInterrupt(6);\r
+ }\r
if(Pico.m.z80Run && (PicoOpt&4)) // ?\r
z80_int();\r
//dprintf("zint: [%i|%i] zPC=%04x", Pico.m.scanline, SekCyclesDone(), mz80GetRegisterValue(NULL, 0));\r
getSamples(y);\r
\r
// Run scanline:\r
- if (Pico.m.dma_bytes) SekCyclesBurn(CheckDMA());\r
+ if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());\r
SekRun(cycles_68k);\r
if ((PicoOpt&4) && Pico.m.z80Run) {\r
if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80;\r
\r
return 0;\r
}\r
+#else\r
+#include "PicoFrameHints.c"\r
+#endif\r
\r
// helper z80 runner\r
static void PicoRunZ80Simple(int line_from, int line_to)\r
int y=0,line=0,lines=0,lines_step=0,sects;\r
int cycles_68k_vblock,cycles_68k_block;\r
\r
- // we don't emulate DMA timing in this mode\r
- if (Pico.m.dma_bytes) {\r
- Pico.m.dma_bytes=0;\r
- Pico.video.status&=~2;\r
- }\r
-\r
if (Pico.m.pal) {\r
// M68k cycles/frame: 152009.78\r
if(pv->reg[1]&8) { // 240 lines\r
lines_step = 14;\r
}\r
\r
+ // we don't emulate DMA timing in this mode\r
+ if (Pico.m.dma_xfers) {\r
+ Pico.m.dma_xfers=0;\r
+ Pico.video.status&=~2;\r
+ }\r
+\r
+ // VDP FIFO too\r
+ pv->lwrite_cnt = 0;\r
+ Pico.video.status|=0x200;\r
+\r
Pico.m.scanline=-1;\r
\r
SekCyclesReset();\r
\r
- if(PicoOpt&4)\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
\r
// ---- Active Scan ----\r
- pv->status&=~88; // clear V-Int, come out of vblank\r
+ pv->status&=~0x88; // clear V-Int, come out of vblank\r
\r
// Run in sections:\r
for(sects=16; sects; sects--)\r
//dprintf("vint: @ %06x [%i]", SekPc, SekCycleCnt);\r
pv->pending_ints|=0x20;\r
if (pv->reg[1]&0x20) SekInterrupt(6); // Set IRQ\r
- pv->status|=0x88; // V-Int happened / go into vblank\r
+ pv->status|=8; // go into vblank\r
if(Pico.m.z80Run && (PicoOpt&4)) // ?\r
z80_int();\r
\r
code2 = sprite[1];\r
sx = (code2>>16)&0x1ff;\r
\r
- dprintf("#%02i x: %03i y: %03i %ix%i", u, sx, sy, ((code>>26)&3)+1, height);\r
+ printf("#%02i x: %03i y: %03i %ix%i\n", u, sx, sy, ((code>>26)&3)+1, height);\r
\r
link=(code>>16)&0x7f;\r
if(!link) break; // End of sprites\r
--- /dev/null
+#define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
+#define CYCLES_M68K_VINT_LAG 68
+#define CYCLES_M68K_ASD 148
+#define CYCLES_Z80_LINE 228
+#define CYCLES_Z80_ASD 69
+
+// pad delay (for 6 button pads)
+#define PAD_DELAY \
+ if (PicoOpt&0x20) { \
+ if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0; \
+ if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0; \
+ }
+
+#define Z80_RUN(z80_cycles) \
+{ \
+ if ((PicoOpt&4) && Pico.m.z80Run) \
+ { \
+ if (Pico.m.z80Run & 2) z80CycleAim += z80_cycles; \
+ else { \
+ int cnt = SekCyclesDone() - z80startCycle; \
+ cnt = (cnt>>1)-(cnt>>5); \
+ if (cnt > (z80_cycles)) cnt = z80_cycles; \
+ Pico.m.z80Run |= 2; \
+ z80CycleAim+=cnt; \
+ } \
+ total_z80+=z80_run(z80CycleAim-total_z80); \
+ } \
+}
+
+// Accurate but slower frame which does hints
+static int PicoFrameHints(void)
+{
+ struct PicoVideo *pv=&Pico.video;
+ int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample;
+ int skip=PicoSkipFrame || (PicoOpt&0x10);
+ int hint; // Hint counter
+
+ if (Pico.m.pal) {
+ //cycles_68k = (int) ((double) OSC_PAL / 7 / 50 / 312 + 0.4); // should compile to a constant (488)
+ //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228
+ line_sample = 68;
+ if(pv->reg[1]&8) lines_vis = 240;
+ } else {
+ //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488
+ //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228
+ line_sample = 93;
+ }
+
+ SekCyclesReset();
+
+ pv->status&=~0x88; // clear V-Int, come out of vblank
+
+ hint=pv->reg[10]; // Load H-Int counter
+ //dprintf("-hint: %i", hint);
+
+ // This is to make active scan longer (needed for Double Dragon 2, mainly)
+ SekRun(CYCLES_M68K_ASD);
+ Z80_RUN(CYCLES_Z80_ASD);
+
+ for (y=0;y<lines_vis;y++)
+ {
+ Pico.m.scanline=(short)y;
+
+ // VDP FIFO
+ pv->lwrite_cnt -= 12;
+ if (pv->lwrite_cnt <= 0) {
+ pv->lwrite_cnt=0;
+ Pico.video.status|=0x200;
+ }
+
+ PAD_DELAY
+
+ // H-Interrupts:
+ if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
+ {
+ hint=pv->reg[10]; // Reload H-Int counter
+ pv->pending_ints|=0x10;
+ if (pv->reg[0]&0x10) {
+ elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
+ SekInterrupt(4);
+ }
+ }
+
+ // decide if we draw this line
+#if CAN_HANDLE_240_LINES
+ if(!skip && ((!(pv->reg[1]&8) && y<224) || (pv->reg[1]&8)) )
+#else
+ if(!skip && y<224)
+#endif
+ PicoLine(y);
+
+ if(PicoOpt&1)
+ sound_timers_and_dac(y);
+
+ // get samples from sound chips
+ if(y == 32 && PsndOut)
+ emustatus &= ~1;
+ else if((y == 224 || y == line_sample) && PsndOut)
+ getSamples(y);
+
+ // Run scanline:
+ if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
+ SekRun(CYCLES_M68K_LINE);
+ Z80_RUN(CYCLES_Z80_LINE);
+ }
+
+ // V-int line (224 or 240)
+ Pico.m.scanline=(short)y;
+
+ // VDP FIFO
+ pv->lwrite_cnt=0;
+ Pico.video.status|=0x200;
+
+ PAD_DELAY
+
+ // Last H-Int:
+ if (--hint < 0)
+ {
+ hint=pv->reg[10]; // Reload H-Int counter
+ pv->pending_ints|=0x10;
+ //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCycleCnt);
+ if (pv->reg[0]&0x10) SekInterrupt(4);
+ }
+
+ // V-Interrupt:
+ pv->status|=0x08; // go into vblank
+ pv->pending_ints|=0x20;
+
+ // the following SekRun is there for several reasons:
+ // there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
+ // also delay between F bit (bit 7) is set in SR and IRQ happens (Ex-Mutants)
+ // also delay between last H-int and V-int (Golden Axe 3)
+ SekRun(CYCLES_M68K_VINT_LAG);
+ if (pv->reg[1]&0x20) {
+ elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
+ SekInterrupt(6);
+ }
+ if (Pico.m.z80Run && (PicoOpt&4))
+ z80_int();
+
+ if (PicoOpt&1)
+ sound_timers_and_dac(y);
+
+ // get samples from sound chips
+ if ((y == 224) && PsndOut)
+ getSamples(y);
+
+ // Run scanline:
+ if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
+ SekRun(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
+ Z80_RUN(CYCLES_Z80_LINE - CYCLES_Z80_ASD);
+
+ // PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
+ lines = Pico.m.pal ? 312 : 262;
+
+ for (y++;y<lines;y++)
+ {
+ Pico.m.scanline=(short)y;
+
+ PAD_DELAY
+
+ if(PicoOpt&1)
+ sound_timers_and_dac(y);
+
+ // Run scanline:
+ if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
+ SekRun(CYCLES_M68K_LINE);
+ Z80_RUN(CYCLES_Z80_LINE);
+ }
+
+ // draw a frame just after vblank in alternative render mode
+ if (!PicoSkipFrame && (PicoOpt&0x10))
+ PicoFrameFull();
+
+ return 0;
+}
+
+#undef PAD_DELAY
+#undef Z80_RUN
+
static int SekIntAck(int level)\r
{\r
// try to emulate VDP's reaction to 68000 int ack\r
- if (level == 4) Pico.video.pending_ints = 0;\r
- else if(level == 6) Pico.video.pending_ints &= ~0x20;\r
+ if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }\r
+ else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }\r
PicoCpu.irq = 0;\r
return CYCLONE_INT_ACK_AUTOVECTOR;\r
}\r
\r
-static void SekResetAck()\r
+static void SekResetAck(void)\r
{\r
-#if defined(__DEBUG_PRINT) || defined(WIN32)\r
- dprintf("Reset encountered @ %06x", SekPc);\r
-#endif\r
+ elprintf(EL_ANOMALY, "Reset encountered @ %06x", SekPc);\r
}\r
\r
static int SekUnrecognizedOpcode()\r
unsigned int pc, op;\r
pc = SekPc;\r
op = PicoCpu.read16(pc);\r
-#if defined(__DEBUG_PRINT) || defined(WIN32)\r
- dprintf("Unrecognized Opcode %04x @ %06x", op, pc);\r
-#endif\r
+ elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc);\r
// see if we are not executing trash\r
if (pc < 0x200 || (pc > Pico.romsize+4 && (pc&0xe00000)!=0xe00000)) {\r
PicoCpu.cycles = 0;\r
#ifdef EMU_M68K\r
static int SekIntAckM68K(int level)\r
{\r
- if (level == 4) { Pico.video.pending_ints = 0; dprintf("hack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); }\r
- else if(level == 6) { Pico.video.pending_ints &= ~0x20; dprintf("vack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); }\r
+ if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }\r
+ else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }\r
CPU_INT_LEVEL = 0;\r
return M68K_INT_ACK_AUTOVECTOR;\r
}\r
#endif\r
\r
\r
-static __inline void AutoIncrement()\r
+static __inline void AutoIncrement(void)\r
{\r
Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);\r
}\r
Pico.vram [(a>>1)&0x7fff]=d;\r
rendstatus|=0x10; break;\r
case 3: Pico.m.dirtyPal = 1;\r
- //dprintf("w[%i] @ %04x, inc=%i [%i|%i]", Pico.video.type, a, Pico.video.reg[0xf], Pico.m.scanline, SekCyclesDone());\r
Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)\r
case 5: Pico.vsram[(a>>1)&0x003f]=d; break;\r
+ default:elprintf(EL_ANOMALY, "VDP write %04x with bad type %i", d, Pico.video.type); break;\r
}\r
\r
//dprintf("w[%i] @ %04x, inc=%i [%i|%i]", Pico.video.type, a, Pico.video.reg[0xf], Pico.m.scanline, SekCyclesDone());\r
AutoIncrement();\r
}\r
\r
-static unsigned int VideoRead()\r
+static unsigned int VideoRead(void)\r
{\r
unsigned int a=0,d=0;\r
\r
case 0: d=Pico.vram [a&0x7fff]; break;\r
case 8: d=Pico.cram [a&0x003f]; break;\r
case 4: d=Pico.vsram[a&0x003f]; break;\r
+ default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break;\r
}\r
\r
AutoIncrement();\r
return d;\r
}\r
\r
-static int GetDmaLength()\r
+static int GetDmaLength(void)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
int len=0;\r
source|=Pico.video.reg[0x16]<<9;\r
source|=Pico.video.reg[0x17]<<17;\r
\r
- dprintf("DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i|%i] @ %x",\r
+ elprintf(EL_VDPDMA, "DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i] @ %06x",\r
Pico.video.type, source, a, len, inc, (Pico.video.status&8)||!(Pico.video.reg[1]&0x40),\r
- Pico.m.scanline, SekCyclesDone(), SekPc);\r
+ SekCyclesDone(), SekPc);\r
\r
if(Pico.m.scanline != -1) {\r
- Pico.m.dma_bytes += len;\r
+ Pico.m.dma_xfers += len;\r
if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCyclesBurn(CheckDMA());\r
else SekSetCyclesLeftNoMCD(SekCyclesLeftNoMCD - CheckDMA());\r
} else {\r
pd=(u16 *)(Pico.ram+(source&0xfffe));\r
pdend=(u16 *)(Pico.ram+0x10000);\r
} else if(PicoMCD & 1) {\r
- dprintf("DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);\r
+ elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);\r
if(source<0x20000) { // Bios area\r
pd=(u16 *)(Pico_mcd->bios+(source&~1));\r
pdend=(u16 *)(Pico_mcd->bios+0x20000);\r
int bank = Pico_mcd->s68k_regs[3]&1;\r
pd=(u16 *)(Pico_mcd->word_ram1M[bank]+(source&0x1fffe));\r
pdend=(u16 *)(Pico_mcd->word_ram1M[bank]+0x20000);\r
- } else {\r
+ } else {\r
DmaSlowCell(source, a, len, inc);\r
return;\r
- }\r
+ }\r
}\r
} else if ((source&0xfe0000)==0x020000) { // Prg Ram\r
u8 *prg_ram = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
pd=(u16 *)(prg_ram+(source&0x1fffe));\r
pdend=(u16 *)(prg_ram+0x20000);\r
} else {\r
- dprintf("DmaSlow FIXME: unsupported src");\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow FIXME: unsupported src");\r
return;\r
}\r
} else {\r
pd=(u16 *)(Pico.rom+(source&~1));\r
pdend=(u16 *)(Pico.rom+Pico.romsize);\r
} else {\r
- dprintf("DmaSlow: invalid dma src");\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow: invalid dma src");\r
return;\r
}\r
}\r
// overflow protection, might break something..\r
if (len > pdend - pd) {\r
len = pdend - pd;\r
- dprintf("DmaSlow overflow");\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow overflow");\r
}\r
\r
switch (Pico.video.type)\r
}\r
a=(a&0xff00)|a2;\r
break;\r
+\r
+ default:\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\r
+ break;\r
}\r
// remember addr\r
Pico.video.addr=(u16)a;\r
unsigned char *vrs;\r
unsigned char inc=Pico.video.reg[0xf];\r
int source;\r
- dprintf("DmaCopy len %i [%i|%i]", len, Pico.m.scanline, SekCyclesDone());\r
+ elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());\r
\r
- Pico.m.dma_bytes += len;\r
+ Pico.m.dma_xfers += len;\r
if(Pico.m.scanline != -1)\r
Pico.video.status|=2; // dma busy\r
\r
unsigned char inc=Pico.video.reg[0xf];\r
\r
len=GetDmaLength();\r
- dprintf("DmaFill len %i inc %i [%i|%i]", len, inc, Pico.m.scanline, SekCyclesDone());\r
+ elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());\r
\r
- Pico.m.dma_bytes += len;\r
+ Pico.m.dma_xfers += len;\r
if(Pico.m.scanline != -1)\r
Pico.video.status|=2; // dma busy (in accurate mode)\r
\r
rendstatus|=0x10;\r
}\r
\r
-static void CommandDma()\r
+static void CommandDma(void)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
int len=0,method=0;\r
if (method==3) DmaCopy(len); // VRAM Copy\r
}\r
\r
-static void CommandChange()\r
+static void CommandChange(void)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
unsigned int cmd=0,addr=0;\r
addr =(cmd>>16)&0x3fff;\r
addr|=(cmd<<14)&0xc000;\r
pvid->addr=(unsigned short)addr;\r
- //dprintf("addr set: %04x", addr);\r
\r
// Check for dma:\r
if (cmd&0x80) CommandDma();\r
\r
if (a==0x00) // Data port 0 or 2\r
{\r
- if (pvid->pending) CommandChange();\r
- pvid->pending=0;\r
+ if (pvid->pending) {\r
+ CommandChange();\r
+ pvid->pending=0;\r
+ }\r
\r
// If a DMA fill has been set up, do it\r
if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
}\r
else\r
{\r
+ // preliminary FIFO emulation for Chaos Engine, The (E)\r
+ if(!(pvid->status&8) && (pvid->reg[1]&0x40) && Pico.m.scanline!=-1) // active display, accurate mode?\r
+ {\r
+ pvid->status&=~0x200; // FIFO no longer empty\r
+ pvid->lwrite_cnt++;\r
+ if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
+ if (pvid->lwrite_cnt > 4) {\r
+ SekCyclesBurn(32); // penalty // 488/12-8\r
+ if (SekCycleCnt>=SekCycleAim) SekEndRun(0);\r
+ }\r
+ elprintf(EL_ASVDP, "VDP data write: %04x {%i} #%i @ %06x", d, Pico.video.type, pvid->lwrite_cnt, SekPc);\r
+ }\r
VideoWrite(d);\r
}\r
return;\r
\r
if (a==0x04) // Control (command) port 4 or 6\r
{\r
- //dprintf("vdp cw(%04x), p=%i @ %06x [%i]", d, pvid->pending, SekPc, SekCyclesDone());\r
if(pvid->pending)\r
{\r
// Low word of command:\r
{\r
// Register write:\r
int num=(d>>8)&0x1f;\r
- if(num==00) dprintf("hint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[0]&0x10)>>4, (d&0x10)>>4, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
- if(num==01) dprintf("vint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[1]&0x20)>>5, (d&0x20)>>5, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
+ if(num==00) elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (pvid->reg[0]&0x10)>>4,\r
+ (d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
+ if(num==01) elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (pvid->reg[1]&0x20)>>5,\r
+ (d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
//if(num==01) dprintf("set_blank: %i @ %06x [%i|%i]", !((d&0x40)>>6), SekPc, Pico.m.scanline, SekCyclesDone());\r
- //if(num==05) dprintf("spr_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone());\r
//if(num==10) dprintf("hint_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone());\r
pvid->reg[num]=(unsigned char)d;\r
#if !(defined(EMU_C68K) && defined(EMU_M68K)) // not debugging Cyclone\r
// update IRQ level (Lemmings, Wiz 'n' Liz intro, ... )\r
// may break if done improperly:\r
- // International Superstar Soccer Deluxe (crash), Street Racer (logos), Burning Force (gfx), Fatal Rewind (hang), Sesame Street Counting Cafe\r
+ // International Superstar Soccer Deluxe (crash), Street Racer (logos), Burning Force (gfx),\r
+ // Fatal Rewind (hang), Sesame Street Counting Cafe\r
if(num < 2) {\r
#ifdef EMU_C68K\r
// hack: make sure we do not touch the irq line if Cyclone is just about to take the IRQ\r
\r
a&=0x1c;\r
\r
+\r
if (a==0x00) // data port\r
{\r
d=VideoRead();\r
\r
if (a==0x04) // control port\r
{\r
- d=Pico.video.status;\r
- if(PicoOpt&0x10) d|=0x0020; // sprite collision (Shadow of the Beast)\r
- if(Pico.m.rotate++&8) d|=0x0100; else d|=0x0200; // Toggle fifo full empty (who uses that stuff?)\r
- if(!(Pico.video.reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled\r
- if(SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)\r
- // dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone());\r
+ struct PicoVideo *pv=&Pico.video;\r
+ d=pv->status;\r
+ if (PicoOpt&0x10) d|=0x0020; // sprite collision (Shadow of the Beast)\r
+ if (!(pv->reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled\r
+ if (SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)\r
+\r
+ d|=(pv->pending_ints&0x20)<<2; // V-int pending?\r
+ if (d&0x100) pv->status&=~0x100; // FIFO no longer full\r
\r
- Pico.video.pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
+ pv->pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
\r
+ elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc);\r
goto end;\r
}\r
\r
if (d&0xf00) d|= 1;\r
}\r
\r
- dprintf("hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);\r
+ elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);\r
d&=0xff; d<<=8;\r
d|=hc;\r
goto end;\r
dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
}\r
\r
-\r
+#define _CD_MEMORY_C\r
#undef _ASM_MEMORY_C\r
#include "../MemoryCmn.c"\r
#include "cell_map.c"\r
Pico_mcd->m.timer_int3 -= counter_timer;
if (Pico_mcd->m.timer_int3 < 0) {
if (Pico_mcd->s68k_regs[0x33] & (1<<3)) {
- dprintf("s68k: timer irq 3");
+ elprintf(EL_INTS, "s68k: timer irq 3");
SekInterruptS68k(3);
Pico_mcd->m.timer_int3 += int3_set << 16;
}
// Run scanline:
//dprintf("m68k starting exec @ %06x", SekPc);
- if (Pico.m.dma_bytes) SekCycleCnt+=CheckDMA();
+ if (Pico.m.dma_xfers) SekCycleCnt+=CheckDMA();
if ((PicoOpt & 0x2000) && (Pico_mcd->m.busreq&3) == 1) {
SekRunPS(cycles_68k, cycles_s68k); // "better/perfect sync"
} else {
\r
static unsigned char DrZ80_in(unsigned short p)\r
{\r
+ elprintf(EL_ANOMALY, "Z80 port %04x read", p);\r
return 0xff;\r
}\r
\r
static void DrZ80_out(unsigned short p,unsigned char d)\r
{\r
+ elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d);\r
}\r
\r
static void DrZ80_irq_callback()\r
\r
#if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES\r
// this is a bit hacky\r
- if ((tea==0x39||(tea&0x38)==0x10)&&size>=1)\r
+ if ((tea==0x39||(tea>=0x10&&tea<0x30))&&size>=1)\r
ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");\r
#endif\r
\r
endif\r
\r
DEFINC = -I../.. -I. -DARM -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK\r
-COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
+COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math -Winline\r
ifeq "$(profile)" "1"\r
COPT_COMMON += -fprofile-generate\r
endif\r
// pico.c\r
#define CAN_HANDLE_240_LINES 1\r
\r
+// logging emu events\r
+#define EL_LOGMASK 0 // (EL_STATUS|EL_ANOMALY) // xffff\r
+\r
//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)\r
#define dprintf(x...)\r
\r
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+#include <semaphore.h>
#include <gtk/gtk.h>
#include <unistd.h>
return 0;
}
-static void *gtk_threadf(void *none)
-{
- gtk_main();
-
- printf("linux: gtk thread finishing\n");
- engineState = PGS_Quit;
-
- return NULL;
-}
-
-static void gtk_initf(void)
+static void *gtk_threadf(void *targ)
{
int argc = 0;
char *argv[] = { "" };
GtkWidget *box;
- pthread_t gtk_thread;
+ sem_t *sem = targ;
g_thread_init (NULL);
gdk_threads_init ();
gtk_widget_show (gtk_items.window);
- // pthread_mutex_init (&thr_mutex, NULL);
- // pthread_mutex_lock (&thr_mutex);
- // pthread_mutex_init (&scanner_muttex, NULL);
+ sem_post(sem);
+
+ gtk_main();
+
+ printf("linux: gtk thread finishing\n");
+ exit(1);
+
+ return NULL;
+}
+
+static void gtk_initf(void)
+{
+ pthread_t gtk_thread;
+ sem_t sem;
+ sem_init(&sem, 0, 0);
+
+ pthread_create(>k_thread, NULL, gtk_threadf, &sem);
+ pthread_detach(gtk_thread);
- pthread_create(>k_thread, NULL, gtk_threadf, NULL);
+ sem_wait(&sem);
+ sem_close(&sem);
}
void finalize_image(guchar *pixels, gpointer data)
// pico.c
#define CAN_HANDLE_240_LINES 1
+#define EL_LOGMASK (EL_ANOMALY|EL_STATUS|EL_VDPDMA|EL_ASVDP|EL_SR) // |EL_BUSREQ|EL_Z80BNK)
+
//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
#define dprintf(x...)