shithub: riscv

Download patch

ref: c124e341b9a87ea67719d070cedc27861aadca75
parent: 235cc0747d3909c4d3eac307fa58664896eb5951
author: aiju <devnull@localhost>
date: Sun May 25 21:10:46 EDT 2014

games/md: moonwalker!

--- a/sys/src/games/md/cpu.c
+++ b/sys/src/games/md/cpu.c
@@ -461,7 +461,7 @@
 	int n, m, d;
 	static int cnt;
 
-	if(0 && pc == 0x48ee){
+	if(0 && pc == 0x61e8){
 		trace++;
 		print("%x\n", curpc);
 	}
@@ -935,7 +935,7 @@
 			if((op & 8) != 0){
 				a = amode(4, n, 0);
 				v = rmode(a, 0);
-				w = rmode(amode(5, n, 0), 0);
+				w = rmode(amode(4, m, 0), 0);
 				v = addbcd(v, w);
 				wmode(a, 0, v);
 			}else
--- a/sys/src/games/md/dat.h
+++ b/sys/src/games/md/dat.h
@@ -35,6 +35,8 @@
 	HORSCR  = 0x0d,
 	AUTOINC = 0x0f,
 	PLSIZ   = 0x10,
+	WINH    = 0x11,
+	WINV    = 0x12,
 	DMACL   = 0x13,
 	DMACH   = 0x14,
 	DMASRC0 = 0x15,
--- a/sys/src/games/md/md.c
+++ b/sys/src/games/md/md.c
@@ -97,7 +97,7 @@
 		if(buf[0] != 'k' && buf[0] != 'K')
 			continue;
 		s = buf + 1;
-		k = 0;
+		k = 0xc00;
 		while(*s != 0){
 			s += chartorune(&r, s);
 			switch(r){
--- a/sys/src/games/md/mem.c
+++ b/sys/src/games/md/mem.c
@@ -31,8 +31,8 @@
 			v >>= 8;
 		return ctl[0] & 0xc0 | v & 0x3f;
 	case 0x0005:
-		return ctl[1] & 0xc0 | 0x3f;
 	case 0x0007:
+		return ctl[1] & 0xc0 | 0x3f;
 	case 0x0009: case 0x000b: case 0x000d:
 		return ctl[a-3>>1];
 	case 0x1101: return (~z80bus & BUSACK) << 7;
@@ -330,7 +330,7 @@
 	}
 }
 
-u32int irql[8] = {[6] INTVBL};
+u32int irql[8] = {[6] INTVBL, [4] INTHOR};
 
 int
 intack(int l)
--- a/sys/src/games/md/mkfile
+++ b/sys/src/games/md/mkfile
@@ -1,7 +1,7 @@
 </$objtype/mkfile
 
 BIN=/$objtype/bin/games
-TARG=sega
+TARG=md
 OFILES=\
 	cpu.$O\
 	mem.$O\
--- a/sys/src/games/md/vdp.c
+++ b/sys/src/games/md/vdp.c
@@ -69,6 +69,7 @@
 	u16int t;
 	u32int c;
 } pctxt[3];
+int lwin, rwin;
 
 static void
 tile(struct pctxt *p)
@@ -79,7 +80,7 @@
 	switch(p - pctxt){
 	default: a = (reg[PANT] & 0x38) << 9; break;
 	case 1: a = (reg[PBNT] & 7) << 12; break;
-	case 2: a = (reg[PWNT] & 0x38) << 9; break;
+	case 2: a = (reg[PWNT] & 0x3e) << 9; break;
 	}
 	a += p->ty << p->ws;
 	a += p->tx;
@@ -102,7 +103,7 @@
 	pctxt[0].ws = pctxt[1].ws = szs[reg[PLSIZ] & 3];
 	pctxt[2].ws = (reg[MODE4] & WIDE) != 0 ? 6 : 5;
 	pctxt[2].hs = 5;
-	for(i = 0; i < 2; i++){
+	for(i = 0; i <= 2; i++){
 		pctxt[i].h = 1<<pctxt[i].hs;
 		pctxt[i].w = 1<<pctxt[i].ws;
 	}
@@ -120,7 +121,7 @@
 		v = vsram[i] + vdpy;
 		p->tny = v & 7;
 		p->ty = v >> 3 & pctxt[i].h - 1;
-		tile(pctxt + i);
+		tile(p);
 		if(p->tnx != 0)
 			if((p->t & 0x800) != 0)
 				p->c >>= p->tnx << 2;
@@ -129,10 +130,30 @@
 	}
 	sx = 0;
 	snx = 0;
+	v = reg[WINV] << 3 & 0xf8;
+	if((reg[WINV] & 0x80) != 0 ? vdpy < v : vdpy >= v){
+		lwin = 0;
+		rwin = reg[WINH] << 4 & 0x1f0;
+		if((reg[WINH] & 0x80) != 0){
+			lwin = rwin;
+			rwin = 320;
+		}
+	}else{
+		lwin = 0;
+		rwin = 320;
+	}
+	if(rwin > lwin){
+		p = pctxt + 2;
+		p->tx = p->ty = 0;
+		v = vdpy - v;
+		p->tny = vdpy & 7;
+		p->ty = vdpy >> 3 & pctxt[2].h - 1;
+		tile(p);
+	}
 }
 
 static void
-plane(int n)
+plane(int n, int w)
 {
 	struct pctxt *p;
 	u8int v, pr;
@@ -145,7 +166,7 @@
 		v = p->c >> 28;
 		p->c <<= 4;
 	}
-	if(v != 0){
+	if(v != 0 && w != 0){
 		v |= p->t >> 9 & 48;
 		pr = 2 - (n & 1) + (p->t >> 13 & 4);
 		pixel(v, pr);
@@ -161,7 +182,7 @@
 static void
 planes(void)
 {
-	int i;
+	int i, w;
 	u16int v;
 
 	if((reg[MODE3] & 4) != 0 && ++snx == 16){
@@ -173,8 +194,11 @@
 			pctxt[i].ty = v >> 3 & pctxt[i].h - 1;
 		}
 	}
-	plane(0);
-	plane(1);
+	w = vdpx < rwin && vdpx >= lwin;
+	plane(0, !w);
+	plane(1, 1);
+	if(w)
+		plane(2, 1);
 }
 
 static struct sprite {
@@ -289,7 +313,7 @@
 			vdpy = 0;
 			irq &= ~INTVBL;
 			vdpstat ^= STATFR;
-			vdpstat &= ~(STATINT | STATFR | STATOVR | STATCOLL);
+			vdpstat &= ~(STATINT | STATVBL | STATOVR | STATCOLL);
 			flush();
 		}
 		if(vdpy == 0 || vdpy >= 225)