commit eb8e241

neauoire  ·  2022-04-06 02:40:49 +0000 UTC
parent de3b024
Renamed a few functions in uxn11
1 files changed,  +22, -29
+22, -29
  1@@ -24,7 +24,7 @@ static Window window;
  2 #define HEIGHT (40 * 8)
  3 
  4 static int
  5-error(char *msg, const char *err)
  6+emu_error(char *msg, const char *err)
  7 {
  8 	fprintf(stderr, "Error %s: %s\n", msg, err);
  9 	return 0;
 10@@ -50,7 +50,7 @@ console_deo(Uint8 *d, Uint8 port)
 11 }
 12 
 13 static Uint8
 14-uxn11_dei(struct Uxn *u, Uint8 addr)
 15+emu_dei(struct Uxn *u, Uint8 addr)
 16 {
 17 	Uint8 p = addr & 0x0f, d = addr & 0xf0;
 18 	switch(d) {
 19@@ -63,7 +63,7 @@ uxn11_dei(struct Uxn *u, Uint8 addr)
 20 }
 21 
 22 static void
 23-uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
 24+emu_deo(Uxn *u, Uint8 addr, Uint8 v)
 25 {
 26 	Uint8 p = addr & 0x0f, d = addr & 0xf0;
 27 	u->dev[addr] = v;
 28@@ -81,7 +81,7 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
 29 }
 30 
 31 static void
 32-redraw(void)
 33+emu_redraw(void)
 34 {
 35 	screen_redraw(&uxn_screen, uxn_screen.pixels);
 36 	XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, 0, 0, uxn_screen.width, uxn_screen.height);
 37@@ -119,13 +119,13 @@ get_button(KeySym sym)
 38 }
 39 
 40 static void
 41-processEvent(Uxn *u)
 42+emu_event(Uxn *u)
 43 {
 44 	XEvent ev;
 45 	XNextEvent(display, &ev);
 46 	switch(ev.type) {
 47 	case Expose:
 48-		redraw();
 49+		emu_redraw();
 50 		break;
 51 	case ClientMessage: {
 52 		XDestroyImage(ximage);
 53@@ -166,22 +166,6 @@ processEvent(Uxn *u)
 54 	}
 55 }
 56 
 57-static int
 58-start(Uxn *u, char *rom)
 59-{
 60-	if(!uxn_boot(u, (Uint8 *)calloc(0x10300, sizeof(Uint8))))
 61-		return error("Boot", "Failed");
 62-	if(!load_rom(u, rom))
 63-		return error("Load", "Failed");
 64-	fprintf(stderr, ">> Loaded %s\n", rom);
 65-	u->dei = uxn11_dei;
 66-	u->deo = uxn11_deo;
 67-	screen_resize(&uxn_screen, WIDTH, HEIGHT);
 68-	if(!uxn_eval(u, PAGE_PROGRAM))
 69-		return error("Boot", "Failed to start rom.");
 70-	return 1;
 71-}
 72-
 73 static int
 74 init(void)
 75 {
 76@@ -190,7 +174,7 @@ init(void)
 77 	visual = DefaultVisual(display, 0);
 78 	window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width, uxn_screen.height, 1, 0, 0);
 79 	if(visual->class != TrueColor)
 80-		return error("Init", "True-color visual failed");
 81+		return emu_error("Init", "True-color visual failed");
 82 	XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
 83 	wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
 84 	XSetWMProtocols(display, window, &wmDelete, 1);
 85@@ -209,11 +193,20 @@ main(int argc, char **argv)
 86 	struct pollfd fds[2];
 87 	static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
 88 	if(argc < 2)
 89-		return error("Usage", "uxncli game.rom args");
 90-	if(!start(&u, argv[1]))
 91-		return error("Start", "Failed");
 92+		return emu_error("Usage", "uxncli game.rom args");
 93+	/* start sequence */
 94+	if(!uxn_boot(&u, (Uint8 *)calloc(0x10300, sizeof(Uint8))))
 95+		return emu_error("Boot", "Failed");
 96+	if(!load_rom(&u, argv[1]))
 97+		return emu_error("Load", "Failed");
 98+	fprintf(stderr, "Loaded %s\n", argv[1]);
 99+	u.dei = emu_dei;
100+	u.deo = emu_deo;
101+	screen_resize(&uxn_screen, WIDTH, HEIGHT);
102+	if(!uxn_eval(&u, PAGE_PROGRAM))
103+		return emu_error("Boot", "Failed to start rom.");
104 	if(!init())
105-		return error("Init", "Failed");
106+		return emu_error("Init", "Failed");
107 	/* console vector */
108 	for(i = 2; i < argc; i++) {
109 		char *p = argv[i];
110@@ -229,13 +222,13 @@ main(int argc, char **argv)
111 		if(poll(fds, 2, 1000) <= 0)
112 			continue;
113 		while(XPending(display))
114-			processEvent(&u);
115+			emu_event(&u);
116 		if(poll(&fds[1], 1, 0)) {
117 			read(fds[1].fd, expirations, 8);    /* Indicate we handled the timer */
118 			uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
119 		}
120 		if(uxn_screen.fg.changed || uxn_screen.bg.changed)
121-			redraw();
122+			emu_redraw();
123 	}
124 	XDestroyImage(ximage);
125 	return 0;