summaryrefslogtreecommitdiff
path: root/src/ubox/ubox_read_ctl.z80
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2020-12-30 19:07:31 +0000
committerJuan J. Martinez <jjm@usebox.net>2020-12-30 19:23:41 +0000
commit2682bc5d1d864341aaeb42a449db73c3ecd16d70 (patch)
tree9116764364b4ee0ce7f6037305077807b57776de /src/ubox/ubox_read_ctl.z80
downloadubox-msx-lib-2682bc5d1d864341aaeb42a449db73c3ecd16d70.tar.gz
ubox-msx-lib-2682bc5d1d864341aaeb42a449db73c3ecd16d70.zip
Initial import1.0
Diffstat (limited to 'src/ubox/ubox_read_ctl.z80')
-rw-r--r--src/ubox/ubox_read_ctl.z80100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/ubox/ubox_read_ctl.z80 b/src/ubox/ubox_read_ctl.z80
new file mode 100644
index 0000000..91963c0
--- /dev/null
+++ b/src/ubox/ubox_read_ctl.z80
@@ -0,0 +1,100 @@
+.globl _ubox_read_ctl
+
+RDPSG = 0x0096
+WRTPSG = 0x0093
+SNSMAT = 0x0141
+
+_ubox_read_ctl::
+ ld a, l
+ or a
+ jr z, is_keyb
+ dec a
+ jr z, is_joy1
+ dec a
+ jr z, is_joy2
+
+ ld l, #0
+ ret
+
+is_joy2:
+ ; select
+ ld e, #0xcf
+ jr call_psg
+
+is_joy1:
+ ; select
+ ld e, #0x8f
+
+call_psg:
+ ld a, #0x0f
+ call WRTPSG
+
+ ld a, #0x0e
+
+ di
+ call RDPSG
+ ei
+ cpl
+ and #0x3f
+ ld e, a
+
+ ; button 2 (M)
+ ld a, #4
+ call SNSMAT
+ rra
+ rra
+ rra
+ ld a, #0x20
+ jr nc, joy_extra_m
+ xor a
+joy_extra_m:
+ or e
+ ld l, a
+ ret
+
+is_keyb:
+ ; button 2 (M)
+ ld a, #4
+ call SNSMAT
+ rra
+ rra
+ rra
+ ld e, #0x20
+ jr nc, is_keyb_dir
+
+ ld e, #0
+
+is_keyb_dir:
+ ; direction
+ ld a, #8
+ call SNSMAT
+ cpl
+ rrca
+ rrca
+ ld c, a
+
+ and #4
+ ld b, a
+ ; b has left
+
+ ld a, c
+ rrca
+ rrca
+ ld c, a
+
+ and #0x18
+ or b
+ ld b, a
+ ; added space and right
+
+ ld a, c
+ rrca
+ and #3
+ or b
+ ; added down and up
+
+ or e
+ ; added 2nd fire (M)
+
+ ld l, a
+ ret