shithub: riscv

Download patch

ref: 66c98fab71ea8878fc963b38a106a38518dac83a
parent: edfdc4ac07fe2748b72d36ea455876907227c4c3
author: aiju <devnull@localhost>
date: Wed Apr 1 15:02:03 EDT 2015

games/gb: fix -2/-3

--- a/sys/src/games/gb/dat.h
+++ b/sys/src/games/gb/dat.h
@@ -22,7 +22,7 @@
 
 extern u8int mode;
 extern u8int mbc, feat;
-extern int keys;
+extern int keys, scale;
 
 enum {
 	JOYP = 0x00,
--- a/sys/src/games/gb/ppu.c
+++ b/sys/src/games/gb/ppu.c
@@ -5,7 +5,7 @@
 #include "fns.h"
 
 u8int ppustate, ppuy;
-u32int pic[PICW*PICH];
+u32int pic[PICW*PICH*3];
 ulong hblclock, rendclock;
 jmp_buf mainjmp, renderjmp;
 static int cyc, done, ppux, ppux0;
@@ -63,7 +63,7 @@
 			}
 		ppux = 0;
 		ppux0 = 0;
-		picp = pic + ppuy * PICW;
+		picp = pic + ppuy * PICW * scale;
 		y = ppuy + reg[SCY] << 1 & 14;
 		ta = 0x1800 | reg[LCDC] << 7 & 0x400 | ppuy + reg[SCY] << 2 & 0x3e0 | reg[SCX] >> 3;
 		x = -(reg[SCX] & 7);
@@ -197,7 +197,7 @@
 	int x, x1;
 	u16int chr;
 	
-	picp = pic + ppuy * PICW;
+	picp = pic + ppuy * PICW * scale;
 	for(q = spr; q < sprm; q++){
 		if(q->x <= ppux0 || q->x >= ppux + 8)
 			continue;
@@ -250,6 +250,25 @@
 	return t*2;
 }
 
+static void
+lineexpand(void)
+{
+	u32int *picp, *p, *q, l;
+	int i, s;
+
+	s = scale;
+	picp = pic + ppuy * PICW * s;
+	p = picp + PICW;
+	q = picp + PICW * scale;
+	for(i = PICW; --i >= 0; ){
+		l = *--p;
+		*--q = l;
+		*--q = l;
+		if(scale == 3)
+			*--q = l;
+	}
+}
+
 void
 hblanktick(void *)
 {
@@ -298,6 +317,8 @@
 		ppusync();
 		if(!done) print("not done?!\n");
 		done = 0;
+		if(scale > 1)
+			lineexpand();
 		ppustate = 0;
 		if((reg[STAT] & IRQM0) != 0)
 			reg[IF] |= IRQLCDS;