Browse code

(screen.c) Removed pixel function

Devine Lu Linvega authored on 14/04/2023 04:57:17
Showing 1 changed files
... ...
@@ -1,5 +1,4 @@
1 1
 #include <stdlib.h>
2
-#include <stdio.h>
3 2
 
4 3
 #include "../uxn.h"
5 4
 #include "screen.h"
... ...
@@ -25,14 +24,6 @@ static Uint8 blending[4][16] = {
25 24
 	{1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1},
26 25
 	{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
27 26
 
28
-static void
29
-screen_pixel(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
30
-{
31
-	if(x >= p->width || y >= p->height)
32
-		return;
33
-	layer->pixels[x + y * p->width] = color;
34
-}
35
-
36 27
 static void
37 28
 screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
38 29
 {
... ...
@@ -50,15 +41,14 @@ screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
50 41
 		Uint16 c = sprite[v] | (twobpp ? (sprite[v + 8] << 8) : 0);
51 42
 		for(h = 7; h >= 0; --h, c >>= 1) {
52 43
 			Uint8 ch = (c & 1) | ((c >> 7) & 2);
53
-			if(opaque || ch)
54
-				screen_pixel(p,
55
-					layer,
56
-					x + (flipx ? 7 - h : h),
57
-					y + (flipy ? 7 - v : v),
58
-					blending[ch][color]);
44
+			if(opaque || ch) {
45
+				Uint16 xx = x + (flipx ? 7 - h : h);
46
+				Uint16 yy = y + (flipy ? 7 - v : v);
47
+				if(xx < p->width && yy < p->height)
48
+					layer->pixels[xx + yy * p->width] = blending[ch][color];
49
+			}
59 50
 		}
60 51
 	}
61
-	layer->changed = 1;
62 52
 }
63 53
 
64 54
 void
... ...
@@ -158,29 +148,32 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
158 148
 		break;
159 149
 	}
160 150
 	case 0xf: {
161
-		Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
151
+		Uint8 i;
152
+		Uint8 ctrl = d[0xf];
153
+		Uint8 move = d[0x6];
154
+		Uint8 length = move >> 4;
155
+		Uint8 twobpp = !!(ctrl & 0x80);
162 156
 		Uint16 x = PEEK2(d + 0x8);
163 157
 		Uint16 y = PEEK2(d + 0xa);
164 158
 		Uint16 addr = PEEK2(d + 0xc);
165
-		Uint16 dx = (d[0x6] & 0x01) << 3;
166
-		Uint16 dy = (d[0x6] & 0x02) << 2;
167
-		Uint8 n = d[0x6] >> 4;
168
-		Uint8 twobpp = !!(d[0xf] & 0x80);
169
-		Uint8 i;
170
-		if(addr > 0x10000 - ((n + 1) << (3 + twobpp)))
159
+		Uint16 dx = (move & 0x1) << 3;
160
+		Uint16 dy = (move & 0x2) << 2;
161
+		Layer *layer = (ctrl & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
162
+		if(addr > 0x10000 - ((length + 1) << (3 + twobpp)))
171 163
 			return;
172
-		for(i = 0; i <= n; i++) {
173
-			if(!(d[0xf] & 0xf)) {
164
+		for(i = 0; i <= length; i++) {
165
+			if(!(ctrl & 0xf)) {
174 166
 				Uint16 ex = x + dy * i, ey = y + dx * i;
175 167
 				screen_fill(&uxn_screen, layer, ex, ey, ex + 8, ey + 8, 0);
176 168
 			} else {
177
-				screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &ram[addr], d[0xf] & 0xf, d[0xf] & 0x10, d[0xf] & 0x20, twobpp);
178
-				addr += (d[0x6] & 0x04) << (1 + twobpp);
169
+				screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &ram[addr], ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp);
170
+				addr += (move & 0x04) << (1 + twobpp);
179 171
 			}
180 172
 		}
181
-		if(d[0x6] & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */
182
-		if(d[0x6] & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */
183
-		if(d[0x6] & 0x4) POKE2(d + 0xc, addr);   /* auto addr+length */
173
+		layer->changed = 1;
174
+		if(move & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */
175
+		if(move & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */
176
+		if(move & 0x4) POKE2(d + 0xc, addr);   /* auto addr+length */
184 177
 		break;
185 178
 	}
186 179
 	}