Browse code

Add emulator without SDL window.

Andrew Alderwick authored on 22/03/2021 09:20:49
Showing 3 changed files
... ...
@@ -17,6 +17,7 @@ clang-format -i uxn.c
17 17
 clang-format -i emulator.c
18 18
 rm -f ./bin/emulator
19 19
 cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator
20
+cc -std=c89 -DNO_SDL -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator-nosdl
20 21
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 22
 
22 23
 # run
... ...
@@ -238,6 +238,7 @@ quit(void)
238 238
 int
239 239
 init(void)
240 240
 {
241
+#ifndef NO_SDL
241 242
 	if(SDL_Init(SDL_INIT_VIDEO) < 0)
242 243
 		return error("Init", SDL_GetError());
243 244
 	gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_SHOWN);
... ...
@@ -254,6 +255,7 @@ init(void)
254 255
 	clear(pixels);
255 256
 	SDL_StartTextInput();
256 257
 	SDL_ShowCursor(SDL_DISABLE);
258
+#endif
257 259
 	screen.bounds.x1 = PAD * 8;
258 260
 	screen.bounds.x2 = WIDTH - PAD * 8 - 1;
259 261
 	screen.bounds.y1 = PAD * 8;
... ...
@@ -429,12 +431,17 @@ ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
429 431
 int
430 432
 start(Uxn *u)
431 433
 {
434
+#ifndef NO_SDL
432 435
 	int ticknext = 0;
436
+#endif
433 437
 	evaluxn(u, u->vreset);
434 438
 	loadtheme(u->ram.dat + PAGE_DEVICE + 0x00f8);
439
+#ifndef NO_SDL
435 440
 	if(screen.reqdraw)
436 441
 		redraw(pixels, u);
442
+#endif
437 443
 	while(1) {
444
+#ifndef NO_SDL
438 445
 		int tick = SDL_GetTicks();
439 446
 		SDL_Event event;
440 447
 		if(tick < ticknext)
... ...
@@ -455,9 +462,12 @@ start(Uxn *u)
455 462
 				break;
456 463
 			}
457 464
 		}
465
+#endif
458 466
 		evaluxn(u, u->vframe);
467
+#ifndef NO_SDL
459 468
 		if(screen.reqdraw)
460 469
 			redraw(pixels, u);
470
+#endif
461 471
 	}
462 472
 }
463 473
 
464 474
new file mode 100755
... ...
@@ -0,0 +1,13 @@
1
+#!/bin/bash
2
+set -e
3
+EMULATOR=./bin/emulator
4
+if [ "${1}" = '--no-sdl' ]; then
5
+    EMULATOR=./bin/emulator-nosdl
6
+    shift
7
+fi
8
+if [ -z "${1}" ]; then
9
+    printf 'usage: %s [--no-sdl] USM_FILE\n' "${0}" >&2
10
+    exit 2
11
+fi
12
+./bin/assembler "${1}" bin/boot.rom
13
+"${EMULATOR}" bin/boot.rom