new acc mode timing, VDP FIFO code

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@244 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-09-11 20:52:21 +00:00
parent 83c093a48a
commit 69996cb7c6
14 changed files with 373 additions and 132 deletions

View file

@ -81,7 +81,10 @@ static u32 CPU_CALL PicoCheckPc(u32 pc)
// pc&=0xfffffe;
pc&=~1;
if ((pc<<8) == 0)
{
printf("%i:%03i: game crash detected @ %06x\n", Pico.m.frame_count, Pico.m.scanline, SekPc);
return (int)Pico.rom + Pico.romsize; // common crash condition, can happen if acc timing is off
}
PicoCpu.membase=PicoMemBase(pc&0x00ffffff);
PicoCpu.membase-=pc&0xff000000;
@ -697,13 +700,15 @@ PICO_INTERNAL unsigned char z80_read(unsigned short a)
addr68k+=a&0x7fff;
ret = (u8) PicoRead8(addr68k);
//dprintf("z80->68k w8 : %06x, %02x", addr68k, ret);
elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);
goto end;
}
// should not be needed || dprintf("z80_read RAM");
if (a<0x4000) { ret = (u8) Pico.zram[a&0x1fff]; goto end; }
elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, ret);
end:
return ret;
}
@ -745,13 +750,15 @@ PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a)
u32 addr68k;
addr68k=Pico.m.z80_bank68k<<15;
addr68k+=a&0x7fff;
elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data);
PicoWrite8(addr68k, data);
//dprintf("z80->68k w8 : %06x, %02x", addr68k, data);
return;
}
// should not be needed, drZ80 knows how to access RAM itself || dprintf("z80_write RAM @ %08x", lr);
if (a<0x4000) { Pico.zram[a&0x1fff]=data; return; }
elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);
}
PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a)

View file

@ -55,11 +55,14 @@ u32 z80ReadBusReq(void)
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;
}
@ -80,16 +83,19 @@ void z80WriteBusReq(u32 d)
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 {
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;
}
@ -115,7 +121,6 @@ u32 OtherRead16(u32 a, int realsize)
// 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;
}
@ -124,7 +129,7 @@ u32 OtherRead16(u32 a, int realsize)
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;
@ -214,6 +219,7 @@ void OtherWrite16(u32 a,u32 d)
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);
@ -225,8 +231,10 @@ void OtherWrite16(u32 a,u32 d)
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
}

View file

