add emscripten wasm

This commit is contained in:
zongor 2025-06-14 11:44:36 -04:00
parent 381b6ebb9a
commit 0cd92bb919
1 changed files with 22 additions and 8 deletions

View File

@ -1,18 +1,28 @@
#include "debug.h"
#include "vm.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
#define MEMORY_SIZE 1024
void run_vm(Data *memory, uint32_t memory_size) {
uint32_t pc = 1; /* Program counter */
while (pc) {
pc = step_vm(memory, memory_size, pc);
Data memory[MEMORY_SIZE] = {0}; /* Memory array */
uint32_t pc = 1; /* Program counter */
void mainloop() {
pc = step_vm(memory, MEMORY_SIZE, pc);
if (pc == 0) {
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop(); /* this should "kill" the app. */
#else
core_dump(memory, MEMORY_SIZE);
exit(0);
#endif
}
}
int main() {
Data memory[MEMORY_SIZE] = {0}; /* Memory array */
int i = 1;
memory[0].c[0] = 'z';
@ -61,7 +71,11 @@ int main() {
memory[102].f = 5.f;
memory[103].f = 5.f;
run_vm(memory, MEMORY_SIZE);
return core_dump(memory, MEMORY_SIZE);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainloop, 0, 1);
#else
while (1) {
mainloop();
}
#endif
}