aboutsummaryrefslogtreecommitdiff
path: root/src/pad/ps1
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2021-07-03 00:49:03 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:20 +0200
commit6b9f686913efc3725b2690033cd4f398e07076ba (patch)
treee9aa91a6b9f617d78123ebe7ad272fc42a60d306 /src/pad/ps1
parentc9e6ae44a9aeb89b3f48f3443d6baa80103f7445 (diff)
downloadjancity-6b9f686913efc3725b2690033cd4f398e07076ba.tar.gz
Add project source code
Diffstat (limited to 'src/pad/ps1')
-rw-r--r--src/pad/ps1/inc/pad/port.h20
-rw-r--r--src/pad/ps1/src/pad.c41
2 files changed, 61 insertions, 0 deletions
diff --git a/src/pad/ps1/inc/pad/port.h b/src/pad/ps1/inc/pad/port.h
new file mode 100644
index 0000000..14dc784
--- /dev/null
+++ b/src/pad/ps1/inc/pad/port.h
@@ -0,0 +1,20 @@
+#ifndef PAD_PS1_H
+#define PAD_PS1_H
+
+#include <psx.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct pad_port
+{
+ psx_pad_state pps;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PAD_PS1_H */
diff --git a/src/pad/ps1/src/pad.c b/src/pad/ps1/src/pad.c
new file mode 100644
index 0000000..eea56ed
--- /dev/null
+++ b/src/pad/ps1/src/pad.c
@@ -0,0 +1,41 @@
+#include <pad.h>
+#include <pad_private.h>
+#include <pad/port.h>
+#include <stddef.h>
+#include <string.h>
+
+void pad_init(const int player, struct pad *const p)
+{
+ memset(p, 0, sizeof *p);
+ p->player = player;
+}
+
+void pad_port_update(struct pad *const p)
+{
+ static const int psx_keys[] =
+ {
+ [PAD_KEY_LEFT] = PAD_LEFT,
+ [PAD_KEY_RIGHT] = PAD_RIGHT,
+ [PAD_KEY_UP] = PAD_UP,
+ [PAD_KEY_DOWN] = PAD_DOWN,
+ [PAD_KEY_A] = PAD_CROSS,
+ [PAD_KEY_B] = PAD_CIRCLE,
+ [PAD_KEY_C] = PAD_TRIANGLE,
+ [PAD_KEY_D] = PAD_SQUARE,
+ [PAD_KEY_E] = PAD_L1,
+ [PAD_KEY_OPTIONS] = PAD_START
+ };
+
+ p->mask = 0;
+ PSX_PollPad(p->player, &p->port.pps);
+
+ for (size_t i = 0; i < sizeof psx_keys / sizeof *psx_keys; i++)
+ {
+ const int mask = 1 << i;
+
+ if (p->port.pps.buttons & psx_keys[i])
+ p->mask |= mask;
+ else
+ p->mask &= ~mask;
+ }
+}