aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-12 10:42:03 +0200
committerkdx <kikoodx@paranoici.org>2023-06-12 10:42:03 +0200
commit0bf3be956c9cc8d919aea9f1c6f4ab7f3b735a52 (patch)
treeffd9c83025fed53e4aeafe649192ab1d54c960f2
parent78dc5325ae51a8871457b9c418fbed0495bc8910 (diff)
downloadorga-0bf3be956c9cc8d919aea9f1c6f4ab7f3b735a52.tar.gz
NO_SDL define
-rwxr-xr-xbuild.sh2
-rw-r--r--src/orgaemu.c92
2 files changed, 53 insertions, 41 deletions
diff --git a/build.sh b/build.sh
index d742611..b48d718 100755
--- a/build.sh
+++ b/build.sh
@@ -2,6 +2,6 @@
CFLAGS='-std=c99 -Wall -Wextra -O3 -s'
[ "$CC" = "" ] && CC=gcc
printf 'orgaasm\n'
-$CC $CFLAGS -o orgaasm src/orgaasm.c
+$CC $CFLAGS $1 -o orgaasm src/orgaasm.c
printf 'orgaemu\n'
$CC $CFLAGS -o orgaemu src/orgaemu.c $@ -lSDL2
diff --git a/src/orgaemu.c b/src/orgaemu.c
index 09fd453..189f88c 100644
--- a/src/orgaemu.c
+++ b/src/orgaemu.c
@@ -2,7 +2,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
-#include <SDL2/SDL.h>
#ifdef EMBED_ROM
#include "rom.h"
@@ -12,6 +11,12 @@
#define MEM_SIZE 0xffff
+static uint16_t *mem = NULL, *stack = NULL, *rstack = NULL;
+static size_t stack_ptr = 0, rstack_ptr = 0;
+
+#ifndef NO_SDL
+#include <SDL2/SDL.h>
+
static const uint16_t buttons[SDL_NUM_SCANCODES] = {
[SDL_SCANCODE_BACKSPACE] = 1 << 2,
[SDL_SCANCODE_RETURN] = 1 << 3,
@@ -31,51 +36,12 @@ static const uint16_t buttons[SDL_NUM_SCANCODES] = {
[SDL_SCANCODE_RIGHT] = 1 << 7,
};
-static uint16_t *mem = NULL, *stack = NULL, *rstack = NULL;
-static size_t stack_ptr = 0, rstack_ptr = 0;
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
static SDL_Texture *target = NULL;
static Uint64 next_time = 0;
static int
-fail(void)
-{
- if (target != NULL)
- SDL_DestroyTexture(target);
- if (renderer != NULL)
- SDL_DestroyRenderer(renderer);
- if (window != NULL)
- SDL_DestroyWindow(window);
- SDL_Quit();
- if (mem != NULL)
- free(mem);
- if (stack != NULL)
- free(stack);
- if (rstack != NULL)
- free(rstack);
- return 1;
-}
-
-static void
-error(const char *fmt, ...)
-{
- char buf[256] = {0};
- va_list va;
- va_start(va, fmt);
- vsnprintf(buf, sizeof(buf) - 1, fmt, va);
- va_end(va);
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "orgaemu", buf, window);
- fprintf(stderr, "%s\n", buf);
-}
-
-static uint16_t
-get_short(const unsigned char *s)
-{
- return s[0] | (s[1] * 0x0100);
-}
-
-static int
cycle_events(uint16_t *input)
{
SDL_Event e;
@@ -148,6 +114,48 @@ render(uint16_t *mem)
SDL_RenderPresent(renderer);
}
+#endif
+
+static uint16_t
+get_short(const unsigned char *s)
+{
+ return s[0] | (s[1] * 0x0100);
+}
+
+static int
+fail(void)
+{
+#ifndef NO_SDL
+ if (target != NULL)
+ SDL_DestroyTexture(target);
+ if (renderer != NULL)
+ SDL_DestroyRenderer(renderer);
+ if (window != NULL)
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+#endif
+ if (mem != NULL)
+ free(mem);
+ if (stack != NULL)
+ free(stack);
+ if (rstack != NULL)
+ free(rstack);
+ return 1;
+}
+
+static void
+error(const char *fmt, ...)
+{
+ char buf[256] = {0};
+ va_list va;
+ va_start(va, fmt);
+ vsnprintf(buf, sizeof(buf) - 1, fmt, va);
+ va_end(va);
+ fprintf(stderr, "%s\n", buf);
+#ifndef NO_SDL
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "orgaemu", buf, window);
+#endif
+}
static void
push(uint16_t v)
@@ -342,9 +350,11 @@ exec_op(uint16_t *mem, long pc)
return pc + 1;
}
case OP_SLP:
+#ifndef NO_SDL
if (cycle_events(mem + 0xbffe))
return MEM_SIZE;
render(mem + 0xbfff);
+#endif
return pc + 1;
case OP_INC:
push(pop() + 1);
@@ -427,6 +437,7 @@ main(int argc, char **argv)
return fail();
}
+#ifndef NO_SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "%s\n", SDL_GetError());
return fail();
@@ -443,6 +454,7 @@ main(int argc, char **argv)
return fail();
}
next_time = SDL_GetTicks64();
+#endif
exec_data(mem);
return fail(), 0;