junglejourney
changeset 20:df2cb7f1ff50
Changed the layout of the room buffer in memory, making it match
the layout as shown on screen.
Fixed possible bug in displaying the contents of rooms.
Changed the order of entries in the character array to make it
easier to calculate the screen address of characters while stepping
through the array.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sun Aug 14 20:58:00 2011 +0200 |
| parents | 56200da13c3e |
| children | a8765ab185b8 |
| files | build.py mapcode.oph |
| diffstat | 2 files changed, 228 insertions(+), 165 deletions(-) [+] |
line diff
1.1 --- a/build.py Sun Aug 14 13:33:50 2011 +0200 1.2 +++ b/build.py Sun Aug 14 20:58:00 2011 +0200 1.3 @@ -49,15 +49,13 @@ 1.4 # Planned memory map 1.5 # 1900 CODE (map) 1.6 # 1x00 space 1.7 - # 3300 character table (0xf0/8 = 30 entries) 1.8 + # 3300 character table (0xf0/6 = 40 entries) 1.9 # n type (0 missing, 1 player, 2 projectile, 3 explosion, 4) 1.10 - # n+1 counter/direction 1.11 - # n+2 x room offset (0-10) 1.12 - # n+3 y room offset (0-10) 1.13 - # n+4 screen address (low byte) 1.14 - # n+5 screen address (high byte) 1.15 - # n+6 dx (0-3) 1.16 - # n+7 dy (0-5) 1.17 + # n+1 counter/direction (player: bit 1 is direction, bit 0 is animation) 1.18 + # n+2 y room offset (0-10) 1.19 + # n+3 dy (0-5) 1.20 + # n+4 x room offset (0-10) 1.21 + # n+5 dx (0-3) 1.22 # 1.23 # first character is always the player 1.24 # second character is always the player's weapon
2.1 --- a/mapcode.oph Sun Aug 14 13:33:50 2011 +0200 2.2 +++ b/mapcode.oph Sun Aug 14 20:58:00 2011 +0200 2.3 @@ -23,38 +23,42 @@ 2.4 clc 2.5 rts ; A % 9 2.6 2.7 +tile_values_map: .byte 0,1,0,0,0,0,2,3 2.8 + 2.9 next_value: ; no argument 2.10 jsr unlimited_values 2.11 lda $7d 2.12 jsr div9 2.13 - and #7 2.14 + and #7 ; (next value % 9) & 7 2.15 + tax 2.16 + lda tile_values_map,x 2.17 sta $7b 2.18 - rts ; $7b = (next value % 9) & 3 2.19 + rts 2.20 2.21 ; Room filling routines, writing to 0x579c to 0x57ff. 2.22 2.23 draw_top_line: 2.24 ldx #9 2.25 - lda #6 2.26 + lda #2 2.27 2.28 draw_top_line_loop0: 2.29 - sta $57f6,x 2.30 + sta $579c,x 2.31 dex 2.32 bpl draw_top_line_loop0 2.33 2.34 - ldx #3 2.35 + ldx #3 ; draw the exit or wall 2.36 lda $76 2.37 draw_top_line_loop1: 2.38 - sta $57f9,x 2.39 + sta $579f,x 2.40 dex 2.41 bpl draw_top_line_loop1 2.42 clc 2.43 rts 2.44 2.45 draw_left_line: 2.46 - ldx #99 2.47 + ldx #90 2.48 draw_left_line_loop0: 2.49 - lda #6 2.50 + lda #2 2.51 sta $579c,x 2.52 txa 2.53 sec 2.54 @@ -62,7 +66,7 @@ 2.55 tax 2.56 bpl draw_left_line_loop0 2.57 2.58 - ldx #39 2.59 + ldx #30 2.60 draw_left_line_loop1: 2.61 lda $77 2.62 sta $57ba,x 2.63 @@ -76,25 +80,25 @@ 2.64 2.65 draw_bottom_line: 2.66 ldx #9 2.67 - lda #6 2.68 + lda #2 2.69 draw_bottom_line_loop0: 2.70 - sta $579c,x 2.71 + sta $57f6,x 2.72 dex 2.73 bpl draw_bottom_line_loop0 2.74 2.75 ldx #3 2.76 lda $76 2.77 draw_bottom_line_loop1: 2.78 - sta $579f,x 2.79 + sta $57f9,x 2.80 dex 2.81 bpl draw_bottom_line_loop1 2.82 clc 2.83 rts 2.84 2.85 draw_right_line: 2.86 - ldx #90 2.87 + ldx #99 2.88 draw_right_line_loop0: 2.89 - lda #6 2.90 + lda #2 2.91 sta $579c,x 2.92 txa 2.93 sec 2.94 @@ -105,7 +109,7 @@ 2.95 ldx #30 2.96 draw_right_line_loop1: 2.97 lda $77 2.98 - sta $57ba,x 2.99 + sta $57c3,x 2.100 txa 2.101 sec 2.102 sbc #10 2.103 @@ -116,14 +120,24 @@ 2.104 2.105 make_room: ; $78,$79=i,j 2.106 2.107 -; Determine if there is a top exit. 2.108 + ; Fill the room with empty space. 2.109 + 2.110 + ldx #100 2.111 + make_empty_room_loop: 2.112 + lda #0 2.113 + sta $579c,x 2.114 + dex 2.115 + bpl make_empty_room_loop 2.116 + 2.117 + ; Determine if there is a top exit. 2.118 + 2.119 lda #0 2.120 sta $76 2.121 2.122 lda $78 ; i == 0 2.123 cmp #0 2.124 bne not_top_screen 2.125 - lda #6 2.126 + lda #2 2.127 sta $76 2.128 jmp do_top_exit 2.129 not_top_screen: 2.130 @@ -144,7 +158,7 @@ 2.131 clc 2.132 cmp $79 ; (i ^ j) + i == j 2.133 bne do_top_exit 2.134 - lda #6 2.135 + lda #2 2.136 sta $76 ; top exit 2.137 2.138 do_top_exit: 2.139 @@ -157,7 +171,7 @@ 2.140 lda $79 2.141 cmp #0 2.142 bne not_left_screen 2.143 - lda #6 2.144 + lda #2 2.145 sta $77 2.146 jmp do_left_exit 2.147 not_left_screen: 2.148 @@ -177,7 +191,7 @@ 2.149 eor $79 ; ^ j 2.150 cmp $78 ; (i | j) ^ j == i 2.151 bne do_left_exit 2.152 - lda #6 2.153 + lda #2 2.154 sta $77 ; left exit 2.155 2.156 do_left_exit: 2.157 @@ -190,7 +204,7 @@ 2.158 lda $79 2.159 cmp #10 2.160 bne not_right_screen 2.161 - lda #6 2.162 + lda #2 2.163 sta $77 2.164 jmp do_right_exit 2.165 not_right_screen: 2.166 @@ -215,7 +229,7 @@ 2.167 eor $70 ; ^ j 2.168 cmp $78 ; (i | j) ^ j == i 2.169 bne do_right_exit 2.170 - lda #6 2.171 + lda #2 2.172 sta $77 ; right exit 2.173 2.174 do_right_exit: 2.175 @@ -228,7 +242,7 @@ 2.176 lda $78 2.177 cmp #10 2.178 bne not_bottom_screen 2.179 - lda #6 2.180 + lda #2 2.181 sta $76 2.182 jmp do_bottom_exit 2.183 not_bottom_screen: 2.184 @@ -252,7 +266,7 @@ 2.185 adc $70 ; + i 2.186 cmp $79 ; (i ^ j) + i == j 2.187 bne do_bottom_exit 2.188 - lda #6 2.189 + lda #2 2.190 sta $76 ; bottom exit 2.191 2.192 do_bottom_exit: 2.193 @@ -267,28 +281,9 @@ 2.194 cmp $33f1 2.195 bne not_starting_room 2.196 2.197 - clc 2.198 - 2.199 - ; Fill the room with empty space. 2.200 - 2.201 - ldx #78 2.202 - ldy #63 2.203 - make_empty_room_loop: 2.204 - lda #0 2.205 - sta $57a6,x 2.206 - dey 2.207 - tya 2.208 - and #7 2.209 - cmp #7 2.210 - bne finished_empty_room 2.211 - dex 2.212 - dex 2.213 - 2.214 -finished_empty_room: 2.215 - clc 2.216 rts 2.217 2.218 -not_starting_room: 2.219 + not_starting_room: 2.220 clc 2.221 2.222 ; Fill in the room details. 2.223 @@ -314,24 +309,30 @@ 2.224 2.225 ; Fill the room array with values. 2.226 2.227 - ldx #78 2.228 - ldy #63 2.229 + lda #$a7 2.230 + sta $70 2.231 + lda #$57 2.232 + sta $71 2.233 + 2.234 + ldy #0 2.235 make_room_loop1: 2.236 + 2.237 jsr next_value 2.238 - sta $57a6,x 2.239 - dey 2.240 - tya 2.241 - and #7 2.242 - cmp #7 2.243 - bne next1 2.244 - dex 2.245 - dex 2.246 + sta ($70),y 2.247 + iny 2.248 + cpy #8 2.249 + bne make_room_loop1 ; continue the same row 2.250 2.251 -next1: 2.252 - clc 2.253 - dex 2.254 - bpl make_room_loop1 2.255 + lda $70 2.256 + cmp #$ed 2.257 + beq make_room_loop1_exit ; exit after the last row 2.258 + 2.259 + adc #10 2.260 + sta $70 2.261 + ldy #0 ; reset the row counter 2.262 + jmp make_room_loop1 2.263 2.264 + make_room_loop1_exit: 2.265 rts 2.266 2.267 2.268 @@ -452,7 +453,7 @@ 2.269 jmp plot_not_blank 2.270 2.271 not_flowers: 2.272 - cmp #6 2.273 + cmp #2 2.274 bne not_tree1 2.275 lda #$60 2.276 sta $70 2.277 @@ -461,7 +462,7 @@ 2.278 jmp plot_not_blank 2.279 2.280 not_tree1: 2.281 - cmp #7 2.282 + cmp #3 2.283 bne not_tree2 2.284 lda #$c0 2.285 sta $70 2.286 @@ -511,7 +512,7 @@ 2.287 2.288 jsr make_room 2.289 2.290 - lda #99 2.291 + lda #0 2.292 sta $7a 2.293 row_loop: 2.294 2.295 @@ -526,8 +527,7 @@ 2.296 jsr plot_tile 2.297 2.298 lda $7a 2.299 - sec 2.300 - sbc #1 2.301 + adc #1 2.302 sta $7a 2.303 lda $76 2.304 sec 2.305 @@ -580,6 +580,7 @@ 2.306 2.307 plotloop8x24_y0_0: 2.308 lda ($70),y 2.309 + eor ($72),y 2.310 sta ($72),y 2.311 dey 2.312 bpl plotloop8x24_y0_0 2.313 @@ -597,6 +598,7 @@ 2.314 2.315 plotloop8x24_y0_1: 2.316 lda ($70),y 2.317 + eor ($72),y 2.318 sta ($72),y 2.319 dey 2.320 cpy #16 2.321 @@ -615,6 +617,7 @@ 2.322 2.323 plotloop8x24_y0_2: 2.324 lda ($70),y 2.325 + eor ($72),y 2.326 sta ($72),y 2.327 dey 2.328 cpy #32 2.329 @@ -647,6 +650,7 @@ 2.330 2.331 plotloop8x24_y1_0: 2.332 lda ($70),y 2.333 + eor ($72),y 2.334 sta ($72),y 2.335 dey 2.336 bpl plotloop8x24_y1_0 2.337 @@ -656,6 +660,7 @@ 2.338 2.339 plotloop8x24_y1_1: 2.340 lda ($70),y 2.341 + eor ($72),y 2.342 sta ($72),y 2.343 dey 2.344 cpy #8 2.345 @@ -682,6 +687,7 @@ 2.346 2.347 plotloop8x24_y1_2: 2.348 lda ($70),y 2.349 + eor ($72),y 2.350 sta ($72),y 2.351 dey 2.352 bpl plotloop8x24_y1_2 2.353 @@ -691,6 +697,7 @@ 2.354 2.355 plotloop8x24_y1_3: 2.356 lda ($70),y 2.357 + eor ($72),y 2.358 sta ($72),y 2.359 dey 2.360 cpy #8 2.361 @@ -805,107 +812,149 @@ 2.362 player_direction_chars_low: .byte $00,$30,$60,$90,$c0,$f0,$20,$50 2.363 player_direction_chars_high: .byte $34,$34,$34,$34,$34,$34,$35,$35 2.364 2.365 +screen_rows_low: .byte $00,$c0,$80,$40,$00,$c0,$80,$40,$00,$c0 2.366 +screen_rows_high: .byte $58,$5b,$5f,$63,$67,$6a,$6e,$72,$76,$79 2.367 +screen_subrows_low: .byte $00,$04,$40,$44,$80,$84 2.368 +screen_subrows_high: .byte $00,$00,$01,$01,$02,$02 2.369 + 2.370 +screen_columns_low: .byte $00,$20,$40,$60,$80,$a0,$c0,$e0,$00,$20 2.371 +screen_columns_high: .byte $00,$00,$00,$00,$00,$00,$00,$00,$01,$01 2.372 +screen_subcolumns_low: .byte $00,$08,$10,$18 2.373 + 2.374 plot_characters: 2.375 2.376 - lda $3300 2.377 - cmp #1 2.378 - bne plot_characters_loop 2.379 - clc 2.380 + lda #$00 2.381 + sta $74 2.382 + lda #$33 2.383 + sta $75 2.384 2.385 - ; Use lookup tables to load the offsets into the sprite. 2.386 + ldy #0 2.387 + plot_characters_loop: 2.388 2.389 - lda $3301 ; direction 2.390 - tax 2.391 - lda player_direction_chars_low,x 2.392 - sta $70 2.393 - lda player_direction_chars_high,x 2.394 - sta $71 2.395 + lda ($74),y 2.396 + cmp #1 2.397 + bne plot_characters_next 2.398 2.399 - ; Load the screen address. 2.400 + ; Use lookup tables to load the offsets into the sprite. 2.401 2.402 - lda $3304 2.403 - sta $72 2.404 - lda $3305 2.405 - sta $73 2.406 + ; Direction 2.407 + iny 2.408 + lda ($74),y 2.409 + tax 2.410 + lda player_direction_chars_low,x 2.411 + sta $70 2.412 + lda player_direction_chars_high,x 2.413 + sta $71 2.414 2.415 - ; Use the dy value to determine which plotting routine to use. 2.416 + ; y 2.417 + iny 2.418 + lda ($74),y 2.419 + tax 2.420 + lda screen_rows_low,x 2.421 + sta $72 2.422 + lda screen_rows_high,x 2.423 + sta $73 2.424 + clc 2.425 2.426 - lda $3307 2.427 - and #1 2.428 - bne plot_characters_plot_player1 2.429 + ; dy 2.430 + iny 2.431 + lda ($74),y 2.432 + tax 2.433 + lda screen_subrows_low,x 2.434 + adc $72 2.435 + sta $72 2.436 + lda screen_subrows_high,x 2.437 + adc $73 2.438 + sta $73 2.439 + clc 2.440 2.441 - jsr plot8x24_y0 2.442 - jmp plot_characters_array 2.443 + ; x 2.444 + iny 2.445 + lda ($74),y 2.446 + tax 2.447 + lda screen_columns_low,x 2.448 + adc $72 2.449 + sta $72 2.450 + lda screen_columns_high,x 2.451 + adc $73 2.452 + sta $73 2.453 + clc 2.454 2.455 -plot_characters_plot_player1: 2.456 - clc 2.457 - jsr plot8x24_y1 2.458 + ; dx 2.459 + iny 2.460 + lda ($74),y 2.461 + tax 2.462 + lda screen_subcolumns_low,x 2.463 + adc $72 2.464 + sta $72 2.465 + clc 2.466 2.467 -plot_characters_array: 2.468 - ldx #6 2.469 + ; Use the dy value to determine which plotting routine to use. 2.470 2.471 - plot_characters_loop: 2.472 - lda $3300,x 2.473 - txa 2.474 + iny 2.475 + lda ($74),y 2.476 + and #1 2.477 + bne plot_characters_plot_player1 2.478 + 2.479 + jsr plot8x24_y0 2.480 + jmp plot_characters_exit 2.481 + 2.482 + plot_characters_plot_player1: 2.483 clc 2.484 - adc #6 2.485 - cmp #234 2.486 - tax 2.487 - bne plot_characters_loop 2.488 + jsr plot8x24_y1 2.489 2.490 - rts 2.491 + plot_characters_next: 2.492 + clc 2.493 2.494 -room_row_offsets_low: .byte $9c,$a6,$b0,$ba,$c4,$ce,$d8,$e2,$ec,$f6 2.495 + ; Examine the next character. 2.496 2.497 -move_player_left: 2.498 + iny 2.499 + bcc plot_characters_loop 2.500 2.501 - ; Decrement dx and subtract 8 from the screen address. 2.502 - 2.503 - lda $3301 2.504 - and #254 ; remove direction information 2.505 - eor #1 ; toggle animation flag 2.506 - sta $3301 2.507 - lda #0 ; direction = 0 2.508 - sta $3301 2.509 - 2.510 - dec $3306 2.511 - bpl move_player_left_not_underflow 2.512 - lda #3 2.513 - sta $3306 2.514 - 2.515 -move_player_left_not_underflow: 2.516 - sec 2.517 - lda $3304 ; screen position -= 8 2.518 - sbc #8 2.519 - sta $3304 2.520 + plot_characters_exit: 2.521 clc 2.522 rts 2.523 2.524 +; Note that the room offsets reflect that the room is 2.525 +room_row_offsets_low: .byte $9c,$a6,$b0,$ba,$c4,$ce,$d8,$e2,$ec,$f6 2.526 + 2.527 +animate_player_left: 2.528 + 2.529 + ; Set the direction and toggle the animation bit. 2.530 + 2.531 + lda $3301 2.532 + and #1 ; remove direction information (result is 0) 2.533 + eor #1 ; toggle animation flag 2.534 + sta $3301 2.535 + rts 2.536 + 2.537 move_player: 2.538 - jsr key_input 2.539 - cmp #1 2.540 + 2.541 + ldx #158 ; handle left key 2.542 + jsr check_key 2.543 + cpy #255 2.544 bne move_player_not_left_key 2.545 2.546 ; Handle the left key. 2.547 2.548 - lda $3306 ; read dx 2.549 + lda $3305 ; read dx 2.550 cmp #0 2.551 beq move_player_check_x 2.552 2.553 - jmp move_player_left ; optimise rts 2.554 + dec $3305 2.555 + clc 2.556 + jmp animate_player_left ; optimise away the rts 2.557 + 2.558 + move_player_check_x: ; Check the x offset. 2.559 2.560 -move_player_check_x: 2.561 - 2.562 - ; Check the x offset. 2.563 - 2.564 - lda $3302 2.565 + lda $3304 2.566 cmp #0 2.567 beq move_player_leave_room_left 2.568 2.569 sec 2.570 - sbc #1 ; dx = dx - 1 2.571 + sbc #1 ; x - 1 2.572 tay 2.573 - lda $3303 ; load the y offset 2.574 + lda $3302 ; load the y offset 2.575 tax ; as an index 2.576 lda room_row_offsets_low,x ; read the address of the row 2.577 sta $70 2.578 @@ -916,13 +965,25 @@ 2.579 cmp #0 2.580 bne move_player_not_left_key 2.581 2.582 + lda $3303 ; dy 2.583 + cmp #0 2.584 + bne move_player_allow_left 2.585 + lda $70 2.586 + adc #10 2.587 + lda ($70),y ; load the tile below and to the left 2.588 + 2.589 + cmp #0 2.590 + bne move_player_not_left_key 2.591 + 2.592 + move_player_allow_left: 2.593 tya 2.594 - sta $3302 ; store the new room x offset 2.595 + sta $3304 ; store the new room x offset 2.596 lda #3 2.597 - sta $3306 ; dx = 3 2.598 - jmp move_player_left ; optimise rts 2.599 + sta $3305 ; dx = 3 2.600 + clc 2.601 + jmp animate_player_left ; optimise away the rts 2.602 2.603 -move_player_leave_room_left: 2.604 + move_player_leave_room_left: 2.605 sec 2.606 lda $33f3 2.607 sbc #1 2.608 @@ -932,22 +993,17 @@ 2.609 ; Set the player's position on the right of the screen. 2.610 2.611 lda #9 ; x = 9 2.612 - sta $3302 2.613 + sta $3304 2.614 lda #2 ; dx = 2 2.615 - sta $3306 2.616 + sta $3305 2.617 2.618 - lda $3304 2.619 - adc #$30 2.620 - sta $3304 2.621 - lda $3305 2.622 - adc #0 2.623 - sta $3305 2.624 - 2.625 - sec 2.626 + sec ; indicate to the calling routine that the player 2.627 + jsr animate_player_left ; has left the room 2.628 rts 2.629 2.630 -not_left_room: 2.631 -move_player_not_left_key: 2.632 + move_player_not_left_key: 2.633 + 2.634 + move_player_not_up_key: 2.635 clc 2.636 rts 2.637 2.638 @@ -1073,20 +1129,16 @@ 2.639 2.640 lda #1 ; player 2.641 sta $3300 2.642 - lda #3 ; down 2.643 + lda #6 ; down (first frame) 2.644 sta $3301 2.645 + lda #5 ; y=5 2.646 + sta $3302 2.647 + lda #0 ; dy=0 2.648 + sta $3303 2.649 lda #5 ; x=5 2.650 - sta $3302 2.651 - lda #5 ; y=5 2.652 - sta $3303 2.653 - lda #$60 ; centre of the screen 2.654 sta $3304 2.655 - lda #$6b 2.656 + lda #0 ; dx=0 2.657 sta $3305 2.658 - lda #0 ; dx=0 2.659 - sta $3306 2.660 - lda #0 ; dy=0 2.661 - sta $3307 2.662 rts 2.663 2.664 main: 2.665 @@ -1110,11 +1162,21 @@ 2.666 lda $33f3 2.667 sta $79 2.668 jsr plot_room 2.669 + jsr plot_characters 2.670 2.671 room_loop: 2.672 - jsr plot_characters 2.673 + lda #19 2.674 + jsr $fff4 2.675 + jsr plot_characters ; unplot 2.676 jsr move_player 2.677 bcs after_room_loop 2.678 + 2.679 + jsr plot_characters ; plot 2.680 + ldx #157 2.681 + jsr check_key 2.682 + cpy #255 2.683 + beq exit 2.684 + clc 2.685 jmp room_loop 2.686 2.687 after_room_loop: 2.688 @@ -1122,4 +1184,7 @@ 2.689 jmp game_loop 2.690 2.691 jmp main_loop 2.692 + 2.693 + exit: 2.694 + clc 2.695 rts
