summaryrefslogtreecommitdiff
path: root/sys/src/games
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2014-03-20 16:44:01 +0100
committeraiju <devnull@localhost>2014-03-20 16:44:01 +0100
commit4b0467ce442ad6a4eef0caf44391f7b924186a1b (patch)
tree2448413e03262f9c4f5944f809d122b41a09bbfe /sys/src/games
parent3a54967108ab173389448ba2145502cf62602111 (diff)
games/snes: made cpu timing slightly more accurate
Diffstat (limited to 'sys/src/games')
-rw-r--r--sys/src/games/snes/dat.h2
-rw-r--r--sys/src/games/snes/mem.c18
-rw-r--r--sys/src/games/snes/snes.c7
3 files changed, 23 insertions, 4 deletions
diff --git a/sys/src/games/snes/dat.h b/sys/src/games/snes/dat.h
index 78d27ae84..ebc92dd9d 100644
--- a/sys/src/games/snes/dat.h
+++ b/sys/src/games/snes/dat.h
@@ -6,6 +6,7 @@ extern u32int rPB, curpc;
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 @@ enum {
OVERSCAN = 1<<2,
AUTOJOY = 1,
NMITIMEN = 0x4200,
+ MEMSEL = 0x420d,
RDNMI = 0x4210,
VBLANK = 1<<7,
VCNTIRQ = 1<<5,
diff --git a/sys/src/games/snes/mem.c b/sys/src/games/snes/mem.c
index 99d794af6..2d8307ecb 100644
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -10,6 +10,7 @@ u8int oam[544], vram[65536];
u16int cgram[256];
u16int oamaddr, vramlatch;
u32int keylatch, lastkeys;
+int memcyc;
enum {
OAMLATCH,
CGLATCH,
@@ -373,11 +374,18 @@ memread(u32int a)
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 @@ memwrite(u32int a, u8int v)
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 @@ memwrite(u32int a, u8int v)
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;
diff --git a/sys/src/games/snes/snes.c b/sys/src/games/snes/snes.c
index 937a77496..939397ec4 100644
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -255,7 +255,12 @@ usage:
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;