commit 92954e5

Devine Lu Linvega  ·  2025-04-08 23:29:37 +0000 UTC
parent 32be4e8
Progress on merging resizes
4 files changed,  +21, -29
+4, -3
 1@@ -17,9 +17,10 @@
 2 @on-reset ( -> )
 3 	;meta #06 DEO2
 4 	#0200 .Screen/height DEO2
 5-	( theme ) #0fa8 .System/r DEO2
 6-	#0f4f .System/g DEO2
 7-	#0fc2 .System/b DEO2
 8+	( theme ) 
 9+	#f0a8 .System/r DEO2
10+	#f04f .System/g DEO2
11+	#f0c2 .System/b DEO2
12 	( vectors ) ;on-mouse .Mouse/vector DEO2
13 	;on-frame .Screen/vector DEO2
14 	<draw-mouse>
+10, -21
 1@@ -1,4 +1,5 @@
 2 #include <stdlib.h>
 3+#include <stdio.h>
 4 
 5 #include "../uxn.h"
 6 #include "screen.h"
 7@@ -64,40 +65,28 @@ screen_palette(void)
 8 	screen_change(0, 0, uxn_screen.width, uxn_screen.height);
 9 }
10 
11-static void
12+void
13 screen_apply(int width, int height)
14 {
15-	int length = MAR2(width) * MAR2(height);
16+	int length;
17+	clamp(width, 8, 0x800);
18+	clamp(height, 8, 0x800);
19+	length = MAR2(width) * MAR2(height);
20 	uxn_screen.bg = realloc(uxn_screen.bg, length), uxn_screen.fg = realloc(uxn_screen.fg, length);
21 	uxn_screen.width = width, uxn_screen.height = height;
22+	screen_change(0, 0, width, height);
23 	uxn_screen.resize = 1;
24 }
25 
26 void
27-screen_resize(Uint16 width, Uint16 height, int scale)
28+screen_resize(int scale)
29 {
30 	Uint32 *pixels;
31-	clamp(width, 8, 0x800);
32-	clamp(height, 8, 0x800);
33 	clamp(scale, 1, 3);
34-	/* on rescale */
35-	pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32) * scale * scale);
36-	if(!pixels) return;
37-	uxn_screen.pixels = pixels;
38+	uxn_screen.pixels = realloc(uxn_screen.pixels, uxn_screen.width * uxn_screen.height * sizeof(Uint32) * scale * scale);
39 	uxn_screen.scale = scale;
40-	/* on resize */
41-	if(uxn_screen.width != width || uxn_screen.height != height) {
42-		int i, length = MAR2(width) * MAR2(height);
43-		Uint8 *bg = realloc(uxn_screen.bg, length), *fg = realloc(uxn_screen.fg, length);
44-		if(!bg || !fg) return;
45-		uxn_screen.bg = bg, uxn_screen.fg = fg;
46-		uxn_screen.width = width, uxn_screen.height = height;
47-		for(i = 0; i < length; i++)
48-			uxn_screen.bg[i] = uxn_screen.fg[i] = 0;
49-	}
50 	uxn_screen.resize = 0;
51-	screen_change(0, 0, width, height);
52-	emu_resize(width, height);
53+	emu_resize(uxn_screen.width, uxn_screen.height);
54 }
55 
56 void
+2, -1
 1@@ -19,7 +19,8 @@ extern UxnScreen uxn_screen;
 2 extern int emu_resize(int width, int height);
 3 int screen_changed(void);
 4 void screen_palette(void);
 5-void screen_resize(Uint16 width, Uint16 height, int scale);
 6+void screen_apply(int width, int height);
 7+void screen_resize(int scale);
 8 void screen_redraw(void);
 9 
10 Uint8 screen_dei(Uint8 addr);
+5, -4
 1@@ -89,14 +89,14 @@ static void
 2 emu_restart(int soft)
 3 {
 4 	close_console();
 5-	screen_resize(WIDTH, HEIGHT, uxn_screen.scale);
 6+	screen_apply(WIDTH, HEIGHT);
 7 	system_reboot(soft);
 8 }
 9 
10 static void
11 emu_rescale(void)
12 {
13-	screen_resize(uxn_screen.width, uxn_screen.height, uxn_screen.scale >= 3 ? 1 : uxn_screen.scale + 1);
14+	screen_resize(uxn_screen.scale >= 3 ? 1 : uxn_screen.scale + 1);
15 }
16 
17 static Uint8
18@@ -215,7 +215,7 @@ display_init(void)
19 	XStoreName(display, window, "uxn11");
20 	XSetClassHint(display, window, &class);
21 	XMapWindow(display, window);
22-	screen_resize(WIDTH, HEIGHT, 1);
23+	screen_apply(WIDTH, HEIGHT);
24 	return 1;
25 }
26 
27@@ -241,7 +241,7 @@ emu_run(void)
28 		if(poll(&fds[1], 1, 0)) {
29 			read(fds[1].fd, expirations, 8);
30 			if(uxn_screen.resize)
31-				screen_resize(uxn_screen.width, uxn_screen.height, uxn_screen.scale);
32+				screen_resize(uxn_screen.scale);
33 			if(uxn_screen.vector)
34 				uxn_eval(uxn_screen.vector);
35 			if(uxn_screen.x2 && uxn_screen.y2 && screen_changed()) {
36@@ -277,6 +277,7 @@ main(int argc, char **argv)
37 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
38 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
39 	console_arguments(i, argc, argv);
40+	printf("%dx%d\n", uxn_screen.width, uxn_screen.height);
41 	emu_run();
42 	close_console();
43 	XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);