junglejourney
changeset 33:5414e8e0e9fe
Ensured that the lists of sprites to unplot and plot are only
populated with those that have moved.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Aug 21 01:24:55 2011 +0200 |
| parents | a0d2f1c1ecdd |
| children | 125080c5c19b |
| files | mapcode.oph |
| diffstat | 1 files changed, 355 insertions(+), 378 deletions(-) [+] |
line diff
1.1 --- a/mapcode.oph Sat Aug 20 23:22:01 2011 +0200 1.2 +++ b/mapcode.oph Sun Aug 21 01:24:55 2011 +0200 1.3 @@ -1032,246 +1032,233 @@ 1.4 emerge_explode_chars_low: .byte $00,$40,$80,$c0,$00,$40,$80,$c0 1.5 emerge_explode_chars_high: .byte $41,$41,$41,$41,$42,$42,$42,$42 1.6 1.7 -plot_characters: 1.8 +unplot_character: ; $74,$75=character address 1.9 1.10 - lda #$00 1.11 - sta $74 1.12 - lda #$33 1.13 - sta $75 1.14 + lda $82 1.15 + sta $78 1.16 + lda $83 1.17 + sta $79 1.18 + jsr plot_character_sprite 1.19 + lda $78 1.20 + sta $82 1.21 + rts 1.22 1.23 - plot_characters_loop: 1.24 +plot_character: ; $74,$75=character address 1.25 1.26 - ldy #0 1.27 - lda ($74),y 1.28 - cmp #0 1.29 - bne plot_characters_read_character 1.30 - jmp plot_characters_next 1.31 + lda $84 1.32 + sta $78 1.33 + lda $85 1.34 + sta $79 1.35 + jsr plot_character_sprite 1.36 + lda $78 1.37 + sta $84 1.38 + rts 1.39 1.40 - plot_characters_read_character: 1.41 - clc 1.42 +plot_character_sprite: ; $74,$75=character address 1.43 + ; $78,$79=plot buffer address 1.44 1.45 - sta $77 ; temporarily store the object type 1.46 + ldy #0 1.47 + lda ($74),y 1.48 + cmp #0 1.49 + bne plot_characters_read_character 1.50 + jmp plot_characters_next 1.51 1.52 - ; Use lookup tables to load the offsets into the sprite. 1.53 + plot_characters_read_character: 1.54 + clc 1.55 1.56 - ; Direction 1.57 - iny 1.58 - lda ($74),y 1.59 - sta $80 ; temporarily store the direction 1.60 + sta $77 ; temporarily store the object type 1.61 1.62 - ; y 1.63 - iny 1.64 - lda ($74),y 1.65 - tax 1.66 - lda screen_rows_low,x 1.67 - sta $72 1.68 - lda screen_rows_high,x 1.69 - sta $73 1.70 - clc 1.71 + ; Use lookup tables to load the offsets into the sprite. 1.72 1.73 - ; dy 1.74 - iny 1.75 - lda ($74),y 1.76 - sta $76 1.77 - tax 1.78 - lda screen_subrows_low,x 1.79 - adc $72 1.80 - sta $72 1.81 - lda screen_subrows_high,x 1.82 - adc $73 1.83 - sta $73 1.84 - clc 1.85 + ; Direction 1.86 + iny 1.87 + lda ($74),y 1.88 + sta $80 ; temporarily store the direction 1.89 1.90 - ; x 1.91 - iny 1.92 - lda ($74),y 1.93 - tax 1.94 - lda screen_columns_low,x 1.95 - adc $72 1.96 - sta $72 1.97 - lda screen_columns_high,x 1.98 - adc $73 1.99 - sta $73 1.100 - clc 1.101 + ; y 1.102 + iny 1.103 + lda ($74),y 1.104 + tax 1.105 + lda screen_rows_low,x 1.106 + sta $72 1.107 + lda screen_rows_high,x 1.108 + sta $73 1.109 + clc 1.110 1.111 - ; dx 1.112 - iny 1.113 - lda ($74),y 1.114 - tax 1.115 - lda screen_subcolumns_low,x 1.116 - adc $72 1.117 - sta $72 1.118 - clc 1.119 + ; dy 1.120 + iny 1.121 + lda ($74),y 1.122 + sta $76 1.123 + tax 1.124 + lda screen_subrows_low,x 1.125 + adc $72 1.126 + sta $72 1.127 + lda screen_subrows_high,x 1.128 + adc $73 1.129 + sta $73 1.130 + clc 1.131 1.132 - lda $77 1.133 - cmp #1 1.134 - bne plot_characters_loop_not_player 1.135 - 1.136 - ; Plot 8x24 sprites (player) 1.137 + ; x 1.138 + iny 1.139 + lda ($74),y 1.140 + tax 1.141 + lda screen_columns_low,x 1.142 + adc $72 1.143 + sta $72 1.144 + lda screen_columns_high,x 1.145 + adc $73 1.146 + sta $73 1.147 + clc 1.148 1.149 - ldx $80 1.150 - lda player_direction_chars_low,x 1.151 - sta $70 1.152 - lda player_direction_chars_high,x 1.153 - sta $71 1.154 + ; dx 1.155 + iny 1.156 + lda ($74),y 1.157 + tax 1.158 + lda screen_subcolumns_low,x 1.159 + adc $72 1.160 + sta $72 1.161 + clc 1.162 1.163 - ; Use the dy value to determine which plotting routine to use. 1.164 + lda $77 1.165 + cmp #1 1.166 + bne plot_characters_loop_not_player 1.167 1.168 - ldy #0 1.169 - lda $76 1.170 - and #1 1.171 - bne plot_characters_plot_8x24_1 1.172 + ; Plot 8x24 sprites (player) 1.173 1.174 - lda #<plot8x24_y0 1.175 - sta ($84),y 1.176 - iny 1.177 - lda #>plot8x24_y0 1.178 - sta ($84),y 1.179 - jmp plot_characters_stored 1.180 + ldx $80 1.181 + lda player_direction_chars_low,x 1.182 + sta $70 1.183 + lda player_direction_chars_high,x 1.184 + sta $71 1.185 1.186 - plot_characters_plot_8x24_1: 1.187 - clc 1.188 - lda #<plot8x24_y1 1.189 - sta ($84),y 1.190 - iny 1.191 - lda #>plot8x24_y1 1.192 - sta ($84),y 1.193 - jmp plot_characters_stored 1.194 + ; Use the dy value to determine which plotting routine to use. 1.195 1.196 + ldy #0 1.197 + lda $76 1.198 + and #1 1.199 + bne plot_characters_plot_8x24_1 1.200 1.201 - plot_characters_loop_not_player: 1.202 - cmp #2 1.203 - bne plot_characters_loop_not_projectile 1.204 + lda #1 1.205 + sta ($78),y 1.206 + jmp plot_characters_stored 1.207 1.208 - ; Plot 8x8 sprites (projectiles) 1.209 + plot_characters_plot_8x24_1: 1.210 + clc 1.211 + lda #2 1.212 + sta ($78),y 1.213 + jmp plot_characters_stored 1.214 1.215 - ; Use the dy value to determine which plotting routine to use. 1.216 1.217 - ldy #0 1.218 - lda $76 1.219 - and #1 1.220 - bne plot_characters_plot_8x8_1 1.221 + plot_characters_loop_not_player: 1.222 + cmp #2 1.223 + bne plot_characters_loop_not_projectile 1.224 1.225 - lda #<plot8x8_y0 1.226 - sta ($84),y 1.227 - iny 1.228 - lda #>plot8x8_y0 1.229 - sta ($84),y 1.230 - jmp plot_characters_stored 1.231 + ; Plot 8x8 sprites (projectiles) 1.232 1.233 - plot_characters_plot_8x8_1: 1.234 - clc 1.235 - lda #<plot8x8_y1 1.236 - sta ($84),y 1.237 - iny 1.238 - lda #>plot8x8_y1 1.239 - sta ($84),y 1.240 - jmp plot_characters_stored 1.241 + ; Use the dy value to determine which plotting routine to use. 1.242 1.243 + ldy #0 1.244 + lda $76 1.245 + and #1 1.246 + bne plot_characters_plot_8x8_1 1.247 1.248 - plot_characters_loop_not_projectile: 1.249 - cmp #3 1.250 - bne plot_characters_loop_not_explosion 1.251 + lda #3 1.252 + sta ($78),y 1.253 + jmp plot_characters_stored 1.254 1.255 - ; Plot 16x16 sprites (emerging, explosions) 1.256 + plot_characters_plot_8x8_1: 1.257 + clc 1.258 + lda #4 1.259 + sta ($78),y 1.260 + jmp plot_characters_stored 1.261 1.262 - ; Select the sprites to use. 1.263 1.264 - lda $80 ; remove the least significant bit, used to delay 1.265 - lsr ; the animation 1.266 - and #7 ; only keep the bits required to find the correct sprite 1.267 - tax 1.268 - lda emerge_explode_chars_low,x 1.269 - sta $70 1.270 - lda emerge_explode_chars_high,x 1.271 - sta $71 1.272 + plot_characters_loop_not_projectile: 1.273 + cmp #3 1.274 + bne plot_characters_loop_not_explosion 1.275 1.276 - jmp plot_characters_16x16 1.277 + ; Plot 16x16 sprites (emerging, explosions) 1.278 1.279 - plot_characters_loop_not_explosion: 1.280 - cmp #4 1.281 - bmi plot_characters_loop_not_enemy 1.282 + ; Select the sprites to use. 1.283 1.284 - ; Plot 16x16 sprites (enemies) 1.285 + lda $80 ; remove the least significant bit, used to delay 1.286 + lsr ; the animation 1.287 + and #7 ; only keep the bits required to find the correct sprite 1.288 + tax 1.289 + lda emerge_explode_chars_low,x 1.290 + sta $70 1.291 + lda emerge_explode_chars_high,x 1.292 + sta $71 1.293 1.294 - ; Select the set of sprites to use. 1.295 + jmp plot_characters_16x16 1.296 1.297 - and #$38 1.298 - lsr 1.299 - lsr ; bits 3,4,5 >> 2 -> bits 1,2,3 1.300 - clc 1.301 - sta $71 ; 0x00, 0x02, 0x04, 0x06, 0x08 1.302 + plot_characters_loop_not_explosion: 1.303 + cmp #4 1.304 + bmi plot_characters_loop_not_enemy 1.305 1.306 - ldx $80 1.307 - lda enemy_direction_chars_low,x 1.308 - sta $70 1.309 - lda enemy_direction_chars_high,x 1.310 - adc $71 1.311 - sta $71 1.312 + ; Plot 16x16 sprites (enemies) 1.313 1.314 - plot_characters_16x16: 1.315 + ; Select the set of sprites to use. 1.316 1.317 - ; Use the dy value to determine which plotting routine to use. 1.318 + and #$38 1.319 + lsr 1.320 + lsr ; bits 3,4,5 >> 2 -> bits 1,2,3 1.321 + clc 1.322 + sta $71 ; 0x00, 0x02, 0x04, 0x06, 0x08 1.323 1.324 - ldy #0 1.325 - lda $76 1.326 - and #1 1.327 - bne plot_characters_plot_16x16_1 1.328 + ldx $80 1.329 + lda enemy_direction_chars_low,x 1.330 + sta $70 1.331 + lda enemy_direction_chars_high,x 1.332 + adc $71 1.333 + sta $71 1.334 1.335 - lda #<plot16x16_y0 1.336 - sta ($84),y 1.337 - iny 1.338 - lda #>plot16x16_y0 1.339 - sta ($84),y 1.340 - jmp plot_characters_stored 1.341 + plot_characters_16x16: 1.342 1.343 - plot_characters_plot_16x16_1: 1.344 - clc 1.345 - lda #<plot16x16_y1 1.346 - sta ($84),y 1.347 - iny 1.348 - lda #>plot16x16_y1 1.349 - sta ($84),y 1.350 + ; Use the dy value to determine which plotting routine to use. 1.351 1.352 + ldy #0 1.353 + lda $76 1.354 + and #1 1.355 + bne plot_characters_plot_16x16_1 1.356 1.357 - plot_characters_stored: 1.358 + lda #5 1.359 + sta ($78),y 1.360 + jmp plot_characters_stored 1.361 1.362 - iny 1.363 - lda $70 1.364 - sta ($84),y 1.365 - iny 1.366 - lda $71 1.367 - sta ($84),y 1.368 - iny 1.369 - lda $72 1.370 - sta ($84),y 1.371 - iny 1.372 - lda $73 1.373 - sta ($84),y 1.374 + plot_characters_plot_16x16_1: 1.375 + clc 1.376 + lda #6 1.377 + sta ($78),y 1.378 1.379 - clc 1.380 - lda $84 1.381 - adc #12 1.382 - sta $84 1.383 1.384 - plot_characters_loop_not_enemy: 1.385 + plot_characters_stored: 1.386 1.387 - plot_characters_next: 1.388 - clc 1.389 + iny 1.390 + lda $70 1.391 + sta ($78),y 1.392 + iny 1.393 + lda $71 1.394 + sta ($78),y 1.395 + iny 1.396 + lda $72 1.397 + sta ($78),y 1.398 + iny 1.399 + lda $73 1.400 + sta ($78),y 1.401 1.402 - ; Examine the next character. 1.403 - lda $74 1.404 - adc #6 1.405 + clc 1.406 + lda $78 1.407 + adc #12 1.408 + sta $78 1.409 1.410 - cmp #$24 1.411 - bpl plot_characters_exit 1.412 - sta $74 1.413 - jmp plot_characters_loop 1.414 + plot_characters_loop_not_enemy: 1.415 1.416 - plot_characters_exit: 1.417 - lda #255 1.418 + plot_characters_next: 1.419 + 1.420 + lda #255 ; terminate this stream of entries in the plot buffer 1.421 ldy #0 1.422 - sta ($84),y 1.423 + sta ($78),y 1.424 clc 1.425 rts 1.426 1.427 @@ -1280,15 +1267,26 @@ 1.428 sta $84 1.429 lda #$47 1.430 sta $85 1.431 + 1.432 + lda #255 ; terminate the plot list 1.433 + ldy #0 1.434 + sta ($84),y 1.435 rts 1.436 1.437 reset_unplot_buffer: 1.438 lda #$00 ; reset the index into the plot buffer 1.439 - sta $84 1.440 + sta $82 1.441 lda #$47 1.442 - sta $85 1.443 + sta $83 1.444 + 1.445 + lda #255 ; terminate the unplot list 1.446 + ldy #0 1.447 + sta ($82),y 1.448 rts 1.449 1.450 +plot_buffer_types_low: .byte <plot_buffer_loop_next, <plot8x24_y0, <plot8x24_y1, <plot8x8_y0, <plot8x8_y1, <plot16x16_y0, <plot16x16_y1 1.451 +plot_buffer_types_high: .byte >plot_buffer_loop_next, >plot8x24_y0, >plot8x24_y1, >plot8x8_y0, >plot8x8_y1, >plot16x16_y0, >plot16x16_y1 1.452 + 1.453 plot_buffer: 1.454 1.455 lda #$00 1.456 @@ -1307,10 +1305,10 @@ 1.457 beq plot_buffer_loop_skip 1.458 1.459 clc 1.460 + tax 1.461 + lda plot_buffer_types_low,x 1.462 sta $86 1.463 - 1.464 - iny 1.465 - lda ($84),y 1.466 + lda plot_buffer_types_high,x 1.467 sta $87 1.468 1.469 iny 1.470 @@ -1366,6 +1364,8 @@ 1.471 and #1 1.472 eor #1 ; toggle animation flag 1.473 sta $3301 ; left (directional bits are 0) 1.474 + 1.475 + jsr plot_character 1.476 rts 1.477 1.478 animate_player_right: 1.479 @@ -1377,6 +1377,8 @@ 1.480 eor #1 ; toggle animation flag 1.481 ora #2 ; right 1.482 sta $3301 1.483 + 1.484 + jsr plot_character 1.485 rts 1.486 1.487 animate_player_up: 1.488 @@ -1388,6 +1390,8 @@ 1.489 eor #1 ; toggle animation flag 1.490 ora #4 ; up 1.491 sta $3301 1.492 + 1.493 + jsr plot_character 1.494 rts 1.495 1.496 animate_player_down: 1.497 @@ -1399,10 +1403,17 @@ 1.498 eor #1 ; toggle animation flag 1.499 ora #6 ; down 1.500 sta $3301 1.501 + 1.502 + jsr plot_character 1.503 rts 1.504 1.505 move_player: 1.506 1.507 + lda #$00 ; set up the address of the player character 1.508 + sta $74 1.509 + lda #$33 1.510 + sta $75 1.511 + 1.512 ; Handle the left key. 1.513 1.514 ldx #158 ; (Z) 1.515 @@ -1414,6 +1425,7 @@ 1.516 cmp #0 1.517 beq move_player_left_check_x 1.518 1.519 + jsr unplot_character ; unplot the player character 1.520 dec $3305 1.521 clc 1.522 jmp animate_player_left ; optimise away the rts 1.523 @@ -1453,6 +1465,9 @@ 1.524 1.525 move_player_allow_left: 1.526 tya 1.527 + sta $81 ; temporary 1.528 + jsr unplot_character ; unplot the player character 1.529 + lda $81 1.530 sta $3304 ; store the new room x offset 1.531 lda #3 1.532 sta $3305 ; dx = 3 1.533 @@ -1467,14 +1482,17 @@ 1.534 clc 1.535 1.536 ; Set the player's position on the right of the screen. 1.537 + 1.538 + ; No need to unplot. 1.539 1.540 lda #9 ; x = 9 1.541 sta $3304 1.542 lda #2 ; dx = 2 1.543 sta $3305 1.544 1.545 + jsr animate_player_left 1.546 sec ; indicate to the calling routine that the player 1.547 - jmp animate_player_left ; has left the room (optimising away the rts) 1.548 + rts ; has left the room 1.549 1.550 move_player_not_left_key: 1.551 1.552 @@ -1491,6 +1509,7 @@ 1.553 cmp #3 1.554 beq move_player_right_tile 1.555 1.556 + jsr unplot_character ; unplot the player character 1.557 inc $3305 1.558 clc 1.559 jmp animate_player_right ; optimise away the rts 1.560 @@ -1530,12 +1549,14 @@ 1.561 1.562 move_player_allow_right: 1.563 1.564 + jsr unplot_character ; unplot the player character 1.565 inc $3305 ; update dx 1.566 clc 1.567 jmp animate_player_right ; optimise away the rts 1.568 1.569 move_player_right_tile: 1.570 1.571 + jsr unplot_character ; unplot the player character 1.572 inc $3304 ; store the new room x offset 1.573 lda #0 1.574 sta $3305 ; dx = 0 1.575 @@ -1551,14 +1572,16 @@ 1.576 1.577 ; Set the player's position on the left of the screen. 1.578 1.579 + ; No need to unplot. 1.580 + 1.581 lda #0 ; x = 0 1.582 sta $3304 1.583 lda #0 ; dx = 0 1.584 sta $3305 1.585 1.586 + jsr animate_player_right 1.587 sec ; indicate to the calling routine that the 1.588 - jmp animate_player_right ; player has left the room (optimising away the 1.589 - ; rts) 1.590 + rts ; player has left the room 1.591 1.592 move_player_not_right_key: 1.593 1.594 @@ -1573,6 +1596,7 @@ 1.595 cmp #0 1.596 beq move_player_up_check_y 1.597 1.598 + jsr unplot_character ; unplot the player character 1.599 dec $3303 1.600 clc 1.601 jmp animate_player_up ; optimise away the rts 1.602 @@ -1610,6 +1634,9 @@ 1.603 1.604 move_player_allow_up: 1.605 txa 1.606 + sta $81 ; temporary 1.607 + jsr unplot_character ; unplot the player character 1.608 + lda $81 1.609 sta $3302 ; store the new room y offset 1.610 lda #5 1.611 sta $3303 ; dy = 5 1.612 @@ -1625,13 +1652,16 @@ 1.613 1.614 ; Set the player's position on the bottom of the screen. 1.615 1.616 + ; No need to unplot. 1.617 + 1.618 lda #9 ; y = 9 1.619 sta $3302 1.620 lda #0 ; dy = 0 1.621 sta $3303 1.622 1.623 + jsr animate_player_up 1.624 sec ; indicate to the calling routine that the player 1.625 - jmp animate_player_up ; has left the room (optimising away the rts) 1.626 + rts ; has left the room 1.627 1.628 move_player_not_up_key: 1.629 1.630 @@ -1648,6 +1678,7 @@ 1.631 cmp #5 1.632 beq move_player_down_tile 1.633 1.634 + jsr unplot_character ; unplot the player character 1.635 inc $3303 ; 0 < dy < 5 1.636 clc 1.637 jmp animate_player_down ; optimise away the rts 1.638 @@ -1685,12 +1716,14 @@ 1.639 1.640 move_player_allow_down: 1.641 1.642 + jsr unplot_character ; unplot the player character 1.643 inc $3303 ; update dy 1.644 clc 1.645 jmp animate_player_down ; optimise away the rts 1.646 1.647 move_player_down_tile: 1.648 1.649 + jsr unplot_character ; unplot the player character 1.650 inc $3302 ; store the new room y offset 1.651 lda #0 1.652 sta $3303 ; dy = 0 1.653 @@ -1706,14 +1739,16 @@ 1.654 1.655 ; Set the player's position on the top of the screen. 1.656 1.657 + ; No need to unplot. 1.658 + 1.659 lda #0 ; y = 0 1.660 sta $3302 1.661 lda #0 ; dy = 0 1.662 sta $3303 1.663 1.664 + jsr animate_player_down 1.665 sec ; indicate to the calling routine that the 1.666 - jmp animate_player_down ; player has left the room (optimising away the 1.667 - ; rts) 1.668 + rts ; player has left the room 1.669 1.670 move_player_not_down_key: 1.671 clc 1.672 @@ -1740,11 +1775,115 @@ 1.673 clc 1.674 rts 1.675 1.676 +emerge_character: ; $74,$75=character address 1.677 + 1.678 + lda #63 1.679 + sta $33ff 1.680 + 1.681 + jsr emerge_position ; obtain a y position 1.682 + tax 1.683 + jsr emerge_position ; obtain an x position 1.684 + sta $80 ; temporary 1.685 + tay 1.686 + 1.687 + lda room_row_offsets_low,x 1.688 + sta $70 1.689 + lda #$57 1.690 + sta $71 1.691 + lda ($70),y ; load the tile 1.692 + 1.693 + cmp #0 1.694 + bne emerge_character_exit 1.695 + 1.696 + ; There is a space in the room, so add an emerging enemy. 1.697 + 1.698 + ldy #0 1.699 + lda #3 1.700 + sta ($74),y 1.701 + 1.702 + jsr emerge_type ; obtain an enemy type 1.703 + iny 1.704 + sta ($74),y 1.705 + 1.706 + txa 1.707 + iny 1.708 + sta ($74),y ; store the y position 1.709 + lda #1 1.710 + iny 1.711 + sta ($74),y ; store the dy offset 1.712 + 1.713 + lda $80 1.714 + iny 1.715 + sta ($74),y ; store the x position 1.716 + lda #0 1.717 + iny 1.718 + sta ($74),y ; store the dx offset 1.719 + 1.720 + jsr plot_character 1.721 + 1.722 + emerge_character_exit: 1.723 + clc 1.724 + rts 1.725 + 1.726 +emerge_explode: ; $74,$75=character address 1.727 + 1.728 + jsr unplot_character 1.729 + 1.730 + ldy #1 1.731 + lda ($74),y ; direction/animation 1.732 + tax 1.733 + adc #1 ; update the counter 1.734 + and #7 ; mask off everything else 1.735 + sta $80 ; store the masked counter value 1.736 + bne move_characters_explosion_not_finished 1.737 + 1.738 + txa 1.739 + and #8 1.740 + bne move_characters_remove_character 1.741 + 1.742 + ; For emerges, convert into an enemy. 1.743 + txa 1.744 + and #$70 ; only keep bits 4,5,6 1.745 + lsr ; bits 4,5,6 -> 3,4,5 1.746 + ora #4 ; make this an enemy 1.747 + 1.748 + ldy #0 1.749 + sta ($74),y ; update the type 1.750 + iny 1.751 + lda #0 ; prepare the direction and animation offset 1.752 + sta ($74),y 1.753 + 1.754 + jsr plot_character 1.755 + jmp emerge_explode_exit 1.756 + 1.757 + move_characters_remove_character: 1.758 + 1.759 + ; For finished explosions, just write 0 into the character array. 1.760 + lda #0 1.761 + ldy #0 1.762 + sta ($74),y 1.763 + jmp emerge_explode_exit 1.764 + 1.765 + move_characters_explosion_not_finished: 1.766 + txa 1.767 + and #$f8 1.768 + ora $80 1.769 + 1.770 + ldy #1 1.771 + sta ($74),y 1.772 + 1.773 + jsr plot_character 1.774 + 1.775 + emerge_explode_exit: 1.776 + clc 1.777 + rts 1.778 + 1.779 + 1.780 move_characters: 1.781 1.782 dec $33ff 1.783 1.784 - lda #$0c 1.785 + lda #$0c ; set the character address 1.786 sta $74 1.787 lda #$33 1.788 sta $75 1.789 @@ -1761,48 +1900,7 @@ 1.790 cmp #0 1.791 bne move_characters_next 1.792 1.793 - lda #63 1.794 - sta $33ff 1.795 - 1.796 - jsr emerge_position ; obtain a y position 1.797 - tax 1.798 - jsr emerge_position ; obtain an x position 1.799 - sta $80 ; temporary 1.800 - tay 1.801 - 1.802 - lda room_row_offsets_low,x 1.803 - sta $70 1.804 - lda #$57 1.805 - sta $71 1.806 - lda ($70),y ; load the tile 1.807 - 1.808 - cmp #0 1.809 - bne move_characters_next 1.810 - 1.811 - ; There is a space in the room, so add an emerging enemy. 1.812 - 1.813 - ldy #0 1.814 - lda #3 1.815 - sta ($74),y 1.816 - 1.817 - jsr emerge_type ; obtain an enemy type 1.818 - iny 1.819 - sta ($74),y 1.820 - 1.821 - txa 1.822 - iny 1.823 - sta ($74),y ; store the y position 1.824 - lda #1 1.825 - iny 1.826 - sta ($74),y ; store the dy offset 1.827 - 1.828 - lda $80 1.829 - iny 1.830 - sta ($74),y ; store the x position 1.831 - lda #0 1.832 - iny 1.833 - sta ($74),y ; store the dx offset 1.834 - 1.835 + jsr emerge_character 1.836 jmp move_characters_next 1.837 1.838 move_characters_read_character: 1.839 @@ -1811,45 +1909,7 @@ 1.840 cmp #3 1.841 bne move_characters_next 1.842 1.843 - iny 1.844 - lda ($74),y ; direction/animation 1.845 - tax 1.846 - adc #1 1.847 - and #7 1.848 - sta $80 1.849 - bne move_characters_explosion_not_finished 1.850 - 1.851 - dey 1.852 - 1.853 - txa 1.854 - and #8 1.855 - bne move_characters_remove_character 1.856 - 1.857 - ; For emerges, convert into an enemy. 1.858 - txa 1.859 - and #$70 ; only keep bits 4,5,6 1.860 - lsr ; bits 4,5,6 -> 3,4,5 1.861 - ora #4 ; make this an enemy 1.862 - 1.863 - sta ($74),y ; update the type 1.864 - iny 1.865 - lda #0 ; prepare the direction and animation offset 1.866 - 1.867 - jmp move_characters_update_character 1.868 - 1.869 - move_characters_remove_character: 1.870 - 1.871 - ; For explosions, just write 0 into the character array. 1.872 - lda #0 1.873 - jmp move_characters_update_character 1.874 - 1.875 - move_characters_explosion_not_finished: 1.876 - txa 1.877 - and #$f8 1.878 - ora $80 1.879 - 1.880 - move_characters_update_character: 1.881 - sta ($74),y 1.882 + jsr emerge_explode 1.883 1.884 move_characters_next: 1.885 clc 1.886 @@ -1867,19 +1927,19 @@ 1.887 clc 1.888 rts 1.889 1.890 -clear_characters: 1.891 +remove_characters: 1.892 1.893 ; Clear the character table. 1.894 1.895 ldx #6 1.896 - clear_character_loop: 1.897 + remove_characters_loop: 1.898 lda #0 1.899 sta $3300,x 1.900 txa 1.901 adc #6 1.902 tax 1.903 cpx #$24 1.904 - bmi clear_character_loop 1.905 + bmi remove_characters_loop 1.906 1.907 rts 1.908 1.909 @@ -2005,84 +2065,6 @@ 1.910 sta $3304 1.911 lda #0 ; dx=0 1.912 sta $3305 1.913 - 1.914 -; lda #$3 ; explode/emerge 1.915 -; sta $330c 1.916 -; lda #0 ; emerge (first frame) 1.917 -; sta $330d 1.918 -; lda #3 ; y=3 1.919 -; sta $330e 1.920 -; lda #1 ; dy=1 1.921 -; sta $330f 1.922 -; lda #3 ; x=3 1.923 -; sta $3310 1.924 -; lda #0 ; dx=0 1.925 -; sta $3311 1.926 -; 1.927 -; lda #$4 ; enemy (0) 1.928 -; sta $330c 1.929 -; lda #0 ; left up (first frame) 1.930 -; sta $330d 1.931 -; lda #3 ; y=3 1.932 -; sta $330e 1.933 -; lda #1 ; dy=1 1.934 -; sta $330f 1.935 -; lda #3 ; x=3 1.936 -; sta $3310 1.937 -; lda #0 ; dx=0 1.938 -; sta $3311 1.939 -; 1.940 -; lda #$c ; enemy (1) 1.941 -; sta $3312 1.942 -; lda #4 ; left down (first frame) 1.943 -; sta $3313 1.944 -; lda #3 ; y=3 1.945 -; sta $3314 1.946 -; lda #0 ; dy=0 1.947 -; sta $3315 1.948 -; lda #7 ; x=7 1.949 -; sta $3316 1.950 -; lda #0 ; dx=0 1.951 -; sta $3317 1.952 -; 1.953 -; lda #$14 ; enemy (2) 1.954 -; sta $3318 1.955 -; lda #2 ; right up (first frame) 1.956 -; sta $3319 1.957 -; lda #7 ; y=7 1.958 -; sta $331a 1.959 -; lda #0 ; dy=0 1.960 -; sta $331b 1.961 -; lda #3 ; x=3 1.962 -; sta $331c 1.963 -; lda #0 ; dx=0 1.964 -; sta $331d 1.965 -; 1.966 -; lda #$1c ; enemy (3) 1.967 -; sta $331e 1.968 -; lda #2 ; right up (first frame) 1.969 -; sta $331f 1.970 -; lda #7 ; y=7 1.971 -; sta $3320 1.972 -; lda #0 ; dy=0 1.973 -; sta $3321 1.974 -; lda #3 ; x=3 1.975 -; sta $3322 1.976 -; lda #0 ; dx=0 1.977 -; sta $3323 1.978 -; 1.979 -; lda #$24 ; enemy (4) 1.980 -; sta $3324 1.981 -; lda #6 ; right down (first frame) 1.982 -; sta $3325 1.983 -; lda #7 ; y=7 1.984 -; sta $3326 1.985 -; lda #0 ; dy=0 1.986 -; sta $3327 1.987 -; lda #7 ; x=7 1.988 -; sta $3328 1.989 -; lda #0 ; dx=0 1.990 -; sta $3329 1.991 rts 1.992 1.993 main: 1.994 @@ -2106,34 +2088,29 @@ 1.995 lda $33f3 1.996 sta $79 1.997 jsr plot_room 1.998 - jsr clear_characters 1.999 + jsr remove_characters 1.1000 1.1001 jsr reset_unplot_buffer 1.1002 - lda #255 ; terminate the unplot list by default because the 1.1003 - ldy #0 ; initial plotting of the buffer only plots characters 1.1004 - sta ($84),y 1.1005 jsr reset_plot_buffer 1.1006 - jsr plot_characters 1.1007 + 1.1008 + lda #$00 ; plot the player 1.1009 + sta $74 1.1010 + lda #$33 1.1011 + sta $75 1.1012 + jsr plot_character 1.1013 + 1.1014 jsr plot_buffer 1.1015 1.1016 lda #63 1.1017 sta $33ff 1.1018 1.1019 room_loop: 1.1020 - lda #$00 ; reset the index into the plot buffer 1.1021 - sta $84 1.1022 - lda #$47 1.1023 - sta $85 1.1024 - 1.1025 jsr reset_unplot_buffer 1.1026 - jsr plot_characters ; unplot 1.1027 + jsr reset_plot_buffer 1.1028 jsr move_characters 1.1029 jsr move_player 1.1030 bcs after_room_loop 1.1031 1.1032 - jsr reset_plot_buffer 1.1033 - jsr plot_characters ; plot 1.1034 - 1.1035 lda #19 1.1036 jsr $fff4 1.1037 jsr plot_buffer
