-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoystick.asm
209 lines (170 loc) · 2.48 KB
/
joystick.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
j_a: .equ %00000001
j_b: .equ %00000010
j_select: .equ %00000100
j_start: .equ %00001000
j_up: .equ %00010000
j_down: .equ %00100000
j_left: .equ %01000000
j_right: .equ %10000000
handle_joy:
;; don't do it if drawing
lda num_tiles_changed
beq .ok
rts
.ok:
;; clear
lda #0
sta cur_joy_state
;; strobe joystick 1
lda #1
sta $4016
lda #0
sta $4016
;; buttons...
.a:
lda $4016
and #%1
beq .b
lda #j_a
ora cur_joy_state
sta cur_joy_state
.b:
lda $4016
and #%1
beq .select
lda #j_b
ora cur_joy_state
sta cur_joy_state
.select:
lda $4016
and #%1
beq .start
lda #j_select
ora cur_joy_state
sta cur_joy_state
.start:
lda $4016
and #%1
beq .up
lda #j_start
ora cur_joy_state
sta cur_joy_state
.up:
lda $4016
and #%1
beq .down
lda #j_up
ora cur_joy_state
sta cur_joy_state
.down:
lda $4016
and #%1
beq .left
lda #j_down
ora cur_joy_state
sta cur_joy_state
.left:
lda $4016
and #%1
beq .right
lda #j_left
ora cur_joy_state
sta cur_joy_state
.right:
lda $4016
and #%1
beq .action
lda #j_right
ora cur_joy_state
sta cur_joy_state
.action:
lda #$FF
eor last_joy_state
and cur_joy_state
;; now, only new buttons are active
sta last_joy_state
;; perform actions
and #j_right
beq .act1
mov #dir_right,newd
jsr handle_direction
jmp .done
.act1: lda last_joy_state
and #j_left
beq .act2
mov #dir_left,newd
jsr handle_direction
jmp .done
.act2: lda last_joy_state
and #j_down
beq .act3
mov #dir_down,newd
jsr handle_direction
jmp .done
.act3: lda last_joy_state
and #j_up
beq .act4
mov #dir_up,newd
jsr handle_direction
jmp .done
.act4: lda last_joy_state
and #j_start
beq .act5
jsr handle_start
jmp .done
.act5: lda last_joy_state
and #j_select
beq .act6
jsr handle_select
jmp .done
.act6:
lda last_joy_state
and #j_a
beq .act7
jsr handle_a
jmp .done
.act7:
.done:
lda cur_joy_state
sta last_joy_state
rts
go_to_next_level:
lda level_num
clc
adc #1
cmp #29
bne .level_set
lda #0 ; reset
.level_set:
sta level_num
rts
handle_start: ; restart
jsr choose_level
rts
handle_select:
jsr go_to_next_level
jsr choose_level
rts
handle_a:
lda is_won ; only advance if won
beq .not_won
jsr go_to_next_level
jsr choose_level
.not_won:
lda is_dead
beq .not_dead
jsr choose_level ; reset if dead
.not_dead:
rts
handle_direction:
lda is_dead
bne .do_nothing
lda is_won
bne .do_nothing
jsr mask_nmi
jsr do_move
jsr draw_guy
jsr set_end_states
jsr ppu_on
.do_nothing:
rts