Use save block (and a for loop) in the flagship demo game source.
Chris Pressey
7 years ago
405 | 405 | } |
406 | 406 | |
407 | 407 | define game_state_play game_state_routine |
408 | static byte save_x : 0 | |
409 | 408 | { |
410 | 409 | ld x, 0 |
411 | repeat { | |
410 | for x up to 15 { | |
412 | 411 | copy actor_pos + x, pos |
413 | 412 | copy actor_delta + x, delta |
414 | 413 | |
415 | st x, save_x | |
416 | ||
417 | copy actor_logic + x, dispatch_logic | |
418 | call dispatch_logic | |
419 | ||
420 | if c { | |
421 | // Player died! Want no dead! | |
422 | call clear_screen | |
423 | copy game_state_game_over, dispatch_game_state | |
424 | } | |
425 | ld x, save_x | |
414 | // | |
415 | // Save our loop counter on the stack temporarily. This means that routines | |
416 | // like `dispatch_logic` and `clear_screen` are allowed to do whatever they | |
417 | // want with the `x` register; we will restore it at the end of this block. | |
418 | // | |
419 | save x { | |
420 | copy actor_logic + x, dispatch_logic | |
421 | 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 | } | |
426 | 429 | |
427 | 430 | copy pos, actor_pos + x |
428 | 431 | copy delta, actor_delta + x |
429 | ||
430 | inc x | |
431 | cmp x, 16 | |
432 | } until z | |
432 | } | |
433 | 433 | |
434 | 434 | goto save_cinv |
435 | 435 | } |