ref: 08e433f31db74945aecfcad2755ccf274e849810
parent: 8d11fd6d274a0792ebb64dcc89e2b8c087888fab
author: aiju <devnull@localhost>
date: Fri Mar 14 14:20:13 EDT 2014
games/snes: hirom support and register 2180 fix
--- a/sys/src/games/snes/dat.h
+++ b/sys/src/games/snes/dat.h
@@ -5,8 +5,8 @@
extern int trace;
extern uchar *prg, *sram;
-extern int nprg, nsram, keys;
-extern u32int keylatch, lastkeys;
+extern int nprg, nsram, hirom;
+extern u32int keys, keylatch, lastkeys;
extern u8int reg[32768], spcmem[65536], vram[65536], oam[544];
extern u16int cgram[256];
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -48,6 +48,14 @@
}
static void
+incwram(void)
+{
+ if(++reg[0x2181] == 0)
+ if(++reg[0x2182] == 0)
+ reg[0x2183] ^= 1;
+}
+
+static void
hvlatch(void)
{
reg[0x213c] = ppux;
@@ -146,8 +154,8 @@
reg[OPCTLATCH] &= ~3;
return v;
case 0x2180:
- v = memread(reg[0x2181] | reg[0x2182] << 8 | reg[0x2183] << 16);
- reg[0x2181]++;
+ v = memread(0x7e0000 | reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16);
+ incwram();
return v;
case 0x4016:
if((reg[0x4016] & 1) != 0){
@@ -261,8 +269,8 @@
if((v & 0x20) != 0) subcolor = subcolor & 0x03ff | (v & 0x1f) << 10;
return;
case 0x2180:
- memwrite(reg[0x2181] | reg[0x2182] << 8 | reg[0x2183] << 16, v);
- reg[0x2181]++;
+ memwrite(0x7e0000 | reg[0x2181] | reg[0x2182] << 8 | (reg[0x2183] & 1) << 16, v);
+ incwram();
return;
case 0x213e:
return;
@@ -342,11 +350,13 @@
if(al < 0x8000){
if(b < 0x40)
return regread(al);
- if(b >= 0x70 && b < 0x78 && nsram != 0)
- return sram[((a & 0x7fffff) - 0x700000) & (nsram - 1)];
+ if((b & 0xf8) == (hirom ? 0x20 : 0x70) && nsram != 0)
+ return sram[a & 0x07ffff & (nsram - 1)];
}
if(b >= 0x7e && (a & (1<<23)) == 0)
return mem[a - 0x7e0000];
+ if(hirom)
+ return prg[((b & 0x3f) % nprg) << 16 | al];
return prg[(b%nprg) << 15 | al & 0x7fff];
}
@@ -365,8 +375,8 @@
regwrite(a, v);
return;
}
- if(b >= 0x70 && b < 0x78 && nsram != 0){
- sram[((a & 0x7fffff) - 0x700000) & (nsram - 1)] = v;
+ if((b & 0xf8) == (hirom ? 0x20 : 0x70) && nsram != 0){
+ sram[a & 0x07ffff & (nsram - 1)] = v;
if(saveclock == 0)
saveclock = SAVEFREQ;
return;
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -14,8 +14,8 @@
int ppuclock, spcclock, stimerclock, saveclock, msgclock, paused, perfclock;
Mousectl *mc;
QLock pauselock;
-int keys, savefd;
-int scale, profile, mouse;
+u32int keys;
+int savefd, scale, profile, mouse;
Rectangle picr;
Image *tmp, *bg;
@@ -57,6 +57,13 @@
if(readn(fd, prg, size) < size)
sysfatal("read: %r");
close(fd);
+ if((memread(0xffd5) & ~0x10) != 0x20)
+ if((memread(0x1ffd5) & ~0x10) == 0x21)
+ hirom = 1;
+ else
+ sysfatal("invalid rom (neither hirom nor lorom)");
+ if(hirom)
+ nprg >>= 1;
switch(memread(0xffd6)){
case 0:
break;