summaryrefslogtreecommitdiff
path: root/sys/src/games
diff options
context:
space:
mode:
authorJacob Moody <moody@posixcafe.org>2023-02-11 03:38:26 +0000
committerJacob Moody <moody@posixcafe.org>2023-02-11 03:38:26 +0000
commit28e362d368805ad91e0662fcc9577cb74ef13d4e (patch)
treea590506cf549e9821e84e48ad20d5845e3e0d5f2 /sys/src/games
parent9651e5cbd6d9f6064b3ad63246b09194e32139e3 (diff)
games/gb: implement internal window line counter
The y offset used for windows is not based on LY but another internal window counter that is incremented alongside LY but only when the window is on screen. This fixes an issue with the dmg-acid2 and cgb-acid2 test roms. https://github.com/mattcurrie/dmg-acid2 https://gbdev.io/pandocs/Tile_Maps.html#window
Diffstat (limited to 'sys/src/games')
-rw-r--r--sys/src/games/gb/dat.h2
-rw-r--r--sys/src/games/gb/mem.c1
-rw-r--r--sys/src/games/gb/ppu.c11
3 files changed, 10 insertions, 4 deletions
diff --git a/sys/src/games/gb/dat.h b/sys/src/games/gb/dat.h
index 890856663..e6bc54453 100644
--- a/sys/src/games/gb/dat.h
+++ b/sys/src/games/gb/dat.h
@@ -14,7 +14,7 @@ extern u32int divclock;
extern Event *elist;
extern ulong clock;
-extern u8int ppuy, ppustate;
+extern u8int ppuy, ppustate, ppuw;
extern u8int apustatus;
diff --git a/sys/src/games/gb/mem.c b/sys/src/games/gb/mem.c
index 13509877f..165445870 100644
--- a/sys/src/games/gb/mem.c
+++ b/sys/src/games/gb/mem.c
@@ -109,6 +109,7 @@ regwrite(u8int a, u8int v)
ppusync();
if((~v & reg[a] & LCDEN) != 0){
ppuy = 0;
+ ppuw = 0;
ppustate = 0;
delevent(&evhblank);
}
diff --git a/sys/src/games/gb/ppu.c b/sys/src/games/gb/ppu.c
index 9043420eb..82f0510aa 100644
--- a/sys/src/games/gb/ppu.c
+++ b/sys/src/games/gb/ppu.c
@@ -5,7 +5,7 @@
#include "dat.h"
#include "fns.h"
-u8int ppustate, ppuy;
+u8int ppustate, ppuy, ppuw;
ulong hblclock, rendclock;
jmp_buf mainjmp, renderjmp;
static int cyc, done, ppux, ppux0;
@@ -118,8 +118,8 @@ ppurender(void)
}while(m > 8);
if(win == -1){
win = 1;
- ta = 0x1800 | reg[LCDC] << 4 & 0x400 | ppuy - reg[WY] << 2 & 0x3e0;
- y = ppuy - reg[WY] << 1 & 14;
+ ta = 0x1800 | reg[LCDC] << 4 & 0x400 | ppuw - reg[WY] << 2 & 0x3e0;
+ y = ppuw - reg[WY] << 1 & 14;
cyc += 2;
m = 175 - reg[WX];
goto restart;
@@ -292,6 +292,8 @@ hblanktick(void *)
switch(ppustate){
case 0:
hblclock = clock + evhblank.time;
+ if(reg[WX] <= 166 && reg[WY] <= 143)
+ ppuw++;
if(++ppuy == 144){
ppustate = 1;
if((reg[STAT] & IRQM1) != 0)
@@ -310,8 +312,11 @@ hblanktick(void *)
break;
case 1:
hblclock = clock + evhblank.time;
+ if(reg[WX] <= 166 && reg[WY] <= 143)
+ ppuw++;
if(++ppuy == 154){
ppuy = 0;
+ ppuw = 0;
ppustate = 2;
if((reg[STAT] & IRQM2) != 0)
reg[IF] |= IRQLCDS;