Work on game a bit. Multiple actors.
Cat's Eye Technologies
8 years ago
27 | 27 | |
28 | 28 | reserve byte[16] actor_pos_hi |
29 | 29 | reserve byte[16] actor_pos_lo |
30 | ||
31 | reserve vector dispatch_state | |
32 | ||
33 | reserve byte[18] press_fire_msg: "PRESS FIRE TO PLAY" | |
34 | ||
35 | reserve byte save_x // TODO: SHOULD BE BLOCK LOCAL! | |
30 | 36 | |
31 | 37 | routine calculate_new_position outputs (new_position) { |
32 | 38 | clc |
124 | 130 | } |
125 | 131 | } |
126 | 132 | |
133 | // output is .z flag | |
134 | routine check_fire { | |
135 | ldx joy2 | |
136 | txa | |
137 | and #16 | |
138 | } | |
139 | ||
140 | routine init_game { | |
141 | ldy #0 | |
142 | repeat bne { | |
143 | lda #$04 | |
144 | sta actor_pos_hi, y | |
145 | tya | |
146 | sta actor_pos_lo, y | |
147 | iny | |
148 | cpy #8 | |
149 | } | |
150 | } | |
151 | ||
152 | routine state_title_screen { | |
153 | ldy #0 | |
154 | repeat bne { | |
155 | lda press_fire_msg, y | |
156 | sec | |
157 | sbc #64 // yuck | |
158 | sta screen, y | |
159 | iny | |
160 | cpy #18 | |
161 | } | |
162 | jsr check_fire | |
163 | if beq { | |
164 | jsr clear_screen | |
165 | jsr init_game | |
166 | copy routine state_play_game to dispatch_state | |
167 | } else { } | |
168 | jmp (save_cinv) | |
169 | } | |
170 | ||
171 | routine state_play_game { | |
172 | // reserve byte save_x | |
173 | ldx #0 | |
174 | repeat bne { | |
175 | stx save_x | |
176 | ||
177 | lda actor_pos_hi, x | |
178 | sta >position | |
179 | lda actor_pos_lo, x | |
180 | sta <position | |
181 | ||
182 | jsr read_stick | |
183 | jsr calculate_new_position | |
184 | jsr check_new_position_in_bounds | |
185 | if bcs { | |
186 | lda #32 | |
187 | ldy #0 | |
188 | sta (position), y | |
189 | copy new_position position | |
190 | lda #81 | |
191 | ldy #0 | |
192 | sta (position), y | |
193 | } else { } | |
194 | ||
195 | ldx save_x | |
196 | lda >position | |
197 | sta actor_pos_hi, x | |
198 | lda <position | |
199 | sta actor_pos_lo, x | |
200 | inx | |
201 | cpx #8 | |
202 | } | |
203 | jmp (save_cinv) | |
204 | } | |
205 | ||
127 | 206 | routine our_cinv { |
128 | ldy #0 | |
129 | lda actor_pos_hi, y | |
130 | sta >position | |
131 | lda actor_pos_lo, y | |
132 | sta <position | |
133 | ||
134 | jsr read_stick | |
135 | jsr calculate_new_position | |
136 | jsr check_new_position_in_bounds | |
137 | if bcs { | |
138 | lda #32 | |
139 | ldy #0 | |
140 | sta (position), y | |
141 | copy new_position position | |
142 | lda #81 | |
143 | ldy #0 | |
144 | sta (position), y | |
145 | } else { } | |
146 | ||
147 | ldy #0 | |
148 | lda >position | |
149 | sta actor_pos_hi, y | |
150 | lda <position | |
151 | sta actor_pos_lo, y | |
152 | ||
153 | jmp (save_cinv) | |
207 | jmp (dispatch_state) | |
154 | 208 | } |
155 | 209 | |
156 | 210 | routine main { |
158 | 212 | sta vic_border |
159 | 213 | lda #0 |
160 | 214 | sta vic_bg |
161 | // copy #$0400 position | |
162 | ||
163 | ldy #0 | |
164 | lda #$04 | |
165 | sta actor_pos_hi, y | |
166 | lda #$00 | |
167 | sta actor_pos_lo, y | |
168 | 215 | |
169 | 216 | jsr clear_screen |
217 | copy routine state_title_screen to dispatch_state | |
218 | ||
170 | 219 | with sei { |
171 | 220 | copy cinv save_cinv |
172 | 221 | copy routine our_cinv to cinv |