junglejourney
changeset 120:67134c74700e
Attempted to improve performance by pre-calculating enemy positions
and reducing the number of times routines for motion and enemy
creation are called, but flicker and jerky motion is still a
problem.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Fri Sep 09 00:02:02 2011 +0200 |
| parents | 57fea6bcc814 |
| children | c9a57615aab5 |
| files | build.py mapcode.oph |
| diffstat | 2 files changed, 157 insertions(+), 128 deletions(-) [+] |
line diff
1.1 --- a/build.py Thu Sep 08 22:10:06 2011 +0200 1.2 +++ b/build.py Fri Sep 09 00:02:02 2011 +0200 1.3 @@ -47,6 +47,8 @@ 1.4 out_uef_file = sys.argv[1] 1.5 1.6 # Memory map 1.7 + # 0FE0 enemy x locations in the current room 1.8 + # 0FF0 enemy x locations in the current room 1.9 # 1000 completion screen 1.10 # 1780 title screen 1.11 # 1F00 CODE
2.1 --- a/mapcode.oph Thu Sep 08 22:10:06 2011 +0200 2.2 +++ b/mapcode.oph Fri Sep 09 00:02:02 2011 +0200 2.3 @@ -569,6 +569,101 @@ 2.4 clc 2.5 rts 2.6 2.7 +create_enemy_positions: 2.8 + 2.9 + lda #31 ; counter 2.10 + sta $7e 2.11 + 2.12 + lda #1 ; x 2.13 + sta $70 2.14 + 2.15 + lda #1 ; y 2.16 + sta $71 2.17 + 2.18 + lda #$a7 2.19 + sta $72 2.20 + lda #$57 2.21 + sta $73 2.22 + 2.23 + ldx #15 ; offset into position areas 2.24 + ldy #0 2.25 + 2.26 + create_enemy_positions_loop: 2.27 + 2.28 + jsr unlimited_values 2.29 + and #7 2.30 + sta $80 ; store temporarily 2.31 + 2.32 + lda $72 2.33 + adc $80 2.34 + sta $72 ; update the offset into the room data 2.35 + clc 2.36 + 2.37 + lda $70 2.38 + adc $80 ; update x 2.39 + cmp #10 2.40 + bpl create_enemy_positions_next_row 2.41 + 2.42 + sta $70 ; store x 2.43 + jmp create_enemy_positions_check_tile 2.44 + 2.45 + create_enemy_positions_next_row: 2.46 + 2.47 + sec 2.48 + sbc #10 2.49 + sta $70 ; store the x position on the next row 2.50 + clc 2.51 + 2.52 + lda $71 2.53 + adc #1 ; update the y position 2.54 + cmp #10 2.55 + bpl create_enemy_positions_to_top 2.56 + 2.57 + sta $71 ; store the y position for the next row 2.58 + jmp create_enemy_positions_check_tile 2.59 + 2.60 + create_enemy_positions_to_top: 2.61 + 2.62 + lda #1 ; reset the x, y and offset values 2.63 + sta $70 2.64 + sta $71 2.65 + lda #$a7 2.66 + sta $72 2.67 + 2.68 + create_enemy_positions_check_tile: 2.69 + 2.70 + lda ($72),y 2.71 + cmp #0 2.72 + bne create_enemy_positions_next 2.73 + 2.74 + lda $70 2.75 + sta $0fe0,x ; store the x value 2.76 + 2.77 + lda $71 2.78 + sta $0ff0,x ; store the y value 2.79 + 2.80 + dex 2.81 + bmi create_enemy_positions_exit 2.82 + 2.83 + create_enemy_positions_next: 2.84 + clc 2.85 + dec $7e 2.86 + bpl create_enemy_positions_loop 2.87 + 2.88 + ; The position areas were not filled. Write invalid values into the 2.89 + ; first area for the emerge routine to find. 2.90 + 2.91 + lda #0 2.92 + create_enemy_positions_fill_loop: 2.93 + 2.94 + sta $0fe0,x 2.95 + dex 2.96 + bpl create_enemy_positions_fill_loop 2.97 + 2.98 + create_enemy_positions_exit: 2.99 + clc 2.100 + rts 2.101 + 2.102 plot: ; $70,$71=source address 2.103 ; $72,$73=destination address 2.104 ldy #$1f 2.105 @@ -2149,103 +2244,23 @@ 2.106 clc 2.107 rts 2.108 2.109 -emerge_x_position: ; returns A=position 2.110 - 2.111 - jsr unlimited_values 2.112 - lda $5184 2.113 - jmp emerge_position_common 2.114 - 2.115 -emerge_y_position: ; returns A=position 2.116 - 2.117 - jsr unlimited_values 2.118 - lda $5182 2.119 - ; run on into the next routine 2.120 - 2.121 -emerge_position_common: 2.122 - 2.123 - cmp #3 2.124 - bpl emerge_position_common_not_first_area 2.125 - 2.126 - lda $7d 2.127 - and #7 2.128 - cmp #6 2.129 - bpl emerge_position_common_first_area_truncate 2.130 - 2.131 - adc #4 2.132 - rts 2.133 - 2.134 - emerge_position_common_first_area_truncate: 2.135 - clc 2.136 - lda #8 2.137 - rts 2.138 - 2.139 - emerge_position_common_not_first_area: 2.140 - cmp #7 2.141 - bpl emerge_position_common_third_area 2.142 - 2.143 - lda $7d 2.144 - cmp #5 2.145 - bmi emerge_position_common_lower_second_area 2.146 - 2.147 - clc 2.148 - lda $7d 2.149 - and #3 2.150 - adc #6 2.151 - rts 2.152 - 2.153 - emerge_position_common_lower_second_area: 2.154 - clc 2.155 - 2.156 - lda $7d 2.157 - and #3 2.158 - rts 2.159 - 2.160 - emerge_position_common_third_area: 2.161 - clc 2.162 - 2.163 - lda $7d 2.164 - and #7 2.165 - cmp #6 2.166 - bpl emerge_position_common_third_area_truncate 2.167 - 2.168 - rts 2.169 - 2.170 - emerge_position_common_third_area_truncate: 2.171 - clc 2.172 - lda #5 2.173 - rts 2.174 - 2.175 emerge_character: ; $74,$75=character address 2.176 2.177 lda #63 2.178 sta $3dff 2.179 2.180 - lda #3 ; try three tiles to find a space 2.181 - sta $81 2.182 - emerge_character_loop: 2.183 - 2.184 - jsr emerge_y_position ; obtain a y position 2.185 - tax 2.186 - jsr emerge_x_position ; obtain an x position 2.187 - sta $80 ; temporary 2.188 - tay 2.189 - 2.190 - lda room_row_offsets_low,x 2.191 - sta $70 2.192 - lda #$57 2.193 - sta $71 2.194 - lda ($70),y ; load the tile 2.195 - 2.196 - cmp #0 2.197 - beq emerge_character_space_found 2.198 - 2.199 - dec $81 2.200 - bpl emerge_character_loop 2.201 - 2.202 - bne emerge_character_exit 2.203 - 2.204 - emerge_character_space_found: 2.205 - ; There is a space in the room, so add an emerging enemy. 2.206 + jsr unlimited_values 2.207 + and #$0f 2.208 + tax 2.209 + lda $0fe0,x 2.210 + cmp #0 ; check for an invalid value and exit if found 2.211 + beq emerge_character_exit 2.212 + 2.213 + sta $80 ; temporary 2.214 + lda $0ff0,x 2.215 + tax 2.216 + 2.217 + ; Add an emerging enemy. 2.218 2.219 ldy #0 2.220 lda #3 2.221 @@ -3379,47 +3394,52 @@ 2.222 clc 2.223 rts 2.224 2.225 -move_characters: 2.226 +emerge_characters: 2.227 2.228 lda #$8c ; set the character address 2.229 sta $74 2.230 lda #$51 2.231 sta $75 2.232 2.233 - move_characters_loop: 2.234 + emerge_characters_loop: 2.235 2.236 ldy #0 2.237 lda ($74),y 2.238 cmp #0 2.239 - bne move_characters_read_character 2.240 - 2.241 + bne emerge_characters_next 2.242 + 2.243 + jmp emerge_character ; optimise away the rts 2.244 + 2.245 + emerge_characters_next: 2.246 + clc 2.247 + 2.248 + ; Examine the next character. 2.249 lda $74 2.250 + adc #6 2.251 + 2.252 cmp #$a4 2.253 - bpl move_characters_read_character 2.254 - 2.255 - ; See if it is time to generate a new enemy. 2.256 - lda $3dff 2.257 - cmp #0 2.258 - bne move_characters_next 2.259 - 2.260 - lda $3df0 ; player demise - no more enemies 2.261 - and #$40 2.262 - bne move_characters_next 2.263 - 2.264 - jsr emerge_character 2.265 - jmp move_characters_next 2.266 - 2.267 - move_characters_read_character: 2.268 - clc 2.269 - 2.270 - move_characters_not_projectile: 2.271 + bpl emerge_characters_exit 2.272 + sta $74 2.273 + jmp emerge_characters_loop 2.274 + 2.275 + emerge_characters_exit: 2.276 + clc 2.277 + rts 2.278 + 2.279 +move_characters: 2.280 + 2.281 + lda #$8c ; set the character address 2.282 + sta $74 2.283 + lda #$51 2.284 + sta $75 2.285 + 2.286 + move_characters_loop: 2.287 + 2.288 + ldy #0 2.289 + lda ($74),y 2.290 cmp #3 2.291 bne move_characters_not_emerge_explode 2.292 2.293 - lda $3dfe ; check motion counter 2.294 - and #3 2.295 - bne move_characters_next 2.296 - 2.297 jsr emerge_explode 2.298 jmp move_characters_next 2.299 2.300 @@ -3427,14 +3447,6 @@ 2.301 cmp #8 2.302 bmi move_characters_next 2.303 2.304 - lda $3dfe ; check motion counter 2.305 - and #3 2.306 - bne move_characters_next 2.307 - 2.308 - lda $3df0 ; player demise - no enemy motion 2.309 - and #$40 2.310 - bne move_characters_next 2.311 - 2.312 jsr move_enemy 2.313 2.314 move_characters_next: 2.315 @@ -5299,6 +5311,7 @@ 2.316 sta $79 2.317 jsr plot_room 2.318 jsr set_room_palette 2.319 + jsr create_enemy_positions 2.320 jsr add_treasure 2.321 2.322 jsr plot_the_player 2.323 @@ -5316,8 +5329,6 @@ 2.324 jsr reset_unplot_buffer 2.325 jsr reset_plot_buffer 2.326 2.327 - jsr move_characters 2.328 - 2.329 jsr move_projectile 2.330 2.331 lda $3df0 ; is player out of strength? 2.332 @@ -5350,6 +5361,22 @@ 2.333 2.334 room_loop_player_move: 2.335 2.336 + ; See if it is time to generate a new enemy. 2.337 + lda $3dff 2.338 + cmp #0 2.339 + bne no_emerge_characters 2.340 + jsr emerge_characters 2.341 + 2.342 + no_emerge_characters: 2.343 + 2.344 + lda $3dfe ; check motion counter 2.345 + and #3 2.346 + bne no_move_characters 2.347 + jsr move_characters 2.348 + 2.349 + no_move_characters: 2.350 + clc 2.351 + 2.352 jsr check_fire_key 2.353 jsr move_player 2.354 bcs after_room_loop ; check if we are leaving the level
