From 035397209d4b11c70ad38a976063c14e8c7f53c9 Mon Sep 17 00:00:00 2001 From: zongor Date: Sun, 20 Jul 2025 10:00:38 -0400 Subject: [PATCH] add more devices --- src/arch/linux/main.c | 30 ++++++++++++++++++++---------- src/opcodes.h | 17 ++++++++++++++++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/arch/linux/main.c b/src/arch/linux/main.c index 31dc0db..46593e6 100644 --- a/src/arch/linux/main.c +++ b/src/arch/linux/main.c @@ -14,12 +14,9 @@ int main(int argc, char **argv) { /* test_add_compile(vm.memory); */ /* test_add_function_compile(vm.memory); */ - /* test_loop_compile(vm.memory); */ - test_hello_world_compile(vm.memory); + /* end = test_loop_compile(vm.memory); */ + end = test_hello_world_compile(vm.memory); /* test_recursive_function_compile(vm.memory); */ - while (step_vm(&vm)); - core_dump(&vm); - return 0; uint32_t buffer_size = 640 * 480 * sizeof(uint32_t); @@ -32,6 +29,17 @@ int main(int argc, char **argv) { vm.devices[vm.dp++] = screen; vm.mp += buffer_size; + Device mouse; + mouse.type = MOUSE; + mouse.m = (Mouse){.x = 0, .y = 0, .btn1 = 0, .btn2 = 0, .btn3 = 0}; + vm.devices[vm.dp++] = mouse; + + Device keyboard; + keyboard.type = KEYBOARD; + const uint8_t *state = SDL_GetKeyboardState(NULL); + keyboard.k = (Keyboard){.length = SDL_NUM_SCANCODES, .keys = state}; + vm.devices[vm.dp++] = keyboard; + /* Create window and renderer */ SDL_Window *window = SDL_CreateWindow("Reality Engine VM", SDL_WINDOWPOS_CENTERED, @@ -56,7 +64,7 @@ int main(int argc, char **argv) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: - running = false; + running = false; case SDL_MOUSEBUTTONDOWN: printf("mouse_down: x=%d, y=%d, btn=%d\n", event.button.x, event.button.y, event.button.button); @@ -65,12 +73,14 @@ int main(int argc, char **argv) { printf("mouse_move: x=%d, y=%d\n", event.motion.x, event.motion.y); break; case SDL_FINGERDOWN: - printf("touch_down x=%f, y=%f\n", event.tfinger.x * screen.s.width, - event.tfinger.y * screen.s.height); + printf("touch_down x=%d, y=%d\n", + (int)(event.tfinger.x * screen.s.width), + (int)(event.tfinger.y * screen.s.height)); break; case SDL_FINGERMOTION: - printf("touch_move x=%f, y=%f\n", event.tfinger.x * screen.s.width, - event.tfinger.y * screen.s.height); + printf("touch_move x=%d, y=%d\n", + (int)(event.tfinger.x * screen.s.width), + (int)(event.tfinger.y * screen.s.height)); break; } } diff --git a/src/opcodes.h b/src/opcodes.h index 37deebd..213e890 100644 --- a/src/opcodes.h +++ b/src/opcodes.h @@ -34,9 +34,24 @@ typedef struct screen_t { Value *buffer; } Screen; +typedef struct mouse_t { + uint32_t x; + uint32_t y; + uint8_t btn1; + uint8_t btn2; + uint8_t btn3; +} Mouse; + +typedef struct keyboard_t { + uint32_t length; + const uint8_t *keys; +} Keyboard; + typedef union device_u { uint8_t type; Screen s; + Mouse m; + Keyboard k; } Device; #define MEMORY_SIZE 65536 @@ -100,7 +115,7 @@ typedef enum { OP_UINT_TO_REAL, /* utor : dest = src1 as f32 */ OP_ADD_REAL, /* addr : dest = src1 + src2 */ OP_SUB_REAL, /* subr : dest = src1 - src2 */ - OP_MUL_REAL, /* mulr : dest = src1 * src2 */ + OP_MUL_REAL, /* ulr : dest = src1 * src2 */ OP_DIV_REAL, /* divr : dest = src1 / src2 */ OP_JEQ_REAL, /* jeqr : jump to address dest if src1 as real == src2 as real */ OP_JGE_REAL, /* jgtr : jump to address dest if src1 as real >= src2 as real */