git @ Cat's Eye Technologies SixtyPical / 5a794a4
Name flags in routine outputs. Refactor game, add check_button. Cat's Eye Technologies 8 years ago
2 changed file(s) with 175 addition(s) and 117 deletion(s). Raw diff Collapse all Expand all
3535 reserve vector dispatch_logic
3636
3737 reserve byte[18] press_fire_msg: "PRESS`FIRE`TO`PLAY"
38
39 // could be routine-local, if they were truly static
40 reserve byte button_down: 0
41
42 /******************************************
43 * Utility routines for manipulating/checking the current actor's
44 * position and delta.
45 ******************************************/
46
47 routine reverse_delta {
48 lda #40
49 cmp <delta
50 if beq {
51 // copy #-40 delta
52 lda #216
53 sta <delta
54 lda #255
55 sta >delta
56 } else {
57 // copy #40 delta
58 lda #40
59 sta <delta
60 lda #0
61 sta >delta
62 }
63 }
3864
3965 routine calculate_new_position outputs (new_position) {
4066 clc
4672 sta >new_position
4773 }
4874
49 // output is carry
50 routine compare_new_pos {
75 routine compare_new_pos outputs (.c) {
5176 lda >new_position
5277 cmp >compare_target
5378 if beq {
5782 }
5883 }
5984
60 // output is carry
61 routine check_new_position_in_bounds {
85 routine check_new_position_in_bounds outputs (.c) {
6286 copy #$07e8 compare_target // just past bottom of screen
6387 jsr compare_new_pos
6488
76100 }
77101 }
78102 }
103
104 /******************************************
105 * Utility routines for dealing with the current actor's logic routine.
106 ******************************************/
107
108 routine indirect_jsr_logic {
109 jmp (dispatch_logic)
110 }
111
112 routine read_stick outputs (delta) {
113 lda #0
114 sta <delta
115 sta >delta
116 ldx joy2
117 txa
118 and #1 // up
119 if beq {
120 lda #216 // -40
121 sta <delta
122 lda #255
123 sta >delta
124 } else {
125 txa
126 and #2 // down
127 if beq {
128 lda #40
129 sta <delta
130 } else {
131 txa
132 and #4 // left
133 if beq {
134 lda #255 // -1
135 sta <delta
136 sta >delta
137 } else {
138 txa
139 and #8 // right
140 if beq {
141 lda #1
142 sta <delta
143 } else { }
144 }
145 }
146 }
147 }
148
149 routine check_fire outputs (.z) {
150 ldx joy2
151 txa
152 and #16
153 }
154
155 /********************
156 *** Actor Logics ***
157 ********************/
158
159 routine logic_player {
160 jsr read_stick
161 jsr calculate_new_position
162 jsr check_new_position_in_bounds
163 if bcs {
164 ldy #0
165 lda (new_position), y
166 cmp #32
167 if beq {
168 lda #32
169 ldy #0
170 sta (position), y
171 copy new_position position
172 lda #81
173 ldy #0
174 sta (position), y
175 } else {
176 // copy routine state_game_over to dispatch_state
177 }
178 } else { }
179 }
180
181 routine logic_obstacle {
182 jsr calculate_new_position
183 jsr check_new_position_in_bounds
184 if bcs {
185 ldy #0
186 lda (new_position), y
187 cmp #32
188 if beq {
189 lda #32
190 ldy #0
191 sta (position), y
192 copy new_position position
193 lda #82
194 ldy #0
195 sta (position), y
196 } else {
197 copy routine state_game_over to dispatch_state
198 }
199 } else {
200 jsr reverse_delta
201 }
202 }
203
204 /******************************************
205 * Utility routines used in dealing with the game state.
206 ******************************************/
79207
80208 routine clear_screen {
81209 ldy #0
97225 }
98226 }
99227
100 routine read_stick outputs (delta) {
101 lda #0
102 sta <delta
103 sta >delta
104 ldx joy2
105 txa
106 and #1 // up
228 // You can repeatedly (i.e. as part of actor logic or an IRQ handler)
229 // call this routine.
230 // Upon return, if carry is set, the button was pressed then released.
231
232 routine check_button outputs (.c) {
233 lda button_down
107234 if beq {
108 lda #216 // -40
109 sta <delta
110 lda #255
111 sta >delta
112 } else {
113 txa
114 and #2 // down
115 if beq {
116 lda #40
117 sta <delta
118 } else {
119 txa
120 and #4 // left
121 if beq {
122 lda #255 // -1
123 sta <delta
124 sta >delta
125 } else {
126 txa
127 and #8 // right
128 if beq {
129 lda #1
130 sta <delta
131 } else { }
132 }
133 }
134 }
135 }
136
137 // output is .z flag
138 routine check_fire {
139 ldx joy2
140 txa
141 and #16
235 lda joy2
236 and #$10
237 if beq {
238 lda #1
239 sta button_down
240 } else { }
241 clc
242 } else {
243 lda joy2
244 and #$10
245 if bne {
246 lda #0
247 sta button_down
248 sec
249 } else {
250 clc
251 }
252 }
142253 }
143254
144255 routine init_game {
172283 cpy #16
173284 }
174285 }
286
287 /*******************
288 *** Game States ***
289 *******************/
175290
176291 routine state_title_screen {
177292 lda #5
187302 iny
188303 cpy #18
189304 }
190 jsr check_fire
191 if beq {
305 jsr check_button
306 if bcs {
192307 jsr clear_screen
193308 jsr init_game
194309 copy routine state_play_game to dispatch_state
198313
199314 routine state_game_over {
200315 inc vic_border
201 jsr check_fire
202 if beq {
316 jsr check_button
317 if bcs {
318 jsr clear_screen
203319 copy routine state_title_screen to dispatch_state
204320 } else { }
205321 jmp (save_cinv)
206 }
207
208 routine logic_player {
209 jsr read_stick
210 jsr calculate_new_position
211 jsr check_new_position_in_bounds
212 if bcs {
213 ldy #0
214 lda (new_position), y
215 cmp #32
216 if beq {
217 lda #32
218 ldy #0
219 sta (position), y
220 copy new_position position
221 lda #81
222 ldy #0
223 sta (position), y
224 } else {
225 // copy routine state_game_over to dispatch_state
226 }
227 } else { }
228 }
229
230 routine reverse_delta {
231 lda #40
232 cmp <delta
233 if beq {
234 // copy #-40 delta
235 lda #216
236 sta <delta
237 lda #255
238 sta >delta
239 } else {
240 // copy #40 delta
241 lda #40
242 sta <delta
243 lda #0
244 sta >delta
245 }
246 }
247
248 routine logic_obstacle {
249 jsr calculate_new_position
250 jsr check_new_position_in_bounds
251 if bcs {
252 ldy #0
253 lda (new_position), y
254 cmp #32
255 if beq {
256 lda #32
257 ldy #0
258 sta (position), y
259 copy new_position position
260 lda #82
261 ldy #0
262 sta (position), y
263 } else {
264 copy routine state_game_over to dispatch_state
265 }
266 } else {
267 jsr reverse_delta
268 }
269 }
270
271 routine indirect_jsr_logic {
272 jmp (dispatch_logic)
273322 }
274323
275324 routine state_play_game {
294343 jmp (save_cinv)
295344 }
296345
346 /*************************
347 * Main Game Loop Driver *
348 *************************/
349
297350 routine our_cinv {
298351 jmp (dispatch_state)
299352 }
218218 explicit_register :: Parser StorageLocation
219219 explicit_register = ((try $ explicit_location ".a" A) <|>
220220 (try $ explicit_location ".x" X) <|>
221 (explicit_location ".y" Y))
221 (try $ explicit_location ".y" Y) <|>
222 (try $ explicit_location ".n" FlagN) <|>
223 (try $ explicit_location ".v" FlagV) <|>
224 (try $ explicit_location ".d" FlagD) <|>
225 (try $ explicit_location ".z" FlagZ) <|>
226 (explicit_location ".c" FlagC))
222227
223228 register_location :: Parser AddressingModality
224229 register_location = do