~rabbits/public-inbox

[PATCH uxn11] Exit emulator on HALT.

Details
Message ID
<20220603134647.fdyzjjqcd7xjvxyl@t480>
DKIM signature
pass
Download raw message
Check if .System/halt is non-zero like uxnemu does.

I tried to use the return value of uxn_eval, which would seem to return
0 on halt:

uxn_eval(Uxn *u, Uint16 pc) {
	if (!pc || u->dev[0x0f]) return 0;
	...
	return 1;
}

but in some programs (eg. polycat), pc can be zero at unexpected times.
I'm not really sure what pc does.

The patch to check uxn_eval would be:

@@ -252,7 +252,8 @@ main(int argc, char **argv)
 			emu_event(&u);
 		if(poll(&fds[1], 1, 0)) {
 			read(fds[1].fd, expirations, 8);    /* Indicate we handled the timer */
-			uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
+			if (!uxn_eval(&u, GETVEC(&u.dev[0x20]))) /* Call the vector once, even if the timer fired multiple times */
+				break;
 		}
 		if(uxn_screen.fg.changed || uxn_screen.bg.changed)
 			emu_draw();
---
 src/uxn11.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/uxn11.c b/src/uxn11.c
index e68300f..10f23f6 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -246,6 +246,8 @@ main(int argc, char **argv)
 	fds[0].events = fds[1].events = POLLIN;
 	/* main loop */
 	while(1) {
+		if(u.dev[0x0f])
+			break;
 		if(poll(fds, 2, 1000) <= 0)
 			continue;
 		while(XPending(display))
-- 
2.36.1
Reply to thread Export thread (mbox)