Change global instead of returning with carry set.
Chris Pressey
3 years ago
35 | 35 | screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4 |
36 | 36 | outputs dispatch_game_state, |
37 | 37 | actor_pos, actor_delta, actor_logic, |
38 | player_died, | |
38 | 39 | screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4 |
39 | 40 | trashes a, x, y, c, z, n, v, pos, new_pos, delta, ptr, dispatch_logic |
40 | 41 | game_state_routine |
44 | 45 | // |
45 | 46 | // Routines that conform to this type also follow this convention: |
46 | 47 | // |
47 | // Set carry if the player perished. Carry clear otherwise. | |
48 | // Set player_died to 1 if the player perished. Unchanged otherwise. | |
48 | 49 | // |
49 | 50 | |
50 | 51 | typedef routine |
51 | inputs pos, delta, joy2, screen | |
52 | outputs pos, delta, new_pos, screen, c | |
53 | trashes a, x, y, z, n, v, ptr | |
52 | inputs pos, delta, joy2, screen, player_died | |
53 | outputs pos, delta, new_pos, screen, player_died | |
54 | trashes a, x, y, z, n, v, c, ptr | |
54 | 55 | logic_routine |
55 | 56 | |
56 | 57 | // ---------------------------------------------------------------- |
85 | 86 | |
86 | 87 | word table[256] actor_delta |
87 | 88 | word delta |
89 | ||
90 | byte player_died | |
88 | 91 | |
89 | 92 | vector logic_routine table[256] actor_logic |
90 | 93 | vector logic_routine dispatch_logic |
240 | 243 | |
241 | 244 | routine init_game |
242 | 245 | inputs actor_pos, actor_delta, actor_logic |
243 | outputs actor_pos, actor_delta, actor_logic | |
246 | outputs actor_pos, actor_delta, actor_logic, player_died | |
244 | 247 | trashes pos, a, y, z, n, c, v |
245 | 248 | { |
246 | 249 | ld y, 0 |
258 | 261 | } until z |
259 | 262 | |
260 | 263 | ld y, 0 |
261 | copy word 0, actor_pos + y | |
264 | copy word 40, actor_pos + y | |
262 | 265 | copy word 0, actor_delta + y |
263 | 266 | copy player_logic, actor_logic + y |
267 | ||
268 | st y, player_died | |
264 | 269 | } |
265 | 270 | |
266 | 271 | // ---------------------------------------------------------------- |
300 | 305 | st off, c |
301 | 306 | add ptr, pos |
302 | 307 | copy 81, [ptr] + y |
303 | ||
304 | st off, c | |
305 | 308 | } else { |
306 | st on, c | |
309 | ld a, 1 | |
310 | st a, player_died | |
307 | 311 | } |
308 | 312 | |
309 | 313 | // FIXME these trashes, strictly speaking, probably shouldn't be needed, |
313 | 317 | trash ptr |
314 | 318 | trash y |
315 | 319 | trash v |
316 | } else { | |
317 | st off, c | |
318 | 320 | } |
319 | 321 | } |
320 | 322 | |
350 | 352 | st off, c |
351 | 353 | add ptr, pos |
352 | 354 | copy 82, [ptr] + y |
353 | ||
354 | st off, c | |
355 | } else { | |
356 | st on, c | |
357 | 355 | } |
358 | 356 | |
359 | 357 | // FIXME these trashes, strictly speaking, probably shouldn't be needed, |
372 | 370 | copy $ffd8, delta |
373 | 371 | } |
374 | 372 | } |
375 | ||
376 | st off, c | |
377 | 373 | } |
378 | 374 | |
379 | 375 | // ---------------------------------------------------------------- |
383 | 379 | define game_state_title_screen game_state_routine |
384 | 380 | { |
385 | 381 | ld y, 0 |
382 | st y, player_died | |
386 | 383 | for y up to 17 { |
387 | 384 | ld a, press_fire_msg + y |
388 | 385 | |
407 | 404 | define game_state_play game_state_routine |
408 | 405 | { |
409 | 406 | ld x, 0 |
407 | st x, player_died | |
410 | 408 | for x up to 15 { |
411 | 409 | copy actor_pos + x, pos |
412 | 410 | copy actor_delta + x, delta |
419 | 417 | save x { |
420 | 418 | copy actor_logic + x, dispatch_logic |
421 | 419 | call dispatch_logic |
422 | ||
423 | if c { | |
424 | // Player died! Want no dead! | |
425 | call clear_screen | |
426 | copy game_state_game_over, dispatch_game_state | |
427 | } | |
428 | 420 | } |
429 | 421 | |
430 | 422 | copy pos, actor_pos + x |
431 | 423 | copy delta, actor_delta + x |
432 | 424 | } |
433 | 425 | |
426 | ld a, player_died | |
427 | if not z { | |
428 | // Player died! Want no dead! | |
429 | call clear_screen | |
430 | copy game_state_game_over, dispatch_game_state | |
431 | } | |
432 | ||
434 | 433 | goto save_cinv |
435 | 434 | } |
436 | 435 | |
437 | 436 | define game_state_game_over game_state_routine |
438 | 437 | { |
438 | ld y, 0 | |
439 | st y, player_died | |
439 | 440 | st off, c |
440 | 441 | call check_button |
441 | 442 |