-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.asm
91 lines (72 loc) · 2.18 KB
/
input.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module INPUT
;
; ----- 4 3 2 1 0
;
; $FE - V, C, X, Z, SH 0
; $FD - G, F, D, S, A 1
; $FB - T, R, E, W, Q 2
; $F7 - 5, 4, 3, 2, 1 3
; $EF - 6, 7, 8, 9, 0 4
; $DF - Y, U, I, O, P 5
; $BF - H, J, K, L, NL 6
; $7F - B, N, M, ., SP 7
;
; joystick bit, or $ff/%11111111 for no joy
; key row offset 0-7,
; key mask, or $ff/%11111111 for no key
; trigger impulse
; calculate actual input impulse addresses
up = inputstates + 3
down = inputstates + 7
left = inputstates + 11
right = inputstates + 15
fire = inputstates + 19
advance = inputstates + 23
feature = inputstates + 27
pause = inputstates + 31
.align 8
_kbin:
.fill 8
_lastJ:
.byte 0
_nullstick:
ld a,$ff
ret
readinput:
jsreadfn = $+1
call _nullstick
ld (_lastJ),a
; point at first input state block
;
ld hl,inputstates
call updateinputstate ; (up)
call updateinputstate ; (down)
call updateinputstate ; etc.
call updateinputstate ;
call updateinputstate
call updateinputstate
call updateinputstate
; fall into here for last input - quit
updateinputstate:
ld a,(hl) ; input info table
ld (_uibittest),a ; get mask for j/s bit test
inc hl
ld a,(hl) ; half-row index
inc hl
ld de,_kbin ; keyboard bits table pointer - 8 byte aligned
or e
ld e,a ; add offset to table
ld a,(de) ; get key input bits
and (hl) ; result will be a = 0 if required key is down
inc hl
jr z,{+} ; skip joystick read if pressed
ld a,(_lastJ)
+: sla (hl) ; (key & 3) = 0 - not pressed, 1 - just pressed, 2 - just released and >3 - held
_uibittest = $+1
and 0 ; if a key was already detected a will be 0 so this test succeeds
jr nz,{+} ; otherwise joystick bit is tested - skip if bit = 1 (not pressed)
set 0,(hl) ; signify impulse
+: inc hl ; ready for next input in table
ret