aboutsummaryrefslogtreecommitdiff
path: root/tr8vm.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-09 22:43:06 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-09 22:43:06 +0100
commit741561787cc2df547d5f520a142beaff234c488e (patch)
treed2753e0603d19c263f6b57986a4329408deff346 /tr8vm.c
parentc486618ae83fa7c822b29ab7f3f6f8f119112dd6 (diff)
downloadtr8vm-741561787cc2df547d5f520a142beaff234c488e.tar.gz
tr8vm-741561787cc2df547d5f520a142beaff234c488e.zip
Implement controller 1 (keyboard)
Exposed via port.
Diffstat (limited to 'tr8vm.c')
-rw-r--r--tr8vm.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tr8vm.c b/tr8vm.c
index 107b54b..fdede7c 100644
--- a/tr8vm.c
+++ b/tr8vm.c
@@ -113,6 +113,50 @@ uint8_t read_m(uint16_t addr)
return ram[addr];
}
+#define CTL_FIRE1 (1 << 0)
+#define CTL_FIRE2 (1 << 1)
+#define CTL_UP (1 << 2)
+#define CTL_DOWN (1 << 3)
+#define CTL_LEFT (1 << 4)
+#define CTL_RIGHT (1 << 5)
+#define CTL_SELECT (1 << 6)
+#define CTL_START (1 << 7)
+
+uint8_t ctl[2] = { 0 };
+
+static void update_ctl(SDL_Event *ev)
+{
+ switch (ev->key.keysym.sym)
+ {
+ case SDLK_z:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_FIRE1 : ctl[0] & ~CTL_FIRE1;
+ break;
+ case SDLK_x:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_FIRE2 : ctl[0] & ~CTL_FIRE2;
+ break;
+ case SDLK_UP:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_UP : ctl[0] & ~CTL_UP;
+ break;
+ case SDLK_DOWN:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_DOWN : ctl[0] & ~CTL_DOWN;
+ break;
+ case SDLK_LEFT:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_LEFT : ctl[0] & ~CTL_LEFT;
+ break;
+ case SDLK_RIGHT:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_RIGHT : ctl[0] & ~CTL_RIGHT;
+ break;
+ case SDLK_s:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_START : ctl[0] & ~CTL_START;
+ break;
+ case SDLK_d:
+ ctl[0] = ev->type == SDL_KEYDOWN ? ctl[0] | CTL_SELECT : ctl[0] & ~CTL_SELECT;
+ break;
+ default:
+ break;
+ }
+}
+
uint8_t blt_set = 0;
uint8_t blt_paramc = 0;
uint8_t blt_param[6] = { 0 };
@@ -192,6 +236,14 @@ uint8_t port(uint8_t p, uint8_t v)
blt_param[blt_paramc++] = v;
return p;
+ /* controller 1 */
+ case 0xf0:
+ return ctl[0];
+
+ /* controller 2 */
+ case 0xf1:
+ return ctl[1];
+
default:
return 0xff;
}
@@ -317,7 +369,11 @@ int main(int argc, char *argv[])
fullscreen ^= 1;
resize_full_screen(screen, renderer, fullscreen, &dst);
}
+ update_ctl(&ev);
}
+
+ if (ev.type == SDL_KEYUP)
+ update_ctl(&ev);
}
pitch = 0;