Add emulator without SDL window.

This commit is contained in:
Andrew Alderwick 2021-03-22 09:20:49 +00:00
parent f884031c2d
commit e860fc8932
3 changed files with 24 additions and 0 deletions

View File

@ -17,6 +17,7 @@ clang-format -i uxn.c
clang-format -i emulator.c clang-format -i emulator.c
rm -f ./bin/emulator rm -f ./bin/emulator
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 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
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
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run # run

View File

@ -238,6 +238,7 @@ quit(void)
int int
init(void) init(void)
{ {
#ifndef NO_SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0) if(SDL_Init(SDL_INIT_VIDEO) < 0)
return error("Init", SDL_GetError()); return error("Init", SDL_GetError());
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_SHOWN); gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * ZOOM, HEIGHT * ZOOM, SDL_WINDOW_SHOWN);
@ -254,6 +255,7 @@ init(void)
clear(pixels); clear(pixels);
SDL_StartTextInput(); SDL_StartTextInput();
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
#endif
screen.bounds.x1 = PAD * 8; screen.bounds.x1 = PAD * 8;
screen.bounds.x2 = WIDTH - PAD * 8 - 1; screen.bounds.x2 = WIDTH - PAD * 8 - 1;
screen.bounds.y1 = PAD * 8; screen.bounds.y1 = PAD * 8;
@ -429,12 +431,17 @@ ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
int int
start(Uxn *u) start(Uxn *u)
{ {
#ifndef NO_SDL
int ticknext = 0; int ticknext = 0;
#endif
evaluxn(u, u->vreset); evaluxn(u, u->vreset);
loadtheme(u->ram.dat + PAGE_DEVICE + 0x00f8); loadtheme(u->ram.dat + PAGE_DEVICE + 0x00f8);
#ifndef NO_SDL
if(screen.reqdraw) if(screen.reqdraw)
redraw(pixels, u); redraw(pixels, u);
#endif
while(1) { while(1) {
#ifndef NO_SDL
int tick = SDL_GetTicks(); int tick = SDL_GetTicks();
SDL_Event event; SDL_Event event;
if(tick < ticknext) if(tick < ticknext)
@ -455,9 +462,12 @@ start(Uxn *u)
break; break;
} }
} }
#endif
evaluxn(u, u->vframe); evaluxn(u, u->vframe);
#ifndef NO_SDL
if(screen.reqdraw) if(screen.reqdraw)
redraw(pixels, u); redraw(pixels, u);
#endif
} }
} }

13
run.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
EMULATOR=./bin/emulator
if [ "${1}" = '--no-sdl' ]; then
EMULATOR=./bin/emulator-nosdl
shift
fi
if [ -z "${1}" ]; then
printf 'usage: %s [--no-sdl] USM_FILE\n' "${0}" >&2
exit 2
fi
./bin/assembler "${1}" bin/boot.rom
"${EMULATOR}" bin/boot.rom