aboutsummaryrefslogtreecommitdiff
path: root/src/orgaemu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/orgaemu.c')
-rw-r--r--src/orgaemu.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/orgaemu.c b/src/orgaemu.c
index 4de09cf..ecc9c4d 100644
--- a/src/orgaemu.c
+++ b/src/orgaemu.c
@@ -1,9 +1,14 @@
-#include "drain.h"
#include "ops.h"
#include <stdio.h>
#include <stdint.h>
#include <SDL2/SDL.h>
+#ifdef EMBED_ROM
+#include "rom.h"
+#else
+#include "drain.h"
+#endif
+
#define MEM_SIZE 0xffff
static const uint16_t buttons[SDL_NUM_SCANCODES] = {
@@ -123,10 +128,9 @@ render(uint16_t *mem)
next_time += 1000 / 30;
const Uint64 cur_time = SDL_GetTicks64();
- if (next_time <= cur_time) {
- fprintf(stderr, "lagging %lu\n", cur_time - next_time);
+ if (next_time <= cur_time)
next_time = cur_time;
- } else
+ else
SDL_Delay(next_time - cur_time);
SDL_RenderPresent(renderer);
@@ -349,12 +353,22 @@ exec_data(uint16_t *mem)
int
main(int argc, char **argv)
{
+#ifdef EMBED_ROM
+ (void)argc, (void)argv;
+ mem = calloc(MEM_SIZE, sizeof(uint16_t));
+ if (mem == NULL) {
+ perror("main:calloc");
+ return 1;
+ }
+ for (unsigned i = 0; i < sizeof(rom); i += 2)
+ mem[i / 2] = get_short(rom + i);
+#else
if (argc != 2) {
fprintf(stderr, "usage: %s <rom>\n", argv[0]);
return 1;
}
- FILE *file = fopen(argv[1], "rb");
+ FILE *const file = fopen(argv[1], "rb");
if (file == NULL) {
perror(argv[1]);
return 1;
@@ -372,10 +386,9 @@ main(int argc, char **argv)
free(data);
return 1;
}
-
for (long i = 0; i < size; i += 2)
mem[i / 2] = get_short(data + i);
- free(data);
+#endif
stack = calloc(MEM_SIZE, sizeof(uint16_t));
if (stack == NULL) {