ref: 4b0467ce442ad6a4eef0caf44391f7b924186a1b
parent: 3a54967108ab173389448ba2145502cf62602111
author: aiju <devnull@localhost>
date: Thu Mar 20 12:44:01 EDT 2014
games/snes: made cpu timing slightly more accurate
--- a/sys/src/games/snes/dat.h
+++ b/sys/src/games/snes/dat.h
@@ -6,6 +6,7 @@
extern u8int dma, nmi, irq;
extern u32int hdma;
extern int trace;
+extern int memcyc;
extern uchar *prg, *sram;
extern int nprg, nsram, hirom;
@@ -66,6 +67,7 @@
OVERSCAN = 1<<2,
AUTOJOY = 1,
NMITIMEN = 0x4200,
+ MEMSEL = 0x420d,
RDNMI = 0x4210,
VBLANK = 1<<7,
VCNTIRQ = 1<<5,
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -10,6 +10,7 @@
u16int cgram[256];
u16int oamaddr, vramlatch;
u32int keylatch, lastkeys;
+int memcyc;
enum {
OAMLATCH,
CGLATCH,
@@ -373,11 +374,18 @@
return sram[(b << 13 | al & 0x1ffff) & (nsram - 1)];
return regread(al);
}
- if(!hirom && (b & 0xf8) == 0x70 && nsram != 0)
+ if(!hirom && (b & 0xf8) == 0x70 && nsram != 0){
+ if(a < 0x800000 || (reg[MEMSEL] & 1) == 0)
+ memcyc += 2;
return sram[a & 0x07ffff & (nsram - 1)];
+ }
}
- if(b >= 0x7e && (a & (1<<23)) == 0)
+ if(b >= 0x7e && (a & (1<<23)) == 0){
+ memcyc += 2;
return mem[a - 0x7e0000];
+ }
+ if(a < 0x800000 || (reg[MEMSEL] & 1) == 0)
+ memcyc += 2;
if(hirom)
return prg[((b & 0x3f) % nprg) << 16 | al];
return prg[(b%nprg) << 15 | al & 0x7fff];
@@ -391,8 +399,10 @@
al = a;
b = (a>>16) & 0x7f;
- if(b >= 0x7e && a < 0x800000)
+ if(b >= 0x7e && a < 0x800000){
+ memcyc += 2;
mem[a - 0x7e0000] = v;
+ }
if(al < 0x8000){
if(b < 0x40){
if(hirom && al >= 0x6000 && nsram != 0){
@@ -405,6 +415,8 @@
if(!hirom && (b & 0xf8) == 0x70 && nsram != 0){
sram[a & 0x07ffff & (nsram - 1)] = v;
save:
+ if(a < 0x800000 || (reg[MEMSEL] & 1) == 0)
+ memcyc += 2;
if(saveclock == 0)
saveclock = SAVEFREQ;
return;
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -255,7 +255,12 @@
qlock(&pauselock);
qunlock(&pauselock);
}
- t = cpustep() * 8;
+ memcyc = 0;
+ t = cpustep();
+ if(curpc == -1)
+ t *= 8;
+ else
+ t = t * 6 + memcyc;
spcclock -= t;
stimerclock += t;
ppuclock += t;