ref: eeac553c36e1cb1d7786115d7202bfe732deb54e
parent: 9c40e15ba8ae000f73c23d89143d6c44b75220fd
author: aiju <devnull@localhost>
date: Thu Feb 20 18:22:14 EST 2014
games/nes: bug fixing
--- a/sys/src/games/nes/cpu.c
+++ b/sys/src/games/nes/cpu.c
@@ -6,6 +6,7 @@
u16int pc, curpc;
u8int rA, rX, rY, rS, rP;
int nmi;
+extern int map;
static u8int
fetch8(void)
@@ -172,7 +173,13 @@
static void
inc(u16int a)
{
- memwrite(a, nz(memread(a) + 1));
+ u8int v;
+
+ v = memread(a);
+ memwrite(a, v);
+ v = nz(v + 1);
+ if(!(map == 1 && a >= 0x8000))
+ memwrite(a, v);
}
static void
@@ -229,6 +236,8 @@
rP |= FLAGI;
}
+int trace;
+
int
step(void)
{
@@ -243,6 +252,8 @@
}
curpc = pc;
op = fetch8();
+ if(trace)
+ print("%x %x %x %x %x %x %x %x\n", curpc, op, rA, rX, rY, rS, rP, memread(0x2c));
switch(op){
case 0x00: pc++; interrupt(0, 1); return 7;
case 0x01: nz(rA |= indX()); return 6;
@@ -397,12 +408,12 @@
case 0xC5: cmp(rA, zp()); return 3;
case 0xC9: cmp(rA, imm()); return 2;
case 0xCD: cmp(rA, abso()); return 4;
+ case 0xD0: if((rP & FLAGZ) == 0) return branch(); pc++; return 3;
case 0xD1: cmp(rA, indY(&c)); return 5 + c;
case 0xD5: cmp(rA, zpX()); return 4;
case 0xD8: rP &= ~FLAGD; return 2;
case 0xD9: cmp(rA, absY()); return 4 + ((u8int)a < rY);
case 0xDD: cmp(rA, absX()); return 4 + ((u8int)a < rX);
- case 0xD0: if((rP & FLAGZ) == 0) return branch(); pc++; return 3;
case 0xC0: cmp(rY, imm()); return 2;
case 0xC4: cmp(rY, zp()); return 3;
case 0xC6: dec(fetch8()); return 5;
--- a/sys/src/games/nes/mem.c
+++ b/sys/src/games/nes/mem.c
@@ -193,7 +193,8 @@
p &= 0x2007;
switch(p){
case PPUCTRL:
- if((v & PPUNMI) != 0 && (mem[PPUSTATUS] & PPUVBLANK) != 0)
+ if((mem[PPUCTRL] & PPUNMI) == 0 && (v & PPUNMI) != 0 &&
+ (mem[PPUSTATUS] & PPUVBLANK) != 0)
nmi = 1;
pput = (pput & 0xF3FF) | ((v & 3) << 10);
break;
--- a/sys/src/games/nes/nes.c
+++ b/sys/src/games/nes/nes.c
@@ -83,6 +83,8 @@
mapper[map](-1, 0);
}
+extern int trace;
+
void
keyproc(void *)
{
@@ -99,6 +101,8 @@
if(buf[0] == 'c'){
if(utfrune(buf, Kdel))
threadexitsall(nil);
+ if(utfrune(buf, 't'))
+ trace ^= 1;
}
if(buf[0] != 'k' && buf[0] != 'K')
continue;
--- a/sys/src/games/nes/ppu.c
+++ b/sys/src/games/nes/ppu.c
@@ -5,7 +5,7 @@
#include "dat.h"
#include "fns.h"
-int ppuy, ppux;
+int ppuy, ppux, odd;
uchar pic[256*240*4*9];
extern uchar oam[256];
@@ -289,7 +289,11 @@
if(ppux > 340){
ppux = 0;
ppuy++;
- if(ppuy > 261)
+ if(ppuy > 261){
ppuy = 0;
+ if(odd && (mem[PPUCTRL] & (BGDISP | SPRITEDISP)) != 0)
+ ppux++;
+ odd ^= 1;
+ }
}
}