summaryrefslogtreecommitdiff
path: root/source/spec.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/spec.c')
-rw-r--r--source/spec.c80
1 files changed, 78 insertions, 2 deletions
diff --git a/source/spec.c b/source/spec.c
index 1a5eba2..0dc753f 100644
--- a/source/spec.c
+++ b/source/spec.c
@@ -134,9 +134,16 @@ static struct
};
-/* The keyboard
+/* The keyboard and joystick
*/
static Z80Byte matrix[8];
+static Z80Byte joystick;
+
+#define JOY_FIRE 0x10
+#define JOY_UP 0x08
+#define JOY_DOWN 0x04
+#define JOY_LEFT 0x02
+#define JOY_RIGHT 0x01
static struct
{
@@ -424,7 +431,66 @@ void SPECHandleKey(SoftKey key, int is_pressed)
}
else
{
- /* TODO: Joysticks? */
+ switch(key)
+ {
+ case SK_PAD_UP:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_UP;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_UP;
+ }
+ break;
+
+ case SK_PAD_DOWN:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_DOWN;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_DOWN;
+ }
+ break;
+
+ case SK_PAD_LEFT:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_LEFT;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_LEFT;
+ }
+ break;
+
+ case SK_PAD_RIGHT:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_RIGHT;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_RIGHT;
+ }
+ break;
+
+ case SK_PAD_A:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_FIRE;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_FIRE;
+ }
+ break;
+
+ default:
+ break;
+ }
}
}
@@ -448,9 +514,19 @@ Z80Byte SPECReadPort(Z80 *z80, Z80Word port)
switch(lo)
{
case 0x1f: /* Kempston joystick */
+ b = joystick;
break;
case 0x7f: /* Fuller joystick */
+ b = ~joystick;
+ if (b & JOY_FIRE)
+ {
+ b |= 0x80;
+ }
+ else
+ {
+ b &= 0x7f;
+ }
break;
case 0xfb: /* ZX Printer */