ref: e5a6ebecd29404c64a7a3da24c4ee4fd0fac122c
parent: 11489407ecb860a1836ebfab5e4c1620ffd8b23b
author: aiju <devnull@localhost>
date: Fri Mar 14 18:34:47 EDT 2014
games/snes: bug fixes
--- a/sys/src/games/snes/mem.c
+++ b/sys/src/games/snes/mem.c
@@ -348,9 +348,12 @@
al = a;
b = (a>>16) & 0x7f;
if(al < 0x8000){
- if(b < 0x40)
+ if(b < 0x40){
+ if(hirom && al >= 0x6000 && nsram != 0)
+ return sram[(b << 13 | al & 0x1ffff) & (nsram - 1)];
return regread(al);
- if((b & 0xf8) == (hirom ? 0x20 : 0x70) && nsram != 0)
+ }
+ if(!hirom && (b & 0xf8) == 0x70 && nsram != 0)
return sram[a & 0x07ffff & (nsram - 1)];
}
if(b >= 0x7e && (a & (1<<23)) == 0)
@@ -372,11 +375,16 @@
mem[a - 0x7e0000] = v;
if(al < 0x8000){
if(b < 0x40){
+ if(hirom && al >= 0x6000 && nsram != 0){
+ sram[(b << 13 | al & 0x1fff) & (nsram - 1)] = v;
+ goto save;
+ }
regwrite(a, v);
return;
}
- if((b & 0xf8) == (hirom ? 0x20 : 0x70) && nsram != 0){
+ if(!hirom && (b & 0xf8) == 0x70 && nsram != 0){
sram[a & 0x07ffff & (nsram - 1)] = v;
+ save:
if(saveclock == 0)
saveclock = SAVEFREQ;
return;
--- a/sys/src/games/snes/ppu.c
+++ b/sys/src/games/snes/ppu.c
@@ -11,7 +11,7 @@
uchar pic[256*239*2*9];
u16int m7[6], hofs[4], vofs[4];
-enum { OBJ = 4, COL = 5, OBJNC = 6 };
+enum { OBJ = 4, COL = 5, OBJNC = 8 };
static u16int
darken(u16int v)
@@ -290,8 +290,6 @@
u8int v;
p = bgctxts + n;
- if(p->sz == 0)
- return;
v = bgpixel(p->c, p->nb, p->t & 0x4000);
if(p->msz != 1)
if(p->mx++ == 0)
@@ -348,11 +346,23 @@
static void
bgs(void)
{
- bg(0);
- bg(1);
- if(mode <= 1){
+ switch(mode){
+ case 0:
+ bg(0);
+ bg(1);
bg(2);
bg(3);
+ break;
+ case 1:
+ bg(0);
+ bg(1);
+ bg(2);
+ break;
+ case 2:
+ case 3:
+ bg(0);
+ bg(1);
+ break;
}
}
@@ -510,7 +520,7 @@
colormath(void)
{
u16int v, w, r, g, b;
- u8int m, m2;
+ u8int m, m2, div;
int cw;
m = reg[CGWSEL];
@@ -536,11 +546,13 @@
case 2: if(cw < 0) cw = window(COL); if(cw) return v; break;
default: return v;
}
+ div = (m2 & 0x40) != 0;
if((m & 2) != 0){
if((pixelcol[1] & 0x10000) != 0)
w = pixelcol[1];
else
w = cgram[pixelcol[1] & 0xff];
+ div = div && (pixelpri[1] & 0xf) != COL;
}else
w = subcolor;
if((m2 & 0x80) != 0){
@@ -547,20 +559,20 @@
r = (v & 0x7c00) - (w & 0x7c00);
g = (v & 0x03e0) - (w & 0x03e0);
b = (v & 0x001f) - (w & 0x001f);
- if((m2 & 0x40) != 0){
+ if(r > 0x7c00) r = 0;
+ if(g > 0x03e0) g = 0;
+ if(b > 0x001f) b = 0;
+ if(div){
r = (r >> 1) & 0xfc00;
g = (g >> 1) & 0xffe0;
b >>= 1;
}
- if(r > 0x7c00) r = 0;
- if(g > 0x03e0) g = 0;
- if(b > 0x001f) b = 0;
return r | g | b;
}else{
r = (v & 0x7c00) + (w & 0x7c00);
g = (v & 0x03e0) + (w & 0x03e0);
b = (v & 0x001f) + (w & 0x001f);
- if((m2 & 0x40) != 0){
+ if(div){
r = (r >> 1) & 0xfc00;
g = (g >> 1) & 0xffe0;
b >>= 1;
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -233,8 +233,8 @@
mc = initmouse(nil, screen);
if(mc == nil)
sysfatal("initmouse: %r");
- loadbat(argv[0]);
screeninit();
+ loadbat(argv[0]);
proccreate(keyproc, 0, 8192);
cpureset();
memreset();