summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2014-03-22 12:50:40 +0100
committeraiju <devnull@localhost>2014-03-22 12:50:40 +0100
commit0d080855b2a1b8095f2a7d4c6f649685d20e3c42 (patch)
tree74986a06721fc044939e1a26cc95438910156bae
parentb13425e2b077de3d2562a8d6ebe5b8f6ab537f3d (diff)
downloadplan9front-0d080855b2a1b8095f2a7d4c6f649685d20e3c42.tar.xz
games/snes: cpu timing fix
-rw-r--r--sys/src/games/snes/cpu.c8
-rw-r--r--sys/src/games/snes/dat.h2
-rw-r--r--sys/src/games/snes/mem.c4
-rw-r--r--sys/src/games/snes/ppu.c4
-rw-r--r--sys/src/games/snes/snes.c8
5 files changed, 14 insertions, 12 deletions
diff --git a/sys/src/games/snes/cpu.c b/sys/src/games/snes/cpu.c
index c52683e80..602d4ca8f 100644
--- a/sys/src/games/snes/cpu.c
+++ b/sys/src/games/snes/cpu.c
@@ -609,11 +609,8 @@ enum { COP = 0, BRK = 1, NMI = 3, IRQ = 5 };
static void
interrupt(int src)
{
- if(src > BRK){
- io();
- if(!emu)
- io();
- }
+ if(src > BRK)
+ memread(pc | rPB);
if(!emu)
push8(rPB >> 16);
push16(pc);
@@ -687,7 +684,6 @@ cpustep(void)
lastpc = curpc;
if(trace)
print("%.6x %.2x A=%.4x X=%.4x Y=%.4x P=%.2x %.2x\n", curpc, op, rA, rX, rY, rP, rS);
- cyc = 0;
switch(op){
case 0x00: fetch8(); interrupt(BRK); break;
case 0x01: nz(rA |= mem816(dpi(0, 1, 0), 0)); break;
diff --git a/sys/src/games/snes/dat.h b/sys/src/games/snes/dat.h
index 2a0b53223..86a14a5a4 100644
--- a/sys/src/games/snes/dat.h
+++ b/sys/src/games/snes/dat.h
@@ -24,7 +24,7 @@ extern u16int spc;
extern u8int dspstate;
extern u16int dspcounter, noise;
-extern int ppuclock, spcclock, dspclock, stimerclock;
+extern int ppuclock, spcclock, dspclock, stimerclock, cpupause;
extern int battery, saveclock, scale, mouse;
enum {
diff --git a/sys/src/games/snes/mem.c b/sys/src/games/snes/mem.c
index 1bd839dc2..6fea74bfd 100644
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -183,7 +183,7 @@ regread(u16int p)
reg[OPCTLATCH] &= ~3;
return mdr2 = reg[p] | v | mdr2 & 0x20;
case 0x2180:
- v = memread(0x7e0000 | reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16);
+ v = mem[reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16];
incwram();
return v;
case 0x4016:
@@ -337,7 +337,7 @@ regwrite(u16int p, u8int v)
case 0x213e:
return;
case 0x2180:
- memwrite(0x7e0000 | reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16, v);
+ mem[reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16] = v;
incwram();
return;
case 0x4016:
diff --git a/sys/src/games/snes/ppu.c b/sys/src/games/snes/ppu.c
index 7e9228fe9..1f2175a49 100644
--- a/sys/src/games/snes/ppu.c
+++ b/sys/src/games/snes/ppu.c
@@ -857,9 +857,11 @@ ppustep(void)
pixeldraw(rx, ppuy - 1, ppuy >= yvbl ? 0x31c8 : 0);
}
+ if(ppux == 134)
+ cpupause = 1;
if(ppux == 0x116 && ppuy <= yvbl)
hdma |= reg[0x420c];
- if((reg[NMITIMEN] & HCNTIRQ) != 0 && htime == ppux && ((reg[NMITIMEN] & VCNTIRQ) == 0 || vtime == ppuy))
+ if((reg[NMITIMEN] & HCNTIRQ) != 0 && htime+4 == ppux && ((reg[NMITIMEN] & VCNTIRQ) == 0 || vtime == ppuy))
irq |= IRQPPU;
if(++ppux >= 340){
ppux = 0;
diff --git a/sys/src/games/snes/snes.c b/sys/src/games/snes/snes.c
index f6bd85567..0d7800b30 100644
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -11,7 +11,7 @@
uchar *prg, *sram;
int nprg, nsram, hirom, battery;
-int ppuclock, spcclock, dspclock, stimerclock, saveclock, msgclock, paused, perfclock;
+int ppuclock, spcclock, dspclock, stimerclock, saveclock, msgclock, paused, perfclock, cpupause;
Mousectl *mc;
QLock pauselock;
u32int keys;
@@ -267,7 +267,11 @@ usage:
qlock(&pauselock);
qunlock(&pauselock);
}
- t = cpustep();
+ if(cpupause){
+ t = 40;
+ cpupause = 0;
+ }else
+ t = cpustep();
spcclock -= t;
stimerclock += t;
ppuclock += t;