junglejourney
changeset 18:ddb15fb07db6
Started adding support for characters.
Created a specialised routine for wiping characters to reduce the
memory used for sprites.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sat Aug 13 18:48:27 2011 +0200 |
| parents | ae5f572644bd |
| children | 56200da13c3e |
| files | build.py mapcode.oph |
| diffstat | 2 files changed, 99 insertions(+), 23 deletions(-) [+] |
line diff
1.1 --- a/build.py Sat Aug 13 15:45:29 2011 +0200 1.2 +++ b/build.py Sat Aug 13 18:48:27 2011 +0200 1.3 @@ -49,11 +49,13 @@ 1.4 # Planned memory map 1.5 # 1900 CODE (map) 1.6 # 1x00 space 1.7 - # 4F00 character table (128/4 entries) 1.8 - # n type 1.9 + # 4F00 character table (0xf0/6 = 40 entries) 1.10 + # n type (0 missing, 1 player, 2 projectile, 3 explosion, 4) 1.11 # n+1 counter/direction 1.12 - # n+2 x position (0-19, top bit 0-1) 1.13 - # n+3 y position (0-27, top bit 0-1) 1.14 + # n+2 room offset (0-99) 1.15 + # n+3 x and y steps (0-1, bits 0 and 1) 1.16 + # n+4 screen address (low byte) 1.17 + # n+5 screen address (high byte) 1.18 # 1.19 # first character is always the player 1.20 # second character is always the player's weapon 1.21 @@ -63,6 +65,7 @@ 1.22 # 4FF2 current room (i, j) 1.23 # 4FF4 lives 1.24 # 4FF6 score (four bytes) 1.25 + # 4FFA level 1.26 # 4FFB palette workspace (enough for one 5 byte palette entry) 1.27 # 1.28 # 5000 CHARS (character sprites)
2.1 --- a/mapcode.oph Sat Aug 13 15:45:29 2011 +0200 2.2 +++ b/mapcode.oph Sat Aug 13 18:48:27 2011 +0200 2.3 @@ -387,6 +387,57 @@ 2.4 2.5 rts 2.6 2.7 +plot_blank: ; $72,$73=destination address 2.8 + 2.9 + ldy #$1f 2.10 + lda #0 2.11 + plot_blank_loop0: 2.12 + sta ($72),y 2.13 + dey 2.14 + bpl plot_blank_loop0 2.15 + 2.16 + lda $72 2.17 + adc #$20 2.18 + sta $72 2.19 + lda $73 2.20 + adc #$01 2.21 + sta $73 ; next line minus 0x20 2.22 + clc 2.23 + 2.24 + ldy #$3f 2.25 + lda #0 2.26 + plot_blank_loop1: 2.27 + sta ($72),y 2.28 + dey 2.29 + cpy #$20 2.30 + bpl plot_blank_loop1 2.31 + 2.32 + lda $72 2.33 + adc #$20 2.34 + sta $72 2.35 + lda $73 2.36 + adc #$01 2.37 + sta $73 ; next line minus 0x20 2.38 + clc 2.39 + 2.40 + ldy #$5f 2.41 + lda #0 2.42 + plot_blank_loop2: 2.43 + sta ($72),y 2.44 + dey 2.45 + cpy #$40 2.46 + bpl plot_blank_loop2 2.47 + 2.48 + sec 2.49 + lda $72 2.50 + sbc #$20 2.51 + sta $72 2.52 + lda $73 2.53 + sbc #$02 2.54 + sta $73 ; back two lines minus 0x20 2.55 + clc 2.56 + 2.57 + rts 2.58 2.59 plot_tile: ; $7b=tile number 2.60 ; $72,$73=screen position 2.61 @@ -419,12 +470,8 @@ 2.62 clc 2.63 jmp plot ; optimise away the rts 2.64 not_tree2: 2.65 - lda #$00 2.66 - sta $70 2.67 - lda #$56 2.68 - sta $71 2.69 clc 2.70 - jsr plot 2.71 + jsr plot_blank 2.72 rts 2.73 2.74 plot_room: ; $78,$79 = i,j (from $4ff0,$4ff1) 2.75 @@ -703,6 +750,23 @@ 2.76 lda #0 2.77 rts 2.78 2.79 +plot_characters: 2.80 + rts 2.81 + 2.82 +move_player: 2.83 + jsr key_input 2.84 + cmp #1 2.85 + bne not_left_room 2.86 + sec 2.87 + lda $4ff3 2.88 + sbc #1 2.89 + sta $4ff3 2.90 + sec 2.91 + rts 2.92 + 2.93 +not_left_room: 2.94 + clc 2.95 + rts 2.96 2.97 set_palette: 2.98 ; $70=logical colour 2.99 @@ -786,13 +850,28 @@ 2.100 rts 2.101 2.102 start_new_game: 2.103 - lda #5 ; set starting room and current room 2.104 + 2.105 + ; Set starting room and current room. 2.106 + 2.107 + lda #5 2.108 sta $4ff0 2.109 sta $4ff2 2.110 lda #5 2.111 sta $4ff1 2.112 sta $4ff3 2.113 2.114 + ; Clear the character table and set player position. 2.115 + 2.116 + ldx #234 2.117 + clear_character_loop: 2.118 + lda #0 2.119 + sta $4f00,x 2.120 + txa 2.121 + sec 2.122 + sbc #6 2.123 + tax 2.124 + bpl clear_character_loop 2.125 + 2.126 rts 2.127 2.128 main: 2.129 @@ -817,20 +896,14 @@ 2.130 sta $79 2.131 jsr plot_room 2.132 2.133 - key_loop: 2.134 - jsr key_input 2.135 - cmp #1 2.136 - bne not_left 2.137 - sec 2.138 - lda $4ff3 2.139 - sbc #1 2.140 - sta $4ff3 2.141 - jmp after_key_loop 2.142 + room_loop: 2.143 + jsr plot_characters 2.144 + jsr move_player 2.145 + bcs after_room_loop 2.146 + jmp room_loop 2.147 2.148 - not_left: 2.149 - jmp key_loop 2.150 - 2.151 - after_key_loop: 2.152 + after_room_loop: 2.153 + clc 2.154 jmp game_loop 2.155 2.156 jmp main_loop
