aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-14 03:35:46 +0200
committerkdx <kikoodx@paranoici.org>2023-04-14 03:35:46 +0200
commitcccfd1feffba5cab4510ed1d0597a9a7961854ef (patch)
tree71072737806a72bac6767001ee3e548bce3bafda /src
parentd77814424e5e3fe1b01cc4d2250d97248a70e2a9 (diff)
downloadorga-cccfd1feffba5cab4510ed1d0597a9a7961854ef.tar.gz
receive input
Diffstat (limited to 'src')
-rw-r--r--src/orgaemu.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/orgaemu.c b/src/orgaemu.c
index 7de0334..c1c898f 100644
--- a/src/orgaemu.c
+++ b/src/orgaemu.c
@@ -6,6 +6,25 @@
#define MEM_SIZE 0xffff
+static const uint16_t buttons[SDL_NUM_SCANCODES] = {
+ [SDL_SCANCODE_BACKSPACE] = 1 << 2,
+ [SDL_SCANCODE_RETURN] = 1 << 3,
+ /* WASD JK */
+ [SDL_SCANCODE_J] = 1 << 0,
+ [SDL_SCANCODE_K] = 1 << 1,
+ [SDL_SCANCODE_W] = 1 << 4,
+ [SDL_SCANCODE_S] = 1 << 5,
+ [SDL_SCANCODE_A] = 1 << 6,
+ [SDL_SCANCODE_D] = 1 << 7,
+ /* arrows XC */
+ [SDL_SCANCODE_X] = 1 << 0,
+ [SDL_SCANCODE_C] = 1 << 1,
+ [SDL_SCANCODE_UP] = 1 << 4,
+ [SDL_SCANCODE_DOWN] = 1 << 5,
+ [SDL_SCANCODE_LEFT] = 1 << 6,
+ [SDL_SCANCODE_RIGHT] = 1 << 7,
+};
+
static uint16_t *mem = NULL, *stack = NULL, *rstack = NULL;
static size_t stack_ptr = 0, rstack_ptr = 0;
static SDL_Window *window = NULL;
@@ -38,13 +57,21 @@ get_short(const unsigned char *s)
}
static int
-cycle_events(void)
+cycle_events(uint16_t *input)
{
SDL_Event e;
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_QUIT:
return 1;
+ case SDL_KEYDOWN:
+ if (e.key.repeat)
+ break;
+ *input |= buttons[e.key.keysym.scancode];
+ break;
+ case SDL_KEYUP:
+ *input &= ~(buttons[e.key.keysym.scancode]);
+ break;
default:
break;
}
@@ -272,7 +299,7 @@ exec_op(uint16_t *mem, long pc)
return pc + 1;
}
case OP_SLP:
- if (cycle_events())
+ if (cycle_events(mem + 0xbffe))
return MEM_SIZE;
render(mem + 0xbfff);
return pc + 1;