Browse code

(screen) Removed clamp function

Devine Lu Linvega authored on 13/04/2023 02:20:11
Showing 1 changed files
... ...
@@ -22,16 +22,9 @@ static Uint8 blending[4][16] = {
22 22
 	{1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1},
23 23
 	{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
24 24
 
25
-static int
26
-clamp(int val, int min, int max)
27
-{
28
-	return (val >= min) ? (val <= max) ? val : max : min;
29
-}
30
-
31 25
 static void
32 26
 screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
33 27
 {
34
-
35 28
 	if(x < p->width && y < p->height) {
36 29
 		Uint32 i = x + y * p->width;
37 30
 		if(color != layer->pixels[i]) {
... ...
@@ -86,11 +79,13 @@ screen_palette(UxnScreen *p, Uint8 *addr)
86 79
 void
87 80
 screen_resize(UxnScreen *p, Uint16 width, Uint16 height)
88 81
 {
89
-	Uint8
90
-		*bg = realloc(p->bg.pixels, width * height),
91
-		*fg = realloc(p->fg.pixels, width * height);
92
-	Uint32
93
-		*pixels = realloc(p->pixels, width * height * sizeof(Uint32));
82
+	Uint8 *bg, *fg;
83
+	Uint32 *pixels;
84
+	if(width < 0x20 || height < 0x20 || width >= 0x400 || height >= 0x400)
85
+		return;
86
+	bg = realloc(p->bg.pixels, width * height),
87
+	fg = realloc(p->fg.pixels, width * height);
88
+	pixels = realloc(p->pixels, width * height * sizeof(Uint32));
94 89
 	if(bg) p->bg.pixels = bg;
95 90
 	if(fg) p->fg.pixels = fg;
96 91
 	if(pixels) p->pixels = pixels;
... ...
@@ -130,10 +125,10 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
130 125
 {
131 126
 	switch(port) {
132 127
 	case 0x3:
133
-		screen_resize(&uxn_screen, clamp(PEEK2(d + 2), 1, 1024), uxn_screen.height);
128
+		screen_resize(&uxn_screen, PEEK2(d + 2), uxn_screen.height);
134 129
 		break;
135 130
 	case 0x5:
136
-		screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK2(d + 4), 1, 1024));
131
+		screen_resize(&uxn_screen, uxn_screen.width, PEEK2(d + 4));
137 132
 		break;
138 133
 	case 0xe: {
139 134
 		Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa);