git @ Cat's Eye Technologies SixtyPical / f78460a
Finally, use typedefs in example game. Chris Pressey 4 years ago
1 changed file(s) with 79 addition(s) and 100 deletion(s). Raw diff Collapse all Expand all
22 // ****************************
33
44 // ----------------------------------------------------------------
5 // System Locations
6 // ----------------------------------------------------------------
7
8 byte vic_border @ 53280
9 byte vic_bg @ 53281
10
11 table[256] byte screen1 @ 1024
12 table[256] byte screen2 @ 1274
13 table[256] byte screen3 @ 1524
14 table[256] byte screen4 @ 1774
15
16 table[256] byte colormap1 @ 55296
17 table[256] byte colormap2 @ 55546
18 table[256] byte colormap3 @ 55796
19 table[256] byte colormap4 @ 56046
20
21 buffer[2048] screen @ 1024
22 byte joy2 @ $dc00
23
24 // ----------------------------------------------------------------
25 // Global Variables
26 // ----------------------------------------------------------------
27
28 pointer ptr @ 254
29
30 table[256] word actor_pos
31 word pos
32 word new_pos
33
34 table[256] word actor_delta
35 word delta
36
37 byte button_down : 0 // effectively static-local to check_button
38 table[32] byte press_fire_msg: "PRESS`FIRE`TO`PLAY"
39
40 byte save_x
41 word compare_target
42
43 //
44 // Points to the routine that implements the current game state.
5 // Type Definitions
6 // ----------------------------------------------------------------
7
8 //
9 // Type of routines (and vectors to those routines) which are called on each frame
10 // to implement a certain state of the game (title screen, in play, game over, etc.)
11 //
12 // This type is also used as the type for the interrupt vector, even though
13 // the interrupt routine saves and restores everything before being called and
14 // thus clearly does not actually trash all the registers. It is declared this
15 // way so that the game state routines, which do trash these registers, can be
16 // assigned to it.
17 //
18 // This type is also used as the type for the location the old interrupt vector
19 // is backed up to, because all the game state routines "goto" the old handler
20 // and the end of their own routines, so the type needs to be compatible.
21 // (In a good sense, it is a continuation.)
22 //
23 // Further,
4524 //
4625 // It's very arguable that screen1/2/3/4 and colormap1/2/3/4 are not REALLY inputs.
4726 // They're only there to support the fact that game states sometimes clear the
5029 // and output. There is probably a better way to do this, but it needs thought.
5130 //
5231
53 vector routine
32 typedef routine
5433 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
5534 actor_pos, pos, new_pos, actor_delta, delta,
5635 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
5837 actor_pos, pos, new_pos, actor_delta, delta,
5938 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
6039 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
40 game_state_routine
41
42 // ----------------------------------------------------------------
43 // System Locations
44 // ----------------------------------------------------------------
45
46 byte vic_border @ 53280
47 byte vic_bg @ 53281
48
49 table[256] byte screen1 @ 1024
50 table[256] byte screen2 @ 1274
51 table[256] byte screen3 @ 1524
52 table[256] byte screen4 @ 1774
53
54 table[256] byte colormap1 @ 55296
55 table[256] byte colormap2 @ 55546
56 table[256] byte colormap3 @ 55796
57 table[256] byte colormap4 @ 56046
58
59 buffer[2048] screen @ 1024
60 byte joy2 @ $dc00
61
62 // ----------------------------------------------------------------
63 // Global Variables
64 // ----------------------------------------------------------------
65
66 pointer ptr @ 254
67
68 table[256] word actor_pos
69 word pos
70 word new_pos
71
72 table[256] word actor_delta
73 word delta
74
75 byte button_down : 0 // effectively static-local to check_button
76 table[32] byte press_fire_msg: "PRESS`FIRE`TO`PLAY"
77
78 byte save_x
79 word compare_target
80
81 //
82 // Points to the routine that implements the current game state.
83 //
84
85 vector game_state_routine
6186 dispatch_game_state
6287
6388 //
64 // The constraints on these 2 vectors are kind-of sort-of big fibs.
65 // They're only written this way so they can be compatible with our
66 // routine. In fact, CINV is an interrupt routine where it doesn't
67 // really matter what you trash anyway, because all registers were
68 /// saved by the caller (the KERNAL) and will be restored by the end
69 // of the code of the saved origin cinv routine that we goto.
70 //
71 // I wonder if this could be arranged somehow to be less fibby, in
72 // a future version of SixtyPical.
73 //
74
75 vector routine
76 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
77 actor_pos, pos, new_pos, actor_delta, delta,
78 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
79 outputs button_down, dispatch_game_state,
80 actor_pos, pos, new_pos, actor_delta, delta,
81 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
82 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
89 // Interrupt vector. Has same type as game states (see above.)
90 //
91
92 vector game_state_routine
8393 cinv @ 788
8494
85 vector routine
86 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
87 actor_pos, pos, new_pos, actor_delta, delta,
88 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
89 outputs button_down, dispatch_game_state,
90 actor_pos, pos, new_pos, actor_delta, delta,
91 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
92 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
95 //
96 // Location to which the old interrupt vector is saved before replacement.
97 //
98
99 vector game_state_routine
93100 save_cinv
94101
95102 // ----------------------------------------------------------------
382389 // Because these all `goto save_cinv` at the end, they must have the same signature as that routine.
383390 //
384391
385 routine game_state_title_screen
386 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
387 actor_pos, pos, new_pos, actor_delta, delta,
388 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
389 outputs button_down, dispatch_game_state,
390 actor_pos, pos, new_pos, actor_delta, delta,
391 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
392 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
392 define game_state_title_screen game_state_routine
393393 {
394394 ld y, 0
395395 repeat {
427427 goto save_cinv
428428 }
429429
430 routine game_state_play
431 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
432 actor_pos, pos, new_pos, actor_delta, delta,
433 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
434 outputs button_down, dispatch_game_state,
435 actor_pos, pos, new_pos, actor_delta, delta,
436 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
437 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
430 define game_state_play game_state_routine
438431 {
439432 ld x, 0
440433 repeat {
480473 goto save_cinv
481474 }
482475
483 routine game_state_game_over
484 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
485 actor_pos, pos, new_pos, actor_delta, delta,
486 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
487 outputs button_down, dispatch_game_state,
488 actor_pos, pos, new_pos, actor_delta, delta,
489 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
490 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
476 define game_state_game_over game_state_routine
491477 {
492478 st off, c
493479 call check_button
517503 // * Main Game Loop Driver *
518504 // *************************
519505
520 routine our_cinv
521 inputs joy2, button_down, press_fire_msg, dispatch_game_state, save_x,
522 actor_pos, pos, new_pos, actor_delta, delta,
523 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
524 outputs button_down, dispatch_game_state,
525 actor_pos, pos, new_pos, actor_delta, delta,
526 screen, screen1, screen2, screen3, screen4, colormap1, colormap2, colormap3, colormap4
527 trashes a, x, y, c, z, n, v, ptr, save_x, compare_target
506 define our_cinv game_state_routine
528507 {
529508 goto dispatch_game_state
530509 }