@ -10,7 +10,7 @@
#include "PicoInt.h"
#include "sound/ym2612.h"
int PicoVer=0x0110;
int PicoVer=0x0133;
struct Pico Pico;
int PicoOpt=0; // disable everything by default
int PicoSkipFrame=0; // skip rendering frame?
@ -38,7 +38,6 @@ int PicoInit(void)
PicoInitMCD();
// notaz: sram
SRam.data=0;
SRam.resize=1;
@ -52,7 +51,6 @@ void PicoExit(void)
PicoExitMCD();
z80_exit();
// notaz: sram
if(SRam.data) free(SRam.data); SRam.data=0;
}
@ -151,8 +149,6 @@ int PicoReset(int hard)
return 0;
}
// notaz: sram
if(SRam.resize) {
int sram_size = 0;
if(SRam.data) free(SRam.data); SRam.data=0;
@ -160,7 +156,7 @@ int PicoReset(int hard)
if(*(Pico.rom+0x1B1) == 'R' && *(Pico.rom+0x1B0) == 'A') {
if(*(Pico.rom+0x1B2) & 0x40) {
// EEPROM SRAM
// EEPROM
// what kind of EEPROMs are actually used? X24C02? X24C04? (X24C01 has only 128), but we will support up to 8K
SRam.start = PicoRead32(0x1B4) & ~1; // zero address is used for clock by some games
SRam.end = PicoRead32(0x1B8);
@ -193,7 +189,7 @@ 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",
elprintf(EL_STATUS, "sram: det: %i; eeprom: %i; start: %06x; end: %06x",
(Pico.m.sram_reg>>4)&1, (Pico.m.sram_reg>>2)&1, SRam.start, SRam.end);
}
@ -203,48 +199,45 @@ int PicoReset(int hard)
return 0;
}
static int dma_timings[] = {
// dma2vram settings are just hacks to unglitch Legend of Galahad (needs <= 104 to work)
// same for Outrunners (92-121, when active is set to 24)
static const 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 // ...
16, 16, 15, 8, // active: 32cell:
24, 18, 17, 9 // ...
};
static int dma_bsycles[] = {
(488<<8)/83, (488<<8)/167, (488<<8)/166, (488<<8)/83,
static const int dma_bsycles[] = {
(488<<8)/82, (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
(488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,
(488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9
};
PICO_INTERNAL 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 burn = 0, xfers_can, dma_op = Pico.video.reg[0x17]>>6; // see gens for 00 and 01 modes
int xfers = Pico.m.dma_xfers;
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) {
xfers_can = dma_timings[dma_op];
if(xfers <= xfers_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;
burn = xfers * dma_bsycles[dma_op] >> 8; // have to be approximate because can't afford division..
}
Pico.m.dma_bytes = 0;
Pico.m.dma_xfers = 0;
} else {
if(!(dma_op&2)) burn = 488;
Pico.m.dma_bytes -= bytes_can;
Pico.m.dma_xfers -= xfers_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());
elprintf(EL_VDPDMA, "~Dma %i op=%i can=%i burn=%i [%i]", Pico.m.dma_xfers, dma_op1, xfers_can, burn, SekCyclesDone());
//dprintf("~aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);
return burn;
}
@ -253,9 +246,9 @@ static __inline void SekRun(int cyc)
{
int cyc_do;
SekCycleAim+=cyc;
//dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);
//printf("aim: %i, cnt: %i\n", SekCycleAim, SekCycleCnt);
if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
//dprintf("cyc_do: %i", cyc_do);
//printf("cyc_do: %i\n", cyc_do);
#if defined(EMU_C68K) && defined(EMU_M68K)
// this means we do run-compare Cyclone vs Musashi
SekCycleCnt+=CM_compareRun(cyc_do);
@ -321,7 +314,6 @@ 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)
curr_pos += sound_render(curr_pos, PsndLen-PsndLen/2);
else curr_pos = sound_render(0, PsndLen);
@ -337,7 +329,9 @@ static __inline void getSamples(int y)
}
}
//extern UINT32 mz80GetRegisterValue(void *, UINT32);
#if 1*0
int vint_delay = 205/*68*/, as_delay = 18/*148*/;
// Accurate but slower frame which does hints
static int PicoFrameHints(void)
@ -373,10 +367,19 @@ static int PicoFrameHints(void)
hint=pv->reg[10]; // Load H-Int counter
//dprintf("-hint: %i", hint);
//SekRun(as_delay);
SekRun(148);
for (y=0;y<lines;y++)
{
Pico.m.scanline=(short)y;
// VDP FIFO
pv->lwrite_cnt -= 12;
if (pv->lwrite_cnt < 0) pv->lwrite_cnt=0;
if (pv->lwrite_cnt == 0)
Pico.video.status|=0x200;
// pad delay (for 6 button pads)
if(PicoOpt&0x20) {
if(Pico.m.padDelay[0]++ > 25) Pico.m.padTHPhase[0]=0;
@ -389,24 +392,30 @@ static int PicoFrameHints(void)
//dprintf("rhint:old @ %06x", SekPc);
hint=pv->reg[10]; // Reload H-Int counter
pv->pending_ints|=0x10;
if (pv->reg[0]&0x10) SekInterrupt(4);
//dprintf("rhint: %i @ %06x [%i|%i]", hint, SekPc, y, SekCycleCnt);
if (pv->reg[0]&0x10) {
elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCycleCnt);
SekInterrupt(4);
}
//dprintf("hint_routine: %x", (*(unsigned short*)(Pico.ram+0x0B84)<<16)|*(unsigned short*)(Pico.ram+0x0B86));
}
// V-Interrupt:
if (y == lines_vis)
{
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)) {
//pv->status|=0x80; // V-Int happened
//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
SekRun(68); SekCycleAim-=68; // 128; ?
SekCycleAim-=148;
// SekRun(vint_delay); SekCycleAim-=vint_delay; // 128; ?
// SekCycleAim-=as_delay;
//}
pv->pending_ints|=0x20;
if(pv->reg[1]&0x20) SekInterrupt(6);
if(pv->reg[1]&0x20) {
elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCycleCnt);
SekInterrupt(6);
}
if(Pico.m.z80Run && (PicoOpt&4)) // ?
z80_int();
//dprintf("zint: [%i|%i] zPC=%04x", Pico.m.scanline, SekCyclesDone(), mz80GetRegisterValue(NULL, 0));
@ -430,7 +439,7 @@ static int PicoFrameHints(void)
getSamples(y);
// Run scanline:
if (Pico.m.dma_bytes) SekCyclesBurn(CheckDMA());
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
SekRun(cycles_68k);
if ((PicoOpt&4) && Pico.m.z80Run) {
if (Pico.m.z80Run & 2) z80CycleAim+=cycles_z80;
@ -452,6 +461,9 @@ static int PicoFrameHints(void)
return 0;
}
#else
#include "PicoFrameHints.c"
#endif
// helper z80 runner
static void PicoRunZ80Simple(int line_from, int line_to)
@ -483,12 +495,6 @@ static int PicoFrameSimple(void)
int y=0,line=0,lines=0,lines_step=0,sects;
int cycles_68k_vblock,cycles_68k_block;
// 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
@ -507,18 +513,25 @@ static int PicoFrameSimple(void)
lines_step = 14;
}
// we don't emulate DMA timing in this mode
if (Pico.m.dma_xfers) {
Pico.m.dma_xfers=0;
Pico.video.status&=~2;
}
// VDP FIFO too
pv->lwrite_cnt = 0;
Pico.video.status|=0x200;
Pico.m.scanline=-1;
SekCyclesReset();
if(PicoOpt&4)
z80_resetCycles();
// 6 button pad: let's just say it timed out now
Pico.m.padTHPhase[0]=Pico.m.padTHPhase[1]=0;
// ---- Active Scan ----
pv->status&=~88; // clear V-Int, come out of vblank
pv->status&=~0x88; // clear V-Int, come out of vblank
// Run in sections:
for(sects=16; sects; sects--)
@ -588,7 +601,7 @@ static int PicoFrameSimple(void)
//dprintf("vint: @ %06x [%i]", SekPc, SekCycleCnt);
pv->pending_ints|=0x20;
if (pv->reg[1]&0x20) SekInterrupt(6); // Set IRQ
pv->status|=0x88; // V-Int happened / go into vblank
pv->status|=8; // go into vblank
if(Pico.m.z80Run && (PicoOpt&4)) // ?
z80_int();
@ -724,7 +737,7 @@ char *debugString(void)
code2 = sprite[1];
sx = (code2>>16)&0x1ff;
dprintf("#%02i x: %03i y: %03i %ix%i", u, sx, sy, ((code>>26)&3)+1, height);
printf("#%02i x: %03i y: %03i %ix%i\n", u, sx, sy, ((code>>26)&3)+1, height);
link=(code>>16)&0x7f;
if(!link) break; // End of sprites

