ref: 0d080855b2a1b8095f2a7d4c6f649685d20e3c42
parent: b13425e2b077de3d2562a8d6ebe5b8f6ab537f3d
author: aiju <devnull@localhost>
date: Sat Mar 22 08:50:40 EDT 2014
games/snes: cpu timing fix
--- a/sys/src/games/snes/cpu.c
+++ b/sys/src/games/snes/cpu.c
@@ -609,11 +609,8 @@
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 @@
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;
--- a/sys/src/games/snes/dat.h
+++ b/sys/src/games/snes/dat.h
@@ -24,7 +24,7 @@
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 {
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -183,7 +183,7 @@
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 @@
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:
--- a/sys/src/games/snes/ppu.c
+++ b/sys/src/games/snes/ppu.c
@@ -857,9 +857,11 @@
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;
--- 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 @@
qlock(&pauselock);
qunlock(&pauselock);
}
- t = cpustep();
+ if(cpupause){
+ t = 40;
+ cpupause = 0;
+ }else
+ t = cpustep();
spcclock -= t;
stimerclock += t;
ppuclock += t;