git @ Cat's Eye Technologies SixtyPical / 43b3a08
Use a vector table in the demo game. Chris Pressey 3 years ago
3 changed file(s) with 16 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
3131
3232 typedef routine
3333 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
34 actor_pos, pos, new_pos, actor_delta, delta,
34 actor_pos, pos, new_pos, actor_delta, delta, actor_logic,
3535 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
3636 outputs button_down, dispatch_game_state,
37 actor_pos, pos, new_pos, actor_delta, delta,
37 actor_pos, pos, new_pos, actor_delta, delta, actor_logic,
3838 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
39 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
39 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target, dispatch_logic
4040 game_state_routine
4141
4242 //
8585
8686 word table[256] actor_delta
8787 word delta
88
89 vector (logic_routine) table[256] actor_logic
90 vector logic_routine dispatch_logic
8891
8992 byte button_down : 0 // effectively static-local to check_button
9093 byte table[32] press_fire_msg: "PRESS`FIRE`TO`PLAY"
238241 }
239242
240243 routine init_game
241 inputs actor_pos, actor_delta
242 outputs actor_pos, actor_delta, pos
244 inputs actor_pos, actor_delta, actor_logic
245 outputs actor_pos, actor_delta, pos, actor_logic
243246 trashes a, y, z, n, c, v
244247 {
245248 ld y, 0
247250 repeat {
248251 copy pos, actor_pos + y
249252 copy word 40, actor_delta + y
253 copy forward enemy_logic, actor_logic + y
250254
251255 st off, c
252256 add pos, word 7
258262 ld y, 0
259263 copy word 0, actor_pos + y
260264 copy word 0, actor_delta + y
265 copy forward player_logic, actor_logic + y
261266 }
262267
263268 // ----------------------------------------------------------------
432437
433438 st x, save_x
434439
435 // FIXME need VECTOR TABLEs to make this happen:
436 // copy actor_logic, x dispatch_logic
437 // call indirect_jsr_logic
438 // For now, just check the actor ID to see what type it is, and go from there.
439
440 cmp x, 0
441 if z {
442 call player_logic
443 } else {
444 call enemy_logic
445 }
440 copy actor_logic + x, dispatch_logic
441 call dispatch_logic
446442
447443 if c {
448444 // Player died! Want no dead! Break out of the loop (this is a bit awkward.)
449445 call clear_screen
450446 copy forward game_state_game_over, dispatch_game_state
451447 ld x, 15
452 st x, save_x
453 trash n
454 trash z
455 trash x
456 } else {
448 } else {
449 ld x, save_x
457450 trash c
458451 }
459
460 ld x, save_x
461452
462453 copy pos, actor_pos + x
463454 copy delta, actor_delta + x
419419 context.assert_meaningful(src, dest.ref, dest.index)
420420 context.set_written(dest.ref)
421421 elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
422 context.assert_meaningful(src.ref, src.index, dest)
422 context.assert_meaningful(src.ref, src.index)
423423 context.set_touched(dest)
424424 context.set_written(dest)
425425 else:
409409 self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
410410 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
411411 self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(Offset(dest_label, 256))))
412 elif isinstance(src.type, VectorType) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType):
412 elif isinstance(src.type, (VectorType, RoutineType)) and isinstance(dest.ref.type, TableType) and isinstance(dest.ref.type.of_type, VectorType):
413413 # FIXME this is the exact same as above - can this be simplified?
414414 src_label = self.labels[src.name]
415415 dest_label = self.labels[dest.ref.name]