180
Pico/PicoFrameHints.c Normal file
View file

@ -0,0 +1,180 @@
#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

View file

@ -46,17 +46,15 @@ static int (*ResetCallback)()=DoReset;
static int SekIntAck(int level)
{
// try to emulate VDP's reaction to 68000 int ack
if (level == 4) Pico.video.pending_ints = 0;
else if(level == 6) Pico.video.pending_ints &= ~0x20;
if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }
else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }
PicoCpu.irq = 0;
return CYCLONE_INT_ACK_AUTOVECTOR;
}
static void SekResetAck()
static void SekResetAck(void)
{
#if defined(__DEBUG_PRINT) || defined(WIN32)
dprintf("Reset encountered @ %06x", SekPc);
#endif
elprintf(EL_ANOMALY, "Reset encountered @ %06x", SekPc);
}
static int SekUnrecognizedOpcode()
@ -64,9 +62,7 @@ static int SekUnrecognizedOpcode()
unsigned int pc, op;
pc = SekPc;
op = PicoCpu.read16(pc);
#if defined(__DEBUG_PRINT) || defined(WIN32)
dprintf("Unrecognized Opcode %04x @ %06x", op, pc);
#endif
elprintf(EL_ANOMALY, "Unrecognized Opcode %04x @ %06x", op, pc);
// see if we are not executing trash
if (pc < 0x200 || (pc > Pico.romsize+4 && (pc&0xe00000)!=0xe00000)) {
PicoCpu.cycles = 0;
@ -88,8 +84,8 @@ static int SekUnrecognizedOpcode()
#ifdef EMU_M68K
static int SekIntAckM68K(int level)
{
if (level == 4) { Pico.video.pending_ints = 0; dprintf("hack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); }
else if(level == 6) { Pico.video.pending_ints &= ~0x20; dprintf("vack: [%i|%i]", Pico.m.scanline, SekCyclesDone()); }
if (level == 4) { Pico.video.pending_ints = 0; elprintf(EL_INTS, "hack: @ %06x [%i]", SekPc, SekCycleCnt); }
else if(level == 6) { Pico.video.pending_ints &= ~0x20; elprintf(EL_INTS, "vack: @ %06x [%i]", SekPc, SekCycleCnt); }
CPU_INT_LEVEL = 0;
return M68K_INT_ACK_AUTOVECTOR;
}

View file

@ -23,7 +23,7 @@ typedef unsigned int u32;
#endif
static __inline void AutoIncrement()
static __inline void AutoIncrement(void)
{
Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);
}
@ -38,16 +38,16 @@ static void VideoWrite(u16 d)
Pico.vram [(a>>1)&0x7fff]=d;
rendstatus|=0x10; break;
case 3: Pico.m.dirtyPal = 1;
//dprintf("w[%i] @ %04x, inc=%i [%i|%i]", Pico.video.type, a, Pico.video.reg[0xf], Pico.m.scanline, SekCyclesDone());
Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)
case 5: Pico.vsram[(a>>1)&0x003f]=d; break;
default:elprintf(EL_ANOMALY, "VDP write %04x with bad type %i", d, Pico.video.type); break;
}
//dprintf("w[%i] @ %04x, inc=%i [%i|%i]", Pico.video.type, a, Pico.video.reg[0xf], Pico.m.scanline, SekCyclesDone());
AutoIncrement();
}
static unsigned int VideoRead()
static unsigned int VideoRead(void)
{
unsigned int a=0,d=0;
@ -58,13 +58,14 @@ static unsigned int VideoRead()
case 0: d=Pico.vram [a&0x7fff]; break;
case 8: d=Pico.cram [a&0x003f]; break;
case 4: d=Pico.vsram[a&0x003f]; break;
default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break;
}
AutoIncrement();
return d;
}
static int GetDmaLength()
static int GetDmaLength(void)
{
struct PicoVideo *pvid=&Pico.video;
int len=0;
@ -87,12 +88,12 @@ static void DmaSlow(int len)
source|=Pico.video.reg[0x16]<<9;
source|=Pico.video.reg[0x17]<<17;
dprintf("DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i|%i] @ %x",
elprintf(EL_VDPDMA, "DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i] @ %06x",
Pico.video.type, source, a, len, inc, (Pico.video.status&8)||!(Pico.video.reg[1]&0x40),
Pico.m.scanline, SekCyclesDone(), SekPc);
SekCyclesDone(), SekPc);
if(Pico.m.scanline != -1) {
Pico.m.dma_bytes += len;
Pico.m.dma_xfers += len;
if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCyclesBurn(CheckDMA());
else SekSetCyclesLeftNoMCD(SekCyclesLeftNoMCD - CheckDMA());
} else {
@ -104,7 +105,7 @@ static void DmaSlow(int len)
pd=(u16 *)(Pico.ram+(source&0xfffe));
pdend=(u16 *)(Pico.ram+0x10000);
} else if(PicoMCD & 1) {
dprintf("DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);
elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);
if(source<0x20000) { // Bios area
pd=(u16 *)(Pico_mcd->bios+(source&~1));
pdend=(u16 *)(Pico_mcd->bios+0x20000);
@ -128,7 +129,7 @@ static void DmaSlow(int len)
pd=(u16 *)(prg_ram+(source&0x1fffe));
pdend=(u16 *)(prg_ram+0x20000);
} else {
dprintf("DmaSlow FIXME: unsupported src");
elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow FIXME: unsupported src");
return;
}
} else {
@ -136,7 +137,7 @@ static void DmaSlow(int len)
pd=(u16 *)(Pico.rom+(source&~1));
pdend=(u16 *)(Pico.rom+Pico.romsize);
} else {
dprintf("DmaSlow: invalid dma src");
elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow: invalid dma src");
return;
}
}
@ -144,7 +145,7 @@ static void DmaSlow(int len)
// overflow protection, might break something..
if (len > pdend - pd) {
len = pdend - pd;
dprintf("DmaSlow overflow");
elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow overflow");
}
switch (Pico.video.type)
@ -203,6 +204,10 @@ static void DmaSlow(int len)
}
a=(a&0xff00)|a2;
break;
default:
elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);
break;
}
// remember addr
Pico.video.addr=(u16)a;
@ -215,9 +220,9 @@ static void DmaCopy(int len)
unsigned char *vrs;
unsigned char inc=Pico.video.reg[0xf];
int source;
dprintf("DmaCopy len %i [%i|%i]", len, Pico.m.scanline, SekCyclesDone());
elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());
Pico.m.dma_bytes += len;
Pico.m.dma_xfers += len;
if(Pico.m.scanline != -1)
Pico.video.status|=2; // dma busy
@ -249,9 +254,9 @@ static void DmaFill(int data)
unsigned char inc=Pico.video.reg[0xf];
len=GetDmaLength();
dprintf("DmaFill len %i inc %i [%i|%i]", len, inc, Pico.m.scanline, SekCyclesDone());
elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());
Pico.m.dma_bytes += len;
Pico.m.dma_xfers += len;
if(Pico.m.scanline != -1)
Pico.video.status|=2; // dma busy (in accurate mode)
@ -278,7 +283,7 @@ static void DmaFill(int data)
rendstatus|=0x10;
}
static void CommandDma()
static void CommandDma(void)
{
struct PicoVideo *pvid=&Pico.video;
int len=0,method=0;
@ -292,7 +297,7 @@ static void CommandDma()
if (method==3) DmaCopy(len); // VRAM Copy
}
static void CommandChange()
static void CommandChange(void)
{
struct PicoVideo *pvid=&Pico.video;
unsigned int cmd=0,addr=0;
@ -306,7 +311,6 @@ static void CommandChange()
addr =(cmd>>16)&0x3fff;
addr|=(cmd<<14)&0xc000;
pvid->addr=(unsigned short)addr;
//dprintf("addr set: %04x", addr);
// Check for dma:
if (cmd&0x80) CommandDma();
@ -320,8 +324,10 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
if (a==0x00) // Data port 0 or 2
{
if (pvid->pending) CommandChange();
if (pvid->pending) {
CommandChange();
pvid->pending=0;
}
// If a DMA fill has been set up, do it
if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)
@ -330,6 +336,18 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
}
else
{
// preliminary FIFO emulation for Chaos Engine, The (E)
if(!(pvid->status&8) && (pvid->reg[1]&0x40) && Pico.m.scanline!=-1) // active display, accurate mode?
{
pvid->status&=~0x200; // FIFO no longer empty
pvid->lwrite_cnt++;
if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full
if (pvid->lwrite_cnt > 4) {
SekCyclesBurn(32); // penalty // 488/12-8
if (SekCycleCnt>=SekCycleAim) SekEndRun(0);
}
elprintf(EL_ASVDP, "VDP data write: %04x {%i} #%i @ %06x", d, Pico.video.type, pvid->lwrite_cnt, SekPc);
}
VideoWrite(d);
}
return;
@ -337,7 +355,6 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
if (a==0x04) // Control (command) port 4 or 6
{
//dprintf("vdp cw(%04x), p=%i @ %06x [%i]", d, pvid->pending, SekPc, SekCyclesDone());
if(pvid->pending)
{
// Low word of command:
@ -350,16 +367,18 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
{
// Register write:
int num=(d>>8)&0x1f;
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);
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);
if(num==00) elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (pvid->reg[0]&0x10)>>4,
(d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);
if(num==01) elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (pvid->reg[1]&0x20)>>5,
(d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);
//if(num==01) dprintf("set_blank: %i @ %06x [%i|%i]", !((d&0x40)>>6), SekPc, Pico.m.scanline, SekCyclesDone());
//if(num==05) dprintf("spr_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone());
//if(num==10) dprintf("hint_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone());
pvid->reg[num]=(unsigned char)d;
#if !(defined(EMU_C68K) && defined(EMU_M68K)) // not debugging Cyclone
// update IRQ level (Lemmings, Wiz 'n' Liz intro, ... )
// may break if done improperly:
// International Superstar Soccer Deluxe (crash), Street Racer (logos), Burning Force (gfx), Fatal Rewind (hang), Sesame Street Counting Cafe
// International Superstar Soccer Deluxe (crash), Street Racer (logos), Burning Force (gfx),
// Fatal Rewind (hang), Sesame Street Counting Cafe
if(num < 2) {
#ifdef EMU_C68K
// hack: make sure we do not touch the irq line if Cyclone is just about to take the IRQ
@ -400,6 +419,7 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
a&=0x1c;
if (a==0x00) // data port
{
d=VideoRead();
@ -408,15 +428,18 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
if (a==0x04) // control port
{
d=Pico.video.status;
struct PicoVideo *pv=&Pico.video;
d=pv->status;
if (PicoOpt&0x10) d|=0x0020; // sprite collision (Shadow of the Beast)
if(Pico.m.rotate++&8) d|=0x0100; else d|=0x0200; // Toggle fifo full empty (who uses that stuff?)
if(!(Pico.video.reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled
if (!(pv->reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled
if (SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)
// dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone());
Pico.video.pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)
d|=(pv->pending_ints&0x20)<<2; // V-int pending?
if (d&0x100) pv->status&=~0x100; // FIFO no longer full
pv->pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)
elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc);
goto end;
}
@ -466,7 +489,7 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
if (d&0xf00) d|= 1;
}
dprintf("hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);
elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);
d&=0xff; d<<=8;
d|=hc;
goto end;

View file

@ -407,7 +407,7 @@ static void OtherWrite8End(u32 a, u32 d, int realsize)
dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc);
}
#define _CD_MEMORY_C
#undef _ASM_MEMORY_C
#include "../MemoryCmn.c"
#include "cell_map.c"

View file

@ -194,7 +194,7 @@ static __inline void update_chips(void)
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;
}
@ -319,7 +319,7 @@ static int PicoFrameHintsMCD(void)
// 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 {

