undar-lang/arch/web/gui/main.c

54 lines
954 B
C

#include <stdio.h>
#include "../../../vm/vm.h"
#undef true
#undef false
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
#include <emscripten.h>
#include <emscripten/html5.h>
#define CODE_SIZE 8192
#define MEMORY_SIZE 65536
u8 lmem[MEMORY_SIZE] = {0};
u32 lcode[CODE_SIZE] = {0};
bool init_vm() {
mem = lmem;
memset(mem, 0, MEMORY_SIZE*sizeof(u8));
code = lcode;
mp = 0;
cp = 0;
pc = 0;
interrupt = 0;
return true;
}
u32 syscall(u32 id, u32 args, u32 mem_ptr) {
return 0; // success
}
void mainloop() {
if (!step_vm()) {
emscripten_cancel_main_loop();
return;
}
}
i32 main() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL initialization failed: %s\n", SDL_GetError());
return 1;
}
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
emscripten_set_canvas_element_size("#canvas", 640, 480);
printf("VM loaded successfully\n");
emscripten_set_main_loop(mainloop, 0, 1);
return 0;
}