-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.z80
98 lines (93 loc) · 3.93 KB
/
input.z80
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
92
93
94
95
96
97
; functions for input recognition, mapped to behaviours in the game
; handles key and joystick
; Current interface is that the main function get_input processes the keyb_buffer
; (see input_raw.z80), identifies inputs that map to actions (up/down/left/right/fire/pause/quit/etc)
; and updates one of a few state variables:
; controller_flags_fire : non-zero if the fire button is held
; controller_flags_dirs : a bitmask of up/down/left/right actions
; (where up+down are mutually exclusive and so are left+right
; but diagonals are allowed)
; todo: redefinable keys
; todo: include joystick
get_input:
; joystick left, right, up, down, fire
; keyboard left arrow, right arrow, up arrow, down arrow, space
call get_input_raw
; if key is pressed, set corresponding key flag
; if key is not pressed, clear corresponding key flag
; keyboard:
; up=row_9_bit_1
; down=row_9_bit_2
; left=row_9_bit_3
; right=row_9_bit_4
; fire(space)=row_8_bit_0
; joystick1:
; up=row_4_bit_3
; down=row_4_bit_2
; left=row_4_bit_0
; right=row_4_bit_1
; fire=row_4_bit_4
; joystick2:
; up=row_5_bit_1
; down=row_4_bit_2
; left=row_4_bit_4
; right=row_4_bit_3
; fire=row_4_bit_0
; REMEMBER: if key is down then bit reads ZERO. if key is not down then bit reads ONE
xor a
ld hl, keyb_buffer+7
bit 0, (hl)
jr nz, @+next
inc a; set key flag for FIRE
@next:
ld (controller_flags_fire), a
xor a
ld hl, keyb_buffer+8
; CHECK UP
bit 1, (hl) ; UP key was pressed
jr nz, @+next
or controller_flags_dirs_up ; set key flag for UP
@next:
; CHECK DOWN
bit 2, (hl) ; DOWN key was pressed
jr nz, @+next
or controller_flags_dirs_down ; set key flag for DOWN
@next:
; CHECK LEFT
bit 3, (hl) ; LEFT key was pressed
jr nz, @+next
or controller_flags_dirs_left ; set key flag for LEFT
@next:
; CHECK RIGHT
bit 4,(hl) ; RIGHT key was pressed
jr nz, @+next
or controller_flags_dirs_right ; set key flag for RIGHT
@next:
; check for invalid combinations.
; left + right is disallowed
; up + down is disallowed
ld b, a
and controller_flags_dirs_left + controller_flags_dirs_right
cp controller_flags_dirs_left + controller_flags_dirs_right
ld a, b ; doesn't affect flags
jr nz, @done_checking_left_right_combo
and 255 - controller_flags_dirs_left - controller_flags_dirs_right
@done_checking_left_right_combo:
ld b, a
and controller_flags_dirs_up + controller_flags_dirs_down
cp controller_flags_dirs_up + controller_flags_dirs_down
ld a, b ; doesn't affect flags
jr nz, @done_checking_up_down_combo
and 255 - controller_flags_dirs_up - controller_flags_dirs_down
@done_checking_up_down_combo:
ld (controller_flags_dirs), a
; check for freeze key (use H to halt)
if DEBUG
ld hl, keyb_buffer+6
xor a
bit 4, (hl)
jr nz, @+next
inc a
@next: ld (freeze), a
ENDIF
ret