View file

@ -310,11 +310,13 @@ static unsigned int DrZ80_rebaseSP(unsigned short a)
static unsigned char DrZ80_in(unsigned short p)
{
elprintf(EL_ANOMALY, "Z80 port %04x read", p);
return 0xff;
}
static void DrZ80_out(unsigned short p,unsigned char d)
{
elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d);
}
static void DrZ80_irq_callback()

View file

@ -150,7 +150,7 @@ int OpMove(int op)
#if CYCLONE_FOR_GENESIS && !MEMHANDLERS_CHANGE_CYCLES
// this is a bit hacky
if ((tea==0x39||(tea&0x38)==0x10)&&size>=1)
if ((tea==0x39||(tea>=0x10&&tea<0x30))&&size>=1)
ot(" ldr r5,[r7,#0x5c] ;@ Load Cycles\n");
#endif

View file

@ -32,7 +32,7 @@ use_cyclone = 1
endif
DEFINC = -I../.. -I. -DARM -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK
COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math
COPT_COMMON = -static -Wall -O2 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math -Winline
ifeq "$(profile)" "1"
COPT_COMMON += -fprofile-generate
endif

View file

@ -12,6 +12,9 @@
// pico.c
#define CAN_HANDLE_240_LINES 1
// logging emu events
#define EL_LOGMASK 0 // (EL_STATUS|EL_ANOMALY) // xffff
//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
#define dprintf(x...)

View file

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#include <gtk/gtk.h>
#include <unistd.h>
@ -98,22 +99,12 @@ static gint key_release_event (GtkWidget *widget, GdkEventKey *event)
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 ();
@ -149,11 +140,27 @@ static void gtk_initf(void)
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);
pthread_create(&gtk_thread, NULL, gtk_threadf, NULL);
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(&gtk_thread, NULL, gtk_threadf, &sem);
pthread_detach(gtk_thread);
sem_wait(&sem);
sem_close(&sem);
}
void finalize_image(guchar *pixels, gpointer data)

View file

@ -13,6 +13,8 @@
// 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...)