commit 6d9d022

Devine Lu Linvega  ·  2026-02-18 16:51:03 +0000 UTC
parent 922bca8
Merged variances in sprite blitter
1 files changed,  +25, -53
+25, -53
  1@@ -368,6 +368,8 @@ static const Uint8 blend_lut[16][2][4] = {
  2 	{{3, 2, 3, 1}, {12, 8, 12, 4}},
  3 	{{3, 3, 1, 2}, {12, 12, 4, 8}}};
  4 
  5+static const Uint8 alpha_lut[16] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0};
  6+
  7 void emu_redraw(void), emu_resize(void);
  8 
  9 static void
 10@@ -402,9 +404,9 @@ screen_resize(int width, int height)
 11 	if(width != screen_width || height != screen_height) {
 12 		int length;
 13 		screen_width = width, screen_wmar2 = width + 0x10;
 14-		dev[0x22] = screen_width >> 8, dev[0x23] = screen_width;
 15+		poke2(&dev[0x22], screen_width);
 16 		screen_height = height, screen_hmar2 = height + 0x10;
 17-		dev[0x24] = screen_height >> 8, dev[0x25] = screen_height;
 18+		poke2(&dev[0x24], screen_height);
 19 		length = screen_wmar2 * screen_hmar2;
 20 		screen_layers = realloc(screen_layers, length);
 21 		memset(screen_layers, 0, length);
 22@@ -520,64 +522,34 @@ screen_deo_sprite(void)
 23 {
 24 	int i, j, x = rX, y = rY;
 25 	const int ctrl = dev[0x2f];
 26-	const int flipx = ctrl & 0x10, flipy = ctrl & 0x20;
 27-	const int dx = flipx ? -rDY : rDY, dy = flipy ? -rDX : rDX;
 28+	const int flipx = ctrl & 0x10, dx = flipx ? -rDY : rDY;
 29+	const int flipy = ctrl & 0x20, dy = flipy ? -rDX : rDX;
 30+	const int row_start = flipx ? 0 : 7, row_delta = flipx ? 1 : -1;
 31+	const int col_start = flipy ? 7 : 0, col_delta = flipy ? -1 : 1;
 32 	const int layer = ctrl & 0x40, layer_mask = layer ? 0x3 : 0xc;
 33+	const int is_2bpp = ctrl >> 7;
 34+	const int addr_incr = rMA << (is_2bpp + 1);
 35 	const int blend = ctrl & 0xf;
 36-	const int opaque_mask = blend % 5;
 37-	const int row_incr = flipy ? -1 : 1;
 38-	const int row_start = flipy ? 7 : 0;
 39+	const Uint8 opaque_mask = alpha_lut[blend];
 40 	const Uint8 *table = blend_lut[blend][layer >> 6];
 41-	if(ctrl & 0x80) {
 42-		const int addr_incr = rMA << 2;
 43-		for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
 44-			const Uint16 x0 = x + 8, y0 = y + 8;
 45-			if(x0 + 8 >= screen_wmar2 || y0 + 8 >= screen_hmar2) continue;
 46-			Uint8 *dst = screen_layers + y0 * screen_wmar2 + x0;
 47-			const Uint8 *rowptr = &ram[rA + row_start];
 48-			for(j = 0; j < 8; j++, dst += screen_wmar2, rowptr += row_incr) {
 49-				Uint8 *d = dst, bits1 = rowptr[0], bits2 = rowptr[8];
 50-				if(flipx)
 51-					for(int k = 0; k < 8; k++, d++, bits1 >>= 1, bits2 >>= 1) {
 52-						int color = (bits1 & 1) | ((bits2 << 1) & 2);
 53-						if(opaque_mask || color)
 54-							*d = (*d & layer_mask) | table[color];
 55-					}
 56-				else
 57-					for(int k = 0; k < 8; k++, d++, bits1 <<= 1, bits2 <<= 1) {
 58-						int color = (bits1 >> 7) | ((bits2 >> 6) & 2);
 59-						if(opaque_mask || color)
 60-							*d = (*d & layer_mask) | table[color];
 61-					}
 62-			}
 63-		}
 64-	} else {
 65-		const int addr_incr = rMA << 1;
 66-		for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
 67-			const Uint16 x0 = x + 8, y0 = y + 8;
 68-			if(x0 + 8 >= screen_wmar2 || y0 + 8 >= screen_hmar2) continue;
 69-			Uint8 *dst = screen_layers + y0 * screen_wmar2 + x0;
 70-			const Uint8 *rowptr = &ram[rA + row_start];
 71-			for(j = 0; j < 8; j++, dst += screen_wmar2, rowptr += row_incr) {
 72-				Uint8 *d = dst, bits = rowptr[0];
 73-				if(flipx)
 74-					for(int k = 0; k < 8; k++, d++, bits >>= 1) {
 75-						int color = bits & 1;
 76-						if(opaque_mask || color)
 77-							*d = (*d & layer_mask) | table[color];
 78-					}
 79-				else
 80-					for(int k = 0; k < 8; k++, d++, bits <<= 1) {
 81-						int color = bits >> 7;
 82-						if(opaque_mask || color)
 83-							*d = (*d & layer_mask) | table[color];
 84-					}
 85+	for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
 86+		const Uint16 x0 = x + 8, y0 = y + 8;
 87+		if(x0 + 8 >= screen_wmar2 || y0 + 8 >= screen_hmar2) continue;
 88+		Uint8 *dst = screen_layers + y0 * screen_wmar2 + x0;
 89+		const Uint8 *col = &ram[rA + col_start];
 90+		for(j = 0; j < 8; j++, dst += screen_wmar2, col += col_delta) {
 91+			Uint8 *d = dst;
 92+			const int ch1 = *col, ch2 = is_2bpp ? col[8] : 0;
 93+			for(int k = 0, row = row_start; k < 8; k++, d++, row += row_delta) {
 94+				const int color = ((ch1 >> row) & 1) | (((ch2 >> row) & 1) << 1);
 95+				if(opaque_mask || color)
 96+					*d = (*d & layer_mask) | table[color];
 97 			}
 98 		}
 99 	}
100 	if(!screen_reqdraw) {
101-		int x1 = flipx ? x : rX, y1 = flipy ? y : rY;
102-		int x2 = flipx ? rX : x, y2 = flipy ? rY : y;
103+		int x1 = flipx ? x : rX, x2 = flipx ? rX : x;
104+		int y1 = flipy ? y : rY, y2 = flipy ? rY : y;
105 		screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
106 	}
107 	if(rMX) rX += flipx ? -rDX : rDX;