1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-29 03:51:35 +00:00

Use a vector table in the demo game.

This commit is contained in:
Chris Pressey 2018-02-06 15:03:59 +00:00
parent 02d703aaf1
commit 43b3a088b0
3 changed files with 15 additions and 24 deletions

View File

@ -32,12 +32,12 @@
typedef routine typedef routine
inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x, inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
actor_pos, pos, new_pos, actor_delta, delta, actor_pos, pos, new_pos, actor_delta, delta, actor_logic,
screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
outputs button_down, dispatch_game_state, outputs button_down, dispatch_game_state,
actor_pos, pos, new_pos, actor_delta, delta, actor_pos, pos, new_pos, actor_delta, delta, actor_logic,
screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
trashes a, x, y, c, z, n, v, ptr, save_x, compare_target trashes a, x, y, c, z, n, v, ptr, save_x, compare_target, dispatch_logic
game_state_routine game_state_routine
// //
@ -87,6 +87,9 @@ word new_pos
word table[256] actor_delta word table[256] actor_delta
word delta word delta
vector (logic_routine) table[256] actor_logic
vector logic_routine dispatch_logic
byte button_down : 0 // effectively static-local to check_button byte button_down : 0 // effectively static-local to check_button
byte table[32] press_fire_msg: "PRESS`FIRE`TO`PLAY" byte table[32] press_fire_msg: "PRESS`FIRE`TO`PLAY"
@ -239,8 +242,8 @@ routine check_new_position_in_bounds
} }
routine init_game routine init_game
inputs actor_pos, actor_delta inputs actor_pos, actor_delta, actor_logic
outputs actor_pos, actor_delta, pos outputs actor_pos, actor_delta, pos, actor_logic
trashes a, y, z, n, c, v trashes a, y, z, n, c, v
{ {
ld y, 0 ld y, 0
@ -248,6 +251,7 @@ routine init_game
repeat { repeat {
copy pos, actor_pos + y copy pos, actor_pos + y
copy word 40, actor_delta + y copy word 40, actor_delta + y
copy forward enemy_logic, actor_logic + y
st off, c st off, c
add pos, word 7 add pos, word 7
@ -259,6 +263,7 @@ routine init_game
ld y, 0 ld y, 0
copy word 0, actor_pos + y copy word 0, actor_pos + y
copy word 0, actor_delta + y copy word 0, actor_delta + y
copy forward player_logic, actor_logic + y
} }
// ---------------------------------------------------------------- // ----------------------------------------------------------------
@ -433,33 +438,19 @@ define game_state_play game_state_routine
st x, save_x st x, save_x
// FIXME need VECTOR TABLEs to make this happen: copy actor_logic + x, dispatch_logic
// copy actor_logic, x dispatch_logic call dispatch_logic
// call indirect_jsr_logic
// For now, just check the actor ID to see what type it is, and go from there.
cmp x, 0
if z {
call player_logic
} else {
call enemy_logic
}
if c { if c {
// Player died! Want no dead! Break out of the loop (this is a bit awkward.) // Player died! Want no dead! Break out of the loop (this is a bit awkward.)
call clear_screen call clear_screen
copy forward game_state_game_over, dispatch_game_state copy forward game_state_game_over, dispatch_game_state
ld x, 15 ld x, 15
st x, save_x
trash n
trash z
trash x
} else { } else {
ld x, save_x
trash c trash c
} }
ld x, save_x
copy pos, actor_pos + x copy pos, actor_pos + x
copy delta, actor_delta + x copy delta, actor_delta + x

View File

@ -420,7 +420,7 @@ class Analyzer(object):
context.assert_meaningful(src, dest.ref, dest.index) context.assert_meaningful(src, dest.ref, dest.index)
context.set_written(dest.ref) context.set_written(dest.ref)
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef): elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
context.assert_meaningful(src.ref, src.index, dest) context.assert_meaningful(src.ref, src.index)
context.set_touched(dest) context.set_touched(dest)
context.set_written(dest) context.set_written(dest)
else: else:

View File

@ -410,7 +410,7 @@ class Compiler(object):
self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label))) self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
self.emitter.emit(LDA(Absolute(Offset(src_label, 1)))) self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(Offset(dest_label, 256)))) self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(Offset(dest_label, 256))))
elif isinstance(src.type, VectorType) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType): elif isinstance(src.type, (VectorType, RoutineType)) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType):
# FIXME this is the exact same as above - can this be simplified? # FIXME this is the exact same as above - can this be simplified?
src_label = self.labels[src.name] src_label = self.labels[src.name]
dest_label = self.labels[dest.ref.name] dest_label = self.labels[dest.ref.name]