shithub: sms

Download patch

ref: c68687ab0d9a2352617468f912be3a0373b6b629
parent: 0bc05e8fa07ce2c45198698c6b4a1680240fab72
author: Jean-André Santoni <jean.andre.santoni@gmail.com>
date: Thu Jul 18 20:31:05 EDT 2024

Remove md vdp code, and fix sprites being 1px too high

--- a/vdp.c
+++ b/vdp.c
@@ -13,7 +13,6 @@
 uint16_t hctr;
 static int xmax, xdisp;
 static int sx, snx, col, pri, lum;
-enum { DARK, NORM, BRIGHT };
 enum { ymax = 262, yvbl = 234 };
 
 void
@@ -43,178 +42,16 @@
 	*p = u.l;
 }
 
-static uint32_t
-shade(uint32_t v, int l)
-{
-	if(l == 1)
-		return v;
-	if(l == 2)
-		return v << 1 & 0xefefef;
-	return v >> 1 & 0xf7f7f7;
-}
-
 static void
-pixel(int v, int p)
-{
-	if(p >= pri){
-		col = v;
-		pri = p;
-	}
-}
-
-struct pctxt {
-	uint8_t ws, w, hs, h;
-	uint16_t tx, ty;
-	uint8_t tnx, tny;
-	uint16_t t;
-	uint32_t c;
-} pctxt[3];
-int lwin, rwin;
-
-static void
-tile(struct pctxt *p)
-{
-	uint16_t a;
-	int y;
-
-	switch(p - pctxt){
-	default: a = (reg[PANT] & 0x38) << 9; break;
-	case 1: a = (reg[PBNT] & 7) << 12; break;
-	case 2: a = (reg[PWNT] & 0x3e) << 9; break;
-	}
-	a += p->ty << p->ws;
-	a += p->tx;
-	p->t = vram[a];
-	y = p->tny;
-	if(intla){
-		if((p->t & 0x1000) != 0)
-			y = 15 - y;
-		a = (p->t & 0x7ff) << 5 | y << 1;
-	}else{
-		if((p->t & 0x1000) != 0)
-			y = 7 - y;
-		a = (p->t & 0x7ff) << 4 | y << 1;
-	}
-	p->c = vram[a] << 16 | vram[a+1];
-}
-
-static void
-planeinit(void)
-{
-	// printf("planeinit\n");
-	static int szs[] = {5, 6, 6, 7};
-	int v, a, i;
-	struct pctxt *p;
-
-	pctxt[0].hs = pctxt[1].hs = szs[reg[PLSIZ] >> 4 & 3];
-	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++){
-		pctxt[i].h = 1<<pctxt[i].hs;
-		pctxt[i].w = 1<<pctxt[i].ws;
-	}
-	a = reg[HORSCR] << 9 & 0x7fff;
-	switch(reg[MODE3] & 3){
-	case 1: a += vdpy << 1 & 0xe; break;
-	case 2: a += vdpy << 1 & 0xff0; break;
-	case 3: a += vdpy << 1 & 0xffe; break;
-	}
-	for(i = 0; i < 2; i++){
-		p = pctxt + i;
-		v = -(vram[a + i] & 0x3ff);
-		p->tnx = v & 7;
-		p->tx = v >> 3 & pctxt[i].w - 1;
-		if(intla){
-			v = vsram[i] + vdpyy;
-			p->tny = v & 15;
-			p->ty = v >> 4 & pctxt[i].h - 1;
-		}else{
-			v = vsram[i] + vdpy;
-			p->tny = v & 7;
-			p->ty = v >> 3 & pctxt[i].h - 1;
-		}
-		tile(p);
-		if(p->tnx != 0)
-			if((p->t & 0x800) != 0)
-				p->c >>= p->tnx << 2;
-			else
-				p->c <<= p->tnx << 2;
-	}
-	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 = lwin >> 3 & pctxt[2].w - 1;
-		p->tnx = lwin & 7;
-		p->tny = vdpy & 7;
-		p->ty = vdpy >> 3 & pctxt[2].h - 1;
-		tile(p);
-	}
-}
-
-static void
 plane(int n, int vis)
 {
-	struct pctxt *p;
-	uint8_t v, pr;
 
-	p = pctxt + n;
-	if((p->t & 0x800) != 0){
-		v = p->c & 15;
-		p->c >>= 4;
-	}else{
-		v = p->c >> 28;
-		p->c <<= 4;
-	}
-	if(vis != 0){
-		if(v != 0){
-			v |= p->t >> 9 & 48;
-			pr = 2 - (n & 1) + (p->t >> 13 & 4);
-			pixel(v, pr);
-		}
-		lum |= p->t >> 15;
-	}
-	if(++p->tnx == 8){
-		p->tnx = 0;
-		if(++p->tx == p->w)
-			p->tx = 0;
-		tile(pctxt + n);
-	}
 }
 
 static void
 planes(void)
 {
-	int i, w;
-	uint8_t v;
 
-	if((reg[MODE3] & 4) != 0 && ++snx == 16){
-		snx = 0;
-		sx++;
-		for(i = 0; i < 2; i++){
-			v = vsram[sx + i] + vdpy;
-			pctxt[i].tny = v & 7;
-			pctxt[i].ty = v >> 3 & pctxt[i].h - 1;
-		}
-	}
-	w = vdpx < rwin && vdpx >= lwin;
-	plane(0, !w);
-	plane(1, 1);
-	if(w)
-		plane(2, 1);
 }
 
 static struct sprite {
@@ -247,7 +84,7 @@
 		int y = vram[spridx] + 1;
 		int h = (reg[1] & 1 << 1) != 0 ? 16 : 8;
 
-		if(vdpy >= y && vdpy <= y+h && y > 1){
+		if(vdpy >= y && vdpy < y+h && y > 1){
 			if(bufidx >= 8){
 				if (vdpy < 192)
 					vdpstat |= STATOVR;
@@ -387,24 +224,17 @@
 {
 	uint32_t v;
 
-	if(vdpx == 0){
-		planeinit();
+	if(vdpx == 0)
 		spritesinit();
-	}
-	if(vdpx < 320 && vdpy < 224)
+
+	if(vdpx < 320 && vdpy < 192)
 		if(vdpx < xdisp){
-			col = reg[BGCOL] & 0x3f;
+			col = reg[BGCOL] & 0x0f + 16;
 			pri = 0;
 			lum = 0;
 			planes();
 			sprites();
-			if((reg[MODE2] & 0x40) != 0 && (vdpx >= 8 || (reg[MODE1] & 0x20) == 0)){
-				v = cramc[col];
-				if((reg[MODE4] & SHI) != 0)
-					v = shade(v, lum);
-				pixeldraw(vdpx, vdpy, v);
-			}else
-				pixeldraw(vdpx, vdpy, 0);
+			pixeldraw(vdpx, vdpy, 0);
 		}else
 			pixeldraw(vdpx, vdpy, 0xcccccc);
 	if(++vdpx >= xmax){
@@ -419,7 +249,7 @@
 		}
 		if(intla)
 			vdpyy = vdpy << 1 | frame;
-		if(vdpy == 0 || vdpy >= 225)
+		if(vdpy == 0 || vdpy >= 193)
 			hctr = reg[HORCTR];
 		else
 			if(hctr-- == 0){
--