add more devices
This commit is contained in:
parent
a9f3ec694c
commit
035397209d
|
@ -14,12 +14,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
/* test_add_compile(vm.memory); */
|
/* test_add_compile(vm.memory); */
|
||||||
/* test_add_function_compile(vm.memory); */
|
/* test_add_function_compile(vm.memory); */
|
||||||
/* test_loop_compile(vm.memory); */
|
/* end = test_loop_compile(vm.memory); */
|
||||||
test_hello_world_compile(vm.memory);
|
end = test_hello_world_compile(vm.memory);
|
||||||
/* test_recursive_function_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);
|
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.devices[vm.dp++] = screen;
|
||||||
vm.mp += buffer_size;
|
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 */
|
/* Create window and renderer */
|
||||||
SDL_Window *window =
|
SDL_Window *window =
|
||||||
SDL_CreateWindow("Reality Engine VM", SDL_WINDOWPOS_CENTERED,
|
SDL_CreateWindow("Reality Engine VM", SDL_WINDOWPOS_CENTERED,
|
||||||
|
@ -56,7 +64,7 @@ int main(int argc, char **argv) {
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
running = false;
|
running = false;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
printf("mouse_down: x=%d, y=%d, btn=%d\n", event.button.x,
|
printf("mouse_down: x=%d, y=%d, btn=%d\n", event.button.x,
|
||||||
event.button.y, event.button.button);
|
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);
|
printf("mouse_move: x=%d, y=%d\n", event.motion.x, event.motion.y);
|
||||||
break;
|
break;
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
printf("touch_down x=%f, y=%f\n", event.tfinger.x * screen.s.width,
|
printf("touch_down x=%d, y=%d\n",
|
||||||
event.tfinger.y * screen.s.height);
|
(int)(event.tfinger.x * screen.s.width),
|
||||||
|
(int)(event.tfinger.y * screen.s.height));
|
||||||
break;
|
break;
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
printf("touch_move x=%f, y=%f\n", event.tfinger.x * screen.s.width,
|
printf("touch_move x=%d, y=%d\n",
|
||||||
event.tfinger.y * screen.s.height);
|
(int)(event.tfinger.x * screen.s.width),
|
||||||
|
(int)(event.tfinger.y * screen.s.height));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,24 @@ typedef struct screen_t {
|
||||||
Value *buffer;
|
Value *buffer;
|
||||||
} Screen;
|
} 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 {
|
typedef union device_u {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
Screen s;
|
Screen s;
|
||||||
|
Mouse m;
|
||||||
|
Keyboard k;
|
||||||
} Device;
|
} Device;
|
||||||
|
|
||||||
#define MEMORY_SIZE 65536
|
#define MEMORY_SIZE 65536
|
||||||
|
@ -100,7 +115,7 @@ typedef enum {
|
||||||
OP_UINT_TO_REAL, /* utor : dest = src1 as f32 */
|
OP_UINT_TO_REAL, /* utor : dest = src1 as f32 */
|
||||||
OP_ADD_REAL, /* addr : dest = src1 + src2 */
|
OP_ADD_REAL, /* addr : dest = src1 + src2 */
|
||||||
OP_SUB_REAL, /* subr : 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_DIV_REAL, /* divr : dest = src1 / src2 */
|
||||||
OP_JEQ_REAL, /* jeqr : jump to address dest if src1 as real == src2 as real */
|
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 */
|
OP_JGE_REAL, /* jgtr : jump to address dest if src1 as real >= src2 as real */
|
||||||
|
|
Loading…
Reference in New Issue